<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Optimization in Data Science</title>
 <link href="https://optimization-for-data-science-iuh-2025.pages.dev/atom.xml" rel="self"/>
 <link href="https://optimization-for-data-science-iuh-2025.pages.dev/"/>
 <updated>2026-12-05T04:04:43+00:00</updated>
 <id>https://optimization-for-data-science-iuh-2025.pages.dev</id>
 <author>
   <name>Nguyen Le Linh</name>
   <email>nglelinh@gmail.com</email>
 </author>

 
 <entry>
   <title>28-05 Điều kiện PL và câu chuyện tốc độ hiện đại</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_05_pl_condition/"/>
   <updated>2026-09-18T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_05_pl_condition</id>
   <content type="html">&lt;p&gt;Trong suốt khóa học tối ưu lồi, ta quen với một câu chuyện đẹp: hàm \(L\)-trơn và \(m\)-lồi mạnh thì Gradient Descent hội tụ tuyến tính với tốc độ \((1 - m/L)^k\). Nhưng khi sang học sâu, hàm mất mát thậm chí &lt;strong&gt;không lồi&lt;/strong&gt; (có cả vùng độ cong âm!), vậy tại sao thực nghiệm lại thường xuyên chứng kiến đường mất mát huấn luyện lao thẳng xuống theo đường thẳng trên đồ thị logarit giống hệt hội tụ tuyến tính?&lt;/p&gt;

&lt;p&gt;Câu trả lời nằm ở một bất đẳng thức gọn nhẹ từ thập niên 1960 nhưng mãi đến năm 2016 mới được Karimi, Nutini và Schmidt phục hưng rực rỡ trong học máy: &lt;strong&gt;Điều kiện Polyak–Łojasiewicz (PL)&lt;/strong&gt;. Điều kỳ diệu là bất đẳng thức PL &lt;strong&gt;không hề đòi hỏi tính lồi&lt;/strong&gt;, không đòi hỏi cực tiểu phải duy nhất — nhưng vẫn đủ mạnh để giữ nguyên vẹn phép chứng minh hội tụ tuyến tính chỉ trong 3 dòng đại số!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-điều-kiện-polyakłojasiewicz-pl&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của Điều kiện Polyak–Łojasiewicz (PL)&lt;/h2&gt;

&lt;p&gt;Để thấy vị trí đặc biệt của điều kiện PL trong hệ thống phân cấp các giả thiết tối ưu hóa, hãy nắm ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phát biểu và Hệ quả hình học (Không có cực tiểu giả):&lt;/strong&gt; Bất đẳng thức \(\frac{1}{2}\|\nabla F(w)\|_2^2 \ge \mu(F(w) - F^\star)\) nói rằng hễ bạn còn cách đáy \(F^\star\) bao nhiêu thì độ dốc \(\|\nabla F(w)\|\) phải lớn tương xứng bấy nhiêu. Hệ quả tức thì: tại bất cứ điểm nào có \(\nabla F(w) = 0\), ta &lt;em&gt;bắt buộc&lt;/em&gt; có \(F(w) = F^\star\) — mọi điểm dừng đều là cực tiểu toàn cục!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân cấp chặt chẽ các giả thiết:&lt;/strong&gt; Lồi mạnh (\(m\)-strongly convex) \(\implies\) PL (với \(\mu = m\)), nhưng &lt;strong&gt;chiều ngược lại hoàn toàn sai&lt;/strong&gt;: một hàm có thể vừa không lồi vừa có vô số cực tiểu toàn cục (như bình phương tối thiểu thiếu xác định \(\frac{1}{2}\|Xw - y\|_2^2\) hay mạng rộng chế độ NTK) mà vẫn thỏa mãn PL!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh hội tụ tuyến tính 3 dòng:&lt;/strong&gt; Chỉ cần ghép đúng hai bất đẳng thức — bổ đề giảm của hàm \(L\)-trơn \(F(w_{k+1}) \le F(w_k) - \frac{1}{2L}\|\nabla F(w_k)\|_2^2\) và bất đẳng thức PL — ta thu ngay \(F(w_{k+1}) - F^\star \le \left(1 - \frac{\mu}{L}\right)(F(w_k) - F^\star)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tay-một-hàm-không-lồi-nhưng-thỏa-điều-kiện-pl&quot;&gt;Giải thích: Kiểm chứng tay một hàm KHÔNG LỒI nhưng thỏa Điều kiện PL&lt;/h3&gt;

&lt;p&gt;Xét ví dụ kinh điển của Karimi, Nutini và Schmidt (2016):&lt;/p&gt;

\[F(w) = w^2 + 3\sin^2(w), \qquad w \in \mathbb{R}.\]

&lt;p&gt;Nghiệm tối ưu toàn cục hiển nhiên là \(w^\star = 0\) với \(F^\star = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh \(F(w)\) KHÔNG LỒI:&lt;/strong&gt;
Tính đạo hàm bậc nhất và bậc hai:
\(F&apos;(w) = 2w + 6\sin w \cos w = 2w + 3\sin(2w), \qquad F&apos;&apos;(w) = 2 + 6\cos(2w).\)
Thay \(w = \frac{\pi}{2} \approx 1.571\):
\(F&apos;&apos;\!\left(\frac{\pi}{2}\right) = 2 + 6\cos(\pi) = 2 - 6 = -4 &amp;lt; 0!\)
Vì đạo hàm bậc hai âm mạnh tại \(w = \pi/2\), đồ thị bị &lt;strong&gt;lõm xuống&lt;/strong&gt; — \(F\) hoàn toàn không lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thế nhưng tại chính điểm lõm \(w = \frac{\pi}{2}\), gradient KHÔNG hề bằng 0 mà rất lớn:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giá trị hàm: \(F\!\left(\frac{\pi}{2}\right) = \left(\frac{\pi}{2}\right)^2 + 3\sin^2\!\left(\frac{\pi}{2}\right) \approx 2.467 + 3 = 5.467\).&lt;/li&gt;
      &lt;li&gt;Đạo hàm bậc nhất: \(F&apos;\!\left(\frac{\pi}{2}\right) = \pi + 3\sin(\pi) = \pi \approx 3.142\).&lt;/li&gt;
      &lt;li&gt;Tỷ số PL tại \(w = \frac{\pi}{2}\):
\(\frac{\frac{1}{2}|F&apos;(\pi/2)|^2}{F(\pi/2) - F^\star} = \frac{\pi^2 / 2}{5.467} \approx \frac{4.935}{5.467} \approx 0.903 &amp;gt; 0!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Nhờ thành phần \(w^2\) luôn kéo \(F&apos;(w)\) đủ lớn trên toàn trục thực (thực tế $$\frac{1}{2}&lt;/td&gt;
          &lt;td&gt;F’(w)&lt;/td&gt;
          &lt;td&gt;^2 \ge \frac{1}{32} F(w)\(với mọi\)w \in \mathbb{R}\(), hàm sóng gập ghềnh này không có bất kỳ cực tiểu địa phương giả nào — và Gradient Descent lao thẳng về\)w^\star = 0$$ với tốc độ hội tụ tuyến tính!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chương 06 đã chứng minh gradient descent đạt tốc độ hội tụ tuyến tính dưới giả thiết &lt;strong&gt;lồi mạnh&lt;/strong&gt;: \(F(w_k)-F^\star\le c^k(F(w_0)-F^\star)\) với \(c=1-\Theta(m/L)\). Hàm mất mát trong học sâu không lồi mạnh — thậm chí không lồi — nhưng trên thực tế người ta vẫn thường quan sát thấy đường mất mát huấn luyện giảm tuyến tính trên trục log khi mạng đủ rộng để nội suy. Bất đẳng thức &lt;strong&gt;Polyak–Łojasiewicz (PL)&lt;/strong&gt; là điều kiện yếu nhất cho phép &lt;em&gt;tái sử dụng trực tiếp phép chứng minh Chương 06&lt;/em&gt; cho một lớp bài toán không lồi. Bài đọc tùy chọn này đóng vai trò cầu nối giữa 06-03-04 và địa hình không lồi ở 28-01–28-03.&lt;/p&gt;

&lt;p&gt;Tài liệu tham khảo nền tảng là Karimi, Nutini và Schmidt, &lt;em&gt;Linear Convergence of Gradient and Proximal-Gradient Methods under the Polyak–Łojasiewicz Condition&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/1608.04636&quot;&gt;arXiv:1608.04636&lt;/a&gt; (bản rút gọn tại ECML 2016).&lt;/p&gt;

&lt;h2 id=&quot;bất-đẳng-thức-pl-và-phạm-vi-hàm-ý&quot;&gt;Bất đẳng thức PL và phạm vi hàm ý&lt;/h2&gt;

&lt;p&gt;Hàm \(F\) thỏa &lt;strong&gt;điều kiện PL&lt;/strong&gt; với hằng số \(\mu&amp;gt;0\) trên tập \(\mathcal{W}\) nếu với mọi \(w\in\mathcal{W}\):&lt;/p&gt;

\[\tfrac12\|\nabla F(w)\|_2^2\ge\mu\bigl(F(w)-F^\star\bigr),\]

&lt;p&gt;trong đó \(F^\star=\inf F\) (giả sử đạt được). Bất đẳng thức này kéo theo ngay: hễ \(\nabla F(w)=0\) thì \(F(w)=F^\star\), nghĩa là mọi điểm tới hạn trong \(\mathcal{W}\) đều là cực tiểu &lt;em&gt;toàn cục&lt;/em&gt; — không tồn tại cực tiểu địa phương giả trong \(\mathcal{W}\) dù không cần giả thiết tính lồi.&lt;/p&gt;

&lt;p&gt;Tuy nhiên, điều kiện PL &lt;strong&gt;không&lt;/strong&gt; đảm bảo nghiệm cực tiểu là duy nhất: tập \(\{w:F(w)=F^\star\}\) có thể là một không gian affine nhiều chiều (ví dụ bài toán bình phương tối thiểu quá tham số hóa). PL cũng &lt;strong&gt;không&lt;/strong&gt; suy ra tính lồi: hàm một chiều \(F(w)=w^2+3\sin^2 w\) thỏa điều kiện PL trên toàn \(\mathbb{R}\) nhưng không lồi. Ngoài ra, PL trên tập \(\mathcal{W}\) không loại trừ sự tồn tại của điểm yên ngựa ngoài \(\mathcal{W}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính lồi mạnh kéo theo PL.&lt;/strong&gt; Nếu \(F\) là \(\mu\)-lồi mạnh và khả vi, bất đẳng thức chuẩn của hàm lồi mạnh suy ra \(\|\nabla F(w)\|_2^2\ge 2\mu(F(w)-F^\star)\), tức \(F\) thỏa điều kiện PL với cùng tham số \(\mu\). Chiều ngược lại không đúng; và điểm cốt lõi là phép chứng minh hội tụ tuyến tính ở &lt;a href=&quot;/contents/vi/chapter06/06_03_04_convergence_analysis_under_strong_convexity/&quot;&gt;06-03-04&lt;/a&gt; thực chất chỉ cần kết hợp bổ đề hạ (descent lemma) với bất đẳng thức PL.&lt;/p&gt;

&lt;h2 id=&quot;hội-tụ-tuyến-tính-của-gradient-descent-dưới-điều-kiện-pl&quot;&gt;Hội tụ tuyến tính của Gradient Descent dưới điều kiện PL&lt;/h2&gt;

&lt;p&gt;Giả sử \(\nabla F\) liên tục \(L\)-Lipschitz và \(F\) thỏa PL với hằng số \(\mu\). Theo bổ đề hạ (mục 06-03-01), với kích thước bước \(\eta\in(0,1/L]\):&lt;/p&gt;

\[F(w-\eta\nabla F(w))\le F(w)-\eta\bigl(1-\tfrac{L\eta}{2}\bigr)\|\nabla F(w)\|_2^2.\]

&lt;p&gt;Chọn \(\eta=1/L\) và áp dụng trực tiếp bất đẳng thức PL:&lt;/p&gt;

\[F(w_{k+1})-F^\star
\le F(w_k)-F^\star-\frac{1}{2L}\|\nabla F(w_k)\|_2^2
\le\Bigl(1-\frac{\mu}{L}\Bigr)\bigl(F(w_k)-F^\star\bigr).\]

&lt;p&gt;Ta thu được ngay tốc độ hội tụ tuyến tính \(F(w_k)-F^\star\le(1-\mu/L)^k(F(w_0)-F^\star)\) tương tự trường hợp lồi mạnh ở Chương 06 &lt;strong&gt;mà không dùng bất kỳ giả thiết lồi nào&lt;/strong&gt;. Karimi và cộng sự cũng mở rộng cùng lược đồ chứng minh này (“bổ đề hạ + PL ⇒ co sai số tối ưu”) cho proximal gradient, coordinate descent và gradient descent có chiếu.&lt;/p&gt;

&lt;p&gt;Đối với SGD, cần thêm giả thiết nhiễu &lt;em&gt;triệt tiêu tại cực tiểu&lt;/em&gt; (ví dụ điều kiện nội suy/quá tham số hóa \(\mathbb{E}[\|\nabla f_I(w)\|_2^2]\le C\|\nabla F(w)\|_2^2\)) để bước hằng nhỏ tiếp tục co theo kỳ vọng. Nếu sàn nhiễu vẫn dương, SGD quay lại giới hạn \(O(1/\sqrt{T})\) ở &lt;a href=&quot;/contents/vi/chapter26/26_01_sgd_and_minibatch/&quot;&gt;26-01&lt;/a&gt;. Trong khi giảm phương sai (&lt;a href=&quot;/contents/vi/chapter26/26_05_variance_reduction/&quot;&gt;26-05&lt;/a&gt;) khôi phục tốc độ tuyến tính trên tổng hữu hạn &lt;em&gt;lồi&lt;/em&gt; bằng cách triệt tiêu sàn nhiễu, điều kiện PL mang lại cơ sở lý thuyết tương tự ở phạm vi cục bộ cho bài toán &lt;em&gt;không lồi&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;nơi-điều-kiện-pl-xuất-hiện-trong-khoa-học-dữ-liệu&quot;&gt;Nơi điều kiện PL xuất hiện trong khoa học dữ liệu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bình phương tối thiểu quá tham số hóa:&lt;/strong&gt; Xét \(F(w)=\frac{1}{2n}\|Xw-y\|_2^2\) với \(X\in\mathbb{R}^{n\times d}\), \(d\ge n\) và \(X\) đủ hạng hàng. Mọi nghiệm nội suy đều là cực tiểu toàn cục; ma trận Hessian \(X^\top X/n\) chỉ nửa xác định dương (nên \(F\) không lồi mạnh). Tuy nhiên, \(F\) thỏa điều kiện PL trên toàn không gian với \(\mu\) bằng trị riêng &lt;em&gt;khác không&lt;/em&gt; nhỏ nhất của \(X^\top X/n\). Nhờ đó, gradient descent từ mọi điểm khởi tạo đều hội tụ tuyến tính về một nghiệm nội suy (được xác định bởi thiên kiến ẩn ở mục 28-03) với hệ số co \(1-\mu/L\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mạng nơ-ron rộng (cục bộ):&lt;/strong&gt; Trong một số chế độ đặc trưng ngẫu nhiên và nhân tiếp tuyến thần kinh (NTK), hàm mất mát thỏa điều kiện PL &lt;em&gt;cục bộ&lt;/em&gt; trong lân cận điểm khởi tạo hoặc quanh đa tạp nội suy. Đây là nội dung toán học chính xác của nhận định rằng quá tham số hóa làm địa hình hàm mất mát thuận lợi hơn cho tối ưu bậc nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giới hạn áp dụng:&lt;/strong&gt; Một bài toán ERM không lồi, thiếu tham số hoặc có điều kiện xấu nhìn chung không thỏa PL. Ví dụ, mạng ReLU có các nơ-ron chết có thể xuất hiện vùng \(\nabla F=0\) với \(F&amp;gt;F^\star\). Do đó, chỉ nên viện dẫn điều kiện PL khi nêu rõ miền \(\mathcal{W}\) và giả thiết chứng minh tương ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Tổng quan các tốc độ hội tụ chính.&lt;/strong&gt;
GD trên hàm lồi trơn: $$O(1/k)$$.
GD trên hàm lồi mạnh: tuyến tính, $$1-\Theta(m/L)$$ (06-03-04).
Nesterov / FISTA trên hàm lồi trơn: $$O(1/k^2)$$ (09-05, 26-02).
SGD trên hàm lồi Lipschitz: $$O(1/\sqrt{T})$$ (26-01).
SVRG / SAGA trên tổng hữu hạn lồi mạnh: tuyến tính theo số gradient thành phần (26-05).
Điều kiện PL (có thể không lồi): cùng tốc độ tuyến tính của GD như lồi mạnh, không đòi hỏi nghiệm duy nhất (bài này).
Học sâu không lồi, không thỏa PL: trọng tâm chuyển sang điểm yên ngựa và thiên kiến ẩn (28-01–28-03).
&lt;/div&gt;

&lt;h2 id=&quot;kiểm-tra-nhanh-bằng-python&quot;&gt;Kiểm tra nhanh bằng Python&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;pl_gap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;grad_sq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fstar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Trả về True nếu bất đẳng thức PL thỏa mãn tại điểm đang xét.&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grad_sq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fstar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# Bình phương tối thiểu quá tham số hóa: F(w) = 0.5/n ||Xw - y||^2
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;default_rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w_star&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_star&lt;/span&gt;                      &lt;span class=&quot;c1&quot;&gt;# tồn tại nghiệm nội suy chính xác
# mu = trị riêng khác không nhỏ nhất của X^T X / n
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;svd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;compute_uv&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Tham số PL trên range(X^T):&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;kappa&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Chọn một vector \(w\) ngẫu nhiên, tính \(F(w)\) và \(\|\nabla F(w)\|_2^2=\|X^\top(Xw-y)/n\|_2^2\) để kiểm tra bất đẳng thức PL, sau đó chạy GD với \(\eta=1/L\) để quan sát \(F(w_k)\) giảm theo tỉ lệ \(1-\mu/L\) trên một hàm không lồi mạnh.&lt;/p&gt;

&lt;h3 id=&quot;điều-kiện-pl-trong-khoảng-3-phút&quot;&gt;Điều kiện PL trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/pl-condition_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;w² + 3 sin² w không lồi nhưng thỏa PL, GD hội tụ tuyến tính dưới cận (1 − μ/L)ᵏ, w⁴ lồi mà không PL, và bình phương tối thiểu n = 20, d = 50 của bài.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Chứng minh rằng tính \(\mu\)-lồi mạnh kéo theo điều kiện PL với tham số \(\mu\). Kiểm chứng bằng số rằng hàm một chiều \(F(w)=w^2+3\sin^2 w\) vừa không lồi vừa thỏa điều kiện PL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với bài toán bình phương tối thiểu \(n=20, d=50\) ở trên, chạy GD từ hai điểm khởi tạo ngẫu nhiên khác nhau. Xác nhận cả hai đều đạt hàm mất mát huấn luyện gần bằng 0, hội tụ về hai nghiệm khác nhau, và đường sai số giảm tuyến tính trên đồ thị bán log (semilog). Giải thích vì sao điều này hoàn toàn tương thích với việc PL không đòi hỏi nghiệm cực tiểu duy nhất.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Nếu một mạng nơ-ron sâu chỉ thỏa điều kiện PL &lt;em&gt;cục bộ&lt;/em&gt; quanh đa tạp nội suy, thì yếu tố nào của Chương 28 (điểm yên ngựa, quá tham số hóa hay thiên kiến ẩn) vẫn quyết định nghiệm nội suy mà SGD chọn, và vì sao tốc độ hội tụ PL không tự đảm bảo sai số kiểm tra nhỏ?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;H. Karimi, J. Nutini, and M. Schmidt, “Linear Convergence of Gradient and Proximal-Gradient Methods under the Polyak–Łojasiewicz Condition,” &lt;a href=&quot;https://arxiv.org/abs/1608.04636&quot;&gt;arXiv:1608.04636&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;B. T. Polyak, &lt;em&gt;Gradient methods for minimizing functionals&lt;/em&gt; (1963); S. Łojasiewicz, &lt;em&gt;Une propriété topologique des sous-ensembles analytiques réels&lt;/em&gt; (1963) — nguồn cổ điển của bất đẳng thức.&lt;/li&gt;
  &lt;li&gt;Chương 06 (06-03-04) cho tổ tiên lồi mạnh; Chương 26 cho SGD / SVRG; 28-03 cho phong cảnh quá tham số mà tốc độ này ngồi lên.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>27-05 Tối ưu hai mức và siêu gradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_05_bilevel_hypergrad/"/>
   <updated>2026-09-18T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_05_bilevel_hypergrad</id>
   <content type="html">&lt;p&gt;Ở các bài trước, ta học cách lấy đạo hàm của hàm mất mát theo trọng số \(w\) với tốc độ học \(\eta\) và hệ số phạt \(\lambda\) cố định. Nhưng câu hỏi lớn tiếp theo trong thực hành học máy là: &lt;em&gt;làm sao tự động tối ưu chính các siêu tham số \(\lambda\) (như hệ số chính quy hóa, trọng số dữ liệu, hay kiến trúc mạng) bằng gradient thay vì mò mẫm bằng tìm kiếm lưới (grid search)?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Đó chính là thế giới của &lt;strong&gt;Tối ưu hai mức (Bilevel Optimization)&lt;/strong&gt; và &lt;strong&gt;Siêu gradient (Hypergradient)&lt;/strong&gt;: bản thân nghiệm tối ưu \(w^\star(\lambda)\) của bài toán huấn luyện bên trong lại là một hàm số phụ thuộc vào \(\lambda\), và ta cần kéo đạo hàm của hàm mất mát kiểm định bên ngoài &lt;em&gt;xuyên qua&lt;/em&gt; cả một quy trình tối ưu hóa bên trong!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-tối-ưu-hai-mức-và-siêu-gradient&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của Tối ưu hai mức và Siêu gradient&lt;/h2&gt;

&lt;p&gt;Hai phương pháp tính siêu gradient trong bài học này dựa trên ba trụ cột toán học sâu sắc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc lồng nhau (Upper-Level vs. Lower-Level):&lt;/strong&gt; Bài toán ngoài cực tiểu hóa rủi ro kiểm định \(F(w^\star(\lambda), \lambda)\) theo siêu tham số \(\lambda\), bị ràng buộc bởi điều kiện \(w^\star(\lambda) \in \arg\min_w L(w, \lambda)\) của bài toán huấn luyện trong. Tổng đạo hàm gồm hai nhánh: tác động trực tiếp \(\nabla_\lambda F\) và tác động gián tiếp \(\bigl(\frac{\partial w^\star}{\partial \lambda}\bigr)^T \nabla_w F\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vi phân ẩn bằng Định lý Hàm ẩn (Implicit Differentiation):&lt;/strong&gt; Tại nghiệm tối ưu trong, \(\nabla_w L(w^\star(\lambda), \lambda) = 0\). Lấy đạo hàm hai vế theo \(\lambda\) cho ta hệ phương trình tuyến tính \(\nabla_{ww}^2 L \cdot \frac{\partial w^\star}{\partial \lambda} + \nabla_{w\lambda}^2 L = 0\). Điểm kỳ diệu là ta &lt;strong&gt;không cần lưu lịch sử vòng lặp huấn luyện trong&lt;/strong&gt; — chỉ cần giải hệ tuyến tính (bằng Conjugate Gradient + HVP) ngay tại điểm hội tụ \(w^\star\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trải phẳng vòng lặp (Unrolling / Differentiating through Optimization):&lt;/strong&gt; Nếu bài toán trong chỉ chạy \(K\) bước SGD/GD, ta coi cả \(K\) bước đó như một đồ thị tính toán lớn rồi chạy AD chiều nghịch xuyên qua tất cả \(K\) bước. Dễ cài bằng PyTorch/JAX khi \(K\) nhỏ (như MAML trong meta-learning), nhưng bộ nhớ tăng tuyến tính theo \(K\) và dễ mất ổn định khi \(K\) lớn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-siêu-gradient-bằng-định-lý-hàm-ẩn-cho-hồi-quy-ridge&quot;&gt;Giải thích: Tính tay Siêu gradient bằng Định lý Hàm ẩn cho Hồi quy Ridge&lt;/h3&gt;

&lt;p&gt;Xét bài toán hai mức 1 chiều cực kỳ trong sáng: chọn hệ số phạt \(\lambda &amp;gt; 0\) để cực tiểu hóa mất mát kiểm định (ngoài) \(F(w) = \frac{1}{2}(w - 2)^2\), trong khi bài toán huấn luyện (trong) là hồi quy Ridge:&lt;/p&gt;

\[w^\star(\lambda) = \arg\min_{w \in \mathbb{R}}\ L(w, \lambda) = \arg\min_w \left[\frac{1}{2}(w - 4)^2 + \frac{\lambda}{2} w^2\right].\]

&lt;p&gt;Hãy tính siêu gradient \(\frac{dF(w^\star(\lambda))}{d\lambda}\) tại điểm thử hiện tại \(\lambda = 3\) bằng &lt;strong&gt;Định lý Hàm ẩn&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán trong tại \(\lambda = 3\):&lt;/strong&gt;
Điều kiện tối ưu bậc nhất \(\nabla_w L(w, \lambda) = (w - 4) + \lambda w = 0 \implies w^\star(\lambda) = \frac{4}{1 + \lambda}\).
Tại \(\lambda = 3\), ta nhận được \(w^\star(3) = \frac{4}{1 + 3} = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính các đạo hàm bậc hai cục bộ của \(L\) tại \((w^\star, \lambda) = (1, 3)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hessian theo \(w\): \(\nabla_{ww}^2 L = 1 + \lambda = 1 + 3 = 4\).&lt;/li&gt;
      &lt;li&gt;Đạo hàm hỗn hợp theo \(w, \lambda\): \(\nabla_{w\lambda}^2 L = w^\star = 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng Định lý Hàm ẩn tìm độ nhạy \(\frac{dw^\star}{d\lambda}\):&lt;/strong&gt;
\(\frac{dw^\star}{d\lambda} = -\bigl(\nabla_{ww}^2 L\bigr)^{-1} \nabla_{w\lambda}^2 L = -\frac{1}{4} = -0.25.\)
(Kiểm tra trực tiếp từ công thức đóng \(w^\star(\lambda) = 4(1+\lambda)^{-1}\): đạo hàm là \(-4(1+3)^{-2} = -4/16 = -0.25\) — khớp tuyệt đối!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng quy tắc dây chuyền ra Siêu gradient:&lt;/strong&gt;
Vì \(\nabla_w F(w^\star) = w^\star - 2 = 1 - 2 = -1\) và \(\nabla_\lambda F = 0\):
\(\frac{dF}{d\lambda}\Big|_{\lambda=3} = \nabla_w F(w^\star) \cdot \frac{dw^\star}{d\lambda} = (-1)(-0.25) = +0.25 &amp;gt; 0.\)
&lt;strong&gt;Ý nghĩa trực giác:&lt;/strong&gt; Siêu gradient dương (\(+0.25\)) báo ngay cho ta biết phải &lt;strong&gt;giảm \(\lambda\)&lt;/strong&gt; xuống để hạ mất mát kiểm định \(F\) — hoàn toàn đúng vì giảm \(\lambda\) từ \(3\) về \(1\) sẽ đẩy \(w^\star\) từ \(1\) lên đúng đích kiểm định \(w^\star(1) = 2\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các Chương 26–27 xét bài toán huấn luyện mô hình bằng cách lấy đạo hàm một hàm mất mát &lt;em&gt;đơn&lt;/em&gt; theo vector trọng số. Tuy nhiên, nhiều bài toán học máy hiện đại lại có cấu trúc tối ưu &lt;strong&gt;lồng nhau (hai mức)&lt;/strong&gt;: bản thân trọng số \(w^\star(\lambda)\) là nghiệm của một bài toán tối ưu bên trong phụ thuộc vào siêu tham số \(\lambda\), và ta cần lấy đạo hàm của mục tiêu &lt;em&gt;bên ngoài&lt;/em&gt; xuyên qua nghiệm đó. Bài đọc tùy chọn này giới thiệu khuôn khổ tối ưu hai mức (bilevel optimization) và khái niệm &lt;strong&gt;siêu gradient (hypergradient)&lt;/strong&gt; — bổ sung ứng dụng cho AD ở các mục 27-01 đến 27-03.&lt;/p&gt;

&lt;p&gt;Tài liệu tham khảo chính gồm bài tổng quan của Chen, Chen, Jiang, Ye, Wang, Yang, Poor và Wang (&lt;em&gt;A Whole New World, but How? A Survey of Bilevel Optimization and Applications&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2405.04996&quot;&gt;arXiv:2405.04996&lt;/a&gt;, 2024), bài báo nền tảng về định lý hàm ẩn của Bengio (&lt;em&gt;Gradient-Based Optimization of Hyperparameters&lt;/em&gt;, 2000) và cách tiếp cận cho học sâu của Franceschi, Frasconi, Salzo, Grazzi và Pontil (ICML 2018).&lt;/p&gt;

&lt;h2 id=&quot;khuôn-khổ-bài-toán-lồng-nhau&quot;&gt;Khuôn khổ bài toán lồng nhau&lt;/h2&gt;

&lt;p&gt;Một bài toán tối ưu &lt;strong&gt;hai mức (bilevel)&lt;/strong&gt; có dạng tổng quát:&lt;/p&gt;

\[\begin{align}
\min_{\lambda}\quad &amp;amp; F\bigl(w^\star(\lambda),\lambda\bigr)\\
\text{s.t.}\quad &amp;amp; w^\star(\lambda)\in\arg\min_w\, L(w,\lambda).
\end{align}\]

&lt;p&gt;Bài toán &lt;strong&gt;bên trong&lt;/strong&gt; tương ứng với quá trình huấn luyện thông thường: \(L\) là hàm mất mát huấn luyện, \(w\) là trọng số mô hình, còn \(\lambda\) là siêu tham số tác động vào bài toán trong (tốc độ học, hệ số suy giảm trọng số, trọng số mẫu dữ liệu hoặc điểm khởi tạo cho vài bước cập nhật). Hàm mục tiêu &lt;strong&gt;bên ngoài&lt;/strong&gt; \(F\) thường là hàm mất mát trên tập kiểm định (validation loss), tiêu chí công bằng hoặc mất mát trên tác vụ mới. Đạo hàm toàn phần \(\nabla_\lambda F(w^\star(\lambda),\lambda)\) được gọi là &lt;strong&gt;siêu gradient (hypergradient)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Cấu trúc này xuất hiện dưới nhiều tên gọi quen thuộc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu siêu tham số (HPO):&lt;/strong&gt; \(\lambda\) là hệ số chính quy hóa hoặc tốc độ học; \(F\) là hàm mất mát kiểm định. Tìm kiếm lưới (grid search) không lấy đạo hàm xuyên qua \(w^\star\), còn phương pháp siêu gradient tối ưu trực tiếp theo \(\lambda\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học siêu cấp (Meta-learning / MAML):&lt;/strong&gt; Mỗi tác vụ thực hiện vài bước SGD bên trong xuất phát từ điểm khởi tạo chung \(\lambda\); hàm mất mát ngoài đo hiệu năng sau các bước thích nghi đó (Finn, Abbeel &amp;amp; Levine, ICML 2017).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chưng cất dữ liệu và học bộ tối ưu:&lt;/strong&gt; Vòng trong chạy vài bước gradient descent; biến ngoài là tập dữ liệu tổng hợp hoặc chính tham số của bộ tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các lớp ẩn (Implicit layers):&lt;/strong&gt; Nghiệm cân bằng \(w=\Phi(w,\lambda)\) là một điểm bất động bên trong; mô hình Deep Equilibrium (DEQ) lấy đạo hàm xuyên qua điểm bất động này bằng tích vector–Jacobian.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;hai-cách-tính-siêu-gradient&quot;&gt;Hai cách tính siêu gradient&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Khai triển vòng lặp (Unrolling).&lt;/strong&gt; Thay nghiệm chính xác \(w^\star(\lambda)\) bằng kết quả sau \(T\) bước của một bộ giải khả vi, \(w_{t+1}=w_t-\eta\nabla_w L(w_t,\lambda)\), rồi lan truyền ngược qua toàn bộ chuỗi \(T\) bước đó. AD chiều nghịch (27-03) tính \(\nabla_\lambda F\) với chi phí thời gian và bộ nhớ tăng tuyến tính theo \(T\) (tương tự lan truyền ngược theo thời gian trong RNN). Với \(T\) nhỏ (chẳng hạn bài toán học ít mẫu kiểu MAML), khai triển vòng lặp rất trực tiếp và hiệu quả.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vi phân ẩn (Implicit differentiation).&lt;/strong&gt; Nếu bài toán trong trơn và ma trận Hessian \(H=\nabla_{ww}^2 L(w^\star,\lambda)\) khả nghịch tại nghiệm \(w^\star\), định lý hàm ẩn cho:&lt;/p&gt;

\[\frac{\mathrm{d}w^\star}{\mathrm{d}\lambda}
=-H^{-1}\nabla_{w\lambda}^2 L(w^\star,\lambda),\]

&lt;p&gt;suy ra siêu gradient có dạng:&lt;/p&gt;

\[\nabla_\lambda F
=\nabla_\lambda F\big|_{\text{tường minh}}
-\bigl(\nabla_{w\lambda}^2 L\bigr)^\top H^{-1}\nabla_w F.\]

&lt;p&gt;Trong thực tế, ta không tạo tường minh ma trận nghịch đảo \(H^{-1}\) mà giải hệ tuyến tính \(H\,v=\nabla_w F\) bằng phương pháp gradient liên hợp (dùng tích Hessian–vector qua AD thuận-trên-nghịch ở mục 27-03), sau đó nhân với đạo hàm riêng hỗn hợp \(\nabla_{w\lambda}^2 L\). Lorraine, Vicol và Duvenaud (ICML 2020, &lt;em&gt;Optimizing Millions of Hyperparameters by Implicit Differentiation&lt;/em&gt;) áp dụng cách này cho bài toán HPO quy mô lớn. Giả thiết \(H\) khả nghịch tại nghiệm tối ưu chính xác là điều kiện cần lưu ý: nó phù hợp với bài toán trong lồi mạnh giải đến hội tụ, còn với mạng nơ-ron không lồi thường dừng sớm sau ít bước, khai triển vòng lặp phản ánh trung thực hơn quy trình thực tế đã chạy.&lt;/p&gt;

&lt;p&gt;Các kỹ thuật vi phân ẩn xấp xỉ (như gradient liên hợp cắt cụt hoặc chuỗi Neumann) nằm trung gian giữa hai cách tiếp cận trên.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Khi nào dùng khai triển vòng lặp, khi nào dùng vi phân ẩn.&lt;/strong&gt;
Khi vòng trong ngắn, không lồi, hoặc bản thân thuật toán tối ưu là một phần của mô hình (MAML, học bộ tối ưu): dùng khai triển vòng lặp.
Khi vòng trong dài, lồi mạnh và số lượng siêu tham số lớn: dùng vi phân ẩn kết hợp gradient liên hợp.
Không nên vi phân xuyên qua toàn bộ quá trình tiền huấn luyện AdamW của một mô hình ngôn ngữ lớn bằng cả hai cách trên; hãy dùng bài toán đại diện nhẹ hơn (tinh chỉnh ngắn, lớp tuyến tính trên cùng hoặc tập con dữ liệu).
&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-siêu-gradient-theo-tốc-độ-học-sau-một-bước&quot;&gt;Ví dụ: siêu gradient theo tốc độ học sau một bước&lt;/h2&gt;

&lt;p&gt;Ví dụ đơn giản nhất là bài toán trong dạng bậc hai với siêu tham số vô hướng là tốc độ học \(\lambda=\eta\). Một bước gradient descent từ \(w_0\) cho \(w_1(\eta)=w_0-\eta\nabla L(w_0)\). Với hàm mất mát ngoài \(F(w_1)=\tfrac12\|w_1-w_{\mathrm{val}}\|_2^2\), ta tính được siêu gradient \(\mathrm{d}F/\mathrm{d}\eta\) trực tiếp bằng quy tắc dây chuyền:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;one_step_hypergrad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Trong: một bước GD trên 0.5 w^T A w - b^T w. Ngoài: 0.5 ||w1 - w_val||^2.&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# d w1 / d eta = -g ; hypergrad = (w1 - w_val)^T dw1/deta
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;hyper&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hyper&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;diag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;10.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w_val&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;# lấy nghiệm tối ưu làm mục tiêu kiểm định
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dF&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;one_step_hypergrad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.05&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_val&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;siêu gradient dF/deta&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Giá trị siêu gradient âm cho biết hàm mất mát kiểm định sẽ giảm nếu ta &lt;em&gt;tăng&lt;/em&gt; \(\eta\). Khi \(T&amp;gt;1\) hoặc khi \(L\) là mạng nơ-ron, AD chiều nghịch (PyTorch hoặc JAX) tự động thực hiện đúng cùng phép tính quy tắc dây chuyền này dọc theo băng tính toán.&lt;/p&gt;

&lt;p&gt;Nếu xét nghiệm tối ưu &lt;em&gt;chính xác&lt;/em&gt; của bài toán hồi quy ridge \(L(w,\lambda)=\tfrac12\|Xw-y\|_2^2+\frac{\lambda}{2}\|w\|_2^2\) với hàm mất mát ngoài trên tập kiểm định, vi phân ẩn dẫn tới hệ tuyến tính \((X^\top X+\lambda I)v=\nabla_w F\) — chính là hệ phương trình tuyến tính quen thuộc của hồi quy ridge ở Chương 05.&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-cần-nắm&quot;&gt;Mục tiêu cần nắm&lt;/h2&gt;

&lt;p&gt;Sau bài này, bạn cần: (i) viết được dạng tối ưu hai mức cho HPO và MAML một bước; (ii) giải thích được vì sao AD chiều nghịch trên vòng trong khai triển cho ra siêu gradient; (iii) viết được công thức vi phân ẩn và nhận diện hệ phương trình tuyến tính chứa Hessian; và (iv) nhận thức được giới hạn chi phí để không áp dụng khai triển cho quá trình tiền huấn luyện mô hình lớn. Tài liệu đọc thêm (không kiểm tra): Maclaurin, Duvenaud &amp;amp; Adams (2015) về đảo ngược SGD cho HPO; Rajeswaran, Finn, Kakade &amp;amp; Levine (ICML 2019) về MAML ẩn; khảo sát Chen và cộng sự (2024).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Suy ra \(\mathrm{d}w_1/\mathrm{d}\eta=-\nabla L(w_0)\) cho một bước GD và tính siêu gradient của \(F(w_1)=\tfrac12\|w_1-w_{\mathrm{val}}\|_2^2\). Sau đó tự tính cho hai bước (\(T=2\)) và đối chiếu với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.autograd&lt;/code&gt; trên cùng hàm bậc hai.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với bài toán hồi quy ridge \(L(w,\lambda)=\tfrac12\|Xw-y\|_2^2+\frac{\lambda}{2}\|w\|_2^2\) và hàm mất mát ngoài trên tập kiểm định, hãy viết biểu thức siêu gradient ẩn và tính nó bằng cách giải \((X^\top X+\lambda I)v=\nabla_w F\). So sánh kết quả này với siêu gradient khai triển sau &lt;em&gt;một&lt;/em&gt; bước GD: khi nào hai giá trị sai lệch, và giá trị nào phản ánh đúng quy trình chỉ chạy \(T\) bước?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; AD chế độ hỗn hợp ở mục 27-03 tính tích Hessian–vector với chi phí tương đương một lượt tính gradient. Phép tính đó xuất hiện ở &lt;em&gt;vị trí nào&lt;/em&gt; trong công thức siêu gradient ẩn, và vì sao nó cho phép Lorraine và cộng sự mở rộng lên hàng triệu siêu tham số?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Y. Bengio, “Gradient-Based Optimization of Hyperparameters,” &lt;em&gt;Neural Computation&lt;/em&gt;, 2000.&lt;/li&gt;
  &lt;li&gt;L. Franceschi, P. Frasconi, S. Salzo, R. Grazzi, and M. Pontil, “Bilevel Programming for Hyperparameter Optimization and Meta-Learning,” ICML 2018.&lt;/li&gt;
  &lt;li&gt;J. Lorraine, P. Vicol, and D. Duvenaud, “Optimizing Millions of Hyperparameters by Implicit Differentiation,” ICML 2020.&lt;/li&gt;
  &lt;li&gt;C. Finn, P. Abbeel, and S. Levine, “Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks,” ICML 2017.&lt;/li&gt;
  &lt;li&gt;C. Chen et al., “A Whole New World, but How?,” &lt;a href=&quot;https://arxiv.org/abs/2405.04996&quot;&gt;arXiv:2405.04996&lt;/a&gt;, 2024.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>28-05 The PL condition and modern rates</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_05_pl_condition/"/>
   <updated>2026-09-18T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_05_pl_condition</id>
   <content type="html">&lt;p&gt;For decades, proving fast linear convergence \(F(w_k) - F^\star \le c^k (F(w_0) - F^\star)\) for gradient descent seemed to require strong convexity—an assumption that fails immediately for overparameterized least squares, logistic regression, matrix factorization, and every neural network ever trained! In 2016, Hamed Karimi, Julie Nutini, and Mark Schmidt revived a 1963 inequality due to Boris Polyak and Stanisław Łojasiewicz—the &lt;strong&gt;PL condition&lt;/strong&gt;—and proved in &lt;strong&gt;five lines of algebra&lt;/strong&gt; that gradient descent converges linearly under PL even when the objective is completely &lt;strong&gt;nonconvex&lt;/strong&gt; and has infinitely many global minima.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-gradient-dominance-and-linear-rates-without-convexity&quot;&gt;Key ideas: Gradient Dominance and Linear Rates Without Convexity&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;The Polyak–Łojasiewicz (PL) Inequality:&lt;/strong&gt; A smooth function \(F\) satisfies \(\mu\)-PL if \(\frac{1}{2}\|\nabla F(w)\|_2^2 \ge \mu \bigl(F(w) - F^\star\bigr)\) for all \(w\). Intuitively, whenever you are still above the global minimum \(F^\star\), the gradient cannot vanish—forcing every stationary point to be globally optimal!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strictly Weaker Than Strong Convexity:&lt;/strong&gt; Every \(\mu\)-strongly convex function is \(\mu\)-PL, but the converse is false: \(F(w) = \frac{1}{2}\|Xw - y\|_2^2\) with rank-deficient \(X\) (overparameterized least squares) is &lt;em&gt;not&lt;/em&gt; strongly convex (its Hessian has zero eigenvalues!), yet it satisfies PL with \(\mu = \lambda_{\min}^+(X^\top X) &amp;gt; 0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The 5-Line Linear Convergence Proof:&lt;/strong&gt; Combining \(L\)-smoothness descent \(F(w_{k+1}) \le F(w_k) - \frac{1}{2L}\|\nabla F(w_k)\|_2^2\) (at \(\eta = 1/L\)) directly with \(\|\nabla F(w_k)\|_2^2 \ge 2\mu(F(w_k) - F^\star)\) yields
\(F(w_{k+1}) - F^\star \le \left(1 - \frac{\mu}{L}\right)\bigl(F(w_k) - F^\star\bigr).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;What PL Does NOT Require:&lt;/strong&gt; PL allows nonconvexity, non-unique minima, and flat zero-curvature directions along the solution manifold—making it the gold-standard modern regularity condition for overparameterized ML.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-pl-on-a-nonconvex-function-and-checking-one-gd-step&quot;&gt;Worked example: Verifying PL on a Nonconvex Function and Checking One GD Step&lt;/h3&gt;

&lt;p&gt;Consider the classic Karimi–Nutini–Schmidt nonconvex 1D example:
\(F(w) = w^2 + 3\sin^2(w).\)
Clearly \(F^\star = F(0) = 0\), and \(F&apos;&apos;(w) = 2 + 6\cos(2w)\) becomes negative at \(w = \pi/2\) (\(F&apos;&apos;(\pi/2) = 2 - 6 = -4 &amp;lt; 0\)), so \(F\) is &lt;strong&gt;strictly nonconvex&lt;/strong&gt;!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the derivative:&lt;/strong&gt;
\(F&apos;(w) = 2w + 6\sin(w)\cos(w) = 2w + 3\sin(2w).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the PL inequality at \(w = \pi/2\) (right where convexity fails!):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Suboptimality: \(F(\pi/2) - F^\star = \left(\frac{\pi}{2}\right)^2 + 3(1)^2 \approx 2.467 + 3 = 5.467\).&lt;/li&gt;
      &lt;li&gt;Gradient at \(w = \pi/2\): \(F&apos;(\pi/2) = \pi + 3\sin(\pi) = \pi \approx 3.1416\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Ratio $$\frac{\frac{1}{2}&lt;/td&gt;
              &lt;td&gt;F’(\pi/2)&lt;/td&gt;
              &lt;td&gt;^2}{F(\pi/2) - F^\star} = \frac{\frac{1}{2}\pi^2}{5.467} \approx \frac{4.935}{5.467} \approx 0.903 &amp;gt; 0$$!&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;In fact, one can prove \(F\) satisfies \(\mu\)-PL globally (with \(\mu \approx 1/32\)) and \(L\)-smoothness with $$L = \max_w&lt;/td&gt;
              &lt;td&gt;2 + 6\cos(2w)&lt;/td&gt;
              &lt;td&gt;= 8$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take one GD step from \(w_0 = \pi/2 \approx 1.5708\) with \(\eta = 1/L = 1/8 = 0.125\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(w_1 = 1.5708 - 0.125(3.1416) = 1.1781\).&lt;/li&gt;
      &lt;li&gt;\(F(w_1) = (1.1781)^2 + 3\sin^2(1.1781) \approx 1.388 + 3(0.8536) = 3.949 &amp;lt; 5.467\)!
Even starting at a point of &lt;em&gt;negative curvature&lt;/em&gt;, PL guarantees monotonic geometric descent straight to the global optimum \(w^\star = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chapter 06 proved a linear rate for gradient descent under &lt;strong&gt;strong convexity&lt;/strong&gt;: \(F(w_k)-F^\star\le c^k(F(w_0)-F^\star)\) with \(c=1-\Theta(m/L)\). Deep-learning losses are not strongly convex — they are not even convex — yet practitioners still see training curves that look linear on a log plot once the net is wide enough to interpolate. The &lt;strong&gt;Polyak–Łojasiewicz (PL)&lt;/strong&gt; inequality is the cheapest assumption that lets you &lt;em&gt;reuse the Chapter 06 proof&lt;/em&gt; on some of those nonconvex empirical risks. This optional lesson is the bridge; it does not replace 06-03-04, and it does not re-do the saddle taxonomy of 28-01.&lt;/p&gt;

&lt;p&gt;The note to keep on the desk is Karimi, Nutini, and Schmidt, &lt;em&gt;Linear Convergence of Gradient and Proximal-Gradient Methods under the Polyak–Łojasiewicz Condition&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/1608.04636&quot;&gt;arXiv:1608.04636&lt;/a&gt; (a short version appeared at ECML 2016).&lt;/p&gt;

&lt;h2 id=&quot;the-inequality-and-what-it-does-not-say&quot;&gt;The inequality, and what it does &lt;em&gt;not&lt;/em&gt; say&lt;/h2&gt;

&lt;p&gt;\(F\) is &lt;strong&gt;PL&lt;/strong&gt; with parameter \(\mu&amp;gt;0\) on a set \(\mathcal{W}\) if, for every \(w\in\mathcal{W}\),&lt;/p&gt;

\[\tfrac12\|\nabla F(w)\|_2^2\ge\mu\bigl(F(w)-F^\star\bigr),\]

&lt;p&gt;where \(F^\star=\inf F\) (assumed attained). Gradient vanishing forces the optimality gap to vanish: every critical point in \(\mathcal{W}\) is a &lt;em&gt;global&lt;/em&gt; minimizer. That is already a landscape statement — no spurious local minima inside the set — without convexity.&lt;/p&gt;

&lt;p&gt;PL does &lt;strong&gt;not&lt;/strong&gt; give a unique minimizer. The set \(\{w:F(w)=F^\star\}\) can be a huge affine space; overparameterized least squares is the textbook example. It does &lt;strong&gt;not&lt;/strong&gt; imply convexity: \(F(w)=w^2+3\sin^2 w\) is a standard one-dimensional PL function that is not convex. It does &lt;strong&gt;not&lt;/strong&gt; certify saddles outside \(\mathcal{W}\); you still need 28-01–28-02 for the high-dimensional saddle story.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strong convexity implies PL.&lt;/strong&gt; If \(F\) is \(\mu\)-strongly convex and differentiable, the standard three-point identity yields \(\|\nabla F(w)\|_2^2\ge 2\mu(F(w)-F^\star)\), which is PL with the same \(\mu\). The converse is false, and that is the whole point of the lesson: the &lt;em&gt;rate&lt;/em&gt; you proved in &lt;a href=&quot;/contents/en/chapter06/06_03_04_convergence_analysis_under_strong_convexity/&quot;&gt;06-03-04&lt;/a&gt; needed a quadratic lower bound on \(F\), but the &lt;em&gt;algebra of the descent lemma&lt;/em&gt; only used PL.&lt;/p&gt;

&lt;h2 id=&quot;gradient-descent-under-pl-the-karimi-reuse&quot;&gt;Gradient descent under PL (the Karimi reuse)&lt;/h2&gt;

&lt;p&gt;Assume \(\nabla F\) is \(L\)-Lipschitz and \(F\) is PL-\(\mu\). The descent lemma with step \(\eta\in(0,1/L]\) is the same sentence as in 06-03-01,&lt;/p&gt;

\[F(w-\eta\nabla F(w))\le F(w)-\eta\bigl(1-\tfrac{L\eta}{2}\bigr)\|\nabla F(w)\|_2^2.\]

&lt;p&gt;Plug in \(\eta=1/L\) and the PL inequality:&lt;/p&gt;

\[F(w_{k+1})-F^\star
\le F(w_k)-F^\star-\frac{1}{2L}\|\nabla F(w_k)\|_2^2
\le\Bigl(1-\frac{\mu}{L}\Bigr)\bigl(F(w_k)-F^\star\bigr).\]

&lt;p&gt;That is linear convergence \(F(w_k)-F^\star\le(1-\mu/L)^k(F(w_0)-F^\star)\), with the same condition-number flavour as Chapter 06, &lt;strong&gt;and we never used convexity&lt;/strong&gt;. Proximal gradient, coordinate descent, and a projected step have the same reuse in Karimi et al.; the pattern is always “descent lemma + PL ⇒ contract the gap.”&lt;/p&gt;

&lt;p&gt;SGD needs an extra hypothesis: the noise must &lt;em&gt;die at minimizers&lt;/em&gt;, or you must average. If \(\mathbb{E}[\|\nabla f_I(w)\|_2^2]\le C\|\nabla F(w)\|_2^2\) (a strong but standard “interpolation / overparameterized” bound), then a small constant step still contracts in expectation. If the noise floor stays positive, you recover the familiar \(O(1/\sqrt{T})\) ball of &lt;a href=&quot;/contents/en/chapter26/26_01_sgd_and_minibatch/&quot;&gt;26-01&lt;/a&gt;. Variance reduction (&lt;a href=&quot;/contents/en/chapter26/26_05_variance_reduction/&quot;&gt;26-05&lt;/a&gt;) restores a linear rate on &lt;em&gt;convex&lt;/em&gt; finite sums by killing that floor; PL is what lets a &lt;em&gt;nonconvex&lt;/em&gt; finite sum hope for the same, locally.&lt;/p&gt;

&lt;h2 id=&quot;where-pl-actually-appears-in-data-science&quot;&gt;Where PL actually appears in data science&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Overparameterized least squares.&lt;/strong&gt; \(F(w)=\frac{1}{2n}\|Xw-y\|_2^2\) with \(X\in\mathbb{R}^{n\times d}\), \(d\ge n\), and \(X\) full row rank. Every interpolator is a global minimizer; the Hessian \(X^\top X/n\) is only positive &lt;em&gt;semidefinite&lt;/em&gt;. Nevertheless \(F\) satisfies PL on all of \(\mathbb{R}^d\) with \(\mu = \lambda_{\min}^{+}(X^\top X/n)\), the smallest &lt;em&gt;nonzero&lt;/em&gt; eigenvalue of that Hessian (equivalently, of \(XX^\top/n\)). Gradient descent from any start converges linearly to &lt;em&gt;some&lt;/em&gt; interpolator — the one selected by implicit bias (28-03) — and the Chapter 06 constant \(c=1-\mu/L\) is honest on that subspace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wide nets, locally.&lt;/strong&gt; In several random-feature and neural-tangent regimes the training loss is &lt;em&gt;locally&lt;/em&gt; PL in a neighbourhood of the initialization or of an interpolating manifold. That is the precise content of the slogan “overparameterization makes the landscape benign”: not “the loss is convex,” but “once you are close enough, PL holds and every nearby critical point interpolates.” Lesson 28-03 pointed at this inequality without proving the rate; now you have the rate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What PL is not.&lt;/strong&gt; A poorly conditioned, underparameterized, nonconvex ERM need not be PL. A ReLU net with dead units can have regions where \(\nabla F=0\) while \(F&amp;gt;F^\star\). Do not write “the network is PL” on an exam unless you name the set \(\mathcal{W}\) and the paper that justifies it.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;The modern rate story, in one ladder.&lt;/strong&gt;
Smooth convex GD: $$O(1/k)$$.
Strongly convex GD: linear, $$1-\Theta(m/L)$$ (06-03-04).
Nesterov / FISTA on smooth convex: $$O(1/k^2)$$ (09-05, 26-02).
SGD, convex Lipschitz: $$O(1/\sqrt{T})$$ (26-01).
SVRG / SAGA, strongly convex finite-sum: linear in incremental gradients (26-05).
PL, possibly nonconvex: the same linear GD rate as strong convexity, without uniqueness (this page).
Nonconvex DL without PL: saddles and implicit bias (28-01–28-03), not a rate you should quote.
&lt;/div&gt;

&lt;h2 id=&quot;a-two-line-check&quot;&gt;A two-line check&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;pl_gap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;grad_sq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fstar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Return True if the PL inequality holds at this point.&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grad_sq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fstar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# Overparameterized least squares: F(w) = 0.5/n ||Xw - y||^2
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;default_rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w_star&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_star&lt;/span&gt;                      &lt;span class=&quot;c1&quot;&gt;# interpolable
# mu = smallest nonzero eigenvalue of X^T X / n, on the row space
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;svd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;compute_uv&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;PL parameters on range(X^T):&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;kappa&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Pick a random \(w\), compute \(F(w)\) and \(\|\nabla F(w)\|_2^2= \|X^\top(Xw-y)/n\|_2^2\), and check the predicate. Then run GD with \(\eta=1/L\) and watch \(F(w_k)\) contract by about \(1-\mu/L\) per step — the 06-03-04 picture, now on a non-strongly-convex loss.&lt;/p&gt;

&lt;h3 id=&quot;the-pl-condition-in-about-3-minutes&quot;&gt;The PL condition in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/pl-condition_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;w² + 3 sin² w is nonconvex but PL, GD converges linearly under the (1 − μ/L)ᵏ bound, w⁴ is convex but not PL, and the lesson’s n = 20, d = 50 least squares.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Prove that \(\mu\)-strong convexity implies PL-\(\mu\). Give a one-dimensional \(F\) that is PL but not convex (you may use \(w^2+3\sin^2 w\) after checking the numbers).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; On the \(n=20\), \(d=50\) least-squares problem above, run GD from two random starts. Confirm both reach machine-zero train loss, that the two limits differ, and that each path’s gap plot is linear on a semilog axis. How is that compatible with “no unique minimizer”?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; If a deep net is only &lt;em&gt;locally&lt;/em&gt; PL near an interpolating manifold, which Chapter 28 object — saddles, overparameterization, or implicit bias — still decides &lt;em&gt;which&lt;/em&gt; interpolator SGD finds, and why is the PL rate silent on test error?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;H. Karimi, J. Nutini, and M. Schmidt, “Linear Convergence of Gradient and Proximal-Gradient Methods under the Polyak–Łojasiewicz Condition,” &lt;a href=&quot;https://arxiv.org/abs/1608.04636&quot;&gt;arXiv:1608.04636&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;B. T. Polyak, &lt;em&gt;Gradient methods for minimizing functionals&lt;/em&gt; (1963); S. Łojasiewicz, &lt;em&gt;Une propriété topologique des sous-ensembles analytiques réels&lt;/em&gt; (1963) — the classical sources of the inequality.&lt;/li&gt;
  &lt;li&gt;Chapter 06 (06-03-04) for the strongly convex ancestor; Chapter 26 for SGD / SVRG; 28-03 for the overparameterized landscape this rate sits on.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>27-05 Bilevel optimization and hypergradients</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_05_bilevel_hypergrad/"/>
   <updated>2026-09-18T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_05_bilevel_hypergrad</id>
   <content type="html">&lt;p&gt;Tuning a learning rate or regularization strength \(\lambda\) by grid search works for 2 hyperparameters, not 20,000. What if we could differentiate the &lt;em&gt;validation loss&lt;/em&gt; directly with respect to \(\lambda\) and run gradient descent on the hyperparameters themselves? That is &lt;strong&gt;bilevel optimization&lt;/strong&gt;: an outer loop minimizes \(L_{\text{val}}(w^\star(\lambda), \lambda)\) where the inner weights \(w^\star(\lambda) = \arg\min_w L_{\text{train}}(w, \lambda)\) are themselves the output of an optimization problem! Computing the &lt;strong&gt;hypergradient&lt;/strong&gt; \(\frac{d L_{\text{val}}}{d\lambda}\) via unrolling or the Implicit Function Theorem (IFT) unifies hyperparameter optimization, MAML meta-learning, and data valuation.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-bilevel-templates-unrolling-and-implicit-differentiation&quot;&gt;Key ideas: Bilevel Templates, Unrolling, and Implicit Differentiation&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;The Nested Bilevel Template:&lt;/strong&gt; Outer problem \(\min_\lambda F(\lambda) = L_{\text{val}}(w^\star(\lambda), \lambda)\) subject to \(w^\star(\lambda) = \arg\min_w L_{\text{train}}(w, \lambda)\). By the chain rule, \(\frac{d F}{d\lambda} = \frac{\partial L_{\text{val}}}{\partial \lambda} + \left(\frac{\partial w^\star}{\partial \lambda}\right)^\top \frac{\partial L_{\text{val}}}{\partial w}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Method 1 — Unrolled Differentiation:&lt;/strong&gt; Replace \(w^\star(\lambda)\) with \(K\) steps of inner gradient descent \(w_K(\lambda)\) and backpropagate through the entire \(K\)-step optimization loop. Simple to code in PyTorch/JAX, but memory scales as \(O(K \cdot d)\) and gradients can vanish or explode for large \(K\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Method 2 — Implicit Function Theorem (IFT):&lt;/strong&gt; Differentiating the inner optimality condition \(\nabla_w L_{\text{train}}(w^\star(\lambda), \lambda) = 0\) with respect to \(\lambda\) gives the exact linear system \(\nabla_{ww}^2 L_{\text{train}} \cdot \frac{\partial w^\star}{\partial \lambda} = -\nabla_{w\lambda}^2 L_{\text{train}}\). Using reverse-mode adjoints + conjugate gradients (or truncated Neumann series) solves for the hypergradient in \(O(d)\) memory—independent of \(K\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical Trade-off:&lt;/strong&gt; Use unrolling when \(K\) is tiny (e.g., 1–5 steps in MAML); use IFT when the inner solver runs hundreds of steps to near-convergence.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-an-exact-hypergradient-via-ift-on-ridge-regression&quot;&gt;Worked example: Computing an Exact Hypergradient via IFT on Ridge Regression&lt;/h3&gt;

&lt;p&gt;Let \(L_{\text{train}}(w, \lambda) = \frac{1}{2}(w - 4)^2 + \frac{\lambda}{2} w^2\) (1D ridge regression) and \(L_{\text{val}}(w) = \frac{1}{2}(w - 2)^2\). Evaluate the hypergradient \(\frac{d L_{\text{val}}}{d\lambda}\) at \(\lambda = 1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the inner optimality condition \(\nabla_w L_{\text{train}}(w^\star, \lambda) = 0\):&lt;/strong&gt;
\((w^\star - 4) + \lambda w^\star = 0 \implies w^\star(\lambda) = \frac{4}{1 + \lambda}.\)
At \(\lambda = 1\), \(w^\star(1) = \frac{4}{2} = 2\)? Let us make the validation target \(y_{\text{val}} = 3\) so the hypergradient is nonzero: \(L_{\text{val}}(w) = \frac{1}{2}(w - 3)^2\). Then at \(\lambda = 1\), \(w^\star(1) = 2\) and \(\frac{\partial L_{\text{val}}}{\partial w} = 2 - 3 = -1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the Implicit Function Theorem (without differentiating the closed-form solution):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Inner Hessian: \(\nabla_{ww}^2 L_{\text{train}} = 1 + \lambda = 2\).&lt;/li&gt;
      &lt;li&gt;Mixed partial: \(\nabla_{w\lambda}^2 L_{\text{train}} = w^\star = 2\).&lt;/li&gt;
      &lt;li&gt;IFT sensitivity: \(\frac{\partial w^\star}{\partial \lambda} = -(\nabla_{ww}^2 L_{\text{train}})^{-1} \nabla_{w\lambda}^2 L_{\text{train}} = -\frac{2}{2} = -1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assemble the hypergradient:&lt;/strong&gt;
\(\frac{d L_{\text{val}}}{d\lambda} = \frac{\partial L_{\text{val}}}{\partial w} \cdot \frac{\partial w^\star}{\partial \lambda} = (-1)(-1) = +1 &amp;gt; 0.\)
Since the hypergradient is positive, gradient descent on \(\lambda\) decreases \(\lambda\)—reducing shrinkage so \(w^\star\) moves up from \(2\) toward the validation target \(3\)!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Verify directly:&lt;/strong&gt; $$\frac{d}{d\lambda}\left[\frac{1}{2}\left(\frac{4}{1+\lambda} - 3\right)^2\right]\Big&lt;/td&gt;
          &lt;td&gt;_{\lambda=1} = (2 - 3)\cdot \frac{-4}{(1+1)^2} = (-1)(-1) = +1$$. Exact!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chapters 26–27 trained a model by differentiating a &lt;em&gt;single&lt;/em&gt; loss with respect to weights. A surprising amount of modern machine learning is a &lt;strong&gt;nested&lt;/strong&gt; pair of optimizations: the weights are themselves the solution of an inner problem that depends on a hyperparameter, and we want to differentiate the &lt;em&gt;outer&lt;/em&gt; objective through that solution. This optional lesson is one nested template — bilevel optimization and the &lt;strong&gt;hypergradient&lt;/strong&gt; — at course depth. It is not a second autodiff lecture (27-01–27-03 already own JVP / VJP) and it is not a survey of every HPO library.&lt;/p&gt;

&lt;p&gt;The map to keep is Chen, Chen, Jiang, Ye, Wang, Yang, Poor, and Wang, &lt;em&gt;A Whole New World, but How? A Survey of Bilevel Optimization and Applications&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2405.04996&quot;&gt;arXiv:2405.04996&lt;/a&gt; (2024), together with the classical implicit-function viewpoint in Bengio, &lt;em&gt;Gradient-Based Optimization of Hyperparameters&lt;/em&gt; (2000) and the modern deep-learning treatment of Franceschi, Frasconi, Salzo, Grazzi, and Pontil (ICML 2018).&lt;/p&gt;

&lt;h2 id=&quot;one-nested-template&quot;&gt;One nested template&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;bilevel&lt;/strong&gt; program is&lt;/p&gt;

\[\begin{align}
\min_{\lambda}\quad &amp;amp; F\bigl(w^\star(\lambda),\lambda\bigr)\\
\text{s.t.}\quad &amp;amp; w^\star(\lambda)\in\arg\min_w\, L(w,\lambda).
\end{align}\]

&lt;p&gt;The &lt;strong&gt;inner&lt;/strong&gt; problem is ordinary training: \(L\) is the training loss, \(w\) the weights, \(\lambda\) a hyperparameter that &lt;em&gt;enters the inner problem&lt;/em&gt; (a learning rate, a weight-decay, a validation-weighted data filter, the initialization of a few inner steps). The &lt;strong&gt;outer&lt;/strong&gt; objective \(F\) is usually a validation loss, a fairness constraint, or a meta-task. The object \(\nabla_\lambda F(w^\star(\lambda),\lambda)\) is the &lt;strong&gt;hypergradient&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is the same template under several course names:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hyperparameter optimization (HPO).&lt;/strong&gt; \(\lambda\) is weight decay or a step-size; \(F\) is validation loss. Pedestrian grid search never differentiates through \(w^\star\); a hypergradient method does.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Meta-learning / MAML.&lt;/strong&gt; Each “task” is an inner SGD of a few steps from a shared initialization \(\lambda\); the outer loss is performance after those steps. Finn, Abbeel, and Levine (ICML 2017) is the algorithm; the mathematics is unrolled bilevel.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dataset distillation / learning to optimize.&lt;/strong&gt; The inner solver is a few GD steps; the outer variables are synthetic data, or even the optimizer’s own hyperparameters.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Implicit layers.&lt;/strong&gt; An equilibrium \(w=\Phi(w,\lambda)\) is an inner fixed point; Deep Equilibrium Models differentiate through it with a vector–Jacobian product (a cousin of 27-02 / 27-03).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you can draw the nested pair and name which gradient is the hypergradient, you can read those papers without a new theory course.&lt;/p&gt;

&lt;h2 id=&quot;two-ways-to-get-the-hypergradient&quot;&gt;Two ways to get the hypergradient&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Unrolling.&lt;/strong&gt; Replace \(w^\star(\lambda)\) by \(T\) steps of a differentiable inner solver, \(w_{t+1}=w_t-\eta\nabla_w L(w_t,\lambda)\), and backpropagate through the tape. Reverse mode (27-03) gives \(\nabla_\lambda F\) at a cost linear in \(T\) times the cost of one inner step — exactly the memory story of a long unrolled RNN. One-step unrolling (\(T=1\)) is already enough to &lt;em&gt;feel&lt;/em&gt; the chain rule; MAML-style few-shot methods live at small \(T\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implicit differentiation.&lt;/strong&gt; If the inner problem is smooth and the Hessian \(H=\nabla_{ww}^2 L(w^\star,\lambda)\) is invertible at the minimizer, the implicit function theorem says&lt;/p&gt;

\[\frac{\mathrm{d}w^\star}{\mathrm{d}\lambda}
=-H^{-1}\nabla_{w\lambda}^2 L(w^\star,\lambda),\]

&lt;p&gt;so the hypergradient is&lt;/p&gt;

\[\nabla_\lambda F
=\nabla_\lambda F\big|_{\text{explicit}}
-\bigl(\nabla_{w\lambda}^2 L\bigr)^\top H^{-1}\nabla_w F.\]

&lt;p&gt;You never form \(H^{-1}\): you solve \(H\,v=\nabla_w F\) by conjugate gradients (Hessian–vector products via forward-over-reverse AD, the mixed mode mentioned in 27-03) and then contract against the mixed partial. Lorraine, Vicol, and Duvenaud (ICML 2020, &lt;em&gt;Optimizing Millions of Hyperparameters by Implicit Differentiation&lt;/em&gt;) is the scalable-HPO slogan built on that solve. The invertibility hypothesis is the price: at a true inner minimizer of a strongly convex \(L\) it is honest; on a nonconvex net that you stopped early, unrolling is often the more honest model of what you actually computed.&lt;/p&gt;

&lt;p&gt;Approximate implicit differentiation (truncated CG, Neumann series) sits between the two. Treat it as a seminar paper, not a second set of homework knobs.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;When to unroll, when to invert.&lt;/strong&gt;
Short inner loop, nonconvex, or “the algorithm &lt;em&gt;is&lt;/em&gt; the model” (MAML, learned optimizers): unroll.
Long inner loop, strongly convex inner problem, many hyperparameters (validation-weighted training, neural architecture with a convex inner solver): implicit / CG.
Never differentiate through a full AdamW pretrain of a language model by either route — use a proxy (a short fine-tune, a linear head, a subset) or do not claim a hypergradient.
&lt;/div&gt;

&lt;h2 id=&quot;a-one-step-unrolled-learning-rate&quot;&gt;A one-step unrolled learning-rate&lt;/h2&gt;

&lt;p&gt;The smallest honest example is a quadratic inner problem and a scalar step-size \(\lambda=\eta\). One gradient step from \(w_0\) gives \(w_1(\eta)=w_0-\eta\nabla L(w_0)\). An outer loss \(F(w_1)=\tfrac12\|w_1-w_{\mathrm{val}}\|_2^2\) then has an elementary hypergradient \(\mathrm{d}F/\mathrm{d}\eta\) by the chain rule — no library required.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;one_step_hypergrad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Inner: one GD step on 0.5 w^T A w - b^T w. Outer: 0.5 ||w1 - w_val||^2.&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# d w1 / d eta = -g ; hypergrad = (w1 - w_val)^T dw1/deta
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;hyper&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hyper&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;diag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;10.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w_val&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;# pretend the val target is the minimizer
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dF&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;one_step_hypergrad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.05&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_val&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hypergrad dF/deta&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A negative hypergradient says “the validation loss would decrease if you &lt;em&gt;raised&lt;/em&gt; \(\eta\).” That is the entire HPO message, written without a tuner. Reverse-mode AD (PyTorch or JAX) does the same bookkeeping when \(T&amp;gt;1\) or when \(L\) is a net; you now know which tape you are asking it to play.&lt;/p&gt;

&lt;p&gt;For a &lt;em&gt;true&lt;/em&gt; inner minimizer of the same quadratic, implicit differentiation recovers \(\mathrm{d}w^\star/\mathrm{d}\lambda\) for any hyperparameter that enters \(A\) or \(b\) (a ridge \(\lambda\) is the usual classroom choice: \(L(w,\lambda)=\tfrac12\|Xw-y\|_2^2+\frac{\lambda}{2}\|w\|_2^2\), outer loss on a validation split). The linear system is \((X^\top X+\lambda I)v=\nabla_w F\) — a ridge solve you already met in Chapter 05.&lt;/p&gt;

&lt;h2 id=&quot;what-this-course-expects&quot;&gt;What this course expects&lt;/h2&gt;

&lt;p&gt;You should be able to (i) write the nested pair for HPO and for one-step MAML, (ii) say why reverse mode on an unrolled inner loop &lt;em&gt;is&lt;/em&gt; a hypergradient, (iii) write the implicit formula and name the Hessian solve, and (iv) refuse to unroll a full LLM pretrain. Chapter 26’s AdamW remains the inner &lt;em&gt;algorithm&lt;/em&gt; for the models we actually train; this page is how a validation loss can talk back to a hyperparameter without a grid. Further reading, not assessed: Maclaurin, Duvenaud, and Adams (2015) on reversing SGD for HPO; Rajeswaran, Finn, Kakade, and Levine (ICML 2019) on implicit MAML; the 2024 Chen survey for the taxonomy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Derive \(\mathrm{d}w_1/\mathrm{d}\eta=- \nabla L(w_0)\) for one GD step and the hypergradient of \(F(w_1)=\tfrac12\|w_1-w_{\mathrm{val}}\|_2^2\). Then implement two steps (\(T=2\)) by hand and check against &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.autograd&lt;/code&gt; on the same quadratic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; For ridge \(L(w,\lambda)=\tfrac12\|Xw-y\|_2^2+\frac{\lambda}{2}\|w\|_2^2\) with a validation outer loss, write the implicit hypergradient and compute it by solving \((X^\top X+\lambda I)v=\nabla_w F\). Compare to differentiating a &lt;em&gt;single&lt;/em&gt; GD step on the same \(L\). When do the two numbers disagree, and which one matches “I actually ran \(T\) steps”?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; Mixed-mode AD in 27-03 computes Hessian–vector products in time comparable to one gradient. Where, exactly, does that product appear in the implicit hypergradient — and why is that the reason Lorraine et al. can advertise “millions of hyperparameters”?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Y. Bengio, “Gradient-Based Optimization of Hyperparameters,” &lt;em&gt;Neural Computation&lt;/em&gt;, 2000.&lt;/li&gt;
  &lt;li&gt;L. Franceschi, P. Frasconi, S. Salzo, R. Grazzi, and M. Pontil, “Bilevel Programming for Hyperparameter Optimization and Meta-Learning,” ICML 2018.&lt;/li&gt;
  &lt;li&gt;J. Lorraine, P. Vicol, and D. Duvenaud, “Optimizing Millions of Hyperparameters by Implicit Differentiation,” ICML 2020.&lt;/li&gt;
  &lt;li&gt;C. Finn, P. Abbeel, and S. Levine, “Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks,” ICML 2017.&lt;/li&gt;
  &lt;li&gt;C. Chen et al., “A Whole New World, but How?,” &lt;a href=&quot;https://arxiv.org/abs/2405.04996&quot;&gt;arXiv:2405.04996&lt;/a&gt;, 2024.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>29-04 Ứng dụng liên federated hiện đại</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter29/29_04_modern_federated/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter29/29_04_modern_federated</id>
   <content type="html">&lt;p&gt;Từ năm 2020 đến 2026, học liên kết đã bước ra khỏi phòng thí nghiệm để giải quyết những bài toán mang ý nghĩa nhân văn sâu sắc: hàng chục bệnh viện trên khắp thế giới hợp tác huấn luyện mô hình phân đoạn u não hay phát hiện bệnh lý phổi mà &lt;strong&gt;không một bức ảnh y khoa nào của bệnh nhân phải rời khỏi tường lửa bệnh viện&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Nhưng để triển khai thành công trong thế giới thực — nơi dữ liệu giữa các bệnh viện cực kỳ không đồng nhất (non-IID) và tốc độ phần cứng mỗi nơi một khác — cộng đồng tối ưu hóa đã phải phát triển ba vũ khí nâng cấp trực tiếp cho FedAvg: &lt;strong&gt;FedProx&lt;/strong&gt; (sợi dây neo proximal), &lt;strong&gt;SCAFFOLD&lt;/strong&gt; (biến kiểm soát triệt tiêu trôi cục bộ), và &lt;strong&gt;FedAdam / FedOpt&lt;/strong&gt; (tách bộ tối ưu thích nghi lên máy chủ).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-học-liên-kết-hiện-đại-20202026&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của Học liên kết hiện đại (2020–2026)&lt;/h2&gt;

&lt;p&gt;Bài đọc cuối khóa này khép lại chuỗi kết nối giữa tất cả các chương tối ưu bạn đã học:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;FedProx (Sợi dây neo Proximal \(\frac{\mu}{2}\|w - w_t\|_2^2\)):&lt;/strong&gt; Thêm số hạng phạt bậc hai vào hàm mục tiêu cục bộ của từng máy khách để ngăn trọng số chạy quá xa mô hình toàn cục \(w_t\) — cực kỳ đơn giản, không cần lưu trạng thái cục bộ, xử lý tốt cả non-IID lẫn máy khách yếu chỉ chạy kịp ít bước.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SCAFFOLD (Biến kiểm soát kiểu SVRG cho Liên kết):&lt;/strong&gt; Mượn trực tiếp ý tưởng biến kiểm soát (control variate) của SVRG (Chương 26) và tinh thần đối ngẫu của ADMM (Chương 21): mỗi máy khách giữ ước lượng hướng trôi \(c_i\), sửa gradient cục bộ thành \(\nabla F_i(w) - c_i + c\) để &lt;strong&gt;triệt tiêu hoàn toàn client drift&lt;/strong&gt; mà không cần bước proximal chính xác.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;FedOpt / FedAdam (Tối ưu hai cấp máy khách – máy chủ):&lt;/strong&gt; Coi hiệu số trung bình \(\Delta_t = w_t - \sum_i p_i w_{t+1}^{(i)}\) như một “giả gradient” (pseudo-gradient) ở phía máy chủ, rồi áp dụng Momentum hoặc Adam lên \(\Delta_t\) ở phía máy chủ trong khi máy khách vẫn chạy SGD gọn nhẹ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên kết Y tế Cross-Silo (FeTS &amp;amp; OpenFL):&lt;/strong&gt; Minh chứng thực tiễn sống động nơi số nút nhỏ (vài chục bệnh viện), mỗi nút ổn định và đủ năng lực tính toán — mảnh đất lý tưởng để áp dụng cả FedProx, SCAFFOLD lẫn các khung mã nguồn mở như Flower và NVFlare.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-cách-fedprox-và-scaffold-chữa-bệnh-trôi-cục-bộ&quot;&gt;Giải thích: Tính tay cách FedProx và SCAFFOLD chữa bệnh Trôi cục bộ&lt;/h3&gt;

&lt;p&gt;Quay lại đúng bài toán 2 máy khách non-IID xuyên suốt Chương 29: \(F_1(w) = \frac{1}{2}w^2\) và \(F_2(w) = \frac{3}{2}(w - 4)^2\) với nghiệm toàn cục \(w^\star = 3.0\), xuất phát từ \(w_t = 3.0\) (nhớ rằng FedAvg thuần với \(E \to \infty\) đã trôi tụt về \(2.0\), sai số \(1.0\)!).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Dùng FedProx với hệ số neo \(\mu = 2\) (mỗi máy cực tiểu hóa \(F_i(w) + \frac{2}{2}(w - 3)^2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Máy khách 1:&lt;/em&gt; \(\nabla\bigl[\frac{1}{2}w^2 + (w - 3)^2\bigr] = w + 2(w - 3) = 0 \implies w^{(1)} = 2.0\) (được kéo lại gần \(3.0\) hơn rất nhiều so với \(0.0\)!).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Máy khách 2:&lt;/em&gt; \(\nabla\bigl[\frac{3}{2}(w - 4)^2 + (w - 3)^2\bigr] = 3(w - 4) + 2(w - 3) = 0 \implies 5w = 18 \implies w^{(2)} = 3.6\) (gần \(3.0\) hơn \(4.0\)!).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Trung bình máy chủ:&lt;/em&gt; \(w_{t+1}^{\text{FedProx}} = \frac{2.0 + 3.6}{2} = 2.8\)!
Chỉ với một số hạng neo đơn giản, sai số trôi đã giảm &lt;strong&gt;5 lần&lt;/strong&gt; (từ \(1.0\) xuống còn \(0.2\))!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng SCAFFOLD (với biến kiểm soát lý tưởng \(c_1 = \nabla F_1(3) = +3,\; c_2 = \nabla F_2(3) = -3\) và trung bình toàn cục \(c = \frac{3 + (-3)}{2} = 0\)):&lt;/strong&gt;
Tại \(w = 3.0\), gradient đã hiệu chỉnh của cả hai máy khách đều là:
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Máy khách 1:&lt;/em&gt; \(g_1^{\text{corr}} = \nabla F_1(3) - c_1 + c = 3 - 3 + 0 = 0\)!&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Máy khách 2:&lt;/em&gt; \(g_2^{\text{corr}} = \nabla F_2(3) - c_2 + c = (-3) - (-3) + 0 = 0\)!
Cả hai máy đứng yên tại &lt;strong&gt;đúng \(w^\star = 3.0\)&lt;/strong&gt; — sai số trôi bằng \(0\) tuyệt đối! Nhìn lại cả ba bài 29-02 → 29-03 → 29-04 trên cùng một ví dụ số, bạn đã thấy trọn vẹn mạch tiến hóa tuyệt đẹp của tối ưu hóa liên kết hiện đại.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các bài 29-01 đến 29-03 đã trình bày SGD song song dữ liệu, &lt;strong&gt;FedAvg&lt;/strong&gt; và sự khác biệt với ADMM. Bài đọc tùy chọn này mở rộng sang các phương pháp và ứng dụng học liên kết giai đoạn 2020–2026: xử lý dữ liệu non-IID giữa các máy khách (FedProx, SCAFFOLD), đưa bộ tối ưu thích nghi lên máy chủ (FedOpt) và ứng dụng thực tế trong y tế liên viện.&lt;/p&gt;

&lt;h2 id=&quot;1-fedprox-bổ-sung-số-hạng-proximal-hạn-chế-trôi-cục-bộ&quot;&gt;1. FedProx: bổ sung số hạng proximal hạn chế trôi cục bộ&lt;/h2&gt;

&lt;p&gt;Li, Sahu, Zaheer, Sanjabi, Talwalkar và Smith (&lt;em&gt;Federated Optimization in Heterogeneous Networks&lt;/em&gt;, MLSys 2020, &lt;a href=&quot;https://proceedings.mlsys.org/paper_files/paper/2020/hash/1f5fe83998a09396ebe6477d9475ba0c-Abstract.html&quot;&gt;proceedings.mlsys.org&lt;/a&gt;) thay hàm mục tiêu cục bộ \(F_c(w)\) bằng:&lt;/p&gt;

\[F_c(w)+\frac{\mu}{2}\|w-w_t\|_2^2.\]

&lt;p&gt;Số hạng phạt bậc hai này kéo nghiệm cục bộ không đi quá xa khỏi mô hình toàn cục \(w_t\) vừa nhận — có ý tưởng gần với số hạng phạt trong Lagrangian tăng cường nhưng không có biến đối ngẫu. FedProx là phương pháp mở rộng phổ biến ngay sau FedAvg khi hệ thống có sự không đồng nhất cả về dữ liệu (non-IID) lẫn phần cứng (máy khách thực hiện số bước cục bộ không đều hoặc ngắt kết nối). Tuy nhiên, FedProx &lt;strong&gt;không&lt;/strong&gt; phải ADMM vì không có bước cập nhật đối ngẫu hay phần dư kiểm chứng đồng thuận như đã phân biệt ở mục 29-03.&lt;/p&gt;

&lt;h2 id=&quot;2-scaffold-biến-kiểm-soát-triệt-tiêu-trôi-máy-khách&quot;&gt;2. SCAFFOLD: biến kiểm soát triệt tiêu trôi máy khách&lt;/h2&gt;

&lt;p&gt;Karimireddy, Kale, Mohri, Reddi, Stich và Suresh (&lt;em&gt;SCAFFOLD: Stochastic Controlled Averaging for Federated Learning&lt;/em&gt;, ICML 2020, &lt;a href=&quot;https://proceedings.mlr.press/v119/karimireddy20a.html&quot;&gt;PMLR v119&lt;/a&gt;) duy trì các &lt;em&gt;biến kiểm soát (control variates)&lt;/em&gt; trên máy chủ và trên từng máy khách để hiệu chỉnh trực tiếp độ lệch gradient cục bộ \((\nabla F_c-\nabla F)\) trong mỗi bước SGD cục bộ. Chi phí truyền thông mỗi vòng tăng thêm một vector tham số, nhưng đổi lại tốc độ hội tụ không bị suy giảm theo số bước cục bộ \(E\). Nếu FedAvg chỉ lấy trung bình các mô hình đã bị trôi, SCAFFOLD chủ động trừ đi thành phần trôi ước lượng — cùng cơ chế biến kiểm soát như trong SVRG/SAGA ở mục 26-05.&lt;/p&gt;

&lt;h2 id=&quot;3-fedopt--fedadam-dùng-bộ-tối-ưu-thích-nghi-ở-phía-máy-chủ&quot;&gt;3. FedOpt / FedAdam: dùng bộ tối ưu thích nghi ở phía máy chủ&lt;/h2&gt;

&lt;p&gt;Reddi, Charles, Zaheer, Garrett, Rush, Konečný, Kumar và McMahan (&lt;em&gt;Adaptive Federated Optimization&lt;/em&gt;, ICLR 2021, &lt;a href=&quot;https://openreview.net/forum?id=LkFG3lB13U5&quot;&gt;OpenReview&lt;/a&gt;) xem độ chênh lệch trung bình của các máy khách \(w_t-\bar w_{t+1}\) như một &lt;em&gt;giả gradient (pseudo-gradient)&lt;/em&gt; và áp dụng các bộ tối ưu thích nghi (Adam, Yogi, AdaGrad) ngay &lt;strong&gt;tại máy chủ&lt;/strong&gt;. Nhờ đó, máy khách chỉ cần chạy SGD đơn giản với bộ nhớ thấp, còn trạng thái mô-men \(\hat m, \hat v\) của tiền điều kiện thích nghi được lưu ở máy chủ. Khi kết hợp với bước cục bộ kiểu FedAvg, biến thể này thường được gọi là &lt;strong&gt;FedAdam&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;4-y-tế-liên-viện-ứng-dụng-thực-tế-nổi-bật-của-học-liên-kết&quot;&gt;4. Y tế liên viện: ứng dụng thực tế nổi bật của học liên kết&lt;/h2&gt;

&lt;p&gt;Các bài toán chẩn đoán ảnh y khoa và hồ sơ bệnh án điện tử (EHR) liên bệnh viện (cross-silo) là lĩnh vực đưa học liên kết vượt ra ngoài bài toán dự đoán gõ phím trên điện thoại. Guan, Yap, Bozoki và Liu (&lt;em&gt;Federated learning for medical image analysis: A survey&lt;/em&gt;, &lt;em&gt;Pattern Recognition&lt;/em&gt; 151:110424, 2024, &lt;a href=&quot;https://doi.org/10.1016/j.patcog.2024.110424&quot;&gt;doi:10.1016/j.patcog.2024.110424&lt;/a&gt;) hệ thống hóa các bài toán phân đoạn khối u, ảnh X-quang ngực và dữ liệu đa phương thức. Các bài khảo sát của Nguyen và cộng sự (&lt;em&gt;Federated Learning for Smart Healthcare: A Survey&lt;/em&gt;, &lt;em&gt;ACM Comput. Surv.&lt;/em&gt; 55(3), 2022) cùng bài tổng quan trên &lt;em&gt;CSBJ&lt;/em&gt; 2025 (hơn 250 công trình giai đoạn 2019–2024, &lt;a href=&quot;https://doi.org/10.1016/j.csbj.2025.06.009&quot;&gt;doi:10.1016/j.csbj.2025.06.009&lt;/a&gt;) tổng hợp kiến trúc hệ thống, phân hoạch ngang/dọc và các bộ tổng hợp được triển khai thực tế: FedAvg vẫn là lựa chọn khởi đầu phổ biến nhất; FedProx và SCAFFOLD được dùng khi phân phối lớp giữa các bệnh viện lệch mạnh; còn bảo vệ quyền riêng tư hình thức (DP-SGD, tổng hợp an toàn) được kết hợp ở tầng bảo mật riêng như đã nêu ở mục 29-02.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Cơ chế bổ sung&lt;/th&gt;
      &lt;th&gt;Chi phí truyền thông thêm&lt;/th&gt;
      &lt;th&gt;Khi nào nên thử&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;FedAvg (29-02)&lt;/td&gt;
      &lt;td&gt;trung bình trọng số sau \(E\) bước cục bộ&lt;/td&gt;
      &lt;td&gt;1 mô hình / vòng&lt;/td&gt;
      &lt;td&gt;chuẩn đối chiếu, dữ liệu gần IID&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FedProx&lt;/td&gt;
      &lt;td&gt;số hạng proximal \(\mu\) kéo về \(w_t\)&lt;/td&gt;
      &lt;td&gt;tương đương FedAvg&lt;/td&gt;
      &lt;td&gt;thiết bị không đồng đều, non-IID vừa&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SCAFFOLD&lt;/td&gt;
      &lt;td&gt;biến kiểm soát máy khách / máy chủ&lt;/td&gt;
      &lt;td&gt;\(+1\) vector / máy khách&lt;/td&gt;
      &lt;td&gt;trôi cục bộ mạnh (non-IID cao)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FedAdam&lt;/td&gt;
      &lt;td&gt;áp dụng Adam lên giả gradient tại máy chủ&lt;/td&gt;
      &lt;td&gt;tương đương FedAvg (+ bộ nhớ máy chủ)&lt;/td&gt;
      &lt;td&gt;muốn cập nhật thích nghi ở máy chủ, máy khách nhẹ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FedADMM (21-07)&lt;/td&gt;
      &lt;td&gt;phần dư đối ngẫu&lt;/td&gt;
      &lt;td&gt;cùng bậc với FedAvg&lt;/td&gt;
      &lt;td&gt;cần theo dõi phần dư gốc–đối ngẫu&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Dùng lại cách chia dữ liệu MNIST (hoặc hỗn hợp Gaussian 2 chiều) cho 3 máy khách, mỗi máy khách một lớp từ mục 29-02. Chạy \(E=5\) bước cục bộ với: (i) FedAvg, (ii) FedProx tại hai giá trị \(\mu\) khác nhau, và (iii) một phiên bản đơn giản của SCAFFOLD trừ trung bình trượt của gradient cục bộ. Vẽ độ chính xác kiểm tra toàn cục theo &lt;em&gt;số vòng truyền thông&lt;/em&gt; (không theo số bước cục bộ) và nhận xét phương pháp nào làm giảm dao động rõ nhất so với mục 29-02.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;H. B. McMahan et al., AISTATS 2017 — FedAvg (đã bắt buộc).&lt;/li&gt;
  &lt;li&gt;T. Li et al., MLSys 2020 — FedProx.&lt;/li&gt;
  &lt;li&gt;S. P. Karimireddy et al., ICML 2020 — SCAFFOLD.&lt;/li&gt;
  &lt;li&gt;S. Reddi et al., ICLR 2021 — FedOpt / FedAdam.&lt;/li&gt;
  &lt;li&gt;H. Guan et al., &lt;em&gt;Pattern Recognition&lt;/em&gt; 151:110424, 2024 — FL ảnh y khoa.&lt;/li&gt;
  &lt;li&gt;D. C. Nguyen et al., &lt;em&gt;ACM Comput. Surv.&lt;/em&gt; 55(3), 2022 — FL y tế thông minh.&lt;/li&gt;
  &lt;li&gt;Khảo sát CSBJ 2025, &lt;a href=&quot;https://doi.org/10.1016/j.csbj.2025.06.009&quot;&gt;doi:10.1016/j.csbj.2025.06.009&lt;/a&gt; — rà hệ thống 2019–2024.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>28-04 Nghiên cứu tình huống phong cảnh hiện đại</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_04_modern_landscapes/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_04_modern_landscapes</id>
   <content type="html">&lt;p&gt;Nếu ba bài trước là bản đồ lý thuyết của thế giới không lồi, thì bài đọc này đưa bạn vào bảo tàng những &lt;strong&gt;hiện tượng thực nghiệm kỳ lạ nhất của học sâu hiện đại&lt;/strong&gt; — những hiện tượng từng khiến giới thống kê cổ điển phải viết lại sách giáo khoa: hai mạng nơ-ron huấn luyện hoàn toàn độc lập có thể nối với nhau bằng một con đường mất mát gần bằng \(0\) (&lt;strong&gt;mode connectivity&lt;/strong&gt;); mạng Transformer sau khi đã đạt \(100\%\) độ chính xác tập train bỗng nhiên “giác ngộ” trên tập test sau hàng chục nghìn bước tiếp theo (&lt;strong&gt;grokking&lt;/strong&gt;); và sai số kiểm tra tăng vọt ở ngưỡng nội suy rồi lại giảm sâu hơn nữa khi tăng thêm kích thước mạng (&lt;strong&gt;double descent&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Điểm chung đáng kinh ngạc của cả bốn hiện tượng trong bài là chúng đều bắt nguồn trực tiếp từ hình học địa hình hàm mất mát và động lực học tối ưu mà bạn vừa học!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-hiện-tượng-thực-nghiệm-định-hình-lý-thuyết-học-sâu-hiện-đại&quot;&gt;Kiến thức cần nhớ: Bốn hiện tượng thực nghiệm định hình lý thuyết học sâu hiện đại&lt;/h2&gt;

&lt;p&gt;Khi đọc bốn nghiên cứu tình huống trong bài, hãy gắn từng hiện tượng với nguyên lý tối ưu tương ứng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Liên thông mode (Mode Connectivity) và Tính đối xứng:&lt;/strong&gt; Do mạng nơ-ron bất biến dưới hoán vị các nơ-ron ẩn, các cực tiểu không nằm tách rời như những hố cô lập mà tạo thành mạng lưới thung lũng liên thông trong tập dưới mức; tuy nhiên &lt;em&gt;hàng rào mất mát thấp&lt;/em&gt; vẫn có thể kèm &lt;em&gt;hàng rào entropy/độ cong cao&lt;/em&gt; giữ SGD ở lại từng nhánh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Grokking (Tổng quát hóa muộn sau khi nội suy):&lt;/strong&gt; Sau khi mất mát dữ liệu đã bằng \(0\), trọng số vẫn tiếp tục trượt bên trong đa tạp nghiệm nội suy dưới tác dụng của &lt;strong&gt;weight decay (AdamW)&lt;/strong&gt; và thiên kiến ẩn, dần chuyển từ mạch “học vẹt” (chuẩn trọng số lớn) sang mạch “thuật toán tổng quát” (chuẩn trọng số nhỏ).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giảm kép (Double Descent):&lt;/strong&gt; Đường cong chữ U cổ điển của đánh đổi thiên lệch–phương sai chỉ mô tả nhánh trái (\(d &amp;lt; n\)). Tại ngưỡng nội suy \(d \approx n\), ma trận thiết kế gần suy biến làm chuẩn nghiệm bùng nổ (đỉnh sai số test); vượt sang nhánh phải (\(d \gg n\)), thiên kiến ẩn chọn nghiệm chuẩn nhỏ lại kéo sai số test giảm sâu xuống lần thứ hai!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phổ Hessian thực nghiệm của mạng sâu:&lt;/strong&gt; Khi đo phổ Hessian của mạng đã huấn luyện, ta luôn thấy một “khối lớn” trị riêng tập trung quanh \(0\) (hàng triệu phương phẳng) cùng đúng vài trị riêng tách rời lớn (thường bằng số lớp phân loại \(C\)) — xác nhận bức tranh hình học vừa phẳng vừa dị hướng của mạng sâu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-vì-sao-nội-suy-thẳng-giữa-hai-cực-tiểu-hoán-vị-gặp-ngọn-núi-mất-mát&quot;&gt;Giải thích: Tính tay vì sao nội suy thẳng giữa hai cực tiểu hoán vị gặp “ngọn núi” mất mát&lt;/h3&gt;

&lt;p&gt;Xét mạng nơ-ron 1 lớp ẩn gồm 2 nơ-ron: \(f_\theta(x) = a_1 \max(0, b_1 x) + a_2 \max(0, b_2 x)\) với 4 tham số \(\theta = (a_1, b_1, a_2, b_2)\). Giả sử hàm đích là \(y(x) = \max(0, 2x) - \max(0, 3x)\) (bằng \(-x\) với \(x &amp;gt; 0\) và \(0\) với \(x \le 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hai nghiệm tối ưu toàn cục hoàn toàn đối xứng (hoán vị nơ-ron 1 và nơ-ron 2):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nghiệm A: \(\theta_A = (1,\; 2,\; -1,\; 3) \implies f_{\theta_A}(x) = 1\cdot\max(0, 2x) - 1\cdot\max(0, 3x) = y(x)\) (mất mát \(= 0\)!).&lt;/li&gt;
      &lt;li&gt;Nghiệm B: \(\theta_B = (-1,\; 3,\; 1,\; 2) \implies f_{\theta_B}(x) = -1\cdot\max(0, 3x) + 1\cdot\max(0, 2x) = y(x)\) (mất mát \(= 0\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử đi theo đoạn thẳng nối \(\theta_A\) và \(\theta_B\) tại trung điểm \(\theta_{\text{mid}} = \frac{1}{2}(\theta_A + \theta_B)\):&lt;/strong&gt;
\(\theta_{\text{mid}} = \left(\frac{1 + (-1)}{2},\; \frac{2 + 3}{2},\; \frac{-1 + 1}{2},\; \frac{3 + 2}{2}\right) = (0,\; 2.5,\; 0,\; 2.5)!\)
Tại trung điểm này, cả hai trọng số lớp ra đều bằng \(0\), nên \(f_{\theta_{\text{mid}}}(x) \equiv 0\) — &lt;strong&gt;sai lệch hoàn toàn so với \(y(x) = -x\)&lt;/strong&gt;, tạo thành một ngọn núi mất mát lớn chắn giữa đường thẳng!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thông điệp của Mode Connectivity:&lt;/strong&gt; Hai nghiệm tốt không thể nối bằng &lt;em&gt;đoạn thẳng&lt;/em&gt; do khác thứ tự hoán vị nơ-ron, nhưng lại có thể nối bằng một &lt;strong&gt;đường gấp khúc 2 đoạn&lt;/strong&gt; (hoặc căn chỉnh lại hoán vị trước khi lấy trung bình trọng số) mà mất mát vẫn giữ gần bằng \(0\) suốt dọc đường — mở đường cho kỹ thuật trộn mô hình (&lt;em&gt;model soup / weight averaging&lt;/em&gt;) hiện đại!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các bài 28-01 đến 28-03 đã xây dựng các khái niệm điểm tới hạn, điểm yên ngựa và quá tham số hóa. Bài đọc tùy chọn này điểm qua bốn hiện tượng &lt;em&gt;thực nghiệm&lt;/em&gt; nổi bật trong học sâu hiện đại gắn trực tiếp với các khái niệm đó.&lt;/p&gt;

&lt;h2 id=&quot;1-liên-thông-mode-các-cực-tiểu-không-bị-cô-lập&quot;&gt;1. Liên thông mode: các cực tiểu không bị cô lập&lt;/h2&gt;

&lt;p&gt;Garipov, Izmailov, Podoprikhin, Vetrov và Wilson (NeurIPS 2018) cùng Draxler, Veschgini, Salmhofer và Hamprecht (ICML 2018) chỉ ra rằng hai nghiệm độc lập tìm được bởi SGD trên một mạng sâu thường có thể nối với nhau bằng một đường gấp khúc đơn giản (thường chỉ gồm hai đoạn thẳng) mà dọc theo đó hàm mất mát huấn luyện hầu như không tăng. Frankle, Dziugaite, Roy và Carbin (ICML 2020) liên kết tính chất này với hướng nghiên cứu giả thuyết vé số (lottery ticket hypothesis). Một phân tích cập nhật năm 2025 về hiện tượng giam cầm entropy (&lt;a href=&quot;https://arxiv.org/abs/2512.06297&quot;&gt;arXiv:2512.06297&lt;/a&gt;) làm rõ thêm: đường nối tuy có &lt;em&gt;giá trị mất mát thấp&lt;/em&gt; nhưng có thể sở hữu &lt;em&gt;độ cong cao&lt;/em&gt; ở đoạn giữa, khiến SGD có nhiễu vẫn ở lại trong một vùng trũng dù tồn tại đường đi tất định sang vùng trũng khác. Như vậy, tính liên thông là tính chất của &lt;em&gt;tập dưới mức (sublevel set)&lt;/em&gt;, còn hiện tượng giam cầm là tính chất của &lt;em&gt;động lực học tối ưu&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;2-grokking-tổng-quát-hóa-xuất-hiện-rất-lâu-sau-khi-nội-suy&quot;&gt;2. Grokking: tổng quát hóa xuất hiện rất lâu sau khi nội suy&lt;/h2&gt;

&lt;p&gt;Power, Burda, Edwards, Babuschkin và Misra (&lt;em&gt;Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2201.02177&quot;&gt;arXiv:2201.02177&lt;/a&gt;, 2022) huấn luyện các mạng transformer nhỏ trên các bài toán số học modulo. Độ chính xác trên tập huấn luyện đạt 100% rất nhanh, nhưng độ chính xác &lt;em&gt;kiểm định&lt;/em&gt; vẫn ở mức ngẫu nhiên trong hàng bậc độ lớn bước tiếp theo trước khi đột ngột tăng vọt. Góc nhìn từ địa hình hàm mất mát giải thích hiện tượng này: đạt trạng thái nội suy (mất mát huấn luyện \(\approx 0\)) chưa phải là kết thúc quá trình tối ưu. Bộ tối ưu vẫn tiếp tục dịch chuyển &lt;em&gt;bên trong&lt;/em&gt; tập các nghiệm nội suy, và thiên kiến ẩn (28-03) cùng suy giảm trọng số (AdamW, 26-04) dần dẫn mô hình sang nghiệm có khả năng tổng quát hóa tốt.&lt;/p&gt;

&lt;h2 id=&quot;3-hiện-tượng-giảm-kép-double-descent&quot;&gt;3. Hiện tượng giảm kép (Double descent)&lt;/h2&gt;

&lt;p&gt;Belkin, Hsu, Ma và Mandal (&lt;em&gt;PNAS&lt;/em&gt;, 2019) và Nakkiran, Kaplun, Bansal, Yang, Barak và Sutskever (ICLR 2020; bản thảo 2019, &lt;a href=&quot;https://arxiv.org/abs/1912.02292&quot;&gt;arXiv:1912.02292&lt;/a&gt;) chứng minh thực nghiệm rằng sai số kiểm tra có thể &lt;em&gt;tăng đỉnh&lt;/em&gt; tại ngưỡng nội suy rồi lại &lt;em&gt;giảm xuống&lt;/em&gt; khi kích thước mô hình tiếp tục vượt vào miền quá tham số hóa. Quá tham số hóa (28-03) vì thế không phải là trạng thái bất thường mà là nhánh thứ hai của đường cong này. Các nghiên cứu giai đoạn 2022–2024 tiếp tục ghi nhận cùng quy luật theo số epoch và kích thước tập dữ liệu, thay thế quan niệm đường cong chữ U cổ điển cho các mô hình lớn.&lt;/p&gt;

&lt;h2 id=&quot;4-cực-tiểu-phẳng-và-sam-dưới-góc-nhìn-hessian&quot;&gt;4. Cực tiểu phẳng và SAM dưới góc nhìn Hessian&lt;/h2&gt;

&lt;p&gt;SAM (Foret và cộng sự, ICLR 2021; xem chi tiết ở &lt;a href=&quot;/contents/vi/chapter26/26_06_modern_optimizers/&quot;&gt;26-06&lt;/a&gt;) là &lt;em&gt;thuật toán&lt;/em&gt; hướng quá trình học về vùng phẳng. Các phân tích của Bartlett, Long và Bousquet (&lt;em&gt;JMLR&lt;/em&gt; 24(43), 2023) cùng Shin, Lee, Andriushchenko và Lee (&lt;a href=&quot;https://arxiv.org/abs/2311.17539&quot;&gt;arXiv:2311.17539&lt;/a&gt;) chuyển quan sát đó thành tính chất &lt;em&gt;địa hình&lt;/em&gt;: các cực tiểu ổn định của SAM có phổ trị riêng Hessian đồng đều hơn, và khoảng cách tổng quát hóa giữa SAM và SGD &lt;em&gt;mở rộng&lt;/em&gt; khi mức độ quá tham số hóa tăng lên. Trong các mạng nội suy, không phải mọi cực tiểu địa phương đều tương đương nhau: chúng khác biệt ở độ sắc, và độ sắc được đặc trưng bởi thông tin bậc hai (Hessian hoặc cận PAC-Bayes) chứ không chỉ điều kiện bậc nhất.&lt;/p&gt;

&lt;p&gt;Mở &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/loss_function_landscapes.html&quot;&gt;loss_function_landscapes.html&lt;/a&gt; để quan sát trực quan trên lát cắt 2 chiều sự khác biệt giữa các cực tiểu nằm trong khe hẹp và vùng trũng rộng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; (i) Trên một mạng ReLU 2 chiều nhỏ, lấy hai nghiệm tìm được từ SGD với khởi tạo khác nhau và vẽ hàm mất mát dọc đoạn thẳng \(w(t)=(1-t)w_A+t w_B\) để quan sát hàng rào mất mát ở giữa. (ii) Chèn thêm một điểm uốn \(w_{1/2}= (w_A+w_B)/2 + v\) và tối ưu theo vector \(v\) nhỏ để tìm một đường gấp khúc có mức mất mát thấp nối hai nghiệm. (iii) Xem Hình 1 của Power và cộng sự và giải thích ngắn gọn vì sao độ chính xác huấn luyện là tiêu chí dừng không phù hợp trong bối cảnh grokking.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;T. Garipov et al., NeurIPS 2018; F. Draxler et al., ICML 2018 — liên thông mode.&lt;/li&gt;
  &lt;li&gt;J. Frankle et al., ICML 2020 — liên thông và vé số.&lt;/li&gt;
  &lt;li&gt;Giam cầm entropy, &lt;a href=&quot;https://arxiv.org/abs/2512.06297&quot;&gt;arXiv:2512.06297&lt;/a&gt;, 2025.&lt;/li&gt;
  &lt;li&gt;A. Power et al., &lt;a href=&quot;https://arxiv.org/abs/2201.02177&quot;&gt;arXiv:2201.02177&lt;/a&gt;, 2022 — grokking.&lt;/li&gt;
  &lt;li&gt;M. Belkin et al., &lt;em&gt;PNAS&lt;/em&gt; 2019; P. Nakkiran et al., ICLR 2020 — double descent.&lt;/li&gt;
  &lt;li&gt;P. Foret et al., ICLR 2021; P. L. Bartlett et al., &lt;em&gt;JMLR&lt;/em&gt; 24(43), 2023 — SAM / cực tiểu phẳng.&lt;/li&gt;
  &lt;li&gt;S. Shin, D. Lee, M. Andriushchenko, N. Lee, &lt;a href=&quot;https://arxiv.org/abs/2311.17539&quot;&gt;arXiv:2311.17539&lt;/a&gt; — SAM và quá tham số.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>27-04 Khung vi phân tự động và ML khoa học</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_04_autodiff_frameworks/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_04_autodiff_frameworks</id>
   <content type="html">&lt;p&gt;Từ công thức quy tắc dây chuyền trên bảng trắng cho đến việc lấy đạo hàm xuyên qua một bộ giải khí động lực học viết bằng C++/Fortran hay biên dịch đồ thị Transformer chạy trên cụm nghìn GPU là cả một bước nhảy vọt về kỹ nghệ phần mềm. Trong giai đoạn 2022–2026, hệ sinh thái vi phân tự động đã phân hóa thành ba trường phái rõ rệt — &lt;strong&gt;PyTorch&lt;/strong&gt;, &lt;strong&gt;JAX&lt;/strong&gt; và &lt;strong&gt;Enzyme&lt;/strong&gt; — mỗi công cụ giải quyết một tầng bài toán khác nhau.&lt;/p&gt;

&lt;p&gt;Điểm thú vị nhất của AD hiện đại không chỉ dừng ở tính gradient bậc nhất: bằng cách &lt;strong&gt;lồng ghép chế độ thuận và chế độ nghịch&lt;/strong&gt; (như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jvp&lt;/code&gt; bọc ngoài &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grad&lt;/code&gt;), các khung như JAX cho phép tính tích Hessian–vector (HVP) cho tối ưu bậc hai và tính đạo hàm phương trình đạo hàm riêng trong mạng nơ-ron vật lý (PINN) một cách gọn gàng chỉ trong vài dòng lệnh.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-hệ-sinh-thái-ad-giai-đoạn-20222026&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của hệ sinh thái AD giai đoạn 2022–2026&lt;/h2&gt;

&lt;p&gt;Khi chọn công cụ AD cho một dự án nghiên cứu hay sản phẩm, hãy đối chiếu theo bốn trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;PyTorch 2.x (Đồ thị động + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.compile&lt;/code&gt;):&lt;/strong&gt; Kế thừa băng Wengert động cực kỳ thân thiện cho gỡ lỗi và mô hình điều khiển phức tạp, nay kết hợp thêm TorchDynamo/Inductor để thu nhận và biên dịch đồ thị chiều nghịch thành mã GPU tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;JAX (Phép biến đổi hàm thuần — Composable Transformations):&lt;/strong&gt; Coi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grad&lt;/code&gt; (VJP), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jvp&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vmap&lt;/code&gt; (vector hóa) và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jit&lt;/code&gt; (biên dịch XLA) là các toán tử hàm có thể lồng ghép tùy ý — cực mạnh cho đạo hàm bậc cao, tính Hessian–vector và mô phỏng khoa học.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enzyme (AD cấp trình biên dịch LLVM):&lt;/strong&gt; Thay vì buộc nhà khoa học viết lại hàng triệu dòng code mô phỏng C++/Fortran/Julia sang Python, Enzyme chạy AD chiều nghịch trực tiếp trên mã trung gian LLVM IR &lt;em&gt;sau khi trình biên dịch đã tối ưu hóa&lt;/em&gt;, đạt tốc độ gần ngang mã viết tay.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học máy khoa học &amp;amp; PINN (Physics-Informed Neural Networks):&lt;/strong&gt; Mạng nơ-ron không chỉ khớp dữ liệu mà còn phải thỏa mãn phương trình vi phân riêng (như Navier–Stokes hay phương trình truyền nhiệt), đòi hỏi lấy đạo hàm &lt;em&gt;của đầu ra theo tọa độ đầu vào&lt;/em&gt; \((x, t)\) rồi lại lấy đạo hàm bậc hai theo trọng số \(w\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-tích-hessianvector-hvp-bằng-kỹ-thuật-forward-over-reverse&quot;&gt;Giải thích: Tính tay tích Hessian–Vector (HVP) bằng kỹ thuật Forward-over-Reverse&lt;/h3&gt;

&lt;p&gt;Trong tối ưu bậc hai (Chương 14) hay PINN, ma trận Hessian \(H \in \mathbb{R}^{d \times d}\) quá lớn để lưu trữ khi \(d = 10^6\), nhưng ta chỉ cần tích \(H(x)v\). Kỹ thuật &lt;strong&gt;Forward-over-Reverse&lt;/strong&gt; (trong JAX là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.jvp(jax.grad(f), (x,), (v,))&lt;/code&gt;) tính chính xác \(H(x)v\) mà không bao giờ lập ma trận \(H\)!&lt;/p&gt;

&lt;p&gt;Xét \(f(x_1, x_2) = x_1^3 + x_1 x_2^2\) tại điểm \(x = (1,\; 2)\) và vector hướng \(v = (1,\; -1)\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Dùng AD chiều nghịch định nghĩa hàm gradient \(g(x) = \nabla f(x)\):&lt;/strong&gt;
\(g_1(x_1, x_2) = 3x_1^2 + x_2^2, \qquad g_2(x_1, x_2) = 2x_1 x_2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Chạy AD chiều thuận (JVP) lên hàm \(g\) với hạt giống \(\dot{x} = v = (1,\; -1)\):&lt;/strong&gt;
Áp dụng quy tắc tiếp tuyến trực tiếp lên từng thành phần của \(g\) tại \((x_1, x_2) = (1, 2)\):
    &lt;ul&gt;
      &lt;li&gt;
\[\dot{g}_1 = 6 x_1 \dot{x}_1 + 2 x_2 \dot{x}_2 = 6(1)(1) + 2(2)(-1) = 6 - 4 = 2.\]
      &lt;/li&gt;
      &lt;li&gt;\(\dot{g}_2 = 2 \dot{x}_1 x_2 + 2 x_1 \dot{x}_2 = 2(1)(2) + 2(1)(-1) = 4 - 2 = 2.\)
Ta thu ngay tích Hessian–vector \(H(1, 2)v = (2,\; 2)^T\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng trực tiếp bằng ma trận Hessian tường minh:&lt;/strong&gt;
\(H(x) = \begin{pmatrix} 6x_1 &amp;amp; 2x_2 \\ 2x_2 &amp;amp; 2x_1 \end{pmatrix} \implies H(1, 2) = \begin{pmatrix} 6 &amp;amp; 4 \\ 4 &amp;amp; 2 \end{pmatrix}, \qquad H(1, 2)\begin{pmatrix} 1 \\ -1 \end{pmatrix} = \begin{pmatrix} 6 - 4 \\ 4 - 2 \end{pmatrix} = \begin{pmatrix} 2 \\ 2 \end{pmatrix}!\)
&lt;strong&gt;Khớp 100%&lt;/strong&gt; — và chi phí tính toán chỉ gấp một hằng số nhỏ lần lượt chạy \(f\), hoàn toàn tránh được độ phức tạp bộ nhớ \(O(d^2)\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các bài 27-01 đến 27-03 trình bày nền tảng toán học của vi phân tự động: đồ thị tính toán, tích Jacobian–vector (JVP) ở chế độ thuận và tích vector–Jacobian (VJP) ở chế độ nghịch. Bài đọc tùy chọn này giới thiệu cách các chế độ đó được triển khai trong &lt;em&gt;hệ sinh thái phần mềm&lt;/em&gt; giai đoạn 2022–2026. Bài tổng quan của Baydin, Pearlmutter, Radul và Siskind (&lt;em&gt;JMLR&lt;/em&gt; 18(153), 2018, &lt;a href=&quot;https://www.jmlr.org/papers/v18/17-468.html&quot;&gt;jmlr.org/papers/v18/17-468.html&lt;/a&gt;) vẫn là tài liệu tham khảo lý thuyết chuẩn; còn các khung dưới đây là những công cụ được sử dụng trực tiếp trong thực tế.&lt;/p&gt;

&lt;h2 id=&quot;1-pytorch-chế-độ-nghịch-trên-băng-động-và-biên-dịch-đồ-thị&quot;&gt;1. PyTorch: chế độ nghịch trên băng động và biên dịch đồ thị&lt;/h2&gt;

&lt;p&gt;Paszke và cộng sự (&lt;em&gt;Automatic differentiation in PyTorch&lt;/em&gt;, hội thảo Autodiff NIPS 2017; &lt;em&gt;PyTorch: An Imperative Style, High-Performance Deep Learning Library&lt;/em&gt;, NeurIPS 2019) xây dựng AD chiều nghịch dựa trên băng tính toán động: chạy mã Python ở lượt thuận, ghi lại các nút &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grad_fn&lt;/code&gt; rồi phát ngược để tính đạo hàm. &lt;strong&gt;PyTorch 2.0&lt;/strong&gt; (2023) bổ sung &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.compile&lt;/code&gt; (TorchDynamo + Inductor), cho phép thu nhận và biên dịch cùng đồ thị chiều nghịch đó để tối ưu tốc độ mà vẫn bảo toàn cơ chế vi phân. Nguyên tắc kiểm chứng không đổi: nếu kết quả &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.autograd.grad&lt;/code&gt; lệch so với biến liên hợp tính tay, lỗi nằm ở cấu trúc đồ thị hoặc thao tác &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;detach&lt;/code&gt;. PyTorch phù hợp khi mô hình có đồ thị động, tận dụng hệ sinh thái thị giác máy tính / LLM và cần gỡ lỗi thuận tiện.&lt;/p&gt;

&lt;h2 id=&quot;2-jax-phép-biến-đổi-hàm-kết-hợp-jvp-và-vjp&quot;&gt;2. JAX: phép biến đổi hàm kết hợp JVP và VJP&lt;/h2&gt;

&lt;p&gt;Bradbury, Frostig, Hawkins, Johnson, Leary, Maclaurin, Necula, Paszke, VanderPlas, Wanderman-Milne và Zhang (&lt;em&gt;JAX: composable transformations of Python+NumPy programs&lt;/em&gt;, 2018–, &lt;a href=&quot;https://github.com/google/jax&quot;&gt;github.com/google/jax&lt;/a&gt;) thiết kế &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grad&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vmap&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jit&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pmap&lt;/code&gt; như các &lt;em&gt;phép biến đổi hàm thuần túy&lt;/em&gt;. Hai chế độ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.jvp&lt;/code&gt; (thuận) và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.vjp&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.grad&lt;/code&gt; (nghịch) được cung cấp trực tiếp ở mức API cốt lõi. Nhờ sử dụng mảng bất biến và hàm thuần, JAX trở thành lựa chọn phổ biến trong học máy khoa học giai đoạn 2022–2026 (mạng nơ-ron tích hợp vật lý, thế năng phân tử, mô phỏng khả vi): người dùng dễ dàng vector hóa một mô phỏng bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vmap&lt;/code&gt; rồi lấy đạo hàm bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grad&lt;/code&gt; và biên dịch qua XLA.&lt;/p&gt;

&lt;h2 id=&quot;3-enzyme-vi-phân-tự-động-ở-tầng-trình-biên-dịch&quot;&gt;3. Enzyme: vi phân tự động ở tầng trình biên dịch&lt;/h2&gt;

&lt;p&gt;Moses và Churavy (&lt;em&gt;Instead of rewriting foreign code for machine learning, automatically synthesize fast gradients&lt;/em&gt;, NeurIPS 2020) triển khai AD chiều nghịch trực tiếp trên &lt;strong&gt;LLVM IR&lt;/strong&gt;, giúp các chương trình viết bằng C++, Fortran, Julia và Rust có thể vi phân tự động mà không cần viết lại bằng Python. Các công trình tiếp theo — Moses, Churavy, Paehler và cộng sự (&lt;em&gt;Reverse-Mode Automatic Differentiation and Optimization of GPU Kernels via Enzyme&lt;/em&gt;, SC 2021) cùng Moses, Narayanan, Paehler và cộng sự (&lt;em&gt;Scalable Automatic Differentiation of Multiple Parallel Paradigms&lt;/em&gt;, SC 2022) — mở rộng phương pháp này sang CUDA, OpenMP, MPI và các tác vụ song song trong Julia. Giao diện Enzyme-JAX (từ 2023) cho phép đăng ký các kernel đó như phép toán nguyên thủy của JAX, giúp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.grad&lt;/code&gt; vi phân xuyên qua cả bộ giải truyền nhiệt viết bằng Fortran.&lt;/p&gt;

&lt;h2 id=&quot;4-học-máy-khoa-học-và-mạng-nơ-ron-tích-hợp-vật-lý-pinn&quot;&gt;4. Học máy khoa học và mạng nơ-ron tích hợp vật lý (PINN)&lt;/h2&gt;

&lt;p&gt;Một mạng nơ-ron tích hợp vật lý (Physics-Informed Neural Network — PINN) cực tiểu hóa phần dư phương trình vi phân \(r_\theta(x)=\mathcal{L}[u_\theta](x)\), trong đó các đạo hàm riêng theo &lt;em&gt;biến đầu vào&lt;/em&gt; \(x\) (không chỉ theo tham số \(\theta\)) đều được tính bằng AD. Công trình của Raissi, Perdikaris và Karniadakis (&lt;em&gt;J. Comput. Phys.&lt;/em&gt; 378:686–707, 2019) và bài tổng quan của Karniadakis, Kevrekidis, Lu, Perdikaris, Wang và Yang (&lt;em&gt;Nature Reviews Physics&lt;/em&gt; 3:422–440, 2021) đã đưa PINN thành một hướng nghiên cứu lớn. Các phát triển giai đoạn 2022–2025 (phần dư có trọng số nhân quả, học toán tử, mô phỏng lai Enzyme+JAX) đều kết hợp chế độ nghịch theo \(\theta\) với chế độ thuận hoặc nghịch lồng nhau theo \(x\). Đây là minh họa rõ ràng cho thấy “một hàm mất mát vô hướng với hàng triệu tham số” không phải là dạng truy vấn AD duy nhất trong thực tế.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# JAX: chế độ nghịch cho tham số, JVP chế độ thuận cho đạo hàm theo hướng
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loss&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loss&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ones&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# VJP cho hàm mất mát vô hướng
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jvp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;jvp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ones&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),))&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# đạo hàm theo hướng
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Cài đặt hàm \(f(w)=\|Aw-b\|_2^2\) bằng NumPy, PyTorch và (nếu có sẵn) JAX; đối chiếu công thức giải tích &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2 * A.T @ (A @ w - b)&lt;/code&gt; với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.autograd&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.grad&lt;/code&gt;. Tiếp theo, đo thời gian tính ma trận &lt;em&gt;Jacobian&lt;/em&gt; của một ánh xạ có ít đầu vào (ví dụ 2 hoặc 3 chiều) và 8 đầu ra bằng hai cách: (i) 8 lần gọi chế độ nghịch theo từng đầu ra và (ii) các lần gọi JVP chế độ thuận theo từng đầu vào — chế độ thuận sẽ nhanh hơn, minh họa trực tiếp phân tích độ phức tạp ở mục 27-02.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;A. G. Baydin et al., &lt;em&gt;JMLR&lt;/em&gt; 18(153), 2018 — khảo sát AD.&lt;/li&gt;
  &lt;li&gt;A. Paszke et al., NeurIPS 2019 — PyTorch.&lt;/li&gt;
  &lt;li&gt;J. Bradbury et al., 2018– — JAX.&lt;/li&gt;
  &lt;li&gt;W. S. Moses and V. Churavy, NeurIPS 2020; Moses et al., SC 2021 &amp;amp; SC 2022 — Enzyme.&lt;/li&gt;
  &lt;li&gt;M. Raissi, P. Perdikaris, G. E. Karniadakis, &lt;em&gt;J. Comput. Phys.&lt;/em&gt; 378, 2019 — PINN.&lt;/li&gt;
  &lt;li&gt;G. E. Karniadakis et al., &lt;em&gt;Nat. Rev. Phys.&lt;/em&gt; 3:422–440, 2021 — khảo sát ML thông tin vật lý.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>26-06 Bộ tối ưu thích nghi hiện đại (seminar)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_06_modern_optimizers/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_06_modern_optimizers</id>
   <content type="html">&lt;p&gt;Suốt nửa thập kỷ qua, &lt;strong&gt;AdamW&lt;/strong&gt; đứng vững như một tượng đài bất khả xâm phạm trong huấn luyện mô hình ngôn ngữ lớn (LLM) và mô hình thị giác. Nhưng khi chi phí một lần huấn luyện chạm mốc hàng chục triệu đô la, chỉ cần giảm \(20\%\) số bước hội tụ hoặc tìm được vùng cực tiểu phẳng tổng quát hóa tốt hơn cũng mang lại giá trị khổng lồ.&lt;/p&gt;

&lt;p&gt;Bài seminar này mở cánh cửa vào phòng thí nghiệm tối ưu hóa giai đoạn 2021–2026, nơi các nhà nghiên cứu đặt câu hỏi: &lt;em&gt;nếu AdamW chỉ dùng độ cong đường chéo bậc nhất, ta sẽ thu được gì khi đưa thêm hình học lân cận (SAM), độ cong Hessian bậc hai giá rẻ (Sophia), trực giao hóa ma trận trọng số (Muon) hay loại bỏ hoàn toàn lịch tốc độ học (Schedule-Free)?&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-hướng-đột-phá-vượt-ra-ngoài-adamw&quot;&gt;Kiến thức cần nhớ: Bốn hướng đột phá vượt ra ngoài AdamW&lt;/h2&gt;

&lt;p&gt;Bốn bộ tối ưu hiện đại trong bài đại diện cho bốn góc nhìn hình học khác nhau lên cùng một bề mặt hàm mất mát:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;SAM (Sharpness-Aware Minimization — Hình học Minimax):&lt;/strong&gt; Thay vì chỉ tìm điểm có \(F(w)\) nhỏ, SAM tìm điểm mà &lt;em&gt;mọi điểm xung quanh trong bán kính \(\rho\)&lt;/em&gt; đều có hàm mất mát nhỏ, chủ động né tránh các “hố nhọn” dễ overfitting để đáp xuống các thung lũng phẳng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sophia (Tiền điều kiện bậc hai nhẹ):&lt;/strong&gt; Thay ước lượng bình phương gradient \(v_k\) (vốn chỉ phản ánh độ lớn gradient chứ không phải độ cong thực) bằng ước lượng đường chéo Hessian \(h_k\) tính bằng thuật toán Hutchinson hoặc Gauss–Newton, kết hợp cắt ngưỡng để tránh nổ bước ở vùng độ cong âm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Muon (Tối ưu trên cấu trúc Ma trận — Spectral Geometry):&lt;/strong&gt; Nhận ra trọng số của lớp tuyến tính là &lt;em&gt;ma trận&lt;/em&gt; chứ không phải vector phẳng; Muon dùng phép lặp Newton–Schulz để xấp xỉ cực trực giao (orthogonalize) của ma trận động lượng, ép mọi giá trị kỳ dị của bước cập nhật đều nhau (tương đương xuống dốc theo chuẩn phổ).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Schedule-Free AdamW (Bỏ lịch giảm \(\eta\) bằng Nội suy Polyak–Ruppert):&lt;/strong&gt; Thay vì phải đoán trước tổng số bước \(T\) để cài lịch cosine decay, phương pháp duy trì cặp điểm nội suy giúp tự động đạt hiệu ứng tương đương lịch giảm tốc độ học mà có thể dừng bất cứ lúc nào.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-1-bước-sam-để-thấy-nó-né-vách-dốc-nhọn-như-thế-nào&quot;&gt;Giải thích: Tính tay 1 bước SAM để thấy nó né “vách dốc nhọn” như thế nào&lt;/h3&gt;

&lt;p&gt;Để hiểu trực giác 2-bước của SAM (bước 1: leo lên điểm xấu nhất trong bán kính \(\rho\); bước 2: dùng gradient tại điểm xấu nhất đó để kéo \(w\) xuống), hãy xét hàm 1 chiều bất đối xứng:&lt;/p&gt;

\[F(w) = \frac{1}{2}w^2 + \frac{1}{3}w^3, \qquad F&apos;(w) = w + w^2, \qquad F&apos;&apos;(w) = 1 + 2w.\]

&lt;p&gt;Chú ý rằng bên phải \(w &amp;gt; 0\) hàm cong dựng đứng rất nhanh (\(F&apos;&apos;(w)\) tăng mạnh), còn bên trái \(w \in (-0.5, 0)\) hàm phẳng hơn nhiều. Xuất phát từ \(w_0 = 1.0\) với bán kính SAM \(\rho = 0.5\) và tốc độ học \(\eta = 0.1\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;So sánh với bước Gradient Descent thường tại \(w_0 = 1.0\):&lt;/strong&gt;
Gradient tại chỗ: \(F&apos;(1.0) = 1 + 1 = 2.0\).
GD bước xuống: \(w_1^{\text{GD}} = 1.0 - 0.1(2.0) = 0.80\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thực hiện 2 pha của SAM tại \(w_0 = 1.0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Pha 1 (Bước đối kháng — leo lên tìm điểm xấu nhất trong lân cận \(\rho = 0.5\)):&lt;/em&gt;
\(\hat{\varepsilon} = \rho \frac{F&apos;(1.0)}{|F&apos;(1.0)|} = 0.5 \cdot \frac{2.0}{2.0} = +0.5 \implies w_{\text{adv}} = 1.0 + 0.5 = 1.5.\)&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Pha 2 (Tính gradient tại \(w_{\text{adv}} = 1.5\) rồi cập nhật từ gốc \(w_0\)!):&lt;/em&gt;
\(F&apos;(1.5) = 1.5 + (1.5)^2 = 1.5 + 2.25 = 3.75.\)
Cập nhật SAM: \(w_1^{\text{SAM}} = w_0 - \eta F&apos;(w_{\text{adv}}) = 1.0 - 0.1(3.75) = 0.625!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan sát sắc nét:&lt;/strong&gt; Vì phía bên phải \(w_0\) có vách dốc dựng đứng, điểm thăm dò \(w_{\text{adv}} = 1.5\) lập tức cảm nhận được độ dốc khổng lồ \(3.75\) (gần gấp đôi \(2.0\)) và &lt;strong&gt;đẩy mạnh \(w\) lùi về vùng phẳng hơn&lt;/strong&gt; (\(0.625\) so với \(0.80\)). Chi phí là 2 lần tính gradient mỗi bước, đổi lại là khả năng tự động tìm đáy phẳng!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các bài từ 26-01 đến 26-05 bao quát bộ công cụ cốt lõi trong chương trình: SGD, momentum theo trực giác Distill, AdaGrad → Adam, &lt;strong&gt;AdamW&lt;/strong&gt;, cùng SVRG và SAGA. Bài seminar tùy chọn này điểm qua các bộ tối ưu hiện đại giai đoạn 2021–2026 ở mức &lt;em&gt;công thức cập nhật&lt;/em&gt; — trình bày ngắn gọn từng phương pháp để đặt SAM, Sophia và Muon lên cùng bảng so sánh với AdamW. Cơ chế tách weight decay đã trình bày ở &lt;a href=&quot;/contents/vi/chapter26/26_04_adamw_and_practice/&quot;&gt;26-04&lt;/a&gt;, còn góc nhìn tiền điều kiện Hessian của Sophia như họ hàng phương pháp Newton nằm ở &lt;a href=&quot;/contents/vi/chapter14/14_10_modern_applications/&quot;&gt;14-10&lt;/a&gt;. Cả ba phương pháp trong bài này đều không thuộc nội dung kiểm tra.&lt;/p&gt;

&lt;p&gt;Câu hỏi trọng tâm của seminar là: &lt;em&gt;sau khi AdamW trở thành tiêu chuẩn mặc định, cộng đồng huấn luyện mô hình lớn đang thử nghiệm những bộ tối ưu nào, và mỗi phương pháp khai thác thêm cấu trúc hình học gì?&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;adamw-vẫn-là-chuẩn-đối-chiếu&quot;&gt;AdamW vẫn là chuẩn đối chiếu&lt;/h2&gt;

&lt;p&gt;AdamW (Loshchilov &amp;amp; Hutter, ICLR 2019, &lt;a href=&quot;https://arxiv.org/abs/1711.05101&quot;&gt;arXiv:1711.05101&lt;/a&gt;) vẫn là bộ tối ưu chuẩn trong các công thức huấn luyện mô hình ngôn ngữ lớn kiểu Llama hay GPT: \(\eta\) cỡ \(10^{-4}\), \(\beta=(0.9,0.95)\) hoặc \((0.9,0.999)\), hệ số suy giảm trọng số tách rời \(\lambda\approx 0.1\), kết hợp warmup và lịch giảm cosine. Mọi bộ tối ưu dưới đây đều được đánh giá dựa trên chuẩn đối chiếu này.&lt;/p&gt;

&lt;h2 id=&quot;sam-cực-đại-hóa-cục-bộ-trước-khi-hạ-bước&quot;&gt;SAM: cực đại hóa cục bộ trước khi hạ bước&lt;/h2&gt;

&lt;p&gt;Sharpness-Aware Minimization (Foret, Kleiner, Mobahi, Neyshabur, ICLR 2021, &lt;a href=&quot;https://openreview.net/forum?id=6Tm1mposlrM&quot;&gt;OpenReview&lt;/a&gt;) thay mục tiêu rủi ro tại một điểm \(F(w)\) bằng giá trị xấu nhất trong một &lt;em&gt;lân cận bán kính \(\rho\)&lt;/em&gt;:&lt;/p&gt;

\[\min_w\ \max_{\|\varepsilon\|_2\le\rho} F(w+\varepsilon)
\approx F\bigl(w+\rho\,\nabla F(w)/\|\nabla F(w)\|_2\bigr).\]

&lt;p&gt;Mỗi bước cập nhật của SAM thực hiện hai lượt tính gradient chứ không tạo ma trận tiền điều kiện mới:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước nhiễu (ascent):&lt;/strong&gt; Tính \(g\leftarrow\nabla F(w)\), sau đó đặt \(\varepsilon\leftarrow\rho\,g/\|g\|_2\) (hoặc dạng tổng quát theo chuẩn đối ngẫu).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước hạ (SAM gradient):&lt;/strong&gt; Tính \(g_{\mathrm{SAM}}\leftarrow\nabla F(w+\varepsilon)\) và cập nhật \(w\leftarrow w-\eta\,g_{\mathrm{SAM}}\) (hoặc đưa \(g_{\mathrm{SAM}}\) vào bộ tối ưu nền như AdamW hay SGD+momentum).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Bước nhiễu hướng quá trình tối ưu về các cực tiểu &lt;strong&gt;phẳng&lt;/strong&gt;, nơi hàm mất mát ít tăng khi tham số dao động trong một hình cầu nhỏ quanh \(w\). Bartlett, Long và Bousquet (&lt;em&gt;The Dynamics of Sharpness-Aware Minimization&lt;/em&gt;, &lt;em&gt;JMLR&lt;/em&gt; 24(43), 2023) chứng minh rằng gần một cực tiểu trơn, bước bổ sung này tạo ra dao động dọc phương Hessian có độ cong lớn nhất kèm xu hướng &lt;em&gt;giảm&lt;/em&gt; \(\|\nabla^2 F\|\). Shin, Lee, Andriushchenko và Lee (&lt;a href=&quot;https://arxiv.org/abs/2311.17539&quot;&gt;arXiv:2311.17539&lt;/a&gt;) ghi nhận lợi ích tổng quát hóa của SAM &lt;em&gt;tăng&lt;/em&gt; khi mô hình quá tham số hóa — kết nối trực tiếp với Chương 28 và điều kiện PL ở &lt;a href=&quot;/contents/vi/chapter28/28_05_pl_condition/&quot;&gt;28-05&lt;/a&gt;. Trong thực tế, SAM thường dùng cho thị giác máy tính và tinh chỉnh mô hình; tiền huấn luyện LLM đầy đủ thường tránh dùng vì chi phí tính gradient tăng gấp đôi. Các biến thể bán kính thích nghi (ASAM, GSAM) chỉ thay đổi hình dạng lân cận, giữ nguyên cấu trúc hai bước.&lt;/p&gt;

&lt;h2 id=&quot;sophia-adamw-với-ước-lượng-hessian-đường-chéo-có-cắt-ngưỡng&quot;&gt;Sophia: AdamW với ước lượng Hessian đường chéo có cắt ngưỡng&lt;/h2&gt;

&lt;p&gt;Liu, Li, Hall, Liang và Ma (&lt;em&gt;Sophia&lt;/em&gt;, ICLR 2024, &lt;a href=&quot;https://openreview.net/forum?id=3xHDeA8Noi&quot;&gt;OpenReview&lt;/a&gt;) giữ nguyên mô-men bậc nhất kiểu Adam nhưng thay bộ tích lũy mô-men bậc hai bằng ước lượng đường chéo của ma trận Hessian kèm phép &lt;em&gt;cắt ngưỡng&lt;/em&gt;. Gọi \(m\) là trung bình trượt mũ của gradient và \(\hat h\) là trung bình trượt mũ của ước lượng độ cong đường chéo:&lt;/p&gt;

\[w\leftarrow w-\eta\cdot\operatorname{clip}\bigl(m/(\hat h+\varepsilon),\,\tau\bigr),\]

&lt;p&gt;trong đó \(\hat h\) chỉ cần cập nhật định kỳ sau mỗi vài bước (bằng tích Hessian–vector Hutchinson hoặc ước lượng Gauss–Newton–Bartlett lấy mẫu nhãn từ đầu ra mô hình rồi bình phương gradient). Phép cắt ngưỡng đóng vai trò vùng tin cậy nhằm ngăn bước cập nhật bùng nổ khi ước lượng đường chéo cũ hoặc không xác định dương. Có thể xem Sophia như “AdamW với mẫu số mang thông tin độ cong” thay vì phương pháp Newton đầy đủ (phần thảo luận về bất biến affine và Hessian nằm ở mục 14-10). Các tác giả báo cáo Sophia cần ít bước hơn AdamW trong tiền huấn luyện mô hình ngôn ngữ với chi phí bổ sung mỗi bước tương đối nhỏ.&lt;/p&gt;

&lt;h2 id=&quot;muon-trực-giao-hóa-bước-cập-nhật-cho-ma-trận-trọng-số-ẩn&quot;&gt;Muon: trực giao hóa bước cập nhật cho ma trận trọng số ẩn&lt;/h2&gt;

&lt;p&gt;Jordan, Jin, Boza, Cesista, Newhouse và Bernstein (&lt;em&gt;Muon&lt;/em&gt;, 2024, &lt;a href=&quot;https://kellerjordan.github.io/posts/muon/&quot;&gt;kellerjordan.github.io/posts/muon&lt;/a&gt;) áp dụng momentum Nesterov lên từng tham số dạng &lt;em&gt;ma trận&lt;/em&gt; \(W\in\mathbb{R}^{m\times n}\) rồi thay hướng cập nhật bằng ma trận trực giao gần nhất, tính xấp xỉ qua vài vòng lặp Newton–Schulz (không cần SVD):&lt;/p&gt;

\[\begin{align}
B &amp;amp;\leftarrow \beta B+\nabla_W F,\\
O &amp;amp;\leftarrow \operatorname{NewtonSchulz}(B)\approx\arg\min_{Q^\top Q=I}\|Q-B\|_F,\\
W &amp;amp;\leftarrow W-\eta\,O.
\end{align}\]

&lt;p&gt;Các lớp nhúng (embedding), lớp đầu ra và tham số vector vẫn dùng AdamW: các ma trận trọng số ẩn 2 chiều hưởng lợi từ bước cập nhật trực giao (chuẩn phổ gần như đồng nhất giữa các phương), trong khi bảng nhúng token có cấu trúc cập nhật thưa theo hàng không phù hợp với trực giao hóa. Sau khi trở nên phổ biến trong cộng đồng tối ưu tốc độ huấn luyện NanoGPT cuối năm 2024, Jingyuan Liu và cộng sự (&lt;em&gt;Muon is Scalable for LLM Training&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2502.16982&quot;&gt;arXiv:2502.16982&lt;/a&gt;, 2025) bổ sung weight decay và hệ số tỉ lệ theo kích thước tham số, huấn luyện mô hình MoE 3B/16B (Moonlight) trên 5,7 nghìn tỷ token và báo cáo hiệu quả tính toán gấp khoảng \(2\times\) AdamW trên đường cong định luật tỉ lệ. Shah và cộng sự (&lt;a href=&quot;https://arxiv.org/abs/2505.02222&quot;&gt;arXiv:2505.02222&lt;/a&gt;, 2025) tiếp tục khảo sát biên Pareto đánh đổi giữa chi phí tính toán và thời gian đến quy mô 4 tỷ tham số. Đây là đối thủ &lt;em&gt;nhận biết cấu trúc ma trận&lt;/em&gt; đáng chú ý đầu tiên đối với tiền điều kiện đường chéo của AdamW.&lt;/p&gt;

&lt;p&gt;Vòng lặp Newton–Schulz thực chất là một phép lặp đa thức chi phí thấp trên \(X^\top X\) nhằm kéo các giá trị kỳ dị về \(1\). Điểm cốt lõi cần nhớ là: &lt;strong&gt;Muon tiền điều kiện bằng nhân tử cực (polar factor) của ma trận, còn AdamW tiền điều kiện bằng căn trung bình bình phương (RMS) từng tọa độ&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;adamw-không-cần-lịch-tốc-độ-học-schedule-free-adamw&quot;&gt;AdamW không cần lịch tốc độ học (Schedule-free AdamW)&lt;/h2&gt;

&lt;p&gt;Defazio và cộng sự (2024) đề xuất phiên bản AdamW &lt;em&gt;không dùng lịch giảm tốc độ học&lt;/em&gt; bằng cách thay lịch giảm \(\eta_t\) bởi cơ chế lấy trung bình Polyak–Ruppert nội suy. Đây là tài liệu tham khảo tốt cho seminar; phần ghi chú tùy chọn ở &lt;a href=&quot;/contents/vi/chapter06/06_08_Applications_Recent/&quot;&gt;06-08&lt;/a&gt; cũng đã đặt phương pháp này cạnh Lion và hiện tượng mép ổn định (edge of stability).&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Chi phí / bộ nhớ thêm&lt;/th&gt;
      &lt;th&gt;Cấu trúc hình học khai thác&lt;/th&gt;
      &lt;th&gt;Ứng dụng điển hình&lt;/th&gt;
      &lt;th&gt;Kiểm tra?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;AdamW&lt;/td&gt;
      &lt;td&gt;hai trung bình trượt mũ&lt;/td&gt;
      &lt;td&gt;RMS theo từng tọa độ&lt;/td&gt;
      &lt;td&gt;chuẩn mặc định cho LLM / thị giác&lt;/td&gt;
      &lt;td&gt;có (26-04)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SAM&lt;/td&gt;
      &lt;td&gt;gấp đôi lượt tính gradient&lt;/td&gt;
      &lt;td&gt;cực tiểu phẳng (bài toán max cục bộ)&lt;/td&gt;
      &lt;td&gt;thị giác, tinh chỉnh mô hình&lt;/td&gt;
      &lt;td&gt;không&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Sophia&lt;/td&gt;
      &lt;td&gt;ước lượng Hessian đường chéo + cắt ngưỡng&lt;/td&gt;
      &lt;td&gt;mẫu số mang thông tin độ cong&lt;/td&gt;
      &lt;td&gt;thử nghiệm tiền huấn luyện LM&lt;/td&gt;
      &lt;td&gt;không&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Muon&lt;/td&gt;
      &lt;td&gt;lặp Newton–Schulz trên ma trận ẩn&lt;/td&gt;
      &lt;td&gt;bước cập nhật trực giao / cực&lt;/td&gt;
      &lt;td&gt;NanoGPT, một số cấu hình tiền huấn luyện LLM&lt;/td&gt;
      &lt;td&gt;không&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Bài tập (khảo sát lý thuyết).&lt;/strong&gt; Đọc phần giải thích trong bài viết Muon về lý do “dùng AdamW cho lớp nhúng và đầu ra” rồi trả lời ngắn gọn bốn ý: (i) vì sao ma trận trọng số ẩn 2 chiều phù hợp với bước cập nhật trực giao, (ii) vì sao bảng nhúng token lại không phù hợp, (iii) cơ chế này khác gì với hệ số \(1/\sqrt{\hat v}\) &lt;em&gt;từng tọa độ&lt;/em&gt; của AdamW, và (iv) vì sao bài toán cực đại hóa cục bộ của SAM phản ánh tính chất &lt;em&gt;địa hình hàm mất mát&lt;/em&gt; (Chương 28) hơn là phép tiền điều kiện.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Trong ba phương pháp (SAM, Sophia, Muon), phương pháp nào vẫn hoạt động được nếu chỉ cho phép tính đúng &lt;em&gt;một&lt;/em&gt; gradient ở mỗi bước, và nó gần với thành phần nào nhất của Chương 26 (momentum, mô-men bậc hai đường chéo, hay giảm phương sai)?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;I. Loshchilov and F. Hutter, ICLR 2019 — AdamW.&lt;/li&gt;
  &lt;li&gt;P. Foret, A. Kleiner, H. Mobahi, B. Neyshabur, ICLR 2021 — SAM.&lt;/li&gt;
  &lt;li&gt;P. L. Bartlett et al., &lt;em&gt;JMLR&lt;/em&gt; 24(43), 2023 — động lực học SAM.&lt;/li&gt;
  &lt;li&gt;H. Liu et al., ICLR 2024 — Sophia (cập nhật ở đây; đọc Newton ở 14-10).&lt;/li&gt;
  &lt;li&gt;K. Jordan et al., 2024 — Muon.&lt;/li&gt;
  &lt;li&gt;Jingyuan Liu et al., &lt;a href=&quot;https://arxiv.org/abs/2502.16982&quot;&gt;arXiv:2502.16982&lt;/a&gt;, 2025 — Muon ở quy mô LLM.&lt;/li&gt;
  &lt;li&gt;I. Shah et al., &lt;a href=&quot;https://arxiv.org/abs/2505.02222&quot;&gt;arXiv:2505.02222&lt;/a&gt;, 2025 — hiệu quả tiền huấn luyện Muon.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>25-03 Ứng dụng hiện đại của MIP trong khoa học dữ liệu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_03_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_03_modern_applications</id>
   <content type="html">&lt;p&gt;Nếu bạn nghĩ rằng mặt phẳng cắt và mã hóa big-\(M\) chỉ thuộc về lĩnh vực hậu cần hay thống kê cổ điển, hãy nhìn vào một trong những câu hỏi nóng nhất của an toàn trí tuệ nhân tạo hiện nay: &lt;em&gt;làm sao để chứng minh toán học 100% rằng không tồn tại bất kỳ nhiễu pixel nào trong bán kính \(\varepsilon\) có thể đánh lừa một mạng nơ-ron ReLU nhận diện nhầm biển báo “STOP” thành biển “Giới hạn tốc độ”?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Các phương pháp tấn công thử-sai (như PGD attack) chỉ có thể tìm ra lỗi chứ không bao giờ &lt;em&gt;chứng nhận&lt;/em&gt; được sự an toàn. Ngược lại, vì mỗi nút ReLU \(\max(0, a)\) là một hàm tuyến tính từng khúc hai nhánh, toàn bộ mạng ReLU có thể được mã hóa chính xác thành một &lt;strong&gt;bài toán MILP&lt;/strong&gt; — biến công cụ Chương 25 thành chiếc chìa khóa cho cả kiểm chứng độ bền vững mạng nơ-ron, chọn đặc trưng đầu vào, lẫn xây dựng cây quyết định tối ưu!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-ứng-dụng-mũi-nhọn-của-mip-trong-khoa-học-dữ-liệu&quot;&gt;Kiến thức cần nhớ: Bốn nhánh ứng dụng mũi nhọn của MIP trong Khoa học Dữ liệu&lt;/h2&gt;

&lt;p&gt;Bài đọc này tổng kết bốn hướng giao thoa sôi động nhất giữa MIP và học máy giai đoạn 2019–2026:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng chính thức mạng ReLU (MILP Verification):&lt;/strong&gt; Biến bài toán tìm nhiễu đối kháng xấu nhất thành MILP bằng biến nhị phân chỉ trạng thái bật/tắt của từng nơ-ron ReLU; các thuật toán cắt và thắt chặn (bound tightening) giúp chứng nhận mạng hàng trăm nghìn nơ-ron.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn đặc trưng hậu huấn luyện (Model-Based Feature Selection):&lt;/strong&gt; Áp dụng cùng cách mã hóa MILP cho mạng đã huấn luyện để tìm tập con đầu vào nhỏ nhất vẫn bảo toàn độ tin cậy phân lớp — phiên bản phi tuyến của Best Subset Selection.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cây quyết định tối ưu (Optimal Classification Trees — OCT):&lt;/strong&gt; Thay vì dựng cây tham lam từng nút một như CART (dễ rơi vào cực tiểu cục bộ), OCT tối ưu đồng thời &lt;em&gt;toàn bộ&lt;/em&gt; cấu trúc cây có độ sâu cố định bằng MILP, đạt độ chính xác cao hơn mà vẫn giữ nguyên tính diễn giải trực quan.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học chọn mặt phẳng cắt (Learning to Cut):&lt;/strong&gt; Khi bộ giải sinh ra hàng trăm lát cắt ứng viên (Gomory, MIR) tại mỗi nút, mạng nơ-ron học tăng cường hoặc học bắt chước sẽ chọn ra đúng vài lát cắt sắc bén nhất để vừa siết chặt cận dưới vừa giữ bảng đơn hình thưa và nhanh.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-mã-hóa-chính-xác-một-nơ-ron-relu-bằng-4-bất-đẳng-thức-tuyến-tính&quot;&gt;Giải thích: Mã hóa chính xác một nơ-ron ReLU bằng 4 bất đẳng thức tuyến tính&lt;/h3&gt;

&lt;p&gt;Đây là viên gạch nền tảng của cả bài toán kiểm chứng mạng nơ-ron (Tjeng–Xiao–Tedrake, ICLR 2019) lẫn chọn đặc trưng cho mạng ReLU. Xét một nơ-ron \(h = \max(0, a)\) trong đó đầu vào trước kích hoạt \(a = w^T x + b\) đã được chặn chặt trong khoảng \([l, u] = [-2,\; 3]\) (với \(l &amp;lt; 0 &amp;lt; u\)).&lt;/p&gt;

&lt;p&gt;Ta đưa vào đúng 1 biến nhị phân \(z \in \{0, 1\}\) (\(z = 0\) ứng với nhánh tắt \(a \le 0\), \(z = 1\) ứng với nhánh bật \(a \ge 0\)) cùng 4 bất đẳng thức tuyến tính:&lt;/p&gt;

\[h \ge 0, \qquad h \ge a, \qquad h \le 3z, \qquad h \le a + 2(1 - z).\]

&lt;p&gt;Hãy kiểm tra tính chính xác tuyệt đối ở cả hai trường hợp:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 1 — Đầu vào âm, giả sử \(a = -1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu chọn \(z = 1\): bất đẳng thức thứ tư thành \(h \le -1 + 2(0) = -1\), mâu thuẫn ngay với \(h \ge 0\) — &lt;strong&gt;bị loại trừ!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;Bắt buộc \(z = 0\): bốn bất đẳng thức trở thành \(h \ge 0,\; h \ge -1,\; h \le 0,\; h \le 1\), ép duy nhất &lt;strong&gt;\(h = 0 = \max(0, -1)\)&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 2 — Đầu vào dương, giả sử \(a = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu chọn \(z = 0\): bất đẳng thức thứ ba thành \(h \le 0\), mâu thuẫn ngay với \(h \ge 2\) — &lt;strong&gt;bị loại trừ!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;Bắt buộc \(z = 1\): bốn bất đẳng thức trở thành \(h \ge 0,\; h \ge 2,\; h \le 3,\; h \le 2\), ép duy nhất &lt;strong&gt;\(h = 2 = \max(0, 2)\)&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bí mật về độ chặt của cận \([l, u]\):&lt;/strong&gt; Nếu ta dùng số \(l = -1000, u = 1000\) cẩu thả thay vì \([-2, 3]\), nới lỏng LP sẽ tạo ra một tam giác khổng lồ lỏng lẻo; ngược lại, thắt chặt \([l, u]\) cho từng nơ-ron chính là cách sinh ra các mặt phẳng cắt cực sắc giúp MILP kiểm chứng mạng sâu nhanh gấp hàng nghìn lần!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chương 25 tập trung vào phía &lt;em&gt;bộ giải&lt;/em&gt; của quy hoạch nguyên hỗn hợp: mặt phẳng cắt, thuật toán nhánh và cắt, cùng hai ví dụ thống kê mở rộng (chọn tập con tốt nhất và hồi quy phân vị nhỏ nhất). Trong giai đoạn 2022–2026, các kỹ thuật này tiếp tục được ứng dụng để &lt;em&gt;chọn đặc trưng&lt;/em&gt; cho mạng nơ-ron, &lt;em&gt;chứng nhận&lt;/em&gt; độ bền vững đối kháng, &lt;em&gt;xây dựng cây quyết định tối ưu&lt;/em&gt; và thậm chí &lt;em&gt;học chiến lược chọn mặt phẳng cắt&lt;/em&gt;. Bài đọc tùy chọn này tổng hợp bốn hướng ứng dụng đó mà không lặp lại phần suy diễn lát cắt Gomory.&lt;/p&gt;

&lt;h2 id=&quot;1-chọn-tập-con-tốt-nhất-ví-dụ-tiêu-biểu-của-mip-trong-thống-kê&quot;&gt;1. Chọn tập con tốt nhất: ví dụ tiêu biểu của MIP trong thống kê&lt;/h2&gt;

&lt;p&gt;Bài toán bình phương tối thiểu ràng buộc chuẩn giả \(\ell_0\) ở mục 25-02-01 có dạng:&lt;/p&gt;

\[\min_\beta\ \tfrac12\|y-X\beta\|_2^2\qquad\text{subject to}\qquad \|\beta\|_0\le k,\]

&lt;p&gt;có thể viết lại bằng kỹ thuật big-\(M\) với biến nhị phân \(z_i\). Bertsimas, King và Mazumder (&lt;em&gt;Ann. Statist.&lt;/em&gt; 44(2):813–852, 2016) cho thấy các bộ giải MIP hiện đại kết hợp khởi động nóng đã vượt qua quan niệm cũ rằng bài toán này bất khả thi khi \(p&amp;gt;30\). Bối cảnh so sánh trong thập niên 2020 không còn đơn giản là MIP đối đầu với Lasso: đó là sự cân nhắc giữa MIP, hạ theo tọa độ dọc đường tham số (Chương 23) và các hàm phạt không lồi (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt;) ở quy mô hàng trăm đặc trưng, trong đó MIP mang lại &lt;em&gt;chứng nhận tối ưu&lt;/em&gt; khi khoảng cách cận (MIP gap) khép kín. Trong thực hành, Lasso hoặc elastic net phù hợp cho bước thăm dò nhanh, còn MIP chọn tập con tốt nhất hữu ích khi bài toán yêu cầu chính xác \(k\) đặc trưng kèm cận dưới tối ưu có chứng nhận.&lt;/p&gt;

&lt;h2 id=&quot;2-chọn-đặc-trưng-cho-mạng-nơ-ron-đã-huấn-luyện&quot;&gt;2. Chọn đặc trưng cho mạng nơ-ron đã huấn luyện&lt;/h2&gt;

&lt;p&gt;Zhao, Tsay và Kronqvist (&lt;em&gt;Model-based feature selection for neural networks: A mixed-integer programming approach&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2302.10344&quot;&gt;arXiv:2302.10344&lt;/a&gt;, 2023) mã hóa một mạng ReLU đã huấn luyện thành bài toán MILP và giải một chuỗi MILP nhằm tìm &lt;em&gt;tập đầu vào thưa&lt;/em&gt; cực đại hóa độ tin cậy phân lớp dưới ràng buộc về số lượng và phân phối. Trên MNIST và Fashion-MNIST, nhóm tác giả giữ lại khoảng 15% số điểm ảnh để huấn luyện lại mạng nhỏ gọn hơn và ít nhạy cảm với tấn công đối kháng hơn. Đây chính là tư duy chọn tập con tốt nhất áp dụng cho &lt;em&gt;đầu vào&lt;/em&gt; của mạng nơ-ron tuyến tính từng khúc — sử dụng cùng cách mã hóa MILP như trong bài toán kiểm chứng bên dưới.&lt;/p&gt;

&lt;h2 id=&quot;3-kiểm-chứng-mạng-relu-bằng-milp&quot;&gt;3. Kiểm chứng mạng ReLU bằng MILP&lt;/h2&gt;

&lt;p&gt;Một nút kích hoạt ReLU \(h=\max(0,Wx+b)\) có thể mã hóa chính xác bằng ràng buộc tuyến tính nguyên hỗn hợp (sử dụng biến nhị phân chỉ trạng thái kích hoạt và kỹ thuật big-\(M\) hoặc công thức chặt hơn). Khi đó, câu hỏi “liệu có tồn tại nhiễu trong bán kính \(\varepsilon\) làm đảo nhãn dự đoán không?” trở thành một bài toán MILP. Tjeng, Xiao và Tedrake (&lt;em&gt;Evaluating Robustness of Neural Networks with Mixed Integer Programming&lt;/em&gt;, ICLR 2019, &lt;a href=&quot;https://openreview.net/forum?id=HyGIdiRqtm&quot;&gt;OpenReview&lt;/a&gt;) kết hợp mã hóa chặt với kỹ thuật thắt chặn dần và kiểm chứng được các mạng trên MNIST có hơn \(10^5\) đơn vị, nhanh hơn nhiều bậc so với bộ kiểm chứng SMT Reluplex; bài báo của Fischetti và Jo (2018) là nghiên cứu song hành từ góc nhìn vận trù học. Các công trình giai đoạn 2022–2025 (bất đẳng thức ReLU chặt hơn, phân tích phụ thuộc, lan truyền cận trên GPU) đều xây dựng trên nền tảng này: mỗi “lát cắt” chính là một bất đẳng thức tuyến tính hợp lệ mà phép biến đổi ReLU phải thỏa mãn.&lt;/p&gt;

&lt;h2 id=&quot;4-cây-phân-loại-tối-ưu-và-học-chọn-mặt-phẳng-cắt&quot;&gt;4. Cây phân loại tối ưu và học chọn mặt phẳng cắt&lt;/h2&gt;

&lt;p&gt;Bertsimas và Dunn (&lt;em&gt;Machine Learning&lt;/em&gt; 106:1039–1082, 2017) mô hình hóa toàn bộ cây quyết định dưới dạng MIP (Optimal Classification Trees — OCT). Hua, Ren và Cao (NeurIPS 2022, &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/37771cc0be272368102a37f202bb88d8-Abstract-Conference.html&quot;&gt;bài báo&lt;/a&gt;) đề xuất thuật toán nhánh và cận trên không gian thu gọn (RS-OCT), mở rộng quy mô OCT lên các bảng dữ liệu hàng trăm nghìn dòng và đạt độ chính xác kiểm tra cao hơn các phương pháp MIP-OCT trước đó trên các tập UCI lớn. Các mô hình cây tối ưu hàm mất mát logistic (TOP, 2024) giữ cùng cấu trúc MILP và thay hàm mất mát phân loại sai bằng xấp xỉ tuyến tính từng khúc của hàm mất mát logistic.&lt;/p&gt;

&lt;p&gt;Ở góc độ &lt;em&gt;bộ giải&lt;/em&gt;, hướng nghiên cứu &lt;strong&gt;học chọn mặt phẳng cắt&lt;/strong&gt; (chẳng hạn HGTSM, &lt;a href=&quot;https://arxiv.org/abs/2410.03112&quot;&gt;arXiv:2410.03112&lt;/a&gt;, 2024) huấn luyện mô hình đồ thị dị chất trên MIPLIB 2017 và các bộ bài toán ML4CO để tự động lựa chọn chuỗi mặt phẳng cắt thay cho heuristic viết tay — biến chính thuật toán mặt phẳng cắt của mục 25-01 thành dữ liệu huấn luyện cho học máy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Mã hóa một mạng ReLU hai lớp cỡ nhỏ \(f(x)=W_2\,\mathrm{ReLU}(W_1 x)\) với \(W_1\in\mathbb{R}^{3\times 2}\) thành bài toán MILP (dùng 3 biến nhị phân cho ba đơn vị ẩn). Cực đại hóa \(f(x)_1-f(x)_2\) dưới ràng buộc \(\|x-x_0\|_\infty\le\varepsilon\). Nếu giá trị tối ưu dương, ta tìm được một ví dụ đối kháng hợp lệ; nếu bộ giải chứng minh cận trên không dương, ta có chứng nhận độ bền vững tại \(x_0\). So sánh kết quả MIP với tấn công bằng gradient có chiếu (PGD): PGD có thể &lt;em&gt;tìm&lt;/em&gt; được ví dụ làm đảo nhãn nếu tồn tại, nhưng chỉ MIP mới có thể &lt;em&gt;chứng minh&lt;/em&gt; rằng không tồn tại ví dụ đối kháng nào trong lân cận đó.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;D. Bertsimas, A. King, R. Mazumder, &lt;em&gt;Ann. Statist.&lt;/em&gt; 44(2):813–852, 2016 — tập con tốt nhất qua MIP.&lt;/li&gt;
  &lt;li&gt;Chọn đặc trưng dựa trên mô hình cho NN, &lt;a href=&quot;https://arxiv.org/abs/2302.10344&quot;&gt;arXiv:2302.10344&lt;/a&gt;, 2023.&lt;/li&gt;
  &lt;li&gt;V. Tjeng, K. Xiao, R. Tedrake, ICLR 2019 — kiểm chứng bền vững MILP.&lt;/li&gt;
  &lt;li&gt;M. Fischetti and J. Jo, CPAIOR 2018 — mạng sâu như MIP.&lt;/li&gt;
  &lt;li&gt;D. Bertsimas and J. Dunn, &lt;em&gt;Mach. Learn.&lt;/em&gt; 106:1039–1082, 2017 — cây phân loại tối ưu.&lt;/li&gt;
  &lt;li&gt;NeurIPS 2022 RS-OCT — OCT toàn cục khả mở.&lt;/li&gt;
  &lt;li&gt;Học chọn mặt phẳng cắt, &lt;a href=&quot;https://arxiv.org/abs/2410.03112&quot;&gt;arXiv:2410.03112&lt;/a&gt;, 2024.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>24-06 Ứng dụng hiện đại của mô hình nguyên hỗn hợp</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_06_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_06_modern_applications</id>
   <content type="html">&lt;p&gt;Nhiều người lầm tưởng rằng khi học sâu và mạng nơ-ron lên ngôi, quy hoạch số nguyên hỗn hợp (MIP) sẽ dần lùi vào dĩ vãng. Thực tế giai đoạn 2020–2026 lại cho thấy điều hoàn toàn ngược lại: &lt;strong&gt;học máy và MIP đang trở thành cặp bài trùng không thể tách rời&lt;/strong&gt;. Mạng nơ-ron cực giỏi trong việc dự báo nhu cầu giao hàng hay thời gian di chuyển từ dữ liệu nhiễu, nhưng nó không thể tự đảm bảo các ràng buộc vận hành bắt buộc như “mỗi phi công nghỉ đủ 12 giờ” hay “tải trọng xe không vượt quá \(Q\)”.&lt;/p&gt;

&lt;p&gt;Ngược lại, chính học máy cũng đang quay vào &lt;em&gt;bên trong&lt;/em&gt; bộ giải MIP — thông qua mạng nơ-ron đồ thị (GNN) học cách chọn biến rẽ nhánh trong cuộc thi ML4CO — để tăng tốc vòng lặp nhánh và cận cho các bài toán lặp đi lặp lại mỗi ngày trong công nghiệp.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-kết-nối-mip-cổ-điển-với-ai-hiện-đại&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột kết nối MIP cổ điển với AI hiện đại&lt;/h2&gt;

&lt;p&gt;Bài đọc ứng dụng này giúp bạn nhìn thấy vị trí thực tế của bốn mô hình Chương 24 trong hệ thống công nghiệp ngày nay:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kiến trúc “Predict-then-Optimize” (Dự báo rồi Tối ưu):&lt;/strong&gt; Trong giao hàng chặng cuối và điện toán biên, mô hình ML ước lượng tham số bất định (thời gian đi lại, lưu lượng người dùng), còn bộ giải MIP biến dự báo đó thành quyết định khả thi 100% dưới mọi ràng buộc cứng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biểu diễn Đồ thị Hai phía Biến–Ràng buộc (Bipartite Graph Representation):&lt;/strong&gt; Mọi bài toán MILP đều tương ứng với một đồ thị hai phía nối mỗi biến \(x_j\) với các ràng buộc \(i\) mà nó tham gia (trọng số cạnh là hệ số \(A_{ij}\)). Đây chính là cầu nối cho phép GNN “đọc” được bài toán tối ưu mà không phụ thuộc vào thứ tự đánh số biến.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bắt chước Rẽ nhánh Mạnh (Imitating Strong Branching):&lt;/strong&gt; &lt;em&gt;Strong branching&lt;/em&gt; chọn biến rẽ nhánh cực kỳ thông minh nhưng quá chậm vì phải giải thử hàng trăm LP ở mỗi nút. GNN được huấn luyện để bắt chước quyết định của strong branching trong vài mili-giây.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính đơn mô-đun toàn phần vs. Ràng buộc thực tế:&lt;/strong&gt; Bài toán phân công thuần túy có nghiệm LP tự động nguyên (định lý Birkhoff–von Neumann), nhưng chỉ cần thêm một ràng buộc ca trực hay ngân sách thực tế, cấu trúc đẹp ấy vỡ ngay và MIP thực thụ lập tức cần thiết.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-bài-toán-đặt-cụm-gpu-biên-edge-facility-location&quot;&gt;Giải thích: Tính tay bài toán đặt cụm GPU biên (Edge Facility Location)&lt;/h3&gt;

&lt;p&gt;Giả sử một nền tảng AI cần phục vụ 2 khu vực người dùng (Vùng 1 và Vùng 2) bằng cách mở cụm GPU tại tối đa 2 vị trí ứng viên (Vị trí A và Vị trí B):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Chi phí cố định để thuê hạ tầng mỗi ngày: \(f_A = 10\), \(f_B = 8\) (đơn vị triệu đồng).&lt;/li&gt;
  &lt;li&gt;Chi phí độ trễ và truyền dữ liệu \(c_{ij}\) khi phục vụ Vùng \(i\) từ Vị trí \(j\):
\(c_{1A} = 2,\; c_{1B} = 6,\qquad c_{2A} = 5,\; c_{2B} = 2.\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mô hình MIP là \(\min \sum_{j \in \{A, B\}} f_j y_j + \sum_{i=1}^2 \sum_{j \in \{A, B\}} c_{ij} x_{ij}\) với \(x_{iA} + x_{iB} = 1\) và \(x_{ij} \le y_j\), \(y_j \in \{0, 1\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Phương án 1 — Chỉ mở Vị trí A (\(y_A = 1, y_B = 0\)):&lt;/strong&gt;
Cả hai vùng bắt buộc định tuyến về A (\(x_{1A} = x_{2A} = 1\)).
Tổng chi phí: \(10 + (2 + 5) = 17\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương án 2 — Chỉ mở Vị trí B (\(y_A = 0, y_B = 1\)):&lt;/strong&gt;
Cả hai vùng định tuyến về B (\(x_{1B} = x_{2B} = 1\)).
Tổng chi phí: \(8 + (6 + 2) = 16\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương án 3 — Mở cả hai vị trí (\(y_A = 1, y_B = 1\)):&lt;/strong&gt;
Mỗi vùng chọn vị trí gần mình nhất (\(x_{1A} = 1, x_{2B} = 1\)) để giảm chi phí truyền xuống còn \(2 + 2 = 4\), nhưng chi phí cố định tăng lên \(10 + 8 = 18\).
Tổng chi phí: \(18 + 4 = 22\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quyết định tối ưu:&lt;/strong&gt; Chỉ mở Vị trí B (tổng chi phí &lt;strong&gt;\(16\)&lt;/strong&gt;). Dù Vùng 1 chịu độ trễ cao hơn (\(6\) thay vì \(2\)), mức tiết kiệm chi phí hạ tầng cố định đã bù đắp vượt trội — chính sự đánh đổi định lượng này là lý do MIP giữ vai trò xương sống trong thiết kế mạng lưới kho vận và đám mây!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chương 24 tập trung vào phần &lt;em&gt;mô hình hóa&lt;/em&gt; của quy hoạch nguyên hỗn hợp (MIP): biến quyết định nhị phân, phân công, bài toán cái túi và đặt cơ sở. Các khuôn mẫu này vẫn được sử dụng trực tiếp trong nhiều hệ thống thực tế như xếp lịch phi hành đoàn, định tuyến giao hàng chặng cuối (last-mile) và lựa chọn vị trí kho hàng hay cụm GPU biên. Từ khoảng năm 2019, một hướng nghiên cứu mới còn hình thành xung quanh chúng: &lt;strong&gt;học để tối ưu (learning to optimize)&lt;/strong&gt; — dùng mạng nơ-ron đồ thị (GNN) để đề xuất biến rẽ nhánh, mặt phẳng cắt hoặc điểm khởi động nóng cho bộ giải MIP. Bài đọc tùy chọn này điểm qua bốn ứng dụng tiêu biểu; các chủ đề mặt phẳng cắt, chọn tập con tốt nhất và kiểm chứng mạng nơ-ron sẽ được trình bày ở &lt;a href=&quot;/contents/vi/chapter25/25_Mixed_integer_programming/&quot;&gt;Chương 25&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;1-xếp-lịch-phi-hành-đoàn-hàng-không&quot;&gt;1. Xếp lịch phi hành đoàn hàng không&lt;/h2&gt;

&lt;p&gt;Bài toán ghép cặp chuyến bay và xếp lịch phi hành đoàn là một quy hoạch nguyên với các ràng buộc chặt về giờ trực, thời gian nghỉ và cấu hình đội bay. Bộ dữ liệu chuẩn công khai &lt;strong&gt;air05&lt;/strong&gt; trong MIPLIB 2017 (Gleixner, Hendel, Gamrath và cộng sự, &lt;em&gt;Math. Prog. Comput.&lt;/em&gt; 13:443–490, 2021, &lt;a href=&quot;https://doi.org/10.1007/s12532-020-00194-3&quot;&gt;doi:10.1007/s12532-020-00194-3&lt;/a&gt;) vẫn được dùng để đánh giá các chiến lược rẽ nhánh mới. Một nghiên cứu giải thích năm 2025 (biểu diễn bài toán xếp lịch &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;air05&lt;/code&gt; dưới dạng đồ thị hai phía biến–ràng buộc; &lt;a href=&quot;https://arxiv.org/abs/2512.01698&quot;&gt;arXiv:2512.01698&lt;/a&gt;) đặt ra câu hỏi gắn trực tiếp với Chương 24: sau khi mô hình hóa bài toán thành MIP, liệu phép nhúng đồ thị bằng GNN có đủ tốt để thay thế các đặc trưng thủ công trong bộ giải hay không? Trong quy trình đó, MIP không bị thay thế mà đóng vai trò &lt;em&gt;nguồn sinh nhãn&lt;/em&gt; cho hệ thống học máy.&lt;/p&gt;

&lt;h2 id=&quot;2-phân-công-và-định-tuyến-giao-hàng-chặng-cuối&quot;&gt;2. Phân công và định tuyến giao hàng chặng cuối&lt;/h2&gt;

&lt;p&gt;Bài toán phân công ở mục 24-02 là khối con cốt lõi trong nhiều hệ thống logistics hiện đại. Giao hàng chặng cuối và điều phối giao đồ ăn theo yêu cầu thường được mô hình hóa dưới dạng MIP định tuyến phương tiện (hoặc MIP kết hợp sinh cột) với ràng buộc khung thời gian và ca làm việc của tài xế. Chuyên khảo &lt;em&gt;Vehicle Routing&lt;/em&gt; của Toth và Vigo là tài liệu nền tảng cho hướng này; cách triển khai phổ biến trong thập niên 2020 là dùng mô hình học có giám sát để &lt;em&gt;dự báo&lt;/em&gt; thời gian di chuyển và nhu cầu, rồi đưa các tham số đó vào bộ giải MIP để xuất ra lộ trình khả thi trong vài phút. Mô hình học máy đảm nhận phần dự báo từ dữ liệu, còn quy hoạch nguyên đảm bảo các ràng buộc cứng (“một tài xế, một xe, tải trọng tối đa \(Q\)”) mà mạng nơ-ron không tự đảm bảo được. Cách phân tách trách nhiệm — học những quy luật khó viết công thức và tối ưu những ràng buộc cần chứng nhận chặt — là kiến trúc phổ biến kết hợp vận trù học và học máy hiện nay.&lt;/p&gt;

&lt;h2 id=&quot;3-đặt-cơ-sở-cho-kho-vận-và-điện-toán-biên&quot;&gt;3. Đặt cơ sở cho kho vận và điện toán biên&lt;/h2&gt;

&lt;p&gt;Bài toán đặt cơ sở (cũng ở mục 24-02) là khung mô hình để quyết định mở trung tâm hoàn tất đơn hàng (fulfillment center), nút bộ nhớ đệm hay &lt;strong&gt;điểm suy luận GPU biên&lt;/strong&gt;. Biến nhị phân \(y_j\) quyết định việc mở địa điểm \(j\) với chi phí cố định \(f_j\), còn biến luồng liên tục (hoặc nguyên) \(x_{ij}\) phân bổ nhu cầu từ vùng \(i\) sang địa điểm \(j\). Nhiều nghiên cứu về điện toán đám mây và học máy biên giữ nguyên cấu trúc này, với \(f_j\) là chi phí hạ tầng máy chủ hoặc bản quyền và \(c_{ij}\) là độ trễ hay chi phí truyền dữ liệu ra ngoài (egress). Mô hình MIP giữ nguyên, chỉ khác ở chỗ dữ liệu đầu vào trong hàm mục tiêu đến từ mô hình dự báo nhu cầu.&lt;/p&gt;

&lt;h2 id=&quot;4-học-quy-tắc-rẽ-nhánh-và-cuộc-thi-ml4co&quot;&gt;4. Học quy tắc rẽ nhánh và cuộc thi ML4CO&lt;/h2&gt;

&lt;p&gt;Gasse, Chételat, Ferroni, Charlin và Lodi (&lt;em&gt;Exact Combinatorial Optimization with Graph Convolutional Neural Networks&lt;/em&gt;, NeurIPS 2019) huấn luyện mạng nơ-ron tích chập đồ thị để bắt chước chiến lược rẽ nhánh mạnh (strong branching). Cuộc thi NeurIPS 2021 &lt;strong&gt;ML4CO&lt;/strong&gt; (Ecole và cộng sự) chuẩn hóa hướng này thành các bài toán đánh giá công khai cho việc học heuristic gốc, tinh chỉnh cấu hình và chọn biến rẽ nhánh trên các họ MIP. Các nghiên cứu giai đoạn 2024–2025 tiếp tục mở rộng sang học &lt;em&gt;chuỗi mặt phẳng cắt&lt;/em&gt; và thử nghiệm bộ giải học tăng cường đầu–cuối (sẽ đề cập thêm ở Chương 25). Điểm cốt lõi cần ghi nhớ là: trong thực tế, ứng dụng MIP thường xuất hiện dưới dạng một &lt;em&gt;phân phối&lt;/em&gt; các bài toán cùng họ, và mô hình học máy hoạt động &lt;em&gt;bên trong&lt;/em&gt; vòng lặp nhánh và cận của mục 24-05 chứ không thay thế các ràng buộc nguyên.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Lấy mô hình bài toán phân công từ mục 24-02 với \(n=8\) và ma trận chi phí ngẫu nhiên. Giải bài toán bằng hai cách: (i) dùng bộ giải MIP hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.optimize.linear_sum_assignment&lt;/code&gt;; và (ii) giải bài toán nới lỏng LP với \(x_{ij}\in[0,1]\) rồi làm tròn. Quan sát số lần nghiệm nới lỏng LP tự động là nghiệm nguyên (định lý Birkhoff–von Neumann đảm bảo điều này &lt;em&gt;luôn&lt;/em&gt; đúng cho bài toán phân công thuần). Sau đó thêm một ràng buộc bổ sung (chẳng hạn ràng buộc “người 1 không làm các công việc 1–3” hoặc thêm ràng buộc ghép cặp/ngân sách) để quan sát sự khác biệt giữa bài toán phân công chuẩn trong sách giáo khoa và bài toán MIP xếp lịch thực tế.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;A. Gleixner et al., &lt;em&gt;MIPLIB 2017&lt;/em&gt;, &lt;em&gt;Math. Prog. Comput.&lt;/em&gt; 13:443–490, 2021.&lt;/li&gt;
  &lt;li&gt;M. Gasse, D. Chételat, N. Ferroni, L. Charlin, A. Lodi, NeurIPS 2019 — rẽ nhánh GNN.&lt;/li&gt;
  &lt;li&gt;A. Prouvost, A. Chowdhury, et al. / Ecole et al., cuộc thi NeurIPS 2021 ML4CO.&lt;/li&gt;
  &lt;li&gt;P. Toth and D. Vigo (eds.), &lt;em&gt;Vehicle Routing: Problems, Methods, and Applications&lt;/em&gt;, SIAM, 2nd ed., 2014.&lt;/li&gt;
  &lt;li&gt;D. Bertsimas and J. Tsitsiklis, &lt;em&gt;Introduction to Linear Optimization&lt;/em&gt; — gán và định vị cơ sở như xương sống mô hình.&lt;/li&gt;
  &lt;li&gt;Nhúng GNN air05, &lt;a href=&quot;https://arxiv.org/abs/2512.01698&quot;&gt;arXiv:2512.01698&lt;/a&gt;, 2025 — xếp kíp như instance học đồ thị.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>23-05 Ứng dụng hiện đại của hạ theo tọa độ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_05_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_05_modern_applications</id>
   <content type="html">&lt;p&gt;Nếu bạn từng nghĩ hạ theo tọa độ chỉ là một mẹo hay cho bài toán Lasso bậc hai cổ điển, bức tranh công nghiệp giai đoạn 2022–2026 sẽ khiến bạn bất ngờ. Khi chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LassoCV&lt;/code&gt; hay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LinearSVC&lt;/code&gt; trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt;, khớp mô hình sống còn Cox trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet 4.x&lt;/code&gt;, hay giải bài toán ngược tín hiệu não M/EEG hàng triệu chiều bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt;, động cơ thực sự đang chạy hết công suất bên dưới không phải Adam mà chính là &lt;strong&gt;hạ theo tọa độ&lt;/strong&gt; được trang bị thêm hai vũ khí hiện đại: &lt;strong&gt;sàng lọc an toàn theo khoảng cách đối ngẫu (gap-safe screening)&lt;/strong&gt; và &lt;strong&gt;tăng tốc Anderson&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Bài đọc này nối trực tiếp lý thuyết Chương 23 với các thư viện mã nguồn mở chuẩn mực đang vận hành hàng ngày trong thống kê sinh học, xử lý ngôn ngữ tự nhiên quy mô nhẹ và dữ liệu bảng nhiều chiều.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-công-nghệ-biến-cd-thành-bộ-giải-triệu-chiều&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép công nghệ biến CD thành bộ giải triệu chiều&lt;/h2&gt;

&lt;p&gt;Để nắm được vì sao các thư viện hiện đại lại đạt tốc độ vượt trội trên dữ liệu siêu cao chiều (\(p \gg n\)), hãy chú ý bốn trụ cột kỹ thuật sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vòng ngoài Proximal-Newton / IRLS (trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet 4.x&lt;/code&gt;):&lt;/strong&gt; Mọi mô hình tuyến tính tổng quát (logistic, Poisson, Cox) đều có hàm log-hợp lý trơn; xấp xỉ bậc hai cục bộ đưa mỗi bước ngoài về một bài toán Lasso bình phương tối thiểu &lt;em&gt;có trọng số&lt;/em&gt;, cho phép tái sử dụng nguyên vẹn lõi CD của mục 23-03.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sàng lọc an toàn theo khoảng cách đối ngẫu (Gap-Safe Screening):&lt;/strong&gt; Dựa trên khoảng cách đối ngẫu \(G = P(\beta) - D(\theta)\), ta dựng được một hình cầu chắc chắn chứa nghiệm đối ngẫu tối ưu \(\theta^\star\). Đặc trưng nào có tích vô hướng với mọi điểm trong hình cầu đều nhỏ hơn \(1\) thì chắc chắn có \(\beta_j^\star = 0\) và bị loại vĩnh viễn khỏi bộ nhớ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập hoạt động + Tăng tốc Anderson (trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt;):&lt;/strong&gt; Mở rộng ra ngoài chuẩn \(\ell_1\) sang các hàm phạt không lồi (MCP, SCAD) hay chuẩn nhóm, kết hợp ngoại suy tổ hợp tuyến tính các bước lặp gần nhất (Anderson acceleration) để rút ngắn mạnh số vòng lặp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hạ theo tọa độ đối ngẫu (Dual CD trong LIBLINEAR):&lt;/strong&gt; Với SVM tuyến tính khi số mẫu lớn và đặc trưng thưa (văn bản túi từ, dự đoán CTR), bài toán đối ngẫu có ràng buộc hộp \(0 \le \alpha_i \le C\) đơn giản, nên mỗi bước CD chỉ là cắt ngưỡng một nghiệm bậc hai 1 chiều.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-quy-tắc-sàng-lọc-an-toàn-gap-safe-screening&quot;&gt;Giải thích: Tính tay quy tắc sàng lọc an toàn (Gap-Safe Screening)&lt;/h3&gt;

&lt;p&gt;Hãy tự tay chứng nhận một đặc trưng chắc chắn bằng \(0\) tại nghiệm tối ưu mà &lt;strong&gt;chưa cần giải xong bài toán&lt;/strong&gt;! Xét Lasso với hai cột trực chuẩn \(X_1 = (1, 0)^T, X_2 = (0, 1)^T\) (\(\|X_1\|_2 = \|X_2\|_2 = 1\)), nhãn \(y = (3,\; 0.2)^T\) và \(\lambda = 1\).&lt;/p&gt;

&lt;p&gt;Giả sử sau vài vòng lặp, ta đang ở điểm hiện tại \(\beta = (1.8,\; 0)\) (chưa phải nghiệm tối ưu \((2, 0)\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính phần dư và điểm khả thi đối ngẫu \(\theta\):&lt;/strong&gt;
Phần dư \(r = y - X\beta = (3 - 1.8,\; 0.2 - 0)^T = (1.2,\; 0.2)^T\).
Điều kiện khả thi đối ngẫu của Lasso là \(\|X^T \theta\|_\infty \le 1\). Ta chuẩn hóa \(r\) bằng hệ số \(\max(\lambda, \|X^T r\|_\infty) = \max(1, 1.2) = 1.2\):
\(\theta = \frac{r}{1.2} = \left(1,\; \frac{1}{6}\right)^T \approx (1,\; 0.1667)^T.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính khoảng cách đối ngẫu \(G = P(\beta) - D(\theta)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giá trị gốc: \(P(\beta) = \frac{1}{2}\|r\|_2^2 + \lambda\|\beta\|_1 = \frac{1}{2}(1.2^2 + 0.2^2) + 1.8 = 0.74 + 1.8 = 2.54\).&lt;/li&gt;
      &lt;li&gt;Giá trị đối ngẫu chuẩn của Lasso: \(D(\theta) = \frac{1}{2}\|y\|_2^2 - \frac{\lambda^2}{2}\left\|\theta - \frac{y}{\lambda}\right\|_2^2 = \frac{9.04}{2} - \frac{1}{2}\left((1 - 3)^2 + \left(\frac{1}{6} - 0.2\right)^2\right) \approx 4.52 - 2.00056 = 2.51944\).&lt;/li&gt;
      &lt;li&gt;Khoảng cách đối ngẫu: \(G = 2.54 - 2.51944 = 0.02056\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng phép thử hình cầu an toàn cho đặc trưng \(j = 2\):&lt;/strong&gt;
Bán kính hình cầu chứa \(\theta^\star\) là \(r_{\text{safe}} = \frac{\sqrt{2G}}{\lambda} \approx \sqrt{0.04112} \approx 0.2028\).
Kiểm tra cận trên cho \(|X_2^T \theta^\star|\):
\(|X_2^T \theta| + \|X_2\|_2 \cdot r_{\text{safe}} \approx 0.1667 + 1 \cdot 0.2028 = 0.3695 &amp;lt; 1!\)&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Vì $$&lt;/td&gt;
          &lt;td&gt;X_2^T \theta^\star&lt;/td&gt;
          &lt;td&gt;&amp;lt; 1\(được **chứng minh chặt chẽ về mặt toán học**, theo điều kiện KKT thì\)\beta_2^\star\(**bắt buộc bằng 0**. Thuật toán loại bỏ hoàn toàn cột\)X_2$$ khỏi mọi vòng lặp còn lại mà không đánh mất dù chỉ một chữ số chính xác nào!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hạ theo tọa độ dọc đường chính quy hóa (pathwise coordinate descent) là lý do giúp hồi quy Lasso trở thành công cụ tiêu chuẩn trong thống kê ứng dụng thay vì chỉ dừng ở mức nghiên cứu lý thuyết. Thư viện &lt;strong&gt;glmnet&lt;/strong&gt; của Friedman, Hastie và Tibshirani (JSS 2010) vẫn được sử dụng rộng rãi trong R, còn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lasso_path&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enet_path&lt;/code&gt; của scikit-learn triển khai cùng ý tưởng bằng Cython. Bài đọc tùy chọn này cập nhật bối cảnh giai đoạn 2023–2026: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; mở rộng cho &lt;em&gt;mọi&lt;/em&gt; họ mô hình tuyến tính tổng quát (GLM), các kỹ thuật sàng lọc an toàn và tập hoạt động ở quy mô hàng triệu đặc trưng, cùng bộ giải hạ theo tọa độ đối ngẫu tiếp tục phục vụ huấn luyện SVM tuyến tính trong thực tế.&lt;/p&gt;

&lt;p&gt;Mỗi bước tọa độ tuần hoàn (hoặc ngẫu nhiên) trên hàm mục tiêu hợp thành \(f(\beta)+ \lambda\|\beta\|_1\) chỉ là một phép co ngưỡng mềm vô hướng. Toàn bộ &lt;strong&gt;đường chính quy hóa&lt;/strong&gt; là vòng lặp khởi động nóng (warm start) trên lưới giá trị giảm dần \(\lambda_1&amp;gt;\cdots&amp;gt;\lambda_T\). Dưới đây là những hệ thống thực tế xây dựng trên nền tảng thuật toán đó.&lt;/p&gt;

&lt;h2 id=&quot;1-glmnet-cho-mọi-họ-glm-2023&quot;&gt;1. glmnet cho mọi họ GLM (2023)&lt;/h2&gt;

&lt;p&gt;Tay, Narasimhan và Hastie, &lt;em&gt;Elastic Net Regularization Paths for All Generalized Linear Models&lt;/em&gt;, &lt;em&gt;Journal of Statistical Software&lt;/em&gt; 106(1):1–31, 2023, &lt;a href=&quot;https://doi.org/10.18637/jss.v106.i01&quot;&gt;doi:10.18637/jss.v106.i01&lt;/a&gt;, mở rộng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet 4.x&lt;/code&gt; vượt ra ngoài các họ phân phối cố định (Gaussian, nhị thức, Poisson, Cox). Mọi mô hình GLM có hàm log-hợp lý trơn đều có thể tính đường chính quy hóa elastic-net bằng hạ theo tọa độ tuần hoàn. Phiên bản 4.1 (tài liệu giai đoạn 2021–2023 tại &lt;a href=&quot;https://glmnet.stanford.edu/&quot;&gt;glmnet.stanford.edu&lt;/a&gt;) bổ sung hỗ trợ dữ liệu phân tích sống còn dạng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(start, stop)&lt;/code&gt;, phân tầng (strata) và ma trận đặc trưng \(X\) thưa.&lt;/p&gt;

&lt;p&gt;Đây là tài liệu trực tiếp trả lời câu hỏi thường gặp: “Ta mới học Lasso trên bình phương tối thiểu — liệu hạ theo tọa độ còn hiệu quả với hồi quy logistic, Cox hay các GLM tùy chỉnh không?” Câu trả lời là có, vì vòng lặp ngoài IRLS / proximal-Newton đưa mỗi bước về một bài toán Lasso bình phương tối thiểu &lt;em&gt;có trọng số&lt;/em&gt;, và bài toán vòng trong chính là thuật toán hạ theo tọa độ ở mục 23-03.&lt;/p&gt;

&lt;h2 id=&quot;2-đường-chính-quy-hóa-trong-scikit-learn-và-sàng-lọc-an-toàn-theo-khoảng-cách-đối-ngẫu&quot;&gt;2. Đường chính quy hóa trong scikit-learn và sàng lọc an toàn theo khoảng cách đối ngẫu&lt;/h2&gt;

&lt;p&gt;Các hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sklearn.linear_model.lasso_path&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enet_path&lt;/code&gt; (scikit-learn phiên bản 1.5–1.9) chạy hạ theo tọa độ trên mảng lưu theo thứ tự Fortran kết hợp &lt;strong&gt;quy tắc sàng lọc an toàn theo khoảng cách đối ngẫu (gap-safe screening)&lt;/strong&gt;: ngay khi khoảng cách đối ngẫu chứng nhận một tọa độ chắc chắn bằng 0 tại nghiệm, tọa độ đó bị loại khỏi các bước cập nhật còn lại của mức \(\lambda\) hiện tại. Các cải tiến bảo trì giai đoạn 2025–2026 (như tính trước phần dư và chuẩn cột dọc theo đường nghiệm) giúp một bộ dữ liệu biểu hiện gen với \(p\sim 10^4\) đặc trưng vẫn khớp xong đường 100 điểm trong vài giây. Khi gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LassoCV&lt;/code&gt;, bên dưới chính là thuật toán Chương 23 chứ không phải Adam.&lt;/p&gt;

&lt;h2 id=&quot;3-skglm-tập-hoạt-động-cho-các-hàm-phạt-ngoài-ell_1-neurips-2022&quot;&gt;3. skglm: tập hoạt động cho các hàm phạt ngoài \(\ell_1\) (NeurIPS 2022)&lt;/h2&gt;

&lt;p&gt;Bertrand, Klopfenstein, Blondel, Vaiter, Gramfort và Massias, &lt;em&gt;Beyond L1: Faster and Better Sparse Models with skglm&lt;/em&gt;, NeurIPS 2022, &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/fe5c31e525e9a26a1426ab0b589f42fe-Abstract-Conference.html&quot;&gt;bài báo&lt;/a&gt;, mở rộng hạ theo tọa độ vượt ra ngoài phạm vi của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;. Kỹ thuật &lt;strong&gt;tập hoạt động (working set)&lt;/strong&gt; mở rộng dần tập đặc trưng tích cực cỡ nhỏ, kết hợp tăng tốc Anderson (Bertrand &amp;amp; Massias, 2021) nhằm cải thiện tốc độ thực tế. Thư viện hỗ trợ các hàm phạt không lồi MCP / SCAD, chuẩn nhóm, học đa nhiệm và hàm khớp dữ liệu tùy chỉnh — hiện thực hóa hạng mục “hàm phạt không lồi” đã nêu ở mục 23-00 thành gói phần mềm cài đặt trực tiếp qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip&lt;/code&gt;. Các ứng dụng chính trong bài báo gồm hệ gen học, học từ điển thị giác và bài toán ngược M/EEG; kết quả thực nghiệm cho thấy hạ theo tọa độ kết hợp tập hoạt động vượt trội phương pháp proximal gradient đầy đủ khi \(p\) lên tới hàng triệu.&lt;/p&gt;

&lt;h2 id=&quot;4-hạ-theo-tọa-độ-đối-ngẫu-cho-svm-tuyến-tính&quot;&gt;4. Hạ theo tọa độ đối ngẫu cho SVM tuyến tính&lt;/h2&gt;

&lt;p&gt;Hsieh, Chang, Lin, Keerthi và Sundararajan (ICML 2008) đề xuất huấn luyện SVM tuyến tính bằng hạ theo tọa độ đối ngẫu; &lt;strong&gt;LIBLINEAR&lt;/strong&gt; đến nay vẫn là bộ giải cốt lõi đằng sau &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sklearn.svm.LinearSVC&lt;/code&gt; và nhiều hệ thống phân loại văn bản trong công nghiệp. Mỗi bước cập nhật tọa độ đối ngẫu chỉ là cực tiểu hóa một hàm bậc hai một chiều có chặn biên. Sự phổ biến của các mô hình transformer không làm phương pháp này lỗi thời: các mô hình cơ sở logistic/SVM trên đặc trưng túi từ, mô hình dự đoán tỉ lệ nhấp (CTR) và GLM trên dữ liệu bảng nhiều chiều vẫn là thế mạnh của coordinate descent. Nói ngắn gọn, hãy dùng AdamW (Chương 26) cho mạng sâu và dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; / LIBLINEAR / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt; cho các mô hình &lt;em&gt;tuyến tính tổng quát có tính thưa&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Pathwise CD gói gọn trong một lời gọi thư viện — nền tảng là thuật toán Chương 23
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sklearn.linear_model&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lasso_path&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sklearn.datasets&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;make_regression&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;make_regression&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_samples&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_features&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_informative&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;8.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;alphas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coefs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lasso_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# coefs.shape == (n_features, n_alphas); quan sát thứ tự các đặc trưng bước vào đường nghiệm
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Trên dữ liệu sinh bởi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make_regression&lt;/code&gt; với \(p=200\), \(n=150\) và 5 đặc trưng có thông tin, vẽ đường hệ số của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lasso_path&lt;/code&gt; theo \(-\log\lambda\). Sau đó khớp cùng đường nghiệm bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt; (hoặc tự viết vòng lặp co ngưỡng mềm tuần hoàn nếu không cài thêm thư viện) và kiểm tra xem tập đặc trưng khác 0 (&lt;em&gt;support&lt;/em&gt;) có khớp nhau tại giá trị \(\lambda\) chọn bằng kiểm chứng chéo hay không. Cuối cùng, huấn luyện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LinearSVC&lt;/code&gt; trên một tập con túi từ của bộ dữ liệu 20-newsgroups và so sánh thời gian chạy thực tế (wall-clock time) với mô hình hồi quy logistic huấn luyện bằng Adam theo minibatch với cùng chuẩn phạt \(\ell_2\): coordinate descent sẽ nhanh hơn trên mô hình tuyến tính, còn Adam chỉ phát huy ưu thế khi bổ sung thêm lớp ẩn phi tuyến.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;J. Friedman, T. Hastie, R. Tibshirani, &lt;em&gt;J. Stat. Softw.&lt;/em&gt; 33(1), 2010 — glmnet pathwise CD.&lt;/li&gt;
  &lt;li&gt;J. K. Tay, B. Narasimhan, T. Hastie, &lt;em&gt;J. Stat. Softw.&lt;/em&gt; 106(1):1–31, 2023 — đường elastic-net cho mọi GLM.&lt;/li&gt;
  &lt;li&gt;Q. Bertrand et al., NeurIPS 2022 — skglm, working set, mô hình thưa không lồi.&lt;/li&gt;
  &lt;li&gt;C.-J. Hsieh et al., ICML 2008 — CD đối ngẫu cho SVM tuyến tính (LIBLINEAR).&lt;/li&gt;
  &lt;li&gt;Hướng dẫn scikit-learn, &lt;em&gt;Coordinate descent&lt;/em&gt; / gap-safe screening (v1.5+).&lt;/li&gt;
  &lt;li&gt;S. J. Wright, &lt;em&gt;Math. Programming&lt;/em&gt; 151:3–34, 2015 — khảo sát thuật toán CD.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>22-07 Ứng dụng hiện đại của Frank–Wolfe</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_07_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_07_modern_applications</id>
   <content type="html">&lt;p&gt;Khi một thuật toán tối ưu cổ điển bước sang thập niên thứ tám mà vẫn xuất hiện đều đặn trong các bài báo đầu ngành, bí mật không nằm ở sự phức tạp của công thức mà nằm ở &lt;strong&gt;khả năng thay thế một bài toán phi tuyến khó bằng một phép tính tổ hợp cực nhanh&lt;/strong&gt;. Trong bối cảnh học máy giai đoạn 2022–2026, nơi các nhà nghiên cứu phải xử lý bài toán vận chuyển tối ưu không cân bằng (unbalanced OT) và tìm mặt nạ giải thích thưa cho mạng nơ-ron hàng tỷ tham số, Frank–Wolfe tiếp tục chứng tỏ giá trị đặc biệt.&lt;/p&gt;

&lt;p&gt;Bài đọc mở rộng này nhấn mạnh góc nhìn so sánh thuật toán trong thực tế: làm thế nào để nhận diện cấu trúc bài toán có LMO tuyến tính rẻ (như sắp xếp 1 chiều hay quy hoạch trên đa diện Birkhoff) và khi nào nên chọn Frank–Wolfe thay vì Sinkhorn hay gradient có chiếu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-thuật-toán-đằng-sau-các-ứng-dụng-20222026&quot;&gt;Kiến thức cần nhớ: Ba trụ cột thuật toán đằng sau các ứng dụng 2022–2026&lt;/h2&gt;

&lt;p&gt;Để đánh giá đúng vị thế của Frank–Wolfe trong hệ sinh thái tối ưu hiện đại, hãy nắm ba trụ cột kỹ thuật sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu hóa và Tuyến tính hóa trong Vận chuyển tối ưu 1 chiều (1-D OT):&lt;/strong&gt; Trong không gian 1 chiều, khoảng cách Wasserstein giữa hai phân phối rời rạc kích thước \(n\) không cần giải quy hoạch tuyến tính \(O(n^3)\); chỉ cần &lt;strong&gt;sắp xếp&lt;/strong&gt; các điểm hỗ trợ trong \(O(n \log n)\) rồi ghép theo thứ tự tăng dần. Khi áp dụng Frank–Wolfe lên bài toán đối ngẫu của OT không cân bằng, mỗi lần gọi LMO lại tận dụng đúng phép sắp xếp siêu nhanh này.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đa diện Birkhoff và Quả cầu \(\ell_1\) trong Giải thích mô hình (XAI):&lt;/strong&gt; Các bài toán giải thích mô hình thường ràng buộc trọng số gán điểm trên quả cầu \(\ell_1\) (kiểm soát độ thưa) hoặc đa diện Birkhoff của các ma trận ngẫu nhiên kép (mô hình hóa hoán vị). LMO trên đa diện Birkhoff chính là bài toán ghép cặp cực tiểu (Hungarian algorithm), rẻ hơn nhiều so với phép chiếu Euclid.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chí lựa chọn bộ giải (Solver Selection Trade-offs):&lt;/strong&gt; So sánh trực diện giữa Frank–Wolfe (bảo toàn tính thưa, không cần chính quy hóa entropy, ít bộ nhớ) với Sinkhorn/PGD (tính toán ma trận đặc thân thiện GPU, hội tụ trơn nhưng làm mờ kế hoạch vận chuyển).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-vì-sao-lmo-của-vận-chuyển-tối-ưu-1-chiều-chỉ-tốn-một-bước-sắp-xếp&quot;&gt;Giải thích: Vì sao LMO của vận chuyển tối ưu 1 chiều chỉ tốn một bước sắp xếp?&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Để hiểu sức mạnh của công trình Séjourné và cộng sự (AISTATS 2022), hãy tự tay tính chi phí vận chuyển tối ưu 1 chiều giữa hai phân phối đều rời rạc trên 3 điểm: phân phối nguồn đặt khối lượng \(\frac{1}{3}\) tại các vị trí \(a = (5,\; 0,\; 2)\) và phân phối đích đặt khối lượng \(\frac{1}{3}\) tại \(b = (3,\; 1,\; 4)\), với hàm chi phí $$c(u, v) =&lt;/td&gt;
      &lt;td&gt;u - v&lt;/td&gt;
      &lt;td&gt;$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nếu giải bằng quy hoạch tuyến tính thông thường:&lt;/strong&gt;
Ta phải thiết lập ma trận kế hoạch vận chuyển \(P \in \mathbb{R}^{3 \times 3}\) gồm \(9\) biến không âm thỏa mãn \(6\) ràng buộc tổng hàng và tổng cột bằng \(\frac{1}{3}\) — tổng cộng \(n^2\) biến khi kích thước là \(n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng tính chất đơn điệu của OT 1 chiều (LMO tuyến tính hóa):&lt;/strong&gt;
Bất đẳng thức sắp xếp lại (rearrangement inequality) bảo đảm kế hoạch ghép tối ưu 1 chiều luôn ghép điểm nhỏ nhất với điểm nhỏ nhất, điểm giữa với điểm giữa, điểm lớn nhất với điểm lớn nhất:
    &lt;ul&gt;
      &lt;li&gt;Sắp xếp nguồn: \(a_{(1)} = 0 \le a_{(2)} = 2 \le a_{(3)} = 5\).&lt;/li&gt;
      &lt;li&gt;Sắp xếp đích: \(b_{(1)} = 1 \le b_{(2)} = 3 \le b_{(3)} = 4\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chi phí tối ưu trực tiếp:&lt;/strong&gt;
\(W_1(a, b) = \frac{1}{3}\bigl(|0 - 1| + |2 - 3| + |5 - 4|\bigr) = \frac{1}{3}(1 + 1 + 1) = 1.\)
Thử kiểm tra một cách ghép chéo khác, ví dụ ghép \((0 \to 3, 2 \to 1, 5 \to 4)\): chi phí là \(\frac{1}{3}(3 + 1 + 1) = \frac{5}{3} &amp;gt; 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài học cốt lõi:&lt;/strong&gt; Nhờ LMO rút gọn về đúng một thao tác sắp xếp tốn \(O(n \log n)\) (và sau khi đã sắp xếp ban đầu thì mỗi bước chỉ tốn \(O(n)\) tuyến tính), Frank–Wolfe giải được bài toán đối ngẫu của OT không cân bằng 1 chiều với hàng chục nghìn điểm mà không bao giờ cần dựng ma trận chi phí \(n \times n\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Frank–Wolfe (gradient có điều kiện) là lựa chọn phù hợp khi tập khả thi \(\mathcal{C}\) có &lt;strong&gt;bộ giải cực tiểu tuyến tính (linear minimization oracle — LMO)&lt;/strong&gt; rẻ:&lt;/p&gt;

\[s_k \in \arg\min_{s\in\mathcal{C}}\ \langle \nabla f(x_k), s\rangle\]

&lt;p&gt;trong khi &lt;em&gt;phép chiếu&lt;/em&gt; lên \(\mathcal{C}\) tốn kém hoặc phá vỡ tính thưa của nghiệm. Làn sóng nghiên cứu thập niên 2010 (Jaggi; Lacoste-Julien) đã hình thành nên bộ công cụ ứng dụng rộng rãi trong thập niên 2020: dự đoán có cấu trúc, vận chuyển tối ưu và giải thích mạng nơ-ron có ràng buộc. Bài đọc tùy chọn này trình bày bốn trường hợp tiêu biểu, không lặp lại phần chứng minh hội tụ.&lt;/p&gt;

&lt;h2 id=&quot;1-dự-đoán-có-cấu-trúc-frankwolfe-theo-khối-tọa-độ&quot;&gt;1. Dự đoán có cấu trúc: Frank–Wolfe theo khối tọa độ&lt;/h2&gt;

&lt;p&gt;Bài toán cực tiểu hóa rủi ro thực nghiệm (ERM) trong dự đoán có cấu trúc (CRF, SVM có cấu trúc) có dạng:&lt;/p&gt;

\[\min_{w}\ \frac{\lambda}{2}\|w\|_2^2 + \frac1n\sum_{i=1}^n \max_{y\in\mathcal{Y}_i}\bigl(\langle w, \phi(x_i,y)\rangle - \delta(y_i,y)\bigr).\]

&lt;p&gt;Bài toán đối ngẫu là tối ưu trên tích Descartes của các đơn hình (simplex) xác suất. Nhờ cấu trúc tích này, mỗi bước &lt;strong&gt;Frank–Wolfe theo khối tọa độ (BCFW)&lt;/strong&gt; tương ứng đúng với một lần gọi &lt;em&gt;suy luận tăng cường hàm mất mát (loss-augmented inference)&lt;/em&gt; — chính là bộ giải vốn đã có sẵn trong mô hình cấu trúc. Công trình của Lacoste-Julien, Jaggi, Schmidt và Pletscher (ICML 2013) đặt nền móng cho hướng này, và đó vẫn là lý do Frank–Wolfe được duy trì trong các thư viện dự đoán có cấu trúc hiện nay.&lt;/p&gt;

&lt;p&gt;Cùng ý tưởng tách theo khối tọa độ được áp dụng sang &lt;strong&gt;vận chuyển tối ưu (optimal transport — OT)&lt;/strong&gt;. Fukunaga và Kasai (&lt;a href=&quot;https://arxiv.org/abs/2205.13766&quot;&gt;arXiv:2205.13766&lt;/a&gt;, 2022; bản hội nghị ICASSP 2022) triển khai BCFW — bao gồm cả biến thể away-step và pairwise step — cho bài toán OT &lt;em&gt;bán nới lỏng (semi-relaxed)&lt;/em&gt;, nơi ràng buộc biên chặt thông thường buộc phải giải một bài toán quy hoạch tuyến tính đầy đủ. Bộ giải tuyến tính trên từng khối có nghiệm dạng đóng trên đơn hình và tạo ra kế hoạch vận chuyển thưa. Ứng dụng minh họa chính của bài báo là &lt;strong&gt;chuyển màu (color transfer)&lt;/strong&gt; giữa hai ảnh: kế hoạch vận chuyển có cấu trúc thưa trên đơn hình đúng với thế mạnh bảo toàn tính thưa của Frank–Wolfe.&lt;/p&gt;

&lt;h2 id=&quot;2-vận-chuyển-tối-ưu-không-cân-bằng-một-chiều&quot;&gt;2. Vận chuyển tối ưu không cân bằng một chiều&lt;/h2&gt;

&lt;p&gt;Séjourné, Feydy, Vialard, Trouvé và Peyré (AISTATS 2022, &lt;a href=&quot;https://proceedings.mlr.press/v151/sejourne22a.html&quot;&gt;PMLR v151&lt;/a&gt;) áp dụng Frank–Wolfe lên bài toán &lt;em&gt;đối ngẫu&lt;/em&gt; của vận chuyển tối ưu không cân bằng 1 chiều (1-D unbalanced OT). Bài toán con tuyến tính hóa lúc này là bài toán OT 1 chiều &lt;em&gt;cân bằng&lt;/em&gt;, có thể giải trong thời gian tuyến tính sau một bước sắp xếp. Đây là minh họa trực diện cho nguyên lý của Frank–Wolfe: thay thế bài toán phi tuyến khó bằng một bộ giải tuyến tính đơn giản và hiệu quả. Nhóm tác giả cũng tính tâm khối (barycenter) 1 chiều bằng cùng phép tuyến tính hóa. Khi cần nghiệm UOT &lt;em&gt;không chính quy hóa&lt;/em&gt;, Frank–Wolfe có thể vượt trội Sinkhorn; ngược lại, khi cần kế hoạch ghép trơn và tận dụng GPU tốt, Sinkhorn vẫn có ưu thế. Điều quan trọng là hiểu rõ &lt;em&gt;vì sao&lt;/em&gt; có sự đánh đổi này thay vì chỉ chọn một phương pháp cố định.&lt;/p&gt;

&lt;h2 id=&quot;3-giải-thích-mạng-nơ-ron-có-ràng-buộc&quot;&gt;3. Giải thích mạng nơ-ron có ràng buộc&lt;/h2&gt;

&lt;p&gt;Macdonald, Besançon và Pokutta (ICML 2022, &lt;a href=&quot;https://proceedings.mlr.press/v162/macdonald22a.html&quot;&gt;PMLR v162&lt;/a&gt;) phát biểu lại bài toán &lt;strong&gt;giải thích theo độ méo–tốc độ (rate-distortion explanation — RDE)&lt;/strong&gt; dưới dạng tối ưu có ràng buộc và giải bằng Frank–Wolfe tất định cũng như ngẫu nhiên. Yêu cầu độ thưa của bản đồ độ liên quan trở thành ràng buộc hình cầu \(\ell_1\) (hoặc đơn hình); còn biến thể &lt;em&gt;xếp hạng đặc trưng&lt;/em&gt; tối ưu trên &lt;strong&gt;đa diện Birkhoff&lt;/strong&gt; (bao lồi của tập các ma trận hoán vị), nơi bộ giải tuyến tính quy về bài toán gán tuyến tính (linear assignment). Trên các bộ dữ liệu phân loại ảnh tiêu chuẩn, các biến thể đa tốc độ và xếp hạng đạt kết quả tốt hơn RDE gốc. Về bản chất, đây là một dạng dự đoán có cấu trúc: miền đa diện mã hóa dạng lời giải thích dễ đọc, và Frank–Wolfe tránh hoàn toàn phép chiếu tốn kém lên đa diện đó.&lt;/p&gt;

&lt;h2 id=&quot;4-bài-tổng-quan-năm-2024-đáng-tham-khảo&quot;&gt;4. Bài tổng quan năm 2024 đáng tham khảo&lt;/h2&gt;

&lt;p&gt;Bomze, Rinaldi và Zeffiro, &lt;strong&gt;“Frank–Wolfe and friends: a journey into projection-free first-order optimization methods”&lt;/strong&gt;, &lt;em&gt;Ann. Oper. Res.&lt;/em&gt; 343:607–638, 2024, &lt;a href=&quot;https://doi.org/10.1007/s10479-024-06251-7&quot;&gt;doi:10.1007/s10479-024-06251-7&lt;/a&gt;, hệ thống hóa các ứng dụng từ gán lưu lượng giao thông, tối ưu hàm dưới mô-đun (submodular), hoàn thiện ma trận, tấn công đối kháng, huấn luyện SVM đến tìm tập đầy đủ cực đại (maximum clique), đồng thời trình bày các biến thể hiện đại (away-step, pairwise, sliding, ngẫu nhiên). Đây là tài liệu tra cứu tổng quan hữu ích khi cần chọn biến thể phù hợp cho từng ứng dụng.&lt;/p&gt;

&lt;h2 id=&quot;khi-nào-nên-chọn-frankwolfe-thay-vì-gradient-có-chiếu&quot;&gt;Khi nào nên chọn Frank–Wolfe thay vì gradient có chiếu&lt;/h2&gt;

&lt;p&gt;Nên dùng Frank–Wolfe khi: (i) tập ràng buộc \(\mathcal{C}\) là đa diện, phổ diện (spectrahedron) hoặc đa diện luồng mà LMO quy về một phép sắp xếp, bài toán gán hay tìm vector kỳ dị hàng đầu; và (ii) mong muốn các điểm lặp giữ dạng tổ hợp lồi thưa của ít nguyên tử. Ngược lại, nên chọn phương pháp chiếu khi phép chiếu rất rẻ (như cắt ngưỡng trên hình hộp hay chiếu lên đơn hình theo thuật toán Michelot) và cần tốc độ hội tụ tuyến tính mà Frank–Wolfe thuần không đạt được nếu thiếu away-step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Xét bài toán mô phỏng chuyển màu 1 chiều với hai biểu đồ tần suất \(a,b\in\Delta^{k}\) và ma trận chi phí \(C_{ij}=(i-j)^2\). Hãy chạy: (i) 40 bước Frank–Wolfe trên đa diện vận chuyển (trong đó LMO là bài toán vận chuyển, có thể giải bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.optimize.linprog&lt;/code&gt; với kích thước nhỏ \(k=12\)) và (ii) gradient descent có chiếu trên cùng đa diện. So sánh số phần tử khác không trong kế hoạch vận chuyển và giá trị chi phí OT giữa hai phương pháp: Frank–Wolfe cho nghiệm thưa hơn, còn PGD thường giảm chi phí nhanh hơn ở vài bước đầu nếu phép chiếu được cài đặt chính xác.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;M. Jaggi, ICML 2013 — khe đối ngẫu FW và tốc độ bất biến affine.&lt;/li&gt;
  &lt;li&gt;S. Lacoste-Julien, M. Jaggi, M. Schmidt, P. Pletscher, ICML 2013 — BCFW cho SVM cấu trúc.&lt;/li&gt;
  &lt;li&gt;T. Fukunaga and H. Kasai, &lt;a href=&quot;https://arxiv.org/abs/2205.13766&quot;&gt;arXiv:2205.13766&lt;/a&gt;, 2022 / ICASSP 2022 — BCFW cho OT bán nới, chuyển màu.&lt;/li&gt;
  &lt;li&gt;T. Séjourné et al., AISTATS 2022, &lt;a href=&quot;https://proceedings.mlr.press/v151/sejourne22a.html&quot;&gt;PMLR v151&lt;/a&gt; — FW cho OT không cân 1-D.&lt;/li&gt;
  &lt;li&gt;J. Macdonald et al., ICML 2022, &lt;a href=&quot;https://proceedings.mlr.press/v162/macdonald22a.html&quot;&gt;PMLR v162&lt;/a&gt; — FW cho giải thích méo-tốc độ.&lt;/li&gt;
  &lt;li&gt;I. M. Bomze, F. Rinaldi, D. Zeffiro, &lt;em&gt;Ann. Oper. Res.&lt;/em&gt;, 2024, &lt;a href=&quot;https://doi.org/10.1007/s10479-024-06251-7&quot;&gt;doi:10.1007/s10479-024-06251-7&lt;/a&gt; — “Frank–Wolfe and friends.”&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>22-05 Ứng dụng hiện đại của Frank–Wolfe</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_05_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_05_modern_applications</id>
   <content type="html">&lt;p&gt;Một thuật toán từ năm 1956 sống khỏe trong các hội nghị học máy hàng đầu thập niên 2020 (ICML, AISTATS, NeurIPS) không phải vì hoài cổ, mà vì cấu trúc hình học của nhiều bài toán hiện đại trùng khớp hoàn hảo với điểm mạnh nhất của nó: &lt;strong&gt;tập ràng buộc có LMO siêu rẻ nhưng phép chiếu lại quá đắt&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Từ bài toán dự đoán có cấu trúc trên hàng nghìn nhãn chuỗi, bài toán vận chuyển tối ưu (Optimal Transport) ghép phân phối màu ảnh, cho đến việc giải thích quyết định của mạng nơ-ron sâu bằng các mặt nạ thưa, Frank–Wolfe liên tục xuất hiện như một “vũ khí thầm lặng” giúp giải bài toán quy mô lớn mà vẫn giữ nguyên cấu trúc diễn giải được của nghiệm.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-ứng-dụng-hiện-đại-kết-nối-với-frankwolfe&quot;&gt;Kiến thức cần nhớ: Bốn nhánh ứng dụng hiện đại kết nối với Frank–Wolfe&lt;/h2&gt;

&lt;p&gt;Để đọc bài tổng quan ứng dụng này thật hiệu quả, hãy nắm trực giác của bốn lĩnh vực mà Frank–Wolfe đang đóng vai trò trung tâm:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dự đoán có cấu trúc (Structured Prediction &amp;amp; BCFW):&lt;/strong&gt; Trong mô hình CRF hay SVM có cấu trúc, không gian nhãn \(\mathcal{Y}_i\) lớn theo hàm mũ, khiến miền đối ngẫu là tích của \(n\) đơn hình khổng lồ. Frank–Wolfe theo khối tọa độ (BCFW) chỉ cập nhật &lt;em&gt;một&lt;/em&gt; mẫu \(i\) mỗi bước, biến LMO thành đúng thuật toán suy luận (như Viterbi) đã có sẵn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vận chuyển tối ưu (Optimal Transport — OT):&lt;/strong&gt; OT tìm kế hoạch chuyển khối lượng từ phân phối nguồn sang phân phối đích với chi phí nhỏ nhất. Trong bài toán OT bán nới lỏng hoặc OT không cân bằng 1 chiều, LMO quy về thao tác tìm cực tiểu từng cột hoặc sắp xếp 1 chiều — rẻ hơn rất nhiều so với giải quy hoạch tuyến tính đầy đủ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả năng giải thích mạng nơ-ron (Explainable AI &amp;amp; Rate-Distortion):&lt;/strong&gt; Khi giải thích vì sao mạng nơ-ron dự đoán một ảnh là “mèo”, ta muốn tìm một mặt nạ đặc trưng nằm trong quả cầu \(\ell_1\) (ít pixel nhất nhưng giữ nguyên dự đoán). Frank–Wolfe đảm bảo mặt nạ tìm được có tính thưa kiểm soát được trực tiếp qua số vòng lặp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh đổi giữa Frank–Wolfe và Sinkhorn/PGD:&lt;/strong&gt; Hiểu rõ khi nào cần kế hoạch vận chuyển &lt;em&gt;thưa và không chính quy hóa entropy&lt;/em&gt; (ưu thế của Frank–Wolfe) so với kế hoạch &lt;em&gt;trơn, dễ song song hóa trên GPU&lt;/em&gt; (ưu thế của thuật toán Sinkhorn).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-một-vòng-block-coordinate-frankwolfe-bcfw-trên-tích-hai-đơn-hình&quot;&gt;Giải thích: Tính tay một vòng Block-Coordinate Frank–Wolfe (BCFW) trên tích hai đơn hình&lt;/h3&gt;

&lt;p&gt;Để hình dung cách BCFW hoạt động trong dự đoán có cấu trúc và OT bán nới lỏng, xét miền khả thi là tích của hai đơn hình xác suất \(C = \Delta_2 \times \Delta_2\), tức biến \(\alpha = (\alpha^{(1)}, \alpha^{(2)})\) với \(\alpha^{(i)} \in \Delta_2\). Giả sử ta tối ưu hàm mục tiêu \(f(\alpha^{(1)}, \alpha^{(2)}) = \frac{1}{2}\|\alpha^{(1)} - (1.2, -0.2)\|_2^2 + \frac{1}{2}\|\alpha^{(2)} - (0.1, 0.9)\|_2^2\), khởi tạo từ \(\alpha_0^{(1)} = (0.5, 0.5)\) và \(\alpha_0^{(2)} = (0.5, 0.5)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Chọn ngẫu nhiên khối 1 (giữ nguyên khối 2):&lt;/strong&gt;
Tính gradient riêng theo khối 1: \(\nabla_1 f = (0.5 - 1.2,\; 0.5 - (-0.2)) = (-0.7,\; 0.7)\).
Gọi LMO chỉ trên \(\Delta_2\) của khối 1: \(\arg\min_{s \in \Delta_2} (-0.7 s_1 + 0.7 s_2) = (1, 0)\).
Với bước \(\gamma = 0.5\), cập nhật khối 1:
\(\alpha_1^{(1)} = 0.5(0.5, 0.5) + 0.5(1, 0) = (0.75,\; 0.25)\), trong khi \(\alpha_1^{(2)}\) giữ nguyên \((0.5, 0.5)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Chọn khối 2 (giữ nguyên khối 1):&lt;/strong&gt;
Tính gradient riêng theo khối 2: \(\nabla_2 f = (0.5 - 0.1,\; 0.5 - 0.9) = (0.4,\; -0.4)\).
Gọi LMO trên \(\Delta_2\) của khối 2: \(\arg\min_{s \in \Delta_2} (0.4 s_1 - 0.4 s_2) = (0, 1)\).
Với bước \(\gamma = 0.5\), cập nhật khối 2:
\(\alpha_2^{(2)} = 0.5(0.5, 0.5) + 0.5(0, 1) = (0.25,\; 0.75)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa thực chiến:&lt;/strong&gt; Thay vì phải gọi LMO cho cả \(n\) khối (tốn \(n\) lần chạy thuật toán suy luận chỉ để đi 1 bước), BCFW chỉ cần tính gradient và LMO trên &lt;strong&gt;đúng 1 khối&lt;/strong&gt; mỗi lần cập nhật — giảm chi phí mỗi vòng đi \(n\) lần mà vẫn bảo toàn tính khả thi trên toàn bộ tích đơn hình!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Frank–Wolfe (gradient có điều kiện) là lựa chọn phù hợp khi tập khả thi \(\mathcal{C}\) có &lt;strong&gt;bộ giải cực tiểu tuyến tính (linear minimization oracle — LMO)&lt;/strong&gt; rẻ:&lt;/p&gt;

\[s_k \in \arg\min_{s\in\mathcal{C}}\ \langle \nabla f(x_k), s\rangle\]

&lt;p&gt;trong khi &lt;em&gt;phép chiếu&lt;/em&gt; lên \(\mathcal{C}\) tốn kém hoặc phá vỡ tính thưa của nghiệm. Làn sóng nghiên cứu thập niên 2010 (Jaggi; Lacoste-Julien) đã hình thành nên bộ công cụ ứng dụng rộng rãi trong thập niên 2020: dự đoán có cấu trúc, vận chuyển tối ưu và giải thích mạng nơ-ron có ràng buộc. Bài đọc tùy chọn này trình bày bốn trường hợp tiêu biểu, không lặp lại phần chứng minh hội tụ.&lt;/p&gt;

&lt;h2 id=&quot;1-dự-đoán-có-cấu-trúc-frankwolfe-theo-khối-tọa-độ&quot;&gt;1. Dự đoán có cấu trúc: Frank–Wolfe theo khối tọa độ&lt;/h2&gt;

&lt;p&gt;Bài toán cực tiểu hóa rủi ro thực nghiệm (ERM) trong dự đoán có cấu trúc (CRF, SVM có cấu trúc) có dạng:&lt;/p&gt;

\[\min_{w}\ \frac{\lambda}{2}\|w\|_2^2 + \frac1n\sum_{i=1}^n \max_{y\in\mathcal{Y}_i}\bigl(\langle w, \phi(x_i,y)\rangle - \delta(y_i,y)\bigr).\]

&lt;p&gt;Bài toán đối ngẫu là tối ưu trên tích Descartes của các đơn hình (simplex) xác suất. Nhờ cấu trúc tích này, mỗi bước &lt;strong&gt;Frank–Wolfe theo khối tọa độ (BCFW)&lt;/strong&gt; tương ứng đúng với một lần gọi &lt;em&gt;suy luận tăng cường hàm mất mát (loss-augmented inference)&lt;/em&gt; — chính là bộ giải vốn đã có sẵn trong mô hình cấu trúc. Công trình của Lacoste-Julien, Jaggi, Schmidt và Pletscher (ICML 2013) đặt nền móng cho hướng này, và đó vẫn là lý do Frank–Wolfe được duy trì trong các thư viện dự đoán có cấu trúc hiện nay.&lt;/p&gt;

&lt;p&gt;Cùng ý tưởng tách theo khối tọa độ được áp dụng sang &lt;strong&gt;vận chuyển tối ưu (optimal transport — OT)&lt;/strong&gt;. Fukunaga và Kasai (&lt;a href=&quot;https://arxiv.org/abs/2205.13766&quot;&gt;arXiv:2205.13766&lt;/a&gt;, 2022; bản hội nghị ICASSP 2022) triển khai BCFW — bao gồm cả biến thể away-step và pairwise step — cho bài toán OT &lt;em&gt;bán nới lỏng (semi-relaxed)&lt;/em&gt;, nơi ràng buộc biên chặt thông thường buộc phải giải một bài toán quy hoạch tuyến tính đầy đủ. Bộ giải tuyến tính trên từng khối có nghiệm dạng đóng trên đơn hình và tạo ra kế hoạch vận chuyển thưa. Ứng dụng minh họa chính của bài báo là &lt;strong&gt;chuyển màu (color transfer)&lt;/strong&gt; giữa hai ảnh: kế hoạch vận chuyển có cấu trúc thưa trên đơn hình đúng với thế mạnh bảo toàn tính thưa của Frank–Wolfe.&lt;/p&gt;

&lt;h2 id=&quot;2-vận-chuyển-tối-ưu-không-cân-bằng-một-chiều&quot;&gt;2. Vận chuyển tối ưu không cân bằng một chiều&lt;/h2&gt;

&lt;p&gt;Séjourné, Feydy, Vialard, Trouvé và Peyré (AISTATS 2022, &lt;a href=&quot;https://proceedings.mlr.press/v151/sejourne22a.html&quot;&gt;PMLR v151&lt;/a&gt;) áp dụng Frank–Wolfe lên bài toán &lt;em&gt;đối ngẫu&lt;/em&gt; của vận chuyển tối ưu không cân bằng 1 chiều (1-D unbalanced OT). Bài toán con tuyến tính hóa lúc này là bài toán OT 1 chiều &lt;em&gt;cân bằng&lt;/em&gt;, có thể giải trong thời gian tuyến tính sau một bước sắp xếp. Đây là minh họa trực diện cho nguyên lý của Frank–Wolfe: thay thế bài toán phi tuyến khó bằng một bộ giải tuyến tính đơn giản và hiệu quả. Nhóm tác giả cũng tính tâm khối (barycenter) 1 chiều bằng cùng phép tuyến tính hóa. Khi cần nghiệm UOT &lt;em&gt;không chính quy hóa&lt;/em&gt;, Frank–Wolfe có thể vượt trội Sinkhorn; ngược lại, khi cần kế hoạch ghép trơn và tận dụng GPU tốt, Sinkhorn vẫn có ưu thế. Điều quan trọng là hiểu rõ &lt;em&gt;vì sao&lt;/em&gt; có sự đánh đổi này thay vì chỉ chọn một phương pháp cố định.&lt;/p&gt;

&lt;h2 id=&quot;3-giải-thích-mạng-nơ-ron-có-ràng-buộc&quot;&gt;3. Giải thích mạng nơ-ron có ràng buộc&lt;/h2&gt;

&lt;p&gt;Macdonald, Besançon và Pokutta (ICML 2022, &lt;a href=&quot;https://proceedings.mlr.press/v162/macdonald22a.html&quot;&gt;PMLR v162&lt;/a&gt;) phát biểu lại bài toán &lt;strong&gt;giải thích theo độ méo–tốc độ (rate-distortion explanation — RDE)&lt;/strong&gt; dưới dạng tối ưu có ràng buộc và giải bằng Frank–Wolfe tất định cũng như ngẫu nhiên. Yêu cầu độ thưa của bản đồ độ liên quan trở thành ràng buộc hình cầu \(\ell_1\) (hoặc đơn hình); còn biến thể &lt;em&gt;xếp hạng đặc trưng&lt;/em&gt; tối ưu trên &lt;strong&gt;đa diện Birkhoff&lt;/strong&gt; (bao lồi của tập các ma trận hoán vị), nơi bộ giải tuyến tính quy về bài toán gán tuyến tính (linear assignment). Trên các bộ dữ liệu phân loại ảnh tiêu chuẩn, các biến thể đa tốc độ và xếp hạng đạt kết quả tốt hơn RDE gốc. Về bản chất, đây là một dạng dự đoán có cấu trúc: miền đa diện mã hóa dạng lời giải thích dễ đọc, và Frank–Wolfe tránh hoàn toàn phép chiếu tốn kém lên đa diện đó.&lt;/p&gt;

&lt;h2 id=&quot;4-bài-tổng-quan-năm-2024-đáng-tham-khảo&quot;&gt;4. Bài tổng quan năm 2024 đáng tham khảo&lt;/h2&gt;

&lt;p&gt;Bomze, Rinaldi và Zeffiro, &lt;strong&gt;“Frank–Wolfe and friends: a journey into projection-free first-order optimization methods”&lt;/strong&gt;, &lt;em&gt;Ann. Oper. Res.&lt;/em&gt; 343:607–638, 2024, &lt;a href=&quot;https://doi.org/10.1007/s10479-024-06251-7&quot;&gt;doi:10.1007/s10479-024-06251-7&lt;/a&gt;, hệ thống hóa các ứng dụng từ gán lưu lượng giao thông, tối ưu hàm dưới mô-đun (submodular), hoàn thiện ma trận, tấn công đối kháng, huấn luyện SVM đến tìm tập đầy đủ cực đại (maximum clique), đồng thời trình bày các biến thể hiện đại (away-step, pairwise, sliding, ngẫu nhiên). Đây là tài liệu tra cứu tổng quan hữu ích khi cần chọn biến thể phù hợp cho từng ứng dụng.&lt;/p&gt;

&lt;h2 id=&quot;khi-nào-nên-chọn-frankwolfe-thay-vì-gradient-có-chiếu&quot;&gt;Khi nào nên chọn Frank–Wolfe thay vì gradient có chiếu&lt;/h2&gt;

&lt;p&gt;Nên dùng Frank–Wolfe khi: (i) tập ràng buộc \(\mathcal{C}\) là đa diện, phổ diện (spectrahedron) hoặc đa diện luồng mà LMO quy về một phép sắp xếp, bài toán gán hay tìm vector kỳ dị hàng đầu; và (ii) mong muốn các điểm lặp giữ dạng tổ hợp lồi thưa của ít nguyên tử. Ngược lại, nên chọn phương pháp chiếu khi phép chiếu rất rẻ (như cắt ngưỡng trên hình hộp hay chiếu lên đơn hình theo thuật toán Michelot) và cần tốc độ hội tụ tuyến tính mà Frank–Wolfe thuần không đạt được nếu thiếu away-step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Xét bài toán mô phỏng chuyển màu 1 chiều với hai biểu đồ tần suất \(a,b\in\Delta^{k}\) và ma trận chi phí \(C_{ij}=(i-j)^2\). Hãy chạy: (i) 40 bước Frank–Wolfe trên đa diện vận chuyển (trong đó LMO là bài toán vận chuyển, có thể giải bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.optimize.linprog&lt;/code&gt; với kích thước nhỏ \(k=12\)) và (ii) gradient descent có chiếu trên cùng đa diện. So sánh số phần tử khác không trong kế hoạch vận chuyển và giá trị chi phí OT giữa hai phương pháp: Frank–Wolfe cho nghiệm thưa hơn, còn PGD thường giảm chi phí nhanh hơn ở vài bước đầu nếu phép chiếu được cài đặt chính xác.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;M. Jaggi, ICML 2013 — khe đối ngẫu FW và tốc độ bất biến affine.&lt;/li&gt;
  &lt;li&gt;S. Lacoste-Julien, M. Jaggi, M. Schmidt, P. Pletscher, ICML 2013 — BCFW cho SVM cấu trúc.&lt;/li&gt;
  &lt;li&gt;T. Fukunaga and H. Kasai, &lt;a href=&quot;https://arxiv.org/abs/2205.13766&quot;&gt;arXiv:2205.13766&lt;/a&gt;, 2022 / ICASSP 2022 — BCFW cho OT bán nới, chuyển màu.&lt;/li&gt;
  &lt;li&gt;T. Séjourné et al., AISTATS 2022, &lt;a href=&quot;https://proceedings.mlr.press/v151/sejourne22a.html&quot;&gt;PMLR v151&lt;/a&gt; — FW cho OT không cân 1-D.&lt;/li&gt;
  &lt;li&gt;J. Macdonald et al., ICML 2022, &lt;a href=&quot;https://proceedings.mlr.press/v162/macdonald22a.html&quot;&gt;PMLR v162&lt;/a&gt; — FW cho giải thích méo-tốc độ.&lt;/li&gt;
  &lt;li&gt;I. M. Bomze, F. Rinaldi, D. Zeffiro, &lt;em&gt;Ann. Oper. Res.&lt;/em&gt;, 2024, &lt;a href=&quot;https://doi.org/10.1007/s10479-024-06251-7&quot;&gt;doi:10.1007/s10479-024-06251-7&lt;/a&gt; — “Frank–Wolfe and friends.”&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>21-09 Ứng dụng hiện đại của ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_09_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_09_modern_applications</id>
   <content type="html">&lt;p&gt;Khi nhìn vào công thức ADMM đồng thuận ở bài 21-05, ta dễ nghĩ nó chỉ dành cho những bài toán học máy tĩnh trên cụm máy chủ. Nhưng từ năm 2022 đến 2026, chính kiến trúc đồng thuận + biến đối ngẫu đó lại đang vận hành âm thầm phía sau những hạ tầng trọng yếu nhất ngoài đời thực: từ &lt;strong&gt;điều độ lưới điện thông minh theo thời gian thực&lt;/strong&gt; (nơi hàng trăm nhà máy điện mặt trời, pin lưu trữ và trạm biến áp phải cân bằng cung–cầu mỗi vài giây mà không lộ bí mật chi phí), đến &lt;strong&gt;học sâu liên kết&lt;/strong&gt; và &lt;strong&gt;khôi phục ảnh y tế bằng Plug-and-Play ADMM&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-yêu-cầu-thực-chiến-thúc-đẩy-làn-sóng-admm-giai-đoạn-20222026&quot;&gt;Kiến thức cần nhớ: Ba yêu cầu thực chiến thúc đẩy làn sóng ADMM giai đoạn 2022–2026&lt;/h2&gt;

&lt;p&gt;So với các bài toán mẫu trong giáo trình, các hệ thống thực tế đặt ra ba thách thức mới mà các biến thể ADMM hiện đại giải quyết trực tiếp:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính riêng tư và tự trị cục bộ (Privacy-Preserving Coordination):&lt;/strong&gt; Trong lưới điện liên vùng hay y tế liên viện, các đơn vị không được phép gửi dữ liệu thô hoặc đường cong chi phí lên máy chủ trung tâm. Consensus ADMM chỉ trao đổi biến biên (công suất đường dây liên kết hoặc vector trọng số mô hình) và biến đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vận hành trực tuyến theo thời gian thực (Online / Warm-Started ADMM):&lt;/strong&gt; Trong bài toán điều độ điện trực tuyến (Online OPF), phụ tải thay đổi liên tục mỗi vài giây. Thay vì giải lại từ đầu, hệ thống khởi động nóng (warm-start) từ nghiệm gốc và biến đối ngẫu \(w\) của chu kỳ trước — chỉ cần 2–5 vòng lặp ADMM là theo kịp biến động thời gian thực!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tích hợp tiên nghiệm học sâu (Deep Priors &amp;amp; Nonconvex ADMM):&lt;/strong&gt; Bằng cách thay toán tử proximal cổ điển bằng bộ khử nhiễu mạng nơ-ron (PnP-ADMM) hoặc áp dụng cho hàm mất mát không lồi trơn có điều chuẩn, phạm vi của ADMM mở rộng mạnh mẽ ra ngoài ranh giới tối ưu lồi cổ điển.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-điều-phối-công-suất-đường-dây-liên-kết-giữa-2-vùng-lưới-điện-bằng-1-bước-consensus-admm&quot;&gt;Giải thích: Điều phối công suất đường dây liên kết giữa 2 vùng lưới điện bằng 1 bước Consensus ADMM&lt;/h3&gt;

&lt;p&gt;Giả sử hai vùng lưới điện (Vùng 1 và Vùng 2) nối với nhau bởi một đường dây truyền tải có công suất trao đổi \(z\) (đơn vị MW). Tại một chu kỳ điều độ với \(\rho = 1\) và biến đối ngẫu khởi tạo \(w_1^{(0)} = w_2^{(0)} = 0\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Vùng 1 tối ưu chi phí phát điện cục bộ và muốn xuất sang Vùng 2 mức \(p_1^{(1)} = 60\text{ MW}\).&lt;/li&gt;
  &lt;li&gt;Vùng 2 tối ưu chi phí cục bộ và chỉ muốn nhận từ Vùng 1 mức \(p_2^{(1)} = 40\text{ MW}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước đồng thuận trên đường dây liên kết:&lt;/strong&gt;
Nút điều phối lấy trung bình công suất đề xuất:
\(z^{(1)} = \frac{p_1^{(1)} + p_2^{(1)}}{2} = \frac{60 + 40}{2} = 50\text{ MW}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước cập nhật tín hiệu giá đối ngẫu \(w_i^{(1)} = w_i^{(0)} + p_i^{(1)} - z^{(1)}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vùng 1 nhận \(w_1^{(1)} = 60 - 50 = +10\) (tín hiệu phạt vì muốn xuất nhiều hơn mức đồng thuận, kéo \(p_1\) giảm xuống ở chu kỳ sau).&lt;/li&gt;
      &lt;li&gt;Vùng 2 nhận \(w_2^{(1)} = 40 - 50 = -10\) (tín hiệu khuyến khích nhận thêm điện, kéo \(p_2\) tăng lên ở chu kỳ sau).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết quả sau vài chu kỳ trao đổi:&lt;/strong&gt; Hai vùng tự hội tụ về một mức công suất chung \(z^\star\) (ví dụ \(52\text{ MW}\)) tối ưu hóa tổng chi phí toàn lưới mà &lt;strong&gt;không một vùng nào phải chia sẻ thông số tổ máy hay phụ tải nội bộ của mình&lt;/strong&gt;!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Các bài trước trong chương này xem ADMM như một phương pháp tách bài toán &lt;em&gt;lồi có cấu trúc&lt;/em&gt;: gồm hai (hoặc nhiều) khối proximal dễ tính, một bước cập nhật đối ngẫu, cùng các phần dư có thể theo dõi trực tiếp. Tuy nhiên, phạm vi ứng dụng của ADMM không dừng lại ở năm 2011. Giai đoạn 2022–2026, cùng khuôn mẫu đồng thuận và Lagrangian tăng cường này tiếp tục xuất hiện trong học sâu liên kết, tạo ảnh tính toán với bộ khử nhiễu học được, và điều độ hệ thống điện trực tuyến. Bài đọc tùy chọn này phác họa các hướng triển khai đó thay vì suy diễn lại ADMM dạng chuẩn hóa.&lt;/p&gt;

&lt;p&gt;Nhắc lại bài toán đồng thuận từ &lt;a href=&quot;/contents/vi/chapter21/21_05_Consensus_ADMM/&quot;&gt;21-05&lt;/a&gt;:&lt;/p&gt;

\[\min_{x_1,\ldots,x_B,z}\ \sum_{i=1}^B f_i(x_i)\qquad\text{subject to}\qquad x_i=z.\]

&lt;p&gt;Mỗi máy khách (hoặc mỗi khối ảnh, mỗi vùng lưới điện) giữ một hàm mục tiêu cục bộ \(f_i\) riêng; máy chủ chỉ thực hiện phép lấy trung bình và cập nhật biến đối ngẫu. Tất cả các ứng dụng dưới đây đều là những chuyên biệt hóa của khuôn mẫu này.&lt;/p&gt;

&lt;h2 id=&quot;1-fedadmm-học-đồng-thuận-khi-dữ-liệu-giữa-các-máy-khách-không-đồng-nhất&quot;&gt;1. FedADMM: học đồng thuận khi dữ liệu giữa các máy khách không đồng nhất&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Học liên kết (federated learning)&lt;/strong&gt; (Chương 29) thường lấy trung bình &lt;em&gt;trọng số&lt;/em&gt; sau một số bước SGD cục bộ (thuật toán FedAvg). Cách làm đó &lt;em&gt;không&lt;/em&gt; phải là ADMM: không có biến đối ngẫu theo dõi sai lệch và hiện tượng trôi cục bộ (client drift) xuất hiện tự nhiên. Một hướng nghiên cứu giai đoạn 2022–2023 đã đưa biến đối ngẫu quay trở lại.&lt;/p&gt;

&lt;p&gt;Gong, Li và Freris (&lt;a href=&quot;https://arxiv.org/abs/2204.03529&quot;&gt;arXiv:2204.03529&lt;/a&gt;, 2022) đề xuất &lt;strong&gt;FedADMM&lt;/strong&gt;. Mỗi máy khách \(i\) cực tiểu hóa xấp xỉ hàm Lagrangian tăng cường (cho phép thực hiện vài bước SGD cục bộ — tức bước cập nhật \(x\) &lt;em&gt;không chính xác&lt;/em&gt;), máy chủ lấy trung bình các biến gốc, còn biến đối ngẫu \(w_i\) tích lũy độ lệch \(x_i-z\). Chi phí truyền thông mỗi vòng tương đương FedAvg, nhưng biến đối ngẫu tự thích nghi với &lt;strong&gt;tính không đồng nhất về thống kê (statistical heterogeneity)&lt;/strong&gt; mà không cần tinh chỉnh thủ công hệ số proximal. Bài báo ghi nhận giảm tới 87% số vòng giao tiếp so với FedAvg/FedProx trên CIFAR-10 và Fashion-MNIST dưới phân hoạch non-IID.&lt;/p&gt;

&lt;p&gt;Zhou và Li, &lt;em&gt;Federated Learning via Inexact ADMM&lt;/em&gt;, IEEE TPAMI 45(8):9699–9708, 2023, &lt;a href=&quot;https://doi.org/10.1109/TPAMI.2023.3243080&quot;&gt;doi:10.1109/TPAMI.2023.3243080&lt;/a&gt;, bổ sung cơ sở lý thuyết cho trường hợp giải cục bộ không chính xác, tham gia một phần (partial participation) và hàm mục tiêu không lồi. Có thể rút ra điểm chính rất rõ ràng: nếu bài toán có thể phát biểu dưới dạng đồng thuận và cần theo dõi phần dư, ADMM vẫn là công cụ thích hợp. Khi mô hình là mạng sâu và nút thắt nằm ở &lt;em&gt;số vòng truyền thông&lt;/em&gt;, FedADMM đóng vai trò là biến thể thập niên 2020 của &lt;a href=&quot;/contents/vi/chapter21/21_05_Consensus_ADMM/&quot;&gt;21-05&lt;/a&gt; — không thay thế FedAvg và cũng không đơn thuần là “SGD cộng thêm nhân tử Lagrange”.&lt;/p&gt;

&lt;p&gt;Một nghiên cứu ứng dụng y khoa giai đoạn 2025–2026 (học liên kết tăng cường bằng ADMM trên bộ dữ liệu tiểu đường PIMA và ảnh X-quang ngực) so sánh FedADMM với SCAFFOLD và FedDyn. Đây là một &lt;em&gt;triển khai ứng dụng&lt;/em&gt; hơn là thuật toán mới: các bệnh viện không thể gộp chung dữ liệu ảnh, và phần dư gốc–đối ngẫu cung cấp một chỉ báo hữu ích để kiểm tra quá trình hội tụ.&lt;/p&gt;

&lt;h2 id=&quot;2-plug-and-play-admm-trong-tạo-ảnh-tính-toán&quot;&gt;2. Plug-and-play ADMM trong tạo ảnh tính toán&lt;/h2&gt;

&lt;p&gt;Phục hồi ảnh là bài toán tối ưu hợp thành kinh điển:&lt;/p&gt;

\[\min_x\ \tfrac12\|Ax-b\|_2^2 + g(x),\]

&lt;p&gt;trong đó \(A\) mô tả toán tử làm mờ hoặc lấy mẫu thưa và \(g\) là hàm chính quy hóa. ADMM cổ điển sử dụng toán tử \(\mathrm{prox}_g\). &lt;strong&gt;Plug-and-play (PnP) ADMM&lt;/strong&gt; thay thế bước proximal đó bằng một bộ khử nhiễu có sẵn \(D_{\sigma}\) — trước đây là BM3D, hiện nay thường là mạng CNN — đồng thời giữ nguyên bước cập nhật \(x\) đảm bảo tính trung thành với dữ liệu (data fidelity).&lt;/p&gt;

&lt;p&gt;Chan, Wang và Elgendy, &lt;em&gt;IEEE Trans. Computational Imaging&lt;/em&gt; 3:84–98, 2017 (trực tuyến 2016), &lt;a href=&quot;https://doi.org/10.1109/TCI.2016.2629286&quot;&gt;doi:10.1109/TCI.2016.2629286&lt;/a&gt;, chứng minh hội tụ điểm bất động đối với bộ khử nhiễu &lt;em&gt;bị chặn&lt;/em&gt; theo lược đồ tiếp diễn (continuation), sử dụng bài toán siêu phân giải và ảnh đơn photon làm ví dụ minh họa. Giai đoạn 2022–2023 đánh dấu sự chuyển dịch sang bộ khử nhiễu bằng mạng sâu. Zhang, Li, Zuo, Zhang, Van Gool và Timofte, &lt;em&gt;Plug-and-Play Image Restoration with Deep Denoiser Prior&lt;/em&gt;, IEEE TPAMI 44(10):6360–6376, 2022, &lt;a href=&quot;https://doi.org/10.1109/TPAMI.2021.3088914&quot;&gt;doi:10.1109/TPAMI.2021.3088914&lt;/a&gt;, tích hợp một mạng DRUNet đã huấn luyện sẵn vào nhiều bài toán ngược khác nhau. Hurault, Chambolle, Leclaire và Papadakis (&lt;a href=&quot;https://arxiv.org/abs/2210.10605&quot;&gt;arXiv:2210.10605&lt;/a&gt;, 2023) tuyến tính hóa bước cập nhật \(x\) của ADMM để xử lý toán tử mờ không đồng nhất mà không cần vòng lặp liên hợp gradient (CG) bên trong. Shoushtari, Liu, Schniter và Kamilov (&lt;a href=&quot;https://arxiv.org/abs/2311.18810&quot;&gt;arXiv:2311.18810&lt;/a&gt;, 2023) giải thích vì sao PnP-ADMM vẫn thường hội tụ ngay cả với các mạng CNN &lt;em&gt;giãn nở&lt;/em&gt; khi xem \(D_{\sigma}\) như một ước lượng MMSE (tương ứng với toán tử proximal của một hàm \(g\) có thể không lồi).&lt;/p&gt;

&lt;p&gt;Điểm quan trọng về mặt kỹ thuật: ADMM đóng vai trò như một &lt;em&gt;giao diện mô-đun&lt;/em&gt;. Một khối biểu diễn mô hình vật lý (\(A\), hàm hợp lý Poisson), còn khối kia là tri thức tiên nghiệm học từ dữ liệu. Nhờ đó, không cần huấn luyện lại mạng nơ-ron cho từng thiết bị máy ảnh riêng biệt. Đây là lý do cộng đồng tạo ảnh tính toán vẫn duy trì giảng dạy và sử dụng ADMM bên cạnh các bộ tối ưu như Adam.&lt;/p&gt;

&lt;h2 id=&quot;3-tối-ưu-dòng-công-suất-phân-tán&quot;&gt;3. Tối ưu dòng công suất phân tán&lt;/h2&gt;

&lt;p&gt;Bài toán tối ưu dòng công suất (Optimal Power Flow — OPF) là một bài toán quy hoạch bậc hai có ràng buộc bậc hai (QCQP) không lồi trên lưới điện, liên quan đến điện áp, công suất phát và giới hạn đường dây. Các vùng vận hành thường không chia sẻ toàn bộ dữ liệu lưới nội bộ, trong khi nguồn năng lượng tái tạo biến động liên tục khiến bài toán mang tính &lt;em&gt;trực tuyến&lt;/em&gt;. ADMM đồng thuận tách lưới điện tại các nút biên: mỗi vùng tự giải bài toán OPF cục bộ, còn biến đối ngẫu trên điện áp biên buộc các vùng thỏa mãn định luật Kirchhoff.&lt;/p&gt;

&lt;p&gt;Wang, Pu, Huang, Yu, Shi và Wang, &lt;em&gt;Online ADMM for Distributed Optimal Power Flow via Lagrangian Duality&lt;/em&gt;, &lt;em&gt;Energies&lt;/em&gt; 15(24):9525, 2022, &lt;a href=&quot;https://doi.org/10.3390/en15249525&quot;&gt;doi:10.3390/en15249525&lt;/a&gt;, triển khai ADMM đồng thuận trên bài toán OPF &lt;em&gt;đối ngẫu&lt;/em&gt; để chỉ trao đổi các nhân tử tại biên và cập nhật &lt;em&gt;trực tuyến&lt;/em&gt; khi nguồn phát phân tán dao động. Thực nghiệm trên lưới IEEE 30 nút so sánh OPF tĩnh và động cho thấy vòng lặp ADMM trực tuyến bám sát độ dốc biến thiên của nguồn tái tạo mà không làm các tổ máy phát truyền thống thay đổi công suất đột ngột như khi giải lại toàn bộ OPF ngoại tuyến. Đây chính là khuôn mẫu đồng thuận của Boyd áp dụng cho hàm mục tiêu \(f_i\) của hệ thống điện, cho thấy “tối ưu phân tán” hiện nay không chỉ giới hạn ở tác vụ all-reduce trên cụm GPU.&lt;/p&gt;

&lt;h2 id=&quot;so-sánh-phạm-vi-với-chương-29&quot;&gt;So sánh phạm vi với Chương 29&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Ứng dụng&lt;/th&gt;
      &lt;th&gt;Thành phần tách&lt;/th&gt;
      &lt;th&gt;Đại lượng lấy trung bình&lt;/th&gt;
      &lt;th&gt;Tiêu chí kiểm chứng&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;FedADMM&lt;/td&gt;
      &lt;td&gt;hàm mất mát huấn luyện cục bộ&lt;/td&gt;
      &lt;td&gt;biến gốc \(z\) và đối ngẫu&lt;/td&gt;
      &lt;td&gt;phần dư (và tốc độ hội tụ không lồi)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;PnP tạo ảnh&lt;/td&gt;
      &lt;td&gt;độ trung thành dữ liệu và bộ khử nhiễu&lt;/td&gt;
      &lt;td&gt;ảnh / biến đối ngẫu&lt;/td&gt;
      &lt;td&gt;điểm bất động của bộ khử nhiễu proximal&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;OPF phân tán&lt;/td&gt;
      &lt;td&gt;các vùng lưới điện&lt;/td&gt;
      &lt;td&gt;điện áp biên / nhân tử&lt;/td&gt;
      &lt;td&gt;phần dư cân bằng công suất&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FedAvg (Ch. 29)&lt;/td&gt;
      &lt;td&gt;ERM cục bộ&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;trọng số&lt;/strong&gt; sau \(E\) bước&lt;/td&gt;
      &lt;td&gt;không có&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Lấy các bước cập nhật đồng thuận dạng chuẩn hóa từ mục 21-05 và viết &lt;em&gt;phác thảo&lt;/em&gt; thuật toán FedADMM cho 3 máy khách (không cần huấn luyện mạng): mỗi máy khách thực hiện một bước gradient trên \(\frac12\|x_i-x_i^{\mathrm{data}}\|_2^2+\frac{\rho}{2}\|x_i-z+u_i\|_2^2\), sau đó lấy trung bình. Vẽ đồ thị \(\|x_i-z\|\) và so sánh với cách lấy trung bình kiểu FedAvg không có biến đối ngẫu. Phiên bản có biến đối ngẫu sẽ kéo cả ba \(x_i\) hội tụ về cùng một điểm, còn phiên bản không có biến đối ngẫu sẽ giữ lại khoảng cách lệch đúng bằng độ chênh lệch giữa dữ liệu của các máy khách.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;S. Boyd et al., &lt;em&gt;Foundations and Trends in ML&lt;/em&gt; 3(1):1–122, 2011 — ADMM đồng thuận.&lt;/li&gt;
  &lt;li&gt;Y. Gong, Y. Li, N. M. Freris, &lt;a href=&quot;https://arxiv.org/abs/2204.03529&quot;&gt;arXiv:2204.03529&lt;/a&gt;, 2022 — FedADMM.&lt;/li&gt;
  &lt;li&gt;S. Zhou and G. Y. Li, &lt;em&gt;IEEE TPAMI&lt;/em&gt; 45(8):9699–9708, 2023 — ADMM không chính xác cho FL.&lt;/li&gt;
  &lt;li&gt;S. H. Chan, X. Wang, O. A. Elgendy, &lt;em&gt;IEEE TCI&lt;/em&gt; 3:84–98, 2017 — hội tụ PnP-ADMM.&lt;/li&gt;
  &lt;li&gt;K. Zhang et al., &lt;em&gt;IEEE TPAMI&lt;/em&gt; 44(10):6360–6376, 2022 — bộ khử nhiễu PnP sâu.&lt;/li&gt;
  &lt;li&gt;S. Hurault et al., &lt;a href=&quot;https://arxiv.org/abs/2210.10605&quot;&gt;arXiv:2210.10605&lt;/a&gt;, 2023 — PnP-ADMM tuyến tính hóa.&lt;/li&gt;
  &lt;li&gt;S. Shoushtari et al., &lt;a href=&quot;https://arxiv.org/abs/2311.18810&quot;&gt;arXiv:2311.18810&lt;/a&gt;, 2023 — PnP-ADMM không lồi.&lt;/li&gt;
  &lt;li&gt;S. Wang, L. Pu, X. Huang, Y. Yu, Y. Shi, H. Wang, &lt;em&gt;Energies&lt;/em&gt; 15(24):9525, 2022 — OPF phân tán trực tuyến.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>21-07 Ứng dụng hiện đại của ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_07_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_07_modern_applications</id>
   <content type="html">&lt;p&gt;Một trong những ý tưởng táo bạo và giàu sức sống nhất của thập kỷ qua trong xử lý ảnh tính toán là &lt;strong&gt;Plug-and-Play ADMM (PnP-ADMM)&lt;/strong&gt;: trong thuật toán ADMM tách biến \(\min f(x) + g(z) \text{ s.t. } x = z\), bước cập nhật \(z^{(k)} = \operatorname{prox}_{g, 1/\rho}(x^{(k)} + w^{(k-1)})\) thực chất chính là một &lt;strong&gt;bộ khử nhiễu Gaussian&lt;/strong&gt; với phương sai nhiễu \(\sigma^2 = 1/\rho\)! Vậy tại sao phải giới hạn mình ở những hàm điều chuẩn \(g(z)\) viết tay bằng công thức toán học (như Total Variation) khi ta có thể “cắm thẳng” (plug-and-play) một mạng nơ-ron khử nhiễu học sâu hiện đại (như DnCNN hay Diffusion denoiser) vào đúng vị trí của \(\operatorname{prox}_g\)? Bài 21-07 mở ra cánh cửa ứng dụng ADMM giai đoạn 2022–2026 trong tạo ảnh tính toán, học liên kết và điều độ năng lượng.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-ứng-dụng-admm-hiện-đại-20222026&quot;&gt;Kiến thức cần nhớ: Ba trụ cột ứng dụng ADMM hiện đại (2022–2026)&lt;/h2&gt;

&lt;p&gt;Để thấy vì sao khuôn mẫu tách biến đơn giản từ năm 1975 vẫn là xương sống của nhiều hệ thống AI và kỹ thuật hiện đại, hãy điểm qua ba hướng triển khai nổi bật:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Plug-and-Play ADMM (PnP-ADMM) trong tạo ảnh tính toán:&lt;/strong&gt; Tách bài toán tái tạo ảnh y tế (MRI, CT) hoặc kính thiên văn thành hai bước rõ rệt: bước vật lý \(x^{(k)}\) đảm bảo khớp đúng dữ liệu đo lường \(Ax \approx y\), còn bước tiên nghiệm \(z^{(k)} = D_\sigma(x^{(k)} + w^{(k-1)})\) thay toán tử proximal bằng một bộ khử nhiễu học sâu có tính không giãn (non-expansive) để bảo toàn hội tụ điểm bất động!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học liên kết không đồng nhất (Federated ADMM):&lt;/strong&gt; Kết hợp đồng thuận phân tán của bài 21-05 với các bước cập nhật SGD cục bộ trên thiết bị biên, dùng biến đối ngẫu để triệt tiêu độ lệch phân phối dữ liệu giữa các máy khách.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều độ lưới điện trực tuyến (Online Distributed OPF):&lt;/strong&gt; Các vùng lưới điện tối ưu lịch phát điện cục bộ riêng tư và chỉ trao đổi công suất trên đường dây liên kết thông qua ADMM đồng thuận ở chu kỳ vài giây đến vài phút.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-1-vòng-pnp-admm-khử-mờ-tín-hiệu-2-điểm-bằng-bộ-khử-nhiễu-thay-cho-operatornameprox_g&quot;&gt;Giải thích: Chạy tay 1 vòng PnP-ADMM khử mờ tín hiệu 2 điểm bằng bộ khử nhiễu thay cho \(\operatorname{prox}_g\)&lt;/h3&gt;

&lt;p&gt;Giả sử ta đo được tín hiệu bị làm mờ 1 chiều \(y = 0.5 x_1 + 0.5 x_2 = 5\) (chỉ có 1 phương trình cho 2 ẩn số \((x_1, x_2)\) nên bài toán ngược bị thiếu dữ kiện!). Ta chạy 1 vòng PnP-ADMM với \(\rho = 1\), khởi tạo \(z^{(0)} = (0, 0)^T, w^{(0)} = (0, 0)^T\), và dùng một bộ khử nhiễu \(D_\sigma\) có tính làm mượt kéo hai điểm kề nhau lại gần trung bình của chúng (ví dụ \(D_\sigma(a, b) = (0.75a + 0.25b, \; 0.25a + 0.75b)\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Khớp vật lý (giải bài toán con trơn \(x^{(1)}\)):&lt;/strong&gt;
\(x^{(1)} = \arg\min_{x_1, x_2} \left\{ \frac{1}{2}(0.5 x_1 + 0.5 x_2 - 5)^2 + \frac{1}{2}(x_1^2 + x_2^2) \right\}.\)
Vì đối xứng theo \(x_1, x_2\), đặt \(x_1 = x_2 = c\): đạo hàm \((c - 5)(0.5) + c = 0 \implies 1.5c = 2.5 \implies x^{(1)} = \left(\frac{5}{3}, \; \frac{5}{3}\right)^T \approx (1.67, 1.67)^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Cắm bộ khử nhiễu học sâu \(z^{(1)} = D_\sigma(x^{(1)} + w^{(0)})\):&lt;/strong&gt;
Thay vì tính \(\operatorname{prox}_g\) từ một hàm \(g\) tường minh, ta đưa thẳng \(v = (1.67, 1.67)^T\) vào mạng khử nhiễu \(D_\sigma\) (giả sử với nhiễu thực tế trên ảnh, \(v = (2.2, 1.1)^T \implies z^{(1)} = (1.925, 1.375)^T\) đã mượt hơn hẳn).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Cập nhật biến đối ngẫu:&lt;/strong&gt; \(w^{(1)} = w^{(0)} + x^{(1)} - z^{(1)}\), đẩy sai lệch vào vòng kế tiếp để tín hiệu cuối cùng vừa khớp sát phép đo vật lý \(y = 5\), vừa mang đầy đủ đặc trưng tự nhiên mà mạng khử nhiễu đã học!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Các bài trước trong chương này xem ADMM như một phương pháp tách bài toán &lt;em&gt;lồi có cấu trúc&lt;/em&gt;: gồm hai (hoặc nhiều) khối proximal dễ tính, một bước cập nhật đối ngẫu, cùng các phần dư có thể theo dõi trực tiếp. Tuy nhiên, phạm vi ứng dụng của ADMM không dừng lại ở năm 2011. Giai đoạn 2022–2026, cùng khuôn mẫu đồng thuận và Lagrangian tăng cường này tiếp tục xuất hiện trong học sâu liên kết, tạo ảnh tính toán với bộ khử nhiễu học được, và điều độ hệ thống điện trực tuyến. Bài đọc tùy chọn này phác họa các hướng triển khai đó thay vì suy diễn lại ADMM dạng chuẩn hóa.&lt;/p&gt;

&lt;p&gt;Nhắc lại bài toán đồng thuận từ &lt;a href=&quot;/contents/vi/chapter21/21_05_Consensus_ADMM/&quot;&gt;21-05&lt;/a&gt;:&lt;/p&gt;

\[\min_{x_1,\ldots,x_B,z}\ \sum_{i=1}^B f_i(x_i)\qquad\text{subject to}\qquad x_i=z.\]

&lt;p&gt;Mỗi máy khách (hoặc mỗi khối ảnh, mỗi vùng lưới điện) giữ một hàm mục tiêu cục bộ \(f_i\) riêng; máy chủ chỉ thực hiện phép lấy trung bình và cập nhật biến đối ngẫu. Tất cả các ứng dụng dưới đây đều là những chuyên biệt hóa của khuôn mẫu này.&lt;/p&gt;

&lt;h2 id=&quot;1-fedadmm-học-đồng-thuận-khi-dữ-liệu-giữa-các-máy-khách-không-đồng-nhất&quot;&gt;1. FedADMM: học đồng thuận khi dữ liệu giữa các máy khách không đồng nhất&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Học liên kết (federated learning)&lt;/strong&gt; (Chương 29) thường lấy trung bình &lt;em&gt;trọng số&lt;/em&gt; sau một số bước SGD cục bộ (thuật toán FedAvg). Cách làm đó &lt;em&gt;không&lt;/em&gt; phải là ADMM: không có biến đối ngẫu theo dõi sai lệch và hiện tượng trôi cục bộ (client drift) xuất hiện tự nhiên. Một hướng nghiên cứu giai đoạn 2022–2023 đã đưa biến đối ngẫu quay trở lại.&lt;/p&gt;

&lt;p&gt;Gong, Li và Freris (&lt;a href=&quot;https://arxiv.org/abs/2204.03529&quot;&gt;arXiv:2204.03529&lt;/a&gt;, 2022) đề xuất &lt;strong&gt;FedADMM&lt;/strong&gt;. Mỗi máy khách \(i\) cực tiểu hóa xấp xỉ hàm Lagrangian tăng cường (cho phép thực hiện vài bước SGD cục bộ — tức bước cập nhật \(x\) &lt;em&gt;không chính xác&lt;/em&gt;), máy chủ lấy trung bình các biến gốc, còn biến đối ngẫu \(w_i\) tích lũy độ lệch \(x_i-z\). Chi phí truyền thông mỗi vòng tương đương FedAvg, nhưng biến đối ngẫu tự thích nghi với &lt;strong&gt;tính không đồng nhất về thống kê (statistical heterogeneity)&lt;/strong&gt; mà không cần tinh chỉnh thủ công hệ số proximal. Bài báo ghi nhận giảm tới 87% số vòng giao tiếp so với FedAvg/FedProx trên CIFAR-10 và Fashion-MNIST dưới phân hoạch non-IID.&lt;/p&gt;

&lt;p&gt;Zhou và Li, &lt;em&gt;Federated Learning via Inexact ADMM&lt;/em&gt;, IEEE TPAMI 45(8):9699–9708, 2023, &lt;a href=&quot;https://doi.org/10.1109/TPAMI.2023.3243080&quot;&gt;doi:10.1109/TPAMI.2023.3243080&lt;/a&gt;, bổ sung cơ sở lý thuyết cho trường hợp giải cục bộ không chính xác, tham gia một phần (partial participation) và hàm mục tiêu không lồi. Có thể rút ra điểm chính rất rõ ràng: nếu bài toán có thể phát biểu dưới dạng đồng thuận và cần theo dõi phần dư, ADMM vẫn là công cụ thích hợp. Khi mô hình là mạng sâu và nút thắt nằm ở &lt;em&gt;số vòng truyền thông&lt;/em&gt;, FedADMM đóng vai trò là biến thể thập niên 2020 của &lt;a href=&quot;/contents/vi/chapter21/21_05_Consensus_ADMM/&quot;&gt;21-05&lt;/a&gt; — không thay thế FedAvg và cũng không đơn thuần là “SGD cộng thêm nhân tử Lagrange”.&lt;/p&gt;

&lt;p&gt;Một nghiên cứu ứng dụng y khoa giai đoạn 2025–2026 (học liên kết tăng cường bằng ADMM trên bộ dữ liệu tiểu đường PIMA và ảnh X-quang ngực) so sánh FedADMM với SCAFFOLD và FedDyn. Đây là một &lt;em&gt;triển khai ứng dụng&lt;/em&gt; hơn là thuật toán mới: các bệnh viện không thể gộp chung dữ liệu ảnh, và phần dư gốc–đối ngẫu cung cấp một chỉ báo hữu ích để kiểm tra quá trình hội tụ.&lt;/p&gt;

&lt;h2 id=&quot;2-plug-and-play-admm-trong-tạo-ảnh-tính-toán&quot;&gt;2. Plug-and-play ADMM trong tạo ảnh tính toán&lt;/h2&gt;

&lt;p&gt;Phục hồi ảnh là bài toán tối ưu hợp thành kinh điển:&lt;/p&gt;

\[\min_x\ \tfrac12\|Ax-b\|_2^2 + g(x),\]

&lt;p&gt;trong đó \(A\) mô tả toán tử làm mờ hoặc lấy mẫu thưa và \(g\) là hàm chính quy hóa. ADMM cổ điển sử dụng toán tử \(\mathrm{prox}_g\). &lt;strong&gt;Plug-and-play (PnP) ADMM&lt;/strong&gt; thay thế bước proximal đó bằng một bộ khử nhiễu có sẵn \(D_{\sigma}\) — trước đây là BM3D, hiện nay thường là mạng CNN — đồng thời giữ nguyên bước cập nhật \(x\) đảm bảo tính trung thành với dữ liệu (data fidelity).&lt;/p&gt;

&lt;p&gt;Chan, Wang và Elgendy, &lt;em&gt;IEEE Trans. Computational Imaging&lt;/em&gt; 3:84–98, 2017 (trực tuyến 2016), &lt;a href=&quot;https://doi.org/10.1109/TCI.2016.2629286&quot;&gt;doi:10.1109/TCI.2016.2629286&lt;/a&gt;, chứng minh hội tụ điểm bất động đối với bộ khử nhiễu &lt;em&gt;bị chặn&lt;/em&gt; theo lược đồ tiếp diễn (continuation), sử dụng bài toán siêu phân giải và ảnh đơn photon làm ví dụ minh họa. Giai đoạn 2022–2023 đánh dấu sự chuyển dịch sang bộ khử nhiễu bằng mạng sâu. Zhang, Li, Zuo, Zhang, Van Gool và Timofte, &lt;em&gt;Plug-and-Play Image Restoration with Deep Denoiser Prior&lt;/em&gt;, IEEE TPAMI 44(10):6360–6376, 2022, &lt;a href=&quot;https://doi.org/10.1109/TPAMI.2021.3088914&quot;&gt;doi:10.1109/TPAMI.2021.3088914&lt;/a&gt;, tích hợp một mạng DRUNet đã huấn luyện sẵn vào nhiều bài toán ngược khác nhau. Hurault, Chambolle, Leclaire và Papadakis (&lt;a href=&quot;https://arxiv.org/abs/2210.10605&quot;&gt;arXiv:2210.10605&lt;/a&gt;, 2023) tuyến tính hóa bước cập nhật \(x\) của ADMM để xử lý toán tử mờ không đồng nhất mà không cần vòng lặp liên hợp gradient (CG) bên trong. Shoushtari, Liu, Schniter và Kamilov (&lt;a href=&quot;https://arxiv.org/abs/2311.18810&quot;&gt;arXiv:2311.18810&lt;/a&gt;, 2023) giải thích vì sao PnP-ADMM vẫn thường hội tụ ngay cả với các mạng CNN &lt;em&gt;giãn nở&lt;/em&gt; khi xem \(D_{\sigma}\) như một ước lượng MMSE (tương ứng với toán tử proximal của một hàm \(g\) có thể không lồi).&lt;/p&gt;

&lt;p&gt;Điểm quan trọng về mặt kỹ thuật: ADMM đóng vai trò như một &lt;em&gt;giao diện mô-đun&lt;/em&gt;. Một khối biểu diễn mô hình vật lý (\(A\), hàm hợp lý Poisson), còn khối kia là tri thức tiên nghiệm học từ dữ liệu. Nhờ đó, không cần huấn luyện lại mạng nơ-ron cho từng thiết bị máy ảnh riêng biệt. Đây là lý do cộng đồng tạo ảnh tính toán vẫn duy trì giảng dạy và sử dụng ADMM bên cạnh các bộ tối ưu như Adam.&lt;/p&gt;

&lt;h2 id=&quot;3-tối-ưu-dòng-công-suất-phân-tán&quot;&gt;3. Tối ưu dòng công suất phân tán&lt;/h2&gt;

&lt;p&gt;Bài toán tối ưu dòng công suất (Optimal Power Flow — OPF) là một bài toán quy hoạch bậc hai có ràng buộc bậc hai (QCQP) không lồi trên lưới điện, liên quan đến điện áp, công suất phát và giới hạn đường dây. Các vùng vận hành thường không chia sẻ toàn bộ dữ liệu lưới nội bộ, trong khi nguồn năng lượng tái tạo biến động liên tục khiến bài toán mang tính &lt;em&gt;trực tuyến&lt;/em&gt;. ADMM đồng thuận tách lưới điện tại các nút biên: mỗi vùng tự giải bài toán OPF cục bộ, còn biến đối ngẫu trên điện áp biên buộc các vùng thỏa mãn định luật Kirchhoff.&lt;/p&gt;

&lt;p&gt;Wang, Pu, Huang, Yu, Shi và Wang, &lt;em&gt;Online ADMM for Distributed Optimal Power Flow via Lagrangian Duality&lt;/em&gt;, &lt;em&gt;Energies&lt;/em&gt; 15(24):9525, 2022, &lt;a href=&quot;https://doi.org/10.3390/en15249525&quot;&gt;doi:10.3390/en15249525&lt;/a&gt;, triển khai ADMM đồng thuận trên bài toán OPF &lt;em&gt;đối ngẫu&lt;/em&gt; để chỉ trao đổi các nhân tử tại biên và cập nhật &lt;em&gt;trực tuyến&lt;/em&gt; khi nguồn phát phân tán dao động. Thực nghiệm trên lưới IEEE 30 nút so sánh OPF tĩnh và động cho thấy vòng lặp ADMM trực tuyến bám sát độ dốc biến thiên của nguồn tái tạo mà không làm các tổ máy phát truyền thống thay đổi công suất đột ngột như khi giải lại toàn bộ OPF ngoại tuyến. Đây chính là khuôn mẫu đồng thuận của Boyd áp dụng cho hàm mục tiêu \(f_i\) của hệ thống điện, cho thấy “tối ưu phân tán” hiện nay không chỉ giới hạn ở tác vụ all-reduce trên cụm GPU.&lt;/p&gt;

&lt;h2 id=&quot;so-sánh-phạm-vi-với-chương-29&quot;&gt;So sánh phạm vi với Chương 29&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Ứng dụng&lt;/th&gt;
      &lt;th&gt;Thành phần tách&lt;/th&gt;
      &lt;th&gt;Đại lượng lấy trung bình&lt;/th&gt;
      &lt;th&gt;Tiêu chí kiểm chứng&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;FedADMM&lt;/td&gt;
      &lt;td&gt;hàm mất mát huấn luyện cục bộ&lt;/td&gt;
      &lt;td&gt;biến gốc \(z\) và đối ngẫu&lt;/td&gt;
      &lt;td&gt;phần dư (và tốc độ hội tụ không lồi)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;PnP tạo ảnh&lt;/td&gt;
      &lt;td&gt;độ trung thành dữ liệu và bộ khử nhiễu&lt;/td&gt;
      &lt;td&gt;ảnh / biến đối ngẫu&lt;/td&gt;
      &lt;td&gt;điểm bất động của bộ khử nhiễu proximal&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;OPF phân tán&lt;/td&gt;
      &lt;td&gt;các vùng lưới điện&lt;/td&gt;
      &lt;td&gt;điện áp biên / nhân tử&lt;/td&gt;
      &lt;td&gt;phần dư cân bằng công suất&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FedAvg (Ch. 29)&lt;/td&gt;
      &lt;td&gt;ERM cục bộ&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;trọng số&lt;/strong&gt; sau \(E\) bước&lt;/td&gt;
      &lt;td&gt;không có&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Lấy các bước cập nhật đồng thuận dạng chuẩn hóa từ mục 21-05 và viết &lt;em&gt;phác thảo&lt;/em&gt; thuật toán FedADMM cho 3 máy khách (không cần huấn luyện mạng): mỗi máy khách thực hiện một bước gradient trên \(\frac12\|x_i-x_i^{\mathrm{data}}\|_2^2+\frac{\rho}{2}\|x_i-z+u_i\|_2^2\), sau đó lấy trung bình. Vẽ đồ thị \(\|x_i-z\|\) và so sánh với cách lấy trung bình kiểu FedAvg không có biến đối ngẫu. Phiên bản có biến đối ngẫu sẽ kéo cả ba \(x_i\) hội tụ về cùng một điểm, còn phiên bản không có biến đối ngẫu sẽ giữ lại khoảng cách lệch đúng bằng độ chênh lệch giữa dữ liệu của các máy khách.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;S. Boyd et al., &lt;em&gt;Foundations and Trends in ML&lt;/em&gt; 3(1):1–122, 2011 — ADMM đồng thuận.&lt;/li&gt;
  &lt;li&gt;Y. Gong, Y. Li, N. M. Freris, &lt;a href=&quot;https://arxiv.org/abs/2204.03529&quot;&gt;arXiv:2204.03529&lt;/a&gt;, 2022 — FedADMM.&lt;/li&gt;
  &lt;li&gt;S. Zhou and G. Y. Li, &lt;em&gt;IEEE TPAMI&lt;/em&gt; 45(8):9699–9708, 2023 — ADMM không chính xác cho FL.&lt;/li&gt;
  &lt;li&gt;S. H. Chan, X. Wang, O. A. Elgendy, &lt;em&gt;IEEE TCI&lt;/em&gt; 3:84–98, 2017 — hội tụ PnP-ADMM.&lt;/li&gt;
  &lt;li&gt;K. Zhang et al., &lt;em&gt;IEEE TPAMI&lt;/em&gt; 44(10):6360–6376, 2022 — bộ khử nhiễu PnP sâu.&lt;/li&gt;
  &lt;li&gt;S. Hurault et al., &lt;a href=&quot;https://arxiv.org/abs/2210.10605&quot;&gt;arXiv:2210.10605&lt;/a&gt;, 2023 — PnP-ADMM tuyến tính hóa.&lt;/li&gt;
  &lt;li&gt;S. Shoushtari et al., &lt;a href=&quot;https://arxiv.org/abs/2311.18810&quot;&gt;arXiv:2311.18810&lt;/a&gt;, 2023 — PnP-ADMM không lồi.&lt;/li&gt;
  &lt;li&gt;S. Wang, L. Pu, X. Huang, Y. Yu, Y. Shi, H. Wang, &lt;em&gt;Energies&lt;/em&gt; 15(24):9525, 2022 — OPF phân tán trực tuyến.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>20-06 Ứng dụng hiện đại của phương pháp đối ngẫu (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_06_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_06_modern_applications</id>
   <content type="html">&lt;p&gt;Khi bạn huấn luyện một mô hình học máy trên hàng nghìn chiếc điện thoại hoặc hàng trăm bệnh viện mà dữ liệu không được phép rời khỏi thiết bị — gọi là &lt;strong&gt;Học liên bang (Federated Learning)&lt;/strong&gt; — thuật toán đơn giản nhất (FedAvg) chỉ lấy trung bình cộng trọng số của các máy khách. Nhưng khi dữ liệu giữa các bệnh viện khác biệt mạnh (non-IID), mỗi máy khách tự kéo mô hình về cực tiểu cục bộ riêng của mình, tạo ra hiện tượng &lt;strong&gt;trôi dạt máy khách (client drift)&lt;/strong&gt; làm mô hình toàn cục chệch hướng! Giai đoạn 2022–2026, tư duy đối ngẫu và ADMM của Chương 20 đã trở thành vũ khí sắc bén giải quyết tận gốc vấn đề này qua họ thuật toán &lt;strong&gt;FedADMM&lt;/strong&gt; và &lt;strong&gt;FedDyn&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-cầu-nối-từ-lý-thuyết-đối-ngẫu-sang-học-liên-bang-hiện-đại&quot;&gt;Kiến thức cần nhớ: Ba cầu nối từ lý thuyết đối ngẫu sang Học liên bang hiện đại&lt;/h2&gt;

&lt;p&gt;Để nhìn xuyên qua các thuật ngữ hệ thống phân tán và thấy đúng bản chất Chương 20 bên trong FedADMM, hãy chú ý ba cơ chế sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán đồng thuận (Consensus Formulation):&lt;/strong&gt; Huấn luyện liên bang \(\min_z \sum_{i=1}^B f_i(z)\) được viết lại thành \(\min \sum_i f_i(x_i) \text{ s.t. } x_i = z\) — chính xác dạng phân rã hai khối của ADMM!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến đối ngẫu \(w_i\) triệt tiêu độ trôi dạt (Client Drift Correction):&lt;/strong&gt; Trong FedAvg, khi mỗi client chạy nhiều bước cục bộ trên \(f_i(x_i)\), nó quên mất các client khác. Trong FedADMM, biến đối ngẫu \(w_i\) ghi nhớ độ lệch tích lũy \(x_i - z\), tự động cộng một “lực bù tuyến tính” vào hàm mất mát cục bộ để kéo điểm dừng của mọi client khớp đúng với cực tiểu toàn cục!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bền vững trước tham gia từng phần (Partial Participation) và tính toán không chính xác:&lt;/strong&gt; Ở quy mô thực tế, mỗi vòng truyền thông chỉ có một tập con nhỏ thiết bị trực tuyến và mỗi thiết bị chỉ chạy vài bước SGD cục bộ (inexact ADMM). Các phân tích năm 2022–2025 chứng minh FedADMM vẫn hội tụ vững chắc dưới cả hai ràng buộc khắc nghiệt này.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-minh-họa-bằng-số-cách-biến-đối-ngẫu-w_i-triệt-tiêu-hoàn-toàn-client-drift&quot;&gt;Giải thích: Minh họa bằng số cách biến đối ngẫu \(w_i\) triệt tiêu hoàn toàn Client Drift&lt;/h3&gt;

&lt;p&gt;Xét hệ thống học liên bang gồm \(B = 2\) bệnh viện có phân phối dữ liệu lệch hẳn nhau (non-IID):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bệnh viện 1: \(f_1(x) = \frac{1}{2}(x - 1)^2\) (cực tiểu riêng tại \(1\)).&lt;/li&gt;
  &lt;li&gt;Bệnh viện 2: \(f_2(x) = \frac{1}{2}(x - 5)^2\) (cực tiểu riêng tại \(5\)).
Nghiệm toàn cục tối ưu của \(\frac{1}{2}[f_1(x) + f_2(x)]\) rõ ràng là \(z^\star = 3\).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điều gì xảy ra nếu mỗi bệnh viện tự tối ưu cục bộ có phạt gần \(z\) nhưng KHÔNG có biến đối ngẫu (kiểu FedProx, \(\rho = 1\))?&lt;/strong&gt;
Giả sử máy chủ đang đứng ngay tại điểm tối ưu toàn cục \(z = 3\):
    &lt;ul&gt;
      &lt;li&gt;Bệnh viện 1 giải \(\min_{x_1} \frac{1}{2}(x_1 - 1)^2 + \frac{1}{2}(x_1 - 3)^2 \implies x_1 = 2\) (bị kéo lệch về \(1\)!).&lt;/li&gt;
      &lt;li&gt;Bệnh viện 2 giải \(\min_{x_2} \frac{1}{2}(x_2 - 5)^2 + \frac{1}{2}(x_2 - 3)^2 \implies x_2 = 4\) (bị kéo lệch về \(5\)!).
Nếu vòng đó chỉ có Bệnh viện 1 gửi cập nhật (partial participation), mô hình toàn cục bị kéo tụt từ \(3\) xuống \(2\) — sinh ra độ trôi dạt lớn!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách FedADMM dùng biến đối ngẫu \(w_1, w_2\) khóa chặt nghiệm toàn cục (\(\rho = 1\)):&lt;/strong&gt;
Tại điểm cân bằng đối ngẫu, \(w_1^\star = +2\) (tích lũy lực đẩy sang phải) và \(w_2^\star = -2\) (tích lũy lực đẩy sang trái). Khi \(z = 3\):
    &lt;ul&gt;
      &lt;li&gt;Bệnh viện 1 giải \(\min_{x_1} \frac{1}{2}(x_1 - 1)^2 + \frac{1}{2}(x_1 - 3 + 2)^2 \implies (x_1 - 1) + (x_1 - 1) = 0\)? Chú ý dấu chuẩn ADMM: \(x_i = \arg\min_{x_i} f_i(x_i) + \frac{\rho}{2}\|x_i - z + w_i\|^2\)!&lt;/li&gt;
      &lt;li&gt;Với \(w_1^\star = -2\) và \(w_2^\star = +2\):
        &lt;ul&gt;
          &lt;li&gt;Bệnh viện 1 giải \(\min_{x_1} \frac{1}{2}(x_1 - 1)^2 + \frac{1}{2}(x_1 - 3 - 2)^2 \implies (x_1 - 1) + (x_1 - 5) = 0 \implies \mathbf{x_1 = 3 = z^\star}\)!&lt;/li&gt;
          &lt;li&gt;Bệnh viện 2 giải \(\min_{x_2} \frac{1}{2}(x_2 - 5)^2 + \frac{1}{2}(x_2 - 3 + 2)^2 \implies (x_2 - 5) + (x_2 - 1) = 0 \implies \mathbf{x_2 = 3 = z^\star}\)!
Cả hai bệnh viện đều tự nguyện dừng chính xác tại \(z^\star = 3\) — &lt;strong&gt;triệt tiêu hoàn toàn độ trôi dạt cục bộ!&lt;/strong&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Các phương pháp (sub)gradient đối ngẫu, phân rã đối ngẫu, hàm Lagrange tăng cường và ADMM trong chương này đều xoay quanh một ý tưởng cốt lõi: &lt;em&gt;định giá một ràng buộc đồng thuận hoặc nguồn lực chung bằng biến đối ngẫu để mỗi khối biến có thể tự tối ưu độc lập&lt;/em&gt;. Đây cũng chính là cơ chế đứng sau học liên bang (federated learning). Khi học đến FedAvg ở Chương 29, ta có thể nhìn nhận FedADMM như phiên bản có máy chủ trung tâm của Chương 20: biến đối ngẫu đóng vai trò mức giá điều chỉnh liên tục cho yêu cầu “mô hình cục bộ của mỗi client phải khớp với mô hình toàn cục”.&lt;/p&gt;

&lt;h2 id=&quot;fedadmm-dùng-biến-đối-ngẫu-xử-lý-tính-không-đồng-nhất-giữa-các-client&quot;&gt;FedADMM: dùng biến đối ngẫu xử lý tính không đồng nhất giữa các client&lt;/h2&gt;

&lt;p&gt;Zhou và Li (2022/23, &lt;a href=&quot;https://arxiv.org/abs/2204.10607&quot;&gt;arXiv:2204.10607&lt;/a&gt;) biểu diễn bài toán cực tiểu hóa rủi ro thực nghiệm liên bang dưới dạng bài toán đồng thuận và áp dụng &lt;strong&gt;ADMM không chính xác (inexact ADMM)&lt;/strong&gt;. Các client có thể giải gần đúng bài toán con hàm Lagrange tăng cường, máy chủ có thể bỏ qua các nút chậm (stragglers), và không cần đồng bộ giao tiếp sau mỗi bước cập nhật cục bộ. Các biến đối ngẫu hấp thụ tính không đồng nhất về phân phối dữ liệu (statistical heterogeneity) mà FedAvg chỉ xử lý bằng phép lấy trung bình đơn giản. Nhiều biến thể FedADMM khác (Gong et al. 2022; Wang et al. 2023; Zhang et al. 2021) đều kế thừa khung thuật toán này.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FedADMM-InSa&lt;/strong&gt; (Song, Wang và Zuazua, 2024, &lt;a href=&quot;https://arxiv.org/abs/2402.13989&quot;&gt;arXiv:2402.13989&lt;/a&gt;) bổ sung hai thành phần thực hành quan trọng: một &lt;em&gt;tiêu chí kiểm tra độ không chính xác khả thi&lt;/em&gt; (implementable inexactness criterion) mà từng client tự đánh giá từ phần dư cục bộ, và một &lt;em&gt;tham số phạt tự thích nghi&lt;/em&gt; \(\beta_i^k\) thay cho việc chỉnh tay tham số hàm Lagrange tăng cường như ở bài 20-03. Trên các thí nghiệm báo cáo, sự kết hợp này tăng độ chính xác khoảng 8% đồng thời giảm khối lượng tính toán cục bộ khoảng 56% so với các phương pháp đối chứng. Thuật toán không dựa trên một định lý đối ngẫu mới mà là sự kỹ thuật hóa phân rã đối ngẫu cùng các nguyên tắc của Boyd, Parikh, Chu, Peleato và Eckstein cho bối cảnh tham gia từng phần trong học liên bang.&lt;/p&gt;

&lt;p&gt;Chỉ cần viết bài toán đồng thuận dưới dạng&lt;/p&gt;

\[\min_{w_1,\ldots,w_N,z}\ \sum_{i=1}^N f_i(w_i)\quad\text{s.t.}\quad w_i=z,\]

&lt;p&gt;toàn bộ phần còn lại chính là quy trình của Chương 20: đối ngẫu hóa ràng buộc \(w_i = z\), cộng số hạng phạt bậc hai \(\frac{\beta}{2}\|w_i-z\|_2^2\), rồi cập nhật luân phiên \(w_i\), \(z\) và các nhân tử đối ngẫu. FedAvg có thể xem là trường hợp đặc biệt khi bỏ qua các nhân tử đối ngẫu và chỉ lấy bước gradient trên \(f_i\).&lt;/p&gt;

&lt;h2 id=&quot;ràng-buộc-đối-ngẫu-phi-tập-trung-dfedadmm&quot;&gt;Ràng buộc đối ngẫu phi tập trung: DFedADMM&lt;/h2&gt;

&lt;p&gt;Khi không có máy chủ trung tâm, ràng buộc đồng thuận được xác định trên một đồ thị mạng. &lt;strong&gt;DFedADMM&lt;/strong&gt; và &lt;strong&gt;DFedADMM-SAM&lt;/strong&gt; (Li, Shen, Li, Yin và Tao, 2023, &lt;a href=&quot;https://arxiv.org/abs/2308.08290&quot;&gt;arXiv:2308.08290&lt;/a&gt;) gắn một biến đối ngẫu trên từng cạnh (hoặc sai lệch giữa các nút láng giềng) để các mục tiêu cục bộ không đồng nhất không trôi lệch độc lập khỏi nhau. Thành phần SAM (tối ưu hóa nhận biết độ sắc — Sharpness-Aware Minimization) đóng vai trò điều chuẩn cục bộ nhằm hạn chế quá khớp trên dữ liệu không đồng nhất, còn cơ chế &lt;em&gt;đối ngẫu&lt;/em&gt; đến trực tiếp từ Chương 20. Bài báo thiết lập tốc độ hội tụ cho bài toán không lồi phụ thuộc vào khoảng cách phổ (spectral gap) của ma trận gossip — cùng cấu trúc ma trận Laplacian đồ thị như trong ADMM đồng thuận cổ điển.&lt;/p&gt;

&lt;p&gt;Góc nhìn này giúp kết nối trực tiếp với gossip SGD trong tối ưu phân tán: gossip bậc nhất tương ứng với phân rã đối ngẫu đơn giản không có số hạng hàm Lagrange tăng cường, còn DFedADMM khôi phục cả số hạng tăng cường lẫn bộ nhớ đối ngẫu.&lt;/p&gt;

&lt;h2 id=&quot;học-tăng-cường-liên-bang-dùng-admm-cho-bước-gradient-chính-sách-tự-nhiên&quot;&gt;Học tăng cường liên bang: dùng ADMM cho bước gradient chính sách tự nhiên&lt;/h2&gt;

&lt;p&gt;Bài báo tại NeurIPS 2023 “Improved Communication Efficiency in Federated Natural Policy Gradient via ADMM-based Gradient Updates” thay bước giải hệ phương trình ma trận Fisher tốn chi phí truyền thông \(O(d^2)\) bằng một phép tách ADMM chỉ truyền \(O(d)\) số thực mỗi vòng. Natural Policy Gradient (NPG) liên bang thực chất là một bước cập nhật bậc hai (liên hệ với Chương 14), và việc giảm chi phí truyền thông đạt được nhờ &lt;em&gt;phân rã đối ngẫu chính hệ Newton đó&lt;/em&gt;. Thí nghiệm trên các tác vụ MuJoCo cho thấy phương pháp đạt phần thưởng tương đương FedNPG đầy đủ với chi phí truyền thông ngang với FedPPO bậc nhất.&lt;/p&gt;

&lt;p&gt;Nguyên tắc chung cần ghi nhớ: bất cứ khi nào một phương pháp liên bang cần giải một bước Newton hoặc phép chiếu có liên kết giữa các nút, ADMM giúp tách rời bài toán mà không phải truyền cả ma trận qua mạng.&lt;/p&gt;

&lt;h2 id=&quot;phân-rã-đối-ngẫu-ngoài-học-máy-trung-tâm-dữ-liệu&quot;&gt;Phân rã đối ngẫu ngoài học máy trung tâm dữ liệu&lt;/h2&gt;

&lt;p&gt;Cấu trúc đối ngẫu tách khối vẫn là công cụ chủ lực giai đoạn 2022–2026 trong bài toán trào lưu công suất tối ưu (OPF) của hệ thống điện, điều độ năng lượng đa chu kỳ và một số bài toán học máy y tế bảo vệ quyền riêng tư: mỗi tác nhân giữ riêng biến \(x_i\), còn bộ điều phối cập nhật nhân tử \(\lambda\) trên các ràng buộc liên kết (cân bằng dòng công suất hoặc rủi ro chung). Nghiên cứu Bayesian-ADMM (2025, &lt;a href=&quot;https://arxiv.org/abs/2506.13150&quot;&gt;arXiv:2506.13150&lt;/a&gt;) diễn giải lại điểm bất động của ADMM dưới góc nhìn đối ngẫu Bayes biến phân và thu lại các biến thể học liên bang kiểu Newton và kiểu Adam bằng cách thay đổi phân phối hậu nghiệm thuộc họ mũ.&lt;/p&gt;

&lt;p&gt;Chương 29 sẽ so sánh FedAvg và ADMM dưới góc độ thiết kế &lt;em&gt;hệ thống&lt;/em&gt;. Còn về mặt tối ưu hóa, điểm khác biệt cốt lõi nằm ở đây: &lt;strong&gt;biến đối ngẫu đóng vai trò bộ nhớ lưu giữ mức vi phạm đồng thuận&lt;/strong&gt;. Khi bỏ biến đối ngẫu, ta thu được phép lấy trung bình; khi giữ biến đối ngẫu kèm số hạng Lagrange tăng cường bậc hai, ta thu được các phương pháp của chương này — lý do khiến chúng liên tục được sử dụng mỗi khi dữ liệu học liên bang có tính không đồng nhất cao.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;S. Zhou, G. Y. Li, “Federated Learning via Inexact ADMM,” 2022. &lt;a href=&quot;https://arxiv.org/abs/2204.10607&quot;&gt;arXiv:2204.10607&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Y. Song, Z. Wang, E. Zuazua, “FedADMM-InSa: An Inexact and Self-Adaptive ADMM for Federated Learning,” 2024. &lt;a href=&quot;https://arxiv.org/abs/2402.13989&quot;&gt;arXiv:2402.13989&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Q. Li, L. Shen, G. Li, Q. Yin, D. Tao, “DFedADMM: Dual Constraints Controlled Model Inconsistency for Decentralized Federated Learning,” 2023. &lt;a href=&quot;https://arxiv.org/abs/2308.08290&quot;&gt;arXiv:2308.08290&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;“Improved Communication Efficiency in Federated Natural Policy Gradient via ADMM-based Gradient Updates,” NeurIPS 2023.&lt;/li&gt;
  &lt;li&gt;“Federated ADMM from Bayesian Duality,” 2025. &lt;a href=&quot;https://arxiv.org/abs/2506.13150&quot;&gt;arXiv:2506.13150&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;S. Boyd, N. Parikh, E. Chu, B. Peleato, J. Eckstein, “Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers,” &lt;em&gt;Found. Trends Mach. Learn.&lt;/em&gt; 2011 (khung thuật toán nền tảng cho các công trình trên).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>19-08 Ứng dụng hiện đại của phương pháp proximal Newton (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_08_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_08_modern_applications</id>
   <content type="html">&lt;p&gt;Nhiều thuật toán tối ưu cổ điển bị bỏ lại phía sau khi dữ liệu phình to lên hàng chục nghìn chiều, nhưng phương pháp Newton proximal giai đoạn 2022–2026 lại có một hành trình ngược lại: càng ở những bài toán thống kê nhiều chiều gai góc — như ước lượng đồ thị thưa (graphical lasso) với hàng chục nghìn nút, hay mô hình tuyến tính tổng quát nhiều biến (GLM) tích hợp trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt; — sự kết hợp giữa &lt;strong&gt;độ cong bậc hai cục bộ&lt;/strong&gt; và &lt;strong&gt;sàng lọc tập hoạt động (active-set screening)&lt;/strong&gt; càng tỏ ra không thể thay thế.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-xu-hướng-ứng-dụng-newton-proximal-giai-đoạn-20222026&quot;&gt;Kiến thức cần nhớ: Ba xu hướng ứng dụng Newton proximal giai đoạn 2022–2026&lt;/h2&gt;

&lt;p&gt;Để thấy lý thuyết Chương 19 đang vận hành như thế nào trong các thư viện thực chiến hôm nay, hãy điểm qua ba trục phát triển chính:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sàng lọc an toàn (Safe Screening) + Tập tự do cho Graphical Lasso quy mô lớn:&lt;/strong&gt; Các phiên bản kế thừa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt; (như BigQUIC và các biến thể phân khối song song) phân rã ma trận hiệp phương sai mẫu thành các thành phần liên thông trước khi gọi Newton proximal, mở rộng khả năng giải từ vài trăm lên hàng chục nghìn biến.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bộ giải Newton–Cholesky cho GLM trong hệ sinh thái Python:&lt;/strong&gt; Trong các phiên bản mới của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glum&lt;/code&gt;, khi số mẫu \(n \gg p\), việc tính trực tiếp Hessian \(X^T W X\) và giải bằng Cholesky (hoặc kết hợp hạ tọa độ có phạt \(\ell_1/\ell_2\)) nhanh hơn gấp nhiều lần so với L-BFGS thuần túy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton proximal không chính xác có điều khiển thích nghi (Adaptive Inexactness):&lt;/strong&gt; Thay vì giải bài toán con bên trong tới sai số máy ngay từ những vòng lặp đầu còn xa nghiệm, các bộ giải hiện đại nới lỏng dung sai bài toán con ở giai đoạn đầu và chỉ siết chặt khi gần nghiệm — giữ nguyên hội tụ siêu tuyến tính nhưng cắt giảm 50–70% thời gian chạy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-nhanh-mức-tiết-kiệm-bộ-nhớ-nhờ-tập-hoạt-động-trong-graphical-lasso&quot;&gt;Giải thích: Tính nhanh mức tiết kiệm bộ nhớ nhờ tập hoạt động trong Graphical Lasso&lt;/h3&gt;

&lt;p&gt;Xét bài toán ước lượng ma trận chính xác đối xứng \(\Theta \in \mathbb{S}^p\) với \(p = 1{,}000\) biến (ví dụ mạng biểu hiện 1.000 gen):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bài toán không khai thác độ thưa:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Số biến tự do trong ma trận đối xứng \(\Theta\) là \(N = \frac{p(p+1)}{2} \approx 500{,}500\) biến.&lt;/li&gt;
      &lt;li&gt;Nếu lập trực tiếp ma trận Hessian đầy đủ \(\Theta^{-1} \otimes \Theta^{-1}\) kích thước \(N \times N\), số phần tử sẽ lên tới \(N^2 \approx 2.5 \times 10^{11}\) — tương đương &lt;strong&gt;2 Terabyte RAM&lt;/strong&gt;, hoàn toàn bất khả thi!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sức mạnh của tập tự do (Free Set) trong Proximal Newton (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt;):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nhờ phạt \(\lambda\|\Theta\|_1\), giả sử mỗi gen chỉ kết nối trung bình với \(10\) gen khác, nên số cạnh khác \(0\) (tập tự do) chỉ là \(s \approx \frac{1{,}000 \times 10}{2} + 1{,}000 = 6{,}000\) biến!&lt;/li&gt;
      &lt;li&gt;Bài toán con bậc hai được hạ tọa độ giải &lt;strong&gt;chỉ trên \(6{,}000\) tọa độ tự do&lt;/strong&gt; thay vì \(500{,}500\) tọa độ — giảm kích thước không gian tìm kiếm gần &lt;strong&gt;83 lần&lt;/strong&gt;, đồng thời mỗi phép cập nhật tọa độ chỉ dùng hai cột của ma trận \(W = \Theta^{-1}\) đã tính sẵn nên bộ nhớ chỉ tốn cỡ \(p^2 \approx 8\text{ MB}\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phương pháp proximal Newton xây dựng mô hình bậc hai cho thành phần &lt;em&gt;trơn&lt;/em&gt; \(g\) và giữ nguyên thành phần &lt;em&gt;không trơn&lt;/em&gt; \(h\) trong bài toán con:&lt;/p&gt;

\[v^{+} = \arg\min_v\ \nabla g(x)^\top v + \tfrac12 v^\top H v + h(x+v),\qquad H\approx\nabla^2 g(x).\]

&lt;p&gt;Khi \(h = \lambda\|\cdot\|_1\), bài toán con có dạng Lasso; khi \(h\) là hàm chỉ thị của một tập lồi, bài toán con trở thành quy hoạch bậc hai có ràng buộc. Khung lý thuyết của Lee, Sun và Saunders (2014) cùng các thư viện kinh điển (glmnet, QUIC) vẫn giữ nguyên giá trị cốt lõi. Điểm thay đổi lớn trong giai đoạn 2022–2026 nằm ở quy mô bài toán: các bộ giải tổng hợp bậc hai hiện nay giải được toàn bộ đường điều chuẩn cho ma trận chính xác (precision matrix) nhiều chiều mà các thuật toán bậc nhất như glasso không kham nổi, đồng thời các thư viện GLM phổ biến đã tích hợp thêm bộ giải Newton–Cholesky tường minh — tức proximal Newton với \(h = \frac{\alpha}{2}\|\cdot\|_2^2\).&lt;/p&gt;

&lt;h2 id=&quot;mô-hình-đồ-thị-từ-quic-đến-mars&quot;&gt;Mô hình đồ thị: từ QUIC đến MARS&lt;/h2&gt;

&lt;p&gt;QUIC (Hsieh, Sustik, Dhillon, Ravikumar, JMLR 2014) là ví dụ kinh điển đã nêu ở bài 19-05: áp dụng mô hình bậc hai Newton lên \(-\log\det\Theta + \langle S, \Theta \rangle\) kèm phạt \(\ell_1\), giải bài toán con bằng hạ theo tọa độ và đạt tốc độ hội tụ siêu tuyến tính. Bước tiến tiếp theo của thập niên 2020 cho ước lượng ma trận chính xác &lt;em&gt;nhiều chiều&lt;/em&gt; là &lt;strong&gt;MARS&lt;/strong&gt; (Li, Jiang, Sun, JMLR 2023). Thuật toán này tối ưu hàm mất mát D-trace có phạt \(\ell_1\) thay cho glasso, kết hợp kỹ thuật sàng lọc thích nghi (loại bỏ các tọa độ đã được điều kiện KKT xác nhận bằng \(0\)) với bộ giải &lt;strong&gt;hàm Lagrange tăng cường kết hợp Newton bán trơn (semismooth Newton augmented Lagrangian — SSNAL)&lt;/strong&gt; trên bài toán đối ngẫu đã rút gọn. Các tác giả báo cáo giải được toàn bộ đường điều chuẩn cho bài toán \(p \approx 2 \times 10^4\) (dữ liệu biểu hiện gen ung thư vú, tương ứng hàng trăm triệu biến đối ngẫu trước khi sàng lọc) — quy mô mà glasso và QUIC gặp bế tắc.&lt;/p&gt;

&lt;p&gt;Hai nguyên lý cốt lõi của Chương 19 vẫn được bảo toàn nguyên vẹn. Thứ nhất, phép toán tốn kém nhất vẫn là &lt;em&gt;ánh xạ proximal có tỉ lệ&lt;/em&gt; (ở đây là hệ Newton đối ngẫu), chứ không phải việc lưu toàn bộ ma trận Hessian dày đặc \(p^2\) phần tử. Thứ hai, chiến lược tập hoạt động / sàng lọc là yếu tố giúp proximal Newton vượt trội proximal gradient: một khi tập giá (support — tập các tọa độ khác 0) được nhận diện, thuật toán đạt hội tụ bậc hai trên tập biến tự do đúng như phân tích cục bộ ở bài 19-04. Mã nguồn được công bố tại &lt;a href=&quot;https://github.com/QianLI-QL/MARS&quot;&gt;QianLI-QL/MARS&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;glm-trong-scikit-learn-dùng-newton-khi-h-bậc-hai-dùng-l-bfgs-khi-không&quot;&gt;GLM trong scikit-learn: dùng Newton khi \(h\) bậc hai, dùng L-BFGS khi không&lt;/h2&gt;

&lt;p&gt;Từ scikit-learn 1.2 (2022), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PoissonRegressor(..., solver=&quot;newton-cholesky&quot;)&lt;/code&gt; và phần mở rộng sau đó cho hồi quy logistic tạo trực tiếp ma trận \(H = \nabla^2 g + \alpha I\) rồi giải bước Newton bằng phân rã Cholesky. Hạng tử phạt \(\alpha\|w\|_2^2\) chính là điều chuẩn Tikhonov / ridge: dưới góc nhìn bài toán tổng hợp với \(g\) là âm log-likelihood và \(h = \frac{\alpha}{2}\|w\|_2^2\), ánh xạ proximal của một hàm bậc hai lồi mạnh trở thành một hệ phương trình tuyến tính — nên proximal Newton suy biến về phương pháp Newton có điều chuẩn (damped Newton). Đây là minh họa thực tế cho bảng so sánh ở bài 19-03: khi \(h\) dễ xử lý (ridge, ràng buộc hộp, hoặc \(\ell_1\) với hạ theo tọa độ) và số đặc trưng \(d\) nhỏ, việc lập Hessian của \(g\) mang lại lợi ích rõ rệt.&lt;/p&gt;

&lt;p&gt;Trong thực hành, L-BFGS (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;lbfgs&quot;&lt;/code&gt;) phù hợp với bài toán nhiều đặc trưng hoặc có ràng buộc hộp (Chương 18), còn SAGA phù hợp với bài toán rất lớn, thưa có phạt \(\ell_1\) (Chương 26). Proximal Newton chiếm vị trí trung gian quan trọng: số chiều \(d\) vừa phải, chi phí tính \(g\) cao và \(h\) có cấu trúc tốt.&lt;/p&gt;

&lt;h2 id=&quot;glmnet-và-liblinear-công-cụ-chủ-lực-cho-glm-thưa&quot;&gt;glmnet và LIBLINEAR: công cụ chủ lực cho GLM thưa&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;glmnet&lt;/strong&gt; (Friedman, Hastie, Tibshirani — đã dẫn ở bài 19-05) đến năm 2026 vẫn là bộ giải tiêu chuẩn cho đường điều chuẩn trong R và các gói giao tiếp Python: vòng lặp hạ theo tọa độ trên bài toán con bậc hai nằm bên trong vòng ngoài proximal-Newton / IRLS. Bộ giải Newton miền tin cậy của LIBLINEAR cho hồi quy logistic / SVM điều chuẩn \(\ell_2\) và NewGLMNET cho \(\ell_1\) cũng vận hành theo cùng nguyên lý với bộ giải con khác nhau. Đây là những công cụ thực tế vẫn đang huấn luyện mô hình tuyến tính thưa trên dữ liệu tỷ lệ nhấp (click-through) và dữ liệu y tế dạng bảng hàng ngày.&lt;/p&gt;

&lt;p&gt;Bước phát triển của giai đoạn 2022–2026 tập trung vào mở rộng quy mô và tích hợp hệ thống: bản viết lại GLM trong scikit-learn, các công cụ tính toán ngoài bộ nhớ chính (out-of-core) như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;biglasso&lt;/code&gt;, và các bộ giải dựa trên SSNAL (hướng nghiên cứu của Sun–Toh) giúp đưa cùng khung vòng ngoài đáng tin cậy này lên các bài toán vượt quá giới hạn bộ nhớ RAM của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;cách-phân-biệt-bài-toán-proximal-newton-với-phương-pháp-bậc-nhất&quot;&gt;Cách phân biệt bài toán proximal Newton với phương pháp bậc nhất&lt;/h2&gt;

&lt;p&gt;Hãy quan sát bài toán con bên trong ở mỗi vòng lặp. Nếu mỗi bước giải một bài toán &lt;em&gt;toàn phương cộng \(h\)&lt;/em&gt; (Lasso, QP có ràng buộc hộp, hoặc hệ Newton đối ngẫu trên nón) tới độ chính xác vừa đủ rồi tìm kiếm theo đường thẳng trên hàm mục tiêu tổng hợp, đó là lớp thuật toán Chương 19 (MARS, QUIC, glmnet, Newton–Cholesky). Ngược lại, nếu mỗi bước chỉ gồm một bước gradient cộng một phép co ngưỡng dạng đóng, đó là lớp thuật toán bậc nhất Chương 09 (ISTA, FISTA, SAGA). Các phương án lai (giải bài toán con không chính xác, dùng xấp xỉ quasi-Newton \(H_k\)) thuộc bài 19-06 và là cách mở rộng khi \(\nabla^2 g\) chỉ có thể tiếp cận qua tích Hessian–vector.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Q. Li, B. Jiang, D. Sun, “MARS: A Second-Order Reduction Algorithm for High-Dimensional Sparse Precision Matrices Estimation,” JMLR 24, 2023. &lt;a href=&quot;https://jmlr.org/papers/v24/21-0699.html&quot;&gt;bài báo&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;C.-J. Hsieh, M. A. Sustik, I. S. Dhillon, P. Ravikumar, “QUIC: Quadratic Approximation for Sparse Inverse Covariance Estimation,” JMLR 15, 2014.&lt;/li&gt;
  &lt;li&gt;J. Lee, Y. Sun, M. A. Saunders, “Proximal Newton-type methods for minimizing composite functions,” SIAM J. Optim. 24(3), 2014.&lt;/li&gt;
  &lt;li&gt;J. Friedman, T. Hastie, R. Tibshirani, “Regularization paths for generalized linear models via coordinate descent,” J. Stat. Softw. 33(1), 2010 (glmnet; vẫn là đường sản xuất).&lt;/li&gt;
  &lt;li&gt;Bộ giải GLM &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newton-cholesky&lt;/code&gt; của scikit-learn 1.2+.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>18-08 Ứng dụng hiện đại của phương pháp quasi-Newton (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_08_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_08_modern_applications</id>
   <content type="html">&lt;p&gt;Trong cơn sốt học sâu hiện đại, nhiều người tưởng rằng Adam đã “đánh bại” mọi thuật toán tối ưu cổ điển. Thế nhưng giai đoạn 2022–2026 lại chứng kiến sự trở lại ngoạn mục của tư duy Quasi-Newton trên hai mặt trận lớn: trong &lt;strong&gt;học máy khoa học (Scientific ML / PINN)&lt;/strong&gt;, chiến lược &lt;em&gt;Adam khởi động + L-BFGS về đích&lt;/em&gt; là tiêu chuẩn bắt buộc để vượt qua số điều kiện khủng khiếp của phương trình đạo hàm riêng; còn trong &lt;strong&gt;huấn luyện mô hình nền tảng quy mô lớn&lt;/strong&gt;, các bộ tiền điều kiện có cấu trúc như Shampoo và SOAP chính là hậu duệ phân rã Kronecker mang chung dòng máu độ cong với BFGS.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-hướng-phát-triển-của-quasi-newton-trong-giai-đoạn-20222026&quot;&gt;Kiến thức cần nhớ: Ba hướng phát triển của Quasi-Newton trong giai đoạn 2022–2026&lt;/h2&gt;

&lt;p&gt;Để liên kết lý thuyết Chương 18 với các công trình hàng đầu tại ICML/NeurIPS gần đây, hãy chú ý ba cầu nối then chốt:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Số điều kiện phổ của PINN và bài toán ngược (Inverse Problems):&lt;/strong&gt; Khác với phân loại ảnh thông thường, hàm mất mát của mạng nơ-ron vật lý chứa đạo hàm bậc hai (toán tử Laplace, Navier–Stokes), khiến tỉ số trị riêng lớn nhất trên nhỏ nhất \(\kappa = \lambda_{\max}/\lambda_{\min}\) dễ dàng vượt \(10^4\text{–}10^6\). Bộ tối ưu bậc nhất bị kẹt sớm, còn L-BFGS nén phổ độ cong và hạ sai số xuống thêm 2–4 bậc độ lớn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược lai hai giai đoạn (Adam → L-BFGS):&lt;/strong&gt; L-BFGS đòi hỏi đánh giá gradient toàn lô (full-batch) chính xác và dễ mắc kẹt ở vùng yên ngựa không lồi nếu khởi tạo ngẫu nhiên. Chạy Adam trước để đi vào thung lũng lồi cục bộ rồi chuyển sang L-BFGS tận dụng trọn vẹn ưu thế của cả hai thế giới.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiền điều kiện cấu trúc Kronecker (K-FAC, Shampoo, SOAP):&lt;/strong&gt; Thay vì xấp xỉ Hessian của toàn bộ mạng bằng một ma trận khổng lồ, các thuật toán này xấp xỉ độ cong cho từng ma trận trọng số \(W \in \mathbb{R}^{d_1 \times d_2}\) dưới dạng tích Kronecker \(L \otimes R\), giữ chi phí bộ nhớ cỡ \(O(d_1^2 + d_2^2)\) nhưng nắm bắt được tương quan chéo giữa các tham số.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-minh-họa-vì-sao-số-điều-kiện-kappa--104-làm-adam-chững-lại-còn-l-bfgs-bứt-phá&quot;&gt;Giải thích: Minh họa vì sao số điều kiện \(\kappa = 10^4\) làm Adam chững lại còn L-BFGS bứt phá&lt;/h3&gt;

&lt;p&gt;Xét một hàm mục tiêu bậc hai mô phỏng độ cong điển hình của bài toán PDE rời rạc hóa 2 chế độ (tần số thấp và tần số cao):&lt;/p&gt;

\[f(w_1, w_2) = \frac{1}{2}\left(w_1^2 + 10{,}000\, w_2^2\right), \qquad \kappa = \frac{\lambda_{\max}}{\lambda_{\min}} = 10{,}000.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hạ gradient chuẩn không tiền điều kiện:&lt;/strong&gt; Để ổn định trên trục \(w_2\), bước học buộc phải thỏa mãn \(\eta &amp;lt; \frac{2}{\lambda_{\max}} = 2 \times 10^{-4}\). Với \(\eta = 10^{-4}\), sai số dọc trục \(w_1\) sau mỗi bước chỉ nhân với \((1 - 10^{-4}) = 0.9999\). Muốn giảm sai số xuống \(10^{-4}\), ta cần cỡ \(\frac{\ln(10^4)}{10^{-4}} \approx 92{,}100\) vòng lặp!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu quả tiền điều kiện của Quasi-Newton / L-BFGS:&lt;/strong&gt; Chỉ sau \(2\) bước đo cặp \((s, y)\) dọc hai hướng độc lập, xấp xỉ \(H_2\) khôi phục chính xác ma trận nghịch đảo độ cong \(\operatorname{diag}(1, \; 10^{-4})\). Số điều kiện hiệu dụng của hệ đã tiền điều kiện \(H_2 \nabla^2 f\) sụt từ \(\kappa = 10{,}000\) xuống đúng \(\kappa_{\text{eff}} = 1\) — và thuật toán nhảy thẳng tới nghiệm tối ưu \((0, 0)\) chỉ trong &lt;strong&gt;1 bước Newton&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hệ thực tế với PINN:&lt;/strong&gt; Trong mạng nơ-ron có hàng chục nghìn tham số, L-BFGS (với \(m = 50\text{–}100\)) loại bỏ vài chục chế độ trị riêng lớn nhất gây dao động mạnh, làm giảm \(\kappa_{\text{eff}}\) hàng trăm lần và đưa sai số PDE từ \(10^{-2}\) xuống \(10^{-6}\) chỉ sau vài trăm vòng lặp.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phương pháp quasi-Newton thay ma trận Hessian \(\nabla^2 f(x)\) bằng một ma trận xấp xỉ \(B\) thỏa mãn phương trình secant \(B^{+}s = y\) và (với BFGS/L-BFGS) bảo toàn tính xác định dương dưới điều kiện độ cong \(y^\top s &amp;gt; 0\). Những ứng dụng tiêu biểu giai đoạn 2022–2026 gắn trực tiếp với chương này không phải các bộ tối ưu tiền huấn luyện LLM ước lượng Hessian đường chéo (vốn thuộc nhóm Newton / Sophia ở Chương 14), mà là các thuật toán lưu giữ lịch sử ngắn các cặp \((s, y)\) — tiêu biểu là L-BFGS trong học máy khoa học và mô hình dữ liệu dạng bảng — cùng các bộ tiền điều kiện có cấu trúc (Shampoo / SOAP) mang họ hàng phân rã Kronecker với BFGS.&lt;/p&gt;

&lt;h2 id=&quot;pinn-dùng-adam-để-tiến-gần-dùng-l-bfgs-để-hội-tụ-chính-xác&quot;&gt;PINN: dùng Adam để tiến gần, dùng L-BFGS để hội tụ chính xác&lt;/h2&gt;

&lt;p&gt;Mạng nơ-ron tích hợp tri thức vật lý (PINN) cực tiểu hóa phần dư chứa các toán tử vi phân. Chính các toán tử vi phân này khiến bài toán tối ưu có số điều kiện rất xấu: phổ trị riêng của Hessian bám theo phổ của phương trình đạo hàm riêng (PDE) rời rạc hóa thay vì phổ của hàm mất mát entropy chéo. Rathore, Lei, Frangella, Lu và Udell (ICML 2024) so sánh Adam, L-BFGS và tổ hợp &lt;strong&gt;Adam+L-BFGS&lt;/strong&gt;, cho thấy tổ hợp vượt trội từng phương pháp đơn lẻ, đồng thời đề xuất NysNewton-CG như một cải tiến bậc hai bổ sung. Đóng góp lý thuyết của bài báo là làm rõ mối liên hệ giữa toán tử vi phân điều kiện xấu và Hessian điều kiện xấu của PINN — giải thích vì sao các phương pháp dựa trên phương trình secant (tích lũy thông tin độ cong dọc quỹ đạo) vượt trội các phương pháp thích nghi đường chéo vốn bỏ qua sự tương tác ngoài đường chéo của phần dư.&lt;/p&gt;

&lt;p&gt;Quy trình huấn luyện phổ biến trong thực tế — hình thành từ trước năm 2024 và vẫn là chuẩn mực đến năm 2026 — là chạy Adam để đưa nghiệm vào vùng lồi bậc hai (quadratic bowl), sau đó chuyển sang L-BFGS kèm tìm kiếm theo đường thẳng thỏa mãn điều kiện Wolfe. Urbán, Stefanou, Pons et al. (2024, &lt;a href=&quot;https://arxiv.org/abs/2405.04230&quot;&gt;arXiv:2405.04230&lt;/a&gt;) phân tích chiến lược hai giai đoạn này và định lượng mức cải thiện độ chính xác mà BFGS / L-BFGS mang lại sau pha khởi đầu bằng Adam. Đây chính là ứng dụng trực tiếp của thuật toán đệ quy hai vòng ở bài 18-07.&lt;/p&gt;

&lt;h2 id=&quot;bfgs-tự-co-giãn-trên-pinn-pikan-và-deeponet&quot;&gt;BFGS tự co giãn trên PINN, PIKAN và DeepONet&lt;/h2&gt;

&lt;p&gt;Kiyani, Shukla, Urbán, Darbon và Karniadakis (2025, &lt;a href=&quot;https://arxiv.org/abs/2501.16371&quot;&gt;arXiv:2501.16371&lt;/a&gt;) quay lại lớp Broyden ở bài 18-05. &lt;strong&gt;BFGS tự co giãn (self-scaled BFGS)&lt;/strong&gt; và &lt;strong&gt;Broyden tự co giãn&lt;/strong&gt; hiệu chỉnh tỷ lệ của xấp xỉ Hessian dựa trên cặp độ cong gần nhất — một cơ chế ổn định kinh điển (Oren–Luenberger) giúp hạn chế sự biến động quá lớn của độ dài bước trên phần dư PDE. Trên các phương trình Burgers, Allen–Cahn, Kuramoto–Sivashinsky, Ginzburg–Landau cũng như trên mạng Kolmogorov–Arnold tích hợp vật lý (PIKAN), các tác giả ghi nhận mức giảm phần dư theo hàng bậc độ lớn mà &lt;em&gt;không&lt;/em&gt; cần kỹ thuật gán trọng số hàm mất mát thích nghi thường thấy ở PINN. Cùng công thức cập nhật này cũng cải thiện hiệu quả huấn luyện DeepONet.&lt;/p&gt;

&lt;p&gt;Có thể xem đây là minh họa thực nghiệm trực tiếp cho lớp Broyden: \(\phi = 0\) là BFGS, \(\phi = 1\) là DFP, còn phiên bản tự co giãn sử dụng tham số \(\phi\) phụ thuộc dữ liệu kết hợp hệ số co giãn vô hướng. Điều kiện độ cong \(y^\top s &amp;gt; 0\) được đảm bảo bởi bước tìm kiếm theo đường thẳng; khi điều kiện này không thỏa mãn, cặp \((s, y)\) sẽ bị bỏ qua — đúng như cơ chế bảo vệ tiêu chuẩn trong mọi cài đặt L-BFGS.&lt;/p&gt;

&lt;h2 id=&quot;l-bfgs-b-lựa-chọn-mặc-định-tiêu-chuẩn-trong-học-máy-dữ-liệu-bảng&quot;&gt;L-BFGS-B: lựa chọn mặc định tiêu chuẩn trong học máy dữ liệu bảng&lt;/h2&gt;

&lt;p&gt;Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LogisticRegression(solver=&quot;lbfgs&quot;)&lt;/code&gt; và họ mô hình tuyến tính tổng quát (GLM) trong scikit-learn (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;lbfgs&quot;&lt;/code&gt;, dùng mặc định bên cạnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newton-cholesky&lt;/code&gt;) đều gọi bộ giải &lt;strong&gt;L-BFGS-B&lt;/strong&gt; của SciPy (L-BFGS có ràng buộc hộp). Với số mẫu \(n\) ở mức hàng chục nghìn và số đặc trưng \(d\) từ vài trăm đến vài nghìn, L-BFGS-B vẫn là lựa chọn phù hợp nhất: rẻ hơn so với tính trực tiếp Hessian, chính xác hơn SGD trên các bài toán GLM lồi và hỗ trợ khởi động ấm dọc theo đường điều chuẩn. Hugging Face Trainer cũng cung cấp tùy chọn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;optim=&quot;lbfgs&quot;&lt;/code&gt; cho các bài toán tinh chỉnh cỡ nhỏ. Điểm rút ra quan trọng — đối lập với câu chuyện Sophia ở bài toán LLM lớn — là: &lt;em&gt;khi mô hình đủ nhỏ để lưu xấp xỉ Hessian bằng vài chục vector trên CPU, phương pháp quasi-Newton thường vượt trội Adam&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Một đoạn mã kiểm chứng ngắn gọn:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sklearn.linear_model&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LogisticRegression&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;clf&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;LogisticRegression&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;solver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;lbfgs&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;clf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_iter_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hãy so sánh với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;newton-cholesky&quot;&lt;/code&gt; (Chương 14) trên ma trận thiết kế nhiều mẫu (\(n \gg d\)) và với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;saga&quot;&lt;/code&gt; trên ma trận thiết kế nhiều đặc trưng (\(d \gg n\)). Việc chọn giữa Newton, L-BFGS và phương pháp bậc nhất giảm phương sai phụ thuộc trực tiếp vào kích thước \((n, d)\) và cấu trúc ràng buộc.&lt;/p&gt;

&lt;h2 id=&quot;soap-hệ-cơ-sở-vector-riêng-của-shampoo-như-một-phương-pháp-quasi-newton-có-cấu-trúc&quot;&gt;SOAP: hệ cơ sở vector riêng của Shampoo như một phương pháp quasi-Newton có cấu trúc&lt;/h2&gt;

&lt;p&gt;Vyas, Morwani, Zhao, Kwun, Shapira, Brandfonbrener, Janson và Kakade (ICLR 2025) giới thiệu &lt;strong&gt;SOAP&lt;/strong&gt; (&lt;em&gt;ShampoO with Adam in the Preconditioner’s eigenbasis&lt;/em&gt;). Shampoo (Gupta, Koren, Singer, 2018; cùng các triển khai quy mô lớn giai đoạn 2023–2024) duy trì các ma trận mô-men bậc hai phân rã theo tích Kronecker, mang bản chất lai giữa quasi-Newton và gradient tự nhiên có cấu trúc. SOAP chứng minh rằng Shampoo với nghịch đảo căn bậc hai tương đương với việc chạy Adafactor trong hệ cơ sở vector riêng của Shampoo, từ đó &lt;em&gt;thay&lt;/em&gt; Adafactor bằng AdamW trong hệ cơ sở biến đổi chậm này. Trên các mô hình ngôn ngữ 360 triệu và 660 triệu tham số ở chế độ kích thước lô lớn, SOAP giảm hơn 40% số vòng lặp và hơn 35% thời gian chạy thực tế (wall-clock time) so với AdamW, đồng thời giảm khoảng 20% so với Shampoo.&lt;/p&gt;

&lt;p&gt;Dù không dùng các cặp \((s, y)\) như L-BFGS, SOAP chia sẻ chung nguyên lý thiết kế với DFP/BFGS: &lt;em&gt;ước lượng thông tin độ cong xác định dương, dễ nghịch đảo với chi phí thấp và cập nhật theo chu kỳ chậm hơn tốc độ cập nhật gradient.&lt;/em&gt; Siêu tham số tần suất phân rã trị riêng đóng vai trò tương tự kích thước bộ nhớ \(m\) của L-BFGS. Trong giảng dạy và thực hành, có thể đặt SOAP cạnh K-FAC (Chương 14) khi thảo luận lý thuyết, và đặt L-BFGS cạnh PINN trong bài thực hành.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;P. Rathore, W. Lei, Z. Frangella, L. Lu, M. Udell, “Challenges in Training PINNs: A Loss Landscape Perspective,” ICML 2024, PMLR 235.&lt;/li&gt;
  &lt;li&gt;W. Urbán et al., “Unveiling the optimization process of Physics Informed Neural Networks,” 2024. &lt;a href=&quot;https://arxiv.org/abs/2405.04230&quot;&gt;arXiv:2405.04230&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;E. Kiyani, K. Shukla, J. F. Urbán, J. Darbon, G. E. Karniadakis, “Optimizing the Optimizer for Physics-Informed Neural Networks and Kolmogorov-Arnold Networks,” 2025. &lt;a href=&quot;https://arxiv.org/abs/2501.16371&quot;&gt;arXiv:2501.16371&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;N. Vyas et al., “SOAP: Improving and Stabilizing Shampoo using Adam,” ICLR 2025. &lt;a href=&quot;https://arxiv.org/abs/2409.11321&quot;&gt;arXiv:2409.11321&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SciPy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L-BFGS-B&lt;/code&gt;; scikit-learn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LogisticRegression(solver=&quot;lbfgs&quot;)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>17-06 Ứng dụng hiện đại của phương pháp điểm trong nguyên thủy–đối ngẫu (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_06_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_06_modern_applications</id>
   <content type="html">&lt;p&gt;Hơn bốn thập kỷ sau bài báo của Karmarkar, phương pháp điểm trong gốc–đối ngẫu không hề trở thành “kiến thức sách giáo khoa cũ kỹ” — ngược lại, giai đoạn 2022–2026 chứng kiến một làn sóng tái kiến trúc mạnh mẽ. Các bộ giải mới viết bằng Rust và Julia như Clarabel đã trở thành nhân mặc định của CVXPY, các bộ giải LP/QP điểm trong được đưa lên GPU để xử lý bài toán hàng chục triệu biến, đồng thời nới lỏng SDP lại trở thành công cụ trung tâm trong bài toán kiểm chứng độ bền vững (robustness verification) của mạng nơ-ron sâu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-động-lực-nâng-cấp-pd-ipm-trong-kỷ-nguyên-hiện-đại&quot;&gt;Kiến thức cần nhớ: Ba động lực nâng cấp PD-IPM trong kỷ nguyên hiện đại&lt;/h2&gt;

&lt;p&gt;Để hiểu vì sao các hệ thống tối ưu giai đoạn 2022–2026 vẫn xoay quanh khung PD-IPM của Chương 17 nhưng khác xa cài đặt cơ bản, hãy chú ý ba bước tiến sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nhúng tự đối ngẫu đồng nhất (Homogeneous Self-Dual Embedding):&lt;/strong&gt; PD-IPM cơ bản dễ bị phân kỳ khi bài toán vô nghiệm hoặc không bị chặn. Các bộ giải hiện đại (Clarabel, Mosek, ECOS) nhúng bài toán vào một hệ đồng nhất thêm biến vô hướng \((\tau_{\text{hom}}, \kappa)\) để đồng thời giải tối ưu HOẶC trả về chứng chỉ Farkas khẳng định vô nghiệm trong đúng một lần chạy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tích các nón đối xứng và bất đối xứng:&lt;/strong&gt; Bài toán hiện đại không chỉ có LP hay SDP mà kết hợp cả nón bậc hai (SOC), nón mũ (exponential cone — cho hồi quy logistic, entropy) và nón lũy thừa (power cone). Clarabel mở rộng hàm chắn và bước Newton gốc–đối ngẫu trực tiếp trên tích các nón này.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tăng tốc phần cứng và bài toán kiểm chứng học sâu:&lt;/strong&gt; Việc giải hệ KKT khối (chiếm &amp;gt;85% thời gian chạy) đang được tăng tốc bằng phân rã Cholesky/LDL song song trên GPU và tiền điều kiện lặp, đồng thời mở ra cuộc đua giữa độ chặt của nới lỏng SDP và giới hạn bộ nhớ \(O(n^2)\) khi kiểm chứng mạng nơ-ron.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-nhúng-đồng-nhất-phát-hiện-bài-toán-vô-nghiệm-như-thế-nào&quot;&gt;Giải thích: Nhúng đồng nhất phát hiện bài toán vô nghiệm như thế nào?&lt;/h3&gt;

&lt;p&gt;Giả sử bạn đưa vào bộ giải một bài toán LP 1 biến &lt;strong&gt;vô nghiệm&lt;/strong&gt; (infeasible):&lt;/p&gt;

\[\min_{x} \; x \qquad \text{với điều kiện} \qquad x = -1, \quad x \ge 0.\]

&lt;p&gt;Hãy xem điều gì xảy ra với PD-IPM thường so với nhúng đồng nhất (như trong Clarabel):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điều gì làm PD-IPM thường lúng túng?&lt;/strong&gt; Ràng buộc \(x = -1\) và \(x \ge 0\) mâu thuẫn nhau, nên không tồn tại điểm khả thi gốc; trong khi bài toán đối ngẫu \(\max_y (-y) \text{ s.t. } y \le 1\) không bị chặn trên (\(y \to -\infty\)). Nếu chạy PD-IPM thường, giá trị \(y^{(k)} \to -\infty\) còn phần dư \(r_{\text{prim}} = x + 1\) không bao giờ về \(0\), khiến thuật toán chạy hết số vòng lặp rồi báo lỗi số học.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách nhúng đồng nhất xử lý:&lt;/strong&gt; Thay vì cố định vế phải \(b = -1\) và \(c = 1\), ta nhân chúng với một biến vô hướng \(\tau_{\text{hom}} \ge 0\) và bổ sung biến bù \(\kappa \ge 0\) với điều kiện bù chặt \(\tau_{\text{hom}}\kappa = 0\):
\(Ax - b\tau_{\text{hom}} = 0 \implies x + \tau_{\text{hom}} = 0, \qquad A^T y + s - c\tau_{\text{hom}} = 0 \implies y + s - \tau_{\text{hom}} = 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết quả hội tụ sạch sẽ:&lt;/strong&gt; Khi thuật toán hội tụ, ta thu được \(\tau_{\text{hom}}^\star = 0\), \(\kappa^\star &amp;gt; 0\), \(x^\star = 0\), \(y^\star = -1\), \(s^\star = 1 \ge 0\). Kiểm tra bất đẳng thức Farkas:
\(A^T y^\star = -1 \le 0 \quad \text{và} \quad b^T y^\star = (-1)(-1) = +1 &amp;gt; 0.\)
Bộ giải trả về ngay một &lt;strong&gt;chứng chỉ toán học chính xác&lt;/strong&gt; khẳng định bài toán gốc vô nghiệm — không cần đoán qua ngưỡng dừng hay chạy thêm Pha I!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phương pháp điểm trong nguyên thủy–đối ngẫu chỉ thực hiện &lt;em&gt;một&lt;/em&gt; bước Newton trên hệ phương trình KKT bị nhiễu&lt;/p&gt;

\[r_t(x,u,v) = 0\]

&lt;p&gt;thay vì giải bài toán rào cản tới độ chính xác cao ở mọi giá trị \(t\). Những đại lượng bạn đã tính trong chương này — khoảng cách đối ngẫu thay thế \(-h(x)^\top u\), phần dư nguyên thủy và đối ngẫu, cùng khối bù tuyến tính hóa \(U\nabla h(x)^\top\,\Delta x + H(x)\,\Delta u = -Uh(x) - (1/t)\mathbf{1}\) — chính là các phần dư mà các bộ giải nón hiện đại hiển thị trong nhật ký chạy. Diễn biến đáng chú ý giai đoạn 2022–2026 là các bộ giải này đã trở thành backend Python mặc định, được tăng tốc trên GPU, và đồng thời chạm tới giới hạn lý thuyết của nới lỏng SDP trong bài toán kiểm chứng mạng nơ-ron.&lt;/p&gt;

&lt;h2 id=&quot;clarabel-pd-ipm-dưới-dạng-thư-viện-chuẩn&quot;&gt;Clarabel: PD-IPM dưới dạng thư viện chuẩn&lt;/h2&gt;

&lt;p&gt;Clarabel (Goulart &amp;amp; Chen, 2024) cài đặt thuật toán điểm trong nguyên thủy–đối ngẫu đồng nhất cho bài toán có hàm mục tiêu bậc hai trên tích các nón đối xứng và không đối xứng. So với PD-IPM cơ bản trong giáo trình, thư viện này bổ sung nhúng đồng nhất (homogeneous embedding — giúp xử lý bài toán không khả thi hoặc không bị chặn với đường trung tâm xác định tốt), bước dự báo – hiệu chỉnh kiểu Mehrotra và phân rã LDL thưa cho hệ Newton KKT. Kết quả thực nghiệm cho thấy bộ giải nhanh và ổn định hơn nhiều đối thủ thương mại lẫn mã nguồn mở trên các bộ kiểm chuẩn, &lt;em&gt;đặc biệt&lt;/em&gt; trên bài toán QP — đúng lớp bài toán mà hệ Newton của chương này hướng tới.&lt;/p&gt;

&lt;p&gt;Từ phiên bản CVXPY 1.5, Clarabel trở thành bộ giải mặc định cho các lớp bài toán trước đây dùng ECOS. Do đó, khi bạn gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prob.solve()&lt;/code&gt; trên một bài toán SOCP, hệ thống đang thực thi chính thuật toán của Chương 17 chứ không phải phương pháp đơn hình. Các biến đối ngẫu mà CVXPY trả về chính là \(u, v\) trong chương này, còn phần dư bù là khoảng cách đối ngẫu thay thế. Nói cách khác, PD-IPM hiện đại đã có sẵn ngay trên máy tính cá nhân thông qua một lệnh gọi thư viện.&lt;/p&gt;

&lt;h2 id=&quot;cuclarabel-giải-hệ-newton-trên-gpu&quot;&gt;CuClarabel: giải hệ Newton trên GPU&lt;/h2&gt;

&lt;p&gt;Chen, Tse, Nobel, Goulart và Boyd (2024) chuyển vòng lặp này lên GPU NVIDIA với tên gọi &lt;strong&gt;CuClarabel&lt;/strong&gt;. Cấu trúc thuật toán vẫn là điểm trong nguyên thủy–đối ngẫu: pha tiền xử lý cân bằng dữ liệu, pha thiết lập và phân rã hệ Newton, kết hợp chiến lược song song hỗn hợp cho các nón (xử lý ràng buộc tuyến tính trước, sau đó xử lý song song các nón còn lại). Phần đại số tuyến tính được giao cho NVIDIA cuDSS với tùy chọn phân rã độ chính xác hỗn hợp. Bộ giải hỗ trợ nón không, nón không âm, nón bậc hai, nón mũ, nón lũy thừa và nón PSD. Bài báo cho thấy IPM trên GPU vượt trội IPM trên CPU trên nhiều lớp bài toán quy hoạch nón, bao gồm bài toán tối ưu danh mục đầu tư dạng QP và SOCP viết trong JuMP hoặc CVXPY.&lt;/p&gt;

&lt;p&gt;Kết quả này minh họa trực tiếp phân tích độ phức tạp ở Chương 17: nút thắt tính toán của PD-IPM không nằm ở các phép cập nhật biến mà nằm ở bước phân rã hệ KKT. Khi phép phân rã ma trận thưa này được tăng tốc trực tiếp trên GPU, phương pháp điểm trong trở nên khả thi cho các bài toán nón cỡ vài nghìn đến hàng chục nghìn biến trong quy trình khoa học dữ liệu thực tế, trong khi các phương pháp tách bậc nhất vẫn phù hợp hơn với quy mô hàng triệu biến ở mức độ chính xác vừa phải.&lt;/p&gt;

&lt;h2 id=&quot;nới-lỏng-sdp-cho-kiểm-chứng-mạng-nơ-ron&quot;&gt;Nới lỏng SDP cho kiểm chứng mạng nơ-ron&lt;/h2&gt;

&lt;p&gt;Nới lỏng bán xác định (SDP relaxation) của mạng ReLU tạo ra một bài toán SDP mà giá trị tối ưu đóng vai trò chứng chỉ cho độ bền vững (robustness) của mạng (Raghunathan, Steinhardt, Liang và các công trình về kiểm chứng SDP-NN). Những bài toán SDP này thường được giải bằng phương pháp điểm trong nguyên thủy–đối ngẫu khi cần một &lt;em&gt;chứng chỉ đáng tin cậy&lt;/em&gt;, bởi các phương pháp bậc nhất có thể có vẻ hội tụ nhưng không cung cấp bảo chứng về khoảng cách đối ngẫu. Tuy nhiên, một nghiên cứu năm 2025, “Interior-Point Vanishing Problem in Semidefinite Relaxations for Neural Network Verification” (&lt;a href=&quot;https://arxiv.org/abs/2506.10269&quot;&gt;arXiv:2506.10269&lt;/a&gt;), chỉ ra vấn đề phát sinh khi bài toán nới lỏng &lt;em&gt;không&lt;/em&gt; khả thi ngặt: đường trung tâm không có điểm trong, tính đối ngẫu mạnh có thể không còn đúng, và PD-IPM theo dõi khoảng cách \(X\cdot S\) có thể không bao giờ xác nhận được tính tối ưu. Các tác giả sử dụng IPM độ chính xác cao (SDPA-GMP) để chẩn đoán hiện tượng này và đề xuất các kỹ thuật điều chuẩn SDP cũng như rút gọn mặt (facial reduction).&lt;/p&gt;

&lt;p&gt;Đây là nơi mục SDP của Chương 17 giao thoa trực tiếp với học máy hiện đại. Phương trình đường trung tâm \(XS = \tau I\) đòi hỏi điều kiện điểm trong \(X, S \succ 0\). Nếu đa diện phổ (spectrahedron) không có phần trong tương đối, giả thiết này bị vi phạm và thuật toán ở bài 17-02 không chỉ chậm đi mà trở nên &lt;em&gt;không đặt chỉnh (ill-posed)&lt;/em&gt;. Bài học thực tiễn vẫn là nguyên tắc kinh điển của Boyd–Vandenberghe: cần kiểm tra điều kiện Slater trước khi tin cậy vào khoảng cách đối ngẫu.&lt;/p&gt;

&lt;h2 id=&quot;thực-hành-gợi-ý-trong-khóa-học&quot;&gt;Thực hành gợi ý trong khóa học&lt;/h2&gt;

&lt;p&gt;Trong một buổi thực hành khoảng một giờ, bạn có thể lấy một bài toán danh mục đầu tư chỉ mua (long-only portfolio) cỡ nhỏ hoặc SVM lề cứng, giải bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.CLARABEL&lt;/code&gt;, và in ra phần dư nguyên thủy, phần dư đối ngẫu cùng khoảng cách đối ngẫu. Sau đó, hãy thử thay đổi loại nón ràng buộc (từ ràng buộc hộp sang nón bậc hai) để quan sát sự thay đổi về số vòng lặp Newton. Đây là cách trực quan nhất để thấy phương pháp điểm trong nguyên thủy–đối ngẫu vận hành trên mô hình khoa học dữ liệu mà không cần thêm lý thuyết ngoài chương này.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;P. J. Goulart, Y. Chen, “Clarabel: An interior-point solver for conic programs with quadratic objectives,” 2024. &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv:2405.12762&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Y. Chen, D. Tse, P. Nobel, P. Goulart, S. Boyd, “CuClarabel: GPU Acceleration for a Conic Optimization Solver,” 2024. &lt;a href=&quot;https://arxiv.org/abs/2412.19027&quot;&gt;arXiv:2412.19027&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;CVXPY 1.5: Clarabel làm backend IPM mặc định.&lt;/li&gt;
  &lt;li&gt;“Interior-Point Vanishing Problem in Semidefinite Relaxations for Neural Network Verification,” 2025. &lt;a href=&quot;https://arxiv.org/abs/2506.10269&quot;&gt;arXiv:2506.10269&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>16-04 Ứng dụng hiện đại của tính đối ngẫu (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_04_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_04_modern_applications</id>
   <content type="html">&lt;p&gt;Nếu ai đó nghĩ rằng đối ngẫu Lagrange và liên hợp Fenchel chỉ dành cho các bộ giải quy hoạch tuyến tính thế kỷ trước, hãy nhìn vào những công trình định hình trí tuệ nhân tạo giai đoạn &lt;strong&gt;2022–2026&lt;/strong&gt;: &lt;strong&gt;hàm mất mát Fenchel–Young&lt;/strong&gt; (thống nhất Cross-Entropy, Sparsemax và học có cấu trúc), &lt;strong&gt;căn chỉnh mô hình ngôn ngữ lớn bằng RLHF&lt;/strong&gt; (nơi hệ số \(\beta\) trước phân kỳ KL chính là nhân tử Lagrange!), &lt;strong&gt;học tăng cường an toàn (Safe RL)&lt;/strong&gt; chạy vòng lặp nguyên thủy – đối ngẫu trực tiếp, và &lt;strong&gt;vận chuyển tối ưu (Optimal Transport / Wasserstein)&lt;/strong&gt; dưới góc nhìn đối ngẫu Fenchel–Kantorovich.&lt;/p&gt;

&lt;p&gt;Bài đọc hiện đại này chỉ ra cách chính xác ba trụ cột của Chương 16 (Lagrange, KKT và Fenchel) đang giải quyết những bài toán nóng nhất của AI ngày nay.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-cầu-nối-từ-đối-ngẫu-chương-16-sang-ai-hiện-đại-20222026&quot;&gt;Kiến thức cần nhớ: Bốn cầu nối từ Đối ngẫu Chương 16 sang AI hiện đại (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mất mát Fenchel–Young:&lt;/strong&gt; Cho bất kỳ hàm lồi \(\Omega(p)\) nào (như entropy âm hay bình phương \(\ell_2\)), định nghĩa \(L_\Omega(\theta; y) = \Omega^*(\theta) + \Omega(y) - \theta^T y \ge 0\) nhờ bất đẳng thức Fenchel–Young! Khi \(\Omega\) là entropy âm, \(L_\Omega\) chính là &lt;strong&gt;Cross-Entropy Loss&lt;/strong&gt; quen thuộc!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;RLHF và ràng buộc phân kỳ KL:&lt;/strong&gt; Bài toán cực đại hóa phần thưởng \(\mathbb{E}_\pi[r(x, y)]\) dưới ràng buộc \(D_{\text{KL}}(\pi \| \pi_{\text{ref}}) \le \delta\) khi đưa vào hàm Lagrange với nhân tử \(\beta &amp;gt; 0\) cho ra nghiệm đóng &lt;strong&gt;phân phối Boltzmann&lt;/strong&gt; \(\pi^*(y \mid x) \propto \pi_{\text{ref}}(y \mid x)\exp(r(x, y)/\beta)\) — nền tảng của cả PPO-RLHF lẫn DPO!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp nguyên thủy – đối ngẫu trong Safe RL:&lt;/strong&gt; Thay vì tự mò trọng số phạt an toàn cố định, thuật toán cập nhật chính sách \(\pi\) (giảm cực tiểu Lagrange) xen kẽ với bước tăng/giảm nhân tử Lagrange \(\lambda \ge 0\) (leo dốc đối ngẫu) cho đến khi tỷ lệ vi phạm an toàn tụt xuống dưới ngưỡng cho phép.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vận chuyển tối ưu (Optimal Transport):&lt;/strong&gt; Đối ngẫu Fenchel–Kantorovich chuyển bài toán tìm kế hoạch vận chuyển khối lượng xác suất thành bài toán tìm hai hàm thế năng đối ngẫu \((\phi, \psi)\) (nền tảng của Wasserstein GAN và khớp phân phối trong mô hình sinh).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-nghiệm-đóng-rlhf-phân-phối-boltzmann-từ-điều-kiện-kkt&quot;&gt;Giải thích: Tính tay nghiệm đóng RLHF (phân phối Boltzmann) từ điều kiện KKT&lt;/h3&gt;

&lt;p&gt;Xét bài toán chọn phân phối hành động \(\pi = (\pi_1, \pi_2)\) trên 2 câu trả lời (\(\pi_1 + \pi_2 = 1, \pi_i &amp;gt; 0\)) với phân phối tham chiếu đều \(\pi_{\text{ref}} = (0.5, 0.5)\), điểm thưởng \(r = (2, 0)\), và nhân tử Lagrange KL cố định \(\beta = 1\):&lt;/p&gt;

\[\max_{\pi_1 + \pi_2 = 1} \bigl(2\pi_1 + 0\pi_2\bigr) - 1 \cdot \left(\pi_1 \ln\frac{\pi_1}{0.5} + \pi_2 \ln\frac{\pi_2}{0.5}\right).\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập hàm Lagrange (với nhân tử \(\nu\) cho \(\pi_1 + \pi_2 = 1\)):&lt;/strong&gt;
\(L(\pi, \nu) = 2\pi_1 - \pi_1 \ln(2\pi_1) - \pi_2 \ln(2\pi_2) + \nu(1 - \pi_1 - \pi_2).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải điều kiện dừng KKT \(\frac{\partial L}{\partial \pi_i} = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Theo \(\pi_1\): \(2 - \ln(2\pi_1) - 1 - \nu = 0 \implies \pi_1 = \frac{1}{2} e^{1 - \nu}\).&lt;/li&gt;
      &lt;li&gt;Theo \(\pi_2\): \(0 - \ln(2\pi_2) - 1 - \nu = 0 \implies \pi_2 = \frac{1}{2} e^{-1 - \nu}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn hóa bằng \(\pi_1 + \pi_2 = 1\):&lt;/strong&gt;
\(\frac{\pi_1}{\pi_2} = \frac{e^2}{e^0} = e^2 \approx 7.389 \implies \pi_1^\star = \frac{e^2}{e^2 + 1} \approx 0.8808, \qquad \pi_2^\star = \frac{1}{e^2 + 1} \approx 0.1192.\)
Nhờ ràng buộc KL (nhân tử \(\beta = 1\)), mô hình ưu tiên câu trả lời tốt hơn (88.1%) nhưng không sụp đổ thành 100% (reward hacking) mà vẫn giữ độ đa dạng gần mô hình gốc!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Chương 16 hệ thống lại đối ngẫu Lagrange, điều kiện KKT và liên hợp Fenchel làm nền tảng cho phương pháp điểm trong nguyên thủy – đối ngẫu ở Chương 17. Ba đối tượng quen thuộc này — hàm Lagrange, biến đối ngẫu định giá ràng buộc và hàm liên hợp Fenchel chuyển đổi giữa hàm mất mát và hàm điều chuẩn (regularizer) — chính là cách học máy giai đoạn 2022–2026 &lt;em&gt;xây dựng hàm mục tiêu&lt;/em&gt;, chứ không chỉ dùng trong chứng minh lý thuyết. Bốn ứng dụng dưới đây giữ rõ cấu trúc toán học của chương này: ở mỗi trường hợp, ta đều có thể chỉ ra rõ ràng bài toán nguyên thủy, ràng buộc và biến đối ngẫu tương ứng.&lt;/p&gt;

&lt;h2 id=&quot;hàm-mất-mát-fenchelyoung-dùng-hàm-liên-hợp-làm-mục-tiêu-huấn-luyện&quot;&gt;Hàm mất mát Fenchel–Young: dùng hàm liên hợp làm mục tiêu huấn luyện&lt;/h2&gt;

&lt;p&gt;Blondel, Martins và Niculae (JMLR 2020) định nghĩa &lt;strong&gt;hàm mất mát Fenchel–Young&lt;/strong&gt; từ một ánh xạ dự báo có điều chuẩn. Nếu \(\Omega\) là hàm điều chuẩn lồi trên đơn hình (hoặc một tập có cấu trúc) và \(\Omega^\star\) là hàm liên hợp của nó, thì hàm mất mát&lt;/p&gt;

\[L_\Omega(\theta; y) = \Omega^\star(\theta) + \Omega(y) - \theta^\top y\]

&lt;p&gt;chính là khe Fenchel–Young đã xét ở &lt;a href=&quot;/contents/vi/chapter16/16_03_fenchel_duality/&quot;&gt;16-03&lt;/a&gt;. Hàm mất mát entropy chéo là trường hợp riêng với \(\Omega\) là âm entropy; các hàm mất mát thưa và có cấu trúc khác thu được khi thay đổi \(\Omega\). Dù khái niệm ra đời trước năm 2022, nó đã trở thành một &lt;em&gt;khuôn mẫu thiết kế&lt;/em&gt; phổ biến trong những năm gần đây. Blondel, Llinares-López, Dadashi, Hussenot và Geist (NeurIPS 2022) mở rộng hướng này sang mạng năng lượng bằng cách thay tích song tuyến bằng một phép ghép tổng quát (hàm liên hợp tổng quát, bao gồm phép biến đổi \(C\)-transform của vận chuyển tối ưu). Năm 2025, hàm mất mát Fenchel–Young sắc nét (sharpened Fenchel–Young losses) được ứng dụng cho bài toán ngược vận chuyển tối ưu không cân bằng và dòng gradient JKO ngược — bao gồm mô hình hóa động lực quần thể tế bào trong hệ gen học đơn bào (&lt;a href=&quot;https://arxiv.org/abs/2505.07124&quot;&gt;arXiv:2505.07124&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Góc nhìn thực hành: hãy lấy một hàm mất mát quen thuộc, viết lại nó dưới dạng \(\Omega^\star(\theta)-\theta^\top y+\Omega(y)\), và nhìn nhận biến đối ngẫu như một &lt;em&gt;dự báo&lt;/em&gt; thay vì chỉ là nhân tử Lagrange. Lúc này, đối ngẫu không chỉ là công cụ kiểm chứng tính tối ưu mà trực tiếp trở thành hàm mất mát.&lt;/p&gt;

&lt;h2 id=&quot;rlhf-ràng-buộc-kl-và-nhân-tử-lagrange-tương-ứng&quot;&gt;RLHF: ràng buộc KL và nhân tử Lagrange tương ứng&lt;/h2&gt;

&lt;p&gt;Ouyang et al. (NeurIPS 2022), &lt;em&gt;Training language models to follow instructions with human feedback&lt;/em&gt; (InstructGPT), tinh chỉnh mô hình đã học có giám sát bằng PPO theo mô hình phần thưởng, kết hợp với &lt;strong&gt;hạng tử phạt KL theo từng token&lt;/strong&gt; để giữ chính sách không lệch quá xa mô hình tham chiếu SFT. Mục tiêu RLHF tiêu chuẩn chính là hàm Lagrange của bài toán&lt;/p&gt;

\[\max_\pi\ \mathbb{E}_{x\sim\mathcal{D},\, y\sim\pi(\cdot\mid x)}\bigl[r_\theta(x,y)\bigr]
\quad\text{với}\quad
\mathbb{E}\bigl[\mathrm{KL}(\pi(\cdot\mid x)\,\|\,\pi_{\mathrm{SFT}}(\cdot\mid x))\bigr] \le \varepsilon.\]

&lt;p&gt;Hệ số nhân với hạng tử KL là biến đối ngẫu của ràng buộc phân kỳ KL. Tăng hệ số này tương ứng với một bước tăng đối ngẫu (dual ascent): ta nâng mức phạt cho việc rời xa mô hình tham chiếu cho đến khi ràng buộc được thỏa mãn. Các phương pháp căn chỉnh sau này (như DPO và các biến thể liên quan) viết lại &lt;em&gt;chính hàm Lagrange đó&lt;/em&gt; để chính sách tối ưu có nghiệm dạng đóng và hệ số đối ngẫu trở thành tham số nhiệt độ; cấu trúc đối ngẫu vẫn được giữ nguyên, chỉ khác là được giải theo hướng giải tích.&lt;/p&gt;

&lt;p&gt;Đây là một ví dụ thực tế gần gũi của Chương 16: đối ngẫu mạnh không được đảm bảo cho lớp chính sách không lồi, nhưng &lt;em&gt;cách mô hình hóa&lt;/em&gt; — đặt ràng buộc trước, định giá ràng buộc và xem nhân tử như một tham số điều chỉnh — chính là ứng dụng trực tiếp của đối ngẫu Lagrange trong thực tiễn.&lt;/p&gt;

&lt;h2 id=&quot;học-tăng-cường-an-toàn-safe-rl-vòng-lặp-nguyên-thủy--đối-ngẫu-trong-thực-tế&quot;&gt;Học tăng cường an toàn (Safe RL): vòng lặp nguyên thủy – đối ngẫu trong thực tế&lt;/h2&gt;

&lt;p&gt;Bài toán MDP có ràng buộc (CMDP) yêu cầu tìm chính sách cực đại hóa lợi tức kỳ vọng trong giới hạn ngân sách chi phí kỳ vọng. PPO-Lagrangian và TRPO-Lagrangian (OpenAI Safety Gym, Ray et al. 2019) cập nhật chính sách bằng PPO/TRPO và cập nhật nhân tử bằng bước tăng đối ngẫu dựa trên phần dư chi phí — đúng theo sơ đồ nguyên thủy – đối ngẫu kinh điển trên một bài toán điểm yên ngẫu nhiên, không lồi. CPO (Achiam et al., 2017) tuyến tính hóa ràng buộc và giải một bài toán QP nhỏ ở mỗi bước; IPO (Chương 15) dùng hàm rào cản thay cho nhân tử. Các bộ thư viện OmniSafe (Ji et al., JMLR 2024) và Safety Gymnasium (Ji et al., NeurIPS 2023) chuẩn hóa các thuật toán này để nghiên cứu và đồ án giai đoạn 2024–2026 có thể &lt;em&gt;so sánh trực tiếp&lt;/em&gt; phương pháp rào cản, nguyên thủy – đối ngẫu và đối ngẫu miền tin cậy trên cùng một môi trường robot.&lt;/p&gt;

&lt;p&gt;Paternain, Chamon, Calvo-Fullana và Ribeiro (và loạt nghiên cứu SafeRL nguyên thủy – đối ngẫu năm 2022) cung cấp nền tảng giải tích lồi cho hướng này: hàm đối ngẫu của CMDP là một bài toán quy hoạch lõm theo nhân tử, và khe đối ngẫu nhỏ giúp kiểm soát mức độ vi phạm ràng buộc. Đó chính là nội dung &lt;a href=&quot;/contents/vi/chapter16/16_01_lagrangian_duality_revisited/&quot;&gt;16-01&lt;/a&gt; với phép lấy kỳ vọng nằm bên trong các tích trong.&lt;/p&gt;

&lt;h2 id=&quot;vận-chuyển-tối-ưu-dưới-góc-nhìn-đối-ngẫu-fenchel&quot;&gt;Vận chuyển tối ưu dưới góc nhìn đối ngẫu Fenchel&lt;/h2&gt;

&lt;p&gt;Bài toán vận chuyển tối ưu có điều chuẩn entropy (entropic optimal transport),&lt;/p&gt;

\[\min_{\pi\in\Pi(\mu,\nu)}\ \langle C,\pi\rangle + \varepsilon\,\mathrm{KL}(\pi\,\|\,\mu\otimes\nu),\]

&lt;p&gt;có bài toán đối ngẫu Fenchel là bài toán cực đại hóa hàm lõm không ràng buộc theo hai thế năng — chính là đối ngẫu Sinkhorn. Vận chuyển tối ưu tính toán (chuyên khảo Peyré &amp;amp; Cuturi; thư viện POT) được sử dụng rộng rãi trong giai đoạn 2022–2026 cho phân tích dữ liệu đơn bào, thích nghi miền và mô hình sinh nhằm vận chuyển khối lượng xác suất giữa các độ đo thực nghiệm. Hàm mất mát Fenchel–Young tổng quát (NeurIPS 2022) chuyển phép biến đổi \(C\)-transform của đối ngẫu đó thành &lt;em&gt;hàm mất mát huấn luyện&lt;/em&gt; cho mô hình năng lượng. Nếu đối ngẫu Fenchel ở bài 16-03 từng có vẻ trừu tượng, thì ứng dụng này cho thấy ý nghĩa trực quan của nó: hàm liên hợp của chi phí vận chuyển là một thế năng, và việc khớp các thế năng đó trở thành bài toán học có giám sát.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;M. Blondel, A. F. T. Martins, V. Niculae, “Learning with Fenchel-Young Losses,” JMLR 21(35), 2020.&lt;/li&gt;
  &lt;li&gt;M. Blondel, F. Llinares-López, R. Dadashi, L. Hussenot, M. Geist, “Learning Energy Networks with Generalized Fenchel-Young Losses,” NeurIPS 2022.&lt;/li&gt;
  &lt;li&gt;“Learning from Samples: Inverse Problems over Measures via Sharpened Fenchel-Young Losses,” 2025. &lt;a href=&quot;https://arxiv.org/abs/2505.07124&quot;&gt;arXiv:2505.07124&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;L. Ouyang et al., “Training language models to follow instructions with human feedback,” NeurIPS 2022.&lt;/li&gt;
  &lt;li&gt;J. Ji et al., “OmniSafe,” JMLR 25(285), 2024; “Safety Gymnasium,” NeurIPS 2023 Datasets.&lt;/li&gt;
  &lt;li&gt;S. Paternain et al., phương pháp nguyên thủy–đối ngẫu cho RL ràng buộc (dòng 2022); G. Peyré, M. Cuturi, &lt;em&gt;Computational Optimal Transport&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>15-09 Ứng dụng hiện đại của phương pháp rào chắn (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_09_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_09_modern_applications</id>
   <content type="html">&lt;p&gt;Nếu bạn từng nghĩ phương pháp chắn logarit chỉ là một chương lý thuyết cổ điển từ thập niên 1990, thì thực tế công nghiệp giai đoạn &lt;strong&gt;2022–2026&lt;/strong&gt; sẽ khiến bạn bất ngờ: hàm chắn logarit vẫn đang chạy âm thầm phía sau hầu hết các hệ thống tối ưu quan trọng nhất thế giới! Từ &lt;strong&gt;Clarabel&lt;/strong&gt; (bộ giải điểm trong viết bằng Rust trở thành bộ giải mặc định của CVXPY), &lt;strong&gt;điều khiển dự báo mô hình (MPC)&lt;/strong&gt; cho tên lửa và robot, đến &lt;strong&gt;học tăng cường an toàn (Safe RL)&lt;/strong&gt; và &lt;strong&gt;các tầng tối ưu khả vi (Differentiable Optimization Layers)&lt;/strong&gt; tích hợp thẳng vào mạng PyTorch.&lt;/p&gt;

&lt;p&gt;Điều kỳ diệu là dù giao diện lập trình hiện đại ngày càng thông minh và tự động, linh hồn toán học bên dưới vẫn y nguyên những gì bạn vừa học ở Chương 15: hàm chắn tự hài hòa, đường trung tâm và hệ điều kiện KKT nhiễu!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mặt-trận-ứng-dụng-của-phương-pháp-chắn-20222026&quot;&gt;Kiến thức cần nhớ: Bốn mặt trận ứng dụng của Phương pháp chắn (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Clarabel và hệ sinh thái bộ giải nón hiện đại:&lt;/strong&gt; Bộ giải mã nguồn mở Clarabel xử lý đồng thời LP, QP, SOCP, SDP và nón hàm mũ bằng thuật toán điểm trong thuần nhất tự đối ngẫu — kế thừa trực tiếp lý thuyết hàm chắn tự hài hòa của mục 15-08.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu danh mục tài chính &amp;amp; Điều khiển MPC thời gian thực:&lt;/strong&gt; Các bài toán phân bổ tài sản có ràng buộc rủi ro phương sai và bài toán điều khiển quỹ đạo (như hạ cánh tên lửa SpaceX hay xe tự hành) đều được giải ở tần số hàng chục Hz nhờ bộ giải điểm trong khai thác độ thưa của Hessian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chắn trong Học tăng cường an toàn (Safe RL) &amp;amp; Control Barrier Functions (CBF):&lt;/strong&gt; Thay vì để robot vi phạm giới hạn an toàn rồi mới phạt, hàm chắn logarit/CBF tạo lực đẩy trơn giữ trạng thái robot luôn nằm chặt bên trong tập an toàn suốt quá trình học!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lớp tối ưu khả vi (DiffOpt / OptNet / CvxpyLayers):&lt;/strong&gt; Bằng cách áp dụng định lý hàm ẩn ngay lên hệ phương trình KKT (hoặc KKT nhiễu trên đường trung tâm), ta truyền ngược gradient (backpropagation) xuyên qua cả một bộ giải tối ưu lồi nằm giữa mạng nơ-ron!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-đạo-hàm-ngược-xuyên-qua-điểm-đường-trung-tâm-trực-giác-differentiable-optimization&quot;&gt;Giải thích: Tính đạo hàm ngược xuyên qua điểm đường trung tâm (trực giác Differentiable Optimization)&lt;/h3&gt;

&lt;p&gt;Giả sử một tầng mạng nơ-ron nhận tham số đầu vào \(c &amp;gt; 0\) và giải bài toán chắn 1 chiều để xuất ra hành động \(x^*(c) &amp;gt; 0\):
\(x^*(c) = \arg\min_{x &amp;gt; 0} \bigl(c x - \log x\bigr) \qquad (\text{tức } t = 1, \text{ ràng buộc an toàn } x &amp;gt; 0).\)
Để huấn luyện mạng bằng backpropagation, ta cần tính đạo hàm \(\frac{dx^*}{dc}\) mà không cần “mở vòng lặp Newton”:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Viết phương trình KKT nhiễu (điều kiện dừng) tại nghiệm \(x^*\):&lt;/strong&gt;
\(F(x^*, c) = c - \frac{1}{x^*} = 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lấy vi phân hai vế theo \(c\) (Định lý hàm ẩn — chính là nguyên lý của CvxpyLayers/OptNet):&lt;/strong&gt;
\(1 + \frac{1}{(x^*)^2} \frac{dx^*}{dc} = 0 \implies \frac{dx^*}{dc} = -(x^*)^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra bằng số tại \(c = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nghiệm bài toán chắn: \(x^*(2) = \frac{1}{2} = 0.5\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Đạo hàm ngược tính bằng định lý hàm ẩn: $$\frac{dx^*}{dc}\Big&lt;/td&gt;
              &lt;td&gt;_{c=2} = -(0.5)^2 = -0.25$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Kiểm chứng trực tiếp từ công thức đóng \(x^*(c) = 1/c\): \((1/c)&apos; = -1/c^2 = -1/4 = -0.25\) — &lt;strong&gt;khớp chính xác tuyệt đối!&lt;/strong&gt; Nhờ tính trơn của đường trung tâm, ta tính được gradient truyền ngược cực kỳ ổn định ngay cả khi bài toán gốc có ràng buộc bất đẳng thức gãy khúc!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Hàm chắn logarit&lt;/p&gt;

\[\phi(x) = -\sum_{i=1}^{m}\log\bigl(-h_i(x)\bigr)\]

&lt;p&gt;chuyển bài toán có ràng buộc bất đẳng thức thành một họ bài toán trơn không ràng buộc (hoặc chỉ có ràng buộc đẳng thức) theo tham số \(t\). Đây vẫn là nền tảng cốt lõi của nhiều bộ giải tối ưu lồi trong thực tế, ngay cả khi người dùng không viết tường minh hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log&lt;/code&gt;. Mục này khảo sát bốn ứng dụng thực tế giai đoạn 2022–2026 gắn trực tiếp với đường trung tâm của chương: bộ giải mặc định trong CVXPY, các bài toán nón trong tài chính và điều khiển, học tăng cường an toàn, và các lớp tối ưu khả vi.&lt;/p&gt;

&lt;h2 id=&quot;clarabel-bộ-giải-điểm-trong-mặc-định-của-cvxpy&quot;&gt;Clarabel: bộ giải điểm trong mặc định của CVXPY&lt;/h2&gt;

&lt;p&gt;Goulart và Chen (2024) giới thiệu &lt;strong&gt;Clarabel&lt;/strong&gt;, một bộ giải điểm trong mã nguồn mở cho các bài toán tối ưu nón lồi có hàm mục tiêu bậc hai. Thuật toán sử dụng nhúng tự đối ngẫu đồng nhất (homogeneous self-dual embedding) kết hợp vòng lặp điểm trong: hàm chắn logarit (hoặc hàm chắn tự hài hòa tương ứng trên từng nón) giữ các điểm lặp trong phần trong của góc phần tư không âm, nón bậc hai, nón mũ, nón lũy thừa và nón nửa xác định dương (PSD), trong khi hệ phương trình Newton trên phần dư KKT đồng thời giảm sai số khả thi nguyên thủy, khả thi đối ngẫu và độ lệch bù. Clarabel cũng hỗ trợ phân rã chordal cho các bài toán quy hoạch nửa xác định (SDP) cỡ lớn.&lt;/p&gt;

&lt;p&gt;Một thay đổi thực tiễn đáng chú ý là từ phiên bản CVXPY 1.5, Clarabel &lt;em&gt;thay thế ECOS làm bộ giải mặc định&lt;/em&gt; cho các lớp bài toán mà trước đây ECOS đảm nhiệm (ghi chú phát hành CVXPY 1.5; Goulart &amp;amp; Chen, mục cài đặt). Các bài toán quy hoạch bậc hai (QP) thông thường vẫn thường dùng OSQP (dựa trên ADMM, Chương 21), nhưng LP, SOCP và nhiều mô hình nón mũ nay mặc định chạy bằng phương pháp điểm trong kiểu rào chắn. Nhờ đó, các mô hình viết theo &lt;a href=&quot;/contents/vi/chapter05/05_07_Modeling_with_DCP_CVXPY/&quot;&gt;05-07&lt;/a&gt; trực tiếp sử dụng thuật toán Chương 15 ở tầng dưới:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cvxpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Variable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Problem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Minimize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum_squares&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;solver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CLARABEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Kiểm tra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prob.solver_stats&lt;/code&gt; sau khi gọi hàm giải mặc định (khi không chọn OSQP) sẽ cho thấy bài toán đang được giải bằng một phương pháp bám đường trung tâm.&lt;/p&gt;

&lt;h2 id=&quot;tối-ưu-danh-mục-mpc-và-các-bài-toán-qp-nón&quot;&gt;Tối ưu danh mục, MPC và các bài toán QP nón&lt;/h2&gt;

&lt;p&gt;Cùng nhóm bộ giải này được dùng rộng rãi trong tối ưu danh mục trung bình–phương sai có ràng buộc rủi ro, quy hoạch bậc hai cho điều khiển dự báo mô hình (MPC), và các bài toán tối ưu vững cỡ nhỏ dạng nón. Các thí nghiệm số của Clarabel và những phiên bản chạy trên GPU sau này (Chương 17) thường lấy bài toán danh mục và điều khiển làm chuẩn đánh giá vì chúng vừa có hàm chắn tự hài hòa cho phương pháp Newton, vừa có cấu trúc thưa thuận lợi cho việc phân rã hệ KKT. Một bài toán danh mục chỉ-mua-dài kèm ràng buộc sai số bám dạng SOCP thực chất là bài toán đường trung tâm Chương 15 với ma trận Hessian gồm ma trận hiệp phương sai cộng thêm thành phần rào chắn trên đơn hình hoặc nón bậc hai.&lt;/p&gt;

&lt;p&gt;Nguyên tắc thực hành vẫn nhất quán với Boyd &amp;amp; Vandenberghe, Chương 11: không cần tự cài đặt gradient chiếu trên nón khi bộ giải điểm trong đã có sẵn qua một lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solve()&lt;/code&gt;. Các phương pháp tách bậc nhất (như OSQP, SCS) có ưu thế khi cần khởi động ấm ở tần số cao (ví dụ 100 Hz), còn phương pháp chắn và điểm trong nổi trội khi cần độ chính xác cao và số chiều vẫn phù hợp để giải hệ Newton thưa.&lt;/p&gt;

&lt;h2 id=&quot;hàm-chắn-logarit-trong-học-tăng-cường-an-toàn&quot;&gt;Hàm chắn logarit trong học tăng cường an toàn&lt;/h2&gt;

&lt;p&gt;Liu, Ding và Liu (&lt;em&gt;IPO: Interior-Point Policy Optimization under Constraints&lt;/em&gt;, AAAI 2020) áp dụng hàm chắn logarit cho các ràng buộc chi phí trong quá trình quyết định Markov có ràng buộc (CMDP), sau đó tối ưu hàm mục tiêu trơn thu được bằng phương pháp bậc nhất kiểu PPO. Dù không giải bằng phương pháp Newton vì chính sách được tham số hóa bởi mạng nơ-ron, &lt;em&gt;ý tưởng chuyển đổi bài toán&lt;/em&gt; vẫn là Chương 15: ràng buộc bất đẳng thức trở thành số hạng phạt có gradient tiến ra vô cùng ở biên, giúp các bước cập nhật duy trì tính khả thi chặt nếu xuất phát từ chính sách khả thi. Các thư viện như OmniSafe (Ji, Zhou, Zhang, Dai, Pan, Sun, Huang, Geng, Liu, Yang; JMLR 2024) và Safety Gymnasium (Ji et al., NeurIPS 2023 Datasets) tích hợp IPO song song với PPO-Lagrangian, đưa hàm chắn logarit trực tiếp vào quy trình tối ưu chính sách.&lt;/p&gt;

&lt;p&gt;Sự đối chiếu này làm rõ bản chất hai tầng của phương pháp: IPO là phương pháp chắn dùng bộ giải bên trong &lt;em&gt;ngẫu nhiên, bậc nhất&lt;/em&gt;; Clarabel là phương pháp chắn dùng bộ giải bên trong &lt;em&gt;xác định, bậc hai (Newton)&lt;/em&gt;. Khi ràng buộc là nón lồi trên vài trăm đến vài nghìn biến, giải hệ Newton trên hàm chắn là lựa chọn tối ưu; khi biến tối ưu là trọng số mạng nơ-ron sâu, ta giữ lại hàm chắn nhưng bỏ qua ma trận Hessian.&lt;/p&gt;

&lt;h2 id=&quot;các-lớp-tối-ưu-khả-vi-dựa-trên-bộ-giải-điểm-trong&quot;&gt;Các lớp tối ưu khả vi dựa trên bộ giải điểm trong&lt;/h2&gt;

&lt;p&gt;Agrawal, Amos, Barratt, Boyd, Diamond và Kolter (NeurIPS 2019) giới thiệu &lt;strong&gt;cvxpylayers&lt;/strong&gt;, cho phép nhúng một bài toán CVXPY thành một lớp khả vi trong PyTorch hoặc JAX. Ở lượt truyền xuôi (forward pass), hệ thống giải bài toán bằng bộ giải điểm trong hoặc bộ giải nón bậc nhất; ở lượt truyền ngược (backward pass), đạo hàm được tính bằng vi phân ẩn trên hệ điều kiện KKT — sử dụng chính ma trận Jacobian mà phương pháp Newton đã phân rã trong chương này. Giai đoạn 2022–2026, cách tiếp cận này trở thành khuôn mẫu tiêu chuẩn trong MPC khả vi, dự báo có cấu trúc và các kiến trúc “tối ưu như một lớp” (optimization as a layer), giúp tránh phải khai triển ngược qua hàng chục bước gradient chiếu.&lt;/p&gt;

&lt;p&gt;Nói cách khác, hệ phương trình Newton của đường trung tâm không chỉ dùng để tính điểm \(x^\star(t)\), mà còn cung cấp ánh xạ tuyến tính cho phép các hệ thống học sâu lấy đạo hàm trực tiếp qua lời gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solve()&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;P. J. Goulart, Y. Chen, “Clarabel: An interior-point solver for conic programs with quadratic objectives,” 2024. &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv:2405.12762&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Ghi chú phát hành CVXPY 1.5: Clarabel thay ECOS làm mặc định cho các lớp bài từng thuộc ECOS.&lt;/li&gt;
  &lt;li&gt;Y. Liu, J. Ding, X. Liu, “IPO: Interior-Point Policy Optimization under Constraints,” AAAI 2020.&lt;/li&gt;
  &lt;li&gt;J. Ji et al., “OmniSafe: An Infrastructure for Accelerating Safe Reinforcement Learning Research,” JMLR 25(285), 2024; “Safety Gymnasium,” NeurIPS 2023 Datasets.&lt;/li&gt;
  &lt;li&gt;A. Agrawal, B. Amos, S. Barratt, S. Boyd, S. Diamond, J. Z. Kolter, “Differentiable Convex Optimization Layers,” NeurIPS 2019 (cvxpylayers; vẫn là giao diện 2022–2026).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>14-10 Ứng dụng hiện đại của phương pháp Newton (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_10_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_10_modern_applications</id>
   <content type="html">&lt;p&gt;Trong suốt thập kỷ 2010, nhiều người từng tin rằng phương pháp bậc hai đã “nhường sân” hoàn toàn cho SGD và Adam trong học sâu vì không thể lưu nổi ma trận Hessian của mạng có hàng tỷ tham số. Nhưng giai đoạn &lt;strong&gt;2022–2026&lt;/strong&gt; chứng kiến một cuộc trở lại ngoạn mục của tư duy Newton: thay vì tính Hessian đầy đủ \(O(n^2)\), các nhà nghiên cứu thiết kế những xấp xỉ độ cong cực kỳ tinh gọn — từ &lt;strong&gt;Hessian đường chéo có cắt ngưỡng (Sophia)&lt;/strong&gt; cho tiền huấn luyện LLM, &lt;strong&gt;xấp xỉ tích Kronecker (K-FAC)&lt;/strong&gt; cho Transformer/CNN/GNN, đến &lt;strong&gt;Newton–Cholesky&lt;/strong&gt; ngay trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt; cho các mô hình tuyến tính tổng quát.&lt;/p&gt;

&lt;p&gt;Tất cả những thuật toán hiện đại ấy đều bắt nguồn từ đúng một triết lý của Chương 14: chia gradient cho độ cong cục bộ để bước đi tự thích nghi với hình học bài toán, kèm theo một cơ chế giảm chấn hoặc cắt ngưỡng để tránh phân kỳ trên hàm không lồi!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-cách-đưa-độ-cong-bậc-hai-vào-hệ-thống-ai-20222026&quot;&gt;Kiến thức cần nhớ: Ba cách đưa độ cong bậc hai vào hệ thống AI 2022–2026&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sophia (Second-order Clipped Stochastic Optimization):&lt;/strong&gt; Ước lượng đường chéo Hessian bằng bộ ước lượng Hutchinson hoặc Gauss–Newton chỉ mỗi \(k\) bước (phí tổn phụ chưa tới 5%), rồi cập nhật \(x^+ = x - \eta \operatorname{clip}\bigl(m_t / \max(h_t, \epsilon), -1, 1\bigr)\) — cắt ngưỡng đóng vai trò “giảm chấn” chống độ cong âm trên hàm không lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;K-FAC (Kronecker-Factored Approximate Curvature):&lt;/strong&gt; Khai thác cấu trúc tầng của mạng nơ-ron để xấp xỉ khối ma trận Fisher/Gauss–Newton bằng tích Kronecker \(A \otimes G\) của hai ma trận nhỏ (kích thước vào và ra của tầng), biến phép nghịch đảo \((pq \times pq)\) thành hai phép nghịch đảo nhỏ \(A^{-1} \otimes G^{-1}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton–Cholesky trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt;:&lt;/strong&gt; Với các bài toán GLM (hồi quy logistic, Poisson, Gamma) có số mẫu \(N\) rất lớn nhưng số đặc trưng \(p\) vừa phải (\(p \lesssim 10^3\)), lập ma trận Hessian \(p \times p\) và giải bằng phân rã Cholesky hội tụ tới độ chính xác máy tính nhanh gấp nhiều lần L-BFGS hay SAGA.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-một-bước-cập-nhật-kiểu-sophia-hessian-đường-chéo-có-cắt-ngưỡng&quot;&gt;Giải thích: Tính tay một bước cập nhật kiểu Sophia (Hessian đường chéo có cắt ngưỡng)&lt;/h3&gt;

&lt;p&gt;Giả sử tại bước \(t\) của một mạng nơ-ron 2 tham số \((\theta_1, \theta_2)\), ta có ước lượng gradient trung bình trượt \(m_t = (0.4, 0.4)^T\), tốc độ học \(\eta = 0.01\), ngưỡng bảo vệ \(\epsilon = 10^{-4}\), và đường chéo Hessian ước lượng là \(h_t = (10.0, 0.05)^T\) (tham số 1 đang ở vùng cong rất gắt, tham số 2 ở vùng cực phẳng).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính tỷ số Newton đường chéo \(r_i = m_{t,i} / \max(h_{t,i}, \epsilon)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tham số 1 (cong gắt): \(r_1 = \frac{0.4}{10.0} = 0.04\).&lt;/li&gt;
      &lt;li&gt;Tham số 2 (rất phẳng): \(r_2 = \frac{0.4}{0.05} = 8.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng cơ chế cắt ngưỡng (clipping vào \([-1, 1]\)) để tránh bước nhảy quá đà:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\operatorname{clip}(0.04, -1, 1) = 0.04\) (bước nhỏ, thận trọng trên trục cong gắt!).&lt;/li&gt;
      &lt;li&gt;\(\operatorname{clip}(8.0, -1, 1) = 1.0\) (bước lớn nhất cho phép trên trục phẳng, nhưng không bị nổ tung!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật tham số:&lt;/strong&gt;
\(\Delta \theta_1 = -0.01 \times 0.04 = -0.0004, \qquad \Delta \theta_2 = -0.01 \times 1.0 = -0.01.\)
&lt;strong&gt;So sánh với Adam:&lt;/strong&gt; Trong Adam, nếu hai tham số có cùng độ lớn gradient \(0.4\), cả hai đều nhận bước đi gần bằng nhau (\(\approx -0.01\)), làm tham số 1 dao động mạnh trên vách dốc. Sophia nhận ra độ cong \(h_1 = 10.0\) lớn hơn \(h_2 = 0.05\) tới 200 lần, nên tự động hãm phanh ở \(\theta_1\) và tăng tốc ở \(\theta_2\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phương pháp Newton trong chương này dựa trên mô hình bậc hai cục bộ chính xác&lt;/p&gt;

\[x^{+} = x - t\, \bigl(\nabla^2 f(x)\bigr)^{-1}\nabla f(x),\]

&lt;p&gt;đi kèm các khái niệm đại lượng giảm Newton (Newton decrement), tính bất biến affine và tính tự hài hòa. Với các mô hình ngôn ngữ lớn, ma trận Hessian đầy đủ không thể lưu trữ trong bộ nhớ; tuy nhiên, cùng một ý tưởng cốt lõi — tiền điều kiện theo độ cong rồi thực hiện bước cập nhật có giảm chấn — đã giúp một số thuật toán giai đoạn 2022–2026 vượt qua Adam đã tinh chỉnh. Bài này mang tính khảo sát: với mỗi phương pháp dưới đây, hãy chú ý cách người ta xấp xỉ ma trận Hessian (dạng đường chéo hoặc tích Kronecker) và những phần nào được lược bỏ để bước cập nhật vẫn tính được trong thực tế.&lt;/p&gt;

&lt;p&gt;Các trường hợp dưới đây đều là triển khai thực tế hoặc kết quả thực nghiệm đã qua phản biện. Khác với phần giới thiệu ngắn gọn về Sophia ở Chương 26, mục này tập trung làm rõ &lt;em&gt;vì sao&lt;/em&gt; tiền điều kiện kiểu Newton có thể đạt chi phí tính toán thấp hơn dự kiến.&lt;/p&gt;

&lt;h2 id=&quot;sophia-hessian-đường-chéo-cho-tiền-huấn-luyện-mô-hình-ngôn-ngữ&quot;&gt;Sophia: Hessian đường chéo cho tiền huấn luyện mô hình ngôn ngữ&lt;/h2&gt;

&lt;p&gt;Liu, Li, Hall, Liang và Ma (ICLR 2024) đề xuất &lt;strong&gt;Sophia&lt;/strong&gt; (&lt;em&gt;Second-order Clipped Stochastic Optimization&lt;/em&gt;). Bước cập nhật lấy trung bình động hàm mũ của gradient ngẫu nhiên chia cho trung bình động hàm mũ của ước lượng Hessian &lt;em&gt;đường chéo&lt;/em&gt;, sau đó cắt ngưỡng (clip) theo từng tọa độ. Vì ước lượng Hessian chỉ được cập nhật định kỳ sau mỗi vài bước, chi phí trung bình mỗi bước gần tương đương Adam. Bài báo xét hai bộ ước lượng đường chéo Hessian: bộ ước lượng Hutchinson dùng tích Hessian–vector, và bộ ước lượng Gauss–Newton–Bartlett lấy mẫu nhãn từ phân phối dự báo rồi dùng bình phương gradient của hàm mất mát trên mẫu đó — tuy có độ chệch nhưng luôn không âm và rẻ về mặt tính toán.&lt;/p&gt;

&lt;p&gt;Trên các mô hình kiểu GPT có quy mô từ 125 triệu đến 1,5 tỷ tham số, Sophia đạt cùng mức perplexity trên tập kiểm định với khoảng một nửa số bước so với Adam; do chi phí mỗi bước tương đương, tổng chi phí tính toán và thời gian chạy thực tế (wall-clock time) cũng giảm khoảng một nửa. Kết quả lý thuyết (trên một mô hình lồi mạnh đơn giản hóa) cho thấy thời gian hội tụ không còn phụ thuộc mạnh vào số điều kiện khi mỗi tọa độ được chuẩn hóa theo độ cong riêng — tương ứng với trực giác bất biến affine ở &lt;a href=&quot;/contents/vi/chapter14/14_02_02_affine_invariance_of_newton_method/&quot;&gt;14-02-02&lt;/a&gt; thu hẹp về nhóm phép biến đổi đường chéo.&lt;/p&gt;

&lt;p&gt;Cơ chế cắt ngưỡng theo tọa độ đóng vai trò tương tự miền tin cậy (trust region): khi ước lượng Hessian cục bộ đã cũ hoặc không xác định dương, bước Newton thuần túy có thể tăng quá mạnh; việc cắt ngưỡng khôi phục tính ổn định của bước “Newton có giảm chấn” tương tự tìm kiếm đường backtracking. Mã nguồn chính thức: &lt;a href=&quot;https://github.com/Liuhong99/Sophia&quot;&gt;Liuhong99/Sophia&lt;/a&gt;. Ở mức độ khảo sát, trọng tâm là nắm được công thức cập nhật của Sophia và lý do vì sao ma trận Hessian &lt;em&gt;đường chéo&lt;/em&gt; là dạng xấp xỉ còn phù hợp với bộ nhớ GPU khi huấn luyện mô hình hàng tỷ tham số.&lt;/p&gt;

&lt;h2 id=&quot;k-fac-cho-transformer-mạng-tích-chập-và-mạng-đồ-thị&quot;&gt;K-FAC cho transformer, mạng tích chập và mạng đồ thị&lt;/h2&gt;

&lt;p&gt;Kronecker-Factored Approximate Curvature (K-FAC; Martens &amp;amp; Grosse, 2015) xấp xỉ ma trận Fisher / Gauss–Newton tổng quát của từng lớp mạng bằng tích Kronecker — đây là độ cong của hàm mất mát &lt;em&gt;kỳ vọng&lt;/em&gt;, không phải Hessian thô, nhưng lại là đối tượng mà các phương pháp kiểu Newton trong học sâu thực sự nghịch đảo. Eschenhagen, Immer, Turner, Schneider và Hennig (NeurIPS 2023) mở rộng khung K-FAC cho các lớp &lt;em&gt;chia sẻ trọng số&lt;/em&gt; như lớp tích chập, lớp hồi quy, mạng đồ thị (GNN) và transformer. Các tác giả phân biệt &lt;strong&gt;K-FAC-expand&lt;/strong&gt; (tương ứng cách phân rã KFC trước đây) và &lt;strong&gt;K-FAC-reduce&lt;/strong&gt;, chứng minh tính chính xác của từng biến thể trên mạng tuyến tính sâu trong chế độ chia sẻ trọng số tương ứng, đồng thời cho thấy cả hai đạt cùng ngưỡng chất lượng kiểm định trên GNN và Vision Transformer với khoảng 50–75% số bước của phương pháp bậc nhất kèm mức giảm thời gian chạy thực tế tương ứng.&lt;/p&gt;

&lt;p&gt;Đây là dạng phương pháp Newton với phép nghịch đảo có cấu trúc: thuật toán vẫn giải hệ tuyến tính theo ma trận độ cong xấp xỉ, nhưng cấu trúc tích Kronecker thu nhỏ bài toán về kích thước ma trận hiệp phương sai của các giá trị kích hoạt thay vì kích thước toàn bộ ma trận trọng số. Nếu Sophia là xấp xỉ Newton trên đường chéo thì K-FAC là xấp xỉ Newton trên cấu trúc Kronecker. Câu hỏi cốt lõi tương tự phân tích hàm tự hài hòa: &lt;em&gt;ta chấp nhận tính phần độ cong nào và giữ lại tính bất biến nào?&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;newtoncholesky-cho-mô-hình-tuyến-tính-tổng-quát-trong-scikit-learn&quot;&gt;Newton–Cholesky cho mô hình tuyến tính tổng quát trong scikit-learn&lt;/h2&gt;

&lt;p&gt;Ứng dụng hiện đại của phương pháp Newton không chỉ giới hạn ở mô hình ngôn ngữ. Từ phiên bản scikit-learn 1.2 (2022), thư viện bổ sung &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;newton-cholesky&quot;&lt;/code&gt; cho các mô hình tuyến tính tổng quát (GLM) như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PoissonRegressor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GammaRegressor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TweedieRegressor&lt;/code&gt;, và sau đó mở rộng sang hồi quy logistic nhị phân. Bộ giải thực hiện trực tiếp bước Newton–Raphson — tương đương phương pháp bình phương tối thiểu tái trọng số lặp (IRLS) — bằng cách phân rã Cholesky trên ma trận Hessian tường minh. Tài liệu thư viện nêu rõ đây là lựa chọn phù hợp khi số mẫu lớn hơn nhiều so với số đặc trưng (\(n_{\text{mẫu}} \gg n_{\text{đặc trưng}}\), đặc biệt với biến mã hóa one-hot có hạng mục hiếm), trong đó bộ nhớ tăng theo bình phương số đặc trưng do phải lưu tường minh ma trận Hessian.&lt;/p&gt;

&lt;p&gt;Đây là phương pháp Newton chính xác của Chương 14 mà không cần xấp xỉ. Ma trận Hessian IRLS của GLM có dạng ma trận Gram \(X^\top W X\) với ma trận trọng số đường chéo \(W\) phụ thuộc vào giá trị kỳ vọng hiện tại, và phân rã Cholesky cho cách tính ổn định số học khi áp dụng \((\nabla^2 f)^{-1}\). Người học có thể chạy thử trực tiếp&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sklearn.linear_model&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PoissonRegressor&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;PoissonRegressor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;solver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;newton-cholesky&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;và so sánh số vòng lặp với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;lbfgs&quot;&lt;/code&gt;. Khi ma trận thiết kế có nhiều mẫu và ít đặc trưng (dạng cao và hẹp), phương pháp Newton chính xác là một bộ giải thực tế và hiệu quả.&lt;/p&gt;

&lt;h2 id=&quot;điểm-cốt-lõi-cần-ghi-nhớ&quot;&gt;Điểm cốt lõi cần ghi nhớ&lt;/h2&gt;

&lt;p&gt;AdaHessian (Yao, Gholami, Shen, Keutzer, Mahoney, AAAI 2021) là tiền thân trực tiếp của Sophia, kết hợp ước lượng đường chéo Hutchinson với động lượng kiểu Adam. SOAP và Shampoo (Chương 18) mở rộng từ đường chéo sang tiền điều kiện Kronecker hoặc theo cơ sở riêng. Trong khi đó, phương pháp Newton đầy đủ vẫn giữ vai trò trung tâm trong các mô hình tuyến tính tổng quát, phương pháp hạt nhân cỡ vừa, và các bước định tâm của phương pháp chắn cũng như phương pháp nguyên thủy–đối ngẫu ở Chương 15 và 17.&lt;/p&gt;

&lt;p&gt;Có thể tóm gọn tinh thần của tối ưu bậc hai hiện đại trong học máy như sau: thay vì xây dựng tường minh toàn bộ \(\nabla^2 f\) rồi phân rã ở mọi bước, đa số thuật toán ước lượng độ cong theo cấu trúc gọn nhẹ, giảm chấn hoặc cắt ngưỡng bước cập nhật, và phân bổ chi phí ước lượng độ cong qua nhiều vòng lặp. Trường hợp ngoại lệ — bộ giải Newton–Cholesky cho GLM — đồng thời cho thấy rằng khi kích thước đặc trưng đủ nhỏ để lập Hessian trực tiếp, phương pháp Newton chính xác vẫn hiệu quả hơn các phương pháp bậc nhất.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;H. Liu, Z. Li, D. Hall, P. Liang, T. Ma, “Sophia: A Scalable Stochastic Second-order Optimizer for Language Model Pre-training,” ICLR 2024. &lt;a href=&quot;https://arxiv.org/abs/2305.14342&quot;&gt;arXiv:2305.14342&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;R. Eschenhagen, A. Immer, R. Turner, F. Schneider, P. Hennig, “Kronecker-Factored Approximate Curvature for Modern Neural Network Architectures,” NeurIPS 2023.&lt;/li&gt;
  &lt;li&gt;Z. Yao, A. Gholami, S. Shen, K. Keutzer, M. W. Mahoney, “ADAHESSIAN: An Adaptive Second Order Optimizer for Machine Learning,” AAAI 2021.&lt;/li&gt;
  &lt;li&gt;Ghi chú phát hành scikit-learn 1.2 và tài liệu bộ giải &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newton-cholesky&lt;/code&gt; (2022–); PR GLM &lt;a href=&quot;https://github.com/scikit-learn/scikit-learn/pull/24637&quot;&gt;#24637&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>13-10 Cách dùng hiện đại của liên hợp, chuẩn đối ngẫu và nón đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_10_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_10_modern_applications</id>
   <content type="html">&lt;p&gt;Khi một mô hình tối ưu lồi hiện đại (như CVXPY gọi bộ giải Clarabel hay SCS) trả về nghiệm trong vài mili-giây, điều gì thực sự diễn ra bên dưới nắp ca-pô? Thay vì viết một thuật toán riêng cho từng bài toán, các bộ giải nón hiện đại quy toàn bộ về một cặp bài toán nguyên thủy – đối ngẫu trên tích các nón tự đối ngẫu, nơi &lt;strong&gt;hàm liên hợp&lt;/strong&gt;, &lt;strong&gt;toán tử gần kề (proximal operator)&lt;/strong&gt; và &lt;strong&gt;nón đối ngẫu&lt;/strong&gt; phối hợp nhịp nhàng.&lt;/p&gt;

&lt;p&gt;Bài đọc mở rộng này giúp bạn nhìn xuyên qua lớp vỏ thư viện để thấy cách bốn công cụ của Chương 13 (chuẩn đối ngẫu, đối ngẫu Lasso, phân rã Moreau qua hàm liên hợp và nón đối ngẫu) trở thành nền tảng cho cả bộ giải tối ưu công nghiệp lẫn hệ thống kiểm chứng an toàn AI giai đoạn 2022–2026.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hệ-sinh-thái-thuật-toán-dựa-trên-đối-ngẫu-hiện-đại&quot;&gt;Kiến thức cần nhớ: Hệ sinh thái thuật toán dựa trên đối ngẫu hiện đại&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phép chiếu nón và phân rã Moreau:&lt;/strong&gt; Mọi vectơ \(v\) đều phân tách trực giao duy nhất thành hình chiếu lên nón \(K\) và hình chiếu lên nón cực \(-K^*\): \(v = \Pi_K(v) + \Pi_{-K^*}(v)\). Đây là trái tim của các bộ giải tách toán tử như ADMM và SCS.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chứng chỉ đối ngẫu cho tính khả thi và tối ưu:&lt;/strong&gt; Các bộ giải nón hiện đại không chỉ xuất ra nghiệm \(x^\star\) mà còn xuất ra biến đối ngẫu \(y^\star, s^\star \in K^*\) để chứng minh tính tối ưu (duality gap \(\approx 0\)) hoặc chứng minh bài toán vô nghiệm (chứng chỉ Farkas tổng quát).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biên an toàn trong kiểm chứng mạng nơ-ron:&lt;/strong&gt; Khi nới lỏng hàm kích hoạt phi tuyến ReLU thành bao lồi, việc cực đại hóa hàm đối ngẫu tạo ra chặn dưới hợp lệ cho biên phân loại ngay cả khi chưa chạy đến hội tụ hoàn toàn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sàng lọc đặc trưng bằng quả cầu an toàn (Gap Safe Screening):&lt;/strong&gt; Từ khoảng cách đối ngẫu tại vòng lặp \(k\), ta dựng được một quả cầu chắc chắn chứa \(u^\star\) để loại sớm các biến Lasso bằng \(0\) mà không hề đánh mất tính chính xác toàn cục.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tay-đồng-nhất-thức-moreau-cho-chuẩn-ell_1-và-liên-hợp-ell_infty&quot;&gt;Giải thích: Kiểm chứng tay đồng nhất thức Moreau cho chuẩn \(\ell_1\) và liên hợp \(\ell_\infty\)&lt;/h3&gt;

&lt;p&gt;Xét hàm không trơn \(f(x) = \|x\|_1\) trên \(\mathbb{R}^2\) và hàm liên hợp của nó \(f^*(y) = I_{\{\|y\|_\infty \le 1\}}(y)\). Đồng nhất thức Moreau khẳng định với mọi \(v \in \mathbb{R}^2\):&lt;/p&gt;

\[\operatorname{prox}_f(v) + \operatorname{prox}_{f^*}(v) = v.\]

&lt;p&gt;Hãy kiểm chứng trực tiếp bằng tay với điểm \(v = (2.5, -0.4)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(\operatorname{prox}_{f^*}(v)\) (phép chiếu Euclid lên khối hộp \([-1, 1]^2\)):&lt;/strong&gt;
Với mỗi tọa độ, ta kẹp giá trị vào đoạn \([-1, 1]\):
\(\operatorname{prox}_{f^*}(v) = \Pi_{[-1, 1]^2}\begin{bmatrix} 2.5 \\ -0.4 \end{bmatrix} = \begin{bmatrix} 1.0 \\ -0.4 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suy ra \(\operatorname{prox}_f(v)\) bằng phép trừ đơn giản (không cần giải tối ưu lại!):&lt;/strong&gt;
\(\operatorname{prox}_f(v) = v - \operatorname{prox}_{f^*}(v) = \begin{bmatrix} 2.5 \\ -0.4 \end{bmatrix} - \begin{bmatrix} 1.0 \\ -0.4 \end{bmatrix} = \begin{bmatrix} 1.5 \\ 0.0 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối chiếu trực tiếp với định nghĩa ngưỡng mềm (Soft-Thresholding):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tọa độ 1: \(\operatorname{sign}(2.5)\max(\vert 2.5\vert - 1, 0) = +1.5\).&lt;/li&gt;
      &lt;li&gt;Tọa độ 2: \(\operatorname{sign}(-0.4)\max(\vert -0.4\vert - 1, 0) = 0.0\).
Kết quả trùng khớp hoàn toàn! Trong thực tế, kỹ thuật này cho phép tính nhanh toán tử prox của bất kỳ chuẩn phức tạp nào (như Group Lasso hay chuẩn vết) chỉ bằng cách chiếu lên quả cầu chuẩn đối ngẫu.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;cách-dùng-hiện-đại-của-liên-hợp-chuẩn-đối-ngẫu-và-nón-đối-ngẫu&quot;&gt;Cách dùng hiện đại của liên hợp, chuẩn đối ngẫu và nón đối ngẫu&lt;/h1&gt;

&lt;p&gt;Chương 13 tập trung vào các ứng dụng của lý thuyết đối ngẫu: giải bài toán nguyên thủy thông qua đối ngẫu, chuẩn đối ngẫu, hàm liên hợp, đối ngẫu Lasso và nón đối ngẫu. Bài đọc tùy chọn này gắn các ứng dụng trong khoa học máy tính giai đoạn 2022–2026 vào đúng các cặp tương ứng đó, mà không trình bày lại định nghĩa của \(f^*\) hay \(\|y\|_*\).&lt;/p&gt;

&lt;h2 id=&quot;1-chuẩn-đối-ngẫu-và-quả-cầu-nhiễu-đối-kháng-ell_p&quot;&gt;1. Chuẩn đối ngẫu và quả cầu nhiễu đối kháng \(\ell_p\)&lt;/h2&gt;

&lt;p&gt;Hàm hỗ trợ của quả cầu tấn công \(\ell_p\) bán kính \(\varepsilon\) là \(\varepsilon\|g\|_*\), trong đó \(\|\cdot\|_*\) là chuẩn đối ngẫu của \(\|\cdot\|_p\):&lt;/p&gt;

\[\|g\|_\infty=\sup_{\|v\|_1\le 1}g^\top v,\qquad
\|g\|_2=\sup_{\|v\|_2\le 1}g^\top v,\qquad
\|g\|_1=\sup_{\|v\|_\infty\le 1}g^\top v.\]

&lt;p&gt;Các phương pháp tấn công như FGSM và PGD tuyến tính hóa hàm mất mát rồi dịch chuyển một bước độ dài \(\varepsilon\) theo hướng cực đại hóa tích vô hướng tương ứng với chuẩn đối ngẫu (lấy dấu của gradient cho tấn công \(\ell_\infty\), chuẩn hóa theo \(\ell_2\) cho tấn công \(\ell_2\)). AutoAttack (Croce và Hein, 2020) và bảng chuẩn &lt;strong&gt;RobustBench&lt;/strong&gt; (Croce và cộng sự, 2021; duy trì đến 2025) đã chuẩn hóa quy trình đánh giá cho hai cặp đối ngẫu này trên các mô hình quy mô CIFAR và ImageNet. Khi một bài báo báo cáo “độ chính xác bền vững dưới nhiễu \(\ell_\infty\) mức 0,03”, hình học tấn công được chọn chính là quả cầu ứng với chuẩn đối ngẫu của \(\|\cdot\|_1\) — tức nội dung mục &lt;a href=&quot;/contents/vi/chapter13/13_03_Dual_norms/&quot;&gt;13-03 Chuẩn đối ngẫu&lt;/a&gt; đặt trong ngữ cảnh mô hình mối đe dọa.&lt;/p&gt;

&lt;p&gt;Độ bền vững được chứng nhận (certified robustness) còn đi xa hơn: một bài toán LP hoặc SDP đối ngẫu (Chương 10 và phần nón đối ngẫu dưới đây) giúp &lt;em&gt;chứng minh&lt;/em&gt; rằng không có nhiễu nào trong quả cầu bán kính \(\varepsilon\) có thể làm đổi nhãn dự đoán.&lt;/p&gt;

&lt;h2 id=&quot;2-đối-ngẫu-lasso-như-chứng-chỉ-sàng-lọc-đặc-trưng&quot;&gt;2. Đối ngẫu Lasso như chứng chỉ sàng lọc đặc trưng&lt;/h2&gt;

&lt;p&gt;Bài toán đối ngẫu Lasso trong mục &lt;a href=&quot;/contents/vi/chapter13/13_04_01_Example_lasso_dual/&quot;&gt;13-04-01&lt;/a&gt; có dạng bài toán chiếu lên đa diện \(\|X^\top\theta\|_\infty\le\lambda\). Khoảng cách đối ngẫu \(P(\beta)-D(\theta)\) là một &lt;strong&gt;chứng chỉ tính toán được trực tiếp&lt;/strong&gt;. Kỹ thuật sàng lọc an toàn theo khoảng cách đối ngẫu (gap safe screening — Ndiaye, Fercoq, Gramfort, Salmon) loại bỏ sớm các đặc trưng có tích vô hướng với điểm khả thi đối ngẫu \(\theta\) chắc chắn không thể đạt ngưỡng \(\lambda\). Bertrand, Klopfenstein, Bannier, Gidel và Massias (NeurIPS 2022) tích hợp kỹ thuật tập làm việc (working set) cùng các kiểm định đối ngẫu này vào thư viện &lt;strong&gt;skglm&lt;/strong&gt;, giúp huấn luyện các mô hình tuyến tính tổng quát (GLM) thưa với hàng triệu biến. Guha, Ndiaye và Huo (ICML 2023) tái sử dụng quỹ đạo đối ngẫu (homotopy) để xây dựng tập dự đoán conformal. Ở mọi trường hợp này, việc giải hoặc theo dõi bài toán đối ngẫu đều nhằm giải bài toán gốc nhanh hơn — đúng tinh thần của mục &lt;a href=&quot;/contents/vi/chapter13/13_02_Solving_the_primal_via_the_dual/&quot;&gt;13-02&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;3-hàm-liên-hợp-toán-tử-prox-và-các-bộ-giải-nón-trong-thực-tế&quot;&gt;3. Hàm liên hợp, toán tử prox và các bộ giải nón trong thực tế&lt;/h2&gt;

&lt;p&gt;Đẳng thức Moreau \(\operatorname{prox}_f(v)+\operatorname{prox}_{f^\star}(v)=v\) là cơ sở để các bộ giải quy hoạch nón bậc nhất hiện đại cài đặt phép chiếu. Các bộ giải như OSQP, SCS và &lt;strong&gt;Clarabel&lt;/strong&gt; (Goulart và Chen, 2024) nhận bài toán ở dạng cặp nón nguyên thủy–đối ngẫu và chạy vòng lặp ADMM hoặc phương pháp điểm trong, trong đó bước tốn chi phí chính là tính toán tử prox hoặc đánh giá phần dư liên hợp. Quy trình chuẩn hóa (canonicalization) của CVXPY (đã giới thiệu ở Chương 05) chuyển đổi mô hình người dùng viết sang ngôn ngữ nón này; chẳng hạn, khi viết &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.norm1(x)&lt;/code&gt;, hệ thống thực chất đang sử dụng mối liên hệ liên hợp với hàm chỉ thị của quả cầu \(\ell_\infty\).&lt;/p&gt;

&lt;h2 id=&quot;4-nón-đối-ngẫu-và-chứng-chỉ-kiểm-chứng-mạng-nơ-ron&quot;&gt;4. Nón đối ngẫu và chứng chỉ kiểm chứng mạng nơ-ron&lt;/h2&gt;

&lt;p&gt;Điều kiện thuộc nón đối ngẫu \(z\in K^*\) chính là bất đẳng thức chuyển bài toán quy hoạch nón nguyên thủy thành một cận chứng nhận được. Các phép nới lỏng LP và SDP cho mạng ReLU là những bài toán quy hoạch nón; bài toán đối ngẫu của chúng tương ứng với các phiếm hàm lan truyền cận trong &lt;strong&gt;\(\alpha,\beta\)-CROWN&lt;/strong&gt; và bài toán đối ngẫu mặt cắt trong &lt;strong&gt;GCP-CROWN&lt;/strong&gt; (Zhang và cộng sự, NeurIPS 2022). Dưới góc nhìn của chương này, việc dẫn đầu cuộc thi kiểm chứng mạng nơ-ron VNN-COMP giai đoạn 2021–2025 thực chất là tạo ra được các chứng chỉ khả thi đối ngẫu trên nón đủ nhanh bằng GPU. Như vậy, nón đối ngẫu không chỉ là khái niệm đại số thuần túy mà đóng vai trò trực tiếp như cấu trúc của chứng chỉ kiểm chứng.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Đối tượng Chương 13&lt;/th&gt;
      &lt;th&gt;Ứng dụng giai đoạn 2022–2026&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Chuẩn đối ngẫu \(|g|_*\)&lt;/td&gt;
      &lt;td&gt;Bước tấn công đối kháng \(\ell_p\) và RobustBench&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đối ngẫu và khoảng cách đối ngẫu Lasso&lt;/td&gt;
      &lt;td&gt;Sàng lọc đặc trưng trong skglm và GLM thưa conformal&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hàm liên hợp \(f^\star\) và đẳng thức Moreau&lt;/td&gt;
      &lt;td&gt;Toán tử prox trong OSQP, SCS, Clarabel và CVXPY&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Nón đối ngẫu \(K^*\)&lt;/td&gt;
      &lt;td&gt;Chứng chỉ LP/SDP trong kiểm chứng mạng nơ-ron&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi gợi mở:&lt;/strong&gt; Vì sao đối ngẫu của thành phần điều chuẩn \(\ell_1\) là ràng buộc chuẩn \(\ell_\infty\), và mối liên hệ này đồng thời giải thích cả quy tắc sàng lọc đặc trưng trong Lasso lẫn bước tấn công lấy dấu FGSM như thế nào?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Croce, F., &amp;amp; Hein, M. (2020). Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Croce, F., et al. (2021). RobustBench: A standardized adversarial robustness benchmark. &lt;em&gt;NeurIPS Datasets and Benchmarks&lt;/em&gt;. &lt;a href=&quot;https://robustbench.github.io/&quot;&gt;https://robustbench.github.io/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bertrand, Q., Klopfenstein, Q., Bannier, P.-A., Gidel, G., &amp;amp; Massias, M. (2022). Beyond L1: Faster and better sparse models with skglm. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Guha, E. K., Ndiaye, E., &amp;amp; Huo, X. (2023). Conformalization of sparse generalized linear models. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Goulart, P. J., &amp;amp; Chen, Y. (2024). Clarabel: An interior-point solver for conic programs with quadratic objectives. &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv:2405.12762&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Zhang, H., Wang, S., Xu, K., Li, L., Li, B., Jana, S., Hsieh, C.-J., &amp;amp; Kolter, J. Z. (2022). General cutting planes for bound-propagation-based neural network verification. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Parikh, N., &amp;amp; Boyd, S. (2014). Proximal algorithms. &lt;em&gt;Foundations and Trends in Optimization&lt;/em&gt;, 1(3). (trình bày đẳng thức Moreau mà các bộ giải trên sử dụng)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>13-07 Cách dùng hiện đại của liên hợp, chuẩn đối ngẫu và nón đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_07_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_07_modern_applications</id>
   <content type="html">&lt;p&gt;Nhiều người học xong lý thuyết đối ngẫu ở bậc đại học vẫn tự hỏi: những công thức như chuẩn đối ngẫu \(\|y\|_*\), hàm liên hợp \(f^*\) hay nón đối ngẫu \(K^*\) liệu có chỉ nằm trên bảng đen hay thực sự đang chạy bên trong các hệ thống AI hiện đại? Câu trả lời của giai đoạn 2022–2026 là một lời khẳng định vang dội: chúng chính là động cơ toán học đứng sau &lt;strong&gt;phòng thủ tấn công đối kháng (adversarial robustness)&lt;/strong&gt;, &lt;strong&gt;sàng lọc đặc trưng siêu tốc&lt;/strong&gt;, các &lt;strong&gt;bộ giải nón thế hệ mới&lt;/strong&gt; và &lt;strong&gt;kiểm chứng an toàn mạng nơ-ron&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Khi một kẻ tấn công nhiễu từng pixel ảnh trong quả cầu \(\ell_\infty\) bán kính \(\epsilon\), hướng tấn công nguy hiểm nhất không còn là gradient thuần túy mà là vectơ đạt cực đại trong định nghĩa &lt;strong&gt;chuẩn đối ngẫu \(\ell_1\)&lt;/strong&gt;. Bài đọc chuyên sâu này nối thẳng các khái niệm vừa học trong Chương 13 với những bài toán mũi nhọn nhất của khoa học máy tính ngày nay.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mũi-nhọn-ứng-dụng-của-đối-ngẫu-trong-ai-hiện-đại&quot;&gt;Kiến thức cần nhớ: Bốn mũi nhọn ứng dụng của đối ngẫu trong AI hiện đại&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn đối ngẫu và tấn công đối kháng \(\ell_p\):&lt;/strong&gt; Xấp xỉ bậc nhất mức tăng hàm mất mát dưới nhiễu \(\|\delta\|_p \le \epsilon\) là \(\max_{\|\delta\|_p \le \epsilon} \nabla \ell(x)^T \delta = \epsilon \|\nabla \ell(x)\|_q\) — biến chuẩn đối ngẫu thành công cụ định lượng trực tiếp độ nhạy của mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu Lasso và sàng lọc an toàn (Safe Screening):&lt;/strong&gt; Nghiệm đối ngẫu \(u\) cho phép kiểm tra điều kiện \(\vert X_j^T u \vert &amp;lt; \lambda\) để loại bỏ chắc chắn các đặc trưng có \(\beta_j^\star = 0\) ngay giữa quá trình lặp, tăng tốc huấn luyện trên dữ liệu hàng triệu chiều.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm liên hợp và phân rã Moreau:&lt;/strong&gt; Đồng nhất thức \(\operatorname{prox}_{f}(v) + \operatorname{prox}_{f^*}(v) = v\) cho phép tính toán tử gần kề của một hàm khó thông qua phép chiếu đơn giản lên tập liên hợp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nón đối ngẫu và kiểm chứng mạng nơ-ron:&lt;/strong&gt; Các bộ kiểm chứng như \(\alpha,\beta\)-CROWN dùng biến đối ngẫu không âm (hoặc thuộc nón đối ngẫu) để tạo ra chứng chỉ toán học khẳng định mạng không bao giờ phân loại sai trong vùng nhiễu cho trước.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-nhiễu-đối-kháng-tối-ưu-ell_infty-và-ell_2-bằng-chuẩn-đối-ngẫu&quot;&gt;Giải thích: Tính tay nhiễu đối kháng tối ưu \(\ell_\infty\) và \(\ell_2\) bằng chuẩn đối ngẫu&lt;/h3&gt;

&lt;p&gt;Giả sử tại một ảnh đầu vào \(x \in \mathbb{R}^3\), gradient của hàm mất mát theo đầu vào là \(g = \nabla_x \ell(x) = (0.8, -0.6, 0.2)^T\), và kẻ tấn công được phép cộng nhiễu \(\delta\) với ngân sách \(\epsilon = 0.1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tấn công dưới ràng buộc \(\|\delta\|_\infty \le 0.1\) (kiểu FGSM):&lt;/strong&gt;
Ta cần \(\max_{\|\delta\|_\infty \le 0.1} g^T \delta = 0.1 \|g\|_1\).
    &lt;ul&gt;
      &lt;li&gt;Nhiễu tối ưu lấy dấu của từng thành phần gradient: \(\delta^\star_{\ell_\infty} = 0.1 \cdot \operatorname{sign}(g) = (0.1, -0.1, 0.1)^T\).&lt;/li&gt;
      &lt;li&gt;Mức tăng hàm mất mát bậc nhất: \(g^T \delta^\star_{\ell_\infty} = 0.1(\vert 0.8\vert + \vert -0.6\vert + \vert 0.2\vert) = 0.1 \times 1.6 = 0.16\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tấn công dưới ràng buộc \(\|\delta\|_2 \le 0.1\):&lt;/strong&gt;
Ta cần \(\max_{\|\delta\|_2 \le 0.1} g^T \delta = 0.1 \|g\|_2\).
    &lt;ul&gt;
      &lt;li&gt;Tính chuẩn Euclid: \(\|g\|_2 = \sqrt{0.64 + 0.36 + 0.04} = \sqrt{1.04} \approx 1.0198\).&lt;/li&gt;
      &lt;li&gt;Nhiễu tối ưu cùng hướng với \(g\): \(\delta^\star_{\ell_2} = 0.1 \frac{g}{\|g\|_2} \approx (0.0784, -0.0588, 0.0196)^T\).&lt;/li&gt;
      &lt;li&gt;Mức tăng hàm mất mát bậc nhất: \(0.1 \times 1.0198 \approx 0.1020\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa thiết kế:&lt;/strong&gt; Cùng một ngân sách \(\epsilon = 0.1\), quả cầu \(\ell_\infty\) rộng hơn quả cầu \(\ell_2\) nên cho phép mức tăng mất mát lớn hơn (\(0.16 &amp;gt; 0.102\)), và muốn phòng thủ theo chuẩn \(\ell_\infty\) thì ta cần ép &lt;strong&gt;chuẩn đối ngẫu \(\ell_1\) của gradient&lt;/strong&gt; nhỏ xuống!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;cách-dùng-hiện-đại-của-liên-hợp-chuẩn-đối-ngẫu-và-nón-đối-ngẫu&quot;&gt;Cách dùng hiện đại của liên hợp, chuẩn đối ngẫu và nón đối ngẫu&lt;/h1&gt;

&lt;p&gt;Chương 13 tập trung vào các ứng dụng của lý thuyết đối ngẫu: giải bài toán nguyên thủy thông qua đối ngẫu, chuẩn đối ngẫu, hàm liên hợp, đối ngẫu Lasso và nón đối ngẫu. Bài đọc tùy chọn này gắn các ứng dụng trong khoa học máy tính giai đoạn 2022–2026 vào đúng các cặp tương ứng đó, mà không trình bày lại định nghĩa của \(f^*\) hay \(\|y\|_*\).&lt;/p&gt;

&lt;h2 id=&quot;1-chuẩn-đối-ngẫu-và-quả-cầu-nhiễu-đối-kháng-ell_p&quot;&gt;1. Chuẩn đối ngẫu và quả cầu nhiễu đối kháng \(\ell_p\)&lt;/h2&gt;

&lt;p&gt;Hàm hỗ trợ của quả cầu tấn công \(\ell_p\) bán kính \(\varepsilon\) là \(\varepsilon\|g\|_*\), trong đó \(\|\cdot\|_*\) là chuẩn đối ngẫu của \(\|\cdot\|_p\):&lt;/p&gt;

\[\|g\|_\infty=\sup_{\|v\|_1\le 1}g^\top v,\qquad
\|g\|_2=\sup_{\|v\|_2\le 1}g^\top v,\qquad
\|g\|_1=\sup_{\|v\|_\infty\le 1}g^\top v.\]

&lt;p&gt;Các phương pháp tấn công như FGSM và PGD tuyến tính hóa hàm mất mát rồi dịch chuyển một bước độ dài \(\varepsilon\) theo hướng cực đại hóa tích vô hướng tương ứng với chuẩn đối ngẫu (lấy dấu của gradient cho tấn công \(\ell_\infty\), chuẩn hóa theo \(\ell_2\) cho tấn công \(\ell_2\)). AutoAttack (Croce và Hein, 2020) và bảng chuẩn &lt;strong&gt;RobustBench&lt;/strong&gt; (Croce và cộng sự, 2021; duy trì đến 2025) đã chuẩn hóa quy trình đánh giá cho hai cặp đối ngẫu này trên các mô hình quy mô CIFAR và ImageNet. Khi một bài báo báo cáo “độ chính xác bền vững dưới nhiễu \(\ell_\infty\) mức 0,03”, hình học tấn công được chọn chính là quả cầu ứng với chuẩn đối ngẫu của \(\|\cdot\|_1\) — tức nội dung mục &lt;a href=&quot;/contents/vi/chapter13/13_03_Dual_norms/&quot;&gt;13-03 Chuẩn đối ngẫu&lt;/a&gt; đặt trong ngữ cảnh mô hình mối đe dọa.&lt;/p&gt;

&lt;p&gt;Độ bền vững được chứng nhận (certified robustness) còn đi xa hơn: một bài toán LP hoặc SDP đối ngẫu (Chương 10 và phần nón đối ngẫu dưới đây) giúp &lt;em&gt;chứng minh&lt;/em&gt; rằng không có nhiễu nào trong quả cầu bán kính \(\varepsilon\) có thể làm đổi nhãn dự đoán.&lt;/p&gt;

&lt;h2 id=&quot;2-đối-ngẫu-lasso-như-chứng-chỉ-sàng-lọc-đặc-trưng&quot;&gt;2. Đối ngẫu Lasso như chứng chỉ sàng lọc đặc trưng&lt;/h2&gt;

&lt;p&gt;Bài toán đối ngẫu Lasso trong mục &lt;a href=&quot;/contents/vi/chapter13/13_04_01_Example_lasso_dual/&quot;&gt;13-04-01&lt;/a&gt; có dạng bài toán chiếu lên đa diện \(\|X^\top\theta\|_\infty\le\lambda\). Khoảng cách đối ngẫu \(P(\beta)-D(\theta)\) là một &lt;strong&gt;chứng chỉ tính toán được trực tiếp&lt;/strong&gt;. Kỹ thuật sàng lọc an toàn theo khoảng cách đối ngẫu (gap safe screening — Ndiaye, Fercoq, Gramfort, Salmon) loại bỏ sớm các đặc trưng có tích vô hướng với điểm khả thi đối ngẫu \(\theta\) chắc chắn không thể đạt ngưỡng \(\lambda\). Bertrand, Klopfenstein, Bannier, Gidel và Massias (NeurIPS 2022) tích hợp kỹ thuật tập làm việc (working set) cùng các kiểm định đối ngẫu này vào thư viện &lt;strong&gt;skglm&lt;/strong&gt;, giúp huấn luyện các mô hình tuyến tính tổng quát (GLM) thưa với hàng triệu biến. Guha, Ndiaye và Huo (ICML 2023) tái sử dụng quỹ đạo đối ngẫu (homotopy) để xây dựng tập dự đoán conformal. Ở mọi trường hợp này, việc giải hoặc theo dõi bài toán đối ngẫu đều nhằm giải bài toán gốc nhanh hơn — đúng tinh thần của mục &lt;a href=&quot;/contents/vi/chapter13/13_02_Solving_the_primal_via_the_dual/&quot;&gt;13-02&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;3-hàm-liên-hợp-toán-tử-prox-và-các-bộ-giải-nón-trong-thực-tế&quot;&gt;3. Hàm liên hợp, toán tử prox và các bộ giải nón trong thực tế&lt;/h2&gt;

&lt;p&gt;Đẳng thức Moreau \(\operatorname{prox}_f(v)+\operatorname{prox}_{f^\star}(v)=v\) là cơ sở để các bộ giải quy hoạch nón bậc nhất hiện đại cài đặt phép chiếu. Các bộ giải như OSQP, SCS và &lt;strong&gt;Clarabel&lt;/strong&gt; (Goulart và Chen, 2024) nhận bài toán ở dạng cặp nón nguyên thủy–đối ngẫu và chạy vòng lặp ADMM hoặc phương pháp điểm trong, trong đó bước tốn chi phí chính là tính toán tử prox hoặc đánh giá phần dư liên hợp. Quy trình chuẩn hóa (canonicalization) của CVXPY (đã giới thiệu ở Chương 05) chuyển đổi mô hình người dùng viết sang ngôn ngữ nón này; chẳng hạn, khi viết &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.norm1(x)&lt;/code&gt;, hệ thống thực chất đang sử dụng mối liên hệ liên hợp với hàm chỉ thị của quả cầu \(\ell_\infty\).&lt;/p&gt;

&lt;h2 id=&quot;4-nón-đối-ngẫu-và-chứng-chỉ-kiểm-chứng-mạng-nơ-ron&quot;&gt;4. Nón đối ngẫu và chứng chỉ kiểm chứng mạng nơ-ron&lt;/h2&gt;

&lt;p&gt;Điều kiện thuộc nón đối ngẫu \(z\in K^*\) chính là bất đẳng thức chuyển bài toán quy hoạch nón nguyên thủy thành một cận chứng nhận được. Các phép nới lỏng LP và SDP cho mạng ReLU là những bài toán quy hoạch nón; bài toán đối ngẫu của chúng tương ứng với các phiếm hàm lan truyền cận trong &lt;strong&gt;\(\alpha,\beta\)-CROWN&lt;/strong&gt; và bài toán đối ngẫu mặt cắt trong &lt;strong&gt;GCP-CROWN&lt;/strong&gt; (Zhang và cộng sự, NeurIPS 2022). Dưới góc nhìn của chương này, việc dẫn đầu cuộc thi kiểm chứng mạng nơ-ron VNN-COMP giai đoạn 2021–2025 thực chất là tạo ra được các chứng chỉ khả thi đối ngẫu trên nón đủ nhanh bằng GPU. Như vậy, nón đối ngẫu không chỉ là khái niệm đại số thuần túy mà đóng vai trò trực tiếp như cấu trúc của chứng chỉ kiểm chứng.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Đối tượng Chương 13&lt;/th&gt;
      &lt;th&gt;Ứng dụng giai đoạn 2022–2026&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Chuẩn đối ngẫu \(|g|_*\)&lt;/td&gt;
      &lt;td&gt;Bước tấn công đối kháng \(\ell_p\) và RobustBench&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đối ngẫu và khoảng cách đối ngẫu Lasso&lt;/td&gt;
      &lt;td&gt;Sàng lọc đặc trưng trong skglm và GLM thưa conformal&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hàm liên hợp \(f^\star\) và đẳng thức Moreau&lt;/td&gt;
      &lt;td&gt;Toán tử prox trong OSQP, SCS, Clarabel và CVXPY&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Nón đối ngẫu \(K^*\)&lt;/td&gt;
      &lt;td&gt;Chứng chỉ LP/SDP trong kiểm chứng mạng nơ-ron&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi gợi mở:&lt;/strong&gt; Vì sao đối ngẫu của thành phần điều chuẩn \(\ell_1\) là ràng buộc chuẩn \(\ell_\infty\), và mối liên hệ này đồng thời giải thích cả quy tắc sàng lọc đặc trưng trong Lasso lẫn bước tấn công lấy dấu FGSM như thế nào?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Croce, F., &amp;amp; Hein, M. (2020). Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Croce, F., et al. (2021). RobustBench: A standardized adversarial robustness benchmark. &lt;em&gt;NeurIPS Datasets and Benchmarks&lt;/em&gt;. &lt;a href=&quot;https://robustbench.github.io/&quot;&gt;https://robustbench.github.io/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bertrand, Q., Klopfenstein, Q., Bannier, P.-A., Gidel, G., &amp;amp; Massias, M. (2022). Beyond L1: Faster and better sparse models with skglm. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Guha, E. K., Ndiaye, E., &amp;amp; Huo, X. (2023). Conformalization of sparse generalized linear models. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Goulart, P. J., &amp;amp; Chen, Y. (2024). Clarabel: An interior-point solver for conic programs with quadratic objectives. &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv:2405.12762&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Zhang, H., Wang, S., Xu, K., Li, L., Li, B., Jana, S., Hsieh, C.-J., &amp;amp; Kolter, J. Z. (2022). General cutting planes for bound-propagation-based neural network verification. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Parikh, N., &amp;amp; Boyd, S. (2014). Proximal algorithms. &lt;em&gt;Foundations and Trends in Optimization&lt;/em&gt;, 1(3). (trình bày đẳng thức Moreau mà các bộ giải trên sử dụng)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>12-10 Ứng dụng hiện đại của điều kiện KKT</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_10_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_10_modern_applications</id>
   <content type="html">&lt;p&gt;Trong kỹ thuật hệ thống năng lượng và kinh tế học hiện đại, một trong những minh chứng rõ rệt nhất về sức mạnh thực tiễn của &lt;strong&gt;điều kiện bù KKT&lt;/strong&gt; là hiện tượng &lt;em&gt;tách giá điện theo vùng địa lý&lt;/em&gt; (Locational Marginal Pricing — LMP). Tại sao điện sản xuất ở một tỉnh gió nắng dồi dào có thể chỉ tốn 20 USD/MWh, nhưng cách đó vài trăm km tại trung tâm đô thị, giá điện bán buôn cùng thời điểm lại vọt lên 60 USD/MWh?&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Câu trả lời nằm gọn trong một dấu bất đẳng thức: &lt;strong&gt;đường dây truyền tải nối hai vùng đã chạm trần công suất tối đa&lt;/strong&gt;! Khi ràng buộc công suất đường dây còn lỏng ($$&lt;/td&gt;
      &lt;td&gt;f&lt;/td&gt;
      &lt;td&gt;&amp;lt; F_{\max}\(), điều kiện bù KKT ép nhân tử nghẽn\)\mu^* = 0\(và giá điện ở hai vùng bằng hệt nhau; nhưng ngay giây phút dòng điện chạm trần\)f = F_{\max}\(, nhân tử KKT\)\mu^&lt;em&gt;\(bật dương và chênh lệch giá giữa hai vùng bằng **chính xác\)\mu^&lt;/em&gt;$$**! Bài đọc tổng kết ứng dụng cuối Chương 12 này kết nối hệ điều kiện KKT với 4 lĩnh vực mũi nhọn giai đoạn 2022–2026: tầng tối ưu khả vi, SVM, giá điện LMP và học máy công bằng.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-góc-nhìn-công-nghiệp-về-điều-kiện-kkt&quot;&gt;Kiến thức cần nhớ: Bốn góc nhìn công nghiệp về điều kiện KKT&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù trong vận hành lưới điện (LMP &amp;amp; Congestion Rent):&lt;/strong&gt; Nhân tử KKT của phương trình cân bằng công suất tại nút \(i\) là giá biên \(\text{LMP}_i\); nhân tử KKT \(\mu_{ij}^* \ge 0\) của giới hạn nhiệt đường dây \((i, j)\) chỉ dương khi đường dây nghẽn, tạo ra chênh lệch \(\text{LMP}_j - \text{LMP}_i = \mu_{ij}^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lấy vi phân ẩn xuyên qua bộ giải tối ưu (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Theseus&lt;/code&gt;):&lt;/strong&gt; Biến hệ KKT thành phương trình hàm ẩn giúp lan truyền ngược gradient xuyên qua các bài toán tối ưu lồi nhúng trong mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định danh vector hỗ trợ và giải thích mô hình (SVM):&lt;/strong&gt; Chỉ những điểm dữ liệu có ràng buộc biên chặt (\(\alpha_i^* &amp;gt; 0\)) mới tham gia tạo nên siêu phẳng phân tách.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phát hiện nút thắt công bằng (Active Fairness Constraints):&lt;/strong&gt; Trong học máy có ràng buộc công bằng nhóm, nhân tử KKT \(u_g^* &amp;gt; 0\) chỉ ra chính xác nhóm nhân khẩu học nào đang bị ràng buộc chặt và kéo giảm mục tiêu chính.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-giá-điện-lmp-trên-lưới-2-nút-bị-nghẽn-đường-dây&quot;&gt;Giải thích: Tính tay giá điện LMP trên lưới 2 nút bị nghẽn đường dây&lt;/h3&gt;

&lt;p&gt;Xét lưới điện gồm 2 nút nối bởi một đường dây có giới hạn truyền tải \(F_{\max} = 50\) MWh:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nút 1 có nhà máy giá rẻ \(20\) USD/MWh (công suất đủ lớn), nhu cầu tại nút 1 bằng \(0\).&lt;/li&gt;
  &lt;li&gt;Nút 2 có nhà máy đắt \(60\) USD/MWh, nhu cầu tại nút 2 là \(D_2 = 80\) MWh.&lt;/li&gt;
  &lt;li&gt;Gọi \(p_1, p_2 \ge 0\) là công suất phát tại hai nút và \(f\) là dòng truyền từ nút 1 sang nút 2 (\(f \le 50\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập bài toán tối ưu và hàm Lagrangian:&lt;/strong&gt;
\(\min_{p_1, p_2, f} \; 20 p_1 + 60 p_2 \quad \text{s.t.} \quad \begin{cases} p_1 - f = 0 &amp;amp; (\text{giá nút 1: } \lambda_1) \\ p_2 + f = 80 &amp;amp; (\text{giá nút 2: } \lambda_2) \\ f - 50 \le 0 &amp;amp; (\text{phí nghẽn: } \mu \ge 0) \end{cases}\)
Dễ thấy phương án rẻ nhất là đẩy tối đa \(f^* = 50\) MWh từ nút 1 sang nút 2 (\(p_1^* = 50\)) và phát nốt \(p_2^* = 30\) MWh tại nút 2.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải 3 phương trình dừng KKT theo \(p_1, p_2, f\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Theo \(p_1\): \(20 - \lambda_1^* = 0 \implies \lambda_1^* = 20\) USD/MWh.&lt;/li&gt;
      &lt;li&gt;Theo \(p_2\): \(60 - \lambda_2^* = 0 \implies \lambda_2^* = 60\) USD/MWh.&lt;/li&gt;
      &lt;li&gt;Theo \(f\): \(\lambda_1^* - \lambda_2^* + \mu^* = 0 \implies \mu^* = \lambda_2^* - \lambda_1^* = 60 - 20 = 40\) USD/MWh!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng điều kiện bù KKT:&lt;/strong&gt; Vì đường dây chạm trần (\(f^* - 50 = 0\)), \(\mu^* = 40 &amp;gt; 0\) hoàn toàn hợp lệ! Ngược lại, nếu đường dây được nâng cấp lên \(F_{\max} = 100\) MWh (ràng buộc lỏng \(80 &amp;lt; 100\)), điều kiện bù ép \(\mu^* = 0\) và lập tức \(\lambda_1^* = \lambda_2^* = 20\) USD/MWh — giá điện toàn lưới giảm đồng loạt về mức rẻ nhất!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-điều-kiện-kkt&quot;&gt;Ứng dụng hiện đại của điều kiện KKT&lt;/h1&gt;

&lt;p&gt;Chương 12 đã trình bày hệ điều kiện KKT — gồm tính khả thi nguyên thủy, tính khả thi đối ngẫu, điều kiện bù yếu và điều kiện dừng của hàm Lagrangian — cùng các ví dụ về SVM, thuật toán water-filling và bài toán phạt \(\ell_1\). Bài đọc tùy chọn này điểm qua các ứng dụng thực tế giai đoạn 2022–2026 nơi hệ KKT được giải trực tiếp, lấy vi phân ẩn hoặc diễn giải như giá biên trong phần mềm tối ưu, mà không lặp lại phần lý thuyết cơ bản.&lt;/p&gt;

&lt;h2 id=&quot;1-lấy-vi-phân-xuyên-qua-bộ-giải-cvxpylayers-và-theseus&quot;&gt;1. Lấy vi phân xuyên qua bộ giải: cvxpylayers và Theseus&lt;/h2&gt;

&lt;p&gt;Nếu \(x^\star(\theta)\) là nghiệm duy nhất của một bài toán quy hoạch lồi phụ thuộc tham số \(\theta\), định lý hàm ẩn áp dụng lên ánh xạ KKT \(F(x,u,v;\theta)=0\) cho phép tính đạo hàm \(\mathrm{d}x^\star/\mathrm{d}\theta\) mà không cần trải ngược (unroll) các bước lặp của bộ giải. Agrawal, Amos, Barratt, Boyd, Diamond và Kolter (NeurIPS 2019) hiện thực hóa ý tưởng này trong thư viện &lt;strong&gt;cvxpylayers&lt;/strong&gt; (hỗ trợ PyTorch, JAX và MLX). Trong giai đoạn 2024–2026, đây vẫn là cách làm tiêu chuẩn để nhúng một bài toán QP hoặc SOCP &lt;em&gt;bên trong&lt;/em&gt; mạng nơ-ron, chẳng hạn trong lớp tối ưu hóa danh mục đầu tư (DeepDow), chính sách điều khiển dự báo mô hình (MPC) và các phép chiếu kiểu sparsemax.&lt;/p&gt;

&lt;p&gt;Pineda, Fan, Monge, Venkataraman, Sodhi, Chen, Ortiz, DeTone, Wang, Anderson, Dong, Amos và Mukadam (NeurIPS 2022) phát hành &lt;strong&gt;Theseus&lt;/strong&gt;, thư viện chạy trên GPU cho bài toán bình phương tối thiểu &lt;em&gt;phi tuyến&lt;/em&gt; khả vi dùng trong robot và thị giác máy tính. Quá trình lan truyền ngược dựa trên vi phân ẩn của điều kiện dừng (Gauss–Newton hoặc Levenberg–Marquardt) — tương ứng với hệ KKT của bài toán bình phương tối thiểu phi tuyến có ràng buộc đẳng thức hoặc thành phần điều chuẩn. Công trình năm 2022 là tài liệu tham khảo chính, còn mã nguồn thư viện được dùng trực tiếp trong nhiều hệ thống SLAM và hiệu chỉnh chùm tia (bundle adjustment).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liên hệ với giáo trình:&lt;/strong&gt; Điều kiện dừng \(\nabla_x L=0\) tạo thành hệ tuyến tính mà Theseus lấy vi phân, còn điều kiện bù yếu xuất hiện ngay khi lớp tối ưu có ràng buộc bất đẳng thức như trong cvxpylayers.&lt;/p&gt;

&lt;h2 id=&quot;2-vector-hỗ-trợ-của-svm-dưới-góc-nhìn-kkt&quot;&gt;2. Vector hỗ trợ của SVM dưới góc nhìn KKT&lt;/h2&gt;

&lt;p&gt;Ví dụ trong mục &lt;a href=&quot;/contents/vi/chapter12/12_04_Example_support_vector_machines/&quot;&gt;12-04&lt;/a&gt; có ý nghĩa trực tiếp trong thực hành. Điều kiện bù yếu cho biết các điểm có \(0&amp;lt;\alpha_i&amp;lt;C\) nằm đúng trên lề, các điểm có \(\alpha_i=0\) được phân loại đúng và nằm ngoài vùng lề (không có sai số vi phạm), còn các điểm có \(\alpha_i=C\) là các vector hỗ trợ chạm giới hạn trên (nằm trong lề hoặc bị phân loại sai). Trong giai đoạn 2022–2026, SVM nhân (kernel SVM) vẫn là công cụ phổ biến trong học máy khoa học cỡ mẫu \(n\) nhỏ (như hóa tin học, dữ liệu điện não đồ EEG, dữ liệu lâm sàng dạng bảng) chính vì mô hình chỉ phụ thuộc vào tập hữu hạn các vector hỗ trợ này. Khi một bài báo nêu mô hình có “47 vector hỗ trợ”, con số đó chính là kích thước tập ràng buộc tích cực (active set) của hệ KKT.&lt;/p&gt;

&lt;h2 id=&quot;3-giá-biên-theo-vị-trí-lmp-trong-thị-trường-điện-và-điều-kiện-bù&quot;&gt;3. Giá biên theo vị trí (LMP) trong thị trường điện và điều kiện bù&lt;/h2&gt;

&lt;p&gt;Giá biên theo vị trí (Locational Marginal Price — LMP) là các biến đối ngẫu ứng với ràng buộc cân bằng công suất và giới hạn truyền tải đường dây (Chương 10). Liang và Dvorkin (2023) sử dụng tối ưu hóa ngược trên dữ liệu LMP công bố để khôi phục giá chào bán của các nhà máy điện; phép khôi phục này thực hiện được vì tại điểm cân bằng không suy biến, hệ KKT xác định rõ ràng buộc bất đẳng thức nào đang chặt. Donti, Rolnick và Kolter (2021) huấn luyện phương pháp DC3 sao cho đầu ra của mạng nơ-ron được hiệu chỉnh về điểm khả thi KKT của bài toán trào lưu công suất tối ưu (OPF). Thuật toán water-filling trong &lt;a href=&quot;/contents/vi/chapter12/12_03_Example_water_filling/&quot;&gt;12-03&lt;/a&gt; cũng mang cấu trúc điều kiện bù tương tự trên kênh nhiễu Gauss; các nghiên cứu phân bổ công suất cho mạng 5G/6G vẫn biểu diễn mực nước như nhân tử đối ngẫu của ràng buộc tổng công suất.&lt;/p&gt;

&lt;h2 id=&quot;4-tính-công-bằng-trong-học-máy-nhận-diện-ràng-buộc-nhóm-đang-chặt&quot;&gt;4. Tính công bằng trong học máy: nhận diện ràng buộc nhóm đang chặt&lt;/h2&gt;

&lt;p&gt;Trong khung công cụ Fairlearn theo cách tiếp cận quy giảm (Weerts và cộng sự, 2023), một nhân tử Lagrange có giá trị lớn gắn với tiêu chí equalised odds của nhóm \(a\) cho thấy ràng buộc tỷ lệ lỗi của nhóm đó &lt;strong&gt;đang chặt&lt;/strong&gt; — đây chính là ý nghĩa trực tiếp của điều kiện bù yếu. Ngược lại, nhân tử bằng không cho thấy mô hình không ràng buộc đã tự thỏa mãn tiêu chí đó (hoặc ràng buộc không còn tác động biên). Vì vậy, việc quan sát cặp nghiệm \((x^\star,v^\star)\) đóng vai trò như một công cụ chẩn đoán: nó chỉ ra ràng buộc xã hội–kỹ thuật nào đang tạo ra chi phí đánh đổi lớn nhất, thay vì chỉ cho biết hàm Lagrangian đã đạt cực tiểu.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;p&gt;Hệ KKT là tập điều kiện bậc nhất giúp: (i) đặc trưng nghiệm tối ưu của bài toán lồi có ràng buộc, (ii) lấy vi phân ẩn để huấn luyện các lớp tối ưu trong mạng học sâu, và (iii) gán giá biên cho các tài nguyên bị giới hạn. Khi các nghiên cứu hiện đại đề cập đến việc nhúng QP vào mạng nơ-ron, báo cáo số lượng vector hỗ trợ hay công bố giá điện LMP, nền tảng toán học chung đằng sau đều là hệ KKT.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi gợi mở:&lt;/strong&gt; Vì sao phép lấy vi phân ẩn qua hệ KKT đòi hỏi điều kiện ràng buộc (constraint qualification) và ma trận Jacobian KKT không suy biến? Điều gì xảy ra trong một lớp Lasso khi hai đặc trưng trùng hệt nhau?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Agrawal, A., Amos, B., Barratt, S., Boyd, S., Diamond, S., &amp;amp; Kolter, J. Z. (2019). Differentiable convex optimization layers. &lt;em&gt;NeurIPS&lt;/em&gt;. Thư viện: &lt;a href=&quot;https://www.cvxpylayers.org/&quot;&gt;cvxpylayers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Pineda, L., Fan, T., Monge, M., Venkataraman, S., Sodhi, P., Chen, R. T. Q., Ortiz, J., DeTone, D., Wang, A., Anderson, S., Dong, J., Amos, B., &amp;amp; Mukadam, M. (2022). Theseus: A library for differentiable nonlinear optimization. &lt;em&gt;NeurIPS&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2207.09442&quot;&gt;arXiv:2207.09442&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Liang, Z., &amp;amp; Dvorkin, Y. (2023). Data-driven inverse optimization for marginal offer price recovery in electricity markets. &lt;em&gt;ACM e-Energy ’23&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Donti, P. L., Rolnick, D., &amp;amp; Kolter, J. Z. (2021). DC3: A learning method for optimization with hard constraints. &lt;em&gt;ICLR&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>12-07 Ứng dụng hiện đại của điều kiện KKT</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_07_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_07_modern_applications</id>
   <content type="html">&lt;p&gt;Nếu trước năm 2019, bài toán tối ưu lồi và mạng nơ-ron sâu sống ở hai thế giới riêng biệt — mạng nơ-ron dự đoán tham số, sau đó một bộ giải tối ưu chạy tách rời ở bước cuối — thì giai đoạn 2022–2026 đã hợp nhất hai thế giới ấy bằng một đột phá tuyệt đẹp: &lt;strong&gt;lấy vi phân xuyên qua bộ giải tối ưu (Differentiable Optimization Layers — &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OptNet&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Theseus&lt;/code&gt;)&lt;/strong&gt;! Bạn có thể nhúng thẳng cả một bài toán tối ưu lồi làm một tầng (layer) bên trong mạng PyTorch và huấn luyện đầu-cuối bằng lan truyền ngược!&lt;/p&gt;

&lt;p&gt;Bí mật giúp ta tính được đạo hàm \(\frac{\partial x^*(\theta)}{\partial \theta}\) của nghiệm tối ưu \(x^*(\theta)\) theo tham số đầu vào \(\theta\) mà không cần mở tung hàng nghìn vòng lặp của bộ giải bên trong chính là &lt;strong&gt;hệ phương trình KKT kết hợp với Định lý Hàm Ẩn (Implicit Function Theorem)&lt;/strong&gt;! Vì \(x^*(\theta)\) và \((u^*(\theta), v^*(\theta))\) luôn thỏa đẳng thức KKT \(F(x^*, u^*, v^*; \theta) = 0\), chỉ cần lấy vi phân hai vế của đúng hệ KKT đó tại điểm nghiệm là ta thu ngay ma trận Jacobian chính xác!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-ứng-dụng-hiện-đại-của-điều-kiện-kkt-20222026&quot;&gt;Kiến thức cần nhớ: Bốn nhánh ứng dụng hiện đại của điều kiện KKT (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lấy vi phân ẩn xuyên qua bộ giải (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt; &amp;amp; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Theseus&lt;/code&gt;):&lt;/strong&gt; Thay vì lưu toàn bộ đồ thị tính toán của vòng lặp tối ưu (tốn bộ nhớ khổng lồ), lan truyền ngược chỉ cần giải &lt;em&gt;một hệ phương trình tuyến tính duy nhất&lt;/em&gt; từ vi phân của hệ KKT tại điểm tối ưu \((x^*, u^*, v^*)\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải mã độ thưa của SVM và các mô hình biên rộng:&lt;/strong&gt; Điều kiện bù KKT giải thích vì sao chỉ một tập con nhỏ các vector hỗ trợ mới định hình biên quyết định, giúp nén mô hình và phân tích độ nhạy dữ liệu (influence functions).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giá điện biên theo vị trí (LMP) trong vận hành lưới điện:&lt;/strong&gt; Điều kiện bù KKT tự động xác định những đường dây truyền tải nào đang bị nghẽn (\(u_l^* &amp;gt; 0\)), từ đó phân tách giá điện theo từng nút địa lý một cách minh bạch.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm soát ràng buộc công bằng trong học máy:&lt;/strong&gt; Nhận diện nhóm nhân khẩu học nào đang có ràng buộc công bằng chặt (\(u_g^* &amp;gt; 0\)) giúp kỹ sư AI biết chính xác nhóm nào đang là điểm nghẽn của sự đánh đổi độ chính xác – công bằng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-đạo-hàm-fracpartial-xpartial-theta-xuyên-qua-hệ-kkt-của-một-tầng-tối-ưu&quot;&gt;Giải thích: Tính tay đạo hàm \(\frac{\partial x^*}{\partial \theta}\) xuyên qua hệ KKT của một tầng tối ưu&lt;/h3&gt;

&lt;p&gt;Xét một tầng tối ưu lồi cực giản dị (chính là tầng kích hoạt ReLU dưới lăng kính tối ưu!):
\(x^*(\theta) = \arg\min_{x \in \mathbb{R}} \; \frac{1}{2}(x - \theta)^2 \quad \text{s.t.} \quad -x \le 0 \; (\text{tức } x \ge 0).\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Viết hệ phương trình KKT tại nghiệm \((x^*(\theta), u^*(\theta))\):&lt;/strong&gt;
\(\begin{cases} x^* - \theta - u^* = 0 &amp;amp; (\text{dừng}) \\ u^* x^* = 0 &amp;amp; (\text{điều kiện bù}) \end{cases}\)
Dễ thấy nghiệm đóng là \(x^*(\theta) = \max(0, \theta)\) và \(u^*(\theta) = \max(0, -\theta)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lấy vi phân ẩn hai vế hệ KKT theo \(\theta\) (cách &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt; hoạt động!):&lt;/strong&gt;
\(\begin{pmatrix} 1 &amp;amp; -1 \\ u^* &amp;amp; x^* \end{pmatrix} \begin{pmatrix} \frac{\partial x^*}{\partial \theta} \\ \frac{\partial u^*}{\partial \theta} \end{pmatrix} = \begin{pmatrix} 1 \\ 0 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải hệ tuyến tính \(2 \times 2\) cho hai chế độ:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Khi \(\theta = 2 &amp;gt; 0\)&lt;/strong&gt; (\(x^* = 2, u^* = 0\)): hàng 2 là \(0\frac{\partial x^*}{\partial \theta} + 2\frac{\partial u^*}{\partial \theta} = 0 \implies \frac{\partial u^*}{\partial \theta} = 0\), thay vào hàng 1 cho \(\frac{\partial x^*}{\partial \theta} = 1\)!&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Khi \(\theta = -2 &amp;lt; 0\)&lt;/strong&gt; (\(x^* = 0, u^* = 2\)): hàng 2 là \(2\frac{\partial x^*}{\partial \theta} + 0 = 0 \implies \frac{\partial x^*}{\partial \theta} = 0\), thay vào hàng 1 cho \(\frac{\partial u^*}{\partial \theta} = -1\)!
Chỉ từ 2 dòng vi phân hệ KKT, ta khôi phục chính xác 100% đạo hàm của hàm ReLU — và cơ chế này mở rộng tức thì lên mọi bài toán QP, SOCP, SDP hàng nghìn biến trong PyTorch!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-điều-kiện-kkt&quot;&gt;Ứng dụng hiện đại của điều kiện KKT&lt;/h1&gt;

&lt;p&gt;Chương 12 đã trình bày hệ điều kiện KKT — gồm tính khả thi nguyên thủy, tính khả thi đối ngẫu, điều kiện bù yếu và điều kiện dừng của hàm Lagrangian — cùng các ví dụ về SVM, thuật toán water-filling và bài toán phạt \(\ell_1\). Bài đọc tùy chọn này điểm qua các ứng dụng thực tế giai đoạn 2022–2026 nơi hệ KKT được giải trực tiếp, lấy vi phân ẩn hoặc diễn giải như giá biên trong phần mềm tối ưu, mà không lặp lại phần lý thuyết cơ bản.&lt;/p&gt;

&lt;h2 id=&quot;1-lấy-vi-phân-xuyên-qua-bộ-giải-cvxpylayers-và-theseus&quot;&gt;1. Lấy vi phân xuyên qua bộ giải: cvxpylayers và Theseus&lt;/h2&gt;

&lt;p&gt;Nếu \(x^\star(\theta)\) là nghiệm duy nhất của một bài toán quy hoạch lồi phụ thuộc tham số \(\theta\), định lý hàm ẩn áp dụng lên ánh xạ KKT \(F(x,u,v;\theta)=0\) cho phép tính đạo hàm \(\mathrm{d}x^\star/\mathrm{d}\theta\) mà không cần trải ngược (unroll) các bước lặp của bộ giải. Agrawal, Amos, Barratt, Boyd, Diamond và Kolter (NeurIPS 2019) hiện thực hóa ý tưởng này trong thư viện &lt;strong&gt;cvxpylayers&lt;/strong&gt; (hỗ trợ PyTorch, JAX và MLX). Trong giai đoạn 2024–2026, đây vẫn là cách làm tiêu chuẩn để nhúng một bài toán QP hoặc SOCP &lt;em&gt;bên trong&lt;/em&gt; mạng nơ-ron, chẳng hạn trong lớp tối ưu hóa danh mục đầu tư (DeepDow), chính sách điều khiển dự báo mô hình (MPC) và các phép chiếu kiểu sparsemax.&lt;/p&gt;

&lt;p&gt;Pineda, Fan, Monge, Venkataraman, Sodhi, Chen, Ortiz, DeTone, Wang, Anderson, Dong, Amos và Mukadam (NeurIPS 2022) phát hành &lt;strong&gt;Theseus&lt;/strong&gt;, thư viện chạy trên GPU cho bài toán bình phương tối thiểu &lt;em&gt;phi tuyến&lt;/em&gt; khả vi dùng trong robot và thị giác máy tính. Quá trình lan truyền ngược dựa trên vi phân ẩn của điều kiện dừng (Gauss–Newton hoặc Levenberg–Marquardt) — tương ứng với hệ KKT của bài toán bình phương tối thiểu phi tuyến có ràng buộc đẳng thức hoặc thành phần điều chuẩn. Công trình năm 2022 là tài liệu tham khảo chính, còn mã nguồn thư viện được dùng trực tiếp trong nhiều hệ thống SLAM và hiệu chỉnh chùm tia (bundle adjustment).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liên hệ với giáo trình:&lt;/strong&gt; Điều kiện dừng \(\nabla_x L=0\) tạo thành hệ tuyến tính mà Theseus lấy vi phân, còn điều kiện bù yếu xuất hiện ngay khi lớp tối ưu có ràng buộc bất đẳng thức như trong cvxpylayers.&lt;/p&gt;

&lt;h2 id=&quot;2-vector-hỗ-trợ-của-svm-dưới-góc-nhìn-kkt&quot;&gt;2. Vector hỗ trợ của SVM dưới góc nhìn KKT&lt;/h2&gt;

&lt;p&gt;Ví dụ trong mục &lt;a href=&quot;/contents/vi/chapter12/12_04_Example_support_vector_machines/&quot;&gt;12-04&lt;/a&gt; có ý nghĩa trực tiếp trong thực hành. Điều kiện bù yếu cho biết các điểm có \(0&amp;lt;\alpha_i&amp;lt;C\) nằm đúng trên lề, các điểm có \(\alpha_i=0\) được phân loại đúng và nằm ngoài vùng lề (không có sai số vi phạm), còn các điểm có \(\alpha_i=C\) là các vector hỗ trợ chạm giới hạn trên (nằm trong lề hoặc bị phân loại sai). Trong giai đoạn 2022–2026, SVM nhân (kernel SVM) vẫn là công cụ phổ biến trong học máy khoa học cỡ mẫu \(n\) nhỏ (như hóa tin học, dữ liệu điện não đồ EEG, dữ liệu lâm sàng dạng bảng) chính vì mô hình chỉ phụ thuộc vào tập hữu hạn các vector hỗ trợ này. Khi một bài báo nêu mô hình có “47 vector hỗ trợ”, con số đó chính là kích thước tập ràng buộc tích cực (active set) của hệ KKT.&lt;/p&gt;

&lt;h2 id=&quot;3-giá-biên-theo-vị-trí-lmp-trong-thị-trường-điện-và-điều-kiện-bù&quot;&gt;3. Giá biên theo vị trí (LMP) trong thị trường điện và điều kiện bù&lt;/h2&gt;

&lt;p&gt;Giá biên theo vị trí (Locational Marginal Price — LMP) là các biến đối ngẫu ứng với ràng buộc cân bằng công suất và giới hạn truyền tải đường dây (Chương 10). Liang và Dvorkin (2023) sử dụng tối ưu hóa ngược trên dữ liệu LMP công bố để khôi phục giá chào bán của các nhà máy điện; phép khôi phục này thực hiện được vì tại điểm cân bằng không suy biến, hệ KKT xác định rõ ràng buộc bất đẳng thức nào đang chặt. Donti, Rolnick và Kolter (2021) huấn luyện phương pháp DC3 sao cho đầu ra của mạng nơ-ron được hiệu chỉnh về điểm khả thi KKT của bài toán trào lưu công suất tối ưu (OPF). Thuật toán water-filling trong &lt;a href=&quot;/contents/vi/chapter12/12_03_Example_water_filling/&quot;&gt;12-03&lt;/a&gt; cũng mang cấu trúc điều kiện bù tương tự trên kênh nhiễu Gauss; các nghiên cứu phân bổ công suất cho mạng 5G/6G vẫn biểu diễn mực nước như nhân tử đối ngẫu của ràng buộc tổng công suất.&lt;/p&gt;

&lt;h2 id=&quot;4-tính-công-bằng-trong-học-máy-nhận-diện-ràng-buộc-nhóm-đang-chặt&quot;&gt;4. Tính công bằng trong học máy: nhận diện ràng buộc nhóm đang chặt&lt;/h2&gt;

&lt;p&gt;Trong khung công cụ Fairlearn theo cách tiếp cận quy giảm (Weerts và cộng sự, 2023), một nhân tử Lagrange có giá trị lớn gắn với tiêu chí equalised odds của nhóm \(a\) cho thấy ràng buộc tỷ lệ lỗi của nhóm đó &lt;strong&gt;đang chặt&lt;/strong&gt; — đây chính là ý nghĩa trực tiếp của điều kiện bù yếu. Ngược lại, nhân tử bằng không cho thấy mô hình không ràng buộc đã tự thỏa mãn tiêu chí đó (hoặc ràng buộc không còn tác động biên). Vì vậy, việc quan sát cặp nghiệm \((x^\star,v^\star)\) đóng vai trò như một công cụ chẩn đoán: nó chỉ ra ràng buộc xã hội–kỹ thuật nào đang tạo ra chi phí đánh đổi lớn nhất, thay vì chỉ cho biết hàm Lagrangian đã đạt cực tiểu.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;p&gt;Hệ KKT là tập điều kiện bậc nhất giúp: (i) đặc trưng nghiệm tối ưu của bài toán lồi có ràng buộc, (ii) lấy vi phân ẩn để huấn luyện các lớp tối ưu trong mạng học sâu, và (iii) gán giá biên cho các tài nguyên bị giới hạn. Khi các nghiên cứu hiện đại đề cập đến việc nhúng QP vào mạng nơ-ron, báo cáo số lượng vector hỗ trợ hay công bố giá điện LMP, nền tảng toán học chung đằng sau đều là hệ KKT.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi gợi mở:&lt;/strong&gt; Vì sao phép lấy vi phân ẩn qua hệ KKT đòi hỏi điều kiện ràng buộc (constraint qualification) và ma trận Jacobian KKT không suy biến? Điều gì xảy ra trong một lớp Lasso khi hai đặc trưng trùng hệt nhau?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Agrawal, A., Amos, B., Barratt, S., Boyd, S., Diamond, S., &amp;amp; Kolter, J. Z. (2019). Differentiable convex optimization layers. &lt;em&gt;NeurIPS&lt;/em&gt;. Thư viện: &lt;a href=&quot;https://www.cvxpylayers.org/&quot;&gt;cvxpylayers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Pineda, L., Fan, T., Monge, M., Venkataraman, S., Sodhi, P., Chen, R. T. Q., Ortiz, J., DeTone, D., Wang, A., Anderson, S., Dong, J., Amos, B., &amp;amp; Mukadam, M. (2022). Theseus: A library for differentiable nonlinear optimization. &lt;em&gt;NeurIPS&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2207.09442&quot;&gt;arXiv:2207.09442&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Liang, Z., &amp;amp; Dvorkin, Y. (2023). Data-driven inverse optimization for marginal offer price recovery in electricity markets. &lt;em&gt;ACM e-Energy ’23&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Donti, P. L., Rolnick, D., &amp;amp; Kolter, J. Z. (2021). DC3: A learning method for optimization with hard constraints. &lt;em&gt;ICLR&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>11-11 Ứng dụng hiện đại của đối ngẫu Lagrange</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_11_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_11_modern_applications</id>
   <content type="html">&lt;p&gt;Nếu phải chọn một ứng dụng duy nhất khiến hàng triệu kỹ sư học máy trên toàn thế giới phải thầm cảm ơn Joseph-Louis Lagrange, đó chắc chắn là &lt;strong&gt;bài toán đối ngẫu của Máy vector hỗ trợ (SVM)&lt;/strong&gt; và &lt;strong&gt;Thủ thuật nhân (Kernel Trick)&lt;/strong&gt;. Trong không gian đặc trưng gốc, bài toán SVM cần tìm một siêu phẳng phân tách trong \(\mathbb{R}^p\); nhưng khi ta ánh xạ dữ liệu sang không gian đặc trưng phi tuyến có hàng triệu (thậm chí vô hạn!) chiều để tách các lớp dữ liệu xoắn ốc phức tạp, việc tính trực tiếp vector trọng số \(w\) trở nên bất khả thi.&lt;/p&gt;

&lt;p&gt;Chính nhờ &lt;strong&gt;tính đối ngẫu mạnh Lagrange&lt;/strong&gt; (được bảo chứng tự động bởi điều kiện Slater tinh gọn vì mọi ràng buộc SVM đều là ràng buộc affine!), ta chuyển bài toán sang biến đối ngẫu \(\alpha \in \mathbb{R}^n\). Trong bài toán đối ngẫu ấy, vector trọng số \(w\) biến mất hoàn toàn, chỉ còn lại ma trận tích vô hướng \(x_i^T x_j\) — thứ có thể thay tức thì bằng hàm nhân \(K(x_i, x_j)\) như nhân Gaussian RBF! Bài đọc tổng kết cuối chương này kết nối trực tiếp sức mạnh ấy của đối ngẫu Lagrange với bốn trụ cột hiện đại giai đoạn 2022–2026: DRO, ràng buộc vật lý trong năng lượng, công bằng học máy và phương pháp nhân.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-cầu-nối-từ-đối-ngẫu-lagrange-đến-hệ-thống-ai--kỹ-thuật-hiện-đại&quot;&gt;Kiến thức cần nhớ: Bốn cầu nối từ đối ngẫu Lagrange đến hệ thống AI &amp;amp; kỹ thuật hiện đại&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thủ thuật nhân (Kernel Trick) sinh ra từ đối ngẫu SVM:&lt;/strong&gt; Từ điều kiện dừng \(\nabla_w L = 0 \implies w = \sum_{i=1}^n \alpha_i y_i x_i\), bài toán đối ngẫu chỉ phụ thuộc vào \(x_i^T x_j\) và nghiệm \(\alpha_i^*\) chỉ khác \(0\) trên một số ít &lt;strong&gt;vector hỗ trợ (support vectors)&lt;/strong&gt; nằm sát biên phân loại.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều chuẩn hóa tự động từ đối ngẫu DRO:&lt;/strong&gt; Trong tối ưu bền vững theo phân phối, nhân tử Lagrange của ràng buộc khoảng cách Wasserstein đóng vai trò chính xác là hệ số điều chuẩn phạt chuẩn gradient/Lipschitz của mô hình!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lớp thực thi ràng buộc vật lý (DC3 / OPF-DNN):&lt;/strong&gt; Kết hợp hàm phạt Lagrangian vào quá trình huấn luyện mạng nơ-ron cho phép các hệ thống lưới điện thông minh và robot đạt tốc độ suy luận mili-giây mà vẫn tôn trọng định luật bảo toàn năng lượng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu minimax công bằng (Fairness Dual Games):&lt;/strong&gt; Biến các tiêu chí công bằng phi tuyến thành bài toán điểm yên ngựa Lagrange giữa mô hình dự đoán và bộ trọng số đối ngẫu của từng nhóm dữ liệu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-trọn-vẹn-bài-toán-đối-ngẫu-svm-cho-2-điểm-dữ-liệu-1d&quot;&gt;Giải thích: Giải tay trọn vẹn bài toán đối ngẫu SVM cho 2 điểm dữ liệu 1D&lt;/h3&gt;

&lt;p&gt;Xét tập dữ liệu 1D tối giản gồm 2 điểm: \((x_1, y_1) = (-1, -1)\) và \((x_2, y_2) = (+1, +1)\).
Bài toán gốc Hard-Margin SVM:
\(\min_{w, b} \; \frac{1}{2}w^2 \quad \text{s.t.} \quad y_1(w x_1 + b) \ge 1, \quad y_2(w x_2 + b) \ge 1.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập bài toán đối ngẫu Lagrange (biến \(\alpha_1, \alpha_2 \ge 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ràng buộc từ \(\frac{\partial L}{\partial b} = 0\): \(\sum \alpha_i y_i = -\alpha_1 + \alpha_2 = 0 \implies \alpha_1 = \alpha_2 = \alpha \ge 0\).&lt;/li&gt;
      &lt;li&gt;Biểu thức trọng số từ \(\frac{\partial L}{\partial w} = 0\): \(w = \alpha_1 y_1 x_1 + \alpha_2 y_2 x_2 = \alpha_1(-1)(-1) + \alpha_2(1)(1) = \alpha_1 + \alpha_2 = 2\alpha\).&lt;/li&gt;
      &lt;li&gt;Hàm mục tiêu đối ngẫu:
\(g(\alpha) = (\alpha_1 + \alpha_2) - \frac{1}{2}w^2 = 2\alpha - \frac{1}{2}(2\alpha)^2 = 2\alpha - 2\alpha^2.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán đối ngẫu lồi \(\max_{\alpha \ge 0} (2\alpha - 2\alpha^2)\):&lt;/strong&gt;
Đạo hàm \(2 - 4\alpha = 0 \implies \alpha^* = 0.5\), tức \(\alpha_1^* = \alpha_2^* = 0.5 &amp;gt; 0\) (cả hai điểm đều là vector hỗ trợ!).
Giá trị đối ngẫu tối ưu: \(g^* = 2(0.5) - 2(0.25) = 0.5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khôi phục siêu phẳng phân tách tối ưu:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Trọng số: \(w^* = 2\alpha^* = 1\).&lt;/li&gt;
      &lt;li&gt;Hệ số tự do \(b^*\) từ điều kiện chặt \(y_2(w^* x_2 + b^*) = 1 \implies 1(1 + b^*) = 1 \implies b^* = 0\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Giá trị gốc: \(\frac{1}{2}(w^*)^2 = 0.5 = g^*\), với độ rộng lề cực đại $$\frac{1}{&lt;/td&gt;
              &lt;td&gt;w^*&lt;/td&gt;
              &lt;td&gt;} = 1$$! Mọi thứ khớp chặt tuyệt đối nhờ đối ngẫu mạnh!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-đối-ngẫu-lagrange&quot;&gt;Ứng dụng hiện đại của đối ngẫu Lagrange&lt;/h1&gt;

&lt;p&gt;Chương 11 mở rộng lý thuyết đối ngẫu từ quy hoạch tuyến tính sang các bài toán tối ưu tổng quát: hàm Lagrangian \(L(x,u,v)\), hàm đối ngẫu \(g(u,v)=\inf_x L\), tính đối ngẫu yếu \(g\le f^\star\) và tính đối ngẫu mạnh khi bài toán lồi kèm điều kiện chuẩn hóa ràng buộc. Bài đọc tùy chọn này trình bày bốn ứng dụng hiện đại của cơ chế đối ngẫu đó — trong đó nhân tử Lagrange đóng vai trò như giá biên, bán kính bền vững hoặc tín hiệu huấn luyện.&lt;/p&gt;

&lt;h2 id=&quot;1-tối-ưu-bền-vững-theo-phân-phối-dro&quot;&gt;1. Tối ưu bền vững theo phân phối (DRO)&lt;/h2&gt;

&lt;p&gt;Thay vì cực tiểu hóa rủi ro thực nghiệm \(\mathbb{E}_{\hat P}[\ell(x,\xi)]\), bài toán tối ưu bền vững theo phân phối (Distributionally Robust Optimization – DRO) giải:&lt;/p&gt;

\[\min_x\ \sup_{P\in\mathcal{P}}\ \mathbb{E}_P[\ell(x,\xi)],\]

&lt;p&gt;trong đó tập bất định \(\mathcal{P}\) là một quả cầu phân phối (theo phân kỳ \(\phi\) hoặc khoảng cách Wasserstein) quanh phân phối thực nghiệm. Bài toán \(\sup\) bên trong là một bài toán &lt;strong&gt;liên hợp / đối ngẫu&lt;/strong&gt;: với quả cầu Wasserstein, nó biến đổi thành bài toán cực tiểu hóa rủi ro có điều chuẩn, trong đó biến đối ngẫu đóng vai trò như hằng số phạt Lipschitz cho chi phí dịch chuyển khối lượng xác suất. Rahimian và Mehrotra (2022) tổng hợp lý thuyết đối ngẫu, cách chọn tập \(\mathcal{P}\) và các bộ giải tương ứng. Công trình hướng dẫn về Wasserstein DRO của Kuhn, Esfahani, Nguyen và Shafieezadeh-Abadeh (2019) vẫn được trích dẫn rộng rãi giai đoạn 2023–2026 trong các nghiên cứu học máy về nhãn nhiễu, dịch chuyển phân phối và huấn luyện đối kháng. Chính tính đối ngẫu mạnh giúp chuyển bài toán kỳ vọng trường hợp xấu nhất vô hạn chiều thành một bài toán lồi hữu hạn chiều có thể giải bằng CVXPY.&lt;/p&gt;

&lt;h2 id=&quot;2-ràng-buộc-cứng-trong-năng-lượng-và-vật-lý-opf-dnn-và-dc3&quot;&gt;2. Ràng buộc cứng trong năng lượng và vật lý: OPF-DNN và DC3&lt;/h2&gt;

&lt;p&gt;Bài toán luồng công suất tối ưu xoay chiều (AC-OPF) là một bài toán tối ưu không lồi với các phương trình đẳng thức Kirchhoff và giới hạn nhiệt của đường dây. Fioretto, Mak và Van Hentenryck (AAAI 2020) huấn luyện mạng nơ-ron dự đoán điểm vận hành đồng thời &lt;strong&gt;cập nhật nhân tử Lagrange bằng các bước dưới đạo hàm (subgradient)&lt;/strong&gt; theo độ vi phạm ràng buộc — sử dụng đối ngẫu Lagrange trực tiếp như một vòng lặp huấn luyện. Donti, Rolnick và Kolter (ICLR 2021) đề xuất phương pháp &lt;strong&gt;DC3&lt;/strong&gt;: hoàn tất các ràng buộc đẳng thức một cách khả vi, rồi hiệu chỉnh các ràng buộc bất đẳng thức bằng các bước gradient trải phẳng (unrolled), và kiểm chứng trên bài toán AC-OPF. Các nghiên cứu “học để tối ưu” (learning to optimize) giai đoạn 2022–2025 tiếp tục khai thác cùng cơ chế này: nhân tử Lagrange không chỉ là chứng chỉ kiểm tra sau khi giải, mà trở thành tín hiệu trực tiếp định hướng quá trình huấn luyện mạng.&lt;/p&gt;

&lt;p&gt;Cần lưu ý rằng tính đối ngẫu yếu vẫn cung cấp cận dưới ngay cả khi bài toán gốc không lồi, nhưng tính đối ngẫu mạnh không tự động được bảo đảm — đây chính là ranh giới quan trọng của Chương 11.&lt;/p&gt;

&lt;h2 id=&quot;3-quy-giảm-công-bằng-như-một-trò-chơi-đối-ngẫu&quot;&gt;3. Quy giảm công bằng như một trò chơi đối ngẫu&lt;/h2&gt;

&lt;p&gt;Agarwal và cộng sự (2018) cùng phương pháp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExponentiatedGradient&lt;/code&gt; trong thư viện Fairlearn (Weerts và cộng sự, 2023) biểu diễn các ràng buộc công bằng theo nhóm dưới dạng một hàm Lagrangian. Trong trò chơi hai người tương ứng, phía đối ngẫu tăng trọng số lên các nhóm đang bị vi phạm ràng buộc, còn phía gốc giải bài toán cực tiểu hóa rủi ro thực nghiệm (ERM) có trọng số. Cotter và cộng sự (2019) mở rộng khung này sang các ràng buộc tỷ lệ không khả vi thông qua proxy-Lagrangian. Ở cả ba phương pháp, \(v \ge 0\) là nhân tử Lagrange cho ràng buộc bất đẳng thức \(g_i(x) \le 0\), và theo điều kiện bù (Chương 12), nhóm nào đã thỏa mãn chặt chẽ tiêu chí công bằng (ràng buộc lỏng) sẽ có nhân tử \(v_i = 0\).&lt;/p&gt;

&lt;h2 id=&quot;4-máy-vector-hỗ-trợ-svm-và-phương-pháp-nhân-kernel&quot;&gt;4. Máy vector hỗ trợ (SVM) và phương pháp nhân (kernel)&lt;/h2&gt;

&lt;p&gt;Bài toán SVM lề mềm là ví dụ kinh điển của tối ưu tổng quát với bài toán đối ngẫu là một quy hoạch bậc hai có ràng buộc hộp trên các hệ số \(\alpha_i\). Trình giải &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SVC&lt;/code&gt; trong scikit-learn cùng nhiều nghiên cứu giai đoạn 2022–2026 trong sinh học tính toán và bài toán dữ liệu bảng cỡ nhỏ vẫn giải trực tiếp bài toán đối ngẫu, bởi kỹ thuật nhân (kernel trick) được áp dụng trên hàm đối ngẫu \(g(\alpha)\) thay vì trực tiếp trên vector trọng số \(w\). Dạng điều kiện tối ưu KKT sẽ được phân tích ở Chương 12, còn cơ sở tồn tại của hàm đối ngẫu \(g\) nằm ở chương này.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;p&gt;Quy trình tổng quát gồm ba bước: lập hàm Lagrangian, cực tiểu hóa theo \(x\) để thu được hàm đối ngẫu \(g\), và cực đại hóa \(g\) theo các nhân tử đối ngẫu. Khi bài toán gốc lồi và thỏa mãn một điều kiện chuẩn hóa ràng buộc (CQ), ta có thể hoán đổi thứ tự \(\inf\) và \(\sup\) (đối ngẫu mạnh). DRO, mạng nơ-ron có ràng buộc vật lý, quy giảm công bằng và SVM nhân là bốn ứng dụng khác nhau của cùng nguyên lý này.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi tự kiểm tra:&lt;/strong&gt; Trong bài toán Wasserstein DRO, một biến đối ngẫu tối ưu có giá trị lớn ứng với bán kính quả cầu cho biết điều gì về độ nhạy với dịch chuyển phân phối, và bất đẳng thức nào trong chương này bảo đảm giá trị đó tạo thành cận dưới hợp lệ cho rủi ro trường hợp xấu nhất?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Rahimian, H., &amp;amp; Mehrotra, S. (2022). Frameworks and results in distributionally robust optimization. &lt;em&gt;Open Journal of Mathematical Optimization&lt;/em&gt;, 3, bài 4. &lt;a href=&quot;https://doi.org/10.5802/ojmo.15&quot;&gt;doi:10.5802/ojmo.15&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Kuhn, D., Esfahani, P. M., Nguyen, V. A., &amp;amp; Shafieezadeh-Abadeh, S. (2019). Wasserstein distributionally robust optimization: Theory and applications in machine learning. Trong &lt;em&gt;Operations Research &amp;amp; Management Science in the Age of Analytics&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Fioretto, F., Mak, T. W. K., &amp;amp; Van Hentenryck, P. (2020). Predicting AC optimal power flows: Combining deep learning and Lagrangian dual methods. &lt;em&gt;AAAI&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Donti, P. L., Rolnick, D., &amp;amp; Kolter, J. Z. (2021). DC3: A learning method for optimization with hard constraints. &lt;em&gt;ICLR&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257).&lt;/li&gt;
  &lt;li&gt;Agarwal, A., Beygelzimer, A., Dudík, M., Langford, J., &amp;amp; Wallach, H. (2018). A reductions approach to fair classification. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Cotter, A., et al. (2019). Optimization with non-differentiable constraints with applications to fairness, recall, churn, and other goals. &lt;em&gt;JMLR&lt;/em&gt;, 20(172).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>11-08 Ứng dụng hiện đại của đối ngẫu Lagrange</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_08_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_08_modern_applications</id>
   <content type="html">&lt;p&gt;Trong thực tế giai đoạn 2022–2026, rất ít mô hình học máy hay hệ thống điều khiển được chạy trong “phòng thí nghiệm lý tưởng” nơi phân phối dữ liệu kiểm thử giống hệt dữ liệu huấn luyện. Khi khí hậu biến đổi, hành vi người dùng dịch chuyển, hay cảm biến lưới điện bị nhiễu, mô hình tối ưu theo kỳ vọng thực nghiệm thông thường có thể sụp đổ đột ngột. Giải pháp đột phá của thập kỷ hiện tại là &lt;strong&gt;Tối ưu bền vững theo phân phối (Distributionally Robust Optimization — DRO)&lt;/strong&gt;: thay vì tối thiểu hóa mất mát trung bình trên đúng phân phối mẫu \(\hat{P}\), ta tối thiểu hóa &lt;strong&gt;mất mát kỳ vọng xấu nhất&lt;/strong&gt; trên toàn bộ một quả cầu phân phối \(Q\) nằm gần \(\hat{P}\) (theo khoảng cách Wasserstein hay \(f\)-divergence)!&lt;/p&gt;

&lt;p&gt;Nghe qua thì DRO bất khả thi về mặt tính toán vì bài toán bên trong \(\sup_{Q \in \mathcal{B}(\hat{P}, \rho)} \mathbb{E}_Q[\ell(x, \xi)]\) tối ưu trên một &lt;strong&gt;không gian vô hạn chiều các phân phối xác suất&lt;/strong&gt;! Nhưng phép màu của Chương 11 xuất hiện đúng lúc: bằng cách áp dụng &lt;strong&gt;đối ngẫu mạnh Lagrange&lt;/strong&gt; lên bài toán con vô hạn chiều ấy, ta biến nó thành một &lt;strong&gt;bài toán tối ưu lồi hữu hạn chiều chỉ có đúng 1 biến nhân tử Lagrange vô hướng \(\lambda \ge 0\)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-ứng-dụng-hiện-đại-của-đối-ngẫu-lagrange-20222026&quot;&gt;Kiến thức cần nhớ: Bốn nhánh ứng dụng hiện đại của đối ngẫu Lagrange (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu bền vững theo phân phối (DRO):&lt;/strong&gt; Đối ngẫu mạnh biến bài toán minimax trên không gian phân phối xác suất (Wasserstein / KL / \(\chi^2\)-divergence) thành bài toán có số hạng điều chuẩn tường minh — hé lộ mối liên hệ sâu sắc rằng DRO thực chất tương đương với việc thêm điều chuẩn chuẩn Lipschitz lên mô hình!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc vật lý cứng trong lưới điện và kỹ thuật (OPF-DNN &amp;amp; DC3):&lt;/strong&gt; Kết hợp mạng nơ-ron dự đoán nhanh với bước sửa ràng buộc bằng hàm Lagrangian tăng cường (Augmented Lagrangian) giúp giải bài toán điều phối công suất xoay chiều (AC-OPF) nhanh gấp trăm lần bộ giải cổ điển mà vẫn bảo đảm không vi phạm giới hạn nhiệt hay điện áp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học máy công bằng như trò chơi yên ngựa Lagrange:&lt;/strong&gt; Ràng buộc công bằng giữa các nhóm nhân khẩu học được đưa vào hàm Lagrangian và giải bằng vòng lặp cực tiểu hóa theo trọng số mô hình xen kẽ cực đại hóa theo nhân tử Lagrange.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Máy vector hỗ trợ (SVM) và thủ thuật nhân (Kernel Trick):&lt;/strong&gt; Nhờ đối ngẫu mạnh (Slater tự động thỏa cho ràng buộc affine), bài toán đối ngẫu SVM chỉ phụ thuộc vào tích vô hướng \(x_i^T x_j\), mở cửa cho mọi nhân phi tuyến \(K(x_i, x_j)\) trong không gian Hilbert vô hạn chiều!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-đối-ngẫu-lagrange-cho-bài-toán-dro-2-trạng-thái&quot;&gt;Giải thích: Tính tay đối ngẫu Lagrange cho bài toán DRO 2 trạng thái&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Giả sử một quyết định đầu tư có 2 kịch bản mất mát là \(\ell_1 = 1\) và \(\ell_2 = 5\). Phân phối thực nghiệm hiện tại là \(\hat{p} = (0.5, 0.5)\) (mất mát trung bình \(0.5(1) + 0.5(5) = 3.0\)). Ta muốn tìm &lt;strong&gt;mất mát kỳ vọng xấu nhất&lt;/strong&gt; trên mọi phân phối \(q = (q_1, q_2)\) cách \(\hat{p}\) không quá \(\rho = 0.2\) theo chuẩn \(\ell_1\) (tức $$&lt;/td&gt;
      &lt;td&gt;q_1 - 0.5&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;q_2 - 0.5&lt;/td&gt;
      &lt;td&gt;\le 0.2\(,\)q_1 + q_2 = 1, q \ge 0$$).&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải trực tiếp bài toán gốc (vì chỉ có 2 trạng thái):&lt;/strong&gt;
Để mất mát lớn nhất, ta chuyển tối đa xác suất từ kịch bản nhẹ (\(\ell_1 = 1\)) sang kịch bản nặng (\(\ell_2 = 5\)): với \(|q_1 - 0.5| + |q_2 - 0.5| = 2|q_2 - 0.5| \le 0.2 \implies q_2 \le 0.6\).
Phân phối xấu nhất là \(q^* = (0.4, 0.6)\), cho mất mát xấu nhất \(p^* = 0.4(1) + 0.6(5) = 3.4\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bằng đối ngẫu Lagrange (chỉ 1 nhân tử phạt \(\lambda \ge 0\) cho ngân sách \(\rho = 0.2\)):&lt;/strong&gt;
Đặt \(\Delta = q - \hat{p} = (-\delta, +\delta)\) với \(2|\delta| \le 0.2\). Hàm Lagrangian theo \(\delta\) là:
\(L(\delta, \lambda) = 3.0 + (5 - 1)\delta + \lambda(0.2 - 2|\delta|) = 3.0 + 0.2\lambda + (4\delta - 2\lambda|\delta|).\)
Để \(\sup_\delta L(\delta, \lambda)\) hữu hạn (không vọt lên \(+\infty\)), ta bắt buộc có \(2\lambda \ge 4 \implies \lambda \ge 2\)! Khi đó \(\sup_\delta (4\delta - 2\lambda|\delta|) = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa hàm đối ngẫu \(g(\lambda) = 3.0 + 0.2\lambda\) trên \(\lambda \ge 2\):&lt;/strong&gt;
Đạt tại \(\lambda^* = 2\) với \(d^* = 3.0 + 0.2(2) = 3.4 = p^*\)!
Ý nghĩa tuyệt đẹp: mất mát DRO bằng &lt;strong&gt;mất mát thực nghiệm (\(3.0\)) cộng thêm bán kính bền vững (\(0.2\)) nhân biên độ dao động mất mát (\(\frac{5-1}{2} = 2\))&lt;/strong&gt; — đúng là công thức điều chuẩn hóa từ đối ngẫu Lagrange!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-đối-ngẫu-lagrange&quot;&gt;Ứng dụng hiện đại của đối ngẫu Lagrange&lt;/h1&gt;

&lt;p&gt;Chương 11 mở rộng lý thuyết đối ngẫu từ quy hoạch tuyến tính sang các bài toán tối ưu tổng quát: hàm Lagrangian \(L(x,u,v)\), hàm đối ngẫu \(g(u,v)=\inf_x L\), tính đối ngẫu yếu \(g\le f^\star\) và tính đối ngẫu mạnh khi bài toán lồi kèm điều kiện chuẩn hóa ràng buộc. Bài đọc tùy chọn này trình bày bốn ứng dụng hiện đại của cơ chế đối ngẫu đó — trong đó nhân tử Lagrange đóng vai trò như giá biên, bán kính bền vững hoặc tín hiệu huấn luyện.&lt;/p&gt;

&lt;h2 id=&quot;1-tối-ưu-bền-vững-theo-phân-phối-dro&quot;&gt;1. Tối ưu bền vững theo phân phối (DRO)&lt;/h2&gt;

&lt;p&gt;Thay vì cực tiểu hóa rủi ro thực nghiệm \(\mathbb{E}_{\hat P}[\ell(x,\xi)]\), bài toán tối ưu bền vững theo phân phối (Distributionally Robust Optimization – DRO) giải:&lt;/p&gt;

\[\min_x\ \sup_{P\in\mathcal{P}}\ \mathbb{E}_P[\ell(x,\xi)],\]

&lt;p&gt;trong đó tập bất định \(\mathcal{P}\) là một quả cầu phân phối (theo phân kỳ \(\phi\) hoặc khoảng cách Wasserstein) quanh phân phối thực nghiệm. Bài toán \(\sup\) bên trong là một bài toán &lt;strong&gt;liên hợp / đối ngẫu&lt;/strong&gt;: với quả cầu Wasserstein, nó biến đổi thành bài toán cực tiểu hóa rủi ro có điều chuẩn, trong đó biến đối ngẫu đóng vai trò như hằng số phạt Lipschitz cho chi phí dịch chuyển khối lượng xác suất. Rahimian và Mehrotra (2022) tổng hợp lý thuyết đối ngẫu, cách chọn tập \(\mathcal{P}\) và các bộ giải tương ứng. Công trình hướng dẫn về Wasserstein DRO của Kuhn, Esfahani, Nguyen và Shafieezadeh-Abadeh (2019) vẫn được trích dẫn rộng rãi giai đoạn 2023–2026 trong các nghiên cứu học máy về nhãn nhiễu, dịch chuyển phân phối và huấn luyện đối kháng. Chính tính đối ngẫu mạnh giúp chuyển bài toán kỳ vọng trường hợp xấu nhất vô hạn chiều thành một bài toán lồi hữu hạn chiều có thể giải bằng CVXPY.&lt;/p&gt;

&lt;h2 id=&quot;2-ràng-buộc-cứng-trong-năng-lượng-và-vật-lý-opf-dnn-và-dc3&quot;&gt;2. Ràng buộc cứng trong năng lượng và vật lý: OPF-DNN và DC3&lt;/h2&gt;

&lt;p&gt;Bài toán luồng công suất tối ưu xoay chiều (AC-OPF) là một bài toán tối ưu không lồi với các phương trình đẳng thức Kirchhoff và giới hạn nhiệt của đường dây. Fioretto, Mak và Van Hentenryck (AAAI 2020) huấn luyện mạng nơ-ron dự đoán điểm vận hành đồng thời &lt;strong&gt;cập nhật nhân tử Lagrange bằng các bước dưới đạo hàm (subgradient)&lt;/strong&gt; theo độ vi phạm ràng buộc — sử dụng đối ngẫu Lagrange trực tiếp như một vòng lặp huấn luyện. Donti, Rolnick và Kolter (ICLR 2021) đề xuất phương pháp &lt;strong&gt;DC3&lt;/strong&gt;: hoàn tất các ràng buộc đẳng thức một cách khả vi, rồi hiệu chỉnh các ràng buộc bất đẳng thức bằng các bước gradient trải phẳng (unrolled), và kiểm chứng trên bài toán AC-OPF. Các nghiên cứu “học để tối ưu” (learning to optimize) giai đoạn 2022–2025 tiếp tục khai thác cùng cơ chế này: nhân tử Lagrange không chỉ là chứng chỉ kiểm tra sau khi giải, mà trở thành tín hiệu trực tiếp định hướng quá trình huấn luyện mạng.&lt;/p&gt;

&lt;p&gt;Cần lưu ý rằng tính đối ngẫu yếu vẫn cung cấp cận dưới ngay cả khi bài toán gốc không lồi, nhưng tính đối ngẫu mạnh không tự động được bảo đảm — đây chính là ranh giới quan trọng của Chương 11.&lt;/p&gt;

&lt;h2 id=&quot;3-quy-giảm-công-bằng-như-một-trò-chơi-đối-ngẫu&quot;&gt;3. Quy giảm công bằng như một trò chơi đối ngẫu&lt;/h2&gt;

&lt;p&gt;Agarwal và cộng sự (2018) cùng phương pháp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExponentiatedGradient&lt;/code&gt; trong thư viện Fairlearn (Weerts và cộng sự, 2023) biểu diễn các ràng buộc công bằng theo nhóm dưới dạng một hàm Lagrangian. Trong trò chơi hai người tương ứng, phía đối ngẫu tăng trọng số lên các nhóm đang bị vi phạm ràng buộc, còn phía gốc giải bài toán cực tiểu hóa rủi ro thực nghiệm (ERM) có trọng số. Cotter và cộng sự (2019) mở rộng khung này sang các ràng buộc tỷ lệ không khả vi thông qua proxy-Lagrangian. Ở cả ba phương pháp, \(v \ge 0\) là nhân tử Lagrange cho ràng buộc bất đẳng thức \(g_i(x) \le 0\), và theo điều kiện bù (Chương 12), nhóm nào đã thỏa mãn chặt chẽ tiêu chí công bằng (ràng buộc lỏng) sẽ có nhân tử \(v_i = 0\).&lt;/p&gt;

&lt;h2 id=&quot;4-máy-vector-hỗ-trợ-svm-và-phương-pháp-nhân-kernel&quot;&gt;4. Máy vector hỗ trợ (SVM) và phương pháp nhân (kernel)&lt;/h2&gt;

&lt;p&gt;Bài toán SVM lề mềm là ví dụ kinh điển của tối ưu tổng quát với bài toán đối ngẫu là một quy hoạch bậc hai có ràng buộc hộp trên các hệ số \(\alpha_i\). Trình giải &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SVC&lt;/code&gt; trong scikit-learn cùng nhiều nghiên cứu giai đoạn 2022–2026 trong sinh học tính toán và bài toán dữ liệu bảng cỡ nhỏ vẫn giải trực tiếp bài toán đối ngẫu, bởi kỹ thuật nhân (kernel trick) được áp dụng trên hàm đối ngẫu \(g(\alpha)\) thay vì trực tiếp trên vector trọng số \(w\). Dạng điều kiện tối ưu KKT sẽ được phân tích ở Chương 12, còn cơ sở tồn tại của hàm đối ngẫu \(g\) nằm ở chương này.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;p&gt;Quy trình tổng quát gồm ba bước: lập hàm Lagrangian, cực tiểu hóa theo \(x\) để thu được hàm đối ngẫu \(g\), và cực đại hóa \(g\) theo các nhân tử đối ngẫu. Khi bài toán gốc lồi và thỏa mãn một điều kiện chuẩn hóa ràng buộc (CQ), ta có thể hoán đổi thứ tự \(\inf\) và \(\sup\) (đối ngẫu mạnh). DRO, mạng nơ-ron có ràng buộc vật lý, quy giảm công bằng và SVM nhân là bốn ứng dụng khác nhau của cùng nguyên lý này.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi tự kiểm tra:&lt;/strong&gt; Trong bài toán Wasserstein DRO, một biến đối ngẫu tối ưu có giá trị lớn ứng với bán kính quả cầu cho biết điều gì về độ nhạy với dịch chuyển phân phối, và bất đẳng thức nào trong chương này bảo đảm giá trị đó tạo thành cận dưới hợp lệ cho rủi ro trường hợp xấu nhất?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Rahimian, H., &amp;amp; Mehrotra, S. (2022). Frameworks and results in distributionally robust optimization. &lt;em&gt;Open Journal of Mathematical Optimization&lt;/em&gt;, 3, bài 4. &lt;a href=&quot;https://doi.org/10.5802/ojmo.15&quot;&gt;doi:10.5802/ojmo.15&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Kuhn, D., Esfahani, P. M., Nguyen, V. A., &amp;amp; Shafieezadeh-Abadeh, S. (2019). Wasserstein distributionally robust optimization: Theory and applications in machine learning. Trong &lt;em&gt;Operations Research &amp;amp; Management Science in the Age of Analytics&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Fioretto, F., Mak, T. W. K., &amp;amp; Van Hentenryck, P. (2020). Predicting AC optimal power flows: Combining deep learning and Lagrangian dual methods. &lt;em&gt;AAAI&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Donti, P. L., Rolnick, D., &amp;amp; Kolter, J. Z. (2021). DC3: A learning method for optimization with hard constraints. &lt;em&gt;ICLR&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257).&lt;/li&gt;
  &lt;li&gt;Agarwal, A., Beygelzimer, A., Dudík, M., Langford, J., &amp;amp; Wallach, H. (2018). A reductions approach to fair classification. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Cotter, A., et al. (2019). Optimization with non-differentiable constraints with applications to fairness, recall, churn, and other goals. &lt;em&gt;JMLR&lt;/em&gt;, 20(172).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>10-10 Ứng dụng hiện đại của đối ngẫu LP</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_10_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_10_modern_applications</id>
   <content type="html">&lt;p&gt;Nếu có ai hỏi &lt;em&gt;“Học biến đối ngẫu và giá bóng LP để làm gì ngoài đời?”&lt;/em&gt;, hãy kể cho họ nghe về hóa đơn tiền điện mỗi tháng. Trên các thị trường điện hiện đại như PJM, ERCOT hay châu Âu, cứ mỗi 5 đến 15 phút, một bài toán quy hoạch tuyến tính khổng lồ lại được giải để quyết định nhà máy điện nào phát bao nhiêu megawatt sao cho chi phí toàn hệ thống thấp nhất mà không làm quá tải bất kỳ đường dây truyền tải nào. Và con số quyết định giá mua bán điện tại từng khu vực không phải do ai đoán mò — nó chính là &lt;strong&gt;nghiệm đối ngẫu (giá bóng)&lt;/strong&gt; của ràng buộc cân bằng cung–cầu!&lt;/p&gt;

&lt;p&gt;Bài đọc tổng kết ứng dụng cuối chương này kết nối trực tiếp lý thuyết đối ngẫu LP của Chương 10 với bốn lĩnh vực mũi nhọn giai đoạn 2022–2026: kiểm chứng mạng nơ-ron, thị trường năng lượng, thuật toán luồng đồ thị tốc độ gần tuyến tính và vận chuyển tối ưu — giúp bạn nhìn thấy tư duy Primal–Dual đang vận hành thế giới thực như thế nào.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-góc-nhìn-công-nghiệp-về-sức-mạnh-của-đối-ngẫu-lp&quot;&gt;Kiến thức cần nhớ: Bốn góc nhìn công nghiệp về sức mạnh của đối ngẫu LP&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Giá bóng trong kinh tế năng lượng (Market Clearing &amp;amp; Shadow Pricing):&lt;/strong&gt; Nghiệm đối ngẫu của ràng buộc \(\sum_g p_g = D\) đo chính xác chi phí biên để cung cấp thêm 1 MWh điện; khi đường dây truyền tải bị nghẽn (ràng buộc bất đẳng thức chặt), biến đối ngẫu của đường dây trở nên dương và tạo ra chênh lệch giá giữa hai vùng!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chứng chỉ an toàn không cần giải chính xác (Dual Bounds in AI Safety):&lt;/strong&gt; Trong bài toán kiểm chứng độ bền vững mạng nơ-ron, bất kỳ điểm khả thi nào của bài toán đối ngẫu LP đều là một cận dưới toán học hợp lệ, cho phép chứng nhận an toàn nhanh gấp hàng nghìn lần giải Primal LP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu Kantorovich trong học máy phân phối (Optimal Transport):&lt;/strong&gt; Thay vì giải LP có \(n^2\) biến vận chuyển giữa hai đám mây điểm cỡ \(n\), bài toán đối ngẫu chỉ có \(2n\) biến thế năng (potentials), giúp tính khoảng cách Wasserstein khả thi trên tập dữ liệu lớn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán luồng đồ thị thế hệ mới:&lt;/strong&gt; Các bước tiến gần tuyến tính sau 2022 cho bài toán Max Flow / Min-Cost Flow đều khai thác cấu trúc cây khung và phép cập nhật song hành trên cả biến luồng gốc lẫn thế năng đỉnh đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-giá-điện-biên-giá-bóng-đối-ngẫu-cho-hệ-thống-2-nhà-máy&quot;&gt;Giải thích: Tính tay giá điện biên (giá bóng đối ngẫu) cho hệ thống 2 nhà máy&lt;/h3&gt;

&lt;p&gt;Giả sử lưới điện cần đáp ứng phụ tải \(D = 130\) MWh bằng 2 nhà máy phát điện:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nhà máy 1 (thủy điện): công suất tối đa \(100\) MWh, chi phí phát \(20\) USD/MWh.&lt;/li&gt;
  &lt;li&gt;Nhà máy 2 (nhiệt điện khí): công suất tối đa \(100\) MWh, chi phí phát \(50\) USD/MWh.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập và giải bài toán gốc (LP điều phối tối thiểu hóa chi phí):&lt;/strong&gt;
\(\min_{p_1, p_2} \; 20 p_1 + 50 p_2 \quad \text{s.t.} \quad \begin{cases} p_1 + p_2 = 130 &amp;amp; (\text{giá bóng } \lambda \in \mathbb{R}) \\ 0 \le p_1 \le 100 &amp;amp; (\text{phí nghẽn } \mu_1 \ge 0) \\ 0 \le p_2 \le 100 &amp;amp; (\text{phí nghẽn } \mu_2 \ge 0) \end{cases}\)
Hiển nhiên ta khai thác tối đa nhà máy rẻ trước: \(p_1^* = 100\) MWh, phần còn lại lấy từ nhà máy đắt: \(p_2^* = 30\) MWh. Tổng chi phí: \(20(100) + 50(30) = 3{,}500\) USD.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đọc ra nghiệm đối ngẫu (giá điện thị trường \(\lambda^*\) và lợi nhuận nghẽn \(\mu_1^*, \mu_2^*\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nhà máy 2 chưa chạm trần (\(0 &amp;lt; 30 &amp;lt; 100\)) \(\implies\) theo điều kiện bù, \(\mu_2^* = 0\) và điều kiện dừng \(50 - \lambda^* + \mu_2^* = 0 \implies \lambda^* = 50\) USD/MWh!&lt;/li&gt;
      &lt;li&gt;Nhà máy 1 chạm trần (\(p_1^* = 100\)) \(\implies\) \(20 - \lambda^* + \mu_1^* = 0 \implies \mu_1^* = 50 - 20 = 30\) USD/MWh!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng ý nghĩa giá bóng:&lt;/strong&gt; Nếu nhu cầu tăng thêm \(1\) MWh (lên \(131\) MWh), chỉ nhà máy 2 còn dư công suất nên chi phí hệ thống tăng đúng \(\lambda^* = 50\) USD; còn nếu mở rộng nhà máy thủy điện thêm \(1\) MWh (lên \(101\) MWh), nó thay thế \(1\) MWh nhiệt điện khí và tiết kiệm cho hệ thống đúng \(\mu_1^* = 30\) USD!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-đối-ngẫu-lp&quot;&gt;Ứng dụng hiện đại của đối ngẫu LP&lt;/h1&gt;

&lt;p&gt;Chương 10 đã trình bày cách xây dựng bài toán đối ngẫu của quy hoạch tuyến tính, tính đối ngẫu yếu và mạnh, điều kiện bù, cùng hai ví dụ kinh điển là luồng cực đại – lát cắt cực tiểu và trò chơi ma trận. Bài đọc tùy chọn này giới thiệu bốn lĩnh vực trong khoa học máy tính và khoa học dữ liệu giai đoạn 2022–2026 nơi các chứng chỉ đối ngẫu đó được sử dụng trực tiếp.&lt;/p&gt;

&lt;p&gt;Với một LP gốc \(\min\{c^\top x:Ax=b,\,Gx\le h\}\) và bài toán đối ngẫu tương ứng, mọi cặp biến đối ngẫu khả thi \((u, v)\) đều tạo thành một &lt;strong&gt;cận dưới&lt;/strong&gt; cho giá trị tối ưu gốc; tại điểm tối ưu, cận này đạt dấu bằng và mọi ràng buộc bất đẳng thức không chặt đều có nhân tử đối ngẫu bằng \(0\).&lt;/p&gt;

&lt;h2 id=&quot;1-kiểm-chứng-mạng-nơ-ron-qua-lp-và-mặt-cắt&quot;&gt;1. Kiểm chứng mạng nơ-ron qua LP và mặt cắt&lt;/h2&gt;

&lt;p&gt;Bài toán kiểm tra xem một bộ phân loại có bị đổi nhãn trong vùng nhiễu \(\ell_\infty\) hay không là một bài toán không lồi do các hàm kích hoạt ReLU. Cách nới lỏng tiêu chuẩn là thay mỗi hàm ReLU bằng bao lồi dạng tam giác tuyến tính (Ehlers; Wong và Kolter). Khi đó, các biến đối ngẫu của LP nới lỏng đóng vai trò là &lt;strong&gt;nhân tử lan truyền cận&lt;/strong&gt;. Zhang, Wang, Xu, Li, Li, Jana, Hsieh và Kolter (NeurIPS 2022) đã bổ sung &lt;strong&gt;mặt cắt tổng quát&lt;/strong&gt; vào bài toán đối ngẫu này (GCP-CROWN) và tích hợp vào công cụ &lt;strong&gt;\(\alpha,\beta\)-CROWN&lt;/strong&gt; — hệ thống đứng đầu cuộc thi International Verification of Neural Networks (VNN-COMP) liên tiếp các năm 2021–2025. Phần tính toán hiệu năng cao nằm ở bước lan truyền cận trên GPU, còn chứng chỉ toán học vẫn dựa trên nguyên lý cơ bản: nếu giá trị đối ngẫu của LP đã siết chặt lớn hơn \(0\), thì không tồn tại ví dụ đối kháng nào trong vùng xét.&lt;/p&gt;

&lt;p&gt;Ở đây, tính đối ngẫu yếu của Chương 10 được dùng trực tiếp như một &lt;strong&gt;chứng chỉ an toàn&lt;/strong&gt;, chứ không mang ý nghĩa định giá kinh tế.&lt;/p&gt;

&lt;h2 id=&quot;2-thị-trường-điện-lp-khớp-lệnh-và-giá-bóng&quot;&gt;2. Thị trường điện: LP khớp lệnh và giá bóng&lt;/h2&gt;

&lt;p&gt;Thị trường điện năng ngày tới (day-ahead) vận hành dựa trên một bài toán quy hoạch tuyến tính hỗn hợp nguyên nhằm cực tiểu hóa tổng chi phí chào giá dưới các ràng buộc cân bằng công suất và giới hạn truyền tải đường dây. Biến đối ngẫu của bản nới lỏng tuyến tính tương ứng chính là vector &lt;strong&gt;giá biên theo vị trí&lt;/strong&gt; (Locational Marginal Price – LMP). Sau biến động giá năng lượng tại châu Âu năm 2022, các biến đối ngẫu này phản ánh trực tiếp con số trên hóa đơn điện. Liang và Dvorkin (ACM e-Energy 2023) đã sử dụng tối ưu nghịch trên lịch phát điện và dữ liệu LMP công bố để khôi phục mức giá chào của các nhà máy bằng cách giải ngược hệ điều kiện KKT và quan hệ đối ngẫu của LP khớp lệnh. Nhiều nghiên cứu giai đoạn 2022–2023 về đấu giá điện ngày tới ở châu Âu cũng biểu diễn giá theo vùng trực tiếp như biến đối ngẫu của bài toán LP tối đa hóa phúc lợi có ràng buộc lưới truyền tải.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liên hệ với giáo trình:&lt;/strong&gt; Điều kiện bù khẳng định chỉ những đường dây bị nghẽn (\(Gx = h\)) mới có thành phần giá tắc nghẽn \(v\) khác \(0\).&lt;/p&gt;

&lt;h2 id=&quot;3-bài-toán-luồng-cực-đại--lát-cắt-cực-tiểu-sau-năm-2022&quot;&gt;3. Bài toán luồng cực đại – lát cắt cực tiểu sau năm 2022&lt;/h2&gt;

&lt;p&gt;Định lý trong bài &lt;a href=&quot;/contents/vi/chapter10/10_03_Max_flow_and_min_cut/&quot;&gt;10-03&lt;/a&gt; tiếp tục là cơ sở cho các bài toán phân đoạn ảnh, phát hiện cộng đồng và đánh giá độ tin cậy mạng truyền thông. Các bộ giải quy mô lớn hiện nay (như Gurobi, HiGHS, OR-Tools) đều xuất trực tiếp vector nghiệm đối ngẫu; các quy trình khoa học dữ liệu liên quan đến phân bổ băng thông hay phân tách đồ thị nguồn – đích đều khai thác trực tiếp vector này. Một hướng kết hợp phổ biến gần đây trong khoa học máy tính là học dung lượng cạnh bằng mạng nơ-ron đồ thị (GNN), sau đó đặt bài toán đối ngẫu luồng cực đại cổ điển như một lớp tối ưu bên trong — tương tự tư tưởng tối ưu khả vi ở Chương 12, nhưng bài toán lõi là một LP.&lt;/p&gt;

&lt;h2 id=&quot;4-vận-chuyển-tối-ưu-như-một-bài-toán-lp-cỡ-lớn&quot;&gt;4. Vận chuyển tối ưu như một bài toán LP cỡ lớn&lt;/h2&gt;

&lt;p&gt;Bài toán vận chuyển tối ưu Kantorovich:&lt;/p&gt;

\[\min_{\pi\ge 0}\ \langle C,\pi\rangle\quad\text{s.t.}\quad \pi\mathbf{1}=a,\ \pi^\top\mathbf{1}=b\]

&lt;p&gt;là một bài toán LP. Bài toán đối ngẫu của nó là \(\max_{f,g} f^\top a + g^\top b\) với ràng buộc \(f_i + g_j \le C_{ij}\), trong đó \((f, g)\) được gọi là các &lt;strong&gt;thế Kantorovich&lt;/strong&gt; (Kantorovich potentials). Chuyên khảo của Peyré và Cuturi (2019) vẫn là tài liệu chuẩn cho các bài toán tính toán vận chuyển tối ưu; các ứng dụng giai đoạn 2022–2026 như thích nghi miền, chưng cất dữ liệu và căn chỉnh dữ liệu đơn bào vẫn giải phiên bản có điều chuẩn (Sinkhorn) hoặc không điều chuẩn, rồi đọc nghiệm đối ngẫu như một ánh xạ ghép mềm. Theo tính đối ngẫu yếu, không có phương án vận chuyển nào có chi phí thấp hơn giá trị của bất kỳ cặp thế khả thi nào.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;p&gt;Đối ngẫu LP đóng vai trò như một &lt;strong&gt;chứng chỉ&lt;/strong&gt;: chứng chỉ bất khả thi (trong kiểm chứng mạng nơ-ron), giá biên (trong thị trường điện), lát cắt (trong mạng luồng) hoặc cận chi phí ghép (trong vận chuyển tối ưu). Nếu ta tìm được một nghiệm gốc khả thi và một nghiệm đối ngẫu khả thi có cùng giá trị mục tiêu, bài toán đã được giải tối ưu theo tính đối ngẫu mạnh của LP.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi tự kiểm tra:&lt;/strong&gt; Trong GCP-CROWN, vì sao việc &lt;em&gt;bổ sung&lt;/em&gt; một mặt cắt hợp lệ vào LP gốc chỉ có thể làm &lt;em&gt;tăng&lt;/em&gt; (hoặc giữ nguyên) cận dưới đối ngẫu? Kết quả nào trong chương này giải thích điều đó?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Zhang, H., Wang, S., Xu, K., Li, L., Li, B., Jana, S., Hsieh, C.-J., &amp;amp; Kolter, J. Z. (2022). General cutting planes for bound-propagation-based neural network verification. &lt;em&gt;NeurIPS&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2208.05740&quot;&gt;arXiv:2208.05740&lt;/a&gt;. Công cụ: &lt;a href=&quot;https://github.com/Verified-Intelligence/alpha-beta-CROWN&quot;&gt;α,β-CROWN&lt;/a&gt; (vô địch VNN-COMP 2021–2025).&lt;/li&gt;
  &lt;li&gt;Liang, Z., &amp;amp; Dvorkin, Y. (2023). Data-driven inverse optimization for marginal offer price recovery in electricity markets. &lt;em&gt;ACM e-Energy ’23&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Peyré, G., &amp;amp; Cuturi, M. (2019). Computational optimal transport. &lt;em&gt;Foundations and Trends in Machine Learning&lt;/em&gt;, 11(5–6). (tham chiếu LP/đối ngẫu chuẩn vẫn dùng trong pipeline OT 2022–2026)&lt;/li&gt;
  &lt;li&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;, Ch. 5 (đối ngẫu LP và giá bóng).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>10-07 Ứng dụng hiện đại của đối ngẫu LP</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_07_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_07_modern_applications</id>
   <content type="html">&lt;p&gt;Quy hoạch tuyến tính và tính đối ngẫu của nó đã gần 80 tuổi, nhưng giai đoạn 2022–2026 lại chứng kiến một cuộc “hồi sinh rực rỡ” của đối ngẫu LP trong những bài toán tiên phong nhất của trí tuệ nhân tạo và khoa học dữ liệu. Từ việc &lt;strong&gt;chứng nhận an toàn cho mạng nơ-ron sâu&lt;/strong&gt; (khẳng định không tồn tại bất kỳ nhiễu đối kháng nào đánh lừa được mô hình), định giá điện năng theo thời gian thực trên lưới điện quốc gia, cho tới bài toán vận chuyển tối ưu (Optimal Transport / khoảng cách Wasserstein) so sánh hai phân phối xác suất trong mô hình sinh — tất cả đều chạy dựa trên cặp Primal–Dual LP!&lt;/p&gt;

&lt;p&gt;Điểm mấu chốt khiến đối ngẫu LP trở nên bất khả chiến bại trong các ứng dụng kiểm chứng an toàn là &lt;strong&gt;tính đối ngẫu yếu&lt;/strong&gt;: ngay cả khi bạn không có đủ thời gian giải bài toán LP hàng triệu biến tới nghiệm chính xác tuyệt đối, &lt;em&gt;bất kỳ nghiệm đối ngẫu khả thi nào&lt;/em&gt; cũng đã cung cấp ngay một &lt;strong&gt;chứng chỉ cận dưới toán học 100% chặt chẽ&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-miền-ứng-dụng-hiện-đại-của-đối-ngẫu-lp-20222026&quot;&gt;Kiến thức cần nhớ: Bốn miền ứng dụng hiện đại của đối ngẫu LP (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng mạng nơ-ron (Neural Network Verification — \(\alpha,\beta\)-CROWN):&lt;/strong&gt; Nới lỏng hàm kích hoạt phi tuyến ReLU \(y = \max(0, x)\) trên đoạn \([l, u]\) thành một tam giác lồi (Planet relaxation) biến bài toán kiểm chứng thành LP; giải bài toán đối ngẫu trên GPU cho ra cận dưới an toàn chỉ trong vài mili-giây!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thị trường điện và giá bóng theo nút (Locational Marginal Pricing — LMP):&lt;/strong&gt; Bộ điều độ lưới điện giải LP điều phối công suất phát (DC-OPF) mỗi 5 phút; biến đối ngẫu của ràng buộc cân bằng cung–cầu tại mỗi nút lưới chính là giá điện bán buôn tại địa điểm đó!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Luồng cực đại – lát cắt cực tiểu thời gian gần tuyến tính:&lt;/strong&gt; Đột phá lý thuyết năm 2022 (Chen–Kyng–Liu–Peng–Probst Gutenberg–Sachdeva) giải Max Flow và Min-Cost Flow trong thời gian gần tuyến tính \(m^{1+o(1)}\) nhờ kết hợp phương pháp điểm trong với cấu trúc dữ liệu động trên cặp Primal–Dual.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vận chuyển tối ưu (Optimal Transport / Earth Mover’s Distance):&lt;/strong&gt; Bài toán Kantorovich tìm kế hoạch vận chuyển khối lượng xác suất rẻ nhất là một LP khổng lồ, còn bài toán đối ngẫu Kantorovich–Rubinstein chính là nền tảng của WGAN và các thước đo khoảng cách phân phối hiện đại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-nới-lỏng-tam-giác-lp-cho-một-nơ-ron-relu&quot;&gt;Giải thích: Tính tay nới lỏng tam giác LP cho một nơ-ron ReLU&lt;/h3&gt;

&lt;p&gt;Trong kiểm chứng mạng nơ-ron, giả sử đầu vào \(x\) của một nút ReLU \(y = \max(0, x)\) bị chặn trong đoạn \([l, u] = [-1, 2]\) (trạng thái không ổn định vì \(l &amp;lt; 0 &amp;lt; u\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Dựng ba ràng buộc tuyến tính bao quanh đồ thị gấp khúc \(y = \max(0, x)\) trên \([-1, 2]\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hai cạnh dưới (nằm dưới chữ V): \(y \ge 0\) và \(y \ge x\).&lt;/li&gt;
      &lt;li&gt;Một cạnh trên nối hai đầu mút \((-1, 0)\) và \((2, 2)\):
\(y \le \frac{u}{u - l}(x - l) = \frac{2}{2 - (-1)}(x + 1) = \frac{2}{3}x + \frac{2}{3}.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra độ chặt tại ba điểm mốc:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(x = -1\): \(0 \le y \le \frac{2}{3}(-1 + 1) = 0 \implies y = 0\) (khớp chính xác!).&lt;/li&gt;
      &lt;li&gt;Tại \(x = 2\): \(2 \le y \le \frac{2}{3}(3) = 2 \implies y = 2\) (khớp chính xác!).&lt;/li&gt;
      &lt;li&gt;Tại điểm gãy \(x = 0\): \(0 \le y \le \frac{2}{3}\) (chấp nhận khoảng nới lỏng tối đa \(\frac{2}{3}\) để đổi lấy tính tuyến tính!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vai trò của đối ngẫu LP:&lt;/strong&gt; Bằng cách gán biến đối ngẫu cho 3 ràng buộc tam giác này ở mọi nơ-ron, các trình kiểm chứng như CROWN lan truyền ngược chứng chỉ cận dưới qua toàn bộ mạng nơ-ron mà không cần chạy thuật toán đơn hình chậm chạp!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-đối-ngẫu-lp&quot;&gt;Ứng dụng hiện đại của đối ngẫu LP&lt;/h1&gt;

&lt;p&gt;Chương 10 đã trình bày cách xây dựng bài toán đối ngẫu của quy hoạch tuyến tính, tính đối ngẫu yếu và mạnh, điều kiện bù, cùng hai ví dụ kinh điển là luồng cực đại – lát cắt cực tiểu và trò chơi ma trận. Bài đọc tùy chọn này giới thiệu bốn lĩnh vực trong khoa học máy tính và khoa học dữ liệu giai đoạn 2022–2026 nơi các chứng chỉ đối ngẫu đó được sử dụng trực tiếp.&lt;/p&gt;

&lt;p&gt;Với một LP gốc \(\min\{c^\top x:Ax=b,\,Gx\le h\}\) và bài toán đối ngẫu tương ứng, mọi cặp biến đối ngẫu khả thi \((u, v)\) đều tạo thành một &lt;strong&gt;cận dưới&lt;/strong&gt; cho giá trị tối ưu gốc; tại điểm tối ưu, cận này đạt dấu bằng và mọi ràng buộc bất đẳng thức không chặt đều có nhân tử đối ngẫu bằng \(0\).&lt;/p&gt;

&lt;h2 id=&quot;1-kiểm-chứng-mạng-nơ-ron-qua-lp-và-mặt-cắt&quot;&gt;1. Kiểm chứng mạng nơ-ron qua LP và mặt cắt&lt;/h2&gt;

&lt;p&gt;Bài toán kiểm tra xem một bộ phân loại có bị đổi nhãn trong vùng nhiễu \(\ell_\infty\) hay không là một bài toán không lồi do các hàm kích hoạt ReLU. Cách nới lỏng tiêu chuẩn là thay mỗi hàm ReLU bằng bao lồi dạng tam giác tuyến tính (Ehlers; Wong và Kolter). Khi đó, các biến đối ngẫu của LP nới lỏng đóng vai trò là &lt;strong&gt;nhân tử lan truyền cận&lt;/strong&gt;. Zhang, Wang, Xu, Li, Li, Jana, Hsieh và Kolter (NeurIPS 2022) đã bổ sung &lt;strong&gt;mặt cắt tổng quát&lt;/strong&gt; vào bài toán đối ngẫu này (GCP-CROWN) và tích hợp vào công cụ &lt;strong&gt;\(\alpha,\beta\)-CROWN&lt;/strong&gt; — hệ thống đứng đầu cuộc thi International Verification of Neural Networks (VNN-COMP) liên tiếp các năm 2021–2025. Phần tính toán hiệu năng cao nằm ở bước lan truyền cận trên GPU, còn chứng chỉ toán học vẫn dựa trên nguyên lý cơ bản: nếu giá trị đối ngẫu của LP đã siết chặt lớn hơn \(0\), thì không tồn tại ví dụ đối kháng nào trong vùng xét.&lt;/p&gt;

&lt;p&gt;Ở đây, tính đối ngẫu yếu của Chương 10 được dùng trực tiếp như một &lt;strong&gt;chứng chỉ an toàn&lt;/strong&gt;, chứ không mang ý nghĩa định giá kinh tế.&lt;/p&gt;

&lt;h2 id=&quot;2-thị-trường-điện-lp-khớp-lệnh-và-giá-bóng&quot;&gt;2. Thị trường điện: LP khớp lệnh và giá bóng&lt;/h2&gt;

&lt;p&gt;Thị trường điện năng ngày tới (day-ahead) vận hành dựa trên một bài toán quy hoạch tuyến tính hỗn hợp nguyên nhằm cực tiểu hóa tổng chi phí chào giá dưới các ràng buộc cân bằng công suất và giới hạn truyền tải đường dây. Biến đối ngẫu của bản nới lỏng tuyến tính tương ứng chính là vector &lt;strong&gt;giá biên theo vị trí&lt;/strong&gt; (Locational Marginal Price – LMP). Sau biến động giá năng lượng tại châu Âu năm 2022, các biến đối ngẫu này phản ánh trực tiếp con số trên hóa đơn điện. Liang và Dvorkin (ACM e-Energy 2023) đã sử dụng tối ưu nghịch trên lịch phát điện và dữ liệu LMP công bố để khôi phục mức giá chào của các nhà máy bằng cách giải ngược hệ điều kiện KKT và quan hệ đối ngẫu của LP khớp lệnh. Nhiều nghiên cứu giai đoạn 2022–2023 về đấu giá điện ngày tới ở châu Âu cũng biểu diễn giá theo vùng trực tiếp như biến đối ngẫu của bài toán LP tối đa hóa phúc lợi có ràng buộc lưới truyền tải.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liên hệ với giáo trình:&lt;/strong&gt; Điều kiện bù khẳng định chỉ những đường dây bị nghẽn (\(Gx = h\)) mới có thành phần giá tắc nghẽn \(v\) khác \(0\).&lt;/p&gt;

&lt;h2 id=&quot;3-bài-toán-luồng-cực-đại--lát-cắt-cực-tiểu-sau-năm-2022&quot;&gt;3. Bài toán luồng cực đại – lát cắt cực tiểu sau năm 2022&lt;/h2&gt;

&lt;p&gt;Định lý trong bài &lt;a href=&quot;/contents/vi/chapter10/10_03_Max_flow_and_min_cut/&quot;&gt;10-03&lt;/a&gt; tiếp tục là cơ sở cho các bài toán phân đoạn ảnh, phát hiện cộng đồng và đánh giá độ tin cậy mạng truyền thông. Các bộ giải quy mô lớn hiện nay (như Gurobi, HiGHS, OR-Tools) đều xuất trực tiếp vector nghiệm đối ngẫu; các quy trình khoa học dữ liệu liên quan đến phân bổ băng thông hay phân tách đồ thị nguồn – đích đều khai thác trực tiếp vector này. Một hướng kết hợp phổ biến gần đây trong khoa học máy tính là học dung lượng cạnh bằng mạng nơ-ron đồ thị (GNN), sau đó đặt bài toán đối ngẫu luồng cực đại cổ điển như một lớp tối ưu bên trong — tương tự tư tưởng tối ưu khả vi ở Chương 12, nhưng bài toán lõi là một LP.&lt;/p&gt;

&lt;h2 id=&quot;4-vận-chuyển-tối-ưu-như-một-bài-toán-lp-cỡ-lớn&quot;&gt;4. Vận chuyển tối ưu như một bài toán LP cỡ lớn&lt;/h2&gt;

&lt;p&gt;Bài toán vận chuyển tối ưu Kantorovich:&lt;/p&gt;

\[\min_{\pi\ge 0}\ \langle C,\pi\rangle\quad\text{s.t.}\quad \pi\mathbf{1}=a,\ \pi^\top\mathbf{1}=b\]

&lt;p&gt;là một bài toán LP. Bài toán đối ngẫu của nó là \(\max_{f,g} f^\top a + g^\top b\) với ràng buộc \(f_i + g_j \le C_{ij}\), trong đó \((f, g)\) được gọi là các &lt;strong&gt;thế Kantorovich&lt;/strong&gt; (Kantorovich potentials). Chuyên khảo của Peyré và Cuturi (2019) vẫn là tài liệu chuẩn cho các bài toán tính toán vận chuyển tối ưu; các ứng dụng giai đoạn 2022–2026 như thích nghi miền, chưng cất dữ liệu và căn chỉnh dữ liệu đơn bào vẫn giải phiên bản có điều chuẩn (Sinkhorn) hoặc không điều chuẩn, rồi đọc nghiệm đối ngẫu như một ánh xạ ghép mềm. Theo tính đối ngẫu yếu, không có phương án vận chuyển nào có chi phí thấp hơn giá trị của bất kỳ cặp thế khả thi nào.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;p&gt;Đối ngẫu LP đóng vai trò như một &lt;strong&gt;chứng chỉ&lt;/strong&gt;: chứng chỉ bất khả thi (trong kiểm chứng mạng nơ-ron), giá biên (trong thị trường điện), lát cắt (trong mạng luồng) hoặc cận chi phí ghép (trong vận chuyển tối ưu). Nếu ta tìm được một nghiệm gốc khả thi và một nghiệm đối ngẫu khả thi có cùng giá trị mục tiêu, bài toán đã được giải tối ưu theo tính đối ngẫu mạnh của LP.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi tự kiểm tra:&lt;/strong&gt; Trong GCP-CROWN, vì sao việc &lt;em&gt;bổ sung&lt;/em&gt; một mặt cắt hợp lệ vào LP gốc chỉ có thể làm &lt;em&gt;tăng&lt;/em&gt; (hoặc giữ nguyên) cận dưới đối ngẫu? Kết quả nào trong chương này giải thích điều đó?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Zhang, H., Wang, S., Xu, K., Li, L., Li, B., Jana, S., Hsieh, C.-J., &amp;amp; Kolter, J. Z. (2022). General cutting planes for bound-propagation-based neural network verification. &lt;em&gt;NeurIPS&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2208.05740&quot;&gt;arXiv:2208.05740&lt;/a&gt;. Công cụ: &lt;a href=&quot;https://github.com/Verified-Intelligence/alpha-beta-CROWN&quot;&gt;α,β-CROWN&lt;/a&gt; (vô địch VNN-COMP 2021–2025).&lt;/li&gt;
  &lt;li&gt;Liang, Z., &amp;amp; Dvorkin, Y. (2023). Data-driven inverse optimization for marginal offer price recovery in electricity markets. &lt;em&gt;ACM e-Energy ’23&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Peyré, G., &amp;amp; Cuturi, M. (2019). Computational optimal transport. &lt;em&gt;Foundations and Trends in Machine Learning&lt;/em&gt;, 11(5–6). (tham chiếu LP/đối ngẫu chuẩn vẫn dùng trong pipeline OT 2022–2026)&lt;/li&gt;
  &lt;li&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;, Ch. 5 (đối ngẫu LP và giá bóng).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-06 Ứng dụng hiện đại của proximal GD và tăng tốc</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_06_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_06_modern_applications</id>
   <content type="html">&lt;p&gt;Nếu bạn từng chụp cộng hưởng từ (MRI) trong bệnh viện, có lẽ bạn nhớ cảm giác nằm bất động suốt 30–45 phút trong đường hầm máy quét. Một trong những đột phá kỹ thuật lớn nhất của y sinh học thập kỷ vừa qua là rút ngắn thời gian chụp MRI xuống chỉ còn vài phút bằng cách thu thập ít dữ liệu tần số hơn (undersampled k-space) rồi tái tạo lại bức ảnh sắc nét bằng thuật toán tối ưu. Đứng ngay trung tâm của cuộc cách mạng ấy chính là &lt;strong&gt;FISTA&lt;/strong&gt; và thế hệ con cháu hiện đại của nó giai đoạn 2022–2026: &lt;strong&gt;Plug-and-Play FISTA (PnP-FISTA)&lt;/strong&gt; và &lt;strong&gt;Algorithm Unrolling (FISTA-Net)&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Ý tưởng nối liền tối ưu lồi cổ điển với học sâu thật sự khiến người ta phải trầm trồ: trong công thức \(x^{(k)} = \operatorname{prox}_{t h}(v^{(k)} - t\nabla g(v^{(k)}))\), toán tử \(\operatorname{prox}_{t h}\) đóng vai trò chính xác như một &lt;strong&gt;bộ khử nhiễu ảnh&lt;/strong&gt; (MAP denoiser dưới phân phối tiên nghiệm \(e^{-h(x)}\)). Thay vì viết tay một hàm phạt \(h(x)\) đơn giản như chuẩn \(\ell_1\) trên wavelet, các nhà nghiên cứu “cắm” hẳn một mạng nơ-ron khử nhiễu đã huấn luyện sẵn vào vị trí của \(\operatorname{prox}\) — giữ nguyên phần vật lý đo đạc \(\nabla g\) chính xác 100%, đồng thời tận dụng sức mạnh biểu diễn của học sâu!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-ứng-dụng-hiện-đại-của-proximal-gd-và-fista&quot;&gt;Kiến thức cần nhớ: Bốn nhánh ứng dụng hiện đại của Proximal GD và FISTA&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tái tạo ảnh y sinh (MRI / CT) với Plug-and-Play (PnP-FISTA):&lt;/strong&gt; Giữ nguyên phần nhất quán dữ liệu vật lý \(g(x) = \frac{1}{2}\|\mathcal{A}x - y\|_2^2\) (phép biến đổi Fourier / Radon), và thay toán tử \(\operatorname{prox}_{t h}\) bằng bộ khử nhiễu hiện đại (như BM3D hoặc mạng DRUNet) để tái tạo ảnh vượt trội về độ sắc nét.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trải phẳng thuật toán (Algorithm Unrolling — LISTA / FISTA-Net):&lt;/strong&gt; Biến \(K\) vòng lặp hữu hạn (ví dụ \(K = 10\)) của FISTA thành đúng \(K\) tầng của một mạng nơ-ron sâu, trong đó bước học \(\eta_k\), ngưỡng \(\lambda_k\) và ma trận lọc được học trực tiếp từ dữ liệu bằng lan truyền ngược — kết hợp tốc độ suy luận tức thì của mạng sâu với tính diễn giải vật lý của tối ưu lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thư viện thống kê và học máy sản xuất (glmnet, scikit-learn, CVXPY):&lt;/strong&gt; Elastic Net (\(\lambda_1\|x\|_1 + \frac{\lambda_2}{2}\|x\|_2^2\)), hồi quy logistic thưa và hoàn thiện ma trận trong các thư viện chuẩn công nghiệp đều dựa trên khung proximal / coordinate descent kế thừa trực tiếp từ Chương 09.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện hội tụ của PnP (Non-expansiveness &amp;amp; Firmly Non-expansive Denoisers):&lt;/strong&gt; Để vòng lặp PnP-FISTA không bị phân kỳ khi thay prox chuẩn bằng mạng nơ-ron, các nghiên cứu 2022–2026 ràng buộc hằng số Lipschitz của mạng khử nhiễu (như chuẩn hóa phổ — spectral normalization) nhằm bảo toàn tính không giãn giống hệt toán tử gần kề cổ điển.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-1-tầng-fista-net--pnp-cho-tín-hiệu-1d-bị-nhiễu&quot;&gt;Giải thích: Tính tay 1 tầng FISTA-Net / PnP cho tín hiệu 1D bị nhiễu&lt;/h3&gt;

&lt;p&gt;Giả sử ta đo một tín hiệu gốc 2 chiều \(x_{\text{true}} = (3, 0)^T\) qua phép đo đơn giản \(A = I_2\) bị nhiễu Gaussian thành \(y = (2.8, 0.3)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhịp nhất quán dữ liệu (Data Fidelity — giữ nguyên vật lý đo đạc):&lt;/strong&gt;
Từ ước lượng ban đầu \(x^{(0)} = (0, 0)^T\) với bước \(\eta = 1.0\):
\(v^{(1)} = x^{(0)} - \eta A^T(A x^{(0)} - y) = (2.8, 0.3)^T.\)
Điểm \(v^{(1)}\) khớp hoàn hảo với phép đo \(y\), nhưng vẫn mang theo nhiễu \(0.3\) ở tọa độ thứ 2 vốn phải bằng \(0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhịp khử nhiễu (Proximal / Plug-and-Play Denoiser):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với &lt;strong&gt;FISTA cổ điển&lt;/strong&gt; (\(h(x) = \lambda\|x\|_1\), \(\lambda = 0.5\)):
\(x^{(1)}_{\text{FISTA}} = S_{0.5}(2.8, 0.3) = (2.3, 0.0)^T.\)
Nhiễu ở tọa độ 2 bị xóa sạch, nhưng tín hiệu mạnh \(2.8\) cũng bị co thiên lệch xuống \(2.3\) (sai số \(0.7\) so với \(3.0\)).&lt;/li&gt;
      &lt;li&gt;Với &lt;strong&gt;FISTA-Net / PnP&lt;/strong&gt; (dùng bộ khử nhiễu học được \(D_\theta\) biết rằng biên độ lớn \(&amp;gt; 1\) là tín hiệu thật nên gần như không co, chỉ lọc nhiễu biên độ nhỏ):
\(x^{(1)}_{\text{PnP}} = D_\theta(2.8, 0.3) \approx (2.8, 0.0)^T.\)
Vừa khử sạch nhiễu \(0.3 \to 0\), vừa tránh thiên lệch co ngót của chuẩn \(\ell_1\), trong khi vẫn tuân thủ khung lặp proximal của Chương 09!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-proximal-gd-và-tăng-tốc&quot;&gt;Ứng dụng hiện đại của proximal GD và tăng tốc&lt;/h1&gt;

&lt;p&gt;Chương 09 nghiên cứu bài toán tối ưu tổng hợp \(\min_x g(x)+h(x)\) với \(g\) trơn và \(h\) có toán tử gần kề dễ tính, cùng vòng lặp gradient gần kề và kỹ thuật tăng tốc Nesterov / FISTA. Bài đọc tùy chọn này chỉ ra cách khuôn mẫu đó được ứng dụng trong tái tạo ảnh y sinh, mô hình tuyến tính tổng quát thưa, và các mạng nơ-ron &lt;em&gt;trải phẳng thuật toán (algorithm unrolling)&lt;/em&gt; giai đoạn 2022–2026.&lt;/p&gt;

&lt;p&gt;Nhắc lại cặp công thức cập nhật FISTA trong &lt;a href=&quot;/contents/vi/chapter09/09_05_03_example_FISTA/&quot;&gt;09-05-03&lt;/a&gt; (với kích thước bước \(\alpha \le 1/L\) và dãy hệ số động lượng \(t_k\)):&lt;/p&gt;

\[y^{k}=x^{k-1}+\frac{t_{k-1}-1}{t_k}(x^{k-1}-x^{k-2}),\qquad
x^{k}=\operatorname{prox}_{\alpha h}\bigl(y^{k}-\alpha\nabla g(y^{k})\bigr).\]

&lt;p&gt;Khi \(h=\lambda\|\cdot\|_1\), toán tử gần kề chính là phép ngưỡng mềm (soft-thresholding) — cùng ánh xạ đã gặp ở Chương 07.&lt;/p&gt;

&lt;h2 id=&quot;1-tái-tạo-ảnh-mri--ct-từ-fista-đến-pnp-fista&quot;&gt;1. Tái tạo ảnh MRI / CT: từ FISTA đến PnP-FISTA&lt;/h2&gt;

&lt;p&gt;Bài toán tái tạo MRI nén và CT góc thưa có dạng bình phương tối thiểu kết hợp thành phần chính quy hóa thưa hoặc biến phân toàn phần (total variation). FISTA cổ điển (Beck và Teboulle, 2009) vẫn là thuật toán cơ sở trên CPU/GPU trong nhiều hệ thống nghiên cứu y sinh. Bài tổng quan trên &lt;em&gt;IEEE SPM&lt;/em&gt; năm 2023 của Kamilov, Bouman, Buzzard và Wohlberg phân tích lý do các phòng thí nghiệm &lt;strong&gt;thay toán tử gần kề của \(h\) bằng một bộ khử nhiễu học được&lt;/strong&gt;, trong khi vẫn giữ nguyên bước gradient của phần trung thực dữ liệu \(g\) (mô hình vật lý thuận). Phương pháp lai này được gọi là &lt;strong&gt;plug-and-play (PnP)&lt;/strong&gt;; Thuật toán 4 trong bài báo của họ chính là &lt;strong&gt;PnP-FISTA&lt;/strong&gt;. Các lĩnh vực ứng dụng được khảo sát gồm kính hiển vi sinh học, chụp CT, MRI và chụp cắt lớp ptycho-tomography.&lt;/p&gt;

&lt;p&gt;Thành phần trung thực dữ liệu đóng vai trò hàm trơn \(g\) của chương này, còn bộ khử nhiễu đảm nhiệm vai trò \(\operatorname{prox}_{\alpha h}\). Do đó, việc nắm vững vòng lặp gradient gần kề là bước cần thiết trước khi tích hợp mạng nơ-ron.&lt;/p&gt;

&lt;h2 id=&quot;2-trải-phẳng-thuật-toán-algorithm-unrolling-fista-net-và-pfista-dr&quot;&gt;2. Trải phẳng thuật toán (Algorithm Unrolling): FISTA-Net và pFISTA-DR&lt;/h2&gt;

&lt;p&gt;Kỹ thuật trải phẳng thuật toán (Monga, Li và Eldar, 2021) chuyển một số bước lặp cố định của proximal gradient / FISTA thành một kiến trúc mạng nơ-ron, trong đó kích thước bước, ngưỡng co và thậm chí cả toán tử gần kề đều có thể học từ dữ liệu. Xiang, Dong và Yang (2021) giới thiệu &lt;strong&gt;FISTA-Net&lt;/strong&gt; trên &lt;em&gt;IEEE TMI&lt;/em&gt;: một chuỗi các khối gồm mô-đun gradient, mô-đun gần kề và mô-đun động lượng, được đánh giá trên chụp cắt lớp điện từ và CT tia X. Qu, Zhang, Kang, Lin, Lin, She, Wu, Wang và Zheng (2024) trải phẳng &lt;strong&gt;FISTA có chiếu&lt;/strong&gt; cho ảnh MRI quét hướng kính (&lt;strong&gt;pFISTA-DR&lt;/strong&gt;), ghi nhận thời gian tái tạo giảm từ khoảng 48 giây/lát xuống 0,55 giây/lát trên dữ liệu lâm sàng. Zhang, Chen, Xiong và Zhang (2023) tổng hợp hướng nghiên cứu này dưới tên gọi &lt;em&gt;cảm biến nén lấy cảm hứng vật lý (physics-inspired compressed sensing)&lt;/em&gt;: khung thuật toán ISTA/FISTA được giữ nguyên, còn các ánh xạ tuyến tính và bộ lọc được học từ dữ liệu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liên hệ với giáo trình.&lt;/strong&gt; Nếu không nắm được công thức lặp FISTA trên giấy, các mạng trải phẳng sẽ chỉ là một hộp đen. Điểm cốt lõi của chương này là các kết nối tắt (skip connection) và động lượng trong mạng thực chất tương ứng với dãy hệ số \(t_k\) của Nesterov.&lt;/p&gt;

&lt;h2 id=&quot;3-elastic-net-và-hoàn-thiện-ma-trận-trong-các-bộ-giải-thực-tế&quot;&gt;3. Elastic net và hoàn thiện ma trận trong các bộ giải thực tế&lt;/h2&gt;

&lt;p&gt;Bài toán elastic net \(\tfrac12\|X\beta-y\|_2^2+\lambda\bigl(\alpha\|\beta\|_1+(1-\alpha)\tfrac12\|\beta\|_2^2\bigr)\) có thể giải bằng phương pháp gradient gần kề (hoặc giảm theo tọa độ trên hàm bậc hai cộng chuẩn \(\ell_1\)) với &lt;strong&gt;toán tử ngưỡng mềm có điều chỉnh Ridge&lt;/strong&gt;. Tay, Narasimhan và Hastie (2023) đưa đường chính quy hóa này thành lựa chọn mặc định cho mọi họ GLM trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; — phục vụ phân tích hệ gene, dự báo tỷ lệ nhấp chuột và mô hình sống còn Cox. Ví dụ hoàn thiện ma trận ở bài &lt;a href=&quot;/contents/vi/chapter09/09_03_example_matrix_completion/&quot;&gt;09-03&lt;/a&gt; cũng tuân theo đúng khuôn mẫu tổng hợp (số hạng sai số dữ liệu trơn cộng toán tử gần kề của chuẩn hạt nhân là ngưỡng mềm trên giá trị kỳ dị), hiện vẫn là nền tảng cho nhiều hệ thống gợi ý và bài toán điền khuyết dữ liệu đơn bào.&lt;/p&gt;

&lt;p&gt;ISTA và FISTA không phải lúc nào cũng là thuật toán chạy &lt;em&gt;CPU&lt;/em&gt; nhanh nhất cho Lasso (giảm theo tọa độ kết hợp quy tắc sàng lọc biến thường nhanh hơn; xem Chương 13), nhưng chúng đặc biệt thuận tiện để &lt;strong&gt;triển khai song song trên GPU, trải phẳng thành mạng nơ-ron, hoặc thay thế toán tử gần kề&lt;/strong&gt;. Đó là lý do các lĩnh vực tái tạo ảnh và lập trình khả vi chuẩn hóa dựa trên họ thuật toán này.&lt;/p&gt;

&lt;h2 id=&quot;4-một-bước-lặp-ista-tối-giản&quot;&gt;4. Một bước lặp ISTA tối giản&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;soft_threshold&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;maximum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ista_step&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# t &amp;lt; 1 / ||A||^2 với g(x) = 0.5 ||Ax - b||^2
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;soft_threshold&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;FISTA chỉ thay đổi &lt;em&gt;điểm&lt;/em&gt; tính gradient \(\nabla g\) bằng cách dùng bước ngoại suy động lượng ở bài 09-05. PnP-FISTA thay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;soft_threshold&lt;/code&gt; bằng một bộ khử nhiễu (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;denoiser&lt;/code&gt;), còn FISTA-Net cho phép học trực tiếp cả bước &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t&lt;/code&gt; lẫn bộ khử nhiễu đó.&lt;/p&gt;

&lt;h2 id=&quot;tóm-lược&quot;&gt;Tóm lược&lt;/h2&gt;

&lt;p&gt;Cấu trúc tổng hợp (hàm mất mát trơn cộng thành phần chính quy hóa có toán tử gần kề tính được) là lý do ra đời của phương pháp gradient gần kề, còn kỹ thuật tăng tốc là một lịch trình hệ số \(t_k\) chứ không làm thay đổi mô hình bài toán. Trong giai đoạn 2022–2026, cùng một lịch trình này vừa đóng vai trò (i) bộ giải tối ưu chuẩn, (ii) khung plug-and-play bao quanh các mạng CNN khử nhiễu, và (iii) kiến trúc mạng nơ-ron thu được khi trải phẳng từ 10 đến 40 bước lặp.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Khi nào nên giữ nguyên toán tử gần kề giải tích (như ngưỡng mềm, SVT) thay vì thay bằng bộ khử nhiễu học được — và trong trường hợp PnP, những bảo đảm lý thuyết nào của Chương 09 vẫn còn giữ được?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Beck, A., &amp;amp; Teboulle, M. (2009). A fast iterative shrinkage-thresholding algorithm for linear inverse problems. &lt;em&gt;SIAM J. Imaging Sciences&lt;/em&gt;, 2(1), 183–202. (FISTA cổ điển)&lt;/li&gt;
  &lt;li&gt;Kamilov, U. S., Bouman, C. A., Buzzard, G. T., &amp;amp; Wohlberg, B. (2023). Plug-and-play methods for integrating physical and learned models in computational imaging. &lt;em&gt;IEEE Signal Processing Magazine&lt;/em&gt;, 40(1), 85–97.&lt;/li&gt;
  &lt;li&gt;Monga, V., Li, Y., &amp;amp; Eldar, Y. C. (2021). Algorithm unrolling: Interpretable, efficient deep learning for signal and image processing. &lt;em&gt;IEEE Signal Processing Magazine&lt;/em&gt;, 38(2), 18–44.&lt;/li&gt;
  &lt;li&gt;Xiang, J., Dong, Y., &amp;amp; Yang, Y. (2021). FISTA-Net: Learning a fast iterative shrinkage thresholding network for inverse problems in imaging. &lt;em&gt;IEEE Transactions on Medical Imaging&lt;/em&gt;, 40(5), 1329–1339.&lt;/li&gt;
  &lt;li&gt;Qu, B., Zhang, J., Kang, T., Lin, J., Lin, M., She, H., Wu, Q., Wang, M., &amp;amp; Zheng, G. (2024). Radial magnetic resonance image reconstruction with a deep unrolled projected fast iterative soft-thresholding network. &lt;em&gt;Computers in Biology and Medicine&lt;/em&gt;, 168, 107707.&lt;/li&gt;
  &lt;li&gt;Zhang, J., Chen, B., Xiong, R., &amp;amp; Zhang, Y. (2023). Physics-inspired compressive sensing: Beyond deep unrolling. &lt;em&gt;IEEE Signal Processing Magazine&lt;/em&gt;, 40(1), 58–72.&lt;/li&gt;
  &lt;li&gt;Tay, J. K., Narasimhan, B., &amp;amp; Hastie, T. (2023). Elastic net regularization paths for all generalized linear models. &lt;em&gt;Journal of Statistical Software&lt;/em&gt;, 106(1).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-12 Ứng dụng hiện đại của phương pháp subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_12_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_12_modern_applications</id>
   <content type="html">&lt;p&gt;Khi bước ra khỏi các bài tập học thuật gọn gàng để đối mặt với hệ thống AI triển khai thực tế giai đoạn 2022–2026, điều đầu tiên ta nhận ra là các mục tiêu vận hành hiếm khi trơn mượt hay đơn nhất. Ta vừa muốn mô hình chính xác, vừa phải chống chịu nhiễu đối kháng, vừa phải đảm bảo chênh lệch sai số giữa các nhóm người dùng không vượt quá ngưỡng quy định. Chính ở giao điểm của những yêu cầu sắc cạnh ấy, phương pháp subgradient — với cấu trúc cực kỳ nhẹ và linh hoạt — lại tỏa sáng như một công cụ không thể thay thế.&lt;/p&gt;

&lt;p&gt;Phiên bản tổng hợp cuối chương này kết nối trực tiếp ba khuôn mẫu thuật toán của Chương 08 (subgradient tiêu chuẩn, subgradient có chiếu, và subgradient ngẫu nhiên) với các bài toán công nghiệp tiêu biểu, giúp bạn nhìn thấy toàn cảnh từ lý thuyết hội tụ đến cách thiết kế vòng lặp trong thư viện mã nguồn mở.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-triển-khai-subgradient-trong-hệ-thống-ai-thực-tế&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột triển khai subgradient trong hệ thống AI thực tế&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xử lý hàm mất mát không trơn quy mô lớn:&lt;/strong&gt; Từ hinge loss trong phân loại biên rộng, mất mát lượng phân vị (quantile/pinball loss) trong dự báo chuỗi thời gian đến kiến trúc mạng dùng ReLU, subgradient ngẫu nhiên cho phép cập nhật trọng số với chi phí tuyến tính theo kích thước mini-batch.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp đặt ràng buộc cứng bằng phép chiếu nhanh:&lt;/strong&gt; Trong tối ưu đối kháng (PGD) hay nén mô hình bị chặn biên độ, phép chiếu lên quả cầu \(\ell_\infty\) hoặc \(\ell_2\) biến một bài toán ràng buộc phức tạp thành hai dòng phép toán vector hóa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều phối ràng buộc công bằng qua cập nhật đối ngẫu (Dual Subgradient):&lt;/strong&gt; Khi bài toán có ràng buộc dạng tỷ lệ giữa các nhóm nhân khẩu học (như trong Fairlearn), nhân tử Lagrange \(\lambda \ge 0\) đóng vai trò “giá phạt” tự điều chỉnh bằng bước subgradient có chiếu lên nửa trục dương \(\mathbb{R}_+\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhận diện giới hạn để chọn đúng công cụ:&lt;/strong&gt; Biết khi nào tốc độ \(O(1/\epsilon^2)\) là đủ dùng (huấn luyện mô hình lớn với độ chính xác vừa) và khi nào cần chuyển sang phương pháp phân tách proximal (Chương 09) hoặc giảm phương sai SVRG/SAGA (Chương 26).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-bước-subgradient-đối-ngẫu-cho-ràng-buộc-công-bằng&quot;&gt;Giải thích: Tính tay bước subgradient đối ngẫu cho ràng buộc công bằng&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Giả sử một mô hình xét duyệt tín dụng có tỷ lệ duyệt giữa hai nhóm A và B chênh lệch nhau $$v(\theta) =&lt;/td&gt;
      &lt;td&gt;p_A(\theta) - p_B(\theta)&lt;/td&gt;
      &lt;td&gt;- 0.05\((ta muốn\)v(\theta) \le 0\(, tức chênh lệch không quá 5%). Bài toán đối ngẫu cực đại hóa theo nhân tử phạt\)\lambda \ge 0\(có phần hàm mục tiêu theo\)\lambda\(là\)\lambda \cdot v(\theta)\(, nên subgradient hướng tăng của hàm đối ngẫu theo\)\lambda\(chính là mức vi phạm\)v(\theta)$$!&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Vòng 1:&lt;/strong&gt; Khởi tạo \(\lambda^{(0)} = 0\), bước học đối ngẫu \(\eta = 2.0\). Mô hình ban đầu có $$p_A = 0.72, p_B = 0.60 \implies v(\theta^{(0)}) =&lt;/td&gt;
          &lt;td&gt;0.72 - 0.60&lt;/td&gt;
          &lt;td&gt;- 0.05 = +0.07 &amp;gt; 0$$ (đang vi phạm 7%).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Cập nhật subgradient có chiếu lên \(\lambda \ge 0\):
\(\lambda^{(1)} = \max\big(0, \; 0 + 2.0 \times 0.07\big) = 0.14.\)&lt;/li&gt;
      &lt;li&gt;Nhân tử phạt tăng lên \(0.14\), buộc mô hình ở vòng sau phải chú ý thu hẹp khoảng cách giữa hai nhóm.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng 2:&lt;/strong&gt; Nhờ lực phạt \(\lambda^{(1)} = 0.14\), mô hình mới đạt \(p_A = 0.66, p_B = 0.63 \implies v(\theta^{(1)}) = 0.03 - 0.05 = -0.02 &amp;lt; 0\) (đã thỏa mãn ràng buộc với biên an toàn 2%).
    &lt;ul&gt;
      &lt;li&gt;Cập nhật tiếp theo:
\(\lambda^{(2)} = \max\big(0, \; 0.14 + 2.0 \times (-0.02)\big) = \max(0, 0.10) = 0.10.\)&lt;/li&gt;
      &lt;li&gt;Lực phạt tự động nới lỏng khi ràng buộc đã an toàn, tạo nên cơ chế cân bằng động giữa độ chính xác và tính công bằng!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-phương-pháp-subgradient&quot;&gt;Ứng dụng hiện đại của phương pháp subgradient&lt;/h1&gt;

&lt;p&gt;Chương 08 phân tích vòng lặp \(x^{k+1}=x^k-\alpha_k g^k\) với \(g^k\in\partial f(x^k)\), cùng hai biến thể quan trọng là bản có chiếu và bản ngẫu nhiên. Bài đọc tùy chọn này liên hệ ba khuôn mẫu thuật toán đó với các quy trình thực tế đã được chuẩn hóa trong giai đoạn 2022–2026. Chúng ta không chứng minh lại tốc độ hội tụ \(O(1/\varepsilon^2)\), mà làm rõ vì sao các bước cập nhật subgradient (có chiếu hoặc ngẫu nhiên) vẫn được sử dụng rộng rãi trong thực hành.&lt;/p&gt;

&lt;h2 id=&quot;1-tối-ưu-rủi-ro-thực-nghiệm-không-trơn-hinge-huber-và-huấn-luyện-relu&quot;&gt;1. Tối ưu rủi ro thực nghiệm không trơn: hinge, Huber và huấn luyện ReLU&lt;/h2&gt;

&lt;p&gt;Hồi quy logistic có chính quy hóa trong &lt;a href=&quot;/contents/vi/chapter08/08_01_05_example_regularized_logistic_regression/&quot;&gt;08-01-05&lt;/a&gt; là một ví dụ trực tiếp của phương pháp subgradient. Cùng cấu trúc vòng lặp đó được dùng để huấn luyện SVM tuyến tính (hàm mất mát hinge), hồi quy bền vững (hàm Huber hoặc phân vị), hay lớp phân loại cuối của một bộ mã hóa đã đóng băng trọng số. Với mạng ReLU nhiều lớp, hàm mất mát không còn lồi, nhưng lan truyền ngược &lt;em&gt;trong các thư viện thực tế&lt;/em&gt; vẫn tính ra một lựa chọn bảo toàn của subgradient (Bolte và Pauwels, 2021). Kết quả hội tụ của họ cung cấp cơ sở lý thuyết trực tiếp cho &lt;strong&gt;SGD không trơn đúng như cách các thư viện hiện hành triển khai&lt;/strong&gt;, chứ không phụ thuộc vào một oracle vi phân Clarke lý tưởng.&lt;/p&gt;

&lt;p&gt;Trên các bài toán tổng hữu hạn lồi, phân tích còn rõ ràng hơn: bước giảm dần và bước Polyak trong chương này vẫn là nền tảng tiêu chuẩn, còn các thuật toán chọn bước thích nghi hoặc không cần siêu tham số giai đoạn 2022–2024 (như DoG, Polyak restart) là sự kế thừa trực tiếp từ &lt;a href=&quot;/contents/vi/chapter08/08_01_06_polyak_step_sizes/&quot;&gt;08-01-06 Kích thước bước Polyak&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;2-pgd-có-chiếu-và-huấn-luyện-đối-kháng-theo-chuẩn-ell_p&quot;&gt;2. PGD có chiếu và huấn luyện đối kháng theo chuẩn \(\ell_p\)&lt;/h2&gt;

&lt;p&gt;Trong huấn luyện đối kháng theo cách tiếp cận của Madry, tại mỗi minibatch ta giải bài toán bên trong có ràng buộc:&lt;/p&gt;

\[\max_{\|\delta\|_p\le\varepsilon}\ \ell\bigl(h_w(x+\delta),y\bigr)\]

&lt;p&gt;bằng &lt;strong&gt;bước tăng gradient / subgradient có chiếu&lt;/strong&gt; theo nhiễu \(\delta\), xen kẽ với bước giảm theo tham số \(w\). Phép chiếu lên quả cầu \(\ell_\infty\) hoặc \(\ell_2\) chính là toán tử trong &lt;a href=&quot;/contents/vi/chapter08/08_01_08_projected_subgradient_method/&quot;&gt;08-01-08 Phương pháp subgradient có chiếu&lt;/a&gt;. Croce và Hein (2020) chỉ ra rằng vòng lặp PGD bên trong nếu tinh chỉnh kém sẽ &lt;em&gt;đánh giá quá cao&lt;/em&gt; độ bền vững của mô hình; từ đó, bộ tổ hợp không tham số &lt;strong&gt;AutoAttack&lt;/strong&gt; (gồm APGD + FAB + Square) trở thành chuẩn kiểm thử mặc định. Croce và cộng sự (2021) đóng gói quy trình này thành &lt;strong&gt;RobustBench&lt;/strong&gt;, vốn vẫn là bảng xếp hạng công khai chuẩn cho độ bền đối kháng \(\ell_\infty\) và \(\ell_2\) đến năm 2025. Khía cạnh chuẩn đối ngẫu (hàm tựa của quả cầu tấn công) sẽ được đề cập ở Chương 13, còn &lt;em&gt;thuật toán&lt;/em&gt; cốt lõi chính là phương pháp có chiếu của chương này.&lt;/p&gt;

&lt;h2 id=&quot;3-tính-công-bằng-và-các-ràng-buộc-theo-tỷ-lệ&quot;&gt;3. Tính công bằng và các ràng buộc theo tỷ lệ&lt;/h2&gt;

&lt;p&gt;Nhiều ràng buộc trong hệ thống thực tế có dạng &lt;strong&gt;tỷ lệ không trơn&lt;/strong&gt;: cân bằng nhân khẩu học (demographic parity), cân bằng tỷ lệ sai số (equalised odds), ngưỡng dưới của độ nhạy, hay ngưỡng trên của tỷ lệ rời bỏ (churn). Các ràng buộc này có dạng \(\mathbb{P}(\hat y=1\mid A=a)\le \alpha\) — là trung bình của hàm chỉ báo, do đó từng khúc hằng và không khả vi. Cotter, Jiang, Gupta và cộng sự (JMLR 2019) đề xuất cách tiếp cận trò chơi hai người &lt;strong&gt;proxy-Lagrangian&lt;/strong&gt;: một phía thực hiện bước gradient trên hàm thay thế trơn, phía kia áp đặt ràng buộc tỷ lệ gốc bằng phương pháp (sub)gradient trên nhân tử đối ngẫu. Agarwal, Beygelzimer, Dudík, Langford và Wallach (2018) quy bài toán phân loại công bằng về một dãy bài toán phân loại có trọng số chi phí (cost-sensitive); thư viện &lt;strong&gt;Fairlearn&lt;/strong&gt; (Weerts, Dudík, Edgar, Jalali, Lutz và Madaio, 2023, &lt;em&gt;JMLR&lt;/em&gt;) cài đặt phương pháp quy giảm này qua lớp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExponentiatedGradient&lt;/code&gt; và là công cụ được dùng phổ biến trong hệ sinh thái scikit-learn giai đoạn 2024–2026.&lt;/p&gt;

&lt;p&gt;Bài toán tối ưu rủi ro thực nghiệm có trọng số ở vòng trong thường được giải bằng bước subgradient hoặc SGD trên hàm mất mát hinge hay logistic, còn bước cập nhật nhân tử ở vòng ngoài là bước subgradient theo mức độ vi phạm ràng buộc — tức là thuật toán của chương này xuất hiện ở cả hai tầng.&lt;/p&gt;

&lt;h2 id=&quot;4-ví-dụ-ngắn-bước-chiếu-lên-quả-cầu-ell_infty&quot;&gt;4. Ví dụ ngắn: bước chiếu lên quả cầu \(\ell_\infty\)&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;proj_linf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;clip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;pgd_inner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros_like&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;proj_linf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Khi thay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; bằng gradient minibatch của hàm mất mát, ta thu được vòng lặp bên trong của huấn luyện đối kháng. Khi thay phép chiếu lên quả cầu bằng phép chiếu lên đơn hình xác suất hoặc đa diện công bằng, ta thu được đúng phương pháp subgradient có chiếu ở mục 08-01-08.&lt;/p&gt;

&lt;h2 id=&quot;tóm-lược&quot;&gt;Tóm lược&lt;/h2&gt;

&lt;p&gt;Khi hàm mục tiêu hoặc ràng buộc chứa hàm max, chuẩn \(\ell_1\), mất mát hinge hay các tỷ lệ thực nghiệm, thuật toán bậc nhất cơ bản &lt;em&gt;chính là&lt;/em&gt; phương pháp subgradient (có thể kèm phép chiếu hoặc lấy mẫu ngẫu nhiên). Các kỹ thuật tăng tốc và toán tử gần kề ở Chương 09 giúp cải thiện đáng kể khi bài toán có cấu trúc tổng hợp rõ ràng, nhưng không thay thế hoàn toàn vòng lặp này đối với các ràng buộc tỷ lệ không trơn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Vì sao kích thước bước cố định về mặt lý thuyết gặp khó khăn với ràng buộc tỷ lệ lồi không trơn, và vì sao các phương pháp quy giảm công bằng trong thực hành vẫn sử dụng kiểu bước này?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bolte, J., &amp;amp; Pauwels, E. (2021). Conservative set valued fields, automatic differentiation, stochastic gradient methods and deep learning. &lt;em&gt;Mathematical Programming&lt;/em&gt;, 188, 19–51.&lt;/li&gt;
  &lt;li&gt;Croce, F., &amp;amp; Hein, M. (2020). Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks. &lt;em&gt;ICML&lt;/em&gt;, PMLR 119.&lt;/li&gt;
  &lt;li&gt;Croce, F., Andriushchenko, M., Sehwag, V., Debenedetti, E., Flammarion, N., Chiang, M., Mittal, P., &amp;amp; Hein, M. (2021). RobustBench: A standardized adversarial robustness benchmark. &lt;em&gt;NeurIPS Datasets and Benchmarks&lt;/em&gt;. Bảng: &lt;a href=&quot;https://robustbench.github.io/&quot;&gt;robustbench.github.io&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Cotter, A., Jiang, H., Gupta, M., Wang, S., Narayan, T., You, S., &amp;amp; Sridharan, K. (2019). Optimization with non-differentiable constraints with applications to fairness, recall, churn, and other goals. &lt;em&gt;JMLR&lt;/em&gt;, 20(172).&lt;/li&gt;
  &lt;li&gt;Agarwal, A., Beygelzimer, A., Dudík, M., Langford, J., &amp;amp; Wallach, H. (2018). A reductions approach to fair classification. &lt;em&gt;ICML&lt;/em&gt;, PMLR 80.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257). &lt;a href=&quot;https://fairlearn.org&quot;&gt;https://fairlearn.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-09 Ứng dụng hiện đại của phương pháp subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_09_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_09_modern_applications</id>
   <content type="html">&lt;p&gt;Đừng tưởng rằng một thuật toán ra đời từ thập niên 1960 như phương pháp subgradient đã bị bỏ lại trong ngăn tủ lịch sử trước làn sóng học sâu hiện đại. Trái lại, mỗi khi một mạng nơ-ron dùng hàm kích hoạt ReLU (\(\max(0, z)\)), mỗi khi một nhóm nghiên cứu an toàn AI tạo nhiễu đối kháng bằng PGD trong quả cầu \(\ell_\infty\) để kiểm thử độ bền vững của mô hình, hay khi một nền tảng tài chính ép ràng buộc công bằng nhân khẩu học — chính vòng lặp subgradient (và biến thể có chiếu, ngẫu nhiên của nó) đang âm thầm chạy bên dưới.&lt;/p&gt;

&lt;p&gt;Bài đọc mở rộng này bắc cây cầu từ lý thuyết Chương 08 sang thực tiễn giai đoạn 2022–2026. Bạn sẽ thấy rằng dù tên gọi trong các thư viện phần mềm có thể khác đi (như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PyTorch autograd&lt;/code&gt; tại điểm gãy ReLU hay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PGD-20&lt;/code&gt; trên bảng xếp hạng RobustBench), cốt lõi toán học vẫn không thay đổi: chọn một phần tử trong dưới vi phân, bước theo hướng đối diện, rồi chiếu về miền hợp lệ.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-ứng-dụng-hiện-đại-của-phương-pháp-subgradient&quot;&gt;Kiến thức cần nhớ: Bốn nhánh ứng dụng hiện đại của phương pháp subgradient&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu không trơn trong học sâu (ReLU &amp;amp; Clarke Subdifferential):&lt;/strong&gt; Hàm ReLU không khả vi tại \(0\), khiến hàm mất mát của mạng nơ-ron trở nên không trơn (và không lồi). Các framework tự động tính vi phân chọn một giá trị cố định (thường là \(0\)) tại điểm gãy, vận hành như một phương pháp subgradient ngẫu nhiên trên tập dưới vi phân tổng quát Clarke.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Huấn luyện đối kháng (Adversarial Training) bằng PGD có chiếu:&lt;/strong&gt; Để tìm nhiễu độc hại \(\delta\) tối đa hóa mất mát trong quả cầu \(\|\delta\|_\infty \le \epsilon\), thuật toán Projected Gradient Ascent thực hiện đúng bước cập nhật theo dấu gradient rồi chiếu bằng hàm cắt ngưỡng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clip(delta, -eps, eps)&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu có ràng buộc công bằng (Fairness-Constrained Learning):&lt;/strong&gt; Các ràng buộc công bằng như chênh lệch tỷ lệ dương tính giả giữa hai nhóm không vượt quá \(\tau\) được đưa vào hàm Lagrangian và giải bằng trò chơi minimax dùng bước subgradient trên nhân tử Lagrange.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ bền vững với ngoại lai (Robust Loss — Hinge &amp;amp; Huber):&lt;/strong&gt; Các hàm mất mát ít nhạy cảm với điểm nhiễu ngoại lai thường có góc gãy tuyến tính; phương pháp subgradient cho phép tối ưu trực tiếp mà không cần ép về bình phương tối thiểu nhạy nhiễu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-2-bước-tấn-công-pgd-có-chiếu-lên-quả-cầu-ell_infty&quot;&gt;Giải thích: Tính tay 2 bước tấn công PGD có chiếu lên quả cầu \(\ell_\infty\)&lt;/h3&gt;

&lt;p&gt;Xét một bộ phân loại tuyến tính 2 chiều đơn giản có hàm mất mát đối với nhiễu \(\delta = (\delta_1, \delta_2)\) là:
\(L(\delta) = 2\delta_1 - 3\delta_2 + 1,\)
ta muốn &lt;strong&gt;tối đa hóa&lt;/strong&gt; \(L(\delta)\) (tương đương cực tiểu hóa \(-L(\delta)\)) trong quả cầu \(\ell_\infty\) bán kính \(\epsilon = 0.2\) (tức \(|\delta_1| \le 0.2, |\delta_2| \le 0.2\)). Bắt đầu từ \(\delta^{(0)} = (0, 0)\) với bước \(\alpha = 0.15\) và chuẩn hóa hướng theo dấu (\(\ell_\infty\)-PGD).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient hướng tăng mất mát: \(\nabla L(\delta^{(0)}) = (2, -3)\).&lt;/li&gt;
      &lt;li&gt;Lấy dấu từng tọa độ (hướng tối ưu theo chuẩn \(\ell_\infty\)): \(s^{(0)} = \operatorname{sign}(2, -3) = (+1, -1)\).&lt;/li&gt;
      &lt;li&gt;Bước tự do: \(\tilde{\delta}^{(1)} = (0, 0) + 0.15(1, -1) = (0.15, -0.15)\).&lt;/li&gt;
      &lt;li&gt;Chiếu lên hộp \([-0.2, 0.2]^2\): cả hai tọa độ đều nằm trong \([-0.2, 0.2]\) nên \(\delta^{(1)} = (0.15, -0.15)\). Mất mát tăng từ \(1.0\) lên \(2(0.15) - 3(-0.15) + 1 = 1.75\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bước tự do tiếp theo: \(\tilde{\delta}^{(2)} = (0.15, -0.15) + 0.15(1, -1) = (0.30, -0.30)\) — văng ra ngoài quả cầu bán kính \(0.2\)!&lt;/li&gt;
      &lt;li&gt;Chiếu cắt ngưỡng lên \([-0.2, 0.2]^2\):
\(\delta^{(2)} = \operatorname{clip}\big((0.30, -0.30), -0.2, 0.2\big) = (0.20, -0.20).\)&lt;/li&gt;
      &lt;li&gt;Mất mát đạt cực đại trong hộp: \(L(0.20, -0.20) = 2(0.2) - 3(-0.2) + 1 = 2.0\).
Đây chính xác là cơ chế bên trong mỗi vòng lặp PGD đang chạy trong các hệ thống kiểm định độ bền vững AI hiện đại!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-phương-pháp-subgradient&quot;&gt;Ứng dụng hiện đại của phương pháp subgradient&lt;/h1&gt;

&lt;p&gt;Chương 08 phân tích vòng lặp \(x^{k+1}=x^k-\alpha_k g^k\) với \(g^k\in\partial f(x^k)\), cùng hai biến thể quan trọng là bản có chiếu và bản ngẫu nhiên. Bài đọc tùy chọn này liên hệ ba khuôn mẫu thuật toán đó với các quy trình thực tế đã được chuẩn hóa trong giai đoạn 2022–2026. Chúng ta không chứng minh lại tốc độ hội tụ \(O(1/\varepsilon^2)\), mà làm rõ vì sao các bước cập nhật subgradient (có chiếu hoặc ngẫu nhiên) vẫn được sử dụng rộng rãi trong thực hành.&lt;/p&gt;

&lt;h2 id=&quot;1-tối-ưu-rủi-ro-thực-nghiệm-không-trơn-hinge-huber-và-huấn-luyện-relu&quot;&gt;1. Tối ưu rủi ro thực nghiệm không trơn: hinge, Huber và huấn luyện ReLU&lt;/h2&gt;

&lt;p&gt;Hồi quy logistic có chính quy hóa trong &lt;a href=&quot;/contents/vi/chapter08/08_01_05_example_regularized_logistic_regression/&quot;&gt;08-01-05&lt;/a&gt; là một ví dụ trực tiếp của phương pháp subgradient. Cùng cấu trúc vòng lặp đó được dùng để huấn luyện SVM tuyến tính (hàm mất mát hinge), hồi quy bền vững (hàm Huber hoặc phân vị), hay lớp phân loại cuối của một bộ mã hóa đã đóng băng trọng số. Với mạng ReLU nhiều lớp, hàm mất mát không còn lồi, nhưng lan truyền ngược &lt;em&gt;trong các thư viện thực tế&lt;/em&gt; vẫn tính ra một lựa chọn bảo toàn của subgradient (Bolte và Pauwels, 2021). Kết quả hội tụ của họ cung cấp cơ sở lý thuyết trực tiếp cho &lt;strong&gt;SGD không trơn đúng như cách các thư viện hiện hành triển khai&lt;/strong&gt;, chứ không phụ thuộc vào một oracle vi phân Clarke lý tưởng.&lt;/p&gt;

&lt;p&gt;Trên các bài toán tổng hữu hạn lồi, phân tích còn rõ ràng hơn: bước giảm dần và bước Polyak trong chương này vẫn là nền tảng tiêu chuẩn, còn các thuật toán chọn bước thích nghi hoặc không cần siêu tham số giai đoạn 2022–2024 (như DoG, Polyak restart) là sự kế thừa trực tiếp từ &lt;a href=&quot;/contents/vi/chapter08/08_01_06_polyak_step_sizes/&quot;&gt;08-01-06 Kích thước bước Polyak&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;2-pgd-có-chiếu-và-huấn-luyện-đối-kháng-theo-chuẩn-ell_p&quot;&gt;2. PGD có chiếu và huấn luyện đối kháng theo chuẩn \(\ell_p\)&lt;/h2&gt;

&lt;p&gt;Trong huấn luyện đối kháng theo cách tiếp cận của Madry, tại mỗi minibatch ta giải bài toán bên trong có ràng buộc:&lt;/p&gt;

\[\max_{\|\delta\|_p\le\varepsilon}\ \ell\bigl(h_w(x+\delta),y\bigr)\]

&lt;p&gt;bằng &lt;strong&gt;bước tăng gradient / subgradient có chiếu&lt;/strong&gt; theo nhiễu \(\delta\), xen kẽ với bước giảm theo tham số \(w\). Phép chiếu lên quả cầu \(\ell_\infty\) hoặc \(\ell_2\) chính là toán tử trong &lt;a href=&quot;/contents/vi/chapter08/08_01_08_projected_subgradient_method/&quot;&gt;08-01-08 Phương pháp subgradient có chiếu&lt;/a&gt;. Croce và Hein (2020) chỉ ra rằng vòng lặp PGD bên trong nếu tinh chỉnh kém sẽ &lt;em&gt;đánh giá quá cao&lt;/em&gt; độ bền vững của mô hình; từ đó, bộ tổ hợp không tham số &lt;strong&gt;AutoAttack&lt;/strong&gt; (gồm APGD + FAB + Square) trở thành chuẩn kiểm thử mặc định. Croce và cộng sự (2021) đóng gói quy trình này thành &lt;strong&gt;RobustBench&lt;/strong&gt;, vốn vẫn là bảng xếp hạng công khai chuẩn cho độ bền đối kháng \(\ell_\infty\) và \(\ell_2\) đến năm 2025. Khía cạnh chuẩn đối ngẫu (hàm tựa của quả cầu tấn công) sẽ được đề cập ở Chương 13, còn &lt;em&gt;thuật toán&lt;/em&gt; cốt lõi chính là phương pháp có chiếu của chương này.&lt;/p&gt;

&lt;h2 id=&quot;3-tính-công-bằng-và-các-ràng-buộc-theo-tỷ-lệ&quot;&gt;3. Tính công bằng và các ràng buộc theo tỷ lệ&lt;/h2&gt;

&lt;p&gt;Nhiều ràng buộc trong hệ thống thực tế có dạng &lt;strong&gt;tỷ lệ không trơn&lt;/strong&gt;: cân bằng nhân khẩu học (demographic parity), cân bằng tỷ lệ sai số (equalised odds), ngưỡng dưới của độ nhạy, hay ngưỡng trên của tỷ lệ rời bỏ (churn). Các ràng buộc này có dạng \(\mathbb{P}(\hat y=1\mid A=a)\le \alpha\) — là trung bình của hàm chỉ báo, do đó từng khúc hằng và không khả vi. Cotter, Jiang, Gupta và cộng sự (JMLR 2019) đề xuất cách tiếp cận trò chơi hai người &lt;strong&gt;proxy-Lagrangian&lt;/strong&gt;: một phía thực hiện bước gradient trên hàm thay thế trơn, phía kia áp đặt ràng buộc tỷ lệ gốc bằng phương pháp (sub)gradient trên nhân tử đối ngẫu. Agarwal, Beygelzimer, Dudík, Langford và Wallach (2018) quy bài toán phân loại công bằng về một dãy bài toán phân loại có trọng số chi phí (cost-sensitive); thư viện &lt;strong&gt;Fairlearn&lt;/strong&gt; (Weerts, Dudík, Edgar, Jalali, Lutz và Madaio, 2023, &lt;em&gt;JMLR&lt;/em&gt;) cài đặt phương pháp quy giảm này qua lớp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExponentiatedGradient&lt;/code&gt; và là công cụ được dùng phổ biến trong hệ sinh thái scikit-learn giai đoạn 2024–2026.&lt;/p&gt;

&lt;p&gt;Bài toán tối ưu rủi ro thực nghiệm có trọng số ở vòng trong thường được giải bằng bước subgradient hoặc SGD trên hàm mất mát hinge hay logistic, còn bước cập nhật nhân tử ở vòng ngoài là bước subgradient theo mức độ vi phạm ràng buộc — tức là thuật toán của chương này xuất hiện ở cả hai tầng.&lt;/p&gt;

&lt;h2 id=&quot;4-ví-dụ-ngắn-bước-chiếu-lên-quả-cầu-ell_infty&quot;&gt;4. Ví dụ ngắn: bước chiếu lên quả cầu \(\ell_\infty\)&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;proj_linf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;clip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;pgd_inner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros_like&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;proj_linf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Khi thay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; bằng gradient minibatch của hàm mất mát, ta thu được vòng lặp bên trong của huấn luyện đối kháng. Khi thay phép chiếu lên quả cầu bằng phép chiếu lên đơn hình xác suất hoặc đa diện công bằng, ta thu được đúng phương pháp subgradient có chiếu ở mục 08-01-08.&lt;/p&gt;

&lt;h2 id=&quot;tóm-lược&quot;&gt;Tóm lược&lt;/h2&gt;

&lt;p&gt;Khi hàm mục tiêu hoặc ràng buộc chứa hàm max, chuẩn \(\ell_1\), mất mát hinge hay các tỷ lệ thực nghiệm, thuật toán bậc nhất cơ bản &lt;em&gt;chính là&lt;/em&gt; phương pháp subgradient (có thể kèm phép chiếu hoặc lấy mẫu ngẫu nhiên). Các kỹ thuật tăng tốc và toán tử gần kề ở Chương 09 giúp cải thiện đáng kể khi bài toán có cấu trúc tổng hợp rõ ràng, nhưng không thay thế hoàn toàn vòng lặp này đối với các ràng buộc tỷ lệ không trơn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Vì sao kích thước bước cố định về mặt lý thuyết gặp khó khăn với ràng buộc tỷ lệ lồi không trơn, và vì sao các phương pháp quy giảm công bằng trong thực hành vẫn sử dụng kiểu bước này?&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bolte, J., &amp;amp; Pauwels, E. (2021). Conservative set valued fields, automatic differentiation, stochastic gradient methods and deep learning. &lt;em&gt;Mathematical Programming&lt;/em&gt;, 188, 19–51.&lt;/li&gt;
  &lt;li&gt;Croce, F., &amp;amp; Hein, M. (2020). Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks. &lt;em&gt;ICML&lt;/em&gt;, PMLR 119.&lt;/li&gt;
  &lt;li&gt;Croce, F., Andriushchenko, M., Sehwag, V., Debenedetti, E., Flammarion, N., Chiang, M., Mittal, P., &amp;amp; Hein, M. (2021). RobustBench: A standardized adversarial robustness benchmark. &lt;em&gt;NeurIPS Datasets and Benchmarks&lt;/em&gt;. Bảng: &lt;a href=&quot;https://robustbench.github.io/&quot;&gt;robustbench.github.io&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Cotter, A., Jiang, H., Gupta, M., Wang, S., Narayan, T., You, S., &amp;amp; Sridharan, K. (2019). Optimization with non-differentiable constraints with applications to fairness, recall, churn, and other goals. &lt;em&gt;JMLR&lt;/em&gt;, 20(172).&lt;/li&gt;
  &lt;li&gt;Agarwal, A., Beygelzimer, A., Dudík, M., Langford, J., &amp;amp; Wallach, H. (2018). A reductions approach to fair classification. &lt;em&gt;ICML&lt;/em&gt;, PMLR 80.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257). &lt;a href=&quot;https://fairlearn.org&quot;&gt;https://fairlearn.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-11 Ứng dụng hiện đại của subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_11_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_11_modern_applications</id>
   <content type="html">&lt;p&gt;Từ các mô hình ngôn ngữ khổng lồ sử dụng khối kích hoạt không trơn (ReLU, GeLU cắt ngưỡng, chuẩn \(\ell_1\)) cho tới các hệ thống dự báo chuỗi thời gian năng lượng đòi hỏi khoảng tin cậy 90%–95% chống lại biến động cực đoan, &lt;strong&gt;giải tích không trơn (nonsmooth analysis)&lt;/strong&gt; của Chương 07 không còn là chuyên đề phụ lục của tối ưu hóa lồi — mà đã trở thành ngôn ngữ nền tảng để hiểu cách các hệ thống học máy thực sự hành xử tại những “điểm gấp nếp”.&lt;/p&gt;

&lt;p&gt;Phiên bản chuyên đề ứng dụng này tổng hợp và mở rộng góc nhìn thực chiến về ba cột trụ ứng dụng của subgradient trong giai đoạn hiện đại: lý thuyết hội tụ của vi phân tự động trên mạng không trơn, các bộ giải tối ưu thưa quy mô triệu đặc trưng, và ước lượng phân vị kết hợp dự báo đồng dạng (Conformal Prediction).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-kết-nối-subgradient-với-hệ-sinh-thái-học-máy-hiện-đại&quot;&gt;Kiến thức cần nhớ: Kết nối Subgradient với Hệ sinh thái Học máy Hiện đại&lt;/h2&gt;

&lt;p&gt;Bốn cầu nối sau giúp bạn nhìn thấy sự hiện diện của \(\partial f(x)\) đằng sau các công cụ lập trình hàng ngày:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối 1 — Subdifferential Clarke &amp;amp; Trường bảo toàn (Conservative Fields):&lt;/strong&gt; Mở rộng khái niệm vi phân dưới từ hàm lồi sang hàm Lipschitz phi lồi (như mạng nơ-ron sâu ghép nhiều lớp ReLU), giải thích tại sao SGD trên PyTorch không bị phá vỡ dù hàm mất mát không khả vi trên một hợp các siêu phẳng!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Cầu nối 2 — Tối ưu hóa Tọa độ &amp;amp; Sàng lọc KKT (Coordinate Descent + Screening):&lt;/strong&gt; Dùng trực tiếp bất đẳng thức $$&lt;/td&gt;
          &lt;td&gt;X_j^T(y - X\beta)&lt;/td&gt;
          &lt;td&gt;\le \lambda$$ để bỏ qua các biến 0 và cập nhật từng tọa độ bằng Soft-Thresholding với tốc độ nhanh hơn phương pháp điểm trong hàng trăm lần trên dữ liệu thưa.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối 3 — Dự báo Khoảng bất định bằng Pinball Loss:&lt;/strong&gt; Dùng hàm mất mát gãy khúc bất đối xứng \(\rho_\tau\) để học đồng thời cận dưới (\(\tau = 0.05\)) và cận trên (\(\tau = 0.95\)), sau đó hiệu chỉnh bằng Conformal Prediction để có bảo đảm phủ xác suất toán học chặt chẽ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối 4 — Phương pháp Subgradient vs. Proximal Gradient:&lt;/strong&gt; Khi hàm mục tiêu có dạng \(f(x) + g(x)\) (trơn + không trơn như Lasso), thay vì dùng phương pháp Subgradient chậm \(O(1/\sqrt{k})\), thực tế tách phần không trơn ra xử lý bằng &lt;strong&gt;toán tử Proximal&lt;/strong&gt; (như Soft-Thresholding) để khôi phục lại tốc độ \(O(1/k)\) và \(O(1/k^2)\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-minh-họa-quy-tắc-sàng-lọc-kkt-cho-lasso-trên-3-đặc-trưng&quot;&gt;Giải thích: Minh họa quy tắc Sàng lọc KKT cho Lasso trên 3 đặc trưng&lt;/h3&gt;

&lt;p&gt;Giả sử ta giải Lasso \(\min_\beta \frac{1}{2}\|y - X\beta\|_2^2 + \lambda\|\beta\|_1\) với \(\lambda = 2.0\), các cột dữ liệu chuẩn hóa \(\|X_j\|_2 = 1\) và giá trị tương quan ban đầu với \(y\) là:
\(X_1^T y = 5.0, \qquad X_2^T y = 0.4, \qquad X_3^T y = -3.1.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Ý tưởng sàng lọc từ điều kiện subgradient:&lt;/strong&gt;
Điều kiện để \(\beta_j^\star = 0\) là \(|X_j^T(y - X\beta^\star)| \le \lambda\).
Theo bất đẳng thức tam giác và Cauchy-Schwarz (với \(\|X_j\|_2 = 1\)):
\(|X_j^T(y - X\beta^\star)| \le |X_j^T y| + \|X_j\|_2 \|X\beta^\star\|_2 = |X_j^T y| + \|X\beta^\star\|_2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Ước lượng cận trên thô cho \(\|X\beta^\star\|_2\):&lt;/strong&gt;
Giả sử tại điểm khởi tạo hoặc từ nghiệm đối ngẫu ta biết chắc \(\|X\beta^\star\|_2 \le 1.2\).
Kiểm tra cho đặc trưng 2 (\(|X_2^T y| = 0.4\)):
\(|X_2^T(y - X\beta^\star)| \le 0.4 + 1.2 = 1.6 &amp;lt; \lambda = 2.0!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kết luận an toàn tuyệt đối (Safe Screening):&lt;/strong&gt;
Không cần chạy thêm bất kỳ vòng lặp nào trên đặc trưng 2, điều kiện subgradient đảm bảo 100% rằng \(\beta_2^\star = 0\)! Trong dữ liệu thực có \(p = 100\,000\) đặc trưng, quy tắc sàng lọc như thế này giúp vứt bỏ ngay &amp;gt;95% cột dữ liệu vô ích!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-subgradient&quot;&gt;Ứng dụng hiện đại của subgradient&lt;/h1&gt;

&lt;p&gt;Bài đọc tùy chọn này &lt;strong&gt;không&lt;/strong&gt; lặp lại các phép tính cơ bản của Chương 07, mà chỉ ra nơi các khái niệm đó — một vector \(g\) thỏa mãn \(f(y)\ge f(x)+g^\top(y-x)\), tập vi phân dưới \(\partial f(x)\), và điều kiện dừng \(0\in\partial f(x^\star)\) — xuất hiện trong các hệ thống khoa học máy tính và khoa học dữ liệu giai đoạn 2022–2026. Sau bài này, bạn có thể nhận diện một hàm mất mát hoặc thành phần chính quy hóa không trơn trong hệ thống thực tế, viết được điều kiện bao hàm đặc trưng cho nghiệm tối ưu, và liên hệ trực tiếp với các công trình nghiên cứu nền tảng.&lt;/p&gt;

&lt;h2 id=&quot;vì-sao-subgradient-vẫn-giữ-vai-trò-cốt-lõi&quot;&gt;Vì sao subgradient vẫn giữ vai trò cốt lõi&lt;/h2&gt;

&lt;p&gt;Mạng ReLU, chọn đặc trưng bằng chuẩn \(\ell_1\), hàm mất mát pinball (cho hồi quy phân vị) và hàm mất mát Huber đều là những thành phần &lt;strong&gt;lồi không trơn hoặc khả vi theo đường (path-differentiable)&lt;/strong&gt;. Các thư viện vi phân tự động như PyTorch hay JAX vẫn trả về một vector tại điểm gấp khúc; khái niệm toán học chính xác cho đối tượng đó là &lt;strong&gt;trường bảo toàn&lt;/strong&gt; (conservative field), vốn trùng với subgradient trên các thành phần lồi và trùng với vi phân Clarke hầu khắp nơi. Nếu chỉ dựa vào quy tắc “gradient bằng không tại cực tiểu”, ta không thể phân tích tập giá (support) của Lasso, hiện tượng nút ReLU bất hoạt, hay nghiệm của bài toán hồi quy phân vị.&lt;/p&gt;

&lt;h2 id=&quot;1-mạng-relu-và-vi-phân-tự-động-không-trơn&quot;&gt;1. Mạng ReLU và vi phân tự động không trơn&lt;/h2&gt;

&lt;p&gt;Hàm kích hoạt chỉnh lưu \(\operatorname{ReLU}(t)=\max\{t,0\}\) có vi phân dưới:&lt;/p&gt;

\[\partial\operatorname{ReLU}(t)=\begin{cases}\{0\} &amp;amp; t&amp;lt;0,\\ [0,1] &amp;amp; t=0,\\ \{1\} &amp;amp; t&amp;gt;0.\end{cases}\]

&lt;p&gt;Một mạng nơ-ron sâu tạo từ các phép biến đổi affine và hàm ReLU có tính liên tục Lipschitz và nửa đại số (semialgebraic), do đó &lt;strong&gt;khả vi theo đường&lt;/strong&gt;. Bolte và Pauwels (2021) chỉ ra rằng đối tượng mà lan truyền ngược (backpropagation) thực sự tính toán là một &lt;em&gt;trường đa trị bảo toàn&lt;/em&gt; (conservative set-valued field): nó thỏa mãn quy tắc dây chuyền ngay cả khi vi phân Clarke của mạng ReLU không nhất thiết tuân theo quy tắc này. Bolte, Boustany, Pauwels và Pesquet (2022) chứng minh &lt;strong&gt;nguyên lý gradient chi phí thấp cho hàm không trơn&lt;/strong&gt; đối với vi phân tự động chế độ ngược, đồng thời chỉ ra rằng bài toán tính &lt;em&gt;hai&lt;/em&gt; phần tử Clarke khác nhau của một mạng ReLU đơn giản đã là NP-khó — vì vậy các thư viện thực tế chọn một phần tử cố định trong \(\partial\operatorname{ReLU}(0)\) (thường là \(0\)) là điều có cơ sở lý thuyết. Blondel và Roulet (2024) hệ thống hóa cách tiếp cận này dưới khung &lt;em&gt;lập trình khả vi&lt;/em&gt;: thiết kế chương trình sao cho tồn tại đạo hàm bảo toàn, rồi huấn luyện bằng SGD.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liên hệ với giáo trình.&lt;/strong&gt; Các quy tắc trong &lt;a href=&quot;/contents/vi/chapter07/07_02_02_subgradient_calculus/&quot;&gt;07-02-02 Phép tính subgradient&lt;/a&gt; (phép cộng, giá trị lớn nhất, hợp thành với ánh xạ affine) chính là các quy tắc trên đồ thị tính toán của mạng ReLU. Điều kiện \(0\in\partial f(x)\) vẫn là tiêu chuẩn tối ưu bắt buộc đối với các bài toán lớp cuối lồi như SVM tuyến tính hay đầu ra Lasso.&lt;/p&gt;

&lt;h2 id=&quot;2-lasso-elastic-net-và-các-bộ-giải-glm-hiện-đại&quot;&gt;2. Lasso, elastic net và các bộ giải GLM hiện đại&lt;/h2&gt;

&lt;p&gt;Bài toán Lasso&lt;/p&gt;

\[\min_\beta\ \tfrac12\|y-X\beta\|_2^2+\lambda\|\beta\|_1\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;là ví dụ xuyên suốt chương này: điều kiện dừng là \(X^\top(y-X\beta)=\lambda v\) với \(v\in\partial|\beta|_1\), nghĩa là \(v_j=\operatorname{sign}(\beta_j)\) trên tập giá và $$&lt;/td&gt;
      &lt;td&gt;v_j&lt;/td&gt;
      &lt;td&gt;\le 1$$ ngoài tập giá (&lt;a href=&quot;/contents/vi/chapter07/07_03_03_example_lasso_optimality_condition/&quot;&gt;07-03-03 Điều kiện tối ưu Lasso&lt;/a&gt;). Chính điều kiện bao hàm này là cơ sở để &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt; xác định tọa độ nào bằng không.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Tay, Narasimhan và Hastie (2023) mở rộng đường chính quy hóa elastic net trong &lt;strong&gt;glmnet 4.1+&lt;/strong&gt; cho &lt;em&gt;mọi&lt;/em&gt; họ mô hình tuyến tính tổng quát (GLM) và mô hình Cox phân tầng — công cụ quen thuộc cho điểm số đa gene, phân tích sống còn và dự báo lâm sàng nhiều chiều. Bertrand, Klopfenstein, Bannier, Gidel và Massias (2022) phát triển &lt;strong&gt;skglm&lt;/strong&gt;, bộ giải tương thích scikit-learn sử dụng chiến lược tập làm việc (working set) kết hợp kiểm định khoảng cách đối ngẫu (dual gap, cũng dựa trên bao hàm vi phân dưới) để khớp các GLM thưa với hàng triệu đặc trưng chỉ trong vài giây. Guha, Ndiaye và Huo (2023) sử dụng kỹ thuật đồng luân (homotopy) của Lasso — bám theo đúng các bước chuyển tập hoạt động suy ra từ \(\partial\|\cdot\|_1\) — để xây dựng &lt;strong&gt;tập dự báo conformal&lt;/strong&gt; cho GLM thưa mà không cần huấn luyện lại cho từng giá trị đầu ra ứng viên.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điểm cần nhớ.&lt;/strong&gt; Toán tử ngưỡng mềm (soft-thresholding) không chỉ là một bài tập tính toán; nó là ánh xạ gần kề của \(\lambda\|\cdot\|_1\) và là cơ sở để chứng nhận một cột đặc trưng không hoạt động.&lt;/p&gt;

&lt;h2 id=&quot;3-hàm-mất-mát-pinball-phân-vị-và-khoảng-dự-báo-không-phụ-thuộc-phân-phối&quot;&gt;3. Hàm mất mát pinball, phân vị và khoảng dự báo không phụ thuộc phân phối&lt;/h2&gt;

&lt;p&gt;Hàm mất mát pinball (còn gọi là hàm check) \(\rho_\tau(r)=\tau r_+ +(1-\tau)(-r)_+\) là hàm lồi và tuyến tính từng khúc. Ước lượng phân vị mẫu là nghiệm cực tiểu của \(\sum_i\rho_\tau(y_i-x_i^\top\beta)\); gradient dưới theo phần dư bằng \(\tau\) khi phần dư dương, bằng \(\tau-1\) khi phần dư âm, và thuộc đoạn \([\tau-1,\tau]\) tại điểm gấp khúc bằng không. Hồi quy phân vị conformal (Conformalized Quantile Regression — Romano, Patterson và Candès, 2019) kết hợp bước khớp không trơn này với một bước hiệu chuẩn để bảo đảm độ phủ thống kê; Angelopoulos và Bates (2023) trình bày tài liệu hướng dẫn được sử dụng rộng rãi trong các hệ thống thị giác máy tính và xử lý ngôn ngữ tự nhiên khi cần &lt;strong&gt;khoảng dự báo 90%&lt;/strong&gt; thay vì dự báo điểm. Công trình ICML 2023 nêu trên là phiên bản mở rộng cho bài toán thưa nhiều chiều.&lt;/p&gt;

&lt;h2 id=&quot;4-đoạn-mã-kiểm-tra-ngắn&quot;&gt;4. Đoạn mã kiểm tra ngắn&lt;/h2&gt;

&lt;p&gt;Đoạn mã sau tính một gradient dưới của \(\|x\|_1\) và của hàm ReLU tại gốc tọa độ — hai điểm gấp khúc phổ biến nhất.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;subgrad_l1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# một phần tử của [-1, 1]
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;relu_elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kink&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;else &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subgrad_l1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;relu_elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Việc thay đổi giá trị chọn tại điểm gấp khúc không làm thay đổi bất đẳng thức lồi, nhưng &lt;em&gt;có&lt;/em&gt; làm thay đổi kết quả lan truyền ngược trong mạng sâu. Đó là minh họa trực quan nhất cho khái niệm trường bảo toàn.&lt;/p&gt;

&lt;h2 id=&quot;tóm-lược&quot;&gt;Tóm lược&lt;/h2&gt;

&lt;p&gt;Gradient dưới là chứng chỉ tối ưu cho các mô hình lồi không trơn, và một lựa chọn bảo toàn của nó chính là đối tượng mà các thư viện vi phân tự động hiện đại tính toán. Khi các bài báo đề cập đến việc huấn luyện mạng ReLU, GLM-Lasso hay hồi quy phân vị, đối tượng bậc nhất đằng sau đều quay về khái niệm được định nghĩa trong chương này.&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Nếu một tọa độ trong bài toán Lasso thỏa mãn $$&lt;/td&gt;
      &lt;td&gt;X_j^\top(y-X\hat\beta)&lt;/td&gt;
      &lt;td&gt;&amp;lt;\lambda\(, vì sao ta có thể loại bỏ cột\)j\(mà không làm thay đổi nghiệm\)\hat\beta$$? Về mặt hình học, hiện tượng này tương đồng như thế nào với một đơn vị ReLU không kích hoạt?&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bolte, J., &amp;amp; Pauwels, E. (2021). Conservative set valued fields, automatic differentiation, stochastic gradient methods and deep learning. &lt;em&gt;Mathematical Programming&lt;/em&gt;, 188, 19–51. &lt;a href=&quot;https://doi.org/10.1007/s10107-020-01501-5&quot;&gt;doi:10.1007/s10107-020-01501-5&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bolte, J., Boustany, R., Pauwels, E., &amp;amp; Pesquet, B. (2022). On the complexity of nonsmooth automatic differentiation. &lt;a href=&quot;https://arxiv.org/abs/2206.01730&quot;&gt;arXiv:2206.01730&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Blondel, M., &amp;amp; Roulet, V. (2024). &lt;em&gt;The Elements of Differentiable Programming&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2403.14606&quot;&gt;arXiv:2403.14606&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Tay, J. K., Narasimhan, B., &amp;amp; Hastie, T. (2023). Elastic net regularization paths for all generalized linear models. &lt;em&gt;Journal of Statistical Software&lt;/em&gt;, 106(1), 1–31. &lt;a href=&quot;https://doi.org/10.18637/jss.v106.i01&quot;&gt;doi:10.18637/jss.v106.i01&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bertrand, Q., Klopfenstein, Q., Bannier, P.-A., Gidel, G., &amp;amp; Massias, M. (2022). Beyond L1: Faster and better sparse models with skglm. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Guha, E. K., Ndiaye, E., &amp;amp; Huo, X. (2023). Conformalization of sparse generalized linear models. &lt;em&gt;ICML&lt;/em&gt;, PMLR 202.&lt;/li&gt;
  &lt;li&gt;Angelopoulos, A. N., &amp;amp; Bates, S. (2023). Conformal prediction: A gentle introduction. &lt;em&gt;Foundations and Trends in Machine Learning&lt;/em&gt;, 16(4).&lt;/li&gt;
  &lt;li&gt;Romano, Y., Patterson, E., &amp;amp; Candès, E. J. (2019). Conformalized quantile regression. &lt;em&gt;NeurIPS&lt;/em&gt;. (nền cho pipeline pinball + hiệu chuẩn)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-08 Ứng dụng hiện đại của subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_08_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_08_modern_applications</id>
   <content type="html">&lt;p&gt;Một hiểu lầm rất phổ biến trong giới sinh viên AI là: &lt;em&gt;“Mạng nơ-ron sâu chạy bằng PyTorch Autograd, còn Subgradient chỉ là lý thuyết cổ điển dành cho Lasso hay SVM thôi!”&lt;/em&gt; Sự thật hoàn toàn ngược lại: hàm kích hoạt phổ biến nhất lịch sử học sâu — &lt;strong&gt;ReLU&lt;/strong&gt; \(\max(0, z)\) — &lt;strong&gt;không hề khả vi tại \(z = 0\)&lt;/strong&gt;! Mỗi lần bạn bấm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.backward()&lt;/code&gt; trên một mạng ReLU nhiều lớp, bộ vi phân tự động đang âm thầm chọn một &lt;strong&gt;subgradient&lt;/strong&gt; (hoặc Clarke generalized gradient) tại các điểm gãy khúc!&lt;/p&gt;

&lt;p&gt;Bài đọc chuyên đề hiện đại này nối trực tiếp khái niệm \(g \in \partial f(x)\) của Chương 07 với ba lĩnh vực nóng nhất giai đoạn 2022–2026: &lt;strong&gt;vi phân tự động không trơn cho mạng ReLU&lt;/strong&gt;, &lt;strong&gt;các bộ giải GLM/Lasso quy mô lớn (coordinate descent, screening rules)&lt;/strong&gt;, và &lt;strong&gt;hồi quy phân vị (Pinball Loss / Conformalized Quantile Regression)&lt;/strong&gt; dùng để xây dựng khoảng tin cậy bất định không phụ thuộc phân phối!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-mặt-trận-hiện-đại-của-subgradient-trong-ai--thống-kê&quot;&gt;Kiến thức cần nhớ: Ba mặt trận hiện đại của Subgradient trong AI &amp;amp; Thống kê&lt;/h2&gt;

&lt;p&gt;Để đọc hiểu sâu các chủ đề ứng dụng trong bài, hãy gắn chúng vào ba trụ cột lý thuyết Chương 07:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vi phân tự động không trơn (Nonsmooth Autograd &amp;amp; Conservative Fields):&lt;/strong&gt; Với mạng ReLU sâu (phi lồi &amp;amp; không trơn), quy tắc dây chuyền cổ điển không còn đúng hoàn toàn tại tập điểm độ đo 0. Lý thuyết &lt;em&gt;conservative set-valued fields&lt;/em&gt; (Bolte &amp;amp; Pauwels) tổng quát hóa subdifferential để chứng minh vì sao PyTorch/JAX chọn đạo hàm bằng \(0\) (hoặc \(1\)) tại \(z = 0\) vẫn hội tụ hợp lệ!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Quy tắc sàng lọc an toàn cho Lasso/Elastic Net (Safe Screening Rules):&lt;/strong&gt; Nhờ điều kiện subgradient $$&lt;/td&gt;
          &lt;td&gt;X_j^T(y - X\beta^\star)&lt;/td&gt;
          &lt;td&gt;\le \lambda \implies \beta_j^\star = 0$$, các thư viện như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;celer&lt;/code&gt; có thể &lt;strong&gt;loại bỏ trước hàng trăm nghìn đặc trưng chắc chắn bằng 0&lt;/strong&gt; ngay từ vòng lặp đầu mà không cần tối ưu trên chúng!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mất mát Pinball &amp;amp; Hồi quy Phân vị (Quantile Regression):&lt;/strong&gt; Thay vì dự báo giá trị trung bình (\(\ell_2\)) hay trung vị (\(\ell_1\)), hàm mất mát pinball không trơn \(\rho_\tau(u) = \max(\tau u,\; (\tau - 1)u)\) (với \(\tau \in (0, 1)\)) dùng đúng điều kiện \(0 \in \partial \sum \rho_\tau(y_i - \hat{y}_i)\) để ước lượng phân vị thứ \(\tau\) (ví dụ 90% hay 95%) cho bài toán định lượng bất định (Conformal Prediction)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-dùng-điều-kiện-subgradient-chứng-minh-pinball-loss-tìm-đúng-phân-vị-thứ-tau&quot;&gt;Giải thích: Dùng điều kiện subgradient chứng minh Pinball Loss tìm đúng phân vị thứ \(\tau\)&lt;/h3&gt;

&lt;p&gt;Xét 4 quan sát đã sắp xếp \(y = (10,\; 20,\; 30,\; 100)\) và mục tiêu tìm hằng số \(q\) cực tiểu hóa tổng hàm mất mát pinball với \(\tau = 0.75\) (phân vị 75%):
\(F(q) = \sum_{i=1}^4 \rho_{0.75}(y_i - q), \qquad \rho_\tau(u) = \begin{cases} \tau u &amp;amp; \text{nếu } u \ge 0 \\ (\tau - 1) u &amp;amp; \text{nếu } u &amp;lt; 0 \end{cases}\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tính vi phân dưới theo \(q\) của từng số hạng \(f_i(q) = \rho_{0.75}(y_i - q)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu \(q &amp;lt; y_i\) (tức \(y_i - q &amp;gt; 0\)): \(f_i(q) = 0.75(y_i - q) \implies f_i&apos;(q) = -0.75\).&lt;/li&gt;
      &lt;li&gt;Nếu \(q &amp;gt; y_i\) (tức \(y_i - q &amp;lt; 0\)): \(f_i(q) = -0.25(y_i - q) \implies f_i&apos;(q) = +0.25\).&lt;/li&gt;
      &lt;li&gt;Nếu \(q = y_i\) (điểm gãy khúc): \(\partial f_i(q) = [-0.75,\; +0.25]\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Kiểm tra điều kiện tối ưu \(0 \in \partial F(q)\) tại \(q = 30\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(y_1 = 10 &amp;lt; 30\): đóng góp \(+0.25\).&lt;/li&gt;
      &lt;li&gt;Với \(y_2 = 20 &amp;lt; 30\): đóng góp \(+0.25\).&lt;/li&gt;
      &lt;li&gt;Với \(y_3 = 30 = q\): đóng góp đoạn \([-0.75,\; +0.25]\).&lt;/li&gt;
      &lt;li&gt;Với \(y_4 = 100 &amp;gt; 30\): đóng góp \(-0.75\).
Cộng Minkowski: \(\partial F(30) = (0.25 + 0.25 - 0.75) + [-0.75, 0.25] = [-1.00,\; 0.00]\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Vì \(0 \in [-1.00, 0.00]\), \(q^\star = 30\) (chính xác là phân vị 75%: 3/4 mẫu \(\le 30\)!) là nghiệm tối ưu toàn cục — bất kể giá trị ngoại lai \(100\) có tăng lên \(10\,000\) đi nữa!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;ứng-dụng-hiện-đại-của-subgradient&quot;&gt;Ứng dụng hiện đại của subgradient&lt;/h1&gt;

&lt;p&gt;Bài đọc tùy chọn này &lt;strong&gt;không&lt;/strong&gt; lặp lại các phép tính cơ bản của Chương 07, mà chỉ ra nơi các khái niệm đó — một vector \(g\) thỏa mãn \(f(y)\ge f(x)+g^\top(y-x)\), tập vi phân dưới \(\partial f(x)\), và điều kiện dừng \(0\in\partial f(x^\star)\) — xuất hiện trong các hệ thống khoa học máy tính và khoa học dữ liệu giai đoạn 2022–2026. Sau bài này, bạn có thể nhận diện một hàm mất mát hoặc thành phần chính quy hóa không trơn trong hệ thống thực tế, viết được điều kiện bao hàm đặc trưng cho nghiệm tối ưu, và liên hệ trực tiếp với các công trình nghiên cứu nền tảng.&lt;/p&gt;

&lt;h2 id=&quot;vì-sao-subgradient-vẫn-giữ-vai-trò-cốt-lõi&quot;&gt;Vì sao subgradient vẫn giữ vai trò cốt lõi&lt;/h2&gt;

&lt;p&gt;Mạng ReLU, chọn đặc trưng bằng chuẩn \(\ell_1\), hàm mất mát pinball (cho hồi quy phân vị) và hàm mất mát Huber đều là những thành phần &lt;strong&gt;lồi không trơn hoặc khả vi theo đường (path-differentiable)&lt;/strong&gt;. Các thư viện vi phân tự động như PyTorch hay JAX vẫn trả về một vector tại điểm gấp khúc; khái niệm toán học chính xác cho đối tượng đó là &lt;strong&gt;trường bảo toàn&lt;/strong&gt; (conservative field), vốn trùng với subgradient trên các thành phần lồi và trùng với vi phân Clarke hầu khắp nơi. Nếu chỉ dựa vào quy tắc “gradient bằng không tại cực tiểu”, ta không thể phân tích tập giá (support) của Lasso, hiện tượng nút ReLU bất hoạt, hay nghiệm của bài toán hồi quy phân vị.&lt;/p&gt;

&lt;h2 id=&quot;1-mạng-relu-và-vi-phân-tự-động-không-trơn&quot;&gt;1. Mạng ReLU và vi phân tự động không trơn&lt;/h2&gt;

&lt;p&gt;Hàm kích hoạt chỉnh lưu \(\operatorname{ReLU}(t)=\max\{t,0\}\) có vi phân dưới:&lt;/p&gt;

\[\partial\operatorname{ReLU}(t)=\begin{cases}\{0\} &amp;amp; t&amp;lt;0,\\ [0,1] &amp;amp; t=0,\\ \{1\} &amp;amp; t&amp;gt;0.\end{cases}\]

&lt;p&gt;Một mạng nơ-ron sâu tạo từ các phép biến đổi affine và hàm ReLU có tính liên tục Lipschitz và nửa đại số (semialgebraic), do đó &lt;strong&gt;khả vi theo đường&lt;/strong&gt;. Bolte và Pauwels (2021) chỉ ra rằng đối tượng mà lan truyền ngược (backpropagation) thực sự tính toán là một &lt;em&gt;trường đa trị bảo toàn&lt;/em&gt; (conservative set-valued field): nó thỏa mãn quy tắc dây chuyền ngay cả khi vi phân Clarke của mạng ReLU không nhất thiết tuân theo quy tắc này. Bolte, Boustany, Pauwels và Pesquet (2022) chứng minh &lt;strong&gt;nguyên lý gradient chi phí thấp cho hàm không trơn&lt;/strong&gt; đối với vi phân tự động chế độ ngược, đồng thời chỉ ra rằng bài toán tính &lt;em&gt;hai&lt;/em&gt; phần tử Clarke khác nhau của một mạng ReLU đơn giản đã là NP-khó — vì vậy các thư viện thực tế chọn một phần tử cố định trong \(\partial\operatorname{ReLU}(0)\) (thường là \(0\)) là điều có cơ sở lý thuyết. Blondel và Roulet (2024) hệ thống hóa cách tiếp cận này dưới khung &lt;em&gt;lập trình khả vi&lt;/em&gt;: thiết kế chương trình sao cho tồn tại đạo hàm bảo toàn, rồi huấn luyện bằng SGD.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liên hệ với giáo trình.&lt;/strong&gt; Các quy tắc trong &lt;a href=&quot;/contents/vi/chapter07/07_02_02_subgradient_calculus/&quot;&gt;07-02-02 Phép tính subgradient&lt;/a&gt; (phép cộng, giá trị lớn nhất, hợp thành với ánh xạ affine) chính là các quy tắc trên đồ thị tính toán của mạng ReLU. Điều kiện \(0\in\partial f(x)\) vẫn là tiêu chuẩn tối ưu bắt buộc đối với các bài toán lớp cuối lồi như SVM tuyến tính hay đầu ra Lasso.&lt;/p&gt;

&lt;h2 id=&quot;2-lasso-elastic-net-và-các-bộ-giải-glm-hiện-đại&quot;&gt;2. Lasso, elastic net và các bộ giải GLM hiện đại&lt;/h2&gt;

&lt;p&gt;Bài toán Lasso&lt;/p&gt;

\[\min_\beta\ \tfrac12\|y-X\beta\|_2^2+\lambda\|\beta\|_1\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;là ví dụ xuyên suốt chương này: điều kiện dừng là \(X^\top(y-X\beta)=\lambda v\) với \(v\in\partial|\beta|_1\), nghĩa là \(v_j=\operatorname{sign}(\beta_j)\) trên tập giá và $$&lt;/td&gt;
      &lt;td&gt;v_j&lt;/td&gt;
      &lt;td&gt;\le 1$$ ngoài tập giá (&lt;a href=&quot;/contents/vi/chapter07/07_03_03_example_lasso_optimality_condition/&quot;&gt;07-03-03 Điều kiện tối ưu Lasso&lt;/a&gt;). Chính điều kiện bao hàm này là cơ sở để &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt; xác định tọa độ nào bằng không.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Tay, Narasimhan và Hastie (2023) mở rộng đường chính quy hóa elastic net trong &lt;strong&gt;glmnet 4.1+&lt;/strong&gt; cho &lt;em&gt;mọi&lt;/em&gt; họ mô hình tuyến tính tổng quát (GLM) và mô hình Cox phân tầng — công cụ quen thuộc cho điểm số đa gene, phân tích sống còn và dự báo lâm sàng nhiều chiều. Bertrand, Klopfenstein, Bannier, Gidel và Massias (2022) phát triển &lt;strong&gt;skglm&lt;/strong&gt;, bộ giải tương thích scikit-learn sử dụng chiến lược tập làm việc (working set) kết hợp kiểm định khoảng cách đối ngẫu (dual gap, cũng dựa trên bao hàm vi phân dưới) để khớp các GLM thưa với hàng triệu đặc trưng chỉ trong vài giây. Guha, Ndiaye và Huo (2023) sử dụng kỹ thuật đồng luân (homotopy) của Lasso — bám theo đúng các bước chuyển tập hoạt động suy ra từ \(\partial\|\cdot\|_1\) — để xây dựng &lt;strong&gt;tập dự báo conformal&lt;/strong&gt; cho GLM thưa mà không cần huấn luyện lại cho từng giá trị đầu ra ứng viên.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điểm cần nhớ.&lt;/strong&gt; Toán tử ngưỡng mềm (soft-thresholding) không chỉ là một bài tập tính toán; nó là ánh xạ gần kề của \(\lambda\|\cdot\|_1\) và là cơ sở để chứng nhận một cột đặc trưng không hoạt động.&lt;/p&gt;

&lt;h2 id=&quot;3-hàm-mất-mát-pinball-phân-vị-và-khoảng-dự-báo-không-phụ-thuộc-phân-phối&quot;&gt;3. Hàm mất mát pinball, phân vị và khoảng dự báo không phụ thuộc phân phối&lt;/h2&gt;

&lt;p&gt;Hàm mất mát pinball (còn gọi là hàm check) \(\rho_\tau(r)=\tau r_+ +(1-\tau)(-r)_+\) là hàm lồi và tuyến tính từng khúc. Ước lượng phân vị mẫu là nghiệm cực tiểu của \(\sum_i\rho_\tau(y_i-x_i^\top\beta)\); gradient dưới theo phần dư bằng \(\tau\) khi phần dư dương, bằng \(\tau-1\) khi phần dư âm, và thuộc đoạn \([\tau-1,\tau]\) tại điểm gấp khúc bằng không. Hồi quy phân vị conformal (Conformalized Quantile Regression — Romano, Patterson và Candès, 2019) kết hợp bước khớp không trơn này với một bước hiệu chuẩn để bảo đảm độ phủ thống kê; Angelopoulos và Bates (2023) trình bày tài liệu hướng dẫn được sử dụng rộng rãi trong các hệ thống thị giác máy tính và xử lý ngôn ngữ tự nhiên khi cần &lt;strong&gt;khoảng dự báo 90%&lt;/strong&gt; thay vì dự báo điểm. Công trình ICML 2023 nêu trên là phiên bản mở rộng cho bài toán thưa nhiều chiều.&lt;/p&gt;

&lt;h2 id=&quot;4-đoạn-mã-kiểm-tra-ngắn&quot;&gt;4. Đoạn mã kiểm tra ngắn&lt;/h2&gt;

&lt;p&gt;Đoạn mã sau tính một gradient dưới của \(\|x\|_1\) và của hàm ReLU tại gốc tọa độ — hai điểm gấp khúc phổ biến nhất.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;subgrad_l1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# một phần tử của [-1, 1]
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;relu_elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kink&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;else &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subgrad_l1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;relu_elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Việc thay đổi giá trị chọn tại điểm gấp khúc không làm thay đổi bất đẳng thức lồi, nhưng &lt;em&gt;có&lt;/em&gt; làm thay đổi kết quả lan truyền ngược trong mạng sâu. Đó là minh họa trực quan nhất cho khái niệm trường bảo toàn.&lt;/p&gt;

&lt;h2 id=&quot;tóm-lược&quot;&gt;Tóm lược&lt;/h2&gt;

&lt;p&gt;Gradient dưới là chứng chỉ tối ưu cho các mô hình lồi không trơn, và một lựa chọn bảo toàn của nó chính là đối tượng mà các thư viện vi phân tự động hiện đại tính toán. Khi các bài báo đề cập đến việc huấn luyện mạng ReLU, GLM-Lasso hay hồi quy phân vị, đối tượng bậc nhất đằng sau đều quay về khái niệm được định nghĩa trong chương này.&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Nếu một tọa độ trong bài toán Lasso thỏa mãn $$&lt;/td&gt;
      &lt;td&gt;X_j^\top(y-X\hat\beta)&lt;/td&gt;
      &lt;td&gt;&amp;lt;\lambda\(, vì sao ta có thể loại bỏ cột\)j\(mà không làm thay đổi nghiệm\)\hat\beta$$? Về mặt hình học, hiện tượng này tương đồng như thế nào với một đơn vị ReLU không kích hoạt?&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bolte, J., &amp;amp; Pauwels, E. (2021). Conservative set valued fields, automatic differentiation, stochastic gradient methods and deep learning. &lt;em&gt;Mathematical Programming&lt;/em&gt;, 188, 19–51. &lt;a href=&quot;https://doi.org/10.1007/s10107-020-01501-5&quot;&gt;doi:10.1007/s10107-020-01501-5&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bolte, J., Boustany, R., Pauwels, E., &amp;amp; Pesquet, B. (2022). On the complexity of nonsmooth automatic differentiation. &lt;a href=&quot;https://arxiv.org/abs/2206.01730&quot;&gt;arXiv:2206.01730&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Blondel, M., &amp;amp; Roulet, V. (2024). &lt;em&gt;The Elements of Differentiable Programming&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2403.14606&quot;&gt;arXiv:2403.14606&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Tay, J. K., Narasimhan, B., &amp;amp; Hastie, T. (2023). Elastic net regularization paths for all generalized linear models. &lt;em&gt;Journal of Statistical Software&lt;/em&gt;, 106(1), 1–31. &lt;a href=&quot;https://doi.org/10.18637/jss.v106.i01&quot;&gt;doi:10.18637/jss.v106.i01&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bertrand, Q., Klopfenstein, Q., Bannier, P.-A., Gidel, G., &amp;amp; Massias, M. (2022). Beyond L1: Faster and better sparse models with skglm. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Guha, E. K., Ndiaye, E., &amp;amp; Huo, X. (2023). Conformalization of sparse generalized linear models. &lt;em&gt;ICML&lt;/em&gt;, PMLR 202.&lt;/li&gt;
  &lt;li&gt;Angelopoulos, A. N., &amp;amp; Bates, S. (2023). Conformal prediction: A gentle introduction. &lt;em&gt;Foundations and Trends in Machine Learning&lt;/em&gt;, 16(4).&lt;/li&gt;
  &lt;li&gt;Romano, Y., Patterson, E., &amp;amp; Candès, E. J. (2019). Conformalized quantile regression. &lt;em&gt;NeurIPS&lt;/em&gt;. (nền cho pipeline pinball + hiệu chuẩn)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-08 Ứng dụng và phát triển gần đây</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_08_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_08_Applications_Recent</id>
   <content type="html">&lt;p&gt;Suốt Chương 06, bạn đã nắm vững định lý cổ điển: Gradient Descent chỉ ổn định khi kích thước bước \(t &amp;lt; 2/L\), và nếu vượt quá ngưỡng đó thuật toán sẽ phân kỳ. Thế nhưng vào năm 2021, khi các nhà nghiên cứu đo trực tiếp độ cong Hessian trong quá trình huấn luyện mạng nơ-ron sâu thật, họ phát hiện một hiện tượng gây chấn động: &lt;strong&gt;độ sắc nét \(\lambda_{\max}(\nabla^2 L)\) tự động tăng vọt lên chạm đúng ngưỡng \(2/t\) rồi dao động ổn định ngay trên “mép vực” đó trong suốt hàng nghìn vòng lặp mà không hề phân kỳ!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hiện tượng &lt;strong&gt;Mép ổn định (Edge of Stability)&lt;/strong&gt; cùng với sự ra đời của các bộ tối ưu thế hệ mới như &lt;strong&gt;Lion&lt;/strong&gt; (tìm ra bằng tiến hóa chương trình tự động của Google Brain, chỉ dùng dấu của momentum) và &lt;strong&gt;Schedule-Free SGD/AdamW&lt;/strong&gt; (bỏ hoàn toàn lịch giảm tốc độ học thủ công) cho thấy lý thuyết Gradient Descent của Chương 06 vẫn đang tiến hóa sôi động từng năm!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-bước-tiến-hiện-đại-vượt-ra-ngoài-khung-gd-cổ-điển&quot;&gt;Kiến thức cần nhớ: Ba bước tiến hiện đại vượt ra ngoài khung GD cổ điển&lt;/h2&gt;

&lt;p&gt;Để kết nối lý thuyết Chương 06 với nghiên cứu tối ưu hóa giai đoạn 2021–2026, hãy nắm ba trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mép ổn định (Edge of Stability — Cohen et al.):&lt;/strong&gt; Trên mạng nơ-ron phi lồi, bước học cố định \(\eta\) không khiến hàm mất mát phân kỳ khi \(\lambda_{\max}\) vượt \(2/\eta\); thay vào đó, độ cong tự điều chỉnh xoay quanh đúng ranh giới \(2/\eta\) và hàm mất mát vẫn giảm dần theo xu hướng dài hạn dù dao động cục bộ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lion (EvoLved Sign Momentum):&lt;/strong&gt; Cập nhật tham số chỉ bằng &lt;strong&gt;dấu&lt;/strong&gt; (\(\operatorname{sign}\)) của tổ hợp momentum: \(x_{t+1} = x_t - \eta \operatorname{sign}(\beta_1 m_{t-1} + (1-\beta_1) g_t)\). Mọi tọa độ di chuyển cùng một biên độ \(\eta\) (tương ứng chuẩn \(\ell_\infty\) thay vì \(\ell_2\)!), giúp tiết kiệm một nửa bộ nhớ trạng thái so với AdamW!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa không cần lịch học (Schedule-Free Optimization):&lt;/strong&gt; Thay vì phải đoán trước tổng số bước \(T\) để thiết kế lịch cosine decay, phương pháp Schedule-Free duy trì hai chuỗi lặp (một chuỗi cập nhật và một chuỗi trung bình nội suy) để tự động đạt tốc độ hội tụ tối ưu cho mọi thời điểm dừng!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-sự-khác-biệt-giữa-bước-gd-chuẩn-và-bước-lion-sign-momentum&quot;&gt;Giải thích: Tính tay sự khác biệt giữa bước GD chuẩn và bước Lion (Sign Momentum)&lt;/h3&gt;

&lt;p&gt;Giả sử tại một bước huấn luyện, hai tọa độ của vector gradient (sau khi trộn momentum) có độ lớn chênh lệch cực mạnh:
\(u = (0.01,\; -10.0)^T, \qquad \text{với tốc độ học } \eta = 0.1.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật của GD / Momentum chuẩn (theo chuẩn \(\ell_2\)):&lt;/strong&gt;
\(\Delta x_{\text{GD}} = -0.1 \begin{pmatrix} 0.01 \\ -10.0 \end{pmatrix} = \begin{pmatrix} -0.001 \\ +1.000 \end{pmatrix}.\)
Tọa độ thứ nhất nhích đi cực chậm (\(0.001\)), trong khi tọa độ thứ hai nhảy vọt gấp &lt;strong&gt;1.000 lần&lt;/strong&gt; (\(1.0\)), dễ gây mất ổn định!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật của Lion (theo dấu \(\operatorname{sign}(u)\), chuẩn \(\ell_\infty\)):&lt;/strong&gt;
\(\operatorname{sign}(u) = \begin{pmatrix} +1 \\ -1 \end{pmatrix} \implies \Delta x_{\text{Lion}} = -0.1 \begin{pmatrix} +1 \\ -1 \end{pmatrix} = \begin{pmatrix} -0.1 \\ +0.1 \end{pmatrix}.\)
Cả hai tọa độ đều bước đi đều đặn đúng biên độ \(\eta = 0.1\) bất kể gradient lớn hay nhỏ! (Vì bước luôn có độ lớn cố định \(\eta\), Lion thường dùng \(\eta\) nhỏ hơn AdamW khoảng 3–10 lần và kết hợp weight decay lớn hơn để giữ ổn định!)&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Chương 06 trình bày nền tảng cổ điển của gradient descent gồm tính liên tục Lipschitz của gradient, các quy tắc chọn kích thước bước và tốc độ hội tụ nhanh hơn dưới giả thiết lồi mạnh. Khung lý thuyết đó vẫn là điểm khởi đầu đúng đắn, nhưng chưa phản ánh đầy đủ thực tế huấn luyện mạng nơ-ron sâu giai đoạn 2022–2026. Bài đọc này bổ sung ba phát triển thực nghiệm và thuật toán tiêu biểu: chế độ mép ổn định (edge of stability) của gradient descent toàn tập (full-batch GD), phương pháp momentum theo dấu tìm được qua tìm kiếm chương trình (&lt;strong&gt;Lion&lt;/strong&gt;), và phương pháp trung bình không lịch bước (schedule-free averaging) không cần biết trước tổng số bước \(T\). Các thuật toán thích ứng như AdamW được trình bày ở &lt;a href=&quot;/contents/vi/chapter26/&quot;&gt;Chương 26&lt;/a&gt; và chỉ được nhắc tới ở đây khi đóng vai trò mốc so sánh trong các bài báo.&lt;/p&gt;

&lt;h2 id=&quot;mép-ổn-định-khi-cận-bước-cổ-điển-không-còn-mô-tả-đủ-thực-tế&quot;&gt;Mép ổn định: khi cận bước cổ điển không còn mô tả đủ thực tế&lt;/h2&gt;

&lt;p&gt;Nếu \(\nabla f\) liên tục Lipschitz toàn cục với hằng số \(L\), bổ đề giảm khẳng định rằng kích thước bước &lt;em&gt;cố định&lt;/em&gt; \(t &amp;lt; 2/L\) đảm bảo hàm mục tiêu \(f\) giảm đơn điệu. Tuy nhiên, Cohen, Kaur, Li, Kolter và Talwalkar (&lt;em&gt;Gradient Descent on Neural Networks Typically Occurs at the Edge of Stability&lt;/em&gt;, &lt;a href=&quot;https://openreview.net/forum?id=jh-rTtvkGeM&quot;&gt;ICLR 2021&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2103.00065&quot;&gt;arXiv:2103.00065&lt;/a&gt;) đã đo đạc full-batch GD trên các mạng nơ-ron hiện đại và ghi nhận một hành vi khác: trị riêng lớn nhất của Hessian \(\lambda_{\max}\) tăng dần cho đến khi dao động ngay trên ngưỡng \(2/t\); giá trị mất mát huấn luyện dao động ngắn hạn nhưng vẫn có xu hướng giảm về dài hạn. Hiện tượng này không phù hợp với giả định một hằng số \(L\) cố định trên toàn miền.&lt;/p&gt;

&lt;p&gt;Arora, Li và Panigrahi (&lt;em&gt;Understanding Gradient Descent on the Edge of Stability in Deep Learning&lt;/em&gt;, &lt;a href=&quot;https://proceedings.mlr.press/v162/arora22a.html&quot;&gt;ICML 2022&lt;/a&gt;) đề xuất cơ chế giải thích: sau khi bước vào pha mép ổn định, quỹ đạo lặp bám theo một dòng tất định dọc theo đa tạp (gần) cực tiểu của hàm mất mát, đồng thời làm &lt;em&gt;giảm&lt;/em&gt; độ sắc (sharpness) \(\lambda_{\max}(\nabla^2 L)\). Họ chứng minh hiện tượng này cho gradient descent chuẩn hóa và cho gradient descent trên hàm \(\sqrt{L - L^\star}\) dưới các giả thiết chính quy.&lt;/p&gt;

&lt;p&gt;Trong phạm vi chương này, cả hai góc nhìn đều cần được phân biệt rõ. Bổ đề giảm không sai; điều không còn đúng trên mạng sâu là giả thiết “\(L\) không đổi dọc theo quỹ đạo”. Khi làm các bài tập giả định cận trên bậc hai (06-03-01), ta đang xét chế độ trước mép ổn định. Khi các công trình học sâu mô tả quá trình huấn luyện đang ở “mép ổn định”, điều đó có nghĩa là \(\lambda_{\max} \approx 2/t\) và hàm mất mát không còn giảm đơn điệu qua từng bước.&lt;/p&gt;

&lt;h2 id=&quot;lion-momentum-theo-dấu&quot;&gt;Lion: momentum theo dấu&lt;/h2&gt;

&lt;p&gt;Chen, Liang, Huang, Real, Wang, Pham, Dong, Luong, Hsieh, Lu, Le và cộng sự (&lt;em&gt;Symbolic Discovery of Optimization Algorithms&lt;/em&gt;, &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2023/hash/9a39b4925e35cf447ccba8757137d84f-Abstract-Conference.html&quot;&gt;NeurIPS 2023&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2302.06675&quot;&gt;arXiv:2302.06675&lt;/a&gt;; mã nguồn tại &lt;a href=&quot;https://github.com/google/automl/tree/master/lion&quot;&gt;google/automl/lion&lt;/a&gt;) đã thực hiện tìm kiếm trong không gian các chương trình tối ưu và phát hiện thuật toán &lt;strong&gt;Lion&lt;/strong&gt; (EvoLved Sign Momentum). Thuật toán chỉ lưu một bộ đệm momentum \(m\) và cập nhật tham số theo &lt;em&gt;dấu&lt;/em&gt; của tổ hợp tuyến tính giữa \(m\) và gradient hiện tại:&lt;/p&gt;

\[\begin{align}
u_t &amp;amp;= \beta_1 m_{t-1} + (1-\beta_1) g_t,\\
\theta_t &amp;amp;= \theta_{t-1} - \eta\,\mathrm{sign}(u_t),\\
m_t &amp;amp;= \beta_2 m_{t-1} + (1-\beta_2) g_t.
\end{align}\]

&lt;p&gt;Do không sử dụng ước lượng mô-men bậc hai, mức tiêu thụ bộ nhớ của Lion gần với SGD có momentum hơn là Adam. Nhóm tác giả báo cáo cải thiện trên ImageNet với ViT, tiết kiệm chi phí tính toán trên tập JFT và mô hình khuếch tán, cùng kết quả cạnh tranh trên mô hình ngôn ngữ (đồng thời cũng ghi nhận các thiết lập mà mức cải thiện nhỏ). Về mặt thực hành, tốc độ học \(\eta\) của Lion thường được chọn &lt;em&gt;nhỏ hơn&lt;/em&gt; so với AdamW, vì \(\|\mathrm{sign}(u)\|_{\infty}=1\) khiến biên độ cập nhật trên mọi tọa độ đều bằng nhau.&lt;/p&gt;

&lt;p&gt;Chương 06 giới thiệu phương pháp momentum ở mục 06-06. Lion là biến thể lấy dấu theo từng tọa độ của ý tưởng đó — một phương pháp phi Euclid có thể xem như hạ dốc nhất chuẩn hóa trong hình học \(\ell_\infty\). Lưu ý rằng Lion không thay thế các chứng minh hội tụ ở mục 06-03, vốn được xây dựng cho bước cập nhật Euclid trơn.&lt;/p&gt;

&lt;h2 id=&quot;sgd-và-adamw-không-cần-lịch-giảm-bước&quot;&gt;SGD và AdamW không cần lịch giảm bước&lt;/h2&gt;

&lt;p&gt;Lý thuyết tối ưu cổ điển thường yêu cầu lịch giảm tốc độ học phụ thuộc vào tổng số bước \(T\) (ngân sách lặp định trước), và trong thực tế lịch cosine cũng cần biết trước \(T\). Defazio, Yang, Khaled, Mishchenko, Mehta và Cutkosky (&lt;em&gt;The Road Less Scheduled&lt;/em&gt;, &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2024/hash/136b9a13861308c8948cd308ccd02658-Abstract-Conference.html&quot;&gt;NeurIPS 2024&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2405.15682&quot;&gt;arXiv:2405.15682&lt;/a&gt;; mã nguồn tại &lt;a href=&quot;https://github.com/facebookresearch/schedule_free&quot;&gt;facebookresearch/schedule_free&lt;/a&gt;) đề xuất nội suy giữa dãy tham số đã lấy trung bình và dãy lặp gốc kiểu momentum để loại bỏ hoàn toàn lịch giảm tốc độ học. &lt;strong&gt;Schedule-Free AdamW&lt;/strong&gt; là thuật toán cốt lõi trong giải pháp giành vị trí dẫn đầu của nhóm ở hạng mục tự điều chỉnh (self-tuning) tại cuộc thi 2024 MLCommons AlgoPerf. Về mặt thực nghiệm, phương pháp này bám sát đường biên Pareto giữa mất mát và thời gian huấn luyện mà thông thường chỉ đạt được khi phải chạy nhiều lịch cosine với các độ dài \(T\) khác nhau.&lt;/p&gt;

&lt;p&gt;Điểm kết nối với chương này nằm ở cơ chế trung bình Polyak–Ruppert và momentum, chứ không phải một bổ đề giảm mới. Nếu đã hiểu vì sao lấy trung bình có thể thay thế việc giảm kích thước bước (cùng trực giác với SGD có nhiễu ở mục 06-05), ta có thể xem phép nội suy của bài báo là một lược đồ trung bình thực dụng đạt hiệu năng ngang bằng các lịch giảm tốc độ học đã tinh chỉnh.&lt;/p&gt;

&lt;h2 id=&quot;định-hướng-áp-dụng-học-phần-và-thực-hành&quot;&gt;Định hướng Áp dụng: Học phần và Thực hành&lt;/h2&gt;

&lt;p&gt;Đối với bài tập và kỳ thi trong môn học, hãy áp dụng các kết quả tốc độ hội tụ theo hằng số Lipschitz và tính lồi mạnh ở mục 06-03. Khi theo dõi quá trình huấn luyện mạng sâu, bên cạnh đường cong mất mát, nếu chi phí tính toán cho phép, hãy ước lượng \(\lambda_{\max}\) bằng phương pháp lặp lũy thừa (power iteration) và lưu ý khả năng xuất hiện dao động mép ổn định dưới full-batch GD. Với các bài toán huấn luyện ngẫu nhiên quy mô lớn, nên bắt đầu từ AdamW hoặc Schedule-Free AdamW (Chương 26), và xem Lion như một lựa chọn momentum thay thế đáng cân nhắc.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;J. M. Cohen, S. Kaur, Y. Li, J. Z. Kolter và A. Talwalkar, “Gradient Descent on Neural Networks Typically Occurs at the Edge of Stability,” ICLR 2021. &lt;a href=&quot;https://openreview.net/forum?id=jh-rTtvkGeM&quot;&gt;OpenReview&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2103.00065&quot;&gt;arXiv:2103.00065&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;S. Arora, Z. Li và A. Panigrahi, “Understanding Gradient Descent on the Edge of Stability in Deep Learning,” ICML 2022. &lt;a href=&quot;https://proceedings.mlr.press/v162/arora22a.html&quot;&gt;PMLR&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;X. Chen và cộng sự, “Symbolic Discovery of Optimization Algorithms,” NeurIPS 2023. &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2023/hash/9a39b4925e35cf447ccba8757137d84f-Abstract-Conference.html&quot;&gt;tóm tắt&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2302.06675&quot;&gt;arXiv:2302.06675&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;A. Defazio, X. Yang, A. Khaled, K. Mishchenko, H. Mehta và A. Cutkosky, “The Road Less Scheduled,” NeurIPS 2024. &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2024/hash/136b9a13861308c8948cd308ccd02658-Abstract-Conference.html&quot;&gt;tóm tắt&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2405.15682&quot;&gt;arXiv:2405.15682&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>05-08 Ứng dụng và phát triển gần đây</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_08_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_08_Applications_Recent</id>
   <content type="html">&lt;p&gt;Nếu có ai đó hỏi: &lt;em&gt;“Các bài toán chuẩn LP, QP, SOCP, SDP từ thế kỷ trước ngày nay còn vai trò gì trong kỷ nguyên AI tạo sinh và tài chính định lượng tốc độ cao không?”&lt;/em&gt; — bài học này sẽ mang đến câu trả lời sắc nét nhất. Không những không lỗi thời, hệ phân loại bài toán nón của Chương 05 đang âm thầm vận hành những hệ thống công nghệ tối tân nhất hiện nay!&lt;/p&gt;

&lt;p&gt;Từ &lt;strong&gt;Clarabel&lt;/strong&gt; — bộ giải điểm trong viết bằng Rust thế hệ mới trở thành động cơ mặc định của CVXPY, đến tối ưu danh mục đầu tư thực tế có tính chi phí giao dịch, cho tới việc dùng &lt;strong&gt;nới lỏng SDP để cấp chứng chỉ an toàn toán học cho mạng nơ-ron sâu&lt;/strong&gt; chống lại tấn công đối kháng — tất cả đều xây thẳng lên khung xương Chương 05.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mũi-nhọn-ứng-dụng-hiện-đại-của-bài-toán-chuẩn&quot;&gt;Kiến thức cần nhớ: Bốn mũi nhọn ứng dụng hiện đại của bài toán chuẩn&lt;/h2&gt;

&lt;p&gt;Để đọc các nghiên cứu thực tế trong bài một cách có hệ thống, hãy kết nối chúng về đúng bốn trụ cột của Chương 05:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bộ giải điểm trong thế hệ mới (Clarabel &amp;amp; Homogeneous Self-Dual Embedding):&lt;/strong&gt; Thay vì chỉ giải riêng lẻ LP hay QP, Clarabel giải đồng thời cả &lt;strong&gt;hàm mục tiêu bậc hai&lt;/strong&gt; trên &lt;strong&gt;tích của nhiều nón&lt;/strong&gt; (không âm, bậc hai, nửa xác định, mũ, lũy thừa) và tự động phát hiện bài toán vô nghiệm hay không bị chặn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu danh mục đầu tư thực tế (QP + Chi phí giao dịch &amp;amp; Ràng buộc đòn bẩy):&lt;/strong&gt; Mô hình Markowitz hiện đại mở rộng QP cổ điển bằng thành phần không trơn \(\ell_1\) (phí giao dịch tuyến tính \(\kappa \|w - w_0\|_1\)) và ràng buộc SOCP (phí tác động thị trường \(\|w - w_0\|_2^{3/2}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng mạng nơ-ron bằng SDP (Semidefinite Verification):&lt;/strong&gt; Phép kích hoạt ReLU \(y = \max(0, z)\) thỏa ba ràng buộc: \(y \ge 0,\; y \ge z\) và &lt;strong&gt;đẳng thức bậc hai&lt;/strong&gt; \(y(y - z) = 0\)! Gom chúng thành ma trận gram nửa xác định dương tạo ra nới lỏng SDP giúp chứng minh toán học rằng nhiễu đầu vào nhỏ không bao giờ làm mạng nhận diện nhầm biển báo giao thông!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khôi phục thưa &amp;amp; Nén cảm biến (Sparse Recovery via QP/Lasso):&lt;/strong&gt; Từ chụp cộng hưởng từ MRI nhanh hơn gấp nhiều lần đến ước lượng tín hiệu radar, bài toán khôi phục vector thưa vẫn dựa trên nền tảng QP chuẩn của Lasso (\(\frac{1}{2}\|Ax - b\|_2^2 + \lambda \|x\|_1\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-lập-ràng-buộc-sdp-cho-một-nơ-ron-relu&quot;&gt;Giải thích: Tự tay lập ràng buộc SDP cho một nơ-ron ReLU&lt;/h3&gt;

&lt;p&gt;Xét một nơ-ron ReLU duy nhất \(y = \max(0, z)\) với đầu vào bị chặn trong đoạn nhiễu \(z \in [-1, 2]\). Ta muốn chứng minh mối liên hệ đại số giữa \(z\) và \(y\) để đưa vào nới lỏng SDP:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Ba điều kiện đại số chính xác của ReLU:&lt;/strong&gt;
Với mọi \(z \in \mathbb{R}\), \(y = \max(0, z) \iff y \ge 0,\; y \ge z,\; y(y - z) = 0\).
Kiểm tra: nếu \(z = 2 \implies y = 2\) thỏa \(2(2-2)=0\); nếu \(z = -1 \implies y = 0\) thỏa \(0(0-(-1))=0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Biểu diễn qua ma trận đối xứng \(P = \begin{pmatrix} 1 \\ z \\ y \end{pmatrix} \begin{pmatrix} 1 &amp;amp; z &amp;amp; y \end{pmatrix} = \begin{pmatrix} 1 &amp;amp; z &amp;amp; y \\ z &amp;amp; Z &amp;amp; W \\ y &amp;amp; W &amp;amp; Y \end{pmatrix} \succeq 0\):&lt;/strong&gt;
Trong đó \(Z = z^2,\; W = zy,\; Y = y^2\).
    &lt;ul&gt;
      &lt;li&gt;Đẳng thức phi lồi \(y(y - z) = 0\) trở thành &lt;strong&gt;đẳng thức tuyến tính&lt;/strong&gt; trên ma trận: \(Y - W = 0\)!&lt;/li&gt;
      &lt;li&gt;Điều kiện \(z \in [-1, 2]\) tương đương \((z + 1)(z - 2) \le 0 \iff Z - z - 2 \le 0\) — cũng là &lt;strong&gt;bất đẳng thức tuyến tính&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Bỏ ràng buộc \(\operatorname{rank}(P) = 1\):&lt;/strong&gt;
Ta thu được một bài &lt;strong&gt;SDP lồi hoàn toàn&lt;/strong&gt; chặn cực chặt mọi đầu ra có thể của nơ-ron ReLU trên miền nhiễu \([-1, 2]\)! Đây chính là viên gạch cốt lõi của phương pháp kiểm chứng mạng nơ-ron SDP (Fazlyab et al., 2020).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Chương 05 phân loại các bài toán tối ưu hóa lồi theo cấu trúc hàm mục tiêu và các loại nón trong ràng buộc: LP, QP, QCQP, SOCP, SDP và quy hoạch hình học. Hệ phân loại này cũng chính là giao diện nền tảng của các ngôn ngữ mô hình hóa tối ưu hiện đại. Bài học này điểm qua ba ứng dụng thực tiễn tiêu biểu trong giai đoạn 2022–2026 — bộ giải điểm trong thế hệ mới tích hợp sẵn trong CVXPY, bài toán QP tối ưu hóa danh mục đầu tư có thể kiểm thử trên dữ liệu lịch sử, và kỹ thuật nới lỏng SDP để kiểm chứng độ bền vững của mạng nơ-ron — kèm theo nhận xét về vai trò của dạng QP chuẩn trong bài toán Lasso và khôi phục thưa.&lt;/p&gt;

&lt;p&gt;Phần thực hành DCP/CVXPY đã được trình bày ở bài &lt;a href=&quot;/contents/vi/chapter05/05_07_Modeling_with_DCP_CVXPY/&quot;&gt;05-07&lt;/a&gt;; bài này bổ sung góc nhìn về lý do các lớp nón chuẩn đó quan trọng trong thực tế.&lt;/p&gt;

&lt;h2 id=&quot;clarabel-bộ-giải-điểm-trong-hiện-đại-cho-các-bài-toán-nón&quot;&gt;Clarabel: Bộ giải điểm trong hiện đại cho các bài toán nón&lt;/h2&gt;

&lt;p&gt;Goulart và Chen (&lt;em&gt;Clarabel: An interior-point solver for conic programs with quadratic objectives&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv:2405.12762&lt;/a&gt;, 2024; tài liệu &lt;a href=&quot;https://clarabel.org/&quot;&gt;clarabel.org&lt;/a&gt;; &lt;a href=&quot;https://oxfordcontrol.github.io/ClarabelDocs/stable/citing/&quot;&gt;trang trích dẫn&lt;/a&gt;) xây dựng phương pháp điểm trong nhúng thuần nhất cho các bài toán quy hoạch nón có hàm mục tiêu bậc hai. Bộ giải hỗ trợ trực tiếp các loại nón đã học trong chương này — nón không âm, nón bậc hai, nón nửa xác định (có hỗ trợ phân rã chordal) và một số nón không đối xứng — đồng thời được tích hợp làm bộ giải mặc định trong CVXPY. Kết quả thực nghiệm cho thấy Clarabel đạt hiệu năng cao trên các bài toán QP so với nhiều bộ giải mã nguồn mở và thương mại.&lt;/p&gt;

&lt;p&gt;Điểm đáng chú ý về mặt thực hành là: khi mô hình đã được chuẩn hóa theo DCP, ta không cần tự cài đặt thuật toán giải Lasso bằng tay mà chỉ cần chuyển bài toán quy hoạch nón chuẩn cho một bộ giải điểm trong (IPM). Việc chuyển đổi giữa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=cp.CLARABEL&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.OSQP&lt;/code&gt; hay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.SCS&lt;/code&gt; thực chất là so sánh hiệu quả của các thuật toán trên cùng một dạng chuẩn. OSQP (Stellato, Banjac, O’Donoghue, Bemporad và Boyd, &lt;em&gt;Math. Prog. Comp.&lt;/em&gt; 2020) vẫn là lựa chọn bậc nhất quen thuộc cho nhiều bài toán QP điều khiển và tài chính, còn Clarabel là bộ giải điểm trong hiện đại tiêu biểu của năm 2024.&lt;/p&gt;

&lt;h2 id=&quot;tối-ưu-hóa-danh-mục-đầu-tư-dưới-dạng-qp-thực-tế&quot;&gt;Tối ưu hóa danh mục đầu tư dưới dạng QP thực tế&lt;/h2&gt;

&lt;p&gt;Bài toán phân bổ danh mục trung bình–phương sai của Markowitz là một bài toán QP:&lt;/p&gt;

\[\begin{align}
\min_x \quad &amp;amp; x^\top \Sigma x - \gamma \hat{r}^\top x \\
\text{s.t.} \quad &amp;amp; \mathbf{1}^\top x = 1, \quad x\in\mathcal{X},
\end{align}\]

&lt;p&gt;trong đó \(\mathcal{X}\) là tập đa diện biểu diễn các ràng buộc như không bán khống (long-only), giới hạn đòn bẩy hoặc giới hạn vòng quay danh mục. Boyd, Busseti, Diamond, Kahn, Koh, Nystrup và Speth (&lt;em&gt;Multi-Period Trading via Convex Optimization&lt;/em&gt;, &lt;a href=&quot;https://stanford.edu/~boyd/papers/cvx_portfolio.html&quot;&gt;&lt;em&gt;Found. Trends Optim.&lt;/em&gt; 2017&lt;/a&gt;) mở rộng mô hình QP này cho cả bài toán một kỳ và nhiều kỳ có tính đến chi phí giao dịch và chi phí nắm giữ. Thư viện đi kèm &lt;a href=&quot;https://www.cvxportfolio.com/&quot;&gt;cvxportfolio&lt;/a&gt; (tiếp tục được bảo trì đến giữa thập niên 2020, phiên bản v1.5) cho phép kiểm thử trực tiếp các chiến lược &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SinglePeriodOptimization&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MultiPeriodOptimization&lt;/code&gt; trên dữ liệu thị trường thực tế thông qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;StockMarketSimulator&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Dù chuyên khảo gốc công bố năm 2017, mô hình QP chuẩn vẫn giữ nguyên giá trị nền tảng, trong khi hệ sinh thái bộ giải (OSQP, Clarabel) và phần mềm mô phỏng liên tục được cập nhật. Với hướng mở rộng bền vững theo phân phối (DRO) dùng khoảng cách Wasserstein gần đây hơn (Gao và Kleywegt, &lt;a href=&quot;https://doi.org/10.1287/moor.2022.1275&quot;&gt;&lt;em&gt;Math. Oper. Res.&lt;/em&gt; 2023&lt;/a&gt;; xem Chương 02), bài toán sau khi lấy đối ngẫu cũng quy về dạng QP hoặc SOCP.&lt;/p&gt;

&lt;h2 id=&quot;nới-lỏng-sdp-trong-kiểm-chứng-mạng-nơ-ron&quot;&gt;Nới lỏng SDP trong kiểm chứng mạng nơ-ron&lt;/h2&gt;

&lt;p&gt;Bài toán kiểm tra độ bền vững cục bộ của mạng nơ-ron ReLU — xác minh rằng không có nhiễu đầu vào trong bán kính \(\varepsilon\) nào làm thay đổi nhãn dự đoán — vốn là một bài toán khả thi không lồi. Bằng cách thay tích của các đầu ra kích hoạt bằng một ma trận mô-men nửa xác định dương, ta thu được một bài toán &lt;em&gt;nới lỏng&lt;/em&gt; SDP (kết hợp ý tưởng nới lỏng ở bài 04-08 với nón SDP của bài 05-05). Lan, Zheng và Lomuscio (&lt;em&gt;Tight Neural Network Verification via Semidefinite Relaxations and Linear Reformulations&lt;/em&gt;, &lt;a href=&quot;https://doi.org/10.1609/aaai.v36i7.20689&quot;&gt;AAAI 2022&lt;/a&gt;) kết hợp nới lỏng SDP theo từng lớp với các lát cắt tuyến tính hóa (RLT), giúp tăng mạnh tỉ lệ chứng nhận bền vững trên mạng MNIST (chẳng hạn tăng từ 0% lên 82% trên mạng khoảng 10 nghìn nút trong thực nghiệm của họ). Trước đó, hướng nới lỏng SDP theo lớp kết hợp lát cắt tam giác cũng đã được Batten, Kouvaros, Lomuscio và Zheng giới thiệu tại &lt;a href=&quot;https://doi.org/10.24963/ijcai.2021/301&quot;&gt;IJCAI 2021&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Mặc dù khó áp dụng SDP trực tiếp cho các mạng cỡ ImageNet, khuôn mẫu mô hình hóa ở đây rất rõ ràng: các ràng buộc tổ hợp hoặc song tuyến được thay bằng điều kiện \(X\succeq 0\) kèm các đẳng thức tuyến tính, sau đó bộ giải SDP của Chương 05 sẽ giúp chứng nhận tính chất hoặc đưa ra chặn chặt.&lt;/p&gt;

&lt;h2 id=&quot;khôi-phục-thưa-vẫn-dựa-trên-nền-tảng-qp-chuẩn&quot;&gt;Khôi phục thưa vẫn dựa trên nền tảng QP chuẩn&lt;/h2&gt;

&lt;p&gt;Bài toán Lasso:&lt;/p&gt;

\[\min_x \tfrac12\|Ax-b\|_2^2 + \lambda \|x\|_1\]

&lt;p&gt;là công cụ quen thuộc cho bài toán khôi phục thưa trong xử lý ảnh y khoa và thống kê chiều cao, đồng thời dễ dàng biểu diễn trong CVXPY bằng vài hàm nguyên tử (xem bài 05-07). Nhiều nghiên cứu sau năm 2021 phát triển hướng &lt;em&gt;khai triển thuật toán&lt;/em&gt; (algorithm unrolling), chuyển các bước lặp hạ gradient cận kề (như ISTA) của bài toán QP này thành các lớp mạng nơ-ron có thể học bước nhảy và từ điển từ dữ liệu (Monga, Li và Eldar, “Algorithm Unrolling,” &lt;a href=&quot;https://doi.org/10.1109/MSP.2020.3016905&quot;&gt;&lt;em&gt;IEEE Signal Processing Magazine&lt;/em&gt;, 2021&lt;/a&gt;). Tuy vậy, cấu trúc toán học cốt lõi vẫn là cùng một bài toán QP; nắm vững cách viết Lasso về dạng QP với biến phụ giúp người học tiếp cận các mô hình ISTA khai triển một cách trực tiếp.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;P. J. Goulart và Y. Chen, “Clarabel: An interior-point solver for conic programs with quadratic objectives,” arXiv:2405.12762, 2024. &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv&lt;/a&gt; · &lt;a href=&quot;https://clarabel.org/&quot;&gt;clarabel.org&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;S. Boyd, E. Busseti, S. Diamond và cộng sự, “Multi-Period Trading via Convex Optimization,” &lt;em&gt;Found. Trends Optim.&lt;/em&gt;, 2017. &lt;a href=&quot;https://stanford.edu/~boyd/papers/cvx_portfolio.html&quot;&gt;trang&lt;/a&gt; · &lt;a href=&quot;https://www.cvxportfolio.com/&quot;&gt;cvxportfolio&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;J. Lan, Y. Zheng và A. Lomuscio, “Tight Neural Network Verification via Semidefinite Relaxations and Linear Reformulations,” AAAI 2022. &lt;a href=&quot;https://doi.org/10.1609/aaai.v36i7.20689&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;B. Batten, P. Kouvaros, A. Lomuscio và Y. Zheng, “Efficient Neural Network Verification via Layer-based Semidefinite Relaxations and Linear Cuts,” IJCAI 2021. &lt;a href=&quot;https://doi.org/10.24963/ijcai.2021/301&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;V. Monga, Y. Li và Y. C. Eldar, “Algorithm Unrolling: Interpretable, Efficient Deep Learning for Signal and Image Processing,” &lt;em&gt;IEEE SPM&lt;/em&gt; 38(2):18–44, 2021. &lt;a href=&quot;https://doi.org/10.1109/MSP.2020.3016905&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>04-09 Ứng dụng và phát triển gần đây</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_09_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_09_Applications_Recent</id>
   <content type="html">&lt;p&gt;Trong suốt hàng thập kỷ, tối ưu hóa lồi và học sâu (Deep Learning) sống như hai thế giới tách biệt: mạng nơ-ron chạy lan truyền ngược (backpropagation) trên các phép tính tường minh, còn bài toán tối ưu lồi nằm ở cuối đường ống như một “hộp đen” tách rời để ra quyết định. Nhưng từ năm 2019 trở lại đây, một cuộc cách mạng thầm lặng đã phá vỡ bức tường đó: các nhà nghiên cứu phát hiện ra ta có thể &lt;strong&gt;đạo hàm xuyên qua chính nghiệm tối ưu \(x^\star(\theta)\)&lt;/strong&gt; bằng định lý hàm ẩn áp dụng lên điều kiện tối ưu KKT!&lt;/p&gt;

&lt;p&gt;Điều đó có nghĩa là gì? Toàn bộ một bài toán tối ưu hóa lồi của Chương 04 giờ đây có thể trở thành &lt;strong&gt;một lớp (layer) khả vi ngay bên trong PyTorch hoặc JAX&lt;/strong&gt; — vừa học tham số từ dữ liệu, vừa đảm bảo đầu ra tuân thủ tuyệt đối các ràng buộc vật lý, an toàn hay tài chính. Bài học này kết nối những khái niệm nền tảng bạn vừa học với các công trình hiện đại như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Theseus&lt;/code&gt; và tối ưu hóa khấu hao (amortized optimization).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-khi-tối-ưu-hóa-lồi-bước-vào-kiến-trúc-mạng-nơ-ron&quot;&gt;Kiến thức cần nhớ: Khi tối ưu hóa lồi bước vào kiến trúc mạng nơ-ron&lt;/h2&gt;

&lt;p&gt;Để đọc hiểu các ứng dụng hiện đại trong bài mà không thấy “phép màu”, hãy kết nối chúng với ba trụ cột của Chương 04:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vi phân ẩn qua điều kiện tối ưu (Implicit Differentiation of KKT):&lt;/strong&gt; Thay vì lưu vết hàng trăm bước lặp của bộ giải bên trong bộ nhớ GPU, ta chỉ cần giải bài toán lồi ở bước xuôi để lấy \(x^\star(\theta)\), rồi lấy vi phân trực tiếp hệ điều kiện tối ưu \(F(x^\star, \theta) = 0\) để tính \(\frac{\partial x^\star}{\partial \theta} = -(\nabla_x F)^{-1} \nabla_\theta F\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lớp tối ưu phi tuyến &amp;amp; Robot học (Differentiable Nonlinear Least Squares):&lt;/strong&gt; Trong bài toán định vị SLAM hay điều khiển cánh tay robot (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Theseus&lt;/code&gt;), các ràng buộc động học tạo thành bài toán bình phương tối thiểu phi tuyến giải lặp kiểu Gauss-Newton, và đạo hàm được truyền ngược qua chính nghiệm tối ưu đó.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa khấu hao &amp;amp; Học theo quyết định (Decision-Focused Learning):&lt;/strong&gt; Khi phải giải hàng triệu bài toán tối ưu có cấu trúc giống nhau chỉ khác tham số đầu vào \(\theta\), ta huấn luyện mạng dự đoán trực tiếp nghiệm hoặc điểm khởi tạo (khấu hao chi phí tính toán), hoặc huấn luyện mô hình dự báo sao cho &lt;em&gt;quyết định tối ưu cuối cùng&lt;/em&gt; đạt lợi ích cao nhất thay vì chỉ tối thiểu hóa sai số dự báo MSE.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-lấy-vi-phân-ẩn-xuyên-qua-một-lớp-tối-ưu-hóa-lồi&quot;&gt;Giải thích: Tự tay lấy vi phân ẩn xuyên qua một lớp tối ưu hóa lồi!&lt;/h3&gt;

&lt;p&gt;Giả sử một mạng nơ-ron xuất ra tham số \(\theta \in \mathbb{R}\) và đưa vào lớp tối ưu hóa lồi (chiếu lên đoạn \([0, 1]\)):
\(x^\star(\theta) = \arg\min_{x \in \mathbb{R}} \; \frac{1}{2}(x - \theta)^2 \quad \text{thỏa mãn} \quad 0 \le x \le 1.\)
Ta muốn tính đạo hàm \(\frac{dx^\star}{d\theta}\) để lan truyền ngược (backprop) khi huấn luyện mạng!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 1 — Nghiệm nằm ở phần trong (\(0 &amp;lt; \theta &amp;lt; 1\)), ví dụ \(\theta = 0.4\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ràng buộc không tích cực, điều kiện tối ưu bậc nhất là \(F(x^\star, \theta) = x^\star - \theta = 0 \implies x^\star = 0.4\).&lt;/li&gt;
      &lt;li&gt;Lấy vi phân ẩn hai vế theo \(\theta\): \(\frac{dx^\star}{d\theta} - 1 = 0 \implies \frac{dx^\star}{d\theta} = 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 2 — Ràng buộc biên tích cực (\(\theta &amp;gt; 1\) hoặc \(\theta &amp;lt; 0\)), ví dụ \(\theta = 1.8\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nghiệm bị chặn cứng tại biên \(x^\star = 1\) (ràng buộc \(x - 1 \le 0\) tích cực).&lt;/li&gt;
      &lt;li&gt;Thay đổi nhẹ \(\theta\) quanh \(1.8\) không làm dịch chuyển \(x^\star\), nên \(\frac{dx^\star}{d\theta} = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhận xét thú vị:&lt;/strong&gt; Hàm nghiệm \(x^\star(\theta) = \operatorname{clip}(\theta, 0, 1)\) hóa ra chính là hàm kích hoạt bị chặn (giống ReLU cắt trên)! Với các bài toán QP/SOCP nhiều biến hơn trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt;, cơ chế hoàn toàn tương tự: vi phân hệ KKT tại \(x^\star(\theta)\) trả về chính xác ma trận Jacobian \(\frac{\partial x^\star}{\partial \theta}\) chỉ bằng một phép giải hệ tuyến tính duy nhất.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Chương 04 xây dựng nền tảng cho bài toán tối ưu hóa lồi: biến quyết định, hàm mục tiêu, ràng buộc, điều kiện tối ưu và các phép biến đổi hợp lệ (tối ưu hóa từng phần, đổi biến, loại bỏ ràng buộc đẳng thức, biến phụ và nới lỏng). Trong những năm gần đây, chính cấu trúc này được tích hợp trực tiếp như một &lt;em&gt;lớp&lt;/em&gt; (layer) trong mạng nơ-ron và làm cơ sở thiết kế &lt;em&gt;hàm mất mát&lt;/em&gt; cho các mô hình dự đoán phục vụ bài toán ra quyết định. Bài học này điểm qua ba hướng phát triển tiêu biểu giai đoạn 2019–2023 dựa trực tiếp trên điều kiện tối ưu dạng “\(0\in\partial f(x^\star)+N_{\mathcal{C}}(x^\star)\)”.&lt;/p&gt;

&lt;h2 id=&quot;lớp-tối-ưu-hóa-lồi-khả-vi-và-vi-phân-ẩn&quot;&gt;Lớp tối ưu hóa lồi khả vi và vi phân ẩn&lt;/h2&gt;

&lt;p&gt;Agrawal, Amos, Barratt, Boyd, Diamond và Kolter (&lt;em&gt;Differentiable Convex Optimization Layers&lt;/em&gt;, &lt;a href=&quot;https://web.stanford.edu/~boyd/papers/diff_cvxpy.html&quot;&gt;NeurIPS 2019&lt;/a&gt;; thư viện &lt;a href=&quot;https://cvxpylayers.org/&quot;&gt;cvxpylayers&lt;/a&gt;) đưa một bài toán quy hoạch lồi có cấu trúc (disciplined convex program) vào đồ thị tính toán của PyTorch hoặc TensorFlow như một lớp khả vi. Ở lượt lan truyền thuận, lớp này &lt;em&gt;giải&lt;/em&gt; bài toán tối ưu; ở lượt lan truyền ngược, gradient của nghiệm theo tham số được tính bằng vi phân ẩn thông qua phần dư của bộ giải (dựa trên biểu diễn affine–bộ giải–affine gọi là DPP). Dù công bố từ năm 2019, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt; vẫn là thư viện tiêu chuẩn trong giai đoạn 2022–2026 mỗi khi một nghiên cứu cần nhúng trực tiếp bài toán quy hoạch bậc hai (QP) hay bài toán lồi vào mạng nơ-ron.&lt;/p&gt;

&lt;p&gt;Cách tiếp cận này gắn trực tiếp với điều kiện tối ưu của Chương 04. Nếu \(x^\star(\theta)\) là nghiệm của một bài toán lồi phụ thuộc tham số \(\theta\), thì hệ điều kiện KKT \(F(x,\lambda;\theta)=0\) đóng vai trò là phương trình ẩn xác định nghiệm. Thay vì khai triển (unroll) toàn bộ các bước lặp của thuật toán hạ gradient chiếu, ta chỉ cần tuyến tính hóa hệ \(F\) — cách làm sau này được Blondel và cộng sự hệ thống hóa và tự động hóa trong thư viện JAXopt (&lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/228b9279ecf9bbafe582406850c57115-Abstract-Conference.html&quot;&gt;NeurIPS 2022&lt;/a&gt;). Điều kiện tối ưu bậc nhất trong Chương 04 chính là &lt;em&gt;đặc tả&lt;/em&gt; trực tiếp của hệ \(F\).&lt;/p&gt;

&lt;h2 id=&quot;theseus-bình-phương-tối-thiểu-phi-tuyến-dưới-dạng-lớp-khả-vi&quot;&gt;Theseus: Bình phương tối thiểu phi tuyến dưới dạng lớp khả vi&lt;/h2&gt;

&lt;p&gt;Không phải mọi bài toán tối ưu bên trong mô hình đều lồi. Trong lĩnh vực robot và thị giác 3D, các hệ thống thường xuyên phải giải bài toán bình phương tối thiểu phi tuyến:&lt;/p&gt;

\[\min_x \tfrac12 \sum_i \bigl\| r_i(x;\theta)\bigr\|_2^2\]

&lt;p&gt;bằng các thuật toán như Gauss–Newton hoặc Levenberg–Marquardt. Pineda, Fan, Monge, Venkataraman, Sodhi, Chen, Ortiz, DeTone, Wang, Anderson, Dong, Amos và Mukadam (&lt;em&gt;Theseus: A Library for Differentiable Nonlinear Optimization&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2207.09442&quot;&gt;NeurIPS 2022&lt;/a&gt;; &lt;a href=&quot;https://github.com/facebookresearch/theseus&quot;&gt;facebookresearch/theseus&lt;/a&gt;) đã xây dựng thư viện PyTorch coi cả quá trình giải bài toán này như một lớp khả vi, hỗ trợ bộ giải thưa, nhóm Lie, xử lý theo lô (batch) trên GPU, đồng thời cho phép tính gradient bằng vi phân ẩn hoặc vi phân qua các bước lặp đã khai triển.&lt;/p&gt;

&lt;p&gt;Điểm kết nối của công trình này với Chương 04 nằm ở tư duy mô hình hóa: xuất phát từ điều kiện dừng của bài toán bình phương tối thiểu rồi lựa chọn &lt;em&gt;phép biến đổi tương đương&lt;/em&gt; phù hợp — giữa vi phân ẩn và khai triển vòng lặp — tương tự tư duy biến đổi và đổi biến ở bài 04-05. Khi bài toán bên trong có tính lồi, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt; là lựa chọn ưu tiên; còn khi gặp bài toán bình phương tối thiểu phi tuyến có cấu trúc, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Theseus&lt;/code&gt; là thư viện tham chiếu phổ biến từ năm 2022.&lt;/p&gt;

&lt;h2 id=&quot;tối-ưu-hóa-khấu-hao-và-hàm-thay-thế-lồi-cho-bài-toán-ra-quyết-định&quot;&gt;Tối ưu hóa khấu hao và hàm thay thế lồi cho bài toán ra quyết định&lt;/h2&gt;

&lt;p&gt;Hai hướng nghiên cứu khác cũng vận dụng trực tiếp các khái niệm của Chương 04.&lt;/p&gt;

&lt;p&gt;Thứ nhất, Amos (&lt;em&gt;Tutorial on Amortized Optimization&lt;/em&gt;, &lt;a href=&quot;https://doi.org/10.1561/2200000102&quot;&gt;&lt;em&gt;Foundations and Trends in Machine Learning&lt;/em&gt; 16:592–732, 2023&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2202.00665&quot;&gt;arXiv:2202.00665&lt;/a&gt;) tổng hợp hướng tiếp cận &lt;em&gt;học để tối ưu&lt;/em&gt; (learning to optimize): huấn luyện một mạng nơ-ron dự đoán trực tiếp \(x\approx x^\star(\theta)\) cho cả một họ bài toán có chung cấu trúc (như suy diễn biến phân, mã hóa thưa, học siêu tham số, vận chuyển tối ưu hay mạng cân bằng sâu). Tối ưu hóa khấu hao không thay thế điều kiện tối ưu mà &lt;em&gt;xấp xỉ ánh xạ nghiệm&lt;/em&gt;; bài toán bên trong vẫn cần được phát biểu chuẩn xác và vẫn được kiểm tra sai số thông qua phần dư của điều kiện tối ưu.&lt;/p&gt;

&lt;p&gt;Thứ hai, Elmachtoub và Grigas (&lt;a href=&quot;https://doi.org/10.1287/mnsc.2020.3922&quot;&gt;&lt;em&gt;Management Science&lt;/em&gt; 2022&lt;/a&gt;) xét bài toán ra quyết định theo quy trình “dự đoán rồi tối ưu”: hàm mất mát quyết định thực tế không liên tục theo vectơ chi phí dự đoán, nên các tác giả &lt;em&gt;nới lỏng&lt;/em&gt; nó thành hàm mất mát thay thế lồi SPO+ xây dựng từ lý thuyết đối ngẫu. Đây là ứng dụng điển hình kết hợp kỹ thuật nới lỏng ở bài 04-08 với điều kiện tối ưu của quy hoạch tuyến tính: tập khả thi đa diện gốc được giữ nguyên, chỉ hàm mục tiêu huấn luyện được thay bằng một hàm lồi theo tham số của mô hình dự đoán.&lt;/p&gt;

&lt;h2 id=&quot;khuôn-mẫu-chung-khi-áp-dụng-vào-bài-tập&quot;&gt;Khuôn mẫu chung khi áp dụng vào bài tập&lt;/h2&gt;

&lt;p&gt;Khi phân tích hoặc thiết kế một bài toán tối ưu hóa khả vi, có thể tổ chức theo ba bước chuẩn: viết bài toán bên trong ở dạng chuẩn, xác định hệ điều kiện tối ưu (phép viết lại), và tính gradient bên ngoài:&lt;/p&gt;

\[\begin{align}
\text{bài toán trong:}&amp;amp;\quad x^\star(\theta)\in\arg\min_{x\in\mathcal{C}(\theta)} f(x;\theta),\\
\text{điều kiện tối ưu:}&amp;amp;\quad F(x^\star,\nu^\star;\theta)=0 \quad\text{(KKT / điểm dừng)},\\
\text{gradient ngoài:}&amp;amp;\quad \nabla_\theta \ell\bigl(x^\star(\theta)\bigr) \quad\text{qua } \nabla_x F,\;\nabla_\theta F.
\end{align}\]

&lt;p&gt;Nếu chưa viết được hệ \(F\), ta chưa thể thực hiện vi phân ẩn qua bộ giải. Nếu viết được \(F\) nhưng tập \(\mathcal{C}\) hoặc hàm mục tiêu không lồi, bài toán chuyển sang phạm vi của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Theseus&lt;/code&gt; hay bình phương tối thiểu phi tuyến, nơi tính tối ưu toàn cục không còn được đảm bảo — đây cũng là lý do Chương 04 tập trung phân tích kỹ tính chất của tập nghiệm lồi.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;A. Agrawal, B. Amos, S. Barratt, S. Boyd, S. Diamond và J. Z. Kolter, “Differentiable Convex Optimization Layers,” NeurIPS 2019. &lt;a href=&quot;https://web.stanford.edu/~boyd/papers/diff_cvxpy.html&quot;&gt;trang&lt;/a&gt; · &lt;a href=&quot;https://cvxpylayers.org/&quot;&gt;cvxpylayers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;M. Blondel và cộng sự, “Efficient and Modular Implicit Differentiation,” NeurIPS 2022. &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/228b9279ecf9bbafe582406850c57115-Abstract-Conference.html&quot;&gt;tóm tắt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;L. Pineda và cộng sự, “Theseus: A Library for Differentiable Nonlinear Optimization,” NeurIPS 2022. &lt;a href=&quot;https://arxiv.org/abs/2207.09442&quot;&gt;arXiv:2207.09442&lt;/a&gt; · &lt;a href=&quot;https://github.com/facebookresearch/theseus&quot;&gt;mã&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;B. Amos, “Tutorial on Amortized Optimization,” &lt;em&gt;Found. Trends Mach. Learn.&lt;/em&gt; 16:592–732, 2023. &lt;a href=&quot;https://doi.org/10.1561/2200000102&quot;&gt;DOI&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2202.00665&quot;&gt;arXiv:2202.00665&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;A. N. Elmachtoub và P. Grigas, “Smart ‘Predict, then Optimize’,” &lt;em&gt;Management Science&lt;/em&gt; 2022. &lt;a href=&quot;https://doi.org/10.1287/mnsc.2020.3922&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>03-08 Ứng dụng và phát triển gần đây</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_08_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_08_Applications_Recent</id>
   <content type="html">&lt;p&gt;Một trong những nghịch lý thú vị nhất của học sâu hiện đại là: toàn bộ mạng nơ-ron sâu với hàng tỷ tham số là một bài toán cực kỳ &lt;strong&gt;không lồi&lt;/strong&gt;, thế nhưng chính &lt;strong&gt;lớp cuối cùng&lt;/strong&gt; — nơi hàm mất mát Cross-Entropy, Log-Sum-Exp và hiệu chỉnh xác suất (calibration) vận hành — lại là một bài toán &lt;strong&gt;tối ưu hóa lồi&lt;/strong&gt; mẫu mực! Thậm chí hiện tượng &lt;strong&gt;Neural Collapse&lt;/strong&gt; phát hiện gần đây cho thấy trong giai đoạn huấn luyện cuối, đặc trưng học được tự hội tụ về một cấu trúc hình học cực kỳ đều đặn (Simplex ETF) khớp sát với lý thuyết hàm lồi Chương 03.&lt;/p&gt;

&lt;p&gt;Bài đọc mở rộng này nối trực tiếp hàm lồi, log-sum-exp và bất đẳng thức Jensen với Cross-Entropy, Neural Collapse và học tương phản (Contrastive Learning) giai đoạn 2022–2026.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-điểm-chạm-của-hàm-lồi-trong-học-sâu-hiện-đại&quot;&gt;Kiến thức cần nhớ: Ba điểm chạm của Hàm lồi trong Học sâu hiện đại&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cross-Entropy và Log-Sum-Exp:&lt;/strong&gt; Hàm mất mát phân loại chuẩn \(L(z, y) = -z_y + \log\sum_k e^{z_k}\) là tổng của hàm tuyến tính \(-z_y\) và hàm lồi \(\operatorname{lse}(z)\), nên luôn lồi theo vector logit \(z\); gradient của nó có dạng siêu gọn \(\nabla_z L = \operatorname{softmax}(z) - e_y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Neural Collapse (NC1–NC4):&lt;/strong&gt; Khi huấn luyện mạng sâu qua điểm sai số bằng 0 trên tập huấn luyện, các vector đặc trưng của từng lớp sụp về đúng tâm lớp và các tâm lớp xếp thành các đỉnh đối xứng cực đại (Simplex Equiangular Tight Frame) tối ưu hóa biên lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học tương phản (InfoNCE / CLIP Loss):&lt;/strong&gt; Hàm mất mát đối sánh thực chất là hàm log-sum-exp có tham số nhiệt độ trên tích vô hướng cặp mẫu dương–âm, thừa hưởng trực tiếp tính lồi theo các điểm tương đồng (similarities).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-cross-entropy-gradient-và-xác-nhận-hessian-bán-xác-định-dương&quot;&gt;Giải thích: Tính tay Cross-Entropy, Gradient và xác nhận Hessian bán xác định dương&lt;/h3&gt;

&lt;p&gt;Xét một bài toán phân loại 3 lớp với vector logit đầu ra \(z = (2, 1, 0)^T\) và nhãn đúng là lớp đầu tiên (\(y = 1\), vector one-hot \(e_1 = (1, 0, 0)^T\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính hàm mất mát Cross-Entropy \(L(z) = -z_1 + \ln(e^{z_1} + e^{z_2} + e^{z_3})\):&lt;/strong&gt;
\(e^2 + e^1 + e^0 \approx 7.389 + 2.718 + 1.000 = 11.107.\)
\(L(z) = -2 + \ln(11.107) \approx -2 + 2.408 = 0.408.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính phân phối Softmax và Gradient \(\nabla_z L(z) = p - e_1\):&lt;/strong&gt;
\(p = \operatorname{softmax}(z) \approx (0.665,\ 0.245,\ 0.090)^T.\)
\(\nabla_z L(z) = p - e_1 \approx (-0.335,\ +0.245,\ +0.090)^T.\)
Dấu âm ở tọa độ 1 bảo thuật toán &lt;em&gt;tăng&lt;/em&gt; logit \(z_1\) của lớp đúng, còn dấu dương ở tọa độ 2, 3 bảo &lt;em&gt;giảm&lt;/em&gt; logit của hai lớp sai!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra độ cong (Hessian \(\nabla^2_z L = \operatorname{diag}(p) - p p^T\)):&lt;/strong&gt;
Với mọi vector \(v \in \mathbb{R}^3\), ta có \(v^T(\operatorname{diag}(p) - pp^T)v = \sum p_i v_i^2 - (\sum p_i v_i)^2 = \operatorname{Var}_{I \sim p}(v_I) \ge 0\)! Chính vì phương sai luôn không âm, ma trận Hessian luôn bán xác định dương và Cross-Entropy chắc chắn &lt;strong&gt;lồi&lt;/strong&gt; theo \(z\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Hàm lồi là dạng hàm mục tiêu có cấu trúc thuận lợi nhất trong tối ưu hóa: mọi cực tiểu địa phương đều là cực tiểu toàn cục, và chặn dưới bậc nhất \(f(y)\ge f(x)+\nabla f(x)^\top(y-x)\) xác định một siêu phẳng hỗ trợ cho epigraph của hàm. Bài này trình bày ba ngữ cảnh trong học máy giai đoạn 2021–2025 nơi cấu trúc lồi vẫn phát huy tác dụng trực tiếp — ngay cả khi &lt;em&gt;toàn bộ&lt;/em&gt; mạng nơ-ron sâu là không lồi.&lt;/p&gt;

&lt;h2 id=&quot;cross-entropy-log-sum-exp-và-hiệu-chỉnh-xác-suất&quot;&gt;Cross-entropy, log-sum-exp và hiệu chỉnh xác suất&lt;/h2&gt;

&lt;p&gt;Khi ánh xạ đặc trưng được cố định, bài toán hồi quy logistic đa lớp là bài toán lồi theo trọng số lớp cuối. Với vector logit \(z\in\mathbb{R}^C\) và nhãn one-hot \(y\), hàm mất mát&lt;/p&gt;

\[\ell(z,y) = -z_y + \log\sum_{c=1}^C e^{z_c}\]

&lt;p&gt;là hàm lồi theo \(z\) vì log-sum-exp lồi và tăng theo từng tọa độ, còn \(-z_y\) là hàm affine (suy trực tiếp từ các quy tắc hợp thành ở bài 03-02). Gradient của log-sum-exp chính là phân phối xác suất softmax, còn hàm liên hợp của nó là hàm entropy âm trên đơn hình xác suất (bài 03-03). Nhờ cấu trúc này, phương pháp &lt;em&gt;temperature scaling&lt;/em&gt; — thay \(z\) bằng \(z/T\) và điều chỉnh một tham số vô hướng \(T\) trên tập kiểm định — trở thành một bài toán tối ưu &lt;em&gt;lồi&lt;/em&gt; một chiều.&lt;/p&gt;

&lt;p&gt;Guo và cộng sự (2017) đã phổ biến temperature scaling như một bước hiệu chỉnh xác suất sau huấn luyện. Minderer, Djolonga, Romijnders, Hubis, Zhai, Houlsby, Tran và Lucic (&lt;em&gt;Revisiting the Calibration of Modern Neural Networks&lt;/em&gt;, &lt;a href=&quot;https://proceedings.neurips.cc/paper/2021/hash/8420d359404024567b5aefda1231af24-Abstract.html&quot;&gt;NeurIPS 2021&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2106.07998&quot;&gt;arXiv:2106.07998&lt;/a&gt;) khảo sát lại độ hiệu chỉnh trên diện rộng nhiều mô hình thị giác hiện đại như Vision Transformer và MLP-Mixer, cho thấy một số kiến trúc không dùng tích chập có độ hiệu chỉnh tốt hơn các mạng CNN quá tự tin trước đây. Dưới góc độ tối ưu hóa, điểm cốt lõi rất gọn: hàm mất mát là lồi theo logit, nên bước hiệu chỉnh bằng một tham số nhiệt độ là một bài toán tối ưu lồi.&lt;/p&gt;

&lt;h2 id=&quot;neural-collapse-khi-mạng-không-lồi-gặp-lớp-cuối-lồi&quot;&gt;Neural collapse: khi mạng không lồi gặp lớp cuối lồi&lt;/h2&gt;

&lt;p&gt;Sau khi đạt mức nội suy trên tập huấn luyện, các mô hình phân loại sâu thường bước vào &lt;em&gt;giai đoạn cuối&lt;/em&gt; với hiện tượng đặc trưng lớp áp chót hội tụ về trung bình lớp, các trung bình lớp tạo thành một khung chặt đều góc đơn hình (simplex ETF), và các vector trọng số phân loại thẳng hàng với các trung bình lớp đó (Papyan, Han và Donoho, &lt;a href=&quot;https://www.pnas.org/doi/10.1073/pnas.2015509117&quot;&gt;PNAS 2020&lt;/a&gt;). Zhu, Ding, Zhou và cộng sự (&lt;a href=&quot;https://papers.nips.cc/paper/2021/hash/f92586a25bb3145facd64ab20fd554ff-Abstract.html&quot;&gt;NeurIPS 2021&lt;/a&gt;) phân tích mô hình đặc trưng không ràng buộc tách riêng lớp cuối — coi đặc trưng và trọng số phân loại là các biến tự do với hàm mất mát cross-entropy kèm suy giảm trọng số (weight decay) — và chỉ ra rằng địa hình tối ưu có cấu trúc thuận lợi: mọi cấu hình ETF đều là cực tiểu toàn cục, còn mọi điểm dừng khác đều là điểm yên ngựa chặt có độ cong âm.&lt;/p&gt;

&lt;p&gt;Bài học cho Chương 03 không phải là “mạng nơ-ron sâu là lồi”, mà là thành phần &lt;em&gt;lồi&lt;/em&gt; ở lớp cuối (cross-entropy theo đặc trưng và trọng số kèm số hạng chuẩn hóa Euclidean) đã giải thích phần lớn cấu trúc hình học quan sát được ở cuối quá trình huấn luyện: khi đặc trưng đủ tự do, bài toán lớp cuối tự nhiên dẫn đến một cấu hình rất đối xứng.&lt;/p&gt;

&lt;h2 id=&quot;mất-mát-đối-sánh-và-thành-phần-lồi&quot;&gt;Mất mát đối sánh và thành phần lồi&lt;/h2&gt;

&lt;p&gt;Các phương pháp học đối sánh tự giám sát (như SimCLR, CLIP và các biến thể tiếp theo) thường cực tiểu hóa hàm mất mát dạng InfoNCE. Với vector biểu diễn neo \(u\), mẫu dương \(v_+\) và các mẫu âm \(v_1,\ldots,v_K\):&lt;/p&gt;

\[\ell = -\log \frac{e^{u^\top v_+/\tau}}{e^{u^\top v_+/\tau} + \sum_{k=1}^K e^{u^\top v_k/\tau}}.\]

&lt;p&gt;Xét theo các độ tương tự (hoặc theo \(u\) khi cố định các vector \(v\)), biểu thức này tiếp tục có dạng log-sum-exp của các hàm tuyến tính nên là hàm lồi theo \(u\). Dù toàn bộ mạng nơ-ron không lồi, đầu đối sánh ở lớp trên cùng vẫn là một bài toán phân loại lồi trên mặt cầu. Wang và Isola (&lt;em&gt;Understanding Contrastive Representation Learning through Alignment and Uniformity&lt;/em&gt;, &lt;a href=&quot;https://proceedings.mlr.press/v119/wang20k.html&quot;&gt;ICML 2020&lt;/a&gt;) phân tích mục tiêu InfoNCE ở giới hạn tiệm cận thành hai thành phần: &lt;em&gt;alignment&lt;/em&gt; (kéo cặp mẫu dương lại gần nhau) và &lt;em&gt;uniformity&lt;/em&gt; (phân bố đều đặc trưng trên mặt cầu). Dù công bố năm 2020, hàm mất mát này vẫn là tiêu chuẩn trong nhiều mô hình thị giác–ngôn ngữ giai đoạn 2022–2026, bao gồm các thiết lập kiểu CLIP được so sánh với bộ tối ưu Lion ở Chương 06.&lt;/p&gt;

&lt;h2 id=&quot;kiểm-chứng-nhanh-bằng-numpy&quot;&gt;Kiểm chứng nhanh bằng NumPy&lt;/h2&gt;

&lt;p&gt;Đoạn mã sau kiểm tra trực tiếp bất đẳng thức Jensen (định nghĩa ở bài 03-01) cho hàm log-sum-exp trên hai vector logit ngẫu nhiên:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;default_rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;z1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lhs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;rhs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lhs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rhs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nếu đoạn kiểm tra này sai trên các số thực hữu hạn sau khi đã dịch theo giá trị lớn nhất &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;m&lt;/code&gt;, nguyên nhân chắc chắn nằm ở lỗi lập trình chứ không phải phản ví dụ toán học.&lt;/p&gt;

&lt;h2 id=&quot;điểm-cốt-lõi-cần-nhớ&quot;&gt;Điểm cốt lõi cần nhớ&lt;/h2&gt;

&lt;p&gt;Khi thiết kế một hàm mất mát, câu hỏi đầu tiên nên đặt ra là liệu hàm có lồi theo &lt;em&gt;đối số cuối cùng&lt;/em&gt; mà nó nhận vào hay không (logit, độ tương tự hoặc dự đoán tuyến tính). Nếu có, toàn bộ các quy tắc hợp thành và lý thuyết hàm liên hợp trong chương này đều áp dụng được, bất kể kiến trúc trích xuất đặc trưng phía trước là gì. Hiệu chỉnh xác suất, hiện tượng neural collapse và hàm mất mát đối sánh là ba bài toán khác nhau nhưng cùng dựa trên một khối xây dựng lồi chung: hàm log-sum-exp.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;M. Minderer và cộng sự, “Revisiting the Calibration of Modern Neural Networks,” NeurIPS 2021. &lt;a href=&quot;https://proceedings.neurips.cc/paper/2021/hash/8420d359404024567b5aefda1231af24-Abstract.html&quot;&gt;tóm tắt&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2106.07998&quot;&gt;arXiv:2106.07998&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;V. Papyan, X. Y. Han và D. L. Donoho, “Prevalence of neural collapse…,” &lt;em&gt;PNAS&lt;/em&gt; 2020. &lt;a href=&quot;https://www.pnas.org/doi/10.1073/pnas.2015509117&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Z. Zhu, T. Ding, J. Zhou và cộng sự, “A Geometric Analysis of Neural Collapse with Unconstrained Features,” NeurIPS 2021. &lt;a href=&quot;https://papers.nips.cc/paper/2021/hash/f92586a25bb3145facd64ab20fd554ff-Abstract.html&quot;&gt;tóm tắt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;T. Wang và P. Isola, “Understanding Contrastive Representation Learning through Alignment and Uniformity,” ICML 2020. &lt;a href=&quot;https://proceedings.mlr.press/v119/wang20k.html&quot;&gt;PMLR&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>02-07 Ứng dụng và phát triển gần đây</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_07_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_07_Applications_Recent</id>
   <content type="html">&lt;p&gt;Đơn hình xác suất (probability simplex), quả cầu chuẩn và đa diện không phải là những hình vẽ cổ điển nằm yên trong sách giáo khoa những năm 1970. Mỗi giây trên toàn cầu, tầng đầu ra &lt;strong&gt;Softmax&lt;/strong&gt; của mọi mô hình ngôn ngữ lớn đang chiếu hàng trăm nghìn điểm logit thẳng vào bên trong một &lt;strong&gt;đơn hình xác suất&lt;/strong&gt;; các hệ thống học máy bền vững (Distributionally Robust Optimization) đang tối ưu trong &lt;strong&gt;quả cầu Wasserstein&lt;/strong&gt; lồi; và các nền tảng phân bổ nguồn lực công bằng đang vận hành trên &lt;strong&gt;đa diện Birkhoff&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Bài đọc mở rộng này kết nối trực tiếp hình học tập lồi Chương 02 với các chủ đề nghiên cứu mũi nhọn giai đoạn 2022–2026.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-miền-lồi-trong-ai-và-dữ-liệu-hiện-đại&quot;&gt;Kiến thức cần nhớ: Ba miền lồi trong AI và dữ liệu hiện đại&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đơn hình xác suất \(\Delta_K\) và ánh xạ Softmax:&lt;/strong&gt; Đầu ra xác suất của mạng phân loại hay LLM luôn bị ràng buộc nằm trong tập lồi \(\Delta_K = \{p \ge 0 : \mathbf{1}^T p = 1\}\), với các đỉnh là các vector one-hot đại diện cho quyết định chắc chắn tuyệt đối.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quả cầu Wasserstein (Tối ưu bền vững theo phân phối — DRO):&lt;/strong&gt; Thay vì tin mù quáng vào phân phối mẫu quan sát được \(\hat P\), ta tối ưu trường hợp xấu nhất trên một quả cầu lồi các phân phối xác suất quanh \(\hat P\) đo bằng khoảng cách vận chuyển tối ưu Wasserstein.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đa diện công bằng và phân bổ tài nguyên (Fairness Polytopes):&lt;/strong&gt; Các ràng buộc tỷ lệ đại diện nhóm hay ma trận song ngẫu nhiên (Birkhoff polytope) đều tạo thành đa diện lồi, cho phép giải bài toán phân bổ công bằng bằng quy hoạch tuyến tính hoặc chiếu lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-quan-sát-softmax-và-tham-số-nhiệt-độ-tau-dịch-chuyển-điểm-trong-đơn-hình-delta_3&quot;&gt;Giải thích: Quan sát Softmax và tham số nhiệt độ \(\tau\) dịch chuyển điểm trong đơn hình \(\Delta_3\)&lt;/h3&gt;

&lt;p&gt;Cho vector logit đầu ra của 3 lớp \(z = (2, 1, 0)^T\). Ánh xạ Softmax với nhiệt độ \(\tau &amp;gt; 0\) là \(p_i(\tau) = \frac{e^{z_i/\tau}}{\sum_j e^{z_j/\tau}} \in \Delta_3\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhiệt độ chuẩn \(\tau = 1\):&lt;/strong&gt;
\(e^2 \approx 7.389,\quad e^1 \approx 2.718,\quad e^0 = 1.000 \implies \text{tổng } Z_1 \approx 11.107.\)
Vector xác suất là:
\(p(1) \approx \left(\frac{7.389}{11.107},\ \frac{2.718}{11.107},\ \frac{1.000}{11.107}\right) \approx (0.665,\ 0.245,\ 0.090) \in \operatorname{int}(\Delta_3).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hạ nhiệt độ xuống \(\tau = 0.5\) (nhân đôi logit thành \((4, 2, 0)\)):&lt;/strong&gt;
\(e^4 \approx 54.598,\quad e^2 \approx 7.389,\quad e^0 = 1.000 \implies \text{tổng } Z_{0.5} \approx 62.987.\)
Vector xác suất trở thành:
\(p(0.5) \approx (0.867,\ 0.117,\ 0.016) \in \Delta_3.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trực giác hình học trên đơn hình \(\Delta_3\):&lt;/strong&gt; Khi \(\tau \to 0^+\), điểm \(p(\tau)\) tiến sát về &lt;strong&gt;đỉnh cực biên&lt;/strong&gt; \((1, 0, 0)\) (lựa chọn tham lam argmax); ngược lại khi \(\tau \to \infty\), \(p(\tau)\) kéo về đúng &lt;strong&gt;trọng tâm&lt;/strong&gt; \((1/3, 1/3, 1/3)\) của đơn hình!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Tập lồi là miền khả thi mà mọi tổ hợp trung bình có trọng số không âm của các điểm trong đó vẫn nằm lại bên trong miền. Tính chất hình học này giải thích vì sao nhiều tập ràng buộc trong học máy hiện đại có dạng đơn hình, hình cầu hoặc phổ diện (spectrahedron). Bài này điểm qua ba họ tập lồi xuất hiện thường xuyên trong các công trình và thư viện giai đoạn 2022–2025, mỗi họ gắn trực tiếp với một định nghĩa đã học: đơn hình xác suất, quả cầu Wasserstein trong không gian phân phối, và đa diện xác định bởi các bất đẳng thức công bằng hoặc ngân sách.&lt;/p&gt;

&lt;h2 id=&quot;đơn-hình-xác-suất-softmax-và-hình-học-lớp-cuối&quot;&gt;Đơn hình xác suất, softmax và hình học lớp cuối&lt;/h2&gt;

&lt;p&gt;Đơn hình chuẩn&lt;/p&gt;

\[\Delta^{n-1} = \bigl\{ p\in\mathbb{R}^n : p\ge 0,\; \mathbf{1}^\top p = 1\bigr\}\]

&lt;p&gt;là một tập lồi (giao của một siêu phẳng với góc phần tư không âm). Hàm softmax là ánh xạ trơn đưa vector logit &lt;em&gt;vào&lt;/em&gt; phần trong tương đối của \(\Delta^{n-1}\). Nhờ vậy, mọi đầu attention trong kiến trúc Transformer và mọi mô hình hồi quy logistic đa lớp đều dùng tầng phi tuyến cuối để chiếu vector logit lên một tập lồi có thể hình dung trực tiếp trong \(\mathbb{R}^2\) và \(\mathbb{R}^3\).&lt;/p&gt;

&lt;p&gt;Một cấu trúc đơn hình khác xuất hiện ở giai đoạn &lt;em&gt;cuối&lt;/em&gt; quá trình huấn luyện mạng nơ-ron sâu. Papyan, Han và Donoho (&lt;em&gt;Prevalence of neural collapse&lt;/em&gt;, &lt;a href=&quot;https://www.pnas.org/doi/10.1073/pnas.2015509117&quot;&gt;PNAS 2020&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2008.08186&quot;&gt;arXiv:2008.08186&lt;/a&gt;) quan sát thấy các vector trung bình lớp (đã quy tâm) ở tầng áp chót hội tụ về một &lt;em&gt;khung chặt đều góc đơn hình&lt;/em&gt; (simplex equiangular tight frame, gọi tắt là simplex ETF) — cấu hình điểm đối xứng nhất trên mặt cầu. Zhu, Ding, Zhou và cộng sự (&lt;em&gt;A Geometric Analysis of Neural Collapse with Unconstrained Features&lt;/em&gt;, &lt;a href=&quot;https://papers.nips.cc/paper/2021/hash/f92586a25bb3145facd64ab20fd554ff-Abstract.html&quot;&gt;NeurIPS 2021&lt;/a&gt;) sau đó chứng minh rằng trong mô hình đặc trưng không ràng buộc với hàm mất mát cross-entropy và suy giảm trọng số (weight decay), mọi cấu hình ETF đều là cực tiểu toàn cục còn mọi điểm dừng khác đều là điểm yên ngựa chặt. Như vậy, hình học tập lồi gắn trực tiếp với cấu trúc nghiệm của bài toán: ETF là một tập con xác định trên mặt cầu, còn đơn hình xác suất là miền đầu ra thực tế của bộ phân loại.&lt;/p&gt;

&lt;p&gt;Khi luyện tập kiểm tra tính lồi của một tập \(C\), nên luôn đưa \(\Delta^{n-1}\) và hình cầu Euclidean vào nhóm ví dụ nền tảng, vì đây là cấu trúc hình học của nhiều bài toán phân loại và chuẩn hóa (regularization).&lt;/p&gt;

&lt;h2 id=&quot;quả-cầu-wasserstein-như-tập-bất-định-phân-phối&quot;&gt;Quả cầu Wasserstein như tập bất định phân phối&lt;/h2&gt;

&lt;p&gt;Tối ưu hóa vững theo phân phối (Distributionally Robust Optimization — DRO) thay phân phối thực nghiệm \(\hat{P}\) bằng một &lt;em&gt;tập&lt;/em&gt; các phân phối lân cận, rồi tối ưu theo trường hợp xấu nhất trong tập đó. Quả cầu Wasserstein&lt;/p&gt;

\[\mathcal{B}_\varepsilon(\hat{P}) = \bigl\{ Q : W_p(Q,\hat{P}) \le \varepsilon\bigr\}\]

&lt;p&gt;là một tập lồi trong không gian các độ đo xác suất (quả cầu theo khoảng cách vận chuyển tối ưu). Nhờ đó, bài toán tối ưu chống lại phân phối xấu nhất \(Q\in\mathcal{B}_\varepsilon(\hat{P})\) thường có thể viết lại thành một bài toán tối ưu lồi hữu hạn chiều.&lt;/p&gt;

&lt;p&gt;Hai tài liệu tham khảo chính gồm: Gao và Kleywegt, “Distributionally Robust Stochastic Optimization with Wasserstein Distance,” &lt;a href=&quot;https://doi.org/10.1287/moor.2022.1275&quot;&gt;&lt;em&gt;Mathematics of Operations Research&lt;/em&gt; 48(2):603–655, 2023&lt;/a&gt;, chứng minh đối ngẫu mạnh cho DRO Wasserstein và mô tả cấu trúc phân phối trường hợp xấu nhất; và bài hướng dẫn của Kuhn, Mohajerin Esfahani, Nguyen và Shafieezadeh-Abadeh, &lt;em&gt;Wasserstein Distributionally Robust Optimization&lt;/em&gt; (&lt;a href=&quot;https://doi.org/10.1287/educ.2019.0198&quot;&gt;INFORMS TutORials 2019&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/1908.08729&quot;&gt;arXiv:1908.08729&lt;/a&gt;, bản cập nhật tháng 11/2024), trình bày rõ mối liên hệ giữa quả cầu Wasserstein với các bài toán phân loại, hồi quy và ước lượng hợp lý cực đại (MLE). Ngoài ra, bài khảo sát tổng quan năm 2025 trên &lt;em&gt;Acta Numerica&lt;/em&gt; (&lt;a href=&quot;https://www.cambridge.org/core/journals/acta-numerica/article/distributionally-robust-optimization/5B4E65E3A5A2AEF24E218A6B34E6EAA2&quot;&gt;Kuhn, Shafiee, et al.&lt;/a&gt;) đặt quả cầu Wasserstein trong tương quan với các loại tập bất định phân phối khác.&lt;/p&gt;

&lt;p&gt;Cách mô hình hóa này tương tự việc thay ước lượng điểm bằng một tập bất định lồi trong quy hoạch tuyến tính vững, chỉ khác ở chỗ “điểm” ở đây là một phân phối xác suất. Khi \(\mathcal{B}_\varepsilon(\hat{P})\) là tập lồi và hàm mục tiêu ứng với phân phối xấu nhất lồi theo biến quyết định, bài toán DRO bên ngoài trở thành một bài toán tối ưu lồi — dạng bài sẽ được hệ thống hóa ở Chương 04.&lt;/p&gt;

&lt;h2 id=&quot;polytope-công-bằng-và-phân-bổ-tài-nguyên&quot;&gt;Polytope công bằng và phân bổ tài nguyên&lt;/h2&gt;

&lt;p&gt;Các bất đẳng thức tuyến tính trên xác suất xác định một đa diện. Chẳng hạn, ràng buộc ngang bằng nhân khẩu học (demographic parity)&lt;/p&gt;

\[\bigl| \mathbb{E}[h(X)\mid A=a] - \mathbb{E}[h(X)\mid A=a&apos;] \bigr| \le \epsilon\]

&lt;p&gt;cắt ra một polytope trong không gian các bộ phân loại ngẫu nhiên hóa. Agarwal, Beygelzimer, Dudík, Langford và Wallach (&lt;a href=&quot;https://proceedings.mlr.press/v80/agarwal18a.html&quot;&gt;ICML 2018&lt;/a&gt;) xây dựng phương pháp quy giảm (reductions) xem các ràng buộc này là miền khả thi; thư viện &lt;a href=&quot;https://fairlearn.org/v0.12/user_guide/mitigation/reductions.html&quot;&gt;Fairlearn&lt;/a&gt; vẫn cung cấp cơ chế này thông qua đối tượng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Moment&lt;/code&gt; trong các phiên bản 2025–2026.&lt;/p&gt;

&lt;p&gt;Cấu trúc hình học tương tự cũng mô tả các ràng buộc ngân sách và phân bổ tài nguyên: \(x\ge 0\), \(\mathbf{1}^\top x = 1\) (phân bổ danh mục trên đơn hình), hoặc \(0\le x\le 1\), \(Ax\le b\) (polytope phân bổ ngân sách truyền thông dạng bài toán cái túi). Siêu phẳng phân tách ở phần sau của chương chính là chứng chỉ cho thấy một nghiệm ứng viên \(x\) nằm ngoài polytope — cũng là dạng chứng chỉ mà các bộ giải tối ưu dùng để khẳng định bài toán vô nghiệm.&lt;/p&gt;

&lt;h2 id=&quot;hai-công-thức-hình-học-cốt-lõi&quot;&gt;Hai công thức hình học cốt lõi&lt;/h2&gt;

&lt;p&gt;Mọi miền ràng buộc được nhắc tới trong bài đều có thể biểu diễn dưới dạng giao của các tập lồi cơ bản hoặc quả cầu trong không gian phân phối:&lt;/p&gt;

\[\mathcal{C} = \Delta^{n-1} \cap \{ x : Fx \le g \} \qquad\text{hoặc}\qquad \mathcal{B}_\varepsilon(\hat{P}).\]

&lt;p&gt;Khi từng thành phần là tập lồi thì giao của chúng cũng lồi, đảm bảo mọi bước tìm kiếm địa phương trong \(\mathcal{C}\) diễn ra trên một miền không có “lỗ hổng”. Đó chính là vai trò nền tảng của Chương 02 khi nhìn qua các bài toán attention, DRO và công bằng trong học máy.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;V. Papyan, X. Y. Han và D. L. Donoho, “Prevalence of neural collapse during the terminal phase of deep learning training,” &lt;em&gt;PNAS&lt;/em&gt; 117(40):24652–24663, 2020. &lt;a href=&quot;https://www.pnas.org/doi/10.1073/pnas.2015509117&quot;&gt;DOI&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2008.08186&quot;&gt;arXiv:2008.08186&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Z. Zhu, T. Ding, J. Zhou và cộng sự, “A Geometric Analysis of Neural Collapse with Unconstrained Features,” NeurIPS 2021. &lt;a href=&quot;https://papers.nips.cc/paper/2021/hash/f92586a25bb3145facd64ab20fd554ff-Abstract.html&quot;&gt;tóm tắt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;R. Gao và A. J. Kleywegt, “Distributionally Robust Stochastic Optimization with Wasserstein Distance,” &lt;em&gt;Math. Oper. Res.&lt;/em&gt; 48(2):603–655, 2023. &lt;a href=&quot;https://doi.org/10.1287/moor.2022.1275&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;D. Kuhn, P. Mohajerin Esfahani, V. A. Nguyen và S. Shafieezadeh-Abadeh, “Wasserstein Distributionally Robust Optimization,” INFORMS TutORials 2019; arXiv:1908.08729 (sửa 2024). &lt;a href=&quot;https://arxiv.org/abs/1908.08729&quot;&gt;arXiv&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;A. Agarwal và cộng sự, “A Reductions Approach to Fair Classification,” ICML 2018. &lt;a href=&quot;https://proceedings.mlr.press/v80/agarwal18a.html&quot;&gt;PMLR&lt;/a&gt; · &lt;a href=&quot;https://fairlearn.org/v0.12/user_guide/mitigation/reductions.html&quot;&gt;Fairlearn&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>01-05 Ứng dụng và phát triển gần đây</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_05_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_05_Applications_Recent</id>
   <content type="html">&lt;p&gt;Khi bạn đọc công thức ngắn gọn \(\min_{x \in \mathcal{C}} f(x)\) ở Chương 01, rất dễ nghĩ nó chỉ dành cho những bài toán nhỏ trên giấy. Nhưng hãy nhìn vào các bài báo AI gây chấn động nhất giai đoạn 2022–2026: từ định luật mở rộng Chinchilla quyết định cách chi hàng chục triệu USD huấn luyện LLM, khung Predict-then-Optimize (SPO+) nối dự báo học máy với quyết định vận trù học, cho đến các ràng buộc công bằng (fairness) trong chấm điểm tín dụng — tất cả đều viết trực tiếp bằng đúng bộ khung của Chương 01!&lt;/p&gt;

&lt;p&gt;Bài đọc mở rộng này giúp bạn luyện kỹ năng đọc các bài báo khoa học dữ liệu hiện đại dưới lăng kính của một nhà tối ưu hóa: nhận diện biến, hàm mất mát thay thế và tập ràng buộc.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-mặt-trận-ứng-dụng-hiện-đại-của-khung-chương-01&quot;&gt;Kiến thức cần nhớ: Ba mặt trận ứng dụng hiện đại của khung Chương 01&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa rủi ro thực nghiệm dưới ngân sách tính toán (Compute-Optimal ERM):&lt;/strong&gt; Tối ưu hóa việc phân bổ ngân sách FLOP cố định \(C \approx 6ND\) giữa kích thước mô hình \(N\) và số token huấn luyện \(D\) để cực tiểu hóa hàm mất mát kiểm thử \(L(N, D)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Predict-then-Optimize và hàm thay thế lồi SPO+:&lt;/strong&gt; Khi đầu ra của mô hình dự báo được nạp vào một bài toán LP hạ nguồn, cực tiểu hóa sai số dự báo MSE chưa chắc cho quyết định tốt nhất; hàm mất mát SPO+ thay thế bài toán rời rạc khó bằng một chặn trên &lt;strong&gt;lồi&lt;/strong&gt; tối ưu hóa trực tiếp chất lượng quyết định.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Công bằng thuật toán như ràng buộc tối ưu (Fairness-Constrained Optimization):&lt;/strong&gt; Biến các tiêu chuẩn đạo đức (như chênh lệch tỷ lệ chọn giữa hai nhóm nhân khẩu học không quá \(\epsilon\)) thành ràng buộc bất đẳng thức tường minh bên cạnh hàm mục tiêu độ chính xác.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-phân-bổ-ngân-sách-huấn-luyện-theo-luật-chinchilla&quot;&gt;Giải thích: Tính tay phân bổ ngân sách huấn luyện theo luật Chinchilla&lt;/h3&gt;

&lt;p&gt;Trong nghiên cứu Chinchilla (Hoffmann et al., 2022), tổng chi phí huấn luyện một mô hình ngôn ngữ có \(N\) tham số trên \(D\) token xấp xỉ \(C = 6ND\) (FLOPs), và nghiệm tối ưu của bài toán \(\min_{N, D} L(N, D)\) dưới ràng buộc \(6ND = C\) cho tỷ lệ vàng xấp xỉ \(D^* \approx 20 N^*\).&lt;/p&gt;

&lt;p&gt;Giả sử bạn có ngân sách cố định \(C = 6 \times 10^{18}\) FLOPs:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thay quan hệ tối ưu \(D = 20N\) vào ràng buộc ngân sách:&lt;/strong&gt;
\(6 \cdot N \cdot (20N) = 6 \times 10^{18} \implies 120 N^2 = 6 \times 10^{18}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải tìm số tham số tối ưu \(N^*\):&lt;/strong&gt;
\(N^2 = \frac{6 \times 10^{18}}{120} = 5 \times 10^{16} \implies N^* = \sqrt{5} \times 10^8 \approx 2.24 \times 10^8 \text{ (224 triệu tham số)}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suy ra số token huấn luyện tối ưu \(D^*\):&lt;/strong&gt;
\(D^* = 20 N^* \approx 4.47 \times 10^9 \text{ (4.47 tỷ token)}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra ngược ràng buộc:&lt;/strong&gt; \(6 N^* D^* = 6 \times (2.236 \times 10^8) \times (4.472 \times 10^9) \approx 6.00 \times 10^{18}\) FLOPs. Nếu bạn phạm sai lầm xây mô hình lớn gấp 4 lần (\(900\) triệu tham số) nhưng chỉ huấn luyện trên \(1.1\) tỷ token (cùng ngân sách \(C\)), mô hình sẽ rơi vào vùng &lt;em&gt;thiếu dữ liệu&lt;/em&gt; và có hàm mất mát kém tối ưu hơn rõ rệt!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Chương 01 định nghĩa bài toán tối ưu hóa là “chọn \(x\in\mathcal{C}\) để làm \(f(x)\) nhỏ nhất”. Cấu trúc này hiện là nền tảng của khoa học dữ liệu trong công nghiệp: huấn luyện mô hình dự đoán (thường qua cực tiểu hóa rủi ro thực nghiệm), sau đó đưa dự đoán vào một bài toán ra quyết định &lt;em&gt;ở bước tiếp theo&lt;/em&gt;, đôi khi kèm theo ràng buộc công bằng hoặc giới hạn vận hành. Bài đọc này xem xét ba bối cảnh cụ thể giai đoạn 2022–2026. Các định nghĩa ở 01-01 và 01-02 giữ nguyên; ta chỉ cập nhật những &lt;em&gt;ví dụ&lt;/em&gt; điển hình mà người làm khoa học dữ liệu cần nắm được.&lt;/p&gt;

&lt;h2 id=&quot;erm-quy-mô-lớn-mô-hình-ngôn-ngữ-tối-ưu-theo-tính-toán&quot;&gt;ERM quy mô lớn: mô hình ngôn ngữ tối ưu theo tính toán&lt;/h2&gt;

&lt;p&gt;Tiền huấn luyện mô hình ngôn ngữ lớn là một bài toán cực tiểu hóa rủi ro thực nghiệm với hàm mất mát dự đoán token kế tiếp (hoặc token bị che). Gọi \(N\) là số tham số và \(D\) là số token huấn luyện. Với ngân sách tính toán cố định \(C\) (tính bằng FLOPs), ta có quan hệ xấp xỉ \(C \propto N\cdot D\). Câu hỏi thiết kế trung tâm không phải “bài toán này có lồi không?” — huấn luyện Transformer là không lồi — mà là cặp \((N,D)\) nào cho giá trị mất mát nhỏ nhất dưới ngân sách \(C\) cho trước.&lt;/p&gt;

&lt;p&gt;Hoffmann, Borgeaud, Mensch, Sifre và cộng sự (&lt;em&gt;Training Compute-Optimal Large Language Models&lt;/em&gt;, &lt;a href=&quot;https://proceedings.neurips.cc/paper/2022/hash/c1e2faff6f588870935f114ebe04a3e5-Abstract-Conference.html&quot;&gt;NeurIPS 2022&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2203.15556&quot;&gt;arXiv:2203.15556&lt;/a&gt;) huấn luyện hơn 400 mô hình và chỉ ra rằng, để tối ưu theo ngân sách tính toán, kích thước mô hình và lượng dữ liệu huấn luyện cần tăng cùng tỷ lệ: khi tăng gấp đôi \(N\) thì cũng nên tăng gấp đôi \(D\). Mô hình Chinchilla 70 tỷ tham số, huấn luyện trên khoảng 1.4 nghìn tỷ token với cùng ngân sách tính toán như Gopher 280 tỷ tham số, vượt trội hơn Gopher, GPT-3 và nhiều mô hình lớn hơn nhưng thiếu dữ liệu trên nhiều bộ kiểm chuẩn, đạt 67.5% trên MMLU. Bài giới thiệu kèm theo của DeepMind nằm &lt;a href=&quot;https://deepmind.google/blog/an-empirical-analysis-of-compute-optimal-large-language-model-training/&quot;&gt;tại đây&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Đối với khóa học này, bài học rút ra mang tính cấu trúc. &lt;em&gt;Dạng bài toán&lt;/em&gt; vẫn là&lt;/p&gt;

\[\min_w \frac{1}{n}\sum_{i=1}^n \ell\bigl(h_w(x_i), y_i\bigr),\]

&lt;p&gt;nhưng &lt;em&gt;biến quyết định của bài toán thiết kế bên ngoài&lt;/em&gt; là \(N\) và \(D\), không chỉ riêng trọng số \(w\). Điều giúp Chinchilla thành công không phải tính lồi, mà là việc &lt;em&gt;đặt đúng&lt;/em&gt; bài toán tối ưu hóa.&lt;/p&gt;

&lt;h2 id=&quot;predict-then-optimize-và-hàm-thay-thế-lồi-spo&quot;&gt;Predict-then-optimize và hàm thay thế lồi SPO+&lt;/h2&gt;

&lt;p&gt;Nhiều quy trình phân tích gồm hai bước nối tiếp: dự đoán vector chi phí \(\hat{c}\) từ đặc trưng đầu vào, sau đó giải bài toán&lt;/p&gt;

\[\min_{z\in\mathcal{Z}} \hat{c}^\top z\]

&lt;p&gt;để đưa ra quyết định định tuyến, tồn kho hoặc phân bổ danh mục \(z\). Huấn luyện bộ dự đoán nhằm cực tiểu hóa sai số bình phương trên \(c\) có thể không phản ánh đúng mục tiêu cuối cùng: một sai số nhỏ của \(\hat{c}\) nhưng làm thay đổi đỉnh tối ưu của \(\mathcal{Z}\) có thể gây thiệt hại lớn hơn nhiều so với một sai số lớn nhưng không làm đổi quyết định.&lt;/p&gt;

&lt;p&gt;Elmachtoub và Grigas (&lt;em&gt;Smart “Predict, then Optimize”&lt;/em&gt;, &lt;a href=&quot;https://doi.org/10.1287/mnsc.2020.3922&quot;&gt;Management Science 68(1):9–26, 2022&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/1710.08005&quot;&gt;arXiv:1710.08005&lt;/a&gt;) định nghĩa hàm mất mát SPO để đo trực tiếp &lt;em&gt;sai số quyết định&lt;/em&gt; gây ra bởi \(\hat{c}\). Do hàm mất mát này khó tối ưu trực tiếp, họ xây dựng hàm thay thế (surrogate) lồi &lt;strong&gt;SPO+&lt;/strong&gt; từ tính đối ngẫu và chứng minh tính vững Fisher (Fisher consistency) dưới các điều kiện nhẹ. Hàm thay thế này áp dụng được cho mọi bài toán tối ưu đa diện, lồi hoặc quy hoạch nguyên hỗn hợp có hàm mục tiêu tuyến tính. Các thực nghiệm trên bài toán đường đi ngắn nhất và tối ưu danh mục cho thấy mô hình tuyến tính huấn luyện theo SPO+ có thể vượt qua các bộ dự đoán phức tạp hơn nhưng chỉ tối ưu sai số dự đoán khi mô hình bị chỉ định sai (misspecified).&lt;/p&gt;

&lt;p&gt;Đây là tinh thần của Chương 01 ở dạng cô đọng: viết ra mục tiêu &lt;em&gt;thực sự&lt;/em&gt; (chất lượng quyết định), rồi thay thế bằng một bài toán quy hoạch lồi có thể giải hiệu quả.&lt;/p&gt;

&lt;h2 id=&quot;công-bằng-như-bài-toán-tối-ưu-có-ràng-buộc&quot;&gt;Công bằng như bài toán tối ưu có ràng buộc&lt;/h2&gt;

&lt;p&gt;Các tiêu chí công bằng theo nhóm — như demographic parity, equalized odds và các biến thể liên quan — thực chất là các &lt;em&gt;ràng buộc&lt;/em&gt; trên bộ phân loại chứ không chỉ là khẩu hiệu trình bày. Agarwal, Beygelzimer, Dudík, Langford và Wallach (&lt;em&gt;A Reductions Approach to Fair Classification&lt;/em&gt;, &lt;a href=&quot;https://proceedings.mlr.press/v80/agarwal18a.html&quot;&gt;ICML 2018&lt;/a&gt;) quy bài toán “cực tiểu hóa sai số phân loại dưới các bất đẳng thức công bằng” về một dãy các bài toán phân loại nhạy chi phí. Đối tượng cốt lõi ở đây là tập khả thi gồm các bộ phân loại (ngẫu nhiên hóa) thỏa mãn ràng buộc công bằng; phép quy về tìm một điểm có sai số thấp trong tập đó.&lt;/p&gt;

&lt;p&gt;Cơ chế quy về này là nền tảng của thư viện đang được duy trì &lt;a href=&quot;https://fairlearn.org/&quot;&gt;Fairlearn&lt;/a&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExponentiatedGradient&lt;/code&gt; và các ràng buộc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Moment&lt;/code&gt;; tài liệu hướng dẫn: &lt;a href=&quot;https://fairlearn.org/v0.12/user_guide/mitigation/reductions.html&quot;&gt;reductions&lt;/a&gt;). Bộ công cụ này vẫn xuất hiện phổ biến trong các đồ án giai đoạn 2024–2026 và các quy trình kiểm toán công bằng trong công nghiệp. Dù bài báo gốc công bố năm 2018 (trước mốc 2022–2026), đây vẫn là tài liệu chuẩn mà phần mềm hiện hành trích dẫn và triển khai.&lt;/p&gt;

&lt;p&gt;Một mô hình phác thảo — không hàm ý rằng sai số và ràng buộc công bằng luôn lồi — có dạng:&lt;/p&gt;

\[\begin{align}
\min_h \quad &amp;amp; \widehat{\mathrm{err}}(h) \\
\text{s.t.} \quad &amp;amp; \bigl|\Pr(\hat{Y}=1\mid A=a) - \Pr(\hat{Y}=1\mid A=a&apos;)\bigr| \le \epsilon
\end{align}\]

&lt;p&gt;với \(A\) là thuộc tính nhạy cảm. Chương 02 sẽ phân tích khi nào tập ràng buộc là tập lồi, còn Chương 04 sẽ giải thích vì sao nghiệm địa phương của phiên bản lồi hóa cũng là nghiệm toàn cục.&lt;/p&gt;

&lt;h2 id=&quot;cách-đọc-một-bài-báo-tối-ưu-hóa-cho-khoa-học-dữ-liệu&quot;&gt;Cách đọc một bài báo “tối ưu hóa cho khoa học dữ liệu”&lt;/h2&gt;

&lt;p&gt;Hãy đặt bốn câu hỏi nền tảng mà chương này trang bị: Biến quyết định là gì? Hàm mục tiêu mà tác giả &lt;em&gt;thực sự&lt;/em&gt; quan tâm là gì, và hàm thay thế (surrogate) họ thực sự cực tiểu hóa là gì? Tập khả thi có dạng nào (hình hộp, đơn hình, bất đẳng thức công bằng hay bao lồi nguyên)? Bài toán có lồi không, và nếu không thì bài toán con nào bên trong là lồi? Chinchilla, SPO và Fairlearn là ba cách trả lời khác nhau cho chính bốn câu hỏi này.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;J. Hoffmann và cộng sự, “Training Compute-Optimal Large Language Models,” NeurIPS 2022. &lt;a href=&quot;https://proceedings.neurips.cc/paper/2022/hash/c1e2faff6f588870935f114ebe04a3e5-Abstract-Conference.html&quot;&gt;tóm tắt&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2203.15556&quot;&gt;arXiv:2203.15556&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;A. N. Elmachtoub và P. Grigas, “Smart ‘Predict, then Optimize’,” &lt;em&gt;Management Science&lt;/em&gt; 68(1):9–26, 2022. &lt;a href=&quot;https://doi.org/10.1287/mnsc.2020.3922&quot;&gt;DOI&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/1710.08005&quot;&gt;arXiv:1710.08005&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;A. Agarwal, A. Beygelzimer, M. Dudík, J. Langford và H. Wallach, “A Reductions Approach to Fair Classification,” ICML 2018. &lt;a href=&quot;https://proceedings.mlr.press/v80/agarwal18a.html&quot;&gt;PMLR&lt;/a&gt; · &lt;a href=&quot;https://fairlearn.org/v0.12/user_guide/mitigation/reductions.html&quot;&gt;Fairlearn reductions&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>00-05 Ứng dụng và phát triển gần đây</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_05_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_05_Applications_Recent</id>
   <content type="html">&lt;p&gt;Nhiều sinh viên sau khi học xong đạo hàm dây chuyền, hạng ma trận và phân phối chuẩn thường tự hỏi: &lt;em&gt;“Những công thức thế kỷ 18–19 này thực sự làm gì bên trong các mô hình AI tạo sinh năm 2024–2026?”&lt;/em&gt; Câu trả lời có thể khiến bạn bất ngờ: ba đột phá đình đám nhất gần đây — &lt;strong&gt;vi phân tự động (autodiff)&lt;/strong&gt;, &lt;strong&gt;tinh chỉnh hạng thấp LoRA&lt;/strong&gt; và &lt;strong&gt;mô hình khuếch tán (diffusion models)&lt;/strong&gt; — đều là ứng dụng trực tiếp, tinh tế của đúng những kiến thức nền trong Chương 00.&lt;/p&gt;

&lt;p&gt;Bài đọc mở rộng này bắc cây cầu từ các khái niệm đại học cơ bản sang những kiến trúc tối ưu hóa đang chạy trên các hệ thống AI hiện đại nhất.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-công-cụ-chương-00-trong-hệ-thống-ai-hiện-đại&quot;&gt;Kiến thức cần nhớ: Công cụ Chương 00 trong hệ thống AI hiện đại&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc dây chuyền → Vi phân tự động chế độ ngược (Reverse-mode Autodiff):&lt;/strong&gt; Thay vì tính riêng từng đạo hàm riêng (tốn \(\mathcal{O}(n)\) lượt chạy), lan truyền ngược tích lũy sản phẩm vector–Jacobian để lấy toàn bộ gradient \(\nabla_\theta L\) chỉ trong &lt;strong&gt;một&lt;/strong&gt; lượt đi ngược với chi phí tương đương lượt đi xuôi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hạng ma trận (Low-rank Factorization) → LoRA:&lt;/strong&gt; Thay vì cập nhật toàn bộ ma trận trọng số khổng lồ \(W \in \mathbb{R}^{d \times k}\), ta đóng băng \(W_0\) và chỉ tối ưu phần bù hạng thấp \(\Delta W = BA\) với \(r \ll \min(d, k)\), cắt giảm bộ nhớ và chi phí tối ưu hàng chục đến hàng trăm lần.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient của log-mật độ → Score Matching &amp;amp; Mô hình khuếch tán:&lt;/strong&gt; Học trực tiếp trường vector score \(\nabla_x \log p_t(x)\) để đảo ngược quá trình thêm nhiễu Gauss từng bước, biến nhiễu trắng thành ảnh hoặc âm thanh chân thực.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-một-lượt-autodiff-ngược-và-đếm-tham-số-lora&quot;&gt;Giải thích: Tính tay một lượt Autodiff ngược và đếm tham số LoRA&lt;/h3&gt;

&lt;p&gt;Hãy kiểm chứng bằng hai phép tính tay gọn gàng:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Autodiff chế độ ngược cho hàm mất mát \(L(w) = (wx - y)^2\)&lt;/strong&gt; tại \(x = 2,\ w = 3,\ y = 10\):
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Lượt xuôi (Forward):&lt;/em&gt; \(z = wx = 3 \cdot 2 = 6\); sai số \(e = z - y = 6 - 10 = -4\); mất mát \(L = e^2 = 16\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Lượt ngược (Backward):&lt;/em&gt;
\(\frac{\partial L}{\partial e} = 2e = -8, \qquad \frac{\partial L}{\partial z} = \frac{\partial L}{\partial e}\cdot 1 = -8, \qquad \frac{\partial L}{\partial w} = \frac{\partial L}{\partial z}\cdot x = (-8)\cdot 2 = -16.\)
Dấu âm \(-16\) báo hiệu cần tăng \(w\) để kéo \(z=6\) tiến gần \(y=10\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiết kiệm tham số của LoRA trên một lớp tuyến tính \(1024 \times 1024\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tinh chỉnh toàn phần \(W_0 \in \mathbb{R}^{1024 \times 1024}\): cần tối ưu \(1024 \times 1024 = 1{,}048{,}576\) tham số.&lt;/li&gt;
      &lt;li&gt;Tinh chỉnh LoRA với hạng \(r = 8\) (\(B \in \mathbb{R}^{1024 \times 8},\ A \in \mathbb{R}^{8 \times 1024}\)): số tham số cần học chỉ là:
\(1024 \times 8 + 8 \times 1024 = 16{,}384 \text{ tham số},\)
tức chỉ bằng \(\frac{16{,}384}{1{,}048{,}576} = \frac{1}{64} \approx 1.56\%\) — tiết kiệm tới &lt;strong&gt;\(98.44\%\)&lt;/strong&gt; số biến tối ưu!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Giải tích, đại số tuyến tính và xác suất trong chương này không chỉ là phần “khởi động” rồi bỏ qua; đó là ngôn ngữ làm việc trực tiếp của các mô hình bạn sẽ huấn luyện ngay từ những tuần đầu tiên. Bài đọc này kết nối các công cụ đó với bốn hướng phát triển giai đoạn 2022–2025 mà sinh viên khoa học dữ liệu thường gặp trong bài báo khoa học, thư viện mã nguồn và thực tập. Phần lý thuyết ở các bài trước không thay đổi; mục tiêu ở đây là chỉ ra &lt;em&gt;vị trí&lt;/em&gt; của gradient, phân tích hạng thấp và hàm score trong các hệ thống thực tế.&lt;/p&gt;

&lt;h2 id=&quot;vi-phân-tự-động-và-gradient-ẩn&quot;&gt;Vi phân tự động và gradient ẩn&lt;/h2&gt;

&lt;p&gt;Lan truyền ngược thực chất là quy tắc dây chuyền áp dụng trên đồ thị tính toán. Các thư viện hiện đại triển khai &lt;em&gt;vi phân tự động&lt;/em&gt; (automatic differentiation): bạn viết hàm Python \(f\), thư viện tự động tính \(\nabla f\) mà không cần viết tay ma trận Jacobian. Chuyên khảo năm 2024–2025 của Blondel và Roulet, &lt;em&gt;The Elements of Differentiable Programming&lt;/em&gt; (&lt;a href=&quot;https://arxiv.org/abs/2403.14606&quot;&gt;arXiv:2403.14606&lt;/a&gt;), xem đây là một mô hình lập trình hoàn chỉnh chứ không chỉ là kỹ thuật tính toán: miễn là chương trình được cấu thành từ các phép toán cơ bản khả vi, việc tối ưu tham số bằng gradient vẫn được định nghĩa chặt chẽ, ngay cả khi có cấu trúc điều khiển.&lt;/p&gt;

&lt;p&gt;Một ứng dụng tinh tế hơn của giải tích Chương 00 là &lt;strong&gt;định lý hàm ẩn&lt;/strong&gt;. Khi bộ giải trả về nghiệm \(x^\star(\theta)\) thỏa mãn điều kiện tối ưu \(F(x,\theta)=0\) (chẳng hạn \(\nabla_x L(x,\theta)=0\)), ta &lt;strong&gt;không&lt;/strong&gt; cần lan truyền ngược qua toàn bộ các vòng lặp bên trong. Lấy vi phân đồng nhất thức \(F(x^\star(\theta),\theta)=0\) dẫn đến hệ phương trình tuyến tính&lt;/p&gt;

\[\nabla_\theta x^\star = - \bigl(\nabla_x F\bigr)^{-1} \nabla_\theta F.\]

&lt;p&gt;Blondel, Berthet, Cuturi, Frostig, Hoyer, Llinares-López, Pedregosa và Vert triển khai cơ chế này thành &lt;em&gt;vi phân ẩn tự động&lt;/em&gt; trong thư viện JAXopt (&lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/228b9279ecf9bbafe582406850c57115-Abstract-Conference.html&quot;&gt;NeurIPS 2022&lt;/a&gt;; &lt;a href=&quot;https://github.com/google/jaxopt&quot;&gt;github.com/google/jaxopt&lt;/a&gt;). Người dùng chỉ cần định nghĩa ánh xạ \(F\) bằng Python; JAX tự động lấy vi phân của \(F\) và giải hệ tuyến tính tương ứng. Các bài toán chọn siêu tham số cho hồi quy ridge, học siêu tham số (meta-learning) và các tầng tối ưu đều quy về đồng nhất thức này. Khi học đến điều kiện tối ưu bậc nhất ở Chương 04, hãy quay lại đọc đoạn này: chính điều kiện \(\nabla f(x)=0\) là biểu thức được tuyến tính hóa trong vi phân ẩn.&lt;/p&gt;

&lt;h2 id=&quot;cập-nhật-hạng-thấp-lora-dưới-góc-nhìn-đại-số-tuyến-tính&quot;&gt;Cập nhật hạng thấp: LoRA dưới góc nhìn đại số tuyến tính&lt;/h2&gt;

&lt;p&gt;Tinh chỉnh (fine-tune) mô hình ngôn ngữ lớn bằng cách cập nhật toàn bộ phần tử của ma trận trọng số \(W_0\in\mathbb{R}^{d\times k}\) tiêu tốn rất nhiều bộ nhớ và dung lượng lưu trữ cho từng tác vụ. Hu, Shen, Wallis, Allen-Zhu, Li, Wang, Wang và Chen (&lt;em&gt;LoRA&lt;/em&gt;, &lt;a href=&quot;https://openreview.net/forum?id=nZeVKeeFYf9&quot;&gt;ICLR 2022&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2106.09685&quot;&gt;arXiv:2106.09685&lt;/a&gt;) giữ cố định \(W_0\) và chỉ học một phần hiệu chỉnh hạng \(r\):&lt;/p&gt;

\[W = W_0 + BA, \qquad B\in\mathbb{R}^{d\times r},\; A\in\mathbb{R}^{r\times k},\; r\ll \min(d,k).\]

&lt;p&gt;Số tham số cần huấn luyện giảm từ \(dk\) xuống còn \(r(d+k)\). Trên mô hình cỡ GPT-3, bài báo ghi nhận số tham số huấn luyện giảm đi nhiều bậc độ lớn mà không làm tăng độ trễ suy luận, vì tích \(BA\) có thể gộp trực tiếp vào \(W_0\) sau khi huấn luyện. Kiến thức đại số tuyến tính ở Chương 00 giúp kiểm chứng ngay khẳng định này: hạng ma trận, chi phí phép nhân ma trận và ý tưởng rằng phép cập nhật có cấu trúc có thể nằm gọn trong một không gian con số chiều nhỏ. Các thư viện adapter trên Hugging Face (PEFT) được xây dựng trên nền phân tích này kết hợp với kỹ thuật hệ thống.&lt;/p&gt;

&lt;h2 id=&quot;score-matching-và-mô-hình-khuếch-tán&quot;&gt;Score matching và mô hình khuếch tán&lt;/h2&gt;

&lt;p&gt;Các mô hình sinh ảnh bằng cách khử nhiễu Gauss từng bước về bản chất là một bài toán xác suất. Gọi \(p_t\) là họ mật độ xác suất đã được làm mượt theo mức nhiễu và \(s_\theta(x,t)\) là mạng xấp xỉ hàm &lt;em&gt;score&lt;/em&gt; \(\nabla_x \log p_t(x)\). Quá trình huấn luyện cực tiểu hóa sai số hồi quy có trọng số trên hàm score; quá trình sinh mẫu quy về giải phương trình vi phân thường (ODE) hoặc phương trình vi phân ngẫu nhiên (SDE) dẫn hướng bởi \(s_\theta\). Karras, Aittala, Aila và Laine (&lt;em&gt;Elucidating the Design Space of Diffusion-Based Generative Models&lt;/em&gt;, &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/a98846e9d9cc01cfb87eb694d946ce6b-Abstract-Conference.html&quot;&gt;NeurIPS 2022&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2206.00364&quot;&gt;arXiv:2206.00364&lt;/a&gt;; mã nguồn &lt;a href=&quot;https://github.com/NVlabs/edm&quot;&gt;NVlabs/edm&lt;/a&gt;) thống nhất nhiều biến thể khuếch tán phổ biến vào chung một không gian thiết kế gồm tiền điều kiện mạng, lịch nhiễu và bộ lấy mẫu, đạt chỉ số FID \(1.79\) trên CIFAR-10 có điều kiện lớp chỉ với 35 lần đánh giá mạng và trở thành bản triển khai tham chiếu.&lt;/p&gt;

&lt;p&gt;Những kiến thức Chương 00 cần dùng ở đây hoàn toàn cụ thể và vừa sức: gradient của log-mật độ, phân phối chuẩn Gauss và góc nhìn giải tích về ODE/SDE. Ta chưa cần đến toàn bộ lý thuyết giải tích ngẫu nhiên để hiểu vì sao quy trình “dự đoán nhiễu rồi cập nhật bước Euler” thực chất là một phương pháp số trên trường score.&lt;/p&gt;

&lt;h2 id=&quot;kiểm-tra-số-nhỏ-kích-thước-tham-số-lora&quot;&gt;Kiểm tra số nhỏ (kích thước tham số LoRA)&lt;/h2&gt;

&lt;p&gt;Đoạn mã dưới đây không huấn luyện Transformer mà chỉ kiểm tra số lượng tham số của phân tích hạng thấp đúng như công thức LoRA nêu trên. Bạn có thể chạy thử sau khi ôn lại phép nhân ma trận ở bài 00-02.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4096&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4096&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;full&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lora&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;full params:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;LoRA params:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lora&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ratio:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lora&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;W0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;W&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;W0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;W shape:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rank bound:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;điểm-cốt-lõi-cần-ghi-nhớ&quot;&gt;Điểm cốt lõi cần ghi nhớ&lt;/h2&gt;

&lt;p&gt;Khi một bài báo viết “vi phân qua ánh xạ KKT”, “chèn adapter hạng \(r\)” hay “khớp hàm score của nhiễu Gauss”, đó đều là ứng dụng trực tiếp của các khái niệm trong Chương 00. Các chương tiếp theo sẽ bổ sung tính lồi, dạng chuẩn và thuật toán tối ưu, nhưng tất cả đều đứng trên nền tảng đạo hàm, phân tích ma trận và mật độ xác suất.&lt;/p&gt;

&lt;h2 id=&quot;nguồn&quot;&gt;Nguồn&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;M. Blondel và V. Roulet, &lt;em&gt;The Elements of Differentiable Programming&lt;/em&gt;, arXiv:2403.14606, 2024 (sửa 2025). &lt;a href=&quot;https://arxiv.org/abs/2403.14606&quot;&gt;https://arxiv.org/abs/2403.14606&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;M. Blondel và cộng sự, “Efficient and Modular Implicit Differentiation,” NeurIPS 2022. &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/228b9279ecf9bbafe582406850c57115-Abstract-Conference.html&quot;&gt;bài báo&lt;/a&gt; · &lt;a href=&quot;https://github.com/google/jaxopt&quot;&gt;JAXopt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;E. J. Hu và cộng sự, “LoRA: Low-Rank Adaptation of Large Language Models,” ICLR 2022. &lt;a href=&quot;https://openreview.net/forum?id=nZeVKeeFYf9&quot;&gt;OpenReview&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2106.09685&quot;&gt;arXiv:2106.09685&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;T. Karras, M. Aittala, T. Aila và S. Laine, “Elucidating the Design Space of Diffusion-Based Generative Models,” NeurIPS 2022. &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/a98846e9d9cc01cfb87eb694d946ce6b-Abstract-Conference.html&quot;&gt;tóm tắt&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2206.00364&quot;&gt;arXiv:2206.00364&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>29-04 Modern federated applications</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter29/29_04_modern_federated/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter29/29_04_modern_federated</id>
   <content type="html">&lt;p&gt;Once Lesson 29-02 exposed client drift under non-IID data, the 2020–2026 federated learning community set out to fix FedAvg without sacrificing its simplicity. Three algorithmic pillars emerged—and together they transformed federated learning into a clinical workhorse for cross-silo healthcare, where hospitals collaborate on cancer imaging and genomics without ever moving protected patient records off-premise: &lt;strong&gt;FedProx&lt;/strong&gt; (a proximal leash), &lt;strong&gt;SCAFFOLD&lt;/strong&gt; (SVRG-style control variates for client drift), and &lt;strong&gt;FedOpt / FedAdam&lt;/strong&gt; (adaptive server-side optimization).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-taming-non-iid-heterogeneity-fedprox-scaffold-fedadam&quot;&gt;Key ideas: Taming Non-IID Heterogeneity (FedProx, SCAFFOLD, FedAdam)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;FedProx (Proximal Leash):&lt;/strong&gt; Adds \(\frac{\mu}{2}\|w - w_t\|_2^2\) to each client’s local objective, penalizing local iterates from wandering too far from the global broadcast \(w_t\)—simple, stateless, and tolerant of variable local work across heterogeneous devices.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SCAFFOLD (Control Variates for Client Drift):&lt;/strong&gt; Borrows Chapter 26’s SVRG trick directly into federated learning! Each client maintains a local control variate \(c_i\) and receives the global average \(c = \frac{1}{P}\sum_j c_j\), correcting every local gradient to \(\nabla F_i(w) - c_i + c\)—eliminating client drift completely!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;FedOpt / FedAdam (Server-Side Adaptivity):&lt;/strong&gt; Treats the averaged client weight delta $$\Delta_t = \frac{1}{&lt;/td&gt;
          &lt;td&gt;\mathcal{S}_t&lt;/td&gt;
          &lt;td&gt;}\sum_{i \in \mathcal{S}&lt;em&gt;t}(w&lt;/em&gt;{t+1}^{(i)} - w_t)\(as a *pseudo-gradient* on the server and feeds\)-\Delta_t$$ into Adam or Yogi—stabilizing training on non-IID vision and language tasks without extra client memory.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cross-Silo Healthcare &amp;amp; Privacy Governance:&lt;/strong&gt; In multi-hospital radiology and EHR consortiums (10–100 reliable institutions), cross-silo FL pairs FedProx/FedAdam with secure aggregation and differential privacy to satisfy HIPAA/GDPR while pooling statistical power across rare diseases.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-how-scaffold-cancels-non-iid-client-drift-in-one-step&quot;&gt;Worked example: How SCAFFOLD Cancels Non-IID Client Drift in One Step&lt;/h3&gt;

&lt;p&gt;Return to our 2-client non-IID problem \(F_1(w) = 2(w - 1)^2\) and \(F_2(w) = \frac{1}{2}(w + 1)^2\) (global optimum \(w^\star = 0.6\)). Suppose we are at \(w_t = 0.6\), and the control variates have tracked the local gradients at \(w_t\):
\(c_1 = F_1&apos;(0.6) = -1.6, \qquad c_2 = F_2&apos;(0.6) = +1.6, \qquad c = \frac{c_1 + c_2}{2} = 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute Client 1’s SCAFFOLD-corrected local gradient at \(w = 0.6\):&lt;/strong&gt;
\(g_1^{\text{SCAFFOLD}} = F_1&apos;(0.6) - c_1 + c = (-1.6) - (-1.6) + 0 = 0!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute Client 2’s SCAFFOLD-corrected local gradient at \(w = 0.6\):&lt;/strong&gt;
\(g_2^{\text{SCAFFOLD}} = F_2&apos;(0.6) - c_2 + c = (+1.6) - (+1.6) + 0 = 0!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with FedProx (\(\mu = 4\)) at \(w_t = 0.6\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Under FedProx, Client 1 minimizes \(2(w - 1)^2 + \frac{4}{2}(w - 0.6)^2 \implies 4(w - 1) + 4(w - 0.6) = 0 \implies w_1^{(1)} = 0.8\) (reduced drift from \(1.0\) down to \(0.8\), though not zero).&lt;/li&gt;
      &lt;li&gt;Under SCAFFOLD, &lt;em&gt;every&lt;/em&gt; local step at \(w^\star = 0.6\) has &lt;strong&gt;exact zero gradient&lt;/strong&gt;—proving how control variates cancel client drift completely just like SVRG cancels minibatch noise!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lessons 29-01 to 29-03 already own data-parallel SGD, &lt;strong&gt;FedAvg&lt;/strong&gt;, and the ADMM contrast. This optional note is the 2020–2026 &lt;em&gt;application&lt;/em&gt; layer: what to do when clients are non-IID (FedProx, SCAFFOLD), how adaptive server steps enter (FedOpt), and where the methods actually run (cross-silo healthcare). It does not re-derive the FedAvg three-step loop.&lt;/p&gt;

&lt;h2 id=&quot;1-fedprox-a-proximal-leash-on-local-drift&quot;&gt;1. FedProx: a proximal leash on local drift&lt;/h2&gt;

&lt;p&gt;Li, Sahu, Zaheer, Sanjabi, Talwalkar, and Smith, &lt;em&gt;Federated Optimization in Heterogeneous Networks&lt;/em&gt;, MLSys 2020, &lt;a href=&quot;https://proceedings.mlsys.org/paper_files/paper/2020/hash/1f5fe83998a09396ebe6477d9475ba0c-Abstract.html&quot;&gt;proceedings.mlsys.org&lt;/a&gt;, replace the local objective \(F_c(w)\) by&lt;/p&gt;

\[F_c(w)+\frac{\mu}{2}\|w-w_t\|_2^2.\]

&lt;p&gt;That is a proximal term toward the broadcast global model — the same &lt;em&gt;idea&lt;/em&gt; as an augmented-Lagrangian penalty, without a dual variable. FedProx is the first paper to read after FedAvg when client systems drop out and local data are non-IID. It is &lt;strong&gt;not&lt;/strong&gt; ADMM (no dual ascent, no residual certificate); Chapter 29-03 already made that distinction. Use \(\mu&amp;gt;0\) as a robustness knob, not as a proof that you have consensus.&lt;/p&gt;

&lt;h2 id=&quot;2-scaffold-control-variates-for-client-drift&quot;&gt;2. SCAFFOLD: control variates for client drift&lt;/h2&gt;

&lt;p&gt;Karimireddy, Kale, Mohri, Reddi, Stich, and Suresh, &lt;em&gt;SCAFFOLD: Stochastic Controlled Averaging for Federated Learning&lt;/em&gt;, ICML 2020, &lt;a href=&quot;https://proceedings.mlr.press/v119/karimireddy20a.html&quot;&gt;PMLR v119&lt;/a&gt;, keep a &lt;em&gt;control variate&lt;/em&gt; on the server and on each client so that local SGD is corrected by an estimate of the client-gradient bias \((\nabla F_c-\nabla F)\). Communication per round grows by one extra vector; the payoff is a rate that does not explode with the number of local steps \(E\). If FedAvg is “hope the average of drifted models is fine,” SCAFFOLD is “subtract the estimated drift.” Variance-reduction students (26-05) will recognize the move.&lt;/p&gt;

&lt;h2 id=&quot;3-fedopt--fedadam-the-server-is-allowed-to-be-adam&quot;&gt;3. FedOpt / FedAdam: the server is allowed to be Adam&lt;/h2&gt;

&lt;p&gt;Reddi, Charles, Zaheer, Garrett, Rush, Konečný, Kumar, and McMahan, &lt;em&gt;Adaptive Federated Optimization&lt;/em&gt;, ICLR 2021, &lt;a href=&quot;https://openreview.net/forum?id=LkFG3lB13U5&quot;&gt;OpenReview&lt;/a&gt;, treat the &lt;em&gt;pseudo-gradient&lt;/em&gt; \(w_t-\bar w_{t+1}\) (the averaged client delta) as an observation and apply Adam / Yogi / Adagrad &lt;strong&gt;on the server&lt;/strong&gt;. Clients can stay on SGD; the adaptive preconditioner lives where memory is cheap. Combined with FedAvg-style local steps this is often called FedAdam. It is the Chapter 26 optimizer, lifted one level up the hierarchy — a useful exam question: &lt;em&gt;who&lt;/em&gt; holds \(\hat m,\hat v\)?&lt;/p&gt;

&lt;h2 id=&quot;4-healthcare-the-application-that-made-fl-mandatory&quot;&gt;4. Healthcare: the application that made FL mandatory&lt;/h2&gt;

&lt;p&gt;Cross-silo medical imaging and EHR prediction are why federated methods left the mobile-keyboard paper. Guan, Yap, Bozoki, and Liu, &lt;em&gt;Federated learning for medical image analysis: A survey&lt;/em&gt;, &lt;em&gt;Pattern Recognition&lt;/em&gt; 151:110424, 2024, &lt;a href=&quot;https://doi.org/10.1016/j.patcog.2024.110424&quot;&gt;doi:10.1016/j.patcog.2024.110424&lt;/a&gt;, is the imaging map (tumour segmentation, chest X-rays, missing modalities). Nguyen et al., &lt;em&gt;Federated Learning for Smart Healthcare: A Survey&lt;/em&gt;, &lt;em&gt;ACM Comput. Surv.&lt;/em&gt; 55(3), 2022, and the 2025 CSBJ review (250+ papers, 2019–2024, &lt;a href=&quot;https://doi.org/10.1016/j.csbj.2025.06.009&quot;&gt;doi:10.1016/j.csbj.2025.06.009&lt;/a&gt;) catalogue system architecture, horizontal vs vertical partition, and which aggregator (FedAvg / FedProx / SCAFFOLD / FedAdam) deployments actually used. The optimization lesson is sober: FedAvg is still the default &lt;em&gt;implementation&lt;/em&gt;; FedProx and SCAFFOLD are the default &lt;em&gt;answers&lt;/em&gt; when a hospital’s class balance does not match another’s; formal privacy (DP-SGD, secure aggregation) is a different course, as 29-02 already warned.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Extra idea&lt;/th&gt;
      &lt;th&gt;Extra communication&lt;/th&gt;
      &lt;th&gt;When to try&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;FedAvg (29-02)&lt;/td&gt;
      &lt;td&gt;average weights after \(E\) local steps&lt;/td&gt;
      &lt;td&gt;one model / round&lt;/td&gt;
      &lt;td&gt;baseline, IID-ish&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FedProx&lt;/td&gt;
      &lt;td&gt;proximal \(\mu\) toward \(w_t\)&lt;/td&gt;
      &lt;td&gt;same as FedAvg&lt;/td&gt;
      &lt;td&gt;dropouts, mild non-IID&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SCAFFOLD&lt;/td&gt;
      &lt;td&gt;client/server control variates&lt;/td&gt;
      &lt;td&gt;\(+1\) vector / client&lt;/td&gt;
      &lt;td&gt;strong client drift&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FedAdam&lt;/td&gt;
      &lt;td&gt;Adam on the server pseudo-gradient&lt;/td&gt;
      &lt;td&gt;same as FedAvg (+ server state)&lt;/td&gt;
      &lt;td&gt;adaptive server, cheap clients&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FedADMM (21-08)&lt;/td&gt;
      &lt;td&gt;dual residuals&lt;/td&gt;
      &lt;td&gt;same order&lt;/td&gt;
      &lt;td&gt;when you want a primal-dual certificate&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Reuse the 3-client, one-class-each MNIST (or 2-D Gaussian) split from 29-02. Run \(E=5\) local steps with (i) FedAvg, (ii) FedProx at two \(\mu\), (iii) a &lt;em&gt;cartoon&lt;/em&gt; SCAFFOLD that subtracts a running mean of each client’s gradient from the local step. Plot global test accuracy versus rounds, not versus local steps. Write four sentences on which method shrinks the oscillation you saw in 29-02.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;H. B. McMahan et al., AISTATS 2017 — FedAvg (already required).&lt;/li&gt;
  &lt;li&gt;T. Li et al., MLSys 2020 — FedProx.&lt;/li&gt;
  &lt;li&gt;S. P. Karimireddy et al., ICML 2020 — SCAFFOLD.&lt;/li&gt;
  &lt;li&gt;S. Reddi et al., ICLR 2021 — FedOpt / FedAdam.&lt;/li&gt;
  &lt;li&gt;H. Guan et al., &lt;em&gt;Pattern Recognition&lt;/em&gt; 151:110424, 2024 — medical imaging FL.&lt;/li&gt;
  &lt;li&gt;D. C. Nguyen et al., &lt;em&gt;ACM Comput. Surv.&lt;/em&gt; 55(3), 2022 — smart-healthcare FL.&lt;/li&gt;
  &lt;li&gt;CSBJ 2025 survey, &lt;a href=&quot;https://doi.org/10.1016/j.csbj.2025.06.009&quot;&gt;doi:10.1016/j.csbj.2025.06.009&lt;/a&gt; — 2019–2024 system review.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>28-04 Modern landscape case studies</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_04_modern_landscapes/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_04_modern_landscapes</id>
   <content type="html">&lt;p&gt;Textbook nonconvexity paints a bleak picture of disconnected, treacherous local traps. Yet empirical deep learning between 2018 and 2026 uncovered four astonishing geometric phenomena that rewrote our intuition: independently trained minima are connected by zero-barrier valleys (&lt;strong&gt;mode connectivity&lt;/strong&gt;), networks can suddenly generalize long after memorizing training data (&lt;strong&gt;grokking&lt;/strong&gt;), test error drops a second time past the interpolation threshold (&lt;strong&gt;double descent&lt;/strong&gt;), and flatter Hessian basins correlate strongly with robustness (&lt;strong&gt;flat minima &amp;amp; SAM&lt;/strong&gt;).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-empirical-phenomena-of-deep-loss-landscapes&quot;&gt;Key ideas: Four Empirical Phenomena of Deep Loss Landscapes&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Linear &amp;amp; Nonlinear Mode Connectivity:&lt;/strong&gt; Two neural nets trained from independent random seeds can be connected by a low-loss curve (Garipov et al. 2018)—and after aligning hidden-neuron permutation symmetries (Git Re-Basin, Ainsworth et al. 2023), often by a &lt;em&gt;straight line&lt;/em&gt; with nearly zero loss barrier!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Grokking (Delayed Generalization):&lt;/strong&gt; On algorithmic tasks (e.g., modular arithmetic), AdamW first drives training loss to zero via memorization while validation accuracy sits at random chance; hundreds of epochs later, weight decay slowly prunes the memorizing circuit in favor of a lower-norm generalizing circuit, causing validation accuracy to jump abruptly to 100%.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Double Descent:&lt;/strong&gt; Plotting test error against model capacity \(d\) reveals the classical U-shaped bias–variance curve up to the interpolation peak \(d \approx n\) (where ill-conditioned matrices amplify label noise), followed by a &lt;em&gt;second descent&lt;/em&gt; for \(d \gg n\) as minimum-norm interpolation smooths the fit.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Flat Minima &amp;amp; Hessian Sharpness:&lt;/strong&gt; A minimum with small top Hessian eigenvalue \(\lambda_{\max}(\nabla^2 F(w^\star))\) tolerates distribution shifts (small shifts in the loss surface) with far smaller test-loss degradation than a razor-sharp minimum.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-quantifying-a-flat-vs-sharp-minimum-under-distribution-shift&quot;&gt;Worked example: Quantifying a Flat vs. Sharp Minimum Under Distribution Shift&lt;/h3&gt;

&lt;p&gt;Suppose test loss is simply training loss shifted horizontally by a small distribution shift \(\Delta = 0.2\): \(F_{\text{test}}(w) = F_{\text{train}}(w - 0.2)\). Compare two zero-loss minima—one &lt;strong&gt;flat&lt;/strong&gt; and one &lt;strong&gt;sharp&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Flat basin around \(w_A^\star = 0\): \(F_A(w) = \frac{1}{2}(1)\, w^2\) (curvature \(\lambda_A = 1\)).&lt;/li&gt;
  &lt;li&gt;Sharp basin around \(w_B^\star = 0\): \(F_B(w) = \frac{1}{2}(100)\, w^2\) (curvature \(\lambda_B = 100\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate training loss at both minima:&lt;/strong&gt;
\(F_A(0) = 0, \qquad F_B(0) = 0.\)
On training data, both solutions look &lt;strong&gt;100% identical&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate test loss under the \(\Delta = 0.2\) distribution shift:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Flat minimum: \(F_{A,\text{test}}(0) = \frac{1}{2}(1)(0 - 0.2)^2 = 0.02\).&lt;/li&gt;
      &lt;li&gt;Sharp minimum: \(F_{B,\text{test}}(0) = \frac{1}{2}(100)(0 - 0.2)^2 = 2.00\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Under the exact same distribution shift, the sharp minimum suffers &lt;strong&gt;100× worse&lt;/strong&gt; test degradation—illustrating quantitatively why sharpness-aware optimizers (like SAM) and large-step SGD bias toward flatter basins.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lessons 28-01 to 28-03 defined critical points, saddles, and overparameterization. This optional note is four &lt;em&gt;empirical&lt;/em&gt; phenomena that those definitions were meant to unlock. It does not re-prove that high-dimensional saddles dominate, and it does not re-derive the PL inequality.&lt;/p&gt;

&lt;h2 id=&quot;1-mode-connectivity-minima-are-not-islands&quot;&gt;1. Mode connectivity: minima are not islands&lt;/h2&gt;

&lt;p&gt;Garipov, Izmailov, Podoprikhin, Vetrov, and Wilson (NeurIPS 2018) and Draxler, Veschgini, Salmhofer, and Hamprecht (ICML 2018) showed that two SGD solutions of a deep net can be joined by a low-loss &lt;em&gt;polygonal&lt;/em&gt; path — often two linear segments — on which the train loss stays almost constant. Frankle, Dziugaite, Roy, and Carbin (ICML 2020) tied the same picture to the lottery-ticket literature. The 2025 refinement (entropic confinement, &lt;a href=&quot;https://arxiv.org/abs/2512.06297&quot;&gt;arXiv:2512.06297&lt;/a&gt;) is the student-level punchline: the path can be low-&lt;em&gt;loss&lt;/em&gt; and still high-&lt;em&gt;curvature&lt;/em&gt; in the middle, so noisy SGD stays in one basin even though a deterministic path to another basin exists. Connectivity is a statement about the &lt;em&gt;sublevel set&lt;/em&gt;; confinement is a statement about &lt;em&gt;dynamics&lt;/em&gt;. Chapter 28 needs both.&lt;/p&gt;

&lt;h2 id=&quot;2-grokking-generalization-long-after-interpolation&quot;&gt;2. Grokking: generalization long after interpolation&lt;/h2&gt;

&lt;p&gt;Power, Burda, Edwards, Babuschkin, and Misra, &lt;em&gt;Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2201.02177&quot;&gt;arXiv:2201.02177&lt;/a&gt;, 2022, train small transformers on modular arithmetic. Training accuracy hits 100% quickly; &lt;em&gt;validation&lt;/em&gt; accuracy stays at chance for orders of magnitude more steps, then jumps. The landscape interpretation that belongs in this chapter: interpolation (train loss \(\approx 0\)) is not the end of training. The optimizer keeps moving &lt;em&gt;inside&lt;/em&gt; the interpolating set, and the implicit bias of Chapter 28-03 eventually picks a generalizing point. Weight decay (AdamW, 26-04) is empirically necessary for grokking on these tasks — another reminder that the optimizer is part of the inductive bias.&lt;/p&gt;

&lt;h2 id=&quot;3-double-descent-now-a-landscape-fact&quot;&gt;3. Double descent, now a landscape fact&lt;/h2&gt;

&lt;p&gt;Belkin, Hsu, Ma, and Mandal, &lt;em&gt;PNAS&lt;/em&gt; 2019, and Nakkiran, Kaplun, Bansal, Yang, Barak, and Sutskever, ICLR 2020 (preprint 2019, &lt;a href=&quot;https://arxiv.org/abs/1912.02292&quot;&gt;arXiv:1912.02292&lt;/a&gt;), showed that test error can &lt;em&gt;rise&lt;/em&gt; at the interpolation threshold and then &lt;em&gt;fall&lt;/em&gt; again as the model grows. Overparameterization (28-03) is not a pathology; it is the second half of that curve. The 2022–2024 follow-ups (epoch-wise double descent, data-wise double descent) are the same geometry with a different axis. When a student says “more parameters overfit,” the figure to draw is double descent, not a U-curve from 1990s statistics.&lt;/p&gt;

&lt;h2 id=&quot;4-flat-minima-and-sam-seen-from-the-hessian&quot;&gt;4. Flat minima and SAM, seen from the Hessian&lt;/h2&gt;

&lt;p&gt;Foret et al., ICLR 2021 (SAM; details in &lt;a href=&quot;/contents/en/chapter26/26_06_modern_optimizers/&quot;&gt;26-06&lt;/a&gt;) is an &lt;em&gt;algorithm&lt;/em&gt; that prefers flat regions. Bartlett, Long, and Bousquet, &lt;em&gt;JMLR&lt;/em&gt; 24(43), 2023, and Shin, Lee, Andriushchenko, and Lee, &lt;a href=&quot;https://arxiv.org/abs/2311.17539&quot;&gt;arXiv:2311.17539&lt;/a&gt;, make it a &lt;em&gt;landscape&lt;/em&gt; statement: linearly stable SAM minima have a more uniform Hessian spectrum, and the generalization gap between SAM and SGD &lt;em&gt;widens&lt;/em&gt; as the net becomes more overparameterized. You do not need to implement SAM to use this section. You need to stop saying “a local minimum is a local minimum.” In an interpolating deep net, minima differ by sharpness, and sharpness is a Hessian (or PAC-Bayes) story, not a first-order one.&lt;/p&gt;

&lt;p&gt;Open &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/loss_function_landscapes.html&quot;&gt;loss_function_landscapes.html&lt;/a&gt; and look at a 2-D slice: the same low loss can sit in a ravine or a bowl. That cartoon is the whole of 28-04.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; (i) On a 2-D random-ReLU net, take two SGD solutions and plot the loss along the linear path \(w(t)=(1-t)w_A+t w_B\). You will usually see a barrier (linear paths are the &lt;em&gt;wrong&lt;/em&gt; connectors). (ii) Insert a bend \(w_{1/2}= (w_A+w_B)/2 + v\) and minimize the barrier over a small \(v\) — a poor person’s mode-connectivity search. (iii) Read Power et al. Figure 1 and write three sentences on why train accuracy is the wrong stopping rule for that plot.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;T. Garipov et al., NeurIPS 2018; F. Draxler et al., ICML 2018 — mode connectivity.&lt;/li&gt;
  &lt;li&gt;J. Frankle et al., ICML 2020 — connectivity and lottery tickets.&lt;/li&gt;
  &lt;li&gt;Entropic confinement, &lt;a href=&quot;https://arxiv.org/abs/2512.06297&quot;&gt;arXiv:2512.06297&lt;/a&gt;, 2025.&lt;/li&gt;
  &lt;li&gt;A. Power et al., &lt;a href=&quot;https://arxiv.org/abs/2201.02177&quot;&gt;arXiv:2201.02177&lt;/a&gt;, 2022 — grokking.&lt;/li&gt;
  &lt;li&gt;M. Belkin et al., &lt;em&gt;PNAS&lt;/em&gt; 2019; P. Nakkiran et al., ICLR 2020 — double descent.&lt;/li&gt;
  &lt;li&gt;P. Foret et al., ICLR 2021; P. L. Bartlett et al., &lt;em&gt;JMLR&lt;/em&gt; 24(43), 2023 — SAM / flat minima.&lt;/li&gt;
  &lt;li&gt;S. Shin, D. Lee, M. Andriushchenko, N. Lee, &lt;a href=&quot;https://arxiv.org/abs/2311.17539&quot;&gt;arXiv:2311.17539&lt;/a&gt; — SAM and overparameterization.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>27-04 Autodiff frameworks and scientific ML</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_04_autodiff_frameworks/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_04_autodiff_frameworks</id>
   <content type="html">&lt;p&gt;Knowing the chain rule on a whiteboard is only half the story; turning it into a system that differentiates ten-thousand-layer transformers or coupled Navier–Stokes solvers at terabytes per second is a triumph of compiler engineering. Modern AD splits into three distinct software paradigms—PyTorch’s dynamic tape plus &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.compile&lt;/code&gt;, JAX’s pure-functional composable JVPs/VJPs (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grad&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vmap&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jit&lt;/code&gt;), and Enzyme’s compiler-level differentiation directly on LLVM IR—each tailored to different scientific and ML workloads.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-modern-autodiff-software-ecosystem-20222026&quot;&gt;Key ideas: The Modern Autodiff Software Ecosystem (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;PyTorch (Dynamic Tape + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.compile&lt;/code&gt;):&lt;/strong&gt; Records operations dynamically in eager mode for effortless debugging, then uses TorchDynamo and Inductor (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.compile&lt;/code&gt;) to capture static subgraphs and fuse backward kernels directly into Triton/CUDA code.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;JAX (Functional Program Transformations):&lt;/strong&gt; Treats differentiation as pure higher-order transformations: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.jvp&lt;/code&gt; (forward), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.vjp&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.grad&lt;/code&gt; (reverse), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.vmap&lt;/code&gt; (vectorization), and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.jit&lt;/code&gt; (XLA compilation). Because transformations compose cleanly, Hessian-vector products are a 1-line &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jvp(grad(f))&lt;/code&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enzyme (Differentiating LLVM IR):&lt;/strong&gt; Instead of operator overloading in Python, Enzyme differentiates &lt;em&gt;after&lt;/em&gt; the C++/Rust/Julia compiler has already optimized loops and memory layout—delivering dramatic speedups on legacy scientific simulation codebases.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scientific ML &amp;amp; PINNs:&lt;/strong&gt; Physics-Informed Neural Networks differentiate a neural network \(u_\theta(x, t)\) with respect to its &lt;em&gt;spatial/temporal inputs&lt;/em&gt; (often 2nd order via forward-over-reverse AD) to penalize PDE residuals directly inside the loss.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-an-exact-hessian-vector-product-in-o1-passes-forward-over-reverse&quot;&gt;Worked example: Computing an Exact Hessian-Vector Product in \(O(1)\) Passes (Forward-over-Reverse)&lt;/h3&gt;

&lt;p&gt;Suppose \(f(x_1, x_2) = x_1^3 + 2 x_1 x_2^2\) at \(x = (1, 2)^\top\), and we need the Hessian-vector product \(H(x) v\) for \(v = (1, -1)^\top\) &lt;strong&gt;without&lt;/strong&gt; ever forming the \(d \times d\) Hessian matrix (critical when \(d = 10^8\)!).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Reverse-mode inner map gives the gradient function:&lt;/strong&gt;
\(g(x_1, x_2) = \nabla f(x_1, x_2) = \bigl(3 x_1^2 + 2 x_2^2,\ 4 x_1 x_2\bigr)^\top.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply forward-mode JVP to \(g\) at \(x = (1, 2)\) with tangent \(\dot{x} = v = (1, -1)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;First component tangent: \(\frac{d}{dt}(3 x_1^2 + 2 x_2^2) = 6 x_1 \dot{x}_1 + 4 x_2 \dot{x}_2 = 6(1)(1) + 4(2)(-1) = 6 - 8 = -2\).&lt;/li&gt;
      &lt;li&gt;Second component tangent: \(\frac{d}{dt}(4 x_1 x_2) = 4 \dot{x}_1 x_2 + 4 x_1 \dot{x}_2 = 4(1)(2) + 4(1)(-1) = 8 - 4 = 4\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Verify against explicit Hessian:&lt;/strong&gt; $$H(1, 2) = \begin{pmatrix} 6 x_1 &amp;amp; 4 x_2 \ 4 x_2 &amp;amp; 4 x_1 \end{pmatrix}\big&lt;/td&gt;
          &lt;td&gt;_{(1,2)} = \begin{pmatrix} 6 &amp;amp; 8 \ 8 &amp;amp; 4 \end{pmatrix}\(, so\)H(1,2)\begin{pmatrix} 1 \ -1 \end{pmatrix} = \begin{pmatrix} -2 \ 4 \end{pmatrix}\(. Forward-over-reverse (`jvp(grad(f))`) computes this exact vector in a single pass with\)O(d)\(memory instead of\)O(d^2)$$!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lessons 27-01 to 27-03 are the mathematics: computational graphs, forward-mode JVPs, reverse-mode VJPs / backprop. This optional note is where those modes live in &lt;em&gt;software&lt;/em&gt; in 2022–2026. Baydin, Pearlmutter, Radul, and Siskind, &lt;em&gt;JMLR&lt;/em&gt; 18(153), 2018, &lt;a href=&quot;https://www.jmlr.org/papers/v18/17-468.html&quot;&gt;jmlr.org/papers/v18/17-468.html&lt;/a&gt;, remains the survey on your desk; the frameworks below are the ones you will actually import.&lt;/p&gt;

&lt;h2 id=&quot;1-pytorch-tape-reverse-mode-then-compile&quot;&gt;1. PyTorch: tape reverse-mode, then compile&lt;/h2&gt;

&lt;p&gt;Paszke et al., &lt;em&gt;Automatic differentiation in PyTorch&lt;/em&gt; (NIPS Autodiff workshop, 2017) and the later &lt;em&gt;PyTorch: An Imperative Style, High-Performance Deep Learning Library&lt;/em&gt; (NeurIPS 2019) built reverse-mode AD on a dynamic tape: run the forward Python, record &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grad_fn&lt;/code&gt;, play the tape backward. That is 27-03 with an allocator. &lt;strong&gt;PyTorch 2.0&lt;/strong&gt; (2023) added &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.compile&lt;/code&gt; (TorchDynamo + Inductor): the same reverse-mode graph is captured, compiled, and still differentiated. For this course the rule is unchanged. If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.autograd.grad&lt;/code&gt; disagrees with your hand-written adjoint, your graph or your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;detach&lt;/code&gt; is wrong — not the definition of a derivative. Use PyTorch when the model is a dynamic net, the ecosystem is vision / LLM, and you want a tape you can print.&lt;/p&gt;

&lt;h2 id=&quot;2-jax-composable-jvps-and-vjps&quot;&gt;2. JAX: composable JVPs and VJPs&lt;/h2&gt;

&lt;p&gt;Bradbury, Frostig, Hawkins, Johnson, Leary, Maclaurin, Necula, Paszke, VanderPlas, Wanderman-Milne, and Zhang, &lt;em&gt;JAX: composable transformations of Python+NumPy programs&lt;/em&gt;, 2018–, &lt;a href=&quot;https://github.com/google/jax&quot;&gt;github.com/google/jax&lt;/a&gt;, treat &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grad&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vmap&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jit&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pmap&lt;/code&gt; as &lt;em&gt;function transformations&lt;/em&gt;. Forward-mode &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.jvp&lt;/code&gt; and reverse-mode &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.vjp&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.grad&lt;/code&gt; are the two modes of this chapter, exposed as first-class APIs. Arrays are immutable; the program you differentiate is a pure function. That restriction is why scientific-ML groups (physics-informed nets, molecular potentials, differentiable simulators) standardized on JAX in 2022–2026: you can &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vmap&lt;/code&gt; a simulation and then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grad&lt;/code&gt; the residual. Use JAX when you need nested JVPs/VJPs, batching, or a compiler (XLA) more than a pretrained-model zoo.&lt;/p&gt;

&lt;h2 id=&quot;3-enzyme-differentiate-after-the-compiler&quot;&gt;3. Enzyme: differentiate after the compiler&lt;/h2&gt;

&lt;p&gt;Moses and Churavy, &lt;em&gt;Instead of rewriting foreign code for machine learning, automatically synthesize fast gradients&lt;/em&gt;, NeurIPS 2020, run reverse-mode AD on &lt;strong&gt;LLVM IR&lt;/strong&gt;, so C++, Fortran, Julia, and Rust become differentiable without a source rewrite. Moses, Churavy, Paehler, et al., &lt;em&gt;Reverse-Mode Automatic Differentiation and Optimization of GPU Kernels via Enzyme&lt;/em&gt;, SC 2021, and Moses, Narayanan, Paehler, et al., &lt;em&gt;Scalable Automatic Differentiation of Multiple Parallel Paradigms&lt;/em&gt;, SC 2022, extend the same idea to CUDA, OpenMP, MPI, and Julia tasks. Enzyme-JAX (2023–) registers those kernels as JAX primitives, so &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.grad&lt;/code&gt; can see a Fortran heat solver. This is the 2020s answer to “our production simulator is not a PyTorch module.”&lt;/p&gt;

&lt;h2 id=&quot;4-scientific-machine-learning--pinns&quot;&gt;4. Scientific machine learning / PINNs&lt;/h2&gt;

&lt;p&gt;A physics-informed network minimizes a residual \(r_\theta(x)=\mathcal{L}[u_\theta](x)\) whose derivatives w.r.t. &lt;em&gt;inputs&lt;/em&gt; \(x\) (not only parameters \(\theta\)) come from AD. Raissi, Perdikaris, and Karniadakis, &lt;em&gt;J. Comput. Phys.&lt;/em&gt; 378:686–707, 2019, is the classic; Karniadakis, Kevrekidis, Lu, Perdikaris, Wang, and Yang, &lt;em&gt;Nature Reviews Physics&lt;/em&gt; 3:422–440, 2021, is the survey that made PINNs a data-science topic. The 2022–2025 wave (better causal/weighted residuals, operator learning, hybrid Enzyme+JAX simulators) still stands on reverse-mode in \(\theta\) and often &lt;em&gt;forward-mode&lt;/em&gt; or nested reverse in \(x\). That is why Chapter 27 taught both modes: a PINN is the example where “one scalar loss, millions of parameters” is &lt;em&gt;not&lt;/em&gt; the only AD query.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# JAX: reverse-mode for parameters, forward-mode JVP if you need a directional derivative
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loss&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loss&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ones&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# VJP, one scalar
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jvp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;jvp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;jnp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ones&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),))&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# directional
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Implement \(f(w)=\|Aw-b\|_2^2\) in NumPy, PyTorch, and (if installed) JAX. Compare &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2 A.T @ (A@w-b)&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.autograd&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.grad&lt;/code&gt;. Then time a &lt;em&gt;Jacobian&lt;/em&gt; of an 8-output map with (i) eight reverse-mode calls and (ii) eight forward-mode JVPs — forward should win, which is the 27-02 lesson in software form.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;A. G. Baydin et al., &lt;em&gt;JMLR&lt;/em&gt; 18(153), 2018 — AD survey.&lt;/li&gt;
  &lt;li&gt;A. Paszke et al., NeurIPS 2019 — PyTorch.&lt;/li&gt;
  &lt;li&gt;J. Bradbury et al., 2018– — JAX.&lt;/li&gt;
  &lt;li&gt;W. S. Moses and V. Churavy, NeurIPS 2020; Moses et al., SC 2021 &amp;amp; SC 2022 — Enzyme.&lt;/li&gt;
  &lt;li&gt;M. Raissi, P. Perdikaris, G. E. Karniadakis, &lt;em&gt;J. Comput. Phys.&lt;/em&gt; 378, 2019 — PINNs.&lt;/li&gt;
  &lt;li&gt;G. E. Karniadakis et al., &lt;em&gt;Nat. Rev. Phys.&lt;/em&gt; 3:422–440, 2021 — physics-informed ML survey.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>26-06 Modern adaptive optimizers (seminar)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_06_modern_optimizers/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_06_modern_optimizers</id>
   <content type="html">&lt;p&gt;AdamW has reigned as the default deep-learning optimizer since 2019, yet every frontier lab keeps asking the same question: can we exploit &lt;em&gt;geometry&lt;/em&gt; beyond diagonal second moments without paying the prohibitive \(O(d^2)\) cost of full Newton’s method? Between 2020 and 2026, three distinct geometric ideas broke through into practical training loops: &lt;strong&gt;SAM&lt;/strong&gt; (seek flat basins via a minimax step), &lt;strong&gt;Sophia&lt;/strong&gt; (clip a cheap diagonal Hessian estimator), and &lt;strong&gt;Muon&lt;/strong&gt; (orthogonalize 2D hidden-layer weight updates via Newton–Schulz iterations).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-beyond-diagonal-adamw-sam-sophia-muon-schedule-free&quot;&gt;Key ideas: Beyond Diagonal AdamW (SAM, Sophia, Muon, Schedule-Free)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;SAM (Sharpness-Aware Minimization):&lt;/strong&gt; Solves the minimax objective \(\min_w \max_{\|\epsilon\|_2 \le \rho} F(w + \epsilon)\) by first ascending to the worst nearby perturbation \(\hat{\epsilon} = \rho \frac{\nabla F(w)}{\|\nabla F(w)\|_2}\), then stepping with \(\nabla F(w + \hat{\epsilon})\)—trading \(2\times\) gradient cost for flatter, better-generalizing minima.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sophia (Clipped Diagonal Second-Order):&lt;/strong&gt; Replaces Adam’s squared-gradient denominator with a Hutchinson or Gauss–Newton diagonal Hessian estimate \(h_t\) and clips the Newton step \(\operatorname{clip}(m_t / \max(h_t, \varepsilon), \pm 1)\), preventing explosions near nonconvex saddle points where curvature turns negative.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Muon (Matrix Orthogonalization via Newton–Schulz):&lt;/strong&gt; Recognizes that hidden-layer weights are &lt;em&gt;matrices&lt;/em&gt;, not flat vectors. Instead of diagonal rescaling, Muon maps the momentum matrix \(M_t\) toward its nearest orthogonal polar factor \(U V^\top\) using fast matrix-multiply Newton–Schulz iterations—equalizing singular-value step sizes across all matrix directions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Schedule-Free Optimization:&lt;/strong&gt; Eliminates the need to pre-commit to a total training horizon \(T\) (for cosine decay) by interpolating between a momentum iterate and an online average, matching tuned cosine schedules automatically.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-sam-minimax-step-vs-one-muon-polar-orthogonalization&quot;&gt;Worked example: One SAM Minimax Step vs. One Muon Polar Orthogonalization&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Part A (SAM on a 1D asymmetric valley):&lt;/strong&gt; Suppose \(F(w)\) has gradient \(F&apos;(w_0) = 1.0\) at \(w_0 = 0\), and sharpness radius \(\rho = 0.2\).&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Ascend to the adversarial perturbation: $$\hat{\epsilon} = \rho \frac{F’(0)}{&lt;/td&gt;
          &lt;td&gt;F’(0)&lt;/td&gt;
          &lt;td&gt;} = 0.2 \cdot (+1) = +0.2\(, giving\)w_{\text{adv}} = 0.2$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;Evaluate gradient at the perturbed point: suppose \(F&apos;(0.2) = 3.0\) (steep wall on the right!).&lt;/li&gt;
  &lt;li&gt;Apply the SAM update (\(\eta = 0.1\)) from the &lt;em&gt;original&lt;/em&gt; \(w_0\):
\(w_1 = w_0 - \eta F&apos;(w_{\text{adv}}) = 0 - 0.1(3.0) = -0.3,\)
pushing \(3\times\) harder away from the sharp cliff than vanilla GD (\(-0.1\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Part B (Muon polar orthogonalization on a \(2 \times 2\) momentum matrix):&lt;/strong&gt; Suppose a hidden-layer momentum matrix is \(M = \begin{pmatrix} 10 &amp;amp; 0 \\ 0 &amp;amp; 0.1 \end{pmatrix}\) (singular values \(10\) and \(0.1\)—condition number \(100\)).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Its polar factor \(U V^\top\) replaces all nonzero singular values with \(1\):
\(\operatorname{orth}(M) = \begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;Every singular direction now receives unit step magnitude, preventing the dominant singular direction from drowning out subtle orthogonal feature directions!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lessons 26-01 to 26-05 are the assessed stack: SGD, Distill-style momentum, AdaGrad → Adam, &lt;strong&gt;AdamW&lt;/strong&gt;, and SVRG / SAGA. This optional seminar is the 2021–2026 optimizer zoo at &lt;em&gt;algorithm&lt;/em&gt; depth — one recurrence each, not a second AdamW lecture. &lt;a href=&quot;/contents/en/chapter26/26_04_adamw_and_practice/&quot;&gt;26-04&lt;/a&gt; already owns decoupled weight decay. The Hessian-preconditioner story of Sophia as a Newton cousin lives in &lt;a href=&quot;/contents/en/chapter14/14_10_modern_applications/&quot;&gt;14-10&lt;/a&gt;; here we only need the &lt;em&gt;update&lt;/em&gt;, so we can place SAM, Sophia, and Muon on the same board as AdamW. None of the three is assessed this term.&lt;/p&gt;

&lt;p&gt;The question is: &lt;em&gt;what did people actually train large models with after AdamW became the default, and what extra geometry does each method buy?&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;adamw-remains-the-baseline&quot;&gt;AdamW remains the baseline&lt;/h2&gt;

&lt;p&gt;Loshchilov and Hutter, ICLR 2019, &lt;a href=&quot;https://arxiv.org/abs/1711.05101&quot;&gt;arXiv:1711.05101&lt;/a&gt;, is still the optimizer named in Llama / GPT-style recipes: \(\eta\) in the \(10^{-4}\) range, \(\beta=(0.9,0.95)\) or \((0.9,0.999)\), decoupled \(\lambda\approx 0.1\), warmup then cosine. Every method below is measured &lt;em&gt;against&lt;/em&gt; that recipe. If you can only remember one algorithm from Chapter 26, remember AdamW.&lt;/p&gt;

&lt;h2 id=&quot;sam-a-local-max-then-a-descent&quot;&gt;SAM: a local max, then a descent&lt;/h2&gt;

&lt;p&gt;Sharpness-Aware Minimization (Foret, Kleiner, Mobahi, Neyshabur, ICLR 2021, &lt;a href=&quot;https://openreview.net/forum?id=6Tm1mposlrM&quot;&gt;OpenReview&lt;/a&gt;) replaces the pointwise risk \(F(w)\) by a &lt;em&gt;neighbourhood&lt;/em&gt; worst case&lt;/p&gt;

\[\min_w\ \max_{\|\varepsilon\|_2\le\rho} F(w+\varepsilon)
\approx F\bigl(w+\rho\,\nabla F(w)/\|\nabla F(w)\|_2\bigr).\]

&lt;p&gt;The algorithm is two gradients per step, not a new preconditioner.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Ascent (perturb).&lt;/strong&gt; \(g\leftarrow\nabla F(w)\), then \(\varepsilon\leftarrow\rho\,g/\|g\|_2\) (or a dual-norm cousin).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Descent (SAM gradient).&lt;/strong&gt; Evaluate \(g_{\mathrm{SAM}}\leftarrow\nabla F(w+\varepsilon)\) and step \(w\leftarrow w-\eta\,g_{\mathrm{SAM}}\) (or feed \(g_{\mathrm{SAM}}\) to AdamW / SGD+momentum).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The extra ascent biases the iterate toward &lt;strong&gt;flat&lt;/strong&gt; minima: a small ball around \(w\) still has small loss. Bartlett, Long, and Bousquet, &lt;em&gt;The Dynamics of Sharpness-Aware Minimization&lt;/em&gt;, &lt;em&gt;JMLR&lt;/em&gt; 24(43), 2023, show that near a smooth minimum the extra step is a bounce across the sharpest Hessian direction plus a drift that &lt;em&gt;decreases&lt;/em&gt; \(\|\nabla^2 F\|\). Shin, Lee, Andriushchenko, and Lee (&lt;a href=&quot;https://arxiv.org/abs/2311.17539&quot;&gt;arXiv:2311.17539&lt;/a&gt;) find that SAM’s generalization gain &lt;em&gt;grows&lt;/em&gt; with overparameterization — a bridge to Chapter 28 and to the PL story in &lt;a href=&quot;/contents/en/chapter28/28_05_pl_condition/&quot;&gt;28-05&lt;/a&gt;. SAM is used in vision and some fine-tunes; full LLM pretraining usually skips the doubled gradient cost. Adaptive-radius variants (ASAM, GSAM) change the ball, not the two-step template.&lt;/p&gt;

&lt;h2 id=&quot;sophia-adamw-with-a-clipped-diagonal-hessian&quot;&gt;Sophia: AdamW with a clipped diagonal Hessian&lt;/h2&gt;

&lt;p&gt;Liu, Li, Hall, Liang, and Ma, &lt;em&gt;Sophia&lt;/em&gt;, ICLR 2024, &lt;a href=&quot;https://openreview.net/forum?id=3xHDeA8Noi&quot;&gt;OpenReview&lt;/a&gt;, keep Adam-like first moments but replace the second-moment accumulator by a &lt;em&gt;clipped&lt;/em&gt; diagonal Hessian estimate. Writing \(m\) for the EMA of the gradient and \(\hat h\) for the EMA of a diagonal curvature estimate,&lt;/p&gt;

\[w\leftarrow w-\eta\cdot\operatorname{clip}\bigl(m/(\hat h+\varepsilon),\,\tau\bigr),\]

&lt;p&gt;with \(\hat h\) refreshed only every handful of steps (Hutchinson Hessian–vector products, or a Gauss–Newton–Bartlett estimator that draws a label from the model and squares that gradient). The clip is a trust-region: a stale or indefinite diagonal must not explode the step. Treat Sophia as “AdamW whose denominator knows curvature,” not as full Newton — the affine-invariance and Hessian-factorisation discussion belongs in 14-10. The claim is fewer steps than AdamW on language-model pretraining at a modest extra cost per step.&lt;/p&gt;

&lt;h2 id=&quot;muon-orthogonalize-the-hidden-layer-update&quot;&gt;Muon: orthogonalize the hidden-layer update&lt;/h2&gt;

&lt;p&gt;Jordan, Jin, Boza, Cesista, Newhouse, and Bernstein, &lt;em&gt;Muon&lt;/em&gt;, 2024, &lt;a href=&quot;https://kellerjordan.github.io/posts/muon/&quot;&gt;kellerjordan.github.io/posts/muon&lt;/a&gt;, take Nesterov momentum on each &lt;em&gt;matrix&lt;/em&gt; parameter \(W\in\mathbb{R}^{m\times n}\) and replace the update by its nearest orthogonal matrix, computed by a few Newton–Schulz iterations (no SVD in the inner loop):&lt;/p&gt;

\[\begin{align}
B &amp;amp;\leftarrow \beta B+\nabla_W F,\\
O &amp;amp;\leftarrow \operatorname{NewtonSchulz}(B)\approx\arg\min_{Q^\top Q=I}\|Q-B\|_F,\\
W &amp;amp;\leftarrow W-\eta\,O.
\end{align}\]

&lt;p&gt;Embeddings, heads, and vectors stay on AdamW — a 2-D hidden weight wants an orthogonal step (a rotation of features, roughly constant spectral norm); a token-embedding table does not. NanoGPT speedrunning (late 2024) made Muon the default in that community. Jingyuan Liu et al., &lt;em&gt;Muon is Scalable for LLM Training&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2502.16982&quot;&gt;arXiv:2502.16982&lt;/a&gt;, 2025, add weight decay and a per-parameter scale, train a 3B/16B MoE (Moonlight) on 5.7T tokens, and report about \(2\times\) compute efficiency versus AdamW on a scaling-law plot. Shah et al., &lt;a href=&quot;https://arxiv.org/abs/2505.02222&quot;&gt;arXiv:2505.02222&lt;/a&gt;, 2025, push the Pareto frontier on the compute–time tradeoff up to 4B parameters. This is the first serious &lt;em&gt;matrix-aware&lt;/em&gt; challenger to diagonal AdamW.&lt;/p&gt;

&lt;p&gt;Newton–Schulz itself is a cheap polynomial iteration on \(X^\top X\) that drives singular values toward \(1\). You do not need the coefficients for this course; you need the slogan: &lt;strong&gt;Muon preconditions by polar factor, AdamW preconditions by per-coordinate RMS&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;schedule-free-adamw-pointer&quot;&gt;Schedule-free AdamW (pointer)&lt;/h2&gt;

&lt;p&gt;Defazio and colleagues (2024) propose a &lt;em&gt;schedule-free&lt;/em&gt; AdamW that replaces a decreasing \(\eta_t\) by an implicit Polyak–Ruppert average. Useful as a seminar paper; not a second set of homework knobs. The Chapter 06 optional note &lt;a href=&quot;/contents/en/chapter06/06_08_Applications_Recent/&quot;&gt;06-08&lt;/a&gt; already placed that paper next to Lion and the edge of stability.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Extra work / memory&lt;/th&gt;
      &lt;th&gt;Geometry it adds&lt;/th&gt;
      &lt;th&gt;Typical home (2026)&lt;/th&gt;
      &lt;th&gt;Assessed?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;AdamW&lt;/td&gt;
      &lt;td&gt;two EMAs&lt;/td&gt;
      &lt;td&gt;per-coordinate RMS&lt;/td&gt;
      &lt;td&gt;default LLM / vision&lt;/td&gt;
      &lt;td&gt;yes (26-04)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SAM&lt;/td&gt;
      &lt;td&gt;\(2\times\) gradient&lt;/td&gt;
      &lt;td&gt;flat-minima (inner max)&lt;/td&gt;
      &lt;td&gt;vision, some fine-tunes&lt;/td&gt;
      &lt;td&gt;no&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Sophia&lt;/td&gt;
      &lt;td&gt;cheap diagonal Hessian + clip&lt;/td&gt;
      &lt;td&gt;curvature-aware denominator&lt;/td&gt;
      &lt;td&gt;LM pretraining experiments&lt;/td&gt;
      &lt;td&gt;no&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Muon&lt;/td&gt;
      &lt;td&gt;Newton–Schulz on hidden matrices&lt;/td&gt;
      &lt;td&gt;polar / orthogonal update&lt;/td&gt;
      &lt;td&gt;NanoGPT, some LLM pretrains&lt;/td&gt;
      &lt;td&gt;no&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Exercise (survey, not a bake-off).&lt;/strong&gt; Read the Muon blog’s “use AdamW on embeddings and the head” paragraph and write four sentences: (i) why a 2-D hidden weight wants an orthogonal update, (ii) why the embedding table does not, (iii) how this differs from AdamW’s &lt;em&gt;per-coordinate&lt;/em&gt; \(1/\sqrt{\hat v}\), and (iv) why SAM’s inner max is a &lt;em&gt;landscape&lt;/em&gt; statement (Ch.28) rather than a preconditioner. No training run required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; Which of the three methods still makes sense if you are only allowed &lt;em&gt;one&lt;/em&gt; gradient per step — and which Chapter 26 object (momentum, diagonal second moment, or variance reduction) is it closest to?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;I. Loshchilov and F. Hutter, ICLR 2019 — AdamW.&lt;/li&gt;
  &lt;li&gt;P. Foret, A. Kleiner, H. Mobahi, B. Neyshabur, ICLR 2021 — SAM.&lt;/li&gt;
  &lt;li&gt;P. L. Bartlett et al., &lt;em&gt;JMLR&lt;/em&gt; 24(43), 2023 — SAM dynamics.&lt;/li&gt;
  &lt;li&gt;H. Liu et al., ICLR 2024 — Sophia (update here; Newton reading in 14-10).&lt;/li&gt;
  &lt;li&gt;K. Jordan et al., 2024 — Muon.&lt;/li&gt;
  &lt;li&gt;Jingyuan Liu et al., &lt;a href=&quot;https://arxiv.org/abs/2502.16982&quot;&gt;arXiv:2502.16982&lt;/a&gt;, 2025 — Muon at LLM scale.&lt;/li&gt;
  &lt;li&gt;I. Shah et al., &lt;a href=&quot;https://arxiv.org/abs/2505.02222&quot;&gt;arXiv:2505.02222&lt;/a&gt;, 2025 — Muon pretraining efficiency.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>25-03 Modern applications of MIP in data science</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_03_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_03_modern_applications</id>
   <content type="html">&lt;p&gt;A decade ago, few ML researchers imagined running a Mixed Integer Linear Program &lt;em&gt;inside&lt;/em&gt; deep learning workflows. Today, Chapter 25’s Branch-and-Cut machinery powers three flagship frontiers of trustworthy AI: exact sparse feature selection, &lt;strong&gt;formal verification of ReLU neural networks&lt;/strong&gt; (proving mathematically that no \(\ell_\infty\) adversarial perturbation can flip a classifier’s prediction), and &lt;strong&gt;optimal decision trees&lt;/strong&gt; that outperform greedy CART/C4.5 splits with certified global optimality.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-where-branch-and-cut-meets-modern-machine-learning&quot;&gt;Key ideas: Where Branch-and-Cut Meets Modern Machine Learning&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Exact ReLU Verification via MILP:&lt;/strong&gt; Every ReLU neuron \(h = \max(0, w^\top x + b)\) is piecewise linear with two regimes (active vs. inactive), encoded exactly by one binary variable \(z \in \{0, 1\}\) and tight pre-activation bounds \([l, u]\). Maximizing an adversary’s margin over an \(\ell_\infty\) ball certifies robustness with zero false negatives.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tight Bounds Drive Verification Speed:&lt;/strong&gt; In MILP neural verification, computing tight interval or Crown/alpha-beta-CROWN pre-activation bounds \([l_j, u_j]\) shrinks the triangle relaxation of each ReLU neuron—turning intractable verification into millisecond proofs.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal Classification Trees (OCT):&lt;/strong&gt; Unlike greedy CART, which locks in myopic top splits, encoding tree routing decisions as binary variables optimizes &lt;em&gt;all&lt;/em&gt; splits jointly subject to depth and leaf-count budgets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Learning to Cut:&lt;/strong&gt; Just as ML4CO learns branching heuristics, modern solvers train neural policies to select &lt;em&gt;which&lt;/em&gt; candidate Gomory and MIR cuts from the cut pool yield the largest dual bound lift per simplex pivot.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-exact-milp-encoding-of-one-relu-neuron&quot;&gt;Worked example: Exact MILP Encoding of One ReLU Neuron&lt;/h3&gt;

&lt;p&gt;Suppose a ReLU neuron computes \(y = \max(0, z)\) where the pre-activation input \(z\) is known to lie in \([l, u] = [-2, 4]\). Introduce binary switch \(a \in \{0, 1\}\) (\(a = 1\) means active, \(a = 0\) means inactive).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the 4 exact MILP inequalities (the tight triangle relaxation):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(y \ge 0\),&lt;/li&gt;
      &lt;li&gt;\(y \ge z\),&lt;/li&gt;
      &lt;li&gt;\(y \le u \cdot a = 4 a\),&lt;/li&gt;
      &lt;li&gt;\(y \le z - l(1 - a) = z + 2(1 - a)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify both binary states:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;If \(a = 0\) (inactive): \(y \ge 0\) and \(y \le 0 \implies y = 0\); meanwhile \(y \ge z\) forces \(z \le 0\), and \(0 \le z + 2 \iff z \ge -2\) (valid!).&lt;/li&gt;
      &lt;li&gt;If \(a = 1\) (active): \(y \ge z\) and \(y \le z \implies y = z\); meanwhile \(y \ge 0\) forces \(z \ge 0\), and \(z \le 4\) (valid!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the continuous relaxation at \(z = 1\):&lt;/strong&gt; Setting \(a \in [0, 1]\) allows \(y\) to lie inside the triangle bounded above by the chord connecting \((-2, 0)\) and \((4, 4)\), namely \(y \le \frac{4}{6}(z + 2) = \frac{2}{3}(1 + 2) = 2\). Tightening \([l, u]\) shrinks this relaxation triangle directly!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chapter 25 is the &lt;em&gt;solver&lt;/em&gt; half of mixed-integer programming: cutting planes, branch-and-cut, and two extended examples (best subset, least quantile). Those techniques are now used to &lt;em&gt;select features&lt;/em&gt;, &lt;em&gt;certify&lt;/em&gt; neural nets, &lt;em&gt;grow optimal trees&lt;/em&gt;, and even &lt;em&gt;learn which cuts&lt;/em&gt; to add. This optional note is the 2022–2026 application layer on top of 25-01 and 25-02; it does not re-derive Gomory cuts.&lt;/p&gt;

&lt;h2 id=&quot;1-best-subset-selection-still-the-mip-poster-child&quot;&gt;1. Best-subset selection, still the MIP poster child&lt;/h2&gt;

&lt;p&gt;The \(\ell_0\)-constrained least-squares problem in 25-02-01 is&lt;/p&gt;

\[\min_\beta\ \tfrac12\|y-X\beta\|_2^2\qquad\text{subject to}\qquad \|\beta\|_0\le k,\]

&lt;p&gt;or the big-\(M\) form with binaries \(z_i\). Bertsimas, King, and Mazumder, &lt;em&gt;Ann. Statist.&lt;/em&gt; 44(2):813–852, 2016, showed that a modern MIP solver plus warm starts can beat the folklore “intractable for \(p&amp;gt;30\).” The 2020s comparison is no longer MIP versus Lasso on a laptop: it is MIP versus pathwise CD (Chapter 23) versus nonconvex penalties (skglm) on \(p\) in the hundreds, with a &lt;em&gt;certificate&lt;/em&gt; when the gap closes. Use Lasso / elastic net to explore; use best-subset MIP when a regulator or a scientist asks for “exactly \(k\) genes” and a bound on suboptimality.&lt;/p&gt;

&lt;h2 id=&quot;2-feature-selection-for-trained-networks&quot;&gt;2. Feature selection for trained networks&lt;/h2&gt;

&lt;p&gt;Zhao, Tsay, and Kronqvist, &lt;em&gt;Model-based feature selection for neural networks: A mixed-integer programming approach&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2302.10344&quot;&gt;arXiv:2302.10344&lt;/a&gt; (2023), encode a trained ReLU net and solve a sequence of MILPs that search for &lt;em&gt;sparse inputs&lt;/em&gt; maximizing class confidence, with cardinality and distribution constraints. On MNIST / Fashion-MNIST they keep about 15% of pixels and retrain a smaller, more attack-robust net. This is best-subset thinking applied to the &lt;em&gt;input&lt;/em&gt;, with the trained network encoded as a piecewise-linear MIP — the same encoding used for verification below.&lt;/p&gt;

&lt;h2 id=&quot;3-verifying-relu-networks-with-milp&quot;&gt;3. Verifying ReLU networks with MILP&lt;/h2&gt;

&lt;p&gt;A ReLU \(h=\max(0,Wx+b)\) is a mixed-integer linear constraint (binary activation, big-\(M\) or a tighter formulation). Asking “does there exist a perturbation of size \(\varepsilon\) that flips the label?” is then a MILP. Tjeng, Xiao, and Tedrake, &lt;em&gt;Evaluating Robustness of Neural Networks with Mixed Integer Programming&lt;/em&gt;, ICLR 2019, &lt;a href=&quot;https://openreview.net/forum?id=HyGIdiRqtm&quot;&gt;OpenReview&lt;/a&gt;, combined a tight encoding with progressive bound tightening and verified MNIST nets with over \(10^5\) units, orders of magnitude beyond the SMT verifier Reluplex. Fischetti and Jo (2018) is the MIP-OR companion. The 2022–2025 literature (stronger ReLU inequalities, dependency analysis, GPU bound propagation) still sits on that formulation. If you understood Gomory and branch-and-cut in this chapter, you can read a verification paper: the “cut” is a linear inequality that a ReLU activation must satisfy.&lt;/p&gt;

&lt;h2 id=&quot;4-optimal-classification-trees-and-learning-to-cut&quot;&gt;4. Optimal classification trees and learning to cut&lt;/h2&gt;

&lt;p&gt;Bertsimas and Dunn, &lt;em&gt;Machine Learning&lt;/em&gt; 106:1039–1082, 2017, write the entire decision tree as a MIP (Optimal Classification Trees, OCT). Hua, Ren, and Cao, NeurIPS 2022 (&lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/37771cc0be272368102a37f202bb88d8-Abstract-Conference.html&quot;&gt;paper&lt;/a&gt;), give a reduced-space branch-and-bound algorithm (RS-OCT) that scales OCT to tables with hundreds of thousands of rows and reports better test accuracy than prior MIP-OCT baselines on large UCI sets. Loss-optimal / logistic trees (TOP, 2024) keep the same MILP backbone and swap the misclassification objective for a piecewise-linear logistic loss.&lt;/p&gt;

&lt;p&gt;On the &lt;em&gt;solver&lt;/em&gt; side, learning to &lt;strong&gt;select cutting planes&lt;/strong&gt; (e.g. HGTSM, &lt;a href=&quot;https://arxiv.org/abs/2410.03112&quot;&gt;arXiv:2410.03112&lt;/a&gt;, 2024) trains a heterogeneous graph model on MIPLIB 2017 and ML4CO instances so that the cut sequence of 25-01 is no longer a hand-written heuristic. That is Chapter 25 looking in a mirror: the cutting-plane algorithm became training data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Encode a 2-layer ReLU toy \(f(x)=W_2\,\mathrm{ReLU}(W_1 x)\) with \(W_1\in\mathbb{R}^{3\times 2}\) as a MILP (binaries for the three hidden units). Maximize \(f(x)_1-f(x)_2\) subject to \(\|x-x_0\|_\infty\le\varepsilon\). If the optimal value is positive, you have a certified adversarial example; if the solver proves a non-positive bound, you have a robustness certificate at \(x_0\). Compare the MIP answer to a projected-gradient attack — the attack can &lt;em&gt;find&lt;/em&gt; a flip, only the MIP can &lt;em&gt;prove&lt;/em&gt; there is none.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;D. Bertsimas, A. King, R. Mazumder, &lt;em&gt;Ann. Statist.&lt;/em&gt; 44(2):813–852, 2016 — best subset via MIP.&lt;/li&gt;
  &lt;li&gt;Model-based feature selection for NNs, &lt;a href=&quot;https://arxiv.org/abs/2302.10344&quot;&gt;arXiv:2302.10344&lt;/a&gt;, 2023.&lt;/li&gt;
  &lt;li&gt;V. Tjeng, K. Xiao, R. Tedrake, ICLR 2019 — MILP robustness verification.&lt;/li&gt;
  &lt;li&gt;M. Fischetti and J. Jo, CPAIOR 2018 — deep nets as MIPs.&lt;/li&gt;
  &lt;li&gt;D. Bertsimas and J. Dunn, &lt;em&gt;Mach. Learn.&lt;/em&gt; 106:1039–1082, 2017 — optimal classification trees.&lt;/li&gt;
  &lt;li&gt;NeurIPS 2022 RS-OCT — scalable global OCT.&lt;/li&gt;
  &lt;li&gt;Learning to select cutting planes, &lt;a href=&quot;https://arxiv.org/abs/2410.03112&quot;&gt;arXiv:2410.03112&lt;/a&gt;, 2024.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>24-06 Modern applications of mixed-integer models</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_06_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_06_modern_applications</id>
   <content type="html">&lt;p&gt;Mixed-integer models are far from dusty textbook exercises—they quietly coordinate the physical backbone of the 2026 economy. Every time an airline builds legal crew pairings across thousands of flights, a logistics platform routes last-mile delivery vans under tight time windows, or a cloud provider places edge compute nodes to meet latency SLAs, an industrial MILP solver is solving a model built from Chapter 24’s exact templates. Even more exciting, modern ML4CO (Machine Learning for Combinatorial Optimization) research now trains graph neural networks to imitate strong branching inside Branch and Bound.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-classic-mip-templates-to-2026-industrial-solvers&quot;&gt;Key ideas: From Classic MIP Templates to 2026 Industrial Solvers&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Set Partitioning for Crew Scheduling:&lt;/strong&gt; Airlines model crew pairing as selecting a minimum-cost subset of legal multi-day pairings such that every flight leg is covered exactly once (\(\sum_p a_{fp} x_p = 1\)), solved at scale via column generation (Branch and Price).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Capacitated Routing &amp;amp; Assignment:&lt;/strong&gt; Last-mile delivery augments classical assignment with vehicle capacity, time windows, and subtour elimination constraints, turning dispatching into a structured MILP solved in rolling real-time horizons.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Facility Location for Edge Infrastructure:&lt;/strong&gt; Choosing which data centers or warehouses to open (\(y_i \in \{0, 1\}\)) and how to route traffic (\(x_{ij}\)) balances capital expenditure against latency constraints using tight disaggregated linking inequalities \(x_{ij} \le y_i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Learning to Branch (ML4CO):&lt;/strong&gt; Because strong branching is accurate but expensive, modern hybrid solvers train bipartite graph neural networks on the constraint-variable incidence graph to predict strong-branching scores in microseconds.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-disaggregated-linking-cuts-beat-aggregated-constraints-in-facility-location&quot;&gt;Worked example: Why Disaggregated Linking Cuts Beat Aggregated Constraints in Facility Location&lt;/h3&gt;

&lt;p&gt;Suppose 1 candidate warehouse (\(y \in \{0, 1\}\)) can serve \(m = 3\) customers (\(x_1, x_2, x_3 \in [0, 1]\)), and currently only customer 1 is assigned to it (\(x_1 = 1, x_2 = 0, x_3 = 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Aggregated linking constraint:&lt;/strong&gt; \(x_1 + x_2 + x_3 \le 3 y\).
    &lt;ul&gt;
      &lt;li&gt;At \((x_1, x_2, x_3) = (1, 0, 0)\), the LP relaxation only requires \(1 \le 3y \implies y \ge 1/3\)! The solver pays just \(1/3\) of the warehouse opening cost in the relaxation.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Disaggregated linking constraints:&lt;/strong&gt; \(x_1 \le y,\ x_2 \le y,\ x_3 \le y\).
    &lt;ul&gt;
      &lt;li&gt;At \((x_1, x_2, x_3) = (1, 0, 0)\), the first inequality immediately forces \(y \ge 1\)—paying &lt;strong&gt;100%&lt;/strong&gt; of the warehouse cost even in the LP relaxation!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Both formulations have the exact same integer solutions, yet disaggregated inequalities eliminate the fractional loophole \(y = 1/3\) completely—a classic modeling lesson that accelerates real-world facility location MIPs by orders of magnitude.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chapter 24 is the &lt;em&gt;modeling&lt;/em&gt; half of mixed-integer programming: binary decisions, assignment, knapsacks, and facility location. Those templates did not stay in textbooks. Crew pairing, last-mile routing, and the placement of warehouses or edge-GPU sites are still solved as MIPs, and since about 2019 a second industry has grown around them: &lt;strong&gt;learning to optimize&lt;/strong&gt; — graph neural nets that propose branches, cuts, or warm starts for a MIP solver. This optional note is four data-science-facing applications. Cutting planes, best-subset selection, and neural-net verification wait for &lt;a href=&quot;/contents/en/chapter25/25_Mixed_integer_programming/&quot;&gt;Chapter 25&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;1-airline-crew-scheduling-still-a-living-mip&quot;&gt;1. Airline crew scheduling, still a living MIP&lt;/h2&gt;

&lt;p&gt;Crew pairing / rostering is an integer program with duty, rest, and fleet constraints. The public instance &lt;strong&gt;air05&lt;/strong&gt; in MIPLIB 2017 (Gleixner, Hendel, Gamrath, et al., &lt;em&gt;Math. Prog. Comput.&lt;/em&gt; 13:443–490, 2021, &lt;a href=&quot;https://doi.org/10.1007/s12532-020-00194-3&quot;&gt;doi:10.1007/s12532-020-00194-3&lt;/a&gt;) is the instance every new branching heuristic is still measured on. A 2025 explainability study (crew-scheduling air05 as a bipartite variable–constraint graph; &lt;a href=&quot;https://arxiv.org/abs/2512.01698&quot;&gt;arXiv:2512.01698&lt;/a&gt;) asks a data-science question that Chapter 24 already prepared: once you &lt;em&gt;model&lt;/em&gt; the MIP, can a GNN embed that graph well enough to replace hand-crafted solver features? The MIP did not go away; it became the &lt;em&gt;label generator&lt;/em&gt; for a learning pipeline.&lt;/p&gt;

&lt;h2 id=&quot;2-assignment-and-last-mile-routing&quot;&gt;2. Assignment and last-mile routing&lt;/h2&gt;

&lt;p&gt;The assignment problem in 24-02 is the linear oracle inside a great deal of modern logistics. Last-mile delivery and on-demand meal routing are vehicle-routing MIPs (or MIP + column generation) with time windows and driver shifts. Toth and Vigo’s &lt;em&gt;Vehicle Routing&lt;/em&gt; monograph is the classical reference; the 2020s twist is that travel times and demand are &lt;em&gt;predicted&lt;/em&gt; by a supervised model, then fed to a MIP that must return a feasible route in minutes. The data scientist owns the forecast; the integer program owns the “one driver, one vehicle, capacity \(Q\)” logic that a neural net will happily violate. That split — learn what you cannot write, optimize what you must certify — is the 2026 default in operations + ML.&lt;/p&gt;

&lt;h2 id=&quot;3-facility-location-for-warehouses-and-edge-compute&quot;&gt;3. Facility location for warehouses and edge compute&lt;/h2&gt;

&lt;p&gt;Facility location (also 24-02) is how platforms decide which fulfillment center, cache, or &lt;strong&gt;GPU inference site&lt;/strong&gt; to open. Binary \(y_j\) opens site \(j\) at cost \(f_j\); continuous (or integer) flows \(x_{ij}\) send demand \(i\) to \(j\). Cloud and edge-ML papers reuse exactly this skeleton: \(f_j\) is rack / license cost, \(c_{ij}\) is latency or egress. The MIP is the same; the “data” in the objective is a learned demand surface. If you can write the 24-02 formulation, you can read those papers.&lt;/p&gt;

&lt;h2 id=&quot;4-learning-to-branch-and-the-ml4co-competition&quot;&gt;4. Learning to branch and the ML4CO competition&lt;/h2&gt;

&lt;p&gt;Gasse, Chételat, Ferroni, Charlin, and Lodi, &lt;em&gt;Exact Combinatorial Optimization with Graph Convolutional Neural Networks&lt;/em&gt;, NeurIPS 2019, taught a GNN to imitate a strong branching expert. The NeurIPS 2021 &lt;strong&gt;ML4CO&lt;/strong&gt; competition (Ecole et al.) turned that idea into a public benchmark: learn primal heuristics, configurations, or branching on families of MIPs. Follow-ups through 2024–2025 learn &lt;em&gt;cut sequences&lt;/em&gt; and even try end-to-end RL solvers; those belong more to Chapter 25 (cutting planes) and are cited there. For this chapter, remember one sentence: a modern MIP application is often a &lt;em&gt;distribution&lt;/em&gt; of instances, and a data-science model sits &lt;em&gt;inside&lt;/em&gt; the branch-and-bound loop of 24-05, it does not replace the integrality constraint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Take the assignment formulation from 24-02 with \(n=8\) random costs. Solve it (i) with a MIP solver or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.optimize.linear_sum_assignment&lt;/code&gt; and (ii) by relaxing \(x_{ij}\in[0,1]\) and rounding. Count how often the LP relaxation is already integral (Birkhoff–von Neumann says &lt;em&gt;always&lt;/em&gt; for a pure assignment — that is the point). Then add one extra inequality, “person 1 cannot do jobs 1–3,” and watch the relaxation need branching. That tiny edit is the difference between a textbook assignment and a crew-pairing MIP.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;A. Gleixner et al., &lt;em&gt;MIPLIB 2017&lt;/em&gt;, &lt;em&gt;Math. Prog. Comput.&lt;/em&gt; 13:443–490, 2021.&lt;/li&gt;
  &lt;li&gt;M. Gasse, D. Chételat, N. Ferroni, L. Charlin, A. Lodi, NeurIPS 2019 — GNN branching.&lt;/li&gt;
  &lt;li&gt;A. Prouvost, A. Chowdhury, et al. / Ecole et al., NeurIPS 2021 ML4CO competition.&lt;/li&gt;
  &lt;li&gt;P. Toth and D. Vigo (eds.), &lt;em&gt;Vehicle Routing: Problems, Methods, and Applications&lt;/em&gt;, SIAM, 2nd ed., 2014.&lt;/li&gt;
  &lt;li&gt;D. Bertsimas and J. Tsitsiklis, &lt;em&gt;Introduction to Linear Optimization&lt;/em&gt; — assignment and facility location as the modeling backbone.&lt;/li&gt;
  &lt;li&gt;Air05 GNN embeddings, &lt;a href=&quot;https://arxiv.org/abs/2512.01698&quot;&gt;arXiv:2512.01698&lt;/a&gt;, 2025 — crew scheduling as a graph-learning instance.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>23-05 Modern applications of coordinate descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_05_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_05_modern_applications</id>
   <content type="html">&lt;p&gt;Pathwise coordinate descent did not freeze in 2010 with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;. Over the past decade, it has evolved into the standard computational backbone for generalized linear models, safe feature-screening rules that provably discard millions of irrelevant predictors before ever touching them, nonconvex sparse penalties in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt;, and dual linear SVMs in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LIBLINEAR&lt;/code&gt;. Whenever a modern statistical package computes a full regularization path in a fraction of a second, you are watching Chapter 23’s coordinate-wise mechanics running under the hood.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-modern-extensions-of-coordinate-descent&quot;&gt;Key ideas: Modern Extensions of Coordinate Descent&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;IRLS + Coordinate Descent for All GLMs:&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; (2023) wraps coordinate descent inside Iteratively Reweighted Least Squares: an outer loop forms a quadratic approximation (working weights and response), and the inner loop solves the weighted Lasso via active-set CD.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gap-Safe Screening Rules:&lt;/strong&gt; Using the duality gap \(G(\beta, \theta)\) between a primal iterate \(\beta\) and a feasible dual vector \(\theta\), gap-safe rules prove that any feature \(j\) inside a safe sphere around \(\theta\) must have \(\beta_j^\star = 0\)—eliminating it permanently from all remaining iterations with &lt;strong&gt;zero&lt;/strong&gt; loss of exactness.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Working Sets Beyond \(\ell_1\) (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt;):&lt;/strong&gt; Modern solvers extend active-set CD to nonconvex and structured penalties (MCP, SCAD, Group Lasso, Sparse-Group Lasso) by maintaining small dynamic working sets and prioritizing features with largest KKT violation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Coordinate Descent for Linear SVMs:&lt;/strong&gt; In &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LIBLINEAR&lt;/code&gt;, minimizing the dual SVM objective subject to box constraints \(0 \le \alpha_i \le C\) updates one dual multiplier \(\alpha_i\) at a time via a clipped 1D Newton step, scaling effortlessly to millions of sparse text features.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-gap-safe-feature-screening-in-action&quot;&gt;Worked example: Gap-Safe Feature Screening in Action&lt;/h3&gt;

&lt;p&gt;Suppose we are solving Lasso \(\min_\beta \frac{1}{2}\|y - X\beta\|_2^2 + \lambda \|\beta\|_1\) with \(\lambda = 2\), unit-norm columns \(\|X_j\|_2 = 1\), current primal-dual gap \(G(\beta, \theta) = 0.08\), and feasible dual point \(\theta = r / \max(\lambda, \|X^\top r\|_\infty)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the safe sphere radius:&lt;/strong&gt; The classic Gap-Safe sphere (Fercoq, Gramfort, Salmon 2015) certifies that the optimal dual variable \(\theta^\star\) lies within Euclidean radius
\(R = \sqrt{\frac{2 G(\beta, \theta)}{\lambda^2}} = \sqrt{\frac{2(0.08)}{2^2}} = \sqrt{0.04} = 0.2\)
of the current dual vector \(\theta\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Apply Cauchy–Schwarz to test feature \(j\):&lt;/strong&gt; By KKT optimality, if $$&lt;/td&gt;
          &lt;td&gt;X_j^\top \theta^\star&lt;/td&gt;
          &lt;td&gt;&amp;lt; 1\(, then necessarily\)\beta_j^\star = 0$$. Using the triangle inequality and Cauchy–Schwarz,&lt;/td&gt;
          &lt;td&gt; &lt;/td&gt;
          &lt;td&gt; &lt;/td&gt;
          &lt;td&gt; &lt;/td&gt;
          &lt;td&gt; &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;$$&lt;/td&gt;
          &lt;td&gt;X_j^\top \theta^\star&lt;/td&gt;
          &lt;td&gt;\le&lt;/td&gt;
          &lt;td&gt;X_j^\top \theta&lt;/td&gt;
          &lt;td&gt;+ |X_j|_2 \cdot |\theta^\star - \theta|_2 \le&lt;/td&gt;
          &lt;td&gt;X_j^\top \theta&lt;/td&gt;
          &lt;td&gt;+ (1)(0.2).$$&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Screen two candidate features:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Feature A&lt;/strong&gt; has $$&lt;/td&gt;
              &lt;td&gt;X_A^\top \theta&lt;/td&gt;
              &lt;td&gt;= 0.65\(: upper bound is\)0.65 + 0.20 = 0.85 &amp;lt; 1\(. **Safely screened out!** We can delete column\)A\(immediately with mathematical certainty that\)\beta_A^\star = 0$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Feature B&lt;/strong&gt; has $$&lt;/td&gt;
              &lt;td&gt;X_B^\top \theta&lt;/td&gt;
              &lt;td&gt;= 0.90\(: upper bound is\)0.90 + 0.20 = 1.10 \ge 1\(. Keep feature\)B\(in the active pool until\)G$$ shrinks further.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Pathwise coordinate descent is the reason the Lasso is a &lt;em&gt;default button&lt;/em&gt; in applied statistics rather than a research prototype. Friedman, Hastie, and Tibshirani’s &lt;strong&gt;glmnet&lt;/strong&gt; (JSS 2010) still ships in R; scikit-learn’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lasso_path&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enet_path&lt;/code&gt; are the same idea in Cython. This optional note updates that story to 2023–2026: glmnet for &lt;em&gt;every&lt;/em&gt; GLM family, screening and working sets at a million features, and the dual CD solver that still trains linear SVMs in production.&lt;/p&gt;

&lt;p&gt;A cyclic (or random) coordinate step on a composite objective \(f(\beta)+ \lambda\|\beta\|_1\) is a scalar soft-threshold. The whole &lt;strong&gt;regularization path&lt;/strong&gt; is a warm-started loop over a decreasing grid \(\lambda_1&amp;gt;\cdots&amp;gt;\lambda_T\). That is the algorithm; the applications below are what practitioners actually run.&lt;/p&gt;

&lt;h2 id=&quot;1-glmnet-for-all-glms-2023&quot;&gt;1. glmnet for all GLMs (2023)&lt;/h2&gt;

&lt;p&gt;Tay, Narasimhan, and Hastie, &lt;em&gt;Elastic Net Regularization Paths for All Generalized Linear Models&lt;/em&gt;, &lt;em&gt;Journal of Statistical Software&lt;/em&gt; 106(1):1–31, 2023, &lt;a href=&quot;https://doi.org/10.18637/jss.v106.i01&quot;&gt;doi:10.18637/jss.v106.i01&lt;/a&gt;, extend glmnet 4.x beyond the built-in Gaussian / binomial / Poisson / Cox families. Any GLM with a smooth log-likelihood now gets a cyclical elastic-net path. Version 4.1 (same codebase, 2021–2023 docs at &lt;a href=&quot;https://glmnet.stanford.edu/&quot;&gt;glmnet.stanford.edu&lt;/a&gt;) adds &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(start, stop)&lt;/code&gt; survival data, strata, and sparse \(X\).&lt;/p&gt;

&lt;p&gt;This is the paper to cite when a student asks “we learned Lasso on least squares — does CD still win for logistic, Cox, or a custom GLM?” Yes, because the IRLS / proximal-Newton outer loop reduces each step to a &lt;em&gt;weighted&lt;/em&gt; least-squares Lasso, and that inner problem is exactly the coordinate descent you already coded in 23-03.&lt;/p&gt;

&lt;h2 id=&quot;2-scikit-learn-paths-and-gap-safe-screening&quot;&gt;2. scikit-learn paths and gap-safe screening&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sklearn.linear_model.lasso_path&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enet_path&lt;/code&gt; (current docs: scikit-learn 1.5–1.9) run Fortran-order coordinate descent with &lt;strong&gt;gap-safe screening rules&lt;/strong&gt;: once the duality gap certifies that a coordinate stays at zero, it is dropped for the rest of that \(\lambda\). The 2025–2026 maintenance PRs (e.g. precomputing residuals and column norms across a path) are not new mathematics; they are the reason a leukemia microarray with \(p\sim 10^4\) genes still fits a 100-point path in seconds. When you write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LassoCV&lt;/code&gt;, you are running Chapter 23, not Adam.&lt;/p&gt;

&lt;h2 id=&quot;3-skglm-working-sets-beyond-ell_1-neurips-2022&quot;&gt;3. skglm: working sets beyond \(\ell_1\) (NeurIPS 2022)&lt;/h2&gt;

&lt;p&gt;Bertrand, Klopfenstein, Blondel, Vaiter, Gramfort, and Massias, &lt;em&gt;Beyond L1: Faster and Better Sparse Models with skglm&lt;/em&gt;, NeurIPS 2022, &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/fe5c31e525e9a26a1426ab0b589f42fe-Abstract-Conference.html&quot;&gt;paper&lt;/a&gt;, push coordinate descent past the glmnet feature set. &lt;strong&gt;Working sets&lt;/strong&gt; iteratively enlarge a small active set; Anderson acceleration (Bertrand &amp;amp; Massias, 2021) gives a practical speedup that Nesterov-on-CD often does not. The package handles MCP / SCAD, group and multitask norms, and custom data-fits — the “nonconvex penalties” bullet already on the 23-00 landing page, now with software you can &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install&lt;/code&gt;. Genomics, vision dictionaries, and M/EEG inverse problems are the running applications in the paper; the optimization claim is that CD plus working sets still dominates full-gradient proximal methods once \(p\) is in the millions.&lt;/p&gt;

&lt;h2 id=&quot;4-dual-coordinate-descent-for-linear-svms&quot;&gt;4. Dual coordinate descent for linear SVMs&lt;/h2&gt;

&lt;p&gt;Hsieh, Chang, Lin, Keerthi, and Sundararajan (ICML 2008) trained a linear SVM by dual coordinate descent; &lt;strong&gt;LIBLINEAR&lt;/strong&gt; is still the solver behind &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sklearn.svm.LinearSVC&lt;/code&gt; and a large fraction of industrial text classifiers. Each dual coordinate is a clipped 1-D quadratic. Nothing about that algorithm became obsolete because transformers arrived: bag-of-words logistic / SVM baselines, click models, and high-dimensional tabular GLMs are still CD’s home turf. Use AdamW (Chapter 26) for a deep net; use glmnet / LIBLINEAR / skglm when the model is &lt;em&gt;generalized linear and sparse&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Pathwise CD is one library call — the algorithm is Chapter 23
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sklearn.linear_model&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lasso_path&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sklearn.datasets&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;make_regression&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;make_regression&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_samples&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_features&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_informative&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;8.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;alphas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coefs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lasso_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# coefs.shape == (n_features, n_alphas); count how late each feature enters
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; On &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make_regression&lt;/code&gt; with \(p=200\), \(n=150\), five informative features, plot the glmnet / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lasso_path&lt;/code&gt; coefficients against \(-\log\lambda\). Then fit the same path with skglm (or a hand-rolled cyclic soft-threshold if you skip the extra dependency) and check that the &lt;em&gt;support&lt;/em&gt; agrees on the cross-validated \(\lambda\). Finally, train &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LinearSVC&lt;/code&gt; on a bag-of-words subset of 20-newsgroups and report wall-clock versus a mini-batch Adam logistic net with the same \(\ell_2\) ball. CD should win on the linear model; Adam should win only after you add a hidden layer.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;J. Friedman, T. Hastie, R. Tibshirani, &lt;em&gt;J. Stat. Softw.&lt;/em&gt; 33(1), 2010 — glmnet pathwise CD.&lt;/li&gt;
  &lt;li&gt;J. K. Tay, B. Narasimhan, T. Hastie, &lt;em&gt;J. Stat. Softw.&lt;/em&gt; 106(1):1–31, 2023 — elastic-net paths for all GLMs.&lt;/li&gt;
  &lt;li&gt;Q. Bertrand et al., NeurIPS 2022 — skglm, working sets, nonconvex sparse models.&lt;/li&gt;
  &lt;li&gt;C.-J. Hsieh et al., ICML 2008 — dual CD for linear SVMs (LIBLINEAR).&lt;/li&gt;
  &lt;li&gt;scikit-learn user guide, &lt;em&gt;Coordinate descent&lt;/em&gt; / gap-safe screening (v1.5+).&lt;/li&gt;
  &lt;li&gt;S. J. Wright, &lt;em&gt;Math. Programming&lt;/em&gt; 151:3–34, 2015 — survey of CD algorithms.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>22-07 Modern applications of Frank–Wolfe</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_07_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_07_modern_applications</id>
   <content type="html">&lt;p&gt;As optimization scales to high-dimensional structured domains—from sequence tagging and unbalanced optimal transport to sparse neural explanations—the bottleneck is rarely computing a gradient; it is enforcing the structural constraint. Projection-free Frank–Wolfe methods turn what would be an intractable quadratic projection into a fast linear oracle, bridging classical 1956 convex optimization with 2024–2026 machine learning pipelines.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-selecting-frankwolfe-in-modern-applied-workflows&quot;&gt;Key ideas: Selecting Frank–Wolfe in Modern Applied Workflows&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Oracle Complexity Asymmetry:&lt;/strong&gt; Frank–Wolfe beats projected gradient descent precisely when the Linear Minimization Oracle is asymptotically cheaper than Euclidean projection (e.g., \(O(d)\) vs. \(O(d \log d)\) on structured polytopes, or top-1 SVD vs. full SVD on trace-norm balls).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Block-Coordinate Scalability:&lt;/strong&gt; Decomposing product constraints \(\mathcal{C} = \mathcal{C}_1 \times \dots \times \mathcal{C}_n\) via Block-Coordinate FW allows stochastic per-example updates while preserving global primal-dual gap certificates.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unbalanced &amp;amp; 1D Optimal Transport:&lt;/strong&gt; In transport problems with relaxed marginal penalties, linear subproblems decompose cleanly over rows/columns or 1D orderings, making conditional gradients competitive with Sinkhorn iterations when exact sparse couplings are preferred over entropic blur.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sparsity-Accuracy Trade-off via Iteration Budget:&lt;/strong&gt; Because each FW step adds at most one atom, stopping early at \(k\) iterations acts simultaneously as computational budgeting and explicit structural regularization (e.g., rank-\(k\) matrices or \(k\)-sparse explanations).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-comparing-lmo-vs-projection-cost-on-a-2-times-2-trace-norm-step&quot;&gt;Worked example: Comparing LMO vs. Projection Cost on a \(2 \times 2\) Trace-Norm Step&lt;/h3&gt;

&lt;p&gt;Suppose we minimize a matrix loss with current iterate \(X_0 = 0 \in \mathbb{R}^{2 \times 2}\) over the trace-norm ball \(\|X\|_{\text{tr}} \le 3\), and the gradient is \(G = \begin{pmatrix} -4 &amp;amp; 0 \\ 0 &amp;amp; -2 \end{pmatrix}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Frank–Wolfe LMO (rank-1 only):&lt;/strong&gt; We only need the largest singular value \(\sigma_1 = 4\) with \(u_1 = (1, 0)^\top\), \(v_1 = (-1, 0)^\top\).
\(S_0 = -3 u_1 v_1^\top = \begin{pmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{pmatrix}.\)
With step size \(\gamma = \frac{1}{2}\), \(X_1^{\text{FW}} = \begin{pmatrix} 1.5 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{pmatrix}\)—strictly &lt;strong&gt;rank 1&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Projected Gradient Step (full SVD + simplex projection):&lt;/strong&gt; With step size \(\eta = 1\), the unprojected step is \(Y = X_0 - G = \begin{pmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}\), whose singular values \((4, 2)\) sum to \(6 &amp;gt; 3\). Projecting \((4, 2)\) onto the \(\ell_1\) ball of radius \(3\) requires soft-thresholding by \(\tau = 1.5\), giving singular values \((2.5, 0.5)\) and \(X_1^{\text{PGD}} = \begin{pmatrix} 2.5 &amp;amp; 0 \\ 0 &amp;amp; 0.5 \end{pmatrix}\)—&lt;strong&gt;rank 2&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Key Takeaway:&lt;/strong&gt; Even on a \(2 \times 2\) toy problem, PGD requires &lt;em&gt;all&lt;/em&gt; singular values and immediately inflates rank, whereas FW needs only the top singular pair and preserves low-rank structure automatically.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Frank–Wolfe (conditional gradient) is the algorithm you reach for when the feasible set \(\mathcal{C}\) has a cheap &lt;strong&gt;linear minimization oracle&lt;/strong&gt;&lt;/p&gt;

\[s_k \in \arg\min_{s\in\mathcal{C}}\ \langle \nabla f(x_k), s\rangle\]

&lt;p&gt;and a &lt;em&gt;projection&lt;/em&gt; onto \(\mathcal{C}\) is expensive or destructive of sparsity. The 2010s revival (Jaggi; Lacoste-Julien) is now a 2020s toolkit: structured prediction, optimal transport, and constrained explanations of neural nets. This optional note is four case studies, not a second convergence proof.&lt;/p&gt;

&lt;h2 id=&quot;1-structured-prediction-block-coordinate-frankwolfe&quot;&gt;1. Structured prediction: block-coordinate Frank–Wolfe&lt;/h2&gt;

&lt;p&gt;A structured-prediction ERM (CRF, structured SVM) has the form&lt;/p&gt;

\[\min_{w}\ \frac{\lambda}{2}\|w\|_2^2 + \frac1n\sum_{i=1}^n \max_{y\in\mathcal{Y}_i}\bigl(\langle w, \phi(x_i,y)\rangle - \delta(y_i,y)\bigr).\]

&lt;p&gt;The dual is optimization over a product of probability simplices — a Cartesian product on which a &lt;strong&gt;block-coordinate Frank–Wolfe (BCFW)&lt;/strong&gt; step is a &lt;em&gt;loss-augmented inference&lt;/em&gt; call, i.e. the same oracle the structured model already implements. Lacoste-Julien, Jaggi, Schmidt, and Pletscher (ICML 2013) is the classical reference; it is still the reason FW appears in structured-prediction code in 2026.&lt;/p&gt;

&lt;p&gt;The same block-coordinate idea moved to &lt;strong&gt;optimal transport&lt;/strong&gt;. Fukunaga and Kasai, &lt;a href=&quot;https://arxiv.org/abs/2205.13766&quot;&gt;arXiv:2205.13766&lt;/a&gt; (2022; conference version ICASSP 2022), apply BCFW — including away-steps and pairwise steps — to a &lt;em&gt;semi-relaxed&lt;/em&gt; OT problem whose tight marginal constraints would otherwise force a full LP. The linear oracle on each block is a closed-form argmin over a simplex; the output coupling is sparse. Their running application is &lt;strong&gt;color transfer&lt;/strong&gt; between images: the transport plan is exactly the kind of sparse, simplex-constrained object FW is designed to keep.&lt;/p&gt;

&lt;h2 id=&quot;2-unbalanced-and-1-d-transport&quot;&gt;2. Unbalanced and 1-D transport&lt;/h2&gt;

&lt;p&gt;Séjourné, Feydy, Vialard, Trouvé, and Peyré (AISTATS 2022, &lt;a href=&quot;https://proceedings.mlr.press/v151/sejourne22a.html&quot;&gt;PMLR v151&lt;/a&gt;) put Frank–Wolfe on the &lt;em&gt;dual&lt;/em&gt; of 1-D unbalanced OT. The linearized subproblem is a &lt;em&gt;balanced&lt;/em&gt; 1-D OT, which is solvable in linear time after a sort. That is the FW contract in one sentence: replace a hard nonlinear program by a linear oracle you already know how to solve. They also compute 1-D barycenters by the same linearization. When the goal is an &lt;em&gt;unregularized&lt;/em&gt; UOT solution, FW can beat Sinkhorn; when you want a smooth, GPU-friendly coupling, Sinkhorn still wins. Students should be able to say &lt;em&gt;why&lt;/em&gt;, not only &lt;em&gt;which&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;3-constrained-explanations-of-neural-nets&quot;&gt;3. Constrained explanations of neural nets&lt;/h2&gt;

&lt;p&gt;Macdonald, Besançon, and Pokutta (ICML 2022, &lt;a href=&quot;https://proceedings.mlr.press/v162/macdonald22a.html&quot;&gt;PMLR v162&lt;/a&gt;) recast &lt;strong&gt;rate-distortion explanations (RDE)&lt;/strong&gt; as a constrained problem and solve it with deterministic and stochastic Frank–Wolfe. Sparsity of a relevance map becomes an \(\ell_1\)-ball (or a simplex) constraint; a &lt;em&gt;feature-ordering&lt;/em&gt; variant optimizes over the &lt;strong&gt;Birkhoff polytope&lt;/strong&gt; (the convex hull of permutation matrices), whose linear oracle is an assignment problem. On image-classification benchmarks the multi-rate and ordering variants beat vanilla RDE. This is structured prediction in disguise: the “structure” is a polytope that encodes a human-readable explanation, and FW never materializes a projection onto that polytope.&lt;/p&gt;

&lt;h2 id=&quot;4-a-2024-survey-to-keep-on-the-desk&quot;&gt;4. A 2024 survey to keep on the desk&lt;/h2&gt;

&lt;p&gt;Bomze, Rinaldi, and Zeffiro, &lt;strong&gt;“Frank–Wolfe and friends: a journey into projection-free first-order optimization methods”&lt;/strong&gt;, &lt;em&gt;Ann. Oper. Res.&lt;/em&gt; 343:607–638, 2024, &lt;a href=&quot;https://doi.org/10.1007/s10479-024-06251-7&quot;&gt;doi:10.1007/s10479-024-06251-7&lt;/a&gt;, It walks through traffic assignment, submodular optimization, matrix completion, adversarial attacks, SVM training, and maximal-clique search, and explains the 2020s variants (away-steps, pairwise, sliding, stochastic). Use it when you need a &lt;em&gt;menu&lt;/em&gt;, not when you need a proof.&lt;/p&gt;

&lt;h2 id=&quot;when-fw-still-beats-projected-gradient-in-2026&quot;&gt;When FW still beats projected gradient in 2026&lt;/h2&gt;

&lt;p&gt;Use Frank–Wolfe when (i) \(\mathcal{C}\) is a polytope, spectrahedron, or flow polytope whose LMO is a sort, an assignment, or an eigenvalue, and (ii) you &lt;em&gt;want&lt;/em&gt; the iterate to stay a sparse convex combination of atoms. Use a projection method when the projection is a cheap clip (box, simplex with Michelot) and you need a linear rate that vanilla FW will not give you without away-steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Color-transfer toy: two 1-D histograms \(a,b\in\Delta^{k}\) and a cost \(C_{ij}=(i-j)^2\). Run (i) 40 FW steps on the transportation polytope (LMO = a transportation problem you may solve with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.optimize.linprog&lt;/code&gt; on a tiny \(k=12\)) and (ii) projected gradient on the same polytope. Compare the number of nonzeros in the plan and the OT cost. FW should be sparser; PGD should drop the cost faster in the first few steps if you project exactly.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;M. Jaggi, ICML 2013 — FW duality gap and affine-invariant rates.&lt;/li&gt;
  &lt;li&gt;S. Lacoste-Julien, M. Jaggi, M. Schmidt, P. Pletscher, ICML 2013 — BCFW for structured SVMs.&lt;/li&gt;
  &lt;li&gt;T. Fukunaga and H. Kasai, &lt;a href=&quot;https://arxiv.org/abs/2205.13766&quot;&gt;arXiv:2205.13766&lt;/a&gt;, 2022 / ICASSP 2022 — BCFW for semi-relaxed OT, color transfer.&lt;/li&gt;
  &lt;li&gt;T. Séjourné et al., AISTATS 2022, &lt;a href=&quot;https://proceedings.mlr.press/v151/sejourne22a.html&quot;&gt;PMLR v151&lt;/a&gt; — FW for 1-D unbalanced OT.&lt;/li&gt;
  &lt;li&gt;J. Macdonald et al., ICML 2022, &lt;a href=&quot;https://proceedings.mlr.press/v162/macdonald22a.html&quot;&gt;PMLR v162&lt;/a&gt; — FW for rate-distortion explanations.&lt;/li&gt;
  &lt;li&gt;I. M. Bomze, F. Rinaldi, D. Zeffiro, &lt;em&gt;Ann. Oper. Res.&lt;/em&gt;, 2024, &lt;a href=&quot;https://doi.org/10.1007/s10479-024-06251-7&quot;&gt;doi:10.1007/s10479-024-06251-7&lt;/a&gt; — “Frank–Wolfe and friends.”&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>22-05 Modern applications of Frank–Wolfe</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_05_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_05_modern_applications</id>
   <content type="html">&lt;p&gt;Why would a 1956 algorithm still sit inside 2026 machine learning libraries alongside PyTorch and JAX? Because modern ML repeatedly runs into structured feasible sets—marginal polytopes of sequence labellings, optimal transport couplings, and sparse explanation masks—where projecting onto the constraint set is intractable, yet maximizing a linear score over it is an exact dynamic program or sorting operation. Modern Frank–Wolfe variants (Block-Coordinate FW, Blended Pairwise Conditional Gradients, and stochastic FW) turn those fast combinatorial oracles directly into scalable solvers.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-projection-free-optimization-thrives-in-modern-ml&quot;&gt;Key ideas: Why Projection-Free Optimization Thrives in Modern ML&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Block-Coordinate Frank–Wolfe (BCFW):&lt;/strong&gt; In structural SVMs, the dual constraint set is a Cartesian product of \(n\) exponential-size marginal polytopes (one per training sequence). BCFW updates a single randomly chosen block per step, reducing \(n\) expensive Viterbi calls per iteration to just &lt;strong&gt;one&lt;/strong&gt;, while keeping \(O(1/k)\) convergence.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Combinatorial Oracles as Linear Minimizers:&lt;/strong&gt; Many classic computer science algorithms—Viterbi decoding, Hungarian matching, minimum spanning trees, and 1D quantile sorting—are exact LMOs for convex hulls of combinatorial structures, plugging directly into Frank–Wolfe without relaxation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Structured Sparsity in Model Interpretability:&lt;/strong&gt; Constraining saliency masks or sparse neural perturbations to \(k\)-sparse polytopes or \(\ell_1\) balls naturally yields compact explanations where the iteration count \(k\) directly caps the number of active atoms.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Modern Acceleration (BPCG &amp;amp; Lazy Oracles):&lt;/strong&gt; Blended Pairwise Conditional Gradients (BPCG) and lazified LMOs reuse cached atoms to avoid calling the expensive linear oracle on most steps, delivering order-of-magnitude wall-clock speedups over classical FW.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-block-coordinate-frankwolfe-bcfw-step&quot;&gt;Worked example: One Block-Coordinate Frank–Wolfe (BCFW) Step&lt;/h3&gt;

&lt;p&gt;Suppose a structured prediction dual problem has \(n = 2\) decoupled simplex blocks \(x = (x^{(1)}, x^{(2)}) \in \Delta_2 \times \Delta_2\), with objective \(f(x^{(1)}, x^{(2)}) = \frac{1}{2}(x_1^{(1)} - 0.7)^2 + \frac{1}{2}(x_1^{(2)} - 0.2)^2\). Start at \(x_0^{(1)} = (0, 1)^\top\), \(x_0^{(2)} = (1, 0)^\top\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Sample one block uniformly:&lt;/strong&gt; Suppose iteration \(k = 1\) samples block \(i = 1\) (leaving block 2 untouched—saving 50% of oracle calls here, or \(99.9\%\) when \(n = 1000\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the block partial gradient:&lt;/strong&gt;
\(\nabla_1 f(x_0) = \bigl(x_1^{(1)} - 0.7,\ 0\bigr)^\top = (-0.7,\ 0)^\top.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Call the block LMO on \(\Delta_2\):&lt;/strong&gt; Minimize \(\langle (-0.7, 0), s \rangle\) over \(s \in \Delta_2\), which picks \(s^{(1)} = (1, 0)^\top\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update only block 1 with exact line search:&lt;/strong&gt; Along \(d^{(1)} = s^{(1)} - x_0^{(1)} = (1, -1)^\top\), we minimize \(\frac{1}{2}((0 + \gamma) - 0.7)^2\), giving \(\gamma = 0.7\).
\(x_1^{(1)} = (1 - 0.7)(0, 1)^\top + 0.7(1, 0)^\top = (0.7, 0.3)^\top, \qquad x_1^{(2)} = (1, 0)^\top.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Observe the computational win:&lt;/strong&gt; Block 1 hit its exact optimum in a single local LMO call without ever touching block 2’s gradient or oracle.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Frank–Wolfe (conditional gradient) is the algorithm you reach for when the feasible set \(\mathcal{C}\) has a cheap &lt;strong&gt;linear minimization oracle&lt;/strong&gt;&lt;/p&gt;

\[s_k \in \arg\min_{s\in\mathcal{C}}\ \langle \nabla f(x_k), s\rangle\]

&lt;p&gt;and a &lt;em&gt;projection&lt;/em&gt; onto \(\mathcal{C}\) is expensive or destructive of sparsity. The 2010s revival (Jaggi; Lacoste-Julien) is now a 2020s toolkit: structured prediction, optimal transport, and constrained explanations of neural nets. This optional note is four case studies, not a second convergence proof.&lt;/p&gt;

&lt;h2 id=&quot;1-structured-prediction-block-coordinate-frankwolfe&quot;&gt;1. Structured prediction: block-coordinate Frank–Wolfe&lt;/h2&gt;

&lt;p&gt;A structured-prediction ERM (CRF, structured SVM) has the form&lt;/p&gt;

\[\min_{w}\ \frac{\lambda}{2}\|w\|_2^2 + \frac1n\sum_{i=1}^n \max_{y\in\mathcal{Y}_i}\bigl(\langle w, \phi(x_i,y)\rangle - \delta(y_i,y)\bigr).\]

&lt;p&gt;The dual is optimization over a product of probability simplices — a Cartesian product on which a &lt;strong&gt;block-coordinate Frank–Wolfe (BCFW)&lt;/strong&gt; step is a &lt;em&gt;loss-augmented inference&lt;/em&gt; call, i.e. the same oracle the structured model already implements. Lacoste-Julien, Jaggi, Schmidt, and Pletscher (ICML 2013) is the classical reference; it is still the reason FW appears in structured-prediction code in 2026.&lt;/p&gt;

&lt;p&gt;The same block-coordinate idea moved to &lt;strong&gt;optimal transport&lt;/strong&gt;. Fukunaga and Kasai, &lt;a href=&quot;https://arxiv.org/abs/2205.13766&quot;&gt;arXiv:2205.13766&lt;/a&gt; (2022; conference version ICASSP 2022), apply BCFW — including away-steps and pairwise steps — to a &lt;em&gt;semi-relaxed&lt;/em&gt; OT problem whose tight marginal constraints would otherwise force a full LP. The linear oracle on each block is a closed-form argmin over a simplex; the output coupling is sparse. Their running application is &lt;strong&gt;color transfer&lt;/strong&gt; between images: the transport plan is exactly the kind of sparse, simplex-constrained object FW is designed to keep.&lt;/p&gt;

&lt;h2 id=&quot;2-unbalanced-and-1-d-transport&quot;&gt;2. Unbalanced and 1-D transport&lt;/h2&gt;

&lt;p&gt;Séjourné, Feydy, Vialard, Trouvé, and Peyré (AISTATS 2022, &lt;a href=&quot;https://proceedings.mlr.press/v151/sejourne22a.html&quot;&gt;PMLR v151&lt;/a&gt;) put Frank–Wolfe on the &lt;em&gt;dual&lt;/em&gt; of 1-D unbalanced OT. The linearized subproblem is a &lt;em&gt;balanced&lt;/em&gt; 1-D OT, which is solvable in linear time after a sort. That is the FW contract in one sentence: replace a hard nonlinear program by a linear oracle you already know how to solve. They also compute 1-D barycenters by the same linearization. When the goal is an &lt;em&gt;unregularized&lt;/em&gt; UOT solution, FW can beat Sinkhorn; when you want a smooth, GPU-friendly coupling, Sinkhorn still wins. Students should be able to say &lt;em&gt;why&lt;/em&gt;, not only &lt;em&gt;which&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;3-constrained-explanations-of-neural-nets&quot;&gt;3. Constrained explanations of neural nets&lt;/h2&gt;

&lt;p&gt;Macdonald, Besançon, and Pokutta (ICML 2022, &lt;a href=&quot;https://proceedings.mlr.press/v162/macdonald22a.html&quot;&gt;PMLR v162&lt;/a&gt;) recast &lt;strong&gt;rate-distortion explanations (RDE)&lt;/strong&gt; as a constrained problem and solve it with deterministic and stochastic Frank–Wolfe. Sparsity of a relevance map becomes an \(\ell_1\)-ball (or a simplex) constraint; a &lt;em&gt;feature-ordering&lt;/em&gt; variant optimizes over the &lt;strong&gt;Birkhoff polytope&lt;/strong&gt; (the convex hull of permutation matrices), whose linear oracle is an assignment problem. On image-classification benchmarks the multi-rate and ordering variants beat vanilla RDE. This is structured prediction in disguise: the “structure” is a polytope that encodes a human-readable explanation, and FW never materializes a projection onto that polytope.&lt;/p&gt;

&lt;h2 id=&quot;4-a-2024-survey-to-keep-on-the-desk&quot;&gt;4. A 2024 survey to keep on the desk&lt;/h2&gt;

&lt;p&gt;Bomze, Rinaldi, and Zeffiro, &lt;strong&gt;“Frank–Wolfe and friends: a journey into projection-free first-order optimization methods”&lt;/strong&gt;, &lt;em&gt;Ann. Oper. Res.&lt;/em&gt; 343:607–638, 2024, &lt;a href=&quot;https://doi.org/10.1007/s10479-024-06251-7&quot;&gt;doi:10.1007/s10479-024-06251-7&lt;/a&gt;, It walks through traffic assignment, submodular optimization, matrix completion, adversarial attacks, SVM training, and maximal-clique search, and explains the 2020s variants (away-steps, pairwise, sliding, stochastic). Use it when you need a &lt;em&gt;menu&lt;/em&gt;, not when you need a proof.&lt;/p&gt;

&lt;h2 id=&quot;when-fw-still-beats-projected-gradient-in-2026&quot;&gt;When FW still beats projected gradient in 2026&lt;/h2&gt;

&lt;p&gt;Use Frank–Wolfe when (i) \(\mathcal{C}\) is a polytope, spectrahedron, or flow polytope whose LMO is a sort, an assignment, or an eigenvalue, and (ii) you &lt;em&gt;want&lt;/em&gt; the iterate to stay a sparse convex combination of atoms. Use a projection method when the projection is a cheap clip (box, simplex with Michelot) and you need a linear rate that vanilla FW will not give you without away-steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Color-transfer toy: two 1-D histograms \(a,b\in\Delta^{k}\) and a cost \(C_{ij}=(i-j)^2\). Run (i) 40 FW steps on the transportation polytope (LMO = a transportation problem you may solve with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.optimize.linprog&lt;/code&gt; on a tiny \(k=12\)) and (ii) projected gradient on the same polytope. Compare the number of nonzeros in the plan and the OT cost. FW should be sparser; PGD should drop the cost faster in the first few steps if you project exactly.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;M. Jaggi, ICML 2013 — FW duality gap and affine-invariant rates.&lt;/li&gt;
  &lt;li&gt;S. Lacoste-Julien, M. Jaggi, M. Schmidt, P. Pletscher, ICML 2013 — BCFW for structured SVMs.&lt;/li&gt;
  &lt;li&gt;T. Fukunaga and H. Kasai, &lt;a href=&quot;https://arxiv.org/abs/2205.13766&quot;&gt;arXiv:2205.13766&lt;/a&gt;, 2022 / ICASSP 2022 — BCFW for semi-relaxed OT, color transfer.&lt;/li&gt;
  &lt;li&gt;T. Séjourné et al., AISTATS 2022, &lt;a href=&quot;https://proceedings.mlr.press/v151/sejourne22a.html&quot;&gt;PMLR v151&lt;/a&gt; — FW for 1-D unbalanced OT.&lt;/li&gt;
  &lt;li&gt;J. Macdonald et al., ICML 2022, &lt;a href=&quot;https://proceedings.mlr.press/v162/macdonald22a.html&quot;&gt;PMLR v162&lt;/a&gt; — FW for rate-distortion explanations.&lt;/li&gt;
  &lt;li&gt;I. M. Bomze, F. Rinaldi, D. Zeffiro, &lt;em&gt;Ann. Oper. Res.&lt;/em&gt;, 2024, &lt;a href=&quot;https://doi.org/10.1007/s10479-024-06251-7&quot;&gt;doi:10.1007/s10479-024-06251-7&lt;/a&gt; — “Frank–Wolfe and friends.”&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>21-09 Modern applications of ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_09_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_09_modern_applications</id>
   <content type="html">&lt;p&gt;Why does an algorithm formalized in the 1970s keep resurfacing in 2022–2026 top conferences across machine learning, computational imaging, and energy systems? Because &lt;strong&gt;consensus ADMM&lt;/strong&gt; solves a universal systems bottleneck: decoupling &lt;em&gt;private local physics or data&lt;/em&gt; (each client’s GPU, each imaging forward model, each regional power grid) from &lt;em&gt;global coordination&lt;/em&gt; through a lightweight dual price vector \(w_i\). This companion note highlights how modern implementations adapt ADMM for non-IID federated rounds, neural-denoiser imaging, and real-time online power dispatch.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-engineering-patterns-in-modern-admm-deployments&quot;&gt;Key ideas: Engineering Patterns in Modern ADMM Deployments&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Communication-Efficient Federated Consensus (Gong et al., 2022):&lt;/strong&gt; FedADMM transmits the exact same payload per round as FedAvg (one model vector), yet cuts communication rounds dramatically on non-IID CIFAR-10 / Fashion-MNIST by using dual variables to correct local objective mismatch.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inexact Primal Updates Without Breaking Convergence:&lt;/strong&gt; Modern deployments replace exact \(\arg\min_{x_i}\) with a few steps of SGD, CG, or L-BFGS—preserving convergence as long as subproblem errors are summable or satisfy an adaptive relative-error check.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Operator-Splitting with Learned Priors (PnP / RED):&lt;/strong&gt; Viewing ADMM through monotone operator theory explains why replacing \(\operatorname{prox}_{g/\rho}\) with a bounded-Lipschitz neural denoiser still converges to a stable fixed point balancing measurement fidelity and learned priors.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Online &amp;amp; Time-Varying Consensus (Smart Grids):&lt;/strong&gt; In online power dispatch, load demand \(y_t\) changes every few seconds; warm-starting ADMM’s primal and dual variables \((x_i^t, z^t, w_i^t)\) from the previous time slot tracks the moving optimum with just 1–5 iterations per second.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-warm-starting-online-consensus-admm-in-power-dispatch&quot;&gt;Worked example: Warm-Starting Online Consensus ADMM in Power Dispatch&lt;/h3&gt;

&lt;p&gt;Two regional power areas balance a time-varying total load by minimizing \(f_1(x_1) + f_2(x_2)\) subject to a tie-line consensus variable \(z\). Suppose at time \(t\) the grid has converged to \(x_1^\star(t) = x_2^\star(t) = z^\star(t) = 10\text{ MW}\) with dual prices \(w_1^\star(t) = -2, \; w_2^\star(t) = +2\) (for \(\rho = 1\), reflecting Area 1’s cheaper cost \(f_1(x_1) = \frac{1}{2}(x_1 - 12)^2\) and Area 2’s cost \(f_2(x_2) = \frac{1}{2}(x_2 - 8)^2\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;A sudden load shift occurs at time \(t + 1\):&lt;/strong&gt;
Area 1’s target shifts slightly to \(f_1^{\text{new}}(x_1) = \frac{1}{2}(x_1 - 13)^2\) (new exact global optimum: \(z^\star(t+1) = 10.5\text{ MW}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare Cold-Start (\(z^0 = 0, w^0 = 0\)) vs. Warm-Start (\(z^0 = 10, w_1^0 = -2, w_2^0 = +2\)) after 1 ADMM step:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Cold-start:&lt;/strong&gt; \(x_1^1 = \frac{13 + 0}{2} = 6.5\), \(x_2^1 = \frac{8 + 0}{2} = 4.0 \implies z^1 = 5.25\text{ MW}\) (error &lt;strong&gt;\(5.25\text{ MW}\)&lt;/strong&gt;!).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Warm-start:&lt;/strong&gt;
\(x_1^1 = \frac{13 + (10 - (-2))}{2} = 12.5, \qquad x_2^1 = \frac{8 + (10 - 2)}{2} = 8.0 \implies z^1 = \frac{12.5 + 8.0}{2} = 10.25\text{ MW}\) (error only &lt;strong&gt;\(0.25\text{ MW}\)&lt;/strong&gt;!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt;
Warm-starting both primal &lt;em&gt;and&lt;/em&gt; dual variables reduced the tracking error by &lt;strong&gt;21×&lt;/strong&gt; in a single iteration—showing why dual memory makes online ADMM ideal for real-time control!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The earlier lessons in this chapter treat ADMM as a &lt;em&gt;structured convex&lt;/em&gt; splitting method: two (or more) easy proximal pieces, a dual ascent, and residuals you can monitor. That story did not retire in 2011. Between 2022 and 2026 the same consensus / augmented-Lagrangian pattern shows up in federated deep learning, computational imaging with learned denoisers, and online power-system dispatch. This optional note is a map of those deployments, not a second derivation of scaled ADMM.&lt;/p&gt;

&lt;p&gt;Recall the consensus form from &lt;a href=&quot;/contents/en/chapter21/21_05_Consensus_ADMM/&quot;&gt;21-05&lt;/a&gt;:&lt;/p&gt;

\[\min_{x_1,\ldots,x_B,z}\ \sum_{i=1}^B f_i(x_i)\qquad\text{subject to}\qquad x_i=z.\]

&lt;p&gt;Each client (or each imaging block, or each electrical area) owns a private \(f_i\); the server only averages and updates duals. Everything below is a specialization of that template.&lt;/p&gt;

&lt;h2 id=&quot;1-fedadmm-consensus-learning-when-clients-are-heterogeneous&quot;&gt;1. FedADMM: consensus learning when clients are heterogeneous&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Federated learning&lt;/strong&gt; (Chapter 29) usually averages &lt;em&gt;weights&lt;/em&gt; after several local SGD steps (FedAvg). That is &lt;em&gt;not&lt;/em&gt; ADMM: there is no dual residual, and local drift is intentional. A 2022–2023 line of work puts the dual back.&lt;/p&gt;

&lt;p&gt;Gong, Li, and Freris (&lt;a href=&quot;https://arxiv.org/abs/2204.03529&quot;&gt;arXiv:2204.03529&lt;/a&gt;, 2022) introduce &lt;strong&gt;FedADMM&lt;/strong&gt;. Each client \(i\) approximately minimizes its augmented Lagrangian (a few local SGD steps are allowed — an &lt;em&gt;inexact&lt;/em&gt; \(x\)-update), the server averages the primals, and dual variables \(w_i\) accumulate the disagreement \(x_i-z\). Communication per round matches FedAvg, but the duals adapt to &lt;strong&gt;statistical heterogeneity&lt;/strong&gt; without a hand-tuned proximal penalty. The same paper reports up to 87% fewer rounds than FedAvg/FedProx on CIFAR-10 / Fashion-MNIST under non-IID splits.&lt;/p&gt;

&lt;p&gt;Zhou and Li, &lt;em&gt;Federated Learning via Inexact ADMM&lt;/em&gt;, IEEE TPAMI 45(8):9699–9708, 2023, &lt;a href=&quot;https://doi.org/10.1109/TPAMI.2023.3243080&quot;&gt;doi:10.1109/TPAMI.2023.3243080&lt;/a&gt;, give a companion theory: inexact local solves, partial participation, and a nonconvex objective. The message for this course is precise. If you can write a consensus program and you care about residuals, ADMM is still the right language. If the model is a deep net and the scarce resource is &lt;em&gt;rounds&lt;/em&gt;, FedADMM is the 2020s dialect of &lt;a href=&quot;/contents/en/chapter21/21_05_Consensus_ADMM/&quot;&gt;21-05&lt;/a&gt; — not a replacement for FedAvg, and not “just SGD with a Lagrange multiplier.”&lt;/p&gt;

&lt;p&gt;A 2025–2026 medical follow-up (ADMM-enhanced FL on PIMA diabetes and chest X-rays) treats FedADMM as one more federated optimizer next to SCAFFOLD and FedDyn. That is an &lt;em&gt;application&lt;/em&gt;, not a new algorithm: hospitals cannot pool images, and a primal-dual residual is a useful health check.&lt;/p&gt;

&lt;h2 id=&quot;2-plug-and-play-admm-in-computational-imaging&quot;&gt;2. Plug-and-play ADMM in computational imaging&lt;/h2&gt;

&lt;p&gt;Image restoration is a textbook composite problem&lt;/p&gt;

\[\min_x\ \tfrac12\|Ax-b\|_2^2 + g(x),\]

&lt;p&gt;where \(A\) is blur / undersampling and \(g\) is a regularizer. Classical ADMM uses \(\mathrm{prox}_g\). &lt;strong&gt;Plug-and-play (PnP) ADMM&lt;/strong&gt; replaces that prox by an off-the-shelf denoiser \(D_{\sigma}\) — BM3D yesterday, a CNN today — and keeps the data-fidelity \(x\)-update.&lt;/p&gt;

&lt;p&gt;Chan, Wang, and Elgendy, &lt;em&gt;IEEE Trans. Computational Imaging&lt;/em&gt; 3:84–98, 2017 (online 2016), &lt;a href=&quot;https://doi.org/10.1109/TCI.2016.2629286&quot;&gt;doi:10.1109/TCI.2016.2629286&lt;/a&gt;, proved fixed-point convergence for &lt;em&gt;bounded&lt;/em&gt; denoisers under a continuation scheme, with super-resolution and single-photon imaging as the running examples. The 2022–2023 wave made the denoiser a deep network. Zhang, Li, Zuo, Zhang, Van Gool, and Timofte, &lt;em&gt;Plug-and-Play Image Restoration with Deep Denoiser Prior&lt;/em&gt;, IEEE TPAMI 44(10):6360–6376, 2022, &lt;a href=&quot;https://doi.org/10.1109/TPAMI.2021.3088914&quot;&gt;doi:10.1109/TPAMI.2021.3088914&lt;/a&gt;, drop a single trained DRUNet into many inverse problems. Hurault, Chambolle, Leclaire, and Papadakis (&lt;a href=&quot;https://arxiv.org/abs/2210.10605&quot;&gt;arXiv:2210.10605&lt;/a&gt;, 2023) linearize the ADMM \(x\)-step so that a non-uniform blur operator never needs an inner CG solve. Shoushtari, Liu, Schniter, and Kamilov (&lt;a href=&quot;https://arxiv.org/abs/2311.18810&quot;&gt;arXiv:2311.18810&lt;/a&gt;, 2023) explain why PnP-ADMM often converges even for &lt;em&gt;expansive&lt;/em&gt; CNN denoisers if one interprets \(D_{\sigma}\) as an MMSE estimator (hence a prox of a possibly nonconvex \(g\)).&lt;/p&gt;

&lt;p&gt;The data-science takeaway: ADMM is a &lt;em&gt;modular interface&lt;/em&gt;. One block is physics (\(A\), Poisson likelihood); the other is a learned prior. You do not retrain a network for every camera. That is why computational-imaging groups still teach ADMM after everyone else moved to Adam.&lt;/p&gt;

&lt;h2 id=&quot;3-distributed-optimal-power-flow&quot;&gt;3. Distributed optimal power flow&lt;/h2&gt;

&lt;p&gt;Optimal power flow (OPF) is a nonconvex QCQP on a grid: voltages, generation, and line limits. Areas refuse to share full network data, and renewables make the problem &lt;em&gt;online&lt;/em&gt;. Consensus ADMM splits the grid at boundary buses: each area solves a local OPF, duals on the shared voltages enforce Kirchhoff agreement.&lt;/p&gt;

&lt;p&gt;Wang, Pu, Huang, Yu, Shi, and Wang, &lt;em&gt;Online ADMM for Distributed Optimal Power Flow via Lagrangian Duality&lt;/em&gt;, &lt;em&gt;Energies&lt;/em&gt; 15(24):9525, 2022, &lt;a href=&quot;https://doi.org/10.3390/en15249525&quot;&gt;doi:10.3390/en15249525&lt;/a&gt;, run consensus ADMM on the &lt;em&gt;dual&lt;/em&gt; OPF so that only boundary multipliers move, and they do it &lt;em&gt;online&lt;/em&gt; as distributed energy resources fluctuate. IEEE 30-bus experiments compare static versus dynamic OPF: the online ADMM iterate tracks renewable ramps without the violent generator chatter of a fully re-solved offline OPF. This is Boyd’s consensus template with a power-systems \(f_i\), and it is a useful reminder that “distributed optimization” in 2026 is not only GPU all-reduce.&lt;/p&gt;

&lt;h2 id=&quot;what-to-keep-what-to-send-to-chapter-29&quot;&gt;What to keep, what to send to Chapter 29&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Application&lt;/th&gt;
      &lt;th&gt;What is split&lt;/th&gt;
      &lt;th&gt;What is averaged&lt;/th&gt;
      &lt;th&gt;Certificate&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;FedADMM&lt;/td&gt;
      &lt;td&gt;local training loss&lt;/td&gt;
      &lt;td&gt;primal \(z\) and duals&lt;/td&gt;
      &lt;td&gt;residuals (and a nonconvex rate)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;PnP imaging&lt;/td&gt;
      &lt;td&gt;data fidelity vs denoiser&lt;/td&gt;
      &lt;td&gt;the image / dual&lt;/td&gt;
      &lt;td&gt;fixed-point of a denoiser-prox&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Distributed OPF&lt;/td&gt;
      &lt;td&gt;electrical areas&lt;/td&gt;
      &lt;td&gt;boundary voltages / multipliers&lt;/td&gt;
      &lt;td&gt;power-balance residual&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FedAvg (Ch.29)&lt;/td&gt;
      &lt;td&gt;local ERM&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;weights&lt;/strong&gt; after \(E\) steps&lt;/td&gt;
      &lt;td&gt;none&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Take the scaled consensus updates from 21-05 and write a 3-client FedADMM &lt;em&gt;sketch&lt;/em&gt; (no training required): each client takes one gradient step on \(\frac12\|x_i-x_i^{\mathrm{data}}\|_2^2+\frac{\rho}{2}\|x_i-z+u_i\|_2^2\), then average. Plot \(\|x_i-z\|\) versus a FedAvg-style average-without-duals run. The dual run should pull the three \(x_i\) together; the dual-free run should leave a gap equal to the data offset.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;S. Boyd et al., &lt;em&gt;Foundations and Trends in ML&lt;/em&gt; 3(1):1–122, 2011 — consensus ADMM.&lt;/li&gt;
  &lt;li&gt;Y. Gong, Y. Li, N. M. Freris, &lt;a href=&quot;https://arxiv.org/abs/2204.03529&quot;&gt;arXiv:2204.03529&lt;/a&gt;, 2022 — FedADMM.&lt;/li&gt;
  &lt;li&gt;S. Zhou and G. Y. Li, &lt;em&gt;IEEE TPAMI&lt;/em&gt; 45(8):9699–9708, 2023 — inexact ADMM for FL.&lt;/li&gt;
  &lt;li&gt;S. H. Chan, X. Wang, O. A. Elgendy, &lt;em&gt;IEEE TCI&lt;/em&gt; 3:84–98, 2017 — PnP-ADMM convergence.&lt;/li&gt;
  &lt;li&gt;K. Zhang et al., &lt;em&gt;IEEE TPAMI&lt;/em&gt; 44(10):6360–6376, 2022 — deep PnP denoisers.&lt;/li&gt;
  &lt;li&gt;S. Hurault et al., &lt;a href=&quot;https://arxiv.org/abs/2210.10605&quot;&gt;arXiv:2210.10605&lt;/a&gt;, 2023 — linearized PnP-ADMM.&lt;/li&gt;
  &lt;li&gt;S. Shoushtari et al., &lt;a href=&quot;https://arxiv.org/abs/2311.18810&quot;&gt;arXiv:2311.18810&lt;/a&gt;, 2023 — nonconvex PnP-ADMM.&lt;/li&gt;
  &lt;li&gt;S. Wang, L. Pu, X. Huang, Y. Yu, Y. Shi, H. Wang, &lt;em&gt;Energies&lt;/em&gt; 15(24):9525, 2022 — online distributed OPF.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>21-07 Modern applications of ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_07_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_07_modern_applications</id>
   <content type="html">&lt;p&gt;When Boyd et al. published their landmark 2011 ADMM survey, the flagship applications were Lasso, SVMs, and distributed MapReduce clusters. Fifteen years later, the exact same consensus template \(\min \sum_i f_i(x_i) \text{ s.t. } x_i = z\) is thriving inside three unexpectedly modern domains: &lt;strong&gt;FedADMM&lt;/strong&gt; for heterogeneous federated deep learning, &lt;strong&gt;Plug-and-Play (PnP) ADMM&lt;/strong&gt; for computational imaging with deep neural denoisers, and &lt;strong&gt;distributed optimal power flow (OPF)&lt;/strong&gt; for renewable smart grids.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-where-consensus-admm-lives-today-20222026&quot;&gt;Key ideas: Where Consensus ADMM Lives Today (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;FedADMM in Heterogeneous Federated Learning:&lt;/strong&gt; Replaces naive weight averaging (FedAvg) with primal-dual consensus across edge devices; dual variables \(w_i\) cancel non-IID client drift while allowing inexact local SGD updates.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Plug-and-Play (PnP) ADMM in Computational Imaging:&lt;/strong&gt; Replaces the explicit regularizer proximal map \(\operatorname{prox}_{g/\rho}(v)\) inside ADMM with a pre-trained deep denoiser \(D_\sigma(v)\) (e.g., DRUNet or diffusion denoisers) for MRI, CT, and astronomical deblurring—with provable fixed-point convergence when \(D_\sigma\) is firmly non-expansive.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Distributed Optimal Power Flow (OPF) &amp;amp; Microgrids:&lt;/strong&gt; Splits a national electrical grid into regional balancing areas coupled only by tie-line voltage/power consensus constraints \(x_i = z\), allowing real-time online dispatch without sharing proprietary generator bids.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive Penalty &amp;amp; Inexact Subproblems:&lt;/strong&gt; Across all three modern deployments, strict exact inner solves are replaced by a few warm-started gradient steps paired with adaptive \(\rho\) schedules to keep primal and dual residuals balanced.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-iteration-of-plug-and-play-pnp-admm-for-image-denoising&quot;&gt;Worked example: One Iteration of Plug-and-Play (PnP) ADMM for Image Denoising&lt;/h3&gt;

&lt;p&gt;Consider an inverse imaging problem \(\min_x \frac{1}{2}\|A x - y\|_2^2 + g(x)\) in 2D with diagonal blur \(A = \operatorname{diag}(1, 0.5)\), noisy observation \(y = (2.0, 1.0)^T\), and a linear shrinkage denoiser \(D_\sigma(v) = 0.8 v\) standing in for \(\operatorname{prox}_{g/\rho}(v)\) (representing a learned neural denoiser with Lipschitz constant \(0.8 &amp;lt; 1\)). Run 1 iteration of PnP-ADMM with \(\rho = 1\) from \(z^0 = (0, 0)^T, \; w^0 = (0, 0)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Data-fidelity \(x\)-update (exact physics / measurement consistency):&lt;/strong&gt;
\(x^1 = (A^T A + \rho I)^{-1}\!\big(A^T y + \rho(z^0 - w^0)\big) = \begin{bmatrix} 1 + 1 &amp;amp; 0 \\ 0 &amp;amp; 0.25 + 1 \end{bmatrix}^{-1}\begin{bmatrix} 2.0 \\ 0.5 \end{bmatrix} = \begin{bmatrix} 1.0 \\ 0.4 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Learned-prior \(z\)-update (plug in the denoiser \(D_\sigma\) instead of a hand-crafted prox!):&lt;/strong&gt;
\(z^1 = D_\sigma(x^1 + w^0) = 0.8 \begin{bmatrix} 1.0 \\ 0.4 \end{bmatrix} = \begin{bmatrix} 0.80 \\ 0.32 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual residual accumulation:&lt;/strong&gt;
\(w^1 = w^0 + x^1 - z^1 = \begin{bmatrix} 0.20 \\ 0.08 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why PnP-ADMM is so powerful:&lt;/strong&gt;
The data-fidelity step enforces the exact physical forward model \(Ax \approx y\) (e.g., MRI Fourier measurements), while the neural denoiser \(D_\sigma\) injects rich natural-image priors—without ever needing to differentiate through the neural network!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The earlier lessons in this chapter treat ADMM as a &lt;em&gt;structured convex&lt;/em&gt; splitting method: two (or more) easy proximal pieces, a dual ascent, and residuals you can monitor. That story did not retire in 2011. Between 2022 and 2026 the same consensus / augmented-Lagrangian pattern shows up in federated deep learning, computational imaging with learned denoisers, and online power-system dispatch. This optional note is a map of those deployments, not a second derivation of scaled ADMM.&lt;/p&gt;

&lt;p&gt;Recall the consensus form from &lt;a href=&quot;/contents/en/chapter21/21_05_Consensus_ADMM/&quot;&gt;21-05&lt;/a&gt;:&lt;/p&gt;

\[\min_{x_1,\ldots,x_B,z}\ \sum_{i=1}^B f_i(x_i)\qquad\text{subject to}\qquad x_i=z.\]

&lt;p&gt;Each client (or each imaging block, or each electrical area) owns a private \(f_i\); the server only averages and updates duals. Everything below is a specialization of that template.&lt;/p&gt;

&lt;h2 id=&quot;1-fedadmm-consensus-learning-when-clients-are-heterogeneous&quot;&gt;1. FedADMM: consensus learning when clients are heterogeneous&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Federated learning&lt;/strong&gt; (Chapter 29) usually averages &lt;em&gt;weights&lt;/em&gt; after several local SGD steps (FedAvg). That is &lt;em&gt;not&lt;/em&gt; ADMM: there is no dual residual, and local drift is intentional. A 2022–2023 line of work puts the dual back.&lt;/p&gt;

&lt;p&gt;Gong, Li, and Freris (&lt;a href=&quot;https://arxiv.org/abs/2204.03529&quot;&gt;arXiv:2204.03529&lt;/a&gt;, 2022) introduce &lt;strong&gt;FedADMM&lt;/strong&gt;. Each client \(i\) approximately minimizes its augmented Lagrangian (a few local SGD steps are allowed — an &lt;em&gt;inexact&lt;/em&gt; \(x\)-update), the server averages the primals, and dual variables \(w_i\) accumulate the disagreement \(x_i-z\). Communication per round matches FedAvg, but the duals adapt to &lt;strong&gt;statistical heterogeneity&lt;/strong&gt; without a hand-tuned proximal penalty. The same paper reports up to 87% fewer rounds than FedAvg/FedProx on CIFAR-10 / Fashion-MNIST under non-IID splits.&lt;/p&gt;

&lt;p&gt;Zhou and Li, &lt;em&gt;Federated Learning via Inexact ADMM&lt;/em&gt;, IEEE TPAMI 45(8):9699–9708, 2023, &lt;a href=&quot;https://doi.org/10.1109/TPAMI.2023.3243080&quot;&gt;doi:10.1109/TPAMI.2023.3243080&lt;/a&gt;, give a companion theory: inexact local solves, partial participation, and a nonconvex objective. The message for this course is precise. If you can write a consensus program and you care about residuals, ADMM is still the right language. If the model is a deep net and the scarce resource is &lt;em&gt;rounds&lt;/em&gt;, FedADMM is the 2020s dialect of &lt;a href=&quot;/contents/en/chapter21/21_05_Consensus_ADMM/&quot;&gt;21-05&lt;/a&gt; — not a replacement for FedAvg, and not “just SGD with a Lagrange multiplier.”&lt;/p&gt;

&lt;p&gt;A 2025–2026 medical follow-up (ADMM-enhanced FL on PIMA diabetes and chest X-rays) treats FedADMM as one more federated optimizer next to SCAFFOLD and FedDyn. That is an &lt;em&gt;application&lt;/em&gt;, not a new algorithm: hospitals cannot pool images, and a primal-dual residual is a useful health check.&lt;/p&gt;

&lt;h2 id=&quot;2-plug-and-play-admm-in-computational-imaging&quot;&gt;2. Plug-and-play ADMM in computational imaging&lt;/h2&gt;

&lt;p&gt;Image restoration is a textbook composite problem&lt;/p&gt;

\[\min_x\ \tfrac12\|Ax-b\|_2^2 + g(x),\]

&lt;p&gt;where \(A\) is blur / undersampling and \(g\) is a regularizer. Classical ADMM uses \(\mathrm{prox}_g\). &lt;strong&gt;Plug-and-play (PnP) ADMM&lt;/strong&gt; replaces that prox by an off-the-shelf denoiser \(D_{\sigma}\) — BM3D yesterday, a CNN today — and keeps the data-fidelity \(x\)-update.&lt;/p&gt;

&lt;p&gt;Chan, Wang, and Elgendy, &lt;em&gt;IEEE Trans. Computational Imaging&lt;/em&gt; 3:84–98, 2017 (online 2016), &lt;a href=&quot;https://doi.org/10.1109/TCI.2016.2629286&quot;&gt;doi:10.1109/TCI.2016.2629286&lt;/a&gt;, proved fixed-point convergence for &lt;em&gt;bounded&lt;/em&gt; denoisers under a continuation scheme, with super-resolution and single-photon imaging as the running examples. The 2022–2023 wave made the denoiser a deep network. Zhang, Li, Zuo, Zhang, Van Gool, and Timofte, &lt;em&gt;Plug-and-Play Image Restoration with Deep Denoiser Prior&lt;/em&gt;, IEEE TPAMI 44(10):6360–6376, 2022, &lt;a href=&quot;https://doi.org/10.1109/TPAMI.2021.3088914&quot;&gt;doi:10.1109/TPAMI.2021.3088914&lt;/a&gt;, drop a single trained DRUNet into many inverse problems. Hurault, Chambolle, Leclaire, and Papadakis (&lt;a href=&quot;https://arxiv.org/abs/2210.10605&quot;&gt;arXiv:2210.10605&lt;/a&gt;, 2023) linearize the ADMM \(x\)-step so that a non-uniform blur operator never needs an inner CG solve. Shoushtari, Liu, Schniter, and Kamilov (&lt;a href=&quot;https://arxiv.org/abs/2311.18810&quot;&gt;arXiv:2311.18810&lt;/a&gt;, 2023) explain why PnP-ADMM often converges even for &lt;em&gt;expansive&lt;/em&gt; CNN denoisers if one interprets \(D_{\sigma}\) as an MMSE estimator (hence a prox of a possibly nonconvex \(g\)).&lt;/p&gt;

&lt;p&gt;The data-science takeaway: ADMM is a &lt;em&gt;modular interface&lt;/em&gt;. One block is physics (\(A\), Poisson likelihood); the other is a learned prior. You do not retrain a network for every camera. That is why computational-imaging groups still teach ADMM after everyone else moved to Adam.&lt;/p&gt;

&lt;h2 id=&quot;3-distributed-optimal-power-flow&quot;&gt;3. Distributed optimal power flow&lt;/h2&gt;

&lt;p&gt;Optimal power flow (OPF) is a nonconvex QCQP on a grid: voltages, generation, and line limits. Areas refuse to share full network data, and renewables make the problem &lt;em&gt;online&lt;/em&gt;. Consensus ADMM splits the grid at boundary buses: each area solves a local OPF, duals on the shared voltages enforce Kirchhoff agreement.&lt;/p&gt;

&lt;p&gt;Wang, Pu, Huang, Yu, Shi, and Wang, &lt;em&gt;Online ADMM for Distributed Optimal Power Flow via Lagrangian Duality&lt;/em&gt;, &lt;em&gt;Energies&lt;/em&gt; 15(24):9525, 2022, &lt;a href=&quot;https://doi.org/10.3390/en15249525&quot;&gt;doi:10.3390/en15249525&lt;/a&gt;, run consensus ADMM on the &lt;em&gt;dual&lt;/em&gt; OPF so that only boundary multipliers move, and they do it &lt;em&gt;online&lt;/em&gt; as distributed energy resources fluctuate. IEEE 30-bus experiments compare static versus dynamic OPF: the online ADMM iterate tracks renewable ramps without the violent generator chatter of a fully re-solved offline OPF. This is Boyd’s consensus template with a power-systems \(f_i\), and it is a useful reminder that “distributed optimization” in 2026 is not only GPU all-reduce.&lt;/p&gt;

&lt;h2 id=&quot;what-to-keep-what-to-send-to-chapter-29&quot;&gt;What to keep, what to send to Chapter 29&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Application&lt;/th&gt;
      &lt;th&gt;What is split&lt;/th&gt;
      &lt;th&gt;What is averaged&lt;/th&gt;
      &lt;th&gt;Certificate&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;FedADMM&lt;/td&gt;
      &lt;td&gt;local training loss&lt;/td&gt;
      &lt;td&gt;primal \(z\) and duals&lt;/td&gt;
      &lt;td&gt;residuals (and a nonconvex rate)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;PnP imaging&lt;/td&gt;
      &lt;td&gt;data fidelity vs denoiser&lt;/td&gt;
      &lt;td&gt;the image / dual&lt;/td&gt;
      &lt;td&gt;fixed-point of a denoiser-prox&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Distributed OPF&lt;/td&gt;
      &lt;td&gt;electrical areas&lt;/td&gt;
      &lt;td&gt;boundary voltages / multipliers&lt;/td&gt;
      &lt;td&gt;power-balance residual&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FedAvg (Ch.29)&lt;/td&gt;
      &lt;td&gt;local ERM&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;weights&lt;/strong&gt; after \(E\) steps&lt;/td&gt;
      &lt;td&gt;none&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Take the scaled consensus updates from 21-05 and write a 3-client FedADMM &lt;em&gt;sketch&lt;/em&gt; (no training required): each client takes one gradient step on \(\frac12\|x_i-x_i^{\mathrm{data}}\|_2^2+\frac{\rho}{2}\|x_i-z+u_i\|_2^2\), then average. Plot \(\|x_i-z\|\) versus a FedAvg-style average-without-duals run. The dual run should pull the three \(x_i\) together; the dual-free run should leave a gap equal to the data offset.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;S. Boyd et al., &lt;em&gt;Foundations and Trends in ML&lt;/em&gt; 3(1):1–122, 2011 — consensus ADMM.&lt;/li&gt;
  &lt;li&gt;Y. Gong, Y. Li, N. M. Freris, &lt;a href=&quot;https://arxiv.org/abs/2204.03529&quot;&gt;arXiv:2204.03529&lt;/a&gt;, 2022 — FedADMM.&lt;/li&gt;
  &lt;li&gt;S. Zhou and G. Y. Li, &lt;em&gt;IEEE TPAMI&lt;/em&gt; 45(8):9699–9708, 2023 — inexact ADMM for FL.&lt;/li&gt;
  &lt;li&gt;S. H. Chan, X. Wang, O. A. Elgendy, &lt;em&gt;IEEE TCI&lt;/em&gt; 3:84–98, 2017 — PnP-ADMM convergence.&lt;/li&gt;
  &lt;li&gt;K. Zhang et al., &lt;em&gt;IEEE TPAMI&lt;/em&gt; 44(10):6360–6376, 2022 — deep PnP denoisers.&lt;/li&gt;
  &lt;li&gt;S. Hurault et al., &lt;a href=&quot;https://arxiv.org/abs/2210.10605&quot;&gt;arXiv:2210.10605&lt;/a&gt;, 2023 — linearized PnP-ADMM.&lt;/li&gt;
  &lt;li&gt;S. Shoushtari et al., &lt;a href=&quot;https://arxiv.org/abs/2311.18810&quot;&gt;arXiv:2311.18810&lt;/a&gt;, 2023 — nonconvex PnP-ADMM.&lt;/li&gt;
  &lt;li&gt;S. Wang, L. Pu, X. Huang, Y. Yu, Y. Shi, H. Wang, &lt;em&gt;Energies&lt;/em&gt; 15(24):9525, 2022 — online distributed OPF.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>20-06 Modern applications of dual methods (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_06_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_06_modern_applications</id>
   <content type="html">&lt;p&gt;In 2017, Federated Averaging (FedAvg) became the standard recipe for training machine learning models across phones and hospitals without centralizing raw data. Yet whenever clients hold &lt;em&gt;non-IID&lt;/em&gt; (heterogeneous) data, FedAvg suffers from &lt;strong&gt;client drift&lt;/strong&gt;: each local optimizer pulls weights toward its own local optimum, and naive averaging stalls far from the global minimizer. Between 2022 and 2026, &lt;strong&gt;FedADMM&lt;/strong&gt; and &lt;strong&gt;FedADMM-InSa&lt;/strong&gt; solved client drift using the exact lesson of Chapter 20: add a dual variable \(u_i\) to price the consensus constraint \(w_i = z\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-dual-methods-inside-modern-federated-learning&quot;&gt;Key ideas: Dual Methods Inside Modern Federated Learning&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Federated Consensus Formulation:&lt;/strong&gt; Minimizing \(\sum_{i=1}^N f_i(w_i)\) subject to \(w_i = z\) casts federated learning directly as Chapter 20’s equality-constrained decomposition problem, where client \(i\) keeps its private loss \(f_i\) on-device.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why FedAvg Drifts Under Heterogeneity:&lt;/strong&gt; FedAvg drops the dual multipliers \(u_i\) completely. At the global optimum \(z^\star\), individual local gradients \(\nabla f_i(z^\star) \neq 0\) even though \(\sum_i \nabla f_i(z^\star) = 0\)—so local SGD steps push clients &lt;em&gt;away&lt;/em&gt; from \(z^\star\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Multipliers Cancel Local Bias:&lt;/strong&gt; In FedADMM, each client’s dual variable converges to \(u_i^\star = -\nabla f_i(z^\star)\), shifting client \(i\)’s local augmented objective so that \(z^\star\) becomes a &lt;em&gt;stationary point of every single client’s subproblem&lt;/em&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inexactness &amp;amp; Self-Adaptive Penalties (FedADMM-InSa, 2024):&lt;/strong&gt; Modern federated ADMM allows clients to run just a few local SGD steps (verifying an implementable local residual test) while adapting \(\beta_i^k\) automatically to handle stragglers and partial participation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-seeing-dual-variables-cure-client-drift-on-2-heterogeneous-clients&quot;&gt;Worked example: Seeing Dual Variables Cure Client Drift on 2 Heterogeneous Clients&lt;/h3&gt;

&lt;p&gt;Suppose two clients have conflicting 1D quadratic losses: \(f_1(w_1) = \frac{1}{2}(w_1 - 2)^2\) (local optimum \(2\)) and \(f_2(w_2) = \frac{1}{2}(w_2 + 2)^2\) (local optimum \(-2\)). The true global consensus optimum is \(z^\star = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Watch FedAvg drift if each client minimizes locally from \(z^0 = 0\):&lt;/strong&gt;
Client 1 jumps to \(w_1 = 2\), Client 2 jumps to \(w_2 = -2\). Even though their average is \(0\), if Client 1 has weight \(2\) (\(f_1(w_1) = (w_1 - 2)^2\), so global optimum is \(z^\star = 2/3\)), taking multiple local GD steps with \(\eta = 0.25\) pushes Client 1 to \(2\) and Client 2 to \(-2\), whose average is \(0 \neq \frac{2}{3}\)—a permanent bias!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Now run FedADMM (\(\beta = 1\)) with dual variables \(u_1, u_2\) on \(f_1(w_1) = (w_1 - 2)^2\) and \(f_2(w_2) = \frac{1}{2}(w_2 + 2)^2\):&lt;/strong&gt;
At the exact global optimum \(z^\star = \frac{2}{3}\):
    &lt;ul&gt;
      &lt;li&gt;\(\nabla f_1(2/3) = 2(2/3 - 2) = -\frac{8}{3} \implies u_1^\star = +\frac{8}{3}\).&lt;/li&gt;
      &lt;li&gt;\(\nabla f_2(2/3) = (2/3 + 2) = +\frac{8}{3} \implies u_2^\star = -\frac{8}{3}\).
Check client 1’s local augmented Lagrangian stationarity at \(w_1 = z^\star = 2/3\):
\(\nabla f_1(w_1) + u_1^\star + \beta(w_1 - z^\star) = -\frac{8}{3} + \frac{8}{3} + 0 = 0!\)
Check client 2’s local stationarity at \(w_2 = z^\star = 2/3\):
\(\nabla f_2(w_2) + u_2^\star + \beta(w_2 - z^\star) = +\frac{8}{3} - \frac{8}{3} + 0 = 0!\)
Because the dual multipliers \(u_i^\star\) absorb each client’s local gradient bias identically, &lt;em&gt;zero&lt;/em&gt; client drift occurs at \(z^\star\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Dual (sub)gradient, dual decomposition, augmented Lagrangians, and the first look at ADMM in this chapter all share one move: &lt;em&gt;price a consensus or resource constraint and let each block optimise independently&lt;/em&gt;. That is also the move behind federated learning. A 2026 student who has already seen FedAvg in Chapter 29 should recognise FedADMM as Chapter 20 with a server: the dual variable is the running price of “your local model must match the global model.”&lt;/p&gt;

&lt;h2 id=&quot;fedadmm-dual-variables-against-client-heterogeneity&quot;&gt;FedADMM: dual variables against client heterogeneity&lt;/h2&gt;

&lt;p&gt;Zhou and Li (2022/23, &lt;a href=&quot;https://arxiv.org/abs/2204.10607&quot;&gt;arXiv:2204.10607&lt;/a&gt;) formulate federated empirical risk as a consensus problem and apply an &lt;strong&gt;inexact ADMM&lt;/strong&gt;. Clients may solve their augmented-Lagrangian subproblems approximately; the server may skip stragglers; communication need not happen every local step. The dual variables absorb statistical heterogeneity that FedAvg treats only by averaging. Subsequent FedADMM variants (Gong et al. 2022; Wang et al. 2023; Zhang et al. 2021) keep that skeleton.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FedADMM-InSa&lt;/strong&gt; (Song, Wang, and Zuazua, 2024, &lt;a href=&quot;https://arxiv.org/abs/2402.13989&quot;&gt;arXiv:2402.13989&lt;/a&gt;) adds two missing pieces from this chapter’s practice sheet: an &lt;em&gt;implementable inexactness test&lt;/em&gt; that each client can evaluate from local residuals, and a &lt;em&gt;self-adaptive penalty&lt;/em&gt; \(\beta_i^k\) that plays the role of the AL parameter you tuned by hand in 20-03. On their reported tests the combination raises accuracy by about 8% while cutting local work by about 56% versus the baselines they compare. The algorithm is not a new duality theorem; it is dual decomposition with the safeguards Boyd, Parikh, Chu, Peleato, and Eckstein already recommended, engineered for FL’s partial participation.&lt;/p&gt;

&lt;p&gt;Write the consensus form once,&lt;/p&gt;

\[\min_{w_1,\ldots,w_N,z}\ \sum_{i=1}^N f_i(w_i)\quad\text{s.t.}\quad w_i=z,\]

&lt;p&gt;and the rest of Chapter 20 is the method: dualise \(w_i=z\), take an AL term \(\frac{\beta}{2}\|w_i-z\|_2^2\), and alternate \(w_i\), \(z\), and the multipliers. FedAvg is the special case that throws the multipliers away and takes one gradient step on \(f_i\).&lt;/p&gt;

&lt;h2 id=&quot;decentralised-dual-constraints-dfedadmm&quot;&gt;Decentralised dual constraints: DFedADMM&lt;/h2&gt;

&lt;p&gt;When there is no server, consensus is a graph. &lt;strong&gt;DFedADMM&lt;/strong&gt; and &lt;strong&gt;DFedADMM-SAM&lt;/strong&gt; (Li, Shen, Li, Yin, and Tao, 2023, &lt;a href=&quot;https://arxiv.org/abs/2308.08290&quot;&gt;arXiv:2308.08290&lt;/a&gt;) put a dual variable on each edge (or neighbour disagreement) so that heterogeneous local objectives cannot drift independently. SAM (sharpness-aware minimisation) is an extra local regulariser against heterogeneous overfitting; the &lt;em&gt;dual&lt;/em&gt; part is Chapter 20. The paper gives nonconvex rates that depend on the spectral gap of the gossip matrix — the same graph Laplacian that appears in classical consensus ADMM.&lt;/p&gt;

&lt;p&gt;This is the right reading for students who will meet gossip SGD in distributed systems: first-order gossip is dual decomposition with a unit-step dual update and no AL; DFedADMM restores the AL and the dual memory.&lt;/p&gt;

&lt;h2 id=&quot;federated-rl-admm-on-a-natural-policy-gradient-step&quot;&gt;Federated RL: ADMM on a natural-policy-gradient step&lt;/h2&gt;

&lt;p&gt;Khodadadian, Chen, Maguluri, and collaborators / the NeurIPS 2023 paper “Improved Communication Efficiency in Federated Natural Policy Gradient via ADMM-based Gradient Updates” replace an \(O(d^2)\) Fisher solve by an ADMM splitting that communicates \(O(d)\) numbers per round. Federated NPG is a second-order policy step (a cousin of Chapter 14); the communication reduction is &lt;em&gt;dual decomposition of that Newton system&lt;/em&gt;. The experiments on MuJoCo tasks show reward on par with full FedNPG and communication comparable to first-order FedPPO.&lt;/p&gt;

&lt;p&gt;The pattern to remember: whenever a federated method wants a &lt;em&gt;coupled&lt;/em&gt; local Newton or projection, ADMM is how you decouple it without sending a matrix.&lt;/p&gt;

&lt;h2 id=&quot;dual-decomposition-outside-the-datacenter&quot;&gt;Dual decomposition outside the datacenter&lt;/h2&gt;

&lt;p&gt;The same block-separable dual is how power-system OPF, multi-period energy dispatch, and some privacy-preserving medical models are still solved in 2022–2026: each agent keeps \(x_i\), a coordinator updates \(\lambda\) on the linking constraints (flow balance, shared risk). Bayesian-ADMM (2025, &lt;a href=&quot;https://arxiv.org/abs/2506.13150&quot;&gt;arXiv:2506.13150&lt;/a&gt;) recasts the ADMM fixed point as a variational-Bayes duality and recovers Newton-like and Adam-like federated variants by changing the exponential-family posterior — a survey-level pointer, not a new required algorithm.&lt;/p&gt;

&lt;p&gt;Chapter 29 will contrast FedAvg with ADMM as &lt;em&gt;systems&lt;/em&gt; choices. This lesson is the optimisation reason they differ: &lt;strong&gt;dual variables are the memory of violated consensus&lt;/strong&gt;. If you delete them, you get averaging. If you keep them and a quadratic AL, you get the methods of this chapter, which is why they reappear every time federated data are heterogeneous.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;S. Zhou, G. Y. Li, “Federated Learning via Inexact ADMM,” 2022. &lt;a href=&quot;https://arxiv.org/abs/2204.10607&quot;&gt;arXiv:2204.10607&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Y. Song, Z. Wang, E. Zuazua, “FedADMM-InSa: An Inexact and Self-Adaptive ADMM for Federated Learning,” 2024. &lt;a href=&quot;https://arxiv.org/abs/2402.13989&quot;&gt;arXiv:2402.13989&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Q. Li, L. Shen, G. Li, Q. Yin, D. Tao, “DFedADMM: Dual Constraints Controlled Model Inconsistency for Decentralized Federated Learning,” 2023. &lt;a href=&quot;https://arxiv.org/abs/2308.08290&quot;&gt;arXiv:2308.08290&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;“Improved Communication Efficiency in Federated Natural Policy Gradient via ADMM-based Gradient Updates,” NeurIPS 2023.&lt;/li&gt;
  &lt;li&gt;“Federated ADMM from Bayesian Duality,” 2025. &lt;a href=&quot;https://arxiv.org/abs/2506.13150&quot;&gt;arXiv:2506.13150&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;S. Boyd, N. Parikh, E. Chu, B. Peleato, J. Eckstein, “Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers,” &lt;em&gt;Found. Trends Mach. Learn.&lt;/em&gt; 2011 (the skeleton all of the above reuse).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>19-08 Modern applications of proximal Newton methods (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_08_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_08_modern_applications</id>
   <content type="html">&lt;p&gt;Between 2022 and 2026, proximal Newton methods quietly crossed a major scalability frontier. In high-dimensional genomics, where precision matrices have \(p \approx 20{,}000\) genes (over 200 million matrix entries), classical Graphical Lasso and even QUIC hit a memory and speed wall. New solvers like &lt;strong&gt;MARS&lt;/strong&gt; (adaptive KKT sieving + semismooth Newton augmented Lagrangian) and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt;’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newton-cholesky&lt;/code&gt; GLM path show that the core insight of Chapter 19—couple second-order curvature with exact nonsmooth structure, and shrink the working set via KKT certificates—scales to modern data science.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-modern-second-order-composite-solvers-20222026&quot;&gt;Key ideas: Modern Second-Order Composite Solvers (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Adaptive KKT Sieving (MARS, JMLR 2023):&lt;/strong&gt; Before forming a huge Hessian, check the KKT optimality condition $$&lt;/td&gt;
          &lt;td&gt;\nabla_j g(x)&lt;/td&gt;
          &lt;td&gt;&amp;lt; \lambda$$ to certify coordinates that must be zero, solving the semismooth Newton system only on the tiny surviving active set.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Semismooth Newton Augmented Lagrangian (SSNAL):&lt;/strong&gt; Applies generalized Newton steps to the continuously differentiable (but piecewise-smooth) augmented Lagrangian dual, achieving superlinear convergence on massive \(\ell_1\)-penalized D-trace and Lasso paths.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Production GLM Solvers (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newton-cholesky&lt;/code&gt; in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt;):&lt;/strong&gt; When \(h(\beta) = \frac{\alpha}{2}\|\beta\|_2^2\) is quadratic ridge, proximal Newton reduces to a single Cholesky solve of \((X^T W X + \alpha I) v = -\nabla f\), outperforming L-BFGS whenever \(n \gg p\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Support Identification &amp;amp; Local Quadratic Polishing:&lt;/strong&gt; Across all modern applications, the winning pattern is identical: identify the sparse support cheaply, then let second-order curvature polish the free variables to \(10^{-10}\) accuracy in 3–5 steps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-kkt-active-set-sieving-on-a-3-feature-lasso&quot;&gt;Worked example: KKT Active-Set Sieving on a 3-Feature Lasso&lt;/h3&gt;

&lt;p&gt;Consider \(\min_{x \in \mathbb{R}^3} \frac{1}{2}\|Ax - b\|_2^2 + \lambda\|x\|_1\) with \(\lambda = 2\), where at the current iterate \(x^k = (1, 0, 0)^T\) the smooth gradient is \(\nabla g(x^k) = (-2.0, \; 0.3, \; -0.5)^T\) and the Hessian is \(H = A^T A = \begin{bmatrix} 4 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 5 &amp;amp; 2 \\ 0 &amp;amp; 2 &amp;amp; 6 \end{bmatrix}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Test the KKT zero-optimality condition $$&lt;/td&gt;
          &lt;td&gt;\nabla_j g(x^k)&lt;/td&gt;
          &lt;td&gt;&amp;lt; \lambda$$ on zero coordinates:**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Coordinate 1 is nonzero (\(x_1^k = 1\)) \(\implies\) stays in the &lt;strong&gt;active set&lt;/strong&gt; \(\mathcal{A}\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Coordinate 2 has \(x_2^k = 0\) and $$&lt;/td&gt;
              &lt;td&gt;\nabla_2 g(x^k)&lt;/td&gt;
              &lt;td&gt;= 0.3 &amp;lt; 2 = \lambda\(\)\implies\(**sieved out** (fixed at\)v_2 = 0$$).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Coordinate 3 has \(x_3^k = 0\) and $$&lt;/td&gt;
              &lt;td&gt;\nabla_3 g(x^k)&lt;/td&gt;
              &lt;td&gt;= 0.5 &amp;lt; 2 = \lambda\(\)\implies\(**sieved out** (fixed at\)v_3 = 0$$).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the reduced Newton system on \(\mathcal{A} = \{1\}\) only:&lt;/strong&gt;
Instead of factoring the \(3 \times 3\) matrix \(H\) (or a \(20{,}000 \times 20{,}000\) matrix in genomics!), we only solve the \(1 \times 1\) subproblem:
\(\min_{v_1} \; -2.0 v_1 + \frac{1}{2}(4)v_1^2 + 2|1 + v_1| \implies -2 + 4v_1 + 2 = 0 \implies v_1 = 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Global KKT certification:&lt;/strong&gt;
At \(x^k = (1, 0, 0)^T\), \(\nabla_1 g + 2\operatorname{sign}(1) = -2 + 2 = 0\) and \(|\nabla_2 g|, |\nabla_3 g| &amp;lt; 2\)—so KKT sieving just certified global optimality using a \(1 \times 1\) solve instead of a \(3 \times 3\) solve!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Proximal Newton applies a quadratic model to the &lt;em&gt;smooth&lt;/em&gt; piece \(g\) and leaves the &lt;em&gt;nonsmooth&lt;/em&gt; piece \(h\) inside the subproblem&lt;/p&gt;

\[v^{+} = \arg\min_v\ \nabla g(x)^\top v + \tfrac12 v^\top H v + h(x+v),\qquad H\approx\nabla^2 g(x).\]

&lt;p&gt;When \(h=\lambda\|\cdot\|_1\) that inner problem is a Lasso; when \(h\) is an indicator it is a constrained quadratic. The 2014 theory (Lee, Sun, Saunders) and the classical implementations (glmnet, QUIC) are still the right mental model. What changed in 2022–2026 is scale: second-order composite solvers now finish precision-matrix paths that first-order glasso cannot, and production GLM libraries grew an explicit Newton–Cholesky path that is proximal Newton with \(h=\frac{\alpha}{2}\|\cdot\|_2^2\).&lt;/p&gt;

&lt;h2 id=&quot;graphical-models-from-quic-to-mars&quot;&gt;Graphical models: from QUIC to MARS&lt;/h2&gt;

&lt;p&gt;QUIC (Hsieh, Sustik, Dhillon, Ravikumar, JMLR 2014) is the example already in 19-05: a Newton quadratic on \(-\log\det\Theta+\langle S,\Theta\rangle\) with an \(\ell_1\) penalty, inner coordinate descent, and superlinear convergence. It remains a standard reference. &lt;strong&gt;MARS&lt;/strong&gt; (Li, Jiang, Sun, JMLR 2023) is the 2020s sequel that students should cite for &lt;em&gt;high-dimensional&lt;/em&gt; precision matrices. The estimator is an \(\ell_1\)-penalised D-trace loss rather than glasso; the algorithm is adaptive sieving (drop coordinates certified zero by KKT) plus a &lt;strong&gt;semismooth Newton augmented Lagrangian&lt;/strong&gt; (SSNAL) solve on each reduced dual. The authors report paths on problems with \(p\approx 2\times 10^4\) (breast-cancer gene-expression, hundreds of millions of dual variables before sieving) where glasso and QUIC stall.&lt;/p&gt;

&lt;p&gt;Two Chapter 19 morals travel intact. First, the expensive object is still a &lt;em&gt;scaled proximal map&lt;/em&gt; (here a dual Newton system), not a full dense Hessian of all \(p^2\) entries. Second, active-set / sieving is how proximal Newton stays cheaper than proximal gradient: once the support is identified, quadratic convergence on the free set looks like the local analysis of 19-04. Genomics and Gaussian Markov random fields are the application, not a metaphor — the package is &lt;a href=&quot;https://github.com/QianLI-QL/MARS&quot;&gt;QianLI-QL/MARS&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;glms-in-scikit-learn-newton-when-h-is-quadratic-l-bfgs-when-it-is-not&quot;&gt;GLMs in scikit-learn: Newton when \(h\) is quadratic, L-BFGS when it is not&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PoissonRegressor(..., solver=&quot;newton-cholesky&quot;)&lt;/code&gt; (scikit-learn 1.2, 2022) and the later logistic extension form \(H=\nabla^2 g+\alpha I\) and Cholesky-solve the Newton step. The \(\alpha\|w\|_2^2\) term is Tikhonov / ridge: the composite view is \(g=\) negative log-likelihood, \(h=\frac{\alpha}{2}\|w\|_2^2\), and the proximal map of a strongly convex quadratic is itself a linear solve — so proximal Newton &lt;em&gt;collapses&lt;/em&gt; to damped Newton. That is the “when would we use proximal Newton?” table of 19-03 in library form: if \(h\) is cheap (ridge, box, \(\ell_1\) with coordinate descent), a Hessian of \(g\) is worth forming whenever \(d\) is small.&lt;/p&gt;

&lt;p&gt;Keep L-BFGS (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;lbfgs&quot;&lt;/code&gt;) for the wide, bound-constrained case (Chapter 18) and SAGA for the huge, sparse, \(\ell_1\) case (Chapter 26). Proximal Newton is the &lt;em&gt;middle&lt;/em&gt; of that menu: moderate \(d\), expensive \(g\), structured \(h\).&lt;/p&gt;

&lt;h2 id=&quot;glmnet-and-liblinear-still-the-sparse-glm-workhorses&quot;&gt;glmnet and LIBLINEAR, still the sparse-GLM workhorses&lt;/h2&gt;

&lt;p&gt;Friedman, Hastie, Tibshirani’s &lt;strong&gt;glmnet&lt;/strong&gt; (the 19-05 citation) remains the path algorithm in R and in Python wrappers through 2026: cyclic coordinate descent on the inner quadratic, which &lt;em&gt;is&lt;/em&gt; a proximal-Newton / IRLS outer loop. LIBLINEAR’s trust-region Newton for \(\ell_2\)-regularised logistic / SVM, and NewGLMNET for \(\ell_1\), are the same idea with a different inner solver. They are not new papers, but they are the codes that still train sparse logistic models on click-through and medical tabular data while deep-learning papers discuss Sophia. A course that teaches proximal Newton and then never names &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet::glmnet&lt;/code&gt; has skipped the application.&lt;/p&gt;

&lt;p&gt;The 2022–2026 increment is integration: scikit-learn’s GLM rewrite, biglasso-style out-of-core paths, and SSNAL-based composite solvers (the Sun–Toh line) made the &lt;em&gt;same&lt;/em&gt; outer iteration reliable at sizes glmnet’s dense-enough-to-fit-in-RAM assumption does not cover.&lt;/p&gt;

&lt;h2 id=&quot;how-to-tell-a-proximal-newton-paper-from-a-first-order-one&quot;&gt;How to tell a proximal-Newton paper from a first-order one&lt;/h2&gt;

&lt;p&gt;Look at the inner problem. If each iteration solves a &lt;em&gt;quadratic plus \(h\)&lt;/em&gt; (Lasso, box QP, dual Newton on a cone) to moderate accuracy and then takes a line search on the composite objective, it is Chapter 19. If each iteration is a gradient step plus a closed-form shrink, it is Chapter 09. MARS, QUIC, glmnet, and Newton–Cholesky sit on the first side; ISTA, FISTA, and SAGA sit on the second. Hybrid papers (inexact inner solves, quasi-Newton \(H_k\)) are 19-06, and they are how you scale when \(\nabla^2 g\) itself is only available as a Hessian–vector product.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Q. Li, B. Jiang, D. Sun, “MARS: A Second-Order Reduction Algorithm for High-Dimensional Sparse Precision Matrices Estimation,” JMLR 24, 2023. &lt;a href=&quot;https://jmlr.org/papers/v24/21-0699.html&quot;&gt;paper&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;C.-J. Hsieh, M. A. Sustik, I. S. Dhillon, P. Ravikumar, “QUIC: Quadratic Approximation for Sparse Inverse Covariance Estimation,” JMLR 15, 2014.&lt;/li&gt;
  &lt;li&gt;J. Lee, Y. Sun, M. A. Saunders, “Proximal Newton-type methods for minimizing composite functions,” SIAM J. Optim. 24(3), 2014.&lt;/li&gt;
  &lt;li&gt;J. Friedman, T. Hastie, R. Tibshirani, “Regularization paths for generalized linear models via coordinate descent,” J. Stat. Softw. 33(1), 2010 (glmnet; still the production path).&lt;/li&gt;
  &lt;li&gt;scikit-learn 1.2+ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newton-cholesky&lt;/code&gt; GLM solver.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>18-08 Modern applications of quasi-Newton methods (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_08_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_08_modern_applications</id>
   <content type="html">&lt;p&gt;With stochastic first-order optimizers like Adam dominating deep learning headlines, it is tempting to assume quasi-Newton methods were left behind in the 1990s. The reality of 2022–2026 scientific computing is the exact opposite: whenever a loss involves stiff differential operators (Physics-Informed Neural Networks, PIKANs, DeepONets) or high-accuracy tabular generalized linear models, diagonal adaptive methods stall on off-diagonal curvature—and &lt;strong&gt;L-BFGS&lt;/strong&gt;, &lt;strong&gt;self-scaled Broyden updates&lt;/strong&gt;, and &lt;strong&gt;L-BFGS-B&lt;/strong&gt; step in to drop residuals by three to five orders of magnitude.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-quasi-newton-thrives-in-modern-sciml--tabular-ml&quot;&gt;Key ideas: Why Quasi-Newton Thrives in Modern SciML &amp;amp; Tabular ML&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ill-Conditioned PDE Spectra in PINNs:&lt;/strong&gt; Differential operators like \(\Delta u\) couple neighboring spatial modes tightly, producing Hessians with massive condition numbers and strong off-diagonal structure that diagonal preconditioners (Adam) cannot invert.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Two-Stage Hybrid Training (Adam \(\to\) L-BFGS):&lt;/strong&gt; Standard scientific ML pipelines run Adam first to escape noisy nonconvex saddles, then switch to L-BFGS with a Wolfe line search once inside a smoother basin—combining global exploration with rapid second-order polishing.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Oren–Luenberger Self-Scaled Broyden Updates (SSBFGS):&lt;/strong&gt; Rescaling \(H_k \leftarrow \gamma_k H_k\) before the Broyden update prevents huge step-length oscillations across PDE residual scales, dramatically improving PINN and DeepONet convergence without manual loss-weight tuning.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;L-BFGS-B for Bound-Constrained Production ML:&lt;/strong&gt; SciPy’s L-BFGS-B (the default solver behind &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt;’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LogisticRegression&lt;/code&gt;) combines limited-memory curvature with projected gradient Cauchy points to handle box constraints \(l \le x \le u\) at scale.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-how-self-scaling-fixes-a-104-pde-spectrum-mismatch&quot;&gt;Worked example: How Self-Scaling Fixes a \(10^4\) PDE Spectrum Mismatch&lt;/h3&gt;

&lt;p&gt;Suppose a discretized 2-mode PDE residual has quadratic loss \(f(x) = \frac{1}{2}(x_1^2 + 10^4 x_2^2)\), and after an initial step \(s = (0, 1)^T\) along the stiff high-frequency mode we observe \(y = (0, 10^4)^T\), starting from \(H_0 = I_2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Standard unscaled BFGS update:&lt;/strong&gt;
Here \(\rho = \frac{1}{y^T s} = 10^{-4}\), \(V = I - \rho s y^T = \operatorname{diag}(1, 0)\). Thus:
\(H_1^{\text{BFGS}} = V I V^T + \rho s s^T = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 10^{-4} \end{bmatrix}.\)
Now suppose instead the step was diagonal: \(s = (1, 1)^T\), \(y = (1, 10^4)^T\) (so \(y^T s = 10{,}001\) and \(y^T y = 10^8 + 1\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Oren–Luenberger self-scaling factor \(\gamma = \frac{y^T s}{y^T H_0 y}\):&lt;/strong&gt;
\(\gamma = \frac{10{,}001}{10^8 + 1} \approx 1.0001 \times 10^{-4}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare the trace / scale of \(H_0\) vs. \(\gamma H_0\) before updating:&lt;/strong&gt;
Unscaled \(H_0 = I_2\) assumes curvature \(1\) in all directions—off by a factor of \(10^4\) in the stiff mode, which causes line-search backtracking failures when the PDE residual jumps. Rescaling \(H_0 \to \gamma H_0 \approx 10^{-4} I_2\) immediately brings the Hessian inverse onto the same order of magnitude as the stiffest PDE eigenvalue, allowing the very next Wolfe step to accept \(\alpha = 1\) cleanly!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Quasi-Newton methods replace \(\nabla^2 f(x)\) by a matrix \(B\) that obeys the secant equation \(B^{+}s = y\) and (for BFGS/L-BFGS) stays positive definite under the curvature condition \(y^\top s &amp;gt; 0\). The 2022–2026 applications that still &lt;em&gt;look like this chapter&lt;/em&gt; are not the LLM pre-trainers that estimate a diagonal Hessian (those belong with Newton / Sophia in Chapter 14). They are the codes that keep a short history of \((s,y)\) pairs — L-BFGS in scientific machine learning and in classical tabular models — and the structured preconditioners (Shampoo / SOAP) that are BFGS’s Kronecker cousins.&lt;/p&gt;

&lt;h2 id=&quot;pinns-adam-to-get-close-l-bfgs-to-finish&quot;&gt;PINNs: Adam to get close, L-BFGS to finish&lt;/h2&gt;

&lt;p&gt;Physics-informed neural networks minimise a residual that contains differential operators. Those operators make the loss ill-conditioned: the Hessian’s eigenvalue range tracks the spectrum of a discretised PDE, not the spectrum of a cross-entropy. Rathore, Lei, Frangella, Lu, and Udell (ICML 2024) compare Adam, L-BFGS, and &lt;strong&gt;Adam+L-BFGS&lt;/strong&gt;, show that the combination dominates either method alone, and introduce NysNewton-CG as a further second-order refinement. The paper’s theoretical contribution is the link between ill-conditioned differential operators and an ill-conditioned PINN Hessian — which is exactly why a secant method, which accumulates curvature along the trajectory, outperforms a diagonal adaptive method that never sees off-diagonal residual couplings.&lt;/p&gt;

&lt;p&gt;The training recipe that papers actually ship is older than 2024 and still standard in 2026: run Adam until the residual is in a quadratic bowl, then switch to L-BFGS with a Wolfe line search. Urbán, Stefanou, Pons, et al. (2024, &lt;a href=&quot;https://arxiv.org/abs/2405.04230&quot;&gt;arXiv:2405.04230&lt;/a&gt;) state the same split and measure how much accuracy BFGS / L-BFGS add after the Adam prelude. This is Chapter 18 in a lab notebook: the two-loop recursion of 18-07, not a new optimiser.&lt;/p&gt;

&lt;h2 id=&quot;self-scaled-bfgs-on-pinns-pikans-and-deeponets&quot;&gt;Self-scaled BFGS on PINNs, PIKANs, and DeepONets&lt;/h2&gt;

&lt;p&gt;Kiyani, Shukla, Urbán, Darbon, and Karniadakis (2025, &lt;a href=&quot;https://arxiv.org/abs/2501.16371&quot;&gt;arXiv:2501.16371&lt;/a&gt;) revisit the Broyden class you studied in 18-05. &lt;strong&gt;Self-scaled BFGS&lt;/strong&gt; and &lt;strong&gt;self-scaled Broyden&lt;/strong&gt; rescale the Hessian approximation using the most recent curvature pair, which is a classical safeguard (Oren–Luenberger) against the wild step-length variation of PDE residuals. On Burgers, Allen–Cahn, Kuramoto–Sivashinsky, and Ginzburg–Landau, and on physics-informed Kolmogorov–Arnold networks, they report orders-of-magnitude residual improvements &lt;em&gt;without&lt;/em&gt; the adaptive loss weights that PINN papers usually need. The same updates help DeepONet training.&lt;/p&gt;

&lt;p&gt;Read this as a live Broyden-class experiment: \(\phi=0\) is BFGS, \(\phi=1\) is DFP, and a self-scaled member is a data-dependent \(\phi\) plus a scalar prefactor. The curvature condition \(y^\top s&amp;gt;0\) is enforced by the line search; when it fails, the pair is skipped — the same skip that L-BFGS implementations have always used.&lt;/p&gt;

&lt;h2 id=&quot;l-bfgs-b-as-the-quiet-default-in-tabular-ml&quot;&gt;L-BFGS-B as the quiet default in tabular ML&lt;/h2&gt;

&lt;p&gt;scikit-learn’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LogisticRegression(solver=&quot;lbfgs&quot;)&lt;/code&gt; and its GLM family (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;lbfgs&quot;&lt;/code&gt;, the default next to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newton-cholesky&lt;/code&gt;) call SciPy’s &lt;strong&gt;L-BFGS-B&lt;/strong&gt;: limited-memory BFGS with bound constraints. For \(n\) in the tens of thousands and \(d\) in the hundreds to low thousands, this is still the correct algorithm — cheaper than forming a Hessian, more accurate than SGD on a convex GLM, and warm-startable along a regularisation path. Hugging Face Trainer exposes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;optim=&quot;lbfgs&quot;&lt;/code&gt; for the rare fine-tune that is small enough; the important cultural fact is the opposite of the Sophia story: &lt;em&gt;when the model fits in a CPU Hessian sketch of a few dozen vectors, quasi-Newton beats Adam&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;A five-line check:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sklearn.linear_model&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LogisticRegression&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;clf&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;LogisticRegression&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;solver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;lbfgs&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;clf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_iter_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Compare with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;newton-cholesky&quot;&lt;/code&gt; (Chapter 14) on a tall design and with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;saga&quot;&lt;/code&gt; on a wide one. You are choosing among Newton, L-BFGS, and a variance-reduced first-order method using only the dimensions \(n,d\) and the constraint type.&lt;/p&gt;

&lt;h2 id=&quot;soap-shampoos-eigenbasis-as-a-structured-quasi-newton&quot;&gt;SOAP: Shampoo’s eigenbasis as a structured quasi-Newton&lt;/h2&gt;

&lt;p&gt;Vyas, Morwani, Zhao, Kwun, Shapira, Brandfonbrener, Janson, and Kakade (ICLR 2025) introduce &lt;strong&gt;SOAP&lt;/strong&gt; (&lt;em&gt;ShampoO with Adam in the Preconditioner’s eigenbasis&lt;/em&gt;). Shampoo (Gupta, Koren, Singer, 2018; the 2023–2024 large-scale revivals) maintains Kronecker-factored second-moment matrices and is a structured quasi-Newton / natural-gradient hybrid. SOAP proves that Shampoo with the square-root inverse is Adafactor run in Shampoo’s eigenbasis, then &lt;em&gt;replaces&lt;/em&gt; Adafactor by AdamW in that slowly moving basis. On 360M and 660M language models, in the large-batch regime, SOAP cuts iteration count by more than 40% and wall-clock by more than 35% versus AdamW, and by about 20% versus Shampoo.&lt;/p&gt;

&lt;p&gt;This is not L-BFGS — there is no \((s,y)\) pair — but it is the same design thesis as DFP/BFGS: &lt;em&gt;estimate a positive-definite curvature, invert it cheaply, refresh it on a slower schedule than the gradient.&lt;/em&gt; The extra hyperparameter is the eigendecomposition frequency, analogous to L-BFGS memory \(m\). Place SOAP next to K-FAC (Chapter 14) in a seminar; place L-BFGS next to PINNs in a lab.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;P. Rathore, W. Lei, Z. Frangella, L. Lu, M. Udell, “Challenges in Training PINNs: A Loss Landscape Perspective,” ICML 2024, PMLR 235.&lt;/li&gt;
  &lt;li&gt;W. Urbán et al., “Unveiling the optimization process of Physics Informed Neural Networks,” 2024. &lt;a href=&quot;https://arxiv.org/abs/2405.04230&quot;&gt;arXiv:2405.04230&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;E. Kiyani, K. Shukla, J. F. Urbán, J. Darbon, G. E. Karniadakis, “Optimizing the Optimizer for Physics-Informed Neural Networks and Kolmogorov-Arnold Networks,” 2025. &lt;a href=&quot;https://arxiv.org/abs/2501.16371&quot;&gt;arXiv:2501.16371&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;N. Vyas et al., “SOAP: Improving and Stabilizing Shampoo using Adam,” ICLR 2025. &lt;a href=&quot;https://arxiv.org/abs/2409.11321&quot;&gt;arXiv:2409.11321&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SciPy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L-BFGS-B&lt;/code&gt;; scikit-learn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LogisticRegression(solver=&quot;lbfgs&quot;)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>17-06 Modern applications of primal-dual interior-point methods (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_06_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_06_modern_applications</id>
   <content type="html">&lt;p&gt;A decade ago, primal-dual interior-point methods were often taught as an elegant but somewhat heavy 1990s technology—too expensive for machine learning and too brittle for raw industrial pipelines. Between 2022 and 2026, that narrative flipped completely. Homogeneous conic solvers like Clarabel became the default backend inside CVXPY, GPU sparse direct factorizations brought PD-IPMs onto NVIDIA hardware (CuClarabel), and SDP relaxations for neural-network robustness pushed interior-point theory to its sharpest geometric edge: what happens when Slater’s condition fails and the interior itself vanishes.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-modern-conic-pd-ipms-in-practice&quot;&gt;Key ideas: Modern Conic PD-IPMs in Practice&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Homogeneous Self-Dual Embedding:&lt;/strong&gt; Classical PD-IPMs diverge unpredictably on infeasible or unbounded problems. Modern solvers (Clarabel, MOSEK) embed the problem in a homogeneous self-dual cone with scaling variables \((\tau, \kappa)\), guaranteeing a well-defined central path that returns either an optimal solution or an Farkas infeasibility certificate.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Symmetric &amp;amp; Nonsymmetric Cones:&lt;/strong&gt; Beyond LP/QP/SOCP/SDP, modern libraries handle exponential cones (logistic regression, entropy) and power cones inside the same unified KKT Newton factorization.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;GPU Sparse Direct KKT Factorizations:&lt;/strong&gt; Because PD-IPM’s runtime is dominated by sparse \(LDL^T\) factorization of the KKT matrix, GPU solvers like CuClarabel (using cuDSS) accelerate medium-to-large conic QPs by an order of magnitude while retaining \(10^{-8}\) duality-gap certificates.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Facial Reduction &amp;amp; Interior-Point Vanishing:&lt;/strong&gt; In SDP relaxations of ReLU neural networks, algebraic couplings often force every feasible matrix \(X \succeq 0\) onto a low-rank boundary face (no \(X \succ 0\) exists), causing standard IPMs to stall unless facial reduction or regularization restores strict feasibility.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-diagnosing-an-interior-point-vanishing-sdp&quot;&gt;Worked example: Diagnosing an Interior-Point Vanishing SDP&lt;/h3&gt;

&lt;p&gt;Consider a tiny \(2 \times 2\) SDP mimicking a degenerate ReLU-network verification constraint:
\(\min_{X \succeq 0} \; X_{22} \quad \text{subject to} \quad X_{11} = 0, \quad X_{11} + 2X_{12} + X_{22} = 1.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test Slater’s strict feasibility condition:&lt;/strong&gt;
Any feasible \(X = \begin{bmatrix} X_{11} &amp;amp; X_{12} \\ X_{12} &amp;amp; X_{22} \end{bmatrix} \succeq 0\) has \(X_{11} = 0\). For \(X\) to be positive semidefinite, its determinant must satisfy:
\(X_{11} X_{22} - X_{12}^2 = -X_{12}^2 \ge 0 \implies X_{12} = 0.\)
Therefore, &lt;strong&gt;no strictly positive definite matrix \(X \succ 0\) is feasible&lt;/strong&gt;—the relative interior of the feasible set is empty!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;See what happens to a naive PD-IPM central path:&lt;/strong&gt;
A primal-dual solver attempts to maintain \(X \succ 0\) and \(S \succ 0\) with \(XS = \mu I\). As \(X_{11} \to 0^+\) to satisfy the first constraint, \(S_{11} = \mu / X_{11} \to +\infty\), blowing up the dual multiplier and destabilizing the KKT factorization before the duality gap can certify optimality.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply facial reduction to restore strict feasibility:&lt;/strong&gt;
Since \(X_{11} = 0\) and \(X \succeq 0\) force the first row and column of \(X\) to vanish, every feasible matrix lies on the \(1 \times 1\) face \(X = \begin{bmatrix} 0 &amp;amp; 0 \\ 0 &amp;amp; z \end{bmatrix}\) with \(z \ge 0\). Substituting into the second constraint yields \(z = 1 &amp;gt; 0\), a strictly feasible \(1 \times 1\) SDP with immediate certificate \(f^\star = 1\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A primal-dual interior-point method takes &lt;em&gt;one&lt;/em&gt; Newton step on the perturbed KKT map&lt;/p&gt;

\[r_t(x,u,v) = 0\]

&lt;p&gt;instead of driving a barrier problem to high accuracy at every \(t\). The objects you computed in this chapter — the surrogate duality gap \(-h(x)^\top u\), the primal and dual residuals, the linearised complementarity block \(U\nabla h(x)\,\Delta x + H(x)\,\Delta u = -Uh(x) - (1/t)\mathbf{1}\) — are exactly the residuals modern cone solvers print. The 2022–2026 story is that those solvers became the default Python backend, then moved onto GPUs, and then ran into the limits of SDP relaxations for neural-network verification.&lt;/p&gt;

&lt;h2 id=&quot;clarabel-pd-ipm-as-a-library-not-a-homework-exercise&quot;&gt;Clarabel: PD-IPM as a library, not a homework exercise&lt;/h2&gt;

&lt;p&gt;Clarabel (Goulart &amp;amp; Chen, 2024) implements a homogeneous primal-dual interior-point iteration for quadratic objectives over a product of symmetric and nonsymmetric cones. Relative to a textbook PD-IPM it adds: a homogeneous embedding (so infeasible and unbounded instances have well-posed central paths), Mehrotra-style correctors, and a sparse LDL factorisation of the KKT Newton system. The authors report that the solver is faster and more robust than several commercial and open-source competitors on standard benchmarks, &lt;em&gt;especially&lt;/em&gt; on QPs — the case this chapter’s Newton system was built for.&lt;/p&gt;

&lt;p&gt;CVXPY 1.5 made Clarabel the default engine for the problem classes that previously fell through to ECOS. A student who writes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prob.solve()&lt;/code&gt; on an SOCP is therefore running Chapter 17, not a simplex tableau. The dual variables returned by CVXPY are the \(u,v\) of this chapter; the complementarity residual is the surrogate gap. That single fact is worth more than a new derivation: &lt;em&gt;you already have a PD-IPM on your laptop&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;cuclarabel-the-same-newton-system-on-a-gpu&quot;&gt;CuClarabel: the same Newton system on a GPU&lt;/h2&gt;

&lt;p&gt;Chen, Tse, Nobel, Goulart, and Boyd (2024) port the iteration to NVIDIA GPUs as &lt;strong&gt;CuClarabel&lt;/strong&gt;. The algorithm is still a primal-dual interior-point method: a setup phase equilibrates data, a solve phase builds and factors the Newton system, and cones are processed with a mixed parallel strategy (linear constraints first, then other cones in parallel). The linear algebra is delegated to NVIDIA cuDSS, with an optional mixed-precision factorisation. Supported cones include the zero and nonnegative cones, second-order, exponential and power cones, and same-dimension PSD cones. The paper shows GPU IPM beating CPU IPM across a range of conic programs; the public examples include a portfolio QP — the same SOCP you can write in JuMP or CVXPY.&lt;/p&gt;

&lt;p&gt;This is the complexity discussion of Chapter 17 made concrete. The bottleneck of PD-IPM was never the three-line update; it was the KKT factorisation. Once that factorisation is a GPU sparse direct solve, interior-point methods become plausible for the cone sizes that data-science pipelines actually emit (thousands to tens of thousands of variables), while first-order splitting remains the tool for millions of variables with modest accuracy.&lt;/p&gt;

&lt;h2 id=&quot;sdp-relaxations-for-neural-network-verification&quot;&gt;SDP relaxations for neural-network verification&lt;/h2&gt;

&lt;p&gt;Semidefinite relaxations of ReLU networks produce an SDP whose optimal value certifies robustness (Raghunathan, Steinhardt, Liang, and the line of SDP-NN verifiers). Those SDPs are solved by primal-dual interior-point methods when a &lt;em&gt;certificate&lt;/em&gt; is required: first-order methods may look converged without a duality-gap proof. A 2025 analysis, “Interior-Point Vanishing Problem in Semidefinite Relaxations for Neural Network Verification” (&lt;a href=&quot;https://arxiv.org/abs/2506.10269&quot;&gt;arXiv:2506.10269&lt;/a&gt;), shows what happens when the relaxation is &lt;em&gt;not&lt;/em&gt; strictly feasible: the central path has no interior, strong duality can fail, and a PD-IPM that monitors the gap \(X\cdot S\) may never declare optimality. The authors use high-precision IPMs (SDPA-GMP) to diagnose the pathology and propose regularised / face-reduced SDPs.&lt;/p&gt;

&lt;p&gt;This is Chapter 17’s SDP section meeting a modern ML task. The central-path equation \(XS = \tau I\) assumes \(X,S\succ 0\). If the spectrahedron has empty relative interior, the hypothesis is false and the algorithm you implemented in 17-02 is not merely slow — it is &lt;em&gt;ill-posed&lt;/em&gt;. The lesson is the one Boyd–Vandenberghe already taught: check Slater, then trust the gap.&lt;/p&gt;

&lt;h2 id=&quot;what-to-run-in-this-course&quot;&gt;What to run in this course&lt;/h2&gt;

&lt;p&gt;For a one-hour lab, take a small long-only portfolio or a hard-margin SVM, solve it with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.CLARABEL&lt;/code&gt;, and print the primal residual, dual residual, and gap. Then change the cone (box vs second-order) and watch the Newton iteration count. That is a primal-dual interior-point method applied to a data-science model, with no new theory beyond this chapter.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;P. J. Goulart, Y. Chen, “Clarabel: An interior-point solver for conic programs with quadratic objectives,” 2024. &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv:2405.12762&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Y. Chen, D. Tse, P. Nobel, P. Goulart, S. Boyd, “CuClarabel: GPU Acceleration for a Conic Optimization Solver,” 2024. &lt;a href=&quot;https://arxiv.org/abs/2412.19027&quot;&gt;arXiv:2412.19027&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;CVXPY 1.5: Clarabel as default IPM backend.&lt;/li&gt;
  &lt;li&gt;“Interior-Point Vanishing Problem in Semidefinite Relaxations for Neural Network Verification,” 2025. &lt;a href=&quot;https://arxiv.org/abs/2506.10269&quot;&gt;arXiv:2506.10269&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>16-04 Modern applications of duality (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_04_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_04_modern_applications</id>
   <content type="html">&lt;p&gt;When you read papers from 2022–2026 on aligning large language models with human feedback (InstructGPT / RLHF), training safe robots (OmniSafe), or computing single-cell trajectories with optimal transport, you might not expect to see Chapter 16’s Lagrangians and Fenchel conjugates on page 2. Yet every one of those breakthroughs relies on the same three dual moves: turning a regularizer’s conjugate into a &lt;strong&gt;Fenchel–Young training loss&lt;/strong&gt;, pricing a KL divergence constraint with a &lt;strong&gt;Lagrange multiplier&lt;/strong&gt;, and solving &lt;strong&gt;entropic optimal transport&lt;/strong&gt; via its unconstrained Fenchel dual!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-duality-as-a-20222026-ml-design-pattern&quot;&gt;Key ideas: Duality as a 2022–2026 ML Design Pattern&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Fenchel–Young Losses:&lt;/strong&gt; For any convex regularizer \(\Omega\), the Fenchel–Young gap \(L_\Omega(\theta; y) = \Omega^*(\theta) + \Omega(y) - \theta^T y \ge 0\) is automatically a convex, nonnegative loss that equals \(0\) iff \(y = \nabla\Omega^*(\theta)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — RLHF &amp;amp; DPO as Constrained Lagrangian Duality:&lt;/strong&gt; Maximizing expected reward subject to \(\mathrm{KL}(\pi \| \pi_{\mathrm{SFT}}) \le \varepsilon\) produces the exact Lagrangian \(\mathbb{E}[r(x,y)] - \beta\,\mathrm{KL}(\pi \| \pi_{\mathrm{SFT}})\), where \(\beta \ge 0\) is the dual price of drifting from the reference model.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Primal–Dual Safe RL (CMDPs):&lt;/strong&gt; Algorithms like PPO-Lagrangian run primal policy steps alternating with dual-ascent updates \(\lambda_{k+1} = [\lambda_k + \eta(J_C(\pi_k) - d)]_+\) to enforce safety budgets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Sinkhorn Potentials as Fenchel Duals:&lt;/strong&gt; Entropic optimal transport dualizes the marginal constraints into an unconstrained concave maximization over dual potentials \((f, g)\), enabling GPU-parallel Sinkhorn iterations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-deriving-cross-entropy-as-a-fenchelyoung-loss&quot;&gt;Worked example: Deriving Cross-Entropy as a Fenchel–Young Loss&lt;/h3&gt;

&lt;p&gt;Let \(\Omega(p) = \sum_{i=1}^K p_i \log p_i + I_{\Delta_K}(p)\) be the negative entropy on the probability simplex \(\Delta_K\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the conjugate \(\Omega^*(\theta) = \max_{p \in \Delta_K} \left(\theta^T p - \sum_{i=1}^K p_i \log p_i\right)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Introducing Lagrange multiplier \(\nu\) for \(\sum_i p_i = 1\) gives \(\theta_i - \log p_i - 1 - \nu = 0 \implies p_i^\star = \frac{e^{\theta_i}}{\sum_j e^{\theta_j}} = \operatorname{softmax}(\theta)_i\).&lt;/li&gt;
      &lt;li&gt;Substituting \(p^\star\) back into \(\theta^T p - \sum p_i \log p_i\) yields the log-sum-exp function:
\(\Omega^*(\theta) = \log\left(\sum_{j=1}^K e^{\theta_j}\right).\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the Fenchel–Young loss for a one-hot label \(y = e_c\) (where \(\Omega(e_c) = 0\)):&lt;/strong&gt;
\(L_\Omega(\theta; e_c) = \Omega^*(\theta) + \Omega(e_c) - \theta^T e_c = \log\left(\sum_{j=1}^K e^{\theta_j}\right) - \theta_c = -\log\big(\operatorname{softmax}(\theta)_c\big).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical check for \(K = 2\), logits \(\theta = (1, 0)^T\), true class \(c = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\Omega^*(\theta) = \log(e^1 + e^0) = \log(3.7183) \approx 1.3133\).&lt;/li&gt;
      &lt;li&gt;\(L_\Omega(\theta; e_1) = 1.3133 + 0 - 1 = 0.3133 = -\log(0.7311)\)—exact cross-entropy loss, born directly from Fenchel duality!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chapter 16 revisits Lagrangian duality, KKT, and Fenchel conjugates so that the primal-dual interior-point method of Chapter 17 has somewhere to stand. The same three objects — a Lagrangian, a dual variable that prices a constraint, and a Fenchel conjugate that swaps a loss for a regulariser — are how 2022–2026 machine learning &lt;em&gt;writes objectives&lt;/em&gt;, not only how it proves them. The four applications below keep the math of this chapter visible: you should be able to name the primal, the constraint, and the dual variable in each story.&lt;/p&gt;

&lt;h2 id=&quot;fenchelyoung-losses-conjugates-as-training-objectives&quot;&gt;Fenchel–Young losses: conjugates as training objectives&lt;/h2&gt;

&lt;p&gt;Blondel, Martins, and Niculae (JMLR 2020) define a &lt;strong&gt;Fenchel–Young loss&lt;/strong&gt; from a regularised prediction function. If \(\Omega\) is a convex regulariser on the simplex (or a structured set) and \(\Omega^\star\) is its conjugate, the loss&lt;/p&gt;

\[L_\Omega(\theta; y) = \Omega^\star(\theta) + \Omega(y) - \theta^\top y\]

&lt;p&gt;is exactly the Fenchel–Young gap from &lt;a href=&quot;/contents/en/chapter16/16_03_fenchel_duality/&quot;&gt;16-03&lt;/a&gt;. Cross-entropy is the special case \(\Omega = \text{negentropy}\); sparse and structured losses appear by changing \(\Omega\). The construction is older than 2022, but it became a &lt;em&gt;design pattern&lt;/em&gt; in the years that followed. Blondel, Llinares-López, Dadashi, Hussenot, and Geist (NeurIPS 2022) lift it to energy networks by replacing the bilinear pairing with a general coupling (a generalised conjugate, including the \(C\)-transform of optimal transport). In 2025, sharpened Fenchel–Young losses are used for inverse unbalanced OT and inverse JKO gradient flows — including cell-population dynamics in single-cell genomics (arXiv:2505.07124).&lt;/p&gt;

&lt;p&gt;The classroom move is to take a loss you already know, write it as \(\Omega^\star(\theta)-\theta^\top y+\Omega(y)\), and read the dual variable as a &lt;em&gt;prediction&lt;/em&gt; rather than as a Lagrange multiplier. Duality is no longer only a certificate; it is the loss.&lt;/p&gt;

&lt;h2 id=&quot;rlhf-a-kl-constraint-and-its-lagrange-multiplier&quot;&gt;RLHF: a KL constraint and its Lagrange multiplier&lt;/h2&gt;

&lt;p&gt;Ouyang et al. (NeurIPS 2022), &lt;em&gt;Training language models to follow instructions with human feedback&lt;/em&gt; (InstructGPT), fine-tune a supervised model with PPO against a reward model, plus a &lt;strong&gt;per-token KL penalty&lt;/strong&gt; that keeps the policy near the SFT reference. The standard RLHF objective is the Lagrangian of&lt;/p&gt;

\[\max_\pi\ \mathbb{E}_{x\sim\mathcal{D},\, y\sim\pi(\cdot\mid x)}\bigl[r_\theta(x,y)\bigr]
\quad\text{subject to}\quad
\mathbb{E}\bigl[\mathrm{KL}(\pi(\cdot\mid x)\,\|\,\pi_{\mathrm{SFT}}(\cdot\mid x))\bigr] \le \varepsilon.\]

&lt;p&gt;The coefficient on the KL term is the dual variable of a divergence constraint. Increasing it is a dual ascent step: you raise the price of leaving the reference until the constraint is tolerable. Later alignment recipes (DPO and its cousins) rewrite the &lt;em&gt;same&lt;/em&gt; Lagrangian so that the optimal policy has a closed form and the dual coefficient becomes a temperature; the duality is still there, just solved analytically.&lt;/p&gt;

&lt;p&gt;This is the Chapter 16 story that students have already used as chatbots: strong duality is not claimed for a nonconvex policy class, but the &lt;em&gt;modelling&lt;/em&gt; — constrain first, price the constraint, read the multiplier as a knob — is Lagrangian duality in production.&lt;/p&gt;

&lt;h2 id=&quot;safe-rl-primaldual-loops-you-can-run&quot;&gt;Safe RL: primal–dual loops you can run&lt;/h2&gt;

&lt;p&gt;Constrained MDPs ask for a policy that maximises return subject to an expected-cost budget. PPO-Lagrangian and TRPO-Lagrangian (OpenAI Safety Gym, Ray et al. 2019) update the policy by PPO/TRPO and the multiplier by dual ascent on the cost residual — the textbook primal-dual method on a stochastic, nonconvex saddle. CPO (Achiam et al., 2017) linearises the constraint and solves a small QP; IPO (Chapter 15) uses a barrier instead of a multiplier. OmniSafe (Ji et al., JMLR 2024) and Safety Gymnasium (Ji et al., NeurIPS 2023) package these algorithms so that a 2024–2026 project can &lt;em&gt;compare&lt;/em&gt; barrier, primal-dual, and trust-region duals on the same robots.&lt;/p&gt;

&lt;p&gt;Paternain, Chamon, Calvo-Fullana, and Ribeiro (and the 2022 line of primal-dual SafeRL) give the convex-analytic backbone: the dual function of a CMDP is a concave program in the multiplier, and a small duality gap controls constraint violation. That is &lt;a href=&quot;/contents/en/chapter16/16_01_lagrangian_duality_revisited/&quot;&gt;16-01&lt;/a&gt; with an expectation inside every inner product.&lt;/p&gt;

&lt;h2 id=&quot;optimal-transport-as-a-fenchel-dual&quot;&gt;Optimal transport as a Fenchel dual&lt;/h2&gt;

&lt;p&gt;Entropic optimal transport,&lt;/p&gt;

\[\min_{\pi\in\Pi(\mu,\nu)}\ \langle C,\pi\rangle + \varepsilon\,\mathrm{KL}(\pi\,\|\,\mu\otimes\nu),\]

&lt;p&gt;has a Fenchel dual that is an unconstrained concave maximisation over two potentials — the Sinkhorn dual. Computational OT (Peyré &amp;amp; Cuturi’s monograph; the POT library) is how single-cell, domain adaptation, and generative-modelling papers in 2022–2026 move mass between empirical measures. Generalized Fenchel–Young losses (NeurIPS 2022) make the \(C\)-transform of that dual into a &lt;em&gt;training loss&lt;/em&gt; for energy models. If Fenchel duality in 16-03 felt abstract, this is the picture: the conjugate of a transport cost is a potential, and fitting those potentials is supervised learning.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;M. Blondel, A. F. T. Martins, V. Niculae, “Learning with Fenchel-Young Losses,” JMLR 21(35), 2020.&lt;/li&gt;
  &lt;li&gt;M. Blondel, F. Llinares-López, R. Dadashi, L. Hussenot, M. Geist, “Learning Energy Networks with Generalized Fenchel-Young Losses,” NeurIPS 2022.&lt;/li&gt;
  &lt;li&gt;“Learning from Samples: Inverse Problems over Measures via Sharpened Fenchel-Young Losses,” 2025. &lt;a href=&quot;https://arxiv.org/abs/2505.07124&quot;&gt;arXiv:2505.07124&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;L. Ouyang et al., “Training language models to follow instructions with human feedback,” NeurIPS 2022.&lt;/li&gt;
  &lt;li&gt;J. Ji et al., “OmniSafe,” JMLR 25(285), 2024; “Safety Gymnasium,” NeurIPS 2023 Datasets.&lt;/li&gt;
  &lt;li&gt;S. Paternain et al., primal-dual methods for constrained RL (2022 line); G. Peyré, M. Cuturi, &lt;em&gt;Computational Optimal Transport&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>15-09 Modern applications of the barrier method (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_09_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_09_modern_applications</id>
   <content type="html">&lt;p&gt;You might think you have never run a log-barrier method—until you write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prob.solve()&lt;/code&gt; in CVXPY 1.5+. Under the hood, &lt;strong&gt;Clarabel&lt;/strong&gt; immediately wraps your linear, quadratic, second-order-cone, or semidefinite constraints in self-concordant barriers and tracks a central path. Even more remarkably, in 2022–2026 that exact same barrier machinery powers safe reinforcement learning (&lt;strong&gt;IPO / OmniSafe&lt;/strong&gt;) and differentiable optimization layers inside PyTorch and JAX (&lt;strong&gt;cvxpylayers&lt;/strong&gt;)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-chapter-15-theory-to-20222026-systems&quot;&gt;Key ideas: From Chapter 15 Theory to 2022–2026 Systems&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Clarabel as CVXPY’s Default Conic IPM:&lt;/strong&gt; Clarabel solves conic QPs across nonnegative, second-order, exponential, power, and PSD cones using self-concordant barriers and sparse KKT Newton factorizations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — High-Accuracy Conic QPs vs. First-Order Splitting:&lt;/strong&gt; Barrier IPMs beat ADMM/OSQP whenever high precision (\(10^{-8}\) certificates) is needed in portfolio optimization, tracking-error SOCPs, and Model Predictive Control (MPC).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Log Barriers in Safe RL (IPO &amp;amp; OmniSafe):&lt;/strong&gt; Adding \(-\frac{1}{t}\log(d - J_C(\pi))\) directly to a policy objective keeps neural policies strictly inside safety budgets using first-order PPO updates when Hessians are too big to form.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Differentiable Optimization Layers (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt;):&lt;/strong&gt; Implicitly differentiating the central-path / KKT Jacobian lets deep networks backpropagate through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prob.solve()&lt;/code&gt; without unrolling iterative solvers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-implicit-differentiation-through-a-log-barrier-solution-map&quot;&gt;Worked example: Implicit Differentiation Through a Log-Barrier Solution Map&lt;/h3&gt;

&lt;p&gt;Suppose a differentiable layer solves the 1D barrier-regularized problem \(x^*(\theta) = \arg\min_{x &amp;gt; 0} \left(\frac{1}{2}(x - \theta)^2 - \frac{1}{t}\log(x)\right)\) for an upstream neural-network output \(\theta = 1\) with \(t = 1\). We want the backward-pass gradient \(\frac{dx^*}{d\theta}\) without unrolling Newton steps!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the implicit optimality equation \(F(x^*, \theta) = 0\):&lt;/strong&gt;
\(F(x^*, \theta) = (x^* - \theta) - \frac{1}{t x^*} = 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find the forward-pass solution at \(\theta = 1, t = 1\):&lt;/strong&gt;
\((x^*)^2 - x^* - 1 = 0 \implies x^*(1) = \frac{1 + \sqrt{5}}{2} \approx 1.6180 \quad (\text{golden ratio!}).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Differentiate \(F(x^*(\theta), \theta) = 0\) implicitly with respect to \(\theta\):&lt;/strong&gt;
\(\frac{\partial F}{\partial x^*}\frac{dx^*}{d\theta} + \frac{\partial F}{\partial \theta} = 0 \implies \left(1 + \frac{1}{t(x^*)^2}\right)\frac{dx^*}{d\theta} - 1 = 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve for \(\frac{dx^*}{d\theta}\) using the &lt;em&gt;exact&lt;/em&gt; Newton Hessian \(H = 1 + \frac{1}{(x^*)^2}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Since \((x^*)^2 = x^* + 1 \approx 2.6180\), \(H = 1 + \frac{1}{2.6180} \approx 1.3820\).&lt;/li&gt;
      &lt;li&gt;Backward gradient: \(\frac{dx^*}{d\theta} = H^{-1}(1) \approx \frac{1}{1.3820} \approx 0.7236\)!
The forward Newton Hessian directly gives the backward-pass derivative in one linear solve!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The log barrier&lt;/p&gt;

\[\phi(x) = -\sum_{i=1}^{m}\log\bigl(-h_i(x)\bigr)\]

&lt;p&gt;turns an inequality-constrained problem into a &lt;em&gt;smooth&lt;/em&gt; family of unconstrained (or equality-constrained) Newton problems indexed by a tightness parameter \(t\). That is still how industrial convex solvers think, even when the user never types &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log&lt;/code&gt;. This lesson follows the barrier from the central path you derived in this chapter into four places students actually meet in 2022–2026: the default CVXPY engine, GPU-era cone solvers, safe reinforcement learning, and differentiable control layers.&lt;/p&gt;

&lt;h2 id=&quot;clarabel-a-barrier-style-ipm-as-cvxpys-default-engine&quot;&gt;Clarabel: a barrier-style IPM as CVXPY’s default engine&lt;/h2&gt;

&lt;p&gt;Goulart and Chen (2024) describe &lt;strong&gt;Clarabel&lt;/strong&gt;, an open-source interior-point solver for convex conic programs with quadratic objectives. The algorithm is a homogeneous embedding specialised to an interior-point iteration: a log-style barrier (or a self-concordant analogue on each atomic cone) keeps iterates in the interior of the nonnegative orthant, the second-order cone, the exponential and power cones, and the PSD cone, while a Newton system on the KKT residual drives primal feasibility, dual feasibility, and complementarity. Chordal decomposition is available for large SDPs.&lt;/p&gt;

&lt;p&gt;The software fact that changes homework is this: as of CVXPY 1.5, Clarabel &lt;em&gt;replaces ECOS as the default&lt;/em&gt; for the problem classes where ECOS used to be called automatically (CVXPY 1.5 release notes; Goulart &amp;amp; Chen, §implementation). Quadratic programs still often go to OSQP (an ADMM solver, Chapter 21), but LPs, SOCPs, and many exponential-cone models now silently run a barrier / interior-point method. The modelling habit from &lt;a href=&quot;/contents/en/chapter05/05_07_Modeling_with_DCP_CVXPY/&quot;&gt;05-07&lt;/a&gt; therefore has a Chapter 15 engine under the hood:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cvxpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Variable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Problem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Minimize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum_squares&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;solver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CLARABEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ask &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prob.solver_stats&lt;/code&gt; after a default solve: if you did not name OSQP, you are watching a central-path method. That is the cleanest modern answer to “where is the barrier method used in data science?” — &lt;em&gt;inside the modelling layer you already teach&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;portfolio-mpc-and-other-cone-qps&quot;&gt;Portfolio, MPC, and other cone QPs&lt;/h2&gt;

&lt;p&gt;The same solver stack is the production path for mean–variance and risk-constrained portfolios, model-predictive control (MPC) QPs, and small robust-optimisation cones. Clarabel’s own numerical section and the later GPU port (Chapter 17) use portfolio and control QPs as running examples precisely because they are &lt;em&gt;self-concordant enough&lt;/em&gt; for Newton and &lt;em&gt;structured enough&lt;/em&gt; for a sparse KKT factorisation. A data-science student who writes a long-only portfolio with a tracking-error SOCP is not “doing finance instead of ML”; they are generating the central path of Chapter 15 on a problem whose Hessian is a covariance plus a barrier term on the simplex (or on a second-order cone).&lt;/p&gt;

&lt;p&gt;The modelling moral is the same as Boyd &amp;amp; Vandenberghe, Chapter 11: &lt;em&gt;do not hand-code a projected gradient on a cone if a barrier IPM is one &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solve()&lt;/code&gt; away.&lt;/em&gt; First-order splitting (OSQP, SCS) wins when you need warm starts at 100 Hz; the barrier wins when you need a high-accuracy certificate and the dimension still fits a sparse Newton system.&lt;/p&gt;

&lt;h2 id=&quot;log-barriers-in-constrained-and-safe-rl&quot;&gt;Log barriers in constrained and safe RL&lt;/h2&gt;

&lt;p&gt;Liu, Ding, and Liu (&lt;em&gt;IPO: Interior-Point Policy Optimization under Constraints&lt;/em&gt;, AAAI 2020) put a logarithmic barrier on the cost constraint of a constrained MDP and then run a PPO-style first-order method on the resulting smooth objective. The barrier is not solved by Newton in that paper — the policy is a neural net — but the &lt;em&gt;reduction&lt;/em&gt; is exactly Chapter 15: inequalities become a penalty whose gradient blows up at the boundary, so iterates stay strictly feasible if they start feasible. OmniSafe (Ji, Zhou, Zhang, Dai, Pan, Sun, Huang, Geng, Liu, Yang; JMLR 2024) and Safety Gymnasium (Ji et al., NeurIPS 2023 Datasets) ship IPO next to PPO-Lagrangian, which is why a 2024–2026 student meets log barriers in a &lt;em&gt;policy-optimisation&lt;/em&gt; README rather than only in a convex-analysis chapter.&lt;/p&gt;

&lt;p&gt;The comparison is pedagogically sharp. IPO is a barrier method with a &lt;em&gt;stochastic, first-order&lt;/em&gt; inner solver; Clarabel is a barrier method with a &lt;em&gt;deterministic, Newton&lt;/em&gt; inner solver. Same outer idea, opposite computational regime. When the constraint is a convex cone on a few hundred variables, Newton on the barrier is optimal; when the “variable” is a deep policy, you keep the barrier and throw away the Hessian.&lt;/p&gt;

&lt;h2 id=&quot;differentiable-layers-that-still-call-a-barrier-solver&quot;&gt;Differentiable layers that still call a barrier solver&lt;/h2&gt;

&lt;p&gt;Agrawal, Amos, Barratt, Boyd, Diamond, and Kolter (NeurIPS 2019) introduced &lt;strong&gt;cvxpylayers&lt;/strong&gt;: a CVXPY problem becomes a PyTorch / JAX layer whose backward pass differentiates the solution map. The forward solve is still an IPM or a first-order cone solver; the backward pass applies implicit differentiation to the KKT system — the same Jacobian that Newton’s method factors in this chapter. Through 2022–2026 the pattern is standard in differentiable MPC, structured prediction, and “optimization-as-a-layer” architectures: you do &lt;em&gt;not&lt;/em&gt; unroll gradient descent through 50 projected steps if a barrier solver returns a solution and a factorisation you can reuse for the adjoint.&lt;/p&gt;

&lt;p&gt;That is the deepest Chapter 15 transfer: the Newton system of the central path is not only an algorithm for \(x^\star(t)\), it is the linear map that lets learning systems treat &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solve()&lt;/code&gt; as a differentiable primitive.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;P. J. Goulart, Y. Chen, “Clarabel: An interior-point solver for conic programs with quadratic objectives,” 2024. &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv:2405.12762&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;CVXPY 1.5 release notes: Clarabel replaces ECOS as the default for former ECOS problem classes.&lt;/li&gt;
  &lt;li&gt;Y. Liu, J. Ding, X. Liu, “IPO: Interior-Point Policy Optimization under Constraints,” AAAI 2020.&lt;/li&gt;
  &lt;li&gt;J. Ji et al., “OmniSafe: An Infrastructure for Accelerating Safe Reinforcement Learning Research,” JMLR 25(285), 2024; “Safety Gymnasium,” NeurIPS 2023 Datasets.&lt;/li&gt;
  &lt;li&gt;A. Agrawal, B. Amos, S. Barratt, S. Boyd, S. Diamond, J. Z. Kolter, “Differentiable Convex Optimization Layers,” NeurIPS 2019 (cvxpylayers; still the 2022–2026 interface).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>14-10 Modern applications of Newton's method (2022–2026)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_10_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_10_modern_applications</id>
   <content type="html">&lt;p&gt;Conventional wisdom in 2015 said second-order optimization was dead for deep learning and only belonged in convex textbooks. Between 2022 and 2026, that conventional wisdom cracked: diagonal-Hessian optimizers like &lt;strong&gt;Sophia&lt;/strong&gt; cut GPT pre-training steps in half, &lt;strong&gt;K-FAC&lt;/strong&gt; brought Kronecker curvature to Vision Transformers and GNNs, and scikit-learn made exact &lt;strong&gt;Newton–Cholesky&lt;/strong&gt; a production default for tall generalized linear models.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-modern-second-order-optimization-20222026&quot;&gt;Key ideas: Modern Second-Order Optimization (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Structured Curvature Approximations:&lt;/strong&gt; Because dense \(n \times n\) Hessians are infeasible for \(n \sim 10^9\), modern methods restrict curvature to diagonal matrices (Sophia, AdaHessian) or Kronecker-factored blocks (K-FAC, Shampoo).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Amortization &amp;amp; Cheap Estimators:&lt;/strong&gt; Refreshing curvature every \(k\) steps (e.g., every 10 steps in Sophia) via Hutchinson Hessian–vector products or Gauss–Newton–Bartlett resampling keeps wall-clock cost close to Adam.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Clipping as Modern Damping:&lt;/strong&gt; When curvature estimates are noisy or non-positive in nonconvex landscapes, coordinate-wise clipping \(\operatorname{clip}(m_t / \max(\gamma h_t, \epsilon), 1)\) plays the exact protective role of trust-region / backtracking damping.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Exact Newton–Cholesky Still Wins for Tall GLMs:&lt;/strong&gt; When \(n_{\text{samples}} \gg n_{\text{features}}\), forming the exact IRLS Gram matrix \(X^T W X\) and factoring via Cholesky beats L-BFGS in both accuracy and speed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-one-clipped-diagonal-newton-sophia-step&quot;&gt;Worked example: Computing One Clipped Diagonal-Newton (Sophia) Step&lt;/h3&gt;

&lt;p&gt;Suppose a 2-parameter model has exponential moving-average gradient \(m = (0.40,\ -0.60)^T\), diagonal Hessian estimate \(h = (2.0,\ 0.05)^T\), damping/scale \(\gamma = 1\), clipping threshold \(\rho = 1.0\), and learning rate \(\eta = 0.01\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute raw diagonal-Newton preconditioned steps \(m_i / h_i\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Coordinate 1 (high curvature \(h_1 = 2.0\)): \(\frac{m_1}{h_1} = \frac{0.40}{2.0} = 0.20\).&lt;/li&gt;
      &lt;li&gt;Coordinate 2 (nearly flat curvature \(h_2 = 0.05\)): \(\frac{m_2}{h_2} = \frac{-0.60}{0.05} = -12.0\) (huge overshoot risk!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply Sophia’s coordinate-wise clipping \(\operatorname{clip}(\cdot, -\rho, \rho)\) with \(\rho = 1.0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Coordinate 1: \(\operatorname{clip}(0.20, -1, 1) = 0.20\) (unclipped—takes the exact curvature-scaled step).&lt;/li&gt;
      &lt;li&gt;Coordinate 2: \(\operatorname{clip}(-12.0, -1, 1) = -1.0\) (clipped—prevents explosion along the flat/noisy direction).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Final parameter update:&lt;/strong&gt;
\(\Delta \theta = -\eta \begin{bmatrix} 0.20 \\ -1.0 \end{bmatrix} = \begin{bmatrix} -0.002 \\ +0.010 \end{bmatrix}.\)
Notice how Coordinate 1 obeys exact diagonal Newton while Coordinate 2 is safely damped by clipping!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Newton’s method in this chapter is the exact local quadratic model&lt;/p&gt;

\[x^{+} = x - t\, \bigl(\nabla^2 f(x)\bigr)^{-1}\nabla f(x),\]

&lt;p&gt;together with the Newton decrement, affine invariance, and self-concordance that make the theory honest. Full Hessians of language models are not stored, yet the &lt;em&gt;same idea&lt;/em&gt; — precondition by curvature, then take a damped step — is how several 2022–2026 systems beat a well-tuned Adam baseline. This lesson is a survey, not an assessed algorithm zoo: you should be able to point to the Hessian (or a diagonal / Kronecker stand-in) in each story and say what was thrown away to make the step cheap.&lt;/p&gt;

&lt;p&gt;The four snapshots below are chosen because they are real deployments or refereed measurements, not folklore. They sit next to Chapter 26’s remark that Sophia is further reading there; here we unpack &lt;em&gt;why&lt;/em&gt; a Newton-style preconditioner can be cheaper than it looks.&lt;/p&gt;

&lt;h2 id=&quot;sophia-a-diagonal-hessian-for-language-model-pre-training&quot;&gt;Sophia: a diagonal Hessian for language-model pre-training&lt;/h2&gt;

&lt;p&gt;Liu, Li, Hall, Liang, and Ma (ICLR 2024) introduce &lt;strong&gt;Sophia&lt;/strong&gt; (&lt;em&gt;Second-order Clipped Stochastic Optimization&lt;/em&gt;). The update is an exponential moving average of stochastic gradients divided by an exponential moving average of a &lt;em&gt;diagonal&lt;/em&gt; Hessian estimate, followed by coordinate-wise clipping. The Hessian is refreshed only every handful of steps, so the average wall-clock overhead is small. Two estimators appear in the paper: a Hutchinson estimator that uses Hessian–vector products, and a Gauss–Newton–Bartlett estimator that draws a label from the model’s predictive distribution and uses the squared gradient of that resampled loss — biased, but nonnegative and cheap.&lt;/p&gt;

&lt;p&gt;On GPT-style models from 125M to 1.5B parameters, Sophia matches Adam’s validation perplexity in about half the steps and, because the per-step cost is comparable, in about half the compute and wall-clock time. The theory (in a simplified strongly convex setting) says the runtime need not depend on the condition number once each coordinate is scaled by its own curvature — exactly the affine-invariance intuition from &lt;a href=&quot;/contents/en/chapter14/14_02_02_affine_invariance_of_newton_method/&quot;&gt;14-02-02&lt;/a&gt;, restricted to a diagonal group.&lt;/p&gt;

&lt;p&gt;The clipping parameter is the engineering counterpart of a trust region: when the local Hessian is stale or indefinite, a raw Newton step can explode; a coordinate clip restores the “damped Newton” discipline you already saw with backtracking. Official code lives at &lt;a href=&quot;https://github.com/Liuhong99/Sophia&quot;&gt;Liuhong99/Sophia&lt;/a&gt;. Read this at survey depth: you are not expected to re-derive the Bartlett estimator, but you should be able to write the update and explain why a &lt;em&gt;diagonal&lt;/em&gt; Hessian is the only object that still fits in GPU memory next to a 1B-parameter model.&lt;/p&gt;

&lt;h2 id=&quot;k-fac-for-transformers-convnets-and-graphs&quot;&gt;K-FAC for transformers, convnets, and graphs&lt;/h2&gt;

&lt;p&gt;Kronecker-Factored Approximate Curvature (K-FAC; Martens &amp;amp; Grosse, 2015) approximates the Fisher / generalised Gauss–Newton matrix of a layer as a Kronecker product, which is the curvature of the &lt;em&gt;expected&lt;/em&gt; loss rather than a raw Hessian, but it is the object Newton-type methods actually invert in deep learning. Eschenhagen, Immer, Turner, Schneider, and Hennig (NeurIPS 2023) give the missing framework for &lt;em&gt;weight-sharing&lt;/em&gt; layers — the linear maps inside convolutions, recurrent cells, graph networks, and transformers. They distinguish &lt;strong&gt;K-FAC-expand&lt;/strong&gt; (the historical KFC-style factorisation) from &lt;strong&gt;K-FAC-reduce&lt;/strong&gt;, prove exactness of each flavour on deep linear networks in the matching sharing regime, and show that both reach a fixed validation target on a GNN and a Vision Transformer in roughly 50–75% of the first-order step count, with a comparable wall-clock gain.&lt;/p&gt;

&lt;p&gt;This is Newton with a structured inverse: you still solve a linear system against an approximate Hessian, but the Kronecker factors keep the solve at the size of an activation covariance rather than the size of the weight matrix. If Sophia is “Newton on the diagonal,” K-FAC is “Newton on a Kronecker algebra.” The pedagogical question is the same as in the self-concordant analysis: &lt;em&gt;what curvature are you willing to compute, and what invariance do you keep?&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;newtoncholesky-for-generalised-linear-models-in-scikit-learn&quot;&gt;Newton–Cholesky for generalised linear models in scikit-learn&lt;/h2&gt;

&lt;p&gt;Not every modern Newton story is a language model. scikit-learn 1.2 (2022) added &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;newton-cholesky&quot;&lt;/code&gt; to its GLM estimators (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PoissonRegressor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GammaRegressor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TweedieRegressor&lt;/code&gt;), later extended to binary logistic regression. The solver performs Newton–Raphson steps — equivalently, iteratively reweighted least squares — and factors the explicit Hessian by Cholesky. The documentation is unusually honest for a library: the method is the right default when \(n_{\text{samples}} \gg n_{\text{features}}\) (especially one-hot categoricals with rare levels), and memory is quadratic in the number of features because the Hessian is &lt;em&gt;formed&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This is the Chapter 14 algorithm without approximation. The IRLS Hessian of a GLM is a Gram matrix \(X^\top W X\) with a diagonal weight \(W\) that depends on the current mean; Cholesky is the numerically stable way to apply \((\nabla^2 f)^{-1}\). Students who only meet Newton on a whiteboard should run&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sklearn.linear_model&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PoissonRegressor&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;PoissonRegressor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;solver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;newton-cholesky&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and compare iteration counts with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;lbfgs&quot;&lt;/code&gt;. When the design is tall and skinny, exact Newton is not a luxury — it is the production solver.&lt;/p&gt;

&lt;h2 id=&quot;what-to-keep-from-the-survey&quot;&gt;What to keep from the survey&lt;/h2&gt;

&lt;p&gt;AdaHessian (Yao, Gholami, Shen, Keutzer, Mahoney, AAAI 2021) is the immediate precursor of Sophia: a Hutchinson diagonal with Adam-style moments. SOAP and Shampoo (Chapter 18) replace the diagonal by a Kronecker or eigenbasis preconditioner and are cousins, not competitors. Full Newton remains the right tool on GLMs, kernel methods of moderate size, and the centering steps of the barrier / primal-dual methods in Chapters 15 and 17.&lt;/p&gt;

&lt;p&gt;A useful exam sentence: &lt;em&gt;modern second-order ML is almost never “form \(\nabla^2 f\) and factor it”; it is “estimate a structured curvature, damp or clip the step, and amortise the estimate over many iterations.”&lt;/em&gt; The exceptions — Newton–Cholesky GLMs — prove the rule by being the cases where forming the Hessian is still cheaper than walking with a first-order method.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;H. Liu, Z. Li, D. Hall, P. Liang, T. Ma, “Sophia: A Scalable Stochastic Second-order Optimizer for Language Model Pre-training,” ICLR 2024. &lt;a href=&quot;https://arxiv.org/abs/2305.14342&quot;&gt;arXiv:2305.14342&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;R. Eschenhagen, A. Immer, R. Turner, F. Schneider, P. Hennig, “Kronecker-Factored Approximate Curvature for Modern Neural Network Architectures,” NeurIPS 2023.&lt;/li&gt;
  &lt;li&gt;Z. Yao, A. Gholami, S. Shen, K. Keutzer, M. W. Mahoney, “ADAHESSIAN: An Adaptive Second Order Optimizer for Machine Learning,” AAAI 2021.&lt;/li&gt;
  &lt;li&gt;scikit-learn 1.2 release notes and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newton-cholesky&lt;/code&gt; solver documentation (2022–); GLM PR &lt;a href=&quot;https://github.com/scikit-learn/scikit-learn/pull/24637&quot;&gt;#24637&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>13-10 Modern uses of conjugates, dual norms, and dual cones</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_10_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_10_modern_applications</id>
   <content type="html">&lt;p&gt;Picture training a sparse generalized linear model on 500,000 genetic markers when only 40 markers actually matter. Waiting for a primal solver to update all half-million coordinates every epoch is painfully slow—unless you maintain a feasible dual vector and use the duality gap to &lt;em&gt;mathematically prove&lt;/em&gt; which 499,900 features must be zero at the optimum, dropping them forever mid-solve. That is how Chapter 13’s duality correspondences power today’s fastest ML libraries.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-modern-duality-pipelines-20222026&quot;&gt;Key ideas: Modern Duality Pipelines (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Dual-Norm Threat Models:&lt;/strong&gt; Adversarial robustness benchmarks (AutoAttack, RobustBench) formalize worst-case perturbations through the exact dual-norm pairing \(\sup_{\|v\|_p \le \varepsilon} g^T v = \varepsilon \|g\|_q\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Computable Duality Gaps for Feature Screening:&lt;/strong&gt; In &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt; and gap-safe screening, the duality gap \(P(\beta) - D(\theta)\) bounds \(\|\theta - \theta^\star\|_2 \le \sqrt{2(P(\beta) - D(\theta))}\), enabling provably safe elimination of inactive coordinates.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Conjugate-Based Canonicalization in Cone Solvers:&lt;/strong&gt; CVXPY, OSQP, SCS, and Clarabel rely on Fenchel conjugates and Moreau’s identity to convert high-level norms and penalties into standardized cone projections.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Dual-Cone Certificates for Verified AI:&lt;/strong&gt; Neural network verifiers (\(\alpha,\beta\)-CROWN, GCP-CROWN) cast robustness verification as a conic relaxation where any feasible dual-cone vector \(z \in K^*\) provides a sound mathematical proof of safety.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-gap-safe-feature-screening-in-action&quot;&gt;Worked example: Gap-Safe Feature Screening in Action&lt;/h3&gt;

&lt;p&gt;Suppose we are solving a Lasso problem with \(\lambda = 10\) and normalized feature columns \(\|x_j\|_2 = 1\). At iteration \(k\), our current primal iterate \(\beta\) has objective \(P(\beta) = 12.50\), and a rescaled dual-feasible residual \(\theta\) (satisfying \(\|X^T \theta\|_\infty \le \lambda\)) gives dual objective \(D(\theta) = 12.32\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the duality gap and safe dual-ball radius:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Duality gap: \(G = P(\beta) - D(\theta) = 12.50 - 12.32 = 0.18\).&lt;/li&gt;
      &lt;li&gt;Because the dual objective \(-\frac{1}{2}\|y - \theta\|_2^2\) is \(1\)-strongly concave in \(\theta\), strong concavity guarantees:
\(\|\theta - \theta^\star\|_2 \le \sqrt{2G} = \sqrt{2(0.18)} = \sqrt{0.36} = 0.6.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the gap-safe screening test to two candidate features:&lt;/strong&gt; By Cauchy–Schwarz,
\(|x_j^T \theta^\star| \le |x_j^T \theta| + \|x_j\|_2 \|\theta - \theta^\star\|_2 \le |x_j^T \theta| + 1 \cdot 0.6.\)
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Feature A&lt;/strong&gt; has $$&lt;/td&gt;
              &lt;td&gt;x_A^T \theta&lt;/td&gt;
              &lt;td&gt;= 9.1\(: upper bound is\)9.1 + 0.6 = 9.7 &amp;lt; \lambda = 10\(. Since\)&lt;/td&gt;
              &lt;td&gt;x_A^T \theta^\star&lt;/td&gt;
              &lt;td&gt;&amp;lt; \lambda\(strictly, KKT optimality forces\)\beta_A^\star = 0$$—we can safely delete Feature A!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Feature B&lt;/strong&gt; has $$&lt;/td&gt;
              &lt;td&gt;x_B^T \theta&lt;/td&gt;
              &lt;td&gt;= 9.6\(: upper bound is\)9.6 + 0.6 = 10.2 \ge 10$$. Feature B might still be active, so we keep it in the working set.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-uses-of-conjugates-dual-norms-and-dual-cones&quot;&gt;Modern uses of conjugates, dual norms, and dual cones&lt;/h1&gt;

&lt;p&gt;Chapter 13 is already titled “uses of duality”: solving the primal via the dual, dual norms, conjugates, the Lasso dual, and dual cones. This optional lesson attaches 2022–2026 CS applications to those &lt;em&gt;same&lt;/em&gt; correspondences. We do not re-derive \(f^\star\) or \(\|y\|_*\).&lt;/p&gt;

&lt;h2 id=&quot;1-dual-norms-and-adversarial-ell_p-balls&quot;&gt;1. Dual norms and adversarial \(\ell_p\) balls&lt;/h2&gt;

&lt;p&gt;The support function of an \(\ell_p\) attack ball of radius \(\varepsilon\) is \(\varepsilon\|g\|_*\), where \(\|\cdot\|_*\) is the dual of \(\|\cdot\|_p\):&lt;/p&gt;

\[\|g\|_\infty=\sup_{\|v\|_1\le 1}g^\top v,\qquad
\|g\|_2=\sup_{\|v\|_2\le 1}g^\top v,\qquad
\|g\|_1=\sup_{\|v\|_\infty\le 1}g^\top v.\]

&lt;p&gt;FGSM / PGD linearise the loss and take a step of length \(\varepsilon\) in the dual-norm direction (sign for \(\ell_\infty\), normalisation for \(\ell_2\)). AutoAttack (Croce and Hein, 2020) and the &lt;strong&gt;RobustBench&lt;/strong&gt; leaderboard (Croce et al., 2021; maintained through 2025) standardised evaluation for those two dual pairs on CIFAR and ImageNet-scale models. When a paper writes “\(\ell_\infty\) robust accuracy 0.03,” it has chosen the dual of \(\|\cdot\|_1\) as the attack geometry. That is &lt;a href=&quot;/contents/en/chapter13/13_03_Dual_norms/&quot;&gt;13-03 Dual norms&lt;/a&gt; with a threat model.&lt;/p&gt;

&lt;p&gt;Certified robustness goes further: a dual LP or SDP (Chapter 10 / dual cones below) &lt;em&gt;proves&lt;/em&gt; that no perturbation inside the ball flips the label.&lt;/p&gt;

&lt;h2 id=&quot;2-the-lasso-dual-as-a-screening-certificate&quot;&gt;2. The Lasso dual as a screening certificate&lt;/h2&gt;

&lt;p&gt;The Lasso dual in &lt;a href=&quot;/contents/en/chapter13/13_04_01_Example_lasso_dual/&quot;&gt;13-04-01&lt;/a&gt; is a projection onto a polytope \(\|X^\top\theta\|_\infty\le\lambda\). The duality gap \(P(\beta)-D(\theta)\) is a &lt;strong&gt;computable certificate&lt;/strong&gt;. Gap-safe screening (Ndiaye, Fercoq, Gramfort, Salmon) discards features whose inner product with a dual-feasible \(\theta\) cannot reach \(\lambda\). Bertrand, Klopfenstein, Bannier, Gidel, and Massias (NeurIPS 2022) put working sets and those dual tests into &lt;strong&gt;skglm&lt;/strong&gt;, which fits sparse GLMs with millions of coordinates. Guha, Ndiaye, and Huo (ICML 2023) reuse the dual / homotopy path to build conformal sets. In all of these, you solve or &lt;em&gt;monitor&lt;/em&gt; the dual in order to finish the primal faster — the slogan of &lt;a href=&quot;/contents/en/chapter13/13_02_Solving_the_primal_via_the_dual/&quot;&gt;13-02&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;3-conjugates-prox-operators-and-production-cone-solvers&quot;&gt;3. Conjugates, prox operators, and production cone solvers&lt;/h2&gt;

&lt;p&gt;The identity \(\operatorname{prox}_f(v)+\operatorname{prox}_{f^\star}(v)=v\) (Moreau) is how modern first-order cone solvers implement projections. OSQP, SCS, and &lt;strong&gt;Clarabel&lt;/strong&gt; (Goulart and Chen, 2024) take a problem in a dual-cone form and run ADMM / interior-point iterations whose expensive step is a prox or a conjugate residual. CVXPY’s canonicalization (already in Chapter 05 of this course) is a map &lt;em&gt;into&lt;/em&gt; that cone language. When you write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.norm1(x)&lt;/code&gt; you are asking for the conjugate of an \(\ell_\infty\) indicator.&lt;/p&gt;

&lt;h2 id=&quot;4-dual-cones-and-neural-network-certificates&quot;&gt;4. Dual cones and neural-network certificates&lt;/h2&gt;

&lt;p&gt;A dual-cone membership \(z\in K^*\) is the inequality that turns a primal cone program into a bound. SDP and LP relaxations of ReLU networks are cone programs; their duals are the bound-propagation functionals of &lt;strong&gt;\(\alpha,\beta\)-CROWN&lt;/strong&gt; and the cutting-plane dual of &lt;strong&gt;GCP-CROWN&lt;/strong&gt; (Zhang et al., NeurIPS 2022). Winning VNN-COMP from 2021 through 2025 is, in the language of this chapter, “produce a dual-feasible cone certificate fast enough, on a GPU.” Dual cones are not an algebraic curiosity — they are the type of the proof.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Object in Chapter 13&lt;/th&gt;
      &lt;th&gt;2022–2026 use&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual norm \(|g|_*\)&lt;/td&gt;
      &lt;td&gt;\(\ell_p\) attack step and RobustBench&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lasso dual / gap&lt;/td&gt;
      &lt;td&gt;skglm screening and conformal sparse GLMs&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Conjugate \(f^\star\) and Moreau&lt;/td&gt;
      &lt;td&gt;Prox in OSQP / SCS / Clarabel / CVXPY&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual cone \(K^*\)&lt;/td&gt;
      &lt;td&gt;LP/SDP certificates for NN verification&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; Why is the dual of an \(\ell_1\) regulariser an \(\ell_\infty\) constraint, and how does that single fact give both the Lasso screening test &lt;em&gt;and&lt;/em&gt; the FGSM sign attack?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Croce, F., &amp;amp; Hein, M. (2020). Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Croce, F., et al. (2021). RobustBench: A standardized adversarial robustness benchmark. &lt;em&gt;NeurIPS Datasets and Benchmarks&lt;/em&gt;. &lt;a href=&quot;https://robustbench.github.io/&quot;&gt;https://robustbench.github.io/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bertrand, Q., Klopfenstein, Q., Bannier, P.-A., Gidel, G., &amp;amp; Massias, M. (2022). Beyond L1: Faster and better sparse models with skglm. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Guha, E. K., Ndiaye, E., &amp;amp; Huo, X. (2023). Conformalization of sparse generalized linear models. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Goulart, P. J., &amp;amp; Chen, Y. (2024). Clarabel: An interior-point solver for conic programs with quadratic objectives. &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv:2405.12762&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Zhang, H., Wang, S., Xu, K., Li, L., Li, B., Jana, S., Hsieh, C.-J., &amp;amp; Kolter, J. Z. (2022). General cutting planes for bound-propagation-based neural network verification. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Parikh, N., &amp;amp; Boyd, S. (2014). Proximal algorithms. &lt;em&gt;Foundations and Trends in Optimization&lt;/em&gt;, 1(3). (Moreau identity used by the solvers above)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>13-07 Modern uses of conjugates, dual norms, and dual cones</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_07_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_07_modern_applications</id>
   <content type="html">&lt;p&gt;Every time an AI safety researcher reports that an image classifier survives an \(\ell_\infty\) adversarial attack of radius \(\varepsilon = 8/255\), or a genomicist fits a million-feature sparse regression in seconds with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt;, they are not inventing new optimization theory—they are deploying the exact four correspondences of Chapter 13: dual norms, Lasso duals, Fenchel conjugates, and dual cones.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-chapter-13-theory-to-20222026-systems&quot;&gt;Key ideas: From Chapter 13 Theory to 2022–2026 Systems&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Dual Norms Define Adversarial Geometry:&lt;/strong&gt; Maximizing a linearized loss \(g^T v\) over an \(\ell_p\) threat ball \(\|v\|_p \le \varepsilon\) produces \(\varepsilon\|g\|_*\); choosing \(p = \infty\) automatically selects the \(\ell_1\) dual norm and the FGSM/PGD sign direction.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Gap-Safe Screening via the Lasso Dual:&lt;/strong&gt; Any dual-feasible \(\theta\) defines a safe sphere around \(\theta^\star\) of radius \(\sqrt{2(P(\beta) - D(\theta))}\); features whose inner product with that entire sphere stays strictly below \(\lambda\) are provably zero and deleted permanently.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Moreau Identity Powers Modern Cone Solvers:&lt;/strong&gt; The conjugate identity \(\operatorname{prox}_f(v) + \operatorname{prox}_{f^*}(v) = v\) lets solvers like OSQP, SCS, and Clarabel evaluate hard projections via easy dual projections.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Dual Cones Certify Neural Networks:&lt;/strong&gt; Proving a ReLU network cannot misclassify inside an input ball reduces to exhibiting a dual-feasible point \(z \in K^*\) in an LP/SDP relaxation (as in \(\alpha,\beta\)-CROWN and GCP-CROWN).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-an-exact-dual-norm-adversarial-perturbation&quot;&gt;Worked example: Computing an Exact Dual-Norm Adversarial Perturbation&lt;/h3&gt;

&lt;p&gt;Suppose a classifier’s loss gradient at an input image pixel vector \(x\) is \(g = (0.3,\ -1.2,\ 0.4)^T\), and the attacker has a perturbation budget \(\varepsilon = 0.1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(\ell_\infty\) attack ball (\(\|v\|_\infty \le 0.1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Dual norm is \(\ell_1\): $$|g|_1 =&lt;/td&gt;
              &lt;td&gt;0.3&lt;/td&gt;
              &lt;td&gt;+&lt;/td&gt;
              &lt;td&gt;-1.2&lt;/td&gt;
              &lt;td&gt;+&lt;/td&gt;
              &lt;td&gt;0.4&lt;/td&gt;
              &lt;td&gt;= 1.9$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Maximum first-order loss increase: \(\varepsilon \|g\|_1 = 0.1 \times 1.9 = 0.19\).&lt;/li&gt;
      &lt;li&gt;Optimal FGSM perturbation: \(v^\star_\infty = \varepsilon \operatorname{sign}(g) = (0.1,\ -0.1,\ 0.1)^T\).&lt;/li&gt;
      &lt;li&gt;Check: \(g^T v^\star_\infty = 0.03 + 0.12 + 0.04 = 0.19\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\ell_2\) attack ball (\(\|v\|_2 \le 0.1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Dual norm is \(\ell_2\): \(\|g\|_2 = \sqrt{0.09 + 1.44 + 0.16} = \sqrt{1.69} = 1.3\).&lt;/li&gt;
      &lt;li&gt;Maximum first-order loss increase: \(\varepsilon \|g\|_2 = 0.1 \times 1.3 = 0.13\).&lt;/li&gt;
      &lt;li&gt;Optimal perturbation: \(v^\star_2 = \varepsilon \frac{g}{\|g\|_2} = \frac{0.1}{1.3}(0.3, -1.2, 0.4)^T \approx (0.0231, -0.0923, 0.0308)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Key insight:&lt;/strong&gt; Both attacks come from the exact same formula \(\max_{\|v\|_p \le \varepsilon} g^T v = \varepsilon \|g\|_q\) with \(1/p + 1/q = 1\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-uses-of-conjugates-dual-norms-and-dual-cones&quot;&gt;Modern uses of conjugates, dual norms, and dual cones&lt;/h1&gt;

&lt;p&gt;Chapter 13 is already titled “uses of duality”: solving the primal via the dual, dual norms, conjugates, the Lasso dual, and dual cones. This optional lesson attaches 2022–2026 CS applications to those &lt;em&gt;same&lt;/em&gt; correspondences. We do not re-derive \(f^\star\) or \(\|y\|_*\).&lt;/p&gt;

&lt;h2 id=&quot;1-dual-norms-and-adversarial-ell_p-balls&quot;&gt;1. Dual norms and adversarial \(\ell_p\) balls&lt;/h2&gt;

&lt;p&gt;The support function of an \(\ell_p\) attack ball of radius \(\varepsilon\) is \(\varepsilon\|g\|_*\), where \(\|\cdot\|_*\) is the dual of \(\|\cdot\|_p\):&lt;/p&gt;

\[\|g\|_\infty=\sup_{\|v\|_1\le 1}g^\top v,\qquad
\|g\|_2=\sup_{\|v\|_2\le 1}g^\top v,\qquad
\|g\|_1=\sup_{\|v\|_\infty\le 1}g^\top v.\]

&lt;p&gt;FGSM / PGD linearise the loss and take a step of length \(\varepsilon\) in the dual-norm direction (sign for \(\ell_\infty\), normalisation for \(\ell_2\)). AutoAttack (Croce and Hein, 2020) and the &lt;strong&gt;RobustBench&lt;/strong&gt; leaderboard (Croce et al., 2021; maintained through 2025) standardised evaluation for those two dual pairs on CIFAR and ImageNet-scale models. When a paper writes “\(\ell_\infty\) robust accuracy 0.03,” it has chosen the dual of \(\|\cdot\|_1\) as the attack geometry. That is &lt;a href=&quot;/contents/en/chapter13/13_03_Dual_norms/&quot;&gt;13-03 Dual norms&lt;/a&gt; with a threat model.&lt;/p&gt;

&lt;p&gt;Certified robustness goes further: a dual LP or SDP (Chapter 10 / dual cones below) &lt;em&gt;proves&lt;/em&gt; that no perturbation inside the ball flips the label.&lt;/p&gt;

&lt;h2 id=&quot;2-the-lasso-dual-as-a-screening-certificate&quot;&gt;2. The Lasso dual as a screening certificate&lt;/h2&gt;

&lt;p&gt;The Lasso dual in &lt;a href=&quot;/contents/en/chapter13/13_04_01_Example_lasso_dual/&quot;&gt;13-04-01&lt;/a&gt; is a projection onto a polytope \(\|X^\top\theta\|_\infty\le\lambda\). The duality gap \(P(\beta)-D(\theta)\) is a &lt;strong&gt;computable certificate&lt;/strong&gt;. Gap-safe screening (Ndiaye, Fercoq, Gramfort, Salmon) discards features whose inner product with a dual-feasible \(\theta\) cannot reach \(\lambda\). Bertrand, Klopfenstein, Bannier, Gidel, and Massias (NeurIPS 2022) put working sets and those dual tests into &lt;strong&gt;skglm&lt;/strong&gt;, which fits sparse GLMs with millions of coordinates. Guha, Ndiaye, and Huo (ICML 2023) reuse the dual / homotopy path to build conformal sets. In all of these, you solve or &lt;em&gt;monitor&lt;/em&gt; the dual in order to finish the primal faster — the slogan of &lt;a href=&quot;/contents/en/chapter13/13_02_Solving_the_primal_via_the_dual/&quot;&gt;13-02&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;3-conjugates-prox-operators-and-production-cone-solvers&quot;&gt;3. Conjugates, prox operators, and production cone solvers&lt;/h2&gt;

&lt;p&gt;The identity \(\operatorname{prox}_f(v)+\operatorname{prox}_{f^\star}(v)=v\) (Moreau) is how modern first-order cone solvers implement projections. OSQP, SCS, and &lt;strong&gt;Clarabel&lt;/strong&gt; (Goulart and Chen, 2024) take a problem in a dual-cone form and run ADMM / interior-point iterations whose expensive step is a prox or a conjugate residual. CVXPY’s canonicalization (already in Chapter 05 of this course) is a map &lt;em&gt;into&lt;/em&gt; that cone language. When you write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.norm1(x)&lt;/code&gt; you are asking for the conjugate of an \(\ell_\infty\) indicator.&lt;/p&gt;

&lt;h2 id=&quot;4-dual-cones-and-neural-network-certificates&quot;&gt;4. Dual cones and neural-network certificates&lt;/h2&gt;

&lt;p&gt;A dual-cone membership \(z\in K^*\) is the inequality that turns a primal cone program into a bound. SDP and LP relaxations of ReLU networks are cone programs; their duals are the bound-propagation functionals of &lt;strong&gt;\(\alpha,\beta\)-CROWN&lt;/strong&gt; and the cutting-plane dual of &lt;strong&gt;GCP-CROWN&lt;/strong&gt; (Zhang et al., NeurIPS 2022). Winning VNN-COMP from 2021 through 2025 is, in the language of this chapter, “produce a dual-feasible cone certificate fast enough, on a GPU.” Dual cones are not an algebraic curiosity — they are the type of the proof.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Object in Chapter 13&lt;/th&gt;
      &lt;th&gt;2022–2026 use&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual norm \(|g|_*\)&lt;/td&gt;
      &lt;td&gt;\(\ell_p\) attack step and RobustBench&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lasso dual / gap&lt;/td&gt;
      &lt;td&gt;skglm screening and conformal sparse GLMs&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Conjugate \(f^\star\) and Moreau&lt;/td&gt;
      &lt;td&gt;Prox in OSQP / SCS / Clarabel / CVXPY&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual cone \(K^*\)&lt;/td&gt;
      &lt;td&gt;LP/SDP certificates for NN verification&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; Why is the dual of an \(\ell_1\) regulariser an \(\ell_\infty\) constraint, and how does that single fact give both the Lasso screening test &lt;em&gt;and&lt;/em&gt; the FGSM sign attack?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Croce, F., &amp;amp; Hein, M. (2020). Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Croce, F., et al. (2021). RobustBench: A standardized adversarial robustness benchmark. &lt;em&gt;NeurIPS Datasets and Benchmarks&lt;/em&gt;. &lt;a href=&quot;https://robustbench.github.io/&quot;&gt;https://robustbench.github.io/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bertrand, Q., Klopfenstein, Q., Bannier, P.-A., Gidel, G., &amp;amp; Massias, M. (2022). Beyond L1: Faster and better sparse models with skglm. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Guha, E. K., Ndiaye, E., &amp;amp; Huo, X. (2023). Conformalization of sparse generalized linear models. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Goulart, P. J., &amp;amp; Chen, Y. (2024). Clarabel: An interior-point solver for conic programs with quadratic objectives. &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv:2405.12762&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Zhang, H., Wang, S., Xu, K., Li, L., Li, B., Jana, S., Hsieh, C.-J., &amp;amp; Kolter, J. Z. (2022). General cutting planes for bound-propagation-based neural network verification. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Parikh, N., &amp;amp; Boyd, S. (2014). Proximal algorithms. &lt;em&gt;Foundations and Trends in Optimization&lt;/em&gt;, 1(3). (Moreau identity used by the solvers above)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>12-10 Modern applications of the KKT conditions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_10_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_10_modern_applications</id>
   <content type="html">&lt;p&gt;Across 2022–2026 machine learning, robotics, and energy systems, the KKT conditions have moved from the chalkboard directly into production runtime loops. Whether backpropagating through a convex optimization layer in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Theseus&lt;/code&gt;, certifying SVM support vectors, auditing which transmission lines are congested in an electricity market, or measuring the exact accuracy cost of a fairness bound, engineers treat the KKT system as both an &lt;strong&gt;optimality oracle&lt;/strong&gt; and a &lt;strong&gt;sensitivity calculator&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-production-roles-of-the-kkt-system&quot;&gt;Key ideas: Four Production Roles of the KKT System&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Differentiable Convex &amp;amp; Nonlinear Layers:&lt;/strong&gt; Tools like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Theseus&lt;/code&gt; embed optimization problems inside end-to-end neural pipelines by differentiating the KKT residual \(F(x^\star, u^\star, v^\star; \theta) = 0\) via the implicit function theorem—requiring only one KKT linear solve in the backward pass.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Complementary Slackness as Sparse Support Identification:&lt;/strong&gt; In SVMs, Lasso, and active-set QP solvers, complementary slackness \(u_i^\star h_i(x^\star) = 0\) cleanly separates active constraints/support vectors from inactive ones, enabling massive speedups via active-set screening.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Marginal Prices &amp;amp; Grid Auditing:&lt;/strong&gt; In wholesale electricity clearing, KKT stationarity ties every generator’s dispatch directly to nodal Locational Marginal Prices (LMPs), while complementary slackness exposes exactly which thermal or ramping limits are binding.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Fairness Trade-off Attribution:&lt;/strong&gt; When multiple demographic fairness constraints compete inside a single training objective, inspecting the KKT multipliers \(\lambda_g^\star &amp;gt; 0\) pinpoints which group’s constraint is actively shaping the decision boundary.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-implicit-kkt-sensitivity-of-an-equality-constrained-layer&quot;&gt;Worked example: Implicit KKT Sensitivity of an Equality-Constrained Layer&lt;/h3&gt;

&lt;p&gt;Consider a differentiable portfolio/control layer parameterized by a predicted target vector \(\theta = (\theta_1, \theta_2)^\top\):
\(x^\star(\theta) = \arg\min_{x \in \mathbb{R}^2}\; \frac{1}{2}\|x - \theta\|_2^2 \quad \text{s.t.} \quad x_1 + x_2 = 1.\)
We want the Jacobian \(\frac{\partial x^\star}{\partial \theta}\) for backpropagation via the KKT system!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the KKT equations (stationarity + primal feasibility):&lt;/strong&gt;
\(x_1^\star - \theta_1 + v^\star = 0, \qquad x_2^\star - \theta_2 + v^\star = 0, \qquad x_1^\star + x_2^\star = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Differentiate the entire KKT system with respect to \(\theta_1\):&lt;/strong&gt;
\(\begin{pmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{pmatrix} \begin{pmatrix} \partial x_1^\star / \partial \theta_1 \\ \partial x_2^\star / \partial \theta_1 \\ \partial v^\star / \partial \theta_1 \end{pmatrix} = \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the \(3 \times 3\) linear system:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Row 1 + Row 2 gives \((\partial x_1^\star/\partial \theta_1 + \partial x_2^\star/\partial \theta_1) + 2\partial v^\star/\partial \theta_1 = 1\).&lt;/li&gt;
      &lt;li&gt;Row 3 gives \(\partial x_1^\star/\partial \theta_1 + \partial x_2^\star/\partial \theta_1 = 0\), so \(\partial v^\star/\partial \theta_1 = 0.5\)!&lt;/li&gt;
      &lt;li&gt;Back-substitute: \(\frac{\partial x_1^\star}{\partial \theta_1} = 1 - 0.5 = 0.5\) and \(\frac{\partial x_2^\star}{\partial \theta_1} = -0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interpret the result:&lt;/strong&gt; Increasing \(\theta_1\) by \(1\) shifts \(+0.5\) into \(x_1^\star\) and \(-0.5\) out of \(x_2^\star\) to preserve \(x_1^\star + x_2^\star = 1\)—giving the exact Jacobian \(\frac{\partial x^\star}{\partial \theta} = \begin{pmatrix}0.5 &amp;amp; -0.5 \\ -0.5 &amp;amp; 0.5\end{pmatrix} = I - \frac{1}{2}\mathbf{1}\mathbf{1}^\top\) directly from the KKT matrix!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-the-kkt-conditions&quot;&gt;Modern applications of the KKT conditions&lt;/h1&gt;

&lt;p&gt;Chapter 12 states the KKT system — primal feasibility, dual feasibility, complementary slackness, and stationarity of the Lagrangian — and works the SVM, water-filling, and \(\ell_1\) examples. This optional lesson shows where that &lt;em&gt;system&lt;/em&gt; is solved, differentiated, or read as a price in 2022–2026 software. We do not re-list the four blocks.&lt;/p&gt;

&lt;h2 id=&quot;1-differentiating-through-a-solver-cvxpylayers-and-theseus&quot;&gt;1. Differentiating through a solver: cvxpylayers and Theseus&lt;/h2&gt;

&lt;p&gt;If \(x^\star(\theta)\) is the unique solution of a parametrized convex program, the implicit-function theorem applied to the KKT map \(F(x,u,v;\theta)=0\) yields \(\mathrm{d}x^\star/\mathrm{d}\theta\) without unrolling the solver. Agrawal, Amos, Barratt, Boyd, Diamond, and Kolter (NeurIPS 2019) shipped that idea as &lt;strong&gt;cvxpylayers&lt;/strong&gt; (PyTorch / JAX / MLX). It is still the default way, in 2024–2026, to put a QP or SOCP &lt;em&gt;inside&lt;/em&gt; a net: portfolio layers (DeepDow), MPC policies, and sparsemax-type projections.&lt;/p&gt;

&lt;p&gt;Pineda, Fan, Monge, Venkataraman, Sodhi, Chen, Ortiz, DeTone, Wang, Anderson, Dong, Amos, and Mukadam (NeurIPS 2022) released &lt;strong&gt;Theseus&lt;/strong&gt;, a GPU library for differentiable &lt;em&gt;nonlinear&lt;/em&gt; least squares used in robotics and vision. The backward pass is again implicit differentiation of the stationarity (Gauss–Newton / Levenberg–Marquardt) conditions — KKT for an equality-constrained or regularised NLS. The 2022 paper is the one to cite; the repo is what a SLAM / bundle-adjustment stack actually imports.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Course link.&lt;/strong&gt; Stationarity \(\nabla_x L=0\) is the linear system Theseus differentiates. Complementary slackness appears as soon as the layer has inequalities (cvxpylayers).&lt;/p&gt;

&lt;h2 id=&quot;2-svm-support-vectors-are-a-kkt-statement&quot;&gt;2. SVM support vectors are a KKT statement&lt;/h2&gt;

&lt;p&gt;The example &lt;a href=&quot;/contents/en/chapter12/12_04_Example_support_vector_machines/&quot;&gt;12-04&lt;/a&gt; is not ornamental. Complementary slackness says a point with \(0&amp;lt;\alpha_i&amp;lt;C\) lies on the margin, a point with \(\alpha_i=0\) is correctly classified with slack, and a point with \(\alpha_i=C\) is a bound support vector. Kernel SVM remains a standard tool in 2022–2026 small-\(n\) scientific ML (chemoinformatics, EEG, tabular clinical data) precisely because that finite set of vectors &lt;em&gt;is&lt;/em&gt; the model. When a paper reports “47 support vectors,” it is reporting the active set of a KKT system.&lt;/p&gt;

&lt;h2 id=&quot;3-electricity-lmps-and-complementary-slackness&quot;&gt;3. Electricity LMPs and complementary slackness&lt;/h2&gt;

&lt;p&gt;Locational marginal prices are the dual variables of power-balance and flow limits (Chapter 10). Liang and Dvorkin (2023) invert published LMPs to recover offer prices; the inversion is possible because, at a nondegenerate clearing point, KKT identifies which inequalities bind. Donti, Rolnick, and Kolter (2021) train DC3 so that the network’s output is driven toward a KKT-feasible OPF point. Water-filling in &lt;a href=&quot;/contents/en/chapter12/12_03_Example_water_filling/&quot;&gt;12-03&lt;/a&gt; is the same complementary-slackness picture in a Gaussian channel; 5G / 6G power-allocation papers still write that water level as a multiplier of a total-power inequality.&lt;/p&gt;

&lt;h2 id=&quot;4-fairness-which-group-constraint-is-tight&quot;&gt;4. Fairness: which group constraint is tight?&lt;/h2&gt;

&lt;p&gt;In a Fairlearn / reductions fit (Weerts et al., 2023), a large multiplier on equalised odds for group \(a\) means that group’s rate constraint is &lt;strong&gt;binding&lt;/strong&gt; — complementary slackness in prose. A zero multiplier means the unconstrained model already satisfied that rate. Reading \((x^\star,v^\star)\) is therefore a debugging tool: it tells you &lt;em&gt;which&lt;/em&gt; sociotechnical constraint is expensive, not only that the Lagrangian was minimised.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;KKT is the first-order system that (i) characterises a convex constrained optimum, (ii) can be differentiated to train a layer, and (iii) names the resources that have a price. If a 2024 paper “embeds a QP in a net” or “reports support vectors” or “publishes an LMP,” it is talking about that system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; Why does implicit differentiation of KKT need a constraint qualification and a nonsingular KKT Jacobian — and what fails in a Lasso layer when two features are identical?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Agrawal, A., Amos, B., Barratt, S., Boyd, S., Diamond, S., &amp;amp; Kolter, J. Z. (2019). Differentiable convex optimization layers. &lt;em&gt;NeurIPS&lt;/em&gt;. Library: &lt;a href=&quot;https://www.cvxpylayers.org/&quot;&gt;cvxpylayers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Pineda, L., Fan, T., Monge, M., Venkataraman, S., Sodhi, P., Chen, R. T. Q., Ortiz, J., DeTone, D., Wang, A., Anderson, S., Dong, J., Amos, B., &amp;amp; Mukadam, M. (2022). Theseus: A library for differentiable nonlinear optimization. &lt;em&gt;NeurIPS&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2207.09442&quot;&gt;arXiv:2207.09442&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Liang, Z., &amp;amp; Dvorkin, Y. (2023). Data-driven inverse optimization for marginal offer price recovery in electricity markets. &lt;em&gt;ACM e-Energy ’23&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Donti, P. L., Rolnick, D., &amp;amp; Kolter, J. Z. (2021). DC3: A learning method for optimization with hard constraints. &lt;em&gt;ICLR&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>12-07 Modern applications of the KKT conditions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_07_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_07_modern_applications</id>
   <content type="html">&lt;p&gt;You might think the KKT conditions are only for pencil-and-paper derivations, yet between 2022 and 2026 they became the secret engine behind &lt;strong&gt;differentiable optimization layers&lt;/strong&gt; inside deep neural networks (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt;, OptNet, Theseus)! How do PyTorch and JAX backpropagate gradients &lt;em&gt;through&lt;/em&gt; a convex optimization solver embedded inside a neural network? Not by unrolling thousands of solver iterations, but by applying the &lt;strong&gt;implicit function theorem directly to the KKT equations&lt;/strong&gt; at the optimal solution!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-where-the-kkt-system-lives-in-20222026-software&quot;&gt;Key ideas: Where the KKT System Lives in 2022–2026 Software&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Implicit Differentiation Through KKT (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt;, Theseus):&lt;/strong&gt; Writing the KKT system as \(F(z^\star(\theta), \theta) = 0\) (where \(z^\star = (x^\star, u^\star, v^\star)\)) lets us compute exact sensitivities \(\frac{\partial z^\star}{\partial \theta} = -(\nabla_z F)^{-1} \nabla_\theta F\) by solving a &lt;em&gt;single&lt;/em&gt; linear system—independent of how many iterations the forward solver took!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — SVM Support Vectors as Complementary Slackness:&lt;/strong&gt; Production kernel solvers (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libsvm&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt;) check KKT violation directly as their stopping criterion, and complementary slackness guarantees that only active margin points carry nonzero dual weights \(\alpha_i^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Electricity Grid LMPs &amp;amp; Congestion Pricing:&lt;/strong&gt; In wholesale power markets, KKT stationarity equates nodal Locational Marginal Prices (LMPs) to marginal generator cost plus congestion terms, while complementary slackness zeroes out congestion prices on every uncongested line.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Diagnosing Tight Fairness Constraints:&lt;/strong&gt; In constrained ML pipelines, reading the optimal KKT multipliers \(\lambda_g^\star\) tells engineers instantly &lt;em&gt;which&lt;/em&gt; demographic group constraint is binding (\(\lambda_g^\star &amp;gt; 0\)) and how much accuracy is being traded per unit of fairness tolerance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-differentiating-through-a-constrained-layer-via-kkt&quot;&gt;Worked example: Differentiating Through a Constrained Layer via KKT&lt;/h3&gt;

&lt;p&gt;Suppose a differentiable optimization layer takes a neural-network output \(\theta \in \mathbb{R}\) and outputs the solution \(x^\star(\theta)\) to the 1D constrained QP:
\(x^\star(\theta) = \arg\min_{x \in \mathbb{R}}\; \frac{1}{2}(x - \theta)^2 \quad \text{s.t.} \quad x \le 1.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the KKT system for \((x^\star, u^\star)\):&lt;/strong&gt;
\(x^\star - \theta + u^\star = 0, \qquad u^\star(x^\star - 1) = 0, \qquad x^\star \le 1,\; u^\star \ge 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Differentiate implicitly at \(\theta = 0.4\) (inactive regime: \(x^\star = 0.4 &amp;lt; 1,\; u^\star = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Since \(u^\star = 0\) stays identically zero in a neighborhood of \(\theta = 0.4\), differentiating \(x^\star - \theta = 0\) gives:
\(\frac{\partial x^\star}{\partial \theta}\Big|_{\theta=0.4} = 1.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Differentiate implicitly at \(\theta = 2.5\) (active regime: \(x^\star = 1,\; u^\star = 1.5 &amp;gt; 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Differentiating the active KKT pair \(x^\star - \theta + u^\star = 0\) and \(x^\star - 1 = 0\) with respect to \(\theta\) gives:
\(\begin{pmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{pmatrix} \begin{pmatrix} \partial x^\star / \partial \theta \\ \partial u^\star / \partial \theta \end{pmatrix} = \begin{pmatrix} 1 \\ 0 \end{pmatrix} \implies \frac{\partial x^\star}{\partial \theta} = 0, \quad \frac{\partial u^\star}{\partial \theta} = 1!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Aha!&lt;/strong&gt; Implicit KKT differentiation automatically derived the exact backward pass of a clamped ReLU/projection layer (slope \(1\) when inactive, slope \(0\) when saturated at \(1\))—and the exact same matrix solve scales to arbitrary multi-dimensional convex layers in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt;!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-the-kkt-conditions&quot;&gt;Modern applications of the KKT conditions&lt;/h1&gt;

&lt;p&gt;Chapter 12 states the KKT system — primal feasibility, dual feasibility, complementary slackness, and stationarity of the Lagrangian — and works the SVM, water-filling, and \(\ell_1\) examples. This optional lesson shows where that &lt;em&gt;system&lt;/em&gt; is solved, differentiated, or read as a price in 2022–2026 software. We do not re-list the four blocks.&lt;/p&gt;

&lt;h2 id=&quot;1-differentiating-through-a-solver-cvxpylayers-and-theseus&quot;&gt;1. Differentiating through a solver: cvxpylayers and Theseus&lt;/h2&gt;

&lt;p&gt;If \(x^\star(\theta)\) is the unique solution of a parametrized convex program, the implicit-function theorem applied to the KKT map \(F(x,u,v;\theta)=0\) yields \(\mathrm{d}x^\star/\mathrm{d}\theta\) without unrolling the solver. Agrawal, Amos, Barratt, Boyd, Diamond, and Kolter (NeurIPS 2019) shipped that idea as &lt;strong&gt;cvxpylayers&lt;/strong&gt; (PyTorch / JAX / MLX). It is still the default way, in 2024–2026, to put a QP or SOCP &lt;em&gt;inside&lt;/em&gt; a net: portfolio layers (DeepDow), MPC policies, and sparsemax-type projections.&lt;/p&gt;

&lt;p&gt;Pineda, Fan, Monge, Venkataraman, Sodhi, Chen, Ortiz, DeTone, Wang, Anderson, Dong, Amos, and Mukadam (NeurIPS 2022) released &lt;strong&gt;Theseus&lt;/strong&gt;, a GPU library for differentiable &lt;em&gt;nonlinear&lt;/em&gt; least squares used in robotics and vision. The backward pass is again implicit differentiation of the stationarity (Gauss–Newton / Levenberg–Marquardt) conditions — KKT for an equality-constrained or regularised NLS. The 2022 paper is the one to cite; the repo is what a SLAM / bundle-adjustment stack actually imports.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Course link.&lt;/strong&gt; Stationarity \(\nabla_x L=0\) is the linear system Theseus differentiates. Complementary slackness appears as soon as the layer has inequalities (cvxpylayers).&lt;/p&gt;

&lt;h2 id=&quot;2-svm-support-vectors-are-a-kkt-statement&quot;&gt;2. SVM support vectors are a KKT statement&lt;/h2&gt;

&lt;p&gt;The example &lt;a href=&quot;/contents/en/chapter12/12_04_Example_support_vector_machines/&quot;&gt;12-04&lt;/a&gt; is not ornamental. Complementary slackness says a point with \(0&amp;lt;\alpha_i&amp;lt;C\) lies on the margin, a point with \(\alpha_i=0\) is correctly classified with slack, and a point with \(\alpha_i=C\) is a bound support vector. Kernel SVM remains a standard tool in 2022–2026 small-\(n\) scientific ML (chemoinformatics, EEG, tabular clinical data) precisely because that finite set of vectors &lt;em&gt;is&lt;/em&gt; the model. When a paper reports “47 support vectors,” it is reporting the active set of a KKT system.&lt;/p&gt;

&lt;h2 id=&quot;3-electricity-lmps-and-complementary-slackness&quot;&gt;3. Electricity LMPs and complementary slackness&lt;/h2&gt;

&lt;p&gt;Locational marginal prices are the dual variables of power-balance and flow limits (Chapter 10). Liang and Dvorkin (2023) invert published LMPs to recover offer prices; the inversion is possible because, at a nondegenerate clearing point, KKT identifies which inequalities bind. Donti, Rolnick, and Kolter (2021) train DC3 so that the network’s output is driven toward a KKT-feasible OPF point. Water-filling in &lt;a href=&quot;/contents/en/chapter12/12_03_Example_water_filling/&quot;&gt;12-03&lt;/a&gt; is the same complementary-slackness picture in a Gaussian channel; 5G / 6G power-allocation papers still write that water level as a multiplier of a total-power inequality.&lt;/p&gt;

&lt;h2 id=&quot;4-fairness-which-group-constraint-is-tight&quot;&gt;4. Fairness: which group constraint is tight?&lt;/h2&gt;

&lt;p&gt;In a Fairlearn / reductions fit (Weerts et al., 2023), a large multiplier on equalised odds for group \(a\) means that group’s rate constraint is &lt;strong&gt;binding&lt;/strong&gt; — complementary slackness in prose. A zero multiplier means the unconstrained model already satisfied that rate. Reading \((x^\star,v^\star)\) is therefore a debugging tool: it tells you &lt;em&gt;which&lt;/em&gt; sociotechnical constraint is expensive, not only that the Lagrangian was minimised.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;KKT is the first-order system that (i) characterises a convex constrained optimum, (ii) can be differentiated to train a layer, and (iii) names the resources that have a price. If a 2024 paper “embeds a QP in a net” or “reports support vectors” or “publishes an LMP,” it is talking about that system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; Why does implicit differentiation of KKT need a constraint qualification and a nonsingular KKT Jacobian — and what fails in a Lasso layer when two features are identical?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Agrawal, A., Amos, B., Barratt, S., Boyd, S., Diamond, S., &amp;amp; Kolter, J. Z. (2019). Differentiable convex optimization layers. &lt;em&gt;NeurIPS&lt;/em&gt;. Library: &lt;a href=&quot;https://www.cvxpylayers.org/&quot;&gt;cvxpylayers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Pineda, L., Fan, T., Monge, M., Venkataraman, S., Sodhi, P., Chen, R. T. Q., Ortiz, J., DeTone, D., Wang, A., Anderson, S., Dong, J., Amos, B., &amp;amp; Mukadam, M. (2022). Theseus: A library for differentiable nonlinear optimization. &lt;em&gt;NeurIPS&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2207.09442&quot;&gt;arXiv:2207.09442&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Liang, Z., &amp;amp; Dvorkin, Y. (2023). Data-driven inverse optimization for marginal offer price recovery in electricity markets. &lt;em&gt;ACM e-Energy ’23&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Donti, P. L., Rolnick, D., &amp;amp; Kolter, J. Z. (2021). DC3: A learning method for optimization with hard constraints. &lt;em&gt;ICLR&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>11-11 Modern applications of Lagrangian duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_11_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_11_modern_applications</id>
   <content type="html">&lt;p&gt;Between 2022 and 2026, Lagrangian duality evolved from a theoretical proof tool into a core architectural primitive inside machine learning and scientific computing. Whether you are training a distributionally robust classifier against shifted test data, enforcing AC power-grid physics inside a neural solver, or balancing fairness constraints across subpopulations, dualizing the constraints converts hard feasibility walls into smooth, differentiable shadow prices that scale to millions of parameters.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-high-impact-modern-uses-of-lagrangian-duality&quot;&gt;Key ideas: Four High-Impact Modern Uses of Lagrangian Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Dualizing Robustness Radii (DRO):&lt;/strong&gt; In KL-divergence or Wasserstein DRO, strong duality collapses the worst-case distributional supremum into a tractable variance or Lipschitz regularizer parameterized by a single dual multiplier \(\lambda \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Primal–Dual Neural Surrogates (OPF-DNN / DC3):&lt;/strong&gt; Deep learning models trained to predict physical grid or control schedules use primal–dual Lagrangian training loops to penalize constraint violations dynamically until feasibility is restored.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Cost-Sensitive Fairness Games:&lt;/strong&gt; Turning demographic parity or equalized odds into Lagrangian penalties allows existing unconstrained classifiers (trees, neural nets) to serve as the primal best-response oracle while dual multipliers reweight groups.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Dual Sparsity in Kernel Machines:&lt;/strong&gt; Even in the deep-learning era, dual SVMs remain widely used in bioinformatics and low-data scientific regimes because dual variables \(\alpha_i\) vanish on non-support vectors, yielding compact, kernelizable decision boundaries.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-primaldual-update-in-a-constrained-neural-training-loop&quot;&gt;Worked example: One Primal–Dual Update in a Constrained Neural Training Loop&lt;/h3&gt;

&lt;p&gt;Suppose a neural surrogate parameterized by \(\theta \in \mathbb{R}\) minimizes prediction error \(f(\theta) = \frac{1}{2}(\theta - 4)^2\) subject to a physical safety cap \(h(\theta) = \theta - 2 \le 0\). Instead of projecting onto \(h(\theta) \le 0\), a primal–dual trainer updates \(\theta\) by gradient descent on \(L(\theta, u) = \frac{1}{2}(\theta - 4)^2 + u(\theta - 2)\) and \(u \ge 0\) by projected gradient ascent, with step sizes \(\eta_\theta = 0.5,\; \eta_u = 1.0\), starting from \(\theta^{(0)} = 3.0,\; u^{(0)} = 0.0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Step 1 at \((\theta^{(0)}, u^{(0)}) = (3.0, 0.0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal gradient: \(\nabla_\theta L(3, 0) = (3 - 4) + 0 = -1.0 \implies \theta^{(1)} = 3.0 - 0.5(-1.0) = 3.5\) (constraint violation worsens to \(3.5 - 2 = 1.5\) because price \(u^{(0)} = 0\)!).&lt;/li&gt;
      &lt;li&gt;Dual ascent on constraint violation \(h(\theta^{(1)}) = 3.5 - 2 = +1.5\):
\(u^{(1)} = \max(0,\; 0.0 + 1.0(1.5)) = 1.5.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 2 at \((\theta^{(1)}, u^{(1)}) = (3.5, 1.5)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal gradient: \(\nabla_\theta L(3.5, 1.5) = (3.5 - 4) + 1.5 = +1.0 \implies \theta^{(2)} = 3.5 - 0.5(1.0) = 3.0\) (the rising dual price immediately pulls \(\theta\) back toward the safe boundary \(\theta \le 2\)!).&lt;/li&gt;
      &lt;li&gt;Dual ascent on \(h(\theta^{(2)}) = 3.0 - 2 = +1.0\):
\(u^{(2)} = \max(0,\; 1.5 + 1.0(1.0)) = 2.5.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equilibrium check:&lt;/strong&gt; The primal–dual saddle point satisfies \(\theta^\star - 4 + u^\star = 0\) and \(\theta^\star = 2 \implies (\theta^\star, u^\star) = (2, 2)\). Watching \(u\) automatically ramp up until it balances the primal pull toward \(4\) is the exact feedback mechanism powering primal–dual constrained deep learning!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-lagrangian-duality&quot;&gt;Modern applications of Lagrangian duality&lt;/h1&gt;

&lt;p&gt;Chapter 11 lifts duality from LPs to a general program: the Lagrangian \(L(x,u,v)\), the dual function \(g(u,v)=\inf_x L\), weak duality \(g\le f^\star\), and strong duality under convexity plus a constraint qualification. This optional lesson shows four modern uses of &lt;em&gt;that&lt;/em&gt; dual — multipliers as prices, as robustness radii, and as training signals — without re-deriving \(g\).&lt;/p&gt;

&lt;h2 id=&quot;1-distributionally-robust-learning-dro&quot;&gt;1. Distributionally robust learning (DRO)&lt;/h2&gt;

&lt;p&gt;Instead of minimising empirical risk \(\mathbb{E}_{\hat P}[\ell(x,\xi)]\), DRO solves&lt;/p&gt;

\[\min_x\ \sup_{P\in\mathcal{P}}\ \mathbb{E}_P[\ell(x,\xi)],\]

&lt;p&gt;where the ambiguity set \(\mathcal{P}\) is a ball of distributions (\(\phi\)-divergence or Wasserstein) around the sample. The inner supremum is a &lt;strong&gt;conjugate / dual&lt;/strong&gt; problem: for a Wasserstein ball it becomes a regularised risk whose dual variable is the Lipschitz price of moving mass. Rahimian and Mehrotra (2022) survey the duality, the calibration of \(\mathcal{P}\), and the solvers. Kuhn, Esfahani, Nguyen, and Shafieezadeh-Abadeh (2019) is the Wasserstein tutorial still cited in 2023–2026 ML papers on noisy labels, shift, and adversarial training. Strong duality is what turns an infinite-dimensional worst-case expectation into a finite convex program you can hand to CVXPY.&lt;/p&gt;

&lt;h2 id=&quot;2-hard-constraints-in-energy-and-physics-opf-dnn-and-dc3&quot;&gt;2. Hard constraints in energy and physics: OPF-DNN and DC3&lt;/h2&gt;

&lt;p&gt;AC optimal power flow (OPF) is a nonconvex program with Kirchhoff equalities and thermal limits. Fioretto, Mak, and Van Hentenryck (AAAI 2020) train a network to predict setpoints while &lt;strong&gt;updating Lagrange multipliers by a subgradient step&lt;/strong&gt; on constraint residuals — Lagrangian duality as a training loop. Donti, Rolnick, and Kolter (ICLR 2021) propose &lt;strong&gt;DC3&lt;/strong&gt;: complete equalities differentiably, then correct inequalities by unrolled gradient steps, and demonstrate it on AC-OPF. Follow-up 2022–2025 “learning to optimize” papers keep the same dual idea: multipliers are not only certificates after the fact; they are &lt;strong&gt;features&lt;/strong&gt; the net is trained to respect.&lt;/p&gt;

&lt;p&gt;Weak duality still gives a bound even when the primal is nonconvex; strong duality is &lt;em&gt;not&lt;/em&gt; free. That distinction is the whole point of this chapter.&lt;/p&gt;

&lt;h2 id=&quot;3-fairness-reductions-as-a-dual-game&quot;&gt;3. Fairness reductions as a dual game&lt;/h2&gt;

&lt;p&gt;Agarwal et al. (2018) and the Fairlearn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExponentiatedGradient&lt;/code&gt; reducer (Weerts et al., 2023) treat group-rate constraints as a Lagrangian. The dual player puts mass on the currently violated group; the primal player solves a &lt;em&gt;weighted&lt;/em&gt; ERM. Cotter et al. (2019) extend the game to nonsmooth rate constraints via a proxy-Lagrangian. In all three, \(v\ge 0\) is the Chapter 11 multiplier of an inequality \(g_i(x)\le 0\), and complementary slackness (Chapter 12) says a group that already meets its rate should have \(v_i=0\).&lt;/p&gt;

&lt;h2 id=&quot;4-svm-and-kernel-machines-still-via-the-dual&quot;&gt;4. SVM and kernel machines, still via the dual&lt;/h2&gt;

&lt;p&gt;The soft-margin SVM is the textbook general program whose dual is a box-constrained QP in the coefficients \(\alpha_i\). sklearn’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SVC&lt;/code&gt; and a long tail of 2022–2026 computational-biology and small-\(n\) tabular papers still &lt;em&gt;solve the dual&lt;/em&gt;, because the kernel trick is a statement about \(g(\alpha)\), not about \(w\). You will meet the KKT form in Chapter 12; the &lt;em&gt;existence&lt;/em&gt; of a useful \(g\) is this chapter.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;Form the Lagrangian, minimise in \(x\) to get \(g\), maximise \(g\) in the multipliers. If the primal is convex and a CQ holds, you may swap inf and sup. DRO, constrained nets, fairness reducers, and kernel SVMs are four different stories about that swap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; In a Wasserstein DRO problem, what does a large optimal dual variable on the radius tell you about the cost of a distribution shift — and which inequality of this chapter makes that number a valid lower bound on worst-case risk?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Rahimian, H., &amp;amp; Mehrotra, S. (2022). Frameworks and results in distributionally robust optimization. &lt;em&gt;Open Journal of Mathematical Optimization&lt;/em&gt;, 3, article 4. &lt;a href=&quot;https://doi.org/10.5802/ojmo.15&quot;&gt;doi:10.5802/ojmo.15&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Kuhn, D., Esfahani, P. M., Nguyen, V. A., &amp;amp; Shafieezadeh-Abadeh, S. (2019). Wasserstein distributionally robust optimization: Theory and applications in machine learning. In &lt;em&gt;Operations Research &amp;amp; Management Science in the Age of Analytics&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Fioretto, F., Mak, T. W. K., &amp;amp; Van Hentenryck, P. (2020). Predicting AC optimal power flows: Combining deep learning and Lagrangian dual methods. &lt;em&gt;AAAI&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Donti, P. L., Rolnick, D., &amp;amp; Kolter, J. Z. (2021). DC3: A learning method for optimization with hard constraints. &lt;em&gt;ICLR&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257).&lt;/li&gt;
  &lt;li&gt;Agarwal, A., Beygelzimer, A., Dudík, M., Langford, J., &amp;amp; Wallach, H. (2018). A reductions approach to fair classification. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Cotter, A., et al. (2019). Optimization with non-differentiable constraints with applications to fairness, recall, churn, and other goals. &lt;em&gt;JMLR&lt;/em&gt;, 20(172).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>11-08 Modern applications of Lagrangian duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_08_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_08_modern_applications</id>
   <content type="html">&lt;p&gt;If Lagrangian duality felt abstract when we defined \(g(u, v) = \inf_x L(x, u, v)\), look at how modern ML and engineering systems from 2022 to 2026 actually deploy it: in &lt;strong&gt;distributionally robust optimization (DRO)&lt;/strong&gt;, dualizing a worst-case Wasserstein or \(f\)-divergence ball around the empirical distribution converts an infinite-dimensional adversary into a single scalar multiplier \(\lambda \ge 0\)! Likewise, in physics-constrained neural grids (OPF-DNN / DC3), fairness reductions, and kernel SVMs, the Lagrange dual is what makes otherwise intractable constraints computationally solvable.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-modern-roles-of-the-lagrange-dual-20222026&quot;&gt;Key ideas: Modern Roles of the Lagrange Dual (2022–2026)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Distributionally Robust Learning (DRO):&lt;/strong&gt; Protecting a model against distribution shift solves \(\min_\theta \sup_{Q : D(Q \| \hat{P}_n) \le \rho} \mathbb{E}_Q[\ell(\theta; Z)]\). Taking the Lagrange dual of the inner supremum eliminates the infinite-dimensional measure \(Q\) completely, leaving a finite-dimensional joint minimization over \((\theta, \lambda \ge 0)\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Physics &amp;amp; Energy Constraints (OPF-DNN / DC3):&lt;/strong&gt; Training neural surrogates to solve AC Optimal Power Flow in milliseconds uses augmented Lagrangian / dual-ascent updates to keep voltages and thermal limits strictly feasible.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Fairness Reductions as Saddle-Point Games:&lt;/strong&gt; Enforcing group-fairness inequalities via Lagrange multipliers turns constrained classification into a two-player zero-sum game between a cost-sensitive learner (primal) and an exponentiated-gradient multiplier player (dual).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Kernel SVMs &amp;amp; High-Dimensional Duals:&lt;/strong&gt; Whenever feature dimension \(p \gg n\) (or infinite-dimensional RKHS via kernels), Slater’s condition guarantees strong duality so we can solve the \(n\)-variable dual QP instead of the \(p\)-variable primal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-dualizing-a-2-scenario-worst-case-dro-subproblem&quot;&gt;Worked example: Dualizing a 2-Scenario Worst-Case DRO Subproblem&lt;/h3&gt;

&lt;p&gt;Suppose a model incurs loss \(\ell_1 = 1\) on Scenario 1 and \(\ell_2 = 5\) on Scenario 2, with nominal probabilities \(p = (0.5, 0.5)\). An adversary can shift probabilities to \(q = (q_1, q_2)\) on the simplex subject to the \(\chi^2\)-divergence budget \(\frac{1}{2}\sum_{i=1}^2 \frac{(q_i - 0.5)^2}{0.5} \le \rho\) with \(\rho = 0.08\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Primal inner adversary problem:&lt;/strong&gt;
\(\max_{q_1 + q_2 = 1}\; 1 q_1 + 5 q_2 \quad \text{s.t.} \quad (q_1 - 0.5)^2 + (q_2 - 0.5)^2 \le 0.08.\)
Write \(q_1 = 0.5 - \delta\), \(q_2 = 0.5 + \delta\) (so \(q_1 + q_2 = 1\) automatically). The objective is \(3 + 4\delta\) and the constraint is \(2\delta^2 \le 0.08 \iff \delta^2 \le 0.04 \iff |\delta| \le 0.2\).
    &lt;ul&gt;
      &lt;li&gt;Primal worst-case loss: \(\delta^\star = 0.2 \implies q^\star = (0.3, 0.7)\) and \(p^\star = 3 + 4(0.2) = 3.8\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve via the Lagrange dual (multiplier \(\lambda \ge 0\) on \(2\delta^2 - 0.08 \le 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Lagrangian: \(L(\delta, \lambda) = 3 + 4\delta - \lambda(2\delta^2 - 0.08)\).&lt;/li&gt;
      &lt;li&gt;Maximize over unconstrained \(\delta\): \(4 - 4\lambda\delta = 0 \implies \delta = 1/\lambda\) (for \(\lambda &amp;gt; 0\)).&lt;/li&gt;
      &lt;li&gt;Dual objective to &lt;em&gt;minimize&lt;/em&gt; over \(\lambda &amp;gt; 0\):
\(d(\lambda) = 3 + \frac{4}{\lambda} - \lambda\left(\frac{2}{\lambda^2} - 0.08\right) = 3 + \frac{2}{\lambda} + 0.08\lambda.\)&lt;/li&gt;
      &lt;li&gt;Set \(d&apos;(\lambda) = -\frac{2}{\lambda^2} + 0.08 = 0 \implies \lambda^2 = 25 \implies \lambda^\star = 5\)!&lt;/li&gt;
      &lt;li&gt;Dual optimal value: \(d(5) = 3 + \frac{2}{5} + 0.08(5) = 3 + 0.4 + 0.4 = 3.8 = p^\star\)!
Notice how the dual replaced the constrained optimization over \(q\) with a simple 1D formula \(3 + \sqrt{2 \rho \, \text{Var}(\ell)}\)—exact mean + standard-deviation regularization!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-lagrangian-duality&quot;&gt;Modern applications of Lagrangian duality&lt;/h1&gt;

&lt;p&gt;Chapter 11 lifts duality from LPs to a general program: the Lagrangian \(L(x,u,v)\), the dual function \(g(u,v)=\inf_x L\), weak duality \(g\le f^\star\), and strong duality under convexity plus a constraint qualification. This optional lesson shows four modern uses of &lt;em&gt;that&lt;/em&gt; dual — multipliers as prices, as robustness radii, and as training signals — without re-deriving \(g\).&lt;/p&gt;

&lt;h2 id=&quot;1-distributionally-robust-learning-dro&quot;&gt;1. Distributionally robust learning (DRO)&lt;/h2&gt;

&lt;p&gt;Instead of minimising empirical risk \(\mathbb{E}_{\hat P}[\ell(x,\xi)]\), DRO solves&lt;/p&gt;

\[\min_x\ \sup_{P\in\mathcal{P}}\ \mathbb{E}_P[\ell(x,\xi)],\]

&lt;p&gt;where the ambiguity set \(\mathcal{P}\) is a ball of distributions (\(\phi\)-divergence or Wasserstein) around the sample. The inner supremum is a &lt;strong&gt;conjugate / dual&lt;/strong&gt; problem: for a Wasserstein ball it becomes a regularised risk whose dual variable is the Lipschitz price of moving mass. Rahimian and Mehrotra (2022) survey the duality, the calibration of \(\mathcal{P}\), and the solvers. Kuhn, Esfahani, Nguyen, and Shafieezadeh-Abadeh (2019) is the Wasserstein tutorial still cited in 2023–2026 ML papers on noisy labels, shift, and adversarial training. Strong duality is what turns an infinite-dimensional worst-case expectation into a finite convex program you can hand to CVXPY.&lt;/p&gt;

&lt;h2 id=&quot;2-hard-constraints-in-energy-and-physics-opf-dnn-and-dc3&quot;&gt;2. Hard constraints in energy and physics: OPF-DNN and DC3&lt;/h2&gt;

&lt;p&gt;AC optimal power flow (OPF) is a nonconvex program with Kirchhoff equalities and thermal limits. Fioretto, Mak, and Van Hentenryck (AAAI 2020) train a network to predict setpoints while &lt;strong&gt;updating Lagrange multipliers by a subgradient step&lt;/strong&gt; on constraint residuals — Lagrangian duality as a training loop. Donti, Rolnick, and Kolter (ICLR 2021) propose &lt;strong&gt;DC3&lt;/strong&gt;: complete equalities differentiably, then correct inequalities by unrolled gradient steps, and demonstrate it on AC-OPF. Follow-up 2022–2025 “learning to optimize” papers keep the same dual idea: multipliers are not only certificates after the fact; they are &lt;strong&gt;features&lt;/strong&gt; the net is trained to respect.&lt;/p&gt;

&lt;p&gt;Weak duality still gives a bound even when the primal is nonconvex; strong duality is &lt;em&gt;not&lt;/em&gt; free. That distinction is the whole point of this chapter.&lt;/p&gt;

&lt;h2 id=&quot;3-fairness-reductions-as-a-dual-game&quot;&gt;3. Fairness reductions as a dual game&lt;/h2&gt;

&lt;p&gt;Agarwal et al. (2018) and the Fairlearn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExponentiatedGradient&lt;/code&gt; reducer (Weerts et al., 2023) treat group-rate constraints as a Lagrangian. The dual player puts mass on the currently violated group; the primal player solves a &lt;em&gt;weighted&lt;/em&gt; ERM. Cotter et al. (2019) extend the game to nonsmooth rate constraints via a proxy-Lagrangian. In all three, \(v\ge 0\) is the Chapter 11 multiplier of an inequality \(g_i(x)\le 0\), and complementary slackness (Chapter 12) says a group that already meets its rate should have \(v_i=0\).&lt;/p&gt;

&lt;h2 id=&quot;4-svm-and-kernel-machines-still-via-the-dual&quot;&gt;4. SVM and kernel machines, still via the dual&lt;/h2&gt;

&lt;p&gt;The soft-margin SVM is the textbook general program whose dual is a box-constrained QP in the coefficients \(\alpha_i\). sklearn’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SVC&lt;/code&gt; and a long tail of 2022–2026 computational-biology and small-\(n\) tabular papers still &lt;em&gt;solve the dual&lt;/em&gt;, because the kernel trick is a statement about \(g(\alpha)\), not about \(w\). You will meet the KKT form in Chapter 12; the &lt;em&gt;existence&lt;/em&gt; of a useful \(g\) is this chapter.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;Form the Lagrangian, minimise in \(x\) to get \(g\), maximise \(g\) in the multipliers. If the primal is convex and a CQ holds, you may swap inf and sup. DRO, constrained nets, fairness reducers, and kernel SVMs are four different stories about that swap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; In a Wasserstein DRO problem, what does a large optimal dual variable on the radius tell you about the cost of a distribution shift — and which inequality of this chapter makes that number a valid lower bound on worst-case risk?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Rahimian, H., &amp;amp; Mehrotra, S. (2022). Frameworks and results in distributionally robust optimization. &lt;em&gt;Open Journal of Mathematical Optimization&lt;/em&gt;, 3, article 4. &lt;a href=&quot;https://doi.org/10.5802/ojmo.15&quot;&gt;doi:10.5802/ojmo.15&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Kuhn, D., Esfahani, P. M., Nguyen, V. A., &amp;amp; Shafieezadeh-Abadeh, S. (2019). Wasserstein distributionally robust optimization: Theory and applications in machine learning. In &lt;em&gt;Operations Research &amp;amp; Management Science in the Age of Analytics&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Fioretto, F., Mak, T. W. K., &amp;amp; Van Hentenryck, P. (2020). Predicting AC optimal power flows: Combining deep learning and Lagrangian dual methods. &lt;em&gt;AAAI&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Donti, P. L., Rolnick, D., &amp;amp; Kolter, J. Z. (2021). DC3: A learning method for optimization with hard constraints. &lt;em&gt;ICLR&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257).&lt;/li&gt;
  &lt;li&gt;Agarwal, A., Beygelzimer, A., Dudík, M., Langford, J., &amp;amp; Wallach, H. (2018). A reductions approach to fair classification. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Cotter, A., et al. (2019). Optimization with non-differentiable constraints with applications to fairness, recall, churn, and other goals. &lt;em&gt;JMLR&lt;/em&gt;, 20(172).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>10-10 Modern applications of LP duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_10_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_10_modern_applications</id>
   <content type="html">&lt;p&gt;From pricing megawatts across continental power grids to certifying the safety of deep neural networks and matching high-dimensional probability distributions via optimal transport, LP duality is quietly embedded in modern 2022–2026 software stacks. What makes LP duality uniquely valuable in production is not just strong duality at optimality, but &lt;strong&gt;anytime weak duality&lt;/strong&gt;: every dual-feasible vector immediately delivers a rock-solid lower bound or shadow-price interpretation that downstream systems can trust in real time.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-production-pillars-of-lp-duality&quot;&gt;Key ideas: Four Production Pillars of LP Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Anytime Verification Certificates:&lt;/strong&gt; In formal verification of ReLU networks, optimizing the LP dual on GPUs produces valid safety lower bounds at &lt;em&gt;every&lt;/em&gt; iteration, allowing branch-and-bound verifiers to prune safe regions milliseconds after starting.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Shadow Prices in Grid Dispatch:&lt;/strong&gt; In DC optimal power flow (DC-OPF), the primal minimizes generation cost subject to nodal power balance and thermal line caps; complementary slackness reveals exactly which transmission lines are congested (nonzero dual price) and drives locational price differences.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Modern Max-Flow Solvers:&lt;/strong&gt; The 2022 near-linear-time \(m^{1+o(1)}\) max-flow breakthrough combines primal–dual interior-point barriers with dynamic trees, turning classical network-flow duality into an ultra-fast subroutine for vision, clustering, and logistics.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Kantorovich Potentials in Optimal Transport:&lt;/strong&gt; Dualizing the discrete transport LP reveals potentials \((\phi, \psi)\) with \(\phi_i + \psi_j \le C_{ij}\) that generalize seamlessly to continuous distributions and entropic (Sinkhorn) regularization.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-nodal-shadow-prices-lmps-in-a-2-bus-power-grid&quot;&gt;Worked example: Nodal Shadow Prices (LMPs) in a 2-Bus Power Grid&lt;/h3&gt;

&lt;p&gt;Consider two cities (Bus 1 and Bus 2) connected by a single transmission line with thermal capacity \(F_{\max} = 30\) MW. Bus 1 has a cheap generator (\(\$20\)/MWh, capacity \(100\) MW); Bus 2 has an expensive generator (\(\$50\)/MWh, capacity \(100\) MW) and local demand \(D_2 = 50\) MW.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Primal Economic Dispatch LP:&lt;/strong&gt; Minimize \(20 g_1 + 50 g_2\) subject to:
    &lt;ul&gt;
      &lt;li&gt;Bus 1 balance: \(g_1 - f = 0\) (dual price \(\lambda_1\)).&lt;/li&gt;
      &lt;li&gt;Bus 2 balance: \(g_2 + f = 50\) (dual price \(\lambda_2\)).&lt;/li&gt;
      &lt;li&gt;Line thermal cap: \(f \le 30\) (congestion price \(\mu \ge 0\)), and \(g_1, g_2, f \ge 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the primal dispatch:&lt;/strong&gt; Send as much cheap power as the line allows: \(f^\star = 30\) MW, \(g_1^\star = 30\) MW, and generate the remaining \(g_2^\star = 20\) MW locally at Bus 2. Total cost: \(20(30) + 50(20) = \$1{,}600\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Read off the dual LMPs via complementary slackness:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Because \(g_1^\star = 30 &amp;gt; 0\) (below its 100 MW cap), Bus 1’s marginal price must equal Generator 1’s cost: \(\lambda_1^\star = \$20\text{/MWh}\).&lt;/li&gt;
      &lt;li&gt;Because \(g_2^\star = 20 &amp;gt; 0\) (below its 100 MW cap), Bus 2’s marginal price must equal Generator 2’s cost: \(\lambda_2^\star = \$50\text{/MWh}\).&lt;/li&gt;
      &lt;li&gt;Because \(f^\star = 30 &amp;gt; 0\), dual stationarity on \(f\) gives \(\lambda_2^\star - \lambda_1^\star - \mu^\star = 0 \implies \mu^\star = 50 - 20 = \$30\text{/MWh}\) (the exact congestion rent per MW of line capacity!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify strong duality:&lt;/strong&gt; Dual value \(= 50 \lambda_2^\star - 30 \mu^\star = 50(50) - 30(30) = 2500 - 900 = \$1{,}600 = p^\star\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-lp-duality&quot;&gt;Modern applications of LP duality&lt;/h1&gt;

&lt;p&gt;Chapter 10 derives the dual of a linear program, weak/strong duality, complementary slackness, and the max-flow / min-cut and matrix-game examples. This optional lesson shows four places where those &lt;em&gt;same&lt;/em&gt; certificates were used in CS and data-science systems from about 2022 to 2026.&lt;/p&gt;

&lt;p&gt;A primal LP \(\min\{c^\top x:Ax=b,\,Gx\le h\}\) and its dual still mean: every feasible dual pair \((u,v)\) is a &lt;strong&gt;lower bound&lt;/strong&gt;, and at optimality the bound is tight and unused inequalities have zero multipliers.&lt;/p&gt;

&lt;h2 id=&quot;1-neural-network-verification-as-an-lp-then-a-cut-lp&quot;&gt;1. Neural-network verification as an LP (then a cut LP)&lt;/h2&gt;

&lt;p&gt;Asking whether a classifier can change its label inside an \(\ell_\infty\) box is a nonconvex problem in the ReLU activations. The standard relaxation replaces each ReLU by a triangle / LP outer approximation (Ehlers; Wong and Kolter). Dual variables of that LP are &lt;strong&gt;bound-propagation multipliers&lt;/strong&gt;. Zhang, Wang, Xu, Li, Li, Jana, Hsieh, and Kolter (NeurIPS 2022) added &lt;strong&gt;general cutting planes&lt;/strong&gt; to that dual (GCP-CROWN) and folded it into &lt;strong&gt;\(\alpha,\beta\)-CROWN&lt;/strong&gt;, which won the International Verification of Neural Networks Competition in 2021, 2022, 2023, 2024, and 2025. The engineering is GPU bound-propagation; the certificate is still “the dual of a tightened LP is above zero, hence no adversarial example exists.”&lt;/p&gt;

&lt;p&gt;This is Chapter 10’s weak duality used as a &lt;strong&gt;safety proof&lt;/strong&gt;, not as a pricing story.&lt;/p&gt;

&lt;h2 id=&quot;2-electricity-markets-clearing-lps-and-shadow-prices&quot;&gt;2. Electricity markets: clearing LPs and shadow prices&lt;/h2&gt;

&lt;p&gt;Day-ahead energy markets clear a (mixed-integer) linear program: minimise offer cost subject to power-balance and line limits. The dual of the &lt;em&gt;linear&lt;/em&gt; relaxation is the vector of &lt;strong&gt;locational marginal prices&lt;/strong&gt; (LMPs). After the 2022 European price spike, that dual was no longer a textbook cartoon: it is the number on the invoice. Liang and Dvorkin (ACM e-Energy 2023) use inverse optimization on published schedules and LMPs to recover generators’ offer prices — they invert the KKT / dual map of the clearing LP. Related 2022–2023 work on European day-ahead auctions writes zonal prices explicitly as duals of network-constrained welfare LPs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Course link.&lt;/strong&gt; Complementary slackness says a congested line (\(Gx=h\)) is the only line that can carry a nonzero congestion price \(v\). That sentence is this chapter, applied to a grid.&lt;/p&gt;

&lt;h2 id=&quot;3-max-flow--min-cut-after-2022&quot;&gt;3. Max-flow / min-cut after 2022&lt;/h2&gt;

&lt;p&gt;The theorem in &lt;a href=&quot;/contents/en/chapter10/10_03_Max_flow_and_min_cut/&quot;&gt;10-03&lt;/a&gt; is still the dual pair behind image segmentation, closed-world community detection, and reliability cuts in communication networks. Modern large-scale solvers (Gurobi, HiGHS, OR-Tools) expose the dual as a first-class vector; a data-science workflow that “allocates bandwidth” or “cuts a graph into source/sink sets” is reading that vector. The &lt;em&gt;new&lt;/em&gt; CS use is often a &lt;strong&gt;learned&lt;/strong&gt; capacity (a GNN predicts edge weights) followed by a classical max-flow dual as a layer — the same pairing as differentiable optimization in Chapter 12, but the inner problem is an LP.&lt;/p&gt;

&lt;h2 id=&quot;4-optimal-transport-as-a-giant-lp&quot;&gt;4. Optimal transport as a giant LP&lt;/h2&gt;

&lt;p&gt;The Kantorovich problem&lt;/p&gt;

\[\min_{\pi\ge 0}\ \langle C,\pi\rangle\quad\text{s.t.}\quad \pi\mathbf{1}=a,\ \pi^\top\mathbf{1}=b\]

&lt;p&gt;is an LP. Its dual is \(\max_{f,g} f^\top a+g^\top b\) subject to \(f_i+g_j\le C_{ij}\) — the &lt;strong&gt;Kantorovich potentials&lt;/strong&gt;. Peyré and Cuturi (2019) is the computational monograph; 2022–2026 domain adaptation, dataset distillation, and single-cell alignment still solve a regularised (Sinkhorn) or unregularised version and read the dual as a soft matching. Weak duality is the statement that no coupling can cost less than any feasible pair of potentials.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;An LP dual is a &lt;strong&gt;certificate&lt;/strong&gt;: of infeasibility (verification), of a price (markets), of a cut (networks), or of a matching cost (transport). If you can write the primal and produce a feasible dual with equal objective, you are done — that is strong duality for LPs, and it is what those four applications compute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; In GCP-CROWN, why does &lt;em&gt;adding&lt;/em&gt; a cutting plane to the primal LP only &lt;em&gt;raise&lt;/em&gt; the dual lower bound? Which theorem of this chapter is that?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Zhang, H., Wang, S., Xu, K., Li, L., Li, B., Jana, S., Hsieh, C.-J., &amp;amp; Kolter, J. Z. (2022). General cutting planes for bound-propagation-based neural network verification. &lt;em&gt;NeurIPS&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2208.05740&quot;&gt;arXiv:2208.05740&lt;/a&gt;. Tool: &lt;a href=&quot;https://github.com/Verified-Intelligence/alpha-beta-CROWN&quot;&gt;α,β-CROWN&lt;/a&gt; (VNN-COMP 2021–2025 winner).&lt;/li&gt;
  &lt;li&gt;Liang, Z., &amp;amp; Dvorkin, Y. (2023). Data-driven inverse optimization for marginal offer price recovery in electricity markets. &lt;em&gt;ACM e-Energy ’23&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Peyré, G., &amp;amp; Cuturi, M. (2019). Computational optimal transport. &lt;em&gt;Foundations and Trends in Machine Learning&lt;/em&gt;, 11(5–6). (standard LP/dual reference still used in 2022–2026 OT pipelines)&lt;/li&gt;
  &lt;li&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;, Ch. 5 (LP duality and shadow prices).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>10-07 Modern applications of LP duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_07_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_07_modern_applications</id>
   <content type="html">&lt;p&gt;Linear programming duality might be seventy-five years old, but between 2022 and 2026 it became one of the sharpest weapons in modern computer science and infrastructure engineering. When a neural-network verifier certifies that an autonomous-driving perception model cannot be fooled inside an \(\ell_\infty\) box, when an electricity grid operator computes real-time locational marginal prices (LMPs) every five minutes, or when a generative model computes Wasserstein optimal transport distances, the core mathematical engine is literally a dual LP certificate!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-lp-duality-in-20222026-systems&quot;&gt;Key ideas: LP Duality in 2022–2026 Systems&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Neural-Network Verification via Dual Bounds (\(\alpha,\beta\)-CROWN):&lt;/strong&gt; Relaxing ReLU activations to their convex triangle envelope yields an LP whose &lt;em&gt;any&lt;/em&gt; dual-feasible point gives a sound, certified lower bound on the worst-case margin—allowing GPU-parallel dual ascent to verify robustness without solving the primal LP to completion.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Electricity Markets &amp;amp; Locational Marginal Prices (LMPs):&lt;/strong&gt; Economic dispatch clears power generation via a large-scale LP subject to transmission-line limits; the optimal dual variables on nodal power-balance constraints &lt;em&gt;are&lt;/em&gt; the real-time electricity prices paid to generators and charged to utilities.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Near-Linear-Time Max-Flow / Min-Cut (2022 Breakthrough):&lt;/strong&gt; Chen et al. (2022) solved minimum-cost flow and max-flow in almost-linear time \(O(m^{1 + o(1)})\) using interior-point primal–dual updates and dynamic data structures, closing a decades-old algorithmic frontier.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Optimal Transport &amp;amp; Kantorovich Duality:&lt;/strong&gt; Matching two empirical probability distributions \(\mu, \nu\) at minimum Earth Mover’s cost is a giant LP whose dual maximizes \(\mathbb{E}_\mu[\phi] - \mathbb{E}_\nu[\psi]\) over \(1\)-Lipschitz Kantorovich potentials—the exact foundation of Wasserstein distances in ML.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-a-sound-dual-robustness-certificate-for-a-tiny-relu-relaxation&quot;&gt;Worked example: Computing a Sound Dual Robustness Certificate for a Tiny ReLU Relaxation&lt;/h3&gt;

&lt;p&gt;Suppose verifying a neural network boils down to checking whether \(p^\star = \min \{ x_2 : x_2 \ge 0,\; x_2 \ge 2x_1 - 1,\; 0 \le x_1 \le 1 \}\) is strictly above \(-0.5\) (safe). We want a &lt;strong&gt;certified lower bound&lt;/strong&gt; using &lt;em&gt;any&lt;/em&gt; dual-feasible multiplier without even solving the primal!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Rewrite constraints in \(\le\) form:&lt;/strong&gt;
\(-x_2 \le 0 \;(u_1), \quad 2x_1 - x_2 \le 1 \;(u_2), \quad -x_1 \le 0 \;(u_3), \quad x_1 \le 1 \;(u_4).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form the dual objective and constraints (\(c = (0, 1)^\top\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Dual objective to maximize: \(-h^\top u = -u_2 - u_4\).&lt;/li&gt;
      &lt;li&gt;Dual constraints \(-G^\top u = c\):
        &lt;ul&gt;
          &lt;li&gt;For \(x_1\): \(-2u_2 + u_3 - u_4 = 0\).&lt;/li&gt;
          &lt;li&gt;For \(x_2\): \(u_1 + u_2 = 1\).&lt;/li&gt;
          &lt;li&gt;With \(u_1, u_2, u_3, u_4 \ge 0\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate an instant dual-feasible point:&lt;/strong&gt; Pick \(u_1 = 1, u_2 = 0, u_3 = 0, u_4 = 0\).
    &lt;ul&gt;
      &lt;li&gt;Check feasibility: \(-2(0) + 0 - 0 = 0\) and \(1 + 0 = 1\). Valid!&lt;/li&gt;
      &lt;li&gt;Certified lower bound: \(d = -0 - 0 = 0 &amp;gt; -0.5\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why verifiers love the dual:&lt;/strong&gt; Even a suboptimal or early-stopped dual point yields a &lt;strong&gt;100% mathematically sound&lt;/strong&gt; lower bound (\(p^\star \ge d = 0 &amp;gt; -0.5\)), whereas an early-stopped primal point only gives an upper bound and can never certify safety!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-lp-duality&quot;&gt;Modern applications of LP duality&lt;/h1&gt;

&lt;p&gt;Chapter 10 derives the dual of a linear program, weak/strong duality, complementary slackness, and the max-flow / min-cut and matrix-game examples. This optional lesson shows four places where those &lt;em&gt;same&lt;/em&gt; certificates were used in CS and data-science systems from about 2022 to 2026.&lt;/p&gt;

&lt;p&gt;A primal LP \(\min\{c^\top x:Ax=b,\,Gx\le h\}\) and its dual still mean: every feasible dual pair \((u,v)\) is a &lt;strong&gt;lower bound&lt;/strong&gt;, and at optimality the bound is tight and unused inequalities have zero multipliers.&lt;/p&gt;

&lt;h2 id=&quot;1-neural-network-verification-as-an-lp-then-a-cut-lp&quot;&gt;1. Neural-network verification as an LP (then a cut LP)&lt;/h2&gt;

&lt;p&gt;Asking whether a classifier can change its label inside an \(\ell_\infty\) box is a nonconvex problem in the ReLU activations. The standard relaxation replaces each ReLU by a triangle / LP outer approximation (Ehlers; Wong and Kolter). Dual variables of that LP are &lt;strong&gt;bound-propagation multipliers&lt;/strong&gt;. Zhang, Wang, Xu, Li, Li, Jana, Hsieh, and Kolter (NeurIPS 2022) added &lt;strong&gt;general cutting planes&lt;/strong&gt; to that dual (GCP-CROWN) and folded it into &lt;strong&gt;\(\alpha,\beta\)-CROWN&lt;/strong&gt;, which won the International Verification of Neural Networks Competition in 2021, 2022, 2023, 2024, and 2025. The engineering is GPU bound-propagation; the certificate is still “the dual of a tightened LP is above zero, hence no adversarial example exists.”&lt;/p&gt;

&lt;p&gt;This is Chapter 10’s weak duality used as a &lt;strong&gt;safety proof&lt;/strong&gt;, not as a pricing story.&lt;/p&gt;

&lt;h2 id=&quot;2-electricity-markets-clearing-lps-and-shadow-prices&quot;&gt;2. Electricity markets: clearing LPs and shadow prices&lt;/h2&gt;

&lt;p&gt;Day-ahead energy markets clear a (mixed-integer) linear program: minimise offer cost subject to power-balance and line limits. The dual of the &lt;em&gt;linear&lt;/em&gt; relaxation is the vector of &lt;strong&gt;locational marginal prices&lt;/strong&gt; (LMPs). After the 2022 European price spike, that dual was no longer a textbook cartoon: it is the number on the invoice. Liang and Dvorkin (ACM e-Energy 2023) use inverse optimization on published schedules and LMPs to recover generators’ offer prices — they invert the KKT / dual map of the clearing LP. Related 2022–2023 work on European day-ahead auctions writes zonal prices explicitly as duals of network-constrained welfare LPs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Course link.&lt;/strong&gt; Complementary slackness says a congested line (\(Gx=h\)) is the only line that can carry a nonzero congestion price \(v\). That sentence is this chapter, applied to a grid.&lt;/p&gt;

&lt;h2 id=&quot;3-max-flow--min-cut-after-2022&quot;&gt;3. Max-flow / min-cut after 2022&lt;/h2&gt;

&lt;p&gt;The theorem in &lt;a href=&quot;/contents/en/chapter10/10_03_Max_flow_and_min_cut/&quot;&gt;10-03&lt;/a&gt; is still the dual pair behind image segmentation, closed-world community detection, and reliability cuts in communication networks. Modern large-scale solvers (Gurobi, HiGHS, OR-Tools) expose the dual as a first-class vector; a data-science workflow that “allocates bandwidth” or “cuts a graph into source/sink sets” is reading that vector. The &lt;em&gt;new&lt;/em&gt; CS use is often a &lt;strong&gt;learned&lt;/strong&gt; capacity (a GNN predicts edge weights) followed by a classical max-flow dual as a layer — the same pairing as differentiable optimization in Chapter 12, but the inner problem is an LP.&lt;/p&gt;

&lt;h2 id=&quot;4-optimal-transport-as-a-giant-lp&quot;&gt;4. Optimal transport as a giant LP&lt;/h2&gt;

&lt;p&gt;The Kantorovich problem&lt;/p&gt;

\[\min_{\pi\ge 0}\ \langle C,\pi\rangle\quad\text{s.t.}\quad \pi\mathbf{1}=a,\ \pi^\top\mathbf{1}=b\]

&lt;p&gt;is an LP. Its dual is \(\max_{f,g} f^\top a+g^\top b\) subject to \(f_i+g_j\le C_{ij}\) — the &lt;strong&gt;Kantorovich potentials&lt;/strong&gt;. Peyré and Cuturi (2019) is the computational monograph; 2022–2026 domain adaptation, dataset distillation, and single-cell alignment still solve a regularised (Sinkhorn) or unregularised version and read the dual as a soft matching. Weak duality is the statement that no coupling can cost less than any feasible pair of potentials.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;An LP dual is a &lt;strong&gt;certificate&lt;/strong&gt;: of infeasibility (verification), of a price (markets), of a cut (networks), or of a matching cost (transport). If you can write the primal and produce a feasible dual with equal objective, you are done — that is strong duality for LPs, and it is what those four applications compute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; In GCP-CROWN, why does &lt;em&gt;adding&lt;/em&gt; a cutting plane to the primal LP only &lt;em&gt;raise&lt;/em&gt; the dual lower bound? Which theorem of this chapter is that?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Zhang, H., Wang, S., Xu, K., Li, L., Li, B., Jana, S., Hsieh, C.-J., &amp;amp; Kolter, J. Z. (2022). General cutting planes for bound-propagation-based neural network verification. &lt;em&gt;NeurIPS&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2208.05740&quot;&gt;arXiv:2208.05740&lt;/a&gt;. Tool: &lt;a href=&quot;https://github.com/Verified-Intelligence/alpha-beta-CROWN&quot;&gt;α,β-CROWN&lt;/a&gt; (VNN-COMP 2021–2025 winner).&lt;/li&gt;
  &lt;li&gt;Liang, Z., &amp;amp; Dvorkin, Y. (2023). Data-driven inverse optimization for marginal offer price recovery in electricity markets. &lt;em&gt;ACM e-Energy ’23&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Peyré, G., &amp;amp; Cuturi, M. (2019). Computational optimal transport. &lt;em&gt;Foundations and Trends in Machine Learning&lt;/em&gt;, 11(5–6). (standard LP/dual reference still used in 2022–2026 OT pipelines)&lt;/li&gt;
  &lt;li&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;, Ch. 5 (LP duality and shadow prices).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-06 Modern applications of proximal GD and acceleration</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_06_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_06_modern_applications</id>
   <content type="html">&lt;p&gt;From reconstructing high-resolution MRI scans from undersampled k-space data in seconds, to training “unrolled” deep neural networks where every layer &lt;em&gt;is&lt;/em&gt; one FISTA iteration, proximal gradient descent and acceleration sit quietly at the center of 2022–2026 computational imaging and scientific ML. Rather than replacing classical optimization with opaque black-box networks, modern pipelines fuse both worlds—plugging learned denoisers directly into the proximal slot (Plug-and-Play FISTA) or learning step sizes and thresholds end-to-end (FISTA-Net).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-proximal-splitting-in-20222026-imaging--ml&quot;&gt;Key ideas: Proximal Splitting in 2022–2026 Imaging &amp;amp; ML&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Inverse Problems &amp;amp; Data Consistency:&lt;/strong&gt; In MRI/CT reconstruction, \(g(x) = \frac{1}{2}\|Ax - b\|_2^2\) encodes the exact known physics of the scanner (Fourier or Radon transform), while \(h(x)\) encodes prior structure (wavelet sparsity or total variation). Keeping \(g\) explicit guarantees physical fidelity.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Plug-and-Play (PnP) FISTA:&lt;/strong&gt; Because \(\operatorname{prox}_{t h}(y) = \arg\min_z \{\frac{1}{2t}\|z - y\|_2^2 + h(z)\}\) is mathematically a Gaussian denoiser at noise level \(\sigma = \sqrt{t}\), PnP-FISTA replaces \(\operatorname{prox}_{t h}\) with a pretrained deep denoiser \(D_\sigma\) while retaining FISTA’s momentum and physical gradient steps.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Algorithm Unrolling (LISTA / FISTA-Net):&lt;/strong&gt; Fixing the iteration count to \(K = 8\text{–}15\) layers and turning step sizes, thresholds, and linear filters into learnable parameters yields interpretable, physics-guided neural architectures that achieve FISTA-grade accuracy in \(10\times\) fewer iterations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Production Sparse GLMs &amp;amp; Low-Rank Solvers:&lt;/strong&gt; In statistical libraries (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FISTA&lt;/code&gt;-based solvers), proximal gradient with backtracking, active-set screening, and warm starts remains the gold standard for elastic-net regression and matrix completion.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-unrolled-fista-layer-vs-classical-ista-on-a-2-pixel-signal&quot;&gt;Worked example: One Unrolled FISTA Layer vs. Classical ISTA on a 2-Pixel Signal&lt;/h3&gt;

&lt;p&gt;Suppose a 2-pixel compressed-sensing measurement obeys \(A = \begin{pmatrix}1 &amp;amp; 0 \\ 0 &amp;amp; 2\end{pmatrix}\), \(b = \begin{pmatrix}2 \\ 6\end{pmatrix}\), so \(g(x) = \frac{1}{2}\|Ax - b\|_2^2\) has \(\nabla g(x) = A^\top(Ax - b) = \begin{pmatrix}x_1 - 2 \\ 4x_2 - 12\end{pmatrix}\) and Lipschitz constant \(L = \|A\|_2^2 = 4\). With \(\lambda = 1\) and \(x^{(0)} = (0, 0)^\top\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Classical ISTA layer with safe step size \(t = 1/L = 0.25\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient at \(x^{(0)} = (0, 0)^\top\): \(\nabla g(0) = (-2, -12)^\top\).&lt;/li&gt;
      &lt;li&gt;Proposal: \(u = (0, 0)^\top - 0.25(-2, -12)^\top = (0.5, 3.0)^\top\).&lt;/li&gt;
      &lt;li&gt;Soft-threshold by \(\lambda t = 1 \cdot 0.25 = 0.25\):
\(x^{(1)}_{\text{ISTA}} = (0.5 - 0.25,\; 3.0 - 0.25)^\top = (0.25,\; 2.75)^\top.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with the exact Lasso optimum \(x^\star\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Coordinate 1 solves \(x_1 - 2 + 1 = 0 \implies x_1^\star = 1.0\).&lt;/li&gt;
      &lt;li&gt;Coordinate 2 solves \(4x_2 - 12 + 1 = 0 \implies x_2^\star = 2.75\).&lt;/li&gt;
      &lt;li&gt;Notice that \(x_2\) converged in &lt;em&gt;one&lt;/em&gt; step because \(t = 1/4\) matched its curvature \(4\), whereas \(x_1\) moved only 25% of the way because its curvature was \(1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why an unrolled layer (e.g., FISTA-Net) converges faster:&lt;/strong&gt; Allowing a learned per-layer diagonal step size \(T = \operatorname{diag}(1.0, 0.25)\) and threshold \(\theta = (1.0, 0.25)\) produces \(u_{\text{unrolled}} = (2.0, 3.0)^\top \implies x^{(1)}_{\text{unrolled}} = (1.0, 2.75)^\top = x^\star\) in a single layer—showing concretely why algorithm unrolling compresses hundreds of iterations into a tiny physics-informed network!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-proximal-gd-and-acceleration&quot;&gt;Modern applications of proximal GD and acceleration&lt;/h1&gt;

&lt;p&gt;Chapter 09 studies composite problems \(\min_x g(x)+h(x)\) with \(g\) smooth and \(h\) prox-friendly, the proximal-gradient iteration, and Nesterov / FISTA acceleration. This optional lesson stays on that template and shows where it ran in imaging, sparse GLMs, and &lt;em&gt;unrolled&lt;/em&gt; networks from 2022 to 2026.&lt;/p&gt;

&lt;p&gt;Recall the FISTA pair already in &lt;a href=&quot;/contents/en/chapter09/09_05_03_example_FISTA/&quot;&gt;09-05-03&lt;/a&gt;:&lt;/p&gt;

\[y^{k}=x^{k-1}+\frac{t_{k-1}-1}{t_k}(x^{k-1}-x^{k-2}),\qquad
x^{k}=\operatorname{prox}_{t_k h}\bigl(y^{k}-t_k\nabla g(y^{k})\bigr).\]

&lt;p&gt;When \(h=\lambda\|\cdot\|_1\) the prox is soft-thresholding — the same map as Chapter 07.&lt;/p&gt;

&lt;h2 id=&quot;1-mri--ct-reconstruction-fista-then-pnp-fista&quot;&gt;1. MRI / CT reconstruction: FISTA, then PnP-FISTA&lt;/h2&gt;

&lt;p&gt;Compressed-sensing MRI and sparse-view CT are composite least-squares plus a sparsity or total-variation regulariser. Classical FISTA (Beck and Teboulle, 2009) is still the CPU/GPU baseline in hospital research code. The 2023 IEEE SPM tutorial of Kamilov, Bouman, Buzzard, and Wohlberg explains why labs then &lt;strong&gt;replace the prox of \(h\) by a learned denoiser&lt;/strong&gt; and keep the gradient step of \(g\) (the physical forward model). That hybrid is &lt;strong&gt;plug-and-play (PnP)&lt;/strong&gt;; their Algorithm 4 is literally &lt;strong&gt;PnP-FISTA&lt;/strong&gt;. Applications they survey include bio-microscopy, CT, MRI, and ptycho-tomography.&lt;/p&gt;

&lt;p&gt;The data-fidelity piece is the smooth \(g\) of this chapter; the denoiser plays the role of \(\operatorname{prox}_{t h}\). You should be able to write the iteration before you discuss the neural net.&lt;/p&gt;

&lt;h2 id=&quot;2-algorithm-unrolling-fista-net-and-pfista-dr&quot;&gt;2. Algorithm unrolling: FISTA-Net and pFISTA-DR&lt;/h2&gt;

&lt;p&gt;Unrolling (Monga, Li, and Eldar, 2021) turns a fixed number of proximal-gradient / FISTA steps into a neural architecture whose step sizes, thresholds, and even the prox are trained. Xiang, Dong, and Yang (2021) published &lt;strong&gt;FISTA-Net&lt;/strong&gt; in &lt;em&gt;IEEE TMI&lt;/em&gt;: cascade of gradient, proximal, and momentum modules, evaluated on electromagnetic tomography and X-ray CT. Qu, Zhang, Kang, Lin, Lin, She, Wu, Wang, and Zheng (2024) unrolled &lt;strong&gt;projected FISTA&lt;/strong&gt; for radial MRI (&lt;strong&gt;pFISTA-DR&lt;/strong&gt;) and reported reconstruction dropping from about 48 s/slice to 0.55 s/slice on clinical data. Zhang, Chen, Xiong, and Zhang (2023) survey the same idea as &lt;em&gt;physics-inspired compressive sensing&lt;/em&gt;: the ISTA/FISTA skeleton stays, the linear maps become learned.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Course link.&lt;/strong&gt; If you cannot write FISTA on paper, an unrolled net is just another black box. The point of this chapter is that the skip / momentum connection &lt;em&gt;is&lt;/em&gt; Nesterov’s \(t_k\) sequence.&lt;/p&gt;

&lt;h2 id=&quot;3-elastic-net-and-matrix-completion-in-production-solvers&quot;&gt;3. Elastic net and matrix completion in production solvers&lt;/h2&gt;

&lt;p&gt;The elastic net \(\tfrac12\|X\beta-y\|_2^2+\lambda\bigl(\alpha\|\beta\|_1+(1-\alpha)\tfrac12\|\beta\|_2^2\bigr)\) is proximal gradient (or coordinate descent on a quadratic-plus-\(\ell_1\)) with a &lt;strong&gt;ridge-adjusted soft-threshold&lt;/strong&gt;. Tay, Narasimhan, and Hastie (2023) made that path the default for every GLM family in glmnet — genomics, click prediction, and Cox models included. The matrix-completion example of &lt;a href=&quot;/contents/en/chapter09/09_03_example_matrix_completion/&quot;&gt;09-03&lt;/a&gt; is the same composite pattern (smooth data term + nuclear-norm prox = singular-value thresholding) that still sits under recommender and single-cell imputation pipelines.&lt;/p&gt;

&lt;p&gt;ISTA / FISTA are not always the fastest &lt;em&gt;CPU&lt;/em&gt; method for Lasso (coordinate descent plus screening usually wins; see Chapter 13), but they are the methods you can &lt;strong&gt;GPU-batch, unroll, or swap the prox of&lt;/strong&gt;. That is why imaging and differentiable programming standardised on them.&lt;/p&gt;

&lt;h2 id=&quot;4-a-tiny-ista-step&quot;&gt;4. A tiny ISTA step&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;soft_threshold&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;maximum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ista_step&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# t &amp;lt; 1 / ||A||^2 for the quadratic g(x) = 0.5 ||Ax - b||^2
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;soft_threshold&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;FISTA only changes the &lt;em&gt;point&lt;/em&gt; at which you evaluate \(\nabla g\), using the momentum of Section 09-05. PnP-FISTA changes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;soft_threshold&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;denoiser&lt;/code&gt;. FISTA-Net makes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t&lt;/code&gt; and the denoiser learnable.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;Composite structure (smooth likelihood + prox-friendly regulariser) is why proximal gradient exists. Acceleration is a \(t_k\) schedule, not a different model. From 2022 to 2026 the same schedule is (i) a solver, (ii) a plug-and-play wrapper around a CNN denoiser, and (iii) a neural net obtained by unrolling ten to forty steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; When would you keep a true prox (soft-threshold, SVT) instead of replacing it by a learned denoiser — and what does Chapter 09’s theory still guarantee in the PnP case?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Beck, A., &amp;amp; Teboulle, M. (2009). A fast iterative shrinkage-thresholding algorithm for linear inverse problems. &lt;em&gt;SIAM J. Imaging Sciences&lt;/em&gt;, 2(1), 183–202. (classical FISTA)&lt;/li&gt;
  &lt;li&gt;Kamilov, U. S., Bouman, C. A., Buzzard, G. T., &amp;amp; Wohlberg, B. (2023). Plug-and-play methods for integrating physical and learned models in computational imaging. &lt;em&gt;IEEE Signal Processing Magazine&lt;/em&gt;, 40(1), 85–97.&lt;/li&gt;
  &lt;li&gt;Monga, V., Li, Y., &amp;amp; Eldar, Y. C. (2021). Algorithm unrolling: Interpretable, efficient deep learning for signal and image processing. &lt;em&gt;IEEE Signal Processing Magazine&lt;/em&gt;, 38(2), 18–44.&lt;/li&gt;
  &lt;li&gt;Xiang, J., Dong, Y., &amp;amp; Yang, Y. (2021). FISTA-Net: Learning a fast iterative shrinkage thresholding network for inverse problems in imaging. &lt;em&gt;IEEE Transactions on Medical Imaging&lt;/em&gt;, 40(5), 1329–1339.&lt;/li&gt;
  &lt;li&gt;Qu, B., Zhang, J., Kang, T., Lin, J., Lin, M., She, H., Wu, Q., Wang, M., &amp;amp; Zheng, G. (2024). Radial magnetic resonance image reconstruction with a deep unrolled projected fast iterative soft-thresholding network. &lt;em&gt;Computers in Biology and Medicine&lt;/em&gt;, 168, 107707.&lt;/li&gt;
  &lt;li&gt;Zhang, J., Chen, B., Xiong, R., &amp;amp; Zhang, Y. (2023). Physics-inspired compressive sensing: Beyond deep unrolling. &lt;em&gt;IEEE Signal Processing Magazine&lt;/em&gt;, 40(1), 58–72.&lt;/li&gt;
  &lt;li&gt;Tay, J. K., Narasimhan, B., &amp;amp; Hastie, T. (2023). Elastic net regularization paths for all generalized linear models. &lt;em&gt;Journal of Statistical Software&lt;/em&gt;, 106(1).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-12 Modern applications of the subgradient method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_12_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_12_modern_applications</id>
   <content type="html">&lt;p&gt;In production machine learning between 2022 and 2026, theoretical elegance only survives if it fits inside a fast, GPU-friendly inner loop. That is precisely why the projected and stochastic subgradient methods of Chapter 08 have never gone out of style: from crafting worst-case adversarial perturbations in RobustBench to balancing fairness constraints via dual subgradient updates in Fairlearn, modern ML systems rely daily on cheap nonsmooth steps coupled with closed-form projections.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-bridging-classical-subgradient-theory-to-modern-ml-systems&quot;&gt;Key ideas: Bridging Classical Subgradient Theory to Modern ML Systems&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Subgradients Inside Autograd:&lt;/strong&gt; ReLU activations, Huber/hinge losses, and quantile regressors are piecewise smooth; automatic differentiation returns a valid subgradient (more generally, a conservative-field element) at kinks in \(O(1)\) extra overhead.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Projection-Friendly Threat &amp;amp; Policy Sets:&lt;/strong&gt; Constraining perturbations to \(\ell_\infty\) boxes (clipping) or \(\ell_2\) balls (radial rescaling), and constraining dual fairness weights to the probability simplex or nonnegative orthant, makes projected subgradient iterations trivial to vectorize.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Dual Subgradient Updates for Fairness Constraints:&lt;/strong&gt; When a model must satisfy group error-rate disparities \(g_j(\theta) \le \tau_j\), the dual multiplier update \(\lambda^{(k+1)} = \max(0, \lambda^{(k)} + \eta_k (g(\theta^{(k)}) - \tau))\) is literally projected subgradient ascent on the concave Lagrangian dual.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Coarse-Accuracy Sweet Spot:&lt;/strong&gt; Because generalization error and finite-sample noise cap useful optimization precision in ML, the \(O(1/\varepsilon^2)\) iteration rate is easily outweighed by minimal memory footprint and trivial parallelization.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-dual-projected-subgradient-step-for-a-fairness-constraint&quot;&gt;Worked example: One Dual Projected Subgradient Step for a Fairness Constraint&lt;/h3&gt;

&lt;p&gt;Suppose a classifier must keep the false-negative-rate gap between two demographic groups below \(\tau = 0.05\): \(g(\theta) - 0.05 \le 0\). We maintain a nonnegative Lagrange multiplier \(\lambda \ge 0\) updated via projected subgradient ascent \(\lambda^{(k+1)} = \max(0,\; \lambda^{(k)} + \eta (g(\theta^{(k)}) - \tau))\) with step size \(\eta = 2.0\) and initial multiplier \(\lambda^{(0)} = 0.20\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Round 1 — Constraint violated:&lt;/strong&gt; Suppose the current classifier \(\theta^{(0)}\) has disparity \(g(\theta^{(0)}) = 0.12 &amp;gt; 0.05\).
    &lt;ul&gt;
      &lt;li&gt;Constraint violation (dual subgradient): \(s^{(0)} = 0.12 - 0.05 = +0.07\).&lt;/li&gt;
      &lt;li&gt;Update and project onto \(\lambda \ge 0\):
\(\lambda^{(1)} = \max(0,\; 0.20 + 2.0(0.07)) = \max(0,\; 0.34) = 0.34.\)&lt;/li&gt;
      &lt;li&gt;Raising \(\lambda\) from \(0.20\) to \(0.34\) increases the penalty on the disadvantaged group’s errors in the next learner round.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Round 2 — Constraint over-satisfied:&lt;/strong&gt; Suppose the reweighted classifier \(\theta^{(1)}\) achieves \(g(\theta^{(1)}) = 0.01 &amp;lt; 0.05\).
    &lt;ul&gt;
      &lt;li&gt;Dual subgradient: \(s^{(1)} = 0.01 - 0.05 = -0.04\).&lt;/li&gt;
      &lt;li&gt;Update and project onto \(\lambda \ge 0\):
\(\lambda^{(2)} = \max(0,\; 0.34 + 2.0(-0.04)) = \max(0,\; 0.26) = 0.26.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Insight:&lt;/strong&gt; This two-line projected subgradient update automatically tightens the fairness penalty when the threshold is violated and relaxes it when the model has headroom—connecting Chapter 08 directly to the Lagrangian duality of Chapter 11.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-the-subgradient-method&quot;&gt;Modern applications of the subgradient method&lt;/h1&gt;

&lt;p&gt;Chapter 08 analyses the iteration \(x^{k+1}=x^k-\alpha_k g^k\) with \(g^k\in\partial f(x^k)\), its projected cousin, and the stochastic variant. This optional lesson maps those three templates onto pipelines that were standard or newly standardised between about 2022 and 2026. We do not re-prove the \(O(1/\varepsilon^2)\) rate; we show why a practitioner still runs a (projected, stochastic) subgradient step.&lt;/p&gt;

&lt;h2 id=&quot;1-nonsmooth-empirical-risk-hinge-huber-and-relu-training&quot;&gt;1. Nonsmooth empirical risk: hinge, Huber, and ReLU training&lt;/h2&gt;

&lt;p&gt;Regularised logistic regression in &lt;a href=&quot;/contents/en/chapter08/08_01_05_example_regularized_logistic_regression/&quot;&gt;08-01-05&lt;/a&gt; is already a subgradient-method example. The same loop trains a linear SVM (hinge), a robust regressor (Huber / quantile), or the last layer of a frozen encoder. For a full ReLU net the loss is no longer convex, but the &lt;em&gt;implemented&lt;/em&gt; backward pass is still a conservative selection of a subgradient (Bolte and Pauwels, 2021). Their convergence-in-values result is precisely a justification of &lt;strong&gt;stochastic subgradient descent as libraries run it&lt;/strong&gt;, not of an idealised Clarke-critical-point oracle.&lt;/p&gt;

&lt;p&gt;On convex finite-sum problems the picture is kinder: diminishing or Polyak steps from this chapter remain the textbook guarantee, and 2022–2024 work on adaptive / parameter-free steps (DoG, Polyak restarts) is a direct descendant of &lt;a href=&quot;/contents/en/chapter08/08_01_06_polyak_step_sizes/&quot;&gt;08-01-06 Polyak step sizes&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;2-projected-pgd-and-adversarial-ell_p-training&quot;&gt;2. Projected PGD and adversarial \(\ell_p\) training&lt;/h2&gt;

&lt;p&gt;Madry-style adversarial training solves, at each minibatch, a constrained inner problem&lt;/p&gt;

\[\max_{\|\delta\|_p\le\varepsilon}\ \ell\bigl(h_w(x+\delta),y\bigr)\]

&lt;p&gt;by &lt;strong&gt;projected gradient / subgradient ascent&lt;/strong&gt; on \(\delta\) and a descent step on \(w\). The projection onto the \(\ell_\infty\) or \(\ell_2\) ball is the operator in &lt;a href=&quot;/contents/en/chapter08/08_01_08_projected_subgradient_method/&quot;&gt;08-01-08 Projected subgradient&lt;/a&gt;. Croce and Hein (2020) showed that a poorly tuned inner PGD &lt;em&gt;overestimates&lt;/em&gt; robustness; their parameter-free ensemble &lt;strong&gt;AutoAttack&lt;/strong&gt; (APGD + FAB + Square) became the default test. Croce et al. (2021) packaged that test as &lt;strong&gt;RobustBench&lt;/strong&gt;, which is still the public leaderboard for \(\ell_\infty\) and \(\ell_2\) robustness through 2025. The dual-norm story (the support function of the attack ball) is Chapter 13; the &lt;em&gt;algorithm&lt;/em&gt; is this chapter’s projected method.&lt;/p&gt;

&lt;h2 id=&quot;3-fairness-and-other-rate-constraints&quot;&gt;3. Fairness and other rate constraints&lt;/h2&gt;

&lt;p&gt;Many production constraints are &lt;strong&gt;nonsmooth rates&lt;/strong&gt;: demographic parity, equalised odds, recall floors, churn caps. They look like \(\mathbb{P}(\hat y=1\mid A=a)\le \alpha\) — indicator averages, hence piecewise constant. Cotter, Jiang, Gupta, and co-authors (JMLR 2019) introduced a &lt;strong&gt;proxy-Lagrangian&lt;/strong&gt; two-player game: one player takes gradient steps on a smooth surrogate, the other enforces the original rate by a (sub)gradient method on multipliers. Agarwal, Beygelzimer, Dudík, Langford, and Wallach (2018) reduce fair classification to a sequence of cost-sensitive problems; the &lt;strong&gt;Fairlearn&lt;/strong&gt; library (Weerts, Dudík, Edgar, Jalali, Lutz, and Madaio, 2023, &lt;em&gt;JMLR&lt;/em&gt;) ships that reduction as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExponentiatedGradient&lt;/code&gt; and is what a 2024–2026 sklearn stack actually calls.&lt;/p&gt;

&lt;p&gt;The inner weighted ERM is often solved by a subgradient or SGD step on a hinge or logistic loss. The outer multiplier update is a subgradient step on a constraint residual. That is the algorithm of this chapter, twice.&lt;/p&gt;

&lt;h2 id=&quot;4-mini-example-projected-step-on-an-ell_infty-ball&quot;&gt;4. Mini-example: projected step on an \(\ell_\infty\) ball&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;proj_linf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;clip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;pgd_inner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros_like&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;proj_linf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; by a minibatch gradient of the loss and you have the inner loop of adversarial training. Replace the ball by a probability simplex or a fairness polytope and you have the projected method of Section 08-01-08.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;If the objective or the constraint is a max, an \(\ell_1\), a hinge, or an empirical rate, first-order training &lt;em&gt;is&lt;/em&gt; a subgradient method (possibly projected, possibly stochastic). Acceleration and prox maps (Chapter 09) are upgrades you earn after the composite structure is visible; they do not replace this loop on a raw rate constraint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; Why is a constant step size theoretically uncomfortable for a nonsmooth convex rate constraint, and why do fairness reductions still use one in practice?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bolte, J., &amp;amp; Pauwels, E. (2021). Conservative set valued fields, automatic differentiation, stochastic gradient methods and deep learning. &lt;em&gt;Mathematical Programming&lt;/em&gt;, 188, 19–51.&lt;/li&gt;
  &lt;li&gt;Croce, F., &amp;amp; Hein, M. (2020). Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks. &lt;em&gt;ICML&lt;/em&gt;, PMLR 119.&lt;/li&gt;
  &lt;li&gt;Croce, F., Andriushchenko, M., Sehwag, V., Debenedetti, E., Flammarion, N., Chiang, M., Mittal, P., &amp;amp; Hein, M. (2021). RobustBench: A standardized adversarial robustness benchmark. &lt;em&gt;NeurIPS Datasets and Benchmarks&lt;/em&gt;. Leaderboard: &lt;a href=&quot;https://robustbench.github.io/&quot;&gt;robustbench.github.io&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Cotter, A., Jiang, H., Gupta, M., Wang, S., Narayan, T., You, S., &amp;amp; Sridharan, K. (2019). Optimization with non-differentiable constraints with applications to fairness, recall, churn, and other goals. &lt;em&gt;JMLR&lt;/em&gt;, 20(172).&lt;/li&gt;
  &lt;li&gt;Agarwal, A., Beygelzimer, A., Dudík, M., Langford, J., &amp;amp; Wallach, H. (2018). A reductions approach to fair classification. &lt;em&gt;ICML&lt;/em&gt;, PMLR 80.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257). &lt;a href=&quot;https://fairlearn.org&quot;&gt;https://fairlearn.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-09 Modern applications of the subgradient method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_09_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_09_modern_applications</id>
   <content type="html">&lt;p&gt;If you thought the subgradient method was a 1970s relic replaced by Adam and second-order solvers, look inside today’s adversarial robustness benchmarks, algorithmic fairness pipelines, and nonsmooth empirical risk trainers: the exact projected stochastic subgradient loop from Chapter 08 is running at their core. Whenever an engineer crafts an \(\ell_\infty\) adversarial perturbation or enforces a demographic parity constraint on a black-box classifier, the workhorse iteration is still \(x^{(k+1)} = P_C(x^{(k)} - \alpha_k g^{(k)})\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-subgradient-loops-power-20222026-ml-pipelines&quot;&gt;Key ideas: Why Subgradient Loops Power 2022–2026 ML Pipelines&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Nonsmooth Empirical Risk &amp;amp; Conservative Fields:&lt;/strong&gt; Hinge losses, quantile (pinball) losses, and ReLU networks are non-differentiable on sets of measure zero, yet autograd engines (PyTorch/JAX) routinely return a single conservative-field / subgradient element and step along it with stochastic schedules.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Projected PGD on \(\ell_p\) Threat Balls:&lt;/strong&gt; Adversarial training solves a min-max saddle problem whose inner maximization projects subgradient (or signed-gradient) steps onto an \(\ell_\infty\) box or \(\ell_2\) ball—literally projected subgradient ascent on the perturbation \(\delta\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Lagrangian Fairness &amp;amp; Rate Constraints:&lt;/strong&gt; Enforcing group-fairness bounds (such as equalized odds in Fairlearn) introduces Lagrange multipliers \(\lambda \ge 0\) updated via projected exponentiated/subgradient ascent while the learner minimizes the reweighted classification loss.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Precision Regime Fit:&lt;/strong&gt; In adversarial attacks (7–40 PGD steps) and statistical learning (where generalization error dominates optimization error below \(\varepsilon \sim 10^{-2}\)), the \(O(1/\varepsilon^2)\) rate is not a liability—cheap per-step cost and simple projections are what matter most.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-two-projected-subgradient-steps-for-an-ell_infty-adversarial-perturbation&quot;&gt;Worked example: Two Projected Subgradient Steps for an \(\ell_\infty\) Adversarial Perturbation&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Suppose a linear classifier has score \(s(\delta) = w^\top (x_0 + \delta)\) with \(w = (3, -1)^\top\), and an adversary wants to maximize $$L(\delta) =&lt;/td&gt;
      &lt;td&gt;w^\top \delta&lt;/td&gt;
      &lt;td&gt;\((equivalently minimize\)-L(\delta)\() inside the\)\ell_\infty\(threat ball\)C = { \delta \in \mathbb{R}^2 : |\delta|_\infty \le 0.3 }\(, starting from\)\delta^{(0)} = (0.1, 0.1)^\top\(with step size\)\alpha = 0.2$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 at \(\delta^{(0)} = (0.1, 0.1)^\top\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Compute \(w^\top \delta^{(0)} = 3(0.1) - 1(0.1) = 0.2 &amp;gt; 0\), so \(L(\delta^{(0)}) = 0.2\).&lt;/li&gt;
      &lt;li&gt;Subgradient of \(L\) is \(g^{(0)} = \operatorname{sign}(0.2)\, w = (3, -1)^\top\).&lt;/li&gt;
      &lt;li&gt;Unconstrained ascent step: \(\tilde{\delta}^{(1)} = (0.1, 0.1) + 0.2(3, -1) = (0.7, -0.1)\).&lt;/li&gt;
      &lt;li&gt;Project onto \(C = [-0.3, 0.3]^2\) (coordinatewise clip):
\(\delta^{(1)} = (\operatorname{clip}(0.7, -0.3, 0.3),\; \operatorname{clip}(-0.1, -0.3, 0.3)) = (0.3, -0.1).\)&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;New objective: $$L(\delta^{(1)}) =&lt;/td&gt;
              &lt;td&gt;3(0.3) - (-0.1)&lt;/td&gt;
              &lt;td&gt;= 1.0$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2 at \(\delta^{(1)} = (0.3, -0.1)^\top\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Since \(w^\top \delta^{(1)} = 1.0 &amp;gt; 0\), \(g^{(1)} = (3, -1)^\top\).&lt;/li&gt;
      &lt;li&gt;Unconstrained ascent step: \(\tilde{\delta}^{(2)} = (0.3, -0.1) + 0.2(3, -1) = (0.9, -0.3)\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Project onto \([-0.3, 0.3]^2\): \(\delta^{(2)} = (0.3, -0.3)\), achieving $$L(\delta^{(2)}) =&lt;/td&gt;
              &lt;td&gt;0.9 + 0.3&lt;/td&gt;
              &lt;td&gt;= 1.2\(—the exact maximum over the\)\ell_\infty$$ ball!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-the-subgradient-method&quot;&gt;Modern applications of the subgradient method&lt;/h1&gt;

&lt;p&gt;Chapter 08 analyses the iteration \(x^{k+1}=x^k-\alpha_k g^k\) with \(g^k\in\partial f(x^k)\), its projected cousin, and the stochastic variant. This optional lesson maps those three templates onto pipelines that were standard or newly standardised between about 2022 and 2026. We do not re-prove the \(O(1/\varepsilon^2)\) rate; we show why a practitioner still runs a (projected, stochastic) subgradient step.&lt;/p&gt;

&lt;h2 id=&quot;1-nonsmooth-empirical-risk-hinge-huber-and-relu-training&quot;&gt;1. Nonsmooth empirical risk: hinge, Huber, and ReLU training&lt;/h2&gt;

&lt;p&gt;Regularised logistic regression in &lt;a href=&quot;/contents/en/chapter08/08_01_05_example_regularized_logistic_regression/&quot;&gt;08-01-05&lt;/a&gt; is already a subgradient-method example. The same loop trains a linear SVM (hinge), a robust regressor (Huber / quantile), or the last layer of a frozen encoder. For a full ReLU net the loss is no longer convex, but the &lt;em&gt;implemented&lt;/em&gt; backward pass is still a conservative selection of a subgradient (Bolte and Pauwels, 2021). Their convergence-in-values result is precisely a justification of &lt;strong&gt;stochastic subgradient descent as libraries run it&lt;/strong&gt;, not of an idealised Clarke-critical-point oracle.&lt;/p&gt;

&lt;p&gt;On convex finite-sum problems the picture is kinder: diminishing or Polyak steps from this chapter remain the textbook guarantee, and 2022–2024 work on adaptive / parameter-free steps (DoG, Polyak restarts) is a direct descendant of &lt;a href=&quot;/contents/en/chapter08/08_01_06_polyak_step_sizes/&quot;&gt;08-01-06 Polyak step sizes&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;2-projected-pgd-and-adversarial-ell_p-training&quot;&gt;2. Projected PGD and adversarial \(\ell_p\) training&lt;/h2&gt;

&lt;p&gt;Madry-style adversarial training solves, at each minibatch, a constrained inner problem&lt;/p&gt;

\[\max_{\|\delta\|_p\le\varepsilon}\ \ell\bigl(h_w(x+\delta),y\bigr)\]

&lt;p&gt;by &lt;strong&gt;projected gradient / subgradient ascent&lt;/strong&gt; on \(\delta\) and a descent step on \(w\). The projection onto the \(\ell_\infty\) or \(\ell_2\) ball is the operator in &lt;a href=&quot;/contents/en/chapter08/08_01_08_projected_subgradient_method/&quot;&gt;08-01-08 Projected subgradient&lt;/a&gt;. Croce and Hein (2020) showed that a poorly tuned inner PGD &lt;em&gt;overestimates&lt;/em&gt; robustness; their parameter-free ensemble &lt;strong&gt;AutoAttack&lt;/strong&gt; (APGD + FAB + Square) became the default test. Croce et al. (2021) packaged that test as &lt;strong&gt;RobustBench&lt;/strong&gt;, which is still the public leaderboard for \(\ell_\infty\) and \(\ell_2\) robustness through 2025. The dual-norm story (the support function of the attack ball) is Chapter 13; the &lt;em&gt;algorithm&lt;/em&gt; is this chapter’s projected method.&lt;/p&gt;

&lt;h2 id=&quot;3-fairness-and-other-rate-constraints&quot;&gt;3. Fairness and other rate constraints&lt;/h2&gt;

&lt;p&gt;Many production constraints are &lt;strong&gt;nonsmooth rates&lt;/strong&gt;: demographic parity, equalised odds, recall floors, churn caps. They look like \(\mathbb{P}(\hat y=1\mid A=a)\le \alpha\) — indicator averages, hence piecewise constant. Cotter, Jiang, Gupta, and co-authors (JMLR 2019) introduced a &lt;strong&gt;proxy-Lagrangian&lt;/strong&gt; two-player game: one player takes gradient steps on a smooth surrogate, the other enforces the original rate by a (sub)gradient method on multipliers. Agarwal, Beygelzimer, Dudík, Langford, and Wallach (2018) reduce fair classification to a sequence of cost-sensitive problems; the &lt;strong&gt;Fairlearn&lt;/strong&gt; library (Weerts, Dudík, Edgar, Jalali, Lutz, and Madaio, 2023, &lt;em&gt;JMLR&lt;/em&gt;) ships that reduction as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExponentiatedGradient&lt;/code&gt; and is what a 2024–2026 sklearn stack actually calls.&lt;/p&gt;

&lt;p&gt;The inner weighted ERM is often solved by a subgradient or SGD step on a hinge or logistic loss. The outer multiplier update is a subgradient step on a constraint residual. That is the algorithm of this chapter, twice.&lt;/p&gt;

&lt;h2 id=&quot;4-mini-example-projected-step-on-an-ell_infty-ball&quot;&gt;4. Mini-example: projected step on an \(\ell_\infty\) ball&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;proj_linf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;clip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;pgd_inner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros_like&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;proj_linf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;delta&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; by a minibatch gradient of the loss and you have the inner loop of adversarial training. Replace the ball by a probability simplex or a fairness polytope and you have the projected method of Section 08-01-08.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;If the objective or the constraint is a max, an \(\ell_1\), a hinge, or an empirical rate, first-order training &lt;em&gt;is&lt;/em&gt; a subgradient method (possibly projected, possibly stochastic). Acceleration and prox maps (Chapter 09) are upgrades you earn after the composite structure is visible; they do not replace this loop on a raw rate constraint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; Why is a constant step size theoretically uncomfortable for a nonsmooth convex rate constraint, and why do fairness reductions still use one in practice?&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bolte, J., &amp;amp; Pauwels, E. (2021). Conservative set valued fields, automatic differentiation, stochastic gradient methods and deep learning. &lt;em&gt;Mathematical Programming&lt;/em&gt;, 188, 19–51.&lt;/li&gt;
  &lt;li&gt;Croce, F., &amp;amp; Hein, M. (2020). Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks. &lt;em&gt;ICML&lt;/em&gt;, PMLR 119.&lt;/li&gt;
  &lt;li&gt;Croce, F., Andriushchenko, M., Sehwag, V., Debenedetti, E., Flammarion, N., Chiang, M., Mittal, P., &amp;amp; Hein, M. (2021). RobustBench: A standardized adversarial robustness benchmark. &lt;em&gt;NeurIPS Datasets and Benchmarks&lt;/em&gt;. Leaderboard: &lt;a href=&quot;https://robustbench.github.io/&quot;&gt;robustbench.github.io&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Cotter, A., Jiang, H., Gupta, M., Wang, S., Narayan, T., You, S., &amp;amp; Sridharan, K. (2019). Optimization with non-differentiable constraints with applications to fairness, recall, churn, and other goals. &lt;em&gt;JMLR&lt;/em&gt;, 20(172).&lt;/li&gt;
  &lt;li&gt;Agarwal, A., Beygelzimer, A., Dudík, M., Langford, J., &amp;amp; Wallach, H. (2018). A reductions approach to fair classification. &lt;em&gt;ICML&lt;/em&gt;, PMLR 80.&lt;/li&gt;
  &lt;li&gt;Weerts, H., Dudík, M., Edgar, R., Jalali, A., Lutz, R., &amp;amp; Madaio, M. (2023). Fairlearn: Assessing and improving fairness of AI systems. &lt;em&gt;JMLR&lt;/em&gt;, 24(257). &lt;a href=&quot;https://fairlearn.org&quot;&gt;https://fairlearn.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-11 Modern applications of the subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_11_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_11_modern_applications</id>
   <content type="html">&lt;p&gt;Every time a modern ML pipeline trains a ReLU transformer, computes an adversarial perturbation, or enforces structured sparsity via nuclear or \(\ell_1\) norms, it steps directly onto points where ordinary gradients do not exist. This companion lesson traces how Chapter 07’s core objects—subgradients, subdifferentials \(\partial f(x)\), and stationarity \(0 \in \partial f(x^\star)\)—reappear across 2022–2026 deep learning, automatic differentiation, and large-scale optimization.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-subgradient-theory-in-modern-computing-20222026&quot;&gt;Key ideas: Subgradient Theory in Modern Computing (2022–2026)&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nonsmooth Autograd &amp;amp; Path Differentiability&lt;/strong&gt;: Reverse-mode AD on piecewise-smooth networks (ReLU, LeakyReLU, MaxPool, Huber, \(\ell_1\)) computes a &lt;em&gt;selection&lt;/em&gt; from a conservative field. Understanding why the chain rule holds &lt;em&gt;as an inclusion&lt;/em&gt; (\(\partial^C(f \circ g) \subseteq \dots\)) rather than strict equality explains edge-case gradient discrepancies at zero activations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adversarial &amp;amp; Distributionally Robust Optimization (Danskin’s Theorem)&lt;/strong&gt;: Minimizing a worst-case loss \(\phi(w) = \max_{\delta \in \Delta} \ell(w, \delta)\) is an infinite-index pointwise maximum. Subgradient calculus guarantees that \(\nabla_w \ell(w, \delta^\star) \in \partial \phi(w)\) whenever \(\delta^\star\) attains the inner maximum—justifying PGD adversarial training.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nuclear-Norm &amp;amp; Group-Sparsity Subdifferentials&lt;/strong&gt;: Lifting the \(\ell_1\) subdifferential from vectors to singular values of a matrix \(W = U\Sigma V^T\) yields \(\partial \|W\|_* = \{UV^T + M : U^T M = 0,\; MV = 0,\; \|M\|_2 \le 1\}\), which drives matrix completion and low-rank regularization.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Subgradient vs. Proximal Methods in Practice&lt;/strong&gt;: Pure subgradient descent on nonsmooth objectives converges slowly at \(O(1/\sqrt{k})\) and is non-monotone; modern solvers instead isolate the nonsmooth term inside a closed-form &lt;em&gt;proximal operator&lt;/em&gt; (like soft-thresholding), recovering fast \(O(1/k)\) or \(O(1/k^2)\) rates.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-computing-a-danskin-subgradient-for-a-robust-loss&quot;&gt;Worked example: Computing a Danskin Subgradient for a Robust Loss&lt;/h3&gt;

&lt;p&gt;Consider a 1D robust regression loss where a single data point has uncertain target \(y \in [2, 4]\):
\(\phi(w) = \max_{y \in [2, 4]} \; \frac{1}{2}(w - y)^2.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the inner maximization for fixed \(w\)&lt;/strong&gt;: Since \(\frac{1}{2}(w - y)^2\) is convex in \(y\), its maximum over the interval \([2, 4]\) is attained at one of the two endpoints \(y = 2\) or \(y = 4\):
\(\phi(w) = \max\!\left\{\frac{1}{2}(w - 2)^2,\; \frac{1}{2}(w - 4)^2\right\}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the Danskin subgradient at \(w = 1\) (smooth point)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;At \(w = 1\), \(\frac{1}{2}(1 - 2)^2 = 0.5\) while \(\frac{1}{2}(1 - 4)^2 = 4.5\), so the unique maximizer is \(y^\star = 4\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Unique subgradient (gradient): $$\nabla_w \bigl[\tfrac{1}{2}(w - 4)^2\bigr]\big&lt;/td&gt;
              &lt;td&gt;_{w=1} = 1 - 4 = -3$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the full subdifferential at the tie point \(w = 3\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;At \(w = 3\), both endpoints tie with loss \(\frac{1}{2}(1)^2 = 0.5\)!&lt;/li&gt;
      &lt;li&gt;The two active gradients are \(3 - 2 = +1\) and \(3 - 4 = -1\).&lt;/li&gt;
      &lt;li&gt;By Danskin’s / pointwise-max rule, \(\partial \phi(3) = \operatorname{conv}\{-1, +1\} = [-1, 1]\).&lt;/li&gt;
      &lt;li&gt;Since \(0 \in [-1, 1]\), \(w^\star = 3\) (the exact midpoint of \([2, 4]\)) is certified as the globally optimal robust estimate with minimax loss \(0.5\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-the-subgradient&quot;&gt;Modern applications of the subgradient&lt;/h1&gt;

&lt;p&gt;This optional lesson does &lt;strong&gt;not&lt;/strong&gt; redo the calculus of Chapter 07. It shows where the same objects — a vector \(g\) satisfying \(f(y)\ge f(x)+g^\top(y-x)\), the set \(\partial f(x)\), and the stationarity test \(0\in\partial f(x^\star)\) — appear in CS and data-science work from about 2022 to 2026. After reading it you should be able to name a nonsmooth loss or regularizer in a deployed pipeline, write the inclusion that characterises a minimiser, and point to a paper rather than a slogan.&lt;/p&gt;

&lt;h2 id=&quot;why-the-subgradient-is-not-a-historical-footnote&quot;&gt;Why the subgradient is not a historical footnote&lt;/h2&gt;

&lt;p&gt;ReLU networks, \(\ell_1\) feature selection, pinball (quantile) losses, and Huber-type robust fits are all &lt;strong&gt;nonsmooth convex or path-differentiable&lt;/strong&gt; pieces. Automatic differentiation in PyTorch or JAX still returns a vector at a kink; the right language for that vector is a &lt;strong&gt;conservative field&lt;/strong&gt;, which agrees with a subgradient on convex pieces and with a Clarke element almost everywhere. If you only remember “the gradient is zero at a min,” you cannot debug a Lasso support, a dead ReLU, or a quantile fit.&lt;/p&gt;

&lt;h2 id=&quot;1-relu-networks-and-nonsmooth-automatic-differentiation&quot;&gt;1. ReLU networks and nonsmooth automatic differentiation&lt;/h2&gt;

&lt;p&gt;The rectifier \(\operatorname{ReLU}(t)=\max\{t,0\}\) has&lt;/p&gt;

\[\partial\operatorname{ReLU}(t)=\begin{cases}\{0\} &amp;amp; t&amp;lt;0,\\ [0,1] &amp;amp; t=0,\\ \{1\} &amp;amp; t&amp;gt;0.\end{cases}\]

&lt;p&gt;A deep net composed of affine maps and ReLUs is Lipschitz and semialgebraic, hence &lt;strong&gt;path-differentiable&lt;/strong&gt;. Bolte and Pauwels (2021) showed that the object backprop actually implements is a &lt;em&gt;conservative set-valued field&lt;/em&gt;: it obeys a chain rule even though the Clarke subdifferential of a ReLU program need not. Bolte, Boustany, Pauwels, and Pesquet (2022) then proved a &lt;strong&gt;nonsmooth cheap-gradient principle&lt;/strong&gt; for reverse-mode AD and showed that computing &lt;em&gt;two distinct Clarke subgradients&lt;/em&gt; of a simple ReLU net is NP-hard — so production frameworks are not being lazy when they pick one element of \(\partial\operatorname{ReLU}(0)\) (usually \(0\)). Blondel and Roulet (2024) organise the same story as &lt;em&gt;differentiable programming&lt;/em&gt;: you design the program so that a conservative derivative exists, then you train with SGD.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Course link.&lt;/strong&gt; The calculus rules in &lt;a href=&quot;/contents/en/chapter07/07_02_02_subgradient_calculus/&quot;&gt;07-02-02 Subgradient calculus&lt;/a&gt; (sums, maxima, composition with affine maps) are exactly the rules a ReLU computational graph uses. The optimality test \(0\in\partial f(x)\) is what a convex last-layer problem (for example a linear SVM or a Lasso head) still has to satisfy.&lt;/p&gt;

&lt;h2 id=&quot;2-lasso-elastic-net-and-modern-glm-paths&quot;&gt;2. Lasso, elastic net, and modern GLM paths&lt;/h2&gt;

&lt;p&gt;The Lasso&lt;/p&gt;

\[\min_\beta\ \tfrac12\|y-X\beta\|_2^2+\lambda\|\beta\|_1\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;is the running example of this chapter: stationarity is \(X^\top(y-X\beta)=\lambda v\) with \(v\in\partial|\beta|_1\), i.e. \(v_j=\operatorname{sign}(\beta_j)\) on the support and $$&lt;/td&gt;
      &lt;td&gt;v_j&lt;/td&gt;
      &lt;td&gt;\le 1$$ off it (&lt;a href=&quot;/contents/en/chapter07/07_03_03_example_lasso_optimality_condition/&quot;&gt;07-03-03 Lasso optimality&lt;/a&gt;). That inclusion is still how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt; decide which coordinates are zero.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Tay, Narasimhan, and Hastie (2023) extended elastic-net paths in &lt;strong&gt;glmnet 4.1+&lt;/strong&gt; to &lt;em&gt;all&lt;/em&gt; GLM families and to stratified Cox models — the workhorse for polygenic scores, survival analysis, and high-dimensional clinical prediction. Bertrand, Klopfenstein, Bannier, Gidel, and Massias (2022) released &lt;strong&gt;skglm&lt;/strong&gt;, a scikit-learn solver that uses working sets and dual-gap tests (again, subdifferential inclusions) to fit sparse GLMs with millions of features in seconds. Guha, Ndiaye, and Huo (2023) then used the Lasso homotopy — the same active-set jumps you see from \(\partial\|\cdot\|_1\) — to compute &lt;strong&gt;conformal prediction sets&lt;/strong&gt; for sparse GLMs without refitting at every candidate response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Takeaway.&lt;/strong&gt; Soft-thresholding is not a homework trick; it is the proximal map of \(\lambda\|\cdot\|_1\) and the reason a coordinate can be certified inactive.&lt;/p&gt;

&lt;h2 id=&quot;3-pinball-loss-quantiles-and-distribution-free-intervals&quot;&gt;3. Pinball loss, quantiles, and distribution-free intervals&lt;/h2&gt;

&lt;p&gt;The pinball (check) loss \(\rho_\tau(r)=\tau r_+ +(1-\tau)(-r)_+\) is convex and piecewise linear. A sample quantile is a minimiser of \(\sum_i\rho_\tau(y_i-x_i^\top\beta)\); the subgradient with respect to the residual is \(\tau\) above zero, \(\tau-1\) below, and \([\tau-1,\tau]\) at a kink. Conformalised quantile regression (Romano, Patterson, and Candès, 2019) wraps that nonsmooth fit in a calibration step; Angelopoulos and Bates (2023) is the 2023 handbook used in vision and NLP pipelines that need a &lt;strong&gt;90% interval&lt;/strong&gt;, not a point. The 2023 ICML path-following work above is the sparse, high-dimensional cousin.&lt;/p&gt;

&lt;h2 id=&quot;4-a-five-line-check-you-can-run&quot;&gt;4. A five-line check you can run&lt;/h2&gt;

&lt;p&gt;The following snippet prints a subgradient of \(\|x\|_1\) and of ReLU at the origin — the two kinks students meet first.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;subgrad_l1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# one element of [-1, 1]
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;relu_elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kink&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;else &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subgrad_l1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;relu_elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Changing the kink value does not change the convex inequality; it &lt;em&gt;does&lt;/em&gt; change a deep net’s backward pass. That is the conservative-field story in miniature.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;The subgradient is the certificate that a nonsmooth convex model is optimal, and a conservative selection of it is what modern autodiff actually differentiates. When a paper says “we train a ReLU net / a Lasso-GLM / a quantile head,” the first-order object is the one defined in this chapter.&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Question.&lt;/strong&gt; If a Lasso coordinate satisfies $$&lt;/td&gt;
      &lt;td&gt;X_j^\top(y-X\hat\beta)&lt;/td&gt;
      &lt;td&gt;&amp;lt;\lambda\(, why can you delete column\)j\(without changing\)\hat\beta$$? How is that the same geometry as a ReLU unit that stays off?&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bolte, J., &amp;amp; Pauwels, E. (2021). Conservative set valued fields, automatic differentiation, stochastic gradient methods and deep learning. &lt;em&gt;Mathematical Programming&lt;/em&gt;, 188, 19–51. &lt;a href=&quot;https://doi.org/10.1007/s10107-020-01501-5&quot;&gt;doi:10.1007/s10107-020-01501-5&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bolte, J., Boustany, R., Pauwels, E., &amp;amp; Pesquet, B. (2022). On the complexity of nonsmooth automatic differentiation. &lt;a href=&quot;https://arxiv.org/abs/2206.01730&quot;&gt;arXiv:2206.01730&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Blondel, M., &amp;amp; Roulet, V. (2024). &lt;em&gt;The Elements of Differentiable Programming&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2403.14606&quot;&gt;arXiv:2403.14606&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Tay, J. K., Narasimhan, B., &amp;amp; Hastie, T. (2023). Elastic net regularization paths for all generalized linear models. &lt;em&gt;Journal of Statistical Software&lt;/em&gt;, 106(1), 1–31. &lt;a href=&quot;https://doi.org/10.18637/jss.v106.i01&quot;&gt;doi:10.18637/jss.v106.i01&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bertrand, Q., Klopfenstein, Q., Bannier, P.-A., Gidel, G., &amp;amp; Massias, M. (2022). Beyond L1: Faster and better sparse models with skglm. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Guha, E. K., Ndiaye, E., &amp;amp; Huo, X. (2023). Conformalization of sparse generalized linear models. &lt;em&gt;ICML&lt;/em&gt;, PMLR 202.&lt;/li&gt;
  &lt;li&gt;Angelopoulos, A. N., &amp;amp; Bates, S. (2023). Conformal prediction: A gentle introduction. &lt;em&gt;Foundations and Trends in Machine Learning&lt;/em&gt;, 16(4).&lt;/li&gt;
  &lt;li&gt;Romano, Y., Patterson, E., &amp;amp; Candès, E. J. (2019). Conformalized quantile regression. &lt;em&gt;NeurIPS&lt;/em&gt;. (background for the pinball + calibration pipeline)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-08 Modern applications of the subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_08_modern_applications/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_08_modern_applications</id>
   <content type="html">&lt;p&gt;Open PyTorch, define a ReLU neural network, and call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.backward()&lt;/code&gt;—even though \(\mathrm{ReLU}(z) = \max(0, z)\) has a sharp kink at \(z = 0\) where no classical derivative exists! Far from being a dusty 1960s footnote, the subdifferential \(\partial f(x)\) and its nonconvex Clarke/conservative extensions are the quiet mathematical bedrock behind modern deep-learning autograd, sparse/low-rank recovery, and nonsmooth fairness losses.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-where-subgradients-power-20222026-ml-systems&quot;&gt;Key ideas: Where Subgradients Power 2022–2026 ML Systems&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nonsmooth Automatic Differentiation &amp;amp; Conservative Fields&lt;/strong&gt;: PyTorch and JAX evaluate a chosen branch slope at ReLU/max-pool kinks (e.g., setting \(\mathrm{ReLU}&apos;(0) = 0\)). Bolte and Pauwels (2020–2024) formalized &lt;em&gt;conservative set-valued fields&lt;/em&gt;—showing when backpropagation through nonsmooth compositions still yields valid generalized gradients and guarantees convergence of SGD.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Clarke Subdifferential for Nonconvex Nonsmooth Losses&lt;/strong&gt;: When a function \(f\) is locally Lipschitz but &lt;em&gt;nonconvex&lt;/em&gt; (like a deep ReLU network), the convex subgradient inequality breaks. Taking the convex hull of limit points of gradients \(\nabla f(x_k)\) from nearby smooth points produces the &lt;strong&gt;Clarke subdifferential&lt;/strong&gt; \(\partial^C f(x)\), which coincides with \(\partial f(x)\) whenever \(f\) is convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sparsity, Low-Rank Matrices &amp;amp; Structured Norms&lt;/strong&gt;: Subdifferentials of the \(\ell_1\) norm, group-Lasso \(\sum_g \|w_g\|_2\), and nuclear norm \(\|W\|_*\) (sum of singular values) govern exact recovery guarantees in compressed sensing, matrix completion, and LoRA-style low-rank adaptation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robustness &amp;amp; Minimax Adversarial Training&lt;/strong&gt;: Training against worst-case perturbations \(\min_w \max_{\|\delta\| \le \epsilon} L(w, x + \delta)\) creates a pointwise maximum over \(\delta\)—Danskin’s theorem (the infinite-index max rule of subgradient calculus) says the gradient at the worst-case adversarial example \(\delta^\star\) is a valid subgradient of the robust loss!&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-why-chain-rule-autograd-can-differ-from-the-exact-clarke-subdifferential&quot;&gt;Worked example: Why Chain-Rule Autograd Can Differ from the Exact Clarke Subdifferential&lt;/h3&gt;

&lt;p&gt;Consider the 1D composition \(h(x) = \mathrm{ReLU}(x) - \mathrm{ReLU}(x) = 0\) for all \(x \in \mathbb{R}\), where \(\mathrm{ReLU}(z) = \max(0, z)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Exact mathematical derivative&lt;/strong&gt;: Since \(h(x) \equiv 0\) identically, its true derivative and Clarke subdifferential at \(x = 0\) is strictly \(\{0\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;What naive subgradient sum rule / autograd computes at \(x = 0\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(\partial \mathrm{ReLU}(0) = [0, 1]\).&lt;/li&gt;
      &lt;li&gt;Treating the two terms independently gives \(\partial \mathrm{ReLU}(0) - \partial \mathrm{ReLU}(0) = [0, 1] - [0, 1] = [-1, 1] \supsetneq \{0\}\)!&lt;/li&gt;
      &lt;li&gt;If a custom autograd rule chose slope \(1\) for the first ReLU and \(0\) for the second, it could return a &lt;em&gt;spurious&lt;/em&gt; value \(1 \neq 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Contrast with a standard convex hinge loss \(L(w) = \max(0, 1 - w)\) at the kink \(w = 1\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Smooth branches: \(0\) (slope \(0\)) and \(1 - w\) (slope \(-1\)).&lt;/li&gt;
      &lt;li&gt;Exact subdifferential: \(\partial L(1) = [-1, 0]\).&lt;/li&gt;
      &lt;li&gt;PyTorch’s deterministic choice \(g = 0\) (or \(g = -1\)) both belong to \([-1, 0]\), so every autograd output on a single convex hinge is a genuine subgradient!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;modern-applications-of-the-subgradient&quot;&gt;Modern applications of the subgradient&lt;/h1&gt;

&lt;p&gt;This optional lesson does &lt;strong&gt;not&lt;/strong&gt; redo the calculus of Chapter 07. It shows where the same objects — a vector \(g\) satisfying \(f(y)\ge f(x)+g^\top(y-x)\), the set \(\partial f(x)\), and the stationarity test \(0\in\partial f(x^\star)\) — appear in CS and data-science work from about 2022 to 2026. After reading it you should be able to name a nonsmooth loss or regularizer in a deployed pipeline, write the inclusion that characterises a minimiser, and point to a paper rather than a slogan.&lt;/p&gt;

&lt;h2 id=&quot;why-the-subgradient-is-not-a-historical-footnote&quot;&gt;Why the subgradient is not a historical footnote&lt;/h2&gt;

&lt;p&gt;ReLU networks, \(\ell_1\) feature selection, pinball (quantile) losses, and Huber-type robust fits are all &lt;strong&gt;nonsmooth convex or path-differentiable&lt;/strong&gt; pieces. Automatic differentiation in PyTorch or JAX still returns a vector at a kink; the right language for that vector is a &lt;strong&gt;conservative field&lt;/strong&gt;, which agrees with a subgradient on convex pieces and with a Clarke element almost everywhere. If you only remember “the gradient is zero at a min,” you cannot debug a Lasso support, a dead ReLU, or a quantile fit.&lt;/p&gt;

&lt;h2 id=&quot;1-relu-networks-and-nonsmooth-automatic-differentiation&quot;&gt;1. ReLU networks and nonsmooth automatic differentiation&lt;/h2&gt;

&lt;p&gt;The rectifier \(\operatorname{ReLU}(t)=\max\{t,0\}\) has&lt;/p&gt;

\[\partial\operatorname{ReLU}(t)=\begin{cases}\{0\} &amp;amp; t&amp;lt;0,\\ [0,1] &amp;amp; t=0,\\ \{1\} &amp;amp; t&amp;gt;0.\end{cases}\]

&lt;p&gt;A deep net composed of affine maps and ReLUs is Lipschitz and semialgebraic, hence &lt;strong&gt;path-differentiable&lt;/strong&gt;. Bolte and Pauwels (2021) showed that the object backprop actually implements is a &lt;em&gt;conservative set-valued field&lt;/em&gt;: it obeys a chain rule even though the Clarke subdifferential of a ReLU program need not. Bolte, Boustany, Pauwels, and Pesquet (2022) then proved a &lt;strong&gt;nonsmooth cheap-gradient principle&lt;/strong&gt; for reverse-mode AD and showed that computing &lt;em&gt;two distinct Clarke subgradients&lt;/em&gt; of a simple ReLU net is NP-hard — so production frameworks are not being lazy when they pick one element of \(\partial\operatorname{ReLU}(0)\) (usually \(0\)). Blondel and Roulet (2024) organise the same story as &lt;em&gt;differentiable programming&lt;/em&gt;: you design the program so that a conservative derivative exists, then you train with SGD.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Course link.&lt;/strong&gt; The calculus rules in &lt;a href=&quot;/contents/en/chapter07/07_02_02_subgradient_calculus/&quot;&gt;07-02-02 Subgradient calculus&lt;/a&gt; (sums, maxima, composition with affine maps) are exactly the rules a ReLU computational graph uses. The optimality test \(0\in\partial f(x)\) is what a convex last-layer problem (for example a linear SVM or a Lasso head) still has to satisfy.&lt;/p&gt;

&lt;h2 id=&quot;2-lasso-elastic-net-and-modern-glm-paths&quot;&gt;2. Lasso, elastic net, and modern GLM paths&lt;/h2&gt;

&lt;p&gt;The Lasso&lt;/p&gt;

\[\min_\beta\ \tfrac12\|y-X\beta\|_2^2+\lambda\|\beta\|_1\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;is the running example of this chapter: stationarity is \(X^\top(y-X\beta)=\lambda v\) with \(v\in\partial|\beta|_1\), i.e. \(v_j=\operatorname{sign}(\beta_j)\) on the support and $$&lt;/td&gt;
      &lt;td&gt;v_j&lt;/td&gt;
      &lt;td&gt;\le 1$$ off it (&lt;a href=&quot;/contents/en/chapter07/07_03_03_example_lasso_optimality_condition/&quot;&gt;07-03-03 Lasso optimality&lt;/a&gt;). That inclusion is still how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt; decide which coordinates are zero.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Tay, Narasimhan, and Hastie (2023) extended elastic-net paths in &lt;strong&gt;glmnet 4.1+&lt;/strong&gt; to &lt;em&gt;all&lt;/em&gt; GLM families and to stratified Cox models — the workhorse for polygenic scores, survival analysis, and high-dimensional clinical prediction. Bertrand, Klopfenstein, Bannier, Gidel, and Massias (2022) released &lt;strong&gt;skglm&lt;/strong&gt;, a scikit-learn solver that uses working sets and dual-gap tests (again, subdifferential inclusions) to fit sparse GLMs with millions of features in seconds. Guha, Ndiaye, and Huo (2023) then used the Lasso homotopy — the same active-set jumps you see from \(\partial\|\cdot\|_1\) — to compute &lt;strong&gt;conformal prediction sets&lt;/strong&gt; for sparse GLMs without refitting at every candidate response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Takeaway.&lt;/strong&gt; Soft-thresholding is not a homework trick; it is the proximal map of \(\lambda\|\cdot\|_1\) and the reason a coordinate can be certified inactive.&lt;/p&gt;

&lt;h2 id=&quot;3-pinball-loss-quantiles-and-distribution-free-intervals&quot;&gt;3. Pinball loss, quantiles, and distribution-free intervals&lt;/h2&gt;

&lt;p&gt;The pinball (check) loss \(\rho_\tau(r)=\tau r_+ +(1-\tau)(-r)_+\) is convex and piecewise linear. A sample quantile is a minimiser of \(\sum_i\rho_\tau(y_i-x_i^\top\beta)\); the subgradient with respect to the residual is \(\tau\) above zero, \(\tau-1\) below, and \([\tau-1,\tau]\) at a kink. Conformalised quantile regression (Romano, Patterson, and Candès, 2019) wraps that nonsmooth fit in a calibration step; Angelopoulos and Bates (2023) is the 2023 handbook used in vision and NLP pipelines that need a &lt;strong&gt;90% interval&lt;/strong&gt;, not a point. The 2023 ICML path-following work above is the sparse, high-dimensional cousin.&lt;/p&gt;

&lt;h2 id=&quot;4-a-five-line-check-you-can-run&quot;&gt;4. A five-line check you can run&lt;/h2&gt;

&lt;p&gt;The following snippet prints a subgradient of \(\|x\|_1\) and of ReLU at the origin — the two kinks students meet first.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;subgrad_l1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# one element of [-1, 1]
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;relu_elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kink&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;else &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subgrad_l1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;relu_elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Changing the kink value does not change the convex inequality; it &lt;em&gt;does&lt;/em&gt; change a deep net’s backward pass. That is the conservative-field story in miniature.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;p&gt;The subgradient is the certificate that a nonsmooth convex model is optimal, and a conservative selection of it is what modern autodiff actually differentiates. When a paper says “we train a ReLU net / a Lasso-GLM / a quantile head,” the first-order object is the one defined in this chapter.&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Question.&lt;/strong&gt; If a Lasso coordinate satisfies $$&lt;/td&gt;
      &lt;td&gt;X_j^\top(y-X\hat\beta)&lt;/td&gt;
      &lt;td&gt;&amp;lt;\lambda\(, why can you delete column\)j\(without changing\)\hat\beta$$? How is that the same geometry as a ReLU unit that stays off?&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bolte, J., &amp;amp; Pauwels, E. (2021). Conservative set valued fields, automatic differentiation, stochastic gradient methods and deep learning. &lt;em&gt;Mathematical Programming&lt;/em&gt;, 188, 19–51. &lt;a href=&quot;https://doi.org/10.1007/s10107-020-01501-5&quot;&gt;doi:10.1007/s10107-020-01501-5&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bolte, J., Boustany, R., Pauwels, E., &amp;amp; Pesquet, B. (2022). On the complexity of nonsmooth automatic differentiation. &lt;a href=&quot;https://arxiv.org/abs/2206.01730&quot;&gt;arXiv:2206.01730&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Blondel, M., &amp;amp; Roulet, V. (2024). &lt;em&gt;The Elements of Differentiable Programming&lt;/em&gt;. &lt;a href=&quot;https://arxiv.org/abs/2403.14606&quot;&gt;arXiv:2403.14606&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Tay, J. K., Narasimhan, B., &amp;amp; Hastie, T. (2023). Elastic net regularization paths for all generalized linear models. &lt;em&gt;Journal of Statistical Software&lt;/em&gt;, 106(1), 1–31. &lt;a href=&quot;https://doi.org/10.18637/jss.v106.i01&quot;&gt;doi:10.18637/jss.v106.i01&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Bertrand, Q., Klopfenstein, Q., Bannier, P.-A., Gidel, G., &amp;amp; Massias, M. (2022). Beyond L1: Faster and better sparse models with skglm. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Guha, E. K., Ndiaye, E., &amp;amp; Huo, X. (2023). Conformalization of sparse generalized linear models. &lt;em&gt;ICML&lt;/em&gt;, PMLR 202.&lt;/li&gt;
  &lt;li&gt;Angelopoulos, A. N., &amp;amp; Bates, S. (2023). Conformal prediction: A gentle introduction. &lt;em&gt;Foundations and Trends in Machine Learning&lt;/em&gt;, 16(4).&lt;/li&gt;
  &lt;li&gt;Romano, Y., Patterson, E., &amp;amp; Candès, E. J. (2019). Conformalized quantile regression. &lt;em&gt;NeurIPS&lt;/em&gt;. (background for the pinball + calibration pipeline)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-08 Applications and recent developments</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_08_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_08_Applications_Recent</id>
   <content type="html">&lt;p&gt;Classical gradient-descent theory tells you that stepping past \(t &amp;gt; 2/L\) causes immediate explosion. Yet if you measure the Hessian of a deep neural network during real training, something astonishing happens: the sharpness \(\lambda_{\max}(\nabla^2 f)\) climbs &lt;em&gt;right up to&lt;/em&gt; \(2/t\) and hovers there for thousands of epochs without diverging! This lesson explores three major 2022–2026 breakthroughs—Edge of Stability, the Lion optimizer, and Schedule-Free SGD/AdamW—where empirical deep learning reshaped our understanding of first-order methods.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-first-order-optimization-at-the-20222026-frontier&quot;&gt;Key ideas: First-Order Optimization at the 2022–2026 Frontier&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Edge of Stability (EoS)&lt;/strong&gt;: Cohen et al. showed that full-batch GD on neural nets undergoes &lt;em&gt;progressive sharpening&lt;/em&gt; until \(\lambda_{\max}(\nabla^2 f(x_k)) \approx 2/t\). Beyond that threshold, nonlinear third/fourth-order terms self-stabilize the oscillations while the loss continues to drop non-monotonically over long horizons—defying the quadratic \(L\)-smoothness picture.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sign-Based Momentum (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Lion&lt;/code&gt;)&lt;/strong&gt;: Discovered via symbolic program search (Chen et al., 2023), Lion tracks a single momentum buffer and updates weights via the elementwise &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sign&lt;/code&gt; of an interpolated momentum vector: \(x_{k+1} = x_k - t \operatorname{sign}\bigl(\beta_1 m_k + (1 - \beta_1) g_k\bigr)\). Every parameter moves by the exact same magnitude \(t\), cutting optimizer memory in half compared to AdamW.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Schedule-Free Optimization (Defazio et al., 2024)&lt;/strong&gt;: Instead of pre-committing to a cosine or linear learning-rate decay horizon \(T\), Schedule-Free SGD/AdamW decouples the &lt;em&gt;iterates&lt;/em&gt; (where gradients are evaluated via Polyak–Ruppert averaging interpolation) from the &lt;em&gt;solution sequence&lt;/em&gt;, removing the stopping-time hyperparameter while matching tuned cosine schedules.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Classical Theory Still Anchors Modern Practice&lt;/strong&gt;: Even at the Edge of Stability, understanding \(2/L\), momentum damping, and iterate averaging is the exact language needed to diagnose loss spikes, tune weight decay, and reason about step-size scaling.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-computing-one-update-of-lion-vs-vanilla-momentum&quot;&gt;Worked example: Computing One Update of Lion vs. Vanilla Momentum&lt;/h3&gt;

&lt;p&gt;Compare one update on a 2D weight vector \(x_0 = (1.0,\; 1.0)\) with initial momentum \(m_0 = (0.2,\; -0.4)\), current gradient \(g_1 = (0.01,\; -5.0)\), learning rate \(t = 0.1\), and \(\beta_1 = 0.9, \beta_2 = 0.99\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vanilla Momentum update&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(m_1 = 0.9(0.2, -0.4) + (0.01, -5.0) = (0.19,\; -5.36)\).&lt;/li&gt;
      &lt;li&gt;\(x_1^{\mathrm{Mom}} = (1.0, 1.0) - 0.1(0.19, -5.36) = (0.981,\; 1.536)\).&lt;/li&gt;
      &lt;li&gt;Notice coordinate 2 moved &lt;strong&gt;28× farther&lt;/strong&gt; than coordinate 1 because of the huge gradient scale disparity.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lion update&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Interpolated update direction: \(u_1 = \beta_1 m_0 + (1 - \beta_1) g_1 = 0.9(0.2, -0.4) + 0.1(0.01, -5.0) = (0.181,\; -0.860)\).&lt;/li&gt;
      &lt;li&gt;Apply elementwise &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sign&lt;/code&gt;: \(\operatorname{sign}(u_1) = (+1,\; -1)\).&lt;/li&gt;
      &lt;li&gt;Update weights: \(x_1^{\mathrm{Lion}} = (1.0, 1.0) - 0.1(+1, -1) = (0.900,\; 1.100)\).&lt;/li&gt;
      &lt;li&gt;Update stored momentum for the next step: \(m_1^{\mathrm{Lion}} = 0.99(0.2, -0.4) + 0.01(0.01, -5.0) = (0.1981,\; -0.4460)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Key insight&lt;/strong&gt;: Lion normalizes every coordinate’s step magnitude to exactly \(t = 0.1\) using only one buffer \(m\) (no second-moment variance buffer \(v\) like Adam!), preventing giant gradients from destabilizing individual layers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chapter 06 developed gradient descent with a Lipschitz gradient, step-size rules, and the faster rate under strong convexity. That theory is still the right first picture — and it is &lt;em&gt;not&lt;/em&gt; the whole picture of how people train networks in 2022–2026. This lesson adds three empirical and algorithmic developments you should be able to cite: the edge-of-stability regime for full-batch GD, a sign-based momentum method discovered by program search (Lion), and schedule-free averaging that removes the need to know \(T\) in advance. Adaptive methods (AdamW) live in &lt;a href=&quot;/contents/en/chapter26/&quot;&gt;Chapter 26&lt;/a&gt;; we only mention them when a paper uses them as a baseline.&lt;/p&gt;

&lt;h2 id=&quot;edge-of-stability-when-the-textbook-step-size-bound-fails&quot;&gt;Edge of stability: when the textbook step-size bound fails&lt;/h2&gt;

&lt;p&gt;If \(\nabla f\) is \(L\)-Lipschitz, the standard descent lemma says that a &lt;em&gt;fixed&lt;/em&gt; step \(t&amp;lt;2/L\) makes \(f\) decrease monotonically. Cohen, Kaur, Li, Kolter, and Talwalkar (&lt;em&gt;Gradient Descent on Neural Networks Typically Occurs at the Edge of Stability&lt;/em&gt;, &lt;a href=&quot;https://openreview.net/forum?id=jh-rTtvkGeM&quot;&gt;ICLR 2021&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2103.00065&quot;&gt;arXiv:2103.00065&lt;/a&gt;) measured full-batch GD on modern nets and found a different regime: the largest Hessian eigenvalue \(\lambda_{\max}\) &lt;em&gt;rises&lt;/em&gt; until it hovers just above \(2/t\), and the training loss oscillates on short windows while still trending down. That is incompatible with a global \(L\) that you treat as fixed.&lt;/p&gt;

&lt;p&gt;Arora, Li, and Panigrahi (&lt;em&gt;Understanding Gradient Descent on the Edge of Stability in Deep Learning&lt;/em&gt;, &lt;a href=&quot;https://proceedings.mlr.press/v162/arora22a.html&quot;&gt;ICML 2022&lt;/a&gt;) gave a mechanism: after entering the edge-of-stability phase, iterates can follow a deterministic flow on a manifold of (near) minimal loss that &lt;em&gt;decreases&lt;/em&gt; sharpness \(\lambda_{\max}(\nabla^2 L)\). They prove the phenomenon for normalized GD and for GD on \(\sqrt{L-L^\star}\) under regularity assumptions.&lt;/p&gt;

&lt;p&gt;For this chapter, keep both statements in your head. The descent lemma is not wrong; the hypothesis “\(L\) is constant along the path” is. When your homework assumes a quadratic upper bound (06-03-01), you are in the pre-edge regime. When a deep-learning paper says the run is “at the edge of stability,” they mean \(\lambda_{\max}\approx 2/t\) and you should not expect monotone decrease.&lt;/p&gt;

&lt;h2 id=&quot;lion-momentum-with-a-sign&quot;&gt;Lion: momentum with a sign&lt;/h2&gt;

&lt;p&gt;Chen, Liang, Huang, Real, Wang, Pham, Dong, Luong, Hsieh, Lu, Le, and colleagues (&lt;em&gt;Symbolic Discovery of Optimization Algorithms&lt;/em&gt;, &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2023/hash/9a39b4925e35cf447ccba8757137d84f-Abstract-Conference.html&quot;&gt;NeurIPS 2023&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2302.06675&quot;&gt;arXiv:2302.06675&lt;/a&gt;; code in &lt;a href=&quot;https://github.com/google/automl/tree/master/lion&quot;&gt;google/automl/lion&lt;/a&gt;) searched a space of optimizer programs and found &lt;strong&gt;Lion&lt;/strong&gt; (EvoLved Sign Momentum). The update keeps a single momentum buffer \(m\) and steps in the &lt;em&gt;sign&lt;/em&gt; of a blend of \(m\) and the current gradient:&lt;/p&gt;

\[\begin{align}
u_t &amp;amp;= \beta_1 m_{t-1} + (1-\beta_1) g_t,\\
\theta_t &amp;amp;= \theta_{t-1} - \eta\,\mathrm{sign}(u_t),\\
m_t &amp;amp;= \beta_2 m_{t-1} + (1-\beta_2) g_t.
\end{align}\]

&lt;p&gt;There is no second-moment preconditioner, so memory is closer to SGD-with-momentum than to Adam. The authors report ImageNet gains on ViT, compute savings on JFT and on diffusion training, and competitive language-model runs; they also document settings where the gain is small. Default practice is a &lt;em&gt;smaller&lt;/em&gt; \(\eta\) than AdamW, because \(\|\mathrm{sign}(u)\|_{\infty}=1\) makes each coordinate step full size.&lt;/p&gt;

&lt;p&gt;Chapter 06 already introduced momentum (06-06). Lion is that idea with a coordinate-wise sign — a non-Euclidean twist you can view as normalized steepest descent in the \(\ell_\infty\) geometry. It is &lt;em&gt;not&lt;/em&gt; a replacement for the convergence proofs in 06-03; those proofs assume smooth Euclidean steps.&lt;/p&gt;

&lt;h2 id=&quot;schedule-free-sgd-and-adamw&quot;&gt;Schedule-free SGD and AdamW&lt;/h2&gt;

&lt;p&gt;Classical theory often wants a decreasing step size that depends on the horizon \(T\) (or on a budget you announce in advance). Practitioners instead pick a cosine schedule that also depends on \(T\). Defazio, Yang, Khaled, Mishchenko, Mehta, and Cutkosky (&lt;em&gt;The Road Less Scheduled&lt;/em&gt;, &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2024/hash/136b9a13861308c8948cd308ccd02658-Abstract-Conference.html&quot;&gt;NeurIPS 2024&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2405.15682&quot;&gt;arXiv:2405.15682&lt;/a&gt;; &lt;a href=&quot;https://github.com/facebookresearch/schedule_free&quot;&gt;facebookresearch/schedule_free&lt;/a&gt;) interpolate an iterate-averaged sequence with a momentum-like base sequence so that &lt;em&gt;no&lt;/em&gt; decreasing schedule is required. Schedule-Free AdamW was the core of their winning entry in the 2024 MLCommons AlgoPerf self-tuning track. Empirically the method tracks the Pareto frontier of “loss versus training time” that you would otherwise get by launching many cosine runs of different lengths.&lt;/p&gt;

&lt;p&gt;The link to this chapter is Polyak–Ruppert averaging and momentum, not a new descent lemma. If you understand why averaging can replace a decaying step (the same intuition as 06-05’s noisy SGD), you can read the paper’s interpolation as a &lt;em&gt;practical&lt;/em&gt; averaging scheme that finally matches tuned schedules.&lt;/p&gt;

&lt;h2 id=&quot;what-to-do-in-this-course-versus-later&quot;&gt;What to do in this course versus later&lt;/h2&gt;

&lt;p&gt;For homework and the midterm, use the Lipschitz and strong-convexity rates as written in 06-03. For a training log of a deep net, plot loss &lt;em&gt;and&lt;/em&gt;, if you can afford it, a power-iteration estimate of \(\lambda_{\max}\); expect edge-of-stability oscillations under full-batch GD. For a large stochastic run, start from AdamW or Schedule-Free AdamW (Chapter 26) and treat Lion as an alternative momentum baseline, not as the new default proof.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;J. M. Cohen, S. Kaur, Y. Li, J. Z. Kolter, and A. Talwalkar, “Gradient Descent on Neural Networks Typically Occurs at the Edge of Stability,” ICLR 2021. &lt;a href=&quot;https://openreview.net/forum?id=jh-rTtvkGeM&quot;&gt;OpenReview&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2103.00065&quot;&gt;arXiv:2103.00065&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;S. Arora, Z. Li, and A. Panigrahi, “Understanding Gradient Descent on the Edge of Stability in Deep Learning,” ICML 2022. &lt;a href=&quot;https://proceedings.mlr.press/v162/arora22a.html&quot;&gt;PMLR&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;X. Chen et al., “Symbolic Discovery of Optimization Algorithms,” NeurIPS 2023. &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2023/hash/9a39b4925e35cf447ccba8757137d84f-Abstract-Conference.html&quot;&gt;abstract&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2302.06675&quot;&gt;arXiv:2302.06675&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;A. Defazio, X. Yang, A. Khaled, K. Mishchenko, H. Mehta, and A. Cutkosky, “The Road Less Scheduled,” NeurIPS 2024. &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2024/hash/136b9a13861308c8948cd308ccd02658-Abstract-Conference.html&quot;&gt;abstract&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2405.15682&quot;&gt;arXiv:2405.15682&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>05-08 Applications and recent developments</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_08_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_08_Applications_Recent</id>
   <content type="html">&lt;p&gt;Canonical forms are not museum pieces—they are the live production APIs running inside quantitative trading desks, aerospace flight computers, and AI safety verifiers. Between 2022 and 2026, a new generation of Rust-based conic interior-point solvers (like Clarabel), realistic transaction-cost portfolio QPs, and semidefinite relaxations for certifying neural-network robustness have pushed Chapter 05’s taxonomy straight to the frontier of applied computing.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-production-conic-optimization-20222026&quot;&gt;Key ideas: Production Conic Optimization (2022–2026)&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Unified Interior-Point Engines (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Clarabel&lt;/code&gt;)&lt;/strong&gt;: Earlier solvers fragmented by class—OSQP for QPs, ECOS for SOCPs, SCS for large cone problems. Clarabel solves LP, QP, SOCP, SDP, exponential, and power cones in a single homogeneous self-dual interior-point engine without splitting quadratic objectives into extra cones.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Shippable Portfolio QPs&lt;/strong&gt;: Real portfolio optimization extends textbook Markowitz with turnover penalties \(\gamma \|w - w_{\mathrm{prev}}\|_1\) (linearized via epigraph slacks), leverage caps, sector limits, and factor covariance models \(\Sigma = B \Sigma_f B^T + D\) that keep KKT linear systems sparse and fast.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SDP Certification of Neural Networks&lt;/strong&gt;: Verifying that no \(\ell_\infty\) perturbation \(\|\delta\|_\infty \le \epsilon\) flips a ReLU classifier’s decision is NP-hard in general. Encoding the ReLU relation \(y = \max(0, z)\) as quadratic inequalities \(y \ge 0, y \ge z, y(y - z) = 0\) and lifting to an SDP yields a tight, sound robustness certificate.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sparsity and Structure Exploitation&lt;/strong&gt;: Across all three applications, problem size is only half the story—chordal sparsity in SDPs and low-rank-plus-diagonal factor models in QPs turn \(O(n^3)\) bottlenecks into near-linear runtimes.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-factor-model-speedup-and-relu-quadratic-encoding&quot;&gt;Worked example: Factor-Model Speedup and ReLU Quadratic Encoding&lt;/h3&gt;

&lt;p&gt;Verify two core mathematical tricks used in modern production QPs and SDPs:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Part A — Factor-Model Variance Simplification (QP)&lt;/strong&gt;: Suppose a portfolio has \(n = 2\) assets with factor loading \(B = (1, 2)^T\), single-factor variance \(\sigma_f^2 = 0.04\), and idiosyncratic diagonal variance \(D = \operatorname{diag}(0.01, 0.01)\).
    &lt;ul&gt;
      &lt;li&gt;The full covariance is \(\Sigma = B \sigma_f^2 B^T + D = 0.04\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix} + \begin{bmatrix} 0.01 &amp;amp; 0 \\ 0 &amp;amp; 0.01 \end{bmatrix} = \begin{bmatrix} 0.05 &amp;amp; 0.08 \\ 0.08 &amp;amp; 0.17 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;Introducing the factor exposure scalar \(y = B^T w = w_1 + 2w_2\) decouples the quadratic risk into a purely diagonal form:
\(w^T \Sigma w = 0.04 y^2 + 0.01 w_1^2 + 0.01 w_2^2.\)&lt;/li&gt;
      &lt;li&gt;Check at \(w = (0.6, 0.4)\): \(y = 0.6 + 0.8 = 1.4\), so \(0.04(1.96) + 0.01(0.36 + 0.16) = 0.0784 + 0.0052 = 0.0836\). Directly: \(0.36(0.05) + 2(0.24)(0.08) + 0.16(0.17) = 0.018 + 0.0384 + 0.0272 = 0.0836\)—exact match, and for \(n = 5{,}000\) assets with \(k = 20\) factors, this shrinks the KKT matrix from dense \(5000 \times 5000\) to sparse!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Part B — Quadratic Encoding of a ReLU Neuron (SDP Verification)&lt;/strong&gt;: Check that \(y = \max(0, z)\) satisfies the three exact conditions \(y \ge 0\), \(y \ge z\), and \(y(y - z) = 0\):
    &lt;ul&gt;
      &lt;li&gt;If \(z = 3\): \(y = 3\) gives \(3 \ge 0\), \(3 \ge 3\), and \(3(3 - 3) = 0\).&lt;/li&gt;
      &lt;li&gt;If \(z = -2\): \(y = 0\) gives \(0 \ge 0\), \(0 \ge -2\), and \(0(0 - (-2)) = 0\).&lt;/li&gt;
      &lt;li&gt;Relaxing the rank-1 outer product \([1, z, y]^T[1, z, y]\) to a \(3 \times 3\) PSD matrix \(P \succeq 0\) converts \(y(y - z) = 0\) into the linear trace constraint \(P_{yy} - P_{yz} = 0\) inside an SDP.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chapter 05 classified convex programs by the &lt;em&gt;shape&lt;/em&gt; of the objective and the cones in the constraints: LP, QP, QCQP, SOCP, SDP, and geometric programs. That taxonomy is also the API of a modeling language. This lesson looks at three places where those canonical forms are the 2022–2026 production objects — a modern interior-point solver shipped with CVXPY, portfolio QPs you can backtest, and SDP relaxations that certify neural nets — plus a reminder that Lasso and sparse recovery are still QPs (or QPs in extended form) you should model, not hand-code.&lt;/p&gt;

&lt;p&gt;You already have a DCP/CVXPY lab in &lt;a href=&quot;/contents/en/chapter05/05_07_Modeling_with_DCP_CVXPY/&quot;&gt;05-07&lt;/a&gt;. Treat this lesson as the &lt;em&gt;why these cones&lt;/em&gt; companion.&lt;/p&gt;

&lt;h2 id=&quot;clarabel-a-2024-interior-point-engine-for-the-whole-taxonomy&quot;&gt;Clarabel: a 2024 interior-point engine for the whole taxonomy&lt;/h2&gt;

&lt;p&gt;Goulart and Chen (&lt;em&gt;Clarabel: An interior-point solver for conic programs with quadratic objectives&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv:2405.12762&lt;/a&gt;, 2024; docs &lt;a href=&quot;https://clarabel.org/&quot;&gt;clarabel.org&lt;/a&gt;; &lt;a href=&quot;https://oxfordcontrol.github.io/ClarabelDocs/stable/citing/&quot;&gt;citing page&lt;/a&gt;) built a homogeneous-embedding interior-point method for convex programs with conic constraints and a quadratic objective. The solver speaks the cones this chapter named — nonnegative, second-order, semidefinite (with chordal decomposition), and selected nonsymmetric cones — and is distributed as a standard solver in CVXPY. Their numerical profile is especially strong on QPs relative to several open-source and commercial codes.&lt;/p&gt;

&lt;p&gt;The pedagogical point is ruthless: once your DCP model is canonicalized, you are no longer “doing Lasso in Python.” You are handing a cone program to an IPM. Switching &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=cp.CLARABEL&lt;/code&gt; versus &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.OSQP&lt;/code&gt; versus &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.SCS&lt;/code&gt; is an experiment on &lt;em&gt;canonical form + algorithm&lt;/em&gt;, not a rewrite of the science. OSQP (Stellato, Banjac, O’Donoghue, Bemporad, and Boyd, &lt;em&gt;Math. Prog. Comp.&lt;/em&gt; 2020) remains the first-choice first-order QP solver for many control and portfolio QPs; Clarabel is the 2024 interior-point counterpart you should know by name.&lt;/p&gt;

&lt;h2 id=&quot;portfolio-construction-as-a-qp-you-can-ship&quot;&gt;Portfolio construction as a QP you can ship&lt;/h2&gt;

&lt;p&gt;Markowitz mean–variance allocation is the QP&lt;/p&gt;

\[\begin{align}
\min_x \quad &amp;amp; x^\top \Sigma x - \gamma \hat{r}^\top x \\
\text{s.t.} \quad &amp;amp; \mathbf{1}^\top x = 1, \quad x\in\mathcal{X},
\end{align}\]

&lt;p&gt;with \(\mathcal{X}\) a polytope of long-only, leverage, or turnover limits. Boyd, Busseti, Diamond, Kahn, Koh, Nystrup, and Speth (&lt;em&gt;Multi-Period Trading via Convex Optimization&lt;/em&gt;, &lt;a href=&quot;https://stanford.edu/~boyd/papers/cvx_portfolio.html&quot;&gt;&lt;em&gt;Found. Trends Optim.&lt;/em&gt; 2017&lt;/a&gt;) put single- and multi-period versions of this QP — plus transaction and holding costs — in one framework. The companion library &lt;a href=&quot;https://www.cvxportfolio.com/&quot;&gt;cvxportfolio&lt;/a&gt; (actively maintained through the mid-2020s, currently documented at v1.5) is how you &lt;em&gt;run&lt;/em&gt; that paper on recent market data: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SinglePeriodOptimization&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MultiPeriodOptimization&lt;/code&gt; policies inside a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;StockMarketSimulator&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The 2017 monograph is older than 2022; the reason it belongs here is that the &lt;em&gt;canonical form&lt;/em&gt; has not been replaced, only the solver stack (OSQP / Clarabel) and the software API have. If you need a 2022–2023 scientific counterpart, Wasserstein DRO portfolios (Gao and Kleywegt, &lt;a href=&quot;https://doi.org/10.1287/moor.2022.1275&quot;&gt;&lt;em&gt;Math. Oper. Res.&lt;/em&gt; 2023&lt;/a&gt;; see Chapter 02) are QPs or SOCPs once the dual is written down.&lt;/p&gt;

&lt;h2 id=&quot;sdp-relaxations-for-neural-network-verification&quot;&gt;SDP relaxations for neural-network verification&lt;/h2&gt;

&lt;p&gt;Asking whether a ReLU network is locally robust — “no perturbation of radius \(\varepsilon\) changes the predicted class” — is a nonconvex feasibility problem. Replacing products of activations by a positive-semidefinite moment matrix produces an SDP &lt;em&gt;relaxation&lt;/em&gt; (the same relaxation idea as 04-08, now in the SDP cone of 05-05). Lan, Zheng, and Lomuscio (&lt;em&gt;Tight Neural Network Verification via Semidefinite Relaxations and Linear Reformulations&lt;/em&gt;, &lt;a href=&quot;https://doi.org/10.1609/aaai.v36i7.20689&quot;&gt;AAAI 2022&lt;/a&gt;) combine a layerwise SDP with reformulation-linearization (RLT) cuts and report large gains in certified robustness on MNIST networks (for example, from 0% to 82% certified on a ~10k-node net in their tables). An earlier layer-SDP plus triangle cuts appears in Batten, Kouvaros, Lomuscio, and Zheng (&lt;a href=&quot;https://doi.org/10.24963/ijcai.2021/301&quot;&gt;IJCAI 2021&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;You will not solve ImageNet-scale SDPs in this course. You &lt;em&gt;will&lt;/em&gt; recognize the pattern: a combinatorial or bilinear constraint is replaced by \(X\succeq 0\) plus linear equalities, and a solver for Chapter 05’s SDP class either certifies the property or returns a bound.&lt;/p&gt;

&lt;h2 id=&quot;sparse-recovery-is-still-a-canonical-qp&quot;&gt;Sparse recovery is still a canonical QP&lt;/h2&gt;

&lt;p&gt;Lasso&lt;/p&gt;

\[\min_x \tfrac12\|Ax-b\|_2^2 + \lambda \|x\|_1\]

&lt;p&gt;is the sparse-recovery workhorse in imaging and high-dimensional statistics. In CVXPY it is a few atoms (see 05-07). The &lt;em&gt;science&lt;/em&gt; after 2021 is often &lt;em&gt;unrolling&lt;/em&gt; that QP’s proximal-gradient iteration into a network (Monga, Li, and Eldar, “Algorithm Unrolling,” &lt;a href=&quot;https://doi.org/10.1109/MSP.2020.3016905&quot;&gt;&lt;em&gt;IEEE Signal Processing Magazine&lt;/em&gt;, 2021&lt;/a&gt;) so that step-sizes and dictionaries become trainable. The inner object remains the same QP. If you can write Lasso as a QP with slacks, you can read an unrolled-ISTA paper without new theory.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;P. J. Goulart and Y. Chen, “Clarabel: An interior-point solver for conic programs with quadratic objectives,” arXiv:2405.12762, 2024. &lt;a href=&quot;https://arxiv.org/abs/2405.12762&quot;&gt;arXiv&lt;/a&gt; · &lt;a href=&quot;https://clarabel.org/&quot;&gt;clarabel.org&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;S. Boyd, E. Busseti, S. Diamond, et al., “Multi-Period Trading via Convex Optimization,” &lt;em&gt;Found. Trends Optim.&lt;/em&gt;, 2017. &lt;a href=&quot;https://stanford.edu/~boyd/papers/cvx_portfolio.html&quot;&gt;page&lt;/a&gt; · &lt;a href=&quot;https://www.cvxportfolio.com/&quot;&gt;cvxportfolio&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;J. Lan, Y. Zheng, and A. Lomuscio, “Tight Neural Network Verification via Semidefinite Relaxations and Linear Reformulations,” AAAI 2022. &lt;a href=&quot;https://doi.org/10.1609/aaai.v36i7.20689&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;B. Batten, P. Kouvaros, A. Lomuscio, and Y. Zheng, “Efficient Neural Network Verification via Layer-based Semidefinite Relaxations and Linear Cuts,” IJCAI 2021. &lt;a href=&quot;https://doi.org/10.24963/ijcai.2021/301&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;V. Monga, Y. Li, and Y. C. Eldar, “Algorithm Unrolling: Interpretable, Efficient Deep Learning for Signal and Image Processing,” &lt;em&gt;IEEE SPM&lt;/em&gt; 38(2):18–44, 2021. &lt;a href=&quot;https://doi.org/10.1109/MSP.2020.3016905&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>04-09 Applications and recent developments</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_09_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_09_Applications_Recent</id>
   <content type="html">&lt;p&gt;For decades, convex optimization lived at the &lt;em&gt;end&lt;/em&gt; of a machine-learning pipeline: first you trained a neural network to predict prices or demands, and only afterward did you hand those predictions to a solver to make a decision. Over the last few years, that wall collapsed—by differentiating directly &lt;em&gt;through&lt;/em&gt; the first-order optimality conditions of Chapter 04, an entire convex solver now sits inside PyTorch or JAX as a trainable layer.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-optimality-conditions-to-differentiable-layers&quot;&gt;Key ideas: From Optimality Conditions to Differentiable Layers&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Implicit Function Theorem on KKT/Variational Residuals&lt;/strong&gt;: At a solution \(x^\star(\theta)\) of a parameterized convex program, the optimality condition can be written as a root-finding equation \(F(x^\star(\theta), \theta) = 0\). Differentiating implicitly yields \(\frac{\partial x^\star}{\partial \theta} = -\bigl(D_x F\bigr)^{-1} D_\theta F\), letting backpropagation flow through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;argmin&lt;/code&gt; without unrolling hundreds of solver iterations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Canonicalization and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt;&lt;/strong&gt;: Just as Chapter 04 transforms arbitrary convex programs into standard forms, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cvxpylayers&lt;/code&gt; compiles a Disciplined Parametrized Program (DPP) into a cone program, solves it forward, and differentiates the homogeneous self-dual embedding residual in the backward pass.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nonlinear Least Squares in Robotics (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Theseus&lt;/code&gt;)&lt;/strong&gt;: Vision, SLAM, and motion planning rely on Gauss–Newton and Levenberg–Marquardt updates. Embedding these structured solvers as differentiable layers lets perception networks learn features directly optimized for downstream geometric pose accuracy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Decision-Focused Learning (Predict-Then-Optimize)&lt;/strong&gt;: Minimizing prediction MSE does not necessarily minimize downstream decision cost when predictions enter a constrained LP or QP. Differentiating through convex surrogates (such as SPO+ or quadratic-regularized LPs) aligns the predictor’s gradients with actual operational regret.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-differentiating-through-an-argmin-layer-by-hand&quot;&gt;Worked example: Differentiating Through an Argmin Layer by Hand&lt;/h3&gt;

&lt;p&gt;Consider a 1D parameterized convex optimization layer:
\(x^\star(\theta) = \arg\min_{x \ge 0} \; \frac{1}{2}(x - \theta)^2 + \frac{1}{2}x^2,\)
where \(\theta \in \mathbb{R}\) is the output of an upstream neural network layer.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the first-order optimality condition&lt;/strong&gt;: The objective is \(f(x; \theta) = x^2 - \theta x + \frac{1}{2}\theta^2\) with derivative \(\nabla_x f(x; \theta) = 2x - \theta\). On \(C = [0, \infty)\), optimality requires \(x^\star \ge 0\), \(2x^\star - \theta \ge 0\), and \(x^\star(2x^\star - \theta) = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve for \(x^\star(\theta)\) in closed form&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;If \(\theta &amp;gt; 0\), the constraint \(x \ge 0\) is inactive, so \(2x^\star - \theta = 0 \implies x^\star(\theta) = \frac{\theta}{2}\).&lt;/li&gt;
      &lt;li&gt;If \(\theta \le 0\), the constraint binds and \(x^\star(\theta) = 0\).
Thus \(x^\star(\theta) = \max\!\left(0, \frac{\theta}{2}\right)\)—a scaled ReLU emerging naturally from constrained convex optimization!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the implicit derivative \(\frac{dx^\star}{d\theta}\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;On the active interior (\(\theta &amp;gt; 0\)), the residual is \(F(x, \theta) = 2x - \theta = 0\). Implicit differentiation gives
\(\frac{\partial F}{\partial x} \frac{dx^\star}{d\theta} + \frac{\partial F}{\partial \theta} = 0 \implies 2\frac{dx^\star}{d\theta} - 1 = 0 \implies \frac{dx^\star}{d\theta} = \frac{1}{2}.\)&lt;/li&gt;
      &lt;li&gt;On the boundary region (\(\theta &amp;lt; 0\)), the solution is pinned at \(x^\star(\theta) = 0\), so \(\frac{dx^\star}{d\theta} = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Backpropagate a downstream loss&lt;/strong&gt;: Suppose the downstream task loss is \(L(x^\star) = (x^\star - 3)^2\) and the current prediction is \(\theta = 4\). Forward pass: \(x^\star(4) = 2\), loss \(L = (2 - 3)^2 = 1\). Backward pass: \(\frac{dL}{d\theta} = \frac{dL}{dx^\star}\frac{dx^\star}{d\theta} = 2(2 - 3)\cdot \frac{1}{2} = -1\), telling the upstream network to increase \(\theta\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chapter 04 is the contract of a convex program: variables, objective, constraints, optimality, and the legal rewrites (partial minimization, change of variables, eliminating equalities, slacks, relaxations). The same contract is now a &lt;em&gt;layer&lt;/em&gt; inside a neural net and a &lt;em&gt;loss&lt;/em&gt; for a predictor that will be consumed by a solver. This lesson looks at three 2019–2023 developments that only make sense after you can write “\(0\in\partial f(x^\star)+N_{\mathcal{C}}(x^\star)\)” without flinching.&lt;/p&gt;

&lt;h2 id=&quot;differentiable-convex-layers-and-implicit-optimality&quot;&gt;Differentiable convex layers and implicit optimality&lt;/h2&gt;

&lt;p&gt;Agrawal, Amos, Barratt, Boyd, Diamond, and Kolter (&lt;em&gt;Differentiable Convex Optimization Layers&lt;/em&gt;, &lt;a href=&quot;https://web.stanford.edu/~boyd/papers/diff_cvxpy.html&quot;&gt;NeurIPS 2019&lt;/a&gt;; library &lt;a href=&quot;https://cvxpylayers.org/&quot;&gt;cvxpylayers&lt;/a&gt;) embed a disciplined convex program in a PyTorch or TensorFlow graph. The forward pass &lt;em&gt;solves&lt;/em&gt; the program; the backward pass differentiates the solution map by implicit differentiation through the residual of the solver (an affine-solver-affine factorization they call DPP). The 2019 date is slightly before the requested window; the library is the 2022–2026 default when a paper says “we put a QP in the net.”&lt;/p&gt;

&lt;p&gt;The optimality language is exactly this chapter’s. If \(x^\star(\theta)\) solves a parametrized convex problem, the KKT residual \(F(x,\lambda;\theta)=0\) is an implicit equation. You do not need to unroll projected gradient; you linearize \(F\), as Blondel et al. later automated in JAXopt (&lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/228b9279ecf9bbafe582406850c57115-Abstract-Conference.html&quot;&gt;NeurIPS 2022&lt;/a&gt;). Chapter 04’s first-order condition is the &lt;em&gt;specification&lt;/em&gt; of \(F\).&lt;/p&gt;

&lt;h2 id=&quot;theseus-nonlinear-least-squares-as-a-differentiable-layer&quot;&gt;Theseus: nonlinear least squares as a differentiable layer&lt;/h2&gt;

&lt;p&gt;Not every inner problem is convex. Robotics and 3D vision repeatedly solve nonlinear least squares&lt;/p&gt;

\[\min_x \tfrac12 \sum_i \bigl\| r_i(x;\theta)\bigr\|_2^2\]

&lt;p&gt;with Gauss–Newton or Levenberg–Marquardt. Pineda, Fan, Monge, Venkataraman, Sodhi, Chen, Ortiz, DeTone, Wang, Anderson, Dong, Amos, and Mukadam (&lt;em&gt;Theseus: A Library for Differentiable Nonlinear Optimization&lt;/em&gt;, &lt;a href=&quot;https://arxiv.org/abs/2207.09442&quot;&gt;NeurIPS 2022&lt;/a&gt;; &lt;a href=&quot;https://github.com/facebookresearch/theseus&quot;&gt;facebookresearch/theseus&lt;/a&gt;) ship a PyTorch library that treats that inner solve as a layer: sparse solvers, Lie groups, batching, GPU, and gradients by implicit differentiation or by differentiating the unrolled steps.&lt;/p&gt;

&lt;p&gt;Why it belongs in &lt;em&gt;this&lt;/em&gt; chapter rather than only in a robotics elective: the authors still start from an optimality residual (a stationarity condition for the least-squares objective) and then choose a &lt;em&gt;legal rewrite&lt;/em&gt; — implicit differentiation versus unrolling — exactly the “transformations and change of variables” habit of 04-05. When the inner problem &lt;em&gt;is&lt;/em&gt; convex, prefer cvxpylayers; when it is a structured nonlinear LS, Theseus is the 2022 reference implementation.&lt;/p&gt;

&lt;h2 id=&quot;amortized-optimization-and-convex-surrogates-for-decisions&quot;&gt;Amortized optimization and convex surrogates for decisions&lt;/h2&gt;

&lt;p&gt;Two complementary ideas recycle Chapter 04’s vocabulary.&lt;/p&gt;

&lt;p&gt;Amos (&lt;em&gt;Tutorial on Amortized Optimization&lt;/em&gt;, &lt;a href=&quot;https://doi.org/10.1561/2200000102&quot;&gt;&lt;em&gt;Foundations and Trends in Machine Learning&lt;/em&gt; 16:592–732, 2023&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2202.00665&quot;&gt;arXiv:2202.00665&lt;/a&gt;) surveys &lt;em&gt;learning to optimize&lt;/em&gt;: a network predicts \(x\approx x^\star(\theta)\) for a family of problems that share structure (variational inference, sparse coding, meta-learning, optimal transport, deep equilibrium nets). Amortization does not replace optimality conditions; it &lt;em&gt;approximates the solution map&lt;/em&gt;. You still need the inner problem to be well-posed, and you still debug by looking at residuals.&lt;/p&gt;

&lt;p&gt;Elmachtoub and Grigas (&lt;a href=&quot;https://doi.org/10.1287/mnsc.2020.3922&quot;&gt;&lt;em&gt;Management Science&lt;/em&gt; 2022&lt;/a&gt;) start from a true decision loss that is discontinuous in the predicted cost, then &lt;em&gt;relax&lt;/em&gt; it to a convex surrogate SPO+ derived from duality — a textbook use of 04-08 (relaxation) plus the optimality conditions of a linear program. The feasible set stays the original polyhedron; only the training objective is replaced by something convex in the predictor’s parameters.&lt;/p&gt;

&lt;h2 id=&quot;a-pattern-to-reuse-on-homework&quot;&gt;A pattern to reuse on homework&lt;/h2&gt;

&lt;p&gt;Write the inner problem in standard form, name the rewrite, and name the outer gradient:&lt;/p&gt;

\[\begin{align}
\text{inner:}&amp;amp;\quad x^\star(\theta)\in\arg\min_{x\in\mathcal{C}(\theta)} f(x;\theta),\\
\text{rewrite:}&amp;amp;\quad F(x^\star,\nu^\star;\theta)=0 \quad\text{(KKT / stationarity)},\\
\text{outer:}&amp;amp;\quad \nabla_\theta \ell\bigl(x^\star(\theta)\bigr) \quad\text{via } \nabla_x F,\;\nabla_\theta F.
\end{align}\]

&lt;p&gt;If you cannot write \(F\), you are not ready to differentiate through the solver. If you can write \(F\) but \(\mathcal{C}\) is nonconvex, you are in Theseus / nonlinear LS territory, and global optimality is gone — which is precisely why Chapter 04 spent so many pages on convex solution sets.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;A. Agrawal, B. Amos, S. Barratt, S. Boyd, S. Diamond, and J. Z. Kolter, “Differentiable Convex Optimization Layers,” NeurIPS 2019. &lt;a href=&quot;https://web.stanford.edu/~boyd/papers/diff_cvxpy.html&quot;&gt;page&lt;/a&gt; · &lt;a href=&quot;https://cvxpylayers.org/&quot;&gt;cvxpylayers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;M. Blondel et al., “Efficient and Modular Implicit Differentiation,” NeurIPS 2022. &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/228b9279ecf9bbafe582406850c57115-Abstract-Conference.html&quot;&gt;abstract&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;L. Pineda et al., “Theseus: A Library for Differentiable Nonlinear Optimization,” NeurIPS 2022. &lt;a href=&quot;https://arxiv.org/abs/2207.09442&quot;&gt;arXiv:2207.09442&lt;/a&gt; · &lt;a href=&quot;https://github.com/facebookresearch/theseus&quot;&gt;code&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;B. Amos, “Tutorial on Amortized Optimization,” &lt;em&gt;Found. Trends Mach. Learn.&lt;/em&gt; 16:592–732, 2023. &lt;a href=&quot;https://doi.org/10.1561/2200000102&quot;&gt;DOI&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2202.00665&quot;&gt;arXiv:2202.00665&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;A. N. Elmachtoub and P. Grigas, “Smart ‘Predict, then Optimize’,” &lt;em&gt;Management Science&lt;/em&gt; 2022. &lt;a href=&quot;https://doi.org/10.1287/mnsc.2020.3922&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>03-08 Applications and recent developments</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_08_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_08_Applications_Recent</id>
   <content type="html">&lt;p&gt;Open any deep learning training script and you will find Chapter 03 sitting right at the top of the loss function: cross-entropy is a shifted log-sum-exp (convex in the logits!), temperature scaling calibrates probabilities via a 1D convex problem, and even in deep nonconvex networks, the phenomenon of &lt;em&gt;Neural Collapse&lt;/em&gt; shows that the final classifier layer settles into a clean convex geometry. Understanding convex functions lets you diagnose training stability, smoothness constants, and surrogate losses in modern AI.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-chapter-03-functions-inside-modern-ml&quot;&gt;Key ideas: Chapter 03 Functions Inside Modern ML&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cross-Entropy &amp;amp; Log-Sum-Exp:&lt;/strong&gt; Softmax cross-entropy \(\ell(z, y) = \log\left(\sum_k e^{z_k}\right) - z_y\) is convex and smooth in the logits \(z\), with bounded Hessian curvature that stabilizes gradient updates.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Calibration (Temperature Scaling):&lt;/strong&gt; Post-hoc calibration tunes a single scalar temperature \(T &amp;gt; 0\) to minimize negative log-likelihood—a low-dimensional convex optimization problem with a unique global solution.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Surrogates (Hinge, Logistic, InfoNCE):&lt;/strong&gt; Because 0–1 classification error is discontinuous and nonconvex, ML replaces it with smooth convex upper bounds whose gradients provide informative descent signals.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smoothness &amp;amp; Step-Size Bounds:&lt;/strong&gt; Computing the exact upper bound \(L\) on \(\nabla^2 \ell(z)\) (e.g., \(L = 1/4\) for binary logistic loss) directly dictates the largest stable learning rate \(\alpha \le 1/L\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-convexity-and-exact-smoothness-of-binary-logistic-loss&quot;&gt;Worked example: Convexity and Exact Smoothness of Binary Logistic Loss&lt;/h3&gt;

&lt;p&gt;Analyze the binary logistic loss \(\ell(z) = \log(1 + e^{-z})\) as a function of margin \(z \in \mathbb{R}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;First derivative (gradient):&lt;/strong&gt; Let \(\sigma(z) = \frac{1}{1 + e^{-z}} \in (0, 1)\) be the sigmoid function. Then
\(\ell&apos;(z) = \frac{-e^{-z}}{1 + e^{-z}} = -\frac{1}{1 + e^z} = \sigma(z) - 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second derivative (curvature):&lt;/strong&gt; Using \(\sigma&apos;(z) = \sigma(z)(1 - \sigma(z))\),
\(\ell&apos;&apos;(z) = \sigma(z)(1 - \sigma(z)) &amp;gt; 0 \quad \text{for all } z \in \mathbb{R}.\)
Hence \(\ell(z)\) is &lt;strong&gt;strictly convex&lt;/strong&gt; everywhere!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find the exact Lipschitz smoothness constant \(L = \sup_z \ell&apos;&apos;(z)\):&lt;/strong&gt;
By AM–GM, for any \(p = \sigma(z) \in (0, 1)\), \(p(1 - p) \le \left(\frac{p + (1 - p)}{2}\right)^2 = \frac{1}{4}\), attained at \(z = 0\) (\(\sigma(0) = 0.5\)), where \(\ell(0) = \ln 2 \approx 0.693\), \(\ell&apos;(0) = -0.5\), and \(\ell&apos;&apos;(0) = 0.25\). Therefore \(\ell\) is \(\frac{1}{4}\)-smooth!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Convex functions are the objectives you can trust: a local minimizer is global, and the first-order lower bound \(f(y)\ge f(x)+\nabla f(x)^\top(y-x)\) is a supporting hyperplane of the epigraph. This lesson shows three places where that geometry is still doing work in 2021–2025 machine learning — even when the &lt;em&gt;full&lt;/em&gt; deep network is nonconvex.&lt;/p&gt;

&lt;h2 id=&quot;cross-entropy-log-sum-exp-and-calibration&quot;&gt;Cross-entropy, log-sum-exp, and calibration&lt;/h2&gt;

&lt;p&gt;For a fixed feature map, multiclass logistic regression is convex in the last-layer weights. With logits \(z\in\mathbb{R}^C\) and one-hot label \(y\),&lt;/p&gt;

\[\ell(z,y) = -z_y + \log\sum_{c=1}^C e^{z_c}\]

&lt;p&gt;is convex in \(z\) because log-sum-exp is convex and increasing in each coordinate, and \(-z_y\) is affine. Composition rules from 03-02 are exactly the certificate. Softmax probabilities are \(\nabla\) of log-sum-exp; the conjugate of log-sum-exp is the negative entropy on the simplex (03-03). That is why temperature scaling — replacing \(z\) by \(z/T\) and fitting a single scalar \(T\) on a validation set — is a &lt;em&gt;convex&lt;/em&gt; one-dimensional problem.&lt;/p&gt;

&lt;p&gt;Guo et al. (2017) popularized temperature scaling as a post-hoc calibration map. Minderer, Djolonga, Romijnders, Hubis, Zhai, Houlsby, Tran, and Lucic (&lt;em&gt;Revisiting the Calibration of Modern Neural Networks&lt;/em&gt;, &lt;a href=&quot;https://proceedings.neurips.cc/paper/2021/hash/8420d359404024567b5aefda1231af24-Abstract.html&quot;&gt;NeurIPS 2021&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2106.07998&quot;&gt;arXiv:2106.07998&lt;/a&gt;) re-measured calibration on a large grid of modern image models, including Vision Transformers and MLP-Mixer, and found that several recent non-convolutional architectures are &lt;em&gt;better&lt;/em&gt; calibrated than the overconfident CNNs of the previous generation. The optimization content for this course is smaller than the empirical claim: the loss you already know is convex in the logits, and a one-parameter temperature is a convex recalibration.&lt;/p&gt;

&lt;h2 id=&quot;neural-collapse-when-a-nonconvex-net-meets-a-convex-last-layer&quot;&gt;Neural collapse: when a nonconvex net meets a convex last layer&lt;/h2&gt;

&lt;p&gt;After interpolation, trained classifiers often enter a &lt;em&gt;terminal phase&lt;/em&gt; in which last-layer features collapse to their class means, those means form a simplex ETF, and the classifier aligns with the means (Papyan, Han, and Donoho, &lt;a href=&quot;https://www.pnas.org/doi/10.1073/pnas.2015509117&quot;&gt;PNAS 2020&lt;/a&gt;). Zhu, Ding, Zhou, and coauthors (&lt;a href=&quot;https://papers.nips.cc/paper/2021/hash/f92586a25bb3145facd64ab20fd554ff-Abstract.html&quot;&gt;NeurIPS 2021&lt;/a&gt;) analyzed an unconstrained-feature model that &lt;em&gt;isolates&lt;/em&gt; the last layer: features and classifier weights are free variables, the loss is cross-entropy plus weight decay. In that model the landscape is benign — ETF configurations are the only global minimizers, and other critical points are strict saddles with negative curvature.&lt;/p&gt;

&lt;p&gt;The lesson for Chapter 03 is not “deep nets are convex.” It is that the &lt;em&gt;convex&lt;/em&gt; piece you can name (cross-entropy in the last-layer activations and weights, plus a Euclidean regularizer) already explains a surprising amount of the geometry people measure at the end of training. When a paper says the last layer “collapses,” translate it as: the convex last-layer problem, given free features, wants a highly symmetric configuration.&lt;/p&gt;

&lt;h2 id=&quot;contrastive-losses-and-convex-surrogates&quot;&gt;Contrastive losses and convex surrogates&lt;/h2&gt;

&lt;p&gt;Self-supervised contrastive learning (SimCLR, CLIP, and their successors) typically minimizes an InfoNCE-style loss. For an anchor representation \(u\), a positive \(v_+\), and negatives \(v_1,\ldots,v_K\),&lt;/p&gt;

\[\ell = -\log \frac{e^{u^\top v_+/\tau}}{e^{u^\top v_+/\tau} + \sum_{k=1}^K e^{u^\top v_k/\tau}}.\]

&lt;p&gt;As a function of the &lt;em&gt;similarities&lt;/em&gt; (or of \(u\) with the \(v\)’s held fixed), this is again a log-sum-exp of linear forms, hence convex in \(u\). The overall deep network is not convex, but every inner contrastive head is a convex classification problem on the hypersphere. Wang and Isola (&lt;em&gt;Understanding Contrastive Representation Learning through Alignment and Uniformity&lt;/em&gt;, &lt;a href=&quot;https://proceedings.mlr.press/v119/wang20k.html&quot;&gt;ICML 2020&lt;/a&gt;) decompose the asymptotic InfoNCE objective into an alignment term (pull positives together) and a uniformity term (spread features on the sphere). The 2020 date sits just before the requested window; the same loss is the default in 2022–2026 vision–language models, including the CLIP-style setups against which Lion was later compared (Chapter 06).&lt;/p&gt;

&lt;h2 id=&quot;a-three-line-check-you-can-do-in-numpy&quot;&gt;A three-line check you can do in NumPy&lt;/h2&gt;

&lt;p&gt;Convexity of log-sum-exp is not an abstract slogan. The following snippet checks the Jensen inequality on random logits — the definition from 03-01.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;default_rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;z1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lhs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;rhs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lhs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rhs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If this ever fails on finite floats after the standard max-shift, you have a bug, not a counterexample.&lt;/p&gt;

&lt;h2 id=&quot;what-to-carry-forward&quot;&gt;What to carry forward&lt;/h2&gt;

&lt;p&gt;When you write a loss, ask whether it is convex in the &lt;em&gt;last&lt;/em&gt; argument the solver sees (logits, similarities, linear predictors). If it is, composition rules and conjugates from this chapter apply, even if the feature map in front is a Transformer. Calibration, neural collapse, and contrastive heads are three different stories with the same convex atom: log-sum-exp.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;M. Minderer et al., “Revisiting the Calibration of Modern Neural Networks,” NeurIPS 2021. &lt;a href=&quot;https://proceedings.neurips.cc/paper/2021/hash/8420d359404024567b5aefda1231af24-Abstract.html&quot;&gt;abstract&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2106.07998&quot;&gt;arXiv:2106.07998&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;V. Papyan, X. Y. Han, and D. L. Donoho, “Prevalence of neural collapse…,” &lt;em&gt;PNAS&lt;/em&gt; 2020. &lt;a href=&quot;https://www.pnas.org/doi/10.1073/pnas.2015509117&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Z. Zhu, T. Ding, J. Zhou, et al., “A Geometric Analysis of Neural Collapse with Unconstrained Features,” NeurIPS 2021. &lt;a href=&quot;https://papers.nips.cc/paper/2021/hash/f92586a25bb3145facd64ab20fd554ff-Abstract.html&quot;&gt;abstract&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;T. Wang and P. Isola, “Understanding Contrastive Representation Learning through Alignment and Uniformity,” ICML 2020. &lt;a href=&quot;https://proceedings.mlr.press/v119/wang20k.html&quot;&gt;PMLR&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>02-07 Applications and recent developments</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_07_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_07_Applications_Recent</id>
   <content type="html">&lt;p&gt;Convex sets are not abstract museum pieces—they sit right inside the output layer of every large language model (the probability simplex), inside distributionally robust optimization against data shift (Wasserstein balls), and inside ethical AI systems (fairness polytopes). Whenever a modern ML architecture averages distributions, enforces a robustness radius, or balances competing group metrics, it is exploiting the exact Chapter 02 geometry of convex sets.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-modern-ml-geometry-through-chapter-02&quot;&gt;Key ideas: Modern ML Geometry Through Chapter 02&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Probability Simplex &amp;amp; Softmax:&lt;/strong&gt; The softmax map \(\text{softmax}(z)_i = e^{z_i} / \sum_j e^{z_j}\) maps unconstrained neural network logits \(z \in \mathbb{R}^K\) smoothly into the relative interior of the probability simplex \(\Delta_K\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Wasserstein Ambiguity Balls:&lt;/strong&gt; Distributionally robust optimization (DRO) protects models against distribution shift by hedging over a convex ball of probability distributions centered at the empirical data.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fairness &amp;amp; Resource Polytopes:&lt;/strong&gt; Group fairness constraints (demographic parity, equal opportunity) carve a convex polytope out of the space of randomized classifiers, allowing exact feasibility analysis via linear programming.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometry Drives Tractability:&lt;/strong&gt; Whenever an ML constraint forms a convex set with an efficient projection or separation oracle, we can enforce it provably during training.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-mapping-logits-onto-the-probability-simplex-via-softmax&quot;&gt;Worked example: Mapping Logits onto the Probability Simplex via Softmax&lt;/h3&gt;

&lt;p&gt;Given a 3-class classifier’s raw logit vector \(z = (2, 1, 0)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Exponentiate each logit:&lt;/strong&gt;
\(e^2 \approx 7.389, \qquad e^1 \approx 2.718, \qquad e^0 = 1.000.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Normalize to land inside the relative interior of \(\Delta_3\):&lt;/strong&gt;
\(Z = 7.389 + 2.718 + 1.000 = 11.107,\)
\(p = \text{softmax}(z) = \left(\frac{7.389}{11.107},\; \frac{2.718}{11.107},\; \frac{1.000}{11.107}\right)^T \approx (0.665,\; 0.245,\; 0.090)^T.\)
Check simplex membership: every entry is strictly positive and \(0.665 + 0.245 + 0.090 = 1.000\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify shift invariance (numerical stability trick):&lt;/strong&gt; Subtracting \(\max_i z_i = 2\) gives \(z&apos; = (0, -1, -2)^T\) with \(e^{z&apos;} = (1, 0.368, 0.135)^T\) and sum \(1.503\), producing the identical simplex point \((0.665, 0.245, 0.090)^T\) without risk of floating-point overflow.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A convex set is a feasible region you can &lt;em&gt;average inside&lt;/em&gt;. That geometric fact is why so many modern machine-learning constraints look like simplices, balls, or spectrahedra. This lesson names three families of convex sets that appear in 2022–2025 papers and libraries, each tied to a definition you already have: the probability simplex, a Wasserstein ball of distributions, and a polyhedron cut by fairness (or budget) inequalities.&lt;/p&gt;

&lt;h2 id=&quot;the-probability-simplex-softmax-and-last-layer-geometry&quot;&gt;The probability simplex, softmax, and last-layer geometry&lt;/h2&gt;

&lt;p&gt;The standard simplex&lt;/p&gt;

\[\Delta^{n-1} = \bigl\{ p\in\mathbb{R}^n : p\ge 0,\; \mathbf{1}^\top p = 1\bigr\}\]

&lt;p&gt;is convex (it is the intersection of a hyperplane with the nonnegative orthant). Softmax is a smooth map &lt;em&gt;onto&lt;/em&gt; the relative interior of \(\Delta^{n-1}\). Every attention head in a Transformer, and every multiclass logistic model, therefore spends its last nonlinearity projecting a vector of logits onto a convex set you can draw in \(\mathbb{R}^2\) and \(\mathbb{R}^3\).&lt;/p&gt;

&lt;p&gt;A more surprising simplex appears at the &lt;em&gt;end&lt;/em&gt; of training. Papyan, Han, and Donoho (&lt;em&gt;Prevalence of neural collapse&lt;/em&gt;, &lt;a href=&quot;https://www.pnas.org/doi/10.1073/pnas.2015509117&quot;&gt;PNAS 2020&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2008.08186&quot;&gt;arXiv:2008.08186&lt;/a&gt;) measured a &lt;em&gt;simplex equiangular tight frame&lt;/em&gt; (ETF) among last-layer class means: the centered means form the most symmetric point configuration on a sphere. Zhu, Ding, Zhou, et al. (&lt;em&gt;A Geometric Analysis of Neural Collapse with Unconstrained Features&lt;/em&gt;, &lt;a href=&quot;https://papers.nips.cc/paper/2021/hash/f92586a25bb3145facd64ab20fd554ff-Abstract.html&quot;&gt;NeurIPS 2021&lt;/a&gt;) later showed that, in a simplified unconstrained-feature model with cross-entropy and weight decay, those ETF configurations are the global minimizers and every other critical point is a strict saddle. The convex-set language is not decorative: the ETF is a concrete subset of a sphere, and the probability simplex is the set the classifier actually outputs.&lt;/p&gt;

&lt;p&gt;When you check “is \(C\) convex?” on a homework set, include \(\Delta^{n-1}\) and a Euclidean ball. Those two sets are the geometry of classification and of many regularizers.&lt;/p&gt;

&lt;h2 id=&quot;wasserstein-balls-as-ambiguity-sets&quot;&gt;Wasserstein balls as ambiguity sets&lt;/h2&gt;

&lt;p&gt;Distributionally robust optimization (DRO) replaces a single training distribution \(\hat{P}\) by a &lt;em&gt;set&lt;/em&gt; of distributions, and optimizes against the worst member of that set. The Wasserstein ball&lt;/p&gt;

\[\mathcal{B}_\varepsilon(\hat{P}) = \bigl\{ Q : W_p(Q,\hat{P}) \le \varepsilon\bigr\}\]

&lt;p&gt;is a convex set in the space of probability measures (an optimal-transport ball). Decisions that survive the worst \(Q\in\mathcal{B}_\varepsilon(\hat{P})\) often admit convex finite-dimensional reformulations.&lt;/p&gt;

&lt;p&gt;Two references you can actually open: Gao and Kleywegt, “Distributionally Robust Stochastic Optimization with Wasserstein Distance,” &lt;a href=&quot;https://doi.org/10.1287/moor.2022.1275&quot;&gt;&lt;em&gt;Mathematics of Operations Research&lt;/em&gt; 48(2):603–655, 2023&lt;/a&gt;, prove a strong duality result for Wasserstein DRO and describe the structure of worst-case distributions. Kuhn, Mohajerin Esfahani, Nguyen, and Shafieezadeh-Abadeh’s tutorial &lt;em&gt;Wasserstein Distributionally Robust Optimization&lt;/em&gt; (&lt;a href=&quot;https://doi.org/10.1287/educ.2019.0198&quot;&gt;INFORMS TutORials 2019&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/1908.08729&quot;&gt;arXiv:1908.08729&lt;/a&gt;, revised November 2024) is the readable companion and explicitly connects the ball to classification, regression, and MLE. A broader 2025 survey in &lt;em&gt;Acta Numerica&lt;/em&gt; (&lt;a href=&quot;https://www.cambridge.org/core/journals/acta-numerica/article/distributionally-robust-optimization/5B4E65E3A5A2AEF24E218A6B34E6EAA2&quot;&gt;Kuhn, Shafiee, et al.&lt;/a&gt;) places Wasserstein balls next to other ambiguity sets.&lt;/p&gt;

&lt;p&gt;The modeling move is the same as “replace a point estimate by a convex uncertainty set” in robust linear programming, except the “points” are distributions. If you can certify that \(\mathcal{B}_\varepsilon(\hat{P})\) is convex and that the inner worst-case map is convex in the decision, the outer DRO program is a convex optimization problem of the kind Chapter 04 will formalize.&lt;/p&gt;

&lt;h2 id=&quot;fairness-and-resource-polytopes&quot;&gt;Fairness and resource polytopes&lt;/h2&gt;

&lt;p&gt;Linear inequalities in probabilities define polyhedra. Demographic-parity style constraints of the form&lt;/p&gt;

\[\bigl| \mathbb{E}[h(X)\mid A=a] - \mathbb{E}[h(X)\mid A=a&apos;] \bigr| \le \epsilon\]

&lt;p&gt;cut a polytope in the space of (randomized) classifiers. Agarwal, Beygelzimer, Dudík, Langford, and Wallach (&lt;a href=&quot;https://proceedings.mlr.press/v80/agarwal18a.html&quot;&gt;ICML 2018&lt;/a&gt;) treat those cuts as the feasible set of a reduction; &lt;a href=&quot;https://fairlearn.org/v0.12/user_guide/mitigation/reductions.html&quot;&gt;Fairlearn&lt;/a&gt; still exposes them as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Moment&lt;/code&gt; objects in 2025–2026.&lt;/p&gt;

&lt;p&gt;The same picture covers budget and allocation constraints: \(x\ge 0\), \(\mathbf{1}^\top x = 1\) (a portfolio on the simplex), or \(0\le x\le 1\), \(Ax\le b\) (a knapsack-type media-mix polytope). Separating hyperplanes from later in this chapter are exactly the certificates that a candidate \(x\) is outside such a polytope — the same certificates a solver uses when it returns an infeasible status.&lt;/p&gt;

&lt;h2 id=&quot;a-two-line-picture-to-keep&quot;&gt;A two-line picture to keep&lt;/h2&gt;

&lt;p&gt;Every modern constraint in this lesson is an intersection of convex pieces you can name:&lt;/p&gt;

\[\mathcal{C} = \Delta^{n-1} \cap \{ x : Fx \le g \} \qquad\text{or}\qquad \mathcal{B}_\varepsilon(\hat{P}).\]

&lt;p&gt;If you can prove each piece is convex, the intersection is convex, and every local search that stays in \(\mathcal{C}\) is searching a set without “holes.” That is the entire reason Chapter 02 exists, restated in the language of attention, DRO, and fairness.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;V. Papyan, X. Y. Han, and D. L. Donoho, “Prevalence of neural collapse during the terminal phase of deep learning training,” &lt;em&gt;PNAS&lt;/em&gt; 117(40):24652–24663, 2020. &lt;a href=&quot;https://www.pnas.org/doi/10.1073/pnas.2015509117&quot;&gt;DOI&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2008.08186&quot;&gt;arXiv:2008.08186&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Z. Zhu, T. Ding, J. Zhou, et al., “A Geometric Analysis of Neural Collapse with Unconstrained Features,” NeurIPS 2021. &lt;a href=&quot;https://papers.nips.cc/paper/2021/hash/f92586a25bb3145facd64ab20fd554ff-Abstract.html&quot;&gt;abstract&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;R. Gao and A. J. Kleywegt, “Distributionally Robust Stochastic Optimization with Wasserstein Distance,” &lt;em&gt;Math. Oper. Res.&lt;/em&gt; 48(2):603–655, 2023. &lt;a href=&quot;https://doi.org/10.1287/moor.2022.1275&quot;&gt;DOI&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;D. Kuhn, P. Mohajerin Esfahani, V. A. Nguyen, and S. Shafieezadeh-Abadeh, “Wasserstein Distributionally Robust Optimization,” INFORMS TutORials 2019; arXiv:1908.08729 (rev. 2024). &lt;a href=&quot;https://arxiv.org/abs/1908.08729&quot;&gt;arXiv&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;A. Agarwal et al., “A Reductions Approach to Fair Classification,” ICML 2018. &lt;a href=&quot;https://proceedings.mlr.press/v80/agarwal18a.html&quot;&gt;PMLR&lt;/a&gt; · &lt;a href=&quot;https://fairlearn.org/v0.12/user_guide/mitigation/reductions.html&quot;&gt;Fairlearn&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>01-05 Applications and recent developments</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_05_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_05_Applications_Recent</id>
   <content type="html">&lt;p&gt;A decade ago, “optimization for data science” mostly meant fitting a logistic regression or SVM. Today, the exact same Chapter 01 template—choose \(x \in \mathcal{C}\) to minimize \(f_0(x)\)—governs how frontier labs split trillion-FLOP compute budgets between model size and training tokens (Chinchilla scaling laws), how supply chains train predictive models to minimize &lt;em&gt;downstream decision regret&lt;/em&gt; (SPO+), and how classifiers enforce statistical fairness constraints directly inside the feasible set.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-modern-frontiers-built-on-chapter-01&quot;&gt;Key ideas: Modern Frontiers Built on Chapter 01&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Compute-Optimal Scaling (Constrained ERM):&lt;/strong&gt; Allocates a fixed compute budget \(C \approx 6ND\) across model parameters \(N\) and dataset tokens \(D\) to minimize validation loss.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Predict-Then-Optimize (SPO+):&lt;/strong&gt; Replaces a discontinuous downstream decision loss with a tight convex surrogate so predictive models learn features that matter for the final optimization decision.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fairness as Explicit Constraints:&lt;/strong&gt; Encodes demographic parity or equalized odds as linear/convex constraints on group error rates rather than hoping unconstrained accuracy is fair.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reading Modern Optimization Papers:&lt;/strong&gt; Dissect any new method into four questions: what is \(x\), what is the surrogate \(f_0\), is \(\mathcal{C}\) convex, and what solver matches the problem’s scale?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-a-compute-budget-allocation-problem&quot;&gt;Worked example: Solving a Compute-Budget Allocation Problem&lt;/h3&gt;

&lt;p&gt;Minimize a simplified Chinchilla-style scaling loss \(L(N, D) = 4N^{-0.5} + D^{-0.5}\) subject to a fixed compute budget \(6ND = 600\) (so \(ND = 100\)) with \(N, D &amp;gt; 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Eliminate \(D\) using the compute constraint:&lt;/strong&gt; \(D = \frac{100}{N}\), so \(D^{-0.5} = \frac{N^{0.5}}{10} = 0.1 N^{0.5}\).
The 1D objective in \(N &amp;gt; 0\) becomes:
\(\phi(N) = 4 N^{-0.5} + 0.1 N^{0.5}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Set the derivative to zero:&lt;/strong&gt;
\(\phi&apos;(N) = -2 N^{-1.5} + 0.05 N^{-0.5} = N^{-1.5}(-2 + 0.05 N) = 0 \implies N^* = \frac{2}{0.05} = 40.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recover \(D^*\) and verify optimality:&lt;/strong&gt;
\(D^* = \frac{100}{40} = 2.5.\)
Check the second derivative: \(\phi&apos;&apos;(N) = 3 N^{-2.5} - 0.025 N^{-1.5}\); at \(N^* = 40\), \(\phi&apos;&apos;(40) = 40^{-2.5}(3 - 0.025 \cdot 40) = 2 \cdot 40^{-2.5} &amp;gt; 0\), certifying a global minimum with loss \(L(40, 2.5) = \frac{4}{\sqrt{40}} + \frac{1}{\sqrt{2.5}} = \frac{4 + 4}{\sqrt{40}} = \frac{8}{\sqrt{40}} \approx 1.265\). Notice how at the optimum, the parameter-error term and data-error term are perfectly balanced (\(\approx 0.6325\) each)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chapter 01 defined an optimization problem as “choose \(x\in\mathcal{C}\) to make \(f\) small.” That sentence is now the architecture of industrial data science: train a predictor (often by empirical risk minimization), then use the predictor inside a &lt;em&gt;downstream&lt;/em&gt; decision problem, sometimes with extra constraints that encode fairness or operations limits. This lesson walks through three concrete 2022–2026 settings. The definitions in 01-01 and 01-02 stay as they are; we only change the &lt;em&gt;examples&lt;/em&gt; you should be able to name.&lt;/p&gt;

&lt;h2 id=&quot;large-scale-erm-compute-optimal-language-models&quot;&gt;Large-scale ERM: compute-optimal language models&lt;/h2&gt;

&lt;p&gt;Pretraining a language model is empirical risk minimization on next-token (or masked-token) loss. Write \(N\) for the number of parameters and \(D\) for the number of training tokens. A fixed compute budget \(C\) (FLOPs) roughly satisfies \(C \propto N\cdot D\). The design question is not “is this convex?” — Transformer training is not — but &lt;em&gt;which&lt;/em&gt; \((N,D)\) pair minimizes the loss for that \(C\).&lt;/p&gt;

&lt;p&gt;Hoffmann, Borgeaud, Mensch, Sifre, and colleagues (&lt;em&gt;Training Compute-Optimal Large Language Models&lt;/em&gt;, &lt;a href=&quot;https://proceedings.neurips.cc/paper/2022/hash/c1e2faff6f588870935f114ebe04a3e5-Abstract-Conference.html&quot;&gt;NeurIPS 2022&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2203.15556&quot;&gt;arXiv:2203.15556&lt;/a&gt;) trained more than 400 models and concluded that, for compute-optimal training, model size and token count should scale together: doubling \(N\) should come with doubling \(D\). Their 70B-parameter model Chinchilla, trained on about 1.4T tokens with the same compute as the 280B Gopher model, outperformed Gopher, GPT-3, and other larger-but-undertrained models on a broad suite, including 67.5% on MMLU. DeepMind’s accompanying note is &lt;a href=&quot;https://deepmind.google/blog/an-empirical-analysis-of-compute-optimal-large-language-model-training/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For this course the moral is structural. The &lt;em&gt;form&lt;/em&gt; is still&lt;/p&gt;

\[\min_w \frac{1}{n}\sum_{i=1}^n \ell\bigl(h_w(x_i), y_i\bigr),\]

&lt;p&gt;but the &lt;em&gt;decision variables of the outer design problem&lt;/em&gt; are \(N\) and \(D\), not only \(w\). Convexity is not what makes Chinchilla work; a well-posed optimization &lt;em&gt;question&lt;/em&gt; is.&lt;/p&gt;

&lt;h2 id=&quot;predict-then-optimize-and-the-spo-convex-surrogate&quot;&gt;Predict, then optimize (and the SPO+ convex surrogate)&lt;/h2&gt;

&lt;p&gt;Many analytics pipelines do two jobs in sequence: predict a cost vector \(\hat{c}\) from features, then solve&lt;/p&gt;

\[\min_{z\in\mathcal{Z}} \hat{c}^\top z\]

&lt;p&gt;for a routing, inventory, or portfolio decision \(z\). Training the predictor to minimize squared error on \(c\) can be the wrong objective: a small error in \(\hat{c}\) that flips the optimal vertex of \(\mathcal{Z}\) is worse than a large error that leaves the decision unchanged.&lt;/p&gt;

&lt;p&gt;Elmachtoub and Grigas (&lt;em&gt;Smart “Predict, then Optimize”&lt;/em&gt;, &lt;a href=&quot;https://doi.org/10.1287/mnsc.2020.3922&quot;&gt;Management Science 68(1):9–26, 2022&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/1710.08005&quot;&gt;arXiv:1710.08005&lt;/a&gt;) define an SPO loss that charges the &lt;em&gt;decision&lt;/em&gt; error induced by \(\hat{c}\). That loss is hard to optimize, so they derive a convex surrogate &lt;strong&gt;SPO+&lt;/strong&gt; from duality and prove Fisher consistency under mild conditions. The surrogate applies to any polyhedral, convex, or mixed-integer problem with a linear objective. Their experiments on shortest path and portfolio problems show that a linear model trained with SPO+ can beat a more flexible predictor trained on prediction error when the model is misspecified.&lt;/p&gt;

&lt;p&gt;This is Chapter 01 in miniature: write the &lt;em&gt;true&lt;/em&gt; objective (decision quality), then replace it by a convex program you can actually solve.&lt;/p&gt;

&lt;h2 id=&quot;fairness-as-constrained-optimization&quot;&gt;Fairness as constrained optimization&lt;/h2&gt;

&lt;p&gt;Group-fairness requirements — demographic parity, equalized odds, and their relatives — are &lt;em&gt;constraints&lt;/em&gt; on a classifier, not decorations on a slide. Agarwal, Beygelzimer, Dudík, Langford, and Wallach (&lt;em&gt;A Reductions Approach to Fair Classification&lt;/em&gt;, &lt;a href=&quot;https://proceedings.mlr.press/v80/agarwal18a.html&quot;&gt;ICML 2018&lt;/a&gt;) reduce “minimize error subject to fairness inequalities” to a sequence of cost-sensitive classification problems. The feasible set of (randomized) classifiers that meet the constraints is the object you care about; the reduction finds a low-error point in that set.&lt;/p&gt;

&lt;p&gt;The same reduction is the engine of the maintained &lt;a href=&quot;https://fairlearn.org/&quot;&gt;Fairlearn&lt;/a&gt; library (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExponentiatedGradient&lt;/code&gt; and related &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Moment&lt;/code&gt; constraints; user guide: &lt;a href=&quot;https://fairlearn.org/v0.12/user_guide/mitigation/reductions.html&quot;&gt;reductions&lt;/a&gt;). You will still meet this stack in 2024–2026 course projects and industry fairness reviews. The 2018 paper is older than the 2022–2026 window, but it is the reference the current software cites; treat it as the canonical &lt;em&gt;formulation&lt;/em&gt;, not as a closed research topic.&lt;/p&gt;

&lt;p&gt;A schematic program — not a claim that error and fairness are always convex — is&lt;/p&gt;

\[\begin{align}
\min_h \quad &amp;amp; \widehat{\mathrm{err}}(h) \\
\text{s.t.} \quad &amp;amp; \bigl|\Pr(\hat{Y}=1\mid A=a) - \Pr(\hat{Y}=1\mid A=a&apos;)\bigr| \le \epsilon
\end{align}\]

&lt;p&gt;for a sensitive attribute \(A\). Chapter 02 will tell you when the constraint set is convex; Chapter 04 will tell you why a local solution of a convex restriction is global.&lt;/p&gt;

&lt;h2 id=&quot;how-to-read-an-optimization-for-ds-paper&quot;&gt;How to read an “optimization for DS” paper&lt;/h2&gt;

&lt;p&gt;Ask four questions that this chapter already equipped you to ask. What is the variable? What is the objective that the authors &lt;em&gt;claim&lt;/em&gt; to care about, and what surrogate do they actually minimize? What is the feasible set (box constraints, simplex, fairness inequalities, integer hull)? Is the program convex, and if not, which piece is the convex inner solve? Chinchilla, SPO, and Fairlearn are three different answers to those four questions.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;J. Hoffmann et al., “Training Compute-Optimal Large Language Models,” NeurIPS 2022. &lt;a href=&quot;https://proceedings.neurips.cc/paper/2022/hash/c1e2faff6f588870935f114ebe04a3e5-Abstract-Conference.html&quot;&gt;abstract&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2203.15556&quot;&gt;arXiv:2203.15556&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;A. N. Elmachtoub and P. Grigas, “Smart ‘Predict, then Optimize’,” &lt;em&gt;Management Science&lt;/em&gt; 68(1):9–26, 2022. &lt;a href=&quot;https://doi.org/10.1287/mnsc.2020.3922&quot;&gt;DOI&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/1710.08005&quot;&gt;arXiv:1710.08005&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;A. Agarwal, A. Beygelzimer, M. Dudík, J. Langford, and H. Wallach, “A Reductions Approach to Fair Classification,” ICML 2018. &lt;a href=&quot;https://proceedings.mlr.press/v80/agarwal18a.html&quot;&gt;PMLR&lt;/a&gt; · &lt;a href=&quot;https://fairlearn.org/v0.12/user_guide/mitigation/reductions.html&quot;&gt;Fairlearn reductions&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>00-05 Applications and recent developments</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_05_Applications_Recent/"/>
   <updated>2026-09-16T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_05_Applications_Recent</id>
   <content type="html">&lt;p&gt;It is tempting to treat Chapter 00 as dusty textbook review, yet the biggest breakthroughs in modern AI—reverse-mode automatic differentiation, low-rank adaptation (LoRA) of billion-parameter language models, and score-based diffusion models—are direct applications of the multivariable chain rule, low-rank matrix factorization, and log-density gradients. Mastering these fundamentals means you can read cutting-edge machine learning papers without treating their equations as black boxes.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-where-chapter-00-math-powers-frontier-ai&quot;&gt;Key ideas: Where Chapter 00 Math Powers Frontier AI&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Reverse-Mode AutoDiff &amp;amp; Implicit Gradients:&lt;/strong&gt; Scales the multivariable chain rule to compute \(\nabla f(x) \in \mathbb{R}^n\) in \(O(1)\) forward-pass multiples via vector-Jacobian products (VJPs), and differentiates right through argmin layers using the implicit function theorem.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Low-Rank Matrix Parameterization (LoRA):&lt;/strong&gt; Replaces a dense \(d \times k\) weight update \(\Delta W\) with a rank-\(r\) factor \(BA\) (\(r \ll \min(d, k)\)), cutting memory and optimizer states by orders of magnitude.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Score Functions (\(\nabla_x \log p(x)\)):&lt;/strong&gt; Diffusion models learn the gradient of the log probability density—a vector field pointing toward high-density data regions—bypassing intractable normalizing constants.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conditioning &amp;amp; Numerical Precision:&lt;/strong&gt; Matrix norms, singular values, and Lipschitz bounds govern whether large-scale training stays numerically stable under reduced-precision arithmetic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-lora-compression-ratio-and-forward-pass&quot;&gt;Worked example: LoRA Compression Ratio and Forward Pass&lt;/h3&gt;

&lt;p&gt;Suppose a transformer projection layer has weight matrix \(W_0 \in \mathbb{R}^{4096 \times 4096}\) and we adapt it with rank \(r = 8\) via \(W = W_0 + BA\) where \(B \in \mathbb{R}^{4096 \times 8}\) and \(A \in \mathbb{R}^{8 \times 4096}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compare trainable parameter counts:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Full fine-tuning: \(4096 \times 4096 = 16{,}777{,}216\) parameters.&lt;/li&gt;
      &lt;li&gt;LoRA (\(r = 8\)): \(4096 \times 8 + 8 \times 4096 = 65{,}536\) parameters.&lt;/li&gt;
      &lt;li&gt;Compression factor: \(\frac{16{,}777{,}216}{65{,}536} = 256\times\) fewer trainable parameters (just \(0.390625\%\) of the full matrix).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify a concrete \(2 \times 2\) rank-1 update:&lt;/strong&gt; Let \(W_0 = \begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}\), \(B = \begin{pmatrix} 2 \\ -1 \end{pmatrix}\), \(A = \begin{pmatrix} 1 &amp;amp; 3 \end{pmatrix}\), and input \(x = \begin{pmatrix} 1 \\ 2 \end{pmatrix}\).
    &lt;ul&gt;
      &lt;li&gt;Compute \(Ax = 1(1) + 3(2) = 7\) (a scalar!).&lt;/li&gt;
      &lt;li&gt;Compute \(B(Ax) = 7\begin{pmatrix} 2 \\ -1 \end{pmatrix} = \begin{pmatrix} 14 \\ -7 \end{pmatrix}\).&lt;/li&gt;
      &lt;li&gt;Total output: \(W_0 x + B(Ax) = \begin{pmatrix} 1 \\ 2 \end{pmatrix} + \begin{pmatrix} 14 \\ -7 \end{pmatrix} = \begin{pmatrix} 15 \\ -5 \end{pmatrix}\), matching \((W_0 + BA)x = \begin{pmatrix} 3 &amp;amp; 6 \\ -1 &amp;amp; -2 \end{pmatrix}\begin{pmatrix} 1 \\ 2 \end{pmatrix} = \begin{pmatrix} 15 \\ -5 \end{pmatrix}\) without ever materializing the full \(BA\) matrix.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The calculus, linear algebra, and probability in this chapter are not a warm-up you leave behind. They are the working language of the models you will train after week one. This lesson connects those tools to four developments from roughly 2022–2025 that a data-science student will meet in papers, libraries, and internships. The theory in the earlier lessons does not change; the point is to see &lt;em&gt;where&lt;/em&gt; gradients, low-rank factorizations, and score functions show up in production systems.&lt;/p&gt;

&lt;h2 id=&quot;automatic-differentiation-and-implicit-gradients&quot;&gt;Automatic differentiation and implicit gradients&lt;/h2&gt;

&lt;p&gt;Backpropagation is the chain rule applied to a computation graph. Modern frameworks implement &lt;em&gt;automatic differentiation&lt;/em&gt;: you write a Python function \(f\), and the library returns \(\nabla f\) without a handwritten Jacobian. Blondel and Roulet’s 2024–2025 monograph &lt;em&gt;The Elements of Differentiable Programming&lt;/em&gt; (&lt;a href=&quot;https://arxiv.org/abs/2403.14606&quot;&gt;arXiv:2403.14606&lt;/a&gt;) treats this as a programming model, not a trick: if a program is assembled from differentiable atoms, gradient-based optimization of its parameters is well-defined, including programs with control flow.&lt;/p&gt;

&lt;p&gt;A second, quieter use of Chapter 00 calculus is the &lt;strong&gt;implicit function theorem&lt;/strong&gt;. If a solver returns \(x^\star(\theta)\) defined by an optimality map \(F(x,\theta)=0\) (for example \(\nabla_x L(x,\theta)=0\)), you do &lt;strong&gt;not&lt;/strong&gt; backpropagate through every inner iteration. Differentiating the identity \(F(x^\star(\theta),\theta)=0\) yields the linear system&lt;/p&gt;

\[\nabla_\theta x^\star = - \bigl(\nabla_x F\bigr)^{-1} \nabla_\theta F.\]

&lt;p&gt;Blondel, Berthet, Cuturi, Frostig, Hoyer, Llinares-López, Pedregosa, and Vert implement this as &lt;em&gt;automatic implicit differentiation&lt;/em&gt; in JAXopt (&lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/228b9279ecf9bbafe582406850c57115-Abstract-Conference.html&quot;&gt;NeurIPS 2022&lt;/a&gt;; &lt;a href=&quot;https://github.com/google/jaxopt&quot;&gt;github.com/google/jaxopt&lt;/a&gt;). The user supplies \(F\) in Python; JAX differentiates \(F\) and solves the linear system. Hyperparameter tuning of ridge regression, meta-learning, and optimization layers all reduce to this identity. When you later meet first-order optimality in Chapter 04, reread this paragraph: the same \(\nabla f(x)=0\) condition is what implicit differentiation linearizes.&lt;/p&gt;

&lt;h2 id=&quot;low-rank-updates-lora-as-linear-algebra&quot;&gt;Low-rank updates: LoRA as linear algebra&lt;/h2&gt;

&lt;p&gt;Fine-tuning a large language model by changing every entry of a weight matrix \(W_0\in\mathbb{R}^{d\times k}\) is expensive in memory and in storage of task-specific copies. Hu, Shen, Wallis, Allen-Zhu, Li, Wang, Wang, and Chen (&lt;em&gt;LoRA&lt;/em&gt;, &lt;a href=&quot;https://openreview.net/forum?id=nZeVKeeFYf9&quot;&gt;ICLR 2022&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2106.09685&quot;&gt;arXiv:2106.09685&lt;/a&gt;) freeze \(W_0\) and learn a rank-\(r\) correction&lt;/p&gt;

\[W = W_0 + BA, \qquad B\in\mathbb{R}^{d\times r},\; A\in\mathbb{R}^{r\times k},\; r\ll \min(d,k).\]

&lt;p&gt;The number of trainable parameters drops from \(dk\) to \(r(d+k)\). On GPT-3-scale models the paper reports order-of-magnitude reductions in trainable parameters with no extra inference latency, because \(B\) and \(A\) can be merged into \(W\) after training. The linear-algebra content of Chapter 00 is exactly what makes the claim checkable: rank, matrix multiplication cost, and the idea that a structured update can live in a thin subspace. Adapter libraries you will see in Hugging Face (PEFT) are this factorization plus engineering.&lt;/p&gt;

&lt;h2 id=&quot;score-matching-and-diffusion-models&quot;&gt;Score matching and diffusion models&lt;/h2&gt;

&lt;p&gt;A generative model that samples images by gradually denoising Gaussian noise is, at heart, a probability exercise. Let \(p_t\) be a family of smoothed densities and let \(s_\theta(x,t)\) approximate the &lt;em&gt;score&lt;/em&gt; \(\nabla_x \log p_t(x)\). Training minimizes a weighted regression on scores; sampling integrates an ordinary differential (or stochastic differential) equation driven by \(s_\theta\). Karras, Aittala, Aila, and Laine (&lt;em&gt;Elucidating the Design Space of Diffusion-Based Generative Models&lt;/em&gt;, &lt;a href=&quot;https://proceedings.neurips.cc/paper/2022/hash/a98846e9d9cc01cfb87eb694d946ce6b-Abstract-Conference.html&quot;&gt;NeurIPS 2022&lt;/a&gt;; &lt;a href=&quot;https://arxiv.org/abs/2206.00364&quot;&gt;arXiv:2206.00364&lt;/a&gt;; code &lt;a href=&quot;https://github.com/NVlabs/edm&quot;&gt;NVlabs/edm&lt;/a&gt;) rewrite several popular diffusion recipes as one design space: preconditioning of the network, the noise schedule, and the sampler. Their class-conditional CIFAR-10 FID of \(1.79\) with 35 network evaluations became a standard reference implementation.&lt;/p&gt;

&lt;p&gt;What you need from Chapter 00 is modest and precise: the gradient of a log-density, the Gaussian family, and the fact that an ODE/SDE is a calculus object. You do not need the full stochastic-analysis machinery to see why “predict the noise, then take an Euler step” is a numerical method for a score field.&lt;/p&gt;

&lt;h2 id=&quot;a-compact-numerical-check-lora-shapes&quot;&gt;A compact numerical check (LoRA shapes)&lt;/h2&gt;

&lt;p&gt;The following snippet does not train a Transformer; it only checks that a low-rank factorization has the parameter count the LoRA paper advertises. Run it after you review matrix multiplication in 00-02.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4096&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4096&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;full&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lora&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;full params:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;LoRA params:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lora&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ratio:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lora&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;W0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;W&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;W0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;W shape:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rank bound:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;what-to-carry-forward&quot;&gt;What to carry forward&lt;/h2&gt;

&lt;p&gt;When a paper says “we differentiate through the KKT map,” “we inject a rank-\(r\) adapter,” or “we match the score of a Gaussian perturbation,” it is speaking Chapter 00. The later chapters add convexity, canonical forms, and algorithms; they do not replace derivatives, factorizations, or densities.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;M. Blondel and V. Roulet, &lt;em&gt;The Elements of Differentiable Programming&lt;/em&gt;, arXiv:2403.14606, 2024 (rev. 2025). &lt;a href=&quot;https://arxiv.org/abs/2403.14606&quot;&gt;https://arxiv.org/abs/2403.14606&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;M. Blondel et al., “Efficient and Modular Implicit Differentiation,” NeurIPS 2022. &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/228b9279ecf9bbafe582406850c57115-Abstract-Conference.html&quot;&gt;paper&lt;/a&gt; · &lt;a href=&quot;https://github.com/google/jaxopt&quot;&gt;JAXopt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;E. J. Hu et al., “LoRA: Low-Rank Adaptation of Large Language Models,” ICLR 2022. &lt;a href=&quot;https://openreview.net/forum?id=nZeVKeeFYf9&quot;&gt;OpenReview&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2106.09685&quot;&gt;arXiv:2106.09685&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;T. Karras, M. Aittala, T. Aila, and S. Laine, “Elucidating the Design Space of Diffusion-Based Generative Models,” NeurIPS 2022. &lt;a href=&quot;https://proceedings.neurips.cc/paper/2022/hash/a98846e9d9cc01cfb87eb694d946ce6b-Abstract-Conference.html&quot;&gt;abstract&lt;/a&gt; · &lt;a href=&quot;https://arxiv.org/abs/2206.00364&quot;&gt;arXiv:2206.00364&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>29-03 ADMM so với song song dữ liệu và FedAvg</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter29/29_03_admm_vs_federated/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter29/29_03_admm_vs_federated</id>
   <content type="html">&lt;p&gt;Nếu bạn đã học Chương 21 (ADMM đồng thuận) và vừa học xong Bài 29-02 (FedAvg), một câu hỏi cực kỳ sắc sảo sẽ lập tức nảy ra trong đầu: &lt;em&gt;cả hai đều giải bài toán tổng \(\sum_{p=1}^P f_p(w)\) trên nhiều máy tính tách biệt rồi lấy trung bình về biến toàn cục — vậy thực chất chúng giống và khác nhau ở đâu, và tại sao ADMM không bị hiện tượng “trôi cục bộ” như FedAvg?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Câu trả lời gói gọn trong đúng &lt;strong&gt;một thành phần bị thiếu ở FedAvg nhưng luôn hiện diện ở ADMM&lt;/strong&gt;: &lt;strong&gt;biến đối ngẫu cục bộ \(u_p\)&lt;/strong&gt;! Nhờ duy trì lực bù đối ngẫu \(u_p\) tại mỗi nút để cân bằng chính xác gradient cục bộ \(\nabla f_p(z^\star)\), ADMM đồng thuận hội tụ về đúng nghiệm toàn cục không chút sai lệch ngay cả khi dữ liệu các nút khác nhau hoàn toàn — đổi lại nó đòi hỏi tính lồi và lưu trữ trạng thái đối ngẫu trên từng nút, điều khó làm khi có hàng triệu điện thoại di động chập chờn.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-phân-biệt-admm-data-parallel-sgd-và-fedavg&quot;&gt;Kiến thức cần nhớ: Ba trụ cột phân biệt ADMM, Data-Parallel SGD và FedAvg&lt;/h2&gt;

&lt;p&gt;Bảng so sánh trong bài trở nên cực kỳ dễ nhớ khi bạn đối chiếu ba phương pháp qua ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trạng thái cục bộ (Stateful Dual vs. Stateless Clients):&lt;/strong&gt; ADMM là thuật toán &lt;em&gt;có trạng thái&lt;/em&gt; — mỗi nút \(p\) phải giữ biến đối ngẫu \(u_p\) qua mọi vòng để nhớ độ lệch riêng của mình. Ngược lại, FedAvg &lt;em&gt;không cần trạng thái máy khách&lt;/em&gt; (stateless), rất phù hợp với kịch bản &lt;em&gt;cross-device&lt;/em&gt; nơi mỗi điện thoại chỉ tham gia vài lần rồi biến mất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lớp bài toán và Cấu trúc hàm mục tiêu:&lt;/strong&gt; ADMM phát huy sức mạnh tối đa trên bài toán &lt;strong&gt;lồi có cấu trúc&lt;/strong&gt; (Lasso phân tán, quy hoạch bậc hai, ràng buộc cứng giữa các nút), nơi bước con proximal giải được chính xác. Data-Parallel SGD và FedAvg sinh ra cho &lt;strong&gt;mạng nơ-ron sâu phi lồi&lt;/strong&gt; hàng triệu tham số, nơi chỉ có thể chạy vài bước SGD xấp xỉ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Môi trường hạ tầng (Data Center vs. Cross-Silo vs. Cross-Device):&lt;/strong&gt; Data-Parallel SGD thống trị cụm GPU tốc độ cao; ADMM và các biến thể có trạng thái (như SCAFFOLD) tỏa sáng trong liên kết liên tổ chức (&lt;em&gt;cross-silo&lt;/em&gt;, ví dụ 10–50 bệnh viện ổn định); còn FedAvg là chuẩn mực cho hàng triệu thiết bị biên (&lt;em&gt;cross-device&lt;/em&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-cách-biến-đối-ngẫu-admm-triệt-tiêu-100-lỗi-trôi-cục-bộ&quot;&gt;Giải thích: Tính tay cách biến đối ngẫu ADMM triệt tiêu 100% lỗi trôi cục bộ!&lt;/h3&gt;

&lt;p&gt;Hãy mang đúng ví dụ 2 máy khách non-IID từ Bài 29-02 (nơi FedAvg bị trôi vĩnh viễn về \(2.0\) thay vì nghiệm đúng \(z^\star = 3.0\)!) sang giải bằng &lt;strong&gt;ADMM đồng thuận&lt;/strong&gt;:&lt;/p&gt;

\[\min_{x_1, x_2, z}\ \underbrace{\frac{1}{2}x_1^2}_{F_1(x_1)} + \underbrace{\frac{3}{2}(x_2 - 4)^2}_{F_2(x_2)} \qquad \text{thỏa mãn } x_1 = z,\quad x_2 = z.\]

&lt;p&gt;Lagrangian tăng cường của ADMM cho mỗi nút \(p \in \{1, 2\}\) có dạng \(F_p(x_p) + u_p(x_p - z) + \frac{\rho}{2}(x_p - z)^2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện cân bằng tại nghiệm đúng \(x_1 = x_2 = z^\star = 3.0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại nút 1: \(\nabla F_1(3) + u_1^\star = 0 \implies 3 + u_1^\star = 0 \implies u_1^\star = -3\).&lt;/li&gt;
      &lt;li&gt;Tại nút 2: \(\nabla F_2(3) + u_2^\star = 0 \implies 3(3 - 4) + u_2^\star = 0 \implies u_2^\star = +3\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra điều kiện đối ngẫu toàn cục cho \(z\): \(u_1^\star + u_2^\star = -3 + 3 = 0\) (thỏa mãn tuyệt đối!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử cho mỗi nút giải CHÍNH XÁC bài toán cục bộ ADMM (\(E \to \infty\)) từ \(z = 3.0\) với \(u_1^\star = -3, u_2^\star = +3\) và \(\rho = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Nút 1 cực tiểu hóa&lt;/em&gt; \(\frac{1}{2}x_1^2 - 3(x_1 - 3) + \frac{1}{2}(x_1 - 3)^2\):
Đạo hàm bằng \(0 \implies x_1 - 3 + (x_1 - 3) = 0 \implies x_1 = 3.0\)!&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Nút 2 cực tiểu hóa&lt;/em&gt; \(\frac{3}{2}(x_2 - 4)^2 + 3(x_2 - 3) + \frac{1}{2}(x_2 - 3)^2\):
Đạo hàm bằng \(0 \implies 3(x_2 - 4) + 3 + (x_2 - 3) = 4x_2 - 12 = 0 \implies x_2 = 3.0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm vỡ òa:&lt;/strong&gt; Nhờ biến đối ngẫu \(u_1 = -3\) kéo nút 1 sang phải và \(u_2 = +3\) kéo nút 2 sang trái, cả hai nút &lt;strong&gt;đứng im chính xác tại \(3.0\) với 0% trôi cục bộ&lt;/strong&gt;! Đây chính là bản chất sâu sắc phân tách ADMM với FedAvg!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href=&quot;/contents/vi/chapter21/&quot;&gt;Chương 21&lt;/a&gt; đã trình bày &lt;strong&gt;phương pháp hướng luân phiên của các nhân tử (ADMM)&lt;/strong&gt;. Dạng đồng thuận giải bài toán:&lt;/p&gt;

\[\min_{x_1,\ldots,x_P,z} \sum_{p=1}^P f_p(x_p) \quad\text{subject to}\quad x_p=z,\]

&lt;p&gt;thông qua hàm Lagrangian tăng cường: cập nhật các biến gốc cục bộ \(x_p\) (thường dưới dạng toán tử proximal), lấy trung bình cập nhật biến toàn cục \(z\), và cập nhật biến đối ngẫu theo phần dư. Khi mỗi \(f_p\) lồi và các bước con được giải đủ chính xác, ADMM có lý thuyết hội tụ hoàn chỉnh và là công cụ chuẩn mực cho các bài toán tách &lt;strong&gt;lồi có cấu trúc&lt;/strong&gt; (Lasso phân tán, quy hoạch bậc hai đồng thuận, một số bài toán nới lỏng SDP).&lt;/p&gt;

&lt;p&gt;Ngược lại, SGD song song dữ liệu và FedAvg được thiết kế cho bối cảnh khác hẳn:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tiêu chí&lt;/th&gt;
      &lt;th&gt;ADMM (Ch. 21)&lt;/th&gt;
      &lt;th&gt;SGD song song dữ liệu&lt;/th&gt;
      &lt;th&gt;FedAvg&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Hàm mục tiêu \(f\) điển hình&lt;/td&gt;
      &lt;td&gt;lồi, thường có cấu trúc hợp thành&lt;/td&gt;
      &lt;td&gt;ERM không lồi / mạng sâu&lt;/td&gt;
      &lt;td&gt;không lồi, ERM cục bộ &lt;em&gt;không đồng nhất&lt;/em&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đại lượng lấy trung bình&lt;/td&gt;
      &lt;td&gt;biến gốc \(z\) và biến đối ngẫu&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;gradient&lt;/strong&gt; (hoặc trọng số đồng bộ) mỗi bước&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;trọng số&lt;/strong&gt; sau \(E\) bước cục bộ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Biến đối ngẫu&lt;/td&gt;
      &lt;td&gt;có, phần dư thúc đẩy đồng thuận&lt;/td&gt;
      &lt;td&gt;không&lt;/td&gt;
      &lt;td&gt;không&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tài nguyên khan hiếm&lt;/td&gt;
      &lt;td&gt;số vòng lặp của bài toán lồi cỡ vừa&lt;/td&gt;
      &lt;td&gt;băng thông kết nối liên nút mỗi bước&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;số vòng truyền thông&lt;/strong&gt; (thiết bị gián đoạn, Wi-Fi)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tiêu chí chứng nhận&lt;/td&gt;
      &lt;td&gt;khoảng cách đối ngẫu / phần dư&lt;/td&gt;
      &lt;td&gt;không (bài toán không lồi)&lt;/td&gt;
      &lt;td&gt;không&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Gọi FedAvg là “ADMM bỏ biến đối ngẫu” dễ làm mờ đi sự khác biệt bản chất: FedAvg &lt;em&gt;chủ động&lt;/em&gt; cho phép các máy khách chạy nhiều bước cục bộ và chấp nhận độ trôi trước khi trung bình hóa tham số, trong khi ADMM &lt;em&gt;phạt trực tiếp&lt;/em&gt; sự sai lệch giữa các nút qua biến đối ngẫu ở mọi vòng lặp. Nên dùng ADMM khi bài toán viết được dưới dạng đồng thuận lồi và cần theo dõi phần dư; dùng SGD song song dữ liệu khi huấn luyện mô hình lớn trên cụm máy chủ tập trung; và dùng FedAvg khi dữ liệu phải ở lại thiết bị đầu cuối còn chi phí truyền thông là nút thắt chính.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài thực hành.&lt;/strong&gt; Với 3 máy khách chia nhau dữ liệu của một bài toán hồi quy logistic lồi, hãy giải cùng bài toán bằng (i) ADMM đồng thuận và (ii) FedAvg với \(E\in\{1,5\}\), sau đó so sánh hàm mất mát huấn luyện theo &lt;em&gt;số vòng truyền thông&lt;/em&gt; thay vì theo số lượt tính gradient cục bộ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Trong những tình huống nào một phương pháp không cần phép chiếu hoặc phương pháp tách biến (như Frank–Wolfe hay ADMM) vẫn có thể vượt trội hơn SGD song song dữ liệu trên cùng một cụm tính toán?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>29-02 FedAvg</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter29/29_02_fedavg/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter29/29_02_fedavg</id>
   <content type="html">&lt;p&gt;Năm 2017, khi Google muốn cải thiện mô hình gợi ý từ gõ trên bàn phím điện thoại Android (Gboard) của hàng trăm triệu người dùng mà &lt;strong&gt;tuyệt đối không được tải tin nhắn cá nhân lên máy chủ&lt;/strong&gt;, Brendan McMahan và cộng sự đã đề xuất một thuật toán cực kỳ thanh lịch: &lt;strong&gt;Federated Averaging (FedAvg)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Thay vì gom dữ liệu về mô hình, FedAvg mang mô hình xuống tận từng chiếc điện thoại, để mỗi máy tự chạy \(E\) epoch SGD trên dữ liệu riêng của mình, rồi gửi trọng số đã cập nhật về máy chủ lấy trung bình có trọng số. Mọi thứ nghe hoàn hảo — cho đến khi dữ liệu giữa các người dùng &lt;strong&gt;không đồng nhất (non-IID)&lt;/strong&gt; (ví dụ bệnh viện A chuyên bệnh nhi, bệnh viện B chuyên lão khoa). Lúc này một hiện tượng tinh vi và cực kỳ quan trọng xuất hiện: &lt;strong&gt;trôi cục bộ (client drift)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-phân-tích-thuật-toán-fedavg&quot;&gt;Kiến thức cần nhớ: Ba trụ cột phân tích thuật toán FedAvg&lt;/h2&gt;

&lt;p&gt;Để hiểu vì sao FedAvg vừa thành công vang dội vừa cần các bản nâng cấp ở Bài 29-04, hãy nắm ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bốn bước vòng đời một vòng truyền thông FedAvg:&lt;/strong&gt; (1) Lấy mẫu tập con máy khách \(\mathcal{S}_t\) đang rảnh; (2) Phát tán trọng số toàn cục \(w_t\); (3) Mỗi máy chạy \(E\) epoch SGD cục bộ; (4) Tổng hợp trung bình có trọng số \(w_{t+1} = \sum_{c \in \mathcal{S}_t} \frac{n_c}{n_{\mathcal{S}_t}} w_{t+1}^{(c)}\) để bảo toàn đúng tỷ lệ cỡ mẫu của mục tiêu ERM toàn cục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiện tượng Trôi cục bộ (Client Drift) dưới dữ liệu Non-IID:&lt;/strong&gt; Ngay cả khi máy chủ khởi đầu từ &lt;strong&gt;đúng nghiệm tối ưu toàn cục \(w^\star\)&lt;/strong&gt;, vì gradient cục bộ \(\nabla F_c(w^\star) \neq 0\) trên từng máy khách, sau \(E &amp;gt; 1\) bước cục bộ mỗi máy sẽ kéo trọng số về phía cực tiểu riêng \(w_c^\star\) của mình — và trung bình của các cực tiểu cục bộ &lt;strong&gt;không hề trùng với cực tiểu toàn cục&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh đổi giữa số bước cục bộ \(E\) và tốc độ học \(\eta\):&lt;/strong&gt; Tăng \(E\) giúp giảm số vòng truyền thông, nhưng làm trầm trọng thêm client drift; do đó lý thuyết hội tụ của FedAvg dưới dữ liệu non-IID đòi hỏi giảm tốc độ học cục bộ \(\eta\) (hoặc dùng thêm số hạng neo/biến kiểm soát như FedProx, SCAFFOLD).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-hiện-tượng-trôi-cục-bộ--fedavg-tự-đi-chệch-khỏi-nghiệm-tối-ưu-toàn-cục&quot;&gt;Giải thích: Tính tay hiện tượng Trôi cục bộ — FedAvg tự đi chệch khỏi nghiệm tối ưu toàn cục!&lt;/h3&gt;

&lt;p&gt;Xét hệ thống gồm 2 máy khách có cùng số mẫu (\(n_1 = n_2 = 50\)) nhưng phân phối dữ liệu khác nhau (non-IID), tương ứng với hai hàm mất mát cục bộ có độ cong khác nhau:&lt;/p&gt;

\[F_1(w) = \frac{1}{2}w^2 \quad (\text{đáy riêng } w_1^\star = 0), \qquad F_2(w) = \frac{3}{2}(w - 4)^2 \quad (\text{đáy riêng } w_2^\star = 4).\]

&lt;p&gt;Mục tiêu toàn cục là trung bình cộng \(F(w) = \frac{1}{2}\bigl[F_1(w) + F_2(w)\bigr]\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tìm nghiệm tối ưu toàn cục thực sự \(w^\star\):&lt;/strong&gt;
\(\nabla F(w) = \frac{1}{2}\bigl[w + 3(w - 4)\bigr] = 2w - 6 = 0 \implies w^\star = 3.0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử chạy FedAvg xuất phát NGAY TẠI nghiệm tối ưu \(w_t = 3.0\) với \(E = 2\) bước cục bộ (\(\eta = 0.25\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Máy khách 1 (\(\nabla F_1(w) = w\)):&lt;/em&gt;
        &lt;ul&gt;
          &lt;li&gt;Bước 1: \(3.0 - 0.25(3.0) = 2.25\).&lt;/li&gt;
          &lt;li&gt;Bước 2: \(2.25 - 0.25(2.25) = 1.6875\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Máy khách 2 (\(\nabla F_2(w) = 3(w - 4)\)):&lt;/em&gt;
        &lt;ul&gt;
          &lt;li&gt;Bước 1: \(3.0 - 0.25\cdot 3(3.0 - 4) = 3.0 + 0.75 = 3.75\).&lt;/li&gt;
          &lt;li&gt;Bước 2: \(3.75 - 0.25\cdot 3(3.75 - 4) = 3.75 + 0.1875 = 3.9375\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Máy chủ lấy trung bình:&lt;/em&gt;
\(w_{t+1} = \frac{1.6875 + 3.9375}{2} = 2.8125 \neq 3.0!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thậm chí nếu cho \(E \to \infty\) (mỗi máy giải chính xác bài toán cục bộ):&lt;/strong&gt;
Máy 1 đi về \(0\), Máy 2 đi về \(4\), và trung bình FedAvg dừng mãi ở \(\frac{0 + 4}{2} = 2.0\) — &lt;strong&gt;lệch vĩnh viễn \(1.0\) đơn vị&lt;/strong&gt; so với nghiệm đúng \(w^\star = 3.0\)! Phép tính ngắn này bóc trần bản chất toán học của &lt;em&gt;client drift&lt;/em&gt; và lý giải tại sao ở Bài 29-03 và 29-04 ta cần biến đối ngẫu (ADMM) hoặc biến kiểm soát (SCAFFOLD)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thuật toán &lt;strong&gt;Trung bình liên kết (Federated Averaging — FedAvg)&lt;/strong&gt; của McMahan, Moore, Ramage, Hampson và y Arcas (AISTATS 2017) lặp lại ba bước sau qua từng vòng truyền thông \(t\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Máy chủ gửi bản sao mô hình toàn cục hiện tại \(w_t\) tới một tập con máy khách \(\mathcal{S}_t\).&lt;/li&gt;
  &lt;li&gt;Mỗi máy khách \(c\in\mathcal{S}_t\) chạy \(E\) epoch SGD cục bộ trên tập dữ liệu &lt;em&gt;riêng&lt;/em&gt; của mình, thu được tham số \(w_{t+1}^{(c)}\).&lt;/li&gt;
  &lt;li&gt;Máy chủ tổng hợp mô hình mới bằng trung bình có trọng số theo số lượng mẫu:&lt;/li&gt;
&lt;/ol&gt;

\[w_{t+1} = \sum_{c\in\mathcal{S}_t} \frac{n_c}{n_{\mathcal{S}_t}} w_{t+1}^{(c)},\]

&lt;p&gt;trong đó \(n_c\) là số mẫu dữ liệu của máy khách \(c\) và \(n_{\mathcal{S}_t}=\sum_{c\in\mathcal{S}_t}n_c\).&lt;/p&gt;

&lt;p&gt;Khi \(E=1\) và mỗi máy khách chỉ đi đúng một bước trên lô dữ liệu đồng bộ, FedAvg quy về SGD song song dữ liệu tiêu chuẩn. Trường hợp thực tế thú vị và khó phân tích hơn là \(E&amp;gt;1\) kết hợp với phân phối dữ liệu &lt;strong&gt;không đồng nhất (non-IID)&lt;/strong&gt; giữa các máy khách, làm xuất hiện hiện tượng trôi cục bộ (client drift). Khi đó, số vòng truyền thông trở thành thước đo chi phí quan trọng nhất.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fedavg_round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client_models&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client_sizes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client_sizes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_c&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client_models&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client_sizes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_c&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Vì sao huấn luyện trực tiếp trên thiết bị?&lt;/strong&gt; Động lực đến từ yêu cầu quyền riêng tư, quy định pháp lý và giới hạn băng thông: không thể tải toàn bộ ảnh hay dữ liệu cá nhân trên hàng triệu thiết bị về trung tâm dữ liệu. Tuy nhiên, cần lưu ý FedAvg chỉ là một &lt;em&gt;mô hình triển khai&lt;/em&gt; chứ không tự cung cấp bảo đảm quyền riêng tư chặt chẽ vì gradient và trọng số chia sẻ vẫn có thể làm rò rỉ thông tin; các cơ chế bảo mật hình thức như DP-SGD hay tổng hợp an toàn (secure aggregation) thuộc phạm vi chuyên đề riêng.&lt;/p&gt;

&lt;h3 id=&quot;fedavg-và-hiện-tượng-trôi-trong-khoảng-3-phút&quot;&gt;FedAvg và hiện tượng trôi trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/fedavg-drift_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Ba máy khách với hàm bậc hai khác nhau: E = 1 chính là GD, E = 5 và E = 20 tiết kiệm vòng giao tiếp nhưng trôi khỏi w*.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Chia một tập con MNIST (hoặc hỗn hợp Gaussian 2 chiều) cho 3 máy khách sao cho mỗi máy khách chỉ sở hữu dữ liệu của một lớp riêng biệt. Chạy FedAvg với \(E=1\) so với \(E=5\) và quan sát sự dao động của mô hình toàn cục khi các bước cập nhật cục bộ quá khớp vào lớp dữ liệu riêng của từng máy khách.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>29-01 SGD song song dữ liệu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter29/29_01_data_parallel_sgd/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter29/29_01_data_parallel_sgd</id>
   <content type="html">&lt;p&gt;Khi bạn huấn luyện một mạng thị giác hay mô hình ngôn ngữ trên 8, 64 hay 1.024 chiếc GPU cùng lúc bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DistributedDataParallel&lt;/code&gt; (DDP) của PyTorch, điều gì thực sự diễn ra sau dòng lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;loss.backward()&lt;/code&gt;? Về mặt toán học, &lt;strong&gt;SGD song song dữ liệu đồng bộ&lt;/strong&gt; giản dị đến bất ngờ: chia lô dữ liệu lớn thành \(P\) phần nhỏ cho \(P\) máy tính gradient song song, rồi lấy trung bình cộng lại — kết quả &lt;strong&gt;trùng khớp 100%&lt;/strong&gt; với việc chạy SGD trên một chiếc máy khổng lồ duy nhất có kích thước lô \(PB\)!&lt;/p&gt;

&lt;p&gt;Sự khác biệt quyết định thành bại lại nằm ở tầng &lt;em&gt;giao thức truyền thông&lt;/em&gt;: nếu tất cả \(P\) máy đều gửi gradient về một &lt;strong&gt;Máy chủ tham số (Parameter Server)&lt;/strong&gt; trung tâm, chiếc máy chủ đó sẽ tắc nghẽn ngay khi \(P\) tăng lên; còn với giao thức &lt;strong&gt;Ring All-Reduce&lt;/strong&gt;, các GPU nối thành một vòng tròn chuyền từng lát dữ liệu cho nhau, giúp lượng dữ liệu mỗi GPU phải truyền &lt;strong&gt;hầu như không tăng dù bạn gắn thêm hàng trăm GPU&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-sgd-song-song-dữ-liệu&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của SGD song song dữ liệu&lt;/h2&gt;

&lt;p&gt;Để hiểu cả tính tương đương toán học lẫn nút thắt hạ tầng của huấn luyện đa GPU, hãy nắm ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tương đương toán học với Minibatch lớn \(PB\):&lt;/strong&gt; Nhờ tính tuyến tính của đạo hàm và phép lấy trung bình, \(\frac{1}{P}\sum_{p=1}^P \left(\frac{1}{B}\sum_{i \in \mathcal{B}_{k,p}} \nabla f_i(w_k)\right) = \frac{1}{PB}\sum_{i \in \mathcal{B}_k} \nabla f_i(w_k)\). Tuy nhiên, tăng \(P\) làm tăng kích thước lô tổng \(PB\), nên ta phải điều chỉnh tốc độ học (linear scaling rule + warmup) và lưu ý giới hạn kích thước lô tới hạn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parameter Server vs. Ring All-Reduce:&lt;/strong&gt; Trong Parameter Server, máy chủ trung tâm chịu tải truyền thông tỉ lệ thuận với \(P\) (điểm nghẽn cổ chai). Trong Ring All-Reduce (pha &lt;em&gt;reduce-scatter&lt;/em&gt; + pha &lt;em&gt;all-gather&lt;/em&gt;), mỗi GPU chỉ gửi và nhận tổng cộng \(2\frac{P-1}{P}M &amp;lt; 2M\) byte — &lt;strong&gt;độc lập với \(P\)&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đồng bộ (Synchronous) vs. Bất đồng bộ (Asynchronous / Hogwild!):&lt;/strong&gt; Đồng bộ đảm bảo gradient luôn tươi mới tại đúng \(w_k\) nhưng bị chậm theo nút chạy chậm nhất (&lt;em&gt;straggler&lt;/em&gt;). Bất đồng bộ loại bỏ thời gian chờ nhưng tạo ra &lt;strong&gt;gradient trễ (stale gradients)&lt;/strong&gt; tính tại phiên bản trọng số cũ \(w_{k-\tau}\), gây khó khăn cho hội tụ ở mô hình lớn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tính-tương-đương-toán-học-và-so-sánh-băng-thông-ring-all-reduce&quot;&gt;Giải thích: Kiểm chứng tính tương đương toán học và so sánh băng thông Ring All-Reduce&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng tương đương toán học với \(P = 2\) máy, mỗi máy giữ \(B = 2\) mẫu:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Máy 1 tính gradient trên 2 mẫu được \(2\) và \(6 \implies g^{(1)} = \frac{2 + 6}{2} = 4\).&lt;/li&gt;
      &lt;li&gt;Máy 2 tính gradient trên 2 mẫu được \(8\) và \(12 \implies g^{(2)} = \frac{8 + 12}{2} = 10\).&lt;/li&gt;
      &lt;li&gt;Trung bình qua All-Reduce: \(g = \frac{4 + 10}{2} = 7\).&lt;/li&gt;
      &lt;li&gt;So với chạy 1 máy duy nhất với minibatch \(PB = 4\) mẫu: \(\frac{2 + 6 + 8 + 12}{4} = \frac{28}{4} = 7\) — &lt;strong&gt;giống hệt từng chữ số!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh tải truyền thông khi mở rộng lên \(P = 4\) GPU với kích thước mô hình \(M = 100\text{ MB}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Parameter Server tập trung:&lt;/em&gt; Máy chủ phải nhận \(100\text{ MB}\) từ \(3\) worker khác (hoặc cả \(4\)) rồi gửi lại \(100\text{ MB}\) cho từng máy. Tổng dữ liệu đi qua nút cổ chai máy chủ là \(2(P - 1)M = 2(3)(100) = 600\text{ MB}\) (khi \(P = 100\) sẽ vọt lên \(19{,}800\text{ MB}\)!).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Ring All-Reduce:&lt;/em&gt; Chia vector \(100\text{ MB}\) thành \(P = 4\) lát (mỗi lát \(25\text{ MB}\)). Pha &lt;em&gt;reduce-scatter&lt;/em&gt; cần \(P - 1 = 3\) bước truyền \(25\text{ MB}\) (\(75\text{ MB}\)), pha &lt;em&gt;all-gather&lt;/em&gt; cần thêm \(3\) bước truyền \(25\text{ MB}\) (\(75\text{ MB}\)). Tổng lượng dữ liệu mỗi GPU gửi đi chỉ là:
\(2\frac{P - 1}{P}M = 2 \cdot \frac{3}{4} \cdot 100 = 150\text{ MB}\) — và ngay cả khi \(P = 1{,}000\) GPU, con số này vẫn bị chặn chặt dưới \(200\text{ MB}\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Giả sử tập dữ liệu gồm \(n\) mẫu được phân chia cho \(P\) nút tính toán (worker), trong đó nút \(p\) giữ tập chỉ số \(\mathcal{I}_p\). Một bước &lt;strong&gt;SGD song song dữ liệu&lt;/strong&gt; đồng bộ thực hiện:&lt;/p&gt;

\[g_k = \frac{1}{P}\sum_{p=1}^P g_k^{(p)}, \qquad
g_k^{(p)} = \frac{1}{B}\sum_{i\in\mathcal{B}_{k,p}} \nabla f_i(w_k),\]

&lt;p&gt;sau đó cập nhật \(w_{k+1}=w_k-\eta g_k\). Nếu hợp các minibatch \(\mathcal{B}_{k,p}\) tương đương với một mẫu rút đều, phép cập nhật này hoàn toàn trùng với SGD minibatch thông thường có kích thước lô \(PB\). Điểm khác biệt nằm ở kiến trúc &lt;em&gt;hệ thống&lt;/em&gt; để tổng hợp \(g_k\): sử dụng &lt;strong&gt;máy chủ tham số (parameter server)&lt;/strong&gt; để gom và cộng gradient, hoặc dùng giao thức &lt;strong&gt;all-reduce&lt;/strong&gt; (dạng vòng, cây hoặc thư viện NCCL) để lấy trung bình trực tiếp giữa các nút mà không tạo điểm nghẽn tập trung.&lt;/p&gt;

&lt;p&gt;Về mặt toán học, song song dữ liệu đồng bộ không làm thay đổi thuật toán SGD miễn là mọi nút đều dùng &lt;em&gt;cùng một&lt;/em&gt; bản sao tham số \(w_k\); lợi ích của nó là giảm thời gian thực thi (wall-clock time) mỗi bước và cho phép huấn luyện với kích thước lô tổng lớn hơn. Khi mô hình có hàng trăm triệu tham số, thao tác all-reduce trở thành bài toán băng thông mạng — đó là động lực cho các kỹ thuật nén gradient (lượng tử hóa, làm thưa).&lt;/p&gt;

&lt;p&gt;Các biến thể &lt;strong&gt;bất đồng bộ&lt;/strong&gt; (như Hogwild!) cho phép cập nhật ngay bằng các gradient tính trên bản sao tham số cũ hơn; chúng có thể tận dụng tốt bộ nhớ dùng chung nhưng khó phân tích hội tụ hơn. Trong phạm vi môn học, ta tập trung nắm vững mô hình đồng bộ trước.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;data_parallel_step&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;workers_grads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;workers_grads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;workers_grads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Bạn có thể xem mô phỏng chia tải song song tại &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/parallel_computing_illustration.html&quot;&gt;parallel_computing_illustration.html&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Nếu mỗi nút xử lý minibatch kích thước \(B=32\) trên \(P=8\) nút, kích thước lô tương đương trên một máy đơn là bao nhiêu? Nếu bạn tăng tuyến tính tốc độ học \(\eta\) theo \(P\), những rủi ro nào có thể xảy ra (gợi ý: xem lại phần lịch tốc độ học và giới hạn kích thước lô lớn ở Chương 26)?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>29 Tối ưu phân tán và liên federated</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter29/29_00_distributed_and_federated/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter29/29_00_distributed_and_federated</id>
   <content type="html">&lt;p&gt;Khi một mô hình học sâu cần huấn luyện trên hàng nghìn tỷ token hoặc dữ liệu y tế nằm rải rác tại hàng trăm bệnh viện không thể gom chung về một máy chủ vì luật bảo mật, bài toán tối ưu không còn chỉ là câu chuyện giữa hàm mục tiêu và một bộ vi xử lý duy nhất. &lt;strong&gt;Nút thắt cổ chai lớn nhất dịch chuyển từ phép tính dấu phẩy động (FLOPs) sang băng thông truyền thông (communication)!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Chương 29 khép lại toàn bộ hành trình tối ưu hóa bằng hai mô hình tính toán phân tán trụ cột của kỷ nguyên hiện đại: &lt;strong&gt;SGD song song dữ liệu&lt;/strong&gt; (trái tim của các cụm siêu máy tính GPU trong trung tâm dữ liệu) và &lt;strong&gt;Học liên kết — Federated Learning&lt;/strong&gt; (nơi dữ liệu nằm yên tại thiết bị/bệnh viện, còn mô hình đi “du lịch” để học và hội tụ qua thuật toán &lt;strong&gt;FedAvg&lt;/strong&gt;).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tối-ưu-phân-tán-và-học-liên-kết&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của Tối ưu phân tán và Học liên kết&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch29_federated_averaging.svg&quot; alt=&quot;Tối ưu hóa Phân tán và Học Liên kết (FedAvg)&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Bốn bài học của Chương 29 kết nối trực tiếp toán học tối ưu với kiến trúc hệ thống phân tán qua bốn trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Song song dữ liệu đồng bộ (Data-Parallel SGD &amp;amp; All-Reduce):&lt;/strong&gt; Trong trung tâm dữ liệu có mạng tốc độ cao (NVLink/InfiniBand), mọi GPU đồng bộ gradient ở &lt;em&gt;mỗi bước&lt;/em&gt; để tái tạo chính xác toán học của minibatch lớn \(PB\) mà giảm thời gian chạy thực tế gần tuyến tính theo số GPU.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học liên kết và Bội bước cục bộ (Federated Learning &amp;amp; FedAvg):&lt;/strong&gt; Khi các máy khách là điện thoại hay bệnh viện nối qua mạng chậm/không ổn định và dữ liệu phải giữ cục bộ vì quyền riêng tư, mỗi máy khách tự chạy \(E\) epoch cục bộ trước khi gửi trọng số về máy chủ, cắt giảm số vòng truyền thông hàng chục đến hàng trăm lần.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dữ liệu Không đồng nhất và Trôi cục bộ (Non-IID &amp;amp; Client Drift):&lt;/strong&gt; Đánh đổi lớn nhất của việc tăng số bước cục bộ \(E\) là khi dữ liệu giữa các máy khách khác phân phối, mỗi máy khách tự kéo mô hình về cực tiểu riêng của mình, khiến trung bình trọng số bị lệch khỏi cực tiểu toàn cục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối ADMM vs. FedAvg và Các biến thể hiện đại:&lt;/strong&gt; Đối chiếu rõ khi nào dùng ADMM đồng thuận (bài toán lồi có cấu trúc, dùng biến đối ngẫu triệt tiêu trôi) và khi nào dùng FedAvg / FedProx / SCAFFOLD / FedAdam (mạng sâu phi lồi, hạn chế băng thông).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-ngân-sách-băng-thông-giữa-data-parallel-sgd-và-fedavg&quot;&gt;Giải thích: Tính tay ngân sách băng thông giữa Data-Parallel SGD và FedAvg&lt;/h3&gt;

&lt;p&gt;Giả sử bạn huấn luyện một mô hình có \(d = 10^7\) tham số (mỗi tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; chiếm \(4\) byte, nên kích thước toàn bộ mô hình hoặc một vector gradient là \(M = 40\text{ MB}\)). Mỗi máy khách cần thực hiện tổng cộng \(100\) bước cập nhật SGD cục bộ:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chế độ SGD song song dữ liệu (đồng bộ sau mỗi \(1\) bước):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Số vòng truyền thông: \(100\) vòng.&lt;/li&gt;
      &lt;li&gt;Tổng lượng dữ liệu mỗi máy khách phải tải lên (chỉ tính chiều gửi):
\(100 \times 40\text{ MB} = 4{,}000\text{ MB} = 4\text{ GB}.\)
Trên mạng di động 4G/Wi-Fi không ổn định với hàng nghìn thiết bị, gửi 4 GB cho mỗi 100 bước là hoàn toàn bất khả thi!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chế độ FedAvg (mỗi máy khách chạy \(E = 10\) bước cục bộ rồi mới đồng bộ 1 lần):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Số vòng truyền thông giảm xuống còn: \(\frac{100}{10} = 10\) vòng.&lt;/li&gt;
      &lt;li&gt;Tổng lượng dữ liệu mỗi máy khách tải lên:
\(10 \times 40\text{ MB} = 400\text{ MB}\) — &lt;strong&gt;giảm đúng 10 lần băng thông!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thông điệp cốt lõi:&lt;/strong&gt; Toàn bộ nghệ thuật của học liên kết nằm ở việc chọn \(E\) đủ lớn để tiết kiệm băng thông như phép tính trên, nhưng đồng thời kiểm soát được sai số trôi cục bộ (client drift) do sự khác biệt dữ liệu giữa các máy khách gây ra!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;tối-ưu-phân-tán-và-học-liên-kết&quot;&gt;Tối ưu phân tán và học liên kết&lt;/h1&gt;

&lt;p&gt;Chương 21 (ADMM) đã giới thiệu cách tiếp cận &lt;em&gt;tối ưu lồi phân tán&lt;/em&gt; đầu tiên trong môn học: tách hàm mục tiêu có cấu trúc, trao đổi biến đối ngẫu và đạt đồng thuận. Tuy nhiên, huấn luyện học sâu quy mô lớn thường không đi theo mô hình đó. Cách tiếp cận tiêu chuẩn hiện nay là &lt;strong&gt;SGD song song dữ liệu (data-parallel SGD)&lt;/strong&gt;: mỗi nút tính toán giữ một phần dữ liệu, tính gradient trên minibatch cục bộ, rồi máy chủ tham số (hoặc phép toán all-reduce) lấy trung bình các gradient hoặc trọng số.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Học liên kết (federated learning)&lt;/strong&gt; mở rộng ý tưởng này dưới ràng buộc quyền riêng tư: dữ liệu thô không được phép rời khỏi thiết bị hoặc cơ sở sở hữu dữ liệu. Thuật toán &lt;strong&gt;FedAvg&lt;/strong&gt; (McMahan và cộng sự, AISTATS 2017) cho mỗi máy khách thực hiện nhiều bước SGD cục bộ rồi mới gửi &lt;em&gt;tham số&lt;/em&gt; về máy chủ để lấy trung bình theo từng vòng. Trong bối cảnh này, băng thông và số vòng truyền thông — chứ không phải số phép tính dấu phẩy động — mới là nút thắt chính.&lt;/p&gt;

&lt;p&gt;Chương này cung cấp phần nhập môn cốt lõi, không đi sâu vào các chủ đề nâng cao như chống lỗi Byzantine hay nén gradient, nhưng sẽ phân biệt rõ bản chất giữa ADMM đồng thuận và FedAvg.&lt;/p&gt;

&lt;h2 id=&quot;nội-dung-các-bài&quot;&gt;Nội dung các bài&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;SGD song song dữ liệu và all-reduce.&lt;/li&gt;
  &lt;li&gt;Thuật toán FedAvg.&lt;/li&gt;
  &lt;li&gt;So sánh ADMM với SGD song song dữ liệu và học liên kết.&lt;/li&gt;
  &lt;li&gt;Ứng dụng học liên kết hiện đại (tùy chọn) — FedProx, SCAFFOLD, FedAdam và ứng dụng y tế.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tài liệu đọc chính: McMahan và cộng sự (&lt;a href=&quot;https://proceedings.mlr.press/v54/mcmahan17a.html&quot;&gt;PMLR v54&lt;/a&gt;) cùng bài khảo sát ADMM của Boyd và cộng sự. Các mở rộng giai đoạn 2020–2026 được trình bày tại bài tùy chọn &lt;a href=&quot;/contents/vi/chapter29/29_04_modern_federated/&quot;&gt;29-04&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>28-03 Quá tham số</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_03_overparameterization/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_03_overparameterization</id>
   <content type="html">&lt;p&gt;Trong thống kê cổ điển, có một điều răn tưởng chừng bất khả xâm phạm: &lt;em&gt;số tham số \(d\) phải nhỏ hơn số mẫu dữ liệu \(n\), nếu không mô hình sẽ “học thuộc lòng” (overfitting) và sụp đổ trên dữ liệu mới&lt;/em&gt;. Thế nhưng mạng nơ-ron sâu hiện đại lại phá vỡ hoàn toàn điều răn đó: các mô hình có hàng trăm triệu, thậm chí hàng trăm tỷ tham số — lớn hơn số mẫu gấp nhiều lần — vẫn tổng quát hóa xuất sắc!&lt;/p&gt;

&lt;p&gt;Chìa khóa để hiểu nghịch lý &lt;strong&gt;quá tham số hóa (overparameterization)&lt;/strong&gt; nằm ở sự thay đổi vai trò của thuật toán tối ưu: khi hệ phương trình \(F(w) = 0\) có &lt;strong&gt;vô số nghiệm&lt;/strong&gt;, bản thân thuật toán tối ưu (khởi tạo từ đâu, đi bước thế nào) không còn chỉ là công cụ tìm nghiệm — nó trở thành &lt;strong&gt;bộ chọn mô hình&lt;/strong&gt; sở hữu một &lt;strong&gt;thiên kiến ẩn (implicit bias)&lt;/strong&gt; mạnh mẽ hướng về các nghiệm đơn giản, chuẩn nhỏ và lề lớn!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-chế-độ-quá-tham-số-hóa&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của chế độ Quá tham số hóa&lt;/h2&gt;

&lt;p&gt;Bài học này làm rõ ba sự biến đổi sâu sắc khi ta bước qua ngưỡng \(d \gg n\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đa tạp nghiệm nội suy (Interpolating Solution Manifold):&lt;/strong&gt; Khi \(d &amp;gt; n\), tập \(\{w : Xw = y\}\) là một không gian affine chiều \(d - n\) thay vì một điểm duy nhất. Do đó, câu hỏi trung tâm chuyển từ &lt;em&gt;“có hội tụ về 0 không?”&lt;/em&gt; sang &lt;em&gt;“thuật toán sẽ chọn điểm nào trên mặt phẳng nghiệm \(0\) này?”&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thiên kiến ẩn của Gradient Descent (Implicit Bias / Implicit Regularization):&lt;/strong&gt; Dù không hề thêm số hạng phạt \(\frac{\lambda}{2}\|w\|_2^2\) vào hàm mất mát, Gradient Descent xuất phát từ \(w_0 = 0\) trên hồi quy tuyến tính thiếu xác định vẫn &lt;strong&gt;tự động hội tụ về nghiệm nội suy có chuẩn \(\ell_2\) nhỏ nhất&lt;/strong&gt;! Trên phân loại tuyến tính tách được với hàm mất mát mũ/logistic, nó tự động hướng về siêu phẳng &lt;strong&gt;cực đại hóa lề (max-margin SVM)&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình học thuận lợi cục bộ và Điều kiện PL:&lt;/strong&gt; Khi mạng đủ rộng (chế độ NTK / quá tham số hóa), ma trận Jacobian tại khởi tạo có hạng đầy đủ, khiến hàm mất mát thỏa điều kiện Polyak–Łojasiewicz (PL) cục bộ — đảm bảo GD hội tụ nhanh về mất mát huấn luyện bằng \(0\) mà không cần tính lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chứng-minh-bằng-tay-thiên-kiến-ẩn-của-gd-trên-hệ-thiếu-xác-định&quot;&gt;Giải thích: Chứng minh bằng tay Thiên kiến ẩn của GD trên hệ thiếu xác định&lt;/h3&gt;

&lt;p&gt;Xét bài toán hồi quy tuyến tính quá tham số hóa tối giản nhất: chỉ có \(n = 1\) mẫu dữ liệu \((x_1, x_2) = (1,\; 2)\) với nhãn \(y = 5\), nhưng có tới \(d = 2\) tham số \(w = (w_1, w_2)^T\):&lt;/p&gt;

\[F(w_1, w_2) = \frac{1}{2}(w_1 + 2w_2 - 5)^2.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tập nghiệm nội suy \(F(w) = 0\) gồm vô số điểm trên đường thẳng \(w_1 + 2w_2 = 5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nghiệm A: \(w_A = (5,\; 0)\) có \(\|w_A\|_2^2 = 25\).&lt;/li&gt;
      &lt;li&gt;Nghiệm B: \(w_B = (0,\; 2.5)\) có \(\|w_B\|_2^2 = 6.25\).&lt;/li&gt;
      &lt;li&gt;Nghiệm C: \(w_C = (1,\; 2)\) có \(\|w_C\|_2^2 = 1^2 + 2^2 = 5\) (nhỏ nhất!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan sát quỹ đạo của Gradient Descent xuất phát từ \(w^{(0)} = (0,\; 0)\):&lt;/strong&gt;
Tính gradient tại mọi điểm \(w\):
\(\nabla F(w) = (w_1 + 2w_2 - 5) \cdot \begin{pmatrix} 1 \\ 2 \end{pmatrix}.\)
Nhận xét chấn động: &lt;strong&gt;ở mọi vòng lặp \(k\), vector gradient luôn song song với vector \((1, 2)^T\)!&lt;/strong&gt;
Vì \(w^{(0)} = (0, 0)\) và mọi bước cập nhật chỉ cộng trừ một bội số của \((1, 2)^T\), nên mọi điểm lặp \(w^{(k)}\) đều buộc phải có dạng \(w^{(k)} = \alpha_k (1,\; 2)^T\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm hội tụ duy nhất:&lt;/strong&gt;
Khi \(F(w^{(k)}) \to 0\), điểm giới hạn \(w^\star = \alpha^\star (1, 2)^T\) phải thỏa phương trình đường thẳng \(w_1 + 2w_2 = 5\):
\(\alpha^\star(1) + 2(\alpha^\star \cdot 2) = 5 \implies 5\alpha^\star = 5 \implies \alpha^\star = 1 \implies w^\star_{\text{GD}} = (1,\; 2)^T!\)
Không hề có một dòng code nào yêu cầu cực tiểu hóa \(\|w\|_2^2\), vậy mà cấu trúc đại số của GD tự động giao cắt vuông góc với đường thẳng nghiệm và chọn đúng điểm \(w_C = (1, 2)\) có chuẩn Euclid nhỏ nhất!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Một mô hình được gọi là &lt;strong&gt;quá tham số hóa (overparameterized)&lt;/strong&gt; khi số lượng tham số \(d\) lớn hơn đáng kể so với số ràng buộc hiệu dụng từ dữ liệu huấn luyện (trường hợp kinh điển là \(d \gg n\) để nội suy \(n\) nhãn vô hướng). Khi đó, phương trình \(F(w)=0\) (tức hàm mất mát huấn luyện xấp xỉ 0) có cả một &lt;strong&gt;tập nghiệm rất lớn&lt;/strong&gt;. Quá trình huấn luyện không còn là bài toán “tìm cực tiểu duy nhất”, mà trở thành câu hỏi: &lt;em&gt;thuật toán tối ưu sẽ chọn nghiệm nội suy nào trong số đó?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Đây chính là góc nhìn &lt;strong&gt;thiên kiến ẩn (implicit bias)&lt;/strong&gt;. Trên bài toán bình phương tối thiểu thiếu xác định, gradient descent xuất phát từ gốc hội tụ về nghiệm nội suy có &lt;strong&gt;chuẩn \(\ell_2\) nhỏ nhất&lt;/strong&gt; trong không gian sinh bởi các đặc trưng; trên bài toán phân loại tuyến tính tách được, nó hội tụ theo hướng cực đại hóa lề (Soudry và cộng sự, cùng nhiều nghiên cứu nối tiếp). Dù mạng nơ-ron sâu là phi tuyến, nguyên lý cốt lõi vẫn giữ nguyên: &lt;strong&gt;thuật toán tối ưu là một phần của thiên kiến quy nạp (inductive bias)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Quá tham số hóa cũng làm thay đổi hình học của \(F\). Trong nhiều chế độ mô hình đặc trưng ngẫu nhiên và mạng đủ rộng, bề mặt hàm mất mát trở nên thuận lợi về mặt cục bộ: khi điểm lặp đã vào đủ gần, mọi điểm tới hạn mà SGD gặp đều nội suy dữ liệu huấn luyện, nên câu hỏi chính không còn là có bị kẹt ở điểm yên ngựa hay không mà là mô hình hội tụ tới &lt;em&gt;điểm nội suy nào&lt;/em&gt;. Điều này giải thích vì sao nhận định “không lồi thì chắc chắn kẹt ở cực tiểu địa phương xấu” không phản ánh đúng thực tế của học sâu hiện đại.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện Polyak–Łojasiewicz (PL)&lt;/strong&gt; (giới thiệu ngắn gọn). Nếu hàm \(F\) thỏa mãn:&lt;/p&gt;

\[\tfrac12 \|\nabla F(w)\|_2^2 \ge \mu \bigl(F(w)-F^\star\bigr)\]

&lt;p&gt;với hằng số \(\mu&amp;gt;0\), thì gradient descent vẫn đạt tốc độ hội tụ tuyến tính &lt;em&gt;mà không cần tính lồi&lt;/em&gt;. Nhiều bài toán bình phương tối thiểu quá tham số hóa và một số chế độ mạng rộng thỏa điều kiện PL cục bộ. Bài tùy chọn &lt;a href=&quot;/contents/vi/chapter28/28_05_pl_condition/&quot;&gt;28-05&lt;/a&gt; trình bày chi tiết cách kế thừa chứng minh Chương 06 cho bất đẳng thức này (Karimi, Nutini &amp;amp; Schmidt, &lt;a href=&quot;https://arxiv.org/abs/1608.04636&quot;&gt;arXiv:1608.04636&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Khớp \(n=20\) điểm dữ liệu vô hướng bằng một đa thức bậc \(50\) theo hai cách: (i) nghiệm chuẩn tối thiểu từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.lstsq&lt;/code&gt; và (ii) gradient descent xuất phát từ hai điểm khởi tạo ngẫu nhiên khác nhau. So sánh sai số kiểm tra trên một hàm gốc trơn: cả hai đều đạt mất mát huấn luyện gần bằng 0 nhưng cho ra các nghiệm nội suy khác nhau.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>28-02 Thoát yên ngựa và hình học phong cảnh</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_02_escaping_saddles/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_02_escaping_saddles</id>
   <content type="html">&lt;p&gt;Biết rằng điểm yên ngựa chặt &lt;em&gt;luôn có lối thoát&lt;/em&gt; về mặt toán học là một chuyện; liệu thuật toán bậc nhất như Gradient Descent hay SGD có &lt;strong&gt;tìm thấy lối thoát đó trong thời gian đa thức&lt;/strong&gt; hay bị mắc kẹt hàng triệu vòng lặp lại là câu chuyện hoàn toàn khác! Một kết quả lý thuyết kinh điển của Du và cộng sự (ICML 2017) chỉ ra rằng Gradient Descent tất định thuần túy có thể mất &lt;strong&gt;thời gian hàm mũ&lt;/strong&gt; để thoát khỏi chuỗi điểm yên ngựa nếu đi vào sát mặt ổn định.&lt;/p&gt;

&lt;p&gt;Thế nhưng chỉ cần một cú huých cực nhỏ — &lt;strong&gt;nhiễu ngẫu nhiên từ minibatch SGD&lt;/strong&gt; hoặc một lượng nhiễu Gaussian đẳng hướng nhỏ (Perturbed GD) — là đủ để biến thời gian hàm mũ thành thời gian đa thức! Và sau khi thoát yên ngựa để đáp xuống đáy cực tiểu, một câu hỏi hình học thứ hai lập tức xuất hiện: &lt;em&gt;giữa hai cực tiểu cùng có mất mát huấn luyện bằng 0, vì sao đáy phẳng (flat minimum) lại tổng quát hóa tốt hơn đáy sắc (sharp minimum)?&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-cơ-chế-thoát-yên-ngựa-và-hình-học-đáy-cực-tiểu&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của cơ chế Thoát yên ngựa và Hình học đáy cực tiểu&lt;/h2&gt;

&lt;p&gt;Bài học này nối kết động lực học tối ưu với khả năng tổng quát hóa thông qua ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khuếch đại theo hàm mũ dọc hướng độ cong âm:&lt;/strong&gt; Gần điểm yên ngựa có trị riêng âm \(-\gamma &amp;lt; 0\), mỗi bước GD nhân thành phần lệch dọc hướng thoát với hệ số \((1 + \eta\gamma) &amp;gt; 1\). Chỉ cần nhiễu SGD tạo ra một thành phần lệch ban đầu cỡ \(\delta &amp;gt; 0\), nó sẽ nở lớn theo hàm mũ \((1 + \eta\gamma)^k \delta\) và bắn vọt ra khỏi yên ngựa sau chỉ \(O(\log(1/\delta))\) bước!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí và Quy mô của các cơ chế thoát yên ngựa:&lt;/strong&gt; SGD thoát yên ngựa tự nhiên nhờ phương sai minibatch; Perturbed GD thêm nhiễu chủ động khi \(\|\nabla F\|\) nhỏ để có bảo đảm lý thuyết; còn các phương pháp khai thác độ cong âm (Hessian–vector product) tìm thẳng hướng thoát nhưng tốn kém hơn trong thực tế mạng lớn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu phẳng vs. Cực tiểu sắc (Flat vs. Sharp Minima):&lt;/strong&gt; Khi phân phối tập test hơi dịch chuyển so với tập train (tương đương bề mặt hàm mất mát dịch ngang một đoạn \(\delta\)), mức tăng sai số tỉ lệ thuận với trị riêng lớn nhất của Hessian \(\frac{1}{2}\lambda_{\max} \delta^2\). Do đó, các đáy phẳng (\(\lambda_{\max}\) nhỏ, mục tiêu của SAM và SGD lô nhỏ) có sức chống chịu phân phối lệch vượt trội.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-tốc-độ-thoát-yên-ngựa-và-độ-nhạy-của-đáy-sắc-vs-đáy-phẳng&quot;&gt;Giải thích: Tính tay tốc độ thoát yên ngựa và độ nhạy của đáy sắc vs. đáy phẳng&lt;/h3&gt;

&lt;p&gt;Hãy tự tay kiểm chứng cả hai hiện tượng cốt lõi của bài học bằng hai phép tính ngắn gọn:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khuếch đại hàm mũ khi thoát yên ngựa (Perturbed GD):&lt;/strong&gt;
Xét hàm yên ngựa \(F(x, y) = \frac{1}{2}(x^2 - y^2)\) tại điểm dừng \((0, 0)\) với \(\eta = 0.5\).
    &lt;ul&gt;
      &lt;li&gt;Không có nhiễu: \(\nabla F(0, 0) = (0, 0) \implies\) kẹt vĩnh viễn tại \((0, 0)\).&lt;/li&gt;
      &lt;li&gt;Thêm một cú huých siêu nhỏ \(\delta = 0.01\) vào tọa độ \(y\) (đưa điểm về \((0,\; 0.01)\)):
Vì \(\frac{\partial F}{\partial y} = -y\), quy tắc cập nhật là \(y_{k+1} = y_k - 0.5(-y_k) = 1.5 y_k\)!
        &lt;ul&gt;
          &lt;li&gt;Sau 1 bước: \(y_1 = 0.015\).&lt;/li&gt;
          &lt;li&gt;Sau 2 bước: \(y_2 = 0.0225\).&lt;/li&gt;
          &lt;li&gt;Sau 12 bước: \(y_{12} = (1.5)^{12} \cdot 0.01 \approx 1.30\) — đã nhảy vọt ra xa hơn &lt;strong&gt;130 lần&lt;/strong&gt; chỉ nhờ một hạt nhiễu \(0.01\)!&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đo độ nhạy của cực tiểu phẳng so với cực tiểu sắc dưới độ lệch \(\delta = 0.1\):&lt;/strong&gt;
Giả sử trên tập train cả hai đều đạt mất mát \(0\) tại \(w^\star\), nhưng khi chuyển sang tập test vị trí tối ưu bị dịch lệch \(\delta = 0.1\):
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Đáy phẳng&lt;/em&gt; \(F_{\text{flat}}(w) = 1 \cdot (w - w^\star)^2\) (Hessian \(H = 2\)): mất mát tăng thêm \(\Delta F_{\text{flat}} = 1 \cdot (0.1)^2 = 0.01\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Đáy sắc&lt;/em&gt; \(F_{\text{sharp}}(w) = 100 \cdot (w - w^\star)^2\) (Hessian \(H = 200\)): mất mát tăng thêm \(\Delta F_{\text{sharp}} = 100 \cdot (0.1)^2 = 1.00\) — &lt;strong&gt;tệ hơn đúng 100 lần&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các thuật toán tối ưu quen thuộc thoát khỏi điểm yên ngựa chặt bằng những cơ chế nào?&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nhiễu từ SGD:&lt;/strong&gt; Gradient ước lượng trên minibatch không trùng khít với \(\nabla F\); thành phần nhiễu ngẫu nhiên có hình chiếu khác 0 lên hướng độ cong âm với xác suất cao, giúp đẩy điểm lặp ra khỏi điểm yên ngựa. Ngược lại, gradient descent toàn lô có thể đứng yên vĩnh viễn nếu rơi đúng vào điểm yên ngựa không có thành phần lệch (như điểm \((0,0)\) ở bài trước).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient descent có nhiễu (Perturbed GD):&lt;/strong&gt; Chủ động cộng nhiễu đẳng hướng khi \(\|\nabla F\|\) nhỏ là phiên bản dễ phân tích lý thuyết của cơ chế trên (Ge, Huang, Jin, Yuan; Jin và cộng sự).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Momentum:&lt;/strong&gt; Quán tính có thể giúp điểm lặp vượt qua vùng yên phẳng rồi trượt xuống, nhưng cũng có thể gây dao động; tự bản thân momentum không phải là bảo đảm toán học cho việc thoát điểm yên ngựa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp bậc hai / khai thác độ cong âm:&lt;/strong&gt; Sử dụng tích Hessian–vector (kiểu Pearlmutter hoặc Neon) để chủ động hạ theo vector riêng ứng với trị riêng âm nhỏ nhất. Các phương pháp này ít dùng trực tiếp trong huấn luyện học sâu quy mô lớn nhưng rất hữu ích để hiểu cơ chế hình học.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cực tiểu sắc và cực tiểu phẳng.&lt;/strong&gt; Giữa hai cực tiểu có cùng giá trị hàm mất mát \(F\), điểm có các trị riêng Hessian lớn hơn tương ứng với đáy &lt;em&gt;sắc&lt;/em&gt; hơn: chỉ một nhiễu nhỏ trên tham số (hoặc độ lệch phân phối nhỏ của dữ liệu kiểm tra) cũng có thể làm hàm mất mát tăng mạnh. Thuật toán &lt;strong&gt;SAM&lt;/strong&gt; (Foret và cộng sự, ICLR 2021) tối ưu giá trị cực đại trong một lân cận nhỏ để hướng về các vùng phẳng hơn (xem bài seminar tùy chọn 26-06).&lt;/p&gt;

&lt;p&gt;Hình dung hình học cần ghi nhớ: bề mặt hàm mất mát của mạng sâu không đơn giản như đồ thị 2 chiều với vài hố riêng lẻ, mà là một cấu trúc nhiều chiều có các &lt;strong&gt;vùng cao nguyên&lt;/strong&gt; rộng, các &lt;strong&gt;hẻm hẹp&lt;/strong&gt; (gắn với số điều kiện xấu ở Chương 06 và 26), và tính &lt;strong&gt;đối xứng&lt;/strong&gt; (hoán vị các nơ-ron ẩn không làm đổi \(F\), nên các điểm cực tiểu tạo thành những đa tạp liên tục). Khi quan sát hình chiếu 3 chiều trong các công cụ mô phỏng, luôn cần lưu ý những chiều thông tin đã bị chiếu mất.&lt;/p&gt;

&lt;h3 id=&quot;điểm-yên-ngựa-trong-khoảng-3-phút&quot;&gt;Điểm yên ngựa trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/saddle-escape_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;GD bị hút vào yên ngựa của x² − y² + ½y⁴, ngồi lâu khi lệch rất nhỏ, thoát nhờ nhiễu, và vì sao ở chiều cao hầu hết điểm tới hạn là yên ngựa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Nếu nhiễu của SGD là cơ chế giúp đẩy điểm lặp khỏi điểm yên ngựa, điều gì xảy ra khi kích thước minibatch \(B \to n\), và nhận xét này liên hệ thế nào đến cuộc thảo luận về khả năng tổng quát hóa của kích thước lô lớn?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>28-01 Điểm tới hạn và yên ngựa</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_01_critical_points_and_saddles/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_01_critical_points_and_saddles</id>
   <content type="html">&lt;p&gt;Trong giải tích một biến ở năm nhất đại học, khi thấy \(f&apos;(x) = 0\), ta thường kiểm tra ngay dấu của \(f&apos;&apos;(x)\): dương là cực tiểu, âm là cực đại. Nhưng ngay khi bước lên mặt phẳng 2 chiều — chứ chưa nói đến không gian 1 tỷ chiều của mạng nơ-ron — một nhân vật thứ ba lập tức chiếm lĩnh sân khấu: &lt;strong&gt;điểm yên ngựa (saddle point)&lt;/strong&gt;, nơi địa hình cong lên theo hướng này nhưng lại dốc tụt xuống theo hướng kia.&lt;/p&gt;

&lt;p&gt;Điều thú vị đến rùng mình của hình học nhiều chiều là: nếu mỗi hướng độc lập có xác suất \(50\%\) cong lên và \(50\%\) cong xuống, thì trong không gian \(d = 100\) chiều, xác suất để một điểm tới hạn có &lt;em&gt;cả 100 hướng đều cong lên&lt;/em&gt; (cực tiểu địa phương) chỉ là \(2^{-100} \approx 10^{-30}\)! Phần còn lại gần như chắc chắn là điểm yên ngựa — giải thích vì sao hiểu phổ Hessian là bước đầu tiên để hiểu động lực huấn luyện mạng sâu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-phân-loại-điểm-tới-hạn-bằng-hessian&quot;&gt;Kiến thức cần nhớ: Ba trụ cột phân loại điểm tới hạn bằng Hessian&lt;/h2&gt;

&lt;p&gt;Bài học này đặt nền tảng giải tích bậc hai cho toàn bộ Chương 28 qua ba trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khai triển Taylor bậc hai và Dấu trị riêng Hessian:&lt;/strong&gt; Tại điểm tới hạn \(\nabla F(w) = 0\), dáng điệu cục bộ hoàn toàn do dạng toàn phương \(\frac{1}{2} \Delta w^T H \Delta w\) quyết định. Chéo hóa \(H = Q \Lambda Q^T\) tách không gian thành \(d\) trục độc lập: mỗi trị riêng âm \(\lambda_i &amp;lt; 0\) là một “lối thoát” giúp giảm hàm mất mát khi bước theo vector riêng \(q_i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Yên ngựa chặt (Strict Saddle) vs. Yên ngựa suy biến (Degenerate Saddle):&lt;/strong&gt; Yên ngựa chặt có ít nhất một \(\lambda_{\min}(H) &amp;lt; 0\) rõ rệt, nên có lối thoát ngay ở bậc hai. Ngược lại, khi \(\lambda_{\min}(H) = 0\) (như hàm \(w^3\) hay các cao nguyên phẳng trong mạng sâu), kiểm định bậc hai bất lực và thuật toán bậc nhất có thể bò cực chậm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lời nguyền kích thước đảo ngược (High-Dimensional Blessing):&lt;/strong&gt; Trái với trực giác 2D lo sợ bị kẹt ở cực tiểu địa phương xấu, trong không gian chiều rất cao, hầu hết các điểm dừng có giá trị mất mát cao đều có nhiều hướng độ cong âm (điểm yên ngựa) để thuật toán thoát ra được.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-phân-loại-đủ-3-điểm-tới-hạn-của-hàm-thế-hai-giếng-double-well&quot;&gt;Giải thích: Tính tay phân loại đủ 3 điểm tới hạn của hàm thế hai giếng (Double-Well)&lt;/h3&gt;

&lt;p&gt;Để luyện kỹ năng phân loại bằng Hessian mà không trùng với bài tập \(x^2 - y^2\) ở cuối bài, hãy xét hàm không lồi 2 biến:&lt;/p&gt;

\[F(x, y) = \frac{1}{4}x^4 - \frac{1}{2}x^2 + \frac{1}{2}y^2.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tìm tất cả điểm tới hạn (\(\nabla F = 0\)):&lt;/strong&gt;
\(\nabla F(x, y) = \bigl(x^3 - x,\; y\bigr) = (0,\; 0) \implies x(x^2 - 1) = 0,\; y = 0.\)
Có đúng 3 điểm tới hạn: \(P_1 = (0, 0)\), \(P_2 = (1, 0)\), và \(P_3 = (-1, 0)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính ma trận Hessian tổng quát:&lt;/strong&gt;
\(H(x, y) = \begin{pmatrix} \frac{\partial^2 F}{\partial x^2} &amp;amp; \frac{\partial^2 F}{\partial x \partial y} \\ \frac{\partial^2 F}{\partial y \partial x} &amp;amp; \frac{\partial^2 F}{\partial y^2} \end{pmatrix} = \begin{pmatrix} 3x^2 - 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân loại từng điểm dựa trên cặp trị riêng \((\lambda_1, \lambda_2) = (3x^2 - 1,\; 1)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Tại \(P_1 = (0, 0)\):&lt;/em&gt; \((\lambda_1, \lambda_2) = (-1,\; +1)\) trái dấu \(\implies\) &lt;strong&gt;Điểm yên ngựa chặt!&lt;/strong&gt; Giá trị \(F(0, 0) = 0\). Nếu dịch nhẹ dọc hướng riêng âm \(u = (1, 0)\) một đoạn \(t = 0.2\), ta có \(F(0.2, 0) = 0.0004 - 0.02 = -0.0196 &amp;lt; 0\) (giảm ngay lập tức!).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Tại \(P_2 = (1, 0)\) và \(P_3 = (-1, 0)\):&lt;/em&gt; \((\lambda_1, \lambda_2) = (+2,\; +1)\) đều dương \(\implies\) &lt;strong&gt;Hai cực tiểu địa phương chặt&lt;/strong&gt; (và đều là cực tiểu toàn cục với \(F = -\frac{1}{4} = -0.25\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cho hàm \(F:\mathbb{R}^d\to\mathbb{R}\) khả vi hai lần liên tục. Điểm \(w\) là &lt;strong&gt;điểm tới hạn (critical point)&lt;/strong&gt; nếu \(\nabla F(w)=0\). Khi ma trận Hessian \(H=\nabla^2 F(w)\) không suy biến (không có trị riêng bằng 0), ta phân loại \(w\) như sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu địa phương chặt:&lt;/strong&gt; \(H\succ 0\) (mọi trị riêng đều dương).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực đại địa phương chặt:&lt;/strong&gt; \(H\prec 0\) (mọi trị riêng đều âm).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm yên ngựa chặt (strict saddle):&lt;/strong&gt; \(H\) không xác định dấu — có ít nhất một trị riêng dương và một trị riêng âm.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nếu tồn tại trị riêng bằng 0, kiểm định bậc hai chưa đủ để kết luận (ví dụ hàm \(w\mapsto w^3\) hoặc các vùng cao nguyên phẳng). Hàm mất mát của mạng nơ-ron sâu thường chứa rất nhiều phương gần suy biến.&lt;/p&gt;

&lt;p&gt;Mặc dù &lt;strong&gt;các phương pháp bậc nhất không tính trực tiếp \(H\)&lt;/strong&gt;, khai triển Taylor bậc hai cục bộ vẫn cho thấy hành vi tại điểm yên ngựa: dọc theo một phương \(u\) có độ cong âm (\(u^\top H u &amp;lt; 0\)), giá trị \(F(w+t u)\approx F(w)+\tfrac12 t^2 u^\top H u\) &lt;em&gt;giảm&lt;/em&gt; với \(t\neq 0\) đủ nhỏ. Do đó, điểm yên ngựa chặt không phải là cái bẫy đối với thuật toán có thể dịch chuyển theo phương độ cong âm, mà chỉ gây dừng sớm cho các thuật toán chỉ kiểm tra điều kiện \(\|\nabla F\| \approx 0\).&lt;/p&gt;

&lt;p&gt;Trong không gian nhiều chiều, nếu dấu các trị riêng của ma trận Hessian tại một điểm tới hạn bất kỳ ứng xử tương tự ma trận đối xứng ngẫu nhiên, xác suất để &lt;em&gt;tất cả&lt;/em&gt; \(d\) trị riêng đều dương giảm theo hàm mũ của \(d\). Nhận xét định tính quan trọng cần nhớ là: &lt;strong&gt;với các hàm tổng quát nhiều chiều, đa số điểm tới hạn là điểm yên ngựa chứ không phải cực tiểu địa phương&lt;/strong&gt;. Dù hàm mất mát học sâu không hoàn toàn giống hàm ngẫu nhiên Gaussian, trực giác này giải thích vì sao tình trạng chậm tiến triển khi huấn luyện thường liên quan đến điểm yên ngựa và vùng phẳng hơn là bị mắc kẹt ở một cực tiểu địa phương xấu.&lt;/p&gt;

&lt;h3 id=&quot;điểm-yên-ngựa-trong-khoảng-3-phút&quot;&gt;Điểm yên ngựa trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/saddle-escape_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;GD bị hút vào yên ngựa của x² − y² + ½y⁴, ngồi lâu khi lệch rất nhỏ, thoát nhờ nhiễu, và vì sao ở chiều cao hầu hết điểm tới hạn là yên ngựa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Xét hàm yên ngựa \(F(x,y)=x^2-y^2\): hãy viết \(\nabla F\) và ma trận Hessian \(H\). Thực hiện hai bước gradient descent với bước \(\eta = 0.1\), xuất phát từ \((0, 10^{-3})\), sau đó giải thích vì sao nếu xuất phát chính xác từ \((0, 0)\) thì gradient descent lý tưởng sẽ không bao giờ rời khỏi điểm đó.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>28 Phong cảnh không lồi cho học sâu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_00_nonconvex_landscapes/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter28/28_00_nonconvex_landscapes</id>
   <content type="html">&lt;p&gt;Suốt 25 chương đầu, tính lồi là tấm lưới bảo hiểm tuyệt đối của ta: chỉ cần tìm được một điểm có gradient bằng \(0\), ta chắc chắn đang đứng ở đáy sâu nhất toàn vũ trụ. Nhưng ngay khi bước sang mạng nơ-ron sâu, tấm lưới bảo hiểm ấy biến mất hoàn toàn — hàm mất mát \(F(w)\) trở nên &lt;strong&gt;không lồi&lt;/strong&gt; với hàng triệu tham số lồng nhau qua các phép nhân ma trận và hàm kích hoạt phi tuyến.&lt;/p&gt;

&lt;p&gt;Thế nhưng một nghịch lý tuyệt đẹp của khoa học máy tính thế kỷ 21 đã xảy ra: thay vì mắc kẹt mãi ở những “hố cực tiểu địa phương tồi tệ” như trực giác 2 chiều cảnh báo, SGD và AdamW lại huấn luyện mạng sâu xuống gần mức mất mát bằng \(0\) một cách đáng kinh ngạc! Chương 28 sẽ giải mã bí ẩn đó thông qua ba chìa khóa hình học: &lt;strong&gt;điểm yên ngựa trong không gian nhiều chiều&lt;/strong&gt;, &lt;strong&gt;cơ chế thoát yên ngựa nhờ nhiễu&lt;/strong&gt;, và &lt;strong&gt;sự dồi dào nghiệm của chế độ quá tham số hóa&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-địa-hình-không-lồi-trong-học-sâu&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của địa hình không lồi trong học sâu&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch28_nonconvex_saddles_pl.svg&quot; alt=&quot;Địa hình Không lồi: Điểm yên ngựa &amp;amp; Điều kiện PL&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Để đọc hiểu các bài 28-01 đến 28-05 một cách hệ thống, hãy nắm bốn trụ cột hình học sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân loại điểm tới hạn theo phổ Hessian:&lt;/strong&gt; Trong không gian \(d\) chiều lớn, xác suất cả \(d\) trị riêng của Hessian cùng dương tại một điểm tới hạn là cực nhỏ; vì vậy, kẻ cản đường phổ biến nhất không phải cực tiểu địa phương kém mà là &lt;strong&gt;điểm yên ngựa chặt (strict saddle)&lt;/strong&gt; và các vùng cao nguyên phẳng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Động lực học thoát yên ngựa (Escaping Saddles):&lt;/strong&gt; Phương pháp bậc nhất tất định có thể bị kẹt nếu rơi đúng vào mặt ổn định của yên ngựa, nhưng nhiễu ngẫu nhiên từ minibatch SGD (hoặc nhiễu thêm vào có chủ đích) luôn có hình chiếu khác 0 lên hướng độ cong âm, đẩy quỹ đạo trượt xuống nhanh chóng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quá tham số hóa và Thiên kiến ẩn (Overparameterization &amp;amp; Implicit Bias):&lt;/strong&gt; Khi số tham số \(d \gg n\), tập nghiệm nội suy \(F(w) = 0\) không phải một điểm cô lập mà là một đa tạp liên tục rộng lớn; thuật toán tối ưu (SGD, AdamW) đóng vai trò bộ chọn ẩn quyết định mô hình rơi vào nghiệm nào trên đa tạp đó.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện Polyak–Łojasiewicz (PL):&lt;/strong&gt; Một bất đẳng thức gradient đơn giản cho phép chứng minh hội tụ tuyến tính của GD ngay cả khi hàm mất mát hoàn toàn không lồi — cây cầu nối thẳng tối ưu lồi Chương 06 sang học sâu hiện đại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-mạng-tuyến-tính-2-lớp--thu-nhỏ-toàn-bộ-địa-hình-học-sâu-vào-2-biến&quot;&gt;Giải thích: Mạng tuyến tính 2 lớp — thu nhỏ toàn bộ địa hình học sâu vào 2 biến&lt;/h3&gt;

&lt;p&gt;Xét mạng nơ-ron tuyến tính tối giản nhất thế giới gồm 2 trọng số vô hướng \(u, v \in \mathbb{R}\) khớp một điểm dữ liệu \((x = 1, y = 1)\):&lt;/p&gt;

\[F(u, v) = \frac{1}{2}(uv - 1)^2.\]

&lt;p&gt;Hàm này &lt;strong&gt;không lồi&lt;/strong&gt; (ví dụ trung điểm của hai nghiệm tối ưu \((1, 1)\) và \((-1, -1)\) là \((0, 0)\) có giá trị \(F(0, 0) = 0.5 &amp;gt; 0\)!). Hãy tìm mọi điểm tới hạn của nó:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải \(\nabla F(u, v) = 0\):&lt;/strong&gt;
\(\nabla F(u, v) = \bigl(v(uv - 1),\; u(uv - 1)\bigr) = (0,\; 0).\)
Hệ này chỉ có đúng hai họ nghiệm:
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Họ 1 (Đa tạp cực tiểu toàn cục):&lt;/em&gt; Mọi điểm trên đường hyperbol \(uv = 1\) đều đạt \(F(u, v) = 0\) — có &lt;strong&gt;vô số&lt;/strong&gt; cực tiểu toàn cục nối liền nhau!&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Họ 2 (Điểm tới hạn ở gốc):&lt;/em&gt; \((u, v) = (0, 0)\) với \(F(0, 0) = 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra Hessian tại \((0, 0)\):&lt;/strong&gt;
\(H(u, v) = \begin{pmatrix} v^2 &amp;amp; 2uv - 1 \\ 2uv - 1 &amp;amp; u^2 \end{pmatrix} \implies H(0, 0) = \begin{pmatrix} 0 &amp;amp; -1 \\ -1 &amp;amp; 0 \end{pmatrix}.\)
Hai trị riêng của \(H(0, 0)\) là \(\lambda_1 = +1\) và \(\lambda_2 = -1\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận tuyệt đẹp:&lt;/strong&gt; Gốc tọa độ \((0, 0)\) là một &lt;strong&gt;điểm yên ngựa chặt&lt;/strong&gt; (trượt xuống dọc hướng \(u = v\)), và &lt;strong&gt;không tồn tại bất kỳ cực tiểu địa phương xấu nào&lt;/strong&gt; trên toàn bộ mặt phẳng \(\mathbb{R}^2\)! Chỉ một đa thức bậc 4 hai biến đã tái hiện trọn vẹn bức tranh hình học của Chương 28.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;địa-hình-hàm-mất-mát-không-lồi-trong-học-sâu&quot;&gt;Địa hình hàm mất mát không lồi trong học sâu&lt;/h1&gt;

&lt;p&gt;Tính lồi là nền tảng bảo đảm ở các Chương 02–25: mọi cực tiểu địa phương đều là cực tiểu toàn cục và điều kiện bậc nhất đủ để chứng nhận nghiệm tối ưu. Tuy nhiên, hàm mất mát huấn luyện \(F(w)\) của mạng nơ-ron sâu là &lt;strong&gt;không lồi&lt;/strong&gt;. Chương này khảo sát cụ thể những dạng phi lồi thực sự xuất hiện trong học sâu.&lt;/p&gt;

&lt;p&gt;Ta sẽ phân loại các &lt;strong&gt;điểm tới hạn&lt;/strong&gt; (\(\nabla F(w)=0\)) dựa trên dấu trị riêng của ma trận Hessian thành cực tiểu, cực đại và &lt;strong&gt;điểm yên ngựa (saddle point)&lt;/strong&gt;. Từ đó, ta thấy vì sao trong không gian nhiều chiều, các điểm yên ngựa mới là trở ngại phổ biến hơn các cực tiểu địa phương kém, và vì sao trạng thái &lt;strong&gt;quá tham số hóa&lt;/strong&gt; (số tham số lớn hơn số ràng buộc dữ liệu) lại khiến nhiều điểm cực tiểu đạt khả năng nội suy dữ liệu huấn luyện.&lt;/p&gt;

&lt;p&gt;Các giáo trình tối ưu hiện đại như EPFL CS-439 và USC CSCI 599 xem đây là phần kiến thức cốt lõi cho học sâu. Chương này dừng ở các định nghĩa chính xác cùng trực giác hình học, không đi vào các giới hạn phương trình đạo hàm riêng trường trung bình (mean-field PDE).&lt;/p&gt;

&lt;p&gt;Bạn có thể mở mô phỏng &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/loss_function_landscapes.html&quot;&gt;loss_function_landscapes.html&lt;/a&gt; trong quá trình đọc.&lt;/p&gt;

&lt;h2 id=&quot;nội-dung-các-bài&quot;&gt;Nội dung các bài&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Điểm tới hạn và điểm yên ngựa.&lt;/li&gt;
  &lt;li&gt;Thoát khỏi điểm yên ngựa và hình học địa hình hàm mất mát.&lt;/li&gt;
  &lt;li&gt;Quá tham số hóa (và giới thiệu điều kiện PL).&lt;/li&gt;
  &lt;li&gt;Các hiện tượng địa hình hiện đại (tùy chọn) — liên thông mode, grokking, double descent, cực tiểu phẳng.&lt;/li&gt;
  &lt;li&gt;Điều kiện Polyak–Łojasiewicz (PL) và tốc độ hội tụ tuyến tính (tùy chọn) — kết quả của Karimi và cộng sự, mở rộng chứng minh Chương 06 mà không cần tính lồi.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Bài tùy chọn &lt;a href=&quot;/contents/vi/chapter28/28_05_pl_condition/&quot;&gt;28-05&lt;/a&gt; xây dựng cầu nối từ tốc độ hội tụ lồi mạnh ở 06-03-04 sang lớp bài toán không lồi thỏa điều kiện PL, còn các hiện tượng thực nghiệm giai đoạn 2022–2026 được tổng hợp tại &lt;a href=&quot;/contents/vi/chapter28/28_04_modern_landscapes/&quot;&gt;28-04&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>27-03 Chiều nghịch và lan truyền ngược</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_03_reverse_mode_backprop/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_03_reverse_mode_backprop</id>
   <content type="html">&lt;p&gt;Nếu có một thuật toán duy nhất xứng đáng được gọi là “đòn bẩy tỷ đô” tạo nên kỷ nguyên học sâu hiện đại, đó chắc chắn là &lt;strong&gt;Vi phân tự động chiều nghịch (Reverse-Mode AD)&lt;/strong&gt; — mà trong mạng nơ-ron ta quen gọi là &lt;strong&gt;lan truyền ngược (backpropagation)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Bí mật kinh tế phi thường của chế độ nghịch nằm ở định lý Baur–Strassen (1983): dù hàm mất mát vô hướng \(\ell(w)\) phụ thuộc vào &lt;strong&gt;100 tỷ tham số&lt;/strong&gt;, chỉ cần chạy một lượt thuận lưu lại các giá trị trung gian rồi đi ngược đồ thị đúng &lt;strong&gt;một lần duy nhất&lt;/strong&gt;, ta thu được toàn bộ 100 tỷ đạo hàm riêng với tổng chi phí phép tính không quá \(4\)–\(5\) lần chi phí lượt thuận! Không có định lý này, mọi mô hình AI hiện đại đều sẽ mất hàng thiên niên kỷ để tính nổi một bước gradient.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-ad-chiều-nghịch-và-lan-truyền-ngược&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của AD chiều nghịch và Lan truyền ngược&lt;/h2&gt;

&lt;p&gt;Để làm chủ hoàn toàn cơ chế của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;loss.backward()&lt;/code&gt; trong PyTorch và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.grad&lt;/code&gt;, hãy nắm chắc ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lượt thuận lưu trữ &amp;amp; Lượt nghịch cộng dồn (Adjoint Accumulation):&lt;/strong&gt; Gắn cho mỗi nút \(v\) biến liên hợp \(\bar{v} = \frac{\partial \ell}{\partial v}\). Bắt đầu từ \(\bar{\ell} = 1\), ta đi ngược thứ tự topo và cộng dồn \(\bar{u} \mathrel{+}= \bar{v} \cdot \frac{\partial v}{\partial u}\) qua mọi mũi tên đi ra khỏi \(u\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tích Vector–Jacobian (VJP) và Chi phí \(O(m)\):&lt;/strong&gt; Một lượt nghịch tính chính xác \(\bar{y}^T J_f(x)\) (một tổ hợp tuyến tính các &lt;em&gt;hàng&lt;/em&gt; của Jacobian). Khi đầu ra là hàm mất mát vô hướng (\(m = 1\)), chỉ cần đúng &lt;strong&gt;1 lượt nghịch&lt;/strong&gt; để lấy toàn bộ gradient \(\nabla_w \ell \in \mathbb{R}^n\) — độc lập hoàn toàn với \(n\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh đổi Bộ nhớ – Tính toán (Memory Wall &amp;amp; Gradient Checkpointing):&lt;/strong&gt; Điểm yếu duy nhất của chế độ nghịch là phải giữ lại các giá trị kích hoạt trung gian từ lượt thuận (ví dụ \(v_1, v_2\) trong phép nhân \(v_1 v_2\)) cho tới khi lượt nghịch dùng xong. Khi huấn luyện mạng rất sâu, kỹ thuật &lt;em&gt;activation checkpointing&lt;/em&gt; chấp nhận bỏ bớt một số nút trung gian rồi tính lại cục bộ lúc đi ngược để tiết kiệm bộ nhớ GPU.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-1-lượt-ad-chiều-nghịch-lấy-trọn-gradient-của-fx_1-x_2--x_1-x_2--ex_1&quot;&gt;Giải thích: Chạy tay 1 lượt AD chiều nghịch lấy trọn gradient của \(f(x_1, x_2) = x_1 x_2 + e^{x_1}\)&lt;/h3&gt;

&lt;p&gt;Ta dùng lại đúng hàm và điểm \((x_1, x_2) = (0,\; 3)\) của Bài 27-02 để đối chiếu trực tiếp với chiều thuận!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Pha 1 — Lượt thuận (tính và lưu giá trị các nút vào bộ nhớ):&lt;/strong&gt;
\(v_1 = 0, \qquad v_2 = 3, \qquad v_3 = v_1 v_2 = 0, \qquad v_4 = e^{v_1} = 1, \qquad v_5 = v_3 + v_4 = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pha 2 — Lượt nghịch (khởi tạo \(\bar{v}_5 = 1\), các \(\bar{v}_k = 0\) rồi đi ngược từ \(v_5\) về \(v_1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Qua nút \(v_5 = v_3 + v_4\):&lt;/em&gt;
\(\bar{v}_3 \mathrel{+}= \bar{v}_5 \cdot 1 = 1, \qquad \bar{v}_4 \mathrel{+}= \bar{v}_5 \cdot 1 = 1.\)&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Qua nút \(v_4 = e^{v_1}\) (cần dùng lại \(v_1 = 0\) đã lưu!):&lt;/em&gt;
\(\bar{v}_1 \mathrel{+}= \bar{v}_4 \cdot e^{v_1} = 1 \cdot e^0 = 1.\)&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Qua nút \(v_3 = v_1 \cdot v_2\) (cần dùng lại \(v_1 = 0, v_2 = 3\) đã lưu!):&lt;/em&gt;
\(\bar{v}_1 \mathrel{+}= \bar{v}_3 \cdot v_2 = 1 \cdot 3 = 3 \implies \text{Tổng } \bar{v}_1 = 1 + 3 = 4!\)
\(\bar{v}_2 \mathrel{+}= \bar{v}_3 \cdot v_1 = 1 \cdot 0 = 0.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết quả sau đúng 1 lượt đi ngược:&lt;/strong&gt; Ta đồng thời nhận được &lt;strong&gt;cả vector gradient&lt;/strong&gt; \(\nabla f(0, 3) = (\bar{v}_1,\; \bar{v}_2) = (4,\; 0)\) — đặc biệt chú ý cách hai nhánh từ \(v_4\) (đóng góp \(1\)) và \(v_3\) (đóng góp \(3\)) tự động cộng dồn tại \(\bar{v}_1 = 4\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Vi phân tự động chiều nghịch (reverse-mode AD)&lt;/strong&gt; gắn cho mỗi nút \(v\) một biến &lt;strong&gt;liên hợp (adjoint)&lt;/strong&gt; \(\bar v = \frac{\partial \ell}{\partial v}\) đối với đầu ra vô hướng \(\ell\). Sau lượt thuận lưu lại các giá trị trung gian, thuật toán duyệt &lt;em&gt;ngược&lt;/em&gt; đồ thị và cộng dồn đạo hàm:&lt;/p&gt;

\[\bar u \mathrel{+}= \bar v\cdot \partial_u h
\quad\text{khi } v=h(u,\ldots).\]

&lt;p&gt;Chỉ trong một lượt duyệt ngược duy nhất, thuật toán thu được toàn bộ gradient \(\nabla_w \ell\) — tương ứng với một &lt;strong&gt;tích vector–Jacobian (VJP)&lt;/strong&gt; \((\nabla \ell)^\top J\). Chi phí tính toán chỉ gấp một hằng số nhỏ lần chi phí lượt thuận và &lt;em&gt;không phụ thuộc vào số lượng tham số&lt;/em&gt;. Tính chất này chính là nền tảng giúp việc huấn luyện các mạng nơ-ron sâu hàng triệu hoặc hàng tỷ tham số trở nên khả thi.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lan truyền ngược (backpropagation)&lt;/strong&gt; là trường hợp riêng của AD chiều nghịch áp dụng cho mạng nơ-ron nhiều lớp, trong đó biến liên hợp tại lớp \(k\) chính là tín hiệu sai số \(\delta^{(k)}\) quen thuộc (dùng \(k\) cho chỉ số lớp vì \(\ell\) đã là hàm mất mát):&lt;/p&gt;

\[\delta^{(k)} = \bigl(W^{(k+1)\top}\delta^{(k+1)}\bigr)\odot \phi&apos;(z^{(k)}).\]

&lt;p&gt;Về bản chất, không có phép biến đổi đặc biệt nào ngoài quy tắc dây chuyền: mỗi phép nhân ma trận và hàm kích hoạt chỉ là một nút sơ cấp với Jacobian cục bộ đã biết.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Ví dụ vô hướng: ℓ = (w2 * relu(w1 * x) - y)**2
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ell&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_ell&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_ell&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_w2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_w1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d_w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Bạn có thể đối chiếu kết quả trên với PyTorch bằng cách dựng cùng biểu thức với các tensor đặt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;requires_grad=True&lt;/code&gt; rồi gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ell.backward()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đánh đổi bộ nhớ.&lt;/strong&gt; Chế độ nghịch phải lưu lại các giá trị trung gian của lượt thuận để dùng khi duyệt ngược. Kỹ thuật &lt;em&gt;gradient checkpointing&lt;/em&gt; (tính lại một phần lượt thuận khi cần) đánh đổi thời gian tính toán lấy dung lượng bộ nhớ RAM/VRAM khi huấn luyện mô hình lớn — đây là kỹ thuật quản lý bộ nhớ trong cài đặt, không làm thay đổi giá trị đạo hàm.&lt;/p&gt;

&lt;p&gt;Tóm lại, hãy ưu tiên chế độ thuận khi bài toán có ít đầu vào và nhiều đầu ra, còn ưu tiên chế độ nghịch khi có một hàm mất mát vô hướng và rất nhiều tham số. Sự kết hợp hai chế độ (chẳng hạn tính tích Hessian–vector bằng lược đồ thuận-trên-nghịch) cho phép các phương pháp bậc hai và tối ưu hai mức giữ chi phí tuyến tính theo số chiều.&lt;/p&gt;

&lt;h3 id=&quot;chế-độ-thuận-và-nghịch-trong-khoảng-3-phút&quot;&gt;Chế độ thuận và nghịch trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/autodiff-forward-reverse_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Đồ thị tính toán của x₁x₂ + sin x₁: tiếp tuyến và số đối ngẫu, adjoint đi ngược, ví dụ ReLU của bài 27-03, và đếm số lượt quét.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>27-02 AD chiều thuận</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_02_forward_mode/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_02_forward_mode</id>
   <content type="html">&lt;p&gt;Nếu ta gõ nhẹ vào một đầu vào \(x_1\) một độ lệch nhỏ \(\dot{x}_1 = 1\), độ rung đó sẽ lan truyền xuôi theo từng mũi tên của đồ thị tính toán như hiệu ứng domino cho tới tận đầu ra \(f\). Đó chính là toàn bộ trực giác của &lt;strong&gt;Vi phân tự động chiều thuận (Forward-Mode AD)&lt;/strong&gt;: đi song hành với mỗi giá trị thực \(v_k\) là một “cái bóng” tiếp tuyến \(\dot{v}_k\) đo tốc độ thay đổi của nút đó theo hướng nhiễu ban đầu.&lt;/p&gt;

&lt;p&gt;Điểm tuyệt đẹp của chế độ thuận là &lt;strong&gt;không cần lưu lại toàn bộ đồ thị vào bộ nhớ&lt;/strong&gt; (bộ nhớ \(O(1)\) so với độ sâu!) và chỉ cần một lần chạy duy nhất để tính một &lt;strong&gt;tích Jacobian–vector (JVP)&lt;/strong&gt; \(J_f(x)\dot{x}\). Dù không phù hợp để tính gradient của mạng nơ-ron triệu tham số (\(n \gg m\)), chế độ thuận lại tỏa sáng rực rỡ khi \(n \ll m\) (mô phỏng vật lý ít tham số nhiều đầu ra) và khi tính đạo hàm bậc hai (Hessian–vector product).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-ad-chiều-thuận&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của AD chiều thuận&lt;/h2&gt;

&lt;p&gt;Để biết chính xác khi nào nên chọn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.jvp&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.func.jvp&lt;/code&gt; thay vì lan truyền ngược, hãy nắm ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đại số Số đối ngẫu (Dual Numbers):&lt;/strong&gt; Mỗi nút lưu cặp \((v, \dot{v})\) tương đương số \(v + \dot{v}\epsilon\) (với \(\epsilon^2 = 0\)). Luật cộng \((u, \dot{u}) + (w, \dot{w}) = (u+w,\; \dot{u}+\dot{w})\) và luật nhân \((u, \dot{u})\cdot(w, \dot{w}) = (uw,\; \dot{u}w + u\dot{w})\) tự động cài đặt quy tắc dây chuyền mà không cần dựng đồ thị riêng!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tích Jacobian–Vector (JVP) và Chi phí \(O(n)\):&lt;/strong&gt; Một lượt thuận trả về chính xác vector \(J_f(x)\dot{x} \in \mathbb{R}^m\) (một tổ hợp tuyến tính các &lt;em&gt;cột&lt;/em&gt; của Jacobian). Để lấy đủ cả ma trận Jacobian \(m \times n\), ta cần chạy \(n\) lượt với \(n\) vector cơ sở chuẩn — siêu nhanh khi \(n\) nhỏ (ví dụ \(n = 3\) tọa độ không gian, \(m = 10{,}000\) điểm lưới).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lợi thế bộ nhớ cực thấp:&lt;/strong&gt; Vì giá trị tiếp tuyến \(\dot{v}_k\) được tính ngay lập tức cùng lúc với \(v_k\), mọi biến trung gian sau khi dùng xong có thể giải phóng bộ nhớ ngay, trái ngược hoàn toàn với chế độ nghịch phải lưu trữ toàn bộ lịch sử lượt thuận.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-trọn-vẹn-bảng-ad-chiều-thuận&quot;&gt;Giải thích: Chạy tay trọn vẹn bảng AD chiều thuận&lt;/h3&gt;

&lt;p&gt;Hãy tính giá trị và đạo hàm riêng \(\frac{\partial f}{\partial x_1}\) của hàm \(f(x_1, x_2) = x_1 x_2 + e^{x_1}\) tại điểm \((x_1, x_2) = (0,\; 3)\) bằng AD chiều thuận với vector hạt giống \(\dot{x} = (1,\; 0)\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khởi tạo 2 nút đầu vào (giá trị thực \(v\) và tiếp tuyến \(\dot{v}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v_1 = x_1 = 0, \qquad \dot{v}_1 = 1\).&lt;/li&gt;
      &lt;li&gt;\(v_2 = x_2 = 3, \qquad \dot{v}_2 = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lan truyền xuôi qua từng phép toán sơ cấp:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Phép nhân \(v_3 = v_1 \cdot v_2\):&lt;/em&gt;
\(v_3 = 0 \cdot 3 = 0, \qquad \dot{v}_3 = \dot{v}_1 v_2 + v_1 \dot{v}_2 = 1(3) + 0(0) = 3.\)&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Phép mũ \(v_4 = e^{v_1}\):&lt;/em&gt;
\(v_4 = e^0 = 1, \qquad \dot{v}_4 = e^{v_1}\dot{v}_1 = 1 \cdot 1 = 1.\)&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Phép cộng đầu ra \(v_5 = v_3 + v_4\):&lt;/em&gt;
\(v_5 = 0 + 1 = 1, \qquad \dot{v}_5 = \dot{v}_3 + \dot{v}_4 = 3 + 1 = 4.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra chéo bằng giải tích:&lt;/strong&gt;
Đạo hàm giải tích là \(\frac{\partial f}{\partial x_1} = x_2 + e^{x_1} = 3 + e^0 = 4\) — &lt;strong&gt;khớp tuyệt đối!&lt;/strong&gt;
&lt;em&gt;Lưu ý quan trọng:&lt;/em&gt; Lượt chạy trên chỉ mới cho ta \(\frac{\partial f}{\partial x_1} = 4\); muốn biết thêm \(\frac{\partial f}{\partial x_2}\), ta buộc phải chạy lại lượt thuận thứ hai với hạt giống \(\dot{x} = (0, 1)\). Ở bài sau, bạn sẽ thấy AD chiều nghịch lấy &lt;strong&gt;cả hai&lt;/strong&gt; đạo hàm riêng này chỉ trong đúng 1 lượt!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Trong &lt;strong&gt;vi phân tự động chiều thuận (forward-mode AD)&lt;/strong&gt;, mỗi nút \(v\) trong đồ thị được gắn thêm một giá trị &lt;strong&gt;tiếp tuyến (tangent)&lt;/strong&gt; \(\dot v = \frac{\partial v}{\partial t}\) ứng với một hướng nhiễu đầu vào đã chọn (vector hạt giống \(\dot x\)). Nếu \(v=h(u,w)\), quy tắc dây chuyền cho:&lt;/p&gt;

\[\dot v = \partial_u h\cdot \dot u + \partial_w h\cdot \dot w.\]

&lt;p&gt;Thực thi chương trình gốc &lt;em&gt;đồng thời&lt;/em&gt; với các phép tính tiếp tuyến cho ra &lt;strong&gt;tích Jacobian–vector (JVP)&lt;/strong&gt; \(J_f(x)\, \dot x\) với chi phí chỉ bằng một hằng số nhỏ nhân chi phí tính \(f(x)\).&lt;/p&gt;

&lt;p&gt;Nếu hàm \(f:\mathbb{R}^n\to\mathbb{R}^m\) có ít đầu vào và nhiều đầu ra (\(n\ll m\)), chế độ thuận rất hiệu quả: chỉ cần \(n\) lượt chạy với các vector cơ sở chuẩn để thu được toàn bộ ma trận Jacobian. Ngược lại, khi \(n\gg m\) — chẳng hạn một hàm mất mát vô hướng (\(m=1\)) phụ thuộc hàng triệu trọng số (\(n \sim 10^6\)) — chế độ thuận không phù hợp vì cần tới \(n\) lượt chạy.&lt;/p&gt;

&lt;p&gt;So với sai phân hữu hạn \([f(x+\varepsilon e_i)-f(x)]/\varepsilon\) (vốn chịu sai số cắt cụt, sai số làm tròn và phụ thuộc vào việc chọn \(\varepsilon\)), AD chiều thuận cho kết quả chính xác đến độ chính xác dấu phẩy động mà không cần chọn tham số \(\varepsilon\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ minh họa.&lt;/strong&gt; Xét \(f(x_1,x_2)=x_1 x_2 + \sin(x_1)\). Với vector hạt giống \(\dot x=(1,0)\), ta thu được \(\dot f = x_2 + \cos(x_1) = \partial_{x_1}f\). Với hạt giống thứ hai \(\dot x=(0,1)\), ta thu được \(\dot f = x_1 = \partial_{x_2}f\).&lt;/p&gt;

&lt;p&gt;Chế độ thuận đặc biệt hữu ích khi phân tích độ nhạy của các bài toán &lt;em&gt;mô phỏng&lt;/em&gt; ít tham số (như phương pháp bắn cho phương trình vi phân thường — ODE shooting) hoặc khi kết hợp tính tích Hessian–vector theo lược đồ “thuận trên nghịch” (forward-over-reverse). Với học sâu, chế độ nghịch ở bài tiếp theo mới là công cụ chủ đạo.&lt;/p&gt;

&lt;h3 id=&quot;chế-độ-thuận-và-nghịch-trong-khoảng-3-phút&quot;&gt;Chế độ thuận và nghịch trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/autodiff-forward-reverse_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Đồ thị tính toán của x₁x₂ + sin x₁: tiếp tuyến và số đối ngẫu, adjoint đi ngược, ví dụ ReLU của bài 27-03, và đếm số lượt quét.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>27-01 Đồ thị tính toán</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_01_computational_graphs/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_01_computational_graphs</id>
   <content type="html">&lt;p&gt;Khi bạn viết một dòng code ngắn ngủi như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;loss = (w1 * x1 + w2 * x2 - y) ** 2&lt;/code&gt;, bộ vi xử lý không nhìn thấy nó như một công thức toán học trừu tượng — nó thực thi tuần tự từng phép nhân, phép cộng, phép trừ và phép bình phương, lưu từng kết quả tạm vào thanh ghi. Nếu vẽ mỗi kết quả tạm đó thành một nút tròn và nối các mũi tên thể hiện sự phụ thuộc dữ liệu, bạn sẽ thu được một &lt;strong&gt;đồ thị tính toán (computational graph)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Nhìn chương trình như một đồ thị có hướng không chu trình (DAG) là bước chuyển hóa tư duy then chốt của Chương 27: nhờ biểu diễn này, việc tính đạo hàm phức tạp cỡ nào cũng rút gọn thành việc &lt;strong&gt;duyệt đồ thị theo thứ tự topo&lt;/strong&gt; (từ đầu vào đến đầu ra hoặc ngược lại) và nhân dồn các đạo hàm cục bộ siêu đơn giản trên từng cạnh.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-đồ-thị-tính-toán&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của Đồ thị tính toán&lt;/h2&gt;

&lt;p&gt;Để nắm vững cấu trúc dữ liệu đứng sau &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.autograd&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jax.make_jaxpr&lt;/code&gt;, hãy hiểu rõ ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân rã thành Băng Wengert (Wengert Tape / Trace):&lt;/strong&gt; Mọi hàm số phức tạp đều phân rã thành một chuỗi tuyến tính các biến trung gian \(v_1, v_2, \dots, v_K\), trong đó mỗi \(v_k\) chỉ là kết quả của &lt;em&gt;một&lt;/em&gt; phép toán nguyên thủy áp lên các nút đi trước. Nhờ đó, thư viện AD chỉ cần biết đạo hàm của khoảng vài chục phép toán cơ bản!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính phân nhánh (Fan-out) và Quy tắc Cộng dồn (Multivariable Chain Rule):&lt;/strong&gt; Khi một biến \(u\) được dùng làm đầu vào cho &lt;em&gt;nhiều&lt;/em&gt; nút phía sau (ví dụ vừa vào phép nhân vừa vào hàm \(\cos\)), ảnh hưởng tổng của \(u\) lên đầu ra bằng &lt;strong&gt;tổng&lt;/strong&gt; đóng góp qua tất cả các đường đi xuất phát từ \(u\) — nguồn gốc của phép cộng dồn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+=&lt;/code&gt; trong lan truyền ngược.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đồ thị động (Define-by-Run) vs. Đồ thị tĩnh (Define-then-Run):&lt;/strong&gt; PyTorch dựng băng Wengert ngay khi chạy Python (linh hoạt với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for&lt;/code&gt; phụ thuộc dữ liệu, cực dễ gỡ lỗi), trong khi JAX (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jit&lt;/code&gt;) và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.compile&lt;/code&gt; truy vết thành đồ thị tĩnh để tối ưu hóa cấp trình biên dịch (gộp nhân tử, loại bỏ bộ nhớ thừa).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-lập-băng-wengert-cho-một-hàm-2-biến&quot;&gt;Giải thích: Tự tay lập Băng Wengert cho một hàm 2 biến&lt;/h3&gt;

&lt;p&gt;Hãy phân rã hàm số \(f(x, y) = (x \cdot y + \cos x)^2\) thành một đồ thị tính toán (băng Wengert) hoàn chỉnh và tính giá trị tại điểm \((x, y) = (0,\; 2)\):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Nút&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Phép toán nguyên thủy&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Giá trị tại \((0, 2)\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Đạo hàm cục bộ theo các nút cha&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(v_1\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Đầu vào \(x\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;—&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(v_2\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Đầu vào \(y\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(2\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;—&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(v_3\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(v_1 \cdot v_2\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0 \cdot 2 = 0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\frac{\partial v_3}{\partial v_1} = v_2 = 2,\quad \frac{\partial v_3}{\partial v_2} = v_1 = 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(v_4\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\cos(v_1)\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(\cos(0) = 1\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\frac{\partial v_4}{\partial v_1} = -\sin(v_1) = 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(v_5\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(v_3 + v_4\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0 + 1 = 1\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\frac{\partial v_5}{\partial v_3} = 1,\quad \frac{\partial v_5}{\partial v_4} = 1\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(v_6\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(v_5^2\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(1^2 = 1\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\frac{\partial v_6}{\partial v_5} = 2v_5 = 2\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Quan sát then chốt:&lt;/strong&gt; Nút đầu vào \(v_1 = x\) có hai mũi tên đi ra (tới \(v_3\) và tới \(v_4\)). Nhờ lưu sẵn cột “Giá trị” và cột “Đạo hàm cục bộ” trên băng Wengert này, ta đã có đủ mọi mảnh ghép để chạy AD chiều thuận (Bài 27-02) hoặc AD chiều nghịch (Bài 27-03) mà không cần động tới biểu thức gốc nữa!&lt;/p&gt;

&lt;p&gt;Một &lt;strong&gt;đồ thị tính toán (computational graph)&lt;/strong&gt; là một đồ thị có hướng không chu trình (DAG), trong đó mỗi nút biểu diễn một giá trị trung gian và các cạnh biểu diễn các phép toán sơ cấp (\(+\), \(\times\), \(\exp\), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;matmul&lt;/code&gt;, …). Các tham số, dữ liệu đầu vào và hàm mất mát vô hướng đều là các nút được đánh dấu trên đồ thị này.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ.&lt;/strong&gt; Xét hàm mất mát logistic trên một mẫu dữ liệu với vector trọng số \(w\in\mathbb{R}^2\):&lt;/p&gt;

\[z = w_1 x_1 + w_2 x_2, \quad p=\sigma(z), \quad \ell = -y\log p -(1-y)\log(1-p).\]

&lt;p&gt;Các nút của đồ thị gồm \(x\), \(w\), \(z\), \(p\) và \(\ell\). Đồ thị tính toán &lt;em&gt;chính là&lt;/em&gt; biểu diễn cấu trúc của chương trình. Khi một trọng số thay đổi, mọi nút phía sau đều chịu ảnh hưởng; nhiệm vụ của vi phân tự động là lan truyền độ nhạy từ đầu vào tới \(\ell\) (chiều thuận) hoặc kéo ngược độ nhạy từ \(\ell\) về các tham số (chiều nghịch).&lt;/p&gt;

&lt;p&gt;Có hai cách triển khai phổ biến trong các thư viện:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ghi băng động / define-by-run&lt;/strong&gt; (PyTorch): đồ thị (còn gọi là băng Wengert) được dựng trực tiếp trong lúc hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forward&lt;/code&gt; chạy; các cấu trúc rẽ nhánh và vòng lặp dùng thẳng cú pháp Python.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa trước khi chạy / define-then-run&lt;/strong&gt; (Theano trước đây, hoặc cơ chế truy vết &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jit&lt;/code&gt; của JAX): chương trình được biên dịch hoặc truy vết thành một đồ thị tĩnh rồi thực thi lặp lại nhiều lần.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hiểu cách quản lý đồ thị giải thích trực tiếp vì sao lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y.backward()&lt;/code&gt; trong PyTorch yêu cầu đồ thị còn tồn tại trong bộ nhớ: mặc định sau một lần gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;backward()&lt;/code&gt;, băng tính toán sẽ được giải phóng trừ khi truyền tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;retain_graph=True&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Vẽ đồ thị tính toán cho hàm mất mát \(\ell=\|W_2\,\phi(W_1 x)-y\|_2^2\) của một mạng một lớp ẩn và đếm số phép nhân ma trận ở lượt thuận. Chi phí này sẽ xuất hiện tương ứng ở lượt chiều nghịch.&lt;/p&gt;

&lt;h2 id=&quot;góc-nhìn-charu-aggarwal-đồ-thị-tính-toán-là-ngôn-ngữ-chung-của-tối-ưu-hóa-học-sâu&quot;&gt;Góc nhìn Charu Aggarwal: Đồ thị Tính toán là Ngôn ngữ Chung của Tối ưu hóa Học sâu&lt;/h2&gt;

&lt;p&gt;Trong &lt;em&gt;Linear Algebra and Optimization for Machine Learning&lt;/em&gt;, Charu Aggarwal nhấn mạnh rằng mạng nơ-ron nhiều lớp thực chất là sự hợp thành của hàng triệu phép toán đại số tuyến tính (nhân ma trận, tích vô hướng, hàm kích hoạt) biểu diễn trên một &lt;strong&gt;Đồ thị Có hướng Không chu trình (DAG)&lt;/strong&gt;. Nhờ quy tắc dây chuyền đa biến (&lt;em&gt;multivariable chain rule&lt;/em&gt;) lan truyền ngược từ nút mất mát \(L\) về từng trọng số, mọi kiến trúc từ hồi quy logistic, SVM đến Transformer đều quy về cùng một quy trình tính gradient \(O(1)\) lượt truyền xuôi–ngược.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>27 Vi phân tự động</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_00_automatic_differentiation/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter27/27_00_automatic_differentiation</id>
   <content type="html">&lt;p&gt;Nếu Chương 26 là động cơ lái xe của học sâu (SGD, AdamW), thì &lt;strong&gt;Vi phân tự động (Automatic Differentiation — AD)&lt;/strong&gt; ở Chương 27 chính là hệ thống cảm biến cung cấp nhiên liệu gradient cho động cơ đó. Điều đáng kinh ngạc là một mạng nơ-ron hiện đại có thể chứa hàng chục tỷ tham số và hàng nghìn lớp phép toán lồng nhau — vậy mà máy tính vẫn tính được &lt;strong&gt;chính xác toàn bộ vector gradient&lt;/strong&gt; chỉ trong một khoảng thời gian xấp xỉ vài lần chạy xuôi hàm mất mát!&lt;/p&gt;

&lt;p&gt;Hiểu sai phổ biến nhất của người mới là tưởng AD giống vi phân ký hiệu (như WolframAlpha rút gọn công thức) hoặc giống sai phân hữu hạn (cộng thêm \(\varepsilon\) nhỏ rồi chia). Thực tế, AD là một phát minh tinh tế hoàn toàn riêng biệt: nó không lấy đạo hàm &lt;em&gt;biểu thức&lt;/em&gt;, mà lấy đạo hàm &lt;strong&gt;chính dòng chảy thực thi của chương trình máy tính&lt;/strong&gt; bằng quy tắc dây chuyền.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-phân-biệt-ad-với-các-phương-pháp-tính-đạo-hàm-khác&quot;&gt;Kiến thức cần nhớ: Ba trụ cột phân biệt AD với các phương pháp tính đạo hàm khác&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch27_autodiff_forward_reverse.svg&quot; alt=&quot;Vi phân Tự động: Chế độ Xuôi vs. Chế độ Ngược&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Trước khi đi vào đồ thị tính toán và hai chế độ thuận/nghịch, hãy đặt AD lên bàn cân cùng hai phương pháp truyền thống:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vi phân ký hiệu (Symbolic Differentiation):&lt;/strong&gt; Biến đổi trực tiếp biểu thức toán học thành công thức đạo hàm tường minh. Nhược điểm chí mạng là hiện tượng &lt;strong&gt;bùng nổ biểu thức (expression swell)&lt;/strong&gt; và hoàn toàn bó tay trước các câu lệnh lập trình như vòng lặp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for&lt;/code&gt;, nhánh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if-else&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sai phân hữu hạn (Finite Differences):&lt;/strong&gt; Xấp xỉ \(\frac{f(x + \varepsilon e_i) - f(x)}{\varepsilon}\). Dễ cài nhưng vừa &lt;em&gt;không chính xác&lt;/em&gt; (kẹt giữa sai số cắt cụt khi \(\varepsilon\) lớn và sai số triệt tiêu số học khi \(\varepsilon\) quá nhỏ), vừa tốn tới \(n+1\) lần chạy hàm cho \(n\) tham số — bất khả thi khi \(n = 10^8\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vi phân tự động (Forward &amp;amp; Reverse Mode AD):&lt;/strong&gt; Phân rã chương trình thành dãy phép toán sơ cấp (\(+, \times, \sin, \exp, \dots\)) và truyền đạo hàm qua từng bước bằng quy tắc dây chuyền: &lt;em&gt;chính xác tuyệt đối đến độ chính xác dấu phẩy động&lt;/em&gt;, chạy được qua nhánh/vòng lặp, và đặc biệt ở chế độ nghịch chỉ tốn \(O(1)\) lần chạy hàm bất kể \(n\) lớn cỡ nào!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-tay-sai-phân-hữu-hạn-với-ad-số-đối-ngẫu-trên-fx--x2&quot;&gt;Giải thích: So sánh tay Sai phân hữu hạn với AD (Số đối ngẫu) trên \(f(x) = x^2\)&lt;/h3&gt;

&lt;p&gt;Xét hàm đơn giản \(f(x) = x^2\) tại điểm \(x = 3\), nơi đạo hàm chính xác là \(f&apos;(3) = 6\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Dùng sai phân hữu hạn \(\frac{f(3 + \varepsilon) - f(3)}{\varepsilon}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Chọn bước hơi lớn \(\varepsilon = 0.1\): \(\frac{3.1^2 - 3^2}{0.1} = \frac{9.61 - 9}{0.1} = 6.1\) — &lt;strong&gt;lệch mất \(0.1\)&lt;/strong&gt; (sai số cắt cụt).&lt;/li&gt;
      &lt;li&gt;Chọn bước quá nhỏ \(\varepsilon = 10^{-16}\) trong số thực 64-bit (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;): máy tính làm tròn \(3.0 + 10^{-16} = 3.0\), nên tử số bằng \(9.0 - 9.0 = 0.0\), kết quả ra &lt;strong&gt;\(0.0\)&lt;/strong&gt; — sai hoàn toàn \(100\%\) (sai số triệt tiêu)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng Vi phân tự động bằng số đối ngẫu (Dual Number \(x + \dot{x}\epsilon\) với quy ước \(\epsilon^2 = 0\)):&lt;/strong&gt;
Đưa đầu vào \(3 + 1\cdot\epsilon\) chạy thẳng qua phép bình phương của chương trình:
\(f(3 + \epsilon) = (3 + \epsilon)^2 = 3^2 + 2(3)\epsilon + \epsilon^2 = 9 + 6\epsilon + 0 = 9 + 6\epsilon.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đọc kết quả:&lt;/strong&gt; Phần thực trả về đúng giá trị hàm \(f(3) = 9\), còn hệ số của \(\epsilon\) trả về &lt;strong&gt;chính xác tuyệt đối \(f&apos;(3) = 6\)&lt;/strong&gt; — không cần chọn bước \(\varepsilon\), không có sai số cắt cụt, và không bao giờ gặp lỗi triệt tiêu!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;vi-phân-tự-động&quot;&gt;Vi phân tự động&lt;/h1&gt;

&lt;p&gt;Mọi bộ tối ưu ở Chương 26 đều cần tính gradient. Trong thực tế hiện nay, gradient hầu như không còn được tính thủ công trên giấy hay xấp xỉ bằng sai phân hữu hạn. &lt;strong&gt;Vi phân tự động (Automatic Differentiation — AD)&lt;/strong&gt; tính đạo hàm &lt;em&gt;chính xác đến sai số dấu phẩy động&lt;/em&gt; của một chương trình bằng cách áp dụng quy tắc dây chuyền (chain rule) một cách hệ thống lên từng phép toán sơ cấp.&lt;/p&gt;

&lt;p&gt;Chương này trả lời ba câu hỏi trọng tâm:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Đồ thị tính toán&lt;/strong&gt; là gì, và vì sao một hàm mất mát có thể xem như một chương trình?&lt;/li&gt;
  &lt;li&gt;AD &lt;strong&gt;chiều thuận&lt;/strong&gt; tính tích Jacobian–vector như thế nào?&lt;/li&gt;
  &lt;li&gt;Vì sao &lt;strong&gt;lan truyền ngược (backpropagation)&lt;/strong&gt; chính là AD chiều nghịch, và vì sao chế độ nghịch là lựa chọn mặc định khi bài toán có một hàm mất mát vô hướng và hàng triệu tham số?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tài liệu tổng quan nền tảng nên tham khảo là Baydin, Pearlmutter, Radul và Siskind, &lt;em&gt;Automatic Differentiation in Machine Learning: a Survey&lt;/em&gt;, JMLR 18(153), 2018, &lt;a href=&quot;https://www.jmlr.org/papers/v18/17-468.html&quot;&gt;jmlr.org/papers/v18/17-468.html&lt;/a&gt;. Ngay từ giáo trình cổ điển của Nocedal &amp;amp; Wright, bài toán tính đạo hàm đã là một phần thiết yếu của tối ưu số; vi phân tự động hiện đại là bước hoàn thiện về mặt phần mềm cho nền tảng đó.&lt;/p&gt;

&lt;h2 id=&quot;nội-dung-các-bài&quot;&gt;Nội dung các bài&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Đồ thị tính toán.&lt;/li&gt;
  &lt;li&gt;AD chiều thuận.&lt;/li&gt;
  &lt;li&gt;AD chiều nghịch và lan truyền ngược.&lt;/li&gt;
  &lt;li&gt;Khung vi phân tự động và học máy khoa học (tùy chọn) — PyTorch, JAX, Enzyme, PINN.&lt;/li&gt;
  &lt;li&gt;Tối ưu hai mức và siêu gradient (tùy chọn) — tối ưu siêu tham số (HPO) và học siêu cấp (meta-learning) dưới dạng bài toán lồng nhau.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Bài thực hành chính: tự cài đặt AD chiều nghịch trên một mạng ba nút và đối chiếu với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.autograd&lt;/code&gt; — nếu kết quả sai lệch, nguyên nhân nằm ở đồ thị tính toán hoặc thao tác &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;detach&lt;/code&gt; chứ không phải định nghĩa đạo hàm. Bản đồ các khung phần mềm nằm ở bài tùy chọn &lt;a href=&quot;/contents/vi/chapter27/27_04_autodiff_frameworks/&quot;&gt;27-04&lt;/a&gt;, còn khuôn khổ tối ưu hai mức cho HPO và MAML (khai triển vòng lặp so với vi phân ẩn) nằm ở &lt;a href=&quot;/contents/vi/chapter27/27_05_bilevel_hypergrad/&quot;&gt;27-05&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26-05 Giảm phương sai — SVRG và SAGA</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_05_variance_reduction/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_05_variance_reduction</id>
   <content type="html">&lt;p&gt;Nhìn lại hai thái cực của tối ưu tổng hữu hạn \(F(w) = \frac{1}{n}\sum_{i=1}^n f_i(w)\) khi \(F\) lồi mạnh: &lt;strong&gt;Full-Batch GD&lt;/strong&gt; hội tụ tuyến tính thần tốc (\(O(\log(1/\epsilon))\) bước), nhưng mỗi bước tốn \(O(n)\) phép tính; còn &lt;strong&gt;SGD&lt;/strong&gt; mỗi bước chỉ tốn \(O(1)\), nhưng lại bị kẹt ở tốc độ chậm \(O(1/\epsilon)\) vì nhiễu gradient không chịu tắt khi tới gần nghiệm \(w^\star\).&lt;/p&gt;

&lt;p&gt;Suốt nhiều năm, người ta tưởng phải chấp nhận một trong hai cái giá ấy — cho đến khi cuộc cách mạng &lt;strong&gt;giảm phương sai (Variance Reduction)&lt;/strong&gt; bùng nổ năm 2013–2014 với &lt;strong&gt;SVRG&lt;/strong&gt; (Johnson &amp;amp; Zhang) và &lt;strong&gt;SAGA&lt;/strong&gt; (Defazio, Bach &amp;amp; Lacoste-Julien). Bằng một thủ thuật thống kê kinh điển gọi là &lt;strong&gt;biến kiểm soát (control variate)&lt;/strong&gt;, họ đạt được điều tưởng chừng bất khả thi: &lt;strong&gt;chi phí mỗi bước chỉ \(O(1)\) như SGD, nhưng tốc độ hội tụ lại tuyến tính nhanh như Full-Batch GD&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-svrg-và-saga&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của SVRG và SAGA&lt;/h2&gt;

&lt;p&gt;Để nhìn xuyên qua các ký hiệu chỉ số trong bài và nắm ngay “phép màu” triệt tiêu phương sai, hãy nhớ ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nguyên lý Biến kiểm soát (Control Variate):&lt;/strong&gt; Cho biến ngẫu nhiên \(X = \nabla f_I(w)\) cần ước lượng kỳ vọng \(\nabla F(w)\). Nếu có một biến \(Y = \nabla f_I(\tilde{w})\) tương quan mạnh với \(X\) mà ta &lt;em&gt;biết chính xác kỳ vọng&lt;/em&gt; \(\mathbb{E}[Y] = \nabla F(\tilde{w})\), thì ước lượng hiệu chỉnh \(v = X - Y + \mathbb{E}[Y]\) vẫn &lt;strong&gt;không chệch&lt;/strong&gt;, nhưng phương sai của nó giảm từ \(\operatorname{Var}(X)\) xuống \(\operatorname{Var}(X - Y) \le L^2 \|w - \tilde{w}\|^2\) — tự động về \(0\) khi \(w, \tilde{w} \to w^\star\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVRG (Lưu điểm mốc theo từng vòng ngoài — ít bộ nhớ):&lt;/strong&gt; Cứ mỗi \(m\) bước trong, SVRG dừng lại tính một lần gradient toàn lô \(\tilde{\mu} = \nabla F(\tilde{w})\) tại điểm mốc \(\tilde{w}\), rồi dùng nó để hiệu chỉnh \(m\) bước ngẫu nhiên tiếp theo. Ưu điểm: không cần lưu bảng gradient (bộ nhớ \(O(d)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SAGA (Lưu bảng gradient — không cần vòng ngoài):&lt;/strong&gt; Giữ một bảng chứa gradient gần nhất của từng mẫu \(1, \dots, n\) và cập nhật 1 dòng mỗi bước. Ưu điểm: không cần tính full-batch định kỳ; nhược điểm: tốn bộ nhớ \(O(nd)\) (hoặc \(O(n)\) cho mô hình tuyến tính), và cả SVRG/SAGA đều phát huy mạnh nhất cho bài toán lồi tổng hữu hạn hơn là mạng sâu có data augmentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-để-thấy-phương-sai-svrg-triệt-tiêu-hoàn-toàn-tại-đích&quot;&gt;Giải thích: Tính tay để thấy phương sai SVRG triệt tiêu hoàn toàn tại đích&lt;/h3&gt;

&lt;p&gt;Xét hàm tổng hữu hạn gồm \(n = 2\) thành phần:&lt;/p&gt;

\[f_1(w) = \frac{1}{2}(w - 2)^2, \qquad f_2(w) = \frac{1}{2}(w + 2)^2, \qquad F(w) = \frac{f_1(w) + f_2(w)}{2} = \frac{1}{2}w^2 + 2.\]

&lt;p&gt;Nghiệm tối ưu toàn cục là \(w^\star = 0\) (\(\nabla F(0) = 0\)). Giả sử ta đang đứng đúng tại đích \(w = 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;SGD thông thường tại \(w = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu bốc mẫu \(I = 1\): \(\nabla f_1(0) = 0 - 2 = -2\).&lt;/li&gt;
      &lt;li&gt;Nếu bốc mẫu \(I = 2\): \(\nabla f_2(0) = 0 + 2 = +2\).
Kỳ vọng bằng \(0\), nhưng &lt;strong&gt;phương sai bằng \(4\)&lt;/strong&gt;! Dù đã đứng ngay tại nghiệm tối ưu \(w^\star = 0\), SGD vẫn bị đá văng khỏi đích ở mọi bước trừ khi ép \(\eta \to 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng SVRG tại \(w = 0\) với điểm mốc \(\tilde{w} = 0.1\):&lt;/strong&gt;
Tại mốc \(\tilde{w} = 0.1\), ta đã tính sẵn \(\nabla F(0.1) = 0.1\), còn \(\nabla f_1(0.1) = 0.1 - 2 = -1.9\) và \(\nabla f_2(0.1) = 0.1 + 2 = +2.1\).
Bây giờ tính vector cập nhật SVRG \(v = \nabla f_I(w) - \nabla f_I(\tilde{w}) + \nabla F(\tilde{w})\):
    &lt;ul&gt;
      &lt;li&gt;Nếu bốc mẫu \(I = 1\): \(v = (-2) - (-1.9) + 0.1 = -0.1 + 0.1 = 0\)!&lt;/li&gt;
      &lt;li&gt;Nếu bốc mẫu \(I = 2\): \(v = (+2) - (+2.1) + 0.1 = -0.1 + 0.1 = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kỳ diệu:&lt;/strong&gt; Cả hai nhánh ngẫu nhiên đều cho kết quả chính xác &lt;strong&gt;bằng 0&lt;/strong&gt; (phương sai triệt tiêu hoàn toàn!) vì thành phần lệch cố định \(-2\) và \(+2\) của từng mẫu đã bị trừ sạch bởi \(\nabla f_I(w) - \nabla f_I(\tilde{w})\)! Do đó SVRG dùng được bước học cố định \(\eta\) lớn mà vẫn hội tụ tuyến tính về đúng \(w^\star\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Giới hạn \(O(1/\sqrt{T})\) của SGD trên bài toán tổng hữu hạn lồi Lipschitz không phải là giới hạn bất khả kháng của lớp bài toán này. Đó là hệ quả của việc sử dụng gradient &lt;em&gt;không chệch nhưng vẫn còn nhiễu&lt;/em&gt; với phương sai không triệt tiêu ngay cả khi \(w\) đã tới sát điểm cực tiểu. Các phương pháp &lt;strong&gt;giảm phương sai (variance reduction)&lt;/strong&gt; tái sử dụng các gradient đã tính trước đó (tại một điểm mốc hoặc trong một bảng lưu trữ) để làm cho nhiễu ước lượng tiến về 0 khi \(w \to w^\star\). Bài này trình bày hai thuật toán nền tảng là SVRG và SAGA: đủ chi tiết đại số để hiểu &lt;em&gt;vì sao&lt;/em&gt; phương sai triệt tiêu, đủ rõ ràng để tự cài đặt, và xác định ranh giới thực tế về phạm vi áp dụng của chúng.&lt;/p&gt;

&lt;p&gt;Bạn có thể xem lại &lt;a href=&quot;/contents/vi/chapter26/26_01_sgd_and_minibatch/&quot;&gt;26-01&lt;/a&gt;, phần so sánh toàn lô và ngẫu nhiên ở &lt;a href=&quot;/contents/vi/chapter08/08_02_04_batch_vs_stochastic_methods/&quot;&gt;08-02-04&lt;/a&gt; và mô phỏng &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/stochastic_gradient_demo.html&quot;&gt;stochastic_gradient_demo.html&lt;/a&gt; để quan sát quỹ đạo SGD vẫn dao động xung quanh đáy sau khi đã tiến vào vùng lân cận nghiệm: phần dao động dư này chính là vấn đề mà giảm phương sai giải quyết.&lt;/p&gt;

&lt;h2 id=&quot;bài-toán-tổng-hữu-hạn-và-giới-hạn-của-sgd&quot;&gt;Bài toán tổng hữu hạn và giới hạn của SGD&lt;/h2&gt;

&lt;p&gt;Hàm rủi ro thực nghiệm là trung bình trên \(n\) hàm thành phần:&lt;/p&gt;

\[F(w)=\frac{1}{n}\sum_{i=1}^n f_i(w),\qquad
\nabla F(w)=\frac{1}{n}\sum_{i=1}^n \nabla f_i(w).\]

&lt;p&gt;Một bước SGD đơn mẫu sử dụng \(g_k=\nabla f_{I_k}(w_k)\). Nếu \(I_k\) rút đều và độc lập với \(w_k\) thì \(\mathbb{E}[g_k\mid w_k]=\nabla F(w_k)\), nhưng phương sai:&lt;/p&gt;

\[\mathbb{E}\bigl[\|g_k-\nabla F(w_k)\|_2^2\mid w_k\bigr]\]

&lt;p&gt;không nhất thiết tiến về 0 khi \(w_k\to w^\star\). Ngay tại điểm tối ưu toàn cục \(w^\star\), từng gradient thành phần \(\nabla f_i(w^\star)\) vẫn có thể khác 0 và chỉ có &lt;em&gt;trung bình&lt;/em&gt; của chúng bằng 0 (ví dụ trong hồi quy tuyến tính có nhiễu quan sát). Vì sàn nhiễu khác 0, SGD với bước hằng chỉ dao động trong một hình cầu bán kính tỉ lệ với \(\eta\sigma\) quanh \(w^\star\), còn muốn hội tụ chính xác phải giảm tốc độ học nên tốc độ dừng ở \(O(1/\sqrt{T})\) (hoặc \(O(1/T)\) khi lồi mạnh).&lt;/p&gt;

&lt;p&gt;Gradient descent toàn lô đạt hội tụ tuyến tính dưới tính lồi mạnh (Chương 06), nhưng mỗi bước tốn \(n\) lượt tính gradient. Giảm phương sai hướng tới mục tiêu đạt tốc độ hội tụ tuyến tính với chi phí phân bổ chỉ cỡ một vài gradient mỗi bước.&lt;/p&gt;

&lt;h2 id=&quot;ý-tưởng-biến-kiểm-soát-control-variate&quot;&gt;Ý tưởng biến kiểm soát (control variate)&lt;/h2&gt;

&lt;p&gt;Chọn một điểm mốc (snapshot) \(\tilde w\) tại đó ta chấp nhận tính &lt;em&gt;một lần&lt;/em&gt; gradient đầy đủ \(\mu=\nabla F(\tilde w)\). Với chỉ số ngẫu nhiên \(I\), xét ước lượng:&lt;/p&gt;

\[g(w)=\nabla f_I(w)-\nabla f_I(\tilde w)+\mu.\]

&lt;p&gt;Ước lượng này vẫn không chệch đối với \(\nabla F(w)\):&lt;/p&gt;

\[\mathbb{E}[g(w)]
=\nabla F(w)-\nabla F(\tilde w)+\nabla F(\tilde w)
=\nabla F(w).\]

&lt;p&gt;Khi \(w=\tilde w\), ta có \(g(\tilde w)=\mu=\nabla F(\tilde w)\) &lt;em&gt;chính xác&lt;/em&gt;, nghĩa là phương sai bằng 0 tại điểm mốc. Khi \(w\) gần \(\tilde w\) và mỗi \(\nabla f_i\) liên tục Lipschitz, hiệu \(\nabla f_I(w)-\nabla f_I(\tilde w)\) nhỏ, kéo theo phương sai của \(g(w)\) nhỏ. Đây chính là kỹ thuật &lt;strong&gt;biến kiểm soát&lt;/strong&gt;: trừ đi một thành phần nhiễu có tương quan cao rồi cộng bù lại đúng kỳ vọng của nó.&lt;/p&gt;

&lt;h2 id=&quot;svrg-johnson--zhang-2013&quot;&gt;SVRG (Johnson &amp;amp; Zhang, 2013)&lt;/h2&gt;

&lt;p&gt;SVRG định kỳ cập nhật điểm mốc ở vòng lặp ngoài và sử dụng ước lượng biến kiểm soát ở vòng lặp trong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vòng ngoài&lt;/strong&gt; \(s=0,1,\ldots,S-1\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Lưu điểm mốc \(\tilde w\leftarrow w\) và tính gradient đầy đủ \(\mu\leftarrow\nabla F(\tilde w)\) (tốn \(n\) gradient thành phần).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng trong&lt;/strong&gt; \(t=0,1,\ldots,m-1\): rút đều chỉ số \(I\) và cập nhật:
\(g\leftarrow\nabla f_I(w)-\nabla f_I(\tilde w)+\mu,\qquad
w\leftarrow w-\eta g.\)&lt;/li&gt;
  &lt;li&gt;Chọn điểm khởi đầu cho vòng ngoài tiếp theo (bằng trung bình các điểm lặp trong hoặc giữ nguyên \(w\) cuối cùng), rồi quay lại bước 1.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Với lựa chọn phổ biến \(m=\Theta(n)\), chi phí &lt;em&gt;phân bổ&lt;/em&gt; cho mỗi bước trong chỉ tương đương một hằng số nhỏ (khoảng 3 lượt tính gradient thành phần: 1 lượt phân bổ từ gradient đầy đủ và 2 lượt trong vòng trong). Bộ nhớ phụ chỉ gồm một điểm mốc \(\tilde w\) và một vector \(\mu\), tức \(O(d)\), không phụ thuộc số mẫu \(n\).&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý (phác thảo cho tổng hữu hạn lồi mạnh).&lt;/strong&gt; Nếu mỗi \(f_i\) trơn-\(L\) và \(F\) lồi mạnh-\(\mu\), thì với bước hằng \(\eta\) đủ nhỏ và độ dài vòng trong \(m\gtrsim L/\mu\), thuật toán thỏa mãn:&lt;/p&gt;

\[\mathbb{E}\bigl[F(\tilde w_{s+1})-F^\star\bigr]
\le \rho\,\mathbb{E}\bigl[F(\tilde w_s)-F^\star\bigr]\]

  &lt;p&gt;với hằng số \(\rho&amp;lt;1\). Tổng số lượt tính gradient thành phần để đạt sai số \(\varepsilon\) là \(O\bigl((n+\kappa)\log(1/\varepsilon)\bigr)\), trong đó \(\kappa=L/\mu\). SGD thuần túy không đạt được tốc độ \(\log(1/\varepsilon)\) này khi sàn nhiễu dương.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ý tưởng chứng minh dựa trên hàm Lyapunov: phương sai ở vòng trong bị chặn bởi khoảng cách \(\|w-\tilde w\|\), và khoảng cách này co dần khi điểm mốc \(\tilde w\) tiến gần \(w^\star\). Điều quan trọng nhất cần nắm vững là cơ chế tại công thức \(g=\nabla f_I(w)-\nabla f_I(\tilde w)+\mu\) giải thích vì sao phương sai giảm về 0.&lt;/p&gt;

&lt;h2 id=&quot;saga-defazio-bach-lacoste-julien-2014&quot;&gt;SAGA (Defazio, Bach, Lacoste-Julien, 2014)&lt;/h2&gt;

&lt;p&gt;SAGA loại bỏ bước tính gradient đầy đủ định kỳ bằng cách duy trì một &lt;strong&gt;bảng&lt;/strong&gt; \(g^{(1)},\ldots,g^{(n)}\) lưu gradient gần nhất của từng hàm thành phần \(f_i\). Khởi tạo \(g^{(i)}\leftarrow\nabla f_i(w_0)\) (hoặc khởi tạo bằng 0 kèm giai đoạn làm nóng ngắn) và lưu sẵn trung bình cộng \(\bar g=\frac1n\sum_i g^{(i)}\).&lt;/p&gt;

&lt;p&gt;Ở mỗi bước: rút chỉ số \(I\), tính gradient mới \(\nabla f_I(w)\), tạo ước lượng:&lt;/p&gt;

\[g\leftarrow \nabla f_I(w)-g^{(I)}+\bar g,\]

&lt;p&gt;cập nhật bảng \(g^{(I)}\leftarrow\nabla f_I(w)\), cập nhật trung bình \(\bar g\) trong \(O(d)\) bằng phép cộng trừ một phần tử, rồi cập nhật tham số \(w\leftarrow w-\eta g\).&lt;/p&gt;

&lt;p&gt;Về bản chất, đây là cùng công thức biến kiểm soát nhưng dùng các điểm mốc &lt;em&gt;cũ riêng cho từng mẫu&lt;/em&gt; thay vì một điểm mốc chung \(\tilde w\). Đổi lại cho việc bỏ vòng tính gradient đầy đủ là chi phí bộ nhớ \(O(nd)\) cho \(n\) vector gradient — hoặc rút xuống \(O(n)\) số vô hướng với các mô hình tuyến tính (do \(\nabla f_i(w)=(x_i^\top w-y_i)x_i\) chỉ cần lưu phần dư vô hướng). Chính vì vậy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sklearn.linear_model.LogisticRegression(solver=&quot;saga&quot;)&lt;/code&gt; rất hiệu quả trên bài toán ERM lồi cỡ vừa, nhưng SAGA không khả thi cho &lt;em&gt;mạng nơ-ron sâu&lt;/em&gt; quy mô lớn như ImageNet do không thể lưu bảng gradient cho mọi mẫu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SAG&lt;/strong&gt; (Schmidt, Le Roux, Bach) là phiên bản tiền nhiệm có chệch: thuật toán dùng trực tiếp trung bình bảng đã cập nhật (tức chỉ nhân phần hiệu chỉnh \(\nabla f_I(w)-g^{(I)}\) với hệ số \(1/n\) thay vì hệ số \(1\)). Việc dùng hệ số \(1\) trong SAGA khôi phục tính không chệch và giúp phân tích lý thuyết gọn gàng hơn.&lt;/p&gt;

&lt;h2 id=&quot;minh-họa-cài-đặt-svrg&quot;&gt;Minh họa cài đặt SVRG&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;clip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;40.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;40.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;svrg_logistic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inner&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;epochs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;inner&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inner&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inner&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;epochs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;# gradient đầy đủ
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;w_snap&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_t&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;yi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;yi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;g_snap&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_snap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;yi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_snap&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g_snap&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hãy so sánh thời gian thực thi (không chỉ số epoch) giữa đoạn mã trên và SGD minibatch ở mục 26-01 trên bài toán hồi quy logistic có chính quy hóa \(\ell_2\) (lồi mạnh) với \(n=5000\) để đạt \(\|\nabla F(w)\|_2\le 10^{-4}\). Sau đó thử cùng bài toán trên mạng nơ-ron có một lớp ẩn: chi phí tính điểm mốc đầy đủ đòi hỏi \(n\) lượt lan truyền ngược, bảng gradient của SAGA vượt quá bộ nhớ, và AdamW ở mục 26-04 trở nên thực tế hơn nhiều.&lt;/p&gt;

&lt;h2 id=&quot;bảng-so-sánh-phạm-vi-sử-dụng&quot;&gt;Bảng so sánh phạm vi sử dụng&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Bộ nhớ phụ&lt;/th&gt;
      &lt;th&gt;Chi phí phân bổ mỗi bước&lt;/th&gt;
      &lt;th&gt;Phạm vi phù hợp&lt;/th&gt;
      &lt;th&gt;Hội tụ tuyến tính trên tổng hữu hạn lồi mạnh?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;SGD / mini-batch&lt;/td&gt;
      &lt;td&gt;không&lt;/td&gt;
      &lt;td&gt;\(1\) (hoặc \(B\)) gradient&lt;/td&gt;
      &lt;td&gt;học sâu&lt;/td&gt;
      &lt;td&gt;không (do sàn nhiễu)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SVRG&lt;/td&gt;
      &lt;td&gt;một điểm mốc + \(\mu\)&lt;/td&gt;
      &lt;td&gt;\(\approx 3\) gradient&lt;/td&gt;
      &lt;td&gt;tổng hữu hạn lồi, nghiên cứu&lt;/td&gt;
      &lt;td&gt;có&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SAGA&lt;/td&gt;
      &lt;td&gt;một gradient mỗi mẫu&lt;/td&gt;
      &lt;td&gt;\(1\) gradient&lt;/td&gt;
      &lt;td&gt;ERM lồi cỡ vừa (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;saga&quot;&lt;/code&gt;)&lt;/td&gt;
      &lt;td&gt;có&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;AdamW&lt;/td&gt;
      &lt;td&gt;hai trung bình trượt mũ&lt;/td&gt;
      &lt;td&gt;\(1\) minibatch&lt;/td&gt;
      &lt;td&gt;mặc định cho học sâu&lt;/td&gt;
      &lt;td&gt;không phải mục tiêu thiết kế&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nắm vững SVRG và SAGA giúp nhận diện rõ những bài toán ERM &lt;em&gt;lồi&lt;/em&gt; (hồi quy logistic, SVM tuyến tính, các dạng Lasso làm trơn) mà ta không nên mặc định dùng Adam. Ngược lại, Adam theo minibatch vẫn vượt trội trên mạng nơ-ron sâu vì ba lý do: (i) chi phí tính hoặc lưu gradient đầy đủ quá lớn, (ii) hàm mất mát không lồi mạnh, và (iii) phần cứng GPU tối ưu cho phép nhân ma trận theo lô lớn thay vì cập nhật đơn mẫu trừ điểm mốc.&lt;/p&gt;

&lt;p&gt;Một số hướng liên quan (không kiểm tra): &lt;strong&gt;SARAH&lt;/strong&gt; và &lt;strong&gt;SPIDER&lt;/strong&gt; thay biến kiểm soát bằng ước lượng đệ quy giúp cải thiện cận lý thuyết; còn &lt;strong&gt;FedAvg&lt;/strong&gt; ở Chương 29 &lt;em&gt;không&lt;/em&gt; phải giảm phương sai (vì chỉ lấy trung bình trọng số), mặc dù biến kiểm soát trong thuật toán SCAFFOLD có thể xem là phiên bản học liên kết của SVRG.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Chứng minh tính không chệch của ước lượng SVRG trong một dòng, sau đó xây dựng một hàm bậc hai gồm hai thành phần sao cho phương sai của SGD thuần tại \(w^\star\) dương trong khi phương sai của SVRG tại điểm mốc \(\tilde w = w^\star\) bằng 0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Trên bài toán hồi quy logistic chính quy hóa ridge với \(n=5000\), vẽ chuẩn gradient theo &lt;em&gt;tổng số lượt tính gradient thành phần \(f_i\)&lt;/em&gt; cho SGD, SVRG và SAGA (nếu đủ bộ nhớ), đánh dấu các thời điểm tính điểm mốc của SVRG. Tiếp theo, vẽ lại các đường này theo thời gian thực thi (wall-clock time) và quan sát xem thứ tự hiệu năng giữa các phương pháp có thay đổi hay không.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Ước lượng biến kiểm soát \(g\) là không chệch với mọi \(w\), không riêng tại \(\tilde w\). Vậy tại sao vẫn cần định kỳ cập nhật điểm mốc \(\tilde w\) — điều gì sẽ xảy ra với \(\mathrm{Var}(g)\) nếu giữ cố định \(\tilde w\) khi \(w\) di chuyển ra xa?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26-04 AdamW và thực hành huấn luyện</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_04_adamw_and_practice/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_04_adamw_and_practice</id>
   <content type="html">&lt;p&gt;Trong suốt nhiều năm sau khi Adam ra đời (2015), giới học sâu vướng phải một bí ẩn khó chịu: Adam huấn luyện cực nhanh trên tập train, nhưng khi đánh giá trên tập test (như phân loại ảnh ImageNet hay huấn luyện Transformer), nó lại &lt;strong&gt;tổng quát hóa kém hơn SGD + Momentum&lt;/strong&gt; có suy giảm trọng số (weight decay).&lt;/p&gt;

&lt;p&gt;Năm 2017–2019, Ilya Loshchilov và Frank Hutter phát hiện ra một lỗi “ghép nhầm” tinh vi nằm ngay trong cách mọi thư viện cài đặt chính quy hóa \(\ell_2\) cho Adam: với SGD thuần, cộng \(\frac{\lambda}{2}\|w\|_2^2\) vào hàm mất mát tương đương hệt với việc co trọng số \((1 - \eta\lambda)w\); nhưng với &lt;strong&gt;Adam&lt;/strong&gt;, thành phần \(\lambda w\) lại bị đem chia cho \(\sqrt{\hat{v}}\), làm hỏng hoàn toàn cơ chế suy giảm trọng số! Chỉ bằng một dòng sửa duy nhất — &lt;strong&gt;tách rời weight decay ra khỏi phép chia thích nghi&lt;/strong&gt; — &lt;strong&gt;AdamW&lt;/strong&gt; ra đời và lập tức trở thành bộ tối ưu mặc định của kỷ nguyên LLM.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-thực-hành-huấn-luyện-mạng-sâu-với-adamw&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột thực hành huấn luyện mạng sâu với AdamW&lt;/h2&gt;

&lt;p&gt;Để huấn luyện mạng sâu ổn định từ đầu tới cuối, AdamW luôn đi cùng ba kỹ thuật thực hành không thể thiếu:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tách rời Suy giảm trọng số (Decoupled Weight Decay):&lt;/strong&gt; Trong AdamW, mọi trọng số chịu lực co đồng đều \(-\eta \lambda w_k\) bất kể gradient quá khứ lớn hay nhỏ. Nhờ vậy, siêu tham số \(\lambda\) và tốc độ học \(\eta\) không bị quấn chặt vào nhau như trong Adam + \(\ell_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lịch tốc độ học Warmup + Cosine Decay:&lt;/strong&gt; Ở vài trăm bước đầu, ước lượng mô-men \(\hat{v}_k\) còn rất nhiễu và trọng số còn ngẫu nhiên; tăng dần \(\eta\) từ \(0\) lên \(\eta_{\max}\) (&lt;em&gt;warmup&lt;/em&gt;) giúp tránh “sốc” gradient ban đầu, sau đó giảm mượt theo đường cong cosine để hạ cánh êm vào đáy thung lũng phẳng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cắt ngưỡng Gradient (Gradient Clipping):&lt;/strong&gt; Giới hạn chuẩn toàn cục \(\|g\|_2 \le \tau\) đóng vai trò van an toàn chống bùng nổ gradient khi gặp minibatch bất thường hoặc vách đá dốc trên địa hình phi lồi của Transformer/RNN.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ổn định số học với \(\varepsilon\) và Huấn luyện độ chính xác hỗn hợp:&lt;/strong&gt; Tham số \(\varepsilon\) (thường \(10^{-8}\)) không chỉ tránh chia cho 0 mà còn điều tiết mức độ “thích nghi” ở các tọa độ có gradient rất nhỏ; khi huấn luyện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fp16&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bf16&lt;/code&gt;, ta thường giữ bản sao trạng thái tối ưu (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;m, v&lt;/code&gt;) ở &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fp32&lt;/code&gt; để không mất độ chính xác.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-sự-khác-biệt-gây-sốc-giữa-adam--ell_2-và-adamw&quot;&gt;Giải thích: Tính tay sự khác biệt gây sốc giữa Adam + \(\ell_2\) và AdamW&lt;/h3&gt;

&lt;p&gt;Giả sử ta có hai trọng số cùng giá trị \(w_1 = 1.0\) và \(w_2 = 1.0\), tốc độ học \(\eta = 0.1\), hệ số phạt \(\lambda = 0.1\). Tọa độ 1 nằm ở lớp có gradient lịch sử lớn (\(\sqrt{\hat{v}_1} = 10\)), còn tọa độ 2 nằm ở lớp có gradient lịch sử nhỏ (\(\sqrt{\hat{v}_2} = 0.1\)). Để cô lập hoàn toàn tác dụng của lực suy giảm trọng số, giả sử gradient của hàm mất mát dữ liệu tại bước này bằng \(0\) (\(g_{\text{data}} = (0, 0)\), \(\hat{m}_{\text{data}} = (0, 0)\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Với Adam + chính quy hóa \(\ell_2\) (cộng \(\lambda w\) vào gradient trước khi chia \(\sqrt{\hat{v}}\)):&lt;/strong&gt;
Gradient tổng có thêm \(\lambda w = (0.1,\; 0.1)\). Khi đi qua phép chia thích nghi \(1/\sqrt{\hat{v}}\):
    &lt;ul&gt;
      &lt;li&gt;Lực kéo về 0 trên tọa độ 1: \(\Delta w_1 = -0.1 \cdot \frac{0.1}{10} = -0.001\) (chỉ giảm \(0.1\%\)!).&lt;/li&gt;
      &lt;li&gt;Lực kéo về 0 trên tọa độ 2: \(\Delta w_2 = -0.1 \cdot \frac{0.1}{0.1} = -0.100\) (giảm tới \(10\%\) — &lt;strong&gt;mạnh gấp 100 lần&lt;/strong&gt; tọa độ 1!).
Nghịch lý xảy ra: những trọng số có gradient lớn nhất (thường cần kiểm soát độ lớn nhất) lại hầu như &lt;strong&gt;không bị suy giảm&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Với AdamW (tách rời \(-\eta\lambda w_k\) ra ngoài phép chia \(\sqrt{\hat{v}}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Lực kéo về 0 trên tọa độ 1: \(\Delta w_1 = -0.1(0.1)(1.0) = -0.01\) (giảm \(1\%\)).&lt;/li&gt;
      &lt;li&gt;Lực kéo về 0 trên tọa độ 2: \(\Delta w_2 = -0.1(0.1)(1.0) = -0.01\) (giảm đúng \(1\%\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Chỉ một thay đổi nhỏ về vị trí dấu ngoặc đã khôi phục hoàn toàn tính đồng đều của weight decay trên mọi lớp mạng, giải thích vì sao AdamW đánh bại Adam + \(\ell_2\) trên hầu hết các mô hình Transformer hiện đại!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chính quy hóa \(\ell_2\) cộng thêm số hạng \(\frac{\lambda}{2}\|w\|_2^2\) vào hàm mất mát, khiến gradient tăng thêm \(\lambda w\). Khi tối ưu bằng &lt;strong&gt;Adam&lt;/strong&gt;, thành phần \(\lambda w\) này cũng bị chia bởi \(1/(\sqrt{\hat v}+\varepsilon)\). Hệ quả là các tọa độ có mô-men bậc hai lớn chịu lực suy giảm &lt;em&gt;nhỏ hơn&lt;/em&gt; so với các tọa độ có mô-men bậc hai nhỏ; tức là bộ tối ưu không còn áp dụng đúng phép suy giảm trọng số đồng đều như mục đích ban đầu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AdamW&lt;/strong&gt; (Loshchilov &amp;amp; Hutter, ICLR 2019, &lt;a href=&quot;https://arxiv.org/abs/1711.05101&quot;&gt;arXiv:1711.05101&lt;/a&gt;) &lt;strong&gt;tách rời&lt;/strong&gt; bước suy giảm trọng số khỏi phần thích nghi:&lt;/p&gt;

\[w_{k+1} = w_k - \eta \Bigl( \hat m \oslash (\sqrt{\hat v}+\varepsilon) + \lambda w_k \Bigr).\]

&lt;p&gt;Lúc này, suy giảm trọng số (weight decay) tác động trực tiếp như một lực co về gốc tọa độ trên không gian tham số, độc lập với hệ số co giãn thích nghi \(\sqrt{\hat v}\). Trong PyTorch, điều này tương ứng với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.optim.AdamW&lt;/code&gt;, khác với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.optim.Adam&lt;/code&gt; có tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;weight_decay&lt;/code&gt; (vốn cộng trực tiếp vào gradient theo kiểu chính quy hóa \(\ell_2\)).&lt;/p&gt;

&lt;h2 id=&quot;các-kỹ-thuật-thực-hành-gắn-liền-với-tối-ưu-hóa&quot;&gt;Các kỹ thuật thực hành gắn liền với tối ưu hóa&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lịch tốc độ học (learning rate schedule):&lt;/strong&gt; Khởi động tăng dần (warmup) rồi giảm theo hàm cosine hoặc tuyến tính chính là cách chọn dãy bước \(\eta_k\) biến thiên. Lý thuyết SGD lồi đã chỉ ra nhu cầu giảm dần tốc độ học; học sâu mở rộng thêm giai đoạn warmup để ổn định giai đoạn đầu khi ước lượng mô-men còn nhiễu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cắt ngưỡng gradient (gradient clipping):&lt;/strong&gt; Thay \(g\) bằng \(g\cdot \min(1, \tau/\|g\|)\) đóng vai trò như một vùng tin cậy đơn giản giới hạn độ dài bước ngẫu nhiên, đặc biệt quan trọng khi huấn luyện mạng hồi quy (RNN) và transformer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan hệ giữa kích thước lô và tốc độ học \(\eta\):&lt;/strong&gt; Quy tắc tỉ lệ tuyến tính (Goyal và cộng sự) coi minibatch lớn hơn là ước lượng ít nhiễu hơn nên có thể tăng \(\eta\) tương ứng cho tới một ngưỡng bão hòa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân biệt rõ cơ chế weight decay:&lt;/strong&gt; Khi báo cáo tham số “weight decay \(\lambda\)” trong thực nghiệm, cần nêu rõ đó là dạng tách rời (kiểu AdamW) hay cộng vào hàm mất mát (chính quy hóa \(\ell_2\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tài liệu đọc thêm (không thuộc phần lõi): SAM (Foret và cộng sự, ICLR 2021) hướng đến các cực tiểu &lt;em&gt;phẳng&lt;/em&gt; thông qua bài toán cực đại hóa cục bộ; còn Muon và Sophia là các bộ tối ưu mới đáng chú ý giai đoạn 2023–2025. Bài seminar tùy chọn &lt;a href=&quot;/contents/vi/chapter26/26_06_modern_optimizers/&quot;&gt;26-06&lt;/a&gt; tóm tắt công thức cập nhật của từng phương pháp (không lặp lại phần phân tích Sophia theo góc nhìn Newton ở mục 14-10); nội dung này không kiểm tra trong học kỳ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Huấn luyện một mạng MLP nhỏ trên tập dữ liệu 2 chiều &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;two-moons&lt;/code&gt; bằng cả Adam và AdamW với cùng hệ số \(\lambda\), sau đó vẽ đồ thị chuẩn \(\|w\|_2\) theo epoch. Dù đường hàm mất mát huấn luyện trông khá tương đồng, quỹ đạo của chuẩn tham số \(\|w\|_2\) sẽ khác biệt rõ rệt giữa hai bộ tối ưu.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26-03 AdaGrad, trực giác RMSProp, và Adam</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_03_adagrad_to_adam/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_03_adagrad_to_adam</id>
   <content type="html">&lt;p&gt;Trong mạng nơ-ron sâu hay mô hình ngôn ngữ, các tham số sống trong những “vũ trụ” hoàn toàn khác nhau: trọng số của từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;và&quot;&lt;/code&gt; nhận gradient lớn ở mọi minibatch, trong khi trọng số của một thuật ngữ hiếm chỉ nhận gradient khác 0 một lần sau mỗi nghìn bước. Ép cả triệu tham số khác biệt như vậy dùng chung một tốc độ học vô hướng \(\eta\) giống như bắt cả xe tải hạng nặng lẫn xe đạp đua đi cùng một lực đạp ga.&lt;/p&gt;

&lt;p&gt;Từ năm 2011 đến 2015, ba cột mốc liên tiếp — &lt;strong&gt;AdaGrad&lt;/strong&gt;, &lt;strong&gt;RMSProp&lt;/strong&gt; và &lt;strong&gt;Adam&lt;/strong&gt; — đã cách mạng hóa việc huấn luyện học sâu bằng một ý tưởng đơn giản mà cực kỳ hiệu quả: &lt;strong&gt;chia gradient của từng tọa độ cho căn bậc hai độ lớn lịch sử của chính nó&lt;/strong&gt;, giúp mọi tọa độ đều di chuyển với nhịp bước đồng đều bất kể độ thưa hay thang đo!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-bước-tiến-hóa-từ-adagrad-đến-adam&quot;&gt;Kiến thức cần nhớ: Ba bước tiến hóa từ AdaGrad đến Adam&lt;/h2&gt;

&lt;p&gt;Đặt ba công thức cạnh nhau, bạn sẽ thấy một chuỗi tiến hóa logic vô cùng mạch lạc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;AdaGrad (Cộng dồn toàn bộ lịch sử \(G_k\)):&lt;/strong&gt; Cộng tích lũy không quên \(G_{k+1} = G_k + g_k^2\). Rất xuất sắc cho dữ liệu thưa lồi (từ hiếm có \(G_k\) nhỏ nên được bước lớn), nhưng trong học sâu nhiều epoch, \(G_k\) phình to mãi làm tốc độ học hiệu dụng chết dần về \(0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;RMSProp (Trung bình trượt mũ — EMA \(v_k\)):&lt;/strong&gt; Thay tổng tích lũy bằng trung bình trượt mũ \(v_{k+1} = \gamma v_k + (1-\gamma)g_k^2\) để “quên” quá khứ xa và chỉ chuẩn hóa theo biên độ gradient gần đây, giữ cho bước học luôn sống động trên địa hình phi lồi thay đổi liên tục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adam (Kết hợp EMA bậc 1 + EMA bậc 2 + Hiệu chỉnh chệch):&lt;/strong&gt; Ghép động lượng \(m_k\) (hướng đi mượt) với chuẩn hóa \(v_k\) (thang đo thích nghi). Vì cả \(m_0 = 0, v_0 = 0\) khởi tạo từ 0, ở các bước đầu chúng bị kéo lệch mạnh về 0 — do đó phép chia hiệu chỉnh \(\hat{m}_k = \frac{m_k}{1 - \beta_1^k},\; \hat{v}_k = \frac{v_k}{1 - \beta_2^k}\) là bắt buộc để bước đi đầu tiên không bị méo!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-2-bước-adagrad-và-kiểm-chứng-hiệu-chỉnh-chệch-của-adam&quot;&gt;Giải thích: Tính tay 2 bước AdaGrad và kiểm chứng hiệu chỉnh chệch của Adam&lt;/h3&gt;

&lt;p&gt;Xét 2 tọa độ trọng số với dòng gradient: bước 1 là \(g^{(1)} = (10,\; 0)\) (tọa độ 1 dày đặc, tọa độ 2 chưa xuất hiện), bước 2 là \(g^{(2)} = (10,\; 1)\) (tọa độ 2 mới xuất hiện với gradient nhỏ). Lấy \(\eta = 0.1\) và bỏ qua \(\varepsilon\) nhỏ để tính tay sắc nét:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Theo dõi AdaGrad (\(G_0 = (0, 0)\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Bước 1:&lt;/em&gt; \(G_1 = (10^2,\; 0) = (100,\; 0)\). Bước cập nhật tọa độ 1 là \(-0.1 \cdot \frac{10}{\sqrt{100}} = -0.1\); tọa độ 2 là \(0\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Bước 2:&lt;/em&gt; \(G_2 = (100 + 100,\; 0 + 1) = (200,\; 1)\).
        &lt;ul&gt;
          &lt;li&gt;Tọa độ 1 (xuất hiện thường xuyên): bước giảm xuống \(-0.1 \cdot \frac{10}{\sqrt{200}} \approx -0.0707\).&lt;/li&gt;
          &lt;li&gt;Tọa độ 2 (đặc trưng hiếm mới xuất hiện): bước giữ nguyên kích thước đầy đủ \(-0.1 \cdot \frac{1}{\sqrt{1}} = -0.1000\)!
Dù gradient tọa độ 2 nhỏ gấp 10 lần tọa độ 1, AdaGrad lại cho tọa độ 2 bước đi &lt;strong&gt;lớn hơn&lt;/strong&gt; tọa độ 1!&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng vì sao Adam cần hiệu chỉnh chệch ở bước \(k = 1\) (\(\beta_1 = 0.9,\; \beta_2 = 0.999\)):&lt;/strong&gt;
Với \(g_1^{(1)} = 10\):
    &lt;ul&gt;
      &lt;li&gt;Chưa hiệu chỉnh: \(m_1 = 0.1(10) = 1.0\) và \(v_1 = 0.001(10^2) = 0.1\). Nếu chia thẳng: \(\frac{m_1}{\sqrt{v_1}} = \frac{1.0}{\sqrt{0.1}} \approx 3.162\) — &lt;strong&gt;phóng đại sai bước đi lên gấp 3.16 lần&lt;/strong&gt; chỉ vì \(\beta_2\) gần 1 hơn \(\beta_1\)!&lt;/li&gt;
      &lt;li&gt;Có hiệu chỉnh chệch: \(\hat{m}_1 = \frac{1.0}{1 - 0.9} = 10\) và \(\hat{v}_1 = \frac{0.1}{1 - 0.999} = 100\). Tỷ số là \(\frac{\hat{m}_1}{\sqrt{\hat{v}_1}} = \frac{10}{10} = 1.0\), cho bước cập nhật chuẩn xác \(-0.1 \cdot 1.0 = -0.1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Không phải mọi tọa độ của vector tham số \(w\) đều nên dùng chung một tốc độ học vô hướng \(\eta\). Các đặc trưng ít xuất hiện (chẳng hạn vector one-hot của từ hiếm) cần bước cập nhật hiệu dụng lớn hơn, trong khi các tọa độ thường xuyên có gradient lớn sẽ dễ phân kỳ nếu dùng cùng mức \(\eta\). Các &lt;strong&gt;phương pháp thích nghi đường chéo&lt;/strong&gt; giải quyết vấn đề này bằng cách duy trì ước lượng mô-men bậc hai của gradient cho từng tọa độ và chia bước cập nhật cho căn bậc hai của ước lượng đó.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AdaGrad&lt;/strong&gt; (Duchi, Hazan, Singer, 2011) cộng dồn bình phương gradient theo từng phần tử:&lt;/p&gt;

\[G_{k+1} = G_k + g_k \odot g_k, \qquad w_{k+1} = w_k - \eta\, g_k \oslash \bigl(\sqrt{G_{k+1}}+\varepsilon\bigr),\]

&lt;p&gt;trong đó \(g_k=\nabla f_{I_k}(w_k)\), còn \(\odot\) và \(\oslash\) lần lượt là phép nhân và phép chia theo từng phần tử. Vì tổng \(G_k\) chỉ tăng mà không quên quá khứ, tốc độ học hiệu dụng &lt;strong&gt;giảm đơn điệu&lt;/strong&gt; về 0. Điều này rất phù hợp với các bài toán lồi có đặc trưng thưa, nhưng lại gây đình trệ khi huấn luyện mạng nơ-ron sâu qua nhiều vòng lặp.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RMSProp&lt;/strong&gt; (Hinton, bài giảng trực tuyến) khắc phục nhược điểm trên bằng cách thay tổng tích lũy bằng trung bình trượt mũ (EMA): \(v_{k+1}=\gamma v_k + (1-\gamma)\,g_k\odot g_k\), cho phép hệ số tỉ lệ thích nghi linh hoạt theo độ lớn gradient gần đây.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adam&lt;/strong&gt; (Kingma &amp;amp; Ba, 2015) kết hợp trung bình trượt mũ của mô-men bậc hai (như RMSProp) với trung bình trượt mũ của mô-men bậc nhất (như momentum), đồng thời bổ sung hệ số hiệu chỉnh chệch vì cả hai đại lượng đều khởi tạo từ \(0\):&lt;/p&gt;

\[\begin{align}
m_{k+1} &amp;amp;= \beta_1 m_k + (1-\beta_1) g_k, \\
v_{k+1} &amp;amp;= \beta_2 v_k + (1-\beta_2)\, g_k\odot g_k, \\
\hat m &amp;amp;= m_{k+1}/(1-\beta_1^{k+1}), \quad
\hat v = v_{k+1}/(1-\beta_2^{k+1}), \\
w_{k+1} &amp;amp;= w_k - \eta\, \hat m \oslash (\sqrt{\hat v}+\varepsilon).
\end{align}\]

&lt;p&gt;Bộ tham số mặc định \(\beta_1=0.9\), \(\beta_2=0.999\), \(\varepsilon=10^{-8}\) hoạt động ổn định trên rất nhiều bài toán, dù vẫn cần điều chỉnh khi huấn luyện các mô hình đặc thù. Về bản chất, Adam là &lt;strong&gt;tiền điều kiện đường chéo kết hợp momentum&lt;/strong&gt;, không phải phương pháp bậc hai vì nó không xây dựng hay xấp xỉ đầy đủ ma trận Hessian.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;adam_step&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.999&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;vhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Tham khảo bài báo gốc tại &lt;a href=&quot;https://arxiv.org/abs/1412.6980&quot;&gt;arXiv:1412.6980&lt;/a&gt;. Bài tiếp theo sẽ phân tích vì sao việc cộng số hạng phạt \((\lambda/2)\|w\|_2^2\) vào hàm mất mát &lt;strong&gt;không&lt;/strong&gt; tương đương với suy giảm trọng số (weight decay) trong AdamW.&lt;/p&gt;

&lt;h3 id=&quot;adagrad--rmsprop--adam-trong-khoảng-3-phút&quot;&gt;AdaGrad → RMSProp → Adam trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/adagrad-rmsprop-adam_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Ba bước thích nghi trên cùng một hàm bậc hai lệch trục: AdaGrad chậm dần, RMSProp rung quanh nghiệm, Adam có hiệu chỉnh độ lệch.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26-02 Momentum và tăng tốc Nesterov</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_02_momentum_and_nesterov/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_02_momentum_and_nesterov</id>
   <content type="html">&lt;p&gt;Hãy hình dung một viên bi nặng lăn xuống một hẻm núi hình lòng chảo rất hẹp và dài: hai vách núi dốc đứng, còn đáy hẻm thì thoai thoải kéo dài hàng cây số. Nếu bạn chỉ đẩy viên bi theo đúng độ dốc tại chỗ rồi dừng lại ở mỗi bước (Gradient Descent thuần), viên bi sẽ liên tục &lt;strong&gt;đập qua đập lại giữa hai vách núi&lt;/strong&gt; mà gần như không nhích lên được bao nhiêu dọc theo đáy hẻm.&lt;/p&gt;

&lt;p&gt;Năm 1964, Boris Polyak mượn trực giác từ cơ học cổ điển để đề xuất &lt;strong&gt;phương pháp quả cầu nặng (Heavy Ball / Momentum)&lt;/strong&gt;: cho viên bi giữ lại một phần vận tốc cũ \(\beta v_k\). Các lực đập qua đập lại giữa hai vách núi ngược dấu nhau nên tự triệt tiêu, còn lực kéo xuôi dọc đáy hẻm cùng dấu nhau nên cộng hưởng mạnh mẽ! Gần hai thập kỷ sau, Yurii Nesterov (1983) tinh chỉnh thêm một bước thiên tài: &lt;strong&gt;nhìn trước một đoạn theo quán tính rồi mới đo độ dốc&lt;/strong&gt;, giúp phanh kịp trước khi lao quá đà lên vách núi đối diện.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-hình-học-của-momentum-và-nesterov&quot;&gt;Kiến thức cần nhớ: Ba trụ cột hình học của Momentum và Nesterov&lt;/h2&gt;

&lt;p&gt;Bài học này giải thích sức mạnh của động lượng qua lăng kính trực giác của bài viết Distill nổi tiếng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Số điều kiện \(\kappa = \lambda_{\max}/\lambda_{\min}\) và Giới hạn của GD thuần:&lt;/strong&gt; Trên hàm bậc hai \(\frac{1}{2}w^T A w\), GD bị kẹt giữa hai gọng kìm: cần \(\eta &amp;lt; 2/\lambda_{\max}\) để không nổ ở vách dốc, khiến hệ số co ở đáy phẳng bị chậm ở mức \(1 - 2/\kappa\) — muốn giảm sai số \(e\) lần cần \(O(\kappa)\) bước.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lọc thông thấp của Heavy Ball (\(\sqrt{\kappa}\) Speedup):&lt;/strong&gt; Động lượng đóng vai trò bộ lọc thông thấp đối với dãy gradient: thành phần đổi dấu liên tục (tần số cao) bị dập tắt, thành phần cùng hướng (tần số thấp) được khuếch đại lên tới \(\frac{1}{1-\beta}\) lần, rút số bước cần thiết từ \(O(\kappa)\) xuống \(O(\sqrt{\kappa})\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cơ chế “Nhìn trước để phanh” của Nesterov (NAG):&lt;/strong&gt; Thay vì tính gradient tại \(w_k\) rồi mới cộng quán tính \(\beta v_k\), Nesterov tính gradient tại điểm dự đoán \(w_k + \beta v_k\). Nếu quán tính sắp đưa điểm lặp vượt qua đáy thung lũng, gradient tại điểm nhìn trước lập tức đổi dấu để kéo ngược lại, tạo ra lực giảm chấn thông minh hơn Heavy Ball trên các hàm lồi tổng quát.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-tay-2-bước-gd-thuần-và-momentum-trên-hẻm-hẹp-kappa--9&quot;&gt;Giải thích: So sánh tay 2 bước GD thuần và Momentum trên hẻm hẹp \(\kappa = 9\)&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai 2 chiều có một phương phẳng (\(\lambda_1 = 1\)) và một phương dốc gấp 9 lần (\(\lambda_2 = 9\)):&lt;/p&gt;

\[F(w_1, w_2) = \frac{1}{2}(w_1^2 + 9w_2^2), \qquad \nabla F(w_1, w_2) = (w_1,\; 9w_2).\]

&lt;p&gt;Xuất phát từ \(w_0 = (1,\; 1)\) với tốc độ học \(\eta = 0.2\) (lưu ý giới hạn ổn định của GD là \(\eta &amp;lt; 2/9 \approx 0.222\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent thuần (\(w_{k+1} = w_k - 0.2 \nabla F(w_k)\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Bước 1:&lt;/em&gt; \(w_1 = (1 - 0.2(1),\; 1 - 0.2(9)) = (0.8,\; -0.8)\). (Thành phần \(w_2\) nhảy vọt qua \(0\) sang \(-0.8\)!).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Bước 2:&lt;/em&gt; \(w_2 = (0.8 - 0.2(0.8),\; -0.8 - 0.2(-7.2)) = (0.64,\; +0.64)\). (Tiếp tục đập zíc-zắc qua lại!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Heavy Ball Momentum với \(\beta = 0.5\) (\(v_{k+1} = 0.5 v_k - 0.2 \nabla F(w_k),\; w_{k+1} = w_k + v_{k+1}\), khởi tạo \(v_0 = (0, 0)\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Bước 1:&lt;/em&gt; \(v_1 = (-0.2,\; -1.8) \Rightarrow w_1 = (0.8,\; -0.8)\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Bước 2:&lt;/em&gt; Tại \(w_1 = (0.8, -0.8)\), gradient là \((0.8,\; -7.2)\).
Tính vận tốc mới:
\(v_2 = 0.5(-0.2,\; -1.8) - 0.2(0.8,\; -7.2) = (-0.1 - 0.16,\; -0.9 + 1.44) = (-0.26,\; +0.54).\)
Điểm mới:
\(w_2 = (0.8 - 0.26,\; -0.8 + 0.54) = (0.54,\; -0.26)!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh ấn tượng sau đúng 2 bước:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Dọc trục phẳng \(w_1\): Momentum tiến về \(0\) nhanh hơn (\(0.54\) so với \(0.64\) của GD) nhờ hai gradient cùng dấu cộng dồn!&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Dọc trục dốc \(w_2\): Momentum dập tắt dao động ngoạn mục ($$&lt;/td&gt;
              &lt;td&gt;-0.26&lt;/td&gt;
              &lt;td&gt;\(so với\)&lt;/td&gt;
              &lt;td&gt;0.64&lt;/td&gt;
              &lt;td&gt;\(của GD — giảm hơn 2.4 lần biên độ lắc!) nhờ vận tốc cũ\)-0.9\(triệt tiêu phần lớn cú bật ngược\)+1.44$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Trên các hàm bậc hai có số điều kiện xấu, gradient descent thường dao động zíc-zắc: kích thước bước đủ nhỏ để ổn định theo phương có độ cong lớn lại trở nên quá chậm theo phương phẳng. &lt;strong&gt;Động lượng (Momentum)&lt;/strong&gt; duy trì một vector vận tốc nhằm tích lũy các thành phần gradient cùng hướng và triệt tiêu các thành phần đổi dấu liên tục. Bài này tập trung vào trực giác hình học theo phong cách Distill thay vì lặp lại biến đổi đại số của FISTA ở &lt;a href=&quot;/contents/vi/chapter09/09_05_01_accelerated_proximal_gradient_method/&quot;&gt;09-05-01&lt;/a&gt; hay hoạt họa ở &lt;a href=&quot;/contents/vi/chapter06/06_06_gradent_descent_with_momentum/&quot;&gt;06-06&lt;/a&gt;. Bạn nên đọc song song bài viết của Goh, &lt;em&gt;&lt;a href=&quot;https://distill.pub/2017/momentum/&quot;&gt;Why Momentum Really Works&lt;/a&gt;&lt;/em&gt; (Distill, 2017).&lt;/p&gt;

&lt;h2 id=&quot;thung-lũng-bậc-hai-khiến-gd-thuần-hội-tụ-chậm&quot;&gt;Thung lũng bậc hai khiến GD thuần hội tụ chậm&lt;/h2&gt;

&lt;p&gt;Xét bài toán mô hình cơ bản cho mọi phương pháp bậc nhất:&lt;/p&gt;

\[F(w)=\tfrac12 w^\top A w,\qquad A=\operatorname{diag}(\lambda_1,\ldots,\lambda_d)\succ 0.\]

&lt;p&gt;Gradient của hàm là \(Aw\). Gradient descent với tốc độ học \(\eta\) tạo ra hệ thức tuyến tính \(w_{k+1}=(I-\eta A)w_k\), nên từng tọa độ riêng tiến triển độc lập theo lũy thừa \((1-\eta\lambda_i)^k\). Điều kiện ổn định trên phương có trị riêng lớn nhất đòi hỏi \(\eta&amp;lt;2/\lambda_{\max}\). Khi đó, trên phương phẳng nhất, hệ số co chỉ đạt \(1-\eta\lambda_{\min}\approx 1-2/\kappa\) với \(\kappa=\lambda_{\max}/\lambda_{\min}\) là số điều kiện. Đó là nguồn gốc của quỹ đạo zíc-zắc: điểm lặp bật qua lại giữa hai thành dốc của thung lũng và tiến rất chậm dọc đáy. Chương 06 đã chứng minh cùng hệ số co \(1-m/L\) dưới giả thiết lồi mạnh; ở đây ta quan sát trực tiếp hiện tượng đó qua hai thang độ cong trên hàm bậc hai.&lt;/p&gt;

&lt;p&gt;Mở &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/gradient_descent_demo.html&quot;&gt;gradient_descent_demo.html&lt;/a&gt; và kéo giãn một trục tọa độ để thấy rõ hành vi này của phương pháp bậc nhất không có bộ nhớ.&lt;/p&gt;

&lt;h2 id=&quot;heavy-ball-bộ-lọc-thông-thấp-đối-với-gradient&quot;&gt;Heavy ball: bộ lọc thông thấp đối với gradient&lt;/h2&gt;

&lt;p&gt;Phương pháp &lt;strong&gt;heavy ball của Polyak&lt;/strong&gt; (1964) bổ sung một biến vận tốc \(v_k\):&lt;/p&gt;

\[\begin{align}
v_{k+1} &amp;amp;= \beta v_k + \nabla F(w_k), \\
w_{k+1} &amp;amp;= w_k - \eta v_{k+1},
\end{align}\]

&lt;p&gt;với hệ số \(\beta\in[0,1)\). Cài đặt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SGD(momentum=…)&lt;/code&gt; của PyTorch thuộc họ này (quy ước nhân thêm \((1-\beta)\) ở mục 06-06 chỉ khác ở hệ số tỉ lệ của trung bình trượt mũ). Khai triển truy hồi cho:&lt;/p&gt;

\[v_{k+1}=\sum_{j=0}^{k}\beta^{k-j}\nabla F(w_j),\]

&lt;p&gt;cho thấy các thành phần gradient &lt;em&gt;giữ cùng dấu&lt;/em&gt; qua nhiều bước được cộng dồn, còn các thành phần &lt;em&gt;đổi dấu luân phiên&lt;/em&gt; tự triệt tiêu nhau. Đây chính là một bộ lọc thông thấp rời rạc: thành phần vuông góc với đáy thung lũng dao động rồi tắt dần, còn thành phần dọc theo thung lũng được khuếch đại đều đặn.&lt;/p&gt;

&lt;p&gt;Trên cùng hàm bậc hai, khử biến \(v\) cho ta hệ thức truy hồi bậc hai:&lt;/p&gt;

\[w_{k+1}=\bigl((1+\beta)I-\eta A\bigr)w_k-\beta w_{k-1}.\]

&lt;p&gt;Mỗi tọa độ riêng ứng với đa thức đặc trưng \(r^2-(1+\beta-\eta\lambda)r+\beta=0\). Khi biết trước số điều kiện \(\kappa\), bộ tham số tối ưu (như phân tích của Goh) đặt cả hai nghiệm lên đường tròn bán kính \((\sqrt{\kappa}-1)/(\sqrt{\kappa}+1)\):&lt;/p&gt;

\[\eta^\star=\Bigl(\frac{2}{\sqrt{\lambda_{\max}}+\sqrt{\lambda_{\min}}}\Bigr)^2,\qquad
\beta^\star=\Bigl(\frac{\sqrt{\kappa}-1}{\sqrt{\kappa}+1}\Bigr)^2.\]

&lt;p&gt;Hệ số co cải thiện từ \(1-\Theta(1/\kappa)\) lên \(1-\Theta(1/\sqrt{\kappa})\) — cùng mức cải thiện căn bậc hai theo số điều kiện như trong tăng tốc Nesterov. Ý chính cần nhớ không phải hai công thức tham số trên, mà là bản chất của phương pháp: &lt;strong&gt;momentum thay đổi cơ chế tắt dần trong thời gian rời rạc chứ không tính thêm thông tin gradient mới&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Một trực giác vật lý quen thuộc (đã nhắc ở mục 06-06) là phương trình vi phân heavy-ball \(m\ddot w+\gamma\dot w+\nabla F(w)=0\): ma sát quá nhỏ gây dao động vượt đích, còn ma sát quá lớn khiến chuyển động chậm chạp. Siêu tham số \(\beta\) đóng vai trò hệ số ma sát rời rạc tương ứng. Trong thực hành học sâu, các giá trị \(\beta=0.9\) (hoặc \(0.99\)) là lựa chọn mặc định ổn định vì ta hiếm khi biết trước \(\kappa\) của một mạng nơ-ron sâu.&lt;/p&gt;

&lt;h2 id=&quot;tăng-tốc-nesterov-tính-gradient-tại-điểm-nhìn-trước&quot;&gt;Tăng tốc Nesterov: tính gradient tại điểm nhìn trước&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tăng tốc Nesterov&lt;/strong&gt; giữ nguyên cấu trúc vận tốc nhưng tính gradient tại điểm &lt;em&gt;nhìn trước (look-ahead)&lt;/em&gt;:&lt;/p&gt;

\[\begin{align}
v_{k+1} &amp;amp;= \beta v_k + \nabla F(w_k-\eta\beta v_k), \\
w_{k+1} &amp;amp;= w_k-\eta v_{k+1}.
\end{align}\]

&lt;p&gt;Trong heavy ball, gradient tại điểm &lt;em&gt;hiện tại&lt;/em&gt; được cộng vào vận tốc vốn đã có quán tính lớn; nếu vận tốc đó sắp đưa điểm lặp vượt qua đáy, thuật toán chỉ phát hiện ở bước sau. Ngược lại, bước nhìn trước đánh giá độ dốc tại vị trí ước lượng &lt;em&gt;phía trước một bước theo vận tốc hiện tại&lt;/em&gt;, giúp hiệu chỉnh hướng sớm hơn một nhịp và giảm biên độ vượt đích.&lt;/p&gt;

&lt;p&gt;Đối với hàm &lt;em&gt;lồi và trơn&lt;/em&gt;, khi lập lịch \(\beta_k\) thích hợp (công thức cổ điển \(\beta_k=(t_k-1)/t_{k+1}\) với \(t_{k+1}=(1+\sqrt{1+4t_k^2})/2\), hoặc trọng số \((k-2)/(k+1)\) như trong FISTA ở &lt;a href=&quot;/contents/vi/chapter09/09_05_01_accelerated_proximal_gradient_method/&quot;&gt;09-05-01&lt;/a&gt;), phương pháp đạt tốc độ hội tụ tối ưu trong lớp bậc nhất:&lt;/p&gt;

\[F(w_T)-F^\star=O\bigl(L\|w_0-w^\star\|_2^2/T^2\bigr).\]

&lt;p&gt;Cần lưu ý định lý này đòi hỏi hàm \(F\) &lt;em&gt;lồi&lt;/em&gt; và hệ số \(\beta_k\) &lt;em&gt;thay đổi theo vòng lặp&lt;/em&gt;. Tùy chọn Nesterov trong học sâu (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.optim.SGD(..., nesterov=True)&lt;/code&gt;) thường dùng \(\beta\) &lt;em&gt;hằng số&lt;/em&gt; trên hàm mất mát không lồi; do đó chứng minh lý thuyết giúp hiểu cơ chế giảm dao động, nhưng không nên suy diễn trực tiếp tốc độ \(O(1/T^2)\) cho độ chính xác trên tập dữ liệu ảnh.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Lý thuyết và thực hành.&lt;/strong&gt; Tốc độ $$O(1/T^2)$$ của Nesterov đòi hỏi $$\beta_k$$ được lập lịch và $$F$$ lồi trơn; hệ số $$\sqrt{\kappa}$$ của heavy ball đòi hỏi hàm bậc hai (hoặc xấp xỉ bậc hai cục bộ). Phần trực giác giữ lại khi sang huấn luyện với AdamW là cơ chế lọc: các hướng nhất quán được duy trì qua nhiều bước, các hướng dao động bị làm dịu, và bước nhìn trước giúp điều tiết quán tính sớm hơn.
&lt;/div&gt;

&lt;h2 id=&quot;cài-đặt-và-quan-sát&quot;&gt;Cài đặt và quan sát&lt;/h2&gt;

&lt;p&gt;Hai phương pháp chỉ khác nhau ở đúng đối số truyền vào gradient. Ngay trên hàm bậc hai hai chiều \(F(w)=\tfrac12 w^\top\operatorname{diag}(1,100)\,w\), quỹ đạo của chúng đã khác biệt rõ rệt:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;diag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;100.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;heavy_ball&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nesterov&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;look&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;look&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hãy xuất phát cả hai thuật toán từ cùng một điểm \(w_0\), thử các giá trị \(\beta\in\{0,0.5,0.8,0.9,0.99\}\) với cùng bước \(\eta\) ổn định cho GD thuần, rồi vẽ các quỹ đạo để quan sát ngưỡng \(\beta\) bắt đầu làm mượt zíc-zắc và ngưỡng gây dao động vượt đích.&lt;/p&gt;

&lt;p&gt;Về liên hệ giữa các chương: FISTA ở Chương 09 là phiên bản &lt;em&gt;proximal&lt;/em&gt; của cùng cơ chế nhìn trước cho bài toán hợp thành \(g+h\); Adam ở Chương 26 dùng trung bình trượt mũ cho cả gradient (chính là momentum) lẫn bình phương gradient từng tọa độ; còn giảm phương sai (&lt;a href=&quot;/contents/vi/chapter26/26_05_variance_reduction/&quot;&gt;26-05&lt;/a&gt;) giải quyết một vấn đề khác — triệt tiêu nhiễu &lt;em&gt;lấy mẫu&lt;/em&gt; chứ không phải zíc-zắc do &lt;em&gt;số điều kiện&lt;/em&gt;.&lt;/p&gt;

&lt;h3 id=&quot;momentum-và-nesterov-trong-khoảng-4-phút&quot;&gt;Momentum và Nesterov trong khoảng 4 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/momentum-nesterov_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Heavy ball và Nesterov trên thung lũng ½(w₁² + 100w₂²): đếm số bước, quét β, và trường hợp Nesterov phân kỳ khi η quá lớn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Cài đặt ba hàm cập nhật trên với \(A=\operatorname{diag}(1,100)\) (\(\kappa=100\)), xuất phát từ \(w_0=(1,1)\), \(v_0=0\). Đếm số vòng lặp đến khi \(\Vert w\Vert_2\le 10^{-4}\) cho: (a) GD với \(\eta=2/(\lambda_{\min}+\lambda_{\max})\), bước tối ưu của GD; (b) heavy ball với cặp \((\eta^\star,\beta^\star)\) của Goh; (c) Nesterov với \(\eta=1/\lambda_{\max}\) và \(\beta=(\sqrt{\kappa}-1)/(\sqrt{\kappa}+1)\). (Để kiểm tra: 478, 71 và 112 vòng lặp.) Sau đó chạy Nesterov với \(\eta^\star\) và giải thích vì sao nó phân kỳ. Gợi ý: \(\eta^\star\lambda_{\max}\approx 3.3&amp;gt;2\). Heavy ball vẫn ổn định khi \(\eta\lambda&amp;lt;2(1+\beta)\), còn Nesterov áp bước gradient tại điểm nhìn trước nên cần bước gần \(1/\lambda_{\max}\). Cuối cùng, phá cách chỉnh tham số: giữ \(\eta=1/\lambda_{\max}\) cho cả hai phương pháp momentum và đặt \(\beta=0.99\). Phương pháp nào dao động mạnh hơn, và vì sao bước nhìn trước giúp giảm dao động? (Để kiểm tra: heavy ball cần khoảng 1430 vòng lặp, Nesterov khoảng 390.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Trên cùng bài toán bậc hai, thay \(A\) bằng một ma trận đối xứng xác định dương ngẫu nhiên có cùng tập trị riêng (\(A=Q\operatorname{diag}(\lambda)Q^\top\)). Kiểm chứng rằng lợi ích của momentum phụ thuộc vào &lt;em&gt;phổ trị riêng&lt;/em&gt; chứ không phụ thuộc vào việc hàm mục tiêu có thẳng hàng theo trục tọa độ hay không.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Với nhận xét thực nghiệm rằng SGD dễ thoát khỏi vùng trũng nông hơn GD toàn lô, ta nên điều chỉnh \(\beta\) theo hướng nào khi chuyển từ hàm bậc hai sang một mạng nơ-ron không lồi nhỏ, và mô hình bộ lọc thông thấp dự đoán điều gì đối với thành phần nhiễu gradient đổi dấu liên tục giữa các minibatch?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26-01 SGD và minibatch</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_01_sgd_and_minibatch/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_01_sgd_and_minibatch</id>
   <content type="html">&lt;p&gt;Năm 1951, Herbert Robbins và Sutton Monro xuất bản một bài báo thống kê ngắn chỉ 8 trang về xấp xỉ ngẫu nhiên — đặt nền móng toán học cho &lt;strong&gt;Hạ gradient ngẫu nhiên (SGD)&lt;/strong&gt;. Hơn bảy thập kỷ sau, công thức một dòng \(w_{k+1} = w_k - \eta_k \nabla f_{I_k}(w_k)\) ấy vẫn là nhịp tim của cả ngành học máy.&lt;/p&gt;

&lt;p&gt;Điều thú vị nhất của SGD nằm ở sự cân bằng tinh tế của kích thước lô \(B\) (minibatch size) và cách lấy mẫu: tăng \(B\) giúp giảm phương sai nhiễu theo tỷ lệ \(1/B\) và tận dụng tối đa năng lực song song của GPU, nhưng vượt quá ngưỡng bão hòa phần cứng, tăng \(B\) lại khiến số bước cập nhật mỗi giây giảm đi. Thêm vào đó, trong thực tế hầu như ai cũng &lt;strong&gt;xáo trộn dữ liệu không hoàn lại (random reshuffling)&lt;/strong&gt; thay vì lấy mẫu i.i.d. — và hóa ra toán học hiện đại đã chứng minh cách làm thực tế đó &lt;em&gt;nhanh hơn&lt;/em&gt; lấy mẫu có hoàn lại!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-sgd-và-minibatch&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của SGD và Minibatch&lt;/h2&gt;

&lt;p&gt;Để hiểu đúng cả định lý hội tụ lẫn cách chỉnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;batch_size&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lr&lt;/code&gt; khi huấn luyện mô hình, hãy nắm ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính không chệch và Sàn phương sai (Unbiasedness &amp;amp; Variance Floor):&lt;/strong&gt; Với bước học cố định \(\eta\), SGD hội tụ nhanh về một quả cầu bán kính tỉ lệ với \(\eta \sigma^2 / B\) quanh nghiệm \(w^\star\) rồi dừng lại ở “sàn nhiễu” đó. Muốn sai số tiến hẳn về \(0\), ta buộc phải giảm dần \(\eta_k\) theo điều kiện Robbins–Monro (\(\sum \eta_k = \infty,\; \sum \eta_k^2 &amp;lt; \infty\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy luật mở rộng tuyến tính theo kích thước lô (Batch Size Scaling):&lt;/strong&gt; Khi tăng kích thước lô lên \(B\) lần (trong vùng nhiễu chiếm ưu thế), phương sai giảm \(B\) lần, cho phép tăng tốc độ học lên tương ứng mà vẫn giữ ổn định động lực học — nhưng chỉ hiệu quả tới ngưỡng &lt;em&gt;kích thước lô tới hạn (critical batch size)&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xáo trộn không hoàn lại vs. Lấy mẫu i.i.d.:&lt;/strong&gt; Lấy mẫu không hoàn lại trong mỗi epoch tạo ra &lt;strong&gt;tương quan âm&lt;/strong&gt; giữa các gradient liên tiếp trong cùng một epoch (nếu đầu epoch bốc phải mẫu lệch dương, cuối epoch chắc chắn sẽ bốc mẫu lệch âm để bù lại), giúp triệt tiêu sai số tích lũy nhanh hơn lấy mẫu i.i.d.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-phương-sai-của-minibatch--có-hoàn-lại-so-với-không-hoàn-lại&quot;&gt;Giải thích: Tính tay phương sai của Minibatch — có hoàn lại so với không hoàn lại&lt;/h3&gt;

&lt;p&gt;Giả sử tại điểm \(w_k\) hiện tại, tập dữ liệu có \(n = 4\) mẫu với 4 giá trị gradient vô hướng là \(1,\; 3,\; 5,\; 7\). Gradient toàn lô chính xác là \(\mu = \frac{1 + 3 + 5 + 7}{4} = 4\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;SGD đơn mẫu (\(B = 1\)):&lt;/strong&gt;
Bốn độ lệch so với \(\mu = 4\) là \(-3,\; -1,\; +1,\; +3\).
Phương sai ước lượng là:
\(\sigma^2 = \frac{(-3)^2 + (-1)^2 + 1^2 + 3^2}{4} = \frac{9 + 1 + 1 + 9}{4} = 5.0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minibatch \(B = 2\) lấy mẫu i.i.d. (có hoàn lại):&lt;/strong&gt;
Hai mẫu độc lập có trung bình \(\bar{g}_2 = \frac{g_{I_1} + g_{I_2}}{2}\), nên phương sai giảm đúng một nửa:
\(\operatorname{Var}_{\text{i.i.d.}}(\bar{g}_2) = \frac{\sigma^2}{2} = \frac{5.0}{2} = 2.5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minibatch \(B = 2\) lấy mẫu không hoàn lại (xáo trộn thực tế):&lt;/strong&gt;
Có đúng \(\binom{4}{2} = 6\) cặp mẫu khác nhau có thể rút ra, với các trung bình cộng lần lượt là:
\(\frac{1+3}{2}=2,\quad \frac{1+5}{2}=3,\quad \frac{1+7}{2}=4,\quad \frac{3+5}{2}=4,\quad \frac{3+7}{2}=5,\quad \frac{5+7}{2}=6.\)
Phương sai trên 6 cặp này là:
\(\operatorname{Var}_{\text{no-repl}}(\bar{g}_2) = \frac{(2-4)^2 + (3-4)^2 + 0^2 + 0^2 + (5-4)^2 + (6-4)^2}{6} = \frac{4 + 1 + 1 + 4}{6} = \frac{10}{6} \approx 1.667!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhận xét:&lt;/strong&gt; Phương sai giảm hẳn từ \(2.5\) xuống \(1.667\) (bằng đúng hệ số hiệu chỉnh tổng thể hữu hạn \(\frac{n-B}{n-1} = \frac{4-2}{4-1} = \frac{2}{3}\) nhân với \(2.5\)). Đó chính là lý do định lượng vì sao &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shuffle=True&lt;/code&gt; trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DataLoader&lt;/code&gt; luôn vượt trội lấy mẫu i.i.d.!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hàm rủi ro thực nghiệm là trung bình cộng trên \(n\) mẫu dữ liệu, và gradient của nó cũng có dạng trung bình tương ứng:&lt;/p&gt;

\[\nabla F(w) = \frac{1}{n}\sum_{i=1}^n \nabla f_i(w).\]

&lt;p&gt;&lt;strong&gt;Hạ gradient ngẫu nhiên (Stochastic Gradient Descent — SGD)&lt;/strong&gt; thay toàn bộ tổng trên bằng gradient tại một chỉ số ngẫu nhiên \(I_k\) rút (có hoàn lại hoặc không hoàn lại) từ \(\{1,\ldots,n\}\):&lt;/p&gt;

\[w_{k+1} = w_k - \eta_k \nabla f_{I_k}(w_k).\]

&lt;p&gt;Nếu \(I_k\) được chọn đều và độc lập với \(w_k\), ước lượng gradient là &lt;strong&gt;không chệch&lt;/strong&gt;: \(\mathbb{E}[\nabla f_{I_k}(w_k)\mid w_k]=\nabla F(w_k)\). Một &lt;strong&gt;minibatch&lt;/strong&gt; kích thước \(B\) lấy trung bình trên \(B\) mẫu như vậy. Khi các mẫu độc lập, phương sai của ước lượng giảm theo tỉ lệ \(1/B\), trong khi thời gian tính mỗi bước tăng gần tuyến tính theo \(B\) cho tới khi tận dụng hết năng lực song song của GPU. Đây là sự đánh đổi cơ bản khi chọn kích thước lô.&lt;/p&gt;

&lt;h2 id=&quot;các-tốc-độ-hội-tụ-cần-nắm&quot;&gt;Các tốc độ hội tụ cần nắm&lt;/h2&gt;

&lt;p&gt;Dưới các giả thiết chuẩn về tính Lipschitz và phương sai bị chặn, SGD trên hàm mục tiêu lồi Lipschitz với tốc độ học giảm dần \(\eta_k \propto 1/\sqrt{k}\) (hoặc bước hằng kết hợp lấy trung bình điểm lặp) thỏa mãn:&lt;/p&gt;

\[\mathbb{E}\bigl[F(\bar w_T)-F^\star\bigr] = O\bigl(\sigma / \sqrt{T}\bigr)\]

&lt;p&gt;theo số bước &lt;em&gt;ngẫu nhiên&lt;/em&gt; \(T\) (Bubeck, Chương 6). Với bài toán trơn và lồi mạnh, SGD có thể đạt tốc độ tuyến tính nếu nhiễu triệt tiêu tại điểm cực tiểu, nhưng mạng nơ-ron sâu nhìn chung không lồi mạnh. Bài học thực hành rút ra là: &lt;strong&gt;nhiều bước cập nhật rẻ với gradient nhiễu thường đạt hiệu quả thực tế tốt hơn ít bước với gradient chính xác&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Chương 06 đã so sánh GD và SGD trên tổng nhỏ; bạn có thể mở lại &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/stochastic_gradient_demo.html&quot;&gt;stochastic_gradient_demo.html&lt;/a&gt; để quan sát quỹ đạo nhiễu vẫn tiến đều về đáy.&lt;/p&gt;

&lt;h2 id=&quot;xáo-trộn-dữ-liệu-so-với-lấy-mẫu-iid&quot;&gt;Xáo trộn dữ liệu so với lấy mẫu i.i.d.&lt;/h2&gt;

&lt;p&gt;Phân tích lý thuyết thường giả sử các chỉ số được rút độc lập cùng phân phối (i.i.d.). Tuy nhiên, trong thực hành người ta hầu như luôn dùng &lt;strong&gt;xáo trộn ngẫu nhiên (random reshuffling)&lt;/strong&gt;: hoán vị toàn bộ \(n\) mẫu ở đầu mỗi epoch rồi duyệt tuần tự không hoàn lại. Lấy mẫu không hoàn lại thường hội tụ nhanh hơn về mặt thực nghiệm và cũng là chủ đề nghiên cứu lý thuyết tích cực giai đoạn 2010–2020. Về mặt triển khai, nên xáo trộn lại dữ liệu ở mỗi epoch để tránh lặp cố định cùng một thứ tự.&lt;/p&gt;

&lt;h2 id=&quot;minh-họa-với-hồi-quy-logistic&quot;&gt;Minh họa với hồi quy logistic&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;clip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sgd_logistic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;batch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;epochs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;epochs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;permutation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;batch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;batch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hãy thử so sánh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;batch=1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;batch=16&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;batch=n&lt;/code&gt; (gradient đầy đủ) trên một tập dữ liệu phân loại nhị phân theo thời gian thực thi (wall-clock time) cần để đạt cùng một mức hàm mất mát, chứ không chỉ đếm số epoch.&lt;/p&gt;

&lt;h3 id=&quot;sgd-và-minibatch-trong-khoảng-3-phút&quot;&gt;SGD và minibatch trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/sgd-minibatch_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Ví dụ m = 3 điểm: một bước GD so với một epoch SGD, bước hằng so với bước giảm dần, rồi ảnh hưởng của kích thước batch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Nếu SGD thường dễ thoát khỏi các vùng trũng nông hơn so với GD toàn lô, nhận xét này nên ảnh hưởng thế nào đến cách chọn kích thước minibatch ban đầu cho một mô hình quá tham số hóa?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26 Phương pháp ngẫu nhiên và thích nghi cho học máy</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_00_stochastic_and_adaptive_methods/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter26/26_00_stochastic_and_adaptive_methods</id>
   <content type="html">&lt;p&gt;Nếu bạn muốn huấn luyện một mô hình ngôn ngữ trên hàng nghìn tỷ token bằng gradient descent toàn lô (full-batch GD), bạn sẽ phải đọc hết toàn bộ kho văn bản internet chỉ để thực hiện… &lt;strong&gt;đúng một bước cập nhật trọng số&lt;/strong&gt;. Trong thế giới dữ liệu khổng lồ của học máy hiện đại, sự hoàn hảo của gradient chính xác lại trở thành kẻ thù lớn nhất của tốc độ.&lt;/p&gt;

&lt;p&gt;Chương 26 đánh dấu bước ngoặt từ tối ưu cổ điển sang &lt;strong&gt;tối ưu ngẫu nhiên và thích nghi&lt;/strong&gt; — động cơ thực sự vận hành đằng sau PyTorch, JAX và mọi hệ thống học sâu ngày nay. Thay vì chờ tính đủ gradient của \(n\) mẫu, ta chấp nhận một ước lượng nhiễu từ một lô nhỏ (minibatch) để đi nhanh gấp hàng nghìn lần, rồi dùng &lt;strong&gt;động lượng (momentum)&lt;/strong&gt;, &lt;strong&gt;co giãn thích nghi theo tọa độ (Adam/AdamW)&lt;/strong&gt; và &lt;strong&gt;giảm phương sai (SVRG/SAGA)&lt;/strong&gt; để thuần hóa nhiễu đó.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tối-ưu-ngẫu-nhiên-hiện-đại&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tối ưu ngẫu nhiên hiện đại&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch26_stochastic_adaptive_opt.svg&quot; alt=&quot;Tối ưu hóa Ngẫu nhiên &amp;amp; Thích nghi Quy mô lớn&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Toàn bộ Chương 26 được xây dựng trên bốn trụ cột kỹ thuật bổ trợ cho nhau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng ngẫu nhiên và Đánh đổi Phương sai – Tốc độ (SGD &amp;amp; Minibatch):&lt;/strong&gt; Thay tổng \(n\) thành phần bằng trung bình trên \(B\) mẫu ngẫu nhiên giữ nguyên tính không chệch (\(\mathbb{E}[g_k] = \nabla F(w_k)\)) nhưng tạo ra sàn nhiễu tỉ lệ với \(\sigma^2 / B\), dẫn tới tốc độ \(O(1/\sqrt{T})\) thay vì \(O(1/T)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lọc nhiễu và Tăng tốc bằng Quán tính (Momentum &amp;amp; Nesterov):&lt;/strong&gt; Tích lũy trung bình trượt của các gradient quá khứ vừa giúp triệt tiêu dao động zíc-zắc trên hẻm hẹp (số điều kiện \(\kappa\) lớn), vừa tăng cường tốc độ dọc theo đáy thung lũng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiền điều kiện đường chéo thích nghi (AdaGrad → RMSProp → Adam → AdamW):&lt;/strong&gt; Tự động gán một tốc độ học riêng cho từng tham số dựa trên lịch sử bình phương gradient, và đặc biệt tách rời suy giảm trọng số (weight decay) khỏi phép chia thích nghi trong AdamW.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến kiểm soát giảm phương sai (SVRG &amp;amp; SAGA):&lt;/strong&gt; Khi bài toán có dạng tổng hữu hạn lồi mạnh, ta tận dụng một “mốc” gradient cũ để triệt tiêu phương sai khi tiến gần nghiệm, khôi phục hội tụ tuyến tính với chi phí mỗi bước chỉ bằng SGD!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-tay-1-epoch-của-full-batch-gd-và-sgd&quot;&gt;Giải thích: So sánh tay 1 epoch của Full-Batch GD và SGD&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa tổng hữu hạn gồm \(n = 2\) mẫu:&lt;/p&gt;

\[F(w) = \frac{1}{2}\Bigl[f_1(w) + f_2(w)\Bigr] = \frac{1}{2}\left[\frac{1}{2}(w - 2)^2 + \frac{1}{2}(w - 6)^2\right],\]

&lt;p&gt;có nghiệm tối ưu toàn cục là trung bình cộng \(w^\star = 4\). Xuất phát từ \(w_0 = 0\) với tốc độ học \(\eta = 0.5\), hãy so sánh kết quả sau &lt;strong&gt;đúng 2 lần tính gradient đơn mẫu (1 epoch)&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Full-Batch GD (dùng cả 2 lần tính gradient cho 1 bước duy nhất):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tính \(\nabla f_1(0) = 0 - 2 = -2\) và \(\nabla f_2(0) = 0 - 6 = -6\).&lt;/li&gt;
      &lt;li&gt;Gradient toàn lô: \(\nabla F(0) = \frac{-2 + (-6)}{2} = -4\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Sau 1 epoch: \(w_1^{\text{GD}} = 0 - 0.5(-4) = 2.0\) (vẫn còn cách đích $$&lt;/td&gt;
              &lt;td&gt;2.0 - 4&lt;/td&gt;
              &lt;td&gt;= 2.0$$).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SGD (cập nhật ngay sau mỗi mẫu, tổng vẫn chỉ 2 lần tính gradient):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Bước 1 (mẫu 1):&lt;/em&gt; \(\nabla f_1(0) = -2 \Rightarrow w_{0.5} = 0 - 0.5(-2) = 1.0\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Bước 2 (mẫu 2, tính tại điểm mới \(w_{0.5} = 1.0\)!):&lt;/em&gt; \(\nabla f_2(1.0) = 1.0 - 6 = -5 \Rightarrow w_1^{\text{SGD}} = 1.0 - 0.5(-5) = 3.5\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận trực giác:&lt;/strong&gt; Với cùng ngân sách tính toán 1 epoch, SGD đã tiến tới \(3.5\) (chỉ còn cách đích \(0.5\) — gấp 4 lần gần hơn GD!), vì nó biết tận dụng ngay thông tin của mẫu 1 trước khi xử lý mẫu 2. Cái giá phải trả sẽ lộ diện ở gần đích \(w = 4\): khi đó \(\nabla f_1(4) = +2 \neq 0\) và \(\nabla f_2(4) = -2 \neq 0\), khiến SGD tiếp tục rung lắc quanh \(4\) nếu không giảm \(\eta\) hoặc dùng kỹ thuật giảm phương sai.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;phương-pháp-ngẫu-nhiên-và-thích-nghi-cho-học-máy&quot;&gt;Phương pháp ngẫu nhiên và thích nghi cho học máy&lt;/h1&gt;

&lt;p&gt;Các Chương 06–09 tập trung vào phương pháp bậc nhất &lt;strong&gt;toàn lô (full-batch)&lt;/strong&gt;, nơi mỗi bước tính gradient (hoặc toán tử proximal) đều duyệt qua toàn bộ tập huấn luyện. Trong học máy hiện đại, cách làm đó hiếm khi khả thi ở quy mô lớn. Chương này trình bày bộ công cụ tiêu chuẩn cho bài toán cực tiểu hóa rủi ro thực nghiệm (ERM):&lt;/p&gt;

\[\min_w F(w) = \frac{1}{n}\sum_{i=1}^n f_i(w), \qquad f_i(w) = \ell\bigl(h_w(x_i), y_i\bigr).\]

&lt;p&gt;Các ý tưởng liên quan đã xuất hiện trong &lt;a href=&quot;/contents/vi/chapter06/06_05_stochastic_gradient_descent/&quot;&gt;06-05 Hạ gradient ngẫu nhiên&lt;/a&gt; và phần dưới đạo hàm ngẫu nhiên ở Chương 08. Ở đây, ta trình bày có hệ thống từ SGD và minibatch đến hai thành phần cốt lõi trong mọi thư viện học sâu: &lt;strong&gt;động lượng (momentum) / tăng tốc Nesterov&lt;/strong&gt; và &lt;strong&gt;điều chỉnh bước học thích nghi theo tọa độ&lt;/strong&gt; (AdaGrad → trực giác RMSProp → Adam → AdamW). Bài bắt buộc cuối cùng giới thiệu các phương pháp giảm phương sai (SVRG, SAGA) để làm rõ khi nào lý thuyết tối ưu lồi cho tốc độ vượt trội hơn Adam.&lt;/p&gt;

&lt;h2 id=&quot;vì-sao-cần-tách-thành-một-chương-riêng&quot;&gt;Vì sao cần tách thành một chương riêng&lt;/h2&gt;

&lt;p&gt;Với các tập dữ liệu lớn như ImageNet hay kho ngữ liệu của mô hình ngôn ngữ, gradient descent toàn lô không chỉ bị giới hạn bởi số vòng lặp mà chủ yếu bị chặn bởi &lt;em&gt;bộ nhớ và thời gian thực thi (wall-clock time)&lt;/em&gt;. Thay gradient đầy đủ bằng một ước lượng không chệch (hoặc gần không chệch) tính từ một mẫu hoặc một minibatch kích thước \(B\ll n\) cho phép thực hiện nhiều bước cập nhật tham số hơn trong cùng một khoảng thời gian, đánh đổi bằng nhiễu lấy mẫu. Các phương pháp thích nghi xử lý nhiễu này bằng cách co giãn tốc độ học riêng theo từng tọa độ, còn momentum tích lũy vận tốc để củng cố các hướng giảm ổn định.&lt;/p&gt;

&lt;p&gt;Nhiều giáo trình tối ưu cho học máy hiện đại đều đặt chủ đề này ở phần cốt lõi, chẳng hạn MIT 6.7220 (S25), EPFL CS-439, USC CSCI 599 và BU EC525.&lt;/p&gt;

&lt;h2 id=&quot;nội-dung-các-bài&quot;&gt;Nội dung các bài&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;SGD và minibatch — ước lượng không chệch, xáo trộn dữ liệu và tốc độ hội tụ \(O(1/\sqrt{T})\).&lt;/li&gt;
  &lt;li&gt;Momentum và tăng tốc Nesterov — heavy ball so với nhìn trước; diễn giải trực quan theo phong cách Distill.&lt;/li&gt;
  &lt;li&gt;Từ AdaGrad đến Adam — tiền điều kiện đường chéo theo từng tọa độ.&lt;/li&gt;
  &lt;li&gt;AdamW và thực hành huấn luyện — tách suy giảm trọng số (weight decay), lịch tốc độ học và cắt ngưỡng gradient.&lt;/li&gt;
  &lt;li&gt;Giảm phương sai — SVRG và SAGA cho bài toán tổng hữu hạn, và khi nào Adam theo minibatch vẫn hiệu quả hơn.&lt;/li&gt;
  &lt;li&gt;Bộ tối ưu thích nghi hiện đại (seminar tùy chọn) — SAM, Sophia và Muon so với chuẩn AdamW.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các mô phỏng tương tác cho SGD nằm trong &lt;a href=&quot;https://github.com/nglelinh/interactive_math/tree/main/optimization&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interactive_math/optimization&lt;/code&gt;&lt;/a&gt;. Bài phân tích trực quan về momentum nằm ở &lt;a href=&quot;/contents/vi/chapter26/26_02_momentum_and_nesterov/&quot;&gt;26-02&lt;/a&gt; (nên đọc kèm FISTA ở &lt;a href=&quot;/contents/vi/chapter09/09_05_acceleration/&quot;&gt;09-05&lt;/a&gt;). Các bộ tối ưu SAM, Muon và Sophia là tài liệu &lt;strong&gt;đọc thêm&lt;/strong&gt; (không nằm trong phạm vi kiểm tra) tại bài seminar tùy chọn &lt;a href=&quot;/contents/vi/chapter26/26_06_modern_optimizers/&quot;&gt;26-06&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-07 Mô hình hóa bằng DCP và CVXPY</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_07_Modeling_with_DCP_CVXPY/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_07_Modeling_with_DCP_CVXPY</id>
   <content type="html">&lt;p&gt;Trước năm 2005, nếu muốn dùng bộ giải điểm trong để giải một bài toán tối ưu hóa lồi mới, nghiên cứu sinh phải dành hàng tuần biến đổi tay các hàm \(\log\), chuẩn \(\ell_1\), tổng bình phương thành hàng trăm ma trận thưa \(G, h, A, b\) của Quy hoạch Nón — chỉ cần nhầm một dấu trừ là bộ giải báo vô nghiệm hoặc ra kết quả vô nghĩa!&lt;/p&gt;

&lt;p&gt;Mọi thứ thay đổi hoàn toàn khi Michael Grant và Stephen Boyd phát minh ra &lt;strong&gt;Quy hoạch Lồi có Kỷ luật (Disciplined Convex Programming - DCP)&lt;/strong&gt; và sau đó cộng đồng xây dựng thư viện mã nguồn mở &lt;strong&gt;CVXPY&lt;/strong&gt;. Với DCP, bạn viết bài toán gần như y hệt công thức toán trên bảng trắng; bộ kiểm tra tự động xác minh tính lồi theo cây cú pháp rồi tự động biên dịch xuống đúng nón LP/QP/SOCP/SDP và gọi bộ giải cho bạn chỉ trong vài dòng Python!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bộ-quy-tắc-ngữ-pháp-của-dcp-và-cvxpy&quot;&gt;Kiến thức cần nhớ: Bộ quy tắc ngữ pháp của DCP và CVXPY&lt;/h2&gt;

&lt;p&gt;Để không bao giờ bị CVXPY báo lỗi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DCPError&lt;/code&gt; mà không hiểu tại sao, hãy nắm chắc ba trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thư viện hàm nguyên tử (Atoms) có sẵn độ cong và tính đơn điệu:&lt;/strong&gt; Mỗi hàm cơ bản trong CVXPY (như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sum_squares&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;norm1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;quad_over_lin&lt;/code&gt;) đều gắn nhãn sẵn: &lt;em&gt;độ cong&lt;/em&gt; (affine, convex, concave) và &lt;em&gt;tính đơn điệu&lt;/em&gt; (tăng, giảm, không đơn điệu) trên từng đối số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc hợp thành DCP (DCP Composition Rule):&lt;/strong&gt; Để khẳng định \(h(g(x))\) là &lt;strong&gt;lồi&lt;/strong&gt; mà không cần tính Hessian, DCP kiểm tra điều kiện đủ:
    &lt;ul&gt;
      &lt;li&gt;\(h\) lồi và &lt;strong&gt;tăng&lt;/strong&gt;, còn \(g\) &lt;strong&gt;lồi&lt;/strong&gt;; HOẶC&lt;/li&gt;
      &lt;li&gt;\(h\) lồi và &lt;strong&gt;giảm&lt;/strong&gt;, còn \(g\) &lt;strong&gt;lõm&lt;/strong&gt;; HOẶC&lt;/li&gt;
      &lt;li&gt;\(g\) là hàm &lt;strong&gt;affine&lt;/strong&gt;.
(Lưu ý quan trọng: DCP là điều kiện &lt;em&gt;đủ&lt;/em&gt;, không phải &lt;em&gt;cần&lt;/em&gt;! Một biểu thức thực sự lồi như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sqrt(1 + x^2)&lt;/code&gt; vẫn bị DCP từ chối nếu viết ngây thơ, và phải viết lại bằng atom &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;norm2([1, x])&lt;/code&gt;!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tự động chuẩn hóa về dạng nón (Canonicalization):&lt;/strong&gt; Sau khi vượt qua kiểm tra DCP, CVXPY tự động sinh biến phụ epigraph để biến biểu thức cấp cao (như Lasso hay SVM) thành ma trận chuẩn cho bộ giải Clarabel, OSQP, ECOS hay SCS.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bắt-lỗi-một-biểu-thức-lồi-thật-nhưng-vi-phạm-dcp-và-cách-sửa-chuẩn&quot;&gt;Giải thích: Bắt lỗi một biểu thức “lồi thật nhưng vi phạm DCP” và cách sửa chuẩn&lt;/h3&gt;

&lt;p&gt;Giả sử bạn muốn cực tiểu hóa hàm \(f(x) = \sqrt{x^2 + 4}\) trên \(x \in \mathbb{R}\) trong CVXPY.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Kiểm tra toán học thật:&lt;/strong&gt; Đạo hàm \(f&apos;(x) = \frac{x}{\sqrt{x^2+4}}\), đạo hàm bậc hai \(f&apos;&apos;(x) = \frac{4}{(x^2+4)^{3/2}} &amp;gt; 0\) với mọi \(x\). Vậy \(f(x)\) &lt;strong&gt;chắc chắn là hàm lồi chặt&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Vì sao viết &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.sqrt(cp.square(x) + 4)&lt;/code&gt; lại bị lỗi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DCPError&lt;/code&gt;?&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Biểu thức trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g(x) = x^2 + 4&lt;/code&gt; là hàm &lt;strong&gt;lồi&lt;/strong&gt; (convex).&lt;/li&gt;
      &lt;li&gt;Hàm ngoài &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h(u) = sqrt(u)&lt;/code&gt; là hàm &lt;strong&gt;lõm&lt;/strong&gt; (concave) và tăng.&lt;/li&gt;
      &lt;li&gt;Hợp thành &lt;em&gt;lõm(lồi)&lt;/em&gt; có độ cong &lt;strong&gt;không xác định&lt;/strong&gt; theo bảng quy tắc DCP! CVXPY từ chối ngay để bảo đảm an toàn tuyệt đối.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Viết lại đúng chuẩn DCP:&lt;/strong&gt;
Nhận ra \(\sqrt{x^2 + 4} = \left\| \begin{pmatrix} x \\ 2 \end{pmatrix} \right\|_2\) — tức là chuẩn Euclidean của một vector &lt;strong&gt;affine&lt;/strong&gt; theo \(x\)!
Trong CVXPY, ta viết &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.norm2(cp.hstack([x, 2]))&lt;/code&gt;.
    &lt;ul&gt;
      &lt;li&gt;Đối số bên trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[x, 2]&lt;/code&gt; là &lt;strong&gt;affine&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Hàm ngoài &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;norm2&lt;/code&gt; là &lt;strong&gt;lồi&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Theo quy tắc DCP, &lt;em&gt;lồi(affine)&lt;/em&gt; luôn &lt;strong&gt;lồi&lt;/strong&gt;! CVXPY lập tức chấp nhận và biên dịch thành đúng 1 ràng buộc SOCP, trả về nghiệm \(x^\star = 0,\; f^\star = 2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Quy hoạch lồi có kỷ luật (Disciplined Convex Programming - DCP) là quy tắc mô hình hóa nền tảng của &lt;a href=&quot;https://www.cvxpy.org/&quot;&gt;CVXPY&lt;/a&gt;: người dùng lắp ghép các hàm nguyên tử (atoms) đã được thư viện xác định trước tính lồi hoặc lõm theo các quy tắc &lt;em&gt;bảo toàn tính lồi&lt;/em&gt;. Khi bộ chuẩn hóa/chuyển đổi (canonicalizer) chấp nhận mô hình, bài toán sẽ được tự động đưa về một bài toán quy hoạch nón chuẩn (đúng theo hệ phân loại của chương này) và chuyển cho các bộ giải số như OSQP, SCS, Clarabel hoặc ECOS.&lt;/p&gt;

&lt;p&gt;Đây là nguyên tắc thực hành quen thuộc của khóa học Stanford EE364a: &lt;strong&gt;mô hình hóa trước, chọn thuật toán sau&lt;/strong&gt;. Đối với các bài toán chuẩn như Lasso, SVM hay QP tối ưu hóa danh mục đầu tư, ta nên mô hình hóa trực tiếp bằng công cụ chuyên dụng thay vì tự cài đặt hạ gradient chiếu (trừ khi mục tiêu là học sâu về thuật toán).&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt-ý-tưởng-dcp&quot;&gt;Tóm tắt ý tưởng DCP&lt;/h2&gt;

&lt;p&gt;Hàm hợp \(f(g(x))\) là hàm lồi khi, chẳng hạn, \(f\) lồi và đơn điệu tăng còn \(g\) là hàm lồi (Boyd &amp;amp; Vandenberghe, Chương 3). CVXPY cung cấp một danh mục hữu hạn các hàm nguyên tử (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;norm&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sum_squares&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;abs&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;quad_over_lin&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;logistic&lt;/code&gt;, …) và sẽ từ chối các biểu thức không thể chứng nhận tính lồi theo quy tắc này. Việc bị từ chối không nhất thiết có nghĩa là bài toán không lồi — đôi khi biểu thức chỉ đang được viết ở dạng mà bộ chuẩn hóa/chuyển đổi không nhận diện được. Cách xử lý đúng là viết lại biểu thức bằng các hàm nguyên tử hợp lệ chứ không tắt kiểm tra DCP.&lt;/p&gt;

&lt;p&gt;Cài đặt thư viện:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;cvxpy numpy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;bài-thực-hành-nhỏ-a--lasso&quot;&gt;Bài thực hành nhỏ A — Lasso&lt;/h2&gt;

&lt;p&gt;Cho ma trận thiết kế \(A\in\mathbb{R}^{m\times n}\) và vectơ mục tiêu \(b\), bài toán Lasso:&lt;/p&gt;

\[\min_x \tfrac12\|Ax-b\|_2^2 + \lambda \|x\|_1\]

&lt;p&gt;có thể viết lại như một bài toán QP lồi (số hạng sai số bình phương là hàm bậc hai lồi; chuẩn \(\|\cdot\|_1\) là hàm lồi). Trong CVXPY, mô hình chỉ cần vài dòng với các hàm nguyên tử sẵn có:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cvxpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;seed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x_true&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x_true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x_true&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.05&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Variable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;objective&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum_squares&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Problem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Minimize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;objective&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;solver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OSQP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# hoặc SCS / CLARABEL
&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;status:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;opt:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;nnz ~&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hãy so sánh tập tọa độ khác không (support) khôi phục được với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x_true&lt;/code&gt;, đồng thời thử thay đổi \(\lambda\) để quan sát sự đánh đổi giữa độ thưa và độ khớp dữ liệu — đây cũng chính là quỹ đạo nghiệm mà phương pháp hạ gradient cận kề sẽ khảo sát ở Chương 09.&lt;/p&gt;

&lt;h2 id=&quot;bài-thực-hành-nhỏ-b--svm-biên-cứng-dưới-dạng-qp&quot;&gt;Bài thực hành nhỏ B — SVM biên cứng dưới dạng QP&lt;/h2&gt;

&lt;p&gt;Với các cặp dữ liệu gán nhãn tách tuyến tính được \((a_i,y_i)\), \(y_i\in\{-1,1\}\), bài toán SVM biên cứng có dạng:&lt;/p&gt;

\[\begin{align}
\min_{w,b} \quad &amp;amp; \tfrac12 \|w\|_2^2 \\
\text{s.t.} \quad &amp;amp; y_i(w^\top a_i + b) \ge 1, \quad i=1,\ldots,m.
\end{align}\]

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cvxpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;seed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Variable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Variable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Problem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Minimize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum_squares&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;status:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;||w|| =&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nếu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;status&lt;/code&gt; trả về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;infeasible&lt;/code&gt;, tập điểm dữ liệu không tách tuyến tính được — khi đó có thể chuyển sang mô hình SVM biên mềm với hàm mất mát hinge (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.pos(1 - cp.multiply(y, a @ w + b))&lt;/code&gt;), vốn vẫn tuân thủ đầy đủ quy tắc DCP.&lt;/p&gt;

&lt;h2 id=&quot;điểm-cần-ghi-nhớ&quot;&gt;Điểm cần ghi nhớ&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DCP là một hệ quy tắc &lt;em&gt;đủ&lt;/em&gt; để chứng nhận tính lồi, nhưng không phải điều kiện cần (không bao quát mọi cách viết của hàm lồi).&lt;/li&gt;
  &lt;li&gt;Bộ giải (chứ không phải vòng lặp Python tự viết) sẽ quyết định việc dùng Simplex, phương pháp điểm trong hay phương pháp nón bậc nhất.&lt;/li&gt;
  &lt;li&gt;Khi bài toán không thể biểu diễn theo DCP (như huấn luyện mạng nơ-ron sâu hoặc phần lớn bài toán ERM không lồi), ta chuyển sang các phương pháp tối ưu không lồi ở &lt;a href=&quot;/contents/vi/chapter26/&quot;&gt;Chương 26&lt;/a&gt; kết hợp vi phân tự động (&lt;a href=&quot;/contents/vi/chapter27/&quot;&gt;Chương 27&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Thay số hạng phạt của Lasso bằng Elastic Net \(\lambda(\alpha\|x\|_1 + \tfrac{1-\alpha}{2}\|x\|_2^2)\) và kiểm chứng rằng CVXPY vẫn chấp nhận bài toán. Sau đó thử viết chuẩn giả \(\|x\|_0\) — bộ chuẩn hóa/chuyển đổi sẽ từ chối vì không tuân thủ DCP.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>29-03 ADMM versus data-parallel and FedAvg</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter29/29_03_admm_vs_federated/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter29/29_03_admm_vs_federated</id>
   <content type="html">&lt;p&gt;If you already learned Consensus ADMM in Chapter 21, a sharp question should immediately occur to you: both Consensus ADMM and FedAvg solve \(\min_w \sum_{p=1}^P f_p(w)\) across distributed workers without sharing raw data—so why didn’t federated deep learning just use ADMM? Putting the two algorithms side by side reveals one of optimization’s clearest design trade-offs: ADMM maintains per-client dual variables that &lt;em&gt;provably cancel client drift&lt;/em&gt; on convex problems, while FedAvg stays stateless so millions of intermittent, nonconvex mobile devices can drop in and out without ever storing stale dual multipliers.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-consensus-admm-vs-data-parallel-sgd-vs-fedavg&quot;&gt;Key ideas: Consensus ADMM vs. Data-Parallel SGD vs. FedAvg&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dual Memory Kills Client Drift (ADMM):&lt;/strong&gt; In Consensus ADMM, each worker \(p\) minimizes \(f_p(x_p) + \frac{\rho}{2}\|x_p - z + u_p\|_2^2\). The dual variable \(u_p\) remembers the exact gradient discrepancy \(\nabla f_p(z^\star)\) at the global optimum, guaranteeing convergence to the &lt;em&gt;exact&lt;/em&gt; global minimizer \(z^\star\) even under extreme non-IID heterogeneity!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Statelessness Matters in Cross-Device FL:&lt;/strong&gt; Cross-device federated learning involves millions of phones where any given device may appear once a week. Maintaining fresh per-client dual state \(u_p\) becomes stale or impossible—favoring stateless FedAvg.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Subproblem Cost vs. Cheap Local SGD:&lt;/strong&gt; Classical ADMM assumes each worker solves (or closely approximates) its proximal subproblem \(\arg\min_{x_p} f_p(x_p) + \frac{\rho}{2}\|x_p - z + u_p\|_2^2\), which is fast for convex GLMs or cross-silo hospitals but expensive for deep neural nets compared to a few local SGD steps.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Three-Way Decision Matrix:&lt;/strong&gt; Use &lt;strong&gt;Data-Parallel SGD&lt;/strong&gt; on fast datacenter GPUs; use &lt;strong&gt;Consensus ADMM&lt;/strong&gt; on convex or cross-silo (10–50 always-on institutions) problems with strong heterogeneity; use &lt;strong&gt;FedAvg&lt;/strong&gt; (or FedProx/FedAdam) on large-scale, nonconvex, intermittent device fleets.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-how-admms-dual-variable-cures-the-exact-drift-that-broke-fedavg&quot;&gt;Worked example: How ADMM’s Dual Variable Cures the Exact Drift That Broke FedAvg&lt;/h3&gt;

&lt;p&gt;Return to the exact 2-client non-IID problem from Lesson 29-02 where FedAvg drifted away from \(w^\star = 0.6\):
\(f_1(x) = 2(x - 1)^2, \qquad f_2(x) = \frac{1}{2}(x + 1)^2, \qquad z^\star = 0.6.\)
Check whether \(z = 0.6\) is a &lt;strong&gt;fixed point&lt;/strong&gt; of Consensus ADMM (with \(\rho = 1\))!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the optimal scaled dual variables \(u_1^\star, u_2^\star\) at consensus \(x_1 = x_2 = z = 0.6\):&lt;/strong&gt;
At stationarity of \(f_p(x_p) + \frac{\rho}{2}(x_p - z + u_p)^2\), we need \(f_p&apos;(z) + \rho u_p^\star = 0 \implies u_p^\star = -f_p&apos;(z)/\rho\):
    &lt;ul&gt;
      &lt;li&gt;Client 1: \(f_1&apos;(0.6) = 4(0.6 - 1) = -1.6 \implies u_1^\star = +1.6\).&lt;/li&gt;
      &lt;li&gt;Client 2: \(f_2&apos;(0.6) = (0.6 + 1) = +1.6 \implies u_2^\star = -1.6\).
Notice \(u_1^\star + u_2^\star = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Now run one full ADMM round from \(z = 0.6,\ u_1 = 1.6,\ u_2 = -1.6\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Client 1 minimizes \(2(x_1 - 1)^2 + \frac{1}{2}(x_1 - 0.6 + 1.6)^2 = 2(x_1 - 1)^2 + \frac{1}{2}(x_1 + 1)^2\):
\(4(x_1 - 1) + (x_1 + 1) = 0 \implies 5x_1 = 3 \implies x_1^+ = 0.6!\)&lt;/li&gt;
      &lt;li&gt;Client 2 minimizes \(\frac{1}{2}(x_2 + 1)^2 + \frac{1}{2}(x_2 - 0.6 - 1.6)^2 = \frac{1}{2}(x_2 + 1)^2 + \frac{1}{2}(x_2 - 2.2)^2\):
\((x_2 + 1) + (x_2 - 2.2) = 0 \implies 2x_2 = 1.2 \implies x_2^+ = 0.6!\)&lt;/li&gt;
      &lt;li&gt;Server consensus update: \(z^+ = \frac{x_1^+ + x_2^+}{2} = 0.6\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Key Insight:&lt;/strong&gt; Even when both clients solve their local subproblems &lt;em&gt;all the way to exact optimality&lt;/em&gt;, the dual variables \(u_1^\star = +1.6\) and \(u_2^\star = -1.6\) exert exact counter-forces that hold both clients pinned at \(z^\star = 0.6\)—zero drift!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href=&quot;/contents/en/chapter21/&quot;&gt;Chapter 21&lt;/a&gt; studies the &lt;strong&gt;alternating direction method of multipliers&lt;/strong&gt;. In consensus form one solves&lt;/p&gt;

\[\min_{x_1,\ldots,x_P,z} \sum_{p=1}^P f_p(x_p) \quad\text{subject to}\quad x_p=z,\]

&lt;p&gt;by an augmented-Lagrangian saddle: primal \(x_p\)-updates (often proximal), a \(z\)-average, and a dual ascent on the residuals. When each \(f_p\) is convex and the steps are exact, ADMM has a mature convergence theory and is the right tool for &lt;strong&gt;structured convex&lt;/strong&gt; splits (distributed Lasso, consensus QP, some SDP relaxations).&lt;/p&gt;

&lt;p&gt;Data-parallel SGD and FedAvg live in a different design space:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt; &lt;/th&gt;
      &lt;th&gt;ADMM (Ch.21)&lt;/th&gt;
      &lt;th&gt;Data-parallel SGD&lt;/th&gt;
      &lt;th&gt;FedAvg&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Typical \(f\)&lt;/td&gt;
      &lt;td&gt;convex, often composite&lt;/td&gt;
      &lt;td&gt;nonconvex ERM / deep net&lt;/td&gt;
      &lt;td&gt;nonconvex, &lt;em&gt;heterogeneous&lt;/em&gt; local ERM&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;What is averaged&lt;/td&gt;
      &lt;td&gt;primal \(z\) and duals&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;gradients&lt;/strong&gt; (or synced weights) each step&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;weights&lt;/strong&gt; after \(E\) local steps&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual variables&lt;/td&gt;
      &lt;td&gt;yes, residuals drive consensus&lt;/td&gt;
      &lt;td&gt;no&lt;/td&gt;
      &lt;td&gt;no&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Scarce resource&lt;/td&gt;
      &lt;td&gt;iterations of a modest-sized convex problem&lt;/td&gt;
      &lt;td&gt;interconnect bandwidth every step&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;rounds&lt;/strong&gt; (devices sleep, Wi-Fi)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Certificate&lt;/td&gt;
      &lt;td&gt;duality gap / residual&lt;/td&gt;
      &lt;td&gt;none (nonconvex)&lt;/td&gt;
      &lt;td&gt;none&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Calling FedAvg “ADMM without the dual” hides the point: FedAvg &lt;em&gt;intentionally&lt;/em&gt; lets clients drift, then averages parameters. ADMM &lt;em&gt;penalizes&lt;/em&gt; disagreement every iteration. Use ADMM when you can write a convex consensus program and want residuals you can monitor. Use data-parallel SGD when you are training one shared net on a cluster you control. Use FedAvg when the data cannot move and communication is expensive.&lt;/p&gt;

&lt;p&gt;A practical lab: three clients, one convex logistic objective split by samples — solve with (i) ADMM consensus and (ii) FedAvg with \(E\in\{1,5\}\). Compare training loss versus &lt;em&gt;communication rounds&lt;/em&gt;, not versus local gradient evaluations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; In what scenarios might a projection-free or splitting method (Frank–Wolfe, ADMM) still beat data-parallel SGD on a cluster — even in 2026?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>29-02 FedAvg</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter29/29_02_fedavg/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter29/29_02_fedavg</id>
   <content type="html">&lt;p&gt;In 2017, Brendan McMahan and colleagues at Google faced a constraint that broke standard distributed ML: improving mobile keyboard next-word prediction across millions of smartphones &lt;em&gt;without ever uploading a single user’s raw text to the cloud&lt;/em&gt;. Their answer—&lt;strong&gt;Federated Averaging (FedAvg)&lt;/strong&gt;—flipped data-parallel SGD on its head: send the model to the data, let a sampled subset of phones run multiple local epochs of SGD, and average only the resulting weight updates back on the server. When client data is IID, FedAvg saves orders of magnitude in communication; when client data is non-IID, however, multiple local steps introduce a fascinating failure mode called &lt;strong&gt;client drift&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-mechanics-and-failure-modes-of-fedavg&quot;&gt;Key ideas: Mechanics and Failure Modes of FedAvg&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;The Four-Step FedAvg Round:&lt;/strong&gt; (1) Server samples a small fraction \(\mathcal{S}_t\) of clients (partial participation), (2) broadcasts \(w_t\), (3) each client runs \(E\) local SGD steps on its private dataset \(F_c\), and (4) server forms the data-weighted average \(w_{t+1} = \sum_{c \in \mathcal{S}_t} \frac{n_c}{n_{\mathcal{S}_t}} w_{t+1}^{(c)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Special Case \(E = 1\) Recovers Data-Parallel SGD:&lt;/strong&gt; When every client takes only 1 local step with identical step size \(\eta\), averaging the resulting weights \(w_t - \eta g_c\) is algebraically identical to averaging gradients!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Client Drift Under Non-IID Heterogeneity:&lt;/strong&gt; When \(E &amp;gt; 1\) and clients have distinct local minimizers \(w_c^\star \ne w^\star\), local SGD pulls each client toward its own \(w_c^\star\). Averaging those drifted models does &lt;em&gt;not&lt;/em&gt; generally equal the global optimum \(w^\star\)—even with exact local gradients and zero sampling noise!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Partial Participation &amp;amp; System Heterogeneity:&lt;/strong&gt; Because mobile clients drop offline and have wildly varying compute speeds, FedAvg samples a fresh subset \(\mathcal{S}_t\) each round, introducing an extra layer of client-sampling variance on top of local minibatch noise.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-seeing-non-iid-client-drift-in-exact-closed-form&quot;&gt;Worked example: Seeing Non-IID Client Drift in Exact Closed Form&lt;/h3&gt;

&lt;p&gt;Consider \(P = 2\) equal-weight clients minimizing \(F(w) = \frac{1}{2}\bigl(F_1(w) + F_2(w)\bigr)\) where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Client 1 has steep local loss \(F_1(w) = \frac{1}{2}\cdot 4(w - 1)^2 = 2(w - 1)^2\) (local optimum \(w_1^\star = 1\)).&lt;/li&gt;
  &lt;li&gt;Client 2 has flat local loss \(F_2(w) = \frac{1}{2}\cdot 1(w + 1)^2 = \frac{1}{2}(w + 1)^2\) (local optimum \(w_2^\star = -1\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find the true global optimum \(w^\star\):&lt;/strong&gt;
\(F&apos;(w) = \frac{1}{2}\bigl[4(w - 1) + (w + 1)\bigr] = \frac{5w - 3}{2} = 0 \implies w^\star = \frac{3}{5} = 0.6.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Run FedAvg with large local steps (\(E \to \infty\), exact local minimization) starting right at the true optimum \(w_0 = 0.6\)!&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Client 1 runs local GD to its own optimum: \(w_1^{(1)} = 1.0\).&lt;/li&gt;
      &lt;li&gt;Client 2 runs local GD to its own optimum: \(w_1^{(2)} = -1.0\).&lt;/li&gt;
      &lt;li&gt;Server averages them: \(w_1 = \frac{1.0 + (-1.0)}{2} = 0.0 \ne 0.6\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check finite \(E = 2\) with \(\eta = 0.2\) starting at \(w_0 = 0.6\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Client 1 (\(w \leftarrow w - 0.8(w - 1) = 0.2 w + 0.8\)): \(0.6 \to 0.92 \to 0.984\).&lt;/li&gt;
      &lt;li&gt;Client 2 (\(w \leftarrow w - 0.2(w + 1) = 0.8 w - 0.2\)): \(0.6 \to 0.28 \to 0.024\).&lt;/li&gt;
      &lt;li&gt;Server average: \(w_1 = \frac{0.984 + 0.024}{2} = 0.504\)!
Even starting at the &lt;em&gt;exact&lt;/em&gt; global optimum \(w^\star = 0.6\), FedAvg with \(E = 2\) immediately &lt;strong&gt;drifts away&lt;/strong&gt; to \(0.504\) (and converges to a biased fixed point \(w_{\text{FedAvg}} \ne 0.6\))—demonstrating concretely why non-IID heterogeneity breaks pure local averaging!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Federated averaging&lt;/strong&gt; (McMahan, Moore, Ramage, Hampson, y Arcas, AISTATS 2017) repeats:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The server broadcasts the current global model \(w_t\) to a subset of clients \(\mathcal{S}_t\).&lt;/li&gt;
  &lt;li&gt;Client \(c\in\mathcal{S}_t\) runs \(E\) local epochs of SGD on its &lt;em&gt;private&lt;/em&gt; data, producing \(w_{t+1}^{(c)}\).&lt;/li&gt;
  &lt;li&gt;The server sets&lt;/li&gt;
&lt;/ol&gt;

\[w_{t+1} = \sum_{c\in\mathcal{S}_t} \frac{n_c}{n_{\mathcal{S}_t}} w_{t+1}^{(c)},\]

&lt;p&gt;where \(n_c\) is the client’s example count and \(n_{\mathcal{S}_t}=\sum_{c\in\mathcal{S}_t}n_c\).&lt;/p&gt;

&lt;p&gt;If \(E=1\) and each client takes one step on the &lt;em&gt;same&lt;/em&gt; global batch size story, FedAvg collapses toward ordinary data-parallel SGD. The interesting (and statistically harder) regime is \(E&amp;gt;1\): local drift on &lt;strong&gt;heterogeneous&lt;/strong&gt; (non-IID) client distributions. Communication rounds become the iteration index that matters.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fedavg_round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client_models&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client_sizes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client_sizes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_c&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client_models&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client_sizes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_c&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Why devices.&lt;/strong&gt; Privacy, regulation, and bandwidth: you cannot ship every phone’s photos to a datacenter every night. FedAvg is a &lt;em&gt;pattern&lt;/em&gt;, not a privacy proof — gradients and weights can still leak. Formal privacy (DP-SGD, secure aggregation) is a different course.&lt;/p&gt;

&lt;h3 id=&quot;fedavg-and-client-drift-in-about-3-minutes&quot;&gt;FedAvg and client drift in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/fedavg-drift_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Three clients with different quadratics: E = 1 is exactly GD, E = 5 and E = 20 save communication rounds but drift away from w*.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Partition a tiny MNIST (or even a 2-D Gaussian mixture) across 3 clients that each see only one class. Run FedAvg with \(E=1\) vs \(E=5\). Watch the global model oscillate when local steps overfit the missing classes.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>29-01 Data-parallel SGD</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter29/29_01_data_parallel_sgd/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter29/29_01_data_parallel_sgd</id>
   <content type="html">&lt;p&gt;Scale a training job from 1 GPU to 64 GPUs using synchronous &lt;strong&gt;Data-Parallel SGD&lt;/strong&gt;, and something remarkably clean happens: if every worker computes a local minibatch gradient of size \(b\) and averages them via an AllReduce collective, the resulting parameter update is mathematically &lt;em&gt;indistinguishable&lt;/em&gt; from running single-GPU SGD with global batch size \(B = P \cdot b\). The real engineering and optimization subtleties lie in what happens as \(P\) grows huge: variance shrinks by \(1/P\), learning rates must scale carefully, and eventually you hit the critical batch size where adding more GPUs yields diminishing returns.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-mathematics-and-scaling-laws-of-data-parallel-sgd&quot;&gt;Key ideas: Mathematics and Scaling Laws of Data-Parallel SGD&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Exact Equivalence to Large-Batch SGD:&lt;/strong&gt; With \(P\) workers each drawing \(b\) i.i.d. samples, the averaged gradient \(g_k = \frac{1}{P}\sum_{p=1}^P g_k^{(p)}\) is unbiased for \(\nabla F(w_k)\) with variance \(\frac{\sigma^2}{Pb}\)—identical to a single worker with batch size \(B = Pb\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ring AllReduce Bandwidth Scaling:&lt;/strong&gt; Instead of funneling all \(P\) gradients through one bottleneck parameter server (\(O(Pd)\) traffic at the server), Ring AllReduce passes chunks around a logical ring so every worker sends and receives only \(2\frac{P-1}{P}d \approx 2d\) bytes—independent of \(P\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear Scaling Rule &amp;amp; Warmup:&lt;/strong&gt; When multiplying global batch size by \(P\), multiplying the learning rate by \(P\) (or \(\sqrt{P}\) under Adam) keeps the noise-to-signal ratio balanced, paired with gradual warmup during early unstable epochs.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Synchronous Stragglers vs. Asynchronous Stale Gradients:&lt;/strong&gt; Synchronous AllReduce waits for the slowest worker each step; asynchronous SGD eliminates straggler waits but injects delayed (“stale”) gradients \(\nabla f(w_{k-\tau})\), which degrade convergence unless delay \(\tau\) is tightly bounded.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-global-variance-reduction-and-ring-allreduce-traffic&quot;&gt;Worked example: Computing Global Variance Reduction and Ring AllReduce Traffic&lt;/h3&gt;

&lt;p&gt;Suppose a single GPU trains with batch size \(b = 32\), per-sample gradient variance \(\sigma^2 = 64\), and model size \(d = 25\text{M}\) float32 weights (\(100\text{ MB}\)). We scale synchronously to \(P = 8\) GPUs.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Single-GPU gradient variance:&lt;/strong&gt;
\(\operatorname{Var}(g_{\text{1 GPU}}) = \frac{\sigma^2}{b} = \frac{64}{32} = 2.0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;8-GPU synchronous data-parallel variance (global batch \(B = 8 \times 32 = 256\)):&lt;/strong&gt;
\(\operatorname{Var}(g_{\text{8 GPUs}}) = \frac{\sigma^2}{P b} = \frac{64}{256} = 0.25\) (an exact &lt;strong&gt;8× variance reduction&lt;/strong&gt;!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare communication volume per step (Parameter Server vs. Ring AllReduce):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Central Parameter Server:&lt;/strong&gt; The server must receive \(8 \times 100\text{ MB} = 800\text{ MB}\) and broadcast \(800\text{ MB}\) = &lt;strong&gt;1,600 MB&lt;/strong&gt; through one link!&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Ring AllReduce:&lt;/strong&gt; Each GPU sends \(2\frac{P-1}{P}(100\text{ MB}) = 2 \cdot \frac{7}{8}(100\text{ MB}) = 175\text{ MB}\)—nearly &lt;strong&gt;10× less&lt;/strong&gt; bottleneck bandwidth, and capped below \(200\text{ MB}\) even if you scale to \(P = 1024\) GPUs!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Suppose we partition the \(n\) examples across \(P\) workers, worker \(p\) holding index set \(\mathcal{I}_p\). A synchronous &lt;strong&gt;data-parallel&lt;/strong&gt; step is&lt;/p&gt;

\[g_k = \frac{1}{P}\sum_{p=1}^P g_k^{(p)}, \qquad
g_k^{(p)} = \frac{1}{B}\sum_{i\in\mathcal{B}_{k,p}} \nabla f_i(w_k),\]

&lt;p&gt;then \(w_{k+1}=w_k-\eta g_k\). If the union of the minibatches \(\mathcal{B}_{k,p}\) is a uniform sample, this is ordinary minibatch SGD with batch size \(PB\). The &lt;em&gt;systems&lt;/em&gt; content is how \(g_k\) is formed: a &lt;strong&gt;parameter server&lt;/strong&gt; sums incoming gradients, or an &lt;strong&gt;all-reduce&lt;/strong&gt; (ring, tree, NCCL) averages them without a single bottleneck node.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is not magic.&lt;/strong&gt; Data parallelism does not change the mathematics of SGD if every worker uses the &lt;em&gt;same&lt;/em&gt; \(w_k\). It changes wall-clock per step and the largest feasible batch. An all-reduce of a 100-million-parameter vector is a bandwidth problem; that is why people discuss compression (quantize, sparsify) as an optional next lecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asynchronous&lt;/strong&gt; variants (Hogwild!-style) apply stale gradients. They can be faster on shared memory and harder to analyse. For this course, implement the synchronous picture first.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Pedagogical sketch — not a real distributed runtime
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;data_parallel_step&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;workers_grads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;workers_grads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;workers_grads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Open &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/parallel_computing_illustration.html&quot;&gt;parallel_computing_illustration.html&lt;/a&gt; for a cartoon of splitting work, then come back and write the all-reduce of \(g\) on the board.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; If each worker’s batch is of size \(B=32\) and \(P=8\), what is the equivalent single-node batch? If you linearly scale \(\eta\) with \(P\), what can go wrong (hint: Chapter 26 schedules and the large-batch breakdown)?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>29 Distributed and federated optimization</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter29/29_00_distributed_and_federated/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter29/29_00_distributed_and_federated</id>
   <content type="html">&lt;p&gt;Modern optimization rarely happens on a single machine anymore—either the dataset and model are too massive for one GPU (forcing &lt;strong&gt;data-parallel distributed training&lt;/strong&gt; across thousands of accelerators connected by InfiniBand), or the data itself cannot legally leave millions of phones and hospitals (forcing &lt;strong&gt;federated learning&lt;/strong&gt; over slow, unreliable wireless links). Chapter 29 unifies these worlds by contrasting synchronous data-parallel SGD, communication-saving Federated Averaging (FedAvg), and Chapter 21’s consensus ADMM—showing how communication bandwidth, synchronization barriers, and non-IID data heterogeneity reshape optimization from the ground up.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-distributed--federated-optimization-landscape&quot;&gt;Key ideas: Distributed &amp;amp; Federated Optimization Landscape&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch29_federated_averaging.svg&quot; alt=&quot;Tối ưu hóa Phân tán và Học Liên kết (FedAvg)&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;The Communication Bottleneck:&lt;/strong&gt; On a cluster or across mobile devices, transmitting a \(d\)-dimensional gradient or model update over a network often takes \(10\times\)–\(1000\times\) longer than computing a local gradient—making &lt;em&gt;communication rounds&lt;/em&gt;, not FLOPs, the dominant resource.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Synchronous Data-Parallel SGD:&lt;/strong&gt; Partitions a giant minibatch across \(P\) workers, averages gradients via AllReduce, and produces an update mathematically &lt;em&gt;identical&lt;/em&gt; to single-machine large-batch SGD—limited mainly by stragglers and the critical batch size.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Federated Learning &amp;amp; Local Steps (FedAvg):&lt;/strong&gt; Keeps raw data strictly on-device, lets each sampled client run \(E\) local SGD steps before sending weight deltas to a central server, trading communication frequency for &lt;strong&gt;client drift&lt;/strong&gt; when client distributions are non-IID.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Consensus (ADMM) vs. Primal Averaging (FedAvg):&lt;/strong&gt; Consensus ADMM uses dual variables to eliminate client drift completely on convex problems, whereas modern federated methods (FedProx, SCAFFOLD, FedAdam) adapt proximal leashes, control variates, and server-side adaptivity to nonconvex deep networks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-communication-cost-of-data-parallel-sgd-vs-local-step-fedavg&quot;&gt;Worked example: Communication Cost of Data-Parallel SGD vs. Local-Step FedAvg&lt;/h3&gt;

&lt;p&gt;Suppose \(P = 10\) clients each hold local data, the model has \(d = 10^6\) float32 parameters (\(4\text{ MB}\) per model), and we want every client to execute \(T = 100\) local gradient steps.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Synchronous Data-Parallel SGD (sync every \(E = 1\) step):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Number of communication rounds: \(100\).&lt;/li&gt;
      &lt;li&gt;Each client uploads + downloads \(4\text{ MB} \times 2 = 8\text{ MB}\) per round.&lt;/li&gt;
      &lt;li&gt;Total network traffic per client: \(100 \times 8\text{ MB} = 800\text{ MB}\) (and \(8\text{ GB}\) aggregate across 10 clients).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;FedAvg with \(E = 10\) local steps per round:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Number of communication rounds: \(100 / 10 = 10\) rounds.&lt;/li&gt;
      &lt;li&gt;Total network traffic per client: \(10 \times 8\text{ MB} = 80\text{ MB}\)—an immediate &lt;strong&gt;10× reduction&lt;/strong&gt; in communication cost!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The trade-off:&lt;/strong&gt; When all 10 clients have IID data, those 10 rounds behave almost like Data-Parallel SGD; when clients have strongly skewed non-IID data, the 10 local steps pull each client toward its own local optimum before averaging—creating the client drift we analyze in Lessons 29-02 and 29-04.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;distributed-and-federated-optimization&quot;&gt;Distributed and federated optimization&lt;/h1&gt;

&lt;p&gt;Chapter 21 (ADMM) is the course’s first &lt;em&gt;distributed convex&lt;/em&gt; workhorse: split a structured objective, pass dual variables, and obtain consensus. Deep learning rarely looks like that. The 2026 default is &lt;strong&gt;data-parallel SGD&lt;/strong&gt;: each worker owns a shard of the data, computes a minibatch gradient, and a server (or an all-reduce) averages the gradients (or the weights).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Federated learning&lt;/strong&gt; is the same idea with a social constraint: raw data must not leave the device. &lt;strong&gt;FedAvg&lt;/strong&gt; (McMahan et al., AISTATS 2017) lets each client run several local SGD steps and averages &lt;em&gt;parameters&lt;/em&gt; once per round. Communication, not flops, is the scarce resource.&lt;/p&gt;

&lt;p&gt;This chapter is an introduction. We will not treat Byzantine robustness or gradient compression in depth (USC CSCI 599 week-12 territory). We &lt;em&gt;will&lt;/em&gt; make the ADMM contrast sharp enough that you never call FedAvg “just ADMM.”&lt;/p&gt;

&lt;h2 id=&quot;lessons&quot;&gt;Lessons&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Data-parallel SGD and all-reduce&lt;/li&gt;
  &lt;li&gt;FedAvg&lt;/li&gt;
  &lt;li&gt;ADMM vs data-parallel / federated methods&lt;/li&gt;
  &lt;li&gt;Modern federated applications (optional) — FedProx, SCAFFOLD, FedAdam, healthcare&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Primary reading: McMahan et al., &lt;em&gt;Communication-Efficient Learning of Deep Networks from Decentralized Data&lt;/em&gt;, &lt;a href=&quot;https://proceedings.mlr.press/v54/mcmahan17a.html&quot;&gt;PMLR v54&lt;/a&gt;. Revisit Boyd et al., &lt;em&gt;Distributed Optimization and Statistical Learning via ADMM&lt;/em&gt;. The 2020–2026 application layer is &lt;a href=&quot;/contents/en/chapter29/29_04_modern_federated/&quot;&gt;29-04&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>28-03 Overparameterization</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_03_overparameterization/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_03_overparameterization</id>
   <content type="html">&lt;p&gt;Classical statistics taught a golden rule: never let the number of parameters \(d\) exceed the number of training examples \(n\), or your model will memorize noise and collapse on test data. Modern deep learning routinely violates that rule by factors of \(100\times\)—and somehow becomes &lt;em&gt;easier&lt;/em&gt; to optimize and &lt;em&gt;better&lt;/em&gt; at generalizing! Overparameterization (\(d \gg n\)) fundamentally transforms the loss landscape: instead of isolated local valleys, the zero-loss set becomes a vast \((d - n)\)-dimensional manifold, and gradient descent implicitly picks out the &lt;strong&gt;minimum-norm&lt;/strong&gt; interpolating solution.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-and-implicit-bias-of-overparameterized-models&quot;&gt;Key ideas: Geometry and Implicit Bias of Overparameterized Models&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Interpolation Manifold (\(d &amp;gt; n\)):&lt;/strong&gt; In an underdetermined linear system \(Xw = y\) (\(X \in \mathbb{R}^{n \times d}\) full row rank, \(d &amp;gt; n\)), there are infinitely many exact global minimizers forming an affine subspace of dimension \(d - n\), all achieving \(F(w) = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Implicit Bias of Gradient Descent:&lt;/strong&gt; Even with zero explicit \(\ell_2\) regularization, running gradient descent from \(w_0 = 0\) keeps every iterate strictly inside \(\operatorname{row}(X) = \operatorname{span}(X^\top)\). Because the &lt;em&gt;unique&lt;/em&gt; interpolator inside \(\operatorname{row}(X)\) is the minimum-\(\ell_2\)-norm solution \(w_{\text{min}} = X^\top(XX^\top)^{-1} y\), GD automatically acts as a hidden regularizer!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lazy Training / Neural Tangent Kernel (NTK) Regime:&lt;/strong&gt; In ultra-wide neural networks, each weight moves only \(O(1/\sqrt{\text{width}})\) from initialization, so the network stays well-approximated by its first-order Taylor expansion in \(w\)—turning nonconvex training into convex kernel regression!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feature Learning vs. Lazy Regime:&lt;/strong&gt; Practical deep networks operate beyond the pure NTK limit, moving weights far enough to learn task-adaptive representations while still retaining the landscape smoothness granted by overparameterization.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-watching-gd-find-the-minimum-norm-interpolator&quot;&gt;Worked example: Watching GD Find the Minimum-Norm Interpolator&lt;/h3&gt;

&lt;p&gt;Consider an overparameterized 1-example, 2-parameter linear model (\(n = 1, d = 2\)): \(X = \begin{pmatrix} 1 &amp;amp; 2 \end{pmatrix}\), \(y = 5\), minimizing \(F(w) = \frac{1}{2}(w_1 + 2 w_2 - 5)^2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Describe the infinite manifold of zero-loss solutions:&lt;/strong&gt; Every point on the line \(w_1 + 2 w_2 = 5\) achieves \(F(w) = 0\) (e.g., \((5, 0)\), \((1, 2)\), \((-5, 5)\), all have zero training loss!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trace Gradient Descent starting from \(w^{(0)} = (0, 0)^\top\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;At any \(w\), the gradient is \(\nabla F(w) = (w_1 + 2 w_2 - 5)\begin{pmatrix} 1 \\ 2 \end{pmatrix}\).&lt;/li&gt;
      &lt;li&gt;Notice every single gradient is a scalar multiple of \((1, 2)^\top\)! Therefore, for &lt;em&gt;every&lt;/em&gt; step \(k\), \(w^{(k)} = \alpha_k (1, 2)^\top\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find the exact GD limit:&lt;/strong&gt; Imposing \(w_1 + 2 w_2 = 5\) on \(w = \alpha (1, 2)^\top\) gives
\(\alpha + 2(2\alpha) = 5 \implies 5\alpha = 5 \implies \alpha = 1 \implies w^{\text{GD}} = (1, 2)^\top.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify minimum Euclidean norm:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\|w^{\text{GD}}\|_2^2 = 1^2 + 2^2 = 5\).&lt;/li&gt;
      &lt;li&gt;Compare with other zero-loss interpolators: \(\|(5, 0)\|_2^2 = 25\), \(\|(3, 1)\|_2^2 = 10\), \(\|(-5, 5)\|_2^2 = 50\).
Without ever adding \(\lambda \|w\|_2^2\) to the loss, GD from \(w^{(0)} = 0\) &lt;strong&gt;automatically&lt;/strong&gt; converged to the unique minimum-norm interpolator \((1, 2)^\top\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A model is &lt;strong&gt;overparameterized&lt;/strong&gt; when the number of parameters \(d\) substantially exceeds the number of effective constraints coming from the data (classically \(d \gg n\) for interpolating \(n\) scalar labels). Then the equation \(F(w)=0\) (or “train loss \(\approx 0\)”) can have a &lt;strong&gt;huge set&lt;/strong&gt; of solutions. Training is no longer “find the unique minimizer”; it is “which interpolator does the algorithm pick?”&lt;/p&gt;

&lt;p&gt;That is the implicit-bias viewpoint: gradient descent on an underdetermined least-squares problem converges to the &lt;strong&gt;min-norm&lt;/strong&gt; interpolator in the span of the features; on separable linear classification it maximizes the margin in the limit (Soudry et al., and a large follow-up literature). Deep nets are not linear, but the slogan remains: &lt;strong&gt;the optimizer is part of the inductive bias&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Overparameterization also changes the &lt;em&gt;shape&lt;/em&gt; of \(F\). In many random-feature and wide-net limits the loss becomes &lt;em&gt;locally&lt;/em&gt; benign: once you are close enough, every critical point that SGD finds interpolates, and saddles become less relevant than &lt;strong&gt;which&lt;/strong&gt; interpolating point you land on. This is why “nonconvex ⇒ unusable local minima” is the wrong slogan for modern deep learning, even though the function is still nonconvex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Polyak–Łojasiewicz (PL) condition&lt;/strong&gt; (pointer, not a full lecture). If&lt;/p&gt;

\[\tfrac12 \|\nabla F(w)\|_2^2 \ge \mu \bigl(F(w)-F^\star\bigr)\]

&lt;p&gt;for some \(\mu&amp;gt;0\), then gradient descent enjoys a linear rate &lt;em&gt;without convexity&lt;/em&gt;. Some overparameterized least-squares and certain wide-net regimes satisfy PL locally. The optional lesson &lt;a href=&quot;/contents/en/chapter28/28_05_pl_condition/&quot;&gt;28-05&lt;/a&gt; reuses the Chapter 06 proof on that inequality (Karimi, Nutini, Schmidt, &lt;a href=&quot;https://arxiv.org/abs/1608.04636&quot;&gt;arXiv:1608.04636&lt;/a&gt;); this page only needs the slogan.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Fit \(n=20\) scalar points with a degree-\(50\) polynomial by (i) the numpy least-squares min-norm solution and (ii) GD from two random starts. Compare test error on a smooth underlying function. Same train loss, different interpolators.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>28-02 Escaping saddles and landscape geometry</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_02_escaping_saddles/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_02_escaping_saddles</id>
   <content type="html">&lt;p&gt;Knowing that a strict saddle has a negative-curvature escape direction is reassuring, yet vanilla gradient descent can still linger exponentially long near a saddle if it approaches almost orthogonally to that unstable eigenvector. How do practical algorithms break free cleanly? Remarkably, &lt;strong&gt;a tiny injection of isotropic noise&lt;/strong&gt; (Perturbed Gradient Descent, Jin et al. 2017) is enough to kick the iterate out of the thin “stuck region” around any strict saddle and guarantee polynomial-time convergence to an \(\varepsilon\)-second-order stationary point—explaining one reason why SGD’s built-in minibatch noise is a feature, not a bug.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-mechanisms-for-escaping-strict-saddles&quot;&gt;Key ideas: Mechanisms for Escaping Strict Saddles&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;The Thin Stuck Region:&lt;/strong&gt; Near a strict saddle \(w_s\), only trajectories initialized on the measure-zero stable manifold (spanned by eigenvectors with \(\lambda_i \ge 0\)) converge into \(w_s\). Gradient descent from a random initialization avoids strict saddles almost surely (Lee et al. 2016), though worst-case escape time can be exponential without perturbations.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Perturbed Gradient Descent (PGD):&lt;/strong&gt; Whenever \(|\nabla F(w_k)|_2\) becomes small, adding a single tiny uniform ball perturbation \(\xi \sim \text{Unif}(B_r(0))\) ensures a non-negligible projection onto the negative-curvature eigenvector \(v_{\min}\), triggering exponential growth $$(1 + \eta&lt;/td&gt;
          &lt;td&gt;\lambda_{\min}&lt;/td&gt;
          &lt;td&gt;)^t$$ away from the saddle!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Approximate Second-Order Stationarity (\(\varepsilon\)-SOSP):&lt;/strong&gt; Because exact global minimization of general nonconvex functions is NP-hard, modern theory targets \(\|\nabla F(w)\|_2 \le \varepsilon\) and \(\lambda_{\min}(\nabla^2 F(w)) \ge -\sqrt{\rho \varepsilon}\) (where \(\rho\) is Hessian Lipschitzness)—achievable in \(\tilde{O}(\varepsilon^{-2})\) perturbed gradient steps.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Negative-Curvature Exploitation (Cubic Newton / Trust Region):&lt;/strong&gt; Second-order methods explicitly compute or approximate \(v_{\min}\) via Hessian-vector products (Lanczos) and step directly along \(v_{\min}\) to escape saddles in fewer iterations at higher per-step cost.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-exponential-escape-rate-from-a-strict-saddle&quot;&gt;Worked example: Exponential Escape Rate From a Strict Saddle&lt;/h3&gt;

&lt;p&gt;Consider the pure quadratic saddle \(F(x, y) = \frac{1}{2}(4 y^2 - x^2)\) near the saddle \((0, 0)\) (so \(\lambda_y = +4\), \(\lambda_x = -1\)). Run gradient descent with step size \(\eta = 0.2\) (safe for \(L = 4\) since \(0.2 &amp;lt; 2/4\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the exact GD update:&lt;/strong&gt;
\(\nabla F(x, y) = (-x,\ 4y)^\top \implies x_{k+1} = (1 + \eta) x_k = 1.2\, x_k, \qquad y_{k+1} = (1 - 4\eta) y_k = 0.2\, y_k.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Start on the stable manifold \((x_0, y_0) = (0, 1)\) (zero noise):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x_k = 0\) forever, while \(y_k = (0.2)^k \to 0\). Vanilla GD falls straight into the saddle \((0, 0)\) and stays trapped forever!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inject a tiny perturbation \(\xi = (0.01, 0)\) at \((0, 0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Now \(x_0 = 0.01\), and every GD step amplifies \(x_k\) geometrically by \(1.2\times\):
        &lt;ul&gt;
          &lt;li&gt;\(k = 10\): \(x_{10} = 0.01 \times (1.2)^{10} \approx 0.0619\).&lt;/li&gt;
          &lt;li&gt;\(k = 26\): \(x_{26} = 0.01 \times (1.2)^{26} \approx 1.145\)!&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Objective drops from \(F(0, 0) = 0\) to \(F(1.145, 0) = -\frac{1}{2}(1.145)^2 \approx -0.655\).
Because growth is exponential (\(1.2^k\)), shrinking the perturbation radius by \(100\times\) only adds \(\log_{1.2}(100) \approx 25\) extra steps—showing concretely why Perturbed GD escapes strict saddles in \(O(\log(d/\varepsilon))\) steps!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;How do the algorithms you already know leave a strict saddle?&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Noise helps.&lt;/strong&gt; SGD’s gradient estimator is not exactly \(\nabla F\). A random perturbation has a component along the negative-curvature direction with high probability. Full-batch GD can sit at a saddle if it arrives with zero component in that direction (the \((0,0)\) example of the previous lesson).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Perturbed GD.&lt;/strong&gt; Adding explicit isotropic noise when \(\|\nabla F\|\) is small is a theorem-friendly cousin of SGD (Ge, Huang, Jin, Yuan, and later Jin et al. on perturbed gradient descent).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Momentum&lt;/strong&gt; can overshoot a flat ridge and fall off; it can also oscillate. Do not treat it as a saddle-escape guarantee.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-order / negative-curvature steps&lt;/strong&gt; (Hessian–vector products via Pearlmutter, or Neon-style) explicitly walk downhill along the most negative eigenvector. Rare in production DL; useful as a mental model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Sharp vs flat minima.&lt;/strong&gt; Around two minimizers with the same \(F\), the larger Hessian eigenvalues mean a &lt;em&gt;sharp&lt;/em&gt; bowl: a small parameter perturbation (or a small distribution shift) raises the loss a lot. &lt;strong&gt;SAM&lt;/strong&gt; (Foret et al., ICLR 2021) optimizes a local-max envelope to prefer flatter regions; it is optional seminar material, not a required algorithm this term.&lt;/p&gt;

&lt;p&gt;Geometry to keep: the loss surface is not a 2-D cartoon with a handful of pits. It is a high-dimensional object with huge &lt;strong&gt;plateaus&lt;/strong&gt;, &lt;strong&gt;narrow canyons&lt;/strong&gt; (the condition-number story of Chapters 06 and 26), and symmetries (permuting hidden units leaves \(F\) invariant, so minima come in manifolds). When a demo shows a 3-D surface, ask what was &lt;em&gt;projected away&lt;/em&gt;.&lt;/p&gt;

&lt;h3 id=&quot;saddle-points-in-about-3-minutes&quot;&gt;Saddle points in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/saddle-escape_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;GD pulled into the saddle of x² − y² + ½y⁴, sitting long with a tiny offset, escaping with noise, and why most critical points are saddles in high dimensions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; If SGD noise is what knocks you off saddles, what happens to that mechanism as batch size \(B\to n\)? How might that inform the “large-batch generalization” debate?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>28-01 Critical points and saddles</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_01_critical_points_and_saddles/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_01_critical_points_and_saddles</id>
   <content type="html">&lt;p&gt;When gradient descent slows to a crawl and \(\|\nabla F(w)\|_2 \approx 0\), you might assume you have arrived at a valley floor. In high dimensions, that assumption is almost always wrong: you are far more likely perched on a mountain pass—a &lt;strong&gt;saddle point&lt;/strong&gt; where the terrain slopes upward along some eigenvectors of the Hessian and downward along others. Classifying critical points cleanly through the Hessian spectrum is the first step toward designing optimizers that refuse to stall on high-dimensional passes.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-hessian-spectrum-and-critical-point-taxonomy&quot;&gt;Key ideas: Hessian Spectrum and Critical-Point Taxonomy&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Second-Order Taylor Model:&lt;/strong&gt; Near any critical point \(w\) where \(\nabla F(w) = 0\), the landscape looks locally quadratic: \(F(w + \Delta) \approx F(w) + \frac{1}{2}\Delta^\top H \Delta\), where \(H = \nabla^2 F(w)\) is symmetric with real eigenvalues \(\lambda_1 \le \dots \le \lambda_d\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strict Saddles vs. Degenerate Saddles:&lt;/strong&gt; A critical point is a &lt;em&gt;strict saddle&lt;/em&gt; if \(\lambda_{\min}(H) &amp;lt; 0\)—meaning there is a clear quadratic escape direction along the corresponding eigenvector. If \(\lambda_{\min}(H) = 0\) (degenerate/monkey saddle), second derivatives are inconclusive and higher-order derivatives dictate geometry.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-Order Necessary &amp;amp; Sufficient Conditions:&lt;/strong&gt; Every local minimum satisfies \(\nabla F(w) = 0\) and \(H \succeq 0\) (necessary); conversely, \(\nabla F(w) = 0\) and \(H \succ 0\) guarantees a strict local minimum (sufficient).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Saddle-to-Minimum Ratio in High Dimensions:&lt;/strong&gt; In random Gaussian landscapes (Dauphin et al. 2014), the fraction of critical points that are local minima shrinks like \(2^{-d}\); nearly every high-loss critical point is a strict saddle with negative curvature waiting to be exploited.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-classifying-all-critical-points-of-a-2d-nonconvex-surface&quot;&gt;Worked example: Classifying All Critical Points of a 2D Nonconvex Surface&lt;/h3&gt;

&lt;p&gt;Consider \(F(x, y) = x^3 - 3x + y^2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the gradient and set \(\nabla F(x, y) = 0\):&lt;/strong&gt;
\(\nabla F(x, y) = \begin{pmatrix} 3x^2 - 3 \\ 2y \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix} \implies (x, y) \in \{(1, 0),\ (-1, 0)\}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Hessian matrix \(H(x, y) = \nabla^2 F(x, y)\):&lt;/strong&gt;
\(H(x, y) = \begin{pmatrix} 6x &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Classify both critical points via eigenvalues:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;At \((1, 0)\): \(H(1, 0) = \operatorname{diag}(6, 2) \succ 0\) (eigenvalues \(6 &amp;gt; 0, 2 &amp;gt; 0\)) \(\implies\) &lt;strong&gt;strict local minimum&lt;/strong&gt; with \(F(1, 0) = -2\).&lt;/li&gt;
      &lt;li&gt;At \((-1, 0)\): \(H(-1, 0) = \operatorname{diag}(-6, 2)\) (eigenvalues \(-6 &amp;lt; 0, +2 &amp;gt; 0\)) \(\implies\) &lt;strong&gt;strict saddle point&lt;/strong&gt; with \(F(-1, 0) = +2\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Identify the escape direction at \((-1, 0)\):&lt;/strong&gt; Along eigenvector \(v = (1, 0)^\top\) (negative eigenvalue \(-6\)), stepping by \(\Delta = (\delta, 0)^\top\) gives \(F(-1 + \delta, 0) = 2 - 3\delta^2 + \delta^3 &amp;lt; 2\) for small \(\delta \ne 0\)—proving the saddle drops quadratically along \(x\) while rising quadratically along \(y\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let \(F:\mathbb{R}^d\to\mathbb{R}\) be twice continuously differentiable. A point \(w\) is &lt;strong&gt;critical&lt;/strong&gt; if \(\nabla F(w)=0\). The Hessian \(H=\nabla^2 F(w)\) then classifies the critical point &lt;em&gt;when it is nondegenerate&lt;/em&gt; (no zero eigenvalue):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Strict local minimum:&lt;/strong&gt; \(H\succ 0\) (all eigenvalues positive).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strict local maximum:&lt;/strong&gt; \(H\prec 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strict saddle:&lt;/strong&gt; \(H\) is indefinite — at least one positive and one negative eigenvalue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If some eigenvalues vanish, the test is inconclusive (think \(w\mapsto w^3\) or a plateau). Deep losses are full of near-degenerate directions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First-order methods do not see \(H\)&lt;/strong&gt;, but the local Taylor story still explains their behavior: along a negative-curvature direction \(u\), \(F(w+t u)\approx F(w)+\tfrac12 t^2 u^\top H u\) &lt;em&gt;decreases&lt;/em&gt; for small \(t\neq 0\). A saddle is not a trap for an algorithm that can move in that direction; it is a trap for algorithms that only look at \(\|\nabla F\|\) being small and stop.&lt;/p&gt;

&lt;p&gt;In high dimension, if eigenvalues of a “typical” Hessian at a critical point behave like a random symmetric matrix, the probability that &lt;em&gt;all&lt;/em&gt; of them are positive is exponentially small. The folk theorem you should remember: &lt;strong&gt;most critical points of high-dimensional generic functions are saddles, not minima&lt;/strong&gt;. Deep-learning losses are not generic Gaussians — but the intuition is why “getting stuck in local minima” is usually the wrong diagnosis after epoch 2.&lt;/p&gt;

&lt;h3 id=&quot;saddle-points-in-about-3-minutes&quot;&gt;Saddle points in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/saddle-escape_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;GD pulled into the saddle of x² − y² + ½y⁴, sitting long with a tiny offset, escaping with noise, and why most critical points are saddles in high dimensions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; For \(F(x,y)=x^2-y^2\) (the hyperbolic paraboloid) write \(\nabla F\) and \(H\). Starting at \((0,10^{-3})\), take two gradient steps with step size \(\eta = 0.1\). Starting at \((0,0)\), explain why GD with exact arithmetic never leaves.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>28 Nonconvex landscapes for deep learning</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_00_nonconvex_landscapes/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter28/28_00_nonconvex_landscapes</id>
   <content type="html">&lt;p&gt;For twenty-five chapters, convexity was our mathematical safety rail: every local minimum was automatically global, and finding \(\nabla F(w) = 0\) meant the job was finished. Yet deep neural networks tear off that safety rail completely—their loss surfaces are wildly nonconvex, teeming with symmetries, flat plateaus, and exponentially many saddle points. Why, then, does simple stochastic gradient descent routinely drive a billion-parameter network straight down to near-zero training loss? Chapter 28 unpacks the modern geometry of nonconvex optimization: why saddle points outnumber bad local minima in high dimensions, how noise escapes them, why overparameterization smooths the landscape, and how the Polyak–Łojasiewicz (PL) condition recovers fast linear convergence without convexity.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-navigating-nonconvex-loss-landscapes&quot;&gt;Key ideas: Navigating Nonconvex Loss Landscapes&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch28_nonconvex_saddles_pl.svg&quot; alt=&quot;Địa hình Không lồi: Điểm yên ngựa &amp;amp; Điều kiện PL&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;First-Order vs. Second-Order Stationarity:&lt;/strong&gt; Without convexity, \(\nabla F(w) = 0\) only certifies a &lt;em&gt;critical point&lt;/em&gt; (minimum, maximum, or saddle). Avoiding strict saddles requires second-order stationarity: \(\nabla F(w) = 0\) and \(\nabla^2 F(w) \succeq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High-Dimensional Saddle Dominance:&lt;/strong&gt; In \(d\) dimensions, a critical point is a local minimum only if all \(d\) Hessian eigenvalues are positive—an event whose probability vanishes exponentially as \(d\) grows. Thus the primary obstacle in deep learning is escaping &lt;strong&gt;saddle points&lt;/strong&gt;, not bad local minima.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Overparameterization &amp;amp; Connected Solution Manifolds:&lt;/strong&gt; When \(d \gg n\), global minima are no longer isolated points; they form high-dimensional connected valleys (mode connectivity), making it easy for gradient trajectories from almost any random initialization to reach a zero-loss basin.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Beyond Convexity — The PL Condition:&lt;/strong&gt; Even when \(F\) is nonconvex with non-unique minima, the gradient-dominance inequality \(\frac{1}{2}\|\nabla F(w)\|_2^2 \ge \mu (F(w) - F^\star)\) guarantees that every stationary point is global and restores linear convergence for plain gradient descent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-a-nonconvex-function-with-multiple-global-minima-and-a-saddle&quot;&gt;Worked example: A Nonconvex Function with Multiple Global Minima and a Saddle&lt;/h3&gt;

&lt;p&gt;Consider the classic 1D symmetric double-well potential \(F(w) = \frac{1}{4}(w^2 - 1)^2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find all critical points (\(F&apos;(w) = 0\)):&lt;/strong&gt;
\(F&apos;(w) = w(w^2 - 1) = 0 \implies w \in \{-1,\ 0,\ +1\}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Classify each critical point via the second derivative \(F&apos;&apos;(w) = 3w^2 - 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;At \(w = 0\): \(F(0) = 0.25\) and \(F&apos;&apos;(0) = -1 &amp;lt; 0\) (local maximum / strict 1D saddle—unstable!).&lt;/li&gt;
      &lt;li&gt;At \(w = \pm 1\): \(F(\pm 1) = 0\) and \(F&apos;&apos;(\pm 1) = +2 &amp;gt; 0\) (two symmetric global minima!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check convexity vs. optimizability:&lt;/strong&gt; Because \(F&apos;&apos;(0) = -1 &amp;lt; 0\), \(F\) is &lt;strong&gt;nonconvex&lt;/strong&gt;, and the midpoint \(0 = \frac{1}{2}(-1) + \frac{1}{2}(+1)\) has strictly higher loss (\(0.25 &amp;gt; 0\)) than both global minima. Yet from &lt;em&gt;any&lt;/em&gt; starting point \(w_0 \ne 0\), gradient descent slides effortlessly into one of the two global minima \(w^\star = \pm 1\)—showing why nonconvexity alone does not imply hardness!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;nonconvex-landscapes-for-deep-learning&quot;&gt;Nonconvex landscapes for deep learning&lt;/h1&gt;

&lt;p&gt;Convexity was the safety rail of Chapters 02–25: local minima are global, and first-order conditions certify optimality. A deep network’s training loss \(F(w)\) is &lt;strong&gt;nonconvex&lt;/strong&gt;. This chapter does not throw the rail away; it asks what &lt;em&gt;kind&lt;/em&gt; of nonconvexity practitioners actually meet.&lt;/p&gt;

&lt;p&gt;We will distinguish &lt;strong&gt;critical points&lt;/strong&gt; (\(\nabla F(w)=0\)) by the inertia of the Hessian: minima, maxima, and &lt;strong&gt;saddles&lt;/strong&gt;. We will see why high-dimensional saddles, not swampy local minima, are the usual obstruction, and why &lt;strong&gt;overparameterization&lt;/strong&gt; (more parameters than data constraints) can make almost all minima interpolate — the modern “why does SGD work?” story at course depth.&lt;/p&gt;

&lt;p&gt;EPFL CS-439 and USC CSCI 599 treat this as an advanced but expected module. We stay at the level of precise definitions plus pictures, not mean-field PDE limits.&lt;/p&gt;

&lt;p&gt;Open &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/loss_function_landscapes.html&quot;&gt;loss_function_landscapes.html&lt;/a&gt; while you read.&lt;/p&gt;

&lt;h2 id=&quot;lessons&quot;&gt;Lessons&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Critical points and saddles&lt;/li&gt;
  &lt;li&gt;Escaping saddles and landscape geometry&lt;/li&gt;
  &lt;li&gt;Overparameterization (and a pointer to the PL condition)&lt;/li&gt;
  &lt;li&gt;Modern landscape case studies (optional) — mode connectivity, grokking, double descent, flat minima&lt;/li&gt;
  &lt;li&gt;The PL condition and modern rates (optional) — Karimi et al.; reuse of the Chapter 06 linear rate without convexity&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The PL bridge from the strongly convex proofs of 06-03-04 to some nonconvex ERMs is now a lesson, not only an arXiv pointer: &lt;a href=&quot;/contents/en/chapter28/28_05_pl_condition/&quot;&gt;28-05&lt;/a&gt;. The 2022–2026 phenomena sit in &lt;a href=&quot;/contents/en/chapter28/28_04_modern_landscapes/&quot;&gt;28-04&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>27-03 Reverse mode and backpropagation</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_03_reverse_mode_backprop/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_03_reverse_mode_backprop</id>
   <content type="html">&lt;p&gt;Here is the single most consequential complexity theorem in modern deep learning: suppose you have a scalar loss \(\ell(w)\) that depends on \(d = 10^9\) weights. Forward-mode AD would require \(10^9\) passes to compute \(\nabla \ell(w)\). &lt;strong&gt;Reverse-mode AD&lt;/strong&gt; (popularized in neural networks as &lt;strong&gt;backpropagation&lt;/strong&gt;) flips the chain rule backward from the scalar output \(\ell\)—computing &lt;em&gt;all&lt;/em&gt; \(10^9\) partial derivatives simultaneously in &lt;strong&gt;one&lt;/strong&gt; backward pass at a total cost bounded by a small constant multiple (typically \(\le 4\times\)) of evaluating \(\ell\) itself!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-adjoints-vjps-and-the-cheap-gradient-principle&quot;&gt;Key ideas: Adjoints, VJPs, and the Cheap-Gradient Principle&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Adjoints (\(\bar{v} = \frac{\partial \ell}{\partial v}\)):&lt;/strong&gt; Reverse mode attaches a scalar sensitivity \(\bar{v}\) to every node measuring how much a tiny bump in \(v\) changes the final loss \(\ell\). We seed \(\bar{\ell} = 1\) and walk the DAG in &lt;em&gt;reverse&lt;/em&gt; topological order.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Accumulating Fan-Out Gradients (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+=&lt;/code&gt;):&lt;/strong&gt; Whenever node \(u\) feeds multiple children \(v^{(1)}, v^{(2)}\), its adjoint &lt;em&gt;accumulates&lt;/em&gt; via \(\bar{u} \mathrel{+}= \bar{v}^{(j)} \frac{\partial v^{(j)}}{\partial u}\)—the exact reason frameworks warn you to zero gradients between batches!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;One Pass = One Row of the Jacobian (VJP):&lt;/strong&gt; Seeding \(\bar{y} = u \in \mathbb{R}^m\) computes the Vector-Jacobian Product \(u^\top J_f(x)\). When \(m = 1\) (scalar loss), a single reverse pass hands you the entire gradient \(\nabla_x \ell \in \mathbb{R}^n\) regardless of how huge \(n\) is (Baur–Strassen Cheap-Gradient Principle).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Memory Price of Reversal:&lt;/strong&gt; Because local derivatives like \(\frac{\partial (uv)}{\partial u} = v\) depend on forward values, reverse mode must cache forward intermediates on a tape—making activation memory, not FLOPs, the primary bottleneck of large-scale training.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-full-forward--reverse-adjoint-trace-on-a-2-layer-relu-loss&quot;&gt;Worked example: Full Forward + Reverse Adjoint Trace on a 2-Layer ReLU Loss&lt;/h3&gt;

&lt;p&gt;Evaluate \(\ell = (w_2 \cdot \operatorname{relu}(w_1 x) - y)^2\) at \(x = 2\), \(y = 5\), \(w_1 = 1.5\), \(w_2 = 2.0\), and find \(\frac{\partial \ell}{\partial w_1}\) and \(\frac{\partial \ell}{\partial w_2}\) via reverse-mode AD.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Forward pass (record intermediates on tape):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(z_1 = w_1 x = (1.5)(2) = 3.0\).&lt;/li&gt;
      &lt;li&gt;\(a_1 = \operatorname{relu}(z_1) = 3.0\) (active since \(z_1 &amp;gt; 0\)).&lt;/li&gt;
      &lt;li&gt;\(\hat{y} = w_2 a_1 = (2.0)(3.0) = 6.0\).&lt;/li&gt;
      &lt;li&gt;\(e = \hat{y} - y = 6.0 - 5.0 = 1.0\).&lt;/li&gt;
      &lt;li&gt;\(\ell = e^2 = 1.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reverse pass (seed \(\bar{\ell} = 1\) and walk backward):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\bar{e} = \bar{\ell} \cdot 2e = 1 \cdot 2(1.0) = 2.0\).&lt;/li&gt;
      &lt;li&gt;\(\bar{\hat{y}} = \bar{e} \cdot 1 = 2.0\).&lt;/li&gt;
      &lt;li&gt;\(\bar{w}_2 = \bar{\hat{y}} \cdot a_1 = 2.0 \cdot 3.0 = 6.0\).&lt;/li&gt;
      &lt;li&gt;\(\bar{a}_1 = \bar{\hat{y}} \cdot w_2 = 2.0 \cdot 2.0 = 4.0\).&lt;/li&gt;
      &lt;li&gt;\(\bar{z}_1 = \bar{a}_1 \cdot \mathbf{1}[z_1 &amp;gt; 0] = 4.0 \cdot 1 = 4.0\).&lt;/li&gt;
      &lt;li&gt;\(\bar{w}_1 = \bar{z}_1 \cdot x = 4.0 \cdot 2 = 8.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Result:&lt;/strong&gt; In a single reverse sweep, we obtained the exact gradient \(\bigl(\frac{\partial \ell}{\partial w_1}, \frac{\partial \ell}{\partial w_2}\bigr) = (8.0,\ 6.0)\), matching the analytic derivatives \(2(w_2 w_1 x - y) w_2 x = 2(1)(2)(2) = 8\) and \(2(w_2 w_1 x - y)(w_1 x) = 2(1)(3) = 6\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Reverse-mode AD&lt;/strong&gt; attaches to every node \(v\) an &lt;strong&gt;adjoint&lt;/strong&gt; \(\bar v = \frac{\partial \ell}{\partial v}\) for a scalar output \(\ell\). After the forward sweep stores intermediates, we go &lt;em&gt;backward&lt;/em&gt;:&lt;/p&gt;

\[\bar u \mathrel{+}= \bar v\cdot \partial_u h
\quad\text{when } v=h(u,\ldots).\]

&lt;p&gt;One reverse sweep produces the full gradient \(\nabla_w \ell\) — a &lt;strong&gt;vector–Jacobian product&lt;/strong&gt; \((\nabla \ell)^\top J\). Cost is a small constant times the forward cost, &lt;em&gt;independent of the number of parameters&lt;/em&gt;. That single sentence is why deep learning is computationally possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backpropagation&lt;/strong&gt; is reverse-mode AD applied to a layered net, with the adjoint at layer \(k\) being the familiar \(\delta^{(k)}\) (we write \(k\) for the layer index, since \(\ell\) already denotes the loss):&lt;/p&gt;

\[\delta^{(k)} = \bigl(W^{(k+1)\top}\delta^{(k+1)}\bigr)\odot \phi&apos;(z^{(k)}).\]

&lt;p&gt;Nothing mystical: matrix multiplies are elementary nodes with known local Jacobians.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Scalar toy: ℓ = (w2 * relu(w1 * x) - y)**2
# Manual reverse vs a tiny tape
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ell&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# reverse
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d_ell&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_ell&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_w2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d_w1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d_w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d_w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Compare with PyTorch: build the same expression as tensors with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;requires_grad=True&lt;/code&gt; and call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ell.backward()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memory.&lt;/strong&gt; Reverse mode stores the forward tape. Checkpointing / rematerialization trades compute for RAM — the reason gradient checkpointing appears in large-model training. That is an implementation footnote, not a different derivative.&lt;/p&gt;

&lt;p&gt;When you have &lt;em&gt;many&lt;/em&gt; outputs and few inputs, prefer forward mode. When you have one loss and a sea of weights, prefer reverse. Mixed mode (forward-over-reverse Hessian–vector products) is how some second-order and bilevel methods stay linear in dimension.&lt;/p&gt;

&lt;h3 id=&quot;forward-and-reverse-mode-in-about-3-minutes&quot;&gt;Forward and reverse mode in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/autodiff-forward-reverse_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The computation graph of x₁x₂ + sin x₁: tangents and dual numbers, adjoints flowing backward, the ReLU toy of lesson 27-03, and counting sweeps.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>27-02 Forward-mode AD</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_02_forward_mode/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_02_forward_mode</id>
   <content type="html">&lt;p&gt;What if you could compute a function’s value &lt;em&gt;and&lt;/em&gt; its directional derivative simultaneously, in a single forward sweep, with zero extra memory for storing tapes? That is the elegance of &lt;strong&gt;Forward-Mode Automatic Differentiation&lt;/strong&gt; (also known as dual-number arithmetic). By attaching a tiny tangent \(\dot{v}\) to every scalar \(v\)—formally writing \(v + \dot{v}\epsilon\) with \(\epsilon^2 = 0\)—every elementary operation automatically propagates exact Jacobian-vector products (JVPs) right alongside the primal computation.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-dual-numbers-tangents-and-jacobian-vector-products&quot;&gt;Key ideas: Dual Numbers, Tangents, and Jacobian-Vector Products&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dual Number Algebra (\(\epsilon^2 = 0\)):&lt;/strong&gt; Carrying pairs \((v, \dot{v})\) under arithmetic rules \((a, \dot{a}) + (b, \dot{b}) = (a+b, \dot{a}+\dot{b})\) and \((a, \dot{a})(b, \dot{b}) = (ab, \dot{a}b + a\dot{b})\) computes exact derivatives via pure operator overloading—no graph tape required!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;One Pass = One Column of the Jacobian (JVP):&lt;/strong&gt; Seeding the input tangent \(\dot{x} = u \in \mathbb{R}^n\) computes the directional derivative \(J_f(x) u \in \mathbb{R}^m\) in a single forward pass. Setting \(u = e_j\) extracts the \(j\)-th column of \(J_f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complexity Sweet Spot (\(n \ll m\)):&lt;/strong&gt; Computing the full Jacobian \(J_f(x) \in \mathbb{R}^{m \times n}\) costs \(n\) forward passes. Forward mode therefore dominates whenever inputs are few and outputs are many (e.g., differentiating a 1000-output ODE trajectory with respect to 3 physical parameters).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constant Memory Footprint:&lt;/strong&gt; Unlike reverse mode, forward mode never needs to store intermediate activations for a backward sweep—making it ultra-lightweight in memory-constrained scientific simulations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-a-jvp-with-dual-numbers&quot;&gt;Worked example: Computing a JVP with Dual Numbers&lt;/h3&gt;

&lt;p&gt;Let \(f(x_1, x_2) = (x_1^2 x_2,\ \ln(x_1) + x_2)^\top\) at \(x = (1, 2)^\top\). We want the directional derivative (JVP) along seed direction \(\dot{x} = (3, -1)^\top\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Initialize dual numbers:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v_1 = (x_1, \dot{x}_1) = (1,\ 3)\),&lt;/li&gt;
      &lt;li&gt;\(v_2 = (x_2, \dot{x}_2) = (2,\ -1)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Propagate forward through each elementary op:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v_3 = v_1^2 = (1^2,\ 2 \cdot 1 \cdot 3) = (1,\ 6)\).&lt;/li&gt;
      &lt;li&gt;\(y_1 = v_3 \cdot v_2 = (1 \cdot 2,\ 6 \cdot 2 + 1 \cdot (-1)) = (2,\ 11)\).&lt;/li&gt;
      &lt;li&gt;\(v_4 = \ln(v_1) = (\ln 1,\ \frac{1}{1}\cdot 3) = (0,\ 3)\).&lt;/li&gt;
      &lt;li&gt;\(y_2 = v_4 + v_2 = (0 + 2,\ 3 + (-1)) = (2,\ 2)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Read off both value and JVP in one pass:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal output: \(f(1, 2) = (2, 2)^\top\).&lt;/li&gt;
      &lt;li&gt;Exact JVP: \(J_f(1, 2)\begin{pmatrix} 3 \\ -1 \end{pmatrix} = \begin{pmatrix} 11 \\ 2 \end{pmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Cross-check with the full Jacobian:&lt;/strong&gt; $$J_f(x_1, x_2) = \begin{pmatrix} 2 x_1 x_2 &amp;amp; x_1^2 \ 1/x_1 &amp;amp; 1 \end{pmatrix} \big&lt;/td&gt;
          &lt;td&gt;_{(1,2)} = \begin{pmatrix} 4 &amp;amp; 1 \ 1 &amp;amp; 1 \end{pmatrix}\(, and\)\begin{pmatrix} 4 &amp;amp; 1 \ 1 &amp;amp; 1 \end{pmatrix}\begin{pmatrix} 3 \ -1 \end{pmatrix} = \begin{pmatrix} 11 \ 2 \end{pmatrix}$$. Exact!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Associate to every node \(v\) a &lt;strong&gt;tangent&lt;/strong&gt; \(\dot v = \frac{\partial v}{\partial t}\) along a chosen input direction (one scalar seed). If \(v=h(u,w)\) then&lt;/p&gt;

\[\dot v = \partial_u h\cdot \dot u + \partial_w h\cdot \dot w.\]

&lt;p&gt;Running the original program &lt;em&gt;together with&lt;/em&gt; these tangent recurrences yields a &lt;strong&gt;Jacobian–vector product&lt;/strong&gt; \(J_f(x)\, \dot x\) at essentially a small constant factor times the cost of \(f\). That is &lt;strong&gt;forward-mode AD&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If \(f:\mathbb{R}^n\to\mathbb{R}^m\) with \(n\ll m\) (few inputs, many outputs), forward mode is cheap: \(n\) seeded sweeps give the full Jacobian. If \(n\gg m\) — one loss, a million weights — forward mode is the wrong default. You would need a million sweeps.&lt;/p&gt;

&lt;p&gt;Finite differences \([f(x+\varepsilon e_i)-f(x)]/\varepsilon\) approximate the same Jacobian–vector products but waste precision and need a step \(\varepsilon\). Forward AD is exact up to floating-point, with no \(\varepsilon\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tiny walk-through.&lt;/strong&gt; \(f(x_1,x_2)=x_1 x_2 + \sin(x_1)\), seed \(\dot x=(1,0)\). Then \(\dot f = x_2 + \cos(x_1)\), which is \(\partial_{x_1}f\). A second seed \((0,1)\) yields \(\partial_{x_2}f=x_1\).&lt;/p&gt;

&lt;p&gt;Forward mode is what you want for sensitivities of a &lt;em&gt;simulation&lt;/em&gt; with few parameters (ODE shooting, some Hessian–vector recipes via “forward-over-reverse”). Deep learning almost always wants the next lesson.&lt;/p&gt;

&lt;h3 id=&quot;forward-and-reverse-mode-in-about-3-minutes&quot;&gt;Forward and reverse mode in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/autodiff-forward-reverse_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The computation graph of x₁x₂ + sin x₁: tangents and dual numbers, adjoints flowing backward, the ReLU toy of lesson 27-03, and counting sweeps.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>27-01 Computational graphs</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_01_computational_graphs/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_01_computational_graphs</id>
   <content type="html">&lt;p&gt;Before an autodiff engine can compute a single derivative, it must first see your program not as lines of Python, but as a &lt;strong&gt;computational graph&lt;/strong&gt;—a Directed Acyclic Graph (DAG) where every node is an intermediate tensor and every edge represents an elementary operation with a known local derivative. The moment a computation becomes a DAG, the multivariable chain rule turns into a pure graph-traversal algorithm: total derivatives are simply the sum of products of edge weights along every directed path from an input to an output!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-graph-structure-fan-out-and-memory-trade-offs&quot;&gt;Key ideas: Graph Structure, Fan-Out, and Memory Trade-Offs&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nodes, Edges, and Topological Order:&lt;/strong&gt; Inputs sit at source nodes, intermediate variables \(v_1, \dots, v_K\) are evaluated in topological order so every parent is computed before its children, and the scalar loss \(\ell\) sits at the sink.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multivariable Chain Rule as Path Summation:&lt;/strong&gt; If node \(x\) influences output \(\ell\) along multiple branches (fan-out), the total derivative \(\frac{\partial \ell}{\partial x}\) is the &lt;strong&gt;sum&lt;/strong&gt; of contributions across all outgoing edges: \(\sum_{c \in \text{children}(x)} \frac{\partial \ell}{\partial c}\frac{\partial c}{\partial x}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Static vs. Dynamic Graphs (Define-and-Run vs. Define-by-Run):&lt;/strong&gt; Dynamic tape graphs (PyTorch eager mode) record operations on the fly—supporting native Python &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for&lt;/code&gt; control flow—while traced/compiled graphs (JAX &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jit&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.compile&lt;/code&gt;) enable global kernel fusion and memory planning.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Activation Checkpointing:&lt;/strong&gt; Because reverse-mode AD needs intermediate forward values to evaluate local derivatives, memory scales with graph depth. Checkpointing discards selected intermediates and recomputes them during the backward pass, trading extra compute for \(O(\sqrt{L})\) memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-unrolling-a-fan-out-function-into-a-dag-and-summing-paths&quot;&gt;Worked example: Unrolling a Fan-Out Function Into a DAG and Summing Paths&lt;/h3&gt;

&lt;p&gt;Consider \(f(x_1, x_2) = x_1 x_2 + \sin(x_1)\) at \((x_1, x_2) = (0, 3)\). Notice \(x_1\) fans out into &lt;strong&gt;two&lt;/strong&gt; branches!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Build the topological DAG evaluation trace:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v_1 = x_1 = 0\), \(v_2 = x_2 = 3\).&lt;/li&gt;
      &lt;li&gt;\(v_3 = v_1 \cdot v_2 = 0 \cdot 3 = 0\) (local partials: \(\frac{\partial v_3}{\partial v_1} = v_2 = 3\), \(\frac{\partial v_3}{\partial v_2} = v_1 = 0\)).&lt;/li&gt;
      &lt;li&gt;\(v_4 = \sin(v_1) = \sin(0) = 0\) (local partial: \(\frac{\partial v_4}{\partial v_1} = \cos(0) = 1\)).&lt;/li&gt;
      &lt;li&gt;\(v_5 = v_3 + v_4 = 0\) (local partials: \(\frac{\partial v_5}{\partial v_3} = 1\), \(\frac{\partial v_5}{\partial v_4} = 1\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(\frac{\partial v_5}{\partial x_1}\) by summing over all directed paths from \(v_1\) to \(v_5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Path 1 (\(v_1 \to v_3 \to v_5\)): \(\frac{\partial v_5}{\partial v_3}\cdot\frac{\partial v_3}{\partial v_1} = 1 \cdot 3 = 3\).&lt;/li&gt;
      &lt;li&gt;Path 2 (\(v_1 \to v_4 \to v_5\)): \(\frac{\partial v_5}{\partial v_4}\cdot\frac{\partial v_4}{\partial v_1} = 1 \cdot 1 = 1\).&lt;/li&gt;
      &lt;li&gt;Sum of paths: \(\frac{\partial v_5}{\partial x_1} = 3 + 1 = 4\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify analytically:&lt;/strong&gt; \(\frac{\partial}{\partial x_1}(x_1 x_2 + \sin x_1) = x_2 + \cos(x_1) = 3 + 1 = 4\). Exact match!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A &lt;strong&gt;computational graph&lt;/strong&gt; is a directed acyclic graph whose nodes are values and whose edges record elementary maps (\(+\), \(\times\), \(\exp\), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;matmul&lt;/code&gt;, …). Parameters, inputs, and the scalar loss are just distinguished nodes.&lt;/p&gt;

&lt;p&gt;Example. Logistic loss on one example with weights \(w\in\mathbb{R}^2\):&lt;/p&gt;

\[z = w_1 x_1 + w_2 x_2, \quad p=\sigma(z), \quad \ell = -y\log p -(1-y)\log(1-p).\]

&lt;p&gt;Nodes: \(x\), \(w\), \(z\), \(p\), \(\ell\). The graph &lt;em&gt;is&lt;/em&gt; the program. Changing a weight changes every downstream node; AD’s job is to push that sensitivity to \(\ell\) or to pull the sensitivity of \(\ell\) backward.&lt;/p&gt;

&lt;p&gt;Two implementation styles:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Wengert tape / define-by-run&lt;/strong&gt; (PyTorch): the graph is recorded while the Python &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forward&lt;/code&gt; executes. Control flow is ordinary Python.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Define-then-run&lt;/strong&gt; (historical Theano, JAX &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jit&lt;/code&gt; traces): you first build or trace a static graph, then execute it many times.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this course the distinction matters only so that you know why &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y.backward()&lt;/code&gt; needs a graph that still exists — calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;backward&lt;/code&gt; twice without &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;retain_graph&lt;/code&gt; frees the tape.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Draw the graph for \(\ell=\|W_2\,\phi(W_1 x)-y\|_2^2\) with one hidden layer. Count multiplies on the forward pass. That count will reappear as the cost of reverse mode.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>27 Automatic differentiation</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_00_automatic_differentiation/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter27/27_00_automatic_differentiation</id>
   <content type="html">&lt;p&gt;Every optimizer in Chapter 26 assumes a magic oracle hands you \(\nabla F(w)\) on demand. Yet for a billion-parameter neural network, deriving gradients by hand is impossible, symbolic algebra explodes into megabytes of redundant expressions, and finite differences suffer both catastrophic roundoff error and \(O(d)\) cost. &lt;strong&gt;Automatic Differentiation (AD)&lt;/strong&gt; is the quiet miracle that resolves all three failures at once: by applying the chain rule mechanically to elementary operations inside a computational graph, reverse-mode AD computes the &lt;em&gt;exact&lt;/em&gt; gradient of a scalar loss with respect to a billion parameters in roughly &lt;strong&gt;2–3×&lt;/strong&gt; the cost of a single forward pass.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-four-pillars-of-automatic-differentiation&quot;&gt;Key ideas: The Four Pillars of Automatic Differentiation&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch27_autodiff_forward_reverse.svg&quot; alt=&quot;Vi phân Tự động: Chế độ Xuôi vs. Chế độ Ngược&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Not Symbolic, Not Finite Differences:&lt;/strong&gt; Finite differences approximate derivatives via \(\frac{f(x+h)-f(x)}{h}\) (truncation + cancellation error, \(O(d)\) evaluations). Symbolic differentiation manipulates closed-form formulas (expression swell). AD differentiates &lt;em&gt;numerical execution traces&lt;/em&gt; at machine precision.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational Graphs (DAGs):&lt;/strong&gt; Every differentiable program unrolls into a Directed Acyclic Graph of elementary primitives (\(+, \times, \exp, \text{matmul}\)) whose local derivatives are known analytically.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Forward Mode (JVP) vs. Reverse Mode (VJP):&lt;/strong&gt; Forward mode propagates input tangents \(\dot{v} = J_v \dot{x}\) in one pass (ideal when inputs \(n \ll m\) outputs). Reverse mode propagates output adjoints \(\bar{v} = J_v^\top \bar{y}\) backward from the loss (ideal when \(n \gg m = 1\), i.e., deep learning!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Higher-Order &amp;amp; Implicit Differentiation:&lt;/strong&gt; Composing JVPs and VJPs yields exact Hessian-vector products in \(O(1)\) passes, while implicit differentiation (IFF / unrolling) computes hypergradients for bilevel optimization.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-finite-differences-fail-while-ad-is-exact&quot;&gt;Worked example: Why Finite Differences Fail While AD Is Exact&lt;/h3&gt;

&lt;p&gt;Consider \(f(x) = \sin(x^2)\) at \(x = 2.0\), where the exact derivative is \(f&apos;(2) = 2x\cos(x^2) = 4\cos(4) \approx -2.61457448\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Finite difference with \(h = 10^{-1}\) (truncation error):&lt;/strong&gt;
\(\frac{\sin(2.1^2) - \sin(2.0^2)}{0.1} = \frac{\sin(4.41) - \sin(4.0)}{0.1} \approx \frac{-0.9546 - (-0.7568)}{0.1} = -1.978\) (off by \(24\%\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Finite difference with \(h = 10^{-15}\) (floating-point cancellation):&lt;/strong&gt; In IEEE-754 float64, \(x + h\) loses almost all significant digits of \(h\), producing pure rounding garbage!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Automatic Differentiation (forward tangent trace at \(x = 2, \dot{x} = 1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v_1 = x = 2\), \(\dot{v}_1 = 1\).&lt;/li&gt;
      &lt;li&gt;\(v_2 = v_1^2 = 4\), \(\dot{v}_2 = 2 v_1 \dot{v}_1 = 4\).&lt;/li&gt;
      &lt;li&gt;\(v_3 = \sin(v_2) = \sin(4)\), \(\dot{v}_3 = \cos(v_2)\dot{v}_2 = 4\cos(4) \approx -2.61457448\).
AD returns the &lt;strong&gt;exact&lt;/strong&gt; derivative to all 16 digits of float64 precision in a single pass with zero step-size tuning!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;automatic-differentiation&quot;&gt;Automatic differentiation&lt;/h1&gt;

&lt;p&gt;Every optimizer in Chapter 26 needs a gradient. In 2026 that gradient is almost never derived on paper and almost never a numerical finite difference. &lt;strong&gt;Automatic differentiation (AD)&lt;/strong&gt; evaluates &lt;em&gt;exact&lt;/em&gt; derivatives of a program by systematically applying the chain rule to elementary operations.&lt;/p&gt;

&lt;p&gt;This chapter answers three questions:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;What is a &lt;strong&gt;computational graph&lt;/strong&gt;, and how is a loss “just a program”?&lt;/li&gt;
  &lt;li&gt;How does &lt;strong&gt;forward-mode&lt;/strong&gt; AD compute Jacobian–vector products?&lt;/li&gt;
  &lt;li&gt;Why is &lt;strong&gt;backpropagation&lt;/strong&gt; reverse-mode AD, and why is reverse mode the right default when we have one scalar loss and millions of parameters?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The survey to keep on your desk is Baydin, Pearlmutter, Radul, Siskind, &lt;em&gt;Automatic Differentiation in Machine Learning: a Survey&lt;/em&gt;, JMLR 18(153), 2018, &lt;a href=&quot;https://www.jmlr.org/papers/v18/17-468.html&quot;&gt;jmlr.org/papers/v18/17-468.html&lt;/a&gt;. Nocedal &amp;amp; Wright already treated “calculating derivatives” as part of numerical optimization; AD is that chapter after software caught up.&lt;/p&gt;

&lt;h2 id=&quot;lessons&quot;&gt;Lessons&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Computational graphs&lt;/li&gt;
  &lt;li&gt;Forward mode&lt;/li&gt;
  &lt;li&gt;Reverse mode and backpropagation&lt;/li&gt;
  &lt;li&gt;Autodiff frameworks and scientific ML (optional) — PyTorch, JAX, Enzyme, PINNs&lt;/li&gt;
  &lt;li&gt;Bilevel optimization and hypergradients (optional) — HPO / meta as one nested template&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Manual reverse mode on a three-node net versus &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.autograd&lt;/code&gt; is the lab: if they disagree, your graph or your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;detach&lt;/code&gt; is wrong — not the definition of a derivative. The optional software map is &lt;a href=&quot;/contents/en/chapter27/27_04_autodiff_frameworks/&quot;&gt;27-04&lt;/a&gt;. The nested HPO / MAML template — unrolling versus implicit differentiation — is &lt;a href=&quot;/contents/en/chapter27/27_05_bilevel_hypergrad/&quot;&gt;27-05&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26-05 Variance reduction — SVRG and SAGA</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_05_variance_reduction/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_05_variance_reduction</id>
   <content type="html">&lt;p&gt;Earlier in this chapter, we saw why SGD stalls at an \(O(1/\sqrt{T})\) crawl even on strongly convex quadratics: even when \(w_k\) lands right on the exact global optimum \(w^\star\), individual sample gradients \(\nabla f_i(w^\star)\) are still nonzero, kicking \(w_k\) right back out! In 2013–2014, Johnson &amp;amp; Zhang (SVRG) and Defazio, Bach &amp;amp; Lacoste-Julien (SAGA) broke that barrier using a classic Monte Carlo weapon—&lt;strong&gt;control variates&lt;/strong&gt;. By subtracting a stale gradient at a snapshot point and adding back its exact average, the gradient estimator stays unbiased while its variance shrinks to &lt;em&gt;zero&lt;/em&gt; as \(w_k \to w^\star\), restoring fast linear convergence \(O\bigl((n + \kappa)\log(1/\varepsilon)\bigr)\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-control-variates-svrg-and-saga&quot;&gt;Key ideas: Control Variates, SVRG, and SAGA&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Why SGD Cannot Converge Linearly:&lt;/strong&gt; For finite sums \(F(w) = \frac{1}{n}\sum_{i=1}^n f_i(w)\), \(\nabla F(w^\star) = 0\) does not imply \(\nabla f_i(w^\star) = 0\). Without variance vanishing at \(w^\star\), constant-step SGD hits a non-zero noise ball.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Control-Variate Estimator:&lt;/strong&gt; Given any reference snapshot \(\tilde{w}\) with known full gradient \(\tilde{\mu} = \nabla F(\tilde{w})\), define \(v_k = \nabla f_{i_k}(w_k) - \nabla f_{i_k}(\tilde{w}) + \tilde{\mu}\). Because \(\mathbb{E}[\nabla f_{i_k}(\tilde{w})] = \tilde{\mu}\), \(v_k\) is &lt;strong&gt;strictly unbiased&lt;/strong&gt;, and its variance is bounded by \(O(\|w_k - \tilde{w}\|_2^2)\)—vanishing as both \(w_k\) and \(\tilde{w}\) approach \(w^\star\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVRG (Low Memory, Periodic Snapshots):&lt;/strong&gt; Computes one full gradient \(\tilde{\mu} = \nabla F(\tilde{w})\) every \(m \approx 2n\) inner steps. Costs \(O(d)\) memory (no per-example table!) at the price of 2 gradient evaluations per inner step plus periodic full passes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SAGA (Incremental Table, No Full Passes):&lt;/strong&gt; Maintains a table of the latest gradient \(g_i\) for each of the \(n\) examples and updates its running average in \(O(d)\) per step—requiring only 1 gradient evaluation per step at the cost of \(O(nd)\) memory (or \(O(n)\) for linear models).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-an-svrg-control-variate-step-at-wstar&quot;&gt;Worked example: Computing an SVRG Control-Variate Step at \(w^\star\)&lt;/h3&gt;

&lt;p&gt;Return to our 2-sample finite sum \(F(w) = \frac{1}{2}\bigl(f_1(w) + f_2(w)\bigr)\) with \(f_1(w) = \frac{1}{2}(w - 1)^2\) and \(f_2(w) = \frac{1}{2}(w + 1)^2\) (optimum \(w^\star = 0\)). Suppose our snapshot is \(\tilde{w} = 0.2\) and current iterate is \(w_k = 0.1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the snapshot full gradient once:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f_1&apos;(\tilde{w}) = 0.2 - 1 = -0.8\), \(f_2&apos;(\tilde{w}) = 0.2 + 1 = 1.2\).&lt;/li&gt;
      &lt;li&gt;Full gradient: \(\tilde{\mu} = F&apos;(\tilde{w}) = \frac{1}{2}(-0.8 + 1.2) = 0.2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare ordinary SGD vs. SVRG when sampling \(i_k = 1\) at \(w_k = 0.1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Plain SGD gradient:&lt;/strong&gt; \(g_{\text{SGD}} = f_1&apos;(0.1) = 0.1 - 1 = -0.9\) (wrong sign relative to \(F&apos;(0.1) = +0.1\), huge error $$&lt;/td&gt;
              &lt;td&gt;-0.9 - 0.1&lt;/td&gt;
              &lt;td&gt;= 1.0$$!).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;SVRG gradient:&lt;/strong&gt;
\(v_k = f_1&apos;(0.1) - f_1&apos;(0.2) + \tilde{\mu} = (-0.9) - (-0.8) + 0.2 = +0.1 = F&apos;(0.1)!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check sampling \(i_k = 2\) as well:&lt;/strong&gt;
\(v_k = f_2&apos;(0.1) - f_2&apos;(0.2) + \tilde{\mu} = (1.1) - (1.2) + 0.2 = +0.1 = F&apos;(0.1)!\)
On quadratics with identical curvature, the SVRG control variate cancels sample noise &lt;strong&gt;100% exactly&lt;/strong&gt;, and on general smooth functions its variance collapses quadratically to \(0\) as \(w_k, \tilde{w} \to w^\star\)—unlocking constant-step linear convergence!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;SGD’s \(O(1/\sqrt{T})\) ceiling on a convex Lipschitz finite sum is not an information-theoretic destiny. It is the price of using an &lt;em&gt;unbiased but noisy&lt;/em&gt; gradient whose variance stays order-one even as \(w\) sits at a minimizer. &lt;strong&gt;Variance-reduced&lt;/strong&gt; methods reuse old gradients so that the estimator becomes exact at a snapshot (or in a table), and the noise dies as \(w\) approaches a minimizer. This lesson is the Opt-for-ML core — SVRG and SAGA — at course depth: enough algebra to see &lt;em&gt;why&lt;/em&gt; the variance vanishes, enough algorithm to implement, and a clear “do not train ResNets this way” boundary.&lt;/p&gt;

&lt;p&gt;You already met the noisy path in &lt;a href=&quot;/contents/en/chapter26/26_01_sgd_and_minibatch/&quot;&gt;26-01&lt;/a&gt; and the batch-versus-stochastic cartoon in &lt;a href=&quot;/contents/en/chapter08/08_02_04_batch_vs_stochastic_methods/&quot;&gt;08-02-04&lt;/a&gt;. Re-open &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/stochastic_gradient_demo.html&quot;&gt;stochastic_gradient_demo.html&lt;/a&gt; and watch the path jitter &lt;em&gt;after&lt;/em&gt; it has reached the bowl: that leftover jitter is the disease this page treats.&lt;/p&gt;

&lt;h2 id=&quot;the-finite-sum-problem-and-why-sgd-cannot-go-linear&quot;&gt;The finite-sum problem, and why SGD cannot go linear&lt;/h2&gt;

&lt;p&gt;Empirical risk is an average,&lt;/p&gt;

\[F(w)=\frac{1}{n}\sum_{i=1}^n f_i(w),\qquad
\nabla F(w)=\frac{1}{n}\sum_{i=1}^n \nabla f_i(w).\]

&lt;p&gt;A single-example SGD step uses \(g_k=\nabla f_{I_k}(w_k)\). If \(I_k\) is uniform and independent of \(w_k\), then \(\mathbb{E}[g_k\mid w_k]=\nabla F(w_k)\) — unbiased — but&lt;/p&gt;

\[\mathbb{E}\bigl[\|g_k-\nabla F(w_k)\|_2^2\mid w_k\bigr]\]

&lt;p&gt;need not go to zero as \(w_k\to w^\star\). Even at a minimizer, \(\nabla f_i(w^\star)\) can be a large vector that merely &lt;em&gt;averages&lt;/em&gt; to zero (think of a well-specified linear model whose residuals still have variance). Bounded-variance SGD on a convex Lipschitz objective therefore stalls at \(O(1/\sqrt{T})\) in function values. Strong convexity does not save you if the noise floor is constant: the iterates bounce in a ball of radius proportional to \(\eta\sigma\).&lt;/p&gt;

&lt;p&gt;Full-batch gradient descent &lt;em&gt;does&lt;/em&gt; go linear under strong convexity (Chapter 06), but each step costs \(n\) gradients. Variance reduction asks for the linear rate at a cost closer to one gradient per step.&lt;/p&gt;

&lt;h2 id=&quot;the-control-variate-idea&quot;&gt;The control-variate idea&lt;/h2&gt;

&lt;p&gt;Pick any snapshot \(\tilde w\) at which you are willing to compute the &lt;em&gt;full&lt;/em&gt; gradient \(\mu=\nabla F(\tilde w)\) once. For a random index \(I\) the vector&lt;/p&gt;

\[g(w)=\nabla f_I(w)-\nabla f_I(\tilde w)+\mu\]

&lt;p&gt;is still unbiased for \(\nabla F(w)\):&lt;/p&gt;

\[\mathbb{E}[g(w)]
=\nabla F(w)-\nabla F(\tilde w)+\nabla F(\tilde w)
=\nabla F(w).\]

&lt;p&gt;When \(w=\tilde w\) one has \(g(\tilde w)=\mu=\nabla F(\tilde w)\) &lt;em&gt;exactly&lt;/em&gt; — the noise is zero at the snapshot. When \(w\) is close to \(\tilde w\) and each \(\nabla f_i\) is Lipschitz, \(\nabla f_I(w)-\nabla f_I(\tilde w)\) is small, so the variance of \(g\) is small. That is a &lt;strong&gt;control variate&lt;/strong&gt;: we subtract a correlated copy of the noise and add back its mean.&lt;/p&gt;

&lt;h2 id=&quot;svrg-johnson--zhang-2013&quot;&gt;SVRG (Johnson &amp;amp; Zhang, 2013)&lt;/h2&gt;

&lt;p&gt;SVRG refreshes the snapshot on an outer loop and walks with the control variate on an inner loop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Outer loop&lt;/strong&gt; \(s=0,1,\ldots,S-1\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Set the snapshot \(\tilde w\leftarrow w\) and compute \(\mu\leftarrow\nabla F(\tilde w)\) (one full pass, \(n\) gradients).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inner loop&lt;/strong&gt; \(t=0,1,\ldots,m-1\): draw \(I\) uniformly, set
\(g\leftarrow\nabla f_I(w)-\nabla f_I(\tilde w)+\mu,\qquad
w\leftarrow w-\eta g.\)&lt;/li&gt;
  &lt;li&gt;Optionally average the inner path, or keep the last \(w\), and return to step 1.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A standard choice is \(m=\Theta(n)\) inner steps, so the &lt;em&gt;amortized&lt;/em&gt; cost is a small constant times one gradient per step: one full gradient every \(m\) steps, plus two stochastic gradients per inner step. Memory beyond the parameter vector is one snapshot \(\tilde w\) and one vector \(\mu\) — \(O(d)\), independent of \(n\).&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem (sketch, strongly convex finite-sum).&lt;/strong&gt; If each \(f_i\) is \(L\)-smooth and \(F\) is \(\mu\)-strongly convex, a sufficiently small constant \(\eta\) and \(m\gtrsim L/\mu\) yield&lt;/p&gt;

\[\mathbb{E}\bigl[F(\tilde w_{s+1})-F^\star\bigr]
\le \rho\,\mathbb{E}\bigl[F(\tilde w_s)-F^\star\bigr]\]

  &lt;p&gt;with \(\rho&amp;lt;1\) independent of the horizon. The number of incremental gradients to \(\varepsilon\)-accuracy is \(O\bigl((n+\kappa)\log(1/\varepsilon)\bigr)\), \(\kappa=L/\mu\). Vanilla SGD cannot write a \(\log(1/\varepsilon)\) of this kind while the noise floor is constant.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The proof is a Lyapunov argument: the inner-loop noise is controlled by \(\|w-\tilde w\|\), which itself shrinks as the snapshot improves. You are not asked to reproduce the constants; you are asked to point at the line \(g=\nabla f_I(w)-\nabla f_I(\tilde w)+\mu\) and say why the variance dies.&lt;/p&gt;

&lt;h2 id=&quot;saga-defazio-bach-lacoste-julien-2014&quot;&gt;SAGA (Defazio, Bach, Lacoste-Julien, 2014)&lt;/h2&gt;

&lt;p&gt;SAGA removes the outer loop by storing a &lt;strong&gt;table&lt;/strong&gt; \(g^{(1)},\ldots,g^{(n)}\) of the last gradient seen for each \(f_i\). Initialise \(g^{(i)}\leftarrow\nabla f_i(w_0)\) (or zeros, with a short burn-in) and keep a running average \(\bar g=\frac1n\sum_i g^{(i)}\).&lt;/p&gt;

&lt;p&gt;At each step: draw \(I\), compute the fresh gradient \(\nabla f_I(w)\), set&lt;/p&gt;

\[g\leftarrow \nabla f_I(w)-g^{(I)}+\bar g,\]

&lt;p&gt;then write \(g^{(I)}\leftarrow\nabla f_I(w)\), update \(\bar g\) in \(O(d)\) by the rank-one change, and step \(w\leftarrow w-\eta g\).&lt;/p&gt;

&lt;p&gt;The same control-variate algebra applies, now with a &lt;em&gt;stale per-example&lt;/em&gt; snapshot instead of a common \(\tilde w\). There is no periodic full pass. The price is memory: \(n\) gradient vectors, \(O(nd)\), or \(O(n)\) scalars for linear models where \(\nabla f_i(w)=(x_i^\top w-y_i)x_i\) and it is enough to store the residual. That is why &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sklearn.linear_model.LogisticRegression(solver=&quot;saga&quot;)&lt;/code&gt; is a production default on medium convex ERM, and why SAGA is hopeless as a &lt;em&gt;deep-net&lt;/em&gt; optimizer — you will not store a gradient table for ImageNet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SAG&lt;/strong&gt; (Schmidt, Le Roux, Bach) is the biased older sibling: it uses the table average &lt;em&gt;without&lt;/em&gt; the \(+\nabla f_I(w)-g^{(I)}\) correction. SAGA’s extra correction restores unbiasedness and simplifies the proof; prefer SAGA unless you are reading the 2013 SAG paper.&lt;/p&gt;

&lt;h2 id=&quot;a-tiny-svrg-loop&quot;&gt;A tiny SVRG loop&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;clip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;40.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;40.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;svrg_logistic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inner&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;epochs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;inner&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inner&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inner&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;epochs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;# full gradient
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;w_snap&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_t&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;yi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;yi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;g_snap&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_snap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;yi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_snap&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g_snap&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Compare wall-clock — not epochs — against the minibatch SGD of 26-01 on a strongly convex ridge-logistic problem with \(n=5000\), target \(\|\nabla F(w)\|_2\le 10^{-4}\). Then spend the same budget on a one-hidden-layer net: the snapshot cost stays \(n\) backward passes, the table-of-gradients fantasy of SAGA becomes impossible, and AdamW from 26-04 will look like the grown-up choice.&lt;/p&gt;

&lt;h2 id=&quot;what-to-use-when&quot;&gt;What to use when&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Extra memory&lt;/th&gt;
      &lt;th&gt;Cost per step (amortized)&lt;/th&gt;
      &lt;th&gt;Typical home&lt;/th&gt;
      &lt;th&gt;Linear rate on SC finite-sum?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;SGD / mini-batch&lt;/td&gt;
      &lt;td&gt;none&lt;/td&gt;
      &lt;td&gt;\(1\) (or \(B\)) gradients&lt;/td&gt;
      &lt;td&gt;deep learning&lt;/td&gt;
      &lt;td&gt;no (noise floor)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SVRG&lt;/td&gt;
      &lt;td&gt;one snapshot + \(\mu\)&lt;/td&gt;
      &lt;td&gt;\(\approx 3\) gradients&lt;/td&gt;
      &lt;td&gt;convex finite-sum, research code&lt;/td&gt;
      &lt;td&gt;yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SAGA&lt;/td&gt;
      &lt;td&gt;one gradient per example&lt;/td&gt;
      &lt;td&gt;\(1\) gradient&lt;/td&gt;
      &lt;td&gt;medium convex ERM (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;solver=&quot;saga&quot;&lt;/code&gt;)&lt;/td&gt;
      &lt;td&gt;yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;AdamW&lt;/td&gt;
      &lt;td&gt;two EMAs&lt;/td&gt;
      &lt;td&gt;\(1\) minibatch&lt;/td&gt;
      &lt;td&gt;default DL&lt;/td&gt;
      &lt;td&gt;not the point&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Learn SVRG so that you can read Opt-for-ML notes (MIT 6.7220, BU EC525) and so that you recognize when a &lt;em&gt;convex&lt;/em&gt; ERM — logistic regression, linear SVM, a Lasso smoother — should &lt;em&gt;not&lt;/em&gt; be trained with Adam out of habit. Mini-batch Adam still wins on deep nets because (i) storing or refreshing full gradients is the wrong complexity class, (ii) the landscape is not strongly convex, and (iii) the hardware wants large, regular kernels, not a random \(I\) with a snapshot subtract.&lt;/p&gt;

&lt;p&gt;A last neighbouring idea, not assessed: &lt;strong&gt;SARAH&lt;/strong&gt; / &lt;strong&gt;SPIDER&lt;/strong&gt; replace the control variate by a recursive estimator that can be tighter in theory; &lt;strong&gt;FedAvg&lt;/strong&gt; in Chapter 29 is &lt;em&gt;not&lt;/em&gt; variance reduction in this sense (it averages models, not control variates), though SCAFFOLD’s control variates are the federated cousin of SVRG.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Prove unbiasedness of the SVRG estimator in one line, then exhibit a two-example quadratic where vanilla SGD’s variance at \(w^\star\) is positive while SVRG’s variance at the snapshot is zero.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; On ridge-logistic with \(n=5000\), plot training gradient norm versus &lt;em&gt;number of \(f_i\) gradients&lt;/em&gt; for SGD, SVRG, and (if memory allows) SAGA. Mark the SVRG snapshot passes. Then plot the same curves versus wall-clock. Which \(x\)-axis changes the winner?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; The control variate \(g\) is unbiased for every \(w\), not only at \(\tilde w\). Why, then, must we still refresh the snapshot — what happens to \(\mathrm{Var}(g)\) if we freeze \(\tilde w\) and let \(w\) walk far away?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26-04 AdamW and training practice</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_04_adamw_and_practice/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_04_adamw_and_practice</id>
   <content type="html">&lt;p&gt;For three years after Adam’s publication, practitioners noticed a puzzling empirical mystery: Adam trained faster than SGD+momentum on computer vision benchmarks, yet generalized noticeably worse—even with carefully tuned \(\ell_2\) regularization. In 2017–2019, Ilya Loshchilov and Frank Hutter uncovered the culprit: inside Adam, \(\ell_2\) regularization and weight decay are &lt;strong&gt;not&lt;/strong&gt; equivalent! Adding \(\lambda w\) inside the gradient gets divided by \(\sqrt{\hat{v}_t}\), accidentally weakening regularization on weights with large historical gradients. Pulling weight decay &lt;em&gt;outside&lt;/em&gt; the adaptive denominator gave birth to &lt;strong&gt;AdamW&lt;/strong&gt;, the default optimizer of modern transformers.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-decoupled-weight-decay-and-optimization-practice-knobs&quot;&gt;Key ideas: Decoupled Weight Decay and Optimization Practice Knobs&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Why \(\ell_2\) Regularization \(\ne\) Weight Decay Under Adam:&lt;/strong&gt; In vanilla SGD, adding \(\frac{\lambda}{2}\|w\|_2^2\) yields \(w_{t+1} = (1 - \eta \lambda) w_t - \eta g_t\)—identical to multiplicative weight decay. In Adam, adding \(\lambda w_t\) to \(g_t\) scales the decay by \(1 / (\sqrt{\hat{v}_t} + \varepsilon)\), coupling regularization strength to gradient variance.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;AdamW (Decoupled Weight Decay):&lt;/strong&gt; Updates \(w_{t+1} = (1 - \eta_t \lambda) w_t - \eta_t \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \varepsilon}\), restoring uniform multiplicative decay across all weights regardless of their gradient history (and typically excluding biases and LayerNorm gains).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warmup + Cosine Annealing:&lt;/strong&gt; Early in deep training, Adam’s second-moment estimate \(\hat{v}_t\) has high variance and curvature is sharp; linear learning-rate warmup prevents early divergence, while cosine decay smoothly shrinks the stochastic noise ball at the end of training.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Clipping &amp;amp; Mixed Precision:&lt;/strong&gt; Global norm clipping (\(\text{clip}(\|g\|_2 \le c)\)) caps rare outlier-batch spikes in nonconvex landscapes without changing step direction, making deep transformer runs stable under FP16/BF16 arithmetic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-adaml2-vs-adamw-on-two-weights-with-different-gradient-scales&quot;&gt;Worked example: Adam+L2 vs. AdamW on Two Weights with Different Gradient Scales&lt;/h3&gt;

&lt;p&gt;Suppose two weights both sit at \(w_1 = w_2 = 1.0\), with weight decay \(\lambda = 0.1\), learning rate \(\eta = 0.1\), and steady historical gradients \(g_1 = 0.01\) (small-gradient coordinate) and \(g_2 = 10.0\) (large-gradient coordinate), so \(\sqrt{\hat{v}_1} \approx 0.01\) and \(\sqrt{\hat{v}_2} \approx 10.0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Under Adam with coupled \(\ell_2\) regularization (\(\tilde{g}_i = g_i + \lambda w_i\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Regularization shrinkage on \(w_1\): \(\eta \frac{\lambda w_1}{\sqrt{\hat{v}_1}} = 0.1 \cdot \frac{0.1}{0.01} = 1.0\) (crushes \(w_1\) by &lt;strong&gt;100%&lt;/strong&gt; in one step!).&lt;/li&gt;
      &lt;li&gt;Regularization shrinkage on \(w_2\): \(\eta \frac{\lambda w_2}{\sqrt{\hat{v}_2}} = 0.1 \cdot \frac{0.1}{10.0} = 0.001\) (shrinks \(w_2\) by just &lt;strong&gt;0.1%&lt;/strong&gt;!).
The two weights receive &lt;strong&gt;1000× different&lt;/strong&gt; effective decay rates!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Under AdamW (decoupled weight decay):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Regularization shrinkage on \(w_1\): \(\eta \lambda w_1 = (0.1)(0.1)(1.0) = 0.01\) (&lt;strong&gt;1%&lt;/strong&gt; decay).&lt;/li&gt;
      &lt;li&gt;Regularization shrinkage on \(w_2\): \(\eta \lambda w_2 = (0.1)(0.1)(1.0) = 0.01\) (&lt;strong&gt;1%&lt;/strong&gt; decay).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; AdamW applies the exact intended \(1\%\) multiplicative shrinkage uniformly across both coordinates, cleanly separating scale-invariant gradient steps from weight regularization.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;L2 regularization adds \(\frac{\lambda}{2}\|w\|_2^2\) to the loss, so the gradient gains \(\lambda w\). Under &lt;strong&gt;Adam&lt;/strong&gt;, that term is immediately rescaled by \(1/(\sqrt{\hat v}+\varepsilon)\). Coordinates with large second moments feel &lt;em&gt;less&lt;/em&gt; decay than coordinates with small ones. The regularizer you thought you wrote is not the regularizer the optimizer applies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AdamW&lt;/strong&gt; (Loshchilov &amp;amp; Hutter, ICLR 2019, &lt;a href=&quot;https://arxiv.org/abs/1711.05101&quot;&gt;arXiv:1711.05101&lt;/a&gt;) &lt;strong&gt;decouples&lt;/strong&gt; the decay:&lt;/p&gt;

\[w_{k+1} = w_k - \eta \Bigl( \hat m \oslash (\sqrt{\hat v}+\varepsilon) + \lambda w_k \Bigr).\]

&lt;p&gt;Weight decay is now a true pull toward the origin in parameter space, independent of the adaptive scale. In PyTorch this is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.optim.AdamW&lt;/code&gt;, not “Adam plus &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;weight_decay&lt;/code&gt; on the old Adam” (the latter still couples on some versions — read the docs for the year you are coding).&lt;/p&gt;

&lt;h2 id=&quot;practice-knobs-that-are-really-optimization&quot;&gt;Practice knobs that are really optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Learning-rate schedules.&lt;/strong&gt; Warmup then cosine / linear decay is a time-varying \(\eta_k\). Theory for convex SGD already wants decreasing steps; deep learning rediscovered it as “training recipes.”&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient clipping.&lt;/strong&gt; Replacing \(g\) by \(g\cdot \min(1, \tau/\|g\|)\) is a trust-region on the stochastic step — crude, and essential for RNNs and transformers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Batch size vs \(\eta\)&lt;/strong&gt;. Linear scaling rules (Goyal et al.) treat a larger batch as a smaller-noise estimator that can bear a larger \(\eta\), up to a breakdown regime.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coupled vs decoupled decay.&lt;/strong&gt; If you report a “weight decay \(\lambda\)” in a paper, say whether it was AdamW-style.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Further reading (not core): SAM (Foret et al., ICLR 2021) asks for &lt;em&gt;flat&lt;/em&gt; minima via a local max; Muon and Sophia are 2023–2025 optimizer-zoo case studies. The optional seminar &lt;a href=&quot;/contents/en/chapter26/26_06_modern_optimizers/&quot;&gt;26-06&lt;/a&gt; writes each update on the board (without repeating the Sophia-as-Newton reading in 14-10); they are not assessed this term.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Train a tiny MLP on a 2-D two-moons set with Adam and AdamW at the same \(\lambda\). Plot \(\|w\|_2\) over epochs. You should see different parameter-norm trajectories even when training loss looks similar.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26-03 AdaGrad, RMSProp intuition, and Adam</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_03_adagrad_to_adam/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_03_adagrad_to_adam</id>
   <content type="html">&lt;p&gt;In a neural language model, the embedding vector for the word “the” receives a gradient on almost every sentence, while the embedding for “eigenvector” fires once every thousand batches. Handing both parameters the same scalar learning rate \(\eta\) forces an impossible compromise: either “the” explodes or “eigenvector” never learns. Adaptive methods—starting with AdaGrad (2011), refined by RMSProp (2012), and unified with momentum in Adam (2015)—solve this by maintaining a per-coordinate running meter of gradient energy and normalizing every step automatically.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-adagrad-to-rmsprop-and-adam&quot;&gt;Key ideas: From AdaGrad to RMSProp and Adam&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;AdaGrad (Cumulative Squared Gradients):&lt;/strong&gt; Tracks \(G_t = \sum_{\tau=1}^t g_\tau \odot g_\tau\) and scales coordinate \(j\) by \(\frac{\eta}{\sqrt{G_{t,j} + \varepsilon}}\). Brilliant for sparse convex features, but because \(G_t\) grows monotonically forever, the effective step size eventually vanishes to zero in deep nonconvex training.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;RMSProp (Exponential Moving Average):&lt;/strong&gt; Replaces the infinite sum \(G_t\) with an exponential moving average \(v_t = \beta_2 v_{t-1} + (1 - \beta_2) g_t^2\), letting the preconditioner forget ancient curvature and adapt smoothly across non-stationary loss landscapes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adam (First + Second Moments):&lt;/strong&gt; Combines exponential momentum \(m_t = \beta_1 m_{t-1} + (1 - \beta_1) g_t\) with RMSProp’s second-moment accumulator \(v_t = \beta_2 v_{t-1} + (1 - \beta_2) g_t^2\), producing an approximately scale-invariant step \(-\eta \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \varepsilon}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Zero-Initialization Bias Correction:&lt;/strong&gt; Because \(m_0 = 0\) and \(v_0 = 0\) bias early estimates heavily toward zero (especially when \(\beta_2 = 0.999\)), dividing by \((1 - \beta_1^t)\) and \((1 - \beta_2^t)\) makes \(\hat{m}_t\) and \(\hat{v}_t\) exact unbiased moment estimators at early steps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-hand-tracing-two-steps-of-adam-on-two-disproportionate-coordinates&quot;&gt;Worked example: Hand-Tracing Two Steps of Adam on Two Disproportionate Coordinates&lt;/h3&gt;

&lt;p&gt;Suppose a 2D parameter \(w_0 = (0, 0)^\top\) sees a tiny gradient on coordinate 1 and a huge gradient on coordinate 2: \(g_1 = (0.1,\ 10)^\top\) and \(g_2 = (0.1,\ 10)^\top\). Use \(\eta = 0.1\), \(\beta_1 = 0.9\), \(\beta_2 = 0.99\), \(\varepsilon = 0\) (for clean hand arithmetic).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Step \(t = 1\) (\(g_1 = (0.1,\ 10)\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(m_1 = (1 - 0.9)(0.1, 10) = (0.01,\ 1.0)\), bias-corrected \(\hat{m}_1 = \frac{m_1}{1 - 0.9} = (0.1,\ 10)\).&lt;/li&gt;
      &lt;li&gt;\(v_1 = (1 - 0.99)(0.01, 100) = (0.0001,\ 1.0)\), bias-corrected \(\hat{v}_1 = \frac{v_1}{1 - 0.99} = (0.01,\ 100)\).&lt;/li&gt;
      &lt;li&gt;Normalized step: \(\frac{\hat{m}_1}{\sqrt{\hat{v}_1}} = \left(\frac{0.1}{0.1},\ \frac{10}{10}\right) = (1,\ 1)\)!&lt;/li&gt;
      &lt;li&gt;Update: \(w_1 = (0, 0) - 0.1(1, 1) = (-0.1,\ -0.1)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Observe what just happened:&lt;/strong&gt; Even though coordinate 2’s gradient was &lt;strong&gt;100× larger&lt;/strong&gt; than coordinate 1’s, Adam moved &lt;em&gt;both&lt;/em&gt; coordinates by the exact same step size \(-0.1\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Without bias correction at \(t = 1\):&lt;/strong&gt; Notice \(\frac{m_1}{\sqrt{v_1}} = \left(\frac{0.01}{0.01},\ \frac{1.0}{1.0}\right) = (1, 1)\) only accidentally matched because \(1 - \beta_1 = 0.1 = \sqrt{1 - \beta_2}\); if \(\beta_2 = 0.999\) (the default!), \(\frac{m_1}{\sqrt{v_1}} = \frac{0.1}{\sqrt{0.001}} \approx 3.16\times\) too large—proving why bias correction is vital at \(t = 1\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Not every coordinate of \(w\) should share one scalar \(\eta\). Features that fire rarely (think one-hot tokens) need larger effective steps; coordinates with huge gradients would explode if given the same \(\eta\). &lt;strong&gt;Diagonal adaptive methods&lt;/strong&gt; keep a running second-moment estimate and divide.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AdaGrad&lt;/strong&gt; (Duchi, Hazan, Singer, 2011) accumulates squared gradients&lt;/p&gt;

\[G_{k+1} = G_k + g_k \odot g_k, \qquad w_{k+1} = w_k - \eta\, g_k \oslash \bigl(\sqrt{G_{k+1}}+\varepsilon\bigr),\]

&lt;p&gt;where \(g_k=\nabla f_{I_k}(w_k)\) and \(\odot,\oslash\) are elementwise. The accumulator never forgets, so the effective step &lt;strong&gt;shrinks monotonically&lt;/strong&gt;. That is ideal for sparse convex problems and awkward for long deep-learning runs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RMSProp&lt;/strong&gt; (Hinton, lecture note) replaces the sum by an exponential moving average \(v_{k+1}=\gamma v_k + (1-\gamma)\,g_k\odot g_k\). The scale can breathe again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adam&lt;/strong&gt; (Kingma &amp;amp; Ba, 2015) pairs that second-moment EMA with a momentum-like first moment, plus bias correction because both EMAs start at zero:&lt;/p&gt;

\[\begin{align}
m_{k+1} &amp;amp;= \beta_1 m_k + (1-\beta_1) g_k, \\
v_{k+1} &amp;amp;= \beta_2 v_k + (1-\beta_2)\, g_k\odot g_k, \\
\hat m &amp;amp;= m_{k+1}/(1-\beta_1^{k+1}), \quad
\hat v = v_{k+1}/(1-\beta_2^{k+1}), \\
w_{k+1} &amp;amp;= w_k - \eta\, \hat m \oslash (\sqrt{\hat v}+\varepsilon).
\end{align}\]

&lt;p&gt;Default knobs \(\beta_1=0.9\), \(\beta_2=0.999\), \(\varepsilon=10^{-8}\) are a surprisingly robust starting point — not laws of nature. Adam is a &lt;strong&gt;diagonal preconditioner&lt;/strong&gt; plus momentum, not a second-order method: it never forms a Hessian.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;adam_step&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.999&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;vhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Read the paper as &lt;a href=&quot;https://arxiv.org/abs/1412.6980&quot;&gt;arXiv:1412.6980&lt;/a&gt;. Next lesson: why adding \((\lambda/2)\|w\|_2^2\) to the loss is &lt;strong&gt;not&lt;/strong&gt; the same as AdamW weight decay.&lt;/p&gt;

&lt;h3 id=&quot;adagrad--rmsprop--adam-in-about-3-minutes&quot;&gt;AdaGrad → RMSProp → Adam in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/adagrad-rmsprop-adam_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Three adaptive steps on the same skewed quadratic: AdaGrad slows down, RMSProp jitters around the solution, Adam with bias correction.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26-02 Momentum and Nesterov acceleration</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_02_momentum_and_nesterov/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_02_momentum_and_nesterov</id>
   <content type="html">&lt;p&gt;Drop a marble down a steep, narrow canyon whose floor slopes gently toward the sea: vanilla gradient descent behaves like a memoryless hiker who bounces violently from wall to wall while creeping painfully slowly down the valley. Give that marble &lt;strong&gt;momentum&lt;/strong&gt;—a velocity vector that remembers past gradients—and the alternating cross-canyon forces cancel out while the steady downhill slope compounds. Boris Polyak’s Heavy Ball (1964) and Yurii Nesterov’s lookahead acceleration (1983) turn this physical intuition into an exact quadratic speedup over condition number \(\kappa\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-conditioning-heavy-ball-and-nesterov-lookahead&quot;&gt;Key ideas: Conditioning, Heavy Ball, and Nesterov Lookahead&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Condition Number \(\kappa = L/\mu\) and Zig-Zagging:&lt;/strong&gt; On an \(L\)-smooth, \(\mu\)-strongly convex quadratic, GD needs \(\eta \le 2/L\) for stability along the steepest axis, restricting progress along the flattest axis to rate \(1 - O(1/\kappa)\)—requiring \(O(\kappa \log(1/\varepsilon))\) steps.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polyak Heavy Ball as a Low-Pass Filter:&lt;/strong&gt; Updating \(v_{k+1} = \beta v_k + \nabla f(w_k)\), \(w_{k+1} = w_k - \eta v_{k+1}\) cancels oscillating gradient components (high frequency) while amplifying consistent directions by up to \(\frac{1}{1 - \beta}\), cutting quadratic complexity to \(O(\sqrt{\kappa}\log(1/\varepsilon))\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov Lookahead (NAG):&lt;/strong&gt; Instead of evaluating the gradient at \(w_k\), NAG evaluates \(\nabla f(w_k - \eta \beta v_k)\) at the &lt;em&gt;predicted&lt;/em&gt; next position. That lookahead acts as an automatic brake whenever velocity overshoots a valley wall—achieving the provable optimal \(O(1/k^2)\) convex rate and \(O(\sqrt{\kappa}\log(1/\varepsilon))\) strongly convex rate.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic Momentum Caveat:&lt;/strong&gt; With noisy minibatch gradients, large \(\beta\) (e.g., \(0.9\)) smooths noise and accelerates early progress, but does not reduce the asymptotic \(O(\sigma/\sqrt{T})\) variance rate without step-size decay.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-watching-momentum-cancel-oscillations-on-an-ill-conditioned-quadratic&quot;&gt;Worked example: Watching Momentum Cancel Oscillations on an Ill-Conditioned Quadratic&lt;/h3&gt;

&lt;p&gt;Consider the narrow canyon \(f(x, y) = \frac{1}{2}(x^2 + 9 y^2)\) (so \(\mu = 1\), \(L = 9\), \(\kappa = 9\), optimum \((0, 0)\)). Start at \((x_0, y_0) = (9, 1)\) with velocity \(v_0 = (0, 0)\). Take \(\eta = 0.2\) (note \(\eta = 0.2 &amp;lt; 2/9 \approx 0.222\) is stable for GD) and compare vanilla GD vs. Heavy Ball (\(\beta = 0.5\)) for 2 steps.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vanilla GD (\(\eta = 0.2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Step 1: \(\nabla f(9, 1) = (9, 9) \implies (x_1, y_1) = (9 - 1.8,\ 1 - 1.8) = (7.2,\ -0.8)\). Notice \(y\) flipped sign!&lt;/li&gt;
      &lt;li&gt;Step 2: \(\nabla f(7.2, -0.8) = (7.2, -7.2) \implies (x_2, y_2) = (7.2 - 1.44,\ -0.8 + 1.44) = (5.76,\ +0.64)\).
Along the flat \(x\)-axis, GD only moved \(9 \to 5.76\) while \(y\) oscillated \(1 \to -0.8 \to +0.64\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Heavy Ball Momentum (\(\eta = 0.2,\ \beta = 0.5\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Step 1: \(v_1 = 0.5(0, 0) + (9, 9) = (9, 9) \implies (x_1, y_1) = (7.2,\ -0.8)\).&lt;/li&gt;
      &lt;li&gt;Step 2: \(\nabla f(7.2, -0.8) = (7.2, -7.2)\), so velocity becomes
\(v_2 = 0.5(9, 9) + (7.2, -7.2) = (11.7,\ -2.7).\)
Notice how the \(y\)-velocity shrank from \(-7.2\) to \(-2.7\) (oscillation damped!) while the \(x\)-velocity grew from \(7.2\) to \(11.7\) (downhill progress boosted!).&lt;/li&gt;
      &lt;li&gt;Update: \((x_2, y_2) = (7.2, -0.8) - 0.2(11.7, -2.7) = (4.86,\ -0.26)\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Compare after just 2 steps:&lt;/strong&gt; Heavy Ball cut \(x\) to \(4.86\) (vs. \(5.76\)) AND cut $$&lt;/td&gt;
          &lt;td&gt;y&lt;/td&gt;
          &lt;td&gt;\(to\)0.26\((vs.\)0.64$$)—improving &lt;em&gt;both&lt;/em&gt; axes simultaneously.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Gradient descent on a badly conditioned quadratic zig-zags: the step that is safe for the sharp eigenvalue is painfully small along the flat one. &lt;strong&gt;Momentum&lt;/strong&gt; keeps a velocity that accumulates consistent gradient components and cancels oscillating ones. This lesson is the Distill-style &lt;em&gt;why&lt;/em&gt;, not a second copy of the FISTA algebra in &lt;a href=&quot;/contents/en/chapter09/09_05_01_accelerated_proximal_gradient_method/&quot;&gt;09-05-01&lt;/a&gt; or the in-page animation in &lt;a href=&quot;/contents/en/chapter06/06_06_gradent_descent_with_momentum/&quot;&gt;06-06&lt;/a&gt;. Read Goh, &lt;em&gt;&lt;a href=&quot;https://distill.pub/2017/momentum/&quot;&gt;Why Momentum Really Works&lt;/a&gt;&lt;/em&gt; (Distill, 2017), with the quadratic valley open in another tab; the notes below are the course’s spoken version of that picture.&lt;/p&gt;

&lt;h2 id=&quot;the-valley-that-vanilla-gd-cannot-walk&quot;&gt;The valley that vanilla GD cannot walk&lt;/h2&gt;

&lt;p&gt;Take the model problem that every first-order method is secretly solving,&lt;/p&gt;

\[F(w)=\tfrac12 w^\top A w,\qquad A=\operatorname{diag}(\lambda_1,\ldots,\lambda_d)\succ 0.\]

&lt;p&gt;The gradient is \(Aw\). Gradient descent with step \(\eta\) is the linear recurrence \(w_{k+1}=(I-\eta A)w_k\), so each eigen-coordinate evolves independently as \((1-\eta\lambda_i)^k\). Stability on the sharpest axis forces \(\eta&amp;lt;2/\lambda_{\max}\). The flattest axis then contracts only by \(1-\eta\lambda_{\min}\approx 1-2/\kappa\), where \(\kappa=\lambda_{\max}/\lambda_{\min}\) is the condition number. That is the zig-zag: you bounce off the walls of a long corridor and crawl down the hallway. Chapter 06 already proved the same \(1-m/L\) factor under strong convexity; here we &lt;em&gt;see&lt;/em&gt; it as two time-scales on a quadratic.&lt;/p&gt;

&lt;p&gt;Open &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/gradient_descent_demo.html&quot;&gt;gradient_descent_demo.html&lt;/a&gt; and stretch one axis. The path that looks “wrong” is the optimal first-order method &lt;em&gt;without memory&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;heavy-ball-a-low-pass-filter-on-the-gradient&quot;&gt;Heavy ball: a low-pass filter on the gradient&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Polyak’s heavy ball&lt;/strong&gt; (1964) introduces a velocity&lt;/p&gt;

\[\begin{align}
v_{k+1} &amp;amp;= \beta v_k + \nabla F(w_k), \\
w_{k+1} &amp;amp;= w_k - \eta v_{k+1},
\end{align}\]

&lt;p&gt;with \(\beta\in[0,1)\). PyTorch’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SGD(momentum=…)&lt;/code&gt; is this family, up to whether the gradient is scaled before or after mixing (the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(1-β)&lt;/code&gt; convention of 06-06 is an exponentially weighted moving average of the same object). Unrolling gives&lt;/p&gt;

\[v_{k+1}=\sum_{j=0}^{k}\beta^{k-j}\nabla F(w_j),\]

&lt;p&gt;so a direction that &lt;em&gt;keeps the same sign&lt;/em&gt; is amplified and a direction that &lt;em&gt;flips every step&lt;/em&gt; is cancelled. That is exactly a discrete low-pass filter. In the corridor, the wall-normal component oscillates and dies; the hallway component is consistent and becomes a cruise speed.&lt;/p&gt;

&lt;p&gt;On the same quadratic the closed recurrence is second-order,&lt;/p&gt;

\[w_{k+1}=(1+\beta)(I-\eta A)w_k-\beta w_{k-1}\]

&lt;p&gt;(up to the usual affine rewrite). Each eigenmode has a characteristic polynomial \(r^2-(1+\beta)(1-\eta\lambda)r+\beta=0\). Goh’s optimal tuning for a known \(\kappa\) is the pair that places both roots on a circle of radius \((\sqrt{\kappa}-1)/(\sqrt{\kappa}+1)\):&lt;/p&gt;

\[\eta^\star=\Bigl(\frac{2}{\sqrt{\lambda_{\max}}+\sqrt{\lambda_{\min}}}\Bigr)^2,\qquad
\beta^\star=\Bigl(\frac{\sqrt{\kappa}-1}{\sqrt{\kappa}+1}\Bigr)^2.\]

&lt;p&gt;The contraction improves from \(1-\Theta(1/\kappa)\) to \(1-\Theta(1/\sqrt{\kappa})\) — the same square-root-of-condition-number miracle that Nesterov’s &lt;em&gt;optimal&lt;/em&gt; convex rate will claim in the next section. You do not need to memorize the two displayed constants; you do need the slogan: &lt;strong&gt;momentum is a change of the discrete-time damping, not a new gradient&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A useful physics picture, already hinted in 06-06, is the heavy-ball ODE \(m\ddot w+\gamma\dot w+\nabla F(w)=0\). Too little friction and you orbit; too much and you crawl. The hyperparameter \(\beta\) is that friction in discrete time. Deep-learning practice (\(\beta=0.9\), sometimes \(0.99\)) is a robust default, not Goh’s optimal \(\beta^\star\) — we almost never know \(\kappa\) of a ResNet.&lt;/p&gt;

&lt;h2 id=&quot;nesterov-evaluate-the-gradient-where-you-are-about-to-be&quot;&gt;Nesterov: evaluate the gradient where you are about to be&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Nesterov acceleration&lt;/strong&gt; keeps the same velocity but evaluates the gradient at a &lt;em&gt;look-ahead&lt;/em&gt; point&lt;/p&gt;

\[\begin{align}
v_{k+1} &amp;amp;= \beta v_k + \nabla F(w_k-\eta\beta v_k), \\
w_{k+1} &amp;amp;= w_k-\eta v_{k+1}.
\end{align}\]

&lt;p&gt;Heavy ball adds the gradient at the &lt;em&gt;current&lt;/em&gt; point to a velocity that already points down the corridor; if that velocity is about to overshoot, you only find out after you have left. Look-ahead asks the slope &lt;em&gt;one step ahead along the current velocity&lt;/em&gt;, so the correction starts a beat earlier. Distill’s vector diagram is the right slide: two arrows (old velocity, new gradient) versus two arrows (old velocity, gradient at the extrapolated point). The second pair turns sooner at the bottom of the bowl.&lt;/p&gt;

&lt;p&gt;On &lt;em&gt;smooth convex&lt;/em&gt; problems, a carefully scheduled \(\beta_k\) (classically \(\beta_k=(t_k-1)/t_{k+1}\) with \(t_{k+1}=(1+\sqrt{1+4t_k^2})/2\), or the FISTA weight \((k-2)/(k+1)\) of &lt;a href=&quot;/contents/en/chapter09/09_05_01_accelerated_proximal_gradient_method/&quot;&gt;09-05-01&lt;/a&gt;) yields the optimal first-order rate&lt;/p&gt;

\[F(w_T)-F^\star=O\bigl(L\|w_0-w^\star\|_2^2/T^2\bigr).\]

&lt;p&gt;That is a theorem about a &lt;em&gt;convex&lt;/em&gt; \(F\) and a &lt;em&gt;time-varying&lt;/em&gt; momentum. Deep-learning “Nesterov” (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.optim.SGD(..., nesterov=True)&lt;/code&gt;) is usually a &lt;em&gt;constant&lt;/em&gt; \(\beta\) look-ahead on a nonconvex loss. Use the proof to understand &lt;em&gt;why&lt;/em&gt; look-ahead damps; do not quote \(O(1/T^2)\) for CIFAR accuracy.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Theory ≠ practice reminder.&lt;/strong&gt; Nesterov’s $$O(1/T^2)$$ needs a scheduled $$\beta_k$$ and a convex smooth $$F$$. Heavy ball’s $$\sqrt{\kappa}$$ tuning needs a quadratic (or a locally quadratic bowl). What transfers to AdamW training is the filter intuition: consistent directions get a longer memory; oscillating directions get cancelled; look-ahead spends that memory a little more carefully.
&lt;/div&gt;

&lt;h2 id=&quot;what-to-implement-and-what-to-watch&quot;&gt;What to implement, and what to watch&lt;/h2&gt;

&lt;p&gt;The two methods differ by a single gradient argument. On the classroom quadratic \(F(w)=\tfrac12 w^\top\operatorname{diag}(1,100)\,w\) they already look different:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;diag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;100.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;heavy_ball&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nesterov&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;look&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;look&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Start both from the same \(w_0\), sweep \(\beta\in\{0,0.5,0.8,0.9,0.99\}\) at a step that is stable for vanilla GD, and plot the two trajectories. The first \(\beta\) that kills the visible zig-zag is the Distill lesson in one figure; the \(\beta\) that then &lt;em&gt;overshoots&lt;/em&gt; the origin is the “too little friction” picture.&lt;/p&gt;

&lt;p&gt;Chapter 09’s FISTA is the &lt;em&gt;proximal&lt;/em&gt; sibling of the same look-ahead (composite \(g+h\), scheduled weight). Chapter 26’s Adam will later put an exponential moving average on the gradient &lt;em&gt;and&lt;/em&gt; on its coordinate-wise square — momentum is the first of those two averages. Variance reduction (&lt;a href=&quot;/contents/en/chapter26/26_05_variance_reduction/&quot;&gt;26-05&lt;/a&gt;) is a different cure for a different disease: it kills &lt;em&gt;sampling&lt;/em&gt; noise, not &lt;em&gt;conditioning&lt;/em&gt; zig-zags.&lt;/p&gt;

&lt;h3 id=&quot;momentum-and-nesterov-in-about-4-minutes&quot;&gt;Momentum and Nesterov in about 4 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/momentum-nesterov_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Heavy ball and Nesterov on the valley ½(w₁² + 100w₂²): step counts, a β sweep, and a case where Nesterov diverges because η is too large.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Implement the three updates above on \(A=\operatorname{diag}(1,100)\) (\(\kappa=100\)), starting from \(w_0=(1,1)\), \(v_0=0\). Count the iterations until \(\Vert w\Vert_2\le 10^{-4}\) for: (a) GD with \(\eta=2/(\lambda_{\min}+\lambda_{\max})\), the optimal GD step; (b) heavy ball with Goh’s pair \((\eta^\star,\beta^\star)\); (c) Nesterov with \(\eta=1/\lambda_{\max}\) and \(\beta=(\sqrt{\kappa}-1)/(\sqrt{\kappa}+1)\). (For checking: 478, 71 and 112 iterations.) Then run Nesterov with \(\eta^\star\) and explain why it diverges. Hint: \(\eta^\star\lambda_{\max}\approx 3.3&amp;gt;2\). Heavy ball is stable as long as \(\eta\lambda&amp;lt;2(1+\beta)\), but Nesterov applies the gradient step at the look-ahead point, so it needs a step close to \(1/\lambda_{\max}\). Finally, break the tuning: keep \(\eta=1/\lambda_{\max}\) for both momentum methods and set \(\beta=0.99\). Which method oscillates more, and why does look-ahead help? (For checking: heavy ball needs about 1430 iterations, Nesterov about 390.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; On the same quadratic, replace \(A\) by a random SPD matrix with the same eigenvalues (\(A=Q\operatorname{diag}(\lambda)Q^\top\)). Convince yourself that momentum’s benefit is &lt;em&gt;spectral&lt;/em&gt;, not axis-aligned.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; Given that SGD often escapes shallow basins more readily than full-batch GD, should you raise or lower \(\beta\) when you switch from the quadratic valley to a small nonconvex net — and what would Distill’s filter picture predict about a noisy gradient that flips sign every minibatch?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26-01 SGD and minibatches</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_01_sgd_and_minibatch/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_01_sgd_and_minibatch</id>
   <content type="html">&lt;p&gt;At the heart of every deep learning training run sits a deceptively simple statistical trick: instead of averaging the gradient over all \(n\) training points, average it over a random minibatch of \(B\) points. That single substitution changes optimization from a deterministic descent into a biased-free random walk—one that initially rockets downhill far faster than full-batch gradient descent, yet eventually hits a “noise ball” around the minimum unless the learning rate decays.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-variance-step-size-schedules-and-random-reshuffling-in-sgd&quot;&gt;Key ideas: Variance, Step-Size Schedules, and Random Reshuffling in SGD&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Unbiasedness &amp;amp; Variance Scaling:&lt;/strong&gt; For a uniform minibatch \(S_k\) of size \(B\) (with replacement), \(\mathbb{E}[g_k \mid w_k] = \nabla F(w_k)\) and \(\operatorname{Var}(g_k \mid w_k) = \frac{1}{B}\operatorname{Var}(\nabla f_I(w_k)) \le \frac{\sigma^2}{B}\). Doubling \(B\) halves variance but doubles work per step until GPU parallelism saturates.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The \(O(\sigma / \sqrt{T})\) Ceiling:&lt;/strong&gt; Because constant-step SGD bounces inside a neighborhood of radius \(O(\eta \sigma^2)\) around \(w^\star\), decaying step sizes \(\eta_k \propto 1/\sqrt{k}\) (or Polyak–Ruppert averaging) are required to reach \(O(1/\sqrt{T})\) expected suboptimality on convex objectives.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear Scaling Rule &amp;amp; Critical Batch Size:&lt;/strong&gt; Increasing batch size \(B \to k B\) reduces gradient variance by \(k\), allowing a larger learning rate (up to the noise-dominated critical batch size \(B_{\text{crit}}\)), beyond which larger batches waste compute without speeding up convergence.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Random Reshuffling vs. i.i.d. Sampling:&lt;/strong&gt; Shuffling the dataset once per epoch (sampling without replacement) introduces negative correlation between consecutive gradients, empirically converging faster than i.i.d. sampling while avoiding adversarial cyclic ordering.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-minibatch-variance-and-the-sgd-noise-floor&quot;&gt;Worked example: Computing Minibatch Variance and the SGD Noise Floor&lt;/h3&gt;

&lt;p&gt;Consider a 1D finite sum \(F(w) = \frac{1}{2}\bigl(f_1(w) + f_2(w)\bigr)\) where \(f_1(w) = \frac{1}{2}(w - 1)^2\) and \(f_2(w) = \frac{1}{2}(w + 1)^2\). Clearly \(F(w) = \frac{1}{2}(w^2 + 1)\) has unique minimizer \(w^\star = 0\) with \(F&apos;(0) = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the gradient variance right at the optimum \(w^\star = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f_1&apos;(0) = -1\) and \(f_2&apos;(0) = +1\), each sampled with probability \(1/2\).&lt;/li&gt;
      &lt;li&gt;Mean: \(\mathbb{E}[g] = \frac{1}{2}(-1) + \frac{1}{2}(+1) = 0 = F&apos;(0)\) (unbiased!).&lt;/li&gt;
      &lt;li&gt;Variance for batch size \(B = 1\): \(\sigma^2 = \frac{1}{2}(-1)^2 + \frac{1}{2}(+1)^2 = 1\). Notice the noise does &lt;strong&gt;not&lt;/strong&gt; vanish at \(w^\star\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the stationary error of constant-step SGD:&lt;/strong&gt; With \(w_{k+1} = w_k - \eta(w_k \pm 1) = (1 - \eta) w_k \mp \eta\), taking expected squares gives
\(\mathbb{E}[w_{k+1}^2] = (1 - \eta)^2 \mathbb{E}[w_k^2] + \eta^2.\)
At steady state (\(\mathbb{E}[w_{k+1}^2] = \mathbb{E}[w_k^2] = v_\infty\)):
\(v_\infty = \frac{\eta^2}{1 - (1 - \eta)^2} = \frac{\eta}{2 - \eta}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Plug in concrete numbers:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;With constant \(\eta = 0.2\): \(v_\infty = \frac{0.2}{1.8} \approx 0.111\), so SGD permanently hovers at RMS error \(\sqrt{0.111} \approx 0.333\) around \(w^\star = 0\).&lt;/li&gt;
      &lt;li&gt;Halving \(\eta\) to \(0.05\) shrinks the noise floor to \(v_\infty = \frac{0.05}{1.95} \approx 0.0256\) (RMS \(\approx 0.160\))—illustrating concretely why learning-rate decay is essential to settle into the minimum.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Empirical risk is an average. Its gradient is an average too:&lt;/p&gt;

\[\nabla F(w) = \frac{1}{n}\sum_{i=1}^n \nabla f_i(w).\]

&lt;p&gt;&lt;strong&gt;Stochastic gradient descent&lt;/strong&gt; replaces the sum by a single random index \(I_k\) drawn (with or without replacement) from \(\{1,\ldots,n\}\):&lt;/p&gt;

\[w_{k+1} = w_k - \eta_k \nabla f_{I_k}(w_k).\]

&lt;p&gt;If \(I_k\) is uniform and independent of \(w_k\), the update is an &lt;strong&gt;unbiased&lt;/strong&gt; estimator: \(\mathbb{E}[\nabla f_{I_k}(w_k)\mid w_k]=\nabla F(w_k)\). A &lt;strong&gt;minibatch&lt;/strong&gt; of size \(B\) averages \(B\) such terms. Variance drops like \(1/B\) for independent draws; wall-clock per step grows roughly linearly in \(B\) until you saturate a GPU. That is the fundamental trade-off.&lt;/p&gt;

&lt;h2 id=&quot;rates-you-should-be-able-to-quote&quot;&gt;Rates you should be able to quote&lt;/h2&gt;

&lt;p&gt;Under standard Lipschitz / bounded-variance assumptions, SGD on a convex Lipschitz objective with step sizes \(\eta_k \propto 1/\sqrt{k}\) (or a constant step plus averaging) satisfies&lt;/p&gt;

\[\mathbb{E}\bigl[F(\bar w_T)-F^\star\bigr] = O\bigl(\sigma / \sqrt{T}\bigr)\]

&lt;p&gt;in the number of &lt;em&gt;stochastic&lt;/em&gt; steps (Bubeck, &lt;em&gt;Convex Optimization: Algorithms and Complexity&lt;/em&gt;, Ch. 6). Smooth strongly convex problems can reach linear rates if the noise vanishes at the minimizer, but deep nets are not strongly convex. The practical message is: &lt;strong&gt;more steps with noisy gradients often beat fewer exact gradients&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Chapter 06 already compared GD and SGD on small sums. Re-open &lt;a href=&quot;https://nglelinh.github.io/interactive_math/optimization/stochastic_gradient_demo.html&quot;&gt;stochastic_gradient_demo.html&lt;/a&gt; and watch a noisy path still trend downhill.&lt;/p&gt;

&lt;h2 id=&quot;shuffling-vs-iid&quot;&gt;Shuffling vs i.i.d.&lt;/h2&gt;

&lt;p&gt;Theory likes independent samples. Practice uses &lt;strong&gt;random reshuffling&lt;/strong&gt;: permute the \(n\) examples each epoch and walk through the permutation. Without-replacement passes often converge faster empirically; proving it is a 2010s–2020s research topic. For this course: shuffle every epoch, do not silently reuse the same order (that can cycle).&lt;/p&gt;

&lt;h2 id=&quot;a-tiny-logistic-loop&quot;&gt;A tiny logistic loop&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;clip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sgd_logistic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;batch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;epochs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;epochs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;permutation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;batch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;batch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Compare &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;batch=1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;batch=16&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;batch=n&lt;/code&gt; (full gradient) on a synthetic two-class cloud: wall-clock to a fixed training loss, not just epochs.&lt;/p&gt;

&lt;h3 id=&quot;sgd-and-minibatches-in-about-3-minutes&quot;&gt;SGD and minibatches in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/sgd-minibatch_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The m = 3 example: one GD step versus one SGD epoch, constant versus decaying steps, then the effect of the batch size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; Given that SGD often escapes shallow basins more readily than full-batch GD, how should that affect your first choice of batch size on an overparameterized model?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>26 Stochastic and adaptive methods for ML</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_00_stochastic_and_adaptive_methods/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter26/26_00_stochastic_and_adaptive_methods</id>
   <content type="html">&lt;p&gt;Imagine training a modern language model on a trillion tokens using classical full-batch gradient descent: before taking even a &lt;em&gt;single&lt;/em&gt; parameter update, you would have to run a forward and backward pass across the entire internet. Modern machine learning lives in a completely different regime—one where gradients are noisy estimates computed on tiny minibatches, curvature varies by six orders of magnitude across layers, and wall-clock time is bounded by GPU memory bandwidth rather than iteration count. Chapter 26 builds the complete optimization stack of modern ML from first principles: from SGD and momentum, through AdaGrad and AdamW, to variance-reduced finite-sum solvers and 2024–2026 optimizers like SAM, Sophia, and Muon.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-modern-stochastic--adaptive-optimization-stack&quot;&gt;Key ideas: The Modern Stochastic &amp;amp; Adaptive Optimization Stack&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch26_stochastic_adaptive_opt.svg&quot; alt=&quot;Tối ưu hóa Ngẫu nhiên &amp;amp; Thích nghi Quy mô lớn&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Finite-Sum Structure &amp;amp; Minibatch Noise:&lt;/strong&gt; Empirical risk \(F(w) = \frac{1}{n}\sum_{i=1}^n f_i(w)\) turns exact gradients into \(O(n)\) bottlenecks. Minibatching replaces exactness with an unbiased stochastic gradient whose variance scales as \(\sigma^2 / B\), trading asymptotic precision for massive throughput.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inertia &amp;amp; Acceleration (Momentum / Nesterov):&lt;/strong&gt; Exponentially averaging past gradients damps oscillations across high-curvature ravines while amplifying consistent motion along flat valleys, reducing condition-number dependence from \(\kappa\) to \(\sqrt{\kappa}\) on quadratics.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diagonal Adaptive Preconditioning (AdaGrad → AdamW):&lt;/strong&gt; Rescaling each coordinate by the inverse square root of accumulated squared gradients equalizes learning speeds across sparse tokens and dense hidden layers, while decoupling weight decay (AdamW) prevents adaptive rescaling from distorting regularization.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Variance Reduction (SVRG / SAGA) &amp;amp; Second-Order / Matrix Preconditioning:&lt;/strong&gt; For finite-sum convex problems, control variates kill the noise floor to recover linear convergence; in deep learning, sharpness-aware updates (SAM), diagonal Hessians (Sophia), and orthogonalized matrix steps (Muon) push beyond diagonal AdamW.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-10-noisy-steps-beat-1-exact-step&quot;&gt;Worked example: Why 10 Noisy Steps Beat 1 Exact Step&lt;/h3&gt;

&lt;p&gt;Suppose \(F(w) = \frac{1}{4}\sum_{i=1}^4 f_i(w)\) where \(f_i(w) = \frac{1}{2}(w - y_i)^2\) with data \(y = (2, 4, 6, 8)\). The exact minimizer is \(w^\star = \bar{y} = 5\), and the full gradient is \(F&apos;(w) = w - 5\). Start at \(w_0 = 0\) with step size \(\eta = 0.2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;One full-batch GD step (costs 4 gradient evaluations):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Full gradient: \(F&apos;(0) = 0 - 5 = -5\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Update: \(w_1^{\text{GD}} = 0 - 0.2(-5) = 1.0\). Remaining distance to optimum: $$&lt;/td&gt;
              &lt;td&gt;1.0 - 5&lt;/td&gt;
              &lt;td&gt;= 4.0$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Four single-example SGD steps (exact same budget: 4 gradient evaluations!):&lt;/strong&gt; Walk through the shuffled pass \((y_1, y_2, y_3, y_4) = (2, 8, 4, 6)\) with \(\eta = 0.2\):
    &lt;ul&gt;
      &lt;li&gt;Step 1 (\(y = 2\)): \(w_1 = 0 - 0.2(0 - 2) = 0.4\).&lt;/li&gt;
      &lt;li&gt;Step 2 (\(y = 8\)): \(w_2 = 0.4 - 0.2(0.4 - 8) = 0.4 + 1.52 = 1.92\).&lt;/li&gt;
      &lt;li&gt;Step 3 (\(y = 4\)): \(w_3 = 1.92 - 0.2(1.92 - 4) = 1.92 + 0.416 = 2.336\).&lt;/li&gt;
      &lt;li&gt;Step 4 (\(y = 6\)): \(w_4 = 2.336 - 0.2(2.336 - 6) = 2.336 + 0.7328 = 3.0688\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare progress per gradient evaluation:&lt;/strong&gt; For the &lt;em&gt;exact same&lt;/em&gt; 4 sample evaluations, full-batch GD reached \(w = 1.0\) (error \(4.0\)), whereas 1 epoch of SGD already reached \(w = 3.0688\) (error \(1.9312\))—cutting the distance to \(w^\star\) more than twice as fast!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;stochastic-and-adaptive-methods-for-ml&quot;&gt;Stochastic and adaptive methods for ML&lt;/h1&gt;

&lt;p&gt;Chapters 06–09 treated &lt;strong&gt;full-batch&lt;/strong&gt; first-order methods: one gradient (or proximal step) that sees every training pair. Modern machine learning almost never does that. This chapter is the 2026 default stack for empirical risk minimization&lt;/p&gt;

\[\min_w F(w) = \frac{1}{n}\sum_{i=1}^n f_i(w), \qquad f_i(w) = \ell\bigl(h_w(x_i), y_i\bigr).\]

&lt;p&gt;You already met a cousin in &lt;a href=&quot;/contents/en/chapter06/06_05_stochastic_gradient_descent/&quot;&gt;06-05 Stochastic gradient descent&lt;/a&gt; and the stochastic subgradient notes in Chapter 08. Here we treat SGD and minibatches as &lt;em&gt;the&lt;/em&gt; algorithm, then add the two ingredients every deep-learning library ships: &lt;strong&gt;momentum / Nesterov&lt;/strong&gt; and &lt;strong&gt;diagonal adaptive scaling&lt;/strong&gt; (AdaGrad → RMSProp intuition → Adam → AdamW). A last required lesson develops variance reduction (SVRG / SAGA) so you know when the convex theory is sharper than Adam.&lt;/p&gt;

&lt;h2 id=&quot;why-a-separate-chapter&quot;&gt;Why a separate chapter&lt;/h2&gt;

&lt;p&gt;Full-batch gradient descent on ImageNet or a language-model corpus is not a step-size problem — it is a &lt;em&gt;memory and wall-clock&lt;/em&gt; problem. An unbiased (or nearly unbiased) gradient estimator built from one example or a minibatch of size \(B\ll n\) lets us take many more parameter steps per hour. The price is noise. Adaptive methods spend that noise on a per-coordinate learning rate; momentum spends it on a velocity that remembers consistent directions.&lt;/p&gt;

&lt;p&gt;Peer syllabi that treat this as core rather than a remark: MIT 6.7220 (S25), EPFL CS-439, USC CSCI 599, BU EC525.&lt;/p&gt;

&lt;h2 id=&quot;lessons&quot;&gt;Lessons&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;SGD and minibatches — estimators, shuffling, the \(O(1/\sqrt{T})\) story&lt;/li&gt;
  &lt;li&gt;Momentum and Nesterov — heavy ball vs look-ahead; Distill-style intuition&lt;/li&gt;
  &lt;li&gt;AdaGrad to Adam — diagonal preconditioning&lt;/li&gt;
  &lt;li&gt;AdamW and training practice — decoupled weight decay, schedules, clipping&lt;/li&gt;
  &lt;li&gt;Variance reduction — SVRG and SAGA as first-class finite-sum methods, and when mini-batch Adam still wins&lt;/li&gt;
  &lt;li&gt;Modern adaptive optimizers (optional seminar) — SAM, Sophia, Muon against the AdamW baseline&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Interactive SGD cartoons sit in &lt;a href=&quot;https://github.com/nglelinh/interactive_math/tree/main/optimization&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interactive_math/optimization&lt;/code&gt;&lt;/a&gt;. The Distill-style momentum lesson is &lt;a href=&quot;/contents/en/chapter26/26_02_momentum_and_nesterov/&quot;&gt;26-02&lt;/a&gt; (pair with the FISTA picture in &lt;a href=&quot;/contents/en/chapter09/09_05_acceleration/&quot;&gt;09-05&lt;/a&gt;). SAM, Muon, and Sophia stay &lt;strong&gt;further reading&lt;/strong&gt; — not assessed this term — but they now have a dedicated optional seminar: &lt;a href=&quot;/contents/en/chapter26/26_06_modern_optimizers/&quot;&gt;26-06&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-07 Modeling with DCP and CVXPY</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_07_Modeling_with_DCP_CVXPY/"/>
   <updated>2026-09-15T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_07_Modeling_with_DCP_CVXPY</id>
   <content type="html">&lt;p&gt;Writing a solver from scratch for every new convex model is like building a compiler every time you write a Python script. Disciplined Convex Programming (DCP), pioneered by Grant, Boyd, and Ye and implemented in CVXPY, flips the workflow: you declare your problem in near-textbook math using a small set of convexity-preserving composition rules, and CVXPY automatically &lt;em&gt;proves&lt;/em&gt; your model is convex and compiles it into a canonical cone program for a solver.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-how-dcp-verifies-and-compiles-convex-models&quot;&gt;Key ideas: How DCP Verifies and Compiles Convex Models&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Atoms with Known Curvature and Sign&lt;/strong&gt;: Every built-in CVXPY atom (like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;norm&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;quad_over_lin&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log_sum_exp&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sum_squares&lt;/code&gt;) carries two tags: its &lt;em&gt;curvature&lt;/em&gt; (affine, convex, concave, or constant) and its &lt;em&gt;monotonicity&lt;/em&gt; in each argument.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The DCP Composition Rule&lt;/strong&gt;: A composition \(h(g_1(x), \dots, g_k(x))\) is certified &lt;strong&gt;convex&lt;/strong&gt; if \(h\) is convex and, for every argument \(i\), one of three conditions holds:
    &lt;ul&gt;
      &lt;li&gt;\(g_i\) is &lt;em&gt;affine&lt;/em&gt;, OR&lt;/li&gt;
      &lt;li&gt;\(h\) is &lt;em&gt;nondecreasing&lt;/em&gt; in argument \(i\) and \(g_i\) is &lt;em&gt;convex&lt;/em&gt;, OR&lt;/li&gt;
      &lt;li&gt;\(h\) is &lt;em&gt;nonincreasing&lt;/em&gt; in argument \(i\) and \(g_i\) is &lt;em&gt;concave&lt;/em&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sufficient, Not Necessary&lt;/strong&gt;: DCP is a &lt;em&gt;sufficient&lt;/em&gt; syntax check, not a complete theorem prover. A genuinely convex function like \(\sqrt{x^2 + 1}\) written naively as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sqrt(square(x) + 1)&lt;/code&gt; gets rejected because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sqrt&lt;/code&gt; is concave while &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;square&lt;/code&gt; is convex—rewriting it via the convex atom &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;norm2(vstack([x, 1]))&lt;/code&gt; satisfies DCP immediately!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Automatic Canonicalization to Cones&lt;/strong&gt;: Once an expression passes DCP, CVXPY replaces each atom with its epigraph cone representation (LP, QP, SOCP, SDP, or ExpCone), hands the canonical matrices to OSQP/Clarabel/SCS, and maps the numerical solution right back into your Python variable objects.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-fixing-a-dcp-violation-by-hand&quot;&gt;Worked example: Fixing a DCP Violation by Hand&lt;/h3&gt;

&lt;p&gt;Suppose you want to minimize the convex function \(f(x) = \frac{1}{x} + \sqrt{x^2 + 4}\) over \(x \ge 1\) in CVXPY.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test the naive expression &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1/x + sqrt(x**2 + 4)&lt;/code&gt; against DCP rules&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Term 1: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inv_pos(x)&lt;/code&gt; is a built-in convex atom (for \(x &amp;gt; 0\)) — &lt;strong&gt;DCP-valid&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Term 2: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x**2 + 4&lt;/code&gt; is &lt;strong&gt;convex&lt;/strong&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sqrt(u)&lt;/code&gt; is &lt;strong&gt;concave&lt;/strong&gt; and nondecreasing. Composing concave(convex) has &lt;em&gt;unknown&lt;/em&gt; curvature under DCP — &lt;strong&gt;CVXPY raises &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DCPError&lt;/code&gt;!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify mathematically that \(\sqrt{x^2 + 4}\) is actually convex&lt;/strong&gt;:
\(\sqrt{x^2 + 4} = \left\|\begin{bmatrix} x \\ 2 \end{bmatrix}\right\|_2.\)
Since the Euclidean norm is convex and \((x, 2)^T\) is affine in \(x\), the composition &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.norm(cp.hstack([x, 2]), 2)&lt;/code&gt; is &lt;strong&gt;DCP-valid&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trace what CVXPY canonicalizes under the hood&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Introduce epigraph scalars \(t_1, t_2\) and minimize \(t_1 + t_2\) subject to \(x \ge 1\),&lt;/li&gt;
      &lt;li&gt;\(1/x \le t_1 \iff \left\|\begin{bmatrix} 2 \\ x - t_1 \end{bmatrix}\right\|_2 \le x + t_1\) (rotated SOCP),&lt;/li&gt;
      &lt;li&gt;\(\left\|\begin{bmatrix} x \\ 2 \end{bmatrix}\right\|_2 \le t_2\) (SOCP).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate at the boundary \(x = 1\) vs. \(x = 2\)&lt;/strong&gt;: At \(x = 1\), \(f(1) = 1 + \sqrt{5} \approx 3.236\); at \(x = 2\), \(f(2) = 0.5 + \sqrt{8} \approx 3.328\). Checking derivative \(f&apos;(x) = -x^{-2} + x/\sqrt{x^2 + 4}\) at \(x = 1\) gives \(-1 + 1/\sqrt{5} \approx -0.553 &amp;lt; 0\), and at \(x \approx 1.46\) it crosses zero—confirming an interior minimum around \(x^\star \approx 1.46\) with \(f^\star \approx 3.16\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Disciplined convex programming (DCP) is the modeling contract used by &lt;a href=&quot;https://www.cvxpy.org/&quot;&gt;CVXPY&lt;/a&gt;: you compose atoms that the library already knows are convex or concave, with rules that &lt;em&gt;preserve&lt;/em&gt; convexity. If the rewriter accepts the model, a numerical solver (OSQP, SCS, Clarabel, ECOS, …) receives a canonical cone program — the same taxonomy as the rest of this chapter.&lt;/p&gt;

&lt;p&gt;This is the Stanford EE364a practice habit: &lt;strong&gt;model first, algorithm second&lt;/strong&gt;. For Lasso, SVM, and portfolio QPs you should not hand-code a projected gradient unless you are studying the algorithm.&lt;/p&gt;

&lt;h2 id=&quot;the-dcp-idea-in-one-paragraph&quot;&gt;The DCP idea in one paragraph&lt;/h2&gt;

&lt;p&gt;A composition \(f(g(x))\) is convex when, for example, \(f\) is convex and increasing and \(g\) is convex (Boyd &amp;amp; Vandenberghe, Ch. 3). CVXPY implements a finite catalog of such atoms (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;norm&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sum_squares&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;abs&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;quad_over_lin&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;logistic&lt;/code&gt;, …) and rejects expressions it cannot certify. A rejection is not always “the problem is nonconvex” — sometimes you wrote a convex function in a form the rewriter does not see. The fix is to rewrite using known atoms, not to silence the error.&lt;/p&gt;

&lt;p&gt;Install once:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;cvxpy numpy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;mini-lab-a--lasso&quot;&gt;Mini-lab A — Lasso&lt;/h2&gt;

&lt;p&gt;Given a design matrix \(A\in\mathbb{R}^{m\times n}\) and responses \(b\), the Lasso&lt;/p&gt;

\[\min_x \tfrac12\|Ax-b\|_2^2 + \lambda \|x\|_1\]

&lt;p&gt;is a convex QP in extended form (squared loss is a convex quadratic; \(\|\cdot\|_1\) is a convex norm). In CVXPY it is three lines of atoms:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cvxpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;seed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x_true&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x_true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x_true&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.05&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Variable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;objective&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum_squares&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lam&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Problem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Minimize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;objective&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;solver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OSQP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# or SCS / CLARABEL
&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;status:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;opt:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;nnz ~&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Compare the recovered support with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x_true&lt;/code&gt;. Change \(\lambda\) and watch the sparsity–fit trade-off — the same path proximal gradient will trace in Chapter 09.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab-b--hard-margin-svm-as-a-qp&quot;&gt;Mini-lab B — hard-margin SVM as a QP&lt;/h2&gt;

&lt;p&gt;For linearly separable labeled pairs \((a_i,y_i)\) with \(y_i\in\{-1,1\}\), the hard-margin SVM is&lt;/p&gt;

\[\begin{align}
\min_{w,b} \quad &amp;amp; \tfrac12 \|w\|_2^2 \\
\text{s.t.} \quad &amp;amp; y_i(w^\top a_i + b) \ge 1, \quad i=1,\ldots,m.
\end{align}\]

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cvxpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;seed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Variable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Variable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Problem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Minimize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum_squares&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;status:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;||w|| =&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;status&lt;/code&gt; is infeasible, the cloud is not linearly separable — switch to a soft-margin hinge (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp.pos(1 - cp.multiply(y, a @ w + b))&lt;/code&gt;), which is still DCP.&lt;/p&gt;

&lt;h2 id=&quot;what-to-remember&quot;&gt;What to remember&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DCP is a &lt;em&gt;sufficient&lt;/em&gt; grammar for convexity, not a complete one.&lt;/li&gt;
  &lt;li&gt;The solver, not your Python loop, chooses between simplex, interior-point, and first-order cone methods.&lt;/li&gt;
  &lt;li&gt;When a model will not DCP-rewrite (deep nets, most nonconvex ERMs), you leave this chapter and enter &lt;a href=&quot;/contents/en/chapter26/&quot;&gt;Chapter 26&lt;/a&gt; with autodiff (&lt;a href=&quot;/contents/en/chapter27/&quot;&gt;Chapter 27&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; Replace the Lasso penalty by the elastic net \(\lambda(\alpha\|x\|_1 + \tfrac{1-\alpha}{2}\|x\|_2^2)\) and confirm CVXPY still accepts the problem. Then try writing \(\|x\|_0\) — the rewriter should refuse.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>author details</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/home/author-details/"/>
   <updated>2021-05-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/home/author-details</id>
   <content type="html">
</content>
 </entry>
 
 <entry>
   <title>17 Phương pháp điểm trong gốc-đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_primal_dual_interior_point_method/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_primal_dual_interior_point_method</id>
   <content type="html">&lt;p&gt;Nếu bạn từng chạy phương pháp chắn (barrier method) trên một bài toán quy hoạch lớn, có lẽ bạn sẽ thấy một nghịch lý khá khó chịu: để giảm tham số \(1/t\) thêm một nấc nhỏ, ta phải chạy cả một vòng lặp Newton bên trong chỉ để định tâm thật chính xác vào một điểm tạm thời \(x^\star(t)\) — một điểm mà ngay bước sau ta lại bỏ đi để chuyển sang giá trị \(t\) lớn hơn! Phương pháp điểm trong gốc–đối ngẫu (Primal-Dual Interior-Point Method, PD-IPM) ra đời để phá bỏ sự lãng phí đó: thay vì giải trọn vẹn bài toán định tâm ở mỗi \(t\), nó chỉ đi &lt;strong&gt;đúng một bước Newton&lt;/strong&gt; đồng thời trên cả biến gốc và biến đối ngẫu, rồi lập tức hạ tham số nhiễu \(\tau\) và tiến thẳng về nghiệm tối ưu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-những-trụ-cột-tạo-nên-phương-pháp-điểm-trong-gốcđối-ngẫu&quot;&gt;Kiến thức cần nhớ: Những trụ cột tạo nên phương pháp điểm trong gốc–đối ngẫu&lt;/h2&gt;

&lt;p&gt;Để nhìn rõ vì sao một thay đổi tưởng chừng đơn giản (“một bước Newton mỗi vòng lặp”) lại biến PD-IPM thành động cơ chủ lực của các bộ giải tối ưu hiện đại, hãy đặt bốn nhánh kiến thức nền cạnh nhau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết đối ngẫu và điều kiện KKT (Duality &amp;amp; KKT Theory):&lt;/strong&gt; Điều kiện KKT mô tả nghiệm tối ưu bằng hệ phương trình tính dừng, khả thi gốc–đối ngẫu và bù chặt \(u_i h_i(x) = 0\). Mọi thuật toán gốc–đối ngẫu đều tìm cách đưa hệ phương trình này về không đồng thời trên cả không gian gốc và đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đường trung tâm và phép làm trơn đồng luân (Central Path &amp;amp; Homotopy):&lt;/strong&gt; Điều kiện bù chặt \(u_i h_i(x) = 0\) tạo ra các góc gãy khiến phương pháp Newton trực tiếp bị kẹt ở biên. Thay nó bằng \(u_i h_i(x) = -\tau\) với \(\tau &amp;gt; 0\) sẽ tạo ra một đường cong trơn đi xuyên qua phần trong miền khả thi dẫn thẳng tới nghiệm tối ưu khi \(\tau \to 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp Newton tìm nghiệm hệ phi tuyến (Root-Finding Newton):&lt;/strong&gt; Khác với Newton tối ưu hóa không ràng buộc, PD-IPM dùng Newton để giải hệ phi tuyến \(r_\tau(x,u,v) = 0\). Nhờ vậy, thuật toán không còn đòi hỏi các điểm lặp trung gian phải thỏa mãn chính xác ràng buộc đẳng thức \(Ax = b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đại số tuyến tính số cho hệ KKT (Numerical Linear Algebra):&lt;/strong&gt; Ở mỗi vòng lặp, phần tốn kém nhất là giải một hệ tuyến tính có cấu trúc khối (hoặc hệ phương trình chuẩn \(AD^2A^T \Delta v = r\)). Khai thác độ thưa và tính đối xứng giúp giải hàng triệu biến chỉ trong vài chục vòng lặp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-một-bước-gốcđối-ngẫu-rút-ngắn-khoảng-cách-tối-ưu-nhanh-cỡ-nào&quot;&gt;Giải thích: Một bước gốc–đối ngẫu rút ngắn khoảng cách tối ưu nhanh cỡ nào?&lt;/h3&gt;

&lt;p&gt;Xét bài toán 1 chiều đơn giản \(\min_{x} x\) với điều kiện \(-x \le 0\) (tức \(h(x) = -x \le 0\), nghiệm tối ưu \(x^\star = 0, u^\star = 1\)). Hệ điều kiện KKT bị nhiễu với tham số \(\tau &amp;gt; 0\) là:&lt;/p&gt;

\[r_{\text{dual}} = 1 - u = 0, \qquad r_{\text{cent}} = -ux + \tau = 0.\]

&lt;p&gt;Giả sử ta đang đứng tại điểm trong \((x^{(0)}, u^{(0)}) = (2, 1)\) (khoảng cách đối ngẫu hiện tại là \(-h(x^{(0)})u^{(0)} = 2\)) và chọn mục tiêu \(\tau = 0.2\) (giảm 10 lần):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính vector phần dư hiện tại:&lt;/strong&gt; \(r_{\text{dual}} = 1 - 1 = 0\) và \(r_{\text{cent}} = -(1)(2) + 0.2 = -1.8\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tuyến tính hóa hệ quanh \((2, 1)\):&lt;/strong&gt; Đạo hàm theo \((\Delta x, \Delta u)\) cho hệ \(-\Delta u = 0\) và \(-u\Delta x - x\Delta u = -r_{\text{cent}} = 1.8\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bước Newton:&lt;/strong&gt; Từ phương trình đầu ta có \(\Delta u = 0\); thay vào phương trình hai được \(-1 \cdot \Delta x = 1.8 \implies \Delta x = -1.8\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật kèm hệ số an toàn giữ điểm trong:&lt;/strong&gt; Nếu lấy bước đầy đủ \(\theta = 1\) thì \(x^{(1)} = 0.2 &amp;gt; 0, u^{(1)} = 1 &amp;gt; 0\) — rơi trúng chính xác điểm đường trung tâm ứng với \(\tau = 0.2\) chỉ sau &lt;strong&gt;đúng 1 bước&lt;/strong&gt;, giảm khoảng cách đối ngẫu từ \(2\) xuống \(0.2\)! Với bài toán tổng quát có độ cong phi tuyến, ta dùng hệ số an toàn (như \(\theta = 0.9\) cho \(x^{(1)} = 0.38\)) để vừa tránh chạm biên vừa rút gọn nhanh khoảng cách đối ngẫu.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong chương này, chúng ta tìm hiểu &lt;strong&gt;phương pháp điểm trong gốc-đối ngẫu (Primal-Dual Interior-Point Method)&lt;/strong&gt; — phương pháp cải thiện hiệu năng bằng cách rút gọn bước định tâm (centering) của phương pháp chắn xuống chỉ còn một bước Newton ở mỗi vòng lặp.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp điểm trong gốc-đối ngẫu&lt;/strong&gt; nới lỏng yêu cầu phải giữ nghiệm luôn khả thi trong bước định tâm, đồng thời áp dụng phiên bản tìm nghiệm (root-finding) của phương pháp Newton để tuyến tính hóa hệ phương trình phi tuyến. Nhờ đó, thuật toán thường hội tụ nhanh hơn và đạt độ chính xác cao hơn so với phương pháp chắn.&lt;/p&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo-và-đọc-thêm&quot;&gt;Tài liệu tham khảo và đọc thêm&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;S. Boyd and L. Vandenberghe (2004), “Convex optimization,” Chapter 11&lt;/li&gt;
  &lt;li&gt;S. Wright (1997), “Primal-dual interior-point methods,” Chapters 5 and 6&lt;/li&gt;
  &lt;li&gt;J. Renegar (2001), “A mathematical view of interior-point methods”&lt;/li&gt;
  &lt;li&gt;Y. Nesterov and M. Todd (1998), “Primal-dual interior-point methods for self-scaled cones.” SIAM J. Optim.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>17-08 Bài Tập Thực Hành - Primal-Dual Interior Point</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_08_Practical_Exercises_Primal_Dual_Interior_Point/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_08_Practical_Exercises_Primal_Dual_Interior_Point</id>
   <content type="html">&lt;p&gt;Cách nhanh nhất để thực sự làm chủ phương pháp điểm trong gốc–đối ngẫu là tự tay lắp ráp hệ phương trình đường trung tâm, giải thử hệ Newton trên giấy với bài toán 2 biến, rồi tự viết vài chục dòng mã quan sát ba phần dư \(r_{\text{prim}}, r_{\text{dual}}, \eta\) rơi tự do về không qua từng vòng lặp. Bộ bài tập thực hành này dẫn bạn đi từ việc giải tay đường trung tâm của LP cho đến phân tích bước Newton và cài đặt thuật toán hoàn chỉnh.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-quy-trình-4-bước-giải-mọi-bài-tập-thực-hành-pd-ipm&quot;&gt;Kiến thức cần nhớ: Quy trình 4 bước giải mọi bài tập thực hành PD-IPM&lt;/h2&gt;

&lt;p&gt;Khi tiếp cận các bài tập tính tay và lập trình bên dưới, hãy luôn đi theo bốn bước kiểm soát chặt chẽ sau để tránh sai dấu:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn hóa dấu ràng buộc:&lt;/strong&gt; Luôn viết rõ ràng ràng buộc bất đẳng thức dưới dạng \(h_i(x) \le 0\) (ví dụ \(x_i \ge 0 \iff -x_i \le 0\)) hoặc dùng ký hiệu LP chuẩn \(x \ge 0, s \ge 0\); sai một dấu trừ ở \(\nabla h(x)\) sẽ làm hỏng toàn bộ hệ KKT.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lập đủ ba khối phần dư:&lt;/strong&gt; Viết tường minh \(r_{\text{dual}}\), \(r_{\text{cent}}\) và \(r_{\text{prim}}\) trước khi lấy đạo hàm lập ma trận Jacobi. Kiểm tra kích thước của từng khối ma trận để chắc chắn hệ tuyến tính vuông.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giữ chặt tính điểm trong khi cập nhật:&lt;/strong&gt; Trước mỗi phép cập nhật \((x, u, v) + \theta(\Delta x, \Delta u, \Delta v)\), luôn kiểm tra tỷ lệ chạm biên \(\theta_{\max}\) cho cả biến gốc \(h(x) &amp;lt; 0\) và biến đối ngẫu \(u &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng chéo kết quả:&lt;/strong&gt; Ở mỗi điểm tính được, kiểm tra lại tích \(x_i s_i \approx \tau\) và đối chiếu giá trị hàm mục tiêu gốc \(f(x)\) với giá trị đối ngẫu \(g(u, v)\) để phát hiện lỗi tính toán ngay lập tức.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-khởi-động-bằng-một-phép-kiểm-tra-1-bước-trên-bài-toán-bậc-hai-có-ràng-buộc-không-âm&quot;&gt;Giải thích: Khởi động bằng một phép kiểm tra 1 bước trên bài toán bậc hai có ràng buộc không âm&lt;/h3&gt;

&lt;p&gt;Trước khi bắt đầu Bài tập 1, hãy thử kiểm tra nhanh một vòng lặp trên bài toán tối ưu 2 biến:&lt;/p&gt;

\[\min_{x_1, x_2} \; \frac{1}{2}(x_1 - 2)^2 + \frac{1}{2}(x_2 + 1)^2 \qquad \text{với điều kiện} \qquad x_1 \ge 0, \; x_2 \ge 0.\]

&lt;p&gt;Nghiệm chính xác là \(x^\star = (2, 0)\), nhân tử \(u^\star = (0, 1)\) (ràng buộc \(x_2 \ge 0\) hoạt động, \(x_1 \ge 0\) không hoạt động). Xét điểm đường trung tâm ứng với \(\tau = 0.25\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hệ KKT bị nhiễu:&lt;/strong&gt; Với \(h_1(x) = -x_1, h_2(x) = -x_2\), ta có:
\(x_1 - 2 - u_1 = 0, \quad x_2 + 1 - u_2 = 0, \quad x_1 u_1 = 0.25, \quad x_2 u_2 = 0.25.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải tách từng biến:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(x_1 &amp;gt; 0\): \(x_1(x_1 - 2) = 0.25 \implies x_1^2 - 2x_1 - 0.25 = 0 \implies x_1(0.25) = 1 + \sqrt{1.25} \approx 2.1180\), \(u_1(0.25) \approx 0.1180\).&lt;/li&gt;
      &lt;li&gt;Với \(x_2 &amp;gt; 0\): \(x_2(x_2 + 1) = 0.25 \implies x_2^2 + x_2 - 0.25 = 0 \implies x_2(0.25) = \frac{-1 + \sqrt{2}}{2} \approx 0.2071\), \(u_2(0.25) \approx 1.2071\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra khoảng cách đối ngẫu:&lt;/strong&gt; \(\eta = x_1 u_1 + x_2 u_2 = 0.25 + 0.25 = 0.50 = 2\tau\). Quan sát thấy khi \(\tau \to 0\), \(x_1(\tau) \to 2, u_1(\tau) \to 0\) (không hoạt động) còn \(x_2(\tau) \to 0, u_2(\tau) \to 1\) (hoạt động) — chính xác hành vi bạn sẽ gặp xuyên suốt các bài tập bên dưới!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---phương-pháp-điểm-trong-gốc-đối-ngẫu&quot;&gt;Bài Tập Thực Hành - Phương pháp điểm trong gốc-đối ngẫu&lt;/h1&gt;

&lt;p&gt;Các bài tập được tham khảo từ Wright (1997) và Nesterov &amp;amp; Nemirovskii (1994).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-1-đường-trung-tâm-gốc-đối-ngẫu-cho-lp&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Đường trung tâm gốc-đối ngẫu cho LP&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho bài toán LP:&lt;/p&gt;

\[\begin{align}
\min \quad &amp;amp; x_1 + 2x_2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 = 3 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết các điều kiện KKT.&lt;br /&gt;
b) Thiết lập hệ điều kiện KKT bị nhiễu với tham số \(\mu\).&lt;br /&gt;
c) Tính điểm trên đường trung tâm \(x(\mu)\) tại \(\mu = 1, 0.1, 0.01\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Các điều kiện KKT:**

$$
\begin{align}
\nabla f + A^T\nu - \lambda &amp;amp;= 0 \quad \text{(tính dừng)} \\
Ax &amp;amp;= b \quad \text{(khả thi gốc)} \\
x &amp;amp;\geq 0, \, \lambda \geq 0 \quad \text{(khả thi gốc và đối ngẫu)} \\
\lambda_i x_i &amp;amp;= 0 \quad \text{(bù chặt)}
\end{align}
$$

Thay dữ liệu bài toán vào, ta có:

$$
\begin{align}
\begin{bmatrix} 1 \\ 2 \end{bmatrix} + \nu \begin{bmatrix} 1 \\ 1 \end{bmatrix} - \begin{bmatrix} \lambda_1 \\ \lambda_2 \end{bmatrix} &amp;amp;= 0 \\
x_1 + x_2 &amp;amp;= 3 \\
\lambda_1 x_1 = \lambda_2 x_2 &amp;amp;= 0
\end{align}
$$

---

**b) Điều kiện KKT bị nhiễu (phương trình đường trung tâm):**

Thay điều kiện bù chặt $$\lambda_i x_i = 0$$ bằng:

$$\lambda_i x_i = \mu \quad \forall i$$

Ta thu được hệ:

$$
\begin{cases}
1 + \nu - \lambda_1 = 0 \\
2 + \nu - \lambda_2 = 0 \\
x_1 + x_2 = 3 \\
\lambda_1 x_1 = \mu \\
\lambda_2 x_2 = \mu
\end{cases}
$$

---

**c) Giải tìm đường trung tâm:**

Từ (1): $$\lambda_1 = 1 + \nu$$  
Từ (2): $$\lambda_2 = 2 + \nu$$  
Từ (4): $$x_1 = \frac{\mu}{1 + \nu}$$  
Từ (5): $$x_2 = \frac{\mu}{2 + \nu}$$

Thay vào phương trình (3):

$$\frac{\mu}{1+\nu} + \frac{\mu}{2+\nu} = 3$$

$$\mu\left(\frac{1}{1+\nu} + \frac{1}{2+\nu}\right) = 3$$

$$\mu \cdot \frac{(2+\nu) + (1+\nu)}{(1+\nu)(2+\nu)} = 3$$

$$\mu \cdot \frac{3 + 2\nu}{(1+\nu)(2+\nu)} = 3$$

$$(1+\nu)(2+\nu) = \mu\left(1 + \frac{2\nu}{3}\right)$$

Giải phương trình bậc hai: $$\nu^2 + 3\nu + 2 = \mu + \frac{2\mu\nu}{3}$$.

**Với $$\mu = 1$$:**

$$\nu^2 + 3\nu + 2 = 1 + \frac{2\nu}{3}$$

$$\nu^2 + \frac{7\nu}{3} + 1 = 0$$

$$\nu = \frac{-7/3 \pm \sqrt{49/9 - 4}}{2} \in \{-0.566, -1.768\}$$

Chỉ nghiệm $$\nu &amp;gt; -1$$ mới đảm bảo $$\lambda_1, \lambda_2 &amp;gt; 0$$, do đó chọn $$\nu \approx -0.566$$, suy ra $$x_1 = \frac{1}{1-0.566} \approx 2.30$$, $$x_2 = \frac{1}{2-0.566} \approx 0.70$$ (kiểm tra: $$x_1 + x_2 = 3$$ ✓).

**Với $$\mu = 0.1$$:** $$\nu \approx -0.9656$$, $$x \approx (2.90, 0.097)$$.

**Với $$\mu = 0.01$$:** $$\nu \approx -0.9967$$, $$x \approx (2.99, 0.010)$$.

**Khi $$\mu \to 0$$:** $$x^* \to (3, 0)$$ (nghiệm tối ưu của bài toán gốc), $$\nu^* \to -1$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-bước-newton-cho-hệ-gốc-đối-ngẫu&quot;&gt;📝 &lt;strong&gt;Bài tập 2: Bước Newton cho hệ gốc-đối ngẫu&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét bài toán LP từ Bài tập 1. Tại điểm lặp \((x, \lambda, \nu)^{(k)}\), xét hệ Newton:&lt;/p&gt;

\[\begin{bmatrix}
0 &amp;amp; A^T &amp;amp; -I \\
A &amp;amp; 0 &amp;amp; 0 \\
\Lambda &amp;amp; 0 &amp;amp; X
\end{bmatrix}
\begin{bmatrix}
\Delta x \\
\Delta \nu \\
\Delta \lambda
\end{bmatrix}
=
-\begin{bmatrix}
r_d \\
r_p \\
r_c
\end{bmatrix}\]

&lt;p&gt;với \(\Lambda = \text{diag}(\lambda)\), \(X = \text{diag}(x)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết các phần dư \(r_d, r_p, r_c\).&lt;br /&gt;
b) Rút gọn hệ phương trình bằng cách khử \(\Delta\lambda\).&lt;br /&gt;
c) Tính \(\Delta x\) tại \(x = (1, 1)\), \(\lambda = (2, 3)\), \(\nu = -1\), \(\mu = 0.5\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Các phần dư:**

$$
\begin{align}
r_d &amp;amp;= \nabla f + A^T\nu - \lambda = \begin{bmatrix} 1 \\ 2 \end{bmatrix} + \nu \begin{bmatrix} 1 \\ 1 \end{bmatrix} - \begin{bmatrix} \lambda_1 \\ \lambda_2 \end{bmatrix} \\
r_p &amp;amp;= Ax - b = x_1 + x_2 - 3 \\
r_c &amp;amp;= \Lambda X e - \mu e = \begin{bmatrix} \lambda_1 x_1 - \mu \\ \lambda_2 x_2 - \mu \end{bmatrix}
\end{align}
$$

---

**b) Khử $$\Delta\lambda$$:**

Từ hàng thứ 3: $$\Lambda \Delta x + X \Delta\lambda = -r_c$$, suy ra:

$$\Delta\lambda = -X^{-1}(\Lambda \Delta x + r_c)$$

Thay vào hàng thứ 1:

$$A^T \Delta\nu - \Delta\lambda = -r_d$$

$$A^T \Delta\nu + X^{-1}(\Lambda \Delta x + r_c) = -r_d$$

$$\Lambda X^{-1} \Delta x + A^T \Delta\nu = -r_d - X^{-1}r_c$$

Kết hợp với hàng thứ 2, ta thu được hệ rút gọn:

$$
\begin{bmatrix}
\Lambda X^{-1} &amp;amp; A^T \\
A &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
\Delta x \\
\Delta \nu
\end{bmatrix}
=
\begin{bmatrix}
-r_d - X^{-1}r_c \\
-r_p
\end{bmatrix}
$$

---

**c) Tính toán bằng số:**

Với $$x = (1, 1)$$, $$\lambda = (2, 3)$$, $$\nu = -1$$, $$\mu = 0.5$$:

$$r_d = \begin{bmatrix} 1-1-2 \\ 2-1-3 \end{bmatrix} = \begin{bmatrix} -2 \\ -2 \end{bmatrix}$$

$$r_p = 1 + 1 - 3 = -1$$

$$r_c = \begin{bmatrix} 2 \cdot 1 - 0.5 \\ 3 \cdot 1 - 0.5 \end{bmatrix} = \begin{bmatrix} 1.5 \\ 2.5 \end{bmatrix}$$

$$\Lambda X^{-1} = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 3 \end{bmatrix} \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 3 \end{bmatrix}$$

$$-r_d - X^{-1}r_c = \begin{bmatrix} 2 \\ 2 \end{bmatrix} - \begin{bmatrix} 1.5 \\ 2.5 \end{bmatrix} = \begin{bmatrix} 0.5 \\ -0.5 \end{bmatrix}$$

Hệ phương trình tuyến tính:

$$
\begin{bmatrix}
2 &amp;amp; 0 &amp;amp; 1 \\
0 &amp;amp; 3 &amp;amp; 1 \\
1 &amp;amp; 1 &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
\Delta x_1 \\
\Delta x_2 \\
\Delta \nu
\end{bmatrix}
=
\begin{bmatrix}
0.5 \\
-0.5 \\
1
\end{bmatrix}
$$

Giải hệ thu được $$\Delta x = (0.8, 0.2)$$, $$\Delta\nu = -1.1$$ (kiểm tra: $$2(0.8) - 1.1 = 0.5$$, $$3(0.2) - 1.1 = -0.5$$, $$0.8 + 0.2 = 1$$ ✓).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-thuật-toán-dự-báo--hiệu-chỉnh-mehrotra-predictor-corrector&quot;&gt;📝 &lt;strong&gt;Bài tập 3: Thuật toán Dự báo – Hiệu chỉnh Mehrotra (Predictor-Corrector)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Thuật toán Mehrotra kết hợp hai bước dự báo (predictor) và hiệu chỉnh (corrector):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước dự báo (Predictor):&lt;/strong&gt; \(\mu = 0\) (hướng affine scaling)&lt;br /&gt;
&lt;strong&gt;Bước hiệu chỉnh (Corrector):&lt;/strong&gt; \(\mu = \sigma \cdot \frac{x^T\lambda}{n}\) với \(\sigma \in (0, 1)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Giải thích trực giác của hai bước này.&lt;br /&gt;
b) Trình bày cách tính \(\sigma\) từ bước dự báo.&lt;br /&gt;
c) Áp dụng minh họa cho bài toán LP từ Bài tập 1.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Trực giác:**

**Bước dự báo (affine):** Hướng thẳng về tập nghiệm tối ưu ($$\mu = 0$$), tạo bước tiến mạnh nhằm giảm nhanh khoảng cách đối ngẫu.

**Bước hiệu chỉnh (centering):** Kéo điểm lặp trở lại gần đường trung tâm, giúp duy trì tính khả thi và đảm bảo hội tụ ổn định.

**Tham số $$\sigma$$ thích nghi** dựa trên chất lượng của bước dự báo:
- Nếu bước dự báo giảm mạnh khoảng cách đối ngẫu → chọn $$\sigma$$ nhỏ (tiến mạnh hơn).
- Nếu bước dự báo tiến được ít → chọn $$\sigma$$ lớn (ưu tiên định tâm an toàn hơn).

---

**b) Tính $$\sigma$$:**

Sau bước dự báo affine thu được $$(\tilde{x}, \tilde{\lambda})$$:

$$\tilde{\mu} = \frac{\tilde{x}^T\tilde{\lambda}}{n}$$

$$\sigma = \left(\frac{\tilde{\mu}}{\mu}\right)^3$$

(quy tắc lũy thừa bậc ba mang lại tốc độ hội tụ nhanh trong thực tế).

---

**c) Ví dụ minh họa:**

Điểm hiện tại: $$x = (2, 1)$$, $$\lambda = (1, 2)$$, $$\mu = \frac{2 \cdot 1 + 1 \cdot 2}{2} = 2$$.

**Bước dự báo ($$\mu_{\text{aff}} = 0$$):**

$$\tilde{x} = (2.5, 0.5)$$, $$\tilde{\lambda} = (0.5, 1.5)$$

$$\tilde{\mu} = \frac{2.5 \cdot 0.5 + 0.5 \cdot 1.5}{2} = \frac{2}{2} = 1$$

$$\sigma = \left(\frac{1}{2}\right)^3 = 0.125$$

**Bước hiệu chỉnh:** Mục tiêu mới $$\mu_{\text{new}} = 0.125 \cdot 2 = 0.25$$.

Giá trị $$\sigma$$ nhỏ cho phép giảm mạnh tham số rào cản ở bước này.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-khởi-tạo-không-khả-thi-infeasible-start&quot;&gt;📝 &lt;strong&gt;Bài tập 4: Khởi tạo không khả thi (Infeasible Start)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho điểm khởi tạo không khả thi \((x^{(0)}, \lambda^{(0)}, \nu^{(0)})\) không thỏa mãn ràng buộc đẳng thức \(Ax = b\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Trình bày cách xử lý phần dư để cho phép điểm khởi tạo không khả thi.&lt;br /&gt;
b) Giải thích cơ chế hội tụ về miền khả thi gốc – đối ngẫu.&lt;br /&gt;
c) Minh họa với bài toán LP và \(x^{(0)} = (1, 1)\) (không thỏa mãn \(x_1 + x_2 = 3\)).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Xử lý phần dư:**

Cho phép phần dư gốc ban đầu $$r_p = Ax - b \neq 0$$. Hệ phương trình Newton giữ nguyên cấu trúc:

$$
\begin{bmatrix}
0 &amp;amp; A^T &amp;amp; -I \\
A &amp;amp; 0 &amp;amp; 0 \\
\Lambda &amp;amp; 0 &amp;amp; X
\end{bmatrix}
\begin{bmatrix}
\Delta x \\
\Delta \nu \\
\Delta \lambda
\end{bmatrix}
=
-\begin{bmatrix}
r_d \\
r_p \\
r_c
\end{bmatrix}
$$

Qua các vòng lặp, chuẩn phần dư $$\|r_p\|$$ giảm dần về $$0$$.

---

**b) Hội tụ:**

Mỗi bước Newton làm giảm đồng thời chuẩn tổng hợp $$\|(r_d, r_p, r_c)\|$$ (và hội tụ bậc hai khi ở gần nghiệm). Trong phương pháp điểm trong gốc-đối ngẫu khởi tạo không khả thi, cả biến gốc $$x$$ và biến đối ngẫu $$(\lambda, \nu)$$ cùng tiến về miền khả thi và nghiệm tối ưu.

---

**c) Ví dụ minh họa:**

Với $$x^{(0)} = (1, 1)$$, ta có $$r_p = 1 + 1 - 3 = -1$$.

Sau một bước Newton đầy đủ ($$\alpha = 1$$), chẳng hạn $$x^{(1)} = (1.5, 1.5)$$, ta có $$r_p = 0$$ (đạt khả thi gốc) vì phương trình hàng 2 đảm bảo $$A\Delta x = -r_p$$. (Nếu dùng độ dài bước $$\alpha &amp;lt; 1$$ thì $$r_p$$ giảm theo hệ số $$1 - \alpha$$.) Sau đó thuật toán tiếp tục như PD-IPM chuẩn.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-tính-tự-tương-thích-self-concordance-và-độ-phức-tạp-đa-thức&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Tính tự tương thích (Self-Concordance) và độ phức tạp đa thức&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Các phương pháp điểm trong đạt độ phức tạp thời gian đa thức nhờ sử dụng hàm chắn tự tương thích (self-concordant barriers).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Phát biểu định nghĩa tính tự tương thích.&lt;br /&gt;
b) Chứng minh hàm chắn logarit \(\phi(x) = -\sum \log x_i\) là hàm tự tương thích.&lt;br /&gt;
c) Giải thích vì sao tính chất này dẫn đến số vòng lặp \(O(\sqrt{n} \log(1/\epsilon))\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Tính tự tương thích:**

Hàm lồi khả vi ba lần $$\phi$$ được gọi là tự tương thích nếu với mọi hướng $$h$$:

$$|\phi&apos;&apos;&apos;(x)[h, h, h]| \leq 2(\phi&apos;&apos;(x)[h, h])^{3/2}$$

**Ý nghĩa:** Đạo hàm bậc ba bị chặn bởi lũy thừa $$3/2$$ của đạo hàm bậc hai, đảm bảo xấp xỉ bậc hai cục bộ của phương pháp Newton có độ ổn định nhất quán trên toàn miền.

---

**b) Chứng minh cho hàm chắn logarit:**

$$\phi(x) = -\sum_{i=1}^n \log x_i$$

$$\phi&apos;(x) = -\sum \frac{1}{x_i} e_i$$

$$\phi&apos;&apos;(x) = \sum \frac{1}{x_i^2} e_i e_i^T = \text{diag}(1/x_1^2, \ldots, 1/x_n^2)$$

$$\phi&apos;&apos;&apos;(x)[h, h, h] = -\sum \frac{2}{x_i^3} h_i^3$$

Kiểm tra bất đẳng thức:

$$|\phi&apos;&apos;&apos;[h,h,h]| = 2\sum \frac{|h_i|^3}{x_i^3} \leq 2\left(\sum \frac{h_i^2}{x_i^2}\right)^{3/2} = 2(\phi&apos;&apos;[h,h])^{3/2}$$ ✓

---

**c) Độ phức tạp thời gian đa thức:**

Tính tự tương thích đảm bảo bước Newton có miền hội tụ bậc hai xác định trước và mức giảm hàm mục tiêu ổn định.

**Ý chính:** Tham số chắn của $$\phi(x) = -\sum_{i=1}^n \log x_i$$ trên góc phần tư dương $$\mathbb{R}^n_+$$ là $$\vartheta = n$$. Mỗi vòng lặp cho phép giảm $$\mu$$ theo hệ số $$\left(1 - \frac{1}{\sqrt{\vartheta}}\right)$$ chỉ với $$O(1)$$ bước Newton, nên chỉ cần tổng cộng $$O(\sqrt{\vartheta}\log(1/\epsilon)) = O(\sqrt{n}\log(1/\epsilon))$$ vòng lặp để đưa $$\mu$$ xuống dưới $$\epsilon$$.

Đây là **độ phức tạp đa thức** (so với độ phức tạp hàm mũ trong trường hợp xấu nhất của phương pháp đơn hình).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;các-thành-phần-chính-của-pd-ipm&quot;&gt;&lt;strong&gt;Các thành phần chính của PD-IPM:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Thành phần&lt;/th&gt;
      &lt;th&gt;Vai trò&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Đường trung tâm (Central path)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Quỹ đạo trơn dẫn về nghiệm tối ưu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Điều kiện KKT bị nhiễu&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Thay điều kiện bù chặt bằng \(\lambda x = \mu e\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hệ Newton&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hệ phương trình tuyến tính khối \(3\times 3\) cập nhật đồng thời biến gốc và đối ngẫu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dự báo – Hiệu chỉnh (Predictor-Corrector)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Cân bằng giữa tốc độ giảm khoảng cách đối ngẫu và bước định tâm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Khởi tạo không khả thi (Infeasible start)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Xử lý trực tiếp điểm khởi tạo chưa thỏa mãn \(Ax = b\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;độ-phức-tạp-tính-toán&quot;&gt;&lt;strong&gt;Độ phức tạp tính toán:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mỗi vòng lặp:&lt;/strong&gt; \(O(n^3)\) (phân rã ma trận)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng số vòng lặp:&lt;/strong&gt; \(O(\sqrt{n} \log(1/\epsilon))\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng thể cho LP:&lt;/strong&gt; \(O(n^{3.5} \log(1/\epsilon))\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Wright, S. J. (1997). &lt;em&gt;Primal-Dual Interior-Point Methods&lt;/em&gt;. SIAM.&lt;/li&gt;
  &lt;li&gt;Nesterov, Y., &amp;amp; Nemirovskii, A. (1994). &lt;em&gt;Interior-Point Polynomial Algorithms&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Mehrotra, S. (1992). “On the Implementation of a Primal-Dual IPM”. &lt;em&gt;SIAM Journal&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>17-07 Bài tập trắc nghiệm - Phương Pháp Điểm Trong Nguyên Thủy-Đối Ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_07_Quiz_Primal_Dual_Interior_Point/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_07_Quiz_Primal_Dual_Interior_Point</id>
   <content type="html">&lt;p&gt;Đọc hiểu công thức hệ Newton gốc–đối ngẫu trên giấy là một chuyện, nhưng khi đối mặt với những câu hỏi bẫy về tính khả thi của điểm lặp trung gian, dấu của phần dư trung tâm, hay sự khác biệt giữa phương pháp chắn và PD-IPM trên bài toán LP/SDP, trực giác toán học mới thực sự được thử lửa. Bộ câu hỏi trắc nghiệm này giúp bạn rà soát lại từng mắt xích lý thuyết của Chương 17 trước khi chuyển sang các thuật toán bậc hai khác.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhóm-bẫy-tư-duy-thường-gặp-ở-chương-17&quot;&gt;Kiến thức cần nhớ: Bốn nhóm bẫy tư duy thường gặp ở Chương 17&lt;/h2&gt;

&lt;p&gt;Trước khi bắt tay làm bài trắc nghiệm, hãy kiểm tra nhanh bốn điểm dễ nhầm lẫn nhất của phương pháp điểm trong gốc–đối ngẫu:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khả thi gốc–đối ngẫu vs. Điểm trong chặt:&lt;/strong&gt; Điểm lặp của PD-IPM luôn phải giữ \(h(x) &amp;lt; 0\) và \(u &amp;gt; 0\) (nằm chặt trong miền bất đẳng thức), nhưng &lt;strong&gt;không&lt;/strong&gt; bắt buộc phải thỏa mãn \(Ax = b\) hay \(\nabla f(x) + \nabla h(x)u + A^T v = 0\) trong quá trình chạy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tham số \(\tau\) (hay \(1/t\)) và tỉ lệ \(\sigma\) (hay \(1/\mu\)):&lt;/strong&gt; Khi \(\tau\) càng nhỏ, điểm đường trung tâm càng sát nghiệm tối ưu, nhưng bước Newton dễ đụng biên hơn. Tỉ lệ \(\sigma = \frac{1}{\mu} \in (0, 1)\) quyết định tốc độ thu hẹp \(\tau\) sau mỗi bước.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu thay thế \(\eta = -h(x)^T u\):&lt;/strong&gt; Chỉ bằng khoảng cách đối ngẫu thực \(f(x) - g(u, v)\) khi điểm lặp đồng thời khả thi gốc và đối ngẫu; nếu \(r_{\text{prim}} \ne 0\) hoặc \(r_{\text{dual}} \ne 0\), \(\eta\) chỉ là đại lượng thay thế để dẫn đường.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp đặc biệt LP và SDP:&lt;/strong&gt; Trên LP, hệ KKT rút gọn thành hệ phương trình chuẩn \(AD^2A^T\Delta y = \text{rhs}\) với \(D^2 = XS^{-1}\); trên SDP, tích ma trận \(XS\) không tự động đối xứng nên cần bước đối xứng hóa hướng Newton.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-đọc-nhật-ký-chạy-một-bộ-giải-pd-ipm-để-kiểm-tra-tiêu-chuẩn-dừng&quot;&gt;Giải thích: Đọc nhật ký chạy một bộ giải PD-IPM để kiểm tra tiêu chuẩn dừng&lt;/h3&gt;

&lt;p&gt;Giả sử bạn chạy một bộ giải PD-IPM với ngưỡng dung sai \(\epsilon_{\text{feas}} = 10^{-6}\) và \(\epsilon = 10^{-6}\) cho một bài toán có \(m = 4\) ràng buộc bất đẳng thức, và thu được bảng nhật ký 3 vòng lặp cuối:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 12:&lt;/strong&gt; \(\|r_{\text{prim}}\|_2 = 2.5 \times 10^{-4}\), \(\|r_{\text{dual}}\|_2 = 8.0 \times 10^{-5}\), \(\eta = 4.0 \times 10^{-7}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 13:&lt;/strong&gt; \(\|r_{\text{prim}}\|_2 = 1.2 \times 10^{-7}\), \(\|r_{\text{dual}}\|_2 = 5.0 \times 10^{-7}\), \(\eta = 2.0 \times 10^{-5}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 14:&lt;/strong&gt; \(\|r_{\text{prim}}\|_2 = 3.0 \times 10^{-8}\), \(\|r_{\text{dual}}\|_2 = 9.0 \times 10^{-8}\), \(\eta = 6.0 \times 10^{-7}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hãy kiểm tra từng vòng lặp:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tại vòng lặp 12:&lt;/strong&gt; Dù \(\eta = 4.0 \times 10^{-7} \le 10^{-6}\) rất nhỏ, ta &lt;strong&gt;chưa được dừng&lt;/strong&gt; vì \(r_{\text{prim}}\) và \(r_{\text{dual}}\) vẫn lớn hơn \(10^{-6}\) — điểm hiện tại chưa đủ khả thi nên \(\eta\) chưa phải khoảng cách đối ngẫu thực!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại vòng lặp 13:&lt;/strong&gt; Cả hai phần dư khả thi đã đạt chuẩn \(\le 10^{-6}\), nhưng \(\eta = 2.0 \times 10^{-5} &amp;gt; 10^{-6}\), nghĩa là nghiệm đã khả thi nhưng chưa đủ gần giá trị tối ưu \(p^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại vòng lặp 14:&lt;/strong&gt; Cả ba điều kiện \(\|r_{\text{prim}}\|_2 \le 10^{-6}\), \(\|r_{\text{dual}}\|_2 \le 10^{-6}\) và \(\eta \le 10^{-6}\) đều thỏa mãn đồng thời — bộ giải &lt;strong&gt;dừng hợp lệ&lt;/strong&gt; và đảm bảo sai số tối ưu dưới \(10^{-6}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-phương-pháp-điểm-trong-gốc-đối-ngẫu-primal-dual-interior-point-method&quot;&gt;⚡ &lt;strong&gt;Phương pháp điểm trong gốc-đối ngẫu (Primal-Dual Interior-Point Method)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;động-lực-và-so-sánh-với-phương-pháp-chắn&quot;&gt;&lt;strong&gt;Động lực và so sánh với phương pháp chắn&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Hạn chế của phương pháp chắn (Barrier Method):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nhiều bước Newton cho mỗi giá trị \(t\):&lt;/strong&gt; Bước định tâm (centering) đòi hỏi nhiều vòng lặp trong.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bắt buộc duy trì tính khả thi:&lt;/strong&gt; Luôn phải giữ \(Ax = b\) và \(h_i(x) &amp;lt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải tuần tự:&lt;/strong&gt; Phải giải từng bài toán con rào cản kế tiếp nhau.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm của phương pháp gốc-đối ngẫu:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Một bước Newton mỗi vòng lặp:&lt;/strong&gt; Không cần giải chính xác bước định tâm ở mỗi giá trị \(\tau\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cho phép khởi tạo không khả thi:&lt;/strong&gt; Không yêu cầu \(Ax^0 = b\) ở điểm bắt đầu (trong dạng này vẫn cần \(h(x^0) &amp;lt; 0, u^0 &amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật đồng thời:&lt;/strong&gt; Cập nhật cùng lúc cả biến gốc và biến đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu năng thực tế tốt hơn:&lt;/strong&gt; Thường cần ít vòng lặp hơn và đạt độ chính xác cao hơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-phương-trình-đường-trung-tâm&quot;&gt;🎯 &lt;strong&gt;Phương trình đường trung tâm&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;điều-kiện-kkt-gốc&quot;&gt;&lt;strong&gt;Điều kiện KKT gốc&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
\nabla f(x) + \nabla h(x)u + A^T v &amp;amp;= 0 \\
Uh(x) &amp;amp;= 0 \\
Ax &amp;amp;= b \\
u \ge 0, \quad -h(x) &amp;amp;\ge 0
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-kkt-bị-nhiễu-đường-trung-tâm&quot;&gt;&lt;strong&gt;Điều kiện KKT bị nhiễu (Đường trung tâm)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
\nabla f(x) + \nabla h(x)u + A^T v &amp;amp;= 0 \\
Uh(x) + \tau\mathbf{1} &amp;amp;= 0 \\
Ax - b &amp;amp;= 0 \\
u &amp;gt; 0, \quad -h(x) &amp;amp;&amp;gt; 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điểm khác biệt chính:&lt;/strong&gt; Điều kiện bù chặt \(Uh(x) = 0\) được thay bằng \(Uh(x) = -\tau\mathbf{1}\), điều kiện không âm \(\ge 0\) chuyển thành điểm trong ngặt \(&amp;gt; 0\), với tham số \(\tau = 1/t\) kiểm soát mức độ nhiễu. Nghiệm \((x(\tau), u(\tau), v(\tau))\) trên đường trung tâm có khoảng cách đối ngẫu đúng bằng:
\(f(x(\tau)) - \min_x L(x, u(\tau), v(\tau)) = m\tau = \frac{m}{t}\)&lt;/p&gt;

&lt;h3 id=&quot;-bước-newton-cho-đường-trung-tâm&quot;&gt;🔄 &lt;strong&gt;Bước Newton cho đường trung tâm&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vector phần dư:&lt;/strong&gt;
\(r(x,u,v) = \begin{bmatrix}
\nabla f(x) + \nabla h(x)u + A^T v \\
Uh(x) + \tau\mathbf{1} \\
Ax - b
\end{bmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hệ phương trình Newton:&lt;/strong&gt;
\(\begin{bmatrix}
\nabla^2 f(x) + \sum u_i \nabla^2 h_i(x) &amp;amp; \nabla h(x) &amp;amp; A^T \\
U \nabla h(x)^T &amp;amp; H(x) &amp;amp; 0 \\
A &amp;amp; 0 &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
\Delta x \\
\Delta u \\
\Delta v
\end{bmatrix} = -r(x,u,v)\)&lt;/p&gt;

&lt;p&gt;với \(H(x) = \text{diag}(h(x))\) và \(U = \text{diag}(u)\). Hệ tuyến tính này xác định đồng thời hướng cập nhật \((\Delta x, \Delta u, \Delta v)\) cho cả biến gốc lẫn biến đối ngẫu theo phiên bản tìm nghiệm (root-finding) của phương pháp Newton.&lt;/p&gt;

&lt;h3 id=&quot;-các-phần-dư-và-khoảng-cách-đối-ngẫu-thay-thế&quot;&gt;📊 &lt;strong&gt;Các phần dư và khoảng cách đối ngẫu thay thế&lt;/strong&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư đối ngẫu:&lt;/strong&gt; \(r_{\text{dual}} = \nabla f(x) + \nabla h(x)u + A^T v\) (\(r_{\text{dual}} = 0\) ứng với khả thi đối ngẫu).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư trung tâm:&lt;/strong&gt; \(r_{\text{cent}} = Uh(x) + \tau\mathbf{1}\) (điều kiện bù chặt bị nhiễu với tham số \(\tau\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư gốc:&lt;/strong&gt; \(r_{\text{prim}} = Ax - b\) (\(r_{\text{prim}} = 0\) ứng với khả thi gốc).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Khoảng cách đối ngẫu thay thế (Surrogate duality gap):&lt;/strong&gt;
\(\eta = -h(x)^T u \quad \text{với} \quad h(x) \le 0, \ u \ge 0\)&lt;/p&gt;

&lt;p&gt;Khi điểm lặp đồng thời khả thi gốc và đối ngẫu (\(r_{\text{prim}} = 0, r_{\text{dual}} = 0\)), khoảng cách đối ngẫu thay thế trùng với khoảng cách đối ngẫu thực sự \(m\tau = m/t\), với \(t = -\frac{m}{h(x)^T u}\).&lt;/p&gt;

&lt;h3 id=&quot;-thuật-toán-gốc-đối-ngẫu-và-tìm-kiếm-theo-đường-lui-nhiều-giai-đoạn&quot;&gt;🔄 &lt;strong&gt;Thuật toán gốc-đối ngẫu và tìm kiếm theo đường lui nhiều giai đoạn&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Đặt \(\tau(x,u) = -\frac{h(x)^T u}{m}\), chọn \(\sigma \in (0,1)\) (\(\sigma = 1/\mu\)) và khởi tạo \((x^0, u^0, v^0)\) với \(h(x^0) &amp;lt; 0, u^0 &amp;gt; 0\). Ở mỗi vòng lặp \(k\):&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Đặt \(\tau = \sigma \tau(x^k, u^k)\) và giải hệ Newton tìm \((\Delta x, \Delta u, \Delta v)\).&lt;/li&gt;
  &lt;li&gt;Tìm độ dài bước \(\theta_k\) bằng &lt;strong&gt;tìm kiếm theo đường lui nhiều giai đoạn (multi-stage backtracking line search)&lt;/strong&gt; với \(\alpha, \beta \in (0,1)\) (thường \(\alpha = 0.01, \beta = 0.5\)):
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Giai đoạn 1 (khả thi đối ngẫu):&lt;/strong&gt; \(\theta_{\max} = \min\left\{1, \min\left\{-\frac{u_i}{\Delta u_i} : \Delta u_i &amp;lt; 0\right\}\right\}\), rồi đặt \(\theta = 0.99\theta_{\max}\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Giai đoạn 2 (khả thi gốc ngặt):&lt;/strong&gt; Giảm \(\theta = \beta\theta\) cho đến khi \(h_i(x^+) &amp;lt; 0\) với mọi \(i\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Giai đoạn 3 (giảm chuẩn phần dư):&lt;/strong&gt; Tiếp tục giảm \(\theta = \beta\theta\) cho đến khi \(\|r(x^+, u^+, v^+)\| \le (1 - \alpha\theta)\|r(x, u, v)\|\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Cập nhật \((x^{k+1}, u^{k+1}, v^{k+1}) = (x^k, u^k, v^k) + \theta_k(\Delta x, \Delta u, \Delta v)\).&lt;/li&gt;
  &lt;li&gt;Dừng khi \(-h(x)^T u \le \epsilon\) và \(\lVert r_{\text{prim}} \rVert^2 + \lVert r_{\text{dual}} \rVert^2 \le \epsilon^2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-trường-hợp-đặc-biệt-lp-và-sdp&quot;&gt;📈 &lt;strong&gt;Trường hợp đặc biệt: LP và SDP&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;quy-hoạch-tuyến-tính-lp&quot;&gt;&lt;strong&gt;Quy hoạch tuyến tính (LP)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện đường trung tâm:&lt;/strong&gt; \(A^T y + s = c\), \(Ax = b\), \(XS\mathbf{1} = \tau\mathbf{1}\), \(x, s &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ Newton:&lt;/strong&gt;
\(\begin{bmatrix}
0 &amp;amp; A^T &amp;amp; I \\
A &amp;amp; 0 &amp;amp; 0 \\
S &amp;amp; 0 &amp;amp; X
\end{bmatrix}
\begin{bmatrix}
\Delta x \\
\Delta y \\
\Delta s
\end{bmatrix} = -\begin{bmatrix}
A^T y + s - c \\
Ax - b \\
XS\mathbf{1} - \tau\mathbf{1}
\end{bmatrix}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;quy-hoạch-bán-xác-định-sdp&quot;&gt;&lt;strong&gt;Quy hoạch bán xác định (SDP)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện đường trung tâm:&lt;/strong&gt; \(\mathcal{A}^*(y) + S = C\), \(\mathcal{A}(X) = b\), \(XS = \tau I\), \(X, S \succ 0\) (với tích vô hướng \(X \bullet S = \text{tr}(XS)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ Newton:&lt;/strong&gt;
\(\begin{bmatrix}
0 &amp;amp; \mathcal{A}^* &amp;amp; I \\
\mathcal{A} &amp;amp; 0 &amp;amp; 0 \\
S &amp;amp; 0 &amp;amp; X
\end{bmatrix}
\begin{bmatrix}
\Delta X \\
\Delta y \\
\Delta S
\end{bmatrix} = -\begin{bmatrix}
\mathcal{A}^*(y) + S - C \\
\mathcal{A}(X) - b \\
XS - \tau I
\end{bmatrix}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-so-sánh-phương-pháp-chắn-và-phương-pháp-gốc-đối-ngẫu&quot;&gt;🔄 &lt;strong&gt;So sánh phương pháp chắn và phương pháp gốc-đối ngẫu&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;strong&gt;Tiêu chí&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Phương pháp chắn (Barrier)&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Phương pháp gốc-đối ngẫu (Primal-Dual)&lt;/strong&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Số bước Newton&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Nhiều bước cho mỗi pha định tâm&lt;/td&gt;
      &lt;td&gt;Một bước ở mỗi vòng lặp&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tính khả thi trung gian&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Phải luôn duy trì khả thi&lt;/td&gt;
      &lt;td&gt;Cho phép khởi tạo không khả thi (\(Ax^0 \neq b\))&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Biến cập nhật&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Chỉ biến gốc&lt;/td&gt;
      &lt;td&gt;Cập nhật đồng thời cả gốc và đối ngẫu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tốc độ hội tụ&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tuyến tính (vòng ngoài)&lt;/td&gt;
      &lt;td&gt;Thường đạt siêu tuyến tính dưới điều kiện thích hợp&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Độ phức tạp (LP)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đa thức&lt;/td&gt;
      &lt;td&gt;\(O(\sqrt{n}\log(1/\epsilon))\) vòng lặp, tổng \(O(n^{3.5}\log(1/\epsilon))\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-lưu-ý-thực-hành-và-mở-rộng&quot;&gt;🛠️ &lt;strong&gt;Lưu ý thực hành và mở rộng&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dự báo – hiệu chỉnh Mehrotra (Predictor-Corrector):&lt;/strong&gt; Kết hợp bước dự báo affine (\(\mu = 0\)) để giảm nhanh khoảng cách đối ngẫu với bước hiệu chỉnh dùng tham số \(\sigma\) thích nghi để giữ gần đường trung tâm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhúng đồng nhất tự đối ngẫu (Homogeneous self-dual):&lt;/strong&gt; Cho phép phát hiện đồng thời tính không khả thi và không bị chặn mà không cần điểm khởi tạo khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải hệ tuyến tính:&lt;/strong&gt; Sử dụng phân rã ma trận thưa (chẳng hạn phân rã LDL thưa cho hệ khối đối xứng rút gọn), theo dõi số điều kiện và điều chuẩn khi cần.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra kiến thức về phương pháp điểm trong gốc-đối ngẫu, bao gồm phương trình đường trung tâm, hệ Newton, phần dư, khoảng cách đối ngẫu thay thế và quy hoạch bán xác định (SDP).&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;⚡ Bài tập trắc nghiệm: Phương pháp điểm trong gốc-đối ngẫu&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 4%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;25&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: Primal-dual vs barrier method --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Phương pháp điểm trong gốc-đối ngẫu khác phương pháp chắn ở điểm nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Cập nhật đồng thời cả biến gốc và biến đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Chỉ thực hiện một bước Newton ở mỗi vòng lặp&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Không yêu cầu điểm khởi tạo phải thỏa mãn ràng buộc đẳng thức khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Tất cả các điểm trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các điểm trên&lt;/strong&gt;&lt;br /&gt;
                Phương pháp gốc-đối ngẫu cập nhật đồng thời biến gốc và đối ngẫu, thường chỉ cần một bước Newton mỗi vòng lặp và cho phép khởi tạo không khả thi ($$Ax^0 \neq b$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Central path equations --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Hệ phương trình đường trung tâm cho bài toán có ràng buộc bất đẳng thức $$g_i(x) \leq 0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) $$\nabla f(x) + \sum \lambda_i \nabla g_i(x) = 0, \ \lambda_i g_i(x) = -\frac{1}{t}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) $$\nabla f(x) + \sum \lambda_i \nabla g_i(x) = 0, \ \lambda_i g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) $$\nabla f(x) = 0, \ g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) $$\lambda_i = \frac{1}{t}, \ g_i(x) = -1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\nabla f(x) + \sum \lambda_i \nabla g_i(x) = 0, \ \lambda_i g_i(x) = -\frac{1}{t}$$&lt;/strong&gt;&lt;br /&gt;
                Phương trình đường trung tâm gồm điều kiện dừng và điều kiện bù chặt bị nhiễu theo tham số $$t$$ (hay $$\tau = 1/t$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Newton system --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Hệ phương trình Newton trong phương pháp gốc-đối ngẫu được giải để tìm đại lượng nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) $$(\Delta x, \Delta \lambda, \Delta \nu)$$ — hướng cập nhật cho cả biến gốc và biến đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Chỉ $$\Delta x$$ — hướng cập nhật biến gốc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Chỉ $$\Delta \lambda$$ — hướng cập nhật biến đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Tham số $$t$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$(\Delta x, \Delta \lambda, \Delta \nu)$$ — hướng cập nhật cho cả biến gốc và biến đối ngẫu&lt;/strong&gt;&lt;br /&gt;
                Hệ Newton giải đồng thời hướng cập nhật biến gốc $$\Delta x$$ và các hướng cập nhật biến đối ngẫu $$\Delta \lambda, \Delta \nu$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Surrogate duality gap --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Khoảng cách đối ngẫu thay thế (surrogate duality gap) trong phương pháp gốc-đối ngẫu là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$\eta = -\sum_{i=1}^m \lambda_i g_i(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) \(\eta = f(x) - g(\lambda, \nu)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) \(\eta = \|\nabla f(x)\|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) \(\eta = \sum_{i=1}^m |\lambda_i|\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\eta = -\sum_{i=1}^m \lambda_i g_i(x)$$&lt;/strong&gt;&lt;br /&gt;
                Khoảng cách đối ngẫu thay thế ước lượng độ chênh lệch đối ngẫu trực tiếp từ điểm gốc-đối ngẫu hiện tại mà không cần đánh giá hàm đối ngẫu hay yêu cầu điểm lặp khả thi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Residuals --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Ba thành phần phần dư (residuals) trong phương pháp gốc-đối ngẫu gồm:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Phần dư đối ngẫu, phần dư gốc và phần dư trung tâm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Chỉ phần dư đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Chỉ phần dư gốc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Chỉ phần dư trung tâm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Phần dư đối ngẫu, phần dư gốc và phần dư trung tâm&lt;/strong&gt;&lt;br /&gt;
                Ba thành phần phần dư tương ứng với điều kiện dừng (đối ngẫu), điều kiện khả thi đẳng thức (gốc) và điều kiện bù chặt bị nhiễu (trung tâm).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Predictor-corrector --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Trong phương pháp dự báo – hiệu chỉnh (predictor-corrector):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) Bước dự báo giảm khoảng cách đối ngẫu, bước hiệu chỉnh cải thiện độ gần đường trung tâm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) Bước dự báo tăng tính khả thi, bước hiệu chỉnh giảm khoảng cách đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) Chỉ có bước dự báo&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Chỉ có bước hiệu chỉnh&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Bước dự báo giảm khoảng cách đối ngẫu, bước hiệu chỉnh cải thiện độ gần đường trung tâm&lt;/strong&gt;&lt;br /&gt;
                Bước dự báo (affine) tiến mạnh về phía nghiệm tối ưu để giảm khoảng cách đối ngẫu, còn bước hiệu chỉnh kéo điểm lặp trở lại gần đường trung tâm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Mehrotra&apos;s algorithm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Thuật toán dự báo – hiệu chỉnh Mehrotra là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Thuật toán gốc-đối ngẫu thực tế với tham số định tâm thích nghi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Phương pháp Newton thuần túy&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Biến thể của phương pháp chắn thuần gốc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Phương pháp bậc nhất&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Thuật toán gốc-đối ngẫu thực tế với tham số định tâm thích nghi&lt;/strong&gt;&lt;br /&gt;
                Thuật toán Mehrotra là biến thể gốc-đối ngẫu được sử dụng rộng rãi nhờ cách chọn tham số định tâm $$\sigma$$ thích nghi dựa trên chất lượng bước dự báo.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Infeasible start --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Phương pháp gốc-đối ngẫu có thể bắt đầu từ điểm không khả thi nhờ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) Tìm kiếm theo đường lui (backtracking line search) làm giảm chuẩn phần dư về 0&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) Bỏ qua các ràng buộc khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Chiếu trực tiếp lên tập khả thi ở mỗi bước&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) Không thể bắt đầu từ điểm không khả thi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Tìm kiếm theo đường lui (backtracking line search) làm giảm chuẩn phần dư về 0&lt;/strong&gt;&lt;br /&gt;
                Tìm kiếm theo đường lui nhiều giai đoạn vừa giữ điểm lặp trong miền $$h(x) &amp;lt; 0, u &amp;gt; 0$$ vừa đảm bảo chuẩn phần dư tổng hợp (gồm cả phần dư khả thi) giảm dần về $$0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: SDP primal problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Bài toán gốc của quy hoạch bán xác định (SDP) có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(\min C \bullet X\) thỏa mãn \(A_i \bullet X = b_i, \ X \succeq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(\min c^T x\) thỏa mãn \(Ax = b, \ x \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(\min \frac{1}{2}x^T Q x\) thỏa mãn \(Ax \leq b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(\min f(x)\) thỏa mãn \(g_i(x) \leq 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\min C \bullet X$$ thỏa mãn $$A_i \bullet X = b_i, \ X \succeq 0$$&lt;/strong&gt;&lt;br /&gt;
                SDP cực tiểu hóa hàm tuyến tính trên biến ma trận đối xứng với các ràng buộc đẳng thức tuyến tính và ràng buộc nửa xác định dương $$X \succeq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: SDP dual --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Bài toán đối ngẫu của SDP có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(\max b^T y\) thỏa mãn \(\sum y_i A_i + S = C, \ S \succeq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(\min b^T y\) thỏa mãn \(A^T y \leq c\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(\max c^T z\) thỏa mãn \(A^T z = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(\min \|y\|^2\) thỏa mãn \(Ay = b\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max b^T y$$ thỏa mãn $$\sum y_i A_i + S = C, \ S \succeq 0$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán đối ngẫu của SDP cực đại hóa $$b^T y$$ với ma trận bù đối ngẫu nửa xác định dương $$S \succeq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: SDP complementary slackness --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Điều kiện bù chặt trong SDP là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(X \bullet S = 0\) (tức \(\text{tr}(XS) = 0\))&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(X \bullet S = 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(X + S = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(\|X - S\| = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$X \bullet S = 0$$ (tức $$\text{tr}(XS) = 0$$)&lt;/strong&gt;&lt;br /&gt;
                Điều kiện bù chặt của SDP yêu cầu tích vô hướng vết giữa ma trận gốc và ma trận đối ngẫu bằng $$0$$ (với $$X, S \succeq 0$$, điều này tương đương với $$XS = 0$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Central path for SDP --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Điều kiện đường trung tâm cho SDP là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) \(XS = \frac{1}{t}I\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) \(X \bullet S = \frac{n}{t}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) \(XS = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) \(X = S\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$XS = \frac{1}{t}I$$&lt;/strong&gt;&lt;br /&gt;
                Trên đường trung tâm của SDP, tích ma trận $$XS$$ bằng bội số của ma trận đơn vị: $$XS = \tau I = \frac{1}{t}I$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Newton direction for SDP --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Hướng Newton trong phương pháp gốc-đối ngẫu cho SDP được tìm bằng cách giải:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Hệ phương trình tuyến tính hóa theo \((\Delta X, \Delta y, \Delta S)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Chỉ theo \(\Delta X\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Chỉ theo \(\Delta S\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Bài toán phân rã trị riêng&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Hệ phương trình tuyến tính hóa theo $$(\Delta X, \Delta y, \Delta S)$$&lt;/strong&gt;&lt;br /&gt;
                Hệ Newton cho SDP giải đồng thời bước cập nhật ma trận gốc $$\Delta X$$, vector đối ngẫu $$\Delta y$$ và ma trận đối ngẫu $$\Delta S$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Polynomial complexity --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Độ phức tạp tính toán trong trường hợp xấu nhất của phương pháp điểm trong gốc-đối ngẫu là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Thời gian đa thức (polynomial-time)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Thời gian hàm mũ (exponential-time)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Thuộc lớp NP-hard&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Không có đảm bảo lý thuyết&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Thời gian đa thức (polynomial-time)&lt;/strong&gt;&lt;br /&gt;
                Các phương pháp điểm trong có độ phức tạp thời gian đa thức trong trường hợp xấu nhất cho LP, SOCP và SDP.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Warm start --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Khởi động ấm (warm start) trong phương pháp gốc-đối ngẫu có nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Khởi tạo từ nghiệm của một bài toán tương tự đã giải trước đó&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Luôn bắt đầu từ gốc tọa độ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Bắt đầu từ một điểm ngẫu nhiên&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Bắt đầu từ biên của tập khả thi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Khởi tạo từ nghiệm của một bài toán tương tự đã giải trước đó&lt;/strong&gt;&lt;br /&gt;
                Khởi động ấm tận dụng nghiệm của bài toán liên quan làm điểm khởi đầu nhằm rút ngắn số vòng lặp hội tụ.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Homogeneous self-dual --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Dạng nhúng đồng nhất tự đối ngẫu (homogeneous self-dual) có ưu điểm nào sau đây?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Phát hiện được cả trường hợp bài toán không khả thi và không bị chặn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Không cần tìm điểm khởi tạo khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Xử lý thống nhất mọi trạng thái nghiệm trong cùng một khuôn khổ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Tất cả các ưu điểm trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các ưu điểm trên&lt;/strong&gt;&lt;br /&gt;
                Dạng đồng nhất tự đối ngẫu xử lý thống nhất cả ba trường hợp (có nghiệm tối ưu, không khả thi, không bị chặn) mà không cần pha tìm điểm khả thi ban đầu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Centering parameter --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Tham số định tâm (centering parameter) \(\sigma\) trong phương pháp gốc-đối ngẫu có vai trò:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Cân bằng giữa việc bám sát đường trung tâm và tốc độ tiến về nghiệm tối ưu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Luôn được cố định bằng 0&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Luôn được cố định bằng 1&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Không ảnh hưởng đến thuật toán&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Cân bằng giữa việc bám sát đường trung tâm và tốc độ tiến về nghiệm tối ưu&lt;/strong&gt;&lt;br /&gt;
                Với $$\sigma \in [0, 1]$$, $$\sigma = 0$$ tương ứng với bước affine thuần túy (tiến nhanh nhất), còn $$\sigma = 1$$ tương ứng với bước định tâm thuần túy.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Linear programming special case --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Với bài toán LP, phương pháp điểm trong gốc-đối ngẫu có đặc điểm nào sau đây?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Hệ phương trình Newton có cấu trúc tuyến tính thưa đơn giản&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Điều kiện bù chặt bị nhiễu có dạng \(x_i s_i = \frac{1}{t}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Cho phép cài đặt với hiệu năng tính toán rất cao&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Tất cả các đặc điểm trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các đặc điểm trên&lt;/strong&gt;&lt;br /&gt;
                LP là trường hợp đặc biệt có cấu trúc đơn giản, giúp phương pháp điểm trong gốc-đối ngẫu đạt hiệu quả rất cao trong thực tế.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Convergence rate --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Tốc độ hội tụ của phương pháp điểm trong gốc-đối ngẫu là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Siêu tuyến tính dưới các điều kiện không suy biến phù hợp&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Luôn chỉ tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Luôn bậc hai ở mọi vòng lặp&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Dưới tuyến tính (sublinear)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Siêu tuyến tính dưới các điều kiện không suy biến phù hợp&lt;/strong&gt;&lt;br /&gt;
                Dưới các giả thiết không suy biến thích hợp, phương pháp điểm trong gốc-đối ngẫu đạt tốc độ hội tụ siêu tuyến tính (thậm chí tiệm cận bậc hai).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Modern applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Phương pháp điểm trong gốc-đối ngẫu được ứng dụng rộng rãi trong:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Các bộ giải tối ưu thương mại và mã nguồn mở&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Quy hoạch tuyến tính và quy hoạch bán xác định quy mô lớn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Các bài toán tối ưu trong học máy&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các ứng dụng trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các ứng dụng trên&lt;/strong&gt;&lt;br /&gt;
                Phương pháp điểm trong gốc-đối ngẫu là thuật toán lõi của nhiều bộ giải hiện đại (như CPLEX, Gurobi, MOSEK, Clarabel) dùng trong công nghiệp và học máy.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Phương pháp điểm trong gốc-đối ngẫu kết hợp hai ý tưởng nền tảng nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Hàm chắn (đường trung tâm) và phương pháp Newton&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Hạ gradient và động lượng (momentum)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Đơn hình gốc và đơn hình đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) SGD và Adam&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Hàm chắn (đường trung tâm) và phương pháp Newton&lt;/strong&gt;&lt;br /&gt;
                Phương pháp điểm trong gốc-đối ngẫu dùng hệ KKT bị nhiễu từ hàm chắn kết hợp với phương pháp Newton để cập nhật đồng thời biến gốc và biến đối ngẫu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Trong phương pháp điểm trong gốc-đối ngẫu, hệ phương trình Newton rút gọn (sau khi khử \(\Delta \lambda\)) có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Ma trận khối đối xứng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Ma trận tam giác&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Ma trận đường chéo&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Ma trận đơn vị&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Ma trận khối đối xứng&lt;/strong&gt;&lt;br /&gt;
                Sau khi khử $$\Delta \lambda$$, hệ KKT trở thành hệ ma trận khối đối xứng (augmented system) thuận lợi cho phân rã LDL; hệ Newton đầy đủ ban đầu nhìn chung không đối xứng.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Cách tiếp cận dự báo – hiệu chỉnh (predictor-corrector) trong IPM thực hiện:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Dự báo hướng tiến về nghiệm và hiệu chỉnh độ gần đường trung tâm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Chỉ thực hiện bước dự báo&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Chỉ thực hiện bước hiệu chỉnh&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Không liên quan đến đường trung tâm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Dự báo hướng tiến về nghiệm và hiệu chỉnh độ gần đường trung tâm&lt;/strong&gt;&lt;br /&gt;
                Bước dự báo tìm hướng giảm nhanh khoảng cách đối ngẫu, còn bước hiệu chỉnh đảm bảo điểm lặp không lệch quá xa đường trung tâm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Độ phức tạp tính toán tổng thể của phương pháp điểm trong cho LP là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$O(n^{3.5} \log(1/\epsilon))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$O(2^n)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$O(n!)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) $$O(n \log n)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$O(n^{3.5} \log(1/\epsilon))$$&lt;/strong&gt;&lt;br /&gt;
                Thuật toán cần $$O(\sqrt{n}\log(1/\epsilon))$$ vòng lặp, mỗi vòng lặp tốn $$O(n^3)$$ phép toán phân rã ma trận, cho tổng độ phức tạp $$O(n^{3.5} \log(1/\epsilon))$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Thuật toán Mehrotra thuộc lớp thuật toán nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Phương pháp điểm trong gốc-đối ngẫu dự báo – hiệu chỉnh thực tế&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Phương pháp đơn hình (Simplex)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Hạ gradient (Gradient descent)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Nhánh và cận (Branch and bound)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Phương pháp điểm trong gốc-đối ngẫu dự báo – hiệu chỉnh thực tế&lt;/strong&gt;&lt;br /&gt;
                Thuật toán dự báo – hiệu chỉnh của Mehrotra là một trong những cài đặt thực tế phổ biến nhất của phương pháp điểm trong gốc-đối ngẫu.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành Quiz!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;d&apos;, q2: &apos;a&apos;, q3: &apos;a&apos;, q4: &apos;a&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;a&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;d&apos;, q17: &apos;a&apos;, q18: &apos;d&apos;, q19: &apos;a&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã thành thạo primal-dual interior point methods!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu tốt về central path và SDP.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại Newton systems và residuals.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Ôn lại primal-dual algorithms và complementary slackness.&apos;;
    } else {
        message = &apos;📖 Hãy học lại từ đầu về primal-dual methods nhé!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>17-05 Điều kiện tối ưu cho quy hoạch bán xác định (SDP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_05_optimality_conditions_for_semidefinite_programming/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_05_optimality_conditions_for_semidefinite_programming</id>
   <content type="html">&lt;p&gt;Nếu quy hoạch tuyến tính tối ưu trên góc phần tư không âm \(x \ge 0\) của các vector, thì &lt;strong&gt;quy hoạch bán xác định (SDP)&lt;/strong&gt; nâng toàn bộ câu chuyện đó lên một chiều không gian hoàn toàn mới: góc nón các ma trận đối xứng nửa xác định dương \(X \succeq 0\). Điều kỳ diệu là hầu hết công thức đẹp đẽ của LP đều dịch chuyển sang SDP một cách tự nhiên — tích vô hướng vector trở thành tích vết \(\operatorname{tr}(CX)\), điều kiện bù chặt \(x_i s_i = 0\) trở thành tích ma trận \(XS = 0\) — nhưng có một “cạm bẫy” đại số tinh tế xuất hiện: tích hai ma trận đối xứng \(X\) và \(S\) nhìn chung &lt;strong&gt;không còn đối xứng&lt;/strong&gt; nữa!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-mở-rộng-pd-ipm-từ-vector-sang-không-gian-ma-trận-đối-xứng&quot;&gt;Kiến thức cần nhớ: Mở rộng PD-IPM từ vector sang không gian ma trận đối xứng&lt;/h2&gt;

&lt;p&gt;Để không bị choáng ngợp trước các ký hiệu toán tử \(\mathcal{A}, \mathcal{A}^*\) và điều kiện \(XS = \tau I\), hãy nắm vững bốn trụ cột nền tảng của SDP:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không gian ma trận đối xứng \(\mathbb{S}^n\) và tích vô hướng vết:&lt;/strong&gt; Trang bị tích vô hướng \(\langle C, X \rangle = \operatorname{tr}(CX) = \sum_{i,j} C_{ij} X_{ij}\) biến \(\mathbb{S}^n\) thành một không gian Euclid thực thụ, nơi các ràng buộc \(\operatorname{tr}(A_i X) = b_i\) đóng vai trò các siêu phẳng tuyến tính.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nón nửa xác định dương \(\mathbb{S}_+^n\) và tính tự đối ngẫu:&lt;/strong&gt; Ma trận \(X \succeq 0\) nghĩa là mọi trị riêng của \(X\) đều không âm. Nón \(\mathbb{S}_+^n\) là nón lồi đóng và &lt;strong&gt;tự đối ngẫu&lt;/strong&gt; (\(\operatorname{tr}(XS) \ge 0\) với mọi \(X, S \succeq 0\)), khiến cặp bài toán SDP gốc–đối ngẫu đối xứng hoàn toàn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù chặt ma trận \(XS = 0\):&lt;/strong&gt; Với \(X, S \succeq 0\), điều kiện \(\operatorname{tr}(XS) = 0\) tương đương với \(XS = 0\). Điều này có nghĩa là \(X\) và \(S\) giao hoán và có thể đồng thời chéo hóa: ở hướng nào \(X\) có trị riêng dương thì \(S\) bắt buộc có trị riêng bằng \(0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đường trung tâm \(XS = \tau I\) và bài toán đối xứng hóa hướng Newton:&lt;/strong&gt; Khi tuyến tính hóa \(XS = \tau I\), ta thu được \(X\Delta S + \Delta X S = \tau I - XS\). Vì vế trái không tự động đối xứng ngay cả khi \(\Delta X, \Delta S \in \mathbb{S}^n\), các bộ giải SDP phải dùng các phép đối xứng hóa (như hướng AHO, HKM hay Nesterov–Todd) để hệ phương trình vuông và giải được duy nhất.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-đường-trung-tâm-sdp-2-times-2-với-xs--tau-i&quot;&gt;Giải thích: Tính tay đường trung tâm SDP \(2 \times 2\) với \(XS = \tau I\)&lt;/h3&gt;

&lt;p&gt;Xét bài toán SDP trên không gian ma trận đối xứng \(2 \times 2\):&lt;/p&gt;

\[\min_{X \in \mathbb{S}^2} \; \operatorname{tr}(CX) \qquad \text{với điều kiện} \qquad \operatorname{tr}(X) = 2, \; X \succeq 0, \qquad C = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 3 \end{bmatrix}.\]

&lt;p&gt;Bài toán đối ngẫu tương ứng là \(\max_{y \in \mathbb{R}} \; 2y\) với điều kiện \(S = C - yI = \begin{bmatrix} 1 - y &amp;amp; 0 \\ 0 &amp;amp; 3 - y \end{bmatrix} \succeq 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nghiệm tối ưu KKT (\(\tau = 0\)):&lt;/strong&gt; Điều kiện \(S \succeq 0\) đòi hỏi \(1 - y \ge 0\) và \(3 - y \ge 0 \implies y \le 1\). Do đó \(y^\star = 1\), \(S^\star = \operatorname{diag}(0, 2)\). Để \(\operatorname{tr}(X^\star) = 2\) và \(X^\star S^\star = 0\), ta buộc phải có \(X^\star = \operatorname{diag}(2, 0)\). Kiểm tra giá trị tối ưu: \(\operatorname{tr}(CX^\star) = 1(2) + 3(0) = 2 = 2y^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm trên đường trung tâm tại \(\tau = 0.2\):&lt;/strong&gt; Ta cần \(X, S \succ 0\) đường chéo \(X = \operatorname{diag}(x_1, x_2)\), \(S = \operatorname{diag}(1-y, 3-y)\) thỏa mãn \(XS = 0.2 I\) và \(x_1 + x_2 = 2\):
\(x_1 = \frac{0.2}{1 - y}, \qquad x_2 = \frac{0.2}{3 - y} \implies \frac{0.2}{1 - y} + \frac{0.2}{3 - y} = 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải phương trình bậc hai cho \(y\):&lt;/strong&gt; Rút gọn cho \(y^2 - 3.8y + 2.6 = 0\). Lấy nghiệm thỏa mãn \(y &amp;lt; 1\) (để \(S \succ 0\)):
\(y(0.2) = \frac{3.8 - \sqrt{3.8^2 - 4(2.6)}}{2} = \frac{3.8 - \sqrt{4.04}}{2} \approx 0.8950.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra cặp ma trận đường trung tâm:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(S(0.2) \approx \operatorname{diag}(0.1050, \; 2.1050) \succ 0\).&lt;/li&gt;
      &lt;li&gt;\(X(0.2) \approx \operatorname{diag}(1.9048, \; 0.0950) \succ 0\) (tổng vết \(= 1.9998 \approx 2\)).&lt;/li&gt;
      &lt;li&gt;Khoảng cách đối ngẫu: \(\operatorname{tr}(X(0.2)S(0.2)) = 2 \times 0.2 = 0.4 = n\tau\), đúng bằng công thức tổng quát cho ma trận cỡ \(n \times n\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong phần này, chúng ta xét phương pháp điểm trong gốc-đối ngẫu áp dụng cho bài toán quy hoạch bán xác định (SDP — semidefinite programming).&lt;/p&gt;

&lt;h2 id=&quot;quy-hoạch-bán-xác-định-sdp&quot;&gt;Quy hoạch bán xác định (SDP)&lt;/h2&gt;
&lt;p&gt;Bài toán SDP gốc được phát biểu như sau:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{X} &amp;amp;&amp;amp; {C \cdot X} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {A_i \cdot X = b_i, i = 1,...,m} \\\\
   &amp;amp; &amp;amp;&amp;amp;{X \succeq 0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán SDP đối ngẫu tương ứng là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\max_{y} &amp;amp;&amp;amp; {b^Ty} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {\sum^m_{i=1} y_iA_i + S = C} \\\\
   &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nhắc lại rằng tích vô hướng vết (trace inner product) trên không gian ma trận đối xứng \(\mathbb{S}^n\) được định nghĩa là:&lt;/p&gt;
&lt;blockquote&gt;
\[X \cdot S = \text{trace}(XS)\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;điều-kiện-tối-ưu-cho-sdp&quot;&gt;Điều kiện tối ưu cho SDP&lt;/h2&gt;
&lt;p&gt;Cặp bài toán SDP gốc và đối ngẫu có thể được viết gọn bằng toán tử tuyến tính \(\mathcal{A}: \mathbb{S}^n \to \mathbb{R}^m\) và toán tử liên hợp \(\mathcal{A}^*\) của nó:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{X} &amp;amp;&amp;amp; {C \cdot X} &amp;amp; \qquad \qquad \qquad &amp;amp; \max_{y,S}  &amp;amp;&amp;amp; {b^Ty} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {\mathcal{A}(X) = b} &amp;amp; \qquad \qquad \qquad &amp;amp; \text{subject to } &amp;amp;&amp;amp; {\mathcal{A}^{*}(y) + S = C} \\\\
   &amp;amp; &amp;amp;&amp;amp;{X \succeq 0} &amp;amp; \qquad \qquad \qquad &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Giả sử tính đối ngẫu mạnh được thỏa mãn, thì \(X^{\star}\) và \((y^{\star}, S^{\star})\) là cặp nghiệm tối ưu gốc – đối ngẫu khi và chỉ khi \((X^{\star}, y^{\star}, S^{\star})\) thỏa mãn hệ điều kiện sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{array}{rcl}
\mathcal{A}^*(y) + S &amp;amp; = &amp;amp; C \\\
\mathcal{A}(X) &amp;amp; = &amp;amp; b \\\
XS &amp;amp; = &amp;amp; 0 \\\
X,S &amp;amp; \succeq &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;đường-trung-tâm-cho-sdp&quot;&gt;Đường trung tâm cho SDP&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Bài toán chắn gốc&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{X} &amp;amp;&amp;amp; {C \cdot X - \tau \log\det(X)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {\mathcal{A}(X) = b} 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bài toán chắn đối ngẫu&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\max_{y, S} &amp;amp;&amp;amp; {b^Ty + \tau \log\det(S)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {\mathcal{A}^*(y) + S = C} 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện tối ưu cho các bài toán chắn gốc và đối ngẫu&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
\mathcal{A}^*(y) + S &amp;amp; = &amp;amp; C \\\
\mathcal{A}(X) &amp;amp; = &amp;amp; b \\\
XS &amp;amp; = &amp;amp; \tau I \\\
X,S &amp;amp; \succ &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;bước-newton&quot;&gt;Bước Newton&lt;/h2&gt;
&lt;p&gt;Hệ phương trình đường trung tâm gốc:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
\mathcal{A}^*(y) + \tau X^{-1} &amp;amp; = &amp;amp; C \\\
\mathcal{A}(X) &amp;amp; = &amp;amp; b \\\
X &amp;amp; \succ &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Phương trình Newton tương ứng (sử dụng vi phân \(d(X^{-1}) = -X^{-1} \Delta X X^{-1}\)):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(-\tau X^{-1}\Delta X X^{-1} +\mathcal{A}^*(\Delta y) = -(\mathcal{A}^*(y) + \tau X^{-1} -C)\)
\(\mathcal{A}(\Delta X) = -(\mathcal{A}(X)-b)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hệ phương trình đường trung tâm và phương trình Newton cho bài toán đối ngẫu theo \((y, S)\) được xây dựng hoàn toàn tương tự.&lt;/p&gt;

&lt;h2 id=&quot;bước-newton-gốc-đối-ngẫu&quot;&gt;Bước Newton gốc-đối ngẫu&lt;/h2&gt;
&lt;p&gt;Hệ phương trình đường trung tâm gốc-đối ngẫu:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{bmatrix}
\mathcal{A}^*(y) + S - C  \\\
\mathcal{A}(X) - b \\\
XS
\end{bmatrix} =
\begin{bmatrix}
0 \\\
0 \\\
\tau I
\end{bmatrix}
, \quad X, S \succ 0\]
&lt;/blockquote&gt;

&lt;p&gt;Hệ bước Newton:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{bmatrix}
0 &amp;amp; \mathcal{A}^* &amp;amp; I \\\
\mathcal{A} &amp;amp; 0 &amp;amp; 0 \\\
S &amp;amp; 0 &amp;amp; X 
\end{bmatrix}
\begin{bmatrix}
\Delta X \\\
\Delta y \\\
\Delta S
\end{bmatrix}= -
\begin{bmatrix}
\mathcal{A}^*(y) + S - C \\\
\mathcal{A}(X) - b \\\
XS - \tau I 
\end{bmatrix}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>17-04 Trường hợp đặc biệt: quy hoạch tuyến tính</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_04_special_case_linear_programming/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_04_special_case_linear_programming</id>
   <content type="html">&lt;p&gt;Trong toàn bộ thế giới tối ưu hóa, quy hoạch tuyến tính (LP) là nơi phương pháp điểm trong gốc–đối ngẫu phô diễn vẻ đẹp đại số thuần khiết nhất. Vì hàm mục tiêu tuyến tính có Hessian bằng không (\(\nabla^2 f(x) = 0\)) và ràng buộc bất đẳng thức chỉ đơn giản là \(x \ge 0\), hệ phương trình Newton khổng lồ với \(2n + m\) ẩn số có thể được khử gọn thành một hệ phương trình đối xứng xác định dương kích thước chỉ \(m \times m\) — gọi là &lt;strong&gt;hệ phương trình chuẩn (normal equations)&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-lp-dạng-chuẩn-đến-hệ-phương-trình-chuẩn-ad2at&quot;&gt;Kiến thức cần nhớ: Từ LP dạng chuẩn đến hệ phương trình chuẩn \(AD^2A^T\)&lt;/h2&gt;

&lt;p&gt;Bốn ý tưởng cốt lõi dưới đây cho thấy vì sao giải LP bằng PD-IPM lại vừa gọn gàng vừa cực nhanh:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu LP dạng chuẩn và biến bù \(s\):&lt;/strong&gt; Viết bài toán gốc \(\min c^T x \text{ s.t. } Ax = b, x \ge 0\) song song với bài toán đối ngẫu \(\max b^T y \text{ s.t. } A^T y + s = c, s \ge 0\) giúp điều kiện bù chặt có dạng cực kỳ đối xứng \(x_i s_i = 0\) (và đường trung tâm là \(XS\mathbf{1} = \tau\mathbf{1}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ tuyến tính KKT của LP:&lt;/strong&gt; Vì không có số hạng bậc hai từ \(f\) hay \(h\), ma trận Jacobi của hệ LP chỉ gồm \(A, A^T, X = \operatorname{diag}(x), S = \operatorname{diag}(s)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khử khối về hệ phương trình chuẩn:&lt;/strong&gt; Khử \(\Delta s\) rồi khử \(\Delta x\) bằng ma trận tỉ lệ đường chéo \(D^2 = X S^{-1} = \operatorname{diag}(x_i/s_i)\), ta chỉ cần giải duy nhất một hệ tuyến tính đối xứng xác định dương \((A D^2 A^T)\Delta y = \text{rhs}\) bằng phân tích Cholesky thưa!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khác biệt bản chất với phương pháp chắn trên LP:&lt;/strong&gt; Khi so sánh hai bước Newton trên cùng một điểm đường trung tâm, bước của phương pháp chắn chỉ cân nhắc đường đi của biến gốc \(x\), trong khi bước gốc–đối ngẫu tự động cân bằng cả \(x\) và \(s\) thông qua tỉ số \(x_i/s_i\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-một-bước-pd-ipm-cho-lp-bằng-hệ-phương-trình-chuẩn-ad2at&quot;&gt;Giải thích: Giải tay một bước PD-IPM cho LP bằng hệ phương trình chuẩn \(AD^2A^T\)&lt;/h3&gt;

&lt;p&gt;Xét bài toán LP 2 biến với \(m = 1\) ràng buộc đẳng thức:&lt;/p&gt;

\[\min_{x_1, x_2} \; 2x_1 + 3x_2 \qquad \text{với điều kiện} \qquad x_1 + x_2 = 1, \; x_1, x_2 \ge 0.\]

&lt;p&gt;Ở đây \(c = (2, 3)^T\), \(A = [1, \; 1]\), \(b = 1\). Nghiệm tối ưu là \(x^\star = (1, 0)^T, y^\star = 2, s^\star = (0, 1)^T\). Xét điểm trong khả thi ban đầu \(x = (0.5, 0.5)^T\), \(y = 0\), \(s = c - A^T y = (2, 3)^T\) (nên \(r_p = Ax - b = 0\) và \(r_d = A^T y + s - c = 0\)). Chọn \(\tau = 0.25\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính phần dư trung tâm:&lt;/strong&gt;
\(r_c = XS\mathbf{1} - \tau\mathbf{1} = \begin{bmatrix} (0.5)(2) - 0.25 \\ (0.5)(3) - 0.25 \end{bmatrix} = \begin{bmatrix} 0.75 \\ 1.25 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lập ma trận tỉ lệ đường chéo \(D^2 = X S^{-1}\):&lt;/strong&gt;
\(D^2 = \operatorname{diag}\!\left(\frac{0.5}{2}, \; \frac{0.5}{3}\right) = \operatorname{diag}\!\left(\frac{1}{4}, \; \frac{1}{6}\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải hệ phương trình chuẩn \(1 \times 1\) tìm \(\Delta y\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vế trái: \(A D^2 A^T = [1, 1] \begin{bmatrix} 1/4 &amp;amp; 0 \\ 0 &amp;amp; 1/6 \end{bmatrix} \begin{bmatrix} 1 \\ 1 \end{bmatrix} = \frac{1}{4} + \frac{1}{6} = \frac{5}{12}\).&lt;/li&gt;
      &lt;li&gt;Với \(r_p = 0, r_d = 0\), vế phải của hệ chuẩn là \(A S^{-1} r_c = \frac{0.75}{2} + \frac{1.25}{3} = \frac{3}{8} + \frac{5}{12} = \frac{19}{24}\).&lt;/li&gt;
      &lt;li&gt;Suy ra \(\Delta y = \frac{19/24}{5/12} = \frac{19}{10} = 1.9\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thế ngược tìm \(\Delta s\) và \(\Delta x\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\Delta s = -A^T \Delta y = (-1.9, \; -1.9)^T \implies s + \Delta s = (0.1, \; 1.1)^T &amp;gt; 0\)!&lt;/li&gt;
      &lt;li&gt;\(\Delta x = -S^{-1}(r_c + X\Delta s) = -\begin{bmatrix} (0.75 - 0.95)/2 \\ (1.25 - 0.95)/3 \end{bmatrix} = \begin{bmatrix} +0.1 \\ -0.1 \end{bmatrix} \implies x + \Delta x = (0.6, \; 0.4)^T &amp;gt; 0\)!
Kiểm tra lại: \(x_1^+ + x_2^+ = 1.0\), \(A^T y^+ + s^+ = (2, 3)^T = c\), và khoảng cách đối ngẫu \(x^T s\) sụt ngay từ \(2.5\) xuống còn \((0.6)(0.1) + (0.4)(1.1) = 0.50\) chỉ sau 1 bước duy nhất!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong phần này, chúng ta xét áp dụng phương pháp gốc-đối ngẫu cho trường hợp đặc biệt là bài toán quy hoạch tuyến tính (LP).&lt;/p&gt;

&lt;h2 id=&quot;quy-hoạch-tuyến-tính&quot;&gt;Quy hoạch tuyến tính&lt;/h2&gt;
&lt;p&gt;Xét bài toán LP gốc dạng chuẩn:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{x} &amp;amp;&amp;amp; {c^Tx} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {Ax = b} \\\\
   &amp;amp; &amp;amp;&amp;amp;{x \ge 0} \\\
\end{align}\]

\[\text{với } c \in \mathbb{R}^n, A \in \mathbb{R}^{m\times n}, b \in \mathbb{R}^m\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán đối ngẫu tương ứng là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\max_{y,s}  &amp;amp;&amp;amp; {b^Ty} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {A^Ty + s = c} \\\\
   &amp;amp; &amp;amp;&amp;amp;{s \ge 0} \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;điều-kiện-tối-ưu-và-phương-trình-đường-trung-tâm&quot;&gt;Điều kiện tối ưu và phương trình đường trung tâm&lt;/h2&gt;
&lt;p&gt;Hệ điều kiện tối ưu (KKT) cho cặp bài toán LP gốc – đối ngẫu trên là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
A^Ty + s &amp;amp; = &amp;amp; c \\\
Ax &amp;amp; = &amp;amp; b \\\
XS\mathbb{1} &amp;amp; = &amp;amp; 0 \\\
x,s  &amp;amp; \succeq &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Hệ phương trình đường trung tâm:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
A^Ty + s &amp;amp; = &amp;amp; c \\\
Ax &amp;amp; = &amp;amp; b \\\
XS\mathbb{1} &amp;amp; = &amp;amp; \tau\mathbb{1} \\\
x,s  &amp;amp; &amp;gt; &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;phương-pháp-gốc-đối-ngẫu-so-với-phương-pháp-chắn&quot;&gt;Phương pháp gốc-đối ngẫu so với phương pháp chắn&lt;/h2&gt;
&lt;h3 id=&quot;bước-newton-của-phương-pháp-gốc-đối-ngẫu&quot;&gt;Bước Newton của phương pháp gốc-đối ngẫu&lt;/h3&gt;
&lt;p&gt;Hệ phương trình Newton cho bài toán LP trong phương pháp gốc-đối ngẫu có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{bmatrix}
0 &amp;amp; A^T &amp;amp; I \\\
A &amp;amp; 0 &amp;amp; 0 \\\
S &amp;amp; 0 &amp;amp; X 
\end{bmatrix}
\begin{bmatrix}
\Delta x \\\
\Delta y \\\
\Delta s 
\end{bmatrix}= -
\begin{bmatrix}
A^Ty + s-c \\\
Ax-b \\\
XS\mathbb{1}-\tau\mathbb{1} 
\end{bmatrix}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ điều kiện bù nhiễu, ta có quan hệ tương đương:&lt;/p&gt;

\[XS\mathbb{1} = \tau \mathbb{1} \iff s = \tau X^{-1}\mathbb{1} \iff x = \tau S^{-1}\mathbb{1}\]

&lt;p&gt;Nhờ đó, ta có thể khử \(s\) để thu về hệ điều kiện tối ưu của bài toán chắn gốc, hoặc khử \(x\) để thu về hệ điều kiện tối ưu của bài toán chắn đối ngẫu.&lt;/p&gt;

&lt;h3 id=&quot;bước-newton-của-phương-pháp-chắn&quot;&gt;Bước Newton của phương pháp chắn&lt;/h3&gt;
&lt;p&gt;Hệ phương trình đường trung tâm cho bài toán chắn gốc (bên trái) và bài toán chắn đối ngẫu (bên phải):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcr}
A^Ty + \tau X^{-1}\mathbb{1} &amp;amp; = &amp;amp; c &amp;amp; \qquad \qquad &amp;amp; A^Ty + s &amp;amp; = &amp;amp; c \\\
Ax &amp;amp; = &amp;amp; b &amp;amp; \qquad \qquad &amp;amp; \tau AS^{-1}\mathbb{1} &amp;amp; = &amp;amp; b\\\
x &amp;amp; &amp;gt; &amp;amp; 0 &amp;amp; \qquad \qquad &amp;amp; s &amp;amp; &amp;gt; &amp;amp; 0
\end{array}\]

&lt;/blockquote&gt;

&lt;p&gt;Tuyến tính hóa các phương trình đường trung tâm trên, ta thu được hệ bước Newton cho bài toán gốc và bài toán đối ngẫu:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước Newton gốc&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{bmatrix}
-\tau X^{-2} &amp;amp; A^T \\\
A &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
\Delta x \\\
\Delta y
\end{bmatrix}= -
\begin{bmatrix}
A^Ty + \tau X^{-1}\mathbb{1}-c \\\
Ax-b 
\end{bmatrix}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước Newton đối ngẫu&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{bmatrix}
A^T &amp;amp; I \\\
0 &amp;amp; -\tau AS^{-2}
\end{bmatrix}
\begin{bmatrix}
\Delta y \\\
\Delta s
\end{bmatrix}= -
\begin{bmatrix}
A^Ty + s -c \\\
\tau AS^{-1}\mathbb{1}-b
\end{bmatrix}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;ví-dụ-so-sánh-phương-pháp-chắn-và-phương-pháp-gốc-đối-ngẫu&quot;&gt;Ví dụ: so sánh phương pháp chắn và phương pháp gốc-đối ngẫu&lt;/h2&gt;
&lt;h3 id=&quot;bài-toán-lp-chuẩn-n--50-m--100&quot;&gt;Bài toán LP chuẩn: \(n = 50\), \(m = 100\)&lt;/h3&gt;
&lt;p&gt;Để so sánh hiệu năng, ta xét ví dụ một bài toán LP chuẩn với \(n = 50\) biến và \(m = 100\) ràng buộc (ví dụ từ Boyd &amp;amp; Vandenberghe, mục 11.3.2 và 11.7.4).&lt;/p&gt;

&lt;p&gt;Phương pháp chắn được thử với nhiều giá trị \(\mu\) khác nhau (\(2, 50, 150\)), trong khi phương pháp gốc-đối ngẫu cố định \(\mu = 10\). Cả hai phương pháp đều sử dụng \(\alpha = 0.01, \beta = 0.5\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter17/barrier_vs_primal_dual.png&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Khoảng cách đối ngẫu (phương pháp chắn so với gốc-đối ngẫu) [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Đồ thị cho thấy phương pháp gốc-đối ngẫu hội tụ nhanh hơn đồng thời đạt độ chính xác cao hơn.&lt;/p&gt;

&lt;h3 id=&quot;chuỗi-bài-toán-n--2m-với-n-tăng-dần&quot;&gt;Chuỗi bài toán: \(n = 2m\) với \(n\) tăng dần&lt;/h3&gt;
&lt;p&gt;Tiếp theo, xét hiệu năng trên một dãy bài toán LP với \(n = 2m\) khi kích thước \(n\) tăng dần:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Phương pháp chắn dùng \(\mu = 100\) và thực hiện khoảng 2 vòng lặp ngoài (khoảng cách đối ngẫu giảm xuống \(10^{-4}\)).&lt;/li&gt;
  &lt;li&gt;Phương pháp gốc-đối ngẫu dùng \(\mu = 10\) và dừng khi khoảng cách đối ngẫu và sai số khả thi đạt xấp xỉ \(10^{-8}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter17/barrier_vs_primal_dual2.png&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Số vòng lặp Newton (phương pháp chắn so với gốc-đối ngẫu) [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Như hình trên cho thấy, phương pháp gốc-đối ngẫu đạt độ chính xác cao hơn nhiều dù chỉ cần thêm một lượng nhỏ vòng lặp Newton.&lt;/p&gt;

&lt;h3 id=&quot;gốc---đối-ngẫu-so-với-phương-pháp-rào-cản-video&quot;&gt;Gốc - đối ngẫu so với phương pháp rào cản (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/primal-dual-ipm_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Phương pháp rào cản phải định tâm lại sau mỗi lần cập nhật \(t\); trong khi đó, phương pháp gốc – đối ngẫu chỉ thực hiện một bước Newton trên hệ điều kiện KKT bị nhiễu theo \((x,\lambda)\) và thu hẹp khoảng cách đối ngẫu với ít bước hơn đáng kể.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-gốc---đối-ngẫu-so-với-rào-cản&quot;&gt;Tự tay thử: gốc - đối ngẫu so với rào cản&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;pdipm&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>17-03 Một chút lịch sử</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_03_some_history/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_03_some_history</id>
   <content type="html">&lt;p&gt;Năm 1984, một bài báo của Narendra Karmarkar tại Bell Labs đã làm chấn động không chỉ giới toán học mà cả trang nhất tờ &lt;em&gt;New York Times&lt;/em&gt;: ông tuyên bố tìm ra một thuật toán thời gian đa thức giải quy hoạch tuyến tính nhanh gấp hàng chục lần phương pháp đơn hình kinh điển của George Dantzig. Cuộc tranh luận nảy lửa kéo dài cả thập kỷ sau đó — giữa những người bảo vệ Simplex đi men theo các đỉnh đa diện và phe điểm trong (Interior-Point) xuyên thẳng qua lòng đa diện — cuối cùng đã sinh ra kỷ nguyên vàng của tối ưu hóa lồi hiện đại và các bộ giải lai (hybrid solvers) ngày nay.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-cột-mốc-lịch-sử-định-hình-ngành-tối-ưu-hóa&quot;&gt;Kiến thức cần nhớ: Bốn cột mốc lịch sử định hình ngành tối ưu hóa&lt;/h2&gt;

&lt;p&gt;Nhìn lại hành trình từ thập niên 1940 đến cuối thế kỷ XX giúp ta hiểu rõ sự khác biệt giữa độ phức tạp lý thuyết (worst-case) và hiệu năng thực tế:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kỷ nguyên Đơn hình (Simplex — Dantzig, 1947):&lt;/strong&gt; Đi dọc theo các cạnh và đỉnh của đa diện khả thi. Trong thực tế, Simplex cực nhanh và dễ khởi động nóng (warm-start), nhưng Klee và Minty (1972) đã chứng minh nó có thể mất số bước hàm mũ \(2^n\) trên các đa diện bị bóp méo.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước ngoặt Lý thuyết (Ellipsoid — Khachiyan, 1979):&lt;/strong&gt; Chứng minh lần đầu tiên rằng quy hoạch tuyến tính thuộc lớp độ phức tạp đa thức &lt;strong&gt;P&lt;/strong&gt;. Tuy nhiên, phương pháp ellipsoid hội tụ quá chậm trong thực tế nên chủ yếu có ý nghĩa lý thuyết.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cuộc cách mạng Điểm trong (Karmarkar 1984 → Renegar 1988 → Mehrotra 1992):&lt;/strong&gt; Kết nối phép chiếu xạ ảnh của Karmarkar với hàm chắn logarit cổ điển (Fiacco–McCormick) và phương pháp Newton gốc–đối ngẫu, đạt cận độ phức tạp \(O(\sqrt{n}\log(1/\epsilon))\) và hiệu năng thực chiến cực mạnh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng quát hóa lên Quy hoạch Nón (Nesterov &amp;amp; Nemirovskii, 1994):&lt;/strong&gt; Lý thuyết hàm tự phù hợp (self-concordant barriers) mở rộng toàn bộ sức mạnh của phương pháp điểm trong từ quy hoạch tuyến tính sang quy hoạch nón bậc hai (SOCP) và quy hoạch bán xác định (SDP).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-con-số-tăng-trưởng-giữa-simplex-kleeminty-và-điểm-trong&quot;&gt;Giải thích: So sánh con số tăng trưởng giữa Simplex (Klee–Minty) và Điểm trong&lt;/h3&gt;

&lt;p&gt;Để cảm nhận sức mạnh của bước nhảy từ độ phức tạp hàm mũ sang độ phức tạp đa thức \(O(\sqrt{n}\log(1/\epsilon))\), hãy tính thử với một bài toán LP kích thước khiêm tốn \(n = 50\) biến và độ chính xác yêu cầu \(\epsilon = 10^{-8}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp xấu nhất của Simplex trên hình lập phương Klee–Minty:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(n = 3\), hình lập phương biến dạng có \(2^3 = 8\) đỉnh; Simplex đi qua cả 8 đỉnh (7 bước xoay).&lt;/li&gt;
      &lt;li&gt;Với \(n = 50\), số đỉnh cần duyệt lên tới \(2^{50} = 1{,}125{,}899{,}906{,}842{,}624 \approx 1.13 \times 10^{15}\) bước! Dù mỗi giây thực hiện \(10^9\) phép xoay, máy tính vẫn mất hơn &lt;strong&gt;13 ngày&lt;/strong&gt; chỉ cho một bài toán 50 biến.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cận lý thuyết của phương pháp điểm trong (Renegar, 1988):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Số vòng lặp Newton bị chặn trên bởi cỡ \(C \sqrt{n}\ln(1/\epsilon)\).&lt;/li&gt;
      &lt;li&gt;Với \(n = 50\) và \(\epsilon = 10^{-8}\), ta có \(\sqrt{50} \approx 7.07\) và \(\ln(10^8) \approx 18.42\), nên tích \(\sqrt{n}\ln(1/\epsilon) \approx 130\) vòng lặp! Trong thực tế với kỹ thuật predictor-corrector của Mehrotra, số vòng lặp thường chỉ khoảng &lt;strong&gt;15–30 bước&lt;/strong&gt;, gần như không tăng theo kích thước \(n\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vì sao cả hai vẫn cùng tồn tại?&lt;/strong&gt; Simplex vượt trội khi giải bài toán nhỏ hoặc cần giải lại hàng nghìn lần sau khi thêm vài ràng buộc (như trong nhánh-và-cận của quy hoạch nguyên), trong khi điểm trong tỏa sáng ở các bài toán cỡ lớn và các bài toán nón phi tuyến (SOCP, SDP) nơi khái niệm “đỉnh đa diện” không còn tồn tại.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Nhìn chung, các bộ giải quy hoạch tuyến tính (LP) hiện đại hàng đầu đều kết hợp cả phương pháp đơn hình (Simplex) và phương pháp điểm trong.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Dantzig (thập niên 1940): Phương pháp đơn hình — phương pháp đầu tiên giải LP dạng tổng quát và tìm được nghiệm chính xác sau một số hữu hạn bước. Đến nay, đây vẫn là một trong những thuật toán nổi tiếng và được nghiên cứu nhiều nhất cho LP.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Klee và Minty (1972): Xây dựng một lớp bài toán LP “bệnh lý” (Klee–Minty cube) gồm \(n\) biến và \(2n\) ràng buộc, khiến phương pháp đơn hình cần tới \(2^n\) vòng lặp trong trường hợp xấu nhất.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Khachiyan (1979): Đề xuất thuật toán thời gian đa thức đầu tiên cho LP dựa trên phương pháp ellipsoid của Nemirovski và Yudin (1976); kết quả này có ý nghĩa lý thuyết lớn nhưng không hiệu quả trong thực tế.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Karmarkar (1984): Đề xuất phương pháp điểm trong thời gian đa thức cho LP có hiệu năng thực tế tốt, tạo bước ngoặt lớn cho lĩnh vực tối ưu hóa (Bằng sáng chế Hoa Kỳ 4,744,026, hết hạn năm 2006).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Renegar (1988): Phát triển thuật toán điểm trong dựa trên phương pháp Newton cho LP, đạt độ phức tạp tính toán lý thuyết tốt nhất cho đến khi có các cải tiến gần đây hơn của Lee–Sidford.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>17-02 Phương pháp điểm trong gốc-đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_02_primal_dual_interior_point_method/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_02_primal_dual_interior_point_method</id>
   <content type="html">&lt;p&gt;Trong phương pháp chắn cổ điển, mỗi khi tăng \(t\) lên \(\mu t\), ta phải dừng lại giữa đường để giải chính xác bài toán định tâm bằng nhiều bước Newton — giống như một người leo núi cứ đi được vài chục mét lại dựng lều đo đạc lại bản đồ thật tỉ mỉ. Phương pháp điểm trong gốc–đối ngẫu đặt ra một triết lý táo bạo hơn hẳn: &lt;strong&gt;vừa bước đi, vừa chỉnh hướng&lt;/strong&gt;, cập nhật đồng thời cả \((x, u, v)\) bằng duy nhất một bước Newton mà thậm chí không cần bắt buộc điểm hiện tại phải nằm sẵn trên mặt phẳng khả thi \(Ax = b\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-tạo-nên-lợi-thế-của-pd-ipm&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép tạo nên lợi thế của PD-IPM&lt;/h2&gt;

&lt;p&gt;Để hiểu đúng bảng so sánh giữa phương pháp chắn và phương pháp điểm trong gốc–đối ngẫu, hãy tách riêng bốn khía cạnh thiết kế thuật toán:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược vòng lặp đơn (Single-Loop Update):&lt;/strong&gt; Thay vì cấu trúc hai vòng lặp lồng nhau (outer loop tăng \(t\), inner loop chạy Newton định tâm), PD-IPM chỉ có một vòng lặp duy nhất: mỗi bước tính một hướng Newton và cập nhật ngay \(\tau\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khởi tạo không khả thi (Infeasible Start):&lt;/strong&gt; Trong nhiều bài toán thực tế, ngay cả việc tìm một điểm ban đầu thỏa mãn \(Ax^{(0)} = b\) cũng tốn kém. PD-IPM chỉ yêu cầu \(h(x^{(0)}) &amp;lt; 0\) và \(u^{(0)} &amp;gt; 0\), còn phần dư đẳng thức \(Ax - b\) được triệt tiêu dần cùng lúc với phần dư đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định hướng đồng thời gốc–đối ngẫu (Coupled Primal-Dual Direction):&lt;/strong&gt; Bước Newton của PD-IPM lấy thông tin độ cong từ cả \(\nabla^2 f(x)\) lẫn các biến đối ngẫu \(u\), giúp hướng đi bám đường trung tâm mượt hơn và tránh hiện tượng lệch hướng khi tiến gần biên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ hội tụ siêu tuyến tính thực tiễn:&lt;/strong&gt; Khi đủ gần nghiệm tối ưu và giảm \(\tau\) linh hoạt theo khoảng cách đối ngẫu hiện tại, PD-IPM thường đạt hội tụ siêu tuyến tính (thậm chí bậc hai trong các biến thể predictor-corrector), vượt xa tốc độ tuyến tính của phương pháp chắn thuần túy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-quan-sát-một-điểm-lặp-không-khả-thi-vẫn-có-thể-tự-kéo-về-miền-khả-thi&quot;&gt;Giải thích: Quan sát một điểm lặp không khả thi vẫn có thể “tự kéo” về miền khả thi&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch bậc hai 2 biến:&lt;/p&gt;

\[\min_{x_1, x_2} \; \frac{1}{2}(x_1^2 + x_2^2) \qquad \text{với điều kiện} \qquad x_1 + x_2 = 2, \; -x_1 \le 0, \; -x_2 \le 0.\]

&lt;p&gt;Nghiệm tối ưu là \(x^\star = (1, 1)\), \(u^\star = (0, 0)\), \(v^\star = -1\). Giả sử ta khởi tạo tại một điểm &lt;strong&gt;không khả thi đẳng thức&lt;/strong&gt; \(x^{(0)} = (2, 1)\) (vì \(2 + 1 = 3 \ne 2\)), nhưng vẫn nằm chặt trong miền bất đẳng thức \((x_1, x_2 &amp;gt; 0)\), cùng \(u^{(0)} = (0.5, 0.5)\), \(v^{(0)} = -1\), và chọn \(\tau = 0.1\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Đo ba độ lệch (phần dư):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Lệch ràng buộc đẳng thức: \(r_{\text{prim}} = x_1 + x_2 - 2 = 2 + 1 - 2 = +1\).&lt;/li&gt;
      &lt;li&gt;Lệch điều kiện dừng (đối ngẫu): \(r_{\text{dual}} = \nabla f(x) - u + v\mathbf{1} = \begin{bmatrix} 2 - 0.5 - 1 \\ 1 - 0.5 - 1 \end{bmatrix} = \begin{bmatrix} 0.5 \\ -0.5 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;Lệch bù chặt bị nhiễu: \(r_{\text{cent}} = \begin{bmatrix} -u_1 x_1 + \tau \\ -u_2 x_2 + \tau \end{bmatrix} = \begin{bmatrix} -1 + 0.1 \\ -0.5 + 0.1 \end{bmatrix} = \begin{bmatrix} -0.9 \\ -0.4 \end{bmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tác dụng của bước Newton gốc–đối ngẫu:&lt;/strong&gt; Hệ tuyến tính Newton buộc \(\Delta x_1 + \Delta x_2 = -r_{\text{prim}} = -1\). Do đó, ngay khi cập nhật với độ dài bước \(\theta \in (0, 1]\), sai số ràng buộc đẳng thức mới giảm chính xác theo tỉ lệ \((1 - \theta) r_{\text{prim}}\). Nếu lấy \(\theta = 1\), điểm lặp trở nên khả thi đẳng thức &lt;strong&gt;ngay lập tức chỉ sau 1 bước&lt;/strong&gt; mà không cần bước Pha I (Phase I) riêng biệt!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Tương tự phương pháp chắn, &lt;strong&gt;phương pháp điểm trong gốc-đối ngẫu&lt;/strong&gt; cũng nhằm tính xấp xỉ các điểm dọc theo đường trung tâm. Tuy nhiên, giữa hai phương pháp có một số điểm khác biệt quan trọng.&lt;/p&gt;

&lt;h2 id=&quot;khác-biệt-giữa-phương-pháp-điểm-trong-gốc-đối-ngẫu-và-phương-pháp-chắn&quot;&gt;Khác biệt giữa phương pháp điểm trong gốc-đối ngẫu và phương pháp chắn&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Thông thường chỉ thực hiện &lt;strong&gt;một bước Newton&lt;/strong&gt; ở mỗi vòng lặp (không cần vòng lặp trong riêng cho bước định tâm — centering).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các điểm lặp không nhất thiết phải khả thi&lt;/strong&gt; trong quá trình chạy (thuật toán đưa điểm lặp tiến dần về miền khả thi kết hợp với tìm kiếm theo đường lui — backtracking line search).&lt;/li&gt;
  &lt;li&gt;Thường &lt;strong&gt;hiệu quả hơn&lt;/strong&gt; trong thực tế; đặc biệt dưới các điều kiện phù hợp, phương pháp đạt tốc độ hội tụ nhanh hơn hội tụ tuyến tính.&lt;/li&gt;
  &lt;li&gt;Kém trực quan hơn một chút so với phương pháp chắn.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>17-02-03 Thuật toán gốc-đối ngẫu (Primal-Dual Algorithm)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_02_03_primal_dual_algorithm/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_02_03_primal_dual_algorithm</id>
   <content type="html">&lt;p&gt;Có hướng Newton rồi, nhưng nếu cứ nhắm mắt bước trọn độ dài \(\theta = 1\) thì chuyện gì sẽ xảy ra? Một biến đối ngẫu \(u_i\) có thể nhảy vọt xuống số âm, hoặc một ràng buộc \(h_i(x)\) có thể vượt qua \(0\) ra ngoài miền xác định, khiến toàn bộ thuật toán sụp đổ ngay lập tức. Thuật toán gốc–đối ngẫu hoàn chỉnh kết hợp hai cơ chế kiểm soát nhịp độ cực kỳ tinh tế: chọn tham số định tâm \(\tau = \sigma \tau(x, u)\) để quyết định độ “tham lam” khi thu hẹp khoảng cách đối ngẫu, và tìm kiếm theo đường lui hai tầng để bảo đảm cả tính điểm trong lẫn mức giảm chuẩn phần dư.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-cơ-chế-vận-hành-một-vòng-lặp-pd-ipm-hoàn-chỉnh&quot;&gt;Kiến thức cần nhớ: Bốn cơ chế vận hành một vòng lặp PD-IPM hoàn chỉnh&lt;/h2&gt;

&lt;p&gt;Để tự lập trình được một bộ giải gốc–đối ngẫu chạy ổn định từ đầu đến cuối, cần hiểu rõ vai trò của từng bánh răng sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tỉ lệ định tâm \(\sigma \in (0, 1)\) và tham số mục tiêu \(\tau = \sigma \eta / m\):&lt;/strong&gt; Nếu \(\sigma\) quá gần \(0\) (đi thẳng vào biên), bước Newton dễ bị cụt vì đụng rào \(u &amp;gt; 0\) hoặc \(h(x) &amp;lt; 0\). Nếu \(\sigma\) quá gần \(1\), thuật toán chỉ lo định tâm mà giảm \(\eta\) rất chậm. Chọn \(\sigma \approx 0.1\) (tương ứng \(\mu = 10\)) là điểm cân bằng kinh điển.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc “phần trăm tới biên” (Fraction-to-the-Boundary Rule):&lt;/strong&gt; Trước khi tìm kiếm theo đường lui, ta tính bước lớn nhất \(\theta_{\max}\) sao cho \(u + \theta \Delta u &amp;gt; 0\) (thường nhân hệ số an toàn \(0.99\)) để chặn ngay nguy cơ vi phạm \(u &amp;gt; 0\) mà không cần thử sai.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm theo đường lui bảo toàn tính điểm trong:&lt;/strong&gt; Giảm dần \(\theta \leftarrow \beta \theta\) cho đến khi mọi bất đẳng thức gốc đều chặt \(h_i(x + \theta\Delta x) &amp;lt; 0\), rồi tiếp tục giảm cho đến khi chuẩn vector phần dư tổng giảm đủ: \(\|r_\tau(w + \theta\Delta w)\|_2 \le (1 - \alpha\theta)\|r_\tau(w)\|_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chuẩn dừng kép (Feasibility + Optimality):&lt;/strong&gt; Thuật toán chỉ dừng khi sai số khả thi gốc–đối ngẫu nhỏ hơn \(\epsilon_{\text{feas}}\) VÀ khoảng cách đối ngẫu thay thế \(\eta = -h(x)^T u \le \epsilon\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-bước-cực-đại-theta_max-và-kiểm-tra-điều-kiện-backtracking&quot;&gt;Giải thích: Tính tay bước cực đại \(\theta_{\max}\) và kiểm tra điều kiện backtracking&lt;/h3&gt;

&lt;p&gt;Giả sử tại vòng lặp \(k\) của một bài toán có \(m = 2\) ràng buộc bất đẳng thức, ta đang ở trạng thái:&lt;/p&gt;

\[h(x^{(k)}) = \begin{bmatrix} -1.0 \\ -0.4 \end{bmatrix}, \qquad u^{(k)} = \begin{bmatrix} 0.5 \\ 0.8 \end{bmatrix}, \qquad \|r_\tau(w^{(k)})\|_2 = 1.20.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính khoảng cách đối ngẫu thay thế và tham số \(\tau\) mới (với \(\sigma = 0.2\)):&lt;/strong&gt;
\(\eta = -h(x^{(k)})^T u^{(k)} = (1.0)(0.5) + (0.4)(0.8) = 0.82 \implies \tau(x^{(k)}, u^{(k)}) = \frac{0.82}{2} = 0.41.\)
Suy ra tham số mục tiêu cho bước Newton là \(\tau = \sigma \cdot 0.41 = 0.2 \times 0.41 = 0.082\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác định bước cực đại giữ \(u &amp;gt; 0\):&lt;/strong&gt; Giả sử giải hệ Newton ta nhận được \(\Delta u = (-1.0, \; +0.2)^T\). Thành phần thứ hai tăng (\(\Delta u_2 &amp;gt; 0\)) nên không giới hạn \(\theta\); thành phần thứ nhất giảm nên cần:
\(u_1^{(k)} + \theta \Delta u_1 &amp;gt; 0 \iff 0.5 - 1.0\theta &amp;gt; 0 \iff \theta &amp;lt; 0.5.\)
Áp dụng hệ số an toàn \(0.99\), ta đặt bước khởi điểm tìm kiếm theo đường lui là \(\theta_{\max} = \min\{1, \; 0.99 \times 0.5\} = 0.495\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện giảm đủ (với \(\alpha = 0.01, \beta = 0.5\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Thử \(\theta = 0.495\): kiểm tra \(h(x^{(k)} + 0.495\Delta x) &amp;lt; 0\). Nếu thỏa mãn, tính chuẩn phần dư mới \(\|r_\tau(w^{(k)} + 0.495\Delta w)\|_2\) và so sánh với ngưỡng \((1 - 0.01 \times 0.495) \times 1.20 = 1.19406\).&lt;/li&gt;
      &lt;li&gt;Nếu chuẩn mới là \(0.65 \le 1.19406\), ta chấp nhận ngay \(\theta_k = 0.495\) và cập nhật \(w^{(k+1)} = w^{(k)} + 0.495\Delta w\); ngược lại, giảm \(\theta \leftarrow 0.5 \times 0.495 = 0.2475\) rồi kiểm tra lại.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Để mô tả thuật toán gốc-đối ngẫu, trước hết ta định nghĩa tham số \(\tau(x, u)\) như sau:&lt;/p&gt;
&lt;blockquote&gt;
\[\tau(x,u) := -\frac{h(x)^Tu}{m} \quad \text{với} \quad h (x) \le 0, u \ge 0\]
&lt;/blockquote&gt;

&lt;p&gt;Lưu ý rằng hai tham số \(t\) và \(\mu\) của phương pháp chắn được viết lại thành \(\tau\) và \(\sigma\) trong thuật toán gốc-đối ngẫu:&lt;/p&gt;
&lt;blockquote&gt;
\[\tau = \frac{1}{t}, \quad \sigma = \frac{1}{\mu}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;thuật-toán-gốc-đối-ngẫu&quot;&gt;Thuật toán gốc-đối ngẫu&lt;/h2&gt;
&lt;p&gt;Thuật toán gồm các bước sau:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;ol&gt;
    &lt;li&gt;Chọn \(\sigma \in (0,1)\).&lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;Chọn điểm khởi tạo \((x^0,u^0,v^0)\) thỏa mãn \(h(x^0) &amp;lt; 0\) và \(u^0 &amp;gt; 0\).&lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;Lặp với \(k = 0, 1, \dots\):&lt;br /&gt;
\(\quad\) * Tính bước Newton:&lt;br /&gt;
\(\qquad \quad (x,u,v) = (x^k,u^k,v^k)\) &lt;br /&gt;
\(\qquad \quad\) tính \(\tau := \sigma \tau(x^k,u^k)\)&lt;br /&gt;
\(\qquad \quad\) giải hệ Newton để tìm \((\Delta x,\Delta u,\Delta v)\) ứng với \(\tau\) này&lt;br /&gt;
\(\quad\) * Chọn độ dài bước \(\theta_k\) bằng tìm kiếm theo đường lui (backtracking line search).&lt;br /&gt;
\(\quad\) * Cập nhật biến gốc-đối ngẫu:&lt;br /&gt;
\(\qquad \quad (x^{k+1},u^{k+1},v^{k+1}) := (x^k,u^k,v^k) + \theta_k(\Delta x,\Delta u,\Delta v)\)&lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;Dừng khi \(-h(x^{k+1})^Tu^{k+1} \le \epsilon\) và \((\parallel r_{prim} \parallel^2_2 + \parallel r_{dual} \parallel^2_2)^{1/2} \le \epsilon\).&lt;br /&gt;&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ở mỗi vòng lặp, thuật toán tính một bước Newton \((\Delta x, \Delta u, \Delta v)\) rồi cập nhật đồng thời các biến để thu được \((x^{k+1}, u^{k+1}, v^{k+1})\). Độ dài bước \(\theta_k\) được xác định qua tìm kiếm theo đường lui nhằm giữ \(h(x) &amp;lt; 0\) và \(u &amp;gt; 0\), đồng thời làm giảm chuẩn phần dư. Thuật toán dừng khi khoảng cách đối ngẫu thay thế và chuẩn phần dư gốc – đối ngẫu đều không vượt quá ngưỡng \(\epsilon\).&lt;/p&gt;

&lt;h2 id=&quot;tìm-kiếm-theo-đường-lui-backtracking-line-search&quot;&gt;Tìm kiếm theo đường lui (Backtracking line search)&lt;/h2&gt;
&lt;p&gt;Vì thuật toán gốc-đối ngẫu chỉ thực hiện một bước Newton mỗi vòng lặp, ta nên xem bước này là một hướng dịch chuyển về phía nghiệm chứ không phải bước nhảy trực tiếp tới nghiệm chính xác. Do đó, cần chọn độ dài bước \(\theta\) thích hợp cho phép cập nhật:&lt;/p&gt;

&lt;blockquote&gt;
\[x^+ = x + \theta \Delta x, \quad  u^+ = u + \theta \Delta u, \quad v^+ = v + \theta \Delta v\]
&lt;/blockquote&gt;

&lt;p&gt;Quá trình chọn \(\theta\) nhằm đạt hai mục tiêu:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Duy trì điều kiện điểm trong \(h(x^+) &amp;lt; 0, u^+ &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;Làm giảm chuẩn phần dư \(\parallel r(x,u,v) \parallel\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Để thực hiện điều này, ta áp dụng &lt;strong&gt;tìm kiếm theo đường lui nhiều giai đoạn (multi-stage backtracking line search)&lt;/strong&gt;:&lt;/p&gt;

&lt;h4 id=&quot;giai-đoạn-1-duy-trì-tính-khả-thi-đối-ngẫu-u-gt-0&quot;&gt;Giai đoạn 1: duy trì tính khả thi đối ngẫu \(u \gt 0\)&lt;/h4&gt;
&lt;p&gt;Bắt đầu bằng bước lớn nhất \(\theta_{\max} \le 1\) sao cho \(u + \theta \Delta u \ge 0\):&lt;/p&gt;

&lt;blockquote&gt;
\[\theta_{\max} = \min \Biggl\{1,\  \min \Bigl\{ -\frac{u_i}{\Delta u_i} : \Delta u_i &amp;lt; 0 \Bigr\} \Biggr\}\]
&lt;/blockquote&gt;

&lt;p&gt;Công thức trên được suy ra trực tiếp từ bất đẳng thức:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;u + \theta \Delta u &amp;amp;&amp;amp; \ge 0  \\\\
\Leftrightarrow \quad &amp;amp;u &amp;amp;&amp;amp; \ge -\theta \Delta u \\\\
\Leftrightarrow \quad &amp;amp;- u/\Delta u &amp;amp;&amp;amp; \ge \theta \quad  \text{ với các thành phần có }\Delta u \lt 0  \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;giai-đoạn-2-duy-trì-tính-khả-thi-gốc-ngặt-hx-lt-0&quot;&gt;Giai đoạn 2: duy trì tính khả thi gốc ngặt \(h(x) \lt 0\)&lt;/h4&gt;
&lt;p&gt;Chọn các tham số \(\alpha, \beta \in (0,1)\), khởi tạo \(\theta = 0.99\theta_{\max}\) (nhờ nhân \(0.99\) mà \(u^+ &amp;gt; 0\) ngặt), sau đó:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Lặp cập nhật \(\theta = \beta\theta\) cho đến khi \(h_i(x^+) &amp;lt; 0\) với mọi \(i = 1, \dots, m\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bước này đảm bảo \(x^+\) nằm trong miền trong của các ràng buộc bất đẳng thức.&lt;/p&gt;

&lt;h4 id=&quot;giai-đoạn-3-giảm-chuẩn-phần-dư-parallel-rxuv-parallel&quot;&gt;Giai đoạn 3: giảm chuẩn phần dư \(\parallel r(x,u,v) \parallel\)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Tiếp tục cập nhật \(\theta = \beta \theta\) cho đến khi \(\| r(x^+,u^+,v^+) \| \le (1-\alpha \theta) \| r(x,u,v) \|\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Điều kiện ở Giai đoạn 3 tương tự điều kiện giảm đủ trong backtracking line search tiêu chuẩn. Vế phải của bất đẳng thức xuất phát từ phương trình Newton:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\Delta w = (\Delta x, \Delta u, \Delta v) &amp;amp;= -r^{\prime}(w)^{-1} r(w) \\\\
\Leftrightarrow r(w)  &amp;amp;=  -r^{\prime}(w) \Delta w \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Thay \(r^{\prime}(w) \Delta w = -r(w)\) vào khai triển Taylor bậc nhất, ta có:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
r(w + \theta \Delta w) &amp;amp; \approx r(w) +  r^{\prime}(w) (\theta \Delta w) \\\\
&amp;amp;\approx (1-\theta) r(w) \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó, với hệ số chiết khấu \(\alpha \in (0, 1)\), ta yêu cầu mức giảm \(\|r(w + \theta \Delta w)\| \le (1-\alpha \theta) \|r(w)\|\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>17-02-02 Khoảng cách đối ngẫu thay thế và các phần dư</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_02_02_surrogate_duality_gap_residuals/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_02_02_surrogate_duality_gap_residuals</id>
   <content type="html">&lt;p&gt;Khi lái một chiếc máy bay xuyên qua sương mù, phi công không thể chỉ nhìn ra cửa sổ mà phải theo dõi đồng hồ độ cao, tốc độ và góc nghiêng. Trong phương pháp điểm trong gốc–đối ngẫu, vì các điểm lặp trung gian không còn bắt buộc phải khả thi, ta không thể tính khoảng cách đối ngẫu thực \(f(x) - g(u, v)\) ở mọi bước. Thay vào đó, ta theo dõi ba “đồng hồ chỉ báo” là ba vector phần dư \(r_{\text{prim}}, r_{\text{dual}}, r_{\text{cent}}\) cùng với &lt;strong&gt;khoảng cách đối ngẫu thay thế&lt;/strong&gt; \(\eta = -h(x)^T u\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-đọc-hiểu-các-chỉ-số-hội-tụ-của-bộ-giải-gốcđối-ngẫu&quot;&gt;Kiến thức cần nhớ: Đọc hiểu các chỉ số hội tụ của bộ giải gốc–đối ngẫu&lt;/h2&gt;

&lt;p&gt;Bốn khái niệm dưới đây giải thích tại sao mọi bộ giải điểm trong công nghiệp đều in ra cột &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p_res&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d_res&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gap&lt;/code&gt; trên màn hình nhật ký:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư gốc (Primal Residual, \(r_{\text{prim}} = Ax - b\)):&lt;/strong&gt; Đo mức độ vi phạm ràng buộc đẳng thức. Khi \(r_{\text{prim}} = 0\) cùng với \(h(x) \le 0\), điểm \(x\) chính thức là điểm khả thi của bài toán gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư đối ngẫu (Dual Residual, \(r_{\text{dual}} = \nabla f(x) + \nabla h(x)u + A^T v\)):&lt;/strong&gt; Đo mức độ vi phạm điều kiện dừng của hàm Lagrange. Khi \(r_{\text{dual}} = 0\) và \(u \ge 0\), cặp \((u, v)\) thuộc miền xác định của hàm đối ngẫu \(g(u, v)\) và cho ra một cận dưới hợp lệ cho \(p^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư trung tâm (Centrality Residual, \(r_{\text{cent}} = Uh(x) + \tau\mathbf{1}\)):&lt;/strong&gt; Đo khoảng cách từ điểm hiện tại tới đường trung tâm ứng với tham số \(\tau\). Khi \(\tau \to 0\) và \(r_{\text{cent}} \to 0\), điều kiện bù chặt được thỏa mãn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu thay thế (Surrogate Duality Gap, \(\eta = -h(x)^T u\)):&lt;/strong&gt; Vì \(h(x) &amp;lt; 0\) và \(u &amp;gt; 0\), đại lượng \(\eta\) luôn dương. Khi cả \(r_{\text{prim}} = 0\) và \(r_{\text{dual}} = 0\), \(\eta\) trùng khớp chính xác với khoảng cách đối ngẫu thực \(f(x) - g(u, v)\); còn khi chưa khả thi, nó là thước đo thay thế tin cậy để điều chỉnh tham số \(\tau\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-ba-phần-dư-và-phân-biệt-khoảng-cách-đối-ngẫu-thay-thế-với-khoảng-cách-thực&quot;&gt;Giải thích: Tính ba phần dư và phân biệt khoảng cách đối ngẫu thay thế với khoảng cách thực&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch tuyến tính 2 biến:&lt;/p&gt;

\[\min_{x_1, x_2} \; x_1 + 2x_2 \qquad \text{với điều kiện} \qquad x_1 + x_2 = 4, \quad h_1(x) = -x_1 \le 0, \quad h_2(x) = -x_2 \le 0.\]

&lt;p&gt;Xét điểm lặp trung gian \(x = (3, 2)\), \(u = (0.4, 0.6)\), \(v = -1.2\), với tham số \(\tau = 0.25\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư gốc:&lt;/strong&gt; \(r_{\text{prim}} = x_1 + x_2 - 4 = 3 + 2 - 4 = +1\) (chưa khả thi gốc).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư đối ngẫu:&lt;/strong&gt; Với \(\nabla f(x) = (1, 2)^T\), \(\nabla h(x) = -I\), \(A^T = (1, 1)^T\):
\(r_{\text{dual}} = \begin{bmatrix} 1 \\ 2 \end{bmatrix} - \begin{bmatrix} 0.4 \\ 0.6 \end{bmatrix} + (-1.2)\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} -0.6 \\ 0.2 \end{bmatrix} \ne 0\) (chưa khả thi đối ngẫu).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu thay thế:&lt;/strong&gt;
\(\eta = -h(x)^T u = x_1 u_1 + x_2 u_2 = (3)(0.4) + (2)(0.6) = 1.2 + 1.2 = 2.4.\)
Lưu ý: vì \(r_{\text{dual}} \ne 0\), hàm Lagrange \(L(x, u, v)\) không bị chặn dưới theo \(x\), nên \(g(u, v) = -\infty\) — khoảng cách đối ngẫu &lt;em&gt;thực&lt;/em&gt; bằng \(+\infty\), nhưng khoảng cách &lt;em&gt;thay thế&lt;/em&gt; \(\eta = 2.4\) vẫn hữu hạn và hoàn toàn đo đạc được!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư trung tâm:&lt;/strong&gt;
\(r_{\text{cent}} = \begin{bmatrix} -x_1 u_1 + \tau \\ -x_2 u_2 + \tau \end{bmatrix} = \begin{bmatrix} -1.2 + 0.25 \\ -1.2 + 0.25 \end{bmatrix} = \begin{bmatrix} -0.95 \\ -0.95 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài học rút ra:&lt;/strong&gt; Do \(\eta\) chỉ trở thành khoảng cách đối ngẫu thực khi điểm lặp khả thi, điều kiện dừng của thuật toán PD-IPM &lt;strong&gt;bắt buộc&lt;/strong&gt; phải kiểm tra đồng thời cả ba: \(\|r_{\text{prim}}\|_2 \le \epsilon_{\text{feas}}\), \(\|r_{\text{dual}}\|_2 \le \epsilon_{\text{feas}}\) và \(\eta \le \epsilon\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Để xây dựng thuật toán gốc-đối ngẫu, trước hết ta định nghĩa ba loại phần dư (residual) và đại lượng khoảng cách đối ngẫu thay thế (surrogate duality gap). Đây là các đại lượng mà thuật toán cần đưa về \(0\).&lt;/p&gt;

&lt;h2 id=&quot;các-phần-dư&quot;&gt;Các phần dư&lt;/h2&gt;
&lt;p&gt;Tại điểm \((x, u, v)\), ba phần dư đối ngẫu, trung tâm và gốc được định nghĩa lần lượt như sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(r_{dual} = \nabla f(x) +\nabla h(x)u + A^Tv\\\)
\(r_{cent} =  Uh(x) + \tau\mathbb{1} \\\) 
\(r_{prim} = Ax-b\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ba đại lượng này tương ứng với ba khối hàng của vector phần dư \(r(x, u, v)\). &lt;strong&gt;Phương pháp điểm trong gốc-đối ngẫu&lt;/strong&gt; điều chỉnh điểm lặp sao cho cả ba phần dư tiến dần về \(0\), thay vì ép buộc chúng luôn bằng \(0\) ở mọi bước; vì vậy các điểm lặp trung gian không nhất thiết phải khả thi.&lt;/p&gt;

&lt;p&gt;Sở dĩ \(r_{dual}\) được gọi là phần dư đối ngẫu vì khi \(r_{dual} = 0\) (cùng với \(u \ge 0\)), điểm \((u, v)\) nằm trong miền xác định của hàm đối ngẫu \(g\), tức là khả thi đối ngẫu:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; r_{dual} = \nabla f(x) +\nabla h(x)u + A^Tv = 0 \\\\
&amp;amp; \iff \min_{x} L(x,u,v) = g(u,v) \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tương tự, điều kiện \(r_{prim} = 0\) (cùng với \(h(x) \le 0\)) biểu thị tính khả thi gốc, nên \(r_{prim}\) được gọi là phần dư gốc.&lt;/p&gt;

&lt;h2 id=&quot;khoảng-cách-đối-ngẫu-thay-thế&quot;&gt;Khoảng cách đối ngẫu thay thế&lt;/h2&gt;
&lt;p&gt;Trong khi phương pháp chắn luôn duy trì điểm khả thi nên có khoảng cách đối ngẫu thực sự ở mọi vòng lặp, phương pháp điểm trong gốc-đối ngẫu không đòi hỏi tính khả thi trung gian nên sử dụng &lt;strong&gt;khoảng cách đối ngẫu thay thế (surrogate duality gap)&lt;/strong&gt;, được định nghĩa là:&lt;/p&gt;

&lt;blockquote&gt;
\[-h(x)^Tu  \quad \text{với} \quad h(x) \le 0, u \ge 0\]
&lt;/blockquote&gt;

&lt;p&gt;Khi \(r_{dual} = 0\) và \(r_{prim} = 0\) (tức là điểm lặp đồng thời khả thi gốc và khả thi đối ngẫu), khoảng cách đối ngẫu thay thế trở thành khoảng cách đối ngẫu thực sự \(\frac{m}{t}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[Tham khảo] Các điều kiện KKT bị nhiễu và tham số \(t\)&lt;/strong&gt; &lt;br /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Trong hệ điều kiện KKT bị nhiễu, tham số \(t\) liên hệ với cặp \((x, u)\) theo công thức \(t = -\frac{m}{h(x)^Tu}\).&lt;/li&gt;
  &lt;li&gt;Xem chi tiết tại &lt;a href=&quot;/contents/vi/chapter15/chapter16/15_03_01_perturbed_kkt_conditions/&quot;&gt;15-03-01 Điều kiện KKT nhiễu&lt;/a&gt; và &lt;a href=&quot;/contents/vi/chapter15/15_03_02_suboptimality_gap/&quot;&gt;15-03-02 Khoảng cách dưới tối ưu&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hơn nữa, nếu \(u &amp;gt; 0, h(x) &amp;lt; 0\) và thỏa mãn&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(r(x,u,v) = 0\) với \(\tau = -\frac{h(x)^Tu}{m}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;thì \((x, u, v)\) nằm chính xác trên đường trung tâm. Nói cách khác, tại mọi điểm thuộc đường trung tâm, toàn bộ phần dư đều bằng \(0\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>17-02-01 Phương trình đường trung tâm và bước Newton</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_02_01_central_path_equations_and_newton_step/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_02_01_central_path_equations_and_newton_step</id>
   <content type="html">&lt;p&gt;Mọi thuật toán Newton đều bắt đầu bằng một câu hỏi cốt lõi: &lt;em&gt;hệ phương trình phi tuyến cần giải là gì, và ma trận Jacobi của nó trông như thế nào?&lt;/em&gt; Khi gom cả điều kiện dừng đối ngẫu, điều kiện bù chặt bị nhiễu và ràng buộc đẳng thức gốc vào một vector phần dư duy nhất \(r_\tau(x, u, v) = 0\), ta thu được một hệ phương trình khối cực kỳ cân đối. Giải hệ tuyến tính hóa của nó chính là trái tim của mỗi vòng lặp PD-IPM.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-hệ-phương-trình-newton-gốcđối-ngẫu&quot;&gt;Kiến thức cần nhớ: Giải phẫu hệ phương trình Newton gốc–đối ngẫu&lt;/h2&gt;

&lt;p&gt;Trước khi nhìn vào ma trận khối \(3 \times 3\) trong bài học, hãy nắm rõ bốn mảnh ghép giải tích và đại số tuyến tính tạo nên nó:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ánh xạ phần dư \(r_\tau(x, u, v)\):&lt;/strong&gt; Ghép ba nhóm phương trình của điều kiện KKT bị nhiễu thành một ánh xạ vector từ \(\mathbb{R}^{n+m+p}\) vào \(\mathbb{R}^{n+m+p}\). Điểm trên đường trung tâm ứng với \(\tau\) chính là không điểm của ánh xạ này.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khai triển Taylor bậc nhất cho hệ vector:&lt;/strong&gt; Xấp xỉ \(r_\tau(w + \Delta w) \approx r_\tau(w) + Dr_\tau(w)\Delta w = 0\) biến bài toán giải hệ phi tuyến thành bài toán giải một hệ phương trình tuyến tính \(Dr_\tau(w)\Delta w = -r_\tau(w)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc ma trận Jacobi theo khối:&lt;/strong&gt; Hàng thứ nhất chứa Hessian của hàm Lagrange \(\nabla^2 f(x) + \sum_{i=1}^m u_i \nabla^2 h_i(x)\); hàng thứ hai chứa ma trận đường chéo \(U = \operatorname{diag}(u)\) và \(\operatorname{diag}(h(x))\); hàng thứ ba chứa ma trận ràng buộc tuyến tính \(A\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khử khối (Schur Complement):&lt;/strong&gt; Vì khối \(\operatorname{diag}(h(x))\) là ma trận đường chéo khả nghịch (do \(h_i(x) &amp;lt; 0\)), ta có thể khử biến \(\Delta u\) ngay lập tức bằng phép chia từng phần tử, thu gọn hệ về ma trận đối xứng nhỏ hơn chỉ theo \((\Delta x, \Delta v)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-hệ-newton-gốcđối-ngẫu-2-times-2-từng-con-số&quot;&gt;Giải thích: Giải tay hệ Newton gốc–đối ngẫu \(2 \times 2\) từng con số&lt;/h3&gt;

&lt;p&gt;Xét bài toán lồi 1 biến (không có ràng buộc đẳng thức \(Ax = b\)):&lt;/p&gt;

\[\min_{x} \; f(x) = \frac{1}{2}x^2 \qquad \text{với điều kiện} \qquad h(x) = 1 - x \le 0.\]

&lt;p&gt;Ta có \(\nabla f(x) = x\), \(\nabla^2 f(x) = 1\), \(\nabla h(x) = -1\), \(\nabla^2 h(x) = 0\). Hệ điều kiện KKT bị nhiễu với tham số \(\tau\) là:&lt;/p&gt;

\[r_{\text{dual}}(x, u) = x - u = 0, \qquad r_{\text{cent}}(x, u) = u(1 - x) + \tau = 0.\]

&lt;p&gt;Hãy tính chính xác một bước Newton từ điểm hiện tại \((x, u) = (2, 1)\) với \(\tau = 0.2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính vector phần dư \(r_\tau(2, 1)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(r_{\text{dual}} = 2 - 1 = 1\).&lt;/li&gt;
      &lt;li&gt;\(r_{\text{cent}} = 1 \cdot (1 - 2) + 0.2 = -0.8\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lập ma trận Jacobi \(Dr_\tau(x, u)\) tại \((2, 1)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đạo hàm của \(r_{\text{dual}} = x - u\) theo \((x, u)\) là \([1, \; -1]\).&lt;/li&gt;
      &lt;li&gt;Đạo hàm của \(r_{\text{cent}} = u(1 - x) + \tau\) theo \((x, u)\) là \([-u, \; 1 - x] = [-1, \; -1]\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải hệ phương trình tuyến tính \(Dr_\tau \Delta w = -r_\tau\):&lt;/strong&gt;
\(\begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; -1 \end{bmatrix} \begin{bmatrix} \Delta x \\ \Delta u \end{bmatrix} = -\begin{bmatrix} 1 \\ -0.8 \end{bmatrix} = \begin{bmatrix} -1 \\ 0.8 \end{bmatrix}.\)
Cộng hai phương trình: \(-2\Delta u = -0.2 \implies \Delta u = 0.1\). Thay lại vào phương trình đầu: \(\Delta x = \Delta u - 1 = -0.9\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điểm mới với bước đầy đủ \(\theta = 1\):&lt;/strong&gt;
\(x^+ = 2 - 0.9 = 1.1 &amp;gt; 1 \quad (h(x^+) = -0.1 &amp;lt; 0), \qquad u^+ = 1 + 0.1 = 1.1 &amp;gt; 0.\)
Tính lại phần dư tại \((1.1, 1.1)\): \(r_{\text{dual}}^+ = 1.1 - 1.1 = 0\), còn \(r_{\text{cent}}^+ = 1.1(-0.1) + 0.2 = +0.09\) (giảm mạnh từ \(-0.8\) xuống \(+0.09\)!). Chỉ sau một bước tuyến tính hóa, cả phần dư đối ngẫu lẫn phần dư trung tâm đều co rút ngoạn mục.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp điểm trong gốc-đối ngẫu (Primal-dual interior-point method)&lt;/strong&gt; tìm nghiệm tối ưu bằng cách bám theo đường trung tâm tương tự phương pháp chắn. Để làm điều này, thuật toán biểu diễn các điều kiện KKT bị nhiễu (perturbed KKT conditions) dưới dạng hàm phần dư và tìm nghiệm làm triệt tiêu các phần dư đó. Phần này trình bày chi tiết cách tiếp cận này.&lt;/p&gt;

&lt;h2 id=&quot;phương-trình-đường-trung-tâm&quot;&gt;Phương trình đường trung tâm&lt;/h2&gt;
&lt;p&gt;Chuyển toàn bộ vế phải sang vế trái trong hệ phương trình đường trung tâm đã nêu ở &lt;a href=&quot;/contents/vi/chapter17/17_01_barrier_method_duality_optimality_revisited/&quot;&gt;17-01 Điều kiện tối ưu&lt;/a&gt;, ta thu được hệ điều kiện KKT bị nhiễu:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
\nabla f(x) +\nabla h(x)u + A^Tv &amp;amp; = &amp;amp; 0 \\\
 Uh(x) + \tau\mathbb{1}  &amp;amp; = &amp;amp; 0 \\\
Ax-b &amp;amp; = &amp;amp; 0 \\\
u,-h(x)  &amp;amp; &amp;gt; &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Lưu ý sự khác biệt giữa điều kiện KKT của bài toán gốc và điều kiện KKT bị nhiễu: ở bài toán gốc ta có điều kiện bù chặt \(Uh(x) = 0\) và \(u, -h(x) \ge 0\), còn ở điều kiện KKT bị nhiễu ta có \(Uh(x) = -\tau\mathbb{1}\) và \(u, -h(x) \gt 0\).&lt;/p&gt;

&lt;p&gt;Hệ phương trình phi tuyến này có thể được giải xấp xỉ ở mỗi bước bằng cách tuyến tính hóa nó thông qua phiên bản tìm nghiệm (root-finding) của phương pháp Newton.&lt;/p&gt;

&lt;h2 id=&quot;bước-newton&quot;&gt;Bước Newton&lt;/h2&gt;
&lt;p&gt;Ta định nghĩa hệ ba phương trình đầu tiên là hàm phần dư \(r(x, u, v) = 0\) (gọi là phần dư vì các đại lượng này cần tiến về \(0\) tại nghiệm tối ưu):&lt;/p&gt;

&lt;blockquote&gt;
\[r(x,u,v) :=
\begin{bmatrix}
\nabla f(x) +\nabla h(x)u + A^Tv \\\
Uh(x) + \tau\mathbb{1} \\\
Ax-b
\end{bmatrix}, H(x) = \text{Diag}(h(x))\]
&lt;/blockquote&gt;

&lt;p&gt;Áp dụng khai triển Taylor bậc nhất để xấp xỉ tuyến tính phương trình \(r(x + \Delta x, u + \Delta u, v + \Delta v) = 0\) (xem chi tiết tại &lt;a href=&quot;/contents/vi/chapter14/14_01_newton_method/&quot;&gt;14-02-01 Tìm nghiệm&lt;/a&gt;):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
0 &amp;amp; = r(x + \Delta x, u + \Delta u, v + \Delta v)  \\\\
  &amp;amp; \approx r(x, u, v) + \nabla r(x, u, v) 
\begin{pmatrix}
\Delta x \\\\
\Delta u \\\\
\Delta v \\\\
\end{pmatrix} \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Suy ra hệ phương trình tuyến tính xác định bước Newton:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\nabla r(x, u, v) 
\begin{pmatrix}
\Delta x \\\\
\Delta u \\\\
\Delta v \\\\
\end{pmatrix} = -r(x, u, v) \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tính ma trận Jacobi \(\nabla r(x, u, v)\) bằng cách lấy đạo hàm riêng của \(r(x, u, v)\) theo \(x, u, v\) rồi thay vào hệ trên, ta thu được:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{bmatrix}
\nabla^2f(x) + \sum_i u_i \nabla^2h_i(x) &amp;amp; \nabla h(x) &amp;amp; A^T \\\
 U \nabla  h(x)^T &amp;amp; H(x) &amp;amp; 0 \\\
A &amp;amp; 0 &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
\Delta x \\\
\Delta u \\\
\Delta v
\end{bmatrix} = -r(x,u,v)\)
trong đó
\(r(x,u,v) :=
\begin{bmatrix}
\nabla f(x) +\nabla h(x)u + A^Tv \\\
Uh(x) + \tau\mathbb{1} \\\
Ax-b
\end{bmatrix}, H(x) = \text{Diag}(h(x))\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nghiệm \((\Delta x, \Delta u, \Delta v)\) của hệ tuyến tính này chính là hướng cập nhật cho cả biến gốc và biến đối ngẫu. Chính vì thuật toán cập nhật đồng thời biến gốc và biến đối ngẫu thông qua hàm phần dư nên nó được gọi là phương pháp điểm trong &lt;strong&gt;gốc-đối ngẫu (Primal-Dual)&lt;/strong&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>17-01 Ôn lại phương pháp chắn, đối ngẫu và điều kiện tối ưu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_01_barrier_method_duality_optimality_revisited/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter17/17_01_barrier_method_duality_optimality_revisited</id>
   <content type="html">&lt;p&gt;Trước khi cải tiến một cỗ máy, người kỹ sư giỏi luôn tháo nó ra xem từng bánh răng hoạt động ra sao. Phương pháp chắn (barrier method) ở Chương 15 thực ra đã ẩn chứa sẵn một bộ biến đối ngẫu cực kỳ đẹp mắt ngay tại mỗi điểm trên đường trung tâm \(x^\star(t)\). Khi viết lại điều kiện tối ưu của bài toán chắn dưới góc nhìn đối ngẫu, ta sẽ bất ngờ nhận ra rằng khoảng cách tối ưu đúng bằng \(m/t\) không phải là một ước lượng ngẫu nhiên, mà là hệ quả trực tiếp của điều kiện KKT bị nhiễu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cầu-nối-từ-hàm-chắn-sang-điều-kiện-kkt-bị-nhiễu&quot;&gt;Kiến thức cần nhớ: Cầu nối từ hàm chắn sang điều kiện KKT bị nhiễu&lt;/h2&gt;

&lt;p&gt;Bài ôn tập này móc nối bốn khái niệm then chốt từ các chương trước thành một khung thống nhất duy nhất:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chắn logarit (Logarithmic Barrier):&lt;/strong&gt; Thay vì ép cứng ràng buộc \(h_i(x) \le 0\), ta cộng thêm \(-\frac{1}{t}\sum_{i=1}^m \log(-h_i(x))\) để dựng một “bức tường vô hạn” dọc theo biên miền khả thi, biến bài toán có bất đẳng thức thành chuỗi bài toán chỉ có ràng buộc đẳng thức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng của bài toán chắn:&lt;/strong&gt; Đạo hàm của \(tf(x) - \sum_{i=1}^m \log(-h_i(x))\) bằng không tạo ra trọng số tự nhiên \(u_i^\star(t) = -\frac{1}{t h_i(x^\star(t))} &amp;gt; 0\). Đây chính là cách biến đối ngẫu “tự lộ diện” từ bài toán gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm đối ngẫu Lagrange và chứng chỉ tối ưu:&lt;/strong&gt; Thay cặp \((u^\star(t), v^\star(t))\) vào hàm đối ngẫu \(g(u, v)\) cho phép chứng minh chính xác \(f(x^\star(t)) - p^\star \le f(x^\star(t)) - g(u^\star(t), v^\star(t)) = m/t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải KKT bị nhiễu:&lt;/strong&gt; Nhân hai vế công thức định nghĩa \(u_i^\star(t)\) với \(-h_i(x^\star(t))\) cho ra \(-u_i^\star(t) h_i(x^\star(t)) = 1/t\) — phiên bản làm trơn của điều kiện bù chặt \(u_i h_i(x) = 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-điểm-đường-trung-tâm-và-kiểm-chứng-khoảng-cách-đối-ngẫu-mt&quot;&gt;Giải thích: Tính tay điểm đường trung tâm và kiểm chứng khoảng cách đối ngẫu \(m/t\)&lt;/h3&gt;

&lt;p&gt;Xét bài toán lồi 1 biến với \(m = 1\) ràng buộc bất đẳng thức:&lt;/p&gt;

\[\min_{x} f(x) = x^2 \qquad \text{với điều kiện} \qquad h(x) = 1 - x \le 0 \quad (\text{tức } x \ge 1).\]

&lt;p&gt;Nghiệm chính xác dễ thấy là \(x^\star = 1\), giá trị tối ưu \(p^\star = 1\). Bây giờ hãy giải bài toán chắn \(\min_{x &amp;gt; 1} \; t x^2 - \log(x - 1)\) bằng tay:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt; Đạo hàm theo \(x\) bằng \(0\) cho phương trình \(2tx - \frac{1}{x - 1} = 0 \iff 2tx^2 - 2tx - 1 = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại \(t = 1\):&lt;/strong&gt; Phương trình là \(2x^2 - 2x - 1 = 0\), nghiệm lớn hơn \(1\) là \(x^\star(1) = \frac{1 + \sqrt{3}}{2} \approx 1.3660\). Khi đó \(f(x^\star(1)) \approx 1.8660\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suy ra biến đối ngẫu từ điểm chắn:&lt;/strong&gt; \(u^\star(1) = -\frac{1}{t h(x^\star(1))} = \frac{1}{1 \cdot (1.3660 - 1)} \approx 2.7321 &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng hàm đối ngẫu và khoảng cách \(m/t\):&lt;/strong&gt; Với \(u &amp;gt; 0\), hàm đối ngẫu là \(g(u) = \min_x (x^2 + u(1 - x)) = u - \frac{u^2}{4}\). Tại \(u^\star(1) \approx 2.7321\), ta có \(g(u^\star(1)) = 2.7321 - \frac{2.7321^2}{4} \approx 0.8660\). Hiệu số \(f(x^\star(1)) - g(u^\star(1)) = 1.8660 - 0.8660 = 1.0000 = \frac{1}{t}\) — khớp tuyệt đối với công thức \(m/t\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tăng lên \(t = 10\):&lt;/strong&gt; Giải \(20x^2 - 20x - 1 = 0\) được \(x^\star(10) = \frac{20 + \sqrt{480}}{40} \approx 1.0477\), lúc này \(f(x^\star(10)) - g(u^\star(10)) = \frac{1}{10} = 0.1\), và điểm \(x^\star(t)\) tiến sát nghiệm \(x^\star = 1\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Ở Chương 15 chúng ta đã tìm hiểu phương pháp chắn (barrier method), còn ở Chương 13 và Chương 16 chúng ta đã xét lý thuyết đối ngẫu. Trước khi đi sâu vào nội dung chương này, ta ôn lại ngắn gọn các khái niệm cốt lõi đó.&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-chắn&quot;&gt;Phương pháp chắn&lt;/h2&gt;
&lt;p&gt;Xét bài toán gốc (primal) lồi với các hàm \(f, h_i \ (i = 1, \dots, m)\) khả vi:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp; f(x) \\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;h_{i}(x) \leq 0, i = 1, \dotsc, m \\
&amp;amp;&amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Sử dụng hàm chắn logarit, ta chuyển bài toán gốc sang bài toán chắn tương ứng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \min_{x} &amp;amp;&amp;amp; f(x) + \frac{1}{t} \phi(x) &amp;amp; \qquad &amp;amp; \min_{x} &amp;amp;&amp;amp; tf(x) + \phi(x) \\
&amp;amp; \text{subject to } &amp;amp;&amp;amp; Ax = b &amp;amp; \iff \qquad &amp;amp; \text{subject to } &amp;amp;&amp;amp; Ax = b \\
&amp;amp; \text{where } &amp;amp;&amp;amp; \phi(x) = - \sum_{i=1}^{m} \log(-h_i(x))
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Thuật toán khởi tạo với \(t = t^{(0)} &amp;gt; 0\) và tăng dần \(t\) cho đến khi \(\frac{m}{t} \le \epsilon\). Tại mỗi vòng lặp \(k = 0, 1, 2, \dots\), phương pháp Newton được dùng để giải bài toán chắn nhằm tìm \(x^{\star}(t)\) với điểm khởi tạo \(x^{(k)}\), rồi gán \(x^{(k+1)} = x^{\star}(t)\).&lt;/p&gt;

&lt;p&gt;Thuật toán có thể được tóm tắt như sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Chọn \(t^{(0)} \gt 0\) và đặt \(k := 0\).&lt;/li&gt;
  &lt;li&gt;Giải bài toán chắn tại \(t = t^{(0)}\) để tìm \(x^{(0)} = x^{\star}(t^{(0)})\).&lt;/li&gt;
  &lt;li&gt;Khi \(m/t^{(k)} \gt \epsilon\), lặp:&lt;br /&gt;
  3-1. Cập nhật \(t^{(k+1)} = \mu t^{(k)}\) với \(\mu &amp;gt; 1\).&lt;br /&gt;
  3-2. Khởi tạo phương pháp Newton từ \(x^{(k)}\) (khởi động ấm — warm start) và giải bài toán chắn tại \(t = t^{(k+1)}\) để tìm \(x^{(k+1)} = x^{\star}(t^{(k+1)})\).&lt;br /&gt;
  3-3. Tăng \(k := k + 1\).&lt;br /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;Xem chi tiết tại &lt;a href=&quot;/contents/vi/chapter15/15_01_02_log_barrier_function_and_barrier_method/&quot;&gt;15-01-02 Hàm chắn logarit và phương pháp chắn&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;đối-ngẫu&quot;&gt;Đối ngẫu&lt;/h2&gt;
&lt;p&gt;Xét bài toán gốc:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad f(x) \\\\
   \text{subject to} &amp;amp;\quad Ax = b \\\\
   &amp;amp;\quad h(x) \le 0
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Hàm Lagrange tương ứng là:&lt;/p&gt;
&lt;blockquote&gt;
\[L(x,u,v) = f(x) + u^Th(x) + v^T(Ax - b)\]
&lt;/blockquote&gt;

&lt;p&gt;Từ hàm Lagrange này, bài toán gốc và bài toán đối ngẫu có thể được viết lại như sau (xem chi tiết tại Chương 16):&lt;br /&gt;&lt;/p&gt;
&lt;h3 id=&quot;bài-toán-gốc&quot;&gt;Bài toán gốc&lt;/h3&gt;
&lt;blockquote&gt;
\[\min_x \mathop{\max_{u,v}}_{u \geq 0} L(x,u,v)\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;bài-toán-đối-ngẫu&quot;&gt;Bài toán đối ngẫu&lt;/h3&gt;
&lt;blockquote&gt;
\[\mathop{\max_{u,v}}_{u \geq 0} \min_x L(x,u,v)\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;điều-kiện-tối-ưu&quot;&gt;Điều kiện tối ưu&lt;/h2&gt;

&lt;p&gt;Khi \(f, h_1, \dots, h_m\) lồi, khả vi và bài toán thỏa mãn tính đối ngẫu mạnh, các điều kiện tối ưu KKT có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{array}{rcl}
\nabla f(x) +\nabla h(x)u + A^Tv &amp;amp; = &amp;amp; 0 &amp;amp; \text{(Tính dừng)}\\\
 Uh(x) &amp;amp; = &amp;amp; 0 &amp;amp; \text{(Bù chặt)} \\\
Ax &amp;amp; = &amp;amp; b &amp;amp; \text{(Khả thi gốc)}\\\
u,-h(x)  &amp;amp; \ge &amp;amp; 0 &amp;amp; \text{(Khả thi gốc và đối ngẫu)}
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong đó, \(U = \text{diag}(u)\) và \(\nabla h(x) = [ \nabla h_1(x) \ \cdots \ \nabla h_m(x) ]\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Xem chi tiết tại &lt;a href=&quot;/contents/vi/chapter12/12_00_KKT_conditions/&quot;&gt;Chương 12 Điều kiện KKT&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;phương-trình-đường-trung-tâm&quot;&gt;Phương trình đường trung tâm&lt;/h2&gt;
&lt;p&gt;Ta có thể viết lại bài toán chắn theo tham số \(\tau = \frac{1}{t}\). Khi cho \(\tau\) tiến dần về \(0\) và giải lặp lại bài toán chắn, ta thu được nghiệm hội tụ về nghiệm tối ưu của bài toán gốc:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp; {f(x) + \tau\phi(x)} \\\\
&amp;amp; &amp;amp;&amp;amp;{Ax = b} \\\
&amp;amp; \text{where } &amp;amp;&amp;amp; \phi(x) = -\sum_{i=1}^m \log(-h_i(x)).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Như vậy, mức sai khác so với bài toán gốc phụ thuộc vào \(\tau\), và tập hợp các nghiệm tương ứng theo tham số \(\tau &amp;gt; 0\) tạo thành quỹ đạo gọi là &lt;strong&gt;đường trung tâm (central path)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Các điều kiện tối ưu cho bài toán chắn là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
\nabla f(x) +\nabla h(x)u + A^Tv  &amp;amp; = &amp;amp; 0 \\\
Uh(x) &amp;amp; = &amp;amp; -\tau\mathbb{1} \\\
Ax &amp;amp; = &amp;amp; b \\\
u,-h(x)  &amp;amp; &amp;gt; &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Xem chi tiết tại &lt;a href=&quot;/contents/vi/chapter16/16_02_optimality_conditions/&quot;&gt;16-02 Điều kiện tối ưu&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp điểm trong gốc-đối ngẫu (Primal-Dual interior-point method)&lt;/strong&gt; trong chương này định nghĩa ba phương trình đầu tiên ở trên thành các phần dư (residual) và tìm nghiệm bằng cách đưa chúng tiến về \(0\).&lt;/p&gt;

&lt;h4 id=&quot;một-tính-chất-hữu-ích&quot;&gt;Một tính chất hữu ích&lt;/h4&gt;
&lt;p&gt;Nghiệm \((x(\tau), u(\tau), v(\tau))\) trên đường trung tâm có khoảng cách đối ngẫu (duality gap) đúng bằng \(m\tau = \frac{m}{t}\):&lt;/p&gt;
&lt;blockquote&gt;
\[f(x(\tau))-\min_x L(x,u(\tau),v(\tau)) = m\tau= \frac{m}{t}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>17 Primal-Dual Interior-Point Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_primal_dual_interior_point_method/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_primal_dual_interior_point_method</id>
   <content type="html">&lt;p&gt;Imagine piloting a glider down a deep, steep-walled canyon toward a tiny landing strip wedged in the corner where two sheer cliffs meet. The classical log-barrier method from Chapter 15 flies cautiously: it freezes an altitude parameter, takes a full sequence of Newton corrections until it sits dead-center in the canyon, then drops the altitude slightly and repeats the entire centering ritual. &lt;strong&gt;Primal-dual interior-point methods (PD-IPMs)&lt;/strong&gt; throw away that inner loop. Instead of solving a sequence of subproblems to high precision, they treat the primal variables, dual multipliers, and complementarity conditions as one coupled nonlinear system—taking a &lt;em&gt;single&lt;/em&gt; damped Newton step per iteration that simultaneously drives feasibility and optimality to zero.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-architecture-of-primal-dual-interior-point-methods&quot;&gt;Key ideas: The Architecture of Primal-Dual Interior-Point Methods&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Perturbed KKT Systems &amp;amp; the Central Path:&lt;/strong&gt; Rather than minimizing an unconstrained barrier objective directly, PD-IPMs formulate optimality as root-finding on the perturbed KKT map \(r_\tau(x, u, v) = 0\), where complementary slackness \(u_i h_i(x) = 0\) is relaxed to \(u_i h_i(x) = -\tau\) for \(\tau &amp;gt; 0\). Driving \(\tau \to 0\) traces a smooth analytic curve—the &lt;em&gt;central path&lt;/em&gt;—leading directly into the optimal primal-dual face.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simultaneous Newton Linearization:&lt;/strong&gt; Applying Newton’s root-finding method directly to \(r_\tau(x, u, v) = 0\) produces a single coupled linear system for \((\Delta x, \Delta u, \Delta v)\). Because primal and dual variables inform each other inside the same Jacobian, one step can make dramatic progress without ever converging an inner centering loop.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infeasible-Start Trajectory &amp;amp; Surrogate Duality Gap:&lt;/strong&gt; Unlike the barrier method, PD-IPMs do not require \(Ax^k = b\) or dual feasibility at intermediate iterates—only strict positivity of slacks and multipliers (\(-h(x^k) &amp;gt; 0, u^k &amp;gt; 0\)). Progress is tracked jointly via the primal/dual residual norms and the &lt;em&gt;surrogate duality gap&lt;/em&gt; \(\eta = -h(x)^T u\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic Generality (LP, QP, SOCP, SDP):&lt;/strong&gt; The primal-dual framework lifts effortlessly from nonnegative orthants (Linear Programming) to symmetric positive semidefinite cones (Semidefinite Programming), powering modern solvers such as Clarabel, MOSEK, and SDPT3 with polynomial-time worst-case complexity and superlinear local convergence.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-primal-dual-step-vs-barrier-centering&quot;&gt;Worked example: One Primal-Dual Step vs. Barrier Centering&lt;/h3&gt;

&lt;p&gt;Consider the minimal 1D constrained problem \(\min_{x \in \mathbb{R}} x\) subject to \(h(x) = -x \le 0\) (exact optimum \(x^\star = 0, u^\star = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the perturbed KKT residual:&lt;/strong&gt;
With \(f&apos;(x) = 1\) and \(h&apos;(x) = -1\), the perturbed KKT conditions for target \(\tau &amp;gt; 0\) are:
\(r_\tau(x, u) = \begin{bmatrix} 1 - u \\ -u x + \tau \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}, \quad x &amp;gt; 0, \; u &amp;gt; 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Start from a dual-infeasible interior point:&lt;/strong&gt;
Take \((x^0, u^0) = (2, 0.5)\). Note that \(r_{\text{dual}}^0 = 1 - 0.5 = 0.5 \neq 0\), and the surrogate duality gap is \(\eta_0 = -h(x^0) u^0 = (2)(0.5) = 1.0\). With centering parameter \(\sigma = 0.5\), set \(\tau = \sigma \eta_0 / m = 0.5(1.0)/1 = 0.5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form and solve the single primal-dual Newton system:&lt;/strong&gt;
The Jacobian of \(r_\tau\) is \(J(x, u) = \begin{bmatrix} 0 &amp;amp; -1 \\ -u &amp;amp; -x \end{bmatrix} = \begin{bmatrix} 0 &amp;amp; -1 \\ -0.5 &amp;amp; -2 \end{bmatrix}\), and \(r_\tau(2, 0.5) = \begin{bmatrix} 0.5 \\ -0.5 \end{bmatrix}\). Solving \(J \Delta z = -r_\tau\):
\(-\Delta u = -0.5 \implies \Delta u = 0.5,\)
\(-0.5\,\Delta x - 2(0.5) = 0.5 \implies -0.5\,\Delta x = 1.5 \implies \Delta x = -3.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply fraction-to-the-boundary damping:&lt;/strong&gt;
A full step \(\theta = 1\) would give \(x^0 + \Delta x = 2 - 3 = -1 &amp;lt; 0\), violating \(x &amp;gt; 0\). The maximum boundary step is \(\theta_{\max} = \frac{2}{3}\). Choosing \(\theta = 0.5 &amp;lt; \theta_{\max}\) yields:
\(x^1 = 2 + 0.5(-3) = 0.5 &amp;gt; 0, \qquad u^1 = 0.5 + 0.5(0.5) = 0.75 &amp;gt; 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify simultaneous progress:&lt;/strong&gt;
In just &lt;em&gt;one&lt;/em&gt; linear solve, the dual residual dropped in half (\(0.5 \to 0.25\)) and the surrogate gap fell by \(62.5\%\) (\(1.0 \to 0.5 \times 0.75 = 0.375\)), with no inner centering loop required.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we will examine the &lt;strong&gt;Primal-Dual Interior-Point Method&lt;/strong&gt;, which improves performance by reducing the centering step of the Barrier method we learned earlier to a single step.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Primal-Dual Interior-Point Method&lt;/strong&gt; relaxes the constraint that the centering step must be feasible and uses the root finding version of Newton’s Method to approximate nonlinear equations with linear equations to find solutions, making it faster and more accurate than the Barrier method.&lt;/p&gt;

&lt;h2 id=&quot;references-and-further-readings&quot;&gt;References and further readings&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;S. Boyd and L. Vandenberghe (2004), “Convex optimization,” Chapter 11&lt;/li&gt;
  &lt;li&gt;S. Wright (1997), “Primal-dual interior-point methods,” Chapters 5 and 6&lt;/li&gt;
  &lt;li&gt;J. Renegar (2001), “A mathematical view of interior-point methods”&lt;/li&gt;
  &lt;li&gt;Y. Nesterov and M. Todd (1998), “Primal-dual interior-point methods for self-scaled cones.” SIAM J. Optim.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>17-08 Practical Exercises - Primal-Dual Interior Point</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_08_Practical_Exercises_Primal_Dual_Interior_Point/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_08_Practical_Exercises_Primal_Dual_Interior_Point</id>
   <content type="html">&lt;p&gt;Theory tells you that primal-dual interior-point methods converge in \(O(\sqrt{n}\log(1/\epsilon))\) iterations; actually computing the KKT Jacobian, solving the normal equations, and tracking \(\theta_{\max}\) by hand reveals &lt;em&gt;why&lt;/em&gt; every single safeguard in a production solver exists. Before diving into the graded exercises below, warm up with a concrete comparison of the &lt;strong&gt;affine-scaling (\(\sigma = 0\))&lt;/strong&gt; direction against the &lt;strong&gt;centered (\(\sigma &amp;gt; 0\))&lt;/strong&gt; direction—the exact split that powers Mehrotra’s predictor-corrector algorithm.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-paper-equations-to-working-solvers&quot;&gt;Key ideas: From Paper Equations to Working Solvers&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Exact Central-Path Algebra:&lt;/strong&gt; Setting up \(X S \mathbf{1} = \mu \mathbf{1}\) alongside primal-dual feasibility lets you trace the closed-form central path for low-dimensional LPs and SDPs.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine-Scaling vs. Centering Directions:&lt;/strong&gt; Setting \(\sigma = 0\) aims straight for \(XS\mathbf{1} = 0\) (maximum gap reduction, high risk of hitting the boundary early), while \(\sigma &amp;gt; 0\) pulls iterates back toward the central path so larger steps become possible.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fraction-to-the-Boundary Ratio Test:&lt;/strong&gt; Computing \(\alpha_p = \min_{\Delta x_i &amp;lt; 0}(-x_i / \Delta x_i)\) and \(\alpha_d = \min_{\Delta s_i &amp;lt; 0}(-s_i / \Delta s_i)\) prevents negative slacks or multipliers and determines how much of the Newton step can be taken.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Implementation &amp;amp; Verification:&lt;/strong&gt; Coding a small primal-dual solver in Python/NumPy lets you observe quadratic local convergence on LPs and verify \(\|r_p\|, \|r_d\|, \mu \to 0\) numerically.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-affine-scaling-vs-centered-step-on-a-2-variable-lp&quot;&gt;Worked example: Affine-Scaling vs. Centered Step on a 2-Variable LP&lt;/h3&gt;

&lt;p&gt;Consider \(\min 3x_1 + x_2\) subject to \(x_1 + 2x_2 = 4\) and \(x_1, x_2 \ge 0\) (exact optimum \(x^\star = (0, 2), y^\star = 0.5, s^\star = (2.5, 0)\)). Start at the feasible interior point \(x = (2, 1)^T, y = 0, s = (3, 1)^T\) (verify: \(x_1 + 2x_2 = 4\) and \(A^T y + s = (3, 1)^T = c\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the scaling matrix and duality measure:&lt;/strong&gt;
\(\mu = \frac{x^T s}{2} = \frac{2(3) + 1(1)}{2} = 3.5, \qquad D^2 = S^{-1} X = \operatorname{diag}\!\left(\frac{2}{3}, 1\right).\)
With \(A = [1, 2]\), the normal-equations scalar is:
\(A D^2 A^T = 1^2\!\left(\frac{2}{3}\right) + 2^2(1) = \frac{14}{3}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the pure affine-scaling step (\(\sigma = 0\)):&lt;/strong&gt;
The right-hand side is \(A x = 4\), so \(\Delta y^{\text{aff}} = \frac{4}{14/3} = \frac{6}{7}\).
Then \(\Delta s^{\text{aff}} = -A^T \Delta y^{\text{aff}} = \left(-\frac{6}{7}, -\frac{12}{7}\right)^T\).
Notice \(s_2 + \Delta s_2^{\text{aff}} = 1 - \frac{12}{7} = -\frac{5}{7} &amp;lt; 0\)! The dual boundary ratio test caps the step at \(\alpha_d^{\max} = \frac{1}{12/7} = \frac{7}{12} \approx 0.583\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Now add centering (\(\sigma = 0.5 \implies \sigma \mu = 1.75\)):&lt;/strong&gt;
The right-hand side shrinks to \(A(x - 1.75 S^{-1}\mathbf{1}) = \left(2 - \frac{1.75}{3}\right) + 2(1 - 1.75) = \frac{17}{12} - \frac{3}{2} = -\frac{1}{12}\).
Thus \(\Delta y^{\text{cent}} = \frac{-1/12}{14/3} = -\frac{1}{56}\), giving \(\Delta s^{\text{cent}} = \left(+\frac{1}{56}, +\frac{2}{56}\right)^T\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare the two steps:&lt;/strong&gt;
The aggressive \(\sigma = 0\) step pushes hard toward the optimum but hits the \(s_2 = 0\) wall at \(\theta = 0.583\); adding centering dramatically pulls \(s_2\) away from the wall so subsequent iterations can take nearly full unit steps. You are now ready to tackle the exercises below!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---primal-dual-interior-point-methods&quot;&gt;Practical Exercises - Primal-Dual Interior Point Methods&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Wright (1997) and Nesterov &amp;amp; Nemirovskii (1994).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-1-primal-dual-central-path-for-an-lp&quot;&gt;📝 &lt;strong&gt;Exercise 1: Primal-Dual Central Path for an LP&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Consider the LP:&lt;/p&gt;

\[\begin{align}
\min \quad &amp;amp; x_1 + 2x_2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 = 3 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the KKT conditions&lt;br /&gt;
b) Derive the perturbed KKT conditions with parameter \(\mu\)&lt;br /&gt;
c) Compute the central path \(x(\mu)\) for \(\mu = 1, 0.1, 0.01\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) KKT conditions:**

$$
\begin{align}
\nabla f + A^T\nu - \lambda &amp;amp;= 0 \quad \text{(stationarity)} \\
Ax &amp;amp;= b \quad \text{(primal feasibility)} \\
x &amp;amp;\geq 0, \, \lambda \geq 0 \quad \text{(dual feasibility)} \\
\lambda_i x_i &amp;amp;= 0 \quad \text{(complementarity)}
\end{align}
$$

With the data:

$$
\begin{align}
\begin{bmatrix} 1 \\ 2 \end{bmatrix} + \nu \begin{bmatrix} 1 \\ 1 \end{bmatrix} - \begin{bmatrix} \lambda_1 \\ \lambda_2 \end{bmatrix} &amp;amp;= 0 \\
x_1 + x_2 &amp;amp;= 3 \\
\lambda_1 x_1 = \lambda_2 x_2 &amp;amp;= 0
\end{align}
$$

---

**b) Perturbed KKT (central path conditions):**

Replace complementarity $$\lambda_i x_i = 0$$ with:

$$\lambda_i x_i = \mu \quad \forall i$$

$$
\begin{cases}
1 + \nu - \lambda_1 = 0 \\
2 + \nu - \lambda_2 = 0 \\
x_1 + x_2 = 3 \\
\lambda_1 x_1 = \mu \\
\lambda_2 x_2 = \mu
\end{cases}
$$

---

**c) Solve for central path:**

From (1): $$\lambda_1 = 1 + \nu$$  
From (2): $$\lambda_2 = 2 + \nu$$  
From (4): $$x_1 = \frac{\mu}{1 + \nu}$$  
From (5): $$x_2 = \frac{\mu}{2 + \nu}$$  

Substitute into (3):

$$\frac{\mu}{1+\nu} + \frac{\mu}{2+\nu} = 3$$

$$\mu\left(\frac{1}{1+\nu} + \frac{1}{2+\nu}\right) = 3$$

$$\mu \cdot \frac{(2+\nu) + (1+\nu)}{(1+\nu)(2+\nu)} = 3$$

$$\mu \cdot \frac{3 + 2\nu}{(1+\nu)(2+\nu)} = 3$$

$$(1+\nu)(2+\nu) = \mu(1 + \frac{2\nu}{3})$$

Solve quadratic: $$\nu^2 + 3\nu + 2 = \mu + \frac{2\mu\nu}{3}$$

**For $$\mu = 1$$:**

$$\nu^2 + 3\nu + 2 = 1 + \frac{2\nu}{3}$$

$$\nu^2 + \frac{7\nu}{3} + 1 = 0$$

$$\nu = \frac{-7/3 \pm \sqrt{49/9 - 4}}{2} \in \{-0.566, -1.768\}$$

Only the root with $$\nu &amp;gt; -1$$ gives $$\lambda_1, \lambda_2 &amp;gt; 0$$, so we take $$\nu \approx -0.566$$, and $$x_1 = \frac{1}{1-0.566} \approx 2.30$$, $$x_2 = \frac{1}{2-0.566} \approx 0.70$$ (check: $$x_1 + x_2 = 3$$ ✓).

**For $$\mu = 0.1$$:** $$\nu \approx -0.9656$$, $$x \approx (2.90, 0.097)$$.

**For $$\mu = 0.01$$:** $$\nu \approx -0.9967$$, $$x \approx (2.99, 0.010)$$.

**As $$\mu \to 0$$:** $$x^* \to (3, 0)$$ (the primal optimal solution), $$\nu^* \to -1$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-newton-step-for-the-primal-dual-system&quot;&gt;📝 &lt;strong&gt;Exercise 2: Newton Step for the Primal-Dual System&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Consider the LP from Exercise 1. At \((x, \lambda, \nu)^{(k)}\), solve the Newton system:&lt;/p&gt;

\[\begin{bmatrix}
0 &amp;amp; A^T &amp;amp; -I \\
A &amp;amp; 0 &amp;amp; 0 \\
\Lambda &amp;amp; 0 &amp;amp; X
\end{bmatrix}
\begin{bmatrix}
\Delta x \\
\Delta \nu \\
\Delta \lambda
\end{bmatrix}
=
-\begin{bmatrix}
r_d \\
r_p \\
r_c
\end{bmatrix}\]

&lt;p&gt;where \(\Lambda = \text{diag}(\lambda)\), \(X = \text{diag}(x)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the residuals \(r_d, r_p, r_c\)&lt;br /&gt;
b) Simplify the system by eliminating \(\Delta\lambda\)&lt;br /&gt;
c) Compute \(\Delta x\) for \(x = (1, 1)\), \(\lambda = (2, 3)\), \(\nu = -1\), \(\mu = 0.5\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Residuals:**

$$
\begin{align}
r_d &amp;amp;= \nabla f + A^T\nu - \lambda = \begin{bmatrix} 1 \\ 2 \end{bmatrix} + \nu \begin{bmatrix} 1 \\ 1 \end{bmatrix} - \begin{bmatrix} \lambda_1 \\ \lambda_2 \end{bmatrix} \\
r_p &amp;amp;= Ax - b = x_1 + x_2 - 3 \\
r_c &amp;amp;= \Lambda X e - \mu e = \begin{bmatrix} \lambda_1 x_1 - \mu \\ \lambda_2 x_2 - \mu \end{bmatrix}
\end{align}
$$

---

**b) Eliminate $$\Delta\lambda$$:**

From row 3: $$\Lambda \Delta x + X \Delta\lambda = -r_c$$

$$\Delta\lambda = -X^{-1}(\Lambda \Delta x + r_c)$$

Substitute into row 1:

$$A^T \Delta\nu - \Delta\lambda = -r_d$$

$$A^T \Delta\nu + X^{-1}(\Lambda \Delta x + r_c) = -r_d$$

$$\Lambda X^{-1} \Delta x + A^T \Delta\nu = -r_d - X^{-1}r_c$$

Combined with row 2:

$$
\begin{bmatrix}
\Lambda X^{-1} &amp;amp; A^T \\
A &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
\Delta x \\
\Delta \nu
\end{bmatrix}
=
\begin{bmatrix}
-r_d - X^{-1}r_c \\
-r_p
\end{bmatrix}
$$

---

**c) Numerical computation:**

$$x = (1, 1)$$, $$\lambda = (2, 3)$$, $$\nu = -1$$, $$\mu = 0.5$$

$$r_d = \begin{bmatrix} 1-1-2 \\ 2-1-3 \end{bmatrix} = \begin{bmatrix} -2 \\ -2 \end{bmatrix}$$

$$r_p = 1 + 1 - 3 = -1$$

$$r_c = \begin{bmatrix} 2 \cdot 1 - 0.5 \\ 3 \cdot 1 - 0.5 \end{bmatrix} = \begin{bmatrix} 1.5 \\ 2.5 \end{bmatrix}$$

$$\Lambda X^{-1} = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 3 \end{bmatrix} \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 3 \end{bmatrix}$$

$$-r_d - X^{-1}r_c = \begin{bmatrix} 2 \\ 2 \end{bmatrix} - \begin{bmatrix} 1.5 \\ 2.5 \end{bmatrix} = \begin{bmatrix} 0.5 \\ -0.5 \end{bmatrix}$$

System:

$$
\begin{bmatrix}
2 &amp;amp; 0 &amp;amp; 1 \\
0 &amp;amp; 3 &amp;amp; 1 \\
1 &amp;amp; 1 &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
\Delta x_1 \\
\Delta x_2 \\
\Delta \nu
\end{bmatrix}
=
\begin{bmatrix}
0.5 \\
-0.5 \\
1
\end{bmatrix}
$$

Solving the system: $$\Delta x = (0.8, 0.2)$$, $$\Delta\nu = -1.1$$ (check: $$2(0.8) - 1.1 = 0.5$$, $$3(0.2) - 1.1 = -0.5$$, $$0.8 + 0.2 = 1$$ ✓)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-mehrotra-predictor-corrector&quot;&gt;📝 &lt;strong&gt;Exercise 3: Mehrotra Predictor-Corrector&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Mehrotra’s algorithm combines predictor and corrector steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Predictor:&lt;/strong&gt; \(\mu = 0\) (affine scaling)&lt;br /&gt;
&lt;strong&gt;Corrector:&lt;/strong&gt; \(\mu = \sigma \cdot \frac{x^T\lambda}{n}\) with \(\sigma \in (0, 1)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Explain the intuition behind the 2 steps&lt;br /&gt;
b) Compute \(\sigma\) from the predictor step&lt;br /&gt;
c) Apply to the LP from Exercise 1&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Intuition:**

**Predictor (affine):** Aim toward optimal set ($$\mu = 0$$), aggressive move.

**Corrector (centering):** Pull back toward central path, ensure feasibility and good convergence.

**Adaptive $$\sigma$$:** Based on predictor quality:
- Good predictor → small $$\sigma$$ (more aggressive)
- Bad predictor → large $$\sigma$$ (more conservative)

---

**b) Computing $$\sigma$$:**

After affine step $$(\tilde{x}, \tilde{\lambda})$$:

$$\tilde{\mu} = \frac{\tilde{x}^T\tilde{\lambda}}{n}$$

$$\sigma = \left(\frac{\tilde{\mu}}{\mu}\right)^3$$

(cubic heuristic for fast convergence)

---

**c) Example:**

Current: $$x = (2, 1)$$, $$\lambda = (1, 2)$$, $$\mu = \frac{2 \cdot 1 + 1 \cdot 2}{2} = 2$$

**Predictor ($$\mu_{\text{aff}} = 0$$):**

$$\tilde{x} = (2.5, 0.5)$$, $$\tilde{\lambda} = (0.5, 1.5)$$

$$\tilde{\mu} = \frac{2.5 \cdot 0.5 + 0.5 \cdot 1.5}{2} = \frac{2}{2} = 1$$

$$\sigma = \left(\frac{1}{2}\right)^3 = 0.125$$

**Corrector:** Target $$\mu_{\text{new}} = 0.125 \cdot 2 = 0.25$$

Small $$\sigma$$ → aggressive reduction!

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-infeasible-start&quot;&gt;📝 &lt;strong&gt;Exercise 4: Infeasible Start&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Consider an infeasible start \((x^{(0)}, \lambda^{(0)}, \nu^{(0)})\) that does not satisfy \(Ax = b\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Modify the residuals to handle infeasibility&lt;br /&gt;
b) Show convergence to primal-dual feasibility&lt;br /&gt;
c) Apply to the LP with \(x^{(0)} = (1, 1)\) (infeasible for \(x_1 + x_2 = 3\))&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Modified residuals:**

Allow primal infeasibility $$r_p = Ax - b \neq 0$$ initially.

Newton system remains:

$$
\begin{bmatrix}
0 &amp;amp; A^T &amp;amp; -I \\
A &amp;amp; 0 &amp;amp; 0 \\
\Lambda &amp;amp; 0 &amp;amp; X
\end{bmatrix}
\begin{bmatrix}
\Delta x \\
\Delta \nu \\
\Delta \lambda
\end{bmatrix}
=
-\begin{bmatrix}
r_d \\
r_p \\
r_c
\end{bmatrix}
$$

As iterations progress, $$\|r_p\| \to 0$$.

---

**b) Convergence:**

Each Newton step reduces $$\|(r_d, r_p, r_c)\|$$ quadratically near solution.

**Infeasible primal-dual:** Both $$x$$ and $$(\lambda, \nu)$$ converge simultaneously.

---

**c) Example:**

$$x^{(0)} = (1, 1)$$, $$r_p = 1 + 1 - 3 = -1$$

After one full Newton step ($$\alpha = 1$$), for example $$x^{(1)} = (1.5, 1.5)$$, we get $$r_p = 0$$ (feasible!), because $$A\Delta x = -r_p$$. (With a damped step $$\alpha &amp;lt; 1$$, $$r_p$$ is only reduced by a factor $$1-\alpha$$.)

Then continue as standard primal-dual IPM.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-self-concordance-and-polynomial-complexity&quot;&gt;📝 &lt;strong&gt;Exercise 5: Self-Concordance and Polynomial Complexity&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Interior point methods have polynomial complexity thanks to self-concordant barriers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Define self-concordance&lt;br /&gt;
b) Show \(\phi(x) = -\sum \log x_i\) is self-concordant&lt;br /&gt;
c) Explain why this gives \(O(\sqrt{n} \log(1/\epsilon))\) iterations&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Self-concordance:**

$$\phi$$ is self-concordant if:

$$|\phi&apos;&apos;&apos;(x)[h, h, h]| \leq 2(\phi&apos;&apos;(x)[h, h])^{3/2} \quad \forall h$$

**Meaning:** the third derivative is controlled by the second derivative.

---

**b) Log barrier:**

$$\phi(x) = -\sum_{i=1}^n \log x_i$$

$$\phi&apos;(x) = -\sum \frac{1}{x_i} e_i$$

$$\phi&apos;&apos;(x) = \sum \frac{1}{x_i^2} e_i e_i^T = \text{diag}(1/x_1^2, \ldots, 1/x_n^2)$$

$$\phi&apos;&apos;&apos;(x)[h, h, h] = -\sum \frac{2}{x_i^3} h_i^3$$

Check:

$$|\phi&apos;&apos;&apos;[h,h,h]| = 2\sum \frac{|h_i|^3}{x_i^3} \leq 2\left(\sum \frac{h_i^2}{x_i^2}\right)^{3/2}$$

$$= 2(\phi&apos;&apos;[h,h])^{3/2}$$ ✓

---

**c) Polynomial complexity:**

Self-concordance → Newton step has predictable damping.

**Key idea:** the barrier parameter of $$\phi(x) = -\sum_{i=1}^n \log x_i$$ on the orthant $$\mathbb{R}^n_+$$ is $$\vartheta = n$$. Each iteration reduces $$\mu$$ by a factor $$\left(1 - \frac{1}{\sqrt{\vartheta}}\right)$$ with only $$O(1)$$ Newton steps, so $$O(\sqrt{\vartheta}\log(1/\epsilon)) = O(\sqrt{n}\log(1/\epsilon))$$ iterations are needed to bring $$\mu$$ below $$\epsilon$$.

**Total:** $$O(\sqrt{n} \log(1/\epsilon))$$ iterations.

**Polynomial!** (versus the worst-case exponential complexity of the simplex method)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;primal-dual-ipm-components&quot;&gt;&lt;strong&gt;Primal-Dual IPM Components:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Component&lt;/th&gt;
      &lt;th&gt;Purpose&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Central path&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Smooth trajectory to optimum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Perturbed KKT&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\lambda x = \mu e\) replaces complementarity&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Newton system&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Solve 3×3 block system&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Predictor-Corrector&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Balance progress vs centering&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Infeasible start&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Handle infeasibility gracefully&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;complexity&quot;&gt;&lt;strong&gt;Complexity:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Per iteration:&lt;/strong&gt; \(O(n^3)\) (matrix factorization)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Total iterations:&lt;/strong&gt; \(O(\sqrt{n} \log(1/\epsilon))\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Overall:&lt;/strong&gt; \(O(n^{3.5} \log(1/\epsilon))\) for LP&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Wright, S. J. (1997). &lt;em&gt;Primal-Dual Interior-Point Methods&lt;/em&gt;. SIAM.&lt;/li&gt;
  &lt;li&gt;Nesterov, Y., &amp;amp; Nemirovskii, A. (1994). &lt;em&gt;Interior-Point Polynomial Algorithms&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Mehrotra, S. (1992). “On the Implementation of a Primal-Dual IPM”. &lt;em&gt;SIAM Journal&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

</content>
 </entry>
 
 <entry>
   <title>17-07 Multiple-Choice Quiz - Primal-Dual Interior Point Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_07_Quiz_Primal_Dual_Interior_Point/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_07_Quiz_Primal_Dual_Interior_Point</id>
   <content type="html">&lt;p&gt;Reading derivations of perturbed KKT systems can create a deceptive sense of fluency—until a multiple-choice question asks whether the primal residual stays zero after a damped Newton step, or why the surrogate duality gap can be smaller than the true suboptimality at an infeasible iterate. Treat this quiz as a high-precision diagnostic lab: every question probes a structural invariant of primal-dual interior-point methods that distinguishes genuine graduate mastery from surface pattern-matching.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-core-invariants-tested-in-this-quiz&quot;&gt;Key ideas: Core Invariants Tested in This Quiz&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Barrier vs. Primal-Dual Mechanics:&lt;/strong&gt; Know the exact trade-offs—single Newton step per iteration, infeasible-start capability, and simultaneous \((x, u, v)\) updates versus inner centering loops.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Residual Definitions &amp;amp; Contraction Laws:&lt;/strong&gt; Distinguish \(r_{\text{prim}} = Ax - b\), \(r_{\text{dual}} = \nabla f(x) + \nabla h(x)u + A^T v\), and \(r_{\text{cent}} = U h(x) + \tau \mathbf{1}\), and recognize how linear residuals contract by exactly \((1 - \theta)\) under a step of length \(\theta\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Surrogate Gap &amp;amp; Centering Parameter \(\sigma\):&lt;/strong&gt; Recall \(\eta = -h(x)^T u\), \(\tau = \sigma \eta / m\), and how \(\sigma \to 0\) yields aggressive affine-scaling steps while \(\sigma \to 1\) yields pure centering steps.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;LP Normal Equations &amp;amp; SDP Symmetrization:&lt;/strong&gt; Connect the \(m \times m\) SPD matrix \(A S^{-1} X A^T\) in LP to the matrix complementarity \(XS = \mu I\) and non-commutativity symmetrization in SDP.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-linear-residuals-contract-by-exactly-1---theta&quot;&gt;Worked example: Why Linear Residuals Contract by Exactly \((1 - \theta)\)&lt;/h3&gt;

&lt;p&gt;Suppose a quiz asks: &lt;em&gt;In a primal-dual IPM for an LP, if the current iterate has primal residual \(r_p^k = Ax^k - b = (2, -4)^T\) and we take a damped Newton step with step length \(\theta_k = 0.75\), what is the new primal residual \(r_p^{k+1}\)?&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the linearized equality constraint from the Newton system:&lt;/strong&gt;
The primal-dual Newton step satisfies \(A \Delta x = -r_p^k\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Substitute the updated iterate \(x^{k+1} = x^k + \theta_k \Delta x\):&lt;/strong&gt;
\(r_p^{k+1} = A(x^k + \theta_k \Delta x) - b = (Ax^k - b) + \theta_k (A \Delta x) = r_p^k - \theta_k r_p^k = (1 - \theta_k) r_p^k.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate numerically at \(\theta_k = 0.75\):&lt;/strong&gt;
\(r_p^{k+1} = (1 - 0.75)\begin{bmatrix} 2 \\ -4 \end{bmatrix} = \begin{bmatrix} 0.5 \\ -1.0 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Key insight for the quiz:&lt;/strong&gt;
Notice this identity holds &lt;em&gt;regardless&lt;/em&gt; of \(\sigma\) or \(\tau\), and once any iteration takes a full step \(\theta_k = 1\), \(r_p^{k+1} = 0\) and primal feasibility is preserved forever thereafter! (The exact same \((1 - \theta_k)\) law holds for \(r_{\text{dual}}\) in LP and QP, because \(\nabla f\) and \(\nabla h\) are linear.)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-primal-dual-interior-point-method&quot;&gt;⚡ &lt;strong&gt;Primal-Dual Interior Point Method&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;motivation-and-comparison-with-the-barrier-method&quot;&gt;&lt;strong&gt;Motivation and comparison with the Barrier Method&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Barrier Method limitations:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Multiple Newton steps:&lt;/strong&gt; Centering steps require many iterations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Must stay feasible:&lt;/strong&gt; Always maintain \(h_i(x) &amp;lt; 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sequential approach:&lt;/strong&gt; Solve sequence of barrier problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Less efficient:&lt;/strong&gt; Many outer iterations needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Primal-Dual advantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Single Newton step:&lt;/strong&gt; One Newton step per iteration&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infeasible start OK:&lt;/strong&gt; Can start from infeasible points (\(Ax^0 = b\) is not required; in this form we still need \(h(x^0) &amp;lt; 0, u^0 &amp;gt; 0\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simultaneous updates:&lt;/strong&gt; Update primal and dual variables together&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;More efficient:&lt;/strong&gt; Generally superior performance&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-central-path-equations-revisited&quot;&gt;🎯 &lt;strong&gt;Central Path Equations Revisited&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;original-kkt-conditions&quot;&gt;&lt;strong&gt;Original KKT conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
\nabla f(x) + \nabla h(x)u + A^T v &amp;amp;= 0 \\
Uh(x) &amp;amp;= 0 \\
Ax &amp;amp;= b \\
u \ge 0, \quad -h(x) &amp;amp;\ge 0
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;perturbed-kkt-conditions-central-path&quot;&gt;&lt;strong&gt;Perturbed KKT conditions (Central Path)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
\nabla f(x) + \nabla h(x)u + A^T v &amp;amp;= 0 \\
Uh(x) + \tau\mathbf{1} &amp;amp;= 0 \\
Ax - b &amp;amp;= 0 \\
u &amp;gt; 0, \quad -h(x) &amp;amp;&amp;gt; 0
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;key-differences&quot;&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; \(Uh(x) = 0\) vs \(Uh(x) = -\tau\mathbf{1}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feasibility:&lt;/strong&gt; \(\ge 0\) vs \(&amp;gt; 0\) (strict interior)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parameter:&lt;/strong&gt; \(\tau = 1/t\) controls perturbation level&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;duality-gap-property&quot;&gt;&lt;strong&gt;Duality gap property&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Important fact:&lt;/strong&gt; Solution \((x(\tau), u(\tau), v(\tau))\) has duality gap:
\(f(x(\tau)) - \min_x L(x, u(\tau), v(\tau)) = m\tau = \frac{m}{t}\)&lt;/p&gt;

&lt;h3 id=&quot;-newton-step-for-central-path&quot;&gt;🔄 &lt;strong&gt;Newton Step for Central Path&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;residual-function-definition&quot;&gt;&lt;strong&gt;Residual function definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(r(x,u,v) = \begin{bmatrix}
\nabla f(x) + \nabla h(x)u + A^T v \\
Uh(x) + \tau\mathbf{1} \\
Ax - b
\end{bmatrix}\)&lt;/p&gt;

&lt;h4 id=&quot;newton-system&quot;&gt;&lt;strong&gt;Newton system&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{bmatrix}
\nabla^2 f(x) + \sum u_i \nabla^2 h_i(x) &amp;amp; \nabla h(x) &amp;amp; A^T \\
U \nabla h(x)^T &amp;amp; H(x) &amp;amp; 0 \\
A &amp;amp; 0 &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
\Delta x \\
\Delta u \\
\Delta v
\end{bmatrix} = -r(x,u,v)\)&lt;/p&gt;

&lt;p&gt;with \(H(x) = \text{diag}(h(x))\), \(U = \text{diag}(u)\)&lt;/p&gt;

&lt;h4 id=&quot;solution-interpretation&quot;&gt;&lt;strong&gt;Solution interpretation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\((\Delta x, \Delta u, \Delta v)\): Newton direction&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simultaneous update:&lt;/strong&gt; Both primal (\(x\)) and dual (\(u,v\)) variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Root finding:&lt;/strong&gt; Solve \(r(x,u,v) = 0\) using Newton method&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-residuals-and-the-surrogate-duality-gap&quot;&gt;📊 &lt;strong&gt;Residuals and the Surrogate Duality Gap&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;three-types-of-residuals&quot;&gt;&lt;strong&gt;Three types of residuals&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Dual residual:&lt;/strong&gt; \(r_{\text{dual}} = \nabla f(x) + \nabla h(x)u + A^T v\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Central residual:&lt;/strong&gt; \(r_{\text{cent}} = Uh(x) + \tau\mathbf{1}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal residual:&lt;/strong&gt; \(r_{\text{prim}} = Ax - b\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;residual-interpretations&quot;&gt;&lt;strong&gt;Residual interpretations&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(r_{\text{dual}} = 0\):&lt;/strong&gt; Dual feasibility (\(u,v\) in domain of \(g\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(r_{\text{prim}} = 0\):&lt;/strong&gt; Primal feasibility&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(r_{\text{cent}} = 0\):&lt;/strong&gt; Complementary slackness with perturbation \(\tau\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;surrogate-duality-gap&quot;&gt;&lt;strong&gt;Surrogate duality gap&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt; \(-h(x)^T u\) for \(h(x) \le 0, u \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;If feasible:&lt;/strong&gt; Surrogate gap = true duality gap = \(m\tau\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parameter relationship:&lt;/strong&gt; \(t = -\frac{m}{h(x)^T u}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Central path condition:&lt;/strong&gt; \(r(x,u,v) = 0\) for \(\tau = -\frac{h(x)^T u}{m}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-primal-dual-algorithm&quot;&gt;🔄 &lt;strong&gt;Primal-Dual Algorithm&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;parameter-definitions&quot;&gt;&lt;strong&gt;Parameter definitions&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(\tau(x,u) = -\frac{h(x)^T u}{m}\) (current perturbation)&lt;/li&gt;
  &lt;li&gt;\(\sigma \in (0,1)\) (centering parameter, \(\sigma = 1/\mu\))&lt;/li&gt;
  &lt;li&gt;\(\tau = \sigma \tau(x^k, u^k)\) (target perturbation)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;algorithm-steps&quot;&gt;&lt;strong&gt;Algorithm steps&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Choose parameters:&lt;/strong&gt; \(\sigma \in (0,1)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Initialize:&lt;/strong&gt; \((x^0, u^0, v^0)\) with \(h(x^0) &amp;lt; 0, u^0 &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Main loop:&lt;/strong&gt; For \(k = 0, 1, 2, \ldots\)
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Compute Newton step:&lt;/strong&gt; Solve for \((\Delta x, \Delta u, \Delta v)\)&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Backtracking line search:&lt;/strong&gt; Find step size \(\theta_k\)&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Update:&lt;/strong&gt; \((x^{k+1}, u^{k+1}, v^{k+1}) = (x^k, u^k, v^k) + \theta_k(\Delta x, \Delta u, \Delta v)\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Termination:&lt;/strong&gt; Stop when \(-h(x)^T u \le \epsilon\) and \(\lVert r_{\text{prim}} \rVert^2 + \lVert r_{\text{dual}} \rVert^2 \le \epsilon^2\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-multi-stage-backtracking-line-search&quot;&gt;🎯 &lt;strong&gt;Multi-Stage Backtracking Line Search&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;stage-1-dual-feasibility-u--0&quot;&gt;&lt;strong&gt;Stage 1: Dual feasibility (\(u &amp;gt; 0\))&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\theta_{\max} = \min\left\{1, \min\left\{-\frac{u_i}{\Delta u_i} : \Delta u_i &amp;lt; 0\right\}\right\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Ensure \(u + \theta \Delta u \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;stage-2-primal-feasibility-hx--0&quot;&gt;&lt;strong&gt;Stage 2: Primal feasibility (\(h(x) &amp;lt; 0\))&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Start with \(\theta = 0.99\theta_{\max}\)&lt;/li&gt;
  &lt;li&gt;Update \(\theta = \beta\theta\) until \(h_i(x^+) &amp;lt; 0\) for all \(i\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Ensure \(h(x + \theta \Delta x) &amp;lt; 0\)&lt;/p&gt;

&lt;h4 id=&quot;stage-3-residual-reduction&quot;&gt;&lt;strong&gt;Stage 3: Residual reduction&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Update \(\theta = \beta\theta\) until:
\(\|r(x^+, u^+, v^+)\| \le (1 - \alpha\theta)\|r(x, u, v)\|\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Sufficient decrease in residual norm&lt;/p&gt;

&lt;h4 id=&quot;parameters&quot;&gt;&lt;strong&gt;Parameters&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(\alpha, \beta \in (0,1)\) (typical: \(\alpha = 0.01, \beta = 0.5\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multi-objective:&lt;/strong&gt; Maintain feasibility + reduce residuals&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-linear-programming-special-case&quot;&gt;📈 &lt;strong&gt;Linear Programming Special Case&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;primal-lp&quot;&gt;&lt;strong&gt;Primal LP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min c^T x \quad \text{s.t.} \quad Ax = b, \quad x \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;dual-lp&quot;&gt;&lt;strong&gt;Dual LP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max b^T y \quad \text{s.t.} \quad A^T y + s = c, \quad s \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;central-path-conditions&quot;&gt;&lt;strong&gt;Central path conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
A^T y + s &amp;amp;= c \\
Ax &amp;amp;= b \\
XS\mathbf{1} &amp;amp;= \tau\mathbf{1} \\
x, s &amp;amp;&amp;gt; 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;with \(X = \text{diag}(x)\), \(S = \text{diag}(s)\)&lt;/p&gt;

&lt;h4 id=&quot;newton-system-for-lp&quot;&gt;&lt;strong&gt;Newton system for LP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{bmatrix}
0 &amp;amp; A^T &amp;amp; I \\
A &amp;amp; 0 &amp;amp; 0 \\
S &amp;amp; 0 &amp;amp; X
\end{bmatrix}
\begin{bmatrix}
\Delta x \\
\Delta y \\
\Delta s
\end{bmatrix} = -\begin{bmatrix}
A^T y + s - c \\
Ax - b \\
XS\mathbf{1} - \tau\mathbf{1}
\end{bmatrix}\)&lt;/p&gt;

&lt;h4 id=&quot;relationship-to-barrier-methods&quot;&gt;&lt;strong&gt;Relationship to barrier methods&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal barrier:&lt;/strong&gt; \(x = \tau S^{-1}\mathbf{1}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual barrier:&lt;/strong&gt; \(s = \tau X^{-1}\mathbf{1}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual:&lt;/strong&gt; Simultaneous updates of both&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-semidefinite-programming-sdp&quot;&gt;📊 &lt;strong&gt;Semidefinite Programming (SDP)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;primal-sdp&quot;&gt;&lt;strong&gt;Primal SDP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min C \bullet X \quad \text{s.t.} \quad \mathcal{A}(X) = b, \quad X \succeq 0\)&lt;/p&gt;

&lt;h4 id=&quot;dual-sdp&quot;&gt;&lt;strong&gt;Dual SDP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max b^T y \quad \text{s.t.} \quad \mathcal{A}^*(y) + S = C, \quad S \succeq 0\)&lt;/p&gt;

&lt;h4 id=&quot;central-path-conditions-1&quot;&gt;&lt;strong&gt;Central path conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
\mathcal{A}^*(y) + S &amp;amp;= C \\
\mathcal{A}(X) &amp;amp;= b \\
XS &amp;amp;= \tau I \\
X, S &amp;amp;\succ 0
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;newton-system-for-sdp&quot;&gt;&lt;strong&gt;Newton system for SDP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{bmatrix}
0 &amp;amp; \mathcal{A}^* &amp;amp; I \\
\mathcal{A} &amp;amp; 0 &amp;amp; 0 \\
S &amp;amp; 0 &amp;amp; X
\end{bmatrix}
\begin{bmatrix}
\Delta X \\
\Delta y \\
\Delta S
\end{bmatrix} = -\begin{bmatrix}
\mathcal{A}^*(y) + S - C \\
\mathcal{A}(X) - b \\
XS - \tau I
\end{bmatrix}\)&lt;/p&gt;

&lt;h4 id=&quot;matrix-operations&quot;&gt;&lt;strong&gt;Matrix operations&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(X \bullet S = \text{tr}(XS)\) (trace inner product)&lt;/li&gt;
  &lt;li&gt;\(XS = \tau I\) (matrix complementary slackness)&lt;/li&gt;
  &lt;li&gt;\(\mathcal{A}: \mathbb{S}^n \to \mathbb{R}^m\) (linear map)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-comparison-barrier-vs-primal-dual&quot;&gt;🔄 &lt;strong&gt;Comparison: Barrier vs Primal-Dual&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;strong&gt;Aspect&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Barrier Method&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Primal-Dual Method&lt;/strong&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Newton steps&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Multiple per centering&lt;/td&gt;
      &lt;td&gt;Single per iteration&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Feasibility&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Must maintain&lt;/td&gt;
      &lt;td&gt;Can start infeasible&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Variables&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Primal only&lt;/td&gt;
      &lt;td&gt;Primal + dual simultaneous&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Convergence&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;Often superlinear&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Efficiency&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Good&lt;/td&gt;
      &lt;td&gt;Generally superior&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Intuition&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Clear (central path)&lt;/td&gt;
      &lt;td&gt;Less intuitive&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;-performance-analysis&quot;&gt;🎯 &lt;strong&gt;Performance Analysis&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;theoretical-advantages&quot;&gt;&lt;strong&gt;Theoretical advantages&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Polynomial-time:&lt;/strong&gt; \(O(\sqrt{n}\log(1/\epsilon))\) iterations, \(O(n^{3.5} \log(1/\epsilon))\) total complexity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Superlinear convergence:&lt;/strong&gt; Under appropriate conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust performance:&lt;/strong&gt; Works across problem classes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infeasible start:&lt;/strong&gt; No need for Phase I (only a point in the strict interior of the inequality constraints is needed)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;practical-benefits&quot;&gt;&lt;strong&gt;Practical benefits&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Fewer iterations:&lt;/strong&gt; Compared to barrier method&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Higher accuracy:&lt;/strong&gt; Can achieve very high precision&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm starts:&lt;/strong&gt; Efficient reoptimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Large-scale capability:&lt;/strong&gt; Handle millions of variables&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;experimental-results-lp-example&quot;&gt;&lt;strong&gt;Experimental results (LP example)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Standard LP:&lt;/strong&gt; \(n = 50, m = 100\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual:&lt;/strong&gt; Fixed \(\mu = 10\), fast convergence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier:&lt;/strong&gt; Various \(\mu\) values, more iterations needed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Accuracy:&lt;/strong&gt; Primal-dual achieves higher precision&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-implementation-considerations&quot;&gt;🛠️ &lt;strong&gt;Implementation Considerations&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;linear-system-solution&quot;&gt;&lt;strong&gt;Linear system solution&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sparse factorization:&lt;/strong&gt; Exploit problem structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iterative methods:&lt;/strong&gt; For very large problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical stability:&lt;/strong&gt; Monitor condition numbers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization:&lt;/strong&gt; Handle near-singular systems&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;step-size-selection&quot;&gt;&lt;strong&gt;Step size selection&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Conservative factors:&lt;/strong&gt; 0.99 for feasibility margin&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive parameters:&lt;/strong&gt; Adjust \(\alpha, \beta\) based on performance&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feasibility monitoring:&lt;/strong&gt; Ensure strict interior maintenance&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence tracking:&lt;/strong&gt; Monitor residual norms&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;stopping-criteria&quot;&gt;&lt;strong&gt;Stopping criteria&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Duality gap:&lt;/strong&gt; \(-h(x)^T u \le \epsilon\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feasibility:&lt;/strong&gt; \(\lVert r_{\text{prim}} \rVert^2 + \lVert r_{\text{dual}} \rVert^2 \le \epsilon^2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Relative criteria:&lt;/strong&gt; Scale by problem data&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multiple conditions:&lt;/strong&gt; All must be satisfied&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-connections-to-other-chapters&quot;&gt;🎯 &lt;strong&gt;Connections to Other Chapters&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-previous-chapters&quot;&gt;&lt;strong&gt;From previous chapters:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 15:&lt;/strong&gt; Barrier method foundation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 16:&lt;/strong&gt; Duality theory, perturbed KKT&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 14:&lt;/strong&gt; Newton’s method for root finding&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 12:&lt;/strong&gt; KKT conditions framework&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;advanced-connections&quot;&gt;&lt;strong&gt;Advanced connections:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Central path:&lt;/strong&gt; Geometric interpretation of optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Perturbed optimality:&lt;/strong&gt; Bridge between exact and approximate&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simultaneous updates:&lt;/strong&gt; Primal-dual variable coordination&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polynomial-time algorithms:&lt;/strong&gt; Theoretical complexity guarantees&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;practical-applications&quot;&gt;&lt;strong&gt;Practical applications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Commercial solvers:&lt;/strong&gt; CPLEX, Gurobi, Mosek&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Large-scale optimization:&lt;/strong&gt; Industrial applications&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; SVM, regularized regression&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Engineering design:&lt;/strong&gt; Control, signal processing&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-theoretical-significance&quot;&gt;🌟 &lt;strong&gt;Theoretical Significance&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;algorithmic-innovation&quot;&gt;&lt;strong&gt;Algorithmic innovation:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual paradigm:&lt;/strong&gt; Simultaneous variable updates&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infeasible start capability:&lt;/strong&gt; No Phase I required&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Superlinear convergence:&lt;/strong&gt; Beyond linear rates&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unified framework:&lt;/strong&gt; Works for LP, QP, SDP&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;theoretical-elegance&quot;&gt;&lt;strong&gt;Theoretical elegance:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Central path following:&lt;/strong&gt; Smooth trajectory to optimality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Perturbed KKT:&lt;/strong&gt; Systematic perturbation approach&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polynomial-time guarantee:&lt;/strong&gt; Worst-case complexity bounds&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-dual structure:&lt;/strong&gt; Exploits problem symmetry&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;practical-impact&quot;&gt;&lt;strong&gt;Practical impact:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Software revolution:&lt;/strong&gt; Foundation of modern solvers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Industrial applications:&lt;/strong&gt; Large-scale optimization capability&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Research foundation:&lt;/strong&gt; Basis for advanced methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Educational value:&lt;/strong&gt; Beautiful theory-practice connection&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;when-to-use-primal-dual-methods&quot;&gt;&lt;strong&gt;When to use primal-dual methods:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Large-scale problems:&lt;/strong&gt; More efficient than barrier methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High accuracy needed:&lt;/strong&gt; Can achieve very high precision&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infeasible start:&lt;/strong&gt; When feasible starting point hard to find&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm starts:&lt;/strong&gt; Efficient reoptimization scenarios&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;parameter-selection&quot;&gt;&lt;strong&gt;Parameter selection:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(\sigma\):&lt;/strong&gt; Usually from 0.1 to 0.9 (0.1 for fast progress, 0.9 for stability)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\alpha, \beta\):&lt;/strong&gt; Standard values 0.01, 0.5 work well&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\epsilon\):&lt;/strong&gt; Problem-dependent tolerance&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feasibility margin:&lt;/strong&gt; 0.99 factor for numerical stability&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;implementation-tips&quot;&gt;&lt;strong&gt;Implementation tips:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sparse linear algebra:&lt;/strong&gt; Essential for large problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical conditioning:&lt;/strong&gt; Monitor and regularize if needed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence monitoring:&lt;/strong&gt; Track multiple criteria&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm starts:&lt;/strong&gt; Use previous solutions as initialization&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;common-pitfalls&quot;&gt;&lt;strong&gt;Common pitfalls:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Poor conditioning:&lt;/strong&gt; Large problems may have numerical issues&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step size too aggressive:&lt;/strong&gt; Can lead to infeasibility&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inadequate stopping criteria:&lt;/strong&gt; May terminate prematurely&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Memory requirements:&lt;/strong&gt; Large Newton systems need careful handling&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-advanced-topics&quot;&gt;🔬 &lt;strong&gt;Advanced Topics&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;mehrotras-predictor-corrector&quot;&gt;&lt;strong&gt;Mehrotra’s predictor-corrector:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Predictor step:&lt;/strong&gt; Estimate progress along central path&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Corrector step:&lt;/strong&gt; Adjust for better centering&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive \(\sigma\):&lt;/strong&gt; Dynamic centering parameter&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Superior performance:&lt;/strong&gt; State-of-the-art implementation&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;homogeneous-methods&quot;&gt;&lt;strong&gt;Homogeneous methods:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Infeasibility detection:&lt;/strong&gt; Distinguish infeasible from unbounded&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unified treatment:&lt;/strong&gt; Handle all problem types&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical completeness:&lt;/strong&gt; Covers all cases&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical robustness:&lt;/strong&gt; More reliable than standard methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;higher-order-methods&quot;&gt;&lt;strong&gt;Higher-order methods:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Beyond Newton:&lt;/strong&gt; Higher-order corrections&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Faster convergence:&lt;/strong&gt; Potential for cubic convergence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational trade-offs:&lt;/strong&gt; More work per iteration&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Research frontier:&lt;/strong&gt; Active area of development&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-real-world-applications&quot;&gt;📈 &lt;strong&gt;Real-World Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;linear-and-quadratic-programming&quot;&gt;&lt;strong&gt;Linear and Quadratic Programming:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Portfolio optimization:&lt;/strong&gt; Large-scale mean-variance models&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Network flows:&lt;/strong&gt; Transportation and communication&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Production planning:&lt;/strong&gt; Resource allocation problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; SVM training, regularized regression&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;semidefinite-programming&quot;&gt;&lt;strong&gt;Semidefinite Programming:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Control theory:&lt;/strong&gt; LMI-based controller design&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Combinatorial optimization:&lt;/strong&gt; SDP relaxations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; Kernel methods, matrix completion&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Signal processing:&lt;/strong&gt; Beamforming, robust filtering&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;engineering-applications&quot;&gt;&lt;strong&gt;Engineering Applications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Structural optimization:&lt;/strong&gt; Truss design, topology optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Circuit design:&lt;/strong&gt; Analog circuit sizing&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Power systems:&lt;/strong&gt; Optimal power flow&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robotics:&lt;/strong&gt; Motion planning, control&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;finance-and-economics&quot;&gt;&lt;strong&gt;Finance and Economics:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Risk management:&lt;/strong&gt; Value-at-Risk optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic trading:&lt;/strong&gt; Execution optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Market design:&lt;/strong&gt; Auction mechanisms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Insurance:&lt;/strong&gt; Portfolio optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-future-directions&quot;&gt;🔮 &lt;strong&gt;Future Directions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;algorithmic-developments&quot;&gt;&lt;strong&gt;Algorithmic developments:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Distributed methods:&lt;/strong&gt; Parallel primal-dual algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Online algorithms:&lt;/strong&gt; Streaming optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic methods:&lt;/strong&gt; Uncertainty handling&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quantum algorithms:&lt;/strong&gt; Quantum optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;application-areas&quot;&gt;&lt;strong&gt;Application areas:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Deep learning:&lt;/strong&gt; Neural network training&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Autonomous systems:&lt;/strong&gt; Real-time optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smart grids:&lt;/strong&gt; Energy system optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bioinformatics:&lt;/strong&gt; Computational biology&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;theoretical-advances&quot;&gt;&lt;strong&gt;Theoretical advances:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Non-convex extensions:&lt;/strong&gt; Beyond convex optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust optimization:&lt;/strong&gt; Worst-case analysis&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multi-objective:&lt;/strong&gt; Pareto optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dynamic optimization:&lt;/strong&gt; Time-varying problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-key-insights&quot;&gt;💎 &lt;strong&gt;Key Insights&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;primal-dual-advantages&quot;&gt;&lt;strong&gt;Primal-dual advantages:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Simultaneous updates:&lt;/strong&gt; Both primal and dual variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infeasible start:&lt;/strong&gt; No Phase I required&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Superior efficiency:&lt;/strong&gt; Fewer iterations than barrier methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High accuracy:&lt;/strong&gt; Can achieve very high precision&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;algorithmic-elegance&quot;&gt;&lt;strong&gt;Algorithmic elegance:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Newton framework:&lt;/strong&gt; Root finding for perturbed KKT&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multi-stage line search:&lt;/strong&gt; Systematic feasibility maintenance&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Residual minimization:&lt;/strong&gt; Clear optimization objective&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polynomial-time guarantee:&lt;/strong&gt; Theoretical complexity bounds&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;practical-power&quot;&gt;&lt;strong&gt;Practical power:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Commercial software:&lt;/strong&gt; Foundation of modern solvers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Large-scale capability:&lt;/strong&gt; Handle millions of variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust performance:&lt;/strong&gt; Works across diverse problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Industrial impact:&lt;/strong&gt; Enables complex optimization applications&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-legacy-of-chapter-17&quot;&gt;🌟 &lt;strong&gt;Legacy of Chapter 17:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic breakthrough:&lt;/strong&gt; Primal-dual interior point revolution&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical completeness:&lt;/strong&gt; Unified framework for convex optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical impact:&lt;/strong&gt; Foundation of commercial optimization software&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Industrial transformation:&lt;/strong&gt; Large-scale optimization capability&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Educational significance:&lt;/strong&gt; Beautiful synthesis of theory and practice&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-takeaway-messages&quot;&gt;🎯 &lt;strong&gt;Takeaway messages:&lt;/strong&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual is superior:&lt;/strong&gt; More efficient than pure barrier methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simultaneous updates:&lt;/strong&gt; Key to algorithmic efficiency&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infeasible start OK:&lt;/strong&gt; No need for feasible initialization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polynomial-time guarantee:&lt;/strong&gt; Theoretical and practical efficiency&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Commercial foundation:&lt;/strong&gt; Basis of modern optimization software&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-philosophical-impact&quot;&gt;💫 &lt;strong&gt;Philosophical impact:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Chapter 17 &lt;strong&gt;completes the interior point revolution&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;From primal-only to primal-dual:&lt;/strong&gt; Simultaneous variable updates&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;From feasible to infeasible start:&lt;/strong&gt; Greater algorithmic flexibility&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;From barrier to direct approach:&lt;/strong&gt; More efficient path following&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;From academic to commercial:&lt;/strong&gt; Industrial optimization software&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;From theory to practice:&lt;/strong&gt; Complete optimization framework&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-synthesis&quot;&gt;🔮 &lt;strong&gt;Synthesis:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The Primal-Dual Interior Point Method represents the &lt;strong&gt;culmination&lt;/strong&gt; of the interior point approach:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical elegance:&lt;/strong&gt; Perturbed KKT conditions framework&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic efficiency:&lt;/strong&gt; Simultaneous primal-dual updates&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical power:&lt;/strong&gt; Foundation of commercial software&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Industrial impact:&lt;/strong&gt; Large-scale optimization capability&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Educational value:&lt;/strong&gt; Beautiful theory-practice synthesis&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-final-insight&quot;&gt;💡 &lt;strong&gt;Final insight:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Chapter 17 demonstrates that &lt;strong&gt;optimization theory can be both beautiful and practical&lt;/strong&gt;. From perturbed KKT conditions to Newton systems, from central path following to multi-stage line search, from theoretical polynomial-time guarantees to commercial software implementations - &lt;strong&gt;primal-dual interior point methods represent a perfect marriage&lt;/strong&gt; of mathematical elegance with computational efficiency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primal-Dual = Simultaneous optimization of dual perspectives!&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Final message:&lt;/strong&gt; The Primal-Dual Interior Point Method is not just an algorithmic improvement - it is the &lt;strong&gt;completion of the interior point revolution&lt;/strong&gt;, enabling both theoretical understanding and the practical solution of large-scale optimization problems across science, engineering, finance, and technology!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the Primal-Dual Interior Point Method, including primal-dual algorithms, central path equations, semidefinite programming and advanced interior point concepts.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;⚡ Quiz: Primal-Dual Interior Point Method&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: The primal-dual interior point method differs from the barrier method in that it:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Updates both primal and dual variables simultaneously&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Needs only one Newton step per iteration&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Does not need a feasible starting point&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                Primal-dual methods update both primal and dual variables, usually need only 1 Newton step, and can start from infeasible points.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The central path equations for inequality constraints $$g_i(x) \leq 0$$ are:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) $$\nabla f(x) + \sum \lambda_i \nabla g_i(x) = 0, \lambda_i g_i(x) = -\frac{1}{t}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) $$\nabla f(x) + \sum \lambda_i \nabla g_i(x) = 0, \lambda_i g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) $$\nabla f(x) = 0, g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) $$\lambda_i = \frac{1}{t}, g_i(x) = -1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\nabla f(x) + \sum \lambda_i \nabla g_i(x) = 0, \lambda_i g_i(x) = -\frac{1}{t}$$&lt;/strong&gt;&lt;br /&gt;
                Central path equations: the stationarity condition and the modified complementary slackness with parameter $$t$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: The Newton system in the primal-dual method solves for:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) $$(\Delta x, \Delta \lambda, \Delta \nu)$$ - directions for both primal and dual&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Only $$\Delta x$$ - the primal direction&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Only $$\Delta \lambda$$ - the dual direction&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Parameter $$t$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$(\Delta x, \Delta \lambda, \Delta \nu)$$ - directions for both primal and dual&lt;/strong&gt;&lt;br /&gt;
                The Newton system solves simultaneously for the primal direction $$\Delta x$$ and the dual directions $$\Delta \lambda, \Delta \nu$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: The surrogate duality gap in the primal-dual method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$\eta = -\sum_{i=1}^m \lambda_i g_i(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) \(\eta = f(x) - g(\lambda, \nu)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) \(\eta = \|\nabla f(x)\|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) \(\eta = \sum_{i=1}^m |\lambda_i|\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\eta = -\sum_{i=1}^m \lambda_i g_i(x)$$&lt;/strong&gt;&lt;br /&gt;
                The surrogate duality gap estimates the duality gap from the current primal-dual point, without computing the dual function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: The residuals in the primal-dual method consist of:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Dual residual, primal residual, centrality residual&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Only the dual residual&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Only the primal residual&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Only the centrality residual&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Dual residual, primal residual, centrality residual&lt;/strong&gt;&lt;br /&gt;
                Ba residuals: dual (stationarity), primal (feasibility), centrality (complementary slackness).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: The predictor-corrector method in primal-dual IPM:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) The predictor step reduces the duality gap, the corrector step improves centrality&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) The predictor step increases feasibility, the corrector step reduces the gap&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) Only a predictor step&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Only a corrector step&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The predictor step reduces the duality gap, the corrector step improves centrality&lt;/strong&gt;&lt;br /&gt;
                Predictor-corrector: predictor step approach optimal, corrector step maintain central path proximity.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: Mehrotra&apos;s predictor-corrector algorithm is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) A practical primal-dual algorithm with adaptive centering&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Pure Newton method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Barrier method variant&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) First-order method&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) A practical primal-dual algorithm with adaptive centering&lt;/strong&gt;&lt;br /&gt;
                Mehrotra&apos;s algorithm is a widely used primal-dual method with adaptive selection of the centering parameter.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The primal-dual method can start from an infeasible point by:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) A backtracking line search that ensures progress toward feasibility&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) Ignore feasibility constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Projecting onto the feasible region&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) It cannot start from an infeasible point&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) A backtracking line search that ensures progress toward feasibility&lt;/strong&gt;&lt;br /&gt;
                Infeasible-start primal-dual methods use a line search to maintain progress toward feasibility and optimality.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The Semidefinite Programming (SDP) primal problem has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(\min C \bullet X\) s.t. \(A_i \bullet X = b_i, X \succeq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(\min c^T x\) s.t. \(Ax = b, x \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(\min \frac{1}{2}x^T Q x\) s.t. \(Ax \leq b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(\min f(x)\) s.t. \(g_i(x) \leq 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\min C \bullet X$$ s.t. $$A_i \bullet X = b_i, X \succeq 0$$&lt;/strong&gt;&lt;br /&gt;
                SDP: minimize a linear function of a matrix variable subject to linear equality constraints and a positive semidefinite constraint.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: The SDP dual problem has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(\max b^T y\) s.t. \(\sum y_i A_i + S = C, S \succeq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(\min b^T y\) s.t. \(A^T y \leq c\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(\max c^T z\) s.t. \(A^T z = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(\min \|y\|^2\) s.t. \(Ay = b\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max b^T y$$ s.t. $$\sum y_i A_i + S = C, S \succeq 0$$&lt;/strong&gt;&lt;br /&gt;
                SDP dual: maximize a linear function with a dual matrix variable $$S \succeq 0$$ and a linear constraint.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: Complementary slackness in SDP is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(X \bullet S = 0\) (i.e. \(\text{tr}(XS) = 0\))&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(X \bullet S = 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(X + S = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(\|X - S\| = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$X \bullet S = 0$$ (i.e. $$\text{tr}(XS) = 0$$)&lt;/strong&gt;&lt;br /&gt;
                SDP complementary slackness: the inner product (trace) of the primal and dual matrix variables is 0. (For $$X, S \succeq 0$$, this is equivalent to $$XS = 0$$.)
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The central path condition for SDP is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) \(XS = \frac{1}{t}I\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) \(X \bullet S = \frac{n}{t}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) \(XS = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) \(X = S\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$XS = \frac{1}{t}I$$&lt;/strong&gt;&lt;br /&gt;
                SDP central path: the matrix product $$XS = \frac{1}{t}I$$ instead of scalar complementary slackness.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The Newton direction in the SDP primal-dual method solves:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) A linearized system for \((\Delta X, \Delta y, \Delta S)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Only for \(\Delta X\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Only for \(\Delta S\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Eigenvalue decomposition&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) A linearized system for $$(\Delta X, \Delta y, \Delta S)$$&lt;/strong&gt;&lt;br /&gt;
                The SDP Newton system solves simultaneously for the primal matrix $$\Delta X$$, the dual vector $$\Delta y$$, and the dual matrix $$\Delta S$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: Primal-dual interior point methods have complexity:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Polynomial-time in the worst case&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Exponential-time&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) NP-hard&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) No theoretical guarantees&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Polynomial-time in the worst case&lt;/strong&gt;&lt;br /&gt;
                Interior point methods have polynomial-time complexity, a breakthrough in optimization theory.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: A warm start in primal-dual methods means:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Starting from the solution of a similar problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Starting from the origin&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Starting from a random point&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Starting from the boundary&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Starting from the solution of a similar problem&lt;/strong&gt;&lt;br /&gt;
                A warm start uses the solution of a previous/similar problem as the starting point, which is very effective in practice.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: The homogeneous self-dual formulation has the advantages:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Detects infeasibility and unboundedness&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Does not need a feasible starting point&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Unified treatment of the different cases&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) All of the above advantages&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above advantages&lt;/strong&gt;&lt;br /&gt;
                The homogeneous self-dual formulation handles all cases (optimal, infeasible, unbounded) in a unified framework.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: The centering parameter \(\sigma\) in the primal-dual method:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Controls the balance between centrality and progress toward optimality&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Is always 0&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Is always 1&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Does not affect the algorithm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Controls the balance between centrality and progress toward optimality&lt;/strong&gt;&lt;br /&gt;
                Centering parameter $$\sigma \in [0,1]$$: $$\sigma = 0$$ (pure affine), $$\sigma = 1$$ (pure centering).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: For LP, the primal-dual method has the characteristics:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) The Newton system becomes a simple linear system&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Complementary slackness: \(x_i s_i = \frac{1}{t}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Highly efficient implementation&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) All of the above characteristics&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above characteristics&lt;/strong&gt;&lt;br /&gt;
                LP is a special case with a simple structure, leading to highly efficient primal-dual algorithms.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: Primal-dual interior point methods have convergence rate:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Superlinear under nondegeneracy conditions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Always linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Always quadratic&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Sublinear&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Superlinear under nondegeneracy conditions&lt;/strong&gt;&lt;br /&gt;
                Primal-dual methods have superlinear convergence under appropriate nondegeneracy assumptions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: Primal-dual interior point methods are used in:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Commercial optimization solvers&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Large-scale linear and semidefinite programming&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Machine learning optimization&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above applications&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above applications&lt;/strong&gt;&lt;br /&gt;
                Primal-dual methods are the backbone of modern optimization: CPLEX, Gurobi, MOSEK, and many ML applications.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: The primal-dual interior point method combines:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Barrier method + Newton method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Gradient descent + momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Simplex + dual simplex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) SGD + Adam&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Barrier method + Newton method&lt;/strong&gt;&lt;br /&gt;
                Primal-dual IPM uses a barrier function and Newton&apos;s method to solve the primal and dual simultaneously.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: In primal-dual IPM, the reduced Newton system (after eliminating \(\Delta \lambda\)) has the form of a:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Symmetric block matrix&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Triangular matrix&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Diagonal matrix&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Identity matrix&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Symmetric block matrix&lt;/strong&gt;&lt;br /&gt;
                After eliminating $$\Delta \lambda$$, the KKT system in IPM becomes a symmetric block matrix (augmented system) with special structure; the original full Newton system is generally not symmetric.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: The predictor-corrector approach in IPM:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Predicts a direction + corrects centrality&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Only predicts&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Only corrects&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Is unrelated&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Predicts a direction + corrects centrality&lt;/strong&gt;&lt;br /&gt;
                The predictor step finds a direction that reduces the duality gap, the corrector step improves centrality.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The complexity of IPM for LP is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$O(n^{3.5} \log(1/\epsilon))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$O(2^n)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$O(n!)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) $$O(n \log n)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$O(n^{3.5} \log(1/\epsilon))$$&lt;/strong&gt;&lt;br /&gt;
                IPM has polynomial complexity: $$O(\sqrt{n}\log(1/\epsilon))$$ iterations, each costing $$O(n^3)$$, for a total of $$O(n^{3.5} \log(1/\epsilon))$$ for LP.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: Mehrotra&apos;s algorithm is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) A practical predictor-corrector IPM&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Simplex method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Branch and bound&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) A practical predictor-corrector IPM&lt;/strong&gt;&lt;br /&gt;
                Mehrotra&apos;s algorithm is the most popular practical implementation of primal-dual IPM.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;d&apos;, q2: &apos;a&apos;, q3: &apos;a&apos;, q4: &apos;a&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;a&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;d&apos;, q17: &apos;a&apos;, q18: &apos;d&apos;, q19: &apos;a&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered primal-dual interior point methods!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand the central path and SDP well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review Newton systems and residuals.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review primal-dual algorithms and complementary slackness.&apos;;
    } else {
        message = &apos;📖 Study primal-dual methods again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>17-05 Optimality conditions for semidefinite programming</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_05_optimality_conditions_for_semidefinite_programming/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_05_optimality_conditions_for_semidefinite_programming</id>
   <content type="html">&lt;p&gt;Step up from vectors \(x \ge 0\) to symmetric positive semidefinite matrices \(X \succeq 0\), and suddenly optimization can certify polynomial nonnegativity, compute Lovász theta numbers of graphs, design robust control Lyapunov functions, and relax NP-hard combinatorial problems like MAX-CUT. Yet the primal-dual interior-point machinery carries over with astonishing elegance: the vector inner product \(c^T x\) becomes the trace inner product \(C \cdot X = \operatorname{tr}(CX)\), and complementarity \(x_i s_i = 0\) becomes the matrix equation \(XS = 0\)—with one fascinating twist caused by non-commutativity of matrices.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-lifting-interior-point-theory-to-the-psd-cone&quot;&gt;Key ideas: Lifting Interior-Point Theory to the PSD Cone&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trace Inner Product &amp;amp; Self-Dual Cone:&lt;/strong&gt; On the space \(\mathbb{S}^n\) of symmetric \(n \times n\) matrices with inner product \(\langle A, B \rangle = \operatorname{tr}(AB)\), the PSD cone \(\mathbb{S}_+^n\) is self-dual: \(X \succeq 0 \iff \operatorname{tr}(XS) \ge 0\) for all \(S \succeq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrix Complementarity (\(XS = 0\)):&lt;/strong&gt; For \(X, S \succeq 0\), \(\operatorname{tr}(XS) = 0\) is equivalent to the matrix product \(XS = 0\), meaning \(X\) and \(S\) share an eigenbasis with disjoint supports of positive eigenvalues (\(\operatorname{rank}(X) + \operatorname{rank}(S) \le n\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Slater’s Condition &amp;amp; Strong Duality Subtlety:&lt;/strong&gt; Unlike LP, where feasibility implies strong duality, SDPs can exhibit positive duality gaps or unattained optima unless strict feasibility (\(\exists X \succ 0\) or \(\exists S \succ 0\)) holds.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Symmetrizing the Newton Step (AHO, HRVW/KSH/M, NT Directions):&lt;/strong&gt; Perturbing complementarity to \(XS = \mu I\) gives a nonsymmetric linearization \(X\Delta S + \Delta X\, S = \mu I - XS\). Because \(\Delta X, \Delta S\) must stay symmetric, SDP solvers apply a similarity symmetrization \(H_P(M) = \frac{1}{2}(P M P^{-1} + P^{-T} M^T P^T)\), giving rise to the classical Alizadeh–Haeberly–Overton, Helmberg–Rendl–Vanderbei–Wolkowicz, and Nesterov–Todd search directions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-an-exact-2-times-2-sdp-central-path&quot;&gt;Worked example: Computing an Exact \(2 \times 2\) SDP Central Path&lt;/h3&gt;

&lt;p&gt;Consider the \(2 \times 2\) primal-dual SDP with \(C = \operatorname{diag}(1, 2)\), \(A_1 = I_2\), and \(b_1 = 2\):
\(\min_{X \succeq 0} \; X_{11} + 2X_{22} \quad \text{s.t.} \quad X_{11} + X_{22} = 2, \qquad \max_{y \in \mathbb{R}} \; 2y \quad \text{s.t.} \quad S = \begin{bmatrix} 1 - y &amp;amp; 0 \\ 0 &amp;amp; 2 - y \end{bmatrix} \succeq 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find the exact optimal primal-dual pair:&lt;/strong&gt;
Dual feasibility \(S \succeq 0\) requires \(1 - y \ge 0\) and \(2 - y \ge 0\), so \(y^\star = 1\) with dual optimal value \(2\) and \(S^\star = \operatorname{diag}(0, 1)\). Primal optimality forces \(X^\star S^\star = 0 \implies X_{22}^\star = 0\) and \(X_{12}^\star = 0\), so \(X^\star = \operatorname{diag}(2, 0)\) with primal value \(2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write the perturbed complementarity equations \(XS = \mu I_2\):&lt;/strong&gt;
Since \(S\) is diagonal and strictly positive definite for \(y &amp;lt; 1\), \(X = \mu S^{-1}\) is also diagonal:
\(X(\mu) = \begin{bmatrix} \frac{\mu}{1 - y} &amp;amp; 0 \\ 0 &amp;amp; \frac{\mu}{2 - y} \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enforce primal feasibility \(\operatorname{tr}(X(\mu)) = 2\) at \(\mu = 0.5\):&lt;/strong&gt;
\(\frac{0.5}{1 - y} + \frac{0.5}{2 - y} = 2 \implies \frac{3 - 2y}{(1 - y)(2 - y)} = 4 \implies 4y^2 - 10y + 5 = 0.\)
Selecting the strictly dual-feasible root \(y &amp;lt; 1\):
\(y(0.5) = \frac{10 - \sqrt{100 - 80}}{8} = \frac{5 - \sqrt{5}}{4} \approx 0.690983.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify interior positivity and exact duality gap:&lt;/strong&gt;
\(S(0.5) \approx \operatorname{diag}(0.309017, \; 1.309017) \succ 0, \qquad X(0.5) \approx \operatorname{diag}(1.618034, \; 0.381966) \succ 0.\)
Check: \(\operatorname{tr}(X(0.5)) = 2.000000\), \(X(0.5)S(0.5) = 0.5\, I_2\), and the duality gap is \(C \cdot X - 2y = 2.381966 - 1.381966 = 1.000000 = n\mu\) identically!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section we look at an example of the primal-dual method for SDP (semidefinite programming) problems.&lt;/p&gt;

&lt;h2 id=&quot;sdp-semidefinite-programming&quot;&gt;SDP (semidefinite programming)&lt;/h2&gt;
&lt;p&gt;The primal SDP problem is defined as follows.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{X} &amp;amp;&amp;amp; {C \cdot X} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {A_i \cdot X = b_i, i = 1,...,m} \\\\
   &amp;amp; &amp;amp;&amp;amp;{X \succeq 0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The dual SDP problem is defined as follows.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\max_{y} &amp;amp;&amp;amp; {b^Ty} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {\sum^m_{i=1} y_iA_i + S = C} \\\\
   &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Recall that the trace inner product on \(\mathbb{S}^n\) is written&lt;/p&gt;
&lt;blockquote&gt;
\[X \cdot S = \text{trace}(XS)\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;optimality-conditions-for-sdp&quot;&gt;Optimality conditions for SDP&lt;/h2&gt;
&lt;p&gt;The primal and dual SDP problems can be written with a linear map as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{X} &amp;amp;&amp;amp; {C \cdot X} &amp;amp; \qquad \qquad \qquad &amp;amp; \max_{y,S}  &amp;amp;&amp;amp; {b^Ty} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {\mathcal{A}(X) = b} &amp;amp; \qquad \qquad \qquad &amp;amp; \text{subject to } &amp;amp;&amp;amp; {\mathcal{A}^{*}(y) + S = C} \\\\
   &amp;amp; &amp;amp;&amp;amp;{X \succeq 0} &amp;amp; \qquad \qquad \qquad &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(\mathcal{A}: \mathbb{S}^n \to \mathbb{R}^m\) is a linear map.&lt;/p&gt;

&lt;p&gt;Assuming strong duality holds, \(X^{\star}\) and \((y^{\star}, S^{\star})\) are optimal solutions of the primal and dual problems if and only if \((X^{\star}, y^{\star}, S^{\star})\) satisfies the following conditions.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{array}{rcl}
\mathcal{A}^*(y) + S &amp;amp; = &amp;amp; C \\\
\mathcal{A}(X) &amp;amp; = &amp;amp; b \\\
XS &amp;amp; = &amp;amp; 0 \\\
X,S &amp;amp; \succeq &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;central-path-for-sdp&quot;&gt;Central path for SDP&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Primal barrier problem&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{X} &amp;amp;&amp;amp; {C \cdot X - \tau \log\det(X)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {\mathcal{A}(X) = b} 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Dual barrier problem&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\max_{y, S} &amp;amp;&amp;amp; {b^Ty + \tau \log\det(S)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {\mathcal{A}^*(y) + S = C} 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Optimality conditions for the primal and dual barrier problems&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
\mathcal{A}^*(y) + S &amp;amp; = &amp;amp; C \\\
\mathcal{A}(X) &amp;amp; = &amp;amp; b \\\
XS &amp;amp; = &amp;amp; \tau I \\\
X,S &amp;amp; \succ &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;newton-step&quot;&gt;Newton step&lt;/h2&gt;
&lt;p&gt;Primal central path equations&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
\mathcal{A}^*(y) + \tau X^{-1} &amp;amp; = &amp;amp; C \\\
\mathcal{A}(X) &amp;amp; = &amp;amp; b \\\
X &amp;amp; \succ &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Newton equations&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\tau X^{-1}\Delta X X^{-1} +\mathcal{A}^*(\Delta y) = -(\mathcal{A}^*(y) + \tau X^{-1} -C)\)
\(\mathcal{A}(\Delta X) = -(\mathcal{A}(X)-b)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The central path equations and Newton equations for the dual, involving \((y,S)\), are defined similarly.&lt;/p&gt;

&lt;h2 id=&quot;primal-dual-newton-step&quot;&gt;Primal-dual Newton step&lt;/h2&gt;
&lt;p&gt;Primal-dual central path equations&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{bmatrix}
\mathcal{A}^*(y) + S - C  \\\
\mathcal{A}(X) - b \\\
XS
\end{bmatrix} =
\begin{bmatrix}
0 \\\
0 \\\
\tau I
\end{bmatrix}
, \quad X, S \succ 0\]
&lt;/blockquote&gt;

&lt;p&gt;Newton step:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{bmatrix}
0 &amp;amp; \mathcal{A}^* &amp;amp; I \\\
\mathcal{A} &amp;amp; 0 &amp;amp; 0 \\\
S &amp;amp; 0 &amp;amp; X 
\end{bmatrix}
\begin{bmatrix}
\Delta X \\\
\Delta y \\\
\Delta S
\end{bmatrix}= -
\begin{bmatrix}
\mathcal{A}^*(y) + S - C \\\
\mathcal{A}(X) - b \\\
XS - \tau I 
\end{bmatrix}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>17-04 Special case, linear programming</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_04_special_case_linear_programming/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_04_special_case_linear_programming</id>
   <content type="html">&lt;p&gt;Linear programming is where primal-dual interior-point methods truly shine: the objective Hessian \(\nabla^2 f(x)\) is identically zero, the inequality constraints \(x \ge 0\) have trivial identity Jacobians, and the entire \(3 \times 3\) block KKT Newton system collapses via exact block elimination into a single symmetric positive definite (SPD) linear system of size \(m \times m\)—the &lt;strong&gt;normal equations&lt;/strong&gt;. Understanding this reduction explains how commercial solvers tackle LPs with millions of variables in seconds using sparse Cholesky factorization.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-the-lp-primal-dual-newton-system&quot;&gt;Key ideas: Anatomy of the LP Primal-Dual Newton System&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Standard-Form LP Primal-Dual Symmetry:&lt;/strong&gt; The primal \(\min c^T x \text{ s.t. } Ax = b, x \ge 0\) and dual \(\max b^T y \text{ s.t. } A^T y + s = c, s \ge 0\) share the exact complementarity condition \(X S \mathbf{1} = 0\), where \(X = \operatorname{diag}(x)\) and \(S = \operatorname{diag}(s)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Zero-Hessian Simplification:&lt;/strong&gt; Because \(f(x) = c^T x\) is linear, the top-left block of the KKT matrix is zero, making the linearized dual equation \(A^T \Delta y + \Delta s = -r_d\) purely algebraic in \(\Delta s\) and the linearized complementarity equation \(S \Delta x + X \Delta s = -X S \mathbf{1} + \sigma \mu \mathbf{1}\) diagonal.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Normal-Equations Schur Complement:&lt;/strong&gt; Eliminating \(\Delta s\) and \(\Delta x\) reduces the \((2n + m)\)-dimensional KKT system to the \(m \times m\) SPD system \((A D^2 A^T)\,\Delta y = \text{rhs}\), where \(D^2 = S^{-1} X = \operatorname{diag}(x_i / s_i) \succ 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Asymmetric Scaling &amp;amp; Mehrotra Predictor-Corrector:&lt;/strong&gt; As iterates approach a vertex, \(x_i/s_i \to \infty\) for basic variables and \(x_i/s_i \to 0\) for nonbasic variables, making \(A D^2 A^T\) progressively ill-conditioned—which modern LP solvers handle via stable LDL factorizations and second-order Mehrotra correctors.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-the-lp-normal-equations-exactly&quot;&gt;Worked example: Solving the LP Normal Equations Exactly&lt;/h3&gt;

&lt;p&gt;Consider the LP \(\min 2x_1 + 5x_2\) subject to \(x_1 + x_2 = 3\) and \(x_1, x_2 \ge 0\) (exact optimum \(x^\star = (3, 0), y^\star = 2, s^\star = (0, 3)\)). Start at the strictly feasible primal-dual point \(x = (2, 1)^T\), \(y = 1\), \(s = (1, 4)^T\) (verify: \(x_1 + x_2 = 3\) and \(A^T y + s = (1,1)^T + (1,4)^T = (2,5)^T = c\), so \(r_p = 0, r_d = 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the duality measure \(\mu\) and target \(\sigma \mu\):&lt;/strong&gt;
\(\mu = \frac{x^T s}{n} = \frac{2(1) + 1(4)}{2} = 3.\)
Choose \(\sigma = \frac{1}{3}\), so \(\sigma \mu = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form the diagonal scaling matrix \(D^2 = S^{-1} X\):&lt;/strong&gt;
\(D^2 = \operatorname{diag}\!\left(\frac{x_1}{s_1}, \frac{x_2}{s_2}\right) = \operatorname{diag}\!\left(\frac{2}{1}, \frac{1}{4}\right) = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 1/4 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assemble and solve the \(1 \times 1\) normal equation \((A D^2 A^T)\,\Delta y = A(x - \sigma \mu S^{-1}\mathbf{1})\):&lt;/strong&gt;
With \(A = [1, 1]\):
\(A D^2 A^T = 2 + \frac{1}{4} = \frac{9}{4}.\)
Since \(r_p = 0\) and \(r_d = 0\), the right-hand side is:
\(A\left(x - \sigma \mu S^{-1}\mathbf{1}\right) = (2 - 1 \cdot 1) + \left(1 - 1 \cdot \frac{1}{4}\right) = 1 + \frac{3}{4} = \frac{7}{4}.\)
Wait—let’s check the sign! From \(S\Delta x + X\Delta s = \sigma \mu \mathbf{1} - X S \mathbf{1}\) and \(\Delta s = -A^T \Delta y\), we get \(\Delta x = S^{-1}(\sigma \mu \mathbf{1} - XS\mathbf{1}) + S^{-1} X A^T \Delta y\). Multiplying by \(A\) and using \(A\Delta x = 0\) gives:
\((A D^2 A^T)\,\Delta y = A\left(x - \sigma \mu S^{-1}\mathbf{1}\right) = \frac{7}{4} \implies \Delta y = \frac{7/4}{9/4} = \frac{7}{9}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recover \(\Delta s\) and \(\Delta x\) by back-substitution:&lt;/strong&gt;
\(\Delta s = -A^T \Delta y = \begin{bmatrix} -7/9 \\ -7/9 \end{bmatrix},\)
\(\Delta x_1 = \frac{1 - 2(1) - 2(-7/9)}{1} = -1 + \frac{14}{9} = +\frac{5}{9}, \qquad \Delta x_2 = \frac{1 - 1(4) - 1(-7/9)}{4} = \frac{-20/9}{4} = -\frac{5}{9}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify exact feasibility and gap contraction at \(\theta = 1\):&lt;/strong&gt;
\(x^+ = \left(\frac{23}{9}, \frac{4}{9}\right)^T &amp;gt; 0, \qquad y^+ = \frac{16}{9}, \qquad s^+ = \left(\frac{2}{9}, \frac{29}{9}\right)^T &amp;gt; 0.\)
Check: \(x_1^+ + x_2^+ = \frac{27}{9} = 3\), \(y^+ + s^+ = (2, 5)^T\), and the duality gap plunged from \(x^T s = 6\) to \(\frac{46 + 116}{81} = \frac{162}{81} = 2 = 2\sigma\mu\) in one exact step!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, let’s look at an example of the Primal-Dual method for LP (linear programming) problems.&lt;/p&gt;

&lt;h2 id=&quot;linear-programming&quot;&gt;Linear programming&lt;/h2&gt;
&lt;p&gt;Consider the following primal LP problem.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{x} &amp;amp;&amp;amp; {c^Tx} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {Ax = b} \\\\
   &amp;amp; &amp;amp;&amp;amp;{x ≥ 0} \\\
\end{align}\]

\[\text{for } c ∈R^n, A ∈R^{m×n}, b ∈R^m\]
&lt;/blockquote&gt;

&lt;p&gt;The dual problem of the above primal LP problem is as follows.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\max_{y,s}  &amp;amp;&amp;amp; {b^Ty} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp; {A^Ty + s = c} \\\\
   &amp;amp; &amp;amp;&amp;amp;{s ≥ 0} \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;optimality-conditions-and-central-path-equations&quot;&gt;Optimality conditions and central path equations&lt;/h2&gt;
&lt;p&gt;The following shows the optimality conditions (KKT Conditions) for the primal-dual problem of the previous LP.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
A^Ty + s &amp;amp; = &amp;amp; c \\\
Ax &amp;amp; = &amp;amp; b \\\
XS\mathbb{1} &amp;amp; = &amp;amp; 0 \\\
x,s  &amp;amp; \succeq &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Central path equations&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
A^Ty + s &amp;amp; = &amp;amp; c \\\
Ax &amp;amp; = &amp;amp; b \\\
XS\mathbb{1} &amp;amp; = &amp;amp; τ\mathbb{1} \\\
x,s  &amp;amp; &amp;gt; &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;primal-dual-method-vs-barrier-method&quot;&gt;Primal-dual method vs. barrier method&lt;/h2&gt;
&lt;h3 id=&quot;newton-steps-for-primer-dual-method&quot;&gt;Newton steps for primer-dual method&lt;/h3&gt;
&lt;p&gt;The following is the Newton equation for the primal-dual method for LP problems.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{bmatrix}
0 &amp;amp; A^T &amp;amp; I \\\
A &amp;amp; 0 &amp;amp; 0 \\\
S &amp;amp; 0 &amp;amp; X 
\end{bmatrix}
\begin{bmatrix}
∆x \\\
∆y \\\
∆s 
\end{bmatrix}= −
\begin{bmatrix}
A^Ty + s−c \\\
Ax−b \\\
XS\mathbb{1}−τ\mathbb{1} 
\end{bmatrix}\]
&lt;/blockquote&gt;

&lt;p&gt;From the optimal condition, we can know the following relationship.&lt;/p&gt;

\[XS\mathbb{1} = \tau \mathbb{1} \iff s = \tau X^{−1}\mathbb{1} \iff x = \tau S^{−1}\mathbb{1}\]

&lt;p&gt;Accordingly, we can obtain optimal conditions for the primal barrier problem by removing \(s\), or obtain optimal conditions for the dual barrier problem by removing \(x\).&lt;/p&gt;

&lt;h3 id=&quot;newton-steps-for-barrier-problems&quot;&gt;Newton steps for barrier problems&lt;/h3&gt;
&lt;p&gt;The following are the primal and dual central path equations for the barrier problem. (Left is primal, right is dual)&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcr}
A^Ty + τX^{−1}1 &amp;amp; = &amp;amp; c &amp;amp; \qquad \qquad &amp;amp; A^Ty + s &amp;amp; = &amp;amp; c \\\
Ax &amp;amp; = &amp;amp; b &amp;amp; \qquad \qquad &amp;amp; τAS^{−1}\mathbb{1} &amp;amp; = &amp;amp; b\\\
x &amp;amp; &amp;gt; &amp;amp; 0 &amp;amp; \qquad \qquad &amp;amp; s &amp;amp; &amp;gt; &amp;amp; 0
\end{array}\]

&lt;/blockquote&gt;

&lt;p&gt;Using the above central path equations, the Newton steps for primal and dual are as follows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primal Newton step&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{bmatrix}
τX^{−2} &amp;amp; A^T \\\
A &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
∆x \\\
∆y
\end{bmatrix}= −
\begin{bmatrix}
A^Ty + τX^{−1}\mathbb{1}−c \\\
Ax−b 
\end{bmatrix}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Dual Newton step&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{bmatrix}
A^T &amp;amp; I \\\
0 &amp;amp; τAS^{−2}
\end{bmatrix}
\begin{bmatrix}
∆y \\\
∆s
\end{bmatrix}= −
\begin{bmatrix}
A^Ty + s −c \\\
τAS^{−1}\mathbb{1}−b
\end{bmatrix}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;example-barrier-versus-primal-dual&quot;&gt;Example: barrier versus primal-dual&lt;/h2&gt;
&lt;h3 id=&quot;standard-lp--n--50-m--100&quot;&gt;Standard LP : \(n = 50\), \(m = 100\)&lt;/h3&gt;
&lt;p&gt;To verify the performance of the Primal-dual method, let’s look at an example of a standard LP problem with \(n = 50\) variables and \(m = 100\) equality constraints. (Example from B &amp;amp; V 11.3.2 and 11.7.4)&lt;/p&gt;

&lt;p&gt;The Barrier method used various \(\mu\) values (2, 50, 150) while the primal-dual method fixed \(\mu\) at 10.
Both methods used \(\alpha = 0.01, \beta = 0.5\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter17/barrier_vs_primal_dual.png&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Duality gap (Barrier vs. Primal-dual) [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;As can be seen from the graph, primal-dual converges quickly while showing high accuracy.&lt;/p&gt;

&lt;h3 id=&quot;sequence-of-problem--n--2m-and-n-growing&quot;&gt;Sequence of problem : \(n = 2m\) and \(n\) growing.&lt;/h3&gt;
&lt;p&gt;Now let’s look at the performance for a series of problems where \(n = 2m\) and \(n\) gradually increases.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The Barrier method used \(\mu = 100\) and the outer loop was performed only about 2 times. (The duality gap was reduced to \(10^4\))&lt;/li&gt;
  &lt;li&gt;The Primal-dual method used \(\mu = 10\) and stopped execution when the duality gap and feasibility gap were approximately \(10^{-8}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter17/barrier_vs_primal_dual2.png&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Newton iteration (Barrier vs. Primal-dual) [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;As can be seen from the above figure, the Primal-dual method finds solutions with higher accuracy but requires some additional iterations.&lt;/p&gt;

&lt;h3 id=&quot;primal-dual-vs-barrier-method-video&quot;&gt;Primal-dual vs. barrier method (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/primal-dual-ipm_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The barrier method re-centres after each update of \(t\); the primal-dual method takes a single Newton step on the perturbed KKT conditions in \((x,\lambda)\) and cuts the duality gap with far fewer steps.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-primal-dual-vs-barrier&quot;&gt;Try it yourself: primal-dual vs barrier&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;pdipm&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>17-03 Some history</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_03_some_history/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_03_some_history</id>
   <content type="html">&lt;p&gt;For thirty years after George Dantzig invented the Simplex method in 1947, linear programming lived with an extraordinary paradox: in practice, Simplex solved industrial problems in a handful of pivots, yet nobody could prove it ran in polynomial time. In 1972, Klee and Minty shattered that hope by constructing a slightly squashed hypercube that forced Simplex to visit every single one of its \(2^n\) corners. That shockwave triggered one of the most dramatic chapters in modern applied mathematics—from Khachiyan’s front-page ellipsoid theorem to Karmarkar’s interior-point revolution and today’s near-linear-time LP algorithms.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-complexity-arc-of-linear-programming&quot;&gt;Key ideas: The Complexity Arc of Linear Programming&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Boundary-Walking (Simplex) vs. Interior-Cutting (IPM):&lt;/strong&gt; Simplex moves along 1D edges of the feasible polytope from vertex to vertex; while typically requiring \(O(m)\) pivots in practice, adversarial geometry (Klee–Minty cubes) induces exponential \(2^n\) worst-case behavior.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khachiyan’s Ellipsoid Breakthrough (1979):&lt;/strong&gt; Proved for the first time that LP is in \(\mathbf{P}\) by enclosing the feasible set in shrinking ellipsoids—a monumental theoretical triumph that remained too slow in practice due to \(O(n^2 \log(1/\epsilon))\) iterations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Karmarkar’s Projective Interior-Point Method (1984):&lt;/strong&gt; Combined polynomial-time complexity with practical speed by cutting straight through the interior of the polytope, sparking the primal-dual path-following revolution.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-Concordance &amp;amp; Modern Complexity (Renegar 1988 to Lee–Sidford):&lt;/strong&gt; Renegar established the \(O(\sqrt{n}\log(1/\epsilon))\) Newton iteration bound via path-following; Nesterov and Nemirovskii generalized it to all self-concordant cones (SOCP, SDP), and recent breakthroughs (Lee–Sidford, Cohen–Lee–Song) pushed total arithmetic complexity toward matrix-multiplication time \(O(n^\omega)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-the-2d-kleeminty-cube-vs-the-analytic-center&quot;&gt;Worked example: The 2D Klee–Minty Cube vs. the Analytic Center&lt;/h3&gt;

&lt;p&gt;Consider the 2D Klee–Minty LP with distortion \(\epsilon = 1/4\):
\(\max \; x_2 \quad \text{subject to} \quad 0 \le x_1 \le 1, \quad \frac{1}{4} x_1 \le x_2 \le 1 - \frac{1}{4} x_1.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify all \(2^2 = 4\) vertices of this slightly tilted square:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v_0 = (0, 0)\), objective \(0\).&lt;/li&gt;
      &lt;li&gt;\(v_1 = (1, 0)\) — wait: \(x_2 \ge \frac{1}{4} x_1\) gives \(v_1 = (1, 1/4)\), objective \(0.25\).&lt;/li&gt;
      &lt;li&gt;\(v_2 = (1, 3/4)\), objective \(0.75\).&lt;/li&gt;
      &lt;li&gt;\(v_3 = (0, 1)\), objective \(1.00\) (global optimum).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trace Dantzig’s steepest-reduced-cost Simplex path starting from \(v_0 = (0, 0)\):&lt;/strong&gt;
Along the tilted bottom edge from \((0, 0)\) to \((1, 1/4)\), \(x_2\) increases; in the canonical Klee–Minty parameterization (where \(x_1\) enters first under Dantzig’s rule), Simplex walks the full Hamiltonian path:
\((0, 0) \;\longrightarrow\; \left(1, \tfrac{1}{4}\right) \;\longrightarrow\; \left(1, \tfrac{3}{4}\right) \;\longrightarrow\; (0, 1),\)
visiting all \(4 = 2^2\) vertices! In \(n\) dimensions, the same recursive tilt forces \(2^n - 1\) pivots (for \(n = 50\), over \(10^{15}\) pivots).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with the interior-point central path:&lt;/strong&gt;
An interior-point method ignores the tilted boundary corners completely. Starting near the analytic center \(x_c \approx (0.5, 0.5)\), its central path curves smoothly upward through the interior directly toward \((0, 1)\). Even in \(n = 50\) dimensions, the iteration bound scales as \(O(\sqrt{n}\log(1/\epsilon))\)—roughly \(20\text{–}30\) Newton steps instead of \(10^{15}\) pivots.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Generally, modern state-of-the-art LP Solvers use both Simplex method and interior-point method.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Dantzig (1940s): Simplex method, the first method to solve the general form of LP, obtaining exact solutions without iteration. It remains one of the best-known and most studied algorithms for LP to this day.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Klee and Minty (1972): A pathological LP with \(n\) variables and \(2n\) constraints. Solving with the Simplex method requires \(2^n\) iterations.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Khachiyan (1979): A polynomial-time algorithm for LP based on the ellipsoid method of Nemirovski and Yudin (1976), which is theoretically strong but not so in practice.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Karmarkar (1984): An interior-point polynomial-time LP method that is quite effective and became a breakthrough research. (US Patent 4,744,026, expired in 2006).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Renegar (1988): Newton-based interior-point algorithm for LP. It had the theoretically best computational complexity until the latest research by Lee-Sidford emerged.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>17-02 Primal-dual interior-point method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_02_primal_dual_interior_point_method/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_02_primal_dual_interior_point_method</id>
   <content type="html">&lt;p&gt;At first glance, switching from the barrier method to a primal-dual interior-point method looks like a minor engineering tweak—dropping the inner loop and taking one Newton step per \(\tau\) update. In practice, that single architectural shift transforms interior-point optimization from a textbook curiosity into the fastest general-purpose convex solver engine ever built. Understanding &lt;em&gt;why&lt;/em&gt; one coupled primal-dual step outperforms an entire inner barrier loop is the conceptual heart of Chapter 17.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-barrier-method-vs-primal-dual-philosophy&quot;&gt;Key ideas: Barrier Method vs. Primal-Dual Philosophy&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Single-Loop Coupled Newton Dynamics:&lt;/strong&gt; The barrier method isolates primal updates inside an inner loop while holding \(t\) fixed; PD-IPM updates \((x, u, v)\) simultaneously in one linearized KKT solve and decreases \(\tau\) at every iteration.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infeasible-Start Flexibility:&lt;/strong&gt; Barrier methods demand a strictly feasible starting point satisfying \(Ax^0 = b\) and \(h(x^0) &amp;lt; 0\) (often requiring a full Phase I solve). PD-IPMs only require strict interiority of the inequalities and multipliers (\(h(x^0) &amp;lt; 0, u^0 &amp;gt; 0\)), driving \(Ax^k - b \to 0\) automatically along the way.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Direct Control of Complementarity:&lt;/strong&gt; Because \(u\) is an independent variable rather than a post-hoc formula \(-1/(t h(x))\), the linearized complementarity equation \(U \nabla h(x)\,\Delta x + H(x)\,\Delta u = -Uh(x) - \tau \mathbf{1}\) directly balances primal slackness against dual magnitude.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Superlinear Local Acceleration:&lt;/strong&gt; Near the solution, the coupled KKT Jacobian approaches the exact Newton system for the active constraints, allowing PD-IPMs to transition from linear global progress to superlinear (and in LP, quadratic) local convergence.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-handling-an-infeasible-start&quot;&gt;Worked example: Handling an Infeasible Start&lt;/h3&gt;

&lt;p&gt;Suppose we want to solve the LP \(\min 2x_1 + 3x_2\) subject to \(x_1 + x_2 = 4\) and \(x_1, x_2 \ge 0\) (exact optimum \(x^\star = (4, 0), v^\star = -2, u^\star = (0, 1)\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Pick a simple interior starting point that violates the equality constraint:&lt;/strong&gt;
Set \(x^0 = (2, 1)\), \(u^0 = (1, 1)\), \(v^0 = 0\). Notice \(x^0 &amp;gt; 0\) and \(u^0 &amp;gt; 0\), so the strict positivity requirement holds, even though \(x_1^0 + x_2^0 = 3 \neq 4\) (primal residual \(r_{\text{prim}}^0 = -1\)). A standard barrier method cannot even start here without a Phase I problem.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the dual residual:&lt;/strong&gt;
With \(c = (2, 3)^T\), \(A = [1, 1]\), and \(h(x) = -x\):
\(r_{\text{dual}}^0 = c - u^0 + A^T v^0 = \begin{bmatrix} 2 \\ 3 \end{bmatrix} - \begin{bmatrix} 1 \\ 1 \end{bmatrix} + \begin{bmatrix} 0 \\ 0 \end{bmatrix} = \begin{bmatrix} 1 \\ 2 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;See how one Newton step eliminates infeasibility:&lt;/strong&gt;
In the primal-dual Newton system, the equality row enforces \(A \Delta x = -r_{\text{prim}}^0 = 1\) (i.e., \(\Delta x_1 + \Delta x_2 = 1\)), and the stationarity row enforces \(-\Delta u + A^T \Delta v = -r_{\text{dual}}^0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Observe the exact contraction law for linear residuals:&lt;/strong&gt;
For &lt;em&gt;any&lt;/em&gt; step length \(\theta \in (0, 1]\) chosen by backtracking, the updated residuals satisfy:
\(r_{\text{prim}}(z^0 + \theta \Delta z) = (1 - \theta) r_{\text{prim}}^0, \qquad r_{\text{dual}}(z^0 + \theta \Delta z) = (1 - \theta) r_{\text{dual}}^0.\)
If \(\theta = 0.8\) is feasible, both primal and dual infeasibility shrink by \(80\%\) in a single iteration—and as soon as a full step \(\theta = 1\) is accepted, both linear residuals vanish identically to \(0\) for all remaining iterations!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Like the barrier method, the &lt;strong&gt;primal-dual interior-point method&lt;/strong&gt; also aims to (approximately) compute points on the central path. However, the two methods have several differences.&lt;/p&gt;

&lt;h2 id=&quot;differences-between-primal-dual-interior-point-method-and-barrier-method&quot;&gt;Differences between Primal-dual interior-point method and barrier method&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Generally performs &lt;strong&gt;one Newton step&lt;/strong&gt; per iteration. (That is, there is no additional loop for the centering step.)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Does not necessarily need to be feasible&lt;/strong&gt;. (Pushes toward feasible regions through backtracking line search.)&lt;/li&gt;
  &lt;li&gt;Generally &lt;strong&gt;more effective&lt;/strong&gt;. Particularly shows superior performance compared to linear convergence under appropriate conditions.&lt;/li&gt;
  &lt;li&gt;Somewhat less intuitive compared to the barrier method.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>17-02-03 Primal-Dual Algorithm</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_02_03_primal_dual_algorithm/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_02_03_primal_dual_algorithm</id>
   <content type="html">&lt;p&gt;You now have all the pieces of the engine—perturbed KKT residuals, the coupled Newton direction, and the surrogate duality gap—so it is time to assemble the complete &lt;strong&gt;Primal-Dual Interior-Point Algorithm&lt;/strong&gt;. The subtle part is not computing \((\Delta x, \Delta u, \Delta v)\), but choosing the step length \(\theta_k\): step too aggressively and a multiplier or slack crosses zero, shattering the interior invariant; step too timidly and convergence stalls. Backtracking on the residual norm \(\|r_\tau\|_2\) with a fraction-to-the-boundary cap threads that needle cleanly.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-orchestrating-the-primal-dual-loop&quot;&gt;Key ideas: Orchestrating the Primal-Dual Loop&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive Target Reduction (\(\tau = \sigma \eta / m\)):&lt;/strong&gt; Rather than guessing a fixed schedule for \(\tau\), the algorithm measures the current average complementarity \(\eta / m\) and aims for a fraction \(\sigma \in (0, 1)\) of it (typically \(\sigma \in [0.1, 0.5]\)), balancing aggressive gap reduction against staying near the central path.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fraction-to-the-Boundary Step Cap (\(\theta_{\max}\)):&lt;/strong&gt; Before backtracking begins, we compute the largest step \(\theta_{\max} = \min\!\big(1, \; \min_{\Delta u_i &amp;lt; 0}(-u_i/\Delta u_i)\big)\) that keeps \(u + \theta \Delta u &amp;gt; 0\), and shrink by \(0.99\) so iterates never touch the boundary \(u_i = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Residual-Norm Backtracking Line Search:&lt;/strong&gt; Because the objective \(f(x)\) can actually &lt;em&gt;increase&lt;/em&gt; while an infeasible iterate moves toward feasibility, line search cannot monitor \(f(x)\). Instead, it enforces strict interiority \(h(x^+) &amp;lt; 0\) and sufficient decrease of the total residual norm: \(\|r_\tau(z + \theta \Delta z)\|_2 \le (1 - \alpha \theta)\|r_\tau(z)\|_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual-Criterion Termination:&lt;/strong&gt; The loop halts only when &lt;em&gt;both&lt;/em&gt; the surrogate gap \(\eta \le \epsilon_{\text{feas}}\) and the combined primal-dual feasibility residual \(\sqrt{\|r_{\text{prim}}\|_2^2 + \|r_{\text{dual}}\|_2^2} \le \epsilon\) meet tolerance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-full-iteration-with-backtracking&quot;&gt;Worked example: One Full Iteration with Backtracking&lt;/h3&gt;

&lt;p&gt;Consider \(\min x_1 + 2x_2\) subject to \(x_1 + x_2 = 2\) and \(x_1, x_2 \ge 0\) (exact optimum \(x^\star = (2, 0), u^\star = (0, 1), v^\star = -1\)). Start at \(x^0 = (1, 1)^T, u^0 = (1, 1)^T, v^0 = -1\) with \(\sigma = 0.5\) and backtracking parameter \(\alpha = 0.1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the surrogate gap and target \(\tau\):&lt;/strong&gt;
\(\eta_0 = x_1^0 u_1^0 + x_2^0 u_2^0 = 1 + 1 = 2 \implies \tau_0 = \frac{2}{2} = 1, \quad \tau = \sigma \tau_0 = 0.5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the residuals at \(z^0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(r_{\text{prim}}^0 = 1 + 1 - 2 = 0\).&lt;/li&gt;
      &lt;li&gt;\(r_{\text{dual}}^0 = \begin{bmatrix}1\\2\end{bmatrix} - \begin{bmatrix}1\\1\end{bmatrix} + (-1)\begin{bmatrix}1\\1\end{bmatrix} = \begin{bmatrix}-1\\0\end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;\(r_{\text{cent}}^0 = \begin{bmatrix}-1 + 0.5 \\ -1 + 0.5\end{bmatrix} = \begin{bmatrix}-0.5 \\ -0.5\end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;Residual norm: \(\|r_\tau(z^0)\|_2 = \sqrt{1^2 + 0^2 + (-0.5)^2 + (-0.5)^2 + 0^2} = \sqrt{1.5} \approx 1.2247\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the Newton system for \((\Delta x, \Delta u, \Delta v)\):&lt;/strong&gt;
From \(r_{\text{prim}}\): \(\Delta x_1 + \Delta x_2 = 0 \implies \Delta x_2 = -\Delta x_1\).
From \(r_{\text{dual}}\): \(-\Delta u_1 + \Delta v = 1\) and \(-\Delta u_2 + \Delta v = 0 \implies \Delta u_1 = \Delta v - 1, \; \Delta u_2 = \Delta v\).
From \(r_{\text{cent}}\): \(-\Delta x_1 - \Delta u_1 = 0.5\) and \(-\Delta x_2 - \Delta u_2 = 0.5\). Adding these two equations eliminates \(\Delta x_1 + \Delta x_2 = 0\), giving:
\(-(\Delta u_1 + \Delta u_2) = 1 \implies -(2\Delta v - 1) = 1 \implies \Delta v = 0.\)
Hence \(\Delta u = (-1, 0)^T\) and \(\Delta x = (0.5, -0.5)^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the boundary step cap \(\theta_{\max}\):&lt;/strong&gt;
Since \(\Delta u_1 = -1 &amp;lt; 0\), \(u_1 + \theta \Delta u_1 &amp;gt; 0 \implies \theta &amp;lt; 1\). Since \(\Delta x_2 = -0.5 &amp;lt; 0\), \(x_2 + \theta \Delta x_2 &amp;gt; 0 \implies \theta &amp;lt; 2\). Taking \(0.99 \theta_{\max}\) gives \(\theta = 0.99\) (for clean hand arithmetic, test \(\theta = 0.8\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the backtracking decrease condition at \(\theta = 0.8\):&lt;/strong&gt;
\(x^1 = (1.4, 0.6)^T, \quad u^1 = (0.2, 1.0)^T, \quad v^1 = -1.\)
    &lt;ul&gt;
      &lt;li&gt;\(r_{\text{prim}}^1 = 0\), \(r_{\text{dual}}^1 = (1 - 0.8) r_{\text{dual}}^0 = (-0.2, 0)^T\).&lt;/li&gt;
      &lt;li&gt;\(r_{\text{cent}}^1 = \begin{bmatrix}-(1.4)(0.2) + 0.5 \\ -(0.6)(1.0) + 0.5\end{bmatrix} = \begin{bmatrix}0.22 \\ -0.10\end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;\(\|r_\tau(z^1)\|_2 = \sqrt{0.04 + 0.0484 + 0.01} = \sqrt{0.0984} \approx 0.3137 \le (1 - 0.1 \times 0.8)(1.2247) = 1.1268\).
The step is accepted immediately! Surrogate gap plunged from \(2.0\) to \(1.4(0.2) + 0.6(1.0) = 0.88\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To define the primal-dual algorithm, we first define \(\tau(x,u)\) as follows.&lt;/p&gt;
&lt;blockquote&gt;
\[\tau(x,u) := -\frac{h(x)^Tu}{m} \quad \text{with} \quad h (x) \le 0, u \ge 0\]
&lt;/blockquote&gt;

&lt;p&gt;Note that the \(t\) and \(\mu\) of the barrier method are rewritten as \(\tau\) and \(\sigma\) in the primal-dual algorithm.&lt;/p&gt;
&lt;blockquote&gt;
\[\tau = \frac{1}{t}, \quad \sigma = \frac{1}{\mu}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;primal-dual-algorithm&quot;&gt;Primal-Dual Algorithm&lt;/h2&gt;
&lt;p&gt;The primal-dual algorithm is as follows.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;ol&gt;
    &lt;li&gt;Choose \(\sigma \in (0,1)\).&lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;Choose \((x^0,u^0,v^0)\) with \(h(x^0) &amp;lt; 0\) and \(u^0 &amp;gt; 0\).&lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;Repeat the following steps (\(k = 0,1,...\)):&lt;br /&gt;
\(\quad\) * Compute the Newton step:&lt;br /&gt;
\(\qquad \quad (x,u,v) = (x^k,u^k,v^k)\) &lt;br /&gt;
\(\qquad \quad\) compute \(\tau := \sigma \tau(x^k,u^k)\)&lt;br /&gt;
\(\qquad \quad\) compute \((\Delta x,\Delta u,\Delta v)\) for this \(\tau\)&lt;br /&gt;
\(\quad\) * Choose the step length \(\theta_k\) by backtracking.&lt;br /&gt;
\(\quad\) * Primal-dual update:&lt;br /&gt;
\(\qquad \quad (x^{k+1},u^{k+1},v^{k+1}) := (x^k,u^k,v^k) + \theta_k(\Delta x,\Delta u,\Delta v)\)&lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;Stop when \(-h(x^{k+1})^Tu \le \epsilon\) and \((\parallel r_{prim} \parallel^2_2 + \parallel r_{dual} \parallel^2_2)^{1/2} \le \epsilon\).&lt;br /&gt;&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;At each step the algorithm takes a Newton step to compute \((\Delta x,\Delta u,\Delta v)\) and then performs the primal-dual update to obtain \((x^{k+1},u^{k+1},v^{k+1})\). The step length \(\theta_k\) is chosen by backtracking line search so that the primal-dual variables stay feasible. The algorithm stops when the surrogate duality gap and the primal and dual residuals are smaller than \(\epsilon\).&lt;/p&gt;

&lt;h2 id=&quot;backtracking-line-search&quot;&gt;Backtracking line search&lt;/h2&gt;
&lt;p&gt;Since the primal-dual algorithm takes only one Newton step per iteration, the step should be regarded as giving a direction toward the solution rather than an exact solution. We therefore need to choose a suitable step length so that, while moving in that direction, the iterate stays inside the feasible set.&lt;/p&gt;

&lt;p&gt;That is, at each step of the algorithm we find \(\theta\) and update the primal-dual variables.&lt;/p&gt;

&lt;blockquote&gt;
\[x^+ = x + \theta \Delta x, \quad  u^+ = u + \theta \Delta u, \quad v^+ = v + \theta \Delta v\]
&lt;/blockquote&gt;

&lt;p&gt;This process has two main goals.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Maintain \(h(x) &amp;lt; 0, u &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;Decrease \(\parallel r(x,u,v) \parallel\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this we use a &lt;strong&gt;multi-stage backtracking line search&lt;/strong&gt;.&lt;/p&gt;

&lt;h4 id=&quot;stage-1-dual-feasibility-u-gt-0&quot;&gt;Stage 1: dual feasibility \(u \gt 0\)&lt;/h4&gt;
&lt;p&gt;We start with the largest step \(\theta_{max} \le 1\) satisfying \(u + \theta \Delta u \ge 0\).&lt;/p&gt;

&lt;blockquote&gt;
\[\theta_{\max} = \min \Biggl\{1,\  \min \Bigl\{ -\frac{u_i}{\Delta u_i} : \Delta u_i &amp;lt; 0 \Bigr\} \Biggr\}\]
&lt;/blockquote&gt;

&lt;p&gt;This is derived as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;u + \theta \Delta u &amp;amp;&amp;amp; \ge 0  \\\\
\Leftrightarrow \quad &amp;amp;u &amp;amp;&amp;amp; \ge -\theta \Delta u \\\\
\Leftrightarrow \quad &amp;amp;- u/\Delta u &amp;amp;&amp;amp; \ge \theta \quad  \text{ for the components with }\Delta u \lt 0  \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This step makes \(u\) feasible.&lt;/p&gt;

&lt;h4 id=&quot;stage-2-primal-feasibility-hx-lt-0&quot;&gt;Stage 2: primal feasibility \(h(x) \lt 0\)&lt;/h4&gt;
&lt;p&gt;Next, choose parameters \(\alpha, \beta \in (0,1)\), set \(\theta = 0.99\theta_{max}\), and then do the following.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Update \(\theta = \beta\theta\) until \(h_i(x^+) &amp;lt; 0, i = 1,...,m\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This step makes \(x\) feasible.&lt;/p&gt;

&lt;h4 id=&quot;stage-3-reduce-parallel-rxuv-parallel&quot;&gt;Stage 3: reduce \(\parallel r(x,u,v) \parallel\)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Update \(\theta = \beta \theta\) until \(\| r(x^+,u^+,v^+) \| \le (1-\alpha \theta) \| r(x,u,v) \|\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The update in Stage 3 is the same as in the standard backtracking line search algorithm.&lt;/p&gt;

&lt;p&gt;The right-hand side of the condition can be derived as follows. First, from Newton’s method we have&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\Delta w = (\Delta x, \Delta u, \Delta v) &amp;amp;\approx -r^{\prime}(w)^{-1} r(w) \\\\
\Leftrightarrow r(w)  &amp;amp;\approx  -r^{\prime}(w) \Delta w \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Since \(r^{\prime}(w) \Delta w \approx -r(w)\), substituting this into the first-order Taylor approximation gives&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
r(w + \theta \Delta w) &amp;amp; \approx r(w) +  r^{\prime}(w) (\theta \Delta w) \\\\
&amp;amp;\approx (1-\theta) r(w) \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Consequently, \(r(w + \alpha \theta \Delta w) \approx (1-\alpha  \theta) r(w)\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>17-02-02 Surrogate duality gap, residuals</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_02_02_surrogate_duality_gap_residuals/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_02_02_surrogate_duality_gap_residuals</id>
   <content type="html">&lt;p&gt;When a barrier solver runs, measuring how close you are to optimality is easy: every iterate is feasible, so \(f(x) - g(u, v) = m/t\) is a genuine, certified upper bound on suboptimality. Once a primal-dual solver allows &lt;em&gt;infeasible&lt;/em&gt; iterates, \(g(u, v)\) may not even be finite—so how do we know whether a step actually improved things, or when it is safe to stop? The answer lies in splitting the KKT error into three distinct residuals and replacing the true duality gap with a &lt;strong&gt;surrogate duality gap&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-measuring-progress-without-feasibility&quot;&gt;Key ideas: Measuring Progress Without Feasibility&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal Residual (\(r_{\text{prim}} = Ax - b\)):&lt;/strong&gt; Quantifies violation of linear equality constraints. Driving \(\|r_{\text{prim}}\|_2 \to 0\) pulls iterates onto the affine feasible subspace.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Residual (\(r_{\text{dual}} = \nabla f(x) + \nabla h(x) u + A^T v\)):&lt;/strong&gt; Measures violation of Lagrangian stationarity. Only when \(r_{\text{dual}} = 0\) does \(x\) minimize \(L(\cdot, u, v)\), certifying that \((u, v)\) lies in the domain of the dual function \(g\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Centrality Residual (\(r_{\text{cent}} = U h(x) + \tau \mathbf{1}\)):&lt;/strong&gt; Tracks how far each inequality’s complementarity product \(-u_i h_i(x)\) deviates from the uniform central-path target \(\tau\), preventing any single constraint from slamming into the boundary prematurely.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Surrogate Duality Gap (\(\eta = -h(x)^T u\)):&lt;/strong&gt; Defined whenever \(h(x) \le 0\) and \(u \ge 0\), \(\eta \ge 0\) equals the true duality gap &lt;em&gt;if and only if&lt;/em&gt; \(r_{\text{prim}} = 0\) and \(r_{\text{dual}} = 0\). In the algorithm, \(\eta / m\) dynamically sets the next target \(\tau = \sigma \eta / m\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-auditing-residuals-and-surrogate-gap-at-an-infeasible-point&quot;&gt;Worked example: Auditing Residuals and Surrogate Gap at an Infeasible Point&lt;/h3&gt;

&lt;p&gt;Consider the convex QP \(\min \frac{1}{2}(x_1^2 + x_2^2)\) subject to \(x_1 + x_2 = 2\) and \(h_1(x) = -x_1 \le 0, \; h_2(x) = -x_2 \le 0\) (\(m = 2\)). Evaluate the residuals at the infeasible interior iterate \(x = (0.5, 1.0)^T\), \(u = (0.4, 0.6)^T\), \(v = -1.0\) with \(\tau = 0.5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Primal residual:&lt;/strong&gt;
\(r_{\text{prim}} = Ax - b = (0.5 + 1.0) - 2 = -0.5 \implies \|r_{\text{prim}}\|_2 = 0.5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual residual:&lt;/strong&gt;
Since \(\nabla f(x) = (x_1, x_2)^T\), \(\nabla h(x) = -I\), and \(A^T = (1, 1)^T\):
\(r_{\text{dual}} = \begin{bmatrix} 0.5 \\ 1.0 \end{bmatrix} - \begin{bmatrix} 0.4 \\ 0.6 \end{bmatrix} + (-1.0)\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} -0.9 \\ -0.6 \end{bmatrix}, \quad \|r_{\text{dual}}\|_2 = \sqrt{0.81 + 0.36} = \sqrt{1.17} \approx 1.0817.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Surrogate duality gap:&lt;/strong&gt;
\(\eta = -h(x)^T u = x_1 u_1 + x_2 u_2 = (0.5)(0.4) + (1.0)(0.6) = 0.2 + 0.6 = 0.8.\)
Notice why \(\eta = 0.8\) is only a &lt;em&gt;surrogate&lt;/em&gt;: at \(x = (0.5, 1.0)\), \(f(x) = 0.625\) is actually &lt;em&gt;below&lt;/em&gt; the true optimal value \(f^\star = 1.0\) (at \(x^\star = (1, 1)\)) because \(x\) is primal infeasible!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Centrality residual:&lt;/strong&gt;
\(r_{\text{cent}} = U h(x) + \tau \mathbf{1} = \begin{bmatrix} -0.2 + 0.5 \\ -0.6 + 0.5 \end{bmatrix} = \begin{bmatrix} 0.3 \\ -0.1 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diagnostic takeaway:&lt;/strong&gt;
Although the average complementarity \(\eta/m = 0.4\) is modest, the combined feasibility residual \(\sqrt{\|r_{\text{prim}}\|_2^2 + \|r_{\text{dual}}\|_2^2} = \sqrt{0.25 + 1.17} = \sqrt{1.42} \approx 1.1916\) is still large, so a solver cannot terminate until &lt;em&gt;both&lt;/em&gt; \(\eta \le \epsilon\) and \(\sqrt{\|r_{\text{prim}}\|_2^2 + \|r_{\text{dual}}\|_2^2} \le \epsilon\) hold.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To define the Primal-Dual algorithm, let’s first define three types of residuals and the surrogate duality gap. Residuals and surrogate duality gap are the objectives to be minimized in the Primal-Dual algorithm.&lt;/p&gt;

&lt;h2 id=&quot;residuals&quot;&gt;Residuals&lt;/h2&gt;
&lt;p&gt;The dual, central, and primal residuals at \((x,u,v)\) are defined as follows.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(r_{dual} = \nabla f(x) +\nabla h(x)u + A^Tv\\\)
\(r_{cent} =  Uh(x) + τ\mathbb{1} \\\) 
\(r_{prim} = Ax−b\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These correspond to each row of the function \(r(x,u,v)\). The &lt;strong&gt;Primal-dual interior point method&lt;/strong&gt; executes in the direction of satisfying 0 rather than continuously making these three residuals equal to 0. This means that it is not necessary to be feasible during the execution process.&lt;/p&gt;

&lt;p&gt;The reason \(r_{dual}\) is called the dual residual is that, as shown in the equation below, if \(r_{dual} = 0\), it guarantees that \(u, v\) are in the domain of \(g\), which means dual feasible.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; r_{dual} = \nabla f(x) +\nabla h(x)u + A^Tv = 0 \\\\
&amp;amp; \iff \min_{x} L(x,u.v) = g(u,v) \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Similarly, satisfying \(r_{prim}=0\) means primal feasible, so \(r_{prim}\) is called the primal residual.&lt;/p&gt;

&lt;h2 id=&quot;surrogate-duality-gap&quot;&gt;Surrogate duality gap&lt;/h2&gt;
&lt;p&gt;While the barrier method has a duality gap because it is feasible, the primal-dual interior-point method uses &lt;strong&gt;surrogate duality gap&lt;/strong&gt; because it doesn’t necessarily need to be feasible. &lt;strong&gt;Surrogate duality gap&lt;/strong&gt; is defined by the following equation.&lt;/p&gt;

&lt;blockquote&gt;
\[−h(x)^Tu  \quad \text{for} \quad h(x) \le 0, u \ge 0\]
&lt;/blockquote&gt;

&lt;p&gt;If \(r_{dual} = 0\) and \(r_{prim} = 0\), then the surrogate duality gap becomes the true duality gap. In other words, if primal and dual feasible, the surrogate duality gap becomes equal to the actual duality gap \(\frac{m}{t}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[Reference] Perturbed KKT conditions and parameter t&lt;/strong&gt; &lt;br /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;In the perturbed KKT conditions, the parameter t is \(t = −\frac{m}{h(x)^Tu}\).&lt;/li&gt;
  &lt;li&gt;For detailed information, see &lt;a href=&quot;/contents/en/chapter15/chapter16/15_03_01_perturbed_kkt_conditions/&quot;&gt;15-03-01 Perturbed KKT conditions&lt;/a&gt; and &lt;a href=&quot;/contents/en/chapter15/15_03_02_suboptimality_gap/&quot;&gt;15-03-02 Suboptimality gap&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Furthermore, if \(u &amp;gt; 0,h(x) &amp;lt; 0\) and the following condition is satisfied, then \((x,u,v)\) exists on the central path.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(r(x,u,v) = 0\) for \(\tau = -\frac{h(x)^Tu}{m}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, the residual is 0 at points existing on the central path.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>17-02-01 Central path equations and Newton step</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_02_01_central_path_equations_and_newton_step/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_02_01_central_path_equations_and_newton_step</id>
   <content type="html">&lt;p&gt;If you tried to apply Newton’s method directly to the &lt;em&gt;unperturbed&lt;/em&gt; KKT conditions, the complementarity equations \(u_i h_i(x) = 0\) would form sharp L-shaped kinks at the boundary, trapping iterates on the wrong active face. By perturbing the right-hand side to \(u_i h_i(x) = -\tau\), those kinks melt into smooth hyperbolas whose Jacobian is nonsingular everywhere in the strict interior. This lesson builds that exact residual map \(r_\tau(x, u, v)\) and its block-structured Newton linear system.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-linearizing-the-perturbed-kkt-map&quot;&gt;Key ideas: Linearizing the Perturbed KKT Map&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Perturbed KKT Residual Map:&lt;/strong&gt; Stacking stationarity, perturbed complementarity, and equality feasibility into \(r_\tau(x, u, v) = [r_{\text{dual}}; r_{\text{cent}}; r_{\text{prim}}]\) converts a constrained optimization problem into a smooth square system of \(n + m + p\) nonlinear equations in \(n + m + p\) unknowns.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Root-Finding Newton Linearization:&lt;/strong&gt; Expanding \(r_\tau(z + \Delta z) \approx r_\tau(z) + Dr_\tau(z)\,\Delta z = 0\) yields the primal-dual search direction \((\Delta x, \Delta u, \Delta v)\) via a single linear solve \(Dr_\tau(z)\,\Delta z = -r_\tau(z)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Block Structure of the KKT Jacobian:&lt;/strong&gt; The derivative \(Dr_\tau\) combines the Lagrangian Hessian \(\nabla^2 f(x) + \sum_i u_i \nabla^2 h_i(x)\), the constraint Jacobians \(\nabla h(x)\) and \(A\), and the diagonal scaling matrices \(U = \operatorname{diag}(u)\) and \(H = \operatorname{diag}(h(x))\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Schur-Complement Reduction:&lt;/strong&gt; Because the complementarity block \(U \nabla h(x)\,\Delta x + H\,\Delta u = -r_{\text{cent}}\) is diagonal in \(\Delta u\), solvers eliminate \(\Delta u = -H^{-1}(r_{\text{cent}} + U \nabla h(x)\,\Delta x)\) analytically, reducing the KKT system to a smaller symmetric system in \((\Delta x, \Delta v)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-the-primal-dual-newton-system-by-hand&quot;&gt;Worked example: Solving the Primal-Dual Newton System by Hand&lt;/h3&gt;

&lt;p&gt;Consider the 1D quadratic problem \(\min_x \frac{1}{2} x^2 + x\) subject to \(h(x) = -x \le 0\) (exact optimum \(x^\star = 0, u^\star = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the residual map \(r_\tau(x, u)\):&lt;/strong&gt;
Here \(f&apos;(x) = x + 1\), \(f&apos;&apos;(x) = 1\), \(h(x) = -x\), \(h&apos;(x) = -1\), and there are no equality constraints. Thus:
\(r_\tau(x, u) = \begin{bmatrix} x + 1 - u \\ -u x + \tau \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Jacobian \(Dr_\tau(x, u)\):&lt;/strong&gt;
\(Dr_\tau(x, u) = \begin{bmatrix} f&apos;&apos;(x) &amp;amp; h&apos;(x) \\ u h&apos;(x) &amp;amp; h(x) \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; -1 \\ -u &amp;amp; -x \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate at \((x, u) = (1, 1)\) with target \(\tau = 0.2\):&lt;/strong&gt;
\(r_{0.2}(1, 1) = \begin{bmatrix} 1 + 1 - 1 \\ -(1)(1) + 0.2 \end{bmatrix} = \begin{bmatrix} 1 \\ -0.8 \end{bmatrix}, \qquad Dr_{0.2}(1, 1) = \begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; -1 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve \(Dr_{0.2}(1, 1) \begin{bmatrix}\Delta x \\ \Delta u\end{bmatrix} = -r_{0.2}(1, 1)\):&lt;/strong&gt;
\(\begin{cases} \Delta x - \Delta u = -1 \\ -\Delta x - \Delta u = 0.8 \end{cases}\)
Adding both equations gives \(-2\Delta u = -0.2 \implies \Delta u = 0.1\). Substituting back gives \(\Delta x = -1 + 0.1 = -0.9\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the updated point \((x^+, u^+) = (1 - 0.9, \; 1 + 0.1) = (0.1, \; 1.1)\):&lt;/strong&gt;
Both coordinates remain strictly positive (\(x^+ = 0.1 &amp;gt; 0, u^+ = 1.1 &amp;gt; 0\))! Moreover:
    &lt;ul&gt;
      &lt;li&gt;Dual residual: \(x^+ + 1 - u^+ = 0.1 + 1 - 1.1 = 0\) (exact stationarity achieved in one step!).&lt;/li&gt;
      &lt;li&gt;Complementarity product: \(u^+ x^+ = (1.1)(0.1) = 0.11\) (reduced from \(1.0\) down near \(\tau = 0.2\), with the discrepancy \(0.11 - 0.2 = -0.09 = \Delta x \Delta u\) coming purely from the second-order bilinear term!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;strong&gt;Primal-dual interior-point method&lt;/strong&gt; is a method that finds solutions by finding the central path, similar to the barrier method. To do this, it defines perturbed KKT conditions as residual functions and finds solutions that make them zero. This section aims to explain this approach.&lt;/p&gt;

&lt;h2 id=&quot;central-path-equations&quot;&gt;Central path equations&lt;/h2&gt;
&lt;p&gt;By moving the right-hand side to the left-hand side in the central path equations explained in the previous &lt;a href=&quot;/contents/en/chapter17/17_01_barrier_method_duality_optimality_revisited/&quot;&gt;17-01 Optimality conditions&lt;/a&gt;, we can organize them as follows. (The optimality conditions of central path equations are also called perturbed KKT conditions.)&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
∇f(x) +∇h(x)u + A^Tv &amp;amp; = &amp;amp; 0 \\\
 Uh(x) + \tau\mathbb{1}  &amp;amp; = &amp;amp; 0 \\\
Ax−b &amp;amp; = &amp;amp; 0 \\\
u,−h(x)  &amp;amp; &amp;gt; &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Note that the complementary slackness and inequality constraints in the KKT conditions for the original problem differ from those in the perturbed KKT conditions. For the original problem, \(Uh(x) = 0\) and \(u,−h(x)  \ge 0\), but in the perturbed KKT conditions, \(Uh(x) = - \tau\mathbb{1}\) and \(u,−h(x)  \gt 0\).&lt;/p&gt;

&lt;p&gt;These organized nonlinear equations, the perturbed KKT conditions, can be solved by approximating them as linear equations using the root finding version of Newton’s method.&lt;/p&gt;

&lt;h2 id=&quot;newton-step&quot;&gt;Newton step&lt;/h2&gt;
&lt;p&gt;Now let’s learn about the method of finding solutions by linearly approximating the perturbed KKT conditions. The perturbed KKT conditions equation can be defined as the following residual function \(r(x, u, v) = 0\). (The reason for naming it residual is that these values must be 0 to be optimal.)&lt;/p&gt;

&lt;blockquote&gt;
\[r(x,u,v) :=
\begin{bmatrix}
∇f(x) +∇h(x)u + A^Tv \\\
Uh(x) + τ\mathbb{1} \\\
Ax−b
\end{bmatrix}, H(x) = \text{Diag}(h(x))\]
&lt;/blockquote&gt;

&lt;p&gt;To find the roots of the function, approximating \(r(x, u, v)\) with a first-order Taylor expansion gives us the following. (This process approximates non-linear equations to linear equations. For detailed information, see &lt;a href=&quot;/contents/en/chapter14/14_01_newton_method/&quot;&gt;14-02-01 Root finding&lt;/a&gt;)&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
0 &amp;amp; = r(x + \Delta x, u + \Delta u, r + \Delta v)  \\\\
  &amp;amp; \approx r(x, u, v) + \nabla r(x, u, v) 
\begin{pmatrix}
\Delta x \\\\
\Delta u \\\\
\Delta v \\\\
\end{pmatrix} \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Accordingly, the function \(r(x, u, v)\) can be organized as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\nabla r(x, u, v) 
\begin{pmatrix}
\Delta x \\\\
\Delta u \\\\
\Delta v \\\\
\end{pmatrix} = -r(x, u, v) \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;By differentiating \(r(x, u, v)\) with respect to \(x, u, v\) to obtain the Jacobian matrix \(\nabla r(x, u, v)\) and substituting the above equation, we get the following.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{bmatrix}
\nabla^2f(x) + \sum_i u_i \nabla^2h_i(x) &amp;amp; \nabla h(x) &amp;amp; A^T \\\
 U \nabla  h(x)^T &amp;amp; H(x) &amp;amp; 0 \\\
A &amp;amp; 0 &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
\Delta x \\\
\Delta u \\\
\Delta v
\end{bmatrix} = −r(x,u,v)\)
where
\(r(x,u,v) :=
\begin{bmatrix}
\nabla f(x) +\nabla h(x)u + A^Tv \\\
Uh(x) + τ\mathbb{1} \\\
Ax−b
\end{bmatrix}, H(x) = \text{Diag}(h(x))\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The solution \((\Delta x, \Delta u, \Delta v)\) to this equation is the update direction for the primal and dual variables. The reason why the method introduced in this chapter is called the &lt;strong&gt;Primal-Dual&lt;/strong&gt; interior point method is that it simultaneously updates primal and dual variables using residual functions.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>17-01 Barrier method & duality & optimality revisited</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_01_barrier_method_duality_optimality_revisited/"/>
   <updated>2021-05-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter17/17_01_barrier_method_duality_optimality_revisited</id>
   <content type="html">&lt;p&gt;Before we replace the barrier method with its primal-dual successor, we need to see &lt;em&gt;why&lt;/em&gt; the barrier method works so cleanly under the hood—and where it leaves performance on the table. Every point on the barrier method’s central path \(x^\star(t)\) secretly defines a valid dual feasible certificate \((u^\star(t), v^\star(t))\) whose duality gap is not merely bounded, but &lt;em&gt;identically&lt;/em&gt; equal to \(m/t\). Seeing that exact duality identity is the bridge that turns a heuristic penalty into a primal-dual Newton method.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-barrier-geometry-and-exact-duality-certificates&quot;&gt;Key ideas: Barrier Geometry and Exact Duality Certificates&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Logarithmic Barrier Smoothness:&lt;/strong&gt; Replacing hard inequalities \(h_i(x) \le 0\) with \(-\frac{1}{t}\sum_{i=1}^m \log(-h_i(x))\) creates an infinite wall along the boundary of the feasible set, turning a constrained problem into a sequence of smooth equality-constrained problems solvable by Newton’s method.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Central Path Optimality Equations:&lt;/strong&gt; At the barrier minimizer \(x^\star(t)\), stationarity of \(t f(x) + \phi(x)\) produces \(\nabla f(x^\star) + \sum_{i=1}^m \frac{1}{-t h_i(x^\star)} \nabla h_i(x^\star) + A^T v^\star = 0\). Defining \(u_i^\star(t) = \frac{-1}{t h_i(x^\star(t))} &amp;gt; 0\) immediately casts \(x^\star(t)\) as a minimizer of the original Lagrangian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact \(m/t\) Duality Gap Identity:&lt;/strong&gt; Evaluating the Lagrange dual function \(g(u^\star(t), v^\star(t))\) at this induced dual pair gives \(f(x^\star(t)) - g(u^\star(t), v^\star(t)) = -\sum_{i=1}^m u_i^\star(t) h_i(x^\star(t)) = \frac{m}{t}\). Thus \(t\) directly controls the suboptimality certificate.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Barrier Centering Bottlenecks:&lt;/strong&gt; Increasing \(t \leftarrow \mu t\) forces an inner loop of multiple Newton steps to re-center \(x^\star(t)\) accurately before the next update, motivating the primal-dual reformulation that relaxes exact centering.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-the-exact-mt-duality-gap&quot;&gt;Worked example: Verifying the Exact \(m/t\) Duality Gap&lt;/h3&gt;

&lt;p&gt;Consider the 1D convex problem \(\min_x f(x) = x^2\) subject to \(h_1(x) = 1 - x \le 0\) (so \(m = 1\), optimal value \(f^\star = 1\) at \(x^\star = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the barrier subproblem:&lt;/strong&gt;
\(\min_{x &amp;gt; 1} \; t x^2 - \log(x - 1).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the central path stationarity equation:&lt;/strong&gt;
Setting the derivative to zero gives \(2tx - \frac{1}{x - 1} = 0 \iff 2tx^2 - 2tx - 1 = 0\). Taking the root with \(x &amp;gt; 1\):
\(x^\star(t) = \frac{2t + \sqrt{4t^2 + 8t}}{4t} = \frac{1 + \sqrt{1 + 2/t}}{2}.\)
At \(t = 4\): \(x^\star(4) = \frac{1 + \sqrt{1.5}}{2} \approx 1.112372\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Extract the induced dual variable \(u^\star(t)\):&lt;/strong&gt;
Using \(u^\star(t) = \frac{-1}{t h_1(x^\star(t))} = \frac{1}{t(x^\star(t) - 1)}\) and noting from step 2 that \(\frac{1}{x^\star(t) - 1} = 2t x^\star(t)\):
\(u^\star(t) = 2x^\star(t) \implies u^\star(4) = 1 + \sqrt{1.5} \approx 2.224745 &amp;gt; 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Lagrange dual function \(g(u)\) explicitly:&lt;/strong&gt;
\(g(u) = \inf_x \big(x^2 + u(1 - x)\big) = u - \frac{u^2}{4}\) (attained at \(x = u/2\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the exact duality gap \(f(x^\star(t)) - g(u^\star(t)) = m/t\):&lt;/strong&gt;
Substituting \(u^\star = 2x^\star\):
\(f(x^\star) - g(u^\star) = (x^\star)^2 - \left(2x^\star - (x^\star)^2\right) = 2(x^\star)^2 - 2x^\star.\)
From the stationarity quadratic \(2t(x^\star)^2 - 2tx^\star = 1\), dividing by \(t\) yields:
\(f(x^\star(t)) - g(u^\star(t)) = \frac{1}{t}.\)
At \(t = 4\), \(f(x^\star(4)) \approx 1.237372\) and \(g(u^\star(4)) \approx 0.987372\), whose difference is &lt;em&gt;identically&lt;/em&gt; \(0.25 = 1/4 = m/t\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Chapter 15, we examined the barrier method, and in Chapters 13 and 16, we looked at duality.
Before covering the content of this chapter, we want to briefly review the barrier method and duality.&lt;/p&gt;

&lt;h2 id=&quot;barrier-method&quot;&gt;Barrier method&lt;/h2&gt;
&lt;p&gt;When the following primal problem is convex and \(f, h_i , i = 1, . . . m\) are differentiable,&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp; f(x) \\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;h_{i}(x) \leq 0, i = 1, \dotsc, m \\
&amp;amp;&amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Using the log barrier function, the primal problem can be transformed into a barrier problem as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \min_{x} &amp;amp;&amp;amp; f(x) + \frac{1}{t} \phi(x) &amp;amp; \qquad &amp;amp; \min_{x} &amp;amp;&amp;amp; tf(x) + \phi(x) \\
&amp;amp; \text{subject to } &amp;amp;&amp;amp; Ax = b &amp;amp; \iff \qquad &amp;amp; \text{subject to } &amp;amp;&amp;amp; Ax = b \\
&amp;amp; \text{where } &amp;amp;&amp;amp; \phi(x) = - \sum_{i=1}^{m} \log(-h_i(x))
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The algorithm starts with \(t = t^{(0)}\) satisfying \(t &amp;gt; 0\) and increases until \(\frac{m}{t}\) becomes less than or equal to \(\epsilon\). At this time, Newton’s method is used to find \(x^{\star}(t)\) for the initial value \(x^{(0)}\), and the process of finding \(x^{(k+1)} = x^{\star}(t)\) at each step for \(k = 1, 2, 3, . . .\) is repeated.&lt;/p&gt;

&lt;p&gt;The algorithm can be briefly summarized as follows:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Choose \(t^{(0)} \gt 0\) and \(k := 0\).&lt;/li&gt;
  &lt;li&gt;Solve the barrier problem at \(t = t^{(0)}\) to find \(x^{(0)} = x^{\star}(t)\).&lt;/li&gt;
  &lt;li&gt;While \(m/t \gt \epsilon\) &lt;br /&gt;
  3-1. Update \(t^{(k+1)} = µt\) where \((µ &amp;gt; 1)\) &lt;br /&gt;
  3-2. Initialize Newton’s method with \(x^{(k)}\) (warm start)&lt;br /&gt;
     Solve the barrier problem at \(t = t^{(k+1)}\) to find \(x^{(k+1)} = x^{\star}(t)\).&lt;br /&gt;
  end while&lt;br /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;For detailed information, see &lt;a href=&quot;/contents/en/chapter15/15_01_02_log_barrier_function_and_barrier_method/&quot;&gt;15-01-02 Log barrier function &amp;amp; barrier method&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;duality&quot;&gt;Duality&lt;/h2&gt;
&lt;p&gt;When the following primal problem is given:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad f(x) \\\\
   \text{subject to} &amp;amp;\quad f Ax = b \\\\
   &amp;amp;\quad h(x) \le 0
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This can be transformed into Lagrangian form as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[L(x,u,v) = f(x) + u^Th(x) + v^T(Ax - b)\]
&lt;/blockquote&gt;

&lt;p&gt;Using the Lagrangian defined in this way, primal and dual problems can be redefined in the following form. Please refer to Chapter 16 for detailed information.&lt;br /&gt;&lt;/p&gt;
&lt;h3 id=&quot;primal-problem&quot;&gt;Primal Problem&lt;/h3&gt;
&lt;blockquote&gt;
\[\min_x \mathop{\max_{u,v}}_{u \geq 0} L(x,u,v)\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;dual-problem&quot;&gt;Dual problem&lt;/h3&gt;
&lt;blockquote&gt;
\[\mathop{\max_{u,v}}_{u \geq 0} \min_x L(x,u,v)\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;optimality-conditions&quot;&gt;Optimality conditions&lt;/h2&gt;

&lt;p&gt;When \(f,h_1,...h_m\) are convex and differentiable, and the given problem satisfies strong duality, the KKT optimality conditions for this problem are as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{array}{rcl}
∇f(x) +∇h(x)u + A^Tv &amp;amp; = &amp;amp; 0 &amp;amp; \text{(Stationarity)}\\\
 Uh(x) &amp;amp; = &amp;amp; 0 &amp;amp; \text{(Complementary Slackness)} \\\
Ax &amp;amp; = &amp;amp; b &amp;amp; \text{(Primal Feasibility)}\\\
u,−h(x)  &amp;amp; ≥ &amp;amp; 0 &amp;amp; \text{(Dual Feasibility)}
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(U\) means \(\text{diag}(u)\), and \(∇h(x)\) means \([ ∇h_1(x) ··· ∇h_m(x) ]\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For detailed information, see &lt;a href=&quot;/contents/en/chapter12/12_00_KKT_conditions/&quot;&gt;Chapter 12 KKT conditions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;central-path-equations&quot;&gt;Central path equations&lt;/h2&gt;
&lt;p&gt;The function \(f(x)\) can be redefined as a barrier problem as follows.&lt;br /&gt;
In the equation below, \(τ\) is \(\frac{1}{t}\), and by making \(τ\) gradually approach 0 and iteratively finding solutions, we ultimately obtain the solution to the original problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp; {f(x) + τ\phi(x)} \\\\
&amp;amp; &amp;amp;&amp;amp;{Ax = b} \\\
&amp;amp; \text{where } &amp;amp;&amp;amp; \phi(x) = −\sum_{i=1}^m \log(−h_i(x)).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;That is, in the above equation, differences from the primal problem occur depending on \(τ\), and the trajectory generated according to \(τ\), i.e., the set of solutions to the barrier problem, is called the central path.&lt;/p&gt;

&lt;p&gt;And the optimality conditions for this barrier problem are as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{array}{rcl}
∇f(x) +∇h(x)u + A^Tv  &amp;amp; = &amp;amp; 0 \\\
Uh(x) &amp;amp; = &amp;amp; −τ\mathbb{1} \\\
Ax &amp;amp; = &amp;amp; b \\\
u,−h(x)  &amp;amp; &amp;gt; &amp;amp; 0
\end{array}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;For detailed information, see &lt;a href=&quot;/contents/en/chapter16/16_02_optimality_conditions/&quot;&gt;16-02 Optimality conditions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;Primal-Dual interior point method&lt;/strong&gt; introduced in this chapter is a method that defines the first three equations above as residuals and finds solutions by reducing them to \(0\).&lt;/p&gt;

&lt;h4 id=&quot;useful-fact&quot;&gt;Useful fact&lt;/h4&gt;
&lt;p&gt;The solution \((x(τ),u(τ),v(τ))\) has a duality gap of size \(mτ\), i.e., \(\frac{m}{t}\), as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[f(x(τ))−\min_x L(x,u(τ),v(τ)) = mτ= \frac{m}{t}\]
&lt;/blockquote&gt;

</content>
 </entry>
 
 <entry>
   <title>13 Ứng dụng của đối ngẫu và các tương ứng</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_Duality_uses_and_correspondences/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_Duality_uses_and_correspondences</id>
   <content type="html">&lt;p&gt;Nếu ở các chương trước, lý thuyết đối ngẫu có thể tạo cảm giác như một cấu trúc đại số thuần túy — nơi ta lập hàm Lagrange rồi lấy cực tiểu và cực đại — thì Chương 13 chính là lúc chiếc chìa khóa ấy mở ra hàng loạt cánh cửa thực chiến. Khi đứng trước một bài toán tối ưu hàng triệu biến với ràng buộc phức tạp, các nhà toán học hiếm khi đâm đầu giải trực tiếp; họ xoay bài toán sang “mặt gương đối ngẫu”, nơi ràng buộc lồng ghép trở thành phép chiếu đơn giản và chuẩn không khả vi hóa thành hình hộp gọn gàng.&lt;/p&gt;

&lt;p&gt;Chương này kết nối năm công cụ sắc bén nhất của phân tích lồi hiện đại: &lt;strong&gt;tiêu chí dừng qua khoảng cách đối ngẫu&lt;/strong&gt;, &lt;strong&gt;khôi phục nghiệm nguyên thủy từ đối ngẫu&lt;/strong&gt;, &lt;strong&gt;chuẩn đối ngẫu&lt;/strong&gt;, &lt;strong&gt;hàm liên hợp Fenchel&lt;/strong&gt; và &lt;strong&gt;nón đối ngẫu&lt;/strong&gt;. Nắm vững các tương ứng này giống như có một cuốn từ điển hai chiều cho phép bạn dịch bài toán khó thành bài toán dễ chỉ trong vài dòng biến đổi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bức-tranh-tổng-thể-của-các-tương-ứng-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Bức tranh tổng thể của các tương ứng đối ngẫu&lt;/h2&gt;

&lt;p&gt;Để đọc thông suốt toàn bộ Chương 13, hãy hình dung bốn trụ cột sau như bốn bánh răng ăn khớp nhau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu Lagrange và chứng chỉ tối ưu:&lt;/strong&gt; Mọi điểm khả thi đối ngẫu đều sinh ra một chặn dưới chắc chắn cho giá trị tối ưu nguyên thủy \(f^\star\). Khoảng cách đối ngẫu \(f(x) - g(u, v)\) biến lý thuyết thành thước đo sai số thực tế mà không cần biết trước \(x^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình học chuẩn và chuẩn đối ngẫu:&lt;/strong&gt; Chuẩn đo “độ dài” của vectơ trong không gian nguyên thủy, còn chuẩn đối ngẫu đo “độ lớn cực đại” của một hàm tuyến tính tác động lên quả cầu đơn vị. Cặp \((\ell_1, \ell_\infty)\) hay \((\ell_2, \ell_2)\) là cầu nối trực tiếp giữa phạt thưa và ràng buộc hộp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến đổi Legendre–Fenchel (hàm liên hợp):&lt;/strong&gt; Thay vì mô tả một hàm lồi bằng đồ thị các điểm \((x, f(x))\), hàm liên hợp \(f^*(y)\) mô tả nó bằng họ các siêu phẳng tiếp xúc có độ dốc \(y\). Mọi phép cực tiểu hóa hàm Lagrange của hàm tách biến đều tự động gọi tên \(f^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình học nón và quy hoạch nón:&lt;/strong&gt; Khi ràng buộc không còn là số thực không âm mà là vectơ thuộc nón bậc hai hay ma trận nửa xác định dương, nón đối ngẫu \(K^*\) giữ vai trò tổng quát hóa khái niệm “nhân tử không âm” sang không gian nhiều chiều.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-một-bài-toán-nhỏ-nhìn-bằng-cả-hai-mặt-gương&quot;&gt;Giải thích: Một bài toán nhỏ, nhìn bằng cả hai mặt gương&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa 1 biến có ràng buộc:&lt;/p&gt;

\[\min_{x \in \mathbb{R}} \frac{1}{2}x^2 - 4x \qquad \text{với điều kiện } x \le 2.\]

&lt;p&gt;Ta thử giải nhanh bằng trực giác trước: parabol \(\frac{1}{2}x^2 - 4x\) có đỉnh tự do tại \(x = 4\), nhưng bị chặn bởi tường \(x \le 2\) nên nghiệm tối ưu là \(x^\star = 2\) với \(f^\star = \frac{1}{2}(4) - 8 = -6\). Giờ hãy xem bốn bánh răng của Chương 13 vận hành trên đúng bài toán này:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập hàm Lagrange và đối ngẫu:&lt;/strong&gt; Với nhân tử \(u \ge 0\) cho ràng buộc \(x - 2 \le 0\), ta có \(L(x, u) = \frac{1}{2}x^2 - 4x + u(x - 2) = \frac{1}{2}x^2 - (4 - u)x - 2u\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng hàm liên hợp để lấy cực tiểu theo \(x\):&lt;/strong&gt; Nhớ rằng \(\min_x \{\frac{1}{2}x^2 - yx\} = -\frac{1}{2}y^2\) (vì liên hợp của \(\frac{1}{2}x^2\) là \(\frac{1}{2}y^2\)). Thay \(y = 4 - u\), ta nhận ngay hàm đối ngẫu \(g(u) = -\frac{1}{2}(4 - u)^2 - 2u = -\frac{1}{2}u^2 + 2u - 8\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử khoảng cách đối ngẫu tại một cặp điểm chưa tối ưu:&lt;/strong&gt; Chọn \(x = 1\) (khả thi vì \(1 \le 2\)) và \(u = 1\) (khả thi vì \(1 \ge 0\)). Khi đó \(f(1) = -3.5\) và \(g(1) = -6.5\). Dù chưa giải xong, ta lập tức có chứng chỉ: \(-6.5 \le f^\star \le -3.5\), khoảng cách đối ngẫu là \(3.0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực đại hóa \(g(u)\) và khôi phục \(x^\star\):&lt;/strong&gt; Đạo hàm \(g&apos;(u) = -u + 2 = 0 \implies u^\star = 2 \ge 0\), cho \(g(2) = -6\). Thay \(u^\star = 2\) vào điều kiện dừng của \(L(x, u^\star)\): \(x^\star - (4 - 2) = 0 \implies x^\star = 2\), khoảng cách đối ngẫu bằng \(-6 - (-6) = 0\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong chương này, chúng ta sẽ tìm hiểu các ứng dụng của tính đối ngẫu (duality) và những khái niệm tương ứng liên quan thông qua các ví dụ cụ thể.&lt;/p&gt;

&lt;h3 id=&quot;lưu-ý-về-ký-hiệu&quot;&gt;Lưu ý về ký hiệu&lt;/h3&gt;

&lt;p&gt;Trong chương này, nghiệm tối ưu được ký hiệu là \(x^{\star}\), còn phép liên hợp (conjugate) được ký hiệu bằng dấu sao \(f^{*}\) để phân biệt rõ ràng.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-hiện-đại-20222026&quot;&gt;Ứng dụng hiện đại (2022–2026)&lt;/h2&gt;

&lt;p&gt;Bài đọc tùy chọn đi kèm gắn các khái niệm của chương với các ứng dụng giai đoạn 2022–2026: chuẩn đối ngẫu trong RobustBench, đối ngẫu Lasso trong kỹ thuật sàng lọc (screening) của skglm, hàm liên hợp trong Clarabel và CVXPY, cùng nón đối ngẫu trong \(\alpha,\beta\)-CROWN. Xem &lt;a href=&quot;/contents/vi/chapter13/13_07_modern_applications/&quot;&gt;13-07 Cách dùng hiện đại của liên hợp, chuẩn đối ngẫu và nón đối ngẫu&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-09 Bài Tập Thực Hành - Ứng Dụng Tính Đối Ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_09_Practical_Exercises_Duality_Applications/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_09_Practical_Exercises_Duality_Applications</id>
   <content type="html">&lt;p&gt;Lý thuyết đối ngẫu chỉ thực sự thấm vào tư duy khi bạn tự tay đặt bút tính một hàm liên hợp, chứng minh một chuẩn đối ngẫu bằng bất đẳng thức Hölder, hay tự tay lập bài toán đối ngẫu cho Lasso và quy hoạch nón. Nhiều khái niệm tưởng chừng trừu tượng trên slide — như vì sao liên hợp của tổng hai hàm lại liên quan đến phép chập infimal, hay vì sao chuẩn đối ngẫu của chuẩn \(\ell_1\) lại là \(\ell_\infty\) — sẽ trở nên trong suốt ngay khi bạn hoàn thành vài bài tập tự luận cốt lõi.&lt;/p&gt;

&lt;p&gt;Tuyển tập bài tập thực hành này chắt lọc những bài toán kinh điển từ Boyd &amp;amp; Vandenberghe, Rockafellar và Ben-Tal &amp;amp; Nemirovski. Trước khi bắt tay giải từng phần, hãy xem qua bản đồ chiến lược và một bài mẫu trình bày chuẩn để quen nhịp chứng minh.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-kỹ-năng-chứng-minh-trọng-tâm-trong-bài-tập-chương-13&quot;&gt;Kiến thức cần nhớ: Bốn kỹ năng chứng minh trọng tâm trong bài tập Chương 13&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh chuẩn đối ngẫu bằng hai chiều bất đẳng thức:&lt;/strong&gt; Để chứng minh \(\|y\|_* = M(y)\), luôn đi theo hai bước chuẩn: (1) dùng bất đẳng thức (Hölder, Cauchy–Schwarz, hoặc bất đẳng thức tam giác) để chỉ ra \(y^T x \le M(y)\) với mọi \(\|x\| \le 1\); (2) chỉ ra một vectơ cụ thể \(x_0\) có \(\|x_0\| \le 1\) đạt đúng dấu bằng \(y^T x_0 = M(y)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hàm liên hợp theo từng miền giá trị của \(y\):&lt;/strong&gt; Khi tính \(f^*(y) = \sup_x (y^T x - f(x))\), luôn kiểm tra trước xem biểu thức có bị không bị chặn trên (\(+\infty\)) ở vùng \(y\) nào không, sau đó mới giải phương trình đạo hàm \(\nabla f(x) = y\) trên miền hữu hạn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lập đối ngẫu có hệ thống qua tách biến:&lt;/strong&gt; Với bài toán dạng \(\min_x f(x) + g(Ax)\), đặt \(z = Ax\) giúp chuẩn hóa quy trình lập đối ngẫu thành 3 dòng đại số không bao giờ nhầm dấu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra chéo bằng ví dụ số nhỏ:&lt;/strong&gt; Sau khi tìm xong công thức tổng quát (cho chuẩn đối ngẫu, hàm liên hợp hay đối ngẫu Lasso), luôn thử thay một bộ số nguyên đơn giản vào cả hai vế để phát hiện tức thì lỗi sai dấu hay thiếu hệ số \(1/2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bài-mẫu-chứng-minh-hàm-liên-hợp-của-hàm-mũ-âm-logarit&quot;&gt;Giải thích: Bài mẫu chứng minh hàm liên hợp của hàm mũ âm logarit&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán mẫu:&lt;/strong&gt; Tính hàm liên hợp \(f^*(y)\) của hàm \(f(x) = -\log x\) với miền xác định \(\operatorname{dom} f = \{x \in \mathbb{R} : x &amp;gt; 0\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập bài toán cực đại hóa:&lt;/strong&gt;
\(f^*(y) = \sup_{x &amp;gt; 0} \bigl(yx + \log x\bigr).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xét trường hợp \(y \ge 0\):&lt;/strong&gt;
Khi \(y \ge 0\) và \(x \to +\infty\), cả \(yx \ge 0\) lẫn \(\log x \to +\infty\) nên \(yx + \log x \to +\infty\). Do đó \(f^*(y) = +\infty\) với mọi \(y \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xét trường hợp \(y &amp;lt; 0\):&lt;/strong&gt;
Đặt \(h(x) = yx + \log x\) trên \((0, +\infty)\). Đạo hàm bậc nhất và bậc hai:
\(h&apos;(x) = y + \frac{1}{x} = 0 \iff x^\star = -\frac{1}{y} &amp;gt; 0, \qquad h&apos;&apos;(x) = -\frac{1}{x^2} &amp;lt; 0.\)
Vì \(h\) lõm chặt trên \((0, +\infty)\), điểm \(x^\star = -1/y\) là cực đại toàn cục duy nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thay \(x^\star = -1/y\) để thu công thức đóng và kiểm tra số:&lt;/strong&gt;
\(f^*(y) = y\left(-\frac{1}{y}\right) + \log\left(-\frac{1}{y}\right) = -1 - \log(-y), \qquad \text{với } y &amp;lt; 0.\)
&lt;em&gt;Kiểm tra nhanh tại \(x = 2, y = -0.5\) (đúng tại \(y = f&apos;(x) = -1/x\)):&lt;/em&gt; \(f(2) = -\log 2\), \(f^*(-0.5) = -1 - \log(0.5) = -1 + \log 2\). Tổng \(f(2) + f^*(-0.5) = -1 = (-0.5) \cdot 2 = yx\) — khớp hoàn hảo dấu bằng Fenchel–Young!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---ứng-dụng-tính-đối-ngẫu&quot;&gt;Bài tập thực hành - Ứng dụng tính đối ngẫu&lt;/h1&gt;

&lt;p&gt;Các bài tập dưới đây được tham khảo từ Boyd &amp;amp; Vandenberghe (2004), Rockafellar (1970) và Ben-Tal &amp;amp; Nemirovski (2001).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-i-chuẩn-đối-ngẫu-dual-norms&quot;&gt;📝 &lt;strong&gt;Phần I: Chuẩn đối ngẫu (Dual Norms)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-tính-toán-chuẩn-đối-ngẫu-boyd--vandenberghe-ex-37&quot;&gt;&lt;strong&gt;Bài tập 1: Tính toán chuẩn đối ngẫu (Boyd &amp;amp; Vandenberghe, Ex. 3.7)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho chuẩn \(\|x\|\), chuẩn đối ngẫu được định nghĩa bởi:&lt;/p&gt;

\[\|y\|_* = \max_{\|x\| \leq 1} y^T x\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Tìm chuẩn đối ngẫu cho các chuẩn sau:&lt;/p&gt;

&lt;p&gt;a) \(\|x\|_1 = \sum_{i=1}^n |x_i|\)&lt;br /&gt;
b) \(\|x\|_2 = \sqrt{\sum_{i=1}^n x_i^2}\)&lt;br /&gt;
c) \(\|x\|_\infty = \max_i |x_i|\)&lt;br /&gt;
d) \(\|x\|_p = (\sum_{i=1}^n |x_i|^p)^{1/p}\) với \(p \geq 1\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**Công thức tổng quát:** Chuẩn đối ngẫu của $$\|\cdot\|_p$$ là $$\|\cdot\|_q$$ với $$\frac{1}{p} + \frac{1}{q} = 1$$.

---

**a) Chuẩn $$\ell_1$$:**

Cần tính:

$$
\|y\|_* = \max_{\|x\|_1 \leq 1} y^T x = \max_{\sum_i |x_i| \leq 1} \sum_i y_i x_i
$$

**Phân tích:**  
- Để cực đại hóa $$\sum_i y_i x_i$$, ta chọn các thành phần $$x_i$$ cùng dấu với $$y_i$$.
- Với ràng buộc $$\sum_i |x_i| \leq 1$$, ta dồn toàn bộ trọng số vào tọa độ có $$|y_i|$$ lớn nhất.

Đặt $$x_j = \text{sign}(y_j)$$ với $$j = \arg\max_i |y_i|$$ và các $$x_i = 0$$ với $$i \neq j$$. Khi đó:

$$
\|y\|_* = \max_i |y_i| = \|y\|_\infty
$$

**Kết luận:** $$(\|\cdot\|_1)_* = \|\cdot\|_\infty$$.

---

**b) Chuẩn $$\ell_2$$:**

$$
\|y\|_* = \max_{\|x\|_2 \leq 1} y^T x
$$

Theo bất đẳng thức Cauchy–Schwarz:

$$
y^T x \leq \|y\|_2 \|x\|_2 \leq \|y\|_2
$$

Dấu bằng đạt được khi $$x = \frac{y}{\|y\|_2}$$ (với $$y \neq 0$$).

**Kết luận:** $$(\|\cdot\|_2)_* = \|\cdot\|_2$$ (tự đối ngẫu).

---

**c) Chuẩn $$\ell_\infty$$:**

$$
\|y\|_* = \max_{\max_i |x_i| \leq 1} \sum_i y_i x_i
$$

Chọn $$x_i = \text{sign}(y_i)$$ cho mọi $$i$$ (thỏa mãn $$|x_i| \leq 1$$):

$$
\|y\|_* = \sum_i |y_i| = \|y\|_1
$$

**Kết luận:** $$(\|\cdot\|_\infty)_* = \|\cdot\|_1$$.

---

**d) Chuẩn $$\ell_p$$ tổng quát:**

Theo bất đẳng thức Hölder:

$$
y^T x \leq \|y\|_q \|x\|_p
$$

với $$\frac{1}{p} + \frac{1}{q} = 1$$.

Dấu bằng đạt được khi chọn $$x_i = c \cdot \text{sign}(y_i) |y_i|^{q-1}$$ (với hằng số chuẩn hóa $$c &amp;gt; 0$$ sao cho $$\|x\|_p = 1$$).

**Kết luận:** $$(\|\cdot\|_p)_* = \|\cdot\|_q$$ với $$\frac{1}{p} + \frac{1}{q} = 1$$.

---

**Bảng tóm tắt:**

| Chuẩn gốc | Chuẩn đối ngẫu | Quan hệ |
|-----------|----------------|---------|
| $$\|\cdot\|_1$$ | $$\|\cdot\|_\infty$$ | $$p=1, q=\infty$$ |
| $$\|\cdot\|_2$$ | $$\|\cdot\|_2$$ | Tự đối ngẫu |
| $$\|\cdot\|_\infty$$ | $$\|\cdot\|_1$$ | $$p=\infty, q=1$$ |
| $$\|\cdot\|_p$$ | $$\|\cdot\|_q$$ | $$1/p + 1/q = 1$$ |

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-2-kiểm-chứng-tính-chất-chuẩn-đối-ngẫu&quot;&gt;&lt;strong&gt;Bài tập 2: Kiểm chứng tính chất chuẩn đối ngẫu&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho \(x = (3, 4)^T\) và \(y = (0.6, 0.8)^T\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tính \(\|x\|_1\), \(\|x\|_2\), \(\|x\|_\infty\)&lt;br /&gt;
b) Tính \(\|y\|_1\), \(\|y\|_2\), \(\|y\|_\infty\)&lt;br /&gt;
c) Kiểm chứng bất đẳng thức \(y^T x \leq \|y\|_* \|x\|\) cho từng cặp chuẩn đối ngẫu&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Các chuẩn của $$x = (3,4)^T$$:**

$$
\begin{align}
\|x\|_1 &amp;amp;= |3| + |4| = 7 \\
\|x\|_2 &amp;amp;= \sqrt{3^2 + 4^2} = \sqrt{25} = 5 \\
\|x\|_\infty &amp;amp;= \max(|3|, |4|) = 4
\end{align}
$$

---

**b) Các chuẩn của $$y = (0.6, 0.8)^T$$:**

$$
\begin{align}
\|y\|_1 &amp;amp;= 0.6 + 0.8 = 1.4 \\
\|y\|_2 &amp;amp;= \sqrt{0.6^2 + 0.8^2} = \sqrt{0.36 + 0.64} = 1 \\
\|y\|_\infty &amp;amp;= \max(0.6, 0.8) = 0.8
\end{align}
$$

---

**c) Kiểm chứng bất đẳng thức:**

Trước hết tính tích vô hướng:

$$
y^T x = 0.6 \times 3 + 0.8 \times 4 = 1.8 + 3.2 = 5
$$

**Trường hợp 1:** Cặp $$\|x\|_1$$ và $$\|y\|_\infty$$ (vì $$(\|\cdot\|_1)_* = \|\cdot\|_\infty$$):

$$
y^T x = 5 \leq \|y\|_\infty \|x\|_1 = 0.8 \times 7 = 5.6
$$

✓ Thỏa mãn.

---

**Trường hợp 2:** Cặp $$\|x\|_2$$ và $$\|y\|_2$$ (tự đối ngẫu):

$$
y^T x = 5 \leq \|y\|_2 \|x\|_2 = 1 \times 5 = 5
$$

✓ Đạt dấu bằng (vì $$y = \frac{x}{\|x\|_2}$$).

---

**Trường hợp 3:** Cặp $$\|x\|_\infty$$ và $$\|y\|_1$$ (vì $$(\|\cdot\|_\infty)_* = \|\cdot\|_1$$):

$$
y^T x = 5 \leq \|y\|_1 \|x\|_\infty = 1.4 \times 4 = 5.6
$$

✓ Thỏa mãn.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-ii-hàm-liên-hợp-conjugate-functions&quot;&gt;📝 &lt;strong&gt;Phần II: Hàm liên hợp (Conjugate Functions)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-3-tính-hàm-liên-hợp-rockafellar-ex-12b&quot;&gt;&lt;strong&gt;Bài tập 3: Tính hàm liên hợp (Rockafellar, Ex. 12.B)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Hàm liên hợp của \(f(x)\) được định nghĩa là:&lt;/p&gt;

\[f^*(y) = \sup_x (y^T x - f(x))\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Tính hàm liên hợp cho các hàm sau:&lt;/p&gt;

&lt;p&gt;a) \(f(x) = \frac{1}{2}x^T Q x\) với \(Q \succ 0\)&lt;br /&gt;
b) \(f(x) = \|x\|_2\)&lt;br /&gt;
c) \(f(x) = e^x\) (với \(x \in \mathbb{R}\))&lt;br /&gt;
d) \(f(x) = I_C(x)\) (hàm chỉ thị của tập \(C\))&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Hàm bậc hai $$f(x) = \frac{1}{2}x^T Q x$$:**

$$
f^*(y) = \sup_x \left( y^T x - \frac{1}{2} x^T Q x \right)
$$

Điều kiện bậc nhất theo $$x$$: $$\nabla_x (y^T x - \frac{1}{2}x^T Q x) = y - Qx = 0 \Rightarrow x^* = Q^{-1} y$$.

Thế lại vào biểu thức:

$$
f^*(y) = y^T Q^{-1} y - \frac{1}{2} (Q^{-1}y)^T Q (Q^{-1}y)
$$

$$
= y^T Q^{-1} y - \frac{1}{2} y^T Q^{-1} y = \frac{1}{2} y^T Q^{-1} y
$$

**Kết quả:** $$\boxed{f^*(y) = \frac{1}{2} y^T Q^{-1} y}$$

**Bất đẳng thức Fenchel tương ứng:**

$$
\frac{1}{2}x^T Q x + \frac{1}{2}y^T Q^{-1} y \geq x^T y
$$

---

**b) Chuẩn Euclidean $$f(x) = \|x\|_2$$:**

$$
f^*(y) = \sup_x (y^T x - \|x\|_2)
$$

**Phân tích:**
- Nếu $$\|y\|_2 \leq 1$$: theo bất đẳng thức Cauchy–Schwarz, $$y^Tx - \|x\|_2 \leq (\|y\|_2 - 1)\|x\|_2 \leq 0$$ với mọi $$x$$, và dấu bằng đạt tại $$x = 0$$.
- Nếu $$\|y\|_2 &amp;gt; 1$$: chọn $$x = ty$$ với $$t \to +\infty$$ thì $$y^T x - \|x\|_2 = t\|y\|_2(\|y\|_2 - 1) \to +\infty$$.

**Kết quả:**

$$
\boxed{f^*(y) = \begin{cases}
0 &amp;amp; \text{if } \|y\|_2 \leq 1 \\
\infty &amp;amp; \text{if } \|y\|_2 &amp;gt; 1
\end{cases}} = I_{\|y\|_2 \leq 1}(y)
$$

---

**c) Hàm mũ $$f(x) = e^x$$:**

$$
f^*(y) = \sup_x (yx - e^x)
$$

Điều kiện bậc nhất: $$y - e^x = 0 \Rightarrow x^* = \ln y$$ (chỉ tồn tại khi $$y &amp;gt; 0$$).

Thế vào biểu thức cho trường hợp $$y &amp;gt; 0$$:

$$
f^*(y) = y \ln y - e^{\ln y} = y \ln y - y
$$

Khi $$y = 0$$, $$\sup_x (-e^x) = 0$$ (khi $$x \to -\infty$$). Khi $$y &amp;lt; 0$$, cho $$x \to -\infty$$ thì $$yx - e^x \to +\infty$$.

**Kết quả:**

$$
\boxed{f^*(y) = \begin{cases}
y \ln y - y &amp;amp; \text{if } y &amp;gt; 0 \\
0 &amp;amp; \text{if } y = 0 \\
\infty &amp;amp; \text{if } y &amp;lt; 0
\end{cases}}
$$

---

**d) Hàm chỉ thị $$f(x) = I_C(x)$$:**

$$
f^*(y) = \sup_x (y^T x - I_C(x)) = \sup_{x \in C} y^T x
$$

**Kết quả:** $$\boxed{f^*(y) = \sup_{x \in C} y^T x}$$ (hàm hỗ trợ của tập $$C$$).

**Ví dụ minh họa:**
- $$C = \{x : \|x\|_2 \leq 1\}$$: $$f^*(y) = \|y\|_2$$
- $$C = \mathbb{R}^n_+$$: $$f^*(y) = I_{\{y \leq 0\}}(y)$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-4-bất-đẳng-thức-fenchel-boyd--vandenberghe-ex-333&quot;&gt;&lt;strong&gt;Bài tập 4: Bất đẳng thức Fenchel (Boyd &amp;amp; Vandenberghe, Ex. 3.33)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho \(f(x) = \frac{1}{2}\|x\|^2\) và các vector \(x = (1, 2)^T\), \(y = (3, 1)^T\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tính \(f(x)\) và \(f^*(y)\)&lt;br /&gt;
b) Tính \(x^T y\)&lt;br /&gt;
c) Kiểm chứng bất đẳng thức Fenchel: \(f(x) + f^*(y) \geq x^T y\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Tính $$f(x)$$ và $$f^*(y)$$:**

$$
f(x) = \frac{1}{2}(1^2 + 2^2) = \frac{1}{2}(1 + 4) = 2.5
$$

Với $$f(x) = \frac{1}{2}\|x\|^2$$ (tức $$Q = I$$), ta có $$f^*(y) = \frac{1}{2}\|y\|^2$$:

$$
f^*(y) = \frac{1}{2}\|y\|^2 = \frac{1}{2}(3^2 + 1^2) = \frac{1}{2}(9 + 1) = 5
$$

---

**b) Tính $$x^T y$$:**

$$
x^T y = 1 \times 3 + 2 \times 1 = 5
$$

---

**c) Kiểm chứng bất đẳng thức Fenchel:**

$$
f(x) + f^*(y) = 2.5 + 5 = 7.5 \geq 5 = x^T y
$$

✓ Thỏa mãn (chênh lệch: $$7.5 - 5 = 2.5$$).

**Điều kiện xảy ra dấu bằng:** Khi $$y \in \partial f(x)$$, tức $$y = \nabla f(x) = x$$. Ở đây $$\nabla f(x) = (1,2)^T \neq (3,1)^T = y$$, nên dấu bằng không xảy ra.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iii-đối-ngẫu-của-bài-toán-lasso&quot;&gt;📝 &lt;strong&gt;Phần III: Đối ngẫu của bài toán LASSO&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-5-xây-dựng-lasso-đối-ngẫu-boyd--vandenberghe-ex-615&quot;&gt;&lt;strong&gt;Bài tập 5: Xây dựng LASSO đối ngẫu (Boyd &amp;amp; Vandenberghe, Ex. 6.15)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét bài toán LASSO nguyên thủy:&lt;/p&gt;

\[\min_x \frac{1}{2}\|Ax - b\|^2 + \lambda \|x\|_1\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Thiết lập bài toán đối ngẫu&lt;br /&gt;
b) Giải thích mối liên hệ giữa nghiệm nguyên thủy và nghiệm đối ngẫu&lt;br /&gt;
c) Với \(A = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}\), \(b = \begin{bmatrix} 1 \\ 1 \\ 3 \end{bmatrix}\), \(\lambda = 0.5\), hãy tìm nghiệm đối ngẫu&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Thiết lập bài toán đối ngẫu:**

Đặt biến phụ $$r = Ax - b$$, bài toán nguyên thủy trở thành:

$$
\begin{align}
\min_{x,r} \quad &amp;amp; \frac{1}{2}\|r\|^2 + \lambda \|x\|_1 \\
\text{s.t.} \quad &amp;amp; Ax - r = b
\end{align}
$$

Hàm Lagrangian tương ứng:

$$
L(x, r, \nu) = \frac{1}{2}\|r\|^2 + \lambda \|x\|_1 + \nu^T(Ax - r - b)
$$

Cực tiểu hóa theo $$x$$:

$$
\min_x \left( \lambda \|x\|_1 + \nu^T A x \right) = \begin{cases}
0 &amp;amp; \text{if } \|A^T \nu\|_\infty \leq \lambda \\
-\infty &amp;amp; \text{otherwise}
\end{cases}
$$

Cực tiểu hóa theo $$r$$ (đạt tại $$r = \nu$$):

$$
\min_r \left( \frac{1}{2}\|r\|^2 - \nu^T r \right) = -\frac{1}{2}\|\nu\|^2
$$

**Hàm đối ngẫu:**

$$
g(\nu) = -\frac{1}{2}\|\nu\|^2 - \nu^T b
$$

với ràng buộc $$\|A^T \nu\|_\infty \leq \lambda$$.

**Bài toán đối ngẫu (đổi dấu để viết dưới dạng cực tiểu hóa):**

$$
\boxed{
\begin{align}
\min_{\nu} \quad &amp;amp; \frac{1}{2}\|\nu\|^2 + \nu^T b \\
\text{s.t.} \quad &amp;amp; \|A^T \nu\|_\infty \leq \lambda
\end{align}
}
$$

---

**b) Quan hệ giữa nghiệm nguyên thủy và đối ngẫu:**

Từ các điều kiện KKT:
- $$r^* = \nu^*$$ (biến đối ngẫu chính là phần dư $$Ax^* - b$$).
- Nếu $$|(A^T \nu^*)_i| &amp;lt; \lambda$$ thì $$x_i^* = 0$$.
- Các chỉ số có $$|(A^T \nu^*)_i| = \lambda$$ tạo thành tập chỉ số tích cực (active set) chứa các thành phần có thể khác $$0$$ của $$x^*$$.

**Khôi phục nghiệm nguyên thủy từ nghiệm đối ngẫu:**

$$
x^* = \text{(nghiệm của bài toán rút gọn trên tập chỉ số tích cực)}
$$

---

**c) Tính nghiệm số:**

Với dữ liệu:

$$
A = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}, \quad
b = \begin{bmatrix} 1 \\ 1 \\ 3 \end{bmatrix}, \quad
\lambda = 0.5
$$

**Bài toán đối ngẫu cụ thể:**

$$
\begin{align}
\min_{\nu} \quad &amp;amp; \frac{1}{2}(\nu_1^2 + \nu_2^2 + \nu_3^2) + \nu_1 + \nu_2 + 3\nu_3 \\
\text{s.t.} \quad &amp;amp; \max(|\nu_1 + \nu_3|, |\nu_2 + \nu_3|) \leq 0.5
\end{align}
$$

**Giải bài toán:**

Nếu xét nghiệm không ràng buộc (điều kiện bậc nhất):

$$
\nu_1 + 1 = 0 \Rightarrow \nu_1 = -1 \\
\nu_2 + 1 = 0 \Rightarrow \nu_2 = -1 \\
\nu_3 + 3 = 0 \Rightarrow \nu_3 = -3
$$

Kiểm tra ràng buộc:

$$
\max(|-1 - 3|, |-1 - 3|) = 4 &amp;gt; 0.5
$$

Điểm này không khả thi, nên ràng buộc phải tích cực.

**Giả sử** cả hai ràng buộc cùng chặt ở biên âm: $$\nu_1 + \nu_3 = \nu_2 + \nu_3 = -0.5$$. Do tính đối xứng, đặt $$\nu_1 = \nu_2 = a$$ và $$\nu_3 = -0.5 - a$$.

Sử dụng đồng nhất thức $$\frac{1}{2}\|\nu\|^2 + \nu^Tb = \frac{1}{2}\|\nu + b\|^2 - \frac{1}{2}\|b\|^2$$, ta cực tiểu hóa:

$$\min_a \; \frac{1}{2}\left[2(a+1)^2 + (2.5 - a)^2\right]$$

Lấy đạo hàm theo $$a$$ bằng $$0$$: $$2(a+1) - (2.5 - a) = 0 \Rightarrow a = \frac{1}{6}$$.

**Nghiệm đối ngẫu:**

$$
\nu^* = \left(\tfrac{1}{6}, \tfrac{1}{6}, -\tfrac{2}{3}\right)^T, \qquad \tfrac{1}{2}\|\nu^*\|^2 + \nu^{*T}b = \tfrac{1}{4} - \tfrac{5}{3} = -\tfrac{17}{12}
$$

Tức giá trị tối ưu của bài toán đối ngẫu (dạng cực đại hóa) là $$\frac{17}{12} \approx 1.4167$$.

**Kiểm chứng với bài toán nguyên thủy:** Nghiệm nguyên thủy $$x^* = \left(\tfrac{7}{6}, \tfrac{7}{6}\right)^T$$ cho phần dư $$Ax^* - b = \left(\tfrac{1}{6}, \tfrac{1}{6}, -\tfrac{2}{3}\right)^T = \nu^*$$ ✓ (đúng hệ thức $$r^* = \nu^*$$) và giá trị mục tiêu nguyên thủy $$\frac{1}{2}\|r^*\|^2 + \lambda\|x^*\|_1 = \frac{1}{4} + 0.5 \cdot \frac{7}{3} = \frac{17}{12}$$ ✓, khoảng cách đối ngẫu bằng $$0$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iv-nón-đối-ngẫu-dual-cones&quot;&gt;📝 &lt;strong&gt;Phần IV: Nón đối ngẫu (Dual Cones)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-6-tính-nón-đối-ngẫu-boyd--vandenberghe-ex-236&quot;&gt;&lt;strong&gt;Bài tập 6: Tính nón đối ngẫu (Boyd &amp;amp; Vandenberghe, Ex. 2.36)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Nón đối ngẫu của nón \(K\) được định nghĩa là:&lt;/p&gt;

\[K^* = \{ y : y^T x \geq 0, \forall x \in K \}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Tìm nón đối ngẫu cho các nón sau:&lt;/p&gt;

&lt;p&gt;a) \(K = \mathbb{R}^n_+ = \{x : x \geq 0\}\)&lt;br /&gt;
b) \(K = \{(t, x) : \|x\|_2 \leq t\}\) (nón bậc hai — second-order cone)&lt;br /&gt;
c) \(K = \mathbb{S}^n_+\) (nón ma trận nửa xác định dương)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Nón không âm $$K = \mathbb{R}^n_+$$:**

Cần tìm các vector $$y$$ sao cho $$y^T x \geq 0$$ với mọi $$x \geq 0$$.

Chọn $$x = e_i$$ (vector cơ sở chuẩn thứ $$i$$):

$$
y^T e_i = y_i \geq 0
$$

Điều kiện này đúng với mọi $$i$$ khi và chỉ khi $$y \geq 0$$.

**Kết luận:** $$\boxed{K^* = \mathbb{R}^n_+}$$ (tự đối ngẫu).

---

**b) Nón bậc hai (Second-order cone):**

$$
K = \{(t, x) : t \in \mathbb{R}, x \in \mathbb{R}^{n-1}, \|x\|_2 \leq t\}
$$

Cần tìm $$(s, y)$$ sao cho:

$$
st + y^T x \geq 0, \quad \forall \|x\|_2 \leq t
$$

Xét trường hợp bất lợi nhất theo $$x$$ (với $$y \neq 0$$): chọn $$x = -\frac{t}{\|y\|_2} y$$ (thỏa $$\|x\|_2 = t$$), ta được:

$$
st - t\|y\|_2 = t(s - \|y\|_2) \geq 0
$$

Để bất đẳng thức đúng với mọi $$t &amp;gt; 0$$, điều kiện cần và đủ là $$s \geq \|y\|_2$$ (khi $$y = 0$$, điều kiện là $$s \geq 0$$, vẫn khớp).

**Kết luận:** $$\boxed{K^* = K}$$ (tự đối ngẫu).

---

**c) Nón ma trận nửa xác định dương $$K = \mathbb{S}^n_+$$:**

Cần tìm các ma trận đối xứng $$Y$$ sao cho:

$$
\text{tr}(Y X) \geq 0, \quad \forall X \succeq 0
$$

Sử dụng phân tích trị riêng $$X = \sum_i \lambda_i v_i v_i^T$$ với $$\lambda_i \geq 0$$:

$$
\text{tr}(Y X) = \sum_i \lambda_i v_i^T Y v_i \geq 0
$$

Điều này đúng với mọi $$\lambda_i \geq 0$$ và mọi vector $$v_i$$ khi và chỉ khi $$v^T Y v \geq 0$$ với mọi $$v$$, tức $$Y \succeq 0$$.

**Kết luận:** $$\boxed{K^* = \mathbb{S}^n_+}$$ (tự đối ngẫu).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-7-kiểm-chứng-tính-chất-nón-bậc-hai&quot;&gt;&lt;strong&gt;Bài tập 7: Kiểm chứng tính chất nón bậc hai&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho \(x = (2, 1, 1)^T\) và \(y = (1.5, 0.5, 0.5)^T\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Kiểm tra \(x\) có thuộc nón bậc hai (SOC) hay không&lt;br /&gt;
b) Kiểm tra \(y\) có thuộc SOC hay không&lt;br /&gt;
c) Tính \(y^T x\) và kiểm chứng tính chất nón đối ngẫu&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

Xét nón bậc hai $$K = \{(t, u) \in \mathbb{R} \times \mathbb{R}^2 : \|u\|_2 \leq t\}$$.

---

**a) Kiểm tra $$x = (2, 1, 1)^T$$** (với $$t = 2$$, $$u = (1, 1)^T$$):

$$
\|(1, 1)\|_2 = \sqrt{2} \approx 1.414 \leq 2
$$

✓ Suy ra $$x \in K$$.

---

**b) Kiểm tra $$y = (1.5, 0.5, 0.5)^T$$:**

$$
\|(0.5, 0.5)\|_2 = \frac{\sqrt{2}}{2} \approx 0.707 \leq 1.5
$$

✓ Suy ra $$y \in K$$.

---

**c) Kiểm chứng tính chất nón đối ngẫu:**

Vì nón bậc hai tự đối ngẫu nên $$y \in K = K^*$$, do đó phải có $$y^T x \geq 0$$ với mọi $$x \in K$$. Tính trực tiếp:

$$
y^T x = 1.5 \times 2 + 0.5 \times 1 + 0.5 \times 1 = 3 + 0.5 + 0.5 = 4 \geq 0
$$

✓ Thỏa mãn.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-v-đối-ngẫu-trong-quy-hoạch-nửa-xác-định-sdp-duality&quot;&gt;📝 &lt;strong&gt;Phần V: Đối ngẫu trong quy hoạch nửa xác định (SDP Duality)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-8-cặp-bài-toán-nguyên-thủyđối-ngẫu-sdp-ben-tal--nemirovski-ex-43&quot;&gt;&lt;strong&gt;Bài tập 8: Cặp bài toán nguyên thủy–đối ngẫu SDP (Ben-Tal &amp;amp; Nemirovski, Ex. 4.3)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét bài toán SDP nguyên thủy:&lt;/p&gt;

\[\begin{align}
\min_{X} \quad &amp;amp; \text{tr}(C X) \\
\text{s.t.} \quad &amp;amp; \text{tr}(A_i X) = b_i, \quad i = 1, \ldots, m \\
&amp;amp; X \succeq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán đối ngẫu&lt;br /&gt;
b) Trình bày điều kiện đối ngẫu mạnh và hệ KKT&lt;br /&gt;
c) Với \(C = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\), \(A_1 = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}\), \(b_1 = 1\), tìm nghiệm nguyên thủy và đối ngẫu&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Bài toán đối ngẫu:**

Hàm Lagrangian:

$$
L(X, y) = \text{tr}(CX) - \sum_i y_i (\text{tr}(A_i X) - b_i)
$$

$$
= \text{tr}\left( \left(C - \sum_i y_i A_i\right) X \right) + \sum_i y_i b_i
$$

Cực tiểu hóa theo $$X \succeq 0$$ (với $$M = C - \sum_i y_i A_i$$):

$$
\min_{X \succeq 0} \text{tr}(MX) = \begin{cases}
0 &amp;amp; \text{if } M \succeq 0 \\
-\infty &amp;amp; \text{otherwise}
\end{cases}
$$

**Bài toán đối ngẫu:**

$$
\boxed{
\begin{align}
\max_{y} \quad &amp;amp; \sum_i y_i b_i \\
\text{s.t.} \quad &amp;amp; C - \sum_i y_i A_i \succeq 0
\end{align}
}
$$

---

**b) Đối ngẫu mạnh và điều kiện KKT:**

Điều kiện Slater: tồn tại ma trận xác định dương $$\tilde{X} \succ 0$$ thỏa $$\text{tr}(A_i \tilde{X}) = b_i$$ với mọi $$i$$. Khi đó tính **đối ngẫu mạnh** được thỏa mãn ($$p^* = d^*$$) và tồn tại nghiệm tối ưu đối ngẫu.

**Các điều kiện KKT:**
1. Khả thi nguyên thủy: $$\text{tr}(A_i X^*) = b_i$$ và $$X^* \succeq 0$$.
2. Khả thi đối ngẫu: $$C - \sum_i y_i^* A_i \succeq 0$$.
3. Điều kiện bù yếu: $$\text{tr}((C - \sum_i y_i^* A_i) X^*) = 0$$.

---

**c) Giải với dữ liệu cụ thể:**

Cho:

$$
C = I_2, \quad A_1 = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}, \quad b_1 = 1
$$

**Bài toán nguyên thủy:**

$$
\begin{align}
\min_{X} \quad &amp;amp; x_{11} + x_{22} \\
\text{s.t.} \quad &amp;amp; x_{11} = 1 \\
&amp;amp; X \succeq 0
\end{align}
$$

Từ $$x_{11} = 1$$ và $$X \succeq 0$$:

$$
X = \begin{bmatrix} 1 &amp;amp; x_{12} \\ x_{12} &amp;amp; x_{22} \end{bmatrix} \succeq 0
$$

Điều kiện nửa xác định dương cho $$\det(X) = x_{22} - x_{12}^2 \geq 0 \Rightarrow x_{22} \geq x_{12}^2 \geq 0$$.

Cực tiểu hóa $$1 + x_{22}$$ đạt được tại $$x_{22}^* = 0$$ và $$x_{12}^* = 0$$.

**Nghiệm nguyên thủy:**

$$
X^* = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}, \quad p^* = 1
$$

---

**Bài toán đối ngẫu:**

$$
\begin{align}
\max_{y_1} \quad &amp;amp; y_1 \\
\text{s.t.} \quad &amp;amp; I - y_1 \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} \succeq 0
\end{align}
$$

$$
\begin{bmatrix} 1-y_1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} \succeq 0 \Rightarrow 1-y_1 \geq 0 \Rightarrow y_1 \leq 1
$$

Cực đại hóa $$y_1$$ cho $$y_1^* = 1$$ và $$d^* = 1$$.

**Kết luận:** $$p^* = d^* = 1$$, tính đối ngẫu mạnh được thỏa mãn ✓.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết-và-chiến-lược&quot;&gt;💡 &lt;strong&gt;Tổng kết và chiến lược&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;chuẩn-đối-ngẫu&quot;&gt;&lt;strong&gt;Chuẩn đối ngẫu&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Ghi nhớ: \((\|\cdot\|_p)_* = \|\cdot\|_q\) với \(1/p + 1/q = 1\).&lt;/li&gt;
  &lt;li&gt;Cặp \(\ell_1 \leftrightarrow \ell_\infty\); chuẩn \(\ell_2\) tự đối ngẫu.&lt;/li&gt;
  &lt;li&gt;Bất đẳng thức tổng quát: \(y^T x \leq \|y\|_* \|x\|\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;hàm-liên-hợp&quot;&gt;&lt;strong&gt;Hàm liên hợp&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Định nghĩa: \(f^*(y) = \sup_x (y^Tx - f(x))\).&lt;/li&gt;
  &lt;li&gt;Bất đẳng thức Fenchel: \(f(x) + f^*(y) \geq x^Ty\) (dấu bằng khi \(y \in \partial f(x)\)).&lt;/li&gt;
  &lt;li&gt;Tính đối hợp: \(f^{**} = f\) nếu \(f\) đóng và lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;đối-ngẫu-của-lasso&quot;&gt;&lt;strong&gt;Đối ngẫu của LASSO&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Bài toán nguyên thủy: \(\min \frac{1}{2}\|Ax-b\|^2 + \lambda\|x\|_1\).&lt;/li&gt;
  &lt;li&gt;Bài toán đối ngẫu: \(\min \frac{1}{2}\|\nu\|^2 + \nu^Tb\) với điều kiện \(\|A^T\nu\|_\infty \leq \lambda\).&lt;/li&gt;
  &lt;li&gt;Bài toán đối ngẫu có số chiều nhỏ hơn (\(m\) biến so với \(n\) biến) khi \(m &amp;lt; n\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;nón-đối-ngẫu&quot;&gt;&lt;strong&gt;Nón đối ngẫu&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Định nghĩa: \(K^* = \{y : y^Tx \geq 0, \forall x \in K\}\).&lt;/li&gt;
  &lt;li&gt;Các nón tự đối ngẫu quan trọng: \(\mathbb{R}^n_+\), nón bậc hai (SOC) và \(\mathbb{S}^n_+\).&lt;/li&gt;
  &lt;li&gt;Tính đối hợp: \(K^{**} = K\) nếu \(K\) là nón đóng và lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;đối-ngẫu-trong-sdp&quot;&gt;&lt;strong&gt;Đối ngẫu trong SDP&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Tính đối ngẫu mạnh được đảm bảo khi điều kiện Slater thỏa mãn.&lt;/li&gt;
  &lt;li&gt;Điều kiện bù yếu có dạng: \(\text{tr}(MX) = 0\) với \(M \succeq 0\) và \(X \succeq 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 3, 5, 6.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Rockafellar, R. T.&lt;/strong&gt; (1970). &lt;em&gt;Convex Analysis&lt;/em&gt;. Princeton University Press.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ben-Tal, A., &amp;amp; Nemirovski, A.&lt;/strong&gt; (2001). &lt;em&gt;Lectures on Modern Convex Optimization&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Borwein, J. M., &amp;amp; Lewis, A. S.&lt;/strong&gt; (2006). &lt;em&gt;Convex Analysis and Nonlinear Optimization&lt;/em&gt; (2nd ed.). Springer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hiriart-Urruty, J.-B., &amp;amp; Lemaréchal, C.&lt;/strong&gt; (2001). &lt;em&gt;Fundamentals of Convex Analysis&lt;/em&gt;. Springer.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>13-08 Bài tập trắc nghiệm - Ứng Dụng và Tương Ứng của Tính Đối Ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_08_Quiz_Duality_Uses/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_08_Quiz_Duality_Uses</id>
   <content type="html">&lt;p&gt;Đọc hiểu công thức đối ngẫu là một chuyện, nhưng phản xạ nhanh trước những tình huống “bẫy” mới thực sự cho thấy bạn đã làm chủ Chương 13. Chẳng hạn: khi bài toán gốc không lồi chặt, việc cực tiểu hóa hàm Lagrange tại \((u^\star, v^\star)\) có chắc chắn trả về \(x^\star\) không? Hay nếu biến đổi tương đương hàm đối ngẫu bằng cách lấy logarit, khoảng cách đối ngẫu tính từ hàm mới còn đáng tin nữa không?&lt;/p&gt;

&lt;p&gt;Bộ câu hỏi trắc nghiệm này được thiết kế như một bài kiểm tra phản xạ toán học toàn diện cho toàn bộ Chương 13 — từ tiêu chí dừng, chuẩn đối ngẫu, hàm liên hợp, đối ngẫu Lasso đến nón đối ngẫu và đối ngẫu kép. Trước khi bước vào phần câu hỏi, hãy dành vài phút rà lại bản đồ bốn nhóm bẫy thường gặp nhất.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhóm-phản-xạ-cốt-lõi-cần-kiểm-tra-ở-chương-13&quot;&gt;Kiến thức cần nhớ: Bốn nhóm phản xạ cốt lõi cần kiểm tra ở Chương 13&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Duality gap và điều kiện khôi phục nghiệm:&lt;/strong&gt; Nhớ rõ khoảng cách đối ngẫu \(f(x) - g(u, v)\) chỉ là chặn trên hợp lệ khi \(x\) khả thi nguyên thủy và \((u, v)\) khả thi đối ngẫu; còn để khôi phục duy nhất \(x^\star\) từ \(L(x, u^\star, v^\star)\) ta cần thêm điều kiện lồi chặt (hoặc kiểm tra lại tính khả thi).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cặp chuẩn đối ngẫu và liên hợp của chuẩn:&lt;/strong&gt; Thuộc lòng bảng tra cứu nhanh: \(\ell_p \leftrightarrow \ell_q\) (\(1/p + 1/q = 1\)), chuẩn vết \(\leftrightarrow\) chuẩn phổ, và liên hợp của bất kỳ chuẩn nào \(\|x\|\) luôn là hàm chỉ thị của quả cầu đơn vị chuẩn đối ngẫu \(\|y\|_* \le 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dịch chuyển toán tử tuyến tính và đối ngẫu Lasso:&lt;/strong&gt; Nhớ quy tắc tách biến \(z = Ax\) khiến ma trận chuyển vị \(A^T\) nhảy sang hàm liên hợp bên kia, còn Lasso có đối ngẫu là bài toán chiếu lên khối đa diện \(\|X^T u\|_\infty \le \lambda\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nón đối ngẫu và đối ngẫu kép:&lt;/strong&gt; Phân biệt rõ nón tự đối ngẫu (\(\mathbb{R}_+^n, \mathcal{Q}_n, \mathbb{S}_+^n\)) với nón nhọn/tù tổng quát, và nhớ định lý \((K^*)^* = K\) chỉ đúng khi \(K\) là nón lồi đóng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-mẫu-một-tình-huống-bẫy-trắc-nghiệm-về-tính-duy-nhất-khi-khôi-phục-xstar&quot;&gt;Giải thích: Giải mẫu một tình huống bẫy trắc nghiệm về tính duy nhất khi khôi phục \(x^\star\)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Tình huống:&lt;/strong&gt; Xét bài toán tuyến tính \(\min_{x \in \mathbb{R}} 0 \cdot x\) với ràng buộc \(0 \le x \le 2\) (hoặc \(\min_{x \in \mathbb{R}^2} x_1 + x_2\) với \(x_1 + x_2 = 1, x_1 \ge 0, x_2 \ge 0\)). Giả sử ta đã có nghiệm đối ngẫu tối ưu \(v^\star = 1\) cho bài toán thứ hai. Liệu mọi điểm cực tiểu của \(L(x, u^\star, v^\star)\) có phải là \(x^\star\) không?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập hàm Lagrange:&lt;/strong&gt; Với ràng buộc \(-x_1 \le 0, -x_2 \le 0\) (nhân tử \(u_1, u_2 \ge 0\)) và \(x_1 + x_2 - 1 = 0\) (nhân tử \(v\)):
\(L(x, u, v) = (1 - u_1 - v)x_1 + (1 - u_2 - v)x_2 + v.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm nghiệm đối ngẫu tối ưu:&lt;/strong&gt; Để \(\min_x L &amp;gt; -\infty\) ta cần \(1 - u_1 - v = 0\) và \(1 - u_2 - v = 0\), nên \(v = 1 - u_1 \le 1\). Cực đại \(g(u, v) = v\) đạt tại \(v^\star = 1, u_1^\star = 0, u_2^\star = 0\), cho \(g^\star = 1 = f^\star\) (đối ngẫu mạnh thỏa mãn!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử khôi phục \(x\) từ \(L(x, u^\star, v^\star)\):&lt;/strong&gt;
Thay \(u^\star = (0, 0), v^\star = 1\) vào \(L\), ta thu được \(L(x, u^\star, v^\star) \equiv 1\) — một hằng số với &lt;strong&gt;mọi&lt;/strong&gt; \(x \in \mathbb{R}^2\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài học rút ra:&lt;/strong&gt; Ngay cả điểm \(x = (-10, -10)\) (hoàn toàn bất khả thi!) cũng cực tiểu hóa \(L(x, u^\star, v^\star)\). Nguyên nhân: hàm mục tiêu tuyến tính &lt;strong&gt;không lồi chặt&lt;/strong&gt;, nên cực tiểu của Lagrangian không duy nhất và ta bắt buộc phải lọc thêm các điều kiện khả thi nguyên thủy + bù yếu để tìm \(x^\star\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập trắc nghiệm, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-hai-ứng-dụng-chính-của-tính-đối-ngẫu&quot;&gt;⚡ &lt;strong&gt;Hai ứng dụng chính của tính đối ngẫu&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Khoảng cách đối ngẫu làm tiêu chí dừng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu (duality gap):&lt;/strong&gt; \(f(x) - g(u,v)\) với \(x\) khả thi nguyên thủy và \((u,v)\) khả thi đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chặn trên sai số tối ưu:&lt;/strong&gt; \(f(x) - f^* \le f(x) - g(u,v)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra tính tối ưu:&lt;/strong&gt; Nếu khoảng cách đối ngẫu bằng \(0\) thì \(x\) là nghiệm tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chí dừng thực tế:&lt;/strong&gt; Dừng thuật toán khi khoảng cách đối ngẫu nhỏ hơn ngưỡng \(\epsilon\) cho trước.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Giải bài toán nguyên thủy thông qua bài toán đối ngẫu:&lt;/strong&gt;
Khi có nghiệm đối ngẫu tối ưu \((u^*, v^*)\) và tính đối ngẫu mạnh thỏa mãn:
\(x^* = \arg\min_x L(x, u^*, v^*) = \arg\min_x \left\{ f(x) + \sum u_i^* h_i(x) + \sum v_j^* l_j(x) \right\}\)&lt;/p&gt;

&lt;p&gt;Cách tiếp cận này đặc biệt hữu ích khi bài toán đối ngẫu dễ giải hơn bài toán nguyên thủy.&lt;/p&gt;

&lt;h3 id=&quot;-giải-bài-toán-tách-biến-thông-qua-đối-ngẫu&quot;&gt;🔄 &lt;strong&gt;Giải bài toán tách biến thông qua đối ngẫu&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán nguyên thủy:&lt;/strong&gt; \(\min_x \sum_{i=1}^n f_i(x_i) \quad \text{s.t.} \quad a^T x = b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm đối ngẫu:&lt;/strong&gt;
\(g(v) = bv - \sum_{i=1}^n f_i^*(a_i v)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt; \(\max_v bv - \sum_{i=1}^n f_i^*(a_i v)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Khôi phục nghiệm nguyên thủy:&lt;/strong&gt; Khi đã có \(v^*\) (và các \(f_i\) lồi chặt, khả vi), giải độc lập từng phương trình \(\nabla f_i(x_i^*) = a_i v^*\) theo từng tọa độ \(i\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Bài toán đối ngẫu chỉ còn một biến vô hướng \(v\); các hàm liên hợp \(f_i^*\) có thể tính song song và nhiều trường hợp có công thức dạng đóng.&lt;/p&gt;

&lt;h3 id=&quot;-chuẩn-đối-ngẫu-dual-norms&quot;&gt;📏 &lt;strong&gt;Chuẩn đối ngẫu (Dual Norms)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa&quot;&gt;&lt;strong&gt;Định nghĩa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Với chuẩn \(\lVert x \rVert\), &lt;strong&gt;chuẩn đối ngẫu&lt;/strong&gt; \(\lVert z \rVert_*\) được định nghĩa là:
\(\lVert z \rVert_* = \max_{\lVert x \rVert \le 1} z^T x\)&lt;/p&gt;

&lt;h4 id=&quot;tính-chất-cơ-bản&quot;&gt;&lt;strong&gt;Tính chất cơ bản&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Cauchy–Schwarz tổng quát:&lt;/strong&gt; \(\lvert z^T x \rvert \le \lVert z \rVert_* \lVert x \rVert\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu kép:&lt;/strong&gt; \(\lVert x \rVert_{**} = \lVert x \rVert\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Luôn là một chuẩn:&lt;/strong&gt; \(\lVert \cdot \rVert_*\) là supremum của họ hàm tuyến tính nên luôn lồi và thỏa các tiên đề chuẩn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;các-cặp-chuẩn-đối-ngẫu-quan-trọng&quot;&gt;&lt;strong&gt;Các cặp chuẩn đối ngẫu quan trọng&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn \(\ell_p\):&lt;/strong&gt; \((\lVert x \rVert_p)_* = \lVert x \rVert_q\) với \(\frac{1}{p} + \frac{1}{q} = 1\):
    &lt;ul&gt;
      &lt;li&gt;
\[(\lVert x \rVert_1)_* = \lVert x \rVert_\infty\]
      &lt;/li&gt;
      &lt;li&gt;
\[(\lVert x \rVert_2)_* = \lVert x \rVert_2\]
      &lt;/li&gt;
      &lt;li&gt;
\[(\lVert x \rVert_\infty)_* = \lVert x \rVert_1\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn ma trận:&lt;/strong&gt; \((\lVert X \rVert_{tr})_* = \lVert X \rVert_{op} = \sigma_1(X)\) (giá trị kỳ dị lớn nhất).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;biểu-diễn-chuẩn-qua-bài-toán-đối-ngẫu&quot;&gt;&lt;strong&gt;Biểu diễn chuẩn qua bài toán đối ngẫu&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Từ bài toán \(\min_y \lVert y \rVert \text{ s.t. } y = x\), ta thu được bài toán đối ngẫu \(\max_{\lVert u \rVert_* \le 1} u^T x\) và đẳng thức \(\lVert x \rVert = \max_{\lVert u \rVert_* \le 1} u^T x\).&lt;/p&gt;

&lt;h3 id=&quot;-ví-dụ-đối-ngẫu-của-bài-toán-lasso&quot;&gt;🎯 &lt;strong&gt;Ví dụ: Đối ngẫu của bài toán LASSO&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-lasso-nguyên-thủy&quot;&gt;&lt;strong&gt;Bài toán LASSO nguyên thủy&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_\beta \frac{1}{2}\lVert y - X\beta \rVert_2^2 + \lambda \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;h4 id=&quot;đưa-về-dạng-có-ràng-buộc&quot;&gt;&lt;strong&gt;Đưa về dạng có ràng buộc&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{\beta,z} \frac{1}{2}\lVert y - z \rVert_2^2 + \lambda \lVert \beta \rVert_1 \quad \text{s.t.} \quad z = X\beta\)&lt;/p&gt;

&lt;h4 id=&quot;hàm-lagrangian-và-hàm-đối-ngẫu&quot;&gt;&lt;strong&gt;Hàm Lagrangian và hàm đối ngẫu&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(L(\beta,z,u) = \frac{1}{2}\lVert y - z \rVert_2^2 + \lambda \lVert \beta \rVert_1 + u^T(z - X\beta)\)&lt;/p&gt;

\[g(u) = \frac{1}{2}\lVert y \rVert_2^2 - \frac{1}{2}\lVert y - u \rVert_2^2 - I_{\{\lVert X^T u \rVert_\infty \le \lambda\}}(u)\]

&lt;h4 id=&quot;bài-toán-lasso-đối-ngẫu-dạng-tương-đương&quot;&gt;&lt;strong&gt;Bài toán LASSO đối ngẫu (dạng tương đương)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_u \lVert y - u \rVert_2^2 \quad \text{s.t.} \quad \lVert X^T u \rVert_\infty \le \lambda\)&lt;/p&gt;

&lt;h4 id=&quot;quan-hệ-nguyên-thủyđối-ngẫu&quot;&gt;&lt;strong&gt;Quan hệ nguyên thủy–đối ngẫu&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Điều kiện Slater được thỏa mãn nên có tính đối ngẫu mạnh, và nghiệm liên hệ bởi \(X\beta^* = y - u^*\) (tức \(u^*\) chính là phần dư).&lt;/p&gt;

&lt;h3 id=&quot;-hàm-liên-hợp-và-bài-toán-đối-ngẫu&quot;&gt;🔗 &lt;strong&gt;Hàm liên hợp và bài toán đối ngẫu&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;hàm-liên-hợp&quot;&gt;&lt;strong&gt;Hàm liên hợp&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f^*(u) = \sup_x \{u^T x - f(x)\} \iff -f^*(u) = \min_x \{f(x) - u^T x\}\)&lt;/p&gt;

&lt;h4 id=&quot;bài-toán-tổng-hai-hàm&quot;&gt;&lt;strong&gt;Bài toán tổng hai hàm&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Với bài toán \(\min_x f(x) + g(x)\), viết lại thành \(\min_{x,z} f(x) + g(z) \text{ s.t. } x = z\), ta thu được hàm đối ngẫu:
\(g(u) = \min_{x,z} f(x) + g(z) + u^T(z - x) = -f^*(u) - g^*(-u)\)&lt;/p&gt;

&lt;p&gt;và bài toán đối ngẫu: \(\max_u -f^*(u) - g^*(-u)\).&lt;/p&gt;

&lt;h4 id=&quot;ví-dụ-áp-dụng&quot;&gt;&lt;strong&gt;Ví dụ áp dụng&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chỉ thị:&lt;/strong&gt; \(\min_x f(x) + I_C(x) \Rightarrow \max_u -f^*(u) - I_C^*(-u)\), với \(I_C^*\) là hàm hỗ trợ của tập \(C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thành phần chuẩn:&lt;/strong&gt; \(\min_x f(x) + \lVert x \rVert \Rightarrow \max_{\lVert u \rVert_* \le 1} -f^*(u)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-nón-đối-ngẫu-dual-cones&quot;&gt;🔺 &lt;strong&gt;Nón đối ngẫu (Dual Cones)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa-1&quot;&gt;&lt;strong&gt;Định nghĩa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Cho nón \(K \subseteq \mathbb{R}^n\), &lt;strong&gt;nón đối ngẫu&lt;/strong&gt; \(K^*\) là:
\(K^* = \{y : y^T x \ge 0 \quad \forall x \in K\}\)&lt;/p&gt;

&lt;h4 id=&quot;tính-chất&quot;&gt;&lt;strong&gt;Tính chất&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(K^*\) luôn là nón lồi ngay cả khi \(K\) không lồi.&lt;/li&gt;
  &lt;li&gt;Nếu \(K\) là nón lồi và đóng thì \(K^{**} = K\).&lt;/li&gt;
  &lt;li&gt;Về mặt hình học: \(y \in K^* \Leftrightarrow\) nửa không gian \(\{x : y^T x \ge 0\}\) chứa toàn bộ nón \(K\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;các-ví-dụ-quan-trọng&quot;&gt;&lt;strong&gt;Các ví dụ quan trọng&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Không gian con tuyến tính \(V\):&lt;/strong&gt; \(V^* = V^\perp\) (phần bù trực giao); ví dụ \((\text{row}(A))^* = \text{null}(A)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nón chuẩn:&lt;/strong&gt; Với \(K = \{(x,t) : \lVert x \rVert \le t\}\), nón đối ngẫu là \(K^* = \{(y,s) : \lVert y \rVert_* \le s\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nón ma trận nửa xác định dương:&lt;/strong&gt; Tự đối ngẫu \((\mathbb{S}_+^n)^* = \mathbb{S}_+^n\), vì \(Y \succeq 0 \Leftrightarrow \text{tr}(YX) \ge 0 \; \forall X \succeq 0\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-đối-ngẫu-trong-quy-hoạch-nón-conic-programming&quot;&gt;🎯 &lt;strong&gt;Đối ngẫu trong quy hoạch nón (Conic Programming)&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán nguyên thủy:&lt;/strong&gt; \(\min_x f(x) \quad \text{s.t.} \quad Ax \in K\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt; \(\max_u -f^*(A^T u) \quad \text{s.t.} \quad u \in K^*\) (suy ra từ hàm hỗ trợ \(I_K^*(-u) = I_{K^*}(u)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ SOCP:&lt;/strong&gt; Bài toán \(\min c^T x \text{ s.t. } \lVert A_i x + b_i \rVert_2 \le c_i^T x + d_i\) viết gọn thành \(Ax + b \in K\) (với \(K\) là tích các nón bậc hai) có đối ngẫu \(\max -b^T u \text{ s.t. } A^T u = c, u \in K^*\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ví-dụ-minh-họa&quot;&gt;💡 &lt;strong&gt;Ví dụ minh họa&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;cực-tiểu-hóa-chuẩn-ell_2-có-ràng-buộc-tuyến-tính&quot;&gt;&lt;strong&gt;Cực tiểu hóa chuẩn \(\ell_2\) có ràng buộc tuyến tính&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán nguyên thủy:&lt;/strong&gt; \(\min_x \lVert x \rVert_2 \quad \text{s.t.} \quad Ax = b\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt; \(\max_{\lVert A^T u \rVert_2 \le 1} b^T u\) (suy từ hàm Lagrangian \(L(x, u) = \lVert x \rVert_2 + u^T(b - Ax)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải:&lt;/strong&gt; Tìm \(u\) thỏa \(\lVert A^T u \rVert_2 \le 1\) để cực đại hóa \(b^T u\); khi hệ \(Ax = b\) khả thi, giá trị tối ưu bằng chuẩn nhỏ nhất \(\lVert x^* \rVert_2\) của nghiệm chuẩn cực tiểu \(x^* = A^+ b\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;cực-tiểu-hóa-chuẩn-ell_1-có-ràng-buộc-tuyến-tính&quot;&gt;&lt;strong&gt;Cực tiểu hóa chuẩn \(\ell_1\) có ràng buộc tuyến tính&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán nguyên thủy:&lt;/strong&gt; \(\min_x \lVert x \rVert_1 \quad \text{s.t.} \quad Ax = b\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt; \(\max_{\lVert A^T u \rVert_\infty \le 1} b^T u\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải hình học:&lt;/strong&gt; Tìm \(u\) thuộc đa diện khả thi đối ngẫu \(\{u : \lVert A^T u \rVert_\infty \le 1\}\) sao cho tích vô hướng \(b^T u\) đạt cực đại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-lưu-ý-thực-hành-và-ứng-dụng&quot;&gt;🛠️ &lt;strong&gt;Lưu ý thực hành và ứng dụng&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khi nào nên giải bài toán đối ngẫu:&lt;/strong&gt; Khi bài toán đối ngẫu có ít biến hơn, cấu trúc ràng buộc đơn giản hơn, tách biến tốt cho tính toán song song, hoặc khi cần theo dõi khoảng cách đối ngẫu làm tiêu chí dừng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các lỗi cần tránh:&lt;/strong&gt; Bỏ qua điều kiện chuẩn ràng buộc đảm bảo đối ngẫu mạnh, đánh giá sai sai số số học của khoảng cách đối ngẫu, hoặc chuẩn hóa tỷ lệ biến chưa phù hợp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng thực tế:&lt;/strong&gt; Học máy (SVM, LASSO, hoàn thiện ma trận với chuẩn hạt nhân), xử lý tín hiệu (cảm biến nén với chuẩn \(\ell_1\), khử nhiễu ảnh tổng biến phân), vận trù học (luồng cực đại–lát cắt cực tiểu, phân bổ tài nguyên) và tài chính (tối ưu danh mục đầu tư, quản trị rủi ro).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra kiến thức về các ứng dụng và tương ứng của tính đối ngẫu, gồm hàm liên hợp, chuẩn đối ngẫu, đối ngẫu LASSO, nón đối ngẫu và các tính chất đối ngẫu liên quan.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🔄 Quiz: Ứng Dụng và Tương Ứng của Tính Đối Ngẫu&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: Conjugate function definition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Conjugate function $$f^*(y)$$ được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) $$f^*(y) = \max_x (y^T x - f(x))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) $$f^*(y) = \min_x (y^T x - f(x))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) $$f^*(y) = \max_x (y^T x + f(x))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) $$f^*(y) = f(y)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f^*(y) = \max_x (y^T x - f(x))$$&lt;/strong&gt;&lt;br /&gt;
                Hàm liên hợp (biến đổi Legendre–Fenchel) là giá trị supremum của hiệu giữa hàm tuyến tính $$y^T x$$ và $$f(x)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Conjugate properties --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Conjugate function $$f^*$$ có tính chất:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) Luôn convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) Luôn concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Có cùng tính lồi với $$f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Không xác định được&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Luôn convex&lt;/strong&gt;&lt;br /&gt;
                Hàm liên hợp luôn lồi vì là supremum theo điểm của một họ các hàm affine, bất kể bản thân $$f$$ có lồi hay không.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Double conjugate --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Nếu $$f$$ là convex và lower semicontinuous, thì $$f^{**}$$ bằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) $$f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) $$-f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) $$f^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) $$0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f$$&lt;/strong&gt;&lt;br /&gt;
                Theo định lý Fenchel–Moreau, nếu $$f$$ là hàm lồi và nửa liên tục dưới (đóng) thì $$f^{**} = f$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Dual norm definition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Dual norm $$\lVert x \rVert_*$$ được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$\lVert x \rVert_* = \max_{\lVert z \rVert \leq 1} z^T x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) $$\lVert x \rVert_* = \min_{\lVert z \rVert \leq 1} z^T x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) $$\lVert x \rVert_* = \max_{\lVert z \rVert = 1} z^T x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) $$\lVert x \rVert_* = \lVert x \rVert$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\|x\|_* = \max_{\|z\| \leq 1} z^T x$$&lt;/strong&gt;&lt;br /&gt;
                Chuẩn đối ngẫu là giá trị lớn nhất của tích vô hướng với các vector nằm trong quả cầu đơn vị của chuẩn gốc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Lp dual norm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Dual norm của $$\ell_p$$ norm là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) $$\ell_p$$ norm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) $$\ell_q$$ norm với $$1/p + 1/q = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(\ell_\infty\) norm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \(\ell_1\) norm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\ell_q$$ norm với $$1/p + 1/q = 1$$&lt;/strong&gt;&lt;br /&gt;
                Theo cặp liên hợp Hölder, chuẩn đối ngẫu của $$\ell_p$$ là $$\ell_q$$ với $$1/p + 1/q = 1$$; đặc biệt chuẩn đối ngẫu của $$\ell_1$$ là $$\ell_\infty$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Holder inequality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Hölder inequality có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(|x^T y| \leq \|x\|_p \|y\|_q\) với \(1/p + 1/q = 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(|x^T y| \leq \|x\|_p \|y\|_p\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(|x^T y| \geq \|x\|_p \|y\|_q\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(\|x + y\|_p \leq \|x\|_p + \|y\|_p\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$|x^T y| \leq \|x\|_p \|y\|_q$$ với $$1/p + 1/q = 1$$&lt;/strong&gt;&lt;br /&gt;
                Bất đẳng thức Hölder là dạng tổng quát của bất đẳng thức Cauchy–Schwarz, liên hệ tích vô hướng với cặp chuẩn đối ngẫu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Nuclear norm dual --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Dual norm của nuclear norm (trace norm) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Frobenius norm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Operator norm (spectral norm)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Nuclear norm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(\ell_1\) norm của singular values&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Operator norm (spectral norm)&lt;/strong&gt;&lt;br /&gt;
                Chuẩn đối ngẫu của chuẩn hạt nhân (nuclear/trace norm) $$\|X\|_* = \sum \sigma_i$$ là chuẩn toán tử $$\|X\|_{op} = \sigma_1$$ (giá trị kỳ dị lớn nhất).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: LASSO dual problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: LASSO dual problem có constraint:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(\|A^T u\|_\infty \leq \lambda\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(\|A^T u\|_1 \leq \lambda\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(\|A^T u\|_2 \leq \lambda\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(\|u\|_2 \leq \lambda\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\|A^T u\|_\infty \leq \lambda$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán LASSO đối ngẫu có ràng buộc $$\|A^T u\|_\infty \leq \lambda$$ vì chuẩn đối ngẫu của chuẩn $$\ell_1$$ là chuẩn $$\ell_\infty$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Conjugate of quadratic --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Conjugate của \(f(x) = \frac{1}{2}x^T Q x\) với \(Q \succ 0\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(f^*(y) = \frac{1}{2}y^T Q^{-1} y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(f^*(y) = \frac{1}{2}y^T Q y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(f^*(y) = y^T Q^{-1} y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(f^*(y) = \frac{1}{2}y^T Q^{-2} y\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f^*(y) = \frac{1}{2}y^T Q^{-1} y$$&lt;/strong&gt;&lt;br /&gt;
                Hàm liên hợp của dạng toàn phương $$\frac{1}{2}x^T Q x$$ (với $$Q \succ 0$$) là dạng toàn phương $$\frac{1}{2}y^T Q^{-1} y$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Conjugate of indicator --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Conjugate của indicator function \(I_C(x)\) của tập lồi \(C\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(I_C^*(y) = \sup_{x \in C} y^T x\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(I_C^*(y) = \inf_{x \in C} y^T x\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(I_C^*(y) = I_C(y)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(I_C^*(y) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$I_C^*(y) = \sup_{x \in C} y^T x$$&lt;/strong&gt;&lt;br /&gt;
                Hàm liên hợp của hàm chỉ thị $$I_C$$ chính là hàm hỗ trợ (support function) của tập $$C$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Dual cone definition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Dual cone \(K^*\) của cone \(K\) được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(K^* = \{y : y^T x \geq 0 \text{ với mọi } x \in K\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(K^* = \{y : y^T x \leq 0 \text{ với mọi } x \in K\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(K^* = \{y : y^T x = 0 \text{ với mọi } x \in K\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(K^* = K\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$K^* = \{y : y^T x \geq 0 \text{ với mọi } x \in K\}$$&lt;/strong&gt;&lt;br /&gt;
                Nón đối ngẫu gồm tất cả các vector tạo góc không tù (tích vô hướng không âm) với mọi vector trong nón gốc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Self-dual cone --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Cone nào sau đây là self-dual?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Positive orthant \(\mathbb{R}_+^n\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Second-order cone (Lorentz cone)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Positive semidefinite cone&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Tất cả các cone trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các cone trên&lt;/strong&gt;&lt;br /&gt;
                Nón không âm $$\mathbb{R}_+^n$$, nón bậc hai và nón ma trận nửa xác định dương đều tự đối ngẫu ($$K^* = K$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Conjugate of norm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Conjugate của norm \(\|x\|\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(f^*(y) = I_{\{\|y\|_* \leq 1\}}(y)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(f^*(y) = \|y\|_*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(f^*(y) = \|y\|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(f^*(y) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f^*(y) = I_{\{\|y\|_* \leq 1\}}(y)$$&lt;/strong&gt;&lt;br /&gt;
                Hàm liên hợp của một chuẩn là hàm chỉ thị của quả cầu đơn vị ứng với chuẩn đối ngẫu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Fenchel duality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Fenchel duality theorem áp dụng cho bài toán \(\min f(x) + g(Ax)\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) \(\min f(x) + g(Ax) = \max -f^*(-A^T y) - g^*(y)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) \(\min f(x) + g(Ax) = \max f^*(A^T y) + g^*(y)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) \(\min f(x) + g(Ax) = \min f^*(x) + g^*(Ax)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Không có mối liên hệ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\min f(x) + g(Ax) = \max -f^*(-A^T y) - g^*(y)$$&lt;/strong&gt;&lt;br /&gt;
                Định lý đối ngẫu Fenchel liên kết bài toán nguyên thủy và bài toán đối ngẫu thông qua các hàm liên hợp.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Legendre transform --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Legendre transform được sử dụng khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(f\) là convex và differentiable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(f\) là concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(f\) là linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) \(f\) là non-convex&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f$$ là convex và differentiable&lt;/strong&gt;&lt;br /&gt;
                Biến đổi Legendre là trường hợp riêng của hàm liên hợp khi $$f$$ lồi và khả vi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Moreau envelope --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Moreau envelope \(M_\lambda f(x)\) liên quan đến:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Proximal operator&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Conjugate function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Smoothing của \(f\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Tất cả các điều trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các điều trên&lt;/strong&gt;&lt;br /&gt;
                Bao Moreau liên hệ chặt với toán tử cận (proximal operator), hàm liên hợp và tạo ra xấp xỉ trơn cho hàm $$f$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Convex conjugate inequality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Fenchel-Young inequality phát biểu rằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) \(f(x) + f^*(y) \geq x^T y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) \(f(x) + f^*(y) \leq x^T y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) \(f(x) + f^*(y) = x^T y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) \(f(x) - f^*(y) \geq x^T y\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f(x) + f^*(y) \geq x^T y$$&lt;/strong&gt;&lt;br /&gt;
                Bất đẳng thức Fenchel–Young khẳng định $$f(x) + f^*(y) \geq x^T y$$, và dấu bằng xảy ra khi $$y \in \partial f(x)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Dual problem solving --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Khi nào nên giải dual problem thay vì primal?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Khi dual có ít variables hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Khi dual có structure đơn giản hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Khi có strong duality&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Tất cả các trường hợp trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các trường hợp trên&lt;/strong&gt;&lt;br /&gt;
                Giải bài toán đối ngẫu có lợi khi số biến ít hơn, cấu trúc ràng buộc đơn giản hơn hoặc thuận tiện tính toán hơn, với điều kiện thỏa mãn tính đối ngẫu mạnh.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Conjugate of max --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Conjugate của \(f(x) = \max\{f_1(x), f_2(x)\}\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) \(f^*(y) = \max\{f_1^*(y), f_2^*(y)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) \(f^*(y) = \min\{f_1^*(y), f_2^*(y)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) \(f^*(y) = f_1^*(y) + f_2^*(y)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) \(f^*(y) = \inf\{\lambda_1 f_1^*(y_1/\lambda_1) + \lambda_2 f_2^*(y_2/\lambda_2) : y_1 + y_2 = y,\ \lambda_1 + \lambda_2 = 1, \lambda_i \geq 0\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) $$f^*(y) = \inf\{\lambda_1 f_1^*(y_1/\lambda_1) + \lambda_2 f_2^*(y_2/\lambda_2) : y_1 + y_2 = y,\ \lambda_1 + \lambda_2 = 1, \lambda_i \geq 0\}$$&lt;/strong&gt;&lt;br /&gt;
                Với $$f_1, f_2$$ lồi, đóng: conjugate của max là bao lồi (convex hull) của $$\min\{f_1^*, f_2^*\}$$, chính là công thức D (dùng perspective). Đáp án B chỉ là $$\min\{f_1^*, f_2^*\}$$, nói chung không lồi nên không thể là một conjugate. Ví dụ: $$\max\{x, -x\} = |x|$$ có conjugate $$I_{[-1,1]}$$, trong khi $$\min\{I_{\{1\}}, I_{\{-1\}}\} = I_{\{-1,1\}}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Conjugate duality được ứng dụng trong:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Machine learning (regularization, kernel methods)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Signal processing (compressed sensing, denoising)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Economics (utility theory, market equilibrium)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các lĩnh vực trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các lĩnh vực trên&lt;/strong&gt;&lt;br /&gt;
                Đối ngẫu liên hợp được ứng dụng rộng rãi trong học máy (điều chuẩn), xử lý tín hiệu (biểu diễn thưa), kinh tế học (tối đa hóa độ thỏa dụng) và nhiều lĩnh vực khác.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Sensitivity analysis trong tối ưu hóa nghiên cứu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Thay đổi nghiệm khi tham số thay đổi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Độ nhạy của thuật toán&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Tốc độ hội tụ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Độ chính xác số&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Thay đổi nghiệm khi tham số thay đổi&lt;/strong&gt;&lt;br /&gt;
                Phân tích độ nhạy nghiên cứu mức độ thay đổi của giá trị và nghiệm tối ưu khi các tham số của bài toán biến thiên.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Trong LP, shadow price của ràng buộc $$i$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Giá trị của dual variable $$y_i^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Giá trị của primal variable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Hệ số trong hàm mục tiêu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Slack variable&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Giá trị của dual variable $$y_i^*$$&lt;/strong&gt;&lt;br /&gt;
                Giá bóng (shadow price) chính là biến đối ngẫu tối ưu, phản ánh tốc độ thay đổi biên của giá trị tối ưu khi nới lỏng ràng buộc thêm một đơn vị.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Envelope theorem trong tối ưu hóa cho biết:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$\frac{\partial f^*(\theta)}{\partial \theta} = \frac{\partial L}{\partial \theta}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$\frac{\partial f^*}{\partial x} = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$\frac{\partial^2 f^*}{\partial \theta^2} = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$f^*(\theta) = \text{const}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\frac{\partial f^*(\theta)}{\partial \theta} = \frac{\partial L}{\partial \theta}$$&lt;/strong&gt;&lt;br /&gt;
                Định lý bao (envelope theorem) cho biết đạo hàm của hàm giá trị tối ưu theo tham số bằng đạo hàm riêng của hàm Lagrangian theo tham số đó tại điểm tối ưu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Parametric programming nghiên cứu bài toán:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$\min f(x,\theta)$$ với $$g(x,\theta) \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$\min f(x)$$ với $$g(x) \leq \theta$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Cả A và B&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Không có tham số&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Cả A và B&lt;/strong&gt;&lt;br /&gt;
                Parametric programming xem xét bài toán tối ưu với tham số trong hàm mục tiêu và/hoặc ràng buộc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Trong portfolio optimization, khi risk aversion tăng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Chọn portfolio ít rủi ro hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Chọn portfolio rủi ro hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Không thay đổi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Tối đa hóa return&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Chọn portfolio ít rủi ro hơn&lt;/strong&gt;&lt;br /&gt;
                Hệ số ngại rủi ro (risk aversion) càng cao thì danh mục đầu tư tối ưu càng ưu tiên phương sai (rủi ro) thấp hơn.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành Quiz!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;a&apos;, q3: &apos;a&apos;, q4: &apos;a&apos;, q5: &apos;b&apos;,
    q6: &apos;a&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;d&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;d&apos;, q17: &apos;a&apos;, q18: &apos;d&apos;, q19: &apos;d&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;c&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã thành thạo advanced duality theory!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu tốt về conjugate functions và dual norms.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại conjugate properties và Fenchel duality.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Ôn lại conjugate functions và dual cones.&apos;;
    } else {
        message = &apos;📖 Hãy học lại từ đầu về advanced duality concepts nhé!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>13-06 Tinh tế đối ngẫu & Đối ngẫu kép</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_06_Dual_subtleties_Double_dual/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_06_Dual_subtleties_Double_dual</id>
   <content type="html">&lt;p&gt;Trong thực hành lập bài toán đối ngẫu, có những “bẫy tinh tế” mà ngay cả người đã thuộc lòng công thức KKT cũng dễ vấp phải. Ví dụ, bạn lấy logarit hoặc nhân đôi hàm mục tiêu của bài toán đối ngẫu để nó trông gọn gàng hơn — nghiệm đối ngẫu \(u^\star\) vẫn giữ nguyên, nhưng liệu giá trị hàm mục tiêu mới có còn dùng được để tính khoảng cách đối ngẫu không? Câu trả lời là &lt;strong&gt;không&lt;/strong&gt;! Chỉ một phép biến đổi đơn điệu tưởng chừng vô hại đã làm mất đi tính chất chặn dưới trực tiếp của hàm đối ngẫu gốc.&lt;/p&gt;

&lt;p&gt;Một câu hỏi sâu sắc không kém là: &lt;em&gt;điều gì xảy ra nếu ta lấy đối ngẫu của chính bài toán đối ngẫu?&lt;/em&gt; Bài học này đi sâu vào những tinh tế đó và chứng minh kết quả đẹp mắt về &lt;strong&gt;đối ngẫu kép (double dual)&lt;/strong&gt;: với bài toán lồi đóng có cấu trúc phù hợp, đi qua hai lần phép đối ngẫu sẽ đưa bạn trở về đúng bài toán nguyên thủy ban đầu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-các-quy-tắc-an-toàn-khi-biến-đổi-bài-toán-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Các quy tắc an toàn khi biến đổi bài toán đối ngẫu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tương đương nghiệm vs. Tương đương giá trị:&lt;/strong&gt; Khi biến đổi bài toán đối ngẫu (như đổi dấu thành cực tiểu hóa, lấy logarit, bỏ hằng số), tập nghiệm tối ưu \(u^\star\) không đổi, nhưng giá trị mục tiêu đã thay đổi — bạn phải hoàn nguyên về \(g(u)\) gốc trước khi tính duality gap \(f(x) - g(u)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán tương đương nguyên thủy có thể cho đối ngẫu khác nhau:&lt;/strong&gt; Thêm ràng buộc dư, biến đổi hàm mục tiêu (ví dụ \(\min \|Ax-b\|_2\) so với \(\min \frac{1}{2}\|Ax-b\|_2^2\)) hay tách biến không làm thay đổi \(x^\star\), nhưng có thể biến bài toán đối ngẫu từ chỗ khó giải thành cực kỳ đẹp mắt!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính đối ngẫu kép (Double Dual):&lt;/strong&gt; Lấy đối ngẫu của bài toán đối ngẫu thực chất là lấy liên hợp kép \(f^{**}\) (bao lồi đóng của \(f\)). Khi bài toán gốc lồi và thỏa tính đóng, đối ngẫu của đối ngẫu trả về đúng bài toán gốc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-minh-họa-hai-bài-toán-nguyên-thủy-tương-đương-sinh-ra-hai-đối-ngẫu-khác-hẳn-nhau&quot;&gt;Giải thích: Minh họa hai bài toán nguyên thủy tương đương sinh ra hai đối ngẫu khác hẳn nhau&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa 1 chiều đơn giản \(\min_{x \in \mathbb{R}} \vert x - 2 \vert\) (nghiệm hiển nhiên \(x^\star = 2, f^\star = 0\)), và so sánh hai cách viết tương đương:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cách viết 1 (không tách biến, không ràng buộc):&lt;/strong&gt;
\(\min_x \vert x - 2 \vert.\)
Không có ràng buộc nên hàm Lagrange là \(L(x) = \vert x - 2 \vert\), hàm đối ngẫu chỉ là hằng số \(g_1 = 0\) — không có biến đối ngẫu để khai thác!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách viết 2 (thêm biến phụ \(z = x - 2\)):&lt;/strong&gt;
\(\min_{x, z} \vert z \vert \qquad \text{với } z = x - 2.\)
Hàm Lagrange: \(L(x, z, v) = \vert z \vert + v(x - 2 - z) = vx + (\vert z \vert - vz) - 2v\).
Lấy cực tiểu theo \(x\) buộc \(v = 0\); lấy cực tiểu theo \(z\) buộc \(\vert v \vert \le 1\). Ta thu được đối ngẫu \(\max_{v = 0} (-2v) = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử bẫy biến đổi hàm đối ngẫu trên bài toán có ràng buộc:&lt;/strong&gt;
Xét \(\min_{x \ge 1} x^2\) (\(f^\star = 1\)). Đối ngẫu gốc là \(\max_{u \ge 0} g(u)\) với \(g(u) = u - \frac{u^2}{4}\) (đạt cực đại \(g(2) = 1\)).
    &lt;ul&gt;
      &lt;li&gt;Nếu ai đó “viết gọn” bài toán đối ngẫu bằng cách nhân 4 lên thành \(\max_{u \ge 0} \tilde{g}(u) = 4u - u^2\): nghiệm tối ưu vẫn là \(u^\star = 2\), nhưng tại \(u = 1\) ta có \(\tilde{g}(1) = 3 &amp;gt; f^\star = 1\)! Nếu dùng \(\tilde{g}(1)\) để tính duality gap sẽ ra số âm vô nghĩa, trong khi dùng \(g(1) = 0.75 \le 1\) mới cho chặn dưới đúng.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;một-số-lưu-ý-tinh-tế-về-đối-ngẫu&quot;&gt;Một số lưu ý tinh tế về đối ngẫu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Trong thực hành, ta thường biến đổi bài toán đối ngẫu sang một bài toán tối ưu tương đương gọn hơn và vẫn gọi đó là bài toán đối ngẫu. Khi tính đối ngẫu mạnh được thỏa mãn, nghiệm của bài toán đối ngẫu đã biến đổi vẫn có thể dùng để phân tích đặc trưng hoặc khôi phục nghiệm nguyên thủy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;lưu-ý&quot;&gt;Lưu ý&lt;/h4&gt;
&lt;p&gt;Giá trị mục tiêu tối ưu của bài toán đối ngẫu sau khi biến đổi (chẳng hạn bỏ hằng số hay đổi dấu) không nhất thiết bằng giá trị tối ưu của bài toán nguyên thủy.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Một kỹ thuật phổ biến để xây dựng bài toán đối ngẫu cho bài toán không ràng buộc là đưa thêm các biến phụ và ràng buộc đẳng thức vào bài toán nguyên thủy. Cách biến đổi này không duy nhất; các cách đặt biến phụ khác nhau có thể dẫn tới những bài toán đối ngẫu khác nhau.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;đối-ngẫu-kép&quot;&gt;Đối ngẫu kép&lt;/h2&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa tổng quát với các ràng buộc tuyến tính:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) \text{ với điều kiện } Ax \le b, \; Cx = d\]
&lt;/blockquote&gt;

&lt;p&gt;Hàm Lagrangian tương ứng là:&lt;/p&gt;

&lt;blockquote&gt;
\[L(x,u,v) = f(x) + (A^Tu + C^Tv)^Tx - b^Tu - d^Tv\]
&lt;/blockquote&gt;

&lt;p&gt;Từ đó, bài toán đối ngẫu có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_{u,v} -f^*(-A^Tu - C^Tv) - b^Tu - d^Tv \text{ với điều kiện } u \ge 0\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;nhắc-lại-tính-chất&quot;&gt;Nhắc lại tính chất&lt;/h4&gt;

&lt;p&gt;Nếu \(f\) là hàm đóng và lồi, ta đã biết hàm liên hợp kép bằng chính hàm gốc (\(f^{**} = f\)), nên bài toán đối ngẫu của bài toán đối ngẫu chính là bài toán nguyên thủy.&lt;/p&gt;

&lt;p&gt;Thực tế, tính chất này còn mở rộng vượt ra ngoài trường hợp ràng buộc tuyến tính. Xét bài toán tổng quát:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \min_x &amp;amp;&amp;amp; f(x) \\
&amp;amp;\text{ với điều kiện } &amp;amp;&amp;amp; h_i(x) \le 0, \; i = 1,\dots,m \\
&amp;amp;&amp;amp;&amp;amp;l_j(x) = 0, \; j = 1,\dots,r
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu \(f\) và các hàm \(h_1, \dots, h_m\) đều đóng và lồi, còn \(l_1, \dots, l_r\) là các hàm affine, thì đối ngẫu của đối ngẫu vẫn là bài toán nguyên thủy. Kết quả này được xây dựng từ góc nhìn lý thuyết hàm hai biến (xem thêm Chương 29 và Chương 30 trong sách của Rockafellar).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-05 Nón đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_05_Dual_cones/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_05_Dual_cones</id>
   <content type="html">&lt;p&gt;Trong quy hoạch tuyến tính (LP), mọi ràng buộc bất đẳng thức đều so sánh từng số thực với số \(0\) (\(x_i \ge 0\)). Nhưng thế giới hiện đại không chỉ có các số vô hướng rời rạc: trong kỹ thuật kết cấu, tài chính định lượng hay điều khiển tối ưu, biến có thể phải nằm trong một &lt;strong&gt;nón bậc hai&lt;/strong&gt; (ràng buộc rủi ro phương sai) hoặc là một &lt;strong&gt;ma trận nửa xác định dương&lt;/strong&gt; (quy hoạch nửa xác định SDP).&lt;/p&gt;

&lt;p&gt;Khi rời khỏi trục số thực để bước vào các &lt;strong&gt;nón lồi&lt;/strong&gt; \(K\), khái niệm “nhân tử không âm \(u \ge 0\)” phải được nâng cấp thành gì? Câu trả lời chính là &lt;strong&gt;nón đối ngẫu \(K^*\)&lt;/strong&gt; — tập hợp mọi vectơ tạo góc không tù (\(y^T x \ge 0\)) với toàn bộ các tia nằm trong nón \(K\). Đặc biệt kỳ diệu là cả ba nón quan trọng nhất của tối ưu lồi hiện đại (nón không âm \(\mathbb{R}_+^n\), nón bậc hai \(\mathcal{Q}_n\) và nón ma trận nửa xác định dương \(\mathbb{S}_+^n\)) đều là &lt;strong&gt;nón tự đối ngẫu&lt;/strong&gt; (\(K^* = K\)).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-góc-nhọn-và-quy-hoạch-nón&quot;&gt;Kiến thức cần nhớ: Hình học góc nhọn và quy hoạch nón&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa hình học của nón đối ngẫu:&lt;/strong&gt; \(K^* = \{y : y^T x \ge 0 \;\forall x \in K\}\). Nón \(K\) càng “mở rộng” (chứa nhiều hướng), nón đối ngẫu \(K^*\) càng “thu hẹp” (càng khó tạo góc \(\le 90^\circ\) với mọi tia trong \(K\)), và ngược lại.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ba nón tự đối ngẫu kinh điển:&lt;/strong&gt; Nón không âm \(\mathbb{R}_+^n\), nón bậc hai (nón kem ốc quế) \(\{(x, t) : \|x\|_2 \le t\}\), và nón ma trận đối xứng nửa xác định dương \(\mathbb{S}_+^n\) đều thỏa \(K^* = K\). Điều này giúp bài toán đối ngẫu của LP, SOCP và SDP giữ nguyên cùng họ nón với bài toán gốc!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hợp của hàm chỉ thị nón:&lt;/strong&gt; Hàm chỉ thị \(I_K(x)\) có hàm liên hợp chính là \(I_{-K^*}(y)\) (hay \(I_{K^*}(-y)\)). Đó là lý do khi chuyển bài toán quy hoạch nón \(\min_{x \in K} f(x)\) sang đối ngẫu, nón đối ngẫu \(K^*\) tự động xuất hiện.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu kép của nón:&lt;/strong&gt; Với mọi nón lồi đóng \(K\), ta luôn có \((K^*)^* = K\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-nón-đối-ngẫu-của-một-nón-nhọn-trong-mathbbr2&quot;&gt;Giải thích: Tính tay nón đối ngẫu của một nón nhọn trong \(\mathbb{R}^2\)&lt;/h3&gt;

&lt;p&gt;Xét nón lồi nhọn \(K \subset \mathbb{R}^2\) sinh bởi hai tia \(a_1 = (2, 1)^T\) và \(a_2 = (1, 2)^T\):&lt;/p&gt;

\[K = \bigl\{\alpha_1 (2, 1)^T + \alpha_2 (1, 2)^T \mid \alpha_1 \ge 0, \alpha_2 \ge 0\bigr\}.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện để \(y = (y_1, y_2)^T \in K^*\):&lt;/strong&gt;
Ta cần \(y^T x \ge 0\) với mọi \(x = \alpha_1 a_1 + \alpha_2 a_2\) (\(\alpha_1, \alpha_2 \ge 0\)). Vì tính tuyến tính, điều này tương đương với hai bất đẳng thức trên hai tia sinh:
\(y^T a_1 = 2y_1 + y_2 \ge 0 \qquad \text{và} \qquad y^T a_2 = y_1 + 2y_2 \ge 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm hai tia biên của nón đối ngẫu \(K^*\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Biên thứ nhất: \(2y_1 + y_2 = 0\) và \(y_1 + 2y_2 \ge 0 \implies y_1 = -t, y_2 = 2t\) (\(t \ge 0\)), tức tia \(b_1 = (-1, 2)^T\) (vuông góc với \(a_1\)).&lt;/li&gt;
      &lt;li&gt;Biên thứ hai: \(y_1 + 2y_2 = 0\) và \(2y_1 + y_2 \ge 0 \implies y_1 = 2t, y_2 = -t\) (\(t \ge 0\)), tức tia \(b_2 = (2, -1)^T\) (vuông góc với \(a_2\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra trực giác “nón nhọn ↔ nón tù”:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Góc mở của \(K\) là góc giữa \((2,1)\) và \((1,2)\): \(\cos\theta_K = \frac{4}{5} \implies \theta_K \approx 36.9^\circ\) (rất nhọn).&lt;/li&gt;
      &lt;li&gt;Góc mở của \(K^*\) là góc giữa \((-1,2)\) và \((2,-1)\): \(\cos\theta_{K^*} = -\frac{4}{5} \implies \theta_{K^*} \approx 143.1^\circ = 180^\circ - \theta_K\) (rất rộng!).&lt;/li&gt;
      &lt;li&gt;Thử điểm \(y = (-1, 2)^T \in K^*\) với \(x = (2, 1)^T \in K\): \(y^T x = -2 + 2 = 0 \ge 0\); với \(x = (1, 2)^T\): \(y^T x = -1 + 4 = 3 &amp;gt; 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;nón-đối-ngẫu&quot;&gt;Nón đối ngẫu&lt;/h2&gt;

&lt;p&gt;Cho một nón \(K \subseteq \mathbb{R}^n\) (nhắc lại từ mục &lt;a href=&quot;/contents/vi/chapter02/02_06_01_Dual_cones/&quot;&gt;02-06-01&lt;/a&gt;, nón là tập thỏa tính chất \(x \in K, t \ge 0 \implies tx \in K\)). &lt;strong&gt;Nón đối ngẫu&lt;/strong&gt; của \(K\) được định nghĩa là:&lt;/p&gt;

&lt;blockquote&gt;
\[K^* = \{ y : y^Tx \ge 0 \text{ với mọi } x \in K \}\]
&lt;/blockquote&gt;

&lt;p&gt;Nón đối ngẫu \(K^*\) luôn là một nón lồi, ngay cả khi bản thân \(K\) không lồi.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter13/dual_cone.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig3] Nón đối ngẫu [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h5 id=&quot;lưu-ý&quot;&gt;Lưu ý&lt;/h5&gt;
&lt;p&gt;\(y \in K^* \iff \text{nửa không gian } \{ x : y^Tx \ge 0 \} \text{ chứa } K\) (Boyd &amp;amp; Vandenberghe, trang 52).&lt;/p&gt;

&lt;p&gt;Một tính chất quan trọng là: nếu \(K\) là một nón lồi và đóng, thì \(K^{**} = K\).&lt;/p&gt;

&lt;h4 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Nón đối ngẫu của một không gian con tuyến tính \(V\) là phần bù trực giao \(V^{\perp}\). Chẳng hạn, \((\text{row}(A))^{*} = \text{null}(A)\).&lt;/li&gt;
  &lt;li&gt;Nón đối ngẫu của nón chuẩn \(K = \{ (x,t) \in \mathbb{R}^{n+1} : \| x \| \le t \}\) là nón chuẩn ứng với chuẩn đối ngẫu: \(K^{*} = \{ (y,s) \in \mathbb{R}^{n+1} : \| y \|_{*} \le s \}\).&lt;/li&gt;
  &lt;li&gt;Nón các ma trận nửa xác định dương \(\mathbb{S}^n_+\) là một nón lồi tự đối ngẫu, tức \((\mathbb{S}^n_+)^{*} = \mathbb{S}^n_+\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Để kiểm chứng tính tự đối ngẫu của \(\mathbb{S}^n_+\), ta sử dụng tương đương:&lt;/p&gt;

&lt;blockquote&gt;
\[Y \succeq 0 \iff \text{tr}(Y X) \ge 0 \text{ với mọi } X \succeq 0\]
&lt;/blockquote&gt;

&lt;p&gt;(có thể chứng minh trực tiếp bằng phép phân tích trị riêng của \(X\)).&lt;/p&gt;

&lt;h2 id=&quot;nón-đối-ngẫu-và-bài-toán-đối-ngẫu&quot;&gt;Nón đối ngẫu và bài toán đối ngẫu&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối ưu có ràng buộc nón:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) \text{ với điều kiện } Ax \in K\]
&lt;/blockquote&gt;

&lt;p&gt;Với hàm hỗ trợ \(I^{*}_K(y) = \max_{z \in K} z^Ty\) của \(K\), bài toán đối ngẫu của bài toán trên có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_u -f^*(A^Tu) - I^*_K(-u)\]
&lt;/blockquote&gt;

&lt;p&gt;Vì \(K\) là một nón nên \(I_K^{*}(-u) = I_{K^{*}}(u)\), do đó bài toán đối ngẫu rút gọn thành:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_u -f^*(A^Tu) \text{ với điều kiện } u \in K^{*}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(K^{*}\) là nón đối ngẫu của \(K\). Dạng biểu diễn này rất thuận tiện vì nhiều lớp ràng buộc trong thực tế đều có thể viết dưới dạng ràng buộc nón.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-04 Hàm liên hợp</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_04_Conjugate_function/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_04_Conjugate_function</id>
   <content type="html">&lt;p&gt;Một đường cong lồi trơn tru có thể được mô tả theo hai cách hoàn toàn tương đương. Cách quen thuộc nhất là liệt kê từng điểm \((x, f(x))\) nằm trên đường cong. Nhưng từ thế kỷ 18, nhà toán học Adrien-Marie Legendre — và sau này là Werner Fenchel trong tối ưu lồi hiện đại — đã chỉ ra một góc nhìn thứ hai đầy bất ngờ: bạn có thể mô tả trọn vẹn hàm \(f\) bằng tập hợp &lt;strong&gt;tất cả các đường tiếp tuyến&lt;/strong&gt; có độ dốc \(y\) nằm ngay dưới đồ thị của nó!&lt;/p&gt;

&lt;p&gt;Mỗi đường thẳng có độ dốc \(y\) được xác định bởi tung độ gốc (hay độ dịch chuyển lớn nhất) để nó chạm sát vào đồ thị \(f(x)\): đó chính là &lt;strong&gt;hàm liên hợp&lt;/strong&gt; \(f^*(y) = \sup_x (y^T x - f(x))\). Không cần \(f\) phải lồi hay khả vi, \(f^*\) luôn luôn là một hàm lồi vì nó là supremum theo từng điểm của một họ các hàm tuyến tính theo \(y\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-tính-chất-của-hàm-liên-hợp-fenchel&quot;&gt;Kiến thức cần nhớ: Bốn tính chất của hàm liên hợp Fenchel&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa hình học của độ dốc và tung độ gốc:&lt;/strong&gt; Khoảng cách lớn nhất theo phương thẳng đứng giữa đường thẳng \(y^T x\) và đồ thị \(f(x)\) chính là \(f^*(y)\). Khi \(f\) khả vi lồi, điểm \(x\) đạt cực đại thỏa \(\nabla f(x) = y\), nghĩa là phép liên hợp biến đổi hàm theo biến vị trí \(x\) thành hàm theo biến độ dốc \(y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi tự động:&lt;/strong&gt; Dù hàm gốc \(f\) lồi lõm tùy ý, \(f^*(y)\) luôn là hàm lồi và đóng. Vì thế, bài toán đối ngẫu lập qua \(f^*\) luôn có cấu trúc lồi đẹp đẽ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Fenchel–Young:&lt;/strong&gt; Với mọi \(x, y\), ta luôn có \(f(x) + f^*(y) \ge y^T x\). Dấu bằng xảy ra khi và chỉ khi \(y \in \partial f(x)\) (tức là \(y\) là dưới-gradient của \(f\) tại \(x\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý Fenchel–Moreau (liên hợp kép):&lt;/strong&gt; Nếu \(f\) là hàm lồi và đóng (nửa liên tục dưới), thì lấy liên hợp hai lần sẽ trả lại chính xác hàm ban đầu: \(f^{**} = f\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-tính-hàm-liên-hợp-của-hai-hàm-kinh-điển&quot;&gt;Giải thích: Tự tay tính hàm liên hợp của hai hàm kinh điển&lt;/h3&gt;

&lt;p&gt;Hãy tính \(f^*(y) = \sup_x (yx - f(x))\) cho một hàm trơn và một hàm không trơn (chuẩn \(\ell_1\)) trong 1 chiều:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hàm bậc hai \(f(x) = \frac{1}{2}ax^2\) (với \(a &amp;gt; 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Xét hàm theo \(x\): \(h(x) = yx - \frac{1}{2}ax^2\).&lt;/li&gt;
      &lt;li&gt;Đạo hàm \(h&apos;(x) = y - ax = 0 \implies x^\star = \frac{y}{a}\) (vì \(h&apos;&apos;(x) = -a &amp;lt; 0\) nên đây là cực đại toàn cục).&lt;/li&gt;
      &lt;li&gt;Thay lại: \(f^*(y) = y\left(\frac{y}{a}\right) - \frac{1}{2}a\left(\frac{y}{a}\right)^2 = \frac{y^2}{2a}\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra nhanh với \(a = 2, x = 3, y = 4\): \(f(3) = 9\), \(f^*(4) = \frac{16}{4} = 4\); vế trái \(f(3) + f^*(4) = 13\), còn \(yx = 12 \le 13\) (thỏa Fenchel–Young; dấu bằng đạt khi \(y = ax = 6\): \(f(3) + f^*(6) = 9 + 9 = 18 = 6 \cdot 3\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm giá trị tuyệt đối \(f(x) = \vert x \vert\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ta cần tìm \(\sup_x (yx - \vert x \vert)\).&lt;/li&gt;
      &lt;li&gt;Nếu \(\vert y \vert \le 1\): với mọi \(x\), \(yx \le \vert y \vert \cdot \vert x \vert \le \vert x \vert\), nên \(yx - \vert x \vert \le 0\), và đạt giá trị \(0\) tại \(x = 0\). Vậy \(f^*(y) = 0\).&lt;/li&gt;
      &lt;li&gt;Nếu \(\vert y \vert &amp;gt; 1\) (ví dụ \(y = 2\)): chọn \(x \to +\infty\) thì \(2x - x = x \to +\infty\). Vậy \(f^*(y) = +\infty\).&lt;/li&gt;
      &lt;li&gt;Kết luận: liên hợp của \(\vert x \vert\) là hàm chỉ thị \(I_{[-1, 1]}(y)\) của đoạn đơn vị \([-1, 1]\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Với một hàm cho trước \(f : \mathbb{R}^n \to \mathbb{R}\), &lt;strong&gt;hàm liên hợp&lt;/strong&gt; (conjugate function) \(f^{*} : \mathbb{R}^n \to \mathbb{R}\) được định nghĩa như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[f^{*}(y) = \max_x (y^Tx - f(x))\]
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter13/conjugate_function.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Minh họa hàm liên hợp [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;lưu-ý&quot;&gt;Lưu ý&lt;/h3&gt;

&lt;p&gt;Hàm \(f^{*}\) luôn là hàm lồi vì nó là cực đại theo từng điểm của một họ các hàm affine \(y \mapsto y^Tx - f(x)\) (ngay cả khi \(f\) không lồi). Về mặt hình học, \(f^{*}(y)\) đo khoảng cách cực đại theo phương thẳng đứng giữa hàm tuyến tính \(y^Tx\) và đồ thị của \(f(x)\) (Boyd &amp;amp; Vandenberghe, trang 91).&lt;/p&gt;

&lt;p&gt;Khi \(f\) khả vi, phép lấy hàm liên hợp còn được gọi là &lt;strong&gt;biến đổi Legendre&lt;/strong&gt;.&lt;/p&gt;

&lt;h4 id=&quot;tính-chất&quot;&gt;Tính chất&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Fenchel:&lt;/strong&gt; Với mọi \(x, y\), ta có \(f(x) + f^{*}(y) \ge x^Ty\).
    &lt;blockquote&gt;
      &lt;p&gt;\(f(x) + f^{*}(y) \ge x^Ty \iff f^{*}(y) \ge x^Ty - f(x)\)
\(f^{*}(y) = \max_z (z^Ty - f(z))\)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Hàm liên hợp của hàm liên hợp được ký hiệu là \(f^{**}\), và bất đẳng thức \(f^{**} \le f\) luôn đúng.&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Nếu \(f\) là hàm đóng và lồi, thì \(f^{**} = f\).&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Nếu \(f\) là hàm đóng và lồi, thì với mọi \(x, y\) ta có các tương đương sau:&lt;br /&gt;
    &lt;blockquote&gt;
\[\begin{align}
x \in \partial f^{*}(y) &amp;amp;\iff y \in \partial f(x) \\\
&amp;amp;\iff f(x) + f^{*}(y) = x^Ty \\\
\end{align}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Nếu hàm tách biến theo dạng \(f(u,v) = f_1(u) + f_2(v)\), thì \(f^{*}(w,z) = f_1^{*}(w) + f_2^{*}(z)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm bậc hai:&lt;/strong&gt; Xét \(f(x) = \frac{1}{2}x^TQx\), trong đó \(Q \succ 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Khi đó, hàm \(x \mapsto y^Tx - \frac{1}{2}x^TQx\) là hàm lõm chặt theo \(x\) và đạt cực đại duy nhất tại \(x = Q^{-1}y\). Thay vào định nghĩa ta được \(f^{*}(y) = \frac{1}{2}y^TQ^{-1}y\).&lt;/p&gt;

&lt;h3 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
f^{*}(y) &amp;amp; =  \max_x \left( y^Tx -\frac{1}{2}x^TQx \right) \\\
&amp;amp; = -\min_x \left(\frac{1}{2}x^TQx- y^Tx \right), \quad x^{\star} = Q^{-1}y  \\\
&amp;amp; = -\frac{1}{2}y^TQ^{-1}QQ^{-1}y + y^TQ^{-1}y \\\
&amp;amp; = \frac{1}{2}y^TQ^{-1}y  \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Từ đó thu được bất đẳng thức Fenchel tương ứng với mọi \(x, y\):
\(\frac{1}{2} x^TQx + \frac{1}{2} y^TQ^{-1}y \ge x^Ty\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chỉ thị:&lt;/strong&gt; Nếu \(f(x) = I_C(x)\), thì hàm liên hợp của nó là:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f^{*}(y) = I^{*}_C(y) = \max_{x \in C} y^Tx\) (được gọi là &lt;strong&gt;hàm hỗ trợ&lt;/strong&gt; của tập \(C\)).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chuẩn:&lt;/strong&gt; Nếu \(f(x) = \|x\|\), thì hàm liên hợp của nó là:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f^{*}(y) = I_{\{ z : \lVert z \rVert_{*} \le 1 \}}(y)\), trong đó \(\lVert \cdot \rVert_{*}\) là chuẩn đối ngẫu của \(\lVert \cdot \rVert\).&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>13-04-03 Dịch chuyển biến đổi tuyến tính</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_04_03_Shifting_linear_transformations/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_04_03_Shifting_linear_transformations</id>
   <content type="html">&lt;p&gt;Trong rất nhiều bài toán thực tế — từ lọc nhiễu ảnh &lt;em&gt;Total Variation&lt;/em&gt; (phạt \(\|Dx\|_1\) với ma trận sai phân \(D\)), đến &lt;em&gt;Fused Lasso&lt;/em&gt; hay hồi quy có ràng buộc tuyến tính — khó khăn lớn nhất nằm ở chỗ hàm không trơn \(g\) lại bọc lấy một phép biến đổi tuyến tính \(Ax\). Ta biết rõ cách xử lý \(g(z)\) khi đứng một mình, nhưng khi bị “dính” với ma trận \(A\) bên trong \(g(Ax)\), toán tử gần kề (proximal operator) không còn công thức đóng nữa!&lt;/p&gt;

&lt;p&gt;Bài học ngắn nhưng cực kỳ đắt giá này chỉ ra một “phép hoán đổi vị trí” kỳ diệu nhờ đối ngẫu: khi lập bài toán đối ngẫu của \(\min_x f(x) + g(Ax)\), ma trận \(A\) nhảy sang vế bên kia dưới dạng ma trận chuyển vị \(A^T\) nằm trong \(f^*(-A^T u)\), còn \(g^*(u)\) hoàn toàn tự do không dính ma trận nào! Nếu \(f^*\) là hàm trơn (như hàm bậc hai), ta đã đẩy được ma trận \(A\) ra khỏi hàm không trơn sang hàm trơn dễ tính đạo hàm.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-nghệ-thuật-đẩy-ma-trận-chuyển-vị-sang-vế-dễ-hơn&quot;&gt;Kiến thức cần nhớ: Nghệ thuật đẩy ma trận chuyển vị sang vế dễ hơn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Biến đổi tương đương \(z = Ax\):&lt;/strong&gt; Tách toán tử tuyến tính \(A\) ra khỏi hàm \(g\) bằng một ràng buộc đẳng thức \(Ax - z = 0\), sau đó nhân với biến đối ngẫu \(u\) trong hàm Lagrange.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất liên hợp của ma trận chuyển vị:&lt;/strong&gt; Trong biểu thức \(u^T(Ax - z) = (A^T u)^T x - u^T z\), ma trận \(A\) tự động chuyển từ tác động lên \(x\) sang dạng \(A^T\) tác động lên biến đối ngẫu \(u\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lợi ích thuật toán thực chiến:&lt;/strong&gt; Khi \(f\) lồi mạnh (nên \(f^*\) khả vi Lipschitz) còn \(g\) là chuẩn không trơn (như \(\|Dx\|_1\)), bài toán đối ngẫu \(\min_u f^*(-A^T u) + g^*(u)\) trở thành bài toán tối ưu hàm trơn trên tập hộp đơn giản — giải cực nhanh bằng FISTA hay Projected Gradient Descent!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-dịch-chuyển-ma-trận-sai-phân-trong-bài-toán-làm-mịn-1d-fused-signal&quot;&gt;Giải thích: Dịch chuyển ma trận sai phân trong bài toán làm mịn 1D (Fused Signal)&lt;/h3&gt;

&lt;p&gt;Xét tín hiệu 2 điểm \(y = (0, 4)^T\) và bài toán làm mịn:&lt;/p&gt;

\[\min_{x \in \mathbb{R}^2} \underbrace{\frac{1}{2}\|x - y\|_2^2}_{f(x)} + \underbrace{\vert x_2 - x_1 \vert}_{g(Ax)},\]

&lt;p&gt;trong đó ma trận sai phân \(A = \begin{bmatrix} -1 &amp;amp; 1 \end{bmatrix}\) (\(Ax = x_2 - x_1\)) và \(g(z) = \vert z \vert\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính hai hàm liên hợp:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f^*(w) = \frac{1}{2}\|w\|_2^2 + y^T w\) (vì \(f(x) = \frac{1}{2}\|x - y\|_2^2\)).&lt;/li&gt;
      &lt;li&gt;\(g^*(u) = I_{[-1, 1]}(u)\) với \(u \in \mathbb{R}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng công thức dịch chuyển biến đổi tuyến tính:&lt;/strong&gt;
Bài toán đối ngẫu là \(\max_u -f^*(-A^T u) - g^*(u)\), tương đương cực tiểu hóa theo biến vô hướng \(u \in [-1, 1]\):
\(\min_{\vert u \vert \le 1} \frac{1}{2}\|A^T u\|_2^2 - y^T (A^T u).\)
Ta tính cụ thể: \(A^T u = (-u, u)^T\), nên \(\|A^T u\|_2^2 = 2u^2\) và \(y^T(A^T u) = 0(-u) + 4(u) = 4u\).
Vậy bài toán đối ngẫu thu gọn thành bài toán 1 biến cực dễ:
\(\min_{-1 \le u \le 1} \bigl(u^2 - 4u\bigr).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải đối ngẫu và khôi phục \(x^\star\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Parabol \(u^2 - 4u\) có đỉnh tại \(u = 2\), bị chặn bởi \([-1, 1]\) nên đạt cực tiểu tại \(u^\star = 1\).&lt;/li&gt;
      &lt;li&gt;Khôi phục từ điều kiện dừng \(x^\star - y = -A^T u^\star\):
\(x^\star = y - A^T u^\star = \begin{bmatrix} 0 \\ 4 \end{bmatrix} - \begin{bmatrix} -1 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \\ 3 \end{bmatrix}.\)&lt;/li&gt;
      &lt;li&gt;Kiểm tra giá trị: nguyên thủy \(f(x^\star) + g(Ax^\star) = \frac{1}{2}(1^2 + (-1)^2) + \vert 3 - 1 \vert = 1 + 2 = 3\); đối ngẫu \(-((1)^2 - 4(1)) = 3\). Hai bên bằng nhau tuyệt đối!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Kỹ thuật lập bài toán đối ngẫu cho phép dịch chuyển phép biến đổi tuyến tính từ một thành phần này sang thành phần khác của hàm mục tiêu.&lt;/p&gt;

&lt;p&gt;Xét bài toán sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) + g(Ax)\]
&lt;/blockquote&gt;

&lt;p&gt;Ta viết lại bài toán ở dạng tương đương bằng cách đặt \(z = Ax\):&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x,z} f(x) + g(z) \text{ với điều kiện } Ax = z\]
&lt;/blockquote&gt;

&lt;p&gt;Từ đó tính hàm đối ngẫu Lagrange:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(g(u) = \min_{x,z} \left(f(x) + g(z) + u^T(z - Ax)\right)\)
\(\qquad  = -\max_{x} \left((A^T u)^T x - f(x)\right) - \max_{z} \left((-u)^T z - g(z)\right)\)
\(\qquad = -f^* (A^T u) - g^* (-u)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vậy bài toán đối ngẫu là:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_u -f^*(A^Tu) - g^*(-u)\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h4&gt;

&lt;p&gt;Với một chuẩn \(\| \cdot \|\) và chuẩn đối ngẫu tương ứng \(\| \cdot \|_{*}\), xét cặp bài toán:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) + \| Ax \|\]

\[\max_u -f^*(A^Tu) \text{ với điều kiện } \| u \|_{*} \leq 1\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán thứ nhất là bài toán nguyên thủy, còn bài toán thứ hai là bài toán đối ngẫu tương ứng, trong đó ma trận \(A\) đã được chuyển sang tác động lên đối số của \(f^*\) dưới dạng \(A^T u\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-04-02 Hàm liên hợp và bài toán đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_04_02_Conjugates_and_dual_problems/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_04_02_Conjugates_and_dual_problems</id>
   <content type="html">&lt;p&gt;Nếu từng phải tính hàm đối ngẫu bằng tay nhiều lần, bạn sẽ nhận ra một mô-típ lặp đi lặp lại đến kỳ lạ: gần như lần nào ta cũng viết ra biểu thức \(\min_x (f(x) - u^T x)\), và lần nào nó cũng biến thành \(-f^*(u)\). Đây không phải sự trùng hợp ngẫu nhiên, mà là cấu trúc cốt lõi nối liền &lt;strong&gt;đối ngẫu Lagrange&lt;/strong&gt; với &lt;strong&gt;đối ngẫu Fenchel&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Thay vì mỗi lần gặp bài toán tổng hai hàm \(\min_x f(x) + g(x)\) lại phải đạo hàm từng bước dài dòng, hàm liên hợp cho ta một “công thức rút gọn siêu tốc”: tách biến \(x = z\), đưa nhân tử \(u\) vào, và chỉ sau hai dòng đại số, bài toán đối ngẫu hiện ra cực kỳ đối xứng: \(\max_u -f^*(u) - g^*(-u)\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-chiếc-cầu-giữa-hàm-liên-hợp-và-bài-toán-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Chiếc cầu giữa hàm liên hợp và bài toán đối ngẫu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đồng nhất thức nền tảng:&lt;/strong&gt; \(\min_x \{f(x) - u^T x\} = -\max_x \{u^T x - f(x)\} = -f^*(u)\). Bất cứ khi nào hàm mục tiêu cộng thêm một số hạng tuyến tính, cực tiểu hóa nó chính là tính âm của hàm liên hợp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tách biến cho tổng hai hàm:&lt;/strong&gt; Bài toán \(\min_x f(x) + g(x)\) được viết thành \(\min_{x=z} f(x) + g(z)\). Nhân tử đối ngẫu \(u\) buộc hai biến \(x, z\) có cùng độ dốc ngược dấu (\(u\) và \(-u\)), dẫn thẳng tới bài toán đối ngẫu Fenchel \(\max_u -f^*(u) - g^*(-u)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mở rộng cho các hàm phạt chuẩn và hàm chỉ thị:&lt;/strong&gt; Khi \(g(x)\) là hàm chỉ thị \(I_C(x)\) của một tập lồi \(C\), liên hợp \(g^*(v)\) chính là &lt;strong&gt;hàm tựa (support function)&lt;/strong&gt; \(\max_{x \in C} v^T x\); khi \(g(x) = \|x\|\), liên hợp là hàm chỉ thị của quả cầu chuẩn đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-suy-dẫn-đối-ngẫu-tức-thì-cho-bài-toán-tổng-hai-hàm-1-chiều&quot;&gt;Giải thích: Suy dẫn đối ngẫu tức thì cho bài toán tổng hai hàm 1 chiều&lt;/h3&gt;

&lt;p&gt;Xét bài toán không ràng buộc:&lt;/p&gt;

\[\min_{x \in \mathbb{R}} \underbrace{\frac{1}{2}(x - 3)^2}_{f(x)} + \underbrace{2\vert x \vert}_{g(x)}.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính nhanh hai hàm liên hợp:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(f(x) = \frac{1}{2}(x - 3)^2\): cực đại của \(ux - \frac{1}{2}(x-3)^2\) đạt tại \(x - 3 = u \implies x = u + 3\). Thay vào ta được:
\(f^*(u) = u(u+3) - \frac{1}{2}u^2 = \frac{1}{2}u^2 + 3u.\)&lt;/li&gt;
      &lt;li&gt;Với \(g(x) = 2\vert x \vert\): tương tự hàm giá trị tuyệt đối có hệ số \(2\), ta có \(g^*(w) = 0\) nếu \(\vert w \vert \le 2\) và \(+\infty\) nếu \(\vert w \vert &amp;gt; 2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng công thức đối ngẫu \(\max_u -f^*(u) - g^*(-u)\):&lt;/strong&gt;
Điều kiện \(g^*(-u) &amp;lt; \infty\) tương đương \(\vert -u \vert \le 2 \iff -2 \le u \le 2\). Bài toán đối ngẫu trở thành:
\(\max_{-2 \le u \le 2} \left(-\frac{1}{2}u^2 - 3u\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán đối ngẫu:&lt;/strong&gt; Parabol \(-\frac{1}{2}u^2 - 3u\) có đỉnh tự do tại \(u = -3\), nằm ngoài đoạn \([-2, 2]\), nên trên \([-2, 2]\) nó đạt cực đại tại biên trái \(u^\star = -2\).
    &lt;ul&gt;
      &lt;li&gt;Giá trị đối ngẫu tối ưu: \(-\frac{1}{2}(-2)^2 - 3(-2) = -2 + 6 = 4\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khôi phục nghiệm nguyên thủy:&lt;/strong&gt; Từ điều kiện đạt cực đại trong \(f^*(u^\star)\), ta có \(x^\star = u^\star + 3 = -2 + 3 = 1\).
    &lt;ul&gt;
      &lt;li&gt;Kiểm tra giá trị nguyên thủy: \(f(1) + g(1) = \frac{1}{2}(1-3)^2 + 2\vert 1\vert = 2 + 2 = 4\) — khớp tuyệt đối!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Hàm liên hợp thường xuất hiện trực tiếp khi suy dẫn bài toán đối ngẫu từ bài toán cực tiểu hóa hàm Lagrangian, thông qua hệ thức:&lt;/p&gt;

&lt;blockquote&gt;
\[-f^{*}(u) = \min_x (f(x) - u^Tx)\]
&lt;/blockquote&gt;

&lt;p&gt;Chẳng hạn, xét bài toán tổng hai hàm không ràng buộc:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x  f(x) + g(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Ta đưa thêm biến phụ và ràng buộc đẳng thức để viết lại bài toán tương đương:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x,z} f(x) + g(z) \text{ với điều kiện } x = z\]
&lt;/blockquote&gt;

&lt;p&gt;Hàm đối ngẫu Lagrange tương ứng là:&lt;/p&gt;

&lt;blockquote&gt;
\[g(u) = \min_{x,z} \left(f(x) + g(z) + u^T(z - x)\right) = -f^{*}(u) - g^{*}(-u)\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó, bài toán đối ngẫu của bài toán gốc là:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_u -f^{*}(u) - g^{*}(-u)\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chỉ thị:&lt;/strong&gt; Đối ngẫu của \(\min_x f(x) + I_C(x)\) là:
    &lt;blockquote&gt;
\[\max_u -f^{*}(u) - I^{*}_C(-u)\]

      &lt;p&gt;trong đó \(I^{*}_C\) là hàm hỗ trợ của tập \(C\).&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chuẩn:&lt;/strong&gt; Đối ngẫu của \(\min_x f(x) + \lVert x \rVert\) là:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\max_u -f^{*}(u) \text{ với điều kiện } \lVert u \rVert_{*} \le 1\), trong đó \(\lVert \cdot \rVert_{*}\) là chuẩn đối ngẫu của \(\lVert \cdot \rVert\).&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>13-04-01 Ví dụ đối ngẫu lasso</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_04_01_Example_lasso_dual/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_04_01_Example_lasso_dual</id>
   <content type="html">&lt;p&gt;Nếu bạn áp dụng máy móc công thức hàm Lagrange cho bài toán Lasso \(\min_\beta \frac{1}{2}\|y - X\beta\|_2^2 + \lambda \|\beta\|_1\), bạn sẽ lập tức gặp một bất ngờ dở khóc dở cười: vì bài toán gốc &lt;strong&gt;không có ràng buộc nào cả&lt;/strong&gt;, hàm đối ngẫu chỉ là một hằng số bằng đúng \(f^\star\) — hoàn toàn vô dụng!&lt;/p&gt;

&lt;p&gt;Bí quyết của các chuyên gia tối ưu nằm ở một bước “tách biến nghệ thuật”: đặt biến phụ \(z = X\beta\) để tách rời phần bình phương sai số khỏi phần phạt \(\ell_1\). Chỉ cần một phương trình ràng buộc nhân tạo đó thôi, bài toán đối ngẫu của Lasso lập tức hiện ra với vẻ đẹp hình học kinh ngạc: &lt;strong&gt;tìm hình chiếu Euclid của vectơ dữ liệu \(y\) lên một khối đa diện lồi \(\{u : \|X^T u\|_\infty \le \lambda\}\)&lt;/strong&gt;. Từ đây, ta không chỉ hiểu sâu cấu trúc hình học của Lasso mà còn mở ra các kỹ thuật sàng lọc biến (safe screening) loại bỏ hàng nghìn đặc trưng thừa ngay trước khi giải.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-lasso-nguyên-thủy-sang-bài-toán-chiếu-hình-học-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Từ Lasso nguyên thủy sang bài toán chiếu hình học đối ngẫu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kỹ thuật đưa biến phụ (Variable Splitting):&lt;/strong&gt; Khi bài toán không ràng buộc gồm tổng hai hàm có cấu trúc khác nhau, đặt \(z = X\beta\) tạo ra ràng buộc đẳng thức để tách phép lấy cực tiểu thành hai bài toán con dễ giải đóng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hợp của hàm bình phương và chuẩn \(\ell_1\):&lt;/strong&gt; Phần \(\frac{1}{2}\|y - z\|_2^2\) sinh ra dạng bậc hai \(\frac{1}{2}\|y - u\|_2^2\) trên biến đối ngẫu \(u\), còn phần \(\lambda \|\beta\|_1\) biến thành điều kiện ràng buộc hộp \(\|X^T u\|_\infty \le \lambda\) (chính là quả cầu chuẩn đối ngẫu \(\ell_\infty\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan hệ nguyên thủy – đối ngẫu (KKT):&lt;/strong&gt; Tại nghiệm tối ưu, phần dư \(r^\star = y - X\beta^\star\) trùng đúng với nghiệm đối ngẫu \(u^\star\) (hoặc tỷ lệ trực tiếp tùy quy ước dấu), cho thấy mọi đặc trưng không được chọn (\(\beta_j^\star = 0\)) đều có tương quan chặt \(\vert X_j^T u^\star \vert &amp;lt; \lambda\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-đối-ngẫu-lasso-trên-một-ví-dụ-2-đặc-trưng&quot;&gt;Giải thích: Tính tay đối ngẫu Lasso trên một ví dụ 2 đặc trưng&lt;/h3&gt;

&lt;p&gt;Xét bài toán Lasso với \(n = 2, p = 2\), ma trận thiết kế đơn giản \(X = I_2\) (hai cột trực chuẩn), dữ liệu \(y = (3, 0.5)^T\) và tham số phạt \(\lambda = 1\):&lt;/p&gt;

\[\min_{\beta \in \mathbb{R}^2} \frac{1}{2}\bigl((3 - \beta_1)^2 + (0.5 - \beta_2)^2\bigr) + (\vert \beta_1 \vert + \vert \beta_2 \vert).\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán đối ngẫu (chiếu \(y\) lên khối hộp \(\|X^T u\|_\infty \le 1\)):&lt;/strong&gt;
Vì \(X = I_2\), bài toán đối ngẫu tương đương với:
\(\min_{u \in \mathbb{R}^2} \frac{1}{2}\|y - u\|_2^2 \qquad \text{với } \vert u_1 \vert \le 1, \;\; \vert u_2 \vert \le 1.\)
Chiếu từng tọa độ của \(y = (3, 0.5)^T\) lên đoạn \([-1, 1]\) ta nhận ngay:
\(u_1^\star = \operatorname{clip}(3, -1, 1) = 1, \qquad u_2^\star = \operatorname{clip}(0.5, -1, 1) = 0.5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khôi phục nghiệm nguyên thủy Lasso từ \(u^\star\):&lt;/strong&gt;
Từ điều kiện \(X\beta^\star = y - u^\star\) (khi \(X = I_2\)), ta có ngay nghiệm thưa:
\(\beta_1^\star = 3 - 1 = 2, \qquad \beta_2^\star = 0.5 - 0.5 = 0.\)
(Khớp hoàn toàn với công thức ngưỡng mềm &lt;em&gt;soft-thresholding&lt;/em&gt;!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra đối ngẫu mạnh:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giá trị nguyên thủy: \(f(\beta^\star) = \frac{1}{2}\bigl((3-2)^2 + (0.5-0)^2\bigr) + (\vert 2\vert + 0) = \frac{1}{2}(1 + 0.25) + 2 = 2.625\).&lt;/li&gt;
      &lt;li&gt;Giá trị đối ngẫu: \(\frac{1}{2}\|y\|_2^2 - \frac{1}{2}\|y - u^\star\|_2^2 = \frac{1}{2}(9.25) - \frac{1}{2}(4 + 0) = 4.625 - 2 = 2.625\).
Khoảng cách đối ngẫu bằng đúng \(0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Xét bài toán lasso với \(y \in \mathbb{R}^n\) và \(X \in \mathbb{R}^{n\times p}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\min_\beta \frac{1}{2} \| y-X\beta \|^2_2 + \lambda\| \beta \|_1\]

\[f(\beta) = \frac{1}{2} \| y - X\beta \|^2_2 +  \lambda\| \beta \|_1\]

\[L(\beta) = f(\beta)\]

\[\min_\beta L(\beta) = f^{\star}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì bài toán gốc không có ràng buộc nên hàm đối ngẫu chỉ là hằng số bằng \(f^{\star}\). Để xây dựng bài toán đối ngẫu hữu ích hơn, ta đưa thêm biến phụ \(z = X\beta\) và viết lại bài toán nguyên thủy tương đương:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{\beta,z} \frac{1}{2} \| y-z \|^2_2 + \lambda \| \beta \|_1 \text{ với điều kiện } z = X\beta\]
&lt;/blockquote&gt;

&lt;p&gt;Hàm đối ngẫu Lagrange của bài toán đã biến đổi là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
g(u) &amp;amp;= \min_{\beta,z} \frac{1}{2} \| y-z \|^2_2 + \lambda \| \beta \|_1 + u^T(z-X\beta) \\
&amp;amp;= \frac{1}{2} \| y \|^2_2 - \frac{1}{2} \| y-u \|^2_2 - I_{\{ v : \| v \|_\infty \leq 1 \}}(X^Tu/\lambda) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h4&gt;
&lt;blockquote&gt;
\[\begin{align}
g(u) &amp;amp;= \min_{\beta,z} \frac{1}{2} \| y-z \|^2_2 + \lambda \| \beta \|_1 + u^T(z-X\beta) \\
&amp;amp;= \underbrace{ \left( \min_z \frac{1}{2} \| y - z \|^2_2 + u^Tz \right)}_{(1)} + \underbrace{\left( \min_\beta \left(\lambda \| \beta \|_1 - u^TX\beta\right) \right)}_{(2)} \\
\end{align}\]

  &lt;p&gt;Ở phần (1), lấy đạo hàm theo \(z\) bằng \(0\) cho \(z^{\star} = y - u\), nên:&lt;/p&gt;

\[\begin{align}
(1) \cdots \left( \min_z \frac{1}{2} \| y - z \|^2_2 + u^Tz \right)
&amp;amp;= \frac{1}{2} \| u \|^2_2 + u^T(y - u) \\
&amp;amp;= -\frac{1}{2} \| y - u \|^2_2 + \frac{1}{2} \| y \|^2_2 \\
\end{align}\]

  &lt;p&gt;Ở phần (2), dùng hàm liên hợp của chuẩn \(\ell_1\):&lt;/p&gt;

\[\begin{align}
(2) \cdots \left( \min_\beta \left(\lambda \| \beta \|_1 - u^TX\beta\right) \right) 
&amp;amp;= - \lambda \max_\beta \left( \left(\frac{X^Tu}{\lambda}\right)^T \beta - \| \beta \|_1 \right) \\
&amp;amp;= - I_{\{ v : \| v \|_\infty \leq 1 \}}(X^Tu/\lambda) \\
&amp;amp;= - I_{\{ w : \| w \|_\infty \leq \lambda \}}(X^Tu) \\
\end{align}\]

  &lt;p&gt;Suy ra:&lt;/p&gt;

\[g(u) = \frac{1}{2} \| y \|^2_2 - \frac{1}{2} \| y-u \|^2_2 - I_{\{ v : \| v \|_\infty \leq 1 \}}(X^Tu/\lambda)\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó, bài toán đối ngẫu của lasso là:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_u \frac{1}{2} ( \| y \|^2_2 - \| y-u \|^2_2 ) \text{ với điều kiện } \| X^Tu \|_\infty \leq \lambda\]
&lt;/blockquote&gt;

&lt;p&gt;Bỏ hằng số \(\frac{1}{2}\|y\|_2^2\) và đổi dấu, bài toán đối ngẫu tương đương với bài toán chiếu Euclidean lên đa diện:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_u \| y-u \|^2_2 \text{ với điều kiện } \| X^Tu \|_\infty \leq \lambda\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;kiểm-tra-tính-đối-ngẫu-mạnh&quot;&gt;Kiểm tra tính đối ngẫu mạnh&lt;/h3&gt;

&lt;p&gt;Bài toán nguyên thủy là bài toán lồi chỉ có ràng buộc đẳng thức tuyến tính nên thỏa mãn điều kiện Slater; do đó tính đối ngẫu mạnh được đảm bảo:&lt;/p&gt;

&lt;blockquote&gt;
\[\text{Đối ngẫu mạnh } \implies (\beta^{\star}, z^{\star}) \text{ phải cực tiểu hóa } L( \beta, z, u^{\star} ) \text{ theo } \beta, z\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;lưu-ý&quot;&gt;Lưu ý&lt;/h3&gt;

&lt;p&gt;Giá trị tối ưu của bài toán rút gọn \(\min_u \|y - u\|_2^2\) không bằng giá trị mục tiêu tối ưu của bài toán lasso gốc (vì đã bỏ hằng số và hệ số \(\frac{1}{2}\)). Tuy nhiên, nghiệm đối ngẫu \(u^{\star}\) và nghiệm lasso \(\beta^{\star}\) liên hệ trực tiếp qua đẳng thức \(X\beta^{\star} = y - u^{\star}\).&lt;/p&gt;

&lt;p&gt;Hệ thức này suy ra từ điều kiện dừng KKT theo \(z\) là \(z - y + u = 0\) kết hợp với ràng buộc \(z = X\beta\). Do đó, nghiệm đối ngẫu \(u^{\star}\) chính là phần dư \(y - X\beta^{\star}\) của bài toán lasso.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter13/Conjugate_LassoDual_Example.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Đối ngẫu của bài toán Lasso [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;đối-ngẫu-của-lasso-nhìn-như-một-phép-chiếu-video&quot;&gt;Đối ngẫu của lasso nhìn như một phép chiếu (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/lasso-dual_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Bài toán đối ngẫu tìm \(u\) thỏa \(\|A^Tu\|_\infty\le\lambda\). Các tọa độ mà ràng buộc này chạm biên (đạt dấu bằng) tương ứng với các thành phần có thể khác \(0\) của nghiệm bài toán gốc.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-lasso-gốc-và-đối-ngẫu&quot;&gt;Tự tay thử: lasso gốc và đối ngẫu&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;ld&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>13-03 Chuẩn đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_03_Dual_norms/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_03_Dual_norms</id>
   <content type="html">&lt;p&gt;Khi đo khoảng cách hay kiểm soát độ lớn của một vectơ tham số \(x\), không phải lúc nào thước đo Euclid \(\|x\|_2\) cũng là lựa chọn duy nhất. Trong học máy thống kê, chuẩn \(\ell_1\) khuyến khích nghiệm thưa, chuẩn \(\ell_\infty\) giới hạn sai số tệ nhất trên từng tọa độ, còn chuẩn vết (nuclear norm) ép ma trận có hạng thấp.&lt;/p&gt;

&lt;p&gt;Nhưng điều kỳ diệu thực sự xảy ra khi các chuẩn này đi vào bài toán đối ngẫu: &lt;strong&gt;mỗi chuẩn \(\|\cdot\|\) đều có một “người bạn đồng hành” gọi là chuẩn đối ngẫu \(\|\cdot\|_*\)&lt;/strong&gt;. Chuẩn đối ngẫu đo mức tương quan lớn nhất mà một vectơ \(y\) có thể đạt được với mọi vectơ \(x\) nằm trong quả cầu đơn vị \(\|x\| \le 1\). Sự ghép cặp hình học giữa hình thoi \(\ell_1\) và hình vuông \(\ell_\infty\) chính là nguồn gốc của hàng loạt bất đẳng thức nền tảng từ Cauchy–Schwarz, Hölder đến điều kiện dừng của Lasso.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-của-chuẩn-và-chuẩn-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Hình học của chuẩn và chuẩn đối ngẫu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa tối ưu của chuẩn đối ngẫu:&lt;/strong&gt; \(\|y\|_* = \max_{\|x\| \le 1} y^T x\). Về mặt hình học, ta trượt siêu phẳng \(y^T x = c\) xa gốc tọa độ nhất có thể sao cho vẫn chạm vào quả cầu đơn vị của chuẩn \(\|\cdot\|\); giá trị cực đại \(c\) chính là \(\|y\|_*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Hölder tổng quát:&lt;/strong&gt; Từ định nghĩa, ta có ngay \(y^T x \le \|x\| \cdot \|y\|_*\) với mọi \(x, y\). Đây là phiên bản tổng quát của bất đẳng thức Cauchy–Schwarz cho mọi cặp chuẩn đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các cặp chuẩn đối ngẫu kinh điển:&lt;/strong&gt; Với \(p, q \ge 1\) thỏa \(\frac{1}{p} + \frac{1}{q} = 1\), chuẩn đối ngẫu của \(\ell_p\) là \(\ell_q\). Đặc biệt: \(\ell_2\) tự đối ngẫu; \(\ell_1\) và \(\ell_\infty\) đối ngẫu với nhau; trên không gian ma trận, chuẩn vết (tổng giá trị kỳ dị) và chuẩn phổ (giá trị kỳ dị lớn nhất) là một cặp đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính đối ngẫu kép của chuẩn:&lt;/strong&gt; Trên \(\mathbb{R}^n\), chuẩn đối ngẫu của chuẩn đối ngẫu luôn quay về đúng chuẩn ban đầu: \(\|\cdot\|_{**} = \|\cdot\|\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-chuẩn-đối-ngẫu-của-ell_1-ell_2-và-ell_infty-trên-cùng-một-vectơ&quot;&gt;Giải thích: Tính tay chuẩn đối ngẫu của \(\ell_1\), \(\ell_2\) và \(\ell_\infty\) trên cùng một vectơ&lt;/h3&gt;

&lt;p&gt;Xét vectơ cụ thể \(y = (3, -4)^T \in \mathbb{R}^2\). Ta sẽ tính trực tiếp \(\max_{\|x\| \le 1} (3x_1 - 4x_2)\) dưới ba chuẩn khác nhau để thấy rõ cực đại đạt tại đâu:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn gốc là \(\ell_1\) (quả cầu là hình thoi \(\vert x_1 \vert + \vert x_2 \vert \le 1\)):&lt;/strong&gt;
Ta có \(3x_1 - 4x_2 \le 3\vert x_1 \vert + 4\vert x_2 \vert \le 4(\vert x_1 \vert + \vert x_2 \vert) \le 4\).
Dấu bằng đạt tại đỉnh \(x = (0, -1)^T\) (có \(\|x\|_1 = 1\)), cho \(y^T x = 4 = \max(\vert 3\vert, \vert -4\vert) = \|y\|_\infty\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn gốc là \(\ell_\infty\) (quả cầu là hình vuông \(\max(\vert x_1 \vert, \vert x_2 \vert) \le 1\)):&lt;/strong&gt;
Mỗi tọa độ được chọn độc lập trong \([-1, 1]\). Để tối đa hóa \(3x_1 - 4x_2\), ta chọn góc \(x = (1, -1)^T\).
Khi đó \(y^T x = 3(1) - 4(-1) = 7 = \vert 3 \vert + \vert -4 \vert = \|y\|_1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn gốc là \(\ell_2\) (quả cầu là đĩa tròn \(x_1^2 + x_2^2 \le 1\)):&lt;/strong&gt;
Theo Cauchy–Schwarz, cực đại đạt khi \(x\) cùng hướng với \(y\): \(x = \frac{y}{\|y\|_2} = \left(\frac{3}{5}, -\frac{4}{5}\right)^T\).
Khi đó \(y^T x = \frac{9}{5} + \frac{16}{5} = 5 = \sqrt{3^2 + (-4)^2} = \|y\|_2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Xét một &lt;strong&gt;chuẩn&lt;/strong&gt; tùy ý \(\| x \|\), chẳng hạn:&lt;/p&gt;

&lt;blockquote&gt;
\[\text{Chuẩn } \ell_p\text{: } \lVert x \rVert_p = \left(\sum^n_{i=1} \lvert x_i \rvert^p\right)^{1/p}, \text{ với } p \ge 1\]

\[\text{Chuẩn vết (trace norm): } \lVert X \rVert_{tr} = \sum^r_{i=1} \sigma_i(X)\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Chuẩn đối ngẫu&lt;/strong&gt; của chuẩn \(\lVert x \rVert\) được ký hiệu là \(\lVert x \rVert_{*}\) và định nghĩa như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\lVert x \rVert_{*} = \max_{\lVert z \rVert \le 1} z^Tx\]
&lt;/blockquote&gt;

&lt;p&gt;Với mọi vector \(y \neq 0\), đặt \(z = \frac{y}{\lVert y \rVert}\) thì \(\lVert z \rVert = 1\). Khi đó \(\lvert z^Tx \rvert \le \lVert x \rVert_{*}\), từ đó suy ra bất đẳng thức tổng quát của &lt;em&gt;bất đẳng thức Cauchy–Schwarz&lt;/em&gt;: \(\lvert y^Tx \rvert \le \lVert y \rVert \lVert x \rVert_{*}\) (hiển nhiên cũng đúng khi \(y = 0\)).&lt;/p&gt;

&lt;p&gt;Một số ví dụ quan trọng về chuẩn đối ngẫu:&lt;/p&gt;

&lt;blockquote&gt;
\[\text{Chuẩn đối ngẫu của chuẩn } \ell_p\text{: } (\lVert x \rVert_p)_{*} = \lVert x \rVert_{q}, \text{ trong đó } \frac{1}{p} + \frac{1}{q} = 1\]

\[\text{Chuẩn đối ngẫu của chuẩn vết: } (\lVert X \rVert_{tr})_{*} = \lVert X \rVert_{op} = \sigma_1(X)\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h4&gt;

&lt;blockquote&gt;
  &lt;p&gt;Ta chứng minh đẳng thức sau cho chuẩn đối ngẫu của chuẩn \(\ell_q\) (với \(p, q \in (1, \infty)\) thỏa \(\frac{1}{p} + \frac{1}{q} = 1\); các trường hợp biên \(p=1, q=\infty\) và ngược lại được kiểm chứng tương tự):&lt;/p&gt;

\[(\lVert z \rVert_q)_{*} = \lVert z \rVert_{p}, \text{ trong đó } \frac{1}{p} + \frac{1}{q} = 1 \qquad \text{(1)}\]

  &lt;p&gt;Theo định nghĩa chuẩn đối ngẫu:&lt;/p&gt;

\[(\lVert z \rVert_q)_{*} = \sup \{ z^Tx : x \in \mathbb{R}^n, \lVert x \rVert_q \le 1 \} \qquad \text{(2)}\]

  &lt;p&gt;Theo bất đẳng thức Hölder, với mọi \(x\) thỏa \(\lVert x \rVert_q \le 1\) ta có:&lt;/p&gt;

\[z^T x \le \lvert z^T x \rvert \le \lVert z \rVert_p \lVert x \rVert_q \le \lVert z \rVert_p \qquad \text{(3)}\]

  &lt;p&gt;Từ (2) và (3) suy ra:&lt;/p&gt;

\[(\lVert z \rVert_q)_{*} \le \lVert z \rVert_p \qquad \text{(4)}\]

  &lt;p&gt;Để chứng minh dấu bằng xảy ra (với \(z \neq 0\); trường hợp \(z = 0\) hiển nhiên), ta cần tìm \(x\) sao cho \(\lVert x \rVert_q \le 1\) và \(z^Tx = \lVert z \rVert_p\).&lt;/p&gt;

  &lt;p&gt;Đặt \(y \in \mathbb{R}^n\) với \(y_i = \text{sign}(z_i)\lvert z_i \rvert^{p-1}\) và chuẩn hóa \(x = \frac{y}{\lVert y \rVert_q}\). Vì \((p-1)q = p\) nên \(\lVert y \rVert_q = \left(\sum_{i=1}^n \lvert z_i \rvert^p\right)^{1/q} = \lVert z \rVert_p^{p-1}\), suy ra \(\lVert x \rVert_q = 1\) và \(z^T x = \frac{\sum_{i=1}^n \lvert z_i \rvert^p}{\lVert z \rVert_p^{p-1}} = \lVert z \rVert_p\).&lt;/p&gt;

  &lt;p&gt;Do đó:&lt;/p&gt;

\[(\lVert z \rVert_q)_{*} = \lVert z \rVert_p, \quad \left(\frac{1}{p} + \frac{1}{q} = 1\right) \qquad \text{(5)}\]
&lt;/blockquote&gt;

&lt;p&gt;Chuẩn đối ngẫu của chuẩn đối ngẫu chính là chuẩn ban đầu:&lt;/p&gt;

&lt;blockquote&gt;
\[\lVert x \rVert_{**} = \lVert x \rVert\]
&lt;/blockquote&gt;

&lt;p&gt;Để thấy điều này, xét bài toán tối ưu sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_y \lVert y \rVert \qquad \text{ với điều kiện } y = x\]
&lt;/blockquote&gt;

&lt;p&gt;Giá trị tối ưu của bài toán là \(\lVert x \rVert\), và hàm Lagrangian tương ứng là:&lt;/p&gt;

&lt;blockquote&gt;
\[L(y,u) = \lVert y \rVert + u^T(x - y) = \lVert y \rVert - y^Tu + x^Tu\]
&lt;/blockquote&gt;

&lt;p&gt;Khi lấy cực tiểu theo \(y\), ta biểu diễn được kết quả theo chuẩn đối ngẫu \(\lVert \cdot \rVert_{*}\) như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\text{Nếu } \lVert u \rVert_{*} \le 1, \text{ thì } \qquad \min_y \{ \lVert y \rVert - y^Tu \} = 0\]

\[\text{Nếu } \lVert u \rVert_{*} &amp;gt; 1, \text{ thì } \qquad \min_y \{ \lVert y \rVert - y^Tu \} = -\infty\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;giải-thích-chi-tiết&quot;&gt;Giải thích chi tiết&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;Nếu \(\lVert u \rVert_{*} \le 1\), ta có \(y^T u \le \lVert y \rVert \lVert u \rVert_{*} \le \lVert y \rVert\) với mọi \(y\), tức \(\lVert y \rVert - y^T u \ge 0\) và dấu bằng đạt tại \(y = 0\). Do đó:&lt;/li&gt;
  &lt;/ul&gt;

\[\min_y \{ \lVert y \rVert - y^Tu \} = 0 \iff \max_y (y^Tu - \lVert y \rVert) = 0\]

  &lt;ul&gt;
    &lt;li&gt;Nếu \(\lVert u \rVert_{*} &amp;gt; 1\), luôn tồn tại \(z\) với \(\lVert z \rVert = 1\) sao cho \(z^Tu = \lVert u \rVert_{*}\) (tức \(z \in \arg\max_{\lVert z \rVert \le 1} z^Tu\)). Chọn \(y = t \cdot z\) với \(t &amp;gt; 0\), khi đó \(y^Tu = t \cdot \lVert u \rVert_{*}\) và:&lt;/li&gt;
  &lt;/ul&gt;

\[y^Tu - \lVert y \rVert = t (\lVert u \rVert_{*} - 1) \rightarrow +\infty \text{ khi } t \rightarrow +\infty\]

  &lt;p&gt;suy ra \(\min_y \{ \lVert y \rVert - y^Tu \} = -\infty\).&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Từ đó, hàm đối ngẫu là:&lt;/li&gt;
  &lt;/ul&gt;

\[g(u) = \min_y L(y, u) = x^Tu - I_{\{\lVert u \rVert_{*} \le 1\}}(u)\]

  &lt;p&gt;nên bài toán đối ngẫu có dạng:&lt;/p&gt;

\[\max_u g(u) \iff \max_{\lVert u \rVert_{*} \le 1} x^Tu\]
&lt;/blockquote&gt;

&lt;p&gt;Như vậy, bài toán đối ngẫu Lagrange là:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_u u^Tx \qquad \text{ với điều kiện }\qquad \lVert u \rVert_{*} \le 1\]
&lt;/blockquote&gt;

&lt;p&gt;Vì bài toán nguyên thủy là bài toán lồi chỉ có ràng buộc đẳng thức tuyến tính nên thỏa mãn điều kiện Slater; theo tính đối ngẫu mạnh, ta có \(f^{\star} = g^{\star}\), hay \(\lVert x \rVert = \lVert x \rVert_{**}\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-02 Giải bài toán nguyên thủy thông qua đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_02_Solving_the_primal_via_the_dual/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_02_Solving_the_primal_via_the_dual</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng bạn phải phân bổ ngân sách cho \(n = 10{,}000\) chiến dịch quảng cáo khác nhau sao cho tổng chi phí đúng bằng một hạn mức \(b\) cố định, đồng thời cực tiểu hóa tổng hàm tổn thất riêng \(f_i(x_i)\) của từng chiến dịch. Nếu giải trực tiếp trong không gian nguyên thủy, bạn phải điều phối đồng thời \(10{,}000\) biến bị trói chặt vào nhau bởi phương trình \(\sum a_i x_i = b\).&lt;/p&gt;

&lt;p&gt;Thế nhưng, khi bước sang không gian đối ngẫu, toàn bộ \(10{,}000\) biến nguyên thủy đột ngột biến mất, chỉ còn lại &lt;strong&gt;đúng một biến vô hướng \(v\)&lt;/strong&gt; — đóng vai trò như “giá bóng” của một đồng ngân sách! Một khi tìm được mức giá cân bằng \(v^\star\) bằng tìm kiếm nhị phân hay phương pháp Newton 1 chiều, từng chiến dịch \(i\) chỉ việc tự tối ưu độc lập theo công thức đóng. Đó chính là sức mạnh tách biến kinh điển của việc giải bài toán nguyên thủy thông qua đối ngẫu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cơ-chế-khôi-phục-nghiệm-nguyên-thủy-từ-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Cơ chế khôi phục nghiệm nguyên thủy từ đối ngẫu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng KKT và đối ngẫu mạnh:&lt;/strong&gt; Khi đối ngẫu mạnh giữ vững, nghiệm nguyên thủy tối ưu \(x^\star\) bắt buộc phải là một điểm cực tiểu của hàm Lagrange \(L(x, u^\star, v^\star)\) tại nhân tử tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính duy nhất nhờ lồi chặt (Strict Convexity):&lt;/strong&gt; Cần hết sức cẩn thận: nếu \(L(x, u^\star, v^\star)\) có nhiều điểm cực tiểu (ví dụ khi \(f\) tuyến tính từng khúc), một điểm cực tiểu tùy ý có thể còn không khả thi cho bài toán gốc! Nhưng khi \(f\) &lt;strong&gt;lồi chặt&lt;/strong&gt;, điểm cực tiểu của \(L(x, u^\star, v^\star)\) là duy nhất nên chắc chắn trùng khít với \(x^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc tách biến (Separability):&lt;/strong&gt; Khi hàm mục tiêu là tổng \(\sum_{i=1}^n f_i(x_i)\) và chỉ có ít ràng buộc ghép chung, phép lấy cực tiểu theo \(x\) tự động rã thành \(n\) bài toán 1 chiều độc lập, liên kết với nhau qua hàm liên hợp \(f_i^*\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-bài-toán-phân-bổ-3-biến-qua-đối-ngẫu-1-chiều&quot;&gt;Giải thích: Giải bài toán phân bổ 3 biến qua đối ngẫu 1 chiều&lt;/h3&gt;

&lt;p&gt;Xét bài toán tách biến 3 chiều:&lt;/p&gt;

\[\min_{x \in \mathbb{R}^3} \frac{1}{2}x_1^2 + x_2^2 + \frac{3}{2}x_3^2 \qquad \text{với điều kiện } x_1 + x_2 + x_3 = 11.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính hàm liên hợp của từng thành phần:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(f_1(x_1) = \frac{1}{2}x_1^2\): \(f_1&apos;(x_1) = x_1 = v \implies x_1 = v\) và \(f_1^*(v) = \frac{1}{2}v^2\).&lt;/li&gt;
      &lt;li&gt;Với \(f_2(x_2) = x_2^2\): \(f_2&apos;(x_2) = 2x_2 = v \implies x_2 = \frac{v}{2}\) và \(f_2^*(v) = \frac{1}{4}v^2\).&lt;/li&gt;
      &lt;li&gt;Với \(f_3(x_3) = \frac{3}{2}x_3^2\): \(f_3&apos;(x_3) = 3x_3 = v \implies x_3 = \frac{v}{3}\) và \(f_3^*(v) = \frac{1}{6}v^2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lập bài toán đối ngẫu 1 chiều theo \(v\):&lt;/strong&gt; Theo công thức \(g(v) = bv - \sum_{i=1}^3 f_i^*(a_i v)\) với \(b = 11, a_i = 1\):
\(g(v) = 11v - \left(\frac{1}{2} + \frac{1}{4} + \frac{1}{6}\right)v^2 = 11v - \frac{11}{12}v^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán đối ngẫu:&lt;/strong&gt; Lấy đạo hàm \(g&apos;(v) = 11 - \frac{11}{6}v = 0 \implies v^\star = 6\). Giá trị đối ngẫu tối ưu là \(g(6) = 66 - \frac{11}{12}(36) = 33\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khôi phục nghiệm nguyên thủy duy nhất (vì các \(f_i\) đều lồi chặt):&lt;/strong&gt;
\(x_1^\star = v^\star = 6, \qquad x_2^\star = \frac{v^\star}{2} = 3, \qquad x_3^\star = \frac{v^\star}{3} = 2.\)
Kiểm tra lại: tổng \(x_1^\star + x_2^\star + x_3^\star = 6 + 3 + 2 = 11\) (khả thi!) và \(f(x^\star) = \frac{1}{2}(36) + 9 + \frac{3}{2}(4) = 18 + 9 + 6 = 33 = g(v^\star)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;một-hệ-quả-quan-trọng-của-điều-kiện-dừng&quot;&gt;Một hệ quả quan trọng của điều kiện dừng&lt;/h3&gt;

&lt;p&gt;Khi tính đối ngẫu mạnh được thỏa mãn và ta đã tìm được nghiệm đối ngẫu tối ưu \((u^{\star}, v^{\star})\), nghiệm nguyên thủy tối ưu \(x^{\star}\) có thể được xác định bằng cách cực tiểu hóa hàm Lagrangian sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) + \sum_{i=1}^m u_i^{\star} h_i(x) + \sum_{j=1}^r v^{\star}_j l_j(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Trong nhiều trường hợp, bài toán không ràng buộc này cho phép biểu diễn tường minh đặc trưng của nghiệm nguyên thủy theo nghiệm đối ngẫu. Đặc biệt, nếu bài toán cực tiểu hóa Lagrangian trên có nghiệm duy nhất, thì nghiệm đó chính là nghiệm nguyên thủy tối ưu \(x^{\star}\). Cách tiếp cận này rất hữu ích khi bài toán đối ngẫu dễ giải hơn nhiều so với bài toán nguyên thủy.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-boyd--vandenberghe-trang-249&quot;&gt;Ví dụ (Boyd &amp;amp; Vandenberghe, trang 249)&lt;/h3&gt;

&lt;p&gt;Xét bài toán tách biến có một ràng buộc đẳng thức tuyến tính:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x \sum_{i=1}^n f_i(x_i) \qquad \text{ với điều kiện }\qquad a^Tx = b\]
&lt;/blockquote&gt;

&lt;p&gt;Hàm đối ngẫu Lagrange được tính như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
g(v) &amp;amp;= \min_x \sum_{i=1}^n f_i(x_i) + v(b−a^Tx) \\\
&amp;amp;= bv + \min_x \sum_{i=1}^n f_i(x_i) −va^Tx \\\
&amp;amp;= bv + \min_x \sum_{i=1}^n f_i(x_i) −v \sum_{i=1}^n a_ix_i \\\
&amp;amp;= bv + \sum_{i=1}^n (\underbrace{\min_{x_i} \{ f_i(x_i) − a_ivx_i \}}_{-f^{*}_i(a_iv)}) \\\
&amp;amp;= bv − \sum_{i=1}^n f^{*}_i (a_iv)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây \(f_i^{*}\) là hàm liên hợp của \(f_i\).&lt;/p&gt;

&lt;p&gt;Do đó, bài toán đối ngẫu là:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_v bv − \sum^n_{i=1} f^{*}_i (a_iv)\]
&lt;/blockquote&gt;

&lt;p&gt;Đổi dấu hàm mục tiêu để chuyển về dạng cực tiểu hóa, ta được:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_v \sum^n_{i=1} f^{*}_i (a_iv) − bv\]
&lt;/blockquote&gt;

&lt;p&gt;Đây là bài toán tối ưu hóa lồi chỉ theo một biến vô hướng \(v\), nên thường dễ giải hơn nhiều so với bài toán nguyên thủy có \(n\) biến.&lt;/p&gt;

&lt;p&gt;Sau khi tìm được \(v^{\star}\), nghiệm nguyên thủy \(x^{\star}\) được xác định từ:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} \sum^n_{i=1} (f_i(x_i) − a_iv^{\star}x_i)\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu mỗi hàm \(f_i\) lồi chặt, bài toán này có nghiệm duy nhất; khi các \(f_i\) khả vi, từng thành phần \(x_i^{\star}\) được tìm trực tiếp bằng cách giải phương trình \(\nabla f_i(x_i) = a_i v^{\star}\) với mỗi \(i\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-01 Ứng dụng của đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_01_Uses_of_duality/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter13/13_01_Uses_of_duality</id>
   <content type="html">&lt;p&gt;Trong thực tế chạy thuật toán tối ưu, câu hỏi khiến kỹ sư đau đầu nhất không phải lúc nào cũng là “làm sao đi bước tiếp theo”, mà là &lt;strong&gt;“khi nào thì đủ tốt để dừng lại?”&lt;/strong&gt;. Nếu chỉ nhìn vào độ lớn gradient hay sự thay đổi nhỏ giữa hai vòng lặp liên tiếp \(\|x^{(k+1)} - x^{(k)}\|\), bạn rất dễ bị đánh lừa bởi một thung lũng phẳng dài nơi thuật toán bò chậm nhưng vẫn còn cách đáy rất xa.&lt;/p&gt;

&lt;p&gt;Lý thuyết đối ngẫu giải quyết dứt điểm nỗi lo này bằng một cơ chế kiểm chứng toán học tuyệt đối: &lt;strong&gt;khoảng cách đối ngẫu (duality gap)&lt;/strong&gt;. Thay vì đoán mò mình còn cách nghiệm tối ưu \(f^\star\) bao xa, bạn xây dựng song song một điểm khả thi đối ngẫu \((u, v)\) để tạo ra một “sàn cứng” \(g(u, v) \le f^\star \le f(x)\). Khi trần và sàn khép sát nhau dưới ngưỡng \(\epsilon\), bạn có thể dừng máy với sự đảm bảo 100% về độ chính xác.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-vì-sao-đối-ngẫu-sinh-ra-tiêu-chí-dừng-và-đường-tắt-giải-toán&quot;&gt;Kiến thức cần nhớ: Vì sao đối ngẫu sinh ra tiêu chí dừng và đường tắt giải toán?&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính đối ngẫu yếu như một chặn dưới phổ quát:&lt;/strong&gt; Bất kể bài toán gốc có lồi hay không, với mọi điểm khả thi nguyên thủy \(x\) và mọi điểm khả thi đối ngẫu \((u, v)\), ta luôn có \(g(u, v) \le f^\star \le f(x)\). Vì vậy \(f(x) - g(u, v)\) luôn là chặn trên chắc chắn cho sai số thực \(f(x) - f^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu (Duality Gap) vs. Độ lệch tối ưu (Suboptimality):&lt;/strong&gt; Ta không bao giờ biết giá trị \(f^\star\) khi thuật toán đang chạy, nên không thể tính trực tiếp \(f(x) - f^\star\). Nhưng ta tính được cả \(f(x)\) lẫn \(g(u, v)\), biến một đại lượng ẩn thành tiêu chí dừng đo được trực tiếp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bắc cầu từ bài toán khó sang bài toán dễ:&lt;/strong&gt; Khi đối ngẫu mạnh thỏa mãn, việc giải bài toán đối ngẫu (thường có ít biến hơn hoặc cấu trúc ràng buộc đơn giản hơn) rồi khôi phục \(x^\star\) giúp giảm mạnh chi phí tính toán.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-khoảng-cách-đối-ngẫu-làm-tiêu-chí-dừng-bằng-tay&quot;&gt;Giải thích: Tính khoảng cách đối ngẫu làm tiêu chí dừng bằng tay&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch bậc hai đơn giản:&lt;/p&gt;

\[\min_{x \in \mathbb{R}^2} \frac{1}{2}(x_1^2 + x_2^2) \qquad \text{với điều kiện } x_1 + x_2 = 4.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tìm hàm đối ngẫu \(g(v)\):&lt;/strong&gt; Lập hàm Lagrange \(L(x, v) = \frac{1}{2}(x_1^2 + x_2^2) + v(4 - x_1 - x_2)\). Lấy đạo hàm theo \(x_1, x_2\) bằng \(0\) ta được \(x_1 = v, x_2 = v\). Thay lại vào \(L\) thu được:
\(g(v) = \frac{1}{2}(v^2 + v^2) + v(4 - 2v) = 4v - v^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh giá ở vòng lặp thứ nhất:&lt;/strong&gt; Giả sử thuật toán đang đứng tại điểm khả thi \(x^{(1)} = (3, 1)\) (thỏa \(3 + 1 = 4\)) và ước lượng đối ngẫu \(v^{(1)} = 1.5\).
    &lt;ul&gt;
      &lt;li&gt;Giá trị nguyên thủy: \(f(x^{(1)}) = \frac{1}{2}(9 + 1) = 5.0\).&lt;/li&gt;
      &lt;li&gt;Giá trị đối ngẫu: \(g(v^{(1)}) = 4(1.5) - (1.5)^2 = 6 - 2.25 = 3.75\).&lt;/li&gt;
      &lt;li&gt;Khoảng cách đối ngẫu: \(\Delta_1 = 5.0 - 3.75 = 1.25\). Ta chắc chắn \(f(x^{(1)}) - f^\star \le 1.25\) (thực tế \(f^\star = 4\), sai số thật là \(1.0 \le 1.25\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh giá ở vòng lặp sau:&lt;/strong&gt; Thuật toán tiến tới \(x^{(2)} = (2.1, 1.9)\) và \(v^{(2)} = 1.95\).
    &lt;ul&gt;
      &lt;li&gt;\(f(x^{(2)}) = \frac{1}{2}(4.41 + 3.61) = 4.01\).&lt;/li&gt;
      &lt;li&gt;\(g(v^{(2)}) = 4(1.95) - (1.95)^2 = 7.8 - 3.8025 = 3.9975\).&lt;/li&gt;
      &lt;li&gt;Khoảng cách đối ngẫu: \(\Delta_2 = 4.01 - 3.9975 = 0.0125\). Nếu ngưỡng dừng là \(\epsilon = 0.02\), thuật toán dừng ngay và đảm bảo chắc chắn giá trị mục tiêu chỉ sai khác đáy tối đa \(0.0125\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;hai-ứng-dụng-chính-của-đối-ngẫu&quot;&gt;Hai ứng dụng chính của đối ngẫu&lt;/h3&gt;

&lt;p&gt;Hãy cùng điểm lại hai tính chất ứng dụng chính của lý thuyết đối ngẫu đã giới thiệu ở Chương 11.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu làm tiêu chí dừng:&lt;/strong&gt; Khi \(x\) khả thi nguyên thủy và \((u, v)\) khả thi đối ngẫu, hiệu giữa giá trị mục tiêu nguyên thủy \(f(x)\) và giá trị hàm đối ngẫu \(g(u, v)\) được gọi là &lt;strong&gt;khoảng cách đối ngẫu&lt;/strong&gt; (duality gap) giữa \(x\) và \((u, v)\):&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[f(x) - f^{\star} \le f(x) - g(u, v)\]
&lt;/blockquote&gt;

&lt;p&gt;Khi khoảng cách đối ngẫu bằng \(0\) (zero duality gap), nghiệm nguyên thủy và nghiệm đối ngẫu đều đạt tối ưu. Ngoài ra, giá trị hàm đối ngẫu \(g(u, v)\) luôn là một &lt;strong&gt;cận dưới&lt;/strong&gt; của giá trị tối ưu \(f^{\star}\) (tức \(g(u, v) \le f^{\star}\)); xem lại chi tiết tại &lt;a href=&quot;/contents/vi/chapter11/11_00_Duality_in_General_Programs/&quot;&gt;[Chương 11]&lt;/a&gt;. Từ đó ta có suy dẫn sau:&lt;/p&gt;

&lt;h4 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h4&gt;
&lt;blockquote&gt;
\[\begin{align*}
f^{\star} &amp;amp;\ge g(u, v) \\
-f^{\star} &amp;amp;\le -g(u, v) \\
f(x)-f^{\star} &amp;amp;\le \underbrace{f(x)-g(u, v)}_{\text{khoảng cách đối ngẫu}}\\
g^{\star}-g(u, v) &amp;amp;\le \underbrace{f(x)-g(u, v)}_{\text{khoảng cách đối ngẫu}}\\
\end{align*}\]
&lt;/blockquote&gt;

&lt;p&gt;Nhờ chặn trên sai số tối ưu này, khoảng cách đối ngẫu thường được dùng trực tiếp làm tiêu chí dừng cho các thuật toán tối ưu hóa.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tìm nghiệm nguyên thủy thông qua nghiệm đối ngẫu:&lt;/strong&gt; Khi tính đối ngẫu mạnh được thỏa mãn và ta đã biết nghiệm đối ngẫu tối ưu \((u^{\star}, v^{\star})\), nghiệm nguyên thủy tối ưu \(x^{\star}\) phải cực tiểu hóa hàm Lagrangian \(L(x, u^{\star}, v^{\star})\) theo \(x\) (tức thỏa mãn điều kiện dừng). Tính chất này cho phép suy ra nghiệm nguyên thủy từ nghiệm đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>13 Duality uses and correspondences</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_Duality_uses_and_correspondences/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_Duality_uses_and_correspondences</id>
   <content type="html">&lt;p&gt;Imagine you are auditing a complex supply-chain optimizer that claims its current routing plan is “within 1% of the theoretical best possible cost.” Without knowing the true optimal cost \(f^\star\)—which nobody has ever computed—how could you possibly verify that claim? Duality is the mathematical lens that hands you an indisputable lower bound from a mirror-image problem, turning an unknowable optimum into a certifiable bracket and revealing hidden geometric correspondences between norms, functions, and cones.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-architecture-of-duality-correspondences&quot;&gt;Key ideas: The Architecture of Duality Correspondences&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Primal-Dual Certificates (Why Bounds Matter):&lt;/strong&gt; Every feasible dual point \((u,v)\) yields a lower bound \(g(u,v) \le f^\star\). Paired with any feasible primal point \(x\), the gap \(f(x) - g(u,v)\) certifies suboptimality without ever knowing \(f^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Dual Norms &amp;amp; Geometric Pairing:&lt;/strong&gt; Measuring a primal vector in one norm \(\|\cdot\|\) automatically induces a dual norm \(\|\cdot\|_*\) that measures linear functionals (gradients, prices, dual variables) against the primal unit ball.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Fenchel Conjugates as Function Mirrors:&lt;/strong&gt; The conjugate \(f^*(y) = \max_x (y^T x - f(x))\) translates convex objectives—including nonsmooth norms and indicator constraints—into dual objectives cleanly, separating optimal values (\(x^\star\)) from conjugates (\(f^*\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Dual Cones as Generalized Nonnegativity:&lt;/strong&gt; Replacing componentwise inequalities \(x \ge 0\) with conic memberships \(Ax \in K\) generalizes Lagrange multipliers from nonnegative vectors to dual-cone certificates \(u \in K^*\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-bracketing-an-unknown-optimum-via-duality&quot;&gt;Worked example: Bracketing an Unknown Optimum via Duality&lt;/h3&gt;

&lt;p&gt;Consider minimizing the 1D convex objective \(f(x) = \frac{1}{2}x^2 - 4x\) subject to \(x \ge 1\) (written as \(h(x) = 1 - x \le 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the Lagrangian:&lt;/strong&gt; Introduce dual variable \(u \ge 0$:\)L(x, u) = \frac{1}{2}x^2 - 4x + u(1 - x) = \frac{1}{2}x^2 - (4+u)x + u.$$&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize over \(x\) to get the dual function \(g(u)\):&lt;/strong&gt; Setting \(\frac{\partial L}{\partial x} = x - (4+u) = 0\) gives \(x(u) = 4 + u\). Substituting back:
\(g(u) = \frac{1}{2}(4+u)^2 - (4+u)^2 + u = -\frac{1}{2}(4+u)^2 + u.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate a feasible primal-dual pair:&lt;/strong&gt; Take primal feasible \(x = 3\) (since \(3 \ge 1\)) and dual feasible \(u = 1\) (since \(u \ge 0\)).
    &lt;ul&gt;
      &lt;li&gt;Primal value: \(f(3) = \frac{1}{2}(9) - 12 = -7.5\).&lt;/li&gt;
      &lt;li&gt;Dual value: \(g(1) = -\frac{1}{2}(25) + 1 = -11.5\).&lt;/li&gt;
      &lt;li&gt;Certified duality gap: \(f(3) - g(1) = -7.5 - (-11.5) = 4.0\), guaranteeing \(f^\star \in [-11.5, -7.5]\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check zero gap at optimality:&lt;/strong&gt; At \(x^\star = 4\) and \(u^\star = 0\), we get \(f(4) = -8\) and \(g(0) = -8\), closing the gap to \(0\) and confirming global optimality.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we will learn about the uses of Duality and related correspondences through examples.&lt;/p&gt;

&lt;h3 id=&quot;notice&quot;&gt;[Notice]&lt;/h3&gt;

&lt;p&gt;In this chapter, the optimal solution \(x^{\star}\) and the conjugate \(x^{*}\) of \(x\) are distinguished and denoted as such.&lt;/p&gt;

&lt;h2 id=&quot;modern-applications-20222026&quot;&gt;Modern applications (2022–2026)&lt;/h2&gt;

&lt;p&gt;An optional companion lesson attaches 2022–2026 uses to the same correspondences: dual norms in RobustBench, the Lasso dual in skglm screening, conjugates in Clarabel / CVXPY, and dual cones in α,β-CROWN. See &lt;a href=&quot;/contents/en/chapter13/13_07_modern_applications/&quot;&gt;13-07 Modern uses of conjugates, dual norms, and dual cones&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-09 Practical Exercises - Duality Applications</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_09_Practical_Exercises_Duality_Applications/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_09_Practical_Exercises_Duality_Applications</id>
   <content type="html">&lt;p&gt;Reading duality theorems feels smooth until a blank sheet of paper asks you to compute the conjugate of a piecewise function, derive the dual of a regularized regression problem, or prove a cone is self-dual. The gap between &lt;em&gt;recognizing&lt;/em&gt; a derivation and &lt;em&gt;producing&lt;/em&gt; one is closed by a disciplined workflow: split cleanly, apply known conjugate primitives, check signs via Fenchel’s inequality, and verify your final answer on a tiny numerical test case.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-a-problem-solving-playbook-for-duality-exercises&quot;&gt;Key ideas: A Problem-Solving Playbook for Duality Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Dual Norm Strategy:&lt;/strong&gt; Always pair Hölder’s inequality (to prove an upper bound \(\|y\|_* \le \text{candidate}\)) with an explicit unit-norm witness \(x^\star\) achieving equality (to prove \(\|y\|_* \ge \text{candidate}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Conjugate Strategy:&lt;/strong&gt; Check domain finiteness first (can \(y^T x - f(x)\) blow up to \(+\infty\) along any ray?), then solve \(y \in \partial f(x)\) on the finite domain.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Composite Dual Strategy:&lt;/strong&gt; Introduce \(z = Ax\) to isolate every nonsmooth term; evaluate \(\min_x\) and \(\min_z\) separately into \(-f^*(A^T u)\) and \(-g^*(-u)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Numerical Sanity Check:&lt;/strong&gt; Plug in a 1D or 2D vector with easy numbers and verify \(f(x^\star) = g(u^\star)\)—this catches 95% of sign and factor-of-2 errors immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-the-conjugate-of-the-huber-style-quadratic--ell_1-norm&quot;&gt;Worked example: Computing the Conjugate of the Huber-Style Quadratic + \(\ell_1\) Norm&lt;/h3&gt;

&lt;p&gt;Find the conjugate of \(f(x) = \frac{1}{2}\|x\|_2^2 + \|x\|_1\) on \(\mathbb{R}^n\) (the Elastic Net penalty with \(\alpha = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Exploit separability:&lt;/strong&gt; Since $$f(x) = \sum_{i=1}^n \left(\frac{1}{2}x_i^2 +&lt;/td&gt;
          &lt;td&gt;x_i&lt;/td&gt;
          &lt;td&gt;\right)\(, its conjugate splits as\)f^&lt;em&gt;(y) = \sum_{i=1}^n \phi^&lt;/em&gt;(y_i)\(, where\)\phi(t) = \frac{1}{2}t^2 +&lt;/td&gt;
          &lt;td&gt;t&lt;/td&gt;
          &lt;td&gt;$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;em&gt;*Compute the 1D conjugate $$\phi^&lt;/em&gt;(s) = \max_{t \in \mathbb{R}} \left(st - \frac{1}{2}t^2 -&lt;/td&gt;
          &lt;td&gt;t&lt;/td&gt;
          &lt;td&gt;\right)$$:**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;**Case $$&lt;/td&gt;
              &lt;td&gt;s&lt;/td&gt;
              &lt;td&gt;\le 1\(:** For any\)t\(,\)st -&lt;/td&gt;
              &lt;td&gt;t&lt;/td&gt;
              &lt;td&gt;\le (&lt;/td&gt;
              &lt;td&gt;s&lt;/td&gt;
              &lt;td&gt;-1)&lt;/td&gt;
              &lt;td&gt;t&lt;/td&gt;
              &lt;td&gt;\le 0\(, and\)-\frac{1}{2}t^2 \le 0\(, so the maximum is achieved at\)t^\star = 0\(with\)\phi^*(s) = 0$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Case \(s &amp;gt; 1\):&lt;/strong&gt; Optimum must have \(t &amp;gt; 0\); setting \(s - t - 1 = 0\) gives \(t^\star = s - 1\) and \(\phi^*(s) = \frac{1}{2}(s-1)^2\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Case \(s &amp;lt; -1\):&lt;/strong&gt; Optimum must have \(t &amp;lt; 0\); setting \(s - t + 1 = 0\) gives \(t^\star = s + 1\) and \(\phi^*(s) = \frac{1}{2}(s+1)^2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Combine into a single closed form:&lt;/strong&gt; Using soft-thresholding $$S_1(s) = \operatorname{sign}(s)\max(&lt;/td&gt;
          &lt;td&gt;s&lt;/td&gt;
          &lt;td&gt;-1, 0)$$,&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;$$f^*(y) = \frac{1}{2}\sum_{i=1}^n \big(\max(&lt;/td&gt;
          &lt;td&gt;y_i&lt;/td&gt;
          &lt;td&gt;- 1, 0)\big)^2 = \frac{1}{2}|S_1(y)|_2^2.$$&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical verification:&lt;/strong&gt; At \(y = 3\), \(t^\star = 2\), \(f(2) = 2 + 2 = 4\), \(f^*(3) = \frac{1}{2}(3-1)^2 = 2\), and \(f(2) + f^*(3) = 6 = 2 \cdot 3 = t^\star y\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---applications-of-duality&quot;&gt;Practical Exercises - Applications of Duality&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd &amp;amp; Vandenberghe (2004), Rockafellar (1970), and Ben-Tal &amp;amp; Nemirovski (2001).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-i-dual-norms&quot;&gt;📝 &lt;strong&gt;Part I: Dual Norms&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-1-computing-dual-norms-boyd--vandenberghe-ex-37&quot;&gt;&lt;strong&gt;Exercise 1: Computing Dual Norms (Boyd &amp;amp; Vandenberghe, Ex. 3.7)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Given a norm \(\|x\|\), the dual norm is defined as:&lt;/p&gt;

\[\|y\|_* = \max_{\|x\| \leq 1} y^T x\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Find the dual norm of the following norms:&lt;/p&gt;

&lt;p&gt;a) \(\|x\|_1 = \sum_{i=1}^n |x_i|\)&lt;br /&gt;
b) \(\|x\|_2 = \sqrt{\sum_{i=1}^n x_i^2}\)&lt;br /&gt;
c) \(\|x\|_\infty = \max_i |x_i|\)&lt;br /&gt;
d) \(\|x\|_p = (\sum_{i=1}^n |x_i|^p)^{1/p}\) with \(p \geq 1\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**General formula:** The dual norm of $$\|\cdot\|_p$$ is $$\|\cdot\|_q$$ with $$\frac{1}{p} + \frac{1}{q} = 1$$.

---

**a) The $$\ell_1$$ norm:**

We need to find:

$$
\|y\|_* = \max_{\|x\|_1 \leq 1} y^T x = \max_{\sum_i |x_i| \leq 1} \sum_i y_i x_i
$$

**Analysis:**  
- To maximize $$\sum_i y_i x_i$$, choose $$x_i$$ with the same sign as $$y_i$$
- Constraint: $$\sum_i |x_i| \leq 1$$

Optimal solution: set $$x_j = \text{sign}(y_j)$$ with $$j = \arg\max_i |y_i|$$, and all other $$x_i$$ = 0.

Result:

$$
\|y\|_* = \max_i |y_i| = \|y\|_\infty
$$

**Conclusion:** $$(\|\cdot\|_1)_* = \|\cdot\|_\infty$$

---

**b) The $$\ell_2$$ norm:**

$$
\|y\|_* = \max_{\|x\|_2 \leq 1} y^T x
$$

By the Cauchy-Schwarz inequality:

$$
y^T x \leq \|y\|_2 \|x\|_2 \leq \|y\|_2
$$

Equality holds when $$x = \frac{y}{\|y\|_2}$$.

**Conclusion:** $$(\|\cdot\|_2)_* = \|\cdot\|_2$$ (self-dual)

---

**c) The $$\ell_\infty$$ norm:**

$$
\|y\|_* = \max_{\max_i |x_i| \leq 1} \sum_i y_i x_i
$$

Choose $$x_i = \text{sign}(y_i)$$ for every $$i$$ (since $$|x_i| \leq 1$$):

$$
\|y\|_* = \sum_i |y_i| = \|y\|_1
$$

**Conclusion:** $$(\|\cdot\|_\infty)_* = \|\cdot\|_1$$

---

**d) The general $$\ell_p$$ norm:**

By Hölder&apos;s inequality:

$$
y^T x \leq \|y\|_q \|x\|_p
$$

with $$\frac{1}{p} + \frac{1}{q} = 1$$.

Equality is attained when $$x_i = c \cdot \text{sign}(y_i) |y_i|^{q-1}$$ (with $$c$$ chosen so that $$\|x\|_p = 1$$).

**Conclusion:** $$(\|\cdot\|_p)_* = \|\cdot\|_q$$ with $$\frac{1}{p} + \frac{1}{q} = 1$$

---

**Summary table:**

| Primal norm | Dual norm | Relation |
|--------------|------------|---------|
| $$\|\cdot\|_1$$ | $$\|\cdot\|_\infty$$ | $$p=1, q=\infty$$ |
| $$\|\cdot\|_2$$ | $$\|\cdot\|_2$$ | Self-dual |
| $$\|\cdot\|_\infty$$ | $$\|\cdot\|_1$$ | $$p=\infty, q=1$$ |
| $$\|\cdot\|_p$$ | $$\|\cdot\|_q$$ | $$1/p + 1/q = 1$$ |

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-2-verifying-the-dual-norm-property&quot;&gt;&lt;strong&gt;Exercise 2: Verifying the Dual Norm Property&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;With \(x = (3, 4)^T\) and \(y = (0.6, 0.8)^T\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Compute \(\|x\|_1\), \(\|x\|_2\), \(\|x\|_\infty\)&lt;br /&gt;
b) Compute \(\|y\|_1\), \(\|y\|_2\), \(\|y\|_\infty\)&lt;br /&gt;
c) Verify: \(y^T x \leq \|y\|_* \|x\|\) for each pair of norms&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Norms of $$x = (3,4)$$:**

$$
\begin{align}
\|x\|_1 &amp;amp;= |3| + |4| = 7 \\
\|x\|_2 &amp;amp;= \sqrt{3^2 + 4^2} = \sqrt{25} = 5 \\
\|x\|_\infty &amp;amp;= \max(|3|, |4|) = 4
\end{align}
$$

---

**b) Norms of $$y = (0.6, 0.8)$$:**

$$
\begin{align}
\|y\|_1 &amp;amp;= 0.6 + 0.8 = 1.4 \\
\|y\|_2 &amp;amp;= \sqrt{0.6^2 + 0.8^2} = \sqrt{0.36 + 0.64} = 1 \\
\|y\|_\infty &amp;amp;= \max(0.6, 0.8) = 0.8
\end{align}
$$

---

**c) Verifying the inequality:**

Compute $$y^T x$$:

$$
y^T x = 0.6 \times 3 + 0.8 \times 4 = 1.8 + 3.2 = 5
$$

**Case 1:** $$\|x\|_1$$ and $$\|y\|_\infty$$ (since $$(\|\cdot\|_1)_* = \|\cdot\|_\infty$$)

$$
y^T x = 5 \leq \|y\|_\infty \|x\|_1 = 0.8 \times 7 = 5.6
$$

✓ Satisfied

---

**Case 2:** $$\|x\|_2$$ and $$\|y\|_2$$ (self-dual)

$$
y^T x = 5 \leq \|y\|_2 \|x\|_2 = 1 \times 5 = 5
$$

✓ Equality (since $$y = \frac{x}{\|x\|_2}$$)

---

**Case 3:** $$\|x\|_\infty$$ and $$\|y\|_1$$ (since $$(\|\cdot\|_\infty)_* = \|\cdot\|_1$$)

$$
y^T x = 5 \leq \|y\|_1 \|x\|_\infty = 1.4 \times 4 = 5.6
$$

✓ Satisfied

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-ii-conjugate-functions&quot;&gt;📝 &lt;strong&gt;Part II: Conjugate Functions&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-3-computing-conjugate-functions-rockafellar-ex-12b&quot;&gt;&lt;strong&gt;Exercise 3: Computing Conjugate Functions (Rockafellar, Ex. 12.B)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The conjugate of a function \(f(x)\) is defined as:&lt;/p&gt;

\[f^*(y) = \sup_x (y^T x - f(x))\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Compute the conjugate of:&lt;/p&gt;

&lt;p&gt;a) \(f(x) = \frac{1}{2}x^T Q x\) with \(Q \succ 0\)&lt;br /&gt;
b) \(f(x) = \|x\|_2\)&lt;br /&gt;
c) \(f(x) = e^x\) (with \(x \in \mathbb{R}\))&lt;br /&gt;
d) \(f(x) = I_C(x)\) (the indicator function of the set \(C\))&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Quadratic function $$f(x) = \frac{1}{2}x^T Q x$$:**

$$
f^*(y) = \sup_x \left( y^T x - \frac{1}{2} x^T Q x \right)
$$

**FOC:** $$\nabla_x (y^T x - \frac{1}{2}x^T Q x) = y - Qx = 0$$

$$
x^* = Q^{-1} y
$$

Substituting:

$$
f^*(y) = y^T Q^{-1} y - \frac{1}{2} (Q^{-1}y)^T Q (Q^{-1}y)
$$

$$
= y^T Q^{-1} y - \frac{1}{2} y^T Q^{-1} y = \frac{1}{2} y^T Q^{-1} y
$$

**Result:** $$\boxed{f^*(y) = \frac{1}{2} y^T Q^{-1} y}$$

**Fenchel&apos;s inequality:**

$$
\frac{1}{2}x^T Q x + \frac{1}{2}y^T Q^{-1} y \geq x^T y
$$

---

**b) Euclidean norm $$f(x) = \|x\|_2$$:**

$$
f^*(y) = \sup_x (y^T x - \|x\|_2)
$$

**Analysis:**
- If $$\|y\|_2 \leq 1$$: we can take $$x$$ along the direction of $$y$$ with $$\|x\| \to \infty$$, but $$y^Tx - \|x\| \leq 0$$
- If $$\|y\|_2 &amp;gt; 1$$: $$y^T x - \|x\|_2 \to \infty$$ for $$x = ty$$ with $$t \to \infty$$

**Result:**

$$
\boxed{f^*(y) = \begin{cases}
0 &amp;amp; \text{if } \|y\|_2 \leq 1 \\
\infty &amp;amp; \text{if } \|y\|_2 &amp;gt; 1
\end{cases}} = I_{\|y\|_2 \leq 1}(y)
$$

---

**c) Exponential function $$f(x) = e^x$$:**

$$
f^*(y) = \sup_x (yx - e^x)
$$

**FOC:** $$y - e^x = 0 \Rightarrow x^* = \ln y$$

(A solution exists only if $$y &amp;gt; 0$$)

Substituting:

$$
f^*(y) = y \ln y - e^{\ln y} = y \ln y - y
$$

**Result:**

$$
\boxed{f^*(y) = \begin{cases}
y \ln y - y &amp;amp; \text{if } y &amp;gt; 0 \\
0 &amp;amp; \text{if } y = 0 \\
\infty &amp;amp; \text{if } y &amp;lt; 0
\end{cases}}
$$

---

**d) Indicator function $$f(x) = I_C(x)$$:**

$$
f^*(y) = \sup_x (y^T x - I_C(x)) = \sup_{x \in C} y^T x
$$

**Result:** $$\boxed{f^*(y) = \sup_{x \in C} y^T x}$$ (the support function of $$C$$)

**Specific examples:**
- $$C = \{x : \|x\|_2 \leq 1\}$$: $$f^*(y) = \|y\|_2$$
- $$C = \mathbb{R}^n_+$$: $$f^*(y) = I_{\{y \leq 0\}}(y)$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-4-fenchels-inequality-boyd--vandenberghe-ex-333&quot;&gt;&lt;strong&gt;Exercise 4: Fenchel’s Inequality (Boyd &amp;amp; Vandenberghe, Ex. 3.33)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Let \(f(x) = \frac{1}{2}\|x\|^2\), \(x = (1, 2)^T\) and \(y = (3, 1)^T\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Compute \(f(x)\) and \(f^*(y)\)&lt;br /&gt;
b) Compute \(x^T y\)&lt;br /&gt;
c) Verify Fenchel’s inequality: \(f(x) + f^*(y) \geq x^T y\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Compute $$f(x)$$ and $$f^*(y)$$:**

$$
f(x) = \frac{1}{2}(1^2 + 2^2) = \frac{1}{2}(1 + 4) = 2.5
$$

For $$f(x) = \frac{1}{2}\|x\|^2$$ we have $$Q = I$$, so:

$$
f^*(y) = \frac{1}{2}\|y\|^2 = \frac{1}{2}(3^2 + 1^2) = \frac{1}{2}(9 + 1) = 5
$$

---

**b) Compute $$x^T y$$:**

$$
x^T y = 1 \times 3 + 2 \times 1 = 5
$$

---

**c) Verify Fenchel:**

$$
f(x) + f^*(y) = 2.5 + 5 = 7.5 \geq 5 = x^T y
$$

✓ Satisfied

**Gap:** $$7.5 - 5 = 2.5$$

**When is there equality?** When $$y \in \partial f(x)$$, i.e. $$y = \nabla f(x) = x$$.

For $$x = (1,2)$$ we have $$\nabla f(x) = (1,2) \neq (3,1) = y$$, so there is no equality.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iii-lasso-dual&quot;&gt;📝 &lt;strong&gt;Part III: LASSO Dual&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-5-constructing-the-lasso-dual-boyd--vandenberghe-ex-615&quot;&gt;&lt;strong&gt;Exercise 5: Constructing the LASSO Dual (Boyd &amp;amp; Vandenberghe, Ex. 6.15)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The primal LASSO problem:&lt;/p&gt;

\[\min_x \frac{1}{2}\|Ax - b\|^2 + \lambda \|x\|_1\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;
a) Write the dual problem&lt;br /&gt;
b) Explain the relationship between primal and dual variables&lt;br /&gt;
c) With \(A = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}\), \(b = \begin{bmatrix} 1 \\ 1 \\ 3 \end{bmatrix}\), \(\lambda = 0.5\), find the dual solution&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) The dual problem:**

LASSO primal:

$$
\min_x \frac{1}{2}\|Ax - b\|^2 + \lambda \|x\|_1
$$

**Method 1: via the Lagrangian**

Rewrite with the auxiliary variable $$r = Ax - b$$:

$$
\begin{align}
\min_{x,r} \quad &amp;amp; \frac{1}{2}\|r\|^2 + \lambda \|x\|_1 \\
\text{s.t.} \quad &amp;amp; Ax - r = b
\end{align}
$$

Lagrangian:

$$
L(x, r, \nu) = \frac{1}{2}\|r\|^2 + \lambda \|x\|_1 + \nu^T(Ax - r - b)
$$

Minimize over $$x$$:

$$
\min_x \left( \lambda \|x\|_1 + \nu^T A x \right) = \begin{cases}
0 &amp;amp; \text{if } \|A^T \nu\|_\infty \leq \lambda \\
-\infty &amp;amp; \text{otherwise}
\end{cases}
$$

Minimize over $$r$$:

$$
\min_r \left( \frac{1}{2}\|r\|^2 - \nu^T r \right) = -\frac{1}{2}\|\nu\|^2
$$

**Dual function:**

$$
g(\nu) = -\frac{1}{2}\|\nu\|^2 - \nu^T b
$$

with the constraint $$\|A^T \nu\|_\infty \leq \lambda$$.

**The dual problem:**

$$
\boxed{
\begin{align}
\min_{\nu} \quad &amp;amp; \frac{1}{2}\|\nu\|^2 + \nu^T b \\
\text{s.t.} \quad &amp;amp; \|A^T \nu\|_\infty \leq \lambda
\end{align}
}
$$

(Converting max to min)

---

**b) Primal-dual relationship:**

From the KKT conditions:
- $$r^* = \nu^*$$ (residual dual = dual variable)
- If $$|(A^T \nu^*)_i| &amp;lt; \lambda$$: $$x_i^* = 0$$
- If $$|(A^T \nu^*)_i| = \lambda$$: $$x_i^* \neq 0$$ (in the active set)

**Recovering the primal from the dual:**

$$
x^* = \text{(solution of the problem restricted to the active set)}
$$

---

**c) Numerical solution:**

Data:

$$
A = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}, \quad
b = \begin{bmatrix} 1 \\ 1 \\ 3 \end{bmatrix}, \quad
\lambda = 0.5
$$

**The dual problem:**

$$
\begin{align}
\min_{\nu} \quad &amp;amp; \frac{1}{2}(\nu_1^2 + \nu_2^2 + \nu_3^2) + \nu_1 + \nu_2 + 3\nu_3 \\
\text{s.t.} \quad &amp;amp; \max(|\nu_1 + \nu_3|, |\nu_2 + \nu_3|) \leq 0.5
\end{align}
$$

**Solving:**

FOC (if the constraint is inactive):

$$
\nu_1 + 1 = 0 \Rightarrow \nu_1 = -1 \\
\nu_2 + 1 = 0 \Rightarrow \nu_2 = -1 \\
\nu_3 + 3 = 0 \Rightarrow \nu_3 = -3
$$

Check the constraint:

$$
\max(|-1 - 3|, |-1 - 3|) = 4 &amp;gt; 0.5
$$

Not satisfied! The constraint must be active.

**Assume** both constraints are active: $$\nu_1 + \nu_3 = \nu_2 + \nu_3 = -0.5$$ (by symmetry, $$\nu_1 = \nu_2 = a$$ and $$\nu_3 = -0.5 - a$$).

Substitute into the objective: $$\min_a \; \frac{1}{2}\left[2(a+1)^2 + (2.5 - a)^2\right]$$ (since $$\frac{1}{2}\|\nu\|^2 + \nu^Tb = \frac{1}{2}\|\nu + b\|^2 - \frac{1}{2}\|b\|^2$$).

Derivative: $$2(a+1) - (2.5 - a) = 0 \Rightarrow a = \frac{1}{6}$$.

**Dual solution:**

$$
\nu^* = \left(\tfrac{1}{6}, \tfrac{1}{6}, -\tfrac{2}{3}\right)^T, \qquad \tfrac{1}{2}\|\nu^*\|^2 + \nu^{*T}b = \tfrac{1}{4} - \tfrac{5}{3} = -\tfrac{17}{12}
$$

that is, the dual value (of the max problem) is $$\frac{17}{12} \approx 1.4167$$.

**Check against the primal:** $$x^* = \left(\tfrac{7}{6}, \tfrac{7}{6}\right)$$ gives $$Ax^* - b = \left(\tfrac{1}{6}, \tfrac{1}{6}, -\tfrac{2}{3}\right) = \nu^*$$ ✓ (indeed $$r^* = \nu^*$$), and the primal value is $$\frac{1}{2}\|r^*\|^2 + \lambda\|x^*\|_1 = \frac{1}{4} + 0.5 \cdot \frac{7}{3} = \frac{17}{12}$$ ✓. There is no duality gap.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iv-dual-cones&quot;&gt;📝 &lt;strong&gt;Part IV: Dual Cones&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-6-computing-dual-cones-boyd--vandenberghe-ex-236&quot;&gt;&lt;strong&gt;Exercise 6: Computing Dual Cones (Boyd &amp;amp; Vandenberghe, Ex. 2.36)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The dual cone of \(K\) is defined as:&lt;/p&gt;

\[K^* = \{ y : y^T x \geq 0, \forall x \in K \}\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Find the dual cone of:&lt;/p&gt;

&lt;p&gt;a) \(K = \mathbb{R}^n_+ = \{x : x \geq 0\}\)&lt;br /&gt;
b) \(K = \{(t, x) : \|x\|_2 \leq t\}\) (second-order cone)&lt;br /&gt;
c) \(K = \mathbb{S}^n_+\) (positive semidefinite cone)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Nonnegative orthant $$K = \mathbb{R}^n_+$$:**

We need to find $$y$$ such that $$y^T x \geq 0$$ for all $$x \geq 0$$.

**Analysis:** take $$x = e_i$$ (the $$i$$-th basis vector):

$$
y^T e_i = y_i \geq 0
$$

This must hold for all $$i$$ → $$y \geq 0$$.

**Conclusion:** $$\boxed{K^* = \mathbb{R}^n_+}$$ (self-dual)

---

**b) Second-order cone:**

$$
K = \{(t, x) : t \in \mathbb{R}, x \in \mathbb{R}^{n-1}, \|x\|_2 \leq t\}
$$

We need to find $$(s, y)$$ such that:

$$
st + y^T x \geq 0, \quad \forall \|x\|_2 \leq t
$$

**Worst case:** $$x = -\frac{t}{\|y\|_2} y$$ (if $$y \neq 0$$)

$$
st - t\|y\|_2 = t(s - \|y\|_2) \geq 0
$$

This must hold for all $$t &amp;gt; 0$$ → $$s \geq \|y\|_2$$.

**Conclusion:** $$\boxed{K^* = K}$$ (self-dual)

---

**c) PSD cone $$K = \mathbb{S}^n_+$$:**

We need to find $$Y$$ such that:

$$
\text{tr}(Y X) \geq 0, \quad \forall X \succeq 0
$$

**Eigenvalue analysis:** $$X = \sum_i \lambda_i v_i v_i^T$$ with $$\lambda_i \geq 0$$:

$$
\text{tr}(Y X) = \sum_i \lambda_i v_i^T Y v_i \geq 0
$$

This must hold for all $$\lambda_i \geq 0$$ → $$v_i^T Y v_i \geq 0$$ for all $$v_i$$ → $$Y \succeq 0$$.

**Conclusion:** $$\boxed{K^* = \mathbb{S}^n_+}$$ (self-dual)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-7-verifying-cone-properties&quot;&gt;&lt;strong&gt;Exercise 7: Verifying Cone Properties&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Let \(x = (2, 1, 1)^T\) and \(y = (1.5, 0.5, 0.5)^T\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;
a) Is \(x\) in the SOC?&lt;br /&gt;
b) Is \(y\) in the SOC?&lt;br /&gt;
c) Compute \(y^T x\) and verify the dual cone property&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**SOC:** $$K = \{(t, x) \in \mathbb{R} \times \mathbb{R}^2 : \|x\|_2 \leq t\}$$

Write $$x = (t, u)$$ with $$t = 2$$, $$u = (1, 1)$$.

---

**a) Check $$x$$:**

$$
\|(1, 1)\|_2 = \sqrt{2} \approx 1.414 \leq 2
$$

✓ $$x \in K$$

---

**b) Check $$y$$:**

$$
\|(0.5, 0.5)\|_2 = \frac{\sqrt{2}}{2} \approx 0.707 \leq 1.5
$$

✓ $$y \in K$$

---

**c) Dual cone property:**

Since $$K$$ is self-dual: $$y \in K^* = K$$

So for every $$x \in K$$: $$y^T x \geq 0$$.

$$
y^T x = 1.5 \times 2 + 0.5 \times 1 + 0.5 \times 1 = 3 + 0.5 + 0.5 = 4 \geq 0
$$

✓ Satisfied

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-v-sdp-duality&quot;&gt;📝 &lt;strong&gt;Part V: SDP Duality&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-8-sdp-primal-dual-ben-tal--nemirovski-ex-43&quot;&gt;&lt;strong&gt;Exercise 8: SDP Primal-Dual (Ben-Tal &amp;amp; Nemirovski, Ex. 4.3)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The primal SDP problem:&lt;/p&gt;

\[\begin{align}
\min_{X} \quad &amp;amp; \text{tr}(C X) \\
\text{s.t.} \quad &amp;amp; \text{tr}(A_i X) = b_i, \quad i = 1, \ldots, m \\
&amp;amp; X \succeq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the dual problem&lt;br /&gt;
b) Explain strong duality&lt;br /&gt;
c) With \(C = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\), \(A_1 = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}\), \(b_1 = 1\), find the solution&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) The dual problem:**

Lagrangian:

$$
L(X, y) = \text{tr}(CX) - \sum_i y_i (\text{tr}(A_i X) - b_i)
$$

$$
= \text{tr}\left( \left(C - \sum_i y_i A_i\right) X \right) + \sum_i y_i b_i
$$

Minimize over $$X \succeq 0$$:

$$
\min_{X \succeq 0} \text{tr}(MX) = \begin{cases}
0 &amp;amp; \text{if } M \succeq 0 \\
-\infty &amp;amp; \text{otherwise}
\end{cases}
$$

with $$M = C - \sum_i y_i A_i$$.

**The dual problem:**

$$
\boxed{
\begin{align}
\max_{y} \quad &amp;amp; \sum_i y_i b_i \\
\text{s.t.} \quad &amp;amp; C - \sum_i y_i A_i \succeq 0
\end{align}
}
$$

---

**b) Strong Duality:**

Slater condition: there exists $$\tilde{X} \succ 0$$ with $$\text{tr}(A_i \tilde{X}) = b_i$$.

Then: **strong duality** $$p^* = d^*$$ holds and a dual optimal solution exists.

**KKT Conditions:**
1. Primal feasible: $$\text{tr}(A_i X^*) = b_i$$, $$X^* \succeq 0$$
2. Dual feasible: $$C - \sum_i y_i^* A_i \succeq 0$$
3. Complementary slackness: $$\text{tr}((C - \sum_i y_i^* A_i) X^*) = 0$$

---

**c) Specific solution:**

Data:

$$
C = I_2, \quad A_1 = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}, \quad b_1 = 1
$$

**Primal:**

$$
\begin{align}
\min_{X} \quad &amp;amp; x_{11} + x_{22} \\
\text{s.t.} \quad &amp;amp; x_{11} = 1 \\
&amp;amp; X \succeq 0
\end{align}
$$

From $$x_{11} = 1$$ and $$X \succeq 0$$:

$$
X = \begin{bmatrix} 1 &amp;amp; x_{12} \\ x_{12} &amp;amp; x_{22} \end{bmatrix} \succeq 0
$$

PSD → $$\det(X) = x_{22} - x_{12}^2 \geq 0$$ → $$x_{22} \geq x_{12}^2 \geq 0$$.

Minimize $$1 + x_{22}$$ → $$x_{22}^* = 0$$, $$x_{12}^* = 0$$.

**Primal solution:**

$$
X^* = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}, \quad p^* = 1
$$

---

**Dual:**

$$
\begin{align}
\max_{y_1} \quad &amp;amp; y_1 \\
\text{s.t.} \quad &amp;amp; I - y_1 \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} \succeq 0
\end{align}
$$

$$
\begin{bmatrix} 1-y_1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} \succeq 0 \Rightarrow 1-y_1 \geq 0 \Rightarrow y_1 \leq 1
$$

Maximize → $$y_1^* = 1$$, $$d^* = 1$$.

**Conclusion:** $$p^* = d^* = 1$$. Strong duality! ✓

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary-and-strategy&quot;&gt;💡 &lt;strong&gt;Summary and Strategy&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;dual-norms&quot;&gt;&lt;strong&gt;Dual Norms:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Remember: \((\|\cdot\|_p)_* = \|\cdot\|_q\) with \(1/p + 1/q = 1\)&lt;/li&gt;
  &lt;li&gt;\(\ell_1 \leftrightarrow \ell_\infty\), \(\ell_2\) is self-dual&lt;/li&gt;
  &lt;li&gt;Use: \(y^T x \leq \|y\|_* \|x\|\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;conjugate-functions&quot;&gt;&lt;strong&gt;Conjugate Functions:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Definition: \(f^*(y) = \sup_x (y^Tx - f(x))\)&lt;/li&gt;
  &lt;li&gt;Fenchel: \(f(x) + f^*(y) \geq x^Ty\)&lt;/li&gt;
  &lt;li&gt;Equality when \(y \in \partial f(x)\)&lt;/li&gt;
  &lt;li&gt;\(f^{**} = f\) if \(f\) is closed and convex&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;lasso-dual&quot;&gt;&lt;strong&gt;LASSO Dual:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Primal: \(\min \frac{1}{2}\|Ax-b\|^2 + \lambda\|x\|_1\)&lt;/li&gt;
  &lt;li&gt;Dual: \(\min \frac{1}{2}\|\nu\|^2 + \nu^Tb\) s.t. \(\|A^T\nu\|_\infty \leq \lambda\)&lt;/li&gt;
  &lt;li&gt;The dual is smaller (\(m\) variables vs \(n\) variables) if \(m &amp;lt; n\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;dual-cones&quot;&gt;&lt;strong&gt;Dual Cones:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Definition: \(K^* = \{y : y^Tx \geq 0, \forall x \in K\}\)&lt;/li&gt;
  &lt;li&gt;Self-dual: \(\mathbb{R}^n_+\), SOC, \(\mathbb{S}^n_+\)&lt;/li&gt;
  &lt;li&gt;\(K^{**} = K\) if \(K\) is closed and convex&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;sdp-duality&quot;&gt;&lt;strong&gt;SDP Duality:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Strong duality if Slater holds&lt;/li&gt;
  &lt;li&gt;Complementary slackness: \(\text{tr}(MX) = 0\) with \(M \succeq 0\), \(X \succeq 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 3, 5, 6.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Rockafellar, R. T.&lt;/strong&gt; (1970). &lt;em&gt;Convex Analysis&lt;/em&gt;. Princeton University Press.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ben-Tal, A., &amp;amp; Nemirovski, A.&lt;/strong&gt; (2001). &lt;em&gt;Lectures on Modern Convex Optimization&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Borwein, J. M., &amp;amp; Lewis, A. S.&lt;/strong&gt; (2006). &lt;em&gt;Convex Analysis and Nonlinear Optimization&lt;/em&gt; (2nd ed.). Springer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hiriart-Urruty, J.-B., &amp;amp; Lemaréchal, C.&lt;/strong&gt; (2001). &lt;em&gt;Fundamentals of Convex Analysis&lt;/em&gt;. Springer.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

</content>
 </entry>
 
 <entry>
   <title>13-08 Multiple-Choice Quiz - Uses and Correspondences of Duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_08_Quiz_Duality_Uses/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_08_Quiz_Duality_Uses</id>
   <content type="html">&lt;p&gt;Before clicking through the multiple-choice questions below, pause and notice why duality questions are favorite traps on graduate qualifying exams: a single missing minus sign in \(f^*(y) = \max_x (y^T x - f(x))\), a swapped primal/dual norm pair, or forgetting that an equivalent dual transformation can change the optimal value will flip an answer from right to wrong. Use the concept map and warm-up calculation below to sharpen your reflexes before starting the quiz.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-high-yield-quiz-checkpoints&quot;&gt;Key ideas: High-Yield Quiz Checkpoints&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Duality Gap &amp;amp; Stopping Criteria:&lt;/strong&gt; Remember \(f(x) - f^\star \le f(x) - g(u,v)\) requires \(x\) primal feasible and \((u,v)\) dual feasible; zero gap certifies optimality under strong duality.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Dual Norm &amp;amp; Conjugate Pairings:&lt;/strong&gt; Memorize the exact pairs: \(\ell_1 \leftrightarrow \ell_\infty\), \(\ell_2 \leftrightarrow \ell_2\), trace norm \(\leftrightarrow\) operator norm; norm \(\leftrightarrow\) indicator of dual-norm unit ball; indicator \(\leftrightarrow\) support function.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Splitting &amp;amp; Linear Transformations:&lt;/strong&gt; For \(\min_x f(x) + g(Ax)\), the dual is \(\max_u -f^*(A^T u) - g^*(-u)\). Watch the transpose \(A^T\) and the minus sign on \(-u\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Dual Cones &amp;amp; Self-Duality:&lt;/strong&gt; \(K^* = \{y : y^T x \ge 0\ \forall x \in K\}\) is always convex and closed; \(\mathbb{R}^n_+\), \(\mathcal{Q}^n\), and \(\mathbb{S}^n_+\) are self-dual, and \(K^{**} = K\) holds for closed convex cones.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-rapid-4-check-diagnostic-before-the-quiz&quot;&gt;Worked example: Rapid 4-Check Diagnostic Before the Quiz&lt;/h3&gt;

&lt;p&gt;Test yourself on four classic exam micro-calculations before taking the quiz:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Duality gap check:&lt;/strong&gt; If primal feasible \(x\) has \(f(x) = 14.2\) and dual feasible \((u,v)\) has \(g(u,v) = 13.7\), what is the tightest guaranteed bound on \(f(x) - f^\star\)?
    &lt;ul&gt;
      &lt;li&gt;Answer: \(f(x) - f^\star \le 14.2 - 13.7 = 0.5\) (and \(f^\star \in [13.7, 14.2]\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual norm check:&lt;/strong&gt; For \(y = (-2, 5, -1)^T\), compute \((\|y\|_1)_*\) and \((\|y\|_\infty)_*\).
    &lt;ul&gt;
      &lt;li&gt;\((\|y\|_1)_* = \|y\|_\infty = 5\); \((\|y\|_\infty)_* = \|y\|_1 = 2 + 5 + 1 = 8\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conjugate check:&lt;/strong&gt; For \(f(x) = \frac{1}{2}ax^2 + bx + c\) (\(a &amp;gt; 0\)), compute \(f^*(y)\).
    &lt;ul&gt;
      &lt;li&gt;Set $$\frac{d}{dx}(yx - \frac{1}{2}ax^2 - bx - c) = y - ax - b = 0 \implies x^\star = \frac{y-b}{a}$.&lt;/li&gt;
      &lt;li&gt;Substituting back: \(f^*(y) = \frac{(y-b)^2}{2a} - c\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual cone check:&lt;/strong&gt; Is \(y = (-1, 3)^T\) in the dual of the first quadrant \(K = \mathbb{R}^2_+\)?
    &lt;ul&gt;
      &lt;li&gt;Test with \(x = (1, 0)^T \in K\): \(y^T x = -1 &amp;lt; 0\). So \(y \notin (\mathbb{R}^2_+)^* = \mathbb{R}^2_+\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-uses-of-duality&quot;&gt;⚡ &lt;strong&gt;Uses of Duality&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;two-main-uses-of-duality&quot;&gt;&lt;strong&gt;Two main uses of duality&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. The Duality Gap as a Stopping Criterion:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Duality gap:&lt;/strong&gt; \(f(x) - g(u,v)\) with \(x\) primal feasible, \((u,v)\) dual feasible&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Upper bound on suboptimality:&lt;/strong&gt; \(f(x) - f^* \le f(x) - g(u,v)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimality test:&lt;/strong&gt; If the duality gap = 0 then \(x\) is optimal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical stopping:&lt;/strong&gt; Stop the algorithm when the duality gap is \(&amp;lt; \epsilon\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Solving Primal via Dual:&lt;/strong&gt;
Given a dual optimal \(u^*, v^*\) and strong duality:
\(x^* = \arg\min_x L(x, u^*, v^*) = \arg\min_x \left\{ f(x) + \sum u_i^* h_i(x) + \sum v_j^* l_j(x) \right\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantage:&lt;/strong&gt; The dual may be easier to solve than the primal&lt;/p&gt;

&lt;h3 id=&quot;-solving-the-primal-via-the-dual&quot;&gt;🔄 &lt;strong&gt;Solving the Primal via the Dual&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;separable-problems&quot;&gt;&lt;strong&gt;Separable problems&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(\min_x \sum_{i=1}^n f_i(x_i) \quad \text{s.t.} \quad a^T x = b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual function:&lt;/strong&gt;
\(g(v) = bv - \sum_{i=1}^n f_i^*(a_i v)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual problem:&lt;/strong&gt; \(\max_v bv - \sum_{i=1}^n f_i^*(a_i v)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recovery primal solution:&lt;/strong&gt;
Once \(v^*\) is known, solve: \(\nabla f_i(x_i^*) = a_i v^*\) for each \(i\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Scalar optimization:&lt;/strong&gt; The dual has only 1 variable \(v\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parallel computation:&lt;/strong&gt; Each \(f_i^*\) is computed independently&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closed-form:&lt;/strong&gt; Many \(f_i^*\) have an analytical form&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-dual-norms&quot;&gt;📏 &lt;strong&gt;Dual Norms&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Given a norm \(\lVert x \rVert\), the &lt;strong&gt;dual norm&lt;/strong&gt; \(\lVert x \rVert_*\) is defined as:
\(\lVert z \rVert_* = \max_{\lVert x \rVert \le 1} z^T x\)&lt;/p&gt;

&lt;h4 id=&quot;basic-properties&quot;&gt;&lt;strong&gt;Basic properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Generalized Cauchy-Schwarz:&lt;/strong&gt; \(\lvert z^T x \rvert \le \lVert z \rVert_* \lVert x \rVert\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Double dual:&lt;/strong&gt; \(\lVert x \rVert_{**} = \lVert x \rVert\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always a norm:&lt;/strong&gt; \(\lVert \cdot \rVert_*\) is always a norm (a supremum of linear functions, hence always convex)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;important-examples&quot;&gt;&lt;strong&gt;Important examples&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(\ell_p\) norms:&lt;/strong&gt; \((\lVert x \rVert_p)_* = \lVert x \rVert_q\) with \(\frac{1}{p} + \frac{1}{q} = 1\)
    &lt;ul&gt;
      &lt;li&gt;
\[(\lVert x \rVert_1)_* = \lVert x \rVert_\infty\]
      &lt;/li&gt;
      &lt;li&gt;
\[(\lVert x \rVert_2)_* = \lVert x \rVert_2\]
      &lt;/li&gt;
      &lt;li&gt;
\[(\lVert x \rVert_\infty)_* = \lVert x \rVert_1\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrix norms:&lt;/strong&gt; \((\lVert X \rVert_{tr})_* = \lVert X \rVert_{op} = \sigma_1(X)\) (largest singular value)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;dual-norm-characterization&quot;&gt;&lt;strong&gt;Dual norm characterization&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(\min_y \lVert y \rVert \quad \text{s.t.} \quad y = x\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual problem:&lt;/strong&gt; \(\max_{\lVert u \rVert_* \le 1} u^T x\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; \(\lVert x \rVert = \max_{\lVert u \rVert_* \le 1} u^T x\)&lt;/p&gt;

&lt;h3 id=&quot;-example-the-lasso-dual&quot;&gt;🎯 &lt;strong&gt;Example: The LASSO Dual&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;primal-lasso&quot;&gt;&lt;strong&gt;Primal LASSO&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_\beta \frac{1}{2}\lVert y - X\beta \rVert_2^2 + \lambda \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;h4 id=&quot;reformulation&quot;&gt;&lt;strong&gt;Reformulation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{\beta,z} \frac{1}{2}\lVert y - z \rVert_2^2 + \lambda \lVert \beta \rVert_1 \quad \text{s.t.} \quad z = X\beta\)&lt;/p&gt;

&lt;h4 id=&quot;dual-derivation&quot;&gt;&lt;strong&gt;Dual derivation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt;
\(L(\beta,z,u) = \frac{1}{2}\lVert y - z \rVert_2^2 + \lambda \lVert \beta \rVert_1 + u^T(z - X\beta)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual function:&lt;/strong&gt;
\(g(u) = \frac{1}{2}\lVert y \rVert_2^2 - \frac{1}{2}\lVert y - u \rVert_2^2 - I_{\{\lVert X^T u \rVert_\infty \le \lambda\}}(u)\)&lt;/p&gt;

&lt;h4 id=&quot;lasso-dual-problem&quot;&gt;&lt;strong&gt;LASSO dual problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_u \lVert y - u \rVert_2^2 \quad \text{s.t.} \quad \lVert X^T u \rVert_\infty \le \lambda\)&lt;/p&gt;

&lt;h4 id=&quot;primal-dual-relationship&quot;&gt;&lt;strong&gt;Primal-dual relationship&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; Slater’s condition satisfied&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal recovery:&lt;/strong&gt; \(X\beta^* = y - u^*\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Residual interpretation:&lt;/strong&gt; \(u^*\) is the dual residual&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-conjugate-functions-and-dual-problems&quot;&gt;🔗 &lt;strong&gt;Conjugate Functions and Dual Problems&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;conjugate-function&quot;&gt;&lt;strong&gt;Conjugate function&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f^*(u) = \sup_x \{u^T x - f(x)\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Equivalent:&lt;/strong&gt; \(-f^*(u) = \min_x \{f(x) - u^T x\}\)&lt;/p&gt;

&lt;h4 id=&quot;composite-problems&quot;&gt;&lt;strong&gt;Composite problems&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(\min_x f(x) + g(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Equivalent constrained form:&lt;/strong&gt;
\(\min_{x,z} f(x) + g(z) \quad \text{s.t.} \quad x = z\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual function:&lt;/strong&gt;
\(g(u) = \min_{x,z} f(x) + g(z) + u^T(z - x) = -f^*(u) - g^*(-u)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual problem:&lt;/strong&gt; \(\max_u -f^*(u) - g^*(-u)\)&lt;/p&gt;

&lt;h4 id=&quot;application-examples&quot;&gt;&lt;strong&gt;Application examples&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Indicator function:&lt;/strong&gt;
\(\min_x f(x) + I_C(x) \Rightarrow \max_u -f^*(u) - I_C^*(-u)\)&lt;/p&gt;

&lt;p&gt;where \(I_C^*\) is the support function of \(C\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Norm regularization:&lt;/strong&gt;
\(\min_x f(x) + \lVert x \rVert \Rightarrow \max_{\lVert u \rVert_* \le 1} -f^*(u)\)&lt;/p&gt;

&lt;h3 id=&quot;-dual-cones&quot;&gt;🔺 &lt;strong&gt;Dual Cones&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition-1&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Given a cone \(K \subseteq \mathbb{R}^n\), the &lt;strong&gt;dual cone&lt;/strong&gt; \(K^*\) is:
\(K^* = \{y : y^T x \ge 0 \quad \forall x \in K\}\)&lt;/p&gt;

&lt;h4 id=&quot;properties&quot;&gt;&lt;strong&gt;Properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Always convex:&lt;/strong&gt; \(K^*\) is always convex even when \(K\) is not convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Double dual:&lt;/strong&gt; If \(K\) is a closed convex cone then \(K^{**} = K\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric interpretation:&lt;/strong&gt; \(y \in K^* \Leftrightarrow\) halfspace \(\{x : y^T x \ge 0\}\) contains \(K\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;important-examples-1&quot;&gt;&lt;strong&gt;Important examples&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Linear subspace:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(V\) subspace:&lt;/strong&gt; \(V^* = V^\perp\) (orthogonal complement)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Row space:&lt;/strong&gt; \((row(A))^* = null(A)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Norm cones:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Norm cone:&lt;/strong&gt; \(K = \{(x,t) : \lVert x \rVert \le t\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual:&lt;/strong&gt; \(K^* = \{(y,s) : \lVert y \rVert_* \le s\}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Positive semidefinite cone:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Self-dual:&lt;/strong&gt; \((\mathbb{S}_+^n)^* = \mathbb{S}_+^n\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verification:&lt;/strong&gt; \(Y \succeq 0 \Leftrightarrow tr(YX) \ge 0 \quad \forall X \succeq 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-conic-programming-duality&quot;&gt;🎯 &lt;strong&gt;Conic Programming Duality&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;primal-conic-problem&quot;&gt;&lt;strong&gt;Primal conic problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) \quad \text{s.t.} \quad Ax \in K\)&lt;/p&gt;

&lt;h4 id=&quot;dual-conic-problem&quot;&gt;&lt;strong&gt;Dual conic problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max_u -f^*(A^T u) \quad \text{s.t.} \quad u \in K^*\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Derivation:&lt;/strong&gt; Using the support function \(I_K^*(y) = \max_{z \in K} z^T y\)&lt;/p&gt;

&lt;h4 id=&quot;example-second-order-cone-programming-socp&quot;&gt;&lt;strong&gt;Example: Second-Order Cone Programming (SOCP)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Primal:&lt;/strong&gt; \(\min c^T x \quad \text{s.t.} \quad \lVert A_i x + b_i \rVert_2 \le c_i^T x + d_i\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Equivalent conic form:&lt;/strong&gt; \(Ax + b \in K\) (stacking \((A_i x + b_i, c_i^T x + d_i)\)) with \(K\) a product of second-order cones&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt; \(\max -b^T u \quad \text{s.t.} \quad A^T u = c, \quad u \in K^*\)&lt;/p&gt;

&lt;h3 id=&quot;️-practical-techniques&quot;&gt;🛠️ &lt;strong&gt;Practical Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;when-to-use-duality&quot;&gt;&lt;strong&gt;When to use duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Dual easier:&lt;/strong&gt; Fewer variables, simpler structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bounds needed:&lt;/strong&gt; Duality gap for convergence monitoring&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity analysis:&lt;/strong&gt; Dual variables as shadow prices&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parallel computation:&lt;/strong&gt; Separable problems&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;computational-strategies&quot;&gt;&lt;strong&gt;Computational strategies:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual methods:&lt;/strong&gt; Update both simultaneously&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual decomposition:&lt;/strong&gt; Exploit separable structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Augmented Lagrangian:&lt;/strong&gt; Improve convergence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier methods:&lt;/strong&gt; Interior point approaches&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;common-applications&quot;&gt;&lt;strong&gt;Common applications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; SVM, regularized regression, matrix completion&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Signal processing:&lt;/strong&gt; Compressed sensing, image denoising&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Network optimization:&lt;/strong&gt; Flow problems, resource allocation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Finance:&lt;/strong&gt; Portfolio optimization, risk management&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-illustrative-examples&quot;&gt;💡 &lt;strong&gt;Illustrative Examples&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;simple-norm-minimization&quot;&gt;&lt;strong&gt;Simple norm minimization:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(\min_x \lVert x \rVert_2 \quad \text{s.t.} \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt; \(\max_{A^T u = 0} -b^T u\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt; Find \(u \perp row(A)\) maximizing \(-b^T u\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; \(u^* = -A^+ b\) (pseudoinverse)&lt;/p&gt;

&lt;h4 id=&quot;ell_1-minimization&quot;&gt;&lt;strong&gt;\(\ell_1\) minimization:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(\min_x \lVert x \rVert_1 \quad \text{s.t.} \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt; \(\max_{\lVert A^T u \rVert_\infty \le 1} b^T u\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Geometric interpretation:&lt;/strong&gt; Find \(u\) in the dual feasible set maximizing \(b^T u\)&lt;/p&gt;

&lt;h3 id=&quot;-connections-to-other-chapters&quot;&gt;🎯 &lt;strong&gt;Connections to Other Chapters&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-the-previous-chapter&quot;&gt;&lt;strong&gt;From the previous chapter:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 12:&lt;/strong&gt; KKT conditions - interpretation of dual variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 11:&lt;/strong&gt; General duality theory - the foundation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 10:&lt;/strong&gt; LP duality - a special case&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;importance-of-duality-uses&quot;&gt;&lt;strong&gt;Importance of Duality Uses:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Computational efficiency:&lt;/strong&gt; Solve easier dual instead of primal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm design:&lt;/strong&gt; Primal-dual methods, decomposition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical insights:&lt;/strong&gt; Optimality conditions, sensitivity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical applications:&lt;/strong&gt; Machine learning, signal processing&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;looking-ahead&quot;&gt;&lt;strong&gt;Looking ahead:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Interior point methods:&lt;/strong&gt; Barrier function approaches&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Decomposition methods:&lt;/strong&gt; ADMM, dual decomposition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic optimization:&lt;/strong&gt; Online dual methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust optimization:&lt;/strong&gt; Worst-case analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-theoretical-significance&quot;&gt;🌟 &lt;strong&gt;Theoretical Significance&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;duality-as-a-computational-tool&quot;&gt;&lt;strong&gt;Duality as a computational tool:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Alternative solution path:&lt;/strong&gt; The dual can be easier than the primal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parallel computation:&lt;/strong&gt; Separable structure exploitation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence monitoring:&lt;/strong&gt; The duality gap as a stopping criterion&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity analysis:&lt;/strong&gt; Dual variables interpretation&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;geometric-insights&quot;&gt;&lt;strong&gt;Geometric insights:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dual norms:&lt;/strong&gt; Characterize the unit balls of different norms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual cones:&lt;/strong&gt; Geometric duality in cone programming&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Support functions:&lt;/strong&gt; Convex analysis foundation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conjugate functions:&lt;/strong&gt; Legendre-Fenchel transform&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;algorithmic-implications&quot;&gt;&lt;strong&gt;Algorithmic implications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual methods:&lt;/strong&gt; Simultaneous updates&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Decomposition:&lt;/strong&gt; Exploit problem structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point:&lt;/strong&gt; Barrier function approaches&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Augmented Lagrangian:&lt;/strong&gt; Penalty method improvements&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;choosing-primal-vs-dual&quot;&gt;&lt;strong&gt;Choosing primal vs dual:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Variable count:&lt;/strong&gt; Fewer variables often easier&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constraint structure:&lt;/strong&gt; Simple constraints preferred&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Separability:&lt;/strong&gt; Dual exploits separable structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational resources:&lt;/strong&gt; Parallel vs sequential&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;implementation-tips&quot;&gt;&lt;strong&gt;Implementation tips:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Numerical stability:&lt;/strong&gt; Check condition numbers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence monitoring:&lt;/strong&gt; Use duality gap&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm starting:&lt;/strong&gt; Initialize with previous solutions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization:&lt;/strong&gt; Add small regularization for stability&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;common-pitfalls&quot;&gt;&lt;strong&gt;Common pitfalls:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Constraint qualifications:&lt;/strong&gt; Ensure strong duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical precision:&lt;/strong&gt; Duality gap sensitivity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infeasibility:&lt;/strong&gt; Handle primal/dual infeasible cases&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaling:&lt;/strong&gt; Proper problem scaling important&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-advanced-topics&quot;&gt;🔬 &lt;strong&gt;Advanced Topics&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;fenchel-duality&quot;&gt;&lt;strong&gt;Fenchel duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;General framework:&lt;/strong&gt; Conjugate function approach&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimax theorems:&lt;/strong&gt; Saddle point theory&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Variational problems:&lt;/strong&gt; Calculus of variations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal transport:&lt;/strong&gt; Kantorovich duality&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;conic-duality&quot;&gt;&lt;strong&gt;Conic duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Semidefinite programming:&lt;/strong&gt; Matrix optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-order cone programming:&lt;/strong&gt; Robust optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exponential cone:&lt;/strong&gt; Entropy optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Power cone:&lt;/strong&gt; Geometric programming&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;algorithmic-developments&quot;&gt;&lt;strong&gt;Algorithmic developments:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;First-order methods:&lt;/strong&gt; Accelerated gradient, FISTA&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual algorithms:&lt;/strong&gt; ADMM, Chambolle-Pock&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point methods:&lt;/strong&gt; Polynomial-time algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic methods:&lt;/strong&gt; Online optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-real-world-applications&quot;&gt;📈 &lt;strong&gt;Real-World Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;machine-learning&quot;&gt;&lt;strong&gt;Machine Learning:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;SVM:&lt;/strong&gt; Dual formulation enables kernel trick&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;LASSO:&lt;/strong&gt; Dual provides geometric insights&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrix completion:&lt;/strong&gt; Nuclear norm dual&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Deep learning:&lt;/strong&gt; Regularization via duality&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;signal-processing&quot;&gt;&lt;strong&gt;Signal Processing:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Compressed sensing:&lt;/strong&gt; \(\ell_1\) minimization dual&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Image denoising:&lt;/strong&gt; Total variation dual&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Filter design:&lt;/strong&gt; Frequency domain duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Beamforming:&lt;/strong&gt; Array processing applications&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;operations-research&quot;&gt;&lt;strong&gt;Operations Research:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Network flows:&lt;/strong&gt; Max-flow min-cut duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Resource allocation:&lt;/strong&gt; Shadow price interpretation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Production planning:&lt;/strong&gt; Capacity constraint duals&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Transportation:&lt;/strong&gt; Assignment problem duality&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;finance&quot;&gt;&lt;strong&gt;Finance:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Portfolio optimization:&lt;/strong&gt; Risk-return duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Option pricing:&lt;/strong&gt; Risk-neutral measure duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Risk management:&lt;/strong&gt; Coherent risk measure duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic trading:&lt;/strong&gt; Execution cost optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-future-directions&quot;&gt;🔮 &lt;strong&gt;Future Directions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;emerging-applications&quot;&gt;&lt;strong&gt;Emerging applications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quantum optimization:&lt;/strong&gt; Quantum duality theory&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Distributed optimization:&lt;/strong&gt; Consensus and duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust optimization:&lt;/strong&gt; Distributionally robust duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Online learning:&lt;/strong&gt; Regret minimization duality&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;computational-advances&quot;&gt;&lt;strong&gt;Computational advances:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;GPU acceleration:&lt;/strong&gt; Parallel dual methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quantum computing:&lt;/strong&gt; Quantum optimization algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Approximate methods:&lt;/strong&gt; Inexact dual solutions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive algorithms:&lt;/strong&gt; Problem-specific dual methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-key-insights&quot;&gt;💎 &lt;strong&gt;Key Insights&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;duality-transformations&quot;&gt;&lt;strong&gt;Duality transformations:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Problem reformulation:&lt;/strong&gt; Convert hard primal to easy dual&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric interpretation:&lt;/strong&gt; Dual norms, cones provide insights&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational efficiency:&lt;/strong&gt; Exploit separable structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical understanding:&lt;/strong&gt; Optimality, sensitivity analysis&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;practical-impact&quot;&gt;&lt;strong&gt;Practical impact:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm design:&lt;/strong&gt; Foundation for modern optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Software implementation:&lt;/strong&gt; Dual methods in solvers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Real-world problems:&lt;/strong&gt; Enable the solution of large-scale problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interdisciplinary applications:&lt;/strong&gt; Across science and engineering&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-legacy-of-chapter-13&quot;&gt;🌟 &lt;strong&gt;Legacy of Chapter 13:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Computational revolution:&lt;/strong&gt; Duality enables efficient algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical unification:&lt;/strong&gt; Connects diverse optimization areas&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical impact:&lt;/strong&gt; Solves real-world problems efficiently&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Educational value:&lt;/strong&gt; Bridges theory and applications&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scientific influence:&lt;/strong&gt; Foundation for modern optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Final message:&lt;/strong&gt; Duality is not just a mathematical curiosity - it is a &lt;strong&gt;powerful computational tool&lt;/strong&gt; enabling the efficient solution of complex optimization problems across science, engineering, and machine learning!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the uses and correspondences of duality, including conjugate functions, dual norms, the LASSO dual, dual cones and advanced duality concepts.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🔄 Quiz: Uses and Correspondences of Duality&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: The conjugate function $$f^*(y)$$ is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) $$f^*(y) = \max_x (y^T x - f(x))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) $$f^*(y) = \min_x (y^T x - f(x))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) $$f^*(y) = \max_x (y^T x + f(x))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) $$f^*(y) = f(y)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f^*(y) = \max_x (y^T x - f(x))$$&lt;/strong&gt;&lt;br /&gt;
                The conjugate function (Legendre-Fenchel transform) is the supremum of the linear function $$y^T x$$ minus $$f(x)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The conjugate function $$f^*$$ has the property of being:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) Always convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) Always concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Of the same convexity as $$f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Undeterminable&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Always convex&lt;/strong&gt;&lt;br /&gt;
                The conjugate function is always convex because it is a supremum of affine functions, whether or not $$f$$ is convex.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: If $$f$$ is convex and lower semicontinuous, then $$f^{**}$$ equals:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) $$f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) $$-f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) $$f^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) $$0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f$$&lt;/strong&gt;&lt;br /&gt;
                Fenchel-Moreau theorem: if $$f$$ is convex and lower semicontinuous then $$f^{**} = f$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: The dual norm $$\lVert x \rVert_*$$ is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$\lVert x \rVert_* = \max_{\lVert z \rVert \leq 1} z^T x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) $$\lVert x \rVert_* = \min_{\lVert z \rVert \leq 1} z^T x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) $$\lVert x \rVert_* = \max_{\lVert z \rVert = 1} z^T x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) $$\lVert x \rVert_* = \lVert x \rVert$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\|x\|_* = \max_{\|z\| \leq 1} z^T x$$&lt;/strong&gt;&lt;br /&gt;
                The dual norm is the maximum inner product with vectors in the unit ball of the primal norm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: The dual norm of the $$\ell_p$$ norm is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) $$\ell_p$$ norm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) $$\ell_q$$ norm with $$1/p + 1/q = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(\ell_\infty\) norm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \(\ell_1\) norm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\ell_q$$ norm with $$1/p + 1/q = 1$$&lt;/strong&gt;&lt;br /&gt;
                Hölder conjugate: the dual of $$\ell_p$$ is $$\ell_q$$ with $$1/p + 1/q = 1$$. In particular: the dual of $$\ell_1$$ is $$\ell_\infty$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: Hölder&apos;s inequality has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(|x^T y| \leq \|x\|_p \|y\|_q\) with \(1/p + 1/q = 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(|x^T y| \leq \|x\|_p \|y\|_p\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(|x^T y| \geq \|x\|_p \|y\|_q\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(\|x + y\|_p \leq \|x\|_p + \|y\|_p\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$|x^T y| \leq \|x\|_p \|y\|_q$$ with $$1/p + 1/q = 1$$&lt;/strong&gt;&lt;br /&gt;
                Hölder&apos;s inequality generalizes Cauchy-Schwarz, relating dual norms to the inner product.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: The dual norm of the nuclear norm (trace norm) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Frobenius norm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Operator norm (spectral norm)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Nuclear norm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(\ell_1\) norm of the singular values&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Operator norm (spectral norm)&lt;/strong&gt;&lt;br /&gt;
                The dual of the nuclear norm $$\|X\|_* = \sum \sigma_i$$ is the operator norm $$\|X\|_{op} = \sigma_1$$ (largest singular value).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The LASSO dual problem has the constraint:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(\|A^T u\|_\infty \leq \lambda\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(\|A^T u\|_1 \leq \lambda\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(\|A^T u\|_2 \leq \lambda\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(\|u\|_2 \leq \lambda\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\|A^T u\|_\infty \leq \lambda$$&lt;/strong&gt;&lt;br /&gt;
                LASSO dual constraint: $$\|A^T u\|_\infty \leq \lambda$$ because the dual of the $$\ell_1$$ norm is the $$\ell_\infty$$ norm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The conjugate of \(f(x) = \frac{1}{2}x^T Q x\) with \(Q \succ 0\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(f^*(y) = \frac{1}{2}y^T Q^{-1} y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(f^*(y) = \frac{1}{2}y^T Q y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(f^*(y) = y^T Q^{-1} y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(f^*(y) = \frac{1}{2}y^T Q^{-2} y\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f^*(y) = \frac{1}{2}y^T Q^{-1} y$$&lt;/strong&gt;&lt;br /&gt;
                The conjugate of a quadratic form with $$Q \succ 0$$ is the quadratic form with $$Q^{-1}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: The conjugate of the indicator function \(I_C(x)\) of a convex set \(C\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(I_C^*(y) = \sup_{x \in C} y^T x\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(I_C^*(y) = \inf_{x \in C} y^T x\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(I_C^*(y) = I_C(y)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(I_C^*(y) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$I_C^*(y) = \sup_{x \in C} y^T x$$&lt;/strong&gt;&lt;br /&gt;
                The conjugate of an indicator function is the support function of the set $$C$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: The dual cone \(K^*\) of a cone \(K\) is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(K^* = \{y : y^T x \geq 0 \text{ for all } x \in K\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(K^* = \{y : y^T x \leq 0 \text{ for all } x \in K\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(K^* = \{y : y^T x = 0 \text{ for all } x \in K\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(K^* = K\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$K^* = \{y : y^T x \geq 0 \text{ for all } x \in K\}$$&lt;/strong&gt;&lt;br /&gt;
                The dual cone consists of the vectors that make a non-obtuse angle with every vector in the original cone.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: Which of the following cones is self-dual?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Positive orthant \(\mathbb{R}_+^n\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Second-order cone (Lorentz cone)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Positive semidefinite cone&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) All of the cones above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the cones above&lt;/strong&gt;&lt;br /&gt;
                The positive orthant, the second-order cone and the PSD cone are all self-dual: $$K^* = K$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The conjugate of a norm \(\|x\|\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(f^*(y) = I_{\{\|y\|_* \leq 1\}}(y)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(f^*(y) = \|y\|_*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(f^*(y) = \|y\|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(f^*(y) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f^*(y) = I_{\{\|y\|_* \leq 1\}}(y)$$&lt;/strong&gt;&lt;br /&gt;
                The conjugate of a norm is the indicator function of the dual-norm unit ball.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: The Fenchel duality theorem for the problem \(\min f(x) + g(Ax)\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) \(\min f(x) + g(Ax) = \max -f^*(-A^T y) - g^*(y)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) \(\min f(x) + g(Ax) = \max f^*(A^T y) + g^*(y)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) \(\min f(x) + g(Ax) = \min f^*(x) + g^*(Ax)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) There is no relation&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\min f(x) + g(Ax) = \max -f^*(-A^T y) - g^*(y)$$&lt;/strong&gt;&lt;br /&gt;
                Fenchel duality connects the primal problem with the dual problem through conjugate functions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: The Legendre transform is used when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(f\) is convex and differentiable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(f\) is concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(f\) is linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) \(f\) is non-convex&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f$$ is convex and differentiable&lt;/strong&gt;&lt;br /&gt;
                The Legendre transform is the special case of the conjugate function when $$f$$ is convex and differentiable.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16: Moreau envelope --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: The Moreau envelope \(M_\lambda f(x)\) is related to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Proximal operator&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Conjugate function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Smoothing of \(f\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                The Moreau envelope connects the proximal operator and the conjugate function, and provides a smooth approximation of $$f$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: The Fenchel-Young inequality states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) \(f(x) + f^*(y) \geq x^T y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) \(f(x) + f^*(y) \leq x^T y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) \(f(x) + f^*(y) = x^T y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) \(f(x) - f^*(y) \geq x^T y\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f(x) + f^*(y) \geq x^T y$$&lt;/strong&gt;&lt;br /&gt;
                Fenchel-Young inequality: $$f(x) + f^*(y) \geq x^T y$$ with equality when $$y \in \partial f(x)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: When should we solve the dual problem instead of the primal?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) When the dual has fewer variables&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) When the dual has a simpler structure&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) When strong duality holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) All of the above cases&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above cases&lt;/strong&gt;&lt;br /&gt;
                Solving the dual is advantageous when it has fewer variables, a simpler structure, or computational advantages, provided strong duality holds.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: The conjugate of \(f(x) = \max\{f_1(x), f_2(x)\}\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) \(f^*(y) = \max\{f_1^*(y), f_2^*(y)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) \(f^*(y) = \min\{f_1^*(y), f_2^*(y)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) \(f^*(y) = f_1^*(y) + f_2^*(y)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) \(f^*(y) = \inf\{\lambda_1 f_1^*(y_1/\lambda_1) + \lambda_2 f_2^*(y_2/\lambda_2) : y_1 + y_2 = y,\ \lambda_1 + \lambda_2 = 1, \lambda_i \geq 0\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) $$f^*(y) = \inf\{\lambda_1 f_1^*(y_1/\lambda_1) + \lambda_2 f_2^*(y_2/\lambda_2) : y_1 + y_2 = y,\ \lambda_1 + \lambda_2 = 1, \lambda_i \geq 0\}$$&lt;/strong&gt;&lt;br /&gt;
                For closed convex $$f_1, f_2$$: the conjugate of the max is the convex hull of $$\min\{f_1^*, f_2^*\}$$, which is exactly formula D (using perspectives). Answer B is only $$\min\{f_1^*, f_2^*\}$$, which is generally not convex and so cannot be a conjugate. Example: $$\max\{x, -x\} = |x|$$ has conjugate $$I_{[-1,1]}$$, whereas $$\min\{I_{\{1\}}, I_{\{-1\}}\} = I_{\{-1,1\}}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20: Applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: Conjugate duality is applied in:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Machine learning (regularization, kernel methods)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Signal processing (compressed sensing, denoising)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Economics (utility theory, market equilibrium)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above fields&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above fields&lt;/strong&gt;&lt;br /&gt;
                Conjugate duality has wide applications: ML (regularization), signal processing (sparsity), economics (utility maximization), and many other fields.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: Sensitivity analysis in optimization studies:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) How the solution changes when parameters change&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) The sensitivity of the algorithm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) The convergence rate&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Numerical accuracy&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) How the solution changes when parameters change&lt;/strong&gt;&lt;br /&gt;
                Sensitivity analysis studies how the optimal solution changes when the problem parameters change.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: In LP, the shadow price of constraint $$i$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) The value of the dual variable $$y_i^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) The value of a primal variable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) A coefficient in the objective function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Slack variable&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The value of the dual variable $$y_i^*$$&lt;/strong&gt;&lt;br /&gt;
                Shadow price = dual variable; it tells how much the optimal value increases when the constraint is relaxed by one unit.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: The envelope theorem in optimization states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$\frac{\partial f^*(\theta)}{\partial \theta} = \frac{\partial L}{\partial \theta}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$\frac{\partial f^*}{\partial x} = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$\frac{\partial^2 f^*}{\partial \theta^2} = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$f^*(\theta) = \text{const}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\frac{\partial f^*(\theta)}{\partial \theta} = \frac{\partial L}{\partial \theta}$$&lt;/strong&gt;&lt;br /&gt;
                Envelope theorem: the derivative of the optimal value with respect to a parameter equals the partial derivative of the Lagrangian.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: Parametric programming studies problems of the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$\min f(x,\theta)$$ subject to $$g(x,\theta) \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$\min f(x)$$ subject to $$g(x) \leq \theta$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Both A and B&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) No parameters&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) Both A and B&lt;/strong&gt;&lt;br /&gt;
                Parametric programming considers optimization problems with parameters in the objective and/or the constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: In portfolio optimization, when risk aversion increases:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) A less risky portfolio is chosen&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) A riskier portfolio is chosen&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Nothing changes&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Return is maximized&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) A less risky portfolio is chosen&lt;/strong&gt;&lt;br /&gt;
                Higher risk aversion leads to choosing a portfolio with lower variance (risk).
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;a&apos;, q3: &apos;a&apos;, q4: &apos;a&apos;, q5: &apos;b&apos;,
    q6: &apos;a&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;d&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;d&apos;, q17: &apos;a&apos;, q18: &apos;d&apos;, q19: &apos;d&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;c&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered advanced duality theory!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand conjugate functions and dual norms well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review the conjugate properties and Fenchel duality.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review conjugate functions and dual cones.&apos;;
    } else {
        message = &apos;📖 Study the advanced duality concepts again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>13-06 Dual subtleties & Double dual</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_06_Dual_subtleties_Double_dual/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_06_Dual_subtleties_Double_dual</id>
   <content type="html">&lt;p&gt;Two graduate students are asked to derive the dual of the exact same unconstrained optimization problem. Student A splits one term and obtains a dual with optimal value \(12\); Student B splits a different linear operator and then drops a constant factor of \(\frac{1}{2}\), obtaining a dual with optimal value \(24\). Who is wrong? Possibly &lt;em&gt;neither&lt;/em&gt;! Understanding how equivalent reformulations alter dual values—and when taking the dual of the dual brings you cleanly back to the primal—prevents subtle bugs when implementing primal-dual solvers.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-navigating-dual-subtleties-and-biduality&quot;&gt;Key ideas: Navigating Dual Subtleties and Biduality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Equivalent Reformulations Can Shift Optimal Values:&lt;/strong&gt; Dropping constants, scaling the dual objective, or taking a monotone transformation (like \(\log\)) preserves the optimal dual variables \(u^\star\), &lt;em&gt;but&lt;/em&gt; breaks the identity \(f(x^\star) = g(u^\star)\) when computing a duality gap.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Non-Uniqueness of Dummy-Variable Duals:&lt;/strong&gt; Introducing \(z = x\) versus \(z = Ax\) leads to structurally different dual problems with different dimensions and conditioning, even though both correspond to the same primal.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Linear-Constraint Double Dual via \(f^{**} = f\):&lt;/strong&gt; For \(\min_x f(x)\) s.t. \(Ax \le b, Cx = d\), the dual is \(\max_{u\ge 0, v} -f^*(-A^Tu - C^Tv) - b^Tu - d^Tv\). Taking its dual again yields \(f^{**}(x)\) under the same constraints—recovering the primal whenever \(f\) is closed and convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Nonlinear Biduality &amp;amp; Convexification:&lt;/strong&gt; Even with nonlinear convex inequalities \(h_i(x) \le 0\), closed convexity ensures the dual of the dual is the primal; for nonconvex problems, the double dual yields the tightest convex relaxation (biconjugate envelope).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-two-different-duals-of-the-same-problem--double-dual-recovery&quot;&gt;Worked example: Two Different Duals of the Same Problem &amp;amp; Double Dual Recovery&lt;/h3&gt;

&lt;p&gt;Consider the unconstrained quadratic \(\min_{x \in \mathbb{R}} \frac{1}{2}(2x - 4)^2 + \frac{1}{2}x^2\). Its true primal optimum is \(x^\star = \frac{8}{5} = 1.6\) with \(f^\star = \frac{1}{2}(-0.8)^2 + \frac{1}{2}(1.6)^2 = 0.32 + 1.28 = 1.6\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Dual A (Split \(z = 2x - 4\)):&lt;/strong&gt; Minimize \(\frac{1}{2}z^2 + \frac{1}{2}x^2\) s.t. \(z = 2x - 4\).
    &lt;ul&gt;
      &lt;li&gt;\(L(x,z,u) = \frac{1}{2}z^2 + \frac{1}{2}x^2 + u(2x - 4 - z)\).&lt;/li&gt;
      &lt;li&gt;Minimizing gives \(x = -2u\), \(z = u\), and \(g_A(u) = -\frac{5}{2}u^2 - 4u\).&lt;/li&gt;
      &lt;li&gt;Maximizing gives \(u^\star = -\frac{4}{5} = -0.8\) and \(g_A(u^\star) = -\frac{5}{2}(0.64) + 3.2 = 1.6 = f^\star\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual B (Transformed equivalent dual):&lt;/strong&gt; Dropping the factor \(\frac{1}{2}\) and flipping sign turns Dual A into \(\min_u 5u^2 + 8u\). Its minimizer is still \(u^\star = -0.8\) (which still recovers \(x^\star = -2u^\star = 1.6\)), &lt;em&gt;but&lt;/em&gt; its optimal value is \(-3.2 \ne 1.6\)! You must never plug \(-3.2\) directly into a duality-gap check \(f(x) - g(u)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the double dual of \(\min_{x \ge 1} \frac{1}{2}x^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal: \(\min_x \frac{1}{2}x^2\) s.t. \(-x \le -1\) (\(A = -1, b = -1\)).&lt;/li&gt;
      &lt;li&gt;Dual: \(\max_{u \ge 0} -\frac{1}{2}u^2 + u\) (equivalent to \(\min_{u \ge 0} \frac{1}{2}u^2 - u\)).&lt;/li&gt;
      &lt;li&gt;Dual of the dual (multiplier \(x \ge 0\) on \(-u \le 0\)): \(L_2(u,x) = \frac{1}{2}u^2 - u - xu\) minimized over \(u\) at \(u = 1+x\) gives \(-\frac{1}{2}(1+x)^2\), so maximizing over \(x \ge 0\) recovers \(-\min_{x \ge 1}\frac{1}{2}x^2\)—the exact original primal!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;dual-subtleties&quot;&gt;Dual subtleties&lt;/h2&gt;
&lt;p&gt;• Sometimes we can transform dual problems into equivalent problems and still call them dual problems. Also, in strong duality, we can use solutions of transformed dual problems for analyzing or computing characteristics of primal solutions.&lt;/p&gt;

&lt;h4 id=&quot;note&quot;&gt;[Note]&lt;/h4&gt;
&lt;p&gt;The optimal value of a transformed dual problem is not necessarily the optimal value of the primal.&lt;/p&gt;

&lt;p&gt;• A common way to derive dual problems for unconstrained problems is to first transform the primal by adding dummy variables and equality constraints.&lt;/p&gt;

&lt;p&gt;Generally, how to do this is ambiguous. Different choices can lead to different dual problems.&lt;/p&gt;

&lt;h2 id=&quot;double-dual&quot;&gt;Double dual&lt;/h2&gt;
&lt;p&gt;Let’s consider a general minimization problem with linear constraints:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) \text{ subject to } Ax ≤ b, Cx = d\]
&lt;/blockquote&gt;

&lt;p&gt;The Lagrangian is as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[L(x,u,v) = f(x) + (A^Tu + C^Tv)^Tx−b^Tu−d^Tv\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore, the dual problem is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_{u,v} −f^∗(−A^Tu−C^Tv)−b^Tu−d^Tv \text{ subject to } u ≥ 0\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;recall-property&quot;&gt;Recall property&lt;/h4&gt;
&lt;p&gt;If \(f\) is closed and convex, we explained earlier that the dual of the dual is the primal in this case (\(f^{∗∗} = f\)).&lt;/p&gt;

&lt;p&gt;In fact, the connection (between dual and dual conjugate) goes much deeper beyond linear constraints.
Consider the following:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \min_x &amp;amp;&amp;amp; f(x) \\
&amp;amp;\text{ subject to } &amp;amp;&amp;amp; h_i(x) ≤ 0, i = 1,...m \\
&amp;amp;&amp;amp;&amp;amp;l_j(x) = 0, j = 1,...r
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;If \(f\) and \(h_1,...h_m\) are closed and convex, and \(l_1,...l_r\) are affine, then the dual of the dual is the primal.&lt;/p&gt;

&lt;p&gt;This is provided as a minimization problem from the perspective of bifunctions.&lt;/p&gt;

&lt;p&gt;(for more, read Chapters 29 and 30 of Rockafellar)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-05 Dual cones</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_05_Dual_cones/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_05_Dual_cones</id>
   <content type="html">&lt;p&gt;When you first learned Lagrange duality, every inequality constraint \(h_i(x) \le 0\) came with a nonnegative multiplier \(u_i \ge 0\)—geometrically, \(u\) lived in the nonnegative orthant \(\mathbb{R}^m_+\). What happens when your constraint is no longer a list of scalar inequalities, but a matrix semidefinite constraint \(X \succeq 0\) or a second-order cone constraint \(\|x\|_2 \le t\)? You need a generalized notion of “nonnegative multiplier” that keeps inner products nonnegative against the cone—and that object is the &lt;strong&gt;dual cone&lt;/strong&gt; \(K^*\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-and-algebra-of-dual-cones&quot;&gt;Key ideas: Geometry and Algebra of Dual Cones&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Acute-Angle Definition:&lt;/strong&gt; \(K^* = \{y : y^T x \ge 0\ \forall x \in K\}\) is the set of all vectors forming an angle of at most \(90^\circ\) with every ray in \(K\). Because it is an intersection of closed halfspaces, \(K^*\) is &lt;em&gt;always&lt;/em&gt; a closed convex cone.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Self-Dual Cones Dominate Convex Optimization:&lt;/strong&gt; The three workhorse cones—nonnegative orthant \(\mathbb{R}^n_+\), second-order (Lorentz) cone \(\mathcal{Q}^n\), and positive semidefinite cone \(\mathbb{S}^n_+\)—all satisfy \(K^* = K\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Polarity &amp;amp; Norm-Cone Pairing:&lt;/strong&gt; Narrower primal cones produce wider dual cones (if \(K_1 \subseteq K_2\), then \(K_2^* \subseteq K_1^*\)). For a norm cone \(K = \{(x,t) : \|x\| \le t\}\), its dual is the dual-norm cone \(K^* = \{(y,s) : \|y\|_* \le s\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Conic Duality Made Automatic:&lt;/strong&gt; For \(\min_x f(x)\) s.t. \(Ax \in K\), the support function \(I_K^*(-u)\) equals \(I_{K^*}(u)\), immediately yielding the conic dual \(\max_{u \in K^*} -f^*(A^T u)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-a-2d-dual-cone-and-checking-psd-self-duality&quot;&gt;Worked example: Computing a 2D Dual Cone and Checking PSD Self-Duality&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Part A — A 2D polyhedral cone:&lt;/strong&gt; Let \(K = \{x \in \mathbb{R}^2 : x_1 \ge 0,\ x_2 \ge 2x_1\}\) (a narrow wedge between the positive \(x_2\)-axis and the ray \((1,2)^T\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify the extreme rays of \(K\):&lt;/strong&gt; Any \(x \in K\) is a nonnegative combination of \(r_1 = (0, 1)^T\) and \(r_2 = (1, 2)^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enforce \(y^T x \ge 0\) on the generators:&lt;/strong&gt; \(y \in K^* \iff y^T r_1 \ge 0\) and \(y^T r_2 \ge 0\), which gives:
\(y_2 \ge 0 \qquad \text{and} \qquad y_1 + 2y_2 \ge 0 \iff y_2 \ge -\frac{1}{2}y_1.\)
Notice that \(K\) is a narrow wedge (aperture \(\approx 26.6^\circ\)), while \(K^*\) is a wide obtuse wedge (aperture \(\approx 153.4^\circ\)), summing to \(180^\circ\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Part B — Checking \(Y \in (\mathbb{S}^2_+)^*\):&lt;/strong&gt; Take \(Y = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}\) and \(X = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} \succeq 0\).&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Frobenius inner product:&lt;/strong&gt; \(\operatorname{tr}(YX) = 2(1) + (-1)(1) + (-1)(1) + 2(1) = 2 \ge 0\). Because \(Y\) has eigenvalues \(1, 3 &amp;gt; 0\), \(\operatorname{tr}(YX) = \sum_i \lambda_i(X)\, v_i^T Y v_i \ge 0\) for &lt;em&gt;all&lt;/em&gt; \(X \succeq 0\), illustrating \((\mathbb{S}^2_+)^* = \mathbb{S}^2_+\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;dual-cones&quot;&gt;Dual cones&lt;/h2&gt;
&lt;p&gt;There exists a cone \(K ⊆ \mathbb{R}^n\).
(Recalling the content covered earlier in &lt;a href=&quot;/contents/en/chapter02/02_06_01_Dual_cones/&quot;&gt;02-06-01&lt;/a&gt;, this means \(x \in K, t ≥ 0 \to tx \in K\).)&lt;/p&gt;
&lt;blockquote&gt;
\[K∗ = \{ y : y^Tx ≥ 0 \text{ for all } x \in K \}\]
&lt;/blockquote&gt;

&lt;p&gt;This is called a &lt;strong&gt;dual cone&lt;/strong&gt;, and it is always a convex cone (even when \(K\) is not convex).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter13/dual_cone.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig3] Dual Cones [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h5 id=&quot;note&quot;&gt;[Note]&lt;/h5&gt;
&lt;p&gt;\(y \in K∗ \iff \text{ the halfspace } \{ x : y^Tx ≥ 0 \} \text { contains } K\)
(From B &amp;amp; V page 52)&lt;/p&gt;

&lt;p&gt;An important property here is that if \(K\) is closed and a convex cone, then \(K^{∗∗} = K\).&lt;/p&gt;

&lt;h4 id=&quot;examples&quot;&gt;Examples:&lt;/h4&gt;
&lt;p&gt;• The dual cone of a linear subspace \(V\) is \(V^{⊥}\), i.e., the orthogonal complement.
E.g., \((row(A))^{∗} = null(A)\)&lt;/p&gt;

&lt;p&gt;• The dual cone of the norm cone \(K = \{ (x,t) \in \mathbb{R}^n+1 : \| x \|≤ t \}\) is the norm cone of its dual norm \(K^{∗} = \{ (y,s) \in \mathbb{R}^{n+1} : \| y \|_{∗} ≤ s \}\).&lt;/p&gt;

&lt;p&gt;• The positive semidefinite cone \(\mathbb{S}^n_+\) is a self-dual convex cone, meaning \((\mathbb{S}^n_+)^{∗} = \mathbb{S}^n_+\).&lt;/p&gt;

&lt;p&gt;Why is this the case? Let’s verify:&lt;/p&gt;
&lt;blockquote&gt;
\[Y \succeq 0 \iff tr(Y X) ≥ 0 \text{ for all } X \succeq 0\]
&lt;/blockquote&gt;

&lt;p&gt;\(X\)’s eigenvalue decomposition&lt;/p&gt;

&lt;h2 id=&quot;dual-cones-and-dual-problems&quot;&gt;Dual cones and dual problems&lt;/h2&gt;
&lt;p&gt;Consider the cone constrained problem:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) \text{ subject to } Ax \in K\]
&lt;/blockquote&gt;

&lt;p&gt;When \(I^{∗}_K(y) = \max_{z\in K} z^Ty\) is the support function of \(K\),
the dual problem of the above expression is as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\max_u −f^∗(A^Tu)−I^∗_K(−u)\]
&lt;/blockquote&gt;

&lt;p&gt;When \(K\) is a cone, this can be easily defined as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\max_u −f^∗(A^Tu) \text{ subject to } u \in K^{∗}\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(K^{∗}\) is the dual cone of \(K\). because \(= I_K^{*}(-u) \ I_{K^{*}}(−u)\)&lt;/p&gt;

&lt;p&gt;This is quite useful because many different types of constraints can appear as cone constraints.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>13-04 Conjugate function</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_04_Conjugate_function/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_04_Conjugate_function</id>
   <content type="html">&lt;p&gt;Think of a convex function \(f(x)\) as the cost of producing \(x\) units of a good, and suppose the market pays a unit price \(y\) per unit sold. Your profit is \(y^T x - f(x)\). The maximum profit you can earn at price \(y\)—namely \(f^*(y) = \max_x (y^T x - f(x))\)—is the &lt;strong&gt;Fenchel conjugate&lt;/strong&gt; of \(f\). Remarkably, knowing the optimal profit curve \(f^*(y)\) for every price \(y\) lets you reconstruct the original convex cost curve \(f(x)\) without losing a single bit of information.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-fenchel-conjugate-engine&quot;&gt;Key ideas: The Fenchel Conjugate Engine&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Pointwise Supremum Guarantees Convexity:&lt;/strong&gt; Because \(y \mapsto y^T x - f(x)\) is affine in \(y\) for every fixed \(x\), \(f^*(y)\) is &lt;em&gt;always&lt;/em&gt; convex—even if the original function \(f\) is nonconvex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Fenchel–Young Inequality &amp;amp; Tightness:&lt;/strong&gt; For every \(x, y\), \(f(x) + f^*(y) \ge x^T y\). Equality holds if and only if \(y \in \partial f(x)\), linking slopes directly to primal-dual optimality.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Biconjugate Duality (\(f^{**} = f\)):&lt;/strong&gt; For any closed, proper convex function, conjugating twice recovers \(f\) exactly, giving the dual representation of a convex function as the envelope of all its supporting hyperplanes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Core Dictionary of Conjugates:&lt;/strong&gt; Quadratics map to inverse-Hessian quadratics (\(\frac{1}{2}x^T Q x \leftrightarrow \frac{1}{2}y^T Q^{-1} y\)), set indicators \(I_C\) map to support functions \(I_C^*\), and norms \(\|\cdot\|\) map to dual-norm unit-ball indicators \(I_{\{\|\cdot\|_*\le 1\}}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-a-conjugate-and-verifying-fenchels-inequality&quot;&gt;Worked example: Computing a Conjugate and Verifying Fenchel’s Inequality&lt;/h3&gt;

&lt;p&gt;Consider the scalar exponential cost \(f(x) = e^x\) on \(\mathbb{R}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Set up the conjugate definition:&lt;/strong&gt;
\(f^*(y) = \sup_{x \in \mathbb{R}} \left(yx - e^x\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Analyze the three regimes of \(y\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;If \(y &amp;lt; 0\):&lt;/strong&gt; Letting \(x \to -\infty\) makes \(yx \to +\infty\) while \(e^x \to 0\), so \(f^*(y) = +\infty\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;If \(y = 0\):&lt;/strong&gt; \(\sup_x (-e^x) = 0\) (approached as \(x \to -\infty\)), so \(f^*(0) = 0\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;If \(y &amp;gt; 0\):&lt;/strong&gt; Differentiate \(g(x) = yx - e^x\): \(g&apos;(x) = y - e^x = 0 \implies x^\star = \ln y\) (a global max since \(g&apos;&apos;(x) = -e^x &amp;lt; 0\)). Substituting back:
\(f^*(y) = y \ln y - y.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check Fenchel’s inequality numerically:&lt;/strong&gt; Pick \(x = 1\) and \(y = e^2 \approx 7.389\).
    &lt;ul&gt;
      &lt;li&gt;\(f(1) + f^*(e^2) = e + (e^2 \cdot 2 - e^2) = e + e^2 \approx 2.718 + 7.389 = 10.107\).&lt;/li&gt;
      &lt;li&gt;\(xy = 1 \cdot e^2 \approx 7.389 \le 10.107\) (strict inequality because \(y = e^2 \ne f&apos;(1) = e\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify equality at \(y = f&apos;(x)\):&lt;/strong&gt; At \(x = 1\) and \(y = e\), \(f(1) + f^*(e) = e + (e \ln e - e) = e = 1 \cdot e = xy\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For a given function \(f : \mathbb{R}^n → \mathbb{R}\), the conjugate \(f^{∗} : \mathbb{R}^n → \mathbb{R}\) is defined as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[f^{∗}(y) = \max_x y^Tx−f(x)\]
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter13/conjugate_function.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Illustration of conjugate function [1]&lt;/figcaption&gt;
&lt;/p&gt;


### [Note] 
$$f^{∗}$$ is always convex since it is the pointwise maximum of convex (affine) functions $$y^Tx - f(x)$$.
(Here, $$f$$ does not necessarily need to be convex.)
$$f^{∗}(y)$$ is the maximum gap between the linear function $$y^Tx$$ and $$f(x)$$.
(From B &amp;amp; V page 91)

Conjugation for differentiable $$f$$ is called the Legendre transform.

#### Properties: 
• Fenchel’s inequality: for any $$x,y, f(x) + f^{∗}(y) ≥ x^Ty$$
&amp;gt; $$f(x) + f^{∗}(y) ≥ x^Ty \iff f^{*}(y) \ge x^Ty - f(x)$$
&amp;gt; $$ f^{*}(y) = \max_z z^Ty - f(x)$$

• The conjugate of a conjugate is $$f^{∗∗}$$, so $$f^{∗∗} ≤ f$$ holds.&lt;br /&gt;
• If $$f$$ is closed and convex, then $$f^{∗∗} = f$$. &lt;br /&gt;
• If $$f$$ is closed and convex, then for all $$x,y$$, the following holds:&lt;br /&gt;
&amp;gt; $$\begin{align}
&amp;gt; x ∈ ∂f^{∗}(y) &amp;amp;\iff y ∈ ∂f(x) \\\
&amp;gt; &amp;amp;\iff f(x) + f^{∗}(y) = x^Ty \\\
&amp;gt; \end{align}$$

• If $$f(u,v) = f_1(u) + f_2(v)$$, then $$f^{∗}(w,z) = f_1^{∗}(w) + f_2^{∗}(z)$$ holds. 



#### Examples: 
• Let&apos;s examine the case where $$f(x)$$ is a simple quadratic as follows:
&amp;gt; $$f(x) = \frac{1}{2}x^TQx$$, where $$Q \succ 0$$

Then $$y^Tx− \frac{1}{2}x^TQx$$ is strictly concave in $$y$$ and reaches its maximum at $$x = Q^{−1}y$$. That is, $$f^{∗}(y) = \frac{1}{2}y^TQ^{−1}y$$. 



### [Proof]
&amp;gt; $$\begin{align}
&amp;gt; f^{*}(y) &amp;amp; =  \max_x \left( y^Tx -\frac{1}{2}x^TQx \right) \\\
&amp;gt; &amp;amp; = -\min_x \left(\frac{1}{2}x^TQx- y^Tx \right), x^{\star} = Q^{-1}y  \\\
&amp;gt; &amp;amp; = -\frac{1}{2}y^TQ^{-1}QQ^{-1}y + y^TQ^{-1}y \\\
&amp;gt; &amp;amp; = \frac{1}{2}y^TQ^{-1}y  \\\
&amp;gt; \end{align}$$

&amp;gt; Fenchel&apos;s inequality: for any $$x, y$$
&amp;gt; $$\frac{1}{2} x^TQx + \frac{1}{2} y^TQ^{-1}y \ge x^Ty$$

• Indicator function: If $$f(x) = I_C(x)$$, then its conjugate is as follows:

&amp;gt; $$f^{∗}(y) = I^{∗}_C(y) = \max_{x ∈ C} y^Tx$$ called the **support function** of $$C$$

• Norm: If $$f(x) = \|x\|$$, then its conjugate is as follows:
&amp;gt; $$f^{∗}(y) = I_{\\{ z : \rVert z \rVert_{∗} ≤ 1 \\}}(y)$$ where $$\rVert · \rVert_{∗}$$ is the dual norm of $$\rVert · \rVert$$ 

&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>13-04-03 Shifting linear transformations</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_04_03_Shifting_linear_transformations/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_04_03_Shifting_linear_transformations</id>
   <content type="html">&lt;p&gt;Consider fused-lasso or total-variation denoising: \(\min_x \frac{1}{2}\|x - y\|_2^2 + \lambda\|Dx\|_1\), where \(D\) is a finite-difference matrix. Because \(D\) sits &lt;em&gt;inside&lt;/em&gt; the nonsmooth \(\ell_1\) norm, you cannot apply coordinate-wise soft-thresholding directly to \(x\). Duality performs a neat sleight of hand: by introducing \(z = Dx\), it migrates the matrix out of the nonsmooth term \(g\) and attaches its transpose \(D^T\) to the smooth conjugate \(f^*\)—turning a hard nonsmooth problem into a smooth quadratic over a simple box!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-migrating-linear-maps-via-duality&quot;&gt;Key ideas: Migrating Linear Maps via Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The Linear-Composition Bottleneck:&lt;/strong&gt; Even when \(f\) and \(g\) are each simple to minimize alone, composing a nonsmooth \(g\) with a linear operator \(A\) (as in \(g(Ax)\)) couples coordinates and breaks closed-form proximal steps.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Splitting \(Ax = z\) Transfers \(A\) to \(A^T\):&lt;/strong&gt; Forming \(L(x,z,u) = f(x) + g(z) + u^T(z - Ax)\) pairs \(x\) with \(A^T u\) and \(z\) with \(-u\), producing the Fenchel dual \(\max_u -f^*(A^T u) - g^*(-u)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Smoothness Swap:&lt;/strong&gt; When \(f\) is strongly convex (so \(f^*\) is smooth) and \(g(\cdot) = \|\cdot\|\) is a norm, the dual \(\max_{\|u\|_*\le 1} -f^*(A^T u)\) is a &lt;em&gt;smooth&lt;/em&gt; maximization over a simple dual-norm ball—ideal for projected gradient or L-BFGS.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Primal Recovery via Conjugate Gradient:&lt;/strong&gt; Once \(u^\star\) is found, \(x^\star = \nabla f^*(A^T u^\star)\) reconstructs the primal solution directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-1d-total-variation-denoising-via-shifting-d&quot;&gt;Worked example: 1D Total-Variation Denoising via Shifting \(D\)&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) + g(Dx) = \frac{1}{2}\|x - y\|_2^2 + \|Dx\|_1\) for \(y = \begin{bmatrix} 0 \\ 4 \end{bmatrix}\) and \(D = \begin{bmatrix} -1 &amp;amp; 1 \end{bmatrix}\) (so \(Dx = x_2 - x_1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute conjugates:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f^*(w) = \frac{1}{2}\|w\|_2^2 + y^T w\) (minimizer \(x = y + w\)).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;$$g^*(-u) = I_{{&lt;/td&gt;
              &lt;td&gt;u&lt;/td&gt;
              &lt;td&gt;\le 1}}(u)\(for scalar\)u \in \mathbb{R}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Shift \(D\) to \(f^*\) in the dual:&lt;/strong&gt; Since \(D^T u = \begin{bmatrix} -u \\ u \end{bmatrix}\),
\(-f^*(D^T u) = -\frac{1}{2}\big((-u)^2 + u^2\big) - \big(0(-u) + 4u\big) = -u^2 - 4u.\)
The dual problem is \(\max_{|u| \le 1} (-u^2 - 4u)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the 1D box-constrained quadratic:&lt;/strong&gt; The unconstrained peak of \(-u^2 - 4u\) is at \(u = -2\). Clipping to \([-1, 1]\) gives \(u^\star = -1\), with dual value \(-(-1)^2 - 4(-1) = 3\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recover \(x^\star = y + D^T u^\star\):&lt;/strong&gt;
\(x^\star = \begin{bmatrix} 0 \\ 4 \end{bmatrix} + \begin{bmatrix} 1 \\ -1 \end{bmatrix} = \begin{bmatrix} 1 \\ 3 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Verify strong duality:&lt;/strong&gt; Primal value at \(x^\star = (1,3)^T\) is $$\frac{1}{2}((1-0)^2 + (3-4)^2) +&lt;/td&gt;
          &lt;td&gt;3-1&lt;/td&gt;
          &lt;td&gt;= 1 + 2 = 3\(, matching the dual value\)3$$!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The dual formulation helps with shifting linear transformations between parts of the objective function and other domains.&lt;/p&gt;

&lt;p&gt;Let’s look at the following:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_x f(x) + g(Ax)\]
&lt;/blockquote&gt;

&lt;p&gt;The following expression is equivalent:&lt;/p&gt;
&lt;blockquote&gt;
\[min_{x,z} f(x) + g(z) \text { subject to } Ax = z\]
&lt;/blockquote&gt;

&lt;p&gt;This leads to the following dual process:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\text {g(u)} = \min_{x,z} f(x) + g(z) + u^T(z - Ax)\)
\(\qquad  = -\max_{x} (A^T u)^T x - f(x) - \max_{z} (-u)^T z - g(z)\)
\(\qquad = -\ f^* (A^T u) - g^* (-u)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And the dual is:&lt;/p&gt;
&lt;blockquote&gt;
\[\max_u -f^*(A^Tu) - g^*(-u)\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;example&quot;&gt;[Example]&lt;/h4&gt;
&lt;p&gt;Norms and their dual norms are related as follows: \(\| \cdot \|, \| \cdot \|^*\), the problems&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) +\| Ax \|\]

\[\max_u -f^*(A^Tu) \text{ subject to } \| u \|^* \leq 1\]
&lt;/blockquote&gt;

&lt;p&gt;The first expression is the primal, and the second is the dual, which can be solved directly.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-04-02 Conjugates and dual problems</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_04_02_Conjugates_and_dual_problems/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_04_02_Conjugates_and_dual_problems</id>
   <content type="html">&lt;p&gt;Many optimization problems in machine learning have the additive form \(\min_x f(x) + g(x)\): a data-fitting loss \(f\) plus a regularizer or constraint indicator \(g\). If you try to derive the Lagrange dual by hand from scratch every time, you repeat the same algebraic steps over and over. Conjugates turn that entire derivation into a one-line lookup table: split \(x = z\), and the dual instantly writes itself as \(\max_u -f^*(u) - g^*(-u)\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-composite-duality-via-conjugates&quot;&gt;Key ideas: Composite Duality via Conjugates&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Consensus Splitting (\(x = z\)):&lt;/strong&gt; Replacing \(\min_x f(x) + g(x)\) with \(\min_{x=z} f(x) + g(z)\) separates the two terms in the Lagrangian \(f(x) - u^T x + g(z) + u^T z\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Fenchel–Rockafellar Pattern:&lt;/strong&gt; Minimizing independently over \(x\) and \(z\) directly yields \(g_{\text{dual}}(u) = -f^*(u) - g^*(-u)\), turning primal sums into dual sums of negative conjugates.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Constraints Become Support Functions:&lt;/strong&gt; When \(g(x) = I_C(x)\) enforces \(x \in C\), its conjugate \(I_C^*(-u)\) is the support function of \(C\) evaluated at \(-u\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Norm Penalties Become Dual-Norm Balls:&lt;/strong&gt; When \(g(x) = \|x\|\), its conjugate \(g^*(-u)\) is the indicator of \(\{\|u\|_* \le 1\}\), converting a nonsmooth primal objective into a smooth dual objective over a simple norm ball.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-dualizing-a-quadratic--ell_1-problem-in-two-lines&quot;&gt;Worked example: Dualizing a Quadratic + \(\ell_1\) Problem in Two Lines&lt;/h3&gt;

&lt;p&gt;Consider \(\min_{x \in \mathbb{R}^2} \underbrace{\frac{1}{2}\|x - b\|_2^2}_{f(x)} + \underbrace{\|x\|_1}_{g(x)}\) with \(b = (2.5, -0.4)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Look up the two conjugates:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(f(x) = \frac{1}{2}\|x - b\|_2^2\): \(\max_x (u^T x - \frac{1}{2}\|x-b\|_2^2)\) is attained at \(x = b + u\), giving \(f^*(u) = \frac{1}{2}\|u\|_2^2 + b^T u\).&lt;/li&gt;
      &lt;li&gt;For \(g(x) = \|x\|_1\): \(g^*(-u) = I_{\{\|-u\|_\infty \le 1\}}(u) = I_{\{\|u\|_\infty \le 1\}}(u)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write the dual problem \(\max_u -f^*(u) - g^*(-u)\):&lt;/strong&gt;
\(\max_{\|u\|_\infty \le 1} -\frac{1}{2}\|u\|_2^2 - b^T u \iff \min_{\|u\|_\infty \le 1} \frac{1}{2}\|u + b\|_2^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the dual by clipping \(-b\) to \([-1, 1]^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(-b = (-2.5, 0.4)^T \implies u^\star = (-1, 0.4)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recover \(x^\star\) from \(x^\star = b + u^\star\):&lt;/strong&gt;
\(x^\star = (2.5 - 1,\ -0.4 + 0.4)^T = (1.5,\ 0)^T.\)
Notice that this matches coordinate-wise soft-thresholding \(S_1(b)\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check strong duality:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal value: \(\frac{1}{2}((1.5-2.5)^2 + (0 - (-0.4))^2) + (1.5 + 0) = \frac{1}{2}(1 + 0.16) + 1.5 = 2.08\).&lt;/li&gt;
      &lt;li&gt;Dual value: \(-\frac{1}{2}(1^2 + 0.4^2) - (2.5(-1) + (-0.4)(0.4)) = -0.58 + 2.5 + 0.16 = 2.08\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Conjugates can often be represented through the derivation of dual problems for Lagrangian minimization problems as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[−f^{∗}(u) = \min_x f(x)−u^Tx\]
&lt;/blockquote&gt;

&lt;p&gt;For example, consider the following expression:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x  f(x) + g(x)\]
&lt;/blockquote&gt;

&lt;p&gt;The following expression has constraints added to the above expression and is equivalent to it:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x,z} f(x) + g(z) \text{ subject to } x = z\]
&lt;/blockquote&gt;

&lt;p&gt;Converting this to a Lagrange dual function gives:&lt;/p&gt;

&lt;blockquote&gt;
\[g(u) = \min_{x,z} f(x) + g(z) + u^T(z−x) = −f^{∗}(u)−g^{∗}(−u)\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore, the dual problem of the original expression can be defined as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\max_u −f^{∗}(u)−g^{∗}(−u)\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;examples&quot;&gt;[Examples]&lt;/h4&gt;
&lt;p&gt;• Indicator function: The dual of \(\min_x f(x) + I_C(x)\) is as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\max_u −f^{∗}(u)−I^{∗}_C(−u)\]

  &lt;p&gt;where \(I^{∗}_C\) is the support function of \(C\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;• Norms:&lt;/p&gt;

&lt;p&gt;The dual of \(\min_x f(x) + \rVert x \rVert\) is as follows:
\(\max_u −f^{∗}(u) \text{ subject to } \rVert u \rVert^{∗} ≤ 1 \text{ where } \rVert · \rVert_{∗} \text{ is the dual norm of } \rVert · \rVert\)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-04-01 Example lasso dual</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_04_01_Example_lasso_dual/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_04_01_Example_lasso_dual</id>
   <content type="html">&lt;p&gt;At first glance, the Lasso objective \(\frac{1}{2}\|y - X\beta\|_2^2 + \lambda\|\beta\|_1\) has &lt;em&gt;no constraints&lt;/em&gt;—so taking its Lagrange dual directly yields a useless constant. Yet by introducing a single dummy residual variable \(z = X\beta\), the nonsmooth \(\ell_1\) penalty magically flips into an \(\ell_\infty\) polytope constraint, turning Lasso into the clean geometric problem of projecting the response vector \(y\) onto a polytope!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-the-lasso-dual&quot;&gt;Key ideas: Anatomy of the Lasso Dual&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Variable Splitting Creates a Nontrivial Dual:&lt;/strong&gt; Introducing \(z = X\beta\) decouples the smooth quadratic fit \(\frac{1}{2}\|y-z\|_2^2\) from the nonsmooth sparsity penalty \(\lambda\|\beta\|_1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Conjugate of Quadratic + Conjugate of \(\ell_1\) Norm:&lt;/strong&gt; Minimizing over \(z\) yields the shifted quadratic \(\frac{1}{2}\|y\|_2^2 - \frac{1}{2}\|y-u\|_2^2\), while minimizing over \(\beta\) produces the indicator constraint \(\|X^T u\|_\infty \le \lambda\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Geometric Projection View:&lt;/strong&gt; Maximizing \(\frac{1}{2}\|y\|_2^2 - \frac{1}{2}\|y-u\|_2^2\) over \(\|X^T u\|_\infty \le \lambda\) is identical to finding the Euclidean projection of \(y\) onto the dual polytope \(\mathcal{P}_\lambda = \{u : \|X^T u\|_\infty \le \lambda\}\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 4 — Primal–Dual Residual Link (\(X\beta^\star = y - u^\star\)):&lt;/strong&gt; Stationarity in \(z\) gives \(u^\star = y - X\beta^\star\), so the optimal dual vector is literally the Lasso fit’s residual vector, and active features correspond to facets of \(\mathcal{P}_\lambda\) where $$&lt;/td&gt;
          &lt;td&gt;x_j^T u^\star&lt;/td&gt;
          &lt;td&gt;= \lambda$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-a-2-observation-1-feature-lasso-via-its-dual&quot;&gt;Worked example: Solving a 2-Observation, 1-Feature Lasso via Its Dual&lt;/h3&gt;

&lt;p&gt;Let \(y = \begin{bmatrix} 3 \\ 1 \end{bmatrix}\), \(X = \begin{bmatrix} 1 \\ 1 \end{bmatrix}\), and \(\lambda = 2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the primal Lasso problem:&lt;/strong&gt;
\(\min_{\beta \in \mathbb{R}} \frac{1}{2}\big((3-\beta)^2 + (1-\beta)^2\big) + 2|\beta|.\)&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Write the dual projection problem:&lt;/strong&gt; We minimize \(\frac{1}{2}|y - u|_2^2\) subject to $$&lt;/td&gt;
          &lt;td&gt;X^T u&lt;/td&gt;
          &lt;td&gt;\le 2\(, i.e.,\)-2 \le u_1 + u_2 \le 2$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Project \(y = (3, 1)^T\) onto the slab \(u_1 + u_2 \le 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Check feasibility of \(y\): \(3 + 1 = 4 &amp;gt; 2\), so \(y\) is outside the slab and projects onto the hyperplane \(u_1 + u_2 = 2\) along the normal \(X = (1,1)^T\):
\(u^\star = y - \frac{X^T y - 2}{\|X\|_2^2} X = \begin{bmatrix} 3 \\ 1 \end{bmatrix} - \frac{4 - 2}{2}\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 2 \\ 0 \end{bmatrix}.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recover the primal fit and \(\beta^\star\) from \(X\beta^\star = y - u^\star\):&lt;/strong&gt;
\(X\beta^\star = \begin{bmatrix} 3 \\ 1 \end{bmatrix} - \begin{bmatrix} 2 \\ 0 \end{bmatrix} = \begin{bmatrix} 1 \\ 1 \end{bmatrix} \implies \beta^\star = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify zero duality gap:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Primal objective at \(\beta^\star = 1\): $$\frac{1}{2}((3-1)^2 + (1-1)^2) + 2&lt;/td&gt;
              &lt;td&gt;1&lt;/td&gt;
              &lt;td&gt;= \frac{1}{2}(4) + 2 = 4$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Dual objective at \(u^\star = (2,0)^T\): \(\frac{1}{2}\|y\|_2^2 - \frac{1}{2}\|y - u^\star\|_2^2 = \frac{1}{2}(10) - \frac{1}{2}(2) = 5 - 1 = 4\). Exact match!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s look at the lasso problem for \(y \in \mathbb{R}^n, X \in \mathbb{R}^{n\times p}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\min_\beta \frac{1}{2} \| y-X\beta \|^2_2 + \lambda\| \beta \|_1\]

\[f(\beta) = \frac{1}{2} \| y - X\beta \|^2_2 +  \lambda\| \beta \|_1\]

\[L(\beta) = f(\beta)\]

\[\min_\beta L(\beta) = f^{\star}\]
&lt;/blockquote&gt;

&lt;p&gt;The dual function of the above is constant (= \(f^*\)). Therefore, we can transform the primal problem as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{\beta,z} \frac{1}{2} \| y-z \|^2_2 + \lambda \| \beta \|_1 \text{ subject to } z = X\beta\]
&lt;/blockquote&gt;

&lt;p&gt;The dual function of the transformed problem is:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
g(u) &amp;amp;= \min_{\beta,z} \frac{1}{2} \| y-z \|^2_2 + \lambda \| \beta \|_1 + u^T(z-X\beta) \\
&amp;amp;= \frac{1}{2} \| y \|^2_2 - \frac{1}{2} \| y-u \|^2_2 - I_{\{ v : \| v \|_\infty \leq 1 \}}(X^Tu/\lambda) \\
\end{align}\]

&lt;/blockquote&gt;

&lt;h4 id=&quot;proof&quot;&gt;[Proof]&lt;/h4&gt;
&lt;blockquote&gt;
\[\begin{align}
g(u) &amp;amp;= \min_{\beta,z} \frac{1}{2} \| y-z \|^2_2 + \lambda \| \beta \|_1 + u^T(z-X\beta) \\
&amp;amp;= \underbrace{ \left( \min_z \frac{1}{2} \| y - z \|^2_2 + u^Tz \right)}_{(1)} + \underbrace{\left( \min_\beta  \lambda \| \beta \|_1 + u^TX\beta \right)}_{(2)} \\
\end{align}\]

\[z^{\star} = y - u\]

  &lt;p&gt;\(\begin{align}
(1) \cdots \left( \min_z \frac{1}{2} \| y - z \|^2_2 + u^Tz \right)
&amp;amp;= \frac{1}{2} \| u \|^2_2 + u^T(y - u) \\
&amp;amp;= -\frac{1}{2} \| y - u \|^2_2 + \frac{1}{2} \| y \|^2_2 \\
\end{align}\)
\(\begin{align}
(2) \cdots \left( \min_\beta  \lambda \| \beta \|_1 + u^TX\beta \right) 
&amp;amp;= - \lambda \max_\beta \frac{u^Tx}{\lambda} \beta - \| \beta \|_2 \\
&amp;amp;= - \lambda \left( \| \frac{u^Tx}{\lambda} \|_\infty \leq 1 \right) \\
&amp;amp;= - \lambda \left( \| u^Tx \|_\infty \leq \lambda \right) \\
\end{align}\)
\therefore g(u) = -\frac{1}{2} | y - u |^2_2 + \frac{1}{2} | y |^2_2 + - \lambda \left( | u^Tx |&lt;em&gt;\infty \leq \lambda \right)
= \frac{1}{2} | y |^2_2 - \frac{1}{2} | y-u |^2_2 - I&lt;/em&gt;{{ v : | v |_\infty \leq 1 }}(X^Tu/\lambda)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Therefore, the lasso dual problem is:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_u \frac{1}{2} ( \| y \|^2_2 - \| y-u \|^2_2 ) \text{ subject to } \| X^Tu \|_\infty \leq \lambda\]
&lt;/blockquote&gt;

&lt;p&gt;This is equivalent to:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_u \| y-u \|^2_2 \text{ subject to } \| X^Tu \|_\infty \leq \lambda\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;check&quot;&gt;[Check]&lt;/h3&gt;
&lt;p&gt;Slater’s condition is satisfied, so strong duality holds.&lt;/p&gt;
&lt;blockquote&gt;
\[\text{strong duality } \implies (\beta^{\star}, z^{\star})\]

\[\text{ must minimize  } L( \beta, z, u^{\star} ) \text{ over } -u, \beta, z\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;note&quot;&gt;[note]&lt;/h3&gt;
&lt;p&gt;The optimal value in the previous problem is not the optimal lasso objective value.
However, the dual solution \(u\) and the lasso solution \(\beta\) satisfy \(X\beta = y-u\).&lt;/p&gt;

&lt;p&gt;This is satisfied by the KKT stationarity condition \(z\) (i.e., \(z-y + \beta = 0\)).&lt;/p&gt;

&lt;p&gt;Therefore, lasso satisfies the dual residual.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter13/Conjugate_LassoDual_Example.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Lasso Dual [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;the-lasso-dual-as-a-projection-video&quot;&gt;The lasso dual as a projection (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/lasso-dual_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The dual asks for \(u\) with \(\|A^Tu\|_\infty\le\lambda\). The coordinates where this constraint is tight are exactly the nonzeros of the primal solution.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-lasso-primal-and-dual&quot;&gt;Try it yourself: lasso primal and dual&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;ld&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>13-03 Dual norms</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_03_Dual_norms/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_03_Dual_norms</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Suppose a portfolio manager caps your total trading volume using the \(\ell_1\) norm \(|z|_1 \le 1\), and you want to maximize expected return \(z^T x\) where \(x\) is the vector of asset returns. Where do you put all your budget? Straight into the single asset with the largest absolute return—yielding $$\max_i&lt;/td&gt;
      &lt;td&gt;x_i&lt;/td&gt;
      &lt;td&gt;= |x|&lt;em&gt;\infty\(! That simple economic reflex *is* the dual norm: every constraint ball\)|z| \le 1\(defines a natural yardstick\)|x|&lt;/em&gt;*$$ for linear payoffs.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;key-ideas-geometry-of-dual-norms&quot;&gt;Key ideas: Geometry of Dual Norms&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Dual Norm as Worst-Case Linear Alignment:&lt;/strong&gt; Defined by \(\|x\|_* = \max_{\|z\| \le 1} z^T x\), the dual norm measures the maximum inner product achievable against the primal unit ball.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 2 — Generalized Cauchy–Schwarz (Hölder) Inequality:&lt;/strong&gt; For any norm and its dual, $$&lt;/td&gt;
          &lt;td&gt;y^T x&lt;/td&gt;
          &lt;td&gt;\le |y|\,|x|_*$$ holds universally, decoupling primal perturbations from dual gradients.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Canonical Dual Pairs (\(\ell_p/\ell_q\) and Matrix Norms):&lt;/strong&gt; The \(\ell_1\) and \(\ell_\infty\) norms are duals, \(\ell_2\) is self-dual, general \(\ell_p\) pairs with \(\ell_q\) (\(1/p + 1/q = 1\)), and the nuclear/trace norm \(\|X\|_{\mathrm{tr}}\) pairs with the spectral/operator norm \(\|X\|_{\mathrm{op}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Reflexivity (\(\|x\|_{**} = \|x\|\)) via Strong Duality:&lt;/strong&gt; Rewriting \(\|x\|\) as \(\min_{y=x}\|y\|\) and taking the Lagrange dual recovers \(\max_{\|u\|_*\le 1} x^T u = \|x\|_{**}\), proving that taking the dual norm twice returns the original norm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-dual-norms-and-tight-aligning-vectors&quot;&gt;Worked example: Computing Dual Norms and Tight Aligning Vectors&lt;/h3&gt;

&lt;p&gt;Let \(x = (3, -4, 0)^T \in \mathbb{R}^3\). We compute \(\|x\|_*\) and the maximizing unit vector \(z^\star\) for three primal norms.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Primal norm \(\|\cdot\|_1 \implies\) Dual norm \(\|\cdot\|_\infty\):&lt;/strong&gt;
\(\|x\|_\infty = \max(|3|, |-4|, |0|) = 4.\)
Achieved at \(z^\star = (0, -1, 0)^T\), where \(\|z^\star\|_1 = 1\) and \((z^\star)^T x = (-1)(-4) = 4\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal norm \(\|\cdot\|_\infty \implies\) Dual norm \(\|\cdot\|_1\):&lt;/strong&gt;
\(\|x\|_1 = |3| + |-4| + |0| = 7.\)
Achieved at \(z^\star = \operatorname{sign}(x) = (1, -1, 0)^T\) (with \(\|z^\star\|_\infty = 1\)), giving \((z^\star)^T x = 3 + 4 + 0 = 7\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal norm \(\|\cdot\|_2 \implies\) Dual norm \(\|\cdot\|_2\):&lt;/strong&gt;
\(\|x\|_2 = \sqrt{3^2 + (-4)^2 + 0^2} = 5.\)
Achieved at \(z^\star = \frac{x}{\|x\|_2} = (0.6, -0.8, 0)^T\), giving \(\|z^\star\|_2 = 1\) and \((z^\star)^T x = 1.8 + 3.2 = 5\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Verify generalized Cauchy–Schwarz on a non-optimal test vector:&lt;/strong&gt; For \(y = (1, 1, 1)^T\), $$&lt;/td&gt;
          &lt;td&gt;y^T x&lt;/td&gt;
          &lt;td&gt;=&lt;/td&gt;
          &lt;td&gt;3 - 4&lt;/td&gt;
          &lt;td&gt;= 1 \le |y|&lt;em&gt;1 |x|&lt;/em&gt;\infty = 3 \times 4 = 12\(and\)1 \le |y|_\infty |x|_1 = 1 \times 7 = 7$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s examine an arbitrary &lt;strong&gt;norm&lt;/strong&gt; \(\| x \|\):&lt;/p&gt;

&lt;blockquote&gt;
\[l_p \text{ norm: } \lVert x \rVert_p = (\sum^n_{i=1} \rVert x_i \rVert_p)^{1/p}, \text{ for } p ≥ 1\]

\[\text{Trace norm: } \lVert X \rVert_{tr} = \sum^r_{i=1} σ_i(X)\]
&lt;/blockquote&gt;

&lt;p&gt;The &lt;strong&gt;dual norm&lt;/strong&gt; of norm \(\lVert x \rVert\) is denoted as \(\lVert x \rVert_{∗}\) and is defined as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\lVert x \rVert_{∗} = \max_{\lVert z \rVert ≤1} z^Tx\]
&lt;/blockquote&gt;

&lt;p&gt;Suppose there exists some arbitrary \(y\). Then when we let \(z = \frac{y}{\rVert y \rVert}\), we have \(\rVert z \rVert = 1\). Also, \(\rVert z^Tx \rVert \le \rVert x \rVert_{*}\) holds,
therefore a form similar to the &lt;em&gt;Cauchy-Schwartz inequality&lt;/em&gt; \(\rVert y^Tx \rVert \le \rVert y \rVert \rVert x \rVert_{*}\) is established.&lt;/p&gt;

&lt;p&gt;Let’s examine examples of dual norms under specific conditions:&lt;/p&gt;
&lt;blockquote&gt;
\[l_p \text{ norm dual: } (\lVert x \rVert_p)_{*} = \lVert x \rVert_{q}, \text{ where } 1/p + 1/q = 1\]

\[\text{Trace norm dual: } (\lVert X \rVert_{tr})_{*} = \lVert X \rVert_{op}) = σ_1(X)\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;proof&quot;&gt;[Proof]&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;Let’s prove that the following holds for the \(l_p\) norm dual:&lt;/p&gt;

\[(\lVert x \rVert_p)_{*} = \lVert x \rVert_{q}, \text{ where } 1/p + 1/q = 1 \qquad \text{(1)}\]

  &lt;p&gt;&lt;em&gt;Proof&lt;/em&gt;&lt;/p&gt;

\[(\lVert x \rVert_p)_{*} = \sup \{ z^Tx : x \in \mathbb{R}^n, \rVert x \rVert_q \le 1 \} \qquad  \text{(2)}\]

  &lt;p&gt;Meanwhile, by Holder’s inequality, the following holds:&lt;/p&gt;

\[z^T x ≤ \rVert z^tx \rVert 1 ≤ \rVert z \rVert_p \rVert x \rVert_q (\text{ where }, 1/p + 1/q = 1)\qquad \text{(3)}\]

  &lt;p&gt;From (1) above, the following relationship holds:&lt;/p&gt;

\[(\rVert z \rVert_q)_∗ ≤ \rVert z \rVert_p\qquad \text{(4)}\]

  &lt;p&gt;Therefore, if we find \(x\) such that \(\rVert x \rVert_q ≤ 1\) and \(z^Tx\) satisfies \(\rVert z \rVert_p\), we can see that \((\rVert z \rVert_q)_∗ = \rVert z \rVert\rVert_p\) holds.&lt;/p&gt;

  &lt;p&gt;Meanwhile, if we set \(y := sign(z) \rVert z\rVert^{p−1} \left( y_i = sign(z_i)\rVert z_i\rVert^{p−1} \right)\) and \(x = y\), then \(\rVert y \rVert_q\)
satisfies \(\rVert x \rVert_q =1\), and we can confirm that \(z^Tx = \rVert z \rVert_p\).&lt;/p&gt;

  &lt;p&gt;Therefore, the following holds:&lt;/p&gt;

\[( \rVert z \rVert_ q)_∗ = \rVert z \rVert_p, (1/p+1/q=1)\qquad \text{(5)}\]
&lt;/blockquote&gt;

&lt;p&gt;The dual norm of a dual norm becomes the original norm again.&lt;/p&gt;
&lt;blockquote&gt;
\[\lVert x \rVert_{**} = \lVert x \rVert\]
&lt;/blockquote&gt;

&lt;p&gt;Let’s examine the following problem:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_y \lVert y \rVert \qquad \text{ subject to } y = x\]
&lt;/blockquote&gt;

&lt;p&gt;When the optimal value is \(\rVert x \rVert\), the Lagrangian is expressed as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[L(y,u) = \rVert y \rVert+ u^T(x−y) = \rVert y \rVert − y^Tu + x^Tu\]
&lt;/blockquote&gt;

&lt;p&gt;When expressed in terms of the dual norm \((\lVert · \rVert_{∗})\), it becomes:&lt;/p&gt;
&lt;blockquote&gt;
\[\text{If } \rVert u \rVert_{∗} ≤ 1,\text{ then}  \qquad \min_y \{ \rVert y \rVert − y^Tu \} = 0\]

\[\text{If } \rVert u \rVert_{∗} &amp;gt; 1, \text{ then}  \qquad \min_y \{ \rVert y \rVert − y^Tu \} = −∞\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;note&quot;&gt;[Note]&lt;/h3&gt;
&lt;blockquote&gt;
\[\text{If } \rVert u \rVert_{∗} ≤ 1, \text{ then}  \qquad \min_y \{ \rVert y \rVert − y^Tu \} = 0\]

\[\max_y (y^Tu - \rVert y \rVert ) = 0\]

\[y^Tu \le \rVert y \rVert \rVert u \rVert_* \le \rVert y \rVert\]

\[\text{If } \rVert u \rVert_{∗} &amp;gt; 1, \text{ then}  \qquad \min_y \{ \rVert y \rVert − y^Tu \} = −∞\]

  &lt;p&gt;\(\text{Can always find} \qquad\) \(z\)  with \(\rVert z \rVert = 1 \qquad \text{ subject to }\qquad z^Tu = \rVert u \rVert_{*} \qquad ( argmax_{\rVert z \rVert \le 1}  z^Tu )\)&lt;/p&gt;

  &lt;p&gt;\(\text{take}\) \(y = t \cdot z, \qquad t &amp;gt; 0\)&lt;/p&gt;

\[y^Tu = t \cdot \rVert u \rVert_{*}\]

\[\text{ for this } y, \qquad y^Tu - \rVert y \rVert = t \cdot \rVert u \rVert_{*} - t \rightarrow ∞ \text{ as } t \rightarrow ∞\]

\[\text{ so therefore }  g(u) = \min_y L(y, u) = x^Tu - I(\rVert u \rVert_{*} \le 1)\]

  &lt;p&gt;dual problem&lt;/p&gt;

\[\max_u g(u) \iff \max_{\rVert u \rVert_{*} \le 1} x^Tu\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore, the Lagrange dual problem is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_u u^Tx \qquad \text{ subject to }\qquad \rVert u \rVert_{∗} ≤ 1\]
&lt;/blockquote&gt;

&lt;p&gt;Since there are no inequality constraints, Slater’s condition is satisfied, and according to strong duality, \(f^{\star} = g^{\star}\).
That is, \(\rVert x \rVert = \rVert x \rVert_{∗∗}\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>13-02 Solving the primal via the dual</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_02_Solving_the_primal_via_the_dual/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_02_Solving_the_primal_via_the_dual</id>
   <content type="html">&lt;p&gt;Imagine allocating power across 10,000 wireless channels to maximize total throughput subject to a single total power budget \(\sum_{i=1}^{10000} x_i = P\). Solving a 10,000-variable constrained problem directly looks daunting—until you dualize that single budget constraint. Suddenly, the 10,000 variables decouple completely into 10,000 trivial 1D problems coordinated by a &lt;em&gt;single&lt;/em&gt; scalar price \(v\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-decomposition-through-scalar-duality&quot;&gt;Key ideas: Decomposition Through Scalar Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Separable Objective Structure:&lt;/strong&gt; When \(f(x) = \sum_{i=1}^n f_i(x_i)\) has no cross-terms, the only coupling between coordinates is the linear constraint \(a^T x = b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Dualizing the Coupling Constraint:&lt;/strong&gt; Moving \(v(b - a^T x)\) into the Lagrangian turns the minimization over \(\mathbb{R}^n\) into \(n\) independent 1D minimizations, each producing \(-f_i^*(a_i v)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Dimensionality Collapse (\(n \to 1\)):&lt;/strong&gt; The dual problem \(\min_v \sum_{i=1}^n f_i^*(a_i v) - bv\) lives in \(\mathbb{R}^1\) regardless of how large \(n\) is, making 1D bisection or Newton’s method instantaneous.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Strict Convexity Guarantees Unique Recovery:&lt;/strong&gt; Once \(v^\star\) is found, each coordinate is recovered independently via the stationarity condition \(\nabla f_i(x_i^\star) = a_i v^\star\), which yields a unique primal optimum whenever each \(f_i\) is strictly convex.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-a-3-variable-separable-problem-via-a-1d-dual&quot;&gt;Worked example: Solving a 3-Variable Separable Problem via a 1D Dual&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = \frac{1}{2}x_1^2 + x_2^2 + \frac{3}{2}x_3^2\) subject to \(x_1 + 2x_2 + 3x_3 = 14\) (so \(a = (1, 2, 3)^T\), \(b = 14\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute each 1D conjugate \(f_i^*(s) = \max_{x_i}(s x_i - f_i(x_i))\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(f_1(x_1) = \frac{1}{2}x_1^2\): \(x_1 = s \implies f_1^*(s) = \frac{1}{2}s^2\).&lt;/li&gt;
      &lt;li&gt;For \(f_2(x_2) = x_2^2\): \(2x_2 = s \implies x_2 = \frac{s}{2} \implies f_2^*(s) = \frac{1}{4}s^2\).&lt;/li&gt;
      &lt;li&gt;For \(f_3(x_3) = \frac{3}{2}x_3^2\): \(3x_3 = s \implies x_3 = \frac{s}{3} \implies f_3^*(s) = \frac{1}{6}s^2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assemble the 1D dual objective \(\phi(v) = \sum_{i=1}^3 f_i^*(a_i v) - bv\):&lt;/strong&gt;
\(\phi(v) = \frac{1}{2}(1v)^2 + \frac{1}{4}(2v)^2 + \frac{1}{6}(3v)^2 - 14v = \left(\frac{1}{2} + 1 + \frac{3}{2}\right)v^2 - 14v = 3v^2 - 14v.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the scalar dual:&lt;/strong&gt; Set \(\phi&apos;(v) = 6v - 14 = 0 \implies v^\star = \frac{7}{3}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recover \(x^\star\) coordinate-by-coordinate from \(f_i&apos;(x_i^\star) = a_i v^\star\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x_1^\star = 1 \cdot \frac{7}{3} = \frac{7}{3}\),&lt;/li&gt;
      &lt;li&gt;\(2x_2^\star = 2 \cdot \frac{7}{3} \implies x_2^\star = \frac{7}{3}\),&lt;/li&gt;
      &lt;li&gt;\(3x_3^\star = 3 \cdot \frac{7}{3} \implies x_3^\star = \frac{7}{3}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify feasibility and strong duality:&lt;/strong&gt; \(x_1^\star + 2x_2^\star + 3x_3^\star = \frac{7}{3}(1+2+3) = 14\). Primal cost is \(\left(\frac{1}{2}+1+\frac{3}{2}\right)\left(\frac{7}{3}\right)^2 = 3 \cdot \frac{49}{9} = \frac{49}{3}\), and dual value is \(-\phi(7/3) = 14\cdot\frac{7}{3} - 3\cdot\frac{49}{9} = \frac{98-49}{3} = \frac{49}{3}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;an-important-consequence-of-stationarity&quot;&gt;An important consequence of stationarity&lt;/h3&gt;
&lt;p&gt;Under the condition of strong duality, when dual solution \(u^{\star}, v^{\star}\) is given, the primal solution \(x^{\star}\) can be found by solving the following Lagrangian:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) + \sum_{i=1}^m u_i^{\star} h_i(x) + \sum_{j=1}^r v^{\star}_i l_j(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Often, the solution to such unconstrained problems can be represented by explicitly bringing the characteristics of the primal solution through the dual solution.&lt;/p&gt;

&lt;p&gt;Moreover, if the solution to this problem is unique, the dual solution becomes the primal solution \(x^{\star}\).
This is very useful when solving the dual problem is easier than solving the primal problem directly.&lt;/p&gt;

&lt;h3 id=&quot;example-from-b--v-page-249&quot;&gt;Example from B &amp;amp; V page 249:&lt;/h3&gt;
&lt;blockquote&gt;
\[\min_x \sum_{i=1}^n f_i(x_i) \qquad \text{ subject to }\qquad a^Tx = b\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
\[\begin{align}
g(v) &amp;amp;= \min_x \sum_{i=1}^n f_i(x_i) + v(b−a^Tx) \\\
&amp;amp;= bv + \min_x \sum_{i=1}^n f_i(x_i) −va^Tx \\\
&amp;amp;= bv + \min_x \sum_{i=1}^n f_i(x_i) −v \sum_{i=1}^n a_ix_i \\\
&amp;amp;= bv + \sum_{i=1}^n (\underbrace{\min_{x_i} \{ f_i(x_i) − a_ivx_i \}}_{-f^{*}_i(a_iv)}) \\\
&amp;amp;= bv − \sum_{i=1}^n f^{*}_i (a_iv)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(f^{*}\) denotes the conjugate of \(f_i\).&lt;/p&gt;

&lt;p&gt;Therefore, the dual problem can be represented as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\max_v bv − \sum^n_{i=1} f^{*}_i (a_iv)\]
&lt;/blockquote&gt;

&lt;p&gt;Also, by multiplying by minus (-), the maximum problem can be represented as the following minimum problem:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_v \sum^n_{i=1} f^{*}_i (a_iv) − bv\]
&lt;/blockquote&gt;

&lt;p&gt;This is a convex minimization problem in scalar variables that can be solved much more easily than the primal problem.&lt;/p&gt;

&lt;p&gt;When \(v^{\star}\) is given, the primal solution \(x^{\star}\) can be solved as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_{x} \sum^n_{i=1} (f_i(x_i) − a_iv^{\star}x_i)\]
&lt;/blockquote&gt;

&lt;p&gt;The strict convexity of each \(f_i\) means that this has a unique solution.
That is, \(x^{\star}\) is obtained through the calculation of \(∇f_i(x_i) = a_iv^{\star}\) for each \(i\).&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>13-01 Uses of duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_01_Uses_of_duality/"/>
   <updated>2021-04-05T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter13/13_01_Uses_of_duality</id>
   <content type="html">&lt;p&gt;A classic headache in numerical optimization is deciding &lt;em&gt;when to stop&lt;/em&gt;. If an iterative solver slows down and the objective barely changes from step \(k\) to step \(k+1\), have you actually reached the optimum, or are you merely crawling across a flat plateau? The duality gap removes the guesswork: it replaces heuristic stopping rules with a rigorous mathematical guarantee of how far you can possibly be from \(f^\star\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-certificates-and-primal-recovery&quot;&gt;Key ideas: Certificates and Primal Recovery&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Weak Duality as a Lower-Bound Engine:&lt;/strong&gt; Because \(g(u,v) \le f^\star\) holds unconditionally for every dual-feasible \((u,v)\), any primal-feasible \(x\) immediately traps \(f^\star\) inside \([g(u,v), f(x)]\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — The Duality Gap as a Stopping Criterion:&lt;/strong&gt; Rearranging weak duality gives \(f(x) - f^\star \le f(x) - g(u,v)\). Terminating when \(f(x) - g(u,v) \le \varepsilon\) guarantees \(\varepsilon\)-suboptimality with zero assumptions on step sizes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Strong Duality &amp;amp; Lagrangian Minimization:&lt;/strong&gt; When \(f^\star = g^\star\), any primal optimum \(x^\star\) must minimize \(L(x, u^\star, v^\star)\) over all \(x\). Thus solving the dual first pins down the primal via an unconstrained minimization.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Uniqueness &amp;amp; Direct Primal Extraction:&lt;/strong&gt; Whenever \(x \mapsto L(x, u^\star, v^\star)\) has a unique minimizer (e.g., strictly convex \(f\)), that minimizer is automatically primal feasible and equals \(x^\star\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-certifying-suboptimality-and-recovering-xstar&quot;&gt;Worked example: Certifying Suboptimality and Recovering \(x^\star\)&lt;/h3&gt;

&lt;p&gt;Suppose we minimize \(f(x) = x_1^2 + 2x_2^2\) subject to \(x_1 + x_2 = 6\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Construct the Lagrangian and dual function:&lt;/strong&gt;
\(L(x_1, x_2, v) = x_1^2 + 2x_2^2 + v(6 - x_1 - x_2).\)
Setting \(\nabla_x L = 0\) gives \(2x_1 = v \implies x_1 = \frac{v}{2}\) and \(4x_2 = v \implies x_2 = \frac{v}{4}\). Substituting back:
\(g(v) = \frac{v^2}{4} + 2\frac{v^2}{16} + 6v - \frac{3v^2}{4} = 6v - \frac{3}{8}v^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test a suboptimal feasible pair for the duality gap:&lt;/strong&gt; Pick primal feasible \(x = (3, 3)\) (since \(3+3=6\)) and dual feasible \(v = 6\).
    &lt;ul&gt;
      &lt;li&gt;Primal value: \(f(3,3) = 9 + 18 = 27\).&lt;/li&gt;
      &lt;li&gt;Dual value: \(g(6) = 36 - \frac{3}{8}(36) = 36 - 13.5 = 22.5\).&lt;/li&gt;
      &lt;li&gt;Duality gap: \(27 - 22.5 = 4.5\), proving \(f(3,3) - f^\star \le 4.5\) without solving the primal!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the scalar dual:&lt;/strong&gt; Maximize \(g(v) = 6v - \frac{3}{8}v^2\) by setting \(g&apos;(v) = 6 - \frac{3}{4}v = 0 \implies v^\star = 8\), giving \(g(8) = 48 - 24 = 24\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recover the primal from \(v^\star = 8\):&lt;/strong&gt; Because \(L(\cdot, 8)\) is strictly convex, its unique minimizer is
\(x_1^\star = \frac{8}{2} = 4, \qquad x_2^\star = \frac{8}{4} = 2.\)
Check: \(x_1^\star + x_2^\star = 6\) and \(f(4,2) = 16 + 8 = 24 = g(8)\), confirming zero duality gap.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;two-key-uses-of-duality&quot;&gt;Two key uses of duality&lt;/h3&gt;
&lt;p&gt;Let’s revisit the two key characteristics of duality covered in Chapter 11.&lt;/p&gt;

&lt;p&gt;• When \(x\) is primal feasible and \(u,v\) are dual feasible, the difference between the primal problem \(f(x)\) and the dual problem \(g(u,v)\) is called the &lt;strong&gt;duality gap&lt;/strong&gt; between \(x\) and \(u,v\).&lt;/p&gt;
&lt;blockquote&gt;
\[f(x)-f^{\star}  \le f(x)-g(u, v)\]
&lt;/blockquote&gt;

&lt;p&gt;When the duality gap is 0, this is called zero duality gap, which means that the solution to the dual problem is optimal.
Also, the upper bound \(g(u, v)\) is always less than or equal to the optimal value \(f^{\star}\). For detailed reasons, please refer to the content in &lt;a href=&quot;/contents/en/chapter11/11_00_Duality_in_General_Programs/&quot;&gt;[Chapter 11]&lt;/a&gt;.
Therefore, the following derivation is possible.&lt;/p&gt;

&lt;h4 id=&quot;proof&quot;&gt;[Proof]&lt;/h4&gt;
&lt;blockquote&gt;
\[\begin{align*}
f^{\star} &amp;amp;\ge g(u, v) \\
-f^{\star} &amp;amp;\le -g(u, v) \\
f(x)-f^{\star} &amp;amp;\le \underbrace{f(x)-g(u, v)}_{\text{duality gap}}\\
g^{\star}-g(x) &amp;amp;\le \underbrace{f(x)-g(u, v)}_{\text{duality gap}}\\
\end{align*}\]
&lt;/blockquote&gt;

&lt;p&gt;Moreover, the duality gap can be used as a stopping criterion for algorithms.
• When dual optimal \(u^{\star}, v^{\star}\) are given, under the condition of strong duality, the primal solution minimizes the Lagrangian \(L (x, u^{\star}, v^{\star})\) for all \(x\) (i.e., satisfies the stationarity condition).&lt;/p&gt;

&lt;p&gt;This can be used for computing the primal solution.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>12-09 Bài Tập Thực Hành - Điều Kiện KKT</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_09_Practical_Exercises_KKT_Conditions/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_09_Practical_Exercises_KKT_Conditions</id>
   <content type="html">&lt;p&gt;Không có cách nào luyện phản xạ KKT sắc bén hơn việc tự tay giải trọn vẹn những bài toán kinh điển từ Boyd &amp;amp; Vandenberghe, Nocedal &amp;amp; Wright và Bertsekas: từ kiểm chứng KKT trên bài toán cơ bản, xây dựng mô hình phân bổ danh mục đầu tư Markowitz Mean–Variance, cho đến tự giải Hard-Margin SVM và bài toán phạt \(\ell_1\).&lt;/p&gt;

&lt;p&gt;Khi giải bài tập thực hành có 1–2 ràng buộc bất đẳng thức, chiến lược hiệu quả nhất gọi là &lt;strong&gt;phân nhánh tập ràng buộc hoạt động (Active-Set Case Splitting)&lt;/strong&gt;: giả sử một nhóm ràng buộc đang lỏng (\(u_i = 0\)) hoặc đang chặt (\(h_i(x) = 0\)), giải hệ phương trình dừng còn lại, rồi kiểm tra ngược xem nghiệm tìm ra có thỏa tính khả thi gốc (\(h_i \le 0\)) và đối ngẫu (\(u_i \ge 0\)) hay không. Khung tính tay dưới đây chạy mẫu trọn vẹn chiến lược này trên một bài toán phân bổ danh mục 2 tài sản nhỏ để bạn tự tin bước vào bộ bài tập!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-bước-thực-hành-giải-bài-tập-kkt-bằng-tay-và-code&quot;&gt;Kiến thức cần nhớ: Bốn bước thực hành giải bài tập KKT bằng tay và code&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Xác nhận tính lồi và dạng chuẩn:&lt;/strong&gt; Kiểm tra ma trận Hessian \(\nabla^2 f \succeq 0\), viết tất cả bất đẳng thức về \(h_i(x) \le 0\) để không bao giờ nhầm dấu trong hàm Lagrangian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Thiết lập đầy đủ 4 nhóm phương trình KKT:&lt;/strong&gt; Ghi rõ từng biến nhân tử \(u_i \ge 0\) (cho bất đẳng thức) và \(v_j \in \mathbb{R}\) (cho đẳng thức).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Phân nhánh tập hoạt động (Active Set):&lt;/strong&gt; Với mỗi bất đẳng thức \(h_i \le 0\), điều kiện bù \(u_i h_i(x) = 0\) tách thành hai nhánh: nhánh lỏng (\(u_i = 0\), kiểm tra \(h_i(x) \le 0\)) và nhánh chặt (\(h_i(x) = 0\), kiểm tra \(u_i \ge 0\)). Nhánh nào thỏa đủ 4 điều kiện KKT là dừng ngay (vì bài toán lồi)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — Đối chiếu bằng code (CVXPY / SciPy):&lt;/strong&gt; Sau khi giải tay, kiểm chứng lại cả nghiệm gốc \(x^*\) lẫn nhân tử đối ngẫu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;constraint.dual_value&lt;/code&gt; trong CVXPY để chắc chắn từng chữ số thập phân!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-bài-toán-phân-bổ-vốn-2-tài-sản-bằng-phân-nhánh-kkt&quot;&gt;Giải thích: Giải tay bài toán phân bổ vốn 2 tài sản bằng phân nhánh KKT&lt;/h3&gt;

&lt;p&gt;Cực tiểu hóa rủi ro danh mục 2 tài sản với tổng tỷ trọng bằng 1 và không bán khống:
\(\min_{w_1, w_2} \; \frac{1}{2}(2w_1^2 + 6w_2^2) - 2w_1 \quad \text{s.t.} \quad w_1 + w_2 = 1, \quad w_1 \ge 0, \; w_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập hệ KKT (\(v \in \mathbb{R}\) cho \(w_1 + w_2 = 1\); \(u_1, u_2 \ge 0\) cho \(-w_1 \le 0, -w_2 \le 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Dừng: \(2w_1 - 2 + v - u_1 = 0\) và \(6w_2 + v - u_2 = 0\).&lt;/li&gt;
      &lt;li&gt;Bù: \(u_1 w_1 = 0, \; u_2 w_2 = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử nhánh 1 — Cả hai tỷ trọng đều dương (\(w_1 &amp;gt; 0, w_2 &amp;gt; 0 \implies u_1 = u_2 = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Từ dừng: \(2w_1 - 2 + v = 0\) và \(6w_2 + v = 0 \implies 2w_1 - 2 = 6w_2\).&lt;/li&gt;
      &lt;li&gt;Thay \(w_2 = 1 - w_1\) vào: \(2w_1 - 2 = 6(1 - w_1) \implies 8w_1 = 8 \implies w_1 = 1, \; w_2 = 0\)!&lt;/li&gt;
      &lt;li&gt;Tính \(v\) từ hàng 2: \(v = -6(0) = 0\); kiểm tra hàng 1: \(2(1) - 2 + 0 = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng tất cả điều kiện KKT tại \(w^* = (1, 0), v^* = 0, u_1^* = 0, u_2^* = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Khả thi gốc: \(1 + 0 = 1\), \(w_1^* = 1 \ge 0, w_2^* = 0 \ge 0\) (thỏa!).&lt;/li&gt;
      &lt;li&gt;Khả thi đối ngẫu: \(u_1^* = 0 \ge 0, u_2^* = 0 \ge 0\) (thỏa!).&lt;/li&gt;
      &lt;li&gt;Bù: \(0(1) = 0, 0(0) = 0\) (thỏa!).
Vì bài toán lồi chặt (\(P = \text{diag}(2, 6) \succ 0\)), đây là &lt;strong&gt;nghiệm tối ưu toàn cục duy nhất&lt;/strong&gt;: dồn 100% vốn vào tài sản 1!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---điều-kiện-kkt-karushkuhntucker&quot;&gt;Bài tập thực hành - Điều kiện KKT (Karush–Kuhn–Tucker)&lt;/h1&gt;

&lt;p&gt;Các bài tập dưới đây được tham khảo từ Boyd &amp;amp; Vandenberghe (2004), Nocedal &amp;amp; Wright (2006) và Bertsekas (1999).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-i-kiểm-chứng-điều-kiện-kkt&quot;&gt;📝 &lt;strong&gt;Phần I: Kiểm chứng điều kiện KKT&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-bài-toán-cơ-bản-boyd--vandenberghe-ex-51&quot;&gt;&lt;strong&gt;Bài tập 1: Bài toán cơ bản (Boyd &amp;amp; Vandenberghe, Ex. 5.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x_1^2 + x_2^2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 = 1 \\
&amp;amp; x_1 \geq 0
\end{align}\]

&lt;p&gt;Kiểm tra hai điểm ứng viên sau:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;\(x^{(1)} = (0.5, 0.5)\), \(\nu = 1\), \(\lambda = 0\)&lt;/li&gt;
  &lt;li&gt;\(x^{(2)} = (0, 1)\), \(\nu = 2\), \(\lambda = 2\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Viết hệ điều kiện KKT, kiểm tra từng điều kiện cho hai điểm trên và xác định nghiệm tối ưu.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**Hàm Lagrangian:** $$L(x,\nu,\lambda) = x_1^2 + x_2^2 - \nu(x_1+x_2-1) + \lambda(-x_1)$$ (viết ràng buộc bất đẳng thức dưới dạng chuẩn $$g(x)=-x_1 \leq 0$$).

**Bốn điều kiện KKT:**

1. **Điều kiện dừng (Stationarity):** $$2x_1 - \nu - \lambda = 0$$, $$2x_2 - \nu = 0$$
2. **Tính khả thi nguyên thủy (Primal feasibility):** $$x_1 + x_2 = 1$$, $$x_1 \geq 0$$
3. **Tính khả thi đối ngẫu (Dual feasibility):** $$\lambda \geq 0$$
4. **Điều kiện bù yếu (Complementary slackness):** $$\lambda \cdot (-x_1) = 0$$

**Kiểm tra $$x^{(1)} = (0.5,0.5)$$, $$\nu=1$$, $$\lambda=0$$:**
- Điều kiện dừng: $$2(0.5)-1-0=0$$ ✓, $$2(0.5)-1=0$$ ✓
- Khả thi nguyên thủy: $$0.5+0.5=1$$ ✓, $$0.5 \geq 0$$ ✓
- Khả thi đối ngẫu: $$0 \geq 0$$ ✓
- Bù yếu: $$0 \cdot (-0.5)=0$$ ✓

Điểm này **thỏa mãn** toàn bộ điều kiện KKT, với giá trị mục tiêu $$f^{(1)} = 0.5$$.

**Kiểm tra $$x^{(2)} = (0,1)$$, $$\nu=2$$, $$\lambda=2$$:**
- Điều kiện dừng: $$0-2-2=-4 \neq 0$$ ✗ (thành phần thứ hai: $$2-2=0$$ ✓)
- Khả thi nguyên thủy: $$0+1=1$$ ✓, $$0 \geq 0$$ ✓
- Khả thi đối ngẫu: $$2 \geq 0$$ ✓
- Bù yếu: $$2 \cdot 0=0$$ ✓

Điểm này **không thỏa mãn** điều kiện dừng. Thực tế, tại $$x^{(2)}$$ ta buộc phải có $$\nu=2x_2=2$$ và $$\lambda = 2x_1-\nu = -2 &amp;lt; 0$$, nên không tồn tại nhân tử đối ngẫu hợp lệ nào; do đó $$(0,1)$$ không phải là điểm KKT (giá trị mục tiêu $$f^{(2)} = 1 &amp;gt; f^{(1)}$$ cũng phản ánh điều này).

**Kết luận:** Chỉ có $$x^* = (0.5,0.5)$$ là điểm KKT. Vì bài toán là bài toán lồi nên điều kiện KKT là điều kiện đủ cho cực tiểu toàn cục; do đó $$x^* = (0.5,0.5)$$ là nghiệm tối ưu duy nhất.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-2-quy-hoạch-bậc-hai-đơn-giản-nocedal--wright-ex-121&quot;&gt;&lt;strong&gt;Bài tập 2: Quy hoạch bậc hai đơn giản (Nocedal &amp;amp; Wright, Ex. 12.1)&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; \frac{1}{2}(x_1^2 + x_2^2) \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 = 1 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Giải bài toán bằng phương pháp tập ràng buộc tích cực (active set).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

Với hàm Lagrangian $$L = \frac{1}{2}\|x\|^2 - \nu(x_1+x_2-1) - \lambda_1x_1 - \lambda_2x_2$$, điều kiện dừng cho $$x_i = \nu + \lambda_i$$ ($$i=1,2$$). Ta xét 3 trường hợp của tập ràng buộc tích cực:

**Trường hợp 1:** Không có ràng buộc bất đẳng thức nào tích cực ($$\lambda_1=\lambda_2=0$$).

Từ điều kiện dừng: $$x_1=\nu$$, $$x_2=\nu$$.  
Thay vào $$x_1+x_2=1$$: $$2\nu=1 \Rightarrow \nu=0.5$$.

Thu được $$x=(0.5, 0.5)$$, $$f=0.25$$, thỏa mãn toàn bộ điều kiện khả thi và KKT ✓.

**Trường hợp 2:** Ràng buộc $$x_1=0$$ tích cực ($$\lambda_2=0$$).

Khi đó $$x_2=1$$; từ điều kiện dừng cho $$x_2$$ suy ra $$\nu=1$$.  
Từ điều kiện dừng cho $$x_1$$ suy ra $$\lambda_1 = x_1 - \nu = -1 &amp;lt; 0$$ ✗.

Điểm $$x=(0,1)$$ khả thi nguyên thủy nhưng **vi phạm tính khả thi đối ngẫu**, nên không phải điểm KKT ($$f=0.5$$).

**Trường hợp 3:** Ràng buộc $$x_2=0$$ tích cực ($$\lambda_1=0$$).

Tương tự, ta có $$\lambda_2 = -1 &amp;lt; 0$$ ✗, nên $$x=(1,0)$$ ($$f=0.5$$) không phải điểm KKT.

**Nghiệm tối ưu:** $$x^*=(0.5,0.5)$$ với giá trị tối ưu $$f^*=0.25$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-ii-ứng-dụng-tối-ưu-hóa-danh-mục-đầu-tư&quot;&gt;📝 &lt;strong&gt;Phần II: Ứng dụng tối ưu hóa danh mục đầu tư&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-3-mô-hình-markowitz-meanvariance&quot;&gt;&lt;strong&gt;Bài tập 3: Mô hình Markowitz Mean–Variance&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; \frac{1}{2} x^T \Sigma x \\
\text{s.t.} \quad &amp;amp; \mu^T x \geq r_{\min} \\
&amp;amp; \mathbf{1}^T x = 1 \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;Cho \(n=3\) với:&lt;/p&gt;

\[\Sigma = \begin{bmatrix} 0.04 &amp;amp; 0.01 &amp;amp; 0 \\ 0.01 &amp;amp; 0.09 &amp;amp; 0.02 \\ 0 &amp;amp; 0.02 &amp;amp; 0.16 \end{bmatrix}, \quad
\mu = \begin{bmatrix} 0.10 \\ 0.15 \\ 0.08 \end{bmatrix}, \quad
r_{\min} = 0.12\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Thử giả thiết \(x_3=0\) (chỉ phân bổ vốn vào tài sản 1 và 2): tìm \(x_1, x_2\) cùng các biến đối ngẫu tương ứng, sau đó kiểm tra các điều kiện KKT.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**Giả thiết thử:** $$x_3=0$$ ($$\nu_{2,3} &amp;gt; 0$$), $$x_1,x_2&amp;gt;0$$, và ràng buộc lợi suất kỳ vọng đang chặt ($$\lambda&amp;gt;0$$).

**Hệ ràng buộc:**
$$
\begin{cases}
x_1 + x_2 = 1 \\
0.10x_1 + 0.15x_2 = 0.12
\end{cases}
$$

Thế $$x_1 = 1-x_2$$ vào phương trình thứ hai:

$$
0.10(1-x_2) + 0.15x_2 = 0.12 \\
0.10 + 0.05x_2 = 0.12 \\
x_2 = 0.4
$$

Suy ra $$x_1 = 0.6$$, tức điểm ứng viên là $$x^* = (0.6, 0.4, 0)^T$$.

**Kiểm tra biến đối ngẫu từ điều kiện dừng:** Với hàm Lagrangian $$L = \frac{1}{2}x^T\Sigma x - \lambda(\mu^Tx - r_{\min}) - \nu_1(\mathbf{1}^Tx-1) - \nu_2^Tx$$, điều kiện dừng cho $$\Sigma x = \lambda\mu + \nu_1\mathbf{1} + \nu_2$$.

Tính tích ma trận–vector:

$$\Sigma x^* = \begin{bmatrix} 0.028 \\ 0.042 \\ 0.008 \end{bmatrix}$$

Vì $$x_1, x_2 &amp;gt; 0$$ nên $$\nu_{2,1}=\nu_{2,2}=0$$, ta có hệ:

$$
\begin{cases}
0.028 = 0.10\lambda + \nu_1 \\
0.042 = 0.15\lambda + \nu_1
\end{cases}
$$

Trừ hai phương trình: $$0.014 = 0.05\lambda \Rightarrow \lambda = 0.28$$, suy ra $$\nu_1 = 0.028 - 0.028 = 0$$.

Từ phương trình thứ ba:
$$\nu_{2,3} = 0.008 - 0.08(0.28) - 0 = -0.0144 &amp;lt; 0$$ ✗

**Kết luận:** Tính khả thi đối ngẫu ($$\nu_2 \geq 0$$) bị vi phạm, nên giả thiết $$x_3=0$$ **không đúng**: tài sản 3 (ít tương quan với tài sản 1) vẫn nên được phân bổ một tỷ trọng nhỏ nhờ hiệu ứng đa dạng hóa rủi ro.

**Giải lại khi cả 3 tài sản đều có tỷ trọng dương** ($$x_i&amp;gt;0$$, ràng buộc lợi suất đang chặt): giải hệ $$\Sigma x = \lambda\mu + \nu_1\mathbf{1}$$, $$\mu^Tx=0.12$$, $$\mathbf{1}^Tx=1$$ thu được:

$$x^* \approx (0.522,\ 0.422,\ 0.056)^T, \quad \lambda^* \approx 0.385, \quad \nu_1^* \approx -0.0134$$

Kiểm tra thành phần thứ ba: $$(\Sigma x^*)_3 \approx 0.0174 = 0.08(0.385) - 0.0134$$ ✓. Giá trị hàm mục tiêu $$\frac{1}{2}x^{*T}\Sigma x^* \approx 0.0164$$ (tương ứng độ lệch chuẩn $$\sigma \approx 0.181$$), thấp hơn mức $$0.0168$$ ($$\sigma \approx 0.183$$) của danh mục $$(0.6, 0.4, 0)$$.

**Ý nghĩa kinh tế:**
- $$\lambda^*\approx 0.385$$ là giá bóng (shadow price) của ràng buộc lợi suất: nếu tăng $$r_{\min}$$ thêm $$0.001$$ thì giá trị $$\frac{1}{2}x^T\Sigma x$$ tăng xấp xỉ $$0.000385$$.
- $$x_3^* \approx 0.056 &amp;gt; 0$$ cho thấy dù tài sản 3 có lợi suất kỳ vọng thấp hơn, nó vẫn giúp giảm phương sai danh mục nhờ đa dạng hóa.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iii-máy-vector-hỗ-trợ-support-vector-machines&quot;&gt;📝 &lt;strong&gt;Phần III: Máy vector hỗ trợ (Support Vector Machines)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-4-hard-margin-svm-boyd--vandenberghe-ex-86&quot;&gt;&lt;strong&gt;Bài tập 4: Hard-Margin SVM (Boyd &amp;amp; Vandenberghe, Ex. 8.6)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Dữ liệu:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Lớp \(+1\): \((1,2)\), \((2,3)\), \((3,3)\)&lt;/li&gt;
  &lt;li&gt;Lớp \(-1\): \((1,1)\), \((2,1)\), \((3,2)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bài toán nguyên thủy (Primal):&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{w,b} \quad &amp;amp; \frac{1}{2}\|w\|^2 \\
\text{s.t.} \quad &amp;amp; y_i(w^Tx_i + b) \geq 1, \quad i=1,\ldots,6
\end{align}\]

&lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu (Dual):&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{\alpha} \quad &amp;amp; \sum_i \alpha_i - \frac{1}{2}\sum_{i,j} \alpha_i\alpha_j y_iy_j x_i^Tx_j \\
\text{s.t.} \quad &amp;amp; \sum_i \alpha_i y_i = 0 \\
&amp;amp; \alpha_i \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Xác định các vector hỗ trợ và siêu phẳng phân cách tối ưu.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**Quan sát hình học:** Hai lớp dữ liệu tách được tuyến tính; các vector hỗ trợ là những điểm nằm đúng trên biên của lề.

**Nghiệm đối ngẫu (giải bằng bộ giải QP rồi kiểm chứng lại bằng KKT):**
- Các vector hỗ trợ có $$\alpha_i^* &amp;gt; 0$$: $$x_1=(1,2)$$ (lớp $$+1$$), $$x_3=(3,3)$$ (lớp $$+1$$), $$x_6=(3,2)$$ (lớp $$-1$$)
- $$\alpha_1^* = 0.5$$, $$\alpha_3^* = 2$$, $$\alpha_6^* = 2.5$$; các $$\alpha_i^*$$ còn lại bằng $$0$$

Kiểm tra ràng buộc cân bằng: $$\sum_i \alpha_i y_i = 0.5 + 2 - 2.5 = 0$$ ✓.

**Tính $$w^*$$:**

$$
w^* = \sum_i \alpha_i^* y_i x_i = 0.5(1,2) + 2(3,3) - 2.5(3,2)
$$

$$
= (0.5,1.0) + (6,6) - (7.5,5) = (-1, 2)
$$

**Tính $$b^*$$ từ vector hỗ trợ $$x_1$$:**

$$y_1(w^{*T}x_1 + b^*) = 1$$

$$1 \cdot ((-1)(1) + (2)(2) + b^*) = 1$$

$$3 + b^* = 1 \Rightarrow b^* = -2$$

**Siêu phẳng phân cách:** $$-x_1 + 2x_2 - 2 = 0$$, hay $$x_2 = \frac{x_1+2}{2}$$.

**Kiểm tra lề:** Giá trị $$y_i(w^{*T}x_i+b^*)$$ lần lượt bằng $$1, 2, 1, 1, 2, 1$$ cho 6 điểm (đều $$\geq 1$$ và bằng $$1$$ tại các vector hỗ trợ) ✓. Độ rộng lề là $$\frac{2}{\|w^*\|} = \frac{2}{\sqrt{5}} \approx 0.894$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iv-thuật-toán-water-filling&quot;&gt;📝 &lt;strong&gt;Phần IV: Thuật toán Water-Filling&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-5-phân-bổ-công-suất-boyd--vandenberghe-ex-57&quot;&gt;&lt;strong&gt;Bài tập 5: Phân bổ công suất (Boyd &amp;amp; Vandenberghe, Ex. 5.7)&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\max_{p} \quad &amp;amp; \sum_{i=1}^n \log(1 + p_i/\sigma_i^2) \\
\text{s.t.} \quad &amp;amp; \sum_i p_i \leq P_{\text{total}} \\
&amp;amp; p_i \geq 0
\end{align}\]

&lt;p&gt;Cho \(n=4\), \(\sigma^2=(1,2,3,4)\) và \(P_{\text{total}}=10\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Suy ra công thức water-filling từ điều kiện KKT và tính nghiệm cụ thể.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**Điều kiện KKT (đưa về bài toán cực tiểu hóa):**

Hàm Lagrangian: $$L = -\sum \log(1+p_i/\sigma_i^2) + \lambda(\sum p_i - P) - \sum \mu_i p_i$$

Điều kiện dừng: $$\frac{\partial L}{\partial p_i} = -\frac{1}{\sigma_i^2 + p_i} + \lambda - \mu_i = 0$$

**Phân tích hai trường hợp:**

- Nếu $$p_i &amp;gt; 0$$: theo điều kiện bù yếu $$\mu_i=0 \Rightarrow \frac{1}{\sigma_i^2+p_i}=\lambda \Rightarrow p_i = \frac{1}{\lambda}-\sigma_i^2$$.
- Nếu $$p_i = 0$$: vì $$\mu_i \geq 0$$ nên $$\sigma_i^2 \geq \frac{1}{\lambda}$$.

**Công thức water-filling:**

$$
\boxed{p_i^* = \max\left(0, \frac{1}{\lambda^*} - \sigma_i^2\right)}
$$

trong đó $$\lambda^*$$ được xác định sao cho $$\sum p_i^* = P_{\text{total}}$$.

---

**Tính nghiệm số:**

Giả sử cả 4 kênh đều được cấp công suất dương:

$$
\sum_{i=1}^4 \left(\frac{1}{\lambda}-\sigma_i^2\right) = 10
$$

$$
\frac{4}{\lambda} - (1+2+3+4) = 10
$$

$$
\frac{4}{\lambda} = 20 \Rightarrow \lambda = 0.2
$$

**Mực nước (water level):** $$\frac{1}{\lambda} = 5$$.

**Công suất phân bổ cho từng kênh:**
- $$p_1 = 5-1 = 4$$ ✓
- $$p_2 = 5-2 = 3$$ ✓
- $$p_3 = 5-3 = 2$$ ✓
- $$p_4 = 5-4 = 1$$ ✓

Kiểm tra tổng công suất: $$4+3+2+1=10$$ ✓. Vậy nghiệm tối ưu là $$p^* = (4,3,2,1)$$.

**Minh họa mực nước:**

```
Water level = 5
|     |     |     |
|  4  |  3  |  2  |  1  |  ← Công suất
+-----+-----+-----+-----+
|  1  |  2  |  3  |  4  |  ← Mức nhiễu nền
+-----+-----+-----+-----+
  p₁    p₂    p₃    p₄
```

Kênh có mức nhiễu nền thấp hơn (chất lượng tốt hơn) nhận được nhiều công suất hơn.

**Tổng dung lượng kênh:**

$$C = \sum \log_2(1+p_i^*/\sigma_i^2) \approx 4.70 \text{ bits/s/Hz}$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-v-bài-tập-nâng-cao&quot;&gt;📝 &lt;strong&gt;Phần V: Bài tập nâng cao&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-6-bình-phương-tối-thiểu-có-ràng-buộc-bertsekas-ex-322&quot;&gt;&lt;strong&gt;Bài tập 6: Bình phương tối thiểu có ràng buộc (Bertsekas, Ex. 3.2.2)&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; \frac{1}{2}\|Ax-b\|^2 \\
\text{s.t.} \quad &amp;amp; Cx = d \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;Với:&lt;/p&gt;

\[A = \begin{bmatrix} 1&amp;amp;1\\1&amp;amp;-1\\2&amp;amp;0 \end{bmatrix}, \quad
b = \begin{bmatrix} 2\\0\\3 \end{bmatrix}, \quad
C = [1\ 1], \quad
d = 2\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Giải bài toán bằng điều kiện KKT.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

Ta có $$\nabla f(x) = A^TAx - A^Tb$$, với:

$$
A^TA = \begin{bmatrix} 6&amp;amp;0\\0&amp;amp;2 \end{bmatrix}, \quad
A^Tb = \begin{bmatrix} 8\\2 \end{bmatrix}
$$

**Giải thử hệ KKT khi bỏ qua ràng buộc $$x \geq 0$$ (tức giả sử $$\lambda = 0$$):**

$$
\begin{bmatrix} 6&amp;amp;0&amp;amp;-1\\0&amp;amp;2&amp;amp;-1\\1&amp;amp;1&amp;amp;0 \end{bmatrix}
\begin{bmatrix} x_1\\x_2\\\nu \end{bmatrix} =
\begin{bmatrix} 8\\2\\2 \end{bmatrix}
$$

Giải hệ phương trình:
- Từ phương trình (3): $$x_1+x_2=2$$.
- Từ phương trình (1) và (2): $$x_1=\frac{8+\nu}{6}$$, $$x_2=\frac{2+\nu}{2}$$; thế vào (3) được $$14+4\nu=12 \Rightarrow \nu=-0.5$$.
- Suy ra $$x_1=1.25$$, $$x_2=0.75$$.

**Kiểm tra tính khả thi $$x \geq 0$$:** $$x_1=1.25&amp;gt;0$$, $$x_2=0.75&amp;gt;0$$ ✓.

**Kiểm tra nhân tử $$\lambda$$:**

$$\lambda = A^TAx - A^Tb - C^T\nu = \begin{bmatrix} 7.5-8+0.5\\1.5-2+0.5 \end{bmatrix} = \begin{bmatrix} 0\\0 \end{bmatrix} \geq 0$$ ✓

**Nghiệm tối ưu:** $$x^*=(1.25, 0.75)^T$$, phần dư $$Ax^*-b=(0,0.5,-0.5)^T$$ và giá trị tối ưu $$f^*=\frac{1}{2}(0.25+0.25)=0.25$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-7-phương-pháp-hàm-phạt-nocedal--wright-ex-171&quot;&gt;&lt;strong&gt;Bài tập 7: Phương pháp hàm phạt (Nocedal &amp;amp; Wright, Ex. 17.1)&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x_1 + x_2 \\
\text{s.t.} \quad &amp;amp; x_1^2 + x_2^2 = 1
\end{align}\]

&lt;p&gt;&lt;strong&gt;Bài toán phạt:&lt;/strong&gt; \(\min \phi(x;\mu) = x_1+x_2 + \frac{\mu}{2}(x_1^2+x_2^2-1)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Giải bài toán gốc bằng KKT, tính nghiệm của bài toán phạt với \(\mu=1,10,100\) và phân tích sự hội tụ.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**Giải bài toán gốc bằng KKT:**

Hàm Lagrangian: $$L = x_1+x_2 - \nu(x_1^2+x_2^2-1)$$

Điều kiện dừng: $$1-2\nu x_1=0$$, $$1-2\nu x_2=0 \Rightarrow x_1=x_2=\frac{1}{2\nu}$$

Thế vào ràng buộc khả thi: $$\frac{1}{4\nu^2}+\frac{1}{4\nu^2}=1 \Rightarrow \nu = \pm\frac{1}{\sqrt{2}}$$

**Hai điểm KKT:**
1. $$x=(1/\sqrt{2}, 1/\sqrt{2})$$, giá trị mục tiêu $$f=\sqrt{2}$$ (cực đại)
2. $$x=(-1/\sqrt{2}, -1/\sqrt{2})$$, giá trị mục tiêu $$f=-\sqrt{2}$$ (cực tiểu)

**Nghiệm cực tiểu tối ưu:** $$x^* = (-1/\sqrt{2}, -1/\sqrt{2})$$.

---

**Giải bằng phương pháp hàm phạt:**

Điều kiện bậc nhất: $$1 + 2\mu x_i(x_1^2+x_2^2-1)=0$$ ($$i=1,2$$).

Với tính đối xứng $$x_1=x_2=x$$: $$1 + 2\mu x(2x^2-1)=0$$, tức $$4\mu x^3 - 2\mu x + 1=0$$.

**Nghiệm số** (chọn nghiệm thực âm của phương trình bậc ba cho giá trị $$\phi$$ nhỏ nhất; khi $$\mu$$ lớn, phương trình còn nghiệm dương tương ứng với cực tiểu địa phương gần điểm cực đại, có giá trị $$\phi$$ lớn hơn):
- $$\mu=1$$: $$x \approx -0.885$$ ($$x_1^2+x_2^2-1 \approx 0.57$$, vi phạm ràng buộc còn lớn)
- $$\mu=10$$: $$x \approx -0.731$$ ($$x_1^2+x_2^2-1 \approx 0.07$$)
- $$\mu=100$$: $$x \approx -0.710$$ ($$x_1^2+x_2^2-1 \approx 0.007$$) $$\to -1/\sqrt{2} \approx -0.7071$$

**Nhận xét về hội tụ:** Khi $$\mu \to \infty$$, nghiệm của bài toán phạt hội tụ về nghiệm KKT từ phía **ngoài** miền khả thi (vì $$x_1^2+x_2^2&amp;gt;1$$).

**Liên hệ với nhân tử Lagrange:** Với quy ước $$L = f - \nu h$$, ta có $$\nu \approx -\mu(x_1^2+x_2^2-1)$$ (chẳng hạn tại $$\mu=100$$, $$\nu \approx -100 \cdot 0.007 \approx -0.7 \approx -1/\sqrt{2}$$ ✓).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết-chiến-lược-giải-bài-tập&quot;&gt;💡 &lt;strong&gt;Tổng kết chiến lược giải bài tập&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;kiểm-chứng-điều-kiện-kkt&quot;&gt;&lt;strong&gt;Kiểm chứng điều kiện KKT&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Kiểm tra riêng rẽ đủ &lt;strong&gt;4 điều kiện&lt;/strong&gt; (dừng, khả thi nguyên thủy, khả thi đối ngẫu, bù yếu).&lt;/li&gt;
  &lt;li&gt;KKT là điều kiện &lt;strong&gt;cần&lt;/strong&gt; cho cực tiểu địa phương (khi thỏa điều kiện chuẩn ràng buộc) và là điều kiện &lt;strong&gt;đủ&lt;/strong&gt; cho cực tiểu toàn cục đối với bài toán lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-bài-toán-bằng-kkt&quot;&gt;&lt;strong&gt;Giải bài toán bằng KKT&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược tập tích cực (active set):&lt;/strong&gt; Chia trường hợp dựa trên các ràng buộc bất đẳng thức đang chặt.&lt;/li&gt;
  &lt;li&gt;Giải hệ phương trình thu được từ điều kiện dừng và các ràng buộc tích cực.&lt;/li&gt;
  &lt;li&gt;Kiểm tra tính khả thi nguyên thủy, đối ngẫu và so sánh giá trị mục tiêu (nếu bài toán không lồi).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;điều-kiện-bù-yếu&quot;&gt;&lt;strong&gt;Điều kiện bù yếu&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(\lambda_i &amp;gt; 0\) thì ràng buộc thứ \(i\) chắc chắn đang chặt (tích cực).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giá bóng (shadow price):&lt;/strong&gt; Nhân tử \(\lambda_i^*\) cho biết tốc độ thay đổi biên của giá trị tối ưu khi nới lỏng ràng buộc thứ \(i\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bài-toán-lồi&quot;&gt;&lt;strong&gt;Bài toán lồi&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Điều kiện KKT là điều kiện đủ: mọi điểm KKT đều là nghiệm tối ưu toàn cục.&lt;/li&gt;
  &lt;li&gt;Khi thỏa tính đối ngẫu mạnh: \(f^* = g^*\).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 5.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nocedal, J., &amp;amp; Wright, S. J.&lt;/strong&gt; (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt; (2nd ed.). Springer. Chapters 12, 16-17.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bertsekas, D. P.&lt;/strong&gt; (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt; (2nd ed.). Athena Scientific. Chapter 3.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Luenberger, D. G., &amp;amp; Ye, Y.&lt;/strong&gt; (2008). &lt;em&gt;Linear and Nonlinear Programming&lt;/em&gt; (3rd ed.). Springer. Chapter 10.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bazaraa, M. S., Sherali, H. D., &amp;amp; Shetty, C. M.&lt;/strong&gt; (2006). &lt;em&gt;Nonlinear Programming: Theory and Algorithms&lt;/em&gt; (3rd ed.). Wiley.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>12-08 Bài tập trắc nghiệm - Điều Kiện KKT</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_08_Quiz_KKT_Conditions/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_08_Quiz_KKT_Conditions</id>
   <content type="html">&lt;p&gt;Điều kiện KKT là đỉnh cao kết nối toàn bộ phần Đối ngẫu (Chương 10–12), đồng thời cũng là nơi đề thi và câu hỏi trắc nghiệm dễ “đánh lừa” nhất. Chỉ cần quên kiểm tra dấu \(u_i \ge 0\) khi giải xong phương trình đạo hàm, nhầm rằng KKT luôn là điều kiện đủ cho bài toán &lt;em&gt;không lồi&lt;/em&gt;, hay áp dụng sai công thức water-filling cho kênh nhiễu là điểm số sẽ tụt ngay lập tức!&lt;/p&gt;

&lt;p&gt;Trước khi làm bộ câu hỏi trắc nghiệm Chương 12 dưới đây, hãy điểm nhanh 4 cụm kiến thức trọng tâm và tự thử sức với 4 chiếc bẫy số ngắn gọn để nắm chắc tuyệt đối toàn chương.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-cụm-kiến-thức-trọng-tâm-cho-bài-trắc-nghiệm-chương-12&quot;&gt;Kiến thức cần nhớ: Bốn cụm kiến thức trọng tâm cho bài trắc nghiệm Chương 12&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thuộc lòng và hiểu bản chất 4 điều kiện KKT:&lt;/strong&gt; (1) Dừng: \(0 \in \partial f + \sum u_i \partial h_i + \sum v_j \partial l_j\); (2) Bù: \(u_i h_i(x) = 0\); (3) Khả thi gốc: \(h_i(x) \le 0, l_j(x) = 0\); (4) Khả thi đối ngẫu: \(u_i \ge 0\) (còn \(v_j\) tự do dấu!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân biệt Điều kiện cần vs. Điều kiện đủ:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Bài toán bất kỳ + đối ngẫu mạnh&lt;/em&gt; \(\implies\) KKT là điều kiện &lt;strong&gt;cần&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Bài toán lồi&lt;/em&gt; \(\implies\) KKT là điều kiện &lt;strong&gt;đủ&lt;/strong&gt; (nghiệm KKT chắc chắn tối ưu toàn cục!).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Bài toán lồi + Slater&lt;/em&gt; \(\implies\) KKT là &lt;strong&gt;cần và đủ&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhận diện cấu trúc nghiệm của 3 ví dụ kinh điển:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;QP ràng buộc đẳng thức \(\implies\) hệ tuyến tính khối đối xứng bất định.&lt;/li&gt;
      &lt;li&gt;Water-filling \(\implies\) \(x_i^* = \max(0, w - \alpha_i)\), tắt hẳn kênh có \(\alpha_i \ge w\).&lt;/li&gt;
      &lt;li&gt;Soft-Margin SVM \(\implies\) \(0 \le \alpha_i^* \le C\), chỉ điểm có \(\alpha_i^* &amp;gt; 0\) là vector hỗ trợ.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dạng ràng buộc (C) vs. Dạng Lagrange (L) và Lasso:&lt;/strong&gt; Hai dạng tương đương về đường nghiệm trong bài toán lồi (thỏa Slater); trong Lasso, \(X\hat{\beta}\) luôn duy nhất còn \(\hat{\beta}\) duy nhất khi \(X_{\mathcal{E}}\) đủ hạng cột.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bốn-phép-thử-số-nhanh-né-bẫy-trắc-nghiệm-chương-12&quot;&gt;Giải thích: Bốn phép thử số nhanh né bẫy trắc nghiệm Chương 12&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 1 — Quên kiểm tra \(u_i \ge 0\):&lt;/strong&gt; Giải bài toán \(\min x^2\) s.t. \(x \le 2\) (tức \(h(x) = x - 2 \le 0\)). Thử điểm biên \(x = 2\): phương trình dừng \(2x + u = 0 \implies u = -4\). Thỏa dừng, thỏa bù (\(-4(0) = 0\)), thỏa khả thi gốc — vậy \(x = 2\) có tối ưu không?
&lt;strong&gt;KHÔNG!&lt;/strong&gt; Vì \(u = -4 &amp;lt; 0\) vi phạm &lt;strong&gt;tính khả thi đối ngẫu&lt;/strong&gt;! Nghiệm đúng là \(x^* = 0, u^* = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 2 — KKT trên bài toán không lồi:&lt;/strong&gt; Xét \(\min -x^2\) s.t. \(-1 \le x \le 1\). Tại \(x = 0\) với \(u_1 = u_2 = 0\), đạo hàm \(-2(0) = 0\) và cả 4 điều kiện KKT đều thỏa — nhưng \(x = 0\) lại là &lt;strong&gt;cực đại toàn cục&lt;/strong&gt; (\(f(0) = 0 &amp;gt; f(\pm 1) = -1\))! Lý do: bài toán không lồi nên KKT &lt;em&gt;không&lt;/em&gt; phải điều kiện đủ!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 3 — Đếm số vector hỗ trợ SVM:&lt;/strong&gt; Nếu giải xong Soft-Margin SVM có \(\alpha^* = (0, 0, 0.3, 1.0, 0)\) với \(C = 1.0\), có bao nhiêu vector hỗ trợ?
Có &lt;strong&gt;2 vector hỗ trợ&lt;/strong&gt; (điểm 3 nằm đúng trên biên vì \(0 &amp;lt; 0.3 &amp;lt; 1\); điểm 4 vi phạm/chạm biên vì \(\alpha_4^* = C = 1\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 4 — Kiểm tra mực nước water-filling:&lt;/strong&gt; Cho \(\alpha = (1, 3)\) và tổng công suất \(1\). Nếu đổ nước vào kênh 1 từ mức \(1\) lên mức \(2\) (dùng hết cả \(1\) đơn vị công suất!), mực nước \(w = 2 &amp;lt; \alpha_2 = 3\) nên kênh 2 nhận \(x_2^* = 0\) và kênh 1 nhận trọn \(x_1^* = 1\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập trắc nghiệm, hãy ôn lại các khái niệm trọng tâm trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-điều-kiện-karushkuhntucker-kkt&quot;&gt;⚡ &lt;strong&gt;Điều kiện Karush–Kuhn–Tucker (KKT)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-tối-ưu-tổng-quát&quot;&gt;&lt;strong&gt;Bài toán tối ưu tổng quát&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) \quad \text{s.t.} \quad h_i(x) \le 0, \quad l_j(x) = 0\)&lt;/p&gt;

&lt;p&gt;với \(i = 1,\ldots,m\) và \(j = 1,\ldots,r\).&lt;/p&gt;

&lt;h4 id=&quot;bốn-điều-kiện-kkt&quot;&gt;&lt;strong&gt;Bốn điều kiện KKT&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Với bộ điểm \((x^*, \lambda^*, \nu^*)\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Điều kiện dừng (Stationarity):&lt;/strong&gt;
\(0 \in \partial \left( f(x^*) + \sum_{i=1}^m \lambda_i^* h_i(x^*) + \sum_{j=1}^r \nu_j^* l_j(x^*) \right)\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Điều kiện bù yếu (Complementary slackness):&lt;/strong&gt;
\(\lambda_i^* \cdot h_i(x^*) = 0 \quad \forall i\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Tính khả thi nguyên thủy (Primal feasibility):&lt;/strong&gt;
\(h_i(x^*) \le 0, \quad l_j(x^*) = 0 \quad \forall i,j\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Tính khả thi đối ngẫu (Dual feasibility):&lt;/strong&gt;
\(\lambda_i^* \ge 0 \quad \forall i\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;ý-nghĩa-của-từng-điều-kiện&quot;&gt;&lt;strong&gt;Ý nghĩa của từng điều kiện&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt; Gradient (hoặc dưới vi phân) của hàm Lagrangian theo \(x\) bằng \(0\) (chứa \(0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù yếu:&lt;/strong&gt; Với mỗi ràng buộc bất đẳng thức, hoặc ràng buộc đang chặt (\(h_i(x^*) = 0\)), hoặc nhân tử đối ngẫu bằng không (\(\lambda_i^* = 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính khả thi nguyên thủy:&lt;/strong&gt; Điểm \(x^*\) thỏa mãn mọi ràng buộc của bài toán gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính khả thi đối ngẫu:&lt;/strong&gt; Các nhân tử ứng với ràng buộc bất đẳng thức phải không âm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-điều-kiện-đủ-và-điều-kiện-cần&quot;&gt;📊 &lt;strong&gt;Điều kiện đủ và điều kiện cần&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;điều-kiện-đủ-sufficiency&quot;&gt;&lt;strong&gt;Điều kiện đủ (Sufficiency)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Nếu \((x^*, \lambda^*, \nu^*)\) thỏa mãn các điều kiện KKT và bài toán là &lt;strong&gt;bài toán lồi&lt;/strong&gt;, thì đây là cặp nghiệm tối ưu nguyên thủy và đối ngẫu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chứng minh ngắn:&lt;/strong&gt;
\(g(\lambda^*, \nu^*) = \min_x L(x, \lambda^*, \nu^*) = L(x^*, \lambda^*, \nu^*) = f(x^*)\)&lt;/p&gt;

&lt;p&gt;Do đó \(g(\lambda^*, \nu^*) = f(x^*)\), tức khoảng cách đối ngẫu bằng \(0\) nên nghiệm đạt tối ưu toàn cục.&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-cần-necessity&quot;&gt;&lt;strong&gt;Điều kiện cần (Necessity)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Nếu \((x^*, \lambda^*, \nu^*)\) là cặp nghiệm tối ưu và bài toán thỏa mãn &lt;strong&gt;tính đối ngẫu mạnh&lt;/strong&gt; (chẳng hạn thỏa điều kiện Slater), thì chúng bắt buộc thỏa mãn các điều kiện KKT.&lt;/p&gt;

&lt;h4 id=&quot;tổng-kết&quot;&gt;&lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Đối với bài toán lồi có tính đối ngẫu mạnh:
\(x^*, \lambda^*, \nu^* \text{ tối ưu} \Leftrightarrow x^*, \lambda^*, \nu^* \text{ thỏa mãn các điều kiện KKT}\)&lt;/p&gt;

&lt;h3 id=&quot;-ví-dụ-quy-hoạch-bậc-hai-với-ràng-buộc-đẳng-thức&quot;&gt;🔄 &lt;strong&gt;Ví dụ: Quy hoạch bậc hai với ràng buộc đẳng thức&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán&quot;&gt;&lt;strong&gt;Bài toán&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x \frac{1}{2}x^T P x + q^T x + r \quad \text{s.t.} \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;với \(P \in \mathbb{S}_+^n\) (ma trận nửa xác định dương).&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-kkt&quot;&gt;&lt;strong&gt;Điều kiện KKT&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt; \(Px^* + q + A^T \nu^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả thi nguyên thủy:&lt;/strong&gt; \(Ax^* = b\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bù yếu và khả thi đối ngẫu:&lt;/strong&gt; Không xuất hiện vì không có ràng buộc bất đẳng thức.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;hệ-ma-trận-kkt&quot;&gt;&lt;strong&gt;Hệ ma trận KKT&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{bmatrix} P &amp;amp; A^T \\ A &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x^* \\ \nu^* \end{bmatrix} = \begin{bmatrix} -q \\ b \end{bmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt; Hệ phương trình này cũng chính là hệ tính &lt;strong&gt;bước Newton&lt;/strong&gt; trong bài toán tối ưu có ràng buộc đẳng thức.&lt;/p&gt;

&lt;h3 id=&quot;-ví-dụ-thuật-toán-water-filling&quot;&gt;🌊 &lt;strong&gt;Ví dụ: Thuật toán Water-Filling&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-1&quot;&gt;&lt;strong&gt;Bài toán&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x -\sum_{i=1}^n \log(\alpha_i + x_i) \quad \text{s.t.} \quad x \succeq 0, \quad \mathbf{1}^T x = 1\)&lt;/p&gt;

&lt;p&gt;với \(\alpha_i &amp;gt; 0\).&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-kkt-1&quot;&gt;&lt;strong&gt;Điều kiện KKT&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt; \(-\frac{1}{\alpha_i + x_i^*} - \lambda_i^* + \nu^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bù yếu:&lt;/strong&gt; \(\lambda_i^* x_i^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả thi nguyên thủy:&lt;/strong&gt; \(x^* \succeq 0, \mathbf{1}^T x^* = 1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả thi đối ngẫu:&lt;/strong&gt; \(\lambda^* \succeq 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;nghiệm-giải-tích&quot;&gt;&lt;strong&gt;Nghiệm giải tích&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x_i^* = \max\left\{0, \frac{1}{\nu^*} - \alpha_i\right\}\)&lt;/p&gt;

&lt;p&gt;với \(\nu^*\) xác định duy nhất từ phương trình \(\sum_{i=1}^n \max\left\{0, \frac{1}{\nu^*} - \alpha_i\right\} = 1\).&lt;/p&gt;

&lt;h4 id=&quot;diễn-giải-trực-quan&quot;&gt;&lt;strong&gt;Diễn giải trực quan&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(\alpha_i\): Độ cao đáy của kênh thứ \(i\).&lt;/li&gt;
  &lt;li&gt;\(\frac{1}{\nu^*}\): Mực nước chung.&lt;/li&gt;
  &lt;li&gt;\(x_i^*\): Lượng nước (công suất) phân bổ cho kênh thứ \(i\) sao cho tổng lượng nước bằng \(1\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ví-dụ-máy-vector-hỗ-trợ-svm&quot;&gt;🎯 &lt;strong&gt;Ví dụ: Máy vector hỗ trợ (SVM)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-nguyên-thủy&quot;&gt;&lt;strong&gt;Bài toán nguyên thủy&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{\beta,\beta_0,\xi} \frac{1}{2}\|\beta\|_2^2 + C\sum_{i=1}^n \xi_i\)
\(\text{s.t.} \quad \xi_i \ge 0, \quad y_i(x_i^T\beta + \beta_0) \ge 1 - \xi_i\)&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-kkt-2&quot;&gt;&lt;strong&gt;Điều kiện KKT&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[\beta^* = \sum_{i=1}^n w_i^* y_i x_i\]
      &lt;/li&gt;
      &lt;li&gt;
\[\sum_{i=1}^n w_i^* y_i = 0\]
      &lt;/li&gt;
      &lt;li&gt;
\[w^* = C\mathbf{1} - v^*\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù yếu:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[v_i^* \xi_i^* = 0\]
      &lt;/li&gt;
      &lt;li&gt;
\[w_i^* (1 - \xi_i^* - y_i(x_i^T\beta^* + \beta_0^*)) = 0\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;các-vector-hỗ-trợ&quot;&gt;&lt;strong&gt;Các vector hỗ trợ&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Điểm \(i\) là vector hỗ trợ khi và chỉ khi \(w_i^* &amp;gt; 0\), gồm hai nhóm:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trên biên lề:&lt;/strong&gt; \(\xi_i^* = 0\), \(w_i^* \in (0, C]\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bên trong lề hoặc phân loại sai:&lt;/strong&gt; \(\xi_i^* &amp;gt; 0\), \(w_i^* = C\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;hệ-quả-thực-hành&quot;&gt;&lt;strong&gt;Hệ quả thực hành&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính thưa:&lt;/strong&gt; Chỉ các vector hỗ trợ mới có \(w_i^* &amp;gt; 0\) và tham gia vào biểu thức siêu phẳng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính diễn giải:&lt;/strong&gt; Các điều kiện KKT giải thích rõ vai trò của từng điểm dữ liệu trong nghiệm SVM.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-dạng-ràng-buộc-và-dạng-lagrange&quot;&gt;🔄 &lt;strong&gt;Dạng ràng buộc và dạng Lagrange&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;dạng-ràng-buộc-c&quot;&gt;&lt;strong&gt;Dạng ràng buộc (C)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) \quad \text{s.t.} \quad h(x) \le t\)&lt;/p&gt;

&lt;h4 id=&quot;dạng-lagrange-l&quot;&gt;&lt;strong&gt;Dạng Lagrange (L)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) + \lambda h(x)\)&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-tương-đương&quot;&gt;&lt;strong&gt;Điều kiện tương đương&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;(C) → (L):&lt;/strong&gt; Nếu (C) thỏa điều kiện Slater (đối ngẫu mạnh), tồn tại \(\lambda^* \ge 0\) sao cho nghiệm của (C) cũng là nghiệm của (L).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;(L) → (C):&lt;/strong&gt; Nếu \(x^*\) là nghiệm của (L), thì \(x^*\) cũng là nghiệm của (C) khi đặt \(t = h(x^*)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;tương-đương-tại-biên&quot;&gt;&lt;strong&gt;Tương đương tại biên&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Khi \(h(x) \ge 0\) (như chuẩn), \(t = 0\) và \(\lambda = \infty\), cả hai dạng đều áp đặt cùng một ràng buộc \(h(x) = 0\).&lt;/p&gt;

&lt;h3 id=&quot;️-kỹ-thuật-thực-hành&quot;&gt;🛠️ &lt;strong&gt;Kỹ thuật thực hành&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;quy-trình-kiểm-tra-điều-kiện-kkt&quot;&gt;&lt;strong&gt;Quy trình kiểm tra điều kiện KKT&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;Kiểm tra điều kiện dừng: \(\nabla_x L(x^*, \lambda^*, \nu^*) = 0\) (hoặc \(0 \in \partial_x L\)).&lt;/li&gt;
  &lt;li&gt;Kiểm tra điều kiện bù yếu: \(\lambda_i^* h_i(x^*) = 0\) với mọi \(i\).&lt;/li&gt;
  &lt;li&gt;Kiểm tra tính khả thi nguyên thủy và đối ngẫu.&lt;/li&gt;
  &lt;li&gt;Kết luận tối ưu: nếu bài toán lồi và thỏa KKT thì điểm đó là nghiệm tối ưu toàn cục.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;chiến-lược-giải-bài-toán-giải-tích&quot;&gt;&lt;strong&gt;Chiến lược giải bài toán giải tích&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;Viết đầy đủ hệ điều kiện KKT cho bài toán.&lt;/li&gt;
  &lt;li&gt;Dùng điều kiện bù yếu để xét các trường hợp tập ràng buộc tích cực.&lt;/li&gt;
  &lt;li&gt;Giải hệ phương trình từ điều kiện dừng và các ràng buộc đang chặt.&lt;/li&gt;
  &lt;li&gt;Kiểm tra lại toàn bộ điều kiện khả thi để loại nghiệm ngoại lai.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;ứng-dụng-trong-thuật-toán-số&quot;&gt;&lt;strong&gt;Ứng dụng trong thuật toán số&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp tập tích cực (Active set):&lt;/strong&gt; Xác định dần tập ràng buộc chặt qua từng bước lặp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp điểm trong (Interior point):&lt;/strong&gt; Bám theo đường trung tâm thỏa mãn hệ KKT đã làm trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp nguyên thủy–đối ngẫu:&lt;/strong&gt; Cập nhật đồng thời biến nguyên thủy và biến đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ví-dụ-minh-họa&quot;&gt;💡 &lt;strong&gt;Ví dụ minh họa&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-đơn-giản&quot;&gt;&lt;strong&gt;Bài toán đơn giản&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x x^2 + y^2 \quad \text{s.t.} \quad x + y = 1, \quad x \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện KKT:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt; \(2x^* - \lambda^* + \nu^* = 0\), \(2y^* + \nu^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bù yếu:&lt;/strong&gt; \(\lambda^* x^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả thi nguyên thủy:&lt;/strong&gt; \(x^* + y^* = 1\), \(x^* \ge 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả thi đối ngẫu:&lt;/strong&gt; \(\lambda^* \ge 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phân tích trường hợp:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 1:&lt;/strong&gt; \(x^* &amp;gt; 0 \implies \lambda^* = 0 \implies x^* = y^* = 1/2\), \(\nu^* = -1\) (thỏa mãn).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 2:&lt;/strong&gt; \(x^* = 0 \implies y^* = 1 \implies \nu^* = -2 \implies \lambda^* = -2 &amp;lt; 0\) (vi phạm tính khả thi đối ngẫu, loại).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Nghiệm tối ưu:&lt;/strong&gt; \(x^* = 1/2, y^* = 1/2\), \(\nu^* = -1\), \(\lambda^* = 0\).&lt;/p&gt;

&lt;h3 id=&quot;-kết-nối-với-các-chương-khác-và-ứng-dụng&quot;&gt;🎯 &lt;strong&gt;Kết nối với các chương khác và ứng dụng&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Liên hệ lý thuyết:&lt;/strong&gt; Chương 11 cung cấp lý thuyết đối ngẫu tổng quát làm nền tảng cho KKT; Chương 10 là trường hợp riêng cho quy hoạch tuyến tính; Chương 04 xét điều kiện tối ưu bậc nhất không ràng buộc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý khi áp dụng:&lt;/strong&gt; Cần kiểm tra điều kiện chuẩn ràng buộc (LICQ, MFCQ hoặc Slater) khi dùng KKT như điều kiện cần; không nhầm lẫn rằng ràng buộc tích cực luôn có \(\lambda_i &amp;gt; 0\) (vẫn có thể có \(\lambda_i = 0\)); với bài toán không lồi, KKT chỉ là điều kiện cần chứ không đủ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng phổ biến:&lt;/strong&gt; Học máy (SVM, điều chuẩn, ràng buộc công bằng), kỹ thuật (điều khiển tối ưu, xử lý tín hiệu, tối ưu kết cấu), kinh tế–tài chính (tối ưu danh mục đầu tư, phân bổ nguồn lực) và vận trù học (luồng mạng, lập kế hoạch sản xuất).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra mức độ nắm vững điều kiện Karush–Kuhn–Tucker (KKT) cùng các ví dụ ứng dụng như SVM, thuật toán water-filling, quy hoạch bậc hai và bài toán phạt L1.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;⚖️ Quiz: Điều Kiện KKT&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: KKT conditions components --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Điều kiện KKT bao gồm những thành phần nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Chỉ stationarity và complementary slackness&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Stationarity, complementary slackness, primal feasibility, dual feasibility&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Chỉ primal và dual feasibility&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Chỉ stationarity&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Stationarity, complementary slackness, primal feasibility, dual feasibility&lt;/strong&gt;&lt;br /&gt;
                Điều kiện KKT gồm 4 thành phần: (1) Điều kiện dừng (stationarity), (2) Điều kiện bù yếu (complementary slackness), (3) Tính khả thi nguyên thủy (primal feasibility) và (4) Tính khả thi đối ngẫu (dual feasibility).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Stationarity condition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Stationarity condition trong KKT có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(\nabla f(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\nabla f(x^*) + \sum \lambda_i \nabla h_i(x^*) + \sum \nu_j \nabla l_j(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(\lambda_i h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(h_i(x^*) \leq 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\nabla f(x^*) + \sum \lambda_i \nabla h_i(x^*) + \sum \nu_j \nabla l_j(x^*) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện dừng yêu cầu gradient của hàm Lagrangian theo $$x$$ bằng 0, tức gradient của hàm mục tiêu cân bằng với tổ hợp tuyến tính các gradient của những ràng buộc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Complementary slackness --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Complementary slackness condition phát biểu rằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(\lambda_i h_i(x^*) = 0\) với mọi \(i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(\lambda_i = 0\) hoặc \(h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Nếu \(h_i(x^*) &amp;lt; 0\) thì \(\lambda_i = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Tất cả các điều trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các điều trên&lt;/strong&gt;&lt;br /&gt;
                Điều kiện bù yếu có nhiều cách phát biểu tương đương: $$\lambda_i h_i(x^*) = 0$$, hoặc ít nhất một trong hai đại lượng $$\lambda_i$$ và $$h_i(x^*)$$ bằng 0, hay mọi ràng buộc không chặt đều có biến đối ngẫu bằng 0.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: KKT sufficiency --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: KKT conditions là điều kiện đủ cho global optimality khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Bài toán là convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Bài toán là non-convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Luôn luôn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Không bao giờ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Bài toán là convex&lt;/strong&gt;&lt;br /&gt;
                Điều kiện KKT là điều kiện cần (khi có điều kiện chuẩn ràng buộc) cho mọi bài toán, nhưng chỉ là điều kiện đủ cho cực tiểu toàn cục khi bài toán là bài toán lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Active constraints --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Constraint \(h_i(x) \leq 0\) được gọi là active tại \(x^*\) khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(h_i(x^*) &amp;lt; 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(\lambda_i &amp;gt; 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \(\lambda_i = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$h_i(x^*) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Một ràng buộc bất đẳng thức được gọi là tích cực (active) khi nó đạt dấu bằng tại điểm tối ưu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Quadratic programming KKT --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Trong quadratic programming \(\min \frac{1}{2}x^T Q x + c^T x\) s.t. \(Ax = b\), stationarity condition là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(Qx^* + c = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(Qx^* + c + A^T \nu^* = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(Ax^* = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(\nu^* = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$Qx^* + c + A^T \nu^* = 0$$&lt;/strong&gt;&lt;br /&gt;
                Stationarity: $$\nabla f(x^*) + A^T \nu^* = Qx^* + c + A^T \nu^* = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Water-filling problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Trong water-filling algorithm, bài toán tối ưu có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) \(\max \sum \log(\alpha_i + x_i)\) s.t. \(\sum x_i = P, x_i \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(\min \sum \log(\alpha_i + x_i)\) s.t. \(\sum x_i = P, x_i \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) \(\max \sum x_i^2\) s.t. \(\sum x_i = P\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(\min \sum x_i^2\) s.t. \(\sum x_i = P\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max \sum \log(\alpha_i + x_i)$$ s.t. $$\sum x_i = P, x_i \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Thuật toán water-filling cực đại hóa tổng dung lượng logarit của các kênh dưới ràng buộc tổng công suất cố định và công suất không âm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Water-filling solution --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Nghiệm của water-filling algorithm có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(x_i^* = \max(0, \mu - \alpha_i)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(x_i^* = \max(0, \alpha_i - \mu)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(x_i^* = \mu - \alpha_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(x_i^* = \alpha_i + \mu\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$x_i^* = \max(0, \mu - \alpha_i)$$&lt;/strong&gt;&lt;br /&gt;
                Nghiệm water-filling phân bổ công suất $$\mu - \alpha_i$$ cho kênh $$i$$ nếu $$\mu &amp;gt; \alpha_i$$, ngược lại phân bổ bằng 0.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: SVM primal problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: SVM primal problem có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(\min \frac{1}{2}\|w\|^2\) s.t. \(y_i(w^T x_i + b) \geq 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(\max \frac{1}{2}\|w\|^2\) s.t. \(y_i(w^T x_i + b) \geq 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(\min \sum \alpha_i\) s.t. \(\sum \alpha_i y_i = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(\max \sum \alpha_i\) s.t. \(\sum \alpha_i y_i = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\min \frac{1}{2}\|w\|^2$$ s.t. $$y_i(w^T x_i + b) \geq 1$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán SVM nguyên thủy cực tiểu hóa $$\frac{1}{2}\|w\|^2$$ (tương đương cực đại hóa độ rộng lề $$2/\|w\|$$) dưới các ràng buộc phân loại đúng.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: SVM dual problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: SVM dual problem có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(\min \sum \alpha_i - \frac{1}{2}\sum \alpha_i \alpha_j y_i y_j x_i^T x_j\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(\max \sum \alpha_i - \frac{1}{2}\sum \alpha_i \alpha_j y_i y_j x_i^T x_j\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(\min \frac{1}{2}\|w\|^2 + C\sum \xi_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(\max \frac{1}{2}\|w\|^2\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\max \sum \alpha_i - \frac{1}{2}\sum \alpha_i \alpha_j y_i y_j x_i^T x_j$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán SVM đối ngẫu cực đại hóa hiệu giữa số hạng tuyến tính và số hạng bậc hai dưới ràng buộc $$\sum \alpha_i y_i = 0$$ và $$\alpha_i \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Support vectors --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Support vectors trong SVM là những điểm có:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(\alpha_i = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(\alpha_i &amp;gt; 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(y_i(w^T x_i + b) &amp;gt; 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(y_i(w^T x_i + b) &amp;lt; 1\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\alpha_i &amp;gt; 0$$&lt;/strong&gt;&lt;br /&gt;
                Các vector hỗ trợ có nhân tử đối ngẫu $$\alpha_i &amp;gt; 0$$ và (trong Hard-Margin SVM) nằm đúng trên biên lề: $$y_i(w^T x_i + b) = 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: LICQ condition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Linear Independence Constraint Qualification (LICQ) yêu cầu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Tất cả constraints đều active&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Gradients của active constraints độc lập tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Tất cả constraints đều inactive&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Objective function khả vi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Gradients của active constraints độc lập tuyến tính&lt;/strong&gt;&lt;br /&gt;
                LICQ yêu cầu các gradient của những ràng buộc tích cực tại điểm tối ưu độc lập tuyến tính, qua đó đảm bảo điều kiện KKT là điều kiện cần.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: L1 penalized problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Trong L1 penalized problem \(\min f(x) + \lambda\|x\|_1\), điều kiện KKT cho thành phần \(x_i\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(\frac{\partial f}{\partial x_i} + \lambda \text{sign}(x_i) = 0\) nếu \(x_i \neq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(\frac{\partial f}{\partial x_i} + \lambda = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(\frac{\partial f}{\partial x_i} = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(x_i = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\frac{\partial f}{\partial x_i} + \lambda \text{sign}(x_i) = 0$$ nếu $$x_i \neq 0$$&lt;/strong&gt;&lt;br /&gt;
                Khi $$x_i \neq 0$$, subgradient của $$|x_i|$$ là $$\text{sign}(x_i)$$. Khi $$x_i = 0$$, subgradient là $$[-1,1]$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Uniqueness in L1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Trong L1 regularization, nghiệm duy nhất khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) \(f\) là strictly convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) \(\lambda &amp;gt; 0\) bất kỳ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Active set được xác định duy nhất&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Tất cả các điều trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f$$ là strictly convex&lt;/strong&gt;&lt;br /&gt;
                Tính lồi chặt của $$f$$ đảm bảo bài toán có nghiệm duy nhất, ngay cả khi thành phần phạt L1 chỉ lồi chứ không lồi chặt.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: KKT matrix system --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Hệ phương trình KKT cho equality constrained QP có thể viết dưới dạng ma trận:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(\begin{bmatrix} Q &amp;amp; A^T \\ A &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x \\ \nu \end{bmatrix} = \begin{bmatrix} -c \\ b \end{bmatrix}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(\begin{bmatrix} Q &amp;amp; A \\ A^T &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x \\ \nu \end{bmatrix} = \begin{bmatrix} -c \\ b \end{bmatrix}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(Qx = -c\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) \(Ax = b\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\begin{bmatrix} Q &amp;amp; A^T \\ A &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x \\ \nu \end{bmatrix} = \begin{bmatrix} -c \\ b \end{bmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                KKT system kết hợp stationarity $$Qx + c + A^T\nu = 0$$ và feasibility $$Ax = b$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Constraint qualification --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Constraint qualification cần thiết để:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Đảm bảo KKT conditions sufficient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Đảm bảo KKT conditions necessary&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Đảm bảo hàm mục tiêu khả vi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Đảm bảo convexity&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Đảm bảo KKT conditions necessary&lt;/strong&gt;&lt;br /&gt;
                Điều kiện chuẩn ràng buộc (như LICQ, MFCQ) đảm bảo điều kiện KKT là điều kiện cần cho cực tiểu địa phương.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Second-order conditions --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Second-order sufficient condition yêu cầu Hessian của Lagrangian:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Positive definite trên toàn không gian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Positive definite trên tangent space của active constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Negative definite&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Singular&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Positive definite trên tangent space của active constraints&lt;/strong&gt;&lt;br /&gt;
                Điều kiện đủ bậc hai (SOSC) yêu cầu ma trận Hessian của hàm Lagrangian xác định dương trên không gian tiếp tuyến của các ràng buộc tích cực, đảm bảo điểm đang xét là cực tiểu địa phương chặt.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Penalty method connection --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Mối liên hệ giữa KKT multipliers và penalty methods:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Ước lượng multiplier của penalty method hội tụ đến KKT multipliers&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Penalty parameters là giới hạn của KKT multipliers&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Không có mối liên hệ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Chúng luôn bằng nhau&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Ước lượng multiplier của penalty method hội tụ đến KKT multipliers&lt;/strong&gt;&lt;br /&gt;
                Khi tham số phạt tiến ra vô cùng, nghiệm của bài toán phạt hội tụ về nghiệm tối ưu gốc và các đại lượng ước lượng nhân tử hội tụ về nhân tử KKT.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Sensitivity analysis --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: KKT multipliers cung cấp thông tin về:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Sensitivity của optimal value đối với thay đổi constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Tốc độ hội tụ của algorithm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Condition number của problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Số lượng iterations cần thiết&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Sensitivity của optimal value đối với thay đổi constraints&lt;/strong&gt;&lt;br /&gt;
                Các nhân tử KKT đóng vai trò giá bóng (shadow price), phản ánh tốc độ thay đổi của giá trị tối ưu khi nới lỏng hoặc siết chặt các ràng buộc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Practical applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: KKT conditions được ứng dụng trong:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Machine learning (SVM, neural networks)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Signal processing (water-filling, beamforming)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Economics (utility maximization, portfolio optimization)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các lĩnh vực trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các lĩnh vực trên&lt;/strong&gt;&lt;br /&gt;
                Điều kiện KKT là công cụ nền tảng của tối ưu hóa có ràng buộc, được ứng dụng rộng rãi trong học máy, xử lý tín hiệu, kinh tế học và nhiều ngành kỹ thuật khác.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Điều kiện KKT bao gồm:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Stationarity, primal feasibility, dual feasibility, complementary slackness&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Chỉ stationarity&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Chỉ feasibility&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Chỉ complementary slackness&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Stationarity, primal feasibility, dual feasibility, complementary slackness&lt;/strong&gt;&lt;br /&gt;
                KKT gồm 4 điều kiện: $$\nabla f + \sum \lambda_i \nabla g_i + \sum \nu_j \nabla h_j = 0$$, $$g_i(x) \leq 0$$, $$\lambda_i \geq 0$$, $$\lambda_i g_i(x) = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Điều kiện complementary slackness có nghĩa:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$\lambda_i g_i(x) = 0$$ cho mọi $$i$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$\lambda_i + g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$\lambda_i = g_i(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$\lambda_i \cdot g_i(x) = 1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\lambda_i g_i(x) = 0$$ cho mọi $$i$$&lt;/strong&gt;&lt;br /&gt;
                Complementary slackness: hoặc $$\lambda_i = 0$$ hoặc $$g_i(x) = 0$$ (ràng buộc tích cực).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Cho bài toán $$\min x^2$$ với $$x \geq 1$$. Điều kiện KKT tại nghiệm $$x^* = 1$$:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$2x - \lambda = 0, \lambda \geq 0, \lambda(1-x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$2x = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$x = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$\lambda = 1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$2x - \lambda = 0, \lambda \geq 0, \lambda(1-x) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Stationarity: $$2x - \lambda = 0$$. Tại $$x^* = 1$$: $$\lambda = 2$$, thỏa mãn complementary slackness.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: LICQ (Linear Independence Constraint Qualification) yêu cầu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Gradient của các ràng buộc tích cực độc lập tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Tất cả ràng buộc tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Hàm mục tiêu tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Ma trận Hessian khả nghịch&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Gradient của các ràng buộc tích cực độc lập tuyến tính&lt;/strong&gt;&lt;br /&gt;
                LICQ: các gradient $$\nabla g_i(x^*), \nabla h_j(x^*)$$ của ràng buộc tích cực phải độc lập tuyến tính.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Trong bài toán QP với KKT, ma trận hệ phương trình có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} H &amp;amp; A^T \\ A &amp;amp; 0 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} H &amp;amp; 0 \\ 0 &amp;amp; A \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$H + A^T A$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$H - A^T A$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\begin{pmatrix} H &amp;amp; A^T \\ A &amp;amp; 0 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                Hệ KKT cho QP có dạng ma trận khối với Hessian $$H$$ và ma trận ràng buộc $$A$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành Quiz!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;d&apos;, q4: &apos;a&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;b&apos;,
    q11: &apos;b&apos;, q12: &apos;b&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;b&apos;, q17: &apos;b&apos;, q18: &apos;a&apos;, q19: &apos;a&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã thành thạo KKT conditions và applications!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu tốt về optimality conditions và practical examples.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại complementary slackness và constraint qualification.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Ôn lại KKT conditions và stationarity.&apos;;
    } else {
        message = &apos;📖 Hãy học lại từ đầu về KKT theory nhé!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>12-06 Tính duy nhất trong các bài toán phạt L1</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_06_Uniqueness_in_L1_penalized_problems/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_06_Uniqueness_in_L1_penalized_problems</id>
   <content type="html">&lt;p&gt;Trong hồi quy tuyến tính cổ điển với \(p &amp;gt; n\) (nhiều biến đặc trưng hơn số mẫu quan sát — chuyện thường ngày trong di truyền học hay xử lý ảnh), hệ phương trình bình phương tối thiểu có vô số nghiệm. Người ta thường kỳ vọng khi thêm phạt \(\ell_1\) (bài toán Lasso), nghiệm \(\hat{\beta}\) sẽ trở nên duy nhất. Nhưng thực tế thú vị hơn thế nhiều: &lt;strong&gt;ngay cả khi \(\lambda &amp;gt; 0\), Lasso vẫn có thể có vô số nghiệm \(\hat{\beta}\) khác nhau!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tuy nhiên, một định lý tuyệt đẹp của Ryan Tibshirani (2013) chứng minh bằng &lt;strong&gt;điều kiện KKT của Lasso&lt;/strong&gt; cho thấy điều kỳ diệu sau: dù có nhiều vector trọng số \(\hat{\beta}\) khác nhau, &lt;strong&gt;giá trị dự đoán \(X\hat{\beta}\) luôn duy nhất tuyệt đối&lt;/strong&gt;; mọi nghiệm đều có cùng dấu trên tập biến hoạt động; và chỉ cần các cột của ma trận \(X\) ở &lt;em&gt;vị trí tổng quát (general position)&lt;/em&gt; (điều xảy ra với xác suất 1 khi dữ liệu rút từ phân phối liên tục!), nghiệm Lasso \(\hat{\beta}\) lập tức &lt;strong&gt;duy nhất&lt;/strong&gt; ngay cả khi \(p \gg n\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tính-duy-nhất-trong-bài-toán-phạt-ell_1&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tính duy nhất trong bài toán phạt \(\ell_1\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hệ điều kiện KKT của Lasso:&lt;/strong&gt; Điểm \(\hat{\beta}\) tối ưu khi và chỉ khi tồn tại vector dấu \(s \in \partial\|\hat{\beta}\|_1\) sao cho:
\(X^T(y - X\hat{\beta}) = \lambda s, \quad \text{với } s_j = \operatorname{sign}(\hat{\beta}_j) \text{ nếu } \hat{\beta}_j \ne 0, \text{ và } |s_j| \le 1 \text{ nếu } \hat{\beta}_j = 0.\)
Chú ý: vế trái là độ tương quan giữa từng đặc trưng \(X_j\) với phần dư \(y - X\hat{\beta}\)! Tập các biến đạt cực đại tương quan \(|X_j^T(y - X\hat{\beta})| = \lambda\) gọi là &lt;strong&gt;tập cân bằng (equicorrelation set)&lt;/strong&gt; \(\mathcal{E}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính duy nhất tuyệt đối của giá trị dự đoán \(X\hat{\beta}\):&lt;/strong&gt; Vì hàm \(\frac{1}{2}\|y - u\|_2^2\) là hàm &lt;strong&gt;lồi chặt&lt;/strong&gt; theo vector dự đoán \(u = X\beta\), mọi nghiệm tối ưu \(\hat{\beta}^{(1)}, \hat{\beta}^{(2)}\) bắt buộc phải cho cùng một dự đoán \(X\hat{\beta}^{(1)} = X\hat{\beta}^{(2)}\), và do đó có cùng phần dư và cùng tập cân bằng \(\mathcal{E}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện đủ cho tính duy nhất của \(\hat{\beta}\):&lt;/strong&gt; Mọi tọa độ ngoài \(\mathcal{E}\) đều bắt buộc bằng \(0\) (\(\hat{\beta}_{-\mathcal{E}} = 0\)). Vì vậy nếu ma trận con \(X_{\mathcal{E}}\) có hạng cột đầy đủ (\(\operatorname{null}(X_{\mathcal{E}}) = \{0\}\)), thì từ \(X_{\mathcal{E}} \hat{\beta}_{\mathcal{E}}^{(1)} = X_{\mathcal{E}} \hat{\beta}_{\mathcal{E}}^{(2)}\) suy ngay ra \(\hat{\beta}^{(1)} = \hat{\beta}^{(2)}\)!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Vị trí tổng quát (General Position) khi \(p &amp;gt; n\):&lt;/strong&gt; Nếu dữ liệu rút từ phân phối xác suất liên tục trên \(\mathbb{R}^{n \times p}\), các cột của \(X\) ở vị trí tổng quát với xác suất 1, bảo đảm $$&lt;/td&gt;
          &lt;td&gt;\mathcal{E}&lt;/td&gt;
          &lt;td&gt;\le n\(và\)X_{\mathcal{E}}\(luôn đủ hạng cột\)\implies\(Lasso có nghiệm duy nhất với tối đa\)n\(hệ số khác\)0$$!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-ví-dụ-tính-tay-khi-lasso-có-vô-số-nghiệm-hatbeta-nhưng-xhatbeta-vẫn-duy-nhất&quot;&gt;Giải thích: Ví dụ tính tay khi Lasso có vô số nghiệm \(\hat{\beta}\) nhưng \(X\hat{\beta}\) vẫn duy nhất&lt;/h3&gt;

&lt;p&gt;Xét bài toán Lasso với \(n = 1\) mẫu quan sát \(y = 4\) và \(p = 2\) đặc trưng giống hệt nhau (cộng tuyến hoàn hảo, vi phạm vị trí tổng quát!):
\(X = \begin{pmatrix} 1 &amp;amp; 1 \end{pmatrix}, \quad \lambda = 1 \implies \min_{\beta_1, \beta_2} \; \frac{1}{2}(4 - \beta_1 - \beta_2)^2 + |\beta_1| + |\beta_2|.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải điều kiện KKT của Lasso:&lt;/strong&gt;
Đặt \(u = X\beta = \beta_1 + \beta_2\). Điều kiện KKT cho cả hai cột giống nhau đòi:
\(1 \cdot (4 - u) = 1 \cdot s_1 = 1 \cdot s_2, \quad s_1 \in \partial|\beta_1|, \; s_2 \in \partial|\beta_2|.\)
Nếu \(\beta_1, \beta_2 \ge 0\) và không đồng thời bằng \(0\), ta cần \(s_1 = s_2 = 1 \implies 4 - u = 1 \implies u^* = \beta_1^* + \beta_2^* = 3\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan sát tập nghiệm vô hạn nhưng chung một dự đoán duy nhất:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\hat{\beta}^{(1)} = (3, 0)^T \implies X\hat{\beta}^{(1)} = 3\), hàm mục tiêu \(= \frac{1}{2}(4-3)^2 + 3 = 3.5\).&lt;/li&gt;
      &lt;li&gt;\(\hat{\beta}^{(2)} = (0, 3)^T \implies X\hat{\beta}^{(2)} = 3\), hàm mục tiêu \(= \frac{1}{2}(4-3)^2 + 3 = 3.5\).&lt;/li&gt;
      &lt;li&gt;Mọi tổ hợp lồi \(\hat{\beta}(\theta) = (3\theta,\; 3(1-\theta))^T\) với \(\theta \in [0, 1]\) đều là nghiệm tối ưu toàn cục (vô số nghiệm!), vì \(X_{\mathcal{E}} = (1, 1)\) không đủ hạng cột!&lt;/li&gt;
      &lt;li&gt;Thế nhưng giá trị dự đoán \(X\hat{\beta} = 3\) và chuẩn \(\|\hat{\beta}\|_1 = 3\) là &lt;strong&gt;duy nhất tuyệt đối&lt;/strong&gt; trên toàn bộ đoạn nghiệm!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Bài toán hồi quy tuyến tính có phạt \(L_1\) dưới đây còn được gọi là bài toán &lt;strong&gt;lasso&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;&amp;amp;&amp;amp;\hat{\beta} \in \text{argmin}_{\beta \in \mathbb{R}^p} \frac{1}{2} \| y - X\beta \|^2_2 + \lambda \|\beta\|_1, \qquad \\\\
&amp;amp;&amp;amp; \text{ --- (1) } &amp;amp;\text{cho trước } y \in \mathbb{R}^n, \\\\
&amp;amp;&amp;amp;&amp;amp; \text{ ma trận } X \in \mathbb{R}^{n \text{ x } p} \ \text{ của các biến dự báo,} \\\\
&amp;amp;&amp;amp;&amp;amp; \text{và tham số điều chỉnh } \lambda \ge 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán lasso (1) có nghiệm duy nhất khi hàm mục tiêu lồi chặt, tức khi \(\text{rank}(X) = p\). Ngược lại, khi \(\text{rank}(X) &amp;lt; p\) (hàm mục tiêu không lồi chặt), bài toán có thể có vô số nghiệm (xem thêm: &lt;a href=&quot;https://en.wikipedia.org/wiki/Underdetermined_system&quot;&gt;Hệ thống thiếu xác định&lt;/a&gt;). Lưu ý rằng nếu số biến \(p\) lớn hơn số quan sát \(n\), thì \(\text{rank}(X)\) chắc chắn nhỏ hơn \(p\).&lt;br /&gt;
Tuy nhiên, trong một số điều kiện cụ thể, bài toán lasso vẫn có nghiệm duy nhất bất kể tỷ lệ giữa \(n\) và \(p\) [13].&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; Khi hàm \(f\) khả vi và lồi chặt, \(\lambda &amp;gt; 0\), và các phần tử của \(X \in \mathbb{R}^{n \times p}\) tuân theo một phân phối xác suất liên tục trên \(\mathbb{R}^{np}\), bài toán tối ưu hóa tương ứng luôn có nghiệm duy nhất (với xác suất 1). Hơn nữa, nghiệm này có tối đa \(\min\{n,p\}\) thành phần khác không, mà không cần ràng buộc gì về kích thước của \(X\) (kể cả khi \(p \gg n\)).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;các-tính-chất-cơ-bản-và-điều-kiện-kkt&quot;&gt;Các tính chất cơ bản và điều kiện KKT&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 1.&lt;/strong&gt; Với mọi \(y, X\) và \(\lambda \ge 0\), bài toán lasso (1) có các tính chất sau:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Bài toán chỉ có một nghiệm duy nhất hoặc có vô số nghiệm.&lt;/li&gt;
    &lt;li&gt;Mọi nghiệm lasso \(\hat{\beta}\) đều cho cùng giá trị dự báo \(X\hat{\beta}\).&lt;/li&gt;
    &lt;li&gt;Khi \(\lambda &amp;gt; 0\), mọi nghiệm lasso \(\hat{\beta}\) đều có cùng chuẩn \(\ell_1\) (\(\|\hat{\beta}\|_1\)).&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

\[\text{ }\]

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;Vì (1) là bài toán lồi, nếu tồn tại hai nghiệm phân biệt \(\hat{\beta}^{(1)}\) và \(\hat{\beta}^{(2)}\), thì với mọi \(0 &amp;lt; \alpha &amp;lt; 1\), tổ hợp lồi \(\alpha \hat{\beta}^{(1)} + (1 - \alpha) \hat{\beta}^{(2)}\) cũng là nghiệm, nên bài toán có vô số nghiệm.&lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;&amp;amp; 3. Giả sử \(\hat{\beta}^{(1)}\) và \(\hat{\beta}^{(2)}\) là hai nghiệm với cùng giá trị tối ưu \(c^\star\). Khi đó, với mọi \(0 &amp;lt; \alpha &amp;lt; 1\), tổ hợp lồi \(\alpha \hat{\beta}^{(1)} + (1 - \alpha) \hat{\beta}^{(2)}\) cũng đạt giá trị tối ưu \(c^\star\):&lt;/li&gt;
  &lt;/ol&gt;

\[\begin{align}
&amp;amp;\frac{1}{2} \| y - X(\alpha \hat{\beta}^{(1)} + (1 - \alpha) \hat{\beta}^{(2)}) \|_2^2 + \lambda \| \alpha \hat{\beta}^{(1)} + (1 - \alpha) \hat{\beta}^{(2)} \|_1 \\
&amp;amp; = \alpha c^\star + (1-\alpha) c^\star = c^\star
\end{align}\]

  &lt;p&gt;Vì hàm \(u \mapsto \frac{1}{2}\|y - u\|_2^2\) lồi chặt, đẳng thức trên chỉ xảy ra khi \(X\hat{\beta}^{(1)} = X\hat{\beta}^{(2)}\), tức \(X\hat{\beta}\) là duy nhất với mọi nghiệm \(\hat{\beta}\). Khi \(\lambda &amp;gt; 0\), thay lại vào giá trị tối ưu \(c^\star\) suy ra \(\|\hat{\beta}\|_1\) cũng phải bằng nhau đối với mọi nghiệm.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Quay lại bài toán (1), các điều kiện KKT của bài toán lasso có dạng:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;&amp;amp;X^T (y - X\hat{\beta}) = \lambda \gamma, \qquad \text{ --- (2)} \\\\
&amp;amp;&amp;amp;\gamma_i \in 
\begin{cases}
\{ \text{sign}(\hat{\beta_i}) \} &amp;amp; \text{nếu } \hat{\beta_i} \neq 0 \\\\
[-1, 1] &amp;amp; \text{nếu } \hat{\beta_i} = 0,
\end{cases} \\\\
&amp;amp;&amp;amp;\text{với } i = 1, \dots, p. \text{ --- (3)} \\\\
&amp;amp;&amp;amp;\text{Ở đây } \gamma \in \mathbb{R}^p \text{ là một dưới gradient (subgradient) của hàm } \\
&amp;amp;&amp;amp;f(x) = \| x \|_1 \text{ tại } x = \hat{\beta}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nghiệm \(\hat{\beta}\) của (1) thỏa mãn (2) và (3) với một vector \(\gamma\) nào đó.&lt;/p&gt;

&lt;p&gt;Ta dùng các điều kiện KKT này để biểu diễn nghiệm lasso ở dạng tường minh hơn. Trong phần dưới đây, giả sử \(\lambda &amp;gt; 0\). Trước hết, định nghĩa tập tương quan bằng nhau (equicorrelation set) \(\mathcal{E}\), gồm mọi chỉ số \(i\) có \(\hat{\beta}_i \neq 0\) và mọi chỉ số \(j\) có \(\hat{\beta}_j = 0\) nhưng \(\vert\gamma_j\vert = 1\):&lt;/p&gt;

\[\mathcal{E} = \{ i \in \{1, \dots, p \}  : \vert X_i^T (y - X\hat{\beta}) \vert = \lambda \}. \qquad \text{ --- (4)}\]

&lt;p&gt;Tiếp theo, định nghĩa vector dấu tương quan bằng nhau (equicorrelation signs) \(s\) như sau, với \(X_\mathcal{E}\) là ma trận gồm các cột \(i \in \mathcal{E}\) của \(X\):&lt;/p&gt;

\[s = \text{sign}(X^T_\mathcal{E} (y -X\hat{\beta})). \qquad \text{ --- (5)}\]

&lt;p&gt;Theo định nghĩa của \(\gamma\), ta có \(\mathcal{E} = \{i \in \{1, \dots, p \} : \vert \gamma_i \vert = 1 \}\) và \(s = \gamma_{\mathcal{E}}\). Hơn nữa, theo Bổ đề 1 (mục 2), \(X\hat{\beta}\) là duy nhất, nên \(\mathcal{E}\) và \(s\) cũng duy nhất.&lt;/p&gt;

&lt;p&gt;Từ (3), với mọi nghiệm lasso \(\hat{\beta}\) ta có \(\hat{\beta}_{-\mathcal{E}} = 0\). Viết lại phương trình (2) trên tập chỉ số \(\mathcal{E}\):&lt;/p&gt;

\[X^T_\mathcal{E} ( y - X_\mathcal{E} \hat{\beta_\mathcal{E}} ) = \lambda \gamma_\mathcal{E}=  \lambda s. \qquad \text{ --- (6)}\]

&lt;p&gt;Nhân hai vế của (6) với giả nghịch đảo \((X^T_\mathcal{E})^+\) và sử dụng đẳng thức \((X^T_\mathcal{E})^+ X^T_\mathcal{E} = X_\mathcal{E} X_\mathcal{E}^+\) (phép chiếu vuông góc lên không gian cột của \(X_\mathcal{E}\)), ta được:&lt;/p&gt;

\[\begin{align}
&amp;amp; X_\mathcal{E} X_\mathcal{E}^+ X_\mathcal{E} \hat{\beta_\mathcal{E}} = X_\mathcal{E} X_\mathcal{E}^+ ( y - (X^T_\mathcal{E})^+  \lambda s) \\\\
\Leftrightarrow
&amp;amp; X_\mathcal{E} \hat{\beta_\mathcal{E}} = X_\mathcal{E} X_\mathcal{E}^+ ( y - (X^T_\mathcal{E})^+  \lambda s).
\end{align}\]

&lt;p&gt;Vì \(X\hat{\beta} = X_\mathcal{E} \hat{\beta_\mathcal{E}}\), nên:&lt;/p&gt;

\[X \hat{\beta} = X_\mathcal{E} X_\mathcal{E}^+ ( y - (X^T_\mathcal{E})^+  \lambda s), \qquad \text{ --- (7)}\]

&lt;p&gt;và mọi nghiệm lasso \(\hat{\beta}\) đều có dạng:&lt;/p&gt;

\[\begin{align}
&amp;amp; \hat{\beta_{-\mathcal{E}}} = 0 \text{ và } \hat{\beta_{\mathcal{E}}} = X_\mathcal{E}^+ ( y - (X^T_\mathcal{E})^+ \lambda s) + b, \qquad \text{ --- (8)} \\\\
&amp;amp; \text{với } b \in \text{null}(X_\mathcal{E}).
\end{align}\]

&lt;h2 id=&quot;điều-kiện-đủ-cho-tính-duy-nhất&quot;&gt;Điều kiện đủ cho tính duy nhất&lt;/h2&gt;

&lt;p&gt;Để \(\hat{\beta_{\mathcal{E}}}\) trong (8) là duy nhất, ta cần \(b = 0\) (vì thành phần \(X_\mathcal{E}^+ ( y - (X^T_\mathcal{E})^+ \lambda s)\) đã xác định duy nhất). Từ đó suy ra kết quả sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 2.&lt;/strong&gt; Với mọi \(y, X\) và \(\lambda &amp;gt; 0\), nếu \(\text{null}(X_\mathcal{E}) = \{0\}\), tức \(\text{rank}(X_\mathcal{E}) = \vert\mathcal{E}\vert\) (&lt;a href=&quot;https://www.quora.com/When-the-null-space-of-a-matrix-is-the-zero-vector-the-matrix-is-invertible-Why/answer/Alexander-Farrugia&quot;&gt;tham khảo&lt;/a&gt;), thì nghiệm lasso là duy nhất và được cho bởi:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;&amp;amp; \hat{\beta_{-\mathcal{E}}} = 0 \text{ và } \hat{\beta_{\mathcal{E}}} = (X^T_\mathcal{E}X_\mathcal{E})^{-1} ( X^T_\mathcal{E} y - \lambda s), \qquad \text{ --- (9)} \\\\
&amp;amp;&amp;amp; \text{trong đó } \mathcal{E} \text{ và } s \text{ là tập và vector dấu equicorrelation định nghĩa trong (4) và (5)}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Lưu ý rằng nghiệm này có tối đa \(\min\{n, p\}\) thành phần khác không.&lt;/p&gt;

&lt;p&gt;Tiếp theo, ta tìm một điều kiện trực tiếp trên ma trận \(X\) đảm bảo \(\text{null}(X_\mathcal{E}) = \{0\}\). Giả sử phản chứng \(\text{null}(X_\mathcal{E}) \neq \{0\}\). Khi đó, tồn tại chỉ số \(i \in \mathcal{E}\) sao cho cột \(X_i\) biểu diễn tuyến tính qua các cột còn lại trong \(\mathcal{E}\):&lt;/p&gt;

\[X_i = \sum_{j \in \mathcal{E} \backslash \{i\} } c_j X_j,\\\\
\text{với } c_j \in \mathbb{R}, j \in \mathcal{E}.\]

&lt;p&gt;Nhân hai vế với \(s_i\) và chèn \(s_j^2 = 1\) vào vế phải:&lt;/p&gt;

\[s_i X_i = \sum_{j \in \mathcal{E} \backslash \{i\} } (s_i s_j c_j) \cdot (s_j X_j). \qquad \text{ --- (10)}\]

&lt;p&gt;Đặt phần dư lasso \(r = y - X \hat{\beta}\); khi đó với mọi \(j \in \mathcal{E}\) ta có \(X_j^T r = s_j \lambda\). Lấy tích vô hướng hai vế của (10) với \(r\) (với \(\lambda &amp;gt; 0\)), ta thu được:&lt;/p&gt;

\[\lambda = \sum_{j \in \mathcal{E} \backslash \{i\} } (s_i s_j c_j) \lambda \quad \text{ và } \quad \sum_{j \in \mathcal{E} \backslash \{i\} } (s_i s_j c_j) = 1.\]

&lt;p&gt;Như vậy, nếu \(\text{null}(X_\mathcal{E}) \neq \{0\}\) thì tồn tại \(i \in \mathcal{E}\) sao cho:&lt;/p&gt;

\[s_iX_i = \sum_{j \in \mathcal{E} \backslash \{i\} } a_j \cdot s_j X_j, \text{ với } \sum_{j \in \mathcal{E} \backslash \{i\} } a_j = 1.\]

&lt;p&gt;Điều này có nghĩa là \(s_i X_i\) nằm trong bao affine của các điểm \(s_j X_j\) (\(j \in \mathcal{E} \backslash \{i\}\)). Nói cách khác, một tập con gồm \(k+2\) phần tử như vậy nằm trong một không gian con affine có số chiều không vượt quá \(k\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter12/l1_uniqueness.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] 4 phần tử trong không gian affine 2 chiều [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Để đảm bảo \(\text{null}(X_\mathcal{E}) = \{0\}\), chỉ cần các cột của ma trận \(X \in \mathbb{R}^{n \text{ x } p}\) ở &lt;a href=&quot;https://en.wikipedia.org/wiki/General_position&quot;&gt;vị trí tổng quát (general position)&lt;/a&gt;: không có không gian con affine \(k\) chiều nào chứa quá \(k+1\) phần tử thuộc tập \(\{\pm X_1, \dots, \pm X_p\}\) (với mọi \(k &amp;lt; \min\{n, p\}\)).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 3.&lt;/strong&gt; Nếu các cột của ma trận \(X\) ở vị trí tổng quát thì với mọi \(y\) và \(\lambda &amp;gt; 0\), nghiệm lasso là duy nhất và thỏa mãn (9).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Những ma trận \(X\) nào thỏa mãn điều kiện vị trí tổng quát? Ta có kết quả sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 4.&lt;/strong&gt; Nếu các phần tử của ma trận \(X \in \mathbb{R}^{n \text{ x } p}\) tuân theo một phân phối xác suất liên tục trên \(\mathbb{R}^{np}\) thì với mọi \(y\) và \(\lambda &amp;gt; 0\), nghiệm lasso là duy nhất (với xác suất 1) và thỏa mãn (9).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Lý do là khi các phần tử được rút từ phân phối xác suất liên tục, các vector cột ở vị trí tổng quát với xác suất 1, nên các tập con cột liên quan độc lập tuyến tính (&lt;a href=&quot;https://math.stackexchange.com/questions/432447/probability-that-n-vectors-drawn-randomly-from-mathbbrn-are-linearly-ind?rq=1&quot;&gt;tham khảo&lt;/a&gt;).&lt;/p&gt;

&lt;h2 id=&quot;hàm-mất-mát-lồi-tổng-quát&quot;&gt;Hàm mất mát lồi tổng quát&lt;/h2&gt;

&lt;p&gt;Kết quả tương tự cũng đúng cho bài toán phạt \(\ell_1\) với hàm mất mát lồi tổng quát [13]:&lt;/p&gt;

\[\hat{\beta} \in \text{argmin}_{\beta \in \mathbb{R}^p} f(X\beta) + \lambda \|\beta\|_1, \qquad \text{ --- (11) }\]

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 5.&lt;/strong&gt; Nếu các phần tử của ma trận \(X \in \mathbb{R}^{n \text{ x } p}\) tuân theo một phân phối xác suất liên tục trên \(\mathbb{R}^{np}\), thì với mọi hàm \(f\) khả vi, lồi chặt và mọi \(\lambda &amp;gt; 0\), bài toán (11) luôn có nghiệm duy nhất (với xác suất 1). Nghiệm này có tối đa \(\min\{n,p\}\) thành phần khác không.&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>12-05 Dạng ràng buộc và dạng Lagrange</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_05_Constrained_and_Lagrange_forms/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_05_Constrained_and_Lagrange_forms</id>
   <content type="html">&lt;p&gt;Trong sách giáo khoa thống kê và thư viện học máy (như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt;), bạn sẽ thấy bài toán Lasso hay Ridge regression đôi khi được viết dưới &lt;strong&gt;dạng ràng buộc (C)&lt;/strong&gt;:
\(\min_\beta \; \frac{1}{2}\|y - X\beta\|_2^2 \quad \text{s.t.} \quad \|\beta\|_1 \le t,\)
nhưng lúc khác lại viết dưới &lt;strong&gt;dạng phạt / dạng Lagrange (L)&lt;/strong&gt;:
\(\min_\beta \; \frac{1}{2}\|y - X\beta\|_2^2 + \lambda \|\beta\|_1.\)
Rất nhiều người học mặc nhiên cho rằng hai dạng này “tương đương nhau” — nhưng chính xác thì chúng tương đương theo nghĩa nào? Có phải &lt;em&gt;mọi&lt;/em&gt; \(t\) đều ứng với một \(\lambda\), và &lt;em&gt;mọi&lt;/em&gt; \(\lambda\) đều ứng với một \(t\) không?&lt;/p&gt;

&lt;p&gt;Bài học này dùng đúng công cụ &lt;strong&gt;điều kiện KKT&lt;/strong&gt; để trả lời câu hỏi ấy một cách sắc bén và chính xác tuyệt đối: nếu bài toán lồi và thỏa Slater, &lt;strong&gt;cả hai dạng quét qua chính xác cùng một họ nghiệm tối ưu&lt;/strong&gt; (đường chính quy hóa — regularization path)! Tuy nhiên, khi bài toán &lt;em&gt;không lồi&lt;/em&gt; (như hồi quy best-subset dùng chuẩn \(\ell_0\)), sự tương đương này có thể sụp đổ: dạng Lagrange có thể bỏ sót cả những nghiệm hoàn hảo của dạng ràng buộc!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-sự-tương-đương-giữa-dạng-c-và-dạng-l&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của sự tương đương giữa dạng (C) và dạng (L)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chiều thuận (Từ dạng Lagrange (L) \(\to\) dạng ràng buộc (C)) — LUÔN ĐÚNG (kể cả không lồi!):&lt;/strong&gt; Nếu \(x^*\) là nghiệm tối ưu của \(\min_x f(x) + \lambda h(x)\) với \(\lambda \ge 0\), chỉ cần đặt \(t = h(x^*)\), lập tức \(x^*\) cũng là nghiệm tối ưu của \(\min_{h(x) \le t} f(x)\)! (Chứng minh 2 dòng: với mọi \(x\) có \(h(x) \le t = h(x^*)\), ta có \(f(x) \ge f(x) + \lambda(h(x) - h(x^*)) \ge f(x^*)\)!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiều ngược (Từ dạng ràng buộc (C) \(\to\) dạng Lagrange (L)) — CẦN TÍNH LỒI + SLATER:&lt;/strong&gt; Nếu \(x^*\) là nghiệm của (C) với ngân sách \(t\), nhờ tính lồi và điều kiện Slater tồn tại nhân tử Lagrange tối ưu \(\lambda^* \ge 0\) sao cho \(x^*\) thỏa điều kiện dừng \(0 \in \partial f(x^*) + \lambda^* \partial h(x^*)\) — mà đó chính xác là điều kiện tối ưu của dạng (L) với \(\lambda = \lambda^*\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ánh xạ nghịch biến giữa ngân sách \(t\) và lực phạt \(\lambda\):&lt;/strong&gt; Ngân sách \(t\) càng nhỏ (ràng buộc càng chặt), lực phạt \(\lambda\) tương ứng càng lớn; khi \(t\) lớn hơn hoặc bằng \(h(x_{\text{unconstrained}}^*)\) (ràng buộc lỏng), lực phạt tương ứng bằng đúng \(\lambda = 0\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-ánh-xạ-11-giữa-ngân-sách-t-và-lực-phạt-lambda-trên-ridge-1d&quot;&gt;Giải thích: Tính tay ánh xạ 1–1 giữa ngân sách \(t\) và lực phạt \(\lambda\) trên Ridge 1D&lt;/h3&gt;

&lt;p&gt;Xét bài toán Ridge 1D với nghiệm không ràng buộc là \(x_{\text{OLS}} = 5\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dạng ràng buộc (C):&lt;/strong&gt; \(\min_x \frac{1}{2}(x - 5)^2 \;\text{ s.t. }\; \frac{1}{2}x^2 \le t\) (với \(t &amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dạng Lagrange (L):&lt;/strong&gt; \(\min_x \frac{1}{2}(x - 5)^2 + \lambda \cdot \frac{1}{2}x^2\) (với \(\lambda \ge 0\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải dạng Lagrange (L) theo \(\lambda \ge 0\):&lt;/strong&gt;
Đạo hàm \((x - 5) + \lambda x = 0 \implies x^*(\lambda) = \frac{5}{1 + \lambda}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm ngân sách \(t\) tương ứng cho từng giá trị \(\lambda\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Chọn \(\lambda = 1.5\): nghiệm là \(x^* = \frac{5}{1 + 1.5} = 2.0\). Đặt ngân sách \(t = \frac{1}{2}(2.0)^2 = 2.0\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Kiểm tra ngược dạng ràng buộc (C) với \(t = 2.0\) (tức $$&lt;/td&gt;
              &lt;td&gt;x&lt;/td&gt;
              &lt;td&gt;\le 2\(): để\)(x - 5)^2\(nhỏ nhất trên\)[-2, 2]\(, hiển nhiên chọn\)x^* = 2.0\(— trùng khít! Và nhân tử KKT tại\)x^* = 2\(là\)u^* = -\frac{2 - 5}{2} = 1.5 = \lambda$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp ràng buộc lỏng (\(t \ge 12.5\), tức \(|x| \ge 5\)):&lt;/strong&gt;
Với mọi \(t \ge 12.5\), nghiệm dạng (C) luôn đứng yên tại \(x^* = 5\), và tất cả các giá trị \(t \in [12.5, \infty)\) đều ánh xạ vào duy nhất một giá trị \(\lambda = 0\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trong thống kê và học máy, ta thường chuyển đổi qua lại giữa &lt;strong&gt;dạng ràng buộc&lt;/strong&gt; và &lt;strong&gt;dạng Lagrange&lt;/strong&gt;. Hai dạng bài toán này được định nghĩa như sau:&lt;/p&gt;

&lt;h3 id=&quot;dạng-ràng-buộc-ký-hiệu-là-c&quot;&gt;Dạng ràng buộc (ký hiệu là (C))&lt;/h3&gt;
&lt;blockquote&gt;
\[\min_x \: f(x) \quad \text{ với điều kiện } h(x) \le t,\\\\
\text{trong đó } t \in \mathbb{R} \text{ là tham số điều chỉnh.}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;dạng-lagrange-ký-hiệu-là-l&quot;&gt;Dạng Lagrange (ký hiệu là (L))&lt;/h3&gt;
&lt;blockquote&gt;
\[\min_x \: f(x) + \lambda \cdot h(x),\\\\
\text{trong đó } \lambda \ge 0 \text{ là tham số điều chỉnh.}\]
&lt;/blockquote&gt;

&lt;p&gt;Khi \(f\) và \(h\) đều là các hàm lồi, xét mối quan hệ tương đương về nghiệm giữa hai bài toán:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Từ (C) sang (L):&lt;/strong&gt; Nếu bài toán (C) khả thi chặt (thỏa mãn điều kiện Slater) nên có tính đối ngẫu mạnh, thì ứng với nghiệm \(x^\star\) của (C), tồn tại nhân tử đối ngẫu \(\lambda^\star \ge 0\) sao cho \(x^\star\) cực tiểu hóa hàm mục tiêu&lt;/li&gt;
&lt;/ol&gt;

\[f(x) + \lambda^\star \cdot (h(x) - t),\]

&lt;p&gt;và do đó \(x^\star\) cũng là nghiệm của (L) với \(\lambda = \lambda^\star\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Từ (L) sang (C):&lt;/strong&gt; Nếu \(x^\star\) là nghiệm của (L) với tham số \(\lambda^\star \ge 0\), thì \(x^\star\) cũng là nghiệm của (C) khi đặt \(t = h(x^\star)\). Lý do là cặp \((x^\star, \lambda^\star)\) thỏa mãn các điều kiện KKT của (L) thì đồng thời cũng thỏa mãn toàn bộ các điều kiện KKT của (C) tại \(t = h(x^\star)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;\(\rightarrow\) Điều kiện KKT của (L):&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\nabla_x f(x^\star) + \lambda^\star \nabla_x h(x^\star) &amp;amp;= 0\\\\
\lambda^\star &amp;amp;\ge 0\\\\
\end{align}\]

  &lt;p&gt;&lt;strong&gt;\(\rightarrow\) Điều kiện KKT của (C) khi \(t = h(x^\star)\):&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\nabla_x f(x^\star) + \lambda^\star \nabla_x h(x^\star) &amp;amp;= 0\\\\
\lambda^\star &amp;amp;\ge 0\\\\
\lambda^\star (\underbrace{h(x^\star) - h(x^\star)}_{=0}) &amp;amp;= 0
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tóm lại, hai chiều suy luận ở mục 1 và mục 2 cho thấy mối liên hệ sau giữa tập nghiệm của (C) và (L):&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter12/conclusion.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Kết luận [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Vậy khi nào (C) và (L) tương đương hoàn toàn ngay cả tại biên?&lt;br /&gt;
Chẳng hạn, khi \(h(x) \ge 0\) (như hàm chuẩn), \(t = 0\) và \(\lambda = \infty\), hai dạng tương đương hoàn toàn. Với \(t = 0\) và \(h(x) \ge 0\), ràng buộc trong (C) trở thành \(h(x) = 0\); tương tự, khi đặt \(\lambda = \infty\), bài toán (L) cũng áp đặt đúng ràng buộc \(h(x) = 0\).&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-dạng-ràng-buộc-và-dạng-lagrange&quot;&gt;Tự tay thử: dạng ràng buộc và dạng Lagrange&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;cl&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>12-04 Ví dụ Máy Vector Hỗ Trợ (Support Vector Machines - SVM)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_04_Example_support_vector_machines/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_04_Example_support_vector_machines</id>
   <content type="html">&lt;p&gt;Trong lịch sử học máy, hiếm có thuật toán nào vừa sắc sảo về hình học, vừa đẹp đẽ về đại số tối ưu như &lt;strong&gt;Máy vector hỗ trợ (Support Vector Machine — SVM)&lt;/strong&gt;. Nhưng tại sao thuật toán này lại mang cái tên kỳ lạ &lt;em&gt;“Máy vector hỗ trợ”&lt;/em&gt;? Tại sao một bộ phân loại huấn luyện trên 100,000 điểm dữ liệu cuối cùng lại có thể &lt;strong&gt;vứt bỏ 95% số điểm&lt;/strong&gt;, chỉ giữ lại vài nghìn điểm nằm sát ranh giới mà kết quả phân loại vẫn giữ nguyên 100%?&lt;/p&gt;

&lt;p&gt;Câu trả lời không nằm ở một mẹo lập trình nào cả — nó nằm gọn trong &lt;strong&gt;điều kiện bù (complementary slackness)&lt;/strong&gt; của hệ điều kiện KKT! Bài học toàn diện này dẫn bạn đi từ hình học khoảng cách siêu phẳng, xây dựng bài toán tối ưu Soft-Margin SVM có biến bù \(\xi_i\), cho đến việc giải mã trọn vẹn 3 vùng phân bố của dữ liệu qua giá trị nhân tử Lagrange \(\alpha_i^* \in [0, C]\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-nối-hình-học-svm-với-điều-kiện-kkt&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột nối hình học SVM với điều kiện KKT&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hình học lề cực đại (Maximum Margin):&lt;/strong&gt; Khoảng cách từ siêu phẳng \(\beta^T x + \beta_0 = 0\) đến hai biên phân loại \(\beta^T x + \beta_0 = \pm 1\) là \(\frac{1}{\|\beta\|_2}\). Cực đại hóa lề tương đương cực tiểu hóa \(\frac{1}{2}\|\beta\|_2^2\) với ràng buộc \(y_i(\beta^T x_i + \beta_0) \ge 1 - \xi_i, \; \xi_i \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng KKT tạo ra biểu diễn thưa của \(\beta^*\):&lt;/strong&gt; Lấy đạo hàm Lagrangian theo \(\beta, \beta_0, \xi_i\) bằng \(0\) cho ta 3 đẳng thức vàng:
\(\beta^* = \sum_{i=1}^n \alpha_i^* y_i x_i, \qquad \sum_{i=1}^n \alpha_i^* y_i = 0, \qquad \alpha_i^* + \mu_i^* = C.\)
Vì \(\alpha_i^* \ge 0\) và \(\mu_i^* \ge 0\), ta lập tức thu được ràng buộc hộp nổi tiếng \(0 \le \alpha_i^* \le C\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ba chế độ của điểm dữ liệu đọc trực tiếp từ điều kiện bù KKT:&lt;/strong&gt;
    &lt;ol&gt;
      &lt;li&gt;\(\alpha_i^* = 0\): điểm nằm &lt;strong&gt;ngoài lề an toàn&lt;/strong&gt; (\(y_i(\beta^{*T} x_i + \beta_0^*) &amp;gt; 1, \xi_i^* = 0\)) — có xóa điểm này đi siêu phẳng cũng không hề nhúc nhích!&lt;/li&gt;
      &lt;li&gt;\(0 &amp;lt; \alpha_i^* &amp;lt; C\): cả \(\alpha_i^* &amp;gt; 0\) lẫn \(\mu_i^* = C - \alpha_i^* &amp;gt; 0\) \(\implies\) \(\xi_i^* = 0\) và \(y_i(\beta^{*T} x_i + \beta_0^*) = 1\) — điểm nằm &lt;strong&gt;chính xác trên biên lề&lt;/strong&gt; (vector hỗ trợ tự do, dùng để tính ngay \(\beta_0^*\)!).&lt;/li&gt;
      &lt;li&gt;\(\alpha_i^* = C\): \(\mu_i^* = 0\) nên \(\xi_i^* \ge 0\) — điểm vi phạm lề hoặc bị phân loại sai (vector hỗ trợ bị chặn).&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mở rộng phi tuyến bằng hàm nhân (Kernel SVM):&lt;/strong&gt; Vì \(\beta^* = \sum \alpha_i^* y_i x_i\), hàm quyết định chỉ dùng tích vô hướng \(\sum \alpha_i^* y_i K(x_i, x) + \beta_0^*\) trên đúng tập các vector hỗ trợ!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tay-3-chế-độ-kkt-trên-3-điểm-dữ-liệu-1d&quot;&gt;Giải thích: Kiểm chứng tay 3 chế độ KKT trên 3 điểm dữ liệu 1D&lt;/h3&gt;

&lt;p&gt;Xét Soft-Margin SVM 1D với tham số phạt \(C = 1\) trên 3 điểm dữ liệu:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Điểm 1: \((x_1, y_1) = (-3, -1)\) (rất xa về bên âm),&lt;/li&gt;
  &lt;li&gt;Điểm 2: \((x_2, y_2) = (-1, -1)\) (sát biên âm),&lt;/li&gt;
  &lt;li&gt;Điểm 3: \((x_3, y_3) = (+1, +1)\) (sát biên dương).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thử siêu phẳng \(\beta^* = 1, \beta_0^* = 0\) (đường quyết định \(x = 0\), hai biên lề tại \(x = \pm 1\)) và nhân tử \(\alpha^* = (0,\; 0.5,\; 0.5)\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra phân loại và biến bù \(\xi_i^*\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Điểm 1: \(y_1(\beta^* x_1 + \beta_0^*) = (-1)(-3) = 3 &amp;gt; 1 \implies \xi_1^* = 0\) (nằm an toàn ngoài lề).&lt;/li&gt;
      &lt;li&gt;Điểm 2: \(y_2(\beta^* x_2 + \beta_0^*) = (-1)(-1) = 1 \implies \xi_2^* = 0\) (nằm đúng biên lề!).&lt;/li&gt;
      &lt;li&gt;Điểm 3: \(y_3(\beta^* x_3 + \beta_0^*) = (+1)(+1) = 1 \implies \xi_3^* = 0\) (nằm đúng biên lề!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện dừng KKT:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\sum \alpha_i^* y_i x_i = 0(-1)(-3) + 0.5(-1)(-1) + 0.5(1)(1) = 0 + 0.5 + 0.5 = 1 = \beta^*\) (khớp!).&lt;/li&gt;
      &lt;li&gt;\(\sum \alpha_i^* y_i = 0 + 0.5(-1) + 0.5(1) = 0\) (khớp!).&lt;/li&gt;
      &lt;li&gt;\(\mu_i^* = C - \alpha_i^* = (1.0,\; 0.5,\; 0.5) \ge 0\) (khớp!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện bù KKT:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Điểm 1 lỏng (\(3 &amp;gt; 1\)) nên \(\alpha_1^* = 0\) (không phải vector hỗ trợ — dù dời \(x_1\) sang \(-100\) siêu phẳng vẫn y nguyên!).&lt;/li&gt;
      &lt;li&gt;Điểm 2 và 3 có \(0 &amp;lt; \alpha_2^* = \alpha_3^* = 0.5 &amp;lt; C = 1\) nên bắt buộc nằm khít trên biên \(y_i(\beta^* x_i + \beta_0^*) = 1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;h2 id=&quot;1-giới-thiệu&quot;&gt;1. Giới thiệu&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Máy vector hỗ trợ (Support Vector Machine — SVM)&lt;/strong&gt; là một thuật toán học máy kinh điển cho bài toán phân loại, được Vladimir Vapnik và cộng sự phát triển vào thập niên 1990. SVM dựa trên nền tảng tối ưu hóa lồi chặt chẽ và hoạt động hiệu quả trên dữ liệu nhiều chiều.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý tưởng cốt lõi:&lt;/strong&gt; Khi cần vẽ một đường thẳng phân chia hai nhóm điểm trên mặt phẳng, có vô số đường phân cách khả dĩ. SVM chọn &lt;strong&gt;đường phân cách có khoảng cách lớn nhất&lt;/strong&gt; đến các điểm gần nhất của cả hai nhóm. Khoảng cách này được gọi là &lt;strong&gt;lề (margin)&lt;/strong&gt;. Lề càng lớn, mô hình thường có khả năng tổng quát hóa tốt hơn trên dữ liệu mới.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lộ trình bài học:&lt;/strong&gt; Chúng ta sẽ cùng nhau đi từ trực giác hình học đến công thức toán học một cách tự nhiên:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bắt đầu với &lt;strong&gt;trực giác hình học&lt;/strong&gt;: Tại sao margin lớn lại quan trọng?&lt;/li&gt;
  &lt;li&gt;Chuyển sang &lt;strong&gt;công thức toán học&lt;/strong&gt;: Biểu diễn bài toán dưới dạng tối ưu lồi (Quadratic Programming)&lt;/li&gt;
  &lt;li&gt;Khám phá &lt;strong&gt;support vectors&lt;/strong&gt;: Những điểm dữ liệu “quyết định” siêu phẳng phân cách&lt;/li&gt;
  &lt;li&gt;Mở rộng sang &lt;strong&gt;Soft-Margin SVM&lt;/strong&gt;: Xử lý dữ liệu thực tế có nhiễu và không tách được hoàn toàn&lt;/li&gt;
  &lt;li&gt;Nghiên cứu &lt;strong&gt;bài toán đối ngẫu&lt;/strong&gt;: Cơ sở để áp dụng kỹ thuật hạt nhân (kernel trick) cho dữ liệu phi tuyến&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;11-kiến-thức-nền-tảng-khoảng-cách-từ-điểm-tới-siêu-phẳng&quot;&gt;1.1. Kiến thức nền tảng: Khoảng cách từ điểm tới siêu phẳng&lt;/h3&gt;

&lt;p&gt;Trước khi bắt đầu, hãy ôn lại một công thức quan trọng từ hình học giải tích:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Không gian 2 chiều:&lt;/strong&gt;&lt;br /&gt;
Khoảng cách từ điểm \((x_0, y_0)\) tới đường thẳng \(w_1x + w_2y + b = 0\) là:
\(\frac{\lvert w_1x_0 + w_2y_0 + b\rvert}{\sqrt{w_1^2 + w_2^2}}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Không gian 3 chiều:&lt;/strong&gt;&lt;br /&gt;
Khoảng cách từ điểm \((x_0, y_0, z_0)\) tới mặt phẳng \(w_1x + w_2y + w_3z + b = 0\) là:
\(\frac{\lvert w_1x_0 + w_2y_0 + w_3z_0 + b\rvert}{\sqrt{w_1^2 + w_2^2 + w_3^2}}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tổng quát - Không gian nhiều chiều:&lt;/strong&gt;&lt;br /&gt;
Khoảng cách từ điểm (vector) \(\mathbf{x}_0\) tới &lt;strong&gt;siêu mặt phẳng&lt;/strong&gt; \(\mathbf{w}^T\mathbf{x} + b = 0\) là:
\(\frac{\lvert\mathbf{w}^T\mathbf{x}_0 + b\rvert}{\|\mathbf{w}\|_2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý quan trọng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu bỏ dấu giá trị tuyệt đối, ta xác định được điểm nằm về phía nào của siêu phẳng&lt;/li&gt;
  &lt;li&gt;Biểu thức dương: điểm ở &lt;strong&gt;phía dương&lt;/strong&gt; của siêu phẳng&lt;/li&gt;
  &lt;li&gt;Biểu thức âm: điểm ở &lt;strong&gt;phía âm&lt;/strong&gt; của siêu phẳng&lt;/li&gt;
  &lt;li&gt;Biểu thức bằng 0: điểm nằm trên siêu phẳng&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;12-ý-tưởng-cốt-lõi---ba-khái-niệm-then-chốt&quot;&gt;1.2. Ý tưởng cốt lõi - Ba khái niệm then chốt&lt;/h3&gt;

&lt;p&gt;Trước khi đi vào chi tiết, hãy nắm vững ba khái niệm nền tảng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Siêu phẳng phân cách&lt;/strong&gt;: Trong không gian nhiều chiều, siêu phẳng \(\beta^T x + \beta_0 = 0\) đóng vai trò như một “bức tường” chia không gian thành hai vùng, mỗi vùng chứa một lớp dữ liệu.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Lề (Margin)&lt;/strong&gt;: Khoảng cách giữa hai siêu phẳng biên đi qua các điểm gần nhất của mỗi lớp; sau khi chuẩn hóa, độ rộng toàn phần của lề là \(\frac{2}{\|\beta\|}\) (khoảng cách từ siêu phẳng phân cách đến mỗi biên là \(\frac{1}{\|\beta\|}\)).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Mục tiêu tối ưu&lt;/strong&gt;: Cực đại hóa lề \(\Leftrightarrow\) cực tiểu hóa \(\|\beta\|\), vì độ rộng lề tỉ lệ nghịch với chuẩn \(\|\beta\|\).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;13-minh-họa-trực-quan-khoảng-cách-và-phân-loại&quot;&gt;1.3. Minh họa trực quan: Khoảng cách và phân loại&lt;/h3&gt;

&lt;div id=&quot;distance-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;canvas id=&quot;distanceCanvas&quot; width=&quot;600&quot; height=&quot;400&quot; style=&quot;border: 1px solid #ccc; display: block; margin: 0 auto;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin-top: 15px;&quot;&gt;
        &lt;p style=&quot;font-size: 14px; color: #666;&quot;&gt;
            &lt;strong&gt;Hướng dẫn:&lt;/strong&gt; Di chuyển chuột trên canvas để xem khoảng cách từ điểm đến đường thẳng
        &lt;/p&gt;
        &lt;p id=&quot;distanceInfo&quot; style=&quot;font-size: 16px; font-weight: bold; color: #333;&quot;&gt;
            Khoảng cách: 0
        &lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    const canvas = document.getElementById(&apos;distanceCanvas&apos;);
    if (!canvas) return;
    
    const ctx = canvas.getContext(&apos;2d&apos;);
    const width = canvas.width;
    const height = canvas.height;
    
    // Tham số đường thẳng: w1*x + w2*y + b = 0
    // Chọn đường thẳng đi qua giữa canvas với góc nghiêng
    const w1 = 1;
    const w2 = 0.5;
    const b = -200;
    const norm = Math.sqrt(w1*w1 + w2*w2);
    
    let mouseX = width / 2;
    let mouseY = height / 2;
    
    function draw() {
        // Clear canvas
        ctx.clearRect(0, 0, width, height);
        
        // Vẽ lưới nền
        ctx.strokeStyle = &apos;#f0f0f0&apos;;
        ctx.lineWidth = 1;
        for (let x = 0; x &lt; width; x += 50) {
            ctx.beginPath();
            ctx.moveTo(x, 0);
            ctx.lineTo(x, height);
            ctx.stroke();
        }
        for (let y = 0; y &lt; height; y += 50) {
            ctx.beginPath();
            ctx.moveTo(0, y);
            ctx.lineTo(width, y);
            ctx.stroke();
        }
        
        // Vẽ đường thẳng w1*x + w2*y + b = 0
        ctx.strokeStyle = &apos;#2c3e50&apos;;
        ctx.lineWidth = 3;
        ctx.beginPath();
        
        // Tính y cho x = 0 và x = width
        const y0 = -(w1 * 0 + b) / w2;
        const y1 = -(w1 * width + b) / w2;
        
        ctx.moveTo(0, y0);
        ctx.lineTo(width, y1);
        ctx.stroke();
        
        // Vẽ label cho đường thẳng
        ctx.fillStyle = &apos;#2c3e50&apos;;
        ctx.font = &apos;14px Arial&apos;;
        ctx.fillText(&apos;w₁x + w₂y + b = 0&apos;, width - 150, y1 + 20);
        
        // Tính khoảng cách từ điểm chuột đến đường thẳng
        const distance = Math.abs(w1 * mouseX + w2 * mouseY + b) / norm;
        const signedDist = (w1 * mouseX + w2 * mouseY + b) / norm;
        
        // Tìm điểm chiếu vuông góc
        const t = -(w1 * mouseX + w2 * mouseY + b) / (w1*w1 + w2*w2);
        const projX = mouseX + t * w1;
        const projY = mouseY + t * w2;
        
        // Vẽ đường vuông góc
        ctx.strokeStyle = &apos;#e74c3c&apos;;
        ctx.lineWidth = 2;
        ctx.setLineDash([5, 5]);
        ctx.beginPath();
        ctx.moveTo(mouseX, mouseY);
        ctx.lineTo(projX, projY);
        ctx.stroke();
        ctx.setLineDash([]);
        
        // Vẽ điểm chuột
        ctx.fillStyle = signedDist &gt; 0 ? &apos;#3498db&apos; : &apos;#e74c3c&apos;;
        ctx.beginPath();
        ctx.arc(mouseX, mouseY, 8, 0, 2 * Math.PI);
        ctx.fill();
        
        // Vẽ điểm chiếu
        ctx.fillStyle = &apos;#95a5a6&apos;;
        ctx.beginPath();
        ctx.arc(projX, projY, 5, 0, 2 * Math.PI);
        ctx.fill();
        
        // Hiển thị khoảng cách
        const distInfo = document.getElementById(&apos;distanceInfo&apos;);
        if (distInfo) {
            const side = signedDist &gt; 0 ? &apos;(Phía dương)&apos; : &apos;(Phía âm)&apos;;
            distInfo.innerHTML = `Khoảng cách: &lt;span style=&quot;color: ${signedDist &gt; 0 ? &apos;#3498db&apos; : &apos;#e74c3c&apos;}&quot;&gt;${distance.toFixed(2)}&lt;/span&gt; ${side}`;
        }
        
        // Vẽ text thông tin
        ctx.fillStyle = &apos;#34495e&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(`Điểm: (${mouseX.toFixed(0)}, ${mouseY.toFixed(0)})`, mouseX + 15, mouseY - 15);
    }
    
    // Event listeners
    canvas.addEventListener(&apos;mousemove&apos;, function(e) {
        const rect = canvas.getBoundingClientRect();
        mouseX = e.clientX - rect.left;
        mouseY = e.clientY - rect.top;
        draw();
    });
    
    // Initial draw
    draw();
})();
&lt;/script&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;2-bài-toán-phân-chia-hai-lớp-dữ-liệu&quot;&gt;2. Bài toán phân chia hai lớp dữ liệu&lt;/h2&gt;

&lt;p&gt;Xét tình huống cơ bản: ta có hai lớp điểm dữ liệu trong không gian nhiều chiều và hai lớp này &lt;strong&gt;tách được tuyến tính&lt;/strong&gt; (linearly separable). Điều này có nghĩa là tồn tại ít nhất một siêu phẳng có thể phân chia hoàn toàn hai nhóm - tất cả điểm của nhóm A nằm về một phía, tất cả điểm của nhóm B nằm về phía đối diện.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nhiệm vụ của chúng ta:&lt;/strong&gt; Tìm một siêu phẳng phân chia sao cho không có điểm nào “đi lạc” - mỗi điểm phải nằm đúng phía của siêu phẳng tương ứng với nhãn của nó.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vấn đề đặt ra:&lt;/strong&gt; Khi dữ liệu tách được tuyến tính, có &lt;strong&gt;vô số cách chọn&lt;/strong&gt; siêu phẳng phân chia. Hình minh họa dưới đây cho thấy ba đường thẳng khác nhau đều phân loại đúng cả hai lớp:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;https://machinelearningcoban.com/assets/19_svm/svm1.png&quot; alt=&quot;&quot; width=&quot;60%&quot; height=&quot;60%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$ \text{[Hình 2] Các mặt phân cách khả dĩ cho hai classes linearly separable}$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi đặt ra:&lt;/strong&gt; Trong vô số siêu phẳng phân loại đúng tập huấn luyện, nên chọn siêu phẳng nào?&lt;/p&gt;

&lt;p&gt;Hãy quan sát kỹ hình minh họa phía trên. Bạn có nhận thấy gì không? Hai đường thẳng đầu tiên “lệch” khá nhiều về phía các điểm hình tròn đỏ - chúng dường như “sợ” các điểm hình vuông xanh và né tránh chúng. Trong khi đó, đường thẳng thứ ba nằm gần như chính giữa hai nhóm, tạo ra một “vùng an toàn” xung quanh nó.&lt;/p&gt;

&lt;p&gt;Về mặt trực giác, đường phân chia nằm chính giữa hai lớp sẽ ổn định hơn trước nhiễu và dữ liệu mới. Tiếp theo, ta sẽ lượng hóa trực giác này thành bài toán tối ưu.&lt;/p&gt;

&lt;h3 id=&quot;21-tiêu-chuẩn-lề-cực-đại-maximum-margin&quot;&gt;2.1. Tiêu chuẩn lề cực đại (Maximum Margin)&lt;/h3&gt;

&lt;p&gt;SVM định lượng độ an toàn của một siêu phẳng phân chia thông qua khái niệm &lt;strong&gt;lề (margin)&lt;/strong&gt;.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;https://machinelearningcoban.com/assets/19_svm/svm2.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$ \text{[Hình 3] So sánh các mặt phân cách với margin khác nhau}$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;Margin là gì?&lt;/strong&gt; Đơn giản nhất, margin là khoảng cách từ siêu phẳng phân cách đến &lt;strong&gt;điểm gần nhất&lt;/strong&gt; của mỗi lớp dữ liệu. Hãy nghĩ về nó như “vùng đệm an toàn” xung quanh đường phân chia.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Siêu phẳng tối ưu cần thỏa mãn hai yêu cầu:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Đối xứng:&lt;/strong&gt; Khoảng cách từ siêu phẳng đến điểm gần nhất của lớp A bằng khoảng cách đến điểm gần nhất của lớp B.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Lề lớn nhất:&lt;/strong&gt; Trong tất cả các siêu phẳng đối xứng, chọn siêu phẳng có lề lớn nhất.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tại sao margin lớn lại quan trọng?&lt;/strong&gt; Ba lý do thực tiễn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Khả năng tổng quát hóa&lt;/strong&gt;: Margin rộng giống như có “vùng dung sai” lớn. Khi có dữ liệu mới hơi lệch so với dữ liệu huấn luyện, mô hình vẫn phân loại đúng.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Độ tin cậy&lt;/strong&gt;: Điểm dữ liệu càng xa siêu phẳng, quyết định phân loại càng “tự tin”. Margin lớn nghĩa là hầu hết điểm đều được phân loại với độ tin cậy cao.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ổn định trước nhiễu&lt;/strong&gt;: Khi dữ liệu mới có sai số đo nhỏ, lề rộng giúp hạn chế thay đổi nhãn dự đoán.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kết luận quan trọng&lt;/strong&gt;: Bài toán SVM chính là bài toán tìm mặt phân cách có &lt;strong&gt;margin lớn nhất&lt;/strong&gt;. Vì vậy, SVM còn được gọi là &lt;strong&gt;Maximum Margin Classifier&lt;/strong&gt; - bộ phân loại margin cực đại.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;3-xây-dựng-bài-toán-tối-ưu-cho-svm&quot;&gt;3. Xây dựng bài toán tối ưu cho SVM&lt;/h2&gt;

&lt;p&gt;Từ tiêu chuẩn lề cực đại, ta sẽ xây dựng mô hình toán học tương ứng và đưa bài toán về dạng quy hoạch bậc hai (Quadratic Programming) chuẩn.&lt;/p&gt;

&lt;h3 id=&quot;31-thiết-lập-ký-hiệu&quot;&gt;3.1. Thiết lập ký hiệu&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Giả sử&lt;/strong&gt;: Các cặp dữ liệu của training set là \((x_1, y_1), (x_2, y_2), \ldots, (x_N, y_N)\) với:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Vector \(x_i \in \mathbb{R}^d\): đầu vào của một điểm dữ liệu&lt;/li&gt;
  &lt;li&gt;\(y_i \in \{-1, +1\}\): nhãn của điểm dữ liệu đó&lt;/li&gt;
  &lt;li&gt;\(d\): số chiều của dữ liệu&lt;/li&gt;
  &lt;li&gt;\(N\): số điểm dữ liệu&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý&lt;/strong&gt;: Để dễ hình dung, chúng ta xét trường hợp không gian hai chiều. Các phép toán hoàn toàn có thể được tổng quát lên không gian nhiều chiều.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;https://machinelearningcoban.com/assets/19_svm/svm6.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$ \text{[Hình 4] Phân tích bài toán SVM}$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;Giả sử&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Các điểm vuông xanh thuộc class +1&lt;/li&gt;
  &lt;li&gt;Các điểm tròn đỏ thuộc class -1&lt;/li&gt;
  &lt;li&gt;Mặt \(w^T x + b = w_1 x_1 + w_2 x_2 + b = 0\) là mặt phân chia&lt;/li&gt;
  &lt;li&gt;Class +1 nằm về &lt;strong&gt;phía dương&lt;/strong&gt;, class -1 nằm về &lt;strong&gt;phía âm&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;32-công-thức-khoảng-cách-có-dấu&quot;&gt;3.2. Công thức khoảng cách có dấu&lt;/h3&gt;

&lt;p&gt;Với cặp dữ liệu \((x_n, y_n)\) bất kỳ, khoảng cách từ điểm \(x_n\) tới siêu phẳng phân chia được tính bởi:&lt;/p&gt;

\[\frac{y_n(w^T x_n + b)}{\|w\|_2}\]

&lt;p&gt;&lt;strong&gt;Vai trò của hệ số \(y_n\) ở tử số:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(x_n\) thuộc lớp +1, nó nằm ở phía dương của siêu phẳng → \(w^T x_n + b &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;Nếu \(x_n\) thuộc lớp -1, nó nằm ở phía âm của siêu phẳng → \(w^T x_n + b &amp;lt; 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vì theo giả sử mô hình phân loại đúng, \(y_n\) luôn &lt;strong&gt;cùng dấu&lt;/strong&gt; với \((w^T x_n + b)\). Do đó:
\(y_n(w^T x_n + b) &amp;gt; 0 \quad \text{(luôn dương!)}\)&lt;/p&gt;

&lt;p&gt;Nhân với \(y_n\) giúp loại bỏ dấu giá trị tuyệt đối trong công thức khoảng cách, thuận tiện cho bước biến đổi đại số tiếp theo.&lt;/p&gt;

&lt;h3 id=&quot;33-định-nghĩa-margin&quot;&gt;3.3. Định nghĩa Margin&lt;/h3&gt;

&lt;p&gt;Với mặt phân chia như trên, &lt;strong&gt;margin&lt;/strong&gt; được tính là khoảng cách gần nhất từ một điểm tới mặt đó (bất kể điểm nào trong hai classes):&lt;/p&gt;

\[\text{margin} = \min_n \frac{y_n(w^T x_n + b)}{\|w\|_2}\]

&lt;h3 id=&quot;34-bài-toán-tối-ưu-ban-đầu&quot;&gt;3.4. Bài toán tối ưu ban đầu&lt;/h3&gt;

&lt;p&gt;Bài toán tối ưu trong SVM chính là bài toán tìm \(w\) và \(b\) sao cho margin này đạt giá trị &lt;strong&gt;lớn nhất&lt;/strong&gt;:&lt;/p&gt;

\[\begin{align}
(w, b) &amp;amp;= \arg\max_{w,b} \left\{ \min_n \frac{y_n(w^T x_n + b)}{\|w\|_2} \right\} \\
&amp;amp;= \arg\max_{w,b} \left\{ \frac{1}{\|w\|_2} \min_n y_n(w^T x_n + b) \right\} \qquad (1)
\end{align}\]

&lt;p&gt;&lt;strong&gt;Vấn đề&lt;/strong&gt;: Việc giải trực tiếp bài toán này sẽ rất phức tạp.&lt;/p&gt;

&lt;h3 id=&quot;35-chuẩn-hóa-tham-số-siêu-phẳng&quot;&gt;3.5. Chuẩn hóa tham số siêu phẳng&lt;/h3&gt;

&lt;p&gt;Trước khi tiếp tục, chúng ta cần một &lt;strong&gt;quan sát quan trọng&lt;/strong&gt; giúp đơn giản hóa bài toán đáng kể.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính bất biến theo tỷ lệ:&lt;/strong&gt; Xét siêu phẳng \(w^T x + b = 0\). Nếu nhân cả \(w\) và \(b\) với một hằng số dương \(k &amp;gt; 0\), ta thu được phương trình \((kw)^T x + kb = 0\) có các tính chất sau:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Mặt phân chia &lt;strong&gt;vẫn là cùng một mặt&lt;/strong&gt; (vì phương trình vẫn cho cùng tập hợp các điểm thỏa mãn)&lt;/li&gt;
  &lt;li&gt;Khoảng cách từ mỗi điểm đến mặt phân chia &lt;strong&gt;không đổi&lt;/strong&gt; (phép chia cho \(\|kw\| = k\|w\|\) triệt tiêu hệ số \(k\))&lt;/li&gt;
  &lt;li&gt;Do đó, margin cũng &lt;strong&gt;không đổi&lt;/strong&gt;!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phép chuẩn hóa:&lt;/strong&gt; Vì tỷ lệ của \((w, b)\) không làm thay đổi siêu phẳng, ta có thể cố định tỷ lệ sao cho tại các điểm gần siêu phẳng nhất (các vector hỗ trợ):&lt;/p&gt;

\[y_n(w^T x_n + b) = 1\]

&lt;p&gt;Với quy ước chuẩn hóa này, khoảng cách từ siêu phẳng đến điểm gần nhất rút gọn thành \(\text{margin} = \frac{1}{\|w\|}\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;https://machinelearningcoban.com/assets/19_svm/svm3.png&quot; alt=&quot;&quot; width=&quot;60%&quot; height=&quot;60%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$ \text{[Hình 5] Các điểm gần mặt phân cách nhất được khoanh tròn}$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Hệ quả&lt;/strong&gt;: Với mọi \(n\), ta có:&lt;/p&gt;

  &lt;p&gt;\(y_n(w^T x_n + b) \geq 1\)&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;36-bài-toán-tối-ưu-có-ràng-buộc&quot;&gt;3.6. Bài toán tối ưu có ràng buộc&lt;/h3&gt;

&lt;p&gt;Vậy bài toán tối ưu \((1)\) có thể đưa về:&lt;/p&gt;

\[\begin{align}
(w, b) &amp;amp;= \arg\max_{w,b} \frac{1}{\|w\|_2} \\
\text{subject to: } &amp;amp; y_n(w^T x_n + b) \geq 1, \quad \forall n = 1,2,\ldots,N \qquad (2)
\end{align}\]

&lt;h3 id=&quot;37-bài-toán-tối-ưu-chuẩn&quot;&gt;3.7. Bài toán tối ưu chuẩn&lt;/h3&gt;

&lt;p&gt;Bằng biến đổi đơn giản, ta có thể đưa bài toán về dạng:&lt;/p&gt;

\[\begin{align}
(w, b) &amp;amp;= \arg\min_{w,b} \frac{1}{2}\|w\|_2^2 \\
\text{subject to: } &amp;amp; 1 - y_n(w^T x_n + b) \leq 0, \quad \forall n = 1,2,\ldots,N \qquad (3)
\end{align}\]

&lt;p&gt;&lt;strong&gt;Giải thích các biến đổi&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Lấy &lt;strong&gt;nghịch đảo&lt;/strong&gt; hàm mục tiêu (max → min)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bình phương&lt;/strong&gt; để được hàm khả vi&lt;/li&gt;
  &lt;li&gt;Nhân thêm hệ số \(\frac{1}{2}\) để rút gọn hệ số khi lấy đạo hàm&lt;/li&gt;
  &lt;li&gt;Đổi dấu ràng buộc&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;38-tính-chất-của-bài-toán&quot;&gt;3.8. Tính chất của bài toán&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Quan sát quan trọng&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hàm mục tiêu&lt;/strong&gt;: \(\frac{1}{2}\|w\|_2^2\) là một hàm &lt;strong&gt;lồi&lt;/strong&gt; (norm bình phương)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hàm ràng buộc&lt;/strong&gt;: \(1 - y_n(w^T x_n + b)\) là hàm &lt;strong&gt;tuyến tính&lt;/strong&gt; theo \(w\) và \(b\), nên là hàm &lt;strong&gt;lồi&lt;/strong&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Kết luận&lt;/strong&gt;: Bài toán \((3)\) là một &lt;strong&gt;bài toán lồi&lt;/strong&gt; (convex optimization problem)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hơn nữa&lt;/strong&gt;: Đây là một &lt;strong&gt;Quadratic Programming (QP)&lt;/strong&gt; problem&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Lồi chặt theo \(w\):&lt;/strong&gt; Hàm mục tiêu \(\frac{1}{2}\|w\|_2^2 = \frac{1}{2}w^T I w\) lồi chặt theo \(w\) vì ma trận đơn vị \(I\) xác định dương.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Tính duy nhất của \(w^*\):&lt;/strong&gt; Nhờ tính lồi chặt theo \(w\), vector pháp tuyến tối ưu \(w^*\) là duy nhất (và khi hai lớp đều có điểm, \(b^*\) cũng xác định duy nhất từ các điểm trên biên lề).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;39-xác-định-class-cho-điểm-mới&quot;&gt;3.9. Xác định class cho điểm mới&lt;/h3&gt;

&lt;p&gt;Sau khi tìm được mặt phân cách \(w^T x + b = 0\), class của bất kỳ một điểm nào sẽ được xác định đơn giản bằng:&lt;/p&gt;

\[\text{class}(x) = \text{sgn}(w^T x + b)\]

&lt;p&gt;Trong đó hàm \(\text{sgn}\) là hàm xác định dấu:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nhận giá trị &lt;strong&gt;+1&lt;/strong&gt; nếu đối số là không âm&lt;/li&gt;
  &lt;li&gt;Nhận giá trị &lt;strong&gt;-1&lt;/strong&gt; nếu ngược lại&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;4-hard-margin-svm-dữ-liệu-tách-được&quot;&gt;4. Hard-Margin SVM (Dữ liệu tách được)&lt;/h2&gt;

&lt;p&gt;Khi dữ liệu &lt;strong&gt;tách được tuyến tính&lt;/strong&gt;, bài toán SVM có dạng:&lt;/p&gt;

\[\begin{align}
&amp;amp;\min_{\beta, \beta_0} &amp;amp;&amp;amp;{\frac{1}{2} \|\beta\|_2^2} \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp; y_i (\beta^T x_i + \beta_0) \geq 1, \quad i = 1, \ldots, n
\end{align}\]

&lt;p&gt;&lt;strong&gt;Giải thích:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu: Minimize \(\|\beta\|\) để maximize margin&lt;/li&gt;
  &lt;li&gt;Ràng buộc: Mọi điểm phải cách siêu phẳng ít nhất 1 đơn vị (theo metric)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;41-minh-họa-tương-tác-hard-margin-svm&quot;&gt;4.1. Minh họa tương tác: Hard-Margin SVM&lt;/h3&gt;

&lt;div id=&quot;hardmargin-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;canvas id=&quot;hardMarginCanvas&quot; width=&quot;700&quot; height=&quot;500&quot; style=&quot;border: 1px solid #ccc; display: block; margin: 0 auto;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin-top: 15px;&quot;&gt;
        &lt;button id=&quot;resetData&quot; style=&quot;padding: 10px 20px; font-size: 14px; cursor: pointer; background: #3498db; color: white; border: none; border-radius: 5px; margin: 5px;&quot;&gt;
            🔄 Tạo dữ liệu mới
        &lt;/button&gt;
        &lt;button id=&quot;addPositive&quot; style=&quot;padding: 10px 20px; font-size: 14px; cursor: pointer; background: #e74c3c; color: white; border: none; border-radius: 5px; margin: 5px;&quot;&gt;
            ➕ Thêm điểm dương (+1)
        &lt;/button&gt;
        &lt;button id=&quot;addNegative&quot; style=&quot;padding: 10px 20px; font-size: 14px; cursor: pointer; background: #2ecc71; color: white; border: none; border-radius: 5px; margin: 5px;&quot;&gt;
            ➕ Thêm điểm âm (-1)
        &lt;/button&gt;
        &lt;p style=&quot;font-size: 14px; color: #666; margin-top: 10px;&quot;&gt;
            &lt;strong&gt;Hướng dẫn:&lt;/strong&gt; Click vào canvas để thêm điểm mới. Đường đen đậm là siêu phẳng phân cách, đường đứt nét là margin boundaries.
        &lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    const canvas = document.getElementById(&apos;hardMarginCanvas&apos;);
    if (!canvas) return;
    
    const ctx = canvas.getContext(&apos;2d&apos;);
    const width = canvas.width;
    const height = canvas.height;
    
    let addMode = 0; // 0: none, 1: positive, -1: negative
    
    // Dữ liệu điểm
    let points = [
        // Class +1 (đỏ)
        {x: 450, y: 150, label: 1},
        {x: 500, y: 100, label: 1},
        {x: 550, y: 200, label: 1},
        {x: 480, y: 250, label: 1},
        {x: 520, y: 180, label: 1},
        // Class -1 (xanh)
        {x: 150, y: 250, label: -1},
        {x: 200, y: 300, label: -1},
        {x: 250, y: 350, label: -1},
        {x: 180, y: 400, label: -1},
        {x: 220, y: 280, label: -1}
    ];
    
    function simpleSVM() {
        // Thuật toán đơn giản để tìm hyperplane
        // Tìm trung điểm giữa 2 classes
        let posPoints = points.filter(p =&gt; p.label === 1);
        let negPoints = points.filter(p =&gt; p.label === -1);
        
        if (posPoints.length === 0 || negPoints.length === 0) return null;
        
        // Tính centroid mỗi class
        let posCenter = {
            x: posPoints.reduce((sum, p) =&gt; sum + p.x, 0) / posPoints.length,
            y: posPoints.reduce((sum, p) =&gt; sum + p.y, 0) / posPoints.length
        };
        
        let negCenter = {
            x: negPoints.reduce((sum, p) =&gt; sum + p.x, 0) / negPoints.length,
            y: negPoints.reduce((sum, p) =&gt; sum + p.y, 0) / negPoints.length
        };
        
        // Vector kết nối 2 centroids
        let dx = posCenter.x - negCenter.x;
        let dy = posCenter.y - negCenter.y;
        
        // Hyperplane vuông góc với vector này, đi qua trung điểm
        let midX = (posCenter.x + negCenter.x) / 2;
        let midY = (posCenter.y + negCenter.y) / 2;
        
        // w = (dx, dy), bias tính từ điểm mid
        let w = {x: dx, y: dy};
        let b = -(w.x * midX + w.y * midY);
        let norm = Math.sqrt(w.x * w.x + w.y * w.y);
        
        // Normalize
        w.x /= norm;
        w.y /= norm;
        b /= norm;
        
        // Tìm margin: khoảng cách gần nhất từ điểm đến hyperplane
        let minDist = Infinity;
        points.forEach(p =&gt; {
            let dist = Math.abs(w.x * p.x + w.y * p.y + b);
            if (dist &lt; minDist) minDist = dist;
        });
        
        // Tìm support vectors
        let supportVectors = points.filter(p =&gt; {
            let dist = Math.abs(w.x * p.x + w.y * p.y + b);
            return dist &lt; minDist + 5; // tolerance
        });
        
        return {w, b, margin: minDist, supportVectors};
    }
    
    function draw() {
        // Clear canvas
        ctx.clearRect(0, 0, width, height);
        
        // Background
        ctx.fillStyle = &apos;#fafafa&apos;;
        ctx.fillRect(0, 0, width, height);
        
        // Tìm SVM solution
        let svm = simpleSVM();
        
        if (svm) {
            // Vẽ margin boundaries (đường đứt nét)
            ctx.strokeStyle = &apos;#95a5a6&apos;;
            ctx.lineWidth = 2;
            ctx.setLineDash([5, 5]);
            
            // Margin boundary 1
            let b1 = svm.b + svm.margin;
            drawLine(svm.w, b1);
            
            // Margin boundary 2
            let b2 = svm.b - svm.margin;
            drawLine(svm.w, b2);
            
            ctx.setLineDash([]);
            
            // Vẽ hyperplane chính (đường đậm)
            ctx.strokeStyle = &apos;#2c3e50&apos;;
            ctx.lineWidth = 3;
            drawLine(svm.w, svm.b);
            
            // Highlight support vectors
            ctx.strokeStyle = &apos;#f39c12&apos;;
            ctx.lineWidth = 3;
            svm.supportVectors.forEach(sv =&gt; {
                ctx.beginPath();
                ctx.arc(sv.x, sv.y, 15, 0, 2 * Math.PI);
                ctx.stroke();
            });
            
            // Hiển thị thông tin
            ctx.fillStyle = &apos;#2c3e50&apos;;
            ctx.font = &apos;bold 16px Arial&apos;;
            ctx.fillText(`Margin: ${(svm.margin * 2).toFixed(1)}`, 10, 30);
            ctx.fillText(`Support Vectors: ${svm.supportVectors.length}`, 10, 55);
        }
        
        // Vẽ các điểm dữ liệu
        points.forEach(p =&gt; {
            ctx.fillStyle = p.label === 1 ? &apos;#e74c3c&apos; : &apos;#2ecc71&apos;;
            ctx.beginPath();
            ctx.arc(p.x, p.y, 8, 0, 2 * Math.PI);
            ctx.fill();
            
            // Viền
            ctx.strokeStyle = &apos;#34495e&apos;;
            ctx.lineWidth = 2;
            ctx.stroke();
        });
        
        // Legend
        ctx.fillStyle = &apos;#e74c3c&apos;;
        ctx.beginPath();
        ctx.arc(630, 30, 8, 0, 2 * Math.PI);
        ctx.fill();
        ctx.fillStyle = &apos;#34495e&apos;;
        ctx.font = &apos;14px Arial&apos;;
        ctx.fillText(&apos;Class +1&apos;, 645, 35);
        
        ctx.fillStyle = &apos;#2ecc71&apos;;
        ctx.beginPath();
        ctx.arc(630, 55, 8, 0, 2 * Math.PI);
        ctx.fill();
        ctx.fillStyle = &apos;#34495e&apos;;
        ctx.fillText(&apos;Class -1&apos;, 645, 60);
        
        // Support vector legend
        ctx.strokeStyle = &apos;#f39c12&apos;;
        ctx.lineWidth = 3;
        ctx.beginPath();
        ctx.arc(630, 80, 8, 0, 2 * Math.PI);
        ctx.stroke();
        ctx.fillStyle = &apos;#34495e&apos;;
        ctx.fillText(&apos;Support Vector&apos;, 645, 85);
    }
    
    function drawLine(w, b) {
        // Vẽ đường thẳng w.x * x + w.y * y + b = 0
        ctx.beginPath();
        
        if (Math.abs(w.y) &gt; 0.01) {
            let y0 = -(w.x * 0 + b) / w.y;
            let y1 = -(w.x * width + b) / w.y;
            ctx.moveTo(0, y0);
            ctx.lineTo(width, y1);
        } else {
            let x = -b / w.x;
            ctx.moveTo(x, 0);
            ctx.lineTo(x, height);
        }
        
        ctx.stroke();
    }
    
    function generateRandomData() {
        points = [];
        // Class +1
        for (let i = 0; i &lt; 5; i++) {
            points.push({
                x: 450 + Math.random() * 150,
                y: 100 + Math.random() * 200,
                label: 1
            });
        }
        // Class -1
        for (let i = 0; i &lt; 5; i++) {
            points.push({
                x: 150 + Math.random() * 150,
                y: 250 + Math.random() * 200,
                label: -1
            });
        }
        draw();
    }
    
    // Event listeners
    canvas.addEventListener(&apos;click&apos;, function(e) {
        if (addMode !== 0) {
            const rect = canvas.getBoundingClientRect();
            const x = e.clientX - rect.left;
            const y = e.clientY - rect.top;
            points.push({x, y, label: addMode});
            draw();
            addMode = 0;
            document.getElementById(&apos;addPositive&apos;).style.opacity = &apos;1&apos;;
            document.getElementById(&apos;addNegative&apos;).style.opacity = &apos;1&apos;;
        }
    });
    
    document.getElementById(&apos;resetData&apos;).addEventListener(&apos;click&apos;, generateRandomData);
    
    document.getElementById(&apos;addPositive&apos;).addEventListener(&apos;click&apos;, function() {
        addMode = 1;
        this.style.opacity = &apos;0.6&apos;;
        document.getElementById(&apos;addNegative&apos;).style.opacity = &apos;1&apos;;
    });
    
    document.getElementById(&apos;addNegative&apos;).addEventListener(&apos;click&apos;, function() {
        addMode = -1;
        this.style.opacity = &apos;0.6&apos;;
        document.getElementById(&apos;addPositive&apos;).style.opacity = &apos;1&apos;;
    });
    
    // Initial draw
    draw();
})();
&lt;/script&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;5-soft-margin-svm-đối-mặt-với-dữ-liệu-thực-tế&quot;&gt;5. Soft-Margin SVM: Đối mặt với dữ liệu thực tế&lt;/h2&gt;

&lt;p&gt;Cho đến nay, chúng ta đã làm việc với một giả thiết lý tưởng: dữ liệu &lt;strong&gt;hoàn toàn tách được tuyến tính&lt;/strong&gt;, không có điểm nào vi phạm margin. Đây là &lt;strong&gt;Hard-Margin SVM&lt;/strong&gt; - một mô hình “cứng nhắc” không cho phép bất kỳ ngoại lệ nào.&lt;/p&gt;

&lt;p&gt;Trong dữ liệu thực tế, giả thiết tách tuyến tính hoàn toàn thường không thỏa mãn.&lt;/p&gt;

&lt;h3 id=&quot;50-khi-lý-thuyết-gặp-thực-tiễn-tại-sao-cần-slack-variables&quot;&gt;5.0. Khi lý thuyết gặp thực tiễn: Tại sao cần Slack Variables?&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu khắt khe của Hard-Margin SVM:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mọi điểm dữ liệu phải thỏa mãn:
\(y_i (\beta^T x_i + \beta_0) \geq 1, \quad \forall i = 1,\ldots,n\)&lt;/p&gt;

&lt;p&gt;Điều này nghĩa là &lt;strong&gt;TẤT CẢ&lt;/strong&gt; các điểm - không ngoại lệ - phải:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Được phân loại &lt;strong&gt;hoàn toàn đúng&lt;/strong&gt; (nằm đúng phía của siêu phẳng)&lt;/li&gt;
  &lt;li&gt;Nằm &lt;strong&gt;ngoài vùng margin&lt;/strong&gt; (cách siêu phẳng ít nhất 1 đơn vị chuẩn hóa)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ba tình huống phổ biến khiến Hard-Margin SVM không phù hợp:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) Dữ liệu không tách được tuyến tính (Linearly Non-separable):&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Class +1:  ○ ○ ○ ● ○     ← Có 1 điểm class -1 lọt vào
                          
Class -1:  ● ● ● ○ ●     ← Có 1 điểm class +1 lọt vào
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;→ &lt;strong&gt;KHÔNG TỒN TẠI&lt;/strong&gt; siêu phẳng nào tách được hoàn toàn!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) Outliers (Điểm nhiễu):&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Class +1:  ○ ○ ○ ○
                      ●  ← Outlier duy nhất
Class -1:  ● ● ● ●
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;→ Outlier có thể &lt;strong&gt;kéo lệch&lt;/strong&gt; siêu phẳng tối ưu, làm giảm margin!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) Overlap tự nhiên:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Trong nhiều bài toán thực tế (y tế, tài chính), hai class có &lt;strong&gt;vùng chồng lấn&lt;/strong&gt; tự nhiên&lt;/li&gt;
  &lt;li&gt;Không có ranh giới rõ ràng 100%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Giải pháp: Biến nới lỏng (Slack Variables) \(\xi_i\)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Thay vì bắt buộc tất cả điểm phải tuân thủ nghiêm ngặt, chúng ta cho phép &lt;strong&gt;nới lỏng có kiểm soát&lt;/strong&gt;:&lt;/p&gt;

\[y_i (\beta^T x_i + \beta_0) \geq 1 - \xi_i, \quad \xi_i \geq 0\]

&lt;p&gt;&lt;strong&gt;Ý nghĩa trực quan:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Mỗi điểm dữ liệu có một &lt;strong&gt;“quyền vi phạm”&lt;/strong&gt; riêng, được đo bằng \(\xi_i\)&lt;/li&gt;
  &lt;li&gt;Nếu điểm \(i\) là “outlier” hoặc gần biên quyết định, nó có thể sử dụng \(\xi_i &amp;gt; 0\) để “xin phép” vi phạm margin&lt;/li&gt;
  &lt;li&gt;Nhưng vi phạm &lt;strong&gt;không miễn phí&lt;/strong&gt;! Điểm đó phải “trả giá” bằng cách đóng góp \(C \cdot \xi_i\) vào hàm mục tiêu&lt;/li&gt;
  &lt;li&gt;Tham số \(C\) quyết định “mức phạt”: \(C\) lớn = phạt nặng = ít vi phạm được chấp nhận&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm của Soft-Margin SVM:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Luôn khả thi&lt;/strong&gt;: Bài toán luôn có nghiệm vì luôn có thể chọn \(\xi_i\) đủ lớn.&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Ổn định trước điểm ngoại lai&lt;/strong&gt;: Một vài điểm nhiễu không làm lệch mạnh siêu phẳng phân cách.&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Linh hoạt&lt;/strong&gt;: Áp dụng được cho cả dữ liệu tách được và không tách được tuyến tính.&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Cân bằng rõ ràng&lt;/strong&gt;: Kiểm soát trực tiếp sự đánh đổi giữa độ rộng lề và tổng mức vi phạm trên tập huấn luyện.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;51-công-thức-toán-học-của-soft-margin-svm&quot;&gt;5.1. Công thức toán học của Soft-Margin SVM&lt;/h3&gt;

&lt;p&gt;Dựa trên ý tưởng slack variable ở trên, ta có bài toán tối ưu hoàn chỉnh:&lt;/p&gt;

\[\begin{align}
&amp;amp;\min_{\beta, \beta_0, \xi} &amp;amp;&amp;amp;{\frac{1}{2} \|\beta\|_2^2 + C\sum_{i=1}^n \xi_i} \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;{\xi_i \geq 0, \quad i = 1, \ldots, n}\\
&amp;amp; &amp;amp;&amp;amp; y_i (\beta^T x_i + \beta_0) \geq 1 - \xi_i, \quad i = 1, \ldots, n
\end{align}\]

&lt;p&gt;trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\beta \in \mathbb{R}^p\): vector trọng số của siêu phẳng&lt;/li&gt;
  &lt;li&gt;\(\beta_0 \in \mathbb{R}\): bias term&lt;/li&gt;
  &lt;li&gt;\(\xi = (\xi_1, \ldots, \xi_n) \in \mathbb{R}^n\): vector slack variables&lt;/li&gt;
  &lt;li&gt;\(y \in \{-1, +1\}^n\): vector nhãn&lt;/li&gt;
  &lt;li&gt;\(X \in \mathbb{R}^{n \times p}\): ma trận dữ liệu&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chi-tiết-các-thành-phần&quot;&gt;Giải thích chi tiết các thành phần&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1) Slack variable \(\xi_i\) - Biến nới lỏng:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Slack variable đo lường &lt;strong&gt;mức độ vi phạm&lt;/strong&gt; của từng điểm dữ liệu. Giá trị của nó cho biết điểm đó nằm ở đâu:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(\xi_i = 0\)&lt;/strong&gt;: Điểm &lt;strong&gt;lý tưởng&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Phân loại đúng&lt;/li&gt;
      &lt;li&gt;Nằm ngoài margin (ở phía đúng, cách siêu phẳng \(\geq 1\) đơn vị)&lt;/li&gt;
      &lt;li&gt;Không vi phạm gì cả&lt;/li&gt;
      &lt;li&gt;Không bị phạt trong hàm mục tiêu&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(0 &amp;lt; \xi_i &amp;lt; 1\)&lt;/strong&gt;: Điểm &lt;strong&gt;vi phạm margin nhẹ&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vẫn phân loại &lt;strong&gt;đúng&lt;/strong&gt; (nằm đúng phía của siêu phẳng)&lt;/li&gt;
      &lt;li&gt;Nhưng nằm &lt;strong&gt;trong vùng margin&lt;/strong&gt; (quá gần siêu phẳng)&lt;/li&gt;
      &lt;li&gt;Vi phạm margin boundary&lt;/li&gt;
      &lt;li&gt;Thường là outliers hoặc điểm gần biên quyết định&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\xi_i = 1\)&lt;/strong&gt;: Điểm &lt;strong&gt;trên siêu phẳng&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nằm chính xác trên đường phân cách \(\beta^T x_i + \beta_0 = 0\)&lt;/li&gt;
      &lt;li&gt;Không thể quyết định phân loại&lt;/li&gt;
      &lt;li&gt;Điểm giới hạn giữa đúng và sai&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\xi_i &amp;gt; 1\)&lt;/strong&gt;: Điểm &lt;strong&gt;bị phân loại sai&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nằm &lt;strong&gt;sai phía&lt;/strong&gt; siêu phẳng&lt;/li&gt;
      &lt;li&gt;Điểm bị phân loại sai&lt;/li&gt;
      &lt;li&gt;Bị phạt nặng trong hàm mục tiêu&lt;/li&gt;
      &lt;li&gt;Giá trị \(\xi_i\) càng lớn, sai càng nghiêm trọng&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2) Tham số \(C &amp;gt; 0\) - Hằng số điều khiển (Regularization parameter):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;\(C\) quyết định &lt;strong&gt;cân bằng&lt;/strong&gt; giữa hai mục tiêu mâu thuẫn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vai trò&lt;/strong&gt;: Trọng số phạt cho vi phạm margin&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa&lt;/strong&gt;: “Giá” phải trả khi vi phạm&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ảnh hưởng của C:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Giá trị C&lt;/th&gt;
      &lt;th&gt;Margin&lt;/th&gt;
      &lt;th&gt;Vi phạm được chấp nhận&lt;/th&gt;
      &lt;th&gt;Khả năng tổng quát&lt;/th&gt;
      &lt;th&gt;Nguy cơ&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;\(C\) rất nhỏ&lt;/strong&gt; (→ 0)&lt;/td&gt;
      &lt;td&gt;Rộng&lt;/td&gt;
      &lt;td&gt;Nhiều&lt;/td&gt;
      &lt;td&gt;Tốt (generalize tốt)&lt;/td&gt;
      &lt;td&gt;Underfitting&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;\(C\) trung bình&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Cân bằng&lt;/td&gt;
      &lt;td&gt;Vừa phải&lt;/td&gt;
      &lt;td&gt;Tốt nhất&lt;/td&gt;
      &lt;td&gt;-&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;\(C\) rất lớn&lt;/strong&gt; (→ ∞)&lt;/td&gt;
      &lt;td&gt;Hẹp&lt;/td&gt;
      &lt;td&gt;Rất ít&lt;/td&gt;
      &lt;td&gt;Kém (fit data)&lt;/td&gt;
      &lt;td&gt;Overfitting&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Giải thích chi tiết:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(C\) nhỏ&lt;/strong&gt; (ví dụ: 0.01):
    &lt;ul&gt;
      &lt;li&gt;Phạt nhẹ cho vi phạm → chấp nhận nhiều \(\xi_i &amp;gt; 0\)&lt;/li&gt;
      &lt;li&gt;Ưu tiên &lt;strong&gt;margin rộng&lt;/strong&gt; hơn là độ chính xác training&lt;/li&gt;
      &lt;li&gt;Mô hình &lt;strong&gt;mềm dẻo&lt;/strong&gt;, robust với outliers&lt;/li&gt;
      &lt;li&gt;Có thể bị underfitting&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(C\) lớn&lt;/strong&gt; (ví dụ: 100):
    &lt;ul&gt;
      &lt;li&gt;Phạt nặng cho vi phạm → cố gắng \(\xi_i \approx 0\)&lt;/li&gt;
      &lt;li&gt;Ưu tiên &lt;strong&gt;độ chính xác training&lt;/strong&gt; hơn là margin rộng&lt;/li&gt;
      &lt;li&gt;Gần với Hard-Margin SVM&lt;/li&gt;
      &lt;li&gt;Có thể bị overfitting, nhạy cảm với outliers&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Công thức toán học:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Khi \(C \to \infty\):
\(\min \frac{1}{2}\|\beta\|^2 + \underbrace{C\sum \xi_i}_{\text{phải } \approx 0} 
\Rightarrow \xi_i \to 0, \, \forall i\)
→ Khi dữ liệu tách được tuyến tính, bài toán tiến về Hard-Margin SVM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) Hàm mục tiêu - Hai thành phần:&lt;/strong&gt;&lt;/p&gt;

\[\underbrace{\frac{1}{2}\|\beta\|_2^2}_{\text{(1) Maximize margin}} + \underbrace{C\sum_{i=1}^n \xi_i}_{\text{(2) Minimize violations}}\]

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;(1) Margin term&lt;/strong&gt;: \(\frac{1}{2}\|\beta\|_2^2\)
    &lt;ul&gt;
      &lt;li&gt;Minimize \(\|\beta\|\) ⟺ Maximize margin width \(\frac{2}{\|\beta\|}\)&lt;/li&gt;
      &lt;li&gt;Muốn margin &lt;strong&gt;càng rộng càng tốt&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;(2) Loss term&lt;/strong&gt;: \(C\sum_{i=1}^n \xi_i\)
    &lt;ul&gt;
      &lt;li&gt;Tổng mức độ vi phạm của tất cả các điểm&lt;/li&gt;
      &lt;li&gt;Muốn vi phạm &lt;strong&gt;càng ít càng tốt&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;\(C\) là trọng số cân bằng hai mục tiêu&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;52-ví-dụ-số-cụ-thể-về-slack-variable&quot;&gt;5.2. Ví dụ số cụ thể về Slack Variable&lt;/h3&gt;

&lt;p&gt;Để hiểu rõ hơn cách slack variable hoạt động, xét một ví dụ đơn giản:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giả sử&lt;/strong&gt;: Ta có siêu phẳng đã tìm được: \(\beta = 1, \beta_0 = -2.5\), tức \(x - 2.5 = 0\) hay \(x = 2.5\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dữ liệu và phân tích:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Điểm&lt;/th&gt;
      &lt;th&gt;\(x_i\)&lt;/th&gt;
      &lt;th&gt;\(y_i\)&lt;/th&gt;
      &lt;th&gt;\(y_i(\beta^T x_i + \beta_0)\)&lt;/th&gt;
      &lt;th&gt;Ràng buộc&lt;/th&gt;
      &lt;th&gt;\(\xi_i\)&lt;/th&gt;
      &lt;th&gt;Phân loại&lt;/th&gt;
      &lt;th&gt;Ghi chú&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;A&lt;/td&gt;
      &lt;td&gt;4.0&lt;/td&gt;
      &lt;td&gt;+1&lt;/td&gt;
      &lt;td&gt;\(1(4-2.5)=1.5\)&lt;/td&gt;
      &lt;td&gt;\(1.5 \geq 1\) ✓&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đúng&lt;/td&gt;
      &lt;td&gt;Ngoài margin, lý tưởng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;B&lt;/td&gt;
      &lt;td&gt;3.0&lt;/td&gt;
      &lt;td&gt;+1&lt;/td&gt;
      &lt;td&gt;\(1(3-2.5)=0.5\)&lt;/td&gt;
      &lt;td&gt;\(0.5 \geq 1\) ✗&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;0.5&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đúng&lt;/td&gt;
      &lt;td&gt;Trong margin zone&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;C&lt;/td&gt;
      &lt;td&gt;2.5&lt;/td&gt;
      &lt;td&gt;+1&lt;/td&gt;
      &lt;td&gt;\(1(2.5-2.5)=0\)&lt;/td&gt;
      &lt;td&gt;\(0 \geq 1\) ✗&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;1.0&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Biên&lt;/td&gt;
      &lt;td&gt;Trên siêu phẳng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;D&lt;/td&gt;
      &lt;td&gt;2.0&lt;/td&gt;
      &lt;td&gt;+1&lt;/td&gt;
      &lt;td&gt;\(1(2-2.5)=-0.5\)&lt;/td&gt;
      &lt;td&gt;\(-0.5 \geq 1\) ✗&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;1.5&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Sai&lt;/td&gt;
      &lt;td&gt;Bị misclassified&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;E&lt;/td&gt;
      &lt;td&gt;1.0&lt;/td&gt;
      &lt;td&gt;-1&lt;/td&gt;
      &lt;td&gt;\(-1(1-2.5)=1.5\)&lt;/td&gt;
      &lt;td&gt;\(1.5 \geq 1\) ✓&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đúng&lt;/td&gt;
      &lt;td&gt;Ngoài margin, lý tưởng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;F&lt;/td&gt;
      &lt;td&gt;2.0&lt;/td&gt;
      &lt;td&gt;-1&lt;/td&gt;
      &lt;td&gt;\(-1(2-2.5)=0.5\)&lt;/td&gt;
      &lt;td&gt;\(0.5 \geq 1\) ✗&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;0.5&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đúng&lt;/td&gt;
      &lt;td&gt;Trong margin zone&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Giải thích từng trường hợp:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điểm A&lt;/strong&gt; (\(x=4, y=+1\)):
    &lt;ul&gt;
      &lt;li&gt;\(y(\beta^T x + \beta_0) = 1.5 \geq 1\) → Thỏa ràng buộc!&lt;/li&gt;
      &lt;li&gt;\(\xi_A = 0\) (không cần nới lỏng)&lt;/li&gt;
      &lt;li&gt;Điểm &lt;strong&gt;lý tưởng&lt;/strong&gt;, đúng phía và xa siêu phẳng&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm B&lt;/strong&gt; (\(x=3, y=+1\)):
    &lt;ul&gt;
      &lt;li&gt;\(y(\beta^T x + \beta_0) = 0.5 &amp;lt; 1\) → Vi phạm!&lt;/li&gt;
      &lt;li&gt;Cần \(\xi_B = 0.5\) để: \(0.5 \geq 1 - 0.5\) ✓&lt;/li&gt;
      &lt;li&gt;Vẫn phân loại đúng nhưng quá gần siêu phẳng&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm C&lt;/strong&gt; (\(x=2.5, y=+1\)):
    &lt;ul&gt;
      &lt;li&gt;Nằm chính xác trên siêu phẳng&lt;/li&gt;
      &lt;li&gt;\(\xi_C = 1.0\) (ngưỡng giới hạn)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm D&lt;/strong&gt; (\(x=2, y=+1\)):
    &lt;ul&gt;
      &lt;li&gt;Nằm sai phía (bên âm) mặc dù nhãn là +1&lt;/li&gt;
      &lt;li&gt;\(\xi_D = 1.5 &amp;gt; 1\) → Bị phân loại sai!&lt;/li&gt;
      &lt;li&gt;Đóng góp lớn vào penalty \(C \cdot \xi_D\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tổng penalty:&lt;/strong&gt;
\(\sum_{i=1}^n \xi_i = 0 + 0.5 + 1.0 + 1.5 + 0 + 0.5 = 3.5\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm mục tiêu:&lt;/strong&gt;
\(\frac{1}{2}(1)^2 + C \cdot 3.5 = 0.5 + 3.5C\)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nếu \(C = 1\): Objective = \(0.5 + 3.5 = 4.0\)&lt;/li&gt;
  &lt;li&gt;Nếu \(C = 10\): Objective = \(0.5 + 35 = 35.5\) (phạt nặng!)&lt;/li&gt;
  &lt;li&gt;Nếu \(C = 0.1\): Objective = \(0.5 + 0.35 = 0.85\) (ít quan tâm đến vi phạm)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;53-minh-họa-tương-tác-ảnh-hưởng-của-tham-số-c&quot;&gt;5.3. Minh họa tương tác: Ảnh hưởng của tham số C&lt;/h3&gt;

&lt;div id=&quot;softmargin-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;canvas id=&quot;softMarginCanvas&quot; width=&quot;700&quot; height=&quot;500&quot; style=&quot;border: 1px solid #ccc; display: block; margin: 0 auto;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin-top: 15px;&quot;&gt;
        &lt;label for=&quot;cSlider&quot; style=&quot;font-size: 16px; font-weight: bold;&quot;&gt;Tham số C: &lt;span id=&quot;cValue&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;cSlider&quot; min=&quot;0.01&quot; max=&quot;10&quot; step=&quot;0.1&quot; value=&quot;1&quot; style=&quot;width: 400px; margin: 10px;&quot; /&gt;
        &lt;p style=&quot;font-size: 14px; color: #666; margin-top: 10px;&quot;&gt;
            &lt;strong&gt;C nhỏ (←)&lt;/strong&gt;: Margin rộng, nhiều vi phạm được chấp nhận&lt;br /&gt;
            &lt;strong&gt;C lớn (→)&lt;/strong&gt;: Margin hẹp, ít vi phạm, phạt nặng
        &lt;/p&gt;
        &lt;div id=&quot;svmStats&quot; style=&quot;margin-top: 10px; font-size: 14px;&quot;&gt;
            &lt;span style=&quot;color: #e74c3c; font-weight: bold;&quot;&gt;● Vi phạm margin: 0&lt;/span&gt; | 
            &lt;span style=&quot;color: #f39c12; font-weight: bold;&quot;&gt;● Support vectors: 0&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    const canvas = document.getElementById(&apos;softMarginCanvas&apos;);
    if (!canvas) return;
    
    const ctx = canvas.getContext(&apos;2d&apos;);
    const width = canvas.width;
    const height = canvas.height;
    
    // Dữ liệu với một số điểm gây overlap
    const points = [
        // Class +1
        {x: 480, y: 150, label: 1},
        {x: 520, y: 100, label: 1},
        {x: 550, y: 200, label: 1},
        {x: 500, y: 250, label: 1},
        {x: 530, y: 180, label: 1},
        // Outliers class +1
        {x: 350, y: 280, label: 1}, // Vi phạm
        {x: 380, y: 320, label: 1}, // Vi phạm
        // Class -1
        {x: 180, y: 250, label: -1},
        {x: 220, y: 300, label: -1},
        {x: 260, y: 350, label: -1},
        {x: 200, y: 400, label: -1},
        {x: 240, y: 280, label: -1},
        // Outliers class -1
        {x: 420, y: 180, label: -1}, // Vi phạm
        {x: 400, y: 220, label: -1}  // Vi phạm
    ];
    
    let C = 1.0;
    
    function softMarginSVM() {
        // Simplified soft-margin SVM
        let posPoints = points.filter(p =&gt; p.label === 1);
        let negPoints = points.filter(p =&gt; p.label === -1);
        
        if (posPoints.length === 0 || negPoints.length === 0) return null;
        
        // Tính centroid với trọng số dựa trên C
        // C lớn -&gt; ít bị ảnh hưởng bởi outliers
        // C nhỏ -&gt; chấp nhận outliers nhiều hơn
        
        let posCenter = {
            x: posPoints.reduce((sum, p) =&gt; sum + p.x, 0) / posPoints.length,
            y: posPoints.reduce((sum, p) =&gt; sum + p.y, 0) / posPoints.length
        };
        
        let negCenter = {
            x: negPoints.reduce((sum, p) =&gt; sum + p.x, 0) / negPoints.length,
            y: negPoints.reduce((sum, p) =&gt; sum + p.y, 0) / negPoints.length
        };
        
        // Điều chỉnh hyperplane dựa trên C
        let dx = posCenter.x - negCenter.x;
        let dy = posCenter.y - negCenter.y;
        
        // Với C nhỏ, cho phép hyperplane linh hoạt hơn
        let flexibility = Math.max(0.1, 1 / C);
        
        let midX = (posCenter.x + negCenter.x) / 2;
        let midY = (posCenter.y + negCenter.y) / 2;
        
        let w = {x: dx, y: dy};
        let b = -(w.x * midX + w.y * midY);
        let norm = Math.sqrt(w.x * w.x + w.y * w.y);
        
        w.x /= norm;
        w.y /= norm;
        b /= norm;
        
        // Tính margin base
        let distances = points.map(p =&gt; ({
            point: p,
            dist: Math.abs(w.x * p.x + w.y * p.y + b),
            signedDist: (w.x * p.x + w.y * p.y + b) * p.label
        }));
        
        // Soft margin: margin điều chỉnh theo C
        let baseMargin = 50;
        let margin = baseMargin / (1 + C * 0.5);
        
        // Tìm violations và support vectors
        let violations = distances.filter(d =&gt; d.signedDist &lt; margin);
        let supportVectors = distances.filter(d =&gt; 
            Math.abs(d.dist - margin) &lt; 20 || d.signedDist &lt; margin
        );
        
        return {
            w, b, margin,
            violations: violations.map(v =&gt; v.point),
            supportVectors: supportVectors.map(v =&gt; v.point),
            distances
        };
    }
    
    function draw() {
        ctx.clearRect(0, 0, width, height);
        
        // Background
        ctx.fillStyle = &apos;#fafafa&apos;;
        ctx.fillRect(0, 0, width, height);
        
        let svm = softMarginSVM();
        
        if (svm) {
            // Vẽ margin region (vùng màu nhạt)
            ctx.fillStyle = &apos;rgba(52, 152, 219, 0.1)&apos;;
            ctx.fillRect(0, 0, width, height);
            
            // Vẽ margin boundaries
            ctx.strokeStyle = &apos;#95a5a6&apos;;
            ctx.lineWidth = 2;
            ctx.setLineDash([5, 5]);
            
            let b1 = svm.b + svm.margin;
            let b2 = svm.b - svm.margin;
            drawLine(svm.w, b1);
            drawLine(svm.w, b2);
            
            ctx.setLineDash([]);
            
            // Vẽ hyperplane
            ctx.strokeStyle = &apos;#2c3e50&apos;;
            ctx.lineWidth = 3;
            drawLine(svm.w, svm.b);
            
            // Highlight violations (slack variables)
            svm.violations.forEach(v =&gt; {
                ctx.strokeStyle = &apos;rgba(231, 76, 60, 0.5)&apos;;
                ctx.lineWidth = 20;
                ctx.beginPath();
                ctx.arc(v.x, v.y, 12, 0, 2 * Math.PI);
                ctx.stroke();
            });
            
            // Highlight support vectors
            svm.supportVectors.forEach(sv =&gt; {
                ctx.strokeStyle = &apos;#f39c12&apos;;
                ctx.lineWidth = 3;
                ctx.beginPath();
                ctx.arc(sv.x, sv.y, 15, 0, 2 * Math.PI);
                ctx.stroke();
            });
            
            // Update stats
            const statsDiv = document.getElementById(&apos;svmStats&apos;);
            if (statsDiv) {
                statsDiv.innerHTML = `
                    &lt;span style=&quot;color: #e74c3c; font-weight: bold;&quot;&gt;● Vi phạm margin: ${svm.violations.length}&lt;/span&gt; | 
                    &lt;span style=&quot;color: #f39c12; font-weight: bold;&quot;&gt;● Support vectors: ${svm.supportVectors.length}&lt;/span&gt; | 
                    &lt;span style=&quot;color: #3498db; font-weight: bold;&quot;&gt;Margin width: ${(svm.margin * 2).toFixed(1)}&lt;/span&gt;
                `;
            }
        }
        
        // Vẽ điểm dữ liệu
        points.forEach(p =&gt; {
            ctx.fillStyle = p.label === 1 ? &apos;#e74c3c&apos; : &apos;#2ecc71&apos;;
            ctx.beginPath();
            ctx.arc(p.x, p.y, 8, 0, 2 * Math.PI);
            ctx.fill();
            
            ctx.strokeStyle = &apos;#34495e&apos;;
            ctx.lineWidth = 2;
            ctx.stroke();
        });
        
        // Legend
        ctx.fillStyle = &apos;#34495e&apos;;
        ctx.font = &apos;bold 14px Arial&apos;;
        ctx.fillText(`C = ${C.toFixed(2)}`, 10, 30);
        
        // Giải thích C
        if (C &lt; 0.5) {
            ctx.fillText(&apos;Soft margin: Chấp nhận nhiều vi phạm&apos;, 10, 55);
        } else if (C &gt; 5) {
            ctx.fillText(&apos;Hard margin: Phạt nặng vi phạm&apos;, 10, 55);
        } else {
            ctx.fillText(&apos;Balanced: Trade-off margin vs error&apos;, 10, 55);
        }
    }
    
    function drawLine(w, b) {
        ctx.beginPath();
        if (Math.abs(w.y) &gt; 0.01) {
            let y0 = -(w.x * 0 + b) / w.y;
            let y1 = -(w.x * width + b) / w.y;
            ctx.moveTo(0, y0);
            ctx.lineTo(width, y1);
        } else {
            let x = -b / w.x;
            ctx.moveTo(x, 0);
            ctx.lineTo(x, height);
        }
        ctx.stroke();
    }
    
    // Slider event
    const slider = document.getElementById(&apos;cSlider&apos;);
    const cValue = document.getElementById(&apos;cValue&apos;);
    
    if (slider &amp;&amp; cValue) {
        slider.addEventListener(&apos;input&apos;, function() {
            C = parseFloat(this.value);
            cValue.textContent = C.toFixed(2);
            draw();
        });
    }
    
    // Initial draw
    draw();
})();
&lt;/script&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;5a-hinge-loss-loss-function-của-svm&quot;&gt;5A. Hinge Loss: Loss Function của SVM&lt;/h2&gt;

&lt;p&gt;Sau khi hiểu bài toán tối ưu của SVM, chúng ta sẽ tìm hiểu một &lt;strong&gt;góc nhìn khác&lt;/strong&gt; - nhìn SVM như một bài toán &lt;strong&gt;minimizing loss function&lt;/strong&gt;, tương tự như các thuật toán machine learning khác.&lt;/p&gt;

&lt;h3 id=&quot;5a1-từ-ràng-buộc-đến-loss-function&quot;&gt;5A.1. Từ ràng buộc đến Loss Function&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Nhìn lại Soft-Margin SVM:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{\beta, \beta_0, \xi} \quad &amp;amp;\frac{1}{2}\|\beta\|^2 + C\sum_{i=1}^n \xi_i \\
\text{s.t.} \quad &amp;amp;y_i(\beta^T x_i + \beta_0) \geq 1 - \xi_i \\
&amp;amp;\xi_i \geq 0, \quad i = 1, \ldots, n
\end{align}\]

&lt;p&gt;&lt;strong&gt;Câu hỏi tự nhiên:&lt;/strong&gt; Có thể loại bỏ biến phụ \(\xi_i\) và ràng buộc không?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trả lời:&lt;/strong&gt; Có! Từ ràng buộc \(\xi_i \geq 0\) và \(y_i(\beta^T x_i + \beta_0) \geq 1 - \xi_i\), ta có:&lt;/p&gt;

\[\xi_i \geq \max\{0, 1 - y_i(\beta^T x_i + \beta_0)\}\]

&lt;p&gt;Để minimize hàm mục tiêu, ta chọn \(\xi_i\) nhỏ nhất có thể:&lt;/p&gt;

\[\xi_i = \max\{0, 1 - y_i(\beta^T x_i + \beta_0)\}\]

&lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt; Bài toán tương đương với:&lt;/p&gt;

\[\min_{\beta, \beta_0} \quad \frac{1}{2}\|\beta\|^2 + C\sum_{i=1}^n \underbrace{\max\{0, 1 - y_i(\beta^T x_i + \beta_0)\}}_{\text{Hinge Loss } \ell(y_i, f(x_i))}\]

&lt;p&gt;Đây chính là &lt;strong&gt;formulation với hinge loss&lt;/strong&gt;!&lt;/p&gt;

&lt;h3 id=&quot;5a2-định-nghĩa-hinge-loss&quot;&gt;5A.2. Định nghĩa Hinge Loss&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hinge Loss&lt;/strong&gt; cho một điểm dữ liệu \((x_i, y_i)\) với dự đoán \(f(x_i) = \beta^T x_i + \beta_0\) được định nghĩa:&lt;/p&gt;

\[\ell_{\text{hinge}}(y_i, f(x_i)) = \max\{0, 1 - y_i f(x_i)\}\]

&lt;p&gt;hoặc viết gọn hơn:&lt;/p&gt;

\[\ell_{\text{hinge}}(y, f) = [1 - yf]_+ = \begin{cases}
0 &amp;amp; \text{nếu } yf \geq 1 \\
1 - yf &amp;amp; \text{nếu } yf &amp;lt; 1
\end{cases}\]

&lt;p&gt;với ký hiệu \([\cdot]_+ = \max\{0, \cdot\}\) (phần dương).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa của từng trường hợp:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;\(yf(x)\)&lt;/th&gt;
      &lt;th&gt;Diễn giải&lt;/th&gt;
      &lt;th&gt;Hinge Loss&lt;/th&gt;
      &lt;th&gt;Ý nghĩa&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;\(&amp;gt; 1\)&lt;/td&gt;
      &lt;td&gt;Phân loại đúng, xa margin&lt;/td&gt;
      &lt;td&gt;\(0\)&lt;/td&gt;
      &lt;td&gt;Không bị phạt, điểm lý tưởng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(= 1\)&lt;/td&gt;
      &lt;td&gt;Phân loại đúng, trên margin&lt;/td&gt;
      &lt;td&gt;\(0\)&lt;/td&gt;
      &lt;td&gt;Biên giới, không phạt&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(0 &amp;lt; yf &amp;lt; 1\)&lt;/td&gt;
      &lt;td&gt;Phân loại đúng, trong margin&lt;/td&gt;
      &lt;td&gt;\(1 - yf &amp;gt; 0\)&lt;/td&gt;
      &lt;td&gt;Bị phạt vì vi phạm margin&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(yf = 0\)&lt;/td&gt;
      &lt;td&gt;Trên siêu phẳng quyết định&lt;/td&gt;
      &lt;td&gt;\(1\)&lt;/td&gt;
      &lt;td&gt;Phạt mức trung bình&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(yf &amp;lt; 0\)&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Phân loại sai&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(1 - yf &amp;gt; 1\)&lt;/td&gt;
      &lt;td&gt;Phạt nặng, sai càng nhiều phạt càng nặng&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Đồ thị Hinge Loss:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Loss
  |
3 | \
  |  \
2 |   \
  |    \
1 |     \
  |      \
0 |_______\_____
  -2  -1  0  1  2  yf(x)
      ↑      ↑
    sai    đúng (ngoài lề)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;5a3-so-sánh-với-các-loss-function-khác&quot;&gt;5A.3. So sánh với các Loss Function khác&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1) Zero-One Loss (0-1 Loss):&lt;/strong&gt;&lt;/p&gt;

\[\ell_{0-1}(y, f) = \mathbb{I}[yf &amp;lt; 0] = \begin{cases}
0 &amp;amp; \text{nếu phân loại đúng} \\
1 &amp;amp; \text{nếu phân loại sai}
\end{cases}\]

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa&lt;/strong&gt;: Đếm số lỗi phân loại, đây là mục tiêu thực sự trong classification&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vấn đề&lt;/strong&gt;: Không khả vi, không lồi, NP-hard để tối ưu!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2) Logistic Loss (Log Loss):&lt;/strong&gt;&lt;/p&gt;

\[\ell_{\text{logistic}}(y, f) = \log(1 + e^{-yf})\]

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dùng trong&lt;/strong&gt;: Logistic Regression&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đặc điểm&lt;/strong&gt;: Smooth (khả vi mọi nơi), lồi&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So với hinge&lt;/strong&gt;: Không bao giờ bằng 0, luôn phạt (nhẹ) ngay cả khi đúng&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3) Exponential Loss:&lt;/strong&gt;&lt;/p&gt;

\[\ell_{\text{exp}}(y, f) = e^{-yf}\]

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dùng trong&lt;/strong&gt;: AdaBoost&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đặc điểm&lt;/strong&gt;: Phạt rất nặng với outliers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4) Squared Hinge Loss:&lt;/strong&gt;&lt;/p&gt;

\[\ell_{\text{squared}}(y, f) = [1 - yf]_+^2\]

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đặc điểm&lt;/strong&gt;: Khả vi tại \(yf = 1\), phạt nặng hơn hinge loss chuẩn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bảng so sánh trực quan:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Loss Function&lt;/th&gt;
      &lt;th&gt;Công thức&lt;/th&gt;
      &lt;th&gt;Lồi&lt;/th&gt;
      &lt;th&gt;Khả vi&lt;/th&gt;
      &lt;th&gt;Robust với outliers&lt;/th&gt;
      &lt;th&gt;Sparse solution&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;0-1 Loss&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\mathbb{I}[yf&amp;lt;0]\)&lt;/td&gt;
      &lt;td&gt;❌&lt;/td&gt;
      &lt;td&gt;❌&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;-&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hinge Loss&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\([1-yf]_+\)&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;⚠️ (subgradient)&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Logistic Loss&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\log(1+e^{-yf})\)&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;⚠️&lt;/td&gt;
      &lt;td&gt;❌&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Exponential Loss&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(e^{-yf}\)&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;❌&lt;/td&gt;
      &lt;td&gt;❌&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Squared Hinge&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\([1-yf]_+^2\)&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;⚠️&lt;/td&gt;
      &lt;td&gt;❌&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Tại sao Hinge Loss phù hợp với SVM?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lồi&lt;/strong&gt;: Đảm bảo bài toán tối ưu có nghiệm duy nhất&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Margin-based&lt;/strong&gt;: Phạt cả điểm đúng nhưng gần margin (không như logistic chỉ quan tâm đúng/sai)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sparse&lt;/strong&gt;: Loss bằng 0 khi \(yf \geq 1\) → Chỉ support vectors đóng góp&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust&lt;/strong&gt;: Phạt tuyến tính với outliers (không như exponential phạt quá nặng)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;5a4-hinge-loss-và-regularization&quot;&gt;5A.4. Hinge Loss và Regularization&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán SVM với Hinge Loss:&lt;/strong&gt;&lt;/p&gt;

\[\min_{\beta, \beta_0} \quad \underbrace{\frac{1}{2}\|\beta\|^2}_{\text{Regularization}} + C\sum_{i=1}^n \underbrace{[1 - y_i(\beta^T x_i + \beta_0)]_+}_{\text{Hinge Loss}}\]

&lt;p&gt;Đây là dạng &lt;strong&gt;Regularized Empirical Risk Minimization&lt;/strong&gt;:&lt;/p&gt;

\[\min_{\beta, \beta_0} \quad \underbrace{\frac{\lambda}{2}\|\beta\|^2}_{\text{Regularization}} + \underbrace{\frac{1}{n}\sum_{i=1}^n \ell(y_i, f(x_i))}_{\text{Empirical Risk}}\]

&lt;p&gt;với \(\lambda = \frac{1}{C \cdot n}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hai vai trò:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(\frac{1}{2}\|\beta\|^2\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Regularization term (Ridge regularization)&lt;/li&gt;
      &lt;li&gt;Prevent overfitting&lt;/li&gt;
      &lt;li&gt;Encourage large margin&lt;/li&gt;
      &lt;li&gt;Smooth solution&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\sum [1 - y_i f(x_i)]_+\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Data fitting term&lt;/li&gt;
      &lt;li&gt;Minimize training error&lt;/li&gt;
      &lt;li&gt;Ensure correct classification&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Trade-off được điều khiển bởi \(C\):&lt;/strong&gt;&lt;/p&gt;

\[\begin{cases}
C \to 0: &amp;amp; \text{Ưu tiên regularization} \to \text{Large margin, simple model} \\
C \to \infty: &amp;amp; \text{Ưu tiên data fitting} \to \text{Small margin, fit data closely}
\end{cases}\]

&lt;h3 id=&quot;5a5-hinge-loss-trong-deep-learning&quot;&gt;5A.5. Hinge Loss trong Deep Learning&lt;/h3&gt;

&lt;p&gt;Hinge loss không chỉ dùng cho SVM, nó còn xuất hiện trong:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) Multi-class Hinge Loss:&lt;/strong&gt;&lt;/p&gt;

\[\ell_{\text{multiclass}}(y, f) = \sum_{j \neq y} [1 + f_j - f_y]_+\]

&lt;ul&gt;
  &lt;li&gt;Dùng trong multi-class SVM&lt;/li&gt;
  &lt;li&gt;\(f_j\): score cho class \(j\)&lt;/li&gt;
  &lt;li&gt;\(y\): true class&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2) Triplet Loss (trong Metric Learning):&lt;/strong&gt;&lt;/p&gt;

\[\ell_{\text{triplet}} = [\|f(a) - f(p)\|^2 - \|f(a) - f(n)\|^2 + \text{margin}]_+\]

&lt;ul&gt;
  &lt;li&gt;\(a\): anchor, \(p\): positive, \(n\): negative&lt;/li&gt;
  &lt;li&gt;Dùng trong face recognition, siamese networks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3) Ranking Loss:&lt;/strong&gt;&lt;/p&gt;

\[\ell_{\text{rank}} = [1 - (f(x^+) - f(x^-))]_+\]

&lt;ul&gt;
  &lt;li&gt;Dùng trong learning to rank, recommendation systems&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5a6-subgradient-và-optimization&quot;&gt;5A.6. Subgradient và Optimization&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vấn đề&lt;/strong&gt;: Hinge loss &lt;strong&gt;không khả vi&lt;/strong&gt; tại \(yf = 1\)!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giải pháp&lt;/strong&gt;: Dùng &lt;strong&gt;subgradient&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tại điểm \(yf = 1\), dưới vi phân của hàm \(z \mapsto [1 - z]_+\) theo \(z = yf\) là đoạn \([-1, 0]\); theo quy tắc dây chuyền, dưới vi phân theo \(f\) là \(\{-y\alpha : \alpha \in [0, 1]\}\) (tức \([-1, 0]\) nếu \(y = +1\) và \([0, 1]\) nếu \(y = -1\)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dưới vi phân của hinge loss theo \(f\):&lt;/strong&gt;&lt;/p&gt;

\[\partial_f \ell_{\text{hinge}}(y, f) = \begin{cases}
\{0\} &amp;amp; \text{nếu } yf &amp;gt; 1 \\
\{-y\alpha : \alpha \in [0, 1]\} &amp;amp; \text{nếu } yf = 1 \\
\{-y\} &amp;amp; \text{nếu } yf &amp;lt; 1
\end{cases}\]

&lt;p&gt;&lt;strong&gt;Gradient của bài toán SVM:&lt;/strong&gt;&lt;/p&gt;

\[\nabla_\beta J(\beta) = \beta + C\sum_{i=1}^n \partial_\beta [1 - y_i(\beta^T x_i + \beta_0)]_+\]

\[= \beta - C\sum_{i: y_i f(x_i) &amp;lt; 1} y_i x_i\]

&lt;p&gt;Đây là cơ sở cho các thuật toán như &lt;strong&gt;Subgradient Descent&lt;/strong&gt; và &lt;strong&gt;Stochastic Gradient Descent&lt;/strong&gt; để train SVM.&lt;/p&gt;

&lt;h3 id=&quot;5a7-kết-nối-với-soft-margin-svm&quot;&gt;5A.7. Kết nối với Soft-Margin SVM&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ba formulation tương đương:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) Constrained form (ban đầu):&lt;/strong&gt;
\(\min \frac{1}{2}\|\beta\|^2 + C\sum \xi_i \quad \text{s.t. } y_i f(x_i) \geq 1 - \xi_i, \xi_i \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) Unconstrained with Hinge Loss:&lt;/strong&gt;
\(\min \frac{1}{2}\|\beta\|^2 + C\sum [1 - y_i f(x_i)]_+\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) Dual form:&lt;/strong&gt;
\(\max \sum w_i - \frac{1}{2}\sum_{i,j} w_i w_j y_i y_j \langle x_i, x_j \rangle \quad \text{s.t. } 0 \leq w_i \leq C, \sum w_i y_i = 0\)&lt;/p&gt;

&lt;p&gt;Ba formulation này &lt;strong&gt;hoàn toàn tương đương&lt;/strong&gt;, cho cùng một nghiệm tối ưu!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Khi nào dùng formulation nào?&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Formulation&lt;/th&gt;
      &lt;th&gt;Khi nào dùng&lt;/th&gt;
      &lt;th&gt;Solver&lt;/th&gt;
      &lt;th&gt;Ưu điểm&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Constrained&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Lý thuyết, phân tích KKT&lt;/td&gt;
      &lt;td&gt;QP solver&lt;/td&gt;
      &lt;td&gt;Dễ phân tích, rõ ràng về ràng buộc&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hinge Loss&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Training với SGD&lt;/td&gt;
      &lt;td&gt;Subgradient descent&lt;/td&gt;
      &lt;td&gt;Nhanh, scalable, dễ implement&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dual&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Kernel methods&lt;/td&gt;
      &lt;td&gt;SMO, LIBSVM&lt;/td&gt;
      &lt;td&gt;Kernel trick, sparse solution&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;6-bài-toán-đối-ngẫu-dual-problem&quot;&gt;6. Bài toán Đối ngẫu (Dual Problem)&lt;/h2&gt;

&lt;h3 id=&quot;61-động-lực-xây-dựng-bài-toán-đối-ngẫu&quot;&gt;6.1. Động lực xây dựng bài toán đối ngẫu&lt;/h3&gt;

&lt;p&gt;Có vẻ như chúng ta đã có bài toán Soft-Margin SVM hoàn chỉnh ở dạng &lt;strong&gt;primal&lt;/strong&gt; (gốc). Tại sao lại cần một “phiên bản đối ngẫu” (dual)?&lt;/p&gt;

&lt;p&gt;Việc chuyển sang bài toán đối ngẫu mang lại ba lợi ích quan trọng trong thực hành:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng kỹ thuật hạt nhân (Kernel Trick)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Dual form chỉ phụ thuộc vào &lt;strong&gt;tích vô hướng&lt;/strong&gt; \(\langle x_i, x_j \rangle\) giữa các điểm dữ liệu&lt;/li&gt;
      &lt;li&gt;Ta có thể thay thế bằng &lt;strong&gt;kernel function&lt;/strong&gt; \(K(x_i, x_j)\) để ánh xạ ngầm lên không gian vô hạn chiều&lt;/li&gt;
      &lt;li&gt;Điều này cho phép SVM xử lý dữ liệu &lt;strong&gt;phi tuyến phức tạp&lt;/strong&gt; mà không tăng độ phức tạp tính toán!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu quả khi số chiều lớn&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Primal: \(p + 1 + n\) biến (\(p\) có thể rất lớn, thậm chí vô hạn với kernel)&lt;/li&gt;
      &lt;li&gt;Dual: chỉ \(n\) biến (số mẫu, thường nhỏ hơn nhiều)&lt;/li&gt;
      &lt;li&gt;Khi \(n \ll p\) (ví dụ: phân loại văn bản, gene expression), dual nhanh hơn đáng kể&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sparsity tự nhiên&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Nghiệm dual có tính sparse: chỉ &lt;strong&gt;support vectors&lt;/strong&gt; có \(w_i &amp;gt; 0\)&lt;/li&gt;
      &lt;li&gt;Phần lớn \(w_i = 0\) → dự đoán nhanh, tiết kiệm bộ nhớ&lt;/li&gt;
      &lt;li&gt;Dễ hiểu: “Những điểm nào quyết định siêu phẳng?”&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;62-xây-dựng-dual-problem&quot;&gt;6.2. Xây dựng Dual Problem&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán Primal:&lt;/strong&gt;
\(\begin{align}
\min_{\beta, \beta_0, \xi} \quad &amp;amp;\frac{1}{2}\|\beta\|^2 + C\sum_{i=1}^n \xi_i \\
\text{s.t.} \quad &amp;amp;y_i(\beta^T x_i + \beta_0) \geq 1 - \xi_i \\
&amp;amp;\xi_i \geq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt;
\(L(\beta, \beta_0, \xi, w, v) = \frac{1}{2}\|\beta\|^2 + C\sum_{i=1}^n \xi_i - \sum_{i=1}^n w_i[y_i(\beta^T x_i + \beta_0) - 1 + \xi_i] - \sum_{i=1}^n v_i \xi_i\)&lt;/p&gt;

&lt;p&gt;trong đó \(w_i \geq 0, v_i \geq 0\) là các Lagrange multipliers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện KKT - Stationarity:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lấy đạo hàm theo các biến primal và cho bằng 0:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
\[\frac{\partial L}{\partial \beta} = 0 \Rightarrow \beta = \sum_{i=1}^n w_i y_i x_i\]
  &lt;/li&gt;
  &lt;li&gt;
\[\frac{\partial L}{\partial \beta_0} = 0 \Rightarrow \sum_{i=1}^n w_i y_i = 0\]
  &lt;/li&gt;
  &lt;li&gt;
\[\frac{\partial L}{\partial \xi_i} = 0 \Rightarrow C - w_i - v_i = 0 \Rightarrow w_i \leq C\]
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Thế vào Lagrangian&lt;/strong&gt;, ta được &lt;strong&gt;Dual Problem:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{w} \quad &amp;amp;\sum_{i=1}^n w_i - \frac{1}{2} \sum_{i,j=1}^n w_i w_j y_i y_j \langle x_i, x_j \rangle \\
\text{s.t.} \quad &amp;amp;\sum_{i=1}^n w_i y_i = 0 \\
&amp;amp;0 \leq w_i \leq C, \quad i = 1, \ldots, n
\end{align}\]

&lt;p&gt;&lt;strong&gt;Hoặc dạng minimization:&lt;/strong&gt;
\(\begin{align}
\min_{w} \quad &amp;amp;\frac{1}{2} \sum_{i,j=1}^n w_i w_j y_i y_j \langle x_i, x_j \rangle - \sum_{i=1}^n w_i \\
\text{s.t.} \quad &amp;amp;\sum_{i=1}^n w_i y_i = 0 \\
&amp;amp;0 \leq w_i \leq C, \quad i = 1, \ldots, n
\end{align}\)&lt;/p&gt;

&lt;h3 id=&quot;63-ý-nghĩa-của-các-biến-đối-ngẫu&quot;&gt;6.3. Ý nghĩa của các biến đối ngẫu&lt;/h3&gt;

&lt;p&gt;Mỗi nhân tử đối ngẫu \(w_i\) phản ánh trực tiếp vai trò của điểm dữ liệu \(x_i\) trong việc xác định siêu phẳng tối ưu:&lt;/p&gt;

&lt;p&gt;Hãy “đọc” ý nghĩa của \(w_i\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(w_i = 0\)&lt;/strong&gt;: Điểm \(x_i\) không ảnh hưởng đến siêu phẳng
    &lt;ul&gt;
      &lt;li&gt;Nằm xa margin, phân loại đúng và an toàn&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Không đóng góp gì&lt;/strong&gt; vào siêu phẳng: có thể xóa điểm này mà mô hình không đổi!&lt;/li&gt;
      &lt;li&gt;Chiếm đa số các điểm trong dataset&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(0 &amp;lt; w_i &amp;lt; C\)&lt;/strong&gt;: Điểm \(x_i\) là &lt;strong&gt;vector hỗ trợ nằm trên biên lề&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nằm &lt;strong&gt;chính xác trên margin boundary&lt;/strong&gt; (\(\xi_i = 0\))&lt;/li&gt;
      &lt;li&gt;Phân loại đúng, nhưng ở vị trí “nguy hiểm” nhất&lt;/li&gt;
      &lt;li&gt;Đây là những điểm &lt;strong&gt;quan trọng nhất&lt;/strong&gt;, quyết định độ nghiêng và vị trí của siêu phẳng&lt;/li&gt;
      &lt;li&gt;Thường rất ít: chỉ 5-20% số điểm&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(w_i = C\)&lt;/strong&gt;: Điểm \(x_i\) là &lt;strong&gt;vector hỗ trợ chạm biên trên&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vi phạm margin (\(\xi_i &amp;gt; 0\)): hoặc nằm trong margin, hoặc bị phân loại sai&lt;/li&gt;
      &lt;li&gt;“Đóng góp” vào siêu phẳng nhưng cũng &lt;strong&gt;bị phạt&lt;/strong&gt; trong hàm mục tiêu&lt;/li&gt;
      &lt;li&gt;Thường là outliers, điểm nhiễu, hoặc điểm thuộc vùng chồng lấn giữa hai lớp&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;64-tính-beta_0-từ-nghiệm-dual&quot;&gt;6.4. Tính \(\beta_0\) từ nghiệm Dual&lt;/h3&gt;

&lt;p&gt;Sau khi giải dual problem và có \(w^\star\), ta tính:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;\(\beta^\star\)&lt;/strong&gt; từ công thức: \(\beta^\star = \sum_{i=1}^n w_i^\star y_i x_i\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;\(\beta_0^\star\)&lt;/strong&gt; từ support vector trên margin (\(0 &amp;lt; w_i^\star &amp;lt; C\), \(\xi_i^\star = 0\)):
\(\beta_0^\star = y_i - \beta^{\star T} x_i\)&lt;/p&gt;

    &lt;p&gt;Trong thực tế, để robust hơn, ta lấy trung bình trên tất cả SV trên margin:
\(\beta_0^\star = \frac{1}{|\mathcal{S}|} \sum_{i \in \mathcal{S}} (y_i - \beta^{\star T} x_i)\)
với \(\mathcal{S} = \{i: 0 &amp;lt; w_i^\star &amp;lt; C\}\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;65-ưu-điểm-của-dual-formulation&quot;&gt;6.5. Ưu điểm của Dual Formulation&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kernel trick&lt;/strong&gt;: Chỉ phụ thuộc vào \(\langle x_i, x_j \rangle\) → có thể thay bằng \(K(x_i, x_j)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ít ràng buộc&lt;/strong&gt;: Chỉ 1 ràng buộc đẳng thức + box constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solver hiệu quả&lt;/strong&gt;: SMO (Sequential Minimal Optimization), LIBSVM&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sparsity tự nhiên&lt;/strong&gt;: Chỉ support vectors có \(w_i &amp;gt; 0\)&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;7-các-vector-hỗ-trợ-support-vectors&quot;&gt;7. Các vector hỗ trợ (Support Vectors)&lt;/h2&gt;

&lt;p&gt;Giờ đây chúng ta đến với &lt;strong&gt;khái niệm trung tâm&lt;/strong&gt; mà SVM được đặt tên theo: &lt;strong&gt;Support Vectors&lt;/strong&gt; (các vector hỗ trợ).&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa-chính-xác&quot;&gt;Định nghĩa chính xác&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Support vectors&lt;/strong&gt; là tất cả các điểm dữ liệu có hệ số đối ngẫu khác không:
\(\text{Support vectors} = \{x_i : w_i^\star &amp;gt; 0\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tại sao chúng quan trọng đến vậy?&lt;/strong&gt; Nhớ lại công thức từ điều kiện KKT stationarity:
\(\beta^\star = \sum_{i: w_i^\star &amp;gt; 0} w_i^\star y_i x_i = \sum_{\text{support vectors}} w_i^\star y_i x_i\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hệ quả quan trọng:&lt;/strong&gt; Siêu phẳng tối ưu &lt;strong&gt;chỉ phụ thuộc vào các vector hỗ trợ&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tất cả điểm khác (\(w_i = 0\)) có thể bỏ đi mà mô hình không thay đổi&lt;/li&gt;
  &lt;li&gt;Siêu phẳng được xác định hoàn toàn bởi một tập con nhỏ các điểm dữ liệu&lt;/li&gt;
  &lt;li&gt;Đây là lý do SVM có tính &lt;strong&gt;sparse&lt;/strong&gt; tự nhiên&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ba-loại-support-vectors---mỗi-loại-một-vai-trò&quot;&gt;Ba loại Support Vectors - Mỗi loại một vai trò&lt;/h3&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter12/svm.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$ \text{[Hình 1] Minh họa các support vectors với } \xi^\star \neq 0 \text{ [3]}$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;1) Support vectors trên margin&lt;/strong&gt; (\(\xi_i^\star = 0\), \(0 &amp;lt; w_i^\star \leq C\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nằm đúng trên đường biên margin&lt;/li&gt;
  &lt;li&gt;
\[y_i(\beta^{\star T} x_i + \beta_0^\star) = 1\]
  &lt;/li&gt;
  &lt;li&gt;Quan trọng nhất trong xác định siêu phẳng&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2) Support vectors trong margin&lt;/strong&gt; (\(0 &amp;lt; \xi_i^\star &amp;lt; 1\), \(w_i^\star = C\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nằm giữa margin và siêu phẳng&lt;/li&gt;
  &lt;li&gt;Vẫn phân loại đúng nhưng vi phạm margin&lt;/li&gt;
  &lt;li&gt;Thường là outliers hoặc điểm gần biên&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3) Support vectors bị misclassify&lt;/strong&gt; (\(\xi_i^\star \geq 1\), \(w_i^\star = C\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nằm sai phía siêu phẳng&lt;/li&gt;
  &lt;li&gt;Bị phân loại sai&lt;/li&gt;
  &lt;li&gt;Đóng góp nhiều vào penalty \(C\sum \xi_i\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;8-kernel-methods-từ-tuyến-tính-đến-phi-tuyến&quot;&gt;8. Kernel Methods: Từ tuyến tính đến phi tuyến&lt;/h2&gt;

&lt;p&gt;Cho đến giờ, chúng ta mới chỉ làm việc với &lt;strong&gt;siêu phẳng tuyến tính&lt;/strong&gt; - một “đường thẳng” (hoặc mặt phẳng trong không gian nhiều chiều) để phân chia dữ liệu. Nhưng dữ liệu thực tế thường có &lt;strong&gt;ranh giới phức tạp, phi tuyến&lt;/strong&gt;. Ví dụ: hai lớp dữ liệu phân bố theo hình tròn đồng tâm - không có đường thẳng nào tách được chúng!&lt;/p&gt;

&lt;p&gt;Để mở rộng SVM sang các ranh giới phi tuyến, ta sử dụng &lt;strong&gt;kỹ thuật hạt nhân (Kernel Trick)&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;80-nhìn-lại-dual-problem-và-vai-trò-của-tích-vô-hướng&quot;&gt;8.0. Nhìn lại: Dual Problem và vai trò của tích vô hướng&lt;/h3&gt;

&lt;p&gt;Trước khi đi vào kernel, hãy nhìn lại &lt;strong&gt;bài toán đối ngẫu&lt;/strong&gt; đã học ở Section 6:&lt;/p&gt;

\[\min_{w} \frac{1}{2} \sum_{i,j=1}^n w_i w_j y_i y_j \underbrace{\langle x_i, x_j \rangle}_{\text{Tích vô hướng!}} - \sum_{i=1}^n w_i\]

&lt;p&gt;&lt;strong&gt;Quan sát then chốt:&lt;/strong&gt; Bài toán dual &lt;strong&gt;CHỈ phụ thuộc&lt;/strong&gt; vào tích vô hướng \(\langle x_i, x_j \rangle\) giữa các cặp điểm dữ liệu, KHÔNG phụ thuộc trực tiếp vào \(x_i\) hay \(x_j\) riêng lẻ!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hệ quả quan trọng:&lt;/strong&gt; Nếu ta thay tích vô hướng \(\langle x_i, x_j \rangle\) bằng một hàm khác \(K(x_i, x_j)\), toàn bộ bài toán vẫn giải được, miễn là \(K\) thỏa mãn một số điều kiện nhất định.&lt;/p&gt;

&lt;p&gt;Đây chính là &lt;strong&gt;cửa ngõ&lt;/strong&gt; dẫn đến kernel methods!&lt;/p&gt;

&lt;h3 id=&quot;81-linear-kernel-điểm-khởi-đầu-đơn-giản-nhất&quot;&gt;8.1. Linear Kernel: Điểm khởi đầu đơn giản nhất&lt;/h3&gt;

&lt;p&gt;Trước khi nghĩ đến những kernel phức tạp, hãy bắt đầu với trường hợp &lt;strong&gt;đơn giản nhất&lt;/strong&gt;: chính tích vô hướng thông thường!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Định nghĩa Linear Kernel:&lt;/strong&gt;&lt;/p&gt;

\[K_{\text{linear}}(x, z) = \langle x, z \rangle = x^T z = \sum_{j=1}^d x_j z_j\]

&lt;p&gt;Dù đơn giản, đây là ví dụ cơ bản nhất để hình dung khái niệm hàm hạt nhân (kernel).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tại sao Linear Kernel là một kernel?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Câu hỏi: Có tồn tại ánh xạ \(\phi\) sao cho \(K_{\text{linear}}(x, z) = \langle \phi(x), \phi(z) \rangle\)?&lt;/p&gt;

&lt;p&gt;Câu trả lời: &lt;strong&gt;CÓ!&lt;/strong&gt; Chọn ánh xạ đơn giản nhất:&lt;/p&gt;

\[\phi(x) = x \quad \text{(ánh xạ đồng nhất - identity map)}\]

&lt;p&gt;Khi đó:&lt;/p&gt;

\[K_{\text{linear}}(x, z) = \langle \phi(x), \phi(z) \rangle = \langle x, z \rangle = x^T z \quad \checkmark\]

&lt;p&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Linear kernel = “KHÔNG ánh xạ gì cả”, dữ liệu vẫn ở không gian gốc&lt;/li&gt;
  &lt;li&gt;Siêu phẳng phân chia vẫn là &lt;strong&gt;tuyến tính&lt;/strong&gt; trong không gian gốc&lt;/li&gt;
  &lt;li&gt;Đây chính là SVM thông thường mà chúng ta đã học!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tại sao vẫn gọi nó là “kernel”?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Vì nó thỏa mãn &lt;strong&gt;điều kiện Mercer&lt;/strong&gt; (sẽ học sau):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối xứng&lt;/strong&gt;: \(K(x, z) = x^T z = z^T x = K(z, x)\) ✓&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Positive semi-definite&lt;/strong&gt;: Ma trận Gram \(\mathbf{K}_{ij} = x_i^T x_j\) luôn PSD ✓&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Khi nào dùng Linear Kernel?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Baseline đầu tiên&lt;/strong&gt;: Luôn thử linear kernel trước!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dữ liệu chiều cao&lt;/strong&gt; (\(p \gg n\)): Như phân loại văn bản với hàng nghìn từ&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dữ liệu đã tách được tuyến tính&lt;/strong&gt;: Không cần phi tuyến hóa&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cần tốc độ&lt;/strong&gt;: Nhanh nhất, ít tham số nhất&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ ứng dụng - Text Classification:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Trong phân loại email spam/ham:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Dữ liệu được biểu diễn bằng TF-IDF với 10,000 từ vựng → không gian 10,000 chiều&lt;/li&gt;
  &lt;li&gt;Linear kernel thường hoạt động tốt vì dữ liệu văn bản thường tách được trong không gian TF-IDF&lt;/li&gt;
  &lt;li&gt;Nhanh và hiệu quả, không cần phi tuyến hóa&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bài toán dual với Linear Kernel:&lt;/strong&gt;&lt;/p&gt;

\[\min_{w} \frac{1}{2} \sum_{i,j} w_i w_j y_i y_j \underbrace{K_{\text{linear}}(x_i, x_j)}_{= x_i^T x_j} - \sum_i w_i\]

&lt;p&gt;Giống hệt bài toán dual ban đầu! Linear kernel chỉ là “viết lại” tích vô hướng dưới dạng kernel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kết luận quan trọng:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Linear kernel là &lt;strong&gt;nền tảng&lt;/strong&gt; để hiểu các kernel khác. Nó cho thấy:&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;Kernel là một hàm \(K(x, z)\) tính “độ giống nhau” giữa \(x\) và \(z\)&lt;/li&gt;
    &lt;li&gt;Với linear kernel, “độ giống nhau” = tích vô hướng thông thường&lt;/li&gt;
    &lt;li&gt;Các kernel khác sẽ định nghĩa “độ giống nhau” theo cách khác, phức tạp hơn&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;Giờ chúng ta đã hiểu linear kernel, hãy xem điều gì xảy ra khi dữ liệu &lt;strong&gt;không tách được tuyến tính&lt;/strong&gt;!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;82-động-lực-khi-linear-kernel-không-đủ&quot;&gt;8.2. Động lực: Khi Linear Kernel không đủ&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vấn đề cơ bản:&lt;/strong&gt; Nhiều bộ dữ liệu thực tế &lt;strong&gt;không tách được tuyến tính&lt;/strong&gt; trong không gian gốc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ kinh điển - Dữ liệu XOR:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Class +1:  (+1, +1)  và  (-1, -1)  (hai góc chéo)
Class -1:  (+1, -1)  và  (-1, +1)  (hai góc chéo còn lại)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Không có đường thẳng nào có thể phân chia hai lớp này trong không gian 2D!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý tưởng chính:&lt;/strong&gt; Khi dữ liệu không tách được tuyến tính trong không gian ban đầu, ta ánh xạ dữ liệu sang một không gian đặc trưng có số chiều cao hơn, nơi hai lớp có thể tách được tuyến tính.&lt;/p&gt;

&lt;h3 id=&quot;83-feature-mapping-từ-linear-đến-polynomial&quot;&gt;8.3. Feature Mapping: Từ Linear đến Polynomial&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bắt đầu với ví dụ đơn giản - Dữ liệu 1 chiều:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Giả sử dữ liệu trên trục số:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Class +1: x = -2, x = +2  (hai đầu)
Class -1: x = 0           (ở giữa)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Không có điểm nào trên trục số (threshold) tách được hai class này!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giải pháp: Ánh xạ lên không gian 2 chiều&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Định nghĩa ánh xạ:
\(\phi(x) = (x, x^2) \in \mathbb{R}^2\)&lt;/p&gt;

&lt;p&gt;Dữ liệu sau khi ánh xạ:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Class +1: φ(-2) = (-2, 4),  φ(+2) = (+2, 4)
Class -1: φ(0) = (0, 0)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Bây giờ trong không gian 2D \((x, x^2)\), ta có thể dùng đường thẳng \(x^2 = 2\) để tách hai class!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kernel tương ứng:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Với ánh xạ \(\phi(x) = (x, x^2)\), kernel là:&lt;/p&gt;

\[\begin{align}
K(x, z) &amp;amp;= \langle \phi(x), \phi(z) \rangle \\
&amp;amp;= \langle (x, x^2), (z, z^2) \rangle \\
&amp;amp;= xz + x^2z^2
\end{align}\]

&lt;p&gt;&lt;strong&gt;Mở rộng: Polynomial Kernel tổng quát&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;84-feature-mapping-tổng-quát-ánh-xạ-lên-không-gian-mới&quot;&gt;8.4. Feature Mapping tổng quát: Ánh xạ lên không gian mới&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; Ánh xạ đặc trưng (feature map) là một hàm \(\phi\) biến đổi dữ liệu từ không gian gốc sang không gian mới:&lt;/p&gt;

\[\phi: \mathbb{R}^d \to \mathcal{H}\]

  &lt;p&gt;trong đó \(\mathcal{H}\) là &lt;strong&gt;không gian đặc trưng&lt;/strong&gt; (feature space), thường có số chiều cao hơn (thậm chí vô hạn!).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ cụ thể - Ánh xạ bậc 2 cho \(\mathbb{R}^2\):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Với \(x = (x_1, x_2) \in \mathbb{R}^2\), định nghĩa:&lt;/p&gt;

\[\phi(x) = (x_1^2, \sqrt{2}x_1x_2, x_2^2, \sqrt{2}x_1, \sqrt{2}x_2, 1) \in \mathbb{R}^6\]

&lt;p&gt;Bây giờ \(x\) được biểu diễn bằng &lt;strong&gt;6 chiều&lt;/strong&gt; thay vì 2 chiều! Trong không gian mới này, nhiều dữ liệu phi tuyến trở nên tách được tuyến tính.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán SVM trong không gian mới:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Thay vì giải:
\(\min_{w} \frac{1}{2} \sum_{i,j} w_i w_j y_i y_j \langle x_i, x_j \rangle - \sum_i w_i\)&lt;/p&gt;

&lt;p&gt;Ta giải trong không gian đặc trưng:
\(\min_{w} \frac{1}{2} \sum_{i,j} w_i w_j y_i y_j \langle \phi(x_i), \phi(x_j) \rangle - \sum_i w_i\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vấn đề lớn:&lt;/strong&gt; Nếu \(\phi(x)\) có số chiều rất cao (ví dụ: 1000 chiều), việc tính toán \(\langle \phi(x_i), \phi(x_j) \rangle\) sẽ &lt;strong&gt;cực kỳ tốn kém&lt;/strong&gt;!&lt;/p&gt;

&lt;h3 id=&quot;85-kỹ-thuật-hạt-nhân-kernel-trick-tính-tích-vô-hướng-không-cần-ánh-xạ-tường-minh&quot;&gt;8.5. Kỹ thuật hạt nhân (Kernel Trick): Tính tích vô hướng không cần ánh xạ tường minh&lt;/h3&gt;

&lt;p&gt;Thay vì tính tường minh \(\phi(x)\) trong không gian chiều cao rồi lấy tích vô hướng, ta chọn một &lt;strong&gt;hàm hạt nhân&lt;/strong&gt; \(K\) thỏa mãn:&lt;/p&gt;

\[K(x_i, x_j) = \langle \phi(x_i), \phi(x_j) \rangle\]

&lt;p&gt;mà &lt;strong&gt;KHÔNG cần tính \(\phi(x)\) tường minh&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lợi ích tính toán của kỹ thuật hạt nhân:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tính \(K(x_i, x_j)\) trực tiếp trong không gian gốc: &lt;strong&gt;\(O(d)\) - rất nhanh!&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Tránh tính \(\phi(x_i)\) và \(\phi(x_j)\) trong không gian chiều cao: tiết kiệm tài nguyên khổng lồ&lt;/li&gt;
  &lt;li&gt;Thậm chí ánh xạ lên &lt;strong&gt;không gian vô hạn chiều&lt;/strong&gt; mà vẫn tính toán được!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ minh họa - Polynomial Kernel bậc 2:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Với ánh xạ \(\phi(x) = (x_1^2, \sqrt{2}x_1x_2, x_2^2, \sqrt{2}x_1, \sqrt{2}x_2, 1)\), ta có:&lt;/p&gt;

\[\begin{align}
\langle \phi(x), \phi(z) \rangle &amp;amp;= x_1^2 z_1^2 + 2x_1x_2z_1z_2 + x_2^2z_2^2 + 2x_1z_1 + 2x_2z_2 + 1 \\
&amp;amp;= (x_1z_1 + x_2z_2)^2 + 2(x_1z_1 + x_2z_2) + 1 \\
&amp;amp;= (\langle x, z \rangle + 1)^2
\end{align}\]

&lt;p&gt;Vậy thay vì tính 6 phép nhân trong \(\mathbb{R}^6\), ta chỉ cần:&lt;/p&gt;

\[K(x, z) = (\langle x, z \rangle + 1)^2\]

&lt;p&gt;&lt;strong&gt;2 phép tính trong \(\mathbb{R}^2\)&lt;/strong&gt; - Nhanh gấp nhiều lần!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So sánh chi phí tính toán:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Các bước&lt;/th&gt;
      &lt;th&gt;Độ phức tạp&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Cách 1: Tính tường minh&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;1. Tính \(\phi(x)\) (6 chiều)&lt;br /&gt;2. Tính \(\phi(z)\) (6 chiều)&lt;br /&gt;3. Tính tích vô hướng (6 phép nhân)&lt;/td&gt;
      &lt;td&gt;\(O(6 + 6 + 6) = O(18)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Cách 2: Kernel trick&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;1. Tính \(\langle x, z \rangle\) (2 phép nhân)&lt;br /&gt;2. Tính \((\cdot + 1)^2\) (1 phép cộng, 1 phép mũ)&lt;/td&gt;
      &lt;td&gt;\(O(2 + 2) = O(4)\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nhanh hơn &lt;strong&gt;4.5 lần&lt;/strong&gt;! Và đây chỉ với ánh xạ bậc 2 trong \(\mathbb{R}^2\). Với dữ liệu chiều cao và bậc lớn hơn, lợi ích còn lớn hơn rất nhiều!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ thực tế với dữ liệu chiều cao:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Với polynomial kernel bậc 3 trong không gian 100 chiều:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Số chiều sau ánh xạ tường minh&lt;/strong&gt;: \(C(100+3, 3) \approx 176,851\) chiều!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí tính toán tường minh&lt;/strong&gt;: Phải tính và lưu trữ vector 176,851 chiều&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí với kernel trick&lt;/strong&gt;: Chỉ cần tính \((\langle x, z \rangle + 1)^3\) - vài phép toán đơn giản&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết quả&lt;/strong&gt;: Kernel trick nhanh hơn &lt;strong&gt;hàng trăm lần&lt;/strong&gt;!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kết luận về Kernel Trick:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giảm chi phí tính toán:&lt;/strong&gt; Không cần biểu diễn tường minh \(\phi(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xử lý được không gian vô hạn chiều:&lt;/strong&gt; Chẳng hạn hạt nhân RBF tương ứng với không gian đặc trưng vô hạn chiều nhưng vẫn tính được trực tiếp trong \(\mathbb{R}^d\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc gọn gàng:&lt;/strong&gt; Chỉ cần thay tích vô hướng trong bài toán đối ngẫu bằng hàm \(K(x, z)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Kernel trick&lt;/strong&gt; là lý do SVM có thể xử lý dữ liệu phi tuyến phức tạp mà vẫn hiệu quả về mặt tính toán!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;86-các-kernel-phổ-biến-và-ứng-dụng&quot;&gt;8.6. Các Kernel phổ biến và ứng dụng&lt;/h3&gt;

&lt;p&gt;Giờ chúng ta đã hiểu kernel trick, hãy xem các kernel phổ biến nhất trong thực tế:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) Linear Kernel (Kernel tuyến tính):&lt;/strong&gt;&lt;/p&gt;

\[K(x, z) = \langle x, z \rangle = x^T z\]

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khi nào dùng:&lt;/strong&gt; Dữ liệu đã tách được tuyến tính, hoặc số chiều rất cao (\(p \gg n\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Nhanh nhất, ít tham số, tránh overfitting&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; Phân loại văn bản (bag-of-words với hàng nghìn từ vựng)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2) Polynomial Kernel (Kernel đa thức):&lt;/strong&gt;&lt;/p&gt;

\[K(x, z) = (\langle x, z \rangle + c)^q\]

&lt;p&gt;với \(q\) là bậc đa thức, \(c \geq 0\) là hằng số.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khi nào dùng:&lt;/strong&gt; Ranh giới quyết định là đa thức bậc thấp (\(q = 2, 3\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Linh hoạt, mô hình hóa tương tác giữa các features&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhược điểm:&lt;/strong&gt; Khó tune tham số \(q\) và \(c\), dễ overfitting với \(q\) lớn&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; Nhận dạng chữ viết tay, xử lý ảnh&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3) RBF (Radial Basis Function) Kernel - Kernel Gauss:&lt;/strong&gt;&lt;/p&gt;

\[K(x, z) = \exp\left(-\frac{\|x - z\|^2}{2\sigma^2}\right) = \exp(-\gamma \|x - z\|^2)\]

&lt;p&gt;với \(\gamma = \frac{1}{2\sigma^2} &amp;gt; 0\) là tham số bandwidth.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khi nào dùng:&lt;/strong&gt; &lt;strong&gt;Default choice&lt;/strong&gt; cho hầu hết bài toán - rất linh hoạt!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ánh xạ lên &lt;strong&gt;không gian vô hạn chiều&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;Có thể xấp xỉ mọi hàm liên tục (universal approximator)&lt;/li&gt;
      &lt;li&gt;Chỉ có 1 tham số \(\gamma\) cần tune&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhược điểm:&lt;/strong&gt; Dễ overfit nếu \(\gamma\) quá lớn&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; Nhận dạng khuôn mặt, phân loại gene expression&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4) Sigmoid Kernel:&lt;/strong&gt;&lt;/p&gt;

\[K(x, z) = \tanh(\alpha \langle x, z \rangle + c)\]

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khi nào dùng:&lt;/strong&gt; Mô phỏng neural network với một hidden layer&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Không phải lúc nào cũng positive definite (không đảm bảo hội tụ)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; Một số bài toán nhị phân đơn giản&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tổng kết so sánh 4 kernel:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Kernel&lt;/th&gt;
      &lt;th&gt;Linear&lt;/th&gt;
      &lt;th&gt;Polynomial&lt;/th&gt;
      &lt;th&gt;RBF&lt;/th&gt;
      &lt;th&gt;Sigmoid&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Công thức&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(x^Tz\)&lt;/td&gt;
      &lt;td&gt;\((\langle x,z\rangle + c)^q\)&lt;/td&gt;
      &lt;td&gt;\(\exp(-\gamma\|x-z\|^2)\)&lt;/td&gt;
      &lt;td&gt;\(\tanh(\alpha\langle x,z\rangle+c)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tham số&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;2 (\(q, c\))&lt;/td&gt;
      &lt;td&gt;1 (\(\gamma\))&lt;/td&gt;
      &lt;td&gt;2 (\(\alpha, c\))&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Không gian&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^d\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^{C(d+q,q)}\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^\infty\)&lt;/td&gt;
      &lt;td&gt;-&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dễ tune&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;✅ Rất dễ&lt;/td&gt;
      &lt;td&gt;⚠️ Khó&lt;/td&gt;
      &lt;td&gt;✅ Dễ&lt;/td&gt;
      &lt;td&gt;❌ Rất khó&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tốc độ&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;⚡ Nhanh nhất&lt;/td&gt;
      &lt;td&gt;⚡ Nhanh&lt;/td&gt;
      &lt;td&gt;🐌 Trung bình&lt;/td&gt;
      &lt;td&gt;🐌 Trung bình&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Khi nào dùng&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Baseline&lt;/td&gt;
      &lt;td&gt;Tương tác bậc thấp&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Default&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hiếm khi&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;87-điều-kiện-hợp-lệ-của-kernel---mercers-theorem&quot;&gt;8.7. Điều kiện hợp lệ của Kernel - Mercer’s Theorem&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi quan trọng:&lt;/strong&gt; Không phải hàm nào cũng có thể làm kernel! Điều kiện nào đảm bảo \(K\) là một kernel hợp lệ?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Định lý Mercer (Mercer’s Theorem):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Một hàm \(K: \mathcal{X} \times \mathcal{X} \to \mathbb{R}\) là một kernel hợp lệ (valid kernel) nếu và chỉ nếu nó là &lt;strong&gt;symmetric positive semi-definite&lt;/strong&gt;, tức là:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Đối xứng:&lt;/strong&gt; \(K(x, z) = K(z, x), \quad \forall x, z\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Positive semi-definite:&lt;/strong&gt; Với mọi \(n\) điểm \(\{x_1, \ldots, x_n\}\) và mọi \(a_1, \ldots, a_n \in \mathbb{R}\):
\(\sum_{i=1}^n \sum_{j=1}^n a_i a_j K(x_i, x_j) \geq 0\)&lt;/p&gt;

    &lt;p&gt;Hay tương đương: Ma trận Gram \(\mathbf{K}\) với \(K_{ij} = K(x_i, x_j)\) là &lt;strong&gt;positive semi-definite&lt;/strong&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa thực tiễn:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nếu \(K\) thỏa điều kiện Mercer → Tồn tại \(\phi\) sao cho \(K(x, z) = \langle \phi(x), \phi(z) \rangle\)&lt;/li&gt;
  &lt;li&gt;Bài toán tối ưu SVM là &lt;strong&gt;convex&lt;/strong&gt; và có nghiệm duy nhất&lt;/li&gt;
  &lt;li&gt;Nếu \(K\) vi phạm điều kiện → Bài toán có thể không hội tụ!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kiểm tra trong thực tế:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Các kernel chuẩn (linear, polynomial, RBF) đều thỏa Mercer&lt;/li&gt;
  &lt;li&gt;Nếu tự định nghĩa kernel mới, cần kiểm tra tính positive definite của ma trận \(\mathbf{K}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;88-xây-dựng-kernel-mới-từ-kernel-cũ&quot;&gt;8.8. Xây dựng Kernel mới từ Kernel cũ&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Tính chất đóng (Closure properties):&lt;/strong&gt; Nếu \(K_1\) và \(K_2\) là kernel hợp lệ, thì các phép toán sau cũng cho kernel hợp lệ:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Tổng:&lt;/strong&gt; \(K(x, z) = K_1(x, z) + K_2(x, z)\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nhân với hằng số dương:&lt;/strong&gt; \(K(x, z) = c \cdot K_1(x, z), \quad c &amp;gt; 0\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Tích:&lt;/strong&gt; \(K(x, z) = K_1(x, z) \cdot K_2(x, z)\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hàm của kernel:&lt;/strong&gt; \(K(x, z) = f(K_1(x, z))\) với \(f\) là hàm positive-preserving&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Tensor product:&lt;/strong&gt; \(K(x, z) = K_1(x_1, z_1) \cdot K_2(x_2, z_2)\) với \(x = (x_1, x_2)\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ ứng dụng:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kết hợp RBF với Linear để có cả tính tuyến tính và phi tuyến:&lt;/p&gt;

\[K(x, z) = \underbrace{\alpha \langle x, z \rangle}_{\text{Linear}} + \underbrace{\beta \exp(-\gamma \|x - z\|^2)}_{\text{RBF}}, \quad \alpha, \beta &amp;gt; 0\]

&lt;h3 id=&quot;89-kernel-svm-trong-thực-tế&quot;&gt;8.9. Kernel SVM trong thực tế&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Công thức dự đoán với Kernel:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sau khi huấn luyện, dự đoán cho điểm mới \(x\):&lt;/p&gt;

\[f(x) = \text{sign}\left(\sum_{i \in SV} w_i^\star y_i K(x, x_i) + \beta_0^\star\right)\]

&lt;p&gt;&lt;strong&gt;Lưu ý quan trọng:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Chỉ cần tính \(K(x, x_i)\) với &lt;strong&gt;support vectors&lt;/strong&gt; (rất ít so với toàn bộ dữ liệu)&lt;/li&gt;
  &lt;li&gt;Không cần biết \(\phi(x)\) là gì - chỉ cần \(K\)!&lt;/li&gt;
  &lt;li&gt;Tốc độ dự đoán: \(O(\#SV \cdot d)\) với \(d\) là chiều dữ liệu gốc&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lựa chọn kernel trong thực tế:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tình huống&lt;/th&gt;
      &lt;th&gt;Kernel đề xuất&lt;/th&gt;
      &lt;th&gt;Lý do&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Baseline / không biết gì&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;Nhanh, ít overfit, baseline tốt&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dữ liệu phi tuyến&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;RBF&lt;/td&gt;
      &lt;td&gt;Linh hoạt, universal approximator&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Số chiều cao (\(p \gg n\))&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;Tránh overfit trong không gian chiều cao&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Feature engineering sẵn&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;Đã có features tốt rồi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tương tác bậc thấp&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Polynomial (\(q=2,3\))&lt;/td&gt;
      &lt;td&gt;Model hóa tương tác rõ ràng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Computational budget thấp&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;Nhanh nhất&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Quy trình thực hành:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bắt đầu với Linear SVM&lt;/strong&gt;: Baseline nhanh&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử RBF SVM&lt;/strong&gt;: Nếu Linear không tốt&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Grid search cho \(C\) và \(\gamma\)&lt;/strong&gt;: Tune hyperparameters&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cross-validation&lt;/strong&gt;: Đánh giá độ tổng quát&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;810-minh-họa-tương-tác-so-sánh-các-kernel&quot;&gt;8.10. Minh họa tương tác: So sánh các Kernel&lt;/h3&gt;

&lt;div id=&quot;kernel-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;canvas id=&quot;kernelCanvas&quot; width=&quot;800&quot; height=&quot;500&quot; style=&quot;border: 1px solid #ccc; display: block; margin: 0 auto;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin-top: 15px;&quot;&gt;
        &lt;label for=&quot;kernelSelect&quot; style=&quot;font-size: 16px; font-weight: bold; margin-right: 10px;&quot;&gt;Chọn Kernel:&lt;/label&gt;
        &lt;select id=&quot;kernelSelect&quot; style=&quot;padding: 8px; font-size: 14px; border-radius: 5px; border: 1px solid #ccc;&quot;&gt;
            &lt;option value=&quot;linear&quot;&gt;Linear Kernel&lt;/option&gt;
            &lt;option value=&quot;poly2&quot;&gt;Polynomial (degree 2)&lt;/option&gt;
            &lt;option value=&quot;poly3&quot;&gt;Polynomial (degree 3)&lt;/option&gt;
            &lt;option value=&quot;rbf&quot; selected=&quot;&quot;&gt;RBF/Gaussian&lt;/option&gt;
        &lt;/select&gt;
        &lt;div style=&quot;margin-top: 15px;&quot; id=&quot;rbfGammaControl&quot;&gt;
            &lt;label for=&quot;gammaSlider&quot; style=&quot;font-size: 14px;&quot;&gt;Gamma (RBF): &lt;span id=&quot;gammaValue&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
            &lt;input type=&quot;range&quot; id=&quot;gammaSlider&quot; min=&quot;0.1&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;0.5&quot; style=&quot;width: 300px; margin-top: 5px;&quot; /&gt;
        &lt;/div&gt;
        &lt;p style=&quot;font-size: 14px; color: #666; margin-top: 10px;&quot;&gt;
            Dữ liệu phi tuyến (XOR-like pattern). Quan sát ranh giới quyết định với từng kernel.
        &lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    const canvas = document.getElementById(&apos;kernelCanvas&apos;);
    if (!canvas) return;
    
    const ctx = canvas.getContext(&apos;2d&apos;);
    const width = canvas.width;
    const height = canvas.height;
    
    // Dữ liệu XOR-like pattern
    const points = [
        // Class +1 (đỏ) - hai góc đối diện
        {x: 200, y: 150, label: 1}, {x: 220, y: 130, label: 1}, {x: 180, y: 170, label: 1},
        {x: 600, y: 350, label: 1}, {x: 620, y: 330, label: 1}, {x: 580, y: 370, label: 1},
        {x: 210, y: 160, label: 1}, {x: 590, y: 340, label: 1},
        
        // Class -1 (xanh) - hai góc đối diện còn lại
        {x: 600, y: 150, label: -1}, {x: 620, y: 130, label: -1}, {x: 580, y: 170, label: -1},
        {x: 200, y: 350, label: -1}, {x: 220, y: 330, label: -1}, {x: 180, y: 370, label: -1},
        {x: 610, y: 160, label: -1}, {x: 190, y: 340, label: -1}
    ];
    
    let currentKernel = &apos;rbf&apos;;
    let gamma = 0.5;
    
    // Kernel functions
    function kernel(x1, x2, type) {
        const dx = x1.x - x2.x;
        const dy = x1.y - x2.y;
        const dot = x1.x * x2.x + x1.y * x2.y;
        
        switch(type) {
            case &apos;linear&apos;:
                return dot;
            case &apos;poly2&apos;:
                return Math.pow(dot / 10000 + 1, 2);
            case &apos;poly3&apos;:
                return Math.pow(dot / 10000 + 1, 3);
            case &apos;rbf&apos;:
                return Math.exp(-gamma * (dx*dx + dy*dy) / 10000);
            default:
                return dot;
        }
    }
    
    // Simplified prediction
    function predict(testPoint) {
        let sum = 0;
        points.forEach(p =&gt; {
            const k = kernel(testPoint, p, currentKernel);
            sum += p.label * k;
        });
        return sum;
    }
    
    function draw() {
        ctx.clearRect(0, 0, width, height);
        
        // Vẽ background với decision boundary
        const gridSize = 5;
        for (let x = 0; x &lt; width; x += gridSize) {
            for (let y = 0; y &lt; height; y += gridSize) {
                const pred = predict({x, y});
                const alpha = Math.min(Math.abs(pred) * 0.02, 0.3);
                ctx.fillStyle = pred &gt; 0 ? `rgba(231, 76, 60, ${alpha})` : `rgba(46, 204, 113, ${alpha})`;
                ctx.fillRect(x, y, gridSize, gridSize);
            }
        }
        
        // Vẽ decision boundary (đường contour pred = 0)
        ctx.strokeStyle = &apos;#2c3e50&apos;;
        ctx.lineWidth = 3;
        ctx.beginPath();
        let firstPoint = true;
        
        for (let y = 50; y &lt; height - 50; y += 2) {
            for (let x = 50; x &lt; width - 50; x += 2) {
                const pred = predict({x, y});
                const predRight = predict({x: x+2, y});
                const predDown = predict({x, y: y+2});
                
                // Tìm zero crossing
                if (Math.sign(pred) !== Math.sign(predRight) || Math.sign(pred) !== Math.sign(predDown)) {
                    if (firstPoint) {
                        ctx.moveTo(x, y);
                        firstPoint = false;
                    } else {
                        ctx.lineTo(x, y);
                    }
                }
            }
        }
        ctx.stroke();
        
        // Vẽ data points
        points.forEach(p =&gt; {
            ctx.fillStyle = p.label === 1 ? &apos;#e74c3c&apos; : &apos;#2ecc71&apos;;
            ctx.beginPath();
            ctx.arc(p.x, p.y, 8, 0, 2 * Math.PI);
            ctx.fill();
            
            ctx.strokeStyle = &apos;#34495e&apos;;
            ctx.lineWidth = 2;
            ctx.stroke();
        });
        
        // Legend
        ctx.fillStyle = &apos;#34495e&apos;;
        ctx.font = &apos;bold 16px Arial&apos;;
        ctx.fillText(`Kernel: ${currentKernel.toUpperCase()}`, 20, 30);
        
        if (currentKernel === &apos;rbf&apos;) {
            ctx.fillText(`γ = ${gamma.toFixed(2)}`, 20, 55);
        }
    }
    
    // Event listeners
    const kernelSelect = document.getElementById(&apos;kernelSelect&apos;);
    const gammaSlider = document.getElementById(&apos;gammaSlider&apos;);
    const gammaValue = document.getElementById(&apos;gammaValue&apos;);
    const gammaControl = document.getElementById(&apos;rbfGammaControl&apos;);
    
    if (kernelSelect) {
        kernelSelect.addEventListener(&apos;change&apos;, function() {
            currentKernel = this.value;
            gammaControl.style.display = currentKernel === &apos;rbf&apos; ? &apos;block&apos; : &apos;none&apos;;
            draw();
        });
    }
    
    if (gammaSlider &amp;&amp; gammaValue) {
        gammaSlider.addEventListener(&apos;input&apos;, function() {
            gamma = parseFloat(this.value);
            gammaValue.textContent = gamma.toFixed(2);
            draw();
        });
    }
    
    // Initial draw
    draw();
})();
&lt;/script&gt;

&lt;h3 id=&quot;811-ưu-và-nhược-điểm-của-kernel-methods&quot;&gt;8.11. Ưu và nhược điểm của Kernel Methods&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;✅ Ưu điểm:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Không gian vô hạn chiều&lt;/strong&gt;: RBF kernel ánh xạ lên không gian vô hạn chiều mà vẫn tính toán nhanh&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không cần feature engineering&lt;/strong&gt;: Kernel tự động tạo features phi tuyến&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết vững chắc&lt;/strong&gt;: Mercer’s theorem đảm bảo tính chất toán học&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linh hoạt&lt;/strong&gt;: Có thể thiết kế kernel riêng cho từng domain (string kernel, graph kernel, …)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu quả với dữ liệu nhỏ/trung bình&lt;/strong&gt;: SVM+kernel hoạt động tốt với \(n &amp;lt; 10^5\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;❌ Nhược điểm cần lưu ý:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khó tune hyperparameters&lt;/strong&gt;: \(C\), \(\gamma\), … cần grid search tốn thời gian&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Training chậm với dữ liệu lớn&lt;/strong&gt;: Độ phức tạp \(O(n^2)\) đến \(O(n^3)\) cho \(n\) lớn&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưu trữ support vectors&lt;/strong&gt;: Cần lưu tất cả SV để dự đoán (có thể nhiều với dữ liệu phức tạp)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Black box&lt;/strong&gt;: Khó interpret hơn linear model&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không có probability estimate tự nhiên&lt;/strong&gt;: Cần Platt scaling để có xác suất&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;So sánh với Neural Networks:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tiêu chí&lt;/th&gt;
      &lt;th&gt;Kernel SVM&lt;/th&gt;
      &lt;th&gt;Neural Networks&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dữ liệu nhỏ (\(n &amp;lt; 10^4\))&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;✅ Tốt hơn&lt;/td&gt;
      &lt;td&gt;Có thể overfit&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dữ liệu lớn (\(n &amp;gt; 10^6\))&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;❌ Chậm&lt;/td&gt;
      &lt;td&gt;✅ Tốt hơn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Interpretability&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Trung bình (SV)&lt;/td&gt;
      &lt;td&gt;❌ Khó&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hyperparameter tuning&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;❌ Khó&lt;/td&gt;
      &lt;td&gt;❌ Rất khó&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Training time&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\)-\(O(n^3)\)&lt;/td&gt;
      &lt;td&gt;Phụ thuộc kiến trúc&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Lý thuyết&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;✅ Vững chắc&lt;/td&gt;
      &lt;td&gt;Đang phát triển&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;9-ví-dụ-chi-tiết&quot;&gt;9. Ví dụ Chi tiết&lt;/h2&gt;

&lt;h3 id=&quot;ví-dụ-1d-dữ-liệu-đơn-giản&quot;&gt;Ví dụ 1D: Dữ liệu đơn giản&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Dữ liệu:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Lớp \(+1\): \(x_1 = 3, x_2 = 4\)&lt;/li&gt;
  &lt;li&gt;Lớp \(-1\): \(x_3 = 1, x_4 = 2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;div id=&quot;svm1d-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;canvas id=&quot;svm1dCanvas&quot; width=&quot;700&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; display: block; margin: 0 auto;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin-top: 15px;&quot;&gt;
        &lt;div style=&quot;background: #f8f9fa; padding: 15px; border-radius: 8px; display: inline-block;&quot;&gt;
            &lt;p style=&quot;margin: 5px; font-size: 14px;&quot;&gt;&lt;strong&gt;Nghiệm tối ưu:&lt;/strong&gt;&lt;/p&gt;
            &lt;p style=&quot;margin: 5px; font-size: 14px;&quot;&gt;Siêu phẳng: $$x = 2.5$$&lt;/p&gt;
            &lt;p style=&quot;margin: 5px; font-size: 14px;&quot;&gt;$$\beta = 2, \quad \beta_0 = -5$$&lt;/p&gt;
            &lt;p style=&quot;margin: 5px; font-size: 14px;&quot;&gt;Margin width: $$\frac{2}{\lvert\beta\rvert} = 1$$&lt;/p&gt;
            &lt;p style=&quot;margin: 5px; font-size: 14px; color: #f39c12;&quot;&gt;&lt;strong&gt;Support Vectors:&lt;/strong&gt; $$x = 2$$ và $$x = 3$$&lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    const canvas = document.getElementById(&apos;svm1dCanvas&apos;);
    if (!canvas) return;
    
    const ctx = canvas.getContext(&apos;2d&apos;);
    const width = canvas.width;
    const height = canvas.height;
    
    // Dữ liệu
    const points = [
        {x: 3, label: 1, name: &apos;x₁&apos;},
        {x: 4, label: 1, name: &apos;x₂&apos;},
        {x: 1, label: -1, name: &apos;x₃&apos;},
        {x: 2, label: -1, name: &apos;x₄&apos;}
    ];
    
    // Nghiệm: β = 2, β₀ = -5
    // Hyperplane: 2x - 5 = 0 =&gt; x = 2.5
    const hyperplane = 2.5;
    const margin = 0.5; // margin = 1/β = 1/2
    
    // Scaling cho visualization
    const scale = 100;
    const offsetX = 150;
    const centerY = height / 2;
    
    function xToScreen(x) {
        return offsetX + x * scale;
    }
    
    function draw() {
        // Clear
        ctx.clearRect(0, 0, width, height);
        
        // Background
        ctx.fillStyle = &apos;#fafafa&apos;;
        ctx.fillRect(0, 0, width, height);
        
        // Vẽ trục x
        ctx.strokeStyle = &apos;#34495e&apos;;
        ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.moveTo(50, centerY);
        ctx.lineTo(width - 50, centerY);
        ctx.stroke();
        
        // Vẽ mũi tên trục x
        ctx.beginPath();
        ctx.moveTo(width - 50, centerY);
        ctx.lineTo(width - 60, centerY - 5);
        ctx.lineTo(width - 60, centerY + 5);
        ctx.closePath();
        ctx.fillStyle = &apos;#34495e&apos;;
        ctx.fill();
        
        // Vẽ các điểm trên trục
        for (let i = 0; i &lt;= 5; i++) {
            const x = xToScreen(i);
            ctx.strokeStyle = &apos;#95a5a6&apos;;
            ctx.lineWidth = 1;
            ctx.beginPath();
            ctx.moveTo(x, centerY - 5);
            ctx.lineTo(x, centerY + 5);
            ctx.stroke();
            
            ctx.fillStyle = &apos;#7f8c8d&apos;;
            ctx.font = &apos;12px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(i.toString(), x, centerY + 20);
        }
        
        // Vẽ margin boundaries (đường đứt nét)
        ctx.strokeStyle = &apos;#95a5a6&apos;;
        ctx.lineWidth = 2;
        ctx.setLineDash([5, 5]);
        
        // Left margin boundary (x = 2)
        const leftMargin = xToScreen(hyperplane - margin);
        ctx.beginPath();
        ctx.moveTo(leftMargin, 50);
        ctx.lineTo(leftMargin, height - 50);
        ctx.stroke();
        
        // Right margin boundary (x = 3)
        const rightMargin = xToScreen(hyperplane + margin);
        ctx.beginPath();
        ctx.moveTo(rightMargin, 50);
        ctx.lineTo(rightMargin, height - 50);
        ctx.stroke();
        
        ctx.setLineDash([]);
        
        // Vẽ margin zone (vùng màu nhạt)
        ctx.fillStyle = &apos;rgba(52, 152, 219, 0.1)&apos;;
        ctx.fillRect(leftMargin, 50, rightMargin - leftMargin, height - 100);
        
        // Vẽ hyperplane (đường đậm)
        const hyperX = xToScreen(hyperplane);
        ctx.strokeStyle = &apos;#2c3e50&apos;;
        ctx.lineWidth = 3;
        ctx.beginPath();
        ctx.moveTo(hyperX, 50);
        ctx.lineTo(hyperX, height - 50);
        ctx.stroke();
        
        // Label cho hyperplane
        ctx.fillStyle = &apos;#2c3e50&apos;;
        ctx.font = &apos;bold 14px Arial&apos;;
        ctx.textAlign = &apos;center&apos;;
        ctx.fillText(&apos;x = 2.5&apos;, hyperX, 40);
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;Siêu phẳng&apos;, hyperX, 25);
        
        // Labels cho margins
        ctx.fillStyle = &apos;#7f8c8d&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;x = 2&apos;, leftMargin, height - 35);
        ctx.fillText(&apos;x = 3&apos;, rightMargin, height - 35);
        
        // Vẽ data points
        points.forEach(p =&gt; {
            const x = xToScreen(p.x);
            
            // Điểm
            ctx.fillStyle = p.label === 1 ? &apos;#e74c3c&apos; : &apos;#2ecc71&apos;;
            ctx.beginPath();
            ctx.arc(x, centerY, 12, 0, 2 * Math.PI);
            ctx.fill();
            
            // Viền
            ctx.strokeStyle = &apos;#34495e&apos;;
            ctx.lineWidth = 2;
            ctx.stroke();
            
            // Highlight support vectors
            if (p.x === 2 || p.x === 3) {
                ctx.strokeStyle = &apos;#f39c12&apos;;
                ctx.lineWidth = 4;
                ctx.beginPath();
                ctx.arc(x, centerY, 18, 0, 2 * Math.PI);
                ctx.stroke();
            }
            
            // Label điểm
            ctx.fillStyle = &apos;#34495e&apos;;
            ctx.font = &apos;bold 14px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(p.name, x, centerY - 30);
            
            // Hiển thị class
            ctx.font = &apos;12px Arial&apos;;
            const classLabel = p.label === 1 ? &apos;y = +1&apos; : &apos;y = -1&apos;;
            ctx.fillStyle = p.label === 1 ? &apos;#e74c3c&apos; : &apos;#2ecc71&apos;;
            ctx.fillText(classLabel, x, centerY + 40);
        });
        
        // Vẽ khoảng cách margin (mũi tên hai chiều)
        const arrowY = 80;
        ctx.strokeStyle = &apos;#3498db&apos;;
        ctx.lineWidth = 2;
        
        // Đường kẻ
        ctx.beginPath();
        ctx.moveTo(leftMargin, arrowY);
        ctx.lineTo(hyperX, arrowY);
        ctx.stroke();
        
        ctx.beginPath();
        ctx.moveTo(hyperX, arrowY);
        ctx.lineTo(rightMargin, arrowY);
        ctx.stroke();
        
        // Mũi tên trái
        ctx.beginPath();
        ctx.moveTo(leftMargin + 5, arrowY - 5);
        ctx.lineTo(leftMargin, arrowY);
        ctx.lineTo(leftMargin + 5, arrowY + 5);
        ctx.stroke();
        
        // Mũi tên phải
        ctx.beginPath();
        ctx.moveTo(rightMargin - 5, arrowY - 5);
        ctx.lineTo(rightMargin, arrowY);
        ctx.lineTo(rightMargin - 5, arrowY + 5);
        ctx.stroke();
        
        // Label margin
        ctx.fillStyle = &apos;#3498db&apos;;
        ctx.font = &apos;bold 12px Arial&apos;;
        ctx.textAlign = &apos;center&apos;;
        ctx.fillText(&apos;margin = 0.5&apos;, (leftMargin + hyperX) / 2, arrowY - 10);
        ctx.fillText(&apos;margin = 0.5&apos;, (hyperX + rightMargin) / 2, arrowY - 10);
        
        // Legend
        const legendX = width - 180;
        const legendY = 100;
        
        // Class +1
        ctx.fillStyle = &apos;#e74c3c&apos;;
        ctx.beginPath();
        ctx.arc(legendX, legendY, 8, 0, 2 * Math.PI);
        ctx.fill();
        ctx.strokeStyle = &apos;#34495e&apos;;
        ctx.lineWidth = 2;
        ctx.stroke();
        ctx.fillStyle = &apos;#34495e&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.textAlign = &apos;left&apos;;
        ctx.fillText(&apos;Class +1&apos;, legendX + 15, legendY + 4);
        
        // Class -1
        ctx.fillStyle = &apos;#2ecc71&apos;;
        ctx.beginPath();
        ctx.arc(legendX, legendY + 25, 8, 0, 2 * Math.PI);
        ctx.fill();
        ctx.strokeStyle = &apos;#34495e&apos;;
        ctx.lineWidth = 2;
        ctx.stroke();
        ctx.fillStyle = &apos;#34495e&apos;;
        ctx.fillText(&apos;Class -1&apos;, legendX + 15, legendY + 29);
        
        // Support Vector
        ctx.strokeStyle = &apos;#f39c12&apos;;
        ctx.lineWidth = 3;
        ctx.beginPath();
        ctx.arc(legendX, legendY + 50, 8, 0, 2 * Math.PI);
        ctx.stroke();
        ctx.fillStyle = &apos;#34495e&apos;;
        ctx.fillText(&apos;Support Vector&apos;, legendX + 15, legendY + 54);
    }
    
    // Initial draw
    draw();
})();
&lt;/script&gt;

&lt;p&gt;&lt;strong&gt;Bài toán hard-margin:&lt;/strong&gt;
\(\begin{align}
\min_{\beta, \beta_0} \quad &amp;amp;\frac{1}{2}\beta^2 \\
\text{s.t.} \quad &amp;amp;3\beta + \beta_0 \geq 1, \quad 4\beta + \beta_0 \geq 1 \\
&amp;amp;-\beta - \beta_0 \geq 1, \quad -2\beta - \beta_0 \geq 1
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phân tích nghiệm:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Support vectors là các điểm gần nhất với siêu phẳng: \(x = 3\) (lớp +1) và \(x = 2\) (lớp -1).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện margin chặt:&lt;/strong&gt;
\(\begin{cases}
3\beta + \beta_0 = 1 \\
2\beta + \beta_0 = -1
\end{cases}
\Rightarrow \beta = 2, \quad \beta_0 = -5\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Siêu phẳng: \(2x - 5 = 0\) hay \(x = 2.5\) ✓&lt;/li&gt;
  &lt;li&gt;Margin width: \(\frac{2}{\lvert\beta\rvert} = \frac{2}{2} = 1\)&lt;/li&gt;
  &lt;li&gt;Support vectors: \(x = 2\) và \(x = 3\)&lt;/li&gt;
  &lt;li&gt;Các điểm \(x = 1\) và \(x = 4\) không phải support vectors vì chúng nằm xa margin hơn&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;9-bài-tập-thực-hành&quot;&gt;9. Bài tập Thực hành&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-phân-tích-support-vectors&quot;&gt;Bài tập 1: Phân tích Support Vectors&lt;/h3&gt;

&lt;p&gt;Cho nghiệm SVM với \(C = 1\):&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;w = (0, 0.5, 1, 1, 0, 1, 0.2)
ξ = (0, 0, 0.2, 0.8, 0, 1.5, 0)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Xác định support vectors&lt;br /&gt;
b) Phân loại theo vị trí (trên margin, trong margin, misclassified)&lt;br /&gt;
c) Giải thích \(w_1 = 0\) nhưng \(\xi_1 = 0\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Support vectors:** $$i \in \{2, 3, 4, 6, 7\}$$ (vì $$w_i &amp;gt; 0$$)

**b) Phân loại:**
- **Trên margin**: $$i = 2, 7$$ ($$\xi_i = 0$$, $$0 &amp;lt; w_i &amp;lt; C$$)
- **Trong margin**: $$i = 3, 4$$ ($$0 &amp;lt; \xi_i &amp;lt; 1$$, $$w_i = C$$)
- **Misclassified**: $$i = 6$$ ($$\xi_6 = 1.5 &amp;gt; 1$$, $$w_6 = C$$)

**c)** $$w_1 = 0$$ nghĩa là không phải SV. Từ CS: $$v_1 = C - 0 = 1 &amp;gt; 0$$ → $$\xi_1 = 0$$ ✓  
Điểm $$x_1$$ nằm xa margin, phân loại đúng.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-2-tính-toán-từ-kkt&quot;&gt;Bài tập 2: Tính toán từ KKT&lt;/h3&gt;

&lt;p&gt;Cho \(C = 2\), \(n = 3\), \(p = 2\):&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;x₁ = (0, 1), y₁ = +1, w₁ = 0.5
x₂ = (1, 0), y₂ = +1, w₂ = 0.5  
x₃ = (0, 0), y₃ = -1, w₃ = 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;\(\xi_1 = \xi_2 = 0\), \(\xi_3 = 0.2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Tính \(\beta\) từ stationarity&lt;br /&gt;
b) Tính \(\beta_0\) từ SV trên margin&lt;br /&gt;
c) Kiểm tra CS cho \(i=3\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a)** $$\beta = \sum w_i y_i x_i = 0.5(0,1) + 0.5(1,0) + 1 \cdot (-1)(0,0) = (0.5, 0.5)$$

**b)** Từ $$i=1$$: $$y_1(\beta^T x_1 + \beta_0) = 1$$  
$$1 \cdot (0.5 + \beta_0) = 1$$ → $$\beta_0 = 0.5$$

**c)** CS: $$w_3(1 - \xi_3 - y_3(\beta^T x_3 + \beta_0)) = 0$$  
$$y_3(\beta^T x_3 + \beta_0) = -1(0.5) = -0.5$$  
$$1(1 - 0.2 - (-0.5)) = 1.3 \neq 0$$ ✗  

**Kết luận:** CS vi phạm! Có lỗi trong dữ liệu.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;10-tóm-tắt-về-máy-vector-hỗ-trợ-svm&quot;&gt;10. Tóm tắt về Máy vector hỗ trợ (SVM)&lt;/h2&gt;

&lt;h3 id=&quot;101-từ-trực-giác-hình-học-đến-toán-học-chặt-chẽ&quot;&gt;10.1. Từ trực giác hình học đến toán học chặt chẽ&lt;/h3&gt;

&lt;p&gt;Các bước xây dựng mô hình SVM đi từ trực giác hình học đến bài toán tối ưu hóa hoàn chỉnh:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔹 Xuất phát điểm (Trực giác):&lt;/strong&gt; 
“Trong vô số đường phân chia, đường nào là &lt;em&gt;tốt nhất&lt;/em&gt;?” → Câu hỏi đơn giản nhưng sâu sắc&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔹 Bước 1 (Định lượng):&lt;/strong&gt; 
Margin = “vùng an toàn” xung quanh đường phân chia → Công cụ đo lường chất lượng khách quan&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔹 Bước 2 (Toán học hóa):&lt;/strong&gt; 
Maximize margin ⇔ Quadratic Programming → Bài toán tối ưu lồi, nghiệm duy nhất, giải được hiệu quả&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔹 Bước 3 (Đối mặt thực tế):&lt;/strong&gt; 
Hard-Margin → Soft-Margin với slack variables → Xử lý nhiễu, outliers, dữ liệu không tách được&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔹 Bước 3A (Góc nhìn Loss Function):&lt;/strong&gt;
Constrained optimization → Hinge Loss → Kết nối với machine learning, subgradient descent&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔹 Bước 4 (Mở rộng sức mạnh):&lt;/strong&gt; 
Primal → Dual Problem → Cánh cửa đến kernel trick và không gian vô hạn chiều&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔹 Bước 5 (Phi tuyến hóa):&lt;/strong&gt;
Linear boundary → Kernel Methods → Xử lý ranh giới quyết định phức tạp, phi tuyến&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔹 Đích đến:&lt;/strong&gt; 
Một framework hoàn chỉnh, vừa có nền tảng lý thuyết vững chắc, vừa mạnh mẽ trong thực tiễn, từ tuyến tính đến phi tuyến, từ optimization đến machine learning&lt;/p&gt;

&lt;h3 id=&quot;102-các-khái-niệm-then-chốt&quot;&gt;10.2. Các khái niệm then chốt&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khái niệm&lt;/th&gt;
      &lt;th&gt;Công thức&lt;/th&gt;
      &lt;th&gt;Ý nghĩa&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Margin&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\frac{2}{|\beta|}\)&lt;/td&gt;
      &lt;td&gt;Khoảng cách giữa 2 margin boundaries&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hard-Margin&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(y_i(\beta^T x_i + \beta_0) \geq 1\)&lt;/td&gt;
      &lt;td&gt;Tất cả điểm phải phân loại đúng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Soft-Margin&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(y_i(\beta^T x_i + \beta_0) \geq 1 - \xi_i\)&lt;/td&gt;
      &lt;td&gt;Cho phép vi phạm có kiểm soát&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Support Vectors&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(w_i &amp;gt; 0\)&lt;/td&gt;
      &lt;td&gt;Các điểm quyết định siêu phẳng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tham số C&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(C \sum \xi_i\)&lt;/td&gt;
      &lt;td&gt;Trọng số phạt vi phạm margin&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hinge Loss&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\([1 - yf]_+ = \max\\{0, 1-yf\\}\)&lt;/td&gt;
      &lt;td&gt;Loss function của SVM, lồi và sparse&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Kernel Function&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(K(x, z) = \langle \phi(x), \phi(z) \rangle\)&lt;/td&gt;
      &lt;td&gt;Ánh xạ ngầm lên không gian đặc trưng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;RBF Kernel&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(K(x, z) = \exp(-\gamma \|x - z\|^2)\)&lt;/td&gt;
      &lt;td&gt;Kernel phổ biến nhất, linh hoạt&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;103-ba-biến-thể-của-svm&quot;&gt;10.3. Ba biến thể của SVM&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hard-Margin SVM&lt;/strong&gt; (Dữ liệu tách được hoàn toàn)
    &lt;ul&gt;
      &lt;li&gt;Nghiệm tồn tại ⟺ dữ liệu linearly separable&lt;/li&gt;
      &lt;li&gt;Margin lớn nhất, không cho phép vi phạm&lt;/li&gt;
      &lt;li&gt;Nhạy cảm với outliers&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Soft-Margin SVM&lt;/strong&gt; (Dữ liệu thực tế)
    &lt;ul&gt;
      &lt;li&gt;Luôn có nghiệm&lt;/li&gt;
      &lt;li&gt;Trade-off: margin rộng vs. vi phạm ít (điều khiển bởi \(C\))&lt;/li&gt;
      &lt;li&gt;Robust với nhiễu&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kernel SVM&lt;/strong&gt; (Dữ liệu phi tuyến)
    &lt;ul&gt;
      &lt;li&gt;Sử dụng dual formulation&lt;/li&gt;
      &lt;li&gt;Ánh xạ ngầm lên không gian chiều cao&lt;/li&gt;
      &lt;li&gt;Không tăng độ phức tạp tính toán&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;104-kernel-methods-chìa-khóa-cho-phi-tuyến&quot;&gt;10.4. Kernel Methods: Chìa khóa cho phi tuyến&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Kỹ thuật hạt nhân (Kernel Trick)&lt;/strong&gt; cho phép mở rộng SVM từ bộ phân loại tuyến tính sang các ranh giới quyết định phi tuyến.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý tưởng cốt lõi:&lt;/strong&gt;&lt;/p&gt;

\[K(x, z) = \langle \phi(x), \phi(z) \rangle\]

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không cần tính \(\phi(x)\) tường minh&lt;/strong&gt;: Tính trực tiếp \(K(x, z)\) trong không gian gốc&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không gian vô hạn chiều&lt;/strong&gt;: RBF kernel ánh xạ lên \(\mathbb{R}^\infty\) mà vẫn tính được!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ phức tạp không đổi&lt;/strong&gt;: \(O(d)\) thay vì \(O(\text{dim}(\phi))\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bốn kernel phổ biến nhất:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Kernel&lt;/th&gt;
      &lt;th&gt;Công thức&lt;/th&gt;
      &lt;th&gt;Khi nào dùng&lt;/th&gt;
      &lt;th&gt;Hyperparameters&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Linear&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\langle x, z \rangle\)&lt;/td&gt;
      &lt;td&gt;Baseline, dữ liệu chiều cao&lt;/td&gt;
      &lt;td&gt;Không&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Polynomial&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\((\langle x, z \rangle + c)^q\)&lt;/td&gt;
      &lt;td&gt;Tương tác bậc thấp&lt;/td&gt;
      &lt;td&gt;\(q, c\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;RBF/Gaussian&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\exp(-\gamma \|x - z\|^2)\)&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Default choice&lt;/strong&gt;, rất linh hoạt&lt;/td&gt;
      &lt;td&gt;\(\gamma\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Sigmoid&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\tanh(\alpha \langle x, z \rangle + c)\)&lt;/td&gt;
      &lt;td&gt;Giống neural net&lt;/td&gt;
      &lt;td&gt;\(\alpha, c\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Định lý Mercer - Điều kiện hợp lệ:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kernel \(K\) hợp lệ ⟺ Ma trận Gram \(\mathbf{K}\) là &lt;strong&gt;symmetric positive semi-definite&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Đảm bảo: Bài toán SVM là convex, có nghiệm duy nhất&lt;/li&gt;
  &lt;li&gt;Tất cả kernel chuẩn đều thỏa mãn&lt;/li&gt;
  &lt;li&gt;Có thể xây dựng kernel mới từ kernel cũ (tổng, tích, …)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lựa chọn kernel trong thực tế:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bắt đầu với Linear SVM&lt;/strong&gt;: Nhanh, baseline tốt&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nếu không đủ → RBF SVM&lt;/strong&gt;: Linh hoạt, universal approximator&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Grid search \(C\) và \(\gamma\)&lt;/strong&gt;: Cross-validation để tune&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polynomial kernel&lt;/strong&gt;: Chỉ khi biết rõ tương tác bậc thấp&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;105-vai-trò-của-support-vectors&quot;&gt;10.5. Vai trò của Support Vectors&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Support vectors&lt;/strong&gt; là “xương sống” của SVM:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Chỉ &lt;strong&gt;support vectors&lt;/strong&gt; (điểm có \(w_i &amp;gt; 0\)) quyết định siêu phẳng&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Thường rất ít: $$&lt;/td&gt;
          &lt;td&gt;{i: w_i &amp;gt; 0}&lt;/td&gt;
          &lt;td&gt;\ll n$$&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;Các điểm khác có thể bỏ đi mà không ảnh hưởng đến mô hình&lt;/li&gt;
  &lt;li&gt;Công thức: \(\beta = \sum_{i: w_i &amp;gt; 0} w_i y_i x_i\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ba loại support vectors:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trên margin&lt;/strong&gt; (\(\xi_i = 0, 0 &amp;lt; w_i &amp;lt; C\)): Điểm lý tưởng, quan trọng nhất&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trong margin&lt;/strong&gt; (\(0 &amp;lt; \xi_i &amp;lt; 1, w_i = C\)): Vi phạm nhẹ, vẫn đúng&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Misclassified&lt;/strong&gt; (\(\xi_i &amp;gt; 1, w_i = C\)): Bị phân loại sai&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;106-primal-vs-dual-khi-nào-dùng-cái-nào&quot;&gt;10.6. Primal vs. Dual: Khi nào dùng cái nào?&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tiêu chí&lt;/th&gt;
      &lt;th&gt;Primal Form&lt;/th&gt;
      &lt;th&gt;Dual Form&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Số biến&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(p + 1 + n\)&lt;/td&gt;
      &lt;td&gt;\(n\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Khi nào tốt&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(p \ll n\) (ít features)&lt;/td&gt;
      &lt;td&gt;\(n \ll p\) (nhiều features)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Kernel trick&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Không&lt;/td&gt;
      &lt;td&gt;Có ✓&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Solver&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;CVXOPT, MOSEK&lt;/td&gt;
      &lt;td&gt;SMO, LIBSVM ✓&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Phổ biến&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Ít&lt;/td&gt;
      &lt;td&gt;Rất phổ biến ✓&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;107-ý-nghĩa-thực-tiễn&quot;&gt;10.7. Ý nghĩa thực tiễn&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Lý thuyết KKT&lt;/strong&gt; trong SVM không chỉ là công cụ để giải bài toán, mà còn giúp:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hiểu cấu trúc nghiệm:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại sao nghiệm sparse (chỉ có support vectors)?&lt;/li&gt;
      &lt;li&gt;Điểm nào quan trọng, điểm nào không?&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phát triển thuật toán:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;SMO (Sequential Minimal Optimization) dựa trên điều kiện KKT&lt;/li&gt;
      &lt;li&gt;Kiểm tra hội tụ: solution tối ưu ⟺ thỏa KKT&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích mô hình:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Sensitivity analysis: \(w_i\) cho biết mức độ “khó phân loại” của điểm \(i\)&lt;/li&gt;
      &lt;li&gt;Model interpretation: support vectors là các “hard cases”&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Debugging:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Kiểm tra tính đúng đắn của implementation&lt;/li&gt;
      &lt;li&gt;Phát hiện lỗi numerical (complementary slackness vi phạm)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;108-khi-nào-nên-dùng-svm&quot;&gt;10.8. Khi nào nên dùng SVM?&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;✅ SVM phù hợp khi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Dữ liệu có &lt;strong&gt;số chiều cao&lt;/strong&gt; (\(p &amp;gt; n\)): text classification, bioinformatics&lt;/li&gt;
  &lt;li&gt;Cần mô hình &lt;strong&gt;robust&lt;/strong&gt; với outliers&lt;/li&gt;
  &lt;li&gt;Có &lt;strong&gt;margin rõ ràng&lt;/strong&gt; giữa các classes&lt;/li&gt;
  &lt;li&gt;Cần &lt;strong&gt;interpretability&lt;/strong&gt; (thông qua support vectors)&lt;/li&gt;
  &lt;li&gt;Muốn dùng &lt;strong&gt;kernel trick&lt;/strong&gt; cho dữ liệu phi tuyến&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;❌ SVM không phù hợp khi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Dữ liệu &lt;strong&gt;rất lớn&lt;/strong&gt; (\(n &amp;gt; 10^6\)): training chậm&lt;/li&gt;
  &lt;li&gt;Cần &lt;strong&gt;probability estimates&lt;/strong&gt;: SVM output là distance, không phải xác suất&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multi-class&lt;/strong&gt; với nhiều classes (\(K &amp;gt; 10\)): cần one-vs-one hay one-vs-all&lt;/li&gt;
  &lt;li&gt;Dữ liệu có &lt;strong&gt;nhiều noise&lt;/strong&gt;: neural networks có thể tốt hơn&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;109-so-sánh-với-các-phương-pháp-khác&quot;&gt;10.9. So sánh với các phương pháp khác&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Ưu điểm&lt;/th&gt;
      &lt;th&gt;Nhược điểm&lt;/th&gt;
      &lt;th&gt;Khi nào dùng&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SVM&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Margin maximization, kernel trick, robust&lt;/td&gt;
      &lt;td&gt;Training chậm, khó tune \(C\)&lt;/td&gt;
      &lt;td&gt;Dữ liệu chiều cao, margin rõ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Logistic Regression&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Nhanh, probability output, dễ hiểu&lt;/td&gt;
      &lt;td&gt;Linear boundary, nhạy outliers&lt;/td&gt;
      &lt;td&gt;Baseline, cần probability&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Decision Tree&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Không cần normalize, dễ visualize&lt;/td&gt;
      &lt;td&gt;Overfitting, unstable&lt;/td&gt;
      &lt;td&gt;Tabular data, cần explain&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Neural Networks&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Flexible, powerful, scalable&lt;/td&gt;
      &lt;td&gt;Cần nhiều data, black box&lt;/td&gt;
      &lt;td&gt;Dữ liệu lớn, pattern phức tạp&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;1010-lời-khuyên-thực-hành&quot;&gt;10.10. Lời khuyên thực hành&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tiền xử lý dữ liệu:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Normalize/standardize&lt;/strong&gt; features: SVM nhạy cảm với scale&lt;/li&gt;
      &lt;li&gt;Xử lý missing values&lt;/li&gt;
      &lt;li&gt;Feature engineering quan trọng cho linear SVM&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn kernel:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Linear kernel&lt;/strong&gt;: Thử đầu tiên, nhanh, tránh overfit&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;RBF kernel&lt;/strong&gt;: Default choice cho non-linear&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Polynomial kernel&lt;/strong&gt;: Ít dùng, khó tune&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Custom kernel&lt;/strong&gt;: Khi có domain knowledge&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tuning hyperparameters:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(C\): Grid search [0.001, 0.01, 0.1, 1, 10, 100, 1000]&lt;/li&gt;
      &lt;li&gt;\(\gamma\) (cho RBF): Grid search [0.001, 0.01, 0.1, 1]&lt;/li&gt;
      &lt;li&gt;Dùng &lt;strong&gt;cross-validation&lt;/strong&gt; (5-fold hoặc 10-fold)&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Stratified CV&lt;/strong&gt; nếu classes imbalanced&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh giá mô hình:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Không chỉ nhìn accuracy&lt;/li&gt;
      &lt;li&gt;Xem &lt;strong&gt;confusion matrix&lt;/strong&gt;, precision, recall, F1-score&lt;/li&gt;
      &lt;li&gt;Phân tích &lt;strong&gt;support vectors&lt;/strong&gt;: Nhiều SV → có thể overfitting&lt;/li&gt;
      &lt;li&gt;Visualize decision boundary (nếu 2D/3D)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xử lý imbalanced data:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Dùng &lt;strong&gt;class_weight=’balanced’&lt;/strong&gt; trong scikit-learn&lt;/li&gt;
      &lt;li&gt;Hoặc tune \(C_+\) và \(C_-\) khác nhau cho mỗi class&lt;/li&gt;
      &lt;li&gt;SMOTE (Synthetic Minority Over-sampling)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 Tài liệu tham khảo&lt;/h2&gt;

&lt;h3 id=&quot;sách-và-giáo-trình&quot;&gt;Sách và giáo trình&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vapnik, V. N.&lt;/strong&gt; (1995). &lt;em&gt;The Nature of Statistical Learning Theory&lt;/em&gt;. Springer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 12.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hastie, T., et al.&lt;/strong&gt; (2009). &lt;em&gt;The Elements of Statistical Learning&lt;/em&gt; (2nd ed.). Springer. Chapter 12.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cristianini, N., &amp;amp; Shawe-Taylor, J.&lt;/strong&gt; (2000). &lt;em&gt;An Introduction to Support Vector Machines&lt;/em&gt;. Cambridge University Press.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bishop, C. M.&lt;/strong&gt; (2006). &lt;em&gt;Pattern Recognition and Machine Learning&lt;/em&gt;. Springer. Chapter 7.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;bài-viết-và-tutorial&quot;&gt;Bài viết và tutorial&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Machine Learning Cơ Bản&lt;/strong&gt; - &lt;a href=&quot;https://machinelearningcoban.com/2017/04/09/smv/&quot;&gt;Bài 19: Support Vector Machine&lt;/a&gt; - Vũ Hữu Tiệp&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;scikit-learn Documentation&lt;/strong&gt; - &lt;a href=&quot;https://scikit-learn.org/stable/modules/svm.html&quot;&gt;Support Vector Machines&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;LIBSVM&lt;/strong&gt; - &lt;a href=&quot;https://www.csie.ntu.edu.tw/~cjlin/libsvm/&quot;&gt;A Library for Support Vector Machines&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>12-03 Ví dụ thuật toán water-filling</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_03_Example_water_filling/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_03_Example_water_filling</id>
   <content type="html">&lt;p&gt;Giả sử bạn là kỹ sư viễn thông thiết kế bộ phát Wi-Fi / 5G dùng kỹ thuật ghép kênh phân chia tần số trực giao (OFDM). Bạn có tổng công suất phát cố định là \(1\) đơn vị để chia cho \(n\) kênh tần số song song, mỗi kênh có mức nhiễu nền \(\alpha_i &amp;gt; 0\) khác nhau — kênh sạch thì \(\alpha_i\) nhỏ, kênh nhiễu nặng thì \(\alpha_i\) lớn. Theo định lý dung lượng kênh của Claude Shannon, tổng tốc độ truyền dữ liệu tỷ lệ với \(\sum_{i=1}^n \log(\alpha_i + x_i)\). Câu hỏi là: &lt;strong&gt;bạn nên dồn công suất vào kênh sạch hay cứu giúp kênh nhiễu?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Khi đặt bút viết 4 điều kiện KKT cho bài toán lồi này, một bức tranh vật lý đẹp đến mức trở thành biểu tượng kinh điển của lý thuyết thông tin lập tức hiện ra: nghiệm tối ưu có dạng \(x_i^* = \max(0, w - \alpha_i)\)! Hãy tưởng tượng bạn xây một bể nước có đáy gồ ghề với độ cao từng bậc bằng mức nhiễu \(\alpha_i\), rồi đổ đúng \(1\) lít nước (tổng công suất) vào bể. Nước tự động dâng ngang đến một &lt;strong&gt;mực nước chung \(w = 1/\nu^*\)&lt;/strong&gt;: những kênh sạch (đáy thấp \(\alpha_i &amp;lt; w\)) nhận nhiều công suất nhất, còn những kênh quá nhiễu (đáy cao hơn mực nước \(\alpha_i \ge w\)) bị &lt;strong&gt;bỏ mặc hoàn toàn với \(x_i^* = 0\)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-bài-toán-đổ-nước-water-filling&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của bài toán Đổ nước (Water-Filling)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình tối ưu lồi từ định lý Shannon:&lt;/strong&gt; Cực tiểu hóa \(-\sum_{i=1}^n \log(\alpha_i + x_i)\) với ràng buộc \(x_i \ge 0\) (không âm) và \(\sum_{i=1}^n x_i = 1\) (ngân sách công suất). Vì \(-\log\) lồi và mọi ràng buộc tuyến tính, KKT là điều kiện cần và đủ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khử nhân tử \(u_i\) bằng điều kiện bù:&lt;/strong&gt; Từ điều kiện dừng \(-\frac{1}{\alpha_i + x_i^*} - u_i^* + \nu^* = 0\), ta suy ra \(u_i^* = \nu^* - \frac{1}{\alpha_i + x_i^*} \ge 0\). Kết hợp với điều kiện bù \(u_i^* x_i^* = 0\) lập tức chia các kênh làm hai nhóm:
    &lt;ul&gt;
      &lt;li&gt;Kênh được cấp nguồn (\(x_i^* &amp;gt; 0\)): \(u_i^* = 0 \implies \alpha_i + x_i^* = \frac{1}{\nu^*} = w\).&lt;/li&gt;
      &lt;li&gt;Kênh bị tắt (\(x_i^* = 0\)): \(u_i^* \ge 0 \implies \alpha_i \ge \frac{1}{\nu^*} = w\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Công thức nghiệm đóng theo mực nước \(w = 1/\nu^*\):&lt;/strong&gt; Gộp hai nhánh lại ta được đúng một công thức duy nhất: \(x_i^* = \max(0, w - \alpha_i)\), trong đó mực nước \(w\) là nghiệm duy nhất của phương trình đơn điệu tăng từng khúc \(\sum_{i=1}^n \max(0, w - \alpha_i) = 1\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán tìm mực nước \(O(n \log n)\):&lt;/strong&gt; Chỉ cần sắp xếp \(\alpha_1 \le \alpha_2 \le \dots \le \alpha_n\) tăng dần rồi thử dần số kênh hoạt động \(k = 1, 2, \dots, n\) (hoặc dùng tìm kiếm nhị phân theo \(w\)) là tìm ra nghiệm chính xác tuyệt đối!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-bài-toán-water-filling-cho-3-kênh-tần-số&quot;&gt;Giải thích: Tính tay bài toán Water-Filling cho 3 kênh tần số&lt;/h3&gt;

&lt;p&gt;Cho 3 kênh với mức nhiễu nền \(\alpha_1 = 0.2\) (rất sạch), \(\alpha_2 = 0.5\) (trung bình), \(\alpha_3 = 1.5\) (rất nhiễu), và tổng công suất \(\sum_{i=1}^3 x_i = 1.0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thử giả thiết cả 3 kênh đều được cấp nguồn (\(k = 3\)):&lt;/strong&gt;
\((w - 0.2) + (w - 0.5) + (w - 1.5) = 1.0 \implies 3w = 3.2 \implies w \approx 1.067.\)
Kiểm tra kênh 3: \(x_3 = w - 1.5 = 1.067 - 1.5 = -0.433 &amp;lt; 0\) (vi phạm \(x_3 \ge 0\)!) \(\implies\) kênh 3 quá nhiễu, chắc chắn \(x_3^* = 0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử giả thiết chỉ 2 kênh đầu hoạt động (\(k = 2\)):&lt;/strong&gt;
\((w - 0.2) + (w - 0.5) = 1.0 \implies 2w - 0.7 = 1.0 \implies w = 0.85.\)
Kiểm tra cả 3 kênh với mực nước \(w = 0.85\) (tức nhân tử đối ngẫu \(\nu^* = 1/0.85 \approx 1.176\)):
    &lt;ul&gt;
      &lt;li&gt;Kênh 1: \(x_1^* = \max(0, 0.85 - 0.2) = 0.65 &amp;gt; 0\) (\(\alpha_1 + x_1^* = 0.85\)).&lt;/li&gt;
      &lt;li&gt;Kênh 2: \(x_2^* = \max(0, 0.85 - 0.5) = 0.35 &amp;gt; 0\) (\(\alpha_2 + x_2^* = 0.85\)).&lt;/li&gt;
      &lt;li&gt;Kênh 3: \(x_3^* = \max(0, 0.85 - 1.5) = 0\) (vì đáy \(\alpha_3 = 1.5 &amp;gt; 0.85\) nằm cao hơn hẳn mặt nước!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng tổng công suất và nhân tử \(u_3^*\):&lt;/strong&gt;
Tổng \(0.65 + 0.35 + 0 = 1.0\) (chính xác!). Và \(u_3^* = \nu^* - \frac{1}{\alpha_3} = \frac{1}{0.85} - \frac{1}{1.5} \approx 0.510 &amp;gt; 0\) thỏa mãn cả 4 điều kiện KKT!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Xét bài toán tối ưu hóa lồi sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{x} &amp;amp;&amp;amp;{- \sum_{i=1}^n \log(\alpha_i + x_i)} \\\\
   &amp;amp;\text{với điều kiện} &amp;amp;&amp;amp;{x \succeq 0, 1^Tx = 1},\\\\
&amp;amp;\text{trong đó } \alpha_i &amp;gt; 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán này xuất hiện trong lý thuyết thông tin, gắn với việc phân bổ công suất cho \(n\) kênh truyền thông. Biến \(x_i\) biểu diễn công suất phát phân bổ cho kênh thứ \(i\), còn \(\log(\alpha_i + x_i)\) biểu diễn dung lượng hay tốc độ truyền của kênh đó. Như vậy, mục tiêu là phân bổ tổng công suất cố định vào các kênh sao cho tổng tốc độ truyền đạt cực đại [1].&lt;/p&gt;

&lt;p&gt;Gọi \(\lambda^\star \in \mathbb{R}^n\) và \(\nu^\star \in \mathbb{R}\) lần lượt là các nhân tử Lagrange ứng với ràng buộc bất đẳng thức \(x^\star \succeq 0\) và ràng buộc đẳng thức \(1^Tx^\star = 1\). Các điều kiện KKT của bài toán là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^\star \succeq 0, \\\\
1^Tx^\star = 1, \\\\
\lambda^\star \succeq 0, \\\\
\lambda_i^\star x_i^\star = 0, \text{    } i = 1, \dots, n, \\\\
-1 / (\alpha_i + x_i^\star) - \lambda_i^\star + \nu^\star = 0,  \text{    } i= 1, \dots, n.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ hệ điều kiện KKT trên, ta có thể tìm \(x^\star, \lambda^\star, \nu^\star\) theo dạng giải tích. Trước hết, khử \(\lambda^\star\) bằng cách coi nó như biến phụ không âm (\(\lambda_i^\star = \nu^\star - 1/(\alpha_i + x_i^\star) \ge 0\)):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^\star \succeq 0, \\\\
1^Tx^\star = 1, \\\\
x_i^\star(\nu^\star - 1 / (\alpha_i + x_i^\star)) = 0, \text{    } i = 1, \dots, n, \\\\
\nu^\star \ge 1/(\alpha_i + x_i^\star),  \text{    } i= 1, \dots, n.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Kết hợp điều kiện dừng và điều kiện bù yếu, ta thu được biểu thức nghiệm:&lt;/p&gt;

&lt;blockquote&gt;
\[x_i^\star = 
\begin{cases}
1 / \nu^\star - \alpha_i &amp;amp;\nu^\star &amp;lt; 1/\alpha_i \ \\\\
0 &amp;amp;\nu^\star \ge 1/\alpha_i\\\\
\end{cases}
= \max\{0, 1/\nu^\star - \alpha_i \}, \quad i = 1, \dots, n.\]
&lt;/blockquote&gt;

&lt;p&gt;Theo ràng buộc \(1^T x^\star = 1\), tổng các thành phần \(x_i^\star\) (\(i = 1, \dots, n\)) bằng \(1\):&lt;/p&gt;

&lt;blockquote&gt;
\[\sum_{i=1}^n \max\{0, 1/\nu^\star - \alpha_i \} = 1.\]
&lt;/blockquote&gt;

&lt;p&gt;Vế trái là một hàm tuyến tính từng khúc và tăng theo \(1/\nu^\star\), nên với các giá trị \(\alpha_i\) cố định, phương trình trên có nghiệm duy nhất cho \(1/\nu^\star\).&lt;/p&gt;

&lt;p&gt;Phương pháp giải này được gọi là &lt;strong&gt;water-filling (đổ nước)&lt;/strong&gt;. Nếu xem \(\alpha_i\) là độ cao đáy của ngăn thứ \(i\), bài toán tương đương với việc đổ nước vào các ngăn cho đến khi mực nước chung đạt mức \(1/\nu^\star\) và tổng lượng nước đổ vào bằng \(1\), như minh họa trong hình dưới đây.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter12/water-fill.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Minh họa thuật toán water-filling [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;kkt-qua-ví-dụ-đổ-nước-trong-khoảng-3-phút&quot;&gt;KKT qua ví dụ đổ nước trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/kkt-water-filling_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Giải bài đổ nước với α = (0,1; 0,4; 0,8; 1,2) bằng bốn điều kiện KKT, đọc ý nghĩa của λ, và ba cách đoán sai bị KKT loại.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>12-02 Ví dụ bài toán bậc hai với ràng buộc đẳng thức</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_02_Example_quadratic_with_equality_constraints/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_02_Example_quadratic_with_equality_constraints</id>
   <content type="html">&lt;p&gt;Nếu có một hệ phương trình xuất hiện ở khắp mọi nơi trong kỹ thuật — từ tối ưu hóa danh mục đầu tư Markowitz, phương pháp Newton có ràng buộc đẳng thức (Chương 14), bộ lọc Kalman, đến cơ học kết cấu phần tử hữu hạn — thì đó chính là &lt;strong&gt;hệ phương trình khối KKT (KKT Matrix System)&lt;/strong&gt; của bài toán quy hoạch bậc hai có ràng buộc đẳng thức!&lt;/p&gt;

&lt;p&gt;Vẻ đẹp phi thường của ví dụ đầu tiên này nằm ở chỗ: vì bài toán chỉ có ràng buộc đẳng thức \(Ax = b\) (không có bất đẳng thức \(h_i \le 0\)), điều kiện bù và ràng buộc dấu \(u \ge 0\) biến mất hoàn toàn! Hai điều kiện KKT còn lại (dừng \(Px^* + q + A^T v^* = 0\) và khả thi \(Ax^* = b\)) ghép khít vào nhau thành &lt;strong&gt;một hệ phương trình tuyến tính duy nhất&lt;/strong&gt; dạng ma trận khối đối xứng. Giải một bài toán tối ưu bậc hai có ràng buộc quy về đúng một phép giải hệ tuyến tính!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-qp-ràng-buộc-đẳng-thức-và-hệ-khối-kkt&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của QP ràng buộc đẳng thức và hệ khối KKT&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán QP ràng buộc đẳng thức:&lt;/strong&gt; \(\min_x \frac{1}{2}x^T P x + q^T x + r\) sao cho \(Ax = b\) với \(P \succeq 0\) (lồi). Vì mọi ràng buộc đều affine, bài toán lồi tự động thỏa điều kiện Slater tinh gọn nên KKT là điều kiện &lt;strong&gt;cần và đủ&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ phương trình khối KKT (Saddle-point System):&lt;/strong&gt;
\(\begin{bmatrix} P &amp;amp; A^T \\ A &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x^* \\ v^* \end{bmatrix} = \begin{bmatrix} -q \\ b \end{bmatrix}.\)
Chú ý rằng ma trận KKT này đối xứng nhưng &lt;strong&gt;không xác định dương&lt;/strong&gt; (nó là ma trận bất định — indefinite — có cả trị riêng dương và âm do khối \(0\) ở góc dưới phải).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện khả nghịch và phương pháp phần bù Schur (Schur Complement):&lt;/strong&gt; Khi \(P \succ 0\) và \(A\) có hạng hàng đầy đủ, ma trận khối KKT khả nghịch duy nhất! Ta có thể khử \(x^* = -P^{-1}(q + A^T v^*)\) rồi thay vào \(Ax^* = b\) để giải hệ nhỏ hơn \((A P^{-1} A^T) v^* = -(A P^{-1} q + b)\) với ma trận Schur \(A P^{-1} A^T \succ 0\) xác định dương!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-hệ-ma-trận-khối-kkt-cho-qp-2-biến&quot;&gt;Giải thích: Giải tay hệ ma trận khối KKT cho QP 2 biến&lt;/h3&gt;

&lt;p&gt;Giải bài toán cực tiểu hóa năng lượng có ràng buộc:
\(\min_{x_1, x_2} \; x_1^2 + 2x_2^2 \quad \text{s.t.} \quad x_1 + x_2 = 3.\)
Ở đây \(f(x) = \frac{1}{2} x^T \begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 4 \end{pmatrix} x\) nên \(P = \begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 4 \end{pmatrix} \succ 0\), \(q = \begin{pmatrix} 0 \\ 0 \end{pmatrix}\), \(A = \begin{pmatrix} 1 &amp;amp; 1 \end{pmatrix}\), \(b = 3\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập hệ phương trình khối KKT \(3 \times 3\):&lt;/strong&gt;
\(\begin{pmatrix} 2 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 4 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{pmatrix} \begin{pmatrix} x_1^* \\ x_2^* \\ v^* \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ 3 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bằng phép khử Schur (khử \(x_1^*, x_2^*\) theo \(v^*\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hàng 1: \(2x_1^* + v^* = 0 \implies x_1^* = -\frac{v^*}{2}\).&lt;/li&gt;
      &lt;li&gt;Hàng 2: \(4x_2^* + v^* = 0 \implies x_2^* = -\frac{v^*}{4}\).&lt;/li&gt;
      &lt;li&gt;Thay vào hàng 3 (\(x_1^* + x_2^* = 3\)):
\(-\frac{v^*}{2} - \frac{v^*}{4} = 3 \implies -\frac{3}{4} v^* = 3 \implies v^* = -4.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thay ngược lại tìm \(x^*\) và kiểm chứng:&lt;/strong&gt;
\(x_1^* = -\frac{-4}{2} = 2, \qquad x_2^* = -\frac{-4}{4} = 1.\)
Kiểm tra: \(x_1^* + x_2^* = 3\), giá trị tối ưu \(2^2 + 2(1)^2 = 6\). Nhận xét vật lý thú vị: biến \(x_1\) có độ cứng \(2\) (nhẹ hơn một nửa so với \(x_2\) có độ cứng \(4\)) nên gánh gấp đôi tải trọng (\(2\) so với \(1\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Xét một &lt;a href=&quot;&quot;&gt;bài toán quy hoạch bậc hai&lt;/a&gt; chỉ có các ràng buộc đẳng thức như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{x} &amp;amp;&amp;amp;{(1/2)x^T P x + q^T x + r} \\\\
   &amp;amp;\text{với điều kiện} &amp;amp;&amp;amp;{Ax = b},\\\\
&amp;amp;\text{trong đó } &amp;amp;&amp;amp;P \in \mathbb{S}_{+}^n \text{ và } A \in \mathbb{R}^{\text{p x n}}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán này là bài toán lồi và không có ràng buộc bất đẳng thức, do đó thỏa mãn điều kiện Slater (tức tính đối ngẫu mạnh được đảm bảo). Nếu \(x^\star, \nu^\star\) là cặp nghiệm tối ưu nguyên thủy và đối ngẫu, theo các điều kiện KKT chúng phải thỏa mãn [1]:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt; \(Px^\star + q + A^T\nu^\star = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù yếu:&lt;/strong&gt; Không xuất hiện do bài toán không có ràng buộc bất đẳng thức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính khả thi nguyên thủy và đối ngẫu:&lt;/strong&gt; \(Ax^\star = b\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hệ điều kiện trên có thể viết gọn dưới dạng phương trình ma trận khối, trong đó ma trận hệ số được gọi là &lt;strong&gt;ma trận KKT&lt;/strong&gt; [3]:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{bmatrix}
    P       &amp;amp; A^T  \\\\
    A       &amp;amp; 0  \\\\
\end{bmatrix}
\begin{bmatrix}
    x^\star  \\\\
    \nu^\star  \\\\
\end{bmatrix}
=
\begin{bmatrix}
    -q  \\\\
    b  \\\\
\end{bmatrix}\]
&lt;/blockquote&gt;

&lt;p&gt;Giải hệ phương trình tuyến tính này cho ta đồng thời nghiệm nguyên thủy \(x^\star\) và nghiệm đối ngẫu \(\nu^\star\).&lt;/p&gt;

&lt;p&gt;Một điểm đáng chú ý là bài toán trên cũng tương ứng với việc tính bước Newton cho bài toán tối ưu có ràng buộc đẳng thức [3]. Cụ thể, với bài toán \(\min_x f(x) \text{ với điều kiện } Ax = b\), nếu đặt \(P, q, r\) theo công thức dưới đây thì hàm mục tiêu của bài toán quy hoạch bậc hai chính là khai triển Taylor bậc hai của \(f\) tại điểm lặp trước đó \(x^{(k-1)}\):&lt;br /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(P = \nabla^2 f(x^{(k-1)})\), \(q = \nabla f(x^{(k-1)})\), \(r = f(x^{(k-1)})\)&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>12-01 Điều kiện Karush-Kuhn-Tucker</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_01_Karush_Kuhn_Tucker_conditions/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_01_Karush_Kuhn_Tucker_conditions</id>
   <content type="html">&lt;p&gt;Nhiều sinh viên học thuộc lòng 4 dòng điều kiện KKT rất nhanh, nhưng lại thường lúng túng trước câu hỏi sắc bén nhất của bài học này: &lt;strong&gt;khi nào KKT là điều kiện &lt;em&gt;cần&lt;/em&gt;, và khi nào KKT là điều kiện &lt;em&gt;đủ&lt;/em&gt;?&lt;/strong&gt; Nếu bạn giải hệ phương trình KKT cho một bài toán không lồi, liệu nghiệm tìm ra có chắc chắn là cực tiểu toàn cục không? Ngược lại, nếu một bài toán lồi có nghiệm tối ưu \(x^*\), liệu \(x^*\) có &lt;em&gt;luôn luôn&lt;/em&gt; thỏa KKT không?&lt;/p&gt;

&lt;p&gt;Bài học này giải mã trọn vẹn mối quan hệ logic hai chiều ấy chỉ bằng đúng một chuỗi bất đẳng thức 4 dòng nối từ Chương 11:
\(f(x^*) = g(u^*, v^*) = \inf_x L(x, u^*, v^*) \le L(x^*, u^*, v^*) = f(x^*) + \sum u_i^* h_i(x^*) + \sum v_j^* l_j(x^*) \le f(x^*).\)
Vì hai đầu chuỗi đều là \(f(x^*)\), mọi dấu \(\le\) ở giữa &lt;strong&gt;bắt buộc trở thành dấu bằng&lt;/strong&gt;! Dấu bằng thứ nhất cho ta &lt;em&gt;điều kiện dừng&lt;/em&gt; (\(x^*\) cực tiểu hóa \(L\)); dấu bằng thứ hai cho ta &lt;em&gt;điều kiện bù&lt;/em&gt; (\(u_i^* h_i(x^*) = 0\))! Không có phép thuật nào cả — toàn bộ hệ KKT bật ra chỉ từ đúng một chuỗi bất đẳng thức kẹp!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-logic-về-điều-kiện-kkt&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột logic về điều kiện KKT&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện cần (Necessity — Cần đối ngẫu mạnh!):&lt;/strong&gt; Cho bài toán bất kỳ (kể cả không lồi) có nghiệm tối ưu gốc \(x^*\) và đối ngẫu \((u^*, v^*)\) thỏa &lt;strong&gt;đối ngẫu mạnh&lt;/strong&gt; (\(f^* = g^*\)), thì \((x^*, u^*, v^*)\) &lt;em&gt;bắt buộc&lt;/em&gt; thỏa mãn cả 4 điều kiện KKT. (Lưu ý: nếu bài toán lồi &lt;em&gt;không&lt;/em&gt; có đối ngẫu mạnh vì vi phạm Slater, nghiệm tối ưu có thể không thỏa KKT!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện đủ (Sufficiency — Cần tính lồi!):&lt;/strong&gt; Nếu bài toán là &lt;strong&gt;bài toán lồi&lt;/strong&gt; (\(f, h_i\) lồi và \(l_j\) affine), thì bất kỳ bộ \((x^*, u^*, v^*)\) nào thỏa 4 điều kiện KKT đều &lt;strong&gt;chắc chắn&lt;/strong&gt; là cặp nghiệm tối ưu toàn cục gốc–đối ngẫu với khoảng cách đối ngẫu bằng \(0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hợp nhất cho bài toán lồi thỏa Slater:&lt;/strong&gt; Khi bài toán lồi và thỏa điều kiện Slater, KKT trở thành &lt;strong&gt;điều kiện cần và đủ (\(\Longleftrightarrow\))&lt;/strong&gt; để đặc trưng toàn bộ tập nghiệm tối ưu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý quan trọng về bài toán không lồi:&lt;/strong&gt; Với bài toán không lồi, một điểm thỏa KKT chỉ là &lt;em&gt;ứng viên dừng&lt;/em&gt; — nó có thể là cực tiểu địa phương, điểm yên ngựa, thậm chí cực đại địa phương!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-bài-toán-2-biến-có-ràng-buộc-bất-đẳng-thức-bằng-hệ-kkt&quot;&gt;Giải thích: Giải tay bài toán 2 biến có ràng buộc bất đẳng thức bằng hệ KKT&lt;/h3&gt;

&lt;p&gt;Tìm nghiệm tối ưu toàn cục của bài toán lồi:
\(\min_{x_1, x_2 \in \mathbb{R}} \; f(x_1, x_2) = x_1^2 + x_2^2 \quad \text{s.t.} \quad h(x_1, x_2) = 4 - x_1 - x_2 \le 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Viết hệ 4 điều kiện KKT với nhân tử \(u \ge 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Dừng: \(\begin{cases} 2x_1 - u = 0 \\ 2x_2 - u = 0 \end{cases} \implies x_1 = x_2 = \frac{u}{2}\).&lt;/li&gt;
      &lt;li&gt;Khả thi gốc: \(4 - x_1 - x_2 \le 0\).&lt;/li&gt;
      &lt;li&gt;Khả thi đối ngẫu: \(u \ge 0\).&lt;/li&gt;
      &lt;li&gt;Bù: \(u(4 - x_1 - x_2) = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xét 2 trường hợp của điều kiện bù \(u(4 - x_1 - x_2) = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Trường hợp 1 (\(u = 0\) — ràng buộc lỏng):&lt;/em&gt; Từ điều kiện dừng suy ra \(x_1 = x_2 = 0\). Kiểm tra khả thi gốc: \(4 - 0 - 0 = 4 &amp;gt; 0\) (vi phạm!) \(\implies\) loại!&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Trường hợp 2 (\(u &amp;gt; 0\) — ràng buộc chặt):&lt;/em&gt; Buộc có \(4 - x_1 - x_2 = 0\). Thay \(x_1 = x_2 = u/2\) vào:
\(4 - \frac{u}{2} - \frac{u}{2} = 0 \implies u^* = 4 &amp;gt; 0 \implies x_1^* = 2, \; x_2^* = 2.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chốt tối ưu toàn cục nhờ Điều kiện đủ:&lt;/strong&gt; Vì \(f(x) = x_1^2 + x_2^2\) lồi và \(h(x)\) tuyến tính, bộ \((x^*, u^*) = ((2, 2), 4)\) thỏa đủ 4 điều kiện KKT chắc chắn là &lt;strong&gt;nghiệm tối ưu toàn cục duy nhất&lt;/strong&gt; với \(f^* = 8\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Xét bài toán tối ưu hóa tổng quát sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{x} &amp;amp;&amp;amp;{f(x)} \\\\
   &amp;amp;\text{với điều kiện } &amp;amp;&amp;amp;{h_i(x) \le 0, \text{ } i=1,\dots,m} \\\\
   &amp;amp; &amp;amp;&amp;amp;{l_j(x) = 0, \text{ } j=1,\dots,r}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Các điều kiện Karush–Kuhn–Tucker (KKT)&lt;/strong&gt; (gọi tắt là &lt;strong&gt;điều kiện KKT&lt;/strong&gt;) bao gồm bốn nhóm điều kiện sau [3]:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(0 \in \partial \big( f(x) + \sum_{i=1}^{m} \lambda_i h_i(x) + \sum_{j=1}^{r} \nu_j l_j(x) \big)\) (&lt;strong&gt;Điều kiện dừng&lt;/strong&gt;): Khi cố định \(\lambda, \nu\), dưới vi phân (subdifferential) của hàm Lagrangian theo \(x\) chứa vector \(0\).&lt;/li&gt;
  &lt;li&gt;\(\lambda_i \cdot h_i(x) = 0 \text{ với mọi } i\) (&lt;strong&gt;Điều kiện bù yếu&lt;/strong&gt;): Với mỗi \(i\), ít nhất một trong hai đại lượng \(\lambda_i\) và \(h_i(x)\) bằng \(0\).&lt;/li&gt;
  &lt;li&gt;\(h_i(x) \le 0, l_j(x) = 0 \text{ với mọi } i, j\) (&lt;strong&gt;Tính khả thi nguyên thủy&lt;/strong&gt;): Điểm \(x\) thỏa mãn toàn bộ các ràng buộc của bài toán nguyên thủy.&lt;/li&gt;
  &lt;li&gt;\(\lambda_i \ge 0 \text{ với mọi } i\) (&lt;strong&gt;Tính khả thi đối ngẫu&lt;/strong&gt;): Các nhân tử tương ứng với ràng buộc bất đẳng thức thỏa mãn điều kiện không âm của bài toán đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;điều-kiện-đủ&quot;&gt;Điều kiện đủ&lt;/h2&gt;

&lt;p&gt;Đối với bài toán nguyên thủy lồi, nếu tồn tại bộ \((x^\star, \lambda^\star, \nu^\star)\) thỏa mãn các điều kiện KKT, thì biến đổi sau cho thấy \((x^\star, \lambda^\star, \nu^\star)\) là cặp nghiệm tối ưu nguyên thủy và đối ngẫu với khoảng cách đối ngẫu bằng không:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   g(\lambda^\star, \nu^\star) &amp;amp;= \min_x L(x, \lambda^\star, \nu^\star) \\\\
                               &amp;amp;= L(x^\star, \lambda^\star, \nu^\star) \\\\
                               &amp;amp;= f(x^\star) + \sum_{i=1}^m \lambda_i^\star h_i(x^\star) + \sum_{j=1}^r \nu_j^\star l_j(x^\star) \\\\
                               &amp;amp;= f(x^\star)
\end{align}\]
&lt;/blockquote&gt;

&lt;ol&gt;
  &lt;li&gt;Hàm \(L(x,\lambda^\star,\nu^\star) = f(x) + \sum_{i=1}^{m} \lambda_i^\star h_i(x) + \sum_{j=1}^{r} \nu_j^\star l_j(x)\) là hàm lồi theo \(x\) (vì là tổng các hàm lồi với hệ số không âm đối với \(h_i\) và các hàm affine \(l_j\)).&lt;/li&gt;
  &lt;li&gt;Vì \(0 \in \partial \big( f(x^\star) + \sum_{i=1}^{m} \lambda_i^\star h_i(x^\star) + \sum_{j=1}^{r} \nu_j^\star l_j(x^\star) \big)\), nên \(\min_x L(x, \lambda^\star, \nu^\star) = L(x^\star, \lambda^\star, \nu^\star)\).&lt;/li&gt;
  &lt;li&gt;Nhờ điều kiện bù yếu và tính khả thi nguyên thủy, ta có \(f(x^\star) + \sum_{i=1}^m \lambda_i^\star h_i(x^\star) + \sum_{j=1}^r \nu_j^\star l_j(x^\star) = f(x^\star)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;điều-kiện-cần&quot;&gt;Điều kiện cần&lt;/h2&gt;

&lt;p&gt;Ngược lại, nếu \((x^\star, \lambda^\star, \nu^\star)\) là nghiệm tối ưu nguyên thủy và đối ngẫu với khoảng cách đối ngẫu bằng không (chẳng hạn khi bài toán thỏa mãn điều kiện Slater), thì mọi bất đẳng thức trong chuỗi dưới đây đều trở thành đẳng thức, suy ra \((x^\star, \lambda^\star, \nu^\star)\) thỏa mãn các điều kiện KKT:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   f(x^\star) &amp;amp;= g(\lambda^\star, \nu^\star) \\\\
                  &amp;amp;= \min_x  \big( f(x) + \sum_{i=1}^{m} \lambda_i^\star h_i(x) + \sum_{j=1}^{r} \nu_j^\star l_j(x) \big) \\\\
                  &amp;amp;\le f(x^\star) + \sum_{i=1}^m \lambda_i^\star h_i(x^\star) + \sum_{j=1}^r \nu_j^\star l_j(x^\star) \\\\
                  &amp;amp;\le f(x^\star)
\end{align}\]
&lt;/blockquote&gt;

&lt;ol&gt;
  &lt;li&gt;Đẳng thức \(f(x^\star) = g(\lambda^\star, \nu^\star)\) thể hiện khoảng cách đối ngẫu bằng không.&lt;/li&gt;
  &lt;li&gt;Để có \(f(x^\star) + \sum_{i=1}^m \underbrace{\lambda_i^\star h_i(x^\star)}_{0} + \sum_{j=1}^r \underbrace{\nu_j^\star l_j(x^\star)}_{0} = f(x^\star)\), điều kiện bù yếu và tính khả thi nguyên thủy phải được thỏa mãn.&lt;/li&gt;
  &lt;li&gt;Khi đẳng thức này đúng, mọi bất đẳng thức trong chuỗi suy dẫn trên đều là đẳng thức; đặc biệt \(x^\star\) đạt cực tiểu của \(L(x, \lambda^\star, \nu^\star)\), dẫn đến điều kiện dừng.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;tổng-kết&quot;&gt;Tổng kết&lt;/h2&gt;

&lt;p&gt;Tóm lại, đối với bài toán tối ưu lồi, các điều kiện KKT là:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Điều kiện đủ cho cặp nghiệm tối ưu nguyên thủy và đối ngẫu có khoảng cách đối ngẫu bằng không.&lt;/li&gt;
  &lt;li&gt;Điều kiện cần cho cặp nghiệm tối ưu nguyên thủy và đối ngẫu khi tính đối ngẫu mạnh được thỏa mãn.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nói cách khác, với các bài toán thỏa mãn tính đối ngẫu mạnh, ta có tương đương sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   x^\star, \lambda^\star, \nu^\star \text{ là nghiệm nguyên thủy và đối ngẫu} \\\\
   \Leftrightarrow x^\star, \lambda^\star, \nu^\star \text{ thỏa mãn các điều kiện KKT} \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;kkt-qua-ví-dụ-đổ-nước-trong-khoảng-3-phút&quot;&gt;KKT qua ví dụ đổ nước trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/kkt-water-filling_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Giải bài đổ nước với α = (0,1; 0,4; 0,8; 1,2) bằng bốn điều kiện KKT, đọc ý nghĩa của λ, và ba cách đoán sai bị KKT loại.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>12 Điều Kiện KKT</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_00_KKT_conditions/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter12/12_00_KKT_conditions</id>
   <content type="html">&lt;p&gt;Năm 1939, chàng sinh viên cao học 22 tuổi William Karush tại Đại học Chicago viết một luận văn thạc sĩ giải quyết trọn vẹn bài toán tìm điều kiện cực trị cho tối ưu có ràng buộc bất đẳng thức — rồi luận văn ấy nằm yên lặng trên kệ thư viện suốt hơn một thập kỷ. Mãi đến năm 1951, Harold Kuhn và Albert Tucker độc lập tái khám phá và công bố rộng rãi hệ điều kiện này, mở ra kỷ nguyên mới cho toàn bộ ngành tối ưu phi tuyến hiện đại. Ngày nay, thế giới gọi chúng bằng tên chung đầy trân trọng: &lt;strong&gt;Điều kiện Karush–Kuhn–Tucker (KKT)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Nếu quy tắc \(\nabla f(x^*) = 0\) là chiếc la bàn vàng của giải tích không ràng buộc, thì hệ 4 điều kiện KKT chính là &lt;strong&gt;luật cơ bản của giải tích có ràng buộc&lt;/strong&gt;. Chương 12 sẽ biến công cụ lý thuyết này thành vũ khí giải toán thực chiến: từ hệ phương trình khối cho quy hoạch bậc hai, thuật toán “đổ nước” (water-filling) trong lý thuyết thông tin Shannon, phân tích vector hỗ trợ của SVM, cho đến tính duy nhất của nghiệm Lasso!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-tạo-nên-hệ-điều-kiện-kkt&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột tạo nên hệ điều kiện KKT&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng (Stationarity):&lt;/strong&gt; \(0 \in \partial f(x^*) + \sum u_i^* \partial h_i(x^*) + \sum v_j^* \partial l_j(x^*)\) (hoặc \(\nabla f + \sum u_i^* \nabla h_i + \sum v_j^* \nabla l_j = 0\) khi khả vi). Trực giác hình học: lực kéo hướng giảm \(-\nabla f(x^*)\) phải bị cân bằng hoàn toàn bởi tổ hợp các pháp tuyến hướng ra ngoài của các bức tường ràng buộc đang chạm!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù (Complementary Slackness):&lt;/strong&gt; \(u_i^* h_i(x^*) = 0\) với mọi \(i = 1, \dots, m\). Ràng buộc nào chưa chạm tường (\(h_i(x^*) &amp;lt; 0\)) thì không hề tạo lực đẩy (\(u_i^* = 0\)); chỉ ràng buộc đang chạm chặt (\(h_i(x^*) = 0\)) mới được phép có lực phản hồi \(u_i^* &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính khả thi nguyên thủy &amp;amp; đối ngẫu (Primal &amp;amp; Dual Feasibility):&lt;/strong&gt; \(h_i(x^*) \le 0, \; l_j(x^*) = 0\) và \(u_i^* \ge 0\). Dấu \(u_i^* \ge 0\) đảm bảo bức tường ràng buộc chỉ “đẩy ngược vào trong miền hợp lệ” chứ không bao giờ hút điểm lặp ra ngoài.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối hai chiều với đối ngẫu mạnh (Chương 11):&lt;/strong&gt; KKT tương đương chính xác với việc khoảng cách đối ngẫu bằng \(0\) (\(f(x^*) = g(u^*, v^*)\)) khi bài toán lồi — là điều kiện &lt;strong&gt;đủ&lt;/strong&gt; cho mọi bài toán lồi, và là điều kiện &lt;strong&gt;cần&lt;/strong&gt; khi có đối ngẫu mạnh (ví dụ thỏa điều kiện Slater).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-cả-4-điều-kiện-kkt-bằng-tay-trên-bài-toán-1-biến&quot;&gt;Giải thích: Kiểm chứng cả 4 điều kiện KKT bằng tay trên bài toán 1 biến&lt;/h3&gt;

&lt;p&gt;Xét bài toán lồi cực giản dị:
\(\min_{x \in \mathbb{R}} \; f(x) = (x - 3)^2 \quad \text{s.t.} \quad h(x) = x - 2 \le 0 \; (\text{tức } x \le 2).\)
Đáy tự do nằm tại \(x = 3\) (ngoài bức tường \(x \le 2\)), nên trực giác bảo ngay nghiệm tối ưu phải tựa sát bức tường tại \(x^* = 2\). Hãy kiểm chứng hệ KKT:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính khả thi nguyên thủy:&lt;/strong&gt; \(h(x^*) = 2 - 2 = 0 \le 0\) (thỏa!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng (\(f&apos;(x) + u h&apos;(x) = 0\)):&lt;/strong&gt;
\(2(x - 3) + u(1) = 0 \implies \text{tại } x^* = 2:\; 2(2 - 3) + u^* = 0 \implies u^* = 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính khả thi đối ngẫu:&lt;/strong&gt; \(u^* = 2 \ge 0\) (thỏa!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù:&lt;/strong&gt; \(u^* h(x^*) = 2 \times (2 - 2) = 0\) (thỏa!).
&lt;em&gt;Thử phản chứng:&lt;/em&gt; nếu ta đặt ràng buộc ngược lại là \(x \le 5\) (tường ở xa đáy \(x = 3\)), thì tại \(x^* = 3\) ta có \(h(3) = -2 &amp;lt; 0\) (lỏng), điều kiện bù ép \(u^* = 0\), và điều kiện dừng \(2(3 - 3) + 0 = 0\) thỏa mãn hoàn hảo!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Khi bài toán nguyên thủy là bài toán lồi, các điều kiện Karush–Kuhn–Tucker (KKT) là &lt;strong&gt;điều kiện đủ&lt;/strong&gt; để các điểm nguyên thủy và đối ngẫu đạt tối ưu với khoảng cách đối ngẫu bằng không. Bên cạnh đó, nếu hàm mục tiêu và các hàm ràng buộc của bài toán nguyên thủy khả vi và bài toán thỏa mãn tính đối ngẫu mạnh, thì mọi cặp nghiệm tối ưu nguyên thủy và đối ngẫu đều phải thỏa mãn các điều kiện KKT.&lt;/p&gt;

&lt;p&gt;Các điều kiện KKT giữ vai trò quan trọng trong tối ưu hóa. Nhờ chúng, nhiều bài toán có cấu trúc đặc biệt có thể được giải bằng phương pháp giải tích, đồng thời nhiều thuật toán tối ưu hóa lồi cũng có thể được xem là các phương pháp đi tìm nghiệm của hệ điều kiện KKT [1]. Trong chương này, chúng ta sẽ tìm hiểu định nghĩa, tính chất của các điều kiện KKT và phân tích một số ví dụ minh họa.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Ghi chú lịch sử:&lt;/em&gt; Các điều kiện KKT ban đầu được Harold W. Kuhn và Albert W. Tucker công bố vào năm 1951 và khi đó được gọi là điều kiện KT (Kuhn–Tucker). Về sau, giới nghiên cứu phát hiện ra rằng các điều kiện cần tương tự đã được William Karush trình bày trong luận văn thạc sĩ năm 1939; từ đó tên của Karush được bổ sung và hệ điều kiện này mang tên KKT (Karush–Kuhn–Tucker) [3].&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-hiện-đại-20222026&quot;&gt;Ứng dụng hiện đại (2022–2026)&lt;/h2&gt;

&lt;p&gt;Bài đọc tùy chọn đi kèm trình bày cách hệ KKT xuất hiện trong cvxpylayers và Theseus, các vector hỗ trợ của SVM, giá biên theo vị trí (LMP) trong thị trường điện và các ràng buộc công bằng đang chặt. Xem &lt;a href=&quot;/contents/vi/chapter12/12_07_modern_applications/&quot;&gt;12-07 Ứng dụng hiện đại của điều kiện KKT&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>12-09 Practical Exercises - KKT Conditions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_09_Practical_Exercises_KKT_Conditions/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_09_Practical_Exercises_KKT_Conditions</id>
   <content type="html">&lt;p&gt;Solving KKT systems by hand is a rite of passage in graduate optimization: it teaches you how to perform systematic active-set case analysis, spot symmetry before grinding algebra, and interpret Lagrange multipliers as physical forces or financial risk prices. The practical exercises below—adapted from Boyd &amp;amp; Vandenberghe, Nocedal &amp;amp; Wright, and Bertsekas—take you from basic 2D quadratic programs through Markowitz portfolio optimization and Support Vector Machines.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-systematic-workflow-for-solving-kkt-exercises&quot;&gt;Key ideas: Systematic Workflow for Solving KKT Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Standardize All Inequalities First:&lt;/strong&gt; Rewrite every inequality constraint as \(h_i(x) \le 0\) before writing \(L(x, u, v)\) so that dual feasibility is uniformly \(u_i \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Active-Set Case Splitting via Complementary Slackness:&lt;/strong&gt; With \(m\) inequalities, complementary slackness splits the search into \(2^m\) active-set combinations (for each \(i\), either \(u_i = 0\) or \(h_i(x) = 0\)). Always test the &lt;strong&gt;unconstrained / all-inactive&lt;/strong&gt; case first—if the unconstrained minimizer is primal feasible, you are done immediately!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Eliminating Primal Variables Using Stationarity:&lt;/strong&gt; For convex quadratics (like Markowitz portfolios or ridge regression), stationarity expresses \(x\) linearly in terms of \((u, v)\); substituting into active constraints solves for the multipliers in closed form.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Checking Convexity &amp;amp; Slater Before Concluding:&lt;/strong&gt; Once you find a KKT point \((x^\star, u^\star, v^\star)\), verify convexity of \(f\) and \(h_i\) (and affinity of \(l_j\)) to conclude &lt;em&gt;global&lt;/em&gt; optimality immediately; for nonconvex problems, compare objective values across all KKT candidates!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-active-set-kkt-case-analysis-on-a-2-constraint-qp&quot;&gt;Worked example: Active-Set KKT Case Analysis on a 2-Constraint QP&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = (x_1 - 3)^2 + (x_2 - 2)^2\) subject to \(h_1(x) = x_1 + x_2 - 3 \le 0\) and \(h_2(x) = -x_2 \le 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write stationarity:&lt;/strong&gt;
\(2(x_1 - 3) + u_1 = 0, \qquad 2(x_2 - 2) + u_1 - u_2 = 0, \qquad u_1, u_2 \ge 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 1 — Neither constraint active (\(u_1 = u_2 = 0\)):&lt;/strong&gt; Gives \((3, 2)\), which violates \(h_1(3, 2) = 3 + 2 - 3 = 2 &amp;gt; 0\). Reject!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 2 — Only \(h_1\) active (\(x_1 + x_2 = 3,\; u_2 = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Stationarity: \(x_1 = 3 - u_1/2\) and \(x_2 = 2 - u_1/2\).&lt;/li&gt;
      &lt;li&gt;Plug into \(x_1 + x_2 = 3\): \((3 - u_1/2) + (2 - u_1/2) = 3 \implies 5 - u_1 = 3 \implies u_1^\star = 2 \ge 0\)!&lt;/li&gt;
      &lt;li&gt;Recover primal point: \(x_1^\star = 3 - 1 = 2\), \(x_2^\star = 2 - 1 = 1\).&lt;/li&gt;
      &lt;li&gt;Check remaining feasibility: \(h_2(2, 1) = -1 &amp;lt; 0\) (strictly feasible, matching \(u_2^\star = 0\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stop immediately!&lt;/strong&gt; Because the problem is convex and Case 2 satisfies all four KKT conditions, \((x_1^\star, x_2^\star) = (2, 1)\) with \((u_1^\star, u_2^\star) = (2, 0)\) is the &lt;strong&gt;unique global optimum&lt;/strong&gt;—no need to test Cases 3 or 4!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---kkt-conditions-karush-kuhn-tucker&quot;&gt;Practical Exercises - KKT Conditions (Karush-Kuhn-Tucker)&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd &amp;amp; Vandenberghe (2004), Nocedal &amp;amp; Wright (2006), and Bertsekas (1999).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-i-verifying-the-kkt-conditions&quot;&gt;📝 &lt;strong&gt;Part I: Verifying the KKT Conditions&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-1-a-basic-problem-boyd--vandenberghe-ex-51&quot;&gt;&lt;strong&gt;Exercise 1: A Basic Problem (Boyd &amp;amp; Vandenberghe, Ex. 5.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the problem:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x_1^2 + x_2^2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 = 1 \\
&amp;amp; x_1 \geq 0
\end{align}\]

&lt;p&gt;Check the two candidate solutions:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;\(x^{(1)} = (0.5, 0.5)\), \(\nu = 1\), \(\lambda = 0\)&lt;/li&gt;
  &lt;li&gt;\(x^{(2)} = (0, 1)\), \(\nu = 2\), \(\lambda = 2\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Write the KKT conditions, check each condition, and determine the optimal solution.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**Lagrangian:** $$L(x,\nu,\lambda) = x_1^2 + x_2^2 - \nu(x_1+x_2-1) + \lambda(-x_1)$$ (the inequality constraint is written as $$g(x)=-x_1 \leq 0$$)

**The four KKT conditions:**

1. **Stationarity:** $$2x_1 - \nu - \lambda = 0$$, $$2x_2 - \nu = 0$$
2. **Primal Feasibility:** $$x_1 + x_2 = 1$$, $$x_1 \geq 0$$
3. **Dual Feasibility:** $$\lambda \geq 0$$
4. **Complementary Slackness:** $$\lambda \cdot (-x_1) = 0$$

**Check $$x^{(1)} = (0.5,0.5)$$, $$\nu=1$$, $$\lambda=0$$:**
- Stationarity: $$2(0.5)-1-0=0$$ ✓, $$2(0.5)-1=0$$ ✓
- Primal Feasibility: $$0.5+0.5=1$$ ✓, $$0.5 \geq 0$$ ✓
- Dual Feasibility: $$0 \geq 0$$ ✓
- Comp. Slackness: $$0 \cdot (-0.5)=0$$ ✓

**Satisfied!** Value: $$f^{(1)} = 0.5$$

**Check $$x^{(2)} = (0,1)$$, $$\nu=2$$, $$\lambda=2$$:**
- Stationarity: $$0-2-2=-4 \neq 0$$ ✗ (second component: $$2-2=0$$ ✓)
- Primal Feasibility: $$0+1=1$$ ✓, $$0 \geq 0$$ ✓
- Dual Feasibility: $$2 \geq 0$$ ✓
- Comp. Slackness: $$2 \cdot 0=0$$ ✓

**Not satisfied!** In fact, at $$x^{(2)}$$ we need $$\nu=2x_2=2$$ and $$\lambda = 2x_1-\nu = -2 &amp;lt; 0$$: no valid multiplier exists, so $$(0,1)$$ is not a KKT point. (The value $$f^{(2)} = 1 &amp;gt; f^{(1)}$$ is consistent with this.)

**Conclusion:** Only $$x^* = (0.5,0.5)$$ is a KKT point.

**Explanation:** The problem is convex, so KKT is sufficient for global optimality; hence $$x^* = (0.5,0.5)$$ is the unique optimal solution.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-2-a-simple-qp-nocedal--wright-ex-121&quot;&gt;&lt;strong&gt;Exercise 2: A Simple QP (Nocedal &amp;amp; Wright, Ex. 12.1)&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; \frac{1}{2}(x_1^2 + x_2^2) \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 = 1 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Solve with the active set method.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**3 active-set cases** (with $$L = \frac{1}{2}\|x\|^2 - \nu(x_1+x_2-1) - \lambda_1x_1 - \lambda_2x_2$$, stationarity: $$x_i = \nu + \lambda_i$$):

**Case 1:** no constraint $$\geq 0$$ is active ($$\lambda_1=\lambda_2=0$$)

From stationarity: $$x_1=\nu$$, $$x_2=\nu$$  
From $$x_1+x_2=1$$: $$2\nu=1 \Rightarrow \nu=0.5$$

→ $$x=(0.5, 0.5)$$, $$f=0.25$$, feasible ✓

**TH2:** $$x_1=0$$ active

$$x_2=1$$, stationarity for $$x_2$$: $$\nu=1$$  
Stationarity for $$x_1$$: $$\lambda_1 = x_1 - \nu = -1 &amp;lt; 0$$ ✗

→ $$x=(0,1)$$ is feasible but **violates dual feasibility**, so it is not a KKT point ($$f=0.5$$)

**TH3:** $$x_2=0$$ active

→ similarly, $$\lambda_2 = -1 &amp;lt; 0$$ ✗, so $$x=(1,0)$$ ($$f=0.5$$) is not a KKT point

**Optimal solution:** $$x^*=(0.5,0.5)$$ with $$f^*=0.25$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-ii-portfolio-optimization-application&quot;&gt;📝 &lt;strong&gt;Part II: Portfolio Optimization Application&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-3-markowitz-mean-variance&quot;&gt;&lt;strong&gt;Exercise 3: Markowitz Mean-Variance&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; \frac{1}{2} x^T \Sigma x \\
\text{s.t.} \quad &amp;amp; \mu^T x \geq r_{\min} \\
&amp;amp; \mathbf{1}^T x = 1 \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;With \(n=3\):&lt;/p&gt;

\[\Sigma = \begin{bmatrix} 0.04 &amp;amp; 0.01 &amp;amp; 0 \\ 0.01 &amp;amp; 0.09 &amp;amp; 0.02 \\ 0 &amp;amp; 0.02 &amp;amp; 0.16 \end{bmatrix}, \quad
\mu = \begin{bmatrix} 0.10 \\ 0.15 \\ 0.08 \end{bmatrix}, \quad
r_{\min} = 0.12\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Try the assumption \(x_3=0\) (invest only in assets 1 and 2): find \(x_1, x_2\) and the dual variables, then check the KKT conditions.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**Assume:** $$x_3=0$$ ($$\nu_{2,3} &amp;gt; 0$$), $$x_1,x_2&amp;gt;0$$, return constraint active ($$\lambda&amp;gt;0$$)

**Constraints:**
$$
\begin{cases}
x_1 + x_2 = 1 \\
0.10x_1 + 0.15x_2 = 0.12
\end{cases}
$$

From equation 2: $$0.10x_1 + 0.15x_2 = 0.12$$  
Substitute $$x_1 = 1-x_2$$:

$$
0.10(1-x_2) + 0.15x_2 = 0.12 \\
0.10 + 0.05x_2 = 0.12 \\
x_2 = 0.4
$$

→ $$x_1 = 0.6$$

**Solution:** $$x^* = (0.6, 0.4, 0)^T$$

**Check the dual variables from stationarity** (with $$L = \frac{1}{2}x^T\Sigma x - \lambda(\mu^Tx - r_{\min}) - \nu_1(\mathbf{1}^Tx-1) - \nu_2^Tx$$, so $$\Sigma x = \lambda\mu + \nu_1\mathbf{1} + \nu_2$$):

$$\Sigma x^* = \begin{bmatrix} 0.028 \\ 0.042 \\ 0.008 \end{bmatrix}$$

With $$\nu_{2,1}=\nu_{2,2}=0$$:

$$
\begin{cases}
0.028 = 0.10\lambda + \nu_1 \\
0.042 = 0.15\lambda + \nu_1
\end{cases}
$$

Subtract: $$0.014 = 0.05\lambda \Rightarrow \lambda = 0.28$$  
→ $$\nu_1 = 0.028 - 0.028 = 0$$

From equation 3:
$$\nu_{2,3} = 0.008 - 0.08(0.28) - 0 = -0.0144 &amp;lt; 0$$ ✗

**Conclusion:** Dual feasibility ($$\nu_2 \geq 0$$) is violated, so the assumption $$x_3=0$$ is **wrong**: asset 3 (weakly correlated with asset 1) should still receive a small investment thanks to the diversification effect.

**Re-solving with all 3 assets active** ($$x_i&amp;gt;0$$, return constraint active): solving $$\Sigma x = \lambda\mu + \nu_1\mathbf{1}$$, $$\mu^Tx=0.12$$, $$\mathbf{1}^Tx=1$$ gives

$$x^* \approx (0.522,\ 0.422,\ 0.056)^T, \quad \lambda^* \approx 0.385, \quad \nu_1^* \approx -0.0134$$

Check component 3: $$(\Sigma x^*)_3 \approx 0.0174 = 0.08(0.385) - 0.0134$$ ✓. The variance $$\frac{1}{2}x^{*T}\Sigma x^* \approx 0.0164$$ ($$\sigma \approx 0.181$$) is lower than $$0.0168$$ ($$\sigma \approx 0.183$$) for $$(0.6, 0.4, 0)$$.

**Meaning:**
- $$\lambda^*\approx 0.385$$: shadow price of the return constraint (raising $$r_{\min}$$ by $$0.001$$ → $$\frac{1}{2}x^T\Sigma x$$ increases by about $$0.000385$$)
- $$x_3^* \approx 0.056 &amp;gt; 0$$: asset 3 has a low return but helps reduce risk through diversification

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iii-support-vector-machines&quot;&gt;📝 &lt;strong&gt;Part III: Support Vector Machines&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-4-hard-margin-svm-boyd--vandenberghe-ex-86&quot;&gt;&lt;strong&gt;Exercise 4: Hard-Margin SVM (Boyd &amp;amp; Vandenberghe, Ex. 8.6)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Data:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Class +1: \((1,2)\), \((2,3)\), \((3,3)\)&lt;/li&gt;
  &lt;li&gt;Class -1: \((1,1)\), \((2,1)\), \((3,2)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Primal:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{w,b} \quad &amp;amp; \frac{1}{2}\|w\|^2 \\
\text{s.t.} \quad &amp;amp; y_i(w^Tx_i + b) \geq 1, \quad i=1,\ldots,6
\end{align}\]

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{\alpha} \quad &amp;amp; \sum_i \alpha_i - \frac{1}{2}\sum_{i,j} \alpha_i\alpha_j y_iy_j x_i^Tx_j \\
\text{s.t.} \quad &amp;amp; \sum_i \alpha_i y_i = 0 \\
&amp;amp; \alpha_i \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Determine the support vectors and the hyperplane.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**Geometric observation:** The two classes are linearly separable. The support vectors are the points lying on the margin boundaries.

**Solution (computed with a QP solver, then verified with KKT):**
- Support vectors: $$x_1=(1,2)$$ (class +1), $$x_3=(3,3)$$ (class +1), $$x_6=(3,2)$$ (class -1)
- $$\alpha_1^* = 0.5$$, $$\alpha_3^* = 2$$, $$\alpha_6^* = 2.5$$
- All other $$\alpha$$&apos;s = 0

Check: $$\sum_i \alpha_i y_i = 0.5 + 2 - 2.5 = 0$$ ✓

**Compute $$w^*$$:**

$$
w^* = \sum_i \alpha_i^* y_i x_i = 0.5(1,2) + 2(3,3) - 2.5(3,2)
$$

$$
= (0.5,1.0) + (6,6) - (7.5,5) = (-1, 2)
$$

**Compute $$b^*$$ from SV $$x_1$$:**

$$y_1(w^{*T}x_1 + b^*) = 1$$

$$1 \cdot ((-1)(1) + (2)(2) + b^*) = 1$$

$$3 + b^* = 1 \Rightarrow b^* = -2$$

**Decision boundary:** $$-x_1 + 2x_2 - 2 = 0$$, i.e. $$x_2 = \frac{x_1+2}{2}$$

**Margin check:** $$y_i(w^{*T}x_i+b^*) = 1, 2, 1, 1, 2, 1$$ for the 6 points (all $$\geq 1$$, equal to 1 at the SVs) ✓. Margin width: $$\frac{2}{\|w^*\|} = \frac{2}{\sqrt{5}} \approx 0.894$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iv-water-filling-algorithm&quot;&gt;📝 &lt;strong&gt;Part IV: Water-Filling Algorithm&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-5-power-allocation-boyd--vandenberghe-ex-57&quot;&gt;&lt;strong&gt;Exercise 5: Power Allocation (Boyd &amp;amp; Vandenberghe, Ex. 5.7)&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\max_{p} \quad &amp;amp; \sum_{i=1}^n \log(1 + p_i/\sigma_i^2) \\
\text{s.t.} \quad &amp;amp; \sum_i p_i \leq P_{\text{total}} \\
&amp;amp; p_i \geq 0
\end{align}\]

&lt;p&gt;With \(n=4\), \(\sigma^2=(1,2,3,4)\), \(P_{\text{total}}=10\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Derive the water-filling formula and compute the solution.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**KKT conditions (converted to a minimization):**

Lagrangian: $$L = -\sum \log(1+p_i/\sigma_i^2) + \lambda(\sum p_i - P) - \sum \mu_i p_i$$

Stationarity: $$\frac{\partial L}{\partial p_i} = -\frac{1}{\sigma_i^2 + p_i} + \lambda - \mu_i = 0$$

**Analysis:**

- If $$p_i &amp;gt; 0$$: $$\mu_i=0 \Rightarrow \frac{1}{\sigma_i^2+p_i}=\lambda \Rightarrow p_i = \frac{1}{\lambda}-\sigma_i^2$$
- If $$p_i = 0$$: $$\mu_i \geq 0 \Rightarrow \sigma_i^2 \geq \frac{1}{\lambda}$$

**Water-filling formula:**

$$
\boxed{p_i^* = \max\left(0, \frac{1}{\lambda^*} - \sigma_i^2\right)}
$$

where $$\lambda^*$$ is such that $$\sum p_i^* = P_{\text{total}}$$.

---

**Computing the solution:**

Assume all channels are active:

$$
\sum_{i=1}^4 \left(\frac{1}{\lambda}-\sigma_i^2\right) = 10
$$

$$
\frac{4}{\lambda} - (1+2+3+4) = 10
$$

$$
\frac{4}{\lambda} = 20 \Rightarrow \lambda = 0.2
$$

**Water level:** $$\frac{1}{\lambda} = 5$$

**Power:**
- $$p_1 = 5-1 = 4$$ ✓
- $$p_2 = 5-2 = 3$$ ✓
- $$p_3 = 5-3 = 2$$ ✓
- $$p_4 = 5-4 = 1$$ ✓

**Total:** $$4+3+2+1=10$$ ✓

**Solution:** $$p^* = (4,3,2,1)$$

**Water Level interpretation:**

```
Water level = 5
|     |     |     |
|  4  |  3  |  2  |  1  |  ← Power
+-----+-----+-----+-----+
|  1  |  2  |  3  |  4  |  ← Noise floor
+-----+-----+-----+-----+
  p₁    p₂    p₃    p₄
```

Good channels (low noise) receive more power!

**Capacity:** 

$$C = \sum \log_2(1+p_i^*/\sigma_i^2) \approx 4.70 \text{ bits/s/Hz}$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-v-advanced-exercises&quot;&gt;📝 &lt;strong&gt;Part V: Advanced Exercises&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-6-constrained-least-squares-bertsekas-ex-322&quot;&gt;&lt;strong&gt;Exercise 6: Constrained Least Squares (Bertsekas, Ex. 3.2.2)&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; \frac{1}{2}\|Ax-b\|^2 \\
\text{s.t.} \quad &amp;amp; Cx = d \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;With:&lt;/p&gt;

\[A = \begin{bmatrix} 1&amp;amp;1\\1&amp;amp;-1\\2&amp;amp;0 \end{bmatrix}, \quad
b = \begin{bmatrix} 2\\0\\3 \end{bmatrix}, \quad
C = [1\ 1], \quad
d = 2\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Solve using KKT.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

$$\nabla f(x) = A^TAx - A^Tb$$

$$
A^TA = \begin{bmatrix} 6&amp;amp;0\\0&amp;amp;2 \end{bmatrix}, \quad
A^Tb = \begin{bmatrix} 8\\2 \end{bmatrix}
$$

**KKT system (without $$x \geq 0$$):**

$$
\begin{bmatrix} 6&amp;amp;0&amp;amp;-1\\0&amp;amp;2&amp;amp;-1\\1&amp;amp;1&amp;amp;0 \end{bmatrix}
\begin{bmatrix} x_1\\x_2\\\nu \end{bmatrix} =
\begin{bmatrix} 8\\2\\2 \end{bmatrix}
$$

Solve:
- From (3): $$x_1+x_2=2$$
- From (1), (2): $$x_1=\frac{8+\nu}{6}$$, $$x_2=\frac{2+\nu}{2}$$; substituting into (3): $$14+4\nu=12 \Rightarrow \nu=-0.5$$
- $$x_1=1.25$$, $$x_2=0.75$$

**Check $$x \geq 0$$:** $$x_1=1.25&amp;gt;0$$, $$x_2=0.75&amp;gt;0$$ ✓

**Check $$\lambda$$:**

$$\lambda = A^TAx - A^Tb - C^T\nu = \begin{bmatrix} 7.5-8+0.5\\1.5-2+0.5 \end{bmatrix} = \begin{bmatrix} 0\\0 \end{bmatrix} \geq 0$$ ✓

**Solution:** $$x^*=(1.25, 0.75)^T$$, $$Ax^*-b=(0,0.5,-0.5)^T$$, $$f^*=\frac{1}{2}(0.25+0.25)=0.25$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-7-penalty-method-nocedal--wright-ex-171&quot;&gt;&lt;strong&gt;Exercise 7: Penalty Method (Nocedal &amp;amp; Wright, Ex. 17.1)&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x_1 + x_2 \\
\text{s.t.} \quad &amp;amp; x_1^2 + x_2^2 = 1
\end{align}\]

&lt;p&gt;&lt;strong&gt;Penalty:&lt;/strong&gt; \(\min \phi(x;\mu) = x_1+x_2 + \frac{\mu}{2}(x_1^2+x_2^2-1)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Solve with KKT, compute the penalty solution for \(\mu=1,10,100\), and analyze the convergence.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**Solving with KKT:**

Lagrangian: $$L = x_1+x_2 - \nu(x_1^2+x_2^2-1)$$

Stationarity: $$1-2\nu x_1=0$$, $$1-2\nu x_2=0$$ → $$x_1=x_2=\frac{1}{2\nu}$$

Feasibility: $$\frac{1}{4\nu^2}+\frac{1}{4\nu^2}=1 \Rightarrow \nu = \pm\frac{1}{\sqrt{2}}$$

**Two KKT points:**
1. $$x=(1/\sqrt{2}, 1/\sqrt{2})$$, $$f=\sqrt{2}$$
2. $$x=(-1/\sqrt{2}, -1/\sqrt{2})$$, $$f=-\sqrt{2}$$

**Optimal (min):** $$x^* = (-1/\sqrt{2}, -1/\sqrt{2})$$

---

**Penalty method:**

FOC: $$1 + 2\mu x_i(x_1^2+x_2^2-1)=0$$

With $$x_1=x_2=x$$: $$1 + 2\mu x(2x^2-1)=0$$, i.e. $$4\mu x^3 - 2\mu x + 1=0$$

**Numerical solution** (take the negative real root of the cubic, which has the smallest $$\phi$$; for large $$\mu$$ the cubic also has a positive root corresponding to a local minimum near the KKT maximizer, with larger $$\phi$$):
- $$\mu=1$$: $$x \approx -0.885$$ ($$x_1^2+x_2^2-1 \approx 0.57$$, a fairly large constraint violation)
- $$\mu=10$$: $$x \approx -0.731$$ ($$x_1^2+x_2^2-1 \approx 0.07$$)
- $$\mu=100$$: $$x \approx -0.710$$ ($$x_1^2+x_2^2-1 \approx 0.007$$) $$\to -1/\sqrt{2} \approx -0.7071$$

**Convergence:** As $$\mu \to \infty$$, the penalty solution converges to the KKT solution (from **outside** the feasible set, since $$x_1^2+x_2^2&amp;gt;1$$)!

**Relation:** $$\nu \approx -\mu(x_1^2+x_2^2-1)$$ (with the convention $$L = f - \nu h$$; e.g. $$\mu=100$$: $$\nu \approx -100 \cdot 0.007 \approx -0.7 \approx -1/\sqrt{2}$$ ✓)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-strategy-summary&quot;&gt;💡 &lt;strong&gt;Strategy Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;verifying-kkt&quot;&gt;&lt;strong&gt;Verifying KKT:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Check the &lt;strong&gt;4 conditions&lt;/strong&gt; separately&lt;/li&gt;
  &lt;li&gt;KKT is &lt;strong&gt;necessary&lt;/strong&gt; for a local optimum (under a CQ) and &lt;strong&gt;sufficient&lt;/strong&gt; for a global optimum (convex problems)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;solving-with-kkt&quot;&gt;&lt;strong&gt;Solving with KKT:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Active set strategy:&lt;/strong&gt; try the active-set cases&lt;/li&gt;
  &lt;li&gt;Solve the KKT system from stationarity + active constraints&lt;/li&gt;
  &lt;li&gt;Check feasibility and compare objectives&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;complementary-slackness&quot;&gt;&lt;strong&gt;Complementary Slackness:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;\(\lambda_i &amp;gt; 0 \Rightarrow\) constraint \(i\) is active&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Shadow price:&lt;/strong&gt; \(\lambda_i^*\) = marginal value of constraint \(i\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;convex-problems&quot;&gt;&lt;strong&gt;Convex problems:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;KKT sufficient → a KKT point is globally optimal&lt;/li&gt;
  &lt;li&gt;Strong duality: \(f^*=g^*\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 5.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nocedal, J., &amp;amp; Wright, S. J.&lt;/strong&gt; (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt; (2nd ed.). Springer. Chapters 12, 16-17.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bertsekas, D. P.&lt;/strong&gt; (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt; (2nd ed.). Athena Scientific. Chapter 3.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Luenberger, D. G., &amp;amp; Ye, Y.&lt;/strong&gt; (2008). &lt;em&gt;Linear and Nonlinear Programming&lt;/em&gt; (3rd ed.). Springer. Chapter 10.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bazaraa, M. S., Sherali, H. D., &amp;amp; Shetty, C. M.&lt;/strong&gt; (2006). &lt;em&gt;Nonlinear Programming: Theory and Algorithms&lt;/em&gt; (3rd ed.). Wiley.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

</content>
 </entry>
 
 <entry>
   <title>12-08 Multiple-Choice Quiz - KKT Conditions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_08_Quiz_KKT_Conditions/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_08_Quiz_KKT_Conditions</id>
   <content type="html">&lt;p&gt;Before you start the Chapter 12 multiple-choice quiz, double-check the exact logical arrows connecting KKT, convexity, and strong duality—this is where 80% of graduate exam mistakes happen! Remember: KKT is &lt;em&gt;sufficient&lt;/em&gt; for global optimality on &lt;strong&gt;every&lt;/strong&gt; convex problem (even without Slater’s condition!), whereas KKT is &lt;em&gt;necessary&lt;/em&gt; whenever &lt;strong&gt;strong duality&lt;/strong&gt; holds (for both convex and differentiable nonconvex problems!). Use the four diagnostic pillars and rapid KKT audit below to warm up.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-chapter-12-exam-day-diagnostic-matrix&quot;&gt;Key ideas: Chapter 12 Exam-Day Diagnostic Matrix&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The Four Conditions by Heart:&lt;/strong&gt; (1) Stationarity \(0 \in \partial f(x^\star) + \sum u_i^\star \partial h_i(x^\star) + \sum v_j^\star \partial l_j(x^\star)\); (2) Complementary slackness \(u_i^\star h_i(x^\star) = 0\); (3) Primal feasibility \(h_i(x^\star) \le 0, l_j(x^\star) = 0\); (4) Dual feasibility \(u_i^\star \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Exact Logical Arrows:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Convex + KKT satisfied \(\implies\) \(x^\star, u^\star, v^\star\) are globally optimal with zero duality gap (no Slater needed!).&lt;/li&gt;
      &lt;li&gt;Strong duality + \((x^\star, u^\star, v^\star)\) optimal \(\implies\) KKT holds (even if nonconvex!).&lt;/li&gt;
      &lt;li&gt;Convex + Slater’s condition \(\implies\) KKT is &lt;strong&gt;both necessary and sufficient&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Iconic KKT Fingerprints:&lt;/strong&gt; Equality-constrained QP \(\to\) block linear KKT matrix; Water-filling \(\to\) \(x_i^\star = \max(0, 1/\nu^\star - \alpha_i)\); Soft-margin SVM \(\to\) \(0 \le w_i^\star \le C\) with \(w_i^\star = 0\) off the margin; Lasso \(\to\) \(X^\top(y - X\hat{\beta}) = \lambda s\) with unique \(X\hat{\beta}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Constrained vs. Lagrange Equivalence:&lt;/strong&gt; Under convexity and Slater’s condition, every constrained solution solves some Lagrange form (\(\lambda = \lambda^\star \ge 0\)), and every Lagrange solution solves the constrained form with \(t = h(x^\star)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-auditing-a-proposed-kkt-solution-in-30-seconds&quot;&gt;Worked example: Auditing a Proposed KKT Solution in 30 Seconds&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = x_1^2 + x_2^2\) subject to \(h_1(x) = 2 - x_1 - x_2 \le 0\) and \(h_2(x) = -x_1 \le 0\). Someone claims \(x^\star = (1, 1)^\top\) with \(u^\star = (2, 0)^\top\) is optimal. Let’s audit all four KKT conditions!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Primal feasibility:&lt;/strong&gt; \(h_1(1, 1) = 2 - 1 - 1 = 0 \le 0\) (active); \(h_2(1, 1) = -1 &amp;lt; 0\) (strictly inactive). Pass!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual feasibility:&lt;/strong&gt; \(u_1^\star = 2 \ge 0\), \(u_2^\star = 0 \ge 0\). Pass!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; \(u_1^\star h_1(x^\star) = 2(0) = 0\) and \(u_2^\star h_2(x^\star) = 0(-1) = 0\). Pass!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt; \(\nabla f(x^\star) + u_1^\star \nabla h_1(x^\star) + u_2^\star \nabla h_2(x^\star) = \begin{pmatrix}2\\2\end{pmatrix} + 2\begin{pmatrix}-1\\-1\end{pmatrix} + 0\begin{pmatrix}-1\\0\end{pmatrix} = \begin{pmatrix}0\\0\end{pmatrix}\). Pass!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verdict:&lt;/strong&gt; Since \(f, h_1, h_2\) are all convex and all four KKT conditions hold, \((1, 1)^\top\) is 100% certified globally optimal!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-the-karush-kuhn-tucker-kkt-conditions&quot;&gt;⚡ &lt;strong&gt;The Karush-Kuhn-Tucker (KKT) Conditions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;general-optimization-problem&quot;&gt;&lt;strong&gt;General optimization problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) \quad \text{s.t.} \quad h_i(x) \le 0, \quad l_j(x) = 0\)&lt;/p&gt;

&lt;p&gt;with \(i = 1,\ldots,m\) and \(j = 1,\ldots,r\)&lt;/p&gt;

&lt;h4 id=&quot;the-four-kkt-conditions&quot;&gt;&lt;strong&gt;The four KKT conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Given \(x^*, \lambda^*, \nu^*\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt;
\(0 \in \partial \left( f(x^*) + \sum_{i=1}^m \lambda_i^* h_i(x^*) + \sum_{j=1}^r \nu_j^* l_j(x^*) \right)\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Complementary Slackness:&lt;/strong&gt;
\(\lambda_i^* \cdot h_i(x^*) = 0 \quad \forall i\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Primal Feasibility:&lt;/strong&gt;
\(h_i(x^*) \le 0, \quad l_j(x^*) = 0 \quad \forall i,j\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Dual Feasibility:&lt;/strong&gt;
\(\lambda_i^* \ge 0 \quad \forall i\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;meaning-of-the-conditions&quot;&gt;&lt;strong&gt;Meaning of the conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt; The gradient of the Lagrangian is 0&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; Either the constraint is active (\(h_i = 0\)) or the dual variable is 0 (\(\lambda_i = 0\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal feasibility:&lt;/strong&gt; All constraints of the original problem are satisfied&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual feasibility:&lt;/strong&gt; Dual variables for inequality constraints must be non-negative&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-sufficiency-and-necessity&quot;&gt;📊 &lt;strong&gt;Sufficiency and Necessity&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;sufficiency&quot;&gt;&lt;strong&gt;Sufficiency&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;If&lt;/strong&gt; \(x^*, \lambda^*, \nu^*\) satisfy the KKT conditions and the problem is &lt;strong&gt;convex&lt;/strong&gt;, &lt;strong&gt;then&lt;/strong&gt; they are optimal solutions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt;
\(g(\lambda^*, \nu^*) = \min_x L(x, \lambda^*, \nu^*) = L(x^*, \lambda^*, \nu^*) = f(x^*)\)&lt;/p&gt;

&lt;p&gt;Hence: \(g(\lambda^*, \nu^*) = f(x^*)\) ⟹ duality gap = 0 ⟹ optimal&lt;/p&gt;

&lt;h4 id=&quot;necessity&quot;&gt;&lt;strong&gt;Necessity&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;If&lt;/strong&gt; \(x^*, \lambda^*, \nu^*\) are optimal solutions with &lt;strong&gt;strong duality&lt;/strong&gt;, &lt;strong&gt;then&lt;/strong&gt; they satisfy the KKT conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; Strong duality (e.g. Slater’s condition)&lt;/p&gt;

&lt;h4 id=&quot;summary&quot;&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;For convex problems with strong duality:
\(x^*, \lambda^*, \nu^* \text{ optimal} \Leftrightarrow x^*, \lambda^*, \nu^* \text{ satisfy KKT}\)&lt;/p&gt;

&lt;h3 id=&quot;-example-quadratic-programming-with-equality-constraints&quot;&gt;🔄 &lt;strong&gt;Example: Quadratic Programming with Equality Constraints&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;problem&quot;&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x \frac{1}{2}x^T P x + q^T x + r \quad \text{s.t.} \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;with \(P \in \mathbb{S}_+^n\) (positive semidefinite)&lt;/p&gt;

&lt;h4 id=&quot;kkt-conditions&quot;&gt;&lt;strong&gt;KKT conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt; \(Px^* + q + A^T \nu^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal feasibility:&lt;/strong&gt; \(Ax^* = b\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; None (no inequality constraints)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual feasibility:&lt;/strong&gt; None (no inequality constraints)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;the-kkt-matrix-system&quot;&gt;&lt;strong&gt;The KKT Matrix System&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{bmatrix} P &amp;amp; A^T \\ A &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x^* \\ \nu^* \end{bmatrix} = \begin{bmatrix} -q \\ b \end{bmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meaning:&lt;/strong&gt; This is exactly the &lt;strong&gt;Newton step&lt;/strong&gt; for constrained optimization!&lt;/p&gt;

&lt;h3 id=&quot;-example-the-water-filling-algorithm&quot;&gt;🌊 &lt;strong&gt;Example: The Water-Filling Algorithm&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;problem-1&quot;&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x -\sum_{i=1}^n \log(\alpha_i + x_i) \quad \text{s.t.} \quad x \succeq 0, \quad \mathbf{1}^T x = 1\)&lt;/p&gt;

&lt;p&gt;with \(\alpha_i &amp;gt; 0\)&lt;/p&gt;

&lt;h4 id=&quot;kkt-conditions-1&quot;&gt;&lt;strong&gt;KKT conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt; \(-\frac{1}{\alpha_i + x_i^*} - \lambda_i^* + \nu^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; \(\lambda_i^* x_i^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal feasibility:&lt;/strong&gt; \(x^* \succeq 0, \mathbf{1}^T x^* = 1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual feasibility:&lt;/strong&gt; \(\lambda^* \succeq 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;analytical-solution&quot;&gt;&lt;strong&gt;Analytical solution&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x_i^* = \max\left\{0, \frac{1}{\nu^*} - \alpha_i\right\}\)&lt;/p&gt;

&lt;p&gt;with \(\nu^*\) determined by: \(\sum_{i=1}^n \max\left\{0, \frac{1}{\nu^*} - \alpha_i\right\} = 1\)&lt;/p&gt;

&lt;h4 id=&quot;water-filling-interpretation&quot;&gt;&lt;strong&gt;Water-filling interpretation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(\alpha_i\): “Ground level” of channel \(i\)&lt;/li&gt;
  &lt;li&gt;\(\frac{1}{\nu^*}\): “Water level” chung&lt;/li&gt;
  &lt;li&gt;\(x_i^*\): “Water depth” in channel \(i\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm:&lt;/strong&gt; Pour water until the total volume = 1&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-example-support-vector-machine-svm&quot;&gt;🎯 &lt;strong&gt;Example: Support Vector Machine (SVM)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;primal-problem&quot;&gt;&lt;strong&gt;Primal problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{\beta,\beta_0,\xi} \frac{1}{2}\|\beta\|_2^2 + C\sum_{i=1}^n \xi_i\)
\(\text{s.t.} \quad \xi_i \ge 0, \quad y_i(x_i^T\beta + \beta_0) \ge 1 - \xi_i\)&lt;/p&gt;

&lt;h4 id=&quot;kkt-conditions-2&quot;&gt;&lt;strong&gt;KKT conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[\beta^* = \sum_{i=1}^n w_i^* y_i x_i\]
      &lt;/li&gt;
      &lt;li&gt;
\[\sum_{i=1}^n w_i^* y_i = 0\]
      &lt;/li&gt;
      &lt;li&gt;
\[w^* = C\mathbf{1} - v^*\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[v_i^* \xi_i^* = 0\]
      &lt;/li&gt;
      &lt;li&gt;
\[w_i^* (1 - \xi_i^* - y_i(x_i^T\beta^* + \beta_0^*)) = 0\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;support-vectors&quot;&gt;&lt;strong&gt;Support vectors&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Point \(i\) is a support vector&lt;/strong&gt; ⟺ \(w_i^* &amp;gt; 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two types of support vectors:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;On margin:&lt;/strong&gt; \(\xi_i^* = 0\), \(w_i^* \in (0, C]\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inside margin:&lt;/strong&gt; \(\xi_i^* &amp;gt; 0\), \(w_i^* = C\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;practical-implications&quot;&gt;&lt;strong&gt;Practical implications&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sparsity:&lt;/strong&gt; Only support vectors have \(w_i^* &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Efficiency:&lt;/strong&gt; Non-support points can be filtered out before optimizing&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt; The KKT conditions explain the structure of the SVM solution&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-constrained-form-vs-lagrangian-form&quot;&gt;🔄 &lt;strong&gt;Constrained Form vs Lagrangian Form&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;constrained-form-c&quot;&gt;&lt;strong&gt;Constrained form (C)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) \quad \text{s.t.} \quad h(x) \le t\)&lt;/p&gt;

&lt;h4 id=&quot;lagrangian-form-l&quot;&gt;&lt;strong&gt;Lagrangian form (L)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) + \lambda h(x)\)&lt;/p&gt;

&lt;h4 id=&quot;equivalence-conditions&quot;&gt;&lt;strong&gt;Equivalence conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;When are (C) and (L) equivalent?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;(C) → (L):&lt;/strong&gt; If (C) satisfies Slater + strong duality, there exists \(\lambda^* \ge 0\) such that a solution of (C) is also a solution of (L)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;(L) → (C):&lt;/strong&gt; If \(x^*\) solves (L) and the KKT conditions hold, then \(x^*\) also solves (C) with \(t = h(x^*)\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;perfect-equivalence&quot;&gt;&lt;strong&gt;Perfect equivalence&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;When:&lt;/strong&gt; \(h(x) \ge 0\) (like a norm), \(t = 0\), \(\lambda = \infty\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; Both enforce \(h(x) = 0\)&lt;/p&gt;

&lt;h3 id=&quot;️-practical-techniques&quot;&gt;🛠️ &lt;strong&gt;Practical Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;checking-the-kkt-conditions&quot;&gt;&lt;strong&gt;Checking the KKT conditions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Verify stationarity:&lt;/strong&gt; \(\nabla_x L(x^*, \lambda^*, \nu^*) = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check complementary slackness:&lt;/strong&gt; \(\lambda_i^* h_i(x^*) = 0 \quad \forall i\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify feasibility:&lt;/strong&gt; Primal and dual constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Confirm optimality:&lt;/strong&gt; If convex + KKT ⟹ optimal&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;analytical-solution-strategy&quot;&gt;&lt;strong&gt;Analytical solution strategy:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the KKT conditions&lt;/strong&gt; for the specific problem&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Use complementary slackness&lt;/strong&gt; to identify the active constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the system of equations&lt;/strong&gt; from stationarity + feasibility&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify that the solution&lt;/strong&gt; satisfies all KKT conditions&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;computational-applications&quot;&gt;&lt;strong&gt;Computational applications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Active set methods:&lt;/strong&gt; Identify active constraints iteratively&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point methods:&lt;/strong&gt; Follow central path satisfying KKT&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual methods:&lt;/strong&gt; Update primal and dual simultaneously&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-illustrative-examples&quot;&gt;💡 &lt;strong&gt;Illustrative Examples&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;simple-problem&quot;&gt;&lt;strong&gt;Simple problem:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x x^2 + y^2 \quad \text{s.t.} \quad x + y = 1, \quad x \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KKT conditions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt; \(2x^* - \lambda^* + \nu^* = 0\), \(2y^* + \nu^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; \(\lambda^* x^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal feasibility:&lt;/strong&gt; \(x^* + y^* = 1\), \(x^* \ge 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual feasibility:&lt;/strong&gt; \(\lambda^* \ge 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Case analysis:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Case 1:&lt;/strong&gt; \(x^* &amp;gt; 0\) ⟹ \(\lambda^* = 0\) ⟹ \(x^* = y^* = 1/2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 2:&lt;/strong&gt; \(x^* = 0\) ⟹ \(y^* = 1\) ⟹ \(\nu^* = -2\) ⟹ \(\lambda^* = -2 &amp;lt; 0\) (violates dual feasibility, rejected)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Optimal solution:&lt;/strong&gt; \(x^* = 1/2, y^* = 1/2\), \(\nu^* = -1\), \(\lambda^* = 0\) (only Case 1 satisfies KKT)&lt;/p&gt;

&lt;h3 id=&quot;-connections-to-other-chapters&quot;&gt;🎯 &lt;strong&gt;Connections to Other Chapters&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-the-previous-chapter&quot;&gt;&lt;strong&gt;From the previous chapter:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 11:&lt;/strong&gt; General duality theory - KKT is a direct consequence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 10:&lt;/strong&gt; LP duality - KKT generalizes the optimality conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 04:&lt;/strong&gt; First-order optimality conditions - KKT extends them to constrained problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;importance-of-kkt&quot;&gt;&lt;strong&gt;Importance of KKT:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Optimality characterization:&lt;/strong&gt; Necessary and sufficient conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm design:&lt;/strong&gt; Active set, interior point, SQP methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical analysis:&lt;/strong&gt; Sensitivity, perturbation theory&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; SVM, regularization, constrained learning&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;looking-ahead&quot;&gt;&lt;strong&gt;Looking ahead:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Second-order conditions:&lt;/strong&gt; Bordered Hessian, LICQ, MFCQ&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nonlinear programming:&lt;/strong&gt; SQP, trust region methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Variational inequalities:&lt;/strong&gt; Complementarity problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal control:&lt;/strong&gt; Pontryagin maximum principle&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-theoretical-significance&quot;&gt;🌟 &lt;strong&gt;Theoretical Significance&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;kkt-as-universal-optimality-conditions&quot;&gt;&lt;strong&gt;KKT as universal optimality conditions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Unifies:&lt;/strong&gt; Unconstrained (\(\nabla f = 0\)) and constrained optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Characterizes:&lt;/strong&gt; Exactly when point is optimal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enables:&lt;/strong&gt; Systematic algorithm design&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Connects:&lt;/strong&gt; Primal and dual perspectives&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;geometric-interpretation&quot;&gt;&lt;strong&gt;Geometric interpretation:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt; Gradient orthogonal to feasible directions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; Either the constraint is active or the multiplier is zero&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feasibility:&lt;/strong&gt; Point lies in feasible region&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-negativity:&lt;/strong&gt; Consistent with the constraint directions&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;computational-significance&quot;&gt;&lt;strong&gt;Computational significance:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm foundation:&lt;/strong&gt; Most constrained optimization algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence criteria:&lt;/strong&gt; KKT residual as a stopping condition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity analysis:&lt;/strong&gt; Dual variables as shadow prices&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Problem structure:&lt;/strong&gt; Active set identification&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;when-to-use-kkt&quot;&gt;&lt;strong&gt;When to use KKT:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Analytical solutions:&lt;/strong&gt; Small problems with closed-form solutions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm design:&lt;/strong&gt; Foundation for numerical methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimality verification:&lt;/strong&gt; Check if candidate point optimal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity analysis:&lt;/strong&gt; Understand parameter changes&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;common-pitfalls&quot;&gt;&lt;strong&gt;Common pitfalls:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Forget constraint qualifications:&lt;/strong&gt; LICQ, MFCQ for necessity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Wrong complementary slackness:&lt;/strong&gt; \(\lambda_i h_i = 0\) only means that at least one of the two is 0; an active constraint can still have \(\lambda_i = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-convex problems:&lt;/strong&gt; KKT necessary but not sufficient&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical issues:&lt;/strong&gt; The KKT matrix can be ill-conditioned&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;debugging-strategies&quot;&gt;&lt;strong&gt;Debugging strategies:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Check each condition separately:&lt;/strong&gt; Stationarity, slackness, feasibility&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify constraint qualifications:&lt;/strong&gt; For necessity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Use geometric intuition:&lt;/strong&gt; Gradient orthogonality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with known solutions:&lt;/strong&gt; Simple test cases&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-advanced-topics&quot;&gt;🔬 &lt;strong&gt;Advanced Topics&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;constraint-qualifications&quot;&gt;&lt;strong&gt;Constraint qualifications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LICQ:&lt;/strong&gt; Linear Independence Constraint Qualification&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;MFCQ:&lt;/strong&gt; Mangasarian-Fromovitz Constraint Qualification&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;CPLD:&lt;/strong&gt; Constant Positive Linear Dependence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Applications:&lt;/strong&gt; When KKT conditions are necessary&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;second-order-conditions&quot;&gt;&lt;strong&gt;Second-order conditions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;SOSC:&lt;/strong&gt; Second-Order Sufficient Conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bordered Hessian:&lt;/strong&gt; For equality-constrained problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Critical cone:&lt;/strong&gt; Directions of potential descent&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Applications:&lt;/strong&gt; Algorithm convergence rates&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;variational-inequalities&quot;&gt;&lt;strong&gt;Variational inequalities:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Complementarity problems:&lt;/strong&gt; Generalize KKT conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nash equilibria:&lt;/strong&gt; Game theory applications&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Contact mechanics:&lt;/strong&gt; Engineering applications&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-real-world-applications&quot;&gt;📈 &lt;strong&gt;Real-World Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;machine-learning&quot;&gt;&lt;strong&gt;Machine Learning:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;SVM:&lt;/strong&gt; Dual formulation and support vector identification&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization:&lt;/strong&gt; L1, L2 penalties via constrained formulation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Neural networks:&lt;/strong&gt; Constrained training, fairness constraints&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;engineering&quot;&gt;&lt;strong&gt;Engineering:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Optimal control:&lt;/strong&gt; Pontryagin maximum principle&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Signal processing:&lt;/strong&gt; Filter design, beamforming&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Structural optimization:&lt;/strong&gt; Weight minimization with stress constraints&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;economics-and-finance&quot;&gt;&lt;strong&gt;Economics and Finance:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Portfolio optimization:&lt;/strong&gt; Risk-return tradeoffs&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mechanism design:&lt;/strong&gt; Incentive compatibility&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Resource allocation:&lt;/strong&gt; Utility maximization&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;operations-research&quot;&gt;&lt;strong&gt;Operations Research:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Production planning:&lt;/strong&gt; Capacity constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Supply chain:&lt;/strong&gt; Inventory optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Transportation:&lt;/strong&gt; Network flow problems&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; The KKT conditions are the &lt;strong&gt;crown jewel&lt;/strong&gt; of optimization theory - they provide an exact characterization of optimality for constrained problems and are the foundation of most modern optimization algorithms!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the Karush-Kuhn-Tucker (KKT) conditions, including practical examples such as SVM, the water-filling algorithm, quadratic programming and L1-penalized problems.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;⚖️ Quiz: KKT Conditions&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: Which components make up the KKT conditions?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Only stationarity and complementary slackness&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Stationarity, complementary slackness, primal feasibility, dual feasibility&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Only primal and dual feasibility&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Only stationarity&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Stationarity, complementary slackness, primal feasibility, dual feasibility&lt;/strong&gt;&lt;br /&gt;
                The KKT conditions have 4 components: (1) Stationarity, (2) Complementary slackness, (3) Primal feasibility, (4) Dual feasibility.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The stationarity condition in KKT has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(\nabla f(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\nabla f(x^*) + \sum \lambda_i \nabla h_i(x^*) + \sum \nu_j \nabla l_j(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(\lambda_i h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(h_i(x^*) \leq 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\nabla f(x^*) + \sum \lambda_i \nabla h_i(x^*) + \sum \nu_j \nabla l_j(x^*) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Stationarity: the gradient of the Lagrangian with respect to $$x$$ is 0, i.e. the gradient of the objective is balanced by a linear combination of the gradients of the constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: The complementary slackness condition states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(\lambda_i h_i(x^*) = 0\) for all \(i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(\lambda_i = 0\) or \(h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) If \(h_i(x^*) &amp;lt; 0\) then \(\lambda_i = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                Complementary slackness can be stated in several equivalent ways: $$\lambda_i h_i(x^*) = 0$$, or $$\lambda_i = 0$$ or $$h_i(x^*) = 0$$, or inactive constraints have dual variable = 0.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: The KKT conditions are sufficient for global optimality when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) The problem is convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) The problem is non-convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Always&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Never&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The problem is convex&lt;/strong&gt;&lt;br /&gt;
                The KKT conditions are necessary (under a constraint qualification) for every problem, but sufficient for global optimality only when the problem is convex.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: A constraint \(h_i(x) \leq 0\) is called active at \(x^*\) when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(h_i(x^*) &amp;lt; 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(\lambda_i &amp;gt; 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \(\lambda_i = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$h_i(x^*) = 0$$&lt;/strong&gt;&lt;br /&gt;
                An active constraint is one that holds with equality at the optimal point.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: In quadratic programming \(\min \frac{1}{2}x^T Q x + c^T x\) s.t. \(Ax = b\), the stationarity condition is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(Qx^* + c = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(Qx^* + c + A^T \nu^* = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(Ax^* = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(\nu^* = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$Qx^* + c + A^T \nu^* = 0$$&lt;/strong&gt;&lt;br /&gt;
                Stationarity: $$\nabla f(x^*) + A^T \nu^* = Qx^* + c + A^T \nu^* = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: In the water-filling algorithm, the optimization problem has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) \(\max \sum \log(\alpha_i + x_i)\) s.t. \(\sum x_i = P, x_i \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(\min \sum \log(\alpha_i + x_i)\) s.t. \(\sum x_i = P, x_i \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) \(\max \sum x_i^2\) s.t. \(\sum x_i = P\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(\min \sum x_i^2\) s.t. \(\sum x_i = P\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max \sum \log(\alpha_i + x_i)$$ s.t. $$\sum x_i = P, x_i \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Water-filling maximizes the sum of log capacities subject to a total power constraint and non-negativity.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The solution of the water-filling algorithm has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(x_i^* = \max(0, \mu - \alpha_i)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(x_i^* = \max(0, \alpha_i - \mu)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(x_i^* = \mu - \alpha_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(x_i^* = \alpha_i + \mu\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$x_i^* = \max(0, \mu - \alpha_i)$$&lt;/strong&gt;&lt;br /&gt;
                Water-filling solution: allocate power $$\mu - \alpha_i$$ to channel $$i$$ if $$\mu &amp;gt; \alpha_i$$, otherwise allocate 0.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The SVM primal problem has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(\min \frac{1}{2}\|w\|^2\) s.t. \(y_i(w^T x_i + b) \geq 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(\max \frac{1}{2}\|w\|^2\) s.t. \(y_i(w^T x_i + b) \geq 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(\min \sum \alpha_i\) s.t. \(\sum \alpha_i y_i = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(\max \sum \alpha_i\) s.t. \(\sum \alpha_i y_i = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\min \frac{1}{2}\|w\|^2$$ s.t. $$y_i(w^T x_i + b) \geq 1$$&lt;/strong&gt;&lt;br /&gt;
                SVM primal: minimize $$\frac{1}{2}\|w\|^2$$, i.e. maximize the margin $$2/\|w\|$$, subject to classification constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: The SVM dual problem has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(\min \sum \alpha_i - \frac{1}{2}\sum \alpha_i \alpha_j y_i y_j x_i^T x_j\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(\max \sum \alpha_i - \frac{1}{2}\sum \alpha_i \alpha_j y_i y_j x_i^T x_j\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(\min \frac{1}{2}\|w\|^2 + C\sum \xi_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(\max \frac{1}{2}\|w\|^2\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\max \sum \alpha_i - \frac{1}{2}\sum \alpha_i \alpha_j y_i y_j x_i^T x_j$$&lt;/strong&gt;&lt;br /&gt;
                SVM dual maximizes linear term minus quadratic term subject to constraints $$\sum \alpha_i y_i = 0, \alpha_i \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: Support vectors in SVM are the points with:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(\alpha_i = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(\alpha_i &amp;gt; 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(y_i(w^T x_i + b) &amp;gt; 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(y_i(w^T x_i + b) &amp;lt; 1\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\alpha_i &amp;gt; 0$$&lt;/strong&gt;&lt;br /&gt;
                Support vectors have dual variables $$\alpha_i &amp;gt; 0$$ and lie on the margin boundary: $$y_i(w^T x_i + b) = 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The Linear Independence Constraint Qualification (LICQ) requires:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) All constraints to be active&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) The gradients of the active constraints to be linearly independent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) All constraints to be inactive&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) The objective function to be differentiable&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The gradients of the active constraints to be linearly independent&lt;/strong&gt;&lt;br /&gt;
                LICQ ensures that the gradients of the active constraints at the optimal point are linearly independent, which guarantees KKT necessity.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: In the L1-penalized problem \(\min f(x) + \lambda\|x\|_1\), the KKT condition for the component \(x_i\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(\frac{\partial f}{\partial x_i} + \lambda \text{sign}(x_i) = 0\) if \(x_i \neq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(\frac{\partial f}{\partial x_i} + \lambda = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(\frac{\partial f}{\partial x_i} = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(x_i = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\frac{\partial f}{\partial x_i} + \lambda \text{sign}(x_i) = 0$$ if $$x_i \neq 0$$&lt;/strong&gt;&lt;br /&gt;
                When $$x_i \neq 0$$, the subgradient of $$|x_i|$$ is $$\text{sign}(x_i)$$. When $$x_i = 0$$, the subdifferential is $$[-1,1]$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: In L1 regularization, the solution is unique when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) \(f\) is strictly convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) \(\lambda &amp;gt; 0\) is arbitrary&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) The active set is uniquely determined&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f$$ is strictly convex&lt;/strong&gt;&lt;br /&gt;
                Strict convexity of $$f$$ guarantees uniqueness of the solution, even though the L1 term is not strictly convex.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: The KKT system for an equality-constrained QP can be written in matrix form as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(\begin{bmatrix} Q &amp;amp; A^T \\ A &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x \\ \nu \end{bmatrix} = \begin{bmatrix} -c \\ b \end{bmatrix}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(\begin{bmatrix} Q &amp;amp; A \\ A^T &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x \\ \nu \end{bmatrix} = \begin{bmatrix} -c \\ b \end{bmatrix}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(Qx = -c\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) \(Ax = b\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\begin{bmatrix} Q &amp;amp; A^T \\ A &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x \\ \nu \end{bmatrix} = \begin{bmatrix} -c \\ b \end{bmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                The KKT system combines stationarity $$Qx + c + A^T\nu = 0$$ and feasibility $$Ax = b$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: A constraint qualification is needed to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Guarantee that the KKT conditions are sufficient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Guarantee that the KKT conditions are necessary&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Guarantee that the objective is differentiable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Guarantee convexity&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Guarantee that the KKT conditions are necessary&lt;/strong&gt;&lt;br /&gt;
                A constraint qualification (LICQ, MFCQ, etc.) guarantees that the KKT conditions are necessary for local optimality.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: The second-order sufficient condition requires the Hessian of the Lagrangian to be:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Positive definite on the whole space&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Positive definite on the tangent space of the active constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Negative definite&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Singular&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Positive definite on the tangent space of the active constraints&lt;/strong&gt;&lt;br /&gt;
                The SOSC: the Hessian of the Lagrangian is positive definite on the tangent space, which guarantees a local minimum.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: The relation between KKT multipliers and penalty methods:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) The multiplier estimates of the penalty method converge to the KKT multipliers&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Penalty parameters are limits of KKT multipliers&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) There is no relation&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) They are always equal&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The multiplier estimates of the penalty method converge to the KKT multipliers&lt;/strong&gt;&lt;br /&gt;
                As the penalty parameter $$\to \infty$$, the solution of the penalized problem converges and the multiplier estimates converge to the KKT multipliers.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: KKT multipliers provide information about:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) The sensitivity of the optimal value to changes in the constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) The convergence rate of the algorithm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) The condition number of the problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) The number of iterations needed&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The sensitivity of the optimal value to changes in the constraints&lt;/strong&gt;&lt;br /&gt;
                KKT multipliers are shadow prices: they tell how much the optimal value changes when the constraint bounds change.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: KKT conditions are applied in:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Machine learning (SVM, neural networks)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Signal processing (water-filling, beamforming)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Economics (utility maximization, portfolio optimization)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above fields&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above fields&lt;/strong&gt;&lt;br /&gt;
                The KKT conditions are a fundamental tool in constrained optimization with wide applications in ML, signal processing, economics and many other fields.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: The KKT conditions consist of:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Stationarity, primal feasibility, dual feasibility, complementary slackness&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Only stationarity&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Only feasibility&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Only complementary slackness&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Stationarity, primal feasibility, dual feasibility, complementary slackness&lt;/strong&gt;&lt;br /&gt;
                KKT consists of 4 conditions: $$\nabla f + \sum \lambda_i \nabla g_i + \sum \nu_j \nabla h_j = 0$$, $$g_i(x) \leq 0$$, $$\lambda_i \geq 0$$, $$\lambda_i g_i(x) = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: The complementary slackness condition means:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$\lambda_i g_i(x) = 0$$ for all $$i$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$\lambda_i + g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$\lambda_i = g_i(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$\lambda_i \cdot g_i(x) = 1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\lambda_i g_i(x) = 0$$ for all $$i$$&lt;/strong&gt;&lt;br /&gt;
                Complementary slackness: either $$\lambda_i = 0$$ or $$g_i(x) = 0$$ (active constraint).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: Given the problem $$\min x^2$$ subject to $$x \geq 1$$. The KKT conditions at the solution $$x^* = 1$$:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$2x - \lambda = 0, \lambda \geq 0, \lambda(1-x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$2x = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$x = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$\lambda = 1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$2x - \lambda = 0, \lambda \geq 0, \lambda(1-x) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Stationarity: $$2x - \lambda = 0$$. At $$x^* = 1$$: $$\lambda = 2$$, which satisfies complementary slackness.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: LICQ (Linear Independence Constraint Qualification) requires:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) The gradients of the active constraints to be linearly independent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) All constraints to be linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) The objective function to be linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) The Hessian matrix to be invertible&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The gradients of the active constraints to be linearly independent&lt;/strong&gt;&lt;br /&gt;
                LICQ: the gradients $$\nabla g_i(x^*), \nabla h_j(x^*)$$ of the active constraints must be linearly independent.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: In a QP with KKT, the matrix of the system of equations has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} H &amp;amp; A^T \\ A &amp;amp; 0 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} H &amp;amp; 0 \\ 0 &amp;amp; A \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$H + A^T A$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$H - A^T A$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\begin{pmatrix} H &amp;amp; A^T \\ A &amp;amp; 0 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                The KKT system for a QP has a block-matrix form with the Hessian $$H$$ and the constraint matrix $$A$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;d&apos;, q4: &apos;a&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;b&apos;,
    q11: &apos;b&apos;, q12: &apos;b&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;b&apos;, q17: &apos;b&apos;, q18: &apos;a&apos;, q19: &apos;a&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered the KKT conditions and their applications!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand the optimality conditions and the practical examples well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review complementary slackness and constraint qualifications.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review the KKT conditions and stationarity.&apos;;
    } else {
        message = &apos;📖 Study KKT theory again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>12-06 Uniqueness in L1 penalized problems</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_06_Uniqueness_in_L1_penalized_problems/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_06_Uniqueness_in_L1_penalized_problems</id>
   <content type="html">&lt;p&gt;When the number of features \(p\) dramatically exceeds the number of observations \(n\) (the high-dimensional regime \(p \gg n\)), the least-squares matrix \(X^\top X\) is rank-deficient, so the Lasso objective \(\frac{1}{2}\|y - X\beta\|_2^2 + \lambda \|\beta\|_1\) is &lt;strong&gt;not strictly convex&lt;/strong&gt;! Does that mean Lasso has infinitely many different optimal coefficient vectors \(\hat{\beta}\)? Surprisingly, Ryan Tibshirani (2013) proved using the KKT conditions that even when \(p \gg n\), the Lasso solution is &lt;strong&gt;almost surely unique&lt;/strong&gt; whenever the predictors are drawn from a continuous distribution—and its fitted values \(X\hat{\beta}\) are &lt;em&gt;always&lt;/em&gt; unique!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-kkt-anatomy-of-lasso-uniqueness&quot;&gt;Key ideas: KKT Anatomy of Lasso Uniqueness&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Universal Uniqueness of Fitted Values \(X\hat{\beta}\):&lt;/strong&gt; Because \(\frac{1}{2}\|y - u\|_2^2\) is &lt;em&gt;strictly&lt;/em&gt; convex in the prediction vector \(u = X\beta\), every optimal Lasso solution \(\hat{\beta}\) must produce the &lt;strong&gt;exact same&lt;/strong&gt; fitted vector \(X\hat{\beta}\) and the &lt;strong&gt;exact same&lt;/strong&gt; \(\ell_1\) norm \(\|\hat{\beta}\|_1\)!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 2 — Equicorrelation Set \(\mathcal{E}\) from KKT Stationarity:&lt;/strong&gt; The Lasso KKT condition \(X^\top(y - X\hat{\beta}) = \lambda s\) (with \(s \in \partial |\hat{\beta}|_1\)) forces every active variable \(j\) to satisfy $$&lt;/td&gt;
          &lt;td&gt;X_j^\top(y - X\hat{\beta})&lt;/td&gt;
          &lt;td&gt;= \lambda\(. Because\)X\hat{\beta}\(is unique, the equicorrelation set\)\mathcal{E} = { j :&lt;/td&gt;
          &lt;td&gt;X_j^\top(y - X\hat{\beta})&lt;/td&gt;
          &lt;td&gt;= \lambda }\(and signs\)s_\mathcal{E}$$ are &lt;strong&gt;identical&lt;/strong&gt; across &lt;em&gt;all&lt;/em&gt; Lasso solutions!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Null-Space Uniqueness Criterion:&lt;/strong&gt; Every Lasso solution must vanish outside \(\mathcal{E}\) (\(\hat{\beta}_{-\mathcal{E}} = 0\)). Therefore, if the submatrix \(X_\mathcal{E}\) has full column rank (\(\ker(X_\mathcal{E}) = \{0\}\)), the Lasso solution \(\hat{\beta}\) is &lt;strong&gt;strictly unique&lt;/strong&gt;—even if the full matrix \(X\) has \(p = 10^6 \gg n = 100\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — General Position Condition:&lt;/strong&gt; Whenever the signed columns \(\{\pm X_j\}\) lie in &lt;em&gt;general position&lt;/em&gt; (no \(k+1\) points lie in a \((k-1)\)-dimensional affine subspace for \(k \le \min(n, p)\), which holds with probability 1 for continuous features), \(X_\mathcal{E}\) automatically has full column rank and Lasso is unique for every \(y\) and \(\lambda &amp;gt; 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-seeing-non-uniqueness-vs-uniqueness-when-p--n&quot;&gt;Worked example: Seeing Non-Uniqueness vs. Uniqueness When \(p &amp;gt; n\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider \(n = 1\) observation \(y = 4\) with \(p = 2\) predictors and \(\lambda = 1\): $$\min_{\beta \in \mathbb{R}^2} \frac{1}{2}(4 - x_1 \beta_1 - x_2 \beta_2)^2 +&lt;/td&gt;
      &lt;td&gt;\beta_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;\beta_2&lt;/td&gt;
      &lt;td&gt;$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Case A — Duplicate predictors (NOT in general position): \(X = [1,\; 1]\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Setting \(u = \beta_1 + \beta_2\), the KKT condition \(X^\top(4 - u) = 1 \cdot s\) forces \(4 - u = 1 \implies u^\star = X\hat{\beta} = 3\) (unique fitted value!).&lt;/li&gt;
      &lt;li&gt;Equicorrelation set: \(\mathcal{E} = \{1, 2\}\), so \(X_\mathcal{E} = [1, 1]\) is &lt;strong&gt;rank-deficient&lt;/strong&gt; (rank 1 &amp;lt; 2 columns)!&lt;/li&gt;
      &lt;li&gt;Consequently, &lt;em&gt;every&lt;/em&gt; nonnegative pair \(\hat{\beta} = (t, 3 - t)^\top\) for \(t \in [0, 3]\) achieves the exact same optimal objective \(\frac{1}{2}(1)^2 + 3 = 3.5\)—infinitely many Lasso solutions!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case B — Slightly perturbed predictors (in general position): \(X = [1,\; 0.9]\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Try \(\hat{\beta}_1 = 3, \hat{\beta}_2 = 0\) (so \(X\hat{\beta} = 3\), residual \(y - X\hat{\beta} = 1\)).&lt;/li&gt;
      &lt;li&gt;Check KKT correlations:
        &lt;ul&gt;
          &lt;li&gt;Feature 1: \(X_1^\top(1) = 1.0 = \lambda\) (active, \(s_1 = +1\)).&lt;/li&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;Feature 2: $$&lt;/td&gt;
                  &lt;td&gt;X_2^\top(1)&lt;/td&gt;
                  &lt;td&gt;= 0.9 &amp;lt; 1.0 = \lambda$$ (strictly inactive!).&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Now \(\mathcal{E} = \{1\}\), so \(X_\mathcal{E} = [1]\) has &lt;strong&gt;full column rank 1&lt;/strong&gt;! Even though \(p = 2 &amp;gt; n = 1\), \(\hat{\beta}^\star = (3, 0)^\top\) is the &lt;strong&gt;unique&lt;/strong&gt; global Lasso minimizer!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;The following \(L1\) penalized linear regression problem is also well known as the lasso problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;&amp;amp;&amp;amp;\hat{\beta} \in \text{argmin}_{\beta \in \mathbb{R}^p} \frac{1}{2} \| y - X\beta \|^2_2 + \lambda \|\beta\|_1, \qquad \\\\
&amp;amp;&amp;amp; \text{ --- (1) } &amp;amp;\text{given } y \in \mathbb{R}^n, \\\\
&amp;amp;&amp;amp;&amp;amp; \text{ a matrix } X \in \mathbb{R}^{n \text{ x } p} \ \text{ of predictor variables,} \\\\
&amp;amp;&amp;amp;&amp;amp; \text{and a tuning parameter} \lambda \ge 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The above Lasso problem has a unique solution when it is strictly convex, i.e., when \(rank(X) = p\). On the other hand, when \(rank(X) &amp;lt; p\) (when it is not strictly convex), it may have infinitely many solutions (Reference: &lt;a href=&quot;https://en.wikipedia.org/wiki/Underdetermined_system&quot;&gt;Underdetermined system&lt;/a&gt;).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Note that if the number of variables (p) is greater than the number of observations (n), then \(rank(X)\) is necessarily less than p.&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Interestingly, in some special cases, the Lasso problem is guaranteed to have a unique solution regardless of the dimension of \(X\) [13].&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Theorem:&lt;/strong&gt; When the function \(f\) is differentiable and strictly convex, \(\lambda &amp;gt; 0\), and \(X \in \mathbb{R}^{n \times p}\) follows some continuous probability distribution on \(\mathbb{R}^{np}\), the following optimization problem always has a unique solution. Moreover, the solution consists of at most \(min\{n,p\}\) nonzero components. There are no restrictions on the dimension of \(X\). (That is, it is valid even when p » n)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;basic-facts-and-the-kkt-conditions&quot;&gt;Basic facts and the KKT conditions&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 1.&lt;/strong&gt; For arbitrary \(y, X, \lambda \ge 0\), the lasso problem (1) has the following properties.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;It has either a unique solution or infinitely many solutions.&lt;/li&gt;
    &lt;li&gt;All lasso solutions \(\hat{\beta}\) have the same \(X\hat{\beta}\) value.&lt;/li&gt;
    &lt;li&gt;When \(\lambda &amp;gt; 0\), all lasso solutions \(\hat{\beta}\) have the same \(l_1\) norm (\(\|\hat{\beta}\|_1\)).&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;
      &lt;p&gt;If (1) has two solutions \(\hat{\beta}^{(1)}\), \(\hat{\beta}^{(2)}\), then for any \(0 &amp;lt; \alpha &amp;lt; 1\), \(\alpha \hat{\beta}^{(1)} + (1 - \alpha) \hat{\beta}^{(2)}\) is also a solution, so infinitely many solutions exist.&lt;br /&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;&amp;amp; 3. Suppose there are two solutions \(\hat{\beta}^{(1)}\), \(\hat{\beta}^{(2)}\). Let the optimal value be \(c^\star\). Then for any solution \(\alpha \hat{\beta}^{(1)} + (1 - \alpha) \hat{\beta}^{(2)}\) (\(0 &amp;lt; \alpha &amp;lt; 1\)), the following equality must always hold.&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;

  &lt;blockquote&gt;
\[\begin{align}
&amp;amp;\frac{1}{2} \| y - X(\alpha \hat{\beta}^{(1)} + (1 - \alpha) \hat{\beta}^{(2)}) \|_2^2 + \lambda \| \alpha \hat{\beta}^{(1)} + (1 - \alpha) \hat{\beta}^{(2)} \|_1 \\
&amp;amp; = \alpha c^\star + (1-\alpha) c^\star = c^\star
\end{align}\]
  &lt;/blockquote&gt;

  &lt;p&gt;To satisfy this equality, \(X\hat{\beta}\) must always have the same value for any solution \(\hat{\beta}\), and when \(\lambda &amp;gt; 0\), \(\|\hat{\beta}\|_1\) must also always be the same.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Returning to the beginning, the KKT conditions for the lasso problem (1) are as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;&amp;amp;X^T (y - X\hat{\beta}) = \lambda \gamma, \qquad \text{ --- (2)} \\\\
&amp;amp;&amp;amp;\gamma_i \in 
\begin{cases}
\{ sign(\hat{\beta_i}) \} &amp;amp; if \hat{\beta_i} \neq 0 \\\\
[-1, 1] &amp;amp; if \hat{\beta_i} = 0,
\end{cases} \\\\
&amp;amp;&amp;amp;\text{for } i = 1, \dots, p. \text{ --- (3)} \\\\
&amp;amp;&amp;amp;\text{Here } \gamma \in \mathbb{R}^p \text{ is called a subgradient of the function } \\
&amp;amp;&amp;amp;f(x) = \| x \|_1 \text{ evaluated at } x = \hat{\beta}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;That is, the solution \(\hat{\beta}\) of (1) satisfies (2) and (3) for some \(\gamma\). Let us try to use the KKT conditions obtained above to convert the condition for the lasso solution into a more explicit form. For the sake of simplicity in the subsequent derivation, we assume \(\lambda &amp;gt; 0\).&lt;/p&gt;

&lt;p&gt;First, we define the equicorrelation set \(\mathcal{E}\) as follows. \(\mathcal{E}\) is a set containing all indices \(i\) where \(\hat{\beta}_i \neq 0\) and all indices \(j\) where \(\hat{\beta}_j = 0\) and \(\vert\gamma_j\vert = 1\).&lt;/p&gt;

\[\mathcal{E} = \{ i \in \{1, \dots, p \} : \vert X_i^T (y - X\hat{\beta}) \vert = \lambda \}. \qquad \text{ --- (4)}\]

&lt;p&gt;Also, we define the equicorrelation sign \(s\) as follows. Here, \(X_\mathcal{E}\) means a matrix obtained by replacing all columns other than column \(i\) where \(i \in \mathcal{E}\) in matrix \(X\) with zero vectors.&lt;/p&gt;

\[s = sign(X^T_\mathcal{E} (y -X\hat{\beta})). \qquad \text{ --- (5)}\]

&lt;p&gt;Here, \(\mathcal{E}, s\) can be expressed as follows with respect to \(\gamma\): \(\mathcal{E} = \{i \in \{1, \dots, p \} : \vert \gamma_i \vert = 1 \}\) and \(s = \gamma_{\mathcal{E}}\). Also, by Lemma 1-2, since \(X\hat{\beta}\) has a unique value, this implies that \(\mathcal{E}\) and \(s\) are unique.&lt;/p&gt;

&lt;p&gt;By the definition of the subgradient \(\gamma\) in (3), we can see that \(\hat{\beta}_{-\mathcal{E}} = 0\) for all lasso solutions \(\hat{\beta}\). Therefore, expressing (2) for the \(\mathcal{E}\) block gives the following.&lt;/p&gt;

\[X^T_\mathcal{E} ( y - X_\mathcal{E} \hat{\beta_\mathcal{E}} ) = \lambda \gamma_\mathcal{E}= \lambda s. \qquad \text{ --- (6)}\]

&lt;p&gt;Multiplying both sides of (6) by \(X^T_\mathcal{E} (X^T_\mathcal{E})^+\) gives the following organization (\((X^T_\mathcal{E})^+\) is the pseudoinverse matrix of \(X^T_\mathcal{E}\)).&lt;/p&gt;

\[\begin{align}
&amp;amp; X^T_\mathcal{E} X_\mathcal{E} \hat{\beta_\mathcal{E}} = X^T_\mathcal{E} ( y - (X^T_\mathcal{E})^+ \lambda s) \\\\
\Leftrightarrow &amp;amp; X_\mathcal{E} \hat{\beta_\mathcal{E}} = X^T_\mathcal{E} (X^T_\mathcal{E})^+ ( y - (X^T_\mathcal{E})^+ \lambda s).
\end{align}\]

&lt;p&gt;Since \(X\hat{\beta} = X_\mathcal{E} \hat{\beta_\mathcal{E}}\), the above equation equals the following.&lt;/p&gt;

\[X \hat{\beta} = X^T_\mathcal{E} (X^T_\mathcal{E})^+ ( y - (X^T_\mathcal{E})^+ \lambda s), \qquad \text{ --- (7)}\]

&lt;p&gt;And any lasso solution \(\hat{\beta}\) is as follows.&lt;/p&gt;

\[\begin{align}
&amp;amp; \hat{\beta_{-\mathcal{E}}} = 0 \text{ and } \hat{\beta_{\mathcal{E}}} = (X^T_\mathcal{E})^+ ( y - (X^T_\mathcal{E}) + b, \qquad \text{ --- (8)} \\\\
&amp;amp; \text{where } b \in null(X_\mathcal{E}).
\end{align}\]

&lt;h2 id=&quot;sufficient-conditions-for-uniqueness&quot;&gt;Sufficient conditions for uniqueness&lt;/h2&gt;

&lt;p&gt;For the uniqueness of \(\hat{\beta_{\mathcal{E}}}\) in (8) to be guaranteed, \(b=0\) must be satisfied (because \((X^T_\mathcal{E})^+ ( y - (X^T_\mathcal{E})\) is unique). Noting that \(b=0\) must be satisfied and transforming the equation in (8), we obtain the following conclusion.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 2.&lt;/strong&gt; For arbitrary \(y, X, \lambda &amp;gt; 0\), if \(null(X_\mathcal{E}) = \{0\}\), or \(rank(X_\mathcal{E}) = \vert\mathcal{E}\vert\) (&lt;a href=&quot;https://www.quora.com/When-the-null-space-of-a-matrix-is-the-zero-vector-the-matrix-is-invertible-Why/answer/Alexander-Farrugia&quot;&gt;reference&lt;/a&gt;), then the lasso solution becomes unique, and this equals the following.&lt;/p&gt;

\[\begin{align}
&amp;amp;&amp;amp; \hat{\beta_{-\mathcal{E}}} = 0 \text{ and } \hat{\beta_{\mathcal{E}}} = (X^T_\mathcal{E}X^T_\mathcal{E})^{-1} ( X^T_\mathcal{E} y - \lambda s), \qquad \text{ --- (9)} \\\\
&amp;amp;&amp;amp; \text{where } \mathcal{E} \text{ and } s \text{ are the equicorrelation set and signs as defined in (4) and (5)}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;As a reference, this solution consists of at most \(min\{n, p\}\) nonzero components.&lt;/p&gt;

&lt;p&gt;So what more natural condition (for \(X\)) implies \(null(X_\mathcal{E}) = \{0\}\)? Let us first assume \(null(X_\mathcal{E}) \neq \{0\}\) before exploring this. In this case, for some \(i \in \mathcal{E}\), the following equation is satisfied.&lt;/p&gt;

\[X_i = \sum_{j \in \mathcal{E} \backslash \{i\} } c_j X_j,\\\\
\text{where } c_j \in \mathbb{R}, j \in \mathcal{E}.\]

&lt;p&gt;Multiplying both sides of the above equation by \(s_i\) and multiplying the right side by \(s_j s_j = 1\).&lt;/p&gt;

\[s_i X_i = \sum_{j \in \mathcal{E} \backslash \{i\} } (s_i s_j c_j) \cdot (s_j X_j). \qquad \text{ --- (10)}\]

&lt;p&gt;If we define \(r = y - X \hat{\beta}\) as \(r\) (lasso residual), then for any \(j \in \mathcal{E}\), \(X_j^T r = s_j \lambda\) is satisfied. Multiplying \(r\) to both sides of (10) above gives an inequality for \(\lambda\). (assuming \(\lambda &amp;gt; 0\))&lt;/p&gt;

\[\lambda = \sum_{j \in \mathcal{E} \backslash \{i\} } (s_i s_j c_j) \lambda \quad \text{ and } \quad \sum_{j \in \mathcal{E} \backslash \{i\} } (s_i s_j c_j) = 1.\]

&lt;p&gt;That is, if \(null(X_\mathcal{E}) \neq \{0\}\), then for some \(i \in \mathcal{E}\), the following equation holds.&lt;/p&gt;

\[s_iX_i = \sum_{j \in \mathcal{E} \backslash \{i\} } a_j \cdot s_j X_j, \text{ with } \sum_{j \in \mathcal{E} \backslash \{i\} } a_j = 1.\]

&lt;p&gt;The above equation means that \(s_iX_i\) exists on the affine span of \(s_j X_j, j \in \mathcal{E} \backslash \{i\}\). Also, this means that any subset containing k+2 elements can represent only a maximum k-dimensional affine space.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter12/l1_uniqueness.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] 4 elements on 2-dimensional affine space [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;What we want is for matrix \(X \in \mathbb{R}^{n \text{ x } p}\) to satisfy \(null(X_\mathcal{E}) = \{0\}\), which means that the columns of matrix \(X\) are in &lt;a href=&quot;https://en.wikipedia.org/wiki/General_position&quot;&gt;general position&lt;/a&gt;. In other words, no k-dimensional affine subspace contains more than k+1 elements in the set.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 3.&lt;/strong&gt; If the columns of matrix \(X\) are in general position, then the lasso solution for arbitrary \(y\) and \(\lambda &amp;gt; 0\) is unique. Also, this solution satisfies (9).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So what matrix \(X\) can always satisfy the above condition? The conclusion is as follows.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 4.&lt;/strong&gt; If all elements of matrix \(X \in \mathbb{R}^{n \text{ x } p}\) follow a continuous probability distribution on \(\mathbb{R}^{np}\), then the lasso solution for arbitrary \(y\) and \(\lambda &amp;gt; 0\) is unique and always satisfies (9).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because when following a continuous probability distribution, all column vectors are linearly independent. (&lt;a href=&quot;https://math.stackexchange.com/questions/432447/probability-that-n-vectors-drawn-randomly-from-mathbbrn-are-linearly-ind?rq=1&quot;&gt;reference&lt;/a&gt;)&lt;/p&gt;

&lt;h2 id=&quot;general-convex-loss-functions&quot;&gt;General convex loss functions&lt;/h2&gt;

&lt;p&gt;The same content can be applied to more general lasso problems [13].&lt;/p&gt;

\[\hat{\beta} \in \text{argmin}_{\beta \in \mathbb{R}^p} f(X\beta) + \lambda \|\beta\|_1, \qquad \text{ --- (11) }\]

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 5.&lt;/strong&gt; If all elements of matrix \(X \in \mathbb{R}^{n \text{ x } p}\) follow a continuous probability distribution on \(\mathbb{R}^{np}\), then any differentiable and strictly convex function \(f\) guarantees a unique solution for the problem in (11) for any \(\lambda &amp;gt; 0\). This solution consists of at most \(min\{n,p\}\) nonzero components.&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>12-05 Constrained and Lagrange forms</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_05_Constrained_and_Lagrange_forms/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_05_Constrained_and_Lagrange_forms</id>
   <content type="html">&lt;p&gt;Open two statistics textbooks on Lasso or Ridge regression and you will see two seemingly different optimization problems: one minimizes loss subject to a hard norm budget \(\|\beta\|_1 \le t\) (&lt;strong&gt;Constrained form&lt;/strong&gt;), while the other minimizes loss plus a penalty \(\lambda \|\beta\|_1\) (&lt;strong&gt;Lagrange form&lt;/strong&gt;). Are these two problems really the same? Using the KKT conditions, this lesson proves a clean, exact equivalence—and flags the one subtle edge case (strictly non-binding budgets vs. zero multipliers) where the two forms part ways!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-bridging-constrained-c-and-lagrange-l-forms&quot;&gt;Key ideas: Bridging Constrained (C) and Lagrange (L) Forms&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Comparing the Two Stationarity Equations:&lt;/strong&gt; For convex \(f, h\), the constrained form \(\min \{ f(x) : h(x) \le t \}\) has KKT stationarity \(0 \in \partial f(x^\star) + \lambda^\star \partial h(x^\star)\) with \(\lambda^\star \ge 0\) and \(\lambda^\star(h(x^\star) - t) = 0\); the unconstrained Lagrange form \(\min_x f(x) + \lambda h(x)\) has stationarity \(0 \in \partial f(x^\star) + \lambda \partial h(x^\star)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — From (C) to (L) via Slater’s Condition:&lt;/strong&gt; If \(x^\star\) solves (C) and Slater’s condition holds, KKT guarantees a multiplier \(\lambda^\star \ge 0\) such that \(0 \in \partial f(x^\star) + \lambda^\star \partial h(x^\star)\), meaning \(x^\star\) &lt;em&gt;also&lt;/em&gt; solves (L) for \(\lambda = \lambda^\star\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — From (L) to (C) via Tight Budget \(t = h(x^\star)\):&lt;/strong&gt; Conversely, if \(x^\star\) solves (L) for some \(\lambda \ge 0\), simply setting \(t = h(x^\star)\) makes primal feasibility (\(h(x^\star) \le t\)) and complementary slackness (\(\lambda(h(x^\star) - t) = 0\)) hold &lt;em&gt;identically&lt;/em&gt;, so \(x^\star\) solves (C) with \(t = h(x^\star)\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Subtle Caveat (Why the Mapping \(\lambda \leftrightarrow t\) Is Not Always 1-to-1):&lt;/strong&gt; If \(f\) is not strictly convex (or if \(t\) exceeds the unconstrained minimum’s norm), a single \(\lambda\) can correspond to a &lt;em&gt;whole set&lt;/em&gt; of solutions with different values of \(h(x)\), and for nonconvex \(f, h\), the Lagrange form can actually &lt;em&gt;miss&lt;/em&gt; constrained optima located on nonconvex dents of the Pareto frontier!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-mapping-lambda-leftrightarrow-t-explicitly-on-1d-ridge-regression&quot;&gt;Worked example: Mapping \(\lambda \leftrightarrow t\) Explicitly on 1D Ridge Regression&lt;/h3&gt;

&lt;p&gt;Let \(f(x) = \frac{1}{2}(x - 4)^2\) and \(h(x) = \frac{1}{2}x^2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the Lagrange Form (L) for any \(\lambda \ge 0\):&lt;/strong&gt;
\(\min_x\; \frac{1}{2}(x - 4)^2 + \frac{\lambda}{2} x^2 \implies (x - 4) + \lambda x = 0 \implies x_L^\star(\lambda) = \frac{4}{1 + \lambda}.\)
    &lt;ul&gt;
      &lt;li&gt;For \(\lambda = 1\): \(x_L^\star(1) = \frac{4}{2} = 2\), with \(h(2) = \frac{1}{2}(2^2) = 2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Solve the Constrained Form (C) with budget \(t = 2\) (i.e., $$\frac{1}{2}x^2 \le 2 \iff&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;\le 2$$):**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Since the unconstrained minimum \(x = 4\) lies outside \([-2, 2]\), the constraint binds at \(x_C^\star(2) = 2\)!&lt;/li&gt;
      &lt;li&gt;KKT stationarity: \((2 - 4) + \lambda^\star (2) = 0 \implies \lambda^\star = 1\)—recovering the exact Lagrange parameter!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Check the non-binding regime ($$t = 12 \implies&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;\le \sqrt{24} \approx 4.90$$):**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Now \(x = 4\) is strictly feasible (\(h(4) = 8 &amp;lt; 12\)), so complementary slackness forces \(\lambda^\star = 0\) for &lt;em&gt;every&lt;/em&gt; \(t \ge 8\)—confirming that \(\lambda(t) = \max\!\left(0,\; \frac{4}{\sqrt{2t}} - 1\right)\) maps \(t \in (0, 8]\) bijectively onto \(\lambda \in [0, \infty)\) and collapses all \(t \ge 8\) onto \(\lambda = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In statistics and machine learning, we often move between &lt;strong&gt;constrained form&lt;/strong&gt; and &lt;strong&gt;Lagrange form&lt;/strong&gt;. Let us define the constrained form and Lagrangian form as follows.&lt;/p&gt;

&lt;h3 id=&quot;constrained-form-c-hereafter&quot;&gt;Constrained Form ((C) hereafter)&lt;/h3&gt;

&lt;blockquote&gt;
\[\min_x \: f(x) \quad \text{ subject to } h(x) \le t,\\\\
\text{where } t \in \mathbb{R} \text{ is a tuning parameter.}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;lagrange-form-l-hereafter&quot;&gt;Lagrange Form ((L) hereafter)&lt;/h3&gt;

&lt;blockquote&gt;
\[\min_x \: f(x) + \lambda \cdot h(x),\\\\
\text{where } \lambda \ge 0 \text{ is a tuning parameter.}\]
&lt;/blockquote&gt;

&lt;p&gt;When \(f, h\) are convex, let us examine the cases where the two problems yield the same solution.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;(C) to (L):&lt;/strong&gt; When (C) is strictly feasible (satisfies Slater’s condition) and satisfies strong duality, if there exists a dual solution \(\lambda^\star \ge 0\) that minimizes the following objective function for the solution \(x^\star\) of (C), then \(x^\star\) is also a solution of (L).&lt;/li&gt;
&lt;/ol&gt;

\[f(x) + \lambda \cdot (h(x) - t)\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;(L) to (C):&lt;/strong&gt; If \(x^\star\) is a solution of (L) and (C) with \(t = h(x^\star)\) satisfies the KKT conditions, then \(x^\star\) is also a solution of (C). This is because \(\lambda^\star, x^\star\) that satisfy the KKT conditions of (L) also satisfy the KKT conditions of (C) with \(t = h(x^\star)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;\(\rightarrow\) KKT conditions of (L):&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\nabla_x f(x^\star) + \lambda^\star \nabla_x h(x^\star) &amp;amp;= 0\\\\
\lambda^\star &amp;amp;\ge 0\\\\
\end{align}\]

  &lt;p&gt;&lt;strong&gt;\(\rightarrow\) KKT conditions of (C) with \(t = h(x^\star)\):&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\nabla_x f(x^\star) + \lambda^\star \nabla_x h(x^\star) &amp;amp;= 0\\\\
\lambda^\star &amp;amp;\ge 0\\\\
\lambda^\star (\underbrace{h(x^\star) - h(x^\star)}_{=0}) &amp;amp;= 0
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In conclusion, 1 and 2 show the following relationships respectively.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter12/conclusion.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Conclusion [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;So, under what circumstances do (C) and (L) show perfect equivalence?&lt;br /&gt;
For example, when \(h(x) \ge 0\) (such as norm), \(t = 0\), and \(\lambda = \infty\), perfect equivalence is shown. Due to the given conditions, the constraint in (C) becomes \(h(x) = 0\), and by setting \(\lambda\) to \(\infty\), (L) also imposes the same constraint (\(h(x) = 0\)).&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-constrained-vs-lagrange-form&quot;&gt;Try it yourself: constrained vs. Lagrange form&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;cl&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>12-04 Example support vector machines</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_04_Example_support_vector_machines/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_04_Example_support_vector_machines</id>
   <content type="html">&lt;p&gt;Why are Support Vector Machines named after &lt;em&gt;support vectors&lt;/em&gt;—and how can a classifier trained on 100,000 data points depend on just a tiny handful of critical boundary examples? The answer is pure KKT complementary slackness! Writing down the KKT system for the soft-margin SVM QP reveals in four lines why \(\beta^\star = \sum_{i=1}^n w_i^\star y_i x_i\) is a sparse linear combination of training points, why points safely outside the margin have \(w_i^\star = 0\), and how margin points pin down the intercept \(\beta_0^\star\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-reading-svm-geometry-directly-from-kkt&quot;&gt;Key ideas: Reading SVM Geometry Directly from KKT&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Stationarity Produces the Representer Formula:&lt;/strong&gt; Differentiating the soft-margin SVM Lagrangian with respect to \(\beta, \beta_0, \xi_i\) gives three gold-mine equations: \(\beta^\star = \sum_{i=1}^n w_i^\star y_i x_i\), \(\sum_{i=1}^n w_i^\star y_i = 0\), and \(w_i^\star + v_i^\star = C\) (hence \(0 \le w_i^\star \le C\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Complementary Slackness Partitions All Data into 3 Regimes:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Strictly outside the margin&lt;/em&gt; (\(y_i(x_i^\top \beta^\star + \beta_0^\star) &amp;gt; 1\)): forces \(w_i^\star = 0\) and \(\xi_i^\star = 0\) (ignored completely by the classifier!).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;On the margin boundary&lt;/em&gt; (\(y_i(x_i^\top \beta^\star + \beta_0^\star) = 1,\; \xi_i^\star = 0\)): allows \(0 &amp;lt; w_i^\star &amp;lt; C\) (&lt;strong&gt;free support vectors&lt;/strong&gt;!).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Inside/violating the margin&lt;/em&gt; (\(\xi_i^\star &amp;gt; 0\)): forces \(v_i^\star = 0 \implies w_i^\star = C\) (&lt;strong&gt;bounded support vectors&lt;/strong&gt;!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Recovering the Intercept \(\beta_0^\star\):&lt;/strong&gt; Any free support vector (\(0 &amp;lt; w_i^\star &amp;lt; C\)) has \(\xi_i^\star = 0\) and tight margin \(y_i(x_i^\top \beta^\star + \beta_0^\star) = 1\), immediately giving \(\beta_0^\star = y_i - x_i^\top \beta^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Dual Sparsity &amp;amp; Computational Payoff:&lt;/strong&gt; Because non-support vectors drop out of \(\beta^\star\) completely, removing them from the training set does &lt;em&gt;not&lt;/em&gt; change the optimal hyperplane by a single millimeter!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-identifying-support-vectors--multipliers-on-a-3-point-1d-dataset&quot;&gt;Worked example: Identifying Support Vectors &amp;amp; Multipliers on a 3-Point 1D Dataset&lt;/h3&gt;

&lt;p&gt;Consider 3 labeled 1D training points with \(C = 2\):
\((x_1, y_1) = (-2, -1), \quad (x_2, y_2) = (0, -1), \quad (x_3, y_3) = (2, +1).\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find the maximum-margin linear separator by geometry:&lt;/strong&gt;
The negative points sit at \(x \le 0\) and the positive point sits at \(x = 2\), so the midpoint is \(x = 1\) with half-margin \(1\): \(\beta^\star = 1,\; \beta_0^\star = -1\) (decision function \(f(x) = x - 1\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check functional margins \(y_i(\beta^\star x_i + \beta_0^\star)\) and slacks \(\xi_i^\star\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Point 1 (\(x_1 = -2, y_1 = -1\)): \((-1)(-2 - 1) = +3 &amp;gt; 1\) (strictly outside margin \(\implies \xi_1^\star = 0,\; w_1^\star = 0\)!).&lt;/li&gt;
      &lt;li&gt;Point 2 (\(x_2 = 0, y_2 = -1\)): \((-1)(0 - 1) = +1\) (on the margin \(\implies \xi_2^\star = 0\), free support vector!).&lt;/li&gt;
      &lt;li&gt;Point 3 (\(x_3 = 2, y_3 = +1\)): \((+1)(2 - 1) = +1\) (on the margin \(\implies \xi_3^\star = 0\), free support vector!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve for the KKT multipliers \(w_2^\star, w_3^\star\) via stationarity:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\sum w_i^\star y_i = -w_2^\star + w_3^\star = 0 \implies w_2^\star = w_3^\star\).&lt;/li&gt;
      &lt;li&gt;\(\beta^\star = \sum w_i^\star y_i x_i = w_2^\star(-1)(0) + w_3^\star(+1)(2) = 2w_3^\star = 1 \implies w_3^\star = 0.5,\; w_2^\star = 0.5\).&lt;/li&gt;
      &lt;li&gt;Dual feasibility check: \(0 \le w_i^\star = 0.5 &amp;lt; C = 2\) and \(v_i^\star = C - w_i^\star = 1.5 &amp;gt; 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Point 1 (\(w_1^\star = 0\)) is completely irrelevant, while Points 2 and 3 (\(w_2^\star = w_3^\star = 0.5\)) are the exact support vectors holding the hyperplane in place!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;The support vector machine problem for non-separable sets is as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{\beta, \beta-0, \xi} &amp;amp;&amp;amp;{\frac{1}{2} \rVert\beta\rVert_2^2 + C\sum_{i=1}^n \xi_i} \\\\
   &amp;amp;\text{subject to} &amp;amp;&amp;amp;{\xi_i \ge 0, \quad i = 1, \dots, n}\\\\
   &amp;amp; &amp;amp;&amp;amp; y_i (x_i^T \beta + \beta-0) \ge 1 - \xi_i, \quad i = 1, \dots, n,\\\\
&amp;amp;&amp;amp;&amp;amp;\text{given } y \in \{-1, 1\}^n \text{ and } X \in \mathbb{R}^{n \times p}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;When the Lagrange multipliers for the two inequality constraints of the given problem are \(v^\star, w^\star \geq 0\) respectively, the Lagrangian function is as follows.&lt;/p&gt;
&lt;blockquote&gt;
\[L(\beta, \beta-0, \xi, v^\star, w^\star) = \frac{1}{2} \rVert\beta\rVert_2^2 + C\sum_{i=1}^n \xi_i - \sum_{i=1}^n v_i^\star \xi_i + \sum_{i=1}^n w_i^\star (1 - \xi_i - y_i ( x_i^T \beta + \beta_0))\]
&lt;/blockquote&gt;

&lt;p&gt;Using the above Lagrangian function, we can find the following conditions that make this problem satisfy the KKT stationarity condition. (Derive the conditions where the Lagrangian function becomes 0 when differentiated with respect to \(\beta, \beta_0, \xi\) respectively)&lt;/p&gt;
&lt;blockquote&gt;
\[0 = \sum_{i=1}^n w_i^\star y_i, \quad \beta = \sum_{i=1}^n w_i^\star y_i x_i, \quad w^\star = C \cdot 1 - v^\star\]
&lt;/blockquote&gt;

&lt;p&gt;Also, complementary slackness for the two inequality constraints is as follows.&lt;/p&gt;
&lt;blockquote&gt;
\[v_i^\star \xi_i = 0, \quad w_i^\star (1 - \xi_i - y_i (x_i^T \beta + \beta-0)) =0, \quad 1 = 1, \dots, n.\]
&lt;/blockquote&gt;

&lt;p&gt;That is, at optimality, \(\beta^\star = \sum_{i=1}^n w_i^\star y_i x_i\) is satisfied, and when \(y_i (x_i^T \beta^\star + \beta-0^\star) = 1 - \xi_i^\star\), \(w_i^\star\) becomes nonzero, and such point i is called &lt;strong&gt;support points&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For a support point i where \(\xi_i^\star = 0\), \(x_i\) is located on the hyperplane and \(w_i^\star \in (0, C]\).&lt;/li&gt;
  &lt;li&gt;For a support point i where \(\xi_i^\star \neq 0\), \(x_i\) is located on the opposite side of the hyperplane and \(w_i^\star = C\).&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter12/svm.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$ \text{[Fig1] Illustration of support points with }\ \xi^\star \neq 0 \text{ [3]}$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Before optimizing the SVM problem, the above method can be used to filter out non-support points (filtering out non-support points can improve computational efficiency). In fact, KKT conditions do not play a direct role in deriving the solution to this problem, but we can gain intuition to better understand the SVM problem through them [3].&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>12-03 Example water-filling</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_03_Example_water_filling/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_03_Example_water_filling</id>
   <content type="html">&lt;p&gt;Imagine you are a wireless communications engineer with 1 watt of total transmission power to distribute across \(n\) parallel radio channels, each corrupted by a different background noise level \(\alpha_i &amp;gt; 0\). By Shannon’s capacity theorem, allocating power \(x_i \ge 0\) to channel \(i\) yields throughput \(\log(\alpha_i + x_i)\). Should you dump all power into the cleanest channel, or spread it equally? Applying the KKT conditions produces one of the most iconic physical metaphors in all of engineering: &lt;strong&gt;water-filling&lt;/strong&gt;—pour a unit volume of water into a vessel whose floor height in bin \(i\) is \(\alpha_i\), and the water depth in each bin &lt;em&gt;is&lt;/em&gt; the exact optimal power \(x_i^\star\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-kkt-anatomy-of-water-filling&quot;&gt;Key ideas: The KKT Anatomy of Water-Filling&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Convexity &amp;amp; Slater’s Condition:&lt;/strong&gt; Minimizing \(-\sum_{i=1}^n \log(\alpha_i + x_i)\) over the simplex \(x \ge 0, \mathbf{1}^\top x = 1\) is strictly convex (since \(-\log\) is strictly convex) and satisfies Slater’s condition (take \(x_i = 1/n &amp;gt; 0\)), so KKT is both necessary and sufficient for the unique global optimum.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Stationarity Gives the Water Level \(w = 1/\nu^\star\):&lt;/strong&gt; Differentiating \(L(x, \lambda, \nu) = -\sum \log(\alpha_i + x_i) - \lambda^\top x + \nu(\mathbf{1}^\top x - 1)\) gives \(-\frac{1}{\alpha_i + x_i^\star} - \lambda_i^\star + \nu^\star = 0 \implies \lambda_i^\star = \nu^\star - \frac{1}{\alpha_i + x_i^\star} \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Complementary Slackness Splits Flooded vs. Dry Channels:&lt;/strong&gt; From \(\lambda_i^\star x_i^\star = 0\):
    &lt;ul&gt;
      &lt;li&gt;If channel \(i\) receives positive power (\(x_i^\star &amp;gt; 0\)), then \(\lambda_i^\star = 0 \implies \alpha_i + x_i^\star = \frac{1}{\nu^\star}\) (all active channels share the &lt;em&gt;same&lt;/em&gt; water surface height \(w = 1/\nu^\star\)!).&lt;/li&gt;
      &lt;li&gt;If channel \(i\) is too noisy (\(\alpha_i \ge 1/\nu^\star\)), then \(x_i^\star = 0\) (it stays completely dry!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Closed-Form Solution via 1D Root-Finding:&lt;/strong&gt; Combining both cases gives \(x_i^\star = \max\!\left(0,\; \frac{1}{\nu^\star} - \alpha_i\right)\), reducing an \(n\)-dimensional nonlinear optimization problem to finding a single scalar water level \(w = 1/\nu^\star\) such that \(\sum_{i=1}^n \max(0, w - \alpha_i) = 1\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-exact-water-filling-powers-across-3-channels&quot;&gt;Worked example: Computing Exact Water-Filling Powers Across 3 Channels&lt;/h3&gt;

&lt;p&gt;Allocate total power \(\sum_{i=1}^3 x_i = 1\) across three channels with noise floors \(\alpha_1 = 0.2,\; \alpha_2 = 0.5,\; \alpha_3 = 1.0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test if all 3 channels are flooded (\(w &amp;gt; \alpha_3 = 1.0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;If \(w &amp;gt; 1.0\), total water volume would be \((w - 0.2) + (w - 0.5) + (w - 1.0) &amp;gt; 0.8 + 0.5 + 0 = 1.3 &amp;gt; 1.0\)! Too much water—Channel 3 must stay &lt;strong&gt;dry&lt;/strong&gt; (\(x_3^\star = 0\))!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test if Channels 1 and 2 are flooded (\(0.5 &amp;lt; w \le 1.0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Total water volume: \((w - 0.2) + (w - 0.5) = 1.0 \implies 2w - 0.7 = 1.0 \implies 2w = 1.7 \implies w^\star = 0.85\).&lt;/li&gt;
      &lt;li&gt;Check the bracket: \(0.5 &amp;lt; 0.85 \le 1.0\) (exact fit!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Read off the optimal powers and KKT multipliers (\(\nu^\star = 1/w^\star = 1/0.85 = 20/17 \approx 1.1765\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x_1^\star = 0.85 - 0.2 = 0.65\), \(\lambda_1^\star = 0\).&lt;/li&gt;
      &lt;li&gt;\(x_2^\star = 0.85 - 0.5 = 0.35\), \(\lambda_2^\star = 0\).&lt;/li&gt;
      &lt;li&gt;\(x_3^\star = 0\), \(\lambda_3^\star = \nu^\star - \frac{1}{1.0} = \frac{20}{17} - 1 = \frac{3}{17} &amp;gt; 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify all KKT conditions:&lt;/strong&gt; \(x^\star \ge 0\), \(0.65 + 0.35 + 0 = 1\), \(\lambda^\star \ge 0\), \(\lambda_i^\star x_i^\star = 0\) for all \(i\), and \(\alpha_1 + x_1^\star = \alpha_2 + x_2^\star = 0.85\)—confirming exact global optimality!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Suppose we have the following convex optimization problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{x} &amp;amp;&amp;amp;{- \sum_{i=1}^n \log(\alpha_i + x_i)} \\\\
   &amp;amp;\text{subject to} &amp;amp;&amp;amp;{x \succeq 0, 1^Tx = 1},\\\\
&amp;amp;\text{where } \alpha_i &amp;gt; 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This problem is about allocating power to n communication channels and arose in information theory. The variable \(x_i\) represents the output of the transmitter allocated to the i-th channel, and \(\log(\alpha_i + x_i)\) represents the capacity or communication rate of that channel. That is, this problem is to determine how much power should be allocated to each channel to maximize the total communication rate [1].&lt;/p&gt;

&lt;p&gt;Let the Lagrange multipliers for the inequality constraint \(x^\star \succeq 0\) and equality constraint \(1^Tx^\star = 1\) be \(\lambda^\star \in \mathbb{R}^n\) and \(\nu^\star \in \mathbb{R}\) respectively. The KKT conditions for the given problem are as follows.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x^\star \succeq 0, \\\\
1^Tx^\star = 1, \\\\
\lambda^\star \succeq 0, \\\\
\lambda_i^\star x_i^\star = 0, \text{    } i = 1, \dots, n, \\\\
-1 / (\alpha_i + x_i^\star) - \lambda_i^\star + \nu^\star = 0,  \text{    } i= 1, \dots, n.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Using the equations obtained from KKT conditions, we can find \(x^\star, \lambda^\star, \nu^\star\) analytically. First, we eliminate \(\lambda^\star\) from the equations using it as a slack variable.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x^\star \succeq 0, \\\\
1^Tx^\star = 1, \\\\
x_i^\star(\nu^\star - 1 / (\alpha_i + x_i^\star)) = 0, \text{    } i = 1, \dots, n, \\\\
\nu^\star \ge 1/(\alpha_i + x_i^\star),  \text{    } i= 1, \dots, n.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This is organized as follows by stationarity and complementary slackness.&lt;/p&gt;
&lt;blockquote&gt;
\[x_i^\star = 
\begin{cases}
1 / \nu^\star - \alpha_i &amp;amp;\nu^\star &amp;lt; 1/\alpha_i \ \\\\
0 &amp;amp;\nu^\star \ge 1/\alpha_i\\\\
\end{cases}
= \max\{0, 1/\nu^\star - \alpha_i \}, \quad i = 1, \dots, n.\]
&lt;/blockquote&gt;

&lt;p&gt;Also, by the condition \(1^T x^\star = 1\), \(x_i^\star, i = 1, \dots, n\) sum to 1.&lt;/p&gt;
&lt;blockquote&gt;
\[\sum_{i=1}^n \max\{0, 1/\nu^\star - \alpha_i \} = 1.\]
&lt;/blockquote&gt;

&lt;p&gt;The left side of the equation is a piecewise-linear increasing function of \(1/\nu^\star\), so this equation has a unique solution for fixed \(\alpha_i\).&lt;/p&gt;

&lt;p&gt;This solution method is called water-filling. When \(\alpha_i\) is the ground level for patch \(i\), this problem can be thought of as pouring water into each region so that the water level becomes \(1/\nu^\star\) as shown in the figure below. We pour water until the total amount of water becomes 1.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter12/water-fill.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Illustration of water-filling algorithm [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;kkt-through-water-filling-in-about-3-minutes&quot;&gt;KKT through water-filling in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/kkt-water-filling_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Solving water-filling with α = (0.1, 0.4, 0.8, 1.2) through the four KKT conditions, reading the meaning of λ, and three wrong guesses that KKT rules out.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>12-02 Example quadratic with equality constraints</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_02_Example_quadratic_with_equality_constraints/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_02_Example_quadratic_with_equality_constraints</id>
   <content type="html">&lt;p&gt;Equality-constrained quadratic programs—minimizing \(\frac{1}{2}x^\top P x + q^\top x + r\) subject to \(Ax = b\)—are the workhorse subproblems inside Newton’s method, interior-point solvers, portfolio optimization (Markowitz mean-variance), and Model Predictive Control. Because there are no inequality constraints at all, complementary slackness and dual sign restrictions vanish completely, and the KKT conditions collapse into a single linear block system called the &lt;strong&gt;KKT matrix equation&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-equality-constrained-qps--the-kkt-linear-system&quot;&gt;Key ideas: Equality-Constrained QPs &amp;amp; the KKT Linear System&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Exact Equivalence to a Linear System:&lt;/strong&gt; For \(P \succeq 0\), the problem is convex with affine constraints (Slater holds trivially whenever \(Ax = b\) is feasible). Thus \(x^\star\) is optimal &lt;em&gt;if and only if&lt;/em&gt; there exists \(v^\star \in \mathbb{R}^p\) satisfying \(P x^\star + A^\top v^\star = -q\) (stationarity) and \(A x^\star = b\) (primal feasibility).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Saddle-Point Block Matrix Structure:&lt;/strong&gt; Writing both equations together gives the symmetric \((n+p) \times (n+p)\) KKT matrix \(\begin{pmatrix} P &amp;amp; A^\top \\ A &amp;amp; 0 \end{pmatrix} \begin{pmatrix} x^\star \\ v^\star \end{pmatrix} = \begin{pmatrix} -q \\ b \end{pmatrix}\). Even when \(P \succ 0\), this matrix is &lt;em&gt;indefinite&lt;/em&gt; (having positive and negative eigenvalues), reflecting the primal-min / dual-max saddle structure.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Nonsingularity &amp;amp; Uniqueness:&lt;/strong&gt; When \(P \succ 0\) and \(A\) has full row rank \(p\), the KKT matrix is nonsingular and we can eliminate \(x^\star = -P^{-1}(q + A^\top v^\star)\) via the Schur complement \(A P^{-1} A^\top v^\star = -(b + A P^{-1} q)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Null-Space Interpretation When \(P\) Is Singular:&lt;/strong&gt; Even if \(P \succeq 0\) is singular, the KKT matrix remains nonsingular whenever \(P\) is strictly positive definite on \(\ker(A)\) (i.e., \(z^\top P z &amp;gt; 0\) for all nonzero \(z\) with \(Az = 0\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-a-2-times-2-equality-constrained-qp-via-the-kkt-matrix&quot;&gt;Worked example: Solving a \(2 \times 2\) Equality-Constrained QP via the KKT Matrix&lt;/h3&gt;

&lt;p&gt;Minimize \(\frac{1}{2}(2x_1^2 + 4x_2^2) - 2x_1\) subject to \(x_1 + x_2 = 3\).
Here \(P = \begin{pmatrix}2 &amp;amp; 0 \\ 0 &amp;amp; 4\end{pmatrix}\), \(q = \begin{pmatrix}-2 \\ 0\end{pmatrix}\), \(A = \begin{pmatrix}1 &amp;amp; 1\end{pmatrix}\), \(b = (3)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Assemble the \(3 \times 3\) KKT linear system:&lt;/strong&gt;
\(\begin{pmatrix} 2 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 4 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{pmatrix} \begin{pmatrix} x_1^\star \\ x_2^\star \\ v^\star \end{pmatrix} = \begin{pmatrix} 2 \\ 0 \\ 3 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Express \(x_1^\star, x_2^\star\) in terms of the multiplier \(v^\star\) from the first two rows:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Row 1: \(2x_1^\star + v^\star = 2 \implies x_1^\star = 1 - \frac{v^\star}{2}\).&lt;/li&gt;
      &lt;li&gt;Row 2: \(4x_2^\star + v^\star = 0 \implies x_2^\star = -\frac{v^\star}{4}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Substitute into Row 3 (primal feasibility \(x_1^\star + x_2^\star = 3\)):&lt;/strong&gt;
\(\left(1 - \frac{v^\star}{2}\right) + \left(-\frac{v^\star}{4}\right) = 3 \implies 1 - \frac{3}{4} v^\star = 3 \implies -\frac{3}{4} v^\star = 2 \implies v^\star = -\frac{8}{3}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Back-substitute to recover the exact optimal primal solution:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x_1^\star = 1 - \frac{-8/3}{2} = 1 + \frac{4}{3} = \frac{7}{3}\).&lt;/li&gt;
      &lt;li&gt;\(x_2^\star = -\frac{-8/3}{4} = \frac{2}{3}\).&lt;/li&gt;
      &lt;li&gt;Check feasibility: \(\frac{7}{3} + \frac{2}{3} = \frac{9}{3} = 3\)! Check stationarity: \(\nabla f(x^\star) = (2(7/3) - 2,\; 4(2/3))^\top = (8/3,\; 8/3)^\top = -v^\star (1, 1)^\top\)—perfectly orthogonal to the constraint line \(x_1 + x_2 = 3\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;A &lt;a href=&quot;&quot;&gt;quadratic program&lt;/a&gt; with only equality constraints is as follows.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{x} &amp;amp;&amp;amp;{(1/2)x^T P x + q^T x + r} \\\\
   &amp;amp;\text{subject to} &amp;amp;&amp;amp;{Ax = b},\\\\
&amp;amp;\text{where } &amp;amp;&amp;amp;P \in \mathbb{S}_{+}^n \text{ and } A \in \mathbb{R}^{\text{p x n}}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This problem is convex and has no inequality constraints, so it satisfies Slater’s condition (Strong duality). If the primal &amp;amp; dual solutions are \(x^\star, \nu^\star\), then by KKT conditions they satisfy the following conditions [1].&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Stationarity: \(Px^\star + q + A^T\nu^\star = 0\)&lt;/li&gt;
  &lt;li&gt;Complementary Slackness: Since there are no inequality constraints, this does not need to be considered.&lt;/li&gt;
  &lt;li&gt;Primal &amp;amp; dual feasibility: \(Ax^\star = b\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These conditions can be concisely expressed using a block matrix, which is called the KKT matrix [3].&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{bmatrix}
    P       &amp;amp; A^T  \\\\
    A       &amp;amp; 0  \\\\
\end{bmatrix}
\begin{bmatrix}
    x^\star  \\\\
    \nu^\star  \\\\
\end{bmatrix}
=
\begin{bmatrix}
    -q  \\\\
    b  \\\\
\end{bmatrix}\]
&lt;/blockquote&gt;

&lt;p&gt;Solving this matrix equation gives the primal &amp;amp; dual solutions for the given problem.&lt;/p&gt;

&lt;p&gt;An interesting fact is that this problem can also be seen as computing the Newton step for an equality constrained problem [3]. For the problem \(min_x f(x) \text{ subject to } Ax = b\), if we set P, q, r as follows, then the objective function of the quadratic program becomes identical to the second-order Taylor expansion of \(f(x)\).&lt;br /&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(P = \nabla^2 f(x^{(k-1)})\), \(q = \nabla f(x^{(k-1)})\), \(r = f(x^{(k-1)})\)&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>12-01 Karush-Kuhn-Tucker conditions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_01_Karush_Kuhn_Tucker_conditions/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_01_Karush_Kuhn_Tucker_conditions</id>
   <content type="html">&lt;p&gt;Why do the four KKT conditions—stationarity, complementary slackness, primal feasibility, and dual feasibility—capture optimality so completely? The answer is not a long list of messy calculus lemmas; it is a breathtakingly short chain of inequalities linking the primal objective \(f(x^\star)\), the Lagrangian \(L(x^\star, u^\star, v^\star)\), and the dual function \(g(u^\star, v^\star)\)! Watching how zero duality gap collapses that chain into equalities shows immediately why KKT is necessary under strong duality and sufficient under convexity.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-proving-necessity--sufficiency-of-kkt&quot;&gt;Key ideas: Proving Necessity &amp;amp; Sufficiency of KKT&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The Collapse Chain Under Strong Duality (Necessity):&lt;/strong&gt; When \(f(x^\star) = g(u^\star, v^\star)\), we have \(f(x^\star) = \inf_x L(x, u^\star, v^\star) \le L(x^\star, u^\star, v^\star) = f(x^\star) + \sum u_i^\star h_i(x^\star) \le f(x^\star)\). Every inequality in the chain must be an equality!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Reading Stationarity &amp;amp; Complementary Slackness Off the Chain:&lt;/strong&gt; The first equality forces \(x^\star \in \arg\min_x L(x, u^\star, v^\star)\) (giving stationarity \(0 \in \partial_x L(x^\star, u^\star, v^\star)\)); the second equality forces \(\sum u_i^\star h_i(x^\star) = 0\), and since every term is \(\le 0\), each individual term \(u_i^\star h_i(x^\star) = 0\) (complementary slackness)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Reverse Direction Under Convexity (Sufficiency):&lt;/strong&gt; When \(f, h_i\) are convex and \(l_j\) are affine, \(L(\cdot, u^\star, v^\star)\) is convex in \(x\). Stationarity then &lt;em&gt;guarantees&lt;/em&gt; \(x^\star\) minimizes \(L(\cdot, u^\star, v^\star)\) globally, so \(g(u^\star, v^\star) = L(x^\star, u^\star, v^\star) = f(x^\star)\) (via complementary slackness)—proving zero duality gap and global optimality!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Caution on Nonconvex &amp;amp; Degenerate Problems:&lt;/strong&gt; For nonconvex problems, KKT points can be local minima, saddle points, or even maxima; for convex problems without Slater’s condition, an optimal primal point may exist with &lt;em&gt;no&lt;/em&gt; finite KKT multiplier!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-a-convex-problem-where-kkt-has-no-solution-slater-fails&quot;&gt;Worked example: A Convex Problem Where KKT Has No Solution (Slater Fails!)&lt;/h3&gt;

&lt;p&gt;Consider the convex problem \(\min_{x \in \mathbb{R}} f(x) = x\) subject to \(h(x) = x^2 \le 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find the exact primal optimum by inspection:&lt;/strong&gt; The only real number with \(x^2 \le 0\) is \(x^\star = 0\), so \(x^\star = 0\) is undeniably the unique global minimizer with \(f^\star = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the KKT stationarity condition at \(x^\star = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(L(x, u) = x + u x^2\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Stationarity: $$\frac{\partial L}{\partial x}\Big&lt;/td&gt;
              &lt;td&gt;_{x=0} = 1 + 2 u (0) = 1 = 0$$ — &lt;strong&gt;contradiction!&lt;/strong&gt;&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why did KKT fail at the true global optimum?&lt;/strong&gt; Because \(h(x) = x^2 \le 0\) has &lt;em&gt;no&lt;/em&gt; strictly feasible point (\(x^2 &amp;lt; 0\) is impossible), so &lt;strong&gt;Slater’s condition fails&lt;/strong&gt;! Geometrically, \(\nabla h(0) = 0\) vanishes at the boundary, leaving no normal vector available to balance \(\nabla f(0) = 1\). This 3-line counterexample permanently cements why Slater’s condition is essential for KKT necessity!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Let us consider the following general optimization problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{x} &amp;amp;&amp;amp;{f(x)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{h_i(x) \le 0, \text{ } i=1,\dots,m} \\\\
   &amp;amp; &amp;amp;&amp;amp;{l_j(x) = 0, \text{ } j=1,\dots,r}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The &lt;strong&gt;Karush–Kuhn–Tucker (KKT) conditions&lt;/strong&gt; or &lt;strong&gt;KKT conditions&lt;/strong&gt; consist of the following conditions [3].&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(0 \in \partial \big( f(x) + \sum_{i=1}^{m} \lambda_i h_i(x) + \sum_{j=1}^{r} \nu_j l_j(x) \big)\) (Stationarity): When \(\lambda, \nu\) are fixed, the subdifferential with respect to \(x\) contains 0.&lt;/li&gt;
  &lt;li&gt;\(\lambda_i \cdot h_i(x) = 0 \text{ for all } i\) (Complementary Slackness):  At least one of \(\lambda_i\) and \(h_i\) has value 0.&lt;/li&gt;
  &lt;li&gt;\(h_i(x) \le 0, l_j(x) = 0 \text{ for all } i, j\) (Primal Feasibility): Indicates whether the constraints of the primal problem are satisfied.&lt;/li&gt;
  &lt;li&gt;\(\lambda_i \ge 0 \text{ for all } i\) (Dual Feasibility): Indicates whether the constraints of the dual problem are satisfied.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;sufficiency&quot;&gt;Sufficiency&lt;/h2&gt;
&lt;p&gt;For a convex primal problem, when there exist \(x^\star, \lambda^\star, \nu^\star\) that satisfy the KKT conditions, the following process shows that \(x^\star, \lambda^\star, \nu^\star\) are primal &amp;amp; dual solutions with zero duality gap.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   g(\lambda^\star, \nu^\star) &amp;amp;= \min_x L(x, \lambda^\star, \nu^\star) \\\\
                               &amp;amp;= L(x^\star, \lambda^\star, \nu^\star) \\\\
                               &amp;amp;= f(x^\star) + \sum_{i=1}^m \lambda_i^\star h_i(x^\star) + \sum_{j=1}^r \nu_j^\star l_j(x^\star) \\\\
                               &amp;amp;= f(x^\star)
\end{align}\]
&lt;/blockquote&gt;

&lt;ol&gt;
  &lt;li&gt;\(L(x,\lambda^\star,\nu^\star) = f(x) + \sum_{i=1}^{m} \lambda_i^\star h_i(x) + \sum_{j=1}^{r} \nu_j^\star l_j(x)\) is a convex function. (sum of convex functions)&lt;/li&gt;
  &lt;li&gt;\(0 \in \partial \big( f(x^\star) + \sum_{i=1}^{m} \lambda_i^\star h_i(x^\star) + \sum_{j=1}^{r} \nu_j^\star l_j(x^\star) \big)\)therefore \(\min_x L(x, \lambda^\star, \nu^\star) = L(x^\star, \lambda^\star, \nu^\star)\).&lt;/li&gt;
  &lt;li&gt;By complementary slackness and primal feasibility, \(f(x^\star) + \sum_{i=1}^m \lambda_i^\star h_i(x^\star) + \sum_{j=1}^r \nu_j^\star l_j(x^\star) = f(x^\star)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;necessity&quot;&gt;Necessity&lt;/h2&gt;
&lt;p&gt;When \(x^\star, \lambda^\star, \nu^\star\) are primal &amp;amp; dual solutions with zero duality gap (for example, satisfying Slater’s condition), all the inequalities below become equalities, so in this problem \(x^\star, \lambda^\star, \nu^\star\) satisfy the KKT conditions.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   f(x^\star) &amp;amp;= g(\lambda^\star, \nu^\star) \\\\
                  &amp;amp;= \min_x  \big( f(x) + \sum_{i=1}^{m} \lambda_i^\star h_i(x) + \sum_{j=1}^{r} \nu_j^\star l_j(x) \big) \\\\
                  &amp;amp;\le f(x^\star) + \sum_{i=1}^m \lambda_i^\star h_i(x^\star) + \sum_{j=1}^r \nu_j^\star l_j(x^\star) \\\\
                  &amp;amp;\le f(x^\star)
\end{align}\]
&lt;/blockquote&gt;

&lt;ol&gt;
  &lt;li&gt;\(f(x^\star) = g(\lambda^\star, \nu^\star)\) means zero duality gap.&lt;/li&gt;
  &lt;li&gt;To satisfy \(f(x^\star) + \sum_{i=1}^m \underbrace{\lambda_i^\star h_i(x^\star)}_{0} + \sum_{j=1}^r \underbrace{\nu_j^\star l_j(x^\star)}_{0} = f(x^\star)\), complementary slackness and primal feasibility must be satisfied.&lt;/li&gt;
  &lt;li&gt;If \(f(x^\star) + \sum_{i=1}^m \lambda_i^\star h_i(x^\star) + \sum_{j=1}^r \nu_j^\star l_j(x^\star) = f(x^\star)\) is satisfied, all inequalities in the above derivation become equalities.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;putting-it-together&quot;&gt;Putting it together&lt;/h2&gt;
&lt;p&gt;In summary, KKT conditions are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Sufficient conditions for primal &amp;amp; dual solutions with zero duality gap.&lt;/li&gt;
  &lt;li&gt;If strong duality holds, they become necessary conditions for primal &amp;amp; dual solutions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is, for problems that satisfy strong duality, the following relationship holds.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   x^\star, \lambda^\star, \nu^\star \text{ are primal and dual solutions} \\\\
   \Leftrightarrow x^\star, \lambda^\star, \nu^\star \text{ satisfy the KKT conditions} \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;kkt-through-water-filling-in-about-3-minutes&quot;&gt;KKT through water-filling in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/kkt-water-filling_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Solving water-filling with α = (0.1, 0.4, 0.8, 1.2) through the four KKT conditions, reading the meaning of λ, and three wrong guesses that KKT rules out.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>12 KKT Conditions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_00_KKT_conditions/"/>
   <updated>2021-04-02T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter12/12_00_KKT_conditions</id>
   <content type="html">&lt;p&gt;In unconstrained calculus, finding the minimum of a smooth convex function reduces to a single famous equation: \(\nabla f(x^\star) = 0\). The moment you add inequality constraints \(h_i(x) \le 0\) and equality constraints \(l_j(x) = 0\), however, the minimum often sits pinned against a boundary where \(\nabla f(x^\star) \neq 0\)! How do you recognize an optimal point when the terrain hits a wall? The &lt;strong&gt;Karush–Kuhn–Tucker (KKT) conditions&lt;/strong&gt;—first discovered by William Karush in his 1939 master’s thesis and independently rediscovered by Harold Kuhn and Albert Tucker in 1951—provide the exact four-part algebraic fingerprint of optimality for constrained optimization.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-four-pillars-of-the-kkt-system&quot;&gt;Key ideas: The Four Pillars of the KKT System&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Stationarity (Force Balance at the Optimum):&lt;/strong&gt; \(0 \in \partial f(x^\star) + \sum_{i=1}^m u_i^\star \partial h_i(x^\star) + \sum_{j=1}^r v_j^\star \partial l_j(x^\star)\). Geometrically, the downhill pull \(-\nabla f(x^\star)\) is exactly cancelled by a nonnegative combination of the outward normal vectors \(\nabla h_i(x^\star)\) of active walls and the normals \(\nabla l_j(x^\star)\) of equality surfaces.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Complementary Slackness (\(u_i^\star h_i(x^\star) = 0\)):&lt;/strong&gt; Either constraint \(i\) is active (\(h_i(x^\star) = 0\), exerting a restoring force \(u_i^\star \ge 0\)), or constraint \(i\) is strictly inactive (\(h_i(x^\star) &amp;lt; 0\), forcing its price \(u_i^\star = 0\)). An untouched wall can never push on the solution!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Primal &amp;amp; Dual Feasibility:&lt;/strong&gt; The primal point must respect all constraints (\(h_i(x^\star) \le 0,\; l_j(x^\star) = 0\)), and inequality multipliers must push &lt;em&gt;inward&lt;/em&gt; rather than pull outward (\(u_i^\star \ge 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Necessity vs. Sufficiency:&lt;/strong&gt; Under strong duality, KKT is &lt;em&gt;necessary&lt;/em&gt; for any optimal primal–dual pair (even for nonconvex differentiable problems). For &lt;em&gt;convex&lt;/em&gt; problems, KKT is &lt;em&gt;always sufficient&lt;/em&gt; for global optimality—and when Slater’s condition holds, KKT is &lt;strong&gt;both necessary and sufficient&lt;/strong&gt;!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-a-constrained-convex-problem-directly-via-kkt&quot;&gt;Worked example: Solving a Constrained Convex Problem Directly via KKT&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = (x - 3)^2\) subject to \(h(x) = x - 1 \le 0\) (i.e., \(x \le 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write all four KKT conditions for \((x^\star, u^\star)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Stationarity: \(2(x^\star - 3) + u^\star = 0 \implies u^\star = 6 - 2x^\star\).&lt;/li&gt;
      &lt;li&gt;Complementary slackness: \(u^\star (x^\star - 1) = 0\).&lt;/li&gt;
      &lt;li&gt;Primal feasibility: \(x^\star \le 1\).&lt;/li&gt;
      &lt;li&gt;Dual feasibility: \(u^\star \ge 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 1 — Inactive wall (\(u^\star = 0\)):&lt;/strong&gt; Stationarity gives \(x^\star = 3\), which violates primal feasibility \(3 \le 1\). Eliminate Case 1!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 2 — Active wall (\(x^\star - 1 = 0 \implies x^\star = 1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Stationarity gives \(u^\star = 6 - 2(1) = 4\).&lt;/li&gt;
      &lt;li&gt;Dual feasibility check: \(u^\star = 4 \ge 0\) (satisfied!).&lt;/li&gt;
      &lt;li&gt;Primal feasibility check: \(1 - 1 = 0 \le 0\) (satisfied!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; Because the problem is convex, \((x^\star, u^\star) = (1, 4)\) satisfies all four KKT conditions and is certified globally optimal—with the multiplier \(u^\star = 4\) literally equaling the restoring force needed to hold the ball against the wall \(x = 1\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When the primal problem is convex, the Karush–Kuhn–Tucker (KKT) conditions become sufficient conditions for primal &amp;amp; dual optimal points with zero duality gap. Additionally, when the objective function and constraint functions of the primal problem are differentiable and satisfy strong duality, the primal &amp;amp; dual optimal points always satisfy the KKT conditions. KKT conditions hold a very important position in optimization. These conditions allow some special problems to be solved analytically, and many convex optimization algorithms can be interpreted as methods for solving KKT conditions [1]. In this chapter, we will learn about the definition and properties of KKT conditions and look at some examples based on them.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;As a side note&lt;/em&gt;, KKT conditions were originally introduced to the world by Harold W. Kuhn and Albert W. Tucker in 1951, and at that time they were called KT (Kuhn-Tucker) conditions. Later, scholars discovered that the necessary conditions for this problem had been addressed by William Karush’s master’s thesis in 1939, and from then on, Karush’s name was included and they became known as KKT (Karush–Kuhn–Tucker) conditions [3].&lt;/p&gt;

&lt;h2 id=&quot;modern-applications-20222026&quot;&gt;Modern applications (2022–2026)&lt;/h2&gt;

&lt;p&gt;An optional companion lesson reads the same KKT system in cvxpylayers / Theseus, SVM support vectors, electricity LMPs, and binding fairness constraints. See &lt;a href=&quot;/contents/en/chapter12/12_07_modern_applications/&quot;&gt;12-07 Modern applications of the KKT conditions&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>16 Tính đối ngẫu - nhìn lại</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_duality_revisited/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_duality_revisited</id>
   <content type="html">&lt;p&gt;Nếu ví các chương trước về đối ngẫu như việc học từng nốt nhạc riêng lẻ — hàm Lagrange, điều kiện KKT, hàm liên hợp, đường trung tâm — thì Chương 16 chính là khoảnh khắc ta đứng lùi lại để nghe trọn vẹn &lt;strong&gt;bản giao hưởng thống nhất&lt;/strong&gt; trước khi bước vào đỉnh cao của tối ưu hóa lồi: &lt;strong&gt;phương pháp điểm trong nguyên thủy – đối ngẫu (Primal-Dual Interior-Point Method)&lt;/strong&gt; ở Chương 17.&lt;/p&gt;

&lt;p&gt;Thay vì giải bài toán nguyên thủy rồi mới tìm biến đối ngẫu một cách thụ động như trong phương pháp chắn (Chương 15), phương pháp nguyên thủy – đối ngẫu sẽ cập nhật &lt;strong&gt;cả biến nguyên thủy \(x\) và biến đối ngẫu \((u, v)\) song song trong cùng một bước Newton&lt;/strong&gt;! Để cỗ máy song song đó vận hành trơn tru, Chương 16 hệ thống lại ba viên đá tảng ở góc nhìn tinh gọn và tổng quát nhất: &lt;strong&gt;Đối ngẫu Lagrange dạng minimax&lt;/strong&gt;, &lt;strong&gt;hệ điều kiện tối ưu KKT vs. đường trung tâm&lt;/strong&gt;, và &lt;strong&gt;Đối ngẫu Fenchel cho quy hoạch nón&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-viên-đá-tảng-chuẩn-bị-cho-phương-pháp-nguyên-thủy--đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Ba viên đá tảng chuẩn bị cho Phương pháp Nguyên thủy – Đối ngẫu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu Lagrange dạng trò chơi Minimax:&lt;/strong&gt; Viết cả bài toán nguyên thủy \(\min_x \max_{u \ge 0, v} L(x, u, v)\) và bài toán đối ngẫu \(\max_{u \ge 0, v} \min_x L(x, u, v)\) trên cùng một hàm \(L\) giúp thấy ngay đối ngẫu yếu chỉ là bất đẳng thức \(\max \min \le \min \max\), còn đối ngẫu mạnh là điểm yên ngựa!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh trực diện KKT và phương trình đường trung tâm:&lt;/strong&gt; Hệ KKT gốc có phương trình bù yếu \(u_i h_i(x) = 0\), còn đường trung tâm chỉ thay đúng số \(0\) ấy bằng \(-1/t\) — chuẩn bị trực tiếp cho bước giải hệ phi tuyến nguyên thủy – đối ngẫu bằng phương pháp Newton ở Chương 17.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu Fenchel và Quy hoạch nón (Conic Programming):&lt;/strong&gt; Thay vì bị bó buộc bởi bất đẳng thức vô hướng \(h_i(x) \le 0\), đối ngẫu Fenchel kết hợp hàm liên hợp \(f^*, g^*\) với nón đối ngẫu \(K^*\) để bao quát cùng lúc LP, SOCP và SDP dưới một khung lý thuyết duy nhất.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-nhìn-trọn-vẹn-bài-toán-nguyên-thủy-đối-ngẫu-và-điểm-yên-ngựa-trên-một-ví-dụ-2-biến&quot;&gt;Giải thích: Nhìn trọn vẹn bài toán nguyên thủy, đối ngẫu và điểm yên ngựa trên một ví dụ 2 biến&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch tuyến tính chuẩn nhỏ nhất có thể:
\(\min_{x \in \mathbb{R}^2} 2x_1 + 3x_2 \qquad \text{với điều kiện } x_1 + x_2 = 1, \;\; x_1 \ge 0, \;\; x_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hàm Lagrange chung cho cả hai chiều:&lt;/strong&gt;
Với \(u = (u_1, u_2) \ge 0\) (cho \(-x_1 \le 0, -x_2 \le 0\)) và \(v \in \mathbb{R}\) (cho \(1 - x_1 - x_2 = 0\)):
\(L(x, u, v) = (2 - u_1 - v)x_1 + (3 - u_2 - v)x_2 + v.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhìn theo chiều Nguyên thủy (\(\min_x \max_{u \ge 0, v} L\)):&lt;/strong&gt;
Nếu \(x_1 &amp;lt; 0\), chọn \(u_1 \to +\infty\) đẩy \(\max L \to +\infty\); nếu \(x_1 + x_2 \ne 1\), chọn \(v \to \pm\infty\) cũng đẩy \(\max L \to +\infty\). Vậy cực tiểu chỉ tồn tại trên tập khả thi và đạt tại \(x^\star = (1, 0)^T\) với \(p^\star = 2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhìn theo chiều Đối ngẫu (\(\max_{u \ge 0, v} \min_x L\)):&lt;/strong&gt;
Để \(\min_x L &amp;gt; -\infty\) ta cần \(2 - u_1 - v = 0\) và \(3 - u_2 - v = 0\), tức \(v \le 2\) và \(v \le 3\). Cực đại hóa \(v\) cho ra \(v^\star = 2\), \(u^\star = (0, 1)^T\) và \(d^\star = 2 = p^\star\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm yên ngựa \((x^\star, u^\star, v^\star)\):&lt;/strong&gt; Tại \(x^\star = (1, 0), u^\star = (0, 1), v^\star = 2\), mọi điều kiện KKT đều khớp hoàn toàn: \(u_1^\star x_1^\star = 0 \cdot 1 = 0\) và \(u_2^\star x_2^\star = 1 \cdot 0 = 0\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong chương này, chúng ta hệ thống lại những kiến thức nền tảng về tính đối ngẫu trước khi đi vào phương pháp điểm trong nguyên thủy – đối ngẫu (Primal-Dual Interior-Point). Phương pháp điểm trong nguyên thủy – đối ngẫu có thể xem là một mở rộng của phương pháp rào cản (Barrier method), trong đó khái niệm đối ngẫu đóng vai trò then chốt xuyên suốt quá trình xây dựng thuật toán.&lt;/p&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo-và-đọc-thêm&quot;&gt;Tài liệu tham khảo và đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;O. Guler (2010), “Foundations of Optimization”, Chapter 11.&lt;/li&gt;
  &lt;li&gt;J. Renegar (2001), “A mathematical view of interior-point methods in convex optimization,” Chapters 2 and 3.&lt;/li&gt;
  &lt;li&gt;S. Wright (1997), “Primal-dual interior-point methods”, Chapters 5 and 6.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>16-06 Bài Tập Thực Hành - Duality Revisited</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_06_Practical_Exercises_Duality_Revisited/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_06_Practical_Exercises_Duality_Revisited</id>
   <content type="html">&lt;p&gt;Ở mức độ đại học và cao học, việc hiểu sâu lý thuyết đối ngẫu không chỉ dừng lại ở tính hàm đối ngẫu của LP, mà thể hiện qua khả năng phân tích &lt;strong&gt;độ nhạy (perturbation analysis)&lt;/strong&gt; — trả lời câu hỏi &lt;em&gt;“nếu nới lỏng ràng buộc thêm một lượng \(\Delta u\) thì giá trị tối ưu thay đổi bao nhiêu?”&lt;/em&gt; — cũng như áp dụng &lt;strong&gt;đối ngẫu nón&lt;/strong&gt;, &lt;strong&gt;đối ngẫu minimax&lt;/strong&gt; và &lt;strong&gt;nới lỏng Lagrange (Lagrangian relaxation)&lt;/strong&gt; cho bài toán rời rạc không lồi.&lt;/p&gt;

&lt;p&gt;Tuyển tập bài tập thực hành Chương 16 dưới đây (tham khảo Boyd &amp;amp; Vandenberghe và Rockafellar) bao quát trọn vẹn năm kỹ năng đỉnh cao đó. Trước khi bắt tay giải Bài tập 1–5, hãy xem qua bản đồ chiến lược và một ví dụ mẫu cực kỳ trực quan về ý nghĩa kinh tế “giá bóng” của nhân tử Lagrange trong phân tích nhiễu loạn.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-năm-kỹ-năng-tự-luận-đỉnh-cao-của-chương-16&quot;&gt;Kiến thức cần nhớ: Năm kỹ năng tự luận đỉnh cao của Chương 16&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích nhiễu loạn và độ nhạy (Sensitivity Analysis):&lt;/strong&gt; Hàm giá trị tối ưu nhiễu loạn \(p^\star(u) = \inf \{f(x) \mid h(x) \le u\}\) là hàm lồi theo \(u\); khi đối ngẫu mạnh thỏa mãn và \(p^\star(u)\) khả vi tại \(u = 0\), ta có \(\lambda^\star = -\nabla p^\star(0)\) — nhân tử đối ngẫu chính là &lt;strong&gt;tốc độ cải thiện mục tiêu trên mỗi đơn vị nới lỏng ràng buộc&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện Slater và đối ngẫu mạnh:&lt;/strong&gt; Luôn phân biệt ràng buộc tuyến tính (chỉ cần \(\le 0\)) với ràng buộc phi tuyến (cần \(&amp;lt; 0\)) và chú ý các trường hợp biên nơi đối ngẫu mạnh bị phá vỡ (duality gap \(&amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu nón (Conic Duality):&lt;/strong&gt; Biết cách dùng tích trong chuẩn trên không gian ma trận \(\langle C, X \rangle = \operatorname{tr}(C^T X)\) và tính tự đối ngẫu của \(\mathbb{S}_+^n\) để suy ra đối ngẫu SDP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng Lagrange cho bài toán không lồi / tổ hợp:&lt;/strong&gt; Dù bài toán gốc không lồi (như quy hoạch nguyên hay Max-Cut), hàm đối ngẫu Lagrange vẫn &lt;strong&gt;luôn lõm&lt;/strong&gt; và cung cấp một chặn dưới (hoặc chặn trên) cực kỳ sắc nét dùng trong thuật toán Nhánh và Cận (Branch-and-Bound).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-minh-họa-trực-giác-phân-tích-nhiễu-loạn-giá-bóng-lambdastar---pstarprime0&quot;&gt;Giải thích: Minh họa trực giác phân tích nhiễu loạn (giá bóng \(\lambda^\star = -p^{\star\prime}(0)\))&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa 1 chiều có tham số nhiễu \(u\) ở vế phải ràng buộc:
\(p^\star(u) = \min_{x \in \mathbb{R}} \frac{1}{2}x^2 \qquad \text{với điều kiện } 2 - x \le u \;\; (\text{tức } x \ge 2 - u).\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính tường minh hàm giá trị tối ưu \(p^\star(u)\) quanh \(u = 0\):&lt;/strong&gt;
Với \(u &amp;lt; 2\), ràng buộc \(x \ge 2 - u &amp;gt; 0\) đang tích cực, nên nghiệm là \(x^\star(u) = 2 - u\) và:
\(p^\star(u) = \frac{1}{2}(2 - u)^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính đạo hàm độ nhạy tại \(u = 0\):&lt;/strong&gt;
\(p^{\star\prime}(u) = -(2 - u) \implies p^{\star\prime}(0) = -2.\)
Điều này có nghĩa là nếu nới lỏng ràng buộc thêm \(\Delta u = +0.01\) (từ \(x \ge 2\) thành \(x \ge 1.99\)), giá trị tối ưu sẽ giảm xấp xỉ \(-2 \times 0.01 = -0.02\) (thực tế \(\frac{1}{2}(1.99)^2 - \frac{1}{2}(2)^2 = 1.98005 - 2 = -0.01995 \approx -0.02\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối chiếu với nhân tử Lagrange tối ưu \(\lambda^\star\) tại \(u = 0\):&lt;/strong&gt;
Hàm Lagrange tại \(u = 0\) là \(L(x, \lambda) = \frac{1}{2}x^2 + \lambda(2 - x)\). Điều kiện dừng \(x - \lambda = 0\) tại \(x^\star = 2\) cho ra \(\lambda^\star = 2 = -p^{\star\prime}(0)\) — khẳng định chính xác nhân tử Lagrange chính là &lt;strong&gt;giá bóng (shadow price)&lt;/strong&gt; của ràng buộc!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---tính-đối-ngẫu-nhìn-lại&quot;&gt;Bài Tập Thực Hành - Tính đối ngẫu (Nhìn lại)&lt;/h1&gt;

&lt;p&gt;Các bài tập được tham khảo từ Boyd &amp;amp; Vandenberghe (2004) và Rockafellar (1970).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-1-phân-tích-nhiễu-loạn-perturbation-analysis&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Phân tích nhiễu loạn (Perturbation Analysis)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho bài toán:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x^2 \\
\text{s.t.} \quad &amp;amp; x \geq u
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tìm hàm giá trị tối ưu \(p^*(u)\) theo tham số \(u\).&lt;br /&gt;
b) Kiểm chứng \(\lambda^* = \frac{dp^*}{du}\) (ràng buộc \(u - x \leq 0\) càng chặt khi \(u\) tăng).&lt;br /&gt;
c) Giải thích ý nghĩa kinh tế của nhân tử \(\lambda^*\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Hàm giá trị tối ưu:**

$$p^*(u) = \begin{cases}
u^2 &amp;amp; \text{if } u \geq 0 \\
0 &amp;amp; \text{if } u &amp;lt; 0
\end{cases}$$

**b) Đạo hàm:**

$$\frac{dp^*}{du} = \begin{cases}
2u &amp;amp; \text{if } u &amp;gt; 0 \\
0 &amp;amp; \text{if } u &amp;lt; 0
\end{cases}$$

**Hàm Lagrange:**

$$L(x, \lambda) = x^2 - \lambda(x - u)$$

Điều kiện KKT: $$2x^* - \lambda^* = 0$$, $$\lambda^*(x^* - u) = 0$$.

- Nếu $$u \geq 0$$: $$x^* = u$$, $$\lambda^* = 2u = \frac{dp^*}{du}$$ ✓
- Nếu $$u &amp;lt; 0$$: $$x^* = 0$$, $$\lambda^* = 0$$ ✓

**c) Ý nghĩa:** $$\lambda^*$$ biểu thị độ nhạy (giá bóng — shadow price) của chi phí tối ưu khi mức ràng buộc $$u$$ thay đổi.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-tính-đối-ngẫu-mạnh-qua-điều-kiện-slater&quot;&gt;📝 &lt;strong&gt;Bài tập 2: Tính đối ngẫu mạnh qua điều kiện Slater&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho bài toán QCQP:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x_1^2 + x_2^2 \\
\text{s.t.} \quad &amp;amp; (x_1 - 1)^2 + x_2^2 \leq 1 \\
&amp;amp; x_1 + x_2 \geq 1
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Kiểm tra điều kiện Slater.&lt;br /&gt;
b) Viết bài toán đối ngẫu.&lt;br /&gt;
c) Kiểm chứng tính đối ngẫu mạnh.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Kiểm tra điều kiện Slater:**

Cần tìm một điểm $$\tilde{x}$$ khả thi ngặt:

$$
\begin{cases}
(x_1 - 1)^2 + x_2^2 &amp;lt; 1 \\
x_1 + x_2 &amp;gt; 1
\end{cases}
$$

Chọn thử $$\tilde{x} = (1, 0.5)$$:

$$(1-1)^2 + (0.5)^2 = 0.25 &amp;lt; 1$$ ✓

$$1 + 0.5 = 1.5 &amp;gt; 1$$ ✓

**Điều kiện Slater được thỏa mãn**, suy ra tính đối ngẫu mạnh đúng.

---

**b) Hàm Lagrange:**

$$L(x, \lambda_1, \lambda_2) = x_1^2 + x_2^2 + \lambda_1[(x_1-1)^2 + x_2^2 - 1] - \lambda_2(x_1 + x_2 - 1)$$

**Hàm đối ngẫu:**

$$g(\lambda_1, \lambda_2) = \inf_x L(x, \lambda)$$

Điều kiện dừng KKT $$\nabla_x L = 0$$:

$$2x_1 + 2\lambda_1(x_1 - 1) - \lambda_2 = 0$$

$$2x_2 + 2\lambda_1 x_2 - \lambda_2 = 0$$

---

**c) Kiểm chứng bằng số:**

Nghiệm tối ưu nguyên thủy: $$x^* = (0.5, 0.5)$$, $$p^* = 0.5$$ (ràng buộc hình đĩa không tác dụng vì $$(0.5-1)^2 + 0.5^2 = 0.5 &amp;lt; 1$$).

Nghiệm tối ưu đối ngẫu: $$\lambda^* = (0, 1)$$, $$d^* = 0.5$$ (từ $$g(0, \lambda_2) = \lambda_2 - \lambda_2^2/2$$, đạt cực đại tại $$\lambda_2 = 1$$).

**Khoảng cách đối ngẫu:** $$p^* - d^* = 0$$ ✓ (thỏa mãn tính đối ngẫu mạnh).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-nón-đối-ngẫu-và-đối-ngẫu-nón-conic-duality&quot;&gt;📝 &lt;strong&gt;Bài tập 3: Nón đối ngẫu và đối ngẫu nón (Conic Duality)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho nón bậc hai (second-order cone): \(K = \{(x, t) : \|x\| \leq t\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tìm nón đối ngẫu \(K^*\).&lt;br /&gt;
b) Kiểm chứng \(K^{**} = K\) (tính tự đối ngẫu).&lt;br /&gt;
c) Áp dụng cho tính đối ngẫu của bài toán SOCP.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Nón đối ngẫu:**

$$K^* = \{(y, s) : \langle (x,t), (y,s) \rangle \geq 0 \, \forall (x,t) \in K\}$$

$$= \{(y, s) : x^Ty + ts \geq 0 \, \forall \|x\| \leq t\}$$

Xét trường hợp bất lợi nhất $$x = -t\frac{y}{\|y\|}$$ (với $$y \neq 0$$):

$$-t\|y\| + ts \geq 0 \Rightarrow s \geq \|y\|$$

Do đó:

$$K^* = \{(y, s) : \|y\| \leq s\} = K$$

Như vậy, **nón bậc hai là nón tự đối ngẫu**.

---

**b) Kiểm chứng:**

$$K^{**} = (K^*)^* = K^* = K$$ ✓

---

**c) Đối ngẫu của bài toán SOCP:**

**Bài toán nguyên thủy:**

$$
\begin{align}
\min \quad &amp;amp; c^Tx \\
\text{s.t.} \quad &amp;amp; \|A_ix + b_i\| \leq c_i^Tx + d_i
\end{align}
$$

**Bài toán đối ngẫu:**

$$
\begin{align}
\max \quad &amp;amp; -\sum_i (b_i^Ty_i + d_iz_i) \\
\text{s.t.} \quad &amp;amp; \sum_i (A_i^Ty_i + c_iz_i) = c \\
&amp;amp; \|y_i\| \leq z_i
\end{align}
$$

Tính tự đối ngẫu của nón bậc hai tạo nên mối quan hệ đối xứng giữa bài toán nguyên thủy và bài toán đối ngẫu của SOCP.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-đối-ngẫu-minimax&quot;&gt;📝 &lt;strong&gt;Bài tập 4: Đối ngẫu Minimax&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho bài toán điểm yên:&lt;/p&gt;

\[\min_{x \in X} \max_{y \in Y} f(x, y)\]

&lt;p&gt;với \(f(x, y) = x^TAy + b^Tx + c^Ty\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán đối ngẫu.&lt;br /&gt;
b) Nêu điều kiện để giá trị minimax bằng maximin.&lt;br /&gt;
c) Giải ví dụ trò chơi ma trận với \(A = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix}\), \(X = Y = \Delta_2\) (đơn hình xác suất).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Bài toán đối ngẫu:**

$$\max_{y \in Y} \min_{x \in X} f(x, y)$$

**Tính đối ngẫu yếu:**

$$\min_x \max_y f(x, y) \geq \max_y \min_x f(x, y)$$

---

**b) Định lý Minimax (von Neumann):**

Nếu $$X, Y$$ là các tập lồi compact và $$f$$ lồi theo $$x$$, lõm theo $$y$$ (convex-concave), thì:

$$\min_x \max_y f = \max_y \min_x f$$

và tồn tại điểm yên $$(x^*, y^*)$$.

---

**c) Trò chơi ma trận:**

$$\min_{x \in \Delta_2} \max_{y \in \Delta_2} x^T A y$$

$$A = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix}$$

**Bài toán cực đại bên trong:**

$$\max_y x^TAy = \max\{2x_1 - x_2, -x_1 + x_2\}$$

(chọn chiến lược thuần mang lại giá trị lớn hơn).

**Bài toán cực tiểu bên ngoài:**

$$\min_x \max\{2x_1 - x_2, -x_1 + x_2\}$$

Với $$x_1 + x_2 = 1$$, thay $$x_2 = 1 - x_1$$:

$$\max\{2x_1 - (1-x_1), -x_1 + (1-x_1)\} = \max\{3x_1 - 1, 1 - 2x_1\}$$

Giao điểm hai đường thẳng: $$3x_1 - 1 = 1 - 2x_1 \Rightarrow 5x_1 = 2 \Rightarrow x_1 = 0.4$$.

**Cân bằng Nash:** $$x^* = (0.4, 0.6)$$, giá trị trò chơi bằng $$0.2$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-nới-lỏng-lagrange-lagrangian-relaxation&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Nới lỏng Lagrange (Lagrangian Relaxation)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho bài toán quy hoạch nguyên:&lt;/p&gt;

\[\begin{align}
\min \quad &amp;amp; c^Tx \\
\text{s.t.} \quad &amp;amp; Ax \leq b \\
&amp;amp; x \in \{0, 1\}^n
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán nới lỏng Lagrange.&lt;br /&gt;
b) Giải thích tính chất cận dưới của bài toán đối ngẫu.&lt;br /&gt;
c) Giải ví dụ với \(c = (-1, -2)\), \(A = [1, 1]\), \(b = 1\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Nới lỏng Lagrange:**

$$L(x, \lambda) = c^Tx + \lambda^T(Ax - b)$$

$$g(\lambda) = \min_{x \in \{0,1\}^n} L(x, \lambda) = \min_{x \in \{0,1\}^n} (c + A^T\lambda)^Tx - \lambda^Tb$$

Cực tiểu hóa độc lập từng thành phần $$x_i$$:

$$x_i^* = \begin{cases}
0 &amp;amp; \text{if } c_i + (A^T\lambda)_i &amp;gt; 0 \\
1 &amp;amp; \text{if } c_i + (A^T\lambda)_i &amp;lt; 0
\end{cases}$$

---

**b) Tính chất cận dưới:**

$$\max_{\lambda \geq 0} g(\lambda) \leq p^*$$

Giải bài toán đối ngẫu (dễ giải hơn) cung cấp cận dưới cho bài toán nguyên thủy (thuộc lớp NP-hard).

---

**c) Ví dụ:**

$$\min -x_1 - 2x_2$$ thỏa mãn $$x_1 + x_2 \leq 1$$, $$x \in \{0,1\}^2$$.

**Nghiệm tối ưu nguyên thủy:** $$x^* = (0, 1)$$, $$p^* = -2$$.

**Hàm Lagrange** (với $$\lambda \geq 0$$):

$$L(x, \lambda) = -x_1 - 2x_2 + \lambda(x_1 + x_2 - 1) = (\lambda - 1)x_1 + (\lambda - 2)x_2 - \lambda$$

**Hàm đối ngẫu:**

$$g(\lambda) = \min(0, \lambda - 1) + \min(0, \lambda - 2) - \lambda = \begin{cases} \lambda - 3 &amp;amp; 0 \leq \lambda \leq 1 \\ -2 &amp;amp; 1 \leq \lambda \leq 2 \\ -\lambda &amp;amp; \lambda \geq 2 \end{cases}$$

**Nghiệm tối ưu đối ngẫu:** $$\lambda^* \in [1, 2]$$, $$d^* = -2 = p^*$$.

Trường hợp này đạt **tính đối ngẫu mạnh** (đây là trường hợp đặc biệt thuận lợi; tổng quát, nới lỏng Lagrange chỉ đảm bảo cận dưới $$d^* \leq p^*$$).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;các-khái-niệm-cốt-lõi-về-đối-ngẫu&quot;&gt;&lt;strong&gt;Các khái niệm cốt lõi về đối ngẫu:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khái niệm&lt;/th&gt;
      &lt;th&gt;Ý tưởng chính&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Phân tích nhiễu loạn (Perturbation)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\lambda^* = -dp^*/du\) cho ràng buộc \(f_i(x) \leq u_i\) (độ nhạy)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Điều kiện Slater&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đảm bảo tính đối ngẫu mạnh cho bài toán lồi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Nón đối ngẫu (Dual cone)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(K^* = \{y : y^Tx \geq 0 \, \forall x \in K\}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Định lý Minimax&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\min \max = \max \min\) dưới điều kiện lồi – lõm và compact&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Nới lỏng Lagrange&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Nới lỏng ràng buộc khó để thu được cận dưới đối ngẫu&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;khi-nào-tính-đối-ngẫu-mạnh-được-thỏa-mãn&quot;&gt;&lt;strong&gt;Khi nào tính đối ngẫu mạnh được thỏa mãn:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP:&lt;/strong&gt; Luôn đúng khi bài toán khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán lồi:&lt;/strong&gt; Khi thỏa mãn điều kiện Slater.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SOCP/SDP:&lt;/strong&gt; Khi tồn tại điểm trong khả thi ngặt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán không lồi:&lt;/strong&gt; Nhìn chung không đảm bảo (thường có khe đối ngẫu khác 0).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Chapter 5.&lt;/li&gt;
  &lt;li&gt;Rockafellar, R. T. (1970). &lt;em&gt;Convex Analysis&lt;/em&gt;. Princeton.&lt;/li&gt;
  &lt;li&gt;Borwein, J., &amp;amp; Lewis, A. (2006). &lt;em&gt;Convex Analysis and Nonlinear Optimization&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>16-05 Bài tập trắc nghiệm - Tính Đối Ngẫu Tái Xét</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_05_Quiz_Duality_Revisited/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_05_Quiz_Duality_Revisited</id>
   <content type="html">&lt;p&gt;Chương 16 tổng hợp những khái niệm sắc nét nhất của toàn bộ lý thuyết đối ngẫu — từ biểu diễn minimax, điều kiện Slater tinh chỉnh, đối chiếu KKT với đường trung tâm LP, đến đối ngẫu Fenchel cho quy hoạch nón. Cũng chính vì tính cô đọng cao nên các câu hỏi trắc nghiệm chương này thường kiểm tra rất kỹ &lt;strong&gt;các điều kiện biên&lt;/strong&gt;: khi nào không cần khả thi chặt? Dấu trừ trong đối ngẫu Fenchel nằm ở đâu? Liên hợp của hàm chỉ thị nón \(K\) là \(I_{K^*}\) hay \(I_{-K^*}\)?&lt;/p&gt;

&lt;p&gt;Hãy dành hai phút rà lại bản đồ bốn điểm phân biệt dễ nhầm trước khi bước vào bộ câu hỏi trắc nghiệm.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-điểm-phân-biệt-sắc-bén-cho-trắc-nghiệm-chương-16&quot;&gt;Kiến thức cần nhớ: Bốn điểm phân biệt sắc bén cho trắc nghiệm Chương 16&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Slater gốc vs. Slater tinh chỉnh:&lt;/strong&gt; Slater gốc đòi mọi bất đẳng thức \(h_i(x) &amp;lt; 0\); Slater tinh chỉnh &lt;strong&gt;miễn&lt;/strong&gt; dấu chặt cho các ràng buộc tuyến tính/affine (chỉ cần \(\le 0\)), nên LP khả thi bị chặn luôn có đối ngẫu mạnh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù yếu KKT vs. Đường trung tâm:&lt;/strong&gt; Trong LP dạng chuẩn, KKT đòi \(x_i s_i = 0\) (nằm trên biên), còn đường trung tâm đòi \(x_i s_i = \mu = 1/t &amp;gt; 0\) (nằm trong miền trong, tổng khoảng cách đối ngẫu \(x^T s = n\mu\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy ước dấu trong Đối ngẫu Fenchel:&lt;/strong&gt; Với \(\min_x f(x) + g(Ax)\), đối ngẫu Fenchel là \(\max_u -f^*(-A^T u) - g^*(u)\) (hoặc \(\max_y -f^*(A^T y) - g^*(-y)\)). Luôn kiểm tra tính đối xứng: hai đối số của \(f^*\) và \(g^*\) phải ngược dấu nhau qua \(A^T\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hợp của hàm chỉ thị nón:&lt;/strong&gt; Với nón \(K\), \(I_K^*(z) = \sup_{x \in K} z^T x\) bằng \(0\) khi \(z^T x \le 0 \;\forall x \in K\) (tức \(-z \in K^*\)) và \(+\infty\) ngược lại — do đó \(I_K^*(z) = I_{-K^*}(z) = I_{K^*}(-z)\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-mẫu-câu-hỏi-bẫy-về-dấu-trừ-trong-liên-hợp-của-hàm-chỉ-thị-nón-i_kz&quot;&gt;Giải thích: Giải mẫu câu hỏi bẫy về dấu trừ trong liên hợp của hàm chỉ thị nón \(I_K^*(z)\)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi mẫu:&lt;/strong&gt; Cho nón không âm 1 chiều \(K = \mathbb{R}_+ = [0, +\infty)\) (tự đối ngẫu: \(K^* = [0, +\infty)\)). Tính \(I_K^*(z)\) tại \(z = 2\) và \(z = -2\) để tránh nhầm giữa \(I_{K^*}(z)\) và \(I_{-K^*}(z)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng định nghĩa hàm liên hợp:&lt;/strong&gt;
\(I_K^*(z) = \sup_{x \ge 0} \bigl(z \cdot x - 0\bigr) = \sup_{x \ge 0} (zx).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử \(z = 2 \in K^*\):&lt;/strong&gt;
Khi cho \(x \to +\infty\), tích \(2x \to +\infty \implies I_K^*(2) = +\infty\)!
(Nếu ai nhầm \(I_K^* = I_{K^*}\) thì sẽ tưởng bằng \(0\) — sai hoàn toàn!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử \(z = -2 \in -K^*\):&lt;/strong&gt;
Với mọi \(x \ge 0\), tích \(-2x \le 0\), và đạt cực đại bằng \(0\) tại \(x = 0 \implies I_K^*(-2) = 0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận chắc chắn:&lt;/strong&gt; \(I_K^*(z) = 0 \iff z \in -K^* \iff -z \in K^*\). Một phép thử 5 giây với số \(2\) và \(-2\) đủ để không bao giờ nhầm dấu trong các bài đối ngẫu nón!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-nhìn-lại-tính-đối-ngẫu-duality-revisited&quot;&gt;⚡ &lt;strong&gt;Nhìn lại tính đối ngẫu (Duality Revisited)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;biểu-diễn-bài-toán-nguyên-thủy--đối-ngẫu-qua-hàm-lagrange&quot;&gt;&lt;strong&gt;Biểu diễn bài toán nguyên thủy – đối ngẫu qua hàm Lagrange&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Bài toán nguyên thủy:&lt;/strong&gt;
\(\min_x f(x) \quad \text{s.t.} \quad h_i(x) \le 0, \quad l_j(x) = 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm Lagrange:&lt;/strong&gt;
\(L(x,u,v) = f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x)\)&lt;/p&gt;

&lt;h4 id=&quot;dạng-viết-lại-nguyên-thủy--đối-ngẫu&quot;&gt;&lt;strong&gt;Dạng viết lại nguyên thủy – đối ngẫu&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Bài toán nguyên thủy:&lt;/strong&gt;
\(\min_x \max_{u \ge 0, v} L(x,u,v)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;
\(\max_{u \ge 0, v} \min_x L(x,u,v)\)&lt;/p&gt;

&lt;h4 id=&quot;cách-hiểu-theo-hàm-chỉ-thị&quot;&gt;&lt;strong&gt;Cách hiểu theo hàm chỉ thị&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán nguyên thủy:&lt;/strong&gt; Phép lấy \(\max_{u \ge 0, v}\) đóng vai trò như hàm chỉ thị, phạt vô hạn mọi điểm \(x\) vi phạm ràng buộc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt; Phép lấy \(\min_x\) với \((u, v)\) cố định giúp nới lỏng miền ràng buộc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính tương đương:&lt;/strong&gt; Dạng viết lại nguyên thủy tương đương với bài toán gốc trên tập khả thi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-tính-đối-ngẫu-yếu-và-mạnh-tinh-chỉnh&quot;&gt;🔄 &lt;strong&gt;Tính đối ngẫu yếu và mạnh (Tinh chỉnh)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-lý-đối-ngẫu-yếu&quot;&gt;&lt;strong&gt;Định lý đối ngẫu yếu&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Bất đẳng thức sau luôn đúng (không phụ thuộc tính lồi): \(p \ge d\) (giá trị tối ưu nguyên thủy luôn lớn hơn hoặc bằng giá trị tối ưu đối ngẫu).&lt;/p&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt; Từ bất đẳng thức minimax:
\(\min_x \max_{u \ge 0, v} L(x,u,v) \ge \max_{u \ge 0, v} \min_x L(x,u,v)\)&lt;/p&gt;
&lt;/div&gt;

&lt;h4 id=&quot;tính-đối-ngẫu-mạnh-điều-kiện-slater-tinh-chỉnh&quot;&gt;&lt;strong&gt;Tính đối ngẫu mạnh (Điều kiện Slater tinh chỉnh)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Điều kiện:&lt;/strong&gt; Trên miền xác định \(D\), giả sử \(f, h_1,\ldots,h_p\) là các hàm lồi và \(h_{p+1},\ldots,h_m, l_1,\ldots,l_r\) là các hàm affine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nếu tồn tại \(\hat{x} \in \text{relint}(D)\) thỏa mãn:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(h_i(\hat{x}) &amp;lt; 0, \quad i = 1,\ldots,p\) (bất đẳng thức ngặt cho ràng buộc không affine)&lt;/li&gt;
  &lt;li&gt;\(h_i(\hat{x}) \le 0, \quad i = p+1,\ldots,m\) (bất đẳng thức không ngặt cho ràng buộc affine)&lt;/li&gt;
  &lt;li&gt;\(l_j(\hat{x}) = 0, \quad j = 1,\ldots,r\) (ràng buộc đẳng thức)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Thì:&lt;/strong&gt; \(p = d\) (tính đối ngẫu mạnh được thỏa mãn).&lt;/p&gt;

&lt;h3 id=&quot;-các-ví-dụ-đối-ngẫu-tiêu-biểu&quot;&gt;📊 &lt;strong&gt;Các ví dụ đối ngẫu tiêu biểu&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-đối-ngẫu-quy-hoạch-tuyến-tính-lp&quot;&gt;&lt;strong&gt;1. Đối ngẫu quy hoạch tuyến tính (LP)&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Bài toán nguyên thủy (dạng chuẩn):&lt;/strong&gt;
\(\min c^T x \quad \text{s.t.} \quad Ax = b, \quad x \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm Lagrange:&lt;/strong&gt;
\(L(x,s,y) = c^T x - s^T x + (b - Ax)^T y\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt; \(\nabla_x L = c - s - A^T y = 0 \Rightarrow c = A^T y + s\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;
\(\max b^T y \quad \text{s.t.} \quad A^T y + s = c, \quad s \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;2-đối-ngẫu-quy-hoạch-bậc-hai-qp&quot;&gt;&lt;strong&gt;2. Đối ngẫu quy hoạch bậc hai (QP)&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Bài toán nguyên thủy:&lt;/strong&gt;
\(\min \frac{1}{2}x^T Q x + c^T x \quad \text{s.t.} \quad Ax = b, \quad x \ge 0\)&lt;/p&gt;

&lt;p&gt;với \(Q\) là ma trận đối xứng nửa xác định dương.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm Lagrange:&lt;/strong&gt;
\(L(x,s,y) = \frac{1}{2}x^T Q x + c^T x - s^T x + (b - Ax)^T y\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt; \(Qx + c - s - A^T y = 0 \Rightarrow Qx = A^T y + s - c\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;
\(\max b^T y - \frac{1}{2}x^T Q x \quad \text{s.t.} \quad Qx = A^T y + s - c, \quad s \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nhận xét:&lt;/strong&gt; Bài toán đối ngẫu của một bài toán QP cũng là một bài toán QP.&lt;/p&gt;

&lt;h4 id=&quot;3-đối-ngẫu-của-bài-toán-rào-cản-barrier&quot;&gt;&lt;strong&gt;3. Đối ngẫu của bài toán rào cản (Barrier)&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Bài toán rào cản nguyên thủy cho LP:&lt;/strong&gt;
\(\min c^T x - \tau \sum_{i=1}^n \log(x_i) \quad \text{s.t.} \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm Lagrange:&lt;/strong&gt;
\(L(x,y) = c^T x - \tau \sum_{i=1}^n \log(x_i) + (b - Ax)^T y\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nghiệm tối ưu theo \(x\):&lt;/strong&gt; \(x_i = \frac{\tau}{s_i}\) với \(s = c - A^T y\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;
\(\max b^T y + \tau \sum_{i=1}^n \log(s_i) \quad \text{s.t.} \quad A^T y + s = c\) (bỏ qua hằng số \(n\tau(1 - \log\tau)\))&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt; Đối ngẫu của bài toán rào cản trùng khớp với bài toán rào cản thiết lập cho bài toán đối ngẫu.&lt;/p&gt;

&lt;h3 id=&quot;-so-sánh-điều-kiện-tối-ưu&quot;&gt;🎯 &lt;strong&gt;So sánh điều kiện tối ưu&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;điều-kiện-kkt-của-bài-toán-gốc&quot;&gt;&lt;strong&gt;Điều kiện KKT của bài toán gốc&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
l_j(x^*) &amp;amp;= 0 \quad \forall j \\
u_i^*, -h_i(x^*) &amp;amp;\ge 0 \quad \forall i \\
u_i^* h_i(x^*) &amp;amp;= 0 \quad \forall i \\
\nabla f(x^*) + \sum u_i^* \nabla h_i(x^*) + \sum v_j^* \nabla l_j(x^*) &amp;amp;= 0
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-kkt-bị-nhiễu-bài-toán-rào-cản&quot;&gt;&lt;strong&gt;Điều kiện KKT bị nhiễu (bài toán rào cản)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
l_j(x^*(t)) &amp;amp;= 0 \quad \forall j \\
u_i(t), -h_i(x^*(t)) &amp;amp;&amp;gt; 0 \quad \forall i \\
u_i(t) h_i(x^*(t)) &amp;amp;= -\tau \quad \forall i \\
\nabla f(x^*(t)) + \sum u_i(t) \nabla h_i(x^*(t)) + \sum \hat{v}_j^* \nabla l_j(x^*(t)) &amp;amp;= 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;với \(\tau = \frac{1}{t}\), \(u_i(t) = -\frac{1}{t h_i(x^*(t))}\), \(\hat{v} = \frac{1}{t}v\).&lt;/p&gt;

&lt;h4 id=&quot;điểm-khác-biệt-chính&quot;&gt;&lt;strong&gt;Điểm khác biệt chính:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù chặt:&lt;/strong&gt; Chuyển từ \(= 0\) sang \(= -\tau\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính khả thi:&lt;/strong&gt; Chuyển từ \(\ge 0\) sang \(&amp;gt; 0\) (điểm trong ngặt).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt; Khi \(\tau \to 0\), nghiệm trên đường trung tâm tiến về nghiệm KKT chính xác của bài toán gốc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-trường-hợp-đặc-biệt-quy-hoạch-tuyến-tính-lp&quot;&gt;📈 &lt;strong&gt;Trường hợp đặc biệt: Quy hoạch tuyến tính (LP)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;điều-kiện-tối-ưu-nguyên-thủy--đối-ngẫu&quot;&gt;&lt;strong&gt;Điều kiện tối ưu nguyên thủy – đối ngẫu&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
A^T y^* + s^* &amp;amp;= c \\
Ax^* &amp;amp;= b \\
X S \mathbf{1} &amp;amp;= 0 \\
x^*, s^* &amp;amp;\ge 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;với \(X = \text{diag}(x^*)\), \(S = \text{diag}(s^*)\).&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-của-bài-toán-rào-cản&quot;&gt;&lt;strong&gt;Điều kiện của bài toán rào cản&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
A^T y^* + s^* &amp;amp;= c \\
Ax^* &amp;amp;= b \\
X S \mathbf{1} &amp;amp;= \tau \mathbf{1} \\
x^*, s^* &amp;amp;&amp;gt; 0
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;ý-nghĩa-về-mặt-thuật-toán&quot;&gt;&lt;strong&gt;Ý nghĩa về mặt thuật toán:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp đơn hình (Simplex nguyên thủy):&lt;/strong&gt; Duy trì điều kiện 2, 3 và \(x \ge 0\), đồng thời tiến dần tới điều kiện 1 với \(s \ge 0\) (khả thi đối ngẫu).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp điểm trong (Interior-Point):&lt;/strong&gt; Duy trì điều kiện 4 (\(x, s &amp;gt; 0\)) và tiến dần tới các điều kiện 1, 2, 3.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đường trung tâm:&lt;/strong&gt; Phương trình \(XS\mathbf{1} = \tau\mathbf{1}\) xác định quỹ đạo trơn trong miền trong dẫn tới nghiệm tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-tính-đối-ngẫu-fenchel&quot;&gt;🔗 &lt;strong&gt;Tính đối ngẫu Fenchel&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;dạng-bài-toán-tổng-hợp&quot;&gt;&lt;strong&gt;Dạng bài toán tổng hợp&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Nguyên thủy:&lt;/strong&gt; \(\min_x f(x) + g(Ax)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Viết lại:&lt;/strong&gt; \(\min_{x,z} f(x) + g(z) \quad \text{s.t.} \quad Ax = z\)&lt;/p&gt;

&lt;h4 id=&quot;cách-tiếp-cận-qua-hàm-liên-hợp&quot;&gt;&lt;strong&gt;Cách tiếp cận qua hàm liên hợp&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Hàm Lagrange:&lt;/strong&gt;
\(L(x,z,v) = f(x) + g(z) + v^T(z - Ax)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm đối ngẫu:&lt;/strong&gt;
\(\begin{align}
g(v) &amp;amp;= \min_{x,z} L(x,z,v) \\
&amp;amp;= \min_x [f(x) - (A^T v)^T x] + \min_z [g(z) + v^T z] \\
&amp;amp;= -f^*(A^T v) - g^*(-v)
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;bài-toán-đối-ngẫu-fenchel&quot;&gt;&lt;strong&gt;Bài toán đối ngẫu Fenchel&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max_v -f^*(A^T v) - g^*(-v)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính đối xứng:&lt;/strong&gt; Nếu \(f, g\) là các hàm lồi và đóng, thì bài toán đối ngẫu của bài toán đối ngẫu quay về chính bài toán nguyên thủy.&lt;/p&gt;

&lt;h3 id=&quot;-ứng-dụng-trong-quy-hoạch-nón-conic-programming&quot;&gt;🎯 &lt;strong&gt;Ứng dụng trong quy hoạch nón (Conic Programming)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-quy-hoạch-nón-dạng-chuẩn&quot;&gt;&lt;strong&gt;Bài toán quy hoạch nón dạng chuẩn&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min c^T x \quad \text{s.t.} \quad Ax = b, \quad x \in K\)&lt;/p&gt;

&lt;h4 id=&quot;biểu-diễn-fenchel&quot;&gt;&lt;strong&gt;Biểu diễn Fenchel&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;
\[f(x) = c^T x + I_K(x)\]
  &lt;/li&gt;
  &lt;li&gt;
\[g(z) = I_{\{b\}}(z)\]
  &lt;/li&gt;
  &lt;li&gt;
\[\min f(x) + g(Ax)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;bài-toán-đối-ngẫu-nón&quot;&gt;&lt;strong&gt;Bài toán đối ngẫu nón&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max b^T y \quad \text{s.t.} \quad A^T y + s = c, \quad s \in K^*\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện đối ngẫu mạnh:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bài toán nguyên thủy khả thi ngặt &lt;strong&gt;hoặc&lt;/strong&gt; bài toán đối ngẫu khả thi ngặt (với giá trị tối ưu hữu hạn) \(\Longrightarrow\) đối ngẫu mạnh thỏa mãn.&lt;/li&gt;
  &lt;li&gt;Cả hai cùng khả thi ngặt \(\Longrightarrow\) đối ngẫu mạnh thỏa mãn và cả hai đều đạt nghiệm tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-quy-hoạch-bán-xác-định-sdp&quot;&gt;📊 &lt;strong&gt;Quy hoạch bán xác định (SDP)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;SDP nguyên thủy:&lt;/strong&gt;
\(\min \text{tr}(CX) \quad \text{s.t.} \quad \text{tr}(A_i X) = b_i, \quad X \succeq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SDP đối ngẫu:&lt;/strong&gt;
\(\max b^T y \quad \text{s.t.} \quad \sum y_i A_i + S = C, \quad S \succeq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính tự đối ngẫu của nón PSD:&lt;/strong&gt; \((\mathbb{S}_+^n)^* = \mathbb{S}_+^n\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán rào cản cho SDP:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nguyên thủy:&lt;/strong&gt; \(\min \text{tr}(CX) - \tau \log(\det(X)) \quad \text{s.t.} \quad \text{tr}(A_i X) = b_i\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu:&lt;/strong&gt; \(\max b^T y + \tau \log(\det(S)) \quad \text{s.t.} \quad \sum y_i A_i + S = C\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Khác với LP, bài toán SDP không phải lúc nào cũng thỏa mãn tính đối ngẫu mạnh.&lt;/p&gt;

&lt;h3 id=&quot;️-ý-nghĩa-thực-hành-và-liên-kết-giữa-các-dạng-đối-ngẫu&quot;&gt;🛠️ &lt;strong&gt;Ý nghĩa thực hành và liên kết giữa các dạng đối ngẫu&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian ↔ Fenchel:&lt;/strong&gt; Đối ngẫu Lagrange phù hợp cho bài toán có ràng buộc tổng quát; đối ngẫu Fenchel đặc biệt thuận tiện cho bài toán tổng hai hàm (có điều chuẩn hoặc toán tử tuyến tính).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn thuật toán:&lt;/strong&gt; Nếu bài toán đối ngẫu có cấu trúc đơn giản hơn, có thể giải trực tiếp bài toán đối ngẫu; với bài toán quy mô lớn có ràng buộc nón hoặc cần độ chính xác cao, phương pháp điểm trong nguyên thủy – đối ngẫu khai thác đồng thời cả hai phía và dùng khoảng cách đối ngẫu làm tiêu chí dừng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý cài đặt:&lt;/strong&gt; Cần kiểm tra điều kiện Slater để đảm bảo đối ngẫu mạnh, theo dõi số điều kiện và tận dụng nghiệm đối ngẫu cho khởi động ấm (warm start) hoặc phân tích độ nhạy (giá bóng).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra kiến thức về tính đối ngẫu, bao gồm đối ngẫu Lagrange, điều kiện tối ưu KKT, đối ngẫu Fenchel và các tính chất liên quan.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🔄 Bài tập trắc nghiệm: Tính đối ngẫu (Nhìn lại)&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 4%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;25&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: Lagrangian definition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Hàm Lagrange cho bài toán có ràng buộc \(h_i(x) \leq 0\) và \(l_j(x) = 0\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(L(x,u,v) = f(x) + \sum u_i h_i(x) + \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(L(x,u,v) = f(x) - \sum u_i h_i(x) - \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(L(x,u,v) = f(x) + \sum u_i h_i(x) - \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(L(x,u,v) = f(x) - \sum u_i h_i(x) + \sum v_j l_j(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$L(x,u,v) = f(x) + \sum u_i h_i(x) + \sum v_j l_j(x)$$&lt;/strong&gt;&lt;br /&gt;
                Đây là dạng chuẩn của hàm Lagrange với biến đối ngẫu $$u_i \geq 0$$ cho ràng buộc bất đẳng thức và $$v_j$$ tự do cho ràng buộc đẳng thức.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Primal problem reformulation --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Bài toán nguyên thủy có thể được viết lại thành:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(\min_x \max_{u \geq 0, v} L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\max_x \min_{u \geq 0, v} L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(\min_x \min_{u \geq 0, v} L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(\max_x \max_{u \geq 0, v} L(x,u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\min_x \max_{u \geq 0, v} L(x,u,v)$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán nguyên thủy cực tiểu hóa theo $$x$$ sau khi cực đại hóa hàm Lagrange theo các biến đối ngẫu để áp đặt các ràng buộc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Dual problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Bài toán đối ngẫu tương ứng là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(\max_{u \geq 0, v} \min_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(\min_{u \geq 0, v} \max_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \(\max_{u \geq 0, v} \max_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \(\min_{u \geq 0, v} \min_x L(x,u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max_{u \geq 0, v} \min_x L(x,u,v)$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán đối ngẫu cực đại hóa theo các biến đối ngẫu sau khi cực tiểu hóa hàm Lagrange theo biến nguyên thủy $$x$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Dual function --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Hàm đối ngẫu \(g(u,v)\) được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) \(g(u,v) = \inf_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) \(g(u,v) = \sup_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) \(g(u,v) = L(x^*,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) \(g(u,v) = \nabla_x L(x,u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$g(u,v) = \inf_x L(x,u,v)$$&lt;/strong&gt;&lt;br /&gt;
                Hàm đối ngẫu là cận dưới đúng (infimum) của hàm Lagrange theo biến nguyên thủy, và luôn là hàm lõm theo các biến đối ngẫu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Strong duality condition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Tính đối ngẫu mạnh xảy ra khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(p^* = d^*\) (giá trị tối ưu nguyên thủy bằng giá trị tối ưu đối ngẫu)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(p^* &amp;gt; d^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(p^* &amp;lt; d^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Khoảng cách đối ngẫu bằng \(\infty\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$p^* = d^*$$ (giá trị tối ưu nguyên thủy bằng giá trị tối ưu đối ngẫu)&lt;/strong&gt;&lt;br /&gt;
                Tính đối ngẫu mạnh đồng nghĩa với khoảng cách đối ngẫu bằng $$0$$, tức $$p^* = d^*$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: KKT stationarity --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Điều kiện dừng (stationarity) trong hệ KKT là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(\nabla_x L(x^*,u^*,v^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(h_i(x^*) \leq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(u_i^* \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(u_i^* h_i(x^*) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\nabla_x L(x^*,u^*,v^*) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện dừng yêu cầu gradient của hàm Lagrange theo biến nguyên thủy triệt tiêu tại điểm tối ưu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Complementary slackness --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Điều kiện bù chặt (complementary slackness) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) \(u_i^* h_i(x^*) = 0\) với mọi \(i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(u_i^* + h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) \(u_i^* h_i(x^*) \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(u_i^* = h_i(x^*)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$u_i^* h_i(x^*) = 0$$ với mọi $$i$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện bù chặt cho biết biến đối ngẫu bằng $$0$$ nếu ràng buộc không tác dụng ($$h_i(x^*) &amp;lt; 0$$), và ràng buộc phải tác dụng ($$h_i(x^*) = 0$$) nếu biến đối ngẫu dương ($$u_i^* &amp;gt; 0$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Fenchel conjugate --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Hàm liên hợp Fenchel của hàm \(f\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(f^*(y) = \sup_x (y^T x - f(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(f^*(y) = \inf_x (y^T x - f(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(f^*(y) = \sup_x (y^T x + f(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(f^*(y) = f(y)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f^*(y) = \sup_x (y^T x - f(x))$$&lt;/strong&gt;&lt;br /&gt;
                Hàm liên hợp Fenchel là cận trên đúng (supremum) của hiệu giữa hàm tuyến tính $$y^Tx$$ và hàm gốc $$f(x)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Fenchel duality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Bài toán đối ngẫu Fenchel của \(\min_x f(x) + g(Ax)\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(\max_v -f^*(A^T v) - g^*(-v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(\min_v f^*(A^T v) + g^*(v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(\max_v f^*(A^T v) - g^*(v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(\min_v -f^*(A^T v) + g^*(-v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max_v -f^*(A^T v) - g^*(-v)$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán đối ngẫu Fenchel biểu diễn mục tiêu đối ngẫu trực tiếp qua hàm liên hợp của $$f$$ và $$g$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Biconjugate --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Hàm song liên hợp (biconjugate) \(f^{**}\) của hàm lồi \(f\) thỏa mãn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(f^{**} = f\) (nếu \(f\) lồi, chính thường và nửa liên tục dưới)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(f^{**} = -f\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(f^{**} = f^2\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(f^{**} = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f^{**} = f$$ (nếu $$f$$ lồi, chính thường và nửa liên tục dưới)&lt;/strong&gt;&lt;br /&gt;
                Theo định lý Fenchel–Moreau, hàm song liên hợp của một hàm lồi chính thường, nửa liên tục dưới (đóng) chính là hàm ban đầu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Saddle point --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: \((x^*, u^*, v^*)\) là điểm yên (saddle point) của hàm Lagrange nếu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(L(x^*, u, v) \leq L(x^*, u^*, v^*) \leq L(x, u^*, v^*)\) với mọi \((x,u,v)\) khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(L(x^*, u^*, v^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(\nabla L(x^*, u^*, v^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(L(x, u, v) = L(x^*, u^*, v^*)\) với mọi \((x,u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$L(x^*, u, v) \leq L(x^*, u^*, v^*) \leq L(x, u^*, v^*)$$ với mọi $$(x,u,v)$$ khả thi&lt;/strong&gt;&lt;br /&gt;
                Điểm yên đạt cực tiểu theo biến nguyên thủy $$x$$ và đạt cực đại theo các biến đối ngẫu $$(u, v)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Slater condition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Với bài toán lồi, điều kiện Slater đảm bảo:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Tính đối ngẫu mạnh được thỏa mãn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Tính đối ngẫu yếu được thỏa mãn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Khoảng cách đối ngẫu bằng 0&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Cả A và C&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Cả A và C&lt;/strong&gt;&lt;br /&gt;
                Điều kiện Slater (tồn tại điểm khả thi ngặt) đảm bảo tính đối ngẫu mạnh, tức là không có khoảng cách đối ngẫu ($$p^* = d^*$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Linear programming dual --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Bài toán đối ngẫu của LP \(\min c^T x\) thỏa mãn \(Ax = b, x \geq 0\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(\max b^T y\) thỏa mãn \(A^T y \leq c\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(\min b^T y\) thỏa mãn \(A^T y \geq c\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(\max c^T y\) thỏa mãn \(A^T y = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(\min A^T y\) thỏa mãn \(b^T y \leq c\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max b^T y$$ thỏa mãn $$A^T y \leq c$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán đối ngẫu chuẩn của LP có biến $$y$$ tự do và ràng buộc $$A^T y \leq c$$ (tương đương $$A^T y + s = c, s \geq 0$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Quadratic programming dual --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Bài toán đối ngẫu của QP \(\min \frac{1}{2}x^T Q x + c^T x\) thỏa mãn \(Ax \leq b\) với \(Q \succ 0\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) \(\max -\frac{1}{2}(A^T u + c)^T Q^{-1} (A^T u + c) - b^T u\) thỏa mãn \(u \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) \(\min \frac{1}{2}u^T Q u - b^T u\) thỏa mãn \(u \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) \(\max b^T u\) thỏa mãn \(A^T u = c\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) \(\min c^T u + b^T u\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max -\frac{1}{2}(A^T u + c)^T Q^{-1} (A^T u + c) - b^T u$$ thỏa mãn $$u \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Từ điều kiện dừng $$\nabla_x L = Qx + c + A^T u = 0 \Rightarrow x = -Q^{-1}(A^T u + c)$$, thay lại vào hàm Lagrange thu được bài toán đối ngẫu trên.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Conjugate of quadratic --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Hàm liên hợp của \(f(x) = \frac{1}{2}x^T Q x\) với \(Q \succ 0\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(f^*(y) = \frac{1}{2}y^T Q^{-1} y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(f^*(y) = \frac{1}{2}y^T Q y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(f^*(y) = y^T Q^{-1} y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) \(f^*(y) = -\frac{1}{2}y^T Q^{-1} y\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f^*(y) = \frac{1}{2}y^T Q^{-1} y$$&lt;/strong&gt;&lt;br /&gt;
                Hàm liên hợp của dạng toàn phương xác định dương thay ma trận $$Q$$ bằng nghịch đảo $$Q^{-1}$$ và giữ nguyên hệ số $$\frac{1}{2}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Moreau envelope --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Bao Moreau (Moreau envelope) của hàm \(f\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(M_\lambda f(x) = \inf_z \left( f(z) + \frac{1}{2\lambda}\|x-z\|^2 \right)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(M_\lambda f(x) = f(x) + \lambda\|x\|^2\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(M_\lambda f(x) = \lambda f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(M_\lambda f(x) = f(\lambda x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$M_\lambda f(x) = \inf_z \left( f(z) + \frac{1}{2\lambda}\|x-z\|^2 \right)$$&lt;/strong&gt;&lt;br /&gt;
                Bao Moreau là một xấp xỉ trơn của hàm $$f$$ thu được bằng phép chập infimal với hàm điều chuẩn bậc hai.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Proximal operator --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Toán tử lân cận (proximal operator) liên hệ với bao Moreau như thế nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) \(\text{prox}_{\lambda f}(x) = \arg\min_z \left( f(z) + \frac{1}{2\lambda}\|x-z\|^2 \right)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) \(\text{prox}_{\lambda f}(x) = \nabla M_\lambda f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) \(\text{prox}_{\lambda f}(x) = M_\lambda f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) \(\text{prox}_{\lambda f}(x) = x - \lambda \nabla f(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\text{prox}_{\lambda f}(x) = \arg\min_z \left( f(z) + \frac{1}{2\lambda}\|x-z\|^2 \right)$$&lt;/strong&gt;&lt;br /&gt;
                Toán tử lân cận chính là điểm đạt cực tiểu (argmin) của bài toán tối ưu trong định nghĩa bao Moreau.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Duality in SVM --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Trong SVM, bài toán đối ngẫu có ưu điểm nào sau đây?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Có thể áp dụng thủ thuật hạt nhân (kernel trick)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Số biến phụ thuộc vào số điểm dữ liệu thay vì số chiều đặc trưng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Là bài toán quy hoạch bậc hai với ràng buộc hộp đơn giản&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Tất cả các ưu điểm trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các ưu điểm trên&lt;/strong&gt;&lt;br /&gt;
                Bài toán đối ngẫu của SVM cho phép dùng kernel trick, có ràng buộc đơn giản và đặc biệt hiệu quả khi không gian đặc trưng có số chiều lớn.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Weak duality theorem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Định lý đối ngẫu yếu khẳng định rằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) \(d^* \leq p^*\) luôn đúng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) \(d^* \geq p^*\) luôn đúng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) \(d^* = p^*\) luôn đúng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Không có quan hệ giữa \(d^*\) và \(p^*\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$d^* \leq p^*$$ luôn đúng&lt;/strong&gt;&lt;br /&gt;
                Theo đối ngẫu yếu, giá trị tối ưu đối ngẫu luôn là cận dưới của giá trị tối ưu nguyên thủy, bất kể bài toán có lồi hay không.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Applications of duality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Lý thuyết đối ngẫu được ứng dụng trong lĩnh vực nào sau đây?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Phân tích độ nhạy (sensitivity analysis)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Thiết kế thuật toán (các phương pháp đối ngẫu và nguyên thủy – đối ngẫu)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Phân tích lý thuyết và thiết lập cận tối ưu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các ứng dụng trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các ứng dụng trên&lt;/strong&gt;&lt;br /&gt;
                Lý thuyết đối ngẫu đóng vai trò nền tảng trong phân tích độ nhạy, thiết kế thuật toán, ước lượng cận dưới và diễn giải kinh tế (giá bóng).
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Trong lý thuyết đối ngẫu, tính đối ngẫu mạnh xảy ra khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Khoảng cách đối ngẫu bằng 0&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Bài toán nguyên thủy không khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Bài toán đối ngẫu không khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Cả hai bài toán đều không bị chặn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Khoảng cách đối ngẫu bằng 0&lt;/strong&gt;&lt;br /&gt;
                Tính đối ngẫu mạnh nghĩa là $$p^* = d^*$$, tức khoảng cách đối ngẫu $$p^* - d^* = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Hàm liên hợp Fenchel của hàm $$f(x) = \frac{1}{2}x^2$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$f^*(y) = \frac{1}{2}y^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$f^*(y) = y^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$f^*(y) = \frac{1}{4}y^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$f^*(y) = 2y^2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f^*(y) = \frac{1}{2}y^2$$&lt;/strong&gt;&lt;br /&gt;
                Hàm liên hợp Fenchel của $$\frac{1}{2}x^2$$ là $$\sup_x (yx - \frac{1}{2}x^2) = \frac{1}{2}y^2$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Định lý song đối ngẫu (biconjugate) khẳng định:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$f^{**} = f$$ nếu $$f$$ lồi, chính thường và đóng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$f^{**} = -f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$f^{**} = f^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$f^{**}$$ không tồn tại&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f^{**} = f$$ nếu $$f$$ lồi, chính thường và đóng&lt;/strong&gt;&lt;br /&gt;
                Với hàm lồi chính thường và đóng, lấy liên hợp hai lần sẽ quay trở về đúng hàm ban đầu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Phân rã Moreau (Moreau decomposition) cho biết:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$x = \text{prox}_f(x) + \text{prox}_{f^*}(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$x = \text{prox}_f(x) - \text{prox}_{f^*}(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$x = \text{prox}_f(x) \cdot \text{prox}_{f^*}(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Không có công thức tổng quát&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$x = \text{prox}_f(x) + \text{prox}_{f^*}(x)$$&lt;/strong&gt;&lt;br /&gt;
                Phân rã Moreau cho thấy mọi điểm $$x$$ có thể được phân tách thành tổng ảnh qua toán tử lân cận của $$f$$ và của hàm liên hợp $$f^*$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Phép biến đổi Legendre (Legendre transform) liên quan trực tiếp đến:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Hàm liên hợp Fenchel (Fenchel conjugate)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Ma trận Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Trị riêng (eigenvalue)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Hàm liên hợp Fenchel (Fenchel conjugate)&lt;/strong&gt;&lt;br /&gt;
                Phép biến đổi Legendre là trường hợp đặc biệt của hàm liên hợp Fenchel đối với các hàm lồi ngặt và khả vi.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành Quiz!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;a&apos;, q3: &apos;a&apos;, q4: &apos;a&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;d&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;a&apos;, q17: &apos;a&apos;, q18: &apos;d&apos;, q19: &apos;a&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã thành thạo duality theory và advanced concepts!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu tốt về Lagrangian và Fenchel duality.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại KKT conditions và conjugate functions.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Ôn lại strong duality và optimality conditions.&apos;;
    } else {
        message = &apos;📖 Hãy học lại từ đầu về duality theory nhé!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>16-03 Tính đối ngẫu Fenchel</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_03_fenchel_duality/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_03_fenchel_duality</id>
   <content type="html">&lt;p&gt;Đối ngẫu Lagrange rất mạnh khi bài toán được viết tường minh dưới dạng hàm mục tiêu kèm các bất đẳng thức vô hướng \(h_i(x) \le 0\). Nhưng khi bài toán là tổng hai hàm lồi không trơn ghép qua một toán tử tuyến tính \(\min_x f(x) + g(Ax)\) — hoặc đặc biệt hơn, là &lt;strong&gt;Quy hoạch nón (Conic Programming)&lt;/strong&gt; với ràng buộc \(x \in K\) (nón bậc hai, nón ma trận nửa xác định dương) — thì &lt;strong&gt;Đối ngẫu Fenchel&lt;/strong&gt; lại tỏa sáng với vẻ đẹp đối xứng và sức tổng quát vượt trội.&lt;/p&gt;

&lt;p&gt;Chỉ bằng đúng hai hàm liên hợp \(f^*\) và \(g^*\), định lý đối ngẫu Fenchel biến bài toán nguyên thủy \(\min_x f(x) + g(Ax)\) thành bài toán đối ngẫu \(\max_y -f^*(A^T y) - g^*(-y)\) (tùy quy ước dấu). Không cần phân tách từng ràng buộc bất đẳng thức, toàn bộ cấu trúc hình học của nón \(K\) tự động chuyển thành nón đối ngẫu \(K^*\) chỉ sau một bước tính liên hợp của hàm chỉ thị!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-đối-ngẫu-fenchel-và-quy-hoạch-nón&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của Đối ngẫu Fenchel và Quy hoạch nón&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cặp bài toán Đối ngẫu Fenchel:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nguyên thủy: \(\min_x f(x) + g(Ax)\).&lt;/li&gt;
      &lt;li&gt;Đối ngẫu: \(\max_u -f^*(-A^T u) - g^*(u)\) (hoặc đổi biến \(y = -u\) thành \(\max_y -f^*(A^T y) - g^*(-y)\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện đối ngẫu mạnh Fenchel–Rockafellar:&lt;/strong&gt; Khi \(f, g\) lồi và tồn tại điểm \(x \in \operatorname{dom} f\) sao cho \(Ax \in \operatorname{int}(\operatorname{dom} g)\) (hoặc điều kiện tương đối trong cho tập affine), khoảng cách đối ngẫu Fenchel bằng \(0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai hàm liên hợp chìa khóa cho Quy hoạch nón:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Liên hợp của hàm chỉ thị không gian affine \(I_{\{Ax = b\}}(x)\) liên kết trực tiếp với nhân tử \(y\) qua \(A^T y\).&lt;/li&gt;
      &lt;li&gt;Liên hợp của hàm chỉ thị nón \(I_K(x)\) chính là hàm chỉ thị của &lt;strong&gt;nón cực&lt;/strong&gt; \(-K^*\) (tức \(I_K^*(z) = I_{K^*}(-z)\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sức mạnh thống nhất LP – SOCP – SDP:&lt;/strong&gt; Quy hoạch nón chuẩn \(\min \{c^T x \mid Ax = b, x \in K\}\) tự động sinh ra đối ngẫu \(\max \{b^T y \mid c - A^T y \in K^*\}\) — chỉ cần thay \(K = \mathbb{R}_+^n, \mathcal{Q}_n, \mathbb{S}_+^n\) là có ngay đối ngẫu của LP, SOCP và SDP!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-áp-dụng-đối-ngẫu-fenchel-suy-ra-đối-ngẫu-của-một-bài-toán-quy-hoạch-nón-bậc-hai-socp-nhỏ&quot;&gt;Giải thích: Áp dụng Đối ngẫu Fenchel suy ra đối ngẫu của một bài toán Quy hoạch Nón Bậc Hai (SOCP) nhỏ&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch nón bậc hai trên \(\mathbb{R}^3\) với biến \(x = (x_1, x_2, x_3)^T\) thuộc nón bậc hai \(K = \{(x_1, x_2, x_3) : \sqrt{x_1^2 + x_2^2} \le x_3\}\) (nhớ \(K\) tự đối ngẫu: \(K^* = K\)):&lt;/p&gt;

&lt;p&gt;\(\min_{x \in \mathbb{R}^3} x_1 + 2x_3 \qquad \text{với } x_3 = 1, \;\; x \in K.\)
(Tức \(c = (1, 0, 2)^T\), \(A = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}\), \(b = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải nhanh trực tiếp bài toán nguyên thủy để kiểm chứng:&lt;/strong&gt;
Vì \(x_3 = 1\) và \(\sqrt{x_1^2 + x_2^2} \le 1\), giá trị nhỏ nhất của \(x_1 + 2(1)\) đạt tại \(x_1^\star = -1, x_2^\star = 0, x_3^\star = 1\), cho \(p^\star = -1 + 2 = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suy dẫn bài toán đối ngẫu bằng công thức đối ngẫu nón Fenchel:&lt;/strong&gt;
\(\max_{y \in \mathbb{R}} b^T y \qquad \text{với } s = c - A^T y \in K^* = K.\)
Ta tính \(s = \begin{bmatrix} 1 \\ 0 \\ 2 \end{bmatrix} - \begin{bmatrix} 0 \\ 0 \\ y \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \\ 2 - y \end{bmatrix}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng điều kiện \(s \in K\) (nón bậc hai):&lt;/strong&gt;
\(\sqrt{1^2 + 0^2} \le 2 - y \iff 1 \le 2 - y \iff y \le 1.\)
Vậy bài toán đối ngẫu là \(\max_{y \le 1} y\), đạt cực đại tại \(y^\star = 1\) với \(d^\star = 1 = p^\star\)!
Kiểm tra thêm tính trực giao nón (bù yếu nón): \(x^{\star T} s^\star = (-1)(1) + 0(0) + (1)(1) = 0\) — khớp hoàn hảo!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trong bài &lt;a href=&quot;/contents/vi/chapter13/13_04_Conjugate_function/&quot;&gt;13-04 Hàm liên hợp&lt;/a&gt;, chúng ta đã biết cách suy ra bài toán đối ngẫu bằng hàm liên hợp (conjugate function). Tính đối ngẫu Fenchel đề cập đến các bài toán đối ngẫu được xây dựng từ hàm liên hợp theo dạng tổng quát sau:&lt;/p&gt;

\[\max_{v} -f^*(A^Tv) - g^*(-v)\]

&lt;p&gt;Hãy xem dạng đối ngẫu này xuất phát từ đâu.&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy&quot;&gt;Bài toán nguyên thủy&lt;/h3&gt;

&lt;blockquote&gt;
\[\min_{x} \quad f(x) + g(Ax)\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán này có thể viết lại tương đương bằng cách đưa thêm biến phụ \(z\) và ràng buộc đẳng thức:&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy-được-viết-lại&quot;&gt;Bài toán nguyên thủy được viết lại&lt;/h3&gt;
&lt;blockquote&gt;

\[\begin{align}
 &amp;amp;\min_{x,z} \        &amp;amp;&amp;amp; f(x) + g(z)\\
 &amp;amp;\text{subject to} \ &amp;amp;&amp;amp; Ax = z.
 \end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ta suy ra bài toán đối ngẫu của dạng viết lại bằng hàm liên hợp. &lt;br /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nhắc lại:&lt;/strong&gt; \(f^*(s) \doteq  \max_{x} \big( s^Tx - f(x) \big) = -\min_{x} \big( f(x) - s^Tx \big)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br /&gt;
\(\begin{align}
&amp;amp;\max_{v} \min_{x, z} \quad L(x,z,v)\\\\
= &amp;amp;\max_{v} \min_{x, z} \quad f(x) + g(z) + v^T (z - Ax) \\\\
= &amp;amp;\max_{v} \min_{x, z} \quad v^Tz + g(z) - (A^Tv)^Tx + f(x)\\\\
= &amp;amp;\max_{v} \quad  -f^*(A^Tv) - g^*(-v)\\\\
\end{align}\)&lt;/p&gt;

&lt;h3 id=&quot;tính-đối-ngẫu-fenchel&quot;&gt;Tính đối ngẫu Fenchel&lt;/h3&gt;
&lt;blockquote&gt;
\[\max_{v} -f^*(A^Tv) - g^*(-v)\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất quan trọng:&lt;/strong&gt; Nếu \(f, g\) là các hàm lồi và đóng, thì bài toán đối ngẫu của bài toán đối ngẫu quay trở lại chính bài toán nguyên thủy (tính đối xứng).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ví-dụ-quy-hoạch-nón-conic-programming&quot;&gt;Ví dụ: quy hoạch nón (Conic Programming)&lt;/h2&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy-của-cp-dạng-chuẩn&quot;&gt;Bài toán nguyên thủy của CP dạng chuẩn&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
    \mathop{\text{minimize}}_x &amp;amp;\quad c^Tx \\\\
    \text{subject to} &amp;amp;\quad Ax = b \\\\
    &amp;amp;\quad x \in K
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán trên có thể viết lại thông qua hai hàm \(f(x) = c^Tx + I_K(x)\) và \(g(z) = I_{\{b\}}(z)\).&lt;br /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; \(\begin{equation}
  f(x) + g(Ax) = 
  \begin{cases}
    c^Tx, &amp;amp; \text{nếu}\ Ax=b, x \in K \\\\
    \infty, &amp;amp; \text{trường hợp khác}
  \end{cases}
\end{equation}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy-của-cp-được-viết-lại&quot;&gt;Bài toán nguyên thủy của CP được viết lại&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, z}       \ &amp;amp;&amp;amp;  f(x) + g(z)\\\
&amp;amp;\text{subject to} \ &amp;amp;&amp;amp; z  =Ax \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;suy-ra-bài-toán-đối-ngẫu-của-cp&quot;&gt;Suy ra bài toán đối ngẫu của CP&lt;/h3&gt;

&lt;p&gt;Từ dạng viết lại ở trên, triển khai tường minh hai hàm \(f\) và \(g\), ta có:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \min_{x, z} &amp;amp;&amp;amp; \; c^Tx + I_K(x) + I_{\{b\}}(z)  \\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp; \;  z   =Ax \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Áp dụng định nghĩa bài toán đối ngẫu và biến đổi bằng hàm liên hợp:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \max_{y} \; \min_{x, z} \;  L(x, z, y) \\\
= \; &amp;amp; \max_{y} \; \min_{x, z} \;  c^Tx + I_K(x) + I_{\{b\}}(z) + y^T(z-Ax) \\\
= \; &amp;amp; \max_{y}  \;\min_{x, z} \; (c - A^Ty)^Tx  + I_K(x) \;+ \;  y^Tz + I_{\{b\}}(z) \\\
= \; &amp;amp; \max_{y} \;  \min_{x, z} \; -( (A^Ty - c)^Tx  - I_K(x)) \;  - \; ( - y^Tz - I_{\{b\}}(z) ) \\\
= \; &amp;amp; \max_{y} \; - I_K^*(A^Ty - c)  -  I_{\{b\}}^*(-y)  \\\
= \; &amp;amp; \max_{y} \; - I_{-K^*}(A^Ty - c)  - I_{\{b\}}^*(-y)  \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Số hạng \(I_{-K^*}(A^Ty - c)\) có thể được chuyển thành ràng buộc tường minh:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
A^Ty - c &amp;amp; = -s, \; -s \in -K^* \\\
\Leftrightarrow A^Ty + s &amp;amp; = c, \; s \in K^* \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do \(I_{\{b\}}^*(-y) = \max_{z} (-y^Tz - I_{\{b\}}(z)) = -b^Ty - I_{\{b\}}(b)\), bài toán có thể được viết lại như sau:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{y, s} \ &amp;amp;&amp;amp; -(-b^Ty - I_{\{b\}}(b)) \\\
&amp;amp;\text{subject to} \ &amp;amp;&amp;amp; A^Ty + s = c \\\
&amp;amp;  \; s \in K^* \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì \(I_{\{b\}}(b) = 0\), ta rút gọn được:&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-đối-ngẫu-của-cp&quot;&gt;Bài toán đối ngẫu của CP&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{y, s} \ &amp;amp;&amp;amp;  \;  b^Ty  \\\
&amp;amp;\text{subject to} \ &amp;amp;&amp;amp; A^Ty + s = c \\\
&amp;amp;  \; s \in K^* \\
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Nếu bài toán nguyên thủy hoặc bài toán đối ngẫu khả thi ngặt, thì tính đối ngẫu mạnh được thỏa mãn.&lt;/li&gt;
  &lt;li&gt;Nếu cả bài toán nguyên thủy và bài toán đối ngẫu đều khả thi ngặt, thì tính đối ngẫu mạnh được thỏa mãn và cả hai bài toán đều đạt nghiệm tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ví-dụ-quy-hoạch-nửa-xác-định-sdp&quot;&gt;Ví dụ: quy hoạch nửa xác định (SDP)&lt;/h2&gt;
&lt;p&gt;Dưới đây là dạng nguyên thủy – đối ngẫu của quy hoạch nửa xác định (SDP) cùng cặp nguyên thủy – đối ngẫu cho bài toán rào cản tương ứng.&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy-của-sdp&quot;&gt;Bài toán nguyên thủy của SDP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\mathop{\text{minimize}}_{X} &amp;amp;&amp;amp;{tr(CX)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{tr(A_iX) = b_i, \phantom{5} i=1,\dotsc,p} \\\\
   &amp;amp; &amp;amp;&amp;amp;{X \succeq 0},\\\\
\end{align}\]

\[\text{trong đó } C, A_1, \dotsc, A_p \in \mathbb{S}^n.\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nhắc lại:&lt;/strong&gt; \(tr(CX) = \sum_{i,j=1}^n C_{ij}X_{ij}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Khác với LP, SDP không phải lúc nào cũng thỏa mãn tính đối ngẫu mạnh.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bài-toán-đối-ngẫu-của-sdp&quot;&gt;Bài toán đối ngẫu của SDP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\mathop{\text{maximize}}_{y} &amp;amp;&amp;amp;{b^Ty} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\sum_{i=1}^p y_i A_i + S = C} \\\\
   &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Nón ma trận nửa xác định dương là một nón tự đối ngẫu: \((\mathbb{S}_{+}^n)^* = \mathbb{S}_{+}^n\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy-của-bài-toán-rào-cản-cho-sdp&quot;&gt;Bài toán nguyên thủy của bài toán rào cản cho SDP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\mathop{\text{minimize}}_{X} &amp;amp;&amp;amp;{tr(CX) - \tau \log \big( det(X) \big)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{tr(A_iX) = b_i, \phantom{5} i=1,\dotsc,p} \\\\
\end{align}\]

\[\text{trong đó } C, A_1, \dotsc, A_p \in \mathbb{S}^n.\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;bài-toán-đối-ngẫu-của-bài-toán-rào-cản-cho-sdp&quot;&gt;Bài toán đối ngẫu của bài toán rào cản cho SDP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\mathop{\text{maximize}}_{y, S} &amp;amp;&amp;amp;{b^Ty +  \tau \log \big( det(S) \big)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\sum_{i=1}^p y_i A_i + S = C}.
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>16-02 Điều kiện tối ưu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_02_optimality_conditions/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_02_optimality_conditions</id>
   <content type="html">&lt;p&gt;Nếu đặt hệ điều kiện tối ưu &lt;strong&gt;KKT&lt;/strong&gt; của bài toán gốc và hệ phương trình &lt;strong&gt;Đường trung tâm (Central Path)&lt;/strong&gt; của bài toán chắn cạnh nhau trên hai cột, bạn sẽ ngỡ ngàng nhận ra chúng giống nhau gần như từng ký tự! Khác biệt duy nhất nằm ở đúng một phương trình: điều kiện bù yếu \(u_i h_i(x) = 0\) được dịch chuyển mượt mà thành \(-u_i h_i(x) = \frac{1}{t}\) (hay trong LP dạng chuẩn là \(x_i s_i = \mu\) với \(\mu = 1/t\)).&lt;/p&gt;

&lt;p&gt;Cú đặt cạnh nhau có chủ đích ở mục 16-02 chính là bản thiết kế kỹ thuật cho toàn bộ Chương 17: phương pháp điểm trong nguyên thủy – đối ngẫu sẽ &lt;strong&gt;không&lt;/strong&gt; lập bài toán chắn thuần nguyên thủy nữa, mà trực tiếp áp dụng &lt;strong&gt;phương pháp Newton để giải hệ phương trình đường trung tâm&lt;/strong&gt; \(F_\mu(x, y, s) = 0\) trong khi giảm dần \(\mu \to 0\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-so-sánh-kkt-và-đường-trung-tâm&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép so sánh KKT và Đường trung tâm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hệ điều kiện KKT cho bài toán tổng quát:&lt;/strong&gt; Gồm 4 khối: (1) Điều kiện dừng, (2) Khả thi nguyên thủy, (3) Khả thi đối ngẫu, và (4) Bù yếu \(u_i h_i(x) = 0\). Khi đối ngẫu mạnh thỏa mãn, KKT vừa là điều kiện &lt;strong&gt;cần&lt;/strong&gt; vừa là điều kiện &lt;strong&gt;đủ&lt;/strong&gt; cho tối ưu toàn cục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ phương trình đường trung tâm:&lt;/strong&gt; Giữ nguyên (1), siết chặt (2) và (3) thành khả thi chặt (\(h_i(x) &amp;lt; 0, u_i &amp;gt; 0\)), và thay (4) bằng \(-u_i h_i(x) = 1/t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dạng đặc biệt cực đẹp của Quy hoạch tuyến tính (LP dạng chuẩn):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;KKT của LP:&lt;/strong&gt; \(Ax = b, \; x \ge 0\); \(A^T y + s = c, \; s \ge 0\); và \(X S \mathbf{1} = 0\) (tức \(x_i s_i = 0 \;\forall i\)).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Đường trung tâm của LP:&lt;/strong&gt; Chỉ thay đúng phương trình cuối thành \(X S \mathbf{1} = \mu \mathbf{1}\) (tức \(x_i s_i = \mu &amp;gt; 0\) với \(\mu = 1/t\))!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu trực tiếp trong LP:&lt;/strong&gt; Với mọi cặp \((x, y, s)\) khả thi nguyên thủy – đối ngẫu, ta có \(c^T x - b^T y = (A^T y + s)^T x - (Ax)^T y = s^T x = \sum_{i=1}^n x_i s_i\)! Trên đường trung tâm, tổng này bằng đúng \(n\mu = n/t\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-hệ-phương-trình-đường-trung-tâm-của-lp-dạng-chuẩn-bằng-tay&quot;&gt;Giải thích: Giải hệ phương trình đường trung tâm của LP dạng chuẩn bằng tay&lt;/h3&gt;

&lt;p&gt;Quay lại bài toán LP 2 biến ở bài trước: \(\min 3x_1 + 5x_2\) thỏa \(x_1 + 2x_2 = 4, \; x_1, x_2 \ge 0\) (có nghiệm KKT gốc \(x^\star = (0, 2), \; y^\star = 2.5, \; s^\star = (0.5, 0)\)). Hãy giải hệ đường trung tâm với tham số nhiễu \(\mu = 0.5\) (tức \(t = 2\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Viết đầy đủ 5 phương trình của đường trung tâm LP (\(x &amp;gt; 0, s &amp;gt; 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Khả thi nguyên thủy: \(x_1 + 2x_2 = 4\).&lt;/li&gt;
      &lt;li&gt;Khả thi đối ngẫu: \(y + s_1 = 3\) và \(2y + s_2 = 5\).&lt;/li&gt;
      &lt;li&gt;Bù yếu nhiễu: \(x_1 s_1 = 0.5\) và \(x_2 s_2 = 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải rút gọn theo 1 biến \(y\):&lt;/strong&gt;
Từ \(s_1 = 3 - y &amp;gt; 0\) và \(s_2 = 5 - 2y &amp;gt; 0\) (nên \(y &amp;lt; 2.5\)), ta suy ra:
\(x_1 = \frac{0.5}{3 - y}, \qquad x_2 = \frac{0.5}{5 - 2y}.\)
Thay vào \(x_1 + 2x_2 = 4\):
\(\frac{0.5}{3 - y} + \frac{1}{5 - 2y} = 4.\)
Thử kiểm tra nhanh giá trị \(y \approx 2.345\):
    &lt;ul&gt;
      &lt;li&gt;\(s_1 = 3 - 2.345 = 0.655 \implies x_1 = \frac{0.5}{0.655} \approx 0.763\).&lt;/li&gt;
      &lt;li&gt;\(s_2 = 5 - 4.690 = 0.310 \implies x_2 = \frac{0.5}{0.310} \approx 1.613\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra \(x_1 + 2x_2 = 0.763 + 3.226 = 3.989 \approx 4\) (nghiệm chính xác là \(y(\mu) \approx 2.346, \; x(\mu) \approx (0.765, 1.618), \; s(\mu) \approx (0.654, 0.309)\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng khoảng cách đối ngẫu \(c^T x - b^T y = x^T s = n\mu\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(c^T x \approx 3(0.765) + 5(1.618) = 10.385\); \(b^T y \approx 4(2.346) = 9.384\).&lt;/li&gt;
      &lt;li&gt;Hiệu \(c^T x - b^T y \approx 1.00 = 2 \times 0.5 = n\mu\)! Khớp chính xác lý thuyết!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trong phần này, chúng ta ôn lại các điều kiện tối ưu KKT cho bài toán nguyên thủy và bài toán rào cản (barrier) tương ứng, sau đó so sánh sự khác biệt giữa hai hệ điều kiện này.
&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;điều-kiện-tối-ưu-kkt&quot;&gt;Điều kiện tối ưu KKT&lt;/h2&gt;

&lt;p&gt;Hãy xem lại các điều kiện KKT đã trình bày ở Chương 12 — đây là công cụ cốt lõi để kiểm tra tính tối ưu của nghiệm.&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy&quot;&gt;Bài toán nguyên thủy&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad f(x) \\\\
   \text{subject to} &amp;amp;\quad h_i(x) \leq 0, i = 1, \ldots, m \\\\
   &amp;amp;\quad l_j(x) = 0, j = 1, \ldots, r
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Khi bài toán nguyên thủy là bài toán lồi, các điều kiện KKT trở thành điều kiện đủ cho tính tối ưu nguyên thủy – đối ngẫu. Cụ thể, giả sử \(f, h_1, \dots, h_m\) lồi, \(l_1, \dots, l_r\) là các hàm affine (và các hàm đều khả vi): nếu \(x^\star, u^\star, v^\star\) thỏa mãn các điều kiện KKT dưới đây, thì \(x^\star\) và \((u^\star, v^\star)\) lần lượt là nghiệm tối ưu nguyên thủy và đối ngẫu với khoảng cách đối ngẫu bằng \(0\). &lt;br /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tham khảo: &lt;a href=&quot;/contents/vi/chapter12/12_00_KKT_conditions/&quot;&gt;12-01 Điều kiện KKT&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;điều-kiện-kkt-cho-bài-toán-nguyên-thủy-đã-cho&quot;&gt;Điều kiện KKT cho bài toán nguyên thủy đã cho&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
l_i(x^\star) &amp;amp;= 0, \quad i=1, \dots, r\\\\
u_i^\star, -h_i(x^\star) &amp;amp;\ge 0, \quad i=1, \dots, m\\\\
u_i^\star h_i(x^\star) &amp;amp;= 0, \quad i=1, \dots, m\\\\
\nabla f(x^\star) + \sum_{i=1}^m \nabla h_i(x^\star) u^\star_i + \sum_{i=1}^r \nabla l_i(x^\star) v_i^\star &amp;amp;= 0.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;phương-trình-đường-trung-tâm-central-path&quot;&gt;Phương trình đường trung tâm (Central Path)&lt;/h2&gt;

&lt;p&gt;Tiếp theo, ta xét các điều kiện xác định tính tối ưu của bài toán rào cản.&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-rào-cản&quot;&gt;Bài toán rào cản&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
    \mathop{\text{minimize}}_x &amp;amp;\quad f(x) + \tau \phi(x) \\\\
    &amp;amp;\quad l_j(x) = 0, j = 1, \ldots, r  \\\\
\end{align}\]

\[\text{trong đó } \phi(x) = - \sum_{i=1}^m \log \big( -h_i(x) \big).\]
&lt;/blockquote&gt;

&lt;p&gt;Từ các điều kiện KKT của bài toán rào cản, ta thu được hệ điều kiện tối ưu sau. Cần chú ý sự khác biệt ở ràng buộc bất đẳng thức (chuyển thành bất đẳng thức ngặt) và điều kiện bù chặt (chuyển từ \(0\) thành \(-\tau\)) so với hệ điều kiện KKT của bài toán nguyên thủy ở trên. (Tham khảo: &lt;a href=&quot;/contents/vi/chapter15/chapter16/15_03_01_perturbed_kkt_conditions/&quot;&gt;15-03-01 Điều kiện KKT bị nhiễu&lt;/a&gt;)&lt;/p&gt;

&lt;h3 id=&quot;điều-kiện-tối-ưu-cho-bài-toán-rào-cản-và-bài-toán-đối-ngẫu-của-nó&quot;&gt;Điều kiện tối ưu cho bài toán rào cản (và bài toán đối ngẫu của nó)&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
l_i(x^\star(t)) &amp;amp;= 0, \quad i=1, \dots, r\\\\
u_i(t), -h_i(x^\star(t)) &amp;amp;\gt 0, \quad i=1, \dots, m\\\\
u_i(t) h_i(x^\star(t)) &amp;amp;= -\tau, \quad i=1, \dots, m\\\\
\nabla f(x^\star(t)) + \sum_{i=1}^m \nabla h_i(x^\star(t)) u_i(t) + \sum_{i=1}^r \nabla l_i(x^\star(t)) \hat{v}_i^\star &amp;amp;= 0,\\\\
\end{align} \\\\\]

\[\text{trong đó } \tau = \frac{1}{t}, u_i(t) = - \frac{1}{t h_i(x^\star(t))}, \quad \hat{v} = \frac{1}{t}v.\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;trường-hợp-đặc-biệt-quy-hoạch-tuyến-tính&quot;&gt;Trường hợp đặc biệt: quy hoạch tuyến tính&lt;/h2&gt;

&lt;h3 id=&quot;nhắc-lại-bài-toán-nguyên-thủy-của-lp-dạng-chuẩn&quot;&gt;Nhắc lại: Bài toán nguyên thủy của LP dạng chuẩn&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad c^Tx \\\\
   \text{subject to} &amp;amp;\quad Ax = b \\\\
   &amp;amp;\quad x \ge 0
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;nhắc-lại-bài-toán-đối-ngẫu-của-lp&quot;&gt;Nhắc lại: Bài toán đối ngẫu của LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{maximize}}_{s,y} &amp;amp;\quad b^Ty \\\\
   \text{subject to} &amp;amp;\quad A^Ty +  s = c \\\\
   &amp;amp;\quad s \ge 0
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Quy hoạch tuyến tính có tính chất thuận lợi là luôn thỏa mãn tính đối ngẫu mạnh theo điều kiện Slater tinh chỉnh (khi khả thi), bởi mọi ràng buộc bất đẳng thức đều là affine. Các điều kiện tối ưu cho LP như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
A^T y^\star + s^\star &amp;amp;= c\\\\
Ax^\star &amp;amp;= b\\\\
X S \mathbb{1} &amp;amp;= 0\\\\
x^\star, s^\star &amp;amp;\ge 0,\\\\
\end{align}\]

\[\text{trong đó }X = Diag(x^\star), S = Diag(s^\star)\]
&lt;/blockquote&gt;

&lt;p&gt;Lưu ý rằng \(X S \mathbb{1} = 0\) tương đương với \(Xs^\star = (x_1^\star s_1^\star, \dots, x_n^\star s_n^\star)^T = 0\). Cách ký hiệu bằng ma trận đường chéo \(X, S\) sẽ rất thuận tiện khi trình bày các thuật toán ở phần sau.&lt;/p&gt;

&lt;h3 id=&quot;thuật-toán-giải-quy-hoạch-tuyến-tính&quot;&gt;Thuật toán giải quy hoạch tuyến tính&lt;/h3&gt;

&lt;p&gt;Có hai lớp phương pháp tiêu biểu để giải LP dựa trên hệ điều kiện tối ưu trên:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Phương pháp đơn hình (Simplex): Duy trì các điều kiện 1, 2 và 3 (hoặc tính khả thi cơ sở và bù chặt) trong khi từng bước đạt tới điều kiện 4 (tính không âm đối ngẫu).&lt;/li&gt;
  &lt;li&gt;Phương pháp điểm trong (Interior-point method): Duy trì điều kiện 4 (tính dương ngặt) trong khi tiến dần tới việc thỏa mãn các điều kiện 1, 2 và 3. Phương pháp này sẽ được trình bày chi tiết ở chương tiếp theo.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đường-trung-tâm-cho-quy-hoạch-tuyến-tính&quot;&gt;Đường trung tâm cho quy hoạch tuyến tính&lt;/h2&gt;

&lt;h3 id=&quot;nhắc-lại-bài-toán-rào-cản-cho-lp&quot;&gt;Nhắc lại: Bài toán rào cản cho LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
    \mathop{\text{minimize}}_x &amp;amp;\quad c^Tx - \tau \sum_{i=1}^n \log(x_i)\\\\
    \text{subject to} &amp;amp;\quad Ax = b, \\\\
    \text{trong đó}  &amp;amp;\quad \tau &amp;gt; 0
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;nhắc-lại-bài-toán-đối-ngẫu-của-bài-toán-rào-cản-cho-lp&quot;&gt;Nhắc lại: Bài toán đối ngẫu của bài toán rào cản cho LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{maximize}}_{s,y} &amp;amp;\quad b^Ty + \tau \sum_{i=1}^n \log(s_i)\\\\
   \text{subject to} &amp;amp;\quad A^Ty +  s = c \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Các điều kiện tối ưu cho bài toán rào cản của LP là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
A^T y^\star + s^\star &amp;amp;= c\\\\
Ax^\star &amp;amp;= b\\\\
X S \mathbb{1} &amp;amp;= \tau \mathbb{1}\\\\
x^\star, s^\star &amp;amp;\gt 0,\\\\
\text{trong đó} &amp;amp;\quad X = Diag(x^\star), S = Diag(s^\star)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Hai điều kiện 3 và 4 thể hiện rõ sự khác biệt so với hệ điều kiện KKT của bài toán LP gốc.&lt;/p&gt;

&lt;h3 id=&quot;kkt-pháp-tuyến-và-nhân-tử-lagrange-video&quot;&gt;KKT: pháp tuyến và nhân tử Lagrange (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/kkt-normals_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Tại điểm tối ưu, \(-\nabla f(x^*)\) là tổ hợp tuyến tính không âm của các pháp tuyến ràng buộc đang tác dụng, còn các ràng buộc không tác dụng có nhân tử bằng \(0\).&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-nhân-tử-kkt&quot;&gt;Tự tay thử: nhân tử KKT&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;kkt&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>16-01 Tính đối ngẫu Lagrangian - nhìn lại</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_01_lagrangian_duality_revisited/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter16/16_01_lagrangian_duality_revisited</id>
   <content type="html">&lt;p&gt;Trong lịch sử toán học, khi nhìn bài toán nguyên thủy và bài toán đối ngẫu dưới dạng hai danh sách ràng buộc tách biệt, ta dễ bị rối trong rừng ký hiệu. Thế nhưng, chỉ cần viết lại cả hai bài toán bằng &lt;strong&gt;một hàm Lagrange duy nhất \(L(x, u, v)\)&lt;/strong&gt;, toàn bộ lý thuyết đối ngẫu bỗng thu gọn lại thành một phép hoán đổi thứ tự cực kỳ đối xứng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nguyên thủy: \(\min_x \max_{u \ge 0, v} L(x, u, v)\)&lt;/li&gt;
  &lt;li&gt;Đối ngẫu: \(\max_{u \ge 0, v} \min_x L(x, u, v)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Góc nhìn minimax này không chỉ biến chứng minh tính đối ngẫu yếu thành đúng &lt;strong&gt;một dòng hiển nhiên&lt;/strong&gt;, mà còn làm sáng tỏ điều kiện &lt;strong&gt;Slater tinh chỉnh (refined Slater’s condition)&lt;/strong&gt;: đối với các ràng buộc bất đẳng thức &lt;em&gt;tuyến tính&lt;/em&gt; (như trong quy hoạch tuyến tính LP), ta thậm chí &lt;strong&gt;không cần&lt;/strong&gt; điểm khả thi chặt (\(&amp;lt; 0\)) mà chỉ cần khả thi thường (\(\le 0\))!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-điểm-nâng-cấp-khi-nhìn-lại-đối-ngẫu-lagrange&quot;&gt;Kiến thức cần nhớ: Bốn điểm nâng cấp khi nhìn lại Đối ngẫu Lagrange&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch16_kkt_duality_bridge.svg&quot; alt=&quot;Cầu nối Đối ngẫu Lagrange và Điều kiện KKT&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Biểu diễn Minimax của bài toán nguyên thủy:&lt;/strong&gt; \(\sup_{u \ge 0, v} L(x, u, v)\) bằng đúng \(f(x)\) khi \(x\) khả thi và bằng \(+\infty\) khi \(x\) vi phạm bất kỳ ràng buộc nào — nên bài toán nguyên thủy tương đương tuyệt đối với \(\inf_x \sup_{u \ge 0, v} L(x, u, v)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu yếu chỉ là bất đẳng thức Max-Min:&lt;/strong&gt; Với mọi hàm \(L\) bất kỳ (không cần lồi!), ta luôn có \(\sup_{u \ge 0, v} \inf_x L(x, u, v) \le \inf_x \sup_{u \ge 0, v} L(x, u, v)\), suy ra ngay \(d^\star \le p^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện Slater tinh chỉnh (Refined Slater):&lt;/strong&gt; Chỉ cần tồn tại \(x \in \operatorname{relint}(\mathcal{D})\) thỏa \(Ax = b\), các ràng buộc &lt;strong&gt;phi tuyến&lt;/strong&gt; thỏa chặt \(h_i(x) &amp;lt; 0\), còn các ràng buộc &lt;strong&gt;affine/tuyến tính&lt;/strong&gt; chỉ cần thỏa thường \(h_j(x) \le 0\)! Hệ quả cực mạnh: mọi bài toán LP khả thi và bị chặn đều tự động thỏa đối ngẫu mạnh!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suy dẫn đối ngẫu LP dạng chuẩn:&lt;/strong&gt; Áp dụng khung minimax cho \(\min c^T x\) thỏa \(Ax = b, x \ge 0\) cho ra ngay đối ngẫu \(\max b^T y\) thỏa \(A^T y + s = c, s \ge 0\) (với biến bù đối ngẫu \(s\) cực kỳ quan trọng cho Chương 17).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-áp-dụng-slater-tinh-chỉnh-và-suy-dẫn-đối-ngẫu-lp-dạng-chuẩn-bằng-tay&quot;&gt;Giải thích: Áp dụng Slater tinh chỉnh và suy dẫn đối ngẫu LP dạng chuẩn bằng tay&lt;/h3&gt;

&lt;p&gt;Xét bài toán LP dạng chuẩn 2 biến:
\(\min_{x \in \mathbb{R}^2} 3x_1 + 5x_2 \qquad \text{với } x_1 + 2x_2 = 4, \;\; x_1 \ge 0, \;\; x_2 \ge 0.\)
Ở đây \(c = (3, 5)^T\), \(A = \begin{bmatrix} 1 &amp;amp; 2 \end{bmatrix}\), \(b = 4\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện Slater tinh chỉnh:&lt;/strong&gt;
Điểm \(x = (4, 0)^T\) thỏa \(x_1 + 2x_2 = 4\) và \(x \ge 0\) (dù \(x_2 = 0\) không chặt!). Vì mọi ràng buộc đều là tuyến tính (affine), theo điều kiện Slater tinh chỉnh, &lt;strong&gt;đối ngẫu mạnh chắc chắn thỏa mãn&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suy dẫn bài toán đối ngẫu qua hàm Lagrange:&lt;/strong&gt;
\(L(x, s, y) = c^T x - s^T x + y^T(b - Ax) = b^T y + (c - A^T y - s)^T x, \qquad s \ge 0.\)
Để \(\min_x L &amp;gt; -\infty\) ta cần \(A^T y + s = c\), tức:
\(y + s_1 = 3, \qquad 2y + s_2 = 5, \qquad s_1 \ge 0, \; s_2 \ge 0.\)
Bài toán đối ngẫu là \(\max_{y, s \ge 0} 4y\) với \(y \le 3\) và \(2y \le 5 \implies y \le 2.5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải và đối chiếu nguyên thủy – đối ngẫu:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đối ngẫu: \(y^\star = 2.5\), \(s^\star = (3 - 2.5, \; 5 - 5)^T = (0.5, \; 0)^T\), giá trị \(d^\star = 4(2.5) = 10\).&lt;/li&gt;
      &lt;li&gt;Nguyên thủy: từ bù yếu \(s_1^\star x_1^\star = 0 \implies x_1^\star = 0\), thay vào \(x_1 + 2x_2 = 4 \implies x_2^\star = 2\), giá trị \(p^\star = 3(0) + 5(2) = 10 = d^\star\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trong phần này, chúng ta sẽ chỉ ra cách biểu diễn bài toán nguyên thủy và bài toán đối ngẫu thông qua hàm Lagrange (Lagrangian), rồi dùng cách biểu diễn này để suy ra bài toán đối ngẫu cho quy hoạch tuyến tính (LP) dạng chuẩn và quy hoạch bậc hai (QP). Tiếp đó, chúng ta sẽ tìm bài toán đối ngẫu của bài toán rào cản (barrier) cho quy hoạch tuyến tính, và thấy rằng dạng của nó trùng khớp với bài toán rào cản thiết lập cho bài toán đối ngẫu của quy hoạch tuyến tính.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
Trước hết, xét bài toán nguyên thủy và hàm Lagrange tương ứng như sau.&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy&quot;&gt;Bài toán nguyên thủy&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad f(x) \\\\
   \text{subject to} &amp;amp;\quad h_i(x) \leq 0, i = 1, \ldots, m \\\\
   &amp;amp;\quad l_j(x) = 0, j = 1, \ldots, r
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;hàm-lagrange-lagrangian&quot;&gt;Hàm Lagrange (Lagrangian)&lt;/h3&gt;
&lt;blockquote&gt;
\[L(x,u,v) = f(x) + \sum_{i=1}^m u_i h_i (x) + \sum_{j=1}^r v_j l_j (x)\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;br /&gt;
Khi đó, bài toán nguyên thủy và bài toán đối ngẫu có thể được viết lại dưới dạng các bài toán minimax/maximin liên quan trực tiếp đến hàm Lagrange.&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy-được-viết-lại&quot;&gt;Bài toán nguyên thủy được viết lại&lt;/h3&gt;
&lt;blockquote&gt;
\[\min_x \mathop{\max_{u,v}}_{u \geq 0} L(x,u,v)\]
&lt;/blockquote&gt;

&lt;p&gt;Dạng viết lại này không liệt kê tường minh các ràng buộc, nhưng phần cực đại hóa theo \(u, v\) đóng vai trò như một hàm chỉ thị (indicator function) đối với mọi điểm \(x\) không khả thi:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Nếu tồn tại \(i \in [1, m]\) sao cho \(h_i(\hat{x}) \gt 0\), thì \(\hat{x}\) là điểm không khả thi. Khi đó, số hạng \(u_i h_i(\hat{x})\) phân kỳ ra \(\infty\) khi lấy \(\max_{u,v}\) với \(u \geq 0\), do đó đóng vai trò như hàm chỉ thị phạt vô hạn mọi điểm \(\hat{x}\) vi phạm ràng buộc bất đẳng thức.&lt;/li&gt;
  &lt;li&gt;Nếu tồn tại \(i \in [1, r]\) sao cho \(l_i(\hat{x}) \neq 0\), thì \(\hat{x}\) là điểm không khả thi. Khi đó, số hạng \(v_i l_i(\hat{x})\) phân kỳ ra \(\infty\) khi lấy \(\max_{u,v}\), do đó đóng vai trò như hàm chỉ thị đối với mọi điểm \(\hat{x}\) vi phạm ràng buộc đẳng thức.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;bài-toán-đối-ngẫu-được-viết-lại&quot;&gt;Bài toán đối ngẫu được viết lại&lt;/h3&gt;
&lt;blockquote&gt;
\[\mathop{\max_{u,v}}_{u \geq 0} \min_x L(x,u,v)\]
&lt;/blockquote&gt;

&lt;p&gt;Trong bài toán đối ngẫu, miền ràng buộc được nới lỏng nên hàm mục tiêu bên trong không còn đóng vai trò hàm chỉ thị cho các ràng buộc nguyên thủy. Vì phép lấy \(\min_x\) với \(u, v\) cố định không áp đặt các ràng buộc của bài toán nguyên thủy, bài toán đối ngẫu viết lại cũng thể hiện rõ cơ chế nới lỏng miền này. (Tham khảo: &lt;a href=&quot;/contents/vi/chapter11/11_02_Lagrange_dual_function/&quot;&gt;11-02 Hàm đối ngẫu Lagrange&lt;/a&gt;)&lt;/p&gt;

&lt;h2 id=&quot;tính-đối-ngẫu-yếu-và-mạnh&quot;&gt;Tính đối ngẫu yếu và mạnh&lt;/h2&gt;
&lt;p&gt;Chúng ta ôn lại hai định lý cơ bản về tính đối ngẫu yếu và tính đối ngẫu mạnh.&lt;/p&gt;

&lt;h3 id=&quot;định-lý-tính-đối-ngẫu-yếu&quot;&gt;Định lý: tính đối ngẫu yếu&lt;/h3&gt;
&lt;p&gt;Gọi \(p\) và \(d\) lần lượt là giá trị tối ưu của bài toán nguyên thủy và bài toán đối ngẫu. Khi đó, bất đẳng thức sau luôn đúng:&lt;/p&gt;

\[p \ge d\]

&lt;h3 id=&quot;định-lý-tính-đối-ngẫu-mạnh-điều-kiện-slater-tinh-chỉnh&quot;&gt;Định lý: tính đối ngẫu mạnh (điều kiện Slater tinh chỉnh)&lt;/h3&gt;
&lt;p&gt;Trên miền xác định \(D\), giả sử \(f, h_1, \dots, h_p\) là các hàm lồi và \(h_{p+1}, \dots, h_m, l_1, \dots, l_r\) là các hàm affine. Nếu tồn tại điểm \(\hat{x} \in \text{relint}(D)\) thỏa mãn:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
h_i(\hat{x}) \ &amp;amp; \lt 0, \ &amp;amp;&amp;amp; i=1, \dots, p \\
h_i(\hat{x}) \ &amp;amp; \le 0, \ &amp;amp;&amp;amp; i=p+1, \dots, m \\
l_j(\hat{x}) \ &amp;amp; = 0, \ &amp;amp;&amp;amp; j = 1, \dots, r
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;thì \(p = d\) được đảm bảo cho các giá trị tối ưu \(p, d\) của bài toán nguyên thủy và bài toán đối ngẫu.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-quy-hoạch-tuyến-tính&quot;&gt;Ví dụ: quy hoạch tuyến tính&lt;/h2&gt;
&lt;p&gt;Ta suy ra bài toán đối ngẫu của quy hoạch tuyến tính (LP) từ dạng định nghĩa ở trên.&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy-của-lp-dạng-chuẩn&quot;&gt;Bài toán nguyên thủy của LP dạng chuẩn&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad c^Tx \\\\
   \text{subject to} &amp;amp;\quad Ax = b \\\\
   &amp;amp;\quad x \ge 0
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Theo định nghĩa đã nêu, bài toán đối ngẫu tương ứng là:&lt;/p&gt;

\[\mathop{\max_{s,y}}_{s\ge0} \min_{x} \: L(x,s,y) = \mathop{\max_{s,y}}_{s\ge0} \min_{x} \: c^Tx - s^Tx + (b-Ax)^T y\]

&lt;p&gt;Từ điều kiện dừng \(\nabla_x L = 0\), ta thu được quan hệ \(c = A^Ty + s\). Thay quan hệ này vào bài toán đối ngẫu:&lt;/p&gt;

\[\mathop{\max_{s,y}}_{s\ge0} \: (A^Ty + s)^Tx - s^Tx + (b-Ax)^Ty \quad \text{ s.t. } c=A^Ty +s\]

&lt;p&gt;Rút gọn biểu thức trên, ta thu được:&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-đối-ngẫu-của-lp&quot;&gt;Bài toán đối ngẫu của LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{maximize}}_{s,y} &amp;amp;\quad b^Ty \\\\
   \text{subject to} &amp;amp;\quad A^Ty +  s = c \\\\
   &amp;amp;\quad s \ge 0
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;ví-dụ-quy-hoạch-bậc-hai-lồi&quot;&gt;Ví dụ: quy hoạch bậc hai lồi&lt;/h2&gt;
&lt;p&gt;Tiếp theo, ta áp dụng cùng cách tiếp cận để suy ra bài toán đối ngẫu của quy hoạch bậc hai lồi (QP).&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-nguyên-thủy-của-qp-dạng-chuẩn&quot;&gt;Bài toán nguyên thủy của QP dạng chuẩn&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad \frac{1}{2} x^T Q x + c^Tx \\
   \text{subject to} &amp;amp;\quad Ax = b \\
   &amp;amp;\quad x \ge 0, \\

\end{align}\]

\[\text{trong đó } Q \text{ là ma trận đối xứng và nửa xác định dương.}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán đối ngẫu tương ứng có dạng:&lt;/p&gt;

\[\mathop{\max_{s,y}}_{s\ge0} \min_{x} \: L(x,s,y) = \mathop{\max_{s,y}}_{s\ge0} \min_{x} \:  \frac{1}{2} x^T Q x + c^Tx - s^Tx + (b-Ax)^T y\]

&lt;p&gt;Giải điều kiện dừng \(\nabla_x L = 0\) cho ta quan hệ \(Qx = A^Ty + s - c\). Thay vào bài toán đối ngẫu:&lt;/p&gt;

\[\begin{align}
&amp;amp;\mathop{\max_{s,y,x}}_{s\ge0} \: \frac{1}{2} x^T (A^Ty +s - c) + c^Tx - s^Tx + (b-Ax)^T y \quad \text{ s.t. } Qx = A^Ty +s - c\\\\
&amp;amp;= \mathop{\max_{s,y,x}}_{s\ge0} \: x^T (A^Ty +s - c) + c^Tx - s^Tx + (b-Ax)^T y -  \frac{1}{2} x^T (A^Ty +s - c) \quad \text{ s.t. } Qx = A^Ty +s - c\\\\
&amp;amp;= \mathop{\max_{s,y,x}}_{s\ge0}  \: b^Ty - \frac{1}{2} x^T (A^Ty +s - c) \quad  \text{ s.t. } Qx = A^Ty +s - c\\\\
&amp;amp;= \mathop{\max_{s,y,x}}_{s\ge0}  \: b^Ty - \frac{1}{2} x^T Q x \quad \text{ s.t. } Qx = A^Ty +s - c
\end{align}\]

&lt;p&gt;Viết gọn lại, ta thu được:&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-đối-ngẫu-của-qp&quot;&gt;Bài toán đối ngẫu của QP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{maximize}}_{s,y,x} &amp;amp;\quad b^Ty - \frac{1}{2} x^T Q x\\\\
   \text{subject to} &amp;amp;\quad A^Ty +  s - c = Qx \\\\
   &amp;amp;\quad s \ge 0
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Như vậy, bài toán đối ngẫu của một bài toán quy hoạch bậc hai cũng là một bài toán quy hoạch bậc hai.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-bài-toán-rào-cản-cho-quy-hoạch-tuyến-tính&quot;&gt;Ví dụ: bài toán rào cản cho quy hoạch tuyến tính&lt;/h2&gt;
&lt;p&gt;Bài toán rào cản (barrier) cho quy hoạch tuyến tính được định nghĩa như sau:&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-rào-cản-cho-lp&quot;&gt;Bài toán rào cản cho LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad c^Tx - \tau \sum_{i=1}^n \log(x_i)\\
   \text{subject to} &amp;amp;\quad Ax = b, \\
\end{align}\]

\[\text{trong đó }\tau &amp;gt; 0.\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán đối ngẫu tương ứng là:
\(\begin{align}
\max_{y} \min_{x} \: L(x,y) &amp;amp;= \max_{y} \min_{x} \:  c^Tx - \tau \sum_{i=1}^n \log(x_i) + (b-Ax)^T y\\\\
&amp;amp;=  \max_{y} \min_{x} \:  \underbrace{(c-A^Ty)^T}_{s^T \doteq (c-A^Ty)^T}x - \tau \sum_{i=1}^n \log(x_i) + b^Ty\\\\
&amp;amp;= \max_{y} \min_{x} \: \sum_{i=1}^n \big( s_i x_i - \tau  \log(x_i) \big) + b^Ty  \quad \text{ s.t. } A^Ty +s = c
\end{align}\)&lt;/p&gt;

&lt;p&gt;Biểu thức \(\sum_{i=1}^n \big( s_i x_i - \tau \log(x_i) \big) + b^Ty\) đạt giá trị nhỏ nhất khi \(x_i = \frac{\tau}{s_i}\) (với \(s_i &amp;gt; 0\)). Thay \(x_i = \frac{\tau}{s_i}\) vào bài toán đối ngẫu:&lt;/p&gt;

\[\begin{align}
&amp;amp;\max_{s,y} \: b^Ty + n\tau - \tau \sum_{i=1}^n \log\left(\frac{\tau}{s_i}\right) \quad \text{ s.t. } A^Ty +s = c\\\\
&amp;amp;= \max_{s,y} \: b^Ty + \tau \sum_{i=1}^n \log(s_i) + n\tau - n\tau\log(\tau) \quad \text{ s.t. } A^Ty +s = c\\\\
\end{align}\]

&lt;p&gt;Vì hằng số \(n\tau - n\tau\log(\tau)\) không ảnh hưởng đến nghiệm tối ưu, ta có thể bỏ qua hằng số này và viết gọn bài toán đối ngẫu như sau:&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-đối-ngẫu-của-bài-toán-rào-cản-cho-lp&quot;&gt;Bài toán đối ngẫu của bài toán rào cản cho LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{maximize}}_{s,y} &amp;amp;\quad b^Ty + \tau \sum_{i=1}^n \log(s_i)\\\\
   \text{subject to} &amp;amp;\quad A^Ty +  s = c \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Có thể thấy bài toán này trùng khớp hoàn toàn với bài toán rào cản thiết lập trực tiếp cho bài toán đối ngẫu của quy hoạch tuyến tính.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>16 Duality Revisited</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_duality_revisited/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_duality_revisited</id>
   <content type="html">&lt;p&gt;You have already met Lagrange duality in Chapter 11, KKT conditions in Chapter 12, and log-barrier interior-point methods in Chapter 15. Why pause right here to &lt;em&gt;revisit&lt;/em&gt; duality before entering Chapter 17? Because the barrier method solves only the primal problem while treating dual variables as a byproduct—whereas &lt;strong&gt;Primal-Dual Interior-Point Methods&lt;/strong&gt; update primal and dual variables &lt;em&gt;simultaneously&lt;/em&gt; on equal footing, and that symmetry only becomes transparent when you see Lagrangian min-max duality, perturbed KKT conditions, and Fenchel conjugates working together as one unified machine.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-duality-is-revisited-before-primal-dual-ipms&quot;&gt;Key ideas: Why Duality Is Revisited Before Primal-Dual IPMs&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Min–Max Saddle-Point Symmetry:&lt;/strong&gt; Writing the primal as \(\min_x \max_{u \ge 0, v} L(x, u, v)\) and the dual as \(\max_{u \ge 0, v} \min_x L(x, u, v)\) puts primal and dual variables on symmetric footing and explains weak duality in one line.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Self-Symmetry of Barrier Problems:&lt;/strong&gt; Taking the Lagrange dual of the LP barrier problem recovers the &lt;em&gt;exact&lt;/em&gt; barrier problem of the dual LP—revealing why primal-dual path-following is naturally symmetric.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Exact vs. Perturbed KKT Systems:&lt;/strong&gt; Comparing KKT optimality (\(u_i h_i = 0\)) with barrier KKT optimality (\(u_i h_i = -1/t\)) directly defines the nonlinear residual vector \(r_t(x, u, v) = 0\) that Chapter 17 solves with Newton’s method.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Fenchel Duality for Structured Problems:&lt;/strong&gt; The Fenchel pair \(\min_x f(x) + g(Ax) \leftrightarrow \max_v -f^*(A^T v) - g^*(-v)\) gives an algebraic shortcut for composite ML losses, regularizers, and optimal transport.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-seeing-the-saddle-point-minmax-identity-on-a-1d-lp&quot;&gt;Worked example: Seeing the Saddle-Point Min–Max Identity on a 1D LP&lt;/h3&gt;

&lt;p&gt;Consider the 1D LP \(\min_x 2x\) subject to \(x \ge 3\) (i.e., \(h(x) = 3 - x \le 0\)). Its Lagrangian is \(L(x, u) = 2x + u(3 - x) = (2 - u)x + 3u\) for \(u \ge 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Primal via \(\min_x \max_{u \ge 0} L(x, u)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;If \(x &amp;lt; 3\), \(3 - x &amp;gt; 0\) so \(\max_{u \ge 0} L(x, u) = +\infty\) (infeasible penalty!).&lt;/li&gt;
      &lt;li&gt;If \(x \ge 3\), \(3 - x \le 0\) so the maximum over \(u \ge 0\) is attained at \(u = 0\), giving \(2x\).&lt;/li&gt;
      &lt;li&gt;Minimizing \(2x\) over \(x \ge 3\) yields \(x^\star = 3, p^\star = 6\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual via \(\max_{u \ge 0} \min_x L(x, u)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;If \(u \ne 2\), \((2 - u)x\) can be driven to \(-\infty\), so \(\min_x L(x, u) = -\infty\).&lt;/li&gt;
      &lt;li&gt;If \(u = 2\), \(L(x, 2) = 6\) for all \(x\), giving \(u^\star = 2, d^\star = 6\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Saddle-point verification at \((x^\star, u^\star) = (3, 2)\):&lt;/strong&gt;
For every \(x \in \mathbb{R}\) and every \(u \ge 0\),
\(L(3, u) = 6 + u(0) = 6 \le L(3, 2) = 6 \le (2 - 2)x + 6 = L(x, 2).\)
\((3, 2)\) is an exact saddle point!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we organize essential background knowledge about duality before covering the Primal-Dual Interior-Point method. The Primal-Dual Interior-Point method can be viewed as an extension of the Barrier method, and the concept of duality emerges as a key topic in the process of developing the content.&lt;/p&gt;

&lt;h2 id=&quot;references-and-further-readings&quot;&gt;References and further readings&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;O. Guler (2010), “Foundations of Optimization”, Chapter 11.&lt;/li&gt;
  &lt;li&gt;J. Renegar (2001), “A mathematical view of interior-point methods in convex optimization,” Chapters 2 and 3.&lt;/li&gt;
  &lt;li&gt;S. Wright (1997), “Primal-dual interior-point methods”, Chapters 5 and 6.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>16-06 Practical Exercises - Duality Revisited</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_06_Practical_Exercises_Duality_Revisited/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_06_Practical_Exercises_Duality_Revisited</id>
   <content type="html">&lt;p&gt;Duality exercises in Chapter 16 focus on the deeper geometric and economic meaning of dual variables: how \(p^*(u)\) behaves when you perturb a constraint right-hand side (shadow prices), how saddle points certify global optimality without calculus, and how Fenchel conjugates cleanly dualize nonsmooth composite problems. Review this four-pillar workflow and worked perturbation example before solving the exercises below.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-exercise-solving-playbook-for-chapter-16&quot;&gt;Key ideas: Exercise-Solving Playbook for Chapter 16&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Perturbation &amp;amp; Shadow-Price Sign Convention:&lt;/strong&gt; Write the perturbed constraint cleanly as \(h_i(x) \le u_i\). Increasing \(u_i\) &lt;em&gt;relaxes&lt;/em&gt; the feasible set, so \(p^*(u)\) is nonincreasing and \(\lambda_i^\star = -\frac{\partial p^*(0)}{\partial u_i} \ge 0\). (If written as \(x \ge u\), increasing \(u\) &lt;em&gt;tightens&lt;/em&gt; the set, flipping the sign to \(+\frac{dp^*}{du}\)!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Checking Saddle Points Directly:&lt;/strong&gt; To prove \((x^\star, u^\star)\) is a saddle point of \(L\), verify the two inequalities \(L(x^\star, u) \le L(x^\star, u^\star) \le L(x, u^\star)\) for all \(x\) and all \(u \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Fenchel Dual Derivation Checklist:&lt;/strong&gt; Identify \(f\), \(g\), and \(A\); compute \(f^*\) and \(g^*\) carefully (including their effective domains!); assemble \(\max_v -f^*(A^T v) - g^*(-v)\); and check Slater/relative-interior qualification.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Verifying Barrier Self-Duality:&lt;/strong&gt; Always check that \(\min_{x &amp;gt; 0} (s_i x_i - \log x_i) = 1 + \log s_i\) for \(s_i &amp;gt; 0\) (and \(-\infty\) otherwise)—that single 1D identity drives every LP barrier dual derivation!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-sensitivity-analysis-shadow-price-on-a-constrained-quadratic&quot;&gt;Worked example: Sensitivity Analysis (Shadow Price) on a Constrained Quadratic&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize \(f(x) = \frac{1}{2}(x - 5)^2\) subject to \(h(x) = x - 2 \le u\) (i.e., \(x \le 2 + u\)). Compute \(p^*(u)\) and verify $$\lambda^\star = -\frac{dp^*}{du}\big&lt;/td&gt;
      &lt;td&gt;_{u=0}$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the perturbed primal for every \(u \in \mathbb{R}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Unconstrained minimizer is \(x = 5\).&lt;/li&gt;
      &lt;li&gt;If \(2 + u \ge 5\) (i.e., \(u \ge 3\)): constraint is inactive, \(x^\star(u) = 5\), so \(p^*(u) = 0\).&lt;/li&gt;
      &lt;li&gt;If \(u &amp;lt; 3\): constraint is active, \(x^\star(u) = 2 + u\), so \(p^*(u) = \frac{1}{2}(2 + u - 5)^2 = \frac{1}{2}(u - 3)^2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Differentiate \(p^*(u)\) at \(u = 0\):&lt;/strong&gt;
\(\frac{dp^*}{du}\Big|_{u=0} = (u - 3)\Big|_{u=0} = -3.\)
Predicted shadow price: \(\lambda^\star = -\frac{dp^*}{du}\Big|_{u=0} = +3\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify directly from KKT at \(u = 0\) (where \(x^\star = 2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Stationarity: \(f&apos;(x^\star) + \lambda^\star h&apos;(x^\star) = (2 - 5) + \lambda^\star(1) = 0 \implies \lambda^\star = 3\)!&lt;/li&gt;
      &lt;li&gt;Economic meaning: Loosening the cap \(x \le 2\) by a tiny amount \(\Delta u = 0.01\) drops the optimal cost by approximately \(\lambda^\star \Delta u = 3(0.01) = 0.03\) (exact check: \(\frac{1}{2}(-2.99)^2 - \frac{1}{2}(-3)^2 = 4.47005 - 4.5 = -0.02995\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---duality-revisited&quot;&gt;Practical Exercises - Duality Revisited&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd &amp;amp; Vandenberghe (2004) and Rockafellar (1970).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-1-perturbation-analysis&quot;&gt;📝 &lt;strong&gt;Exercise 1: Perturbation Analysis&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Consider the problem:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x^2 \\
\text{s.t.} \quad &amp;amp; x \geq u
\end{align}\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Find \(p^*(u)\) (the optimal value as a function of \(u\))&lt;br /&gt;
b) Verify \(\lambda^* = \frac{dp^*}{du}\) (the constraint \(u - x \leq 0\) gets tighter as \(u\) increases)&lt;br /&gt;
c) Explain the economic meaning&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Optimal value function:**

$$p^*(u) = \begin{cases}
u^2 &amp;amp; \text{if } u \geq 0 \\
0 &amp;amp; \text{if } u &amp;lt; 0
\end{cases}$$

**b) Derivative:**

$$\frac{dp^*}{du} = \begin{cases}
2u &amp;amp; \text{if } u &amp;gt; 0 \\
0 &amp;amp; \text{if } u &amp;lt; 0
\end{cases}$$

**Lagrangian:**

$$L(x, \lambda) = x^2 - \lambda(x - u)$$

KKT: $$2x^* - \lambda^* = 0$$, $$\lambda^*(x^* - u) = 0$$

- If $$u \geq 0$$: $$x^* = u$$, $$\lambda^* = 2u = \frac{dp^*}{du}$$ ✓
- If $$u &amp;lt; 0$$: $$x^* = 0$$, $$\lambda^* = 0$$ ✓

**c) Meaning:** $$\lambda^*$$ is the sensitivity of the optimal cost to a change in the constraint.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-strong-duality-via-slaters-condition&quot;&gt;📝 &lt;strong&gt;Exercise 2: Strong Duality via Slater’s Condition&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Consider the QCQP:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x_1^2 + x_2^2 \\
\text{s.t.} \quad &amp;amp; (x_1 - 1)^2 + x_2^2 \leq 1 \\
&amp;amp; x_1 + x_2 \geq 1
\end{align}\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Check Slater’s condition&lt;br /&gt;
b) Write the dual problem&lt;br /&gt;
c) Verify strong duality&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Slater&apos;s condition:**

We need to find a strictly feasible $$\tilde{x}$$:

$$
\begin{cases}
(x_1 - 1)^2 + x_2^2 &amp;lt; 1 \\
x_1 + x_2 &amp;gt; 1
\end{cases}
$$

Try $$\tilde{x} = (1, 0.5)$$:

$$(1-1)^2 + (0.5)^2 = 0.25 &amp;lt; 1$$ ✓

$$1 + 0.5 = 1.5 &amp;gt; 1$$ ✓

**Slater&apos;s condition is satisfied** → strong duality holds!

---

**b) Lagrangian:**

$$L(x, \lambda_1, \lambda_2) = x_1^2 + x_2^2 + \lambda_1[(x_1-1)^2 + x_2^2 - 1] - \lambda_2(x_1 + x_2 - 1)$$

**Dual function:**

$$g(\lambda_1, \lambda_2) = \inf_x L(x, \lambda)$$

KKT stationarity: $$\nabla_x L = 0$$:

$$2x_1 + 2\lambda_1(x_1 - 1) - \lambda_2 = 0$$

$$2x_2 + 2\lambda_1 x_2 - \lambda_2 = 0$$

---

**c) Numerical verification:**

Primal optimal: $$x^* = (0.5, 0.5)$$, $$p^* = 0.5$$ (the disk constraint is not active because $$(0.5-1)^2 + 0.5^2 = 0.5 &amp;lt; 1$$)

Dual optimal: $$\lambda^* = (0, 1)$$, $$d^* = 0.5$$ (from $$g(0, \lambda_2) = \lambda_2 - \lambda_2^2/2$$, maximized at $$\lambda_2 = 1$$)

**Gap:** $$p^* - d^* = 0$$ ✓ (strong duality!)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-dual-cones-and-conic-duality&quot;&gt;📝 &lt;strong&gt;Exercise 3: Dual Cones and Conic Duality&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Consider the second-order cone: \(K = \{(x, t) : \|x\| \leq t\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Find the dual cone \(K^*\)&lt;br /&gt;
b) Verify \(K^{**} = K\) (self-dual)&lt;br /&gt;
c) Apply to SOCP duality&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Dual cone:**

$$K^* = \{(y, s) : \langle (x,t), (y,s) \rangle \geq 0 \, \forall (x,t) \in K\}$$

$$= \{(y, s) : x^Ty + ts \geq 0 \, \forall \|x\| \leq t\}$$

Worst case: $$x = -t\frac{y}{\|y\|}$$ (if $$y \neq 0$$):

$$-t\|y\| + ts \geq 0 \Rightarrow s \geq \|y\|$$

$$K^* = \{(y, s) : \|y\| \leq s\} = K$$

**The SOCP cone is self-dual!**

---

**b) Verification:**

$$K^{**} = (K^*)^* = K^* = K$$ ✓

---

**c) SOCP duality:**

**Primal:**

$$
\begin{align}
\min \quad &amp;amp; c^Tx \\
\text{s.t.} \quad &amp;amp; \|A_ix + b_i\| \leq c_i^Tx + d_i
\end{align}
$$

**Dual:**

$$
\begin{align}
\max \quad &amp;amp; -\sum_i (b_i^Ty_i + d_iz_i) \\
\text{s.t.} \quad &amp;amp; \sum_i (A_i^Ty_i + c_iz_i) = c \\
&amp;amp; \|y_i\| \leq z_i
\end{align}
$$

The self-duality of the SOCP cone → a symmetric primal-dual relationship.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-minimax-duality&quot;&gt;📝 &lt;strong&gt;Exercise 4: Minimax Duality&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Consider the saddle point problem:&lt;/p&gt;

\[\min_{x \in X} \max_{y \in Y} f(x, y)\]

&lt;p&gt;with \(f(x, y) = x^TAy + b^Tx + c^Ty\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the dual problem&lt;br /&gt;
b) Conditions for minimax = maximin&lt;br /&gt;
c) Example: the matrix game \(A = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix}\), \(X = Y = \Delta_2\) (the simplex)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Dual problem:**

$$\max_{y \in Y} \min_{x \in X} f(x, y)$$

**Weak duality:**

$$\min_x \max_y f(x, y) \geq \max_y \min_x f(x, y)$$

---

**b) Minimax theorem (von Neumann):**

If $$X, Y$$ are compact convex sets and $$f$$ is convex-concave, then:

$$\min_x \max_y f = \max_y \min_x f$$

and a saddle point $$(x^*, y^*)$$ exists.

---

**c) Matrix game:**

$$\min_{x \in \Delta_2} \max_{y \in \Delta_2} x^T A y$$

$$A = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix}$$

**Inner max:**

$$\max_y x^TAy = \max\{2x_1 - x_2, -x_1 + x_2\}$$

(choose the pure strategy with the higher payoff)

**Outer min:**

$$\min_x \max\{2x_1 - x_2, -x_1 + x_2\}$$

With $$x_1 + x_2 = 1$$, $$x_2 = 1 - x_1$$:

$$\max\{2x_1 - (1-x_1), -x_1 + (1-x_1)\} = \max\{3x_1 - 1, 1 - 2x_1\}$$

Intersection: $$3x_1 - 1 = 1 - 2x_1 \Rightarrow 5x_1 = 2 \Rightarrow x_1 = 0.4$$

**Nash equilibrium:** $$x^* = (0.4, 0.6)$$, value = $$0.2$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-lagrangian-relaxation&quot;&gt;📝 &lt;strong&gt;Exercise 5: Lagrangian Relaxation&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Consider the integer program:&lt;/p&gt;

\[\begin{align}
\min \quad &amp;amp; c^Tx \\
\text{s.t.} \quad &amp;amp; Ax \leq b \\
&amp;amp; x \in \{0, 1\}^n
\end{align}\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the Lagrangian relaxation&lt;br /&gt;
b) Explain the lower bound property&lt;br /&gt;
c) Example: \(c = (-1, -2)\), \(A = [1, 1]\), \(b = 1\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Lagrangian relaxation:**

$$L(x, \lambda) = c^Tx + \lambda^T(Ax - b)$$

$$g(\lambda) = \min_{x \in \{0,1\}^n} L(x, \lambda) = \min_{x \in \{0,1\}^n} (c + A^T\lambda)^Tx - \lambda^Tb$$

Minimize over each $$x_i$$ independently:

$$x_i^* = \begin{cases}
0 &amp;amp; \text{if } c_i + (A^T\lambda)_i &amp;gt; 0 \\
1 &amp;amp; \text{if } c_i + (A^T\lambda)_i &amp;lt; 0
\end{cases}$$

---

**b) Lower bound:**

$$\max_{\lambda \geq 0} g(\lambda) \leq p^*$$

Solving the dual (easier) → a bound for the primal (NP-hard).

---

**c) Example:**

$$\min -x_1 - 2x_2$$ s.t. $$x_1 + x_2 \leq 1$$, $$x \in \{0,1\}^2$$

**Primal optimal:** $$x^* = (0, 1)$$, $$p^* = -2$$

**Lagrangian** (with $$\lambda \geq 0$$):

$$L(x, \lambda) = -x_1 - 2x_2 + \lambda(x_1 + x_2 - 1) = (\lambda - 1)x_1 + (\lambda - 2)x_2 - \lambda$$

**Dual function:**

$$g(\lambda) = \min(0, \lambda - 1) + \min(0, \lambda - 2) - \lambda = \begin{cases} \lambda - 3 &amp;amp; 0 \leq \lambda \leq 1 \\ -2 &amp;amp; 1 \leq \lambda \leq 2 \\ -\lambda &amp;amp; \lambda \geq 2 \end{cases}$$

**Dual optimal:** $$\lambda^* \in [1, 2]$$, $$d^* = -2 = p^*$$

**Strong duality!** (a lucky case; in general the relaxation only gives a lower bound $$d^* \leq p^*$$)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;duality-concepts&quot;&gt;&lt;strong&gt;Duality Concepts:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Concept&lt;/th&gt;
      &lt;th&gt;Key Idea&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Perturbation&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\lambda^* = -dp^*/du\) for constraints \(f_i(x) \leq u_i\) (sensitivity)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Slater’s condition&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Guarantees strong duality&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dual cone&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(K^* = \{y : y^Tx \geq 0 \, \forall x \in K\}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Minimax&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\min \max = \max \min\) under convexity&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Lagrangian relaxation&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Relax hard constraints → dual bound&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;when-strong-duality-holds&quot;&gt;&lt;strong&gt;When strong duality holds:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP:&lt;/strong&gt; Always (if feasible)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex:&lt;/strong&gt; Slater’s condition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SOCP/SDP:&lt;/strong&gt; An interior point exists&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-convex:&lt;/strong&gt; Generally fails (duality gap)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Chapter 5.&lt;/li&gt;
  &lt;li&gt;Rockafellar, R. T. (1970). &lt;em&gt;Convex Analysis&lt;/em&gt;. Princeton.&lt;/li&gt;
  &lt;li&gt;Borwein, J., &amp;amp; Lewis, A. (2006). &lt;em&gt;Convex Analysis and Nonlinear Optimization&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>16-05 Multiple-Choice Quiz - Duality Revisited</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_05_Quiz_Duality_Revisited/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_05_Quiz_Duality_Revisited</id>
   <content type="html">&lt;p&gt;This quiz brings together the entire duality arc of the course—Lagrangian min–max saddle points, LP/QP duals, the self-duality of LP barriers, exact vs. perturbed KKT conditions, and Fenchel–Rockafellar duality. Most quiz mistakes come from reversing a sign in \(g^*(-v)\) or forgetting which direction weak duality points (\(p^\star \ge d^\star\)). Use the four pillars and rapid warm-up below to lock in every formula before starting.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-high-yield-chapter-16-quiz-checkpoints&quot;&gt;Key ideas: High-Yield Chapter 16 Quiz Checkpoints&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Min–Max &amp;amp; Weak Duality:&lt;/strong&gt; Primal \(p^\star = \min_x \max_{u \ge 0, v} L(x, u, v)\) always satisfies \(p^\star \ge d^\star = \max_{u \ge 0, v} \min_x L(x, u, v)\) by the max–min inequality—no convexity required!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — LP &amp;amp; Barrier Symmetry:&lt;/strong&gt; Dual of \(\min c^T x\) s.t. \(Ax = b, x \ge 0\) is \(\max b^T y\) s.t. \(A^T y \le c\); dualizing the primal LP log-barrier recovers the dual LP log-barrier with \(x_i s_i = 1/t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — KKT vs. Perturbed KKT:&lt;/strong&gt; Exact KKT requires \(u_i h_i(x) = 0\) with \(u_i \ge 0, h_i(x) \le 0\); barrier KKT requires \(u_i h_i(x) = -1/t\) with strict inequalities \(u_i &amp;gt; 0, h_i(x) &amp;lt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Fenchel Dual &amp;amp; Optimality:&lt;/strong&gt; Dual of \(\min_x f(x) + g(Ax)\) is \(\max_v -f^*(A^T v) - g^*(-v)\), with primal-dual optimality iff \(A^T v^\star \in \partial f(x^\star)\) and \(-v^\star \in \partial g(Ax^\star)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-4-check-rapid-quiz-warm-up&quot;&gt;Worked example: 4-Check Rapid Quiz Warm-Up&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Weak duality sign check:&lt;/strong&gt; If a maximization dual yields \(g(u, v) = -7\) and a feasible primal yields \(f(x) = -4\), is this consistent?
    &lt;ul&gt;
      &lt;li&gt;Yes! \(p^\star \le -4\) and \(d^\star \ge -7\), so \(d^\star \le p^\star\) holds with duality gap \(-4 - (-7) = 3 \ge 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel dual sign check:&lt;/strong&gt; For \(\min_x f(x) + g(Ax)\) with \(f(x) = \frac{1}{2}\|x\|_2^2\) and \(g(z) = I_{\{b\}}(z)\), what is the Fenchel dual?
    &lt;ul&gt;
      &lt;li&gt;\(f^*(s) = \frac{1}{2}\|s\|_2^2\) and \(g^*(-v) = (-v)^T b = -b^T v\).&lt;/li&gt;
      &lt;li&gt;Dual: \(\max_v -\frac{1}{2}\|A^T v\|_2^2 + b^T v\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier dual slack check:&lt;/strong&gt; On the LP central path at \(t = 20\), if \(x_1(20) = 0.25\), what is the corresponding dual slack \(s_1(20) = (c - A^T y(20))_1\)?
    &lt;ul&gt;
      &lt;li&gt;From \(x_1 s_1 = 1/t\), \(s_1(20) = \frac{1}{20 \times 0.25} = \frac{1}{5} = 0.20\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Perturbation sensitivity check:&lt;/strong&gt; If the optimal value function \(p^*(u)\) for constraint \(h(x) \le u\) has derivative $$\frac{dp^*}{du}\big&lt;/td&gt;
          &lt;td&gt;_{u=0} = -3\(, what is the optimal Lagrange multiplier\)\lambda^\star$$?&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;By sensitivity analysis, $$\lambda^\star = -\frac{dp^*}{du}\big&lt;/td&gt;
              &lt;td&gt;_{u=0} = 3 \ge 0\((relaxing\)u &amp;gt; 0\(lowers the minimum cost at rate\)3$$).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-duality-revisited&quot;&gt;⚡ &lt;strong&gt;Duality Revisited&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;lagrangian-formulation-of-the-primal-dual-pair&quot;&gt;&lt;strong&gt;Lagrangian formulation of the primal-dual pair&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;The primal problem:&lt;/strong&gt;
\(\min_x f(x) \quad \text{s.t.} \quad h_i(x) \le 0, \quad l_j(x) = 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt;
\(L(x,u,v) = f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x)\)&lt;/p&gt;

&lt;h4 id=&quot;primal-dual-reformulation&quot;&gt;&lt;strong&gt;Primal-dual reformulation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Primal (reformulated):&lt;/strong&gt;
\(\min_x \max_{u \ge 0, v} L(x,u,v)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual (reformulated):&lt;/strong&gt;
\(\max_{u \ge 0, v} \min_x L(x,u,v)\)&lt;/p&gt;

&lt;h4 id=&quot;indicator-function-interpretation&quot;&gt;&lt;strong&gt;Indicator function interpretation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal:&lt;/strong&gt; \(\max_{u,v}\) acts as an indicator function for constraint violations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual:&lt;/strong&gt; \(\min_x\) provides domain relaxation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equivalence:&lt;/strong&gt; Reformulated problems equivalent to original under feasibility&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-weak-and-strong-duality-refined&quot;&gt;🔄 &lt;strong&gt;Weak and Strong Duality (Refined)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;weak-duality-theorem&quot;&gt;&lt;strong&gt;Weak Duality Theorem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Always true:&lt;/strong&gt; \(p \ge d\) (primal optimal ≥ dual optimal)&lt;/p&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt; From minimax inequality
\(\min_x \max_{u \ge 0, v} L(x,u,v) \ge \max_{u \ge 0, v} \min_x L(x,u,v)\)&lt;/p&gt;
&lt;/div&gt;

&lt;h4 id=&quot;strong-duality-refined-slaters-condition&quot;&gt;&lt;strong&gt;Strong Duality (Refined Slater’s Condition)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; For a domain \(D\), assume \(f, h_1,\ldots,h_p\) are convex and \(h_{p+1},\ldots,h_m, l_1,\ldots,l_r\) are affine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If exists \(\hat{x} \in \text{relint}(D)\) such that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(h_i(\hat{x}) &amp;lt; 0, \quad i = 1,\ldots,p\) (strict inequality for non-affine)&lt;/li&gt;
  &lt;li&gt;\(h_i(\hat{x}) \le 0, \quad i = p+1,\ldots,m\) (weak inequality for affine)&lt;/li&gt;
  &lt;li&gt;\(l_j(\hat{x}) = 0, \quad j = 1,\ldots,r\) (equality constraints)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Then:&lt;/strong&gt; \(p = d\) (strong duality holds)&lt;/p&gt;

&lt;h3 id=&quot;-duality-examples-revisited&quot;&gt;📊 &lt;strong&gt;Duality Examples Revisited&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-linear-programming-duality&quot;&gt;&lt;strong&gt;1. Linear Programming Duality&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Primal (Standard Form):&lt;/strong&gt;
\(\min c^T x \quad \text{s.t.} \quad Ax = b, \quad x \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lagrangian approach:&lt;/strong&gt;
\(L(x,s,y) = c^T x - s^T x + (b - Ax)^T y\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stationarity condition:&lt;/strong&gt; \(\nabla_x L = c - s - A^T y = 0\)
\(\Rightarrow c = A^T y + s\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt;
\(\max b^T y \quad \text{s.t.} \quad A^T y + s = c, \quad s \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;2-quadratic-programming-duality&quot;&gt;&lt;strong&gt;2. Quadratic Programming Duality&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Primal:&lt;/strong&gt;
\(\min \frac{1}{2}x^T Q x + c^T x \quad \text{s.t.} \quad Ax = b, \quad x \ge 0\)&lt;/p&gt;

&lt;p&gt;with \(Q\) symmetric positive semidefinite&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt;
\(L(x,s,y) = \frac{1}{2}x^T Q x + c^T x - s^T x + (b - Ax)^T y\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt; \(Qx + c - s - A^T y = 0\)
\(\Rightarrow Qx = A^T y + s - c\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt;
\(\max b^T y - \frac{1}{2}x^T Q x \quad \text{s.t.} \quad Qx = A^T y + s - c, \quad s \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key insight:&lt;/strong&gt; The dual of a QP is also a QP!&lt;/p&gt;

&lt;h4 id=&quot;3-barrier-method-duality&quot;&gt;&lt;strong&gt;3. Barrier Method Duality&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;LP Barrier Primal:&lt;/strong&gt;
\(\min c^T x - \tau \sum_{i=1}^n \log(x_i) \quad \text{s.t.} \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt;
\(L(x,y) = c^T x - \tau \sum_{i=1}^n \log(x_i) + (b - Ax)^T y\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimal \(x\):&lt;/strong&gt; \(x_i = \frac{\tau}{s_i}\) with \(s = c - A^T y\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LP Barrier Dual:&lt;/strong&gt;
\(\max b^T y + \tau \sum_{i=1}^n \log(s_i) \quad \text{s.t.} \quad A^T y + s = c\) (ignoring the constant \(n\tau(1 - \log\tau)\))&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beautiful result:&lt;/strong&gt; The barrier dual = the dual of the barrier problem!&lt;/p&gt;

&lt;h3 id=&quot;-optimality-conditions-comparison&quot;&gt;🎯 &lt;strong&gt;Optimality Conditions Comparison&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;original-problem-kkt&quot;&gt;&lt;strong&gt;Original Problem KKT&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
l_j(x^*) &amp;amp;= 0 \quad \forall j \\
u_i^*, -h_i(x^*) &amp;amp;\ge 0 \quad \forall i \\
u_i^* h_i(x^*) &amp;amp;= 0 \quad \forall i \\
\nabla f(x^*) + \sum u_i^* \nabla h_i(x^*) + \sum v_j^* \nabla l_j(x^*) &amp;amp;= 0
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;barrier-problem-kkt-perturbed&quot;&gt;&lt;strong&gt;Barrier Problem KKT (Perturbed)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
l_j(x^*(t)) &amp;amp;= 0 \quad \forall j \\
u_i(t), -h_i(x^*(t)) &amp;amp;&amp;gt; 0 \quad \forall i \\
u_i(t) h_i(x^*(t)) &amp;amp;= -\tau \quad \forall i \\
\nabla f(x^*(t)) + \sum u_i(t) \nabla h_i(x^*(t)) + \sum \hat{v}_j^* \nabla l_j(x^*(t)) &amp;amp;= 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;with \(\tau = \frac{1}{t}\), \(u_i(t) = -\frac{1}{t h_i(x^*(t))}\), \(\hat{v} = \frac{1}{t}v\)&lt;/p&gt;

&lt;h4 id=&quot;key-differences&quot;&gt;&lt;strong&gt;Key differences:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; \(= 0\) vs \(= -\tau\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feasibility:&lt;/strong&gt; \(\ge 0\) vs \(&amp;gt; 0\) (strict)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt; Exact vs perturbed KKT conditions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-linear-programming-special-case&quot;&gt;📈 &lt;strong&gt;Linear Programming Special Case&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;primal-dual-optimality-conditions&quot;&gt;&lt;strong&gt;Primal-Dual Optimality Conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
A^T y^* + s^* &amp;amp;= c \\
Ax^* &amp;amp;= b \\
X S \mathbf{1} &amp;amp;= 0 \\
x^*, s^* &amp;amp;\ge 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;with \(X = \text{diag}(x^*)\), \(S = \text{diag}(s^*)\)&lt;/p&gt;

&lt;h4 id=&quot;barrier-problem-conditions&quot;&gt;&lt;strong&gt;Barrier Problem Conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
A^T y^* + s^* &amp;amp;= c \\
Ax^* &amp;amp;= b \\
X S \mathbf{1} &amp;amp;= \tau \mathbf{1} \\
x^*, s^* &amp;amp;&amp;gt; 0
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;algorithm-implications&quot;&gt;&lt;strong&gt;Algorithm implications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Simplex (primal):&lt;/strong&gt; Maintains conditions 2, 3 and \(x \ge 0\); gradually satisfies 1 with \(s \ge 0\) (dual feasibility)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior Point:&lt;/strong&gt; Maintain condition 4; gradually satisfy 1,2,3&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Central path:&lt;/strong&gt; \(XS\mathbf{1} = \tau\mathbf{1}\) defines path to optimality&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-fenchel-duality&quot;&gt;🔗 &lt;strong&gt;Fenchel Duality&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;composite-problem-form&quot;&gt;&lt;strong&gt;Composite problem form&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Primal:&lt;/strong&gt; \(\min_x f(x) + g(Ax)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reformulated:&lt;/strong&gt; \(\min_{x,z} f(x) + g(z) \quad \text{s.t.} \quad Ax = z\)&lt;/p&gt;

&lt;h4 id=&quot;conjugate-function-approach&quot;&gt;&lt;strong&gt;Conjugate function approach&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt;
\(L(x,z,v) = f(x) + g(z) + v^T(z - Ax)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual function:&lt;/strong&gt;
\(\begin{align}
g(v) &amp;amp;= \min_{x,z} L(x,z,v) \\
&amp;amp;= \min_x [f(x) - (A^T v)^T x] + \min_z [g(z) + v^T z] \\
&amp;amp;= -f^*(A^T v) - g^*(-v)
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;fenchel-dual&quot;&gt;&lt;strong&gt;Fenchel Dual&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max_v -f^*(A^T v) - g^*(-v)\)&lt;/p&gt;

&lt;h4 id=&quot;beautiful-property&quot;&gt;&lt;strong&gt;Beautiful property&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Symmetry:&lt;/strong&gt; The dual of the dual = the primal (if \(f,g\) are convex and closed)&lt;/p&gt;

&lt;h3 id=&quot;-conic-programming-applications&quot;&gt;🎯 &lt;strong&gt;Conic Programming Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;standard-conic-program&quot;&gt;&lt;strong&gt;Standard Conic Program&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min c^T x \quad \text{s.t.} \quad Ax = b, \quad x \in K\)&lt;/p&gt;

&lt;h4 id=&quot;fenchel-reformulation&quot;&gt;&lt;strong&gt;Fenchel reformulation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;
\[f(x) = c^T x + I_K(x)\]
  &lt;/li&gt;
  &lt;li&gt;
\[g(z) = I_{\{b\}}(z)\]
  &lt;/li&gt;
  &lt;li&gt;
\[\min f(x) + g(Ax)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;conic-dual&quot;&gt;&lt;strong&gt;Conic Dual&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max b^T y \quad \text{s.t.} \quad A^T y + s = c, \quad s \in K^*\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key insight:&lt;/strong&gt; Dual cone \(K^*\) appears naturally!&lt;/p&gt;

&lt;h4 id=&quot;strong-duality-conditions&quot;&gt;&lt;strong&gt;Strong duality conditions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal strictly feasible&lt;/strong&gt; OR &lt;strong&gt;dual strictly feasible&lt;/strong&gt; (and a finite optimal value) ⟹ strong duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Both strictly feasible&lt;/strong&gt; ⟹ strong duality + optimal solutions exist&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-semidefinite-programming-sdp&quot;&gt;📊 &lt;strong&gt;Semidefinite Programming (SDP)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;primal-sdp&quot;&gt;&lt;strong&gt;Primal SDP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min \text{tr}(CX) \quad \text{s.t.} \quad \text{tr}(A_i X) = b_i, \quad X \succeq 0\)&lt;/p&gt;

&lt;h4 id=&quot;dual-sdp&quot;&gt;&lt;strong&gt;Dual SDP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max b^T y \quad \text{s.t.} \quad \sum y_i A_i + S = C, \quad S \succeq 0\)&lt;/p&gt;

&lt;h4 id=&quot;self-dual-cone-property&quot;&gt;&lt;strong&gt;Self-dual cone property&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\((\mathbb{S}_+^n)^* = \mathbb{S}_+^n\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt; Positive semidefinite cone is self-dual&lt;/p&gt;

&lt;h4 id=&quot;sdp-barrier-problems&quot;&gt;&lt;strong&gt;SDP Barrier Problems&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Primal Barrier:&lt;/strong&gt;
\(\min \text{tr}(CX) - \tau \log(\det(X)) \quad \text{s.t.} \quad \text{tr}(A_i X) = b_i\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual Barrier:&lt;/strong&gt;
\(\max b^T y + \tau \log(\det(S)) \quad \text{s.t.} \quad \sum y_i A_i + S = C\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Unlike LP, SDP doesn’t always have strong duality!&lt;/p&gt;

&lt;h3 id=&quot;️-practical-implications&quot;&gt;🛠️ &lt;strong&gt;Practical Implications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;algorithm-design-insights&quot;&gt;&lt;strong&gt;Algorithm design insights:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual methods:&lt;/strong&gt; Update both primal and dual variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier methods:&lt;/strong&gt; Perturbed KKT conditions guide algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-duality:&lt;/strong&gt; Exploit symmetric structure (SDP)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Central path:&lt;/strong&gt; Smooth path from interior to boundary&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;computational-advantages&quot;&gt;&lt;strong&gt;Computational advantages:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dual easier:&lt;/strong&gt; Sometimes dual has better structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bounds:&lt;/strong&gt; Dual provides lower bounds for primal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm starts:&lt;/strong&gt; Use dual information for initialization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stopping criteria:&lt;/strong&gt; Duality gap for convergence&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-connections-between-formulations&quot;&gt;🔄 &lt;strong&gt;Connections Between Formulations&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;lagrangian--fenchel&quot;&gt;&lt;strong&gt;Lagrangian ↔ Fenchel&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt; General constrained problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel:&lt;/strong&gt; Composite function problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Connection:&lt;/strong&gt; Both use conjugate functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Advantage:&lt;/strong&gt; Fenchel more natural for some problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;barrier--original&quot;&gt;&lt;strong&gt;Barrier ↔ Original&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Original KKT:&lt;/strong&gt; Exact optimality conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier KKT:&lt;/strong&gt; Perturbed optimality conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Connection:&lt;/strong&gt; \(\tau \to 0\) recovers original&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Advantage:&lt;/strong&gt; Barrier enables interior point methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;primal--dual&quot;&gt;&lt;strong&gt;Primal ↔ Dual&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal:&lt;/strong&gt; Direct problem formulation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual:&lt;/strong&gt; Alternative perspective via bounds&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Connection:&lt;/strong&gt; Strong duality bridges them&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Advantage:&lt;/strong&gt; Choose easier formulation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-key-theoretical-insights&quot;&gt;💡 &lt;strong&gt;Key Theoretical Insights&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-duality-universality&quot;&gt;&lt;strong&gt;1. Duality universality&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Every optimization problem&lt;/strong&gt; has dual perspective:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian dual:&lt;/strong&gt; For constrained problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel dual:&lt;/strong&gt; For composite problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic dual:&lt;/strong&gt; For conic programs&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier dual:&lt;/strong&gt; For interior point methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-geometric-interpretation&quot;&gt;&lt;strong&gt;2. Geometric interpretation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal:&lt;/strong&gt; Direct search in the feasible region&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual:&lt;/strong&gt; Supporting hyperplane approach&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Central path:&lt;/strong&gt; Smooth trajectory through interior&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; Perfect geometric correspondence&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-algorithmic-implications&quot;&gt;&lt;strong&gt;3. Algorithmic implications&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Simplex:&lt;/strong&gt; Vertex-hopping on boundary&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point:&lt;/strong&gt; Path-following through interior&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual:&lt;/strong&gt; Simultaneous primal-dual updates&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier methods:&lt;/strong&gt; Perturbed optimality conditions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-connections-to-other-chapters&quot;&gt;🎯 &lt;strong&gt;Connections to Other Chapters&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-previous-chapters&quot;&gt;&lt;strong&gt;From previous chapters:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 10:&lt;/strong&gt; LP duality foundation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 11:&lt;/strong&gt; General Lagrangian duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 12:&lt;/strong&gt; KKT conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 15:&lt;/strong&gt; Barrier methods and the central path&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;advanced-connections&quot;&gt;&lt;strong&gt;Advanced connections:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Conjugate functions:&lt;/strong&gt; Fenchel duality framework&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic programming:&lt;/strong&gt; Generalization to cones&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-duality:&lt;/strong&gt; Special structure exploitation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Perturbed KKT:&lt;/strong&gt; Bridge between exact and approximate&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;future-applications&quot;&gt;&lt;strong&gt;Future applications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual algorithms:&lt;/strong&gt; Simultaneous updates&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point methods:&lt;/strong&gt; Polynomial-time algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Semidefinite programming:&lt;/strong&gt; Matrix optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust optimization:&lt;/strong&gt; Worst-case analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-theoretical-significance&quot;&gt;🌟 &lt;strong&gt;Theoretical Significance&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;duality-as-universal-principle&quot;&gt;&lt;strong&gt;Duality as universal principle:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Every problem has dual:&lt;/strong&gt; Alternative formulation always exists&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric correspondence:&lt;/strong&gt; Primal-dual relationship&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic flexibility:&lt;/strong&gt; Choose best formulation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical elegance:&lt;/strong&gt; Unified framework&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;practical-significance&quot;&gt;&lt;strong&gt;Practical significance:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm design:&lt;/strong&gt; Primal-dual methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational efficiency:&lt;/strong&gt; Exploit structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity analysis:&lt;/strong&gt; Dual variables as shadow prices&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence analysis:&lt;/strong&gt; Duality gap monitoring&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;mathematical-beauty&quot;&gt;&lt;strong&gt;Mathematical beauty:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Symmetry:&lt;/strong&gt; The dual of the dual = the primal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-duality:&lt;/strong&gt; Some cones are self-dual&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conjugate functions:&lt;/strong&gt; Elegant mathematical framework&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Central path:&lt;/strong&gt; Smooth geometric trajectory&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;when-to-use-different-duality-formulations&quot;&gt;&lt;strong&gt;When to use different duality formulations:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt; General constrained problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel:&lt;/strong&gt; Composite functions, regularization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic:&lt;/strong&gt; Problems with cone constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier:&lt;/strong&gt; Interior point algorithms&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;algorithm-selection&quot;&gt;&lt;strong&gt;Algorithm selection:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal easier:&lt;/strong&gt; Direct primal methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual easier:&lt;/strong&gt; Dual methods or primal-dual&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Both complex:&lt;/strong&gt; Barrier methods with the central path&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Large-scale:&lt;/strong&gt; Interior point methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;implementation-considerations&quot;&gt;&lt;strong&gt;Implementation considerations:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; Check Slater’s condition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical stability:&lt;/strong&gt; Monitor condition numbers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence:&lt;/strong&gt; Use duality gap&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm starts:&lt;/strong&gt; Exploit dual information&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-advanced-topics&quot;&gt;🔬 &lt;strong&gt;Advanced Topics&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;robust-duality&quot;&gt;&lt;strong&gt;Robust duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Uncertain problems:&lt;/strong&gt; Worst-case duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Distributionally robust:&lt;/strong&gt; Ambiguous distributions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chance constraints:&lt;/strong&gt; Probabilistic duality&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;algorithmic-developments&quot;&gt;&lt;strong&gt;Algorithmic developments:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual interior point:&lt;/strong&gt; Mehrotra’s algorithm&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Homogeneous methods:&lt;/strong&gt; Handle infeasibility&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Higher-order methods:&lt;/strong&gt; Beyond Newton steps&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Distributed algorithms:&lt;/strong&gt; Parallel computation&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;modern-applications&quot;&gt;&lt;strong&gt;Modern applications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; SVM, regularization, neural networks&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Finance:&lt;/strong&gt; Portfolio optimization, risk management&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Engineering:&lt;/strong&gt; Control, signal processing, design&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Operations research:&lt;/strong&gt; Logistics, scheduling, planning&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-real-world-applications&quot;&gt;📈 &lt;strong&gt;Real-World Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;linear-and-conic-programming&quot;&gt;&lt;strong&gt;Linear and Conic Programming:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Portfolio optimization:&lt;/strong&gt; Mean-variance models&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Network flows:&lt;/strong&gt; Transportation, communication&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Production planning:&lt;/strong&gt; Resource allocation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Facility location:&lt;/strong&gt; Optimal placement&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;semidefinite-programming&quot;&gt;&lt;strong&gt;Semidefinite Programming:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Control theory:&lt;/strong&gt; LMI-based design&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Combinatorial optimization:&lt;/strong&gt; SDP relaxations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; Kernel methods, matrix completion&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Signal processing:&lt;/strong&gt; Beamforming, filter design&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;interior-point-methods&quot;&gt;&lt;strong&gt;Interior Point Methods:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Large-scale LP:&lt;/strong&gt; Commercial solvers (CPLEX, Gurobi)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quadratic programming:&lt;/strong&gt; Portfolio optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nonlinear programming:&lt;/strong&gt; General constrained problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex optimization:&lt;/strong&gt; Modern optimization software&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-future-directions&quot;&gt;🔮 &lt;strong&gt;Future Directions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;theoretical-developments&quot;&gt;&lt;strong&gt;Theoretical developments:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Non-convex duality:&lt;/strong&gt; Extensions beyond convexity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic duality:&lt;/strong&gt; Random optimization problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dynamic duality:&lt;/strong&gt; Time-varying problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quantum duality:&lt;/strong&gt; Quantum optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;algorithmic-innovations&quot;&gt;&lt;strong&gt;Algorithmic innovations:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive methods:&lt;/strong&gt; Problem-specific algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parallel algorithms:&lt;/strong&gt; Distributed computation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Online methods:&lt;/strong&gt; Streaming optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Approximation algorithms:&lt;/strong&gt; Near-optimal solutions&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;application-domains&quot;&gt;&lt;strong&gt;Application domains:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Deep learning:&lt;/strong&gt; Neural network optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Autonomous systems:&lt;/strong&gt; Real-time optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smart grids:&lt;/strong&gt; Energy optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bioinformatics:&lt;/strong&gt; Computational biology&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-key-insights&quot;&gt;💎 &lt;strong&gt;Key Insights&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;duality-transformations&quot;&gt;&lt;strong&gt;Duality transformations:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt; Constraint incorporation via multipliers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel:&lt;/strong&gt; Conjugate function perspective&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier:&lt;/strong&gt; Interior point approximation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic:&lt;/strong&gt; Cone-based generalization&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;algorithmic-implications&quot;&gt;&lt;strong&gt;Algorithmic implications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal methods:&lt;/strong&gt; Direct feasible region search&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual methods:&lt;/strong&gt; Bound-based approaches&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual:&lt;/strong&gt; Simultaneous optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point:&lt;/strong&gt; Smooth path following&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;theoretical-elegance&quot;&gt;&lt;strong&gt;Theoretical elegance:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Weak duality:&lt;/strong&gt; Universal lower bounds&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; Perfect correspondence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-duality:&lt;/strong&gt; Symmetric structures&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Central path:&lt;/strong&gt; Geometric optimization trajectory&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-legacy-of-chapter-16&quot;&gt;🌟 &lt;strong&gt;Legacy of Chapter 16:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Unified duality theory:&lt;/strong&gt; Multiple perspectives on same problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic flexibility:&lt;/strong&gt; Choose best formulation approach&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical completeness:&lt;/strong&gt; Comprehensive duality framework&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical impact:&lt;/strong&gt; Foundation for modern optimization software&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Educational value:&lt;/strong&gt; Deep understanding of optimization structure&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-takeaway-messages&quot;&gt;🎯 &lt;strong&gt;Takeaway messages:&lt;/strong&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Duality is universal:&lt;/strong&gt; Every problem has dual perspective&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multiple formulations:&lt;/strong&gt; Lagrangian, Fenchel, conic, barrier&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic choice:&lt;/strong&gt; Select best approach for problem structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric insight:&lt;/strong&gt; Primal-dual correspondence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical power:&lt;/strong&gt; Enables efficient algorithms and software&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-philosophical-impact&quot;&gt;💫 &lt;strong&gt;Philosophical impact:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Chapter 16 &lt;strong&gt;unifies duality theory&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;From specific to general:&lt;/strong&gt; LP duality → universal duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;From single to multiple:&lt;/strong&gt; One formulation → many perspectives&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;From theoretical to practical:&lt;/strong&gt; Mathematical elegance → algorithmic power&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;From simple to sophisticated:&lt;/strong&gt; Basic concepts → advanced applications&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;From academic to industrial:&lt;/strong&gt; Research ideas → commercial software&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-synthesis&quot;&gt;🔮 &lt;strong&gt;Synthesis:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Duality revisited shows that &lt;strong&gt;optimization has multiple faces&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal face:&lt;/strong&gt; Direct problem solving&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual face:&lt;/strong&gt; Bound-based approaches&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier face:&lt;/strong&gt; Interior approximation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conjugate face:&lt;/strong&gt; Function transformation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic face:&lt;/strong&gt; Geometric generalization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each face reveals different aspects of the same underlying mathematical structure, enabling &lt;strong&gt;flexible algorithm design&lt;/strong&gt; and &lt;strong&gt;deep theoretical understanding&lt;/strong&gt;. This multiplicity of perspectives is what makes modern optimization both &lt;strong&gt;theoretically elegant&lt;/strong&gt; and &lt;strong&gt;practically powerful&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;-final-insight&quot;&gt;💡 &lt;strong&gt;Final insight:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Chapter 16 demonstrates that &lt;strong&gt;duality is not just a mathematical curiosity&lt;/strong&gt; - it is a &lt;strong&gt;fundamental organizing principle&lt;/strong&gt; of optimization theory. From simple LP duality to sophisticated Fenchel duality, from exact KKT conditions to perturbed barrier conditions, from primal algorithms to primal-dual methods - &lt;strong&gt;duality provides a unified framework&lt;/strong&gt; that connects theory with practice, algorithms with applications, mathematics with engineering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Duality = Multiple perspectives on same optimization reality!&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Final message:&lt;/strong&gt; Duality Revisited does not just review previous concepts - it &lt;strong&gt;synthesizes multiple duality perspectives&lt;/strong&gt; into a unified framework, showing how Lagrangian, Fenchel, conic, and barrier dualities are all &lt;strong&gt;different faces of the same fundamental principle&lt;/strong&gt;!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of Duality Revisited, including Lagrangian duality theory, optimality conditions, Fenchel duality and advanced duality concepts.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🔄 Quiz: Duality Revisited &amp;amp; Advanced Theory&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1: Lagrangian definition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: The Lagrangian for a problem with constraints \(h_i(x) \leq 0\) and \(l_j(x) = 0\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(L(x,u,v) = f(x) + \sum u_i h_i(x) + \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(L(x,u,v) = f(x) - \sum u_i h_i(x) - \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(L(x,u,v) = f(x) + \sum u_i h_i(x) - \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(L(x,u,v) = f(x) - \sum u_i h_i(x) + \sum v_j l_j(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$L(x,u,v) = f(x) + \sum u_i h_i(x) + \sum v_j l_j(x)$$&lt;/strong&gt;&lt;br /&gt;
                Standard-form Lagrangian with dual variables $$u_i \geq 0$$ for the inequality constraints and free $$v_j$$ for the equality constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The primal problem can be rewritten as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(\min_x \max_{u \geq 0, v} L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\max_x \min_{u \geq 0, v} L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(\min_x \min_{u \geq 0, v} L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(\max_x \max_{u \geq 0, v} L(x,u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\min_x \max_{u \geq 0, v} L(x,u,v)$$&lt;/strong&gt;&lt;br /&gt;
                Primal problem: minimize over $$x$$, maximizing the Lagrangian over the dual variables to enforce the constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: The corresponding dual problem is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(\max_{u \geq 0, v} \min_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(\min_{u \geq 0, v} \max_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \(\max_{u \geq 0, v} \max_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \(\min_{u \geq 0, v} \min_x L(x,u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max_{u \geq 0, v} \min_x L(x,u,v)$$&lt;/strong&gt;&lt;br /&gt;
                Dual problem: maximize over dual variables, minimize Lagrangian over primal variables.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: The dual function \(g(u,v)\) is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) \(g(u,v) = \inf_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) \(g(u,v) = \sup_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) \(g(u,v) = L(x^*,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) \(g(u,v) = \nabla_x L(x,u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$g(u,v) = \inf_x L(x,u,v)$$&lt;/strong&gt;&lt;br /&gt;
                The dual function is the infimum of the Lagrangian over the primal variables, always concave in the dual variables.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: Strong duality holds when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(p^* = d^*\) (primal optimal = dual optimal)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(p^* &amp;gt; d^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(p^* &amp;lt; d^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Duality gap = ∞&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$p^* = d^*$$ (primal optimal = dual optimal)&lt;/strong&gt;&lt;br /&gt;
                Strong duality: there is no duality gap; the primal and dual optimal values are equal.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: The KKT stationarity condition is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(\nabla_x L(x^*,u^*,v^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(h_i(x^*) \leq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(u_i^* \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(u_i^* h_i(x^*) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\nabla_x L(x^*,u^*,v^*) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Stationarity: the gradient of the Lagrangian with respect to the primal variables is 0 at the optimal point.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: The complementary slackness condition is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) \(u_i^* h_i(x^*) = 0\) for all \(i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(u_i^* + h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) \(u_i^* h_i(x^*) \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(u_i^* = h_i(x^*)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$u_i^* h_i(x^*) = 0$$ for all $$i$$&lt;/strong&gt;&lt;br /&gt;
                Complementary slackness: the dual variable is 0 if the constraint is not active, or the constraint is active if the dual variable &amp;gt; 0.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The Fenchel conjugate of a function \(f\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(f^*(y) = \sup_x (y^T x - f(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(f^*(y) = \inf_x (y^T x - f(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(f^*(y) = \sup_x (y^T x + f(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(f^*(y) = f(y)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f^*(y) = \sup_x (y^T x - f(x))$$&lt;/strong&gt;&lt;br /&gt;
                Fenchel conjugate (Legendre transform): the supremum of a linear function minus the original function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: Fenchel duality for the problem \(\min_x f(x) + g(Ax)\) has the dual:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(\max_v -f^*(A^T v) - g^*(-v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(\min_v f^*(A^T v) + g^*(v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(\max_v f^*(A^T v) - g^*(v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(\min_v -f^*(A^T v) + g^*(-v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max_v -f^*(A^T v) - g^*(-v)$$&lt;/strong&gt;&lt;br /&gt;
                The Fenchel dual uses the conjugate functions of both $$f$$ and $$g$$ with appropriate transformations.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: The biconjugate \(f^{**}\) of a convex function \(f\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(f^{**} = f\) (if \(f\) is convex and lower semicontinuous)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(f^{**} = -f\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(f^{**} = f^2\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(f^{**} = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f^{**} = f$$ (if $$f$$ is convex and lower semicontinuous)&lt;/strong&gt;&lt;br /&gt;
                Fenchel-Moreau theorem: the biconjugate of a convex lower semicontinuous function is the function itself.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: \((x^*, u^*, v^*)\) is a saddle point of the Lagrangian if:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(L(x^*, u, v) \leq L(x^*, u^*, v^*) \leq L(x, u^*, v^*)\) for all feasible \((x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(L(x^*, u^*, v^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(\nabla L(x^*, u^*, v^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(L(x, u, v) = L(x^*, u^*, v^*)\) for all \((x,u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$L(x^*, u, v) \leq L(x^*, u^*, v^*) \leq L(x, u^*, v^*)$$ for all feasible $$(x,u,v)$$&lt;/strong&gt;&lt;br /&gt;
                Saddle point: a minimum in the primal variables, a maximum in the dual variables.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: For a convex problem, the Slater condition guarantees:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Strong duality holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Weak duality holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) No duality gap&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Both A and C&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) Both A and C&lt;/strong&gt;&lt;br /&gt;
                The Slater condition (strict feasibility) guarantees strong duality, i.e. no duality gap.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The dual of the LP \(\min c^T x\) s.t. \(Ax = b, x \geq 0\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(\max b^T y\) s.t. \(A^T y \leq c\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(\min b^T y\) s.t. \(A^T y \geq c\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(\max c^T y\) s.t. \(A^T y = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(\min A^T y\) s.t. \(b^T y \leq c\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max b^T y$$ s.t. $$A^T y \leq c$$&lt;/strong&gt;&lt;br /&gt;
                Standard LP dual: maximize with free dual variables $$y$$, constraint $$A^T y \leq c$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: The dual of the QP \(\min \frac{1}{2}x^T Q x + c^T x\) s.t. \(Ax \leq b\) with \(Q \succ 0\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) \(\max -\frac{1}{2}(A^T u + c)^T Q^{-1} (A^T u + c) - b^T u\) s.t. \(u \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) \(\min \frac{1}{2}u^T Q u - b^T u\) s.t. \(u \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) \(\max b^T u\) s.t. \(A^T u = c\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) \(\min c^T u + b^T u\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max -\frac{1}{2}(A^T u + c)^T Q^{-1} (A^T u + c) - b^T u$$ s.t. $$u \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                The QP dual is derived from the Lagrangian by eliminating the primal variables using the stationarity condition.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: The conjugate of \(f(x) = \frac{1}{2}x^T Q x\) with \(Q \succ 0\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(f^*(y) = \frac{1}{2}y^T Q^{-1} y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(f^*(y) = \frac{1}{2}y^T Q y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(f^*(y) = y^T Q^{-1} y\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) \(f^*(y) = -\frac{1}{2}y^T Q^{-1} y\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f^*(y) = \frac{1}{2}y^T Q^{-1} y$$&lt;/strong&gt;&lt;br /&gt;
                Conjugate of a quadratic form: replace $$Q$$ with $$Q^{-1}$$, keeping the coefficient $$\frac{1}{2}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16: Moreau envelope --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: The Moreau envelope of a function \(f\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(M_\lambda f(x) = \inf_z \left( f(z) + \frac{1}{2\lambda}\|x-z\|^2 \right)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(M_\lambda f(x) = f(x) + \lambda\|x\|^2\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(M_\lambda f(x) = \lambda f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(M_\lambda f(x) = f(\lambda x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$M_\lambda f(x) = \inf_z \left( f(z) + \frac{1}{2\lambda}\|x-z\|^2 \right)$$&lt;/strong&gt;&lt;br /&gt;
                Moreau envelope: a smooth approximation of the function obtained by adding a quadratic regularization.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: How is the proximal operator related to the Moreau envelope?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) \(\text{prox}_{\lambda f}(x) = \arg\min_z \left( f(z) + \frac{1}{2\lambda}\|x-z\|^2 \right)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) \(\text{prox}_{\lambda f}(x) = \nabla M_\lambda f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) \(\text{prox}_{\lambda f}(x) = M_\lambda f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) \(\text{prox}_{\lambda f}(x) = x - \lambda \nabla f(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\text{prox}_{\lambda f}(x) = \arg\min_z \left( f(z) + \frac{1}{2\lambda}\|x-z\|^2 \right)$$&lt;/strong&gt;&lt;br /&gt;
                The proximal operator is the argmin of the expression in the definition of the Moreau envelope.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: In SVM, the dual problem has the advantages:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) The kernel trick can be applied&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) The number of variables depends on the number of data points&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Quadratic programming with box constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) All of the above advantages&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above advantages&lt;/strong&gt;&lt;br /&gt;
                The SVM dual allows the kernel trick, has a simpler structure, and is efficient for high-dimensional features.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: The weak duality theorem states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) \(d^* \leq p^*\) always holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) \(d^* \geq p^*\) always holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) \(d^* = p^*\) always holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) There is no relation between \(d^*\) and \(p^*\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$d^* \leq p^*$$ always holds&lt;/strong&gt;&lt;br /&gt;
                Weak duality: the dual optimum is always a lower bound on the primal optimum, independent of convexity.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: Duality theory is applied in:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Sensitivity analysis&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Algorithm design (dual methods)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Theoretical analysis and bounds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above applications&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above applications&lt;/strong&gt;&lt;br /&gt;
                Duality theory has wide applications: sensitivity analysis, dual algorithms, theoretical bounds, economic interpretation.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: In duality revisited, strong duality holds when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Duality gap = 0&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Primal infeasible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Dual infeasible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Both primal and dual are unbounded&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Duality gap = 0&lt;/strong&gt;&lt;br /&gt;
                Strong duality: $$p^* = d^*$$ (the duality gap is 0).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: The Fenchel conjugate of $$f(x) = \frac{1}{2}x^2$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$f^*(y) = \frac{1}{2}y^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$f^*(y) = y^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$f^*(y) = \frac{1}{4}y^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$f^*(y) = 2y^2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f^*(y) = \frac{1}{2}y^2$$&lt;/strong&gt;&lt;br /&gt;
                The Fenchel conjugate of $$\frac{1}{2}x^2$$ is $$\frac{1}{2}y^2$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: The bidual theorem states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$f^{**} = f$$ if $$f$$ is convex and closed&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$f^{**} = -f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$f^{**} = f^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$f^{**}$$ does not exist&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f^{**} = f$$ if $$f$$ is convex and closed&lt;/strong&gt;&lt;br /&gt;
                For a closed convex function, the conjugate of the conjugate returns the original function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The Moreau decomposition states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$x = \text{prox}_f(x) + \text{prox}_{f^*}(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$x = \text{prox}_f(x) - \text{prox}_{f^*}(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$x = \text{prox}_f(x) \cdot \text{prox}_{f^*}(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) There is no formula&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$x = \text{prox}_f(x) + \text{prox}_{f^*}(x)$$&lt;/strong&gt;&lt;br /&gt;
                Moreau decomposition: every point can be decomposed as the sum of two proximal mappings.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: The Legendre transform is related to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Fenchel conjugate&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Eigenvalue&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Fenchel conjugate&lt;/strong&gt;&lt;br /&gt;
                The Legendre transform is a special case of the Fenchel conjugate for strictly convex functions.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;a&apos;, q3: &apos;a&apos;, q4: &apos;a&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;d&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;a&apos;, q17: &apos;a&apos;, q18: &apos;d&apos;, q19: &apos;a&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered duality theory and advanced concepts!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand Lagrangian and Fenchel duality well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review the KKT conditions and conjugate functions.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review strong duality and optimality conditions.&apos;;
    } else {
        message = &apos;📖 Study duality theory again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>16-03 Fenchel duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_03_fenchel_duality/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_03_fenchel_duality</id>
   <content type="html">&lt;p&gt;Lagrange duality is built for explicit inequality and equality constraints, \(h_i(x) \le 0\) and \(Ax = b\). Yet modern machine learning is packed with &lt;em&gt;unconstrained&lt;/em&gt; composite objectives of the form \(\min_x f(x) + g(Ax)\)—loss plus regularizer, data fidelity plus total variation, entropy plus transport cost. &lt;strong&gt;Fenchel duality&lt;/strong&gt; bypasses inequality multipliers altogether and pairs the primal directly with \(\max_v -f^*(A^T v) - g^*(-v)\) using Fenchel conjugates!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-fenchelrockafellar-duality&quot;&gt;Key ideas: Fenchel–Rockafellar Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Derivation via Consensus Splitting:&lt;/strong&gt; Rewriting \(\min_x f(x) + g(Ax)\) as \(\min_{Ax = z} f(x) + g(z)\) and dualizing \(Ax = z\) with multiplier \(v\) immediately yields \(g_{\text{dual}}(v) = -f^*(A^T v) - g^*(-v)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Weak Fenchel Duality Directly from Fenchel–Young:&lt;/strong&gt; Adding \(f(x) + f^*(A^T v) \ge (A^T v)^T x\) and \(g(Ax) + g^*(-v) \ge (-v)^T(Ax)\) cancels the inner products to zero, proving \(f(x) + g(Ax) \ge -f^*(A^T v) - g^*(-v)\) in two lines!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Strong Duality &amp;amp; Fenchel–Rockafellar Qualification:&lt;/strong&gt; Whenever \(f, g\) are closed convex and there exists \(x \in \operatorname{ri}(\operatorname{dom} f)\) with \(Ax \in \operatorname{ri}(\operatorname{dom} g)\), strong duality \(p^\star = d^\star\) holds.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Primal–Dual Optimality via Subdifferentials:&lt;/strong&gt; Strong duality holds at \((x^\star, v^\star)\) if and only if \(A^T v^\star \in \partial f(x^\star)\) and \(-v^\star \in \partial g(Ax^\star)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-ridge-regression-via-fenchel-duality&quot;&gt;Worked example: Solving Ridge Regression via Fenchel Duality&lt;/h3&gt;

&lt;p&gt;Consider 1D Ridge Regression \(\min_{x \in \mathbb{R}} \underbrace{\frac{1}{2}x^2}_{f(x)} + \underbrace{\frac{1}{2}(Ax - b)^2}_{g(Ax)}\) with \(A = 2\) and \(b = 5\). (Exact primal solution: \(x + 2(2x - 5) = 0 \implies 5x = 10 \implies x^\star = 2\), with \(p^\star = \frac{1}{2}(4) + \frac{1}{2}(-1)^2 = 2.5\).)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the two Fenchel conjugates:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(f(x) = \frac{1}{2}x^2\): \(f^*(s) = \frac{1}{2}s^2\).&lt;/li&gt;
      &lt;li&gt;For \(g(z) = \frac{1}{2}(z - 5)^2\): \(\max_z (w z - \frac{1}{2}(z-5)^2)\) is attained at \(z = 5 + w\), giving \(g^*(w) = \frac{1}{2}w^2 + 5w\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assemble the Fenchel dual \(\max_v -f^*(A^T v) - g^*(-v)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(-f^*(2v) = -\frac{1}{2}(2v)^2 = -2v^2\).&lt;/li&gt;
      &lt;li&gt;\(-g^*(-v) = -\left(\frac{1}{2}(-v)^2 + 5(-v)\right) = -\frac{1}{2}v^2 + 5v\).&lt;/li&gt;
      &lt;li&gt;Combined dual objective: \(d(v) = -\frac{5}{2}v^2 + 5v\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the Fenchel dual:&lt;/strong&gt; Set \(d&apos;(v) = -5v + 5 = 0 \implies v^\star = 1\), with dual value \(d^\star = -\frac{5}{2}(1) + 5(1) = 2.5 = p^\star\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify Fenchel subdifferential optimality:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(A^T v^\star = 2(1) = 2 = f&apos;(x^\star)\) (recovers \(x^\star = 2\)!).&lt;/li&gt;
      &lt;li&gt;\(-v^\star = -1 = g&apos;(Ax^\star) = 2(2) - 5 = -1\)! Both inclusions hold with equality.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In &lt;a href=&quot;/contents/en/chapter13/13_04_Conjugate_function/&quot;&gt;13-04 Conjugate function&lt;/a&gt;, we learned how to derive dual problems using conjugate functions. Fenchel duality refers to dual problems derived from conjugate functions that have the following form:&lt;/p&gt;

\[\max_{v} -f^*(A^Tv) - g^*(-v)\]

&lt;p&gt;Let’s explore where this form of problem is derived from.&lt;/p&gt;

&lt;h3 id=&quot;primal-problem&quot;&gt;Primal problem&lt;/h3&gt;

&lt;blockquote&gt;
\[\min_{x} \quad f(x) + g(Ax)\]
&lt;/blockquote&gt;

&lt;p&gt;The given problem can be redefined with an added equality constraint.&lt;/p&gt;

&lt;h3 id=&quot;primal-problem-rewritten&quot;&gt;Primal problem rewritten&lt;/h3&gt;
&lt;blockquote&gt;

\[\begin{align}
 &amp;amp;\min_{x,z} \        &amp;amp;&amp;amp; f(x) + g(z)\\
 &amp;amp;\text{subject to} \ &amp;amp;&amp;amp; Ax = z.
 \end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Let’s derive the dual problem of the redefined primal problem using conjugate functions. &lt;br /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Recall:&lt;/strong&gt; \(f^*(s) \doteq  \max_{x} \big( s^Tx - f(x) \big) = \min_{x} \big( f(x) - s^Tx \big)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br /&gt;
\(\begin{align}
&amp;amp;\max_{v} \min_{x, z} \quad L(x,z,v)\\\\
= &amp;amp;\max_{v} \min_{x, z} \quad f(x) + g(z) + v^T (z - Ax) \\\\
= &amp;amp;\max_{v} \min_{x, z} \quad v^Tz + g(z) - (A^Tv)^Tx + f(x)\\\\
= &amp;amp;\max_{v} \quad  -f^*(A^Tv) - g^*(-v)\\\\
\end{align}\)&lt;/p&gt;

&lt;h3 id=&quot;fenchel-duality&quot;&gt;Fenchel duality&lt;/h3&gt;
&lt;blockquote&gt;
\[\max_{v} -f^*(A^Tv) - g^*(-v)\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nice Property:&lt;/strong&gt; If \(f, g\) are convex and closed, the dual of the dual becomes the primal again. (Symmetric)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;example-conic-programming&quot;&gt;Example: conic programming&lt;/h2&gt;

&lt;h3 id=&quot;primal-problem-of-cp-in-standard-form&quot;&gt;Primal problem of CP in standard form&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
    \mathop{\text{minimize}}_x &amp;amp;\quad c^Tx \\\\
    \text{subject to} &amp;amp;\quad Ax = b \\\\
    &amp;amp;\quad x \in K
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The above problem can be redefined using two functions \(f(x) = c^Tx + I_K(x)\) and \(g(z) = I_{\{b\}}(z)\).&lt;br /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Note:&lt;/strong&gt; \(\begin{equation}
  f(x) + g(Ax) = 
  \begin{cases}
    0, &amp;amp; \text{if}\ Ax=b, x \in K \\\\
    \infty, &amp;amp; \text{otherwise}
  \end{cases}
\end{equation}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;primal-problem-of-cp-rewritten&quot;&gt;Primal problem of CP rewritten&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, z}       \ &amp;amp;&amp;amp;  f(x) + g(z)\\\
&amp;amp;\text{subject to} \ &amp;amp;&amp;amp; z  =Ax \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;deriving-dual-problem-of-cp&quot;&gt;Deriving dual problem of CP&lt;/h3&gt;

&lt;p&gt;Let’s derive the dual problem from the redefined CP primal problem. First, expanding functions \(f\) and \(g\) gives us the following:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \min_{x, z} &amp;amp;&amp;amp; \; c^Tx + I_K(x) + I_{\{b\}}(z)  \\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp; \;  z   =Ax \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Let’s expand the problem using conjugate functions from the definition of the dual problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \max_{y} \; \min_{x, z} \;  L(x, z, y) \\\
= \; &amp;amp; \max_{y} \; \min_{x, z} \;  c^Tx + I_K(x) + I_{\{b\}}(z) + y^T(z-Ax) \\\
= \; &amp;amp; \max_{y}  \;\min_{x, z} \; (c - A^Ty)^Tx  + I_K(x) \;+ \;  y^Tz + I_{\{b\}}(z) \\\
= \; &amp;amp; \max_{y} \;  \min_{x, z} \; -( (A^Ty - c)^Tx  - I_K(x)) \;  - \; ( - y^Tz - I_{\{b\}}(z) ) \\\
= \; &amp;amp; \max_{y} \; - I_K^*(A^Ty - c)  -  I_{\{b\}}^*(-y)  \\\
= \; &amp;amp; \max_{y} \; - I_{-K^*}(A^Ty - c)  - I_{\{b\}}^*(-y)  \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;\(I_{-K^*}(A^Ty - c)\) can be expressed as a constraint.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
A^Ty - c &amp;amp; = -s, \; -s \in -K^* \\\
\Leftrightarrow A^Ty + s &amp;amp; = c, \; s \in K^* \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Since \(I_{\{b\}}^*(-y) = \max_{b} -b^Ty - I_{\{b\}}(b)\), the problem can be organized as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{y, s} \ &amp;amp;&amp;amp; -(-b^Ty - I_{\{b\}}(b)) \\\
&amp;amp;\text{subject to} \ &amp;amp;&amp;amp; y^TA + s = c \\\
&amp;amp;  \; s \in K^* \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Since \(I_{\{b\}}(b) = 0\), it can be removed from the problem.&lt;/p&gt;

&lt;h3 id=&quot;dual-problem-of-cp&quot;&gt;Dual problem of CP&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{y, s} \ &amp;amp;&amp;amp;  \;  b^Ty  \\\
&amp;amp;\text{subject to} \ &amp;amp;&amp;amp; y^TA + s = c \\\
&amp;amp;  \; s \in K^* \\
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;If either the primal problem or dual problem is strictly feasible, then strong duality is satisfied.&lt;/li&gt;
  &lt;li&gt;If both the primal problem and dual problem are strictly feasible, then strong duality is satisfied and primal &amp;amp; dual optima exist.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;example-semidefinite-programming&quot;&gt;Example: semidefinite programming&lt;/h2&gt;
&lt;p&gt;Let’s examine the forms of primal &amp;amp; dual problems for SDP and the primal &amp;amp; dual problems for SDP’s barrier problem.&lt;/p&gt;

&lt;h3 id=&quot;primal-problem-of-sdp&quot;&gt;Primal problem of SDP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\mathop{\text{minimize}}_{X} &amp;amp;&amp;amp;{tr(CX)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{tr(A_iX) = b_i, \phantom{5} i=1,\dotsc,p} \\\\
   &amp;amp; &amp;amp;&amp;amp;{X \succeq 0},\\\\
\end{align}\]

\[\text{where } C, A_1, \dotsc, A_p \in \mathbb{S}^n.\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Recall:&lt;/strong&gt; \(tr(CX) = \sum_{i,j=1}^n C_{ij}X_{ij}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Note:&lt;/strong&gt; Unlike LP, SDP does not always satisfy strong duality.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;dual-problem-of-sdp&quot;&gt;Dual problem of SDP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\mathop{\text{minimize}}_{y} &amp;amp;&amp;amp;{b^Ty} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\sum_{i=1}^m y_i A_i + S = C} \\\\
   &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Note:&lt;/strong&gt; The positive semidefinite cone is a self-dual cone. (\((\mathbb{S}_{+}^n)^* = \mathbb{S}_{+}^n\))&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;primal-problem-of-barrier-problem-for-sdp&quot;&gt;Primal problem of Barrier problem for SDP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\mathop{\text{minimize}}_{X} &amp;amp;&amp;amp;{tr(CX) - \tau \log \big( det(X) \big)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{tr(A_iX) = b_i, \phantom{5} i=1,\dotsc,p} \\\\
\end{align}\]

\[\text{where } C, A_1, \dotsc, A_p \in \mathbb{S}^n.\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;dual-problem-of-barrier-problem-for-sdp&quot;&gt;Dual problem of Barrier problem for SDP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\mathop{\text{minimize}}_{y, S} &amp;amp;&amp;amp;{b^Ty +  \tau \log \big( det(S) \big)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\sum_{i=1}^m y_i A_i + S = C}.
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>16-02 Optimality conditions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_02_optimality_conditions/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_02_optimality_conditions</id>
   <content type="html">&lt;p&gt;When you check whether a candidate point \((x, u, v)\) is optimal for a convex program, the KKT conditions give you a four-part checklist: primal feasibility, dual feasibility, complementary slackness, and stationarity. When you compare that checklist side-by-side against the optimality conditions of the &lt;strong&gt;barrier problem&lt;/strong&gt;, you discover something remarkable: three of the four equations are &lt;em&gt;identical&lt;/em&gt;, and the fourth merely shifts \(u_i h_i(x) = 0\) to \(u_i h_i(x) = -1/t\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-exact-kkt-vs-central-path-optimality&quot;&gt;Key ideas: Exact KKT vs. Central-Path Optimality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Sufficiency of KKT for Convex Problems:&lt;/strong&gt; When \(f, h_1, \dots, h_m\) are convex and differentiable and \(l_1, \dots, l_r\) are affine, any \((x^\star, u^\star, v^\star)\) satisfying KKT is guaranteed globally primal and dual optimal with zero duality gap.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Necessity via Slater’s Condition:&lt;/strong&gt; Under strict feasibility (Slater’s condition), strong duality holds and KKT conditions become both &lt;em&gt;necessary and sufficient&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Barrier KKT as a Homotopy Deformation:&lt;/strong&gt; Introducing \(u_i(t) = -\frac{1}{t h_i(x^*(t))} &amp;gt; 0\) rewrites barrier optimality as exact stationarity, exact primal/dual feasibility, and perturbed complementarity \(u_i h_i = -1/t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Measuring Distance to KKT (Residuals):&lt;/strong&gt; Primal-dual solvers track three residuals—primal residual \(r_{\text{pri}} = Ax - b\), dual residual \(r_{\text{dual}} = \nabla f + \sum u_i \nabla h_i + A^T v\), and complementarity residual \(r_{\text{cent}} = -u \odot h - \frac{1}{t}\mathbf{1}\)—driving all three to zero simultaneously.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-comparing-exact-kkt-and-barrier-kkt-residuals&quot;&gt;Worked example: Comparing Exact KKT and Barrier KKT Residuals&lt;/h3&gt;

&lt;p&gt;Consider \(\min_{x \in \mathbb{R}} (x - 4)^2\) subject to \(h_1(x) = x - 2 \le 0\) (i.e., \(x \le 2\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the exact KKT conditions:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Stationarity: \(2(x^\star - 4) + u_1^\star (1) = 0 \implies u_1^\star = 2(4 - x^\star)\).&lt;/li&gt;
      &lt;li&gt;Try inactive (\(u_1^\star = 0\)): gives \(x = 4\), violating \(x \le 2\).&lt;/li&gt;
      &lt;li&gt;Try active (\(x^\star = 2\)): gives \(u_1^\star = 2(4 - 2) = 4 \ge 0\), and \(u_1^\star h_1(x^\star) = 4(0) = 0\). &lt;strong&gt;Exact KKT optimum:&lt;/strong&gt; \((x^\star, u_1^\star) = (2, 4)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Now test a central-path point at \(t = 10\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Perturbed KKT equations: \(2(x - 4) + u_1 = 0\) and \(u_1(x - 2) = -\frac{1}{10} = -0.1\) with \(x &amp;lt; 2, u_1 &amp;gt; 0\).&lt;/li&gt;
      &lt;li&gt;Substitute \(u_1 = 8 - 2x\): \((8 - 2x)(x - 2) = -0.1 \implies 2x^2 - 12x + 15.9 = 0\).&lt;/li&gt;
      &lt;li&gt;Root with \(x &amp;lt; 2\): \(x^*(10) = \frac{12 - \sqrt{144 - 127.2}}{4} = \frac{12 - \sqrt{16.8}}{4} \approx 1.9753\).&lt;/li&gt;
      &lt;li&gt;Dual variable: \(u_1(10) = 8 - 2(1.9753) = 4.0494\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check all residuals:&lt;/strong&gt; \(r_{\text{dual}} = 2(1.9753 - 4) + 4.0494 = 0\), \(r_{\text{cent}} = -u_1 h_1 - 0.1 = -(4.0494)(-0.0247) - 0.1 = 0\), and \((1.9753, 4.0494)\) is already within \(0.05\) of the exact KKT pair \((2, 4)\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In this section, we will examine the KKT optimality conditions for primal problems and barrier problems respectively, and then compare their differences.
&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;kkt-optimality-conditions&quot;&gt;KKT optimality conditions&lt;/h2&gt;

&lt;p&gt;Let’s review the KKT conditions that we covered in Chapter 12. KKT conditions are used as conditions for determining optimality.&lt;/p&gt;

&lt;h3 id=&quot;primal-problem&quot;&gt;Primal problem&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad f(x) \\\\
   \text{subject to} &amp;amp;\quad h_i(x) \leq 0, i = 1, \ldots, m \\\\
   &amp;amp;\quad l_j(x) = 0, j = 1, \ldots, r
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;When the given primal problem is convex, KKT conditions become sufficient conditions for primal &amp;amp; dual optimality. That is, when \(f, h_1, \dots, h_m\) are convex and \(l_1, \dots, l_r\) are affine, if \(x^\star, u^\star, v^\star\) satisfy the following KKT conditions, then \(x^\star\) and \((u^\star, v^\star)\) are primal &amp;amp; dual optimal with zero duality gap. (We assume that \(f, h_1, \dots, h_m, l_1, \dots, l_r\) are differentiable.) &lt;br /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;reference: &lt;a href=&quot;/contents/en/chapter12/12_00_KKT_conditions/&quot;&gt;12-01 KKT conditions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;kkt-conditions-for-the-given-primal-problem&quot;&gt;KKT conditions for the given primal problem&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
l_i &amp;amp;= 0, \quad i=1, \dots, r\\\\
u_i^\star, -h_i(x^\star) &amp;amp;\ge 0, \quad i=1, \dots, m\\\\
u_i^\star h_i(x^\star) &amp;amp;= 0, \quad i=1, \dots, m\\\\
\nabla f(x^\star) + \sum_{i=1}^m \nabla h_i(x^\star) u^\star_i + \sum_{i=1}^r \nabla l_i(x^\star) v_i^\star &amp;amp;= 0.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;central-path-equations&quot;&gt;Central path equations&lt;/h2&gt;

&lt;p&gt;Let’s also examine the conditions for determining the optimality of barrier problems.&lt;/p&gt;

&lt;h3 id=&quot;barrier-problem&quot;&gt;Barrier problem&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
    \mathop{\text{minimize}}_x &amp;amp;\quad f(x) + \tau \phi(x) \\\\
    &amp;amp;\quad l_j(x) = 0, j = 1, \ldots, r  \\\\
\end{align}\]

\[\text{where } \phi(x) = - \sum_{i=1}^m \log \big( -h_i(x) \big).\]
&lt;/blockquote&gt;

&lt;p&gt;By organizing the KKT conditions for barrier problems, we can derive the following optimality conditions. Note the differences in the inequality constraint and complementary slackness conditions compared to the KKT optimality conditions for primal problems examined earlier. (Reference: &lt;a href=&quot;/contents/en/chapter15/chapter16/15_03_01_perturbed_kkt_conditions/&quot;&gt;15-03-01 Perturbed KKT conditions&lt;/a&gt;)&lt;/p&gt;

&lt;h3 id=&quot;optimality-conditions-for-barrier-problem-and-its-dual&quot;&gt;Optimality conditions for barrier problem (and its dual)&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
l_i &amp;amp;= 0, \quad i=1, \dots, r\\\\
u_i(t), -h_i(x^\star(t)) &amp;amp;\gt 0, \quad i=1, \dots, m\\\\
u_i(t) h_i(x^\star(t)) &amp;amp;= -\tau, \quad i=1, \dots, m\\\\
\nabla f(x^\star(t)) + \sum_{i=1}^m \nabla h_i(x^\star(t)) u_i(t) + \sum_{i=1}^r \nabla l_i(x^\star(t)) \hat{v}_i^\star &amp;amp;= 0,\\\\
\end{align} \\\\\]

\[\text{where } \tau = \frac{1}{t}, u_i(t) = - \frac{1}{t h_i(x^\star(t))}, \quad \hat{v} = \frac{1}{t}v.\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;special-case-linear-programming&quot;&gt;Special case: linear programming&lt;/h2&gt;

&lt;h3 id=&quot;recall-primal-problem-of-lp-in-standard-form&quot;&gt;Recall: Primal problem of LP in standard form&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad c^Tx \\\\
   \text{subject to} &amp;amp;\quad Ax = b \\\\
   &amp;amp;\quad x \ge 0
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;recall-dual-problem-of-lp&quot;&gt;Recall: Dual problem of LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{maximize}}_{s,y} &amp;amp;\quad b^Ty \\\\
   \text{subject to} &amp;amp;\quad A^Ty +  s = c \\\\
   &amp;amp;\quad s \ge 0
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Linear programming has the nice property of always satisfying strong duality due to the refined Slater’s condition, since the inequality constraints are affine. The optimality conditions for LP are as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
A^T y^\star + s^\star &amp;amp;= c\\\\
Ax^\star &amp;amp;= b\\\\
X S \mathbb{1} &amp;amp;= 0\\\\
x^\star, s^\star &amp;amp;\ge 0,\\\\
\end{align}\]

\[text{where }X = Diag(x^\star), S = Diag(s^\star)\]
&lt;/blockquote&gt;

&lt;p&gt;Note that \(X S \mathbb{1} = 0\) is equivalent to \(Xs^\star=(x_1^\star s_1^\star, \dots, x_n^\star s_n^\star)=0\). We use \(X, S\) notation for convenience in algorithms that will be introduced later.&lt;/p&gt;

&lt;h3 id=&quot;algorithms-for-linear-programming&quot;&gt;Algorithms for linear programming&lt;/h3&gt;

&lt;p&gt;We introduce two representative methods for solving LP using optimality conditions.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Simplex: A method that maintains conditions 1, 2, and 3 while gradually satisfying condition 4.&lt;/li&gt;
  &lt;li&gt;Interior-point methods: A method that maintains condition 4 while gradually satisfying conditions 1, 2, and 3. This will be covered in the next chapter.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;central-path-for-linear-programming&quot;&gt;Central path for linear programming&lt;/h2&gt;

&lt;h3 id=&quot;recall-barrier-problem-for-lp&quot;&gt;Recall: Barrier problem for LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
    \mathop{\text{minimize}}_x &amp;amp;\quad c^Tx - \tau \sum_{i=1}^n \log(x_i)\\\\
    \text{subject to} &amp;amp;\quad Ax = b, \\\\
    \text{where}  &amp;amp;\quad \tau &amp;gt; 0
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;recall-dual-problem-of-barrier-problem-for-lp&quot;&gt;Recall: Dual problem of Barrier problem for LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{maximize}}_{s,y} &amp;amp;\quad b^Ty + \tau \sum_{i=1}^n log(s_i)\\\\
   \text{subject to} &amp;amp;\quad A^Ty +  s = c \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The optimality conditions for the barrier problem of LP are as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
A^T y^\star + s^\star &amp;amp;= c\\\\
Ax^\star &amp;amp;= b\\\\
X S \mathbb{1} &amp;amp;= \tau \mathbb{1}\\\\
x^\star, s^\star &amp;amp;\gt 0,\\\\
\text{where} &amp;amp;\quad X = Diag(x^\star), S = Diag(s^\star)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Conditions 3 and 4 show differences from the KKT conditions of the primal LP.&lt;/p&gt;

&lt;h3 id=&quot;kkt-normals-and-lagrange-multipliers-video&quot;&gt;KKT: normals and Lagrange multipliers (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/kkt-normals_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;At the optimum, \(-\nabla f(x^*)\) is a nonnegative combination of the normals of the active constraints, and inactive constraints get multiplier \(0\).&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-kkt-multipliers&quot;&gt;Try it yourself: KKT multipliers&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;kkt&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>16-01 Lagrangian duality revisited</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_01_lagrangian_duality_revisited/"/>
   <updated>2021-03-31T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter16/16_01_lagrangian_duality_revisited</id>
   <content type="html">&lt;p&gt;Here is one of the most astonishing symmetries in convex optimization: take a standard-form linear program, add a logarithmic barrier to its primal inequalities, and compute the Lagrange dual of that barrier problem. You don’t get some messy new formula—you get the &lt;em&gt;exact&lt;/em&gt; logarithmic barrier problem of the &lt;strong&gt;dual&lt;/strong&gt; linear program! Seeing how min–max Lagrangians produce LP duals, QP duals, and this primal-dual barrier mirror lays the exact foundation for Chapter 17.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-minmax-lagrangians-and-conicbarrier-duals&quot;&gt;Key ideas: Min–Max Lagrangians and Conic/Barrier Duals&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch16_kkt_duality_bridge.svg&quot; alt=&quot;Cầu nối Đối ngẫu Lagrange và Điều kiện KKT&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Constraints as Implicit \(\max_{u \ge 0, v}\) Penalties:&lt;/strong&gt; Rewriting the primal as \(\min_x \max_{u \ge 0, v} L(x, u, v)\) uses \(\max_{u \ge 0} u_i h_i(x)\) as an exact indicator function for \(h_i(x) \le 0\), and swapping \(\min\) and \(\max\) yields the dual.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Standard-Form LP &amp;amp; QP Duals:&lt;/strong&gt; Applying \(\min_x L(x, u, v)\) to \(\min c^T x\) s.t. \(Ax = b, x \ge 0\) yields \(\max b^T y\) s.t. \(A^T y \le c\); for strictly convex QPs \(\frac{1}{2}x^T Q x + c^T x\), minimizing the quadratic in \(x\) replaces \(Q\) with \(-Q^{-1}\) in the dual.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Dual of the Primal Barrier = Barrier of the Dual:&lt;/strong&gt; For the LP barrier \(\min t c^T x - \sum \log x_i\) s.t. \(Ax = b\), minimizing \(L(x, y)\) over \(x &amp;gt; 0\) yields \(x_i = 1/(t(c - A^T y)_i)\) and dual objective \(t b^T y + \sum \log(c - A^T y)_i + \text{const}\)—the exact dual log barrier!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Automatic Dual Slack Recovery:&lt;/strong&gt; Along the central path, \(s(t) = c - A^T y(t) &amp;gt; 0\) satisfies \(x_i(t) s_i(t) = 1/t\), linking primal variables and dual slacks symmetrically.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-deriving-the-dual-of-a-1d-lp-barrier-problem&quot;&gt;Worked example: Deriving the Dual of a 1D LP Barrier Problem&lt;/h3&gt;

&lt;p&gt;Consider the 1D LP \(\min_{x &amp;gt; 0} 3x\) subject to \(x \ge 0\) with a single equality constraint \(2x = 4\)? Better yet, to keep a free primal degree of freedom, consider \(\min_{x_1, x_2 &amp;gt; 0} x_1 + 2x_2\) subject to \(x_1 + x_2 = 1\) (so \(c = (1, 2)^T\), \(A = [1, 1]\), \(b = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the primal barrier problem (\(t = 1\)):&lt;/strong&gt;
\(\min_{x_1, x_2 &amp;gt; 0} \; x_1 + 2x_2 - \log x_1 - \log x_2 \quad \text{s.t.} \quad x_1 + x_2 = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form the Lagrangian with dual multiplier \(y \in \mathbb{R}\):&lt;/strong&gt;
\(L(x, y) = x_1 + 2x_2 - \log x_1 - \log x_2 + y(1 - x_1 - x_2) = y + (1 - y)x_1 - \log x_1 + (2 - y)x_2 - \log x_2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize over \(x_1, x_2 &amp;gt; 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Finite only when \(s_1 = 1 - y &amp;gt; 0\) and \(s_2 = 2 - y &amp;gt; 0\) (i.e., \(A^T y &amp;lt; c\) — strict dual feasibility!).&lt;/li&gt;
      &lt;li&gt;Stationarity gives \(x_1 = \frac{1}{1 - y}\) and \(x_2 = \frac{1}{2 - y}\).&lt;/li&gt;
      &lt;li&gt;Substitute back:
\(g(y) = y + 1 + \log(1 - y) + 1 + \log(2 - y) = y + \log(1 - y) + \log(2 - y) + 2.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recognize the dual:&lt;/strong&gt; Maximizing \(g(y)\) over \(y &amp;lt; 1\) is &lt;em&gt;literally&lt;/em&gt; the log-barrier problem for the dual LP \(\max_y y\) s.t. \(y \le 1, y \le 2\) (up to the constant \(+2\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In this section, we will show that primal and dual problems can be defined using the Lagrangian, and use this definition to derive dual problems for standard form linear programming and quadratic programming. Furthermore, we will derive the dual problem for linear programming with barrier problems applied, showing that its form is the same as the barrier problem for the dual problem of linear programming.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
First, let’s define the primal problem and Lagrangian as follows.&lt;/p&gt;

&lt;h3 id=&quot;primal-problem&quot;&gt;Primal problem&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad f(x) \\\\
   \text{subject to} &amp;amp;\quad h_i(x) \leq 0, i = 1, \ldots, m \\\\
   &amp;amp;\quad l_j(x) = 0, j = 1, \ldots, r
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;lagrangian&quot;&gt;Lagrangian&lt;/h3&gt;
&lt;blockquote&gt;
\[L(x,u,v) = f(x) + \sum_{i=1}^m u_i h_i (x) + \sum_{j=1}^r v_j l_j (x)\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;br /&gt;
At this point, the primal problem and dual problem can be redefined as problems involving the Lagrangian.&lt;/p&gt;

&lt;h3 id=&quot;rewritten-primal-problem&quot;&gt;Rewritten primal problem&lt;/h3&gt;
&lt;blockquote&gt;
\[\min_x \mathop{\max_{u,v}}_{u \geq 0} L(x,u,v)\]
&lt;/blockquote&gt;

&lt;p&gt;The redefined primal problem does not explicitly state constraints, but it has the effect of acting like an indicator function for any infeasible \(x\) that violates the constraints.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;If \(h_i(\hat{x}) \gt 0\) for some \(i \in [1, m]\), then \(\hat{x}\) is an infeasible point. In this case, \(u_i h_i(\hat{x})\) diverges to \(\infty\) due to \(\max_{u,v}\), so it acts as an indicator function for any \(\hat{x}\) that violates the inequality constraint.&lt;/li&gt;
  &lt;li&gt;If \(l_i(\hat{x}) \neq 0\) for some \(i \in [1, r]\), then \(\hat{x}\) is an infeasible point. In this case, \(v_i l_i(\hat{x})\) diverges to \(\infty\) due to \(\max_{u,v}\), so it acts as an indicator function for any \(\hat{x}\) that violates the equality constraint.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;rewritten-dual-problem&quot;&gt;Rewritten dual problem&lt;/h3&gt;
&lt;blockquote&gt;
\[\mathop{\max_{u,v}}_{u \geq 0} \min_x L(x,u,v)\]
&lt;/blockquote&gt;

&lt;p&gt;In the dual problem, relaxation of the domain is necessary, so it should not act as an indicator function for the constraints of the primal problem. Since taking \(\min_x\) for fixed \(u, v\) cannot enforce the constraints of the primal problem, the redefined dual problem also has the effect of relaxing the domain. (Reference: &lt;a href=&quot;/contents/en/chapter11/11_02_Lagrange_dual_function/&quot;&gt;11-02 Lagrange dual function&lt;/a&gt;)&lt;/p&gt;

&lt;h2 id=&quot;weak-and-strong-duality&quot;&gt;Weak and strong duality&lt;/h2&gt;
&lt;p&gt;Let’s revisit weak duality and strong duality.&lt;/p&gt;

&lt;h3 id=&quot;theorem-weak-duality&quot;&gt;Theorem: weak duality&lt;/h3&gt;
&lt;p&gt;When \(p\) and \(d\) are the optimal values for the primal problem and dual problem respectively, the following is always satisfied:&lt;/p&gt;

\[p \ge d\]

&lt;h3 id=&quot;theorem-strong-duality-refined-slaters-condition&quot;&gt;Theorem: strong duality (refined Slater’s condition)&lt;/h3&gt;
&lt;p&gt;For the domain set \(D\), assume that \(f, h_1, \dots, h_p\) are convex and \(h_{p+1}, \dots, h_m, l_1, \dots, l_r\) are affine. If there exists \(\hat{x} \in \text{relint}(D)\) that satisfies the following:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
h_i(\hat{x}) \ &amp;amp; \lt 0, \ &amp;amp;&amp;amp; i=1, \dots, p \\
h_i(\hat{x}) \ &amp;amp; \le 0, \ &amp;amp;&amp;amp; i=p+1, \dots, m \\
l_j(\hat{x}) \ &amp;amp; = 0, \ &amp;amp;&amp;amp; j = 1, \dots, r
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;then \(p = d\) is guaranteed for the optimal values \(p, d\) of the primal problem and dual problem.&lt;/p&gt;

&lt;h2 id=&quot;example-linear-programming&quot;&gt;Example: linear programming&lt;/h2&gt;
&lt;p&gt;Let’s derive the dual problem of linear programming using the dual problem defined earlier.&lt;/p&gt;

&lt;h3 id=&quot;primal-problem-of-lp-in-standard-form&quot;&gt;Primal problem of LP in standard form&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad c^Tx \\\\
   \text{subject to} &amp;amp;\quad Ax = b \\\\
   &amp;amp;\quad x \ge 0
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;According to the previous definition, the dual problem of the above problem is as follows:&lt;/p&gt;

\[\mathop{\max_{s,y}}_{s\ge0} \min_{x} \: L(x,s,y) = \mathop{\max_{s,y}}_{s\ge0} \min_{x} \: c^Tx - s^Tx + (b-Ax)^T y\]

&lt;p&gt;We substitute the relationship \(c=A^Ty +s\) obtained by solving \(\nabla_x L = 0\) into the dual problem.&lt;/p&gt;

\[\mathop{\max_{s,y}}_{s\ge0} \: (A^Ty + s)^Tx - s^Tx + (b-Ax)^Ty \quad \text{ s.t. } c=A^Ty +s\]

&lt;p&gt;This can be organized as follows:&lt;/p&gt;

&lt;h3 id=&quot;dual-problem-of-lp&quot;&gt;Dual problem of LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{maximize}}_{s,y} &amp;amp;\quad b^Ty \\\\
   \text{subject to} &amp;amp;\quad A^Ty +  s = 0 \\\\
   &amp;amp;\quad s \ge 0
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;example-convex-quadratic-programming&quot;&gt;Example: convex quadratic programming&lt;/h2&gt;
&lt;p&gt;Now let’s derive the dual problem of quadratic programming using the dual problem defined earlier.&lt;/p&gt;

&lt;h3 id=&quot;primal-problem-of-qp-in-standard-form&quot;&gt;Primal problem of QP in standard form&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad \frac{1}{2} x^T Q x + c^Tx \\
   \text{subject to} &amp;amp;\quad Ax = b \\
   &amp;amp;\quad x \ge 0, \\

\end{align}\]

\[\text{where } Q \text{ is symmetric and positive semidefinite.}\]
&lt;/blockquote&gt;

&lt;p&gt;According to the previous definition, the dual problem of the above problem is as follows:&lt;/p&gt;

\[\mathop{\max_{s,y}}_{s\ge0} \min_{x} \: L(x,s,y) = \mathop{\max_{s,y}}_{s\ge0} \min_{x} \:  \frac{1}{2} x^T Q x + c^Tx - s^Tx + (b-Ax)^T y\]

&lt;p&gt;We substitute the relationship \(Qx = A^Ty +s - c\) obtained by solving \(\nabla_x L = 0\) into the dual problem.&lt;/p&gt;

\[\begin{align}
&amp;amp;\mathop{\max_{s,y,x}}_{s\ge0} \: \frac{1}{2} x^T (A^Ty +s - c) + c^Tx - s^Tx + (b-Ax)^T y \quad \text{ s.t. } Qx = A^Ty +s - c\\\\
&amp;amp;= \mathop{\max_{s,y,x}}_{s\ge0} \: x^T (A^Ty +s - c) + c^Tx - s^Tx + (b-Ax)^T y -  \frac{1}{2} x^T (A^Ty +s - c) \quad \text{ s.t. } Qx = A^Ty +s - c\\\\
&amp;amp;= \mathop{\max_{s,y,x}}_{s\ge0}  \: b^Ty - \frac{1}{2} x^T (A^Ty +s - c) \quad  \text{ s.t. } Qx = A^Ty +s - c\\\\
&amp;amp;= \mathop{\max_{s,y,x}}_{s\ge0}  \: b^Ty - \frac{1}{2} x^T Q x \quad \text{ s.t. } Qx = A^Ty +s - c
\end{align}\]

&lt;p&gt;This can be organized as follows:&lt;/p&gt;

&lt;h3 id=&quot;dual-problem-of-qp&quot;&gt;Dual problem of QP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{maximize}}_{s,y,x} &amp;amp;\quad b^Ty - \frac{1}{2} x^T Q x\\\\
   \text{subject to} &amp;amp;\quad A^Ty +  s - c = Qx \\\\
   &amp;amp;\quad s \ge 0
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The dual problem of a quadratic problem is also a quadratic problem.&lt;/p&gt;

&lt;h2 id=&quot;example-barrier-problem-for-linear-programming&quot;&gt;Example: barrier problem for linear programming&lt;/h2&gt;
&lt;p&gt;The barrier problem for linear programming is defined as follows:&lt;/p&gt;

&lt;h3 id=&quot;barrier-problem-for-lp&quot;&gt;Barrier problem for LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{minimize}}_x &amp;amp;\quad c^Tx - \tau \sum_{i=1}^n \log(x_i)\\
   \text{subject to} &amp;amp;\quad Ax = b, \\
\end{align}\]

\[\text{where }\tau &amp;gt; 0.\]
&lt;/blockquote&gt;

&lt;p&gt;According to the previous definition, the dual problem of the above problem is as follows:
\(\begin{align}
\max_{y} \min_{x} \: L(x,y) &amp;amp;= \max_{y} \min_{x} \:  c^Tx - \tau \sum_{i=1}^n \log(x_i) + (b-Ax)^T y\\\\
&amp;amp;=  \max_{y} \min_{x} \:  \underbrace{(c-A^Ty)}_{s \doteq c-A^Ty}x - \tau \sum_{i=1}^n \log(x_i) + b^Ty\\\\
&amp;amp;= \max_{y} \min_{x} \: \sum_{i=1}^n \big( s_i^Tx_i - \tau  \log(x_i) \big) + b^Ty  \quad \text{ s.t. } A^Ty +s = c
\end{align}\)&lt;/p&gt;

&lt;p&gt;Here, \(\sum_{i=1}^n \big( s_i^Tx_i - \tau  \log(x_i) \big) + b^Ty\) will be minimized when \(x_i = \frac{\tau}{s_i}\). Therefore, let’s substitute \(\frac{\tau}{s_i}\) for \(x_i\) in the dual problem.&lt;/p&gt;

\[\begin{align}
&amp;amp;\max_{s,y} \: b^Ty + n\tau - \tau \sum_{i=1}^n log(\frac{\tau}{s_i}) \quad \text{ s.t. } A^Ty +s = c\\\\
&amp;amp;= \max_{s,y} \: b^Ty + \tau \sum_{i=1}^n log(s_i) + n\tau - n\tau\log(\tau) \quad \text{ s.t. } A^Ty +s = c\\\\
\end{align}\]

&lt;p&gt;Since \(n\tau - n\tau\log(\tau)\) can be omitted from the problem, the dual problem can be organized as follows:&lt;/p&gt;

&lt;h3 id=&quot;dual-problem-of-barrier-problem-for-lp&quot;&gt;Dual problem of Barrier problem for LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   \mathop{\text{maximize}}_{s,y} &amp;amp;\quad b^Ty + \tau \sum_{i=1}^n log(s_i)\\\\
   \text{subject to} &amp;amp;\quad A^Ty +  s = c \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;We can see that this problem is identical to the barrier problem for the dual problem of linear programming.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>21-08 Bài Tập Thực Hành - ADMM Applications</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_08_Practical_Exercises_ADMM_Applications/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_08_Practical_Exercises_ADMM_Applications</id>
   <content type="html">&lt;p&gt;Cài đặt thành công một bộ giải ADMM cho Lasso, Group Lasso hay Consensus ADMM chỉ trong vài chục dòng Python là một trải nghiệm cực kỳ “đã tay”: bạn sẽ thấy một bộ khung vỏn vẹn 3 dòng lặp có thể giải quyết trơn tru hàng loạt bài toán tối ưu lồi tưởng chừng rất khác nhau. Bộ bài tập thực hành này — lấy cảm hứng từ cẩm nang kinh điển của Boyd và cộng sự (2011) — giúp bạn tự tay viết mã, kiểm tra tiêu chuẩn dừng gốc–đối ngẫu và thử nghiệm độ nhạy của tham số \(\rho\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mẹo-thực-hành-giúp-code-admm-chạy-chuẩn-và-nhanh&quot;&gt;Kiến thức cần nhớ: Bốn mẹo thực hành giúp code ADMM chạy chuẩn và nhanh&lt;/h2&gt;

&lt;p&gt;Trước khi bắt tay giải và lập trình các bài tập bên dưới, hãy bỏ túi bốn kinh nghiệm thực chiến sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Luôn dùng dạng chuẩn hóa (Scaled Form) khi lập trình:&lt;/strong&gt; Chỉ lưu một biến đối ngẫu \(u\) (tức \(w = u_{\text{raw}}/\rho\)) giúp code ngắn gọn hơn và giảm hẳn nguy cơ nhân thiếu hoặc nhân thừa hệ số \(\rho\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đặt phân tích Cholesky ra ngoài vòng lặp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for&lt;/code&gt;:&lt;/strong&gt; Với Lasso và bài toán bậc hai, tính &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L = cholesky(A.T @ A + rho * I)&lt;/code&gt; đúng một lần trước vòng lặp, bên trong chỉ gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cho_solve&lt;/code&gt; để tiết kiệm thời gian tính toán theo cấp số nhân.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theo dõi đồng thời cả hai phần dư dừng:&lt;/strong&gt; Tính \(\|r^{(k)}\|_2 = \|x^{(k)} - z^{(k)}\|_2\) và \(\|s^{(k)}\|_2 = \rho\|z^{(k)} - z^{(k-1)}\|_2\) ở cuối mỗi vòng lặp; tuyệt đối không chỉ nhìn riêng vào \(r^{(k)}\) kẻo dừng quá sớm (như ta đã thấy ở bài 21-02!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử cập nhật \(\rho\) thích nghi (Residual Balancing):&lt;/strong&gt; Nếu \(\|r^{(k)}\|_2 &amp;gt; 10\|s^{(k)}\|_2\), nhân đôi \(\rho \leftarrow 2\rho\) và chia đôi biến chuẩn hóa \(w \leftarrow w / 2\); ngược lại nếu \(\|s^{(k)}\|_2 &amp;gt; 10\|r^{(k)}\|_2\), chia đôi \(\rho \leftarrow \rho/2\) và nhân đôi \(w \leftarrow 2w\) để hai phần dư cân bằng và hội tụ nhanh hơn nhiều!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-nháp-1-vòng-lasso-admm-với-ma-trận-trực-giao-2-times-2&quot;&gt;Giải thích: Chạy nháp 1 vòng Lasso ADMM với ma trận trực giao \(2 \times 2\)&lt;/h3&gt;

&lt;p&gt;Trước khi viết code cho Bài tập 1, hãy tự tính tay 1 vòng lặp Lasso ADMM cho \(A = I_2\), \(b = (2, \; -0.5)^T\), \(\lambda = 1\), \(\rho = 1\), khởi tạo \(z^{(0)} = (0, 0)^T, u^{(0)} = (0, 0)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tiền phân tích ma trận hệ thống:&lt;/strong&gt; \(A^T A + \rho I = I_2 + I_2 = 2 I_2 \implies (A^T A + \rho I)^{-1} = 0.5 I_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(x^{(1)}\):&lt;/strong&gt;
\(x^{(1)} = 0.5\left(A^T b + \rho(z^{(0)} - u^{(0)})\right) = 0.5\begin{bmatrix} 2 \\ -0.5 \end{bmatrix} = \begin{bmatrix} 1.0 \\ -0.25 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(z^{(1)}\) (ngưỡng mềm với \(\lambda/\rho = 1\)):&lt;/strong&gt;
\(z^{(1)} = S_1(x^{(1)} + u^{(0)}) = S_1\begin{bmatrix} 1.0 \\ -0.25 \end{bmatrix} = \begin{bmatrix} 0.0 \\ 0.0 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(u^{(1)}\) và hai phần dư:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(u^{(1)} = u^{(0)} + x^{(1)} - z^{(1)} = (1.0, \; -0.25)^T\).&lt;/li&gt;
      &lt;li&gt;Phần dư gốc \(\|r^{(1)}\|_2 = \sqrt{1^2 + 0.25^2} \approx 1.031\); phần dư đối ngẫu \(\|s^{(1)}\|_2 = 0\).
Ở vòng 2, \(x^{(2)} = 0.5(b - u^{(1)}) = (0.5, -0.125)^T\), \(x^{(2)} + u^{(1)} = (1.5, -0.375)^T \implies z^{(2)} = (0.5, 0.0)^T\), tiến thẳng về nghiệm chính xác \(x^\star = S_1(2, -0.5) = (1.0, \; 0.0)^T\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---ứng-dụng-của-admm&quot;&gt;Bài Tập Thực Hành - Ứng dụng của ADMM&lt;/h1&gt;

&lt;p&gt;Các bài tập dưới đây được tham khảo từ Boyd và cộng sự (2011).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-1-cơ-bản-về-admm&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Cơ bản về ADMM&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét bài toán \(\min f(x) + g(z)\) với ràng buộc \(Ax + Bz = c\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết các bước cập nhật của ADMM dạng chuẩn hóa (scaled ADMM).&lt;br /&gt;
b) Áp dụng cho bài toán Lasso: \(\min \frac{1}{2}\|Ax - b\|^2 + \lambda\|x\|_1\).&lt;br /&gt;
c) Chạy thử vài vòng lặp với một ví dụ nhỏ.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) ADMM dạng chuẩn hóa:**

$$x^{(k+1)} = \arg\min_x \left[ f(x) + \frac{\rho}{2}\|Ax + Bz^{(k)} - c + u^{(k)}\|^2 \right]$$

$$z^{(k+1)} = \arg\min_z \left[ g(z) + \frac{\rho}{2}\|Ax^{(k+1)} + Bz - c + u^{(k)}\|^2 \right]$$

$$u^{(k+1)} = u^{(k)} + Ax^{(k+1)} + Bz^{(k+1)} - c$$

**b) Áp dụng cho Lasso** với ràng buộc tách biến $$x - z = 0$$:

$$x^{(k+1)} = (A^TA + \rho I)^{-1}(A^Tb + \rho(z^{(k)} - u^{(k)}))$$

$$z^{(k+1)} = S_{\lambda/\rho}(x^{(k+1)} + u^{(k)})$$

$$u^{(k+1)} = u^{(k)} + x^{(k+1)} - z^{(k+1)}$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-admm-đồng-thuận-consensus-admm&quot;&gt;📝 &lt;strong&gt;Bài tập 2: ADMM đồng thuận (Consensus ADMM)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho \(N\) hàm mục tiêu: \(\min \sum_{i=1}^N f_i(x)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết lại bài toán dưới dạng đồng thuận với các biến cục bộ \(x_i\).&lt;br /&gt;
b) Suy ra bước cập nhật biến toàn cục.&lt;br /&gt;
c) Mô tả cách triển khai phân tán.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Dạng đồng thuận:**

$$\min \sum_i f_i(x_i)$$ với ràng buộc $$x_i = z \, \forall i$$

**b) Các bước ADMM:**

$$x_i^{(k+1)} = \arg\min_{x_i} \left[ f_i(x_i) + \frac{\rho}{2}\|x_i - z^{(k)} + u_i^{(k)}\|^2 \right]$$

$$z^{(k+1)} = \frac{1}{N}\sum_i (x_i^{(k+1)} + u_i^{(k)})$$

$$u_i^{(k+1)} = u_i^{(k)} + x_i^{(k+1)} - z^{(k+1)}$$

**c) Triển khai phân tán:** Mỗi nút tính toán cập nhật độc lập biến cục bộ $$x_i$$, sau đó nút điều phối lấy trung bình để cập nhật biến toàn cục $$z$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-khử-nhiễu-biến-phân-toàn-phần-total-variation-denoising&quot;&gt;📝 &lt;strong&gt;Bài tập 3: Khử nhiễu biến phân toàn phần (Total Variation Denoising)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét bài toán:&lt;/p&gt;

\[\min \frac{1}{2}\|x - b\|^2 + \lambda \|Dx\|_1\]

&lt;p&gt;với \(D\) là toán tử sai phân.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Thiết lập công thức ADMM.&lt;br /&gt;
b) Viết bước cập nhật \(x\) (thành phần trơn).&lt;br /&gt;
c) Viết bước cập nhật \(z\) (co ngưỡng mềm).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Tách biến:** Đặt $$z = Dx$$, bài toán trở thành:

$$\min_{x,z} \frac{1}{2}\|x - b\|^2 + \lambda\|z\|_1$$ với ràng buộc $$Dx - z = 0$$

**b) Bước cập nhật $$x$$:**

$$x^{(k+1)} = (I + \rho D^TD)^{-1}(b + \rho D^T(z^{(k)} - u^{(k)}))$$

(Giải hệ phương trình tuyến tính, thường có cấu trúc dải nên tính toán nhanh.)

**c) Bước cập nhật $$z$$:**

$$z^{(k+1)} = S_{\lambda/\rho}(Dx^{(k+1)} + u^{(k)})$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-phân-rã-ma-trận&quot;&gt;📝 &lt;strong&gt;Bài tập 4: Phân rã ma trận&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét bài toán \(\min \|L\|_* + \lambda\|S\|_1\) với ràng buộc \(L + S = M\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bước cập nhật \(L\) (co ngưỡng giá trị kỳ dị qua SVD).&lt;br /&gt;
b) Viết bước cập nhật \(S\) (co ngưỡng mềm theo phần tử).&lt;br /&gt;
c) Nêu ứng dụng trong PCA bền vững (robust PCA).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Bước cập nhật $$L$$:**

$$L^{(k+1)} = \arg\min_L \left[ \|L\|_* + \frac{\rho}{2}\|L + S^{(k)} - M + U^{(k)}\|_F^2 \right]$$

$$= \mathcal{S}_{1/\rho}(M - S^{(k)} - U^{(k)})$$

với $$\mathcal{S}_\tau(X) = U \text{diag}(\max(\sigma_i - \tau, 0)) V^T$$.

**b) Bước cập nhật $$S$$:**

$$S^{(k+1)} = S_{\lambda/\rho}(M - L^{(k+1)} - U^{(k)})$$

**c) Ứng dụng PCA bền vững:** Phân rã ma trận quan sát $$M = L + S$$ thành thành phần hạng thấp $$L$$ và thành phần thưa $$S$$ (nhiễu ngoại lai).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-hội-tụ-và-điều-chỉnh-tham-số&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Hội tụ và điều chỉnh tham số&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Cách chọn tham số \(\rho\).&lt;br /&gt;
b) Tiêu chí dừng thuật toán.&lt;br /&gt;
c) Quy tắc điều chỉnh \(\rho\) thích nghi.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Chọn $$\rho$$:**

*Quy tắc kinh nghiệm:* Chọn $$\rho \sim 1.0$$ đối với dữ liệu đã chuẩn hóa.

*Nguyên tắc cân bằng:* Điều chỉnh sao cho phần dư gốc và phần dư đối ngẫu giảm cân đối với nhau.

**b) Tiêu chí dừng:**

$$\epsilon_{\text{pri}} = \sqrt{n}\epsilon_{\text{abs}} + \epsilon_{\text{rel}}\max(\|Ax\|, \|Bz\|, \|c\|)$$

$$\epsilon_{\text{dual}} = \sqrt{n}\epsilon_{\text{abs}} + \epsilon_{\text{rel}}\|A^T\nu\|$$

Dừng thuật toán khi $$\|r\| &amp;lt; \epsilon_{\text{pri}}$$ và $$\|s\| &amp;lt; \epsilon_{\text{dual}}$$.

**c) Điều chỉnh $$\rho$$ thích nghi:**

```
if ||r|| &amp;gt; μ ||s||:
    ρ = τ_incr * ρ
elif ||s|| &amp;gt; μ ||r||:
    ρ = ρ / τ_decr
```

thường chọn $$\mu = 10$$ và $$\tau = 2$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Một số ứng dụng tiêu biểu của ADMM:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Bài toán&lt;/th&gt;
      &lt;th&gt;\(f(x)\)&lt;/th&gt;
      &lt;th&gt;\(g(z)\)&lt;/th&gt;
      &lt;th&gt;Ứng dụng&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Lasso&lt;/td&gt;
      &lt;td&gt;\(\frac{1}{2}|Ax-b|^2\)&lt;/td&gt;
      &lt;td&gt;\(\lambda|z|_1\)&lt;/td&gt;
      &lt;td&gt;Hồi quy thưa&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Biến phân toàn phần (TV)&lt;/td&gt;
      &lt;td&gt;\(\frac{1}{2}|x-b|^2\)&lt;/td&gt;
      &lt;td&gt;\(\lambda|z|_1\)&lt;/td&gt;
      &lt;td&gt;Khử nhiễu ảnh&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Robust PCA&lt;/td&gt;
      &lt;td&gt;\(|L|_*\)&lt;/td&gt;
      &lt;td&gt;\(\lambda|S|_1\)&lt;/td&gt;
      &lt;td&gt;Loại bỏ nhiễu ngoại lai&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đồng thuận&lt;/td&gt;
      &lt;td&gt;\(\sum f_i(x_i)\)&lt;/td&gt;
      &lt;td&gt;\(0\)&lt;/td&gt;
      &lt;td&gt;Tối ưu phân tán&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu Tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Boyd, S., et al. (2011). “Distributed Optimization via ADMM”. &lt;em&gt;Foundations and Trends&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>21-06 Faster convergence with subprogram parametrization - example of the 2d fused lasso problem</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_06_Faster_convergence_with_subprogram_parametrization_-_example_of_the_2d_fused_lasso_problem/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_06_Faster_convergence_with_subprogram_parametrization_:_example_of_the_2d_fused_lasso_problem</id>
   <content type="html">&lt;p&gt;Một sai lầm phổ biến của người mới dùng ADMM là nghĩ rằng với mỗi bài toán chỉ có &lt;em&gt;một&lt;/em&gt; cách tách biến duy nhất. Bài 21-06 sẽ thay đổi hoàn toàn tư duy đó bằng một ví dụ ngoạn mục: &lt;strong&gt;Fused Lasso 2D&lt;/strong&gt; (khử nhiễu ảnh bằng biến phân toàn phần Total Variation 2D). Nếu tách biến theo kiểu cơ bản \(D\beta = z\), ta phải giải một hệ phương trình tuyến tính 2D lớn ở mỗi vòng lặp và hai khối biến bị tương quan mạnh nên hội tụ khá chậm. Nhưng chỉ cần khéo léo tách bài toán 2D thành &lt;strong&gt;hai bộ chuỗi 1D trực giao (hàng ngang và cột dọc)&lt;/strong&gt;, mỗi bài toán con lập tức giải chính xác trong thời gian tuyến tính \(O(n)\) và tốc độ hội tụ tăng vọt!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-nguyên-lý-thiết-kế-tham-số-hóa-bài-toán-con-cho-admm&quot;&gt;Kiến thức cần nhớ: Ba nguyên lý thiết kế tham số hóa bài toán con cho ADMM&lt;/h2&gt;

&lt;p&gt;Để biết cách “chế tạo” một phiên bản ADMM chạy nhanh gấp nhiều lần phiên bản sách giáo khoa, hãy ghi nhớ ba nguyên lý sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tách theo hướng ít tương quan (De-correlated Splitting):&lt;/strong&gt; Tương tự hạ tọa độ theo khối (block coordinate descent), ADMM hội tụ nhanh nhất khi các khối biến cập nhật theo những phương hình học gần trực giao nhau (như chiều ngang vs. chiều dọc trên lưới ảnh 2D).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khai thác bộ giải bài toán con tuyến tính \(O(n)\):&lt;/strong&gt; Bài toán Fused Lasso 1D (khử nhiễu trên một đường thẳng \(m\) điểm) có thuật toán quy hoạch động giải &lt;strong&gt;chính xác tuyệt đối&lt;/strong&gt; trong thời gian \(O(m)\) (thuật toán Johnson 2013 / Condat 2013). Do đó, tách lưới 2D thành các chuỗi 1D theo hàng và theo cột cho phép giải song song toàn bộ các hàng rồi toàn bộ các cột mà không cần giải hệ tuyến tính lớn!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cân bằng giữa chi phí mỗi vòng và số vòng lặp:&lt;/strong&gt; Một cách tách biến tốt có thể hơi phức tạp hơn về công thức toán tử proximal, nhưng nếu nó gom được nhiều cấu trúc của bài toán vào mỗi khối (giảm độ lỏng của ràng buộc phụ), tổng thời gian chạy sẽ giảm đi theo cấp số nhân.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-trực-tiếp-độ-phức-tạp-hai-cách-tách-admm-cho-ảnh-100-times-100&quot;&gt;Giải thích: So sánh trực tiếp độ phức tạp hai cách tách ADMM cho ảnh \(100 \times 100\)&lt;/h3&gt;

&lt;p&gt;Xét bài toán khử nhiễu ảnh Fused Lasso 2D trên một bức ảnh nhỏ \(100 \times 100\) điểm ảnh (tổng cộng \(n = 10{,}000\) biến \(\beta_{i,j}\), với \(19{,}800\) cặp cạnh kề ngang–dọc):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cách tách chuẩn (\(D\beta = z\), trong đó \(D\) là ma trận sai phân 2D):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Bước \(\beta\):&lt;/strong&gt; Phải giải hệ tuyến tính \((I + \rho D^T D)\beta = y + \rho D^T(z - w)\) kích thước \(10{,}000 \times 10{,}000\) (ma trận Laplace 2D có băng rộng \(100\)). Nếu dùng phân tích Cholesky dải, chi phí cỡ \(O(n \cdot 100^2) \approx 10^8\) phép toán để khởi tạo và \(O(n \cdot 100) \approx 10^6\) phép toán mỗi vòng.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước \(z\):&lt;/strong&gt; Ngưỡng mềm từng cạnh \(O(n)\), nhưng vì toàn bộ liên kết lưới bị đẩy sang biến \(z\), thông tin lan truyền chậm qua từng cạnh đơn lẻ nên cần nhiều vòng lặp.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách tách trực giao Hàng – Cột (\(\beta = z_1 = z_2\) với phạt ngang trong \(z_1\) và phạt dọc trong \(z_2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Bước \(z_1\) (phạt theo hàng):&lt;/strong&gt; Tách thành &lt;strong&gt;100 bài toán Fused Lasso 1D độc lập&lt;/strong&gt; dài 100 điểm, mỗi bài giải chính xác trong \(O(100)\) phép toán \(\implies\) tổng chỉ \(O(n) \approx 10^4\) phép toán và chạy song song được trên 100 luồng!&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước \(z_2\) (phạt theo cột):&lt;/strong&gt; Tách thành &lt;strong&gt;100 bài toán Fused Lasso 1D độc lập&lt;/strong&gt; theo cột, tổng cũng chỉ \(O(n) \approx 10^4\) phép toán!&lt;/li&gt;
      &lt;li&gt;Nhờ mỗi bước đã tối ưu chính xác trọn vẹn cả một hàng hoặc cả một cột, thông tin lan truyền xuyên toàn bộ bức ảnh chỉ sau vài vòng lặp!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;hội-tụ-nhanh-hơn-nhờ-tham-số-hóa-bài-toán-con&quot;&gt;Hội tụ nhanh hơn nhờ tham số hóa bài toán con&lt;/h1&gt;

&lt;h2 id=&quot;giới-thiệu&quot;&gt;Giới thiệu&lt;/h2&gt;

&lt;p&gt;Một tính chất đáng chú ý của ADMM là tốc độ hội tụ có thể cải thiện đáng kể nếu ta tham số hóa các bài toán con một cách phù hợp. Trong ví dụ ADMM đồng thuận trước đó, thuật toán tối ưu lần lượt theo từng khối biến, khá tương đồng với phương pháp hạ tọa độ theo khối (block coordinate descent). Nhờ vậy, khi thiết kế các khối biến cập nhật theo những hướng gần như trực giao hoặc ít tương quan với nhau, ADMM có thể hội tụ nhanh hơn nhiều so với cách tách biến tiêu chuẩn.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-fused-lasso-2d&quot;&gt;Ví dụ fused lasso 2D&lt;/h2&gt;

&lt;p&gt;Phần này minh họa ý tưởng trên bằng cách thiết kế các ràng buộc phụ sao cho các bước cập nhật biến gốc đi theo những hướng không tương quan (de-correlated). Chi tiết nghiên cứu có thể xem trong [RT16], [WSK14], [BS14].&lt;/p&gt;

&lt;p&gt;Xét bài toán fused lasso 2D (hay khử nhiễu biến phân toàn phần 2D — 2D total variation denoising) đã giới thiệu ở &lt;a href=&quot;/contents/vi/chapter01/01_01_optimization_problems/&quot;&gt;Chương 1&lt;/a&gt;. Cho một ảnh quan sát \(Y\in \mathbb{R}^{d\times d}\), bài toán được phát biểu như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{\Theta}\frac{1}{2}||Y-\Theta||^{2}_{F}+\lambda \sum_{i,j}(|\Theta_{i,j}-\Theta_{i+1,j}|+|\Theta_{i,j}-\Theta_{i,j+1}|).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây mỗi điểm ảnh ứng với một tham số trong ma trận \(\Theta\in \mathbb{R}^{d\times d}\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/2dfussed.png&quot; alt=&quot;[Hình 1] Diễn giải số hạng phạt trong fused lasso 2D [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Diễn giải số hạng phạt trong fused lasso 2D [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;[Hình 1] minh họa trực quan số hạng phạt thứ hai trong hàm mục tiêu. Số hạng này phạt độ chênh lệch giữa mỗi điểm ảnh với các điểm ảnh kề nó theo cả phương ngang và phương dọc, nhờ đó khuyến khích các điểm ảnh lân cận nhận giá trị tương đồng nhau.&lt;/p&gt;

&lt;h2 id=&quot;dạng-vector&quot;&gt;Dạng vector&lt;/h2&gt;

&lt;p&gt;Viết gọn số hạng phạt bằng một toán tử tuyến tính, bài toán có dạng:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\min_{\theta}\frac{1}{2}||y-\theta||^{2}_{2} + \lambda||D\theta||_{1}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(D\in \mathbb{R}^{m\times n}\) là ma trận toán tử sai phân 2D tương ứng với phương trình gốc.&lt;/p&gt;

&lt;h2 id=&quot;các-dạng-cập-nhật-admm-cho-bài-toán-fused-lasso-2d&quot;&gt;Các dạng cập nhật ADMM cho bài toán fused lasso 2D&lt;/h2&gt;

&lt;p&gt;Ta xây dựng hai biến thể ADMM khác nhau thông qua hai cách đặt ràng buộc phụ.&lt;/p&gt;

&lt;p&gt;Cách thứ nhất xuất phát từ dạng vector với toán tử sai phân 2D:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{\theta, z}\frac{1}{2}||y-\theta||^{2}_{2}+\lambda||z||_{1} \qquad \text{subject to   }z = D\theta,
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Các bước cập nhật ADMM tương ứng là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\theta^{(k)} &amp;amp;= (I+\rho D^{T}D)^{-1}(y+\rho D^{T}(z^{(k-1)}+w^{(k-1)}))\\\\
z^{(k)} &amp;amp;= S_{\frac{\lambda}{\rho}}(D\theta^{(k)}-w^{(k-1)})\\\\
w^{(k)} &amp;amp;= w^{(k-1)}+z^{(k)}-D\theta ^{(k)}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;độ-phức-tạp-tính-toán--dạng-vector&quot;&gt;Độ phức tạp tính toán — dạng vector&lt;/h2&gt;

&lt;p&gt;Bước cập nhật \(\theta\) đòi hỏi giải hệ phương trình tuyến tính với ma trận hệ số \((I+\rho D^{T}D)\). Vì \(L=D^{T}D\) là ma trận Laplace của lưới 2D, hệ này có thể giải với chi phí \(O(n)\) phép tính (hoặc gần tuyến tính tùy bộ giải lưới). Bước cập nhật \(z\) chỉ áp dụng toán tử co ngưỡng mềm \(S_{t}\) nên cũng tốn \(O(n)\) phép tính. Như vậy, mỗi vòng lặp của ADMM dạng vector có độ phức tạp \(O(n)\).&lt;/p&gt;

&lt;h2 id=&quot;admm-dạng-ma-trận&quot;&gt;ADMM dạng ma trận&lt;/h2&gt;

&lt;p&gt;Cách thứ hai giữ nguyên cấu trúc ma trận của bài toán gốc và tách thành phần sai phân dọc cho \(\Theta\), sai phân ngang cho \(Z\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{\Theta, Z} &amp;amp;&amp;amp;\frac{1}{2}||Y-\Theta||^{2}_{F}+\lambda\sum_{i,j}(|\Theta_{i,j}-\Theta_{i+1,j}|+|Z_{i,j}-Z_{i,j+1}|)\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;\Theta = Z
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Các bước cập nhật ADMM thu được như sau:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
\Theta_{\cdot \\ , j}^{(k)} &amp;amp;= FL^{1d}_{ \frac{\lambda}{(1+\rho)} } \bigg( \frac{ Y_{\cdot \\ , j}+\rho( Z^{(k-1)}_{\cdot \\ , j}-W_{\cdot \\ ,j}^{(k-1)} ) } {1+\rho} \bigg),\qquad j=1,...,d\\\\
Z_{i, \cdot}^{(k)} &amp;amp;= FL^{1d}_{\frac{\lambda}{\rho}} \bigg(\Theta_{i, \cdot}^{(k)} + W_{i, \cdot}^{(k-1)} \bigg), \qquad i=1,...,d\\\\
W^{(k)} &amp;amp;= W^{(k-1)} + \Theta^{(k)} - Z^{(k)} \\\\
\end{align}\)
trong đó \(FL_{\tau}^{1d}(a)\) là bài toán fused lasso 1D, định nghĩa là \(FL_{\tau}^{1d}(a) = \underset{x}{\operatorname{argmin}}\frac{1}{2}||a-x||^{2}_{2}+\tau\sum_{i=1}^{d-1}|x_{i}-x_{i+1}|\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;độ-phức-tạp-tính-toán--dạng-ma-trận&quot;&gt;Độ phức tạp tính toán — dạng ma trận&lt;/h2&gt;

&lt;p&gt;ADMM dạng ma trận cũng đạt độ phức tạp \(O(n)\) cho mỗi vòng lặp, vì cả hai bước cập nhật \(\Theta\) (theo từng cột) và \(Z\) (theo từng hàng) đều quy về các bài toán fused lasso 1D, vốn có thuật toán giải trong thời gian tuyến tính theo số phần tử.&lt;/p&gt;

&lt;p&gt;[Hình 2] minh họa cách số hạng phạt ban đầu được tách thành các bài toán con fused lasso 1D theo cột và theo hàng.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/2dfussedlasso.png&quot; alt=&quot;[Hình 2] Diễn giải các cập nhật ADMM dạng ma trận cho fused lasso 2D [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Diễn giải các cập nhật ADMM dạng ma trận cho fused lasso 2D [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;thí-nghiệm-khử-nhiễu-ảnh&quot;&gt;Thí nghiệm khử nhiễu ảnh&lt;/h2&gt;

&lt;p&gt;Quay lại bài toán khử nhiễu ảnh ở Chương 1, [Hình 3] trình bày ảnh đầu vào và nghiệm chính xác sau khi khử nhiễu. [Hình 4] so sánh tốc độ hội tụ của hai biến thể ADMM: biến thể ADMM “chuyên biệt” dạng ma trận (tách ràng buộc theo phương dọc và phương ngang) hội tụ nhanh hơn rõ rệt so với “ADMM chuẩn” dạng vector.&lt;/p&gt;

&lt;p&gt;[Hình 5] minh họa chất lượng ảnh tái tạo sau các mốc vòng lặp ADMM khác nhau.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/ll1.png&quot; alt=&quot;[Hình 3] Dữ liệu và ảnh nghiệm chính xác (ảnh 300x200: n = 60.000). Trái: ảnh gốc trước khi khử nhiễu, phải: nghiệm chính xác của ảnh đã khử nhiễu [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 3] Dữ liệu và ảnh nghiệm chính xác (ảnh 300x200: n = 60.000). Trái: ảnh gốc trước khi khử nhiễu, phải: nghiệm chính xác của ảnh đã khử nhiễu [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/ll2.png&quot; alt=&quot;[Hình 4] Đường hội tụ của hai thuật toán ADMM. Đen: chuẩn (dạng vector), đỏ: chuyên biệt (dạng ma trận) [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 4] Đường hội tụ của hai thuật toán ADMM. Đen: chuẩn (dạng vector), đỏ: chuyên biệt (dạng ma trận) [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/admm_iteration_visualized.png&quot; alt=&quot;[Hình 5] Các điểm lặp ADMM sau k = 10, 30, 50, 100 vòng lặp [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 5] Các điểm lặp ADMM sau k = 10, 30, 50, 100 vòng lặp [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>21-05 ADMM đồng thuận (Consensus ADMM)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_05_Consensus_ADMM/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_05_Consensus_ADMM</id>
   <content type="html">&lt;p&gt;Khi tập dữ liệu huấn luyện khổng lồ tới mức phải rải đều trên \(B = 100\) máy chủ khác nhau, bài toán tối ưu có dạng tổng \(\min_x \sum_{i=1}^B f_i(x)\), trong đó mỗi máy chủ \(i\) chỉ nắm giữ hàm mất mát \(f_i\) trên mảnh dữ liệu của riêng nó. Thay vì dồn dữ liệu về một chỗ, &lt;strong&gt;ADMM đồng thuận (Consensus ADMM)&lt;/strong&gt; làm một phép biến hóa đơn giản đến ngỡ ngàng: cấp cho mỗi máy chủ một bản sao biến riêng \(x_i\) kèm ràng buộc đồng nhất \(x_i = x\)! Nhờ vậy, bước cập nhật \(x_i\) chạy &lt;strong&gt;song song tuyệt đối&lt;/strong&gt; trên cả 100 máy, còn bước cập nhật biến toàn cục \(x\) chỉ là &lt;strong&gt;một phép lấy trung bình cộng&lt;/strong&gt; duy nhất!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-admm-đồng-thuận-consensus-admm&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của ADMM đồng thuận (Consensus ADMM)&lt;/h2&gt;

&lt;p&gt;Để cài đặt và mở rộng Consensus ADMM trên hệ thống phân tán thực tế, hãy nắm rõ bốn cơ chế sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tách biến đồng nhất (\(x_i = x, \; i = 1, \dots, B\)):&lt;/strong&gt; Biến bài toán tối ưu chung biến \(x\) thành bài toán hai khối \((x_1, \dots, x_B)\) và biến đồng thuận \(x\). Toàn bộ sự liên kết giữa các máy chủ bị cô lập vào duy nhất biến trung tâm \(x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất tự triệt tiêu tổng biến đối ngẫu (\(\bar{w}^{(k)} = 0\)):&lt;/strong&gt; Vì bước trung tâm đặt \(x^{(k)} = \bar{x}^{(k)} + \bar{w}^{(k-1)}\), nên khi cập nhật \(w_i^{(k)} = w_i^{(k-1)} + x_i^{(k)} - x^{(k)}\), lấy trung bình cộng hai vế lập tức cho \(\bar{w}^{(k)} = \bar{w}^{(k-1)} + \bar{x}^{(k)} - (\bar{x}^{(k)} + \bar{w}^{(k-1)}) = 0\) với mọi \(k \ge 1\)! Nhờ đó bước trung tâm rút gọn thành đúng trung bình cộng \(x^{(k)} = \frac{1}{B}\sum_{i=1}^B x_i^{(k)}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thêm điều chuẩn chung \(g(x)\) tại máy chủ trung tâm:&lt;/strong&gt; Nếu bài toán là \(\min \sum_{i=1}^B f_i(x) + g(x)\) (ví dụ phạt Lasso toàn cục \(\lambda\|x\|_1\)), bước trung tâm chỉ cần thay trung bình cộng bằng \(\operatorname{prox}_{g, 1/(B\rho)}(\bar{x}^{(k)})\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mở rộng sang đồng thuận cục bộ trên đồ thị (General Consensus):&lt;/strong&gt; Khi mỗi nút chỉ dùng một tập con tọa độ của \(x\) (như mô hình đồ thị hay lưới điện), mỗi tọa độ toàn cục \(x_j\) chỉ cần lấy trung bình trên tập các nút có chứa tọa độ \(j\) đó.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-1-vòng-lặp-consensus-admm-trên-3-máy-chủ-và-kiểm-chứng-barw1--0&quot;&gt;Giải thích: Chạy tay 1 vòng lặp Consensus ADMM trên 3 máy chủ và kiểm chứng \(\bar{w}^{(1)} = 0\)&lt;/h3&gt;

&lt;p&gt;Xét \(B = 3\) máy chủ giải bài toán \(\min_x \frac{1}{2}(x - 1)^2 + \frac{1}{2}(x - 4)^2 + \frac{1}{2}(x - 7)^2\) (nghiệm tối ưu toàn cục là trung bình \(x^\star = \frac{1 + 4 + 7}{3} = 4\)). Chọn \(\rho = 1\), khởi tạo \(x^{(0)} = 0\) và \(w_1^{(0)} = w_2^{(0)} = w_3^{(0)} = 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — 3 máy chủ giải song song độc lập:&lt;/strong&gt;
Mỗi máy giải \(x_i^{(1)} = \arg\min_{x_i} \left(\frac{1}{2}(x_i - c_i)^2 + \frac{1}{2}(x_i - 0 + 0)^2\right) = \frac{c_i}{2}\):
    &lt;ul&gt;
      &lt;li&gt;Máy 1 (\(c_1 = 1\)): \(x_1^{(1)} = 0.5\).&lt;/li&gt;
      &lt;li&gt;Máy 2 (\(c_2 = 4\)): \(x_2^{(1)} = 2.0\).&lt;/li&gt;
      &lt;li&gt;Máy 3 (\(c_3 = 7\)): \(x_3^{(1)} = 3.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Máy chủ trung tâm lấy trung bình cộng:&lt;/strong&gt;
\(x^{(1)} = \frac{0.5 + 2.0 + 3.5}{3} = 2.0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — 3 máy chủ tự cập nhật biến đối ngẫu riêng \(w_i^{(1)} = w_i^{(0)} + x_i^{(1)} - x^{(1)}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(w_1^{(1)} = 0.5 - 2.0 = -1.5\).&lt;/li&gt;
      &lt;li&gt;\(w_2^{(1)} = 2.0 - 2.0 = 0.0\).&lt;/li&gt;
      &lt;li&gt;\(w_3^{(1)} = 3.5 - 2.0 = +1.5\).
Kiểm tra tổng biến đối ngẫu: \(\bar{w}^{(1)} = \frac{-1.5 + 0.0 + 1.5}{3} = 0\) — triệt tiêu chính xác! Và ở vòng 2, \(x_1^{(2)} = \frac{1 + 2 - (-1.5)}{2} = 2.25, \; x_2^{(2)} = 3.0, \; x_3^{(2)} = 3.75 \implies x^{(2)} = 3.0\), tiến đều đặn về đúng \(x^\star = 4.0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;admm-đồng-thuận&quot;&gt;ADMM đồng thuận&lt;/h1&gt;

&lt;h2 id=&quot;admm-đồng-thuận-cơ-bản&quot;&gt;ADMM đồng thuận cơ bản&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối ưu tổng các hàm mục tiêu sau:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\min_{x}\sum^{B}_{i=1} f_{i}(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Để áp dụng ADMM và đồng thời biến đổi bài toán sang dạng dễ tính toán song song, phương pháp ADMM đồng thuận (consensus ADMM) tham số hóa lại bài toán bằng cách gán cho mỗi thành phần một bản sao biến cục bộ \(x_i\) kèm ràng buộc đồng nhất:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x_{1},...,x_{B},x} &amp;amp;&amp;amp;\sum^{B}_{i=1} f_{i}(x_{i})\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;x_{i}=x, i = 1,...B
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;thuật-toán-admm&quot;&gt;Thuật toán ADMM&lt;/h2&gt;

&lt;p&gt;Cách tách biến này cho phép suy ra các bước cập nhật ADMM phân rã được theo từng khối:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^{(k)}_{i} &amp;amp;= \underset{x_{i}}{\operatorname{argmin}} f_{i}(x_{i})+\frac{\rho}{2}||x_{i}-x^{(k-1)}+w_{i}^{(k-1)}||_{2}^{2}, i=1,...B\\\\
x^{(k)} &amp;amp;=\frac{1}{B}\sum_{i=1}^{B}(x_{i}^{(k)}+w_{i}^{(k-1)})\\\\
w_{i}^{(k)} &amp;amp;=w_{i}^{(k-1)}+x_{i}^{(k)}-x^{(k)}, i=1,...,B
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;dạng-rút-gọn&quot;&gt;Dạng rút gọn&lt;/h2&gt;

&lt;p&gt;Đặt \(\overline{x}=\frac{1}{B}\sum_{i=1}^{B}x_{i}\) và \(\overline{w}=\frac{1}{B}\sum_{i=1}^{B}w_{i}\). Dễ dàng kiểm tra rằng \(\overline{w}^{(k)}=0\) với mọi vòng lặp \(k \ge 1\), nhờ đó bước cập nhật biến toàn cục rút gọn thành \(x^{(k)}=\overline{x}^{(k)}\). Khi đó, thuật toán được viết gọn lại như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^{(k)}_{i} &amp;amp;= \underset{x_{i}}{\operatorname{argmin}} f_{i}(x_{i})+\frac{\rho}{2}||x_{i}-\overline{x}^{(k-1)}+w_{i}^{(k-1)}||_{2}^{2},  i=1,...B\\\\
w_{i}^{(k)} &amp;amp;=w_{i}^{(k-1)}+x_{i}^{(k)}-\overline{x}^{(k)},  i=1,...,B.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;trực-giác&quot;&gt;Trực giác&lt;/h2&gt;

&lt;p&gt;Các bước cập nhật \(x_{i}\) (\(i = 1,\ldots,B\)) hoàn toàn độc lập nên có thể tính song song.&lt;/p&gt;

&lt;p&gt;Từ dạng rút gọn trên, ta có thể hiểu trực quan cơ chế của ADMM đồng thuận: mỗi bước cập nhật \(x_{i}\) vừa tìm cách cực tiểu hóa hàm mục tiêu riêng \(f_{i}(x_{i})\), vừa chịu số hạng phạt \(l_{2}\) kéo \(x_{i}\) tiến về giá trị trung bình toàn cục \(\overline{x}\). Nếu \(x_{i}\) lớn hơn mức trung bình, biến đối ngẫu \(w_{i}\) sẽ tăng lên, khiến số hạng phạt ở vòng lặp kế tiếp tạo lực kéo mạnh hơn để giảm \(x_{i}\) về lại gần trung bình.&lt;/p&gt;

&lt;h2 id=&quot;admm-đồng-thuận-tổng-quát&quot;&gt;ADMM đồng thuận tổng quát&lt;/h2&gt;

&lt;p&gt;ADMM đồng thuận có thể mở rộng cho lớp bài toán có phép biến đổi affine của \(x\) và thêm một hàm chính quy hóa bất kỳ \(g\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x}\sum_{i=1}^{B} f_{i}(a^{T}_{i}x+b_{i})+g(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ta tiếp tục tham số hóa lại bài toán bằng các ràng buộc đồng thuận:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x_{1},..x_{B},x} &amp;amp;&amp;amp;\sum^{B}_{i=1}f_{i}(a_{i}^{T}x_{i}+b_{i})+g(x)\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;x_{i} = x, i=1,...B
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ đó thu được các bước cập nhật ADMM phân rã được:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x_{i}^{(k)} &amp;amp;= \underset{x_{i}}{\operatorname{argmin}}f_{i}(a_{i}^{T}x_{i}+b_{i})+\frac{\rho}{2}||x_{i}-x^{(k-1)}+w_{i}^{(k-1)}||^{2}_{2}\\\\
x^{(k)}&amp;amp;=\underset{x}{\operatorname{argmin}} \frac{B\rho}{2}||x-\overline{x}^{(k)}-\overline{w}^{(k-1)}||^{2}_{2}+g(x)\\\\
w_{i}^{(k)}&amp;amp;=w_{i}^{(k-1)}+x_{i}^{(k)}-x^{(k)}, i=1,...B
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;những-điểm-khác-biệt-chính&quot;&gt;Những điểm khác biệt chính&lt;/h2&gt;

&lt;p&gt;So với dạng cơ bản, ADMM đồng thuận tổng quát có các đặc điểm sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Do bước cập nhật \(x^{(k)}\) không còn rút gọn thành trung bình đơn thuần, tính chất \(\overline{w}^{(k)}=0\) không còn giữ nguyên.&lt;/li&gt;
  &lt;li&gt;Các biến cục bộ \(x_{i}\) (\(i=1,\ldots,B\)) vẫn được cập nhật song song.&lt;/li&gt;
  &lt;li&gt;Mỗi bước cập nhật \(x_{i}\) tương ứng với việc cực tiểu hóa thành phần mất mát cục bộ kết hợp với số hạng phạt \(l_2\).&lt;/li&gt;
  &lt;li&gt;Bước cập nhật biến toàn cục \(x\) trở thành một phép tính toán tử proximal đối với hàm \(g\) (thường là số hạng chính quy hóa).&lt;/li&gt;
  &lt;li&gt;Các cách tham số hóa lại khác nhau sẽ dẫn đến những biến thể thuật toán ADMM khác nhau.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chi tiết tham khảo thêm tại &lt;a href=&quot;/contents/vi/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;danh mục bài báo tham khảo của Chương 21&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>21-04 Ví dụ: Ước lượng không gian con thưa và phân rã thưa cộng hạng thấp</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_04_Example_-_Sparse_subspace_estimation_and_sparse_plus_low_rank_decomposition/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_04_Example_:_Sparse_subspace_estimation_and_sparse_plus_low_rank_decomposition</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng một camera an ninh quay cố định một hành lang suốt nhiều giờ: phần nền (tường, sàn, cửa) gần như đứng yên nên tạo thành một &lt;strong&gt;ma trận hạng thấp (low-rank)&lt;/strong&gt; \(L\), còn người đi lại chỉ chiếm một phần nhỏ khung hình nên tạo thành một &lt;strong&gt;ma trận thưa (sparse)&lt;/strong&gt; \(S\). Làm thế nào tách khung hình quan sát \(M = L + S\) thành đúng phần nền \(L\) và phần người di chuyển \(S\)? Bài 21-04 giới thiệu hai bài toán ma trận kinh điển — &lt;strong&gt;Ước lượng không gian con thưa (Sparse PCA / Fantope)&lt;/strong&gt; và &lt;strong&gt;Phân rã thưa cộng hạng thấp (Robust PCA)&lt;/strong&gt; — nơi ADMM tỏa sáng bằng cách ghép hai toán tử proximal ma trận cực kỳ thanh lịch: ngưỡng mềm phần tử và &lt;strong&gt;ngưỡng giá trị kỳ dị (Singular Value Thresholding)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tối-ưu-hóa-ma-trận-bằng-admm&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tối ưu hóa ma trận bằng ADMM&lt;/h2&gt;

&lt;p&gt;Để đọc hiểu dễ dàng các ký hiệu không gian ma trận \(\mathbb{S}^p, \mathcal{F}_k, \|L\|_*\) trong bài này, hãy nắm rõ bốn khái niệm nền:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng lồi Fantope \(\mathcal{F}_k\) cho không gian con hạng \(k\):&lt;/strong&gt; Tập các ma trận chiếu hạng \(k\) không lồi. Bao lồi của nó là tập Fantope \(\mathcal{F}_k = \{Y \in \mathbb{S}^p : 0 \preceq Y \preceq I, \; \operatorname{tr}(Y) = k\}\) — cho phép viết bài toán Sparse PCA dưới dạng bài toán tối ưu lồi giải được bằng ADMM!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn hạt nhân \(\|L\|_* = \sum_i \sigma_i(L)\) làm đại diện lồi cho hạng ma trận:&lt;/strong&gt; Hệt như chuẩn \(\ell_1\) là bao lồi chặt nhất của số phần tử khác không (\(\|x\|_0\)) cho vector, chuẩn hạt nhân (tổng các giá trị kỳ dị) là bao lồi chặt nhất của \(\operatorname{rank}(L)\) trên hình cầu đơn vị phổ!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ngưỡng giá trị kỳ dị (SVT) là toán tử proximal của chuẩn hạt nhân:&lt;/strong&gt; Với phân rã SVD \(A = U\Sigma V^T\), ta có \(\operatorname{prox}_{\tau\|\cdot\|_*}(A) = U \operatorname{diag}((\sigma_i - \tau)_+) V^T\) — chỉ cần co các giá trị kỳ dị bằng ngưỡng mềm rồi nhân ghép lại!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân rã 3 khối thành 2 khối trong Robust PCA:&lt;/strong&gt; Bài toán \(\min \|L\|_* + \lambda\|S\|_1 \text{ s.t. } L + S = M\) khớp hoàn hảo với khung ADMM hai khối (\(A = I, B = I, c = M\)): bước \(L\) gọi SVT, bước \(S\) gọi ngưỡng mềm phần tử, cực kỳ gọn gàng!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-1-bước-svt--ngưỡng-mềm-phân-rã-ma-trận-2-times-2&quot;&gt;Giải thích: Chạy tay 1 bước SVT + Ngưỡng mềm phân rã ma trận \(2 \times 2\)&lt;/h3&gt;

&lt;p&gt;Xét ma trận quan sát đường chéo \(M = \begin{bmatrix} 5 &amp;amp; 0 \\ 0 &amp;amp; 1.5 \end{bmatrix}\) (giả sử ta muốn tách \(M = L + S\) với \(L\) hạng thấp và \(S\) thưa), tham số phạt \(\lambda = 1\), \(\rho = 0.5\) (nên ngưỡng SVT cho \(L\) là \(\tau_L = 1/\rho = 2\) và ngưỡng mềm cho \(S\) là \(\tau_S = \lambda/\rho = 2\)). Khởi tạo \(S^{(0)} = 0, W^{(0)} = 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;**Bước 1 — Cập nhật thành phần hạng thấp \(L^{(1)} = \operatorname{SVT}_{2}(M - S^{(0)} - W^{(0)})\): **
    &lt;ul&gt;
      &lt;li&gt;Các giá trị kỳ dị của \(M\) là \(\sigma_1 = 5\) và \(\sigma_2 = 1.5\).&lt;/li&gt;
      &lt;li&gt;Áp dụng ngưỡng mềm với \(\tau_L = 2\):
\(\sigma_1^+ = (5 - 2)_+ = 3, \qquad \sigma_2^+ = (1.5 - 2)_+ = 0.\)&lt;/li&gt;
      &lt;li&gt;Thu được \(L^{(1)} = \begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}\) — &lt;strong&gt;hạng ma trận lập tức giảm từ 2 xuống 1!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Cập nhật thành phần thưa \(S^{(1)} = S_{2}(M - L^{(1)} - W^{(0)})\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Phần dư còn lại: \(M - L^{(1)} = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 1.5 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;Áp dụng ngưỡng mềm từng phần tử với \(\tau_S = 2\): \(S^{(1)} = \begin{bmatrix} (2-2)_+ &amp;amp; 0 \\ 0 &amp;amp; (1.5-2)_+ \end{bmatrix} = \begin{bmatrix} 0 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}\) (nếu chọn \(\lambda = 0.5\) thì \(\tau_S = 1\) cho \(S^{(1)} = \operatorname{diag}(1, 0.5)\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Cập nhật biến đối ngẫu:&lt;/strong&gt; \(W^{(1)} = W^{(0)} + L^{(1)} + S^{(1)} - M\), đẩy phần còn lại sang vòng sau để \(L^{(k)} + S^{(k)}\) hội tụ chính xác về \(M\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;ví-dụ-ước-lượng-không-gian-con-thưa-và-phân-rã-thưa-cộng-hạng-thấp&quot;&gt;Ví dụ: Ước lượng không gian con thưa và phân rã thưa cộng hạng thấp&lt;/h1&gt;

&lt;h2 id=&quot;ước-lượng-không-gian-con-thưa&quot;&gt;Ước lượng không gian con thưa&lt;/h2&gt;

&lt;p&gt;Cho \(S=X^{T}X\) với \(X\in \mathbb{R}^{n\times p}\), xét bài toán tìm ma trận chiếu \(P\) cực tiểu hóa khoảng cách theo chuẩn Frobenius giữa ma trận dữ liệu gốc \(X\) và ảnh chiếu \(XP\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{P} &amp;amp;&amp;amp;||X-XP||^{2}_{F}\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;\text{rank(P)=k where P is a projection matrix}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán này không lồi vì tập các ma trận chiếu hạng \(k\) không phải là tập lồi. Tuy nhiên, nó tương đương với bài toán lồi sau [&lt;a href=&quot;/contents/vi/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;VCLR13&lt;/a&gt;], thường gọi là bài toán ước lượng không gian con:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{Y} &amp;amp;&amp;amp;tr(SY)\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;Y\in F_{k} = \left\{Y\in \mathbb{S}^{p} : 0 \preceq Y \preceq I, tr(Y) = k \right\}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tài liệu [VCLR13] nghiên cứu phiên bản thưa (bổ sung số hạng phạt chuẩn \(l_1\)) của bài toán ước lượng không gian con; chi tiết suy diễn có thể xem trong bài báo gốc:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{Y} &amp;amp;&amp;amp;tr(SY)-\lambda ||Y||_{1}\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;Y\in F_{k} 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(F_{k}\) là tập Fantope bậc \(k\) như đã định nghĩa ở trên.&lt;/p&gt;

&lt;p&gt;Khi \(\lambda = 0\), bài toán trên quy về PCA chuẩn.&lt;/p&gt;

&lt;p&gt;Bài toán này thuộc lớp quy hoạch nửa xác định (SDP) nên có thể giải bằng các phương pháp điểm trong, nhưng cách tiếp cận đó khá phức tạp khi cài đặt và chạy rất chậm khi kích thước bài toán lớn.&lt;/p&gt;

&lt;h2 id=&quot;công-thức-hóa-admm&quot;&gt;Công thức hóa ADMM&lt;/h2&gt;

&lt;p&gt;Để áp dụng ADMM, ta viết lại bài toán dưới dạng tách biến:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{Y,Z} &amp;amp;&amp;amp;-tr(SY)+I_{F_{k}}(Y) + \lambda||Z||_{1}\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;Y = Z.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;thuật-toán-admm&quot;&gt;Thuật toán ADMM&lt;/h2&gt;

&lt;p&gt;Các bước cập nhật ADMM thu được như sau:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
Y^{+} &amp;amp;=  \underset{Y}{\operatorname{argmin}} -tr(SY) + I_{F_{k}}(Y)+\frac{\rho}{2}||Y-Z+W||^{2}_{F}\\\\
&amp;amp;=\underset{Y\in F_{k}}{\operatorname{argmin}} \frac{1}{2}||Y-Z+W-\frac{S}{\rho}||^{2}_{F}\\\\
&amp;amp;=P_{F_{k}}(Z-W+\frac{S}{\rho})\\\\
Z^{+} &amp;amp; = \underset{Z}{\operatorname{argmin}}\lambda||Z||_{1}+\frac{\rho}{2}||Y^{+}-Z+W||^{2}_{F}\\\\
&amp;amp;=S_{\frac{\lambda}{\rho}}(Y^{+}+W)\\\\
W^{+} &amp;amp;=W+Y^{+}-Z^{+}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(P_{F_{k}}\) là toán tử chiếu lên tập Fantope, được định nghĩa bằng cách cắt ngưỡng (clipping) các trị riêng trong phân rã trị riêng \(A= U\Sigma U^{T}, \Sigma = diag(\sigma_{1},\ldots,\sigma_{p})\) [&lt;a href=&quot;/contents/vi/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;VCLR13&lt;/a&gt;]:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
P_{F_{k}}(A) = U\Sigma_{\theta}U^{T}, \: \Sigma_{\theta} = diag(\sigma_{1}(\theta),\ldots,\sigma_{p}(\theta))
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;với mỗi \(\sigma_{i}(\theta) = \min\left\{\max\left\{\sigma_{i}-\theta,0\right\},1\right\}\) và \(\theta\) được chọn sao cho \(\sum^{p}_{i=1}\sigma_{i}(\theta)=k\).&lt;/p&gt;

&lt;h2 id=&quot;phân-rã-thưa-cộng-hạng-thấp&quot;&gt;Phân rã thưa cộng hạng thấp&lt;/h2&gt;

&lt;p&gt;Cho ma trận \(M\in \mathbb{R}^{n\times m}\), bài toán phân rã thưa cộng hạng thấp được phát biểu như sau [&lt;a href=&quot;/contents/vi/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;CLMW09&lt;/a&gt;]:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{L,S} &amp;amp;&amp;amp;||L||_{tr}+\lambda||S||_{1}\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;L+S=M
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;mô-tả-bài-toán&quot;&gt;Mô tả bài toán&lt;/h2&gt;

&lt;p&gt;Mục tiêu là phân rã ma trận quan sát \(M\) thành tổng của một ma trận hạng thấp \(L\) và một ma trận thưa \(S\). Số hạng thứ nhất phạt chuẩn vết (trace norm / chuẩn hạt nhân) của \(L\), tức tổng các giá trị kỳ dị của \(L\); số hạng thứ hai dùng chuẩn \(l_{1}\) lên ma trận \(S\) để khuyến khích tính thưa, còn \(\lambda\) là tham số cân bằng hai thành phần. Cả chuẩn vết lẫn chuẩn \(l_{1}\) đều không trơn, và chuẩn vết nói chung khá tốn kém khi tối ưu. Tương tự bài toán ước lượng không gian con thưa, bài toán này có thể đưa về SDP để giải bằng phương pháp điểm trong nhưng khá nặng nề và chậm. Với ADMM, các bước cập nhật trở nên gọn hơn đáng kể:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
L^{+} &amp;amp;= S^{tr}_{\frac{1}{\rho}}(M-S+W)\\\\
S^{+} &amp;amp;= S^{l_{1}}_{\frac{\lambda}{\rho}}(M-L^{+}+W)\\\\
W^{+} &amp;amp;= W+M-L^{+}-S^{+}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(S^{tr}_{\frac{1}{\rho}}\) là toán tử co ngưỡng mềm theo ma trận (tác động lên các giá trị kỳ dị) và \(S^{l_{1}}_{\frac{\lambda}{\rho}}\) là co ngưỡng mềm theo từng phần tử.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/candes.png&quot; alt=&quot;[Hình 1] Ví dụ phân rã thưa cộng hạng thấp trên video camera giám sát [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Ví dụ phân rã thưa cộng hạng thấp trên video camera giám sát [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;ví-dụ-ứng-dụng&quot;&gt;Ví dụ ứng dụng&lt;/h2&gt;

&lt;p&gt;[Hình 1] minh họa ứng dụng của phân rã thưa cộng hạng thấp trong phân tích video từ camera giám sát. Khi camera quay một khu vực cố định trong thời gian dài, thành phần hạng thấp sẽ nắm bắt phần nền chung xuất hiện ở hầu hết các khung hình, trong khi thành phần thưa tách riêng các vật thể chuyển động hoặc chi tiết chỉ xuất hiện cục bộ ở một số khung hình. Trong [Hình 1], cột giữa tương ứng với thành phần hạng thấp (phông nền tĩnh) và cột phải tương ứng với thành phần thưa (các đối tượng chuyển động).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>21-03 Ví dụ: Hồi quy Lasso và hồi quy group lasso</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_03_Example_-_Lasso_regression_and_group_lasso_Regression/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_03_Example_:_Lasso_regression_and_group_lasso_Regression</id>
   <content type="html">&lt;p&gt;Trong thống kê hiện đại, &lt;strong&gt;Lasso&lt;/strong&gt; chọn từng đặc trưng đơn lẻ bằng phạt \(\ell_1\), còn &lt;strong&gt;Group Lasso&lt;/strong&gt; (Yuan &amp;amp; Lin, 2006) chọn hoặc loại bỏ &lt;strong&gt;cả một nhóm đặc trưng cùng lúc&lt;/strong&gt; (ví dụ toàn bộ các biến giả one-hot của một biến phân loại, hay cả một cụm gen cùng chức năng) bằng phạt tổng chuẩn Euclid \(\sum_{g} \sqrt{p_g}\|\beta_g\|_2\). Điều tuyệt vời khi giải cả hai bài toán này bằng ADMM là: &lt;strong&gt;bước giải hệ tuyến tính cho \(\beta\) giống hệt nhau&lt;/strong&gt;, ta chỉ cần đổi đúng một dòng ở bước cập nhật \(\alpha\) — từ ngưỡng mềm từng phần tử (elementwise soft-thresholding) sang &lt;strong&gt;ngưỡng mềm theo khối (block soft-thresholding)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-admm-cho-lasso-và-group-lasso&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của ADMM cho Lasso và Group Lasso&lt;/h2&gt;

&lt;p&gt;Để áp dụng linh hoạt ADMM cho các biến thể hồi quy có điều chuẩn thưa, hãy nắm chắc bốn điểm sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tách biến \(\beta = \alpha\) để cô lập cấu trúc không trơn:&lt;/strong&gt; Toàn bộ dữ liệu \((X, y)\) nằm gọn trong bước \(\beta\) (một bài toán bình phương tối thiểu có điều chuẩn Ridge \(\frac{\rho}{2}\|\beta - (\alpha - w)\|_2^2\) luôn khả nghịch), còn toàn bộ cấu trúc thưa nằm gọn trong bước \(\alpha\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý đảo ma trận Woodbury khi \(n \ll p\):&lt;/strong&gt; Nếu số đặc trưng \(p\) lớn hơn nhiều so với số mẫu \(n\), thay vì phân tích Cholesky ma trận \(p \times p\) là \(X^T X + \rho I\), ta dùng công thức Woodbury chỉ cần phân tích Cholesky ma trận nhỏ \(n \times n\) là \(I_n + \frac{1}{\rho} X X^T\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Toán tử ngưỡng mềm theo khối cho Group Lasso:&lt;/strong&gt; Với mỗi nhóm biến \(g\), \(\operatorname{prox}_{\tau\|\cdot\|_2}(v_g) = \left(1 - \frac{\tau}{\|v_g\|_2}\right)_+ v_g\). Nếu chuẩn nhóm \(\|v_g\|_2 \le \tau\), toàn bộ vector \(\alpha_g\) bị ép về \(0\) đồng thời; ngược lại, nó bị co tỉ lệ mà vẫn giữ nguyên hướng!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa tốc độ nhờ tái sử dụng phân tích Cholesky:&lt;/strong&gt; Giữ nguyên \(\rho\) (hoặc chỉ đổi \(\rho\) vài lần đầu) giúp chi phí mỗi vòng lặp sau đó chỉ còn \(O(p^2)\) (hoặc \(O(np)\) khi \(n \ll p\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-trực-tiếp-ngưỡng-mềm-lasso-và-ngưỡng-mềm-khối-group-lasso-trên-cùng-vector&quot;&gt;Giải thích: So sánh trực tiếp ngưỡng mềm Lasso và ngưỡng mềm khối Group Lasso trên cùng vector&lt;/h3&gt;

&lt;p&gt;Giả sử trong một bước cập nhật \(\alpha^{(k)}\) của ADMM, ta nhận được vector đầu vào \(v = \beta^{(k)} + w^{(k-1)} = (3, \; 4)^T\) (thuộc cùng một nhóm \(g\) kích thước 2) với ngưỡng hiệu dụng \(\tau = \lambda / \rho = 2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Nếu dùng Lasso (phạt $$\lambda(&lt;/td&gt;
          &lt;td&gt;v_1&lt;/td&gt;
          &lt;td&gt;+&lt;/td&gt;
          &lt;td&gt;v_2&lt;/td&gt;
          &lt;td&gt;)$$ — xử lý độc lập từng tọa độ):**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\alpha_1 = S_2(3) = \max(3 - 2, 0) = 1.0\).&lt;/li&gt;
      &lt;li&gt;\(\alpha_2 = S_2(4) = \max(4 - 2, 0) = 2.0\).&lt;/li&gt;
      &lt;li&gt;Kết quả: \(\alpha_{\text{Lasso}} = (1.0, \; 2.0)^T\). Nếu tăng ngưỡng lên \(\tau = 3.5\), tọa độ 1 bị triệt tiêu (\(0\)) nhưng tọa độ 2 vẫn sống sót (\(0.5\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nếu dùng Group Lasso (phạt \(\lambda\|v\|_2\) — xử lý cả nhóm):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tính chuẩn Euclid của cả nhóm: \(\|v\|_2 = \sqrt{3^2 + 4^2} = 5\).&lt;/li&gt;
      &lt;li&gt;Hệ số co chung: \(\left(1 - \frac{\tau}{\|v\|_2}\right)_+ = \left(1 - \frac{2}{5}\right)_+ = 0.6\).&lt;/li&gt;
      &lt;li&gt;Kết quả: \(\alpha_{\text{Group}} = 0.6 \times (3, \; 4)^T = (1.8, \; 2.4)^T\) (giữ nguyên tỉ lệ \(3:4\) giữa hai biến trong nhóm!).&lt;/li&gt;
      &lt;li&gt;Nếu tăng ngưỡng lên \(\tau = 5.5 &amp;gt; \|v\|_2 = 5\), hệ số co bằng \(0\) và &lt;strong&gt;toàn bộ nhóm&lt;/strong&gt; bị loại về \((0, 0)^T\) cùng một lúc!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;hồi-quy-lasso&quot;&gt;Hồi quy Lasso&lt;/h2&gt;

&lt;p&gt;Hãy xét cách giải bài toán hồi quy Lasso bằng ADMM.&lt;/p&gt;

&lt;p&gt;Cho \(y\in \mathbb{R}^{n}\) và \(X\in \mathbb{R}^{n\times p}\), bài toán Lasso được phát biểu là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\min_{\beta}\frac{1}{2}||y-X\beta||^{2}_{2}+\lambda||\beta||_{1}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ở các chương trước, chúng ta đã giải bài toán này bằng nhiều phương pháp khác nhau, bao gồm &lt;a href=&quot;/contents/vi/chapter09/09_01_proximal_gradient_descent/&quot;&gt;proximal gradient descent (ISTA)&lt;/a&gt;, &lt;a href=&quot;/contents/vi/chapter09/09_05_03_example_FISTA/&quot;&gt;accelerated proximal gradient descent (FISTA)&lt;/a&gt;, &lt;a href=&quot;/contents/vi/chapter15/chapter16/15_barrier_method/&quot;&gt;phương pháp rào (barrier method)&lt;/a&gt; và &lt;a href=&quot;/contents/vi/chapter17/17_primal_dual_interior_point_method/&quot;&gt;phương pháp điểm trong gốc–đối ngẫu&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Tương tự như khi xây dựng bài toán đối ngẫu, hiệu năng của ADMM phụ thuộc đáng kể vào cách chọn biến phụ. Trong các cách tách biến có thể dùng, dạng sau thường mang lại hiệu quả tính toán tốt nhất:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{\beta, \alpha} &amp;amp;&amp;amp;\frac{1}{2}||y-X\beta||^{2}_{2}+\lambda||\alpha||_{1}\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;\beta-\alpha= 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;các-bước-cập-nhật-admm&quot;&gt;Các bước cập nhật ADMM&lt;/h2&gt;

&lt;p&gt;Với cách tách biến trên, bước cập nhật \(\beta\) là bài toán cực tiểu hóa hàm bậc hai trơn nên có thể giải trực tiếp bằng điều kiện đạo hàm bằng không. Bước cập nhật \(\alpha\) tương tự bài toán ở &lt;a href=&quot;/contents/vi/chapter07/07_03_04_example_soft-thresholding/&quot;&gt;Chương 7 (07-03-04)&lt;/a&gt;, cho nghiệm đóng dưới dạng toán tử co ngưỡng mềm (soft-thresholding):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\beta^{+} &amp;amp;= \underset{\beta}{\operatorname{argmin}}\frac{1}{2}||y-X\beta||^{2}_{2}+\frac{\rho}{2}||\beta-\alpha+w||^{2}_{2}\\\\
&amp;amp;= (X^{T}X+\rho I)^{-1}(X^{T}y+\rho (\alpha-w))\\\\
\alpha^{+} &amp;amp;= \underset{\alpha}{\operatorname{argmin}}\lambda||\alpha||_{1}+\frac{\rho}{2}||\beta^{+}-\alpha+w||^{2}_{2}\\\\
&amp;amp;= S_{\frac{\lambda}{\rho}}(\beta^{+}+w)\\\\
w^{+} &amp;amp;=w+\beta^{+}-\alpha^{+}
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;các-tính-chất-chính&quot;&gt;Các tính chất chính&lt;/h2&gt;

&lt;p&gt;Thuật toán trên có những đặc điểm đáng chú ý sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ma trận \(X^{T}X+\rho I\) luôn khả nghịch với mọi \(X\) vì \(\rho&amp;gt;0\).&lt;/li&gt;
  &lt;li&gt;Nếu tính trước phân rã ma trận (thường là phân rã Cholesky) với chi phí \(O(p^{3})\) phép toán dấu phẩy động (flops), thì mỗi bước cập nhật \(\beta\) sau đó chỉ tốn \(O(p^{2})\) flops.&lt;/li&gt;
  &lt;li&gt;Bước cập nhật \(\alpha\) áp dụng toán tử co ngưỡng mềm \(S_{t}\) đã trình bày ở &lt;a href=&quot;/contents/vi/chapter07/07_03_04_example_soft-thresholding/&quot;&gt;07-03-04&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Về trực giác, mỗi vòng lặp ADMM gần như lặp lại việc giải một bài toán hồi quy ridge rồi áp dụng co ngưỡng mềm lên các hệ số.&lt;/li&gt;
  &lt;li&gt;Các giá trị \(\rho\) khác nhau dẫn đến tốc độ hội tụ khác nhau.&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/lasso.png&quot; alt=&quot;[Hình 1] So sánh các thuật toán cho hồi quy lasso (50 trường hợp với n = 100, p = 20) [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] So sánh các thuật toán cho hồi quy lasso (50 trường hợp với n = 100, p = 20) [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;so-sánh-hiệu-năng&quot;&gt;So sánh hiệu năng&lt;/h2&gt;

&lt;p&gt;[Hình 1] so sánh đường hội tụ của nhiều thuật toán trên bài toán hồi quy Lasso, trong đó các thuật toán đều có độ phức tạp mỗi vòng lặp tương đương nhau. Trên đồ thị, ADMM đạt tốc độ hội tụ gần tương đương với proximal gradient descent (đường đen). Accelerated proximal gradient descent (đường đỏ) xuất hiện các dao động dạng “gợn Nesterov” nhưng hội tụ nhanh hơn một chút. Ngoài ra, tốc độ hội tụ của ADMM thay đổi rõ rệt tùy theo giá trị \(\rho\). Phương pháp coordinate descent (đường xanh lá), sẽ được trình bày ở &lt;a href=&quot;/contents/vi/chapter23/23_Coordinate_Descent/&quot;&gt;Chương 23&lt;/a&gt;, khai thác sâu hơn cấu trúc bài toán nên hội tụ nhanh hơn các phương pháp còn lại, dù đòi hỏi các điều kiện áp dụng riêng.&lt;/p&gt;

&lt;p&gt;Nếu đặt \(\rho\) quá lớn, trọng số tương đối của hàm mục tiêu \(f+g\) giảm đi; ngược lại, nếu \(\rho\) quá nhỏ, tốc độ tiến về miền khả thi sẽ chậm. Do đó, việc chọn \(\rho\) phù hợp đóng vai trò quan trọng. Chi tiết hơn có thể xem trong [BPCPE] tại &lt;a href=&quot;/contents/vi/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;danh mục bài báo tham khảo của Chương 21&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;hồi-quy-group-lasso&quot;&gt;Hồi quy Group Lasso&lt;/h2&gt;

&lt;p&gt;Tương tự, ta áp dụng ADMM cho bài toán hồi quy Group Lasso với \(y\in \mathbb{R}^{n}\) và \(X\in \mathbb{R}^{n \times p}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{\beta}\frac{1}{2}||y-X\beta||^{2}_{2}+\lambda\sum^{G}_{g=1} c_{g}||\beta_{(g)}||_{2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tách biến tương tự như trường hợp Lasso, ta viết lại bài toán thành:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{\beta,\alpha} &amp;amp;&amp;amp;\frac{1}{2}||y-X\beta||^{2}_{2}+\lambda\sum^{G}_{g=1} c_{g}||\alpha_{(g)}||_{2}\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;\beta-\alpha=0.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Các bước cập nhật ADMM thu được là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\beta^{+} &amp;amp;= (X^{T}X+\rho I)^{-1}(X^{T}y+\rho (\alpha-w))\\\\
\alpha^{+}_{(g)} &amp;amp;= R_{c_{g}\frac{\lambda}{\rho}}(\beta^{+}_{(g)}+w_{(g)})\qquad g = 1,\ldots,G\\\\
w^{+} &amp;amp;=w+\beta^{+}-\alpha^{+}
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;các-tính-chất-của-admm-cho-group-lasso&quot;&gt;Các tính chất của ADMM cho Group Lasso&lt;/h2&gt;

&lt;p&gt;Thuật toán này có các đặc điểm sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ma trận \(X^{T}X+\rho I\) luôn khả nghịch với mọi \(X\) vì \(\rho&amp;gt;0\).&lt;/li&gt;
  &lt;li&gt;Nếu tính trước phân rã Cholesky với chi phí \(O(p^{3})\) flops, mỗi bước cập nhật \(\beta\) chỉ tốn \(O(p^{2})\) flops.&lt;/li&gt;
  &lt;li&gt;Bước cập nhật \(\alpha\) sử dụng toán tử co ngưỡng mềm theo nhóm (group soft-thresholding) \(R_{t}\), định nghĩa như sau:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\begin{align}
R_{t}(x) = \left(1-\frac{t}{\lVert x \rVert_{2}}\right)_{+}x
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;admm-cho-lasso-video&quot;&gt;ADMM cho lasso (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/admm-lasso_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;ADMM thực hiện luân phiên một bước cập nhật \(x\) kiểu hồi quy ridge, một bước cập nhật \(z\) bằng co ngưỡng mềm, và một bước cập nhật biến đối ngẫu \(u\) nhằm kéo \(x\) và \(z\) tiến lại gần nhau.&lt;/p&gt;

&lt;p&gt;Video dùng ký hiệu chung của ADMM: \(x\) ứng với \(\beta\), \(z\) ứng với \(\alpha\), \(u\) ứng với \(w\) (biến đối ngẫu đã chia cho \(\rho\)); ma trận \(X\) và vectơ \(y\) của bài được viết là \(A\) và \(b\). Trong video, \(y\) là nhân tử Lagrange chứ không phải vectơ đáp ứng.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-admm-trên-bài-toán-lasso&quot;&gt;Tự tay thử: ADMM trên bài toán Lasso&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;admm&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>21-02 Mối liên hệ với toán tử proximal</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_02_Connection_to_proximal_operators/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_02_Connection_to_proximal_operators</id>
   <content type="html">&lt;p&gt;Ở Chương 9, ta giải bài toán tổng hai hàm \(\min_x f(x) + g(x)\) bằng &lt;strong&gt;proximal gradient descent&lt;/strong&gt;, nhưng phương pháp đó đòi hỏi ít nhất một trong hai hàm (ví dụ \(f\)) phải khả vi trơn. Điều gì xảy ra nếu &lt;strong&gt;cả \(f\) và \(g\) đều không khả vi&lt;/strong&gt; (chẳng hạn \(f(x) = \|Ax - b\|_1\) và \(g(x) = \lambda\|x\|_1\), hoặc tổng hai hàm chỉ thị tập lồi)? Chỉ cần tách biến thành \(\min f(x) + g(z) \text{ s.t. } x = z\), ADMM dạng chuẩn hóa lập tức biến thành &lt;strong&gt;một thuật toán hoàn toàn đối xứng chỉ dùng hai toán tử proximal&lt;/strong&gt; \(\operatorname{prox}_{f, 1/\rho}\) và \(\operatorname{prox}_{g, 1/\rho}\) — mà không cần bất kỳ đạo hàm nào!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-điểm-nối-sâu-sắc-giữa-admm-và-toán-tử-proximal&quot;&gt;Kiến thức cần nhớ: Ba điểm nối sâu sắc giữa ADMM và toán tử proximal&lt;/h2&gt;

&lt;p&gt;Để nắm vững sức mạnh của cách viết proximal ADMM trong bài học này, hãy ghi nhớ ba mối liên hệ cốt lõi:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối xứng hoàn toàn giữa \(f\) và \(g\):&lt;/strong&gt; Bước cập nhật \(x^{(k)} = \operatorname{prox}_{f, 1/\rho}(z^{(k-1)} - w^{(k-1)})\) và \(z^{(k)} = \operatorname{prox}_{g, 1/\rho}(x^{(k)} + w^{(k-1)})\) cho phép giải tổng của &lt;strong&gt;hai hàm đều không trơn&lt;/strong&gt;, miễn là mỗi hàm có toán tử proximal dễ tính!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tương đương với thuật toán Douglas–Rachford:&lt;/strong&gt; Biến đổi đại số ngắn cho thấy ADMM áp dụng trên bài toán tách biến \(x = z\) thực chất tương đương với phương pháp tách toán tử Douglas–Rachford nổi tiếng trong giải tích lồi (và nếu áp dụng ADMM trên bài toán đối ngẫu thì tương đương với Douglas–Rachford trên bài toán gốc).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa của tham số \(1/\rho\):&lt;/strong&gt; Trong \(\operatorname{prox}_{f, 1/\rho}(v) = \arg\min_x \left(f(x) + \frac{\rho}{2}\|x - v\|_2^2\right)\), tham số \(1/\rho\) đóng vai trò hệt như bước học \(t\) trong proximal gradient: \(\rho\) lớn giữ \(x^{(k)}\) bám sát \(z^{(k-1)} - w^{(k-1)}\), còn \(\rho\) nhỏ cho phép \(x^{(k)}\) tiến sâu hơn về cực tiểu riêng của \(f\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-3-vòng-lặp-proximal-admm-và-thấy-vì-sao-cả-hai-phần-dư-đều-quan-trọng&quot;&gt;Giải thích: Chạy tay 3 vòng lặp Proximal ADMM và thấy vì sao cả hai phần dư đều quan trọng&lt;/h3&gt;

&lt;p&gt;Xét bài toán \(\min_x \underbrace{\frac{1}{2}(x - 4)^2}_{f(x)} + \underbrace{|x|}_{g(x)}\) (nghiệm chính xác là \(x^\star = 3\) vì \((3 - 4) + 1 = 0\)). Chọn \(\rho = 1\) (nên \(1/\rho = 1\)), ta tính sẵn hai toán tử proximal:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\operatorname{prox}_{f, 1}(v) = \arg\min_x \left(\frac{1}{2}(x - 4)^2 + \frac{1}{2}(x - v)^2\right) = \frac{v + 4}{2}\).&lt;/li&gt;
  &lt;li&gt;\(\operatorname{prox}_{g, 1}(v) = S_1(v)\) (ngưỡng mềm với ngưỡng \(1\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Khởi tạo \(z^{(0)} = 0, w^{(0)} = 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vòng 1:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = \operatorname{prox}_{f, 1}(0 - 0) = \frac{0 + 4}{2} = 2.0\).&lt;/li&gt;
      &lt;li&gt;\(z^{(1)} = S_1(2.0 + 0) = 1.0\).&lt;/li&gt;
      &lt;li&gt;\(w^{(1)} = 0 + 2.0 - 1.0 = 1.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng 2:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(2)} = \operatorname{prox}_{f, 1}(1.0 - 1.0) = \frac{0 + 4}{2} = 2.0\).&lt;/li&gt;
      &lt;li&gt;\(z^{(2)} = S_1(2.0 + 1.0) = S_1(3.0) = 2.0\).&lt;/li&gt;
      &lt;li&gt;\(w^{(2)} = 1.0 + 2.0 - 2.0 = 1.0\).
&lt;em&gt;(Lưu ý cực thú vị: tại Vòng 2, phần dư gốc \(r^{(2)} = x^{(2)} - z^{(2)} = 0\) đã bằng 0, nhưng phần dư đối ngẫu \(s^{(2)} = z^{(2)} - z^{(1)} = 1.0 \ne 0\) — nên thuật toán &lt;strong&gt;không&lt;/strong&gt; dừng tại \(2.0\) mà tiếp tục đi!)&lt;/em&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng 3:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(3)} = \operatorname{prox}_{f, 1}(2.0 - 1.0) = \frac{1.0 + 4}{2} = 2.5\).&lt;/li&gt;
      &lt;li&gt;\(z^{(3)} = S_1(2.5 + 1.0) = S_1(3.5) = 2.5\).&lt;/li&gt;
      &lt;li&gt;\(w^{(3)} = 1.0 + 2.5 - 2.5 = 1.0\).
Cứ thế ở vòng \(k \ge 2\), \(x^{(k)} = z^{(k)} = 3 - 2^{2-k} \to 3 = x^\star\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;mối-liên-hệ-với-toán-tử-proximal&quot;&gt;Mối liên hệ với toán tử proximal&lt;/h1&gt;

&lt;p&gt;Xét bài toán tối ưu một biến với hàm mục tiêu là tổng của hai hàm:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\min_{x} f(x)+g(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ta có thể viết lại bài toán này bằng cách tách biến và thêm một ràng buộc đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\min_{x, z} f(x)+g(z) \qquad \text{subject to  }x=z
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;các-bước-admm-dưới-dạng-proximal&quot;&gt;Các bước ADMM dưới dạng proximal&lt;/h2&gt;

&lt;p&gt;Áp dụng ADMM dạng chuẩn hóa cho bài toán trên, ta thu được các bước cập nhật:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;x^{(k)} = {\operatorname{prox}}_{f,\frac{1}{\rho}}(z^{(k-1)}-w^{(k-1)})\\\\
&amp;amp;z^{(k)} = {\operatorname{prox}}_{g,\frac{1}{\rho}}(x^{(k)}+w^{(k-1)})\\\\
&amp;amp;w^{(k)}=w^{(k-1)}+x^{(k)}-z^{(k)}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\operatorname{prox}_{f,\frac{1}{\rho}}\) và \(\operatorname{prox}_{g,\frac{1}{\rho}}\) lần lượt là các toán tử proximal của \(f\) và \(g\) với tham số \(\frac{1}{\rho}\).&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa-toán-tử-proximal&quot;&gt;Định nghĩa toán tử proximal&lt;/h2&gt;

&lt;p&gt;Nhắc lại rằng với một hàm lồi \(f\), &lt;a href=&quot;/contents/vi/chapter19/19_01_01_Reminder-_proximal_gradient_descent/&quot;&gt;toán tử proximal&lt;/a&gt; được định nghĩa là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
{\operatorname{prox}}_{f, \lambda}(v) = \underset{x}{\operatorname{argmin}}\left(f(x)+\frac{1}{2\lambda}||x-v||_{2}^{2}\right). 
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;suy-diễn-các-bước-cập-nhật-proximal&quot;&gt;Suy diễn các bước cập nhật proximal&lt;/h2&gt;

&lt;p&gt;Gọi \(x^{+}, z^{+}, w^{+}\) là các giá trị mới của \(x, z, w\) sau một vòng lặp. Ta suy ra biểu thức proximal của từng bước như sau:&lt;/p&gt;

&lt;h3 id=&quot;cập-nhật-cho-x&quot;&gt;Cập nhật cho \(x\):&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
x^{+}&amp;amp; = \underset{x}{\operatorname{argmin}}f(x)+\frac{\rho}{2}||x-z+w||^{2}_{2}\\\\
&amp;amp; =\underset{x}{\operatorname{argmin}}\frac{1}{2\cdot\frac{1}{\rho}}||(z-w)-x||^{2}_{2}+f(x)\\\\
&amp;amp; ={\operatorname{prox}}_{f,\frac{1}{\rho}}(z-w)
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;cập-nhật-cho-z&quot;&gt;Cập nhật cho \(z\):&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
z^{+}&amp;amp; = \underset{z}{\operatorname{argmin}}g(z)+\frac{\rho}{2}||x^{+}-z+w||^{2}_{2}\\\\
&amp;amp; =\underset{z}{\operatorname{argmin}}\frac{1}{2\cdot\frac{1}{\rho}}||(x^{+}+w)-z||^{2}_{2}+g(z)\\\\
&amp;amp; ={\operatorname{prox}}_{g,\frac{1}{\rho}}(x^{+}+w)
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;nhận-xét-chính&quot;&gt;Nhận xét chính&lt;/h2&gt;

&lt;p&gt;Trong bài toán ADMM tổng quát, ràng buộc có dạng \(Ax+Bz = c\), còn ở đây ràng buộc đơn giản là \(x=z\). Khi quan hệ tuyến tính giữa \(x\) và \(z\) là phép đồng nhất, hai bước cập nhật biến gốc của ADMM trở thành hai phép tính toán tử proximal liên tiếp trên \(f\) và \(g\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>21-01 Last time - Dual method, Augmented Lagrangian method, ADMM, ADMM in scaled form</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_01_Last_time_Dual_method,_Augmented_Lagrangian_method,_ADMM,_ADMM_in_scaled_form/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_01_Last_time_Dual_method,_Augmented_Lagrangian_method,_ADMM,_ADMM_in_scaled_form</id>
   <content type="html">&lt;p&gt;Trước khi bước vào các ứng dụng thực chiến của Chương 21, bài học này tổng hợp lại trọn vẹn chuỗi tiến hóa bốn bước từ Chương 20 trên cùng một trang giấy: &lt;strong&gt;Phương pháp đối ngẫu&lt;/strong&gt; \(\to\) &lt;strong&gt;Hàm Lagrange tăng cường&lt;/strong&gt; \(\to\) &lt;strong&gt;ADMM chuẩn&lt;/strong&gt; \(\to\) &lt;strong&gt;ADMM dạng chuẩn hóa (scaled form)&lt;/strong&gt;. Đặt bốn công thức cạnh nhau giúp bạn nhìn rõ từng mắt xích: mỗi thuật toán ra đời chính để khắc phục đúng một điểm yếu chí mạng của thuật toán đứng ngay trước nó.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-chuỗi-tiến-hóa-4-thế-hệ-của-phương-pháp-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Chuỗi tiến hóa 4 thế hệ của phương pháp đối ngẫu&lt;/h2&gt;

&lt;p&gt;Hãy đối chiếu nhanh bốn phương pháp để thấy rõ ranh giới sử dụng của từng thuật toán:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dual Ascent / Dual Decomposition:&lt;/strong&gt; Dễ phân rã song song khi hàm mục tiêu tách biến, nhưng đòi hỏi giả thiết mạnh (như \(f\) lồi mạnh) để hàm đối ngẫu trơn và đảm bảo hội tụ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Augmented Lagrangian (Method of Multipliers):&lt;/strong&gt; Thêm phạt bậc hai \(\frac{\rho}{2}\|Ax - b\|_2^2\) để hội tụ vững chắc dưới điều kiện nhẹ và tự động có bước học \(t = \rho\), nhưng làm mất tính phân rã song song.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ADMM dạng chuẩn (Unscaled ADMM):&lt;/strong&gt; Chia biến thành hai khối \(Ax + Bz = c\) và cập nhật luân phiên \(x \to z \to u\), khôi phục tính phân rã đồng thời giữ trọn độ bền hội tụ với mọi \(\rho &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ADMM dạng chuẩn hóa (Scaled ADMM):&lt;/strong&gt; Đặt \(w = u / \rho\) để gộp số hạng tuyến tính và bình phương vào duy nhất \(\frac{\rho}{2}\|Ax + Bz - c + w\|_2^2\), giúp công thức cực ngắn gọn và dễ lập trình.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-đối-chiếu-bằng-số-1-bước-admm-chuẩn-và-admm-chuẩn-hóa-trên-cùng-bài-toán&quot;&gt;Giải thích: Đối chiếu bằng số 1 bước ADMM chuẩn và ADMM chuẩn hóa trên cùng bài toán&lt;/h3&gt;

&lt;p&gt;Xét bài toán \(\min_{x, z} \frac{1}{2}x^2 + \frac{1}{2}(z - 2)^2\) với ràng buộc \(x - z = 0\) (nghiệm chính xác \(x^\star = z^\star = 1\)). Chọn \(\rho = 2\), khởi tạo \(z^{(0)} = 0\) và \(u^{(0)} = 0\) (nên \(w^{(0)} = u^{(0)} / 2 = 0\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chạy 1 bước ADMM dạng chuẩn (unscaled):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bước \(x\): \(x^{(1)} = \arg\min_x \left(\frac{1}{2}x^2 + 0 + \frac{2}{2}(x - 0)^2\right) = \arg\min_x \frac{3}{2}x^2 = 0\).&lt;/li&gt;
      &lt;li&gt;Bước \(z\): \(z^{(1)} = \arg\min_z \left(\frac{1}{2}(z - 2)^2 + 0 + \frac{2}{2}(0 - z)^2\right) \implies (z - 2) + 2z = 0 \implies z^{(1)} = \frac{2}{3}\).&lt;/li&gt;
      &lt;li&gt;Bước đối ngẫu: \(u^{(1)} = 0 + 2\left(0 - \frac{2}{3}\right) = -\frac{4}{3}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chạy 1 bước ADMM dạng chuẩn hóa (scaled, \(w = u/\rho\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bước \(x\): \(x^{(1)} = \arg\min_x \left(\frac{1}{2}x^2 + \frac{2}{2}(x - 0 + 0)^2\right) = 0\).&lt;/li&gt;
      &lt;li&gt;Bước \(z\): \(z^{(1)} = \arg\min_z \left(\frac{1}{2}(z - 2)^2 + \frac{2}{2}(0 - z + 0)^2\right) = \frac{2}{3}\).&lt;/li&gt;
      &lt;li&gt;Bước đối ngẫu: \(w^{(1)} = 0 + \left(0 - \frac{2}{3}\right) = -\frac{2}{3}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng tương đương tuyệt đối:&lt;/strong&gt; Ta có \(w^{(1)} = -\frac{2}{3} = \frac{-4/3}{2} = \frac{u^{(1)}}{\rho}\) và cả \(x^{(1)}, z^{(1)}\) trùng khớp hoàn toàn!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Ở Chương 20, chúng ta đã tìm hiểu các phương pháp đối ngẫu và ADMM. Trước khi đi vào các ứng dụng cụ thể của ADMM, hãy ôn lại phương pháp đối ngẫu, phương pháp Lagrangian tăng cường (augmented Lagrangian), ADMM và ADMM ở dạng chuẩn hóa (scaled form).&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-đối-ngẫu&quot;&gt;Phương pháp đối ngẫu&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối ưu sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\\\
&amp;amp;\text{ subject to } &amp;amp;&amp;amp;Ax = b
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Giả sử \(f\) là hàm lồi chặt và đóng. Hàm Lagrange của bài toán là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
L(x,u) = f(x)+u^{T}(Ax-b)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán đối ngẫu tương ứng là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{equation}
\max_u -f^{\ast}(-A^T u) - b^T u
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(u\) là biến đối ngẫu.&lt;/p&gt;

&lt;p&gt;Phương pháp tăng gradient đối ngẫu (dual gradient ascent) lặp lại các bước cập nhật sau với \(k=1,2,3,\ldots\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x^{(k)}&amp;amp;=\underset{x}{\operatorname{argmin}} L(x,u^{(k-1)}) \\\\
u^{(k)}&amp;amp;= u^{(k-1)} +t_{k}(Ax^{(k)}-b)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây \(t_{k}\) là kích thước bước tại vòng lặp thứ \(k\).&lt;/p&gt;

&lt;p&gt;Trong phương pháp này, biến gốc \(x\) được cập nhật tại điểm cực tiểu hóa hàm Lagrange ứng với biến đối ngẫu \(u^{(k-1)}\) từ bước trước, còn biến đối ngẫu \(u\) được cập nhật theo bước tăng gradient dọc theo hướng \(Ax-b\).&lt;/p&gt;

&lt;p&gt;Ưu điểm của phương pháp đối ngẫu là khi \(f\) phân rã được thành \(B\) thành phần độc lập, biến \(x\) có thể chia thành \(B\) khối \((x =(x_{1}, \ldots, x_{B})\in \mathbb{R}^{n}, \text{ với } x_{i}\in \mathbb{R}^{n_{i}})\) và ma trận \(A\) chia thành \(B\) khối con tương ứng \((A = [A_{1}, \ldots, A_{B}] \text{ với } A_{i} \in \mathbb{R}^{m \times n_{i}})\), nhờ đó dễ dàng song song hóa và mở rộng quy mô. Nhược điểm là điều kiện đảm bảo hội tụ khá khắt khe: để bảo đảm tính khả thi của bài toán gốc, \(f\) phải là hàm lồi mạnh &lt;a href=&quot;/contents/vi/chapter20/20_01_01_Convergence_Analysis/&quot;&gt;[20-01-01]&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-lagrangian-tăng-cường&quot;&gt;Phương pháp Lagrangian tăng cường&lt;/h2&gt;

&lt;p&gt;Phương pháp Lagrangian tăng cường (augmented Lagrangian), còn gọi là phương pháp nhân tử (method of multipliers), bổ sung thêm một số hạng phạt bậc hai vào hàm mục tiêu. Khi quá trình lặp tiến triển, các điều kiện KKT dần được thỏa mãn. So với phương pháp đối ngẫu, phương pháp này nới lỏng điều kiện hội tụ (không đòi hỏi \(f\) lồi mạnh), nhưng đổi lại bài toán không còn tách rời được thành các khối độc lập. Bài toán gốc được viết lại như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x)+\frac{\rho}{2}||Ax-b||_{2}^{2}&amp;amp;\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;Ax=b
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;với \(\rho&amp;gt;0\). Hàm Lagrange tăng cường của bài toán là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
L_{\rho}(x,u)=f(x)+u^{T}(Ax-b)+\frac{\rho}{2}||Ax-b||_{2}^{2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Thuật toán tăng gradient đối ngẫu lặp lại các bước sau (\(k=1,2,3,\ldots\)):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x^{(k)}&amp;amp;=\underset{x}{\operatorname{argmin}} L_{\rho}(x,u^{(k-1)}) \\\\
u^{(k)}&amp;amp;= u^{(k-1)} +\rho(Ax^{(k)}-b)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Như đã nêu, ưu điểm của phương pháp này là điều kiện hội tụ nhẹ hơn so với phương pháp đối ngẫu, còn nhược điểm là số hạng phạt bậc hai ghép chéo các biến làm mất tính phân rã.&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-hướng-luân-phiên-của-các-nhân-tử-admm&quot;&gt;Phương pháp hướng luân phiên của các nhân tử (ADMM)&lt;/h2&gt;

&lt;p&gt;ADMM kết hợp ưu điểm của cả phương pháp đối ngẫu lẫn phương pháp Lagrangian tăng cường. Xét bài toán có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x, z} f(x)+g(z) \qquad \text{subject to  }Ax+Bz=c
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Với \(\rho&amp;gt;0\), hàm Lagrangian tăng cường được định nghĩa là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;L_{\rho} (x,z,u) = f(x)+g(z)+u^{T}(Ax+Bz-c)+\frac{\rho}{2}||Ax+Bz-c||_{2}^{2}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Các biến được cập nhật luân phiên qua từng vòng lặp:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{for k = 1,2,3,...}\\\\
&amp;amp;x^{(k)}=\underset{x}{\operatorname{argmin}} L_{\rho}(x,z^{(k-1)},u^{(k-1)})\\\\
&amp;amp;z^{(k)}=\underset{z}{\operatorname{argmin}} L_{\rho}(x^{(k)},z,u^{(k-1)})\\\\
&amp;amp;u^{(k)}=u^{(k-1)}+\rho(Ax^{(k)}+Bz^{(k)}-c)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong ADMM, hai biến gốc \(x\) và \(z\) không được cập nhật đồng thời mà lần lượt theo thứ tự, luôn sử dụng giá trị mới nhất của biến còn lại. Cụ thể, tại vòng lặp \(k\), bước cập nhật \(z\) sử dụng \(x^{(k)}\) thay vì \(x^{(k-1)}\), và bước cập nhật \(u\) dùng cả \(x^{(k)}\) lẫn \(z^{(k)}\) vừa tính được.&lt;/p&gt;

&lt;h2 id=&quot;hội-tụ-của-admm&quot;&gt;Hội tụ của ADMM&lt;/h2&gt;

&lt;p&gt;Không cần giả sử hai ma trận ràng buộc \(A\) và \(B\) có hạng đầy đủ, và chỉ với các giả thiết tương đối nhẹ trên \(f\) và \(g\), ADMM đảm bảo các tính chất sau với mọi \(\rho &amp;gt; 0\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hội tụ phần dư: \(r^{(k)} = A x^{(k)} + B z^{(k)} - c \to 0\) khi \(k \to \infty\), nghĩa là các điểm lặp gốc tiến dần về miền khả thi.&lt;/li&gt;
  &lt;li&gt;Hội tụ hàm mục tiêu: \(f(x^{(k)}) + g(z^{(k)}) \to f^{\star} + g^{\star}\), trong đó \(f^{\star} + g^{\star}\) là giá trị tối ưu của bài toán gốc.&lt;/li&gt;
  &lt;li&gt;Hội tụ biến đối ngẫu: \(u^{(k)} \to u^{\star}\), trong đó \(u^{\star}\) là một nghiệm đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tốc độ hội tụ trong trường hợp tổng quát vẫn là chủ đề được nghiên cứu tích cực. Các tài liệu tham khảo chi tiết về hội tụ được liệt kê ở &lt;a href=&quot;/contents/vi/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;phần giới thiệu Chương 21&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;admm-dạng-chuẩn-hóa-scaled-form&quot;&gt;ADMM dạng chuẩn hóa (scaled form)&lt;/h2&gt;

&lt;p&gt;ADMM có thể viết gọn hơn dưới dạng chuẩn hóa bằng cách đặt biến đối ngẫu có tỉ lệ \(w=u/\rho\). Khi đó, các bước cập nhật trở thành:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;x^{(k)} = \underset{x}{\operatorname{argmin}} f(x) + \frac{\rho}{2} ||Ax + Bz^{(k-1)} - c + w^{(k-1)} ||_2^2 \\\\
&amp;amp;z^{(k)} = \underset{z}{\operatorname{argmin}} g(z) + \frac{\rho}{2} || Ax^{(k)} + Bz - c + w^{(k-1)} ||_2^2  \\\\
&amp;amp;w^{(k)} = w^{(k-1)} + Ax^{(k)} + Bz^{(k)} - c 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây \(w^{(k)}\) chính là tổng tích lũy của các phần dư tính đến vòng lặp \(k\), và có thể viết tường minh là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
w^{(k)} = w^{(0)} + \sum_{i=1}^k (Ax^{(i)} + Bz^{(i)} - c) 
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>21 Phương pháp hướng luân phiên của các nhân tử (ADMM)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter21/21_00_Alternating_Direction_Method_of_Multipliers</id>
   <content type="html">&lt;p&gt;Nếu Chương 20 giống như việc tháo lắp để hiểu nguyên lý động cơ của ADMM, thì Chương 21 là lúc ta đưa cỗ máy đó ra đường đua thực tế! Từ hồi quy Lasso và Group Lasso trong thống kê nhiều chiều, phân rã ma trận thưa cộng hạng thấp (Robust PCA) trong thị giác máy tính, cho tới tối ưu đồng thuận phân tán trên cụm máy chủ và tái tham số hóa bài toán con cho Fused Lasso 2D — bạn sẽ thấy một bài học sâu sắc của nghệ thuật tối ưu hóa: &lt;strong&gt;cùng một bài toán, chỉ cần khéo chọn cách tách biến cho ADMM, tốc độ hội tụ có thể tăng vọt hàng chục lần!&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-chủ-đề-ứng-dụng-trọng-tâm-của-chương-21&quot;&gt;Kiến thức cần nhớ: Bốn chủ đề ứng dụng trọng tâm của Chương 21&lt;/h2&gt;

&lt;p&gt;Để định hướng rõ mạch nội dung xuyên suốt Chương 21, hãy nhìn bốn mảng ứng dụng tiêu biểu của ADMM:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;ADMM dưới góc nhìn toán tử proximal (21-01 &amp;amp; 21-02):&lt;/strong&gt; Khi ràng buộc tách biến có dạng \(x = z\), ADMM trở thành một vòng lặp gọi luân phiên hai toán tử \(\operatorname{prox}_{f, 1/\rho}\) và \(\operatorname{prox}_{g, 1/\rho}\), gắn chặt với thuật toán tách Douglas–Rachford kinh điển.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thống kê nhiều chiều &amp;amp; Ma trận có cấu trúc (21-03 &amp;amp; 21-04):&lt;/strong&gt; Tách hàm mất mát bậc hai ra khỏi chuẩn \(\ell_1\) (Lasso), chuẩn \(\ell_1/\ell_2\) (Group Lasso), hoặc chuẩn hạt nhân (Nuclear Norm / Robust PCA) biến những bài toán khó nhằn thành chuỗi bước cực đơn giản: một phép giải hệ tuyến tính (phân tích Cholesky đúng một lần!) kết hợp ngưỡng mềm / ngưỡng giá trị kỳ dị.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu phân tán đồng thuận (Consensus ADMM, 21-05):&lt;/strong&gt; Nhân bản biến cục bộ \(x_i = x\) để mỗi nút dữ liệu giải bài toán con riêng hoàn toàn song song, rồi nút trung tâm chỉ việc lấy trung bình cộng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghệ thuật tham số hóa bài toán con (21-06):&lt;/strong&gt; Thay vì tách biến theo kiểu máy móc, thiết kế các ràng buộc tách biến sao cho bài toán con giải được trong thời gian tuyến tính \(O(n)\) và các khối biến ít tương quan hơn giúp ADMM hội tụ nhanh vượt bậc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bí-quyết-phân-tích-cholesky-một-lần-giúp-admm-giải-lasso-cực-nhanh&quot;&gt;Giải thích: Bí quyết “phân tích Cholesky một lần” giúp ADMM giải Lasso cực nhanh&lt;/h3&gt;

&lt;p&gt;Xét bài toán Lasso \(\min_\beta \frac{1}{2}\|y - X\beta\|_2^2 + \lambda\|\beta\|_1\) với \(X \in \mathbb{R}^{n \times p}\). Nếu tách biến \(\beta = \alpha\) và chạy ADMM dạng có tỉ lệ với tham số \(\rho &amp;gt; 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước cập nhật \(\beta^{(k)}\) (hệ tuyến tính đối xứng xác định dương):&lt;/strong&gt;
\(\beta^{(k)} = (X^T X + \rho I)^{-1}\left(X^T y + \rho(\alpha^{(k-1)} - w^{(k-1)})\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước cập nhật \(\alpha^{(k)}\) (ngưỡng mềm từng phần tử):&lt;/strong&gt;
\(\alpha^{(k)} = S_{\lambda/\rho}\left(\beta^{(k)} + w^{(k-1)}\right), \qquad w^{(k)} = w^{(k-1)} + \beta^{(k)} - \alpha^{(k)}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm ăn tiền về hiệu năng tính toán (giả sử \(p = 1{,}000\) và chạy \(200\) vòng lặp):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ma trận \(M = X^T X + \rho I\) &lt;strong&gt;không hề thay đổi&lt;/strong&gt; qua suốt \(200\) vòng lặp (khi giữ cố định \(\rho\))!&lt;/li&gt;
      &lt;li&gt;Ta chỉ cần phân tích Cholesky \(M = L L^T\) &lt;strong&gt;duy nhất một lần&lt;/strong&gt; trước vòng lặp (tốn \(\frac{1}{3}p^3 \approx 3.3 \times 10^8\) phép toán).&lt;/li&gt;
      &lt;li&gt;Ở cả \(200\) vòng lặp sau đó, mỗi bước chỉ giải hai hệ tam giác tốn \(2p^2 = 2 \times 10^6\) phép toán — &lt;strong&gt;rẻ hơn 165 lần&lt;/strong&gt; so với việc giải lại hệ tuyến tính từ đầu ở mỗi bước!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Chương này đi sâu hơn vào phương pháp ADMM đã được giới thiệu ở &lt;a href=&quot;/contents/vi/chapter20/20_00_Dual_Methods/&quot;&gt;Chương 20&lt;/a&gt;. Về mặt khái niệm cơ bản, nội dung không mở rộng thêm nhiều so với Chương 20 mà chủ yếu tập trung vào các bài toán và trường hợp ứng dụng cụ thể.&lt;/p&gt;

&lt;h3 id=&quot;các-bài-báo-tham-khảo&quot;&gt;Các bài báo tham khảo&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Boyd, Stephen, et al. [BPCPE11] “Distributed optimization and statistical learning via the alternating direction method of multipliers.” Foundations and Trends® in Machine learning 3.1 (2011): 1-122.&lt;/li&gt;
  &lt;li&gt;Hong, Mingyi, and Zhi-Quan Luo. [HL12] “On the linear convergence of the alternating direction method of multipliers.” Mathematical Programming 162.1-2 (2017): 165-199.&lt;/li&gt;
  &lt;li&gt;Deng, Wei, and Wotao Yin. [DY16] “On the global and linear convergence of the generalized alternating direction method of multipliers.” Journal of Scientific Computing 66.3 (2016): 889-916.&lt;/li&gt;
  &lt;li&gt;Iutzeler, Franck, et al. [IBCH14] “Linear convergence rate for distributed optimization with the alternating direction method of multipliers.” 53rd IEEE Conference on Decision and Control. IEEE, 2014.&lt;/li&gt;
  &lt;li&gt;Nishihara, Robert, et al. [NLRPJ15] “A general analysis of the convergence of ADMM.” arXiv preprint arXiv:1502.02009 (2015).&lt;/li&gt;
  &lt;li&gt;Parikh, Neal, and Stephen Boyd. [NB13] “Proximal algorithms.” Foundations and Trends® in Optimization 1.3 (2014): 127-239.&lt;/li&gt;
  &lt;li&gt;Vu, Vincent Q., et al. [VCLR13] “Fantope projection and selection: A near-optimal convex relaxation of sparse PCA.” Advances in neural information processing systems. 2013.&lt;/li&gt;
  &lt;li&gt;Candès, Emmanuel J., et al. [CLMW09] “Robust principal component analysis?.” Journal of the ACM (JACM) 58.3 (2011): 11.&lt;/li&gt;
  &lt;li&gt;Ramdas, Aaditya, and Ryan J. Tibshirani. [RT16] “Fast and flexible ADMM algorithms for trend filtering.” Journal of Computational and Graphical Statistics 25.3 (2016): 839-858.&lt;/li&gt;
  &lt;li&gt;Wytock, Matt, Suvrit Sra, and Jeremy Z. Kolter. [WSK14] “Fast Newton methods for the group fused lasso.” UAI. 2014.&lt;/li&gt;
  &lt;li&gt;Barbero, Alvaro, and Suvrit Sra. [BS14] “Modular proximal optimization for multidimensional total-variation regularization.” arXiv preprint arXiv:1411.0589 (2014).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Phân tích hội tụ của ADMM: [BPCPE11], [HL12], [DY16], [IBCH14], [NLRPJ15]&lt;br /&gt;
Ước lượng không gian con thưa: [VCLR13]&lt;br /&gt;
Phân rã thưa cộng hạng thấp: [CLMW09]&lt;br /&gt;
ADMM đồng thuận (Consensus ADMM): [BPCPE11], [NB13]&lt;br /&gt;
Tham số hóa bài toán con: [RT16], [WSK14], [BS14]&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-giai-đoạn-20222026-tùy-chọn&quot;&gt;Ứng dụng giai đoạn 2022–2026 (tùy chọn)&lt;/h2&gt;

&lt;p&gt;Các ví dụ cổ điển trên (Lasso, phân rã thưa cộng hạng thấp, đồng thuận, fused lasso) vẫn là nền tảng cốt lõi để tiếp cận ADMM. Bên cạnh đó, một bài học tùy chọn tổng hợp giai đoạn 2022–2026 sẽ mở rộng &lt;em&gt;cùng&lt;/em&gt; cấu trúc tách đồng thuận và toán tử proximal sang học sâu liên kết (&lt;strong&gt;FedADMM&lt;/strong&gt;), tạo ảnh plug-and-play với bộ khử nhiễu CNN, và bài toán tối ưu dòng công suất (OPF) phân tán trực tuyến. Bạn có thể đọc tiếp tại &lt;a href=&quot;/contents/vi/chapter21/21_07_modern_applications/&quot;&gt;21-07 Ứng dụng hiện đại của ADMM&lt;/a&gt;. Bài học này không thay thế tài liệu của Boyd và cộng sự, mà minh họa những hệ thống thực tế nơi phần dư vẫn đóng vai trò giám sát quan trọng.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>21-08 Practical Exercises - ADMM Applications</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_08_Practical_Exercises_ADMM_Applications/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_08_Practical_Exercises_ADMM_Applications</id>
   <content type="html">&lt;p&gt;The best way to internalize ADMM is to derive a splitting from scratch, check every matrix dimension, and run 3–5 iterations by hand (and in Python) until you watch the primal residual \(r^k\) and dual residual \(s^k\) collapse together. Before diving into the Boyd et al. exercises below, work through this compact 1D Lasso warm-up so you can verify the exact interplay between the ridge \(\beta\)-update, the soft-thresholding \(\alpha\)-update, and the scaled dual accumulator \(w\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-core-admm-skills-tested-in-these-exercises&quot;&gt;Key ideas: Core ADMM Skills Tested in These Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Scaled ADMM Formulation:&lt;/strong&gt; Translate any structured problem (Lasso, total variation, constrained QP, consensus) into \(\min f(x) + g(z) \text{ s.t. } Ax + Bz = c\) and write the three scaled updates cleanly.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closed-Form Proximal &amp;amp; Linear Oracles:&lt;/strong&gt; Recognize when the \(x\)-step is a cacheable Cholesky solve \((A^T A + \rho I)^{-1}\) and when the \(z\)-step is soft-thresholding, block shrinkage, singular-value thresholding, or Euclidean projection.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Residual-Based Stopping &amp;amp; Adaptive \(\rho\):&lt;/strong&gt; Compute \(r^k = Ax^k + Bz^k - c\) and \(s^k = \rho A^T B(z^k - z^{k-1})\), and apply Boyd’s residual-balancing rule (doubling/halving \(\rho\) when \(\|r^k\|_2\) and \(\|s^k\|_2\) differ by a factor of 10).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Splitting Design Intuition:&lt;/strong&gt; Compare alternative auxiliary variable choices to ensure every subproblem is cheap and well-conditioned.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-hand-tracing-two-scaled-admm-steps-on-1d-lasso&quot;&gt;Worked example: Hand-Tracing Two Scaled ADMM Steps on 1D Lasso&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Solve $$\min_x \frac{1}{2}(x - 3)^2 +&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((exact optimum\)x^\star = S_1(3) = 2\() via the Lasso split\)\min \frac{1}{2}(x - 3)^2 +&lt;/td&gt;
      &lt;td&gt;z&lt;/td&gt;
      &lt;td&gt;\(s.t.\)x - z = 0\(with\)\rho = 1\(, starting from\)z^0 = 0, \; w^0 = 0$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the three scaled updates:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^k = \frac{3 + (z^{k-1} - w^{k-1})}{2}\),&lt;/li&gt;
      &lt;li&gt;\(z^k = S_1(x^k + w^{k-1})\),&lt;/li&gt;
      &lt;li&gt;\(w^k = w^{k-1} + x^k - z^k\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 (\(z^0 = 0, w^0 = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^1 = \frac{3 + 0}{2} = 1.5\).&lt;/li&gt;
      &lt;li&gt;\(z^1 = S_1(1.5 + 0) = 0.5\).&lt;/li&gt;
      &lt;li&gt;\(w^1 = 0 + (1.5 - 0.5) = 1.0\). (Primal residual \(r^1 = 1.0\), dual residual \(s^1 = 0.5\).)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2 (\(z^1 = 0.5, w^1 = 1.0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^2 = \frac{3 + (0.5 - 1.0)}{2} = 1.25\).&lt;/li&gt;
      &lt;li&gt;\(z^2 = S_1(1.25 + 1.0) = S_1(2.25) = 1.25\)!&lt;/li&gt;
      &lt;li&gt;\(w^2 = 1.0 + (1.25 - 1.25) = 1.0\). (Notice \(r^2 = 0\), and \(w^2 = 1.0 = w^\star\)!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify Iteration 3:&lt;/strong&gt;
\(x^3 = \frac{3 + (1.25 - 1.0)}{2} = 1.625\), \(z^3 = S_1(2.625) = 1.625\), \(w^3 = 1.0\)—sliding straight along the feasible line \(x = z\) directly into \(x^\star = z^\star = 2.0\)! Now try the full exercises below.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---admm-applications&quot;&gt;Practical Exercises - ADMM Applications&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd et al. (2011).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-1-admm-basics&quot;&gt;📝 &lt;strong&gt;Exercise 1: ADMM Basics&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;\(\min f(x) + g(z)\) s.t. \(Ax + Bz = c\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the scaled ADMM&lt;br /&gt;
b) Apply it to LASSO: \(\min \frac{1}{2}\|Ax - b\|^2 + \lambda\|x\|_1\)&lt;br /&gt;
c) Iterate on a toy example&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Scaled ADMM:**

$$x^{(k+1)} = \arg\min_x \left[ f(x) + \frac{\rho}{2}\|Ax + Bz^{(k)} - c + u^{(k)}\|^2 \right]$$

$$z^{(k+1)} = \arg\min_z \left[ g(z) + \frac{\rho}{2}\|Ax^{(k+1)} + Bz - c + u^{(k)}\|^2 \right]$$

$$u^{(k+1)} = u^{(k)} + Ax^{(k+1)} + Bz^{(k+1)} - c$$

**b) LASSO:** $$x - z = 0$$

$$x^{(k+1)} = (A^TA + \rho I)^{-1}(A^Tb + \rho(z^{(k)} - u^{(k)}))$$

$$z^{(k+1)} = S_{\lambda/\rho}(x^{(k+1)} + u^{(k)})$$

$$u^{(k+1)} = u^{(k)} + x^{(k+1)} - z^{(k+1)}$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-consensus-admm&quot;&gt;📝 &lt;strong&gt;Exercise 2: Consensus ADMM&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;\(N\) functions: \(\min \sum_{i=1}^N f_i(x)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Reformulate with consensus variables \(x_i\)&lt;br /&gt;
b) Global variable update&lt;br /&gt;
c) Distributed implementation&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Consensus form:**

$$\min \sum_i f_i(x_i)$$ s.t. $$x_i = z \, \forall i$$

**b) ADMM:**

$$x_i^{(k+1)} = \arg\min_{x_i} \left[ f_i(x_i) + \frac{\rho}{2}\|x_i - z^{(k)} + u_i^{(k)}\|^2 \right]$$

$$z^{(k+1)} = \frac{1}{N}\sum_i (x_i^{(k+1)} + u_i^{(k)})$$

$$u_i^{(k+1)} = u_i^{(k)} + x_i^{(k+1)} - z^{(k+1)}$$

**c) Distributed:** each node updates $$x_i$$, then the results are averaged to get $$z$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-total-variation-denoising&quot;&gt;📝 &lt;strong&gt;Exercise 3: Total Variation Denoising&lt;/strong&gt;&lt;/h2&gt;

\[\min \frac{1}{2}\|x - b\|^2 + \lambda \|Dx\|_1\]

&lt;p&gt;where \(D\) is the difference operator.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) ADMM formulation&lt;br /&gt;
b) \(x\)-update (smooth)&lt;br /&gt;
c) \(z\)-update (soft-thresholding)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Split:** $$z = Dx$$

$$\min_x \frac{1}{2}\|x - b\|^2 + \lambda\|z\|_1$$ s.t. $$Dx - z = 0$$

**b) $$x$$-update:**

$$x^{(k+1)} = (I + \rho D^TD)^{-1}(b + \rho D^T(z^{(k)} - u^{(k)}))$$

(Solve a linear system, often banded and therefore fast)

**c) $$z$$-update:**

$$z^{(k+1)} = S_{\lambda/\rho}(Dx^{(k+1)} + u^{(k)})$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-matrix-decomposition&quot;&gt;📝 &lt;strong&gt;Exercise 4: Matrix Decomposition&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;\(\min \|L\|_* + \lambda\|S\|_1\) s.t. \(L + S = M\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) \(L\)-update (SVD thresholding)&lt;br /&gt;
b) \(S\)-update (soft-thresholding)&lt;br /&gt;
c) Application: robust PCA&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) $$L$$-update:**

$$L^{(k+1)} = \arg\min_L \left[ \|L\|_* + \frac{\rho}{2}\|L + S^{(k)} - M + U^{(k)}\|_F^2 \right]$$

$$= \mathcal{S}_{1/\rho}(M - S^{(k)} - U^{(k)})$$

where $$\mathcal{S}_\tau(X) = U \text{diag}(\max(\sigma_i - \tau, 0)) V^T$$

**b) $$S$$-update:**

$$S^{(k+1)} = S_{\lambda/\rho}(M - L^{(k+1)} - U^{(k)})$$

**c) Robust PCA:** $$M = L + S$$ (low-rank + sparse)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-convergence-and-parameter-tuning&quot;&gt;📝 &lt;strong&gt;Exercise 5: Convergence and Parameter Tuning&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Choose \(\rho\)&lt;br /&gt;
b) Stopping criteria&lt;br /&gt;
c) Adaptive \(\rho\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Choosing $$\rho$$:**

**Rule of thumb:** $$\rho \sim 1.0$$ for normalized data

**Balance:** primal vs dual residuals

**b) Stopping:**

$$\epsilon_{\text{pri}} = \sqrt{n}\epsilon_{\text{abs}} + \epsilon_{\text{rel}}\max(\|Ax\|, \|Bz\|, \|c\|)$$

$$\epsilon_{\text{dual}} = \sqrt{n}\epsilon_{\text{abs}} + \epsilon_{\text{rel}}\|A^T\nu\|$$

Stop when $$\|r\| &amp;lt; \epsilon_{\text{pri}}$$ and $$\|s\| &amp;lt; \epsilon_{\text{dual}}$$

**c) Adaptive:**

```
if ||r|| &amp;gt; μ ||s||:
    ρ = τ_incr * ρ
elif ||s|| &amp;gt; μ ||r||:
    ρ = ρ / τ_decr
```

with $$\mu = 10$$, $$\tau = 2$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;ADMM Applications:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Problem&lt;/th&gt;
      &lt;th&gt;\(f(x)\)&lt;/th&gt;
      &lt;th&gt;\(g(z)\)&lt;/th&gt;
      &lt;th&gt;Use case&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;LASSO&lt;/td&gt;
      &lt;td&gt;\(\frac{1}{2}|Ax-b|^2\)&lt;/td&gt;
      &lt;td&gt;\(\lambda|z|_1\)&lt;/td&gt;
      &lt;td&gt;Sparse regression&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Total variation&lt;/td&gt;
      &lt;td&gt;\(\frac{1}{2}|x-b|^2\)&lt;/td&gt;
      &lt;td&gt;\(\lambda|z|_1\)&lt;/td&gt;
      &lt;td&gt;Image denoising&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Robust PCA&lt;/td&gt;
      &lt;td&gt;\(|L|_*\)&lt;/td&gt;
      &lt;td&gt;\(\lambda|S|_1\)&lt;/td&gt;
      &lt;td&gt;Outlier removal&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Consensus&lt;/td&gt;
      &lt;td&gt;\(\sum f_i(x_i)\)&lt;/td&gt;
      &lt;td&gt;\(0\)&lt;/td&gt;
      &lt;td&gt;Distributed&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Boyd, S., et al. (2011). “Distributed Optimization via ADMM”. &lt;em&gt;Foundations and Trends&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>21-06 Faster convergence with subprogram parametrization - example of the 2d fused lasso problem</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_06_Faster_convergence_with_subprogram_parametrization_-_example_of_the_2d_fused_lasso_problem/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_06_Faster_convergence_with_subprogram_parametrization_:_example_of_the_2d_fused_lasso_problem</id>
   <content type="html">&lt;p&gt;Here is an insider secret that separates textbook ADMM users from experts: &lt;strong&gt;the exact same convex problem can have two different ADMM splittings where one converges 50× faster than the other!&lt;/strong&gt; Nowhere is this clearer than in &lt;strong&gt;2D Fused Lasso (Total Variation denoising)&lt;/strong&gt;. A naive edge-by-edge split introduces a massive auxiliary vector for every pixel difference and crawls across the image; a clever &lt;strong&gt;row-vs.-column splitting&lt;/strong&gt; decouples the 2D grid into independent 1D fused-lasso chains (each solvable in \(O(d)\) linear time via dynamic programming!) that update in &lt;em&gt;orthogonal&lt;/em&gt; directions and converge dramatically faster!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-designing-fast-admm-parametrizations&quot;&gt;Key ideas: Designing Fast ADMM Parametrizations&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Why Splitting Choice Matters:&lt;/strong&gt; ADMM converges fastest when the coupled blocks act along &lt;em&gt;weakly correlated or orthogonal&lt;/em&gt; subspaces (like horizontal rows vs. vertical columns), minimizing the “ping-pong” lag between \(x\) and \(z\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Naive Graph-Difference Splitting (\(D x = z\)):&lt;/strong&gt; Setting \(z = D x\) makes the \(z\)-update trivial soft-thresholding, but forces the \(x\)-update to solve a 2D discrete Poisson system \((I + \rho D^T D) x = \text{rhs}\) and decouples information only one pixel per iteration.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Orthogonal Row–Column Splitting (\(x = z\) on 1D Chains):&lt;/strong&gt; Splitting the 2D TV penalty into \(\lambda\|D_{\text{row}} x\|_1 + \lambda\|D_{\text{col}} z\|_1\) subject to \(x = z\) turns the \(x\)-update into \(d\) completely independent 1D fused-lasso problems (one per row) and the \(z\)-update into \(d\) independent 1D problems (one per column)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear-Time 1D Fused Lasso Oracles:&lt;/strong&gt; Using Condat’s or Johnson’s \(O(d)\) dynamic-programming algorithm for 1D TV denoising makes each row/column pass cost only \(O(d^2)\) total—the same per-iteration cost as soft-thresholding, while propagating information across the &lt;em&gt;entire&lt;/em&gt; image in a single sweep!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-naive-edge-split-vs-rowcolumn-split-on-a-2-times-2-image&quot;&gt;Worked example: Naive Edge Split vs. Row–Column Split on a \(2 \times 2\) Image&lt;/h3&gt;

&lt;p&gt;Consider denoising a \(2 \times 2\) image \(Y = \begin{bmatrix} 0 &amp;amp; 4 \\ 0 &amp;amp; 4 \end{bmatrix}\) (a sharp vertical step edge between column 1 and column 2!) with 2D TV penalty \(\lambda = 1\):
\(\min_{X \in \mathbb{R}^{2 \times 2}} \; \frac{1}{2}\|Y - X\|_F^2 + \underbrace{\sum_{\text{rows}} |X_{i,1} - X_{i,2}|}_{\text{horizontal diffs}} + \underbrace{\sum_{\text{cols}} |X_{1,j} - X_{2,j}|}_{\text{vertical diffs}}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Exact optimum (by symmetry of rows):&lt;/strong&gt;
Both rows are identical (so vertical diffs are \(0\)!), and each row solves the 1D problem \(\min_{a,b} \frac{1}{2}a^2 + \frac{1}{2}(b - 4)^2 + |a - b|\), giving \(a^\star = 1, \; b^\star = 3\), so \(X^\star = \begin{bmatrix} 1 &amp;amp; 3 \\ 1 &amp;amp; 3 \end{bmatrix}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trace 1 iteration of Row–Column ADMM (\(X = Z\), \(\rho = 1\), \(Z^0 = Y, W^0 = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Row-wise \(X\)-update&lt;/strong&gt; (each row solves \(\min \frac{1}{2}\|Y_{i,:} - X_{i,:}\|^2 + \frac{1}{2}\|X_{i,:} - Z_{i,:}^0\|^2 + |X_{i,1} - X_{i,2}|\)):
For row 1: \(\min (a - 0)^2 + (b - 4)^2 + |a - b| \implies 2a - 1 = 0 \implies a = 0.5\) and \(2(b - 4) + 1 = 0 \implies b = 3.5\).
Thus \(X^1 = \begin{bmatrix} 0.5 &amp;amp; 3.5 \\ 0.5 &amp;amp; 3.5 \end{bmatrix}\) (propagating information across the full row immediately!).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Column-wise \(Z\)-update&lt;/strong&gt; (each column solves 1D TV on \(X_{:,j}^1\)):
Since both entries of column 1 equal \(0.5\) and both entries of column 2 equal \(3.5\), vertical differences are &lt;em&gt;already&lt;/em&gt; zero, so \(Z^1 = X^1 = \begin{bmatrix} 0.5 &amp;amp; 3.5 \\ 0.5 &amp;amp; 3.5 \end{bmatrix}\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why it wins:&lt;/strong&gt;
In one sweep, horizontal and vertical structures decoupled orthogonally with zero cross-contamination—and on a \(512 \times 512\) image, a single row-column sweep propagates boundary information across all 512 pixels at once instead of 1 pixel per iteration!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;faster-convergence-with-subprogram-parametrization&quot;&gt;Faster Convergence with Subprogram Parametrization&lt;/h1&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;One very interesting property of ADMM is that when solving problems, if we parametrize the small subproblems in a special way, it can show much faster convergence performance than general methods. In the previous consensus ADMM example, the updates optimize over blocks of variables, which is similar to block coordinate descent. Therefore, ADMM can also achieve fast convergence by updating blocks of variables in nearly orthogonal directions.&lt;/p&gt;

&lt;h2 id=&quot;2d-fused-lasso-example&quot;&gt;2D Fused Lasso Example&lt;/h2&gt;

&lt;p&gt;In this section, we will demonstrate the above concepts through examples, designing auxiliary constraints so that the primal updates are in de-correlated directions.&lt;/p&gt;

&lt;p&gt;For detailed information, see [RT16], [WSK14], [BS14].&lt;/p&gt;

&lt;p&gt;Let’s examine the 2D fused lasso or 2D total variation denoising problem, which was one of the examples we looked at in &lt;a href=&quot;/contents/en/chapter01/01_01_optimization_problems/&quot;&gt;Chapter 1&lt;/a&gt;. Given an image \(Y\in \mathbb{R}^{d\times d}\), the problem is defined as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{\Theta}\frac{1}{2}||Y-\Theta||^{2}_{F}+\lambda \sum_{i,j}(|\Theta_{i,j}-\Theta_{i+1,j}|+|\Theta_{i,j}-\Theta_{\Theta_{i,j+1}}|).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In this problem, there is a parameter for each pixel of the image, and this parameter matrix is \(\Theta\in \mathbb{R}^{d\times d}\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/2dfussed.png&quot; alt=&quot;[Fig 1] Interpretation of the penalty term in 2d fussed lasso[3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Interpretation of the penalty term in 2d fussed lasso[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;[Fig 1] visually shows the penalty term, which is the second term of the objective function. As can be seen from the defined problem, it aims to reduce the differences between a pixel and its adjacent horizontal and vertical pixels. That is, this penalty term makes the values of neighboring adjacent pixels similar.&lt;/p&gt;

&lt;h2 id=&quot;vector-form&quot;&gt;Vector Form&lt;/h2&gt;

&lt;p&gt;Summarizing the penalty term as an operator, the problem becomes:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\min_{\theta}\frac{1}{2}||y-\theta||^{2}_{F} + \lambda||D\theta||_{1}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;where \(D\in \mathbb{R}^{m\times n}\) is the 2D difference operator corresponding to the original equation.&lt;/p&gt;

&lt;h2 id=&quot;forms-of-admm-updates-for-the-2d-fused-lasso-problem&quot;&gt;Forms of ADMM updates for the 2d fused lasso problem&lt;/h2&gt;
&lt;h2 id=&quot;forms-of-admm-updates-for-the-2d-fused-lasso-problem-1&quot;&gt;Forms of ADMM Updates for the 2D Fused Lasso Problem&lt;/h2&gt;

&lt;p&gt;Now we want to create ADMM steps in two ways by applying auxiliary constraints.&lt;/p&gt;

&lt;p&gt;The first approach is to derive ADMM from the vector form created through the 2D difference operator.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{\theta, z}\frac{1}{2}||y-\theta||^{2}_{2}+\lambda||z||_{1} \qquad \text{subject to   }z = D\theta,
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The ADMM steps are then derived as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\theta^{(k)} &amp;amp;= (I+\rho D^{T}D)^{-1}(y+\rho D^{T}(z^{(k-1)}+w^{(k-1)}))\\\\
z^{(k)} &amp;amp;= S_{\frac{\lambda}{\rho}}(D\theta^{(k)}-w^{(k-1)})\\\\
w^{(k)} &amp;amp;= w^{(k-1)}+z^{(k-1)}-D\theta ^{(k)}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;computational-complexity---vector-form&quot;&gt;Computational Complexity - Vector Form&lt;/h2&gt;

&lt;p&gt;Solving for \(\theta\) is equivalent to solving the linear system \((I+\rho D^{T}D)^{-1}\). Here, \(D^{T}D\) becomes the Laplacian matrix \(L=D^{T}D\) of the 2D grid, which can be solved in \(O(n)\) operations. The \(z\) update also requires \(O(n)\) operations since it involves applying the soft thresholding operator \(S_{t}\). Therefore, solving ADMM in vector form takes \(O(n)\) time.&lt;/p&gt;

&lt;h2 id=&quot;matrix-form-admm&quot;&gt;Matrix Form ADMM&lt;/h2&gt;

&lt;p&gt;The second approach is to derive ADMM in matrix form, identical to the original problem definition.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{\Theta, Z} &amp;amp;&amp;amp;\frac{1}{2}||Y-\Theta||^{2}_{F}+\lambda\sum_{i,j}(|\Theta_{i,j}-\Theta_{i+1,j}+|Z_{i+1,j}-Z_{i,j+1}|)\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;\Theta = Z
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The ADMM steps are as follows:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
\Theta_{\cdot \\ , j}^{(k)} &amp;amp;= FL^{1d}_{ \frac{\lambda}{(1+\rho)} } \bigg( \frac{ Y+\rho( Z^{(k-1)}_{\cdot \\ , j}-W_{\cdot \\ ,j}^{(k-1)} ) } {1+\rho} \bigg),\qquad j=1,...,d\\\\
Z_{i, \cdot}^{(k)} &amp;amp;= FL^{1d}_{\frac{\lambda}{\rho}} \bigg(\Theta_{i, \cdot}^{(k)} + W_{i, \cdot}^{(k-1)} \bigg), \qquad j=1,...,d\\\\
W^{(k)} &amp;amp;= W^{(k-1)} + \Theta^{(k)} - Z^{(k)} \\\\
\end{align}\)
where \(FL_{\tau}^{1d}(a)\) is the 1D fused lasso defined as \(FL_{\tau}^{1d}(a) = \underset{x}{\operatorname{argmin}}\frac{1}{2}||a-x||^{2}_{2}+\tau\sum_{i=1}^{d-1}|x_{i}-x_{i+1}|\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;computational-complexity---matrix-form&quot;&gt;Computational Complexity - Matrix Form&lt;/h2&gt;

&lt;p&gt;The matrix form ADMM can also be performed with \(O(n)\) time complexity. Both \(\Theta\) and \(Z\) are in the form of 1D fused lasso, which has \(O(n)\) time complexity.&lt;/p&gt;

&lt;p&gt;[Fig 2] shows how the original penalty term is separated into 1D fused lasso problems.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/2dfussedlasso.png&quot; alt=&quot;[Fig 2]  Interpretation of the matrix form ADMM updates for 2d fused lasso[3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 2]  Interpretation of the matrix form ADMM updates for 2d fused lasso[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;image-denoising-experiments&quot;&gt;Image denoising experiments&lt;/h2&gt;
&lt;h2 id=&quot;image-denoising-experiments-1&quot;&gt;Image Denoising Experiments&lt;/h2&gt;

&lt;p&gt;Now let’s revisit the image denoising problem we examined in Chapter 1.&lt;/p&gt;

&lt;p&gt;[Fig 3] shows the data and denoised images. [Fig 4] shows a comparison of the two ADMM methods. The “specialized” ADMM in matrix form, which defines constraints by decomposing in vertical/horizontal directions, shows much faster convergence performance than the “standard ADMM” derived in vector form.&lt;/p&gt;

&lt;p&gt;[Fig 5] shows the image quality according to ADMM iterations.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/ll1.png&quot; alt=&quot;[Fig 3]  Data, exact solution image(300x200 image : n = 60,000).  
left : original image before denoising, right : the exact solution of denoised image[3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 3]  Data, exact solution image(300x200 image : n = 60,000).
left : original image before denoising, right : the exact solution of denoised image[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/ll2.png&quot; alt=&quot;[Fig 4]  Convergence curves of two ADMM algorithms. black : standard(vector form), red : specialized(matrix form) [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 4]  Convergence curves of two ADMM algorithms. black : standard(vector form), red : specialized(matrix form) [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/admm_iteration_visualized.png&quot; alt=&quot;[Fig 5]  ADMM iterates visualized after k = 10, 30, 50, 100 iterations [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 5]  ADMM iterates visualized after k = 10, 30, 50, 100 iterations [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>21-05 Consensus ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_05_Consensus_ADMM/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_05_Consensus_ADMM</id>
   <content type="html">&lt;p&gt;Suppose your training dataset is 500 gigabytes—far too big to fit on a single server, so you shard it across \(B = 100\) machines, each holding its own local empirical loss \(f_i(x)\). How do you minimize \(\sum_{i=1}^B f_i(x)\) without shipping raw data over the network? &lt;strong&gt;Consensus ADMM&lt;/strong&gt; gives every machine its own local parameter copy \(x_i\), enforces the agreement constraint \(x_i = z\) with a central consensus vector \(z\), and turns the global \(z\)-update into a single &lt;strong&gt;exact average&lt;/strong&gt; \(\bar{x}^{(k)}\)—producing a clean, fault-tolerant map-reduce optimization loop!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-distributed-map-reduce-via-consensus-admm&quot;&gt;Key ideas: Distributed Map-Reduce via Consensus ADMM&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Variable Replication (\(x_i = z\)):&lt;/strong&gt; Rewriting \(\min_x \sum_{i=1}^B f_i(x)\) as \(\min \sum_{i=1}^B f_i(x_i) \text{ s.t. } x_i = z\) decouples all \(B\) local losses completely during the \(x\)-update, allowing all \(B\) workers to compute \(\operatorname{prox}_{f_i/\rho}(z^{k-1} - w_i^{k-1})\) in parallel.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Averaging in the \(z\)-Update:&lt;/strong&gt; Minimizing \(\sum_{i=1}^B \frac{\rho}{2}\|x_i^k - z + w_i^{k-1}\|_2^2\) over \(z\) yields \(z^k = \bar{x}^k + \bar{w}^{k-1}\). Because \(\bar{w}^k = \bar{w}^{k-1} + \bar{x}^k - z^k = 0\) for all \(k \ge 1\), the consensus update simplifies to the pure average \(z^k = \bar{x}^k\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularized Consensus (Adding \(g(z)\)):&lt;/strong&gt; Adding a global regularizer \(g(z)\) (like \(\lambda\|z\|_1\) for distributed Lasso) keeps all worker updates identical and changes only the coordinator step to \(z^k = \operatorname{prox}_{g/(B\rho)}(\bar{x}^k + \bar{w}^{k-1})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Zero-Mean Dual Invariant (\(\sum_i w_i^k = 0\)):&lt;/strong&gt; The dual variables act as local disagreement memories whose sum vanishes across the cluster, pulling stubborn workers smoothly toward the shared global optimum without sharing private data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-two-machine-consensus-admm-with-zero-mean-duals&quot;&gt;Worked example: Two-Machine Consensus ADMM with Zero-Mean Duals&lt;/h3&gt;

&lt;p&gt;Minimize \(f_1(x) + f_2(x) = \frac{1}{2}(x - 1)^2 + \frac{1}{2}(x - 5)^2\) across \(B = 2\) machines (exact global optimum \(x^\star = 3\)). Split as \(x_1 = z, \; x_2 = z\) with \(\rho = 1\), starting from \(z^0 = 0, \; w_1^0 = 0, \; w_2^0 = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 (Parallel worker updates + coordinator average):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Machine 1: \(x_1^1 = \arg\min_{x_1} \frac{1}{2}(x_1 - 1)^2 + \frac{1}{2}(x_1 - 0)^2 = \frac{1 + 0}{2} = 0.5\).&lt;/li&gt;
      &lt;li&gt;Machine 2: \(x_2^1 = \arg\min_{x_2} \frac{1}{2}(x_2 - 5)^2 + \frac{1}{2}(x_2 - 0)^2 = \frac{5 + 0}{2} = 2.5\).&lt;/li&gt;
      &lt;li&gt;Coordinator average: \(z^1 = \frac{x_1^1 + x_2^1}{2} = \frac{0.5 + 2.5}{2} = 1.5\).&lt;/li&gt;
      &lt;li&gt;Local dual updates: \(w_1^1 = 0 + (0.5 - 1.5) = -1.0\), \(w_2^1 = 0 + (2.5 - 1.5) = +1.0\). (Notice \(w_1^1 + w_2^1 = 0\)!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2 (Watch consensus hit the exact optimum!):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Machine 1: \(x_1^2 = \frac{1 + (z^1 - w_1^1)}{2} = \frac{1 + (1.5 - (-1.0))}{2} = \frac{3.5}{2} = 1.75\).&lt;/li&gt;
      &lt;li&gt;Machine 2: \(x_2^2 = \frac{5 + (z^1 - w_2^1)}{2} = \frac{5 + (1.5 - 1.0)}{2} = \frac{5.5}{2} = 2.75\).&lt;/li&gt;
      &lt;li&gt;Coordinator average: \(z^2 = \frac{1.75 + 2.75}{2} = 2.25\) (moving straight toward \(3.0\)!).&lt;/li&gt;
      &lt;li&gt;Dual updates: \(w_1^2 = -1.0 + (1.75 - 2.25) = -1.5\), \(w_2^2 = +1.0 + (2.75 - 2.25) = +1.5\) (again \(w_1^2 + w_2^2 = 0\), converging to \(w_1^\star = -2, w_2^\star = +2\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;consensus-admm&quot;&gt;Consensus ADMM&lt;/h1&gt;

&lt;h2 id=&quot;basic-consensus-admm&quot;&gt;Basic Consensus ADMM&lt;/h2&gt;

&lt;p&gt;Consider the following problem:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\min_{x}\sum^{B}_{i=1} f_{i}(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;To solve this problem with ADMM, we need to introduce constraints. Here, we want to transform the equation into a form that is easy to operate in parallel. This approach, called consensus ADMM, reparametrizes the equation as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x_{1},...,x_{B},x} &amp;amp;&amp;amp;\sum^{B}_{i=1} f_{i}(x_{i})\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;x_{i}=x, i = 1,...B
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;admm-algorithm&quot;&gt;ADMM Algorithm&lt;/h2&gt;

&lt;p&gt;This allows us to compute decomposable ADMM steps:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^{(k)}_{i} &amp;amp;= \underset{x_{i}}{\operatorname{argmin}} f_{i}(x_{i})+\frac{\rho}{2}||x_{i}-x^{(k-1)}+w_{i}^{(k-1)}||_{2}^{2}, i=1,...B\\\\
x^{(k)} &amp;amp;=\frac{1}{B}\sum_{i=1}^{B}(x_{i}^{(k)}+w_{i}^{(k-1)})\\\\
w_{i}^{(k)} &amp;amp;=w_{i}^{(k-1)}+x_{i}^{(k)}-x^{(k)}, i=1,...,B
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;simplified-form&quot;&gt;Simplified Form&lt;/h2&gt;

&lt;p&gt;Additionally, we can define \(\overline{x}=\frac{1}{B}\sum_{i=1}^{B}x_{i}, \overline{w}=\frac{1}{B}\sum_{i=1}^{B}w_{i}\). With this, we can easily verify that \(\overline{w}^{(k)}=0\) for iterations \(k&amp;gt;1\), and the second equation of the ADMM update simplifies to \(x^{(k)}=\overline{x}^{(k)}\). Therefore, we can simplify the ADMM update equations as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^{(k)}_{i} &amp;amp;= \underset{x_{i}}{\operatorname{argmin}} f_{i}(x_{i})+\frac{\rho}{2}||x_{i}-\overline{x}^{(k-1)}+w_{i}^{(k-1)}||_{2}^{2},  i=1,...B\\\\
w_{i}^{(k)} &amp;amp;=w_{i}^{(k-1)}+x_{i}^{(k)}-\overline{x}^{(k)},  i=1,...,B.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;intuition&quot;&gt;Intuition&lt;/h2&gt;

&lt;p&gt;The \(x_{i}\) updates for \(i = 1,...,B\) can be computed in parallel.&lt;/p&gt;

&lt;p&gt;From the simplified equations, we can gain intuition about consensus ADMM. Each \(x_{i}\) update tries to minimize \(f_{i}(x_{i})\) while simultaneously using \(l_{2}\) regularization to align each \(x_{i}\) with the average \(\overline{x}\). If \(x_{i}\) becomes larger than the average, \(w_{i}\) increases. Therefore, the regularization in the next step will reduce the enlarged \(x_{i}\).&lt;/p&gt;

&lt;h2 id=&quot;general-consensus-admm&quot;&gt;General consensus ADMM&lt;/h2&gt;
&lt;h2 id=&quot;general-consensus-admm-1&quot;&gt;General Consensus ADMM&lt;/h2&gt;

&lt;p&gt;Consensus ADMM can be generalized to a more general form. Let’s look at the form of problems with affine transformations of \(x\) and arbitrary function \(g\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x}\sum_{i=1}^{B} f_{i}(a^{T}_{i}x+b_{i})+g(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;For this equation as well, we reparameterize by adding constraints:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x_{1},..x_{B},x} &amp;amp;&amp;amp;\sum^{B}_{i=1}f_{i}(a_{i}^{T}x+b)+g(x)\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;x_{i} = x, i=1,...B
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;We can then derive decomposable ADMM updates:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x_{i}^{(k)} &amp;amp;= \underset{x_{i}}{\operatorname{argmin}}f_{i}(a_{i}^{T}x+b_{i})+\frac{\rho}{2}||x_{i}-x^{(k-1)}+w_{i}^{(k-1)}||^{2}_{2}+g(x)\\\\
x^{(k)}&amp;amp;=\underset{x}{\operatorname{argmin}} \frac{B\rho}{2}||x-\overline{x}^{(k)}-\overline{w}^{(k-1)}||^{2}_{2}+g(x)\\\\
w_{i}^{(k)}&amp;amp;=w_{i}^{(k-1)}+x_{i}^{(k)}-x^{(k)}, i=1,...B
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;key-differences&quot;&gt;Key Differences&lt;/h2&gt;

&lt;p&gt;The differences between generalized consensus ADMM and the consensus ADMM derived above can be summarized as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Because the ADMM step equations do not simplify, \(\overline{w}^{(k)}=0\) is no longer satisfied.&lt;/li&gt;
  &lt;li&gt;\(x_{i}, i=1,...,B\) can be updated in parallel.&lt;/li&gt;
  &lt;li&gt;Each \(x_{i}\) update can be thought of as minimizing the corresponding partial loss with \(l_2\) regularization.&lt;/li&gt;
  &lt;li&gt;The \(x\) update is a proximal operation for the arbitrary function \(g\) (generally a regularizer).&lt;/li&gt;
  &lt;li&gt;Different ADMM algorithms are derived depending on how the reparameterization is done.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more detailed information, see the &lt;a href=&quot;/contents/en/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;reference papers&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>21-04 Example - Sparse subspace estimation and sparse plus low rank decomposition</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_04_Example_-_Sparse_subspace_estimation_and_sparse_plus_low_rank_decomposition/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_04_Example_:_Sparse_subspace_estimation_and_sparse_plus_low_rank_decomposition</id>
   <content type="html">&lt;p&gt;High-dimensional data matrices—from surveillance video streams to gene-expression tables—often hide two completely different structures superimposed on top of each other: a &lt;strong&gt;low-rank background&lt;/strong&gt; \(L\) plus a &lt;strong&gt;sparse foreground&lt;/strong&gt; \(S\) (Robust PCA), or a &lt;strong&gt;low-rank covariance subspace&lt;/strong&gt; \(P\) with &lt;strong&gt;sparse loadings&lt;/strong&gt; (Fantope Sparse PCA). Interior-point SDP solvers choke once matrices exceed \(100 \times 100\), because their Hessians scale as \(O(p^6)\). &lt;strong&gt;ADMM&lt;/strong&gt; handles \(1000 \times 1000\) matrices effortlessly by splitting the spectral constraint (handled by SVD/eigendecomposition) from the entrywise sparsity constraint (handled by elementwise soft-thresholding)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-spectral--sparse-matrix-splitting-in-admm&quot;&gt;Key ideas: Spectral + Sparse Matrix Splitting in ADMM&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Convex Relaxation of Rank (Fantope &amp;amp; Nuclear Norm):&lt;/strong&gt; Replacing nonconvex \(\operatorname{rank}(P) = k\) with the Fantope \(\mathcal{F}^k = \{P : 0 \preceq P \preceq I, \operatorname{tr}(P) = k\}\) (for Sparse PCA) or replacing \(\operatorname{rank}(L)\) with the nuclear norm \(\|L\|_\ast = \sum_i \sigma_i(L)\) (for Robust PCA) yields tractable convex programs with near-optimal statistical recovery.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Singular Value Thresholding (SVT) Proximal Map:&lt;/strong&gt; The proximal operator of \(\tau\|L\|_\ast\) is simply taking the SVD \(U \Sigma V^T\) and soft-thresholding the singular values: \(\mathcal{D}_\tau(M) = U \operatorname{diag}\big((\sigma_i - \tau)_+\big) V^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fantope Projection:&lt;/strong&gt; Projecting a symmetric matrix \(M = Q \Lambda Q^T\) onto \(\mathcal{F}^k\) keeps the eigenvectors \(Q\) intact and projects the eigenvalues \(\lambda_i\) onto the capped simplex \(\{0 \le \gamma_i \le 1, \sum_i \gamma_i = k\}\) via a fast 1D bisection!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Decoupling Spectral vs. Entrywise Geometry:&lt;/strong&gt; In Robust PCA (\(\min \|L\|_\ast + \lambda\|S\|_1 \text{ s.t. } L + S = M\)), ADMM alternates one SVD (for \(L\)) and one elementwise soft-threshold (for \(S\))—never mixing the two geometries inside a single subproblem!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-admm-iteration-of-robust-pca-l--s--m&quot;&gt;Worked example: One ADMM Iteration of Robust PCA (\(L + S = M\))&lt;/h3&gt;

&lt;p&gt;Consider a \(2 \times 2\) data matrix \(M = \begin{bmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 5 \end{bmatrix}\) (a rank-1 matrix \(\begin{bmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix}\) corrupted by a single sparse outlier \(+3\) in the bottom-right corner!). Solve \(\min \|L\|_\ast + \lambda\|S\|_1\) s.t. \(L + S = M\) with \(\lambda = 0.5, \; \rho = 1\) from \(S^0 = 0, \; W^0 = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(L\)-update (Singular Value Thresholding \(\mathcal{D}_{1/\rho}(M - S^0 - W^0) = \mathcal{D}_1(M)\)):&lt;/strong&gt;
Since \(M\) is symmetric positive definite, its eigenvalues (and singular values) solve \((2 - \sigma)(5 - \sigma) - 4 = \sigma^2 - 7\sigma + 6 = 0 \implies \sigma_1 = 6, \; \sigma_2 = 1\)!
Unit eigenvectors: \(q_1 = \frac{1}{\sqrt{5}}\begin{bmatrix} 1 \\ 2 \end{bmatrix}\) (for \(\sigma_1 = 6\)) and \(q_2 = \frac{1}{\sqrt{5}}\begin{bmatrix} 2 \\ -1 \end{bmatrix}\) (for \(\sigma_2 = 1\)).
Soft-threshold singular values by \(1/\rho = 1\): \(\tilde{\sigma}_1 = 6 - 1 = 5\), \(\tilde{\sigma}_2 = (1 - 1)_+ = 0\)!
Thus \(L^1\) is immediately &lt;strong&gt;rank 1&lt;/strong&gt;:
\(L^1 = 5 q_1 q_1^T = 5 \cdot \frac{1}{5}\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(S\)-update (Entrywise soft-thresholding \(S_{\lambda/\rho}(M - L^1 - W^0) = S_{0.5}(M - L^1)\)):&lt;/strong&gt;
\(M - L^1 = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} \implies S^1 = S_{0.5}\!\begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 0.5 &amp;amp; 0 \\ 0 &amp;amp; 0.5 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual update:&lt;/strong&gt;
\(W^1 = W^0 + (L^1 + S^1 - M) = \begin{bmatrix} -0.5 &amp;amp; 0 \\ 0 &amp;amp; -0.5 \end{bmatrix}.\)
In just &lt;em&gt;one&lt;/em&gt; SVD + soft-thresholding pass, ADMM already extracted a clean rank-1 component \(L^1\) and isolated sparse diagonal residuals!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;example-sparse-subspace-estimation-and-sparse-plus-low-rank-decomposition&quot;&gt;Example: Sparse Subspace Estimation and Sparse Plus Low Rank Decomposition&lt;/h1&gt;

&lt;h2 id=&quot;sparse-subspace-estimation&quot;&gt;Sparse Subspace Estimation&lt;/h2&gt;

&lt;p&gt;Given \(S=X^{T}X, X\in \mathbb{R}^{n\times p}\), consider the problem of finding a projection that minimizes the Frobenius norm distance between the original \(X\) and the projected \(X\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{P} &amp;amp;&amp;amp;||X-XP||^{2}_{F}\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;\text{rank(P)=k where P is a projection matrix}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This problem is non-convex because the set of projection matrices is not a convex set. However, it is known to be equivalent to the following convex problem [&lt;a href=&quot;/contents/en/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;VCLR13&lt;/a&gt;]. This is also called the subspace estimation problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{Y} &amp;amp;&amp;amp;tr(SY)\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;Y\in F_{k} = \left\{Y\in \mathbb{S}^{p} : 0 \preceq Y \preceq I, tr(Y) = k \right\}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;[VCLR13] discusses solving the sparse version (with added L1 norm) of the subspace estimation problem. For detailed derivation, please refer to the corresponding paper.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{Y} &amp;amp;&amp;amp;tr(SY)-\lambda ||Y||_{1}\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;Y\in F_{k} 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;where \(F_{k}\) is the Fantope of order k, as defined in the equation above.&lt;/p&gt;

&lt;p&gt;When \(\lambda = 0\), the above problem is equivalent to standard PCA.&lt;/p&gt;

&lt;p&gt;This problem has an SDP form and can be solved using interior point methods. However, this approach is complex to implement and becomes very slow as the problem size increases.&lt;/p&gt;

&lt;h2 id=&quot;admm-formulation&quot;&gt;ADMM Formulation&lt;/h2&gt;

&lt;p&gt;To solve this problem with ADMM, we reformulate it as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{Y,Z} &amp;amp;&amp;amp;-tr(SY)+I_{F_{k}}(Y) + \lambda||Z||_{1}\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;Y = Z.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;admm-algorithm&quot;&gt;ADMM Algorithm&lt;/h2&gt;

&lt;p&gt;Summarizing the problem, the ADMM steps are as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
Y^{+} &amp;amp;=  \underset{Y}{\operatorname{argmin}} -tr(SY) + I_{F_{k}}(Y)+\frac{\rho}{2}||Y-Z+W||^{2}_{F}\\\\
&amp;amp;=\underset{Y\in F_{k}}{\operatorname{argmin}} \frac{1}{2}||Y-Z+W-\frac{S}{\rho}||^{2}_{F}\\\\
&amp;amp;=P_{F_{k}}(Z-W+\frac{S}{\rho})\\\\
Z^{+} &amp;amp; = \underset{Z}{\operatorname{argmin}}\lambda||Z||_{1}+\frac{\rho}{2}||Y^{+}-Z+W||^{2}_{F}\\\\
&amp;amp;=S_{\frac{\lambda}{\rho}}(Y^{+}+W)\\\\
W^{+} &amp;amp;=W+Y^{+}-Z^{+}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;where \(P_{F_{k}}\) is the fantope projection operator. This is defined by clipping the eigendecomposition \(A= U\Sigma U^{T}, \Sigma = diag(\sigma_{1},...\sigma_{p})\) [&lt;a href=&quot;/contents/en/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;VCLR13&lt;/a&gt;]:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
P_{F_{k}}(A) = U\Sigma_{\theta}U^{T}, \: \Sigma_{\theta} = diag(\sigma_{1}(\theta),...\sigma_{p}(\theta))
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;where each \(\sigma_{i}(\theta) = \min\left\{\max\left\{\sigma_{i}-\theta,0\right\},1\right\}\) and \(\sum^{p}_{i=1}\sigma_{i}(\theta)=k\).&lt;/p&gt;

&lt;h2 id=&quot;sparse-plus-low-rank-decomposition&quot;&gt;Sparse plus low rank decomposition&lt;/h2&gt;
&lt;p&gt;Given \(M\in \mathbb{R}^{n\times m}\), the sparse plus low rank decomposition problem is as follows [&lt;a href=&quot;/contents/en/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;CLMW09&lt;/a&gt;]:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{L,S} &amp;amp;&amp;amp;||L||_{tr}+\lambda||S||_{1}\\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;L+S=M
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;problem-description&quot;&gt;Problem Description&lt;/h2&gt;

&lt;p&gt;The goal of this problem is to decompose the observed matrix \(M\) into a low rank matrix \(L\) and a sparse matrix \(S\). The first term of the objective function is the trace penalty of \(L\), which minimizes the sum of singular values of \(L\). The second term uses the \(l_{1}\) norm on matrix \(S\) to induce sparsity in \(S\). \(\lambda\) is a tuning parameter that balances these two terms. Both the trace norm and \(l_{1}\) norm are non-smooth, and generally the trace norm is known to be difficult to optimize. Like the sparse subspace estimation problem, this problem has an SDP form and can be solved using interior point methods, but this is also complex and slow. For this problem, ADMM provides somewhat easier update steps.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
L^{+} &amp;amp;= S^{tr}_{\frac{1}{\rho}}(M-S+W)\\\\
S^{+} &amp;amp;= S^{l_{1}}_{\frac{\lambda}{\rho}}(M-L^{+}+W)\\\\
W^{+} &amp;amp;= W+M-L^{+}-S^{+}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;where \(S^{tr}_{\frac{1}{\rho}}\) is matrix soft-thresholding and \(S^{l_{1}}_{\frac{\lambda}{\rho}}\) is elementwise soft-thresholding.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/candes.png&quot; alt=&quot;[Fig 1] Example of sparse plue low rank decomposition on surveliance camera[3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Example of sparse plue low rank decomposition on surveliance camera[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;application-example&quot;&gt;Application Example&lt;/h2&gt;

&lt;p&gt;[Fig 1] shows an example of applying sparse plus low rank decomposition to surveillance camera video analysis. From surveillance cameras that film a fixed area for a long time, we can easily separate the low rank part that shares most frames, and the sparse part extracts characteristic parts from specific frames. For example, in [Fig 1], the middle column represents the low rank part and the right column represents the sparse part. As can be confirmed, the low rank part contains background information that appears in almost all frames, and the sparse part contains only characteristic parts that appear only in specific frames.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>21-03 Example - Lasso regression and group lasso Regression</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_03_Example_-_Lasso_regression_and_group_lasso_Regression/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_03_Example_:_Lasso_regression_and_group_lasso_Regression</id>
   <content type="html">&lt;p&gt;You have already seen Lasso solved by subgradients, ISTA/FISTA, coordinate descent, and interior-point methods—so why does &lt;strong&gt;ADMM for Lasso and Group Lasso&lt;/strong&gt; deserve its own spotlight? Because splitting \(\beta = \alpha\) cleanly separates the &lt;em&gt;coupled design matrix&lt;/em&gt; \(X\) (handled by a single pre-cached ridge linear solve) from the &lt;em&gt;nonsmooth sparsity penalty&lt;/em&gt; (handled by elementwise soft-thresholding for Lasso or blockwise vector shrinkage for Group Lasso)—making the exact same 10-line template work for overlapping groups, sparse group Lasso, and distributed datasets!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-admm-architecture-for-lasso--group-lasso&quot;&gt;Key ideas: ADMM Architecture for Lasso &amp;amp; Group Lasso&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ridge + Soft-Thresholding Split (Lasso):&lt;/strong&gt; Splitting \(\min \frac{1}{2}\|y - X\beta\|_2^2 + \lambda\|\alpha\|_1\) s.t. \(\beta = \alpha\) turns the \(\beta\)-update into a smooth ridge regression \((X^T X + \rho I)\beta = X^T y + \rho(\alpha - w)\) and the \(\alpha\)-update into exact scalar soft-thresholding \(S_{\lambda/\rho}(\beta + w)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Woodbury Matrix Identity for \(p \gg n\):&lt;/strong&gt; When features outnumber samples (\(p \gg n\)), factoring the \(p \times p\) matrix \(X^T X + \rho I\) is slow; the Woodbury identity \((X^T X + \rho I)^{-1} = \frac{1}{\rho}I - \frac{1}{\rho^2}X^T(I + \frac{1}{\rho} X X^T)^{-1} X\) shrinks the Cholesky factor down to \(n \times n\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Block Soft-Thresholding for Group Lasso:&lt;/strong&gt; Replacing \(\lambda\|\alpha\|_1\) with \(\lambda \sum_{g=1}^G \|\alpha_g\|_2\) leaves the \(\beta\)-update &lt;em&gt;completely unchanged&lt;/em&gt; and simply swaps scalar soft-thresholding for Euclidean block shrinkage \(\alpha_g = \left(1 - \frac{\lambda/\rho}{\|\beta_g + w_g\|_2}\right)_+ (\beta_g + w_g)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Drop-In Regularizer Swapping:&lt;/strong&gt; Because \(X\) only appears in the \(\beta\)-update, switching between Lasso, Group Lasso, Elastic Net, or Sparse Group Lasso requires changing &lt;em&gt;only one line of code&lt;/em&gt; (the \(\alpha\)-prox)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-admm-iteration-on-a-2-feature-group-lasso&quot;&gt;Worked example: One ADMM Iteration on a 2-Feature Group Lasso&lt;/h3&gt;

&lt;p&gt;Consider a 1-group Group Lasso in \(\mathbb{R}^2\) with \(X = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\), \(y = \begin{bmatrix} 4 \\ 3 \end{bmatrix}\), and group penalty \(\lambda\|\alpha\|_2\) with \(\lambda = 2\):
\(\min_{\beta, \alpha} \; \frac{1}{2}\|y - X\beta\|_2^2 + 2\|\alpha\|_2 \quad \text{subject to} \quad \beta = \alpha.\)
Run one scaled ADMM iteration with \(\rho = 1\) starting from \(\alpha^0 = (0, 0)^T, \; w^0 = (0, 0)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(\beta\)-update (Ridge linear solve):&lt;/strong&gt;
Here \(X^T X + \rho I = \operatorname{diag}(4 + 1, \; 1 + 1) = \operatorname{diag}(5, 2)\) and \(X^T y = (8, 3)^T\).
\(\beta^1 = \begin{bmatrix} 5 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}^{-1}\!\left(\begin{bmatrix} 8 \\ 3 \end{bmatrix} + 1\begin{bmatrix} 0 \\ 0 \end{bmatrix}\right) = \begin{bmatrix} 1.6 \\ 1.5 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\alpha\)-update (Block soft-thresholding with threshold \(\lambda / \rho = 2\)):&lt;/strong&gt;
Compute the vector \(v = \beta^1 + w^0 = (1.6, 1.5)^T\) and its Euclidean norm:
\(\|v\|_2 = \sqrt{1.6^2 + 1.5^2} = \sqrt{2.56 + 2.25} = \sqrt{4.81} \approx 2.1932.\)
Apply block shrinkage:
\(\alpha^1 = \left(1 - \frac{2}{2.1932}\right)_+ \begin{bmatrix} 1.6 \\ 1.5 \end{bmatrix} \approx 0.0881 \begin{bmatrix} 1.6 \\ 1.5 \end{bmatrix} \approx \begin{bmatrix} 0.141 \\ 0.132 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual update:&lt;/strong&gt;
\(w^1 = w^0 + \beta^1 - \alpha^1 \approx (1.459, \; 1.368)^T.\)
Notice how &lt;em&gt;both&lt;/em&gt; coordinates of the group survived together (or would have been zeroed out together had \(\|v\|_2 \le 2\))—while the \(\beta\)-solve stayed a pure linear system!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;lasso-regression&quot;&gt;Lasso regression&lt;/h2&gt;
&lt;p&gt;Let’s solve the Lasso regression problem using ADMM.&lt;/p&gt;

&lt;p&gt;Given \(y\in \mathbb{R}^{n}, X\in \mathbb{R}^{n\times p}\), the Lasso problem is:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\min_{\beta}\frac{1}{2}||y-X\beta||^{2}_{2}+\lambda||\beta||_{1}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In previous chapters, we have solved the Lasso problem using various methods, including &lt;a href=&quot;/contents/en/chapter09/09_01_proximal_gradient_descent/&quot;&gt;proximal gradient descent (ISTA)&lt;/a&gt;, &lt;a href=&quot;/contents/en/chapter09/09_05_03_example_FISTA/&quot;&gt;accelerated proximal gradient descent (FISTA)&lt;/a&gt;, &lt;a href=&quot;/contents/en/chapter15/chapter16/15_barrier_method/&quot;&gt;barrier method&lt;/a&gt;, and &lt;a href=&quot;/contents/en/chapter17/17_primal_dual_interior_point_method/&quot;&gt;primal-dual interior-point method&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As with deriving the dual formulation, the performance of the ADMM algorithm depends on how we set up the auxiliary variables. Among many ways to set auxiliary variables, the following form is known to be one of the most effective:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{\beta, \alpha} &amp;amp;&amp;amp;||y-X\beta||^{2}_{2}+\lambda||\alpha||_{1}\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;\beta-\alpha= 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;admm-updates&quot;&gt;ADMM Updates&lt;/h2&gt;

&lt;p&gt;The ADMM updates for this formulation are derived as follows. The \(\beta\) update involves a quadratic function, so we can find the minimum by differentiation. The \(\alpha\) update is similar to the problem covered in &lt;a href=&quot;/contents/en/chapter07/07_03_04_example_soft-thresholding/&quot;&gt;Chapter 7 (07-03-04)&lt;/a&gt;, which has a soft-thresholding solution.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\beta^{+} &amp;amp;= \underset{\beta}{\operatorname{argmin}}\frac{1}{2}||y-X\beta||^{2}_{2}+\frac{\rho}{2}||\beta-\alpha+w||^{2}_{2}\\\\
&amp;amp;= (X^{T}X+\rho I)^{-1}(X^{T}y+\rho (\alpha-w))\\\\
\alpha^{+} &amp;amp;= \underset{\alpha}{\operatorname{argmin}}\lambda||\alpha||_{1}+\frac{\rho}{2}||\beta^{+}-\alpha+w||^{2}_{2}\\\\
&amp;amp;= S_{\frac{\lambda}{\rho}}(\beta^{+}+w)\\\\
w^{+} &amp;amp;=w+\beta^{+}-\alpha^{+}
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;key-properties&quot;&gt;Key Properties&lt;/h2&gt;

&lt;p&gt;This result has the following characteristics:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The matrix \(X^{T}X+\rho I\) is always invertible regardless of \(X\) since \(\rho&amp;gt;0\).&lt;/li&gt;
  &lt;li&gt;If we precompute the factorization (typically Cholesky factorization) in \(O(p^{3})\) flops, then the \(\beta\) update takes \(O(p^{2})\) flops.&lt;/li&gt;
  &lt;li&gt;The \(\alpha\) update applies the soft-thresholding operator \(S_{t}\), which is identical to the content in &lt;a href=&quot;/contents/en/chapter07/07_03_04_example_soft-thresholding/&quot;&gt;07-03-04&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;The ADMM steps are “almost” equivalent to repeatedly soft-thresholding ridge regression coefficients.&lt;/li&gt;
  &lt;li&gt;Different values of \(\rho\) produce different results.&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter21/lasso.png&quot; alt=&quot;[Fig 1] Comparison of various algorithms for lasso regression (50 instances with n = 100, p = 20) [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Comparison of various algorithms for lasso regression (50 instances with n = 100, p = 20) [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;performance-comparison&quot;&gt;Performance Comparison&lt;/h2&gt;

&lt;p&gt;[Fig 1] compares the convergence of various algorithms for the Lasso regression problem. All algorithms have the same computational complexity per iteration. As can be seen from the convergence speed in the graph, ADMM has similar convergence speed to proximal gradient descent (black). Accelerated proximal gradient descent (red) has “Nesterov ripples” but shows slightly faster convergence speed. We can also confirm that ADMM shows different convergence speeds according to the \(\rho\) value. Coordinate descent (green), which will be discussed later in &lt;a href=&quot;/contents/en/chapter23/23_Coordinate_Descent/&quot;&gt;Chapter 23&lt;/a&gt;, uses more information about the problem and therefore has faster convergence speed compared to other methods. The disadvantage of coordinate descent is that there are conditions required for its application.&lt;/p&gt;

&lt;p&gt;If the \(\rho\) value is set too large, the weight of minimizing the objective function \(f+g\) becomes small, and if the \(\rho\) value is set too small, feasibility decreases. Therefore, setting an appropriate \(\rho\) value is important. For detailed information, see [BPCPE] discussed in the &lt;a href=&quot;/contents/en/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;Chapter 21 reference papers&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;group-lasso-regression&quot;&gt;Group Lasso Regression&lt;/h2&gt;

&lt;p&gt;Similarly, let’s examine solving the Group Lasso regression problem with ADMM. The Group Lasso regression problem is defined as follows for \(y\in \mathbb{R}^{n}, X\in \mathbb{R}^{n \times p}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{\beta}\frac{1}{2}||y-X\beta||^{2}_{2}+\lambda\sum^{G}_{g=1} c_{g}||\beta_{(g)}||_{2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;As with Lasso regression, we can reformulate the problem:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{\beta,\alpha} &amp;amp;&amp;amp;\frac{1}{2}||y-X\beta||^{2}_{2}+\lambda\sum^{G}_{g=1} c_{g}||\alpha_{(g)}||_{2}\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;\beta-\alpha=0.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The ADMM steps are as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\beta^{+} &amp;amp;= (X^{T}X+\rho I)^{-1}(X^{T}y+\rho (\alpha-w))\\\\
\alpha^{+} &amp;amp;= R_{c_{g}\frac{\lambda}{\rho}}(\beta^{+}_{(g)}+w_{(g)})\qquad \text{g = 1,...G}\\\\
w^{+} &amp;amp;=w+\beta^{+}-\alpha^{+}
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;properties-of-group-lasso-admm&quot;&gt;Properties of Group Lasso ADMM&lt;/h2&gt;

&lt;p&gt;This result has the following characteristics:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The matrix \(X^{T}X+\rho I\) is always invertible regardless of \(X\) since \(\rho&amp;gt;0\).&lt;/li&gt;
  &lt;li&gt;If we precompute the factorization (typically Cholesky factorization) in \(O(p^{3})\) flops, then the \(\beta\) update takes \(O(p^{2})\) flops.&lt;/li&gt;
  &lt;li&gt;The \(\alpha\) update applies the group soft-thresholding operator \(R_{t}\), which is defined as follows:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\begin{align}
R_{t}(x) = \left(1-\frac{t}{\lVert x \rVert_{2}}\right)_{+}x
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;admm-for-the-lasso-video&quot;&gt;ADMM for the lasso (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/admm-lasso_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;ADMM alternates a ridge-like \(x\)-update, a soft-thresholding \(z\)-update and a dual update of \(u\), pulling \(x\) and \(z\) together.&lt;/p&gt;

&lt;p&gt;The video uses generic ADMM notation: \(x\) corresponds to \(\beta\), \(z\) to \(\alpha\), and \(u\) to \(w\) (the scaled dual variable); the lesson’s \(X\) and \(y\) are written \(A\) and \(b\). In the video, \(y\) denotes the Lagrange multiplier, not the response vector.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-admm-on-a-lasso&quot;&gt;Try it yourself: ADMM on a lasso&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;admm&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>21-02 Connection to proximal operators</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_02_Connection_to_proximal_operators/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_02_Connection_to_proximal_operators</id>
   <content type="html">&lt;p&gt;At first glance, ADMM looks like a constrained-optimization algorithm built around equality constraints \(Ax + Bz = c\). Yet set \(A = I, B = -I, c = 0\) on the unconstrained composite problem \(\min_x f(x) + g(x)\), and something remarkable happens: &lt;strong&gt;ADMM becomes a pure proximal-operator machine&lt;/strong&gt;—alternating \(\operatorname{prox}_{f/\rho}\) and \(\operatorname{prox}_{g/\rho}\)! Unlike proximal gradient descent (which demands that one term be differentiable), ADMM can minimize the sum of &lt;em&gt;two completely nondifferentiable&lt;/em&gt; functions as long as each has a fast proximal map!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-admm-as-symmetrical-proximal-splitting&quot;&gt;Key ideas: ADMM as Symmetrical Proximal Splitting&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Canonical Consensus Split (\(x = z\)):&lt;/strong&gt; Rewriting \(\min_x f(x) + g(x)\) as \(\min_{x,z} f(x) + g(z) \text{ s.t. } x - z = 0\) gives scaled ADMM updates \(x^k = \operatorname{prox}_{f/\rho}(z^{k-1} - w^{k-1})\) and \(z^k = \operatorname{prox}_{g/\rho}(x^k + w^{k-1})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;No Smoothness Required on Either Block:&lt;/strong&gt; Proximal gradient (ISTA/FISTA) requires \(\nabla f\) to exist and be \(L\)-Lipschitz; proximal ADMM handles nonsmooth \(f\) and nonsmooth \(g\) symmetrically (for instance, \(\ell_1\) loss \(+\) \(\ell_1\) penalty, or two set indicators \(I_C + I_D\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Equivalence to Douglas–Rachford Splitting:&lt;/strong&gt; Defining the reflected variable \(v^k = z^k + w^k\) shows that proximal ADMM is algebraically identical to &lt;strong&gt;Douglas–Rachford operator splitting&lt;/strong&gt; applied to the monotone inclusion \(0 \in \partial f(x) + \partial g(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Moreau Decomposition Shortcut:&lt;/strong&gt; When \(\operatorname{prox}_{g/\rho}\) is hard to compute directly but \(\operatorname{prox}_{\rho g^\ast}\) is easy (e.g., projecting onto an \(\ell_\infty\) dual ball), Moreau’s identity \(v = \operatorname{prox}_{g/\rho}(v) + \frac{1}{\rho}\operatorname{prox}_{\rho g^\ast}(\rho v)\) computes the ADMM update in one line!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-minimizing-the-sum-of-two-nonsmooth-functions-via-proximal-admm&quot;&gt;Worked example: Minimizing the Sum of Two Nonsmooth Functions via Proximal ADMM&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize $$f(x) + g(x) = \underbrace{&lt;/td&gt;
      &lt;td&gt;x - 2&lt;/td&gt;
      &lt;td&gt;}_{f(x)} + \underbrace{&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;}_{g(x)}\((neither function is differentiable at its kink! Optimal set is the entire interval\)x^\star \in [0, 2]\(with value\)2\(). Run proximal ADMM with\)\rho = 1\(starting from\)z^0 = 3, \; w^0 = 0$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write both proximal operators (for \(\rho = 1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;$$\operatorname{prox}_{f}(v) = \arg\min_x&lt;/td&gt;
              &lt;td&gt;x - 2&lt;/td&gt;
              &lt;td&gt;+ \frac{1}{2}(x - v)^2 = 2 + S_1(v - 2)$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;$$\operatorname{prox}_{g}(v) = \arg\min_z&lt;/td&gt;
              &lt;td&gt;z&lt;/td&gt;
              &lt;td&gt;+ \frac{1}{2}(z - v)^2 = S_1(v)$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 (\(z^0 = 3, w^0 = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^1 = \operatorname{prox}_f(3 - 0) = 2 + S_1(1) = 2 + 0 = 2.0\).&lt;/li&gt;
      &lt;li&gt;\(z^1 = \operatorname{prox}_g(2.0 + 0) = S_1(2.0) = 1.0\).&lt;/li&gt;
      &lt;li&gt;\(w^1 = 0 + (2.0 - 1.0) = 1.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2 (\(z^1 = 1.0, w^1 = 1.0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^2 = \operatorname{prox}_f(1.0 - 1.0) = 2 + S_1(-2) = 2 + (-1) = 1.0\).&lt;/li&gt;
      &lt;li&gt;\(z^2 = \operatorname{prox}_g(1.0 + 1.0) = S_1(2.0) = 1.0\).&lt;/li&gt;
      &lt;li&gt;\(w^2 = 1.0 + (1.0 - 1.0) = 1.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact convergence in 2 steps!&lt;/strong&gt;
At \(k = 2\), \(x^2 = z^2 = 1.0 \in [0, 2]\) with primal residual \(r^2 = 0\) and dual residual \(s^2 = 1.0 - 1.0 = 0\)—solving a &lt;em&gt;completely nondifferentiable&lt;/em&gt; composite problem cleanly without subgradient step-size tuning!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;connection-to-proximal-operators&quot;&gt;Connection to Proximal Operators&lt;/h1&gt;

&lt;p&gt;Consider an optimization problem with a single variable that separates into two functions:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\min_{x} f(x)+g(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This can also be expressed by adding a constraint:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\min_{x, z} f(x)+g(z) \qquad \text{subject to  }x=z
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;admm-steps-in-proximal-form&quot;&gt;ADMM Steps in Proximal Form&lt;/h2&gt;

&lt;p&gt;The ADMM steps for this problem are:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;x^{(k)} = {\operatorname{prox}}_{f,\frac{1}{\rho}}(z^{(k-1)}-w^{(k-1)})\\\\
&amp;amp;z^{(k)} = {\operatorname{prox}}_{g,\frac{1}{\rho}}(x^{(k)}+w^{(k-1)})\\\\
&amp;amp;w^{(k)}=w^{(k-1)}+x^{(k)}-z^{(k)}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;where \({\operatorname{prox}}_{f,\frac{1}{\rho}}\) and \({\operatorname{prox}}_{g,\frac{1}{\rho}}\) are the proximal operators of \(f\) and \(g\) respectively, with parameter \(\frac{1}{\rho}\).&lt;/p&gt;

&lt;h2 id=&quot;proximal-operator-definition&quot;&gt;Proximal Operator Definition&lt;/h2&gt;

&lt;p&gt;Recall that for a convex function \(f\), the &lt;a href=&quot;/contents/en/chapter19/19_01_01_Reminder-_proximal_gradient_descent/&quot;&gt;proximal operator&lt;/a&gt; is defined as:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
{\operatorname{prox}}_{f, \lambda}(v) = \underset{x}{\operatorname{argmin}}\left(f(x)+\frac{1}{2\lambda}||x-v||_{2}^{2}\right). 
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;derivation-of-proximal-updates&quot;&gt;Derivation of Proximal Updates&lt;/h2&gt;

&lt;p&gt;The process of deriving ADMM updates in terms of proximal operators is as follows.&lt;/p&gt;

&lt;p&gt;Let \(x^{+}, z^{+}, w^{+}\) be the updated values of \(x, z, w\) after one step.&lt;/p&gt;

&lt;h3 id=&quot;update-for-x&quot;&gt;Update for x:&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
x^{+}&amp;amp; = \underset{x}{\operatorname{argmin}}f(x)+\frac{\rho}{2}||x-z+w||^{2}_{2}\\\\
&amp;amp; =\underset{x}{\operatorname{argmin}}\frac{1}{2\cdot\frac{1}{\rho}}||(z-w)-x||^{2}_{2}+f(x)\\\\
&amp;amp; ={\operatorname{prox}}_{f,\frac{1}{\rho}}(z-w)
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;update-for-z&quot;&gt;Update for z:&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
z^{+}&amp;amp; = \underset{z}{\operatorname{argmin}}g(z)+\frac{\rho}{2}||x^{+}-z+w||^{2}_{2}\\\\
&amp;amp; =\underset{z}{\operatorname{argmin}}\frac{1}{2\cdot\frac{1}{\rho}}||(x^{+}+w)-z||^{2}_{2}+g(z)\\\\
&amp;amp; ={\operatorname{prox}}_{g,\frac{1}{\rho}}(x^{+}+w)
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;key-insight&quot;&gt;Key Insight&lt;/h2&gt;

&lt;p&gt;The original ADMM constraint is \(Ax+Bz = c\), while here the constraint is \(x=z\). That is, when the linear transformation relationship between \(x\) and \(z\) is the identity, we can transform the original ADMM updates into proximal updates.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>21-01 Last time - Dual method, Augmented Lagrangian method, ADMM, ADMM in scaled form</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_01_Last_time_Dual_method,_Augmented_Lagrangian_method,_ADMM,_ADMM_in_scaled_form/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_01_Last_time_Dual_method,_Augmented_Lagrangian_method,_ADMM,_ADMM_in_scaled_form</id>
   <content type="html">&lt;p&gt;Before applying ADMM to Lasso, Robust PCA, and 2D image denoising, it is worth putting all four algorithms from Chapter 20 side by side on a single canvas: &lt;strong&gt;Dual Ascent&lt;/strong&gt;, &lt;strong&gt;Augmented Lagrangian (Method of Multipliers)&lt;/strong&gt;, &lt;strong&gt;Unscaled ADMM&lt;/strong&gt;, and &lt;strong&gt;Scaled ADMM&lt;/strong&gt;. Seeing how each method evolved to cure one exact weakness of its predecessor prevents formula confusion and makes every splitting derivation in Chapter 21 second nature.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-dual-algorithms-in-one-unified-lineage&quot;&gt;Key ideas: Four Dual Algorithms in One Unified Lineage&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dual Ascent (Requires Strict Convexity):&lt;/strong&gt; Updates \(x^k = \arg\min_x L(x, u^{k-1})\) and \(u^k = u^{k-1} + t_k(Ax^k - b)\). Decomposable across blocks, but unstable or unbounded when \(f\) is linear or non-strictly convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Augmented Lagrangian (Cures Instability, Loses Decomposition):&lt;/strong&gt; Adds \(\frac{\rho}{2}\|Ax - b\|_2^2\) and locks \(t_k = \rho\). Converges globally without strong convexity, but cross-terms in \(\|Ax - b\|_2^2\) prevent parallel block solves.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unscaled ADMM (Restores Splitting via Gauss–Seidel):&lt;/strong&gt; Alternates \(x^k = \arg\min_x L_\rho(x, z^{k-1}, u^{k-1})\) and \(z^k = \arg\min_z L_\rho(x^k, z, u^{k-1})\), then updates \(u^k = u^{k-1} + \rho(Ax^k + Bz^k - c)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaled ADMM (Algebraic Simplification via \(w = u/\rho\)):&lt;/strong&gt; Completes the square so both primal steps minimize \(f(x) + \frac{\rho}{2}\|Ax + Bz - c + w\|_2^2\), and the dual update becomes the simple residual accumulator \(w^k = w^{k-1} + Ax^k + Bz^k - c\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-exact-identity-between-unscaled-and-scaled-admm&quot;&gt;Worked example: Verifying Exact Identity Between Unscaled and Scaled ADMM&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Solve $$\min_{x,z} \frac{1}{2}(x - 2)^2 +&lt;/td&gt;
      &lt;td&gt;z&lt;/td&gt;
      &lt;td&gt;\(s.t.\)x - z = 0\(with\)\rho = 2\(from\)z^0 = 0, u^0 = 0\((so\)w^0 = u^0 / \rho = 0$$).&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Unscaled ADMM (Iteration 1):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^1 = \arg\min_x \frac{1}{2}(x - 2)^2 + 0(x - 0) + \frac{2}{2}(x - 0)^2 \implies (x - 2) + 2x = 0 \implies x^1 = \frac{2}{3}\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;$$z^1 = \arg\min_z&lt;/td&gt;
              &lt;td&gt;z&lt;/td&gt;
              &lt;td&gt;+ 0(\tfrac{2}{3} - z) + (z - \tfrac{2}{3})^2 = S_{1/2}!\left(\tfrac{2}{3}\right) = \frac{2}{3} - \frac{1}{2} = \frac{1}{6}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;\(u^1 = 0 + 2\left(\frac{2}{3} - \frac{1}{6}\right) = 2\left(\frac{1}{2}\right) = 1.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaled ADMM (Iteration 1):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^1 = \arg\min_x \frac{1}{2}(x - 2)^2 + (x - 0 + 0)^2 = \frac{2}{3}\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;$$z^1 = \operatorname{prox}_{&lt;/td&gt;
              &lt;td&gt;\cdot&lt;/td&gt;
              &lt;td&gt;/2}!\left(\frac{2}{3} + 0\right) = S_{1/2}!\left(\frac{2}{3}\right) = \frac{1}{6}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;\(w^1 = 0 + \left(\frac{2}{3} - \frac{1}{6}\right) = \frac{1}{2}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check exact correspondence:&lt;/strong&gt;
\(u^1 / \rho = 1.0 / 2 = \frac{1}{2} = w^1\), and both primal iterates \((x^1, z^1) = (\frac{2}{3}, \frac{1}{6})\) match to the last bit!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the previous chapter (Chapter 20) we studied dual methods and ADMM. Before looking at applications of ADMM, let us summarize dual methods, the augmented Lagrangian method, ADMM, and ADMM in scaled form.&lt;/p&gt;

&lt;h2 id=&quot;dual-method&quot;&gt;Dual method&lt;/h2&gt;
&lt;p&gt;Consider the following problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\\\
&amp;amp;\text{ subject to } &amp;amp;&amp;amp;Ax = b
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Assume that \(f\) is strictly convex and closed. The Lagrangian of this problem is&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
L(x,u) = f(x)+u^{T}(Ax-b)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The dual problem is&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{equation}
\max_u -f^{\ast}(-A^T u) - b^T u
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;where \(u\) is the dual variable.&lt;/p&gt;

&lt;p&gt;Dual gradient ascent for this problem repeats the following updates (\(k=1,2,3,...\)).&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x^{(k)}&amp;amp;=\underset{x}{\operatorname{argmin}} L(x,u^{(k-1)}) \\\\
u^{(k)}&amp;amp;= u^{(k-1)} +t_{k}(Ax^{(k)}-b)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(t_{k}\) is the step size at the \(k\)-th iteration.&lt;/p&gt;

&lt;p&gt;In this dual method, as in the first update, the primal variable \(x\) is set to the minimizer of the Lagrangian at the dual variable \(u^{(k-1)}\) from the previous step, and the dual variable \(u\) is updated by gradient ascent, where \(Ax-b\) is the gradient direction.&lt;/p&gt;

&lt;p&gt;The advantage of this method is that when \(f\) is decomposable into \(B\) parts, \(x\) can also be split into \(B\) blocks \(( x =(x_{1}, ...,x_{B})\in \mathbb{R}^{n}, \text{ where }x_{i}\in \mathbb{R}^{n_{i}})\) and the matrix \(A\) into \(B\) sub-matrix blocks \((A = [A_{1}, ..., A_{B}] \text{ where }A_{i} \in \mathbb{R}^{m \times n_{i}})\), so the computation is easy to parallelize and scale. The drawback is that demanding conditions are needed to guarantee convergence: to guarantee primal feasibility, \(f\) must be strongly convex. &lt;a href=&quot;/contents/en/chapter20/20_01_01_Convergence_Analysis/&quot;&gt;[20-01-01]&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;augmented-lagrangian-method&quot;&gt;Augmented Lagrangian method&lt;/h2&gt;
&lt;p&gt;The augmented Lagrangian method, also called the method of multipliers, adds an extra term to the primal problem. As the iterations proceed, the KKT conditions are gradually satisfied. Compared with the dual method, it relaxes the condition needed for convergence (\(f\) strongly convex). In exchange, the problem can no longer be decomposed. The primal problem is defined as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x)+\frac{\rho}{2}||Ax-b||_{2}^{2}&amp;amp;\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;Ax=b
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;where \(\rho&amp;gt;0\). The Lagrangian of this problem is&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
L_{\rho}(x,u)=f(x)+u^{T}(Ax-b)+\frac{\rho}{2}||Ax-b||_{2}^{2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Dual gradient ascent repeats the following (\(k=1,2,3,...\)).&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x^{(k)}&amp;amp;=\underset{x}{\operatorname{argmin}} L_{\rho}(x,u^{(k-1)}) \\\\
u^{(k)}&amp;amp;= u^{(k-1)} +\rho(Ax^{(k)}-b)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;As mentioned above, the advantage of this method is better convergence conditions than the dual method. The drawback is that the added quadratic term destroys decomposability.&lt;/p&gt;

&lt;h2 id=&quot;alternating-direction-method-of-multipliers-admm&quot;&gt;Alternating direction method of multipliers (ADMM)&lt;/h2&gt;
&lt;p&gt;ADMM combines the advantages of the dual method and the augmented Lagrangian method. Suppose the problem is of the following form.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} f(x)+g(z) \qquad \text{subject to  }Ax+Bz=c
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;For this problem we can define the augmented Lagrangian with \(\rho&amp;gt;0\).&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;L_{\rho} (x,z,u) = f(x)+g(z)+u^{T}(Ax+Bz-c)+\frac{\rho}{2}||Ax+Bz-c||_{2}^{2}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;We then update the variables by repeating the following.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{for k = 1,2,3,...}\\\\
&amp;amp;x^{(k)}=\underset{x}{\operatorname{argmin}} L_{\rho}(x,z^{(k-1)},u^{(k-1)})\\\\
&amp;amp;z^{(k)}=\underset{z}{\operatorname{argmin}} L_{\rho}(x^{(k)},z,u^{(k-1)})\\\\
&amp;amp;u^{(k)}=u^{(k-1)}+\rho(Ax^{(k)}+Bz^{(k)}-c)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In ADMM, the primal variables \(x, z\) are not updated jointly but one after the other. When updating sequentially, the other variable takes its most recent value. That is, when updating \(z\) at iteration \(k\) we use \(x^{(k)}\) rather than the value \(x^{(k-1)}\) from the previous iteration, and when updating \(u\) we immediately use the primal variables \(x^{(k)}, z^{(k)}\) just computed in the current iteration.&lt;/p&gt;

&lt;h2 id=&quot;convergence-of-admm&quot;&gt;Convergence of ADMM&lt;/h2&gt;
&lt;p&gt;Without assuming that \(A\) and \(B\) in the constraint have full rank, and under only modest assumptions on \(f\) and \(g\), ADMM satisfies the following for every \(\rho &amp;gt; 0\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Residual convergence: \(r^{(k)} = A x^{(k)} + B z^{(k)} - c \to 0\) as \(k \to \infty\), i.e. the primal iterates approach feasibility.&lt;/li&gt;
  &lt;li&gt;Objective convergence: \(f(x^{(k)}) + g(z^{(k)}) \to f^{\star} + g^{\star}\), where \(f^{\star} + g^{\star}\) is the optimal primal objective value.&lt;/li&gt;
  &lt;li&gt;Dual convergence: \(u^{(k)} \to u^{\star}\), where \(u^{\star}\) is a dual solution.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The convergence rate is not known in general and is still being studied. References on convergence are given in the &lt;a href=&quot;/contents/en/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/&quot;&gt;introduction to Chapter 21&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;admm-in-scaled-form&quot;&gt;ADMM in scaled form&lt;/h2&gt;
&lt;p&gt;ADMM can be written in scaled form by replacing the dual variable \(u\) with the scaled variable \(w=u/\rho\). The ADMM steps then become&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;x^{(k)} = \underset{x}{\operatorname{argmin}} f(x) + \frac{\rho}{2} ||Ax + Bz^{(k-1)} - c + w^{(k-1)} ||_2^2 \\\\
&amp;amp;z^{(k)} = \underset{z}{\operatorname{argmin}} g(z) + \frac{\rho}{2} || Ax^{(k)} + Bz - c + w^{(k-1)} ||_2^2  \\\\
&amp;amp;w^{(k)} = w^{(k-1)} + Ax^{(k)} + Bz^{(k)} - c 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(w^{(k)}\) is the running sum of the residuals up to iteration \(k\), which can also be written as&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
w^{(k)} = w^{(0)} + \sum_{i=1}^k (Ax^{(i)} + Bz^{(i)} - c) 
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>21 Alternating Direction Method of Multipliers</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_00_Alternating_Direction_Method_of_Multipliers/"/>
   <updated>2021-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter21/21_00_Alternating_Direction_Method_of_Multipliers</id>
   <content type="html">&lt;p&gt;Chapter 20 built the engine of &lt;strong&gt;ADMM&lt;/strong&gt;; Chapter 21 takes that engine out onto the open highway of modern statistical learning, matrix decomposition, and distributed computing. What makes ADMM extraordinary in practice is not just its three-line algorithm, but the &lt;em&gt;art of variable splitting&lt;/em&gt;: by choosing the right auxiliary variables \(z\) and linear constraints \(Ax + Bz = c\), seemingly intractable problems—Lasso, Group Lasso, Sparse PCA, Robust PCA, 2D Total Variation denoising, and multi-machine consensus—fracture into cached linear solves and closed-form proximal operators!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-craft-of-admm-variable-splitting&quot;&gt;Key ideas: The Craft of ADMM Variable Splitting&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Proximal-Operator Modularity:&lt;/strong&gt; Splitting \(\min f(x) + g(x)\) into \(\min f(x) + g(z) \text{ s.t. } x = z\) turns ADMM into an alternating pair of proximal maps \(\operatorname{prox}_{f/\rho}\) and \(\operatorname{prox}_{g/\rho}\), allowing each piece to use its own specialized closed-form solver.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Factorization Caching (Pre-Cholesky Advantage):&lt;/strong&gt; In Lasso and ridge-coupled problems, the \(x\)-update solves \((X^T X + \rho I)\beta = \text{rhs}\) with the &lt;em&gt;exact same&lt;/em&gt; matrix at every iteration. Computing the Cholesky factor once at \(k = 0\) drops every subsequent iteration from \(O(p^3)\) to \(O(p^2)\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrix &amp;amp; Spectral Splittings:&lt;/strong&gt; ADMM extends seamlessly from vectors to matrices—combining nuclear-norm singular-value thresholding (low rank) with entrywise soft-thresholding (sparsity) in Robust PCA and Fantope projections in Sparse PCA.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Consensus &amp;amp; Subproblem Parametrization:&lt;/strong&gt; Duplicating variables across machines yields &lt;em&gt;Consensus ADMM&lt;/em&gt; for distributed data, while splitting along orthogonal spatial directions (horizontal vs. vertical chains in 2D Fused Lasso) unlocks dramatic convergence speedups.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-pre-factorizing-xt-x--rho-i-wins&quot;&gt;Worked example: Why Pre-Factorizing \((X^T X + \rho I)\) Wins&lt;/h3&gt;

&lt;p&gt;Suppose we solve a Lasso problem with \(X \in \mathbb{R}^{500 \times 100}\) over \(T = 200\) ADMM iterations using the split \(\min \frac{1}{2}\|y - X\beta\|_2^2 + \lambda\|\alpha\|_1\) s.t. \(\beta = \alpha\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Examine the \(\beta\)-update linear system:&lt;/strong&gt;
\(\left(X^T X + \rho I\right)\beta^{(k)} = X^T y + \rho\big(\alpha^{(k-1)} - w^{(k-1)}\big).\)
Notice that the left-hand matrix \(M = X^T X + \rho I \succ 0\) &lt;strong&gt;never changes across iterations&lt;/strong&gt; (as long as \(\rho\) is fixed)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare naive vs. cached Cholesky cost (\(p = 100, T = 200\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Naive (re-factor every iteration):&lt;/strong&gt; \(200 \times \frac{1}{3} p^3 \approx 6.67 \times 10^7\) FLOPs.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Cached Cholesky (factor \(M = L L^T\) once, then forward/back-solve):&lt;/strong&gt;
\(\frac{1}{3}(100)^3 + 200 \times 2(100)^2 = 3.33 \times 10^5 + 4.00 \times 10^6 \approx 4.33 \times 10^6 \text{ FLOPs}.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Speedup:&lt;/strong&gt;
A single architectural observation—caching \(L\) outside the ADMM loop—delivers an immediate &lt;strong&gt;15× speedup&lt;/strong&gt; (and &lt;strong&gt;150×&lt;/strong&gt; at \(p = 1000\)), turning ADMM into a production-grade statistical solver!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This chapter aims to examine ADMM, which was covered in &lt;a href=&quot;/contents/en/chapter20/20_00_Dual_Methods/&quot;&gt;Chapter 20&lt;/a&gt;, in more detail. The basic concepts are not significantly different in depth from what was covered in Chapter 20, and we will mainly look at application cases.&lt;/p&gt;

&lt;h3 id=&quot;reference-papers&quot;&gt;Reference Papers&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Boyd, Stephen, et al. [BPCPE11] “Distributed optimization and statistical learning via the alternating direction method of multipliers.” Foundations and Trends® in Machine learning 3.1 (2011): 1-122.&lt;/li&gt;
  &lt;li&gt;Hong, Mingyi, and Zhi-Quan Luo. [HL12] “On the linear convergence of the alternating direction method of multipliers.” Mathematical Programming 162.1-2 (2017): 165-199.&lt;/li&gt;
  &lt;li&gt;Deng, Wei, and Wotao Yin. [DY16] “On the global and linear convergence of the generalized alternating direction method of multipliers.” Journal of Scientific Computing 66.3 (2016): 889-916.&lt;/li&gt;
  &lt;li&gt;Iutzeler, Franck, et al. [IBCH14] “Linear convergence rate for distributed optimization with the alternating direction method of multipliers.” 53rd IEEE Conference on Decision and Control. IEEE, 2014.&lt;/li&gt;
  &lt;li&gt;Nishihara, Robert, et al. [NLRPJ15] “A general analysis of the convergence of ADMM.” arXiv preprint arXiv:1502.02009 (2015).&lt;/li&gt;
  &lt;li&gt;Parikh, Neal, and Stephen Boyd. [NB13] “Proximal algorithms.” Foundations and Trends® in Optimization 1.3 (2014): 127-239.&lt;/li&gt;
  &lt;li&gt;Vu, Vincent Q., et al. [VCLR13] “Fantope projection and selection: A near-optimal convex relaxation of sparse PCA.” Advances in neural information processing systems. 2013.&lt;/li&gt;
  &lt;li&gt;Candès, Emmanuel J., et al. [CLMW09] “Robust principal component analysis?.” Journal of the ACM (JACM) 58.3 (2011): 11.&lt;/li&gt;
  &lt;li&gt;Ramdas, Aaditya, and Ryan J. Tibshirani. [RT16] “Fast and flexible ADMM algorithms for trend filtering.” Journal of Computational and Graphical Statistics 25.3 (2016): 839-858.&lt;/li&gt;
  &lt;li&gt;Wytock, Matt, Suvrit Sra, and Jeremy Z. Kolter. [WSK14] “Fast Newton methods for the group fused lasso.” UAI. 2014.&lt;/li&gt;
  &lt;li&gt;Barbero, Alvaro, and Suvrit Sra. [BS14] “Modular proximal optimization for multidimensional total-variation regularization.” arXiv preprint arXiv:1411.0589 (2014).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ADMM convergence relation, : [BPCPE11], [HL12], [DY16], [IBCH14], [NLRPJ15]&lt;br /&gt;
Sparse subspace estimation : [VCLR13]&lt;br /&gt;
Sparse plus low rank decomposition : [CLMW09]&lt;br /&gt;
Consensus ADMM : [BPCPE11], [NB13]&lt;br /&gt;
Subprogram parameterization : [RT16], [WSK14], [BS14]&lt;/p&gt;

&lt;h2 id=&quot;2026-applications-optional&quot;&gt;2026 applications (optional)&lt;/h2&gt;

&lt;p&gt;The classical examples above (Lasso, sparse-plus-low-rank, consensus, fused lasso) are still the right first pass. A 2022–2026 optional lesson maps the &lt;em&gt;same&lt;/em&gt; consensus / proximal split onto federated deep learning (&lt;strong&gt;FedADMM&lt;/strong&gt;), plug-and-play imaging with CNN denoisers, and online distributed optimal power flow. Start at &lt;a href=&quot;/contents/en/chapter21/21_07_modern_applications/&quot;&gt;21-07 Modern applications of ADMM&lt;/a&gt;. It does not replace Boyd et al.; it tells you where the residuals are being monitored in production.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>reference</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/reference/26_reference/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/reference/26_reference</id>
   <content type="html">&lt;ol&gt;
  &lt;li&gt;Boyd, S. and Vandenberghe, L. (2004). &lt;em&gt;&lt;a href=&quot;https://web.stanford.edu/~boyd/cvxbook/&quot;&gt;Convex Optimization&lt;/a&gt;&lt;/em&gt;. Cambridge University Press.&lt;/li&gt;
  &lt;li&gt;Boyd, S. and Vandenberghe, L. (2014). &lt;em&gt;&lt;a href=&quot;https://web.stanford.edu/~boyd/cvxbook/bv_cvxslides.pdf&quot;&gt;Convex Optimization Lecture Slides&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Tibshirani, R. (2016). &lt;em&gt;&lt;a href=&quot;http://www.stat.cmu.edu/~ryantibs/convexopt/&quot;&gt;Convex Optimization: Fall 2016&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Wikipedia. &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Jensen%27s_inequality&quot;&gt;Jensen’s inequality&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Wikipedia. &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Positive-definite_matrix#Further_properties&quot;&gt;Positive-definite matrix - properties&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Wikipedia. &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Matrix_decomposition#Eigendecomposition&quot;&gt;Eigendecomposition&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Wikipedia. &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Eigendecomposition_of_a_matrix#Real_symmetric_matrices&quot;&gt;Eigendecomposition of a matrix - Real symmetric matrices&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Wikipedia. &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Schur_complement&quot;&gt;Schur complement&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Wikipedia. &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Quasiconvex_function&quot;&gt;Quasiconvex function&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Boyd, S. and Dattorro, J. (2013). &lt;em&gt;&lt;a href=&quot;https://web.stanford.edu/class/ee392o/alt_proj.pdf&quot;&gt;Alternating Projections&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Wikipedia. &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Max-flow_min-cut_theorem&quot;&gt;Max-flow min-cut theorem&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Wikipedia. &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm&quot;&gt;Ford-Fulkerson algorithm&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Tibshirani, J. R. (2013). &lt;em&gt;&lt;a href=&quot;https://projecteuclid.org/download/pdfview_1/euclid.ejs/1369148600&quot;&gt;The lasso problem and uniqueness&lt;/a&gt;&lt;/em&gt;. Electronic Journal of Statistics
Vol. 7. pp. 1456–1490.&lt;/li&gt;
  &lt;li&gt;Nocedal, J. (2006). &lt;em&gt;Numerical Optimization 2nd ed&lt;/em&gt;. Springer.&lt;/li&gt;
  &lt;li&gt;Wikipedia. &lt;a href=&quot;https://en.wikipedia.org/wiki/Frank%E2%80%93Wolfe_algorithm&quot;&gt;Frank–Wolfe algorithm&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Wikipedia. &lt;a href=&quot;https://en.wikipedia.org/wiki/Coordinate_descent&quot;&gt;Coordinate descent&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>25 Quy Hoạch Số Nguyên Hỗn Hợp (Phần II)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_Mixed_integer_programming/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_Mixed_integer_programming</id>
   <content type="html">&lt;p&gt;Nếu Chương 24 trao cho bạn thanh kiếm &lt;strong&gt;Nhánh và Cận (Branch and Bound)&lt;/strong&gt; để chia nhỏ bài toán quy hoạch nguyên, thì Chương 25 trao thêm chiếc khiên và mũi khoan sắc bén nhất của vận trù học hiện đại: &lt;strong&gt;Mặt phẳng cắt (Cutting Planes)&lt;/strong&gt; cùng sự hợp nhất huyền thoại &lt;strong&gt;Nhánh và Cắt (Branch and Cut)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Trong thực tế, Nhánh và Cận thuần túy thường bị “nổ cây” khi cận dưới từ nới lỏng LP quá lỏng lẻo. Thay vì vội vàng phân nhánh ngay, Chương 25 chỉ ra cách &lt;em&gt;gọt bớt&lt;/em&gt; những phần thừa chứa nghiệm phân số ra khỏi đa diện LP bằng các bất đẳng thức hợp lệ, rồi áp dụng trực tiếp vũ khí MIP này vào hai bài toán thống kê lừng danh vốn từng bị xem là bất khả thi: &lt;strong&gt;chọn tập con tốt nhất (Best Subset Selection)&lt;/strong&gt; và &lt;strong&gt;hồi quy bình phương trung vị nhỏ nhất (Least Median of Squares)&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-quy-hoạch-số-nguyên-hỗn-hợp-phần-ii&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của Quy hoạch số nguyên hỗn hợp (Phần II)&lt;/h2&gt;

&lt;p&gt;Chương 25 kết nối hình học đa diện cổ điển với thống kê hiện đại qua bốn trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lồi hóa và Bao lồi nguyên (Convexification):&lt;/strong&gt; Mọi quy hoạch tuyến tính nguyên về nguyên tắc đều tương đương với một quy hoạch tuyến tính trên &lt;em&gt;bao lồi&lt;/em&gt; của các điểm nguyên khả thi — vấn đề duy nhất là bao lồi này có thể có số mặt lớn theo hàm mũ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lát cắt Gomory và Bài toán tách (Cutting Planes &amp;amp; Separation):&lt;/strong&gt; Thay vì liệt kê hết mọi mặt của bao lồi, ta chỉ sinh ra đúng một siêu phẳng &lt;em&gt;cắt đứt nghiệm phân số hiện tại&lt;/em&gt; mà không chạm vào bất kỳ điểm nguyên khả thi nào.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhánh và Cắt (Branch and Cut):&lt;/strong&gt; Kết hợp tinh hoa của hai thế giới — dùng mặt phẳng cắt để siết chặt cận dưới ngay tại nút gốc và các nút trung gian, rồi mới phân nhánh khi cần thiết — giúp tốc độ giải tăng hàng triệu lần trong ba thập kỷ qua.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;MIP cho Thống kê hiện đại (Best Subset &amp;amp; LQS):&lt;/strong&gt; Nhờ khởi động nóng bằng thuật toán bậc nhất rời rạc và MIP hiện đại, các bài toán thống kê phi lồi từng bị thay thế bằng xấp xỉ Lasso nay có thể được giải &lt;em&gt;chính xác&lt;/em&gt; kèm chứng nhận tối ưu ở quy mô hàng trăm đến hàng nghìn biến.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-một-lát-cắt-duy-nhất-mạnh-bằng-cả-một-nhánh-cây&quot;&gt;Giải thích: Một lát cắt duy nhất mạnh bằng cả một nhánh cây&lt;/h3&gt;

&lt;p&gt;Hãy quay lại bài toán cực tiểu hóa \(\min -3x_1 - 2x_2\) thỏa mãn \(2x_1 + 2x_2 \le 5\) với \(x_1, x_2 \in \mathbb{Z}_+\) để thấy phép màu của mặt phẳng cắt.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trước khi thêm lát cắt:&lt;/strong&gt;
Miền nới lỏng LP là tam giác \(2x_1 + 2x_2 \le 5,\; x_1, x_2 \ge 0\). Nghiệm LP nằm tại đỉnh phân số \((2.5,\; 0)\) với giá trị \(-7.5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suy ra một lát cắt hợp lệ cực đơn giản:&lt;/strong&gt;
Chia hai vế của \(2x_1 + 2x_2 \le 5\) cho \(2\), ta được \(x_1 + x_2 \le 2.5\).
Nhưng vì \(x_1, x_2\) đều là số nguyên, tổng \(x_1 + x_2\) &lt;strong&gt;bắt buộc phải là số nguyên&lt;/strong&gt;, nên nó không thể vượt quá \(\lfloor 2.5 \rfloor = 2\)!
Vậy bất đẳng thức \(x_1 + x_2 \le 2\) là một &lt;strong&gt;mặt phẳng cắt hợp lệ&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sau khi thêm đúng 1 lát cắt \(x_1 + x_2 \le 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Kiểm tra nghiệm phân số cũ \((2.5, 0)\): \(2.5 + 0 = 2.5 &amp;gt; 2\) — &lt;strong&gt;bị cắt bỏ ngay lập tức!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;Kiểm tra mọi điểm nguyên khả thi cũ \((0,0), (1,0), (2,0), (0,1), (1,1), (0,2)\): tất cả đều có \(x_1 + x_2 \le 2\) — &lt;strong&gt;được bảo toàn 100%!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;Giải lại LP mới: nghiệm nhảy thẳng về đỉnh nguyên \((2, 0)\) với giá trị \(-6\). Bài toán được giải xong ngay lập tức mà &lt;strong&gt;không cần rẽ nhánh dù chỉ một lần&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chương này trình bày thuật toán mặt phẳng cắt (cutting plane) — một trong những công cụ cốt lõi của quy hoạch nguyên (IP) — cùng thuật toán nhánh và cắt (branch and cut), là sự kết hợp được triển khai phổ biến nhất trong các bộ giải thực tế.&lt;/p&gt;

&lt;p&gt;Tiếp theo, chương minh họa hai ví dụ mở rộng của quy hoạch nguyên hỗn hợp trong thống kê: chọn tập con tốt nhất (best subset selection) và hồi quy bình phương trung vị nhỏ nhất / hồi quy phân vị nhỏ nhất (least median of squares / least quantile regression).&lt;/p&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Belotti, Kirches, Leyffer, Linderoth, Luedke, and Mahajan (2012), “Mixed-integer nonlinear optimization”&lt;/li&gt;
  &lt;li&gt;Bertsimas and Mazumder (2016), “Best subset selection via a modern optimization lens”&lt;/li&gt;
  &lt;li&gt;Bertsimas, King, and Mazumder (2014), “Least quantile regression via modern optimization”&lt;/li&gt;
  &lt;li&gt;Conforti, Cornuejols, and Zambelli (2014), “Integer programming”&lt;/li&gt;
  &lt;li&gt;Wolsey (1998), “Integer programming”&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ứng-dụng-giai-đoạn-20222026-tùy-chọn&quot;&gt;Ứng dụng giai đoạn 2022–2026 (tùy chọn)&lt;/h2&gt;

&lt;p&gt;Bài toán chọn tập con tốt nhất bằng MIP vẫn là ví dụ tiêu biểu trong thống kê; cùng kỹ thuật mã hóa big-\(M\) cho hàm kích hoạt ReLU hiện còn được dùng để chọn đặc trưng cho mạng nơ-ron đã huấn luyện, &lt;em&gt;chứng nhận&lt;/em&gt; độ bền vững đối kháng và xây dựng cây phân loại tối ưu. Bên cạnh đó, các nghiên cứu năm 2024 về học quy tắc chọn mặt phẳng cắt kiểu Gomory biến chính quy trình ở mục 25-01 thành bài toán học máy. Đọc thêm tại bài tùy chọn: &lt;a href=&quot;/contents/vi/chapter25/25_03_modern_applications/&quot;&gt;25-03 Ứng dụng hiện đại của MIP trong khoa học dữ liệu&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>25-02 Hai ví dụ mở rộng</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_02_Two_extended_examples/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_02_Two_extended_examples</id>
   <content type="html">&lt;p&gt;Trong nhiều thập kỷ, sách giáo khoa thống kê từng dạy một quan niệm gần như bất di bất dịch: các bài toán thống kê lý tưởng như &lt;strong&gt;chọn đúng \(k\) biến tốt nhất&lt;/strong&gt; (ràng buộc \(\|\beta\|_0 \le k\)) hay &lt;strong&gt;hồi quy bình phương trung vị nhỏ nhất&lt;/strong&gt; (LMS, chống nhiễu tới 50%) tuy đẹp về mặt thống kê nhưng là &lt;em&gt;NP-khó&lt;/em&gt;, nên buộc phải thay thế bằng các xấp xỉ lồi như Lasso (\(\ell_1\)) hay hồi quy Huber.&lt;/p&gt;

&lt;p&gt;Hai bài học mở rộng tiếp theo sẽ đảo ngược quan niệm cũ đó: nhờ sự nhảy vọt của công nghệ &lt;strong&gt;Nhánh và Cắt&lt;/strong&gt; kết hợp với khởi động nóng từ tối ưu bậc nhất, cả hai bài toán thống kê kinh điển này đều có thể được mô hình hóa gọn gàng thành &lt;strong&gt;quy hoạch nguyên hỗn hợp (MIP)&lt;/strong&gt; và giải chính xác ở quy mô thực tế!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-nối-thống-kê-cổ-điển-với-mip-hiện-đại&quot;&gt;Kiến thức cần nhớ: Ba trụ cột nối Thống kê cổ điển với MIP hiện đại&lt;/h2&gt;

&lt;p&gt;Trước khi đi sâu vào chi tiết của từng mô hình ở mục 25-02-01 và 25-02-02, hãy nhìn bức tranh chung qua ba trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Tính phi lồi của các chuẩn thống kê lý tưởng:&lt;/strong&gt; Cả phép đếm số biến khác không \(|\beta|_0\) lẫn phép lấy trung vị phần dư $$\operatorname{median}&lt;/td&gt;
          &lt;td&gt;r_i&lt;/td&gt;
          &lt;td&gt;$$ đều là các hàm không lồi, không liên tục hoặc đa cực tiểu cục bộ — khiến gradient descent thông thường dễ bị mắc kẹt.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sức mạnh mã hóa của Biến nhị phân \(z_i \in \{0, 1\}\):&lt;/strong&gt; Chỉ cần gắn một công tắc \(z_i\) cho mỗi &lt;em&gt;đặc trưng&lt;/em&gt; (chọn hay không chọn trong Best Subset) hoặc cho mỗi &lt;em&gt;mẫu dữ liệu&lt;/em&gt; (tính vào phần dư trung vị hay bỏ qua như điểm ngoại lai trong LMS), ta chuyển toàn bộ tính phi lồi về dạng quy hoạch nguyên hỗn hợp có cấu trúc chặt chẽ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược Lai (Hybrid Warm-Start + MIP):&lt;/strong&gt; Tối ưu bậc nhất rời rạc chạy cực nhanh để tìm một nghiệm khả thi chất lượng cao (cận trên \(\bar{z}\) tốt ngay từ giây đầu tiên), sau đó bộ giải MIP tiếp quản để vừa cải thiện thêm nghiệm vừa cung cấp &lt;strong&gt;chứng nhận tối ưu toàn cục&lt;/strong&gt; qua MIP gap.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-minh-họa-nhỏ-vì-sao-lms-chống-điểm-ngoại-lai-vượt-trội-hơn-ls&quot;&gt;Giải thích: Minh họa nhỏ vì sao LMS chống điểm ngoại lai vượt trội hơn LS&lt;/h3&gt;

&lt;p&gt;Xét bộ dữ liệu 1 biến chỉ gồm 3 điểm \((x_i, y_i)\): \((1, 1)\), \((2, 2)\), và một điểm ngoại lai nặng \((3, 10)\). Ta muốn khớp đường thẳng đi qua gốc tọa độ \(y = \beta x\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng Bình phương tối thiểu (OLS — cực tiểu \(\sum (y_i - \beta x_i)^2\)):&lt;/strong&gt;
\(\hat{\beta}_{\text{OLS}} = \frac{\sum x_i y_i}{\sum x_i^2} = \frac{1(1) + 2(2) + 3(10)}{1^2 + 2^2 + 3^2} = \frac{35}{14} = 2.5.\)
Chỉ vì 1 điểm ngoại lai \((3, 10)\), đường hồi quy bị kéo lệch hoàn toàn từ hệ số góc đúng \(1.0\) lên thành \(2.5\) (sai số trên hai điểm sạch lên tới \(1.5\) và \(3.0\))!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng Bình phương trung vị nhỏ nhất (LMS — cực tiểu \(\operatorname{median}|y_i - \beta x_i|\)):&lt;/strong&gt;
Xét \(\beta = 1\): ba phần dư tuyệt đối là \(|1 - 1| = 0\), \(|2 - 2| = 0\), và \(|10 - 3| = 7\).
Sắp xếp tăng dần: \((0,\; 0,\; 7)\) — &lt;strong&gt;trung vị bằng đúng \(0\)&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt; Vì trung vị không thể âm, \(\hat{\beta}_{\text{LMS}} = 1\) đạt cực tiểu tuyệt đối \(0\) và hoàn toàn miễn nhiễm trước điểm ngoại lai \((3, 10)\) — dù bạn đổi \(10\) thành \(1{,}000{,}000\)! Nhưng để tìm được \(\beta\) như vậy trong không gian nhiều chiều, ta cần công cụ MIP ở hai bài học tiếp theo.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Phần này trình bày hai ví dụ ứng dụng mở rộng của quy hoạch số nguyên hỗn hợp trong thống kê và học máy:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Chọn tập con tốt nhất (Best subset selection)&lt;/li&gt;
  &lt;li&gt;Hồi quy bình phương trung vị nhỏ nhất và hồi quy phân vị nhỏ nhất (Least median of squares / Least quantile regression)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>25-02-02 Least median of squares và least quantile regression</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_02_02_Least_mean_squares/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_02_02_Least_mean_squares</id>
   <content type="html">&lt;p&gt;Nếu dữ liệu thực tế chứa những lỗi nhập liệu khổng lồ hoặc các cảm biến bị hỏng đột ngột, hồi quy bình phương tối thiểu (LS) có thể sụp đổ chỉ vì &lt;strong&gt;một điểm ngoại lai duy nhất&lt;/strong&gt; (điểm sụp đổ \(0\%\)). Peter Rousseeuw (1984) đề xuất một ý tưởng cực kỳ táo bạo: thay vì cực tiểu hóa &lt;em&gt;tổng&lt;/em&gt; bình phương phần dư, hãy cực tiểu hóa &lt;strong&gt;trung vị&lt;/strong&gt; của các phần dư tuyệt đối (&lt;strong&gt;Least Median of Squares — LMS&lt;/strong&gt;), đạt điểm sụp đổ lý thuyết cao nhất có thể là gần \(50\%\)!&lt;/p&gt;

&lt;p&gt;Thách thức duy nhất khiến LMS ít được dùng chính xác trong suốt 30 năm là tính NP-khó của nó. Bài học này trình bày cách Bertsimas và Mazumder (2014) viết lại bài toán tổng quát &lt;strong&gt;Least Quantile Regression (LQS)&lt;/strong&gt; thành một quy hoạch nguyên hỗn hợp (MILP) gọn gàng, kết hợp khởi động nóng bằng thuật toán bậc nhất để giải chính xác và chứng nhận nghiệm.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-hồi-quy-phân-vị-nhỏ-nhất-lqs-bằng-mip&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của Hồi quy phân vị nhỏ nhất (LQS) bằng MIP&lt;/h2&gt;

&lt;p&gt;Để hiểu trọn vẹn công thức MILP của bài toán LQS, hãy nắm chắc bốn trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điểm sụp đổ (Breakdown Point) và Độ bền vững:&lt;/strong&gt; LS (chuẩn \(\ell_2\)) bị kéo lệch vô hạn bởi 1 điểm ngoại lai; LAD (chuẩn \(\ell_1\)) bền vững với ngoại lai ở nhãn \(y\) nhưng vẫn dễ bị phá bởi điểm đòn bẩy cao ở \(X\); LMS/LQS chỉ quan tâm tới phần dư nhỏ thứ \(q\) nên miễn nhiễm ngay cả khi gần một nửa mẫu vừa hỏng \(X\) vừa hỏng \(y\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Mã hóa thống kê thứ tự $$&lt;/td&gt;
          &lt;td&gt;r_{(q)}&lt;/td&gt;
          &lt;td&gt;\(bằng biến nhị phân:** Muốn giá trị\)\gamma\(lớn hơn hoặc bằng ít nhất\)q\(phần dư tuyệt đối, ta gắn biến nhị phân\)z_i \in {0, 1}\(cho mỗi mẫu\)i\(với ràng buộc\)\sum_{i=1}^n z_i \ge q\(và\)&lt;/td&gt;
          &lt;td&gt;r_i&lt;/td&gt;
          &lt;td&gt;\le \gamma + M(1 - z_i)\(. Khi\)z_i = 1\((mẫu sạch được chọn), phần dư bị ép\)&lt;/td&gt;
          &lt;td&gt;r_i&lt;/td&gt;
          &lt;td&gt;\le \gamma\(; khi\)z_i = 0\((mẫu ngoại lai), ràng buộc được nới lỏng bởi hằng số lớn\)M$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu phân rã hàm hiệu hai hàm lồi (Difference-of-Convex / First-Order Heuristic):&lt;/strong&gt; Vì tổng \(q\) phần dư nhỏ nhất có thể viết dưới dạng hiệu của hai hàm lồi, thuật toán bậc nhất lặp luân phiên giữa tuyến tính hóa phần lõm (chọn tập \(q\) mẫu có phần dư nhỏ nhất) và giải bài toán lồi con để tạo điểm khởi động nóng cực tốt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chứng nhận toàn cục qua MIP Gap:&lt;/strong&gt; Khác với các thuật toán chọn ngẫu nhiên cổ điển (như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lqs&lt;/code&gt; trong R chỉ lấy mẫu vài tổ hợp và không biết mình cách tối ưu bao xa), khung MILP cho biết chính xác khoảng cách tới nghiệm toàn cục.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-mô-hình-milp-của-lqs-trên-dữ-liệu-có-ngoại-lai-cực-đoan&quot;&gt;Giải thích: Tính tay mô hình MILP của LQS trên dữ liệu có ngoại lai cực đoan&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét bài toán ước lượng hằng số vị trí \(\beta \in \mathbb{R}\) (tức mô hình \(r_i = y_i - \beta\)) cho 3 quan sát \(y = (1,\; 2,\; 100)^T\), với phân vị trung vị \(q = 2\) (tối thiểu hóa phần dư nhỏ thứ 2, tức $$&lt;/td&gt;
      &lt;td&gt;r_{(2)}&lt;/td&gt;
      &lt;td&gt;$$).&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập bài toán MILP với \(M = 200\):&lt;/strong&gt;
Ta cần tìm \(\beta \in \mathbb{R}\), \(\gamma \ge 0\) và \(z_1, z_2, z_3 \in \{0, 1\}\) sao cho:
\(\min\ \gamma \qquad \text{s.t. } |y_i - \beta| \le \gamma + 200(1 - z_i) \; (i = 1, 2, 3), \quad z_1 + z_2 + z_3 \ge 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xét tổ hợp chọn 2 điểm sạch \(z = (1, 1, 0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Ràng buộc hiệu lực cho \(i = 1, 2\): $$&lt;/td&gt;
              &lt;td&gt;1 - \beta&lt;/td&gt;
              &lt;td&gt;\le \gamma\(và\)&lt;/td&gt;
              &lt;td&gt;2 - \beta&lt;/td&gt;
              &lt;td&gt;\le \gamma$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Ràng buộc cho điểm ngoại lai \(i = 3\) (\(z_3 = 0\)): $$&lt;/td&gt;
              &lt;td&gt;100 - \beta&lt;/td&gt;
              &lt;td&gt;\le \gamma + 200$$ (tự động thỏa mãn thoải mái!).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Để cực tiểu hóa $$\gamma = \max(&lt;/td&gt;
              &lt;td&gt;1 - \beta&lt;/td&gt;
              &lt;td&gt;,\;&lt;/td&gt;
              &lt;td&gt;2 - \beta&lt;/td&gt;
              &lt;td&gt;)\(, ta chọn\)\beta\(nằm chính giữa\)1\(và\)2\(:\)\beta^\star = 1.5\(, cho ra\)\gamma^\star = 0.5$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh với hai tổ hợp còn lại và các chuẩn khác:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu chọn \(z = (1, 0, 1)\) (gồm \(1\) và \(100\)): \(\gamma = \frac{100 - 1}{2} = 49.5 \gg 0.5\).&lt;/li&gt;
      &lt;li&gt;Nếu chọn \(z = (0, 1, 1)\) (gồm \(2\) và \(100\)): \(\gamma = \frac{100 - 2}{2} = 49.0 \gg 0.5\).&lt;/li&gt;
      &lt;li&gt;Trong khi đó, Bình phương tối thiểu (LS) cho \(\hat{\beta}_{\text{LS}} = \frac{1 + 2 + 100}{3} = 34.33\) — hoàn toàn vô dụng!
Ví dụ nhỏ này cho thấy rõ ràng cách biến nhị phân \(z_i\) tự động “gạt” điểm ngoại lai \(100\) ra khỏi mục tiêu cực tiểu hóa \(\gamma\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ở các chương trước, bài toán hồi quy thường được giải bằng cách cực tiểu hóa chuẩn \(l_2\) hoặc chuẩn \(l_1\) của vector phần dư. Để đạt độ bền vững (robustness) cao hơn trước các điểm ngoại lai, ta có thể cực tiểu hóa &lt;em&gt;trung vị&lt;/em&gt; của phần dư — phương pháp mang tên &lt;strong&gt;Least Median of Squares (LMS)&lt;/strong&gt;. Ước lượng này có điểm sụp đổ gần 50%, tức vẫn giữ được độ ổn định ngay cả khi gần một nửa dữ liệu bị nhiễu nặng. Tuy nhiên, bài toán LMS lại thuộc lớp NP-khó.&lt;/p&gt;

&lt;p&gt;Mục này giới thiệu cách mô hình hóa và giải bài toán tổng quát hơn là &lt;strong&gt;Least Quantile of Squares (LQS)&lt;/strong&gt; bằng quy hoạch nguyên hỗn hợp.&lt;/p&gt;

&lt;h2 id=&quot;bình-phương-trung-vị-nhỏ-nhất-least-median-of-squares&quot;&gt;Bình phương trung vị nhỏ nhất (Least Median of Squares)&lt;/h2&gt;

&lt;p&gt;Cho ma trận đặc trưng \(X = [x^{1} \quad \dotsc \quad x^{p}] \in \mathbb{R}^{n \times p}\), vector phản hồi \(y \in \mathbb{R}^{n}\) và hệ số \(\beta \in \mathbb{R}^{p}\), đặt vector phần dư \(r := y - X\beta\).&lt;/p&gt;

&lt;h3 id=&quot;so-sánh-với-các-chuẩn-hồi-quy-quen-thuộc&quot;&gt;So sánh với các chuẩn hồi quy quen thuộc&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Bình phương tối thiểu (Least Squares — LS): \(\beta_{LS} := \underset{\beta}{\text{argmin}} \sum_{i} r^2_i\)&lt;/li&gt;
  &lt;li&gt;Độ lệch tuyệt đối nhỏ nhất (Least Absolute Deviation — LAD): \(\beta_{LAD} := \underset{\beta}{\text{argmin}} \sum_{i} \lvert r_{i} \rvert\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;least-median-of-squares-lms&quot;&gt;Least Median of Squares (LMS)&lt;/h3&gt;

&lt;blockquote&gt;
\[\beta_{LMS} := \underset{\beta}{\text{argmin}} (\text{median} \lvert r_{i} \rvert )\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;hồi-quy-phân-vị-nhỏ-nhất-least-quantile-regression&quot;&gt;Hồi quy phân vị nhỏ nhất (Least Quantile Regression)&lt;/h2&gt;

&lt;p&gt;Tổng quát hóa từ trung vị sang phân vị thứ \(q\), bài toán &lt;strong&gt;Least Quantile of Squares (LQS)&lt;/strong&gt; cực tiểu hóa phần dư tuyệt đối nhỏ thứ \(q\) (ký hiệu \(\lvert r_{(q)} \rvert\)):&lt;/p&gt;

&lt;blockquote&gt;
\[\beta_{LQS} := \underset{\beta}{\text{argmin}} (\lvert r_{(q)} \rvert ), \quad 1 \le q \le n, \quad \lvert r_{(1)} \rvert \le \lvert r_{(2)} \rvert \le \cdots \le \lvert r_{(n)} \rvert\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;ý-tưởng-lập-mô-hình&quot;&gt;Ý tưởng lập mô hình&lt;/h3&gt;

&lt;p&gt;Để biểu diễn bài toán này bằng quy hoạch nguyên hỗn hợp, với mỗi quan sát \(i\) ta dùng một biến nhị phân nhằm phân tách hai nhóm phần dư:&lt;/p&gt;

&lt;blockquote&gt;
\[\lvert r_{i} \rvert \le \lvert r_{(q)} \rvert \quad \text{hoặc} \quad \lvert r_{i} \rvert \ge \lvert r_{(q)} \rvert\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;công-thức-quy-hoạch-nguyên-hỗn-hợp&quot;&gt;Công thức quy hoạch nguyên hỗn hợp&lt;/h3&gt;

&lt;p&gt;Đưa vào các biến phụ (slack) không âm \(\bar{\mu_{i}}\), \(\mu_{i}\) và các biến nhị phân \(z_i\) sao cho \(z_i = 1\) ứng với \(q\) phần dư có trị tuyệt đối nhỏ nhất và \(z_i = 0\) ứng với \(n-q\) phần dư còn lại:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
  \min_{\beta, \mu, \bar{\mu}, z, \gamma} &amp;amp; \quad {\gamma} \\
  \text{subject to} &amp;amp; \quad  \gamma \ge \lvert r_{i} \rvert - \bar{\mu_{i}}, \quad i = 1, \dots, n \\\\
  &amp;amp; \quad  \gamma \le \lvert r_{i} \rvert + \mu_{i}, \quad i = 1, \dots, n \\\\
  &amp;amp; \quad \bar{\mu_{i}} \le M \cdot (1-z_{i}), \quad i = 1, \dots, n \\\\
  &amp;amp; \quad \mu_{i} \le M \cdot z_{i}, \quad i = 1, \dots, n \\\\
  &amp;amp; \quad \sum^{n}_{i=1} z_{i} = q \\\\
  &amp;amp; \quad \mu_{i}, \bar{\mu_{i}} \ge 0, \quad i = 1, \dots, n \\\\
  &amp;amp; \quad z_{i} \in \{0, 1\},  \quad i = 1, \dots, n
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong công thức trên, hai nhóm ràng buộc đầu chứa giá trị tuyệt đối \(\lvert r_{i} \rvert\) (đặc biệt ràng buộc \(\gamma \le \lvert r_i \rvert + \mu_i\) là không lồi), nên cần biểu diễn lại các ràng buộc chứa giá trị tuyệt đối về dạng tuyến tính hóa/lồi thích hợp trước khi giải bằng nới lỏng lồi.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán-bậc-nhất&quot;&gt;Thuật toán bậc nhất&lt;/h2&gt;

&lt;p&gt;Ta có thể biểu diễn phần dư thứ \(q\) dưới dạng hiệu của hai hàm lồi \(H_{q}(\beta)\) và \(H_{q+1}(\beta)\):&lt;/p&gt;

&lt;blockquote&gt;
\[\lvert r_{(q)} \rvert = \lvert y_{(q)} - x^{T}_{(q)} \beta \rvert = H_{q}(\beta) - H_{q+1}(\beta)\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(H_{q}(\beta)\) là tổng của \(n - q + 1\) phần dư tuyệt đối lớn nhất:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
H_{q}(\beta) = \sum^{n}_{i=q} \lvert y_{(i)} - x^{T}_{(i)} \beta \rvert  = &amp;amp;
\max_{w} \sum^{n}_{i=1} w_i \lvert y_{(i)} - x^{T}_{(i)} \beta \rvert \\\\
&amp;amp; \text{subject to} \quad \sum^{n}_{i=1}  w_i  = n − q + 1 \\\\
&amp;amp;0 \le w_i \le 1, \quad i = 1, \dots, n
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Khi các phần dư tuyệt đối được sắp theo thứ tự tăng dần, lấy tổng từ phần tử thứ \(q\) trở đi trừ đi tổng từ phần tử thứ \(q+1\) trở đi sẽ thu được đúng \(\lvert r_{(q)} \rvert\).&lt;/p&gt;

&lt;p&gt;Nhờ biểu diễn hiệu hai hàm lồi này, ta có thể dùng thuật toán dưới đạo hàm (subgradient) để tìm một cực tiểu địa phương của \(H_{q}(\beta) - H_{q+1}(\beta)\) làm điểm khởi động nóng cho bộ giải MIP.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Xem chi tiết trong bài báo &lt;a href=&quot;https://arxiv.org/pdf/1310.8625.pdf&quot;&gt;LEAST QUANTILE REGRESSION VIA MODERN OPTIMIZATION&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kết-quả-thực-nghiệm&quot;&gt;Kết quả thực nghiệm&lt;/h2&gt;

&lt;p&gt;Các đồ thị dưới đây minh họa kết quả thực nghiệm của bài toán Least Quantile of Squares từ bài báo trên.&lt;/p&gt;

&lt;h3 id=&quot;mixed-integer-programming-gap&quot;&gt;Mixed integer programming gap&lt;/h3&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_06_LQS_results1.png&quot; alt=&quot;[Hình 1] Mixed integer programming gap [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Mixed integer programming gap [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;cold-start-và-warm-start&quot;&gt;Cold start và Warm start&lt;/h3&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_07_LQS_results2.png&quot; alt=&quot;[Hình 2] Cold start và Warm start [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Cold start và Warm start [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>25-02-01 Chọn tập con tốt nhất (Best subset selection)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_02_01_Best_subset_selection/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_02_01_Best_subset_selection</id>
   <content type="html">&lt;p&gt;Trong hồi quy thống kê, mục tiêu nguyên thủy khi chọn đặc trưng là giữ lại đúng tối đa \(k\) biến quan trọng nhất (\(\|\beta\|_0 \le k\)). Hồi quy Lasso (\(\ell_1\)) ra đời như một phép thay thế lồi thông minh, nhưng nó đi kèm một cái giá cố hữu: để ép các hệ số nhiễu về \(0\), Lasso cũng đồng thời &lt;strong&gt;co nhỏ (gây thiên lệch — shrinkage bias)&lt;/strong&gt; các hệ số thật sự quan trọng.&lt;/p&gt;

&lt;p&gt;Năm 2016, Dimitris Bertsimas, Angela King và Rahul Mazumder công bố bài báo gây tiếng vang lớn trên &lt;em&gt;Annals of Statistics&lt;/em&gt;, chứng minh rằng với kỹ thuật &lt;strong&gt;MIP hiện đại kết hợp khởi động nóng bằng thuật toán bậc nhất rời rạc&lt;/strong&gt;, bài toán chọn tập con tốt nhất vốn bị coi là “bất khả thi với \(p &amp;gt; 30\)” nay có thể giải chính xác tới quy mô hàng trăm, hàng nghìn đặc trưng!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-best-subset-selection-bằng-mip&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của Best Subset Selection bằng MIP&lt;/h2&gt;

&lt;p&gt;Bài học này kết hợp khéo léo tối ưu liên tục và tối ưu rời rạc qua bốn trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mã hóa ràng buộc \(\|\beta\|_0 \le k\) bằng Big-\(M\) (hoặc SOS-1):&lt;/strong&gt; Gắn mỗi hệ số \(\beta_i\) với một biến nhị phân \(z_i \in \{0, 1\}\) qua điều kiện \(-M z_i \le \beta_i \le M z_i\) và \(\sum_{i=1}^p z_i \le k\). Khi \(z_i = 0\), \(\beta_i\) bị khóa cứng bằng \(0\); tổng số biến khác \(0\) không bao giờ vượt quá \(k\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán bậc nhất rời rạc (Discrete First-Order — Projected Gradient trên \(\ell_0\)):&lt;/strong&gt; Tương tự Proximal Gradient nhưng thay phép co ngưỡng mềm (của Lasso) bằng &lt;strong&gt;phép co ngưỡng cứng (hard thresholding)&lt;/strong&gt; \(H_k(\cdot)\) — giữ lại đúng \(k\) thành phần có trị tuyệt đối lớn nhất và đặt các thành phần còn lại bằng \(0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khởi động nóng (Warm Start) thu hẹp MIP Gap:&lt;/strong&gt; Thuật toán bậc nhất rời rạc tìm ra một tập con rất tốt chỉ trong tích tắc, cung cấp ngay cận trên chặt cho bộ giải MIP. Nhờ đó, bộ giải MIP không phải mò mẫm từ đầu mà tập trung năng lượng vào việc chứng nhận tối ưu (đóng MIP gap).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh Khả năng phát hiện tính thưa (Sparsity Detection):&lt;/strong&gt; Khi tỷ số tín hiệu trên nhiễu (SNR) cao, Best Subset Selection tách biệt đặc trưng thật và nhiễu sắc nét hơn Lasso vì không làm co các hệ số lớn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-big-m-và-1-bước-discrete-first-order-cho-k--1&quot;&gt;Giải thích: Tính tay Big-\(M\) và 1 bước Discrete First-Order cho \(k = 1\)&lt;/h3&gt;

&lt;p&gt;Xét bài toán chọn đúng \(k = 1\) đặc trưng tốt nhất cho \(X = \begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}\) và \(y = \begin{pmatrix} 3 \\ 4 \end{pmatrix}\) (mục tiêu \(\min \frac{1}{2}\|y - X\beta\|_2^2\) với \(\|\beta\|_0 \le 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập mô hình MIP với \(M = 5\):&lt;/strong&gt;
\(\min_{\beta, z}\ \frac{1}{2}(3 - \beta_1)^2 + \frac{1}{2}(4 - 2\beta_2)^2 \quad \text{s.t. } |\beta_1| \le 5z_1,\; |\beta_2| \le 5z_2,\; z_1 + z_2 \le 1,\; z_1, z_2 \in \{0, 1\}.\)
So sánh trực tiếp hai tổ hợp có \(1\) biến hoạt động:
    &lt;ul&gt;
      &lt;li&gt;Nếu chọn đặc trưng 1 (\(z_1=1, z_2=0 \Rightarrow \beta_2 = 0\)): tối ưu theo \(\beta_1\) cho \(\beta_1 = 3\), hàm mất mát bằng \(\frac{1}{2}(0^2 + 4^2) = 8\).&lt;/li&gt;
      &lt;li&gt;Nếu chọn đặc trưng 2 (\(z_1=0, z_2=1 \Rightarrow \beta_1 = 0\)): tối ưu theo \(\beta_2\) cho \(\beta_2 = 2\), hàm mất mát bằng \(\frac{1}{2}(3^2 + 0^2) = 4.5\)!
Nghiệm tối ưu toàn cục là \(\beta^\star = (0, 2)\) với giá trị \(4.5\) (dù \(|\beta_1^{\text{OLS}}| = 3 &amp;gt; |\beta_2^{\text{OLS}}| = 2\), đặc trưng 2 giảm sai số mạnh hơn nhờ chuẩn cột lớn hơn!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra 1 bước Thuật toán bậc nhất rời rạc (tạo Warm Start):&lt;/strong&gt;
Hằng số Lipschitz là \(L = \lambda_{\max}(X^T X) = \max(1^2, 2^2) = 4\). Xuất phát từ \(\beta^{(0)} = (0, 0)\), gradient là \(\nabla f(0) = -X^T y = (-3,\; -8)^T\).
Bước gradient chưa cắt ngưỡng: \(\beta^{(0)} - \frac{1}{L}\nabla f(0) = \frac{1}{4}(3,\; 8)^T = (0.75,\; 2.0)^T\).
Áp dụng toán tử chiếu cứng \(H_1\) (giữ 1 thành phần lớn nhất theo trị tuyệt đối): vì \(2.0 &amp;gt; 0.75\), ta thu ngay \(\beta^{(1)} = (0,\; 2.0)\) — &lt;strong&gt;trúng phóc nghiệm tối ưu toàn cục chỉ sau 1 bước&lt;/strong&gt; để đưa vào làm điểm khởi động nóng cho MIP!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chọn tập con tốt nhất là một bài toán tiêu biểu của quy hoạch nguyên hỗn hợp trong thống kê, nhằm lựa chọn tối đa \(k\) đặc trưng quan trọng nhất trong số \(p\) đặc trưng sẵn có.&lt;/p&gt;

&lt;h2 id=&quot;phát-biểu-bài-toán&quot;&gt;Phát biểu bài toán&lt;/h2&gt;

&lt;p&gt;Cho ma trận đặc trưng \(X = [x^{1} \quad \dotsc \quad x^{p}] \in \mathbb{R}^{n \times p}\) và vector phản hồi \(y \in \mathbb{R}^{n}\), bài toán chọn tập con tốt nhất có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{\beta} &amp;amp; \quad \frac{1}{2} \parallel y - X\beta \parallel^{2} \\\\
\text{subject to } &amp;amp; \quad \parallel \beta \parallel_{0} \leq k
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\parallel \beta \parallel_{0}\) là số phần tử khác không của \(\beta\).&lt;/p&gt;

&lt;p&gt;Ở các chương trước, bài toán Lasso tạo tính thưa một cách xấp xỉ thông qua chuẩn \(l_1\). Ở đây, ràng buộc chuẩn giả \(l_0\) (\(\parallel \beta \parallel_{0} \leq k\)) giới hạn trực tiếp số biến được chọn nhưng lại không lồi, nên không thể giải trực tiếp bằng các phương pháp tối ưu lồi thông thường.&lt;/p&gt;

&lt;h3 id=&quot;mô-hình-quy-hoạch-nguyên-hỗn-hợp&quot;&gt;Mô hình quy hoạch nguyên hỗn hợp&lt;/h3&gt;

&lt;p&gt;Ta biểu diễn lại bài toán trên dưới dạng quy hoạch nguyên hỗn hợp:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{\beta, z} &amp;amp; \quad \frac{1}{2} \parallel y - X\beta \parallel^{2} \\\\
\text{subject to } &amp;amp; \quad \left\vert \beta_{i} \right\vert \leq M_{i} \cdot z_{i}, \quad i = 1, \dotsc, p \\\\
&amp;amp; \quad \sum_{i = 1}^{p} z_{i} \leq k \\\\
&amp;amp; \quad z_{i} \in \lbrace 0, 1 \rbrace, \quad i = 1, \dotsc, p
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Các biến nhị phân \(z_i\) kèm ràng buộc \(\sum_{i=1}^{p} z_i \leq k\) đảm bảo tối đa \(k\) hệ số \(\beta_i\) khác không. Các hằng số \(M_i\) là cận trên của \(\left\vert \beta_{i} \right\vert\) tại nghiệm tối ưu và có thể ước lượng trước bằng cách tiền xử lý \(X\) và \(y\). Khi đã viết ở dạng này, ta có thể giải bài toán bằng các bộ giải quy hoạch nguyên hỗn hợp.&lt;/p&gt;

&lt;h2 id=&quot;cách-tạo-điểm-khởi-động-khả-thi-tốt&quot;&gt;Cách tạo điểm khởi động khả thi tốt&lt;/h2&gt;

&lt;p&gt;Để trình bày thuật toán tìm nghiệm khả thi ban đầu (warm start), ta xét bài toán tổng quát với hàm mục tiêu \(g : \mathbb{R}^{p} \to \mathbb{R}\) lồi, trơn và có gradient \(\nabla g\) liên tục \(L\)-Lipschitz:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{\beta} g(\beta) \quad \text{subject to} \quad \parallel \beta \parallel_{0} \le k\]
&lt;/blockquote&gt;

&lt;p&gt;Với bài toán chọn tập con tốt nhất, \(g(\beta) = \frac{1}{2} \parallel X\beta - y \parallel^2_2\).&lt;/p&gt;

&lt;h3 id=&quot;nhận-xét&quot;&gt;Nhận xét&lt;/h3&gt;

&lt;p&gt;Định nghĩa toán tử \(H_k(u)\) giữ lại đúng \(k\) phần tử có trị tuyệt đối lớn nhất của vector \(u \in \mathbb{R}^p\) và gán các phần tử còn lại bằng 0:&lt;/p&gt;

&lt;blockquote&gt;
\[H_k(u) = \underset{\beta : \parallel \beta \parallel_{0} \le k}{\text{argmin}} \parallel \beta - u \parallel^2_2\]
&lt;/blockquote&gt;

&lt;p&gt;Toán tử \(H_k(u)\) chính là phép co ngưỡng cứng (hard thresholding), hay phép chiếu Euclid của \(u\) lên tập \(\{\beta : \parallel \beta \parallel_{0} \le k\}\).&lt;/p&gt;

&lt;h3 id=&quot;thuật-toán-bậc-nhất-rời-rạc-discrete-first-order-algorithm&quot;&gt;Thuật toán bậc nhất rời rạc (Discrete first-order algorithm)&lt;/h3&gt;

&lt;p&gt;Kết hợp bước hạ gradient với toán tử \(H_k\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Khởi tạo \(\beta^{(0)}\).&lt;/li&gt;
  &lt;li&gt;Với \(i = 0, 1, \dots\): &lt;br /&gt;
\(\quad \beta^{(i+1)} = H_k \left(\beta^{(i)} - \frac{1}{L} \nabla g(\beta^{(i)})\right)\) &lt;br /&gt;
Kết thúc vòng lặp.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Quá trình lặp này hội tụ về một điểm \(\bar{\beta}\) thỏa mãn điều kiện điểm bất động (tương ứng một nghiệm cục bộ tốt để làm điểm khởi động nóng cho MIP):&lt;/p&gt;

&lt;blockquote&gt;
\[\bar{\beta} = H_k \left(\bar{\beta} - \frac{1}{L} \nabla g(\bar{\beta})\right)\]
&lt;/blockquote&gt;

&lt;p&gt;Về cấu trúc, thuật toán này có dạng tương tự proximal gradient descent với \(H_k\) đóng vai trò toán tử proximal trên tập ràng buộc \(l_0\).&lt;/p&gt;

&lt;h2 id=&quot;kết-quả-thực-nghiệm&quot;&gt;Kết quả thực nghiệm&lt;/h2&gt;

&lt;h3 id=&quot;khoảng-cách-tối-ưu-trong-quy-hoạch-nguyên-hỗn-hợp-mip-gap&quot;&gt;Khoảng cách tối ưu trong quy hoạch nguyên hỗn hợp (MIP gap)&lt;/h3&gt;

&lt;p&gt;Hình 1 trình bày kết quả thực nghiệm cho bài toán chọn tập con tốt nhất.&lt;/p&gt;

&lt;p&gt;Ở đồ thị bên trái, cận trên sớm đạt tới giá trị tối ưu nhưng cận dưới tăng chậm hơn; chỉ khi cận dưới gặp cận trên ta mới chứng nhận được nghiệm hiện tại là tối ưu toàn cục. Điều này phản ánh đặc thù của quy hoạch nguyên: không có điều kiện tối ưu đơn giản để kiểm tra trực tiếp mà phải dựa vào việc thu hẹp hiệu giữa cận trên và cận dưới (gọi là &lt;em&gt;MIP gap&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;Đồ thị bên phải minh họa quá trình MIP gap (đường màu cam) giảm dần theo thời gian.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_03_subset_results1.png&quot; alt=&quot;[Hình 1] Tập dữ liệu n=350, p = 64, k=6 [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$[Hình 1] \; Dữ \; liệu \; n=350, p = 64, k=6 \; [3]$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;khởi-động-nguội-và-khởi-động-nóng-cold-và-warm-starts&quot;&gt;Khởi động nguội và khởi động nóng (Cold và Warm Starts)&lt;/h3&gt;

&lt;p&gt;Hình 2 cho thấy việc dùng nghiệm từ thuật toán bậc nhất rời rạc làm điểm khởi động nóng (warm start) mang lại hiệu năng vượt trội so với khởi động nguội (cold start).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_04_subset_results2.png&quot; alt=&quot;[Hình 2] Cold start và Warm start [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Cold start và Warm start [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;khả-năng-phát-hiện-tính-thưa-sparsity-detection&quot;&gt;Khả năng phát hiện tính thưa (Sparsity Detection)&lt;/h3&gt;

&lt;p&gt;Hình 3 so sánh độ thưa của nghiệm thu được giữa MIP, Lasso, hồi quy từng bước (Stepwise regression) và SparseNet trên dữ liệu tổng hợp; kết quả cho thấy MIP đạt độ thưa chính xác nhất.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_05_subset_results3.png&quot; alt=&quot;[Hình 3] Phát hiện tính thưa (dữ liệu tổng hợp) [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 3] Phát hiện tính thưa (dữ liệu tổng hợp) [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>25-01 Mặt phẳng cắt</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_01_Cutting_planes/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_01_Cutting_planes</id>
   <content type="html">&lt;p&gt;Năm 1954, George Dantzig, Ray Fulkerson và Selmer Johnson đã làm chấn động giới toán học khi giải chính xác bài toán Người du lịch (TSP) đi qua 49 thành phố của nước Mỹ — một bài toán có tới \(48!/2 \approx 6 \times 10^{60}\) hành trình khả dĩ — chỉ bằng máy tính bàn cơ học và giấy bút! Bí mật của họ không phải sức mạnh tính toán mà là một ý tưởng hình học thiên tài: &lt;strong&gt;mặt phẳng cắt (cutting planes)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Thay vì cố gắng mô tả toàn bộ hình dáng phức tạp của tập nghiệm nguyên ngay từ đầu, họ bắt đầu bằng một chiếc vỏ nới lỏng LP thật đơn giản, giải nó, và mỗi lần nghiệm LP bị “lòi” ra ngoài tập nguyên (rơi vào một điểm phân số), họ lại dùng một nhát dao siêu phẳng cắt bỏ đúng phần thừa đó đi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-trực-giác-của-phương-pháp-mặt-phẳng-cắt&quot;&gt;Kiến thức cần nhớ: Ba trụ cột trực giác của phương pháp Mặt phẳng cắt&lt;/h2&gt;

&lt;p&gt;Trước khi đi vào các công thức đại số của lát cắt Gomory ở các bài sau, hãy khắc sâu bức tranh hình học của phương pháp này qua ba trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hình học ngăn cách (Hyperplane Separation):&lt;/strong&gt; Nếu điểm phân số \(x^{\text{LP}}\) nằm ngoài bao lồi \(S\) của các điểm nguyên khả thi, định lý siêu phẳng ngăn cách trong giải tích lồi đảm bảo &lt;em&gt;luôn tồn tại&lt;/em&gt; một siêu phẳng \(\pi^T x = \pi_0\) sao cho toàn bộ \(S\) nằm một bên (\(\pi^T x \le \pi_0\)) còn \(x^{\text{LP}}\) nằm hẳn bên kia (\(\pi^T x^{\text{LP}} &amp;gt; \pi_0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lặp tinh chỉnh đa diện (Iterative Polyhedral Refinement):&lt;/strong&gt; Mỗi lần thêm một mặt phẳng cắt, đa diện nới lỏng \(P_k\) lại co nhỏ thêm một chút và tiến sát hơn tới bao lồi \(S\), kéo theo cận dưới tăng đơn điệu lên gần nghiệm nguyên tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Di sản lịch sử (DFJ 1954 → Gomory 1958 → Chvátal 1973):&lt;/strong&gt; Từ các lát cắt thiết kế riêng cho từng bài toán (như lát cắt khử chu trình con cho TSP của Dantzig–Fulkerson–Johnson) đến công thức tổng quát tự động của Ralph Gomory cho &lt;em&gt;mọi&lt;/em&gt; quy hoạch tuyến tính nguyên, mặt phẳng cắt đã mở ra cả ngành lý thuyết tổ hợp đa diện (polyhedral combinatorics).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-hình-dung-một-nhát-cắt-gọt-đúng-về-bao-lồi-nguyên&quot;&gt;Giải thích: Hình dung một nhát cắt gọt đúng về bao lồi nguyên&lt;/h3&gt;

&lt;p&gt;Xét tập khả thi nguyên \(S = \{(0, 0),\; (1, 0),\; (0, 1)\}\) nằm bên trong đa diện nới lỏng LP ban đầu:&lt;/p&gt;

\[P = \{(x_1, x_2) \in \mathbb{R}^2 : x_1 \ge 0,\; x_2 \ge 0,\; 2x_1 + 2x_2 \le 3\},\]

&lt;p&gt;với mục tiêu cực tiểu hóa \(f(x_1, x_2) = -x_1 - x_2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải LP trên đa diện ban đầu \(P\):&lt;/strong&gt;
Cạnh biên \(2x_1 + 2x_2 = 3\) cắt hai trục tại \((1.5, 0)\) và \((0, 1.5)\). Mọi điểm trên đoạn nối hai đỉnh này đều đạt giá trị tối ưu LP là \(-1.5\), nhưng &lt;strong&gt;không có điểm nào là số nguyên&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dựng mặt phẳng cắt ngăn cách:&lt;/strong&gt;
Ta cần một bất đẳng thức \(\pi_1 x_1 + \pi_2 x_2 \le \pi_0\) thỏa mãn hai điều kiện:
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Hợp lệ trên \(S\):&lt;/em&gt; Đúng tại \((0,0)\), \((1,0)\) và \((0,1)\). Chọn \(x_1 + x_2 \le 1\): cả ba điểm đều cho giá trị \(0 \le 1\) hoặc \(1 \le 1\) (hợp lệ!).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Cắt bỏ nghiệm LP:&lt;/em&gt; Tại \((1.5, 0)\) và \((0, 1.5)\), vế trái bằng \(1.5 &amp;gt; 1\) — bị vi phạm nghiêm trọng!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết quả sau nhát cắt:&lt;/strong&gt;
Đa diện mới \(P&apos; = P \cap \{x_1 + x_2 \le 1\}\) thu gọn thành đúng tam giác có 3 đỉnh \((0,0), (1,0), (0,1)\) — trùng khớp hoàn toàn với bao lồi \(\operatorname{conv}(S)\)! Bây giờ giải LP trên \(P&apos;\) lập tức trả về đỉnh nguyên \((1, 0)\) hoặc \((0, 1)\) với giá trị tối ưu chính xác \(-1\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Phương pháp mặt phẳng cắt (cutting plane) giải bài toán quy hoạch tuyến tính nguyên bằng cách xuất phát từ bài toán nới lỏng lồi. Nếu nghiệm tìm được chưa thuộc tập khả thi nguyên ban đầu, thuật toán bổ sung các bất đẳng thức tuyến tính — gọi là &lt;em&gt;lát cắt&lt;/em&gt; (cut) hay &lt;em&gt;mặt phẳng cắt&lt;/em&gt; — nhằm cắt bỏ vùng chứa nghiệm phân số đó mà không loại bỏ bất kỳ điểm nguyên khả thi nào, dần dẫn nghiệm hội tụ về tập khả thi ban đầu.&lt;/p&gt;

&lt;h2 id=&quot;khái-niệm-mặt-phẳng-cắt&quot;&gt;Khái niệm mặt phẳng cắt&lt;/h2&gt;

&lt;p&gt;Về mặt hình học, mặt phẳng cắt tương ứng với một đường thẳng (hay siêu phẳng trong không gian nhiều chiều) ngăn cách nghiệm nới lỏng nằm ngoài miền nguyên khỏi tập khả thi nguyên ban đầu, như minh họa trong Hình 1.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_cutting_plane_concept.png&quot; alt=&quot;[Hình 1] Mặt phẳng cắt&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Mặt phẳng cắt&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Vùng đỏ: bao lồi của tập khả thi thuộc quy hoạch tuyến tính nguyên ban đầu.&lt;/li&gt;
  &lt;li&gt;Vùng xanh: tập khả thi của bài toán nới lỏng lồi.&lt;/li&gt;
  &lt;li&gt;Đường xanh lá: mặt phẳng cắt ngăn cách phần thừa của vùng xanh với vùng đỏ.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thuật toán cụ thể sẽ được trình bày trong các mục tiếp theo.&lt;/p&gt;

&lt;h2 id=&quot;đôi-nét-lịch-sử-về-mặt-phẳng-cắt&quot;&gt;Đôi nét lịch sử về mặt phẳng cắt&lt;/h2&gt;

&lt;p&gt;Phương pháp mặt phẳng cắt trải qua chặng đường dài từ lý thuyết đến triển khai thực tế.&lt;/p&gt;

&lt;p&gt;Năm 1954, Dantzig, Fulkerson và Johnson lần đầu áp dụng ý tưởng mặt phẳng cắt cho bài toán người bán hàng du lịch (TSP). Đến năm 1958, Ralph Gomory đề xuất phương pháp mặt phẳng cắt tổng quát cho mọi bài toán quy hoạch tuyến tính nguyên. Tuy nhiên, trong suốt khoảng 30 năm sau đó, các lát cắt Gomory vẫn ít được sử dụng trong thực tiễn do vấn đề ổn định số và tốc độ hội tụ chậm khi chạy độc lập.&lt;/p&gt;

&lt;p&gt;Năm 1990, Sebastian Ceria (Đại học Carnegie Mellon) cùng các cộng sự đã kết hợp hiệu quả mặt phẳng cắt với thuật toán nhánh và cận, hình thành thuật toán &lt;strong&gt;nhánh và cắt (branch and cut)&lt;/strong&gt;. Từ đó, mặt phẳng cắt trở thành một thành phần không thể thiếu trong hầu hết các bộ giải quy hoạch nguyên thương mại và mã nguồn mở.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>25-01-04 Thuật toán nhánh và cắt (Branch and cut)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_01_04_Branch_and_cut_algorithm/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_01_04_Branch_and_cut_algorithm</id>
   <content type="html">&lt;p&gt;Trong suốt thập niên 1960–1980, giới tối ưu từng bị chia làm hai phe gần như đối lập: phe &lt;strong&gt;Nhánh và Cận&lt;/strong&gt; (ổn định nhưng cây tìm kiếm phình to khủng khiếp) và phe &lt;strong&gt;Mặt phẳng cắt thuần túy&lt;/strong&gt; (ý tưởng đẹp nhưng khi thêm quá nhiều lát cắt Gomory liên tiếp, bảng đơn hình gặp bất ổn định số học và hội tụ chậm dần).&lt;/p&gt;

&lt;p&gt;Bước ngoặt lịch sử đến vào năm 1990 khi Sebastian Ceria cùng nhóm nghiên cứu tại Đại học Carnegie Mellon và IBM nhận ra: &lt;em&gt;tại sao phải chọn một trong hai?&lt;/em&gt; Nếu ta chỉ thêm vài vòng lát cắt thật sắc bén ở nút gốc để siết chặt đa diện, rồi chuyển sang phân nhánh (và thỉnh thoảng thêm lát cắt ngay tại các nút con), hai nhược điểm triệt tiêu nhau hoàn toàn. Sự kết hợp mang tên &lt;strong&gt;Nhánh và Cắt (Branch and Cut)&lt;/strong&gt; đó đã mở ra kỷ nguyên tăng tốc hơn 1 triệu lần về mặt thuật toán của các bộ giải MIP hiện đại!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-kiến-trúc-branch-and-cut&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của kiến trúc Branch and Cut&lt;/h2&gt;

&lt;p&gt;Mọi bộ giải MIP đỉnh cao ngày nay (Gurobi, CPLEX, SCIP, HiGHS) đều vận hành dựa trên sự phối hợp nhịp nhàng của bốn bánh răng sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp Cắt tại nút gốc (Root-Node Cut Loop):&lt;/strong&gt; Trước khi rẽ nhánh lần đầu tiên, bộ giải chạy nhiều vòng sinh lát cắt (Gomory, MIR, clique, cover cuts) để đóng càng nhiều khoảng cách nới lỏng (integrality gap) càng tốt ngay tại nút gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quyết định chuyển từ Cắt sang Nhánh (Cut-vs-Branch Trade-off):&lt;/strong&gt; Khi các lát cắt mới không còn cải thiện đáng kể cận dưới (hiện tượng &lt;em&gt;tailing off&lt;/em&gt;) hoặc làm bài toán LP trở nên quá dày đặc, thuật toán lập tức dừng cắt và chuyển sang phân nhánh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tích hợp Tiền xử lý và Heuristic gốc (Presolve &amp;amp; Primal Heuristics):&lt;/strong&gt; Song song với cắt và nhánh, bộ giải liên tục đơn giản hóa ràng buộc (presolve) và chạy heuristic tìm nghiệm nguyên tốt để hạ nhanh cận trên \(u\), kích hoạt cắt tỉa mạnh trên toàn cây.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sức mạnh cộng hưởng Thuật toán \(\times\) Phần cứng:&lt;/strong&gt; Như tổng kết kinh điển của Bixby (IBM/Gurobi), tốc độ giải MIP từ 1991 đến 2015 tăng khoảng \(10^9\) lần — trong đó phần cứng đóng góp khoảng \(10^3\) lần, còn bản thân thuật toán (nòng cốt là Branch and Cut) đóng góp tới hơn \(10^6\) lần!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-tay-branch-and-bound-thuần-túy-với-branch-and-cut&quot;&gt;Giải thích: So sánh tay Branch-and-Bound thuần túy với Branch-and-Cut&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch nguyên cực tiểu hóa \(\min -5x_1 - 4x_2\) thỏa mãn \(2x_1 + 2x_2 \le 5,\; x_1, x_2 \in \mathbb{Z}_+\) (chính là bài toán ta đã mất 5 nút để giải ở bài 24-05!).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cách 1 — Nhánh và Cận thuần túy (không dùng lát cắt):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nút gốc LP cho \((2.5, 0)\) với cận dưới \(-12.5\).&lt;/li&gt;
      &lt;li&gt;Ta phải rẽ nhánh \(x_1 \le 2\) và \(x_1 \ge 3\), rồi tại nhánh \(x_1 \le 2\) lại ra \((2, 0.5)\) nên phải rẽ thêm \(x_2 \le 0\) và \(x_2 \ge 1\), rồi lại rẽ thêm \(x_1 \le 1\) và \(x_1 \ge 2\)… Tổng cộng &lt;strong&gt;6 lần giải LP&lt;/strong&gt; trên 6 nút!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách 2 — Nhánh và Cắt (thêm 1 vòng cắt ngay tại nút gốc):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nút gốc LP ban đầu cho \((2.5, 0)\) với cận dưới \(-12.5\).&lt;/li&gt;
      &lt;li&gt;Thay vì rẽ nhánh ngay, ta sinh lát cắt Chvátal–Gomory từ ràng buộc \(2x_1 + 2x_2 \le 5\) (chia 2 rồi làm tròn xuống vế phải):
\(x_1 + x_2 \le \left\lfloor \frac{5}{2} \right\rfloor = 2.\)&lt;/li&gt;
      &lt;li&gt;Giải lại LP tại &lt;strong&gt;chính nút gốc&lt;/strong&gt; với ràng buộc mới \(x_1 + x_2 \le 2\): nghiệm LP nhảy thẳng sang đỉnh \((2, 0)\) với giá trị \(-10\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết quả chấn động:&lt;/strong&gt; Điểm \((2, 0)\) đã là &lt;strong&gt;nghiệm nguyên&lt;/strong&gt;! Thuật toán kết thúc ngay tại nút gốc (0 nhánh, chỉ 2 lần giải LP) thay vì phải đào cây xuống nhiều tầng. Trên bài toán lớn, việc khép 80% khoảng cách cận ngay tại nút gốc giúp giảm kích thước cây từ hàng triệu nút xuống còn vài chục nút!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Năm 1990, Sebastian Ceria tại Đại học Carnegie Mellon đã triển khai thành công sự kết hợp giữa phương pháp mặt phẳng cắt và thuật toán nhánh và cận, tạo nên thuật toán &lt;strong&gt;nhánh và cắt (branch and cut)&lt;/strong&gt;. Kể từ đó, cách tiếp cận này trở thành nền tảng cốt lõi của các bộ giải tối ưu thương mại hiện đại.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán-nhánh-và-cắt&quot;&gt;Thuật toán nhánh và cắt&lt;/h2&gt;

&lt;p&gt;Xét bài toán quy hoạch nguyên (IP), trong đó \(f : \mathbb{R}^{n} \to \mathbb{R}\) là hàm lồi, \(C \subseteq \mathbb{R}^{n}\) là tập lồi và \(J \subseteq \{1, \dots, n\}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
          \min_{x} &amp;amp; \quad {f(x)} \\
\text{subject to } &amp;amp; \quad  x \in C \\
                   &amp;amp; \quad  x_j \in \mathbb{Z}, \quad j \in J
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;các-bước-thực-hiện&quot;&gt;Các bước thực hiện&lt;/h3&gt;

&lt;p&gt;Ký hiệu bài toán nới lỏng lồi là (CR) và quy hoạch nguyên là (IP):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Giải bài toán nới lỏng lồi (CR):&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} &amp;amp; \quad {f(x)} \\\\
\text{subject to } &amp;amp; \quad  x \in C
\end{align}\]
&lt;/blockquote&gt;

&lt;ol&gt;
  &lt;li&gt;Nếu (CR) vô nghiệm \(\Rightarrow\) (IP) vô nghiệm (dừng). &lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Nếu nghiệm \(x^{\star}\) của (CR) khả thi cho (IP) \(\Rightarrow\) \(x^{\star}\) là nghiệm tối ưu của (IP) (dừng). &lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Nếu \(x^{\star}\) chưa thỏa mãn ràng buộc nguyên, chọn một trong hai thao tác: &lt;br /&gt;
\(\quad\) 4.1 Thêm một hoặc nhiều mặt phẳng cắt (cut) rồi quay lại bước 1. &lt;br /&gt;
\(\quad\) 4.2 Phân nhánh (branch) thành các bài toán con và giải đệ quy.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Như vậy, thuật toán nhánh và cắt tích hợp mặt phẳng cắt trực tiếp vào bên trong cây nhánh và cận: tại mỗi nút, bộ giải có thể siết chặt bài toán nới lỏng bằng lát cắt trước khi quyết định phân nhánh.&lt;/p&gt;

&lt;h2 id=&quot;tiến-bộ-của-công-nghệ-giải-quy-hoạch-nguyên&quot;&gt;Tiến bộ của công nghệ giải quy hoạch nguyên&lt;/h2&gt;

&lt;p&gt;Các bộ giải hiện đại như Gurobi, CPLEX và FICO Xpress sở hữu những cài đặt rất hiệu quả của phương pháp đơn hình (simplex) và điểm trong (interior-point). Riêng với quy hoạch nguyên hỗn hợp, hầu hết các bộ giải đều dùng kiến trúc nhánh và cắt, khai thác mạnh nới lỏng lồi và khởi động nóng (warm start).&lt;/p&gt;

&lt;p&gt;Trong khoảng 30 năm qua, tốc độ giải quy hoạch nguyên đã tăng lên rất lớn, giúp nhiều bài toán thực tế từng không thể giải nay giải được trong thời gian ngắn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tăng tốc nhờ cải tiến thuật toán (1990–2016): hơn \(500{,}000\) lần.&lt;/li&gt;
  &lt;li&gt;Tăng tốc nhờ cải tiến phần cứng (1990–2016): hơn \(500{,}000\) lần.&lt;/li&gt;
  &lt;li&gt;Tổng mức tăng tốc: hơn \(250\) tỷ lần (\(2{,}5 \cdot 10^{11}\)).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>25-01-03 Lát cắt Gomory (1958)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_01_03_Gomory_cuts/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_01_03_Gomory_cuts</id>
   <content type="html">&lt;p&gt;Nếu phải chọn một phát minh toán học chứng minh rằng &lt;em&gt;những quan sát sơ cấp nhất có thể sinh ra công cụ mạnh mẽ nhất&lt;/em&gt;, thì &lt;strong&gt;lát cắt phân số Gomory (1958)&lt;/strong&gt; chắc chắn đứng đầu bảng. Toàn bộ lý thuyết lẫy lừng của Ralph Gomory khởi nguồn từ một câu nói mà học sinh tiểu học cũng hiểu: nếu \(a \le b\) và \(a\) là số nguyên, thì \(a \le \lfloor b \rfloor\)!&lt;/p&gt;

&lt;p&gt;Bằng cách áp dụng đúng nguyên tắc làm tròn xuống ấy vào từng hàng của bảng đơn hình (simplex tableau) tại nghiệm LP phân số, Gomory đã tạo ra một cỗ máy &lt;strong&gt;tự động 100%&lt;/strong&gt; — không cần biết bài toán đến từ hàng không, tài chính hay thống kê, chỉ cần có một biến cơ sở nhận giá trị phân số, công thức Gomory lập tức xuất ra một mặt phẳng cắt hợp lệ cắt đứt nghiệm đó.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-đằng-sau-lát-cắt-phân-số-gomory&quot;&gt;Kiến thức cần nhớ: Ba trụ cột đằng sau lát cắt phân số Gomory&lt;/h2&gt;

&lt;p&gt;Để không bao giờ nhầm dấu khi viết lát cắt Gomory (đặc biệt với hệ số âm!), hãy nắm chắc ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tách phần nguyên và phần lẻ không âm:&lt;/strong&gt; Mọi số thực \(a\) đều viết duy nhất thành \(a = \lfloor a \rfloor + f\) với phần lẻ \(f = a - \lfloor a \rfloor \in [0, 1)\). Lưu ý cực quan trọng với số âm: \(\lfloor -0.25 \rfloor = -1\) chứ không phải \(0\), nên phần lẻ của \(-0.25\) là \(-0.25 - (-1) = +0.75 \in [0, 1)\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất biến tính nguyên của hiệu hai vế:&lt;/strong&gt; Từ phương trình \(\sum_{j=1}^n a_j x_j = a_0\) với \(x_j \in \mathbb{Z}_+\), thay \(a_j = \lfloor a_j \rfloor + f_j\) rồi chuyển hết phần nguyên sang một vế, ta được \(\sum f_j x_j - f_0 = \lfloor a_0 \rfloor - \sum \lfloor a_j \rfloor x_j \in \mathbb{Z}\). Vì \(f_j \ge 0, x_j \ge 0\) và \(f_0 &amp;lt; 1\), vế trái lớn hơn \(-1\) mà lại là số nguyên, nên &lt;strong&gt;bắt buộc phải \(\ge 0\)&lt;/strong&gt;, tức \(\sum f_j x_j \ge f_0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cắt chắc chắn nghiệm đơn hình hiện tại:&lt;/strong&gt; Trong bảng đơn hình, hàng của biến cơ sở \(x_B\) có hệ số \(1\) tại \(x_B\) (nên \(f_B = 0\)), còn tất cả biến không cơ sở \(x_N\) đang bằng \(0\). Vì thế tại nghiệm LP hiện tại, vế trái \(\sum f_j x_j = 0 &amp;lt; f_0\) — chứng minh lát cắt &lt;em&gt;luôn&lt;/em&gt; cắt bỏ nghiệm phân số hiện tại!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-suy-ra-một-lát-cắt-gomory-có-cả-hệ-số-âm&quot;&gt;Giải thích: Tự tay suy ra một lát cắt Gomory (có cả hệ số âm!)&lt;/h3&gt;

&lt;p&gt;Giả sử sau khi giải LP bằng thuật toán đơn hình, một hàng trong bảng đơn hình cho biến cơ sở \(x_1\) có dạng:&lt;/p&gt;

\[x_1 + \frac{3}{4} x_3 - \frac{1}{4} x_4 = \frac{5}{4}, \qquad x_1, x_3, x_4 \in \mathbb{Z}_+.\]

&lt;p&gt;Tại nghiệm LP hiện tại, hai biến không cơ sở bằng \(0\) (\(x_3 = x_4 = 0\)), nên \(x_1 = \frac{5}{4} = 1.25\) (phân số!).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính phần nguyên \(\lfloor a_j \rfloor\) và phần lẻ \(f_j = a_j - \lfloor a_j \rfloor \in [0, 1)\) cho từng hệ số:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(x_1\): \(a_1 = 1 \Rightarrow \lfloor 1 \rfloor = 1,\; f_1 = 0\).&lt;/li&gt;
      &lt;li&gt;Với \(x_3\): \(a_3 = \frac{3}{4} \Rightarrow \lfloor \frac{3}{4} \rfloor = 0,\; f_3 = \frac{3}{4}\).&lt;/li&gt;
      &lt;li&gt;Với \(x_4\) (chú ý dấu âm!): \(a_4 = -\frac{1}{4} \Rightarrow \lfloor -\frac{1}{4} \rfloor = -1,\; f_4 = -\frac{1}{4} - (-1) = \frac{3}{4}\).&lt;/li&gt;
      &lt;li&gt;Với vế phải: \(a_0 = \frac{5}{4} \Rightarrow \lfloor \frac{5}{4} \rfloor = 1,\; f_0 = \frac{1}{4}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Viết ngay lát cắt phân số Gomory:&lt;/strong&gt;
\(0 \cdot x_1 + \frac{3}{4} x_3 + \frac{3}{4} x_4 \ge \frac{1}{4} \quad \Longleftrightarrow \quad 3x_3 + 3x_4 \ge 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng cả hai tính chất:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Có cắt nghiệm LP hiện tại \((x_1=\frac{5}{4}, x_3=0, x_4=0)\) không?&lt;/em&gt; Thay vào: \(\frac{3}{4}(0) + \frac{3}{4}(0) = 0 &amp;lt; \frac{1}{4}\) — &lt;strong&gt;cắt đứt ngay lập tức!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Có giữ nguyên nghiệm nguyên khả thi không?&lt;/em&gt; Thử một nghiệm nguyên thỏa mãn phương trình gốc là \((x_1, x_3, x_4) = (1, 1, 2)\) (kiểm tra: \(1 + \frac{3}{4}(1) - \frac{1}{4}(2) = \frac{5}{4}\)). Thay vào lát cắt: \(\frac{3}{4}(1) + \frac{3}{4}(2) = \frac{9}{4} \ge \frac{1}{4}\) — &lt;strong&gt;được bảo toàn hoàn toàn!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ralph Gomory đã xây dựng một phương pháp hệ thống để tạo bất đẳng thức hợp lệ dựa trên nhận xét sơ cấp sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Nếu \(a \le b\) và \(a\) là số nguyên thì \(a \le \lfloor b \rfloor\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, khi vế trái là số nguyên, việc làm tròn xuống vế phải vẫn bảo toàn bất đẳng thức.&lt;/p&gt;

&lt;h2 id=&quot;lát-cắt-phân-số-gomory-gomory-fractional-cut&quot;&gt;Lát cắt phân số Gomory (Gomory fractional cut)&lt;/h2&gt;

&lt;p&gt;Giả sử tập khả thi nguyên \(S\) của bài toán IP thỏa mãn:&lt;/p&gt;

\[S \subseteq \left\{ x \in \mathbb{Z}^{n}_{+} : \sum^{n}_{j=1} a_{j} x_{j} = a_{0} \right\} \quad \text{với} \quad a_{0} \notin \mathbb{Z}\]

&lt;p&gt;Khi đó, &lt;strong&gt;lát cắt phân số Gomory&lt;/strong&gt; hợp lệ đối với \(S\) được viết là:&lt;/p&gt;

\[\sum^{n}_{j=1} (a_{j} - \lfloor a_{j} \rfloor) x_{j} \ge a_{0} - \lfloor a_{0} \rfloor\]

&lt;p&gt;Từ ý tưởng nền tảng này, nhiều họ mặt phẳng cắt khác đã được phát triển, chẳng hạn lát cắt Chvátal–Gomory, lát cắt tách (split cuts) và lát cắt lift-and-project.&lt;/p&gt;

&lt;p&gt;Chi tiết bước suy diễn lát cắt phân số Gomory từ bảng đơn hình (simplex tableau) có thể tham khảo tại Wikipedia:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Cutting-plane_method&quot;&gt;Cutting-plane method&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;lát-cắt-gomory-tính-tay-từng-bước-video&quot;&gt;Lát cắt Gomory, tính tay từng bước (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/gomory-cut_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Một mặt phẳng cắt loại bỏ nghiệm LP phân số nhưng giữ nguyên mọi điểm nguyên khả thi, giúp bài toán nới lỏng chặt hơn mà không làm mất nghiệm tối ưu nguyên.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-thêm-mặt-phẳng-cắt&quot;&gt;Tự tay thử: thêm mặt phẳng cắt&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;cuts&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>25-01-02 Thuật toán mặt phẳng cắt</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_01_02_Cutting_plane_algorithm/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_01_02_Cutting_plane_algorithm</id>
   <content type="html">&lt;p&gt;Ở bài trước, ta biết rằng bao lồi nguyên \(S\) có thể có hàng tỷ mặt biên nên không thể viết hết ra giấy. Vậy làm sao để vẫn tận dụng được bao lồi \(S\)? &lt;strong&gt;Thuật toán mặt phẳng cắt&lt;/strong&gt; giải quyết nghịch lý này bằng chiến lược “lười thông minh”: bắt đầu từ đa diện đơn giản \(C_0 = C\), giải bài toán nới lỏng, rồi &lt;strong&gt;chỉ đi tìm một bất đẳng thức hợp lệ duy nhất&lt;/strong&gt; vi phạm đúng điểm phân số vừa xuất hiện.&lt;/p&gt;

&lt;p&gt;Cốt lõi của mỗi vòng lặp nằm ở &lt;strong&gt;bài toán tách (separation problem)&lt;/strong&gt;: cho một điểm \(x^{(k)} \notin S\), hãy tìm một siêu phẳng \(\pi^T x \le \pi_0\) đúng với mọi điểm trong \(S\) nhưng thỏa mãn \(\pi^T x^{(k)} &amp;gt; \pi_0\). Định lý nổi tiếng Grötschel–Lovász–Schrijver thậm chí chỉ ra rằng tối ưu hóa và tách điểm có độ khó tương đương nhau về mặt thời gian đa thức!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-vòng-lặp-mặt-phẳng-cắt&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của vòng lặp Mặt phẳng cắt&lt;/h2&gt;

&lt;p&gt;Để nắm chắc cách thuật toán mặt phẳng cắt vận hành từ đầu tới cuối, hãy chú ý ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính hợp lệ (Validity) vs. Tính tách biệt (Separation):&lt;/strong&gt; Một bất đẳng thức mới phải thỏa mãn đồng thời hai vế: &lt;em&gt;hợp lệ&lt;/em&gt; (không được cắt mất bất kỳ nghiệm nguyên khả thi nào) và &lt;em&gt;tách được&lt;/em&gt; (phải cắt bỏ được nghiệm phân số \(x^{(k)}\) hiện tại để vòng lặp thực sự tiến bộ).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính đơn điệu của dãy đa diện và cận dưới:&lt;/strong&gt; Sau mỗi vòng lặp, ta có \(S \subseteq C_{k+1} \subseteq C_k\), do đó dãy giá trị nới lỏng \(z_{\text{LP}}^{(0)} \le z_{\text{LP}}^{(1)} \le \dots \le z^\star\) tăng dần về nghiệm nguyên tối ưu. Khi nghiệm nới lỏng \(x^{(k)}\) đầu tiên rơi trúng vào tập nguyên, thuật toán dừng ngay với chứng nhận tối ưu tuyệt đối.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tái tối ưu bằng Đơn hình Đối ngẫu (Dual Simplex Warm Start):&lt;/strong&gt; Khi thêm một ràng buộc mới cắt bỏ điểm tối ưu LP cũ \(x^{(k)}\), điểm cũ mất tính khả thi gốc nhưng &lt;em&gt;vẫn giữ tính khả thi đối ngẫu&lt;/em&gt;. Nhờ vậy, thuật toán đơn hình đối ngẫu chỉ cần xoay thêm vài bước trục (pivot) để tìm \(x^{(k+1)}\) thay vì giải lại LP từ đầu!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-2-vòng-lặp-thuật-toán-mặt-phẳng-cắt&quot;&gt;Giải thích: Chạy tay 2 vòng lặp thuật toán Mặt phẳng cắt&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch nguyên \(\min -x_1 - 2x_2\) trên tập nới lỏng ban đầu:&lt;/p&gt;

\[C_0 = \{(x_1, x_2) \ge 0 : 2x_1 + 2x_2 \le 3,\quad x_2 \le 1.4\}, \qquad x_1, x_2 \in \mathbb{Z}_+.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(k = 0\) (trên \(C_0\)):&lt;/strong&gt;
Vì hệ số của \(x_2\) (\(-2\)) âm hơn \(x_1\) (\(-1\)), ta đẩy \(x_2\) lên tối đa \(1.4\), rồi dùng phần dư của \(2x_1 + 2(1.4) \le 3\) cho \(x_1 = 0.1\).
Nghiệm LP là \(x^{(0)} = (0.1,\; 1.4)\) (phân số!), cận dưới \(z^{(0)} = -0.1 - 2.8 = -2.9\).
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Bài toán tách:&lt;/em&gt; Từ \(x_2 \le 1.4\) và \(x_2 \in \mathbb{Z}\), ta sinh lát cắt hợp lệ đầu tiên: \(x_2 \le \lfloor 1.4 \rfloor = 1\). (Cắt bỏ \((0.1, 1.4)\) vì \(1.4 &amp;gt; 1\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(k = 1\) (trên \(C_1 = C_0 \cap \{x_2 \le 1\}\)):&lt;/strong&gt;
Đẩy \(x_2 = 1\), phần dư từ \(2x_1 + 2(1) \le 3\) cho \(x_1 = 0.5\).
Nghiệm LP mới là \(x^{(1)} = (0.5,\; 1)\) (vẫn phân số!), cận dưới tăng lên \(z^{(1)} = -0.5 - 2 = -2.5\).
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Bài toán tách:&lt;/em&gt; Từ \(2x_1 + 2x_2 \le 3 \Rightarrow x_1 + x_2 \le 1.5\) và \(x_1 + x_2 \in \mathbb{Z}\), ta sinh lát cắt hợp lệ thứ hai: \(x_1 + x_2 \le 1\). (Cắt bỏ \((0.5, 1)\) vì \(1.5 &amp;gt; 1\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(k = 2\) (trên \(C_2 = C_1 \cap \{x_1 + x_2 \le 1\}\)):&lt;/strong&gt;
Nghiệm LP mới là \(x^{(2)} = (0,\; 1)\) — &lt;strong&gt;toàn bộ là số nguyên!&lt;/strong&gt; Cận dưới tăng lên \(z^{(2)} = -2\).
Thuật toán dừng ngay tại \((0, 1)\) với giá trị tối ưu chính xác \(-2\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mục này trình bày khái niệm bất đẳng thức hợp lệ và cấu trúc chung của thuật toán mặt phẳng cắt để giải quy hoạch tuyến tính nguyên.&lt;/p&gt;

&lt;h2 id=&quot;bất-đẳng-thức-hợp-lệ-valid-inequality&quot;&gt;Bất đẳng thức hợp lệ (Valid Inequality)&lt;/h2&gt;

&lt;p&gt;Một bất đẳng thức tuyến tính \(\pi^{T}x \le \pi_{0}\) được gọi là &lt;em&gt;hợp lệ&lt;/em&gt; đối với tập \(S\) nếu mọi điểm của \(S\) đều nằm trong nửa không gian xác định bởi bất đẳng thức đó:&lt;/p&gt;

&lt;blockquote&gt;
\[\pi^{T}x \le \pi_{0} \quad \text{với mọi } x \in S\]
&lt;/blockquote&gt;

&lt;p&gt;Điều kiện hợp lệ đảm bảo việc bổ sung bất đẳng thức sẽ không bao giờ loại bỏ nghiệm nguyên khả thi nào của bài toán gốc.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán-mặt-phẳng-cắt&quot;&gt;Thuật toán mặt phẳng cắt&lt;/h2&gt;

&lt;p&gt;Xét bài toán quy hoạch nguyên (IP):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
          \min_{x} &amp;amp; \quad {c^{T}x} \\\\
\text{subject to } &amp;amp; \quad  x \in C \\\\
                   &amp;amp; \quad  x_j \in \mathbb{Z}, \quad j \in J
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;và đặt \(S := \text{conv} \left \{ x \in C : x_j \in \mathbb{Z}, j \in J \right \}\).&lt;/p&gt;

&lt;h3 id=&quot;các-bước-thực-hiện&quot;&gt;Các bước thực hiện&lt;/h3&gt;

&lt;p&gt;Ký hiệu bài toán nới lỏng lồi là (CP) và bài toán gốc là (IP):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Khởi tạo \(C_{0} := C\) và tính \(x^{(0)} := \arg\min_{x} \left\{c^{T}x : x \in C_{0} \right\}\).&lt;/li&gt;
  &lt;li&gt;Với \(k = 0, 1, \dots\): &lt;br /&gt;
\(\quad\) Nếu \(x^{(k)}\) khả thi cho (IP) thì \(x^{(k)}\) là nghiệm tối ưu; dừng thuật toán. &lt;br /&gt;
\(\quad\) Ngược lại: &lt;br /&gt;
\(\quad\quad\) Tìm một bất đẳng thức \((\pi, \pi_{0})\) hợp lệ đối với \(S\) sao cho \(\pi^T x^{(k)} &amp;gt; \pi_0\) (tức cắt bỏ \(x^{(k)}\)). &lt;br /&gt;
\(\quad\quad\) Cập nhật \(C_{k+1} := C_{k} \cap \{ x : \pi^{T}x \le \pi_{0} \}\). &lt;br /&gt;
\(\quad\quad\) Giải lại bài toán nới lỏng: \(x^{(k+1)} := \arg\min_{x} \left\{c^{T}x : x \in C_{k+1} \right\}\). &lt;br /&gt;
\(\quad\) Kết thúc nhánh điều kiện. &lt;br /&gt;
Kết thúc vòng lặp.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Bất đẳng thức hợp lệ tách được \(x^{(k)}\) khỏi \(S\) như trên được gọi là &lt;strong&gt;mặt phẳng cắt (cutting plane)&lt;/strong&gt; hoặc &lt;strong&gt;lát cắt (cut)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Ở bước 1, thuật toán giải bài toán nới lỏng lồi (CP) ban đầu trên \(C\). Ở bước 2, nếu nghiệm thu được đã thỏa mãn ràng buộc nguyên thì quá trình kết thúc; ngược lại, ta thêm một mặt phẳng cắt để loại bỏ nghiệm phân số \(x^{(k)}\), thu hẹp miền khả thi thành \(C_{k+1}\) và giải lại (CP).&lt;/p&gt;

&lt;p&gt;Trong Hình 1, đa giác biểu diễn miền nới lỏng \(C\) và chấm đen là nghiệm của (CP). Bất đẳng thức hợp lệ cắt bỏ chấm đen này trong khi vẫn giữ nguyên toàn bộ bao lồi \(S\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_02_valid_inequality.png&quot; alt=&quot;[Hình 1] Bất đẳng thức hợp lệ&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Bất đẳng thức hợp lệ [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Qua các vòng lặp, tập \(C_k\) dần được siết chặt về phía bao lồi \(S\) cho tới khi nghiệm của bài toán nới lỏng rơi vào một điểm nguyên khả thi của (IP).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>25-01-01 Lồi hóa (Convexification)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_01_01_Convexification/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter25/25_01_01_Convexification</id>
   <content type="html">&lt;p&gt;Một câu hỏi lý thuyết đẹp đến ngỡ ngàng: &lt;em&gt;nếu bài toán quy hoạch nguyên khó vì tập khả thi rời rạc và không lồi, liệu ta có thể “bọc” toàn bộ các điểm nguyên khả thi bằng một tập lồi nhỏ nhất (bao lồi) rồi giải như một bài toán tối ưu lồi bình thường không?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Câu trả lời là &lt;strong&gt;có&lt;/strong&gt; — quá trình đó gọi là &lt;strong&gt;lồi hóa (convexification)&lt;/strong&gt;. Khi hàm mục tiêu là tuyến tính \(c^T x\), cực tiểu trên một tập rời rạc luôn trùng khớp hoàn toàn với cực tiểu trên bao lồi \(S\) của nó, bởi giá trị nhỏ nhất của hàm tuyến tính luôn đạt tại một đỉnh cực trị — mà mọi đỉnh cực trị của \(S\) chính là các điểm nguyên khả thi ban đầu!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-phép-lồi-hóa&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của phép Lồi hóa&lt;/h2&gt;

&lt;p&gt;Để hiểu vì sao lồi hóa vừa là “chén thánh” lý thuyết, vừa không thể thực hiện trực tiếp một lần cho xong trong thực tế, hãy nắm ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tương đương tối ưu trên Bao lồi (Convex Hull Equivalence):&lt;/strong&gt; Với hàm mục tiêu tuyến tính \(c^T x\), mọi điểm \(x \in S = \operatorname{conv}(X)\) là tổ hợp lồi \(\sum \lambda_i x^{(i)}\) của các điểm nguyên \(x^{(i)} \in X\), nên \(c^T x = \sum \lambda_i (c^T x^{(i)}) \ge \min_{i} c^T x^{(i)}\). Do đó \(\min_{x \in S} c^T x = \min_{x \in X} c^T x\) — không hề bị nới lỏng chút nào!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý Meyer (1974) về tính đa diện:&lt;/strong&gt; Khi \(C = \{x : Ax \le b\}\) là một đa diện hữu tỷ (mọi hệ số của \(A, b\) là số hữu tỷ), bao lồi nguyên \(S = \operatorname{conv}(\{x \in C : x_j \in \mathbb{Z}\})\) cũng là một &lt;strong&gt;đa diện&lt;/strong&gt; (biểu diễn được bằng hữu hạn bất đẳng thức tuyến tính). Nói cách khác, về nguyên tắc, mọi MILP hữu tỷ đều là một LP!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghịch lý kích thước (Exponential Number of Facets):&lt;/strong&gt; Dù \(S\) chỉ có hữu hạn mặt biên, số lượng bất đẳng thức cần để mô tả trọn vẹn \(S\) có thể tăng theo hàm mũ theo số chiều \(n\). Vì vậy, thay vì dựng toàn bộ \(S\) từ đầu, ta chỉ xây dựng &lt;em&gt;cục bộ&lt;/em&gt; vài mặt biên ngay quanh vùng chứa nghiệm tối ưu bằng thuật toán mặt phẳng cắt.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-dựng-toàn-bộ-bao-lồi-nguyên-s-của-một-đa-diện-2-chiều&quot;&gt;Giải thích: Tự tay dựng toàn bộ bao lồi nguyên \(S\) của một đa diện 2 chiều&lt;/h3&gt;

&lt;p&gt;Xét đa diện nới lỏng \(P = \{(x_1, x_2) \in \mathbb{R}^2 : x_1 \ge 0,\; x_2 \ge 0,\; 3x_1 + 2x_2 \le 5\}\). Hãy tìm chính xác bao lồi nguyên \(S = \operatorname{conv}(P \cap \mathbb{Z}^2)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Liệt kê tất cả điểm nguyên khả thi trong \(P\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(x_1 = 0\): \(2x_2 \le 5 \Rightarrow x_2 \in \{0, 1, 2\}\), cho các điểm \((0, 0), (0, 1), (0, 2)\).&lt;/li&gt;
      &lt;li&gt;Với \(x_1 = 1\): \(3 + 2x_2 \le 5 \Rightarrow x_2 \in \{0, 1\}\), cho các điểm \((1, 0), (1, 1)\).&lt;/li&gt;
      &lt;li&gt;Với \(x_1 \ge 2\): \(3(2) = 6 &amp;gt; 5\) — không còn điểm nguyên nào!
Tổng cộng có đúng 5 điểm nguyên: \((0,0), (1,0), (0,1), (1,1), (0,2)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác định các đỉnh cực trị và mặt biên (facets) của \(S\):&lt;/strong&gt;
Bốn đỉnh ngoài cùng tạo nên bao lồi là \((0,0), (1,0), (1,1), (0,2)\) (điểm \((0,1)\) nằm trên cạnh nối \((0,0)\) và \((0,2)\)).
Bốn cạnh biên bao quanh tứ giác này cho hệ bất đẳng thức tuyến tính chính xác của \(S\):
\(x_1 \ge 0, \qquad x_2 \ge 0, \qquad x_1 \le 1, \qquad x_1 + x_2 \le 2.\)
(Kiểm tra: cạnh nối \((1,1)\) và \((0,2)\) chính là đường thẳng \(x_1 + x_2 = 2\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng sức mạnh lồi hóa với hàm mục tiêu \(\min -x_1 - 0.1 x_2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Trên \(P\) ban đầu: LP dừng tại đỉnh phân số \((5/3,\; 0) \approx (1.667, 0)\) với giá trị \(-1.667\).&lt;/li&gt;
      &lt;li&gt;Trên bao lồi \(S\): LP chạy thẳng tới đỉnh nguyên \((1, 1)\) với giá trị chính xác \(-1.1\)! Mọi hàm mục tiêu tuyến tính \(c_1 x_1 + c_2 x_2\) bất kỳ tối ưu trên \(S\) đều cho ra đúng đỉnh nguyên!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Quá trình biến đổi một bài toán quy hoạch nguyên thành một bài toán tối ưu lồi tương đương được gọi là lồi hóa (convexification). Trong trường hợp quy hoạch tuyến tính nguyên, tập khả thi sau khi lồi hóa trở thành một đa diện (polyhedron), tạo cơ sở lý thuyết để xây dựng các mặt phẳng cắt hợp lệ.&lt;/p&gt;

&lt;h2 id=&quot;lồi-hóa&quot;&gt;Lồi hóa&lt;/h2&gt;

&lt;p&gt;Xét bài toán quy hoạch nguyên với hàm mục tiêu tuyến tính, tập ràng buộc lồi \(C\) và ràng buộc nguyên trên tập chỉ số \(J\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
          \min_{x} &amp;amp; \quad {c^{T}x} \\\\
\text{subject to } &amp;amp; \quad  x \in C \\\\
                   &amp;amp; \quad  x_j \in \mathbb{Z}, \quad j \in J
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Định nghĩa bao lồi của tập các điểm khả thi nguyên là \(S := \text{conv} \left \{ x \in C : x_j \in \mathbb{Z}, j \in J \right \}\). Thay tập khả thi ban đầu bằng \(S\), ta thu được bài toán tối ưu lồi tương đương:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
          \min_{x} &amp;amp; \quad {c^{T}x} \\\\
\text{subject to } &amp;amp; \quad  x \in S
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong Hình 1, vùng xanh là tập lồi \(C\), các điểm đỏ là những điểm thỏa mãn ràng buộc nguyên, và vùng đỏ chính là bao lồi \(S\) của các điểm đó.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_cutting_plane_concept.png&quot; alt=&quot;[Hình 1] Mặt phẳng cắt&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Mặt phẳng cắt&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Nguồn: https://commons.wikimedia.org/wiki/File:Cutting_plane_algorithm2.png&lt;/p&gt;

&lt;p&gt;Hai bài toán có cùng giá trị tối ưu (và mọi điểm cực trị của \(S\) đều là điểm nguyên) chính vì hàm mục tiêu \(c^T x\) là hàm tuyến tính.&lt;/p&gt;

&lt;h2 id=&quot;trường-hợp-đặc-biệt-quy-hoạch-tuyến-tính-nguyên&quot;&gt;Trường hợp đặc biệt: quy hoạch tuyến tính nguyên&lt;/h2&gt;

&lt;p&gt;Áp dụng lồi hóa cho bài toán quy hoạch tuyến tính nguyên:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
          \min_{x} &amp;amp; \quad {c^{T}x} \\\\
\text{subject to } &amp;amp; \quad  Ax \le b \\\\
                   &amp;amp; \quad  x_j \in \mathbb{Z}, \quad j \in J
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ta có kết quả nền tảng sau về bao lồi \(S\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; Nếu các phần tử của \(A\) và \(b\) là số hữu tỉ thì tập
\(S := \text{conv} \left \{ x : Ax \le b, \; x_j \in \mathbb{Z}, \; j \in J \right \}\)
là một đa diện (polyhedron).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Về mặt lý thuyết, điều này đồng nghĩa quy hoạch tuyến tính nguyên có thể viết dưới dạng một quy hoạch tuyến tính trên đa diện \(S\). Tuy nhiên, trên thực tế đa diện \(S\) có thể cần số lượng bất đẳng thức lớn theo hàm mũ để mô tả đầy đủ. Do đó ta không thể liệt kê trước toàn bộ \(S\) mà phải giải gián tiếp bằng các kỹ thuật như mặt phẳng cắt hay nhánh và cắt.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>24 Quy Hoạch Số Nguyên Hỗn Hợp (Phần I)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_Mixed_integer_programming/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_Mixed_integer_programming</id>
   <content type="html">&lt;p&gt;Suốt 23 chương trước, ta sống trong thế giới êm đềm của tối ưu lồi liên tục — nơi mọi biến đều có thể nhận giá trị \(0.37\) hay \(2.418\), và một bước đạo hàm dẫn thẳng tới cực tiểu toàn cục. Nhưng thế giới thực hiếm khi liên tục như vậy: bạn không thể điều \(0.4\) chiếc máy bay cất cánh, không thể xây \(0.7\) cái nhà kho, và cũng không thể chọn \(0.6\) một đặc trưng trong mô hình thống kê.&lt;/p&gt;

&lt;p&gt;Ngay khoảnh khắc ta thêm ràng buộc tưởng chừng bé nhỏ \(x_j \in \mathbb{Z}\) (hoặc \(x_j \in \{0, 1\}\)), toàn bộ địa hình tối ưu vỡ vụn thành các điểm rời rạc, biến bài toán thành &lt;strong&gt;quy hoạch số nguyên hỗn hợp (Mixed Integer Programming — MIP)&lt;/strong&gt; — một trong những công cụ mô hình hóa mạnh mẽ nhất nhưng cũng thách thức nhất của vận trù học và khoa học dữ liệu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-quy-hoạch-số-nguyên-hỗn-hợp-phần-i&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của Quy hoạch số nguyên hỗn hợp (Phần I)&lt;/h2&gt;

&lt;p&gt;Chương 24 mở cánh cửa bước vào thế giới tối ưu rời rạc thông qua bốn trụ cột liên hoàn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ngôn ngữ mô hình hóa bằng biến nhị phân (Binary Modeling):&lt;/strong&gt; Biến \(x_j \in \{0, 1\}\) đóng vai trò như công tắc logic “có/không”, cho phép mã hóa quyết định đầu tư, ràng buộc chọn tối đa \(k\) phần tử, định tuyến, và các điều kiện logic “nếu–thì” thành hệ bất đẳng thức tuyến tính.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ khó NP-khó và Nghịch lý làm tròn (Why Rounding Fails):&lt;/strong&gt; Việc giải bài toán nới lỏng liên tục (bỏ ràng buộc nguyên) rồi làm tròn nghiệm có thể cho ra điểm &lt;em&gt;không khả thi&lt;/em&gt; hoặc &lt;em&gt;kém tối ưu rất xa&lt;/em&gt; — đó là lý do ta cần các thuật toán tìm kiếm có chứng nhận.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép nới lỏng và Cận đối ngẫu (Relaxations &amp;amp; Dual Bounds):&lt;/strong&gt; Mở rộng miền khả thi về một tập lồi (nới lỏng LP/lồi hoặc nới lỏng Lagrange) cung cấp cận dưới chặt, đóng vai trò chiếc la bàn đo khoảng cách tới nghiệm nguyên tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chia để trị bằng Nhánh và Cận (Branch and Bound):&lt;/strong&gt; Phân hoạch bài toán gốc thành cây các bài toán con nhỏ hơn và mạnh tay &lt;em&gt;cắt tỉa&lt;/em&gt; (prune) những nhánh có cận dưới tệ hơn nghiệm nguyên tốt nhất đã biết — nền tảng của mọi bộ giải MIP chính xác.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-vì-sao-không-thể-giải-lp-rồi-làm-tròn&quot;&gt;Giải thích: Vì sao không thể “giải LP rồi làm tròn”?&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch nguyên 2 biến cực kỳ đơn giản:&lt;/p&gt;

\[\max_{x_1, x_2}\ 3x_1 + 2x_2 \qquad \text{thỏa mãn } x_1 + x_2 \le 2.5,\quad 2x_1 + x_2 \le 4,\quad x_1, x_2 \in \mathbb{Z}_+.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán nới lỏng tuyến tính (LP relaxation, bỏ yêu cầu nguyên):&lt;/strong&gt;
Giao điểm của hai đường thẳng biên \(x_1 + x_2 = 2.5\) và \(2x_1 + x_2 = 4\) là \((x_1, x_2) = (1.5,\; 1)\).
Kiểm tra các đỉnh của miền LP: tại \((0, 2.5)\) giá trị bằng \(5\); tại \((2, 0)\) giá trị bằng \(6\); tại \((1.5, 1)\) giá trị bằng \(3(1.5) + 2(1) = 6.5\) (cực đại LP!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử làm tròn nghiệm LP \((1.5,\; 1)\) sang số nguyên gần nhất:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Làm tròn lên&lt;/em&gt; thành \((2, 1)\): kiểm tra ràng buộc \(2(2) + 1 = 5 &amp;gt; 4\) — &lt;strong&gt;vi phạm ràng buộc, không khả thi!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Làm tròn xuống&lt;/em&gt; thành \((1, 1)\): khả thi (\(1+1=2 \le 2.5\) và \(2+1=3 \le 4\)), cho giá trị \(3(1) + 2(1) = 5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So với nghiệm nguyên tối ưu thực sự:&lt;/strong&gt;
Điểm nguyên \((2, 0)\) thỏa mãn cả hai ràng buộc (\(2 + 0 = 2 \le 2.5\) và \(4 + 0 = 4 \le 4\)) và đạt giá trị \(3(2) + 2(0) = 6 &amp;gt; 5\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài học rút ra:&lt;/strong&gt; Làm tròn lên thì mất tính khả thi, làm tròn xuống thì bỏ lỡ nghiệm tối ưu \((2, 0)\) nằm ở hướng hoàn toàn khác. Chính khoảng trống này giải thích vì sao ta cần cả Chương 24 (Nhánh và cận) lẫn Chương 25 (Mặt phẳng cắt).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chương này giới thiệu định nghĩa, tính chất và các ví dụ kinh điển của quy hoạch số nguyên hỗn hợp (Mixed Integer Programming — MIP), đồng thời trình bày cách tiếp cận tìm nghiệm tối ưu gián tiếp thông qua các bài toán nới lỏng (relaxation) và thuật toán nhánh và cận.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-giai-đoạn-20222026-tùy-chọn&quot;&gt;Ứng dụng giai đoạn 2022–2026 (tùy chọn)&lt;/h2&gt;

&lt;p&gt;Các mô hình phân công, bài toán cái túi (knapsack) và đặt cơ sở không chỉ là ví dụ kinh điển trong giáo trình: xếp lịch phi hành đoàn (bộ chuẩn MIPLIB &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;air05&lt;/code&gt;), định tuyến giao hàng chặng cuối (last-mile) kết hợp dự báo nhu cầu, và lựa chọn vị trí kho hàng hay cụm GPU biên đều trực tiếp kế thừa khung mô hình ở mục 24-02. Bên cạnh đó, từ sau NeurIPS 2019, một hướng nghiên cứu mới — học quy tắc rẽ nhánh ngay bên trong thuật toán nhánh và cận — đã phát triển mạnh quanh các mô hình này. Bạn có thể đọc tiếp tại &lt;a href=&quot;/contents/vi/chapter24/24_06_modern_applications/&quot;&gt;24-06 Ứng dụng hiện đại của mô hình nguyên hỗn hợp&lt;/a&gt;; các chủ đề chọn đặc trưng, kiểm chứng mạng nơ-ron và cây quyết định tối ưu sẽ được trình bày ở Chương 25.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>24-05 Thuật toán nhánh và cận (B&B)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_05_Branch_and_bound_algorithm/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_05_Branch_and_bound_algorithm</id>
   <content type="html">&lt;p&gt;Nếu bạn có một bài toán với \(100\) biến nhị phân, tổng số tổ hợp lên tới \(2^{100} \approx 1.26 \times 10^{30}\) — nhiều hơn số nguyên tử trong một ngọn núi. Vét cạn là bất khả thi. Thế nhưng thuật toán &lt;strong&gt;Nhánh và Cận (Branch and Bound)&lt;/strong&gt;, được Ailsa Land và Alison Doig giới thiệu năm 1960, vẫn thường xuyên giải chính xác những bài toán hàng chục nghìn biến chỉ trong vài giây.&lt;/p&gt;

&lt;p&gt;Bí quyết của Nhánh và Cận nằm ở hai chữ &lt;strong&gt;cắt tỉa (pruning)&lt;/strong&gt;: thay vì đi xuống tận đáy của mọi nhánh cây, ta giải nhanh bài toán nới lỏng lồi tại mỗi nút để lấy cận dưới; ngay khi thấy cận dưới của một nhánh đã tệ hơn (hoặc bằng) nghiệm nguyên tốt nhất đang giữ trong tay, ta lập tức chém phăng cả nhánh cây hàng tỷ nút phía dưới đó mà không bỏ sót nghiệm tối ưu!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-điều-khiển-cây-nhánh-và-cận&quot;&gt;Kiến thức cần nhớ: Ba trụ cột điều khiển cây Nhánh và Cận&lt;/h2&gt;

&lt;p&gt;Khi theo dõi một cây Nhánh và Cận, mọi thao tác ở mỗi nút đều quy về ba quy tắc rõ ràng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc phân nhánh (Branching):&lt;/strong&gt; Khi nghiệm nới lỏng \(x^\star\) tại một nút còn chứa thành phần phân số \(x_j^\star \notin \mathbb{Z}\) (với \(j \in J\)), ta tách nút đó thành hai bài toán con loại trừ hoàn toàn điểm phân số này: nhánh trái thêm \(x_j \le \lfloor x_j^\star \rfloor\) và nhánh phải thêm \(x_j \ge \lceil x_j^\star \rceil\). Hợp của hai nhánh vẫn phủ trọn mọi điểm nguyên khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ba điều kiện cắt tỉa (Fathoming / Pruning Rules):&lt;/strong&gt; Một nút con được đóng lại ngay lập tức (không cần phân nhánh tiếp) nếu rơi vào một trong ba trường hợp: (1) &lt;em&gt;Vô nghiệm&lt;/em&gt; (bài toán nới lỏng không có nghiệm); (2) &lt;em&gt;Cắt theo cận&lt;/em&gt; (cận dưới \(l(X_i) \ge u\), không thể tốt hơn kỷ lục hiện tại); hoặc (3) &lt;em&gt;Nghiệm nguyên&lt;/em&gt; (nghiệm nới lỏng tự động nguyên — lúc này ta cập nhật kỷ lục \(u \leftarrow \min(u, l(X_i))\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược duyệt cây (Node &amp;amp; Variable Selection):&lt;/strong&gt; Chọn nút nào mở tiếp (duyệt sâu để sớm tìm nghiệm khả thi hạ \(u\), hay duyệt nút có cận dưới nhỏ nhất &lt;em&gt;best-first&lt;/em&gt; để nhanh nâng cận toàn cục) và chọn biến phân số nào để rẽ nhánh quyết định trực tiếp kích thước cây tìm kiếm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-trọn-vẹn-một-cây-nhánh-và-cận&quot;&gt;Giải thích: Chạy tay trọn vẹn một cây Nhánh và Cận&lt;/h3&gt;

&lt;p&gt;Hãy tự tay giải bài toán quy hoạch nguyên cực tiểu hóa:&lt;/p&gt;

\[\min_{x_1, x_2 \in \mathbb{Z}_+}\ -5x_1 - 4x_2 \qquad \text{thỏa mãn } 2x_1 + 2x_2 \le 5.\]

&lt;p&gt;Khởi tạo kỷ lục (cận trên toàn cục) \(u = +\infty\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nút gốc \(N_0\) (chưa thêm ràng buộc nhánh):&lt;/strong&gt;
Giải nới lỏng LP: vì hệ số \(-5 &amp;lt; -4\), dồn hết vào \(x_1\) cho ra \(x^{(0)} = (2.5,\; 0)\), cận dưới \(l(N_0) = -12.5\).
Vì \(x_1 = 2.5\) là số phân số, ta rẽ nhánh thành \(N_1: x_1 \le 2\) và \(N_2: x_1 \ge 3\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nút \(N_2\) (\(x_1 \ge 3\)):&lt;/strong&gt;
Ràng buộc \(2x_1 + 2x_2 \le 5\) với \(x_1 \ge 3, x_2 \ge 0\) cho \(6 \le 5\) — &lt;strong&gt;Vô nghiệm → Cắt tỉa (infeasibility)!&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nút \(N_1\) (\(x_1 \le 2\)):&lt;/strong&gt;
Giải LP trên \(2x_1 + 2x_2 \le 5,\; x_1 \le 2\): lấy tối đa \(x_1 = 2\), phần dư cho \(x_2 = 0.5\). Nghiệm \(x^{(1)} = (2,\; 0.5)\), cận dưới \(l(N_1) = -5(2) - 4(0.5) = -12\).
Vì \(x_2 = 0.5\) phân số, rẽ nhánh thành \(N_{1a}: x_2 \le 0\) và \(N_{1b}: x_2 \ge 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nút \(N_{1a}\) (\(x_1 \le 2,\; x_2 \le 0\)):&lt;/strong&gt;
LP cho nghiệm \(x = (2, 0)\) — &lt;strong&gt;toàn số nguyên!&lt;/strong&gt; Giá trị bằng \(-10\). Cập nhật kỷ lục \(u = -10\) và &lt;strong&gt;Cắt tỉa (integrality)&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nút \(N_{1b}\) (\(x_1 \le 2,\; x_2 \ge 1\)):&lt;/strong&gt;
Từ \(2x_1 + 2(1) \le 5 \Rightarrow x_1 \le 1.5\). Nghiệm LP là \((1.5, 1)\) với \(l(N_{1b}) = -7.5 - 4 = -11.5 &amp;lt; -10\) (chưa cắt được vì còn hy vọng!). Rẽ nhánh trên \(x_1\):
    &lt;ul&gt;
      &lt;li&gt;\(N_{1b1}\) (\(x_1 \ge 2, x_2 \ge 1\)): \(2(2)+2(1) = 6 &amp;gt; 5\) — &lt;strong&gt;Vô nghiệm → Cắt tỉa!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;\(N_{1b2}\) (\(x_1 \le 1, x_2 \ge 1\)): LP cho nghiệm nguyên \((1, 1)\) với giá trị \(-9 \ge u = -10\) — &lt;strong&gt;Cắt tỉa (theo cận)!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Hết nút mở! Nghiệm tối ưu được chứng nhận chắc chắn là \(x^\star = (2, 0)\) với giá trị \(-10\). Cả ba quy tắc cắt tỉa (vô nghiệm, nguyên, theo cận) đều đã hoạt động nhịp nhàng!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mục này trình bày cách giải bài toán quy hoạch nguyên bằng thuật toán nhánh và cận (Branch and Bound) kết hợp với nới lỏng lồi.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa-và-nguyên-lý&quot;&gt;Định nghĩa và nguyên lý&lt;/h2&gt;

&lt;p&gt;Nhánh và cận là thuật toán tiêu chuẩn và phổ biến nhất để giải chính xác quy hoạch nguyên. Về bản chất, đây là chiến lược chia để trị: phân hoạch bài toán gốc thành các bài toán con nhỏ hơn và loại bỏ sớm những nhánh không thể chứa nghiệm tối ưu.&lt;/p&gt;

&lt;p&gt;Nếu tập khả thi được phân hoạch thành \(X = X_{1} \cup X_{2} \cup \dotsc \cup X_{k}\), thì:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_{x \in X} f(x) = \min_{i = 1, \dotsc , k} \lbrace \min_{x \in X_{i}} f(x) \rbrace .\]
&lt;/blockquote&gt;

&lt;p&gt;Bất kỳ nghiệm khả thi nào tìm được đều cung cấp một cận trên toàn cục \(u(X)\). Với mỗi bài toán con trên \(X_i\), ta tính một cận dưới \(l(X_i)\). Nếu \(l(X_i) \geq u(X)\), bài toán con \(\min_{x \in X_i} f(x)\) chắc chắn không thể cải thiện nghiệm tốt nhất hiện có nên có thể cắt tỉa (loại bỏ) hoàn toàn.&lt;/p&gt;

&lt;p&gt;Xét bài toán quy hoạch nguyên (IP):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; x \in C \\\\
&amp;amp;&amp;amp;&amp;amp;x_j \in \mathbb{Z}, \quad j \in J
\end{align}\)
\(\begin{align}
\text{trong đó } f \text{ lồi, } f : \mathbb{R}^{n} \rightarrow \mathbb{R}, \quad C \subseteq \mathbb{R}^n 
\quad \text{và} \quad J \subseteq \lbrace 1, \dotsc, n \rbrace
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;và bài toán nới lỏng lồi tương ứng (CR):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;x \in C
\end{align}\)
\(\begin{align}
\text{trong đó } f \text{ lồi, } f : \mathbb{R}^{n} \rightarrow \mathbb{R}, \quad C \subseteq \mathbb{R}^n.
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thuật toán nhánh và cận giải đệ quy trên từng nút bài toán con theo quy trình sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Giải bài toán nới lỏng (CR) tại nút hiện tại:
    &lt;ul&gt;
      &lt;li&gt;Nếu (CR) vô nghiệm thì (IP) trên nhánh này cũng vô nghiệm — dừng (cắt tỉa).&lt;/li&gt;
      &lt;li&gt;Nếu nghiệm \(x^{\star}\) của (CR) đã thỏa mãn toàn bộ ràng buộc nguyên của (IP) thì \(x^{\star}\) là nghiệm tối ưu cục bộ của nhánh; cập nhật cận trên toàn cục nếu \(f(x^{\star})\) nhỏ hơn cận trên hiện tại, rồi dừng.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Nếu \(x^{\star}\) chưa nguyên, giá trị tối ưu của (CR) cung cấp cận dưới cho nhánh hiện tại.&lt;/li&gt;
  &lt;li&gt;Nếu cận dưới này lớn hơn hoặc bằng cận trên toàn cục hiện có — dừng (cắt tỉa).&lt;/li&gt;
  &lt;li&gt;Ngược lại, chia tập ràng buộc (thường bằng cách rẽ nhánh trên một biến nguyên \(x_j\) đang nhận giá trị phân số: \(x_j \leq \lfloor x_j^\star \rfloor\) và \(x_j \geq \lceil x_j^\star \rceil\)) rồi giải đệ quy từng bài toán con.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;xử-lý-sau-khi-phân-nhánh&quot;&gt;Xử lý sau khi phân nhánh&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Sau khi phân nhánh, từng bài toán con được giải và đánh giá theo cùng quy tắc trên.&lt;/li&gt;
  &lt;li&gt;Bất kỳ bài toán con nào có cận dưới lớn hơn hoặc bằng cận trên hiện tại đều bị cắt tỉa mà không cần phân nhánh thêm.&lt;/li&gt;
  &lt;li&gt;Nới lỏng lồi là cách phổ biến và đáng tin cậy nhất để tính cận dưới, bên cạnh các lựa chọn khác như nới lỏng Lagrange.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;nhánh-và-cận-từng-bước-video&quot;&gt;Nhánh và cận từng bước (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/branch-bound_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Thuật toán giải LP nới lỏng, rẽ nhánh theo một biến đang nhận giá trị phân số, và cắt bỏ mọi nút có cận dưới không thể cải thiện nghiệm nguyên tốt nhất đã tìm được.&lt;/p&gt;

&lt;p&gt;Lưu ý: video giải bài toán dạng cực đại (\(\max\ 5x_1 + 4x_2\)), còn bài viết dùng dạng cực tiểu. Hai dạng tương đương vì \(\max_x c^Tx = -\min_x (-c^Tx)\). Khi làm với dạng cực đại, hai cận đổi vai: giá trị LP nới lỏng ở mỗi nút là cận &lt;strong&gt;trên&lt;/strong&gt;, nghiệm nguyên tốt nhất đã có là cận &lt;strong&gt;dưới&lt;/strong&gt;, và nút bị cắt tỉa khi cận trên của nó không vượt được nghiệm nguyên tốt nhất.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-duyệt-qua-nhánh-và-cận&quot;&gt;Tự tay thử: duyệt qua nhánh và cận&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;bnb&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>24-04 Nới Lỏng</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_04_Relaxations/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_04_Relaxations</id>
   <content type="html">&lt;p&gt;Nếu ví quy hoạch nguyên như một khối đá gồ ghề khó đẽo, thì &lt;strong&gt;phép nới lỏng (relaxation)&lt;/strong&gt; là nghệ thuật đặt khối đá đó vào bên trong một chiếc hộp lồi trơn tru hơn để ước lượng nhanh đáy thấp nhất của nó. Một phép nới lỏng tốt phải đi trên sợi dây cân bằng tinh tế giữa hai yêu cầu ngược chiều: &lt;strong&gt;đủ dễ để giải thật nhanh&lt;/strong&gt;, nhưng cũng &lt;strong&gt;đủ chặt để cận dưới nằm thật sát nghiệm nguyên thật&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Trong bài học này, ta đối chiếu hai vũ khí tạo cận dưới quan trọng nhất của tối ưu rời rạc: &lt;strong&gt;nới lỏng lồi&lt;/strong&gt; (bỏ trực tiếp ràng buộc nguyên) và &lt;strong&gt;nới lỏng Lagrange&lt;/strong&gt; (giữ nguyên ràng buộc nguyên nhưng đưa các ràng buộc khó lên hàm mục tiêu kèm nhân tử phạt \(\lambda\)).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-lý-thuyết-nới-lỏng&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của lý thuyết Nới lỏng&lt;/h2&gt;

&lt;p&gt;Để chọn đúng phép nới lỏng cho từng cấu trúc bài toán, hãy nắm chắc ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hai điều kiện vàng của một phép nới lỏng:&lt;/strong&gt; Bài toán \(\min_{x \in Y} g(x)\) là nới lỏng của \(\min_{x \in X} f(x)\) khi và chỉ khi (1) mở rộng tập khả thi \(X \subseteq Y\), và (2) đánh giá thấp hàm mục tiêu \(g(x) \le f(x)\) trên mọi \(x \in X\). Hai điều kiện đơn giản này bảo đảm ngay lập tức \(\min_{Y} g \le \min_{X} f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng lồi (Convex / LP Relaxation):&lt;/strong&gt; Cách tự nhiên nhất là xóa bỏ điều kiện \(x_j \in \mathbb{Z}\) (giữ nguyên \(x \in C\)). Nó luôn giải được trong thời gian đa thức, nhưng chất lượng cận dưới phụ thuộc cực mạnh vào cách ta &lt;em&gt;viết&lt;/em&gt; các ràng buộc của \(C\) (ví dụ ràng buộc rời rạc \(x_{ij} \le y_j\) cho cận chặt hơn hẳn ràng buộc gộp).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng Lagrange (Lagrangian Relaxation) và Bài toán đối ngẫu Lagrange:&lt;/strong&gt; Khi bài toán gồm các ràng buộc “dễ” (cho phép tách biến hoặc giải nhanh trên tập nguyên) trộn với vài ràng buộc “khó” \(Ax \le b\), ta đưa \(Ax - b\) lên hàm mục tiêu với nhân tử \(\lambda \ge 0\). Tối đa hóa hàm đối ngẫu \(g(\lambda)\) cho ra cận dưới &lt;strong&gt;luôn bằng hoặc chặt hơn&lt;/strong&gt; nới lỏng LP tiêu chuẩn!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-nới-lỏng-lagrange-và-đối-chiếu-với-nới-lỏng-lp&quot;&gt;Giải thích: Tính tay Nới lỏng Lagrange và đối chiếu với Nới lỏng LP&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch nguyên 0–1 cực tiểu hóa:&lt;/p&gt;

\[z^\star = \min_{x_1, x_2 \in \{0, 1\}}\ 2x_1 + 5x_2 \qquad \text{thỏa mãn } x_1 + 2x_2 \ge 2.\]

&lt;p&gt;Quan sát nhanh: chỉ có hai nghiệm nguyên khả thi là \((0, 1)\) (giá trị \(5\)) và \((1, 1)\) (giá trị \(7\)), nên nghiệm đúng là \(z^\star = 5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính cận dưới bằng nới lỏng LP (cho \(x_1, x_2 \in [0, 1]\)):&lt;/strong&gt;
Vì \(x_1\) có tỷ số chi phí/đóng góp là \(2/1 = 2\) rẻ hơn \(x_2\) (\(5/2 = 2.5\)), LP lấy hết \(x_1 = 1\) rồi bù thêm \(x_2 = 0.5\) để vừa đủ \(1 + 2(0.5) = 2\).
Giá trị LP: \(z_{\text{LP}} = 2(1) + 5(0.5) = 4.5 \le 5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính cận dưới bằng nới lỏng Lagrange:&lt;/strong&gt;
Ta giữ nguyên tập nguyên \(x_1, x_2 \in \{0, 1\}\) và đưa ràng buộc \(2 - x_1 - 2x_2 \le 0\) lên hàm mục tiêu với nhân tử \(\lambda \ge 0\):
\(L(x, \lambda) = 2x_1 + 5x_2 + \lambda(2 - x_1 - 2x_2) = 2\lambda + (2 - \lambda)x_1 + (5 - 2\lambda)x_2.\)
Hàm đối ngẫu \(g(\lambda) = \min_{x_1, x_2 \in \{0, 1\}} L(x, \lambda)\) &lt;strong&gt;tách rời hoàn toàn&lt;/strong&gt; thành 2 quyết định độc lập (chọn \(x_i = 1\) nếu hệ số âm, chọn \(0\) nếu hệ số dương):
\(g(\lambda) = 2\lambda + \min(0,\; 2 - \lambda) + \min(0,\; 5 - 2\lambda).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử các giá trị \(\lambda\) để tìm cận dưới tốt nhất:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(\lambda = 2\): \(g(2) = 4 + 0 + 0 = 4\).&lt;/li&gt;
      &lt;li&gt;Tại \(\lambda = 2.5\): \(g(2.5) = 5 + \min(0, -0.5) + \min(0, 0) = 5 - 0.5 = 4.5\).&lt;/li&gt;
      &lt;li&gt;Tại \(\lambda = 3\): \(g(3) = 6 + (-1) + (-1) = 4\).
Giá trị đối ngẫu Lagrange cực đại đạt \(4.5\) tại \(\lambda^\star = 2.5\) — minh họa rõ cả tính tách biến tuyệt đẹp lẫn cơ chế cực đại hóa hàm lõm từng khúc \(g(\lambda)\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mục này trình bày định nghĩa tổng quát của phép nới lỏng (relaxation) cùng hai phương pháp phổ biến để tạo cận dưới cho quy hoạch nguyên: nới lỏng lồi (convex relaxation) và nới lỏng Lagrange (Lagrangian relaxation).&lt;/p&gt;

&lt;h2 id=&quot;điều-kiện-của-phép-nới-lỏng&quot;&gt;Điều kiện của phép nới lỏng&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối ưu gốc:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_{x \in X} f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Một bài toán tối ưu khác có dạng sau được gọi là một &lt;em&gt;nới lỏng&lt;/em&gt; của bài toán gốc:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x \in Y} \: g(x)\\\\
&amp;amp;\text{sao cho}\\\\
&amp;amp;\text{① } X \subseteq Y \quad \text{và}\\\\ 
&amp;amp;\text{② } g(x) \leq f(x) \text{ với mọi } x \in X 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu hàm mục tiêu \(g(x)\) trùng với \(f(x)\) thì chỉ cần thỏa mãn điều kiện ①; nếu \(g(x)\) khác \(f(x)\) thì phải thỏa mãn cả hai điều kiện. Từ hai điều kiện này, giá trị tối ưu của bài toán nới lỏng luôn là một cận dưới của giá trị tối ưu của bài toán gốc.&lt;/p&gt;

&lt;h2 id=&quot;nới-lỏng-lồi&quot;&gt;Nới lỏng lồi&lt;/h2&gt;

&lt;p&gt;Với bài toán quy hoạch nguyên hỗn hợp:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; x \in C \\\\
&amp;amp;&amp;amp;&amp;amp;x_j \in \mathbb{Z}, \quad j \in J
\end{align}\)
\(\begin{align}
\text{trong đó } f \text{ lồi, } f : \mathbb{R}^{n} \rightarrow \mathbb{R}, \quad C \subseteq \mathbb{R}^n 
\quad \text{và} \quad J \subseteq \lbrace 1, \dotsc, n \rbrace
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;bài toán nới lỏng lồi thu được bằng cách bỏ các ràng buộc nguyên \(x_j \in \mathbb{Z}\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp; f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; x \in C
\end{align}\)
\(\begin{align}
\text{trong đó } f \text{ lồi, } f: \mathbb{R}^{n} \rightarrow \mathbb{R}, \quad C \subseteq \mathbb{R}^n.
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;nới-lỏng-lagrange&quot;&gt;Nới lỏng Lagrange&lt;/h2&gt;

&lt;p&gt;Xét bài toán có thêm ràng buộc tuyến tính \(Ax \leq b\) bên cạnh tập ràng buộc \(X\) (có thể chứa cả các ràng buộc nguyên):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;Ax \leq b \\\\
&amp;amp;&amp;amp;&amp;amp; x_{j} \in \mathbb{Z}, \quad x \in X 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Đưa ràng buộc \(Ax \leq b\) lên hàm mục tiêu với nhân tử Lagrange \(u \geq 0\), ta thu được hàm đối ngẫu Lagrange:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
L(u) = &amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) + u^{\top}(Ax-b) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;x \in X
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Phép nới lỏng này mở rộng tập khả thi, và với mọi \(x\) thỏa mãn \(Ax \leq b\) cùng \(u \geq 0\), ta luôn có \(f(x) + u^{\top}(Ax - b) \leq f(x)\). Vì vậy \(L(u)\) là một cận dưới hợp lệ với mọi \(u \geq 0\). Cận dưới chặt nhất thu được bằng cách giải bài toán đối ngẫu Lagrange \(\max_{u \geq 0} L(u)\). Do \(L(u)\) là cận dưới theo từng điểm của một họ hàm affine theo \(u\), \(L(u)\) luôn là hàm lõm, nên bài toán đối ngẫu là bài toán cực đại hóa hàm lõm (tương đương tối ưu lồi).&lt;/p&gt;

&lt;p&gt;Áp dụng nới lỏng Lagrange cho bài toán đặt cơ sở ở mục 24-02 bằng cách nới lỏng ràng buộc đẳng thức \(\sum_j x_{ij} = 1\) với nhân tử không ràng buộc dấu \(v\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
L(v) = &amp;amp;\min_{x, y} &amp;amp;&amp;amp; \sum_{j = 1}^{n} f_{j}y_{j} + \sum_{i = 1}^{m}\sum_{j = 1}^{n}(c_{ij} - v_{i})x_{ij} + \sum_{i = 1}^{m} v_{i} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; x_{ij} \leq y_{j}, \quad i = 1, \dotsc, m, \quad j = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp; x_{ij}, y_{j} \in \lbrace 0, 1 \rbrace, \quad i = 1, \dotsc, m, \quad j = 1, \dotsc, n 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Với mỗi vector \(v\) cố định, bài toán con \(L(v)\) có nghiệm dạng đóng rất dễ tính:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(x_{ij}(v) =\begin{cases}1 &amp;amp; \text{nếu } c_{ij} - v_{i} &amp;lt; 0 \text{ và } \sum_{l} (c_{lj} - v_{l})^{-} + f_{j} &amp;lt; 0 \\\\
0 &amp;amp; \text{ngược lại,} \end{cases}\)
\(y_{j}(v) =\begin{cases}1 &amp;amp; \text{nếu } \sum_{l} (c_{lj} - v_{l})^{-} + f_{j} &amp;lt; 0 \\\\
0 &amp;amp; \text{ngược lại.} \end{cases}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Cách giải này vừa cung cấp cận dưới \(L(v)\) vừa gợi ý nghiệm gốc heuristic. Để tìm cận dưới tốt nhất, ta có thể chuyển \(\max_{v} L(v)\) thành \(\min_{v} -L(v)\) và giải bằng phương pháp dưới đạo hàm (subgradient method).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>24-03 Giải quy hoạch nguyên</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_03_Solving_integer_programs/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_03_Solving_integer_programs</id>
   <content type="html">&lt;p&gt;Trong tối ưu lồi, chỉ cần thấy \(\nabla f(x^\star) = 0\) (hoặc điều kiện KKT thỏa mãn), bạn có thể lập tức đóng sổ và tuyên bố: &lt;em&gt;“Tôi đã tìm được nghiệm tối ưu toàn cục!”&lt;/em&gt; Nhưng trong quy hoạch nguyên, công cụ vi phân biến mất hoàn toàn — tại một điểm lưới nguyên, ta không thể “lấy đạo hàm” sang điểm lưới bên cạnh để biết liệu phía bên kia ngọn đồi có một nghiệm tốt hơn hay không.&lt;/p&gt;

&lt;p&gt;Vậy làm sao một bộ giải MIP như Gurobi hay HiGHS có thể &lt;strong&gt;chứng minh chắc chắn 100%&lt;/strong&gt; rằng không còn nghiệm nguyên nào tốt hơn nữa mà không phải vét cạn cả \(2^{1000}\) tổ hợp? Câu trả lời là một chiến lược gọng kìm kinh điển: &lt;strong&gt;kẹp nghiệm tối ưu \(z\) giữa hai dãy cận — cận gốc (primal bound) chạy từ trên xuống và cận đối ngẫu (dual bound) chạy từ dưới lên&lt;/strong&gt; — cho đến khi hai gọng kìm khép chặt vào nhau.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-khung-giải-mip-bằng-gọng-kìm-cận&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của khung giải MIP bằng gọng kìm cận&lt;/h2&gt;

&lt;p&gt;Bài học này đặt ra kiến trúc tổng quát mà mọi bộ giải quy hoạch nguyên hiện đại đều tuân theo:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính NP-khó và Lý do không có công thức cục bộ:&lt;/strong&gt; Quy hoạch nguyên 0–1 có thể mã hóa bài toán 3-SAT, nên trong trường hợp xấu nhất không tồn tại thuật toán thời gian đa thức (nếu \(\text{P} \neq \text{NP}\)). Do đó, chứng nhận tối ưu phải mang tính &lt;em&gt;toàn cục&lt;/em&gt; thông qua cận dưới.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cận gốc \(\bar{z}\) (Primal / Upper Bound cho bài toán cực tiểu):&lt;/strong&gt; Bất kỳ nghiệm nguyên khả thi \(x \in X\) nào tìm được (nhờ heuristic, làm tròn thông minh, hay nghiệm nguyên từ cây tìm kiếm) đều cho ngay một cận trên \(\bar{z} = f(x) \ge z^\star\). Cận trên càng giảm nhanh, bộ giải càng cắt tỉa được nhiều nhánh.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Cận đối ngẫu \(\underline{z}\) (Dual / Lower Bound cho bài toán cực tiểu):&lt;/strong&gt; Thu được từ các phép nới lỏng (LP, lồi, Lagrange) hoặc mặt phẳng cắt. Khi khoảng cách tương đối (&lt;em&gt;MIP gap&lt;/em&gt;) $$\frac{\bar{z} - \underline{z}}{&lt;/td&gt;
          &lt;td&gt;\bar{z}&lt;/td&gt;
          &lt;td&gt;}\(đạt\)0\((hoặc nhỏ hơn ngưỡng\)\varepsilon\(, ví dụ\)0.01\%$$), thuật toán dừng với bằng chứng toán học chặt chẽ về chất lượng nghiệm.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-khép-gọng-kìm-cận-gốc--cận-đối-ngẫu-bằng-tay&quot;&gt;Giải thích: Khép gọng kìm cận gốc – cận đối ngẫu bằng tay&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch nguyên cực tiểu hóa:&lt;/p&gt;

\[z^\star = \min_{x_1, x_2 \in \mathbb{Z}_+}\ 5x_1 + 7x_2 \qquad \text{thỏa mãn } 2x_1 + 3x_2 \ge 7.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tìm cận đối ngẫu ban đầu \(\underline{z}_0\) bằng nới lỏng LP:&lt;/strong&gt;
So sánh chi phí trên mỗi đơn vị ràng buộc: biến \(x_1\) tốn \(5/2 = 2.5\) mỗi đơn vị, còn biến \(x_2\) rẻ hơn với \(7/3 \approx 2.333\) mỗi đơn vị.
Do đó nghiệm nới lỏng LP dồn hết vào \(x_2\): \(x_1 = 0,\; x_2 = \frac{7}{3}\), cho cận dưới \(\underline{z}_0 = 7 \cdot \frac{7}{3} = \frac{49}{3} \approx 16.333\).
&lt;em&gt;Mẹo thắt cận tức thì:&lt;/em&gt; Vì hệ số mục tiêu \(5, 7\) và biến \(x_1, x_2\) đều là số nguyên, giá trị tối ưu \(z^\star\) &lt;strong&gt;bắt buộc là số nguyên&lt;/strong&gt;! Vậy ta lập tức làm tròn lên cận dưới: \(\underline{z}_1 = \lceil 16.333 \rceil = 17\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tìm cận gốc ban đầu \(\bar{z}_0\) bằng làm tròn khả thi:&lt;/strong&gt;
Làm tròn nghiệm LP \((0, 2.333)\) lên thành điểm nguyên khả thi \((0, 3)\) (kiểm tra: \(2(0)+3(3)=9 \ge 7\)).
Chi phí là \(\bar{z}_0 = 5(0) + 7(3) = 21\). Lúc này ta biết chắc \(17 \le z^\star \le 21\) (khoảng cận bằng \(4\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Cải thiện nghiệm khả thi để khép kín khoảng cận:&lt;/strong&gt;
Thử tổ hợp nguyên \((x_1, x_2) = (2, 1)\): kiểm tra ràng buộc \(2(2) + 3(1) = 7 \ge 7\) (khả thi!).
Giá trị mục tiêu mới là \(\bar{z}_1 = 5(2) + 7(1) = 17\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chứng nhận tối ưu:&lt;/strong&gt; Lúc này \(\underline{z}_1 = 17 = \bar{z}_1\) (khoảng cận bằng \(0\))! Ta không cần thử thêm bất kỳ điểm nguyên nào khác mà vẫn chứng minh được 100% rằng \((2, 1)\) là nghiệm tối ưu toàn cục!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sau khi mô hình hóa một bài toán dưới dạng quy hoạch nguyên, ta cần các kỹ thuật như nới lỏng (relaxation) và khép khoảng cận để tìm nghiệm. Mục này trình bày độ khó cơ bản của quy hoạch nguyên và khung thuật toán tổng quát để giải nó.&lt;/p&gt;

&lt;h2 id=&quot;độ-khó-của-quy-hoạch-nguyên&quot;&gt;Độ khó của quy hoạch nguyên&lt;/h2&gt;

&lt;p&gt;Giải quy hoạch nguyên khó hơn nhiều so với tối ưu lồi. Quy hoạch nguyên tổng quát thuộc lớp bài toán &lt;a href=&quot;https://en.wikipedia.org/wiki/NP-hardness&quot;&gt;NP-khó&lt;/a&gt;, nên nhìn chung không tồn tại thuật toán thời gian đa thức được biết. Khi bỏ các ràng buộc nguyên để thực hiện nới lỏng lồi (convex relaxation), ta thu được một cận dưới cho giá trị tối ưu, nhưng cách làm này vẫn gặp ba hạn chế chính:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Việc tìm được một nghiệm nguyên khả thi từ nghiệm nới lỏng có thể rất khó.&lt;/li&gt;
  &lt;li&gt;Giá trị tối ưu của bài toán nới lỏng có thể cách xa giá trị tối ưu thực của quy hoạch nguyên.&lt;/li&gt;
  &lt;li&gt;Nghiệm thu được sau khi làm tròn nghiệm nới lỏng có thể không tối ưu (thậm chí không khả thi).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;khung-thuật-toán-giải-quy-hoạch-nguyên&quot;&gt;Khung thuật toán giải quy hoạch nguyên&lt;/h2&gt;

&lt;p&gt;Xét bài toán quy hoạch nguyên với tập khả thi \(X\) (bao gồm các ràng buộc lồi và ràng buộc nguyên):&lt;/p&gt;

&lt;blockquote&gt;
\[z := \min_{x \in X} f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Khác với tối ưu lồi, ta không có điều kiện tối ưu bậc nhất đơn giản để chứng nhận ngay một điểm khả thi \(x^{\star} \in X\) là tối ưu toàn cục. Thay vào đó, các thuật toán giải quy hoạch nguyên hoạt động bằng cách liên tục cập nhật một cận dưới \(\underline{z} \leq z\) và một cận trên \(\bar{z} \geq z\) cho đến khi khoảng cách giữa chúng đủ nhỏ.&lt;/p&gt;

&lt;h3 id=&quot;khung-thuật-toán-chung&quot;&gt;Khung thuật toán chung&lt;/h3&gt;

&lt;p&gt;Xây dựng dãy cận trên không tăng:&lt;/p&gt;
&lt;blockquote&gt;
\[\bar{z}_1 \geq \bar{z}_2 \geq \dotsc \geq \bar{z}_s \geq z\]
&lt;/blockquote&gt;

&lt;p&gt;và dãy cận dưới không giảm:&lt;/p&gt;
&lt;blockquote&gt;
\[\underline{z}_1 \leq \underline{z}_2 \leq \dotsc \leq \underline{z}_t \leq z\]
&lt;/blockquote&gt;

&lt;p&gt;Với sai số cho trước \(\epsilon &amp;gt; 0\), thuật toán dừng khi \(\bar{z}_s - \underline{z}_t \leq \epsilon\), đảm bảo nghiệm tương ứng với \(\bar{z}_s\) cách giá trị tối ưu thực không quá \(\epsilon\).&lt;/p&gt;

&lt;h3 id=&quot;cận-gốc-primal-bounds&quot;&gt;Cận gốc (Primal bounds)&lt;/h3&gt;

&lt;p&gt;Với mọi điểm khả thi \(x \in X\), giá trị hàm mục tiêu \(f(x) \geq z\) lập tức cung cấp một cận trên (cận gốc). Tuy nhiên, trên thực tế việc tìm được các điểm khả thi \(x \in X\) có chất lượng tốt không phải lúc nào cũng đơn giản.&lt;/p&gt;

&lt;h3 id=&quot;cận-đối-ngẫu-dual-bounds&quot;&gt;Cận đối ngẫu (Dual bounds)&lt;/h3&gt;

&lt;p&gt;Cận đối ngẫu (hay cận dưới) thường được tính thông qua các bài toán nới lỏng. Nội dung chi tiết về các phương pháp nới lỏng được trình bày ở mục tiếp theo.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>24-02 Các ví dụ về quy hoạch nguyên</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_02_Example_of_integer_programs/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_02_Example_of_integer_programs</id>
   <content type="html">&lt;p&gt;Sức mạnh thật sự của quy hoạch nguyên hỗn hợp không nằm ở sự cầu kỳ của công thức, mà ở khả năng &lt;strong&gt;dịch những bài toán tưởng như chẳng liên quan gì đến nhau về cùng một ngôn ngữ toán học chung&lt;/strong&gt;. Dù bạn đang xếp hành lý vào chiếc ba-lô, ghép cặp nhân viên với công việc, chọn nơi đặt kho hàng, phân cụm dữ liệu bằng K-medoids hay chọn tập đặc trưng tốt nhất cho hồi quy, tất cả đều quy về cùng một bộ khung MIP.&lt;/p&gt;

&lt;p&gt;Bài học này giống như một cuốn từ điển mẫu (modeling cookbook): đọc kỹ sáu bài toán kinh điển dưới đây sẽ giúp bạn nhận ra ngay các “mẫu câu” ràng buộc quen thuộc khi đối mặt với một bài toán thực tế hoàn toàn mới.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-khuôn-mẫu-mô-hình-hóa-mip-cốt-lõi&quot;&gt;Kiến thức cần nhớ: Bốn khuôn mẫu mô hình hóa MIP cốt lõi&lt;/h2&gt;

&lt;p&gt;Sáu ví dụ trong bài thực chất xoay quanh bốn khuôn mẫu tư duy mô hình hóa quan trọng nhất của vận trù học và thống kê:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Khuôn mẫu Chọn lọc có ngân sách (Knapsack &amp;amp; Best Subset):&lt;/strong&gt; Dùng \(\sum_j x_j \le k\) hoặc \(\sum_j a_j x_j \le b\) để giới hạn số lượng hoặc tổng tài nguyên, kết hợp liên kết $$&lt;/td&gt;
          &lt;td&gt;\beta_j&lt;/td&gt;
          &lt;td&gt;\le M z_j$$ khi muốn gắn biến nhị phân với biến liên tục.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khuôn mẫu Ghép cặp 1–1 (Assignment):&lt;/strong&gt; Ma trận biến \(x_{ij} \in \{0, 1\}\) có tổng mỗi hàng và tổng mỗi cột bằng \(1\). Điểm đặc biệt kỳ diệu là ma trận ràng buộc của bài toán phân công có tính &lt;em&gt;hoàn toàn đơn mô-đun (totally unimodular)&lt;/em&gt;, nên nghiệm nới lỏng LP luôn tự động là số nguyên!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khuôn mẫu Liên kết Mở–Phục vụ (Facility Location &amp;amp; K-medoids):&lt;/strong&gt; Tách quyết định “mở địa điểm/chọn tâm cụm \(j\)” (biến \(y_j\)) khỏi quyết định “gán khách hàng/điểm dữ liệu \(i\) vào \(j\)” (biến \(x_{ij}\)) qua ràng buộc liên kết \(x_{ij} \le y_j\) (dạng chặt, tốt hơn nhiều so với dạng gộp \(\sum_i x_{ij} \le n y_j\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khuôn mẫu Chọn phân vị/ngoại lai (Least Median of Squares):&lt;/strong&gt; Dùng biến nhị phân \(z_i\) để “tắt” phần dư của một tỷ lệ điểm dữ liệu (các điểm ngoại lai) thông qua big-\(M\), biến hàm mục tiêu trung vị phi lồi thành một MILP giải được chính xác.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-bài-toán-cái-túi-01--khi-thuật-toán-tham-lam-thất-bại&quot;&gt;Giải thích: Tính tay bài toán cái túi 0–1 — khi thuật toán tham lam thất bại&lt;/h3&gt;

&lt;p&gt;Xét bài toán cái túi 0–1 với sức chứa tối đa \(b = 6\) kg và 3 món đồ:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Món 1: giá trị \(c_1 = 10\), khối lượng \(a_1 = 3\) (tỷ số \(c_1/a_1 \approx 3.33\)).&lt;/li&gt;
  &lt;li&gt;Món 2: giá trị \(c_2 = 10\), khối lượng \(a_2 = 3\) (tỷ số \(c_2/a_2 \approx 3.33\)).&lt;/li&gt;
  &lt;li&gt;Món 3: giá trị \(c_3 = 14\), khối lượng \(a_3 = 4\) (tỷ số \(c_3/a_3 = 3.50\) — cao nhất!).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cách giải tham lam (Greedy theo tỷ số giá trị/khối lượng):&lt;/strong&gt;
Tham lam chọn món có tỷ số cao nhất trước là Món 3 (\(x_3 = 1\), nặng \(4\) kg, giá trị \(14\)). Dung tích còn lại là \(6 - 4 = 2\) kg — không nhét vừa Món 1 hay Món 2! Tổng giá trị tham lam dừng ở &lt;strong&gt;\(14\)&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán nới lỏng LP (cho phép cắt nhỏ món đồ, \(x_j \in [0, 1]\)):&lt;/strong&gt;
Chọn trọn Món 3 (\(x_3 = 1\), dùng \(4\) kg) cộng thêm \(\frac{2}{3}\) Món 1 (\(x_1 = \frac{2}{3}\), dùng \(2\) kg). Tổng giá trị LP là \(14 + \frac{2}{3}(10) = 20.67\) — đây là &lt;strong&gt;cận trên&lt;/strong&gt; cho mọi nghiệm nguyên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiệm tối ưu quy hoạch nguyên 0–1:&lt;/strong&gt;
Bỏ qua món “hấp dẫn nhất” là Món 3, ta chọn cả Món 1 và Món 2: \(x^\star = (1, 1, 0)\). Tổng khối lượng \(3 + 3 = 6 \le 6\), tổng giá trị đạt &lt;strong&gt;\(20\)&lt;/strong&gt; — vượt xa tham lam (\(14\)) và rất sát cận trên LP (\(20.67\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mục này giới thiệu một số bài toán kinh điển có thể mô hình hóa bằng quy hoạch nguyên và quy hoạch nguyên hỗn hợp.&lt;/p&gt;

&lt;h2 id=&quot;bài-toán-cái-túi-knapsack&quot;&gt;Bài toán cái túi (Knapsack)&lt;/h2&gt;

&lt;p&gt;Bài toán cái túi là một ví dụ kinh điển trong tối ưu tổ hợp: cho một chiếc túi có dung tích tối đa \(b\) và \(n\) đồ vật, mỗi đồ vật thứ \(j\) có giá trị \(c_j\) và kích thước \(a_j\). Mục tiêu là chọn tập đồ vật có tổng giá trị lớn nhất sao cho tổng kích thước không vượt quá \(b\). Dùng biến nhị phân \(x_j \in \{0, 1\}\) biểu thị việc có chọn đồ vật thứ \(j\) hay không, ta có:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{x} &amp;amp;&amp;amp; c^\intercal x \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; a^\intercal x \leq b \\\\
&amp;amp;&amp;amp;&amp;amp;x_{j} \in \{0, 1\}, \quad j = 1, \dotsc , n
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;bài-toán-phân-công-assignment&quot;&gt;Bài toán phân công (Assignment)&lt;/h2&gt;

&lt;p&gt;Giả sử có \(n\) người và \(n\) công việc, mỗi người đảm nhận đúng một công việc và mỗi công việc được giao cho đúng một người. Gọi \(c_{ij}\) là chi phí để người \(i\) thực hiện công việc \(j\). Bài toán phân công cực tiểu hóa tổng chi phí được phát biểu là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;\sum_{i = 1}^{n} \sum_{j = 1}^{n} c_{ij} x_{ij} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;\sum_{i = 1}^{n} x_{ij} = 1, \quad j = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp;\sum_{j = 1}^{n} x_{ij} = 1, \quad i = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp;x_{ij} \in \lbrace 0, 1\rbrace, \quad i = 1, \dotsc, n, \quad j = 1, \dotsc, n
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;bài-toán-đặt-cơ-sở-facility-location&quot;&gt;Bài toán đặt cơ sở (Facility location)&lt;/h2&gt;

&lt;p&gt;Bài toán đặt cơ sở nhằm đồng thời quyết định những kho nào cần mở và phân bổ khách hàng về các kho đó sao cho tổng chi phí cố định và chi phí vận chuyển là nhỏ nhất.&lt;/p&gt;

&lt;p&gt;Giả sử có tập các vị trí kho ứng viên \(N = \lbrace 1, \dotsc, n \rbrace\) và tập khách hàng \(M = \lbrace 1, \dotsc, m \rbrace\). Mỗi kho \(j\) có chi phí mở cố định \(f_{j}\), còn chi phí vận chuyển hàng từ kho \(j\) đến khách hàng \(i\) là \(c_{ij}\). Mô hình quy hoạch nguyên được viết như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y} &amp;amp;&amp;amp; \sum_{j = 1}^{n} f_{j} y_{j} + \sum_{i = 1}^{m} \sum_{j = 1}^{n} c_{ij} x_{ij} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; \sum_{j = 1}^{n} x_{ij} = 1,  \quad i = 1, \dotsc, m \\\\
&amp;amp;&amp;amp;&amp;amp; x_{ij} \leq y_{j},  \quad i = 1, \dotsc, m,  \quad j = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp; x_{ij} \in \lbrace 0, 1\rbrace, \quad i = 1, \dotsc, m, \quad j = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp; y_{j} \in \lbrace 0, 1\rbrace, \quad j = 1, \dotsc, n
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ràng buộc thứ nhất đảm bảo mỗi khách hàng được phục vụ bởi đúng một kho. Ràng buộc thứ hai yêu cầu kho \(j\) phải được mở (\(y_j = 1\)) thì mới có thể giao hàng cho khách hàng \(i\) (\(x_{ij} = 1\)). Hệ ràng buộc \(x_{ij} \leq y_j\) gồm \(mn\) bất đẳng thức, và cũng có thể viết lại ở dạng gộp (aggregated) chỉ còn \(n\) bất đẳng thức:&lt;/p&gt;

&lt;blockquote&gt;
\[\sum_{i = 1}^{m} x_{ij} \leq m y_{j}, \quad j = 1, \dotsc, n\]
&lt;/blockquote&gt;

&lt;p&gt;Khi đó bài toán có dạng tương đương trên miền nguyên:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y} &amp;amp;&amp;amp;\sum_{j = 1}^{n} f_{j} y_{j} + \sum_{i = 1}^{m} \sum_{j = 1}^{n} c_{ij} x_{ij} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;\sum_{j = 1}^{n} x_{ij} = 1,  \quad i = 1, \dotsc, m \\\\
&amp;amp;&amp;amp;&amp;amp; \sum_{i = 1}^{m} x_{ij} \leq m y_{j}, \quad j = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp; x_{ij} \in \lbrace 0, 1\rbrace, \quad i = 1, \dotsc, m, \quad j = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp; y_{j} \in \lbrace 0, 1\rbrace, \quad j = 1, \dotsc, n
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;phân-cụm-k-means-và-k-medoids&quot;&gt;Phân cụm K-means và K-medoids&lt;/h2&gt;

&lt;p&gt;Phân cụm là quá trình phân hoạch tập dữ liệu \(\{1, \dotsc, n\}\) thành \(K\) nhóm tương đồng \(S_{1} \cup \dotsc \cup S_{K} = \lbrace 1, \dotsc, n \rbrace\). Thuật toán K-means cực tiểu hóa tổng bình phương khoảng cách từ các điểm dữ liệu tới tâm cụm (centroid):&lt;/p&gt;

\[\sum_{i = 1}^{K} \sum_{j \in S_{i}} \| x^{(j)} - \mu^{(i)} \|^{2}\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;trong đó $$\mu^{(i)} := \frac{1}{&lt;/td&gt;
      &lt;td&gt;S_{i}&lt;/td&gt;
      &lt;td&gt;} \sum_{j \in S_{i}} x^{(j)}\(là trung bình cộng (tâm) của cụm\)i$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Một phương pháp ít nhạy cảm với điểm ngoại lai hơn là phân cụm K-medoids: thay vì lấy trung bình cộng làm tâm cụm, K-medoids yêu cầu tâm cụm \(y^{(i)}\) phải là một điểm dữ liệu thực tế trong tập dữ liệu sao cho tổng khoảng cách là nhỏ nhất:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\sum_{i = 1}^{K} \sum_{j \in S_{i}} \| x^{(j)} - y^{(i)} \|^{2}\)
\(\text{với } y^{(i)} \in \lbrace x^{(j)} : j \in S_{i} \rbrace\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Bài toán K-medoids có thể phát biểu trực tiếp dưới dạng quy hoạch nguyên. Đặt \(d_{ij} = \| x^{(i)} - x^{(j)} \|^2\) và định nghĩa hai nhóm biến nhị phân:&lt;/p&gt;

\[\begin{align}
&amp;amp;w_{i} =\begin{cases}1 &amp;amp;&amp;amp; \text{nếu chọn } x^{(i)} \text{ làm tâm cụm} \\\\
0 &amp;amp;&amp;amp; \text{ngược lại,} \end{cases}\\\\
&amp;amp;z_{ji} =\begin{cases}1 &amp;amp;&amp;amp; \text{nếu } x^{(j)} \text{ được gán vào cụm có tâm } x^{(i)} \\\\
0 &amp;amp;&amp;amp; \text{ngược lại.} \end{cases}
\end{align}\]

&lt;p&gt;Khi đó bài toán tối ưu K-medoids trở thành:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{w, z} &amp;amp;&amp;amp; \sum_{i = 1}^{n} \sum_{j = 1}^{n} d_{ij} z_{ji} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; z_{ji} \leq w_{i}, \quad j, i = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp; \sum_{i = 1}^{n} z_{ji} = 1, \quad j = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp; \sum_{i = 1}^{n} w_{i} = K \\\\
&amp;amp;&amp;amp;&amp;amp; w_{i} \in \lbrace 0, 1 \rbrace, \quad i = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp; z_{ji} \in \lbrace 0, 1 \rbrace, \quad j, i = 1, \dotsc, n
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ràng buộc đầu tiên đảm bảo điểm \(x^{(j)}\) chỉ có thể thuộc cụm có tâm \(x^{(i)}\) nếu \(x^{(i)}\) được chọn làm tâm; ràng buộc thứ hai đảm bảo mỗi điểm thuộc đúng một cụm; ràng buộc thứ ba ấn định đúng \(K\) tâm cụm.&lt;/p&gt;

&lt;h2 id=&quot;chọn-tập-con-tốt-nhất-best-subset-selection&quot;&gt;Chọn tập con tốt nhất (Best subset selection)&lt;/h2&gt;

&lt;p&gt;Cho ma trận đặc trưng \(X = [x^{1} \quad \dotsc \quad x^{p}] \in \mathbb{R}^{n \times p}\) và vector phản hồi \(y \in \mathbb{R}^{n}\), bài toán chọn tập con tốt nhất có dạng:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\min_{\beta} &amp;amp;&amp;amp;\frac{1}{2} \| y - X\beta \|^{2} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;\| \beta \|_{0} \leq k
\end{align}\)
\(\begin{align}
\text{trong đó } \| \beta \|_{0} := \text{ số phần tử khác không của } \beta.
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vì ràng buộc \(\|\beta\|_0 \leq k\) không lồi, ta có thể biểu diễn lại bài toán thành quy hoạch nguyên hỗn hợp bằng kỹ thuật hằng số lớn (big-M):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{\beta, z} &amp;amp;&amp;amp; \frac{1}{2} \| y - X\beta \|^{2} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; | \beta_{i} | \leq Mz_{i}, \quad i = 1, \dotsc, p \\\\
&amp;amp;&amp;amp;&amp;amp;z_{i} \in \lbrace 0, 1 \rbrace, \quad i = 1, \dotsc, p \\\\
&amp;amp;&amp;amp;&amp;amp;\sum_{i = 1}^{p} z_{i} \leq k
\end{align}\]
&lt;/blockquote&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;ở đây \(M\) là hằng số đủ lớn sao cho $$&lt;/td&gt;
      &lt;td&gt;\beta_i&lt;/td&gt;
      &lt;td&gt;\leq M$$ tại nghiệm tối ưu.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;hồi-quy-bình-phương-trung-vị-nhỏ-nhất-least-median-of-squares&quot;&gt;Hồi quy bình phương trung vị nhỏ nhất (Least median of squares)&lt;/h2&gt;

&lt;p&gt;Cho \(X = [x^{1} \quad \dotsc \quad x^{p}] \in \mathbb{R}^{n \times p}\), \(y \in \mathbb{R}^{n}\) và \(\beta \in \mathbb{R}^{p}\), đặt vector phần dư \(r := y - X\beta\). Bài toán hồi quy bình phương trung vị nhỏ nhất được định nghĩa là:&lt;/p&gt;

&lt;blockquote&gt;
\[\beta_{LMS} := \arg\min_{\beta} (\text{median} | r_{i} | ).\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>24-01 Định nghĩa</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_01_Definition/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter24/24_01_Definition</id>
   <content type="html">&lt;p&gt;Trong tối ưu hóa, chỉ cần thêm một dòng ngắn ngủi \(x_j \in \mathbb{Z}\) là bản chất hình học của bài toán lập tức đổi khác: tập khả thi không còn là một khối liền mạch mà trở thành tập các điểm lưới rời rạc nằm bên trong tập lồi \(C\). Đặc biệt hơn nữa, khi ràng buộc thu hẹp về \(x_j \in \{0, 1\}\), biến số không còn mang nghĩa “số lượng” mà mang nghĩa &lt;strong&gt;quyết định logic&lt;/strong&gt; — bật hay tắt, chọn hay bỏ, mở hay đóng.&lt;/p&gt;

&lt;p&gt;Bài học này định nghĩa chính xác quy hoạch nguyên thuần túy (pure IP), quy hoạch nguyên hỗn hợp (MIP) và giải thích vì sao lớp bài toán chỉ chứa biến nhị phân (0–1 IP) lại có sức biểu diễn phổ quát đến mức có thể mã hóa hầu hết các bài toán tối ưu tổ hợp kinh điển.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-định-nghĩa-mip&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của định nghĩa MIP&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch24_integer_programming_bnb.svg&quot; alt=&quot;Quy hoạch Nguyên (IP) và Chiến lược Nhánh Cận&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Để phân loại chính xác mọi mô hình MIP bạn sẽ gặp trong thực tế, hãy nắm rõ ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân loại theo tập chỉ số nguyên \(J\):&lt;/strong&gt; Nếu \(J = \{1, \dots, n\}\) (mọi biến đều nguyên), ta có &lt;em&gt;quy hoạch nguyên thuần túy (pure IP)&lt;/em&gt;; nếu \(J\) là tập con thực sự (vừa có biến liên tục như lưu lượng/công suất, vừa có biến nguyên như số xe/trạng thái bật-tắt), ta có &lt;em&gt;quy hoạch nguyên hỗn hợp (MIP)&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân loại theo cấu trúc hàm mục tiêu và tập \(C\):&lt;/strong&gt; Khi \(f\) tuyến tính và \(C\) là đa diện \(\{x : Ax \le b\}\), ta có &lt;strong&gt;MILP&lt;/strong&gt; (Mixed Integer Linear Programming — lớp được hỗ trợ mạnh nhất bởi các bộ giải như Gurobi, CPLEX, HiGHS). Khi \(f\) hoặc \(C\) phi tuyến lồi, ta bước sang &lt;strong&gt;MINLP&lt;/strong&gt; (Mixed Integer Nonlinear Programming).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kỹ thuật liên kết biến liên tục và biến nhị phân (Indicator / Big-\(M\)):&lt;/strong&gt; Biến nhị phân \(y \in \{0, 1\}\) có thể “khóa” hoặc “mở” một biến liên tục \(x \ge 0\) thông qua bất đẳng thức \(x \le M y\): khi \(y = 0\) thì \(x\) buộc phải bằng \(0\); khi \(y = 1\) thì \(x\) tự do nhận giá trị lên tới \(M\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-mô-hình-hóa-bài-toán-chi-phí-cố-định-fixed-charge-bằng-biến-hỗn-hợp&quot;&gt;Giải thích: Mô hình hóa bài toán chi phí cố định (Fixed-Charge) bằng biến hỗn hợp&lt;/h3&gt;

&lt;p&gt;Giả sử một xưởng cần sản xuất ít nhất \(6\) tấn hàng (nhưng công suất tối đa là \(10\) tấn). Để mở dây chuyền, xưởng tốn chi phí khởi động cố định \(50\) triệu đồng, cộng thêm \(4\) triệu đồng cho mỗi tấn sản phẩm. Ta dùng 1 biến liên tục \(x \in \mathbb{R}_+\) (số tấn sản xuất) và 1 biến nhị phân \(y \in \{0, 1\}\) (mở hay không mở dây chuyền):&lt;/p&gt;

\[\min_{x, y}\ 50y + 4x \qquad \text{thỏa mãn } x \le 10y,\quad x \ge 6,\quad x \ge 0,\quad y \in \{0, 1\}.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra hai trạng thái của biến nhị phân \(y\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu \(y = 0\) (không mở xưởng): ràng buộc \(x \le 10(0) = 0\) mâu thuẫn với \(x \ge 6\) — &lt;strong&gt;vô nghiệm&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Nếu \(y = 1\) (mở xưởng): ràng buộc trở thành \(6 \le x \le 10\). Để cực tiểu hóa \(50(1) + 4x\), ta chọn \(x^\star = 6\), tổng chi phí đúng là \(50 + 24 = 74\) triệu.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử bỏ ràng buộc nguyên (cho phép \(y \in [0, 1]\) liên tục):&lt;/strong&gt;
Khi đó bài toán nới lỏng sẽ “lách luật” bằng cách mở đúng \(y = \frac{6}{10} = 0.6\) cái xưởng để vừa đủ sản xuất \(x = 6\) tấn! Chi phí nới lỏng là \(50(0.6) + 4(6) = 30 + 24 = 54\) triệu — nhỏ hơn thực tế tới \(20\) triệu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trực giác quan trọng:&lt;/strong&gt; Khoảng chênh \(74 - 54 = 20\) (gọi là &lt;em&gt;integrality gap&lt;/em&gt;) xuất hiện trực tiếp từ việc nới lỏng công tắc nhị phân \(y\). Chọn hằng số \(M\) càng nhỏ và sát công suất thực (ở đây \(M = 10\) thay vì \(M = 1000\)) thì nới lỏng càng chặt và bộ giải càng nhanh!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mục này giới thiệu các khái niệm nền tảng của quy hoạch số nguyên hỗn hợp và mối liên hệ với tối ưu tổ hợp.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa-bài-toán&quot;&gt;Định nghĩa bài toán&lt;/h2&gt;

&lt;p&gt;Khi một số biến trong bài toán tối ưu bị ràng buộc phải nhận giá trị nguyên, bài toán được gọi là quy hoạch nguyên hỗn hợp (hay gọn hơn là quy hoạch nguyên — integer program):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp; f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; x \in C \\\\
&amp;amp;&amp;amp;&amp;amp;x_{j} \in \mathbb{Z}, \quad j \in J
\end{align}\)
\(\begin{align}
\text{trong đó } f: \mathbb{R}^{n} \rightarrow \mathbb{R}, \quad C \subseteq \mathbb{R}^{n} \quad \text{và} \quad J \subseteq \{1, \dotsc, n\}. 
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nếu mọi biến đều bị ràng buộc là số nguyên, tức:&lt;/p&gt;
&lt;blockquote&gt;
\[J = \{ 1, \dotsc, n \}\]
&lt;/blockquote&gt;

&lt;p&gt;thì bài toán được gọi là quy hoạch nguyên thuần túy (pure integer program). Trong phần này, ta giả sử cả hàm mục tiêu \(f\) lẫn tập ràng buộc liên tục \(C\) đều lồi.&lt;/p&gt;

&lt;h2 id=&quot;biến-nhị-phân&quot;&gt;Biến nhị phân&lt;/h2&gt;

&lt;p&gt;Một lớp ứng dụng rất phổ biến của quy hoạch nguyên là các bài toán ra quyết định có/không hoặc biểu diễn điều kiện logic. Khi đó, ta dùng các biến nhị phân chỉ nhận giá trị \(0\) hoặc \(1\) để mô hình hóa các lựa chọn rời rạc.&lt;/p&gt;

&lt;p&gt;Các bài toán tối ưu tổ hợp (combinatorial optimization) gắn chặt với quy hoạch nguyên nhị phân. Một bài toán tối ưu tổ hợp thường được định nghĩa bởi bộ ba \((N, \mathcal{F}, c)\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(N\) là tập nền hữu hạn.&lt;/li&gt;
  &lt;li&gt;\(\mathcal{F} \subseteq 2^{N}\) là họ các tập con khả thi.&lt;/li&gt;
  &lt;li&gt;\(c \in \mathbb{R}^{N}\) là vector chi phí gắn với từng phần tử của \(N\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mục tiêu của bài toán là tìm tập con khả thi có tổng chi phí nhỏ nhất:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{S \in \mathcal{F}} \sum_{i \in S} c_{i}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nhiều bài toán tối ưu tổ hợp kinh điển có thể chuyển trực tiếp về bài toán quy hoạch nguyên nhị phân.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>23 Phương Pháp Coordinate Descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_Coordinate_Descent/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_Coordinate_Descent</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng bạn cần chỉnh một hệ thống âm thanh có hàng nghìn nút xoay để âm thanh trong trẻo nhất. Thay vì cố gắng xoay đồng thời cả nghìn nút cùng một lúc (như gradient descent toàn phần), bạn chọn cách cực kỳ giản dị: &lt;strong&gt;giữ nguyên 999 nút kia, chỉ vặn đúng 1 nút sao cho âm thanh hay nhất&lt;/strong&gt;, rồi lần lượt chuyển sang nút tiếp theo.&lt;/p&gt;

&lt;p&gt;Ý tưởng tưởng chừng quá ngây thơ ấy — &lt;strong&gt;phương pháp hạ theo tọa độ (Coordinate Descent)&lt;/strong&gt; — hóa ra lại là một trong những thuật toán nhanh nhất và bền bỉ nhất của thống kê hiện đại. Khi hàm mục tiêu có cấu trúc tách biệt thuận lợi (như hồi quy Lasso, Elastic Net, hay bài toán đối ngẫu SVM), mỗi bước xoay một nút có nghiệm dạng đóng tính trong tích tắc, giúp hạ theo tọa độ đánh bại cả những thuật toán bậc nhất nổi tiếng như proximal gradient hay Nesterov acceleration.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-hạ-theo-tọa-độ&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của hạ theo tọa độ&lt;/h2&gt;

&lt;p&gt;Chương 23 sẽ dẫn bạn đi từ câu hỏi lý thuyết căn bản (“khi nào tối ưu từng trục suy ra tối ưu toàn cục?”) đến các bộ giải công nghiệp hàng triệu biến thông qua bốn trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Điều kiện tối ưu và Tính tách biệt (Separability — Định lý Tseng):&lt;/strong&gt; Với hàm lồi khả vi, tối ưu theo mọi trục luôn tương đương tối ưu toàn cục. Nhưng với hàm không trơn, điều này chỉ đúng khi phần không trơn &lt;em&gt;tách được theo từng tọa độ&lt;/em&gt; (như chuẩn \(\ell_1\): $$\sum_i&lt;/td&gt;
          &lt;td&gt;\beta_i&lt;/td&gt;
          &lt;td&gt;$$), nếu không thuật toán có thể bị kẹt vĩnh viễn tại một góc nhọn.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép cập nhật dạng đóng và Bảo trì phần dư (Closed-Form Updates &amp;amp; Residual Tracking):&lt;/strong&gt; Sức mạnh tốc độ của Coordinate Descent đến từ việc không tính lại toàn bộ tích ma trận-vector \(X\beta\) ở mỗi bước; chỉ cần cập nhật phần dư \(r \leftarrow r - (\beta_i^{\text{new}} - \beta_i^{\text{old}}) X_i\) trong thời gian \(O(n)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khởi động nóng dọc đường chính quy hóa (Pathwise Warm Starts):&lt;/strong&gt; Trong thống kê, ta hiếm khi chỉ giải Lasso cho một mức \(\lambda\) duy nhất. Bằng cách giải từ \(\lambda_{\max}\) (nơi mọi hệ số đều bằng 0) giảm dần xuống, nghiệm bước trước gần như đã trùng với nghiệm bước sau.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược chọn tọa độ và Tập hoạt động (Cyclic, Randomized &amp;amp; Active Sets):&lt;/strong&gt; Ngoài duyệt tuần hoàn theo thứ tự \(1, 2, \dots, p\), các bộ giải hiện đại kết hợp chọn ngẫu nhiên, quy tắc Gauss–Southwell, và tập hoạt động để chỉ tập trung tính toán trên một nhúm biến khác 0.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-2-chu-trình-coordinate-descent-trên-hàm-bậc-hai-2-biến&quot;&gt;Giải thích: Tính tay 2 chu trình Coordinate Descent trên hàm bậc hai 2 biến&lt;/h3&gt;

&lt;p&gt;Hãy quan sát cách Coordinate Descent trượt dần xuống đáy của một thung lũng elip nghiêng: cực tiểu hóa \(f(x_1, x_2) = x_1^2 + 2x_2^2 + 2x_1 x_2 - 6x_1 - 8x_2\), bắt đầu từ \(x^{(0)} = (0, 0)\) (giá trị ban đầu \(f(0, 0) = 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Rút công thức cập nhật dạng đóng cho từng trục:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giữ cố định \(x_2\), đặt \(\frac{\partial f}{\partial x_1} = 2x_1 + 2x_2 - 6 = 0 \Rightarrow x_1 \leftarrow 3 - x_2\).&lt;/li&gt;
      &lt;li&gt;Giữ cố định \(x_1\), đặt \(\frac{\partial f}{\partial x_2} = 4x_2 + 2x_1 - 8 = 0 \Rightarrow x_2 \leftarrow 2 - 0.5 x_1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chu trình 1 (từ \((0, 0)\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Cập nhật \(x_1\): \(x_1^{(1)} = 3 - 0 = 3\). Điểm tạm là \((3, 0)\), giá trị \(f(3, 0) = 9 - 18 = -9\).&lt;/li&gt;
      &lt;li&gt;Cập nhật \(x_2\) (dùng ngay \(x_1^{(1)} = 3\) vừa tính!): \(x_2^{(1)} = 2 - 0.5(3) = 0.5\). Điểm sau chu trình 1 là \((3, 0.5)\), giá trị \(f(3, 0.5) = 9 + 0.5 + 3 - 18 - 4 = -9.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chu trình 2 (từ \((3, 0.5)\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Cập nhật \(x_1\): \(x_1^{(2)} = 3 - 0.5 = 2.5\).&lt;/li&gt;
      &lt;li&gt;Cập nhật \(x_2\): \(x_2^{(2)} = 2 - 0.5(2.5) = 0.75\). Giá trị \(f(2.5, 0.75) = 6.25 + 1.125 + 3.75 - 15 - 6 = -9.875\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối chiếu với nghiệm chính xác:&lt;/strong&gt;
Giải hệ \(\nabla f = 0\) ta được \(x^\star = (2, 1)\) với \(f(2, 1) = -10\). Chỉ sau 2 chu trình đơn giản không hề cần chọn kích thước bước (learning rate!), sai số đã giảm từ \(10\) xuống còn \(0.125\) — giảm tới \(80\) lần!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Phương pháp hạ theo tọa độ (coordinate descent) là một thuật toán tối ưu lặp, cập nhật biến lần lượt dọc theo từng trục tọa độ nhằm tìm cực tiểu của hàm mục tiêu. Tại mỗi vòng lặp, dựa trên một quy tắc chọn tọa độ nhất định, thuật toán chọn một tọa độ (hoặc một khối tọa độ) rồi cực tiểu hóa hàm mục tiêu theo hướng đó (chính xác hoặc xấp xỉ) trong khi giữ cố định tất cả các tọa độ còn lại. Phương pháp này áp dụng được cho cả các bài toán có gradient lẫn không dùng gradient, và có thể kết hợp với tìm kiếm đường thẳng (line search) để chọn kích thước bước phù hợp cho từng tọa độ [16].&lt;/p&gt;

&lt;p&gt;Coordinate descent có cấu trúc đơn giản, dễ cài đặt và đạt hiệu năng tính toán cao khi được triển khai cẩn thận trên các lớp bài toán phù hợp.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ ứng dụng:&lt;/strong&gt; hồi quy Lasso, Lasso cho mô hình tuyến tính tổng quát (GLM, kết hợp proximal Newton), SVM, group lasso, graphical lasso (áp dụng cho bài toán đối ngẫu), mô hình cộng tính (additive modeling), hoàn thiện ma trận (matrix completion) và hồi quy với các hàm phạt không lồi.&lt;/p&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo-và-đọc-thêm&quot;&gt;Tài liệu tham khảo và đọc thêm&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Các nghiên cứu nền tảng về coordinate descent trong tối ưu hóa:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;D. Bertsekas and J. Tsitsiklis (1989), “Parallel and distributed computation: numerical methods”&lt;/li&gt;
  &lt;li&gt;Z. Luo and P. Tseng (1992), “On the convergence of the coordinate descent method for convex differentiable minimization”&lt;/li&gt;
  &lt;li&gt;J. Ortega and W. Rheinboldt (1970), “Iterative solution of nonlinear equations in several variables”&lt;/li&gt;
  &lt;li&gt;P. Tseng (2001), “Convergence of a block coordinate descent method for nondifferentiable minimization”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các tài liệu nền tảng về coordinate descent trong thống kê và học máy:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;I. Daubechies and M. Defrise and C. De Mol (2004), “An iterative thresholding algorithm for linear inverse problems with a sparsity constraint”&lt;/li&gt;
  &lt;li&gt;J. Friedman and T. Hastie and H. Hoefling and R. Tibshirani (2007), “Pathwise coordinate optimization”&lt;/li&gt;
  &lt;li&gt;W. Fu (1998), “Penalized regressions: the bridge versus the lasso”&lt;/li&gt;
  &lt;li&gt;T. Wu and K. Lange (2008), “Coordinate descent algorithms for lasso penalized regression”&lt;/li&gt;
  &lt;li&gt;A. van der Kooij (2007), “Prediction accuracy and stability of regression with optimal scaling transformations”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các ứng dụng tiêu biểu của coordinate descent:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;O. Banerjee and L. Ghaoui and A. d’Aspremont (2007), “Model selection through sparse maximum likelihood estimation”&lt;/li&gt;
  &lt;li&gt;J. Friedman and T. Hastie and R. Tibshirani (2007), “Sparse inverse covariance estimation with the graphical lasso”&lt;/li&gt;
  &lt;li&gt;J. Friedman and T. Hastie and R. Tibshirani (2009), “Regularization paths for generalized linear models via coordinate descent”&lt;/li&gt;
  &lt;li&gt;C.J. Hsieh and K.W. Chang and C.J. Lin and S. Keerthi and S. Sundararajan (2008), “A dual coordinate descent method for large-scale linear SVM”&lt;/li&gt;
  &lt;li&gt;R. Mazumder and J. Friedman and T. Hastie (2011), “SparseNet: coordinate descent with non-convex penalties”&lt;/li&gt;
  &lt;li&gt;J. Platt (1998), “Sequential minimal optimization: a fast algorithm for training support vector machines”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lý thuyết gần đây cho coordinate descent:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A. Beck and L. Tetruashvili (2013), “On the convergence of block coordinate descent type methods”&lt;/li&gt;
  &lt;li&gt;Y. Nesterov (2010), “Efficiency of coordinate descent methods on huge-scale optimization problems”&lt;/li&gt;
  &lt;li&gt;J. Nutini, M. Schmidt, I. Laradji, M. Friedlander, H. Koepke (2015), “Coordinate descent converges faster with the Gauss-Southwell rule than random selection”&lt;/li&gt;
  &lt;li&gt;A. Ramdas (2014), “Rows vs columns for linear systems of equations—randomized Kaczmarz or coordinate descent?”&lt;/li&gt;
  &lt;li&gt;P. Richtarik and M. Takac (2011), “Iteration complexity of randomized block-coordinate descent methods for minimizing a composite function”&lt;/li&gt;
  &lt;li&gt;A. Saha and A. Tewari (2013), “On the nonasymptotic convergence of cyclic coordinate descent methods”&lt;/li&gt;
  &lt;li&gt;S. Wright (2015), “Coordinate descent algorithms”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các quy tắc sàng lọc (screening) và tài liệu về graphical lasso:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;L. El Ghaoui and V. Viallon and T. Rabbani (2010), “Safe feature elimination in sparse supervised learning”&lt;/li&gt;
  &lt;li&gt;R. Tibshirani, J. Bien, J. Friedman, T. Hastie, N. Simon, J. Taylor, and R. J. Tibshirani (2011), “Strong rules for discarding predictors in lasso-type problems”&lt;/li&gt;
  &lt;li&gt;R. Mazumder and T. Hastie (2011), “The graphical lasso: new insights and alternatives”&lt;/li&gt;
  &lt;li&gt;R. Mazumder and T. Hastie (2011), “Exact covariance thresholding into connected components for large-scale graphical lasso”&lt;/li&gt;
  &lt;li&gt;J. Wang, P. Wonka, and J. Ye (2015), “Lasso screening rules via dual polytope projection”&lt;/li&gt;
  &lt;li&gt;D. Witten and J. Friedman and N. Simon (2011), “New insights and faster computations for the graphical lasso”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phân tích hội tụ:&lt;/strong&gt;&lt;br /&gt;
Dưới đây là tóm lược các hướng nghiên cứu chính về hội tụ của coordinate descent:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hội tụ của cực tiểu hóa từng tọa độ khi giải hệ phương trình tuyến tính (phương pháp Gauss-Seidel) là một kết quả cổ điển; xem Golub và van Loan (1996) hoặc Ramdas (2014) với góc nhìn hiện đại về coordinate descent ngẫu nhiên.&lt;/li&gt;
  &lt;li&gt;Nesterov (2010) phân tích coordinate descent ngẫu nhiên trên hàm trơn và chứng minh tốc độ hội tụ \(O(1/\varepsilon)\) dưới điều kiện gradient Lipschitz, cùng tốc độ \(O(\log(1/\varepsilon))\) khi hàm lồi mạnh.&lt;/li&gt;
  &lt;li&gt;Richtarik và Takac (2011) mở rộng và đơn giản hóa các kết quả này cho bài toán tổng của hàm trơn và hàm tách được, trong đó mỗi bước tọa độ áp dụng một toán tử proximal.&lt;/li&gt;
  &lt;li&gt;Saha và Tewari (2013) xét bài toán chính quy hóa \(l_1\) dạng \(g(\beta) + \lambda\|\beta\|_1\) với \(g\) trơn, nghiên cứu cả hạ theo tọa độ tuần hoàn lẫn cực tiểu hóa theo tọa độ tuần hoàn; dưới một số điều kiện đặc thù trên \(g\), họ chỉ ra hai phương pháp này đạt tiến triển theo vòng lặp tốt hơn proximal gradient descent.&lt;/li&gt;
  &lt;li&gt;Beck và Tetruashvili (2013) nghiên cứu coordinate descent tuần hoàn cho hàm trơn tổng quát, chứng minh tốc độ \(O(1/\varepsilon)\) dưới điều kiện gradient Lipschitz và \(O(\log(1/\varepsilon))\) khi hàm lồi mạnh, đồng thời mở rộng cho bài toán có ràng buộc với phép chiếu.&lt;/li&gt;
  &lt;li&gt;Nutini và cộng sự (2015) phân tích coordinate descent tham lam (quy tắc Gauss-Southwell) và chỉ ra phương pháp này hội tụ nhanh hơn chọn tọa độ ngẫu nhiên trên một số lớp bài toán.&lt;/li&gt;
  &lt;li&gt;Wright (2015) trình bày cái nhìn thống nhất và tổng quan hệ thống về các thuật toán coordinate descent, bao gồm cả các biến thể song song và bất đồng bộ.&lt;/li&gt;
  &lt;li&gt;Lý thuyết tổng quát vẫn còn một số câu hỏi mở (chẳng hạn sự tương đương giữa chiến lược giảm dần theo gradient từng tọa độ và chiến lược cực tiểu hóa chính xác từng tọa độ).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ứng-dụng-giai-đoạn-20222026-tùy-chọn&quot;&gt;Ứng dụng giai đoạn 2022–2026 (tùy chọn)&lt;/h2&gt;

&lt;p&gt;Hạ theo tọa độ dọc đường chính quy hóa (pathwise coordinate descent) vẫn là nền tảng cốt lõi để &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sklearn.linear_model.lasso_path&lt;/code&gt; ước lượng các mô hình GLM thưa. Bài báo JSS năm 2023 mở rộng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; cho &lt;em&gt;mọi&lt;/em&gt; họ GLM; thư viện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt; (NeurIPS 2022) kết hợp tập hoạt động (working set) và các hàm phạt không lồi ở quy mô hàng triệu đặc trưng; còn hạ theo tọa độ đối ngẫu trong LIBLINEAR vẫn là bộ giải chuẩn cho SVM tuyến tính. Bạn có thể đọc tiếp tại &lt;a href=&quot;/contents/vi/chapter23/23_05_modern_applications/&quot;&gt;23-05 Ứng dụng hiện đại của hạ theo tọa độ&lt;/a&gt; sau khi hoàn thành các ví dụ Lasso và pathwise.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>23-04 Ví dụ: Pathwise coordinate descent cho lasso</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_04_Example_pathwise_coordinate/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_04_Example_pathwise_coordinate</id>
   <content type="html">&lt;p&gt;Trong thực hành khoa học dữ liệu, hiếm khi nào ta biết trước giá trị \(\lambda\) tối ưu cho hồi quy Lasso; thông thường ta phải thử cả một lưới \(50\) đến \(100\) giá trị \(\lambda\) để chọn bằng kiểm định chéo (cross-validation). Nếu giải độc lập 100 bài toán từ con số 0, thời gian tính toán sẽ nhân lên 100 lần.&lt;/p&gt;

&lt;p&gt;Friedman, Hastie, Hoefling và Tibshirani (2007, 2009) đã nghĩ ra một chiến lược vừa thông minh vừa đẹp mắt gọi là &lt;strong&gt;hạ theo tọa độ dọc đường chính quy hóa (Pathwise Coordinate Descent)&lt;/strong&gt; — trái tim của thư viện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; lừng danh. Thay vì giải lẻ tẻ, họ bắt đầu từ mức phạt lớn nhất \(\lambda_{\max}\) nơi nghiệm bằng \(0\) hoàn toàn, rồi giảm dần \(\lambda\) từng nấc nhỏ, dùng nghiệm trước làm điểm khởi tạo nóng (&lt;em&gt;warm start&lt;/em&gt;) và chỉ chạy vòng lặp trên tập các biến thực sự hoạt động (&lt;em&gt;active set&lt;/em&gt;).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-chiến-lược-pathwise--active-set&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của chiến lược Pathwise + Active Set&lt;/h2&gt;

&lt;p&gt;Để hiểu vì sao giải &lt;strong&gt;cả 100 giá trị \(\lambda\)&lt;/strong&gt; theo đường chính quy hóa lại có thể nhanh hơn giải &lt;strong&gt;một giá trị \(\lambda\) nhỏ duy nhất&lt;/strong&gt; từ điểm khởi tạo 0, hãy nắm ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Ngưỡng triệt tiêu \(\lambda_{\max}\) từ điều kiện KKT:&lt;/strong&gt; Từ điều kiện tối ưu \(X_j^T(y - X\beta) = \lambda v_j\) với $$&lt;/td&gt;
          &lt;td&gt;v_j&lt;/td&gt;
          &lt;td&gt;\le 1\(, nghiệm\)\beta = 0\(là tối ưu khi và chỉ khi\)\lambda \ge \max_{1 \le j \le p}&lt;/td&gt;
          &lt;td&gt;X_j^T y&lt;/td&gt;
          &lt;td&gt;$$. Đây là điểm neo khởi đầu hoàn hảo cho toàn bộ đường nghiệm, không cần đoán mò.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khởi động nóng (Warm Starts) trên lưới logarit:&lt;/strong&gt; Đường nghiệm \(\beta^\star(\lambda)\) là một hàm liên tục (thực tế là tuyến tính từng khúc) theo \(\lambda\). Khi giảm từ \(\lambda_k\) sang \(\lambda_{k+1}\) đủ gần nhau, \(\beta^\star(\lambda_k)\) đã nằm rất sát \(\beta^\star(\lambda_{k+1})\), giúp vòng lặp hội tụ chỉ sau vài lượt quét.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Tập hoạt động (Active Set) và Kiểm tra KKT:&lt;/strong&gt; Ở vùng \(\lambda\) lớn đến trung bình, hầu hết tọa độ đều bằng \(0\). Thuật toán chỉ lặp đi lặp lại trên tập nhỏ các tọa độ khác \(0\) cho đến khi hội tụ, sau đó mới quét 1 lượt duy nhất qua các tọa độ ngoài tập hoạt động để kiểm tra điều kiện KKT $$&lt;/td&gt;
          &lt;td&gt;X_j^T(y - X\beta)&lt;/td&gt;
          &lt;td&gt;\le \lambda$$. Nếu không tọa độ nào vi phạm, ta chắc chắn 100% đã tìm đúng nghiệm toàn cục!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-2-nấc-của-pathwise-coordinate-descent--kiểm-tra-kkt&quot;&gt;Giải thích: Tính tay 2 nấc của Pathwise Coordinate Descent + kiểm tra KKT&lt;/h3&gt;

&lt;p&gt;Xét bài toán Lasso 2 đặc trưng với ma trận thiết kế và nhãn:&lt;/p&gt;

\[X = \begin{pmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{pmatrix}, \qquad y = \begin{pmatrix} 4 \\ 2 \\ 0 \end{pmatrix}, \qquad \|X_1\|_2^2 = 2,\; \|X_2\|_2^2 = 2.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 0 — Tìm \(\lambda_{\max}\):&lt;/strong&gt;
Tính tương quan ban đầu với \(y\):
\(|X_1^T y| = |1(4) + 1(2) + 0(0)| = 6, \qquad |X_2^T y| = |0(4) + 1(2) + 1(0)| = 2.\)
Vậy \(\lambda_{\max} = \max(6, 2) = 6\). Tại \(\lambda_1 = 6\), nghiệm chính xác là \(\beta^\star(6) = (0, 0)\) với tập hoạt động \(\mathcal{A} = \emptyset\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Hạ xuống \(\lambda_2 = 4\) với khởi động nóng từ \((0, 0)\):&lt;/strong&gt;
Kiểm tra KKT tại \((0, 0)\) với \(\lambda_2 = 4\): tọa độ 1 có \(|X_1^T y| = 6 &amp;gt; 4\) (vi phạm KKT!), còn tọa độ 2 có \(|X_2^T y| = 2 \le 4\) (thỏa mãn).
Đưa tọa độ 1 vào tập hoạt động: \(\mathcal{A} = \{1\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng trong — Giải chỉ trên tập hoạt động \(\mathcal{A} = \{1\}\):&lt;/strong&gt;
Cập nhật riêng \(\beta_1\):
\(\beta_1 = S_{\lambda_2 / \|X_1\|_2^2}\!\left(\frac{X_1^T y}{\|X_1\|_2^2}\right) = S_{4/2}\!\left(\frac{6}{2}\right) = S_2(3) = 1.\)
Điểm ứng viên là \(\hat{\beta} = (1, 0)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra KKT cho tọa độ không hoạt động \(j = 2\):&lt;/strong&gt;
Tính phần dư: \(r = y - X\hat{\beta} = (4, 2, 0)^T - 1 \cdot (1, 1, 0)^T = (3, 1, 0)^T\).
Kiểm tra \(|X_2^T r| = |0(3) + 1(1) + 1(0)| = 1 \le 4 = \lambda_2\) — &lt;strong&gt;thỏa mãn KKT&lt;/strong&gt;!
Thuật toán dừng ngay tại \(\beta^\star(4) = (1, 0)\) mà không cần cập nhật tọa độ 2 dù chỉ một lần. Trên bài toán \(p = 100{,}000\) đặc trưng, cơ chế này giúp tiết kiệm hơn \(99\%\) khối lượng tính toán!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mục này trình bày tổng quan thuật toán hạ theo tọa độ dọc đường chính quy hóa (pathwise coordinate descent) cho bài toán hồi quy Lasso [&lt;a href=&quot;https://arxiv.org/pdf/0708.1485.pdf&quot;&gt;Friedman et al. (2007)&lt;/a&gt;] [&lt;a href=&quot;https://www.jstatsoft.org/article/view/v033i01/v33i01.pdf&quot;&gt;Friedman et al. (2009)&lt;/a&gt;].&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Bài toán hồi quy Lasso:&lt;/strong&gt;
\(\min_{\beta} \frac{1}{2} \| y - X\beta \|_2^2 + \lambda \|\beta\|_1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ở &lt;a href=&quot;/contents/vi/chapter07/07_03_03_example_lasso_optimality_condition/&quot;&gt;07-03-03 Ví dụ: Điều kiện tối ưu của Lasso&lt;/a&gt;, ta đã suy ra điều kiện tối ưu bậc nhất cho bài toán này. Nghiệm tối ưu \(\beta\) thỏa mãn hệ điều kiện sau:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
X_1^T(y-X\beta) &amp;amp;= \lambda v_1\\\\
X_2^T(y-X\beta) &amp;amp;= \lambda v_2\\\\
\dots\\\\
X_p^T(y-X\beta) &amp;amp;= \lambda v_p
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; \(X_i\) (\(i \in \{ 1,2,\dots,p \}\)) là cột thứ \(i\) của ma trận \(X\), còn \(v=(v_1,v_2,\dots,v_p)\) là một dưới đạo hàm (subgradient) của \(\|\beta\|_1\) tại \(\beta=(\beta_1,\beta_2,\dots,\beta_p)\):&lt;/p&gt;

&lt;blockquote&gt;

\[v_i, i \in \{1,2,\dots,p \} = 
\begin{cases}
\{ 1 \}  &amp;amp;\text{if $\beta_i &amp;gt; 0$} \\
\{-1 \}  &amp;amp;\text{if $\beta_i &amp;lt; 0$} \\
[-1,1]   &amp;amp;\text{if $\beta_i = 0$}
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;Nhờ hệ điều kiện tối ưu này, ta có thể kiểm tra riêng từng thành phần của \(\beta\) xem đã tối ưu hay chưa, từ đó chỉ tập trung cập nhật những tọa độ chưa thỏa điều kiện. Ngoài ra, coordinate descent trên Lasso hội tụ rất nhanh khi \(\lambda\) lớn (vì nghiệm rất thưa); tận dụng tính chất này bằng cách giảm dần \(\lambda\) và dùng nghiệm trước làm điểm khởi tạo (warm start) giúp tăng tốc đáng kể.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán&quot;&gt;Thuật toán&lt;/h2&gt;

&lt;h3 id=&quot;vòng-ngoài-chiến-lược-pathwise&quot;&gt;Vòng ngoài (chiến lược pathwise):&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Giải lần lượt theo dãy tham số giảm dần \(\lambda_1 &amp;gt; \lambda_2 &amp;gt; \dots &amp;gt; \lambda_r\).&lt;/li&gt;
  &lt;li&gt;Dùng nghiệm tối ưu tìm được tại \(\lambda_k\) làm điểm khởi tạo (warm start) cho coordinate descent tại \(\lambda_{k+1}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;vòng-trong-chiến-lược-tập-hoạt-động--active-set&quot;&gt;Vòng trong (chiến lược tập hoạt động — active set):&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Thực hiện một hoặc vài chu trình tọa độ đầy đủ, rồi ghi nhận các tọa độ khác 0 của \(\beta\) vào tập hoạt động \(A\).&lt;/li&gt;
  &lt;li&gt;Lặp các chu trình coordinate descent chỉ trên tập \(A\) cho đến khi hội tụ.&lt;/li&gt;
  &lt;li&gt;Kiểm tra điều kiện tối ưu cho toàn bộ \(p\) tọa độ của \(\beta\); nếu có tọa độ nào vi phạm, bổ sung tọa độ đó vào \(A\) và quay lại bước trước.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ghi-chú&quot;&gt;Ghi chú&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Về mặt thực nghiệm, giải dọc theo đường tham số \(\lambda\) (pathwise) thường nhanh hơn nhiều so với việc giải trực tiếp tại một giá trị \(\lambda\) nhỏ riêng lẻ.&lt;/li&gt;
  &lt;li&gt;Chiến lược tập hoạt động tận dụng triệt để tính thưa của nghiệm; do đó coordinate descent cho hồi quy Lasso chạy nhanh hơn nhiều so với hồi quy ridge (tham khảo: &lt;a href=&quot;https://www.analyticsvidhya.com/blog/2016/01/complete-tutorial-ridge-lasso-regression-python/&quot;&gt;phân tích so sánh hồi quy ridge và lasso&lt;/a&gt;).&lt;/li&gt;
  &lt;li&gt;Pathwise coordinate descent hiện vẫn là một trong những thuật toán nhanh nhất cho bài toán hồi quy Lasso.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>23-03 Ví dụ: hồi quy lasso</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_03_Example_lasso_regression/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_03_Example_lasso_regression</id>
   <content type="html">&lt;p&gt;Khi Robert Tibshirani giới thiệu hồi quy &lt;strong&gt;Lasso&lt;/strong&gt; năm 1996, bài toán này từng bị xem là khá chậm để giải vì hàm phạt \(\lambda\|\beta\|_1\) không khả vi tại gốc tọa độ, buộc người dùng thời đó phải chuyển sang quy hoạch bậc hai (QP) với số ràng buộc tăng gấp đôi. Nhưng hơn một thập kỷ sau, cộng đồng thống kê phát hiện ra một sự thật đẹp đến khó tin: vì chuẩn \(\ell_1\) tách hoàn toàn theo từng tọa độ, &lt;strong&gt;hạ theo tọa độ (Coordinate Descent)&lt;/strong&gt; biến bài toán Lasso không trơn thành một chuỗi phép co ngưỡng mềm 1 chiều đơn giản đến mức có thể tính nhẩm!&lt;/p&gt;

&lt;p&gt;Chính phát hiện này đã đưa Lasso từ một khái niệm học thuật thành công cụ phân tích dữ liệu tiêu chuẩn trong y sinh, tài chính và học máy quy mô lớn, thường nhanh hơn cả Proximal Gradient và Accelerated Proximal Gradient hàng bậc độ lớn.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-coordinate-descent-cho-lasso&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của Coordinate Descent cho Lasso&lt;/h2&gt;

&lt;p&gt;Để hiểu trọn vẹn công thức cập nhật chỉ vỏn vẹn một dòng của bài học này, hãy nắm vững ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Dưới đạo hàm của giá trị tuyệt đối (Subdifferential of $$&lt;/td&gt;
          &lt;td&gt;\beta_i&lt;/td&gt;
          &lt;td&gt;\():** Tại\)\beta_i \neq 0\(, đạo hàm là\)\operatorname{sign}(\beta_i)\(; còn tại điểm gấp khúc\)\beta_i = 0\(, dưới vi phân là cả đoạn\)[-1, 1]\(. Chính đoạn\)[-1, 1]\(này tạo ra &quot;vùng chết&quot; (*dead zone*): nếu tương quan giữa cột\)X_i\(và phần dư đủ nhỏ (\)\le \lambda\(), hệ số\)\beta_i\(bị kéo hẳn về\)0$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Toán tử co ngưỡng mềm (Soft-Thresholding Operator):&lt;/strong&gt; Định nghĩa $$S_\tau(z) = \operatorname{sign}(z)\max(&lt;/td&gt;
          &lt;td&gt;z&lt;/td&gt;
          &lt;td&gt;- \tau, 0)\(. Nghiệm tối ưu theo từng tọa độ của Lasso chỉ gồm hai thao tác liên tiếp: (1) tính nghiệm hồi quy bình phương tối thiểu 1 biến trên phần dư riêng, rồi (2) kéo nó về phía\)0\(một đoạn bằng đúng\)\tau_i = \lambda / |X_i|_2^2$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Định lý Tseng và Tính thưa tức thì:&lt;/strong&gt; Nhờ $$\sum_{i=1}^p&lt;/td&gt;
          &lt;td&gt;\beta_i&lt;/td&gt;
          &lt;td&gt;\(tách được hoàn toàn theo từng biến, Coordinate Descent được đảm bảo hội tụ tới nghiệm tối ưu toàn cục của Lasso. Hơn thế, nhiều hệ số lập tức bằng\)0$$ ngay từ các vòng đầu, mở đường cho kỹ thuật bỏ qua biến không hoạt động (&lt;em&gt;active set&lt;/em&gt;) ở bài sau.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-1-chu-trình-cd-cho-lasso-và-quan-sát-ngưỡng-sinh-tính-thưa&quot;&gt;Giải thích: Tính tay 1 chu trình CD cho Lasso và quan sát ngưỡng sinh tính thưa&lt;/h3&gt;

&lt;p&gt;Ta giữ nguyên ma trận \(X\) và vector \(y\) từ bài trước để so sánh trực tiếp hồi quy tuyến tính thường với Lasso:&lt;/p&gt;

\[X = \begin{pmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \\ 0 &amp;amp; 1 \end{pmatrix}, \qquad y = \begin{pmatrix} 3 \\ 1 \\ 1 \end{pmatrix}, \qquad \|X_1\|_2^2 = 2,\; \|X_2\|_2^2 = 3.\]

&lt;p&gt;Chọn hệ số phạt \(\lambda = 2\), khởi tạo \(\beta^{(0)} = (0, 0)\) và phần dư \(r = (3, 1, 1)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật tọa độ \(i = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nghiệm hồi quy thường 1 biến: \(z_1 = \frac{X_1^T r}{\|X_1\|_2^2} = \frac{3 + 1 + 0}{2} = 2\).&lt;/li&gt;
      &lt;li&gt;Ngưỡng co riêng cho cột 1: \(\tau_1 = \frac{\lambda}{\|X_1\|_2^2} = \frac{2}{2} = 1\).&lt;/li&gt;
      &lt;li&gt;Áp dụng co ngưỡng mềm: \(\beta_1^{(1)} = S_1(2) = \operatorname{sign}(2)\max(2 - 1, 0) = 1\).&lt;/li&gt;
      &lt;li&gt;Cập nhật phần dư: \(r \leftarrow (3, 1, 1)^T - 1 \cdot (1, 1, 0)^T = (2, 0, 1)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật tọa độ \(i = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nghiệm hồi quy thường 1 biến: \(z_2 = \frac{X_2^T r}{\|X_2\|_2^2} = \frac{2 + 0 + 1}{3} = 1\).&lt;/li&gt;
      &lt;li&gt;Ngưỡng co riêng cho cột 2: \(\tau_2 = \frac{\lambda}{\|X_2\|_2^2} = \frac{2}{3}\).&lt;/li&gt;
      &lt;li&gt;Áp dụng co ngưỡng mềm: \(\beta_2^{(1)} = S_{2/3}(1) = 1 - \frac{2}{3} = \frac{1}{3}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử tăng phạt lên \(\lambda = 4\) để thấy tính thưa tuyệt đối:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với cột 1, ngưỡng mới là \(\tau_1 = \frac{4}{2} = 2\), nên \(\beta_1 = S_2(2) = 0\)!&lt;/li&gt;
      &lt;li&gt;Phần dư vẫn là \((3, 1, 1)^T\); với cột 2, \(z_2 = \frac{3 - 1 + 1}{3} = 1\) còn ngưỡng \(\tau_2 = \frac{4}{3} &amp;gt; 1\), nên \(\beta_2 = S_{4/3}(1) = 0\)!
Chỉ cần quan sát một phép trừ nhỏ, bạn đã thấy tận mắt cơ chế cắt hệ số về đúng \(0\) của Lasso!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Xét bài toán hồi quy Lasso dưới dạng tổng của một hàm lồi khả vi và một hàm không trơn tách được theo từng tọa độ:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{\beta} \frac{1}{2} \| y - X\beta \|_2^2 + \lambda \|\beta\|_1\]
&lt;/blockquote&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; $$|\beta|&lt;em&gt;1 = \sum&lt;/em&gt;{i=1}^p&lt;/td&gt;
      &lt;td&gt;\beta_i&lt;/td&gt;
      &lt;td&gt;$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Giữ cố định các thành phần \(\beta_j\) (\(j \neq i\)), ta tìm \(\beta_i\) cực tiểu hóa hàm mục tiêu từ điều kiện tối ưu bậc nhất với dưới đạo hàm:&lt;/p&gt;

\[\begin{align}
&amp;amp;0 \in \partial_i f(\beta) \;\Longleftrightarrow\; 0 = X_i^T X_i \beta_i + X_i^T(X_{-i} \beta_{-i} - y) + \lambda s_i,\\\\
&amp;amp;\text{với } s_i \in \partial |\beta_i|
\;\Rightarrow\;
\beta_i = S_{\lambda / \|X_i\|_2^2} \big( \frac{X_i^T(y-X_{-i} \beta_{-i})}{X_i^TX_i} \big)
\end{align}\]

&lt;p&gt;Nghiệm cập nhật có dạng toán tử co ngưỡng mềm (soft-thresholding) với ngưỡng \(\lambda / \|X_i\|_2^2\). Thuật toán coordinate descent lặp lại bước cập nhật \(\beta_i\) này lần lượt cho \(i=1,2,\dots,p,1,2,\dots\).&lt;/p&gt;

&lt;h2 id=&quot;thí-nghiệm-so-sánh-tốc-độ-hội-tụ-giữa-pg-agd-và-cd&quot;&gt;Thí nghiệm: so sánh tốc độ hội tụ giữa PG, AGD và CD&lt;/h2&gt;

&lt;p&gt;Đồ thị dưới đây so sánh tốc độ hội tụ của proximal gradient descent (PG), accelerated proximal gradient descent (AGD) và coordinate descent (CD) trên bài toán hồi quy Lasso với \(n=100, p=20\). Giá trị \(k\) trên trục hoành biểu diễn một bước lặp (đối với PG, AGD) hoặc một chu trình duyệt đủ \(p\) tọa độ (đối với CD).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter23/pd_vs_agd_vs_cd.png&quot; alt=&quot;[Hình 1] PG, AGD và CD [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] PG, AGD và CD [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Tương tự &lt;a href=&quot;/contents/vi/chapter23/23_02_Example_linear_regression/&quot;&gt;ví dụ hồi quy tuyến tính&lt;/a&gt;, coordinate descent tiếp tục hội tụ nhanh hơn đáng kể so với PG và AGD nhờ sử dụng ngay thông tin cập nhật mới nhất của từng tọa độ trong mỗi chu trình.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Cả ba phương pháp trong thí nghiệm trên đều có chi phí tính toán \(O(np)\) flops cho mỗi vòng lặp/chu trình.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>23-02 Ví dụ: hồi quy tuyến tính</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_02_Example_linear_regression/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_02_Example_linear_regression</id>
   <content type="html">&lt;p&gt;Trong hồi quy tuyến tính bình phương tối thiểu, ai cũng biết công thức nghiệm đóng \(\hat{\beta} = (X^T X)^{-1} X^T y\). Nhưng khi số đặc trưng \(p\) lên tới hàng chục nghìn, việc nhân ma trận \(X^T X\) tốn \(O(np^2)\) và nghịch đảo tốn \(O(p^3)\) trở nên bất khả thi. Ta buộc phải dùng các phương pháp lặp bậc nhất — và đây là lúc một kết quả thực nghiệm đáng kinh ngạc xuất hiện.&lt;/p&gt;

&lt;p&gt;Trên cùng một bài toán hồi quy tuyến tính, khi so sánh từng chu trình hạ theo tọa độ (CD) với từng bước gradient descent (GD) hay thậm chí gradient tăng tốc Nesterov (AGD), đường hội tụ của CD thường lao dốc nhanh hơn hẳn — trong khi tổng số phép tính của &lt;strong&gt;một chu trình CD lại bằng đúng một bước GD&lt;/strong&gt;! Bí mật nằm ở hai chỗ: CD luôn dùng ngay thông tin tọa độ vừa cập nhật (hiệu ứng Gauss–Seidel) và tự động chọn kích thước bước tối ưu riêng cho từng tọa độ mà không bị chặn bởi trị riêng lớn nhất toàn cục.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-tạo-nên-tốc-độ-của-cd-cho-hồi-quy-tuyến-tính&quot;&gt;Kiến thức cần nhớ: Ba trụ cột tạo nên tốc độ của CD cho hồi quy tuyến tính&lt;/h2&gt;

&lt;p&gt;Để hiểu cả công thức cập nhật lẫn lý do so sánh chi phí giữa CD và GD là hoàn toàn công bằng, hãy nắm ba trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chiếu từng phần dư (Partial Residual Regression):&lt;/strong&gt; Khi giữ cố định \(\beta_{-i}\), phần dư chưa được giải thích bởi các đặc trưng khác là \(r^{(-i)} = y - X_{-i}\beta_{-i}\). Cập nhật \(\beta_i = \frac{X_i^T r^{(-i)}}{\|X_i\|_2^2}\) chính là hồi quy tuyến tính 1 biến đơn giản của phần dư đó lên cột \(X_i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bảo trì phần dư trong \(O(n)\) (Incremental Residual Update):&lt;/strong&gt; Nếu mỗi lần cập nhật \(\beta_i\) ta tính lại \(X_{-i}\beta_{-i}\) từ đầu thì tốn \(O(np)\), khiến cả chu trình tốn \(O(np^2)\). Nhưng bằng cách giữ vector phần dư chung \(r = y - X\beta\), ta tính \(r^{(-i)} = r + \beta_i^{\text{old}} X_i\), cập nhật \(\beta_i^{\text{new}}\), rồi sửa \(r \leftarrow r - (\beta_i^{\text{new}} - \beta_i^{\text{old}}) X_i\) — chỉ tốn \(O(n)\) mỗi tọa độ, nên cả chu trình \(p\) tọa độ chỉ tốn đúng \(O(np)\), ngang bằng 1 bước GD!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tự động thích nghi độ cong từng trục (Coordinate-wise Lipschitz Adaptation):&lt;/strong&gt; GD phải dùng chung một bước \(t \le 1/L\) bị chi phối bởi hướng cong mạnh nhất của \(X^T X\). Ngược lại, CD chia riêng cho \(\|X_i\|_2^2\) trên từng trục — tương đương với việc tự động tiền điều kiện theo đường chéo (&lt;em&gt;diagonal preconditioning&lt;/em&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-1-chu-trình-cd-có-bảo-trì-phần-dư&quot;&gt;Giải thích: Tính tay 1 chu trình CD có bảo trì phần dư&lt;/h3&gt;

&lt;p&gt;Xét bài toán \(\min_{\beta \in \mathbb{R}^2} \frac{1}{2}\|y - X\beta\|_2^2\) với ma trận đặc trưng và vector nhãn:&lt;/p&gt;

\[X = \begin{pmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \\ 0 &amp;amp; 1 \end{pmatrix}, \qquad y = \begin{pmatrix} 3 \\ 1 \\ 1 \end{pmatrix}.\]

&lt;p&gt;Ta tính sẵn bình phương chuẩn các cột: \(\|X_1\|_2^2 = 1^2 + 1^2 + 0^2 = 2\) và \(\|X_2\|_2^2 = 1^2 + (-1)^2 + 1^2 = 3\). Khởi tạo \(\beta^{(0)} = (0, 0)\), nên vector phần dư ban đầu là \(r = y - X\beta^{(0)} = (3, 1, 1)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật tọa độ \(i = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vì \(\beta_1^{\text{old}} = 0\), phần dư riêng \(r^{(-1)} = r = (3, 1, 1)^T\).&lt;/li&gt;
      &lt;li&gt;Tích vô hướng \(X_1^T r^{(-1)} = 1(3) + 1(1) + 0(1) = 4\).&lt;/li&gt;
      &lt;li&gt;Suy ra \(\beta_1^{(1)} = \frac{4}{2} = 2\).&lt;/li&gt;
      &lt;li&gt;Cập nhật phần dư ngay tại chỗ (chỉ tốn \(O(n)\)):
\(r \leftarrow (3, 1, 1)^T - (2 - 0)(1, 1, 0)^T = (1,\; -1,\; 1)^T.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật tọa độ \(i = 2\) (dùng ngay \(r\) vừa cập nhật!):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vì \(\beta_2^{\text{old}} = 0\), phần dư riêng \(r^{(-2)} = r = (1, -1, 1)^T\).&lt;/li&gt;
      &lt;li&gt;Tích vô hướng \(X_2^T r^{(-2)} = 1(1) + (-1)(-1) + 1(1) = 3\).&lt;/li&gt;
      &lt;li&gt;Suy ra \(\beta_2^{(1)} = \frac{3}{3} = 1\).&lt;/li&gt;
      &lt;li&gt;Cập nhật phần dư:
\(r \leftarrow (1, -1, 1)^T - (1 - 0)(1, -1, 1)^T = (0,\; 0,\; 0)^T!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan sát:&lt;/strong&gt; Chỉ sau &lt;strong&gt;1 chu trình duy nhất&lt;/strong&gt; gồm đúng 2 phép tích vô hướng và 2 phép trừ vector, ta đã thu được nghiệm chính xác tuyệt đối \(\beta^\star = (2, 1)\) với phần dư bằng \(0\) — minh họa hoàn hảo cho hiệu ứng Gauss–Seidel kết hợp bảo trì phần dư \(O(n)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Xét bài toán hồi quy tuyến tính:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\min_{\beta} \frac{1}{2} \| y - X\beta \|_2^2,\)
\(\text{với } y \in \mathbb{R}^n \text{ và } X \in \mathbb{R}^{n \times p} \text{ có các cột } X_1, \dots, X_p.\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Giữ cố định tất cả các thành phần \(\beta_j\) (\(j \neq i\)), ta tìm \(\beta_i\) cực tiểu hóa hàm mục tiêu (ký hiệu \(-i\) chỉ tập các thành phần còn lại trừ \(i\); tương ứng \(X_{-i}\) là ma trận gồm các cột của \(X\) trừ cột thứ \(i\)):&lt;/p&gt;

\[\begin{align}
0 &amp;amp;= \nabla_i f(\beta)\\\\
&amp;amp;= X_i^T (X\beta - y)\\\\
&amp;amp;= X_i^T (X_i \beta_i + X_{-i} \beta_{-i} - y)\\\\
\Rightarrow\\\\
&amp;amp;\beta_i = \frac{X_i^T (y - X_{-i} \beta_{-i})}{X_i^T X_i}
\end{align}\]

&lt;p&gt;Thuật toán coordinate descent lặp lại việc cập nhật \(\beta_i\) theo công thức trên với \(i = 1, 2, \dots, p, 1, 2, \dots\).&lt;/p&gt;

&lt;h2 id=&quot;thí-nghiệm-so-sánh-tốc-độ-hội-tụ-giữa-gd-agd-và-cd&quot;&gt;Thí nghiệm: so sánh tốc độ hội tụ giữa GD, AGD và CD&lt;/h2&gt;

&lt;p&gt;Đồ thị dưới đây so sánh tốc độ hội tụ của coordinate descent (CD), gradient descent (GD) và accelerated gradient descent (AGD) trên bài toán hồi quy tuyến tính với \(n=100, p=20\). Trên trục hoành, giá trị \(k\) biểu diễn một bước lặp (đối với GD, AGD) hoặc một chu trình duyệt đủ \(p\) tọa độ (đối với CD).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter23/gd_vs_agd_vs_cd.png&quot; alt=&quot;[Hình 1] GD, AGD và CD [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] GD, AGD và CD [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Kết quả cho thấy coordinate descent hội tụ nhanh hơn đáng kể so với AGD — vốn đạt tốc độ tối ưu trong lớp các phương pháp bậc nhất. Lý do là CD không thuộc lớp phương pháp bậc nhất thuần túy: ở mỗi bước con bên trong một chu trình, nó tận dụng ngay giá trị tọa độ vừa được cập nhật ở bước trước đó.&lt;/p&gt;

&lt;h3 id=&quot;câu-hỏi-so-sánh-một-chu-trình-cd-với-một-bước-gd-như-trên-có-công-bằng-không&quot;&gt;Câu hỏi: So sánh một chu trình CD với một bước GD như trên có công bằng không?&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Trả lời: Có.&lt;/strong&gt; Công thức cập nhật CD có thể cài đặt với độ phức tạp \(O(n)\) cho mỗi tọa độ, do đó một chu trình gồm \(p\) tọa độ tốn \(O(np)\) phép tính — tương đương chi phí một bước GD:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật gradient descent:&lt;/strong&gt; \(\beta \leftarrow \beta + tX^T(y-X\beta)\), tốn \(O(np)\) flops để tính \(X\beta\) và \(X^T r\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật coordinate descent:&lt;/strong&gt; duy trì sẵn vector phần dư \(r = y - X\beta\); khi đó mỗi bước chỉ cần cập nhật \(\beta_i \leftarrow \beta_i + \frac{X_i^T r}{X_i^T X_i}\) rồi cập nhật phần dư \(r \leftarrow r - X_i (\beta_i^{\text{new}} - \beta_i^{\text{old}})\), tốn \(O(n)\) flops mỗi tọa độ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;coordinate-descent-mỗi-lần-một-tọa-độ-video&quot;&gt;Coordinate descent: mỗi lần một tọa độ (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/coordinate-descent_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Coordinate descent cực tiểu hóa chính xác theo từng trục tọa độ, tạo nên quỹ đạo dạng bậc thang; khi các biến có tương quan cao, kích thước mỗi bước đi sẽ thu hẹp lại.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-coordinate-descent-so-với-gradient-descent&quot;&gt;Tự tay thử: coordinate descent so với gradient descent&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;cd&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>23-01 Phương Pháp Coordinate Descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_01_Coordinate_descent/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter23/23_01_Coordinate_descent</id>
   <content type="html">&lt;p&gt;Một câu hỏi kinh điển thường làm người mới học tối ưu giật mình: &lt;em&gt;nếu tôi đứng tại một điểm mà bước sang trái cũng lên dốc, bước sang phải cũng lên dốc, bước lên trên hay xuống dưới đều lên dốc — vậy tôi đã ở đáy thung lũng chưa?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Nếu mặt địa hình trơn láng (khả vi), câu trả lời chắc chắn là &lt;strong&gt;có&lt;/strong&gt;. Nhưng chỉ cần mặt địa hình có một vết gấp nhọn chạy chéo góc \(45^\circ\), bạn hoàn toàn có thể bị &lt;strong&gt;mắc kẹt giữa sườn núi&lt;/strong&gt;: mọi bước đi dọc theo trục Bắc–Nam hay Đông–Tây đều leo dốc, trong khi chỉ cần đi chéo Đông–Bắc là thung lũng sâu thẳm mở ra ngay trước mắt! Toàn bộ bài học này xoay quanh việc phân định rạch ròi ranh giới giữa khi nào hạ theo tọa độ thành công và khi nào nó thất bại.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-lý-thuyết-của-định-lý-hội-tụ-tseng&quot;&gt;Kiến thức cần nhớ: Ba trụ cột lý thuyết của định lý hội tụ Tseng&lt;/h2&gt;

&lt;p&gt;Ba câu hỏi Q1–Q2–Q3 trong bài chính là ba nấc thang dẫn tới kết quả kinh điển của Paul Tseng (2001):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp trơn (Smooth Convex Functions):&lt;/strong&gt; Khi \(f\) khả vi trên \(\mathbb{R}^n\), cực tiểu theo từng trục tọa độ suy ra mọi đạo hàm riêng \(\frac{\partial f}{\partial x_i}(x) = 0\), đồng nghĩa \(\nabla f(x) = 0\) — điều kiện đủ cho cực tiểu toàn cục của hàm lồi.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Trường hợp không trơn không tách được (Non-Separable Nonsmooth):&lt;/strong&gt; Khi xuất hiện một hạng tử không trơn ghép nhiều biến với nhau (như $$&lt;/td&gt;
          &lt;td&gt;x_1 - x_2&lt;/td&gt;
          &lt;td&gt;\(hoặc\)\max(x_1, x_2)\(), dưới vi phân\)\partial f(x)$$ không phân rã thành tích Descartes của các dưới vi phân riêng lẻ; điểm tối ưu theo từng trục có thể không phải cực tiểu toàn cục.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc hợp thành tách được (Composite Separable Structure):&lt;/strong&gt; Khi hàm mục tiêu có dạng \(f(x) = g(x) + \sum_{i=1}^n h_i(x_i)\) với \(g\) lồi khả vi và từng \(h_i\) lồi (có thể không trơn nhưng chỉ phụ thuộc riêng vào \(x_i\)), mọi góc nhọn đều &lt;strong&gt;song song với các trục tọa độ&lt;/strong&gt;. Nhờ đó, định lý Tseng đảm bảo cực tiểu theo từng tọa độ luôn là cực tiểu toàn cục — chiếc chìa khóa mở cửa cho Lasso và hàng loạt mô hình thưa!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phản-ví-dụ-tính-tay--điểm-bị-kẹt-trên-hàm-lồi-không-tách-được&quot;&gt;Giải thích: Phản ví dụ tính tay — điểm bị “kẹt” trên hàm lồi không tách được&lt;/h3&gt;

&lt;p&gt;Hãy tự tay kiểm chứng một phản ví dụ cụ thể cho Câu hỏi Q2 để thấy rõ vì sao sự không tách được lại bẫy chết Coordinate Descent. Xét hàm lồi:&lt;/p&gt;

\[f(x_1, x_2) = (x_1 + x_2 - 2)^2 + 5|x_1 - x_2|\]

&lt;p&gt;tại điểm \(x = (0, 0)\), nơi giá trị hàm là \(f(0, 0) = (-2)^2 + 0 = 4\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra cực tiểu dọc theo trục \(x_1\) (giữ cố định \(x_2 = 0\)):&lt;/strong&gt;
Hàm một biến là \(\phi_1(x_1) = (x_1 - 2)^2 + 5|x_1|\).
    &lt;ul&gt;
      &lt;li&gt;Nếu \(x_1 &amp;gt; 0\): \(\phi_1&apos;(x_1) = 2(x_1 - 2) + 5 = 2x_1 + 1 &amp;gt; 0\) (hàm tăng ngặt khi đi sang phải!).&lt;/li&gt;
      &lt;li&gt;Nếu \(x_1 &amp;lt; 0\): \(\phi_1&apos;(x_1) = 2(x_1 - 2) - 5 = 2x_1 - 9 &amp;lt; 0\) (hàm tăng ngặt khi đi sang trái!).
Do đó, \(x_1 = 0\) là &lt;strong&gt;cực tiểu toàn cục duy nhất&lt;/strong&gt; dọc theo trục \(x_1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra cực tiểu dọc theo trục \(x_2\) (giữ cố định \(x_1 = 0\)):&lt;/strong&gt;
Vì hàm đối xứng theo \(x_1, x_2\), hàm \(\phi_2(x_2) = (x_2 - 2)^2 + 5|x_2|\) cũng đạt &lt;strong&gt;cực tiểu toàn cục duy nhất&lt;/strong&gt; tại \(x_2 = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thế nhưng \((0, 0)\) KHÔNG phải cực tiểu toàn cục:&lt;/strong&gt;
Thử bước chéo dọc đường \(x_1 = x_2\) tới điểm \((1, 1)\):
\(f(1, 1) = (1 + 1 - 2)^2 + 5|1 - 1| = 0 &amp;lt; 4 = f(0, 0)!\)&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Kết luận trực giác:&lt;/strong&gt; Vết gấp không trơn của $$5&lt;/td&gt;
          &lt;td&gt;x_1 - x_2&lt;/td&gt;
          &lt;td&gt;\(chạy dọc theo đường chéo\)x_1 = x_2\((chéo\)45^\circ\(so với các trục). Khi Coordinate Descent chỉ được phép đi ngang hoặc đi dọc, nó bị kẹt cứng tại\)(0, 0)\(dù đáy thung lũng\)f = 0\(nằm ngay trước mặt! Ngược lại, nếu thay\)5&lt;/td&gt;
          &lt;td&gt;x_1 - x_2&lt;/td&gt;
          &lt;td&gt;\(bằng chuẩn\)\ell_1\(tách được\)5&lt;/td&gt;
          &lt;td&gt;x_1&lt;/td&gt;
          &lt;td&gt;+ 5&lt;/td&gt;
          &lt;td&gt;x_2&lt;/td&gt;
          &lt;td&gt;$$, mọi vết gấp đều nằm dọc trục tọa độ nên hiện tượng kẹt này không bao giờ xảy ra.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chương này giới thiệu phương pháp hạ theo tọa độ (coordinate descent) — một thuật toán tối ưu đơn giản, hiệu quả và có khả năng mở rộng tốt. Trước khi đi vào công thức, hãy bắt đầu với ba câu hỏi nền tảng về điều kiện tối ưu theo từng trục tọa độ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q1. Với hàm \(f: \mathbb{R}^n \rightarrow \mathbb{R}\) lồi và khả vi, nếu điểm \(x\) làm cực tiểu \(f\) dọc theo từng trục tọa độ, thì \(x\) có phải là điểm cực tiểu toàn cục không?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A1. Có. Khi đó \(\nabla f(x) = 0\) nên \(x\) là điểm cực tiểu toàn cục của \(f\).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Điều kiện cực tiểu theo từng trục tọa độ nghĩa là \(f(x + \delta e_i) \ge f(x)\) với mọi \(\delta \in \mathbb{R}\) và mọi \(i = 1, \dots, n\), trong đó \(e_i = (0, \dots, 1, \dots, 0) \in \mathbb{R}^n\) là vector cơ sở chuẩn thứ \(i\). Vì không thể làm giảm \(f\) khi dịch chuyển dọc theo bất kỳ trục tọa độ nào từ \(x\), mọi đạo hàm riêng tại \(x\) đều bằng 0:&lt;/p&gt;

\[\nabla f(x) = \big( \frac{\partial f}{\partial x_1}(x), \dots, \frac{\partial f}{\partial x_n}(x) \big) = (0, \dots, 0) = 0\]

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter23/smooth_function.png&quot; alt=&quot;[Hình 1] Hàm lồi trơn f [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$[Hình 1] \; Hàm \; lồi \; trơn \; f \; [3]$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q2. Nếu \(f: \mathbb{R}^n \rightarrow \mathbb{R}\) là hàm lồi nhưng &lt;em&gt;không khả vi&lt;/em&gt;, điểm \(x\) đạt cực tiểu dọc theo từng trục tọa độ có luôn là cực tiểu toàn cục không?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A2. Không. Trong trường hợp này, \(x\) chưa chắc là điểm cực tiểu toàn cục của \(f\) (xem phản ví dụ ở Hình 2).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Quan sát các đường đồng mức bên phải ở Hình 2: dù điểm đánh dấu không phải cực tiểu toàn cục, giá trị \(f\) vẫn không thể giảm nếu chỉ đi dọc theo các trục tọa độ (muốn giảm \(f\), ta phải đi vào phần bên trong của đường đồng mức). Nguyên nhân là tại điểm góc không trơn đó, toàn bộ phần bên trong đường đồng mức nằm kẹp giữa hai đường thẳng song song với các trục tọa độ. Khi \(f\) khả vi, mỗi điểm trên đường đồng mức chỉ có duy nhất một tiếp tuyến nên hiện tượng kẹt này không xảy ra.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter23/non-smooth_function.png&quot; alt=&quot;[Hình 2] Phản ví dụ: hàm lồi không trơn f [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$[Hình 2] \; Phản \; ví \; dụ: \; hàm \; lồi \; không \; trơn \; f \; [3]$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q3. Nếu \(f\) là tổng của một hàm lồi khả vi \(g\) và một hàm lồi không trơn &lt;em&gt;tách được theo từng tọa độ&lt;/em&gt;, tức \(f(x) = g(x) + \sum_{i=1}^{n} h_i(x_i)\), thì điểm \(x\) cực tiểu theo từng trục tọa độ có luôn là cực tiểu toàn cục không?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A3. Có. Với mọi \(y \in \mathbb{R}^n\), ta luôn có:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
f(y) - f(x) &amp;amp;\ge \nabla g(x)^T (y-x) + \sum_{i=1}^{n} \big[ h_i(y_i) - h_i(x_i) \big] \\\\
&amp;amp;= \sum_{i=1}^{n} \big[ \underbrace{\nabla_i g(x) (y_i - x_i) + h_i(y_i) - h_i(x_i)}_{\ge 0} \big] \ge 0
\end{align}\]

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Đặt \(F_i(x_i) = g(x_i ; x_{-i}) + h_i(x_i)\), trong đó \(g(x_i ; x_{-i})\) coi thành phần thứ \(i\) là biến số còn tất cả các thành phần khác giữ cố định. Vì \(x_i\) cực tiểu hóa \(F_i\):&lt;/p&gt;

\[\begin{align}
&amp;amp; \: 0 \in \partial F_i (x_i) \\\\
\Leftrightarrow &amp;amp; \: 0 \in \{ \nabla_i g(x) \} + \partial h_i(x_i)\\\\
\Leftrightarrow &amp;amp; \: - \nabla_i g(x) \in \partial h_i(x_i)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Theo &lt;a href=&quot;/contents/vi/chapter07/07_01_subgradient/&quot;&gt;định nghĩa của dưới đạo hàm (subgradient)&lt;/a&gt;, ta suy ra với mọi \(y_i\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; h_i(y_i) \ge h_i(x_i) - \nabla_i g(x) (y_i - x_i)\\\\
\Leftrightarrow &amp;amp; \nabla_i g(x) (y_i - x_i) + h_i(y_i) - h_i(x_i) \ge 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter23/separable_non-smooth.png&quot; alt=&quot;[Hình 3] Hàm lồi f có các phần không trơn tách được [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$[Hình 3] \; Hàm \; lồi \; f \; có \; các \; phần \; không \; trơn \; tách \; được \; [3]$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;kết-luận&quot;&gt;Kết luận&lt;/h2&gt;

&lt;p&gt;Điểm cực tiểu của hàm có dạng \(f(x) = g(x) + \sum_{i=1}^{n} h_i(x_i)\) (với \(g\) lồi khả vi và các \(h_i\) lồi) có thể tìm bằng &lt;strong&gt;coordinate descent&lt;/strong&gt;. Xuất phát từ một điểm khởi tạo \(x^{(0)}\), thuật toán lặp lại chu trình cập nhật sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Coordinate Descent:&lt;/strong&gt; &lt;br /&gt;
\(\:\) Với \(k = 1,2,3,\dots\),&lt;/p&gt;

\[\begin{align}
x_1^{(k)} &amp;amp;\in \text{arg}\min_{x_1} \: f(x_1, x_2^{(k-1)}, x_3^{(k-1)}, \dots, x_n^{(k-1)})\\\\
x_2^{(k)} &amp;amp;\in \text{arg}\min_{x_2} \: f(x_1^{(k)}, x_2, x_3^{(k-1)}, \dots, x_n^{(k-1)})\\\\
x_3^{(k)} &amp;amp;\in \text{arg}\min_{x_3} \: f(x_1^{(k)}, x_2^{(k)}, x_3, \dots, x_n^{(k-1)})\\\\
&amp;amp; \dots\\\\
x_n^{(k)} &amp;amp;\in \text{arg}\min_{x_n} \: f(x_1^{(k)}, x_2^{(k)}, x_3^{(k)}, \dots, x_n)
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;lưu-ý&quot;&gt;Lưu ý:&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Trong chu trình thứ \(k\), bước cập nhật các tọa độ \(x_{i+1}^{(k)}, \dots, x_{n}^{(k)}\) sử dụng ngay giá trị mới \(x_i^{(k)}\) vừa tính được.&lt;/li&gt;
  &lt;li&gt;Thứ tự duyệt các tọa độ trong mỗi chu trình có thể chọn tùy ý (tuần hoàn, ngẫu nhiên hoặc theo quy tắc tham lam).&lt;/li&gt;
  &lt;li&gt;Có thể nhóm nhiều tọa độ thành từng khối để cập nhật đồng thời (block coordinate descent).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Phiên bản trên thực hiện cực tiểu hóa chính xác theo từng tọa độ. Ngoài ra, với hàm \(f\) lồi và khả vi, ta cũng có thể dùng phiên bản cực tiểu hóa không chính xác bằng một bước gradient theo từng tọa độ:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Coordinate Descent (cực tiểu hóa không chính xác theo từng tọa độ):&lt;/strong&gt; &lt;br /&gt;
\(\:\) Với \(k = 1,2,3,\dots\),&lt;/p&gt;

\[\begin{align}
x_1^{(k)} &amp;amp;= x_1^{(k-1)} - t_{k,1} \cdot \nabla_1 f(x_1^{(k-1)}, x_2^{(k-1)}, x_3^{(k-1)}, \dots, x_n^{(k-1)})\\\\
x_2^{(k)} &amp;amp;= x_2^{(k-1)} - t_{k,2} \cdot \nabla_2 f(x_1^{(k)}, x_2^{(k-1)}, x_3^{(k-1)}, \dots, x_n^{(k-1)})\\\\
x_3^{(k)} &amp;amp;= x_3^{(k-1)} - t_{k,3} \cdot \nabla_3 f(x_1^{(k)}, x_2^{(k)}, x_3^{(k-1)}, \dots, x_n^{(k-1)})\\\\
&amp;amp; \dots\\\\
x_n^{(k)} &amp;amp;= x_n^{(k-1)} - t_{k,n} \cdot \nabla_n f(x_1^{(k)}, x_2^{(k)}, x_3^{(k)}, \dots, x_n^{(k-1)})
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>22 Phương pháp Gradient có điều kiện (Frank-Wolfe)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_Conditional_Gradient_Method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_Conditional_Gradient_Method</id>
   <content type="html">&lt;p&gt;Năm 1956, giữa thời kỳ hoàng kim đầu tiên của quy hoạch tuyến tính, hai nhà toán học Marguerite Frank và Philip Wolfe đặt ra một câu hỏi tưởng chừng nghịch lý: &lt;em&gt;nếu ta đã có những bộ giải cực nhanh cho bài toán tối ưu tuyến tính trên một đa diện, tại sao lại phải tự làm khó mình bằng các phép chiếu phi tuyến đắt đỏ khi tối ưu một hàm lồi trơn?&lt;/em&gt; Từ câu hỏi đó, &lt;strong&gt;thuật toán Frank–Wolfe&lt;/strong&gt; (hay phương pháp gradient có điều kiện) ra đời, mở ra một trường phái tối ưu không cần phép chiếu (&lt;em&gt;projection-free&lt;/em&gt;) đầy thanh lịch.&lt;/p&gt;

&lt;p&gt;Suốt nhiều thập kỷ, Frank–Wolfe từng nằm yên trong sách giáo khoa cổ điển, trước khi bất ngờ hồi sinh mạnh mẽ trong kỷ nguyên dữ liệu lớn và học máy hiện đại. Lý do rất thực tế: khi biến tối ưu là một ma trận triệu chiều bị ràng buộc bởi chuẩn vết (trace norm) hay một kế hoạch vận chuyển trên đơn hình khổng lồ, phép chiếu Euclid đòi hỏi phân tích SVD đầy đủ — quá chậm để chạy lặp hàng nghìn lần — trong khi cực tiểu hóa một hàm tuyến tính chỉ cần tìm đúng &lt;em&gt;một&lt;/em&gt; cặp vector kỳ dị hàng đầu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tối-ưu-không-cần-phép-chiếu&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tối ưu không cần phép chiếu&lt;/h2&gt;

&lt;p&gt;Để nhìn thấy trọn vẹn sức mạnh và giới hạn của Chương 22, bạn hãy đặt thuật toán Frank–Wolfe vào giao điểm của bốn nhánh kiến thức nền tảng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hình học lồi và các đỉnh cực trị (Convex Geometry &amp;amp; Extreme Points):&lt;/strong&gt; Một tập lồi compact \(C\) luôn có thể được biểu diễn dưới dạng bao lồi của các đỉnh cực trị (&lt;em&gt;extreme points&lt;/em&gt;). Khi cực tiểu hóa một hàm tuyến tính trên \(C\), nghiệm luôn đạt được tại một đỉnh — đó là nguyên nhân sâu xa khiến nghiệm của Frank–Wolfe mang cấu trúc thưa (sparse) hoặc hạng thấp (low-rank) một cách tự nhiên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ bậc nhất và Bộ giải tuyến tính (Linear Minimization Oracle — LMO):&lt;/strong&gt; Thay vì dựng hình parabol cục bộ rồi chiếu nghiệm xuống \(C\) như Projected Gradient Descent, Frank–Wolfe chỉ thay hàm mục tiêu bằng mặt phẳng tiếp tuyến và gọi LMO. Toàn bộ độ phức tạp của tập ràng buộc được “đóng gói” gọn vào một bài toán tuyến tính duy nhất ở mỗi bước.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu Fenchel và Khoảng cách đối ngẫu (Duality Gap):&lt;/strong&gt; Không giống nhiều thuật toán bậc nhất khó biết khi nào nên dừng, Frank–Wolfe tự động sinh ra một cận trên chặt cho sai số tối ưu \(f(x^{(k)}) - f^\star\) miễn phí ngay từ kết quả gọi LMO, giúp kiểm soát độ chính xác một cách định lượng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Động lực hội tụ và Cấu trúc biên (Convergence &amp;amp; Boundary Geometry):&lt;/strong&gt; Tốc độ hội tụ cổ điển \(O(1/k)\) của Frank–Wolfe có thể bị chậm lại vì hiện tượng đi zíc-zắc khi nghiệm nằm trên một mặt biên của đa diện — động lực trực tiếp dẫn đến các biến thể hiện đại như Away-Step hay Pairwise Frank–Wolfe.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-một-bước-frankwolfe-trên-đơn-hình-xác-suất&quot;&gt;Giải thích: Một bước Frank–Wolfe trên đơn hình xác suất&lt;/h3&gt;

&lt;p&gt;Hãy tự tay tính một vòng lặp để thấy vì sao không cần phép chiếu mà điểm lặp vẫn không bao giờ rời khỏi miền khả thi. Xét bài toán cực tiểu hóa \(f(x_1, x_2) = \frac{1}{2}(x_1 - 2)^2 + \frac{1}{2}(x_2 - 1)^2\) trên đơn hình xác suất \(C = \{(x_1, x_2) : x_1 \ge 0,\; x_2 \ge 0,\; x_1 + x_2 = 1\}\), xuất phát từ đỉnh \(x^{(0)} = (0, 1) \in C\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giá trị và gradient tại điểm hiện tại:&lt;/strong&gt; Tại \(x^{(0)} = (0, 1)\), ta có \(f(x^{(0)}) = \frac{1}{2}(-2)^2 + \frac{1}{2}(0)^2 = 2\) và \(\nabla f(x^{(0)}) = (x_1 - 2,\; x_2 - 1) = (-2, 0)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gọi bộ giải tuyến tính (LMO):&lt;/strong&gt; Ta tìm \(s^{(0)} = \arg\min_{s \in C} \langle (-2, 0), s \rangle = \arg\min_{s \in C} (-2s_1)\). Vì \(s_1 \in [0, 1]\), biểu thức \(-2s_1\) nhỏ nhất khi \(s_1 = 1, s_2 = 0\), tức đỉnh \(s^{(0)} = (1, 0)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Di chuyển bằng tổ hợp lồi:&lt;/strong&gt; Điểm mới có dạng \(x(\gamma) = (1 - \gamma)(0, 1) + \gamma(1, 0) = (\gamma, 1 - \gamma)\) với \(\gamma \in [0, 1]\). Vì cả \(x^{(0)}\) và \(s^{(0)}\) đều nằm trong tập lồi \(C\), mọi \(\gamma \in [0, 1]\) tự động bảo đảm \(x(\gamma) \in C\) — hoàn toàn không cần chiếu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn bước và kiểm tra dừng:&lt;/strong&gt; Thay vào hàm mục tiêu, \(f(x(\gamma)) = \frac{1}{2}(\gamma - 2)^2 + \frac{1}{2}(-\gamma)^2 = \gamma^2 - 2\gamma + 2\), đạt cực tiểu trên \([0, 1]\) tại \(\gamma_1 = 1\) (cũng trùng với bước chuẩn \(\gamma_1 = \frac{2}{1+1} = 1\)). Ta nhận \(x^{(1)} = (1, 0)\) với \(f(x^{(1)}) = 1\). Tại đây, \(\nabla f(1, 0) = (-1, -1)\); với mọi \(s \in C\) thì \(\langle \nabla f(x^{(1)}), s \rangle = -(s_1 + s_2) = -1 = \langle \nabla f(x^{(1)}), x^{(1)} \rangle\), nên khoảng cách đối ngẫu bằng \(0\) — ta đã chạm đúng nghiệm tối ưu toàn cục chỉ sau một bước!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chương này trình bày thuật toán Frank-Wolfe do Marguerite Frank và Philip Wolfe đề xuất năm 1956.&lt;/p&gt;

&lt;p&gt;Thuật toán Frank-Wolfe là một phương pháp tối ưu lặp bậc nhất dành cho bài toán tối ưu lồi có ràng buộc, còn được gọi là phương pháp gradient có điều kiện (conditional gradient method), phương pháp gradient rút gọn (reduced gradient method) hoặc thuật toán tổ hợp lồi (convex combination algorithm). Tại mỗi vòng lặp, thuật toán xấp xỉ tuyến tính hàm mục tiêu xung quanh điểm hiện tại, tìm cực tiểu của hàm tuyến tính đó trên tập ràng buộc, rồi di chuyển theo hướng tới điểm cực tiểu vừa tìm được.&lt;/p&gt;

&lt;p&gt;[15] Wikipedia. &lt;a href=&quot;https://en.wikipedia.org/wiki/Frank%E2%80%93Wolfe_algorithm&quot;&gt;Frank–Wolfe algorithm&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-giai-đoạn-20222026-tùy-chọn&quot;&gt;Ứng dụng giai đoạn 2022–2026 (tùy chọn)&lt;/h2&gt;

&lt;p&gt;Nhờ chỉ cần một bộ giải cực tiểu tuyến tính (linear minimization oracle) thay vì phép chiếu, thuật toán Frank–Wolfe tiếp tục được ứng dụng rộng rãi trong thập niên 2020: từ SVM có cấu trúc, bài toán vận chuyển tối ưu bán nới lỏng (ứng dụng chuyển màu ảnh), vận chuyển tối ưu không cân bằng 1 chiều, cho đến các phương pháp giải thích mạng nơ-ron có ràng buộc (tối ưu độ méo–tốc độ trên hình cầu \(\ell_1\) hoặc đa diện Birkhoff). Bạn có thể tham khảo bài đọc tùy chọn &lt;a href=&quot;/contents/vi/chapter22/22_05_modern_applications/&quot;&gt;22-05 Ứng dụng hiện đại của Frank–Wolfe&lt;/a&gt; sau khi học xong các mục 22-02 đến 22-04; bài đọc này bổ sung bối cảnh ứng dụng và không thay thế phần phân tích hội tụ.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>22-06 Bài Tập Thực Hành - Conditional Gradient (Frank-Wolfe)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_06_Practical_Exercises_Conditional_Gradient/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_06_Practical_Exercises_Conditional_Gradient</id>
   <content type="html">&lt;p&gt;Đọc định lý hội tụ giúp ta hiểu &lt;em&gt;vì sao&lt;/em&gt; Frank–Wolfe đúng, nhưng chỉ khi tự tay viết LMO, tự tính bước tìm kiếm đường thẳng và đối chiếu sai số trên từng bài tập cụ thể, ta mới thật sự làm chủ thuật toán. Năm bài tập thực hành dưới đây được thiết kế như một phòng thí nghiệm thu nhỏ: từ quả cầu \(\ell_1\) cơ bản, sang chuẩn vết của ma trận, đến tìm kiếm đường thẳng chính xác và biến thể bước rời xa.&lt;/p&gt;

&lt;p&gt;Trước khi mở từng phần lời giải chi tiết bên dưới, hãy tự đặt bút thử giải trước — đặc biệt chú ý cách chọn đúng dấu của đỉnh LMO và cách biểu diễn tập hoạt động trong Away-Step, bởi đây là hai vị trí người học hay nhầm dấu nhất khi cài đặt thực tế.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-kỹ-năng-thực-hành-cốt-lõi-trong-bộ-bài-tập&quot;&gt;Kiến thức cần nhớ: Bốn kỹ năng thực hành cốt lõi trong bộ bài tập&lt;/h2&gt;

&lt;p&gt;Bộ bài tập này kiểm tra và rèn luyện đồng thời bốn kỹ năng tính toán thiết yếu của Chương 22:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thiết kế LMO dạng đóng (Closed-Form LMO):&lt;/strong&gt; Nhận diện nhanh đỉnh cực tiểu của \(\langle \nabla f(x), s \rangle\) trên các miền phổ biến: quả cầu \(\ell_1\) (chọn một tọa độ lớn nhất), đơn hình (chọn tọa độ nhỏ nhất), và quả cầu chuẩn vết (chọn cặp vector kỳ dị hàng đầu \(u_1 v_1^T\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính toán độ phức tạp mỗi vòng lặp:&lt;/strong&gt; So sánh định lượng giữa chi phí \(O(mn)\) của một cặp vector kỳ dị hàng đầu (power iteration) trong Frank–Wolfe với chi phí \(O(mn\min(m,n))\) của phân tích SVD đầy đủ trong phép chiếu chuẩn vết.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu 1 chiều cho Exact Line Search:&lt;/strong&gt; Với hàm mục tiêu bậc hai \(f(x) = \frac{1}{2}\|Ax - b\|_2^2\), bài toán tìm bước \(\gamma_k \in [0, 1]\) có nghiệm dạng đóng gọn gàng mà không cần vòng lặp backtracking, chỉ cần cắt ngưỡng (&lt;em&gt;clip&lt;/em&gt;) về đoạn \([0, 1]\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quản lý tập hoạt động trong Away-Step:&lt;/strong&gt; Biết cách lưu bộ trọng số \(\{\alpha_v\}\), tính giới hạn bước tối đa \(\gamma_{\max} = \alpha_{v_k} / (1 - \alpha_{v_k})\), và cập nhật lại trọng số sau cả bước tiến (FW step) lẫn bước lùi (away step).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-mẫu-tính-tay-kết-hợp-lmo-và-exact-line-search-trên-quả-cầu-ell_1&quot;&gt;Giải thích: Mẫu tính tay kết hợp LMO và Exact Line Search trên quả cầu \(\ell_1\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Để khởi động trước khi làm Bài tập 1 và Bài tập 3, hãy giải hoàn chỉnh 1 bước cho \(f(x) = \frac{1}{2}(x_1 - 0.3)^2 + \frac{1}{2}(x_2 - 0.4)^2\) trên $$C = {x \in \mathbb{R}^2 :&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\le 1}\(, xuất phát từ\)x^{(0)} = (1, 0)$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính gradient tại \(x^{(0)} = (1, 0)\):&lt;/strong&gt;
\(\nabla f(x^{(0)}) = (1 - 0.3,\; 0 - 0.4) = (0.7,\; -0.4)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác định đỉnh LMO \(s^{(0)}\) (cẩn thận dấu!):&lt;/strong&gt;
So sánh trị tuyệt đối các thành phần gradient: \(|0.7| = 0.7 &amp;gt; |-0.4| = 0.4\), nên tọa độ lớn nhất là \(i = 1\) với dấu dương.
Ta cần &lt;em&gt;cực tiểu hóa&lt;/em&gt; \(0.7 s_1 - 0.4 s_2\), nên chọn dấu &lt;strong&gt;ngược lại&lt;/strong&gt; dấu gradient: \(s^{(0)} = (-1, 0)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hướng di chuyển và khoảng cách đối ngẫu:&lt;/strong&gt;
Hướng di chuyển \(d^{(0)} = s^{(0)} - x^{(0)} = (-2, 0)\).
Khoảng cách đối ngẫu \(g(x^{(0)}) = \langle -\nabla f(x^{(0)}), d^{(0)} \rangle = (-0.7)(-2) + (0.4)(0) = 1.4 &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bước Exact Line Search trên đoạn \([0, 1]\):&lt;/strong&gt;
Vì \(f(x) = \frac{1}{2}\|x - c\|_2^2\) có Hessian bằng \(I\), nghiệm không ràng buộc là:
\(\gamma^\star = \frac{\langle -\nabla f(x^{(0)}), d^{(0)} \rangle}{\|d^{(0)}\|_2^2} = \frac{1.4}{(-2)^2 + 0^2} = \frac{1.4}{4} = 0.35.\)
Vì \(0.35 \in [0, 1]\), ta giữ nguyên \(\gamma_1 = 0.35\) và thu được:
\(x^{(1)} = (1, 0) + 0.35(-2, 0) = (0.3,\; 0).\)
Kiểm tra giá trị hàm: \(f(x^{(0)}) = \frac{1}{2}(0.49 + 0.16) = 0.325\) giảm ngay xuống \(f(x^{(1)}) = \frac{1}{2}(0 + 0.16) = 0.08\)! Ở bước tiếp theo, gradient tại \((0.3, 0)\) là \((0, -0.4)\), LMO sẽ tự động chuyển sang đỉnh \((0, 1)\) để kéo \(x_2\) lên \(0.4\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---phương-pháp-gradient-có-điều-kiện-frank-wolfe&quot;&gt;Bài Tập Thực Hành - Phương pháp Gradient có điều kiện (Frank-Wolfe)&lt;/h1&gt;

&lt;p&gt;Các bài tập dưới đây được tham khảo từ Jaggi (2013) và Lacoste-Julien &amp;amp; Jaggi (2015).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-1-frank-wolfe-cơ-bản&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Frank-Wolfe cơ bản&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét bài toán \(\min_{x \in C} f(x)\) với \(f(x) = \frac{1}{2}\|x\|^2\) và \(C = \{x : \|x\|_1 \leq 1\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bộ giải cực tiểu tuyến tính (Linear Minimization Oracle — LMO).&lt;br /&gt;
b) Thực hiện vài vòng lặp xuất phát từ \(x^{(0)} = 0\).&lt;br /&gt;
c) Nêu tốc độ hội tụ.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Bộ giải cực tiểu tuyến tính (LMO):**

$$s^{(k)} = \arg\min_{s \in C} \langle \nabla f(x^{(k)}), s \rangle = \arg\min_{\|s\|_1 \leq 1} \langle x^{(k)}, s \rangle$$

Nghiệm tối ưu là $$s = -\text{sign}(x_i^{(k)}) e_i$$ với $$i = \arg\max_j |x_j^{(k)}|$$.

**b) Các bước lặp:**

$$d^{(k)} = s^{(k)} - x^{(k)}$$

$$\gamma^{(k)} = \frac{2}{k+2}$$ (kích thước bước mặc định với chỉ số $$k = 0, 1, 2, \ldots$$)

$$x^{(k+1)} = x^{(k)} + \gamma^{(k)} d^{(k)} = (1 - \gamma^{(k)})x^{(k)} + \gamma^{(k)} s^{(k)}$$

*Vòng 0:* $$x^{(0)} = 0$$, $$\nabla f(x^{(0)}) = 0$$, chọn tùy ý một đỉnh $$s^{(0)}$$ (ví dụ $$e_1$$):

$$x^{(1)} = \frac{2}{2}e_1 = e_1$$

*Vòng 1:* $$\nabla f(e_1) = e_1$$, suy ra $$s^{(1)} = -e_1$$:

$$x^{(2)} = \frac{1}{3}e_1 + \frac{2}{3}(-e_1) = -\frac{1}{3}e_1$$

**c) Tốc độ hội tụ:**

$$f(x^{(k)}) - f^* \leq \frac{2C_f}{k+2}$$

trong đó $$C_f$$ là hằng số độ cong (curvature constant) của $$f$$ trên $$C$$ (thỏa mãn $$C_f \leq L \cdot \text{diam}(C)^2$$ với $$L$$ là hằng số Lipschitz của $$\nabla f$$).

Thuật toán đạt tốc độ hội tụ **$$O(1/k)$$**.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-không-cần-phép-chiếu-projection-free&quot;&gt;📝 &lt;strong&gt;Bài tập 2: Không cần phép chiếu (Projection-Free)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;So sánh Frank-Wolfe với Projected Gradient Descent trên hình cầu \(\ell_1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Độ phức tạp của phép chiếu \(\Pi_{\ell_1}(y)\).&lt;br /&gt;
b) Độ phức tạp của LMO.&lt;br /&gt;
c) Khi nào Frank-Wolfe có lợi thế hơn?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Phép chiếu lên hình cầu $$\ell_1$$:**

$$\Pi_{\|\cdot\|_1 \leq 1}(y) = \arg\min_{\|x\|_1 \leq 1} \|x - y\|^2$$

Thuật toán sử dụng co ngưỡng mềm với ngưỡng chọn thích nghi, có độ phức tạp $$O(n \log n)$$ nếu dùng sắp xếp (hoặc $$O(n)$$ kỳ vọng với thuật toán chọn trung vị).

**b) Bộ giải cực tiểu tuyến tính (LMO):**

$$s = \arg\min_{\|s\|_1 \leq 1} \langle g, s \rangle = -\text{sign}(g_{\max}) e_{\max}$$

Độ phức tạp: $$O(n)$$ (chỉ cần tìm phần tử có trị tuyệt đối lớn nhất).

**c) Ưu điểm của Frank-Wolfe:**

* **Với số chiều $$n$$ lớn:** Chi phí $$O(n)$$ của LMO nhẹ hơn đáng kể so với sắp xếp $$O(n \log n)$$.
* **Điểm lặp thưa:** Mỗi $$x^{(k)}$$ là tổ hợp lồi của tối đa $$k+1$$ nguyên tử.
* **Không cần tinh chỉnh bước:** Kích thước bước mặc định $$\gamma = \frac{2}{k+2}$$ đảm bảo hội tụ.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-tìm-kiếm-đường-thẳng-line-search&quot;&gt;📝 &lt;strong&gt;Bài tập 3: Tìm kiếm đường thẳng (Line Search)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Thay kích thước bước mặc định \(\gamma = \frac{2}{k+2}\) bằng tìm kiếm đường thẳng chính xác (exact line search).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Phát biểu công thức \(\gamma^* = \arg\min_{\gamma \in [0,1]} f(x + \gamma d)\).&lt;br /&gt;
b) Tính nghiệm đóng cho hàm bậc hai \(f(x) = \frac{1}{2}x^TQx - b^Tx\) (với \(Q \succ 0\)).&lt;br /&gt;
c) So sánh hội tụ.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Tìm kiếm đường thẳng chính xác:**

$$\gamma^{(k)} = \arg\min_{\gamma \in [0,1]} f(x^{(k)} + \gamma d^{(k)})$$

**b) Trường hợp hàm bậc hai:**

$$f(x + \gamma d) = \frac{1}{2}(x + \gamma d)^TQ(x + \gamma d) - b^T(x + \gamma d)$$

Đặt đạo hàm theo $$\gamma$$ bằng 0:

$$\frac{d}{d\gamma}f(x + \gamma d) = d^TQ(x + \gamma d) - b^Td = 0$$

$$\gamma^* = \frac{b^Td - x^TQd}{d^TQd} = \frac{-\nabla f(x)^T d}{d^TQd}$$

Sau đó cắt ngưỡng (clip) $$\gamma^*$$ vào đoạn $$[0, 1]$$.

**c) So sánh hội tụ:**

* **Bước mặc định $$\gamma = 2/(k+2)$$:** tốc độ $$O(1/k)$$.
* **Tìm kiếm đường thẳng chính xác:** vẫn giữ bậc $$O(1/k)$$ nhưng có hằng số tốt hơn.
* **Thực nghiệm:** Thường hội tụ nhanh hơn rõ rệt trong thực tế.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-frank-wolfe-với-bước-rời-xa-away-step-frank-wolfe&quot;&gt;📝 &lt;strong&gt;Bài tập 4: Frank-Wolfe với bước rời xa (Away-Step Frank-Wolfe)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Bổ sung bước rời xa (away step) nhằm khắc phục tốc độ hội tụ chậm gần biên.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Xác định tập hoạt động \(\mathcal{S}^{(k)}\).&lt;br /&gt;
b) Viết hướng rời xa \(d_A = x - v_A\).&lt;br /&gt;
c) Nêu quy tắc chọn giữa bước Frank-Wolfe và bước rời xa.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Tập hoạt động:**

$$x^{(k)} = \sum_{v \in \mathcal{S}^{(k)}} \alpha_v v$$ với $$\alpha_v &amp;gt; 0$$ và $$\sum_{v \in \mathcal{S}^{(k)}} \alpha_v = 1$$

(tập các đỉnh có trọng số dương trong biểu diễn tổ hợp lồi của $$x^{(k)}$$).

**b) Đỉnh rời xa và hướng rời xa:**

$$v_A = \arg\max_{v \in \mathcal{S}^{(k)}} \langle \nabla f(x^{(k)}), v \rangle$$

$$d_A = x^{(k)} - v_A$$

**c) Quy tắc chọn bước:**

$$g_{\text{FW}} = \langle \nabla f(x^{(k)}), s - x^{(k)} \rangle$$

$$g_{\text{away}} = \langle \nabla f(x^{(k)}), x^{(k)} - v_A \rangle$$

Nếu $$g_{\text{FW}} \leq g_{\text{away}}$$: chọn bước Frank-Wolfe với $$\gamma_{\max} = 1$$.  
Ngược lại: chọn bước rời xa với $$\gamma_{\max} = \frac{\alpha_{v_A}}{1 - \alpha_{v_A}}$$ (để đảm bảo trọng số của $$v_A$$ sau cập nhật không âm).

**Kết quả:** Loại bỏ được các đỉnh thừa trong tập hoạt động và cải thiện tốc độ hội tụ (đạt hội tụ tuyến tính khi $$f$$ lồi mạnh trên đa diện).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-các-ứng-dụng-tiêu-biểu&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Các ứng dụng tiêu biểu&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Nêu LMO và ưu thế của Frank-Wolfe trên:&lt;br /&gt;
a) Hình cầu chuẩn hạt nhân (nuclear norm ball): \(\|X\|_* \leq \tau\).&lt;br /&gt;
b) Đa diện ghép cặp (matching polytope).&lt;br /&gt;
c) Mô hình đồ thị xác suất (probabilistic graphical models).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Hình cầu chuẩn hạt nhân:**

*LMO:* $$S = \arg\min_{\|S\|_* \leq \tau} \langle G, S \rangle = -\tau u_1 v_1^T$$

với $$(u_1, v_1)$$ là cặp vector kỳ dị hàng đầu của $$G$$.

*Độ phức tạp:* Chi phí tìm cặp vector kỳ dị hàng đầu $$O(mn)$$ (mỗi phép nhân ma trận–vector) thấp hơn nhiều so với phân rã SVD đầy đủ $$O(m^2n)$$ cần cho phép chiếu (giả sử $$m \leq n$$).

**b) Đa diện ghép cặp:**

*LMO:* Quy về bài toán ghép cặp hoàn hảo có trọng số nhỏ nhất (minimum weight perfect matching).

*Độ phức tạp:* $$O(n^3)$$ bằng thuật toán Hungary, trong khi phép chiếu lên đa diện này khó thực hiện trực tiếp.

**c) Mô hình đồ thị xác suất:**

*LMO:* Tương đương với bài toán suy luận MAP.

*Ưu điểm:* Thuật toán vẫn làm việc được ngay cả khi bộ giải LMO chỉ tính gần đúng.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm của Frank-Wolfe:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khía cạnh&lt;/th&gt;
      &lt;th&gt;Lợi ích&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Không cần phép chiếu&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;LMO tốn \(O(n)\) thay vì phép chiếu \(O(n \log n)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Điểm lặp thưa&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tự động tạo nghiệm thưa nhờ tổ hợp lồi của ít đỉnh&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Kích thước bước đơn giản&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Quy tắc \(\gamma = 2/(k+2)\) không cần tinh chỉnh&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ràng buộc có cấu trúc&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;LMO dễ tính hơn nhiều so với phép chiếu&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Hạn chế:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tốc độ hội tụ \(O(1/k)\) chậm hơn các phương pháp có gia tốc.&lt;/li&gt;
  &lt;li&gt;Phiên bản cơ bản không tự tận dụng được tính lồi mạnh.&lt;/li&gt;
  &lt;li&gt;Có thể dao động zíc-zắc khi nghiệm nằm trên biên.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Khi nào nên dùng:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Phép chiếu lên tập ràng buộc tốn kém.&lt;/li&gt;
  &lt;li&gt;Cần nghiệm có cấu trúc thưa (tổ hợp ít nguyên tử).&lt;/li&gt;
  &lt;li&gt;Ràng buộc có cấu trúc tổ hợp hoặc ma trận (chuẩn hạt nhân, đa diện ghép cặp).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu Tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Jaggi, M. (2013). “Revisiting Frank-Wolfe: Projection-Free Sparse Convex Optimization”. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Lacoste-Julien, S., &amp;amp; Jaggi, M. (2015). “On the Global Linear Convergence of Frank-Wolfe”. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>22-04 Tính chất và các biến thể</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_04_Properties_and_variants/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_04_Properties_and_variants</id>
   <content type="html">&lt;p&gt;Nếu bạn từng chạy Frank–Wolfe tiêu chuẩn trên một đa diện và vẽ quỹ đạo điểm lặp, bạn sẽ sớm bắt gặp một cảnh tượng vừa thú vị vừa sốt ruột: khi nghiệm tối ưu \(x^\star\) nằm trên một cạnh biên thay vì ở đỉnh, thuật toán bắt đầu &lt;strong&gt;đi zíc-zắc&lt;/strong&gt; qua lại giữa hai đỉnh hai bên, bước ngày càng ngắn lại và mãi không chịu chạm đích. Đây chính là lý do định lý cổ điển của Wolfe (1970) chứng minh tốc độ \(O(1/k)\) là chặn dưới chặt — không thể cải thiện chỉ bằng cách chọn kích thước bước khéo hơn.&lt;/p&gt;

&lt;p&gt;Để phá vỡ bức tường \(O(1/k)\) và đạt hội tụ tuyến tính (nhanh theo hàm mũ \(O(e^{-\rho k})\)) cho các hàm lồi mạnh trên đa diện, cộng đồng tối ưu đã sáng tạo ra một ý tưởng cực kỳ trực giác: bên cạnh việc &lt;em&gt;bước về phía một đỉnh tốt&lt;/em&gt;, hãy cho phép thuật toán &lt;strong&gt;lùi ra xa khỏi một đỉnh xấu&lt;/strong&gt; đang còn dư âm trong tập hoạt động!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-nâng-cấp-frankwolfe&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột nâng cấp Frank–Wolfe&lt;/h2&gt;

&lt;p&gt;Bài học này mở rộng thuật toán Frank–Wolfe cơ bản sang các biến thể thực chiến thông qua bốn ý tưởng nền tảng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường thẳng và Hiệu chỉnh toàn phần (Line Search &amp;amp; Fully Corrective):&lt;/strong&gt; Thay bước cố định \(2/(k+1)\) bằng tối ưu 1 chiều theo \(\gamma \in [0, 1]\), hoặc cực tiểu hóa lại toàn bộ \(f\) trên bao lồi của tập đỉnh đã gặp. Cách này giảm hàm mục tiêu rất mạnh ở các vòng đầu, nhưng đánh đổi bằng chi phí giải bài toán con lớn hơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biểu diễn tập hoạt động và Bước rời xa (Active Set &amp;amp; Away Steps):&lt;/strong&gt; Mọi điểm lặp đều là tổ hợp lồi \(x^{(k)} = \sum_{v \in \mathcal{S}_k} \alpha_v v\) của một tập hữu hạn các đỉnh hoạt động \(\mathcal{S}_k\). Bước rời xa tìm đỉnh \(v \in \mathcal{S}_k\) kém nhất (tích vô hướng với gradient lớn nhất) rồi giảm trọng số \(\alpha_v\) — thậm chí xóa hẳn \(v\) khỏi \(\mathcal{S}_k\) (gọi là &lt;em&gt;drop step&lt;/em&gt;).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình học đa diện và Độ rộng kim tự tháp (Pyramidal Width):&lt;/strong&gt; Định lý Lacoste-Julien &amp;amp; Jaggi (2013) chứng minh Away-Step Frank–Wolfe hội tụ tuyến tính nhờ hằng số hình học của đa diện (độ rộng kim tự tháp), đảm bảo hướng di chuyển luôn tạo một góc đủ nhọn với hướng giảm gradient âm dù nghiệm nằm sát mặt biên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bám theo đường nghiệm (Path Following):&lt;/strong&gt; Khi giải họ bài toán ràng buộc với tham số \(t\) tăng dần (ví dụ chuỗi nghiệm Lasso), nghiệm của bài toán trước là điểm khởi tạo nóng (warm start) tuyệt vời cho bài toán tiếp theo, giúp giảm mạnh tổng số lần gọi LMO.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-một-bước-away-step-triệt-tiêu-đỉnh-xấu-ngay-lập-tức&quot;&gt;Giải thích: Một bước Away-Step triệt tiêu đỉnh xấu ngay lập tức&lt;/h3&gt;

&lt;p&gt;Hãy xem tại sao Away-Step lại “nhảy thẳng tới đích” ở nơi Frank–Wolfe tiêu chuẩn phải đi zíc-zắc. Xét tam giác \(C = \operatorname{conv}\{v_1=(0,0),\; v_2=(1,0),\; v_3=(0,1)\}\) và hàm mục tiêu lồi mạnh \(f(x_1, x_2) = \frac{1}{2}(x_1 - 0.5)^2 + \frac{1}{2}x_2^2\), có nghiệm tối ưu nằm trên cạnh đáy tại \(x^\star = (0.5, 0)\).&lt;/p&gt;

&lt;p&gt;Giả sử ta đang ở điểm \(x = 0.4 v_1 + 0.4 v_2 + 0.2 v_3 = (0.4,\; 0.2)\) với tập hoạt động \(\mathcal{S} = \{v_1, v_2, v_3\}\) và gradient \(\nabla f(x) = (-0.1,\; 0.2)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính hướng Frank–Wolfe tiêu chuẩn (\(d_{\text{FW}}\)):&lt;/strong&gt;
Tính \(\langle \nabla f(x), v \rangle\) tại ba đỉnh: tại \(v_1\) bằng \(0\), tại \(v_2\) bằng \(-0.1\), tại \(v_3\) bằng \(+0.2\).
Đỉnh cực tiểu là \(s_{\text{FW}} = v_2 = (1, 0)\), nên \(d_{\text{FW}} = v_2 - x = (0.6,\; -0.2)\).
Mức giảm tuyến tính: \(\langle -\nabla f(x), d_{\text{FW}} \rangle = (0.1)(0.6) + (-0.2)(-0.2) = 0.10\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hướng rời xa (\(d_{\text{away}}\)):&lt;/strong&gt;
Trong tập hoạt động \(\mathcal{S}\), đỉnh có tích vô hướng lớn nhất (tệ nhất) là \(v_{\text{away}} = v_3 = (0, 1)\) (giá trị \(+0.2\)).
Hướng rời xa là \(d_{\text{away}} = x - v_3 = (0.4,\; -0.8)\).
Mức giảm tuyến tính: \(\langle -\nabla f(x), d_{\text{away}} \rangle = (0.1)(0.4) + (-0.2)(-0.8) = -0.04 + 0.16 = 0.12\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh và thực hiện Drop Step:&lt;/strong&gt;
Vì \(0.12 &amp;gt; 0.10\), thuật toán chọn hướng rời xa \(d_{\text{away}}\)! Để giữ các trọng số tổ hợp lồi không âm, bước tối đa cho phép là \(\gamma_{\max} = \frac{\alpha_3}{1 - \alpha_3} = \frac{0.2}{0.8} = 0.25\).
Cập nhật với \(\gamma = 0.25\):
\(x^+ = (0.4,\; 0.2) + 0.25(0.4,\; -0.8) = (0.5,\; 0.0) = x^\star!\)
Đỉnh gây nhiễu \(v_3\) bị loại sạch khỏi tập hoạt động (\(\alpha_3^+ = 0\)), và thuật toán chạm đúng nghiệm tối ưu chỉ trong một nước đi — thay vì phải kéo dài hàng chục bước zíc-zắc về phía \(v_1\) và \(v_2\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;một-số-biến-thể&quot;&gt;Một số biến thể&lt;/h2&gt;

&lt;p&gt;Dưới đây là một số biến thể phổ biến của phương pháp gradient có điều kiện:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường thẳng (Line search)&lt;/strong&gt;: Thay vì dùng kích thước bước cố định \(\gamma_k=2/(k+1)\) (\(k=1,2,3,\ldots\)), ta dùng tìm kiếm đường thẳng chính xác (exact line search) tại mỗi vòng lặp:
    &lt;blockquote&gt;
\[\gamma_k = \arg\min_{\gamma\in[0,1]} f\Bigl( x^{(k−1)} + \gamma\bigl(s^{(k−1)} − x^{(k−1)} \bigr) \Bigr)\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ngoài ra cũng có thể dùng backtracking line search.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu chỉnh toàn phần (Fully corrective)&lt;/strong&gt;: Cập nhật bằng cách cực tiểu hóa trực tiếp hàm mục tiêu trên bao lồi của tất cả các đỉnh đã tìm được cho đến bước hiện tại:
    &lt;blockquote&gt;
\[x^{(k)} = \arg\min_y f(y) \: \text{ subject to } y \in \text{conv}\{ x^{(0)}, s^{(0)}, \ldots, s^{(k−1)} \}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Biến thể này thường giảm giá trị hàm mục tiêu nhanh hơn nhiều sau mỗi vòng lặp, nhưng chi phí giải bài toán con cao hơn đáng kể.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter22/away_steps.png&quot; alt=&quot;[Hình 3] Động lực của away step [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 3] Động lực của away step [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;biến-thể-bước-rời-xa-away-steps&quot;&gt;Biến thể bước rời xa (Away steps)&lt;/h2&gt;

&lt;p&gt;Để khắc phục hiện tượng hội tụ chậm (đi zíc-zắc gần biên), hãy xét bài toán cực tiểu hóa minh họa ở [Hình 3], trong đó nghiệm tối ưu là \((0, 0)\). Phương pháp Frank-Wolfe tiêu chuẩn gặp khó khăn khi rời khỏi ảnh hưởng của điểm khởi tạo \((0, 1)\). Với bước rời xa (away step), thuật toán không chỉ di chuyển về phía các đỉnh triển vọng mà còn có thể lùi ra xa khỏi các đỉnh kém triển vọng đang nằm trong tập hoạt động.&lt;/p&gt;

&lt;p&gt;Giả sử tập ràng buộc là bao lồi \(C = \text{conv}(A)\) với tập nguyên tử (atom) \(A\). Khi đó mọi điểm \(x \in C\) có thể biểu diễn tường minh dưới dạng tổ hợp lồi của các phần tử thuộc \(A\):&lt;/p&gt;
&lt;blockquote&gt;
\[x = \sum_{a\in A} \lambda_a(x) a\]
&lt;/blockquote&gt;

&lt;p&gt;Thuật toán gradient có điều kiện với bước rời xa:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Chọn \(x^{(0)} = a^{(0)} \in A\).&lt;/li&gt;
  &lt;li&gt;Với \(k = 1, 2, 3, \ldots\):
    &lt;ul&gt;
      &lt;li&gt;
\[s^{(k−1)} \in \arg\min_{a\in A} \nabla f(x^{(k−1)})^T a\]
      &lt;/li&gt;
      &lt;li&gt;
\[a^{(k−1)} \in \arg\max_{a\in A,\; \lambda_a(x^{(k−1)})&amp;gt;0} \nabla f(x^{(k−1)})^T a\]
      &lt;/li&gt;
      &lt;li&gt;Chọn hướng \(v = s^{(k−1)} − x^{(k−1)}\) (bước Frank-Wolfe) hoặc \(v = x^{(k−1)} − a^{(k−1)}\) (bước rời xa) tùy hướng nào cho độ giảm tuyến tính tốt hơn.&lt;/li&gt;
      &lt;li&gt;Cập nhật \(x^{(k)} = x^{(k−1)} + \gamma_k v\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Kết thúc khi đạt tiêu chí dừng.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;hội-tụ-tuyến-tính&quot;&gt;Hội tụ tuyến tính&lt;/h2&gt;

&lt;p&gt;Xét trước bài toán tối ưu không ràng buộc:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_x f(x) \: \text{ subject to } x \in \mathbb{R}^n\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(f\) là \(\mu\)-lồi mạnh và \(\nabla f\) là \(L\)-Lipschitz. Khi chạy gradient descent \(x^{(k+1)} = x^{(k)} − t_k\nabla f(x^{(k)})\) với \(t_k = 1/L\), ta có tốc độ hội tụ tuyến tính:&lt;/p&gt;
&lt;blockquote&gt;
\[f(x^{(k)}) − f^{\star} \leq \Bigl( 1 −\frac{\mu}{L} \Bigr)^k \bigl( f(x^{(0)}) − f^{\star} \bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;Bây giờ xét bài toán có ràng buộc trên đa diện:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_x f(x) \: \text{ subject to } x \in \text{conv}(A) \subseteq \mathbb{R}^n\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;định-lý-lacoste-julien--jaggi-2013&quot;&gt;[Định lý (Lacoste-Julien &amp;amp; Jaggi 2013)]&lt;/h3&gt;

&lt;p&gt;Giả sử \(f\) là \(\mu\)-lồi mạnh, \(\nabla f\) là \(L\)-Lipschitz và tập nguyên tử \(A \subseteq \mathbb{R}^n\) hữu hạn. Với kích thước bước \(\gamma_k\) phù hợp, thuật toán gradient có điều kiện kết hợp bước rời xa thỏa mãn:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x^{(k)}) − f^{\star} \leq (1 − r)^{k/2}(f(x^{(0)}) − f^{\star}), \qquad r = \frac{\mu}{L}\cdot\frac{\Phi(A)^2}{4\,\text{diam}(A)^2}\)
\(\text{trong đó } \Phi(A) = \min_{F \in \text{faces}(\text{conv}(A))} \text{dist}(F, \text{conv}(A \setminus F))\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nếu đa diện có hình dạng dẹt (phẳng), hằng số hình học \(\Phi(A)\) nhỏ và tốc độ hội tụ sẽ chậm lại.&lt;/p&gt;

&lt;h2 id=&quot;bám-theo-đường-nghiệm-path-following&quot;&gt;Bám theo đường nghiệm (Path following)&lt;/h2&gt;

&lt;p&gt;Xét họ bài toán ràng buộc theo chuẩn với tham số bán kính \(t \geq 0\):&lt;/p&gt;
&lt;blockquote&gt;
\[\min_x f(x) \: \text{ subject to } \| x \| \leq t\]
&lt;/blockquote&gt;

&lt;p&gt;Thuật toán Frank-Wolfe có thể dùng cho bài toán &lt;strong&gt;bám theo đường nghiệm (path following)&lt;/strong&gt;, tức sinh ra một đường nghiệm xấp xỉ \(\hat{x}(t)\) với mọi \(t \geq 0\).&lt;/p&gt;

&lt;p&gt;Khởi tạo \(t_0 = 0\) và \(x^{\star}(0) = 0\), cố định các tham số \(\epsilon &amp;gt; 0\) và \(m &amp;gt; 1\), sau đó lặp với \(k=1,2,3,\ldots\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tính \(t_k = t_{k−1} + \frac{(1 − 1/m)\epsilon}{\| \nabla f(\hat{x}(t_{k−1}))\|_{∗}}\) và giữ nguyên \(\hat{x}(t) = \hat{x}(t_{k−1})\) cho mọi \(t \in (t_{k−1}, t_k)\).&lt;/li&gt;
  &lt;li&gt;Tại \(t = t_k\), chạy Frank-Wolfe để tìm \(\hat{x}(t_k)\) và dừng khi khoảng cách đối ngẫu \(\leq \frac{\epsilon}{m}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chiến lược này giúp đơn giản hóa đáng kể các thuật toán bám đường nghiệm trước đó [Giesen et al. (2012)], đồng thời đảm bảo với mọi giá trị \(t\) trên đường đi:&lt;/p&gt;
&lt;blockquote&gt;
\[f(\hat{x}(t)) − f(x^{\star}(t)) \leq \epsilon\]
&lt;/blockquote&gt;

&lt;p&gt;tức sai số tối ưu bị chặn đều bởi \(\epsilon\) trên toàn bộ đường nghiệm.&lt;/p&gt;

&lt;p&gt;Cơ sở của đảm bảo này nằm ở dạng tuyến tính theo \(t\) của khoảng cách đối ngẫu Frank-Wolfe:&lt;/p&gt;
&lt;blockquote&gt;
\[g_t(x) = \max_{\|s\|\leq t} \nabla f(x)^T(x − s) = \nabla f(x)^Tx + t\|\nabla f(x)\|_{∗}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó, nếu tại \(t\) ta có \(g_t(x) \leq \frac{\epsilon}{m}\), thì khi tăng bán kính lên \(t^+ = t + (1 − 1/m)\epsilon/\|\nabla f(x)\|_{∗}\), ta thu được:&lt;/p&gt;

&lt;blockquote&gt;
\[g_{t^+}(x) = \nabla f(x)^Tx + t\|\nabla f(x)\|_{∗} + \epsilon − \epsilon/m \leq \epsilon\]
&lt;/blockquote&gt;

&lt;p&gt;Điều này chứng tỏ khoảng cách đối ngẫu luôn được duy trì \(\leq \epsilon\) trên toàn đoạn từ \(t\) đến \(t^+\) ngay cả khi giữ nguyên nghiệm \(x\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>22-03 Phân tích hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_03_Convergence_analysis/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_03_Convergence_analysis</id>
   <content type="html">&lt;p&gt;Một thuật toán tối ưu đẹp đến đâu cũng phải trả lời một câu hỏi lạnh lùng: &lt;em&gt;nó hội tụ nhanh cỡ nào, và điều gì quyết định tốc độ ấy?&lt;/em&gt; Ở các phương pháp gradient trước đây, tốc độ hội tụ thường phụ thuộc vào hằng số Lipschitz \(L\) của gradient đo theo chuẩn Euclid. Nhưng Frank–Wolfe lại có một đặc tính hết sức bất ngờ: nếu bạn kéo giãn hay xoay hệ tọa độ bằng một phép biến đổi tuyến tính khả nghịch, toàn bộ quỹ đạo điểm lặp của Frank–Wolfe &lt;strong&gt;không hề thay đổi&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Vì thuật toán bất biến dưới phép biến đổi affine, công cụ đo độ cong để phân tích hội tụ của nó cũng phải bất biến affine! Đó là lý do Martin Jaggi (2011) đưa ra &lt;strong&gt;hằng số độ cong \(M\)&lt;/strong&gt; dựa trên độ phân kỳ Bregman, giúp rút gọn toàn bộ chứng minh hội tụ tốc độ \(O(1/k)\) thành một bất đẳng thức duy nhất cực kỳ trong sáng.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-chứng-minh-hội-tụ-frankwolfe&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của chứng minh hội tụ Frank–Wolfe&lt;/h2&gt;

&lt;p&gt;Trước khi theo dõi từng dòng biến đổi quy nạp trong bài, hãy nắm chắc ba khái niệm làm xương sống cho chứng minh:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Độ phân kỳ Bregman và Hằng số độ cong \(M\):&lt;/strong&gt; Đại lượng \(D_f(y, x) = f(y) - f(x) - \nabla f(x)^T(y - x)\) đo khoảng cách từ hàm \(f\) tới mặt phẳng tiếp tuyến của nó tại \(x\). Hằng số \(M\) chuẩn hóa đại lượng này theo \(\gamma^2/2\) trên mọi đoạn thẳng nằm trong \(C\), nên nó vừa đo “độ cong” của \(f\), vừa đo “đường kính” của tập \(C\) — và hoàn toàn không phụ thuộc vào việc ta chọn chuẩn nào.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức giảm theo khoảng cách đối ngẫu:&lt;/strong&gt; Ở mỗi bước, mức giảm hàm mục tiêu được điều khiển bởi hai lực đối lập: lực kéo xuống \(-\gamma_k g(x^{(k-1)})\) tỉ lệ thuận với khoảng cách đối ngẫu, và sai số độ cong \(+\frac{\gamma_k^2}{2} M\). Khi \(\gamma_k\) nhỏ dần theo quy luật \(2/(k+1)\), số hạng bậc nhất luôn thắng thế số hạng bậc hai.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bất biến affine (Affine Invariance) và Độ bền với LMO xấp xỉ:&lt;/strong&gt; Không chỉ bất biến khi đổi hệ tọa độ (điểm yếu của Projected Gradient Descent khi bài toán bị kéo lệch điều kiện), khung phân tích bằng \(M\) còn cho phép LMO giải &lt;em&gt;gần đúng&lt;/em&gt; với sai số \(\delta\) mà vẫn giữ nguyên bậc hội tụ \(O(1/k)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-hằng-số-độ-cong-m-và-kiểm-chứng-bất-đẳng-thức-cơ-bản&quot;&gt;Giải thích: Tính tay hằng số độ cong \(M\) và kiểm chứng bất đẳng thức cơ bản&lt;/h3&gt;

&lt;p&gt;Hãy kiểm chứng trực tiếp từng đại lượng trong định lý hội tụ trên một bài toán 1 chiều cực kỳ trong sáng: cực tiểu hóa \(f(x) = \frac{1}{2}x^2\) trên đoạn \(C = [-1, 1]\) (nghiệm tối ưu \(x^\star = 0, f^\star = 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính chính xác hằng số độ cong \(M\):&lt;/strong&gt;
Với \(x, s \in [-1, 1]\) và \(y = x + \gamma(s - x)\), ta tính độ phân kỳ Bregman:
\(f(y) - f(x) - f&apos;(x)(y - x) = \frac{1}{2}(x + \gamma(s-x))^2 - \frac{1}{2}x^2 - x \cdot \gamma(s-x) = \frac{1}{2}\gamma^2 (s - x)^2.\)
Nhân với \(\frac{2}{\gamma^2}\), ta thu được biểu thức đơn giản \((s - x)^2\). Giá trị lớn nhất trên \([-1, 1]\) đạt tại \(s = 1, x = -1\), cho ra chính xác \(M = (1 - (-1))^2 = 4\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chạy bước \(k = 1\) từ \(x^{(0)} = 1\) với \(\gamma_1 = \frac{2}{1+1} = 1\):&lt;/strong&gt;
Ta có \(f(x^{(0)}) = 0.5\), \(f&apos;(1) = 1\), LMO chọn \(s^{(0)} = -1\), khoảng cách đối ngẫu \(g(x^{(0)}) = 1 \cdot (1 - (-1)) = 2\).
Điểm mới \(x^{(1)} = (1 - 1)(1) + 1(-1) = -1\), với \(f(x^{(1)}) = 0.5\).
Kiểm tra bất đẳng thức cơ bản:
\(f(x^{(0)}) - \gamma_1 g(x^{(0)}) + \frac{\gamma_1^2}{2} M = 0.5 - 1 \cdot 2 + \frac{1}{2} \cdot 4 = 0.5 = f(x^{(1)}).\)
Dấu bằng xảy ra tuyệt đối!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chạy bước \(k = 2\) với \(\gamma_2 = \frac{2}{2+1} = \frac{2}{3}\):&lt;/strong&gt;
Tại \(x^{(1)} = -1\), ta có \(f&apos;(-1) = -1\), LMO chọn \(s^{(1)} = 1\), khoảng cách đối ngẫu \(g(x^{(1)}) = (-1)(-1 - 1) = 2\).
Điểm mới: \(x^{(2)} = \left(1 - \frac{2}{3}\right)(-1) + \frac{2}{3}(1) = \frac{1}{3}\), nên \(f(x^{(2)}) = \frac{1}{18} \approx 0.0556\).
Kiểm tra bất đẳng thức cơ bản và cận định lý:
    &lt;ul&gt;
      &lt;li&gt;Vế phải bất đẳng thức cơ bản: \(0.5 - \frac{2}{3}(2) + \frac{(2/3)^2}{2}(4) = 0.5 - \frac{4}{3} + \frac{8}{9} = \frac{1}{18} = f(x^{(2)})\).&lt;/li&gt;
      &lt;li&gt;Cận lý thuyết từ định lý: \(f(x^{(2)}) - f^\star = \frac{1}{18} \le \frac{2M}{2 + 2} = \frac{8}{4} = 2\) — hoàn toàn nhất quán!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;phân-tích-hội-tụ&quot;&gt;Phân tích hội tụ&lt;/h2&gt;

&lt;p&gt;Để phân tích tốc độ hội tụ của thuật toán Frank-Wolfe, trước hết ta định nghĩa hằng số độ cong (curvature constant) của hàm \(f\) trên tập \(C\) [Jaggi (2011)]:&lt;/p&gt;
&lt;blockquote&gt;
\[M = \max_{x,s,y\in C,\; y = (1−\gamma)x+\gamma s,\; \gamma \in [0, 1]} \frac{2}{\gamma^2} \Bigl( f(y) − f(x) − \nabla f(x)^T(y − x) \Bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;Hằng số \(M\) đo mức độ sai lệch của hàm \(f\) so với xấp xỉ tuyến tính của nó trên \(C\); chẳng hạn \(M = 0\) khi \(f\) là hàm tuyến tính. Đại lượng \(f(y) - f(x) - \nabla f(x)^T(y - x)\) chính là độ phân kỳ Bregman (Bregman divergence) sinh bởi \(f\).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; Phương pháp gradient có điều kiện với kích thước bước cố định \(\gamma_k = 2 / (k + 1)\) (\(k = 1, 2, 3, \ldots\)) thỏa mãn:
\(f(x^{(k)}) − f^{\star} \leq \frac{2M}{k + 2}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Do đó, số vòng lặp cần thiết để đạt sai số \(f(x^{(k)}) − f^{\star} \leq \epsilon\) là \(O(1/\epsilon)\).&lt;/p&gt;

&lt;p&gt;Ta sẽ chứng minh định lý này bằng quy nạp dựa trên một bất đẳng thức cơ bản dưới đây.&lt;/p&gt;

&lt;h2 id=&quot;bất-đẳng-thức-cơ-bản&quot;&gt;Bất đẳng thức cơ bản&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bất đẳng thức then chốt&lt;/strong&gt; dùng trong chứng minh hội tụ của Frank-Wolfe là:&lt;/p&gt;
&lt;blockquote&gt;
\[f(x^{(k)}) \leq f(x^{(k−1)}) − \gamma_k g(x^{(k−1)}) + \frac{\gamma^2_k}{2}M\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(g(x) = \max_{s\in C} \nabla f(x)^T(x − s)\) là khoảng cách đối ngẫu đã giới thiệu ở bài trước.&lt;/p&gt;

&lt;h3 id=&quot;chứng-minh&quot;&gt;[Chứng minh]&lt;/h3&gt;

&lt;p&gt;Đặt \(x^+ = x^{(k)}, x = x^{(k−1)}, s = s^{(k−1)}, \gamma = \gamma_k\). Khi đó:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^+) &amp;amp;= f\bigl( x + \gamma(s − x) \bigr) \\\\
&amp;amp;\leq f(x) + \gamma\nabla f(x)^T(s − x) + \frac{\gamma^2}{2}M \\\\
&amp;amp;= f(x) − \gamma g(x) + \frac{\gamma^2}{2}M
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây, bất đẳng thức thứ hai suy trực tiếp từ định nghĩa của \(M\) và đẳng thức thứ ba suy từ định nghĩa của \(g(x)\).&lt;/p&gt;

&lt;p&gt;Bây giờ, ta dùng bất đẳng thức cơ bản để chứng minh định lý bằng quy nạp.&lt;/p&gt;

&lt;p&gt;Với \(k=1\), định lý dễ dàng kiểm tra là đúng (khi \(\gamma_1 = 1\), ta có \(f(x^{(1)}) - f^\star \leq f(x^{(0)}) - f^\star - g(x^{(0)}) + \frac{M}{2} \leq \frac{M}{2} \leq \frac{2M}{3}\)).&lt;br /&gt;
Với \(k &amp;gt; 1\), giả sử theo giả thiết quy nạp rằng \(f(x^{(k−1)}) − f^{\star} \leq 2M/(k + 1)\).&lt;/p&gt;

&lt;p&gt;Nhắc lại hai quan hệ:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(g(x^{(k−1)}) \geq f(x^{(k−1)}) − f^{\star}\)
\(\gamma_k = 2/(k + 1)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Áp dụng bất đẳng thức cơ bản:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x^{(k)}) \leq f(x^{(k−1)}) − \frac{2}{k + 1}\bigl(f(x^{(k−1)}) − f^{\star}\bigr) + \frac{2M}{(k + 1)^2}\)
\(f(x^{(k)}) − f^{\star} \leq \Bigl(1 − \frac{2}{k + 1}\Bigr)\bigl(f(x^{(k−1)}) − f^{\star}\bigr) + \frac{2M}{(k + 1)^2}\)
\(f(x^{(k)}) − f^{\star} \leq \frac{k − 1}{k + 1} \cdot \frac{2M}{k + 1} + \frac{2M}{(k + 1)^2} = \frac{2Mk}{(k + 1)^2} \leq \frac{2M}{k + 2}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(Bất đẳng thức trên dùng \(g(x) \geq f(x) − f^{\star}\) nên \(-\gamma_k g(x^{(k-1)}) \leq -\gamma_k (f(x^{(k-1)}) - f^{\star})\), và bất đẳng thức cuối đúng vì \(k(k+2) = k^2 + 2k \leq (k+1)^2\).)&lt;/p&gt;

&lt;p&gt;Tốc độ hội tụ \(O(1/k)\) này trùng với tốc độ của projected gradient descent khi \(\nabla f\) liên tục Lipschitz.&lt;/p&gt;

&lt;p&gt;Hãy so sánh giả thiết của hai phương pháp. Nếu \(\nabla f\) là \(L\)-Lipschitz thì \(M \leq \text{diam}^2(C) \cdot L\), trong đó \(\text{diam}^2(C) = \max_{x,s\in C} \|x − s\|_2^2\). Thật vậy, tính chất \(L\)-Lipschitz của \(\nabla f\) cho:&lt;/p&gt;
&lt;blockquote&gt;
\[f(y) − f(x) − \nabla f(x)^T(y − x) \leq \frac{L}{2} \| y − x \|^2_2\]
&lt;/blockquote&gt;

&lt;p&gt;Thay \(y = (1-\gamma) x + \gamma s\), nhân cả hai vế với \(\frac{2}{\gamma^2}\) và lấy cực đại trên \(C\):&lt;/p&gt;
&lt;blockquote&gt;
\[M \leq \max_{x,s,y\in C,\; y=(1−\gamma)x+\gamma s} \frac{2}{\gamma^2}\cdot\frac{L}{2} \| y − x \|^2_2 = \max_{x,s\in C} L \| x − s \|^2_2\]
&lt;/blockquote&gt;

&lt;p&gt;Như vậy, điều kiện hằng số độ cong \(M\) bị chặn không mạnh hơn giả thiết độ trơn Lipschitz dùng trong proximal gradient descent.&lt;/p&gt;

&lt;h2 id=&quot;tính-bất-biến-affine&quot;&gt;Tính bất biến affine&lt;/h2&gt;

&lt;p&gt;Nhắc lại hai phương pháp đã học:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Gradient descent: \(x^+ = x − t\nabla f(x)\)&lt;/li&gt;
  &lt;li&gt;Phương pháp Newton thuần túy: \(x^+ = x − \nabla^2f(x)^{−1}\nabla f(x)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Gradient descent không bất biến affine (affine invariant), tức tốc độ hội tụ của nó thay đổi khi ta co giãn hệ tọa độ. Ngược lại, phương pháp Newton bất biến affine — hoạt động như nhau dưới mọi phép biến đổi tuyến tính khả nghịch của biến.&lt;/p&gt;

&lt;p&gt;Phương pháp gradient có điều kiện (Frank-Wolfe) là phương pháp bậc nhất nhưng lại có &lt;strong&gt;tính bất biến affine&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Xét một ma trận khả nghịch \(A : \mathbb{R}^n \to \mathbb{R}^n\) và đặt phép đổi biến \(x = Ax&apos;,\; h(x&apos;) = f(Ax&apos;)\). Khi áp dụng Frank-Wolfe cho \(h(x&apos;)\) trên tập \(A^{-1}C\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{array}{rcl}
s&apos; &amp;amp; = &amp;amp; \arg\min_{z\in A^{−1}C} \nabla h(x&apos;)^Tz \\\\
(x&apos;)^+ &amp;amp; = &amp;amp; (1 − \gamma)x&apos; + \gamma s&apos;
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Nhân hai vế với \(A\) ta thu được chính xác bước cập nhật Frank-Wolfe trên \(f(x)\) và tập \(C\). Hơn nữa, ngay cả phân tích hội tụ cũng bất biến affine vì hằng số độ cong \(M\) của \(h\):&lt;/p&gt;
&lt;blockquote&gt;
\[M = \max_{x&apos;,s&apos;,y&apos;\in A^{−1}C,\; y&apos;=(1−\gamma)x&apos;+\gamma s&apos;} \frac{2}{\gamma^2} \Bigl( h(y&apos;) − h(x&apos;) − \nabla h(x&apos;)^T(y&apos; − x&apos;) \Bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;bằng đúng hằng số độ cong của \(f\) do \(\nabla h(x&apos;)^T(y&apos; − x&apos;) = \nabla f(x)^T(y − x)\).&lt;/p&gt;

&lt;p&gt;Tuy nhiên, tính bất biến affine không thể hiện rõ trong cận trên:&lt;/p&gt;
&lt;blockquote&gt;
\[M \leq \max_{x,s\in C} L\|x − s\|^2_2\]
&lt;/blockquote&gt;

&lt;p&gt;vì đường kính của tập \(C\) (theo chuẩn Euclid) không bất biến affine.&lt;/p&gt;

&lt;h2 id=&quot;cập-nhật-không-chính-xác&quot;&gt;Cập nhật không chính xác&lt;/h2&gt;

&lt;p&gt;Trường hợp bài toán con tuyến tính được giải gần đúng cũng đã được phân tích trong [Jaggi (2011)]. Giả sử tại bước \(k\), ta chọn \(s^{(k−1)} \in C\) sao cho:&lt;/p&gt;
&lt;blockquote&gt;
\[\nabla f(x^{(k−1)})^Ts^{(k−1)} \leq \min_{s\in C} \nabla f(x^{(k−1)})^Ts + \frac{M\gamma_k}{2} \cdot \delta\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\delta \geq 0\) là tham số sai số. Khi đó tốc độ hội tụ thu được là:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; Phương pháp gradient có điều kiện với kích thước bước cố định \(\gamma_k=2/(k+1)\) (\(k=1,2,3,\ldots\)) và tham số sai số \(\delta \geq 0\) thỏa mãn:
\(f(x^{(k)}) − f^{\star} \leq \frac{2M}{k + 2} (1 + \delta)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Lưu ý rằng ngưỡng sai số cho phép ở bước \(k\) là \(\frac{M\gamma_k}{2} \cdot \delta\). Vì \(\gamma_k \to 0\), yêu cầu về độ chính xác của bộ giải bài toán con cần siết chặt dần theo thời gian.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>22-02 Phương pháp gradient có điều kiện</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_02_Conditional_gradient_method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_02_Conditional_gradient_method</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng bạn đang đứng trong một căn phòng đa giác lồi và muốn tìm điểm thấp nhất của một mặt sàn cong mềm mại. Phương pháp Projected Gradient Descent (PGD) bảo bạn cứ bước thẳng xuống dốc; nếu lỡ đâm xuyên ra ngoài tường, hãy tìm điểm gần nhất trên tường để kéo mình quay lại. Nghe rất hợp lý — cho đến khi căn phòng là một quả cầu chuẩn vết của ma trận \(10{,}000 \times 10{,}000\), nơi việc “tìm điểm gần nhất trên tường” tốn hàng giờ tính toán mỗi bước.&lt;/p&gt;

&lt;p&gt;Phương pháp &lt;strong&gt;gradient có điều kiện (Frank–Wolfe)&lt;/strong&gt; đảo ngược hoàn toàn tư duy đó: thay vì bước ra ngoài rồi chiếu vào trong, ta đứng nguyên trong phòng, nhìn theo hướng dốc xuống mạnh nhất, chọn &lt;strong&gt;góc tường&lt;/strong&gt; nằm xa nhất theo hướng đó, rồi bước một đoạn thẳng về phía góc tường ấy. Không bao giờ ra khỏi miền khả thi, không bao giờ cần phép chiếu, và mỗi bước chỉ thêm đúng một “nguyên tử” cấu trúc vào nghiệm.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-cốt-lõi-của-bài-học&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép cốt lõi của bài học&lt;/h2&gt;

&lt;p&gt;Bài học này đặt nền móng cho toàn bộ Chương 22 thông qua bốn trụ cột liên kết chặt chẽ:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn đối ngẫu (Dual Norm) và Bộ giải LMO:&lt;/strong&gt; Với ràng buộc dạng chuẩn \(\|x\| \le t\), bài toán tuyến tính \(\min_{\|s\| \le t} \nabla f(x)^T s\) có liên hệ trực tiếp với chuẩn đối ngẫu \(\|\nabla f(x)\|_* = \max_{\|s\| \le 1} \nabla f(x)^T s\). Vì chuẩn đối ngẫu của \(\ell_1\) là \(\ell_\infty\) và của chuẩn vết là chuẩn phổ, LMO rút gọn thành thao tác cực rẻ: tìm phần tử lớn nhất hoặc cặp vector kỳ dị hàng đầu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính thưa và Hạng thấp tự nhiên (Implicit Sparsity &amp;amp; Low-Rank):&lt;/strong&gt; Vì \(x^{(k)}\) là tổ hợp lồi của điểm khởi tạo và các đỉnh \(s^{(0)}, \dots, s^{(k-1)}\), sau \(k\) bước, nghiệm của Frank–Wolfe trên quả cầu \(\ell_1\) có nhiều nhất \(k\) tọa độ khác \(0\) (nếu khởi tạo từ \(0\)), và trên quả cầu chuẩn vết có hạng không vượt quá \(k\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tương đương giữa dạng ràng buộc và dạng Lagrange:&lt;/strong&gt; Trong thống kê và học máy, bài toán \(\min_{\|x\| \le t} f(x)\) (dạng ràng buộc dùng cho Frank–Wolfe) và \(\min_x f(x) + \lambda \|x\|\) (dạng phạt Lagrange dùng cho Proximal Gradient) sinh ra cùng một họ nghiệm tối ưu khi tham số \(t\) và \(\lambda\) biến thiên tương ứng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu (Duality Gap):&lt;/strong&gt; Đại lượng \(g(x) = \max_{s \in C} \nabla f(x)^T (x - s)\) luôn lớn hơn hoặc bằng \(f(x) - f^\star\) nhờ tính lồi bậc nhất của \(f\). Nó vừa là chứng chỉ dừng chính xác, vừa là đại lượng trung tâm trong chứng minh hội tụ ở bài sau.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-frankwolfe-trên-quả-cầu-ell_1-và-kiểm-tra-khoảng-cách-đối-ngẫu&quot;&gt;Giải thích: Tính tay Frank–Wolfe trên quả cầu \(\ell_1\) và kiểm tra khoảng cách đối ngẫu&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét bài toán cực tiểu hóa \(f(x_1, x_2) = \frac{1}{2}(x_1 - 2)^2 + \frac{1}{2}(x_2 - 0.5)^2\) trên quả cầu \(\ell_1\) đơn vị $$C = {(x_1, x_2) :&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\le 1}\(, khởi tạo từ\)x^{(0)} = (0, 0)$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính gradient tại \(x^{(0)} = (0, 0)\):&lt;/strong&gt;
\(\nabla f(0, 0) = (-2,\; -0.5)\). Giá trị hàm mục tiêu ban đầu là \(f(0, 0) = \frac{1}{2}(4 + 0.25) = 2.125\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải LMO trên quả cầu \(\ell_1\):&lt;/strong&gt;
Ta cần cực tiểu hóa \(-2s_1 - 0.5s_2\) với \(|s_1| + |s_2| \le 1\). Quy tắc chuẩn \(\ell_1\) chỉ ra ngay: tìm tọa độ có trị tuyệt đối gradient lớn nhất (ở đây \(|-2| = 2 &amp;gt; |-0.5|\), tức tọa độ \(i = 1\)) và gán dấu ngược lại: \(s^{(0)} = (1, 0)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính khoảng cách đối ngẫu tại \(x^{(0)}\):&lt;/strong&gt;
\(g(x^{(0)}) = \nabla f(x^{(0)})^T (x^{(0)} - s^{(0)}) = (-2)(0 - 1) + (-0.5)(0 - 0) = 2\).
Điều này đảm bảo ngay lập tức rằng \(f(x^{(0)}) - f^\star \le 2\), tức \(f^\star \ge 2.125 - 2 = 0.125\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật bước \(k = 1\) với \(\gamma_1 = \frac{2}{1 + 1} = 1\):&lt;/strong&gt;
\(x^{(1)} = (1 - 1)(0, 0) + 1 \cdot (1, 0) = (1, 0)\), thu được \(f(x^{(1)}) = \frac{1}{2}(1 - 2)^2 + \frac{1}{2}(0 - 0.5)^2 = 0.625\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện dừng tại \(x^{(1)} = (1, 0)\):&lt;/strong&gt;
Ta có \(\nabla f(1, 0) = (-1,\; -0.5)\). Tọa độ có trị tuyệt đối gradient lớn nhất vẫn là \(i = 1\) (\(|-1| = 1 &amp;gt; |-0.5|\)), nên LMO lại trả về \(s^{(1)} = (1, 0)\). Khoảng cách đối ngẫu lúc này là:
\(g(x^{(1)}) = \nabla f(x^{(1)})^T (x^{(1)} - s^{(1)}) = 0.\)
Vì \(0 \le f(x^{(1)}) - f^\star \le g(x^{(1)}) = 0\), ta khẳng định chắc chắn \(x^\star = (1, 0)\) là nghiệm tối ưu toàn cục — đồng thời thấy rõ tính thưa (chỉ có 1 tọa độ khác 0) được bảo toàn tuyệt đối!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;gradient-descent-có-chiếu-projected-gradient-descent&quot;&gt;Gradient descent có chiếu (Projected Gradient Descent)&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối ưu có ràng buộc sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} f(x) \qquad \text{ thỏa mãn } x \in C\]
&lt;/blockquote&gt;

&lt;p&gt;Như đã biết, nếu \(f\) là hàm lồi, trơn và tập \(C\) là tập lồi, ta có thể dùng phương pháp &lt;strong&gt;gradient descent có chiếu (projected gradient descent)&lt;/strong&gt;. Gọi \(P_{C}\) là toán tử chiếu lên tập \(C\); khởi tạo \(x^{(0)}\) và lặp với \(k = 1, 2, 3, \ldots\):&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = P_{C} \bigl( x^{(k−1)} − t_k\nabla f(x^{(k−1)}) \bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;Phương pháp này cũng là một trường hợp đặc biệt của proximal gradient descent, trong đó bước tiếp theo \(x^{(k)}\) thu được bằng cách chiếu điểm cực tiểu của xấp xỉ bậc hai cục bộ (khai triển Taylor bậc hai) lên tập \(C\):&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = P_{C} \Bigl( \arg\min_{y} \nabla f(x^{(k−1)})^T(y − x^{(k−1)}) + \frac{1}{2t} \| y − x^{(k−1)} \|^2_2 \Bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;Xem thêm chi tiết về Projected Gradient Descent tại &lt;a href=&quot;/contents/vi/chapter09/09_04_special_cases/&quot;&gt;9-4&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-gradient-có-điều-kiện-frank-wolfe&quot;&gt;Phương pháp gradient có điều kiện (Frank-Wolfe)&lt;/h2&gt;

&lt;p&gt;Thay vì cực tiểu hóa xấp xỉ bậc hai rồi thực hiện phép chiếu, ta xét một cách tiếp cận đơn giản hơn: cực tiểu hóa trực tiếp xấp xỉ bậc nhất (hàm tuyến tính) của \(f\) trên tập ràng buộc \(C\), sau đó cập nhật điểm mới bằng tổ hợp lồi giữa điểm hiện tại và điểm cực tiểu vừa tìm được.&lt;/p&gt;

&lt;p&gt;Cụ thể, chọn điểm khởi tạo \(x^{(0)} \in C\). Với \(k = 1, 2, 3, \ldots\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{array}{rcl}
s^{(k−1)} &amp;amp; \in &amp;amp; \arg\min_{s \in C} \nabla f(x^{(k−1)})^Ts \\
x^{(k)} &amp;amp; = &amp;amp; (1 − \gamma_k)x^{(k−1)} + \gamma_ks^{(k−1)}
\end{array}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;tham-khảo&quot;&gt;[Tham khảo]&lt;/h3&gt;

&lt;blockquote&gt;
\[f(y) \approx f(x) + \nabla f(x)^T(y-x)\]

\[\arg\min_y \bigl(f(x) + \nabla f(x)^T(y-x)\bigr) \equiv \arg\min_y \nabla f(x)^T y\]
&lt;/blockquote&gt;

&lt;p&gt;Khác với phương pháp có chiếu, thuật toán này không cần thực hiện phép chiếu mà luôn làm việc trực tiếp trên các điểm thuộc \(C\). Kích thước bước mặc định thường chọn là \(\gamma_k = \frac{2}{k + 1}\) với \(k = 1, 2, 3, \ldots\) Vì \(0 \leq \gamma_k \leq 1\) và \(C\) là tập lồi, mọi điểm lặp đều tự động thỏa mãn \(x^{(k)} \in C\). Bước cập nhật cũng có thể viết dưới dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = x^{(k−1)} + \gamma_k\bigl( s^{(k−1)} − x^{(k−1)} \bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;Nghĩa là khi số vòng lặp tăng lên, bước di chuyển về phía điểm cực tiểu tuyến tính nhỏ dần. Trong nhiều bài toán, chẳng hạn tối ưu trên hình cầu \(\ell_1\), bước giải tuyến tính này đơn giản hơn nhiều so với bước chiếu.&lt;/p&gt;

&lt;h3 id=&quot;tham-khảo-1&quot;&gt;[Tham khảo]&lt;/h3&gt;

&lt;p&gt;Một chi tiết lịch sử thú vị là Marguerite Frank và Philip Wolfe từng là nghiên cứu sinh sau tiến sĩ làm việc cùng Albert Tucker. Hai ông bà công bố thuật toán này vào năm 1956. Sau một thời gian dài ít được chú ý, thuật toán Frank-Wolfe đã được quan tâm trở lại rộng rãi trong học máy nhờ các phân tích và mở rộng của Martin Jaggi.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter22/frank_wolfe.png&quot; alt=&quot;[Hình 1] Phương pháp gradient có điều kiện (Frank-Wolfe) (Jaggi 2011)[3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Phương pháp gradient có điều kiện (Frank-Wolfe) (Jaggi 2011)[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;ràng-buộc-chuẩn&quot;&gt;Ràng buộc chuẩn&lt;/h2&gt;

&lt;p&gt;Xét trường hợp tập ràng buộc là hình cầu chuẩn \(C = \{x : \| x \| \leq t \}\) với một chuẩn \(\| \cdot \|\) bất kỳ. Khi đó:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
s &amp;amp;\in \arg\min_{\|s\|\leq t} \nabla f(x^{(k−1)})^Ts \\
&amp;amp;= −t \cdot \arg\max_{\|s\|\leq 1} \nabla f(x^{(k−1)})^Ts \\
&amp;amp;= −t \cdot \partial \| \nabla f(x^{(k−1)}) \|_{*}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\| \cdot \|_{*}\) là chuẩn đối ngẫu của \(\| \cdot \|\). Như vậy, chỉ cần tính được một dưới đạo hàm của chuẩn đối ngẫu là ta thực hiện được bước Frank-Wolfe. Lợi thế chính của Frank-Wolfe trên \(C = \{x : \| x \| \leq t \}\) là bước này thường đơn giản và ít tốn kém hơn đáng kể so với phép chiếu lên \(C\) hoặc toán tử proximal của \(\| \cdot \|\).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-chính-quy-hóa-l_1&quot;&gt;Ví dụ: chính quy hóa \(l_1\)&lt;/h2&gt;

&lt;p&gt;Xét bài toán &lt;strong&gt;chính quy hóa \(l_1\)&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) \qquad \text{ thỏa mãn } \| x \|_1 \leq t\]
&lt;/blockquote&gt;

&lt;p&gt;Áp dụng công thức trên với chuẩn đối ngẫu là chuẩn \(l_\infty\), ta có \(s^{(k−1)} \in −t\partial \|\nabla f(x^{(k−1)}) \|_\infty\). Bước cập nhật Frank-Wolfe trở thành:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{array}{rcl}
i_{k−1} &amp;amp; \in &amp;amp; \arg\max_{i=1,...,p} |\nabla_i f(x^{(k−1)})| \\
x^{(k)} &amp;amp; = &amp;amp; (1 − \gamma_k)x^{(k−1)} − \gamma_kt \cdot \text{sign}(\nabla_{i_{k−1}} f(x^{(k−1)})) \cdot e_{i_{k−1}}
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Cách cập nhật này có dạng tương đồng với phương pháp hạ tọa độ (coordinate descent, sẽ trình bày chi tiết ở chương sau).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý&lt;/strong&gt;: Cả hai phương pháp đều có thể thực hiện trong độ phức tạp \(O(n)\), nhưng bước cập nhật Frank-Wolfe đơn giản hơn nhiều so với phép chiếu lên hình cầu \(l_1\).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-chính-quy-hóa-l_p&quot;&gt;Ví dụ: chính quy hóa \(l_p\)&lt;/h2&gt;

&lt;p&gt;Xét bài toán chính quy hóa \(l_p\):&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} f(x) \qquad \text{ thỏa mãn } \| x \|_{p} \leq t\]
&lt;/blockquote&gt;

&lt;p&gt;Với \(1 \leq p \leq \infty\) và \(q\) là số mũ liên hợp của \(p\) (thỏa mãn \(1/p + 1/q = 1\)), ta có \(s^{(k−1)} \in −t\partial \| \nabla f(x^{(k−1)}) \|_{q}\). Ta có thể chọn tường minh:&lt;/p&gt;

&lt;blockquote&gt;
\[s_i^{(k−1)} = −\alpha \cdot \text{sign}(\nabla f_i(x^{(k−1)})) \cdot \left| \nabla f_i(x^{(k−1)}) \right|^{q-1}, \quad i = 1, \ldots, n\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\alpha\) là hằng số chuẩn hóa sao cho \(\| s^{(k−1)} \|_{p} = t\), sau đó thực hiện bước tổ hợp lồi Frank-Wolfe như bình thường.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý&lt;/strong&gt;: Với \(p\) tổng quát, bước cập nhật Frank-Wolfe đơn giản hơn rất nhiều so với &lt;strong&gt;phép chiếu lên hình cầu \(l_p\)&lt;/strong&gt;. Ngoại trừ các trường hợp đặc biệt (\(p = 1, 2, \infty\)), phép chiếu lên hình cầu \(l_p\) không có công thức dạng đóng mà phải giải một bài toán tối ưu con riêng.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-chính-quy-hóa-chuẩn-vết-trace-norm&quot;&gt;Ví dụ: chính quy hóa chuẩn vết (trace norm)&lt;/h2&gt;

&lt;p&gt;Xét bài toán &lt;strong&gt;chính quy hóa chuẩn vết&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{X} f(X) \qquad \text{ thỏa mãn } \| X \|_{tr} \leq t\]
&lt;/blockquote&gt;

&lt;p&gt;Chuẩn đối ngẫu của chuẩn vết là chuẩn toán tử \(\|\cdot\|_{op}\), nên \(S^{(k−1)} \in −t \cdot \partial\| \nabla f(X^{(k−1)}) \|_{op}\). Ta có thể chọn:&lt;/p&gt;

&lt;blockquote&gt;
\[S^{(k−1)} = −t \cdot uv^T\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(u, v\) là cặp vector kỳ dị trái và phải ứng với giá trị kỳ dị lớn nhất của \(\nabla f(X^{(k−1)})\), rồi cập nhật Frank-Wolfe như thường lệ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý&lt;/strong&gt;: Vì chỉ cần tìm cặp vector kỳ dị hàng đầu thay vì phân rã SVD đầy đủ, bước Frank-Wolfe đơn giản và hiệu quả hơn nhiều so với &lt;strong&gt;phép chiếu lên hình cầu chuẩn vết&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;dạng-ràng-buộc-và-dạng-lagrange&quot;&gt;Dạng ràng buộc và dạng Lagrange&lt;/h2&gt;

&lt;p&gt;Xét lại bài toán dạng ràng buộc:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) \qquad \text{ thỏa mãn } \| x \| \leq t\]
&lt;/blockquote&gt;

&lt;p&gt;và bài toán dạng Lagrange tương đương:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) + \lambda \| x \|\]
&lt;/blockquote&gt;

&lt;p&gt;khi các tham số điều chỉnh \(t\) và \(\lambda\) biến thiên trong \([0,\infty)\). Ta có thể so sánh chi phí giữa bước cập nhật Frank-Wolfe và toán tử proximal của chuẩn \(\| \cdot \|\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn \(l_1\)&lt;/strong&gt;: Frank-Wolfe chỉ cần quét tìm thành phần có trị tuyệt đối lớn nhất của gradient, còn toán tử proximal dùng co ngưỡng mềm (soft-thresholding). Cả hai đều tốn \(O(n)\) phép tính.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn \(l_p\)&lt;/strong&gt;: Frank-Wolfe chỉ cần lũy thừa từng thành phần của gradient rồi chuẩn hóa với chi phí \(O(n)\) phép tính, trong khi toán tử proximal nhìn chung không có công thức đóng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn vết&lt;/strong&gt;: Frank-Wolfe chỉ cần tìm cặp vector kỳ dị hàng đầu của gradient, còn toán tử proximal phải co ngưỡng mềm toàn bộ các giá trị kỳ dị, đòi hỏi phân rã SVD đầy đủ.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ngoài ra, nhiều bộ chính quy hóa khác cũng có bước Frank-Wolfe hiệu quả, chẳng hạn các ràng buộc đa diện hay nón đặc biệt, chính quy hóa tổng các chuẩn theo nhóm, chuẩn nguyên tử (atomic norm), v.v.&lt;/p&gt;

&lt;p&gt;[Hình 2] so sánh hiệu năng giữa projected gradient và conditional gradient trên bài toán Lasso có ràng buộc (\(n=100, p = 500\)):&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter22/comparing_projected_and_conditional_gradient.png&quot; alt=&quot;[Hình 2] So sánh gradient có chiếu và gradient có điều kiện cho bài lasso có ràng buộc [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] So sánh gradient có chiếu và gradient có điều kiện cho bài lasso có ràng buộc [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Quan sát cho thấy Frank-Wolfe có tốc độ hội tụ tương đồng với các phương pháp bậc nhất ở giai đoạn đầu, nhưng thường hội tụ chậm hơn khi cần độ chính xác cao. (Lưu ý rằng thí nghiệm trên dùng kích thước bước cố định; sử dụng tìm kiếm đường thẳng — line search — có thể cải thiện tốc độ hội tụ.)&lt;/p&gt;

&lt;h2 id=&quot;khoảng-cách-đối-ngẫu-duality-gap&quot;&gt;Khoảng cách đối ngẫu (Duality gap)&lt;/h2&gt;

&lt;p&gt;Một ưu điểm tự nhiên của quá trình lặp Frank-Wolfe là nó cung cấp trực tiếp một khoảng cách đối ngẫu, đóng vai trò cận trên cho sai số tối ưu (suboptimality gap):&lt;/p&gt;

&lt;blockquote&gt;
\[g(x^{(k-1)}) := \max_{s\in C} \nabla f(x^{(k−1)})^T(x^{(k−1)} − s)\]
&lt;/blockquote&gt;

&lt;p&gt;Đại lượng này luôn thỏa mãn \(f(x^{(k−1)}) − f^{*} \leq g(x^{(k-1)})\).&lt;/p&gt;

&lt;h3 id=&quot;chứng-minh&quot;&gt;[Chứng minh]&lt;/h3&gt;

&lt;p&gt;Theo điều kiện bậc nhất của hàm lồi:&lt;/p&gt;

&lt;blockquote&gt;
\[f(s) \geq f(x^{(k−1)}) + \nabla f(x^{(k−1)})^T(s − x^{(k−1)})\]
&lt;/blockquote&gt;

&lt;p&gt;Lấy cực tiểu cả hai vế theo mọi \(s \in C\):&lt;/p&gt;

&lt;blockquote&gt;
\[f^{*} \geq f(x^{(k−1)}) + \min_{s\in C} \nabla f(x^{(k−1)})^T(s − x^{(k−1)})\]
&lt;/blockquote&gt;

&lt;p&gt;Chuyển vế, ta thu được cận trên của sai số tối ưu:&lt;/p&gt;

&lt;blockquote&gt;
\[f(x^{(k−1)}) - f^{*} \leq \max_{s\in C} \nabla f(x^{(k−1)})^T(x^{(k−1)} − s) = \nabla f(x^{(k−1)})^T(x^{(k−1)} − s^{(k−1)})\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;ghi-chú&quot;&gt;[Ghi chú]&lt;/h3&gt;

&lt;p&gt;Như vậy, cận trên này thu được miễn phí ngay từ bước cập nhật Frank-Wolfe. Để thấy vì sao nó được gọi là “khoảng cách đối ngẫu”, hãy viết lại bài toán gốc dưới dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} f(x) + I_C(x)\]
&lt;/blockquote&gt;

&lt;p&gt;với \(I_C\) là hàm chỉ thị của tập \(C\). Bài toán đối ngẫu tương ứng là:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_u −f^{*}(u) − I^{*}_C(−u)\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(I_C^{*}\) là hàm tựa (support function) của \(C\) (hàm liên hợp của hàm chỉ thị chính là hàm tựa).&lt;/p&gt;

&lt;h3 id=&quot;nhắc-lại&quot;&gt;[Nhắc lại]&lt;/h3&gt;

&lt;blockquote&gt;
\[I_C(x) = \begin{cases}
+\infty &amp;amp; \text{nếu } x \notin C \\
0 &amp;amp; \text{nếu } x \in C
\end{cases}\]

\[\begin{align}
I_C^{*}(s) &amp;amp;= \max_{x} \{\langle s, x \rangle - I_C(x)\} \\
&amp;amp;= \max_{x \in C} \langle s, x \rangle \\
&amp;amp;= \text{Hàm tựa của } C \text{ tại } s
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Đặt \(x = x^{(k-1)}\) và \(u = \nabla f(x^{(k-1)})\), theo &lt;a href=&quot;/contents/vi/chapter13/13_04_Conjugate_function/&quot;&gt;bất đẳng thức Fenchel&lt;/a&gt; (mục 13-04), khoảng cách đối ngẫu tại cặp \((x, u)\) thỏa mãn:&lt;/p&gt;

&lt;blockquote&gt;
\[f(x) + f^{*}(u) + I^{*}_C(−u) \geq x^Tu + I^{*}_C(−u)\]
&lt;/blockquote&gt;

&lt;p&gt;(và dấu bằng xảy ra khi \(u = \nabla f(x)\), cho đúng đại lượng \(g(x) = \max_{s \in C} \nabla f(x)^T(x - s)\)).&lt;/p&gt;

&lt;h3 id=&quot;frank-wolfe-tiến-về-một-đỉnh-không-cần-chiếu-video&quot;&gt;Frank-Wolfe: tiến về một đỉnh, không cần chiếu (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/frank-wolfe_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Ở mỗi vòng lặp, thuật toán chọn điểm cực trị \(s\) cực tiểu hóa \(\langle \nabla f(x), s\rangle\) và cập nhật \(x\) sang \((1-\gamma_k)x + \gamma_k s\), nên điểm lặp luôn nằm trong tập \(C\).&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-các-bước-frank-wolfe&quot;&gt;Tự tay thử: các bước Frank-Wolfe&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;fw&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>22-01 Nhắc lại: ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_01_Last_time_ADMM/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter22/22_01_Last_time_ADMM</id>
   <content type="html">&lt;p&gt;Trước khi chuyển sang phương pháp gradient có điều kiện (Frank–Wolfe), bài học này đóng vai trò như một trạm trung chuyển chiến lược: dừng lại nhìn về &lt;strong&gt;ADMM (Alternating Direction Method of Multipliers)&lt;/strong&gt; — công cụ chủ lực của Chương 21 — để thấy rõ điểm tương đồng và khác biệt giữa hai triết lý lớn của tối ưu hiện đại.&lt;/p&gt;

&lt;p&gt;Nếu Frank–Wolfe chọn cách giữ nguyên ràng buộc tập lồi \(x \in C\) rồi tuyến tính hóa hàm mục tiêu, thì ADMM lại chọn con đường tách đôi một bài toán khó thành hai bài toán con dễ hơn thông qua biến phụ \(z\) và ràng buộc đẳng thức \(Ax + Bz = c\). Điều kỳ diệu của ADMM là ở chỗ nó ghép sức mạnh ổn định của hàm phạt bậc hai (Augmented Lagrangian) với khả năng giải tách biệt từng biến giống như Dual Decomposition, biến những bài toán khổng lồ thành chuỗi cập nhật luân phiên cực kỳ thân thiện với tính toán phân tán.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-đằng-sau-admm&quot;&gt;Kiến thức cần nhớ: Ba trụ cột đằng sau ADMM&lt;/h2&gt;

&lt;p&gt;Khi đọc lại ba dòng cập nhật ngắn gọn của ADMM, hãy nhớ rằng đằng sau chúng là sự hòa quyện của ba ý tưởng lớn trong giải tích lồi:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm Lagrangian tăng cường (Augmented Lagrangian):&lt;/strong&gt; Cộng thêm số hạng phạt bậc hai \(\frac{\rho}{2}\|Ax + Bz - c\|_2^2\) vào Lagrangian cổ điển không làm thay đổi nghiệm tối ưu của bài toán gốc, nhưng giúp hàm đối ngẫu trở nên trơn hơn và loại bỏ yêu cầu hàm mục tiêu phải lồi chặt mới hội tụ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tách biến luân phiên (Gauss–Seidel Splitting):&lt;/strong&gt; Thay vì cực tiểu hóa đồng thời theo cặp \((x, z)\) — vốn phá vỡ cấu trúc tách biệt — ADMM cập nhật \(x\) trước (giữ \(z\) cố định) rồi mới cập nhật \(z\) (dùng \(x\) vừa tính), giống hệt tinh thần phương pháp Gauss–Seidel trong đại số tuyến tính số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến đối ngẫu chuẩn hóa (Scaled Dual Variable):&lt;/strong&gt; Đặt \(w = u / \rho\) không chỉ giúp viết gọn hai số hạng tuyến tính và bậc hai thành một bình phương hoàn chỉnh \(\frac{\rho}{2}\|Ax + Bz - c + w\|_2^2\), mà còn cho thấy trực giác rõ ràng: \(w^{(k)}\) chính là &lt;em&gt;tổng tích lũy&lt;/em&gt; của mọi sai số vi phạm ràng buộc (primal residuals) từ đầu thuật toán tới bước \(k\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-2-vòng-lặp-admm-dạng-chuẩn-hóa&quot;&gt;Giải thích: Tính tay 2 vòng lặp ADMM dạng chuẩn hóa&lt;/h3&gt;

&lt;p&gt;Để cảm nhận cách biến đối ngẫu \(w\) “kéo” hai biến tách rời \(x\) và \(z\) lại gần nhau, hãy giải bài toán đồng thuận 1 chiều:&lt;/p&gt;

\[\min_{x, z \in \mathbb{R}}\ \frac{1}{2}(x - 4)^2 + \frac{1}{2}z^2 \qquad \text{thỏa mãn } x - z = 0.\]

&lt;p&gt;Nghiệm đúng bằng mắt thường là \(x^\star = z^\star = 2\) (trung bình cộng của \(4\) và \(0\)). Hãy chọn \(\rho = 1\), khởi tạo \(z^{(0)} = 0\) và \(w^{(0)} = 0\) (ở đây \(A = 1, B = -1, c = 0\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(k = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Cập nhật \(x^{(1)}\):&lt;/em&gt; Cực tiểu hóa \(\frac{1}{2}(x - 4)^2 + \frac{1}{2}(x - 0 + 0)^2\). Lấy đạo hàm bằng \(0\): \((x - 4) + x = 0 \Rightarrow x^{(1)} = 2\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Cập nhật \(z^{(1)}\):&lt;/em&gt; Cực tiểu hóa \(\frac{1}{2}z^2 + \frac{1}{2}(2 - z + 0)^2\). Lấy đạo hàm bằng \(0\): \(z - (2 - z) = 0 \Rightarrow z^{(1)} = 1\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Cập nhật biến đối ngẫu \(w^{(1)}\):&lt;/em&gt; \(w^{(1)} = w^{(0)} + (x^{(1)} - z^{(1)}) = 0 + (2 - 1) = 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(k = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Cập nhật \(x^{(2)}\):&lt;/em&gt; Cực tiểu hóa \(\frac{1}{2}(x - 4)^2 + \frac{1}{2}(x - 1 + 1)^2 = \frac{1}{2}(x-4)^2 + \frac{1}{2}x^2 \Rightarrow x^{(2)} = 2\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Cập nhật \(z^{(2)}\):&lt;/em&gt; Cực tiểu hóa \(\frac{1}{2}z^2 + \frac{1}{2}(2 - z + 1)^2 = \frac{1}{2}z^2 + \frac{1}{2}(3 - z)^2\). Đạo hàm bằng \(0\): \(z - (3 - z) = 0 \Rightarrow z^{(2)} = 1.5\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Cập nhật biến đối ngẫu \(w^{(2)}\):&lt;/em&gt; \(w^{(2)} = 1 + (2 - 1.5) = 1.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan sát trực giác:&lt;/strong&gt; Sai số ràng buộc \(x^{(k)} - z^{(k)}\) giảm một nửa sau mỗi bước (\(1 \to 0.5 \to 0.25 \to \dots\)), còn \(w^{(k)}\) tích lũy dần \(0 \to 1 \to 1.5 \to 1.75 \to 2\), đóng vai trò như lực lò xo bù trừ để kéo \(z^{(k)}\) tiến mượt về đúng \(2\) mà không cần đặt \(\rho \to \infty\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;nhắc-lại-admm&quot;&gt;Nhắc lại: ADMM&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối ưu có ràng buộc đẳng thức sau:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x,z} &amp;amp;&amp;amp;f(x) + g(z)\\\\
&amp;amp;\text{ subject to } &amp;amp;&amp;amp;Ax + Bz = c 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Với tham số \(\rho &amp;gt; 0\), hàm Lagrangian tăng cường (Augmented Lagrangian) tương ứng có dạng:&lt;/p&gt;
&lt;blockquote&gt;
\[L_\rho(x, z, u) = f(x) + g(z) + u^T(Ax + Bz − c) + \frac{\rho}{2} \| Ax + Bz − c \|^2_2\]
&lt;/blockquote&gt;

&lt;p&gt;Việc bổ sung số hạng phạt bậc hai \(\frac{\rho}{2} \| Ax + Bz − c \|^2_2\) giúp cải thiện điều kiện hội tụ của bài toán, đồng thời ADMM vẫn duy trì khả năng tách biến thuận tiện cho tính toán song song thông qua các bước cập nhật luân phiên sau (chứng minh chi tiết đã trình bày ở chương trước).&lt;/p&gt;

&lt;p&gt;Các bước lặp ADMM với \(k = 1, 2, 3, \ldots\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(x^{(k)} = \arg\min_{x} L_\rho(x, z^{(k−1)}, u^{(k−1)})\)
\(z^{(k)} = \arg\min_{z} L_\rho(x^{(k)}, z, u^{(k−1)})\)
\(u^{(k)} = u^{(k−1)} + \rho(Ax^{(k)} + Bz^{(k)} − c)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;admm-dạng-chuẩn-hóa-scaled-form&quot;&gt;ADMM dạng chuẩn hóa (scaled form)&lt;/h2&gt;

&lt;p&gt;Đặt biến đối ngẫu chuẩn hóa \(w = u/\rho\), các bước cập nhật ADMM được viết gọn như sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x^{(k)} = \arg\min_{x} f(x) + \frac{\rho}{2} \| Ax + Bz^{(k−1)} − c + w^{(k−1)} \|^2_2\)
\(z^{(k)} = \arg\min_{z} g(z) + \frac{\rho}{2} \| Ax^{(k)} + Bz − c + w^{(k−1)} \|^2_2\) 
\(w^{(k)} = w^{(k−1)} + Ax^{(k)} + Bz^{(k)} − c\)&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>15 Phương pháp chắn (Barrier Method)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_barrier_method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_barrier_method</id>
   <content type="html">&lt;p&gt;Ở Chương 14, phương pháp Newton đã chinh phục trọn vẹn các bài toán tối ưu trơn không ràng buộc và có ràng buộc đẳng thức \(Ax = b\). Nhưng ngoài đời thực, hầu hết các bài toán quan trọng nhất — từ quy hoạch tuyến tính (LP), quy hoạch bậc hai (QP) đến điều khiển tối ưu và danh mục tài chính — đều bị bao vây bởi hàng loạt &lt;strong&gt;ràng buộc bất đẳng thức&lt;/strong&gt; \(h_i(x) \le 0\). Những bức tường cứng ấy khiến nghiệm tối ưu thường nằm ngay trên biên, nơi phương pháp Newton truyền thống hoàn toàn bất lực.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp chắn (Barrier Method)&lt;/strong&gt; giải bài toán đó bằng một ý tưởng hình học đầy táo bạo: thay vì để thuật toán va đầu vào các bức tường biên, ta dựng lên một &lt;strong&gt;trường lực đẩy trơn tru bằng hàm chắn logarit&lt;/strong&gt; \(-\frac{1}{t}\sum \log(-h_i(x))\) tăng vọt lên \(+\infty\) mỗi khi \(x\) tiến sát biên! Nhờ thế, bài toán có ràng buộc bất đẳng thức biến thành một chuỗi bài toán trơn có ràng buộc đẳng thức — nơi ta có thể thả phương pháp Newton vào chạy băng băng dọc theo &lt;strong&gt;đường trung tâm&lt;/strong&gt; cho đến sát nghiệm tối ưu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-phương-pháp-chắn-điểm-trong&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của Phương pháp chắn (Điểm trong)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ hàm chỉ thị bằng hàm chắn logarit:&lt;/strong&gt; Thay bức tường không khả vi \(I_{h_i(x) \le 0}\) bằng hàm trơn \(-\frac{1}{t}\log(-h_i(x))\). Khi tham số \(t\) tăng dần tới \(+\infty\), hàm chắn bám ngày càng sát hàm chỉ thị gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đường trung tâm (Central Path) \(x^*(t)\):&lt;/strong&gt; Tập hợp các nghiệm của bài toán chắn theo tham số \(t &amp;gt; 0\) tạo thành một đường cong mượt mà nằm hoàn toàn trong &lt;strong&gt;miền trong chặt&lt;/strong&gt; của tập khả thi và dẫn thẳng tới \(x^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện KKT nhiễu và khoảng cách dưới tối ưu \(m/t\):&lt;/strong&gt; Mỗi điểm trên đường trung tâm tự động sinh ra một điểm khả thi đối ngẫu với khoảng cách đối ngẫu &lt;strong&gt;đúng bằng \(m/t\)&lt;/strong&gt; — một công thức kỳ diệu không phụ thuộc hàm mục tiêu hay hình dạng miền!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán hai vòng lặp và Pha I tìm điểm khả thi:&lt;/strong&gt; Vòng ngoài tăng \(t \leftarrow \mu t\), vòng trong chạy Newton có ràng buộc đẳng thức (bước định tâm). Khi chưa có điểm khả thi chặt ban đầu, bài toán Pha I tìm điểm xuất phát cũng được giải bằng chính phương pháp chắn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-quan-sát-một-nghiệm-trượt-dọc-đường-trung-tâm-về-biên&quot;&gt;Giải thích: Quan sát một nghiệm trượt dọc đường trung tâm về biên&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa 1 chiều đơn giản nhất có ràng buộc bất đẳng thức:
\(\min_{x \in \mathbb{R}} x \qquad \text{với điều kiện } -x \le 0 \;\; (\text{tức } x \ge 0).\)
Nghiệm tối ưu hiển nhiên là \(x^* = 0\) với \(f^* = 0\) và số ràng buộc bất đẳng thức \(m = 1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập bài toán chắn theo tham số \(t &amp;gt; 0\):&lt;/strong&gt;
\(\min_{x &amp;gt; 0} \bigl(tx - \log x\bigr).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm đường trung tâm \(x^*(t)\):&lt;/strong&gt;
Lấy đạo hàm theo \(x\) bằng \(0\):
\(t - \frac{1}{x} = 0 \implies x^*(t) = \frac{1}{t}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan sát sự hội tụ khi tăng \(t\) theo hệ số \(\mu = 10\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(t = 1\): \(x^*(1) = 1.0\), sai số \(f(x^*(1)) - f^* = 1.0 = \frac{1}{1}\).&lt;/li&gt;
      &lt;li&gt;\(t = 10\): \(x^*(10) = 0.1\), sai số \(0.1 = \frac{1}{10}\).&lt;/li&gt;
      &lt;li&gt;\(t = 1000\): \(x^*(1000) = 0.001\), sai số \(0.001 = \frac{1}{1000} = \frac{m}{t}\)!
Điểm \(x^*(t) = 1/t\) luôn nằm chặt bên trong miền \(x &amp;gt; 0\) (không bao giờ chạm tường \(0\) sớm) nhưng tiến thẳng tới \(0\) với sai số chính xác bằng \(m/t\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong chương này, chúng ta sẽ tìm hiểu &lt;strong&gt;phương pháp chắn (Barrier Method)&lt;/strong&gt; — một phương pháp tối ưu bậc hai quan trọng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp chắn&lt;/strong&gt; được dùng để giải &lt;strong&gt;các bài toán tối ưu trơn có cả ràng buộc bất đẳng thức và ràng buộc đẳng thức&lt;/strong&gt;, nhóm bài toán tổng quát và khó nhất trong khuôn khổ các phương pháp bậc hai.&lt;/p&gt;

&lt;p&gt;(Nhắc lại: các phương pháp chỉ dùng gradient được gọi là phương pháp bậc nhất, còn các phương pháp dùng thêm ma trận Hessian được gọi là phương pháp bậc hai.)&lt;/p&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo-và-đọc-thêm&quot;&gt;Tài liệu tham khảo và đọc thêm&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;S. Boyd and L. Vandenberghe (2004), “Convex optimization”, Chapter 11&lt;/li&gt;
  &lt;li&gt;A. Nemirovski (2004), “Interior-point polynomial time methods in convex programming”, Chapter 4&lt;/li&gt;
  &lt;li&gt;J. Nocedal and S. Wright (2006), “Numerical optimization”, Chapters 14 and 19&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>15-11 Bài Tập Thực Hành - Phương Pháp Rào Cản</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_11_Practical_Exercises_Barrier_Method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_11_Practical_Exercises_Barrier_Method</id>
   <content type="html">&lt;p&gt;Để thực sự làm chủ phương pháp chắn, không có cách nào hiệu quả hơn việc tự tay tính đạo hàm của hàm chắn logarit, giải tường minh đường trung tâm \(x^*(t)\) cho một bài toán LP nhỏ, thiết lập điều kiện KKT nhiễu, và tự tay tính cận số vòng lặp hội tụ. Những phép tính tưởng chừng ngắn gọn đó sẽ giúp bạn nhìn thấy rõ ràng từng khớp nối giữa giải tích, đại số tuyến tính và lý thuyết đối ngẫu.&lt;/p&gt;

&lt;p&gt;Bộ bài tập thực hành dưới đây được biên soạn dựa trên các bài kinh điển của Boyd &amp;amp; Vandenberghe, Nocedal &amp;amp; Wright và Nesterov. Trước khi bắt tay giải, hãy xem qua bốn kỹ năng cốt lõi và một bài mẫu tính trọn vẹn từ hàm chắn đến kiểm tra KKT nhiễu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-kỹ-năng-tự-luận-trọng-tâm-của-bài-tập-chương-15&quot;&gt;Kiến thức cần nhớ: Bốn kỹ năng tự luận trọng tâm của bài tập Chương 15&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Giải tích hàm chắn dạng ma trận:&lt;/strong&gt; Với \(h_i(x) = a_i^T x - b_i\), tập thói quen viết gọn \(\nabla \phi(x) = A^T d\) và \(\nabla^2 \phi(x) = A^T \operatorname{diag}(d^2) A\) (với \(d_i = \frac{1}{b_i - a_i^T x}\)) để chứng minh nhanh tính lồi và tính tự hài hòa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải tường minh đường trung tâm 1D/2D:&lt;/strong&gt; Đặt \(\nabla (t f(x) + \phi(x)) = 0\) (cộng thêm \(A^T w = 0\) nếu có ràng buộc đẳng thức), giải theo \(t\) và luôn chọn nhánh nghiệm nằm trong miền khả thi chặt \(h_i(x) &amp;lt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng cặp nguyên thủy – đối ngẫu trên đường trung tâm:&lt;/strong&gt; Từ \(x^*(t)\), tính ngay \(u_i^*(t) = -\frac{1}{t h_i(x^*(t))}\), kiểm tra \(u_i^* &amp;gt; 0\), điều kiện dừng và xác nhận \(f(x^*(t)) - g(u^*(t)) = m/t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập Pha I và phân tích độ phức tạp:&lt;/strong&gt; Luôn kiểm tra cách chọn \(s^{(0)} &amp;gt; \max_i h_i(x^{(0)})\) và nhớ công thức số vòng ngoài \(\lceil \log(m/(\epsilon t^{(0)})) / \log \mu \rceil\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bài-mẫu-giải-trọn-vẹn-đường-trung-tâm-có-ràng-buộc-đẳng-thức&quot;&gt;Giải thích: Bài mẫu giải trọn vẹn đường trung tâm có ràng buộc đẳng thức&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán mẫu:&lt;/strong&gt; Tìm đường trung tâm \(x^*(t)\) cho bài toán cực tiểu hóa 2 biến có cả ràng buộc đẳng thức và bất đẳng thức:
\(\min_{x \in \mathbb{R}^2} x_1 \qquad \text{với điều kiện } x_1 + x_2 = 1, \;\; x_1 \ge 0, \;\; x_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khử biến bằng ràng buộc đẳng thức (để thấy rõ đường trung tâm 1 chiều):&lt;/strong&gt;
Vì \(x_2 = 1 - x_1\) và \(x_1 &amp;gt; 0, x_2 &amp;gt; 0 \iff x_1 \in (0, 1)\), bài toán chắn trở thành:
\(\min_{x_1 \in (0, 1)} t x_1 - \log(x_1) - \log(1 - x_1).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải điều kiện dừng:&lt;/strong&gt;
\(t - \frac{1}{x_1} + \frac{1}{1 - x_1} = 0 \iff t x_1(1 - x_1) - (1 - 2x_1) = 0 \iff t x_1^2 - (t + 2)x_1 + 1 = 0.\)
Chọn nghiệm nằm trong \((0, 1)\):
\(x_1^*(t) = \frac{t + 2 - \sqrt{t^2 + 4}}{2t}, \qquad x_2^*(t) = 1 - x_1^*(t).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra hai đầu mút và số liệu tại \(t = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Khi \(t \to 0^+\): \(x_1^*(t) \to \frac{1}{2}, x_2^*(t) \to \frac{1}{2}\) (tâm giải tích của đơn hình chuẩn!).&lt;/li&gt;
      &lt;li&gt;Tại \(t = 2\): \(x_1^*(2) = \frac{4 - \sqrt{8}}{4} = 1 - \frac{\sqrt{2}}{2} \approx 0.2929\), \(x_2^*(2) \approx 0.7071\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra khoảng cách dưới tối ưu (\(m = 2, f^* = 0\)): \(f(x^*(2)) - f^* = 0.2929 \le \frac{m}{t} = \frac{2}{2} = 1.0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---phương-pháp-chắn-barrier-method&quot;&gt;Bài Tập Thực Hành - Phương Pháp Chắn (Barrier Method)&lt;/h1&gt;

&lt;p&gt;Các bài tập dưới đây được tham khảo từ Boyd &amp;amp; Vandenberghe (2004), Nocedal &amp;amp; Wright (2006) và Nesterov (2004).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-i-hàm-chắn-logarit-log-barrier-function&quot;&gt;📝 &lt;strong&gt;Phần I: Hàm chắn logarit (Log-Barrier Function)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-tính-đạo-hàm-của-hàm-chắn-logarit-boyd--vandenberghe-ex-111&quot;&gt;&lt;strong&gt;Bài tập 1: Tính đạo hàm của hàm chắn logarit (Boyd &amp;amp; Vandenberghe, Ex. 11.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; f(x) \\
\text{s.t.} \quad &amp;amp; h_i(x) \leq 0, \quad i = 1, \ldots, m
\end{align}\]

&lt;p&gt;với hàm chắn logarit:&lt;/p&gt;

\[\phi(x) = -\sum_{i=1}^m \log(-h_i(x))\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tính \(\nabla \phi(x)\) và \(\nabla^2 \phi(x)\).&lt;br /&gt;
b) Cho \(f(x) = x^2\), \(h_1(x) = x - 1\), \(h_2(x) = -x - 1\) (tương ứng \(-1 \leq x \leq 1\)). Tính \(\phi(x)\), \(\nabla \phi(x)\) và \(\nabla^2 \phi(x)\).&lt;br /&gt;
c) Tính các giá trị trên tại \(x = 0\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Gradient và Hessian của $$\phi(x)$$:**

**Gradient:**

$$
\nabla \phi(x) = -\sum_{i=1}^m \frac{1}{-h_i(x)} (-\nabla h_i(x)) = \sum_{i=1}^m \frac{\nabla h_i(x)}{-h_i(x)}
$$

**Hessian:**

$$
\nabla^2 \phi(x) = \sum_{i=1}^m \left( \frac{\nabla^2 h_i(x)}{-h_i(x)} + \frac{\nabla h_i(x) \nabla h_i(x)^T}{h_i(x)^2} \right)
$$

---

**b) Trường hợp cụ thể:**

$$
f(x) = x^2, \quad h_1(x) = x - 1, \quad h_2(x) = -x - 1
$$

**Hàm chắn:**

$$
\phi(x) = -\log(-(x-1)) - \log(-(-x-1)) = -\log(1-x) - \log(1+x)
$$

**Gradient:**

$$
\nabla h_1(x) = 1, \quad \nabla h_2(x) = -1
$$

$$
\nabla \phi(x) = \frac{1}{1-x} + \frac{-1}{1+x} = \frac{1+x-(1-x)}{(1-x)(1+x)} = \frac{2x}{1-x^2}
$$

**Hessian:**

$$
\nabla^2 h_1(x) = 0, \quad \nabla^2 h_2(x) = 0
$$

$$
\nabla^2 \phi(x) = \frac{1}{(1-x)^2} + \frac{1}{(1+x)^2}
$$

$$
= \frac{(1+x)^2 + (1-x)^2}{(1-x^2)^2} = \frac{2(1+x^2)}{(1-x^2)^2}
$$

---

**c) Tại $$x = 0$$:**

$$
\phi(0) = -\log(1) - \log(1) = 0
$$

$$
\nabla \phi(0) = \frac{0}{1} = 0
$$

$$
\nabla^2 \phi(0) = \frac{2 \cdot 1}{1} = 2
$$

**Nhận xét:** Tại tâm miền khả thi ($$x = 0$$), hàm chắn đạt cực tiểu nên gradient bằng $$0$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-2-đường-trung-tâm-boyd--vandenberghe-ex-112&quot;&gt;&lt;strong&gt;Bài tập 2: Đường trung tâm (Boyd &amp;amp; Vandenberghe, Ex. 11.2)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Tiếp tục Bài tập 1, xét bài toán chắn:&lt;/p&gt;

\[\min_x \quad t f(x) + \phi(x) = t x^2 - \log(1-x) - \log(1+x)\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết điều kiện tối ưu bậc nhất (FOC).&lt;br /&gt;
b) Giải điều kiện bậc nhất để tìm điểm đường trung tâm \(x^*(t)\).&lt;br /&gt;
c) Tính \(x^*(1)\), \(x^*(10)\), \(x^*(100)\).&lt;br /&gt;
d) Xác định giới hạn \(\lim_{t \to \infty} x^*(t)\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Điều kiện tối ưu bậc nhất (FOC):**

$$
\frac{d}{dx}\left( t x^2 - \log(1-x) - \log(1+x) \right) = 0
$$

$$
2tx + \frac{1}{1-x} - \frac{1}{1+x} = 0
$$

$$
2tx + \frac{2x}{1-x^2} = 0
$$

$$
x\left( 2t + \frac{2}{1-x^2} \right) = 0
$$

**Hai trường hợp:**
1. $$x = 0$$.
2. $$2t + \frac{2}{1-x^2} = 0$$ (vô nghiệm trên $$(-1, 1)$$ vì với mọi $$t &amp;gt; 0$$ và $$|x| &amp;lt; 1$$, vế trái luôn dương).

**Kết luận:** $$x^*(t) = 0$$ với mọi $$t &amp;gt; 0$$.

---

**b) Giải thích:**

Do cả hàm mục tiêu $$f(x) = x^2$$ lẫn miền khả thi $$(-1, 1)$$ đều đối xứng qua $$x = 0$$, đường trung tâm suy biến thành một điểm cố định $$x^*(t) = 0$$ với mọi $$t &amp;gt; 0$$.

---

**c) Các giá trị cụ thể:**

$$
x^*(1) = 0, \quad x^*(10) = 0, \quad x^*(100) = 0
$$

---

**d) Giới hạn khi $$t \to \infty$$:**

$$
\lim_{t \to \infty} x^*(t) = 0
$$

Đây chính là nghiệm của bài toán gốc: $$\min_{-1 \leq x \leq 1} x^2 = 0$$ đạt tại $$x = 0$$.

**Lưu ý:** Đây là trường hợp đặc biệt do tính đối xứng; tổng quát, điểm $$x^*(t)$$ sẽ dịch chuyển dọc theo đường trung tâm khi $$t$$ tăng.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-ii-phân-tích-đường-trung-tâm&quot;&gt;📝 &lt;strong&gt;Phần II: Phân tích đường trung tâm&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-3-đường-trung-tâm-cho-quy-hoạch-tuyến-tính-nocedal--wright-ex-141&quot;&gt;&lt;strong&gt;Bài tập 3: Đường trung tâm cho quy hoạch tuyến tính (Nocedal &amp;amp; Wright, Ex. 14.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch tuyến tính (LP):&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; c^T x \\
\text{s.t.} \quad &amp;amp; Ax = b \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;với \(c = \begin{bmatrix} -1 \\ -1 \end{bmatrix}\), \(A = \begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix}\), \(b = 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán chắn tương ứng.&lt;br /&gt;
b) Tìm đường trung tâm \(x^*(t)\).&lt;br /&gt;
c) Tính \(\lim_{t \to \infty} x^*(t)\).&lt;br /&gt;
d) Đối chiếu với bài toán đối ngẫu và tính khoảng cách đối ngẫu.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Bài toán chắn:**

$$
\min_x \quad t c^T x - \sum_{i=1}^2 \log x_i \quad \text{s.t.} \quad x_1 + x_2 = 1
$$

$$
= \min_x \quad -t(x_1 + x_2) - \log x_1 - \log x_2 \quad \text{s.t.} \quad x_1 + x_2 = 1
$$

---

**b) Tìm đường trung tâm:**

**Hàm Lagrange:**

$$
L(x, \nu) = -t(x_1 + x_2) - \log x_1 - \log x_2 - \nu(x_1 + x_2 - 1)
$$

**Điều kiện tối ưu bậc nhất:**

$$
\frac{\partial L}{\partial x_1} = -t - \frac{1}{x_1} - \nu = 0 \Rightarrow \frac{1}{x_1} = -t - \nu
$$

$$
\frac{\partial L}{\partial x_2} = -t - \frac{1}{x_2} - \nu = 0 \Rightarrow \frac{1}{x_2} = -t - \nu
$$

Từ hai phương trình trên suy ra $$x_1 = x_2$$. Kết hợp với $$x_1 + x_2 = 1$$, ta được $$x_1 = x_2 = 0.5$$.

**Đường trung tâm:**

$$
x^*(t) = \begin{bmatrix} 0.5 \\ 0.5 \end{bmatrix} \quad \forall t &amp;gt; 0
$$

**Biến đối ngẫu:**

$$
\frac{1}{0.5} = -t - \nu \Rightarrow \nu = -t - 2
$$

---

**c) Giới hạn khi $$t \to \infty$$:**

$$
\lim_{t \to \infty} x^*(t) = \begin{bmatrix} 0.5 \\ 0.5 \end{bmatrix}
$$

**Đối chiếu với bài toán gốc:**

$$
\min -x_1 - x_2 \quad \text{s.t.} \quad x_1 + x_2 = 1, \quad x \geq 0
$$

Giá trị tối ưu là $$-1$$ tại mọi điểm trên đoạn thẳng nối $$(0,1)$$ và $$(1,0)$$. Đường trung tâm hội tụ về **tâm giải tích (analytic center)** của tập nghiệm tối ưu là $$(0.5, 0.5)^T$$.

---

**d) Đối chiếu nguyên thủy–đối ngẫu:**

**Bài toán đối ngẫu:**

$$
\max_{\nu} \quad \nu \quad \text{s.t.} \quad \begin{bmatrix} \nu \\ \nu \end{bmatrix} \leq \begin{bmatrix} -1 \\ -1 \end{bmatrix}
$$

Điều kiện $$\nu \leq -1$$ cho nghiệm tối ưu đối ngẫu $$\nu^* = -1$$.

**Khoảng cách đối ngẫu:**

$$
\text{gap}(t) = c^T x^*(t) - b^T y(t)
$$

Điểm khả thi đối ngẫu suy ra từ đường trung tâm là $$\lambda_i(t) = \frac{1}{t x_i^*(t)} = \frac{2}{t}$$ và $$y(t) = \frac{\nu(t)}{t} = -1 - \frac{2}{t} \leq -1$$. Giá trị hàm mục tiêu đối ngẫu là $$b^Ty(t) = -1 - \frac{2}{t}$$, nên:

$$
\text{gap}(t) = -1 - \left(-1 - \frac{2}{t}\right) = \frac{2}{t} = \frac{m}{t}
$$

Khoảng cách đối ngẫu luôn dương với mọi $$t$$ hữu hạn và tiến về $$0$$ khi $$t \to \infty$$, khớp với công thức $$m/t$$ (ở đây $$m = 2$$).

**Lưu ý:** Công thức $$\text{gap} = m/t$$ luôn đúng dọc theo đường trung tâm; khoảng cách chỉ bằng $$0$$ khi đối chiếu với giá trị đối ngẫu tối ưu $$\nu^* = -1$$ ở giới hạn $$t \to \infty$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iii-điều-kiện-kkt-nhiễu&quot;&gt;📝 &lt;strong&gt;Phần III: Điều kiện KKT nhiễu&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-4-điều-kiện-kkt-của-bài-toán-chắn-boyd--vandenberghe-ex-114&quot;&gt;&lt;strong&gt;Bài tập 4: Điều kiện KKT của bài toán chắn (Boyd &amp;amp; Vandenberghe, Ex. 11.4)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét bài toán chắn:&lt;/p&gt;

\[\min_x \quad t f(x) + \phi(x)\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết điều kiện tối ưu cho bài toán chắn.&lt;br /&gt;
b) Chứng minh: Nếu \(x^*(t)\) tối ưu cho bài toán chắn thì tồn tại \(\lambda^*(t)\) thỏa mãn:&lt;/p&gt;

\[\begin{align}
\nabla f(x^*(t)) + \sum_i \lambda_i^*(t) \nabla h_i(x^*(t)) &amp;amp;= 0 \\
\lambda_i^*(t) &amp;amp;= -\frac{1}{t h_i(x^*(t))} \\
h_i(x^*(t)) &amp;amp;&amp;lt; 0
\end{align}\]

&lt;p&gt;c) Tính tích \(\lambda_i^*(t) h_i(x^*(t))\).&lt;br /&gt;
d) Điều gì xảy ra khi \(t \to \infty\)?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Điều kiện tối ưu cho bài toán chắn:**

$$
\min_x \quad t f(x) + \phi(x) = t f(x) - \sum_i \log(-h_i(x))
$$

Điều kiện tối ưu bậc nhất:

$$
t \nabla f(x) + \nabla \phi(x) = 0
$$

$$
t \nabla f(x) + \sum_i \frac{\nabla h_i(x)}{-h_i(x)} = 0
$$

---

**b) Chứng minh điều kiện KKT nhiễu:**

Đặt:

$$
\lambda_i^*(t) := -\frac{1}{t h_i(x^*(t))}
$$

Chia cả hai vế của điều kiện bậc nhất cho $$t &amp;gt; 0$$:

$$
t \nabla f(x^*) + \sum_i \frac{\nabla h_i(x^*)}{-h_i(x^*)} = 0
$$

$$
\nabla f(x^*) + \sum_i \frac{1}{-t h_i(x^*)} \nabla h_i(x^*) = 0
$$

$$
\nabla f(x^*) + \sum_i \left(-\frac{1}{t h_i(x^*)}\right) \nabla h_i(x^*) = 0
$$

$$
\nabla f(x^*) + \sum_i \lambda_i^*(t) \nabla h_i(x^*) = 0
$$

Đây chính là điều kiện dừng của hệ KKT.

**Khả thi nguyên thủy:** Vì $$x^*(t)$$ thuộc miền xác định của hàm chắn nên $$h_i(x^*(t)) &amp;lt; 0$$.

**Khả thi đối ngẫu:**

$$
\lambda_i^* = -\frac{1}{t h_i(x^*)} &amp;gt; 0 \quad \text{(vì } h_i(x^*) &amp;lt; 0 \text{ và } t &amp;gt; 0\text{)}
$$

---

**c) Độ lệch bù bị nhiễu:**

$$
\lambda_i^*(t) h_i(x^*(t)) = -\frac{1}{t h_i(x^*)} \cdot h_i(x^*) = -\frac{1}{t}
$$

Tích này khác $$0$$ mà bằng $$-1/t$$, nên được gọi là **điều kiện độ lệch bù nhiễu (perturbed complementary slackness)**.

---

**d) Giới hạn khi $$t \to \infty$$:**

$$
\lambda_i^*(t) h_i(x^*(t)) = -\frac{1}{t} \to 0
$$

Hệ điều kiện KKT nhiễu tiến về hệ điều kiện KKT chính xác của bài toán gốc, nên $$x^*(t) \to x^*$$ và $$\lambda^*(t) \to \lambda^*$$.

**Khoảng cách đối ngẫu:**

$$
\text{gap}(t) = f(x^*(t)) - g(\lambda^*(t), \nu^*(t)) = \frac{m}{t}
$$

với $$m$$ là số ràng buộc bất đẳng thức.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iv-phân-tích-hội-tụ&quot;&gt;📝 &lt;strong&gt;Phần IV: Phân tích hội tụ&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-5-khoảng-cách-đối-ngẫu-và-hội-tụ-boyd--vandenberghe-theorem-112&quot;&gt;&lt;strong&gt;Bài tập 5: Khoảng cách đối ngẫu và hội tụ (Boyd &amp;amp; Vandenberghe, Theorem 11.2)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét phương pháp chắn với tham số \(t^{(k)} = \mu^k t^{(0)}\), trong đó \(\mu &amp;gt; 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Xác định khoảng cách đối ngẫu sau \(k\) vòng lặp ngoài: \(\text{gap}^{(k)} = \frac{m}{t^{(k)}}\).&lt;br /&gt;
b) Để đạt \(\text{gap} &amp;lt; \epsilon\), cần ít nhất bao nhiêu vòng lặp ngoài?&lt;br /&gt;
c) Với \(m = 100\), \(\mu = 10\), \(\epsilon = 10^{-6}\) (và \(t^{(0)} = 1\)), tính số vòng lặp ngoài.&lt;br /&gt;
d) Ước lượng tổng số bước Newton (giả sử mỗi vòng lặp ngoài cần khoảng \(10\) bước Newton).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Khoảng cách đối ngẫu:**

Tại vòng lặp ngoài thứ $$k$$, điểm đường trung tâm $$x^*(t^{(k)})$$ thỏa mãn điều kiện KKT nhiễu:

$$
\lambda_i^*(t^{(k)}) h_i(x^*(t^{(k)})) = -\frac{1}{t^{(k)}}
$$

Khoảng cách đối ngẫu tương ứng là:

$$
\eta(t^{(k)}) = f(x^*(t^{(k)})) - g(\lambda^*(t^{(k)}), \nu^*(t^{(k)}))
$$

Theo lý thuyết phương pháp chắn (Boyd &amp;amp; Vandenberghe, Theorem 11.2):

$$
\eta(t) = \frac{m}{t}
$$

với $$m$$ là số ràng buộc bất đẳng thức.

---

**b) Số vòng lặp ngoài cần thiết:**

Điều kiện dừng: $$\frac{m}{t^{(k)}} &amp;lt; \epsilon \iff t^{(k)} &amp;gt; \frac{m}{\epsilon}$$.

Thay $$t^{(k)} = \mu^k t^{(0)}$$:

$$
\mu^k t^{(0)} &amp;gt; \frac{m}{\epsilon}
$$

$$
k &amp;gt; \frac{\log(m/(\epsilon t^{(0)}))}{\log \mu}
$$

Khi $$t^{(0)} = 1$$:

$$
k &amp;gt; \frac{\log(m/\epsilon)}{\log \mu}
$$

---

**c) Tính toán cụ thể:**

$$
k &amp;gt; \frac{\log(100/10^{-6})}{\log 10} = \frac{\log(10^8)}{\log 10} = 8
$$

Do đó cần $$k = 9$$ vòng lặp ngoài (tại $$k = 8$$ ta có $$\text{gap} = m/\mu^8 = 10^{-6} = \epsilon$$, chưa nhỏ hơn chặt $$\epsilon$$).

---

**d) Tổng số bước Newton ước lượng:**

Giả sử mỗi vòng lặp ngoài cần xấp xỉ $$10$$ bước Newton:

$$
\text{Tổng số bước Newton} \approx 9 \times 10 = 90
$$

**Nhận xét:**
- Với $$\mu$$ cố định, số vòng lặp ngoài là $$O(\log(m/\epsilon))$$.
- Với bước tăng ngắn $$\mu = 1 + 1/\sqrt{m}$$, cần $$O(\sqrt{m}\log(m/\epsilon))$$ vòng lặp ngoài nhưng mỗi vòng chỉ cần $$O(1)$$ bước Newton.
- Tổng độ phức tạp lý thuyết là $$O(\sqrt{m} \log(m/\epsilon))$$ bước Newton.

Với $$\mu = 10$$ (lớn), số vòng lặp ngoài ít nhưng mỗi vòng lặp ngoài có thể đòi hỏi nhiều bước Newton hơn.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-v-tìm-điểm-khả-thi-và-phase-i&quot;&gt;📝 &lt;strong&gt;Phần V: Tìm điểm khả thi và Phase I&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-6-phương-pháp-phase-i-nocedal--wright-ex-143&quot;&gt;&lt;strong&gt;Bài tập 6: Phương pháp Phase I (Nocedal &amp;amp; Wright, Ex. 14.3)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Tìm một điểm khả thi chặt cho hệ ràng buộc:&lt;/p&gt;

\[\begin{align}
&amp;amp; x_1 + x_2 \leq 1 \\
&amp;amp; x_1 - x_2 \leq 0.5 \\
&amp;amp; -x_1 \leq 0 \\
&amp;amp; -x_2 \leq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán Phase I:&lt;/p&gt;

\[\min_{x, s} \quad s \quad \text{s.t.} \quad h_i(x) \leq s, \quad i=1,\ldots,m\]

&lt;p&gt;b) Giải bài toán Phase I.&lt;br /&gt;
c) Nếu nghiệm thỏa \(s^* &amp;lt; 0\), chỉ ra một điểm khả thi chặt.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Bài toán Phase I:**

$$
\begin{align}
\min_{x_1, x_2, s} \quad &amp;amp; s \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 - 1 \leq s \\
&amp;amp; x_1 - x_2 - 0.5 \leq s \\
&amp;amp; -x_1 \leq s \\
&amp;amp; -x_2 \leq s
\end{align}
$$

Tương đương:

$$
\min_{x, s} \quad s \quad \text{s.t.} \quad h_i(x) - s \leq 0
$$

---

**b) Giải bài toán Phase I:**

Bài toán chắn tương ứng:

$$
\min_{x, s} \quad t \cdot s - \sum_i \log(-(h_i(x) - s))
$$

Khi $$t$$ lớn, nghiệm tiến về nghiệm của bài toán LP 3 biến $$(x_1, x_2, s)$$:

$$
\min_{x, s} \quad s \quad \text{s.t.} \quad h_i(x) \leq s
$$

tức $$s^* = \min_x \max_i h_i(x)$$.

Tại nghiệm tối ưu, ba ràng buộc $$h_1, h_3, h_4$$ cùng đạt dấu bằng:

$$x_1 + x_2 - 1 = -x_1 = -x_2 = s \;\Rightarrow\; x_1 = x_2 = -s,\quad -2s - 1 = s \;\Rightarrow\; s = -\tfrac{1}{3}$$

Suy ra nghiệm tối ưu là $$x^* = \left(\tfrac{1}{3}, \tfrac{1}{3}\right)$$ và $$s^* = -\tfrac{1}{3}$$.

**Kiểm tra:**

$$
\begin{align}
h_1 &amp;amp;= \tfrac{1}{3} + \tfrac{1}{3} - 1 = -\tfrac{1}{3} \\
h_2 &amp;amp;= \tfrac{1}{3} - \tfrac{1}{3} - 0.5 = -0.5 \\
h_3 &amp;amp;= -\tfrac{1}{3} \\
h_4 &amp;amp;= -\tfrac{1}{3}
\end{align}
$$

Do đó $$\max_i h_i = -\tfrac{1}{3}$$. (Lưu ý rằng điểm $$x = (0.25, 0.25)$$ cũng khả thi chặt với $$s = -0.25$$ nhưng chưa tối ưu cho Phase I vì $$-0.25 &amp;gt; -\tfrac{1}{3}$$.)

---

**c) Điểm khả thi chặt:**

Vì $$s^* = -\tfrac{1}{3} &amp;lt; 0$$, hệ ràng buộc khả thi chặt và điểm $$x = (\tfrac{1}{3}, \tfrac{1}{3})$$ thỏa mãn chặt cả bốn bất đẳng thức ($$h_i = -\tfrac{1}{3}, -0.5, -\tfrac{1}{3}, -\tfrac{1}{3} &amp;lt; 0$$).

Trong thực hành, không cần giải Phase I đến tối ưu tuyệt đối — chỉ cần dừng ngay khi tìm được một cặp $$(x, s)$$ có $$s &amp;lt; 0$$ (ví dụ $$x = (0.25, 0.25)$$ với $$s = -0.25$$) là đủ làm điểm khởi tạo cho phương pháp chắn.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-vi-bài-toán-tổng-hợp&quot;&gt;📝 &lt;strong&gt;Phần VI: Bài toán tổng hợp&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-7-tối-ưu-danh-mục-đầu-tư-bằng-phương-pháp-chắn-boyd--vandenberghe-ex-1110&quot;&gt;&lt;strong&gt;Bài tập 7: Tối ưu danh mục đầu tư bằng phương pháp chắn (Boyd &amp;amp; Vandenberghe, Ex. 11.10)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu danh mục đầu tư:&lt;/p&gt;

\[\begin{align}
\min_x \quad &amp;amp; x^T \Sigma x \\
\text{s.t.} \quad &amp;amp; \mu^T x \geq r_{\min} \\
&amp;amp; \mathbf{1}^T x = 1 \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;với \(\Sigma = \begin{bmatrix} 0.04 &amp;amp; 0.01 \\ 0.01 &amp;amp; 0.09 \end{bmatrix}\), \(\mu = \begin{bmatrix} 0.10 \\ 0.15 \end{bmatrix}\), \(r_{\min} = 0.12\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán chắn tương ứng.&lt;br /&gt;
b) Xác định điểm đường trung tâm tại \(t = 1, 10, 100\).&lt;br /&gt;
c) Phân tích tốc độ hội tụ.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Bài toán chắn:**

Đưa các ràng buộc về dạng chuẩn:

$$
\begin{align}
\min_x \quad &amp;amp; x^T \Sigma x \\
\text{s.t.} \quad &amp;amp; -\mu^T x + r_{\min} \leq 0 \quad \text{(bất đẳng thức 1)} \\
&amp;amp; \mathbf{1}^T x = 1 \quad \text{(đẳng thức)} \\
&amp;amp; -x_i \leq 0, \quad i=1,2 \quad \text{(bất đẳng thức 2, 3)}
\end{align}
$$

**Hàm chắn logarit:**

$$
\phi(x) = -\log(-(-\mu^T x + r_{\min})) - \sum_{i=1}^2 \log x_i
$$

$$
= -\log(\mu^T x - r_{\min}) - \log x_1 - \log x_2
$$

**Bài toán chắn:**

$$
\min_x \quad t \cdot x^T \Sigma x - \log(\mu^T x - r_{\min}) - \log x_1 - \log x_2
$$

thỏa mãn $$\mathbf{1}^T x = 1$$.

---

**b) Đường trung tâm (tính số):**

**Hàm Lagrange:**

$$
L = t x^T \Sigma x - \log(\mu^T x - r_{\min}) - \sum_i \log x_i - \nu(x_1 + x_2 - 1)
$$

**Điều kiện tối ưu bậc nhất:**

$$
2t \Sigma x - \frac{\mu}{\mu^T x - r_{\min}} - \begin{bmatrix} 1/x_1 \\ 1/x_2 \end{bmatrix} - \nu \mathbf{1} = 0
$$

$$
x_1 + x_2 = 1
$$

Giải số hệ phương trình trên thu được các điểm xấp xỉ:

- **$$t = 1$$:** $$x^*(1) \approx (0.247, 0.753)$$ (với $$t$$ nhỏ, hàm chắn chi phối nên nghiệm gần tâm giải tích của miền khả thi).
- **$$t = 10$$:** $$x^*(10) \approx (0.282, 0.718)$$.
- **$$t = 100$$:** $$x^*(100) \approx (0.448, 0.552)$$ (và $$x^*(1000) \approx (0.571, 0.429)$$).

Khi $$t \to \infty$$, nghiệm hội tụ về $$x^* = (0.6, 0.4)$$ (tại đó ràng buộc lợi suất chặt: $$0.10(0.6) + 0.15(0.4) = 0.12$$ và phương sai tối ưu $$x^T\Sigma x = 0.0336$$).

---

**c) Phân tích hội tụ:**

Bài toán có $$m = 3$$ ràng buộc bất đẳng thức, nên khoảng cách đối ngẫu là:

$$
\text{gap}(t) = \frac{3}{t}
$$

- $$t = 1$$: $$\text{gap} = 3$$
- $$t = 10$$: $$\text{gap} = 0.3$$
- $$t = 100$$: $$\text{gap} = 0.03$$

Để đạt $$\text{gap} &amp;lt; 10^{-6}$$, cần $$t &amp;gt; 3 \times 10^6$$.

Với $$\mu = 10$$ và $$t^{(0)} = 1$$:

$$
k &amp;gt; \frac{\log(3 \times 10^6)}{\log 10} \approx 6.5 \Rightarrow k = 7 \text{ vòng lặp ngoài}
$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết-và-lưu-ý-thực-hành&quot;&gt;💡 &lt;strong&gt;Tổng kết và lưu ý thực hành&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;hàm-chắn-logarit&quot;&gt;&lt;strong&gt;Hàm chắn logarit:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\phi(x) = -\sum_i \log(-h_i(x))\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla \phi(x) = \sum_i \frac{\nabla h_i(x)}{-h_i(x)}\]
  &lt;/li&gt;
  &lt;li&gt;\(\phi(x) \to \infty\) khi \(x\) tiến sát biên&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;đường-trung-tâm&quot;&gt;&lt;strong&gt;Đường trung tâm:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;\(x^*(t)\) là nghiệm của bài toán \(\min t f(x) + \phi(x)\) (với \(Ax = b\))&lt;/li&gt;
  &lt;li&gt;Khi \(t \to \infty\): \(x^*(t) \to x^*\) (nghiệm tối ưu gốc)&lt;/li&gt;
  &lt;li&gt;Đặc trưng bởi hệ điều kiện KKT nhiễu&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;điều-kiện-kkt-nhiễu&quot;&gt;&lt;strong&gt;Điều kiện KKT nhiễu:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\nabla f(x^*) + \sum_i \lambda_i^* \nabla h_i(x^*) = 0\]
  &lt;/li&gt;
  &lt;li&gt;
\[\lambda_i^* = -\frac{1}{t h_i(x^*)}\]
  &lt;/li&gt;
  &lt;li&gt;\(\lambda_i^* h_i(x^*) = -\frac{1}{t} \to 0\) khi \(t \to \infty\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phân-tích-hội-tụ&quot;&gt;&lt;strong&gt;Phân tích hội tụ:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Khoảng cách đối ngẫu: \(\eta(t) = \frac{m}{t}\)&lt;/li&gt;
  &lt;li&gt;Số vòng lặp ngoài: \(O(\log(m/\epsilon) / \log \mu)\)&lt;/li&gt;
  &lt;li&gt;Với \(\mu = 10\): cần xấp xỉ \(\log_{10}(m/\epsilon)\) vòng lặp ngoài&lt;/li&gt;
  &lt;li&gt;Mỗi vòng lặp ngoài giải bài toán chắn bằng phương pháp Newton&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phương-pháp-phase-i&quot;&gt;&lt;strong&gt;Phương pháp Phase I:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Mục tiêu: tìm điểm khởi tạo khả thi chặt&lt;/li&gt;
  &lt;li&gt;Bài toán: \(\min_{x,s} s\) thỏa mãn \(h_i(x) \leq s\) (và \(Ax = b\))&lt;/li&gt;
  &lt;li&gt;Nếu \(s^* &amp;lt; 0\): bài toán khả thi chặt và \(x^*\) dùng làm điểm xuất phát&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 11.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nocedal, J., &amp;amp; Wright, S. J.&lt;/strong&gt; (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt; (2nd ed.). Springer. Chapter 14, 19.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nesterov, Y.&lt;/strong&gt; (2004). &lt;em&gt;Introductory Lectures on Convex Optimization&lt;/em&gt;. Springer. Chapter 4.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Wright, S. J.&lt;/strong&gt; (1997). &lt;em&gt;Primal-Dual Interior-Point Methods&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ben-Tal, A., &amp;amp; Nemirovski, A.&lt;/strong&gt; (2001). &lt;em&gt;Lectures on Modern Convex Optimization&lt;/em&gt;. SIAM. Chapter 4.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>15-10 Bài tập trắc nghiệm - Phương Pháp Rào Cản</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_10_Quiz_Barrier_Method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_10_Quiz_Barrier_Method</id>
   <content type="html">&lt;p&gt;Phương pháp chắn kết nối rất nhiều chi tiết tinh tế từ cả Chương 13 (đối ngẫu) và Chương 14 (Newton &amp;amp; tự hài hòa): vì sao khoảng cách đối ngẫu lại bằng đúng \(m/t\) chứ không phụ thuộc \(n\)? Vì sao v.0 bị hỏng còn v.1 lại chạy mượt? Tại sao chọn \(\mu\) quá lớn hay quá nhỏ đều không tốt? Và tại sao Pha I chỉ cần dừng ngay khi \(s &amp;lt; 0\)?&lt;/p&gt;

&lt;p&gt;Bộ câu hỏi trắc nghiệm này giúp bạn kiểm tra sắc bén toàn bộ chuỗi lập luận của Chương 15 — từ hàm chắn logarit, đường trung tâm, KKT nhiễu, khoảng cách dưới tối ưu, đến các phiên bản thuật toán v.0/v.1/v.2 và Pha I. Hãy lướt qua bốn điểm hay gài bẫy nhất trước khi vào bài.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-điểm-hay-nhầm-lẫn-nhất-trong-trắc-nghiệm-chương-15&quot;&gt;Kiến thức cần nhớ: Bốn điểm hay nhầm lẫn nhất trong trắc nghiệm Chương 15&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(m\) là số ràng buộc bất đẳng thức, KHÔNG phải số chiều \(n\) hay số ràng buộc đẳng thức:&lt;/strong&gt; Công thức \(f(x^*(t)) - f^* \le m/t\) chỉ đếm số hàm bất đẳng thức \(h_i(x) \le 0\) tạo nên hàm chắn \(\phi(x)\) (ràng buộc đẳng thức \(Ax = b\) không nằm trong \(\phi\) nên không đóng góp vào \(m\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mục tiêu chắn \(t f(x) + \phi(x)\) vs. \(f(x) + \frac{1}{t}\phi(x)\):&lt;/strong&gt; Hai dạng có cùng nghiệm \(x^*(t)\), nhưng dạng \(t f(x) + \phi(x)\) giữ nguyên tính tự hài hòa của \(\phi(x)\) khi \(t\) lớn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tâm giải tích (\(t \to 0\)) vs. Nghiệm tối ưu (\(t \to \infty\)):&lt;/strong&gt; Đầu \(t \to 0\) là tâm giải tích (chỉ phụ thuộc hình học ràng buộc); đầu \(t \to \infty\) mới là nghiệm tối ưu \(x^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng Pha I:&lt;/strong&gt; Không cần đợi Pha I hội tụ đến cực tiểu \(s^*\); ngay khi tìm được bất kỳ cặp \((x, s)\) nào có \(s &amp;lt; 0\) là \(x\) đã khả thi chặt cho bài toán gốc (còn nếu \(s^* &amp;gt; 0\) thì bài toán gốc vô nghiệm).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-mẫu-câu-hỏi-bẫy-về-số-ràng-buộc-m-khi-có-cả-ràng-buộc-đẳng-thức&quot;&gt;Giải thích: Giải mẫu câu hỏi bẫy về số ràng buộc \(m\) khi có cả ràng buộc đẳng thức&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi mẫu:&lt;/strong&gt; Một bài toán quy hoạch tuyến tính có \(n = 50\) biến, \(p = 15\) ràng buộc đẳng thức \(Ax = b\), và \(m = 20\) ràng buộc bất đẳng thức \(h_i(x) \le 0\). Nếu điểm đường trung tâm \(x^*(t)\) ứng với \(t = 100\), chặn trên chắc chắn cho \(f(x^*(100)) - f^*\) là bao nhiêu?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Phân loại các ràng buộc:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(n = 50\): số chiều biến \(x\) — &lt;strong&gt;không&lt;/strong&gt; xuất hiện trong công thức \(m/t\).&lt;/li&gt;
      &lt;li&gt;\(p = 15\): số ràng buộc đẳng thức \(Ax = b\) — được giữ nguyên trực tiếp trong phương pháp Newton có ràng buộc đẳng thức, &lt;strong&gt;không&lt;/strong&gt; đưa vào hàm chắn logarit!&lt;/li&gt;
      &lt;li&gt;\(m = 20\): số ràng buộc bất đẳng thức — mỗi ràng buộc đóng góp đúng \(-\frac{1}{t}\) vào hiệu \(g(u^*(t), v^*(t)) - f(x^*(t))\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính khoảng cách dưới tối ưu:&lt;/strong&gt;
\(f(x^*(100)) - f^* \le \frac{m}{t} = \frac{20}{100} = 0.2.\)
(Nhiều bạn dễ nhầm lấy \((20 + 15)/100 = 0.35\) hoặc \(50/100 = 0.5\) — hãy nhớ chỉ đếm các ràng buộc nằm trong hàm chắn \(\phi\)!).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập trắc nghiệm, hãy ôn lại các khái niệm chính của chương này:&lt;/p&gt;

&lt;h3 id=&quot;-phương-pháp-chắn-barrier-method&quot;&gt;⚡ &lt;strong&gt;Phương pháp chắn (Barrier Method)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-tối-ưu-có-ràng-buộc-bất-đẳng-thức&quot;&gt;&lt;strong&gt;Bài toán tối ưu có ràng buộc bất đẳng thức&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) \quad 	ext{s.t.} \quad h_i(x) \le 0, \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;với \(i = 1,\ldots,m\).&lt;/p&gt;

&lt;h4 id=&quot;khó-khăn-khi-tối-ưu-trực-tiếp-trên-biên&quot;&gt;&lt;strong&gt;Khó khăn khi tối ưu trực tiếp trên biên&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc chặt và không chặt:&lt;/strong&gt; Khó xác định trước ràng buộc nào là tích cực (active) tại nghiệm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí khảo sát biên:&lt;/strong&gt; Phương pháp tập tích cực có thể tốn chi phí cao khi số ràng buộc \(m\) lớn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không khả vi:&lt;/strong&gt; Hàm chỉ thị \(I_C(x)\) không khả vi trên biên nên không áp dụng trực tiếp được phương pháp Newton.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;ý-tưởng-của-phương-pháp-điểm-trong&quot;&gt;&lt;strong&gt;Ý tưởng của phương pháp điểm trong&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Giải bài toán từ &lt;strong&gt;phần trong&lt;/strong&gt; của miền khả thi thay vì lần theo biên:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tránh bài toán tổ hợp xác định tập ràng buộc tích cực.&lt;/li&gt;
  &lt;li&gt;Thay hàm chỉ thị bằng hàm chắn trơn, khả vi hai lần.&lt;/li&gt;
  &lt;li&gt;Chuyển bài toán về chuỗi bài toán chỉ còn ràng buộc đẳng thức để giải bằng phương pháp Newton.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-hàm-chắn-logarit-logarithmic-barrier-function&quot;&gt;🚧 &lt;strong&gt;Hàm chắn logarit (Logarithmic Barrier Function)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;xấp-xỉ-hàm-chỉ-thị&quot;&gt;&lt;strong&gt;Xấp xỉ hàm chỉ thị&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Hàm chỉ thị gốc:&lt;/strong&gt; \(I_C(x) = egin{cases} 0 &amp;amp; 	ext{if } x \in C \ \infty &amp;amp; 	ext{otherwise} \end{cases}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm chắn logarit:&lt;/strong&gt; \(\phi(x) = -\sum_{i=1}^m \log(-h_i(x))\)&lt;/p&gt;

&lt;h4 id=&quot;tính-chất-của-hàm-chắn-logarit&quot;&gt;&lt;strong&gt;Tính chất của hàm chắn logarit&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Miền xác định:&lt;/strong&gt; \(\{x : h_i(x) &amp;lt; 0 \quad orall i\}\) (miền khả thi chặt).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính trơn:&lt;/strong&gt; Khả vi hai lần trên phần trong miền khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu ứng chắn:&lt;/strong&gt; \(\phi(x) 	o \infty\) khi \(x\) tiến sát biên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính tự hài hòa:&lt;/strong&gt; Khi các \(h_i\) là hàm affine hoặc bậc hai lồi, \(\phi\) là hàm tự hài hòa, cho phép phân tích hội tụ bất biến affine của phương pháp Newton.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;bài-toán-chắn&quot;&gt;&lt;strong&gt;Bài toán chắn&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Bài toán gốc:&lt;/strong&gt; \(\min f(x)\) thỏa mãn \(h_i(x) \le 0, Ax = b\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán chắn tương ứng (với tham số chắn \(t &amp;gt; 0\)):&lt;/strong&gt;
\(\min_x tf(x) + \phi(x) \quad 	ext{s.t.} \quad Ax = b\)&lt;/p&gt;

&lt;h4 id=&quot;vai-trò-của-tham-số-t&quot;&gt;&lt;strong&gt;Vai trò của tham số \(t\)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(t\) nhỏ:&lt;/strong&gt; Hàm chắn chi phối, đẩy nghiệm vào sâu bên trong miền khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(t\) lớn:&lt;/strong&gt; Hàm mục tiêu gốc \(f(x)\) chi phối mạnh hơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khi \(t 	o \infty\):&lt;/strong&gt; Bài toán chắn hội tụ về bài toán gốc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-đường-trung-tâm-central-path&quot;&gt;🛤️ &lt;strong&gt;Đường trung tâm (Central Path)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa&quot;&gt;&lt;strong&gt;Định nghĩa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Đường trung tâm:&lt;/strong&gt; \(\{x^*(t) : t &amp;gt; 0\}\), trong đó \(x^*(t) = rg\min_x \{tf(x) + \phi(x) : Ax = b\}\).&lt;/p&gt;

&lt;h4 id=&quot;tính-chất&quot;&gt;&lt;strong&gt;Tính chất&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Tạo thành một đường cong trơn trong \(\mathbb{R}^n\).&lt;/li&gt;
  &lt;li&gt;Hội tụ về nghiệm tối ưu gốc: \(x^*(t) 	o x^*\) khi \(t 	o \infty\).&lt;/li&gt;
  &lt;li&gt;Mọi điểm \(x^*(t)\) đều khả thi chặt.&lt;/li&gt;
  &lt;li&gt;Với mỗi \(t &amp;gt; 0\), điểm \(x^*(t)\) là duy nhất dưới điều kiện lồi chặt.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-điều-kiện-kkt-nhiễu-và-diễn-giải&quot;&gt;📊 &lt;strong&gt;Điều kiện KKT nhiễu và diễn giải&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;điều-kiện-kkt-của-bài-toán-chắn&quot;&gt;&lt;strong&gt;Điều kiện KKT của bài toán chắn&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Cho bài toán \(\min tf(x) + \phi(x)\) thỏa mãn \(Ax = b\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt; \(t
abla f(x^*(t)) + 
abla \phi(x^*(t)) + A^T 
u^*(t) = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả thi nguyên thủy:&lt;/strong&gt; \(Ax^*(t) = b\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;điều-kiện-kkt-của-bài-toán-gốc&quot;&gt;&lt;strong&gt;Điều kiện KKT của bài toán gốc&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Cho bài toán \(\min f(x)\) thỏa mãn \(h_i(x) \le 0, Ax = b\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt; \(abla f(x^*) + \sum_{i=1}^m \lambda_i^* 
abla h_i(x^*) + A^T 
u^* = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ lệch bù:&lt;/strong&gt; \(\lambda_i^* h_i(x^*) = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả thi đối ngẫu:&lt;/strong&gt; \(\lambda_i^* \ge 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả thi nguyên thủy:&lt;/strong&gt; \(h_i(x^*) \le 0, Ax^* = b\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;mối-liên-hệ&quot;&gt;&lt;strong&gt;Mối liên hệ&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Từ \(abla \phi(x) = -\sum_{i=1}^m rac{1}{h_i(x)} 
abla h_i(x)\), đặt \(\lambda_i^*(t) = -rac{1}{th_i(x^*(t))}\) ta thu được &lt;strong&gt;điều kiện KKT nhiễu&lt;/strong&gt; với \(\lambda_i^*(t) h_i(x^*(t)) = -rac{1}{t}\).&lt;/p&gt;

&lt;h3 id=&quot;-khoảng-cách-dưới-tối-ưu-suboptimality-gap&quot;&gt;📈 &lt;strong&gt;Khoảng cách dưới tối ưu (Suboptimality Gap)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-lý&quot;&gt;&lt;strong&gt;Định lý&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f(x^*(t)) - f^* \le rac{m}{t}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý tưởng chứng minh:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Xây dựng điểm khả thi đối ngẫu từ nghiệm trên đường trung tâm.&lt;/li&gt;
  &lt;li&gt;Áp dụng đối ngẫu yếu: \(f(x^*(t)) - f^* \le 	ext{duality gap}\).&lt;/li&gt;
  &lt;li&gt;Khoảng cách đối ngẫu tại \(x^*(t)\) đúng bằng \(rac{m}{t}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;ý-nghĩa-thực-hành&quot;&gt;&lt;strong&gt;Ý nghĩa thực hành&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Để đạt nghiệm chính xác \(\epsilon\), chỉ cần \(t \ge rac{m}{\epsilon}\).&lt;/li&gt;
  &lt;li&gt;Đánh đổi: \(t\) càng lớn thì xấp xỉ càng sát nhưng bài toán con càng khó giải.&lt;/li&gt;
  &lt;li&gt;Tiêu chí dừng: \(rac{m}{t} &amp;lt; \epsilon\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-các-phiên-bản-thuật-toán-phương-pháp-chắn&quot;&gt;🔄 &lt;strong&gt;Các phiên bản thuật toán phương pháp chắn&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;phương-pháp-chắn-v0-giải-trực-tiếp-một-lần&quot;&gt;&lt;strong&gt;Phương pháp chắn v.0 (giải trực tiếp một lần)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Chọn trực tiếp \(t = rac{m}{\epsilon}\) và giải \(\min tf(x) + \phi(x)\) thỏa mãn \(Ax = b\). Cách này kém hiệu quả vì với \(t\) quá lớn, ma trận Hessian có số điều kiện rất xấu và phương pháp Newton hội tụ chậm.&lt;/p&gt;

&lt;h4 id=&quot;phương-pháp-chắn-v1-bám-đường-trung-tâm&quot;&gt;&lt;strong&gt;Phương pháp chắn v.1 (bám đường trung tâm)&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;Chọn \(t^{(0)} &amp;gt; 0\), đặt \(k = 0\).&lt;/li&gt;
  &lt;li&gt;Giải bài toán chắn tại \(t^{(0)}\) để thu được \(x^{(0)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trong khi&lt;/strong&gt; \(rac{m}{t^{(k)}} &amp;gt; \epsilon\):
    &lt;ul&gt;
      &lt;li&gt;Cập nhật \(t^{(k+1)} = \mu t^{(k)}\) (với \(\mu &amp;gt; 1\)).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Khởi động ấm (warm start):&lt;/strong&gt; Dùng \(x^{(k)}\) làm điểm khởi tạo cho phương pháp Newton.&lt;/li&gt;
      &lt;li&gt;Giải bài toán chắn tại \(t^{(k+1)}\) để thu được \(x^{(k+1)}\).&lt;/li&gt;
      &lt;li&gt;Tăng \(k \leftarrow k + 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;các-thành-phần-chính&quot;&gt;&lt;strong&gt;Các thành phần chính&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước định tâm (centering step):&lt;/strong&gt; Giải bài toán chắn cho một \(t\) cố định (vòng lặp ngoài).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước Newton:&lt;/strong&gt; Các vòng lặp bên trong của mỗi bước định tâm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khởi động ấm:&lt;/strong&gt; Dùng nghiệm trước làm điểm xuất phát cho bước sau.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-đánh-đổi-khi-chọn-tham-số&quot;&gt;⚖️ &lt;strong&gt;Đánh đổi khi chọn tham số&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hệ số tăng \(\mu\):&lt;/strong&gt; \(\mu\) quá nhỏ làm tăng số vòng lặp ngoài; \(\mu\) quá lớn làm tăng số bước Newton ở mỗi bước định tâm. Giá trị thường dùng là \(\mu = 10\) đến \(50\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tham số khởi tạo \(t^{(0)}\):&lt;/strong&gt; \(t^{(0)}\) quá nhỏ làm tăng số vòng lặp ngoài; \(t^{(0)}\) quá lớn khiến bước định tâm đầu tiên khó giải.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính ổn định:&lt;/strong&gt; Trong thực tế, hiệu năng của phương pháp chắn khá bền vững trên một dải rộng của \((\mu, t^{(0)})\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-phân-tích-hội-tụ&quot;&gt;📊 &lt;strong&gt;Phân tích hội tụ&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Giả sử mỗi bước định tâm được giải chính xác, sau \(k\) vòng lặp ngoài ta có:
\(f(x^{(k)}) - f^* \le rac{m}{\mu^k t^{(0)}}\)&lt;/p&gt;

&lt;p&gt;Số vòng lặp ngoài để đạt sai số \(\epsilon\) là:
\(ext{Số vòng lặp ngoài} = rac{\log(m/(t^{(0)}\epsilon))}{\log \mu} + 1\)&lt;/p&gt;

&lt;p&gt;Bậc hội tụ là \(O(\log(1/\epsilon))\) (hội tụ tuyến tính). So với gradient descent tổng quát (\(O(1/\epsilon)\)) và phương pháp Newton không ràng buộc (\(O(\log\log(1/\epsilon))\)), tốc độ tuyến tính là kết quả tốt cho bài toán có ràng buộc bất đẳng thức.&lt;/p&gt;

&lt;h3 id=&quot;-phương-pháp-tìm-điểm-khả-thi-phase-i&quot;&gt;🎯 &lt;strong&gt;Phương pháp tìm điểm khả thi (Phase I)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Để bắt đầu phương pháp chắn, cần một điểm khả thi chặt thỏa mãn \(h_i(x) &amp;lt; 0 \;orall i\) và \(Ax = b\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa mức bất khả thi lớn nhất:&lt;/strong&gt; \(\min_{x,s} s \quad 	ext{s.t.} \quad h_i(x) \le s, \quad Ax = b\). Nếu tìm được cặp khả thi có \(s &amp;lt; 0\) thì \(x\) là điểm khả thi chặt; nếu tối ưu \(s^* &amp;gt; 0\) thì bài toán gốc vô nghiệm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng mức bất khả thi cho từng ràng buộc:&lt;/strong&gt; \(\min_{x,s} \mathbf{1}^T s \quad 	ext{s.t.} \quad h_i(x) \le s_i, \quad Ax = b, \quad s \succeq 0\). Nghiệm tối ưu \(s^* = 0\) tương đương bài toán gốc khả thi, đồng thời chỉ rõ ràng buộc nào bị vi phạm nếu bài toán vô nghiệm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-chi-tiết-cài-đặt-và-ví-dụ-lp&quot;&gt;🛠️ &lt;strong&gt;Chi tiết cài đặt và ví dụ LP&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;gradient-và-hessian-của-bài-toán-chắn&quot;&gt;&lt;strong&gt;Gradient và Hessian của bài toán chắn&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient:&lt;/strong&gt; \(abla (tf + \phi) = t
abla f - \sum_{i=1}^m rac{1}{h_i(x)} 
abla h_i\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hessian:&lt;/strong&gt; \(abla^2 (tf + \phi) = t
abla^2 f + \sum_{i=1}^m rac{1}{h_i^2(x)} 
abla h_i 
abla h_i^T - \sum_{i=1}^m rac{1}{h_i(x)} 
abla^2 h_i\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;ví-dụ-quy-hoạch-tuyến-tính-lp&quot;&gt;&lt;strong&gt;Ví dụ quy hoạch tuyến tính (LP)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Với bài toán \(\min c^T x\) thỏa mãn \(Ax = b, \; x \ge 0\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán chắn:&lt;/strong&gt; \(\min tc^T x - \sum_{i=1}^n \log x_i\) thỏa mãn \(Ax = b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện KKT đường trung tâm:&lt;/strong&gt; \(tc + A^T 
u - X^{-1} e = 0, \quad Ax = b\) (với \(X = 	ext{diag}(x)\), \(e = (1,\ldots,1)^T\)), tương ứng độ lệch bù nhiễu \(x_i \lambda_i = rac{1}{t}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-kết-nối-và-lưu-ý-thực-hành&quot;&gt;🎯 &lt;strong&gt;Kết nối và lưu ý thực hành&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Liên hệ kiến thức:&lt;/strong&gt; Phương pháp chắn kế thừa phương pháp Newton (Chương 14), điều kiện KKT (Chương 12) và lý thuyết đối ngẫu (Chương 11), đồng thời mở đường cho các phương pháp điểm trong nguyên thủy–đối ngẫu (primal-dual), nhúng đồng nhất và tối ưu nón (SOCP, SDP).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý triển khai:&lt;/strong&gt; Luôn giữ điểm lặp khả thi chặt (\(h_i(x) &amp;lt; 0\)) thông qua backtracking line search; tận dụng khởi động ấm; theo dõi số điều kiện Hessian khi \(t\) lớn; và thực hiện bước Phase I khi chưa có sẵn điểm khả thi chặt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt; Các bộ giải quy hoạch tuyến tính, bậc hai và nón (như CPLEX, Gurobi, MOSEK, Clarabel), tối ưu danh mục đầu tư, điều khiển tối ưu, thiết kế kỹ thuật và học máy.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra kiến thức về phương pháp chắn (barrier method), bao gồm phương pháp điểm trong, hàm chắn logarit, đường trung tâm, phân tích hội tụ và các phương pháp tìm điểm khả thi.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🚧 Bài tập trắc nghiệm: Phương pháp chắn và điểm trong&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 4%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;25&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: Barrier method concept --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Phương pháp chắn (barrier method) xử lý các ràng buộc bất đẳng thức bằng cách:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Chuyển trực tiếp thành ràng buộc đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Thêm hàm chắn vào hàm mục tiêu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Loại bỏ các ràng buộc bất đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Dùng hàm phạt bên ngoài miền khả thi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Thêm hàm chắn vào hàm mục tiêu&lt;/strong&gt;&lt;br /&gt;
                Phương pháp chắn bổ sung hàm chắn vào hàm mục tiêu để giữ mọi điểm lặp nằm trong phần trong miền khả thi, tránh vi phạm ràng buộc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Log barrier function --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Hàm chắn logarit cho ràng buộc \(g_i(x) \leq 0\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(-\log(-g_i(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\log(g_i(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(-\log(g_i(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(\log(-g_i(x))\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$-\log(-g_i(x))$$&lt;/strong&gt;&lt;br /&gt;
                Hàm chắn logarit $$-\log(-g_i(x))$$ xác định khi $$g_i(x) &amp;lt; 0$$ và tiến tới $$+\infty$$ khi $$g_i(x) 	o 0^-$$ (tiến sát biên).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Barrier problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Bài toán chắn (barrier problem) có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(\min tf(x) + \phi(x)\) thỏa mãn \(Ax = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(\min f(x) + t\phi(x)\) thỏa mãn \(Ax = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \(\min f(x) - t\phi(x)\) thỏa mãn \(Ax = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \(\min f(x)\) thỏa mãn \(Ax = b, g(x) \leq 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\min tf(x) + \phi(x)$$ thỏa mãn $$Ax = b$$&lt;/strong&gt;&lt;br /&gt;
                Với tham số $$t &amp;gt; 0$$, khi $$t 	o \infty$$ nghiệm của bài toán chắn hội tụ về nghiệm của bài toán gốc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Central path --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Đường trung tâm (central path) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Tập hợp \(\{x^*(t) | t &amp;gt; 0\}\) với \(x^*(t)\) là nghiệm của bài toán chắn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Đoạn thẳng nối điểm khởi tạo với điểm tối ưu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Tâm hình học của miền khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Quỹ đạo của gradient descent&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Tập hợp $$\{x^*(t) | t &amp;gt; 0\}$$ với $$x^*(t)$$ là nghiệm của bài toán chắn&lt;/strong&gt;&lt;br /&gt;
                Đường trung tâm là quỹ đạo nghiệm tối ưu $$x^*(t)$$ của bài toán chắn khi tham số $$t$$ biến thiên từ $$0$$ đến $$\infty$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Central path properties --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Khi \(t 	o \infty\), đường trung tâm có tính chất:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Hội tụ về nghiệm tối ưu của bài toán gốc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Phân kỳ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Dao động không hội tụ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Tiến tới một điểm bất kỳ trên biên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Hội tụ về nghiệm tối ưu của bài toán gốc&lt;/strong&gt;&lt;br /&gt;
                Khi $$t 	o \infty$$, trọng số tương đối $$rac{1}{t}$$ của hàm chắn tiến về 0 nên $$x^*(t)$$ tiến về nghiệm tối ưu $$x^*$$ của bài toán gốc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: KKT conditions for barrier --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Điều kiện dừng KKT của bài toán chắn tại \(x^*(t)\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(t
abla f(x) + \sum rac{1}{-g_i(x)} 
abla g_i(x) + A^T
u = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(
abla f(x) + \sum \lambda_i 
abla g_i(x) + A^T
u = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(t
abla f(x) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(
abla f(x) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$t
abla f(x) + \sum rac{1}{-g_i(x)} 
abla g_i(x) + A^T
u = 0$$&lt;/strong&gt;&lt;br /&gt;
                Từ điều kiện dừng $$t
abla f(x) + 
abla \phi(x) + A^T
u = 0$$ với $$
abla \phi(x) = \sum rac{1}{-g_i(x)} 
abla g_i(x)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Dual variables interpretation --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Biến đối ngẫu tương ứng với điểm đường trung tâm \(x^*(t)\) được xác định bởi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) \(\lambda_i^*(t) = rac{1}{t(-g_i(x^*(t)))}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(\lambda_i^*(t) = t(-g_i(x^*(t)))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) \(\lambda_i^*(t) = -g_i(x^*(t))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(\lambda_i^*(t) = rac{1}{-g_i(x^*(t))}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\lambda_i^*(t) = rac{1}{t(-g_i(x^*(t)))}$$&lt;/strong&gt;&lt;br /&gt;
                Biến đối ngẫu này luôn dương, khả thi đối ngẫu và hội tụ về biến đối ngẫu tối ưu khi $$t 	o \infty$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Duality gap --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Khoảng cách đối ngẫu (duality gap) tại điểm đường trung tâm \(x^*(t)\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(rac{m}{t}\) với \(m\) là số ràng buộc bất đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(rac{1}{t}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(mt\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(t\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$rac{m}{t}$$ với $$m$$ là số ràng buộc bất đẳng thức&lt;/strong&gt;&lt;br /&gt;
                Khoảng cách đối ngẫu $$\eta = f(x^*(t)) - g(\lambda^*(t), 
u^*(t)) = rac{m}{t}$$, tiến về 0 khi tăng $$t$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Barrier method algorithm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Nguyên lý vận hành của thuật toán phương pháp chắn là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) Tăng dần \(t\) theo dãy và giải bài toán chắn ứng với mỗi giá trị \(t\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) Giảm dần \(t\) theo dãy&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) Giữ \(t\) cố định trong suốt thuật toán&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) Chọn \(t\) ngẫu nhiên ở mỗi bước&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Tăng dần $$t$$ theo dãy và giải bài toán chắn ứng với mỗi giá trị $$t$$&lt;/strong&gt;&lt;br /&gt;
                Thuật toán bắt đầu từ $$t^{(0)}$$, giải bài toán chắn rồi cập nhật $$t^{(k+1)} = \mu t^{(k)}$$ với $$\mu &amp;gt; 1$$ cho đến khi $$m/t \le \epsilon$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Centering step --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Bước định tâm (centering step) trong phương pháp chắn là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) Giải bài toán chắn ứng với một giá trị \(t\) cố định bằng phương pháp Newton&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) Tìm tâm hình học của miền khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Cập nhật tham số \(t\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) Kiểm tra tính khả thi của nghiệm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Giải bài toán chắn ứng với một giá trị $$t$$ cố định bằng phương pháp Newton&lt;/strong&gt;&lt;br /&gt;
                Bước định tâm giải $$\min tf(x) + \phi(x)$$ thỏa mãn $$Ax = b$$ để tìm điểm $$x^*(t)$$ (hoặc xấp xỉ đủ tốt của nó) trên đường trung tâm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Self-concordance of log barrier --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Khi các \(g_i\) là hàm affine, hàm chắn logarit \(-\log(-g_i(x))\) có tính chất:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Tự hài hòa (self-concordant)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Trơn (khả vi vô hạn trên phần trong miền khả thi)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Tất cả các tính chất trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các tính chất trên&lt;/strong&gt;&lt;br /&gt;
                Khi $$g_i$$ là hàm affine, hàm chắn logarit vừa lồi, trơn, vừa tự hài hòa, giúp đảm bảo cận hội tụ lý thuyết cho phương pháp Newton. (Với $$g_i$$ lồi tổng quát, hàm chắn vẫn lồi và trơn nhưng không nhất thiết tự hài hòa.)
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Feasibility methods --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Bài toán Phase I cơ bản để tìm điểm xuất phát khả thi chặt có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) \(\min s\) thỏa mãn \(g_i(x) \leq s, Ax = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) \(\min \|g(x)\|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) \(\min f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) \(\min \|x\|\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\min s$$ thỏa mãn $$g_i(x) \leq s, Ax = b$$&lt;/strong&gt;&lt;br /&gt;
                Phase I cực tiểu hóa biến phụ $$s$$. Nếu nghiệm tối ưu $$s^* &amp;lt; 0$$ thì tồn tại điểm khả thi chặt; nếu $$s^* &amp;gt; 0$$ thì bài toán gốc vô nghiệm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Convergence rate --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Số vòng lặp ngoài của phương pháp chắn để đạt độ chính xác \(\epsilon\) có bậc:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(O(\log(1/\epsilon))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(O(1/\epsilon)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(O(\sqrt{1/\epsilon})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(O(1/\epsilon^2)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$O(\log(1/\epsilon))$$&lt;/strong&gt;&lt;br /&gt;
                Với quy tắc nhân $$t^{(k+1)} = \mu t^{(k)}$$, số vòng lặp ngoài để thu nhỏ khoảng cách đối ngẫu về dưới $$\epsilon$$ tăng theo $$O(\log(1/\epsilon))$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Newton decrement in barrier --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Đại lượng giảm Newton (Newton decrement) trong phương pháp chắn được dùng để:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Làm tiêu chí dừng cho bước định tâm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Cập nhật trực tiếp tham số \(t\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Kiểm tra tính khả thi của ràng buộc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Tính khoảng cách đối ngẫu \(m/t\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Làm tiêu chí dừng cho bước định tâm&lt;/strong&gt;&lt;br /&gt;
                Điều kiện $$\lambda(x) \leq \eta$$ kiểm soát mức độ gần đường trung tâm trước khi tăng tham số $$t$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Primal-dual methods --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Phương pháp điểm trong nguyên thủy–đối ngẫu (primal-dual) khác phương pháp chắn ở chỗ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Cập nhật đồng thời cả biến nguyên thủy và biến đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Không liên quan đến đường trung tâm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Chỉ áp dụng cho quy hoạch tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Không sử dụng phương pháp Newton&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Cập nhật đồng thời cả biến nguyên thủy và biến đối ngẫu&lt;/strong&gt;&lt;br /&gt;
                Phương pháp nguyên thủy–đối ngẫu cập nhật trực tiếp bộ $$(x, \lambda, 
u)$$ cùng lúc thay vì chỉ giải tìm $$x$$ ở từng vòng lặp ngoài.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Barrier parameter update --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Quy tắc cập nhật tham số chắn thường dùng trong thực hành là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(t^{(k+1)} = \mu t^{(k)}\) với \(\mu = 10\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(t^{(k+1)} = t^{(k)} + 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(t^{(k+1)} = 2t^{(k)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(t^{(k+1)} = (t^{(k)})^2\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$t^{(k+1)} = \mu t^{(k)}$$ với $$\mu = 10$$&lt;/strong&gt;&lt;br /&gt;
                Giá trị $$\mu pprox 10$$ (hoặc trong khoảng 10–50) thường cân bằng tốt giữa số vòng lặp ngoài và số bước Newton trong mỗi bước định tâm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Barrier method advantages --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Ưu điểm của phương pháp chắn là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Có độ phức tạp đa thức về mặt lý thuyết&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Tận dụng tốt khởi động ấm (warm start) giữa các bước định tâm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Xử lý ràng buộc bất đẳng thức mà không cần xác định tập tích cực&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Tất cả các ưu điểm trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các ưu điểm trên&lt;/strong&gt;&lt;br /&gt;
                Phương pháp chắn có độ phức tạp đa thức, tận dụng khởi động ấm hiệu quả và xử lý tự nhiên số lượng lớn ràng buộc bất đẳng thức.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Linear programming barrier --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Cho bài toán LP: \(\min c^Tx\) thỏa mãn \(Ax = b, x \geq 0\). Hàm chắn logarit tương ứng là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) \(-\sum_{i=1}^n \log x_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) \(\sum_{i=1}^n \log x_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) \(-\sum_{i=1}^n x_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) \(\sum_{i=1}^n x_i^2\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$-\sum_{i=1}^n \log x_i$$&lt;/strong&gt;&lt;br /&gt;
                Với các ràng buộc $$-x_i \leq 0$$ (tức $$x_i \geq 0$$), hàm chắn logarit là $$-\sum_{i=1}^n \log x_i$$, giữ chặt $$x_i &amp;gt; 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Barrier method vs penalty method --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Phương pháp chắn (barrier) khác phương pháp phạt (penalty) ở điểm nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Phương pháp chắn luôn giữ các điểm lặp bên trong miền khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Phương pháp phạt cho phép các điểm lặp vi phạm ràng buộc trong quá trình tối ưu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Phương pháp chắn đòi hỏi điểm khởi tạo khả thi chặt&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Tất cả các điểm trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các điểm trên&lt;/strong&gt;&lt;br /&gt;
                Phương pháp chắn duy trì tính khả thi chặt ở mọi bước và cần điểm khởi tạo khả thi chặt, trái ngược với phương pháp phạt tiếp cận nghiệm từ bên ngoài miền khả thi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Các phương pháp điểm trong được ứng dụng trong:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Các bộ giải quy hoạch tuyến tính (LP)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Quy hoạch nửa xác định (SDP)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Các thư viện tối ưu lồi hiện đại&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các ứng dụng trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các ứng dụng trên&lt;/strong&gt;&lt;br /&gt;
                Phương pháp điểm trong là thuật toán nền tảng của nhiều bộ giải như CPLEX, Gurobi, CVX, MOSEK và Clarabel.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Phương pháp chắn biến đổi bài toán có ràng buộc bất đẳng thức thành:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Chuỗi bài toán không có ràng buộc bất đẳng thức (không ràng buộc hoặc chỉ có ràng buộc đẳng thức)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Một bài toán tuyến tính duy nhất&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Một bài toán QP không tham số&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Một bài toán SDP&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Chuỗi bài toán không có ràng buộc bất đẳng thức&lt;/strong&gt;&lt;br /&gt;
                Phương pháp chắn giải chuỗi bài toán $$\min t f(x) + \phi(x)$$ (tương đương $$\min f(x) + rac{1}{t}\phi(x)$$) với $$t 	o \infty$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Hàm chắn logarit cho hệ ràng buộc $$g_i(x) \leq 0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$-\sum \log(-g_i(x))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$\sum \log(g_i(x))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$\sum g_i(x)^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$\sum |g_i(x)|$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$-\sum \log(-g_i(x))$$&lt;/strong&gt;&lt;br /&gt;
                Hàm chắn logarit được định nghĩa là $$\phi(x) = -\sum_{i=1}^m \log(-g_i(x))$$ trên miền $$g_i(x) &amp;lt; 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Đường trung tâm trong phương pháp chắn là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Tập nghiệm của hệ $$t
abla f + 
abla \phi + A^T
u = 0$$ (cùng $$Ax = b$$) theo $$t &amp;gt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Đường thẳng đi qua nghiệm tối ưu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Biên của miền khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Quỹ đạo của gradient descent&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Tập nghiệm của hệ $$t
abla f + 
abla \phi + A^T
u = 0$$ (cùng $$Ax = b$$) theo $$t &amp;gt; 0$$&lt;/strong&gt;&lt;br /&gt;
                Mỗi điểm $$x^*(t)$$ trên đường trung tâm thỏa mãn điều kiện tối ưu $$t
abla f(x) + 
abla \phi(x) + A^T
u = 0$$ và $$Ax = b$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Khi $$t 	o \infty$$ trong phương pháp chắn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Nghiệm $$x^*(t)$$ tiến đến nghiệm tối ưu của bài toán gốc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Nghiệm phân kỳ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Hàm chắn luôn bằng 0&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Bài toán mất nghiệm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Nghiệm $$x^*(t)$$ tiến đến nghiệm tối ưu của bài toán gốc&lt;/strong&gt;&lt;br /&gt;
                Khi $$t 	o \infty$$, khoảng cách dưới tối ưu $$m/t 	o 0$$ nên nghiệm bài toán chắn hội tụ về nghiệm bài toán gốc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Với ràng buộc $$x &amp;gt; 0$$, đạo hàm của hàm chắn $$-\log x$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$-1/x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$1/x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$-x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$\log x$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$-1/x$$&lt;/strong&gt;&lt;br /&gt;
                Ta có $$rac{d}{dx}(-\log x) = -rac{1}{x}$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành bài tập trắc nghiệm!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;a&apos;, q3: &apos;a&apos;, q4: &apos;a&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;d&apos;, q12: &apos;a&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;a&apos;, q17: &apos;d&apos;, q18: &apos;a&apos;, q19: &apos;d&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã thành thạo barrier method và interior point optimization!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu tốt về central path và convergence analysis.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại log barrier function và duality gap.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Ôn lại barrier problem và KKT conditions.&apos;;
    } else {
        message = &apos;📖 Hãy học lại từ đầu về interior point methods nhé!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>15-08 Phương pháp chắn chính thức</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_08_formal_barrier_method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_08_formal_barrier_method</id>
   <content type="html">&lt;p&gt;Ở các mục trước, ta đã xây dựng phương pháp chắn dựa trên hàm chắn logarit cho ràng buộc vô hướng \(h_i(x) \le 0\). Nhưng nếu bài toán là &lt;strong&gt;Quy hoạch nón bậc hai (SOCP)&lt;/strong&gt; hay &lt;strong&gt;Quy hoạch nửa xác định (SDP)&lt;/strong&gt; (nơi biến là ma trận \(X \succeq 0\), ràng buộc không phải là \(m\) bất đẳng thức vô hướng mà là một nón lồi tổng quát), thì toàn bộ lý thuyết có còn đứng vững không?&lt;/p&gt;

&lt;p&gt;Mục 15-08 đưa phương pháp chắn lên tầm khái quát cao nhất của tối ưu lồi hiện đại nhờ định nghĩa &lt;strong&gt;hàm chắn tự hài hòa với tham số \(\nu\) (\(\nu\)-self-concordant barrier)&lt;/strong&gt; của Nesterov và Nemirovskii. Chỉ cần hàm chắn \(\phi\) thỏa hai bất đẳng thức gọn nhẹ (tự hài hòa và bình phương Newton decrement \(\lambda_\phi(x)^2 \le \nu\)), toàn bộ định lý hội tụ thời gian đa thức \(O\bigl(\sqrt{\nu}\log(\nu/(\epsilon t^{(0)}))\bigr)\) tự động áp dụng cho &lt;strong&gt;mọi lớp bài toán lồi&lt;/strong&gt;: LP, QP, SOCP và SDP!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-của-phương-pháp-chắn-chính-thức&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép của Phương pháp chắn chính thức&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa \(\nu\)-self-concordant barrier:&lt;/strong&gt; Hàm lồi \(\phi\) trên miền mở \(D\) thỏa hai điều kiện:
    &lt;ol&gt;
      &lt;li&gt;\(\phi\) là hàm tự hài hòa (\(\vert g&apos;&apos;&apos;(0) \vert \le 2(g&apos;&apos;(0))^{3/2}\) dọc mọi đường thẳng).&lt;/li&gt;
      &lt;li&gt;\(\nabla \phi(x)^T (\nabla^2 \phi(x))^{-1} \nabla \phi(x) \le \nu\) với mọi \(x \in D\) (bình phương Newton decrement của riêng \(\phi\) bị chặn đều bởi tham số độ phức tạp \(\nu\)!).&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tham số \(\nu\) cho các nón chuẩn:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nón không âm \(\mathbb{R}_+^m\) với \(\phi(x) = -\sum_{i=1}^m \log x_i\): \(\nu = m\).&lt;/li&gt;
      &lt;li&gt;Nón bậc hai \(\{(x, t) : \|x\|_2 \le t\}\) với \(\phi(x, t) = -\log(t^2 - \|x\|_2^2)\): \(\nu = 2\) (độc lập với số chiều \(n\)!).&lt;/li&gt;
      &lt;li&gt;Nón ma trận nửa xác định dương \(\mathbb{S}_+^n\) với \(\phi(X) = -\log\det X\): \(\nu = n\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý độ phức tạp thời gian đa thức:&lt;/strong&gt; Với bước tăng ngắn \(\mu = 1 + \frac{c}{\sqrt{\nu}}\), sau mỗi lần tăng \(t \leftarrow \mu t\), chỉ cần đúng &lt;strong&gt;1 bước Newton&lt;/strong&gt; để quay lại gần đường trung tâm, dẫn tới tổng số bước Newton là \(O\bigl(\sqrt{\nu}\log(\nu / (\epsilon t^{(0)}))\bigr)\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-tham-số-nu-cho-hàm-chắn-logarit-2-biến-phix_1-x_2---log-x_1---log-x_2&quot;&gt;Giải thích: Tính tay tham số \(\nu\) cho hàm chắn logarit 2 biến \(\phi(x_1, x_2) = -\log x_1 - \log x_2\)&lt;/h3&gt;

&lt;p&gt;Ta kiểm chứng trực tiếp rằng \(\phi(x_1, x_2) = -\log x_1 - \log x_2\) trên \(x_1 &amp;gt; 0, x_2 &amp;gt; 0\) là một hàm chắn tự hài hòa với tham số \(\nu = 2\) (tức \(m = 2\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính gradient và Hessian của \(\phi\):&lt;/strong&gt;
\(\nabla \phi(x) = \begin{bmatrix} -1/x_1 \\ -1/x_2 \end{bmatrix}, \qquad \nabla^2 \phi(x) = \begin{bmatrix} 1/x_1^2 &amp;amp; 0 \\ 0 &amp;amp; 1/x_2^2 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính nghịch đảo Hessian:&lt;/strong&gt;
\((\nabla^2 \phi(x))^{-1} = \begin{bmatrix} x_1^2 &amp;amp; 0 \\ 0 &amp;amp; x_2^2 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bình phương Newton decrement \(\lambda_\phi(x)^2 = \nabla \phi(x)^T (\nabla^2 \phi(x))^{-1} \nabla \phi(x)\):&lt;/strong&gt;
\(\lambda_\phi(x)^2 = \left(-\frac{1}{x_1}\right) x_1^2 \left(-\frac{1}{x_1}\right) + \left(-\frac{1}{x_2}\right) x_2^2 \left(-\frac{1}{x_2}\right) = 1 + 1 = 2.\)
Giá trị này bằng đúng \(\nu = 2\) tại &lt;strong&gt;mọi điểm&lt;/strong&gt; \((x_1, x_2) &amp;gt; 0\)! Tương tự, với \(m\) ràng buộc tuyến tính độc lập, \(\lambda_\phi(x)^2 = m\), giải thích vì sao tham số độ phức tạp của quy hoạch tuyến tính chính là \(\nu = m\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Một hàm lồi \(\phi : D \to \mathbb{R}\) xác định trên tập lồi mở \(D \subset \mathbb{R}^n\) được gọi là &lt;strong&gt;hàm chắn tự hài hòa (self-concordant barrier)&lt;/strong&gt; với tham số \(\nu\) nếu thỏa mãn hai điều kiện:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(\phi\) là hàm tự hài hòa (self-concordant).&lt;/li&gt;
  &lt;li&gt;Với mọi \(x \in D\), bình phương đại lượng giảm Newton (Newton decrement) của \(\phi\) bị chặn bởi \(\nu\):&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\lambda(x)^2 = \nabla \phi(x)^T (\nabla^2 \phi(x))^{-1} \nabla \phi(x) \le \nu\]
&lt;/blockquote&gt;

&lt;p&gt;Xét bài toán quy hoạch tuyến tính (LP) sau, với \(\bar{D}\) là bao đóng của miền \(D\):&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x} \           &amp;amp;&amp;amp; c^Tx \\
&amp;amp;\text{subject to } \ &amp;amp;&amp;amp; x \in \bar{D}  \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán này được xấp xỉ bởi bài toán chắn không ràng buộc:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp; tc^Tx + \phi(x) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Đặt \(\phi_t(x) := tc^Tx + \phi(x)\) và gọi \(\lambda_t(x)\) là đại lượng giảm Newton tương ứng của \(\phi_t\).&lt;/p&gt;

&lt;p&gt;Nhận xét quan trọng: khi tăng tham số lên \(t^+ &amp;gt; t\), ta có bất đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
\lambda_{t^+}(x) \le &amp;amp; \frac{t^+}{t}\lambda_t(x) + \left ( \frac{t^+}{t} -1 \right ) \sqrt{\nu}  \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;định-lý&quot;&gt;Định lý&lt;/h2&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \text{nếu} \quad \lambda_t(x) \le \frac{1}{9} \quad \text{và} \quad \frac{t^+}{t} \le 1 + \frac{1}{8 \sqrt{\nu}} \quad \text{thì} \quad \lambda_{t^+}(x^+) \le \frac{1}{9}  \\
&amp;amp; \qquad \qquad \text{với} \quad x^+ = x - (\nabla^2 \phi_{t^+}(x))^{-1} \nabla \phi_{t^+}(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Kết quả này cho thấy nếu xuất phát từ \(x^{(0)}, t^{(0)}\) thỏa \(\lambda_{t^{(0)}}(x^{(0)}) \lt \frac{1}{9}\) và chọn hệ số tăng \(\mu := 1 + \frac{1}{8 \sqrt{\nu}}\), thì mỗi bước định tâm chỉ cần đúng một bước Newton là đủ duy trì điều kiện bám đường trung tâm.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-07 Các phương pháp tìm điểm khả thi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_07_feasibility_methods/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_07_feasibility_methods</id>
   <content type="html">&lt;p&gt;Từ đầu Chương 15 đến giờ, ta luôn âm thầm giả định một điều kiện “trời cho”: &lt;em&gt;ta đã có sẵn một điểm xuất phát \(x^{(0)}\) khả thi chặt&lt;/em&gt; (\(h_i(x^{(0)}) &amp;lt; 0\) với mọi \(i\) và \(Ax^{(0)} = b\)) để thả vào phương pháp chắn. Nhưng trên thực tế, với một bài toán có 500 ràng buộc lồng ghép chằng chịt, &lt;strong&gt;chỉ riêng việc tìm ra MỘT điểm nằm bên trong miền khả thi thôi đôi khi đã khó ngang ngửa việc giải bài toán gốc!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lời giải đầy thông minh cho bài toán “con gà và quả trứng” này gọi là &lt;strong&gt;Phương pháp Pha I (Phase I)&lt;/strong&gt;: ta đặt thêm một biến phụ vô hướng \(s\) (hoặc vectơ \(s\)) đo &lt;em&gt;mức độ vi phạm ràng buộc&lt;/em&gt;, nới lỏng các bức tường thành \(h_i(x) \le s\), rồi dùng chính phương pháp chắn để &lt;strong&gt;cực tiểu hóa \(s\)&lt;/strong&gt;! Điều kỳ diệu là với bài toán Pha I này, việc tìm điểm khả thi chặt ban đầu dễ như trở bàn tay: chọn bất kỳ \(x_0\) nào thỏa \(Ax_0 = b\) rồi chọn \(s_0 &amp;gt; \max_i h_i(x_0)\) là xong!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hai-chiến-lược-pha-i-kinh-điển-tìm-điểm-khả-thi-chặt&quot;&gt;Kiến thức cần nhớ: Hai chiến lược Pha I kinh điển tìm điểm khả thi chặt&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược 1 — Cực tiểu hóa mức bất khả thi lớn nhất (1 biến phụ \(s\)):&lt;/strong&gt;
\(\min_{x, s} s \qquad \text{với điều kiện } h_i(x) \le s \;\;(i=1,\dots,m), \quad Ax = b.\)
    &lt;ul&gt;
      &lt;li&gt;Khởi tạo cực dễ: lấy bất kỳ \(x^{(0)}\) thỏa \(Ax^{(0)} = b\) và đặt \(s^{(0)} = \max_i h_i(x^{(0)}) + 1\) → lập tức có \(h_i(x^{(0)}) - s^{(0)} \le -1 &amp;lt; 0\) (khả thi chặt!).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tiêu chí dừng sớm cực lợi hại:&lt;/strong&gt; Ta &lt;strong&gt;không cần&lt;/strong&gt; giải Pha I tới tối ưu! Ngay khoảnh khắc thuật toán bước tới một điểm có \(s &amp;lt; 0\), điểm \(x\) tương ứng đã thỏa \(h_i(x) \le s &amp;lt; 0\) — dừng Pha I ngay và chuyển sang Pha II!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược 2 — Tổng mức bất khả thi từng ràng buộc (\(m\) biến phụ \(s_i \ge 0\)):&lt;/strong&gt;
\(\min_{x, s} \mathbf{1}^T s \qquad \text{với điều kiện } h_i(x) \le s_i, \;\; s_i \ge 0, \;\; Ax = b.\)
Rất hữu ích khi bài toán gốc &lt;strong&gt;vô nghiệm&lt;/strong&gt;: nghiệm Pha I sẽ chỉ rõ &lt;em&gt;chính xác những ràng buộc nào đang mâu thuẫn nhau&lt;/em&gt; (các ràng buộc có \(s_i^* &amp;gt; 0\))!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-thiết-lập-bài-toán-pha-i-cho-một-hệ-bất-đẳng-thức-1-chiều&quot;&gt;Giải thích: Chạy tay thiết lập bài toán Pha I cho một hệ bất đẳng thức 1 chiều&lt;/h3&gt;

&lt;p&gt;Giả sử ta cần tìm một điểm khả thi chặt cho hệ hai ràng buộc (không biết trước nghiệm nằm đâu):
\(h_1(x) = x - 5 \le 0, \qquad h_2(x) = 3 - x \le 0 \qquad (\text{miền trong thật là } (3, 5)).\)
Ta thử đại một điểm xuất phát bất kỳ: \(x^{(0)} = 0\) (rõ ràng bất khả thi vì \(h_2(0) = 3 &amp;gt; 0\)!).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập bài toán Pha I (chiến lược 1 biến \(s\)):&lt;/strong&gt;
\(\min_{x, s} s \qquad \text{với } x - 5 - s \le 0 \quad \text{và} \quad 3 - x - s \le 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm khả thi chặt ban đầu cho Pha I từ \(x^{(0)} = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tính \(h_1(0) = -5\), \(h_2(0) = 3 \implies \max(h_1, h_2) = 3\).&lt;/li&gt;
      &lt;li&gt;Chọn \(s^{(0)} = 3 + 1 = 4\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra độ dư tại \((x^{(0)}, s^{(0)}) = (0, 4)\):
\(h_1(0) - 4 = -9 &amp;lt; 0, \qquad h_2(0) - 4 = -1 &amp;lt; 0.\)
Hoàn toàn khả thi chặt cho bài toán Pha I!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan sát Pha I thu hẹp \(s\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Khi chạy phương pháp chắn giảm \(s\), cặp \((x, s)\) di chuyển về phía nghiệm tối ưu Pha I là \((x^*, s^*) = (4, -1)\).&lt;/li&gt;
      &lt;li&gt;Ngay khi thuật toán đi qua điểm \((x, s) = (3.8, -0.5)\) có \(s = -0.5 &amp;lt; 0\), ta kiểm tra bài toán gốc: \(h_1(3.8) = -1.2 &amp;lt; 0\) và \(h_2(3.8) = -0.8 &amp;lt; 0\)! Ta dừng Pha I ngay lập tức và lấy \(x = 3.8\) làm điểm khởi tạo khả thi chặt cho Pha II!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Cho đến nay, ta luôn giả sử bước định tâm đầu tiên (tại \(t = t^{(0)}\)) đã có sẵn một điểm xuất phát khả thi chặt để tìm \(x^{(0)} = x^*(t^{(0)})\).&lt;/p&gt;

&lt;p&gt;Một điểm \(x\) được gọi là khả thi chặt nếu thỏa mãn đồng thời:&lt;/p&gt;
&lt;blockquote&gt;
\[h_i(x) \lt 0, \quad i = 1, \cdots, m, \quad Ax = b\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;cực-tiểu-hóa-mức-bất-khả-thi-lớn-nhất&quot;&gt;Cực tiểu hóa mức bất khả thi lớn nhất&lt;/h2&gt;
&lt;p&gt;Để tìm một điểm \(x\) khả thi chặt, ta giải bài toán phụ (Phase I) sau:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x, s} \        &amp;amp;&amp;amp; s \\
&amp;amp;\text{subject to } \ &amp;amp;&amp;amp; h_i(x) \le s,&amp;amp; i = 1, \cdots, m \\
                      &amp;amp;&amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Mục tiêu của bài toán này là tìm nghiệm có \(s &amp;lt; 0\). Cách tiếp cận này được gọi là &lt;strong&gt;phương pháp tìm điểm khả thi (feasibility method)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Vì bài toán phụ này dễ dàng tìm được điểm xuất phát khả thi chặt (chỉ cần chọn \(x\) thỏa \(Ax = b\) rồi lấy \(s &amp;gt; \max_i h_i(x)\)), ta có thể giải trực tiếp nó bằng phương pháp chắn.&lt;/p&gt;

&lt;p&gt;Khi giải bài toán tìm điểm khả thi, không cần đạt độ chính xác cao; chỉ cần dừng ngay khi tìm được một cặp \((x, s)\) khả thi với \(s &amp;lt; 0\).&lt;/p&gt;

&lt;h2 id=&quot;cực-tiểu-hóa-mức-bất-khả-thi-cho-từng-ràng-buộc&quot;&gt;Cực tiểu hóa mức bất khả thi cho từng ràng buộc&lt;/h2&gt;
&lt;p&gt;Một biến thể khác là gán biến phụ \(s_i\) riêng cho từng ràng buộc bất đẳng thức (\(i = 1, \cdots, m\)) thay vì dùng chung một biến \(s\):&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x, s} \        &amp;amp;&amp;amp; 1^Ts \\
&amp;amp;\text{subject to } \ &amp;amp;&amp;amp; h_i(x) \le s_i,&amp;amp; i = 1, \cdots, m \\
                      &amp;amp;&amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ưu điểm của cách phát biểu này là dựa vào từng thành phần của nghiệm \(s\), ta biết cụ thể ràng buộc nào đang bị vi phạm: nếu có phần tử \(s_i \ge 0\) thì ràng buộc bất đẳng thức thứ \(i\) không được thỏa mãn chặt.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-06 Phương pháp chắn v.2</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_06_barrier_method_v2/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_06_barrier_method_v2</id>
   <content type="html">&lt;p&gt;Ở phiên bản v.1, ta yêu cầu mỗi bước định tâm phải giải &lt;em&gt;chính xác tuyệt đối&lt;/em&gt; bài toán \(\min t f(x) + \phi(x)\) để điểm lặp nằm khít trên đường trung tâm \(x^*(t)\). Nhưng hãy nghĩ lại một chút: &lt;strong&gt;đường trung tâm đâu phải đích đến cuối cùng của chúng ta!&lt;/strong&gt; Điểm \(x^*(t)\) ở các vòng đầu (khi \(t = 1\) hay \(t = 10\)) chỉ là trạm trung chuyển tạm thời. Việc tiêu tốn thêm nhiều bước Newton để tìm \(x^*(10)\) chính xác tới \(10^{-12}\) rồi ngay lập tức vứt đi để tăng \(t \leftarrow 100\) rõ ràng là một sự lãng phí!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp chắn v.2&lt;/strong&gt; khắc phục triệt để sự lãng phí ấy bằng một cải tiến thực dụng nhưng sâu sắc: ở mỗi vòng trong, ta &lt;strong&gt;không giải chính xác tuyệt đối&lt;/strong&gt;, mà chỉ cần chạy Newton cho đến khi &lt;strong&gt;đại lượng giảm Newton&lt;/strong&gt; thỏa \(\frac{1}{2}\lambda(x)^2 \le \epsilon_{\text{center}}\) (hoặc thậm chí chỉ chạy 1 bước Newton — chiến lược &lt;em&gt;short-step&lt;/em&gt;!), miễn là điểm lặp vẫn bám đủ gần đường trung tâm để bước tăng \(t\) kế tiếp an toàn.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-tư-duy-định-tâm-xấp-xỉ-inexact-centering-trong-v2&quot;&gt;Kiến thức cần nhớ: Tư duy định tâm xấp xỉ (Inexact Centering) trong v.2&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tại sao không cần định tâm chính xác tuyệt đối:&lt;/strong&gt; Mục tiêu duy nhất của vòng trong là đưa \(x\) vào vùng hội tụ bậc hai của bài toán chắn tại \(t\) để làm bệ phóng cho \(\mu t\). Khi Newton decrement \(\lambda(x)\) đã nhỏ (ví dụ \(\lambda(x) \le 0.25\)), điểm \(x\) đã ở sát \(x^*(t)\) rồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chí dừng vòng trong bằng Newton decrement:&lt;/strong&gt; Nhờ tính bất biến affine và ước lượng \(\frac{1}{2}\lambda(x)^2 \approx (tf(x)+\phi(x)) - (tf(x^*(t))+\phi(x^*(t)))\), ta dừng vòng trong ngay khi \(\frac{1}{2}\lambda(x)^2 \le \epsilon_{\text{inner}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều chỉnh chứng chỉ dừng ở vòng cuối:&lt;/strong&gt; Vì \(x\) chỉ nằm &lt;em&gt;gần&lt;/em&gt; \(x^*(t)\) chứ không trùng khít, sai số cuối cùng cần cộng thêm độ lệch định tâm nhỏ, hoặc chạy định tâm chính xác hơn chỉ ở đúng vòng ngoài cuối cùng khi \(m/t \le \epsilon\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-chi-phí-giữa-định-tâm-tuyệt-đối-v1-và-định-tâm-vừa-đủ-v2&quot;&gt;Giải thích: So sánh chi phí giữa định tâm tuyệt đối (v.1) và định tâm vừa đủ (v.2)&lt;/h3&gt;

&lt;p&gt;Xét một bài toán chắn tại bước trung gian \(t = 10\), trong đó Newton decrement giảm qua các bước Newton như sau (nhờ hội tụ bậc hai khi \(\lambda &amp;lt; 0.5\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Sau bước 1: \(\lambda_1 = 0.80 \implies \frac{1}{2}\lambda_1^2 = 0.32\).&lt;/li&gt;
  &lt;li&gt;Sau bước 2: \(\lambda_2 = 0.25 \implies \frac{1}{2}\lambda_2^2 = 0.03125\).&lt;/li&gt;
  &lt;li&gt;Sau bước 3: \(\lambda_3 = 0.04 \implies \frac{1}{2}\lambda_3^2 = 0.0008\).&lt;/li&gt;
  &lt;li&gt;Sau bước 4: \(\lambda_4 = 0.001 \implies \frac{1}{2}\lambda_4^2 = 5 \times 10^{-7}\).&lt;/li&gt;
  &lt;li&gt;Sau bước 5: \(\lambda_5 = 10^{-6} \implies \frac{1}{2}\lambda_5^2 = 5 \times 10^{-13}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cách làm của v.1 (đòi \(\frac{1}{2}\lambda^2 \le 10^{-10}\) ở mọi vòng ngoài):&lt;/strong&gt; Tốn &lt;strong&gt;5 bước Newton&lt;/strong&gt; ở ngay trạm trung gian \(t = 10\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách làm của v.2 (chỉ cần \(\frac{1}{2}\lambda^2 \le 0.05\) ở các vòng trung gian):&lt;/strong&gt; Dừng ngay sau &lt;strong&gt;2 bước Newton&lt;/strong&gt; (khi \(\frac{1}{2}\lambda_2^2 = 0.03125 \le 0.05\)) và lập tức tăng \(t \leftarrow \mu t\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu quả cộng dồn:&lt;/strong&gt; Qua 8 vòng ngoài, v.2 tiết kiệm hơn &lt;strong&gt;50% số lần phân rã Cholesky&lt;/strong&gt; mà vẫn cập bến cùng một nghiệm cuối với độ chính xác \(10^{-8}\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong phiên bản trước, thuật toán yêu cầu giải chính xác bài toán chắn để nghiệm nằm đúng trên đường trung tâm. Tuy nhiên, đường trung tâm chỉ là phương tiện dẫn tới nghiệm tối ưu chứ không phải đích đến cuối cùng, nên trên thực tế ta không cần giải chính xác tuyệt đối ở từng bước định tâm.&lt;/p&gt;

&lt;h3 id=&quot;thuật-toán&quot;&gt;Thuật toán&lt;/h3&gt;

&lt;p&gt;Từ nhận xét đó, &lt;strong&gt;phương pháp chắn v.2&lt;/strong&gt; chỉ giải xấp xỉ bài toán chắn ở mỗi bước: cụ thể, \(x^{(0)} \approx x^*(t)\) ở bước 2 và \(x^{(k+1)} \approx x^*(t)\) ở bước 3-2.&lt;/p&gt;

&lt;p&gt;Cấu trúc thuật toán giữ nguyên như phương pháp chắn v.1:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Chọn \(t^{(0)} &amp;gt; 0\) và đặt \(k := 0\).&lt;/li&gt;
  &lt;li&gt;Tại \(t = t^{(0)}\), giải xấp xỉ bài toán chắn để thu được \(x^{(0)} \approx x^*(t)\).&lt;/li&gt;
  &lt;li&gt;Trong khi \(m/t &amp;gt; \epsilon\):&lt;br /&gt;
3-1. Chọn \(t^{(k+1)} &amp;gt; t^{(k)}\).&lt;br /&gt;
3-2. Khởi tạo phương pháp Newton bằng \(x^{(k)}\) (warm start) và giải xấp xỉ bài toán chắn tại \(t = t^{(k+1)}\) để thu được \(x^{(k+1)} \approx x^*(t)\).&lt;br /&gt;
Kết thúc vòng lặp.&lt;br /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Với phương pháp chắn v.2, hai câu hỏi trọng tâm cần đặt ra là:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Mỗi bước giải xấp xỉ cần chính xác đến mức nào?&lt;/li&gt;
  &lt;li&gt;Mỗi bước định tâm cần bao nhiêu bước Newton?&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter15/15_barrier_methodv2_04.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Phân tích số vòng lặp Newton và khoảng cách dưới tối ưu theo $$m$$ [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Hình 1 cho thấy khi áp dụng phương pháp chắn cho bài toán có \(m\) ràng buộc, tốc độ hội tụ vẫn là tuyến tính ngay cả khi \(m\) rất lớn — tức số vòng lặp tăng theo thang logarit đối với \(m\).&lt;/p&gt;

&lt;p&gt;Nhìn từ góc độ khác, số bước Newton cần thiết để giảm khoảng cách đối ngẫu (duality gap) đi một hệ số \(10^4\) chỉ tăng rất chậm theo \(m\). Như thể hiện ở Hình 2, ngay cả khi \(m\) tăng mạnh, mỗi bài toán vẫn chỉ cần khoảng 20–30 bước Newton (dù chi phí của bản thân mỗi bước Newton phụ thuộc đáng kể vào kích thước bài toán).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter15/15_barrier_methodv2_05.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Phân tích số vòng lặp Newton khi $$m$$ tăng [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>15-05 Phân tích hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_05_convergence_analysis/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_05_convergence_analysis</id>
   <content type="html">&lt;p&gt;Nhìn vào phương pháp chắn v.1 với hai vòng lặp lồng nhau (vòng ngoài tăng \(t\), vòng trong chạy Newton), câu hỏi định lượng quan trọng nhất là: &lt;strong&gt;cần bao nhiêu vòng ngoài để sai số giảm xuống dưới \(\epsilon\)?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kết quả phân tích hội tụ ở mục 15-05 gọn gàng đến bất ngờ: vì sau mỗi bước định tâm, \(t\) tăng theo cấp số nhân \(t^{(k)} = \mu^k t^{(0)}\), nên khoảng cách dưới tối ưu giảm theo cấp số nhân \(f(x^{(k)}) - f^* \le \frac{m}{\mu^k t^{(0)}}\)! Điều đó có nghĩa là &lt;strong&gt;phương pháp chắn hội tụ tuyến tính (tốc độ cấp số nhân) theo số vòng ngoài&lt;/strong&gt;, và số vòng ngoài chỉ tăng theo hàm &lt;strong&gt;logarit&lt;/strong&gt; của \(1/\epsilon\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-định-lý-hội-tụ-vòng-ngoài-của-phương-pháp-chắn&quot;&gt;Kiến thức cần nhớ: Giải phẫu định lý hội tụ vòng ngoài của Phương pháp chắn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quy luật giảm sai số sau \(k\) vòng ngoài:&lt;/strong&gt; Khi bắt đầu từ \(t^{(0)}\) và nhân hệ số \(\mu &amp;gt; 1\) mỗi vòng, ta có:
\(f(x^{(k)}) - f^* \le \frac{m}{\mu^k t^{(0)}}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số vòng ngoài tối đa đạt độ chính xác \(\epsilon\):&lt;/strong&gt; Giải bất phương trình \(\frac{m}{\mu^k t^{(0)}} \le \epsilon\) cho ra ngay:
\(k \ge \frac{\log\bigl(m / (\epsilon t^{(0)})\bigr)}{\log \mu}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Góc nhìn “số bước để thêm 1 chữ số chính xác”:&lt;/strong&gt; Nếu chọn \(\mu = 10\), thì &lt;strong&gt;cứ đúng 1 vòng ngoài&lt;/strong&gt;, khoảng cách đối ngẫu giảm đúng 10 lần — tức bạn mua thêm &lt;strong&gt;1 chữ số thập phân chính xác&lt;/strong&gt; sau mỗi bước định tâm!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ghép với độ phức tạp vòng trong:&lt;/strong&gt; Khi kết hợp với tính tự hài hòa của hàm chắn (mục 15-08), mỗi vòng trong chỉ tốn số bước Newton bị chặn bởi \(O(\sqrt{m})\) (nếu chọn \(\mu = 1 + 1/\sqrt{m}\)), đem lại tổng độ phức tạp đa thức huyền thoại \(O\bigl(\sqrt{m}\log(m/(\epsilon t^{(0)}))\bigr)\) bước Newton!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-trực-tiếp-số-vòng-ngoài-và-sai-số-từng-bước-với-m--50-mu--10&quot;&gt;Giải thích: Tính trực tiếp số vòng ngoài và sai số từng bước với \(m = 50, \mu = 10\)&lt;/h3&gt;

&lt;p&gt;Xét một bài toán tối ưu lồi có \(m = 50\) ràng buộc bất đẳng thức, khởi tạo \(t^{(0)} = 0.5\), hệ số tăng \(\mu = 10\), và yêu cầu sai số \(\epsilon = 10^{-5}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính sai số tối đa sau từng vòng ngoài \(k = 0, 1, 2, \dots\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(k = 0\) (\(t^{(0)} = 0.5\)): \(f(x^{(0)}) - f^* \le \frac{50}{0.5} = 100\).&lt;/li&gt;
      &lt;li&gt;\(k = 1\) (\(t^{(1)} = 5\)): \(f(x^{(1)}) - f^* \le 10\).&lt;/li&gt;
      &lt;li&gt;\(k = 2\) (\(t^{(2)} = 50\)): \(f(x^{(2)}) - f^* \le 1\).&lt;/li&gt;
      &lt;li&gt;\(k = 7\) (\(t^{(7)} = 5 \times 10^6\)): \(f(x^{(7)}) - f^* \le \frac{50}{5 \times 10^6} = 10^{-5} = \epsilon\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra lại bằng công thức logarit:&lt;/strong&gt;
\(k = \frac{\log_{10}\bigl(50 / (10^{-5} \times 0.5)\bigr)}{\log_{10}(10)} = \log_{10}(10^7) = 7 \text{ vòng ngoài}.\)
Chỉ cần &lt;strong&gt;7 vòng định tâm&lt;/strong&gt;, sai số đã giảm &lt;strong&gt;10 triệu lần&lt;/strong&gt; từ \(100\) xuống \(10^{-5}\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Giả sử mỗi bước định tâm (centering step) trong phương pháp chắn được giải chính xác, ta thu được kết quả hội tụ sau.&lt;/p&gt;

&lt;h2 id=&quot;định-lý-hội-tụ&quot;&gt;Định lý hội tụ&lt;/h2&gt;
&lt;p&gt;Sau \(k\) bước định tâm (vòng lặp ngoài), &lt;strong&gt;phương pháp chắn&lt;/strong&gt; thỏa mãn bất đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f^{*} \le  \frac{m}{\mu^k t^{(0)}}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nghĩa là để đạt độ chính xác \(\epsilon\), tổng số bước định tâm cần thiết (bao gồm bước định tâm đầu tiên) là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\frac{\log(m/(t^{(0)}\epsilon))}{\log \mu} + 1
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Như vậy, số vòng lặp ngoài có bậc độ phức tạp \(O(\log(1/\epsilon))\), tương ứng tốc độ hội tụ tuyến tính.&lt;/p&gt;

&lt;p&gt;So với tốc độ hội tụ bậc hai \(O(\log \log(1/\epsilon))\) của phương pháp Newton không ràng buộc, hội tụ tuyến tính vẫn là kết quả tốt đối với lớp bài toán có ràng buộc bất đẳng thức vốn khó hơn nhiều.&lt;/p&gt;

&lt;p&gt;Định nghĩa chi tiết về hội tụ tuyến tính và hội tụ bậc hai có thể tham khảo thêm trên Wikipedia:&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tham khảo: &lt;a href=&quot;https://en.wikipedia.org/wiki/Rate_of_convergence&quot;&gt;Rate of convergence&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>15-04 Phương pháp chắn v.0 và v.1</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_04_barrier_method_v0_and_v1/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_04_barrier_method_v0_and_v1</id>
   <content type="html">&lt;p&gt;Sau khi biết công thức kỳ diệu \(f(x^*(t)) - f^* \le m/t\), phản xạ tự nhiên đầu tiên của bất kỳ ai cũng sẽ là: &lt;em&gt;“Ồ, nếu tôi muốn sai số \(\epsilon = 10^{-6}\) với \(m = 10\) ràng buộc, sao tôi không chọn phắt ngay \(t = 10 / 10^{-6} = 10^7\) rồi chạy Newton đúng 1 lần cho xong?!”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ý tưởng ngây thơ đó chính là &lt;strong&gt;Phương pháp chắn v.0&lt;/strong&gt; — và trên thực tế nó &lt;strong&gt;thất bại thảm hại&lt;/strong&gt;! Khi \(t = 10^7\) quá lớn ngay từ đầu, hàm chắn gần như biến thành một vách đá dựng đứng với ma trận Hessian cực kỳ xấu (số điều kiện bùng nổ), khiến phương pháp Newton gần như đứng im hoặc mất hàng nghìn bước giảm chấn. Đó là lý do &lt;strong&gt;Phương pháp chắn v.1&lt;/strong&gt; ra đời: khởi đầu với \(t^{(0)}\) nhỏ (nơi địa hình tròn trịa, dễ đi), giải nhanh tới \(x^*(t^{(0)})\), rồi tăng dần \(t \leftarrow \mu t\) và dùng nghiệm cũ làm &lt;strong&gt;điểm khởi tạo nóng (warm start)&lt;/strong&gt; cho vòng tiếp theo!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-sự-đánh-đổi-khi-chọn-tham-số-mu-trong-phương-pháp-chắn-v1&quot;&gt;Kiến thức cần nhớ: Sự đánh đổi khi chọn tham số \(\mu\) trong Phương pháp chắn v.1&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tại sao v.0 thất bại còn v.1 thành công:&lt;/strong&gt; Ở v.0, điểm khởi tạo nằm rất xa \(x^*(m/\epsilon)\) và địa hình bị méo gắt bởi \(t\) khổng lồ. Ở v.1, nhờ tăng \(t\) từng nấc nhân \(\mu\), điểm \(x^*(t)\) cũ luôn nằm rất gần điểm \(x^*(\mu t)\) mới nên bước Newton định tâm chỉ mất khoảng 3–5 vòng lặp!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc hai vòng lặp của v.1:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Vòng ngoài (outer loop):&lt;/em&gt; Kiểm tra \(m/t \le \epsilon\); nếu chưa đạt, nhân \(t \leftarrow \mu t\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Vòng trong (centering step):&lt;/em&gt; Xuất phát từ \(x\) hiện tại, chạy Newton để tìm \(x^*(t)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sự đánh đổi chọn \(\mu &amp;gt; 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\mu\) nhỏ (ví dụ \(\mu = 2\)): mỗi bước định tâm cực dễ (1–2 bước Newton), nhưng cần nhiều vòng ngoài.&lt;/li&gt;
      &lt;li&gt;\(\mu\) lớn (ví dụ \(\mu = 100\)): ít vòng ngoài, nhưng mỗi vòng trong phải nhảy xa hơn nên tốn nhiều bước Newton hơn.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Vùng ngọt thực tế:&lt;/strong&gt; \(\mu \in [10, 20]\) thường cho tổng số bước Newton gần như tối ưu (thường chỉ 20–50 bước Newton tổng cộng cho mọi bài toán!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tổng-số-vòng-ngoài-và-ước-lượng-bước-newton-cho-các-mức-mu-khác-nhau&quot;&gt;Giải thích: Tính tổng số vòng ngoài và ước lượng bước Newton cho các mức \(\mu\) khác nhau&lt;/h3&gt;

&lt;p&gt;Giả sử một bài toán có \(m = 20\) ràng buộc bất đẳng thức, khởi tạo \(t^{(0)} = 1\), và ta cần độ chính xác \(\epsilon = 10^{-6}\) (tức cần tăng \(t\) từ \(1\) đến \(t_{\text{end}} = \frac{m}{\epsilon} = 2 \times 10^7\)).&lt;/p&gt;

&lt;p&gt;Số vòng lặp ngoài cần thiết là \(K = \left\lceil \frac{\log(t_{\text{end}} / t^{(0)})}{\log \mu} \right\rceil = \left\lceil \frac{\log(2 \times 10^7)}{\log \mu} \right\rceil\) (chú ý \(\ln(2 \times 10^7) \approx 16.81\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Với \(\mu = 2\) (tăng chậm):&lt;/strong&gt;
\(K = \lceil 16.81 / 0.693 \rceil = 25\) vòng ngoài. Nếu mỗi vòng tốn trung bình 2 bước Newton → tổng \(\approx 50\) bước Newton.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Với \(\mu = 10\) (vùng ngọt):&lt;/strong&gt;
\(K = \lceil 16.81 / 2.303 \rceil = 8\) vòng ngoài (\(t = 1, 10, 10^2, \dots, 10^8\)). Nếu mỗi vòng tốn trung bình 4 bước Newton → tổng \(\approx 32\) bước Newton!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Với \(\mu = 1000\) (tăng quá gắt):&lt;/strong&gt;
\(K = \lceil 16.81 / 6.908 \rceil = 3\) vòng ngoài, nhưng mỗi lần nhảy \(t\) gấp 1000 lần làm điểm khởi tạo xa đường trung tâm, mỗi vòng trong có thể tốn 25–40 bước Newton → tổng \(\approx 90\text{–}120\) bước Newton!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phương-pháp-chắn-v0&quot;&gt;Phương pháp chắn v.0&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Phương pháp chắn v.0&lt;/strong&gt; chọn trực tiếp \(t = m/\epsilon\) với độ chính xác mong muốn \(\epsilon &amp;gt; 0\), rồi giải một lần bài toán chắn sau để đảm bảo \(f(x^*(t)) - f(x^*) \le \epsilon\):&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
 &amp;amp;\min_{x} \ &amp;amp;&amp;amp; tf(x) + \phi(x) \\
 &amp;amp;\text{subject to } \ &amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tuy nhiên, vì \(t = m/\epsilon\) tăng rất lớn khi \(\epsilon\) nhỏ, bài toán tương ứng nằm sát cuối đường trung tâm và gần như quay về độ khó của bài toán gốc trên biên, khiến phương pháp Newton hội tụ chậm và khó giải.&lt;/p&gt;

&lt;p&gt;Để khắc phục, thay vì đặt \(t\) lớn ngay từ đầu, ta tăng dần \(t\) để bám theo đường trung tâm. Cách tiếp cận này được gọi là &lt;strong&gt;phương pháp chắn v.1&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-chắn-v1&quot;&gt;Phương pháp chắn v.1&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Phương pháp chắn v.1&lt;/strong&gt; tăng dần tham số \(t\) qua nhiều bước và giải chuỗi bài toán chắn sau:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
 &amp;amp;\min_{x} \ &amp;amp;&amp;amp; tf(x) + \phi(x) \\
 &amp;amp;\text{subject to } \ &amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;thuật-toán&quot;&gt;Thuật toán&lt;/h3&gt;
&lt;p&gt;Các bước của thuật toán như sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Chọn \(t^{(0)} &amp;gt; 0\) và đặt \(k := 0\).&lt;/li&gt;
  &lt;li&gt;Tại \(t = t^{(0)}\), giải bài toán chắn để thu được \(x^{(0)} = x^*(t)\).&lt;/li&gt;
  &lt;li&gt;Trong khi \(m/t &amp;gt; \epsilon\):&lt;br /&gt;
  3-1. Chọn \(t^{(k+1)} &amp;gt; t^{(k)}\).&lt;br /&gt;
  3-2. Khởi tạo phương pháp Newton bằng \(x^{(k)}\) (khởi động ấm — warm start) và giải bài toán chắn tại \(t = t^{(k+1)}\) để thu được \(x^{(k+1)} = x^*(t)\).&lt;br /&gt;
  Kết thúc vòng lặp.&lt;br /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;nhận-xét&quot;&gt;Nhận xét&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc cập nhật thường dùng&lt;/strong&gt;: \(t^{(k+1)} = \mu t^{(k)}\) với \(\mu &amp;gt; 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khởi động ấm (warm start)&lt;/strong&gt;: Ở bước 3-2, nghiệm của vòng lặp trước được dùng làm điểm khởi tạo cho vòng lặp tiếp theo.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước định tâm (centering step)&lt;/strong&gt;: Bước 2 và bước 3-2 (giải bài toán chắn ứng với một giá trị \(t\) cố định) được gọi là các bước định tâm hay vòng lặp ngoài.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;lựa-chọn-tham-số&quot;&gt;Lựa chọn tham số&lt;/h3&gt;
&lt;p&gt;Khi chọn \(\mu\) và \(t^{(0)}\), cần cân nhắc các đánh đổi sau:&lt;/p&gt;

&lt;h5 id=&quot;chọn-mu&quot;&gt;Chọn \(\mu\)&lt;/h5&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(\mu\) quá nhỏ, số vòng lặp ngoài tăng lên (dù khởi động ấm giúp mỗi bước giải nhanh hơn).&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Nếu \(\mu\) quá lớn, điểm khởi tạo nằm xa điểm đường trung tâm mới nên phương pháp Newton cần nhiều vòng lặp hơn ở mỗi bước định tâm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5 id=&quot;chọn-t0&quot;&gt;Chọn \(t^{(0)}\)&lt;/h5&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(t^{(0)}\) quá nhỏ, số vòng lặp ngoài tăng lên.&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Nếu \(t^{(0)}\) quá lớn, bài toán ban đầu trở nên khó giải tương tự phương pháp chắn v.0, làm tăng số bước Newton ở bước định tâm đầu tiên.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Trong thực tế, hiệu năng của phương pháp chắn khá ổn định trước sự thay đổi của \(\mu\) và \(t^{(0)}\), trong đó khoảng giá trị phù hợp phụ thuộc vào kích thước bài toán.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-lp-cỡ-nhỏ&quot;&gt;Ví dụ LP cỡ nhỏ&lt;/h2&gt;
&lt;p&gt;Hình dưới đây minh họa hiệu năng của phương pháp chắn trên một bài toán quy hoạch tuyến tính (LP) với \(n = 50\) biến và \(m = 100\) ràng buộc bất đẳng thức. Khi \(\mu = 2\), số vòng lặp ngoài tăng lên; còn khi \(\mu = 150\), số bước định tâm và bước Newton có sự đánh đổi rõ rệt so với mức \(\mu = 50\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter15/15_barrier_method_03.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Ví dụ LP cỡ nhỏ [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>15-03 Tính chất và diễn giải</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_03_properties_and_interpretation/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_03_properties_and_interpretation</id>
   <content type="html">&lt;p&gt;Một câu hỏi cực kỳ quan trọng của người học khi lần đầu gặp bài toán chắn là: &lt;em&gt;làm sao tôi biết nghiệm \(x^*(t)\) của bài toán xấp xỉ \(t f(x) + \phi(x)\) thực sự gần nghiệm thật \(x^*\) của bài toán gốc đến mức nào? Lỡ với \(t = 1000\) mà sai số vẫn còn lớn thì sao?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Mục 15-03 trả lời câu hỏi ấy bằng một kết nối đẹp đến nghẹt thở giữa Chương 15 và lý thuyết đối ngẫu KKT: bằng cách đối chiếu điều kiện dừng của bài toán chắn với điều kiện KKT của bài toán gốc, ta phát hiện ra rằng &lt;strong&gt;mỗi điểm đường trung tâm \(x^*(t)\) tự động tặng miễn phí một cặp nhân tử đối ngẫu khả thi \((u^*(t), v^*(t))\)&lt;/strong&gt;, từ đó rút ra cận sai số tuyệt đối \(f(x^*(t)) - f(x^*) \le m/t\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hai-phát-hiện-cốt-lõi-của-mục-tính-chất-và-diễn-giải&quot;&gt;Kiến thức cần nhớ: Hai phát hiện cốt lõi của mục Tính chất và Diễn giải&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện KKT nhiễu (Perturbed KKT):&lt;/strong&gt; Phương trình dừng của bài toán chắn khớp hoàn toàn với 3 trong 4 điều kiện KKT của bài toán gốc (khả thi nguyên thủy, khả thi đối ngẫu, điều kiện dừng Lagrangian), và chỉ làm “mềm” duy nhất điều kiện bù yếu từ \(-u_i h_i(x) = 0\) thành \(-u_i h_i(x) = \frac{1}{t}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tự động sinh điểm khả thi đối ngẫu:&lt;/strong&gt; Công thức \(u_i^*(t) = -\frac{1}{t h_i(x^*(t))} &amp;gt; 0\) biến mọi điểm trên đường trung tâm thành một chứng chỉ đối ngẫu hợp lệ cho bài toán gốc mà không cần giải thêm bài toán đối ngẫu nào.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách dưới tối ưu đóng \(m/t\):&lt;/strong&gt; Nhờ cặp điểm khả thi nguyên thủy – đối ngẫu đó, khoảng cách đối ngẫu tính ra &lt;strong&gt;chính xác bằng \(m/t\)&lt;/strong&gt;, mang lại thước đo dừng đơn giản và chắc chắn tuyệt đối.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-khôi-phục-nhân-tử-đối-ngẫu-từ-điểm-đường-trung-tâm-trên-ví-dụ-số&quot;&gt;Giải thích: Khôi phục nhân tử đối ngẫu từ điểm đường trung tâm trên ví dụ số&lt;/h3&gt;

&lt;p&gt;Quay lại bài toán \(\min_x x\) với ràng buộc \(h_1(x) = -x \le 0\) và \(h_2(x) = x - 4 \le 0\) ở bài trước (\(m = 2\), \(f^* = 0\)). Tại \(t = 1\), ta đã tính được điểm đường trung tâm \(x^*(1) = 3 - \sqrt{5} \approx 0.7639\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính cặp nhân tử đối ngẫu theo công thức \(u_i^*(t) = -\frac{1}{t h_i(x^*(t))}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(u_1^*(1) = \frac{1}{1 \cdot x^*(1)} = \frac{1}{0.7639} \approx 1.3090 &amp;gt; 0\).&lt;/li&gt;
      &lt;li&gt;\(u_2^*(1) = \frac{1}{1 \cdot (4 - x^*(1))} = \frac{1}{3.2361} \approx 0.3090 &amp;gt; 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện dừng của bài toán gốc:&lt;/strong&gt;
\(\nabla f(x^*) + u_1^* \nabla h_1 + u_2^* \nabla h_2 = 1 + 1.3090(-1) + 0.3090(+1) = 1 - 1.3090 + 0.3090 = 0!\)
Điều kiện dừng của hàm Lagrange gốc thỏa mãn chính xác!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hàm đối ngẫu \(g(u^*(1))\) và kiểm tra khoảng cách đối ngẫu:&lt;/strong&gt;
\(g(u^*(1)) = L(x^*(1), u^*(1)) = x^*(1) + u_1^*(1)(-x^*(1)) + u_2^*(1)(x^*(1) - 4) = 0.7639 - 1 - 1 = -1.2361.\)
Khoảng cách đối ngẫu:
\(f(x^*(1)) - g(u^*(1)) = 0.7639 - (-1.2361) = 2.0000 = \frac{m}{t} = \frac{2}{1}!\)
Và sai số thật \(f(x^*(1)) - f^* = 0.7639 \le 2.0\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong mục này, ta đối chiếu các điều kiện KKT của bài toán chắn với điều kiện KKT của bài toán ban đầu để thấy rõ mối liên hệ giữa chúng, đồng thời dẫn xuất cận cho khoảng cách dưới tối ưu (suboptimality gap) giữa hai nghiệm.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-03-02 Khoảng cách dưới tối ưu (Suboptimality gap)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_03_02_suboptimality_gap/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_03_02_suboptimality_gap</id>
   <content type="html">&lt;p&gt;Trong hầu hết các thuật toán tối ưu, việc ước lượng xem mình còn cách giá trị tối ưu \(f^*\) bao xa đòi hỏi phải biết các hằng số khó đo như hằng số lồi mạnh \(m\) hay bán kính tập khả thi \(R\). Thế nhưng phương pháp chắn lại sở hữu một công thức chặn sai số gọn gàng đến mức gần như không tưởng:&lt;/p&gt;

\[f(x^*(t)) - f(x^*) \le \frac{m}{t}.\]

&lt;p&gt;Hãy dừng lại vài giây để chiêm ngưỡng sự kỳ diệu của công thức này: nó &lt;strong&gt;không phụ thuộc&lt;/strong&gt; vào hàm mục tiêu \(f\) cong hay phẳng, &lt;strong&gt;không phụ thuộc&lt;/strong&gt; vào số chiều \(n\), và chỉ phụ thuộc vào đúng hai con số ta biết rõ mười mươi là &lt;strong&gt;số lượng ràng buộc bất đẳng thức \(m\)&lt;/strong&gt; và &lt;strong&gt;tham số chắn \(t\)&lt;/strong&gt; do chính tay ta chọn!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cách-chứng-minh-và-ứng-dụng-công-thức-khoảng-cách-dưới-tối-ưu-mt&quot;&gt;Kiến thức cần nhớ: Cách chứng minh và ứng dụng công thức khoảng cách dưới tối ưu \(m/t\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh bằng hàm đối ngẫu Lagrange:&lt;/strong&gt; Vì \(x^*(t)\) cực tiểu hóa hàm Lagrange \(L(x, u^*(t), v^*(t))\) theo \(x\) (do điều kiện dừng KKT nhiễu và tính lồi), ta có:
\(g(u^*(t), v^*(t)) = L(x^*(t), u^*(t), v^*(t)) = f(x^*(t)) + \sum_{i=1}^m u_i^*(t) h_i(x^*(t)) + v^*(t)^T(Ax^*(t) - b).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sự rút gọn kỳ diệu nhờ bù yếu nhiễu:&lt;/strong&gt; Vì \(Ax^*(t) = b\) và mỗi số hạng \(u_i^*(t) h_i(x^*(t)) = -\frac{1}{t}\), tổng \(m\) số hạng đó bằng đúng \(-\frac{m}{t}\)! Do đó:
\(g(u^*(t), v^*(t)) = f(x^*(t)) - \frac{m}{t}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suy ra chặn trên sai số tức thì:&lt;/strong&gt; Theo tính đối ngẫu yếu \(g(u^*(t), v^*(t)) \le f(x^*)\), ta lập tức nhận được \(f(x^*(t)) - f(x^*) \le f(x^*(t)) - g(u^*(t), v^*(t)) = \frac{m}{t}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chí dừng chuẩn vàng:&lt;/strong&gt; Muốn đạt độ chính xác \(\epsilon\), thuật toán chỉ cần tăng \(t\) cho đến khi \(\frac{m}{t} \le \epsilon\) (tức \(t \ge \frac{m}{\epsilon}\)) là có chứng chỉ toán học tuyệt đối để dừng!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-thiết-kế-ngưỡng-dừng-t-và-kiểm-chứng-mt-trên-bài-toán-3-ràng-buộc&quot;&gt;Giải thích: Thiết kế ngưỡng dừng \(t\) và kiểm chứng \(m/t\) trên bài toán 3 ràng buộc&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu lồi có \(m = 3\) ràng buộc bất đẳng thức:
\(\min_{x \in \mathbb{R}^2} x_1 + 2x_2 \qquad \text{với } x_1 \ge 0, \; x_2 \ge 0, \; x_1 + x_2 \ge 1.\)
(Tức \(h_1 = -x_1 \le 0, \; h_2 = -x_2 \le 0, \; h_3 = 1 - x_1 - x_2 \le 0\); nghiệm tối ưu là \(x^* = (1, 0)^T\) với \(f^* = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chọn ngưỡng dừng cho sai số mục tiêu \(\epsilon = 10^{-4}\):&lt;/strong&gt;
Vì có \(m = 3\) ràng buộc bất đẳng thức, ta chỉ cần chạy phương pháp chắn đến khi:
\(\frac{m}{t} \le 10^{-4} \iff t \ge \frac{3}{10^{-4}} = 30{,}000.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng trực tiếp đẳng thức \(f(x^*(t)) - g(u^*(t)) = m/t\) tại \(t = 10\):&lt;/strong&gt;
Giả sử tại \(t = 10\), điểm đường trung tâm \(x^*(10)\) có \(h_1, h_2, h_3 &amp;lt; 0\) và \(u_i^*(10) = -\frac{1}{10 h_i(x^*(10))}\).
Khi thay vào hàm Lagrange gốc:
\(g(u^*(10)) = f(x^*(10)) + \underbrace{u_1^* h_1}_{-0.1} + \underbrace{u_2^* h_2}_{-0.1} + \underbrace{u_3^* h_3}_{-0.1} = f(x^*(10)) - 0.3.\)
Vậy khoảng cách đối ngẫu luôn chính xác bằng \(0.3 = \frac{3}{10}\), đảm bảo chắc chắn \(f(x^*(10)) - 1 \le 0.3\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Khoảng cách dưới tối ưu giữa giá trị \(f(x^*(t))\) tại điểm đường trung tâm và giá trị tối ưu \(f(x^*)\) của bài toán gốc là bao nhiêu?&lt;/p&gt;

&lt;p&gt;Trước hết, từ tính lồi của \(f\) và \(h_i\) (đồ thị hàm lồi luôn nằm trên tiếp tuyến khai triển Taylor bậc nhất của nó), ta có hai bất đẳng thức:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(x^*) &amp;amp;\ge f(x^*(t)) + \nabla f(x^*(t))^T (x^* - x^*(t)) \\\\
h_i(x^*) &amp;amp;\ge h_i(x^*(t)) + \nabla h_i(x^*(t))^T (x^* - x^*(t)), \quad i = 1, \cdots, m
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ bất đẳng thức thứ hai, chuyển vế ta thu được:&lt;/p&gt;

\[h_i(x^*(t)) - h_i(x^*) \le \nabla h_i(x^*(t))^T (x^*(t) - x^*), \quad i = 1, \cdots, m\]

&lt;h2 id=&quot;dẫn-xuất-khoảng-cách-dưới-tối-ưu&quot;&gt;Dẫn xuất khoảng cách dưới tối ưu&lt;/h2&gt;

&lt;p&gt;Kết hợp hai bất đẳng thức trên với điều kiện KKT nhiễu ở mục trước (với \(u_i(t) &amp;gt; 0\)), ta có:&lt;/p&gt;

\[\begin{align}
f(x^*(t)) - f(x^*) + \sum_{i=1}^{m} u_i(t) (h_i(x^*(t)) - h_i(x^*) ) &amp;amp;\le \left\langle \nabla f(x^*(t)) + \sum_{i=1}^{m} u_i(t) \nabla h_i(x^*(t)), \quad x^*(t) - x^* \right\rangle \\\\
&amp;amp;= \left\langle -A^Tv, \quad x^*(t) - x^* \right\rangle \\\\
\end{align}\]

&lt;p&gt;Vì \(Ax^*(t) = b\) và \(Ax^* = b\), nên \(\langle -A^Tv, x^*(t) - x^* \rangle = -v^T A(x^*(t) - x^*) = 0\).&lt;/p&gt;

&lt;p&gt;Chuyển tổng ở vế trái sang vế phải và rút gọn:&lt;/p&gt;

\[\begin{align}
f(x^*(t)) - f(x^*) &amp;amp;\le - \sum_{i=1}^{m} u_i(t) (h_i(x^*(t)) - h_i(x^*) ) \\\\
&amp;amp;= \frac{m}{t} + \sum_{i=1}^{m} u_i(t) h_i(x^*) \\\\
&amp;amp;\le \frac{m}{t}
\end{align}\]

&lt;p&gt;Ở dòng thứ hai, ta thay \(u_i(t) \cdot h_i(x^*(t)) = - \frac{1}{t}\) từ điều kiện KKT nhiễu để thu được \(\frac{m}{t}\). Ở dòng cuối, tổng \(\sum_{i=1}^{m} u_i(t) h_i(x^*) \le 0\) vì \(u_i(t) &amp;gt; 0\) và \(h_i(x^*) \le 0\).&lt;/p&gt;

&lt;p&gt;Như vậy, ta thu được cận trên cho khoảng cách dưới tối ưu, đồng thời là tiêu chí dừng hữu ích cho phương pháp chắn (mối liên hệ với khoảng cách đối ngẫu cũng sẽ được phân tích thêm ở các chương sau):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(x^*(t)) - f(x^*) \le \frac{m}{t}
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>15-03-01 Điều kiện KKT nhiễu (Perturbed KKT conditions)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_03_01_perturbed_kkt_conditions/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/chapter16/15_03_01_perturbed_kkt_conditions</id>
   <content type="html">&lt;p&gt;Trong hệ điều kiện KKT của bài toán gốc, điều kiện khó chịu nhất về mặt tính toán chính là &lt;strong&gt;điều kiện bù yếu (complementary slackness)&lt;/strong&gt;: \(u_i h_i(x) = 0\). Vì tích bằng \(0\) buộc &lt;em&gt;hoặc&lt;/em&gt; \(u_i = 0\) &lt;em&gt;hoặc&lt;/em&gt; \(h_i(x) = 0\), phương trình này có dạng góc vuông chữ L gãy khúc (tổ hợp rời rạc: phải đoán xem ràng buộc nào đang tích cực!).&lt;/p&gt;

&lt;p&gt;Cái đẹp thiên tài của hàm chắn logarit nằm ở chỗ nó &lt;strong&gt;làm tròn góc vuông chữ L đó thành một đường cong hypebol mượt mà&lt;/strong&gt;: \(-u_i h_i(x) = \frac{1}{t}\)! Hệ phương trình mới gọi là &lt;strong&gt;điều kiện KKT nhiễu (perturbed KKT conditions)&lt;/strong&gt;. Khi \(t\) tăng dần tới \(+\infty\), đường cong hypebol ép sát vào hai trục tọa độ và tiến mượt mà về đúng góc vuông KKT gốc — đây cũng chính là cầu nối trực tiếp sang phương pháp điểm trong nguyên thủy – đối ngẫu ở Chương 17!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-so-sánh-trực-diện-kkt-gốc-và-kkt-nhiễu&quot;&gt;Kiến thức cần nhớ: So sánh trực diện KKT gốc và KKT nhiễu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bốn phương trình của KKT gốc:&lt;/strong&gt; (1) Dừng: \(\nabla f(x) + \sum u_i \nabla h_i(x) + A^T v = 0\); (2) Khả thi nguyên thủy: \(h_i(x) \le 0, Ax = b\); (3) Khả thi đối ngẫu: \(u_i \ge 0\); (4) Bù yếu: \(u_i h_i(x) = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến đổi từ phương trình dừng của bài toán chắn:&lt;/strong&gt; Chia phương trình \(t\nabla f(x) - \sum \frac{1}{h_i(x)}\nabla h_i(x) + A^T w = 0\) cho \(t\) và đặt:
\(u_i = -\frac{1}{t h_i(x)}, \qquad v = \frac{w}{t}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sự khác biệt duy nhất nằm ở điều kiện thứ (4):&lt;/strong&gt; Cả ba điều kiện đầu đều khớp nguyên bản (thậm chí chặt hơn: \(h_i(x) &amp;lt; 0\) và \(u_i &amp;gt; 0\)), chỉ duy nhất điều kiện bù yếu bị nhiễu đúng một lượng \(1/t\): \(-u_i h_i(x) = \frac{1}{t}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-quan-sát-đường-hypebol--u-hx--1t-ép-sát-góc-vuông-kkt&quot;&gt;Giải thích: Quan sát đường hypebol \(-u h(x) = 1/t\) ép sát góc vuông KKT&lt;/h3&gt;

&lt;p&gt;Xét bài toán \(\min_{x \in \mathbb{R}} \frac{1}{2}(x - 2)^2\) với ràng buộc \(h(x) = x - 1 \le 0\) (nghiệm KKT gốc: \(x^* = 1, h(x^*) = 0, u^* = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Viết hệ KKT nhiễu ứng với tham số \(t &amp;gt; 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Điều kiện dừng: \((x - 2) + u(1) = 0 \implies u = 2 - x\).&lt;/li&gt;
      &lt;li&gt;Bù yếu nhiễu: \(-u(x - 1) = \frac{1}{t} \iff (2 - x)(1 - x) = \frac{1}{t}\) (với \(x &amp;lt; 1, u &amp;gt; 0\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải cụ thể tại hai mốc \(t = 1\) và \(t = 100\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Tại \(t = 1\):&lt;/strong&gt; \((2-x)(1-x) = 1 \iff x^2 - 3x + 1 = 0 \implies x^*(1) = \frac{3 - \sqrt{5}}{2} \approx 0.382\), \(u^*(1) = 2 - 0.382 = 1.618\).
Kiểm tra tích bù yếu nhiễu: \(-u^*(1) h(x^*(1)) = 1.618 \times (1 - 0.382) = 1.618 \times 0.618 = 1.000 = \frac{1}{1}\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tại \(t = 100\):&lt;/strong&gt; \((2-x)(1-x) = 0.01 \implies x^*(100) \approx 0.9901\), \(u^*(100) \approx 1.0099\).
Kiểm tra tích bù yếu nhiễu: \(-u^*(100) h(x^*(100)) = 1.0099 \times 0.0099 \approx 0.0100 = \frac{1}{100}\).
Cả cặp \((x^*(t), u^*(t))\) cùng trượt mượt mà trên đường hypebol tới đúng nghiệm KKT \((1, 1)\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;So sánh điều kiện KKT của bài toán chắn và bài toán ban đầu cho thấy mối liên hệ chặt chẽ giữa hai bài toán.&lt;/p&gt;

&lt;h2 id=&quot;điều-kiện-kkt-của-bài-toán-chắn&quot;&gt;Điều kiện KKT của bài toán chắn&lt;/h2&gt;
&lt;p&gt;Số hạng thứ hai trong phương trình dừng của bài toán chắn chính là gradient của hàm chắn logarit:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
t \nabla f(x^*(t)) - \sum_{i=1}^{m} \frac{1}{h_i(x^*(t))} \nabla h_i(x^*(t)) + A^Tw = 0  \\\ 
 Ax^*(t) = b, \quad h_i(x^*(t)) \lt 0, \quad i = 1, \cdots , m \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;điều-kiện-kkt-của-bài-toán-ban-đầu&quot;&gt;Điều kiện KKT của bài toán ban đầu&lt;/h2&gt;
&lt;p&gt;Trong điều kiện KKT của bài toán gốc, điều kiện độ lệch bù (complementary slackness) đòi hỏi \(h_i(x^*) \cdot u_i^* = 0\), nhưng trong thực tế ta khó xác định trước ràng buộc nào đạt dấu bằng trên biên:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
\nabla f(x^*) + \sum_{i=1}^{m} u_i^* \nabla h_i(x^*) + A^Tv^* = 0 \\\ 
Ax^* = b, \quad h_i(x^*) \le 0, \quad u_i^* \ge 0,   \\\ 
h_i(x^*) \cdot u_i^* = 0,  \quad i = 1, \cdots , m \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;viết-lại-điều-kiện-kkt-của-bài-toán-chắn&quot;&gt;Viết lại điều kiện KKT của bài toán chắn&lt;/h2&gt;
&lt;p&gt;Để thấy rõ mối quan hệ giữa hai hệ điều kiện, ta định nghĩa các biến đối ngẫu \(u_i(t)\) và \(v\) như sau:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
u_i(t) = - \frac{1}{t h_i(x^*(t))}, \quad v = \frac{1}{t}w
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Chia cả hai vế của phương trình dừng trong bài toán chắn cho \(t\) và thay \(u_i(t)\), \(v\) vào, ta thu được hệ điều kiện tương đương:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
&amp;amp; \nabla f(x^*(t)) + \sum_{i=1}^{m} u_i(t) \nabla h_i(x^*(t)) + A^Tv = 0  \\\ 
&amp;amp; Ax^*(t) = b, \quad u_i(t) \cdot   h_i(x^*(t)) = - \frac{1}{t}, \quad h_i(x^*(t)) \lt 0, \quad u_i(t) \gt 0 , \quad i = 1, \cdots , m \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Hệ này gần như trùng khớp với điều kiện KKT của bài toán gốc, ngoại trừ điều kiện độ lệch bù bị nhiễu thành \(u_i(t) \cdot h_i(x^*(t)) = - \frac{1}{t}\). Khi \(t \to \infty\), vế phải tiến về \(0\), khôi phục đúng điều kiện \(h_i(x^*) \cdot u_i^* = 0\) của bài toán ban đầu.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-02 Đường trung tâm</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_02_central_path/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_02_central_path</id>
   <content type="html">&lt;p&gt;Nếu ví miền khả thi của bài toán tối ưu như một căn phòng đa giác nhiều góc cạnh, và nghiệm tối ưu \(x^*\) là một kho báu nằm ép sát vào một góc tường, thì &lt;strong&gt;đường trung tâm (central path)&lt;/strong&gt; \(\{x^*(t) \mid t &amp;gt; 0\}\) chính là “con đường cao tốc mượt mà” xuất phát từ chính giữa căn phòng (tâm giải tích ứng với \(t \to 0\)), uốn lượn nhẹ nhàng xuyên qua khoảng không rộng rãi ở giữa để tránh các vách tường gồ ghề, và chỉ rẽ vào chạm đúng góc kho báu \(x^*\) khi \(t \to +\infty\).&lt;/p&gt;

&lt;p&gt;Điều kỳ diệu nhất về đường trung tâm là: ta &lt;strong&gt;không cần&lt;/strong&gt; phải tìm chính xác mọi điểm trên đường cong đó. Chỉ cần đi từng bước nhảy lớn dọc theo “hành lang lân cận” của đường trung tâm, ta vừa giữ ma trận Hessian không bị suy biến quá sớm, vừa tiến theo cấp số nhân về đích!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-và-ý-nghĩa-vật-lý-của-đường-trung-tâm&quot;&gt;Kiến thức cần nhớ: Hình học và ý nghĩa vật lý của đường trung tâm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa chính thức:&lt;/strong&gt; Với mỗi \(t &amp;gt; 0\), \(x^*(t) = \arg\min \{t f(x) + \phi(x) \mid Ax = b\}\). Dưới giả thiết tập khả thi chặt khác rỗng và \(\nabla^2 (t f + \phi) \succ 0\), điểm \(x^*(t)\) tồn tại duy nhất và biến thiên trơn theo \(t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải lực vật lý (Force-Field Interpretation) cho bài toán LP:&lt;/strong&gt; Khi \(f(x) = c^T x\), điều kiện dừng \(t c + \nabla \phi(x) = 0\) có nghĩa là tại \(x^*(t)\), trọng lực không đổi \(-tc\) kéo hạt về hướng \(-c\) đang &lt;strong&gt;cân bằng hoàn hảo&lt;/strong&gt; với tổng các lực đẩy điện tích \(\frac{1}{-h_i(x)}\nabla h_i(x)\) phát ra từ các bức tường ràng buộc!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai đầu mút của đường trung tâm:&lt;/strong&gt; Khi \(t \to 0^+\), \(x^*(t)\) tiến về &lt;strong&gt;tâm giải tích (analytic center)&lt;/strong&gt; của tập khả thi (độc lập với hàm mục tiêu \(f\)). Khi \(t \to +\infty\), \(x^*(t)\) hội tụ về nghiệm tối ưu \(x^*\) (và nếu có nhiều nghiệm tối ưu, nó hội tụ về tâm giải tích của mặt tối ưu!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-giải-tích-toàn-bộ-đường-trung-tâm-xt-cho-một-bài-toán-lp-trên-đoạn-thẳng&quot;&gt;Giải thích: Tính giải tích toàn bộ đường trung tâm \(x^*(t)\) cho một bài toán LP trên đoạn thẳng&lt;/h3&gt;

&lt;p&gt;Xét bài toán LP 1 chiều:
\(\min_{x \in \mathbb{R}} x \qquad \text{với điều kiện } 0 \le x \le 4 \;\; (\text{tức } h_1 = -x \le 0, \; h_2 = x - 4 \le 0).\)
Hàm chắn là \(\phi(x) = -\log(x) - \log(4 - x)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập phương trình đường trung tâm:&lt;/strong&gt;
\(\frac{d}{dx}\bigl(tx - \log x - \log(4 - x)\bigr) = t - \frac{1}{x} + \frac{1}{4 - x} = 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy đồng giải phương trình bậc hai theo \(x\):&lt;/strong&gt;
\(t x(4 - x) - (4 - x) + x = 0 \iff t x^2 - (4t + 2)x + 4 = 0.\)
Vì \(x^*(t) \in (0, 4)\), ta chọn nghiệm nhỏ hơn:
\(x^*(t) = \frac{(2t + 1) - \sqrt{4t^2 + 1}}{t}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử các mốc \(t\) để nhìn đường trung tâm chạy:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Khi \(t \to 0^+\): \(x^*(t) \to 2\) (tâm giải tích nằm đúng chính giữa đoạn \([0, 4]\)!).&lt;/li&gt;
      &lt;li&gt;Tại \(t = 1\): \(x^*(1) = 3 - \sqrt{5} \approx 0.764\).&lt;/li&gt;
      &lt;li&gt;Tại \(t = 10\): \(x^*(10) = \frac{21 - \sqrt{401}}{10} \approx \frac{21 - 20.025}{10} = 0.0975\).&lt;/li&gt;
      &lt;li&gt;Khi \(t \to +\infty\): \(x^*(t) \approx \frac{1}{t} \to 0 = x^*\)!
Lưu ý tại \(t = 10\), sai số \(f(x^*(10)) - f^* = 0.0975 \le \frac{m}{t} = \frac{2}{10} = 0.2\) (thực tế còn chặt hơn vì ràng buộc \(x \le 4\) không tích cực!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Ký hiệu \(x^*(t)\) là nghiệm của bài toán chắn ứng với tham số \(t &amp;gt; 0\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} \ &amp;amp;&amp;amp;  tf(x) + \phi(x) \\
&amp;amp;\text{thỏa mãn } \ &amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Khi đó, tập hợp \(\{x^*(t) \mid t &amp;gt; 0 \}\) được gọi là &lt;strong&gt;đường trung tâm (central path)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Dưới các điều kiện phù hợp, đường trung tâm tạo thành một đường cong trơn trong \(\mathbb{R}^n\) và hội tụ về nghiệm tối ưu \(x^*\) của bài toán gốc khi \(t \to \infty\).&lt;/p&gt;

&lt;p&gt;Nói cách khác, thay vì tìm trực tiếp nghiệm tối ưu nằm trên biên, ta giải một chuỗi bài toán chắn với các giá trị \(t\) tăng dần để đi dọc theo đường trung tâm từ bên trong miền khả thi tiến dần ra biên.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-đường-trung-tâm-của-một-bài-toán-lp&quot;&gt;Ví dụ: đường trung tâm của một bài toán LP&lt;/h2&gt;
&lt;p&gt;Xét bài toán quy hoạch tuyến tính (LP):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align*}
&amp;amp;\min_{x} \ &amp;amp;&amp;amp; c^Tx \\
&amp;amp;\text{thỏa mãn } \ &amp;amp;&amp;amp; a_i^Tx \le b_i, \quad i = 1, \cdots , 6 \\
\end{align*}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong hình dưới đây, các đường nét đứt biểu diễn đường đồng mức của hàm chắn logarit \(\phi\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter15/15_central_path_02.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Đường trung tâm [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Khi \(t \to \infty\), đường trung tâm hội tụ về đỉnh tối ưu \(x^*\). Tại mỗi điểm \(x^*(t)\) trên đường trung tâm, siêu phẳng \(c^Tx = c^Tx^*(t)\) tiếp xúc với đường đồng mức của \(\phi\) đi qua \(x^*(t)\).&lt;/p&gt;

&lt;h3 id=&quot;đường-trung-tâm-dẫn-tới-đỉnh-tối-ưu-video&quot;&gt;Đường trung tâm dẫn tới đỉnh tối ưu (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/central-path_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Khi \(t\) tăng dần, nghiệm \(x^*(t)\) của bài toán chắn trượt dọc theo đường trung tâm tiến về đỉnh tối ưu.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-trượt-dọc-đường-trung-tâm&quot;&gt;Tự tay thử: trượt dọc đường trung tâm&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;barrier&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>15-01 Phương pháp chắn và hàm chắn logarit</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_01_barrier_method_and_log_barrier_function/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_01_barrier_method_and_log_barrier_function</id>
   <content type="html">&lt;p&gt;Mục 15-01 mở màn cho Chương 15 bằng câu hỏi bản lề: &lt;em&gt;làm sao tái sử dụng toàn bộ cỗ máy Newton có ràng buộc đẳng thức siêu mạnh ở Chương 14 cho bài toán có thêm hàng trăm ràng buộc bất đẳng thức \(h_i(x) \le 0\)?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Câu trả lời là một kỹ thuật cầu nối cực kỳ thanh lịch: nhét toàn bộ các ràng buộc bất đẳng thức vào hàm mục tiêu dưới dạng &lt;strong&gt;hàm chỉ thị&lt;/strong&gt;, rồi làm trơn hàm chỉ thị “góc cạnh” đó bằng &lt;strong&gt;hàm chắn logarit&lt;/strong&gt; \(\phi(x) = -\sum_{i=1}^m \log(-h_i(x))\). Từ đây, ta vừa giữ nguyên tính lồi, vừa có đạo hàm cấp 1 và cấp 2 đẹp mắt để đưa thẳng vào phương pháp Newton.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-bước-chuyển-hóa-từ-bài-toán-bất-đẳng-thức-sang-bài-toán-newton&quot;&gt;Kiến thức cần nhớ: Ba bước chuyển hóa từ bài toán bất đẳng thức sang bài toán Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Nhúng bất đẳng thức vào mục tiêu bằng hàm chỉ thị:&lt;/strong&gt; Viết lại \(\min f(x)\) thỏa \(h_i(x) \le 0, Ax = b\) thành \(\min f(x) + \sum_{i=1}^m I_-(h_i(x))\) thỏa \(Ax = b\), trong đó \(I_-(u) = 0\) nếu \(u \le 0\) và \(+\infty\) nếu \(u &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Làm trơn bằng hàm chắn logarit:&lt;/strong&gt; Thay \(I_-(u)\) (không khả vi) bằng \(-\frac{1}{t}\log(-u)\) (khả vi vô hạn lần trên \(u &amp;lt; 0\) và là hàm tự hài hòa!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Giải chuỗi bài toán định tâm:&lt;/strong&gt; Với mỗi \(t &amp;gt; 0\) cố định, bài toán \(\min_x t f(x) + \phi(x)\) thỏa \(Ax = b\) chỉ còn ràng buộc đẳng thức, giải cực nhanh bằng phương pháp Newton của mục 14-08.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-trực-tiếp-giá-trị-hàm-chỉ-thị-và-hàm-chắn-logarit-tại-nhiều-mức-t&quot;&gt;Giải thích: So sánh trực tiếp giá trị hàm chỉ thị và hàm chắn logarit tại nhiều mức \(t\)&lt;/h3&gt;

&lt;p&gt;Xét một ràng buộc bất đẳng thức \(u \le 0\) (với \(u = h(x)\)) và hàm xấp xỉ \(B_t(u) = -\frac{1}{t}\log(-u)\) trên miền \(u &amp;lt; 0\). Hãy tính giá trị tại 3 vị trí: sâu trong miền (\(u = -1\)), gần biên (\(u = -0.1\)), và sát biên (\(u = -0.001\)):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Vị trí \(u\)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Hàm chỉ thị \(I_-(u)\)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;\(t = 1\): \(-\log(-u)\)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;\(t = 10\): \(-\frac{1}{10}\log(-u)\)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;\(t = 100\): \(-\frac{1}{100}\log(-u)\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(u = -1\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.000\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.000\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.000\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(u = -0.1\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(2.303\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.230\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.023\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(u = -0.001\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(6.908\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.691\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.069\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(u \to 0^-\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0\) (rồi nhảy lên \(+\infty\))&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(+\infty\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(+\infty\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(+\infty\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nhìn bảng số trên, ta thấy rõ hai điều: tại mọi \(u &amp;lt; 0\) cố định, khi \(t\) tăng từ \(1 \to 100\) thì \(B_t(u) \to 0 = I_-(u)\); nhưng hễ \(u \to 0^-\), \(B_t(u)\) vẫn luôn vọt lên \(+\infty\) để ngăn thuật toán vượt qua biên!&lt;/p&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Ở chương trước, chúng ta đã tìm hiểu cách giải &lt;strong&gt;bài toán tối ưu trơn có ràng buộc đẳng thức&lt;/strong&gt; bằng phương pháp Newton. Trong chương này, ta mở rộng sang &lt;strong&gt;bài toán tối ưu trơn có cả ràng buộc bất đẳng thức lẫn ràng buộc đẳng thức&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Ý tưởng cốt lõi là đưa bài toán về một chuỗi các bài toán trơn chỉ còn ràng buộc đẳng thức rồi giải bằng phương pháp Newton. Hướng tiếp cận này thuộc nhóm &lt;strong&gt;phương pháp điểm trong (interior-point methods)&lt;/strong&gt;, mà đại diện tiêu biểu được xét trong chương này là &lt;strong&gt;phương pháp chắn (barrier method)&lt;/strong&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-01-03 Giải tích của hàm chắn logarit</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_01_03_log_barrier_calculus/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_01_03_log_barrier_calculus</id>
   <content type="html">&lt;p&gt;Để đưa bài toán chắn \(\min t f(x) + \phi(x)\) vào động cơ Newton, ta bắt buộc phải tính nhanh và chính xác &lt;strong&gt;gradient \(\nabla \phi(x)\)&lt;/strong&gt; cùng &lt;strong&gt;ma trận Hessian \(\nabla^2 \phi(x)\)&lt;/strong&gt; của hàm chắn logarit. Nếu nhìn vào tổng \(-\sum_{i=1}^m \log(-h_i(x))\) có vẻ cồng kềnh, thì kết quả đạo hàm lại có cấu trúc đại số gọn gàng đến bất ngờ!&lt;/p&gt;

&lt;p&gt;Đặc biệt khi các ràng buộc là tuyến tính \(h_i(x) = a_i^T x - b_i \le 0\) (như trong LP và QP), đạo hàm cấp hai \(\nabla^2 h_i(x) = 0\) biến mất hoàn toàn, khiến ma trận Hessian của hàm chắn trở thành một ma trận dạng \(A^T D^2 A\) đối xứng, xác định dương (khi \(A\) đủ hạng) — cực kỳ thuận lợi cho phân rã Cholesky!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-công-thức-giải-tích-và-cấu-trúc-đại-số-của-phix&quot;&gt;Kiến thức cần nhớ: Công thức giải tích và cấu trúc đại số của \(\phi(x)\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient của hàm chắn:&lt;/strong&gt; Áp dụng quy tắc dây chuyền cho \(-\log(-h_i(x))\):
\(\nabla \phi(x) = -\sum_{i=1}^m \frac{1}{h_i(x)} \nabla h_i(x) = \sum_{i=1}^m \frac{1}{-h_i(x)} \nabla h_i(x).\)
Chú ý dấu: vì \(-h_i(x) &amp;gt; 0\), mỗi thành phần \(\frac{1}{-h_i(x)} \nabla h_i(x)\) hướng &lt;strong&gt;ra ngoài tường&lt;/strong&gt; (theo hướng tăng \(h_i\)), nên hướng giảm \(-\nabla \phi(x)\) luôn &lt;strong&gt;đẩy ngược vào trong miền khả thi&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hessian của hàm chắn:&lt;/strong&gt; Gồm đúng hai phần đều nửa xác định dương:
\(\nabla^2 \phi(x) = \sum_{i=1}^m \frac{1}{h_i(x)^2} \nabla h_i(x)\nabla h_i(x)^T - \sum_{i=1}^m \frac{1}{h_i(x)} \nabla^2 h_i(x).\)
Phần thứ nhất là tổng các ma trận hạng 1 nửa xác định dương; phần thứ hai cũng nửa xác định dương vì \(-1/h_i(x) &amp;gt; 0\) và \(\nabla^2 h_i(x) \succeq 0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp ràng buộc tuyến tính \(Bx \le d\):&lt;/strong&gt; Đặt độ dư \(s_i = d_i - b_i^T x &amp;gt; 0\), ta viết cực gọn dạng ma trận: \(\nabla \phi(x) = B^T s^{-1}\) và \(\nabla^2 \phi(x) = B^T \operatorname{diag}(s^{-2}) B\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-gradient-và-hessian-của-hàm-chắn-trên-miền-đa-giác-2d&quot;&gt;Giải thích: Tính tay gradient và Hessian của hàm chắn trên miền đa giác 2D&lt;/h3&gt;

&lt;p&gt;Xét 3 ràng buộc tuyến tính trên \(\mathbb{R}^2\): \(h_1(x) = -x_1 \le 0\), \(h_2(x) = -x_2 \le 0\), và \(h_3(x) = x_1 + x_2 - 3 \le 0\).
Hàm chắn là \(\phi(x) = -\log(x_1) - \log(x_2) - \log(3 - x_1 - x_2)\). Hãy tính \(\nabla \phi\) và \(\nabla^2 \phi\) tại điểm trong \(x = (1, 1)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính các độ dư \(-h_i(x)\) và gradient \(\nabla h_i(x)\) tại \(x = (1, 1)^T\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(-h_1 = 1\), \(\nabla h_1 = (-1, 0)^T\).&lt;/li&gt;
      &lt;li&gt;\(-h_2 = 1\), \(\nabla h_2 = (0, -1)^T\).&lt;/li&gt;
      &lt;li&gt;\(-h_3 = 3 - 1 - 1 = 1\), \(\nabla h_3 = (1, 1)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(\nabla \phi(1, 1)\):&lt;/strong&gt;
\(\nabla \phi(1, 1) = \frac{1}{1}\begin{bmatrix} -1 \\ 0 \end{bmatrix} + \frac{1}{1}\begin{bmatrix} 0 \\ -1 \end{bmatrix} + \frac{1}{1}\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}!\)
Không ngẫu nhiên đâu: \((1, 1)^T\) chính là &lt;strong&gt;tâm giải tích&lt;/strong&gt; của tam giác này!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(\nabla^2 \phi(1, 1)\) (do \(\nabla^2 h_i = 0\)):&lt;/strong&gt;
\(\nabla^2 \phi(1, 1) = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} + \begin{bmatrix} 0 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} + \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}.\)
Kiểm tra tính xác định dương: vết \(2 + 2 = 4 &amp;gt; 0\) và định thức \(2(2) - 1^2 = 3 &amp;gt; 0 \implies \nabla^2 \phi(1, 1) \succ 0\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Với hàm chắn logarit:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\phi(x) = - \sum_{i=1}^{m} \log(-h_i(x))
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;gradient và ma trận Hessian của \(\phi(x)\) lần lượt là:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gradient:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\nabla \phi(x) = - \sum_{i=1}^{m} \frac{1}{h_i(x)} \nabla h_i(x)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Hessian:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\nabla^2 \phi(x) = \sum_{i=1}^{m} \frac{1}{h_i(x)^2} \nabla h_i(x) \nabla h_i(x)^T -  \sum_{i=1}^{m} \frac{1}{h_i(x)} \nabla^2 h_i(x)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;ví-dụ-phix---sum_i1n-logx_i&quot;&gt;Ví dụ: \(\phi(x) = -\sum_{i=1}^{n} \log(x_i)\)&lt;/h2&gt;
&lt;p&gt;Xét hàm chắn cho ràng buộc không âm:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\phi(x) = -\sum_{i=1}^{n} \log(x_i)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ở đây, các ràng buộc bất đẳng thức là \(h_i(x) = -x_i \le 0\) (tức \(x_i \ge 0\)), và miền xác định của hàm chắn \(\phi\) là \(x_i &amp;gt; 0\) với mọi \(i\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gradient:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;

\[\nabla \phi(x) = - 
\begin{bmatrix}
1/x_1 \\\
\vdots \\\
1/x_n \\\
\end{bmatrix}
 = -X^{-1} \mathbb{1}, \qquad X = \text{diag}(x)\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Hessian:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;

\[\nabla^2 \phi(x) = 
\begin{bmatrix}
1/x_1^2 &amp;amp; \cdots &amp;amp; \\\
\vdots &amp;amp; \ddots &amp;amp; \vdots  \\\
&amp;amp; \cdots &amp;amp; 1/x_n^2 \\\
\end{bmatrix}
 = X^{-2}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>15-01-02 Hàm chắn logarit và phương pháp chắn</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_01_02_log_barrier_function_and_barrier_method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_01_02_log_barrier_function_and_barrier_method</id>
   <content type="html">&lt;p&gt;Vì sao trong vô số hàm tăng lên \(+\infty\) khi \(u \to 0^-\) (như \(-1/u\) hay \(1/u^2\)), lịch sử tối ưu hóa lại tôn vinh &lt;strong&gt;hàm chắn logarit&lt;/strong&gt; \(\phi(x) = -\sum_{i=1}^m \log(-h_i(x))\) làm “nữ hoàng” của phương pháp điểm trong?&lt;/p&gt;

&lt;p&gt;Lý do không chỉ vì logarit trơn và lồi, mà còn bởi hai phép màu toán học hiếm có: thứ nhất, \(-\log(-u)\) là &lt;strong&gt;hàm tự hài hòa&lt;/strong&gt; chuẩn mực (nên phương pháp Newton chạy trên nó không bị ảnh hưởng bởi sự bùng nổ đạo hàm gần biên); thứ hai, đạo hàm của \(-\log(-u)\) là \(-1/u\) lại khớp khít một cách hoàn hảo với điều kiện &lt;strong&gt;bù yếu (complementary slackness)&lt;/strong&gt; \(u_i h_i(x) = 0\) trong hệ KKT khi thay \(0\) bằng \(-1/t\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-hàm-chắn-logarit-đến-bài-toán-chắn-tương-đương&quot;&gt;Kiến thức cần nhớ: Từ hàm chắn logarit đến bài toán chắn tương đương&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa hàm chắn logarit:&lt;/strong&gt; \(\phi(x) = -\sum_{i=1}^m \log(-h_i(x))\) với miền xác định là tập khả thi chặt \(\{x : h_i(x) &amp;lt; 0 \;\forall i\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi của \(\phi(x)\):&lt;/strong&gt; Vì mỗi \(h_i(x)\) lồi nên \(-h_i(x)\) lõm và dương trên miền trong; hàm \(-\log(\cdot)\) lồi và nghịch biến, do đó theo quy tắc hợp hàm lồi, \(-\log(-h_i(x))\) luôn là hàm lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai cách viết tương đương của bài toán chắn:&lt;/strong&gt; Cực tiểu hóa \(f(x) + \frac{1}{t}\phi(x)\) hoàn toàn tương đương (có cùng tập nghiệm \(x^*(t)\)) với cực tiểu hóa \(t f(x) + \phi(x)\) thỏa \(Ax = b\). Dạng \(t f(x) + \phi(x)\) được ưa chuộng hơn vì giữ hệ số trước \(\phi(x)\) bằng \(1\), bảo toàn nguyên vẹn tính &lt;strong&gt;tự hài hòa&lt;/strong&gt; của hàm chắn!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-nghiệm-bài-toán-chắn-trên-đoạn-0-2-và-thấy-rõ-vai-trò-hệ-số-t&quot;&gt;Giải thích: Tính nghiệm bài toán chắn trên đoạn \([0, 2]\) và thấy rõ vai trò hệ số \(t\)&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa \(\min_x (x - 3)^2\) trên đoạn \(0 \le x \le 2\) (tức \(h_1(x) = -x \le 0\) và \(h_2(x) = x - 2 \le 0\)). Nghiệm gốc rõ ràng là \(x^* = 2\) (nằm ngay sát biên phải).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Viết hàm chắn logarit:&lt;/strong&gt;
\(\phi(x) = -\log(x) - \log(2 - x), \qquad x \in (0, 2).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm tâm giải tích (Analytic Center) khi \(t = 0\):&lt;/strong&gt;
\(\phi&apos;(x) = -\frac{1}{x} + \frac{1}{2 - x} = 0 \implies x^*(0) = 1\) (chính giữa đoạn \((0, 2)\), nơi lực đẩy từ hai tường \(0\) và \(2\) cân bằng nhau!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán chắn \(\min_{x \in (0,2)} t(x - 3)^2 - \log(x) - \log(2 - x)\) tại \(t = 1\) và \(t = 10\):&lt;/strong&gt;
Điều kiện đạo hàm bằng \(0\): \(2t(x - 3) - \frac{1}{x} + \frac{1}{2 - x} = 0\).
    &lt;ul&gt;
      &lt;li&gt;Tại \(t = 1\): thử \(x \approx 1.68\): \(2(1.68 - 3) - \frac{1}{1.68} + \frac{1}{0.32} = -2.64 - 0.595 + 3.125 = -0.11 \approx 0\) (nghiệm chính xác \(x^*(1) \approx 1.691\)).&lt;/li&gt;
      &lt;li&gt;Tại \(t = 10\): thử \(x \approx 1.95\): \(20(1.95 - 3) - \frac{1}{1.95} + \frac{1}{0.05} = -21.0 - 0.513 + 20.0 = -1.51 \implies\) tiến sát hơn nữa: \(x^*(10) \approx 1.953\)!
Khi \(t\) tăng từ \(0 \to 1 \to 10\), lực hút của hàm mục tiêu thắng dần lực đẩy của bức tường \(x = 2\), kéo nghiệm từ tâm \(1.0 \to 1.691 \to 1.953 \to 2.0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trước khi phát biểu phương pháp chắn, ta xem xét cách xấp xỉ hàm chỉ thị bằng hàm chắn trơn.&lt;/p&gt;

&lt;h2 id=&quot;xấp-xỉ-hàm-chỉ-thị&quot;&gt;Xấp xỉ hàm chỉ thị&lt;/h2&gt;
&lt;p&gt;Hình dưới đây minh họa hàm chỉ thị và các hàm chắn tương ứng. Đường nét đứt là hàm chỉ thị \(I_C\), còn các đường nét liền là hàm chắn \(\phi(x) = -1/t\log(-x)\) ứng với \(t = 0.5, 1, 2\). Hàm chắn xấp xỉ hàm chỉ thị một cách trơn tru, và khi \(t\) tăng (chẳng hạn \(t = 2\) trong hình), xấp xỉ càng sát hàm chỉ thị.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter15/15_barrier_function_01.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Hình 1] Hàm chắn }\phi(x) = -1/t\log(-x) [1]$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;hàm-chắn-logarit&quot;&gt;Hàm chắn logarit&lt;/h2&gt;
&lt;p&gt;Giả sử \(h_1, \cdots , h_m : \mathbb{R}^n \to \mathbb{R}\) là các hàm lồi và khả vi hai lần. Trên tập \(\{x : h_i(x) \lt 0, i = 1, \cdots , m \}\), &lt;strong&gt;hàm chắn logarit (logarithmic barrier function)&lt;/strong&gt; được định nghĩa là:&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\phi(x) = - \sum_{i=1}^{m} \log(-h_i(x))
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tập xác định trên được giả sử là phần trong khác rỗng của tập khả thi \(C\).&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-chắn&quot;&gt;Phương pháp chắn&lt;/h2&gt;
&lt;p&gt;Sử dụng hàm chắn logarit với tham số \(t \gt 0\), bài toán tối ưu ban đầu được xấp xỉ bởi bài toán có ràng buộc đẳng thức sau:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x}           &amp;amp;&amp;amp; f(x) + \frac{1}{t} \phi(x) &amp;amp; \qquad      &amp;amp; \min_{x} &amp;amp;&amp;amp; tf(x) + \phi(x) \\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; Ax = b                     &amp;amp; \iff \qquad &amp;amp; \text{subject to } &amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Phương pháp giải bài toán xấp xỉ này bằng phương pháp Newton được gọi là &lt;strong&gt;phương pháp chắn (barrier method)&lt;/strong&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-01-01 Bài toán cực tiểu hóa có ràng buộc bất đẳng thức</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_01_01_inequality_constrained_minimization_problems/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter15/15_01_01_inequality_constrained_minimization_problems</id>
   <content type="html">&lt;p&gt;Trước thế kỷ 20 cuối những năm 1980, nếu cần giải một bài toán quy hoạch tuyến tính có ràng buộc bất đẳng thức, hầu như mọi kỹ sư đều nghĩ ngay đến &lt;strong&gt;thuật toán Đơn hình (Simplex)&lt;/strong&gt; — thuật toán “bò men theo từng cạnh và đỉnh” ở vỏ ngoài của khối đa diện khả thi. Simplex chạy rất nhanh trên nhiều bài toán thực tế, nhưng trong trường hợp xấu nhất (khối lập phương Klee–Minty), nó phải đi qua số đỉnh tăng theo hàm mũ!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp điểm trong (Interior-Point Method)&lt;/strong&gt; tạo ra một cuộc cách mạng tư duy ngược hoàn toàn: thay vì men theo các góc nhọn ở vỏ ngoài, nó &lt;strong&gt;đâm xuyên qua phần ruột (miền trong)&lt;/strong&gt; của tập khả thi! Để làm được điều đó, bài học này bắt đầu bằng việc phát biểu chuẩn bài toán tối ưu lồi có cả ràng buộc đẳng thức lẫn bất đẳng thức và chuyển hóa nó sang bài toán chỉ có ràng buộc đẳng thức thông qua hàm chỉ thị.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bối-cảnh-bài-toán-chuẩn-và-điều-kiện-cần-của-phương-pháp-điểm-trong&quot;&gt;Kiến thức cần nhớ: Bối cảnh bài toán chuẩn và điều kiện cần của phương pháp điểm trong&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dạng chuẩn bài toán tối ưu lồi trơn:&lt;/strong&gt; \(\min_x f(x)\) thỏa \(Ax = b\) và \(h_i(x) \le 0\) (\(i = 1, \dots, m\)), trong đó \(f, h_1, \dots, h_m\) lồi và khả vi hai lần liên tục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện khả thi chặt (Slater’s Condition):&lt;/strong&gt; Phải tồn tại ít nhất một điểm \(x\) nằm hoàn toàn bên trong miền ràng buộc bất đẳng thức (\(h_i(x) &amp;lt; 0\) với mọi \(i\) và \(Ax = b\)). Điều này vừa đảm bảo miền trong khác rỗng cho phương pháp điểm trong, vừa đảm bảo &lt;strong&gt;đối ngẫu mạnh&lt;/strong&gt; và tồn tại nghiệm KKT!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chỉ thị \(I_-(u)\) như bước đệm khái niệm:&lt;/strong&gt; Viết lại ràng buộc \(h_i(x) \le 0\) bằng cách cộng \(\sum I_-(h_i(x))\) vào \(f(x)\) xóa sạch ràng buộc bất đẳng thức về mặt hình thức, mở đường cho bước thay \(I_-\) bằng hàm chắn trơn ở bài tiếp theo.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phân-biệt-miền-khả-thi-biên-và-miền-trong-chặt-trên-một-đa-giác-nhỏ&quot;&gt;Giải thích: Phân biệt miền khả thi, biên và miền trong chặt trên một đa giác nhỏ&lt;/h3&gt;

&lt;p&gt;Xét bài toán trên \(\mathbb{R}^2\) với 3 ràng buộc bất đẳng thức:
\(h_1(x) = -x_1 \le 0, \qquad h_2(x) = -x_2 \le 0, \qquad h_3(x) = x_1 + x_2 - 2 \le 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điểm \(x_A = (0, 0)^T\):&lt;/strong&gt;
\(h_1(x_A) = 0, \quad h_2(x_A) = 0, \quad h_3(x_A) = -2 &amp;lt; 0.\)
Điểm \(x_A\) là &lt;strong&gt;khả thi&lt;/strong&gt; (nằm trên góc biên tam giác), nên hàm chỉ thị \(\sum I_-(h_i(x_A)) = 0\), nhưng &lt;strong&gt;không khả thi chặt&lt;/strong&gt; (vì \(h_1 = h_2 = 0\), nên \(\log(-h_1)\) không xác định!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điểm \(x_B = (0.5, 0.5)^T\):&lt;/strong&gt;
\(h_1(x_B) = -0.5 &amp;lt; 0, \quad h_2(x_B) = -0.5 &amp;lt; 0, \quad h_3(x_B) = -1 &amp;lt; 0.\)
Điểm \(x_B\) là &lt;strong&gt;khả thi chặt&lt;/strong&gt; (nằm hoàn toàn trong ruột tam giác), chứng minh điều kiện Slater thỏa mãn và có thể dùng làm điểm xuất phát cho phương pháp điểm trong!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điểm \(x_C = (1.5, 1)^T\):&lt;/strong&gt;
\(h_3(x_C) = 0.5 &amp;gt; 0 \implies I_-(h_3(x_C)) = +\infty\) — vi phạm ràng buộc, bị hàm chỉ thị loại bỏ ngay lập tức.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Xét bài toán tối ưu lồi sau:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x}           &amp;amp;&amp;amp; f(x) \\ 
&amp;amp;\text{subject to } &amp;amp;&amp;amp; Ax = b \\
                    &amp;amp;&amp;amp;&amp;amp; h_{i}(x) \leq 0, i = 1, \dotsc, m
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Với các bài toán có ràng buộc bất đẳng thức, việc phân biệt ràng buộc chặt (binding — ràng buộc ảnh hưởng trực tiếp đến nghiệm tối ưu) và ràng buộc không chặt (non-binding) thường khó khăn, đặc biệt khi xét trên biên của miền khả thi.&lt;/p&gt;

&lt;p&gt;Do đó, &lt;strong&gt;phương pháp điểm trong (interior-point method)&lt;/strong&gt; tiếp cận bài toán bằng cách tìm nghiệm đi từ bên trong miền khả thi thay vì lần theo biên.&lt;/p&gt;

&lt;h2 id=&quot;bối-cảnh-của-phương-pháp-điểm-trong&quot;&gt;Bối cảnh của phương pháp điểm trong&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Phương pháp điểm trong&lt;/strong&gt; cho các bài toán tối ưu tổng quát được Anthony V. Fiacco và Garth P. McCormick đề xuất vào những năm 1960. Thời điểm đó, cách tiếp cận này ít được chú ý hơn so với các phương pháp phổ biến như quy hoạch toàn phương tuần tự (sequential quadratic programming) hay phương pháp tập tích cực (active set method), và chỉ thực sự phát triển mạnh trở lại từ thập niên 1980.&lt;/p&gt;

&lt;p&gt;Phương pháp tập tích cực tìm cách xác định tập các ràng buộc đang có giá trị bằng 0 tại nghiệm (gọi là tập tích cực). Tuy nhiên, việc xác định tập này đòi hỏi phải khảo sát biên của miền khả thi, nên chi phí tính toán tăng nhanh khi số lượng ràng buộc lớn.&lt;/p&gt;

&lt;p&gt;Nhằm khắc phục hạn chế đó, phương pháp điểm trong giải bài toán ngay từ phần trong của miền khả thi. Chẳng hạn, với quy hoạch tuyến tính (LP) gồm \(m\) ràng buộc, việc tính toán trên biên có thể tốn \(O(m^2)\) phép tính, trong khi phương pháp điểm trong thường chỉ cần khoảng 20–30 bước Newton ngay cả khi \(m\) lớn. Hiệu năng của phương pháp sẽ được phân tích chi tiết ở các mục sau.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tham khảo: &lt;a href=&quot;https://en.wikipedia.org/wiki/Interior-point_method&quot;&gt;Interior point method&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Tham khảo: &lt;a href=&quot;https://en.wikipedia.org/wiki/Active_set_method&quot;&gt;Active set method&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;đưa-về-bài-toán-cực-tiểu-hóa-có-ràng-buộc-đẳng-thức&quot;&gt;Đưa về bài toán cực tiểu hóa có ràng buộc đẳng thức&lt;/h2&gt;
&lt;p&gt;Đặt \(C := \{x : h_i(x) \le 0, i = 1, \cdots , m \}\). Ta có thể đưa toàn bộ các ràng buộc bất đẳng thức vào hàm mục tiêu thông qua hàm chỉ thị (indicator function) \(I_C(x)\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} \ &amp;amp;&amp;amp; f(x) + I_C(x) \\
&amp;amp;\text{subject to }\  &amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Dạng bài toán này chỉ còn ràng buộc đẳng thức. Tuy nhiên, vì hàm chỉ thị \(I_C\) vẫn chứa biên của \(C\) và không khả vi, khó khăn ở biên chưa được giải quyết và ta vẫn không thể áp dụng trực tiếp phương pháp Newton.&lt;/p&gt;

&lt;p&gt;Nếu thay hàm chỉ thị \(I_C\) bằng một &lt;strong&gt;hàm chắn (barrier function)&lt;/strong&gt; trơn, miền xác định sẽ nằm hoàn toàn trong phần trong của \(C\) (không chứa biên) và hàm mục tiêu trở nên khả vi hai lần, cho phép áp dụng phương pháp Newton.&lt;/p&gt;

&lt;p&gt;Cách tiếp cận giải bài toán xấp xỉ bằng hàm chắn này được gọi là &lt;strong&gt;phương pháp chắn (barrier method)&lt;/strong&gt;, sẽ được trình bày chi tiết ở mục tiếp theo.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>25 Mixed Integer Programming (part II)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_Mixed_integer_programming/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_Mixed_integer_programming</id>
   <content type="html">&lt;p&gt;Branch and Bound alone can still drown in an exponential tree when the initial LP relaxation sits far outside the true integer points. Chapter 25 introduces the second half of the modern MIP revolution: &lt;strong&gt;cutting planes&lt;/strong&gt;. Instead of immediately splitting the feasible region in two, we slice away fractional corners of the LP polytope using valid linear inequalities that leave every single integer feasible point untouched. When cutting planes are embedded inside Branch and Bound—forming &lt;strong&gt;Branch and Cut&lt;/strong&gt;—commercial solvers leap from solving 50-variable toys in the 1980s to solving million-variable statistical and engineering problems today.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-solver-half-of-mixed-integer-programming&quot;&gt;Key ideas: The Solver Half of Mixed Integer Programming&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Convex Hull &amp;amp; Convexification:&lt;/strong&gt; Every bounded integer linear program has an equivalent LP over the convex hull \(\operatorname{conv}(S)\) of its integer points. Cutting planes iteratively approximate \(\operatorname{conv}(S)\) locally around the optimal fractional vertex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Valid Inequalities &amp;amp; Separation:&lt;/strong&gt; A linear inequality \(\pi^\top x \le \pi_0\) is &lt;em&gt;valid&lt;/em&gt; if every integer feasible point satisfies it, and a &lt;em&gt;cutting plane&lt;/em&gt; if the current fractional LP optimum violates it (\(\pi^\top x_{\text{LP}} &amp;gt; \pi_0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gomory Cuts &amp;amp; Branch-and-Cut Synergy:&lt;/strong&gt; Gomory’s fractional cuts generate valid cuts automatically from any fractional simplex tableau row—no problem-specific structure required. Embedding cuts at every node of Branch and Bound creates the modern Branch-and-Cut engine.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High-Dimensional Statistical MIPs:&lt;/strong&gt; Armed with warm starts from discrete first-order methods and Branch-and-Cut, exact \(\ell_0\) Best Subset Selection and robust Least Quantile of Squares regression become practically solvable at modern data scales.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-seeing-a-single-cutting-plane-eliminate-branching&quot;&gt;Worked example: Seeing a Single Cutting Plane Eliminate Branching&lt;/h3&gt;

&lt;p&gt;Consider \(\max x_1 + x_2\) subject to \(2 x_1 + 2 x_2 \le 5\) and \(x_1, x_2 \in \mathbb{Z}_{\ge 0}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the LP relaxation:&lt;/strong&gt; The maximum of \(x_1 + x_2\) subject to \(x_1 + x_2 \le 2.5\) is \(2.5\) (achieved, e.g., at \((2.5, 0)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Derive a valid cutting plane by integer rounding:&lt;/strong&gt; Divide \(2 x_1 + 2 x_2 \le 5\) by \(2\) to get \(x_1 + x_2 \le 2.5\). Since \(x_1\) and \(x_2\) are integers, their sum \(x_1 + x_2\) must be an integer, so we can round the right-hand side down:
\(x_1 + x_2 \le \lfloor 2.5 \rfloor = 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check validity and separation:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Every integer feasible point satisfies \(2(x_1 + x_2) \le 5 \implies x_1 + x_2 \le 2\) (valid!).&lt;/li&gt;
      &lt;li&gt;The fractional LP optimum \((2.5, 0)\) has \(2.5 &amp;gt; 2\) (strictly separated!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Re-solve the tightened LP:&lt;/strong&gt; Maximizing \(x_1 + x_2\) subject to \(x_1 + x_2 \le 2\) immediately hits an integer vertex such as \((2, 0)\) with optimal value \(2\)—closing the integrality gap completely at the root node with &lt;strong&gt;zero&lt;/strong&gt; branching.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This chapter examines the cutting plane algorithm, which can be considered the most core algorithm in Integer Programming (IP), and the branch and cut algorithm, which is its practical implementation.&lt;/p&gt;

&lt;p&gt;We will also examine examples of Integer Programming such as best subset selection and Least mean squares.&lt;/p&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Belotti, Kirches, Leyer, Linderoth, Luedke, and Mahajan (2012), “Mixed-integer nonlinear optimization”&lt;/li&gt;
  &lt;li&gt;Bertsimas and Mazumder (2016), “Best subset selection via a modern optimization lens”&lt;/li&gt;
  &lt;li&gt;Bertsimas, King, and Mazumder (2014), “Least quantile regression via modern optimization”&lt;/li&gt;
  &lt;li&gt;Conforti, Cornuejols, and Zambelli (2014), “Integer programming”&lt;/li&gt;
  &lt;li&gt;Wolsey (1998), “Integer programming”&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2026-applications-optional&quot;&gt;2026 applications (optional)&lt;/h2&gt;

&lt;p&gt;Best-subset MIP is still the statistical poster child; the same big-\(M\) / ReLU encoding now selects pixels for a trained net, &lt;em&gt;certifies&lt;/em&gt; robustness, and grows optimal classification trees. Learning to pick Gomory-style cuts (2024) turns 25-01 into training data. Optional lesson: &lt;a href=&quot;/contents/en/chapter25/25_03_modern_applications/&quot;&gt;25-03 Modern applications of MIP in data science&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>25-02 Two extended examples</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_02_Two_extended_examples/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_02_Two_extended_examples</id>
   <content type="html">&lt;p&gt;For decades, statisticians treated exact \(\ell_0\) subset selection and breakdown-proof Least Median of Squares regression as mathematically ideal but computationally untouchable—forcing everyone to settle for convex surrogates like Lasso or Huber loss. The two extended case studies in this section overturn that folklore. By combining modern MIP formulations with warm starts from continuous first-order optimization, we can now solve both classical statistical NP-hard problems to certified global optimality (or tight provable MIP gaps) on real datasets.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-bridging-statistical-estimation-and-modern-mip&quot;&gt;Key ideas: Bridging Statistical Estimation and Modern MIP&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Exact Combinatorial Regularization (Best Subset Selection):&lt;/strong&gt; Instead of shrinking coefficients via \(\ell_1\) (Lasso), binary indicators \(z_j \in \{0, 1\}\) enforce \(\|\beta\|_0 \le k\) directly—eliminating shrinkage bias on truly active predictors.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High-Breakdown Robustness (Least Median / Quantile of Squares):&lt;/strong&gt; Minimizing the \(q\)-th smallest squared residual resists up to nearly \(50\%\) adversarial outliers, unlike OLS (0% breakdown) or even \(\ell_1\) regression under leverage points.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Discrete First-Order Warm Starts:&lt;/strong&gt; Projected gradient descent onto the nonconvex \(k\)-sparse set (iterative hard thresholding) runs in milliseconds and hands the MIP solver a high-quality primal incumbent \(U\) before Branch and Cut even starts.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Certified Optimality Gaps:&lt;/strong&gt; Even when proving exact \(0\%\) optimality takes longer on noisy \(p \gg n\) datasets, the MIP dual bound immediately tells the statistician how close the warm-start solution is to the unattainable global optimum.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-contrasting-ell_0-exact-selection-vs-ell_1-shrinkage-on-2-features&quot;&gt;Worked example: Contrasting \(\ell_0\) Exact Selection vs. \(\ell_1\) Shrinkage on 2 Features&lt;/h3&gt;

&lt;p&gt;Suppose \(X = I_2\) (two orthonormal features) and \(y = (3, 1)^\top\), so minimizing \(\frac{1}{2}\|y - \beta\|_2^2\) gives OLS \(\hat{\beta}_{\text{OLS}} = (3, 1)^\top\). We want a &lt;strong&gt;1-sparse&lt;/strong&gt; model (\(k = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Exact Best Subset Selection (\(\|\beta\|_0 \le 1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Keeping only \(\beta_1\): \(\hat{\beta} = (3, 0)^\top\), squared error \(\frac{1}{2}(0^2 + 1^2) = 0.5\).&lt;/li&gt;
      &lt;li&gt;Keeping only \(\beta_2\): \(\hat{\beta} = (0, 1)^\top\), squared error \(\frac{1}{2}(3^2 + 0^2) = 4.5\).&lt;/li&gt;
      &lt;li&gt;Optimal exact 1-sparse estimate: \(\hat{\beta}_{\text{BSS}} = (3, 0)^\top\)—zero bias on the active feature!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lasso (\(\ell_1\) surrogate) tuned to be 1-sparse:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;To zero out \(\beta_2 = 1\), we must set \(\lambda \ge 1\).&lt;/li&gt;
      &lt;li&gt;At \(\lambda = 1\), soft-thresholding yields \(\hat{\beta}_{\text{Lasso}} = (S_1(3), S_1(1))^\top = (2, 0)^\top\), which shrinks the true signal from \(3\) down to \(2\) (squared error \(\frac{1}{2}(1^2 + 1^2) = 1.0\)—double the error of BSS!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Insight:&lt;/strong&gt; This exact bias–sparsity gap is why Bertsimas, King, and Mazumder (2016) revived MIP for Best Subset Selection.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we will present two examples of Mixed Integer Programming.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Best subset selection&lt;/li&gt;
  &lt;li&gt;Least mean squares&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>25-02-02 Least mean squares</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_02_02_Least_mean_squares/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_02_02_Least_mean_squares</id>
   <content type="html">&lt;p&gt;A single corrupted sensor reading with a massive leverage value can drag Ordinary Least Squares arbitrarily far from the truth—and even \(\ell_1\) (LAD) regression breaks down under high-leverage outliers. In 1984, Peter Rousseeuw proposed &lt;strong&gt;Least Median of Squares (LMS)&lt;/strong&gt; (and more generally &lt;strong&gt;Least Quantile of Squares, LQS&lt;/strong&gt;): instead of minimizing the sum of squared residuals, minimize the &lt;em&gt;median&lt;/em&gt; (or \(q\)-th smallest) squared residual! This achieves the maximum possible \(50\%\) breakdown point, yet for thirty years it was solved only by random subsampling heuristics. Expressing the \(q\)-th order statistic via binary indicator variables turns LQS into an exact Mixed Integer Program.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-order-statistics-robustness-and-mip-for-lqs&quot;&gt;Key ideas: Order Statistics, Robustness, and MIP for LQS&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Breakdown Point &amp;amp; Leverage Immunity:&lt;/strong&gt; OLS has breakdown point \(0\%\) (one bad point ruins the fit). Minimizing the \(q\)-th smallest squared residual \(r_{(q)}^2\) with \(q = \lfloor n/2 \rfloor + 1\) completely ignores up to \(n - q\) arbitrarily extreme outliers—even in both \(X\) and \(y\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Modeling Order Statistics with Binary Variables:&lt;/strong&gt; Saying that the \(q\)-th smallest absolute residual is at most \(\gamma\) is equivalent to requiring &lt;em&gt;at least&lt;/em&gt; \(q\) observations to satisfy $$&lt;/td&gt;
          &lt;td&gt;y_i - x_i^\top \beta&lt;/td&gt;
          &lt;td&gt;\le \gamma\(—leaving the remaining\)n - q\(observations unconstrained via big-\)M\(switches\)z_i \in {0, 1}$$!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Exact MILP Formulation:&lt;/strong&gt; Minimize \(\gamma\) subject to $$&lt;/td&gt;
          &lt;td&gt;y_i - x_i^\top \beta&lt;/td&gt;
          &lt;td&gt;\le \gamma + M(1 - z_i)\(for\)i = 1, \dots, n\(and\)\sum_{i=1}^n z_i = q\(,\)z_i \in {0, 1}\(. Notice that the objective\)\gamma$$ and every constraint are &lt;strong&gt;purely linear&lt;/strong&gt;!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Warm Starts via Difference-of-Convex / Alternating Minimization:&lt;/strong&gt; Fixing \(\beta\) immediately gives the optimal \(z\) (pick the \(q\) smallest residuals), and fixing \(z\) solves a Chebyshev (\(\ell_\infty\)) fit on those \(q\) inliers—providing fast primal incumbents for the MILP.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-lms-defeats-ols-on-a-4-point-dataset-with-1-outlier&quot;&gt;Worked example: Why LMS Defeats OLS on a 4-Point Dataset with 1 Outlier&lt;/h3&gt;

&lt;p&gt;Fit a constant model \(y \approx \beta \in \mathbb{R}\) to four measurements \(y = (1,\ 2,\ 3,\ 100)^\top\) (3 clean points near \(2\), plus 1 gross outlier at \(100\)). Take \(q = 3\) (minimize the 3rd smallest absolute residual, ignoring the single worst outlier).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Ordinary Least Squares (OLS):&lt;/strong&gt;
\(\hat{\beta}_{\text{OLS}} = \frac{1 + 2 + 3 + 100}{4} = 26.5.\)
The single outlier drags OLS completely away from the clean cluster \(\{1, 2, 3\}\)!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Exact LQS / LMS MILP formulation (\(q = 3\)):&lt;/strong&gt; Minimize \(\gamma\) subject to $$&lt;/td&gt;
          &lt;td&gt;y_i - \beta&lt;/td&gt;
          &lt;td&gt;\le \gamma + M(1 - z_i)\(and\)z_1 + z_2 + z_3 + z_4 = 3$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Choose the 3 tightest inliers \(z = (1, 1, 1, 0)\) (ignoring \(y_4 = 100\)).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;We need $$&lt;/td&gt;
              &lt;td&gt;1 - \beta&lt;/td&gt;
              &lt;td&gt;\le \gamma\(,\)&lt;/td&gt;
              &lt;td&gt;2 - \beta&lt;/td&gt;
              &lt;td&gt;\le \gamma\(,\)&lt;/td&gt;
              &lt;td&gt;3 - \beta&lt;/td&gt;
              &lt;td&gt;\le \gamma$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;The minimax center of \(\{1, 2, 3\}\) is \(\hat{\beta}_{\text{LQS}} = \frac{1 + 3}{2} = 2\), achieving \(\gamma^\star = 1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Check the outlier constraint:&lt;/strong&gt; For \(i = 4\), \(z_4 = 0\) activates \(M\), so $$&lt;/td&gt;
          &lt;td&gt;100 - 2&lt;/td&gt;
          &lt;td&gt;= 98 \le 1 + M\(holds cleanly for\)M = 100\(. The outlier has **zero** influence on\)\hat{\beta}_{\text{LQS}} = 2$$!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So far, we have solved regression problems by minimizing the \(l_2\) norm or \(l_1\) norm of residuals. Is there a more robust method than these methods?&lt;/p&gt;

&lt;p&gt;When performing regression to minimize the median of residuals, we can achieve more robust regression. This is called &lt;strong&gt;Least Median of Squares&lt;/strong&gt;, and it is robust enough that the estimator does not get corrupted even if about 50% of the data is corrupted. However, this problem is also an NP-Hard problem!&lt;/p&gt;

&lt;p&gt;This section introduces how to solve the &lt;strong&gt;Least Quantile of Squares&lt;/strong&gt; problem, which generalizes the Least Median of Squares problem, using Integer programming.&lt;/p&gt;
&lt;h2 id=&quot;least-mean-squares&quot;&gt;Least mean squares&lt;/h2&gt;
&lt;p&gt;Let \(X = [x^{1} \quad \dotsc \quad x^{p}] \in \mathbb{R}^{n×p}\) and \(y \in \mathbb{R}^{n}\). And when \(\beta \in \mathbb{R}^{p}\), let \(r : = y - X\beta\).&lt;/p&gt;

&lt;h3 id=&quot;observe&quot;&gt;Observe&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Least squares (LS) : \(\beta_{LS} : = \underset{\beta}{\text{argmin}} \sum_{i} r^2_i\)&lt;/li&gt;
  &lt;li&gt;Least absolute deviation (LAD) : \(\beta_{LAD} : = \underset{\beta}{\text{argmin}} \sum_{i} \lvert r_{i} \rvert\)
    &lt;h3 id=&quot;least-median-of-squares-lms&quot;&gt;Least Median of Squares (LMS)&lt;/h3&gt;
    &lt;blockquote&gt;
\[\beta_{LMS} : = \underset{\beta}{\text{argmin}} (\text{median} \lvert r_{i} \rvert )\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;least-quantile-regression&quot;&gt;Least quantile regression&lt;/h2&gt;
&lt;p&gt;The Least Quantile of Squares problem, which generalizes the Least Median of Squares problem, can be defined as follows. Here \(r_{q}\) is the \(q\)-th ordered absolute residual.&lt;/p&gt;
&lt;h3 id=&quot;least-quantile-of-squares-lqs&quot;&gt;Least Quantile of Squares (LQS)&lt;/h3&gt;
&lt;blockquote&gt;
\[\beta_{LQS} : = \underset{\beta}{\text{argmin}} (\lvert r_{(q)} \rvert ), \quad 1 \le q \le n, \quad \lvert r_{1} \rvert \le \lvert r_{2} \rvert \le \cdots \le \lvert r_{n} \rvert\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;key-step-in-the-formulation&quot;&gt;Key step in the formulation&lt;/h3&gt;
&lt;p&gt;Now let’s reformulate the Least Quantile of Squares problem as Integer Programming. Here, for each entry \(i\) of \(r\), we use the following binary variables.&lt;/p&gt;

&lt;blockquote&gt;
\[\lvert r_{i} \rvert \le \lvert r_{(q)} \rvert$ or $\lvert r_{i} \rvert \ge \lvert r_{(q)} \rvert\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;integer-programming-formulation&quot;&gt;Integer programming formulation&lt;/h3&gt;
&lt;p&gt;\(\bar{\mu_{i}}\) and \(\mu_{i}\) are thresholds, with \(k\) and \(n-k\) of each respectively.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
  \min_{\beta, \mu, \bar{\mu}, z, \gamma} &amp;amp; \quad {\gamma} \\
  \text{subject to} &amp;amp; \quad  \gamma \le \lvert r_{i} \rvert + \bar{\mu_{i}}, \quad i = 1, ..., n \\
  &amp;amp; \quad  \gamma \le \lvert r_{i} \rvert -  \mu_{i}, \quad i = 1, ..., n \\
  &amp;amp; \quad \bar{\mu_{i}} \le M \cdot z_{i}, \quad i = 1, ..., n \\
  &amp;amp; \quad \mu_{i} \le M \cdot (1-z_{i}), \quad i = 1, ..., n \\
  &amp;amp; \quad \sum^{p}_{i=1} z_{i} = q \\
  &amp;amp; \quad \mu_{i}, \bar{\mu_{i}} \ge 0, \quad i = 1, ..., n \\
  &amp;amp; \quad z_{i} \in \{0, 1\},  \quad i = 1, ..., n \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Looking at the first and second constraints of this problem, the absolute value of residuals \(\lvert r_{i} \rvert\) is included, so it cannot be solved with convex relaxation. Therefore, the first and second constraints must be converted to convex functions.&lt;/p&gt;

&lt;h2 id=&quot;first-order-algorithm&quot;&gt;First-order algorithm&lt;/h2&gt;
&lt;p&gt;\(\lvert r_{i} \rvert\) can be redefined as a convex function \(H_{q}(\beta)\) in the following form.&lt;/p&gt;
&lt;blockquote&gt;

\[\lvert r_{q} \rvert = \lvert y_{(q)} - x^{T}_{(q)} \beta \rvert = H_{q}(\beta) - H_{q+1}(\beta)\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(H_{q}(\beta)\) is defined as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
H_{q}(\beta) = \sum^{n}_{i=q} \lvert y_{(i)} - x^{T}_{(i)} \beta \rvert  = &amp;amp;
\max_{w} \sum^{n}_{i=1} w_i \lvert y_{(i)} - x^{T}_{(i)} \beta \rvert \\
&amp;amp; \text{subject to} \sum^{n}_{i=1}  w_i  = n − q + 1 \\
&amp;amp;0 \le w_i \le 1, i = 1, ..., n \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;\(H_{q}(\beta)\) is the sum of all residuals from the \(q\)-th position when the previously defined \(\lvert r_{i} \rvert\) are arranged in ascending order. Therefore, we can see that subtracting the sum of residuals from the \(q+1\)-th position from the sum of residuals from the \(q\)-th position gives the \(q\)-th residual.&lt;/p&gt;

&lt;p&gt;Using the subgradient algorithm, we can find the local minimum of \(H_{q}(\beta) - H_{q+1}(\beta)\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For detailed information, see the paper &lt;a href=&quot;https://arxiv.org/pdf/1310.8625.pdf&quot;&gt;LEAST QUANTILE REGRESSION VIA MODERN OPTIMIZATION&lt;/a&gt;
    &lt;h2 id=&quot;computational-results&quot;&gt;Computational results&lt;/h2&gt;
    &lt;p&gt;The experimental results of the Least Quantile of Squares problem from the above paper can be seen in the following graphs.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;mixed-integer-programming-gap&quot;&gt;Mixed integer programming gap&lt;/h3&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_06_LQS_results1.png&quot; alt=&quot;[Fig1] Mixed integer programming gap [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Mixed integer programming gap [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;cold-vs-warm-starts&quot;&gt;Cold vs Warm Starts&lt;/h3&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_07_LQS_results2.png&quot; alt=&quot;[Fig2] Cold vs Warm Starts [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Cold vs Warm Starts [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>25-02-01 Best subset selection</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_02_01_Best_subset_selection/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_02_01_Best_subset_selection</id>
   <content type="html">&lt;p&gt;In 2016, Dimitris Bertsimas, Angela King, and Rahul Mazumder ignited a spirited debate across statistics and machine learning by showing that Best Subset Selection—minimizing \(\frac{1}{2}\|y - X\beta\|_2^2\) subject to \(\|\beta\|_0 \le k\)—is no longer limited to \(p = 30\) variables as in 1970s textbooks. By pairing a tight big-\(M\) Mixed Integer Quadratic Program (MIQP) with &lt;strong&gt;discrete first-order warm starts&lt;/strong&gt; (projected gradient descent onto the \(k\)-sparse set), modern MIP solvers routinely tackle \(p = 1000+\) predictors with certified optimality gaps.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-formulating-and-warm-starting-best-subset-selection&quot;&gt;Key ideas: Formulating and Warm-Starting Best Subset Selection&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;MIQP Big-\(M\) Formulation:&lt;/strong&gt; Introduce binary switches \(z_j \in \{0, 1\}\) with \(\sum_{j=1}^p z_j \le k\) and linking bounds \(-M_j z_j \le \beta_j \le M_j z_j\). When \(z_j = 0\), \(\beta_j\) is forced to zero; when \(z_j = 1\), \(\beta_j\) is free within \([-M_j, M_j]\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Data-Driven Tight \(M\) Bounds:&lt;/strong&gt; Guessing \(M = 10^6\) wrecks the continuous relaxation. Instead, solving small auxiliary convex programs (or using Cauchy–Schwarz bounds from a feasible warm-start objective) produces tight, provably valid \(M_j\) constants that dramatically strengthen the root lower bound.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Discrete First-Order Algorithm (Iterative Hard Thresholding):&lt;/strong&gt; Updating \(\beta^{(m+1)} \in H_k\!\left(\beta^{(m)} - \frac{1}{L} X^\top(X\beta^{(m)} - y)\right)\), where \(H_k\) keeps only the \(k\) largest-magnitude entries, monotonically decreases the objective and converges quickly to a near-optimal \(k\)-sparse incumbent.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cold Start vs. Warm Start:&lt;/strong&gt; Feeding the IHT solution into the MIQP gives an immediate tight primal upper bound \(U\), allowing Branch and Cut to prune huge swathes of the tree right from node 0.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-discrete-first-order-iht-warm-start-step&quot;&gt;Worked example: One Discrete First-Order (IHT) Warm-Start Step&lt;/h3&gt;

&lt;p&gt;Consider \(X = \begin{pmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \end{pmatrix}\), \(y = (4, 2)^\top\), sparsity budget \(k = 1\), starting at \(\beta^{(0)} = (0, 0, 0)^\top\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the smoothness constant \(L = \lambda_{\max}(X^\top X)\):&lt;/strong&gt;
\(X^\top X = \begin{pmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{pmatrix}.\)
Since \(X X^\top = \begin{pmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{pmatrix}\) has eigenvalues \(3\) and \(1\), \(L = 3\). Choose step size \(1/L = 1/3\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the gradient at \(\beta^{(0)} = 0\):&lt;/strong&gt;
\(\nabla f(0) = -X^\top y = -\begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{pmatrix} \begin{pmatrix} 4 \\ 2 \end{pmatrix} = (-4,\ -2,\ -6)^\top.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take an unconstrained gradient step:&lt;/strong&gt;
\(u = \beta^{(0)} - \frac{1}{3}\nabla f(0) = \left(\frac{4}{3},\ \frac{2}{3},\ 2\right)^\top.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the hard-thresholding operator \(H_1(u)\) (keep only the single largest-magnitude coordinate):&lt;/strong&gt;
The largest entry is \(u_3 = 2\), so \(\beta^{(1)} = (0, 0, 2)^\top\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the objective drop and warm-start quality:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Initial loss: \(f(0) = \frac{1}{2}(4^2 + 2^2) = 10\).&lt;/li&gt;
      &lt;li&gt;After 1 IHT step: \(X\beta^{(1)} = (2, 2)^\top\), residual \(y - X\beta^{(1)} = (2, 0)^\top\), loss \(f(\beta^{(1)}) = \frac{1}{2}(2^2 + 0^2) = 2\)!&lt;/li&gt;
      &lt;li&gt;Polishing \(\beta_3\) on the selected support \(\{3\}\) gives \(\beta_3 = \frac{X_3^\top y}{\|X_3\|_2^2} = \frac{6}{2} = 3\), yielding loss \(\frac{1}{2}((4-3)^2 + (2-3)^2) = 1\)—handing the MIQP an incumbent with \(U = 1\) before Branch and Cut even begins!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Best subset selection, one of the representative examples of Integer Programming, is a problem of selecting k entries from \(p\) entries.&lt;/p&gt;

&lt;h2 id=&quot;best-subset-selection&quot;&gt;Best subset selection&lt;/h2&gt;

&lt;p&gt;When \(X = [x^{1} \quad \dotsc \quad x^{p}] \in \mathbb{R}^{n×p}\) and \(y \in \mathbb{R}^{n}\), the best subset selection problem is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{\beta} &amp;amp; \quad \frac{1}{2} \| y - X\beta \|^{2} \\
\text{subject to } &amp;amp; \quad \| \beta \|_{0} \leq k \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(\| \beta \|_{0}\) is the number of nonzero entries in \(\beta\). Previously in earlier chapters, we defined this type of problem as a Lasso problem and made \(\beta\) sparse using the \(l_1\) norm. In this problem, it is defined as a problem that constrains the number of non-zero entries using the \(l_0\) norm, but since the constraint condition \(\| \beta \|_{0} \leq k\) is non-convex, the problem cannot be solved with the convex optimization techniques we have learned so far.&lt;/p&gt;

&lt;h3 id=&quot;integer-programming-formulation&quot;&gt;Integer programming formulation&lt;/h3&gt;

&lt;p&gt;Then let’s reformulate this problem with Integer programming.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{\beta, z} &amp;amp; \quad \frac{1}{2} \| y - X\beta \|^{2} \\
\text{subject to } &amp;amp; \quad |\beta_{i}| \leq M_{i} \cdot z_{i} \quad i = 1, \dotsc, p \\
&amp;amp; \quad \sum_{i = 1}^{p} z_{i} \leq k \\
&amp;amp; \quad z_{i} \in \{0, 1\} \quad i = 1, \dotsc, p \\
\end{align}\]
&lt;/blockquote&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;By introducing binary variables \(z_i\) and making the sum of \(z_i\) less than \(k\), we made the above problem equivalent to the original problem. \(M_i\) is a value that bounds $$&lt;/td&gt;
      &lt;td&gt;\beta_{i}&lt;/td&gt;
      &lt;td&gt;\(known in advance, which can be computed from preprocessing\)X\(and\)y$$. Now that we have defined the problem as Integer Programming, we can solve it using Integer Programming techniques.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;a-clever-way-to-get-good-feasible-solutions&quot;&gt;A clever way to get good feasible solutions&lt;/h2&gt;

&lt;p&gt;Let’s generalize the problem and explain the algorithm. Let’s say the objective function \(g : \mathbb{R}^{p} \to \mathbb{R}\) is smooth and convex, and \(\nabla g\) is L-Lipschitz.&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{\beta} g(\beta) \quad \text{subject to} \quad \| \beta \|_{0} \le k\]
&lt;/blockquote&gt;

&lt;p&gt;In the case of best subset selection, \(g(\beta) = \frac{1}{2} \| X\beta - y \|^2_2\).&lt;/p&gt;

&lt;h3 id=&quot;observation&quot;&gt;Observation&lt;/h3&gt;

&lt;p&gt;Through the function \(H_k(u)\) defined as follows, we can obtain the k largest entries from \(u \in \mathbb{R}^p\).&lt;/p&gt;

&lt;blockquote&gt;
\[H_k(u) = \underset{\beta : \| \beta \|_{0} \le k}{\text{argmin}} \| \beta - u \|^2_2\]
&lt;/blockquote&gt;

&lt;p&gt;Here, the function \(H_k(u)\) is hard thresholding. Also, it can be seen as projecting \(u\) onto the set \(\beta\).&lt;/p&gt;

&lt;h3 id=&quot;discrete-first-order-algorithm&quot;&gt;Discrete first-order algorithm&lt;/h3&gt;

&lt;p&gt;Now let’s define an algorithm using gradient descent and the function \(H_k(u)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Start with \(\beta^{(0)}\)&lt;/li&gt;
  &lt;li&gt;for \(k = 0, 1, ..\)
    &lt;ul&gt;
      &lt;li&gt;
\[\beta^{(i+1)} = H_k \left(\beta^{(i)} - \frac{1}{L} \nabla g(\beta^{(i)})\right)\]
      &lt;/li&gt;
      &lt;li&gt;end for&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By iterating the above process, we converge to \(\beta^{(i)} \to \bar{\beta}\). This can be called a local solution to the above minimization problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\bar{\beta} = H_k \left(\bar{\beta} - \frac{1}{L} \nabla g(\bar{\beta})\right)\]
&lt;/blockquote&gt;

&lt;p&gt;As a result, the algorithm can be seen as a proximal gradient algorithm. This is because the function \(H_k(u)\) plays the role of a proximal operator.&lt;/p&gt;

&lt;h2 id=&quot;computational-results&quot;&gt;Computational results&lt;/h2&gt;

&lt;h3 id=&quot;mixed-integer-programming-gap&quot;&gt;Mixed integer programming gap&lt;/h3&gt;

&lt;p&gt;Let’s look at the experimental results of the subset selection problem in the figure below. In the left graph, the upper bound becomes optimal, while the lower bound slowly rises and meets the upper bound, at which point we know it is optimal. This is because there is no method to check whether the solution is optimal in linear programming, and we can know it is optimal when the upper bound and lower bound become equal. (For reference, the difference between the upper bound and lower bound is called the mixed integer programming gap.)&lt;/p&gt;

&lt;p&gt;The right figure shows the same experimental results, showing how the mixed integer programming gap decreases. The orange graph represents the mixed integer programming gap, which is the difference between the upper bound and lower bound, and it gradually decreases.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_03_subset_results1.png&quot; alt=&quot;[Fig1] Dataset n=350, p = 64, k=6 [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Dataset n=350, p = 64, k=6 [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;cold-and-warm-starts&quot;&gt;Cold and Warm Starts&lt;/h3&gt;

&lt;p&gt;The next figure shows that warm start performs much better overall than cold start.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_04_subset_results2.png&quot; alt=&quot;[Fig2] Cold and Warm Starts [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Cold and Warm Starts [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;sparsity-detection&quot;&gt;Sparsity Detection&lt;/h3&gt;

&lt;p&gt;The next figure compares the sparsity of MIP (Mixed Integer Programming), Lasso, Step regression, and Sparsenet. As a result, we can see that MIP produces the most sparse results.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_05_subset_results3.png&quot; alt=&quot;[Fig3] Sparsity Detection (synthetic database) [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig3] Sparsity Detection (synthetic database) [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>25-01 Cutting Planes</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_01_Cutting_planes/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_01_Cutting_planes</id>
   <content type="html">&lt;p&gt;In 1954, George Dantzig, Ray Fulkerson, and Selmer Johnson solved a 49-city Traveling Salesman Problem to provable global optimality—a feat everyone thought was impossible—by iteratively solving LP relaxations and adding hand-crafted inequalities that sliced off fractional subtours. Four years later, Ralph Gomory stunned the field by proving that cutting planes could be generated &lt;em&gt;purely algebraically&lt;/em&gt; for any integer linear program. Though pure cutting-plane methods struggled with numerical ill-conditioning in the 1960s, their fusion with Branch and Bound in the 1990s triggered a million-fold speedup in integer programming.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometric-intuition-and-history-of-cutting-planes&quot;&gt;Key ideas: Geometric Intuition and History of Cutting Planes&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Geometric Picture of a Cut:&lt;/strong&gt; Imagine the integer feasible points \(S = P \cap \mathbb{Z}^n\) as pegs hammered into a board, and the LP relaxation \(P\) as a loose polygon wrapped around them. A cutting plane is a straight line sliced across \(P\) that trims away empty space containing \(x_{\text{LP}}\) without nicking a single peg.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Outer Approximation of the Convex Hull:&lt;/strong&gt; Rather than computing all exponentially many facets of \(\operatorname{conv}(S)\) up front, cutting-plane methods generate inequalities lazily—only in the neighborhood of the current optimal LP face.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Pure Cutting Planes Stalled Historically:&lt;/strong&gt; Adding hundreds of algebraic cuts sequentially without branching creates dense, numerically unstable simplex tableaus and suffers from slow tailing-off convergence.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The 1990s Renaissance (Polyhedral Combinatorics + Branch-and-Cut):&lt;/strong&gt; Combining problem-specific facet-defining cuts (cover cuts, clique cuts, MIR cuts) with Gomory cuts inside a Branch-and-Bound tree resolved numerical stalling and birthed modern MIP solvers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-slicing-away-a-fractional-corner-in-2d&quot;&gt;Worked example: Slicing Away a Fractional Corner in 2D&lt;/h3&gt;

&lt;p&gt;Suppose the LP polytope is \(P = \{x \in \mathbb{R}_{\ge 0}^2 : 2 x_1 + x_2 \le 3,\ x_1 + 2 x_2 \le 3\}\), and we maximize \(x_1 + x_2\) over \(S = P \cap \mathbb{Z}^2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find the LP relaxation optimum:&lt;/strong&gt; Solving \(2x_1 + x_2 = 3\) and \(x_1 + 2x_2 = 3\) gives \(x_{\text{LP}} = (1, 1)\)? Wait: check \(2(1)+1 = 3\) and \(1+2(1) = 3\)—that’s already integer! Let us tighten the RHS to \(2\): \(P = \{x \ge 0 : 2x_1 + x_2 \le 2,\ x_1 + 2x_2 \le 2\}\).
    &lt;ul&gt;
      &lt;li&gt;Now solving \(2x_1 + x_2 = 2\) and \(x_1 + 2x_2 = 2\) gives the fractional LP optimum \(x_{\text{LP}} = (2/3, 2/3)^\top\) with objective \(4/3\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enumerate the true integer points \(S = P \cap \mathbb{Z}^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\((0, 0)\), \((1, 0)\), and \((0, 1)\) are feasible; \((1, 1)\) gives \(2(1) + 1 = 3 &amp;gt; 2\) (infeasible!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Construct the facet-defining cutting plane:&lt;/strong&gt; Summing the two constraints gives \(3x_1 + 3x_2 \le 4 \implies x_1 + x_2 \le 4/3\). Rounding down for integer \(x_1 + x_2\) gives the valid cut:
\(x_1 + x_2 \le 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify:&lt;/strong&gt; Every point in \(S = \{(0,0), (1,0), (0,1)\}\) satisfies \(x_1 + x_2 \le 1\), while \(x_{\text{LP}} = (2/3, 2/3)\) violates it (\(4/3 &amp;gt; 1\)). Adding this single cut trims \(P\) down to the exact convex hull \(\operatorname{conv}(S)\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The cutting plane method is an approach that changes an integer linear program to a convex problem and finds a solution. If this solution is not included in the original feasible set, it uses cuts to progressively guide the newly obtained solution to be included in the original feasible set by cutting out the region where the solution exists. Here, a cut is a line (or hyperplane) that cuts the feasible set, also called a cutting plane.&lt;/p&gt;

&lt;h2 id=&quot;concept-of-cutting-plane&quot;&gt;Concept of cutting plane&lt;/h2&gt;
&lt;p&gt;Conceptually, it can be thought of as a method that draws a line between the original feasible set and the feasible set to cut out regions that are not part of the original feasible set, as shown in the figure below.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_cutting_plane_concept.png&quot; alt=&quot;[Fig1] Cutting Plane&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Cutting Plane&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Red region: feasible set of the original integer linear program&lt;/li&gt;
  &lt;li&gt;Blue region: feasible set of the convex relaxation problem&lt;/li&gt;
  &lt;li&gt;Green line: cutting plane (the cutting plane exists between the blue and red regions)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The detailed algorithm will be introduced again in the main text.&lt;/p&gt;

&lt;h2 id=&quot;a-bit-of-history-on-cutting-planes&quot;&gt;A bit of history on cutting planes&lt;/h2&gt;
&lt;p&gt;It took a very long time for the cutting plane method to develop from theory to a practical method.&lt;/p&gt;

&lt;p&gt;In 1954, Dantzig, Fulkerson, and Johnson first proposed the cutting plane method to solve the TSP (traveling salesman problem), and in 1958, mathematician Gomory proposed a general cutting plane method that could solve arbitrary integer linear programs. However, for about 30 years after that, Gomory cuts remained buried in an impractical state for solving real problems.&lt;/p&gt;

&lt;p&gt;In 1990, Sebastian Ceria at CMU successfully implemented the cutting plane method using the branch and bound algorithm, which is called branch and cut. Since then, cutting planes have become a core component of commercial optimization solvers.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>25-01-04 Branch and cut algorithm</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_01_04_Branch_and_cut_algorithm/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_01_04_Branch_and_cut_algorithm</id>
   <content type="html">&lt;p&gt;For three decades, Branch and Bound and Cutting Planes lived in separate camps: Branch and Bound suffered from weak LP bounds, while pure Cutting Planes bogged down in numerical ill-conditioning. In the early 1990s, Sebastian Ceria, Egon Balas, Gérard Cornuéjols, and Manfred Padberg united them into &lt;strong&gt;Branch and Cut&lt;/strong&gt;: run a few rounds of sharp cuts at the root node (and selectively at tree nodes) to tighten the LP relaxation, then branch the moment cuts stop making rapid progress. That single architectural fusion—amplified by presolve, heuristics, and parallelization—drove a documented &lt;strong&gt;billions-fold&lt;/strong&gt; speedup in MIP solving between 1990 and today.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-architecture-of-modern-branch-and-cut-solvers&quot;&gt;Key ideas: Architecture of Modern Branch-and-Cut Solvers&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Root-Node Cut Loops:&lt;/strong&gt; Spending extra effort generating Gomory, Mixed-Integer Rounding (MIR), cover, and clique cuts at the root node strengthens &lt;em&gt;every&lt;/em&gt; descendant in the entire tree simultaneously.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cut-Then-Branch Balance:&lt;/strong&gt; Generating too many cuts bloats the LP basis and slows down every dual simplex pivot; generating too few leaves the tree exponentially large. Solvers use cut-management pools to drop inactive cuts and switch to branching once bound improvement stalls.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Presolve and Conflict Analysis:&lt;/strong&gt; Before the first LP even solves, presolve eliminates redundant variables, tightens variable bounds, and strengthens big-\(M\) constants; during search, conflict analysis learns nogood clauses from infeasible branches (borrowing from SAT solvers).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Local vs. Global Validity of Cuts:&lt;/strong&gt; Cuts derived solely from original problem constraints are &lt;em&gt;globally valid&lt;/em&gt; and can be shared across the entire search tree, whereas cuts derived using a node’s local branching bounds apply only within that subtree.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-tracing-one-root-cut--branch-step-in-branch-and-cut&quot;&gt;Worked example: Tracing One Root Cut + Branch Step in Branch and Cut&lt;/h3&gt;

&lt;p&gt;Consider \(\max z = 3 x_1 + 2 x_2\) subject to \(2 x_1 + 2 x_2 \le 5\), \(x_1 \le 2\), and \(x_1, x_2 \in \mathbb{Z}_{\ge 0}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Initial LP relaxation at Root:&lt;/strong&gt; Pushing \(x_1 = 2\) (highest coefficient) leaves \(2 x_2 \le 1 \implies x_2 = 0.5\). So \(x_{\text{LP}} = (2, 0.5)\) with \(z_{\text{LP}} = 3(2) + 2(0.5) = 7\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Root-Node Cutting Plane (before branching!):&lt;/strong&gt; Divide \(2x_1 + 2x_2 \le 5\) by \(2\) and round down:
\(x_1 + x_2 \le 2.\)
Notice \(x_{\text{LP}} = (2, 0.5)\) has \(2 + 0.5 = 2.5 &amp;gt; 2\), so the cut slices it off cleanly.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Re-solve Root LP with the cut:&lt;/strong&gt; Maximize \(3x_1 + 2x_2\) subject to \(x_1 + x_2 \le 2\), \(x_1 \le 2\), \(x \ge 0\).
    &lt;ul&gt;
      &lt;li&gt;Pushing \(x_1 = 2\) forces \(x_2 = 0\), giving \(x^{(1)} = (2, 0)\) with \(z = 6\).&lt;/li&gt;
      &lt;li&gt;Because \((2, 0)\) is already &lt;strong&gt;integer-feasible&lt;/strong&gt;, the root node terminates with \(z^\star = 6\)—zero branches required!&lt;/li&gt;
      &lt;li&gt;By contrast, pure Branch and Bound without the root cut would have had to branch on \(x_2 = 0.5\) into \(x_2 \le 0\) (giving \((2, 0), z = 6\)) and \(x_2 \ge 1\) (giving \((1.5, 1), z = 6.5\)), then branch &lt;em&gt;again&lt;/em&gt; on \(x_1 = 1.5\)—exploring 5 nodes instead of 1.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In 1990, Sebastian Ceria at CMU successfully implemented the cutting plane method using the branch and bound algorithm, which is called branch and cut. Since then, cutting planes have become a core component of commercial optimization solvers.&lt;/p&gt;

&lt;h2 id=&quot;branch-and-cut-algorithm&quot;&gt;Branch and cut algorithm&lt;/h2&gt;

&lt;p&gt;Consider the following integer programming problem where \(f : \mathbb{R}^{n} \to \mathbb{R}\) and \(C \subseteq \mathbb{R}^{n}\) is convex and \(J \subseteq \{1, ..., n\}\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} &amp;amp; \quad f(x) \\
\text{subject to } &amp;amp; \quad x \in C \\
&amp;amp; \quad x_j \in \mathbb{Z}, \quad j \in J \\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;branch-and-cut-algorithm-1&quot;&gt;Branch and cut algorithm&lt;/h3&gt;

&lt;p&gt;In the algorithm, we denote the Convex Problem as CP and the Integer Program as IP.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Solve the following convex relaxation problem:
    &lt;blockquote&gt;
\[\begin{align}
\min_{x} &amp;amp; \quad f(x) \\
\text{subject to } &amp;amp; \quad x \in C \\
\end{align}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;If (CR) is infeasible \(\Rightarrow\) (IP) is infeasible&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;If the solution \(x^{\star}\) of (CR) is (IP) feasible \(\Rightarrow\) \(x^{\star}\) is the solution of (IP)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;If the solution \(x^{\star}\) of (CR) is (IP) infeasible, choose one of the following two options:
    &lt;ul&gt;
      &lt;li&gt;4.1 Add a cut and go to step 1.&lt;/li&gt;
      &lt;li&gt;4.2 Branch and iteratively solve subproblems.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The branch and cut algorithm combines branch and bound with the cutting plane method, allowing us to choose whether to branch-and-bound or cut in step 4.&lt;/p&gt;

&lt;h2 id=&quot;integer-programming-technology&quot;&gt;Integer programming technology&lt;/h2&gt;

&lt;p&gt;State-of-the-art solvers like Gurobi, CPLEX, and FICO include very efficient implementations of algorithms such as simplex and interior-point methods. Particularly, in the case of mixed integer optimization, most solvers use the branch and cut algorithm and extensively utilize the advantages of convex relaxation and warm start.&lt;/p&gt;

&lt;p&gt;Compared to about 30 years ago, the performance improvement in Integer programming has been dramatic. Therefore, many real-life problems that could not be solved during that time are now being solved through Integer programming, and with the improvement in computing power, they are expected to be used even more actively.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Algorithm speed improvement 1990-2016: over \(500,000\)&lt;/li&gt;
  &lt;li&gt;Hardware speed improvement 1990-2016: over \(500,000\)&lt;/li&gt;
  &lt;li&gt;Total speedup: over \(250\) billion = \(2.5 \cdot 10^{11}\)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>25-01-03 Gomory cuts (1958)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_01_03_Gomory_cuts/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_01_03_Gomory_cuts</id>
   <content type="html">&lt;p&gt;Ralph Gomory’s 1958 discovery is one of the most elegant algebraic tricks in all of mathematics. You do not need to stare at a graph or guess problem-specific geometry to find a cutting plane. Take &lt;em&gt;any&lt;/em&gt; row of the optimal simplex tableau where a basic integer variable equals a fractional number—split every coefficient into its integer part and fractional part—and a single one-line rounding argument immediately hands you a valid inequality that strictly cuts off the fractional LP optimum.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-algebraic-derivation-of-gomory-fractional-cuts&quot;&gt;Key ideas: Algebraic Derivation of Gomory Fractional Cuts&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;The Fundamental Rounding Principle:&lt;/strong&gt; For any integer expression \(a \in \mathbb{Z}\), \(a \le b \implies a \le \lfloor b \rfloor\). Equivalently, if an integer equals a real expression, their fractional parts must reconcile modulo 1.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reading a Fractional Simplex Row:&lt;/strong&gt; At the LP optimum, a basic variable \(x_i\) satisfies \(x_i + \sum_{j \in N} \bar{a}_{ij} x_j = \bar{b}_i\) where \(\bar{b}_i \notin \mathbb{Z}\) and all nonbasic variables \(x_j\) (\(j \in N\)) are currently \(0\) and nonnegative.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Splitting Into Floor and Fractional Parts:&lt;/strong&gt; Writing \(\bar{a}_{ij} = \lfloor \bar{a}_{ij} \rfloor + f_{ij}\) and \(\bar{b}_i = \lfloor \bar{b}_i \rfloor + f_i\) with \(f_{ij} \in [0, 1)\) and \(f_i \in (0, 1)\), moving integer terms to the left shows \(\sum_{j \in N} f_{ij} x_j - f_i \in \mathbb{Z}\). Because \(\sum_{j \in N} f_{ij} x_j \ge 0\) and \(f_i &amp;lt; 1\), this integer must be \(\ge 0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Automatic Strict Separation:&lt;/strong&gt; The resulting &lt;strong&gt;Gomory fractional cut&lt;/strong&gt; \(\sum_{j \in N} f_{ij} x_j \ge f_i\) is &lt;em&gt;always&lt;/em&gt; violated by the current LP optimum (since \(x_j = 0\) for \(j \in N\) gives \(0 &amp;lt; f_i\)) and is &lt;em&gt;always&lt;/em&gt; valid for every integer feasible solution.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-deriving-a-gomory-cut-from-a-simplex-tableau-row&quot;&gt;Worked example: Deriving a Gomory Cut From a Simplex Tableau Row&lt;/h3&gt;

&lt;p&gt;Suppose at the LP optimum, every variable (including slacks \(s_1, s_2\)) must be a nonnegative integer, and one row of the optimal simplex tableau reads:
\(x_1 + \frac{3}{2} s_1 - \frac{1}{4} s_2 = \frac{7}{4},\)
where \(x_1 = \frac{7}{4}\) is basic and \(s_1 = s_2 = 0\) are nonbasic.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the floor and fractional part of every coefficient&lt;/strong&gt; (remember: \(\lfloor -1/4 \rfloor = -1\), NOT \(0\)!):
    &lt;ul&gt;
      &lt;li&gt;\(\bar{b}_1 = \frac{7}{4} = 1 + \frac{3}{4} \implies f_1 = \frac{3}{4}\).&lt;/li&gt;
      &lt;li&gt;\(\bar{a}_{1, s_1} = \frac{3}{2} = 1 + \frac{1}{2} \implies f_{1, s_1} = \frac{1}{2}\).&lt;/li&gt;
      &lt;li&gt;\(\bar{a}_{1, s_2} = -\frac{1}{4} = (-1) + \frac{3}{4} \implies f_{1, s_2} = \frac{3}{4}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rewrite the row separating integers from fractional parts:&lt;/strong&gt;
\(\underbrace{\bigl(x_1 + 1 \cdot s_1 - 1 \cdot s_2 - 1\bigr)}_{\in\ \mathbb{Z}} = \frac{3}{4} - \frac{1}{2} s_1 - \frac{3}{4} s_2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the Gomory inequality:&lt;/strong&gt; Since the LHS is an integer and \(\frac{1}{2} s_1 + \frac{3}{4} s_2 \ge 0\), the RHS is at most \(\frac{3}{4}\), so it must be \(\le 0\):
\(\frac{3}{4} - \frac{1}{2} s_1 - \frac{3}{4} s_2 \le 0 \iff \frac{1}{2} s_1 + \frac{3}{4} s_2 \ge \frac{3}{4} \iff 2 s_1 + 3 s_2 \ge 3.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify strict separation:&lt;/strong&gt; At the current LP optimum \((s_1, s_2) = (0, 0)\), the cut evaluates to \(0 \ge 3\)—strictly violated! Yet any integer solution satisfying the original equation satisfies \(2 s_1 + 3 s_2 \ge 3\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mathematician Gomory devised a method to easily find valid inequalities based on the following fact:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;if \(a \le b\) and \(a\) is an integer then \(a \le \lfloor b \rfloor\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is, if a is an integer, then even if b is rounded down, the relationship that a is less than or equal to b is maintained.&lt;/p&gt;

&lt;h2 id=&quot;gomory-fractional-cut&quot;&gt;Gomory fractional cut&lt;/h2&gt;
&lt;p&gt;Let’s say that the feasible set \(S\) defined by the convex hull of the IP problem mentioned earlier is as follows:&lt;/p&gt;

\[S \subseteq \left\{ x \in \mathbb{Z}^{n}_{+} : \sum^{n}_{j=1} a_{j} x_{j} = a_{0} \right\} \quad \text{where} \quad  a_{0} \notin \mathbb{Z}\]

&lt;p&gt;In this case, the Gomory fractional cut is defined as follows:&lt;/p&gt;

\[\sum^{n}_{j=1} (a_{j} - \lfloor a_{j} \rfloor) x_{j} \ge a_{0} -  \lfloor a_{0} \rfloor\]

&lt;p&gt;There are many ideas that extend this concept. For example, there are Chvatal cuts, split cuts, lift-and-project cuts, etc.&lt;/p&gt;

&lt;p&gt;The derivation process of Gomory fractional cut is detailed on Wikipedia, so please refer to it.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For detailed information, see &lt;a href=&quot;https://en.wikipedia.org/wiki/Cutting-plane_method&quot;&gt;Cutting-plane method&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;gomory-cuts-worked-by-hand-video&quot;&gt;Gomory cuts, worked by hand (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/gomory-cut_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;A cut removes the fractional LP optimum but keeps every integer point, so the relaxation tightens without losing any integer solution.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-add-cutting-planes&quot;&gt;Try it yourself: add cutting planes&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;cuts&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>25-01-02 Cutting plane algorithm</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_01_02_Cutting_plane_algorithm/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_01_02_Cutting_plane_algorithm</id>
   <content type="html">&lt;p&gt;Once you know that the convex hull \(\operatorname{conv}(S)\) is a polyhedron, a natural algorithm leaps off the page: start with the initial LP relaxation \(P^{(0)}\), solve it to obtain \(x^{(k)}\), and if \(x^{(k)}\) is fractional, ask a &lt;strong&gt;separation oracle&lt;/strong&gt; for a valid inequality \(\pi^\top x \le \pi_0\) that cuts off \(x^{(k)}\). Append that inequality to form \(P^{(k+1)} \subsetneq P^{(k)}\) and repeat. This iterative tightening loop is the pure Cutting Plane Algorithm—the conceptual engine behind both Gomory cuts and outer-approximation methods in convex optimization.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-valid-inequalities-separation-and-the-cutting-plane-loop&quot;&gt;Key ideas: Valid Inequalities, Separation, and the Cutting-Plane Loop&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Valid Inequality Criterion:&lt;/strong&gt; An inequality \(\pi^\top x \le \pi_0\) is valid for \(S = P \cap \mathbb{Z}^n\) if \(\pi^\top x \le \pi_0\) holds for every \(x \in S\). Adding valid inequalities never removes any feasible integer point.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Separation Problem:&lt;/strong&gt; Given a fractional point \(x^\star \in P \setminus \operatorname{conv}(S)\), the separation problem asks for a valid inequality \((\pi, \pi_0)\) such that \(\pi^\top x^\star &amp;gt; \pi_0\). By the Hyperplane Separation Theorem, such an inequality always exists!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Monotonic Relaxation Tightening:&lt;/strong&gt; Because \(S \subseteq P^{(k+1)} \subseteq P^{(k)}\), the sequence of LP relaxation values \(z^{(0)}, z^{(1)}, z^{(2)}, \dots\) moves monotonically toward the true integer optimum \(z_{\text{IP}}^\star\) (non-decreasing for minimization, non-increasing for maximization).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Simplex Re-Optimization:&lt;/strong&gt; After adding a single cut that violates the previous LP optimum \(x^{(k)}\), the previous basis remains &lt;em&gt;dual feasible&lt;/em&gt;—allowing the dual simplex method to re-optimize \(P^{(k+1)}\) in just a handful of pivots instead of solving from scratch.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-two-iterations-of-the-cutting-plane-loop&quot;&gt;Worked example: Two Iterations of the Cutting-Plane Loop&lt;/h3&gt;

&lt;p&gt;Maximize \(z = 2 x_1 + 3 x_2\) over \(x_1, x_2 \in \mathbb{Z}_{\ge 0}\) subject to \(P^{(0)} = \{x \ge 0 : x_1 + 2 x_2 \le 3,\ 2 x_1 + x_2 \le 3\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 0 (Solve LP on \(P^{(0)}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Intersecting the two lines gives \(x^{(0)} = (1, 1)\)? Wait: \(1 + 2(1) = 3\) and \(2(1) + 1 = 3\), so \((1,1)\) is already integer! Let us shift the RHS to \(3.5\) and \(2.5\): \(P^{(0)} = \{x \ge 0 : x_1 + 2 x_2 \le 3.5,\ 2 x_1 + x_2 \le 2.5\}\).&lt;/li&gt;
      &lt;li&gt;Intersecting gives \(3x_2 = 4.5 \implies x_2 = 1.5,\ x_1 = 0.5\), so \(x^{(0)} = (0.5, 1.5)\) with \(z^{(0)} = 2(0.5) + 3(1.5) = 5.5\). (Fractional!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Generate Cut 1:&lt;/strong&gt; From \(x_1 + 2x_2 \le 3.5\) and integrality of \(x_1, x_2\), the left-hand side is an integer, so
\(x_1 + 2 x_2 \le \lfloor 3.5 \rfloor = 3.\)
Check separation: \(0.5 + 2(1.5) = 3.5 &amp;gt; 3\) (cuts off \(x^{(0)}\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 (Solve LP on \(P^{(1)} = P^{(0)} \cap \{x_1 + 2x_2 \le 3\}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Intersecting \(x_1 + 2x_2 = 3\) with \(2x_1 + x_2 = 2.5\) gives \(3x_2 = 3.5 \implies x_2 = 7/6,\ x_1 = 2/3\), with \(z^{(1)} = 2(2/3) + 3(7/6) = 29/6 \approx 4.833 &amp;lt; 5.5\). (Still fractional!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Generate Cut 2:&lt;/strong&gt; From \(2x_1 + x_2 \le 2.5\) and integrality, \(2x_1 + x_2 \le \lfloor 2.5 \rfloor = 2\).
Check separation: \(2(2/3) + 7/6 = 2.5 &amp;gt; 2\) (cuts off \(x^{(1)}\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2 (Solve LP on \(P^{(2)}\)):&lt;/strong&gt; Intersecting \(x_1 + 2x_2 \le 3\) and \(2x_1 + x_2 \le 2\) over \(x \ge 0\) achieves its maximum at the integer vertex \(x^{(2)} = (0, 1)\)? Wait: at \((0, 1.5)\) we violate \(x_2 \in \mathbb{Z}\); at \((1/3, 4/3)\) we get \(z^{(2)} = 14/3 \approx 4.667\); one final Chvátal–Gomory cut \(x_1 + x_2 \le 1\) (from summing the two cuts: \(3x_1 + 3x_2 \le 5 \implies x_1 + x_2 \le \lfloor 5/3 \rfloor = 1\)) immediately produces the integer optimum \(x^\star = (0, 1)\) with \(z^\star = 3\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we will examine the cutting plane algorithm that can solve integer linear programs.&lt;/p&gt;

&lt;h2 id=&quot;valid-inequality&quot;&gt;Valid Inequality&lt;/h2&gt;

&lt;p&gt;To define cutting planes, let’s first look at what valid inequalities are. An inequality \(\pi^{T}x \le \pi_{0}\) is said to be valid for set \(S\) if it satisfies the following condition. That is, if a set \(S\) is contained in the halfspace defined by the inequality \(\pi^{T}x \le \pi_{0}\), then this inequality can be considered valid for \(S\).&lt;/p&gt;

&lt;blockquote&gt;
\[\pi^{T}x \le \pi_{0} \text{ for all } x \in S\]
&lt;/blockquote&gt;

&lt;p&gt;An inequality must be valid to become a cutting plane.&lt;/p&gt;

&lt;h2 id=&quot;cutting-plane-algorithm&quot;&gt;Cutting plane algorithm&lt;/h2&gt;

&lt;p&gt;Now let’s examine the cutting plane algorithm when we have the following integer programming problem:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} &amp;amp; \quad c^{T}x \\
\text{subject to } &amp;amp; \quad x \in C \\
&amp;amp; \quad x_j \in \mathbb{Z}, \quad j \in J \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;where \(S := \text{conv} \left \{ x \in C : x_j \in \mathbb{Z}, j \in J \right \}\).&lt;/p&gt;

&lt;h3 id=&quot;cutting-plane-algorithm-1&quot;&gt;Cutting plane algorithm&lt;/h3&gt;

&lt;p&gt;In the following algorithm, we denote the Convex Problem as CP and the Integer Program as IP.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Set \(C_{0} := C\) and compute \(x^{(0)} := \text{argmin}_{x} \left\{c^{T}x : x \in C_{0} \right\}\)&lt;/li&gt;
  &lt;li&gt;for \(k = 0, 1, ..\)
    &lt;ul&gt;
      &lt;li&gt;if \(x^{k}\) is (IP) feasible, then \(x^{k}\) is the optimal solution, so Stop&lt;/li&gt;
      &lt;li&gt;else
        &lt;ul&gt;
          &lt;li&gt;Find a valid inequality \((\pi, \pi_{0})\) for \(S\) that cuts off \(x^{k}\)&lt;/li&gt;
          &lt;li&gt;
\[C_{k+1} := C_{k} \cap \{ x : \pi^{T}x \le \pi_{0} \}\]
          &lt;/li&gt;
          &lt;li&gt;
\[x^{(k+1)} := \text{argmin}_{x} \left\{c^{T}x : x \in C_{k+1} \right\}\]
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;end if&lt;/li&gt;
      &lt;li&gt;end for&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Such valid inequalities are called &lt;strong&gt;cutting planes&lt;/strong&gt; or &lt;strong&gt;cuts&lt;/strong&gt;. Step 1 of the algorithm involves convex relaxation to solve the CP problem. At this time, the feasible set is \(C\). In step 2 of the algorithm, if the obtained solution is feasible for IP, we consider this solution optimal. If it is not feasible, we find a valid inequality that separates the solution \(x^{k}\) from the set \(S\), thereby reducing the scope of \(C_{k}\). Then, we redefine \(C_{k+1}\) to solve the CP problem and iterate step 2 of the algorithm.&lt;/p&gt;

&lt;p&gt;In the figure below, the polygon represents the set \(C\), and the CP solution is represented by the black dot. In this case, a valid inequality cuts off the solution to reduce the scope of the set \(C\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_02_valid_inequality.png&quot; alt=&quot;[Fig1] Valid Inequality&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Valid Inequality [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;By continuously reducing the scope of the set \(C\) in this way, we eventually meet the feasible set \(S\), which is the convex hull of the IP problem, allowing us to find a solution that is feasible for IP.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>25-01-01 Convexification</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_01_01_Convexification/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter25/25_01_01_Convexification</id>
   <content type="html">&lt;p&gt;At its deepest geometric level, every integer linear program is secretly just a linear program in disguise! By Meyer’s theorem, the convex hull of the integer points inside any rational polyhedron \(P = \{x : Ax \le b\}\) is itself a polyhedron \(\operatorname{conv}(P \cap \mathbb{Z}^n)\) whose vertices are all integer vectors. If you could hand an LP solver the linear inequalities describing \(\operatorname{conv}(P \cap \mathbb{Z}^n)\), simplex would return the exact integer optimum on the very first run. Convexification is the formal theory of how close we can get to that ideal polyhedron.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-convex-hulls-and-polyhedral-theory-for-ilps&quot;&gt;Key ideas: Convex Hulls and Polyhedral Theory for ILPs&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Equivalence Over the Convex Hull:&lt;/strong&gt; Because a linear objective \(c^\top x\) achieves its minimum over a compact set \(S\) at an extreme point of \(\operatorname{conv}(S)\), minimizing \(c^\top x\) over \(S = P \cap \mathbb{Z}^n\) yields the exact same optimal value and extreme-point optima as minimizing \(c^\top x\) over \(\operatorname{conv}(S)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Meyer’s Theorem (Rational Polyhedra):&lt;/strong&gt; Whenever \(A\) and \(b\) have rational entries, \(\operatorname{conv}(\{x \in \mathbb{Z}^n : Ax \le b\})\) is a polyhedron—meaning it can be represented by a &lt;em&gt;finite&lt;/em&gt; system of linear inequalities \(\tilde{A}x \le \tilde{b}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why We Cannot Write Down \(\operatorname{conv}(S)\) Explicitly:&lt;/strong&gt; Although finite, the number of facet-defining inequalities of \(\operatorname{conv}(S)\) is typically exponential in \(n\) (for example, in the Traveling Salesman Problem).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Local Convexification via Cutting Planes:&lt;/strong&gt; We never need the entire convex hull—only the few facets active near the optimal face! Cutting planes build this local polyhedral description on demand.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-explicitly-computing-operatornameconvp-cap-mathbbz2&quot;&gt;Worked example: Explicitly Computing \(\operatorname{conv}(P \cap \mathbb{Z}^2)\)&lt;/h3&gt;

&lt;p&gt;Let \(P = \{(x_1, x_2) \in \mathbb{R}_{\ge 0}^2 : x_1 + 2 x_2 \le 3,\ 2 x_1 + x_2 \le 3.5\}\). Let us find \(P \cap \mathbb{Z}^2\) and its exact convexification \(\operatorname{conv}(P \cap \mathbb{Z}^2)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;List all integer points in \(P\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(x_2 = 0\): \(x_1 \le 3\) and \(2x_1 \le 3.5 \implies x_1 \in \{0, 1\}\). Points: \((0, 0), (1, 0)\).&lt;/li&gt;
      &lt;li&gt;For \(x_2 = 1\): \(x_1 \le 1\) and \(2x_1 \le 2.5 \implies x_1 \in \{0, 1\}\). Points: \((0, 1), (1, 1)\).&lt;/li&gt;
      &lt;li&gt;For \(x_2 = 2\): \(x_1 + 4 \le 3\) has no nonnegative solution.
Thus \(S = P \cap \mathbb{Z}^2 = \{(0, 0), (1, 0), (0, 1), (1, 1)\}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Identify the convex hull \(\operatorname{conv}(S)\):&lt;/strong&gt; The convex hull of those 4 lattice points is simply the unit square:
\(\operatorname{conv}(S) = \{(x_1, x_2) : 0 \le x_1 \le 1,\ 0 \le x_2 \le 1\}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare LP vertices before and after convexification:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Original \(P\) had fractional vertices \((1.75, 0)\), \((0, 1.5)\), and \((4/3, 5/6)\).&lt;/li&gt;
      &lt;li&gt;Convexified \(\operatorname{conv}(S)\) has only integer vertices \((0,0), (1,0), (0,1), (1,1)\).
Any linear objective \(c_1 x_1 + c_2 x_2\) minimized over \(\operatorname{conv}(S)\) is now guaranteed to hit an integer optimum immediately via ordinary LP!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Transforming an integer program into an equivalent convex problem is called convexification. When convexification is performed, the feasible set becomes a polyhedron, making it easy to find valid cutting planes for the cutting plane algorithm.&lt;/p&gt;

&lt;h2 id=&quot;convexification&quot;&gt;Convexification&lt;/h2&gt;

&lt;p&gt;To convexify an integer program, the objective function must be linear. In this case, the constraints of the integer program consist of a convex set \(C\) and an integer set \(\{x_j\}\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} &amp;amp; \quad c^{T}x \\
\text{subject to } &amp;amp; \quad x \in C \\
&amp;amp; \quad x_j \in \mathbb{Z}, \quad j \in J \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In this case, the feasible set can be redefined as the convex hull \(S := \text{conv} \left \{ x \in C : x_j \in \mathbb{Z}, j \in J \right \}\). Using the feasible set defined by this convex hull \(S\), we can define a convex problem equivalent to the original problem as follows. This process is called convexification.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} &amp;amp; \quad c^{T}x \\
\text{subject to } &amp;amp; \quad x \in S \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In the figure below, the blue region is \(C\), the red points are \(\{x_j\}\), and the convex hull \(S\) formed by these two sets is the red region.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter25/25_01_cutting_plane_concept.png&quot; alt=&quot;[Fig1] Cutting Plane&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Cutting Plane&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Source: https://commons.wikimedia.org/wiki/File:Cutting_plane_algorithm2.png&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;The reason these two formulations are equivalent is because the objective function is linear.&lt;/p&gt;

&lt;h2 id=&quot;special-case-integer-linear-programs&quot;&gt;Special case: integer linear programs&lt;/h2&gt;

&lt;p&gt;Let’s apply the above convexification process to the following integer linear program.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} &amp;amp; \quad c^{T}x \\
\text{subject to } &amp;amp; \quad Ax \le b \\
&amp;amp; \quad x_j \in \mathbb{Z}, \quad j \in J \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The convex hull \(S\) of the integer linear program is defined as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Theorem&lt;/strong&gt;: If \(A, b\) are rational numbers, then the following set is a polyhedron.&lt;/p&gt;

\[S := \text{conv} \left \{ x : Ax \le b, x_j \in \mathbb{Z}, j \in J \right \}\]
&lt;/blockquote&gt;

&lt;p&gt;So is an integer linear program a linear program? Of course it is. However, in this case, the polyhedron \(S\) can become a very complex polyhedron with an exponentially large number of inequalities. Therefore, generally, we need to solve the problem using different methods than those used to solve linear programs.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>24 Mixed Integer Programming (part I)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_Mixed_integer_programming/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_Mixed_integer_programming</id>
   <content type="html">&lt;p&gt;Up through Chapter 23, every variable lived in a smooth, connected continuum—you could always nudge a weight by \(0.001\) and ask the gradient which way is downhill. The real world is rarely so forgiving: you cannot build \(0.37\) of a warehouse, assign \(0.6\) of a pilot to a flight, or select \(0.4\) of a feature in a clinical diagnostic model. The moment even a subset of decision variables is forced to take discrete integer values, convexity shatters and gradients lose their local authority. Mixed Integer Programming (MIP) is the mathematical discipline that tames this combinatorial cliff—not by brute-force enumeration, but by pairing clever continuous relaxations with systematic tree search.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-entering-the-world-of-mixed-integer-programming&quot;&gt;Key ideas: Entering the World of Mixed Integer Programming&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Discrete vs. Continuous Coupling:&lt;/strong&gt; A Mixed Integer Program optimizes an objective over both continuous variables \(x \in \mathbb{R}^p\) and integer variables \(y \in \mathbb{Z}^q\). Even when the objective and constraints are linear, restricting \(y\) to \(\mathbb{Z}^q\) renders the feasible set nonconvex and NP-hard in general.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Modeling Power of Binary Variables:&lt;/strong&gt; Restricting \(y_j \in \{0, 1\}\) lets you encode logical implications (“if facility \(i\) is open, then customer \(j\) can be served”), cardinality caps (“pick at most \(k\) features”), and piecewise-linear or indicator constraints inside algebraic inequalities.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal–Dual Bounding Framework:&lt;/strong&gt; Because local optimality no longer implies global optimality, MIP solvers maintain two opposing fences: an incumbent feasible integer solution giving an upper bound (for minimization) and a tractable relaxation giving a certified lower bound.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Relaxation + Branching Synergy:&lt;/strong&gt; Solving the continuous LP/convex relaxation yields a fractional solution; splitting the feasible region around a fractional variable (Branch and Bound) progressively tightens the gap until the primal and dual bounds meet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-rounding-an-lp-relaxation-can-fail&quot;&gt;Worked example: Why Rounding an LP Relaxation Can Fail&lt;/h3&gt;

&lt;p&gt;Consider the 2-variable integer linear program:
\(\max_{x_1, x_2 \in \mathbb{Z}_{\ge 0}} x_1 + 5 x_2 \quad \text{subject to} \quad x_1 + 10 x_2 \le 20,\quad x_1 \le 2.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the LP relaxation (dropping integrality):&lt;/strong&gt; To maximize \(x_1 + 5x_2\), push \(x_2\) as high as possible. Setting \(x_1 = 0\) allows \(x_2 = 20 / 10 = 2\), giving objective \(10\). Pushing \(x_1 = 2\) forces \(x_2 = 18 / 10 = 1.8\), giving \(2 + 5(1.8) = 11\). Thus the LP optimum is \(x_{\text{LP}} = (2, 1.8)^\top\) with value \(11\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Try naive rounding:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Rounding \(x_2 = 1.8\) &lt;strong&gt;up&lt;/strong&gt; to \(2\) gives \((2, 2)\)—&lt;strong&gt;infeasible&lt;/strong&gt;, since \(2 + 10(2) = 22 &amp;gt; 20\)!&lt;/li&gt;
      &lt;li&gt;Rounding \(x_2 = 1.8\) &lt;strong&gt;down&lt;/strong&gt; to \(1\) gives \((2, 1)\)—feasible, with objective \(2 + 5(1) = 7\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find the true integer optimum:&lt;/strong&gt; Setting \(x_1 = 0, x_2 = 2\) is feasible (\(0 + 20 \le 20\)) and achieves objective \(0 + 5(2) = 10 &amp;gt; 7\)!
Notice that the true integer optimum \((0, 2)\) is &lt;strong&gt;not&lt;/strong&gt; any simple rounding of \((2, 1.8)\)—showing why MIP requires systematic branching and bounding rather than post-hoc rounding.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This chapter introduces the definition, relationships, and examples of Mixed Integer Programming, and presents methods for finding optimal solutions by indirectly utilizing relaxation to find solutions for Integer programming.&lt;/p&gt;

&lt;h2 id=&quot;2026-applications-optional&quot;&gt;2026 applications (optional)&lt;/h2&gt;

&lt;p&gt;Assignment, knapsack, and facility location are not museum pieces: crew pairing (MIPLIB air05), last-mile routing with learned demand, and warehouse / edge-GPU siting reuse the 24-02 templates. A second industry — learning to branch inside branch-and-bound — grew around those models after NeurIPS 2019. See &lt;a href=&quot;/contents/en/chapter24/24_06_modern_applications/&quot;&gt;24-06 Modern applications of mixed-integer models&lt;/a&gt;. Feature selection, neural-net verification, and optimal trees wait for Chapter 25.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>24-05 Branch and bound algorithm (B&B)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_05_Branch_and_bound_algorithm/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_05_Branch_and_bound_algorithm</id>
   <content type="html">&lt;p&gt;Branch and Bound is the undisputed workhorse of exact discrete optimization—the algorithmic spine of Gurobi, CPLEX, HiGHS, and SCIP. Its idea is deceptively simple: divide and conquer with a sharp pair of scissors. Whenever a relaxation returns a fractional variable \(x_j = 2.4\), split the universe into two mutually exclusive subproblems (\(x_j \le 2\) and \(x_j \ge 3\)). The magic lies in &lt;strong&gt;fathoming (pruning)&lt;/strong&gt;: the moment a subproblem’s relaxation bound is worse than an already-known integer incumbent, you can discard that entire branch—and potentially billions of descendant solutions—in one stroke.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-three-pillars-of-branch-and-bound&quot;&gt;Key ideas: The Three Pillars of Branch and Bound&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Branching (Partitioning the Feasible Set):&lt;/strong&gt; Picking a fractional variable \(x_j \notin \mathbb{Z}\) and adding \(x_j \le \lfloor x_j \rfloor\) to the left child and \(x_j \ge \lceil x_j \rceil\) to the right child eliminates the current fractional point without losing &lt;em&gt;any&lt;/em&gt; integer feasible solution.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Three Fathoming (Pruning) Rules:&lt;/strong&gt; A tree node can be permanently closed without further branching if its relaxation is: (1) &lt;strong&gt;infeasible&lt;/strong&gt;, (2) &lt;strong&gt;worse than the incumbent&lt;/strong&gt; (\(z_{\text{LP}} \ge U\) for minimization, or \(\le L\) for maximization), or (3) &lt;strong&gt;already integer-feasible&lt;/strong&gt; (which also updates the incumbent!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Node Selection Strategy (BFS vs. DFS vs. Best-First):&lt;/strong&gt; Depth-first search finds feasible incumbents quickly using low memory; best-first search always expands the node with the tightest relaxation bound, minimizing total nodes explored to prove optimality.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Variable Selection (Strong Branching &amp;amp; Pseudocosts):&lt;/strong&gt; Choosing &lt;em&gt;which&lt;/em&gt; fractional variable to branch on can shrink the search tree by \(100\times\); strong branching tests candidate splits beforehand to pick the variable that lifts child bounds the most.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-complete-branch-and-bound-tree-by-hand&quot;&gt;Worked example: Complete Branch-and-Bound Tree by Hand&lt;/h3&gt;

&lt;p&gt;Maximize \(z = 5 x_1 + 4 x_2\) subject to \(x_1 + x_2 \le 5\), \(10 x_1 + 6 x_2 \le 45\), and \(x_1, x_2 \in \mathbb{Z}_{\ge 0}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Root Node (Node 0):&lt;/strong&gt; Solve the LP relaxation. Intersecting \(x_1 + x_2 = 5\) and \(10 x_1 + 6 x_2 = 45\) gives \(4 x_1 = 15 \implies x_1 = 3.75,\ x_2 = 1.25\), with \(z_{\text{LP}} = 5(3.75) + 4(1.25) = 23.75\). Since \(z\) must be an integer, global upper bound is \(23\). Incumbent \(L = -\infty\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Branch on \(x_1 = 3.75\) into Node 1 (\(x_1 \le 3\)) and Node 2 (\(x_1 \ge 4\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Node 1 (\(x_1 \le 3\)):&lt;/strong&gt; At \(x_1 = 3\), \(x_1 + x_2 \le 5 \implies x_2 \le 2\) (and \(30 + 12 = 42 \le 45\) is slack). LP optimum is \((3, 2)\) with \(z = 5(3) + 4(2) = 23\)! Because \((3, 2)\) is &lt;strong&gt;integer-feasible&lt;/strong&gt;, update incumbent \(L = 23\) and &lt;strong&gt;fathom Node 1 by integrality&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Node 2 (\(x_1 \ge 4\)):&lt;/strong&gt; At \(x_1 = 4\), \(10(4) + 6 x_2 \le 45 \implies x_2 \le 5/6 \approx 0.833\). LP optimum is \((4, 5/6)\) with \(z_{\text{LP}} = 5(4) + 4(5/6) = 23.333\). Since \(z\) must be integer, any integer solution in Node 2 has \(z \le \lfloor 23.333 \rfloor = 23 \le L = 23\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fathom Node 2 by bound and terminate:&lt;/strong&gt; No integer point in Node 2 can strictly beat our incumbent \(L = 23\). All active nodes are closed: \(x^\star = (3, 2)\) with \(z^\star = 23\) is &lt;strong&gt;provably optimal&lt;/strong&gt; in just 3 nodes!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s find out the method of solving Integer programs through Branch and bound algorithm and Convex relaxation.&lt;/p&gt;

&lt;h2 id=&quot;definition-and-properties&quot;&gt;Definition and properties&lt;/h2&gt;
&lt;p&gt;Branch and bound algorithm is the most common method for solving integer programs. It is mainly a divide and conquer approach that breaks the original problem into several smaller problems (sub-problems) to approach the correct answer.&lt;/p&gt;

&lt;p&gt;When the constraint set \(X = X_{1} \cup X_{2} \cup \dotsc \cup X_{k}\) is a union of partitions consisting of each \(X_{i}\),&lt;/p&gt;
&lt;blockquote&gt;
\[\min_{x \in X} f(x) = \min_{i = 1, \dotsc , k} \lbrace \min_{x \in X_{i}} f(x) \rbrace .\]
&lt;/blockquote&gt;

&lt;p&gt;We can find the optimal solution by partitioning the region and finding the minimum.&lt;/p&gt;

&lt;p&gt;Any feasible solution of a sub-problem can be set as the upper bound \(u(X)\). To obtain the lower bound, we find the lower bound \(l(X_{i})\) of each sub-problem. Then, if \(l(X_{i}) \geq u(X)\), we exclude the sub-problem \(\min_{x \in X_{i}} f(x)\) corresponding to this part.&lt;/p&gt;

&lt;p&gt;The Integer Programming problem (IP) is defined as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; x \in C \\\\
&amp;amp;&amp;amp;&amp;amp;x_j \in \mathbb{Z}, \quad j \in J \\\\
\end{align}\)
\(\begin{align}
\text{where f is convex } f : \mathbb{R}^{n} \rightarrow \mathbb{R}, \quad C \in \mathbb{R}^n 
\quad \text{and} \quad J \in \lbrace 1 \dotsc n \rbrace \\
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And when the Convex Relaxation (CR) problem is as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;x \in C \\\\
\end{align}\)
\(\begin{align}
\text{where f is convex } f : \mathbb{R}^{n} \rightarrow \mathbb{R}, \quad C \in \mathbb{R}^n 
\quad \text{and} \quad J \in \lbrace 1 \dotsc n \rbrace \\
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The problem is solved recursively.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If the constraint set is trivial, solve the (CR) problem. If the solution is less than the current upper bound, update the upper bound. Stop.
    &lt;ul&gt;
      &lt;li&gt;If (CR) is infeasible, then (IP) is also infeasible. Stop.&lt;/li&gt;
      &lt;li&gt;If the solution \(x^{\star}\) of (CR) is also feasible for (IP), then \(x^{\star}\) becomes the solution. Stop.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Find the lower bound of the problem.
    &lt;ul&gt;
      &lt;li&gt;If the solution \(x^{\star}\) of (CR) is infeasible for (IP), update the lower bound of (IP).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;If the lower bound is greater than the current upper bound, Stop.&lt;/li&gt;
  &lt;li&gt;Split the constraint set and solve each sub-problem recursively.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;after-branching&quot;&gt;After branching&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;After branching, solve each subproblem.&lt;/li&gt;
  &lt;li&gt;If the lower bound of a subproblem is greater than the current upper bound, there is no need to consider the subproblems below it.&lt;/li&gt;
  &lt;li&gt;The most reliable method for computing the lower bound is through convex relaxation, but other methods (e.g., Lagrangian relaxation) are also used.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;branch-and-bound-step-by-step-video&quot;&gt;Branch and bound, step by step (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/branch-bound_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Solve the LP relaxation, branch on a fractional variable, and discard any node whose bound cannot beat the best integer solution found so far.&lt;/p&gt;

&lt;p&gt;Note: the video solves a maximization problem (\(\max\ 5x_1 + 4x_2\)), while this lesson uses the minimization form. They are equivalent because \(\max_x c^Tx = -\min_x (-c^Tx)\). In the maximization form the bounds swap roles: the LP relaxation value at a node is an &lt;strong&gt;upper&lt;/strong&gt; bound, the best integer solution so far is a &lt;strong&gt;lower&lt;/strong&gt; bound, and a node is pruned when its upper bound cannot exceed the best integer value.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-step-through-branch-and-bound&quot;&gt;Try it yourself: step through branch and bound&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;bnb&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>24-04 Relaxations</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_04_Relaxations/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_04_Relaxations</id>
   <content type="html">&lt;p&gt;A relaxation is an intentional, mathematically disciplined lie: we replace an intractable discrete problem with an easier continuous one whose optimal value is &lt;em&gt;guaranteed&lt;/em&gt; to sit below (for minimization) the true integer optimum. Not all relaxations are created equal, however. A sloppy relaxation gives a weak lower bound and forces millions of branch-and-bound nodes, whereas a tight &lt;strong&gt;convex relaxation&lt;/strong&gt; or &lt;strong&gt;Lagrangian relaxation&lt;/strong&gt; can close 90% of the integrality gap at the very root node.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-convex-and-lagrangian-relaxations&quot;&gt;Key ideas: Convex and Lagrangian Relaxations&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Formal Definition of a Relaxation:&lt;/strong&gt; A problem \(\min_{x \in \tilde{S}} \tilde{f}(x)\) is a valid relaxation of \(\min_{x \in S} f(x)\) if (i) \(S \subseteq \tilde{S}\) and (ii) \(\tilde{f}(x) \le f(x)\) for all \(x \in S\). Together these guarantee \(\tilde{f}^\star \le f^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex (LP/SDP) Relaxations:&lt;/strong&gt; Dropping integrality \(x \in \{0, 1\}^n \to x \in [0, 1]^n\) produces the canonical LP relaxation; replacing rank-1 binary matrices \(xx^\top\) with positive semidefinite matrices \(X \succeq 0\) produces tighter SDP relaxations (such as Goemans–Williamson for Max-Cut).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian Relaxation:&lt;/strong&gt; Instead of dropping integrality, dualize a set of “complicating” constraints \(Ax \le b\) into the objective via multipliers \(\lambda \ge 0\): \(g(\lambda) = \min_{x \in X} \{c^\top x + \lambda^\top(Ax - b)\}\), then maximize the concave dual function \(g(\lambda)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Lagrangian Relaxation Can Beat LP Relaxation:&lt;/strong&gt; By Geoffrion’s theorem, if the remaining integer subproblem \(X\) does &lt;em&gt;not&lt;/em&gt; have the integrality property (i.e., \(\operatorname{conv}(X)\) is strictly smaller than its LP relaxation), the Lagrangian dual \(\max_{\lambda \ge 0} g(\lambda)\) equals the LP optimum over \(\operatorname{conv}(X) \cap \{Ax \le b\}\)—strictly tighter than the ordinary LP relaxation!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-a-lagrangian-relaxation-lower-bound&quot;&gt;Worked example: Computing a Lagrangian Relaxation Lower Bound&lt;/h3&gt;

&lt;p&gt;Consider the integer program \(\min_{x_1, x_2 \in \{0, 1\}} -3 x_1 - 4 x_2\) subject to the complicating constraint \(2 x_1 + 3 x_2 \le 4\). (By inspection, we cannot pick both \(x_1 = x_2 = 1\) since \(5 &amp;gt; 4\), so the true IP optimum is \((0, 1)\) with value \(-4\).)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the Lagrangian dualizing \(2 x_1 + 3 x_2 - 4 \le 0\) with \(\lambda \ge 0\):&lt;/strong&gt;
\(g(\lambda) = \min_{x_1, x_2 \in \{0, 1\}} \bigl[(-3 + 2\lambda) x_1 + (-4 + 3\lambda) x_2 - 4\lambda\bigr].\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate \(g(\lambda)\) in closed form:&lt;/strong&gt; Because \(x_1, x_2 \in \{0, 1\}\) decouple completely, we set \(x_i = 1\) iff its coefficient is negative:
\(g(\lambda) = \min(0,\ 2\lambda - 3) + \min(0,\ 3\lambda - 4) - 4\lambda.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test key multiplier values:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;At \(\lambda = 0\): \(g(0) = (-3) + (-4) - 0 = -7\) (weak bound).&lt;/li&gt;
      &lt;li&gt;At \(\lambda = 4/3\): \(g(4/3) = \min(0, -1/3) + 0 - 16/3 = -17/3 \approx -5.667\).&lt;/li&gt;
      &lt;li&gt;At \(\lambda = 3/2\): \(g(3/2) = 0 + 0 - 6 = -6\).&lt;/li&gt;
      &lt;li&gt;Check \(\lambda = 4/3\) vs. the LP relaxation: in the LP relaxation, \(x_1 = 1, x_2 = 2/3\) gives \(-3(1) - 4(2/3) = -17/3 \approx -5.667\)!
Here \(X = \{0, 1\}^2\) has the integrality property, so the best Lagrangian dual bound \(\max_{\lambda \ge 0} g(\lambda) = -17/3\) matches the LP relaxation exactly—and always certifies \(f^\star = -4 \ge -5.667\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For relaxation, specific conditions must be satisfied, and Convex relaxation and Lagrangian relaxation methods can be utilized. Let’s examine the detailed content.&lt;/p&gt;

&lt;h2 id=&quot;conditions-for-relaxations&quot;&gt;Conditions for Relaxations&lt;/h2&gt;

&lt;p&gt;If a general optimization problem is defined as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x \in X} f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;The relaxation of this problem is defined as follows when represented as an arbitrary optimization problem:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x \in Y} \: g(x)\\\\
&amp;amp;\text{such that}\\\\
&amp;amp;\text{① } X \subset Y \quad \text{ and}\\\\
&amp;amp;\text{② } g(x) \leq f(x) \text{ for all } x \in X
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;If the objective functions \(f(x)\) and \(g(x)\) are different, both conditions must be satisfied, and if they are the same, only condition ① needs to be satisfied. By these two conditions, the optimal value of the relaxation becomes a lower bound of the optimal value of the original problem.&lt;/p&gt;

&lt;h2 id=&quot;convex-relaxations&quot;&gt;Convex relaxations&lt;/h2&gt;

&lt;p&gt;When the given problem is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; x \in C \\\\
&amp;amp;&amp;amp;&amp;amp;x_j \in \mathbb{Z}, \quad j \in J \\\\
\end{align}\]

\[\begin{align}
\text{where } f \text{ is convex, } f : \mathbb{R}^{n} \rightarrow \mathbb{R}, \quad C \subseteq \mathbb{R}^n
\quad \text{and} \quad J \subseteq \{1, \dotsc, n\}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The convex relaxation can be expressed as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp; f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; x \in C \\\\
\end{align}\]

\[\begin{align}
\text{where } f \text{ is convex, } f: \mathbb{R}^{n} \rightarrow \mathbb{R}, \quad C \subseteq \mathbb{R}^n
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;lagrangian-relaxations&quot;&gt;Lagrangian relaxations&lt;/h2&gt;

&lt;p&gt;When \(X\) includes both convex and integer constraints, we can define the problem as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;Ax \leq b \\\\
&amp;amp;&amp;amp;&amp;amp; x_{j} \in \mathbb{Z}, \quad x \in X
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In this case, by adding constraints to the objective and performing Lagrangian relaxation for some \(u \geq 0\), we get:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
L(u) = &amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) + u^{\top}(Ax-b) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;x \in X
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Through the Lagrangian form, the constraint set is expanded, and since feasible \(x\) satisfies \(Ax \leq b\), we always have \(f(x) + u^{\top}(Ax - b) \leq f(x)\) for \(u \geq 0\). Therefore, \(L(u)\) is a lower bound for any \(u \geq 0\), and the best lower bound can be obtained by solving the dual problem \(\max_{u \geq 0} L(u)\). Remember that since \(L(u)\) is the point-wise minimum of convex functions, it becomes a concave optimization problem.&lt;/p&gt;

&lt;p&gt;Applying Lagrangian relaxation to the previously mentioned Facility location problem, it transforms into a problem of solving the following equation for unconstrained \(v\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
L(u) = &amp;amp;\min_{x} &amp;amp;&amp;amp; \sum_{j = 1}^{n} f_{j}y_{j} + \sum_{i = 1}^{m}\sum_{j = 1}^{n}(c_{ij} - v_{i})x_{ij} + \sum_{i = 1}^{m} v_{i} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; x_{ij} \leq y_{j} \quad i = 1, \dotsc, m, \quad j = 1, \dotsc, n \\\\
&amp;amp;&amp;amp;&amp;amp; x_{ij}, y_{j} \in \{0, 1\} \quad i = 1, \dotsc, m, \quad j = 1, \dotsc, n
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;For each \(v\), the Lagrange relaxation \(L(v)\) can be easily solved:&lt;/p&gt;

&lt;blockquote&gt;
\[x_{ij}(v) =\begin{cases}
1 &amp;amp; \text{if } c_{ij} - v_{i} &amp;lt; 0 \text{ and } \sum_{l} (c_{lj} - v_{l})^{-} + f_{j} &amp;lt; 0 \\\\
0 &amp;amp; \text{otherwise}
\end{cases}\]

\[y_{j}(v) =\begin{cases}
1 &amp;amp; \text{if } \sum_{l} (c_{lj} - v_{l})^{-} + f_{j} &amp;lt; 0 \\\\
0 &amp;amp; \text{otherwise}
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;From this lower bound \(L(v)\), we can also derive heuristic primal solutions. Also, using the subdifferential of \(-L(v)\) makes computation easier. Using the subgradient method, we can solve the problem by transforming \(\max_{v} L(v)\) to \(\min_{v} -L(v)\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>24-03 Solving integer programs</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_03_Solving_integer_programs/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_03_Solving_integer_programs</id>
   <content type="html">&lt;p&gt;If an integer program with 100 binary variables has \(2^{100} \approx 1.26 \times 10^{30}\) candidate solutions, how can a commercial solver find the certified global optimum in under a second? It never enumerates the haystack. Instead, every modern MIP solver runs a disciplined &lt;strong&gt;primal–dual squeeze&lt;/strong&gt;: primal heuristics hunt for better feasible integer solutions to push the upper bound \(U\) down, while relaxations and cuts push the certified lower bound \(L\) up. The moment \(U - L \le \varepsilon\), global optimality is mathematically guaranteed—even though \(99.999999\%\) of the search space was never visited.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-complexity-and-the-primaldual-bounding-template&quot;&gt;Key ideas: Complexity and the Primal–Dual Bounding Template&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;NP-Hardness in Worst Case vs. Tractability in Practice:&lt;/strong&gt; Integer linear programming is NP-complete (Karp 1972), meaning no known polynomial-time algorithm works for all instances. Yet structured real-world instances yield rapidly to strong relaxations and aggressive pruning.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal Bounds (Upper Bounds for Minimization):&lt;/strong&gt; Any feasible integer point \(\hat{x} \in \mathcal{F}\) immediately certifies \(f^\star \le f(\hat{x}) = U\). Solvers generate primal bounds via rounding, feasibility pumps, local search, and integer relaxation solutions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Bounds (Lower Bounds for Minimization):&lt;/strong&gt; Solving any relaxation over a superset \(\tilde{\mathcal{F}} \supseteq \mathcal{F}\) (or minimizing a lower-bounding objective \(\tilde{f} \le f\)) certifies \(L = \tilde{f}^\star \le f^\star\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Optimality Gap &amp;amp; Certified Termination:&lt;/strong&gt; The relative MIP gap $$\frac{U - L}{&lt;/td&gt;
          &lt;td&gt;U&lt;/td&gt;
          &lt;td&gt;}\(measures exact worst-case suboptimality. Stopping at a\)0.1\%\(gap delivers a solution provably within\)0.1\%$$ of global optimality without spending hours proving the last decimal place.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-tracking-primaldual-bounds-and-the-mip-gap&quot;&gt;Worked example: Tracking Primal/Dual Bounds and the MIP Gap&lt;/h3&gt;

&lt;p&gt;Suppose we minimize a discrete cost \(f(x)\) over integer feasible set \(\mathcal{F}\), and our solver executes three rounds of relaxation refinement and primal heuristics:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Initialization:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;LP relaxation solves to \(x_{\text{LP}}\) with objective \(L_0 = 80\).&lt;/li&gt;
      &lt;li&gt;Rounding \(x_{\text{LP}}\) yields a feasible integer solution \(x^{(0)} \in \mathcal{F}\) with cost \(U_0 = 100\).&lt;/li&gt;
      &lt;li&gt;Current absolute gap: \(U_0 - L_0 = 20\); relative gap: \(\frac{100 - 80}{100} = 20.0\%\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Round 1 (Add a valid inequality + run local search):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tightened relaxation raises the lower bound to \(L_1 = 88\).&lt;/li&gt;
      &lt;li&gt;Local search improves the incumbent integer solution to \(U_1 = 92\).&lt;/li&gt;
      &lt;li&gt;Absolute gap drops from \(20\) to \(4\); relative gap drops to \(\frac{92 - 88}{92} \approx 4.35\%\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Round 2 (Branching certifies all subproblems \(\ge 92\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Every remaining leaf relaxation has lower bound \(\ge 92\), so the global dual bound becomes \(L_2 = 92\).&lt;/li&gt;
      &lt;li&gt;Since \(L_2 = U_1 = 92\), the gap is \(0\%\): the incumbent with cost \(92\) is &lt;strong&gt;provably globally optimal&lt;/strong&gt;, without ever evaluating the remaining exponentially many integer vectors!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After transforming the mathematical formulation of Integer programming, techniques such as relaxation are needed to solve the problem. Let’s examine the constraints that appear in integer programs and what approaches are taken to address the problem.&lt;/p&gt;

&lt;h2 id=&quot;hardness-of-integer-programs&quot;&gt;Hardness of integer programs&lt;/h2&gt;
&lt;p&gt;Solving Integer program problems is much more difficult than solving convex optimization problems. General Integer programming is &lt;a href=&quot;https://en.wikipedia.org/wiki/NP-hardness&quot;&gt;NP-hard&lt;/a&gt;, requiring at least polynomial time without even knowing the possibility of solvability. In this case, by removing constraints on integer constraints and performing convex relaxation, we can obtain a lower bound that approaches the optimal value.&lt;br /&gt;&lt;br /&gt;
When solving problems using convex relaxation, the following limitations may occur:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Finding a feasible integer solution can become difficult.&lt;/li&gt;
  &lt;li&gt;The optimal solution obtained under relaxation conditions may be distant from the optimal solution obtained with integer programming.&lt;/li&gt;
  &lt;li&gt;The value after approximation (rounding) may differ from the optimal value.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;algorithmic-template-for-solving-integer-programs&quot;&gt;Algorithmic template for solving integer programs&lt;/h2&gt;
&lt;p&gt;When \(X\) is convex and includes integrality constraints, the integer program is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[z : = \min_{x \in X} f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Unlike convex optimization, there are no direct “optimality conditions” that prove a feasible point \(x* \in X\) is optimal. Instead, we can use a method that finds approximations of the optimal by finding lower bound \(\underline{z} \leq z\) and upper bound \(\bar{z} \geq z\) while approaching \(\underline{z} = \bar{z}\).&lt;/p&gt;

&lt;h3 id=&quot;algorithmic-template&quot;&gt;Algorithmic template&lt;/h3&gt;
&lt;p&gt;Observing the decreasing sequence of upper bounds,&lt;/p&gt;
&lt;blockquote&gt;
\[\bar{z_1} \geq \bar{z_2} \geq \dotsc \bar{z_s} \geq z\]
&lt;/blockquote&gt;

&lt;p&gt;Observing the increasing sequence of lower bounds,&lt;/p&gt;
&lt;blockquote&gt;
\[\underline{z_1} \leq \underline{z_2} \leq \dotsc \underline{z_t} \leq z\]
&lt;/blockquote&gt;

&lt;p&gt;For any \(\epsilon &amp;gt; 0\), the value of \(z\) is determined within the range where \(\bar{z_s} - \underline{z_t} \leq \epsilon\).&lt;/p&gt;

&lt;h3 id=&quot;primal-bounds&quot;&gt;Primal bounds&lt;/h3&gt;
&lt;p&gt;According to the previous \(z\) formula, for any feasible \(x \in X\), \(f(x) \geq z\) always holds, and in this case, \(f(x)\) is an upper bound. However, since we cannot always find a feasible \(x\), if the \(x\) value is included in the corresponding set, the problem can be solved easily, but this may not always be the case.&lt;/p&gt;

&lt;h3 id=&quot;dual-bounds&quot;&gt;Dual bounds&lt;/h3&gt;
&lt;p&gt;Usually also called lower bounds, their values are found through relaxation. Detailed explanations are added in the next section.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>24-02 Examples of integer programs</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_02_Example_of_integer_programs/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_02_Example_of_integer_programs</id>
   <content type="html">&lt;p&gt;What do packing a cargo plane, matching Uber drivers to riders, choosing warehouse locations, clustering customers, and selecting the top \(k\) biomarkers in a genomics study all have in common? Beneath completely different surface stories, all six are canonical Mixed Integer Programs! Learning these six architectural templates—Knapsack, Assignment, Facility Location, \(K\)-medoids, Best Subset Selection, and Least Median of Squares—gives you a reusable vocabulary for translating almost any discrete decision or robust statistical problem into a solvable MIP.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-six-canonical-mip-modeling-templates&quot;&gt;Key ideas: Six Canonical MIP Modeling Templates&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Knapsack &amp;amp; Resource Packing:&lt;/strong&gt; Binary selection \(x_j \in \{0, 1\}\) maximizes total value \(\sum v_j x_j\) subject to a single capacity budget \(\sum w_j x_j \le C\)—the atomic building block of resource allocation and cutting-plane theory.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assignment &amp;amp; Total Unimodularity:&lt;/strong&gt; Matching \(n\) workers to \(n\) tasks with \(\sum_j x_{ij} = 1\) and \(\sum_i x_{ij} = 1\) has a totally unimodular constraint matrix, meaning every vertex of its LP relaxation is &lt;em&gt;already integral&lt;/em&gt;—an extraordinary case where LP solves the IP exactly!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Facility Location (Uncapacitated):&lt;/strong&gt; Pairs binary open/close decisions \(y_i \in \{0, 1\}\) with assignment fractions \(x_{ij} \ge 0\) via linking constraints \(x_{ij} \le y_i\), balancing fixed infrastructure costs against variable transport distances.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Combinatorial Statistics (Best Subset &amp;amp; LMS):&lt;/strong&gt; Binary support variables \(z_j \in \{0, 1\}\) with \(\sum z_j \le k\) and big-\(M\) bounds $$&lt;/td&gt;
          &lt;td&gt;\beta_j&lt;/td&gt;
          &lt;td&gt;\le M z_j\(formulate exact\)\ell_0$$-constrained regression, while binary outlier switches formulate breakdown-proof Least Median of Squares.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-a-3-item-01-knapsack-and-checking-lp-relaxation&quot;&gt;Worked example: Solving a 3-Item 0–1 Knapsack and Checking LP Relaxation&lt;/h3&gt;

&lt;p&gt;Maximize value \(6 x_1 + 10 x_2 + 12 x_3\) subject to weight \(1 x_1 + 2 x_2 + 3 x_3 \le 5\) and \(x_1, x_2, x_3 \in \{0, 1\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute value-to-weight ratios:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Item 1: \(6 / 1 = 6.0\),&lt;/li&gt;
      &lt;li&gt;Item 2: \(10 / 2 = 5.0\),&lt;/li&gt;
      &lt;li&gt;Item 3: \(12 / 3 = 4.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the LP relaxation (\(0 \le x_j \le 1\)) greedily by ratio:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Take full Item 1 (weight \(1\), remaining \(4\), value \(6\)).&lt;/li&gt;
      &lt;li&gt;Take full Item 2 (weight \(2\), remaining \(2\), value \(16\)).&lt;/li&gt;
      &lt;li&gt;Take \(\frac{2}{3}\) of Item 3 (weight \(2\), remaining \(0\), value \(16 + \frac{2}{3}(12) = 24\)).
So \(x_{\text{LP}} = (1, 1, 2/3)^\top\) with LP upper bound \(24\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare greedy integer rounding vs. true IP optimum:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Greedy integer solution (take Items 1 &amp;amp; 2, skip Item 3): \(x = (1, 1, 0)^\top\), weight \(3 \le 5\), value \(16\).&lt;/li&gt;
      &lt;li&gt;Check taking Items 2 &amp;amp; 3: \(x = (0, 1, 1)^\top\), weight \(2 + 3 = 5 \le 5\), value \(10 + 12 = 22\)!&lt;/li&gt;
      &lt;li&gt;Since all values are integers and \(22 &amp;lt; 24\) (can we get \(23\)? No subset of \(\{6, 10, 12\}\) sums to \(23\); all sums are even!), \(x^\star = (0, 1, 1)^\top\) with value \(22\) is provably optimal. Notice how the greedy heuristic missed the optimum by \(6\) units!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, let’s examine various examples corresponding to Integer programming and learn how they are utilized.&lt;/p&gt;

&lt;h2 id=&quot;knapsack-problem&quot;&gt;Knapsack problem&lt;/h2&gt;
&lt;p&gt;The Knapsack problem is a traditional combinatorial optimization problem where the volume that can be put into the knapsack is limited, constraining the total magnitude of items that can fit inside the knapsack. When this constraint exists, the problem aims to select items with maximum value. This problem can be expressed using binary variables \(x\), where \(x_{j}\) takes a value of 0 or 1 depending on whether the \(j\)-th item is selected or not.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{x} &amp;amp;&amp;amp; c^\intercal x \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; a^\intercal x \leq b \\\\
&amp;amp;&amp;amp;&amp;amp;x_{j} \in {0, 1}, j = 1, \dotsc , n
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;\(c_{j}, a_{j}\) represent the value and magnitude (volume) of the \(j\)-th item, respectively.&lt;/p&gt;

&lt;h2 id=&quot;assignment-problem&quot;&gt;Assignment problem&lt;/h2&gt;
&lt;p&gt;Let’s assume there are \(n\) people and \(n\) tasks. Each person can be assigned to exactly one task. Here, \(c_{ij}\) represents the cost required for person \(i\) to perform task \(j\). The Assignment problem aims to assign \(n\) people to \(n\) tasks with the minimum cost. To optimize these conditions, the mathematical formulation is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;\sum_{i = 1}^{n} \sum_{j = 1}^{n} c_{ij} x_{ij} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;\sum_{i = 1}^{n} x_{ij} = 1, j = 1 \dotsc n \\\\
&amp;amp;&amp;amp;&amp;amp;\sum_{j = 1}^{n} x_{ij} = 1, i = 1 \dotsc n \\\\
&amp;amp;&amp;amp;&amp;amp;x_{ij} \in \lbrace 0, 1\rbrace \quad i = 1 \dotsc n, \quad j = 1 \dotsc n
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;facility-location-problem&quot;&gt;Facility location problem&lt;/h2&gt;
&lt;p&gt;The Facility location problem aims to minimize transportation costs from specific facilities to customers.&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Let’s assume there are depots \(N = \lbrace 1, \dotsc, n \rbrace\) and customers \(M = \lbrace 1, \dotsc, m \rbrace\).&lt;br /&gt;
The fixed cost \(f_{j}\) is associated with using depot \(j\).
The transportation cost \(c_{ij}\) is the cost incurred when goods delivered to customer \(i\) are transported from depot \(j\).&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;The decisions to be made here are which depots should be operational and which customers should receive deliveries from each depot, with the goal of minimizing both fixed costs and transportation costs by deriving and solving the mathematical formulation.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y} &amp;amp;&amp;amp; \sum_{i = 1}^{n} f_{j} y_{j} + \sum_{i = 1}^{m} \sum_{j = 1}^{n} c_{ij} x_{ij} \\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; \sum_{j = 1}^{n} x_{ij} = 1,  \quad i = 1 \dotsc m \\
&amp;amp;&amp;amp;&amp;amp; x_{ij} \leq y_{j},  \quad i = 1 \dotsc m,  \quad j = 1 \dotsc n \\
&amp;amp;&amp;amp;&amp;amp; x_{ij} \in \lbrace 0, 1\rbrace \quad i = 1 \dotsc m, \quad j = 1 \dotsc n \\
&amp;amp;&amp;amp;&amp;amp; y_{j} \in \lbrace 0, 1\rbrace \quad j = 1 \dotsc n \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The first constraint means that each customer can receive goods from one depot. The second constraint states that depot \(j\) must be operational for customer \(i\) to receive goods from there. Since both \(x_{ij}\) and \(y_{j}\) are binary, we can consider \(mn\) constraints. This can also be expressed in a “marginalized” form as the following constraint:&lt;/p&gt;

&lt;blockquote&gt;
\[\sum_{i = 1}^{n} x_{ij} \leq m y_{j}, \quad j = 1 \dotsc n\]
&lt;/blockquote&gt;

&lt;p&gt;Reflecting this, it can be replaced with the following mathematical formulation:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y} &amp;amp;&amp;amp;\sum_{i = 1}^{n} f_{j} y_{j} + \sum_{i = 1}^{m} \sum_{j = 1}^{n} c_{ij} x_{ij} \\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;\sum_{j = 1}^{n} x_{ij} = 1,  \quad i = 1 \dotsc n \\
&amp;amp;&amp;amp;&amp;amp; \sum_{i = 1}^{n} x_{ij} \leq m y_{j}, \quad j = 1 \dotsc n \\
&amp;amp;&amp;amp;&amp;amp; x_{ij} \in \lbrace 0, 1\rbrace \quad i = 1 \dotsc n, \quad j = 1 \dotsc n \\
&amp;amp;&amp;amp;&amp;amp; y_{j} \in \lbrace 0, 1\rbrace \quad j = 1 \dotsc n \\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;k-means-and-k-medoids-clustering&quot;&gt;K-means and K-medoids clustering&lt;/h2&gt;
&lt;p&gt;Clustering is the process of dividing data into similar groups. The K-means algorithm aims to find K clusters by finding \(K\) center values (centroids) that minimize the average distance between data points within clusters. The goal is to find a partition \(S_{1} \cup \dotsc \cup S_{K} = \lbrace 1, \dotsc, n \rbrace\) for the given data. In this case, the following formula is minimized:&lt;/p&gt;

\[\sum_{i = 1}^{K} \sum_{j \in S_{i}} \| x^{(j)} - \mu^{(i)} \|^{2}\]

&lt;p&gt;where \(\mu^{(i)} :  = \frac{1}{| S_{i} |} \sum_{j \in S_{i}} x^{(i)}\),
\(\mu^{(i)}\) represents the centroid of cluster \(i\).&lt;/p&gt;

&lt;p&gt;A method that is more robust to outliers than computing centroids by averaging (K-means) is K-medoids clustering, which sets the center value as the data point closest to the cluster center instead of computing the center values of K clusters using arithmetic mean.
That is, K-medoids clustering is a method that considers each data point (\(y^{(i)}\)) as a center point and designates the data point that yields the minimum value when computed as the centroid.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\sum_{i = 1}^{K} \sum_{j \in S_{i}} \| x^{(j)} - y^{(i)} \|^{2}\)
\(\text{where } y^{(i)} \in \lbrace x^{(j)} : j \in S_{i} \rbrace\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br /&gt;
This problem can be transformed and represented as an integer program.
First, we define \(d_{ij} = \| x^{(i)} - x^{(j)} \|^2\) and define the following two binary variables:&lt;/p&gt;

\[\begin{align}
&amp;amp;w_{i} =\begin{cases}1 &amp;amp;&amp;amp; \text{if choose } x^{(i)} \text{ as a centroid} \\\\
0 &amp;amp;&amp;amp; \text{otherwise.} \end{cases}\\\\
&amp;amp;z_{ji} =\begin{cases}1 &amp;amp;&amp;amp; \text{if } x^{(j)} \text{ in the cluster with centroid } x^{(i)} \\\\
0 &amp;amp;&amp;amp; \text{otherwise.} \end{cases}
\end{align}\]

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;The K-medoids problem can be defined as an optimization problem as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{w, z} &amp;amp;&amp;amp; \sum_{i = 1}^{n} \sum_{j = 1}^{n} d_{ij} z_{ji} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; z_{ji} \leq w_{i} \\\\
&amp;amp;&amp;amp;&amp;amp; \sum_{i = 1}^{n} w_{i} = k \\\\
&amp;amp;&amp;amp;&amp;amp; w_{ij} \in 0, 1 \quad i = 1 \dotsc n \\\\
&amp;amp;&amp;amp;&amp;amp; z_{ji} \in 0, 1 \quad j, i = 1 \dotsc n
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The first constraint means that after the centroid is first determined, we will determine whether $x_{j}$ belongs to $x_{i}$ or not.&lt;/p&gt;

&lt;h2 id=&quot;best-subset-selection&quot;&gt;Best subset selection&lt;/h2&gt;
&lt;p&gt;When the conditions \(X = [x^{1} \quad \dotsc \quad x^{p}] \in \mathbb{R}^{n×p}, \quad y \in \mathbb{R}^{n}\) are given, the Best subset selection problem is as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\min_{\beta} &amp;amp;&amp;amp;\frac{1}{2} \| y - X\beta \|^{2} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;\| \beta \| \leq k\\\\
\end{align}\)
\(\begin{align}
\text{where}  \| \beta \|_{0}  :  = \text{ the number of nonzero entries of } \beta.
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since \(\| \beta \|_{0}\) is a non-convex constraint, the problem can be solved more easily by transforming it using Integer programming.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{\beta, z} &amp;amp;&amp;amp; \frac{1}{2} \| y - X\beta \|^{2} \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; | \beta_{i} | \leq Mz_{i} \quad i = 1 \dotsc n \\\\
&amp;amp;&amp;amp;&amp;amp;z_{ji} \in \lbrace 0, 1 \rbrace \quad i = 1 \dotsc n \\\\
&amp;amp;&amp;amp;&amp;amp;\sum_{i = 1}^{p} z_{i} \leq k
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;least-median-of-squares-regression&quot;&gt;Least median of squares regression&lt;/h2&gt;
&lt;p&gt;When the conditions \(X = [x^{1} \quad \dotsc \quad x^{p}] \in \mathbb{R}^{n×p}, \quad y \in \mathbb{R}^{n}\), and \(\beta \in \mathbb{R}^{p}\) are given, if we define \(r : = y - X\beta\), the Least median of squares regression problem is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\beta_{LMS} : = \arg\min_{\beta} (median | r_{i} | ).\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>24-01 Definition</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_01_Definition/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter24/24_01_Definition</id>
   <content type="html">&lt;p&gt;Adding a single line—\(x_i \in \mathbb{Z}\)—to a linear program looks innocent on paper, yet it separates polynomial-time solvability from NP-completeness. At the same time, that single integrality constraint unlocks an extraordinary modeling language: binary variables \(z \in \{0, 1\}\) turn logical rules, fixed setup costs, and “either-or” constraints into clean linear inequalities via big-\(M\) formulations. Mastering the exact definition of MIPs and binary indicator tricks is the foundation of every discrete optimization model.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-mixed-integer-programs-and-binary-logic&quot;&gt;Key ideas: Anatomy of Mixed Integer Programs and Binary Logic&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch24_integer_programming_bnb.svg&quot; alt=&quot;Quy hoạch Nguyên (IP) và Chiến lược Nhánh Cận&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;General MIP Taxonomy:&lt;/strong&gt; Depending on whether the underlying objective and constraints are linear, quadratic, or general convex, we obtain MILP (Mixed Integer Linear Program), MIQP, or MINLP. Pure integer programs restrict &lt;em&gt;all&lt;/em&gt; variables to \(\mathbb{Z}\); mixed integer programs allow continuous and discrete variables to coexist.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Binary Indicator Variables (\(z \in \{0, 1\}\)):&lt;/strong&gt; Binary variables act as algebraic switches. For example, \(z_1 + z_2 \le 1\) encodes mutual exclusivity (“at most one of A or B”), while \(z_1 \le z_2\) encodes logical implication (“if A is chosen, B must also be chosen”).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Big-\(M\) Linking Constraints:&lt;/strong&gt; To link a continuous flow \(x \ge 0\) to a binary activation switch \(z \in \{0, 1\}\), we write \(x \le M z\) where \(M\) is a valid upper bound on \(x\). When \(z = 0\), \(x\) is forced to \(0\); when \(z = 1\), \(x \le M\) is inactive.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tightness of \(M\) Matters:&lt;/strong&gt; Although any huge \(M\) gives the same integer feasible set, an unnecessarily large \(M\) weakens the continuous LP relaxation dramatically—making tight domain-specific bounds on \(M\) one of the highest-leverage modeling skills in MIP.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-tight-vs-loose-big-m-formulations&quot;&gt;Worked example: Tight vs. Loose Big-\(M\) Formulations&lt;/h3&gt;

&lt;p&gt;Suppose a factory decides whether to open a machine (\(z \in \{0, 1\}\), fixed cost \(100\)) and how many units \(x \in [0, 10]\) to produce, with constraint “\(x &amp;gt; 0 \implies z = 1\)”. We want to minimize \(100 z - 15 x\) when demand requires \(x = 4\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tight formulation (\(M = 10\), exact capacity):&lt;/strong&gt; Constraint is \(x \le 10 z\).
    &lt;ul&gt;
      &lt;li&gt;At \(x = 4\), the LP relaxation allows \(z = 4 / 10 = 0.4\), giving LP lower bound \(100(0.4) - 15(4) = 40 - 60 = -20\).&lt;/li&gt;
      &lt;li&gt;The true integer optimum has \(z = 1\), giving \(100(1) - 15(4) = +40\). Integrality gap \(= 40 - (-20) = 60\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Loose formulation (\(M = 1000\), lazy guess):&lt;/strong&gt; Constraint is \(x \le 1000 z\).
    &lt;ul&gt;
      &lt;li&gt;At \(x = 4\), the LP relaxation sets \(z = 4 / 1000 = 0.004\), giving LP lower bound \(100(0.004) - 60 = -59.6\).&lt;/li&gt;
      &lt;li&gt;Integrality gap balloons to \(40 - (-59.6) = 99.6\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Both formulations define the &lt;em&gt;exact same&lt;/em&gt; integer feasible points, yet choosing the tightest valid \(M = 10\) strengthens the relaxation lower bound by nearly \(40\) units before the solver even branches once.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section aims to explain the basic concepts for solving optimization problems through the mixed integer program approach.&lt;/p&gt;

&lt;h2 id=&quot;problem-definition&quot;&gt;Problem definition&lt;/h2&gt;

&lt;p&gt;When some variables in an optimization model have the constraint of being integers, this is called an integer program.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp; f(x) \\\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; x \in C \\\\
&amp;amp;&amp;amp;&amp;amp;x_{j} \in \mathbb{Z}, j \in J
\end{align}\]

\[\begin{align}
\text{where } f: \mathbb{R}^{n} \rightarrow \mathbb{R}, \quad C \subseteq \mathbb{R}^{n} \quad \text{and} \quad J \subseteq \{1, \dotsc, n\}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In the above expression, if \(J\) satisfies the following, it is called a pure integer program.&lt;/p&gt;

\[J = \{1, \dotsc, n\}\]

&lt;p&gt;Let us assume that both \(f\) and \(C\) discussed in this section are convex.&lt;/p&gt;

&lt;h2 id=&quot;binary-variables&quot;&gt;Binary variables&lt;/h2&gt;

&lt;p&gt;Looking at some representative examples of integer programs, we can mention yes/no decision problems or logical values. In this case, we define the problem using binary variables and solve the problem to find values of 0 or 1 for the conditions.&lt;/p&gt;

&lt;p&gt;The combinatorial optimization to be introduced next is directly associated with integer programming. This is because by utilizing binary variables, we can transform existing problems and solve them as new problems.&lt;/p&gt;

&lt;p&gt;Combinatorial optimization problems are defined using the triple \((N, \mathcal{F}, c)\) representation.&lt;br /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;\(N\) is a finite ground set&lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;\(\mathcal{F} \subseteq 2^{N}\) is the set of feasible solutions&lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;\(c \in \mathbb{R}^{N}\) is the cost function&lt;br /&gt;&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;The ultimate goal is to solve the following equation through the triple \((N, \mathcal{F}, c)\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{S \in \mathcal{F}} &amp;amp; \sum_{i \in S} c_{i}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Many combinatorial optimization problems can be formulated using binary integer programs.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>23 Coordinate Descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_Coordinate_Descent/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_Coordinate_Descent</id>
   <content type="html">&lt;p&gt;At first glance, Coordinate Descent looks almost embarrassingly naive: instead of moving along the full gradient in \(\mathbb{R}^p\), freeze \(p - 1\) variables, minimize along a single coordinate axis, and cycle to the next. Why would anyone trade a sophisticated full-gradient direction for axis-aligned baby steps? Yet in modern high-dimensional statistics—most famously in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; for Lasso and Elastic Net—Coordinate Descent routinely crushes gradient descent and even accelerated proximal gradient by an order of magnitude. The secret is that every single coordinate update uses the &lt;em&gt;freshest&lt;/em&gt; information immediately (Gauss–Seidel style) and exploits closed-form 1D minimizers with zero line-search overhead.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-coordinate-wise-optimization-dominates-high-dimensional-regression&quot;&gt;Key ideas: Why Coordinate-Wise Optimization Dominates High-Dimensional Regression&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gauss–Seidel vs. Jacobi Updates:&lt;/strong&gt; Full gradient descent updates all \(p\) coordinates simultaneously from the same stale point (Jacobi). Coordinate descent updates coordinate \(i\) immediately and feeds the new \(x_i^{(k)}\) into coordinate \(i+1\) (Gauss–Seidel), enabling larger effective coordinate-wise step sizes \(1/L_i\) instead of the conservative global \(1/L\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Separability and Nonsmooth Convexity:&lt;/strong&gt; Tseng’s theorem guarantees global convergence of coordinate descent for composite functions \(f(x) = g(x) + \sum_{i=1}^p h_i(x_i)\) whenever \(g\) is smooth convex and the nonsmooth penalty separates across coordinates (like \(\lambda \|x\|_1\)). Without separability, coordinate descent can get stuck at non-optimal kinks!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate Selection Rules:&lt;/strong&gt; Cyclic sweeps are cache-friendly and deterministic; randomized coordinate descent (sampling coordinate \(i\) proportionally to \(L_i\)) yields clean complexity bounds; greedy (Gauss–Southwell) selection picks the coordinate with the largest gradient magnitude.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Residual Maintenance for \(O(n)\) Updates:&lt;/strong&gt; In linear models \(y - X\beta\), updating a single coordinate \(\beta_j \to \beta_j^+\) lets us refresh the residual vector \(r \leftarrow r - (\beta_j^+ - \beta_j) X_j\) in \(O(n)\) time, making one full sweep of \(p\) coordinates cost \(O(np)\)—the exact same cost as a single full gradient!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-cyclic-coordinate-descent-sweep-on-a-2d-quadratic&quot;&gt;Worked example: One Cyclic Coordinate Descent Sweep on a 2D Quadratic&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = x_1^2 + 2 x_2^2 + 2 x_1 x_2 - 4 x_1 - 6 x_2\) starting from \(x^{(0)} = (0, 0)^\top\). (The exact minimizer satisfies \(2x_1 + 2x_2 = 4\) and \(2x_1 + 4x_2 = 6\), giving \(x^\star = (1, 1)^\top\) with \(f(x^\star) = -5\).)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Update \(x_1\) holding \(x_2 = 0\) fixed:&lt;/strong&gt;
Set \(\frac{\partial f}{\partial x_1} = 2 x_1 + 2 x_2 - 4 = 0 \implies x_1^{(1)} = 2 - x_2^{(0)} = 2\).
Objective drops from \(f(0, 0) = 0\) to \(f(2, 0) = 4 - 8 = -4\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update \(x_2\) using the NEW \(x_1^{(1)} = 2\):&lt;/strong&gt;
Set \(\frac{\partial f}{\partial x_2} = 4 x_2 + 2 x_1^{(1)} - 6 = 0 \implies x_2^{(1)} = \frac{6 - 2(2)}{4} = 0.5\).
Objective drops further to \(f(2, 0.5) = 4 + 0.5 + 2 - 8 - 3 = -4.5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second sweep to verify rapid contraction:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x_1^{(2)} = 2 - 0.5 = 1.5\),&lt;/li&gt;
      &lt;li&gt;\(x_2^{(2)} = \frac{6 - 2(1.5)}{4} = 0.75\), giving \(f(1.5, 0.75) = -4.875\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Notice the geometric rate:&lt;/strong&gt; Error in \(x_2\) shrinks by exactly a factor of \(1/2\) each sweep: \(1 \to 0.5 \to 0.25\), converging monotonically without ever tuning a step size \(\eta\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Coordinate descent is an optimization algorithm that iteratively moves along each coordinate axis to find the minimum of the objective function. At each iteration, according to a coordinate selection rule, it determines a coordinate axis (coordinate) or coordinate block, then minimizes the function along the direction of that axis while keeping the unselected coordinate axes or coordinate blocks fixed (exactly or inexactly).&lt;/p&gt;

&lt;p&gt;Coordinate descent can be utilized not only with gradient-based methods but also with gradient-free methods. Additionally, depending on the case, line search can be used to determine appropriate step sizes for each axis [16].&lt;/p&gt;

&lt;p&gt;Coordinate descent is very simple and easy to implement, and shows very good performance when carefully implemented for appropriate problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt; lasso regression, lasso GLMs (under proximal Newton), SVMs, group lasso, graphical lasso (applied to the dual), additive modeling, matrix completion, regression with nonconvex penalties&lt;/p&gt;

&lt;h2 id=&quot;references-and-further-readings&quot;&gt;References and Further readings&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Early coordinate descent in optimization:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;D. Bertsekas and J. Tsitsiklis (1989), “Parallel and distributed computation: numerical methods”&lt;/li&gt;
  &lt;li&gt;Z. Luo and P. Tseng (1992), “On the convergence of the coordinate descent method for convex differentiable minimization”&lt;/li&gt;
  &lt;li&gt;J. Ortega and W. Rheinboldt (1970), “Iterative solution of nonlinear equations in several variables”&lt;/li&gt;
  &lt;li&gt;P. Tseng (2001), “Convergence of a block coordinate descent method for nondifferentiable minimization”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Early coordinate descent references in statistics and ML:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;I. Daubechies and M. Defrise and C. De Mol (2004), “An iterative thresholding algorithm for linear inverse problems with a sparsity constraint”&lt;/li&gt;
  &lt;li&gt;J. Friedman and T. Hastie and H. Hoefling and R. Tibshirani (2007), “Pathwise coordinate optimization”&lt;/li&gt;
  &lt;li&gt;W. Fu (1998), “Penalized regressions: the bridge versus the lasso”&lt;/li&gt;
  &lt;li&gt;T. Wu and K. Lange (2008), “Coordinate descent algorithms for lasso penalized regression”&lt;/li&gt;
  &lt;li&gt;A. van der Kooij (2007), “Prediction accuracy and stability of regression with optimal scaling transformations”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Coordinate descent applications:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;O. Banerjee and L. Ghaoui and A. d’Aspremont (2007), “Model selection through sparse maximum likelihood estimation”&lt;/li&gt;
  &lt;li&gt;J. Friedman and T. Hastie and R. Tibshirani (2007), “Sparse inverse covariance estimation with the graphical lasso”&lt;/li&gt;
  &lt;li&gt;J. Friedman and T. Hastie and R. Tibshirani (2009), “Regularization paths for generalized linear models via coordinate descent”&lt;/li&gt;
  &lt;li&gt;C.J. Hsieh and K.W. Chang and C.J. Lin and S. Keerthi and S. Sundararajan (2008), “A dual coordinate descent method for large-scale linear SVM”&lt;/li&gt;
  &lt;li&gt;R. Mazumder and J. Friedman and T. Hastie (2011), “SparseNet: coordinate descent with non-convex penalties”&lt;/li&gt;
  &lt;li&gt;J. Platt (1998), “Sequential minimal optimization: a fast algorithm for training support vector machines”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Recent theory for coordinate descent:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;A. Beck and L. Tetruashvili (2013), “On the convergence of block coordinate descent type methods”&lt;/li&gt;
  &lt;li&gt;Y. Nesterov (2010), “Efficiency of coordinate descent methods on huge-scale optimization problems”&lt;/li&gt;
  &lt;li&gt;J. Nutini, M. Schmidt, I. Laradji, M. Friedlander, H. Koepke (2015), “Coordinate descent converges faster with the Gauss-Southwell rule than random selection”&lt;/li&gt;
  &lt;li&gt;A. Ramdas (2014), “Rows vs columns for linear systems of equations—randomized Kaczmarz or coordinate descent?”&lt;/li&gt;
  &lt;li&gt;P. Richtarik and M. Takac (2011), “Iteration complexity of randomized block-coordinate descent methods for minimizing a composite function”&lt;/li&gt;
  &lt;li&gt;A. Saha and A. Tewari (2013), “On the nonasymptotic convergence of cyclic coordinate descent methods”&lt;/li&gt;
  &lt;li&gt;S. Wright (2015), “Coordinate descent algorithms”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Screening rules and graphical lasso references:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;L. El Ghaoui and V. Viallon and T. Rabbani (2010), “Safe feature elimination in sparse supervised learning”&lt;/li&gt;
  &lt;li&gt;R. Tibshirani, J. Bien, J. Friedman, T. Hastie, N. Simon, J. Taylor, and R. J. Tibshirani (2011), “Strong rules for discarding predictors in lasso-type problems”&lt;/li&gt;
  &lt;li&gt;R. Mazumder and T. Hastie (2011), “The graphical lasso: new insights and alternatives”&lt;/li&gt;
  &lt;li&gt;R. Mazumder and T. Hastie (2011), “Exact covariance thresholding into connected components for large-scale graphical lasso”&lt;/li&gt;
  &lt;li&gt;J. Wang, P. Wonka, and J. Ye (2015), “Lasso screening rules via dual polytope projection”&lt;/li&gt;
  &lt;li&gt;D. Witten and J. Friedman and N. Simon (2011), “New insights and faster computations for the graphical lasso”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Convergence analysis:&lt;/strong&gt;&lt;br /&gt;
Here is a brief introduction to the research flow of coordinate descent convergence analysis.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Convergence of coordinate-wise minimization for solving linear systems, the Gauss-Seidel method, is a classic topic. E.g., see Golub and van Loan (1996), or Ramdas (2014) for a modern treatment that looks at randomized coordinate descent&lt;/li&gt;
  &lt;li&gt;Nesterov (2010) considers randomized coordinate descent for smooth functions and shows that it achieves a rate O(1/ε) under a Lipschitz gradient condition, and a rate O(log(1/ε)) under strong convexity&lt;/li&gt;
  &lt;li&gt;Richtarik and Takac (2011) extend and simplify these results, considering smooth plus separable functions, where now each coordinate descent update applies a prox operation&lt;/li&gt;
  &lt;li&gt;Saha and Tewari (2013) consider minimizing l1 regularized functions of the form g(β) + λ∥β∥1, for smooth g, and study both cyclic coordinate descent and cyclic coordinate-wise minimization. Under (very strange) conditions on g, they show both methods dominate proximal gradient descent in iteration progress&lt;/li&gt;
  &lt;li&gt;Beck and Tetruashvili (2013) study cyclic coordinate descent for smooth functions in general. They show that it achieves a rate O(1/ε) under a Lipschitz gradient condition, and a rate O(log(1/ε)) under strong convexity. They also extend these results to a constrained setting with projections&lt;/li&gt;
  &lt;li&gt;Nutini et al. (2015) analyze greedy coordinate descent (called Gauss-Southwell rule), and show it achieves a faster rate than randomized coordinate descent for certain problems&lt;/li&gt;
  &lt;li&gt;Wright (2015) provides some unification and a great summary. Also covers parallel versions (even asynchronous ones)&lt;/li&gt;
  &lt;li&gt;General theory is still not complete; still unanswered questions (e.g., are descent and minimization strategies the same?)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2026-applications-optional&quot;&gt;2026 applications (optional)&lt;/h2&gt;

&lt;p&gt;Pathwise CD is still how glmnet and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sklearn.linear_model.lasso_path&lt;/code&gt; fit sparse GLMs. The 2023 JSS paper extends glmnet to &lt;em&gt;every&lt;/em&gt; GLM family; skglm (NeurIPS 2022) adds working sets and nonconvex penalties at a million features; LIBLINEAR dual CD still trains linear SVMs. See &lt;a href=&quot;/contents/en/chapter23/23_05_modern_applications/&quot;&gt;23-05 Modern applications of coordinate descent&lt;/a&gt; after the Lasso / pathwise examples.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>23-04 Example - Pathwise coordinate descent for lasso</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_04_Example_pathwise_coordinate/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_04_Example_pathwise_coordinate</id>
   <content type="html">&lt;p&gt;Solving Lasso for a single, arbitrary regularization parameter \(\lambda\) is rarely what a data scientist actually wants—in cross-validation, you need solutions across an entire grid of 100 values \(\lambda_1 &amp;gt; \lambda_2 &amp;gt; \dots &amp;gt; \lambda_{100}\). Astonishingly, computing the &lt;em&gt;entire&lt;/em&gt; 100-point path via &lt;strong&gt;pathwise coordinate descent&lt;/strong&gt; (the engine inside Friedman, Hastie, and Tibshirani’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;) is often &lt;em&gt;faster&lt;/em&gt; than solving a single small-\(\lambda\) problem from scratch! Two engineering ideas make this magic happen: &lt;strong&gt;warm starts&lt;/strong&gt; from sparse neighboring solutions and &lt;strong&gt;active-set sweeps&lt;/strong&gt; that ignore zero variables until KKT verification.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-inside-the-glmnet-pathwise-engine&quot;&gt;Key ideas: Inside the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; Pathwise Engine&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Exact Threshold \(\lambda_{\max}\):&lt;/strong&gt; At \(\lambda_1 = |X^\top y|_\infty\), every coordinate satisfies $$&lt;/td&gt;
          &lt;td&gt;X_i^\top y&lt;/td&gt;
          &lt;td&gt;\le \lambda_1\(, so\)\hat{\beta}(\lambda_1) = 0$$ is immediately optimal. Starting here guarantees the path begins at maximum sparsity.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm Starts Along a Logarithmic Grid:&lt;/strong&gt; Decreasing \(\lambda_k\) on a log-spaced grid ensures that \(\hat{\beta}(\lambda_{k-1})\) is already very close to \(\hat{\beta}(\lambda_k)\), drastically cutting the number of iterations needed at each grid point—especially for small, ill-conditioned \(\lambda\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Active-Set Strategy:&lt;/strong&gt; Once a few variables become nonzero (the active set \(\mathcal{A} = \{j : \beta_j \ne 0\}\)), inner-loop coordinate descent iterates &lt;em&gt;only&lt;/em&gt; over \(\mathcal{A}\) until convergence. Because $$&lt;/td&gt;
          &lt;td&gt;\mathcal{A}&lt;/td&gt;
          &lt;td&gt;\ll p\(, each inner sweep costs\)O(n&lt;/td&gt;
          &lt;td&gt;\mathcal{A}&lt;/td&gt;
          &lt;td&gt;)\(instead of\)O(np)$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;KKT Verification Pass:&lt;/strong&gt; After the active set converges, a single full pass checks $$&lt;/td&gt;
          &lt;td&gt;X_j^\top r&lt;/td&gt;
          &lt;td&gt;\le \lambda_k\(for all inactive variables\)j \notin \mathcal{A}\(. If none violate KKT, the solution is globally optimal; otherwise, violators enter\)\mathcal{A}$$ and the inner loop repeats.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-tracing-a-3-step-warm-start-path&quot;&gt;Worked example: Tracing a 3-Step Warm-Start Path&lt;/h3&gt;

&lt;p&gt;Using \(X = \begin{pmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}\) and \(y = (3, 1, 2)^\top\), we have \(X^\top y = (4, 5)^\top\). Let us trace the path across \(\lambda_1 = 5\), \(\lambda_2 = 4\), and \(\lambda_3 = 3\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Grid point 1 (\(\lambda_1 = \|X^\top y\|_\infty = 5\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;At \(\beta = (0, 0)^\top\), $$&lt;/td&gt;
              &lt;td&gt;X_1^\top y&lt;/td&gt;
              &lt;td&gt;= 4 \le 5\(and\)&lt;/td&gt;
              &lt;td&gt;X_2^\top y&lt;/td&gt;
              &lt;td&gt;= 5 \le 5$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Optimal solution: \(\hat{\beta}(5) = (0, 0)^\top\), active set \(\mathcal{A} = \emptyset\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Grid point 2 (\(\lambda_2 = 4\)), warm-started from \(\hat{\beta}(5) = (0, 0)^\top\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;KKT scan at \(r = y = (3, 1, 2)^\top\): $$&lt;/td&gt;
              &lt;td&gt;X_1^\top r&lt;/td&gt;
              &lt;td&gt;= 4 \le 4\((passes),\)&lt;/td&gt;
              &lt;td&gt;X_2^\top r&lt;/td&gt;
              &lt;td&gt;= 5 &amp;gt; 4$$ (violates!).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Enter coordinate 2 into active set: \(\mathcal{A} = \{2\}\).&lt;/li&gt;
      &lt;li&gt;Active-set update on \(\beta_2\): \(\beta_2 = \frac{S_4(5)}{2} = 0.5\). Updated residual: \(r = (3, 1, 2)^\top - 0.5(1, 0, 1)^\top = (2.5, 1, 1.5)^\top\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;KKT check on inactive coordinate 1: $$&lt;/td&gt;
              &lt;td&gt;X_1^\top r&lt;/td&gt;
              &lt;td&gt;=&lt;/td&gt;
              &lt;td&gt;2.5 + 1&lt;/td&gt;
              &lt;td&gt;= 3.5 \le 4$$ (passes!).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Optimal solution: \(\hat{\beta}(4) = (0, 0.5)^\top\) in just &lt;strong&gt;1 coordinate update&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Grid point 3 (\(\lambda_3 = 3\)), warm-started from \(\hat{\beta}(4) = (0, 0.5)^\top\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;KKT scan on \(r = (2.5, 1, 1.5)^\top\): \(X_1^\top r = 3.5 &amp;gt; 3\) (violates!) and \(X_2^\top r = 4 &amp;gt; 3\) (already in \(\mathcal{A}\)).&lt;/li&gt;
      &lt;li&gt;Expand \(\mathcal{A} = \{1, 2\}\) and run active-set CD from \((0, 0.5)^\top\):
        &lt;ul&gt;
          &lt;li&gt;\(\beta_1 = \frac{S_3(3.5)}{2} = 0.25\), \(r \leftarrow (2.25, 0.75, 1.5)^\top\).&lt;/li&gt;
          &lt;li&gt;\(\beta_2 = \frac{S_3(X_2^\top(r + 0.5 X_2))}{2} = \frac{S_3(2.25 + 1.5 + 1.0)}{2} = \frac{S_3(4.75)}{2} = 0.875\), \(r \leftarrow (1.875, 0.75, 1.125)^\top\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Notice how coordinate 1 stayed completely out of the computation until \(\lambda\) actually dropped below \(3.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we will briefly introduce the overview of pathwise coordinate descent for lasso [&lt;a href=&quot;https://arxiv.org/pdf/0708.1485.pdf&quot;&gt;Friedman et al. (2007)&lt;/a&gt;] [&lt;a href=&quot;https://www.jstatsoft.org/article/view/v033i01/v33i01.pdf&quot;&gt;Friedman et al. (2009)&lt;/a&gt;].&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Lasso regression problem:&lt;/strong&gt;&lt;/p&gt;

\[\min_{\beta} \frac{1}{2} \| y - X\beta \|_2^2 + \lambda \|\beta\|_1\]
&lt;/blockquote&gt;

&lt;p&gt;In &lt;a href=&quot;/contents/en/chapter07/07_03_03_example_lasso_optimality_condition/&quot;&gt;07-03-03 Example: Lasso Optimality Condition&lt;/a&gt;, we saw the derivation of the optimality condition for the lasso regression problem. The optimal solution for the above problem satisfies the following condition.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
X_1^T(y-X\beta) &amp;amp;= \lambda v_1\\
X_2^T(y-X\beta) &amp;amp;= \lambda v_2\\
\dots\\
X_p^T(y-X\beta) &amp;amp;= \lambda v_p
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; \(X_i, i \in \{1,2,…,p\}\) means the \(i\)-th column data of the given matrix \(X\). Here, \(v=(v_1,v_2,\dots,v_p)\) is the subgradient of \(\beta=(\beta_1,\beta_2,\dots,\beta_p)\).&lt;/p&gt;

\[v_i, i \in \{1,2,\dots,p \} = \begin{cases}
\{ 1 \} &amp;amp;\text{if $\beta_i &amp;gt; 0$} \\
\{-1 \} &amp;amp;\text{if $\beta_i &amp;lt; 0$} \\
[-1,1] &amp;amp;\text{if $\beta_i = 0$}
\end{cases}\]

&lt;p&gt;Using the optimality condition, we can determine whether each element of \(\beta\) corresponds to the current optimal state. Using the coordinate descent algorithm, we can solve the lasso problem more efficiently by updating only the elements that have not yet reached the optimal state.&lt;/p&gt;

&lt;p&gt;Also, the larger the value of \(\lambda\), the faster the coordinate descent algorithm tends to work in lasso regression problems. By utilizing this tendency and gradually reducing \(\lambda\) (warm start), we can approach the solution more quickly.&lt;/p&gt;

&lt;h2 id=&quot;algorithm&quot;&gt;Algorithm&lt;/h2&gt;

&lt;h3 id=&quot;outer-loop-pathwise-strategy&quot;&gt;Outer loop (pathwise strategy):&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Compute optimal solutions in the order \(\lambda_1 &amp;gt; \lambda_2 &amp;gt; \dots &amp;gt; \lambda_r\).&lt;/li&gt;
  &lt;li&gt;Use the result computed at tuning parameter \(\lambda_k\) to initialize the coordinate descent algorithm for \(\lambda_{k+1}\). (warm start)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;inner-loop-active-set-strategy&quot;&gt;Inner loop (active set strategy):&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Perform one or a few coordinate cycles. Record the non-zero elements of \(\beta\) in the active set \(A\).&lt;/li&gt;
  &lt;li&gt;Perform coordinate cycles on the elements recorded in \(A\) until convergence.&lt;/li&gt;
  &lt;li&gt;Check the optimality condition for all elements of \(\beta\). If there are elements that do not satisfy the condition, add them to \(A\) and return to step 1.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;notes&quot;&gt;Notes&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Generally, the pathwise strategy works much more efficiently than directly finding the solution for a given \(\lambda\) in the problem.&lt;/li&gt;
  &lt;li&gt;The active set strategy takes advantage of sparsity. Because of this, coordinate descent works much faster in lasso regression than ridge regression.&lt;/li&gt;
  &lt;li&gt;Pathwise coordinate descent for lasso works as fast as the fastest and most sophisticated algorithms for lasso regression problems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Reference:&lt;/strong&gt; &lt;a href=&quot;https://www.analyticsvidhya.com/blog/2016/01/complete-tutorial-ridge-lasso-regression-python/&quot;&gt;Analysis of ridge regression and lasso regression tendencies&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>23-03 Example - lasso regression</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_03_Example_lasso_regression/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_03_Example_lasso_regression</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;When Robert Tibshirani introduced the Lasso in 1996, it was initially solved with generic quadratic programming—painfully slow once \(p\) grew beyond a few hundred features. Everything changed when statisticians realized that the \(\ell_1\) penalty $$\lambda |\beta|&lt;em&gt;1 = \lambda \sum&lt;/em&gt;{i=1}^p&lt;/td&gt;
      &lt;td&gt;\beta_i&lt;/td&gt;
      &lt;td&gt;$$ is &lt;em&gt;perfectly separable&lt;/em&gt; across coordinates. That single property turns every 1D coordinate subproblem into a closed-form soft-thresholding formula, allowing Coordinate Descent to solve Lasso problems with tens of thousands of predictors in milliseconds.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;key-ideas-soft-thresholding-and-coordinate-descent-for-lasso&quot;&gt;Key ideas: Soft-Thresholding and Coordinate Descent for Lasso&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Separable Composite Structure:&lt;/strong&gt; The Lasso objective $$\frac{1}{2}|y - X\beta|&lt;em&gt;2^2 + \lambda \sum&lt;/em&gt;{i=1}^p&lt;/td&gt;
          &lt;td&gt;\beta_i&lt;/td&gt;
          &lt;td&gt;\(satisfies Tseng’s theorem exactly: the smooth data-fidelity term is convex and differentiable, and the nonsmooth\)\ell_1$$ norm splits cleanly by coordinate.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;1D Subgradient Optimality &amp;amp; Soft-Thresholding:&lt;/strong&gt; Setting $$0 \in -X_i^\top(r^{(-i)} - X_i \beta_i) + \lambda \partial&lt;/td&gt;
          &lt;td&gt;\beta_i&lt;/td&gt;
          &lt;td&gt;\(yields the exact closed-form update\)\beta_i^+ = \frac{S_\lambda(X_i^\top r^{(-i)})}{|X_i|&lt;em&gt;2^2}\(, where\)S&lt;/em&gt;\lambda(z) = \operatorname{sign}(z)\max(&lt;/td&gt;
          &lt;td&gt;z&lt;/td&gt;
          &lt;td&gt;- \lambda, 0)$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Automatic Zero-Locking (Sparsity):&lt;/strong&gt; Whenever the correlation $$&lt;/td&gt;
          &lt;td&gt;X_i^\top r^{(-i)}&lt;/td&gt;
          &lt;td&gt;\le \lambda\(, soft-thresholding snaps\)\beta_i^+\(to *exact* zero—requiring no residual update (\)0$$ flops!) and accelerating sweeps dramatically once most features drop out.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Empirical Dominance Over Proximal Gradient:&lt;/strong&gt; Just as in OLS, one CD sweep matches one Proximal Gradient (ISTA/FISTA) step in \(O(np)\) cost, yet CD’s Gauss–Seidel updates and per-coordinate scaling typically converge in a fraction of the iterations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-coordinate-descent-cycle-on-a-2-feature-lasso&quot;&gt;Worked example: One Coordinate Descent Cycle on a 2-Feature Lasso&lt;/h3&gt;

&lt;p&gt;Use the same design matrix \(X = \begin{pmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}\) (\(\|X_1\|_2^2 = \|X_2\|_2^2 = 2\)) and response \(y = (3, 1, 2)^\top\), now with Lasso penalty \(\lambda = 2\), starting at \(\beta^{(0)} = (0, 0)^\top\) and \(r = (3, 1, 2)^\top\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Update \(\beta_1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Correlation with partial residual: \(c_1 = X_1^\top r^{(-1)} = 1(3) + 1(1) + 0(2) = 4\).&lt;/li&gt;
      &lt;li&gt;Soft-threshold by \(\lambda = 2\): \(S_2(4) = \operatorname{sign}(4)\max(4 - 2, 0) = 2\).&lt;/li&gt;
      &lt;li&gt;Divide by \(\|X_1\|_2^2 = 2\): \(\beta_1^{(1)} = \frac{2}{2} = 1\).&lt;/li&gt;
      &lt;li&gt;Refresh residual: \(r \leftarrow (3, 1, 2)^\top - 1(1, 1, 0)^\top = (2, 0, 2)^\top\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update \(\beta_2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Correlation with partial residual: \(c_2 = X_2^\top r^{(-2)} = 1(2) + 0(0) + 1(2) = 4\).&lt;/li&gt;
      &lt;li&gt;Soft-threshold by \(\lambda = 2\): \(S_2(4) = 2\).&lt;/li&gt;
      &lt;li&gt;Divide by \(\|X_2\|_2^2 = 2\): \(\beta_2^{(1)} = \frac{2}{2} = 1\).&lt;/li&gt;
      &lt;li&gt;Refresh residual: \(r \leftarrow (2, 0, 2)^\top - 1(1, 0, 1)^\top = (1, 0, 1)^\top\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check KKT optimality at \(\beta^{(1)} = (1, 1)^\top\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(X_1^\top r = 1(1) + 1(0) + 0(1) = 1\). Wait—for \(\beta_1 = 1 &amp;gt; 0\), KKT requires \(X_1^\top r = \lambda = 2\)! Since \(1 &amp;lt; 2\), \(\beta_1\) will shrink on Cycle 2.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Cycle 2, coordinate 1:&lt;/strong&gt; \(r^{(-1)} = r + 1\cdot X_1 = (2, 1, 1)^\top\), so \(c_1 = X_1^\top r^{(-1)} = 3\), giving \(\beta_1^{(2)} = \frac{S_2(3)}{2} = 0.5\) and \(r \leftarrow (1.5, 0.5, 1)^\top\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Cycle 2, coordinate 2:&lt;/strong&gt; \(r^{(-2)} = r + 1\cdot X_2 = (2.5, 0.5, 2)^\top\), so \(c_2 = X_2^\top r^{(-2)} = 4.5\), giving \(\beta_2^{(2)} = \frac{S_2(4.5)}{2} = 1.25\) and \(r \leftarrow (1.25, 0.5, 0.75)^\top\).
Notice how the Lasso penalty shrinks the weaker feature \(\beta_1\) while preserving the stronger signal \(\beta_2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s examine the lasso regression problem, which has the form of an objective function with separated smooth and nonsmooth parts as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{\beta} \frac{1}{2} \| y - X\beta \|_2^2 + \lambda \|\beta\|_1\]
&lt;/blockquote&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Note:&lt;/strong&gt; $$|\beta|&lt;em&gt;1 = \sum&lt;/em&gt;{i=1}^p&lt;/td&gt;
      &lt;td&gt;\beta_i&lt;/td&gt;
      &lt;td&gt;$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;When \(\beta_j, j \neq i\) are fixed values, let’s find \(\beta_i\) that minimizes the given objective function.&lt;/p&gt;

\[\begin{align}
&amp;amp;0 = \nabla_i f(\beta) = X_i^T X_i \beta_i + X_i^T(X_{-i} \beta_{-i} - y) + \lambda s_i,\\\\
&amp;amp;\text{where } s_i \in \partial |\beta_i| \Rightarrow \beta_i = S_{\lambda / \|X_i\|_2^2} \big( \frac{X_i^T(y-X_{-i} \beta_{-i})}{X_i^TX_i} \big)
\end{align}\]

&lt;p&gt;The solution equals a soft-thresholding function with thresholding level \(\lambda / \|X_i\|_2^2\).&lt;/p&gt;

&lt;p&gt;Through coordinate descent, we iteratively update \(\beta_i\) for \(i=1,2,\dots,p,1,2,\dots\).&lt;/p&gt;

&lt;h2 id=&quot;experiment-convergence-speed-comparison---pg-vs-agd-vs-cd&quot;&gt;Experiment: convergence speed comparison - PG vs AGD vs CD&lt;/h2&gt;

&lt;p&gt;The graph below shows a comparison of convergence speeds for proximal gradient descent, accelerated gradient descent, and coordinate descent on a lasso regression problem with \(n=100, p=20\). (The x-axis indicates one step (PD, AGD) or one cycle (CD).)&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter23/pd_vs_agd_vs_cd.png&quot; alt=&quot;[Fig1] PD vs AGD vs CD [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] PD vs AGD vs CD [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;As in the &lt;a href=&quot;/contents/en/chapter23/23_02_Example_linear_regression/&quot;&gt;linear regression case&lt;/a&gt;, coordinate descent shows superior convergence speed in the lasso regression problem. (It utilizes more information than first-order methods.)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Note:&lt;/strong&gt; In the above experiment, all methods show \(O(np)\) flops time complexity per iteration.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>23-02 Example: linear regression</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_02_Example_linear_regression/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_02_Example_linear_regression</id>
   <content type="html">&lt;p&gt;Linear regression \(\min_\beta \frac{1}{2}\|y - X\beta\|_2^2\) is the cleanest laboratory in optimization: every coordinate subproblem is a 1D parabola whose exact minimizer is a single inner product. Comparing full Gradient Descent, Nesterov Accelerated Gradient, and Coordinate Descent on this problem reveals a counterintuitive computational truth: one full cycle of \(p\) coordinate updates costs \(O(np)\)—the &lt;em&gt;exact same&lt;/em&gt; floating-point budget as one full gradient step—yet converges dramatically faster because each coordinate immediately benefits from the updated residual and its own local curvature \(\|X_i\|_2^2\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-coordinate-descent-mechanics-for-ordinary-least-squares&quot;&gt;Key ideas: Coordinate Descent Mechanics for Ordinary Least Squares&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Partial Residual Formulation:&lt;/strong&gt; Fixing all coordinates except \(\beta_i\), the residual splits as \(y - X\beta = r^{(-i)} - X_i \beta_i\) where \(r^{(-i)} = y - \sum_{j \ne i} X_j \beta_j\). Minimizing \(\frac{1}{2}\|r^{(-i)} - X_i \beta_i\|_2^2\) gives the exact projection \(\beta_i^+ = \frac{X_i^\top r^{(-i)}}{\|X_i\|_2^2}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact \(O(n)\) Residual Refresh:&lt;/strong&gt; Never recompute \(X\beta\) from scratch inside the inner loop (which would cost \(O(np)\) per coordinate and \(O(np^2)\) per cycle). Maintain \(r = y - X\beta\) and update \(r \leftarrow r - (\beta_i^+ - \beta_i) X_i\) in \(O(n)\) operations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why CD Beats GD Per-Flop:&lt;/strong&gt; Gradient descent must use a single global step size \(\eta \le 1 / \lambda_{\max}(X^\top X)\) dictated by the steepest coupled direction. Coordinate descent implicitly uses diagonal preconditioning \(1 / \|X_i\|_2^2\) plus immediate Gauss–Seidel feedback.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fair Benchmarking Criterion:&lt;/strong&gt; Comparing 1 cycle of CD (\(p\) coordinate updates) against 1 step of GD or AGD is strictly fair in operation count because both touch every entry of \(X \in \mathbb{R}^{n \times p}\) exactly once (\(O(np)\) flops).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-exact-cd-cycle-vs-one-gd-step-on-ols&quot;&gt;Worked example: One Exact CD Cycle vs. One GD Step on OLS&lt;/h3&gt;

&lt;p&gt;Let \(X = \begin{pmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}\) (so \(X_1 = (1,1,0)^\top\), \(X_2 = (1,0,1)^\top\), \(\|X_1\|_2^2 = \|X_2\|_2^2 = 2\)) and \(y = (3, 1, 2)^\top\). Note that the exact solution is \(\beta^\star = (1, 2)^\top\) since \(X\beta^\star = (3, 1, 2)^\top = y\). Start at \(\beta^{(0)} = (0, 0)^\top\) with residual \(r = y = (3, 1, 2)^\top\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate 1 update:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Partial residual \(r^{(-1)} = r + \beta_1^{(0)} X_1 = (3, 1, 2)^\top\).&lt;/li&gt;
      &lt;li&gt;\(\beta_1^{(1)} = \frac{X_1^\top r^{(-1)}}{\|X_1\|_2^2} = \frac{1(3) + 1(1) + 0(2)}{2} = \frac{4}{2} = 2\).&lt;/li&gt;
      &lt;li&gt;Refresh residual: \(r \leftarrow (3, 1, 2)^\top - 2(1, 1, 0)^\top = (1, -1, 2)^\top\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate 2 update (using the refreshed residual!):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Partial residual \(r^{(-2)} = r + \beta_2^{(0)} X_2 = (1, -1, 2)^\top\).&lt;/li&gt;
      &lt;li&gt;\(\beta_2^{(1)} = \frac{X_2^\top r^{(-2)}}{\|X_2\|_2^2} = \frac{1(1) + 0(-1) + 1(2)}{2} = \frac{3}{2} = 1.5\).&lt;/li&gt;
      &lt;li&gt;Refresh residual: \(r \leftarrow (1, -1, 2)^\top - 1.5(1, 0, 1)^\top = (-0.5, -1, 0.5)^\top\).&lt;/li&gt;
      &lt;li&gt;Loss after 1 CD cycle: \(\frac{1}{2}\|r\|_2^2 = \frac{1}{2}(0.25 + 1 + 0.25) = 0.75\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with 1 Gradient Descent step:&lt;/strong&gt; Here \(X^\top X = \begin{pmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{pmatrix}\) has \(L = \lambda_{\max} = 3\), so the optimal safe GD step is \(\eta = 1/3\).
    &lt;ul&gt;
      &lt;li&gt;Gradient at \(0\): \(-X^\top y = -(4, 5)^\top\).&lt;/li&gt;
      &lt;li&gt;\(\beta_{\text{GD}}^{(1)} = \frac{1}{3}(4, 5)^\top = (1.333, 1.667)^\top\), residual \(y - X\beta_{\text{GD}}^{(1)} = (0, -0.333, 0.333)^\top\), loss \(= 0.111\).
Now imagine rescaling column 1 by \(10\): \(L\) explodes by \(100\times\), forcing GD to crawl at \(\eta \approx 1/200\) along column 2, while CD’s coordinate-wise division by \(\|X_i\|_2^2\) remains completely unaffected!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s define the linear regression problem as follows.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\min_{\beta} \frac{1}{2} \| y - X\beta \|_2^2,\)
\(\text{given } y \in \mathbb{R}^n \text{ and } X \in \mathbb{R}^{n \times p} \text{ with columns } X_1, \dots, X_p.\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When \(\beta_j,\: j \neq i\) are fixed values, let’s find \(\beta_i\) that minimizes the given objective function.
(\(-i\) means the remaining terms excluding \(i\). - In the case of \(X\), the remaining columns excluding the \(i\)-th column.)&lt;/p&gt;

\[\begin{align}
0 &amp;amp;= \nabla_i f(\beta)\\\\
&amp;amp;= X_i^T (X\beta - y)\\\\
&amp;amp;= X_i^T (X_i \beta_i + X_{-i} \beta_{-i} - y)\\\\
\Rightarrow\\\\
&amp;amp;\beta_i = \frac{X_i^T (y - X_{-i} \beta_{-i})}{X_i^T X_i}
\end{align}\]

&lt;p&gt;Through coordinate descent, we iterate and update \(\beta_i\) for \(i=1,2,\dots,p,1,2,\dots\).&lt;/p&gt;

&lt;h2 id=&quot;experiment-convergence-speed-comparison---gd-vs-agd-vs-cd&quot;&gt;Experiment: Convergence speed comparison - GD vs AGD vs CD&lt;/h2&gt;

&lt;p&gt;The graph below shows the convergence speeds of coordinate descent, gradient descent, and accelerated gradient descent for a linear regression problem with \(n=100, p=20\). (The k on the horizontal axis represents one step (GD, AGD) or one cycle (CD).)&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter23/gd_vs_agd_vs_cd.png&quot; alt=&quot;[Fig1] GD vs AGD vs CD [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] GD vs AGD vs CD [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;According to the above results, coordinate descent shows significantly better convergence speed than AGD, which is optimal among first-order methods. Why can this phenomenon occur? To conclude, coordinate descent can achieve performance that far surpasses AGD because it utilizes more information than first-order methods. This is because coordinate descent uses the latest information updated in the previous step at each step within one cycle. (That is, CD is not a first-order method.)&lt;/p&gt;

&lt;h3 id=&quot;q-then-is-it-fair-to-compare-one-cycle-of-cd-with-one-step-of-gd-in-the-above-experiment&quot;&gt;Q. Then, is it fair to compare one cycle of CD with one step of GD in the above experiment?&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A. Yes.&lt;/strong&gt; The CD update formula introduced earlier can be modified to have a time complexity of \(O(n)\) per step. Then, the time complexity of one cycle for CD becomes \(O(np)\), which has the same time complexity as one step of GD.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient descent update:&lt;/strong&gt; \(\beta \leftarrow \beta + tX^T(y-X\beta)\), the time complexity of the \(X\beta\) operation becomes \(O(np)\) flops.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;coordinate-descent-one-coordinate-at-a-time-video&quot;&gt;Coordinate descent: one coordinate at a time (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/coordinate-descent_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Coordinate descent minimises exactly along one coordinate at a time, drawing a staircase path; correlated coordinates make the stairs small.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-coordinate-descent-vs-gradient-descent&quot;&gt;Try it yourself: coordinate descent vs gradient descent&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;cd&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>23-01 Coordinate Descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_01_Coordinate_descent/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter23/23_01_Coordinate_descent</id>
   <content type="html">&lt;p&gt;Can a function be strictly decreasing along no coordinate axis and yet still &lt;em&gt;not&lt;/em&gt; be at a minimum? That subtle question is the entire theoretical heart of Coordinate Descent. For smooth convex functions, vanishing partial derivatives along every axis guarantee global optimality. The moment we add a nonsmooth term, however, geometry fights back: if a nonsmooth ridge runs diagonally across the coordinate axes, coordinate-wise minimization can freeze completely at a non-optimal point. Understanding exactly when coordinate descent succeeds—and when it fails—is essential before deploying it on Lasso or sparse models.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-optimality-conditions-and-separability-in-coordinate-descent&quot;&gt;Key ideas: Optimality Conditions and Separability in Coordinate Descent&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate-Wise Optimality for Smooth Convex Functions:&lt;/strong&gt; If \(f\) is convex and differentiable, \(\nabla_i f(x) = 0\) for all \(i = 1, \dots, n\) implies \(\nabla f(x) = 0\), so coordinate-wise stationarity is equivalent to global optimality.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Failure on Non-Separable Nonsmooth Functions:&lt;/strong&gt; When a nonsmooth term couples coordinates (such as $$&lt;/td&gt;
          &lt;td&gt;x_1 - x_2&lt;/td&gt;
          &lt;td&gt;$$), the subdifferential does not factor into a Cartesian product, allowing a point to sit at the bottom of every axis-aligned slice while a diagonal descent direction still exists.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tseng’s Convergence Theorem (2001):&lt;/strong&gt; For \(f(x) = g(x) + \sum_{i=1}^n h_i(x_i)\) with \(g\) convex differentiable and each \(h_i\) convex (possibly nonsmooth), cyclic coordinate descent converges to a global minimum because the nonsmooth kinks are aligned strictly with the coordinate axes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Block Coordinate Descent (BCD):&lt;/strong&gt; Generalizing single scalars \(x_i\) to non-overlapping variable blocks \(x_{B_j}\) preserves Tseng’s guarantee whenever the nonsmooth regularizer is block-separable (e.g., Group Lasso \(\sum_g \|x_g\|_2\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-a-counterexample-where-coordinate-descent-gets-stuck&quot;&gt;Worked example: A Counterexample Where Coordinate Descent Gets Stuck&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider the convex, non-separable function $$f(x_1, x_2) = (x_1 + x_2)^2 + 2&lt;/td&gt;
      &lt;td&gt;x_1 - x_2&lt;/td&gt;
      &lt;td&gt;- 4(x_1 + x_2)\(at the point\)x = (0, 0)^\top\((wait—let us check an even cleaner textbook point:\)f(x_1, x_2) = -x_1 - x_2 + 2&lt;/td&gt;
      &lt;td&gt;x_1 - x_2&lt;/td&gt;
      &lt;td&gt;\(on\)[-1, 1]^2\(, or unconstrained\)f(x_1, x_2) = (x_1 + x_2 - 2)^2 + 4&lt;/td&gt;
      &lt;td&gt;x_1 - x_2&lt;/td&gt;
      &lt;td&gt;\(at\)x = (0, 0)^\top\(). Let us test\)f(x_1, x_2) = (x_1 + x_2 - 2)^2 + 5&lt;/td&gt;
      &lt;td&gt;x_1 - x_2&lt;/td&gt;
      &lt;td&gt;\(at\)x^{(0)} = (0, 0)^\top$$!&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate at \(x^{(0)} = (0, 0)^\top\):&lt;/strong&gt; \(f(0, 0) = (-2)^2 + 0 = 4\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize along \(x_1\) holding \(x_2 = 0\) fixed:&lt;/strong&gt;
\(\phi_1(x_1) = (x_1 - 2)^2 + 5|x_1|.\)
    &lt;ul&gt;
      &lt;li&gt;For \(x_1 &amp;gt; 0\): \(\phi_1&apos;(x_1) = 2(x_1 - 2) + 5 = 2x_1 + 1 &amp;gt; 0\) (strictly increasing!).&lt;/li&gt;
      &lt;li&gt;For \(x_1 &amp;lt; 0\): \(\phi_1&apos;(x_1) = 2(x_1 - 2) - 5 = 2x_1 - 9 &amp;lt; 0\) (strictly decreasing!).
Hence \(x_1 = 0\) is the &lt;strong&gt;unique&lt;/strong&gt; global minimizer along the \(x_1\)-axis!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Minimize along \(x_2\) holding \(x_1 = 0\) fixed:&lt;/strong&gt; By symmetry, $$\phi_2(x_2) = (x_2 - 2)^2 + 5&lt;/td&gt;
          &lt;td&gt;x_2&lt;/td&gt;
          &lt;td&gt;\(is also uniquely minimized at\)x_2 = 0\(. Coordinate descent terminates at\)(0, 0)^\top\(with\)f(0, 0) = 4$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Move diagonally along \(x_1 = x_2 = t\):&lt;/strong&gt;
\(f(t, t) = (2t - 2)^2 + 5|0| = 4(t - 1)^2,\)
which achieves \(f(1, 1) = 0 &amp;lt; 4\)! Because \(|x_1 - x_2|\) is &lt;strong&gt;not separable&lt;/strong&gt;, coordinate descent stalls permanently at a suboptimal point—illustrating exactly why separability in Tseng’s theorem is indispensable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we introduce a method called coordinate descent that is extremely simple, efficient, and highly scalable. First, let’s start with some simple questions and answers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q1. When function \(f: \mathbb{R}^n \rightarrow \mathbb{R}\) is convex and differentiable, if the point where \(f\) is minimized along each coordinate axis is \(x\), is this \(x\) a global minimizer?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A1: Yes. Since \(\nabla f(x) = 0\), \(x\) is a global minimizer of \(f\).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The above question is equivalent to asking whether \(f(x + \delta e_i) \ge f(x)\) is satisfied for all \(\delta, i\) when \(e_i = (0, \dots, 1, \dots, 0) \in \mathbb{R}^n\) is the \(i\)-th standard basis vector. That is, since we cannot make \(f\) smaller by moving in any coordinate axis direction from \(x\), the partial derivatives in all axis directions become 0.&lt;/p&gt;

\[\nabla f(x) = \big( \frac{\partial f}{\partial x_1}(x), \dots, \frac{\partial f}{\partial x_n}(x) \big) = (0, \dots, 0) = 0\]

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter23/smooth_function.png&quot; alt=&quot;[Fig1] Smooth convex function f [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$[Fig1] \; Smooth \; convex \; function \; f \; [3]$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q2. Then, when \(f: \mathbb{R}^n \rightarrow \mathbb{R}\) is convex but ‘non-differentiable’ function, is the point \(x\) where \(f\) is minimized along each coordinate axis always a global minimizer?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A2: No. In this case, we cannot assert that \(x\) is a global minimizer of \(f\). (Counterexample: Fig2 below)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Looking at the contour lines on the right side of the counterexample below, we can see that although the marked point is not the global minimum, \(f\) cannot be made smaller by moving in any coordinate axis direction. (To make \(f\) smaller, one must be able to move inside the contour lines.) This is because at this position, all inner regions of the contour lines are contained within the two tangent lines parallel to the coordinate axes. On the other hand, when \(f\) is a differentiable convex function, only one tangent line exists at any point on the contour lines, so this phenomenon does not occur.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter23/non-smooth_function.png&quot; alt=&quot;[Fig2] Counterexample: Non-smooth convex function f [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$[Fig2] \; Counterexample: Non \, smooth \; convex \; function \; f \; [3]$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q3. When \(f\) can be expressed as the sum of a differentiable convex function \(g\) and a convex function \(h\), is the point \(x\) where \(f\) is minimized along each coordinate axis always a global minimizer? (That is, \(f(x) = g(x) + \sum_{i=1}^{n} h_i(x_i)\))&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A3. Yes. This is because it satisfies the following for any \(y\).&lt;/strong&gt;
\(\begin{align}
f(y) - f(x) &amp;amp;\ge \nabla g(x)^T (y-x) + \sum_{i=1}^{n} \big[ h_i(y_i) - h_i(x_i) \big] \\\\
&amp;amp;= \sum_{i=1}^{n} \big[ \underbrace{\nabla_i g(x) (y_i - x_i) + h_i(y_i) - h_i(x_i)}_{\ge 0} \big] \ge 0
\end{align}\)&lt;/p&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Let \(F_i(x_i) = g(x_i ; x_{-i}) + h_i(x_i)\). (\(g(x_i ; x_{-i})\) means viewing only the \(i\)-th element of \(x\) as a variable, and the rest as fixed values.)&lt;/p&gt;

\[\begin{align}
&amp;amp; \: 0 \in \partial F_i (x_i) \\\\
\Leftrightarrow &amp;amp; \: 0 \in \{ \nabla_i g(x) \} + \partial h_i(x_i)\\\\
\Leftrightarrow &amp;amp; \: - \nabla_i g(x) \in \partial h_i(x\_i)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;By the &lt;a href=&quot;/contents/en/chapter07/07_01_subgradient/&quot;&gt;definition of subgradient&lt;/a&gt;,&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; h_i(y_i) \ge h_i(x_i) - \nabla_i g(x) (y_i - x_i)\\\\
\Leftrightarrow &amp;amp; \nabla_i g(x) (y_i - x_i) + h_i(y_i) - h_i(x_i) \ge 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter23/separable_non-smooth.png&quot; alt=&quot;[Fig3] Convex function f with separable non-smooth parts [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$[Fig3] \; Convex \; function \; f \; with \; separable \; non \,smooth \; parts \; [3]$$ &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;The minimizer of \(f(x) = g(x) + \sum_{i=1}^{n} h_i(x_i)\) with \(g\) convex, differentiable and \(h_i\) convex can be found using &lt;strong&gt;coordinate descent&lt;/strong&gt;. Coordinate descent iterates the following cycle. (Assume that an appropriate initial value \(x^{(0)}\) is set.)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Coordinate Descent:&lt;/strong&gt; &lt;br /&gt;
\(\:\) For \(k = 1,2,3,\dots\),&lt;/p&gt;

\[\begin{align}
x_1^{(k)} &amp;amp;\in \text{arg}\min_{x_1} \: f(x_1, x_2^{(k-1)}, x_3^{(k-1)}, \dots, x_n^{(k-1)})\\\\
x_2^{(k)} &amp;amp;\in \text{arg}\min_{x_2} \: f(x_1^{(k)}, x_2, x_3^{(k-1)}, \dots, x_n^{(k-1)})\\\\
x_3^{(k)} &amp;amp;\in \text{arg}\min_{x_3} \: f(x_1^{(k)}, x_2^{(k)}, x_3, \dots, x_n^{(k-1)})\\\\
&amp;amp; \dots\\\\
x_n^{(k)} &amp;amp;\in \text{arg}\min_{x_n} \: f(x_1^{(k)}, x_2^{(k)}, x_3^{(k)}, \dots, x_n)
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;notes&quot;&gt;Notes:&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;The process of obtaining \(x_{i+1}^{(k)}, \dots, x_{n}^{(k)}\) uses the newly obtained \(x_i^{(k)}\) in the \(k\)-th cycle.&lt;/li&gt;
  &lt;li&gt;The order of coordinate axes in the cycle can be arbitrarily specified.&lt;/li&gt;
  &lt;li&gt;Two or more coordinate axes can be grouped together and processed as blocks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The coordinate descent introduced above corresponds to exact coordinatewise minimization. Another approach is inexact coordinatewise minimization using gradients. (Assuming \(f\) is a differentiable convex function)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Coordinate Descent (inexact coordinatewise minimization):&lt;/strong&gt; &lt;br /&gt;
\(\:\) For \(k = 1,2,3,\dots\),&lt;/p&gt;

\[\begin{align}
x_1^{(k)} &amp;amp;= x_1^{(k-1)} - t_{k,1} \cdot \nabla_1 f(x_1^{(k-1)}, x_2^{(k-1)}, x_3^{(k-1)}, \dots, x_n^{(k-1)})\\\\
x_2^{(k)} &amp;amp;= x_2^{(k-1)} - t_{k,2} \cdot \nabla_2 f(x_1^{(k)}, x_2^{(k-1)}, x_3^{(k-1)}, \dots, x_n^{(k-1)})\\\\
x_3^{(k)} &amp;amp;= x_3^{(k-1)} - t_{k,3} \cdot \nabla_3 f(x_1^{(k)}, x_2^{(k)}, x_3^{(k-1)}, \dots, x_n^{(k-1)})\\\\
&amp;amp; \dots\\\\
x_n^{(k)} &amp;amp;= x_n^{(k-1)} - t_{k,n} \cdot \nabla_n f(x_1^{(k)}, x_2^{(k)}, x_3^{(k)}, \dots, x_n^{(k-1)})
\end{align}\]
&lt;/blockquote&gt;

</content>
 </entry>
 
 <entry>
   <title>22 Conditional Gradient (Frank-Wolfe) Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_Conditional_Gradient_Method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_Conditional_Gradient_Method</id>
   <content type="html">&lt;p&gt;Picture a 1956 operations research room long before GPUs or automatic differentiation: Marguerite Frank and Philip Wolfe are trying to minimize a smooth quadratic objective over a high-dimensional polytope where computing a Euclidean projection at every step is prohibitively expensive, yet solving a single linear program over that same polytope is routine. Their radical insight was to abandon projection altogether—instead of stepping outside the feasible set and pulling back, simply ask a linear oracle which extreme point points most sharply downhill, and slide a fraction of the way toward that corner. Nearly seventy years later, that exact projection-free idea powers sparse regression, low-rank matrix completion, and structured prediction at scales where Euclidean projection would collapse.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-architecture-of-the-conditional-gradient-method&quot;&gt;Key ideas: Architecture of the Conditional Gradient Method&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Linear Minimization Oracles (LMO) vs. Projection Oracles:&lt;/strong&gt; Projected gradient descent requires solving a quadratic subproblem at every iteration to snap back onto \(C\). Frank–Wolfe replaces that quadratic projection with a linear minimization \(\arg\min_{s \in C} \langle \nabla f(x_k), s \rangle\), which over \(\ell_1\) balls, simplices, or nuclear-norm balls reduces to finding a single largest coordinate or leading singular vector.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Combinations and Automatic Feasibility:&lt;/strong&gt; Because each iterate is updated as \(x_{k+1} = (1 - \gamma_k) x_k + \gamma_k s_k\) with \(\gamma_k \in [0, 1]\) and \(x_k, s_k \in C\), convexity of \(C\) guarantees \(x_{k+1} \in C\) without ever leaving the constraint set.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Atomic Sparsity and Carathéodory Representation:&lt;/strong&gt; Every iteration adds at most one new extreme point (atom) \(s_k\) to the active representation of \(x_k\). Consequently, after \(k\) steps, \(x_k\) is guaranteed to be a convex combination of at most \(k+1\) vertices—yielding naturally sparse vectors or low-rank matrices.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duality Gap as a Free Stopping Certificate:&lt;/strong&gt; By convexity of \(f\), the linearized gap \(g_k = \max_{s \in C} \langle \nabla f(x_k), x_k - s \rangle = \langle \nabla f(x_k), x_k - s_k \rangle\) upper-bounds the true suboptimality \(f(x_k) - f(x^\star)\), giving an exact, zero-cost convergence certificate at every iteration.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-projection-free-step-on-the-probability-simplex&quot;&gt;Worked example: One Projection-Free Step on the Probability Simplex&lt;/h3&gt;

&lt;p&gt;Consider minimizing \(f(x) = \frac{1}{2}\|x - c\|_2^2\) with target \(c = (0.8, 0.5, 0.2)^\top\) over the 3-dimensional probability simplex \(\Delta_3 = \{x \in \mathbb{R}^3 : x \ge 0,\ x_1 + x_2 + x_3 = 1\}\), starting from the vertex \(x_0 = (0, 0, 1)^\top\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the gradient at \(x_0\):&lt;/strong&gt;
\(\nabla f(x_0) = x_0 - c = (0 - 0.8,\ 0 - 0.5,\ 1 - 0.2)^\top = (-0.8,\ -0.5,\ 0.8)^\top.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Call the Linear Minimization Oracle (LMO):&lt;/strong&gt; Minimize \(\langle \nabla f(x_0), s \rangle\) over \(s \in \Delta_3\). The minimum over a simplex is achieved at the standard basis vector corresponding to the smallest gradient coordinate. Here the smallest entry is \(-0.8\) at index 1, so \(s_0 = e_1 = (1, 0, 0)^\top\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Frank–Wolfe duality gap:&lt;/strong&gt;
\(g_0 = \langle \nabla f(x_0), x_0 - s_0 \rangle = (-0.8)(0 - 1) + (-0.5)(0 - 0) + (0.8)(1 - 0) = 0.8 + 0.8 = 1.6.\)
This immediately certifies \(f(x_0) - f(x^\star) \le 1.6\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the exact line-search step size \(\gamma_0\):&lt;/strong&gt; Along the segment \(x(\gamma) = x_0 + \gamma(s_0 - x_0)\) with \(d_0 = s_0 - x_0 = (1, 0, -1)^\top\), we minimize \(\frac{1}{2}\|x_0 + \gamma d_0 - c\|_2^2\):
\(\gamma_0 = \operatorname{clip}_{[0,1]}\!\left(\frac{-\langle \nabla f(x_0), d_0 \rangle}{\|d_0\|_2^2}\right) = \operatorname{clip}_{[0,1]}\!\left(\frac{1.6}{1^2 + 0^2 + (-1)^2}\right) = \frac{1.6}{2} = 0.8.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update and verify feasibility:&lt;/strong&gt;
\(x_1 = (1 - 0.8)(0, 0, 1)^\top + 0.8(1, 0, 0)^\top = (0.8, 0, 0.2)^\top.\)
Notice that \(x_1 \in \Delta_3\) automatically (entries sum to \(1\) and are nonnegative), its objective drops from \(f(x_0) = \frac{1}{2}(0.64 + 0.25 + 0.64) = 0.765\) to \(f(x_1) = \frac{1}{2}(0^2 + (-0.5)^2 + 0^2) = 0.125\), and it uses only 2 active vertices.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This chapter will examine the Frank-Wolfe algorithm proposed by Marguerite Frank and Philip Wolfe in 1956.&lt;/p&gt;

&lt;p&gt;The Frank-Wolfe algorithm is an iterative first-order optimization algorithm for constrained convex optimization, also called the conditional gradient method, reduced gradient method, and convex combination algorithm.&lt;/p&gt;

&lt;p&gt;This method was originally proposed by Marguerite Frank and Philip Wolfe in 1956. The Frank-Wolfe algorithm considers a linear approximation of the objective function at each iteration and moves toward the minimizer of this linear function.&lt;/p&gt;

&lt;p&gt;[15] Wikipedia. &lt;a href=&quot;https://en.wikipedia.org/wiki/Frank%E2%80%93Wolfe_algorithm&quot;&gt;Frank–Wolfe algorithm&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;2026-applications-optional&quot;&gt;2026 applications (optional)&lt;/h2&gt;

&lt;p&gt;The linear-minimization oracle is why Frank–Wolfe survived into the 2020s: structured SVMs, semi-relaxed optimal transport (color transfer), 1-D unbalanced OT, and constrained explanations of neural nets (rate-distortion maps on an \(\ell_1\) ball or the Birkhoff polytope). See the optional survey &lt;a href=&quot;/contents/en/chapter22/22_05_modern_applications/&quot;&gt;22-05 Modern applications of Frank–Wolfe&lt;/a&gt;. Use it after 22-02 / 22-04, not instead of the convergence analysis.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>22-06 Practical Exercises - Conditional Gradient (Frank-Wolfe)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_06_Practical_Exercises_Conditional_Gradient/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_06_Practical_Exercises_Conditional_Gradient</id>
   <content type="html">&lt;p&gt;Reading convergence proofs for Frank–Wolfe gives you the blueprint, but the real intuition clicks only when you compute the linear minimization oracle, duality gap, and away-step drop by hand and watch how dramatically the feasible geometry shapes the trajectory. This exercise set moves deliberately from basic 2D polytope iterations to projection-free nuclear-norm steps, exact line search, and away-step linear convergence—turning every theoretical theorem from Chapter 22 into muscle memory.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-diagnostic-checklist-for-solving-frankwolfe-problems&quot;&gt;Key ideas: Diagnostic Checklist for Solving Frank–Wolfe Problems&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Identifying the LMO Closed Form:&lt;/strong&gt; Always check the geometry of \(C\) first: on a polytope, test vertices; on an \(\ell_1\) ball of radius \(t\), pick \(-\operatorname{sign}(g_{i^\star}) t e_{i^\star}\); on a trace-norm ball, compute only the leading singular vector pair \((u_1, v_1)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Monitoring the Duality Gap \(g_k\):&lt;/strong&gt; At every step, compute \(g_k = \langle \nabla f(x_k), x_k - s_k \rangle \ge f(x_k) - f(x^\star)\). If \(g_k = 0\), \(x_k\) is provably optimal—never waste extra iterations once \(g_k \le \varepsilon\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choosing Step Sizes Wisely:&lt;/strong&gt; Open-loop \(\gamma_k = \frac{2}{k+2}\) is parameter-free, whereas for quadratic objectives \(f(x) = \frac{1}{2}\|Ax - b\|_2^2\), exact line search has the closed form \(\gamma_k = \operatorname{clip}_{[0,1]}\!\left(\frac{\langle \nabla f(x_k), x_k - s_k \rangle}{\|A(s_k - x_k)\|_2^2}\right)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diagnosing Zig-Zagging vs. Away Steps:&lt;/strong&gt; Whenever iterates bounce between two boundary vertices with shrinking step sizes, compare the forward gap \(\langle g_k, x_k - s_k \rangle\) against the away gap \(\langle g_k, v_k - x_k \rangle\) to decide whether to drop a stale vertex.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-warm-up-verification-before-exercise-1&quot;&gt;Worked example: Warm-Up Verification Before Exercise 1&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Before tackling Exercise 1, let us trace a tiny 2D quadratic on the \(\ell_1\) diamond $$C = {x \in \mathbb{R}^2 :&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\le 1}\(with\)f(x) = \frac{1}{2}\bigl((x_1 - 2)^2 + (x_2 - 1)^2\bigr)\(starting at\)x_0 = (0, 0)^\top$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 0 gradient:&lt;/strong&gt; \(\nabla f(x_0) = (-2, -1)^\top\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;LMO on the \(\ell_1\) diamond:&lt;/strong&gt; \(\arg\min_{\|s\|_1 \le 1} (-2 s_1 - s_2)\) picks \(s_0 = (1, 0)^\top\) (value \(-2\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact line search:&lt;/strong&gt; Direction \(d_0 = s_0 - x_0 = (1, 0)^\top\), so
\(\gamma_0 = \operatorname{clip}_{[0,1]}\!\left(\frac{-\langle (-2, -1), (1, 0) \rangle}{\|(1, 0)\|_2^2}\right) = \operatorname{clip}_{[0,1]}(2) = 1.\)
Thus \(x_1 = (1, 0)^\top\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check optimality at \(x_1 = (1, 0)^\top\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient: \(\nabla f(x_1) = (1 - 2, 0 - 1)^\top = (-1, -1)^\top\).&lt;/li&gt;
      &lt;li&gt;LMO: \(\min_{\|s\|_1 \le 1} (-s_1 - s_2) = -1\), achieved at \(s_1 = (1, 0)^\top\) or \((0, 1)^\top\).&lt;/li&gt;
      &lt;li&gt;Duality gap: \(g_1 = \langle (-1, -1), (1, 0) - (1, 0) \rangle = 0\)!
A zero duality gap certifies that \(x_1 = (1, 0)^\top\) is already the exact constrained minimizer on the \(\ell_1\) ball—and notice how effortless the check was compared to writing KKT multipliers.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---conditional-gradient-frank-wolfe&quot;&gt;Practical Exercises - Conditional Gradient (Frank-Wolfe)&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Jaggi (2013) and Lacoste-Julien &amp;amp; Jaggi (2015).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-1-basic-frank-wolfe&quot;&gt;📝 &lt;strong&gt;Exercise 1: Basic Frank-Wolfe&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;\(\min_{x \in C} f(x)\) with \(f(x) = \frac{1}{2}\|x\|^2\), \(C = \{x : \|x\|_1 \leq 1\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Linear minimization oracle (LMO)&lt;br /&gt;
b) Iterate from \(x^{(0)} = 0\)&lt;br /&gt;
c) Convergence rate&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) LMO:**

$$s^{(k)} = \arg\min_{s \in C} \langle \nabla f(x^{(k)}), s \rangle$$

$$= \arg\min_{\|s\|_1 \leq 1} \langle x^{(k)}, s \rangle$$

**Solution:** $$s = -\text{sign}(x_i^{(k)})\, e_i$$ for $$i = \arg\max_j |x_j^{(k)}|$$

**b) Iteration:**

$$d^{(k)} = s^{(k)} - x^{(k)}$$

$$\gamma^{(k)} = \frac{2}{k+2}$$ (default step size)

$$x^{(k+1)} = x^{(k)} + \gamma^{(k)} d^{(k)} = (1 - \gamma^{(k)})x^{(k)} + \gamma^{(k)} s^{(k)}$$

**Iter 0:** $$x^{(0)} = 0$$, $$\nabla f = 0$$, $$s^{(0)}$$ arbitrary (say $$e_1$$)

$$x^{(1)} = \frac{2}{2}e_1 = e_1$$

**Iter 1:** $$\nabla f(e_1) = e_1$$, $$s^{(1)} = -e_1$$, $$\gamma^{(1)} = \frac{2}{3}$$

$$x^{(2)} = \frac{1}{3}e_1 + \frac{2}{3}(-e_1) = -\frac{1}{3}e_1$$

**c) Convergence:**

$$f(x^{(k)}) - f^* \leq \frac{2C_f}{k+2}$$

where $$C_f$$ is the curvature constant of $$f$$ over $$C$$ (it satisfies $$C_f \leq L\,\text{diam}(C)^2$$ when $$\nabla f$$ is $$L$$-Lipschitz).

**$$O(1/k)$$ convergence.**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-projection-free&quot;&gt;📝 &lt;strong&gt;Exercise 2: Projection-Free&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Compare Frank-Wolfe with projected GD on the \(\ell_1\) ball.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Complexity of the projection \(\Pi_{\ell_1}(y)\)&lt;br /&gt;
b) Complexity of the LMO&lt;br /&gt;
c) When is FW better?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Projection:**

$$\Pi_{\|·\|_1 \leq 1}(y) = \arg\min_{\|x\|_1 \leq 1} \|x - y\|^2$$

**Algorithm:** soft-thresholding with an adaptive threshold.

**Complexity:** $$O(n \log n)$$ (sorting)

**b) LMO:**

$$s = \arg\min_{\|s\|_1 \leq 1} \langle g, s \rangle = -\text{sign}(g_{i^*})\, e_{i^*}, \quad i^* = \arg\max_i |g_i|$$

**Complexity:** $$O(n)$$ (find the max)

**c) Advantage of FW:**

- **Large $$n$$:** $$O(n)$$ &amp;lt;&amp;lt; $$O(n \log n)$$
- **Sparse iterates:** $$x^{(k)}$$ is a convex combination of few atoms
- **No tuning:** the step size $$\gamma = \frac{2}{k+2}$$ works

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-line-search&quot;&gt;📝 &lt;strong&gt;Exercise 3: Line Search&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Replace \(\gamma = \frac{2}{k+2}\) by exact line search.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) \(\gamma^* = \arg\min_{\gamma \in [0,1]} f(x + \gamma d)\)&lt;br /&gt;
b) For the quadratic \(f(x) = \frac{1}{2}x^TQx - b^Tx\)&lt;br /&gt;
c) Compare the convergence&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Exact line search:**

$$\min_{\gamma \in [0,1]} f(x^{(k)} + \gamma d^{(k)})$$

**b) Quadratic:**

$$f(x + \gamma d) = \frac{1}{2}(x + \gamma d)^TQ(x + \gamma d) - b^T(x + \gamma d)$$

$$\frac{d}{d\gamma} = d^TQ(x + \gamma d) - b^Td = 0$$

$$\gamma^* = \frac{b^Td - x^TQd}{d^TQd} = \frac{-\nabla f(x)^T d}{d^TQd}$$

Clip to $$[0, 1]$$.

**c) Convergence:**

**Default $$\gamma = 2/(k+2)$$:** $$O(1/k)$$

**Exact line search:** $$O(1/k)$$ with better constants

**Adaptive:** often faster empirically

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-away-step-frank-wolfe&quot;&gt;📝 &lt;strong&gt;Exercise 4: Away-Step Frank-Wolfe&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Add “away steps” to escape slow convergence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Identify the active set \(\mathcal{S}^{(k)}\)&lt;br /&gt;
b) Away direction \(d_A = x - v_A\)&lt;br /&gt;
c) Choose between the FW step and the away step&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Active set:**

$$x^{(k)} = \sum_{v \in \mathcal{S}^{(k)}} \alpha_v v$$ with $$\alpha_v &amp;gt; 0$$, $$\sum \alpha_v = 1$$

(The vertices with positive weights in the convex combination)

**b) Away vertex:**

$$v_A = \arg\max_{v \in \mathcal{S}^{(k)}} \langle \nabla f(x^{(k)}), v \rangle$$

$$d_A = x^{(k)} - v_A$$

**c) Choose the step:**

$$g_{\text{FW}} = \langle \nabla f, s - x \rangle$$

$$g_{\text{away}} = \langle \nabla f, x - v_A \rangle$$

If $$g_{\text{FW}} &amp;lt; g_{\text{away}}$$: FW step

Else: away step with $$\gamma_{\max} = \frac{\alpha_{v_A}}{1 - \alpha_{v_A}}$$

**Result:** faster convergence, removes redundant vertices

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-applications&quot;&gt;📝 &lt;strong&gt;Exercise 5: Applications&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Nuclear norm ball: \(\|X\|_* \leq \tau\)&lt;br /&gt;
b) Matching polytope&lt;br /&gt;
c) Probabilistic graphical models&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Nuclear norm:**

**LMO:** $$S = \arg\min_{\|S\|_* \leq \tau} \langle G, S \rangle$$

$$= -\tau u_1 v_1^T$$

where $$(u_1, v_1)$$ are the top singular vectors of $$G$$.

**Complexity:** a top-singular-pair computation (cheap, e.g. power iteration, $$O(mn)$$ per iteration) &amp;lt;&amp;lt; a full SVD (about $$O(m^2n)$$) for the projection

**b) Matching:**

**LMO:** minimum weight perfect matching

**Complexity:** $$O(n^3)$$ (Hungarian algorithm)

**Projection:** hard to compute!

**c) Graphical models:**

**LMO:** MAP inference

**Useful:** even an approximate LMO works (relaxed FW)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Frank-Wolfe Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aspect&lt;/th&gt;
      &lt;th&gt;Benefit&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Projection-free&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(O(n)\) LMO vs \(O(n \log n)\) projection&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Sparse iterates&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Automatic sparsity (convex combinations)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Simple step size&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\gamma = 2/(k+2)\) works&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Structured constraints&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;LMO easier than projection&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Limitations:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(O(1/k)\) convergence (slower than accelerated methods)&lt;/li&gt;
  &lt;li&gt;Does not adapt to strong convexity&lt;/li&gt;
  &lt;li&gt;Zigzagging near the boundary&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Expensive projection&lt;/li&gt;
  &lt;li&gt;Need sparse solutions&lt;/li&gt;
  &lt;li&gt;Structured constraints (nuclear norm, matching)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Jaggi, M. (2013). “Revisiting Frank-Wolfe: Projection-Free Sparse Convex Optimization”. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Lacoste-Julien, S., &amp;amp; Jaggi, M. (2015). “On the Global Linear Convergence of Frank-Wolfe”. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>22-04 Properties and variants</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_04_Properties_and_variants/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_04_Properties_and_variants</id>
   <content type="html">&lt;p&gt;Anyone who runs vanilla Frank–Wolfe on a smooth strongly convex objective whose optimum lies on the boundary of a polytope soon notices a frustrating behavior: the iterates zig-zag wildly back and forth between the active vertices, stalling at a slow \(O(1/k)\) crawl even though the problem is strongly convex. Why? Because classical Frank–Wolfe can only move &lt;em&gt;toward&lt;/em&gt; vertices, never &lt;em&gt;away&lt;/em&gt; from bad vertices already carrying weight in the convex combination. Introducing &lt;strong&gt;away steps&lt;/strong&gt; (Wolfe 1970; analyzed by Lacoste-Julien &amp;amp; Jaggi 2013–2015) cures the zig-zagging completely and restores linear convergence \(O(\exp(-ck))\) over polytopes.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-curing-zig-zagging-and-unlocking-linear-rates&quot;&gt;Key ideas: Curing Zig-Zagging and Unlocking Linear Rates&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Exact Line Search and Fully Corrective Variants:&lt;/strong&gt; Replacing \(\gamma_k = \frac{2}{k+1}\) with exact line search \(\gamma_k = \arg\min_{\gamma \in [0,1]} f(x^{(k-1)} + \gamma(s^{(k-1)} - x^{(k-1)}))\) guarantees monotonic descent, while fully corrective Frank–Wolfe re-optimizes \(f\) over the entire convex hull of discovered atoms at each step.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Away-Step Direction and Active Set:&lt;/strong&gt; Maintaining \(x^{(k-1)} = \sum_{v \in S} \alpha_v v\), we compute both the forward atom \(s_{\text{FW}} = \arg\min_{v \in C} \langle \nabla f(x), v \rangle\) and the worst active atom \(v_{\text{away}} = \arg\max_{v \in S} \langle \nabla f(x), v \rangle\). Stepping along \(x - v_{\text{away}}\) sheds weight from outdated vertices.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pyramidal Width and Linear Convergence:&lt;/strong&gt; Over a polytope \(C = \operatorname{conv}(\mathcal{A})\), strong convexity plus smoothness is not enough for plain FW to converge linearly when \(x^\star\) is on a face. Away-Step FW achieves global linear convergence \(h_{k} \le (1 - \rho)^k h_0\) governed by the polytope’s geometric &lt;strong&gt;pyramidal width&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Path Following for Regularization Paths:&lt;/strong&gt; By coupling Frank–Wolfe with warm starts across increasing norm-ball radii \(t_1 &amp;lt; t_2 &amp;lt; \dots\), one can trace an entire regularization path at controlled suboptimality tolerance \(\varepsilon\) in far fewer iterations than solving each \(t\) from scratch.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-an-away-step-beats-a-forward-step&quot;&gt;Worked example: Why an Away Step Beats a Forward Step&lt;/h3&gt;

&lt;p&gt;Consider minimizing \(f(x) = \frac{1}{2}\|x - c\|_2^2\) with \(c = (0.5, 0.5, 0)^\top\) over the 3-simplex \(\Delta_3 = \operatorname{conv}\{e_1, e_2, e_3\}\). The true optimum is \(x^\star = (0.5, 0.5, 0)^\top\) on the face \(\operatorname{conv}\{e_1, e_2\}\). Suppose our current iterate is \(x = (0.4, 0.4, 0.2)^\top\), with active set \(S = \{e_1, e_2, e_3\}\) and weights \(\alpha = (0.4, 0.4, 0.2)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the gradient at \(x\):&lt;/strong&gt;
\(g = \nabla f(x) = x - c = (-0.1,\ -0.1,\ +0.2)^\top.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the Forward (FW) direction:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;The smallest coordinate of \(g\) is \(-0.1\) (tied at \(e_1, e_2\)). Pick \(s_{\text{FW}} = e_1 = (1, 0, 0)^\top\).&lt;/li&gt;
      &lt;li&gt;Forward direction: \(d_{\text{FW}} = e_1 - x = (0.6, -0.4, -0.2)^\top\).&lt;/li&gt;
      &lt;li&gt;Directional improvement (negative inner product): \(-\langle g, d_{\text{FW}} \rangle = -(-0.06 + 0.04 - 0.04) = 0.06\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the Away-Step direction:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Among active vertices \(S = \{e_1, e_2, e_3\}\), the largest inner product \(\langle g, v \rangle\) is at \(v_{\text{away}} = e_3\) (value \(+0.2\)).&lt;/li&gt;
      &lt;li&gt;Away direction: \(d_{\text{away}} = x - e_3 = (0.4, 0.4, -0.8)^\top\).&lt;/li&gt;
      &lt;li&gt;Directional improvement: \(-\langle g, d_{\text{away}} \rangle = -(-0.04 - 0.04 - 0.16) = 0.24\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare and execute the Away Step:&lt;/strong&gt; Since \(0.24 &amp;gt; 0.06\), Away-Step FW chooses \(d_{\text{away}}\) with maximum feasible step \(\gamma_{\max} = \frac{\alpha_{e_3}}{1 - \alpha_{e_3}} = \frac{0.2}{0.8} = 0.25\).
    &lt;ul&gt;
      &lt;li&gt;Exact line search gives \(\gamma^\star = \frac{0.24}{\|d_{\text{away}}\|_2^2} = \frac{0.24}{0.16 + 0.16 + 0.64} = \frac{0.24}{0.96} = 0.25 = \gamma_{\max}\).&lt;/li&gt;
      &lt;li&gt;Update: \(x_{\text{new}} = x + 0.25(0.4, 0.4, -0.8)^\top = (0.5, 0.5, 0)^\top = x^\star\)!
In a &lt;strong&gt;single&lt;/strong&gt; drop step, Away-Step FW completely removes the spurious vertex \(e_3\) and hits the exact optimum \(x^\star\), whereas standard FW would have zig-zagged toward \(e_1\) and \(e_2\) for dozens of steps.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;some-variants&quot;&gt;Some variants&lt;/h2&gt;
&lt;p&gt;Let’s look at some variant conditional gradient methods:&lt;br /&gt;
• &lt;strong&gt;Line search&lt;/strong&gt;: Instead of fixing \(γk=2/(k+1),k=1,2,3,...\), we use exact line search for the step size at each \(k = 1, 2, 3, . . .\).&lt;/p&gt;
&lt;blockquote&gt;
\[γ_k = \arg\min_{γ∈[0,1]} f\Bigl( x^{(k−1)} + γ\bigl(s^{(k−1)} − x^{(k−1)} \bigr) \Bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;Backtracking can also be used.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Fully corrective&lt;/strong&gt;: Direct update according to the following equation.&lt;/p&gt;
&lt;blockquote&gt;
\[x^{(k)} = \arg\min_y f(y) \: \text{ subject to } y ∈ conv\{ x^{(0)}, s^{(0)}, . . . s^{(k−1)} \}\]
&lt;/blockquote&gt;

&lt;p&gt;This method can achieve much better progress, but the cost is high.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter22/away_steps.png&quot; alt=&quot;[Fig 3] Away step motivation [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 3] Away step motivation [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;another-variant-away-steps&quot;&gt;Another variant: away steps&lt;/h2&gt;
&lt;p&gt;For a faster solution, let’s look at the minimization problem in [Fig 3]. Here, the optimal solution is (0,0). The conditional descent method becomes difficult to move from the initial point (0,1). However, due to away step movement, conditional gradient descent not only moves to promising points but also moves away from unpromising points.&lt;/p&gt;

&lt;p&gt;Let’s assume a convex hull \(C = conv(A)\) for atoms set \(A\)&lt;/p&gt;

&lt;p&gt;We can explicitly represent \(x∈C\) as a convex combination of elements belonging to \(A\).&lt;/p&gt;
&lt;blockquote&gt;
\[x = \sum_{a∈A} λ_a(x)a\]
&lt;/blockquote&gt;

&lt;p&gt;Conditional gradient with away steps: &lt;br /&gt;
\(\text{1. choose } x^{(0)} = a^{(0)} ∈ A\) &lt;br /&gt;
\(\text{2. for } k = 1, 2, 3, . . .\) &lt;br /&gt;
\(\qquad s^{(k−1)} ∈ \arg\min_{a∈A} ∇f(x^{(k−1)})^Ta,\)
\(\qquad a^{(k−1)} ∈ \arg\max_{a∈A, λa(x(k−1))&amp;gt;0} ∇f(x^{(k−1)})^Ta\)
\(\qquad \text{choose } v = s^{(k−1)} − x^{(k−1)} or \quad v = x^{(k−1)} − a^{(k−1)}\)
\(\qquad x^{(k)} = x^{(k−1)} + γ_kv\) &lt;br /&gt;
\(\text{3. end for}\)&lt;/p&gt;

&lt;h2 id=&quot;linear-convergence&quot;&gt;Linear convergence&lt;/h2&gt;
&lt;p&gt;Let’s consider the following unconstrained problem.&lt;/p&gt;
&lt;blockquote&gt;
\[\min_x f(x) \: \text{ subject to } x ∈ \mathbb{R}^n\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(f\) is µ-strongly convex and \(∇f\) is L-Lipschitz.&lt;/p&gt;

&lt;p&gt;By iterating gradient descent \(x^{(k+1)} = x^{(k)} − t_k∇f(x^{(k)})\) with \(t_k = 1/L\), the following is satisfied.&lt;/p&gt;
&lt;blockquote&gt;
\[f(x^{(k)}) − f^{\star} ≤ \Bigl( 1 −\frac{µ}{L} \Bigr)^k \bigl( f(x^{(0)}) − f^{\star} \bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;Now let’s also consider the following constrained problem.&lt;/p&gt;
&lt;blockquote&gt;
\[\min_x f(x) \: \text{ subject to } x ∈ conv(A) ⊆ \mathbb{R}^n\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;theorem-lacoste-julien--jaggi-2013&quot;&gt;[Theorem (Lacoste-Julien &amp;amp; Jaggi 2013)]&lt;/h3&gt;
&lt;p&gt;Assume that \(f\) is µ-strongly convex, \(∇f\) is L-Lipschitz, and \(A ⊆ \mathbb{R}^n\) is finite.&lt;/p&gt;

&lt;p&gt;With appropriate \(γ_k\), the iteration steps generated by the conditional gradient algorithm always satisfy the following.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x^{(k)}) − f^{\star} ≤ (1 − r)^{k/2}(f(x^{(0)}) − f^{\star}) \text { for } r = \frac{µ}{L}·\frac{Φ(A)^2}{4\text{diam}(A)^2}\)
\(\text{where }Φ(A) = \min_{F ∈faces(conv(A))} dist(F, conv(A \ F))\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the polytope is planar, \(Φ\) is small and the algorithm converges slowly.&lt;/p&gt;

&lt;h2 id=&quot;path-following&quot;&gt;Path following&lt;/h2&gt;
&lt;p&gt;Let’s look at the following given norm constrained problem&lt;/p&gt;
&lt;blockquote&gt;
\[\min_x f(x) \: \text{ subject to } \| x \| ≤ t\]
&lt;/blockquote&gt;

&lt;p&gt;The Frank-Wolfe algorithm can be used for &lt;strong&gt;path following&lt;/strong&gt;. In other words, it means that it can generate a (approximate) solution path \(\hat{x}(t), t ≥ 0\).&lt;/p&gt;

&lt;p&gt;Starting with \(t_0 = 0\) and \(x^{\star}(0) = 0\), fix parameters \(\epsilon, m &amp;gt; 0\) and then iterate for \(k=1,2,3,...\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Compute \(t_k = t_{k−1} + \frac{(1 − 1/m)\epsilon}{\| ∇f(\hat{x}(t_k−1))\|\_{∗}}\) and set \(\hat{x}(t) = \hat{x}(t_{k−1})\) for all \(t ∈ (t_{k−1}, t_k)\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;At \(t = t_k\), execute Frank-Wolfe to compute \(\hat{x}(t_k)\) and terminate when the duality gap is \(≤ \frac{\epsilon}{m}\).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a method that simplifies existing strategies. [Giesen et al. (2012)]&lt;/p&gt;

&lt;p&gt;Through this &lt;strong&gt;path following&lt;/strong&gt; strategy, we can guarantee the following for all visited $t$:&lt;/p&gt;
&lt;blockquote&gt;
\[f(\hat{x}(t)) − f(x^{\star}(t)) ≤ \epsilon\]
&lt;/blockquote&gt;

&lt;p&gt;That is, it generates a case of suboptimality gap that is uniformly bounded by \(\epsilon\) for all \(t\).&lt;/p&gt;

&lt;p&gt;As shown in the equation below, the Frank-Wolfe duality gap can be redefined as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[g_t(x) = \max_{\|s\|≤1} ∇f(x)^T(x − s) = ∇f(x)^Tx + t\|∇f(x)\|_{∗}\]
&lt;/blockquote&gt;

&lt;p&gt;This is a linear function with respect to $t$. Therefore, if \(g_t(x) ≤ \frac{\epsilon}{m}\), we can increase \(t\) to \(t^+ = t + (1 − 1/m)\epsilon/\|∇f(x)\|_{∗}\) using the following equation.&lt;/p&gt;

&lt;blockquote&gt;
\[g_t+ (x) = ∇f(x)^Tx + t\|∇f(x)\|_{∗} + \epsilon − \epsilon/m ≤ \epsilon\]
&lt;/blockquote&gt;

&lt;p&gt;That is, the duality gap is maintained at \(≤ \epsilon\) between \(t\) and \(t^+\) for the same \(x\).&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>22-03 Convergence analysis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_03_Convergence_analysis/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_03_Convergence_analysis</id>
   <content type="html">&lt;p&gt;Why does Frank–Wolfe converge at the universal rate \(O(1/k)\) without ever mentioning a Euclidean Lipschitz constant \(L\) or choosing a metric? The secret lies in Martin Jaggi’s 2011 geometric reformulation: instead of bounding curvature in Euclidean norm, we measure how far \(f\) bends above its linear tangent &lt;em&gt;strictly inside&lt;/em&gt; the feasible set \(C\) via the affine-invariant curvature constant \(M\). That single definition unlocks both a clean induction proof and one of optimization’s rarest superpowers—complete invariance under invertible linear transformations of the coordinates.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-curvature-constant-affine-invariance-and-inexact-oracles&quot;&gt;Key ideas: Curvature Constant, Affine Invariance, and Inexact Oracles&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Jaggi’s Curvature Constant \(M\):&lt;/strong&gt; Defined as \(M = \sup_{x, s \in C,\ \gamma \in (0,1]} \frac{2}{\gamma^2}\bigl(f(y) - f(x) - \langle \nabla f(x), y - x \rangle\bigr)\) with \(y = (1-\gamma)x + \gamma s\), \(M\) bounds the quadratic remainder along feasible line segments. Whenever \(\nabla f\) is \(L\)-Lipschitz, \(M \le L \cdot \operatorname{diam}(C)^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The One-Step Descent Recurrence:&lt;/strong&gt; Combining the curvature bound with the optimality of \(s_k\) and convexity of \(f\) produces the key contraction inequality \(h_k \le (1 - \gamma_k) h_{k-1} + \frac{M}{2}\gamma_k^2\) for suboptimality \(h_k = f(x^{(k)}) - f(x^\star)\), which telescopes cleanly under \(\gamma_k = \frac{2}{k+1}\) to give \(h_k \le \frac{2M}{k+2}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine Invariance:&lt;/strong&gt; Because both the inner product \(\langle \nabla f(x), s - x \rangle\) and the curvature constant \(M\) depend only on linear functionals and convex combinations, reparameterizing \(x = A\tilde{x}\) leaves the Frank–Wolfe trajectory identical—unlike projected gradient descent, whose Euclidean projection distorts under rescaling.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robustness to Inexact LMOs:&lt;/strong&gt; In massive matrix problems, computing the exact top singular vector is unnecessary. Solving the LMO up to additive error \(\frac{\delta M \gamma_k}{2}\) preserves the exact \(O(1/k)\) rate with constant scaled merely by \((1 + \delta)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-m-and-checking-the-o1k-bound-by-hand&quot;&gt;Worked example: Computing \(M\) and Checking the \(O(1/k)\) Bound by Hand&lt;/h3&gt;

&lt;p&gt;Let \(f(x) = \frac{1}{2}(x - 1)^2\) on the compact interval \(C = [0, 2]\), starting at \(x^{(0)} = 0\) (where \(f(x^{(0)}) = 0.5\) and \(f(x^\star) = f(1) = 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the exact curvature constant \(M\):&lt;/strong&gt; For any \(x, s \in [0, 2]\) and \(y = x + \gamma(s - x)\), the exact Taylor remainder of this quadratic is
\(f(y) - f(x) - f&apos;(x)(y - x) = \frac{1}{2}(y - x)^2 = \frac{1}{2}\gamma^2 (s - x)^2.\)
Therefore,
\(M = \max_{x, s \in [0, 2]} \frac{2}{\gamma^2} \cdot \frac{1}{2}\gamma^2 (s - x)^2 = \max_{x, s \in [0, 2]} (s - x)^2 = (2 - 0)^2 = 4.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the theoretical upper bound at \(k = 1, 2\):&lt;/strong&gt; Using \(f(x^{(k)}) - f^\star \le \frac{2M}{k+2}\), we get:
    &lt;ul&gt;
      &lt;li&gt;At \(k = 1\): bound \(= \frac{8}{3} \approx 2.667\).&lt;/li&gt;
      &lt;li&gt;At \(k = 2\): bound \(= \frac{8}{4} = 2.000\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Run two exact Frank–Wolfe steps with \(\gamma_k = \frac{2}{k+1}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Step \(k = 1\) (\(\gamma_1 = 1\)):&lt;/strong&gt; \(f&apos;(x^{(0)}) = 0 - 1 = -1 &amp;lt; 0\), so \(s^{(0)} = 2\). Then \(x^{(1)} = (1 - 1)(0) + 1(2) = 2\), giving \(h_1 = f(2) - 0 = 0.5 \le 2.667\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Step \(k = 2\) (\(\gamma_2 = \frac{2}{3}\)):&lt;/strong&gt; \(f&apos;(x^{(1)}) = 2 - 1 = +1 &amp;gt; 0\), so \(s^{(1)} = 0\). Then \(x^{(2)} = \frac{1}{3}(2) + \frac{2}{3}(0) = \frac{2}{3}\), giving \(h_2 = f\!\left(\frac{2}{3}\right) = \frac{1}{2}\left(-\frac{1}{3}\right)^2 = \frac{1}{18} \approx 0.0556 \le 2.000\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify affine invariance:&lt;/strong&gt; Rescale via \(x = 10\tilde{x}\) so \(\tilde{C} = [0, 0.2]\) and \(\tilde{f}(\tilde{x}) = \frac{1}{2}(10\tilde{x} - 1)^2\). Then \(\tilde{f}&apos;&apos; = 100\) while \(\operatorname{diam}(\tilde{C})^2 = 0.04\), so \(\tilde{M} = 100 \times 0.04 = 4 = M\)—identical!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;convergence-analysis&quot;&gt;Convergence analysis&lt;/h2&gt;

&lt;p&gt;To find out the convergence characteristics of the Frank-Wolfe method, it is necessary to define the curvature constant of \(f\) for \(C\) as follows [Jaggi (2011)]:&lt;/p&gt;

&lt;blockquote&gt;
\[M = \max_{x,s,y\in C, y = (1−\gamma)x+\gamma s} \frac{2}{\gamma^2} \Bigl( f(y) − f(x) − \nabla f(x)^T(y − x) \Bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;where \(\gamma \in [0, 1]\). Through \(M\), we can actually measure how far the function tends to be from linear approximation. Here \(M = 0\) indicates that \(f\) is linear. \(f(y) - f(x) - \nabla f(x)^T(y - x)\) is called the Bregman divergence defined by \(f\).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Theorem&lt;/strong&gt;: The conditional gradient method using fixed step size \(\gamma_k = 2/(k + 1), k = 1,2,3, ...\) satisfies the following:&lt;/p&gt;

\[f(x^{(k)}) − f^{*} \leq \frac{2M}{k + 2}\]
&lt;/blockquote&gt;

&lt;p&gt;The number of iterations required to satisfy \(f(x^{(k)}) − f^{*} \leq \epsilon\) is \(O(1/\epsilon)\). We want to prove this theory by induction. However, before moving on to the direct proof, we want to introduce one concept that needs to be addressed.&lt;/p&gt;

&lt;h2 id=&quot;basic-inequality&quot;&gt;Basic inequality&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;key inequality&lt;/strong&gt; used to prove Frank-Wolfe convergence speed is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[f(x^{(k)}) \leq f(x^{(k−1)}) − \gamma_k g(x^{(k−1)}) + \frac{\gamma^2_k}{2}M\]
&lt;/blockquote&gt;

&lt;p&gt;where \(g(x) = \max_{s\in C} \nabla f(x)^T(x − s)\) means the duality gap discussed earlier, and by induction, the ratio follows this inequality.&lt;/p&gt;

&lt;h3 id=&quot;proof&quot;&gt;[Proof]&lt;/h3&gt;

&lt;p&gt;To prove the basic inequality, we specify \(x^+ = x^{(k)}, x = x^{(k−1)}, s = s^{(k−1)}, \gamma = \gamma_k\). Then we organize as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(x^+) &amp;amp;= f\bigl( x + \gamma(s − x) \bigr) \\
&amp;amp;\leq f(x) + \gamma\nabla f(x)^T(s − x) + \frac{\gamma^2}{2}M \\
&amp;amp;= f(x) − \gamma g(x) + \frac{\gamma^2}{2}M
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In the above equation, the second line used the definition of \(M\), and the third line used the definition of \(g\).&lt;/p&gt;

&lt;p&gt;Now, using the basic inequality, we use induction to prove our convergence rate theorem. For the case \(k=1\), we can easily verify that the theorem is satisfied. For any case \(k &amp;gt; 1\), we assume that \(f(x^{(k−1)}) − f^{*} \leq 2M/(k + 1)\) is satisfied.&lt;/p&gt;

&lt;p&gt;Let’s recall the duality gap \(g(x)\) mentioned earlier:&lt;/p&gt;

&lt;blockquote&gt;
\[g(x^{(k−1)}) \leq f(x^{(k−1)}) − f^{*}\]
&lt;/blockquote&gt;

&lt;p&gt;Let’s apply \(\gamma_k = 2/(k + 1)\) and the basic inequality:&lt;/p&gt;

&lt;blockquote&gt;
\[f(x^{(k)}) \leq f(x^{(k−1)}) − 2(f(x^{(k−1)}) − f^{*})/(k + 1) + 4M/2(k + 1)^2\]

\[f(x^{(k)}) − f^{*} \leq (1 − 2/(k + 1))(f(x^{(k−1)}) − f^{*}) + 2M/(k + 1)^2\]

\[f(x^{(k)}) − f^{*} \leq (k − 1)/(k + 1) \times 2M/(k + 1) + 2M/(k + 1)^2 \leq 2M/(k + 2)\]
&lt;/blockquote&gt;

&lt;p&gt;The proven convergence speed matches the speed known for projected gradient descent when \(\nabla f\) is Lipschitz. Let’s compare the assumptions. In fact, if \(\nabla f\) is Lipschitz with constant \(L\), then when \(\text{diam}^2(C) = \max_{x,s\in C} \|x − s\|^2\), we have \(M \leq \text{diam}^2(C) \cdot L\). To verify this, we need to remember that \(\nabla f\) with constant \(L\) Lipschitz is equivalent to the following:&lt;/p&gt;

&lt;blockquote&gt;
\[f(y) − f(x) − \nabla f(x)^T(y − x) \leq \frac{L}{2} \| y − x \|^2_2\]
&lt;/blockquote&gt;

&lt;p&gt;Maximizing over all \(y = (1-\gamma) x + \gamma s\) and multiplying by \(\frac{2}{\gamma^2}\):&lt;/p&gt;

&lt;blockquote&gt;
\[M \leq \max_{x,s,y\in C, y=(1−\gamma)x+\gamma s} \frac{2}{\gamma^2} \cdot \frac{L}{2} \| y − x \|^2_2 = \max_{x,s\in C} L \| x − s \|^2_2\]
&lt;/blockquote&gt;

&lt;p&gt;The boundary of \(M\) has been determined. Basically, we assume that the bounded curvature is not greater than the curvature assumed for proximal gradient.&lt;/p&gt;

&lt;h2 id=&quot;affine-invariance&quot;&gt;Affine invariance&lt;/h2&gt;

&lt;p&gt;Let’s think about the concepts we learned earlier:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent&lt;/strong&gt;: \(x^+ = x − t\nabla f(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pure Newton’s Method&lt;/strong&gt;: \(x^+ = x − \nabla^2 f(x)^{−1}\nabla f(x)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Gradient descent is not affine invariant. That is, scaling coordinates affects the performance of gradient descent. On the other hand, Newton’s method is affine invariant. That is, the algorithm behaves the same under all affine transformations of variables. The conditional gradient method is similar to gradient descent but is affine invariant.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important property of Frank-Wolfe&lt;/strong&gt;: The update is &lt;strong&gt;affine invariant&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Given nonsingular \(A : \mathbb{R}^n → \mathbb{R}^n\), we can define \(x = Ax&apos;, h(x&apos;) = f(Ax&apos;)\). Then Frank-Wolfe for \(h(x&apos;)\) can be computed as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{array}{rcl}
s&apos; &amp;amp; = &amp;amp; \arg\min_{z\in A^{−1}C} \nabla h(x&apos;)^Tz \\
(x&apos;)^+ &amp;amp; = &amp;amp; (1 − \gamma)x&apos; + \gamma s&apos;
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;Multiplying by \(A\) gives the same Frank-Wolfe update performed on \(f(x)\). Even the convergence analysis is affine invariant. The curvature constant \(M\) of \(h\) is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[M = \max_{x&apos;,s&apos;,y&apos;\in A^{−1}C, y&apos;=(1−\gamma)x&apos;+\gamma s&apos;} \frac{2}{\gamma^2} \Bigl( h(y&apos;) − h(x&apos;) − \nabla h(x&apos;)^T(y&apos; − x&apos;) \Bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;Since \(\nabla h(x&apos;)^T(y&apos; − x&apos;) = \nabla f(x)^T(y − x)\), it matches \(f\). However, the affine invariance of the boundary of \(M\) is not intuitive:&lt;/p&gt;

&lt;blockquote&gt;
\[M \leq \max_{x,s\in C} L\|x − s\|^2_2\]
&lt;/blockquote&gt;

&lt;p&gt;If the diameter of the given \(C\) is not affine invariant, this is worth considering.&lt;/p&gt;

&lt;h2 id=&quot;inexact-updates&quot;&gt;Inexact updates&lt;/h2&gt;

&lt;p&gt;We analyzed inaccurate Frank-Wolfe updates [Jaggi (2011)].&lt;/p&gt;

&lt;p&gt;Choose \(s^{(k−1)}\) such that:&lt;/p&gt;

&lt;blockquote&gt;
\[\nabla f(x^{(k−1)})^Ts^{(k−1)} \leq \min_{s\in C} \nabla f(x^{(k−1)})^Ts + \frac{M\gamma_k}{2} \cdot \delta\]
&lt;/blockquote&gt;

&lt;p&gt;where \(\delta \geq 0\) is an inaccuracy parameter. Using this, we basically get the following ratio:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Theorem&lt;/strong&gt;: The conditional gradient method using fixed step size \(\gamma_k=2/(k+1), k=1,2,3, ...\) and inaccuracy parameter \(\delta \geq 0\) satisfies the following:&lt;/p&gt;

\[f(x^{(k)}) − f^{*} \leq \frac{2M}{k + 2} (1 + \delta)\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The optimization error at step \(k\) is \(\frac{M\gamma_k}{2} \cdot \delta\). Since \(\gamma_k → 0\), the error disappears over time as intended.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>22-02 Conditional gradient method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_02_Conditional_gradient_method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_02_Conditional_gradient_method</id>
   <content type="html">&lt;p&gt;Imagine solving a collaborative filtering problem where your decision variable is a \(10{,}000 \times 10{,}000\) matrix constrained to have nuclear norm at most \(t\). Projected gradient descent demands a full singular value decomposition at every single iteration—an \(O(n^3)\) bottleneck that grinds computation to a halt. The Conditional Gradient (Frank–Wolfe) method breaks this barrier by asking a far simpler question: what is the &lt;em&gt;single&lt;/em&gt; rank-1 matrix that best aligns with the negative gradient? Computing that leading singular vector pair via a few power iterations costs orders of magnitude less, and every iterate stays low-rank by construction.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-mechanics-of-conditional-gradient-across-norm-balls&quot;&gt;Key ideas: Mechanics of Conditional Gradient Across Norm Balls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Linearization on Compact Convex Sets:&lt;/strong&gt; At iterate \(x^{(k-1)}\), Frank–Wolfe replaces the nonlinear objective \(f(y)\) by its first-order Taylor model \(f(x^{(k-1)}) + \langle \nabla f(x^{(k-1)}), y - x^{(k-1)} \rangle\) and minimizes it over \(C\), yielding an extreme point \(s^{(k-1)} \in C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Norm Equivalence for Norm Balls:&lt;/strong&gt; When \(C = \{x : \|x\| \le t\}\), the LMO \(\min_{\|s\| \le t} \langle g, s \rangle\) evaluates directly to \(-t \|g\|_\star\), achieved by a dual-norm maximizing atom. Thus the geometry of the constraint ball directly dictates the LMO cost.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Contrast Across \(\ell_1\), \(\ell_p\), and Trace Norms:&lt;/strong&gt; Over an \(\ell_1\) ball, the LMO selects a single signed coordinate \(-\operatorname{sign}(g_i) t e_i\); over an \(\ell_p\) ball (\(1 &amp;lt; p &amp;lt; \infty\)), it rescales coordinates by $$&lt;/td&gt;
          &lt;td&gt;g_i&lt;/td&gt;
          &lt;td&gt;^{q-1}\(where\)1/p + 1/q = 1\(; over a trace-norm ball, it returns\)-t u_1 v_1^\top\(from the top singular vectors of\)\nabla f(X)$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step-Size Decay and Non-Monotonicity:&lt;/strong&gt; With the canonical open-loop schedule \(\gamma_k = \frac{2}{k+1}\), Frank–Wolfe requires no knowledge of the Lipschitz constant \(L\), though unlike exact line search it is not strictly monotone at every step.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-frankwolfe-lmo-for-ell_1-vs-trace-norm-constraints&quot;&gt;Worked example: Frank–Wolfe LMO for \(\ell_1\) vs. Trace-Norm Constraints&lt;/h3&gt;

&lt;p&gt;Suppose we want one Frank–Wolfe direction on two canonical norm balls with radius \(t = 2\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part A (\(\ell_1\) ball in \(\mathbb{R}^3\)):&lt;/strong&gt; Let \(g = \nabla f(x^{(0)}) = (1.5,\ -4.0,\ 2.5)^\top\) with \(x^{(0)} = (0, 0, 0)^\top\) and \(\gamma_1 = \frac{2}{1+1} = 1\) (or \(\gamma_1 = 0.5\) for a partial step).&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Find the dual \(\ell_\infty\) maximizer: $$i^\star = \arg\max_i&lt;/td&gt;
          &lt;td&gt;g_i&lt;/td&gt;
          &lt;td&gt;= 2\(since\)&lt;/td&gt;
          &lt;td&gt;-4.0&lt;/td&gt;
          &lt;td&gt;= 4.0$$ is largest.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;Form the LMO atom: \(s^{(0)} = -\operatorname{sign}(g_2)\cdot t \cdot e_2 = -(-1)\cdot 2 \cdot (0, 1, 0)^\top = (0, 2, 0)^\top\).&lt;/li&gt;
  &lt;li&gt;Verify the linear objective: \(\langle g, s^{(0)} \rangle = (-4.0)(2) = -8.0 = -t \|g\|_\infty\).&lt;/li&gt;
  &lt;li&gt;Update with \(\gamma = 0.5\): \(x^{(1)} = 0.5 x^{(0)} + 0.5 s^{(0)} = (0, 1, 0)^\top\), which is 1-sparse and satisfies \(\|x^{(1)}\|_1 = 1 \le 2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Part B (Trace-norm ball in \(\mathbb{R}^{2 \times 2}\)):&lt;/strong&gt; Let the matrix gradient be diagonal \(G = \begin{pmatrix} -3 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}\) with trace-norm budget \(t = 2\).&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;The singular values of \(G\) are \(\sigma_1 = 3\) (with \(u_1 = (1, 0)^\top\), \(v_1 = (-1, 0)^\top\) because \(G v_1 = (3, 0)^\top = 3 u_1\)) and \(\sigma_2 = 1\).&lt;/li&gt;
  &lt;li&gt;The LMO atom is the rank-1 matrix \(S = -t u_1 v_1^\top = -2 \begin{pmatrix} 1 \\ 0 \end{pmatrix} \begin{pmatrix} -1 &amp;amp; 0 \end{pmatrix} = \begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{pmatrix}\).&lt;/li&gt;
  &lt;li&gt;Verify: \(\langle G, S \rangle = \operatorname{tr}(G^\top S) = (-3)(2) + (1)(0) = -6 = -t \|G\|_{\text{op}}\), and \(\|S\|_{\text{tr}} = 2 \le t\), obtained without ever computing a full SVD.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;projected-gradient-descent&quot;&gt;Projected Gradient Descent&lt;/h2&gt;

&lt;p&gt;Let’s consider a problem with the following constraints.&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} f(x) \qquad \text{ subject to } x \in C\]
&lt;/blockquote&gt;

&lt;p&gt;We previously saw that if \(f\) is convex and smooth, and \(C\) is also convex, we can use the &lt;strong&gt;projected gradient descent&lt;/strong&gt; method. When \(P_{C}\) is the projection operator for set \(C\), for the chosen initial value \(x^{(0)}\) and \(k = 1, 2, 3, ...\), the following equation holds.&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = P_{C} \bigl( x^{(k−1)} − t_k\nabla f(x^{(k−1)}) \bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;Projected Gradient Descent can also be represented as a special case of proximal gradient descent, which is essentially motivated by the fact that the \(y\) value in the local quadratic expansion (2nd Taylor Expansion) becomes the next \(x^{(k)}\).&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = P_{C} \Bigl( \arg\min_{y} \nabla f(x^{(k−1)})^T(y − x^{(k−1)}) + \frac{1}{2t} \| y − x^{(k−1)} \|^2_2 \Bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;For more detailed information about Projected Gradient Descent, please reference &lt;a href=&quot;/contents/en/chapter09/09_04_special_cases/&quot;&gt;9-4&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;conditional-gradient-frank-wolfe-method&quot;&gt;Conditional gradient (Frank-Wolfe) method&lt;/h2&gt;

&lt;p&gt;Instead of minimizing the quadratic approximation here, let’s try something simpler. First, find the point \(s\) of the set \(C\) that minimizes the inner product with \(\nabla f(x)\), i.e. minimize the linear function \(\nabla f(x)^T s\) over \(C\). Instead of a projection, we solve this simpler linear problem over \(C\). We then move to a convex combination of the current point and this minimizer, choosing the weight by line search or a fixed rule.&lt;/p&gt;

&lt;p&gt;Let’s look at the following formalized method. Choose initial value \(x^{(0)} \in C\). For \(k = 1, 2, 3, ...\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{array}{rcl}
s^{(k−1)} &amp;amp; \in &amp;amp; \arg\min_{s \in C} \nabla f(x^{(k−1)})^Ts \\
x^{(k)} &amp;amp; = &amp;amp; (1 − \gamma_k)x^{(k−1)} + \gamma_ks^{(k−1)}
\end{array}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;reference&quot;&gt;[Reference]&lt;/h3&gt;

&lt;blockquote&gt;
\[f(y) \approx f(x) + \nabla f(x)(y-x)\]

\[\arg\min_y f(x) + \nabla f(x)(y-x) \equiv \arg\min_y \nabla f(x)y\]
&lt;/blockquote&gt;

&lt;p&gt;Here, unlike before, when updating without going through the projection process, we solve the problem using points in the constraint set \(C\). Basically, the step size is set as \(\gamma_k = \frac{2}{k + 1}, k = 1, 2, 3, ...\) For any \(0 \leq \gamma_k \leq 1\), by convexity, \(x^{(k)} \in C\) is guaranteed. Also, the update proceeds with the following equation:&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = x^{(k−1)} + \gamma_k\bigl( s^{(k−1)} − x^{(k−1)} \bigr)\]
&lt;/blockquote&gt;

&lt;p&gt;That is, as the algorithm is performed, we move gradually less in the direction of the linear minimizer. In many cases, minimizing a linear function over \(C\) is much cheaper than projecting onto \(C\). For example, over the \(\ell_1\) ball the linear minimizer \(s^{(k-1)}\) is simply a signed coordinate vector, so each step changes the iterate in a single coordinate direction, whereas the Euclidean projection onto the \(\ell_1\) ball requires more work.&lt;/p&gt;

&lt;h3 id=&quot;reference-1&quot;&gt;[Reference]&lt;/h3&gt;

&lt;p&gt;An interesting fact is that Frank and Wolfe were post-docs working together with Tucker. They first proposed the algorithm in 1956 for quadratic programs. For a long time after that, no follow-up papers on this topic came out. However, in recent years, it has gained attention again through Jaggi’s insights and has been reintroduced to the world.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter22/frank_wolfe.png&quot; alt=&quot;[Fig 1] Conditional Gradient (Frank-Wolfe) method (From Jaggi 2011)[3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Conditional Gradient (Frank-Wolfe) method (From Jaggi 2011)[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;norm-constraints&quot;&gt;Norm constraints&lt;/h2&gt;

&lt;p&gt;What happens when \(C = \{x : \| x \| \leq t \}\) for norm \(\| \cdot \|\)? Let’s look at the following:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
s &amp;amp;\in \arg\min_{\|s\|\leq t} \nabla f(x^{(k−1)})^Ts \\
&amp;amp;= −t \cdot \arg\max_{\|s\|\leq 1} \nabla f(x^{(k−1)})^Ts \\
&amp;amp;= −t \cdot \partial \| \nabla f(x^{(k−1)}) \|_{*}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(\| \cdot \|_{*}\) is the dual norm. In other words, if we know how to compute the subgradient of the dual norm, we can easily perform the Frank-Wolfe step. The key of Frank-Wolfe is that for \(C = \{x : \| x \| \leq t \}\), it can be obtained more simply or at lower cost than using the projection method, and also requires simpler or lower cost than the prox operator of \(\| \cdot \|\).&lt;/p&gt;

&lt;h2 id=&quot;example-l_1-regularization&quot;&gt;Example: \(l_1\) regularization&lt;/h2&gt;

&lt;p&gt;The following is &lt;strong&gt;\(l_1\)-regularized&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) \qquad \text{ subject to } \| x \|_1 \leq t\]
&lt;/blockquote&gt;

&lt;p&gt;Expanding according to the previous formula, we get \(s^{(k−1)} \in −t\partial \|\nabla f(x^{(k−1)}) \|_\infty\). The Frank-Wolfe method updates through the following process:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{array}{rcl}
i_{k−1} &amp;amp; \in &amp;amp; \arg\max_{i=1,...,p} |\nabla_i f(x^{(k−1)})| \\
x^{(k)} &amp;amp; = &amp;amp; (1 − \gamma_k)x^{(k−1)} − \gamma_kt \cdot \text{sign}(\nabla_{i_{k−1}} f(x^{(k−1)})) \cdot e_{i_{k−1}}
\end{array}\]
&lt;/blockquote&gt;

&lt;p&gt;This is a type of coordinate descent (we will look at coordinate descent in detail later).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Both require \(O(n)\) complexity, but projecting onto the \(l_1\) ball is much simpler.&lt;/p&gt;

&lt;h2 id=&quot;example-l_p-regularization&quot;&gt;Example: \(l_p\) regularization&lt;/h2&gt;

&lt;p&gt;The following is an \(l_p\)-regularized problem:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} f(x) \qquad \text{ subject to } \| x \|_{p} \leq t\]
&lt;/blockquote&gt;

&lt;p&gt;When \(1 \leq p \leq \infty\) and \(q\) is the dual of \(p\), we have \(s^{(k−1)} \in −t\partial \| \nabla f(x^{(k−1)}) \|_{q}\). That is, \(1/p + 1/q = 1\). We can choose as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[s_i^{(k−1)} = −\alpha \cdot \text{sign}(\nabla f_i(x^{(k−1)})) \cdot \left| \nabla f_i(x^{(k−1)}) \right|^{q-1}, \quad i = 1, ..., n\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(\alpha\) is a constant such that \(\| s^{(k-1)} \|_{p} = t\), and the Frank-Wolfe update is the same.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: For general \(p\) cases, &lt;strong&gt;projecting onto the p Ball&lt;/strong&gt; is much simpler. Except for special cases (\(p = 1, 2, \infty\)), such projections cannot be computed directly (must be processed by optimization).&lt;/p&gt;

&lt;h2 id=&quot;example-trace-norm-regularization&quot;&gt;Example: trace norm regularization&lt;/h2&gt;

&lt;p&gt;Let’s look at the &lt;strong&gt;trace-regularized&lt;/strong&gt; problem:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{X} f(X) \qquad \text{ subject to } \| X \|_{tr} \leq t\]
&lt;/blockquote&gt;

&lt;p&gt;We have \(S^{(k−1)} \in −t \cdot \partial\| \nabla f(X^{(k−1)}) \|_{op}\). We can choose \(S^{(k−1)}\) as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[S^{(k−1)} = −t \cdot uv^T\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(u, v\) are the left and right singular vectors of \(\nabla f(X^{(k−1)})\), and the Frank-Wolfe update is the same as usual.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This method, if singular value decomposition (SVD) is possible, is much simpler and more efficient than &lt;strong&gt;projecting onto the trace norm ball&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;constrained-and-lagrange-forms&quot;&gt;Constrained and Lagrange forms&lt;/h2&gt;

&lt;p&gt;Let’s look at the constrained problem once more:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) \qquad \text{ subject to } \| x \| \leq t\]
&lt;/blockquote&gt;

&lt;p&gt;The following Lagrange problem is equivalent to the above equation:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_x f(x) + \lambda \| x \|\]
&lt;/blockquote&gt;

&lt;p&gt;The tuning parameters \(t\) and \(\lambda\) vary in the interval \([0,\infty]\). Also, we should compare the Frank-Wolfe update of \(\| \cdot \|\) with the proximal operator of \(\| \cdot \|\).&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;\(l_1\) norm&lt;/strong&gt;: The Frank-Wolfe method updates by scanning the maximum value of the gradient. The proximal operator updates while performing soft-thresholding. Both steps use \(O(n)\) flops.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;\(l_p\) norm&lt;/strong&gt;: The Frank-Wolfe update raises each item of the gradient to a power and sums them all, increasing by \(O(n)\) flops. The proximal operator generally cannot be computed directly.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Trace norm&lt;/strong&gt;: The Frank-Wolfe update computes only the left and right singular vectors of the gradient. The proximal operator soft-thresholds the singular values of the gradient step by step, requiring singular value decomposition (SVD).&lt;/p&gt;

&lt;p&gt;Many different regularizers have derived efficient Frank-Wolfe updates. For example, special polyhedra or cone constraints, sum-of-norms (group-based) regularization, atomic norms, etc.&lt;/p&gt;

&lt;p&gt;When comparing the performance of projected gradient technique and conditional gradient technique for Constrained Lasso (here \(n=100, p = 500\)):&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter22/comparing_projected_and_conditional_gradient.png&quot; alt=&quot;[Fig 2] Comparing projected and conditional gradient for constrained lasso problem [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 2] Comparing projected and conditional gradient for constrained lasso problem [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;We can see that the Frank-Wolfe method has a convergence rate similar to first-order methods. However, it can actually be slower to converge to high accuracy. (Reference: Here we use fixed step size, but using line search can improve convergence speed.)&lt;/p&gt;

&lt;h2 id=&quot;duality-gap&quot;&gt;Duality gap&lt;/h2&gt;

&lt;p&gt;In the Frank-Wolfe iteration process, a duality gap naturally occurs, which actually means the suboptimality gap.&lt;/p&gt;

&lt;blockquote&gt;
\[g(x^{(k-1)}) := \max_{s\in C} \nabla f(x^{(k−1)})^T(x^{(k−1)} − s)\]
&lt;/blockquote&gt;

&lt;p&gt;This is an upper bound of \(f(x^{(k−1)}) − f^{*}\).&lt;/p&gt;

&lt;h3 id=&quot;proof&quot;&gt;[Proof]&lt;/h3&gt;

&lt;p&gt;We can prove using the first-order condition of convexity:&lt;/p&gt;

&lt;blockquote&gt;
\[f(s) \geq f(x^{(k−1)}) + \nabla f(x^{(k−1)})^T(s − x^{(k−1)})\]
&lt;/blockquote&gt;

&lt;p&gt;Minimize both sides for all \(s \in C\):&lt;/p&gt;

&lt;blockquote&gt;
\[f^{*} \geq f(x^{(k−1)}) + \min_{s\in C} \nabla f(x^{(k−1)})^T(s − x^{(k−1)})\]
&lt;/blockquote&gt;

&lt;p&gt;Finally, rearranging shows that the following equation is an upper bound of the duality gap:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_{s\in C} \nabla f(x^{(k−1)})^T(x^{(k−1)} − s) = \nabla f(x^{(k−1)})^T(x^{(k−1)} − s^{(k−1)})\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;note&quot;&gt;[Note]&lt;/h3&gt;

&lt;p&gt;Therefore, this quantity comes directly from the Frank-Wolfe update. Why do we call this a “duality gap”? We can rewrite the original problem as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} f(x) + I_C(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(I_C\) means the indicator function of \(C\). The dual problem is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\max_u −f^{*}(u) − I^{*}_C(−u)\]
&lt;/blockquote&gt;

&lt;p&gt;\(I_C^{*}\) means the support function of \(C\). We saw earlier that the conjugate of the indicator function becomes the support function.&lt;/p&gt;

&lt;h3 id=&quot;recall&quot;&gt;[Recall]&lt;/h3&gt;

&lt;blockquote&gt;
\[I_C(x) = \begin{cases}
+\infty &amp;amp; \text{if } x \notin C \\
0 &amp;amp; \text{if } x \in C
\end{cases}\]

\[\begin{align}
I_C^{*} &amp;amp;= \max_{x} \{\langle s, x \rangle - I_C(x)\} \\
&amp;amp;= \max_{x \in C} \langle s, x \rangle \\
&amp;amp;= \text{Support function of } C \text{ at } s
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;When \(x = x^{(k-1)}, u = \nabla f(x^{(k-1)})\), the duality gap occurring at \(x, u\) is as follows (derived from 13-04 &lt;a href=&quot;/contents/en/chapter13/13_04_Conjugate_function/&quot;&gt;Fenchel’s inequality&lt;/a&gt;):&lt;/p&gt;

&lt;blockquote&gt;
\[f(x) + f^{*}(u) + I^{*}_C(−u) \geq x^Tu + I^{*}_C(−u)\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;frank-wolfe-step-toward-a-vertex-no-projection-video&quot;&gt;Frank-Wolfe: step toward a vertex, no projection (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/frank-wolfe_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Each step picks the vertex \(s\) that minimises \(\langle \nabla f(x), s\rangle\) and moves to \((1-\gamma_k)x + \gamma_k s\), so the iterate never leaves \(C\).&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-frank-wolfe-steps&quot;&gt;Try it yourself: Frank-Wolfe steps&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;fw&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>22-01 Last time: ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_01_Last_time_ADMM/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter22/22_01_Last_time_ADMM</id>
   <content type="html">&lt;p&gt;Before stepping into projection-free optimization, it pays to pause and look back at the bridge we just crossed: the Alternating Direction Method of Multipliers (ADMM). In large-scale statistical learning, we routinely face composite objectives \(f(x) + g(z)\) coupled by linear constraints \(Ax + Bz = c\) where neither proximal operator alone can handle the coupled system. ADMM splits the problem cleanly into separate \(x\)- and \(z\)-subproblems linked by a dual price vector—setting the exact contrast against Frank–Wolfe, which avoids proximal/projection steps altogether in favor of linear oracles.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-foundations-of-admm-and-scaled-dual-form&quot;&gt;Key ideas: Foundations of ADMM and Scaled Dual Form&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Augmented Lagrangian Regularization:&lt;/strong&gt; Adding the quadratic penalty \(\frac{\rho}{2}\|Ax + Bz - c\|_2^2\) to the ordinary Lagrangian improves conditioning and ensures dual differentiability even when \(f\) or \(g\) is not strictly convex, without altering the primal optimal value on the feasible set \(Ax + Bz = c\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gauss–Seidel Alternating Minimization:&lt;/strong&gt; Rather than minimizing \(L_\rho(x, z, u)\) jointly over \((x, z)\) (which destroys separability), ADMM updates \(x\) first with \(z\) fixed, then updates \(z\) using the freshest \(x^{(k)}\), exploiting block structure while preserving convergence under mild convexity assumptions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Ascent as Price Adjustment:&lt;/strong&gt; The update \(u^{(k)} = u^{(k-1)} + \rho(Ax^{(k)} + Bz^{(k)} - c)\) uses the primal residual as a gradient ascent step on the dual problem, with step size \(\rho\) matching the augmentation parameter so that dual feasibility holds automatically at each \(z\)-update.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaled Form Economy:&lt;/strong&gt; Defining the scaled dual variable \(w = u / \rho\) absorbs the linear term \(u^\top(Ax + Bz - c)\) into a single completed square \(\frac{\rho}{2}\|Ax + Bz - c + w\|_2^2\), turning both primal updates into standard proximal operators and simplifying implementation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-scaled-admm-iteration-on-a-splitting-problem&quot;&gt;Worked example: One Scaled ADMM Iteration on a Splitting Problem&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider the 1D consensus-regularized problem $$\min_{x, z \in \mathbb{R}} \frac{1}{2}(x - 4)^2 +&lt;/td&gt;
      &lt;td&gt;z&lt;/td&gt;
      &lt;td&gt;\(subject to\)x - z = 0\((so\)A = 1\(,\)B = -1\(,\)c = 0\(). Choose\)\rho = 1\(and initialize\)z^{(0)} = 0\(,\)w^{(0)} = 0$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Exact optimum for reference:&lt;/strong&gt; Since \(x = z\), minimizing $$\frac{1}{2}(x - 4)^2 +&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;\(gives\)x^\star = z^\star = \operatorname{soft}(4, 1) = 3$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaled \(x\)-update (quadratic minimization):&lt;/strong&gt;
\(x^{(1)} = \arg\min_x \left\{\frac{1}{2}(x - 4)^2 + \frac{1}{2}(x - z^{(0)} + w^{(0)})^2\right\} = \arg\min_x \left\{\frac{1}{2}(x - 4)^2 + \frac{1}{2}x^2\right\}.\)
Setting the derivative \((x - 4) + x = 0\) yields \(x^{(1)} = 2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaled \(z\)-update (proximal soft-thresholding):&lt;/strong&gt;
\(z^{(1)} = \arg\min_z \left\{|z| + \frac{1}{2}(x^{(1)} - z + w^{(0)})^2\right\} = \operatorname{soft}(x^{(1)} + w^{(0)},\ 1/\rho) = \operatorname{soft}(2, 1) = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaled dual update (running sum of residuals):&lt;/strong&gt;
\(w^{(1)} = w^{(0)} + (x^{(1)} - z^{(1)}) = 0 + (2 - 1) = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the second iteration to see convergence in action:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(2)} = \frac{4 + (z^{(1)} - w^{(1)})}{2} = \frac{4 + (1 - 1)}{2} = 2\),&lt;/li&gt;
      &lt;li&gt;\(z^{(2)} = \operatorname{soft}(x^{(2)} + w^{(1)}, 1) = \operatorname{soft}(2 + 1, 1) = 2\),&lt;/li&gt;
      &lt;li&gt;\(w^{(2)} = w^{(1)} + (x^{(2)} - z^{(2)}) = 1 + 0 = 1\).
Notice how the primal residual \(r^{(2)} = x^{(2)} - z^{(2)} = 0\) vanishes while \(w\) steadily accumulates the dual subgradient needed to push both variables toward \(3\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;last-time-admm&quot;&gt;Last time: ADMM&lt;/h2&gt;
&lt;p&gt;Let’s consider the following optimization problem&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x,z} &amp;amp;&amp;amp;f(x) + g(z)\\\\
&amp;amp;\text{ subject to } &amp;amp;&amp;amp;Ax + Bz = c 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Converting this to Augmented Lagrangian form gives us the following. (for some \(ρ &amp;gt; 0\))&lt;/p&gt;
&lt;blockquote&gt;
\[L_ρ(x, z, u) = f(x) + g(z) + u^T(Ax + Bz − c) + \frac{ρ}{2} \| Ax + Bz − c \|^2_2\]
&lt;/blockquote&gt;

&lt;p&gt;The above equation becomes Strongly Convex with the addition of \(\frac{ρ}{2} \| Ax + Bz − c \|^2_2\), and this can be transformed into a form useful for parallel processing as shown in the following equation.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;For detailed proof, please refer to the content of the previous chapter.
ADMM: for \(k = 1, 2, 3, . . .\)
    &lt;blockquote&gt;
      &lt;p&gt;\(x^{(k)} = argmin_{x} L_ρ(x, z^{(k−1)}, u^{(k−1)})\)
\(z^{(k)} = argmin_{z} L_ρ(x^{(k)}  , z, u^{(k−1)})\)
\(u^{(k)} = u^{(k−1)} + ρ(Ax^{(k)} + Bz^{(k)} − c)\)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;admm-in-scaled-form&quot;&gt;ADMM in scaled form&lt;/h2&gt;
&lt;p&gt;Let’s change the dual variable \(u\) to the scaled variable \(w = u/ρ\). Here, the ADMM step can be computed as follows.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x^{(k)} = argmin_{x} f(x) + \frac{ρ}{2} \| Ax + Bz^{(k−1)} − c + w^{(k−1)} \|^2_2\)
\(z^{(k)} = argmin_{z} g(z) + \frac{ρ}{2} \| Ax^{(k)} + Bz − c + w^{(k−1)} \|^2_2\) 
\(w^{(k)} = w^{(k−1)} + Ax^{(k)} + Bz^{(k)} − c\)&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>15 Barrier Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_barrier_method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_barrier_method</id>
   <content type="html">&lt;p&gt;Newton’s method conquers smooth unconstrained and equality-constrained problems in a handful of steps—but the moment you add a single inequality constraint \(h_i(x) \le 0\), the optimum usually sits on a sharp corner of the feasible set where derivatives break down and you don’t know which constraints are active. The &lt;strong&gt;Barrier Method&lt;/strong&gt; sidesteps the combinatorial boundary nightmare completely: it erects an invisible, infinitely smooth repulsive force field along every wall \(h_i(x) = 0\) and glides straight through the &lt;em&gt;interior&lt;/em&gt; to the optimal corner.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-architecture-of-interior-point-barrier-methods&quot;&gt;Key ideas: The Architecture of Interior-Point Barrier Methods&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Smooth Interiorization via Log Barriers:&lt;/strong&gt; Replacing the hard indicator \(I_C(x)\) with \(\frac{1}{t}\phi(x) = -\frac{1}{t}\sum_{i=1}^m \log(-h_i(x))\) converts inequality constraints into a smooth equality-constrained problem solvable by Newton’s method.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — The Central Path &amp;amp; Perturbed KKT:&lt;/strong&gt; As \(t\) grows from small to large, the barrier minimizers \(x^*(t)\) trace a smooth curve called the &lt;strong&gt;central path&lt;/strong&gt;, automatically producing strictly feasible dual multipliers \(u_i(t) = -1/(t h_i(x^*(t)))\) satisfying \(u_i(t)h_i(x^*(t)) = -1/t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Exact \(m/t\) Suboptimality Certificate:&lt;/strong&gt; Every central-path point \(x^*(t)\) is guaranteed to satisfy \(f(x^*(t)) - f^\star \le m/t\), giving an exact stopping rule that depends only on the number of inequalities \(m\) and \(t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Path-Following &amp;amp; Phase-I Feasibility:&lt;/strong&gt; Increasing \(t \leftarrow \mu t\) with warm-started Newton centering steps achieves polynomial-time convergence—once a Phase-I feasibility problem hands us a strictly feasible starting point.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-watching-the-barrier-push-a-solution-to-the-boundary&quot;&gt;Worked example: Watching the Barrier Push a Solution to the Boundary&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = x\) subject to \(x \ge 0\) (so \(m = 1\), \(h_1(x) = -x \le 0\), true optimum \(x^\star = 0\), \(f^\star = 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the barrier objective for parameter \(t &amp;gt; 0\):&lt;/strong&gt;
\(\min_{x &amp;gt; 0} \; t x - \log(x).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the optimality condition exactly:&lt;/strong&gt;
\(\frac{d}{dx}(tx - \log x) = t - \frac{1}{x} = 0 \implies x^*(t) = \frac{1}{t}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trace the central path as \(t\) increases (\(\mu = 10\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(t = 1 \implies x^*(1) = 1.0\), gap \(f(x^*(1)) - f^\star = 1.0 = \frac{1}{1}\).&lt;/li&gt;
      &lt;li&gt;\(t = 10 \implies x^*(10) = 0.1\), gap \(= 0.1 = \frac{1}{10}\).&lt;/li&gt;
      &lt;li&gt;\(t = 1000 \implies x^*(1000) = 0.001\), gap \(= 0.001 = \frac{1}{1000}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Notice the exact \(m/t\) bound:&lt;/strong&gt; Here \(m = 1\) and \(f(x^*(t)) - f^\star = \frac{1}{t} = \frac{m}{t}\) with exact equality!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we will look at one of the 2nd-order methods, the &lt;strong&gt;Barrier Method&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Barrier Method&lt;/strong&gt; is a technique for solving &lt;strong&gt;inequality constraint and equality constrained smooth problems&lt;/strong&gt;, which are considered the most difficult among 2nd-order method problems.&lt;/p&gt;

&lt;p&gt;(For reference, using the gradient to solve an optimization problem is called a 1st-order method, and using the Hessian is called a 2nd-order method.)&lt;/p&gt;

&lt;h2 id=&quot;references-and-further-readings&quot;&gt;References and further readings&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;S. Boyd and L. Vandenberghe (2004), “Convex optimization”, Chapter 11&lt;/li&gt;
  &lt;li&gt;A. Nemirovski (2004), “Interior-point polynomial time methods in convex programming”, Chapter 4&lt;/li&gt;
  &lt;li&gt;J. Nocedal and S. Wright (2006), “Numerical optimization”, Chapters 14 and 19&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>15-11 Practical Exercises - Barrier Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_11_Practical_Exercises_Barrier_Method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_11_Practical_Exercises_Barrier_Method</id>
   <content type="html">&lt;p&gt;Working through barrier-method exercises by hand builds deep intuition for what modern solvers like Clarabel do inside every iteration: computing exact barrier gradients and Hessians, deriving closed-form central paths on small LPs and QPs, verifying the \(m/t\) duality gap, and formulating Phase I feasibility problems. Keep this four-pillar playbook handy as you solve the exercises below.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-exercise-solving-playbook-for-chapter-15&quot;&gt;Key ideas: Exercise-Solving Playbook for Chapter 15&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Sign Hygiene in \(\phi(x)\):&lt;/strong&gt; Always rewrite every inequality in the canonical form \(h_i(x) \le 0\) first (so \(-h_i(x) &amp;gt; 0\) inside the logarithm!). For example, \(x \ge a\) becomes \(h(x) = a - x \le 0\), giving \(-\log(x - a)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Computing Central Paths Analytically:&lt;/strong&gt; Set \(t\nabla f(x) + \nabla\phi(x) = 0\), clear denominators to obtain a polynomial equation, and select the unique root lying strictly inside the feasible domain \(h_i(x) &amp;lt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Dual Variable &amp;amp; Gap Verification:&lt;/strong&gt; After finding \(x^*(t)\), always compute \(u_i(t) = -\frac{1}{t h_i(x^*(t))}\) and check both stationarity and \(f(x^*(t)) - f^\star \le \frac{m}{t}\) as a built-in algebraic error detector.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Newton Step Inside the Barrier:&lt;/strong&gt; Remember to include &lt;strong&gt;both&lt;/strong&gt; \(t\nabla^2 f(x)\) and \(\nabla^2 \phi(x)\) in the Hessian of the centering problem, and never let a trial step jump outside \(h_i(x + tv) &amp;lt; 0\) during backtracking.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-full-centering-newton-step-on-a-barrier-problem&quot;&gt;Worked example: One Full Centering Newton Step on a Barrier Problem&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = 2x\) subject to \(x \ge 1\) (\(h_1(x) = 1 - x \le 0\)) using the barrier problem \(\Phi_t(x) = 2tx - \log(x - 1)\) at \(t = 1\), starting from the strictly feasible point \(x^{(0)} = 2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute exact central-path target (for reference):&lt;/strong&gt;
\(\Phi_1&apos;(x) = 2 - \frac{1}{x - 1} = 0 \implies x^*(1) = 1.5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute gradient and Hessian of \(\Phi_1(x)\) at \(x^{(0)} = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\Phi_1&apos;(2) = 2 - \frac{1}{2 - 1} = 1\).&lt;/li&gt;
      &lt;li&gt;\(\Phi_1&apos;&apos;(2) = \frac{1}{(2 - 1)^2} = 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the pure Newton step:&lt;/strong&gt;
\(\Delta x_{\text{nt}} = -\frac{\Phi_1&apos;(2)}{\Phi_1&apos;&apos;(2)} = -\frac{1}{1} = -1 \implies x^{(0)} + \Delta x_{\text{nt}} = 2 - 1 = 1!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Domain-safety catch!&lt;/strong&gt; Notice \(x = 1\) lands right on the boundary where \(\log(x - 1) = -\infty\)! Backtracking immediately halves \(t_{\text{step}} = 0.5\):
\(x^{(1)} = 2 + 0.5(-1) = 1.5 = x^*(1)!\)
This tiny example illustrates &lt;em&gt;both&lt;/em&gt; why domain-checking in backtracking is mandatory and how rapidly Newton centers once inside the domain.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---the-barrier-method&quot;&gt;Practical Exercises - The Barrier Method&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd &amp;amp; Vandenberghe (2004), Nocedal &amp;amp; Wright (2006), and Nesterov (2004).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-i-the-log-barrier-function&quot;&gt;📝 &lt;strong&gt;Part I: The Log-Barrier Function&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-1-computing-the-log-barrier-boyd--vandenberghe-ex-111&quot;&gt;&lt;strong&gt;Exercise 1: Computing the Log-Barrier (Boyd &amp;amp; Vandenberghe, Ex. 11.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the problem:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; f(x) \\
\text{s.t.} \quad &amp;amp; h_i(x) \leq 0, \quad i = 1, \ldots, m
\end{align}\]

&lt;p&gt;Log-barrier function:&lt;/p&gt;

\[\phi(x) = -\sum_{i=1}^m \log(-h_i(x))\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Compute \(\nabla \phi(x)\) and \(\nabla^2 \phi(x)\)&lt;br /&gt;
b) Let \(f(x) = x^2\), \(h_1(x) = x - 1\), \(h_2(x) = -x - 1\) (i.e. \(-1 \leq x \leq 1\)). Compute \(\phi(x)\), \(\nabla \phi(x)\), \(\nabla^2 \phi(x)\)&lt;br /&gt;
c) Evaluate the quantities above at \(x = 0\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Gradient and Hessian of $$\phi(x)$$:**

**Gradient:**

$$
\nabla \phi(x) = -\sum_{i=1}^m \frac{1}{-h_i(x)} \nabla h_i(x) = \sum_{i=1}^m \frac{\nabla h_i(x)}{-h_i(x)}
$$

**Hessian:**

$$
\nabla^2 \phi(x) = \sum_{i=1}^m \left( \frac{\nabla^2 h_i(x)}{-h_i(x)} + \frac{\nabla h_i(x) \nabla h_i(x)^T}{h_i(x)^2} \right)
$$

---

**b) A concrete example:**

$$
f(x) = x^2, \quad h_1(x) = x - 1, \quad h_2(x) = -x - 1
$$

**Barrier function:**

$$
\phi(x) = -\log(-(x-1)) - \log(-(-x-1)) = -\log(1-x) - \log(1+x)
$$

**Gradient:**

$$
\nabla h_1(x) = 1, \quad \nabla h_2(x) = -1
$$

$$
\nabla \phi(x) = \frac{1}{1-x} + \frac{-1}{1+x} = \frac{1+x-(1-x)}{(1-x)(1+x)} = \frac{2x}{1-x^2}
$$

**Hessian:**

$$
\nabla^2 h_1(x) = 0, \quad \nabla^2 h_2(x) = 0
$$

$$
\nabla^2 \phi(x) = \frac{1}{(1-x)^2} + \frac{1}{(1+x)^2}
$$

$$
= \frac{(1+x)^2 + (1-x)^2}{(1-x^2)^2} = \frac{2(1+x^2)}{(1-x^2)^2}
$$

---

**c) At $$x = 0$$:**

$$
\phi(0) = -\log(1) - \log(1) = 0
$$

$$
\nabla \phi(0) = \frac{0}{1} = 0
$$

$$
\nabla^2 \phi(0) = \frac{2 \cdot 1}{1} = 2
$$

**Explanation:** At the center of the feasible region ($$x=0$$), the barrier function attains its minimum and the gradient is 0.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-2-central-path-boyd--vandenberghe-ex-112&quot;&gt;&lt;strong&gt;Exercise 2: Central Path (Boyd &amp;amp; Vandenberghe, Ex. 11.2)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Continuing Exercise 1, consider the barrier problem:&lt;/p&gt;

\[\min_x \quad t f(x) + \phi(x) = t x^2 - \log(1-x) - \log(1+x)\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Find the first-order condition (FOC)&lt;br /&gt;
b) Solve the FOC to find \(x^*(t)\) (a central path point)&lt;br /&gt;
c) Compute \(x^*(1)\), \(x^*(10)\), \(x^*(100)\)&lt;br /&gt;
d) What is \(x^*(t)\) as \(t \to \infty\)?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) FOC:**

$$
\frac{d}{dx}\left( t x^2 - \log(1-x) - \log(1+x) \right) = 0
$$

$$
2tx + \frac{1}{1-x} - \frac{1}{1+x} = 0
$$

$$
2tx + \frac{2x}{1-x^2} = 0
$$

$$
x\left( 2t + \frac{2}{1-x^2} \right) = 0
$$

**Two cases:**
1. $$x = 0$$ (always a solution, by symmetry)
2. $$2t + \frac{2}{1-x^2} = 0$$ (no real solution since the left-hand side is &amp;gt; 0)

**Conclusion:** $$x^*(t) = 0$$ for all $$t &amp;gt; 0$$.

---

**b) Explanation:**

Since $$f(x) = x^2$$ is symmetric about $$x=0$$ and the feasible region $$(-1, 1)$$ is also symmetric, the central path is $$x^*(t) = 0$$ for every $$t$$.

---

**c) Values:**

$$
x^*(1) = 0, \quad x^*(10) = 0, \quad x^*(100) = 0
$$

---

**d) Limit:**

$$
\lim_{t \to \infty} x^*(t) = 0
$$

This is exactly the solution of the original problem: $$\min_{-1 \leq x \leq 1} x^2 = 0$$ at $$x = 0$$.

**Note:** This is a special case. Normally, the central path moves as $$t$$ increases.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-ii-central-path-analysis&quot;&gt;📝 &lt;strong&gt;Part II: Central Path Analysis&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-3-central-path-for-an-lp-nocedal--wright-ex-141&quot;&gt;&lt;strong&gt;Exercise 3: Central Path for an LP (Nocedal &amp;amp; Wright, Ex. 14.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the LP:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; c^T x \\
\text{s.t.} \quad &amp;amp; Ax = b \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;With \(c = \begin{bmatrix} -1 \\ -1 \end{bmatrix}\), \(A = \begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix}\), \(b = 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the barrier problem&lt;br /&gt;
b) Find the central path \(x^*(t)\)&lt;br /&gt;
c) Compute \(\lim_{t \to \infty} x^*(t)\)&lt;br /&gt;
d) Compare with the primal-dual solution&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Barrier problem:**

$$
\min_x \quad t c^T x - \sum_{i=1}^2 \log x_i \quad \text{s.t.} \quad x_1 + x_2 = 1
$$

$$
= \min_x \quad -t(x_1 + x_2) - \log x_1 - \log x_2 \quad \text{s.t.} \quad x_1 + x_2 = 1
$$

---

**b) Find the central path:**

**Lagrangian:**

$$
L(x, \nu) = -t(x_1 + x_2) - \log x_1 - \log x_2 - \nu(x_1 + x_2 - 1)
$$

**FOC:**

$$
\frac{\partial L}{\partial x_1} = -t - \frac{1}{x_1} - \nu = 0 \Rightarrow \frac{1}{x_1} = -t - \nu
$$

$$
\frac{\partial L}{\partial x_2} = -t - \frac{1}{x_2} - \nu = 0 \Rightarrow \frac{1}{x_2} = -t - \nu
$$

From the two equations → $$x_1 = x_2$$.

From $$x_1 + x_2 = 1$$: $$x_1 = x_2 = 0.5$$.

**Central path:**

$$
x^*(t) = \begin{bmatrix} 0.5 \\ 0.5 \end{bmatrix} \quad \forall t &amp;gt; 0
$$

**Dual variable:**

$$
\frac{1}{0.5} = -t - \nu \Rightarrow \nu = -t - 2
$$

---

**c) Limit:**

$$
\lim_{t \to \infty} x^*(t) = \begin{bmatrix} 0.5 \\ 0.5 \end{bmatrix}
$$

**Check against the original problem:**

$$
\min -x_1 - x_2 \quad \text{s.t.} \quad x_1 + x_2 = 1, \quad x \geq 0
$$

Optimal value: $$-1$$ at any $$x$$ satisfying $$x_1 + x_2 = 1$$, $$x \geq 0$$.

Optimal set: the line segment from $$(0,1)$$ to $$(1,0)$$.

The central path converges to the **analytic center** of the optimal set ($$x_1 = x_2 = 0.5$$).

---

**d) Primal-dual comparison:**

**Dual problem:**

$$
\max_{\nu} \quad \nu \quad \text{s.t.} \quad \begin{bmatrix} \nu \\ \nu \end{bmatrix} \leq \begin{bmatrix} -1 \\ -1 \end{bmatrix}
$$

$$\nu \leq -1$$ → $$\nu^* = -1$$.

**Duality gap:**

$$
\text{gap}(t) = c^T x^*(t) - b^T y(t)
$$

The dual feasible point obtained from the central path: $$\lambda_i(t) = \frac{1}{t x_i^*(t)} = \frac{2}{t}$$ and $$y(t) = \frac{\nu(t)}{t} = -1 - \frac{2}{t} \leq -1$$ (feasible for the dual). The dual value is $$b^Ty(t) = -1 - \frac{2}{t}$$, hence

$$
\text{gap}(t) = -1 - \left(-1 - \frac{2}{t}\right) = \frac{2}{t} = \frac{m}{t}
$$

The gap is **nonzero** for every finite $$t$$ and $$\to 0$$ as $$t \to \infty$$ (exactly the formula $$m/t$$ with $$m = 2$$).

**Note:** The formula $$\text{gap} = m/t$$ always holds on the central path; the gap is 0 only when compared with the optimal dual value $$\nu^* = -1$$, i.e. in the limit $$t \to \infty$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iii-perturbed-kkt-conditions&quot;&gt;📝 &lt;strong&gt;Part III: Perturbed KKT Conditions&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-4-kkt-conditions-with-the-barrier-boyd--vandenberghe-ex-114&quot;&gt;&lt;strong&gt;Exercise 4: KKT Conditions with the Barrier (Boyd &amp;amp; Vandenberghe, Ex. 11.4)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the barrier problem:&lt;/p&gt;

\[\min_x \quad t f(x) + \phi(x)\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the KKT conditions for the barrier problem&lt;br /&gt;
b) Prove: if \(x^*(t)\) satisfies the KKT conditions of the barrier problem, then there exists \(\lambda^*(t)\) such that:&lt;/p&gt;

\[\begin{align}
\nabla f(x^*(t)) + \sum_i \lambda_i^*(t) \nabla h_i(x^*(t)) &amp;amp;= 0 \\
\lambda_i^*(t) &amp;amp;= -\frac{1}{t h_i(x^*(t))} \\
h_i(x^*(t)) &amp;amp;&amp;lt; 0
\end{align}\]

&lt;p&gt;c) Compute \(\lambda_i^*(t) h_i(x^*(t))\)&lt;br /&gt;
d) What happens as \(t \to \infty\)?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) KKT for the barrier problem:**

$$
\min_x \quad t f(x) + \phi(x) = t f(x) - \sum_i \log(-h_i(x))
$$

**FOC:**

$$
t \nabla f(x) + \nabla \phi(x) = 0
$$

$$
t \nabla f(x) + \sum_i \frac{\nabla h_i(x)}{-h_i(x)} = 0
$$

---

**b) Proof of the perturbed KKT conditions:**

Define:

$$
\lambda_i^*(t) := -\frac{1}{t h_i(x^*(t))}
$$

Substitute into the FOC:

$$
t \nabla f(x^*) + \sum_i \frac{\nabla h_i(x^*)}{-h_i(x^*)} = 0
$$

$$
\nabla f(x^*) + \sum_i \frac{1}{-t h_i(x^*)} \nabla h_i(x^*) = 0
$$

$$
\nabla f(x^*) + \sum_i \left(-\frac{1}{t h_i(x^*)}\right) \nabla h_i(x^*) = 0
$$

$$
\nabla f(x^*) + \sum_i \lambda_i^*(t) \nabla h_i(x^*) = 0
$$

✓ This is exactly the stationarity condition of KKT!

**Feasibility:**

Since $$x^*$$ is strictly feasible for the barrier problem: $$h_i(x^*) &amp;lt; 0$$ ✓

**Dual feasibility:**

$$
\lambda_i^* = -\frac{1}{t h_i(x^*)} &amp;gt; 0 \quad \text{(since } h_i(x^*) &amp;lt; 0 \text{)}
$$

✓

---

**c) Complementary slackness (perturbed):**

$$
\lambda_i^*(t) h_i(x^*(t)) = -\frac{1}{t h_i(x^*)} \cdot h_i(x^*) = -\frac{1}{t}
$$

**Not zero!** This is **perturbed complementary slackness**.

---

**d) As $$t \to \infty$$:**

$$
\lambda_i^*(t) h_i(x^*(t)) = -\frac{1}{t} \to 0
$$

**Perturbed KKT conditions** → **exact KKT conditions**.

$$x^*(t) \to x^*$$, $$\lambda^*(t) \to \lambda^*$$ (the true optimal solution).

**Duality gap:**

$$
\text{gap}(t) = f(x^*(t)) - g(\lambda^*(t), \nu^*(t)) = \frac{m}{t}
$$

where $$m$$ = the number of inequality constraints.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iv-convergence-analysis&quot;&gt;📝 &lt;strong&gt;Part IV: Convergence Analysis&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-5-duality-gap-and-convergence-boyd--vandenberghe-theorem-112&quot;&gt;&lt;strong&gt;Exercise 5: Duality Gap and Convergence (Boyd &amp;amp; Vandenberghe, Theorem 11.2)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the barrier method with parameter \(t^{(k)} = \mu^k t^{(0)}\), \(\mu &amp;gt; 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Prove that the duality gap after \(k\) iterations is \(\text{gap}^{(k)} = \frac{m}{t^{(k)}}\)&lt;br /&gt;
b) How many outer iterations are needed to reach \(\text{gap} &amp;lt; \epsilon\)?&lt;br /&gt;
c) For \(m = 100\), \(\mu = 10\), \(\epsilon = 10^{-6}\), compute the number of iterations&lt;br /&gt;
d) Total number of Newton iterations (assume each outer iteration needs \(\approx 10\) Newton steps)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Duality gap:**

At iteration $$k$$, the central path point $$x^*(t^{(k)})$$ satisfies the perturbed KKT conditions:

$$
\lambda_i^*(t^{(k)}) h_i(x^*(t^{(k)})) = -\frac{1}{t^{(k)}}
$$

**Duality gap:**

$$
\eta(t^{(k)}) = f(x^*(t^{(k)})) - g(\lambda^*(t^{(k)}), \nu^*(t^{(k)}))
$$

By barrier method theory (Boyd &amp;amp; Vandenberghe, Theorem 11.2):

$$
\eta(t) = \frac{m}{t}
$$

where $$m$$ = the number of inequality constraints.

---

**b) Required number of iterations:**

Condition: $$\frac{m}{t^{(k)}} &amp;lt; \epsilon$$

$$
t^{(k)} &amp;gt; \frac{m}{\epsilon}
$$

With $$t^{(k)} = \mu^k t^{(0)}$$:

$$
\mu^k t^{(0)} &amp;gt; \frac{m}{\epsilon}
$$

$$
k &amp;gt; \frac{\log(m/(\epsilon t^{(0)}))}{\log \mu}
$$

If we start with $$t^{(0)} = 1$$:

$$
k &amp;gt; \frac{\log(m/\epsilon)}{\log \mu}
$$

---

**c) Numerical computation:**

$$
k &amp;gt; \frac{\log(100/10^{-6})}{\log 10} = \frac{\log(10^8)}{\log 10} = 8
$$

**Number of outer iterations:** $$k &amp;gt; 8$$, so we need $$k = 9$$ (for $$k = 8$$ the gap is $$m/\mu^8 = 10^{-6} = \epsilon$$, which is not strictly smaller than $$\epsilon$$)

---

**d) Total Newton iterations:**

Assume each outer iteration needs $$\approx 10$$ Newton steps:

$$
\text{Total Newton iters} \approx 9 \times 10 = 90
$$

**Analysis:**
- Barrier method with fixed $$\mu$$: $$O(\log(m/\epsilon))$$ outer iterations
- With $$\mu = 1 + 1/\sqrt{m}$$ (short-step): $$O(\sqrt{m}\log(m/\epsilon))$$ outer iterations, each needing only $$O(1)$$ Newton steps
- Total Newton steps (in theory): $$O(\sqrt{m} \log(m/\epsilon))$$

For this problem ($$\mu = 10$$ is large): few outer iterations, but possibly more Newton steps per iteration.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-v-feasibility-and-phase-i&quot;&gt;📝 &lt;strong&gt;Part V: Feasibility and Phase I&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-6-phase-i-method-nocedal--wright-ex-143&quot;&gt;&lt;strong&gt;Exercise 6: Phase I Method (Nocedal &amp;amp; Wright, Ex. 14.3)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Find a strictly feasible point for:&lt;/p&gt;

\[\begin{align}
&amp;amp; x_1 + x_2 \leq 1 \\
&amp;amp; x_1 - x_2 \leq 0.5 \\
&amp;amp; -x_1 \leq 0 \\
&amp;amp; -x_2 \leq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the Phase I problem:&lt;/p&gt;

\[\min_{x, s} \quad s \quad \text{s.t.} \quad h_i(x) \leq s, \quad i=1,\ldots,m\]

&lt;p&gt;b) Solve the Phase I problem with the barrier method&lt;br /&gt;
c) If the solution has \(s^* &amp;lt; 0\), choose a strictly feasible point&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Phase I problem:**

$$
\begin{align}
\min_{x_1, x_2, s} \quad &amp;amp; s \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 - 1 \leq s \\
&amp;amp; x_1 - x_2 - 0.5 \leq s \\
&amp;amp; -x_1 \leq s \\
&amp;amp; -x_2 \leq s
\end{align}
$$

**Equivalently:**

$$
\min_{x, s} \quad s \quad \text{s.t.} \quad h_i(x) - s \leq 0
$$

---

**b) Solving via the analytic center:**

**Barrier problem:**

$$
\min_{x, s} \quad t \cdot s - \sum_i \log(-(h_i(x) - s))
$$

For large $$t$$, the solution is close to:

$$
\min_s \quad s \quad \text{s.t.} \quad h_i(x) \leq s
$$

that is, $$s^* = \max_i h_i(x)$$.

**Solution:** The Phase I problem is an LP in 3 variables $$(x_1, x_2, s)$$. At the optimum, the three constraints $$h_1, h_3, h_4$$ are all active:

$$x_1 + x_2 - 1 = -x_1 = -x_2 = s \;\Rightarrow\; x_1 = x_2 = -s,\quad -2s - 1 = s \;\Rightarrow\; s = -\tfrac{1}{3}$$

**Solution:** $$x^* = \left(\tfrac{1}{3}, \tfrac{1}{3}\right)$$, $$s^* = -\tfrac{1}{3}$$.

**Check:**

$$
\begin{align}
h_1 &amp;amp;= \tfrac{1}{3} + \tfrac{1}{3} - 1 = -\tfrac{1}{3} \\
h_2 &amp;amp;= \tfrac{1}{3} - \tfrac{1}{3} - 0.5 = -0.5 \\
h_3 &amp;amp;= -\tfrac{1}{3} \\
h_4 &amp;amp;= -\tfrac{1}{3}
\end{align}
$$

$$s = \max_i h_i = -\tfrac{1}{3}$$. (The point $$x = (0.25, 0.25)$$ is also feasible with $$s = -0.25$$, but it is not optimal for Phase I since $$-0.25 &amp;gt; -\tfrac{1}{3}$$.)

---

**c) Strictly feasible point:**

Since $$s^* = -\tfrac{1}{3} &amp;lt; 0$$, the problem is **feasible** and $$x = (\tfrac{1}{3}, \tfrac{1}{3})$$ satisfies all four inequalities **strictly** ($$h_i = -\tfrac{1}{3}, -0.5, -\tfrac{1}{3}, -\tfrac{1}{3} &amp;lt; 0$$).

In practice any point with $$s &amp;lt; 0$$ (for example $$x = (0.25, 0.25)$$ with $$s = -0.25$$) is enough as a starting point for the barrier method.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-vi-a-comprehensive-problem&quot;&gt;📝 &lt;strong&gt;Part VI: A Comprehensive Problem&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-7-portfolio-optimization-with-the-barrier-method-boyd--vandenberghe-ex-1110&quot;&gt;&lt;strong&gt;Exercise 7: Portfolio Optimization with the Barrier Method (Boyd &amp;amp; Vandenberghe, Ex. 11.10)&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_x \quad &amp;amp; x^T \Sigma x \\
\text{s.t.} \quad &amp;amp; \mu^T x \geq r_{\min} \\
&amp;amp; \mathbf{1}^T x = 1 \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;With \(\Sigma = \begin{bmatrix} 0.04 &amp;amp; 0.01 \\ 0.01 &amp;amp; 0.09 \end{bmatrix}\), \(\mu = \begin{bmatrix} 0.10 \\ 0.15 \end{bmatrix}\), \(r_{\min} = 0.12\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the barrier problem&lt;br /&gt;
b) Compute the central path at \(t = 1, 10, 100\)&lt;br /&gt;
c) Analyze the convergence&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Barrier problem:**

Rewrite:

$$
\begin{align}
\min_x \quad &amp;amp; x^T \Sigma x \\
\text{s.t.} \quad &amp;amp; -\mu^T x + r_{\min} \leq 0 \quad \text{(inequality 1)} \\
&amp;amp; \mathbf{1}^T x = 1 \quad \text{(equality)} \\
&amp;amp; -x_i \leq 0, \quad i=1,2 \quad \text{(inequalities 2, 3)}
\end{align}
$$

**Barrier function:**

$$
\phi(x) = -\log(-(-\mu^T x + r_{\min})) - \sum_{i=1}^2 \log x_i
$$

$$
= -\log(\mu^T x - r_{\min}) - \log x_1 - \log x_2
$$

**Barrier problem:**

$$
\min_x \quad t \cdot x^T \Sigma x - \log(\mu^T x - r_{\min}) - \log x_1 - \log x_2
$$

s.t. $$\mathbf{1}^T x = 1$$

---

**b) Central path (numerical):**

**Lagrangian:**

$$
L = t x^T \Sigma x - \log(\mu^T x - r_{\min}) - \sum_i \log x_i - \nu(x_1 + x_2 - 1)
$$

**FOC:**

$$
2t \Sigma x - \frac{\mu}{\mu^T x - r_{\min}} - \begin{bmatrix} 1/x_1 \\ 1/x_2 \end{bmatrix} - \nu \mathbf{1} = 0
$$

$$
x_1 + x_2 = 1
$$

**Solving the system (a numerical solver is needed):**

For the given data, approximate solutions:

**$$t = 1$$:**

$$x^*(1) \approx (0.247, 0.753)$$

(for small $$t$$ the barrier term dominates, so the solution is near the analytic center of the feasible region)

**$$t = 10$$:**

$$x^*(10) \approx (0.282, 0.718)$$

**$$t = 100$$:**

$$x^*(100) \approx (0.448, 0.552)$$ (and $$x^*(1000) \approx (0.571, 0.429)$$)

Converging to the optimal solution: $$x^* = (0.6, 0.4)$$ (the return constraint is active: $$0.10(0.6)+0.15(0.4)=0.12$$; $$x^T\Sigma x = 0.0336$$).

---

**c) Convergence analysis:**

**Duality gap:**

$$m = 3$$ inequality constraints

$$
\text{gap}(t) = \frac{3}{t}
$$

- $$t = 1$$: gap = 3
- $$t = 10$$: gap = 0.3
- $$t = 100$$: gap = 0.03

For a gap $$&amp;lt; 10^{-6}$$ we need $$t &amp;gt; 3 \times 10^6$$.

With $$\mu = 10$$:

$$
k &amp;gt; \frac{\log(3 \times 10^6)}{\log 10} \approx 6.5 \Rightarrow k = 7 \text{ iterations}
$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary-and-strategy&quot;&gt;💡 &lt;strong&gt;Summary and Strategy&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;log-barrier-function&quot;&gt;&lt;strong&gt;Log-Barrier Function:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\phi(x) = -\sum_i \log(-h_i(x))\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla \phi(x) = \sum_i \frac{\nabla h_i(x)}{-h_i(x)}\]
  &lt;/li&gt;
  &lt;li&gt;\(\phi(x) \to \infty\) as \(x\) approaches the boundary&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;central-path&quot;&gt;&lt;strong&gt;Central Path:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;\(x^*(t)\) = the solution of \(\min t f(x) + \phi(x)\)&lt;/li&gt;
  &lt;li&gt;As \(t \to \infty\): \(x^*(t) \to x^*\) (the optimal solution)&lt;/li&gt;
  &lt;li&gt;Central path characterization: perturbed KKT&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;perturbed-kkt&quot;&gt;&lt;strong&gt;Perturbed KKT:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\nabla f(x^*) + \sum_i \lambda_i^* \nabla h_i(x^*) = 0\]
  &lt;/li&gt;
  &lt;li&gt;
\[\lambda_i^* = -\frac{1}{t h_i(x^*)}\]
  &lt;/li&gt;
  &lt;li&gt;\(\lambda_i^* h_i(x^*) = -\frac{1}{t} \to 0\) as \(t \to \infty\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;convergence&quot;&gt;&lt;strong&gt;Convergence:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Duality gap: \(\eta(t) = \frac{m}{t}\)&lt;/li&gt;
  &lt;li&gt;Outer iterations: \(O(\log(m/\epsilon) / \log \mu)\)&lt;/li&gt;
  &lt;li&gt;With \(\mu = 10\): \(\approx \log_{10}(m/\epsilon)\) iterations&lt;/li&gt;
  &lt;li&gt;Each iteration: solve the barrier problem with Newton’s method&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phase-i-method&quot;&gt;&lt;strong&gt;Phase I Method:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Find a strictly feasible point&lt;/li&gt;
  &lt;li&gt;\(\min_{x,s} s\) s.t. \(h_i(x) \leq s\)&lt;/li&gt;
  &lt;li&gt;If \(s^* &amp;lt; 0\): feasible, choose \(x^*\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 11.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nocedal, J., &amp;amp; Wright, S. J.&lt;/strong&gt; (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt; (2nd ed.). Springer. Chapter 14, 19.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nesterov, Y.&lt;/strong&gt; (2004). &lt;em&gt;Introductory Lectures on Convex Optimization&lt;/em&gt;. Springer. Chapter 4.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Wright, S. J.&lt;/strong&gt; (1997). &lt;em&gt;Primal-Dual Interior-Point Methods&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ben-Tal, A., &amp;amp; Nemirovski, A.&lt;/strong&gt; (2001). &lt;em&gt;Lectures on Modern Convex Optimization&lt;/em&gt;. SIAM. Chapter 4.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

</content>
 </entry>
 
 <entry>
   <title>15-10 Multiple-Choice Quiz - Barrier Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_10_Quiz_Barrier_Method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_10_Quiz_Barrier_Method</id>
   <content type="html">&lt;p&gt;Barrier method quizzes test whether you can connect the geometry of the interior to the algebra of duality: knowing why \(u_i(t) = -1/(t h_i(x^*(t)))\) is automatically positive, why the suboptimality gap is \(m/t\) (and &lt;em&gt;not&lt;/em&gt; \(n/t\)!), how \(\mu\) trades off outer vs. inner iterations, and how Phase I certifies infeasibility when \(s^\star &amp;gt; 0\). Review these four pillars and the quick diagnostic below before starting the quiz.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-high-yield-barrier-method-checkpoints&quot;&gt;Key ideas: High-Yield Barrier Method Checkpoints&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Log Barrier Calculus &amp;amp; Convexity:&lt;/strong&gt; \(\phi(x) = -\sum_{i=1}^m \log(-h_i(x))\) requires \(h_i(x) &amp;lt; 0\); its gradient is \(-\sum \frac{1}{h_i}\nabla h_i\) and its Hessian is \(\sum \frac{1}{h_i^2}\nabla h_i \nabla h_i^T - \sum \frac{1}{h_i}\nabla^2 h_i \succeq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Central Path &amp;amp; Perturbed KKT:&lt;/strong&gt; \(u_i(t) = -1/(t h_i(x^*(t))) &amp;gt; 0\) satisfies exact stationarity and perturbed complementarity \(u_i(t)h_i(x^*(t)) = -1/t\), giving \(f(x^*(t)) - f^\star \le m/t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Path-Following Complexity:&lt;/strong&gt; Outer iterations scale as \(\frac{\log(m/(t^{(0)}\epsilon))}{\log \mu} + 1\) (linear convergence in outer loops), while short-step formal barrier theory achieves \(O(\sqrt{\nu}\log(1/\epsilon))\) total Newton steps.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Phase I Feasibility:&lt;/strong&gt; Minimizing \(s\) s.t. \(h_i(x) \le s, Ax = b\) stops the moment \(s &amp;lt; 0\) (strictly feasible point found) or proves infeasibility if \(s^\star &amp;gt; 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-4-check-rapid-quiz-warm-up&quot;&gt;Worked example: 4-Check Rapid Quiz Warm-Up&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gap formula check:&lt;/strong&gt; A problem in \(\mathbb{R}^{500}\) has \(m = 40\) inequality constraints and \(10\) equality constraints. At \(t = 8000\) on the central path, what is the guaranteed suboptimality bound?
    &lt;ul&gt;
      &lt;li&gt;Only inequalities enter \(m\): \(f(x^*(t)) - f^\star \le \frac{m}{t} = \frac{40}{8000} = 0.005\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual multiplier check:&lt;/strong&gt; If at \(t = 5\) an inequality has value \(h_3(x^*(5)) = -0.04\), what is \(u_3(5)\)?
    &lt;ul&gt;
      &lt;li&gt;\(u_3(5) = -\frac{1}{5(-0.04)} = \frac{1}{0.20} = 5.0 &amp;gt; 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier Hessian check:&lt;/strong&gt; For \(\phi(x) = -\log(x_1) - \log(x_2)\) at \(x = (2, 0.5)^T\), compute \(\nabla^2 \phi(x)\).
    &lt;ul&gt;
      &lt;li&gt;\(\nabla^2 \phi(2, 0.5) = \operatorname{diag}(1/2^2,\ 1/0.5^2) = \operatorname{diag}(0.25,\ 4.0)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phase I check:&lt;/strong&gt; If Phase I returns an optimal value \(s^\star = +0.15\), what do we conclude?
    &lt;ul&gt;
      &lt;li&gt;Because \(s^\star &amp;gt; 0\), no point satisfies all \(h_i(x) \le 0\) simultaneously—the original problem is &lt;strong&gt;infeasible&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-the-barrier-method&quot;&gt;⚡ &lt;strong&gt;The Barrier Method&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;the-inequality-constrained-problem&quot;&gt;&lt;strong&gt;The inequality-constrained problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) \quad \text{s.t.} \quad h_i(x) \le 0, \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;with \(i = 1,\ldots,m\)&lt;/p&gt;

&lt;h4 id=&quot;problems-with-boundary-optimization&quot;&gt;&lt;strong&gt;Problems with boundary optimization&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Binding vs non-binding constraints:&lt;/strong&gt; Hard to tell which constraints are active&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Boundary computation:&lt;/strong&gt; \(O(m^2)\) complexity for active set methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-differentiable:&lt;/strong&gt; The indicator function is not differentiable&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;interior-method-philosophy&quot;&gt;&lt;strong&gt;Interior method philosophy&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Idea:&lt;/strong&gt; Solve from the &lt;strong&gt;interior&lt;/strong&gt; of the feasible region instead of the boundary&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Avoid boundary:&lt;/strong&gt; No need to identify the active constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smooth approximation:&lt;/strong&gt; Use differentiable barrier functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton applicable:&lt;/strong&gt; Enables Newton’s method for constrained problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-logarithmic-barrier-function&quot;&gt;🚧 &lt;strong&gt;Logarithmic Barrier Function&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;indicator-function-approximation&quot;&gt;&lt;strong&gt;Indicator function approximation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Original:&lt;/strong&gt; \(I_C(x) = \begin{cases} 0 &amp;amp; \text{if } x \in C \\ \infty &amp;amp; \text{otherwise} \end{cases}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Barrier approximation:&lt;/strong&gt; \(\phi(x) = -\sum_{i=1}^m \log(-h_i(x))\)&lt;/p&gt;

&lt;h4 id=&quot;properties-of-the-log-barrier&quot;&gt;&lt;strong&gt;Properties of the log barrier&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Domain:&lt;/strong&gt; \(\{x : h_i(x) &amp;lt; 0 \quad \forall i\}\) (strictly feasible)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smooth:&lt;/strong&gt; Twice differentiable in the interior&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier effect:&lt;/strong&gt; \(\phi(x) \to \infty\) as \(x\) approaches the boundary&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-concordant:&lt;/strong&gt; (when \(h_i\) is affine or convex quadratic) Enables elegant Newton analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;barrier-problem-formulation&quot;&gt;&lt;strong&gt;Barrier problem formulation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Original problem:&lt;/strong&gt; \(\min f(x)\) s.t. \(h_i(x) \le 0, Ax = b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Barrier approximation:&lt;/strong&gt;
\(\min_x tf(x) + \phi(x) \quad \text{s.t.} \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;with \(t &amp;gt; 0\) the &lt;strong&gt;barrier parameter&lt;/strong&gt;&lt;/p&gt;

&lt;h4 id=&quot;interpretation&quot;&gt;&lt;strong&gt;Interpretation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Large \(t\):&lt;/strong&gt; Emphasize original objective \(f(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Small \(t\):&lt;/strong&gt; Emphasize staying interior (large barrier effect)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(t \to \infty\):&lt;/strong&gt; Barrier problem → original problem&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-central-path&quot;&gt;🛤️ &lt;strong&gt;Central Path&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Central path:&lt;/strong&gt; \(\{x^*(t) : t &amp;gt; 0\}\) with \(x^*(t) = \arg\min_x \{tf(x) + \phi(x) : Ax = b\}\)&lt;/p&gt;

&lt;h4 id=&quot;properties&quot;&gt;&lt;strong&gt;Properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Smooth curve:&lt;/strong&gt; Forms a continuous path in \(\mathbb{R}^n\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence:&lt;/strong&gt; \(x^*(t) \to x^*\) as \(t \to \infty\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior:&lt;/strong&gt; All points strictly feasible&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unique:&lt;/strong&gt; Each \(t\) gives unique \(x^*(t)\) (under strict convexity)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;geometric-interpretation&quot;&gt;&lt;strong&gt;Geometric interpretation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Path from interior to boundary:&lt;/strong&gt; Gradually approach optimal solution&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Balance:&lt;/strong&gt; Trade-off between the objective and barrier terms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smooth transition:&lt;/strong&gt; Continuous movement toward optimum&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-kkt-conditions-and-interpretation&quot;&gt;📊 &lt;strong&gt;KKT Conditions and Interpretation&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;barrier-problem-kkt&quot;&gt;&lt;strong&gt;Barrier problem KKT&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;For the barrier problem \(\min tf(x) + \phi(x)\) s.t. \(Ax = b\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt; \(t\nabla f(x^*(t)) + \nabla \phi(x^*(t)) + A^T \nu^*(t) = 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feasibility:&lt;/strong&gt; \(Ax^*(t) = b\)&lt;/p&gt;

&lt;h4 id=&quot;original-problem-kkt&quot;&gt;&lt;strong&gt;Original problem KKT&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;For the original problem \(\min f(x)\) s.t. \(h_i(x) \le 0, Ax = b\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt; \(\nabla f(x^*) + \sum_{i=1}^m \lambda_i^* \nabla h_i(x^*) + A^T \nu^* = 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; \(\lambda_i^* h_i(x^*) = 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual feasibility:&lt;/strong&gt; \(\lambda_i^* \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primal feasibility:&lt;/strong&gt; \(h_i(x^*) \le 0, Ax^* = b\)&lt;/p&gt;

&lt;h4 id=&quot;connection&quot;&gt;&lt;strong&gt;Connection&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Key insight:&lt;/strong&gt; \(\nabla \phi(x) = -\sum_{i=1}^m \frac{1}{h_i(x)} \nabla h_i(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Perturbed KKT:&lt;/strong&gt; \(\lambda_i^*(t) = -\frac{1}{th_i(x^*(t))}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt; Barrier method gives &lt;strong&gt;perturbed KKT conditions&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;-suboptimality-gap&quot;&gt;📈 &lt;strong&gt;Suboptimality Gap&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;duality-gap-for-barrier-problem&quot;&gt;&lt;strong&gt;Duality gap for barrier problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Theorem:&lt;/strong&gt; \(f(x^*(t)) - f^* \le \frac{m}{t}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proof sketch:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Construct a dual feasible point from the barrier solution&lt;/li&gt;
  &lt;li&gt;Use weak duality: \(f(x^*(t)) - f^* \le \text{duality gap}\)&lt;/li&gt;
  &lt;li&gt;Duality gap = \(\frac{m}{t}\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;practical-implication&quot;&gt;&lt;strong&gt;Practical implication&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Accuracy control:&lt;/strong&gt; Choose \(t = \frac{m}{\epsilon}\) for \(\epsilon\)-optimal solution&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trade-off:&lt;/strong&gt; Larger \(t\) → better approximation but harder subproblem&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stopping criterion:&lt;/strong&gt; \(\frac{m}{t} &amp;lt; \epsilon\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-barrier-method-algorithms&quot;&gt;🔄 &lt;strong&gt;Barrier Method Algorithms&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;barrier-method-v0-naive&quot;&gt;&lt;strong&gt;Barrier Method v.0 (Naive)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Algorithm:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Choose \(t = \frac{m}{\epsilon}\)&lt;/li&gt;
  &lt;li&gt;Solve barrier problem \(\min tf(x) + \phi(x)\) s.t. \(Ax = b\)&lt;/li&gt;
  &lt;li&gt;Return \(x^*(t)\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Problems:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Large \(t\):&lt;/strong&gt; Very difficult subproblem&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Poor conditioning:&lt;/strong&gt; Hessian becomes ill-conditioned&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Slow convergence:&lt;/strong&gt; Many Newton iterations needed&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;barrier-method-v1-path-following&quot;&gt;&lt;strong&gt;Barrier Method v.1 (Path-following)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Algorithm:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Choose \(t^{(0)} &amp;gt; 0\), set \(k = 0\)&lt;/li&gt;
  &lt;li&gt;Solve barrier problem at \(t^{(0)}\) to get \(x^{(0)}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;While&lt;/strong&gt; \(\frac{m}{t^{(k)}} &amp;gt; \epsilon\):
    &lt;ul&gt;
      &lt;li&gt;Choose \(t^{(k+1)} &amp;gt; t^{(k)}\) (typically \(t^{(k+1)} = \mu t^{(k)}\))&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Warm start:&lt;/strong&gt; Initialize Newton with \(x^{(k)}\)&lt;/li&gt;
      &lt;li&gt;Solve barrier problem at \(t^{(k+1)}\) to get \(x^{(k+1)}\)&lt;/li&gt;
      &lt;li&gt;
\[k \leftarrow k + 1\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;key-components&quot;&gt;&lt;strong&gt;Key components&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Centering steps:&lt;/strong&gt; Solve barrier problem (outer iterations)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton steps:&lt;/strong&gt; Within each centering step (inner iterations)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm start:&lt;/strong&gt; Use previous solution as initialization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parameter update:&lt;/strong&gt; \(t^{(k+1)} = \mu t^{(k)}\) with \(\mu &amp;gt; 1\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-parameter-selection-trade-offs&quot;&gt;⚖️ &lt;strong&gt;Parameter Selection Trade-offs&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;choice-of-mu-update-factor&quot;&gt;&lt;strong&gt;Choice of \(\mu\) (update factor)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(\mu\) too small:&lt;/strong&gt; Many outer iterations (more centering steps)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\mu\) too large:&lt;/strong&gt; Many inner iterations (Newton steps per centering)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Typical choice:&lt;/strong&gt; \(\mu = 10\) to \(50\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;choice-of-t0-initial-parameter&quot;&gt;&lt;strong&gt;Choice of \(t^{(0)}\) (initial parameter)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(t^{(0)}\) too small:&lt;/strong&gt; Many outer iterations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(t^{(0)}\) too large:&lt;/strong&gt; Difficult first centering step&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical:&lt;/strong&gt; Start with a moderate value; the algorithm is robust&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;robustness&quot;&gt;&lt;strong&gt;Robustness&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Good news:&lt;/strong&gt; Barrier method performance is &lt;strong&gt;robust&lt;/strong&gt; to parameter choices&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Wide range:&lt;/strong&gt; Many \((\mu, t^{(0)})\) combinations work well&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Problem-dependent:&lt;/strong&gt; Optimal values vary with problem size&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical guidance:&lt;/strong&gt; Default values usually sufficient&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-convergence-analysis&quot;&gt;📊 &lt;strong&gt;Convergence Analysis&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;convergence-theorem&quot;&gt;&lt;strong&gt;Convergence theorem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Assumption:&lt;/strong&gt; Centering steps solved exactly&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; After \(k\) outer iterations:
\(f(x^{(k)}) - f^* \le \frac{m}{\mu^k t^{(0)}}\)&lt;/p&gt;

&lt;h4 id=&quot;iteration-complexity&quot;&gt;&lt;strong&gt;Iteration complexity&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;To achieve \(\epsilon\)-optimal solution:&lt;/strong&gt;
\(\text{Outer iterations} = \frac{\log(m/(t^{(0)}\epsilon))}{\log \mu} + 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convergence rate:&lt;/strong&gt; \(O(\log(1/\epsilon))\) - &lt;strong&gt;linear convergence&lt;/strong&gt;&lt;/p&gt;

&lt;h4 id=&quot;comparison-with-other-methods&quot;&gt;&lt;strong&gt;Comparison with other methods&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Newton method:&lt;/strong&gt; \(O(\log\log(1/\epsilon))\) - quadratic convergence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient descent:&lt;/strong&gt; \(O(1/\epsilon)\) - sublinear convergence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier method:&lt;/strong&gt; \(O(\log(1/\epsilon))\) - linear convergence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Linear convergence is &lt;strong&gt;very good&lt;/strong&gt; for constrained problems!&lt;/p&gt;

&lt;h3 id=&quot;-feasibility-methods&quot;&gt;🎯 &lt;strong&gt;Feasibility Methods&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;problem-finding-strictly-feasible-starting-point&quot;&gt;&lt;strong&gt;Problem: Finding strictly feasible starting point&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Need:&lt;/strong&gt; \(x\) such that \(h_i(x) &amp;lt; 0 \quad \forall i, \quad Ax = b\)&lt;/p&gt;

&lt;h4 id=&quot;phase-i-maximum-infeasibility&quot;&gt;&lt;strong&gt;Phase I: Maximum infeasibility&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{x,s} s \quad \text{s.t.} \quad h_i(x) \le s, \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Find \(s &amp;lt; 0\) (strictly feasible point exists)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantage:&lt;/strong&gt; Single slack variable&lt;/p&gt;

&lt;h4 id=&quot;phase-i-individual-infeasibilities&quot;&gt;&lt;strong&gt;Phase I: Individual infeasibilities&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{x,s} \mathbf{1}^T s \quad \text{s.t.} \quad h_i(x) \le s_i, \quad Ax = b, \quad s \succeq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Optimal \(s^* = 0\) ⟺ the original problem is feasible&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantage:&lt;/strong&gt; Identify which constraints are problematic&lt;/p&gt;

&lt;h4 id=&quot;implementation&quot;&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Use barrier method:&lt;/strong&gt; For Phase I problems too&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lower accuracy:&lt;/strong&gt; Don’t need high precision for feasibility&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infeasibility detection:&lt;/strong&gt; In the basic Phase I, if the optimal \(s^* &amp;gt; 0\) then the original problem is infeasible; if \(s^* \ge 0\) there is no strictly feasible point&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-implementation-details&quot;&gt;🛠️ &lt;strong&gt;Implementation Details&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;newton-method-for-barrier-problems&quot;&gt;&lt;strong&gt;Newton method for barrier problems&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Gradient:&lt;/strong&gt; \(\nabla (tf + \phi) = t\nabla f - \sum_{i=1}^m \frac{1}{h_i(x)} \nabla h_i\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hessian:&lt;/strong&gt; \(\nabla^2 (tf + \phi) = t\nabla^2 f + \sum_{i=1}^m \frac{1}{h_i^2(x)} \nabla h_i \nabla h_i^T - \sum_{i=1}^m \frac{1}{h_i(x)} \nabla^2 h_i\)&lt;/p&gt;

&lt;h4 id=&quot;numerical-considerations&quot;&gt;&lt;strong&gt;Numerical considerations&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Stay strictly feasible:&lt;/strong&gt; Ensure \(h_i(x) &amp;lt; 0\) throughout&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Line search:&lt;/strong&gt; Backtracking to maintain feasibility&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conditioning:&lt;/strong&gt; Hessian becomes ill-conditioned as \(t\) increases&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stopping criteria:&lt;/strong&gt; Use duality gap \(\frac{m}{t}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-example-linear-programming&quot;&gt;💡 &lt;strong&gt;Example: Linear Programming&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;lp-problem&quot;&gt;&lt;strong&gt;LP problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min c^T x \quad \text{s.t.} \quad Ax = b, \quad x \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;barrier-formulation&quot;&gt;&lt;strong&gt;Barrier formulation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min tc^T x - \sum_{i=1}^n \log x_i \quad \text{s.t.} \quad Ax = b\)&lt;/p&gt;

&lt;h4 id=&quot;central-path&quot;&gt;&lt;strong&gt;Central path&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;KKT conditions:&lt;/strong&gt; \(tc + A^T \nu - X^{-1} e = 0, \quad Ax = b\)&lt;/p&gt;

&lt;p&gt;with \(X = \text{diag}(x)\), \(e = (1,\ldots,1)^T\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt; \(x_i \lambda_i = \frac{1}{t}\) (perturbed complementary slackness)&lt;/p&gt;

&lt;h3 id=&quot;-connections-to-other-chapters&quot;&gt;🎯 &lt;strong&gt;Connections to Other Chapters&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-the-previous-chapter&quot;&gt;&lt;strong&gt;From the previous chapter:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 14:&lt;/strong&gt; Newton’s method - the foundation of the barrier method&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 12:&lt;/strong&gt; KKT conditions - perturbed KKT interpretation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 11:&lt;/strong&gt; General duality - duality gap analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;importance-of-the-barrier-method&quot;&gt;&lt;strong&gt;Importance of the Barrier Method:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Interior point revolution:&lt;/strong&gt; Polynomial-time algorithms for LP&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constrained optimization:&lt;/strong&gt; A practical method for inequality constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-concordance:&lt;/strong&gt; Elegant theoretical framework&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Real-world impact:&lt;/strong&gt; Standard in optimization software&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;looking-ahead&quot;&gt;&lt;strong&gt;Looking ahead:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual methods:&lt;/strong&gt; Simultaneous primal-dual updates&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Homogeneous methods:&lt;/strong&gt; Handle infeasible problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Semidefinite programming:&lt;/strong&gt; Extension to matrix constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Large-scale applications:&lt;/strong&gt; Sparse matrix techniques&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-theoretical-significance&quot;&gt;🌟 &lt;strong&gt;Theoretical Significance&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;interior-point-paradigm&quot;&gt;&lt;strong&gt;Interior point paradigm:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Avoid combinatorial complexity:&lt;/strong&gt; No active set identification&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polynomial-time:&lt;/strong&gt; \(O(n^3 \log(1/\epsilon))\) for LP&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smooth approximation:&lt;/strong&gt; Differentiable barrier functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Path-following:&lt;/strong&gt; Systematic approach to boundary&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;theoretical-elegance&quot;&gt;&lt;strong&gt;Theoretical elegance:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Self-concordance:&lt;/strong&gt; Affine-invariant analysis&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Central path:&lt;/strong&gt; Geometric interpretation of optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duality connection:&lt;/strong&gt; Perturbed KKT conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence guarantees:&lt;/strong&gt; Rigorous complexity analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;practical-impact&quot;&gt;&lt;strong&gt;Practical impact:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Software revolution:&lt;/strong&gt; CPLEX, Gurobi use interior point&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Large-scale problems:&lt;/strong&gt; Handle millions of variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust performance:&lt;/strong&gt; Works across diverse problem classes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm start capability:&lt;/strong&gt; Efficient reoptimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;when-to-use-barrier-methods&quot;&gt;&lt;strong&gt;When to use barrier methods:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Many inequality constraints:&lt;/strong&gt; More efficient than active set&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Large-scale problems:&lt;/strong&gt; Polynomial-time complexity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High accuracy needed:&lt;/strong&gt; Linear convergence to high precision&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smooth problems:&lt;/strong&gt; Twice differentiable objectives and constraints&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;implementation-tips&quot;&gt;&lt;strong&gt;Implementation tips:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Maintain strict feasibility:&lt;/strong&gt; Never let \(h_i(x) \ge 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Use warm starts:&lt;/strong&gt; Previous solution as initialization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Monitor conditioning:&lt;/strong&gt; Watch Hessian condition number&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive parameters:&lt;/strong&gt; Adjust \(\mu\) based on performance&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feasibility phase:&lt;/strong&gt; Always check for strictly feasible starting point&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;common-pitfalls&quot;&gt;&lt;strong&gt;Common pitfalls:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Infeasible start:&lt;/strong&gt; Must begin with strictly feasible point&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Poor conditioning:&lt;/strong&gt; Large \(t\) makes Hessian ill-conditioned&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Boundary approach:&lt;/strong&gt; Don’t let iterates get too close to boundary&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parameter choice:&lt;/strong&gt; Extreme \(\mu\) values can hurt performance&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-advanced-topics&quot;&gt;🔬 &lt;strong&gt;Advanced Topics&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;primal-dual-interior-point&quot;&gt;&lt;strong&gt;Primal-dual interior point:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Simultaneous updates:&lt;/strong&gt; Update both primal and dual variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Predictor-corrector:&lt;/strong&gt; Mehrotra’s algorithm&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Homogeneous methods:&lt;/strong&gt; Handle infeasible problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Higher-order methods:&lt;/strong&gt; Beyond Newton steps&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;extensions&quot;&gt;&lt;strong&gt;Extensions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Semidefinite programming:&lt;/strong&gt; Matrix inequality constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-order cone programming:&lt;/strong&gt; Conic constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust optimization:&lt;/strong&gt; Uncertainty sets&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic programming:&lt;/strong&gt; Probabilistic constraints&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;large-scale-techniques&quot;&gt;&lt;strong&gt;Large-scale techniques:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sparse linear algebra:&lt;/strong&gt; Exploit problem structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iterative methods:&lt;/strong&gt; CG for Newton systems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preconditioning:&lt;/strong&gt; Improve conditioning&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parallel computation:&lt;/strong&gt; Distributed implementations&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-real-world-applications&quot;&gt;📈 &lt;strong&gt;Real-World Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;linear-and-quadratic-programming&quot;&gt;&lt;strong&gt;Linear and Quadratic Programming:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Portfolio optimization:&lt;/strong&gt; Risk-return trade-offs&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Production planning:&lt;/strong&gt; Resource allocation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Network flows:&lt;/strong&gt; Transportation problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; SVM training&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;engineering-design&quot;&gt;&lt;strong&gt;Engineering Design:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Structural optimization:&lt;/strong&gt; Weight minimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Control systems:&lt;/strong&gt; Optimal control&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Signal processing:&lt;/strong&gt; Filter design&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Image processing:&lt;/strong&gt; Reconstruction problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;finance-and-economics&quot;&gt;&lt;strong&gt;Finance and Economics:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Risk management:&lt;/strong&gt; Value-at-Risk optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic trading:&lt;/strong&gt; Execution strategies&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Auction design:&lt;/strong&gt; Mechanism optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Market equilibrium:&lt;/strong&gt; Economic modeling&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;machine-learning&quot;&gt;&lt;strong&gt;Machine Learning:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Regularized regression:&lt;/strong&gt; L1, L2 penalties&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Neural network training:&lt;/strong&gt; Constrained optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kernel methods:&lt;/strong&gt; SVM and variants&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrix completion:&lt;/strong&gt; Low-rank optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-future-directions&quot;&gt;🔮 &lt;strong&gt;Future Directions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;algorithmic-developments&quot;&gt;&lt;strong&gt;Algorithmic developments:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quantum interior point:&lt;/strong&gt; Quantum optimization algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Distributed methods:&lt;/strong&gt; Parallel barrier methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Online algorithms:&lt;/strong&gt; Streaming optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive methods:&lt;/strong&gt; Problem-specific adaptations&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;application-areas&quot;&gt;&lt;strong&gt;Application areas:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Deep learning:&lt;/strong&gt; Constrained neural network training&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Autonomous systems:&lt;/strong&gt; Real-time optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smart grids:&lt;/strong&gt; Energy optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bioinformatics:&lt;/strong&gt; Computational biology problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-key-insights&quot;&gt;💎 &lt;strong&gt;Key Insights&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;barrier-method-contributions&quot;&gt;&lt;strong&gt;Barrier method contributions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Interior approach:&lt;/strong&gt; Avoid boundary complexity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polynomial-time:&lt;/strong&gt; A theoretical breakthrough for LP&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical efficiency:&lt;/strong&gt; Handle large-scale problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smooth approximation:&lt;/strong&gt; Enable Newton methods&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;practical-impact-1&quot;&gt;&lt;strong&gt;Practical impact:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Software standard:&lt;/strong&gt; Foundation of modern solvers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Industrial applications:&lt;/strong&gt; Optimization across industries&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Research foundation:&lt;/strong&gt; Basis for advanced methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Educational value:&lt;/strong&gt; Elegant theory-practice connection&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-legacy-of-chapter-15&quot;&gt;🌟 &lt;strong&gt;Legacy of Chapter 15:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic revolution:&lt;/strong&gt; Interior point methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical breakthrough:&lt;/strong&gt; Polynomial-time linear programming&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical impact:&lt;/strong&gt; Large-scale optimization capability&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Software influence:&lt;/strong&gt; Standard in commercial solvers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Educational significance:&lt;/strong&gt; Beautiful theory-practice synthesis&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Final message:&lt;/strong&gt; The barrier method is not just a clever approximation technique - it is a &lt;strong&gt;paradigm shift&lt;/strong&gt; from boundary-based to interior-based optimization, enabling polynomial-time algorithms and the practical solution of large-scale constrained problems!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the barrier method, including interior point methods, the log barrier function, the central path, convergence analysis and feasibility methods.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🚧 Quiz: Barrier &amp;amp; Interior Point Methods&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: The barrier method handles inequality constraints by:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Converting them into equality constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Adding a barrier function to the objective&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Removing the constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Using a penalty method&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Adding a barrier function to the objective&lt;/strong&gt;&lt;br /&gt;
                The barrier method adds a barrier function that &quot;pushes&quot; the solution into the interior of the feasible region, avoiding constraint violations.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The log barrier function for the constraint \(g_i(x) \leq 0\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(-\log(-g_i(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\log(g_i(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(-\log(g_i(x))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(\log(-g_i(x))\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$-\log(-g_i(x))$$&lt;/strong&gt;&lt;br /&gt;
                The log barrier function $$-\log(-g_i(x))$$ ensures $$g_i(x) &amp;lt; 0$$ and grows to $$+\infty$$ as the boundary is approached.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: The barrier problem has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(\min tf(x) + \phi(x)\) subject to \(Ax = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(\min f(x) + t\phi(x)\) subject to \(Ax = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \(\min f(x) - t\phi(x)\) subject to \(Ax = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \(\min f(x)\) subject to \(Ax = b, g(x) \leq 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\min tf(x) + \phi(x)$$ subject to $$Ax = b$$&lt;/strong&gt;&lt;br /&gt;
                The barrier problem has a parameter $$t &amp;gt; 0$$; as $$t \to \infty$$ the solution approaches that of the original problem.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: The central path is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) The set \(\{x^*(t) | t &amp;gt; 0\}\) where \(x^*(t)\) is the solution of the barrier problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) A straight line from the starting point to the optimum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) The center of the feasible region&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Gradient descent path&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The set $$\{x^*(t) | t &amp;gt; 0\}$$ where $$x^*(t)$$ is the solution of the barrier problem&lt;/strong&gt;&lt;br /&gt;
                The central path is the trajectory of the optimal solutions as the parameter $$t$$ goes from 0 to $$\infty$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: As \(t \to \infty\), the central path:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Converges to the optimal solution of the original problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Diverge&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Oscillate&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Approach boundary&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Converges to the optimal solution of the original problem&lt;/strong&gt;&lt;br /&gt;
                As $$t \to \infty$$, the barrier term $$\phi(x)$$ becomes negligible and the solution approaches the original optimum $$x^*$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: The KKT conditions for the barrier problem at \(x^*(t)\) are:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(t\nabla f(x) + \sum \frac{1}{-g_i(x)} \nabla g_i(x) + A^T\nu = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(\nabla f(x) + \sum \lambda_i \nabla g_i(x) + A^T\nu = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(t\nabla f(x) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(\nabla f(x) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$t\nabla f(x) + \sum \frac{1}{-g_i(x)} \nabla g_i(x) + A^T\nu = 0$$&lt;/strong&gt;&lt;br /&gt;
                Gradient of the barrier objective: $$t\nabla f(x) + \nabla \phi(x) + A^T\nu = 0$$ with $$\nabla \phi(x) = \sum \frac{1}{-g_i(x)} \nabla g_i(x)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: The dual variables in the barrier method satisfy:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) \(\lambda_i^*(t) = \frac{1}{t(-g_i(x^*(t)))}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(\lambda_i^*(t) = t(-g_i(x^*(t)))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) \(\lambda_i^*(t) = -g_i(x^*(t))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(\lambda_i^*(t) = \frac{1}{-g_i(x^*(t))}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\lambda_i^*(t) = \frac{1}{t(-g_i(x^*(t)))}$$&lt;/strong&gt;&lt;br /&gt;
                Dual variables from the barrier method: $$\lambda_i^*(t) = \frac{1}{t(-g_i(x^*(t)))}$$, approaching the true dual as $$t \to \infty$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8: Duality gap --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The duality gap in the barrier method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(\frac{m}{t}\) where \(m\) is the number of inequality constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(\frac{1}{t}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(mt\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(t\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\frac{m}{t}$$ where $$m$$ is the number of inequality constraints&lt;/strong&gt;&lt;br /&gt;
                Duality gap $$\eta = f(x^*(t)) - g(\lambda^*(t), \nu^*(t)) = \frac{m}{t}$$, decreasing as $$t$$ increases.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: Barrier method algorithm:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) Increase \(t\) along a sequence, solving the barrier problem for each \(t\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) Decrease \(t\) along a sequence&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) Keep \(t\) fixed&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) Random \(t\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Increase $$t$$ along a sequence, solving the barrier problem for each $$t$$&lt;/strong&gt;&lt;br /&gt;
                Algorithm: start with $$t^{(0)}$$, solve the barrier problem, update $$t^{(k+1)} = \mu t^{(k)}$$ with $$\mu &amp;gt; 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: The centering step in the barrier method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) Solving the barrier problem for fixed \(t\) with Newton&apos;s method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) Finding the center of the feasible region&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Update parameter \(t\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) Check feasibility&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Solving the barrier problem for fixed $$t$$ with Newton&apos;s method&lt;/strong&gt;&lt;br /&gt;
                The centering step solves $$\min tf(x) + \phi(x)$$ subject to $$Ax = b$$ to find $$x^*(t)$$ on the central path.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: For affine \(g_i\), the log barrier function \(-\log(-g_i(x))\) has the property of being:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Self-concordant&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Smooth&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) All of the above properties&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above properties&lt;/strong&gt;&lt;br /&gt;
                For affine $$g_i$$, the log barrier function is convex, smooth and self-concordant, which gives Newton&apos;s method convergence guarantees. (For general convex $$g_i$$, the barrier is still convex and smooth but not necessarily self-concordant.)
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The Phase I problem for finding a feasible starting point:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) \(\min s\) subject to \(g_i(x) \leq s, Ax = b\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) \(\min \|g(x)\|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) \(\min f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) \(\min \|x\|\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\min s$$ subject to $$g_i(x) \leq s, Ax = b$$&lt;/strong&gt;&lt;br /&gt;
                Phase I finds a feasible point by minimizing the slack variable $$s$$. If the optimal $$s^* &amp;lt; 0$$ there is a strictly feasible point; if $$s^* &amp;gt; 0$$ the problem is infeasible.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The number of outer iterations of the barrier method to reach accuracy \(\epsilon\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(O(\log(1/\epsilon))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(O(1/\epsilon)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(O(\sqrt{1/\epsilon})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(O(1/\epsilon^2)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$O(\log(1/\epsilon))$$&lt;/strong&gt;&lt;br /&gt;
                With the update rule $$t^{(k+1)} = \mu t^{(k)}$$, $$O(\log(1/\epsilon))$$ outer iterations are needed to reduce the duality gap.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: The Newton decrement in the barrier method is used as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) The stopping criterion for the centering step&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Update parameter \(t\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Check feasibility&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Compute duality gap&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The stopping criterion for the centering step&lt;/strong&gt;&lt;br /&gt;
                The Newton decrement $$\lambda(x) \leq \eta$$ is the stopping criterion that ensures $$x$$ is close enough to the central path before updating $$t$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: Primal-dual interior point methods differ from the barrier method in that they:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Update both primal and dual variables simultaneously&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Do not need the central path&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Only apply to linear programs&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Do not need Newton&apos;s method&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Update both primal and dual variables simultaneously&lt;/strong&gt;&lt;br /&gt;
                Primal-dual methods update $$(x, \lambda, \nu)$$ together instead of solving only for $$x$$ as the barrier method does.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: The typical choice for the barrier parameter update:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(t^{(k+1)} = \mu t^{(k)}\) with \(\mu = 10\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(t^{(k+1)} = t^{(k)} + 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(t^{(k+1)} = 2t^{(k)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(t^{(k+1)} = t^{(k)}^2\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$t^{(k+1)} = \mu t^{(k)}$$ with $$\mu = 10$$&lt;/strong&gt;&lt;br /&gt;
                $$\mu = 10$$ is usually chosen to balance the number of outer iterations against the computational cost of each centering step.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: Advantages of the barrier method:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Polynomial-time complexity&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Warm-start capability&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Handle inequality constraints naturally&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) All of the above advantages&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above advantages&lt;/strong&gt;&lt;br /&gt;
                The barrier method has polynomial complexity, supports warm starts, and handles inequality constraints naturally.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: Given the LP: \(\min c^Tx\) s.t. \(Ax = b, x \geq 0\). The barrier function is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) \(-\sum_{i=1}^n \log x_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) \(\sum_{i=1}^n \log x_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) \(-\sum_{i=1}^n x_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) \(\sum_{i=1}^n x_i^2\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$-\sum_{i=1}^n \log x_i$$&lt;/strong&gt;&lt;br /&gt;
                For the constraints $$x_i \geq 0$$, the log barrier function is $$-\sum_{i=1}^n \log x_i$$, which enforces $$x_i &amp;gt; 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: The barrier method differs from the penalty method in that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) The barrier keeps the solution in the feasible region&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) The penalty allows constraint violations&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) The barrier needs a feasible starting point&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                The barrier method maintains feasibility and needs a feasible start, unlike the penalty method, which allows constraint violations.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20: Applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: Interior point methods are applied in:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Linear programming solvers&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Semidefinite programming&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Convex optimization packages&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above applications&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above applications&lt;/strong&gt;&lt;br /&gt;
                Interior point methods are the foundation of modern optimization solvers: CPLEX, Gurobi, CVX, MOSEK.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: The barrier method transforms a constrained problem into:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) A sequence of unconstrained problems&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) A linear problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) A QP problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) An SDP problem&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) A sequence of unconstrained problems&lt;/strong&gt;&lt;br /&gt;
                Barrier method: $$\min t f(x) + \phi(x)$$ (equivalently $$\min f(x) + \frac{1}{t}\phi(x)$$) with $$\phi$$ the barrier function, $$t \to \infty$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: The logarithmic barrier for the constraints $$g_i(x) \leq 0$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$-\sum \log(-g_i(x))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$\sum \log(g_i(x))$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$\sum g_i(x)^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$\sum |g_i(x)|$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$-\sum \log(-g_i(x))$$&lt;/strong&gt;&lt;br /&gt;
                Log barrier: $$\phi(x) = -\sum_{i=1}^m \log(-g_i(x))$$ with $$g_i(x) &amp;lt; 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: The central path in the barrier method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) The set of solutions of $$t\nabla f + \nabla \phi + A^T\nu = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) A straight line through the solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) The boundary of the feasible region&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) The gradient descent path&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The set of solutions of $$t\nabla f + \nabla \phi + A^T\nu = 0$$&lt;/strong&gt;&lt;br /&gt;
                Central path: $$x^*(t)$$ satisfies $$t\nabla f(x) + \nabla \phi(x) + A^T\nu = 0$$, $$Ax = b$$ for the parameter $$t &amp;gt; 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: As $$t \to \infty$$ in the barrier method:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) The solution approaches the original optimal solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) The solution diverges&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) The barrier function equals 0&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) It has no meaning&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The solution approaches the original optimal solution&lt;/strong&gt;&lt;br /&gt;
                As $$t \to \infty$$, the solution of the barrier problem approaches the solution of the original problem.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: For the constraint $$x &amp;gt; 0$$, the barrier function $$-\log x$$ has gradient:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$-1/x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$1/x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$-x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$\log x$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$-1/x$$&lt;/strong&gt;&lt;br /&gt;
                $$\frac{d}{dx}(-\log x) = -\frac{1}{x}$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;a&apos;, q3: &apos;a&apos;, q4: &apos;a&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;d&apos;, q12: &apos;a&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;a&apos;, q17: &apos;d&apos;, q18: &apos;a&apos;, q19: &apos;d&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered the barrier method and interior point optimization!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand the central path and convergence analysis well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review the log barrier function and the duality gap.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review the barrier problem and the KKT conditions.&apos;;
    } else {
        message = &apos;📖 Study interior point methods again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>15-08 Formal barrier method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_08_formal_barrier_method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_08_formal_barrier_method</id>
   <content type="html">&lt;p&gt;Earlier we saw the practical barrier method (v.1 and v.2) jump \(t\) by a big factor \(\mu = 10\) and take several Newton steps to re-center. Can we prove a mathematically airtight polynomial-time worst-case bound for &lt;em&gt;all&lt;/em&gt; conic programs? Yes—by taking &lt;strong&gt;short steps&lt;/strong&gt;! If \(\phi\) is a \(\nu\)-self-concordant barrier and we nudge \(t\) by the tiny factor \(\mu = 1 + \frac{1}{8\sqrt{\nu}}\), then &lt;strong&gt;one single Newton step&lt;/strong&gt; is guaranteed to restore \(\lambda_{t^+}(x^+) \le \frac{1}{9}\) forever!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-short-step-path-following--polynomial-complexity&quot;&gt;Key ideas: Short-Step Path-Following &amp;amp; Polynomial Complexity&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — \(\nu\)-Self-Concordant Barrier Parameter:&lt;/strong&gt; A self-concordant function \(\phi\) is a \(\nu\)-barrier if its own Newton decrement is uniformly bounded: \(\lambda_\phi(x)^2 = \nabla\phi(x)^T (\nabla^2\phi(x))^{-1}\nabla\phi(x) \le \nu\) for all \(x \in D\). For \(m\) linear inequalities, \(\nu = m\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Quantifying the Jump in \(\lambda\) When \(t \to t^+\):&lt;/strong&gt; Increasing \(t\) to \(t^+\) perturbs the Newton decrement predictably by at most \(\lambda_{t^+}(x) \le \frac{t^+}{t}\lambda_t(x) + \left(\frac{t^+}{t} - 1\right)\sqrt{\nu}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — The One-Step Invariant (\(\lambda \le 1/9\)):&lt;/strong&gt; Choosing \(\frac{t^+}{t} = 1 + \frac{1}{8\sqrt{\nu}}\) keeps \(\lambda_{t^+}(x) \le \frac{1}{4}\), which sits strictly inside Newton’s quadratic-contraction ball—so &lt;strong&gt;one&lt;/strong&gt; pure Newton step snaps \(\lambda_{t^+}(x^+)\) right back below \(\frac{1}{9}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — \(O(\sqrt{\nu}\log(1/\epsilon))\) Worst-Case Complexity:&lt;/strong&gt; Since \(\log\left(1 + \frac{1}{8\sqrt{\nu}}\right) \approx \frac{1}{8\sqrt{\nu}}\), reaching \(t = \nu/\epsilon\) requires at most \(O\left(\sqrt{\nu}\log\left(\frac{\nu}{t^{(0)}\epsilon}\right)\right)\) total Newton steps—proving polynomial time for LP, SOCP, and SDP!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-the-nu-barrier-parameter-and-short-step-growth-factor&quot;&gt;Worked example: Verifying the \(\nu\)-Barrier Parameter and Short-Step Growth Factor&lt;/h3&gt;

&lt;p&gt;Consider the standard orthant barrier \(\phi(x) = -\sum_{i=1}^m \log(x_i)\) on \(D = \mathbb{R}^m_{++}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the barrier parameter \(\nu\) directly from \(\lambda_\phi(x)^2 = \nabla\phi(x)^T (\nabla^2\phi(x))^{-1}\nabla\phi(x)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;From Section 15-01-03: \(\nabla \phi(x) = -X^{-1}\mathbf{1}\) and \(\nabla^2 \phi(x) = X^{-2}\), so \((\nabla^2\phi(x))^{-1} = X^2\).&lt;/li&gt;
      &lt;li&gt;Multiply out:
\(\lambda_\phi(x)^2 = (-X^{-1}\mathbf{1})^T X^2 (-X^{-1}\mathbf{1}) = \mathbf{1}^T X^{-1} X^2 X^{-1} \mathbf{1} = \mathbf{1}^T \mathbf{1} = m.\)&lt;/li&gt;
      &lt;li&gt;Therefore \(\phi(x)\) is a self-concordant barrier with exact parameter \(\nu = m\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the short-step update for \(m = 100\) inequalities (\(\sqrt{\nu} = 10\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Growth factor: \(\mu = 1 + \frac{1}{8\sqrt{100}} = 1 + \frac{1}{80} = 1.0125\).&lt;/li&gt;
      &lt;li&gt;Check the perturbed decrement if \(\lambda_t(x) = \frac{1}{9} \approx 0.1111\):
\(\lambda_{t^+}(x) \le 1.0125(0.1111) + (0.0125)(10) = 0.1125 + 0.125 = 0.2375 &amp;lt; \frac{1}{4}.\)&lt;/li&gt;
      &lt;li&gt;One pure Newton step contracts \(\lambda_{t^+}(x^+) \le \frac{0.2375^2}{(1 - 0.2375)^2} \approx 0.097 \le \frac{1}{9}\)! The invariant holds inductively forever.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If a convex function \(\phi : D \to \mathbb{R}\) defined on an open convex set \(D \subset \mathbb{R}^n\) satisfies the following conditions, then the function is a &lt;strong&gt;self-concordant barrier&lt;/strong&gt; with parameter \(\nu\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(\phi\) is self-concordant&lt;/li&gt;
  &lt;li&gt;For all \(x \in D\), the Newton decrement is bounded by the constant \(\nu\) as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\lambda(x)^2 = \nabla \phi(x) (\nabla^2 \phi(x))^{-1} \nabla \phi(x) \le \nu\]
&lt;/blockquote&gt;

&lt;p&gt;Let’s consider the following LP problem. (Here, \(\bar{D}\) is the closure of the domain \(D\).)&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x} \           &amp;amp;&amp;amp; c^Tx \\
&amp;amp;\text{subject to } \ &amp;amp;&amp;amp; x \in \bar{D}  \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This problem can be approximated as follows.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp; tc^Tx + \phi(x) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, let \(\phi_t(x) := tc^Tx + \phi(x)\) and let the corresponding Newton decrement be \(\lambda_t(x)\).&lt;/p&gt;

&lt;p&gt;Key observation: When \(t^+ &amp;gt; t\)&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
\lambda_t^+(x) \le &amp;amp; \frac{t^+}{t}\lambda_t^+(x) + \left ( \frac{t^+}{t} -1 \right ) \sqrt{\nu}  \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;theorem&quot;&gt;Theorem&lt;/h2&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \text{if} \quad \lambda_t(x) \le \frac{1}{9} \quad \text{and} \quad \frac{t^+}{t} \le 1 + \frac{1}{8 \sqrt{\nu}} \quad \text{then} \quad \lambda_t^+(x^+) \le \frac{1}{9}  \\
&amp;amp; \qquad \qquad \text{for} \quad x^+ = x - (\nabla^2 (\phi_{t^+}(x))^{-1} \nabla (\phi_{t^+}(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In conclusion, if we start with \(x^{(0)}, t^{(0)}\) such that \(\lambda_{t^{(0)}}(x^{(0)}) \lt \frac{1}{9}\) and choose \(\mu := 1 + \frac{1}{8 \sqrt{\nu}}\), then one Newton step per centering step is sufficient.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-07 Feasibility methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_07_feasibility_methods/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_07_feasibility_methods</id>
   <content type="html">&lt;p&gt;Every barrier method lesson so far quietly started with the phrase: &lt;em&gt;“Choose a strictly feasible point \(x^{(0)}\) satisfying \(h_i(x^{(0)}) &amp;lt; 0\) and \(Ax^{(0)} = b\).”&lt;/em&gt; In a 500-dimensional problem with 2,000 intersecting inequalities, finding even &lt;em&gt;one&lt;/em&gt; strictly feasible point can be just as hard as solving the optimization problem itself! &lt;strong&gt;Phase I feasibility methods&lt;/strong&gt; solve this chicken-and-egg puzzle by introducing an auxiliary slack variable \(s\) that relaxes all constraints just enough to make finding a starting point trivial—and then shrinks \(s\) until \(s &amp;lt; 0\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-phase-i--finding-a-strictly-feasible-starting-point&quot;&gt;Key ideas: Phase I — Finding a Strictly Feasible Starting Point&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Basic Phase I (Maximum Infeasibility):&lt;/strong&gt; Solve \(\min_{x,s} s\) subject to \(h_i(x) \le s\) and \(Ax = b\). Any \(x_0\) satisfying \(Ax_0 = b\) paired with \(s_0 = \max_i h_i(x_0) + 1\) is &lt;em&gt;immediately strictly feasible&lt;/em&gt; for Phase I!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Early Termination at \(s &amp;lt; 0\):&lt;/strong&gt; You do &lt;em&gt;not&lt;/em&gt; need to solve Phase I to optimality—the very instant an iterate achieves \(s &amp;lt; 0\), we have \(h_i(x) \le s &amp;lt; 0\) for all \(i\), so \(x\) is strictly feasible for the original Phase II problem!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Exact Infeasibility Detection:&lt;/strong&gt; If the optimal Phase I value satisfies \(s^\star &amp;gt; 0\), the original problem is provably infeasible; if \(s^\star = 0\), no strictly feasible point exists (Slater’s condition fails).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Sum-of-Infeasibilities Variant (\(\min \mathbf{1}^T s\) s.t. \(h_i(x) \le s_i, s_i \ge 0\)):&lt;/strong&gt; Assigning an individual slack \(s_i\) to each constraint diagnoses &lt;em&gt;which exact constraints&lt;/em&gt; conflict when a model is infeasible.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-running-phase-i-on-two-inequality-constraints&quot;&gt;Worked example: Running Phase I on Two Inequality Constraints&lt;/h3&gt;

&lt;p&gt;We need a strictly feasible point for \(h_1(x) = x - 5 \le 0\) and \(h_2(x) = -x + 1 \le 0\) (i.e., \(1 &amp;lt; x &amp;lt; 5\)), starting from an &lt;em&gt;infeasible&lt;/em&gt; initial guess \(x_0 = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate initial constraint violations at \(x_0 = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(h_1(0) = -5\) (satisfied), \(h_2(0) = +1\) (violated!).&lt;/li&gt;
      &lt;li&gt;Maximum violation: \(\max(-5, 1) = 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Construct a strictly feasible Phase I starting point \((x_0, s_0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Pick \(s_0 = \max_i h_i(x_0) + 1 = 1 + 1 = 2\).&lt;/li&gt;
      &lt;li&gt;Check Phase I strict feasibility: \(h_1(0) - s_0 = -7 &amp;lt; 0\) and \(h_2(0) - s_0 = -1 &amp;lt; 0\)! We can now launch the barrier method on Phase I.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the Phase I problem \(\min_{x, s} s\) s.t. \(x - 5 \le s\), \(1 - x \le s\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Adding the two inequalities gives \(-4 \le 2s \implies s \ge -2\), achieved at \(x^\star = 3, s^\star = -2\).&lt;/li&gt;
      &lt;li&gt;Even better: as soon as Phase I passes \((x, s) = (2, -0.5)\) with \(s = -0.5 &amp;lt; 0\), we stop immediately—\(x = 2\) satisfies \(h_1(2) = -3 &amp;lt; 0\) and \(h_2(2) = -1 &amp;lt; 0\) and is ready for Phase II!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So far, we have implicitly assumed that the first centering step (\(t = t^{(0)}\)) starts from a strictly feasible point to compute \(x^{(0)} = x^*\).&lt;/p&gt;

&lt;p&gt;This means that \(x\) is a strictly feasible point satisfying the following conditions:&lt;/p&gt;
&lt;blockquote&gt;
\[h_i(x) \lt 0, \quad i = 1, \cdots, m, \quad Ax = b\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;maximum-infeasibility&quot;&gt;Maximum infeasibility&lt;/h2&gt;
&lt;p&gt;How do we find \(x\)? We can solve the following problem to find it.&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x, s} \        &amp;amp;&amp;amp; s \\
&amp;amp;\text{subject to } \ &amp;amp;&amp;amp; h_i(x) \le s,&amp;amp; i = 1, \cdots, m \\
                      &amp;amp;&amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The goal is to make the solution \(s\) negative. This problem is called the &lt;strong&gt;feasibility method&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Finding a strictly feasible starting point is easy, so it can also be solved using the barrier method. That is, you can add slack variables to the inequality constraint \(h_i(x) \le s\) and convert it to an equality constraint to solve it.&lt;/p&gt;

&lt;p&gt;When solving this problem, high accuracy is not required; you just need to find a feasible \((x,s)\) with \(s &amp;lt; 0\).&lt;/p&gt;

&lt;h2 id=&quot;infeasibility-for-each-inequality-constraint&quot;&gt;Infeasibility for each inequality constraint&lt;/h2&gt;
&lt;p&gt;You can also define and solve the problem as follows. The previous method found the maximum infeasibility for all inequalities, while this problem finds the infeasible variable \(s_i, i = 1, \cdots, m\) for each inequality.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x, s} \        &amp;amp;&amp;amp; 1^Ts \\
&amp;amp;\text{subject to } \ &amp;amp;&amp;amp; h_i(x) \le s_i,&amp;amp; i = 1, \cdots, m \\
                      &amp;amp;&amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The advantage of this method is that by looking at the solution \(s\), you can tell if the problem is infeasible. That is, if any element of \(s\) is greater than or equal to 0, the corresponding constraint is not satisfied.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-06 Barrier method v.2</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_06_barrier_method_v2/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_06_barrier_method_v2</id>
   <content type="html">&lt;p&gt;Here is a practical secret of every real interior-point solver: &lt;em&gt;nobody actually cares about the central path for its own sake!&lt;/em&gt; The central path is merely a highway leading to \(x^\star\). Spending 12 Newton steps to compute \(x^*(t^{(k)})\) to 15 decimal places when you are immediately going to bump \(t\) up by a factor of 10 anyway is pure wasted work. &lt;strong&gt;Barrier Method v.2&lt;/strong&gt; replaces exact centering with &lt;em&gt;approximate&lt;/em&gt; centering—stopping Newton as soon as \(\lambda(x)\) is moderately small—and achieves the exact same accuracy in a fraction of the total Newton steps!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-inexact-centering--total-newton-complexity&quot;&gt;Key ideas: Inexact Centering &amp;amp; Total Newton Complexity&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Central Path as “Means to an End”:&lt;/strong&gt; Intermediate iterates \(x^{(k)} \approx x^*(t^{(k)})\) only need to stay inside Newton’s local neighborhood of the central path—not sit on it to machine precision.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Stopping Criterion for Inner Newton Steps:&lt;/strong&gt; Using the Newton decrement \(\frac{1}{2}\lambda_t(x)^2 \le \epsilon_{\text{inner}}\) (or \(\lambda_t(x) \le \eta\)) cleanly terminates each approximate centering step without wasted iterations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Total Newton Complexity via Self-Concordance:&lt;/strong&gt; Combining the outer loop with Nesterov–Nemirovskii’s self-concordance bound proves that total Newton steps grow only as \(O\left(\sqrt{m}\log\left(\frac{m}{t^{(0)}\epsilon}\right)\right)\) in theory—and roughly 20–40 total steps &lt;em&gt;independent of \(m\)&lt;/em&gt; in practice!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Bottleneck Shifts to Linear Algebra:&lt;/strong&gt; Because total Newton iterations barely change from \(m = 100\) to \(m = 100{,}000\), the true runtime of modern IPMs is governed almost entirely by the sparse KKT factorization cost per Newton step.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-comparing-exact-vs-inexact-centering-work&quot;&gt;Worked example: Comparing Exact vs. Inexact Centering Work&lt;/h3&gt;

&lt;p&gt;Suppose a barrier solve requires \(8\) outer iterations (\(\mu = 10\)) from \(t = 1\) to \(t = 10^8\). At each outer step, after bumping \(t \leftarrow 10t\), suppose the warm-started iterate has Newton decrement \(\lambda \approx 0.4\), and each pure Newton step squares \(\lambda\) roughly as \(\lambda_{j+1} \approx \lambda_j^2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Barrier Method v.1 (Exact centering to \(\lambda \le 10^{-10}\) at every outer step):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\lambda: 0.4 \to 0.16 \to 0.0256 \to 6.6 \times 10^{-4} \to 4.3 \times 10^{-7} \to 1.8 \times 10^{-13}\) (5 Newton steps per outer loop).&lt;/li&gt;
      &lt;li&gt;Total Newton steps: \(8 \times 5 = 40\) steps.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier Method v.2 (Inexact centering to \(\lambda \le 0.2\) on intermediate loops, exact only on the final loop):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Intermediate loops (7 loops): \(\lambda: 0.4 \to 0.16 \le 0.2\) (&lt;strong&gt;1–2 Newton steps&lt;/strong&gt; per loop!).&lt;/li&gt;
      &lt;li&gt;Final loop (1 loop): 5 Newton steps to polish \(x^\star\) to \(10^{-13}\).&lt;/li&gt;
      &lt;li&gt;Total Newton steps: \(7 \times 2 + 5 = 19\) steps—&lt;strong&gt;cutting runtime in half&lt;/strong&gt; with zero loss in final precision!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the previous algorithm, we generated solutions along the central path, but in reality, the central path is just a means to reach the optimal solution (“means to an end”). Therefore, it is not necessary to solve the problem exactly.&lt;/p&gt;

&lt;h3 id=&quot;algorithm&quot;&gt;Algorithm&lt;/h3&gt;

&lt;p&gt;For this reason, Barrier method v.2 solves the barrier problem approximately. However, in step 2, \(x^{(0)} \approx x^*(t)\) and in step 3-2, \(x^{(k+1)} \approx x^*(t)\) are now approximations.&lt;/p&gt;

&lt;p&gt;The steps of the algorithm are the same as those in Barrier method v.1.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Choose \(t^{(0)} &amp;gt; 0\) and set \(k := 0\).&lt;/li&gt;
  &lt;li&gt;At \(t = t^{(0)}\), solve the barrier problem to obtain \(x^{(0)} \approx x^*(t)\).&lt;/li&gt;
  &lt;li&gt;While \(m/t &amp;gt; \epsilon\)&lt;br /&gt;
3-1. Choose \(t^{(k+1)} &amp;gt; t^{(k)}\).&lt;br /&gt;
3-2. Initialize Newton’s method with \(x^{(k)}\) (warm start)&lt;br /&gt;
     At \(t = t^{(k+1)}\), solve the barrier problem to obtain \(x^{(k+1)} \approx x^*(t)\).&lt;br /&gt;
end while&lt;br /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Barrier method v.2, the following two issues are very important:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;How close should each approximation be?&lt;/li&gt;
  &lt;li&gt;How many Newton steps are needed at each centering step?&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter15/15_barrier_methodv2_04.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Analysis of Newton iterations and suboptimality gap with respect to m [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;In the following figure, you can see that when the barrier method is applied to a problem with \(m\) constraints, linear convergence occurs even as \(m\) becomes large. That is, it has a log scale with respect to \(m\).&lt;/p&gt;

&lt;p&gt;From a different perspective, the Newton steps needed (to reduce the initial suboptimal gap (duality gap) of \(10^4\)) increase slowly with respect to \(m\). Looking at the figure below, even when \(m\) increases significantly, about 20-30 Newton steps are needed for each centering step. However, one Newton step varies greatly depending on the size of the problem.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter15/15_barrier_methodv2_05.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 2] Analysis of the number of Newton iterations as m increases [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>15-05 Convergence analysis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_05_convergence_analysis/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_05_convergence_analysis</id>
   <content type="html">&lt;p&gt;How many outer centering loops does the barrier method need to slash the duality gap from \(10^4\) down to \(10^{-8}\)? Because \(t^{(k)} = \mu^k t^{(0)}\) grows geometrically, the suboptimality gap \(\frac{m}{\mu^k t^{(0)}}\) decays &lt;em&gt;linearly&lt;/em&gt; at rate \(1/\mu\)—meaning every single outer iteration adds a fixed number of accurate decimal digits, requiring only \(O(\log(m / (t^{(0)}\epsilon)))\) outer steps!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-outer-loop-complexity-of-the-barrier-method&quot;&gt;Key ideas: Outer-Loop Complexity of the Barrier Method&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Exact Geometric Decay of the Gap:&lt;/strong&gt; After \(k\) updates of \(t^{(k)} = \mu^k t^{(0)}\), the guaranteed suboptimality satisfies \(f(x^{(k)}) - f^\star \le \frac{m}{\mu^k t^{(0)}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Closed-Form Outer Iteration Formula:&lt;/strong&gt; Solving \(\frac{m}{\mu^k t^{(0)}} \le \epsilon\) for \(k\) yields exactly \(k = \left\lceil \frac{\log(m/(t^{(0)}\epsilon))}{\log \mu} \right\rceil\) (plus 1 for the initial centering at \(t^{(0)}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Linear Outer Rate vs. Quadratic Inner Rate:&lt;/strong&gt; Although the outer loop converges linearly (\(O(\log(1/\epsilon))\)) rather than quadratically (\(O(\log\log(1/\epsilon))\)), each outer step slashes the error by a huge factor \(\mu \approx 10\text{–}20\), so 6–10 outer steps suffice for machine precision.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Logarithmic Dependence on \(m\):&lt;/strong&gt; Doubling the number of constraints \(m\) adds at most \(\frac{\log 2}{\log \mu} &amp;lt; 1\) extra outer iteration—explaining why barrier methods scale effortlessly to thousands of inequalities.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-exact-outer-iterations-as-m-scales-100&quot;&gt;Worked example: Computing Exact Outer Iterations as \(m\) Scales 100×&lt;/h3&gt;

&lt;p&gt;Fix \(t^{(0)} = 1\), \(\mu = 10\), and target accuracy \(\epsilon = 10^{-5}\). Compare two problems: Problem A with \(m = 10\) constraints and Problem B with \(m = 1{,}000\) constraints.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Problem A (\(m = 10\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ratio: \(\frac{m}{t^{(0)}\epsilon} = \frac{10}{1 \cdot 10^{-5}} = 10^6\).&lt;/li&gt;
      &lt;li&gt;Outer centering steps (including initial \(t^{(0)}\)): \(\frac{\log_{10}(10^6)}{\log_{10}(10)} + 1 = 6 + 1 = 7\) centering steps.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Problem B (\(m = 1{,}000\) — 100× more constraints!):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ratio: \(\frac{m}{t^{(0)}\epsilon} = \frac{1000}{10^{-5}} = 10^8\).&lt;/li&gt;
      &lt;li&gt;Outer centering steps: \(\frac{\log_{10}(10^8)}{\log_{10}(10)} + 1 = 8 + 1 = 9\) centering steps!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Insight:&lt;/strong&gt; Increasing the number of constraints by &lt;strong&gt;100×&lt;/strong&gt; added only &lt;strong&gt;2&lt;/strong&gt; extra outer iterations!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Assuming the centering step in the barrier method is solved exactly, we can obtain the following convergence results.&lt;/p&gt;

&lt;h2 id=&quot;convergence-theorem&quot;&gt;Convergence Theorem&lt;/h2&gt;
&lt;p&gt;After \(k\) centering steps, the &lt;strong&gt;barrier method&lt;/strong&gt; satisfies the following equation. (Here, \(k\) is the number of outer iterations.)&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f^{*} \le  \frac{m}{\mu^k t^{(0)}}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;That is, to reach the desired accuracy level \(\epsilon\) with the barrier method, you need the following number of centering steps plus one for the first centering step.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\frac{log(m/(t^{(0)}\epsilon))}{\log \mu} + 1
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore, we see that the convergence is linear, with \(O(\log 1/\epsilon )\).&lt;/p&gt;

&lt;p&gt;Newton’s method has quadratic convergence with \(O(\log \log 1/\epsilon )\), but in this case, the problem is very difficult, so linear convergence is not such a bad result.&lt;/p&gt;

&lt;p&gt;For the definitions of linear and quadratic convergence, refer to the Wiki.&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Reference: &lt;a href=&quot;https://en.wikipedia.org/wiki/Rate_of_convergence&quot;&gt;Rate of convergence&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>15-04 Barrier method v.0 and v.1</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_04_barrier_method_v0_and_v1/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_04_barrier_method_v0_and_v1</id>
   <content type="html">&lt;p&gt;If \(t = m/\epsilon\) guarantees \(\epsilon\)-accuracy in one shot, why not just set \(t = 10^8\) right away and run Newton’s method once (Barrier Method v.0)? Try it, and Newton’s method chokes immediately: at \(t = 10^8\), the barrier wall is razor-sharp, its Hessian is horribly ill-conditioned, and Newton’s local quadratic basin shrinks to microscopic size. &lt;strong&gt;Barrier Method v.1&lt;/strong&gt; solves this by &lt;em&gt;continuously walking&lt;/em&gt; along the central path: multiply \(t\) by \(\mu \in [10, 20]\) and warm-start each centering step from the previous solution!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-one-shot-v0-vs-path-following-v1&quot;&gt;Key ideas: One-Shot (v.0) vs. Path-Following (v.1)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Why One-Shot (v.0) Fails:&lt;/strong&gt; Setting \(t = m/\epsilon\) directly creates an almost-discontinuous objective whose Hessian explodes near boundaries, forcing hundreds of painful damped Newton steps.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Geometric Progression (\(t^{(k+1)} = \mu t^{(k)}\)):&lt;/strong&gt; Multiplying \(t\) by a moderate factor \(\mu &amp;gt; 1\) shrinks the guaranteed duality gap \(m/t\) exponentially fast—by a factor of \(\mu\) on every outer iteration.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Warm-Starting Keeps Newton Close to the Basin:&lt;/strong&gt; Starting the centering step for \(\mu t\) at \(x^*(t)\) places the iterate close to \(x^*(\mu t)\), requiring only a few Newton iterations to re-center.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — The \(\mu\) Trade-Off (Sweet Spot \(\mu \in [10, 20]\)):&lt;/strong&gt; Small \(\mu\) (e.g., \(2\)) means cheap centering steps but many outer iterations; huge \(\mu\) (e.g., \(150\)) means few outer iterations but expensive re-centering; moderate \(\mu \approx 10\text{–}20\) minimizes &lt;em&gt;total&lt;/em&gt; Newton steps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-counting-outer-iterations-for-different-choices-of-mu&quot;&gt;Worked example: Counting Outer Iterations for Different Choices of \(\mu\)&lt;/h3&gt;

&lt;p&gt;Suppose a linear program has \(m = 100\) inequality constraints, initial barrier parameter \(t^{(0)} = 1\) (initial gap \(m/t^{(0)} = 100\)), and target accuracy \(\epsilon = 10^{-6}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the required final \(t\):&lt;/strong&gt; We stop once \(\frac{m}{t} \le \epsilon \implies t \ge \frac{100}{10^{-6}} = 10^8\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Count outer centering steps \(k = \left\lceil \frac{\log(10^8)}{\log \mu} \right\rceil\) across three choices of \(\mu\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;\(\mu = 2\) (too timid):&lt;/strong&gt; \(k = \lceil \log_2(10^8) \rceil = \lceil 26.57 \rceil = 27\) outer iterations (plus 1 initial centering = 28).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;\(\mu = 10\) (sweet spot):&lt;/strong&gt; \(k = \lceil \log_{10}(10^8) \rceil = 8\) outer iterations (\(t = 1, 10, 10^2, \dots, 10^8\))! If each centering takes ~4 Newton steps, total cost is only ~32 Newton steps.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;\(\mu = 100\) (aggressive):&lt;/strong&gt; \(k = \lceil \log_{100}(10^8) \rceil = 4\) outer iterations—half as many outer loops, &lt;em&gt;but&lt;/em&gt; each jump is 10× steeper so each centering step may need 10–15 Newton steps (40–60 total).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;barrier-method-v0&quot;&gt;Barrier method v.0&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Barrier method v.0&lt;/strong&gt; chooses \(t = m/\epsilon\) for \(\epsilon &amp;gt; 0\) and solves the following barrier problem to obtain \(f(x^*(t)) - f(x^*) \le \epsilon\).&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
 &amp;amp;\min_{x} \ &amp;amp;&amp;amp; tf(x) + \phi(x) \\
 &amp;amp;\text{subject to } \ &amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(m\) is the number of constraints and \(t\) is a multiple of \(1/\epsilon\), so as \(\epsilon\) gets smaller, \(t\) becomes very large, and eventually the end of the central path is reached, making the problem equivalent to the original problem. Therefore, this can be very slow and difficult to solve.&lt;/p&gt;

&lt;p&gt;Thus, a better approach is to follow the central path to find the solution, which leads to the definition of &lt;strong&gt;barrier method v.1&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;barrier-method-v1&quot;&gt;Barrier method v.1&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Barrier method v.1&lt;/strong&gt; is a method that gradually increases the value of \(t\) and solves the following barrier problem multiple times.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
 &amp;amp;\min_{x} \ &amp;amp;&amp;amp; tf(x) + \phi(x) \\
 &amp;amp;\text{subject to } \ &amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;algorithm&quot;&gt;Algorithm&lt;/h3&gt;
&lt;p&gt;The algorithm can be described as follows.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Choose \(t^{(0)} &amp;gt; 0\) and set \(k := 0\).&lt;/li&gt;
  &lt;li&gt;At \(t = t^{(0)}\), solve the barrier problem to obtain \(x^{(0)} = x^*(t)\).&lt;/li&gt;
  &lt;li&gt;While \(m/t &amp;gt; \epsilon\) &lt;br /&gt;
  3-1. Choose \(t^{(k+1)} &amp;gt; t^{(k)}\). &lt;br /&gt;
  3-2. Initialize Newton’s method with \(x^{(k)}\). (warm start)&lt;br /&gt;
     At \(t = t^{(k+1)}\), solve the barrier problem to obtain \(x^{(k+1)} = x^*(t)\).&lt;br /&gt;
  end while&lt;br /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;comments&quot;&gt;Comments&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Common update method&lt;/strong&gt;: \(t^{(k+1)} = \mu t^{(k)}\), (\(\mu &amp;gt; 1\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm start&lt;/strong&gt;: In step 3-2, the solution from the previous step is used as the initial value for the next step, which is called warm start.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Centering step&lt;/strong&gt;: Steps 2 and 3-2 in the algorithm, which solve the barrier problem, are called centering steps (or outer iterations).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;considerations&quot;&gt;Considerations&lt;/h3&gt;
&lt;p&gt;In choosing \(\mu\) and \(t^{(0)}\), the following trade-offs must be considered.&lt;/p&gt;
&lt;h5 id=&quot;choice-of-mu&quot;&gt;Choice of \(\mu\)&lt;/h5&gt;
&lt;ul&gt;
  &lt;li&gt;If \(\mu\) is too small, the number of outer iterations increases. (In this case, warm start helps.)&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;If \(\mu\) is too large, many iterations are required for Newton’s method to converge in every centering step.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5 id=&quot;choice-of-initial-algorithm-value&quot;&gt;Choice of initial algorithm value&lt;/h5&gt;
&lt;ul&gt;
  &lt;li&gt;If \(t^{(0)}\) is too small, the number of outer iterations increases.&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;If \(t^{(0)}\) is too large, it becomes the same problem as v.0. Therefore, Newton’s method requires many iterations to find \(x^{(0)}\) in the first centering step.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Fortunately, the performance of the actual barrier method is very robust to the choice of \(\mu\) and \(t^{(0)}\). Moreover, the appropriate range of these parameters varies depending on the problem size.&lt;/p&gt;

&lt;h2 id=&quot;example-of-small-lp&quot;&gt;Example of small LP&lt;/h2&gt;
&lt;p&gt;The following figure shows the performance when executing an LP problem with n=50 dimensions and m=100 inequality constraints using the barrier method. It can be confirmed that when \(\mu = 2\), the outer iterations increase, and when \(\mu=150\), the centering steps increase relatively compared to when \(\mu=50\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter15/15_barrier_method_03.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Example of small LP [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>15-03 Properties and interpretation</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_03_properties_and_interpretation/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_03_properties_and_interpretation</id>
   <content type="html">&lt;p&gt;At first glance, replacing a constrained optimization problem with a log-barrier objective \(tf(x) + \phi(x)\) looks like a rough heuristic approximation. How do we know \(x^*(t)\) is actually close to \(x^\star\)—and &lt;em&gt;how close&lt;/em&gt; is it? Section 15-03 reveals the magic behind the scenes: the optimality conditions of the barrier problem are &lt;em&gt;identical&lt;/em&gt; to the true KKT conditions except for a single controlled perturbation \(u_i h_i = -1/t\), which hands us an exact, universal suboptimality bound \(m/t\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-connecting-the-barrier-to-kkt--duality&quot;&gt;Key ideas: Connecting the Barrier to KKT &amp;amp; Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Dual Multipliers Born Automatically:&lt;/strong&gt; Every central-path point \(x^*(t)\) defines strictly positive dual variables \(u_i(t) = -\frac{1}{t h_i(x^*(t))} &amp;gt; 0\) without solving a separate dual problem.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Relaxed Complementary Slackness:&lt;/strong&gt; Instead of the sharp KKT condition \(u_i^\star h_i(x^\star) = 0\), the central path obeys the smooth hyperbolic condition \(u_i(t) h_i(x^*(t)) = -\frac{1}{t}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Exact Primal-Dual Gap (\(m/t\)):&lt;/strong&gt; Evaluating the Lagrange dual function at \((u(t), v(t))\) gives \(g(u(t), v(t)) = f(x^*(t)) - \frac{m}{t}\), proving \(f(x^*(t)) - f^\star \le \frac{m}{t}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Foundation for Primal-Dual IPMs:&lt;/strong&gt; Viewing the barrier method as homotopy continuation on \(u_i h_i = -\mu\) directly paves the road to Chapter 17’s Primal-Dual Interior-Point Methods.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-extracting-dual-variables-and-the-gap-on-a-1d-problem&quot;&gt;Worked example: Extracting Dual Variables and the Gap on a 1D Problem&lt;/h3&gt;

&lt;p&gt;Recall from Section 15-02 the 1D LP \(\min x\) s.t. \(h_1(x) = -x \le 0\), \(h_2(x) = x - 1 \le 0\) (\(m = 2\) constraints), where at \(t = 2\) we found \(x^*(2) = 1 - \frac{\sqrt{2}}{2} \approx 0.2929\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the barrier-induced dual multipliers \(u_i(t) = -\frac{1}{t h_i(x^*(t))}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(u_1(2) = -\frac{1}{2(-0.2929)} = \frac{1}{0.5858} \approx 1.7071 &amp;gt; 0\).&lt;/li&gt;
      &lt;li&gt;\(u_2(2) = -\frac{1}{2(0.2929 - 1)} = \frac{1}{1.4142} \approx 0.7071 &amp;gt; 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify KKT stationarity \(\nabla f(x) + u_1 \nabla h_1 + u_2 \nabla h_2 = 0\):&lt;/strong&gt;
\(1 + (1.7071)(-1) + (0.7071)(+1) = 1 - 1.7071 + 0.7071 = 0!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify perturbed complementarity and the \(m/t\) bound:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(u_1(2)h_1(x^*(2)) = -0.5 = -\frac{1}{t}\) and \(u_2(2)h_2(x^*(2)) = -0.5 = -\frac{1}{t}\).&lt;/li&gt;
      &lt;li&gt;Suboptimality gap: \(f(x^*(2)) - f^\star = 0.2929 - 0 = 0.2929 \le \frac{m}{t} = \frac{2}{2} = 1.0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we will derive the KKT conditions for the barrier problem and the original problem to see what differences exist. We will also calculate the suboptimality gap for the solutions to both problems.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-03-02 Suboptimality gap</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_03_02_suboptimality_gap/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_03_02_suboptimality_gap</id>
   <content type="html">&lt;p&gt;Most approximate optimization methods force you to guess whether your penalty weight \(t\) is large enough. The log barrier is different: it hands you an exact, ironclad formula—\(f(x^*(t)) - f^\star \le \frac{m}{t}\)—requiring zero knowledge of the optimal value \(f^\star\), the dimension \(n\), or the condition number of \(f\). Want an answer guaranteed within \(\epsilon = 10^{-6}\) on a problem with \(m = 50\) inequalities? Just drive \(t\) past \(5 \times 10^7\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-proving-and-using-the-mt-suboptimality-bound&quot;&gt;Key ideas: Proving and Using the \(m/t\) Suboptimality Bound&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Dual Feasibility of \((u(t), v(t))\):&lt;/strong&gt; Because \(x^*(t)\) minimizes the convex Lagrangian \(L(x, u(t), v(t))\) over all \(x\) (by stationarity), evaluating \(g(u(t), v(t))\) is immediate—no extra optimization required!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Exact Evaluation of the Dual Function:&lt;/strong&gt; Plugging \(x^*(t)\) into \(L\) gives
\(g(u(t), v(t)) = f(x^*(t)) + \sum_{i=1}^m \underbrace{u_i(t)h_i(x^*(t))}_{-1/t} + v(t)^T \underbrace{(Ax^*(t) - b)}_{0} = f(x^*(t)) - \frac{m}{t}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Immediate Suboptimality Certificate:&lt;/strong&gt; By weak duality \(g(u(t), v(t)) \le f^\star\), we get \(f(x^*(t)) - f^\star \le f(x^*(t)) - g(u(t), v(t)) = \frac{m}{t}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Direct Algorithmic Stopping Rule:&lt;/strong&gt; The outer loop of the barrier method simply checks \(\frac{m}{t} \le \epsilon\)—stopping with a mathematically certified \(\epsilon\)-optimal primal-dual pair.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-the-exact-dual-lower-bound-and-gap&quot;&gt;Worked example: Computing the Exact Dual Lower Bound and Gap&lt;/h3&gt;

&lt;p&gt;Using the problem from Section 15-03-01—\(\min \frac{1}{2}x^2\) subject to \(h_1(x) = 2 - x \le 0\) (\(m = 1\), true \(f^\star = \frac{1}{2}(2)^2 = 2\))—we found at \(t = 1\) that \(x^*(1) = 1 + \sqrt{2} \approx 2.4142\) and \(u_1(1) = 1 + \sqrt{2} \approx 2.4142\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the primal objective at \(x^*(1)\):&lt;/strong&gt;
\(f(x^*(1)) = \frac{1}{2}(1 + \sqrt{2})^2 = \frac{1}{2}(3 + 2\sqrt{2}) = 1.5 + \sqrt{2} \approx 2.9142.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the dual function \(g(u_1(1)) = L(x^*(1), u_1(1))\):&lt;/strong&gt;
\(g(u_1(1)) = f(x^*(1)) + u_1(1)h_1(x^*(1)) = (1.5 + \sqrt{2}) + (-1) = 0.5 + \sqrt{2} \approx 1.9142.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the duality gap vs. true suboptimality:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Certified duality gap: \(f(x^*(1)) - g(u_1(1)) = 2.9142 - 1.9142 = 1.0 = \frac{m}{t}\).&lt;/li&gt;
      &lt;li&gt;True suboptimality: \(f(x^*(1)) - f^\star = 2.9142 - 2.0 = 0.9142 \le 1.0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;How large must \(t\) be to guarantee \(\epsilon = 10^{-4}\)?&lt;/strong&gt; Simply \(t \ge \frac{m}{\epsilon} = \frac{1}{10^{-4}} = 10{,}000\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What is the suboptimality gap between \(f(x^*(t))\), the solution to the barrier problem obtained in the previous section, and \(f(x^*)\), the solution to the original problem?&lt;/p&gt;

&lt;p&gt;Therefore, we can derive the following equation.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(x^*) &amp;amp;\ge f(x^*(t)) + \nabla f(x^*(t))^T (x^* - x^*(t)) \\\\
h_i(x^*) &amp;amp;\ge h_i(x^*(t)) + \nabla h_i(x^*(t))^T (x^* - x^*(t)), \quad i = 1, \cdots, m
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;If convexity is guaranteed, the function is always greater than its tangent, so \(f(x^*) \ge f(x^*(t)) + \nabla f(x^*(t))^T (x^* - x^*(t))\) holds. (The tangent is the first-order Taylor approximation)&lt;/p&gt;

&lt;p&gt;Similarly, since \(h_i(x^*) \ge h_i(x^*(t)) + \nabla h_i(x^*(t))^T (x^* - x^*(t))\) holds, we can derive the following equation:&lt;/p&gt;

\[h_i(x^*(t)) - h_i(x^*) \le \nabla h_i(x^*(t))^T (x^*(t) - x^*), \quad i = 1, \cdots, m\]

&lt;h2 id=&quot;derivation-of-suboptimality-gap&quot;&gt;Derivation of suboptimality gap&lt;/h2&gt;

&lt;p&gt;Let’s use these two equations to derive the suboptimality gap. The right-hand side is derived from the two convexity conditions above.&lt;/p&gt;

\[\begin{align}
f(x^*(t)) - f(x^*) + \sum_{i=1}^{m} u_i(t) (h_i(x^*(t)) - h_i(x^*) ) &amp;amp;\le \left\langle \nabla f(x^*(t)) + \sum_{i=1}^{m} u_i(t) \nabla h_i(x^*(t)), \quad x^*(t) - x^* \right\rangle \\\\
&amp;amp;= \left\langle -tA^Tv, \quad x^*(t) - x^* \right\rangle \\\\
\end{align}\]

&lt;p&gt;If we look at the right-hand side of this equation as an inner product, since \(Ax^*(t) = b\) and \(Ax^* = b\), the entire term becomes zero.&lt;/p&gt;

&lt;p&gt;Therefore, moving the third term of the first equation to the right and simplifying, we get the following result:&lt;/p&gt;

\[\begin{align}
f(x^*(t)) - f(x^*) &amp;amp;\le - \sum_{i=1}^{m} u_i(t) (h_i(x^*(t)) - h_i(x^*) ) \\\\
&amp;amp;= \frac{m}{t} + \sum_{i=1}^{m} u_i(t) h_i(x^*) \\\\
&amp;amp;\le \frac{m}{t}
\end{align}\]

&lt;p&gt;The first term in the second line becomes \(\frac{m}{t}\) because it satisfies \(u_i(t) \cdot h_i(x^*(t)) = - \frac{1}{t}\) from the KKT conditions.&lt;/p&gt;

&lt;p&gt;The second term can be removed because \(\sum_{i=1}^{m} u_i(t) h_i(x^*) \le 0\) from the KKT conditions.&lt;/p&gt;

&lt;p&gt;As a result, we can obtain the following suboptimality gap, which becomes a useful stopping criterion for this problem. As a reference, the duality gap can also be derived in the next chapter.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(x^*(t)) - f(x^*) \le \frac{m}{t}
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>15-03-01 Perturbed KKT conditions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_03_01_perturbed_kkt_conditions/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/chapter16/15_03_01_perturbed_kkt_conditions</id>
   <content type="html">&lt;p&gt;Why are the exact KKT conditions so hard to solve directly with Newton’s method? Because complementary slackness \(u_i^\star h_i(x^\star) = 0\) forms a sharp L-shaped corner at the origin: either \(u_i = 0\) or \(h_i = 0\). The log barrier magically rounds that sharp L-corner into the smooth hyperbola \(u_i(t) h_i(x^*(t)) = -\frac{1}{t}\)—keeping every variable strictly nonzero so the Jacobian stays smooth and nonsingular!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-exact-kkt-vs-perturbed-kkt&quot;&gt;Key ideas: Exact KKT vs. Perturbed KKT&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Stationarity Matches Exactly:&lt;/strong&gt; Dividing the barrier optimality condition \(t\nabla f(x^*(t)) - \sum \frac{1}{h_i}\nabla h_i + A^T w = 0\) by \(t\) and setting \(u_i(t) = -\frac{1}{t h_i(x^*(t))}\), \(v(t) = \frac{1}{t}w\) yields exact KKT stationarity \(\nabla f + \sum u_i \nabla h_i + A^T v = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Strict Primal and Dual Feasibility:&lt;/strong&gt; Because \(h_i(x^*(t)) &amp;lt; 0\) and \(t &amp;gt; 0\), we automatically get \(u_i(t) &amp;gt; 0\)—meaning \((u(t), v(t))\) is &lt;em&gt;strictly dual feasible&lt;/em&gt; at every single point on the central path!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Hyperbolic Complementarity (\(u_i h_i = -1/t\)):&lt;/strong&gt; The sole difference between central-path KKT and true KKT is replacing \(0\) with \(-1/t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Smooth Limit to Optimality:&lt;/strong&gt; As \(t \to \infty\), the hyperbola \(u_i h_i = -1/t\) hugs the coordinate axes tighter and tighter until it collapses onto exact complementary slackness \(u_i^\star h_i(x^\star) = 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-checking-all-four-perturbed-kkt-conditions-explicitly&quot;&gt;Worked example: Checking All Four Perturbed KKT Conditions Explicitly&lt;/h3&gt;

&lt;p&gt;Consider \(\min_{x} \frac{1}{2}x^2\) subject to \(h_1(x) = 2 - x \le 0\) (i.e., \(x \ge 2\); true KKT solution: \(x^\star = 2, u_1^\star = 2\)). Solve the barrier problem at \(t = 1\): \(\min_{x &amp;gt; 2} \frac{1}{2}x^2 - \log(x - 2)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find \(x^*(1)\) from stationarity:&lt;/strong&gt;
\(x - \frac{1}{x - 2} = 0 \implies x^2 - 2x - 1 = 0 \implies x^*(1) = 1 + \sqrt{2} \approx 2.4142 \quad (\text{since } x &amp;gt; 2).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the central-path dual multiplier \(u_1(1)\):&lt;/strong&gt;
\(h_1(x^*(1)) = 2 - (1 + \sqrt{2}) = 1 - \sqrt{2} \approx -0.4142 &amp;lt; 0.\)
\(u_1(1) = -\frac{1}{1 \cdot (1 - \sqrt{2})} = \frac{1}{\sqrt{2} - 1} = \sqrt{2} + 1 \approx 2.4142 &amp;gt; 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify all four perturbed KKT conditions:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal feasibility: \(h_1(2.4142) = -0.4142 &amp;lt; 0\) (strictly feasible).&lt;/li&gt;
      &lt;li&gt;Dual feasibility: \(u_1(1) = 2.4142 &amp;gt; 0\) (strictly feasible).&lt;/li&gt;
      &lt;li&gt;Stationarity: \(\nabla f(x^*(1)) + u_1(1)\nabla h_1(x^*(1)) = (1 + \sqrt{2}) + (1 + \sqrt{2})(-1) = 0\) (exact!).&lt;/li&gt;
      &lt;li&gt;Perturbed complementarity: \(u_1(1) \cdot h_1(x^*(1)) = (\sqrt{2}+1)(1-\sqrt{2}) = 1 - 2 = -1 = -\frac{1}{t}\) (exact!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If we derive the KKT conditions from the barrier problem and the original formulation, we get the following.&lt;/p&gt;
&lt;h2 id=&quot;kkt-conditions-for-barrier-problem&quot;&gt;KKT conditions for barrier problem&lt;/h2&gt;
&lt;p&gt;The second term in the KKT conditions for the barrier problem is derived using the gradient of the log barrier function.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
t \nabla f(x^*(t)) - \sum_{i=1}^{m} \frac{1}{h_i(x^*(t))} \nabla h_i(x^*(t)) + A^Tw = 0  \\\ 
 Ax^*(t) = b, \quad h_i(x^*(t)) \lt 0, \quad i = 1, \cdots , m \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;kkt-conditions-for-the-original-problem&quot;&gt;KKT conditions for the original problem&lt;/h2&gt;
&lt;p&gt;In the KKT conditions for the original problem, complementary slackness gives \(h_i(x^*) \cdot u_i^* = 0\), but in practice, it is very difficult to know this boundary condition.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
\nabla f(x^*) + \sum_{i=1}^{m} u_i^* \nabla h_i(x^*) + A^Tv^* = 0 \\\ 
Ax^* = b, \quad h_i(x^*) \le 0, \quad u_i^* \ge 0,   \\\ 
h_i(x^*) \cdot u_i^* = 0,  \quad i = 1, \cdots , m \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;redefinition-of-kkt-conditions-for-barrier-problem&quot;&gt;Redefinition of KKT conditions for barrier problem&lt;/h2&gt;
&lt;p&gt;So, what is the relationship between these two KKT conditions?&lt;/p&gt;

&lt;p&gt;First, let \(u_i(t)\) and \(v\) be defined as follows:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
u_i(t) = - \frac{1}{t h_i(x^*(t))}, \quad v = \frac{1}{t}w
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Let’s redefine the KKT conditions for the barrier problem.&lt;/p&gt;

&lt;p&gt;Looking at the redefined problem, we see that the KKT conditions are almost identical to those for the original problem. In this equation, \(u_i(t) \cdot   h_i(x^*(t)) = - \frac{1}{t}\) becomes 0 as \(t \to \infty\), which matches \(h_i(x^*) \cdot u_i^* = 0\) in the original formulation.&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
&amp;amp; \nabla f(x^*(t)) + \sum_{i=1}^{m} u_i(t) \nabla h_i(x^*(t)) + tA^Tv = 0  \\\ 
&amp;amp; Ax^*(t) = b, \quad u_i(t) \cdot   h_i(x^*(t)) = - \frac{1}{t}, \quad h_i(x^*(t)) \lt 0, \quad u_i(t) \gt 0 , \quad i = 1, \cdots , m \\\
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>15-02 Central path</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_02_central_path/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_02_central_path</id>
   <content type="html">&lt;p&gt;Picture a hiker standing at the exact geographic center of a fenced valley (\(t \to 0^+\)) who slowly turns up the pull of gravity toward the lowest corner (\(t \to \infty\)). The smooth, curving trail they trace through the middle of the valley—never scraping a fence until the very last moment—is the &lt;strong&gt;central path&lt;/strong&gt; \(\{x^*(t) : t &amp;gt; 0\}\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-of-the-central-path&quot;&gt;Key ideas: Geometry of the Central Path&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Definition of the Central Path:&lt;/strong&gt; For each \(t &amp;gt; 0\), \(x^*(t) = \arg\min_{Ax=b} \big(tf(x) + \phi(x)\big)\) is the unique minimizer (under strict convexity of \(tf + \phi\)); varying \(t \in (0, \infty)\) sweeps out a smooth 1D curve in \(\mathbb{R}^n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Analytic Center Anchor (\(t \to 0^+\)):&lt;/strong&gt; At \(t = 0\), \(x^*(0)\) minimizes \(\phi(x)\) alone—the &lt;strong&gt;analytic center&lt;/strong&gt; of the feasible set, maximally balanced away from all constraint walls.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Geometric Tangency Condition:&lt;/strong&gt; At every point \(x^*(t)\) on the central path (for an LP \(\min c^T x\)), the optimality condition \(t c + \nabla \phi(x^*(t)) = 0\) means the objective hyperplane \(c^T x = c^T x^*(t)\) is &lt;em&gt;tangent&lt;/em&gt; to the barrier level curve \(\phi(x) = \phi(x^*(t))\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Convergence to the Optimal Face (\(t \to \infty\)):&lt;/strong&gt; As \(t \to \infty\), \(x^*(t)\) converges to the optimal solution \(x^\star\) (and if the optimum is a non-unique face, it converges specifically to the analytic center of the optimal face!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-tracing-an-exact-closed-form-central-path-on-an-lp&quot;&gt;Worked example: Tracing an Exact Closed-Form Central Path on an LP&lt;/h3&gt;

&lt;p&gt;Consider the 1D LP \(\min x\) subject to \(0 \le x \le 1\) (so \(h_1(x) = -x\), \(h_2(x) = x - 1\), true optimum \(x^\star = 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the central-path optimality equation \(\frac{d}{dx}\big(tx - \log x - \log(1-x)\big) = 0\):&lt;/strong&gt;
\(t - \frac{1}{x} + \frac{1}{1-x} = 0 \implies t x(1-x) - (1-x) + x = 0 \implies t x^2 - (t + 2)x + 1 = 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the quadratic formula (selecting the root in \((0, 1)\)):&lt;/strong&gt;
\(x^*(t) = \frac{(t + 2) - \sqrt{(t + 2)^2 - 4t}}{2t} = \frac{t + 2 - \sqrt{t^2 + 4}}{2t}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check both endpoints of the central path:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;As \(t \to 0^+\):&lt;/strong&gt; \(\sqrt{t^2 + 4} \approx 2 + \frac{t^2}{4}\), so \(x^*(t) \approx \frac{t}{2t} = 0.5\)—the exact analytic center of \([0, 1]\)!&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;At \(t = 2\):&lt;/strong&gt; \(x^*(2) = \frac{4 - \sqrt{8}}{4} = 1 - \frac{\sqrt{2}}{2} \approx 0.293\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;As \(t \to \infty\):&lt;/strong&gt; \(\sqrt{t^2 + 4} \approx t + \frac{2}{t}\), so \(x^*(t) \approx \frac{2}{2t} = \frac{1}{t} \to 0 = x^\star\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;If we denote the solution to the following barrier problem (\(t &amp;gt; 0\)) as \(x^*(t)\), then the &lt;strong&gt;central path&lt;/strong&gt; is the set $${x^*(t)&lt;/td&gt;
      &lt;td&gt;t &amp;gt; 0 }$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} \ &amp;amp;&amp;amp;  tf(x) + \phi(x) \\
&amp;amp;\text{subject to } \ &amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Given suitable conditions, the &lt;strong&gt;central path&lt;/strong&gt; set forms a smooth path in \(\mathbb{R}^n\), and as \(t \to \infty\), \(x^*(t) \to x^*\), where \(x^*\) is the solution to the original problem.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;central path&lt;/strong&gt; is a set of solutions obtained by gradually redefining the problem for new values of \(t\), moving from the interior toward the boundary when it is difficult to find the optimal solution at the boundary directly.&lt;/p&gt;

&lt;h2 id=&quot;example-central-path-for-an-lp&quot;&gt;Example: central path for an LP&lt;/h2&gt;
&lt;p&gt;Let’s find the central path for the following LP problem.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align*}
&amp;amp;\min_{x} \ &amp;amp;&amp;amp; c^Tx \\
&amp;amp;\text{subject to } \ &amp;amp;&amp;amp; a_i^Tx \le b_i, \quad i = 1, \cdots , 6 \\
\end{align*}\]
&lt;/blockquote&gt;

&lt;p&gt;In the following figure, the dotted line represents the logarithmic barrier function \(\phi\). &lt;br /&gt;&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter15/15_central_path_02.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Central path [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;You can see that as \(t \to \infty\), the central path converges to the optimal \(x^*\). At this point, the hyperplane \(c^Tx = c^Tx(t)\) is the tangent to the level curve of \(\phi\) passing through \(c^Tx(t)\).&lt;/p&gt;

&lt;h3 id=&quot;the-central-path-to-the-optimal-vertex-video&quot;&gt;The central path to the optimal vertex (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/central-path_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;As \(t\) grows, the solution \(x^*(t)\) of the barrier problem slides along the central path to the optimal vertex.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-slide-along-the-central-path&quot;&gt;Try it yourself: slide along the central path&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;barrier&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>15-01 Barrier method and log barrier function</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_01_barrier_method_and_log_barrier_function/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_01_barrier_method_and_log_barrier_function</id>
   <content type="html">&lt;p&gt;You already know how to use Newton’s method when constraints are linear equalities \(Ax = b\) (Chapter 14). How do we reuse that exact same Newton machinery when inequalities \(h_i(x) \le 0\) enter the picture? Instead of inventing a separate combinatorial solver to guess active constraints, we fold all \(m\) inequalities into the objective using a smooth &lt;strong&gt;logarithmic barrier&lt;/strong&gt;—reducing the hardest convex problem class to a sequence of equality-constrained Newton solves.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-bridging-equality-constrained-newton-to-inequalities&quot;&gt;Key ideas: Bridging Equality-Constrained Newton to Inequalities&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Reduction Strategy:&lt;/strong&gt; Inequality constraints \(h_i(x) \le 0\) are absorbed into the objective so that only linear equalities \(Ax = b\) remain explicit.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Strict Interior Domain:&lt;/strong&gt; Because \(\log(-h_i(x))\) is finite only when \(h_i(x) &amp;lt; 0\), every iterate stays strictly inside the feasible set—never touching or crossing a boundary wall.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Twice-Differentiable &amp;amp; Convex:&lt;/strong&gt; Whenever each \(h_i\) is convex and \(C^2\), the log barrier \(\phi(x) = -\sum_{i=1}^m \log(-h_i(x))\) is also convex and \(C^2\), making equality-constrained Newton directly applicable.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Parameterized Accuracy (\(t &amp;gt; 0\)):&lt;/strong&gt; Scaling \(f(x)\) by \(t\) (solving \(\min tf(x) + \phi(x)\) s.t. \(Ax = b\)) controls the trade-off between staying well-centered away from walls (small \(t\)) and hugging the true optimal boundary (large \(t\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-reducing-a-box-constrained-problem-to-unconstrained-smooth-minimization&quot;&gt;Worked example: Reducing a Box-Constrained Problem to Unconstrained Smooth Minimization&lt;/h3&gt;

&lt;p&gt;Consider minimizing \(f(x) = (x - 2)^2\) subject to \(-1 \le x \le 1\) (written as \(h_1(x) = x - 1 \le 0\) and \(h_2(x) = -x - 1 \le 0\); true constrained optimum is \(x^\star = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the logarithmic barrier on \((-1, 1)\):&lt;/strong&gt;
\(\phi(x) = -\log(1 - x) - \log(1 + x) = -\log(1 - x^2).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form the barrier subproblem for \(t = 1\):&lt;/strong&gt;
\(\min_{x \in (-1, 1)} \; (x - 2)^2 - \log(1 - x^2).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate at the center \(x = 0\) vs. near the wall \(x = 0.99\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;At \(x = 0\): objective is \((-2)^2 - \log(1) = 4.00\).&lt;/li&gt;
      &lt;li&gt;At \(x = 0.7\): objective is \((-1.3)^2 - \log(0.51) \approx 1.69 + 0.673 = 2.363\) (much lower!).&lt;/li&gt;
      &lt;li&gt;At \(x = 0.99\): objective is \((-1.01)^2 - \log(0.0199) \approx 1.02 + 3.917 = 4.937\) (the barrier wall repels \(x\) back inside!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; Smooth repulsion creates a clean interior minimum near \(x^*(1) \approx 0.71\) where Newton’s method converges effortlessly.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In the previous chapter, we explored how to solve an &lt;strong&gt;equality constrained smooth problem&lt;/strong&gt; using Newton’s method. In this chapter, we will look at methods for solving &lt;strong&gt;inequality and equality constrained smooth problems&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The basic idea is to transform the problem into an equality constrained smooth problem and solve it using Newton’s method. This approach is called the &lt;strong&gt;interior method&lt;/strong&gt;, and in this chapter, we will focus on one type of interior method: the &lt;strong&gt;barrier method&lt;/strong&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-01-03 Log barrier calculus</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_01_03_log_barrier_calculus/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_01_03_log_barrier_calculus</id>
   <content type="html">&lt;p&gt;To run Newton’s method on \(tf(x) + \phi(x)\), you need exact, bug-free formulas for \(\nabla \phi(x)\) and \(\nabla^2 \phi(x)\). Look closely at the Hessian of the log barrier: it automatically splits into a sum of positive-semidefinite rank-1 outer products \(\frac{1}{h_i(x)^2}\nabla h_i(x)\nabla h_i(x)^T\) plus positively weighted Hessians \(-\frac{1}{h_i(x)}\nabla^2 h_i(x)\) (since \(h_i(x) &amp;lt; 0\)). That structure explains &lt;em&gt;at a glance&lt;/em&gt; why \(\phi\) is always convex and why its curvature explodes right as you approach any constraint wall!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-derivatives-of-the-logarithmic-barrier&quot;&gt;Key ideas: Derivatives of the Logarithmic Barrier&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Barrier Gradient (Repulsive Force):&lt;/strong&gt; \(\nabla \phi(x) = \sum_{i=1}^m \frac{1}{-h_i(x)}\nabla h_i(x)\). Because \(-h_i(x) &amp;gt; 0\) is the slack to wall \(i\), approaching wall \(i\) (\(-h_i(x) \to 0^+\)) creates an enormous gradient pushing \(x\) inward along \(-\nabla h_i(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Barrier Hessian (Two PSD Terms):&lt;/strong&gt; \(\nabla^2 \phi(x) = \sum_{i=1}^m \frac{1}{h_i(x)^2}\nabla h_i(x)\nabla h_i(x)^T + \sum_{i=1}^m \frac{1}{-h_i(x)}\nabla^2 h_i(x)\). Every term is \(\succeq 0\) for convex \(h_i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Polyhedral Simplification (Linear Inequalities):&lt;/strong&gt; When \(h_i(x) = a_i^T x - b_i\), \(\nabla^2 h_i = 0\) vanishes, leaving the clean weighted Gram matrix \(\nabla^2 \phi(x) = A^T D^2 A\) where \(D_{ii} = \frac{1}{b_i - a_i^T x}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Nonnegative Orthant Special Case:&lt;/strong&gt; For \(x &amp;gt; 0\) (\(h_i(x) = -x_i\)), \(\nabla \phi(x) = -X^{-1}\mathbf{1}\) and \(\nabla^2 \phi(x) = X^{-2}\) (purely diagonal!), which makes linear-programming Newton systems remarkably fast to factor.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-nabla-phix-and-nabla2-phix-for-a-2d-triangle&quot;&gt;Worked example: Computing \(\nabla \phi(x)\) and \(\nabla^2 \phi(x)\) for a 2D Triangle&lt;/h3&gt;

&lt;p&gt;Consider the triangular feasible set \(x_1 \ge 0\), \(x_2 \ge 0\), and \(x_1 + x_2 \le 3\), so \(h_1(x) = -x_1\), \(h_2(x) = -x_2\), \(h_3(x) = x_1 + x_2 - 3\). Evaluate \(\nabla \phi\) and \(\nabla^2 \phi\) at the interior point \(x = (1, 1)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute slacks \(-h_i(x)\) and gradients \(\nabla h_i(x)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(-h_1(1,1) = 1\), \(\quad \nabla h_1 = (-1, 0)^T\).&lt;/li&gt;
      &lt;li&gt;\(-h_2(1,1) = 1\), \(\quad \nabla h_2 = (0, -1)^T\).&lt;/li&gt;
      &lt;li&gt;\(-h_3(1,1) = 3 - (1+1) = 1\), \(\quad \nabla h_3 = (1, 1)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the barrier gradient \(\nabla \phi(1,1) = \sum_{i=1}^3 \frac{1}{-h_i(x)}\nabla h_i(x)\):&lt;/strong&gt;
\(\nabla \phi(1,1) = \frac{1}{1}\begin{bmatrix} -1 \\ 0 \end{bmatrix} + \frac{1}{1}\begin{bmatrix} 0 \\ -1 \end{bmatrix} + \frac{1}{1}\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}!\)
Because \(\nabla \phi(1,1) = 0\), \(x = (1,1)^T\) is the exact &lt;strong&gt;analytic center&lt;/strong&gt; of this triangle!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the barrier Hessian \(\nabla^2 \phi(1,1) = \sum_{i=1}^3 \frac{1}{h_i(x)^2}\nabla h_i \nabla h_i^T\):&lt;/strong&gt;
\(\nabla^2 \phi(1,1) = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} + \begin{bmatrix} 0 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} + \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix} \succ 0.\)
Notice \(\det = 4 - 1 = 3 &amp;gt; 0\) and eigenvalues are \(1, 3 &amp;gt; 0\), confirming strict convexity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The gradient and Hessian of the log barrier function are as follows.&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\phi(x) = - \sum_{i=1}^{m} \log(-h_i(x))
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Gradient:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\nabla \phi(x) = - \sum_{i=1}^{m} \frac{1}{h_i(x)} \nabla h_i(x)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hessian:&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\nabla^2 \phi(x) = \sum_{i=1}^{m} \frac{1}{h_i(x)^2} \nabla h_i(x) \nabla h_i(x)^T -  \sum_{i=1}^{m} \frac{1}{h_i(x)} \nabla^2 h_i(x)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;example-phix---sum_i1n-logx_i&quot;&gt;Example: \(\phi(x) = -\sum_{i=1}^{n} \log(x_i)\)&lt;/h2&gt;
&lt;p&gt;If we compute the gradient and Hessian for the barrier function \(\phi(x) = -\sum_{i=1}^{n} \log(-x_i)\), we get the following results.&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\phi(x) = -\sum_{i=1}^{n} \log(x_i)
\end{align}
Therefore, \(h_i(x) =  -x_i\) and \(x_i \ge 0\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Gradient:&lt;/p&gt;
&lt;blockquote&gt;

\[\nabla \phi(x) = - 
\begin{bmatrix}
1/x_1 \\\
\vdots \\\
1/x_n \\\
\end{bmatrix}
 = -X^{-1} \mathbb{1}, \qquad X = \text{diag}(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Hessian :&lt;/p&gt;
&lt;blockquote&gt;

\[\nabla^2 \phi(x) = 
\begin{bmatrix}
1/x_1^2 &amp;amp; \cdots &amp;amp; \\\
\vdots &amp;amp; \ddots &amp;amp; \vdots  \\\
&amp;amp; \cdots &amp;amp; 1/x_n^2 \\\
\end{bmatrix}
 = X^{-2}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>15-01-02 Log barrier function & barrier method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_01_02_log_barrier_function_and_barrier_method/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_01_02_log_barrier_function_and_barrier_method</id>
   <content type="html">&lt;p&gt;Why specifically the &lt;em&gt;logarithm&lt;/em&gt; \(-\log(-h_i(x))\) instead of a simpler penalty like \(1/(-h_i(x))\)? Two miraculous mathematical facts single out the logarithm: its derivative \(-1/h_i(x)\) scales naturally to form dual multipliers with an exact \(m/t\) duality gap, and \(-\log(-u)\) is &lt;strong&gt;self-concordant&lt;/strong&gt;—meaning Newton’s method never loses its affine-invariant polynomial-time guarantee!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-the-log-barrier-formulation&quot;&gt;Key ideas: Anatomy of the Log-Barrier Formulation&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Exact Form of the Log Barrier:&lt;/strong&gt; For convex \(C^2\) inequalities \(h_1, \dots, h_m\), \(\phi(x) = -\sum_{i=1}^m \log(-h_i(x))\) has open convex domain \(\{x : h_i(x) &amp;lt; 0\ \forall i\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Equivalent Scaling (\(f + \frac{1}{t}\phi \iff tf + \phi\)):&lt;/strong&gt; Multiplying the objective by \(t &amp;gt; 0\) does not change the minimizer \(x^*(t)\), and keeps \(\phi(x)\) unscaled so its self-concordance constant stays fixed at \(1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Strictly Feasible Interior Assumption:&lt;/strong&gt; The barrier method requires Slater’s condition (a nonempty strict interior where \(h_i(x) &amp;lt; 0\) and \(Ax = b\)) so that \(\operatorname{dom}(\phi)\) is nonempty.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Convexity Preservation:&lt;/strong&gt; Because \(-\log(-u)\) is convex and nondecreasing on \((-\infty, 0)\) and each \(h_i\) is convex, the composition \(-\log(-h_i(x))\) is guaranteed convex by the scalar composition rule.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-the-barrier-subproblem-exactly-on-a-1d-interval&quot;&gt;Worked example: Solving the Barrier Subproblem Exactly on a 1D Interval&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = \frac{1}{2}x^2 - 3x\) subject to \(0 \le x \le 2\) (i.e., \(h_1(x) = -x \le 0\) and \(h_2(x) = x - 2 \le 0\)). Note the unconstrained minimum is \(x = 3\), so the true constrained optimum is \(x^\star = 2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the scaled barrier problem \(\min_{0 &amp;lt; x &amp;lt; 2} t\left(\frac{1}{2}x^2 - 3x\right) - \log(x) - \log(2 - x)\):&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Set the first derivative to zero:&lt;/strong&gt;
\(t(x - 3) - \frac{1}{x} + \frac{1}{2 - x} = 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the root \(x^*(t)\) at \(t = 1\) vs. \(t = 10\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;At \(t = 1\): test \(x = 1.5\): \(1(1.5 - 3) - \frac{1}{1.5} + \frac{1}{0.5} = -1.5 - 0.667 + 2.0 = -0.167 &amp;lt; 0\). Test \(x = 1.55\): \(-1.45 - 0.645 + 2.222 = +0.127 &amp;gt; 0\). So \(x^*(1) \approx 1.53\).&lt;/li&gt;
      &lt;li&gt;At \(t = 10\): test \(x = 1.9\): \(10(-1.1) - 0.526 + 10 = -1.526 &amp;lt; 0\). Test \(x = 1.92\): \(10(-1.08) - 0.521 + 12.5 = +1.179 &amp;gt; 0\). So \(x^*(10) \approx 1.91\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Watch the progression:&lt;/strong&gt; As \(t\) grows from \(1 \to 10 \to \infty\), \(x^*(t)\) moves smoothly from \(1.53 \to 1.91 \to 2.0 = x^\star\) while staying strictly inside \((0, 2)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Before introducing the barrier method, let’s first see how the indicator function can be approximated by a barrier function.&lt;/p&gt;

&lt;h2 id=&quot;approximation-of-indicator-function&quot;&gt;Approximation of indicator function&lt;/h2&gt;
&lt;p&gt;In the following figure, you can see the indicator function and the barrier function. The dotted line is the indicator function \(I_C\), and the solid lines are the barrier function \(\phi(x) = -1/t\log(-x)\) for \(t = 0.5, 1, 2\). The barrier function smoothly approximates the indicator function, and when \(t=2\), it provides the best approximation.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter15/15_barrier_function_01.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig 1] barrier function }\phi(x) = -1/t\log(-x) [1]$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;logarithmic-barrier-function&quot;&gt;Logarithmic barrier function&lt;/h2&gt;
&lt;p&gt;Suppose \(h_1, \cdots , h_m : \mathbb{R}^n \to \mathbb{R}\) are convex and twice differentiable. For the set \(\{x : h_i(x) \lt 0, i = 1, \cdots , m \}\), the following function is called the logarithmic barrier function.&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\phi(x) = - \sum_{i=1}^{m} \log(-h_i(x))
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, the set is assumed to be the interior of the feasible set \(C\) and is non-empty.&lt;/p&gt;

&lt;h2 id=&quot;barrier-method&quot;&gt;Barrier method&lt;/h2&gt;

&lt;p&gt;Using the barrier function, the original problem can be approximated as follows. Here, \(t\gt 0\).&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x}           &amp;amp;&amp;amp; f(x) + \frac{1}{t} \phi(x) &amp;amp; \qquad      &amp;amp; \min_{x} &amp;amp;&amp;amp; tf(x) + \phi(x) \\
&amp;amp;\text{subject to } &amp;amp;&amp;amp; Ax = b                     &amp;amp; \iff \qquad &amp;amp; \text{subject to } &amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The method of solving the problem defined in this way using Newton’s method is called the &lt;strong&gt;barrier method&lt;/strong&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>15-01-01 Inequality constrained minimization problems</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_01_01_inequality_constrained_minimization_problems/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter15/15_01_01_inequality_constrained_minimization_problems</id>
   <content type="html">&lt;p&gt;Consider a linear program in 100 dimensions with 200 inequality constraints. The feasible polytope can easily have more vertices than there are atoms in the observable universe! Active-set methods like Simplex walk along the boundary from vertex to vertex, trying to guess which subset of constraints is binding. Interior-point methods flip the script entirely: ignore the boundary, stay strictly inside the feasible region, and cut straight through the middle in 20–30 Newton steps.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-boundary-active-set-vs-interior-point-philosophy&quot;&gt;Key ideas: Boundary Active-Set vs. Interior-Point Philosophy&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The Binding-Constraint Bottleneck:&lt;/strong&gt; At \(x^\star\), some inequalities satisfy \(h_i(x^\star) = 0\) (active/binding) while others satisfy \(h_i(x^\star) &amp;lt; 0\) (inactive); identifying the active set combinatorially is expensive when \(m\) is large.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Indicator Reformulation:&lt;/strong&gt; Rewriting \(\min f(x)\) s.t. \(Ax = b, h_i(x) \le 0\) as \(\min f(x) + \sum_{i=1}^m I_{\mathbb{R}_-}(h_i(x))\) s.t. \(Ax = b\) hides the inequalities in an extended-value objective.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Why Indicators Break Newton:&lt;/strong&gt; The indicator \(I_{\mathbb{R}_-}(u)\) jumps discontinuously from \(0\) to \(+\infty\) at \(u = 0\)—it has neither a gradient nor a Hessian at the boundary.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Smooth Barrier Approximation:&lt;/strong&gt; Replacing \(I_{\mathbb{R}_-}(u)\) with \(-\frac{1}{t}\log(-u)\) smooths out the vertical cliff into a smooth \(C^\infty\) curve that approaches \(I_{\mathbb{R}_-}(u)\) pointwise as \(t \to \infty\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-measuring-how-closely--frac1tlog-u-approximates-i_mathbbr_-u&quot;&gt;Worked example: Measuring How Closely \(-\frac{1}{t}\log(-u)\) Approximates \(I_{\mathbb{R}_-}(u)\)&lt;/h3&gt;

&lt;p&gt;Compare the exact indicator \(I_{\mathbb{R}_-}(u)\) (which is \(0\) for \(u \le 0\) and \(+\infty\) for \(u &amp;gt; 0\)) with the barrier \(\hat{I}_t(u) = -\frac{1}{t}\log(-u)\) at three interior points: \(u = -1\), \(u = -0.1\), and \(u = -0.001\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;For \(t = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(u = -1\): \(\hat{I}_1(-1) = -\log(1) = 0\).&lt;/li&gt;
      &lt;li&gt;\(u = -0.1\): \(\hat{I}_1(-0.1) = -\log(0.1) \approx +2.303\) (strong early push away from wall).&lt;/li&gt;
      &lt;li&gt;\(u = -0.001\): \(\hat{I}_1(-0.001) \approx +6.908\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;For \(t = 100\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(u = -1\): \(\hat{I}_{100}(-1) = 0\).&lt;/li&gt;
      &lt;li&gt;\(u = -0.1\): \(\hat{I}_{100}(-0.1) \approx +0.023\) (almost flat zero—matching \(I_{\mathbb{R}_-}\)!).&lt;/li&gt;
      &lt;li&gt;\(u = -0.001\): \(\hat{I}_{100}(-0.001) \approx +0.069\), yet as \(u \to 0^-\) it &lt;em&gt;still&lt;/em&gt; shoots smoothly to \(+\infty\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Increasing \(t\) sharpens the bend right at the boundary \(u = 0\) without ever losing differentiability.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Let’s consider the following convex optimization problem.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;\min_{x}           &amp;amp;&amp;amp; f(x) \\ 
&amp;amp;\text{subject to } &amp;amp;&amp;amp; Ax = b \\
                    &amp;amp;&amp;amp;&amp;amp; h_{i}(x) \leq 0, i = 1, \dotsc, m
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In problems that include inequalities like this, it is difficult to distinguish between binding and non-binding constraints, especially at the boundary of the feasible region. Binding constraints refer to the constraints that affect the solution.&lt;/p&gt;

&lt;p&gt;Therefore, the &lt;strong&gt;interior method&lt;/strong&gt; is an approach that tries to solve the problem from the interior of the feasible region, not at the boundary.&lt;/p&gt;

&lt;h2 id=&quot;background-of-interior-method&quot;&gt;Background of interior method&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;interior method&lt;/strong&gt; for general problems was proposed in the 1960s by Anthony V. Fiacco and Garth P. McCormick. At the time, it was overshadowed by popular methods like sequential quadratic programming and the active set method, and only gained attention in the 1980s.&lt;/p&gt;

&lt;p&gt;The active set method is a theory for determining which constraints affect the optimization result. In the active set method, a constraint is considered active if it is zero, and such constraints are called the active set. However, to find the active set, you need to compute the boundary of the feasible region, and as the number of constraints increases, the computational cost increases.&lt;/p&gt;

&lt;p&gt;Recognizing these issues, the interior point method was developed to solve problems from the interior rather than the boundary. For example, in LP, if there are \(m\) constraints, calculating the boundary requires \(O(m^2)\) computations, but with the interior method, even for large \(m\), the solution can be found within 20–30 Newton steps. More details on performance will be discussed later.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Reference: &lt;a href=&quot;https://en.wikipedia.org/wiki/Interior-point_method&quot;&gt;Interior point method&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Reference: &lt;a href=&quot;https://en.wikipedia.org/wiki/Active_set_method&quot;&gt;Active set method&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;reducing-equality-constrained-minimization-problem&quot;&gt;Reducing equality constrained minimization problem&lt;/h2&gt;
&lt;p&gt;The above problem can be rewritten as \(C := \{x : h_i(x) \le 0, i = 1, \cdots , m \}\). Inequality constraints can be included in the objective function as an indicator function.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} \ &amp;amp;&amp;amp; f(x) + I_C(x) \\
&amp;amp;\text{subject to }\  &amp;amp;&amp;amp; Ax = b \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In this way, the problem can be transformed into an equality constrained minimization problem. However, since the indicator function still includes the boundary, it still has the difficulty of boundary computation from the original problem, and since it is not differentiable, it is difficult to apply Newton’s method.&lt;/p&gt;

&lt;p&gt;What if we approximate the indicator function \(I_C\) with a &lt;strong&gt;barrier function&lt;/strong&gt;? In that case, the boundary would not be included and since it is differentiable, Newton’s method can be applied.&lt;/p&gt;

&lt;p&gt;The method of solving problems redefined with barrier functions in this way is called the barrier method, which is introduced in detail in the next section.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-07 Bài Tập Thực Hành - Dual Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_07_Practical_Exercises_Dual_Methods/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_07_Practical_Exercises_Dual_Methods</id>
   <content type="html">&lt;p&gt;Để làm chủ hoàn toàn nhóm phương pháp đối ngẫu — từ phân rã song song (Dual Decomposition), hàm Lagrange tăng cường (Augmented Lagrangian) cho đến ADMM — không có cách nào hiệu quả hơn việc tự tay viết hàm Lagrange, tách các khối biến, tính phần dư ràng buộc và chạy thử một vài vòng lặp để tận mắt thấy nhân tử Lagrange tự điều chỉnh như thế nào. Bộ bài tập thực hành dưới đây tổng hợp các dạng bài kinh điển từ Bertsekas (1999) và Boyd et al. (2011).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-quy-tắc-kiểm-chứng-khi-giải-bài-tập-chương-20&quot;&gt;Kiến thức cần nhớ: Bốn quy tắc kiểm chứng khi giải bài tập Chương 20&lt;/h2&gt;

&lt;p&gt;Trước khi bước vào từng bài tập bên dưới, hãy giữ sẵn bốn nguyên tắc kiểm tra nhanh để không bao giờ bị nhầm dấu nhân tử:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thống nhất dấu hàm Lagrange ngay từ dòng đầu:&lt;/strong&gt; Với ràng buộc \(Ax = b\), nếu viết \(L(x, \nu) = f(x) + \nu^T(Ax - b)\) thì bước cập nhật tăng đối ngẫu luôn mang dấu &lt;strong&gt;cộng&lt;/strong&gt;: \(\nu^{(k+1)} = \nu^{(k)} + t_k(Ax^{(k+1)} - b)\). Nếu viết dấu trừ \(-\nu^T(Ax - b)\) thì bước cập nhật phải đổi thành dấu trừ!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện tồn tại cực tiểu của bước gốc:&lt;/strong&gt; Khi làm bài tập Dual Decomposition, luôn kiểm tra xem \(f_i(x_i) + \nu^T A_i x_i\) có lồi chặt để có nghiệm hữu hạn duy nhất không; nếu không, đó chính là dấu hiệu cần chuyển sang Augmented Lagrangian!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng điểm yên ngựa tại nghiệm tìm được:&lt;/strong&gt; Thay \((x^\star, \nu^\star)\) vào cả phương trình dừng \(\nabla_x L(x^\star, \nu^\star) = 0\) lẫn ràng buộc \(Ax^\star = b\), đồng thời kiểm tra \(f(x^\star) = g(\nu^\star)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh độ nhạy tham số \(\rho\):&lt;/strong&gt; Trong các bài tập lập trình Augmented Lagrangian và ADMM, thử chạy với \(\rho \in \{0.1, 1, 10\}\) và vẽ biểu đồ \(\|r^{(k)}\|_2\) cùng \(\|s^{(k)}\|_2\) theo số vòng lặp để cảm nhận trực tiếp sự đánh đổi giữa phần dư gốc và phần dư đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-khởi-động-bằng-phép-kiểm-tra-điểm-yên-ngựa-và-dấu-nhân-tử-lagrange&quot;&gt;Giải thích: Khởi động bằng phép kiểm tra điểm yên ngựa và dấu nhân tử Lagrange&lt;/h3&gt;

&lt;p&gt;Xét bài toán nhỏ \(\min_{x_1, x_2} x_1^2 + x_2^2\) với ràng buộc \(x_1 + 2x_2 = 5\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Viết hàm Lagrange đúng quy ước dấu cộng:&lt;/strong&gt;
\(L(x_1, x_2, \nu) = x_1^2 + x_2^2 + \nu(x_1 + 2x_2 - 5) = (x_1^2 + \nu x_1) + (x_2^2 + 2\nu x_2) - 5\nu.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tách hai bài toán con theo \(\nu\) cố định:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x_1(\nu) = \arg\min_{x_1} (x_1^2 + \nu x_1) = -\frac{\nu}{2}\).&lt;/li&gt;
      &lt;li&gt;\(x_2(\nu) = \arg\min_{x_2} (x_2^2 + 2\nu x_2) = -\nu\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm \(\nu^\star\) để thỏa mãn ràng buộc \(x_1(\nu) + 2x_2(\nu) = 5\):&lt;/strong&gt;
\(-\frac{\nu}{2} + 2(-\nu) = 5 \iff -\frac{5}{2}\nu = 5 \implies \nu^\star = -2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng chéo:&lt;/strong&gt; Thay \(\nu^\star = -2\) ta được \(x_1^\star = 1, x_2^\star = 2\), thỏa mãn \(1 + 2(2) = 5\). Giá trị gốc \(f(1, 2) = 1^2 + 2^2 = 5\); giá trị đối ngẫu \(g(-2) = L(1, 2, -2) = 5 + (-2)(0) = 5\) — khớp tuyệt đối! Giờ bạn đã sẵn sàng giải trọn bộ bài tập Chương 20.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---các-phương-pháp-đối-ngẫu&quot;&gt;Bài Tập Thực Hành - Các phương pháp đối ngẫu&lt;/h1&gt;

&lt;p&gt;Các bài tập được tham khảo từ Bertsekas (1999) và Boyd et al. (2011).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-1-phân-rã-đối-ngẫu-dual-decomposition&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Phân rã đối ngẫu (Dual Decomposition)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa \(\sum_{i=1}^N f_i(x_i)\) với ràng buộc \(\sum_{i=1}^N x_i = c\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết hàm Lagrange và hàm đối ngẫu.&lt;br /&gt;
b) Phân rã thành \(N\) bài toán con độc lập.&lt;br /&gt;
c) Viết công thức cập nhật biến đối ngẫu \(\nu\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Hàm Lagrange và hàm đối ngẫu:**

$$L(x, \nu) = \sum_i f_i(x_i) + \nu\left(\sum_i x_i - c\right) = \sum_i [f_i(x_i) + \nu x_i] - \nu c$$

$$g(\nu) = \sum_i \min_{x_i} [f_i(x_i) + \nu x_i] - \nu c$$

**b) Phân rã:** Với $$\nu$$ cố định, ta giải song song $$N$$ bài toán con độc lập:

$$x_i^{(k)} = \arg\min_{x_i} [f_i(x_i) + \nu^{(k)} x_i], \quad i = 1, \dots, N$$

**c) Cập nhật biến đối ngẫu:**

$$\nu^{(k+1)} = \nu^{(k)} + \alpha\left(\sum_i x_i^{(k)} - c\right)$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-hàm-lagrange-tăng-cường-augmented-lagrangian&quot;&gt;📝 &lt;strong&gt;Bài tập 2: Hàm Lagrange tăng cường (Augmented Lagrangian)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét bài toán \(\min f(x)\) với ràng buộc \(Ax = b\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết hàm Lagrange tăng cường \(L_\rho(x, \nu)\).&lt;br /&gt;
b) So sánh ưu điểm so với hàm Lagrange tiêu chuẩn.&lt;br /&gt;
c) Viết các bước lặp của phương pháp nhân tử (ALM).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Hàm Lagrange tăng cường:**

$$L_\rho(x, \nu) = f(x) + \nu^T(Ax - b) + \frac{\rho}{2}\|Ax - b\|^2$$

**b) So sánh ưu điểm:**

- **Hàm Lagrange tiêu chuẩn:** Hàm đối ngẫu $$g(\nu)$$ có thể không khả vi (khi $$f$$ không lồi chặt).
- **Hàm Lagrange tăng cường:** Tạo ra bài toán đối ngẫu trơn hơn và có số điều kiện tốt hơn, giúp hội tụ ổn định dưới các giả thiết nhẹ hơn.

**c) Các bước lặp của ALM:**

1. $$x^{(k+1)} = \arg\min_x L_\rho(x, \nu^{(k)})$$
2. $$\nu^{(k+1)} = \nu^{(k)} + \rho(Ax^{(k+1)} - b)$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-phương-pháp-nhân-tử-method-of-multipliers&quot;&gt;📝 &lt;strong&gt;Bài tập 3: Phương pháp nhân tử (Method of Multipliers)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Áp dụng ALM cho bài toán \(\min x_1^2 + x_2^2\) thỏa mãn \(x_1 + x_2 = 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Thiết lập hàm Lagrange tăng cường.&lt;br /&gt;
b) Thực hiện các bước lặp đầu tiên từ \(\nu^{(0)} = 0\) với \(\rho = 1\).&lt;br /&gt;
c) Nêu giá trị hội tụ của \((x^{(k)}, \nu^{(k)})\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Hàm Lagrange tăng cường ($$\rho = 1$$):**

$$L_\rho(x, \nu) = x_1^2 + x_2^2 + \nu(x_1 + x_2 - 1) + \frac{1}{2}(x_1 + x_2 - 1)^2$$

**b) Bước cực tiểu hóa theo $$x$$:**

Từ điều kiện dừng $$\nabla_x L_\rho = 0$$:

$$\nabla_x L_\rho = \big(2x_1 + \nu + (x_1 + x_2 - 1),\ 2x_2 + \nu + (x_1 + x_2 - 1)\big) = 0$$

$$3x_1 + x_2 = 1 - \nu, \qquad x_1 + 3x_2 = 1 - \nu$$

Suy ra nghiệm: $$x_1 = x_2 = \frac{1-\nu}{4}$$.

- **Vòng lặp 0:** Với $$\nu^{(0)} = 0$$ $$\Rightarrow$$ $$x^{(1)} = (0.25, 0.25)$$. Phần dư: $$0.5 - 1 = -0.5$$. Cập nhật: $$\nu^{(1)} = 0 + 1(-0.5) = -0.5$$.
- **Vòng lặp 1:** Với $$\nu^{(1)} = -0.5$$ $$\Rightarrow$$ $$x^{(2)} = (0.375, 0.375)$$. Phần dư: $$0.75 - 1 = -0.25$$. Cập nhật: $$\nu^{(2)} = -0.5 + 1(-0.25) = -0.75$$.

**c) Hội tụ:** Dãy lặp hội tụ nhanh về nghiệm tối ưu $$x^* = (0.5, 0.5)$$ và nhân tử tối ưu $$\nu^* = -1$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-so-sánh-dual-gradient-và-dual-newton&quot;&gt;📝 &lt;strong&gt;Bài tập 4: So sánh Dual Gradient và Dual Newton&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét bài toán cực đại hóa hàm đối ngẫu \(g(\nu)\) bằng phương pháp tăng gradient và phương pháp Newton.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết cập nhật Dual Gradient: \(\nu^{(k+1)} = \nu^{(k)} + \alpha \nabla g(\nu^{(k)})\).&lt;br /&gt;
b) Viết công thức Hessian \(\nabla^2 g(\nu)\) cho cập nhật Dual Newton: \(\nu^{(k+1)} = \nu^{(k)} - (\nabla^2 g(\nu^{(k)}))^{-1} \nabla g(\nu^{(k)})\).&lt;br /&gt;
c) So sánh sự đánh đổi giữa hai phương pháp.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Dual Gradient:**

$$\nabla g(\nu) = Ax^*(\nu) - b$$

$$\nu^{(k+1)} = \nu^{(k)} + \alpha(Ax^{(k)} - b)$$

Tốc độ hội tụ là tuyến tính (khi $$g$$ trơn và lõm mạnh) hoặc dưới tuyến tính như phương pháp subgradient nếu $$g$$ không trơn.

**b) Dual Newton:**

Lấy đạo hàm theo $$\nu$$ của $$\nabla g(\nu) = Ax^*(\nu) - b$$ (kết hợp vi phân ẩn của điều kiện dừng $$\nabla f(x^*) + A^T\nu = 0$$ cho $$\frac{\partial x^*}{\partial \nu} = -(\nabla^2 f(x^*))^{-1} A^T$$):

$$\nabla^2 g(\nu) = A \frac{\partial x^*(\nu)}{\partial \nu} = -A (\nabla^2 f(x^*))^{-1} A^T$$

Phương pháp đạt **hội tụ bậc hai cục bộ** nếu $$g$$ trơn (khả vi hai lần) và lõm mạnh.

**c) Đánh đổi:**

- **Dual Gradient:** Chi phí mỗi vòng lặp thấp, nhưng cần nhiều vòng lặp hơn.
- **Dual Newton:** Chi phí mỗi vòng lặp cao (phải tính và giải hệ với ma trận Hessian đối ngẫu), nhưng hội tụ rất nhanh gần nghiệm.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-tối-ưu-đồng-thuận-consensus-optimization&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Tối ưu đồng thuận (Consensus Optimization)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho \(N\) tác tử cùng cực tiểu hóa \(\sum_{i=1}^N f_i(x_i)\) với ràng buộc đồng thuận \(x_1 = x_2 = \cdots = x_N\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Thiết lập phân rã đối ngẫu trên đồ thị kết nối.&lt;br /&gt;
b) Viết quy tắc cập nhật phân tán.&lt;br /&gt;
c) Nêu đặc điểm truyền thông của thuật toán.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Hàm Lagrange và hàm đối ngẫu:**

$$L(x, \nu) = \sum_{i=1}^N f_i(x_i) + \sum_{i&amp;lt;j} \nu_{ij}(x_i - x_j) = \sum_{i=1}^N \left[ f_i(x_i) + \left(\sum_{j&amp;gt;i} \nu_{ij} - \sum_{j&amp;lt;i} \nu_{ji}\right) x_i \right]$$

$$g(\nu) = \sum_{i=1}^N \min_{x_i} \left[ f_i(x_i) + \left(\sum_{j&amp;gt;i} \nu_{ij} - \sum_{j&amp;lt;i} \nu_{ji}\right) x_i \right]$$

**b) Quy tắc cập nhật phân tán:**

Mỗi tác tử $$i$$ cập nhật độc lập:

$$x_i^{(k+1)} = \arg\min_{x_i} \left[ f_i(x_i) + \left(\sum_{j&amp;gt;i} \nu_{ij}^{(k)} - \sum_{j&amp;lt;i} \nu_{ji}^{(k)}\right) x_i \right]$$

Sau đó, với mỗi cặp tác tử kết nối $$(i, j)$$ ($$i &amp;lt; j$$), cập nhật nhân tử trên cạnh:

$$\nu_{ij}^{(k+1)} = \nu_{ij}^{(k)} + \rho(x_i^{(k+1)} - x_j^{(k+1)})$$

**c) Truyền thông:**

Mỗi tác tử chỉ cần trao đổi biến $$x_i$$ với các nút láng giềng trực tiếp trên đồ thị mà không cần máy chủ trung tâm, tạo thành sơ đồ đồng thuận phân tán.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Ý tưởng chính&lt;/th&gt;
      &lt;th&gt;Tốc độ hội tụ tiêu biểu&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Phân rã đối ngẫu (Dual decomposition)&lt;/td&gt;
      &lt;td&gt;Tách thành các bài toán con song song&lt;/td&gt;
      &lt;td&gt;Dưới tuyến tính (nếu không lồi chặt)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hàm Lagrange tăng cường (ALM)&lt;/td&gt;
      &lt;td&gt;Thêm số hạng phạt bậc hai&lt;/td&gt;
      &lt;td&gt;Tuyến tính / siêu tuyến tính&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual gradient&lt;/td&gt;
      &lt;td&gt;Phương pháp bậc nhất trên bài toán đối ngẫu&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\) (tuyến tính nếu lồi mạnh và trơn)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual Newton&lt;/td&gt;
      &lt;td&gt;Phương pháp bậc hai trên bài toán đối ngẫu&lt;/td&gt;
      &lt;td&gt;Bậc hai cục bộ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Bertsekas, D. P. (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt;. Athena Scientific.&lt;/li&gt;
  &lt;li&gt;Boyd, S., et al. (2011). “Distributed Optimization and Statistical Learning via ADMM”.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>20-05 Tài liệu tham khảo</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_05_References/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_05_References</id>
   <content type="html">&lt;p&gt;Sáu tài liệu tham khảo ngắn gọn ở cuối Chương 20 thực chất là một “bản đồ kho báu” thu nhỏ của hơn 10 năm nghiên cứu bùng nổ về ADMM và các phương pháp đối ngẫu. Từ cuốn cẩm nang 122 trang mang tính cách mạng của Boyd và cộng sự (2011) cho tới góc nhìn lý thuyết điều khiển tự động (Integral Quadratic Constraints) cực kỳ độc đáo của Nishihara và cộng sự (2015), mỗi bài báo mở ra một cách nhìn khác nhau về câu hỏi: &lt;em&gt;khi nào ADMM hội tụ tuyến tính và chọn \(\rho\) thế nào cho tối ưu?&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-dòng-nghiên-cứu-chính-trong-danh-mục-tài-liệu-chương-20&quot;&gt;Kiến thức cần nhớ: Ba dòng nghiên cứu chính trong danh mục tài liệu Chương 20&lt;/h2&gt;

&lt;p&gt;Để biết nên mở bài báo nào trước tùy theo nhu cầu học tập hay nghiên cứu của bạn, hãy phân nhóm sáu tài liệu theo ba trục sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nền tảng thực hành &amp;amp; cài đặt hệ thống (Boyd et al., 2010/2011; Vandenberghe EE 236C):&lt;/strong&gt; Đây là điểm khởi đầu tốt nhất cho kỹ sư và sinh viên: trình bày đầy đủ ADMM dạng có tỉ lệ, tiêu chuẩn dừng gốc–đối ngẫu, cập nhật \(\rho\) thích nghi và hàng loạt ứng dụng (Lasso, SVM, đồng thuận phân tán).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết hội tụ tuyến tính toàn cục (Deng &amp;amp; Yin, 2012; Hong &amp;amp; Luo, 2012; Iutzeler et al., 2014):&lt;/strong&gt; Trả lời câu hỏi lý thuyết quan trọng: ngoài tốc độ \(O(1/k)\) tổng quát, khi thêm giả thiết lồi mạnh và độ trơn trên một hoặc cả hai khối (kèm điều kiện hạng ma trận \(A, B\)), ADMM đạt hội tụ tuyến tính \(O(\gamma^k)\) với \(\gamma &amp;lt; 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích hội tụ tự động hóa bằng lý thuyết điều khiển (Nishihara et al., 2015):&lt;/strong&gt; Coi ADMM như một hệ thống động lực tuyến tính có phản hồi phi tuyến và dùng bài toán SDP nhỏ để tự động tìm tốc độ hội tụ chặt nhất cùng tham số \(\rho\) tối ưu!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-hai-chế-độ-hội-tụ-o1k-và-ogammak-trên-cùng-bài-toán&quot;&gt;Giải thích: So sánh hai chế độ hội tụ \(O(1/k)\) và \(O(\gamma^k)\) trên cùng bài toán&lt;/h3&gt;

&lt;p&gt;Để thấy ý nghĩa thực tiễn của các công trình chứng minh hội tụ tuyến tính (Deng &amp;amp; Yin 2012, Hong &amp;amp; Luo 2012, Nishihara et al. 2015), hãy so sánh số vòng lặp ước tính để giảm sai số từ \(1\) xuống \(10^{-6}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chế độ tổng quát không lồi mạnh (tốc độ dưới tuyến tính \(O(1/k)\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Sai số giảm cỡ \(\frac{1}{k} \le 10^{-6}\) đòi hỏi tới cỡ \(k \approx 10^6\) vòng lặp — đó là lý do ADMM tổng quát chỉ nên chạy đến độ chính xác trung bình \(10^{-3}\text{–}10^{-4}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chế độ có cấu trúc tốt (lồi mạnh + trơn, tốc độ tuyến tính \(\gamma^k\) với \(\gamma = 0.9\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Sai số giảm theo \((0.9)^k \le 10^{-6} \iff k \ge \frac{\ln(10^6)}{\ln(1/0.9)} \approx \mathbf{131}\) vòng lặp!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận khi đọc tài liệu:&lt;/strong&gt; Nếu bài toán thực tế của bạn có thể chọn tham số \(\rho\) tối ưu theo phổ giá trị riêng của \(A^T A\) (theo định lý trong Deng &amp;amp; Yin 2012 hoặc Nishihara et al. 2015), hệ số co \(\gamma\) còn có thể hạ từ \(0.9\) xuống \(0.6\), kéo số vòng lặp xuống dưới &lt;strong&gt;30 bước&lt;/strong&gt;!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;S. Boyd, N. Parikh, E. Chu, B. Peleato and J. Eckstein (2010), “Distributed optimization and statistical learning via the alternating direction method of multipliers”&lt;/li&gt;
  &lt;li&gt;W. Deng and W. Yin (2012), “On the global and linear convergence of the generalized alternating direction method of multipliers”&lt;/li&gt;
  &lt;li&gt;M. Hong and Z. Luo (2012), “On the linear convergence of the alternating direction method of multipliers”&lt;/li&gt;
  &lt;li&gt;F. Iutzeler, P. Bianchi, Ph. Ciblat, and W. Hachem (2014), “Linear convergence rate for distributed optimization with the alternating direction method of multipliers”&lt;/li&gt;
  &lt;li&gt;R. Nishihara, L. Lessard, B. Recht, A. Packard, and M. Jordan (2015), “A general analysis of the convergence of ADMM”&lt;/li&gt;
  &lt;li&gt;L. Vandenberghe, Lecture Notes for EE 236C, UCLA, Spring 2011-2012&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>20-04-04 Ví dụ: Chiếu luân phiên (Alternating Projection)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_04_04_Example-_Alternating_Projection/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_04_04_Example:_Alternating_Projection</id>
   <content type="html">&lt;p&gt;Tìm một điểm chung nằm trong giao của hai tập lồi \(C \cap D\) là bài toán kinh điển xuất hiện khắp nơi — từ khôi phục tín hiệu bị cắt xén đến kiểm tra tính khả thi của hệ bất đẳng thức. Cách cổ điển của von Neumann (1933) là &lt;strong&gt;chiếu luân phiên (alternating projection)&lt;/strong&gt;: chiếu lên \(C\), rồi chiếu lên \(D\), cứ lặp đi lặp lại. Nhưng khi hai tập cắt nhau ở góc nhọn, chiếu luân phiên bị zíc-zắc hàng trăm bước mới tới giao điểm! Bằng cách viết bài toán dưới dạng \(\min I_C(x) + I_D(z) \text{ s.t. } x = z\) và chạy ADMM dạng có tỉ lệ, ta thu được thuật toán chiếu có “bộ nhớ” \(w\) — thực chất tương đương với &lt;strong&gt;phương pháp Douglas–Rachford&lt;/strong&gt; nổi tiếng, hội tụ nhanh hơn hẳn!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-ý-tưởng-tạo-nên-sức-mạnh-của-admm-chiếu-luân-phiên&quot;&gt;Kiến thức cần nhớ: Ba ý tưởng tạo nên sức mạnh của ADMM chiếu luân phiên&lt;/h2&gt;

&lt;p&gt;Để hiểu rõ vì sao chỉ thêm một vector \(w^{(k)}\) nhỏ bé lại biến phép chiếu luân phiên cổ điển trở nên vượt trội, hãy xem ba điểm sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chỉ thị \(I_C(x)\) và toán tử chiếu Euclid \(P_C\):&lt;/strong&gt; Áp dụng ADMM dạng có tỉ lệ cho \(f = I_C, g = I_D\) với \(x = z\) biến bước \(\arg\min_x I_C(x) + \frac{\rho}{2}\|x - v\|_2^2\) thành đúng phép chiếu Euclid \(P_C(v)\). Đáng chú ý là tham số \(\rho\) &lt;strong&gt;tự triệt tiêu hoàn toàn&lt;/strong&gt; khỏi thuật toán!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cơ chế “nhắm vượt đích” nhờ biến đối ngẫu \(w\):&lt;/strong&gt; Thay vì chiếu trực tiếp \(z^{(k-1)}\) lên \(C\) như von Neumann, ADMM chiếu điểm đã được dịch chuyển \(z^{(k-1)} - w^{(k-1)}\) lên \(C\), rồi chiếu \(x^{(k)} + w^{(k-1)}\) lên \(D\). Sự dịch chuyển này tự động bẻ góc quỹ đạo zíc-zắc hướng thẳng vào giao điểm \(C \cap D\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mở rộng tự nhiên sang giao của \(m\) tập lồi:&lt;/strong&gt; Nếu cần tìm điểm chung của \(m\) tập lồi \(C_1, \dots, C_m\), ta chỉ cần áp dụng ADMM đồng thuận (Chương 21) để chiếu song song lên cả \(m\) tập rồi lấy trung bình cộng!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-so-sánh-chiếu-luân-phiên-cổ-điển-vs-admm-trên-hai-đường-thẳng-cắt-nhau&quot;&gt;Giải thích: Chạy tay so sánh Chiếu luân phiên cổ điển vs. ADMM trên hai đường thẳng cắt nhau&lt;/h3&gt;

&lt;p&gt;Trong mặt phẳng \(\mathbb{R}^2\), xét hai tập lồi là hai đường thẳng:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(C = \{(x_1, x_2) : x_2 = 0\}\) (trục hoành; phép chiếu \(P_C(a, b) = (a, 0)\)).&lt;/li&gt;
  &lt;li&gt;\(D = \{(x_1, x_2) : x_1 + x_2 = 2\}\) (phép chiếu \(P_D(a, b) = \left(\frac{a - b + 2}{2}, \; \frac{b - a + 2}{2}\right)\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Giao điểm duy nhất là \(C \cap D = \{(2, 0)\}\). Cùng xuất phát từ \(z^{(0)} = (0, 2)\) (và \(w^{(0)} = (0, 0)\) cho ADMM):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chiếu luân phiên cổ điển (von Neumann):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vòng 1: \(x^{(1)} = P_C(0, 2) = (0, 0)\); \(z^{(1)} = P_D(0, 0) = (1, 1)\).&lt;/li&gt;
      &lt;li&gt;Vòng 2: \(x^{(2)} = P_C(1, 1) = (1, 0)\); \(z^{(2)} = P_D(1, 0) = (1.5, 0.5)\).
(Mỗi vòng khoảng cách tới \((2, 0)\) chỉ giảm đúng một nửa — cần vô hạn bước mới chạm \((2, 0)\)!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ADMM chiếu luân phiên (dạng có tỉ lệ):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Vòng 1:&lt;/strong&gt;
        &lt;ul&gt;
          &lt;li&gt;\(x^{(1)} = P_C(z^{(0)} - w^{(0)}) = P_C(0, 2) = (0, 0)\).&lt;/li&gt;
          &lt;li&gt;\(z^{(1)} = P_D(x^{(1)} + w^{(0)}) = P_D(0, 0) = (1, 1)\).&lt;/li&gt;
          &lt;li&gt;\(w^{(1)} = w^{(0)} + x^{(1)} - z^{(1)} = (0, 0) + (0, 0) - (1, 1) = (-1, -1)\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Vòng 2:&lt;/strong&gt;
        &lt;ul&gt;
          &lt;li&gt;Điểm đích đã được dịch chuyển: \(z^{(1)} - w^{(1)} = (1, 1) - (-1, -1) = (2, 2)\)!&lt;/li&gt;
          &lt;li&gt;\(x^{(2)} = P_C(2, 2) = \mathbf{(2, 0)}\) — &lt;strong&gt;chạm trúng chính xác giao điểm \((2, 0)\) ngay ở vòng lặp thứ 2!&lt;/strong&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;ví-dụ-chiếu-luân-phiên&quot;&gt;Ví dụ: Chiếu luân phiên&lt;/h1&gt;

&lt;p&gt;Xét bài toán tìm một điểm thuộc giao của hai tập lồi \(C, D \subseteq \mathbb{R}^n\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_x I_C(x) + I_D(x)  &lt;br /&gt;
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(I_C(x)\) và \(I_D(x)\) lần lượt là hàm chỉ thị của hai tập \(C\) và \(D\).&lt;/p&gt;

&lt;p&gt;Để đưa bài toán về dạng ADMM, ta tách biến như sau:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{equation}
\min_{x,z} I_C(x) + I_D(z) \quad \text{subject to} \quad x - z = 0   
\end{equation}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;thuật-toán-admm-cho-bài-toán-chiếu-luân-phiên&quot;&gt;Thuật toán ADMM cho bài toán chiếu luân phiên&lt;/h2&gt;

&lt;p&gt;Mỗi vòng lặp ADMM (ở dạng có tỉ lệ) gồm hai phép chiếu liên tiếp và một bước cập nhật biến đối ngẫu:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; = P_C \left( z^{(k-1)} - w^{(k-1)} \right) \\
z^{(k)} &amp;amp; = P_D \left( x^{(k)} + w^{(k-1)} \right) \\
w^{(k)} &amp;amp; = w^{(k-1)} + x^{(k)} - z^{(k)}
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(P_C\) và \(P_D\) lần lượt là toán tử chiếu Euclid lên tập \(C\) và tập \(D\).&lt;/p&gt;

&lt;h2 id=&quot;suy-diễn&quot;&gt;Suy diễn&lt;/h2&gt;

&lt;p&gt;Bước cập nhật \(x^{(k)}\) thu được từ định nghĩa phép chiếu:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; = \arg\min_x I_C(x) + \frac{\rho}{2} \lVert x - z^{(k-1)} + w^{(k-1)} \rVert_2^2 \\
&amp;amp; = P_C \left( z^{(k-1)} - w^{(k-1)} \right)
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Tương tự, bước cập nhật \(z^{(k)}\) là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
z^{(k)} &amp;amp; = \arg\min_z I_D(z) + \frac{\rho}{2} \lVert x^{(k)} - z + w^{(k-1)} \rVert_2^2 \\
&amp;amp; = P_D \left( x^{(k)} + w^{(k-1)} \right)
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;so-sánh-với-phương-pháp-cổ-điển&quot;&gt;So sánh với phương pháp cổ điển&lt;/h2&gt;

&lt;p&gt;Thuật toán trên có cấu trúc gần giống phương pháp chiếu luân phiên cổ điển (chỉ thêm biến tích lũy độ lệch \(w^{(k)}\)), nhưng trong thực tế thường hội tụ nhanh và ổn định hơn.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-04-03 ADMM dạng có tỉ lệ (Scaled Form)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_04_03_ADMM_in_Scaled_Form/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_04_03_ADMM_in_Scaled_Form</id>
   <content type="html">&lt;p&gt;Nếu nhìn vào công thức ADMM ban đầu ở bài 20-04-01, bạn sẽ thấy hai số hạng hơi rườm rà luôn đi kèm nhau: số hạng tuyến tính \(u^T(Ax + Bz - c)\) và số hạng bình phương \(\frac{\rho}{2}\|Ax + Bz - c\|_2^2\). Chỉ bằng một phép đổi biến siêu gọn \(w = u / \rho\) và kỹ thuật &lt;strong&gt;tạo bình phương đầy đủ (completing the square)&lt;/strong&gt; của đại số phổ thông, hai số hạng đó gộp lại thành &lt;strong&gt;duy nhất một bình phương&lt;/strong&gt; \(\frac{\rho}{2}\|Ax + Bz - c + w\|_2^2\)! Dạng có tỉ lệ (scaled form) này ngắn hơn, ít sai dấu hơn khi viết code và làm lộ rõ ngay mối liên hệ giữa ADMM với toán tử proximal.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-lợi-ích-cốt-lõi-của-admm-dạng-có-tỉ-lệ&quot;&gt;Kiến thức cần nhớ: Ba lợi ích cốt lõi của ADMM dạng có tỉ lệ&lt;/h2&gt;

&lt;p&gt;Trước khi đọc phép chứng minh tương đương trong bài, hãy nắm rõ vì sao hầu hết bài báo và thư viện phần mềm đều dùng dạng có tỉ lệ:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa biến đối ngẫu có tỉ lệ \(w = u / \rho\):&lt;/strong&gt; Đưa hệ số \(\rho\) ra ngoài ngoặc biến \(u^T r + \frac{\rho}{2}\|r\|_2^2\) thành \(\frac{\rho}{2}\|r + w\|_2^2 - \frac{\rho}{2}\|w\|_2^2\). Vì \(-\frac{\rho}{2}\|w\|_2^2\) là hằng số không phụ thuộc vào \(x\) hay \(z\), ta bỏ luôn nó khỏi phép \(\arg\min\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải trực quan của \(w^{(k)}\) — tổng tích lũy phần dư (Running Sum of Residuals):&lt;/strong&gt; Phương trình cập nhật trở thành \(w^{(k)} = w^{(k-1)} + (Ax^{(k)} + Bz^{(k)} - c) = w^{(0)} + \sum_{j=1}^k r^{(j)}\). Nói cách khác, \(w^{(k)}\) chính là &lt;strong&gt;bộ tích phân sai số&lt;/strong&gt; (giống thành phần I trong bộ điều khiển PID), liên tục tích lũy độ lệch ràng buộc để kéo hệ thống về đúng \(r = 0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến bước cập nhật thành toán tử proximal ngay lập tức:&lt;/strong&gt; Khi ràng buộc là \(x = z\), bước \(x^{(k)} = \arg\min_x f(x) + \frac{\rho}{2}\|x - (z^{(k-1)} - w^{(k-1)})\|_2^2\) chính là \(\operatorname{prox}_{f, 1/\rho}(z^{(k-1)} - w^{(k-1)})\) — hoàn toàn không cần khai triển tích vô hướng!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-bằng-số-phép-gộp-bình-phương-và-theo-dõi-biến-tích-lũy-wk&quot;&gt;Giải thích: Kiểm chứng bằng số phép gộp bình phương và theo dõi biến tích lũy \(w^{(k)}\)&lt;/h3&gt;

&lt;p&gt;Giả sử tại một vòng lặp ADMM, ta có tham số phạt \(\rho = 2\), biến đối ngẫu ban đầu \(u = 4\) (suy ra biến có tỉ lệ \(w = u / \rho = 4 / 2 = 2\)), và ta đang xét một giá trị phần dư \(r = Ax + Bz - c = 1\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính theo dạng ban đầu (unscaled):&lt;/strong&gt;
\(u^T r + \frac{\rho}{2}\|r\|_2^2 = (4)(1) + \frac{2}{2}(1)^2 = 4 + 1 = 5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính theo dạng có tỉ lệ (scaled) kèm hằng số bù \(-\frac{\rho}{2}\|w\|_2^2\):&lt;/strong&gt;
\(\frac{\rho}{2}\|r + w\|_2^2 - \frac{\rho}{2}\|w\|_2^2 = \frac{2}{2}(1 + 2)^2 - \frac{2}{2}(2)^2 = 9 - 4 = 5.\)
Hai biểu thức bằng nhau từng đơn vị một — và vì \(-4\) không đổi khi ta thay đổi \(x\) hay \(z\), việc cực tiểu hóa \((r + 2)^2\) cho đúng nghiệm hệt như cực tiểu hóa \(4r + r^2\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thấy ngay vai trò “tích lũy sai số” của \(w\):&lt;/strong&gt; Nếu ở 3 vòng lặp đầu phần dư lần lượt là \(r^{(1)} = +0.6, \; r^{(2)} = +0.3, \; r^{(3)} = +0.1\) (khởi tạo \(w^{(0)} = 0\)), thì:
\(w^{(1)} = 0.6, \qquad w^{(2)} = 0.9, \qquad w^{(3)} = 1.0.\)
Ngay cả khi \(r^{(3)}\) nhỏ dần về \(0\), giá trị \(w^{(3)} = 1.0\) vẫn lưu giữ toàn bộ “áp lực” cần thiết để giữ điểm tối ưu đứng vững tại ràng buộc \(r = 0\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;admm-dạng-có-tỉ-lệ&quot;&gt;ADMM dạng có tỉ lệ&lt;/h1&gt;

&lt;p&gt;ADMM có thể được viết gọn hơn dưới dạng có tỉ lệ (scaled form) bằng cách đổi biến đối ngẫu \(w = u/\rho\). Khi đó, các bước lặp của ADMM trở thành:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; = \arg\min_x f(x) + \frac{\rho}{2} \lVert Ax + Bz^{(k-1)} - c + w^{(k-1)} \rVert_2^2  \\
z^{(k)} &amp;amp; = \arg\min_z g(z) + \frac{\rho}{2} \lVert Ax^{(k)} + Bz - c + w^{(k-1)} \rVert_2^2  \\
w^{(k)} &amp;amp; = w^{(k-1)} + Ax^{(k)} + Bz^{(k)} - c 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;chứng-minh-tương-đương-với-dạng-ban-đầu&quot;&gt;Chứng minh tương đương với dạng ban đầu&lt;/h2&gt;

&lt;p&gt;Khai triển số hạng bình phương ở bước cập nhật \(x^{(k)}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^{(k)} &amp;amp; = \arg\min_x f(x) + \frac{\rho}{2} \lVert Ax + Bz^{(k-1)} - c + w^{(k-1)} \rVert_2^2  \\
&amp;amp; = \arg\min_x f(x)  + \frac{\rho}{2} \lVert Ax + Bz^{(k-1)} - c \rVert_2^2  + \rho w^{(k-1)T} (Ax + Bz^{(k-1)} - c)  + \frac{\rho}{2}\lVert w^{(k-1)} \rVert_2^2 \\
&amp;amp; = \arg\min_x f(x)  + \frac{\rho}{2} \lVert Ax + Bz^{(k-1)} - c \rVert_2^2  + u^{(k-1)T} (Ax + Bz^{(k-1)} - c) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó ta thay \(u^{(k-1)} = \rho w^{(k-1)}\) và lược bỏ hằng số \(\frac{\rho}{2}\lVert w^{(k-1)} \rVert_2^2\) không phụ thuộc vào \(x\). Biến đổi cho bước cập nhật \(z^{(k)}\) hoàn toàn tương tự.&lt;/p&gt;

&lt;h2 id=&quot;ý-nghĩa-của-biến-đối-ngẫu-có-tỉ-lệ&quot;&gt;Ý nghĩa của biến đối ngẫu có tỉ lệ&lt;/h2&gt;

&lt;p&gt;Từ quy tắc cập nhật ở trên, \(w^{(k)}\) chính là tổng tích lũy các phần dư gốc từ đầu cho đến vòng lặp thứ \(k\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{equation}
w^{(k)} = w^{(0)} + \sum_{i=1}^k (Ax^{(i)} + Bz^{(i)} - c) 
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Dạng có tỉ lệ gọn gàng hơn và thường thuận tiện hơn cả trong phân tích lý thuyết lẫn cài đặt thuật toán.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-04-02 Đảm bảo hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_04_02_Converegence_Guarantee/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_04_02_Converegence_Guarantee</id>
   <content type="html">&lt;p&gt;Vì ADMM không giải đồng thời hàm Lagrange tăng cường mà tách ra cập nhật luân phiên \(x\) rồi \(z\), câu hỏi quan trọng mà mọi nhà toán học đều đặt ra là: &lt;em&gt;liệu sự “đi tắt” luân phiên đó có làm hỏng tính hội tụ hay đòi hỏi tham số phạt \(\rho\) phải chọn thật khéo không?&lt;/em&gt; Câu trả lời là một trong những tin vui lớn nhất của tối ưu hóa lồi: dưới những điều kiện cực kỳ nhẹ (\(f, g\) lồi đóng chính quy và hàm Lagrange có điểm yên ngựa — &lt;strong&gt;không cần \(f, g\) khả vi, không cần lồi mạnh, thậm chí không cần \(A, B\) có hạng đầy đủ&lt;/strong&gt;), ADMM đảm bảo hội tụ với &lt;strong&gt;mọi \(\rho &amp;gt; 0\)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-tiêu-chuẩn-hội-tụ-và-hai-phần-dư-kkt-của-admm&quot;&gt;Kiến thức cần nhớ: Ba tiêu chuẩn hội tụ và hai phần dư KKT của ADMM&lt;/h2&gt;

&lt;p&gt;Để theo dõi và chẩn đoán hội tụ của ADMM khi lập trình thực tế, cần nắm vững ba khái niệm sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ba khẳng định hội tụ cơ bản:&lt;/strong&gt; Với mọi \(\rho &amp;gt; 0\), khi \(k \to \infty\) ta luôn có: (1) phần dư gốc \(r^{(k)} = Ax^{(k)} + Bz^{(k)} - c \to 0\); (2) giá trị hàm mục tiêu \(f(x^{(k)}) + g(z^{(k)}) \to p^\star\); và (3) biến đối ngẫu \(u^{(k)} \to u^\star\). (Lưu ý: bản thân \(x^{(k)}, z^{(k)}\) chỉ chắc chắn hội tụ về nghiệm duy nhất nếu có thêm điều kiện như lồi chặt hoặc hạng cột đầy đủ.)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư gốc và phần dư đối ngẫu làm tiêu chuẩn dừng:&lt;/strong&gt; Điều kiện KKT cho bài toán ADMM tách làm hai độ lệch đo được ngay ở mỗi vòng lặp: phần dư gốc \(r^{(k)} = Ax^{(k)} + Bz^{(k)} - c\) và phần dư đối ngẫu \(s^{(k)} = \rho A^T B(z^{(k)} - z^{(k-1)})\). Khi cả \(\|r^{(k)}\|_2\) và \(\|s^{(k)}\|_2\) đủ nhỏ, ta có chứng chỉ chặt cho độ gần nghiệm tối ưu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghịch lý tốc độ của ADMM và vai trò của \(\rho\):&lt;/strong&gt; Dù hội tụ với mọi \(\rho &amp;gt; 0\), tốc độ thực tế lại rất nhạy với \(\rho\): \(\rho\) quá lớn ép \(r^{(k)}\) về \(0\) nhanh nhưng làm \(s^{(k)}\) chậm; \(\rho\) quá nhỏ thì ngược lại. ADMM thường đạt độ chính xác trung bình (\(10^{-3}\text{–}10^{-4}\)) rất nhanh trong vài chục bước, nhưng để đạt \(10^{-10}\) có thể chậm nếu không điều chỉnh \(\rho\) thích nghi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-trực-tiếp-phần-dư-gốc-rk-và-phần-dư-đối-ngẫu-sk&quot;&gt;Giải thích: Tính trực tiếp phần dư gốc \(r^{(k)}\) và phần dư đối ngẫu \(s^{(k)}\)&lt;/h3&gt;

&lt;p&gt;Quay lại bài toán \(x - z = 0\) (\(A = 1, B = -1, c = 0, \rho = 1\)) ở bài 20-04-01. Giả sử qua ba vòng lặp liên tiếp ta thu được:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Vòng \(0\): \(z^{(0)} = 2.0\)&lt;/li&gt;
  &lt;li&gt;Vòng \(1\): \(x^{(1)} = 1.0, \; z^{(1)} = 0.0\)&lt;/li&gt;
  &lt;li&gt;Vòng \(2\): \(x^{(2)} = -0.5, \; z^{(2)} = 0.0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hãy tính hai chỉ số dừng chuẩn (theo Boyd et al., 2011) tại vòng 1 và vòng 2:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tại vòng \(k = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Phần dư gốc: \(r^{(1)} = A x^{(1)} + B z^{(1)} - c = 1.0 - 0.0 = +1.0\) (chưa khớp ràng buộc \(x = z\)).&lt;/li&gt;
      &lt;li&gt;Phần dư đối ngẫu: \(s^{(1)} = \rho A^T B (z^{(1)} - z^{(0)}) = (1)(1)(-1)(0.0 - 2.0) = +2.0\) (khối \(z\) vừa thay đổi rất mạnh!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại vòng \(k = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Phần dư gốc: \(r^{(2)} = -0.5 - 0.0 = -0.5\) (độ lớn giảm một nửa từ \(1.0\) xuống \(0.5\)).&lt;/li&gt;
      &lt;li&gt;Phần dư đối ngẫu: \(s^{(2)} = (1)(1)(-1)(0.0 - 0.0) = 0.0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Diễn giải:&lt;/strong&gt; Tại vòng 2, dù phần dư đối ngẫu đã bằng \(0\) (chứng tỏ \(z\) đã ổn định đúng vị trí \(0\)), phần dư gốc $$&lt;/td&gt;
          &lt;td&gt;r^{(2)}&lt;/td&gt;
          &lt;td&gt;= 0.5\(vẫn còn lớn nên thuật toán chưa được dừng; chỉ khi cả\)&lt;/td&gt;
          &lt;td&gt;r^{(k)}&lt;/td&gt;
          &lt;td&gt;\le \epsilon_{\text{pri}}\(và\)&lt;/td&gt;
          &lt;td&gt;s^{(k)}&lt;/td&gt;
          &lt;td&gt;\le \epsilon_{\text{dual}}$$ thì mới dừng an toàn!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;đảm-bảo-hội-tụ-của-admm&quot;&gt;Đảm bảo hội tụ của ADMM&lt;/h1&gt;

&lt;p&gt;Dưới các điều kiện chuẩn rất nhẹ trên \(f\) và \(g\) (đáng chú ý là \(A\) và \(B\) không cần có hạng đầy đủ), ADMM đảm bảo các tính chất hội tụ sau với mọi \(\rho &amp;gt; 0\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hội tụ phần dư:&lt;/strong&gt; Khi \(k \to \infty\), \(r^{(k)} = Ax^{(k)} + Bz^{(k)} - c \to 0\), tức là các điểm lặp tiến dần về tập khả thi gốc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hội tụ giá trị hàm mục tiêu:&lt;/strong&gt; \(f(x^{(k)}) + g(z^{(k)}) \to f^{\ast} + g^{\ast}\), trong đó \(f^{\ast} + g^{\ast}\) là giá trị tối ưu của bài toán gốc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hội tụ biến đối ngẫu:&lt;/strong&gt; \(u^{(k)} \to u^{\ast}\), trong đó \(u^{\ast}\) là nghiệm tối ưu đối ngẫu.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tốc độ hội tụ tổng quát của ADMM phụ thuộc vào tính chất cụ thể của bài toán (như tính lồi mạnh hay độ trơn) và là chủ đề có nhiều kết quả nghiên cứu chuyên sâu. Về mặt thực hành, tốc độ hội tụ của ADMM thường tương đương hoặc nhỉnh hơn một chút so với các phương pháp bậc nhất.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-04-01 ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_04_01_ADMM/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_04_01_ADMM</id>
   <content type="html">&lt;p&gt;Ra đời từ giữa thập niên 1970 trong các công trình về phương trình đạo hàm riêng của Glowinski, Marroco, Gabay và Mercier, thuật toán &lt;strong&gt;ADMM (Alternating Direction Method of Multipliers)&lt;/strong&gt; từng ngủ yên hàng thập kỷ trước khi bùng nổ mạnh mẽ trong kỷ nguyên dữ liệu lớn nhờ bài tổng quan kinh điển của Stephen Boyd và cộng sự (2011). Bí quyết thành công của ADMM nằm ở cấu trúc ba dòng cực kỳ gọn nhẹ: một bước cực tiểu hóa theo \(x\), một bước cực tiểu hóa theo \(z\) (dùng ngay \(x^{(k)}\) vừa cập nhật), và một bước tăng biến đối ngẫu \(u\) với bước học đúng bằng tham số phạt \(\rho\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-cấu-trúc-ba-bước-của-admm&quot;&gt;Kiến thức cần nhớ: Giải phẫu cấu trúc ba bước của ADMM&lt;/h2&gt;

&lt;p&gt;Để ghi nhớ chắc chắn và cài đặt chính xác thuật toán ADMM chuẩn, hãy nhìn rõ vai trò từng thành phần trong hàm Lagrange tăng cường \(L_\rho(x, z, u)\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cặp bài toán tổng quát \(\min f(x) + g(z) \text{ s.t. } Ax + Bz = c\):&lt;/strong&gt; Khung này bao trùm hầu như mọi bài toán tối ưu lồi có cấu trúc — từ hồi quy có phạt (\(A = I, B = -I, c = 0\)), quy hoạch tuyến tính/bậc hai, cho đến tối ưu hóa phân tán nhiều nút.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ba bước cập nhật tuần tự (\(x \to z \to u\)):&lt;/strong&gt;
    &lt;ol&gt;
      &lt;li&gt;
\[x^{(k)} = \arg\min_x L_\rho(x, z^{(k-1)}, u^{(k-1)})\]
      &lt;/li&gt;
      &lt;li&gt;
\[z^{(k)} = \arg\min_z L_\rho(x^{(k)}, z, u^{(k-1)})\]
      &lt;/li&gt;
      &lt;li&gt;
\[u^{(k)} = u^{(k-1)} + \rho(Ax^{(k)} + Bz^{(k)} - c)\]
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vai trò của việc dùng \(x^{(k)}\) ngay trong bước \(z^{(k)}\):&lt;/strong&gt; Nếu dùng \(x^{(k-1)}\) (cập nhật song song kiểu Jacobi) thì ADMM có thể mất hội tụ; chính việc cập nhật tuần tự kiểu Gauss–Seidel kết hợp bước học \(t = \rho\) đảm bảo cặp \((z^{(k)}, u^{(k)})\) luôn thỏa mãn điều kiện tối ưu đối ngẫu cho khối \(z\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-1-vòng-lặp-admm-chuẩn-cho-bài-toán-tách-biến-lasso-1-chiều&quot;&gt;Giải thích: Chạy tay 1 vòng lặp ADMM chuẩn cho bài toán tách biến Lasso 1 chiều&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét bài toán $$\min_x \frac{1}{2}x^2 +&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((nghiệm tối ưu\)x^\star = 0\(). Tách biến thành dạng ADMM chuẩn với\)A = 1, B = -1, c = 0$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

\[\min_{x, z} \; \underbrace{\frac{1}{2}x^2}_{f(x)} + \underbrace{|z|}_{g(z)} \qquad \text{với điều kiện} \qquad x - z = 0.\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Chọn \(\rho = 1\), khởi tạo \(z^{(0)} = 2, u^{(0)} = 0\). Hàm Lagrange tăng cường là $$L_1(x, z, u) = \frac{1}{2}x^2 +&lt;/td&gt;
      &lt;td&gt;z&lt;/td&gt;
      &lt;td&gt;+ u(x - z) + \frac{1}{2}(x - z)^2$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Cập nhật \(x^{(1)}\) (cố định \(z^{(0)} = 2, u^{(0)} = 0\)):&lt;/strong&gt;
\(x^{(1)} = \arg\min_x \left\{ \frac{1}{2}x^2 + \frac{1}{2}(x - 2)^2 \right\} \implies x + (x - 2) = 0 \implies x^{(1)} = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Cập nhật \(z^{(1)}\) (dùng ngay \(x^{(1)} = 1\) và \(u^{(0)} = 0\)):&lt;/strong&gt;
\(z^{(1)} = \arg\min_z \left\{ |z| + \frac{1}{2}(1 - z)^2 \right\} = S_1(1) = \max(1 - 1, 0) = 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Cập nhật biến đối ngẫu \(u^{(1)}\):&lt;/strong&gt;
\(u^{(1)} = u^{(0)} + 1 \cdot (x^{(1)} - z^{(1)}) = 0 + (1 - 0) = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chạy thêm vòng 2 để thấy kết quả:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(2)} = \arg\min_x \left\{ \frac{1}{2}x^2 + 1\cdot x + \frac{1}{2}(x - 0)^2 \right\} \implies 2x + 1 = 0 \implies x^{(2)} = -0.5\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;$$z^{(2)} = \arg\min_z \left{&lt;/td&gt;
              &lt;td&gt;z&lt;/td&gt;
              &lt;td&gt;- 1\cdot z + \frac{1}{2}(-0.5 - z)^2 \right} = \arg\min_z \left{&lt;/td&gt;
              &lt;td&gt;z&lt;/td&gt;
              &lt;td&gt;+ \frac{1}{2}(z - 0.5)^2 \right} = S_1(0.5) = 0$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;\(u^{(2)} = 1 + (-0.5 - 0) = 0.5\). Cả \(x^{(k)}\) và phần dư \(x^{(k)} - z^{(k)}\) co nhanh về \(0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;phương-pháp-nhân-tử-hướng-luân-phiên-admm&quot;&gt;Phương pháp nhân tử hướng luân phiên (ADMM)&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp nhân tử hướng luân phiên (ADMM)&lt;/strong&gt; kết hợp ưu điểm của phân rã đối ngẫu (dual decomposition) và phương pháp nhân tử (method of multipliers). Thuật toán đặc biệt phù hợp với các bài toán tối ưu lồi có thể tách thành những bài toán con nhỏ hơn, dễ giải hơn.&lt;/p&gt;

&lt;p&gt;Xét bài toán tối ưu có cấu trúc hai khối biến:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_{x,z} f(x) + g(z) \quad \text{subject to} \quad Ax + Bz = c
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tương tự phương pháp hàm Lagrange tăng cường, ta cộng thêm số hạng phạt bậc hai vào hàm mục tiêu (với tham số phạt \(\rho &amp;gt; 0\)):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_{x,z} f(x) + g(z) + \frac{\rho}{2} \lVert Ax + Bz - c \rVert_2^2 \quad \text{subject to} \quad Ax + Bz = c
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;hàm-lagrange-tăng-cường-augmented-lagrangian&quot;&gt;Hàm Lagrange tăng cường (Augmented Lagrangian)&lt;/h2&gt;

&lt;p&gt;Hàm Lagrange tăng cường tương ứng được định nghĩa là:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
L_{\rho} (x,z,u) = f(x) + g(z) + u^T(Ax + Bz - c) + \frac{\rho}{2} \lVert Ax + Bz - c \rVert_2^2
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;thuật-toán-admm&quot;&gt;Thuật toán ADMM&lt;/h2&gt;

&lt;p&gt;ADMM lặp lại ba bước sau với \(k = 1, 2, 3, \ldots\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; = \arg\min_x  L_{\rho} (x,z^{(k-1)},u^{(k-1)}) \\
z^{(k)} &amp;amp; = \arg\min_z  L_{\rho} (x^{(k)},z,u^{(k-1)}) \\
u^{(k)} &amp;amp; = u^{(k-1)} + \rho (Ax^{(k)} + Bz^{(k)} - c) 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Điểm mấu chốt:&lt;/strong&gt; Nghiệm \(x^{(k)}\) vừa tính ở bước thứ nhất được sử dụng ngay trong bước thứ hai để cập nhật \(z^{(k)}\). Cơ chế cập nhật luân phiên (kiểu Gauss–Seidel) này là yếu tố thiết yếu đảm bảo tính hội tụ của ADMM.&lt;/p&gt;

&lt;h2 id=&quot;so-sánh-với-phương-pháp-nhân-tử&quot;&gt;So sánh với phương pháp nhân tử&lt;/h2&gt;

&lt;p&gt;Trong &lt;strong&gt;phương pháp nhân tử (Method of Multipliers)&lt;/strong&gt; thông thường, hai bước đầu tiên được gộp thành một bài toán cực tiểu hóa đồng thời theo cả \((x, z)\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
(x^{(k)}, z^{(k)}) = \arg\min_{x,z} L_{\rho} (x,z,u^{(k-1)})   &lt;br /&gt;
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ưu điểm chính của ADMM là tách phép cực tiểu hóa đồng thời đó thành hai bài toán con riêng biệt theo \(x\) và \(z\), nhờ đó thường giải nhanh hơn đáng kể hoặc thậm chí có nghiệm dạng đóng.&lt;/p&gt;

&lt;h3 id=&quot;admm-tổng-quát-trong-khoảng-3-phút&quot;&gt;ADMM tổng quát trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/admm-general_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Lagrangian tăng cường, ba bước cập nhật x, z, u, và bài đồng thuận ba máy: giá u, nghiệm 12/7, và ảnh hưởng của ρ.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-04 Nhìn thoáng qua ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_04_00_A_peak_at_ADMM/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_04_00_A_peak_at_ADMM</id>
   <content type="html">&lt;p&gt;Đến cuối bài 20-03, ta đứng trước một thế lưỡng nan kinh điển của tối ưu hóa: &lt;strong&gt;Dual Decomposition&lt;/strong&gt; tách bài toán song song rất đẹp nhưng hay bị phân kỳ khi hàm không lồi mạnh; còn &lt;strong&gt;Augmented Lagrangian&lt;/strong&gt; hội tụ cực kỳ bền bỉ nhưng số hạng bình phương \(\frac{\rho}{2}\|Ax - b\|_2^2\) lại dính các biến lại thành một khối không tách được. &lt;strong&gt;ADMM (Alternating Direction Method of Multipliers)&lt;/strong&gt; chính là “phép lai hoàn hảo” dung hòa cả hai thế giới: giữ lại số hạng phạt bậc hai để bảo toàn độ bền hội tụ, nhưng thay vì cực tiểu hóa đồng thời theo tất cả biến, ta &lt;strong&gt;cập nhật luân phiên từng khối một&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-ý-tưởng-tạo-nên-cú-hích-của-admm&quot;&gt;Kiến thức cần nhớ: Ba ý tưởng tạo nên cú hích của ADMM&lt;/h2&gt;

&lt;p&gt;Phần 20-04 đặt nền móng cho một trong những thuật toán phổ biến nhất của khoa học dữ liệu hiện đại qua ba trục chính:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tách biến có cấu trúc hai khối (\(\min f(x) + g(z) \text{ s.t. } Ax + Bz = c\)):&lt;/strong&gt; Phần lớn bài toán học máy đều tự nhiên tách thành hai phần — ví dụ hàm mất mát trơn \(f(x)\) cộng hàm điều chuẩn không trơn \(g(z)\) với ràng buộc \(x = z\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật luân phiên kiểu Gauss–Seidel:&lt;/strong&gt; Thay vì giải đồng thời \(\min_{x, z} L_\rho(x, z, u)\), ADMM cố định \(z\) để giải bài toán con chỉ phụ thuộc \(f(x)\), sau đó dùng ngay \(x^{(k)}\) vừa tìm được để giải bài toán con chỉ phụ thuộc \(g(z)\), rồi mới cập nhật biến đối ngẫu \(u^{(k)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối sang toán tử proximal và tối ưu phân tán:&lt;/strong&gt; Khi đưa về dạng có tỉ lệ (scaled form, bài 20-04-03), mỗi bước cập nhật của ADMM lộ diện chính là một phép tính toán tử proximal hoặc chiếu lên tập lồi — mở ra vô số ứng dụng từ chiếu luân phiên đến Lasso và học liên bang ở Chương 21.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-quan-sát-cách-cập-nhật-luân-phiên-phá-vỡ-sự-liên-kết-của-số-hạng-phạt-bậc-hai&quot;&gt;Giải thích: Quan sát cách cập nhật luân phiên phá vỡ sự liên kết của số hạng phạt bậc hai&lt;/h3&gt;

&lt;p&gt;Xét bài toán 2 biến \(\min_{x, z} f(x) + g(z)\) với ràng buộc \(x + z = 2\) và phạt \(\rho = 2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vì sao Augmented Lagrangian đồng thời bị kẹt?&lt;/strong&gt;
Số hạng phạt \(\frac{\rho}{2}(x + z - 2)^2 = x^2 + z^2 + 2xz - 4x - 4z + 4\) chứa tích chéo \(2xz\). Do đó nếu giải đồng thời theo \((x, z)\), ta không thể tách bài toán của \(f(x)\) ra khỏi bài toán của \(g(z)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách ADMM tháo gỡ nút thắt:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Pha 1 (cố định \(z = z^{(k-1)}\)):&lt;/strong&gt; Khi \(z\) đã là một hằng số, số hạng \((x + z^{(k-1)} - 2)^2\) chỉ còn là một parabol đơn giản theo \(x\)! Bài toán con hoàn toàn độc lập với \(g(z)\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Pha 2 (cố định \(x = x^{(k)}\) mới nhất):&lt;/strong&gt; Tương tự, bài toán con chỉ còn là \(g(z)\) cộng một parabol đơn giản theo \(z\), hoàn toàn độc lập với \(f(x)\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Pha 3 (cập nhật \(u\)):&lt;/strong&gt; Tích lũy phần dư \(u^{(k)} = u^{(k-1)} + \rho(x^{(k)} + z^{(k)} - 2)\).
Nhờ cập nhật luân phiên, ta vừa giữ được tính bền bỉ của \(\rho &amp;gt; 0\), vừa khai thác triệt để cấu trúc riêng của từng hàm \(f\) và \(g\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tổng-quan-về-admm&quot;&gt;Tổng quan về ADMM&lt;/h2&gt;
&lt;p&gt;Trong phần này, chúng ta tìm hiểu tổng quan về &lt;strong&gt;phương pháp nhân tử hướng luân phiên (Alternating Direction Method of Multipliers — ADMM)&lt;/strong&gt;. Trong khi phương pháp hàm Lagrange tăng cường (augmented Lagrangian) làm mất tính khả phân của bài toán, ADMM kết hợp được đồng thời cả tính khả phân theo khối biến lẫn tính hội tụ vững chắc.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-03 Augmented Lagrangian</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_03_Augmented_Lagrangians/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_03_Augmented_Lagrangians</id>
   <content type="html">&lt;p&gt;Phương pháp tăng đối ngẫu (dual ascent) có một gót chân Achilles cực kỳ khó chịu: nếu hàm mục tiêu \(f(x)\) không lồi mạnh (chẳng hạn \(f(x)\) tuyến tính hoặc có đoạn phẳng), bài toán con \(\min_x (f(x) + u^T Ax)\) có thể &lt;strong&gt;vô nghiệm (tiến tới \(-\infty\))&lt;/strong&gt; hoặc nhảy loạn xạ không bao giờ hội tụ! Năm 1969, Magnus Hestenes và Michael Powell độc lập đề xuất một cú “cứu nguy” thiên tài: cộng thêm một số hạng phạt bậc hai \(\frac{\rho}{2}\|Ax - b\|_2^2\) vào hàm mục tiêu. Số hạng này &lt;strong&gt;bằng 0 hoàn toàn&lt;/strong&gt; tại mọi điểm khả thi \(Ax = b\) (nên không làm thay đổi nghiệm tối ưu), nhưng lại biến hàm mục tiêu thành lồi trơn hơn rất nhiều — đó là &lt;strong&gt;phương pháp hàm Lagrange tăng cường (Augmented Lagrangian / Method of Multipliers)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-phương-pháp-nhân-tử-augmented-lagrangian&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của Phương pháp Nhân tử (Augmented Lagrangian)&lt;/h2&gt;

&lt;p&gt;Hiểu bốn điểm sau sẽ giúp bạn nắm trọn cả ưu điểm lẫn cái giá phải trả của Augmented Lagrangian:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tương đương tuyệt đối về nghiệm tối ưu:&lt;/strong&gt; Vì ràng buộc \(Ax = b\) vẫn được giữ nguyên, việc thêm \(\frac{\rho}{2}\|Ax - b\|_2^2\) không gây ra sai số xấp xỉ như phương pháp phạt thuần túy (penalty method — vốn phải đẩy \(\rho \to \infty\) gây suy biến số học). Ở đây, chỉ cần một hằng số \(\rho &amp;gt; 0\) hữu hạn là đủ đạt nghiệm chính xác!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước học tự nhiên \(t_k = \rho\):&lt;/strong&gt; Điều kiện dừng của bước gốc \(0 \in \partial f(x^{(k)}) + A^T\big(u^{(k-1)} + \rho(Ax^{(k)} - b)\big)\) cho thấy nếu đặt \(u^{(k)} = u^{(k-1)} + \rho(Ax^{(k)} - b)\), thì cặp \((x^{(k)}, u^{(k)})\) &lt;strong&gt;tự động thỏa mãn điều kiện khả thi đối ngẫu&lt;/strong&gt; ở ngay mỗi vòng lặp!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ vững chắc dưới điều kiện rất nhẹ:&lt;/strong&gt; Không còn yêu cầu \(f\) phải lồi chặt hay hữu hạn ở mọi nơi; chỉ cần \(f\) lồi đóng và bài toán có nghiệm là phương pháp nhân tử hội tụ bền bỉ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhược điểm duy nhất — đánh mất tính phân rã:&lt;/strong&gt; Số hạng \(\frac{\rho}{2}\|\sum_i A_i x_i - b\|_2^2\) khi bình phương lên sẽ sinh ra các tích chéo \(x_i^T A_i^T A_j x_j\) trói chặt mọi khối biến lại với nhau — chính nhược điểm này sẽ khai sinh ra ADMM ở bài tiếp theo!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-cứu-một-bài-toán-mà-dual-ascent-thất-bại-hoàn-toàn-chỉ-trong-2-bước&quot;&gt;Giải thích: Cứu một bài toán mà Dual Ascent thất bại hoàn toàn chỉ trong 2 bước&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu tuyến tính 1 biến đơn giản nhất có thể:&lt;/p&gt;

\[\min_{x \in \mathbb{R}} \; f(x) = x \qquad \text{với điều kiện} \qquad x = 2.\]

&lt;p&gt;Nghiệm hiển nhiên là \(x^\star = 2, u^\star = -1\). Hãy so sánh hai phương pháp cùng khởi tạo từ \(u^{(0)} = 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thử chạy Dual Ascent thường:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bước gốc phải giải \(\min_x (x + 0 \cdot x) = \min_x x = -\infty\)! Thuật toán &lt;strong&gt;sập ngay ở vòng lặp đầu tiên&lt;/strong&gt; vì \(f(x) = x\) không lồi chặt.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chạy Augmented Lagrangian với \(\rho = 1\):&lt;/strong&gt;
Hàm Lagrange tăng cường là \(L_1(x, u) = x + u(x - 2) + \frac{1}{2}(x - 2)^2\).
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Vòng 1 (\(u^{(0)} = 0\)):&lt;/strong&gt;
        &lt;ul&gt;
          &lt;li&gt;Bước gốc: \(x^{(1)} = \arg\min_x \left(x + \frac{1}{2}(x - 2)^2\right)\). Đạo hàm \(1 + (x - 2) = 0 \implies x^{(1)} = 1\) (hữu hạn và duy nhất!).&lt;/li&gt;
          &lt;li&gt;Bước đối ngẫu (dùng bước học \(t = \rho = 1\)): \(u^{(1)} = 0 + 1(1 - 2) = -1\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Vòng 2 (\(u^{(1)} = -1\)):&lt;/strong&gt;
        &lt;ul&gt;
          &lt;li&gt;Bước gốc: \(x^{(2)} = \arg\min_x \left(x - (x - 2) + \frac{1}{2}(x - 2)^2\right) = \arg\min_x \left(2 + \frac{1}{2}(x - 2)^2\right) = 2 = x^\star\)!&lt;/li&gt;
          &lt;li&gt;Phần dư ràng buộc \(x^{(2)} - 2 = 0\), nhân tử \(u^{(2)} = -1 = u^\star\) — &lt;strong&gt;đạt nghiệm tối ưu chính xác chỉ sau 2 vòng lặp&lt;/strong&gt; mà không cần đẩy \(\rho \to \infty\)!&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Nhược điểm lớn của phương pháp tăng đối ngẫu (dual ascent) là đòi hỏi điều kiện mạnh — chẳng hạn \(f\) phải lồi mạnh — để đảm bảo hội tụ. &lt;strong&gt;Phương pháp hàm Lagrange tăng cường (Augmented Lagrangian)&lt;/strong&gt;, còn gọi là &lt;strong&gt;phương pháp nhân tử (method of multipliers)&lt;/strong&gt;, khắc phục hạn chế này.&lt;/p&gt;

&lt;p&gt;Ta viết lại bài toán gốc bằng cách cộng thêm một số hạng phạt bậc hai vào hàm mục tiêu:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_x f(x) + \frac{\rho}{2} \lVert Ax - b \rVert _2^2 \quad \text{ subject to } \quad Ax = b
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\rho &amp;gt; 0\). Nếu \(A\) có hạng cột đầy đủ, hàm mục tiêu mới trở nên lồi mạnh. Bài toán này hoàn toàn tương đương với bài toán ban đầu vì số hạng phạt \(\frac{\rho}{2}\lVert Ax - b \rVert_2^2\) bằng \(0\) tại mọi điểm khả thi \(Ax = b\).&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-augmented-lagrangian&quot;&gt;Phương pháp Augmented Lagrangian&lt;/h2&gt;
&lt;p&gt;Áp dụng &lt;strong&gt;dual gradient ascent&lt;/strong&gt; cho bài toán đã biến đổi, ta thu được các bước lặp với \(k = 1, 2, 3, \dots\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; \in \arg\min_x f(x) + (u^{(k-1)})^T A x + \frac{\rho}{2} \lVert Ax - b \rVert_2^2  \\
u^{(k)} &amp;amp; = u^{(k-1)} + \rho (A x^{(k)} - b)
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây, tham số phạt \(\rho\) đồng thời được chọn làm độ dài bước cập nhật đối ngẫu (\(t_k = \rho\)).&lt;/p&gt;

&lt;h4 id=&quot;vì-sao-chọn-độ-dài-bước-t_k--rho&quot;&gt;Vì sao chọn độ dài bước \(t_k = \rho\)?&lt;/h4&gt;

&lt;p&gt;Vì \(x^{(k)}\) là nghiệm cực tiểu của \(f(x) + (u^{(k-1)})^T Ax + \frac{\rho}{2} \lVert Ax - b\rVert _2^2\), điều kiện tối ưu bậc nhất cho ta:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
0 &amp;amp; \in \partial f(x^{(k)}) + A^T \left( u^{(k-1)} + \rho (A x^{(k)} -b) \right)  \\
  &amp;amp; = \partial f(x^{(k)}) + A^T u^{(k)}
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Như vậy, với quy tắc cập nhật \(u^{(k)} = u^{(k-1)} + \rho (A x^{(k)} - b)\), điểm \(x^{(k)}\) luôn thỏa mãn điều kiện dừng đối ngẫu \(0 \in \partial f(x^{(k)}) + A^T u^{(k)}\) ở mọi vòng lặp. Dưới các giả thiết rất nhẹ, phần dư \(Ax^{(k)} - b\) tiến về \(0\), các điều kiện KKT dần được thỏa mãn và \((x^{(k)}, u^{(k)})\) hội tụ về nghiệm tối ưu.&lt;/p&gt;

&lt;p&gt;Ưu điểm của &lt;strong&gt;phương pháp augmented Lagrangian&lt;/strong&gt; là tính hội tụ ổn định và vững chắc hơn nhiều so với dual ascent; tuy nhiên, nhược điểm là số hạng bậc hai \(\frac{\rho}{2}\lVert Ax - b \rVert_2^2\) làm các khối biến liên kết với nhau, phá vỡ tính khả phân (decomposability) của bài toán.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-02-02 Phân rã đối ngẫu với ràng buộc bất đẳng thức</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_02_02_Dual_Decomposition_with_Inequality_Constraint/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_02_02_Dual_Decomposition_with_Inequality_Constraint</id>
   <content type="html">&lt;p&gt;Trong thực tế kỹ thuật và kinh tế, phần lớn ràng buộc tài nguyên không phải là đẳng thức cứng (“dùng đúng bằng \(b\)”), mà là &lt;strong&gt;bất đẳng thức hạn mức&lt;/strong&gt; \(\sum_{i=1}^B A_i x_i \le b\) (“không được vượt quá băng thông \(b\), ngân sách \(b\) hay công suất đường dây \(b\)”). Khi đổi dấu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt; thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;≤&lt;/code&gt;, thuật toán phân rã đối ngẫu chỉ thay đổi đúng một chi tiết nhỏ nhưng mang ý nghĩa kinh tế sâu sắc: biến đối ngẫu \(u\) bắt buộc phải không âm \(u \ge 0\) nhờ phép chiếu \(u^{(k)} = (\cdot)_+\) — biểu thị rằng &lt;strong&gt;tài nguyên dư thừa luôn có giá bóng bằng 0&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-đặc-trưng-của-phân-rã-đối-ngẫu-với-ràng-buộc-bất-đẳng-thức&quot;&gt;Kiến thức cần nhớ: Ba đặc trưng của phân rã đối ngẫu với ràng buộc bất đẳng thức&lt;/h2&gt;

&lt;p&gt;Để hiểu trọn vẹn bài 20-02-02 và diễn giải kinh tế học (Price Update) đi kèm, hãy nắm vững ba ý sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phép chiếu không âm \(u_+ = \max(0, u)\) và điều kiện bù chặt:&lt;/strong&gt; Với bài toán bất đẳng thức, điều kiện KKT đòi hỏi \(u \ge 0\) và \(u_j(\sum_i (A_i x_i)_j - b_j) = 0\). Nếu một tài nguyên \(j\) không bị dùng hết (\(\sum_i (A_i x_i)_j &amp;lt; b_j\)), phép cập nhật sẽ đẩy \(u_j\) giảm dần về \(0\) và giữ chặt tại \(0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán hạ dưới gradient chiếu trên đối ngẫu (Projected Dual Subgradient):&lt;/strong&gt; Bước cập nhật \(u^{(k)} = \left(u^{(k-1)} + t_k(\sum_i A_i x_i^{(k)} - b)\right)_+\) chính là một bước tăng gradient chiếu lên tập lồi \(u \ge 0\) cho hàm đối ngẫu \(g(u)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải điều chỉnh giá theo trạng thái tắc nghẽn:&lt;/strong&gt; Trong mạng viễn thông (tối ưu hóa tốc độ truyền TCP), mỗi liên kết \(j\) có băng thông tối đa \(b_j\): khi lưu lượng vượt \(b_j\), giá tắc nghẽn \(u_j\) tăng lên buộc các luồng dữ liệu tự giảm tốc độ; khi đường truyền thông thoáng, \(u_j\) tụt về \(0\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-2-bước-phân-rã-bất-đẳng-thức-cả-trường-hợp-chặt-và-trường-hợp-dư-tài-nguyên&quot;&gt;Giải thích: Tính tay 2 bước phân rã bất đẳng thức (cả trường hợp chặt và trường hợp dư tài nguyên)&lt;/h3&gt;

&lt;p&gt;Xét 2 người dùng muốn tối ưu lợi ích (tương đương cực tiểu hóa độ lệch so với mức mong muốn \(3\) và \(2\)) với hạn mức tổng băng thông \(b\):&lt;/p&gt;

\[\min_{x_1, x_2} \; (x_1 - 3)^2 + (x_2 - 2)^2 \qquad \text{với điều kiện} \qquad x_1 + x_2 \le b.\]

&lt;p&gt;Khởi tạo giá ban đầu \(u^{(0)} = 0\) và bước học \(t = 0.5\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 1 — Băng thông thiếu (\(b = 4 &amp;lt; 3 + 2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Vòng 1 (\(u^{(0)} = 0\)):&lt;/strong&gt; Người 1 chọn \(x_1^{(1)} = 3\), người 2 chọn \(x_2^{(1)} = 2\). Tổng \(= 5 &amp;gt; 4\) (vượt hạn mức \(+1\)).
Cập nhật giá: \(u^{(1)} = (0 + 0.5(5 - 4))_+ = (0.5)_+ = 0.5\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Vòng 2 (\(u^{(1)} = 0.5\)):&lt;/strong&gt;
        &lt;ul&gt;
          &lt;li&gt;Người 1 giải \(\min (x_1 - 3)^2 + 0.5x_1 \implies x_1^{(2)} = 3 - 0.25 = 2.75\).&lt;/li&gt;
          &lt;li&gt;Người 2 giải \(\min (x_2 - 2)^2 + 0.5x_2 \implies x_2^{(2)} = 2 - 0.25 = 1.75\).&lt;/li&gt;
          &lt;li&gt;Tổng \(= 4.5 &amp;gt; 4\) (chỉ còn vượt \(+0.5\)), cập nhật \(u^{(2)} = (0.5 + 0.5(0.5))_+ = 0.75\), tiến thẳng về nghiệm tối ưu \(u^\star = 1, x^\star = (2.5, 1.5)\)!&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 2 — Băng thông dư thừa (\(b = 6 &amp;gt; 3 + 2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Vòng 1 (\(u^{(0)} = 0\)):&lt;/strong&gt; \(x_1^{(1)} = 3, x_2^{(1)} = 2\), tổng \(= 5 &amp;lt; 6\) (dư \(-1\)).&lt;/li&gt;
      &lt;li&gt;Phép chiếu cắt âm: \(u^{(1)} = (0 + 0.5(-1))_+ = (-0.5)_+ = 0\)! Giá bóng bị ghim tại \(0\) và thuật toán dừng ngay tại nghiệm tối ưu \((3, 2)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Xét bài toán tương tự phần trước nhưng thay ràng buộc đẳng thức bằng ràng buộc bất đẳng thức tuyến tính:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{equation}
\min_x \sum_{i=1}^B f_i(x_i) \quad \text{subject to} \quad \sum_{i=1}^B A_i x_i \leq b
\end{equation}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;phân-rã-đối-ngẫu-phương-pháp-subgradient-chiếu&quot;&gt;Phân rã đối ngẫu (phương pháp subgradient chiếu)&lt;/h2&gt;
&lt;p&gt;Do ràng buộc có dạng bất đẳng thức, biến đối ngẫu phải thỏa mãn điều kiện không âm \(u \geq 0\). Vì vậy, sau bước cập nhật \(u\), ta chiếu kết quả lên góc phần tư không âm:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
x_i^{(k)} &amp;amp; \in \arg \min_{x_i} f_i(x_i) + (u^{(k-1)})^T A_i x_i, \quad i=1,\dots,B  \\
u^{(k)}   &amp;amp; = \left( u^{(k-1)} + t_k \left(\sum_{i=1}^B A_i x_i^{(k)} - b \right) \right)_+
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(u_{+}\) ký hiệu phép lấy phần không âm theo từng thành phần: \((u_+)_i = \max \left\{0, u_i \right\}\) (\(i = 1, \dots, m\)). Hai bước trên được lặp lại với \(k = 1, 2, 3, \dots\)&lt;/p&gt;

&lt;h4 id=&quot;diễn-giải-theo-cơ-chế-điều-phối-giá-price-coordination&quot;&gt;Diễn giải theo cơ chế điều phối giá (price coordination)&lt;/h4&gt;
&lt;p&gt;Theo Vandenberghe, thuật toán phân rã đối ngẫu có cách hiểu kinh tế trực quan như sau:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;Hệ thống gồm \(B\) đơn vị độc lập, mỗi đơn vị tự chọn phương án \(x_i\) của mình.&lt;/li&gt;
    &lt;li&gt;Mỗi ràng buộc biểu diễn giới hạn của một nguồn lực dùng chung giữa \(B\) đơn vị, còn biến đối ngẫu \(u_j\) đóng vai trò đơn giá của nguồn lực thứ \(j\).&lt;/li&gt;
    &lt;li&gt;Các mức giá được cập nhật theo công thức:
 \begin{equation}
 u_j^{+} = (u_j - t s_j)_{+}, \quad  j=1,\dots,m
 \end{equation}&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;\(\quad\) trong đó \(s = b - \sum_{i=1}^B A_ix_i\) là lượng dư (slack) của nguồn lực: &lt;br /&gt;
\(\qquad\) - nếu \(s_j &amp;lt; 0\) (nguồn lực \(j\) bị sử dụng vượt mức cho phép), giá \(u_j\) được tăng lên; &lt;br /&gt;
\(\qquad\) - nếu \(s_j &amp;gt; 0\) (nguồn lực \(j\) vẫn còn dư), giá \(u_j\) được giảm xuống; &lt;br /&gt;
\(\qquad\) - mức giá luôn được giữ không âm (\(u_j \ge 0\)).&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>20-02-01 Phân rã đối ngẫu với ràng buộc đẳng thức</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_02_01_Dual_Decomposition_with_Equality_Constraint/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_02_01_Dual_Decomposition_with_Equality_Constraint</id>
   <content type="html">&lt;p&gt;Trong bài toán tối ưu có ràng buộc đẳng thức tuyến tính \(\sum_{i=1}^B A_i x_i = b\), phân rã đối ngẫu hoạt động theo một nhịp điệu hai pha cực kỳ sạch sẽ: pha song song (từng khối \(i\) tự tìm \(x_i^{(k)}\) ứng với mức giá \(u^{(k-1)}\)) và pha tổng hợp (nút trung tâm cộng dồn độ lệch \(\sum_i A_i x_i^{(k)} - b\) để cập nhật \(u^{(k)}\)). Nhờ chỉ trao đổi vector biến đối ngẫu \(u \in \mathbb{R}^m\) thay vì trao đổi toàn bộ dữ liệu hay hàm chi phí \(f_i\), kỹ thuật này bảo toàn quyền riêng tư dữ liệu và mở rộng tự nhiên trên các cụm máy chủ phân tán.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-điểm-cốt-lõi-của-phân-rã-đối-ngẫu-với-ràng-buộc-đẳng-thức&quot;&gt;Kiến thức cần nhớ: Ba điểm cốt lõi của phân rã đối ngẫu với ràng buộc đẳng thức&lt;/h2&gt;

&lt;p&gt;Để áp dụng đúng thuật toán phân rã đẳng thức mà không gặp bẫy hội tụ, hãy nắm vững ba điểm sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân hoạch theo khối cột của ma trận \(A = [A_1, \dots, A_B]\):&lt;/strong&gt; Điều kiện tiên quyết để bài toán con tách rời hoàn toàn là hàm mục tiêu phải cộng tính \(\sum_i f_i(x_i)\) và ràng buộc đẳng thức phải cộng tính \(\sum_i A_i x_i = b\) (không có số hạng chéo giữa \(x_i\) và \(x_j\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến đối ngẫu tự do dấu (\(u \in \mathbb{R}^m\)):&lt;/strong&gt; Vì ràng buộc là đẳng thức \(Ax = b\), nhân tử \(u\) có thể nhận cả giá trị dương lẫn âm — không cần phép chiếu lên góc phần tư không âm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện hội tụ của từng biến gốc \(x_i^{(k)}\):&lt;/strong&gt; Dù giá trị đối ngẫu \(g(u^{(k)})\) hội tụ dưới điều kiện nhẹ, bản thân dãy điểm gốc \(x^{(k)}\) chỉ chắc chắn hội tụ về nghiệm tối ưu \(x^\star\) khi mỗi \(f_i\) lồi chặt (hoặc lồi mạnh); nếu \(f_i\) tuyến tính, \(x_i^{(k)}\) có thể nhảy qua lại giữa các đỉnh mà không bao giờ thỏa mãn \(Ax = b\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-2-vòng-lặp-phân-rã-song-song-cho-2-khối-biến&quot;&gt;Giải thích: Chạy tay 2 vòng lặp phân rã song song cho 2 khối biến&lt;/h3&gt;

&lt;p&gt;Xét bài toán tách biến với ràng buộc đẳng thức:&lt;/p&gt;

\[\min_{x_1, x_2} \; \underbrace{x_1^2}_{f_1(x_1)} + \underbrace{2x_2^2}_{f_2(x_2)} \qquad \text{với điều kiện} \qquad x_1 + x_2 = 3.\]

&lt;p&gt;Nghiệm tối ưu chính xác là \(x_1^\star = 2, x_2^\star = 1, u^\star = -4\). Khởi tạo \(u^{(0)} = -2\) và chọn bước học \(t = 1\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(k = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Giải song song 2 bài toán con với \(u^{(0)} = -2\):&lt;/strong&gt;
        &lt;ul&gt;
          &lt;li&gt;Khối 1: \(x_1^{(1)} = \arg\min_{x_1} (x_1^2 - 2x_1) = 1.0\).&lt;/li&gt;
          &lt;li&gt;Khối 2: \(x_2^{(1)} = \arg\min_{x_2} (2x_2^2 - 2x_2) = 0.5\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Cập nhật đối ngẫu tại nút trung tâm:&lt;/strong&gt;
Phần dư \(r^{(1)} = x_1^{(1)} + x_2^{(1)} - 3 = 1.5 - 3 = -1.5\).
\(u^{(1)} = -2 + 1(-1.5) = -3.5.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(k = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Giải song song với \(u^{(1)} = -3.5\):&lt;/strong&gt;
        &lt;ul&gt;
          &lt;li&gt;Khối 1: \(x_1^{(2)} = \arg\min_{x_1} (x_1^2 - 3.5x_1) = 1.75\).&lt;/li&gt;
          &lt;li&gt;Khối 2: \(x_2^{(2)} = \arg\min_{x_2} (2x_2^2 - 3.5x_2) = 0.875\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Cập nhật đối ngẫu:&lt;/strong&gt;
Phần dư \(r^{(2)} = 1.75 + 0.875 - 3 = -0.375\) (giảm &lt;strong&gt;4 lần&lt;/strong&gt; chỉ sau 1 vòng!).
\(u^{(2)} = -3.5 + 1(-0.375) = -3.875\) — tiến sát \(u^\star = -4\) cực nhanh!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Xét bài toán tối ưu có hàm mục tiêu tách biến kèm ràng buộc đẳng thức tuyến tính:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{equation}
\min_x \sum_{i=1}^B f_i(x_i) \quad \text{ subject to } \quad Ax = b
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Giả sử biến \(x\) được phân hoạch thành \(B\) khối \(x = (x_1, \dots, x_B) \in \mathbb{R}^n\) với \(x_i \in \mathbb{R}^{n_i}\), và ma trận \(A\) được chia tương ứng thành \(B\) khối cột \(A = [A_1, \dots, A_B]\) với \(A_i \in \mathbb{R}^{m \times n_i}\). Khi cố định biến đối ngẫu \(u\), bài toán cực tiểu hóa theo \(x\) tách hoàn toàn thành \(B\) bài toán con độc lập:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
&amp;amp; \quad x^+ \in \arg\min_x \sum_{i=1}^B f_i(x_i) + u^T Ax  \\
\Longleftrightarrow &amp;amp; \quad x_i^+ \in \arg\min_{x_i} f_i(x_i) + u^T A_ix_i, \quad i=1,\dots, B
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;thuật-toán-phân-rã-đối-ngẫu&quot;&gt;Thuật toán phân rã đối ngẫu&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
x_i^{(k)} &amp;amp; \in \arg \min_{x_i} f_i(x_i) + (u^{(k-1)})^T A_i x_i, \quad i=1,\dots,B  \\
u^{(k)}   &amp;amp; = u^{(k-1)} + t_k \left(\sum_{i=1}^B A_i x_i^{(k)} - b \right)
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Thuật toán lặp lại hai bước sau với \(k = 1, 2, 3, \dots\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước phát (broadcast):&lt;/strong&gt; Giá trị đối ngẫu \(u^{(k-1)}\) hiện tại được gửi tới cả \(B\) bộ xử lý; mỗi bộ xử lý giải song song bài toán con để tìm \(x_i^{(k)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước thu (gather):&lt;/strong&gt; Thu thập các kết quả \(A_i x_i^{(k)}\) từ các bộ xử lý để cập nhật biến đối ngẫu toàn cục \(u^{(k)}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter20/decomposition.png&quot; alt=&quot;[Hình 1] Broadcast and Gather&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Broadcast and Gather&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;phân-rã-đối-ngẫu-giá-và-các-tác-tử-video&quot;&gt;Phân rã đối ngẫu: giá và các tác tử (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/dual-decomposition_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Mỗi tác tử tự giải bài toán con của riêng mình theo mức giá \(\nu\), sau đó bước tăng đối ngẫu (dual ascent) điều chỉnh tăng hoặc giảm \(\nu\) tùy theo mức độ vi phạm ràng buộc \(\sum_i x_i - c\).&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-đặt-mức-giá&quot;&gt;Tự tay thử: đặt mức giá&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;dd&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>20-02 Phân rã đối ngẫu (Dual Decomposition)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_02_00_Dual_Decomposition/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_02_00_Dual_Decomposition</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng một tập đoàn quản lý 100 nhà máy khác nhau, mỗi nhà máy có hàm chi phí sản xuất riêng \(f_i(x_i)\), nhưng cả 100 nhà máy lại dùng chung một nguồn điện hoặc một hạn mức phát thải chung \(\sum_{i=1}^{100} A_i x_i = b\). Nếu gom toàn bộ biến của 100 nhà máy vào một máy tính duy nhất thì bài toán quá khổng lồ, còn nếu để từng nhà máy tự tối ưu riêng thì lại vi phạm nguồn lực chung. &lt;strong&gt;Phân rã đối ngẫu (Dual Decomposition)&lt;/strong&gt; mang đến một lời giải vừa toán học vừa đậm chất kinh tế học: đặt một “người điều phối” chỉ phát đi duy nhất một &lt;strong&gt;bảng giá&lt;/strong&gt; (biến đối ngẫu \(u\)), để 100 nhà máy tự tính toán hoàn toàn song song!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-tư-duy-phân-rã-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của tư duy phân rã đối ngẫu&lt;/h2&gt;

&lt;p&gt;Phần 20-02 mở rộng phương pháp tăng đối ngẫu thành một kiến trúc tối ưu hóa phân tán hoàn chỉnh dựa trên ba nguyên lý:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính tách được của hàm Lagrange (Lagrangian Separability):&lt;/strong&gt; Khi hàm mục tiêu có dạng tổng \(\sum_{i=1}^B f_i(x_i)\) và ràng buộc tuyến tính tách theo khối \(\sum_{i=1}^B A_i x_i = b\) (hoặc \(\le b\)), hàm Lagrange tách thành tổng \(B\) hàm độc lập \(\sum_{i=1}^B (f_i(x_i) + u^T A_i x_i) - u^T b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chu trình Broadcast – Solve – Gather:&lt;/strong&gt; Ở mỗi vòng lặp, máy chủ trung tâm phát giá \(u^{(k-1)}\) tới các nút (broadcast); mỗi nút tự giải bài toán con \(x_i^{(k)}\) độc lập song song (solve); máy chủ thu gom phần dư tổng \(\sum_i A_i x_i^{(k)} - b\) để điều chỉnh giá \(u^{(k)}\) (gather).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy luật cung–cầu tự nhiên:&lt;/strong&gt; Với ràng buộc bất đẳng thức (hạn mức tài nguyên \(\le b\)), nếu tổng mức dùng vượt hạn mức thì giá \(u\) tăng lên để kìm hãm tiêu thụ; nếu dư thừa tài nguyên thì giá giảm xuống (nhưng không âm nhờ phép chiếu \((\cdot)_+\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-cơ-chế-bảng-giá-điện-điều-phối-2-nhà-máy-độc-lập&quot;&gt;Giải thích: Cơ chế “bảng giá điện” điều phối 2 nhà máy độc lập&lt;/h3&gt;

&lt;p&gt;Giả sử 2 nhà máy cần cùng nhau sản xuất tổng cộng \(10\) đơn vị sản phẩm (\(x_1 + x_2 = 10\)) với chi phí riêng \(f_1(x_1) = x_1^2\) và \(f_2(x_2) = 4x_2^2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khi chưa có giá điều phối (\(u = 0\)):&lt;/strong&gt; Cả hai nhà máy đều chọn \(x_1 = 0, x_2 = 0\) để chi phí bằng \(0\) — tổng sản lượng là \(0 &amp;lt; 10\) (thiếu \(10\) đơn vị!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Người điều phối phát giá thưởng \(p = -u = 8\) (tức \(u = -8\)) cho mỗi đơn vị sản xuất:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nhà máy 1 tự tối ưu \(\min_{x_1} (x_1^2 - 8x_1) \implies x_1 = 4\).&lt;/li&gt;
      &lt;li&gt;Nhà máy 2 tự tối ưu \(\min_{x_2} (4x_2^2 - 8x_2) \implies x_2 = 1\).&lt;/li&gt;
      &lt;li&gt;Tổng sản lượng \(4 + 1 = 5 &amp;lt; 10\) (vẫn thiếu \(5\) đơn vị, nên người điều phối phải nâng giá thưởng lên gấp đôi!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Người điều phối nâng giá thưởng lên \(p = -u = 16\) (tức \(u = -16\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nhà máy 1 chọn \(x_1 = 8\); Nhà máy 2 chọn \(x_2 = 2\).&lt;/li&gt;
      &lt;li&gt;Tổng sản lượng \(8 + 2 = 10\) — &lt;strong&gt;khớp chính xác chỉ tiêu chung&lt;/strong&gt; mà hai nhà máy chưa từng phải tiết lộ hàm chi phí riêng của mình cho nhau!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong phần này, chúng ta tìm hiểu các kỹ thuật phân rã bài toán tối ưu thành nhiều bài toán con độc lập thông qua hàm đối ngẫu.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-01-01 Phân tích hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_01_01_Convergence_Analysis/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_01_01_Convergence_Analysis</id>
   <content type="html">&lt;p&gt;Một trong những định lý đối xứng đẹp nhất trong toàn bộ giải tích lồi — xứng đáng được đóng khung treo tường — là sự &lt;strong&gt;đối ngẫu giữa tính lồi mạnh và độ trơn Lipschitz&lt;/strong&gt;: hàm gốc \(f\) càng “cong nhọn” (lồi mạnh với tham số \(d\)), thì hàm liên hợp \(f^*\) càng “mềm mượt” (có gradient liên tục Lipschitz với hằng số \(1/d\)), và ngược lại! Định lý này không chỉ là vẻ đẹp thuần túy mà còn cho ta công thức bước học chính xác \(t \le d / \|A\|_2^2\) để phương pháp tăng gradient đối ngẫu hội tụ an toàn.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-phân-tích-hội-tụ-phương-pháp-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của phân tích hội tụ phương pháp đối ngẫu&lt;/h2&gt;

&lt;p&gt;Để đọc hiểu phần chứng minh và hệ quả thực tiễn trong bài học này, hãy nắm chắc ba mối liên hệ sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu hình học (Cong ở gốc \(\iff\) Trơn ở đối ngẫu):&lt;/strong&gt; Nếu \(f\) lồi mạnh với tham số \(d &amp;gt; 0\), đáy của \(f(x) - u^T x\) là duy nhất và không bao giờ phẳng lì, nên điểm cực tiểu \(x_u = \nabla f^*(u)\) biến thiên liên tục Lipschitz theo \(u\) với độ nhạy tối đa \(1/d\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển đổi hằng số Lipschitz qua ma trận ràng buộc \(A\):&lt;/strong&gt; Với hàm đối ngẫu \(g(u) = -f^*(-A^T u) - b^T u\), áp dụng quy tắc dây chuyền cho \(\nabla g(u) = A\nabla f^*(-A^T u) - b\) cho thấy \(\nabla g\) liên tục Lipschitz với hằng số \(L_g = \frac{\|A\|_2^2}{d}\) (trong đó \(\|A\|_2 = \sigma_{\max}(A)\) là giá trị kỳ dị lớn nhất của \(A\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ quả trực tiếp cho chọn bước học và tốc độ hội tụ:&lt;/strong&gt; Nhờ độ trơn \(L_g\), Dual Gradient Ascent với bước học hằng số \(t \le \frac{1}{L_g} = \frac{d}{\|A\|_2^2}\) đảm bảo hội tụ với tốc độ \(O(1/k)\) (và có thể gia tốc lên \(O(1/k^2)\) bằng Nesterov!). Ngược lại, nếu \(f\) &lt;strong&gt;không&lt;/strong&gt; lồi mạnh (\(d = 0\)), \(g\) có thể không khả vi và buộc phải dùng bước học giảm dần chậm chạp \(O(1/\sqrt{k})\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-bằng-số-cặp-hằng-số-d-1d-và-ngưỡng-bước-học-ổn-định&quot;&gt;Giải thích: Kiểm chứng bằng số cặp hằng số \((d, 1/d)\) và ngưỡng bước học ổn định&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu 1 biến:&lt;/p&gt;

\[\min_{x \in \mathbb{R}} \; f(x) = \frac{d}{2}x^2 \quad (d = 4) \qquad \text{với điều kiện} \qquad 2x = 6 \quad (A = 2, \; b = 6).\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra cặp tính chất đối ngẫu:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hàm gốc \(f(x) = 2x^2\) có \(f&apos;&apos;(x) = 4\), nên lồi mạnh với tham số \(d = 4\).&lt;/li&gt;
      &lt;li&gt;Hàm liên hợp là \(f^*(y) = \sup_x (yx - 2x^2) = \frac{y^2}{8}\), có đạo hàm \(\nabla f^*(y) = \frac{y}{4}\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Với mọi \(y_1, y_2\): $$&lt;/td&gt;
              &lt;td&gt;\nabla f^&lt;em&gt;(y_1) - \nabla f^&lt;/em&gt;(y_2)&lt;/td&gt;
              &lt;td&gt;= \frac{1}{4}&lt;/td&gt;
              &lt;td&gt;y_1 - y_2&lt;/td&gt;
              &lt;td&gt;\(— hằng số Lipschitz đúng bằng\)\frac{1}{d} = \frac{1}{4}$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hằng số Lipschitz của hàm đối ngẫu \(g(u)\) và ngưỡng bước học:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(A = 2\), ta có \(\|A\|_2^2 = 4\), suy ra \(L_g = \frac{\|A\|_2^2}{d} = \frac{4}{4} = 1\).&lt;/li&gt;
      &lt;li&gt;Công thức lý thuyết bảo đảm Dual Gradient Ascent hội tụ với mọi \(t \in (0, 2/L_g) = (0, 2)\), và bước học chuẩn là \(t = 1/L_g = 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử nghiệm so sánh hai bước học từ \(u^{(0)} = 0\) (nghiệm thực \(x^\star = 3, u^\star = -6\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(t = 1\) (đúng chuẩn \(1/L_g\)): \(x^{(1)} = 0 \implies u^{(1)} = 0 + 1(0 - 6) = -6 = u^\star \implies x^{(2)} = 3 = x^\star\) (&lt;strong&gt;hội tụ sau 1 bước!&lt;/strong&gt;).&lt;/li&gt;
      &lt;li&gt;Với \(t = 2.5 &amp;gt; 2/L_g\) (vượt ngưỡng ổn định): \(u^{(1)} = -15 \implies x^{(2)} = 7.5 \implies u^{(2)} = -15 + 2.5(15 - 6) = +7.5\) — &lt;strong&gt;dao động phân kỳ ngày càng lớn!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tính-đối-ngẫu-giữa-gradient-lipschitz-và-tính-lồi-mạnh&quot;&gt;Tính đối ngẫu giữa gradient Lipschitz và tính lồi mạnh&lt;/h2&gt;
&lt;p&gt;Giả sử \(f\) là hàm lồi đóng. Khi đó, mối tương đương sau luôn đúng:&lt;/p&gt;
&lt;blockquote&gt;
\[f \text{ lồi mạnh với tham số } d \Longleftrightarrow \nabla f^{\ast} \text{ liên tục Lipschitz với tham số } 1/d.\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h3&gt;
&lt;p&gt;Ta chứng minh chiều “\(\Rightarrow\)”. Nếu hàm \(g\) lồi mạnh với tham số \(d\) và đạt cực tiểu tại \(x\) thì:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
g(y) \geq g(x) + \frac{d}{2}\lVert y-x \rVert_2^2, \quad \forall y
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Gọi \(x_u = \nabla f^{\ast}(u)\) là điểm cực tiểu của \(x \mapsto f(x) - u^T x\), và \(x_v = \nabla f^{\ast}(v)\) là điểm cực tiểu của \(x \mapsto f(x) - v^T x\). Áp dụng bất đẳng thức trên cho hai hàm này, ta có:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
f(x_v) - u^Tx_v \geq f(x_u) - u^T x_u + \frac{d}{2} \lVert x_u - x_v \rVert_2^2 \\
f(x_u) - v^Tx_u \geq f(x_v) - v^T x_v + \frac{d}{2} \lVert x_u - x_v \rVert_2^2 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Cộng hai bất đẳng thức theo vế:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
f(x_v) - u^Tx_v + f(x_u) - v^Tx_u \geq f(x_u) - u^T x_u +  f(x_v) - v^T x_v + d \lVert x_u - x_v \rVert_2^2.&lt;br /&gt;
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Rút gọn và áp dụng bất đẳng thức Cauchy–Schwarz:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
d \lVert x_u - x_v \rVert_2^2 &amp;amp; \leq - u^Tx_v - v^Tx_u + u^T x_u + v^T x_v \\\\
&amp;amp; = (u-v)^T(x_u - x_v) \\\\
&amp;amp; \leq \lVert u-v \rVert_2 \lVert x_u - x_v \rVert_2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Chia hai vế cho \(d \lVert x_u - x_v \rVert_2\) (khi \(x_u \neq x_v\)), ta thu được:&lt;/p&gt;

&lt;blockquote&gt;
\[\lVert x_u - x_v \rVert_2 \leq \frac{1}{d} \lVert u-v \rVert_2\]
&lt;/blockquote&gt;

&lt;p&gt;chứng tỏ \(\nabla f^{\ast}\) liên tục Lipschitz với hằng số \(1/d\).&lt;/p&gt;

&lt;h2 id=&quot;đảm-bảo-hội-tụ&quot;&gt;Đảm bảo hội tụ&lt;/h2&gt;
&lt;p&gt;Kết hợp tính chất trên với kết quả hội tụ của gradient descent, ta thu được các đảm bảo hội tụ cho phương pháp tăng gradient đối ngẫu (dual gradient ascent):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nếu \(f\) lồi mạnh với tham số \(d\), thì dual gradient ascent với độ dài bước \(t_k = d\) (\(k = 1, 2, 3, \dots\)) hội tụ với tốc độ \(O(1/\epsilon)\).&lt;/li&gt;
  &lt;li&gt;Nếu \(f\) vừa lồi mạnh với tham số \(d\) vừa có \(\nabla f\) liên tục Lipschitz với tham số \(L\), thì dual gradient ascent với độ dài bước \(t_k = 2/(1/d + 1/L)\) (\(k = 1, 2, 3, \dots\)) hội tụ tuyến tính với tốc độ \(O(\log(1/\epsilon))\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(Các công thức độ dài bước trên giả sử \(\lVert A \rVert_2 \le 1\); tổng quát, gradient đối ngẫu liên tục Lipschitz với hằng số \(\lVert A \rVert_2^2 / d\) nên độ dài bước cần được nhân thêm hệ số \(1/\lVert A \rVert_2^2\).)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-01 Các phương pháp dual (sub)gradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_01_00_Dual_(sub)gradient_methods/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_01_00_Dual_(sub)gradient_methods</id>
   <content type="html">&lt;p&gt;Ở ví dụ đơn giản trong bài mở đầu, ta dễ dàng viết được công thức tường minh cho hàm liên hợp \(f^*\). Nhưng trong thực tế, phần lớn hàm \(f\) phức tạp không hề có công thức dạng đóng cho \(f^*\)! Điều kỳ diệu của &lt;strong&gt;phương pháp (dưới) gradient đối ngẫu&lt;/strong&gt; là ta &lt;strong&gt;không bao giờ cần viết tường minh \(f^*\)&lt;/strong&gt;: nhờ định lý bao hàm thức liên hợp \(x \in \partial f^*(-A^T u) \iff x \in \arg\min_z (f(z) + u^T A z)\), chỉ cần giải bài toán cực tiểu hóa theo \(x\) với \(u\) cố định, ta lập tức có ngay một dưới gradient của hàm đối ngẫu — chính là phần dư ràng buộc \(Ax - b\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-vận-hành-phương-pháp-dual-subgradient&quot;&gt;Kiến thức cần nhớ: Ba trụ cột vận hành phương pháp Dual (Sub)gradient&lt;/h2&gt;

&lt;p&gt;Hiểu ba ý tưởng sau sẽ giúp bạn thấy công thức lặp \(x^{(k)}, u^{(k)}\) hoàn toàn tự nhiên như hơi thở:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đẳng thức dưới vi phân liên hợp (Danskin’s Theorem):&lt;/strong&gt; Với \(g(u) = \inf_x (f(x) + u^T(Ax - b))\), mỗi nghiệm \(x^+ \in \arg\min_x (f(x) + u^T Ax)\) tự động cung cấp một dưới gradient (hoặc gradient nếu \(x^+\) duy nhất) của \(g\) tại \(u\) là \(Ax^+ - b \in \partial g(u)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc cập nhật Dual Ascent (tăng theo phần dư ràng buộc):&lt;/strong&gt; Vì ta đang &lt;strong&gt;cực đại hóa&lt;/strong&gt; hàm lõm \(g(u)\), ta cộng thêm bước đi theo hướng gradient: \(u^{(k)} = u^{(k-1)} + t_k(Ax^{(k)} - b)\). Nếu \(Ax^{(k)} &amp;gt; b\), nhân tử \(u\) tăng lên để “phạt” mạnh hơn ở bước sau; nếu \(Ax^{(k)} &amp;lt; b\), \(u\) giảm xuống!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xử lý ràng buộc bất đẳng thức \(Ax \le b\):&lt;/strong&gt; Khi ràng buộc là bất đẳng thức, biến đối ngẫu phải giữ không âm \(u \ge 0\), nên bước cập nhật đối ngẫu chỉ cần thêm phép chiếu đơn giản lên góc phần tư không âm: \(u^{(k)} = (u^{(k-1)} + t_k(Ax^{(k)} - b))_+\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-2-vòng-lặp-dual-gradient-ascent-và-quan-sát-phần-dư-thu-hẹp&quot;&gt;Giải thích: Chạy tay 2 vòng lặp Dual Gradient Ascent và quan sát phần dư thu hẹp&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu lồi 1 biến có ràng buộc đẳng thức:&lt;/p&gt;

\[\min_{x \in \mathbb{R}} \; \frac{1}{2}x^2 \qquad \text{với điều kiện} \qquad x = 2 \quad (A = 1, b = 2).\]

&lt;p&gt;Nghiệm tối ưu dễ thấy là \(x^\star = 2, u^\star = -2\). Chạy thuật toán Dual Gradient Ascent với khởi tạo \(u^{(0)} = 0\) và bước học cố định \(t = 0.5\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(k = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Bước gốc:&lt;/strong&gt; \(x^{(1)} = \arg\min_x \left(\frac{1}{2}x^2 + u^{(0)} x\right) = \arg\min_x \frac{1}{2}x^2 = 0\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Phần dư ràng buộc (gradient đối ngẫu):&lt;/strong&gt; \(r^{(1)} = x^{(1)} - 2 = 0 - 2 = -2\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước đối ngẫu:&lt;/strong&gt; \(u^{(1)} = u^{(0)} + 0.5(-2) = 0 - 1 = -1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(k = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Bước gốc:&lt;/strong&gt; \(x^{(2)} = \arg\min_x \left(\frac{1}{2}x^2 - 1 \cdot x\right) = 1\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Phần dư ràng buộc:&lt;/strong&gt; \(r^{(2)} = x^{(2)} - 2 = 1 - 2 = -1\) (sai số ràng buộc giảm đúng một nửa!).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước đối ngẫu:&lt;/strong&gt; \(u^{(2)} = -1 + 0.5(-1) = -1.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Quan sát quy luật hội tụ:&lt;/strong&gt; Ở mỗi bước, sai số $$&lt;/td&gt;
          &lt;td&gt;x^{(k)} - 2&lt;/td&gt;
          &lt;td&gt;\(và\)&lt;/td&gt;
          &lt;td&gt;u^{(k)} - (-2)&lt;/td&gt;
          &lt;td&gt;\(đều giảm đúng theo cấp số nhân\)0.5^k\(! Nếu chọn bước học\)t = 1\((đúng bằng hằng số lồi mạnh\)d = 1\(chia cho\)|A|_2^2 = 1\(), ta nhảy thẳng từ\)u^{(0)} = 0\(tới\)u^{(1)} = -2 = u^\star\(và\)x^{(2)} = 2 = x^\star$$ ngay tức thì!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Ngay cả khi không thể tìm được biểu thức dạng đóng cho hàm liên hợp (và do đó cho hàm mục tiêu đối ngẫu), ta vẫn có thể áp dụng phương pháp gradient hoặc dưới vi phân (subgradient) trực tiếp trên bài toán đối ngẫu.&lt;/p&gt;

&lt;p&gt;Xét bài toán tối ưu có ràng buộc đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_x f(x) \text{ subject to } Ax = b
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Bài toán đối ngẫu tương ứng — viết qua hàm liên hợp \(f^{\ast}\) của \(f\) — có dạng:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\max_u -f^{\ast}(-A^T u) - b^T u
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Đặt \(g(u) = -f^{\ast}(-A^Tu) - b^Tu\). Khi đó, dưới vi phân của \(g(u)\) là:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\partial g(u) = A \partial f^{\ast}(-A^Tu) - b
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Lấy một phần tử \(x \in \partial f^{\ast}(-A^Tu)\), theo tính chất hàm liên hợp ở bài trước, ta có thể biểu diễn phần tử thuộc \(\partial g(u)\) như sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
Ax - b \in \partial g(u) \quad \text{với} \quad x \in \arg\min_z f(z) + u^T A z
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;phương-pháp-dual-subgradient&quot;&gt;Phương pháp dual subgradient&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Phương pháp dual subgradient&lt;/strong&gt; cực đại hóa hàm mục tiêu đối ngẫu \(g(u)\). Bắt đầu từ điểm khởi tạo \(u^{(0)}\), thuật toán lặp các bước sau với \(k = 1, 2, 3, \dots\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; \in \arg \min_x f(x) + ({u^{(k-1)}})^T A x  \\
u^{(k)} &amp;amp; = u^{(k-1)} + t_k (A x^{(k)} - b) 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó dãy độ dài bước \(t_k\) (\(k = 1, 2, 3, \dots\)) được chọn theo các quy tắc chuẩn của phương pháp subgradient.&lt;/p&gt;

&lt;h4 id=&quot;trường-hợp-f-lồi-chặt&quot;&gt;Trường hợp \(f\) lồi chặt&lt;/h4&gt;
&lt;p&gt;Nếu \(f\) lồi chặt thì \(f^{\ast}\) khả vi, và thuật toán trở thành &lt;strong&gt;tăng gradient đối ngẫu (dual gradient ascent)&lt;/strong&gt; với các bước lặp (\(k = 1, 2, 3, \dots\)):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; = \arg \min_x f(x) + ({u^{(k-1)}})^T A x  \\
u^{(k)} &amp;amp; = u^{(k-1)} + t_k (A x^{(k)}-b) 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Khác biệt so với dạng tổng quát là nghiệm \(x^{(k)}\) là duy nhất (dùng ký hiệu “\(=\)” thay cho “\(\in\)”). Khi giải bài toán con tìm \(x^{(k)}\), ta có thể áp dụng các kỹ thuật tăng tốc hoặc proximal gradient như thông thường.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20 Các phương pháp đối ngẫu (Dual Methods)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_00_Dual_Methods/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter20/20_00_Dual_Methods</id>
   <content type="html">&lt;p&gt;Trong rất nhiều bài toán tối ưu lớn — từ điều phối điện lưới quốc gia đến huấn luyện mô hình học máy trên hàng trăm máy chủ — khó khăn lớn nhất không nằm ở hàm mục tiêu, mà nằm ở &lt;strong&gt;các ràng buộc liên kết&lt;/strong&gt; buộc mọi biến phải phụ thuộc lẫn nhau. Chương 20 mở ra một chiến lược chuyển hướng ngoạn mục: thay vì đối đầu trực diện với ràng buộc trong không gian gốc, ta chuyển sang &lt;strong&gt;không gian đối ngẫu&lt;/strong&gt; thông qua hàm liên hợp \(f^*\) và nhân tử Lagrange \(u\). Khi biến đối ngẫu đóng vai trò như “bảng giá điều phối”, bài toán khổng lồ bỗng tách rời thành hàng trăm bài toán con độc lập — mở đường cho phân rã đối ngẫu, hàm Lagrange tăng cường và thuật toán nổi tiếng &lt;strong&gt;ADMM&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trạm-dừng-chân-cốt-lõi-của-chương-20&quot;&gt;Kiến thức cần nhớ: Bốn trạm dừng chân cốt lõi của Chương 20&lt;/h2&gt;

&lt;p&gt;Để thấy rõ mạch logic xuyên suốt Chương 20 (vì sao ta phải đi từ phương pháp đối ngẫu cơ bản đến tận ADMM), hãy nhìn bốn nấc thang tiến hóa sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm liên hợp Fenchel (\(f^*(y) = \sup_x (y^T x - f(x))\)) và bài toán đối ngẫu:&lt;/strong&gt; Cho phép viết gọn bài toán đối ngẫu của \(\min f(x) \text{ s.t. } Ax = b\) thành \(\max_u -f^*(-A^T u) - b^T u\), và nối trực tiếp dưới vi phân của hàm đối ngẫu với phần dư ràng buộc \(Ax - b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tăng (dưới) gradient đối ngẫu &amp;amp; Phân rã đối ngẫu (Dual Ascent / Decomposition):&lt;/strong&gt; Tối ưu hóa không ràng buộc trên biến đối ngẫu \(u\). Khi \(f(x) = \sum_i f_i(x_i)\) tách biến, bước cập nhật gốc tự động phân rã song song hoàn toàn — nhưng lại đòi hỏi điều kiện ngặt nghèo (như \(f\) lồi chặt/mạnh) mới hội tụ ổn định.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm Lagrange tăng cường (Augmented Lagrangian):&lt;/strong&gt; Cộng thêm số hạng phạt bậc hai \(\frac{\rho}{2}\|Ax - b\|_2^2\) để ép hội tụ vững chắc dưới điều kiện rất nhẹ — nhưng số hạng bình phương lại làm &lt;strong&gt;mất tính phân rã song song&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ADMM (Alternating Direction Method of Multipliers):&lt;/strong&gt; Tách thành hai khối biến \(Ax + Bz = c\) và cập nhật luân phiên theo kiểu Gauss–Seidel, kết hợp trọn vẹn &lt;strong&gt;tính phân rã&lt;/strong&gt; của dual decomposition với &lt;strong&gt;độ bền hội tụ&lt;/strong&gt; của augmented Lagrangian!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-hàm-liên-hợp-f-và-giải-bài-toán-có-ràng-buộc-qua-không-gian-đối-ngẫu&quot;&gt;Giải thích: Tính tay hàm liên hợp \(f^*\) và giải bài toán có ràng buộc qua không gian đối ngẫu&lt;/h3&gt;

&lt;p&gt;Xét bài toán lồi 2 biến có ràng buộc đẳng thức liên kết hai biến:&lt;/p&gt;

\[\min_{x_1, x_2} \; \underbrace{\frac{1}{2}x_1^2 + x_2^2}_{f(x)} \qquad \text{với điều kiện} \qquad x_1 + x_2 = 3.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính hàm liên hợp \(f^*(y_1, y_2) = \sup_{x_1, x_2} \left(y_1 x_1 + y_2 x_2 - \frac{1}{2}x_1^2 - x_2^2\right)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đạo hàm theo \(x_1\) bằng \(0\): \(y_1 - x_1 = 0 \implies x_1 = y_1\), giá trị cực đại là \(\frac{1}{2}y_1^2\).&lt;/li&gt;
      &lt;li&gt;Đạo hàm theo \(x_2\) bằng \(0\): \(y_2 - 2x_2 = 0 \implies x_2 = \frac{y_2}{2}\), giá trị cực đại là \(\frac{1}{4}y_2^2\).&lt;/li&gt;
      &lt;li&gt;Vậy \(f^*(y_1, y_2) = \frac{1}{2}y_1^2 + \frac{1}{4}y_2^2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lập bài toán đối ngẫu 1 biến \(u \in \mathbb{R}\) (với \(A = [1, 1], b = 3\)):&lt;/strong&gt;
\(g(u) = -f^*(-u, -u) - 3u = -\left(\frac{1}{2}u^2 + \frac{1}{4}u^2\right) - 3u = -\frac{3}{4}u^2 - 3u.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán đối ngẫu không ràng buộc và khôi phục nghiệm gốc:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đạo hàm \(g&apos;(u) = -\frac{3}{2}u - 3 = 0 \implies u^\star = -2\), giá trị đối ngẫu \(g(-2) = -3 + 6 = 3\).&lt;/li&gt;
      &lt;li&gt;Khôi phục nghiệm gốc từ \(x^\star = \nabla f^*(-A^T u^\star) = \nabla f^*(2, 2) = (2, \; 1)^T\)!
Kiểm tra lại: \(x_1^\star + x_2^\star = 3\) và \(f(2, 1) = \frac{1}{2}(4) + 1 = 3 = g(-2)\) — đối ngẫu mạnh đạt chính xác!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong chương này, chúng ta tìm hiểu các phương pháp giải bài toán tối ưu thông qua bài toán đối ngẫu: phương pháp hạ dưới vi phân đối ngẫu (dual subgradient), phân rã đối ngẫu (dual decomposition), hàm Lagrange tăng cường (augmented Lagrangian), đồng thời giới thiệu sơ lược ý tưởng của phương pháp nhân tử hướng luân phiên (Alternating Direction Method of Multipliers — ADMM).&lt;/p&gt;

&lt;p&gt;Trước hết, hãy ôn lại ngắn gọn hai nội dung nền tảng từ các chương trước: phương pháp Newton proximal và hàm liên hợp (conjugate function).&lt;/p&gt;

&lt;h2 id=&quot;ôn-tập-phương-pháp-newton-proximal&quot;&gt;Ôn tập: phương pháp Newton proximal&lt;/h2&gt;
&lt;p&gt;Xét bài toán tổng hợp:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_x g(x) + h(x)
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(g\) và \(h\) là các hàm lồi, \(g\) khả vi hai lần và \(h\) có cấu trúc đơn giản.&lt;/p&gt;

&lt;p&gt;Bắt đầu từ điểm khởi tạo \(x^{(0)} \in \mathbb{R}^n\), ở mỗi vòng lặp \(k = 1, 2, 3, \dots\), phương pháp Newton proximal tìm hướng cập nhật \(v^{(k)}\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{alignat}{1}
v^{(k)} &amp;amp; = \arg \min_v \nabla g({x^{(k-1)}})^T v +  \frac{1}{2} v^T \nabla^2 g(x^{(k-1)}) v + h(x^{(k-1)} + v) 
\end{alignat}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;sau đó cập nhật điểm lặp với độ dài bước \(t_k\) (xác định bằng backtracking line search):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
x^{(k)} = x^{(k-1)} + t_k v^{(k)}, \quad k=1,2,3,\dots 
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;Chi phí mỗi vòng lặp cao (việc giải bài toán con tìm \(v^{(k)}\) nói chung khó).&lt;/li&gt;
    &lt;li&gt;Tuy nhiên, dưới các giả thiết thích hợp, phương pháp chỉ cần rất ít vòng lặp và đạt tốc độ hội tụ bậc hai cục bộ.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;ôn-tập-hàm-liên-hợp-conjugate-function&quot;&gt;Ôn tập: hàm liên hợp (conjugate function)&lt;/h2&gt;
&lt;p&gt;Với hàm \(f: \mathbb{R}^n \to \mathbb{R}\), hàm liên hợp \(f^*\) được định nghĩa là:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
f^*(y) = \max_x y^Tx - f(x)
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(1) Hàm liên hợp thường xuất hiện trong các bài toán đối ngẫu dưới dạng tương đương:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
-f^{\ast}(y) = \min_x f(x) - y^Tx
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(2) Nếu \(f\) là hàm lồi và đóng, thì \(f^{**} = f\). Hơn nữa:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
x \in \partial f^{\ast}(y) \Longleftrightarrow y \in \partial f(x) \Longleftrightarrow x \in \arg\min_z f(z) - y^Tz
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h4&gt;
&lt;p&gt;Trước hết, ta chứng minh \(x \in \partial f^{\ast}(y) \Longleftrightarrow y \in \partial f(x)\).&lt;/p&gt;

&lt;h4 id=&quot;bước-1-y-in-partial-fx-longrightarrow-x-in-partial-fasty&quot;&gt;Bước 1: \(y \in \partial f(x) \Longrightarrow x \in \partial f^{\ast}(y)\)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;Giả sử \(y \in \partial f(x)\). Khi đó \(x\) cực đại hóa hàm \(z \mapsto y^Tz - f(z)\), nên \(f^{\ast}(y) = y^Tx - f(x)\). Với mọi \(w\), ta có \(f^{\ast}(w) \ge w^Tx - f(x) = f^{\ast}(y) + x^T(w - y)\), điều này chứng tỏ \(x \in \partial f^{\ast}(y)\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;bước-2-x-in-partial-fasty-longrightarrow-y-in-partial-fx&quot;&gt;Bước 2: \(x \in \partial f^{\ast}(y) \Longrightarrow y \in \partial f(x)\)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;Áp dụng Bước 1 cho hàm \(f^{\ast}\): nếu \(x \in \partial f^{\ast}(y)\) thì \(y \in \partial f^{\ast\ast}(x)\). Vì \(f^{\ast\ast} = f\) nên suy ra \(y \in \partial f(x)\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;bước-3-x-in-partial-fasty-longleftrightarrow-y-in-partial-fx-longleftrightarrow-x-in-argmin_z-fz---ytz&quot;&gt;Bước 3: \(x \in \partial f^{\ast}(y) \Longleftrightarrow y \in \partial f(x) \Longleftrightarrow x \in \arg\min_z f(z) - y^Tz\)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;Tương đương \(y \in \partial f(x) \Longleftrightarrow x \in \arg\min_z f(z) - y^Tz\) suy trực tiếp từ định nghĩa dưới vi phân (\(0 \in \partial(f(x) - y^Tx)\)). Kết hợp với Bước 1 và Bước 2, ta thu được điều phải chứng minh.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(3) Nếu \(f\) lồi chặt thì:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{equation}
\nabla f^{\ast}(y) = \arg\min_z f(z) - y^T z
\end{equation}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;chứng-minh-1&quot;&gt;Chứng minh&lt;/h4&gt;

&lt;blockquote&gt;
  &lt;p&gt;Nếu \(f\) lồi chặt thì hàm \(z \mapsto f(z) - y^Tz\) có điểm cực tiểu duy nhất. Theo tính chất (2) ở trên, dưới vi phân \(\partial f^{\ast}(y)\) chỉ gồm đúng một phần tử — đó chính là gradient \(\nabla f^{\ast}(y)\). Do đó \(f^{\ast}\) là hàm khả vi.&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>20-07 Practical Exercises - Dual Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_07_Practical_Exercises_Dual_Methods/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_07_Practical_Exercises_Dual_Methods</id>
   <content type="html">&lt;p&gt;Mastering dual methods means being able to move fluidly between three representations of the same constrained problem: the &lt;strong&gt;primal Lagrangian&lt;/strong&gt;, the &lt;strong&gt;dual ascent / decomposition update&lt;/strong&gt;, and the &lt;strong&gt;scaled ADMM splitting&lt;/strong&gt;. Before working through the exercises below (adapted from Bertsekas and Boyd et al.), test your intuition on this quick warm-up comparing plain dual decomposition against Augmented Lagrangian on a 2-variable equality problem—seeing firsthand how \(\rho\) stabilizes the dual trajectory.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-key-techniques-practiced-in-these-exercises&quot;&gt;Key ideas: Key Techniques Practiced in These Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Deriving Decomposed Subproblems:&lt;/strong&gt; Separate \(\sum_i f_i(x_i) + \nu^T(\sum_i A_i x_i - c)\) into \(N\) independent scalar or vector minimizations and compute the exact dual ascent residual.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constructing Augmented Lagrangians:&lt;/strong&gt; Add \(\frac{\rho}{2}\|Ax - b\|_2^2\), solve the regularized primal step, and verify that updating \(\nu^{k+1} = \nu^k + \rho(Ax^{k+1} - b)\) enforces dual feasibility automatically.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Designing ADMM Splittings:&lt;/strong&gt; Introduce auxiliary variables \(z\) so that the \(x\)-update is a clean linear solve (Cholesky cacheable!) and the \(z\)-update is a closed-form proximal operator (soft-thresholding or projection).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Monitoring Stopping Criteria:&lt;/strong&gt; Track both primal residual \(\|r^{(k)}\|_2\) and dual residual \(\|s^{(k)}\|_2\) to diagnose whether \(\rho\) is too large (tiny \(r\), huge \(s\)) or too small (huge \(r\), tiny \(s\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-diagnosing-rho-imbalance-from-residuals&quot;&gt;Worked example: Diagnosing \(\rho\) Imbalance from Residuals&lt;/h3&gt;

&lt;p&gt;Suppose you run ADMM on \(\min_{x,z} \frac{1}{2}(x - 10)^2 + \frac{1}{2}z^2\) s.t. \(x - z = 0\) from \(z^0 = 0, w^0 = 0\) (exact optimum \(x^\star = z^\star = 5\)). Compare one iteration with tiny \(\rho = 0.1\) vs. balanced \(\rho = 1\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;With \(\rho = 0.1\) (under-penalized):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^1 = \frac{10 + 0.1(0)}{1 + 0.1} = \frac{10}{1.1} \approx 9.091\).&lt;/li&gt;
      &lt;li&gt;\(z^1 = \frac{0.1(9.091)}{1 + 0.1} \approx 0.826\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Primal residual: $$&lt;/td&gt;
              &lt;td&gt;r^1&lt;/td&gt;
              &lt;td&gt;=&lt;/td&gt;
              &lt;td&gt;9.091 - 0.826&lt;/td&gt;
              &lt;td&gt;= 8.265\((huge!); Dual residual:\)&lt;/td&gt;
              &lt;td&gt;s^1&lt;/td&gt;
              &lt;td&gt;= \rho&lt;/td&gt;
              &lt;td&gt;z^1 - z^0&lt;/td&gt;
              &lt;td&gt;= 0.1(0.826) = 0.083$$ (tiny!).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Ratio $$&lt;/td&gt;
              &lt;td&gt;r^1&lt;/td&gt;
              &lt;td&gt;/&lt;/td&gt;
              &lt;td&gt;s^1&lt;/td&gt;
              &lt;td&gt;\approx 100\(—immediately signaling that\)\rho$$ is too small and should be increased!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;With \(\rho = 1.0\) (balanced):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^1 = \frac{10}{2} = 5.0\), \(z^1 = \frac{5}{2} = 2.5\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Primal residual: $$&lt;/td&gt;
              &lt;td&gt;r^1&lt;/td&gt;
              &lt;td&gt;= 2.5\(; Dual residual:\)&lt;/td&gt;
              &lt;td&gt;s^1&lt;/td&gt;
              &lt;td&gt;= 1.0(2.5) = 2.5$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Ratio $$&lt;/td&gt;
              &lt;td&gt;r^1&lt;/td&gt;
              &lt;td&gt;/&lt;/td&gt;
              &lt;td&gt;s^1&lt;/td&gt;
              &lt;td&gt;= 1.0$$—perfectly balanced, cutting the error in half every single step! Keep this residual-balance diagnostic in mind as you work through the exercises below.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---dual-methods&quot;&gt;Practical Exercises - Dual Methods&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Bertsekas (1999) and Boyd et al. (2011).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-1-dual-decomposition&quot;&gt;📝 &lt;strong&gt;Exercise 1: Dual Decomposition&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Minimize \(\sum_{i=1}^N f_i(x_i)\) s.t. \(\sum x_i = c\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the Lagrangian and the dual&lt;br /&gt;
b) Decompose into \(N\) independent subproblems&lt;br /&gt;
c) Update the dual variable \(\nu\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**Lagrangian:**

$$L(x, \nu) = \sum_i f_i(x_i) + \nu\left(\sum x_i - c\right)$$

$$= \sum_i [f_i(x_i) + \nu x_i] - \nu c$$

**Dual:**

$$g(\nu) = \sum_i \min_{x_i} [f_i(x_i) + \nu x_i] - \nu c$$

**Decomposition:** Solve the $$N$$ problems in parallel!

**Dual update:** $$\nu^{(k+1)} = \nu^{(k)} + \alpha(\sum x_i^{(k)} - c)$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-augmented-lagrangian&quot;&gt;📝 &lt;strong&gt;Exercise 2: Augmented Lagrangian&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;\(\min f(x)\) s.t. \(Ax = b\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the augmented Lagrangian \(L_\rho(x, \nu)\)&lt;br /&gt;
b) Compare it with the standard Lagrangian&lt;br /&gt;
c) Derive dual ascent with a quadratic penalty&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Augmented Lagrangian:**

$$L_\rho(x, \nu) = f(x) + \nu^T(Ax - b) + \frac{\rho}{2}\|Ax - b\|^2$$

**b) Advantage:**

**Standard:** $$g(\nu)$$ may be non-differentiable

**Augmented:** smoother dual, better conditioning

**c) ALM iterations:**

1. $$x^{(k+1)} = \arg\min_x L_\rho(x, \nu^{(k)})$$
2. $$\nu^{(k+1)} = \nu^{(k)} + \rho(Ax^{(k+1)} - b)$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-method-of-multipliers&quot;&gt;📝 &lt;strong&gt;Exercise 3: Method of Multipliers&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Apply ALM to \(\min x_1^2 + x_2^2\) s.t. \(x_1 + x_2 = 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Set up the ALM&lt;br /&gt;
b) Iterate from \(\nu^{(0)} = 0\), \(\rho = 1\)&lt;br /&gt;
c) Compare with dual gradient ascent&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) ALM:**

$$L_\rho(x, \nu) = x_1^2 + x_2^2 + \nu(x_1 + x_2 - 1) + \frac{1}{2}(x_1 + x_2 - 1)^2$$

**b) $$x$$-minimization:**

$$\nabla_x L = (2x_1 + \nu + (x_1 + x_2 - 1), 2x_2 + \nu + (x_1 + x_2 - 1)) = 0$$

$$3x_1 + x_2 = 1 - \nu$$

$$x_1 + 3x_2 = 1 - \nu$$

Solution: $$x_1 = x_2 = \frac{1-\nu}{4}$$

**Iteration 0:** $$\nu = 0$$ → $$x = (0.25, 0.25)$$

Residual: $$0.5 - 1 = -0.5$$

$$\nu^{(1)} = 0 + 1(-0.5) = -0.5$$

**Iteration 1:** $$x = (0.375, 0.375)$$, $$\nu^{(2)} = -0.75$$

Converges to $$x^* = (0.5, 0.5)$$, $$\nu^* = -1$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-dual-gradient-vs-dual-newton&quot;&gt;📝 &lt;strong&gt;Exercise 4: Dual Gradient vs Dual Newton&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Maximize \(g(\nu)\) with gradient ascent and with Newton’s method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Gradient: \(\nu^{(k+1)} = \nu^{(k)} + \alpha \nabla g(\nu^{(k)})\)&lt;br /&gt;
b) Newton: \(\nu^{(k+1)} = \nu^{(k)} - (\nabla^2 g)^{-1} \nabla g\)&lt;br /&gt;
c) Compare the convergence&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Dual gradient:**

$$\nabla g(\nu) = Ax^*(\nu) - b$$

$$\nu^{(k+1)} = \nu^{(k)} + \alpha(Ax^{(k)} - b)$$

**Rate:** sublinear $$O(1/k)$$ in general (as for the subgradient method if $$g$$ is non-smooth); linear when $$g$$ is strongly concave, i.e. when $$f$$ is smooth and $$A$$ has full row rank.

**b) Dual Newton:**

$$\nabla^2 g(\nu) = A \frac{\partial x^*}{\partial \nu} A^T$$

**Quadratic convergence** (locally) if $$g$$ is smooth and strongly concave.

**c) Tradeoff:**

- **Gradient:** cheap per iteration
- **Newton:** expensive (Hessian), fast convergence

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-consensus-optimization&quot;&gt;📝 &lt;strong&gt;Exercise 5: Consensus Optimization&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;\(N\) agents minimize \(\sum f_i(x_i)\) s.t. \(x_1 = x_2 = \cdots = x_N\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Dual decomposition&lt;br /&gt;
b) Average consensus update&lt;br /&gt;
c) Distributed implementation&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Lagrangian:**

$$L(x, \nu) = \sum_i f_i(x_i) + \sum_{i&amp;lt;j} \nu_{ij}(x_i - x_j)$$

**Dual:**

$$g(\nu) = \sum_i \min_{x_i} \left[ f_i(x_i) + \sum_j \nu_{ij}(x_i - x_j) \right]$$

**b) Update:**

Each agent $$i$$:

$$x_i^{(k+1)} = \arg\min_{x_i} \left[ f_i(x_i) + \sum_j \nu_{ij}^{(k)}(x_i - \bar{x}_j^{(k)}) \right]$$

$$\nu_{ij}^{(k+1)} = \nu_{ij}^{(k)} + \rho(x_i^{(k+1)} - x_j^{(k+1)})$$

**c) Communication:**

Each agent only needs to communicate with its neighbors!

**Distributed consensus.**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Key Idea&lt;/th&gt;
      &lt;th&gt;Convergence&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual decomposition&lt;/td&gt;
      &lt;td&gt;Parallel subproblems&lt;/td&gt;
      &lt;td&gt;Sublinear&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Augmented Lagrangian&lt;/td&gt;
      &lt;td&gt;Quadratic penalty&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual gradient&lt;/td&gt;
      &lt;td&gt;First-order&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual Newton&lt;/td&gt;
      &lt;td&gt;Second-order&lt;/td&gt;
      &lt;td&gt;Quadratic&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Bertsekas, D. P. (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt;. Athena Scientific.&lt;/li&gt;
  &lt;li&gt;Boyd, S., et al. (2011). “Distributed Optimization and Statistical Learning via ADMM”.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>20-05 References</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_05_References/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_05_References</id>
   <content type="html">&lt;p&gt;The modern renaissance of dual methods and ADMM did not happen overnight—it grew out of a remarkable dialogue between 1970s PDE splitting (Glowinski, Marrocco, Gabay, Mercier), 2010s distributed machine learning (Boyd et al.’s landmark monograph), and control-theoretic convergence proofs (Nishihara, Lessard, Recht, Packard, and Jordan). This reference guide connects the papers listed below to the exact theoretical questions they answer so you can navigate the graduate literature with confidence.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-navigating-the-dual--admm-literature&quot;&gt;Key ideas: Navigating the Dual &amp;amp; ADMM Literature&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Foundational Synthesis (Boyd et al., 2010/2011):&lt;/strong&gt; The definitive monograph linking dual ascent, dual decomposition, augmented Lagrangians, and scaled ADMM to statistical learning (Lasso, consensus, distributed model fitting) with practical stopping criteria and adaptive \(\rho\) rules.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Global &amp;amp; Linear Convergence Theory (Deng &amp;amp; Yin 2012; Hong &amp;amp; Luo 2012):&lt;/strong&gt; Pinpoints the exact structural conditions—error bounds, strong convexity of one block, and full row/column rank—under which ADMM achieves global R-linear convergence rather than sublinear \(O(1/k)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Distributed &amp;amp; Asynchronous Networks (Iutzeler et al., 2014):&lt;/strong&gt; Extends linear convergence guarantees to randomized and distributed multi-agent networks where nodes update asynchronously.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Control-Theoretic Tight Rates (Nishihara et al., 2015):&lt;/strong&gt; Treats ADMM as a linear dynamical system with nonlinear monotone feedback, using Integral Quadratic Constraints (IQCs) and small SDPs to compute tight worst-case linear convergence factors \(\tau(\rho, \kappa)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-choosing-the-optimal-rho-via-nishiharalessardrecht-theory&quot;&gt;Worked example: Choosing the Optimal \(\rho\) via Nishihara–Lessard–Recht Theory&lt;/h3&gt;

&lt;p&gt;For a strongly convex, smooth quadratic block \(f(x) = \frac{1}{2}x^T Q x\) with eigenvalues in \([m, L]\) (condition number \(\kappa = L/m\)) and a linear constraint \(x = z\), control-theoretic ADMM analysis (Nishihara et al., 2015; Ghadimi et al., 2015) shows that the optimal penalty parameter balancing primal and dual contraction is the geometric mean:
\(\rho^\star = \sqrt{m L}, \qquad \text{giving linear rate } r^\star = 1 - \frac{2}{\sqrt{\kappa} + 1}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test on an ill-conditioned problem with \(m = 1, \; L = 100\) (\(\kappa = 100\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Optimal penalty: \(\rho^\star = \sqrt{1 \times 100} = 10\).&lt;/li&gt;
      &lt;li&gt;Resulting contraction factor per step: \(r^\star = 1 - \frac{2}{\sqrt{100} + 1} = 1 - \frac{2}{11} = \frac{9}{11} \approx 0.8182\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with a poorly chosen \(\rho = 1\) (ignoring the spectrum):&lt;/strong&gt;
With \(\rho = m = 1\), the slowest mode contracts at rate \(\approx 1 - \frac{1}{\kappa} = 0.99\)—requiring \(\approx 458\) iterations to shrink error by \(100\times\), versus only \(\frac{\ln(0.01)}{\ln(0.8182)} \approx 23\) iterations at \(\rho^\star = 10\) (a &lt;strong&gt;20× speedup&lt;/strong&gt; purely from spectral tuning!).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;S. Boyd, N. Parikh, E. Chu, B. Peleato and J. Eckstein (2010), “Distributed optimization and statistical learning via the alternating direction method of multipliers”&lt;/li&gt;
  &lt;li&gt;W. Deng and W. Yin (2012), “On the global and linear convergence of the generalized alternating direction method of multipliers”&lt;/li&gt;
  &lt;li&gt;M. Hong and Z. Luo (2012), “On  the linear convergence of the alternating direction  method of multipliers”&lt;/li&gt;
  &lt;li&gt;F. lutzeler, P. Bianchi, Ph. Ciblat, and W. Hachem (2014), “Linear convergence rate for distributed optimization with the alternating direction method of multipliers”&lt;/li&gt;
  &lt;li&gt;R. Nishihara, L. Lessard, B.  Recht, A. Packard, and M. Jordan (2015), “A general analysis of the convergence of ADMM”&lt;/li&gt;
  &lt;li&gt;L. Vandenberghe, Lecture Notes for EE 236C, UCLA, Spring 2011-2012&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>20-04-04 Example - Alternating Projection</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_04_04_Example-_Alternating_Projection/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_04_04_Example:_Alternating_Projection</id>
   <content type="html">&lt;p&gt;Finding a point in the intersection \(C \cap D\) of two closed convex sets is one of the oldest problems in applied mathematics—from CT image reconstruction to phase retrieval and feasibility of linear matrix inequalities. Classical &lt;strong&gt;von Neumann alternating projections&lt;/strong&gt; simply bounce back and forth (\(x \to \Pi_C(x) \to \Pi_D(x)\)), which can zig-zag painfully slowly when \(C\) and \(D\) meet at a shallow angle. Applying scaled ADMM to \(\min I_C(x) + I_D(z) \text{ s.t. } x = z\) turns out to rediscover &lt;strong&gt;Dykstra’s / Douglas–Rachford splitting&lt;/strong&gt;, using the dual memory \(w\) to push past shallow angles!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-admm-on-set-indicators-vs-naive-alternating-projection&quot;&gt;Key ideas: ADMM on Set Indicators vs. Naive Alternating Projection&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Feasibility as Composite Minimization:&lt;/strong&gt; Encoding \(x \in C \cap D\) as \(\min_{x,z} I_C(x) + I_D(z)\) subject to \(x = z\) turns set intersection into a standard ADMM problem whose proximal operators are Euclidean projections \(\Pi_C\) and \(\Pi_D\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Dual Offset Makes the Difference:&lt;/strong&gt; Plain alternating projection updates \(x^k = \Pi_C(z^{k-1}), \; z^k = \Pi_D(x^k)\). Scaled ADMM updates \(x^k = \Pi_C(z^{k-1} - w^{k-1}), \; z^k = \Pi_D(x^k + w^{k-1}), \; w^k = w^{k-1} + x^k - z^k\)—where \(w\) remembers the normal direction of the boundary!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equivalence to Douglas–Rachford Splitting:&lt;/strong&gt; Eliminating \(w\) shows that ADMM on \(I_C + I_D\) is algebraically identical to Douglas–Rachford reflection-projection splitting, which converges even when \(C\) and \(D\) are tangent!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaling Invariance (\(\rho\) Cancels Out):&lt;/strong&gt; Because \(I_C\) and \(I_D\) only take values \(0\) and \(+\infty\), dividing by \(\rho &amp;gt; 0\) does not change the indicator function at all—making ADMM alternating projection completely &lt;strong&gt;parameter-free&lt;/strong&gt;!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-intersecting-a-line-and-a-box-via-admm-projection&quot;&gt;Worked example: Intersecting a Line and a Box via ADMM Projection&lt;/h3&gt;

&lt;p&gt;Find a point in \(C \cap D \subset \mathbb{R}^2\) where \(C = \{(x_1, x_2) : x_2 = 1\}\) (horizontal line) and \(D = \{(x_1, x_2) : x_1 = x_2\}\) (the \(45^\circ\) diagonal). Clearly \(C \cap D = \{(1, 1)\}\). Start from \(z^0 = (0, 0)^T, \; w^0 = (0, 0)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Recall the two projections:&lt;/strong&gt;
\(\Pi_C(a, b) = (a, 1), \qquad \Pi_D(a, b) = \left(\frac{a+b}{2}, \frac{a+b}{2}\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 (\(z^0 = (0,0), w^0 = (0,0)\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^1 = \Pi_C(z^0 - w^0) = \Pi_C(0, 0) = (0, 1)\).&lt;/li&gt;
      &lt;li&gt;\(z^1 = \Pi_D(x^1 + w^0) = \Pi_D(0, 1) = (0.5, 0.5)\).&lt;/li&gt;
      &lt;li&gt;\(w^1 = w^0 + x^1 - z^1 = (0, 0) + (-0.5, +0.5) = (-0.5, 0.5)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2 (watch how \(w^1\) accelerates past naive alternating projection!):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[x^2 = \Pi_C(z^1 - w^1) = \Pi_C(0.5 - (-0.5), \; 0.5 - 0.5) = \Pi_C(1.0, \; 0.0) = (1.0, \; 1.0)!\]
      &lt;/li&gt;
      &lt;li&gt;
\[z^2 = \Pi_D(x^2 + w^1) = \Pi_D(0.5, \; 1.5) = (1.0, \; 1.0)!\]
      &lt;/li&gt;
      &lt;li&gt;\(w^2 = (-0.5, 0.5) + (0, 0) = (-0.5, 0.5)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with naive alternating projection:&lt;/strong&gt;
ADMM hit the &lt;strong&gt;exact&lt;/strong&gt; intersection \((1, 1)\) in &lt;strong&gt;2 iterations&lt;/strong&gt;! By contrast, naive alternating projection gives \((0, 1) \to (0.5, 0.5) \to (0.5, 1) \to (0.75, 0.75) \to \dots\)—needing infinitely many steps to reach \((1, 1)\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;example-alternating-projection&quot;&gt;Example: Alternating Projection&lt;/h1&gt;

&lt;p&gt;Consider the problem of finding a point in the intersection of convex sets \(C, D \in \mathbb{R}^n\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_x I_C(x) + I_D(x)  &lt;br /&gt;
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;where \(I_C(x)\) and \(I_D(x)\) are indicator functions for sets \(C\) and \(D\) respectively.&lt;/p&gt;

&lt;p&gt;To reformulate this problem in ADMM form, we express it as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{equation}
\min_{x,z} I_C(x) + I_D(x) \quad \text{subject to} \quad x - z = 0   
\end{equation}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;admm-algorithm-for-alternating-projection&quot;&gt;ADMM Algorithm for Alternating Projection&lt;/h2&gt;

&lt;p&gt;Each ADMM cycle involves two projections:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; = P_C \left( z^{(k-1)} - w^{(k-1)} \right) \\
z^{(k)} &amp;amp; = P_D \left( x^{(k)} + w^{(k-1)} \right) \\
w^{(k)} &amp;amp; = w^{(k-1)} + x^{(k)} - z^{(k)}
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;where \(P_C\) and \(P_D\) denote the projection operators onto sets \(C\) and \(D\) respectively.&lt;/p&gt;

&lt;h2 id=&quot;derivation&quot;&gt;Derivation&lt;/h2&gt;

&lt;p&gt;The update for \(x^{(k)}\) is derived as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; = \arg\min_x I_C(x) + \frac{\rho}{2} \lVert x - z^{(k-1)} + w^{(k-1)} \rVert_2^2 \\
&amp;amp; = P_C \left( z^{(k-1)} - w^{(k-1)} \right)
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Similarly, the update for \(z^{(k)}\) is derived as:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
z^{(k)} &amp;amp; = \arg\min_z I_D(z) + \frac{\rho}{2} \lVert x^{(k)} - z + w^{(k-1)} \rVert_2^2 \\
&amp;amp; = P_D \left( x^{(k)} + w^{(k-1)} \right)
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;comparison-with-classical-method&quot;&gt;Comparison with Classical Method&lt;/h2&gt;

&lt;p&gt;This method is similar to the classical alternating projection method but is often more efficient and robust in practice.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-04-03 ADMM in Scaled Form</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_04_03_ADMM_in_Scaled_Form/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_04_03_ADMM_in_Scaled_Form</id>
   <content type="html">&lt;p&gt;Writing out both the linear term \(u^T(Ax + Bz - c)\) and the quadratic term \(\frac{\rho}{2}\|Ax + Bz - c\|_2^2\) in every ADMM derivation is clutter waiting to cause a sign error. Simply defining the &lt;strong&gt;scaled dual variable&lt;/strong&gt; \(w = u / \rho\) and completing the square folds both terms into a single clean squared norm \(\frac{\rho}{2}\|Ax + Bz - c + w\|_2^2\)! Not only is scaled ADMM far easier to memorize and code, it also reveals what \(w^{(k)}\) really is: the &lt;strong&gt;running cumulative sum of all past primal residuals&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-completing-the-square-in-scaled-admm&quot;&gt;Key ideas: Completing the Square in Scaled ADMM&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Scaled Dual Variable (\(w = u / \rho\)):&lt;/strong&gt; Absorbing the linear Lagrangian term into the quadratic penalty via \(u^T r + \frac{\rho}{2}\|r\|_2^2 = \frac{\rho}{2}\|r + w\|_2^2 - \frac{\rho}{2}\|w\|_2^2\) eliminates the cross-term completely (since \(-\frac{\rho}{2}\|w\|_2^2\) does not depend on \(x\) or \(z\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Running Sum of Residuals:&lt;/strong&gt; The dual update simplifies to \(w^{(k)} = w^{(k-1)} + (Ax^{(k)} + Bz^{(k)} - c) = w^{(0)} + \sum_{j=1}^k r^{(j)}\)—literally an integral controller (the “I” term in PID control!) accumulating past constraint violations until they cancel out.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Direct Bridge to Proximal Operators:&lt;/strong&gt; When \(A = I, B = -I, c = 0\), the scaled \(x\)- and \(z\)-updates become pure proximal operators: \(x^{(k)} = \operatorname{prox}_{f/\rho}(z^{(k-1)} - w^{(k-1)})\) and \(z^{(k)} = \operatorname{prox}_{g/\rho}(x^{(k)} + w^{(k-1)})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Algebraic Equivalence:&lt;/strong&gt; Scaled and unscaled ADMM produce the &lt;em&gt;exact&lt;/em&gt; same primal iterates \((x^{(k)}, z^{(k)})\) at every step; scaled form is strictly preferred in practice for cleaner implementation and numerical readability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-a-constrained-box-quadratic-via-scaled-admm&quot;&gt;Worked example: Solving a Constrained Box-Quadratic via Scaled ADMM&lt;/h3&gt;

&lt;p&gt;Minimize \(\frac{1}{2}(x - 3)^2\) subject to \(x \in [0, 1]\) by splitting \(\min_{x,z} \frac{1}{2}(x - 3)^2 + I_{[0,1]}(z)\) s.t. \(x - z = 0\) (exact optimum \(x^\star = z^\star = 1\)). Use scaled ADMM with \(\rho = 2\) starting from \(z^0 = 0, \; w^0 = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the three scaled ADMM updates:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(k)} = \arg\min_x \frac{1}{2}(x - 3)^2 + \frac{2}{2}(x - z^{(k-1)} + w^{(k-1)})^2 = \frac{3 + 2(z^{(k-1)} - w^{(k-1)})}{3}\).&lt;/li&gt;
      &lt;li&gt;\(z^{(k)} = \Pi_{[0, 1]}\!\big(x^{(k)} + w^{(k-1)}\big)\).&lt;/li&gt;
      &lt;li&gt;\(w^{(k)} = w^{(k-1)} + x^{(k)} - z^{(k)}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 (\(z^0 = 0, w^0 = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^1 = \frac{3 + 0}{3} = 1.0\).&lt;/li&gt;
      &lt;li&gt;\(z^1 = \Pi_{[0,1]}(1.0 + 0) = 1.0\).&lt;/li&gt;
      &lt;li&gt;\(w^1 = 0 + (1.0 - 1.0) = 0\).
Wait—check dual optimality! At \(x^1 = 1\), \(\nabla f(1) = -2\), so we need \(w^\star = u^\star/\rho = 2/2 = 1\). Let’s check Iteration 2: \(x^2 = \frac{3 + 2(1 - 0)}{3} = \frac{5}{3} \approx 1.667\)!&lt;/li&gt;
      &lt;li&gt;\(z^2 = \Pi_{[0,1]}(5/3 + 0) = 1.0\).&lt;/li&gt;
      &lt;li&gt;\(w^2 = 0 + (5/3 - 1) = 2/3 \approx 0.667\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 3 (\(z^2 = 1, w^2 = 2/3\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^3 = \frac{3 + 2(1 - 2/3)}{3} = \frac{11}{9} \approx 1.222\).&lt;/li&gt;
      &lt;li&gt;\(z^3 = \Pi_{[0,1]}(11/9 + 2/3) = 1.0\).&lt;/li&gt;
      &lt;li&gt;\(w^3 = 2/3 + (11/9 - 1) = 8/9 \approx 0.889\) (approaching \(w^\star = 1\)!).
Notice how \(w^{(k)}\) accumulates the exact force needed to hold \(x^{(k)}\) against the wall \(x = 1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;admm-in-scaled-form&quot;&gt;ADMM in Scaled Form&lt;/h1&gt;

&lt;p&gt;ADMM can be expressed in scaled form by substituting the dual variable \(u\) with \(w = u/\rho\). The ADMM steps can then be written as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; = \arg\min_x f(x) + \frac{\rho}{2} \lVert Ax + Bz^{(k-1)} - c + w^{(k-1)} \rVert_2^2  \\
z^{(k)} &amp;amp; = \arg\min_z g(x) + \frac{\rho}{2} \lVert Ax^{(k)} + Bz - c + w^{(k-1)} \rVert_2^2  \\
w^{(k)} &amp;amp; = w^{(k-1)} + Ax^{(k)} + Bz^{(k)} - c 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;equivalence-to-original-form&quot;&gt;Equivalence to Original Form&lt;/h2&gt;

&lt;p&gt;We can show that the above equations are equivalent to the original form through the following process:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^{(k)} &amp;amp; = \arg\min_x f(x) + \frac{\rho}{2} \lVert Ax + Bz^{(k-1)} - c + w^{(k-1)} \rVert_2^2  \\
&amp;amp; = \arg\min_x f(x)  + \frac{\rho}{2} \lVert Ax + Bz^{(k-1)} - c \rVert_2^2  + \rho w^{(k-1)T} (Ax + Bz^{(k-1)} - c)  + \frac{\rho}{2}\lVert w^{(k-1)} \rVert_2^2 \\
&amp;amp; = \arg\min_x f(x)  + \frac{\rho}{2} \lVert Ax + Bz^{(k-1)} - c \rVert_2^2  + u^{(k-1)T} (Ax + Bz^{(k-1)} - c) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;where we used \(u^{(k-1)} = \rho w^{(k-1)}\) and dropped the constant term.&lt;/p&gt;

&lt;h2 id=&quot;interpretation-of-scaled-variable&quot;&gt;Interpretation of Scaled Variable&lt;/h2&gt;

&lt;p&gt;Here, \(w^{(k)}\) can be viewed as the sum of residuals up to iteration \(k\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{equation}
w^{(k)} = w^{(0)} + \sum_{i=1}^k (Ax^{(i)} + Bz^{(i)} - c) 
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;This scaled form is often more convenient for implementation and analysis.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-04-02 Convergence Guarantee</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_04_02_Converegence_Guarantee/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_04_02_Converegence_Guarantee</id>
   <content type="html">&lt;p&gt;One of the reasons ADMM became a staple across machine learning, signal processing, and control is how &lt;em&gt;forgiving&lt;/em&gt; its convergence theorem is: you do not need \(f\) or \(g\) to be differentiable, you do not need strong convexity, and you do not even need \(A\) or \(B\) to have full rank! As long as \(f\) and \(g\) are closed, proper, convex functions and the unaugmented Lagrangian has a saddle point, ADMM is guaranteed to drive primal residuals to zero and converge to the exact optimal objective for &lt;em&gt;every&lt;/em&gt; \(\rho &amp;gt; 0\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-what-admm-guaranteesand-what-it-does-not&quot;&gt;Key ideas: What ADMM Guarantees—and What It Does Not&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Three Core Convergence Pillars:&lt;/strong&gt; Under minimal convexity + saddle-point assumptions, ADMM guarantees: (1) primal residual \(r^{(k)} = Ax^{(k)} + Bz^{(k)} - c \to 0\), (2) objective value \(f(x^{(k)}) + g(z^{(k)}) \to p^\star\), and (3) dual multiplier \(u^{(k)} \to u^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lyapunov Energy Proof Intuition:&lt;/strong&gt; Defining the energy \(V^k = \frac{1}{\rho}\|u^k - u^\star\|_2^2 + \rho\|B(z^k - z^\star)\|_2^2\), Boyd et al. show \(V^{k+1} \le V^k - \rho\|r^{k+1}\|_2^2 - \rho\|B(z^{k+1} - z^k)\|_2^2\). Telescoping this inequality immediately proves \(\sum_k (\|r^k\|^2 + \|B(z^k - z^{k-1})\|^2) &amp;lt; \infty\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Primal Iterates May Not Converge Without Extra Assumptions:&lt;/strong&gt; If \(f\) or \(g\) is not strictly convex (e.g., an LP with a flat optimal face), \(f(x^k) + g(z^k) \to p^\star\) and \(r^k \to 0\) still hold, though individual iterates \((x^k, z^k)\) need not settle on a single point unless \(A, B\) have full column rank.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rate Landscape (\(O(1/k)\) vs. Linear):&lt;/strong&gt; Ergodic ADMM converges at \(O(1/k)\) generally, and jumps to &lt;strong&gt;linear convergence&lt;/strong&gt; when at least one block is smooth and strongly convex (Deng &amp;amp; Yin; Nishihara et al.)—making it ideal for modest-to-medium accuracy (\(10^{-3}\text{–}10^{-5}\)) at massive scale.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-monotonic-decay-of-the-admm-lyapunov-function&quot;&gt;Worked example: Verifying Monotonic Decay of the ADMM Lyapunov Function&lt;/h3&gt;

&lt;p&gt;Using the exact iterates from Lesson 20-04-01 (\(\min \frac{1}{2}(x-4)^2 + \frac{1}{2}z^2\) s.t. \(x - z = 0\), \(\rho = 1\), exact optimum \(x^\star = z^\star = u^\star = 2\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(k = 0\): \(z^0 = 0, \; u^0 = 0\).&lt;/li&gt;
  &lt;li&gt;\(k = 1\): \(x^1 = 2, \; z^1 = 1, \; u^1 = 1, \; r^1 = 1\).&lt;/li&gt;
  &lt;li&gt;\(k = 2\): \(x^2 = 2, \; z^2 = 1.5, \; u^2 = 1.5, \; r^2 = 0.5\).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Lyapunov energy \(V^k = \|u^k - u^\star\|^2 + \|z^k - z^\star\|^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(V^0 = (0 - 2)^2 + (0 - 2)^2 = 4 + 4 = 8.0\).&lt;/li&gt;
      &lt;li&gt;\(V^1 = (1 - 2)^2 + (1 - 2)^2 = 1 + 1 = 2.0\).&lt;/li&gt;
      &lt;li&gt;\(V^2 = (1.5 - 2)^2 + (1.5 - 2)^2 = 0.25 + 0.25 = 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the exact dissipation inequality \(V^{k+1} \le V^k - \|r^{k+1}\|^2 - \|z^{k+1} - z^k\|^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;From \(k = 0 \to 1\): \(V^0 - \|r^1\|^2 - \|z^1 - z^0\|^2 = 8 - 1^2 - 1^2 = 6.0 \ge 2.0 = V^1\) \(\checkmark\)!&lt;/li&gt;
      &lt;li&gt;From \(k = 1 \to 2\): \(V^1 - \|r^2\|^2 - \|z^2 - z^1\|^2 = 2 - 0.5^2 - 0.5^2 = 1.5 \ge 0.5 = V^2\) \(\checkmark\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Insight:&lt;/strong&gt;
Because \(V^k \ge 0\) drops by at least \(\|r^{k+1}\|^2 + \|z^{k+1} - z^k\|^2\) at every step, the sum of squared residuals is bounded above by \(V^0 = 8\)—guaranteeing \(r^k \to 0\) and \(s^k \to 0\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;convergence-guarantee-for-admm&quot;&gt;Convergence Guarantee for ADMM&lt;/h1&gt;

&lt;p&gt;Under appropriate conditions on \(f\) and \(g\) (note that \(A\) and \(B\) do not need to be full rank), ADMM satisfies the following for all \(\rho &amp;gt; 0\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Residual convergence&lt;/strong&gt;: As \(k \to \infty\), \(r^{(k)} = Ax^{(k)} + Bz^{(k)} - c \to 0\), meaning the primal iterates approach feasibility.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Objective convergence&lt;/strong&gt;: \(f(x^{(k)}) + g(z^{(k)}) \to f^{\ast} + g^{\ast}\), where \(f^{\ast} + g^{\ast}\) is the optimal primal objective value.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Dual convergence&lt;/strong&gt;: \(u^{(k)} \to u^{\ast}\), where \(u^{\ast}\) is the dual solution.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The exact convergence rate is not yet fully understood, and much research is currently ongoing in this area. Roughly speaking, ADMM performs similarly to or slightly better than first-order methods.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-04-01 ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_04_01_ADMM/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_04_01_ADMM</id>
   <content type="html">&lt;p&gt;Here is the exact algebraic machinery of &lt;strong&gt;ADMM&lt;/strong&gt; in its canonical unscaled form. Whenever you face a convex objective that mixes two incompatible structures—say, a quadratic loss plus an \(\ell_1\) penalty, or a trace norm plus box constraints—you introduce a duplicate variable \(z\) coupled by \(Ax + Bz = c\), write down the augmented Lagrangian \(L_\rho(x, z, u)\), and cycle through three lines: \(x\)-minimization, \(z\)-minimization, and dual ascent with step size \(\rho\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-three-line-admm-engine&quot;&gt;Key ideas: The Three-Line ADMM Engine&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Augmented Lagrangian \(L_\rho(x, z, u)\):&lt;/strong&gt; Combines \(f(x) + g(z) + u^T(Ax + Bz - c) + \frac{\rho}{2}\|Ax + Bz - c\|_2^2\). Every term in the \(x\)-step sees \(z^{(k-1)}\) as a constant, and every term in the \(z\)-step sees \(x^{(k)}\) as a constant.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal Residual (\(r^{(k)} = Ax^{(k)} + Bz^{(k)} - c\)):&lt;/strong&gt; Measures violation of the coupling constraint. Dual optimality of the \(z\)-update holds automatically at every iteration because \(u^{(k)} = u^{(k-1)} + \rho r^{(k)}\) matches the optimality condition of the \(z\)-subproblem!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Residual (\(s^{(k)} = \rho A^T B(z^{(k)} - z^{(k-1)})\)):&lt;/strong&gt; Measures violation of the &lt;em&gt;first&lt;/em&gt; block’s stationarity condition (since \(x^{(k)}\) was minimized against the &lt;em&gt;old&lt;/em&gt; \(z^{(k-1)}\) rather than \(z^{(k)}\)). When both \(\|r^{(k)}\|_2 \to 0\) and \(\|s^{(k)}\|_2 \to 0\), all KKT conditions are satisfied!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Role of the Penalty Parameter \(\rho &amp;gt; 0\):&lt;/strong&gt; While ADMM converges for &lt;em&gt;any&lt;/em&gt; fixed \(\rho &amp;gt; 0\), balancing \(\rho\) so \(\|r^{(k)}\|\) and \(\|s^{(k)}\|\) stay on the same order of magnitude dramatically accelerates practical speed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-primal--dual-residuals-in-unscaled-admm&quot;&gt;Worked example: Computing Primal &amp;amp; Dual Residuals in Unscaled ADMM&lt;/h3&gt;

&lt;p&gt;Solve \(\min_{x, z} \frac{1}{2}(x - 4)^2 + \frac{1}{2}z^2\) subject to \(x - z = 0\) (so \(A = 1, B = -1, c = 0\); exact optimum \(x^\star = z^\star = 2, u^\star = 2\)) with \(\rho = 1\), starting at \(z^0 = 0, u^0 = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;\(x\)-step:&lt;/strong&gt; \(\min_x \frac{1}{2}(x - 4)^2 + 0(x - 0) + \frac{1}{2}(x - 0)^2 \implies (x - 4) + x = 0 \implies x^1 = 2.0\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;\(z\)-step:&lt;/strong&gt; \(\min_z \frac{1}{2}z^2 + 0(2 - z) + \frac{1}{2}(2 - z)^2 \implies z - (2 - z) = 0 \implies z^1 = 1.0\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;\(u\)-step:&lt;/strong&gt; \(u^1 = u^0 + 1(x^1 - z^1) = 0 + (2 - 1) = 1.0\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Check residuals:&lt;/strong&gt; Primal \(r^1 = x^1 - z^1 = 1.0\); Dual \(s^1 = \rho A^T B (z^1 - z^0) = 1(1)(-1)(1 - 0) = -1.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;\(x\)-step:&lt;/strong&gt; \((x - 4) + 1 + (x - 1) = 0 \implies 2x = 4 \implies x^2 = 2.0\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;\(z\)-step:&lt;/strong&gt; \(z - 1 - (2 - z) = 0 \implies 2z = 3 \implies z^2 = 1.5\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;\(u\)-step:&lt;/strong&gt; \(u^2 = 1.0 + (2.0 - 1.5) = 1.5\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Check residuals:&lt;/strong&gt; Primal \(r^2 = 0.5\); Dual \(s^2 = -1(1.5 - 1.0) = -0.5\).
Both primal and dual residuals halved cleanly in one iteration, converging geometrically at rate \(1/2\) directly to \((x^\star, z^\star, u^\star) = (2, 2, 2)\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;alternating-direction-method-of-multipliers-admm&quot;&gt;Alternating Direction Method of Multipliers (ADMM)&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;Alternating Direction Method of Multipliers (ADMM)&lt;/strong&gt; is a powerful optimization algorithm that combines the benefits of dual decomposition and the method of multipliers. It is particularly effective for solving convex optimization problems that can be decomposed into smaller, more manageable subproblems.&lt;/p&gt;

&lt;p&gt;Consider the following problem:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_{x,z} f(x) + g(z) \quad \text{subject to} \quad Ax + Bz = c
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As before, we can augment the objective function as follows:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_{x,z} f(x) + g(z) + \frac{\rho}{2} \lVert Ax + Bz - c \rVert_2^2 \quad \text{subject to} \quad Ax + Bz = c
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;where \(\rho &amp;gt; 0\) is the penalty parameter.&lt;/p&gt;

&lt;h2 id=&quot;augmented-lagrangian&quot;&gt;Augmented Lagrangian&lt;/h2&gt;

&lt;p&gt;The augmented Lagrangian can be defined as:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
L_{\rho} (x,z,u) = f(x) + g(z) + u^T(Ax + Bz - c) + \frac{\rho}{2} \lVert Ax + Bz - c \rVert_2^2
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;admm-algorithm&quot;&gt;ADMM Algorithm&lt;/h2&gt;

&lt;p&gt;ADMM performs the following iterative steps for \(k=1,2,3,\ldots\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; = \arg\min_x  L_{\rho} (x,z^{(k-1)},u^{(k-1)}) \\
z^{(k)} &amp;amp; = \arg\min_z  L_{\rho} (x^{(k)},z,u^{(k-1)}) \\
u^{(k)} &amp;amp; = u^{(k-1)} + \rho (Ax^{(k)} + Bz^{(k)} - c) 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Key Point:&lt;/strong&gt; It is crucial that \(x^{(k)}\) obtained from the first step is used in the second step to compute \(z^{(k)}\). This alternating update structure is essential for convergence.&lt;/p&gt;

&lt;h2 id=&quot;comparison-with-method-of-multipliers&quot;&gt;Comparison with Method of Multipliers&lt;/h2&gt;

&lt;p&gt;Note that in the general &lt;strong&gt;Method of Multipliers&lt;/strong&gt;, the first two steps are replaced by the following joint minimization:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
(x^{(k)}, z^{(k)}) = \arg\min_{x,z} L_{\rho} (x,z,u^{(k-1)})   &lt;br /&gt;
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The key advantage of ADMM is that it decomposes this joint minimization into two separate, simpler subproblems that can often be solved more efficiently or even in closed form.&lt;/p&gt;

&lt;h3 id=&quot;general-admm-in-about-3-minutes&quot;&gt;General ADMM in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/admm-general_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The augmented Lagrangian, the three x, z, u updates, and a three-machine consensus problem: the prices u, the answer 12/7, and the effect of ρ.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-04 A peak at ADMM</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_04_00_A_peak_at_ADMM/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_04_00_A_peak_at_ADMM</id>
   <content type="html">&lt;p&gt;At the end of Section 20-03 we hit a classic engineering dilemma: &lt;strong&gt;dual decomposition&lt;/strong&gt; splits big problems into parallel pieces but diverges without strong convexity; the &lt;strong&gt;augmented Lagrangian method&lt;/strong&gt; converges robustly even for nonsmooth linear problems but re-couples the variables through \(\frac{\rho}{2}\|Ax + Bz - c\|_2^2\). The &lt;strong&gt;Alternating Direction Method of Multipliers (ADMM)&lt;/strong&gt; breaks that stalemate with a deceptively simple Gauss–Seidel trick: instead of minimizing the augmented Lagrangian over \((x, z)\) &lt;em&gt;jointly&lt;/em&gt;, minimize over \(x\) first (holding \(z\) fixed), then over \(z\) (holding the fresh \(x\) fixed), then update the dual price \(u\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-bridging-decomposition-and-augmentation&quot;&gt;Key ideas: Bridging Decomposition and Augmentation&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Two-Block Splitting Template:&lt;/strong&gt; ADMM targets \(\min_{x,z} f(x) + g(z)\) subject to \(Ax + Bz = c\), separating a problem into two simpler pieces (for example, smooth data fidelity \(f(x)\) and nonsmooth sparsity \(g(z)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gauss–Seidel Alternating Minimization:&lt;/strong&gt; Updating \(x^{(k)}\) with \(z^{(k-1)}\) frozen and then \(z^{(k)}\) with \(x^{(k)}\) frozen keeps each subproblem small and separable—often reducing both updates to closed-form linear solves or proximal operators.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preserving Robustness Without Strong Convexity:&lt;/strong&gt; Remarkably, taking just &lt;em&gt;one&lt;/em&gt; alternating pass over \(x\) and \(z\) before updating \(u\) is enough to retain global convergence for general closed convex \(f\) and \(g\) for &lt;em&gt;any&lt;/em&gt; \(\rho &amp;gt; 0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why ADMM Dominates Modern Distributed Optimization:&lt;/strong&gt; From Lasso and Robust PCA to consensus federated learning, ADMM turns intractable coupled convex programs into modular pipelines of tiny subproblems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-alternating-pass-vs-joint-minimization&quot;&gt;Worked example: One Alternating Pass vs. Joint Minimization&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider splitting $$\min_{x,z} \frac{1}{2}x^2 +&lt;/td&gt;
      &lt;td&gt;z&lt;/td&gt;
      &lt;td&gt;\(subject to\)x - z = 0\((exact optimum\)x^\star = z^\star = 0\() with\)\rho = 1\(, starting from\)z^0 = 2, \; u^0 = 0$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(x\)-update (smooth quadratic only, holding \(z^0 = 2\) fixed):&lt;/strong&gt;
\(x^1 = \arg\min_x \; \frac{1}{2}x^2 + 0(x - 2) + \frac{1}{2}(x - 2)^2 \implies x + (x - 2) = 0 \implies x^1 = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(z\)-update (nonsmooth \(\ell_1\) only, using fresh \(x^1 = 1\)):&lt;/strong&gt;
\(z^1 = \arg\min_z \; |z| + 0(1 - z) + \frac{1}{2}(1 - z)^2 = S_1(1) = 0!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual price update:&lt;/strong&gt;
\(u^1 = u^0 + 1(x^1 - z^1) = 0 + (1 - 0) = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why this is magical:&lt;/strong&gt;
Notice we never had to minimize \(\frac{1}{2}x^2 + |x|\) jointly; Step 1 was a pure linear equation and Step 2 was a pure soft-threshold! In Iteration 2, \(x^2 = \arg\min \frac{1}{2}x^2 + 1(x - 0) + \frac{1}{2}x^2 \implies 2x + 1 = 0 \implies x^2 = -0.5\), \(z^2 = S_1(-0.5 + 1) = S_1(0.5) = 0\), and \(u^2 = 0.5\)—closing rapidly on \((0, 0)\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;lipschitz-gradients-and-strong-convexity&quot;&gt;Lipschitz gradients and strong convexity&lt;/h2&gt;
&lt;p&gt;In this section, we examine an overview of the Alternating Direction Method of Multipliers (ADMM) technique. While the augmented Lagrangian method previously did not provide decomposability, ADMM is a method that provides decomposability along with convergence properties.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-03 Augmented Lagrangians</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_03_Augmented_Lagrangians/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_03_Augmented_Lagrangians</id>
   <content type="html">&lt;p&gt;Plain dual ascent has an Achilles’ heel: if \(f(x)\) is not strictly convex (say, a linear program or an \(\ell_1\) regularizer), the Lagrangian minimizer \(x(u)\) can jump wildly or even blow up to \(-\infty\)! In 1969, Magnus Hestenes and Michael Powell discovered an astonishingly simple cure—the &lt;strong&gt;Augmented Lagrangian Method (Method of Multipliers)&lt;/strong&gt;. Adding the quadratic penalty \(\frac{\rho}{2}\|Ax - b\|_2^2\) does not change the optimal solution by a single digit (since \(Ax - b = 0\) at every feasible point!), yet it acts like a mathematical shock absorber: smoothing the dual, restoring convergence without strong convexity, and automatically locking the dual step size to \(t_k = \rho\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-the-quadratic-augmentation-changes-everything&quot;&gt;Key ideas: Why the Quadratic Augmentation Changes Everything&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Feasibility-Preserving Penalty:&lt;/strong&gt; Because \(\frac{\rho}{2}\|Ax - b\|_2^2 = 0\) whenever \(Ax = b\), minimizing \(f(x) + \frac{\rho}{2}\|Ax - b\|_2^2\) subject to \(Ax = b\) has the &lt;em&gt;exact&lt;/em&gt; same optimal set and optimal value as the original problem—unlike pure quadratic penalty methods, which require \(\rho \to \infty\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why the Step Size Is Exactly \(\rho\):&lt;/strong&gt; Stationarity of the \(x\)-update gives \(0 \in \partial f(x^{(k)}) + A^T\big(u^{(k-1)} + \rho(Ax^{(k)} - b)\big)\). Setting \(u^{(k)} = u^{(k-1)} + \rho(Ax^{(k)} - b)\) makes \((x^{(k)}, u^{(k)})\) satisfy dual stationarity \(0 \in \partial f(x^{(k)}) + A^T u^{(k)}\) &lt;em&gt;identically at every single iteration&lt;/em&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smoothing via Moreau Envelope:&lt;/strong&gt; The augmented dual function is literally the Moreau–Yosida regularization of the original dual \(g(u)\), which is &lt;em&gt;always&lt;/em&gt; continuously differentiable with \((1/\rho)\)-Lipschitz gradient—even if \(f\) is linear or nonsmooth!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The One Trade-Off (Loss of Separability):&lt;/strong&gt; Expanding \(\frac{\rho}{2}\|\sum_i A_i x_i - b\|_2^2\) introduces cross-terms \(x_i^T A_i^T A_j x_j\) that re-couple the blocks—setting the stage directly for ADMM in Section 20-04!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-rescuing-a-linear-problem-where-dual-ascent-fails&quot;&gt;Worked example: Rescuing a Linear Problem Where Dual Ascent Fails&lt;/h3&gt;

&lt;p&gt;Consider the 1D linear program \(\min_{x \in \mathbb{R}} 2x\) subject to \(x = 3\) (trivial optimum \(x^\star = 3, u^\star = -2\)). Notice \(f(x) = 2x\) is &lt;strong&gt;not&lt;/strong&gt; strictly convex!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Watch plain dual ascent fail immediately:&lt;/strong&gt;
The ordinary Lagrangian is \(L(x, u) = (2 + u)x - 3u\). For &lt;em&gt;any&lt;/em&gt; \(u \neq -2\), \(\inf_x L(x, u) = -\infty\)! Plain dual ascent cannot even take step 1 unless you already guessed \(u^0 = -2\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Now apply the Augmented Lagrangian Method with \(\rho = 1\) from \(u^0 = 0\):&lt;/strong&gt;
\(L_1(x, u) = 2x + u(x - 3) + \frac{1}{2}(x - 3)^2.\)
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;\(x\)-update:&lt;/strong&gt; Differentiate with respect to \(x$:\)2 + u^0 + (x^1 - 3) = 0 \implies x^1 = 3 - 2 - 0 = 1$$ (well-defined and finite!).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;\(u\)-update:&lt;/strong&gt; \(u^1 = u^0 + \rho(x^1 - 3) = 0 + 1(1 - 3) = -2 = u^\star\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check Iteration 2 at \(u^1 = -2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;\(x\)-update:&lt;/strong&gt; \(2 + (-2) + (x^2 - 3) = 0 \implies x^2 = 3 = x^\star\)!&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;\(u\)-update:&lt;/strong&gt; \(u^2 = -2 + 1(3 - 3) = -2\).
Where plain dual ascent blew up to \(-\infty\), the Augmented Lagrangian Method hit the &lt;em&gt;exact&lt;/em&gt; primal-dual optimum in &lt;strong&gt;two iterations&lt;/strong&gt; with finite \(\rho = 1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A drawback of dual ascent is that it needs strong conditions to guarantee convergence. (To guarantee convergence, \(f\) had to be strongly convex.) This drawback can be remedied by the &lt;strong&gt;augmented Lagrangian method&lt;/strong&gt; (also called the &lt;strong&gt;method of multipliers&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;We transform the primal problem as follows.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_x f(x) + \frac{\rho}{2} \lVert Ax - b \rVert _2^2 \quad \text{ subject to } \quad Ax = b
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here \(\rho &amp;gt; 0\). If \(A\) has full column rank, the objective is strongly convex. The new problem is exactly equivalent to the original one (the augmented term \(Ax - b\) is zero at every feasible point).&lt;/p&gt;

&lt;h2 id=&quot;augmented-lagrangian-method&quot;&gt;Augmented Lagrangian Method&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Dual gradient ascent&lt;/strong&gt; on this problem repeats the following for \(k=1,2,3,\dots\)&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; \in \arg\min_x f(x) + (u^{(k-1)})^T A x + \frac{\rho}{2} \lVert Ax - b \rVert_2^2  \\
u^{(k)} &amp;amp; = u^{(k-1)} + \rho (A x^{(k)} - b)
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;In this dual algorithm, \(\rho\) plays the role of the step size, i.e. \(t_k=\rho\). To see why, consider the following.&lt;/p&gt;

&lt;h4 id=&quot;why-rho-is-a-suitable-step-size&quot;&gt;Why \(\rho\) is a suitable step size&lt;/h4&gt;

&lt;p&gt;Since \(x^{(k)}\) minimizes \(f(x) + (u^{(k-1)})^T Ax + \frac{\rho}{2} \lVert Ax - b\rVert _2^2\),
the stationarity condition says that the subgradient of the objective at \(x^{(k)}\) must contain \(0\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
0 &amp;amp; \in \partial f(x^{(k)}) + A^T \left( u^{(k-1)} + \rho (A x^{(k)} -b) \right)  \\
  &amp;amp; = \partial f(x^{(k)}) + A^T u^{(k)}
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;So with the update \(u^{(k)} = u^{(k-1)} + \rho (A x^{(k)} - b)\), \(x^{(k)}\) minimizes the Lagrangian \(f(x) + (u^{(k)})^T A x\) exactly as the dual stationarity condition requires. Under suitable conditions, \(Ax^{(k)}-b\) approaches \(0\), so the iterates become feasible, the KKT conditions are eventually satisfied, and \(x^{(k)}\) and \(u^{(k)}\) approach optimality.&lt;/p&gt;

&lt;p&gt;The advantage of the &lt;strong&gt;augmented Lagrangian method&lt;/strong&gt; is its much better convergence; its drawback is that it loses the decomposability of the problem.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-02-02 Dual Decomposition with Inequality Constraint</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_02_02_Dual_Decomposition_with_Inequality_Constraint/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_02_02_Dual_Decomposition_with_Inequality_Constraint</id>
   <content type="html">&lt;p&gt;Real-world resource constraints are rarely exact equalities—bandwidth on a network link cannot &lt;em&gt;exceed&lt;/em&gt; capacity \(b\) (\(\sum_i A_i x_i \le b\)), and a shared warehouse budget cannot be overspent, though leaving unused capacity is perfectly legal! Switching from \(=\) to \(\le\) introduces one crucial economic rule: &lt;strong&gt;prices cannot be negative&lt;/strong&gt; (\(u \ge 0\)). If a resource is under-utilized, its price drops to zero and stops there, turning dual decomposition into &lt;strong&gt;projected dual ascent&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-inequality-pricing--complementary-slackness&quot;&gt;Key ideas: Inequality Pricing &amp;amp; Complementary Slackness&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nonnegative Dual Prices (\(u \ge 0\)):&lt;/strong&gt; For \(\sum_{i=1}^B A_i x_i \le b\), dual feasibility requires \(u \ge 0\), so every dual update projects onto the nonnegative orthant: \(u^{(k)} = \big(u^{(k-1)} + t_k(\sum_i A_i x_i^{(k)} - b)\big)_+\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Economic Meaning of Projection \((\cdot)_+\):&lt;/strong&gt; When total demand exceeds capacity (\(\sum_i A_i x_i &amp;gt; b\)), the price rises to ration the resource; when demand is below capacity (\(\sum_i A_i x_i &amp;lt; b\)), the price falls—clamping at \(0\) if the resource is genuinely abundant!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complementary Slackness at Equilibrium:&lt;/strong&gt; At convergence, either the resource is saturated (\(\sum_i A_i x_i^\star = b, u^\star \ge 0\)) or it has slack and becomes free (\(\sum_i A_i x_i^\star &amp;lt; b \implies u^\star = 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Network Utility Maximization (NUM):&lt;/strong&gt; This exact projected dual decomposition algorithm underlies TCP congestion control—routers update link congestion prices \(u_\ell = (u_\ell + t(\text{flow}_\ell - c_\ell))_+\) while users independently adjust sending rates \(x_i\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-congestion-pricing-across-two-links&quot;&gt;Worked example: Congestion Pricing Across Two Links&lt;/h3&gt;

&lt;p&gt;Two users maximize utility (equivalently minimize cost) \(\min_{x \ge 0} \frac{1}{2}(x_1 - 5)^2 + \frac{1}{2}(x_2 - 3)^2\) subject to a shared link capacity \(x_1 + x_2 \le 6\) (and a second abundant link \(x_1 \le 10\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the independent user responses for link prices \(u = (u_1, u_2)^T \ge 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;User 1: \(\min_{x_1 \ge 0} \frac{1}{2}(x_1 - 5)^2 + (u_1 + u_2)x_1 \implies x_1(u) = (5 - u_1 - u_2)_+\).&lt;/li&gt;
      &lt;li&gt;User 2: \(\min_{x_2 \ge 0} \frac{1}{2}(x_2 - 3)^2 + u_1 x_2 \implies x_2(u) = (3 - u_1)_+\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 starting from \(u^0 = (0, 0.5)^T\) with step size \(t = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;User rates: \(x_1^1 = 5 - 0.5 = 4.5\), \(x_2^1 = 3 - 0 = 3.0\).&lt;/li&gt;
      &lt;li&gt;Link 1 residual (congested!): \(4.5 + 3.0 - 6 = +1.5 \implies u_1^1 = (0 + 0.5(1.5))_+ = 0.75\).&lt;/li&gt;
      &lt;li&gt;Link 2 residual (abundant!): \(4.5 - 10 = -5.5 \implies u_2^1 = (0.5 + 0.5(-5.5))_+ = (-2.25)_+ = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2 at \(u^1 = (0.75, 0)^T\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;User rates: \(x_1^2 = 4.25, \; x_2^2 = 2.25\) (total \(6.5\), excess \(+0.5\)).&lt;/li&gt;
      &lt;li&gt;Prices: \(u_1^2 = 0.75 + 0.5(0.5) = 1.0\), \(u_2^2 = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify exact equilibrium at \(u^\star = (1, 0)^T\):&lt;/strong&gt;
\(x_1^\star = 4, \; x_2^\star = 2\), Link 1 is saturated (\(4 + 2 = 6, u_1^\star = 1 &amp;gt; 0\)) and Link 2 is free (\(4 &amp;lt; 10, u_2^\star = 0\))—exact complementary slackness!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Consider the following problem. The difference from the previous one is that the constraint is an inequality.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{equation}
\min_x \sum_{i=1}^B f_i(x_i) \quad \text{subject to} \quad \sum_{i=1}^B A_i x_i \leq b
\end{equation}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;dual-decomposition-projected-subgradient-method&quot;&gt;Dual decomposition (projected subgradient method)&lt;/h2&gt;
&lt;p&gt;For this problem the dual variable must always be nonnegative, i.e. \(u \geq 0\). Therefore, when computing the next value of \(u\), we project it onto the nonnegative orthant.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
x_i^{(k)} &amp;amp; \in \arg \min_{x_i} f_i(x_i) + (u^{(k-1)})^T A_i x_i, \quad i=1,\dots,B  \\
u^{(k)}   &amp;amp; = \left( u^{(k-1)} + t_k \left(\sum_{i=1}^B A_i x_i^{(k)} - b \right) \right)_+
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(u_{+}\) denotes the nonnegative part of \(u\), i.e. \((u_+)_i = \max \left\{0,u_i \right\}, i=1,\dots,m\).
These steps are repeated for \(k=1,2,3,\dots\)&lt;/p&gt;

&lt;h4 id=&quot;price-coordination-interpretation&quot;&gt;Price coordination interpretation&lt;/h4&gt;
&lt;p&gt;In general, dual decomposition problems can be interpreted from the viewpoint of price coordination as follows. (Vandenberghe)&lt;/p&gt;
&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;There are \(B\) independent units, and each unit decides its own decision variable \(x_i\).&lt;/li&gt;
    &lt;li&gt;Each constraint represents a limit on a resource shared by the \(B\) units, and the dual variable \(u_j\) is the price of resource \(j\).&lt;/li&gt;
    &lt;li&gt;The dual variables are updated as
 \begin{equation}
 u_j^{+} = (u_j - t s_j)_{+}, \quad  j=1,\dots,m
 \end{equation}&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;\(\quad\) where \(s=b-\sum_{i=1}^B A_ix_i\) is the slack: &lt;br /&gt;
\(\qquad\) - if \(s_j &amp;lt; 0\), resource \(j\) is over-utilized, so the price \(u_j\) is increased; &lt;br /&gt;
\(\qquad\) - if \(s_j &amp;gt; 0\), resource \(j\) is under-utilized, so the price \(u_j\) is decreased; &lt;br /&gt;
\(\qquad\) - the price is never allowed to become negative.&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>20-02-01 Dual Decomposition with Equality Constraint</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_02_01_Dual_Decomposition_with_Equality_Constraint/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_02_01_Dual_Decomposition_with_Equality_Constraint</id>
   <content type="html">&lt;p&gt;Equality constraints \(\sum_{i=1}^B A_i x_i = b\) are the backbone of network flow conservation, consensus averaging, and power-grid balance: supply must equal demand &lt;em&gt;exactly&lt;/em&gt;, with no slack allowed. Because the dual variable \(u \in \mathbb{R}^m\) is unconstrained in sign, dual decomposition with equality constraints runs pure unconstrained dual ascent—letting each block \(i\) solve its own subproblem \(f_i(x_i) + u^T A_i x_i\) in parallel while the coordinator nudges \(u\) proportionally to the exact imbalance \(\sum_i A_i x_i - b\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-equality-constrained-dual-decomposition&quot;&gt;Key ideas: Equality-Constrained Dual Decomposition&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Column-Block Partitioning:&lt;/strong&gt; Splitting \(x = (x_1, \dots, x_B)\) and \(A = [A_1, \dots, A_B]\) rewrites \(Ax = \sum_{i=1}^B A_i x_i\), exposing the additive structure of \(u^T Ax\) inside the Lagrangian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unconstrained Dual Price \(u \in \mathbb{R}^m\):&lt;/strong&gt; Unlike inequality constraints, equality multipliers can be positive (penalizing oversupply) or negative (penalizing undersupply), so no projection step is needed on \(u\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Residual as Dual Ascent Direction:&lt;/strong&gt; Gathering \(A_i x_i^{(k)}\) from each worker produces \(r^{(k)} = \sum_{i=1}^B A_i x_i^{(k)} - b\), giving the update \(u^{(k)} = u^{(k-1)} + t_k r^{(k)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Limitation on Non-Strictly Convex Blocks:&lt;/strong&gt; If any block \(f_i\) is linear or piecewise-linear, \(x_i^{(k)}\) can jump discontinuously between extreme points as \(u\) crosses a kink, causing persistent oscillation unless ergodic averaging or an augmented Lagrangian is used.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-three-node-weighted-equality-balance&quot;&gt;Worked example: Three-Node Weighted Equality Balance&lt;/h3&gt;

&lt;p&gt;Minimize \(\frac{1}{2}x_1^2 + x_2^2 + \frac{3}{2}x_3^2\) subject to \(x_1 + 2x_2 + x_3 = 6\) (so \(A_1 = 1, A_2 = 2, A_3 = 1, b = 6\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Derive the three parallel block updates for any \(u \in \mathbb{R}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Block 1: \(\min \frac{1}{2}x_1^2 + u x_1 \implies x_1(u) = -u\).&lt;/li&gt;
      &lt;li&gt;Block 2: \(\min x_2^2 + 2u x_2 \implies 2x_2 + 2u = 0 \implies x_2(u) = -u\).&lt;/li&gt;
      &lt;li&gt;Block 3: \(\min \frac{3}{2}x_3^2 + u x_3 \implies 3x_3 + u = 0 \implies x_3(u) = -\frac{u}{3}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the safe step size using strong convexity:&lt;/strong&gt;
Here \(d = \min(1, 2, 3) = 1\) and \(\|A\|_2^2 = 1^2 + 2^2 + 1^2 = 6\), so \(t = \frac{1}{6}\) is guaranteed safe (exact dual Lipschitz constant is \(1 + 2(1) + \frac{1}{3} = \frac{10}{3}\), so even \(t = 0.3\) is exact!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trace two iterations from \(u^0 = 0\) with \(t = 0.25\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Iter 1:&lt;/strong&gt; \(x^{(1)} = (0, 0, 0)^T \implies r^{(1)} = 0 - 6 = -6 \implies u^1 = 0 + 0.25(-6) = -1.5\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Iter 2:&lt;/strong&gt; \(x^{(2)} = (1.5, \; 1.5, \; 0.5)^T \implies A x^{(2)} = 1.5 + 3.0 + 0.5 = 5.0 \implies r^{(2)} = 5.0 - 6 = -1.0\).&lt;/li&gt;
      &lt;li&gt;\(u^2 = -1.5 + 0.25(-1.0) = -1.75\) (exact optimum is \(u^\star = -1.8, \; x^\star = (1.8, 1.8, 0.6)^T\)!).
In just 2 parallel rounds, the equality residual dropped from \(-6.0\) to \(-1.0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Consider the following problem.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{equation}
\min_x \sum_{i=1}^B f_i(x_i) \quad \text{ subject to } \quad Ax = b
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Suppose the variable \(x\) is split into \(B\) blocks, \(x = (x_1,\dots,x_B) \in \mathbb{R}^n, \text{ where } x_i \in \mathbb{R}^{n_i}\), and the matrix \(A\) is likewise split into \(B\) column blocks, \(A = [A_1, \dots, A_B], \text{ where } A_i \in \mathbb{R}^{m \times n_i}\). Then, for a fixed \(u\), the minimization over \(x\) separates into \(B\) independent problems:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
&amp;amp; \quad x^+ \in \arg\min_x \sum_{i=1}^B f_i(x_i) + u^T Ax  \\
\Longleftrightarrow &amp;amp; \quad x_i^+ \in \arg\min_{x_i} f_i(x_i) + u^T A_ix_i, \quad i=1,\dots, B
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;dual-decomposition-algorithm&quot;&gt;Dual decomposition algorithm:&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
x_i^{(k)} &amp;amp; \in \arg \min_{x_i} f_i(x_i) + (u^{(k-1)})^T A_i x_i, \quad i=1,\dots,B  \\
u^{(k)}   &amp;amp; = u^{(k-1)} + t_k \left(\sum_{i=1}^B A_i x_i^{(k)} - b \right)
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;The two steps above can be read as follows.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The first equation is the &lt;strong&gt;broadcast&lt;/strong&gt; step: the current \(u\) is sent to each of the \(B\) processors, and each processor finds its own optimal \(x_i\) in parallel.&lt;/li&gt;
  &lt;li&gt;The second equation is the &lt;strong&gt;gather&lt;/strong&gt; step: \(A_i x_i\) is collected from each processor and the global dual variable \(u\) is updated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The two steps are repeated for \(k=1,2,3,\dots\)&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter20/decomposition.png&quot; alt=&quot;[Fig 1] Broadcast and Gather&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Broadcast and Gather&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;dual-decomposition-prices-and-agents-video&quot;&gt;Dual decomposition: prices and agents (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/dual-decomposition_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Each agent solves its own small problem given a price \(\nu\), and dual ascent raises or lowers \(\nu\) according to the constraint violation \(\sum_i x_i-c\).&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-set-the-price&quot;&gt;Try it yourself: set the price&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;dd&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>20-02 Dual Decomposition</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_02_00_Dual_Decomposition/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_02_00_Dual_Decomposition</id>
   <content type="html">&lt;p&gt;When an optimization problem has millions of variables spread across hundreds of machines, departments, or sensors, the objective \(\sum_{i=1}^B f_i(x_i)\) is often naturally separable—only a handful of shared resource or consistency constraints \(Ax = b\) tie everything together. &lt;strong&gt;Dual decomposition&lt;/strong&gt; (pioneered by Everett and Dantzig–Wolfe in the 1960s) uses Lagrange multipliers as a lightweight coordination bus: every worker solves its own private subproblem in parallel, and a coordinator updates the shared dual prices from the aggregate mismatch.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-architecture-of-dual-decomposition&quot;&gt;Key ideas: The Architecture of Dual Decomposition&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Block-Separable Objective, Coupled Constraints:&lt;/strong&gt; Minimizing \(\sum_{i=1}^B f_i(x_i)\) subject to \(\sum_{i=1}^B A_i x_i = b\) (or \(\le b\)) cannot be parallelized directly in primal space because changing \(x_1\) forces \(x_2, \dots, x_B\) to adjust.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian Decoupling:&lt;/strong&gt; Moving the coupling constraint into the Lagrangian \(\sum_{i=1}^B \big(f_i(x_i) + u^T A_i x_i\big) - u^T b\) breaks the primal minimization into \(B\) completely independent subproblems for any fixed price vector \(u\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Broadcast–Gather Communication Pattern:&lt;/strong&gt; Each iteration needs only one broadcast of \(u\) from the coordinator and one gather of local contributions \(A_i x_i^{(k)}\)—protecting local privacy (workers never share \(f_i\)) and scaling horizontally across clusters.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Price-Adjustment Economics:&lt;/strong&gt; If aggregate usage \(\sum_i A_i x_i^{(k)}\) exceeds \(b\), the dual price \(u\) rises, discouraging consumption on the next round; if it falls short, \(u\) drops—automatically steering the decentralized system toward equilibrium.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-parallelizing-a-coupled-2-block-quadratic&quot;&gt;Worked example: Parallelizing a Coupled 2-Block Quadratic&lt;/h3&gt;

&lt;p&gt;Minimize \(f_1(x_1) + f_2(x_2) = (x_1 - 4)^2 + 2(x_2 - 3)^2\) subject to \(x_1 + x_2 = 4\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the independent worker subproblems given broadcast price \(u\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Worker 1: \(x_1(u) = \arg\min_{x_1} (x_1 - 4)^2 + u x_1 \implies 2(x_1 - 4) + u = 0 \implies x_1(u) = 4 - \frac{u}{2}\).&lt;/li&gt;
      &lt;li&gt;Worker 2: \(x_2(u) = \arg\min_{x_2} 2(x_2 - 3)^2 + u x_2 \implies 4(x_2 - 3) + u = 0 \implies x_2(u) = 3 - \frac{u}{4}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Run one coordinator round from \(u^0 = 0\) with step size \(t = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Workers compute in parallel: \(x_1^1 = 4, \; x_2^1 = 3\).&lt;/li&gt;
      &lt;li&gt;Coordinator gathers sum: \(4 + 3 = 7 &amp;gt; 4\) (excess demand \(+3\)!).&lt;/li&gt;
      &lt;li&gt;Coordinator raises price: \(u^1 = 0 + 1(7 - 4) = 3\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Observe Round 2 at \(u^1 = 3\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Worker 1 responds: \(x_1^2 = 4 - 1.5 = 2.5\).&lt;/li&gt;
      &lt;li&gt;Worker 2 responds: \(x_2^2 = 3 - 0.75 = 2.25\).&lt;/li&gt;
      &lt;li&gt;Aggregate mismatch dropped by \(75\%\) (from \(+3\) down to \(2.5 + 2.25 - 4 = +0.75\)), heading straight to the exact equilibrium \(u^\star = 4, \; x_1^\star = 2, \; x_2^\star = 2\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we examine techniques for decomposing problems using duality.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-01-01 Convergence Analysis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_01_01_Convergence_Analysis/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_01_01_Convergence_Analysis</id>
   <content type="html">&lt;p&gt;One of the deepest dualities in convex analysis links two seemingly unrelated geometric properties: &lt;strong&gt;curvature&lt;/strong&gt; (strong convexity) in the primal space and &lt;strong&gt;smoothness&lt;/strong&gt; (Lipschitz gradients) in the dual space! The sharper the bowl of \(f\) (parameter \(d\)), the gentler and smoother the landscape of its conjugate \(f^\ast\) (Lipschitz constant \(1/d\)). That single equivalence tells you immediately what step size \(t\) guarantees monotonic ascent for dual gradient descent—and explains why losing strong convexity makes dual ascent oscillate.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-strong-convexity-longleftrightarrow-smoothness-duality&quot;&gt;Key ideas: The Strong Convexity \(\Longleftrightarrow\) Smoothness Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel Conjugate Duality Theorem:&lt;/strong&gt; A closed convex function \(f\) is \(d\)-strongly convex &lt;em&gt;if and only if&lt;/em&gt; its conjugate \(f^\ast\) has a \((1/d)\)-Lipschitz continuous gradient: \(\|\nabla f^\ast(u) - \nabla f^\ast(v)\|_2 \le \frac{1}{d}\|u - v\|_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Smoothness Constant Under Linear Maps:&lt;/strong&gt; For \(g(u) = -f^\ast(-A^T u) - b^T u\), applying the chain rule gives \(\|\nabla g(u) - \nabla g(v)\|_2 \le \frac{\|A\|_2^2}{d}\|u - v\|_2\), so the dual objective is \(L_g\)-smooth with \(L_g = \sigma_{\max}^2(A)/d\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Safe Step Size for Dual Ascent:&lt;/strong&gt; Standard smooth gradient ascent theory immediately gives the constant step-size rule \(t \le \frac{1}{L_g} = \frac{d}{\|A\|_2^2}\), guaranteeing \(O(1/k)\) dual suboptimality (and linear convergence if \(f\) is also smooth!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;What Breaks When \(d = 0\):&lt;/strong&gt; If \(f\) is not strongly convex (\(d = 0\)), \(L_g = \infty\)—the dual has sharp ridges where constant-step dual ascent can bounce forever, directly motivating the Augmented Lagrangian in Section 20-03.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-the-exact-dual-step-size-bound&quot;&gt;Worked example: Computing the Exact Dual Step Size Bound&lt;/h3&gt;

&lt;p&gt;Consider \(\min_x f(x) = \frac{1}{2}(4x_1^2 + 2x_2^2)\) subject to \(2x_1 + x_2 = 5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find the primal strong convexity constant \(d\):&lt;/strong&gt;
\(\nabla^2 f(x) = \begin{bmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix} \implies d = \lambda_{\min}(\nabla^2 f) = 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the operator norm squared \(\|A\|_2^2\):&lt;/strong&gt;
Here \(A = [2, 1]\), so \(\|A\|_2^2 = 2^2 + 1^2 = 5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Predict the dual smoothness constant \(L_g\) from the theorem:&lt;/strong&gt;
\(L_g \le \frac{\|A\|_2^2}{d} = \frac{5}{2} = 2.5 \implies \text{guaranteed safe step size } t \le \frac{1}{L_g} = 0.4.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify directly by computing the exact dual Hessian!&lt;/strong&gt;
Minimizing \(L(x, u) = 2x_1^2 + x_2^2 + u(2x_1 + x_2 - 5)\) gives \(x_1(u) = -\frac{u}{2}\) and \(x_2(u) = -\frac{u}{2}\).
Substituting back gives \(g(u) = -\frac{3}{4}u^2 - 5u\), whose exact gradient is \(g&apos;(u) = -\frac{3}{2}u - 5\)—Lipschitz with exact constant \(L_{\text{exact}} = 1.5 \le 2.5 = \frac{\|A\|_2^2}{d}\)!
Check step size \(t = 0.4\): \(u^{k+1} = u^k + 0.4(-1.5 u^k - 5) = 0.4 u^k - 2\), which contracts the dual error by \(60\%\) at &lt;em&gt;every&lt;/em&gt; iteration!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;lipschitz-gradients-and-strong-convexity&quot;&gt;Lipschitz gradients and strong convexity&lt;/h2&gt;
&lt;p&gt;Suppose \(f\) is a closed convex function. Then the following equivalence holds.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\text{\(f\) is strongly convex with parameter \(d\) \(\Longleftrightarrow \nabla f^{\ast}\) is Lipschitz with parameter \(1/d\).} 
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;proof&quot;&gt;Proof&lt;/h3&gt;
&lt;p&gt;We prove the direction “\(\Rightarrow\)”. If \(g\) is strongly convex with parameter \(d\) and minimized at \(x\), then&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
g(y) \geq g(x) + \frac{d}{2}\lVert y-x \rVert_2^2, \text{ for all } y
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let \(x_u = \nabla f^{\ast}(u)\) be the minimizer of \(g(x) = f(x) − u^T x\), and let \(x_v = \nabla f^{\ast}(v)\) be the minimizer of \(g(x) = f(x) − v^T x\).&lt;/p&gt;

&lt;p&gt;Then the inequality above gives the following two inequalities.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
f(x_v) - u^Tx_v \geq f(x_u) - u^T x_u + \frac{d}{2} \lVert x_u - x_v \rVert_2^2 \\
f(x_u) - v^Tx_u \geq f(x_v) - v^T x_v + \frac{d}{2} \lVert x_u - x_v \rVert_2^2 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Adding the two inequalities gives&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
f(x_v) - u^Tx_v + f(x_u) - v^Tx_u \geq f(x_u) - u^T x_u +  f(x_v) - v^T x_v + d \lVert x_u - x_v \rVert_2^2.&lt;br /&gt;
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Rearranging and applying the Cauchy–Schwarz inequality, we get&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
d \lVert x_u - x_v \rVert_2^2 &amp;amp; \leq - u^Tx_v - v^Tx_u + u^T x_u + v^T x_v \\\\
&amp;amp; = (u-v)^T(x_u - x_v) \\\\
&amp;amp; \leq \lVert u-v \rVert_2 \lVert x_u - x_v \rVert_2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore&lt;/p&gt;

&lt;blockquote&gt;
\[\lVert x_u - x_v \rVert_2 \leq \frac{1}{d} \lVert u-v \rVert_2\]
&lt;/blockquote&gt;

&lt;p&gt;which shows that \(\nabla f^{\ast}\) is Lipschitz with parameter \(1/d\).&lt;/p&gt;

&lt;h2 id=&quot;convergence-guarantees&quot;&gt;Convergence guarantees&lt;/h2&gt;
&lt;p&gt;Combining this result with the analysis of gradient descent, we obtain the following convergence guarantees for the dual objective.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If \(f\) is strongly convex with parameter \(d\), then dual gradient ascent with step sizes \(t_k=d\) (\(k=1,2,3, \dots\)) converges at the rate \(O(1/\epsilon)\).&lt;/li&gt;
  &lt;li&gt;If \(f\) is strongly convex with parameter \(d\) and \(\nabla f\) is Lipschitz with parameter \(L\), then dual gradient ascent with step sizes \(t_k=2/(1/d + 1/L)\) (\(k=1,2,3, \dots\)) converges at the rate \(O(\log(1/\epsilon))\) (linear convergence).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(These step sizes assume \(\lVert A \rVert_2 \le 1\); in general the dual gradient is Lipschitz with constant \(\lVert A \rVert_2^2 / d\), so the step sizes should be scaled by \(1/\lVert A \rVert_2^2\).)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20-01 Dual (sub)gradient methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_01_00_Dual_(sub)gradient_methods/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_01_00_Dual_(sub)gradient_methods</id>
   <content type="html">&lt;p&gt;You might worry that dual optimization is only useful when you can compute the Fenchel conjugate \(f^\ast(y)\) in closed form. Remarkably, &lt;strong&gt;Danskin’s theorem&lt;/strong&gt; frees you from ever writing down \(f^\ast\) explicitly: to find a subgradient (or exact gradient) of the dual function \(g(u) = -f^\ast(-A^T u) - b^T u\), you just minimize the Lagrangian over \(x\) once and plug the minimizer \(x^+(u)\) straight into the residual \(A x^+(u) - b\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-computing-dual-gradients-without-closed-form-conjugates&quot;&gt;Key ideas: Computing Dual Gradients Without Closed-Form Conjugates&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian–Conjugate Identity:&lt;/strong&gt; The dual objective \(g(u) = \inf_x \{f(x) + u^T(Ax - b)\} = -f^\ast(-A^T u) - b^T u\) expresses dual maximization directly in terms of the convex conjugate \(f^\ast\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Danskin’s Subgradient Formula:&lt;/strong&gt; Any primal minimizer \(x^{(k)} \in \arg\min_x \{f(x) + (u^{(k-1)})^T A x\}\) belongs to \(\partial f^\ast(-A^T u^{(k-1)})\), which immediately gives \(A x^{(k)} - b \in \partial g(u^{(k-1)})\)—no closed-form differentiation of \(f^\ast\) needed!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Differentiability vs. Subgradients:&lt;/strong&gt; If \(f\) is &lt;em&gt;strictly&lt;/em&gt; convex, the minimizer \(x^{(k)}\) is unique and \(g(u)\) is continuously differentiable (dual gradient ascent); if \(f\) is merely convex (e.g., an LP or \(\ell_1\) norm), \(x^{(k)}\) may be non-unique and we get a dual &lt;em&gt;subgradient&lt;/em&gt; method requiring diminishing step sizes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal Recovery Warning:&lt;/strong&gt; Even when \(g(u^{(k)}) \to g^\star\), the raw primal iterates \(x^{(k)}\) need not converge to \(x^\star\) unless \(f\) is strictly convex; for general convex \(f\), averaging the primal iterates (or adding an augmented Lagrangian penalty) is needed to recover feasibility.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-dual-gradient-ascent-without-writing-fast&quot;&gt;Worked example: Dual Gradient Ascent Without Writing \(f^\ast\)&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = e^{x_1} + e^{x_2}\) subject to \(x_1 + x_2 = 2\) (exact optimum by symmetry: \(x_1^\star = x_2^\star = 1\), \(f^\star = 2e\), \(u^\star = -e \approx -2.7183\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the primal Lagrangian minimization for a given \(u &amp;lt; 0\):&lt;/strong&gt;
\(\min_{x_1, x_2} \; e^{x_1} + e^{x_2} + u(x_1 + x_2 - 2) \implies e^{x_i} = -u \implies x_1(u) = x_2(u) = \ln(-u).\)
Notice we never even formed the entropy conjugate \(f^\ast(y) = y\ln y - y\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the dual gradient at \(u^0 = -1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal minimizer: \(x^{(1)} = (\ln 1, \ln 1)^T = (0, 0)^T\).&lt;/li&gt;
      &lt;li&gt;Dual gradient: \(\nabla g(-1) = A x^{(1)} - b = (0 + 0) - 2 = -2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update \(u\) with step size \(t = 0.5\):&lt;/strong&gt;
\(u^1 = u^0 + 0.5(-2) = -1 - 1 = -2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check Iteration 2 at \(u^1 = -2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal minimizer: \(x^{(2)} = (\ln 2, \ln 2)^T \approx (0.6931, 0.6931)^T\).&lt;/li&gt;
      &lt;li&gt;Dual residual shrank from \(-2.0\) to \(2\ln 2 - 2 \approx -0.6137\), and \(u^2 = -2 + 0.5(-0.6137) \approx -2.3069\), climbing smoothly toward \(u^\star = -e \approx -2.7183\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Even when the dual (conjugate) cannot be found in closed form, we can still use a dual-based subgradient or gradient method.&lt;/p&gt;

&lt;p&gt;For example, consider the following problem.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_x f(x) \text{ subject to } Ax = b
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The dual of this problem is as follows, where \(f^{\ast}\) is the conjugate of \(f\).&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\max_u -f^{\ast}(-A^T u) - b^T u
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Define \(g(u) = -f^{\ast}(-A^Tu)-b^Tu\). Then a subgradient of \(g(u)\) is&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\partial g(u) = A \partial f^{\ast}(-A^Tu) - b
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Writing the element of \(\partial f^{\ast}(-A^Tu)\) as \(x\), this can be expressed as&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\partial g(u) = Ax-b \quad \text{where} \quad x \in \arg\min_z f(z) + u^T A z
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;dual-subgradient-method&quot;&gt;Dual subgradient method&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;dual subgradient method&lt;/strong&gt; maximizes the dual objective. Starting from \(u^{(0)}\), it repeats the following steps for \(k=1,2,3,\dots\)&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; \in \arg \min_x f(x) + ({u^{(k-1)}})^T A x  \\
u^{(k)} &amp;amp; = u^{(k-1)} + t_k (A x^{(k)} - b) 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Here the step sizes \(t_k\) (\(k=1,2,3,\dots\)) are chosen in the standard way.&lt;/p&gt;

&lt;h4 id=&quot;the-strictly-convex-case&quot;&gt;The strictly convex case&lt;/h4&gt;
&lt;p&gt;If \(f\) is strictly convex, then \(f^{\ast}\) is differentiable.&lt;/p&gt;

&lt;p&gt;The algorithm then becomes &lt;strong&gt;dual gradient ascent&lt;/strong&gt;, which repeats the following steps for \(k=1,2,3,\dots\)&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{alignat}{1}
x^{(k)} &amp;amp; = \arg \min_x f(x) + ({u^{(k-1)}})^T A x  \\
u^{(k)} &amp;amp; = u^{(k-1)} + t_k (A x^{(k)}-b) 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;The difference from the previous version is that \(x^{(k)}\) is unique. (Note that the relation with \(\text{argmin}\) is now “\(=\)” instead of “\(\in\)”.)&lt;/p&gt;

&lt;p&gt;Again the step sizes \(t_k\) (\(k=1,2,3,\dots\)) are chosen in the standard way, and when computing the \(\text{argmin}\) we can apply proximal gradient or acceleration as usual.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>20 Dual Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_00_Dual_Methods/"/>
   <updated>2021-03-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter20/20_00_Dual_Methods</id>
   <content type="html">&lt;p&gt;Imagine coordinating a thousand power generators across a continent to meet a single shared electricity demand \(\sum_{i=1}^{1000} x_i = b\). Solving the coupled primal problem in one central computer requires gathering every plant’s private cost curve \(f_i(x_i)\) into one giant matrix. &lt;strong&gt;Dual methods&lt;/strong&gt; flip the script using the timeless logic of economics: broadcast a single &lt;strong&gt;price&lt;/strong&gt; \(u\) for the shared constraint, let every generator optimize its own cost independently in parallel, and then nudge the price up or down based on whether total supply fell short or overshot \(b\). This chapter traces that idea from raw dual ascent all the way to the &lt;strong&gt;Augmented Lagrangian&lt;/strong&gt; and &lt;strong&gt;ADMM&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-ladder-of-dual-optimization-methods&quot;&gt;Key ideas: The Ladder of Dual Optimization Methods&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dual Ascent &amp;amp; Conjugate Smoothness:&lt;/strong&gt; Converting \(\min f(x) \text{ s.t. } Ax = b\) into \(\max_u -f^\ast(-A^T u) - b^T u\) turns hard equality constraints into an unconstrained dual problem whose gradient is simply the constraint residual \(A x(u) - b\) (whenever \(f\) is strictly convex).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Decomposition (Parallel Pricing):&lt;/strong&gt; When \(f(x) = \sum_{i=1}^B f_i(x_i)\) is separable across blocks, fixing the dual price \(u\) completely decouples the primal minimization into \(B\) independent subproblems—enabling distributed optimization across servers or agents.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Augmented Lagrangian (Method of Multipliers):&lt;/strong&gt; Plain dual ascent demands strong convexity of \(f\) and careful step sizes to converge. Adding the quadratic penalty \(\frac{\rho}{2}\|Ax - b\|_2^2\) smooths the dual dramatically and guarantees convergence under far weaker assumptions—at the cost of coupling the blocks together.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ADMM (Best of Both Worlds):&lt;/strong&gt; Alternating minimization over \(x\) and \(z\) in an augmented Lagrangian restores block separability while keeping the robust convergence guarantees of the method of multipliers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-pricing-a-2-agent-resource-split-via-dual-ascent&quot;&gt;Worked example: Pricing a 2-Agent Resource Split via Dual Ascent&lt;/h3&gt;

&lt;p&gt;Minimize \(\frac{1}{2}x_1^2 + \frac{1}{2}(2x_2^2)\) subject to \(x_1 + x_2 = 3\) (exact optimum: \(x_1^\star = 2, x_2^\star = 1, u^\star = -2\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the Lagrangian and decouple the primal minimizers for any price \(u\):&lt;/strong&gt;
\(L(x_1, x_2, u) = \left(\tfrac{1}{2}x_1^2 + u x_1\right) + \left(x_2^2 + u x_2\right) - 3u.\)
Minimizing independently gives \(x_1(u) = -u\) and \(x_2(u) = -\frac{u}{2}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take one dual ascent step from \(u^0 = 0\) with step size \(t = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal response at \(u^0 = 0\): \(x_1^1 = 0, \; x_2^1 = 0\).&lt;/li&gt;
      &lt;li&gt;Constraint residual: \(r^1 = x_1^1 + x_2^1 - 3 = -3\) (shortfall of 3 units!).&lt;/li&gt;
      &lt;li&gt;Price update: \(u^1 = u^0 + t(r^1) = 0 + 1(-3) = -3\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check Iteration 2 at \(u^1 = -3\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal response: \(x_1^2 = 3, \; x_2^2 = 1.5\) (total supply \(4.5\), surplus of \(+1.5\)!).&lt;/li&gt;
      &lt;li&gt;Price update: \(u^2 = -3 + 1(1.5) = -1.5\).
Notice \(u^k\) oscillates straight into \(u^\star = -2\) (errors \(-2 \to +1 \to -0.5 \to +0.25 \dots\), halving every step!), and the agents &lt;em&gt;never once shared their cost functions with each other&lt;/em&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter we study ways of solving problems using the dual: the dual subgradient method, the dual decomposition method, and the augmented Lagrangian method, and we take a brief look at the idea of the Alternating Direction Method of Multipliers (ADMM).&lt;/p&gt;

&lt;p&gt;First, let us briefly review two topics from earlier chapters: the proximal Newton method and conjugate functions.&lt;/p&gt;

&lt;h2 id=&quot;review-proximal-newton-method&quot;&gt;Review: proximal Newton method&lt;/h2&gt;
&lt;p&gt;Consider the problem&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
\min_x g(x) + h(x)
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here \(g\) and \(h\) are convex, \(g\) is twice differentiable, and \(h\) is simple.&lt;/p&gt;

&lt;p&gt;The proximal Newton method starts from an initial point \(x^{(0)} \in \mathbb{R}^n\). First, we find a direction that is good for both \(g\) and \(h\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{alignat}{1}
v^{(k)} &amp;amp; = \arg \min_v \nabla g({x^{(k-1)}})^T v +  \frac{1}{2} v^T \nabla^2 g(x^{(k-1)}) v + h(x^{(k-1)} + v) 
\end{alignat}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then we update the next iterate along this direction:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
x^{(k)} = x^{(k-1)} + t_k v^{(k)}, \quad k=1,2,3,\dots 
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here \(t_k\) is the step size, determined by backtracking.&lt;/p&gt;

&lt;p&gt;These two steps are repeated.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;Each iteration is very expensive (computing \(v^{(k)}\) is generally very hard).&lt;/li&gt;
    &lt;li&gt;However, under suitable conditions, very few iterations are needed to converge, and the method has a local quadratic convergence rate.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;review-conjugate-function&quot;&gt;Review: conjugate function&lt;/h2&gt;
&lt;p&gt;For \(f: \mathbb{R}^n \to \mathbb{R}\), the conjugate function is defined as&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
f^*(y) = \max_x y^Tx - f(x)
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(1) The conjugate can be written as follows, which is a form that frequently appears in dual problems.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
-f^{\ast}(y) = \min_x f(x) - y^Tx
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(2) If \(f\) is closed and convex, then \(f^{**} = f\). Moreover,&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{equation}
x \in \partial f^{\ast}(y) \Longleftrightarrow y \in \partial f(x) \Longleftrightarrow x \in \arg\min_z f(z) - y^Tz
\end{equation}&lt;/p&gt;
  &lt;h4 id=&quot;proof&quot;&gt;Proof&lt;/h4&gt;
  &lt;p&gt;First we prove \(x \in \partial f^{\ast}(y) \Longleftrightarrow y \in \partial f(x)\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;step-1-y-in-partial-fx-longrightarrow-x-in-partial-fasty&quot;&gt;Step 1: \(y \in \partial f(x) \Longrightarrow x \in \partial f^{\ast}(y)\)&lt;/h4&gt;
&lt;blockquote&gt;

  &lt;p&gt;Assume \(y \in \partial f(x)\). Then \(x\) belongs to the set \(M_y\) of maximizers of \(z \mapsto y^Tz - f(z)\), i.e. \(x \in M_y\). &lt;br /&gt; Hence \(f^{\ast}(y) = y^Tx - f(x)\), and for every \(w\) we have \(f^{\ast}(w) \ge w^Tx - f(x) = f^{\ast}(y) + x^T(w - y)\). This says exactly that \(x \in \partial f^{\ast}(y)\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;step-2-x-in-partial-fasty-longrightarrow-y-in-partial-fx&quot;&gt;Step 2: \(x \in \partial f^{\ast}(y) \Longrightarrow y \in \partial f(x)\)&lt;/h4&gt;
&lt;blockquote&gt;

  &lt;p&gt;By Step 1 applied to \(f^{\ast}\), if \(x \in  \partial f^{\ast}(y)\) then \(y \in \partial f^{\ast\ast}(x)\). Since \(f^{\ast\ast}=f\), we get \(y \in \partial f(x)\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Steps 1 and 2 prove \(x \in \partial f^{\ast}(y) \Longleftrightarrow y \in \partial f(x)\).&lt;/p&gt;
&lt;h4 id=&quot;step-3-x-in-partial-fasty-longleftrightarrow-y-in-partial-fx-longleftrightarrow-x-in-argmin_z-fz---ytz&quot;&gt;Step 3: \(x \in \partial f^{\ast}(y) \Longleftrightarrow y \in \partial f(x) \Longleftrightarrow x \in \arg\min_z f(z) - y^Tz\)&lt;/h4&gt;
&lt;blockquote&gt;

  &lt;p&gt;Finally, \(y \in \partial f(x) \Longleftrightarrow x \in \arg\min_z f(z) - y^Tz\) follows directly from the definition of the subgradient. &lt;br /&gt;
Together with the above, this proves \(x \in \partial f^{\ast}(y) \Longleftrightarrow y \in \partial f(x) \Longleftrightarrow x \in \arg\min_z f(z) - y^Tz\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(3) If \(f\) is strictly convex, then&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{equation}
\nabla f^{\ast}(y) = \arg\min_z f(z) - y^T z
\end{equation}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;proof-1&quot;&gt;Proof&lt;/h4&gt;

&lt;blockquote&gt;
  &lt;p&gt;If \(f\) is strictly convex, \(f(z)-y^Tz\) has a unique minimizer \(z\),
and by the proof of (2) above, this minimizer must be \(\nabla f^{\ast}(y)\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, if \(f\) is strictly convex, then the subdifferential of \(f^{\ast}\) consists of a single element, which is the gradient. Hence \(f^{\ast}\) is a differentiable function.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14 Phương pháp Newton</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_newton_method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_newton_method</id>
   <content type="html">&lt;p&gt;Nếu Gradient Descent giống như một người leo núi bịt mắt chỉ biết sờ độ dốc ngay dưới chân rồi bước từng bước ngắn xuống thung lũng, thì &lt;strong&gt;Phương pháp Newton&lt;/strong&gt; lại mang trên mình một chiếc kính nhìn thấy trọn vẹn &lt;strong&gt;độ cong&lt;/strong&gt; của địa hình xung quanh. Trong một hẻm núi dài và hẹp (bài toán có số điều kiện lớn), Gradient Descent có thể mất hàng nghìn bước chạy zích-zắc mệt mỏi, còn phương pháp Newton chỉ cần 5 đến 10 bước để lao thẳng tới đáy với độ chính xác máy tính \(10^{-12}\).&lt;/p&gt;

&lt;p&gt;Chương 14 đưa bạn bước vào thế giới của &lt;strong&gt;tối ưu hóa bậc hai&lt;/strong&gt;: từ công thức cập nhật Newton kinh điển, tính bất biến affine kỳ diệu, đại lượng giảm Newton, tìm kiếm đường backtracking, lý thuyết hàm tự hài hòa của Nesterov–Nemirovskii, cho tới các phương pháp Quasi-Newton (BFGS/L-BFGS) và những biến thể bậc hai đang huấn luyện các mô hình AI ngày nay.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tối-ưu-hóa-bậc-hai&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tối ưu hóa bậc hai&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ Taylor bậc hai và ma trận Hessian:&lt;/strong&gt; Thay vì xấp xỉ hàm mục tiêu bằng mặt phẳng tiếp xúc (bậc nhất), phương pháp Newton khớp một mặt paraboloid \(\tilde{f}(y) = f(x) + \nabla f(x)^T(y-x) + \frac{1}{2}(y-x)^T \nabla^2 f(x)(y-x)\) rồi nhảy thẳng tới đáy của paraboloid đó.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bất biến affine và hình học độ cong:&lt;/strong&gt; Phép nhân với nghịch đảo Hessian \((\nabla^2 f(x))^{-1}\) tự động “làm tròn” các đường đồng mức méo mó thành hình cầu, khiến phương pháp Newton miễn nhiễm với việc đổi đơn vị đo hay kéo giãn trục tọa độ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai pha hội tụ (giảm chấn và bậc hai):&lt;/strong&gt; Khi còn xa đáy, backtracking line search giữ bước đi an toàn (pha giảm chấn); khi đã lọt vào vùng lân cận nghiệm, bước Newton thuần túy kích hoạt &lt;strong&gt;hội tụ bậc hai&lt;/strong&gt; — số chữ số đúng tăng gấp đôi sau mỗi vòng lặp!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí đại số tuyến tính và xấp xỉ bậc hai:&lt;/strong&gt; Mỗi bước Newton đòi hỏi giải hệ tuyến tính cỡ \(n \times n\) (tốn \(O(n^3)\) với ma trận đặc), là động lực ra đời của các phương pháp khai thác cấu trúc thưa, Quasi-Newton (BFGS, L-BFGS) và xấp xỉ Hessian đường chéo/khối trong học sâu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-1-bước-newton-với-gradient-descent-trên-thung-lũng-méo&quot;&gt;Giải thích: So sánh 1 bước Newton với Gradient Descent trên thung lũng méo&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai 2 chiều có số điều kiện \(\kappa = 100\):&lt;/p&gt;

\[f(x_1, x_2) = \frac{1}{2}x_1^2 + 50x_2^2,\]

&lt;p&gt;nghiệm tối ưu là \(x^\star = (0, 0)^T\). Xuất phát từ \(x^{(0)} = (10, 1)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính gradient và ma trận Hessian tại \(x^{(0)} = (10, 1)^T\):&lt;/strong&gt;
\(\nabla f(x^{(0)}) = \begin{bmatrix} x_1 \\ 100 x_2 \end{bmatrix} = \begin{bmatrix} 10 \\ 100 \end{bmatrix}, \qquad \nabla^2 f(x^{(0)}) = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 100 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước Gradient Descent (với bước học an toàn lớn nhất \(t = \frac{1}{L} = \frac{1}{100} = 0.01\)):&lt;/strong&gt;
\(x^{(1)}_{\text{GD}} = \begin{bmatrix} 10 \\ 1 \end{bmatrix} - 0.01 \begin{bmatrix} 10 \\ 100 \end{bmatrix} = \begin{bmatrix} 9.9 \\ 0 \end{bmatrix}.\)
Tọa độ \(x_2\) về \(0\) ngay, nhưng \(x_1\) mới nhích từ \(10\) xuống \(9.9\) — mất hàng trăm vòng lặp nữa mới tiến gần \(0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước Newton thuần túy:&lt;/strong&gt;
\(x^{(1)}_{\text{Newton}} = x^{(0)} - (\nabla^2 f(x^{(0)}))^{-1}\nabla f(x^{(0)}) = \begin{bmatrix} 10 \\ 1 \end{bmatrix} - \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1/100 \end{bmatrix}\begin{bmatrix} 10 \\ 100 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}.\)
Chỉ sau &lt;strong&gt;đúng 1 bước&lt;/strong&gt;, phương pháp Newton hạ cánh chính xác tại nghiệm tối ưu \((0, 0)^T\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong chương này, chúng ta sẽ tìm hiểu về phương pháp Newton.&lt;/p&gt;

&lt;p&gt;Phương pháp Newton là thuật toán tìm giá trị nhỏ nhất của hàm khả vi hai lần dựa trên khai triển Taylor bậc hai. Tại mỗi vòng lặp, phương pháp xấp xỉ hàm mục tiêu bằng một hàm bậc hai và cập nhật nghiệm theo điểm cực tiểu của hàm xấp xỉ đó. Trong vùng lân cận điểm tối ưu, phương pháp đạt tốc độ hội tụ bậc hai, nhanh hơn đáng kể so với phương pháp gradient descent.&lt;/p&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo-và-đọc-thêm&quot;&gt;Tài liệu tham khảo và đọc thêm&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;S. Boyd and L. Vandenberghe (2004), “Convex optimization”, Chapter 9 and 10&lt;/li&gt;
  &lt;li&gt;Y. Nesterov (1998), “Introductory lectures on convex optimization: a basic course”, Chapter 2&lt;/li&gt;
  &lt;li&gt;Y. Nesterov and A. Nemirovskii (1994), “Interior-point polynomial methods in convex programming”, Chapter 2&lt;/li&gt;
  &lt;li&gt;J. Nocedal and S. Wright (2006), “Numerical optimization”, Chapters 6 and 7&lt;/li&gt;
  &lt;li&gt;L. Vandenberghe, Lecture notes for EE 236C, UCLA, Spring 2011-2012&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>14-12 Bài Tập Thực Hành - Phương Pháp Newton</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_12_Practical_Exercises_Newton_Method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_12_Practical_Exercises_Newton_Method</id>
   <content type="html">&lt;p&gt;Tối ưu hóa bậc hai là môn học mà cảm giác toán học chỉ thực sự chín muồi khi bạn tự tay tính một ma trận Hessian cho hồi quy logistic, tự giải một hệ tuyến tính bước Newton, kiểm chứng điều kiện Armijo bằng số, và chứng minh tốc độ hội tụ bậc hai. Khi tự làm những phép tính đó, bạn sẽ thấy ngay tại sao ma trận Hessian của hồi quy logistic lại có dạng \(X^T W X\) đẹp đẽ đến thế, và vì sao một bước Newton có thể thu nhỏ sai số theo cấp số mũ kép.&lt;/p&gt;

&lt;p&gt;Bộ bài tập thực hành dưới đây tuyển chọn các bài toán chuẩn mực từ Boyd &amp;amp; Vandenberghe, Nocedal &amp;amp; Wright và Bertsekas. Trước khi giải từng phần, hãy xem qua bản đồ kỹ năng và một bài mẫu tính nhanh Hessian–Newton cho hồi quy logistic.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-kỹ-năng-tự-luận-cốt-lõi-trong-bài-tập-chương-14&quot;&gt;Kiến thức cần nhớ: Bốn kỹ năng tự luận cốt lõi trong bài tập Chương 14&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính gradient và Hessian dạng ma trận:&lt;/strong&gt; Sử dụng quy tắc dây chuyền ma trận (ví dụ với \(f(x) = \sum \phi_i(a_i^T x)\), ta có \(\nabla f(x) = A^T \phi&apos;(Ax)\) và \(\nabla^2 f(x) = A^T \operatorname{diag}(\phi&apos;&apos;(Ax)) A\)) để tránh tính nhầm từng phần tử.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh tính chất đại số tuyến tính của bước Newton:&lt;/strong&gt; Luôn dùng dạng toàn phương \(v^T H v\) để kiểm tra hướng giảm (\(-\lambda(x)^2 &amp;lt; 0\)), tính bất biến affine và giải hệ khối KKT cho bài toán có ràng buộc đẳng thức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện Armijo và đếm bước hội tụ:&lt;/strong&gt; Thay trực tiếp công thức \(f(x + tv) \le f(x) - \alpha t \lambda(x)^2\) với \(t = 1, \beta, \beta^2, \dots\) và phân tích riêng hai pha giảm chấn – thuần túy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng hàm tự hài hòa và cập nhật Quasi-Newton:&lt;/strong&gt; Dùng định nghĩa lát cắt 1D \(g(t) = f(x + tv)\) cho tự hài hòa, và kiểm tra phương trình cát tuyến \(B_{k+1} s_k = y_k\) cùng điều kiện độ cong \(s_k^T y_k &amp;gt; 0\) cho BFGS.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bài-mẫu-tính-bước-newton-cho-hàm-mất-mát-logistic-1-chiều&quot;&gt;Giải thích: Bài mẫu tính bước Newton cho hàm mất mát logistic 1 chiều&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán mẫu:&lt;/strong&gt; Xét hàm mục tiêu hồi quy logistic 1 biến có điều chuẩn:
\(f(w) = \log(1 + e^{-w}) + \frac{1}{2}w^2.\)
Hãy tính gradient, Hessian, Newton decrement và điểm cập nhật Newton đầu tiên xuất phát từ \(w^{(0)} = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính đạo hàm bậc nhất và bậc hai (dùng hàm sigmoid \(\sigma(z) = \frac{1}{1 + e^{-z}}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(w) = \frac{-e^{-w}}{1 + e^{-w}} + w = -\sigma(-w) + w\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;(w) = \sigma(w)\bigl(1 - \sigma(w)\bigr) + 1 &amp;gt; 1\) (hàm lồi mạnh với \(m = 1\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh giá tại \(w^{(0)} = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vì \(\sigma(0) = 0.5\):
\(f&apos;(0) = -0.5 + 0 = -0.5, \qquad f&apos;&apos;(0) = (0.5)(0.5) + 1 = 1.25.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bước Newton và Newton decrement:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bước Newton: \(v = -\frac{f&apos;(0)}{f&apos;&apos;(0)} = -\frac{-0.5}{1.25} = +0.4\).&lt;/li&gt;
      &lt;li&gt;Điểm mới: \(w^{(1)} = 0 + 0.4 = 0.4\).&lt;/li&gt;
      &lt;li&gt;Newton decrement: \(\lambda(0) = \sqrt{\frac{(-0.5)^2}{1.25}} = \sqrt{0.2} \approx 0.4472\), và ước lượng khoảng cách tới đáy là \(\frac{1}{2}\lambda(0)^2 = 0.1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra độ chính xác sau đúng 1 bước:&lt;/strong&gt; Tại \(w^{(1)} = 0.4\), \(f&apos;(0.4) = -\frac{1}{1+e^{0.4}} + 0.4 \approx -0.4013 + 0.4 = -0.0013\)! Chỉ sau &lt;strong&gt;1 bước duy nhất&lt;/strong&gt;, đạo hàm đã tụt từ \(-0.5\) xuống \(-0.0013\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---phương-pháp-newton&quot;&gt;Bài Tập Thực Hành - Phương Pháp Newton&lt;/h1&gt;

&lt;p&gt;Các bài tập dưới đây được tham khảo từ Boyd &amp;amp; Vandenberghe (2004), Nocedal &amp;amp; Wright (2006) và Bertsekas (1999).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-i-phương-pháp-newton-cơ-bản&quot;&gt;&lt;strong&gt;Phần I: Phương pháp Newton cơ bản&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-tính-bước-newton-boyd--vandenberghe-ex-91&quot;&gt;&lt;strong&gt;Bài tập 1: Tính bước Newton (Boyd &amp;amp; Vandenberghe, Ex. 9.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho hàm mục tiêu:&lt;/p&gt;

\[f(x) = \frac{1}{2}x^T Q x + c^T x\]

&lt;p&gt;với \(Q \succ 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tính gradient \(\nabla f(x)\) và ma trận Hessian \(\nabla^2 f(x)\).&lt;br /&gt;
b) Tại \(x = (1, 2)^T\), tính bước Newton \(\Delta x_{nt}\).&lt;br /&gt;
c) Tính đại lượng giảm Newton (Newton decrement) \(\lambda(x) = \sqrt{\nabla f(x)^T (\nabla^2 f(x))^{-1} \nabla f(x)}\).&lt;br /&gt;
d) Với \(Q = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}\) và \(c = \begin{bmatrix} -1 \\ -1 \end{bmatrix}\), tính tất cả các giá trị trên.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Gradient và Hessian:&lt;/strong&gt;&lt;/p&gt;

\[\nabla f(x) = Qx + c\]

\[\nabla^2 f(x) = Q\]

  &lt;p&gt;(Ma trận Hessian là hằng số vì \(f\) là hàm bậc hai.)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Bước Newton:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Theo định nghĩa:&lt;/p&gt;

\[\Delta x_{nt} = -(\nabla^2 f(x))^{-1} \nabla f(x) = -Q^{-1}(Qx + c)\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Đại lượng giảm Newton:&lt;/strong&gt;&lt;/p&gt;

\[\lambda(x) = \sqrt{\nabla f(x)^T (\nabla^2 f(x))^{-1} \nabla f(x)}\]

\[= \sqrt{(Qx+c)^T Q^{-1} (Qx+c)}\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;d) Tính toán cụ thể:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Dữ liệu:&lt;/p&gt;

\[Q = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}, \quad
c = \begin{bmatrix} -1 \\ -1 \end{bmatrix}, \quad
x = \begin{bmatrix} 1 \\ 2 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Tính \(Q^{-1}\):&lt;/strong&gt;&lt;/p&gt;

\[\det(Q) = 2 \times 2 - 1 \times 1 = 3\]

\[Q^{-1} = \frac{1}{3}\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Gradient tại \(x\):&lt;/strong&gt;&lt;/p&gt;

\[\nabla f(x) = Qx + c = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix} \begin{bmatrix} 1 \\ 2 \end{bmatrix} + \begin{bmatrix} -1 \\ -1 \end{bmatrix}\]

\[= \begin{bmatrix} 4 \\ 5 \end{bmatrix} + \begin{bmatrix} -1 \\ -1 \end{bmatrix} = \begin{bmatrix} 3 \\ 4 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Bước Newton:&lt;/strong&gt;&lt;/p&gt;

\[\Delta x_{nt} = -Q^{-1} \nabla f(x) = -\frac{1}{3}\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix} \begin{bmatrix} 3 \\ 4 \end{bmatrix}\]

\[= -\frac{1}{3}\begin{bmatrix} 6-4 \\ -3+8 \end{bmatrix} = -\frac{1}{3}\begin{bmatrix} 2 \\ 5 \end{bmatrix} = \begin{bmatrix} -2/3 \\ -5/3 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Đại lượng giảm Newton:&lt;/strong&gt;&lt;/p&gt;

\[\lambda^2(x) = \nabla f(x)^T Q^{-1} \nabla f(x)\]

\[= \begin{bmatrix} 3 &amp;amp; 4 \end{bmatrix} \frac{1}{3}\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix} \begin{bmatrix} 3 \\ 4 \end{bmatrix}\]

\[= \frac{1}{3}\begin{bmatrix} 3 &amp;amp; 4 \end{bmatrix} \begin{bmatrix} 2 \\ 5 \end{bmatrix} = \frac{1}{3}(6 + 20) = \frac{26}{3}\]

\[\lambda(x) = \sqrt{\frac{26}{3}} \approx 2.944\]

  &lt;p&gt;&lt;strong&gt;Nghiệm tối ưu:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Vì \(f\) là hàm bậc hai, phương pháp Newton hội tụ ngay trong 1 bước:&lt;/p&gt;

\[x^+ = x + \Delta x_{nt} = \begin{bmatrix} 1 \\ 2 \end{bmatrix} + \begin{bmatrix} -2/3 \\ -5/3 \end{bmatrix} = \begin{bmatrix} 1/3 \\ 1/3 \end{bmatrix}\]

  &lt;p&gt;Kiểm tra trực tiếp từ \(\nabla f(x^*) = Q x^* + c = 0 \Rightarrow x^* = -Q^{-1}c\):&lt;/p&gt;

\[x^* = -\frac{1}{3}\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix} \begin{bmatrix} -1 \\ -1 \end{bmatrix} = -\frac{1}{3}\begin{bmatrix} -1 \\ -1 \end{bmatrix} = \begin{bmatrix} 1/3 \\ 1/3 \end{bmatrix}\]

  &lt;p&gt;Kết quả trùng khớp.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-2-phương-pháp-newton-cho-hồi-quy-logistic-nocedal--wright-ex-81&quot;&gt;&lt;strong&gt;Bài tập 2: Phương pháp Newton cho hồi quy logistic (Nocedal &amp;amp; Wright, Ex. 8.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét bài toán hồi quy logistic:&lt;/p&gt;

\[\min_x \sum_{i=1}^m \log(1 + e^{-y_i (a_i^T x)})\]

&lt;p&gt;với tập dữ liệu \((a_i, y_i)\) trong đó \(y_i \in \{-1, +1\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tính gradient \(\nabla f(x)\).&lt;br /&gt;
b) Tính ma trận Hessian \(\nabla^2 f(x)\).&lt;br /&gt;
c) Chứng minh \(\nabla^2 f(x) \succeq 0\) (hàm lồi).&lt;br /&gt;
d) Với dữ liệu \(m=3\), \(n=2\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(a_1 = (1, 1)^T\), \(y_1 = +1\)&lt;/li&gt;
  &lt;li&gt;\(a_2 = (1, -1)^T\), \(y_2 = +1\)&lt;/li&gt;
  &lt;li&gt;\(a_3 = (-1, 0)^T\), \(y_3 = -1\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tính bước Newton tại \(x = (0, 0)^T\).&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Gradient:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Đặt \(\phi(z) = \log(1 + e^{-z})\), khi đó:&lt;/p&gt;

\[f(x) = \sum_{i=1}^m \phi(y_i a_i^T x)\]

\[\phi&apos;(z) = \frac{-e^{-z}}{1 + e^{-z}} = -\frac{1}{1 + e^z}\]

\[\nabla f(x) = \sum_{i=1}^m \phi&apos;(y_i a_i^T x) \cdot y_i a_i = -\sum_{i=1}^m \frac{y_i a_i}{1 + e^{y_i a_i^T x}}\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Hessian:&lt;/strong&gt;&lt;/p&gt;

\[\phi&apos;&apos;(z) = \frac{e^z}{(1 + e^z)^2}\]

\[\nabla^2 f(x) = \sum_{i=1}^m \phi&apos;&apos;(y_i a_i^T x) \cdot y_i^2 a_i a_i^T = \sum_{i=1}^m \frac{a_i a_i^T}{(1 + e^{y_i a_i^T x})^2} \cdot e^{y_i a_i^T x}\]

  &lt;p&gt;Rút gọn (do \(y_i^2 = 1\)):&lt;/p&gt;

\[\nabla^2 f(x) = \sum_{i=1}^m w_i a_i a_i^T\]

  &lt;p&gt;với \(w_i = \frac{e^{y_i a_i^T x}}{(1 + e^{y_i a_i^T x})^2} &amp;gt; 0\).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Chứng minh tính lồi:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Ta có \(\nabla^2 f(x) = \sum_{i=1}^m w_i a_i a_i^T\) với \(w_i &amp;gt; 0\). Với mọi \(v \in \mathbb{R}^n\):&lt;/p&gt;

\[v^T (\nabla^2 f(x)) v = \sum_{i=1}^m w_i (a_i^T v)^2 \geq 0\]

  &lt;p&gt;Suy ra \(\nabla^2 f(x) \succeq 0\), nên \(f\) là hàm lồi.&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;d) Tính toán tại \(x = (0,0)^T\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Gradient:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Tại \(x = 0\), ta có \(a_i^T x = 0\) với mọi \(i\):&lt;/p&gt;

\[\nabla f(0) = -\sum_{i=1}^3 \frac{y_i a_i}{1 + e^0} = -\frac{1}{2}\sum_{i=1}^3 y_i a_i\]

\[= -\frac{1}{2}\left( (+1)\begin{bmatrix} 1 \\ 1 \end{bmatrix} + (+1)\begin{bmatrix} 1 \\ -1 \end{bmatrix} + (-1)\begin{bmatrix} -1 \\ 0 \end{bmatrix} \right)\]

\[= -\frac{1}{2}\begin{bmatrix} 1+1+1 \\ 1-1+0 \end{bmatrix} = -\frac{1}{2}\begin{bmatrix} 3 \\ 0 \end{bmatrix} = \begin{bmatrix} -1.5 \\ 0 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Hessian:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Ta có \(w_i = \frac{e^0}{(1+e^0)^2} = \frac{1}{4}\) với mọi \(i\):&lt;/p&gt;

\[\nabla^2 f(0) = \frac{1}{4}\sum_{i=1}^3 a_i a_i^T\]

\[= \frac{1}{4}\left( \begin{bmatrix} 1 \\ 1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix} + \begin{bmatrix} 1 \\ -1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; -1 \end{bmatrix} + \begin{bmatrix} -1 \\ 0 \end{bmatrix}\begin{bmatrix} -1 &amp;amp; 0 \end{bmatrix} \right)\]

\[= \frac{1}{4}\left( \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} + \begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix} + \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} \right) = \frac{1}{4}\begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Bước Newton:&lt;/strong&gt;&lt;/p&gt;

\[\Delta x_{nt} = -(\nabla^2 f(0))^{-1} \nabla f(0)\]

\[= -\frac{4}{1}\begin{bmatrix} 1/3 &amp;amp; 0 \\ 0 &amp;amp; 1/2 \end{bmatrix} \begin{bmatrix} -1.5 \\ 0 \end{bmatrix} = 4\begin{bmatrix} 0.5 \\ 0 \end{bmatrix} = \begin{bmatrix} 2 \\ 0 \end{bmatrix}\]

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-ii-tìm-kiếm-đường-backtracking&quot;&gt;&lt;strong&gt;Phần II: Tìm kiếm đường Backtracking&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-3-điều-kiện-armijo-boyd--vandenberghe-ex-93&quot;&gt;&lt;strong&gt;Bài tập 3: Điều kiện Armijo (Boyd &amp;amp; Vandenberghe, Ex. 9.3)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho hàm \(f(x) = x^2\) và điểm \(x = 2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tính gradient \(\nabla f(x)\) và Hessian \(\nabla^2 f(x)\).&lt;br /&gt;
b) Tính hướng Newton \(\Delta x_{nt}\).&lt;br /&gt;
c) Với các tham số Armijo \(\alpha = 0.3\), \(\beta = 0.5\), tìm kích thước bước \(t\) thỏa mãn điều kiện Armijo:&lt;/p&gt;

\[f(x + t \Delta x) \leq f(x) + \alpha t \nabla f(x)^T \Delta x\]

&lt;p&gt;d) Minh họa bằng đồ thị.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Gradient và Hessian:&lt;/strong&gt;&lt;/p&gt;

\[\nabla f(x) = 2x, \quad \nabla^2 f(x) = 2\]

  &lt;p&gt;Tại \(x = 2\):&lt;/p&gt;

\[\nabla f(2) = 4, \quad \nabla^2 f(2) = 2\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Hướng Newton:&lt;/strong&gt;&lt;/p&gt;

\[\Delta x_{nt} = -\frac{\nabla f(x)}{\nabla^2 f(x)} = -\frac{4}{2} = -2\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Tìm kiếm đường backtracking:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Điều kiện Armijo:&lt;/p&gt;

\[f(x + t \Delta x) \leq f(x) + \alpha t \nabla f(x)^T \Delta x\]

  &lt;p&gt;Thay số:&lt;/p&gt;

\[(2 + t(-2))^2 \leq 4 + 0.3 \cdot t \cdot 4 \cdot (-2)\]

\[(2 - 2t)^2 \leq 4 - 2.4t\]

\[4 - 8t + 4t^2 \leq 4 - 2.4t\]

\[4t^2 - 5.6t \leq 0\]

\[t(4t - 5.6) \leq 0\]

  &lt;p&gt;Vì \(t &amp;gt; 0\), điều kiện tương đương \(4t - 5.6 \leq 0 \Rightarrow t \leq 1.4\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Kiểm tra backtracking:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Thử \(t = 1\):&lt;/p&gt;

\[f(2 - 2 \cdot 1) = f(0) = 0\]

\[4 + 0.3 \cdot 1 \cdot (-8) = 4 - 2.4 = 1.6\]

  &lt;p&gt;Vì \(0 \leq 1.6\), điều kiện Armijo được thỏa mãn ngay tại \(t = 1\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt; \(t = 1\) (bước Newton đầy đủ).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;d) Giải thích hình học:&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Đồ thị của \(f(x)\) là parabol \(y = x^2\).&lt;/li&gt;
    &lt;li&gt;Tại \(x = 2\), bước Newton \(\Delta x = -2\) hướng thẳng về điểm cực tiểu \(x^* = 0\).&lt;/li&gt;
    &lt;li&gt;Bước đầy đủ \(t = 1\) đưa nghiệm về đúng điểm tối ưu ngay sau 1 vòng lặp.&lt;/li&gt;
    &lt;li&gt;Điều kiện Armijo đảm bảo mức giảm giá trị hàm là đủ lớn (sufficient decrease).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Đồ thị minh họa:&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;f(x) = x²

     4 |     • (2, 4)
       |    /
       |   /
       |  /
     1 |_/__________
       |/      
     0 •------------ x
      0  1   2
         ↑
      Bước Newton
      đưa đến x=0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;

  &lt;p&gt;Đường Armijo: \(y = 4 - 2.4t\) (đường thẳng đi qua \((2, 4)\) có độ dốc thu nhỏ bằng \(\alpha \nabla f \Delta x\)).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-iii-phân-tích-hội-tụ&quot;&gt;&lt;strong&gt;Phần III: Phân tích hội tụ&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-4-hội-tụ-bậc-hai-nocedal--wright-theorem-35&quot;&gt;&lt;strong&gt;Bài tập 4: Hội tụ bậc hai (Nocedal &amp;amp; Wright, Theorem 3.5)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét phương pháp Newton cho hàm lồi mạnh \(f\) thỏa mãn:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[m I \preceq \nabla^2 f(x) \preceq M I\]
  &lt;/li&gt;
  &lt;li&gt;\(\nabla^2 f\) liên tục Lipschitz với hằng số \(L\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Chứng minh phương pháp Newton có hội tụ bậc hai khi gần nghiệm.&lt;br /&gt;
b) Tính toán cụ thể với \(f(x) = \frac{1}{2}x^T Q x\) trong đó \(Q = \begin{bmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\).&lt;br /&gt;
c) So sánh với gradient descent.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Chứng minh hội tụ bậc hai:&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-theorem&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; Nếu \(f\) lồi mạnh với tham số \(m\) và \(\nabla^2 f\) liên tục Lipschitz với hằng số \(L\), thì tồn tại \(\delta &amp;gt; 0\) sao cho khi \(\|x^{(k)} - x^*\| &amp;lt; \delta\):&lt;/p&gt;

    &lt;p&gt;\(\|x^{(k+1)} - x^*\| \leq \frac{L}{2m} \|x^{(k)} - x^*\|^2\)&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Phác thảo chứng minh:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Công thức lặp Newton:&lt;/p&gt;

\[x^{(k+1)} = x^{(k)} - (\nabla^2 f(x^{(k)}))^{-1} \nabla f(x^{(k)})\]

  &lt;p&gt;Khai triển tích phân của gradient quanh \(x^*\):&lt;/p&gt;

\[\nabla f(x^{(k)}) = \nabla f(x^*) + \int_0^1 \nabla^2 f(x^* + t(x^{(k)} - x^*)) (x^{(k)} - x^*) dt\]

  &lt;p&gt;Vì \(\nabla f(x^*) = 0\):&lt;/p&gt;

\[\nabla f(x^{(k)}) = \int_0^1 \nabla^2 f(x^* + t(x^{(k)} - x^*)) (x^{(k)} - x^*) dt\]

  &lt;p&gt;Suy ra sai số ở bước \(k+1\):&lt;/p&gt;

\[x^{(k+1)} - x^* = x^{(k)} - x^* - (\nabla^2 f(x^{(k)}))^{-1} \nabla f(x^{(k)})\]

  &lt;p&gt;Áp dụng tính liên tục Lipschitz của Hessian:&lt;/p&gt;

\[\|\nabla^2 f(x) - \nabla^2 f(y)\| \leq L \|x - y\|\]

  &lt;p&gt;Kết hợp với cận dưới \(m\) của giá trị riêng Hessian (suy ra \(\|(\nabla^2 f(x^{(k)}))^{-1}\| \leq 1/m\)), ta thu được:&lt;/p&gt;

\[\|x^{(k+1)} - x^*\| \leq \frac{L}{2m} \|x^{(k)} - x^*\|^2\]

  &lt;p&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt; Sai số giảm theo bình phương sau mỗi vòng lặp (hội tụ bậc hai).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Tính toán với \(Q = \text{diag}(4, 1)\):&lt;/strong&gt;&lt;/p&gt;

\[f(x) = \frac{1}{2}x^T Q x = 2x_1^2 + \frac{1}{2}x_2^2\]

  &lt;p&gt;&lt;strong&gt;Các tham số:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[m = \lambda_{\min}(Q) = 1\]
    &lt;/li&gt;
    &lt;li&gt;
\[M = \lambda_{\max}(Q) = 4\]
    &lt;/li&gt;
    &lt;li&gt;\(L = 0\) (vì ma trận Hessian là hằng số \(\nabla^2 f(x) = Q\))&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Sự hội tụ:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Với \(L = 0\), phương pháp Newton hội tụ ngay trong &lt;strong&gt;1 bước&lt;/strong&gt; (do \(f\) là hàm bậc hai). Từ mọi điểm khởi tạo \(x^{(0)}\):&lt;/p&gt;

\[x^{(1)} = x^{(0)} - Q^{-1} (Qx^{(0)}) = x^{(0)} - x^{(0)} = 0 = x^*\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) So sánh với Gradient Descent:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Xét gradient descent với kích thước bước tối ưu \(t = \frac{2}{m + M} = \frac{2}{5} = 0.4\):&lt;/p&gt;

\[x^{(k+1)} = x^{(k)} - 0.4 \nabla f(x^{(k)})\]

  &lt;p&gt;&lt;strong&gt;Tốc độ hội tụ:&lt;/strong&gt;&lt;/p&gt;

\[\|x^{(k+1)} - x^*\| \leq \left(\frac{M - m}{M + m}\right) \|x^{(k)} - x^*\| = \frac{3}{5} \|x^{(k)} - x^*\|\]

  &lt;p&gt;Đây là hội tụ tuyến tính với hệ số co \(0.6\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bảng so sánh:&lt;/strong&gt;&lt;/p&gt;

  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Phương pháp&lt;/th&gt;
        &lt;th&gt;Tốc độ hội tụ&lt;/th&gt;
        &lt;th&gt;Số vòng lặp để đạt sai số \(10^{-6}\)&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;Newton&lt;/td&gt;
        &lt;td&gt;Bậc hai&lt;/td&gt;
        &lt;td&gt;1 (với hàm bậc hai)&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Gradient Descent&lt;/td&gt;
        &lt;td&gt;Tuyến tính (\(0.6^k\))&lt;/td&gt;
        &lt;td&gt;\(k = 28\) (do \(0.6^{27} \approx 1.03 \times 10^{-6}\))&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

  &lt;p&gt;Phương pháp Newton hội tụ nhanh hơn đáng kể so với gradient descent.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-iv-tính-bất-biến-affine&quot;&gt;&lt;strong&gt;Phần IV: Tính bất biến Affine&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-5-tính-chất-bất-biến-affine-boyd--vandenberghe-ex-920&quot;&gt;&lt;strong&gt;Bài tập 5: Tính chất bất biến Affine (Boyd &amp;amp; Vandenberghe, Ex. 9.20)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Phương pháp Newton có tính bất biến affine: khi thực hiện phép biến đổi affine lên hệ tọa độ, quỹ đạo lặp của phương pháp không thay đổi.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Chứng minh: Nếu \(\tilde{x} = Ax + b\) với \(A\) khả nghịch và \(\tilde{f}(\tilde{x}) = f(A^{-1}(\tilde{x} - b))\), thì bước Newton biến đổi tương ứng theo phép biến đổi affine đó.&lt;br /&gt;
b) Minh họa bằng một ví dụ cụ thể.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Chứng minh tính bất biến affine:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Bài toán gốc: \(\min_x f(x)\)&lt;br /&gt;
Bài toán sau biến đổi: \(\min_{\tilde{x}} \tilde{f}(\tilde{x})\) với \(\tilde{x} = Ax + b\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Gradient của \(\tilde{f}\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Theo quy tắc chuỗi (với \(x = A^{-1}(\tilde{x} - b)\)):&lt;/p&gt;

\[\nabla \tilde{f}(\tilde{x}) = A^{-T} \nabla f(x)\]

  &lt;p&gt;&lt;strong&gt;Hessian của \(\tilde{f}\):&lt;/strong&gt;&lt;/p&gt;

\[\nabla^2 \tilde{f}(\tilde{x}) = A^{-T} \nabla^2 f(x) A^{-1}\]

  &lt;p&gt;&lt;strong&gt;Bước Newton trong tọa độ mới:&lt;/strong&gt;&lt;/p&gt;

\[\Delta \tilde{x}_{nt} = -(\nabla^2 \tilde{f}(\tilde{x}))^{-1} \nabla \tilde{f}(\tilde{x})\]

\[= -(A \nabla^2 f(x)^{-1} A^T)(A^{-T} \nabla f(x))\]

\[= -A \nabla^2 f(x)^{-1} \nabla f(x) = A \Delta x_{nt}\]

  &lt;p&gt;&lt;strong&gt;Quan hệ giữa hai bước lặp:&lt;/strong&gt;&lt;/p&gt;

\[\Delta \tilde{x}_{nt} = A \Delta x_{nt}\]

  &lt;p&gt;Trong tọa độ gốc:&lt;/p&gt;

\[x^{(k+1)} = x^{(k)} + \Delta x_{nt}\]

  &lt;p&gt;Trong tọa độ mới:&lt;/p&gt;

\[\tilde{x}^{(k+1)} = \tilde{x}^{(k)} + \Delta \tilde{x}_{nt} = A x^{(k)} + b + A \Delta x_{nt} = A x^{(k+1)} + b\]

  &lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Quỹ đạo của phương pháp Newton giữ nguyên cấu trúc dưới mọi phép biến đổi affine khả nghịch.&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Ví dụ minh họa:&lt;/strong&gt;&lt;/p&gt;

\[f(x) = x_1^2 + 4x_2^2\]

  &lt;p&gt;&lt;strong&gt;Phép biến đổi:&lt;/strong&gt; \(\tilde{x} = Ax\) với \(A = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}\), khi đó:&lt;/p&gt;

\[\tilde{f}(\tilde{x}) = \tilde{x}_1^2 + \tilde{x}_2^2\]

  &lt;p&gt;(Phép biến đổi đưa các đường đồng mức elip thành đường tròn.)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Xuất phát từ \(x^{(0)} = (2, 1)^T\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Trong tọa độ gốc:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[\nabla f = (4, 8)^T\]
    &lt;/li&gt;
    &lt;li&gt;
\[\nabla^2 f = \text{diag}(2, 8)\]
    &lt;/li&gt;
    &lt;li&gt;
\[\Delta x = -(2, 1)^T\]
    &lt;/li&gt;
    &lt;li&gt;
\[x^{(1)} = (0, 0)^T\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Trong tọa độ mới:&lt;/strong&gt; \(\tilde{x}^{(0)} = (2, 2)^T\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[\nabla \tilde{f} = (4, 4)^T\]
    &lt;/li&gt;
    &lt;li&gt;
\[\nabla^2 \tilde{f} = 2I\]
    &lt;/li&gt;
    &lt;li&gt;
\[\Delta \tilde{x} = -(2, 2)^T\]
    &lt;/li&gt;
    &lt;li&gt;
\[\tilde{x}^{(1)} = (0, 0)^T\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Cả hai hệ tọa độ đều cho cùng điểm tối ưu với số vòng lặp như nhau.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-v-bài-toán-ứng-dụng&quot;&gt;&lt;strong&gt;Phần V: Bài toán ứng dụng&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-6-điều-khiển-tối-ưu-bertsekas-ex-235&quot;&gt;&lt;strong&gt;Bài tập 6: Điều khiển tối ưu (Bertsekas, Ex. 2.3.5)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét bài toán điều khiển tối ưu rời rạc:&lt;/p&gt;

\[\min_{u_0,\ldots,u_{N-1}} \sum_{k=0}^{N-1} \left( x_k^T Q x_k + u_k^T R u_k \right) + x_N^T Q_f x_N\]

&lt;p&gt;với phương trình trạng thái:&lt;/p&gt;

\[x_{k+1} = A x_k + B u_k, \quad x_0 = \bar{x}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán dưới dạng quy hoạch bậc hai (QP) không ràng buộc.&lt;br /&gt;
b) Tính gradient và ma trận Hessian.&lt;br /&gt;
c) Áp dụng phương pháp Newton với \(N = 3\), \(Q = I\), \(R = I\), \(Q_f = I\), \(A = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}\), \(B = \begin{bmatrix} 0 \\ 1 \end{bmatrix}\), \(\bar{x} = (1, 0)^T\).&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Biểu diễn bài toán dạng QP không ràng buộc:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Biến quyết định:&lt;/strong&gt; \(z = (u_0, u_1, u_2)^T \in \mathbb{R}^{3}\) (với \(u_k \in \mathbb{R}\)).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Biểu diễn \(x_k\) theo \(u\):&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
x_1 &amp;amp;= Ax_0 + Bu_0 \\
x_2 &amp;amp;= Ax_1 + Bu_1 = A^2 x_0 + AB u_0 + B u_1 \\
x_3 &amp;amp;= A^3 x_0 + A^2 B u_0 + AB u_1 + B u_2
\end{align}\]

  &lt;p&gt;&lt;strong&gt;Dạng rút gọn:&lt;/strong&gt; \(x_k = \Phi_k x_0 + \sum_{j=0}^{k-1} \Psi_{kj} u_j\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Hàm mục tiêu:&lt;/strong&gt;&lt;/p&gt;

\[f(u) = \sum_{k=0}^{N-1} (x_k^T Q x_k + u_k^T R u_k) + x_N^T Q_f x_N\]

\[= \frac{1}{2} u^T H u + g^T u + \text{const}\]

  &lt;p&gt;trong đó \(H\) và \(g\) được xác định từ phương trình trạng thái và các ma trận trọng số.&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Gradient và Hessian:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Vì \(f\) là hàm bậc hai:&lt;/p&gt;

\[\nabla f(u) = Hu + g\]

\[\nabla^2 f(u) = H\]

  &lt;p&gt;&lt;strong&gt;Bước Newton:&lt;/strong&gt;&lt;/p&gt;

\[\Delta u = -H^{-1}(Hu + g) = -u - H^{-1}g\]

  &lt;p&gt;Thuật toán hội tụ ngay trong 1 bước.&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Tính toán cụ thể với \(N=3\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Dữ liệu:&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}, \quad
B = \begin{bmatrix} 0 \\ 1 \end{bmatrix}, \quad
x_0 = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Tính các trạng thái \(x_k\):&lt;/strong&gt;&lt;/p&gt;

\[x_1 = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} 1 \\ 0 \end{bmatrix} + \begin{bmatrix} 0 \\ 1 \end{bmatrix} u_0 = \begin{bmatrix} 1 \\ u_0 \end{bmatrix}\]

\[x_2 = A x_1 + B u_1 = \begin{bmatrix} 1 + u_0 \\ u_0 + u_1 \end{bmatrix}\]

\[x_3 = A x_2 + B u_2 = \begin{bmatrix} 1 + 2u_0 + u_1 \\ u_0 + u_1 + u_2 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Hàm mục tiêu (với \(Q = R = Q_f = I\)):&lt;/strong&gt;&lt;/p&gt;

\[f = \sum_{k=0}^2 (\|x_k\|^2 + u_k^2) + \|x_3\|^2\]

\[= (1^2 + u_0^2) + ((1)^2 + (u_0)^2 + u_1^2) + \ldots\]

  &lt;p&gt;Khai triển đầy đủ và lấy đạo hàm, ta thu được \(\nabla f(0) = (6, 2, 0)^T\) và \(\nabla^2 f = \begin{bmatrix} 18 &amp;amp; 8 &amp;amp; 2 \\ 8 &amp;amp; 8 &amp;amp; 2 \\ 2 &amp;amp; 2 &amp;amp; 4 \end{bmatrix}\). Bước Newton xuất phát từ \(u = 0\) là \(\Delta u = -(\nabla^2 f)^{-1}\nabla f(0)\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Điều khiển tối ưu: \(u^* = (-2/5,\ 4/35,\ 1/7)^T \approx (-0.4,\ 0.114,\ 0.143)^T\), với giá trị mục tiêu tối ưu \(f^* = 102/35 \approx 2.914\).&lt;/p&gt;

  &lt;p&gt;Phương pháp Newton tìm ra nghiệm chính xác sau 1 vòng lặp vì bài toán có dạng quy hoạch bậc hai.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tổng-kết-và-lưu-ý-thực-hành&quot;&gt;&lt;strong&gt;Tổng kết và lưu ý thực hành&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;phương-pháp-newton&quot;&gt;&lt;strong&gt;Phương pháp Newton:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước Newton:&lt;/strong&gt; \(\Delta x = -(\nabla^2 f(x))^{-1} \nabla f(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đại lượng giảm Newton:&lt;/strong&gt; \(\lambda(x) = \sqrt{\nabla f(x)^T (\nabla^2 f(x))^{-1} \nabla f(x)}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chí dừng:&lt;/strong&gt; \(\lambda^2(x)/2 &amp;lt; \epsilon\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tìm-kiếm-đường-backtracking&quot;&gt;&lt;strong&gt;Tìm kiếm đường Backtracking:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện Armijo:&lt;/strong&gt; \(f(x + t\Delta x) \leq f(x) + \alpha t \nabla f(x)^T \Delta x\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tham số:&lt;/strong&gt; \(\alpha \in (0, 0.5)\), \(\beta \in (0, 1)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giá trị thường dùng:&lt;/strong&gt; \(\alpha = 0.3\), \(\beta = 0.8\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tính-chất-hội-tụ&quot;&gt;&lt;strong&gt;Tính chất hội tụ:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ bậc hai:&lt;/strong&gt; \(\|x^{(k+1)} - x^*\| \leq C \|x^{(k)} - x^*\|^2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gần điểm tối ưu:&lt;/strong&gt; Khi ở gần \(x^*\), phương pháp Newton hội tụ rất nhanh&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm bậc hai:&lt;/strong&gt; Hội tụ trong 1 bước&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tính-bất-biến-affine&quot;&gt;&lt;strong&gt;Tính bất biến Affine:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Quỹ đạo phương pháp Newton không phụ thuộc vào phép biến đổi affine của hệ tọa độ&lt;/li&gt;
  &lt;li&gt;Số vòng lặp giữ nguyên dưới các phép biến đổi affine khả nghịch&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lợi ích:&lt;/strong&gt; Không nhạy cảm với số điều kiện của hệ tọa độ&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;khi-nào-nên-dùng-phương-pháp-newton&quot;&gt;&lt;strong&gt;Khi nào nên dùng phương pháp Newton:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu trơn, khả vi hai lần (\(\nabla^2 f\) tồn tại và tính được)&lt;/li&gt;
  &lt;li&gt;Đã ở gần nghiệm hoặc cần tốc độ hội tụ cao&lt;/li&gt;
  &lt;li&gt;Số chiều không quá lớn (lưu trữ và giải hệ tuyến tính cỡ \(n \times n\) còn khả thi)&lt;/li&gt;
  &lt;li&gt;Cần độ chính xác cao&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo&quot;&gt;&lt;strong&gt;Tài liệu tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 9.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nocedal, J., &amp;amp; Wright, S. J.&lt;/strong&gt; (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt; (2nd ed.). Springer. Chapters 3, 6.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bertsekas, D. P.&lt;/strong&gt; (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt; (2nd ed.). Athena Scientific. Chapter 1.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nesterov, Y.&lt;/strong&gt; (2004). &lt;em&gt;Introductory Lectures on Convex Optimization&lt;/em&gt;. Springer. Chapter 2.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Dennis, J. E., &amp;amp; Schnabel, R. B.&lt;/strong&gt; (1996). &lt;em&gt;Numerical Methods for Unconstrained Optimization and Nonlinear Equations&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>14-11 Bài tập trắc nghiệm - Phương Pháp Newton</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_11_Quiz_Newton_Method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_11_Quiz_Newton_Method</id>
   <content type="html">&lt;p&gt;Chương 14 chứa rất nhiều khái niệm sắc nét nhưng cũng dễ nhầm lẫn nếu chỉ đọc lướt: phương pháp Newton có vuông góc với đường đồng mức không? Vì sao Newton decrement \(\lambda(x)\) lại bất biến affine trong khi \(\|\nabla f(x)\|_2\) thì không? Điều kiện nào biến một hàm thành tự hài hòa, và vì sao cận hội tụ lại xuất hiện \(\log_2\log_2(1/\epsilon)\)?&lt;/p&gt;

&lt;p&gt;Bộ câu hỏi trắc nghiệm này sẽ kiểm tra toàn diện phản xạ của bạn về tối ưu hóa bậc hai — từ công thức cơ bản, tính chất hình học, tìm kiếm đường backtracking, phân tích hai pha hội tụ, hàm tự hài hòa, đến Quasi-Newton. Hãy rà nhanh bản đồ bốn nhóm bẫy kinh điển trước khi bắt đầu chọn đáp án.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhóm-bẫy-trắc-nghiệm-thường-gặp-ở-chương-14&quot;&gt;Kiến thức cần nhớ: Bốn nhóm bẫy trắc nghiệm thường gặp ở Chương 14&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hình học bước Newton vs. Gradient Descent:&lt;/strong&gt; Nhớ rằng hướng Newton &lt;strong&gt;không&lt;/strong&gt; nhất thiết vuông góc đường đồng mức (trừ khi \(\nabla f(x)\) là vectơ riêng của \(\nabla^2 f(x)\)), nhưng luôn tạo góc nhọn với \(-\nabla f(x)\) miễn là \(\nabla^2 f(x) \succ 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bất biến affine:&lt;/strong&gt; Cả bước cập nhật Newton, Newton decrement \(\lambda(x)\), lẫn cận hội tụ của hàm tự hài hòa đều &lt;strong&gt;bất biến affine&lt;/strong&gt;; ngược lại, Gradient Descent, \(\|\nabla f(x)\|_2\) và các hằng số \(m, L, M\) thì &lt;strong&gt;không&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ cục bộ vs. toàn cục:&lt;/strong&gt; Newton thuần túy (\(t = 1\)) chỉ hội tụ &lt;strong&gt;cục bộ&lt;/strong&gt; (có thể phân kỳ khi xa nghiệm); muốn hội tụ &lt;strong&gt;toàn cục&lt;/strong&gt; trên hàm lồi phải ghép thêm tìm kiếm đường backtracking (Newton có giảm chấn).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm tự hài hòa và độ phức tạp:&lt;/strong&gt; Kiểm tra đúng số mũ \(3/2\) và hằng số \(2\) (\(\vert f&apos;&apos;&apos; \vert \le 2(f&apos;&apos;)^{3/2}\)), nhớ hàm \(-\log x\) là tự hài hòa còn \(e^x\) trên \(\mathbb{R}\) thì không, và chi phí mỗi bước Newton đặc là \(O(n^3)\) với bộ nhớ \(O(n^2)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-mẫu-một-câu-hỏi-bẫy-về-phép-nhân-vô-hướng-hàm-tự-hài-hòa&quot;&gt;Giải thích: Giải mẫu một câu hỏi bẫy về phép nhân vô hướng hàm tự hài hòa&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi mẫu:&lt;/strong&gt; Cho \(f(x) = -\log x\) (đã biết là hàm tự hài hòa trên \(x &amp;gt; 0\)). Xét hai hàm mới \(g_1(x) = 4 f(x)\) và \(g_2(x) = \frac{1}{4} f(x)\). Hàm nào còn là hàm tự hài hòa?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhắc lại điều kiện kiểm tra:&lt;/strong&gt; \(\vert h&apos;&apos;&apos;(x) \vert \le 2 (h&apos;&apos;(x))^{3/2}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra \(g_1(x) = 4(-\log x)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g_1&apos;&apos;(x) = \frac{4}{x^2}\), \(\vert g_1&apos;&apos;&apos;(x) \vert = \frac{8}{x^3}\).&lt;/li&gt;
      &lt;li&gt;Vế phải: \(2\left(\frac{4}{x^2}\right)^{3/2} = 2 \cdot \frac{8}{x^3} = \frac{16}{x^3} \ge \frac{8}{x^3} = \vert g_1&apos;&apos;&apos;(x) \vert\). → &lt;strong&gt;\(g_1\) VẪN tự hài hòa!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra \(g_2(x) = \frac{1}{4}(-\log x)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g_2&apos;&apos;(x) = \frac{1}{4x^2}\), \(\vert g_2&apos;&apos;&apos;(x) \vert = \frac{1}{2x^3}\).&lt;/li&gt;
      &lt;li&gt;Vế phải: \(2\left(\frac{1}{4x^2}\right)^{3/2} = 2 \cdot \frac{1}{8x^3} = \frac{1}{4x^3} &amp;lt; \frac{1}{2x^3} = \vert g_2&apos;&apos;&apos;(x) \vert\). → &lt;strong&gt;\(g_2\) KHÔNG còn tự hài hòa!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc nhớ nhanh cho phòng thi:&lt;/strong&gt; Nhân hàm tự hài hòa với \(c \ge 1\) thì giữ nguyên tính tự hài hòa; nhân với \(0 &amp;lt; c &amp;lt; 1\) có thể làm mất tính tự hài hòa!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập trắc nghiệm, hãy ôn lại các khái niệm chính của chương này:&lt;/p&gt;

&lt;h3 id=&quot;-phương-pháp-newton-newton-method&quot;&gt;⚡ &lt;strong&gt;Phương pháp Newton (Newton Method)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;từ-phương-pháp-bậc-nhất-đến-bậc-hai&quot;&gt;&lt;strong&gt;Từ phương pháp bậc nhất đến bậc hai&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp bậc nhất:&lt;/strong&gt; Gradient descent sử dụng đạo hàm bậc nhất \(abla f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp bậc hai:&lt;/strong&gt; Phương pháp Newton sử dụng thêm đạo hàm bậc hai \(abla^2 f(x)\) (ma trận Hessian).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý tưởng:&lt;/strong&gt; Thay vì xấp xỉ ma trận Hessian bằng \(rac{1}{t}I\), ta tính trực tiếp \(abla^2 f(x)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;bài-toán&quot;&gt;&lt;strong&gt;Bài toán&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x)\) với \(f\) lồi, khả vi hai lần và \(ext{dom}(f) = \mathbb{R}^n\).&lt;/p&gt;

&lt;h4 id=&quot;công-thức-cập-nhật-newton&quot;&gt;&lt;strong&gt;Công thức cập nhật Newton&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - (
abla^2 f(x^{(k-1)}))^{-1} 
abla f(x^{(k-1)})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So sánh với Gradient Descent:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent:&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - t 
abla f(x^{(k-1)})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton:&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - (
abla^2 f(x^{(k-1)}))^{-1} 
abla f(x^{(k-1)})\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-diễn-giải-và-tính-chất&quot;&gt;🔍 &lt;strong&gt;Diễn giải và tính chất&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;diễn-giải-bước-newton&quot;&gt;&lt;strong&gt;Diễn giải bước Newton&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Hướng Newton:&lt;/strong&gt; \(\Delta x_{nt} = -(
abla^2 f(x))^{-1} 
abla f(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa hình học:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Cực tiểu hóa xấp xỉ bậc hai: \(f(x) + 
abla f(x)^T (y-x) + rac{1}{2}(y-x)^T 
abla^2 f(x) (y-x)\)&lt;/li&gt;
  &lt;li&gt;Điểm cực tiểu: \(y^* = x - (
abla^2 f(x))^{-1} 
abla f(x)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;liên-hệ-với-bài-toán-tìm-nghiệm&quot;&gt;&lt;strong&gt;Liên hệ với bài toán tìm nghiệm&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Phương pháp Newton cho bài toán tối ưu tương đương với phương pháp Newton–Raphson giải phương trình \(abla f(x) = 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Newton–Raphson:&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - rac{g(x^{(k-1)})}{g&apos;(x^{(k-1)})}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Khi \(g(x) = 
abla f(x)\):&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - (
abla^2 f(x^{(k-1)}))^{-1} 
abla f(x^{(k-1)})\)&lt;/p&gt;

&lt;h4 id=&quot;tính-bất-biến-affine&quot;&gt;&lt;strong&gt;Tính bất biến affine&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Tính chất:&lt;/strong&gt; Phương pháp Newton bất biến dưới các phép biến đổi affine khả nghịch của hệ tọa độ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nếu:&lt;/strong&gt; \(g(y) = f(Ay + b)\) với \(A\) không suy biến,&lt;br /&gt;
&lt;strong&gt;Thì:&lt;/strong&gt; các bước Newton của \(g\) và \(f\) tương đương nhau qua phép biến đổi đó.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt; Thuật toán không bị ảnh hưởng bởi số điều kiện của hệ tọa độ như gradient descent.&lt;/p&gt;

&lt;h3 id=&quot;-đại-lượng-giảm-newton-newton-decrement&quot;&gt;📐 &lt;strong&gt;Đại lượng giảm Newton (Newton Decrement)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa&quot;&gt;&lt;strong&gt;Định nghĩa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lambda(x) = (
abla f(x)^T (
abla^2 f(x))^{-1} 
abla f(x))^{1/2}\)&lt;/p&gt;

&lt;h4 id=&quot;ý-nghĩa&quot;&gt;&lt;strong&gt;Ý nghĩa&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chất lượng xấp xỉ bậc hai:&lt;/strong&gt; \(rac{1}{2}\lambda^2(x) = f(x) - \min_y \hat{f}(y)\), trong đó \(\hat{f}(y)\) là xấp xỉ bậc hai của \(f\) tại \(x\). Đại lượng \(rac{1}{2}\lambda^2(x)\) là ước lượng cho khoảng cách tối ưu \(f(x) - f^*\) (dựa trên xấp xỉ bậc hai, không phải cận trên chặt trong mọi trường hợp).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ dài bước Newton:&lt;/strong&gt; \(\lambda(x) = \lVert \Delta x_{nt} 
Vert_{
abla^2 f(x)}\) (theo chuẩn cảm sinh bởi ma trận Hessian).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách Mahalanobis:&lt;/strong&gt; Đo độ lớn bước Newton tính từ điểm hiện tại trong hệ đo xác định bởi Hessian.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;các-biểu-thức-tương-đương&quot;&gt;&lt;strong&gt;Các biểu thức tương đương&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\lambda(x) = (\Delta x_{nt}^T 
abla^2 f(x) \Delta x_{nt})^{1/2}\]
  &lt;/li&gt;
  &lt;li&gt;
\[abla f(x)^T \Delta x_{nt} = -\lambda^2(x)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tính-bất-biến-affine-1&quot;&gt;&lt;strong&gt;Tính bất biến affine&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Đại lượng giảm Newton cũng bất biến affine: \(\lambda_g(y) = \lambda_f(x)\).&lt;/p&gt;

&lt;h3 id=&quot;-phương-pháp-newton-có-giảm-chấn-damped-newton-method&quot;&gt;🎯 &lt;strong&gt;Phương pháp Newton có giảm chấn (Damped Newton Method)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;hạn-chế-của-phương-pháp-newton-thuần-túy&quot;&gt;&lt;strong&gt;Hạn chế của phương pháp Newton thuần túy&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không đảm bảo hội tụ toàn cục:&lt;/strong&gt; Giá trị \(f(x^{(k)})\) có thể tăng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chỉ hội tụ cục bộ:&lt;/strong&gt; Cần điểm khởi tạo đủ gần điểm tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tìm-kiếm-đường-backtracking&quot;&gt;&lt;strong&gt;Tìm kiếm đường backtracking&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Thuật toán:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Tính hướng Newton: \(v = -(
abla^2 f(x))^{-1} 
abla f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Backtracking:&lt;/strong&gt; Với tham số \(0 &amp;lt; lpha \le 1/2\), \(0 &amp;lt; eta &amp;lt; 1\):
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;t = 1
while f(x + tv) &amp;gt; f(x) + α t ∇f(x)^T v:
    t = βt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật:&lt;/strong&gt; \(x^+ = x + tv\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;điều-kiện-armijo&quot;&gt;&lt;strong&gt;Điều kiện Armijo&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f(x + tv) \le f(x) + lpha t 
abla f(x)^T v\)&lt;/p&gt;

&lt;p&gt;với \(abla f(x)^T v = -\lambda^2(x) &amp;lt; 0\).&lt;/p&gt;

&lt;h3 id=&quot;-phân-tích-hội-tụ&quot;&gt;📊 &lt;strong&gt;Phân tích hội tụ&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;các-giả-thiết&quot;&gt;&lt;strong&gt;Các giả thiết&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(abla f\) liên tục Lipschitz:&lt;/strong&gt; \(\lVert 
abla f(x) - 
abla f(y) 
Vert_2 \le L \lVert x-y 
Vert_2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi mạnh:&lt;/strong&gt; \(mI \preceq 
abla^2 f(x) \preceq LI\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(abla^2 f\) liên tục Lipschitz:&lt;/strong&gt; \(\lVert 
abla^2 f(x) - 
abla^2 f(y) 
Vert_2 \le M \lVert x-y 
Vert_2\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;hội-tụ-hai-giai-đoạn&quot;&gt;&lt;strong&gt;Hội tụ hai giai đoạn&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Giai đoạn I — Giai đoạn giảm chấn (Damped phase):&lt;/strong&gt; \(\lVert 
abla f(x^{(k)}) 
Vert_2 \ge \eta\)
\(f(x^{(k+1)}) - f(x^{(k)}) \le -\gamma\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giai đoạn II — Giai đoạn thuần túy (Pure phase):&lt;/strong&gt; \(\lVert 
abla f(x^{(k)}) 
Vert_2 &amp;lt; \eta\)
\(rac{M}{2m^2} \lVert 
abla f(x^{(k+1)}) 
Vert_2 \le \left(rac{M}{2m^2} \lVert 
abla f(x^{(k)}) 
Vert_2
ight)^2\)&lt;/p&gt;

&lt;h4 id=&quot;tốc-độ-hội-tụ&quot;&gt;&lt;strong&gt;Tốc độ hội tụ&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Giai đoạn I:&lt;/strong&gt; Giá trị hàm giảm ít nhất một lượng cố định \(\gamma\) ở mỗi bước:
\(f(x^{(k)}) - f^* \le (f(x^{(0)}) - f^*) - \gamma k\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giai đoạn II:&lt;/strong&gt; Hội tụ bậc hai:
\(f(x^{(k)}) - f^* \le rac{2m^3}{M^2}\left(rac{1}{2}
ight)^{2^{k-k_0+1}}\)&lt;/p&gt;

&lt;h4 id=&quot;tổng-độ-phức-tạp-vòng-lặp&quot;&gt;&lt;strong&gt;Tổng độ phức tạp vòng lặp&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(rac{f(x^{(0)}) - f^*}{\gamma} + \log\log\left(rac{\epsilon_0}{\epsilon}
ight)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ước lượng thực hành:&lt;/strong&gt; \(rac{f(x^{(0)}) - f^*}{\gamma} + 6\).&lt;/p&gt;

&lt;h3 id=&quot;-hàm-tự-hài-hòa-self-concordant-functions&quot;&gt;🌟 &lt;strong&gt;Hàm tự hài hòa (Self-Concordant Functions)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;động-lực&quot;&gt;&lt;strong&gt;Động lực&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Phân tích hội tụ cổ điển có hai hạn chế:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khó xác định hằng số:&lt;/strong&gt; Các hằng số \(L, m, M\) thường không biết trước trong thực tế.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không bất biến affine:&lt;/strong&gt; Cận hội tụ phụ thuộc vào hệ tọa độ.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;định-nghĩa-1&quot;&gt;&lt;strong&gt;Định nghĩa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Hàm \(f\) là &lt;strong&gt;tự hài hòa&lt;/strong&gt; nếu với trường hợp một biến:
\(|f&apos;&apos;&apos;(x)| \le 2(f&apos;&apos;(x))^{3/2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trường hợp nhiều biến:&lt;/strong&gt; \(\lvert D^3 f(x)[h,h,h] 
vert \le 2(h^T 
abla^2 f(x) h)^{3/2}\).&lt;/p&gt;

&lt;h4 id=&quot;tính-chất-chính&quot;&gt;&lt;strong&gt;Tính chất chính&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bất biến affine:&lt;/strong&gt; Tính tự hài hòa được bảo toàn qua phép biến đổi affine.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không phụ thuộc hằng số \(L, m, M\):&lt;/strong&gt; Phân tích hội tụ không cần các hằng số này.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hệ với hàm chắn:&lt;/strong&gt; Các hàm chắn logarit của ràng buộc affine là hàm tự hài hòa.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;hội-tụ-với-hàm-tự-hài-hòa&quot;&gt;&lt;strong&gt;Hội tụ với hàm tự hài hòa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Phân tích chỉ dựa vào đại lượng giảm Newton \(\lambda(x)\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Giai đoạn giảm chấn:&lt;/strong&gt; \(\lambda(x) \ge \eta\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giai đoạn thuần túy:&lt;/strong&gt; \(\lambda(x) &amp;lt; \eta\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-so-sánh-phương-pháp-newton-và-gradient-descent&quot;&gt;🔄 &lt;strong&gt;So sánh phương pháp Newton và Gradient Descent&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khía cạnh&lt;/th&gt;
      &lt;th&gt;Phương pháp Newton&lt;/th&gt;
      &lt;th&gt;Gradient Descent&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Bộ nhớ&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\) (lưu ma trận Hessian)&lt;/td&gt;
      &lt;td&gt;\(O(n)\) (lưu vector gradient)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Chi phí tính toán mỗi bước&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(O(n^3)\) (giải hệ tuyến tính)&lt;/td&gt;
      &lt;td&gt;\(O(n)\) (phép toán vector)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tốc độ hội tụ&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Bậc hai (gần điểm tối ưu)&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ảnh hưởng của số điều kiện&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Bất biến affine&lt;/td&gt;
      &lt;td&gt;Nhạy cảm với số điều kiện&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Độ ổn định số học&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Nhạy cảm hơn với sai số số học&lt;/td&gt;
      &lt;td&gt;Ổn định hơn&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h4 id=&quot;ưu-và-nhược-điểm-của-phương-pháp-newton&quot;&gt;&lt;strong&gt;Ưu và nhược điểm của phương pháp Newton&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hội tụ bậc hai khi gần điểm tối ưu.&lt;/li&gt;
  &lt;li&gt;Bất biến affine, không phụ thuộc số điều kiện của hệ tọa độ.&lt;/li&gt;
  &lt;li&gt;Cần ít vòng lặp, đặc biệt khi yêu cầu độ chính xác cao.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Nhược điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Chi phí mỗi bước cao: \(O(n^3)\).&lt;/li&gt;
  &lt;li&gt;Tốn bộ nhớ lưu trữ ma trận Hessian: \(O(n^2)\).&lt;/li&gt;
  &lt;li&gt;Nhạy cảm với sai số số học khi giải hệ với Hessian.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;lựa-chọn-trong-thực-tế&quot;&gt;&lt;strong&gt;Lựa chọn trong thực tế&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Số chiều \(n\) nhỏ đến trung bình:&lt;/strong&gt; Phương pháp Newton thường hiệu quả hơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số chiều \(n\) lớn:&lt;/strong&gt; Nên dùng gradient descent hoặc các phương pháp quasi-Newton.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cần độ chính xác cao hoặc bài toán có số điều kiện xấu:&lt;/strong&gt; Phương pháp Newton có lợi thế rõ rệt.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-lưu-ý-cài-đặt&quot;&gt;🛠️ &lt;strong&gt;Lưu ý cài đặt&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;tính-bước-newton&quot;&gt;&lt;strong&gt;Tính bước Newton&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;Lập ma trận Hessian \(H = 
abla^2 f(x)\).&lt;/li&gt;
  &lt;li&gt;Giải hệ tuyến tính \(H \Delta x = -
abla f(x)\).&lt;/li&gt;
  &lt;li&gt;Không tính nghịch đảo tường minh; dùng phân rã Cholesky, LU hoặc phương pháp gradient liên hợp (CG).&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;ổn-định-số-học&quot;&gt;&lt;strong&gt;Ổn định số học&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Đảm bảo Hessian xác định dương (bổ sung điều chuẩn \(\epsilon I\) nếu cần).&lt;/li&gt;
  &lt;li&gt;Theo dõi số điều kiện \(\kappa(H)\).&lt;/li&gt;
  &lt;li&gt;Luôn dùng tìm kiếm đường backtracking để đảm bảo hội tụ toàn cục.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tiêu-chí-dừng&quot;&gt;&lt;strong&gt;Tiêu chí dừng&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;Đại lượng giảm Newton: \(\lambda^2(x)/2 &amp;lt; \epsilon\).&lt;/li&gt;
  &lt;li&gt;Chuẩn gradient: \(\lVert 
abla f(x) 
Vert_2 &amp;lt; \epsilon\).&lt;/li&gt;
  &lt;li&gt;Độ giảm giá trị hàm: \(\lvert f(x^{(k)}) - f(x^{(k-1)}) 
vert &amp;lt; \epsilon\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-trường-hợp-đặc-biệt-và-mở-rộng&quot;&gt;🎯 &lt;strong&gt;Trường hợp đặc biệt và mở rộng&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;các-phương-pháp-quasi-newton&quot;&gt;&lt;strong&gt;Các phương pháp Quasi-Newton&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Mục tiêu:&lt;/strong&gt; Tránh tính và phân rã ma trận Hessian chính xác.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Công thức cập nhật BFGS:&lt;/strong&gt;
\(B_{k+1} = B_k + rac{y_k y_k^T}{y_k^T s_k} - rac{B_k s_k s_k^T B_k}{s_k^T B_k s_k}\)&lt;/p&gt;

&lt;p&gt;với \(s_k = x_{k+1} - x_k\) và \(y_k = 
abla f(x_{k+1}) - 
abla f(x_k)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;L-BFGS:&lt;/strong&gt; Phiên bản bộ nhớ giới hạn cho các bài toán quy mô lớn.&lt;/p&gt;

&lt;h4 id=&quot;phương-pháp-miền-tin-cậy-trust-region&quot;&gt;&lt;strong&gt;Phương pháp miền tin cậy (Trust Region)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Thay thế tìm kiếm đường bằng bài toán con có ràng buộc bán kính \(\Delta\):
\(\min_p f(x) + 
abla f(x)^T p + rac{1}{2}p^T 
abla^2 f(x) p \quad 	ext{với} \quad \lVert p 
Vert \le \Delta\)&lt;/p&gt;

&lt;h3 id=&quot;-ví-dụ-minh-họa&quot;&gt;💡 &lt;strong&gt;Ví dụ minh họa&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;hồi-quy-logistic&quot;&gt;&lt;strong&gt;Hồi quy logistic&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; \(\min_eta \sum_{i=1}^n \log(1 + \exp(-y_i x_i^T eta))\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient:&lt;/strong&gt; \(abla f(eta) = -\sum_{i=1}^n rac{y_i x_i}{1 + \exp(y_i x_i^T eta)}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hessian:&lt;/strong&gt; \(abla^2 f(eta) = \sum_{i=1}^n rac{\exp(y_i x_i^T eta)}{(1 + \exp(y_i x_i^T eta))^2} x_i x_i^T\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước Newton:&lt;/strong&gt; Giải hệ \(abla^2 f(eta) \Delta eta = -
abla f(eta)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;hàm-bậc-hai&quot;&gt;&lt;strong&gt;Hàm bậc hai&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; \(f(x) = rac{1}{2}x^T Q x + b^T x + c\) với \(Q \succ 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước Newton:&lt;/strong&gt; \(\Delta x = -Q^{-1}(Qx + b) = -(x + Q^{-1}b)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ trong 1 bước:&lt;/strong&gt; \(x^{(1)} = x^{(0)} - (x^{(0)} + Q^{-1}b) = -Q^{-1}b = x^*\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-kết-nối-với-các-chương-khác&quot;&gt;🎯 &lt;strong&gt;Kết nối với các chương khác&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Từ các chương trước:&lt;/strong&gt; Gradient descent (Chương 06), điều kiện KKT (Chương 12) và ứng dụng đối ngẫu (Chương 13).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hướng phát triển tiếp theo:&lt;/strong&gt; Phương pháp chắn (Chương 15), các phương pháp điểm trong, các phương pháp quasi-Newton (Chương 18) và phương pháp miền tin cậy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-tóm-tắt-thực-hành&quot;&gt;💡 &lt;strong&gt;Tóm tắt thực hành&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nên dùng phương pháp Newton khi:&lt;/strong&gt; số chiều vừa phải (thường \(n \le 10^3\)), hàm mục tiêu trơn, cần độ chính xác cao hoặc bài toán có số điều kiện xấu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lỗi thường gặp:&lt;/strong&gt; Hessian suy biến tại điểm yên ngựa hoặc gần biên, chi phí tính đạo hàm bậc hai quá cao, điểm khởi tạo xa vùng hội tụ bậc hai, hoặc tính nghịch đảo ma trận tường minh gây khuếch đại sai số số học.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các biến thể và lĩnh vực ứng dụng:&lt;/strong&gt; Newton điều chuẩn (\(H + \epsilon I\)), Levenberg–Marquardt, điều chuẩn bậc ba, Newton không chính xác (dùng CG), L-BFGS, Gauss–Newton, SQP, phương pháp điểm trong; ứng dụng trong hồi quy logistic, ước lượng hợp lý cực đại, mô hình tuyến tính tổng quát (IRLS), điều khiển tối ưu, xử lý tín hiệu và tối ưu danh mục đầu tư.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra kiến thức về phương pháp Newton, bao gồm tối ưu bậc hai, phân tích hội tụ, tìm kiếm đường backtracking, hàm tự hài hòa và các phương pháp quasi-Newton.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🔢 Bài tập trắc nghiệm: Phương pháp Newton&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 4%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;25&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: Newton method update --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Công thức cập nhật của phương pháp Newton thuần túy (không dùng tìm kiếm đường) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(x^{(k+1)} = x^{(k)} - t_k 
abla f(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(x^{(k+1)} = x^{(k)} - t_k [
abla^2 f(x^{(k)})]^{-1} 
abla f(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(x^{(k+1)} = x^{(k)} - [
abla^2 f(x^{(k)})]^{-1} 
abla f(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(x^{(k+1)} = x^{(k)} - 
abla^2 f(x^{(k)}) 
abla f(x^{(k)})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) $$x^{(k+1)} = x^{(k)} - [
abla^2 f(x^{(k)})]^{-1} 
abla f(x^{(k)})$$&lt;/strong&gt;&lt;br /&gt;
                Phương pháp Newton thuần túy dùng bước Newton đầy đủ với kích thước bước $$t = 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Newton direction --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Hướng Newton \(\Delta x_{nt}\) được xác định bằng cách giải hệ phương trình:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(
abla^2 f(x) \Delta x_{nt} = 
abla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(
abla^2 f(x) \Delta x_{nt} = -
abla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(
abla f(x) \Delta x_{nt} = -
abla^2 f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(\Delta x_{nt} = -
abla f(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$
abla^2 f(x) \Delta x_{nt} = -
abla f(x)$$&lt;/strong&gt;&lt;br /&gt;
                Hướng Newton được tìm bằng cách giải hệ phương trình tuyến tính với ma trận Hessian và vế phải là đối của gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Second-order method --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Phương pháp Newton được gọi là phương pháp bậc hai vì:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) Sử dụng đạo hàm bậc hai (ma trận Hessian)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Hội tụ trong 2 bước&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Cần 2 lần tính gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Có tốc độ hội tụ bậc hai&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Sử dụng đạo hàm bậc hai (ma trận Hessian)&lt;/strong&gt;&lt;br /&gt;
                Các phương pháp bậc hai sử dụng thông tin đạo hàm bậc hai (Hessian), khác với phương pháp bậc nhất chỉ dùng gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Convergence rate --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Tốc độ hội tụ cục bộ của phương pháp Newton là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Tuyến tính (Linear)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Siêu tuyến tính (Superlinear)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Bậc hai (Quadratic)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Bậc ba (Cubic)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Bậc hai (Quadratic)&lt;/strong&gt;&lt;br /&gt;
                Trong vùng lân cận điểm tối ưu, phương pháp Newton đạt hội tụ bậc hai: $$\lVert x^{(k+1)} - x^* 
Vert \leq C \lVert x^{(k)} - x^* 
Vert^2$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Newton decrement --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Đại lượng giảm Newton (Newton decrement) \(\lambda(x)\) được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(\lambda(x) = \sqrt{
abla f(x)^T [
abla^2 f(x)]^{-1} 
abla f(x)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(\lambda(x) = 
abla f(x)^T [
abla^2 f(x)]^{-1} 
abla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) $$\lambda(x) = \lVert 
abla f(x) 
Vert$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) $$\lambda(x) = \lVert 
abla^2 f(x) 
Vert$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\lambda(x) = \sqrt{
abla f(x)^T [
abla^2 f(x)]^{-1} 
abla f(x)}$$&lt;/strong&gt;&lt;br /&gt;
                Đại lượng giảm Newton là tiêu chí dừng tự nhiên và bất biến affine cho phương pháp Newton.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Affine invariance --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Tính chất bất biến affine của phương pháp Newton có nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) Quỹ đạo lặp không thay đổi dưới các phép biến đổi tọa độ affine khả nghịch&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) Chỉ hoạt động với các hàm affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) Yêu cầu phải có ràng buộc affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Chỉ đạt hội tụ tuyến tính&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Quỹ đạo lặp không thay đổi dưới các phép biến đổi tọa độ affine khả nghịch&lt;/strong&gt;&lt;br /&gt;
                Phương pháp Newton không phụ thuộc hệ tọa độ: nếu biến đổi $$x \mapsto Ax + b$$ (với $$A$$ khả nghịch), các bước Newton biến đổi tương ứng theo đúng phép biến đổi đó.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Backtracking line search --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Tìm kiếm đường backtracking trong phương pháp Newton sử dụng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Điều kiện Armijo dọc theo hướng Newton&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Tìm kiếm đường chính xác (exact line search)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Kích thước bước cố định&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Tìm kiếm tỷ lệ vàng (golden section search)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Điều kiện Armijo dọc theo hướng Newton&lt;/strong&gt;&lt;br /&gt;
                Tìm kiếm đường backtracking kiểm tra điều kiện giảm đủ (Armijo): $$f(x + t\Delta x_{nt}) \leq f(x) + lpha t 
abla f(x)^T \Delta x_{nt}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: When Newton method fails --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Phương pháp Newton thuần túy có thể gặp sự cố hoặc không hội tụ khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) Ma trận Hessian không xác định dương&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) Điểm khởi tạo ở quá xa điểm tối ưu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Ma trận Hessian suy biến&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) Tất cả các trường hợp trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các trường hợp trên&lt;/strong&gt;&lt;br /&gt;
                Phương pháp Newton cần Hessian xác định dương để đảm bảo hướng giảm, không xác định khi Hessian suy biến, và có thể phân kỳ nếu xuất phát quá xa nghiệm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Self-concordant functions --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Lớp hàm tự hài hòa (self-concordant functions) quan trọng vì:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) Phân tích hội tụ không phụ thuộc vào các hằng số $$L, m, M$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) Phân tích hội tụ có tính bất biến affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) Xuất hiện tự nhiên trong các hàm chắn của phương pháp điểm trong&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) Tất cả các lý do trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các lý do trên&lt;/strong&gt;&lt;br /&gt;
                Hàm tự hài hòa loại bỏ sự phụ thuộc vào các hằng số khó ước lượng, giữ nguyên tính bất biến affine trong phân tích hội tụ và là cơ sở lý thuyết cho các hàm chắn logarit.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Self-concordance definition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Hàm lồi \(f\) là hàm tự hài hòa nếu thỏa mãn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(|f&apos;&apos;&apos;(x)[h,h,h]| \leq 2(f&apos;&apos;(x)[h,h])^{3/2}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(f&apos;&apos;(x) \succ 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(f\) là hàm lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(f\) là hàm trơn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$|f&apos;&apos;&apos;(x)[h,h,h]| \leq 2(f&apos;&apos;(x)[h,h])^{3/2}$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện tự hài hòa chặn độ lớn đạo hàm bậc ba theo đạo hàm bậc hai dọc theo mọi hướng $$h$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Quasi-Newton methods --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Các phương pháp quasi-Newton khác phương pháp Newton ở điểm nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Không cần tính ma trận Hessian chính xác&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Dùng ma trận xấp xỉ cho Hessian (hoặc nghịch đảo Hessian)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Chi phí tính toán mỗi bước thấp hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Tất cả các điểm trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các điểm trên&lt;/strong&gt;&lt;br /&gt;
                Các phương pháp quasi-Newton xấp xỉ Hessian từ thông tin gradient để giảm chi phí tính toán mỗi vòng lặp.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: BFGS update --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Phương pháp BFGS (dạng thông dụng) trực tiếp cập nhật xấp xỉ của:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Chỉ đường chéo của ma trận Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Ma trận nghịch đảo của Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Vector gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Giá trị hàm mục tiêu&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Ma trận nghịch đảo của Hessian&lt;/strong&gt;&lt;br /&gt;
                Ở dạng thường dùng, BFGS cập nhật trực tiếp ma trận xấp xỉ $$H_k$$ của nghịch đảo Hessian để tránh giải hệ tuyến tính (cũng có dạng tương đương cập nhật xấp xỉ $$B_k$$ của chính Hessian).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Computational complexity --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Chi phí tính toán tổng quát cho mỗi vòng lặp của phương pháp Newton (với $$n$$ biến) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(O(n)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(O(n^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(O(n^3)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(O(n^4)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) $$O(n^3)$$&lt;/strong&gt;&lt;br /&gt;
                Phương pháp Newton cần lưu trữ $$O(n^2)$$ cho ma trận Hessian và tốn $$O(n^3)$$ phép tính để giải hệ tuyến tính $$H \Delta x = -g$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Damped Newton method --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Phương pháp Newton có giảm chấn (damped Newton method) sử dụng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Kích thước bước nhỏ cố định&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Tìm kiếm đường dọc theo hướng Newton&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Ma trận Hessian hiệu chỉnh cố định&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Hướng của gradient descent&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tìm kiếm đường dọc theo hướng Newton&lt;/strong&gt;&lt;br /&gt;
                Phương pháp Newton có giảm chấn kết hợp hướng Newton với tìm kiếm đường backtracking để đảm bảo hội tụ toàn cục.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Trust region vs line search --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Phương pháp Newton miền tin cậy (trust region) khác phương pháp Newton tìm kiếm đường ở chỗ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Giới hạn độ dài bước đi trong một miền tin cậy&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Có thể thay đổi cả hướng bước đi thay vì chỉ thu nhỏ kích thước bước&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Chọn bước bằng cách giải bài toán con với ràng buộc $$\lVert p 
Vert \leq \Delta$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Tất cả các điểm trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các điểm trên&lt;/strong&gt;&lt;br /&gt;
                Phương pháp miền tin cậy cực tiểu hóa mô hình bậc hai trong vùng bán kính $$\Delta$$, qua đó đồng thời kiểm soát cả độ dài lẫn hướng bước đi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Newton method for root finding --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Phương pháp Newton tìm nghiệm cho phương trình một biến \(g(x) = 0\) có công thức lặp:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(x^{(k+1)} = x^{(k)} - rac{g(x^{(k)})}{g&apos;(x^{(k)})}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(x^{(k+1)} = x^{(k)} - g(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(x^{(k+1)} = x^{(k)} - g&apos;(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(x^{(k+1)} = x^{(k)} + rac{g(x^{(k)})}{g&apos;(x^{(k)})}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$x^{(k+1)} = x^{(k)} - rac{g(x^{(k)})}{g&apos;(x^{(k)})}$$&lt;/strong&gt;&lt;br /&gt;
                Phương pháp Newton cho tối ưu hóa chính là áp dụng công thức tìm nghiệm này cho phương trình $$
abla f(x) = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Hessian modification --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Khi ma trận Hessian không xác định dương, ta có thể xử lý bằng cách:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Thêm điều chuẩn: \(H + \lambda I\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Điều chỉnh các giá trị riêng âm (lấy trị tuyệt đối hoặc cắt ngưỡng dương)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Dùng phân rã Cholesky hiệu chỉnh (modified Cholesky)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Tất cả các phương pháp trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các phương pháp trên&lt;/strong&gt;&lt;br /&gt;
                Cả ba kỹ thuật (thêm điều chuẩn, hiệu chỉnh giá trị riêng, phân rã Cholesky hiệu chỉnh) đều giúp thu được ma trận xác định dương để đảm bảo hướng giảm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: L-BFGS --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Ưu điểm của thuật toán L-BFGS (Limited-memory BFGS) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Yêu cầu bộ nhớ \(O(n)\) thay vì \(O(n^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Phù hợp với các bài toán tối ưu quy mô lớn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Không cần lưu trữ ma trận đầy đủ cỡ \(n 	imes n\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Tất cả các ưu điểm trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các ưu điểm trên&lt;/strong&gt;&lt;br /&gt;
                L-BFGS chỉ lưu một số lượng nhỏ các cặp vector lịch sử (thường từ 5 đến 20 cặp) thay vì ma trận đầy đủ, nên rất phù hợp cho bài toán nhiều biến.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Newton method applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Phương pháp Newton được ứng dụng trong lĩnh vực nào sau đây?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Các phương pháp điểm trong (interior-point methods)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Huấn luyện mô hình học máy và mạng nơ-ron (các biến thể bậc hai)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Ước lượng hợp lý cực đại (maximum likelihood estimation)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Tất cả các ứng dụng trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các ứng dụng trên&lt;/strong&gt;&lt;br /&gt;
                Phương pháp Newton và các biến thể của nó được dùng rộng rãi trong phương pháp điểm trong, học máy và ước lượng thống kê.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Comparison with first-order methods --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: So với các phương pháp bậc nhất, phương pháp Newton có đặc điểm:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Cần ít vòng lặp hơn nhưng chi phí mỗi vòng lặp cao hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Hội tụ bậc hai (cục bộ) so với hội tụ tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Bất biến affine so với phụ thuộc hệ tọa độ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các đặc điểm trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các đặc điểm trên&lt;/strong&gt;&lt;br /&gt;
                Phương pháp Newton đánh đổi chi phí mỗi bước cao hơn để đạt số vòng lặp ít hơn, hội tụ bậc hai gần nghiệm và tính bất biến affine.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Phương pháp Newton sử dụng thông tin nào của hàm mục tiêu?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Cả gradient và ma trận Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Chỉ gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Chỉ ma trận Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Chỉ giá trị hàm số&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Cả gradient và ma trận Hessian&lt;/strong&gt;&lt;br /&gt;
                Công thức cập nhật Newton: $$x^{(k+1)} = x^{(k)} - [
abla^2 f(x^{(k)})]^{-1} 
abla f(x^{(k)})$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Tốc độ hội tụ của phương pháp Newton gần điểm tối ưu là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Bậc hai (Quadratic)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Tuyến tính (Linear)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Dưới tuyến tính (Sublinear)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Bậc ba (Cubic)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Bậc hai (Quadratic)&lt;/strong&gt;&lt;br /&gt;
                Phương pháp Newton hội tụ bậc hai khi ở gần nghiệm với Hessian khả nghịch và liên tục Lipschitz.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Các phương pháp quasi-Newton khác phương pháp Newton ở chỗ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Xấp xỉ ma trận Hessian thay vì tính chính xác&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Không dùng gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Chỉ áp dụng cho hàm tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Luôn chậm hơn trong mọi bài toán&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Xấp xỉ ma trận Hessian thay vì tính chính xác&lt;/strong&gt;&lt;br /&gt;
                Các phương pháp quasi-Newton (như BFGS, L-BFGS) xây dựng xấp xỉ Hessian từ thông tin gradient qua các bước lặp.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Công thức cập nhật BFGS (dạng thông dụng) cập nhật:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Ma trận xấp xỉ nghịch đảo Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Vector gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Điểm lặp hiện tại&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Kích thước bước&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Ma trận xấp xỉ nghịch đảo Hessian&lt;/strong&gt;&lt;br /&gt;
                BFGS cập nhật ma trận xấp xỉ $$H_k pprox [
abla^2 f]^{-1}$$ dựa trên hiệu vị trí và hiệu gradient giữa hai bước liên tiếp.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Với hàm $$f(x) = x^2$$, một bước Newton xuất phát từ $$x_0 = 2$$ cho:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$x_1 = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$x_1 = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$x_1 = -2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$x_1 = 2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$x_1 = 0$$&lt;/strong&gt;&lt;br /&gt;
                Ta có $$
abla f(2) = 4$$ và $$
abla^2 f(2) = 2$$, nên $$x_1 = 2 - 4/2 = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành bài tập trắc nghiệm!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;c&apos;, q2: &apos;b&apos;, q3: &apos;a&apos;, q4: &apos;c&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;a&apos;, q8: &apos;d&apos;, q9: &apos;d&apos;, q10: &apos;a&apos;,
    q11: &apos;d&apos;, q12: &apos;b&apos;, q13: &apos;c&apos;, q14: &apos;b&apos;, q15: &apos;d&apos;,
    q16: &apos;a&apos;, q17: &apos;d&apos;, q18: &apos;d&apos;, q19: &apos;d&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã thành thạo Newton method và second-order optimization!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu tốt về Newton method và convergence analysis.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại self-concordance và quasi-Newton methods.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Ôn lại Newton direction và backtracking line search.&apos;;
    } else {
        message = &apos;📖 Hãy học lại từ đầu về Newton method nhé!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>14-09 Các phương pháp Quasi-Newton</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_09_quasi_newton_methods/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_09_quasi_newton_methods</id>
   <content type="html">&lt;p&gt;Đứng giữa hai thái cực — Gradient Descent quá chậm vì mù độ cong, và Phương pháp Newton quá đắt vì phải tính và nghịch đảo ma trận Hessian \(O(n^3)\) — các nhà toán học thập niên 1960–1970 đã tìm ra một “vùng đất vàng” đầy thiên tài: &lt;strong&gt;các phương pháp Tựa Newton (Quasi-Newton)&lt;/strong&gt;, với đại diện huyền thoại là &lt;strong&gt;BFGS&lt;/strong&gt; và phiên bản tiết kiệm bộ nhớ &lt;strong&gt;L-BFGS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Ý tưởng của Quasi-Newton giống như việc bạn quan sát sự thay đổi của độ dốc sau mỗi bước đi để &lt;strong&gt;dần dần tự vẽ lại bản đồ độ cong&lt;/strong&gt; mà không bao giờ cần tính một đạo hàm bậc hai nào cả! Chỉ từ lịch sử các bước dịch chuyển \(s_k = x^{(k+1)} - x^{(k)}\) và hiệu gradient \(y_k = \nabla f(x^{(k+1)}) - \nabla f(x^{(k)})\), BFGS cập nhật một ma trận xấp xỉ nghịch đảo Hessian \(H_k\) chỉ tốn \(O(n^2)\) (và L-BFGS chỉ tốn \(O(mn)\) với \(m \approx 10\)), nhưng vẫn đạt tốc độ &lt;strong&gt;hội tụ siêu tuyến tính&lt;/strong&gt; sát nút phương pháp Newton!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cách-quasi-newton-học-độ-cong-chỉ-từ-đạo-hàm-bậc-nhất&quot;&gt;Kiến thức cần nhớ: Cách Quasi-Newton học độ cong chỉ từ đạo hàm bậc nhất&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương trình cát tuyến (Secant Equation):&lt;/strong&gt; Vì \(\nabla f(x^{(k+1)}) - \nabla f(x^{(k)}) \approx \nabla^2 f(x^{(k+1)})(x^{(k+1)} - x^{(k)})\), ma trận xấp xỉ Hessian mới \(B_{k+1}\) (hoặc nghịch đảo \(H_{k+1} = B_{k+1}^{-1}\)) phải thỏa mãn:
\(B_{k+1} s_k = y_k \qquad \Longleftrightarrow \qquad H_{k+1} y_k = s_k.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật hạng thấp (Rank-2 Update) của BFGS:&lt;/strong&gt; Trong vô số ma trận đối xứng xác định dương thỏa \(H_{k+1} y_k = s_k\), BFGS chọn ma trận gần \(H_k\) nhất theo chuẩn có trọng số, cho ra công thức cập nhật chỉ gồm phép nhân vectơ-ma trận tốn \(O(n^2)\) mà không cần giải hệ tuyến tính!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện độ cong \(s_k^T y_k &amp;gt; 0\):&lt;/strong&gt; Để \(H_{k+1}\) luôn xác định dương (đảm bảo hướng đi luôn là hướng giảm), ta cần \(s_k^T y_k &amp;gt; 0\) — điều kiện này tự động thỏa mãn khi dùng tìm kiếm đường Wolfe cho hàm lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;L-BFGS cho bài toán lớn:&lt;/strong&gt; Thay vì lưu ma trận \(H_k\) cỡ \(n \times n\), L-BFGS chỉ lưu \(m\) cặp vectơ \((s_i, y_i)\) gần nhất (thường \(m = 5\text{–}20\)), giảm cả bộ nhớ lẫn chi phí mỗi bước xuống \(O(mn)\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-thực-hiện-tay-1-bước-cập-nhật-bfgs-và-kiểm-chứng-phương-trình-cát-tuyến&quot;&gt;Giải thích: Thực hiện tay 1 bước cập nhật BFGS và kiểm chứng phương trình cát tuyến&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai 2 chiều \(f(x_1, x_2) = x_1^2 + 2x_2^2\) (Hessian thật là \(Q = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 4 \end{bmatrix}\), nghịch đảo thật là \(Q^{-1} = \begin{bmatrix} 0.5 &amp;amp; 0 \\ 0 &amp;amp; 0.25 \end{bmatrix}\)).
Khởi tạo tại \(x^{(0)} = (1, 1)^T\) với xấp xỉ nghịch đảo Hessian ban đầu \(H_0 = I_2\) (chưa biết gì về độ cong).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước đi đầu tiên (giống GD vì \(H_0 = I\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\nabla f(x^{(0)}) = (2, 4)^T\), hướng tìm kiếm \(p_0 = -H_0 \nabla f(x^{(0)}) = (-2, -4)^T\).&lt;/li&gt;
      &lt;li&gt;Chọn bước tối ưu theo đường thẳng \(t_0 = \frac{\nabla f^T p_0}{-p_0^T Q p_0} = \frac{20}{2(4) + 4(16)} = \frac{20}{72} = \frac{5}{18} \approx 0.2778\).&lt;/li&gt;
      &lt;li&gt;Giả sử để tính tay cực gọn, ta đi một bước \(t_0 = 0.25\) (thỏa điều kiện giảm mạnh):
\(x^{(1)} = (1, 1)^T + 0.25(-2, -4)^T = (0.5, 0)^T.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính cặp cát tuyến \((s_0, y_0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(s_0 = x^{(1)} - x^{(0)} = (-0.5, -1)^T\).&lt;/li&gt;
      &lt;li&gt;\(\nabla f(x^{(1)}) = (1, 0)^T \implies y_0 = \nabla f(x^{(1)}) - \nabla f(x^{(0)}) = (-1, -4)^T\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra điều kiện độ cong: \(s_0^T y_0 = (-0.5)(-1) + (-1)(-4) = 4.5 &amp;gt; 0\) (đặt \(\rho_0 = \frac{1}{s_0^T y_0} = \frac{2}{9}\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(H_1 = (I - \rho_0 s_0 y_0^T) H_0 (I - \rho_0 y_0 s_0^T) + \rho_0 s_0 s_0^T\) và kiểm chứng \(H_1 y_0 = s_0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Do \(H_0 = I\), ta có \(I - \rho_0 s_0 y_0^T = I - \frac{2}{9}\begin{bmatrix} 0.5 &amp;amp; 2 \\ 1 &amp;amp; 4 \end{bmatrix} = \frac{1}{9}\begin{bmatrix} 8 &amp;amp; -4 \\ -2 &amp;amp; 1 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;Tính trực tiếp:
\(H_1 = \frac{1}{81}\begin{bmatrix} 8 &amp;amp; -4 \\ -2 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 8 &amp;amp; -2 \\ -4 &amp;amp; 1 \end{bmatrix} + \frac{2}{9}\begin{bmatrix} 0.25 &amp;amp; 0.5 \\ 0.5 &amp;amp; 1 \end{bmatrix} = \frac{1}{81}\begin{bmatrix} 80 &amp;amp; -20 \\ -20 &amp;amp; 5 \end{bmatrix} + \frac{1}{81}\begin{bmatrix} 4.5 &amp;amp; 9 \\ 9 &amp;amp; 18 \end{bmatrix} = \frac{1}{81}\begin{bmatrix} 84.5 &amp;amp; -11 \\ -11 &amp;amp; 23 \end{bmatrix}.\)&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Kiểm tra phương trình cát tuyến:&lt;/strong&gt;
\(H_1 y_0 = \frac{1}{81}\begin{bmatrix} 84.5(-1) + (-11)(-4) \\ (-11)(-1) + 23(-4) \end{bmatrix} = \frac{1}{81}\begin{bmatrix} -40.5 \\ -81 \end{bmatrix} = \begin{bmatrix} -0.5 \\ -1 \end{bmatrix} = s_0!\)
Không hề dùng đạo hàm bậc hai, \(H_1\) đã khớp chính xác độ cong dọc theo hướng vừa đi — và trên hàm bậc hai 2 chiều, chỉ sau 2 bước BFGS sẽ khớp trọn vẹn \(Q^{-1}\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
    });
&lt;/script&gt;

&lt;p&gt;Khi chi phí tính ma trận Hessian quá lớn hoặc ma trận Hessian bị suy biến, ta có thể dùng các phương pháp tựa Newton (quasi-Newton) để thay \(\nabla^{2}f(x)\) bằng một ma trận xấp xỉ xác định dương \(H \succ 0\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{+} = x - tH^{-1}\nabla f(x)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Một số đặc điểm chính của các phương pháp quasi-Newton (xem chi tiết tại &lt;a href=&quot;/contents/vi/chapter18/18_00_Quasi_Newton_methods/&quot;&gt;Chương 18&lt;/a&gt;):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ma trận xấp xỉ Hessian \(H\) (hoặc nghịch đảo \(H^{-1}\)) được cập nhật sau mỗi bước với mục tiêu tính \(H^{-1}\nabla f(x)\) với chi phí thấp.&lt;/li&gt;
  &lt;li&gt;Tốc độ hội tụ là siêu tuyến tính, chậm hơn tốc độ bậc hai của phương pháp Newton đầy đủ; thông thường, khoảng \(n\) bước quasi-Newton mang lại mức tiến triển tương đương một bước Newton.&lt;/li&gt;
  &lt;li&gt;Nhiều phương pháp quasi-Newton cập nhật \(H\) ở mỗi vòng lặp bằng các công thức cập nhật bậc thấp dựa trên thông tin gradient thu được từ các bước trước.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>14-08 Các trường hợp đặc biệt</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_08_special_cases/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_08_special_cases</id>
   <content type="html">&lt;p&gt;Ở bài trước, phép tính \(O(n^3)\) có vẻ như đã “tuyên án tử” cho phương pháp Newton trên các bài toán quy mô lớn. Nhưng trong kỹ thuật thực tế, rất ít bài toán lớn có ma trận Hessian đặc hoàn toàn! Từ điều khiển quỹ đạo tên lửa (MPC), ước lượng trạng thái SLAM của xe tự hành, đến tối ưu hóa mạng lưới điện — ma trận Hessian thường &lt;strong&gt;cực kỳ thưa&lt;/strong&gt; (dạng dải băng &lt;em&gt;banded&lt;/em&gt; hoặc mũi tên &lt;em&gt;arrow&lt;/em&gt;), giúp giải hệ Newton chỉ tốn \(O(n)\) thay vì \(O(n^3)\)!&lt;/p&gt;

&lt;p&gt;Không chỉ vậy, bài học này còn mở rộng phương pháp Newton sang một lớp bài toán cực kỳ quan trọng: &lt;strong&gt;tối ưu hóa có ràng buộc đẳng thức tuyến tính \(Ax = b\)&lt;/strong&gt;. Thay vì bỏ qua ràng buộc rồi chiếu lại, ta tuyến tính hóa trực tiếp hệ điều kiện KKT để tạo ra một hệ tuyến tính khối đối xứng (hệ KKT), vừa giữ điểm lặp luôn thỏa \(Ax = b\) vừa bảo toàn nguyên vẹn tốc độ hội tụ bậc hai!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hai-hướng-mở-rộng-quyền-năng-của-phương-pháp-newton&quot;&gt;Kiến thức cần nhớ: Hai hướng mở rộng quyền năng của phương pháp Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khai thác cấu trúc thưa (Structured / Banded Hessian):&lt;/strong&gt; Khi mỗi biến chỉ tương tác với vài biến lân cận (như chuỗi thời gian \(x_t\) chỉ nối với \(x_{t-1}, x_{t+1}\)), ma trận Hessian là ma trận dải băng độ rộng \(k \ll n\), phân rã Cholesky dải băng chỉ tốn \(O(nk^2)\) — tuyến tính theo \(n\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp Newton có ràng buộc đẳng thức (Equality-Constrained Newton):&lt;/strong&gt; Với bài toán \(\min_x f(x)\) thỏa \(Ax = b\), ta thay \(f\) bằng Taylor bậc hai nhưng &lt;strong&gt;giữ nguyên ràng buộc \(A(x + v) = b\)&lt;/strong&gt;. Nếu \(x\) đã khả thi (\(Ax = b\)), điều kiện này trở thành \(Av = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ phương trình KKT cho bước Newton:&lt;/strong&gt; Điều kiện tối ưu của bài toán bậc hai có ràng buộc cho ra hệ tuyến tính khối:
\(\begin{bmatrix} \nabla^2 f(x) &amp;amp; A^T \\ A &amp;amp; 0 \end{bmatrix} \begin{bmatrix} v \\ w \end{bmatrix} = \begin{bmatrix} -\nabla f(x) \\ 0 \end{bmatrix}.\)
Lời giải \(v\) chính là bước Newton khả thi, còn \(w\) là ước lượng nhân tử đối ngẫu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất biến affine và phương pháp điểm trong:&lt;/strong&gt; Phương pháp Newton có ràng buộc đẳng thức cũng hoàn toàn bất biến affine và là “động cơ bên trong” của toàn bộ Chương 15 (Phương pháp chắn).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-hệ-kkt-của-phương-pháp-newton-có-ràng-buộc-đẳng-thức&quot;&gt;Giải thích: Giải tay hệ KKT của phương pháp Newton có ràng buộc đẳng thức&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu có ràng buộc đẳng thức:
\(\min_{x \in \mathbb{R}^2} f(x_1, x_2) = \frac{1}{2}x_1^2 + x_2^2 + e^{x_1 - 1} \qquad \text{với điều kiện } x_1 + x_2 = 2.\)
Xuất phát từ điểm khả thi \(x^{(0)} = (1, 1)^T\) (thỏa \(1 + 1 = 2\)), ta có \(A = \begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính gradient và Hessian tại \(x^{(0)} = (1, 1)^T\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\nabla f(x) = \begin{bmatrix} x_1 + e^{x_1 - 1} \\ 2x_2 \end{bmatrix} \implies \nabla f(1, 1) = \begin{bmatrix} 2 \\ 2 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;\(\nabla^2 f(x) = \begin{bmatrix} 1 + e^{x_1 - 1} &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix} \implies \nabla^2 f(1, 1) = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lập hệ phương trình KKT khối \(3 \times 3\):&lt;/strong&gt;
\(\begin{bmatrix} 2 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} v_1 \\ v_2 \\ w \end{bmatrix} = \begin{bmatrix} -2 \\ -2 \\ 0 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải trực tiếp từng dòng:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Dòng 1: \(2v_1 + w = -2 \implies v_1 = -1 - \frac{w}{2}\).&lt;/li&gt;
      &lt;li&gt;Dòng 2: \(2v_2 + w = -2 \implies v_2 = -1 - \frac{w}{2}\).&lt;/li&gt;
      &lt;li&gt;Thay vào dòng 3 (\(v_1 + v_2 = 0\)): \(-2 - w = 0 \implies w = -2\).&lt;/li&gt;
      &lt;li&gt;Suy ra \(v_1 = 0, v_2 = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra:&lt;/strong&gt; Tại \(x^{(0)} = (1, 1)^T\), \(\nabla f(1, 1) = (2, 2)^T = -w A^T\) — điều kiện KKT thỏa mãn chính xác, nên bước Newton trả về \(v = (0, 0)^T\) và xác nhận \((1, 1)^T\) đã là nghiệm tối ưu toàn cục!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
    });
&lt;/script&gt;

&lt;h2 id=&quot;các-bài-toán-thưa-có-cấu-trúc&quot;&gt;Các bài toán thưa, có cấu trúc&lt;/h2&gt;
&lt;p&gt;Nếu hệ phương trình tuyến tính của bước Newton có ma trận thưa hoặc có cấu trúc đặc biệt và ma trận Hessian tính được hiệu quả, ta có thể giải bài toán nhanh hơn đáng kể so với chi phí \(O(n^3)\) tổng quát.&lt;/p&gt;

&lt;p&gt;Chẳng hạn, nếu \(\nabla^{2}f(x)\) là &lt;a href=&quot;https://en.wikipedia.org/wiki/Band_matrix&quot;&gt;ma trận băng&lt;/a&gt; (các phần tử khác không chỉ tập trung quanh đường chéo chính) với mọi \(x\), phương pháp Newton chỉ tốn \(O(n)\) bộ nhớ và \(O(n)\) phép tính mỗi bước.&lt;/p&gt;

&lt;p&gt;Hai ví dụ điển hình về hàm có Hessian có cấu trúc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Nếu \(g(\beta) = f(X\beta)\) thì \(\nabla^{2}g(\beta)=X^{T}\nabla^{2}f(X\beta)X\). Khi \(X\) là ma trận đặc trưng có cấu trúc và \(\nabla^{2}f\) là ma trận đường chéo, \(\nabla^{2}g\) cũng giữ được cấu trúc tương ứng.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Nếu \(\nabla^{2}f\) là ma trận đường chéo và \(g\) không trơn, xét bài toán cực tiểu hóa \(f(\beta)+g(D\beta)\) với ma trận phạt có cấu trúc \(D\). Bài toán đối ngẫu Lagrange có hàm mục tiêu \(-f^{*}(-D^{T}u)-g^{*}(-u)\), khi đó Hessian phần trơn \(-D\nabla^{2}f^{*}(-D^{T}u)D^{T}\) thường cũng có cấu trúc thuận lợi cho tính toán.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;phương-pháp-newton-với-ràng-buộc-đẳng-thức&quot;&gt;Phương pháp Newton với ràng buộc đẳng thức&lt;/h2&gt;
&lt;p&gt;Xét bài toán tối ưu lồi có ràng buộc đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} f(x) &amp;amp; \text{subject to }Ax=b.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nhìn chung, có ba cách tiếp cận chính cho bài toán này:&lt;/p&gt;

&lt;p&gt;1) &lt;strong&gt;Tiếp cận không gian rút gọn (reduced-space)&lt;/strong&gt;: Thu hẹp miền xác định về không gian nghiệm của ràng buộc đẳng thức bằng cách tham số hóa \(x=Fy+x_{0}\), trong đó các cột của \(F\) sinh không gian hạt nhân (null space) của \(A\) và \(Ax_{0}=b\), rồi giải bài toán không ràng buộc theo \(y\).&lt;/p&gt;

&lt;p&gt;2) &lt;strong&gt;Phương pháp Newton có ràng buộc đẳng thức&lt;/strong&gt;: Tương tự phương pháp Newton không ràng buộc nhưng thêm hai yêu cầu: điểm khởi tạo phải khả thi (\(x \in \text{dom}(f)\) và \(Ax = b\)), và hướng Newton \(\Delta x_{nt}\) phải thỏa mãn \(A\Delta x_{nt}=0\). Chi tiết được trình bày ngay dưới đây.&lt;/p&gt;

&lt;p&gt;3) &lt;strong&gt;Tiếp cận đối ngẫu&lt;/strong&gt;: Sử dụng hàm liên hợp (conjugate) \(f^{*}\) để lập bài toán đối ngẫu Fenchel (xem chi tiết tại &lt;a href=&quot;/contents/vi/chapter16/16_03_fenchel_duality/&quot;&gt;16-03&lt;/a&gt;):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
g(v) &amp;amp;= -b^{T}v + \min_{x}(f(x)+v^{T}Ax)\\\\
&amp;amp;= -b^{T}v - \max_{x}\big( (-A^{T}v)^{T}x - f(x) \big)\\\\
&amp;amp;= -b^{T}v - f^{*}(-A^{T}v),
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ đó thu được bài toán đối ngẫu không ràng buộc:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\max -b^{T}v-f^{*}(-A^{T}v). 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Giả sử bài toán có nghiệm tối ưu và khả thi chặt theo điều kiện Slater, khi đó đối ngẫu mạnh thỏa mãn và tồn tại \(v^{*}\) sao cho \(g(v^{*})=p^{*}\) [1, p.525].&lt;/p&gt;

&lt;p&gt;Bây giờ ta xét chi tiết cách tiếp cận thứ hai. Để tìm bước Newton khả thi \(\Delta x_{nt}\), ta thay hàm mục tiêu bằng xấp xỉ bậc hai quanh \(x\) và giữ nguyên ràng buộc đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\text{minimize}\quad &amp;amp;\hat{f}(x+v) = f(x) + \nabla f(x)^{T}v + \frac{1}{2}v^{T}\nabla^{2} f(x) v\\\\
\text{subject to}\quad &amp;amp;A(x+v) = b,
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tương đương, bước cập nhật có dạng:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x^{+} = x + tv,\,\, \text{where}\\\\
v = \underset{A(x+z)=b}{\operatorname{argmin}}\big( f(x)+\nabla f(x)^{T}z+\frac{1}{2}z^{T}\nabla^{2} f(x)z \big)\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì \(Ax^{+} = Ax+tAv = b\), các điểm lặp tiếp theo luôn duy trì tính khả thi với ràng buộc đẳng thức.&lt;/p&gt;

&lt;p&gt;Điều kiện KKT của bài toán con bậc hai trên dẫn tới hệ phương trình tuyến tính sau, cho ta bước Newton \(v = \Delta x_{nt}\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\begin{bmatrix}
\nabla^{2} f(x) &amp;amp; A^{T}\\\\
A &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
v\\\\
w
\end{bmatrix}
=-
\begin{bmatrix}
\nabla f(x)\\\\
Ax-b
\end{bmatrix}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong đó, \(w\) là biến đối ngẫu tối ưu tương ứng với ràng buộc đẳng thức của bài toán con bậc hai trên.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-07 So sánh với phương pháp bậc nhất</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_07_comparison_to_first_order_method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_07_comparison_to_first_order_method</id>
   <content type="html">&lt;p&gt;Nếu phương pháp Newton hội tụ nhanh gấp hàng trăm, hàng nghìn lần Gradient Descent, tại sao ngày nay thế giới học sâu (Deep Learning) vẫn huấn luyện các mô hình tỷ tham số chủ yếu bằng các phương pháp bậc nhất như SGD và Adam? Câu trả lời không nằm ở &lt;em&gt;số vòng lặp&lt;/em&gt;, mà nằm ở &lt;strong&gt;chi phí trên mỗi vòng lặp&lt;/strong&gt; và &lt;strong&gt;bộ nhớ lưu trữ&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Bài học này đặt Phương pháp Newton và Gradient Descent lên bàn cân định lượng theo số chiều \(n\) — từ bộ nhớ, độ phức tạp tính toán mỗi bước, độ nhạy với số điều kiện, cho đến khả năng mở rộng lên bài toán lớn. Hiểu rõ sự đánh đổi này sẽ giúp bạn chọn đúng vũ khí cho từng quy mô bài toán thực tế.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trục-so-sánh-giữa-bậc-nhất-và-bậc-hai&quot;&gt;Kiến thức cần nhớ: Bốn trục so sánh giữa Bậc nhất và Bậc hai&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bộ nhớ lưu trữ:&lt;/strong&gt; Gradient Descent chỉ cần lưu vectơ \(x\) và gradient \(\nabla f(x)\) — tốn \(O(n)\). Phương pháp Newton phải lưu ma trận Hessian \(n \times n\) — tốn \(O(n^2)\). Với \(n = 10^6\) biến, riêng ma trận Hessian đã ngốn hàng terabyte RAM!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí mỗi vòng lặp:&lt;/strong&gt; GD tốn \(O(n)\) (hoặc chi phí tính 1 lần gradient). Newton phải giải hệ tuyến tính \(H v = -g\) — tốn \(O(n^3)\) với ma trận đặc (có thể giảm xuống \(O(n)\) hoặc \(O(n^{1.5})\) nếu Hessian thưa có cấu trúc).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ hội tụ và độ chính xác:&lt;/strong&gt; GD hội tụ tuyến tính (hoặc dưới tuyến tính), rất nhạy với số điều kiện \(\kappa = L/m\); cần \(O(\kappa \log(1/\epsilon))\) bước. Newton hội tụ bậc hai gần nghiệm, bất biến affine, hầu như không phụ thuộc \(\kappa\) và đạt \(\epsilon = 10^{-12}\) chỉ sau 5–15 bước.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc chọn nhanh trong thực hành:&lt;/strong&gt; \(n \le 10^3\)–\(10^4\) và cần độ chính xác cao (tài chính, điều khiển, quy hoạch lồi) → chọn &lt;strong&gt;Newton&lt;/strong&gt;. \(n \ge 10^5\)–\(10^9\) và chỉ cần độ chính xác vừa phải (học sâu, dữ liệu lớn) → chọn &lt;strong&gt;bậc nhất&lt;/strong&gt; (hoặc L-BFGS / xấp xỉ bậc hai).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-toán-chi-phí-thực-tế-bằng-con-số-ở-hai-quy-mô-n--100-và-n--100000&quot;&gt;Giải thích: Tính toán chi phí thực tế bằng con số ở hai quy mô \(n = 100\) và \(n = 100{,}000\)&lt;/h3&gt;

&lt;p&gt;Giả sử bài toán lồi mạnh có số điều kiện xấu \(\kappa = 10^4\) và yêu cầu sai số \(\epsilon = 10^{-8}\).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Số bước GD ước lượng: \(k_{\text{GD}} \approx \kappa \ln(1/\epsilon) \approx 10^4 \times 18.4 \approx 184{,}000\) bước (mỗi bước tốn cỡ \(c_1 n^2\) phép tính nếu có ma trận dữ liệu đặc, hoặc \(O(n)\) cho hàm tách biến; giả sử đơn giản mỗi bước GD tốn \(10n\) phép tính, còn giải Cholesky bước Newton tốn \(\frac{1}{3}n^3\) phép tính).&lt;/li&gt;
  &lt;li&gt;Số bước Newton ước lượng: \(k_{\text{NT}} \approx 15\) bước.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hãy so sánh tổng số phép tính dấu phẩy động (FLOPs):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Ở quy mô nhỏ \(n = 100\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;GD:&lt;/strong&gt; \(184{,}000 \times (10 \times 100) \approx 1.84 \times 10^8\) FLOPs.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Newton:&lt;/strong&gt; \(15 \times \frac{1}{3}(100)^3 = 5 \times 10^6\) FLOPs — &lt;strong&gt;nhanh hơn GD gần 37 lần&lt;/strong&gt;, bộ nhớ Hessian chỉ \(100^2 \times 8\text{ B} = 80\text{ KB}\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ở quy mô lớn \(n = 100{,}000\) (ma trận Hessian đặc):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;GD:&lt;/strong&gt; \(184{,}000 \times (10 \times 10^5) \approx 1.84 \times 10^{11}\) FLOPs (chạy vài giây), bộ nhớ chỉ vài MB.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Newton đặc:&lt;/strong&gt; \(15 \times \frac{1}{3}(10^5)^3 = 5 \times 10^{15}\) FLOPs (chạy hàng ngày!), bộ nhớ Hessian là \((10^5)^2 \times 8\text{ B} = 80\text{ GB}\) RAM — &lt;strong&gt;không khả thi nếu không khai thác độ thưa hoặc dùng Quasi-Newton!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
    });
&lt;/script&gt;

&lt;p&gt;Trong mục này, ta so sánh tổng quát giữa phương pháp Newton và gradient descent trên miền xác định có số chiều \(n\).&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tiêu chí&lt;/th&gt;
      &lt;th&gt;Phương pháp Newton&lt;/th&gt;
      &lt;th&gt;Gradient descent&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Bộ nhớ&lt;/td&gt;
      &lt;td&gt;\(O(n^{2})\) (lưu trữ ma trận Hessian cỡ \(n \times n\))&lt;/td&gt;
      &lt;td&gt;\(O(n)\) (lưu trữ vector gradient \(n\) chiều)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Chi phí tính toán mỗi bước&lt;/td&gt;
      &lt;td&gt;\(O(n^{3})\) phép tính (giải hệ tuyến tính cỡ \(n \times n\))&lt;/td&gt;
      &lt;td&gt;\(O(n)\) phép tính (cộng vector \(n\) chiều)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tìm kiếm đường backtracking&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Độ nhạy với số điều kiện (conditioning)&lt;/td&gt;
      &lt;td&gt;Bất biến affine, không phụ thuộc số điều kiện của hệ tọa độ&lt;/td&gt;
      &lt;td&gt;Chịu ảnh hưởng mạnh bởi số điều kiện&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Độ ổn định triển khai&lt;/td&gt;
      &lt;td&gt;Nhạy cảm hơn với lỗi cài đặt và sai số số học&lt;/td&gt;
      &lt;td&gt;Ổn định hơn phương pháp Newton&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter14/gd(1).jpeg&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Hồi quy logistic [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Hình 1 biểu diễn lại ví dụ hồi quy logistic ở mục &lt;a href=&quot;/contents/vi/chapter14/14_04_backtracking_line_search/&quot;&gt;14-04&lt;/a&gt; nhưng với trục hoành là thời gian tính toán thực tế. Theo phân tích lý thuyết, phương pháp Newton gồm hai giai đoạn: ở giai đoạn giảm chấn ban đầu, mức giảm sai số theo từng bước tương đương gradient descent nhưng chi phí mỗi bước là \(O(n^{3})\) nên thời gian chạy thực tế có thể chậm hơn; khi bước vào giai đoạn thuần túy (backtracking không còn cần thu nhỏ bước), phương pháp đạt hội tụ bậc hai và giảm sai số rất nhanh.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-newton-so-với-gradient-descent&quot;&gt;Tự tay thử: Newton so với gradient descent&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;newton&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>14-06 Tự hài hòa (Self concordance)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_06_self_concordance/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_06_self_concordance</id>
   <content type="html">&lt;p&gt;Định lý hội tụ ở mục 14-05 rất ấn tượng, nhưng lại mang trong mình một “nghịch lý thẩm mỹ” khiến các nhà toán học tối ưu hồi cuối thế kỷ 20 trăn trở mãi không yên: &lt;strong&gt;bản thân phương pháp Newton hoàn toàn bất biến affine&lt;/strong&gt;, thế nhưng cận hội tụ ở mục 14-05 lại phụ thuộc vào ba hằng số \(m, L, M\) vốn &lt;strong&gt;thay đổi loạn xạ&lt;/strong&gt; khi ta đổi hệ tọa độ! Hơn nữa, nhiều hàm cực kỳ quan trọng trong thực tế — tiêu biểu là hàm chắn logarit \(-\log x\) — thậm chí còn &lt;strong&gt;không&lt;/strong&gt; có hằng số Lipschitz toàn cục \(L\) hay \(M\) hữu hạn gần biên \(x \to 0^+\)!&lt;/p&gt;

&lt;p&gt;Chính nghịch lý này đã thúc đẩy Yurii Nesterov và Arkadi Nemirovskii (1994) tạo ra một bước ngoặt lịch sử: lý thuyết &lt;strong&gt;hàm tự hài hòa (self-concordant functions)&lt;/strong&gt;. Thay vì đo tốc độ thay đổi của đạo hàm bậc ba theo chuẩn Euclid cố định, họ đo nó &lt;em&gt;tương đối theo chính độ cong bậc hai của hàm&lt;/em&gt;, mở ra một phân tích hội tụ hoàn toàn bất biến affine và đặt viên gạch nền móng cho toàn bộ lý thuyết phương pháp điểm trong hiện đại.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-vì-sao-cần-lý-thuyết-hàm-tự-hài-hòa&quot;&gt;Kiến thức cần nhớ: Vì sao cần lý thuyết hàm tự hài hòa?&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hai lỗ hổng của phân tích cổ điển (\(m, L, M\)):&lt;/strong&gt; (1) Các hằng số \(m, L, M\) hầu như không thể tính trước trong thực tế và phụ thuộc hệ tọa độ; (2) Các hàm có tiệm cận đứng như \(-\log x\) bị nổ đạo hàm cấp hai và cấp ba gần biên, nên phân tích cổ điển hoàn toàn bất lực.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Triết lý “tự đo bằng thước của chính mình”:&lt;/strong&gt; Một hàm là tự hài hòa nếu đạo hàm bậc ba bị chặn bởi lũy thừa \(3/2\) của đạo hàm bậc hai: \(\vert f&apos;&apos;&apos;(x) \vert \le 2 (f&apos;&apos;(x))^{3/2}\). Khi tiến sát biên \(x \to 0^+\), cả \(f&apos;&apos;&apos;\) và \(f&apos;&apos;\) cùng bùng nổ nhưng tỷ số \(\vert f&apos;&apos;&apos; \vert / (f&apos;&apos;)^{3/2}\) vẫn giữ nguyên hằng số \(2\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối sang Chương 15 (Phương pháp chắn):&lt;/strong&gt; Mọi hàm chắn logarit của quy hoạch tuyến tính, bậc hai và nửa xác định đều là hàm tự hài hòa, nhờ đó ta có cận độ phức tạp thời gian đa thức hoàn toàn độc lập với hệ tọa độ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-thấy-tận-mắt-sự-sụp-đổ-của-hằng-số-m-và-chiến-thắng-của-tỷ-số-tự-hài-hòa-trên-fx---log-x&quot;&gt;Giải thích: Thấy tận mắt sự sụp đổ của hằng số \(M\) và chiến thắng của tỷ số tự hài hòa trên \(f(x) = -\log x\)&lt;/h3&gt;

&lt;p&gt;Xét hàm \(f(x) = -\log x\) trên miền \(x &amp;gt; 0\) tại hai điểm: \(x = 1\) và \(x = 0.01\) (gần biên).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính các đạo hàm:&lt;/strong&gt;
\(f&apos;(x) = -\frac{1}{x}, \qquad f&apos;&apos;(x) = \frac{1}{x^2}, \qquad f&apos;&apos;&apos;(x) = -\frac{2}{x^3}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử góc nhìn cổ điển (\(m, L, M\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(x = 1\): \(f&apos;&apos;(1) = 1\), \(\vert f&apos;&apos;&apos;(1) \vert = 2\).&lt;/li&gt;
      &lt;li&gt;Tại \(x = 0.01\): \(f&apos;&apos;(0.01) = 10^4\), \(\vert f&apos;&apos;&apos;(0.01) \vert = 2 \times 10^6\)!
Khi \(x \to 0^+\), hằng số Lipschitz \(M = \sup \vert f&apos;&apos;&apos;(x) \vert = +\infty\) — định lý cổ điển ở mục 14-05 không áp dụng được!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử góc nhìn tự hài hòa — tính tỷ số \(\frac{\vert f&apos;&apos;&apos;(x) \vert}{(f&apos;&apos;(x))^{3/2}}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(x = 1\): \(\frac{2}{1^{3/2}} = 2\).&lt;/li&gt;
      &lt;li&gt;Tại \(x = 0.01\): \(\frac{2 \times 10^6}{(10^4)^{3/2}} = \frac{2 \times 10^6}{10^6} = 2\)!&lt;/li&gt;
      &lt;li&gt;Tổng quát với mọi \(x &amp;gt; 0\): \(\frac{2/x^3}{(1/x^2)^{3/2}} = \frac{2/x^3}{1/x^3} = 2\) — &lt;strong&gt;một hằng số bất biến tuyệt đối trên toàn miền \((0, +\infty)\)!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phân tích hội tụ ở mục trước cho phương pháp Newton tồn tại hai hạn chế chính [1].&lt;/p&gt;

&lt;p&gt;Thứ nhất, trong thực tế rất khó xác định các hằng số xuất hiện trong cận hội tụ như hằng số Lipschitz \(L\) của gradient, tham số lồi mạnh \(m\) hay hằng số Lipschitz \(M\) của Hessian. Vì vậy, dù lý thuyết khẳng định tốc độ hội tụ, ta hầu như không thể tính trước số bước Newton cần thiết cho một bài toán cụ thể.&lt;/p&gt;

&lt;p&gt;Thứ hai, bản thân phương pháp Newton bất biến affine, nhưng phân tích hội tụ cổ điển lại không bất biến affine. Với hàm tổng quát, các hằng số \(L, m, M\) thay đổi theo phép biến đổi tọa độ.&lt;/p&gt;

&lt;p&gt;Vì hai lý do trên, mục này giới thiệu lớp &lt;strong&gt;hàm tự hài hòa (self-concordant functions)&lt;/strong&gt; nhằm khắc phục cả hai hạn chế.&lt;/p&gt;

&lt;p&gt;Các hàm tự hài hòa có vai trò quan trọng vì ba lý do:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Các hàm chắn logarit dùng trong phương pháp điểm trong đều là hàm tự hài hòa (khi các ràng buộc bất đẳng thức là hàm affine hoặc bậc hai lồi).&lt;/li&gt;
  &lt;li&gt;Phân tích hội tụ của phương pháp Newton cho hàm tự hài hòa không phụ thuộc vào các hằng số khó ước lượng như \(L, m, M\).&lt;/li&gt;
  &lt;li&gt;Tính tự hài hòa bất biến affine, nghĩa là cận số vòng lặp Newton không phụ thuộc vào phép biến đổi affine của hệ tọa độ.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>14-06-02 Phân tích hội tụ cho các hàm tự hài hòa</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_06_02_convergence_analysis_for_self_concordant_functions/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_06_02_convergence_analysis_for_self_concordant_functions</id>
   <content type="html">&lt;p&gt;Đây chính là phần thưởng lớn nhất của khái niệm tự hài hòa: một định lý hội tụ &lt;strong&gt;không còn bóng dáng của \(m, L, M\)&lt;/strong&gt;, không phụ thuộc số chiều \(n\), không phụ thuộc số điều kiện của bài toán, và hoàn toàn bất biến affine!&lt;/p&gt;

&lt;p&gt;Định lý Nesterov–Nemirovskii khẳng định rằng với mọi hàm tự hài hòa, phương pháp Newton có giảm chấn chỉ cần tối đa \(C(\alpha, \beta)\bigl(f(x^{(0)}) - f^\star\bigr) + \log_2\log_2(1/\epsilon)\) vòng lặp. Toàn bộ độ phức tạp chỉ còn nằm ở đúng hai đại lượng mang ý nghĩa vật lý rõ ràng: khoảng cách hàm ban đầu \(f(x^{(0)}) - f^\star\) và độ chính xác yêu cầu \(\epsilon\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-đọc-hiểu-định-lý-nesterovnemirovskii&quot;&gt;Kiến thức cần nhớ: Đọc hiểu định lý Nesterov–Nemirovskii&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc hai số hạng quen thuộc nhưng sạch hằng số ẩn:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Số hạng thứ nhất \(C(\alpha, \beta)(f(x^{(0)}) - f^\star)\) đếm số bước ở giai đoạn giảm chấn, trong đó hằng số \(C(\alpha, \beta)\) &lt;strong&gt;chỉ phụ thuộc duy nhất vào hai tham số backtracking \(\alpha, \beta\)&lt;/strong&gt; mà bạn tự chọn!&lt;/li&gt;
      &lt;li&gt;Số hạng thứ hai \(\log_2\log_2(1/\epsilon)\) đếm số bước ở giai đoạn hội tụ bậc hai (khi \(\lambda(x) &amp;lt; \eta\), thường \(\eta = 1/4\) hoặc \(0.25\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chứng chỉ dừng trực tiếp từ Newton decrement:&lt;/strong&gt; Với hàm tự hài hòa, khi \(\lambda(x) \le 0.68\) (hoặc \(\lambda(x) &amp;lt; 1\)), ta có chặn trên &lt;strong&gt;tuyệt đối, không cần biết \(m\)&lt;/strong&gt;:
\(f(x) - f^\star \le \lambda(x)^2 \quad (\text{khi } \lambda(x) \le 0.68).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại sao định lý này làm thay đổi ngành tối ưu:&lt;/strong&gt; Nhờ không chứa \(m, L, M\), định lý cho phép chứng minh phương pháp điểm trong giải được LP, QP, SOCP và SDP trong thời gian đa thức được đảm bảo chặt chẽ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-cụ-thể-cận-số-vòng-lặp-với-tham-số-backtracking-chuẩn&quot;&gt;Giải thích: Tính cụ thể cận số vòng lặp với tham số backtracking chuẩn&lt;/h3&gt;

&lt;p&gt;Trong sách của Boyd &amp;amp; Vandenberghe (Chương 9.6), hằng số trong định lý hội tụ hàm tự hài hòa có thể viết tường minh là:
\(C(\alpha, \beta) = \frac{20 - 8\alpha}{\alpha\beta(1 - 2\alpha)^2} \quad \text{(hoặc cận chặt hơn cỡ } \frac{1}{\gamma}\text{ với } \gamma = \alpha\beta\frac{\eta^2}{1+\eta}\text{)}.\)&lt;/p&gt;

&lt;p&gt;Hãy thử thay giá trị thực tế phổ biến \(\alpha = 0.2\), \(\beta = 0.5\) và ngưỡng chuyển pha \(\eta = 0.25\) (từ lý thuyết tự hài hòa):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính mức giảm tối thiểu \(\gamma\) mỗi bước ở pha giảm chấn (khi \(\lambda(x) \ge \eta = 0.25\)):&lt;/strong&gt;
\(\gamma = \alpha\beta \frac{\eta^2}{1 + \eta} = (0.2)(0.5)\frac{0.0625}{1.25} = 0.1 \times 0.05 = 0.005.\)
Suy ra hằng số \(1/\gamma = 200\) (cận lý thuyết trường hợp xấu nhất; thực tế thường nhanh hơn 10–20 lần).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính cận số vòng lặp khi \(f(x^{(0)}) - f^\star = 1.5\) và \(\epsilon = 10^{-10}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Pha giảm chấn: tối đa \(\frac{1.5}{0.005} = 300\) bước (trong thực tế thường chỉ mất 3–8 bước).&lt;/li&gt;
      &lt;li&gt;Pha bậc hai: \(\log_2\log_2(10^{10}) \approx \log_2(33.2) \approx 5.05 \implies 6\) bước.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm quan trọng nhất cần nhớ:&lt;/strong&gt; Nếu bạn nhân trục tọa độ lên \(1{,}000{,}000\) lần (làm số điều kiện \(L/m\) phình lên \(10^{12}\)), cận của Gradient Descent phình lên \(10^{12}\) lần, còn cận tự hài hòa ở trên &lt;strong&gt;không nhúc nhích dù chỉ 1 vòng lặp!&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Đối với các hàm tự hài hòa, kết quả phân tích hội tụ của phương pháp Newton có dạng:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Định lý (Nesterov và Nemirovskii): Phương pháp Newton với tìm kiếm đường backtracking cần tối đa số vòng lặp sau để đạt được \(f(x^{(k)})-f^{\star}\leq \epsilon\):
\begin{align}
C(\alpha, \beta)\big( f(x^{(0)})-f^{\star} \big) + \log\log{(1/\epsilon)},
\end{align}
trong đó \(C(\alpha, \beta)\) là hằng số chỉ phụ thuộc vào hai tham số backtracking \(\alpha, \beta\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Chứng minh định lý này có cấu trúc tương tự phân tích hội tụ tổng quát của phương pháp Newton, nhưng khai thác các tính chất của hàm tự hài hòa để loại bỏ sự phụ thuộc vào các hằng số \(L, m, M\) (xem [1], tr. 503).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-06-01 Định nghĩa các hàm tự hài hòa</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_06_01_definition_of_self_concordant_functions/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_06_01_definition_of_self_concordant_functions</id>
   <content type="html">&lt;p&gt;Nhìn thoáng qua bất đẳng thức định nghĩa hàm tự hài hòa \(\vert f&apos;&apos;&apos;(x) \vert \le 2 (f&apos;&apos;(x))^{3/2}\), nhiều người tự hỏi: &lt;em&gt;số mũ \(3/2\) kỳ lạ kia từ đâu chui ra, và tại sao hằng số phía trước lại là số \(2\)?&lt;/em&gt; Không hề ngẫu nhiên chút nào! Số mũ \(3/2\) là số mũ &lt;strong&gt;duy nhất&lt;/strong&gt; làm cho bất đẳng thức hoàn toàn bất biến dưới phép co giãn trục \(x \mapsto \alpha x\), còn hằng số \(2\) được chuẩn hóa khớp vừa khít với hàm chắn logarit cơ bản nhất \(f(x) = -\log x\).&lt;/p&gt;

&lt;p&gt;Và để mở rộng từ trục thực \(\mathbb{R}\) sang không gian nhiều chiều \(\mathbb{R}^n\) mà không phải vật lộn với ten-xơ đạo hàm bậc ba phức tạp, định nghĩa dùng một thủ thuật cực kỳ thanh lịch: một hàm nhiều biến \(f(x)\) là tự hài hòa nếu lát cắt của nó dọc theo &lt;strong&gt;mọi đường thẳng&lt;/strong&gt; \(g(t) = f(x + tv)\) đều là hàm tự hài hòa 1 chiều!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cấu-trúc-đại-số-và-quy-tắc-bảo-toàn-tính-tự-hài-hòa&quot;&gt;Kiến thức cần nhớ: Cấu trúc đại số và quy tắc bảo toàn tính tự hài hòa&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa của số mũ \(3/2\):&lt;/strong&gt; Nếu đổi biến \(h(t) = f(\alpha t)\), thì \(h&apos;&apos;(t) = \alpha^2 f&apos;&apos;(\alpha t)\) và \(h&apos;&apos;&apos;(t) = \alpha^3 f&apos;&apos;&apos;(\alpha t)\). Ta thấy \(\vert h&apos;&apos;&apos; \vert / (h&apos;&apos;)^{3/2} = \vert \alpha^3 f&apos;&apos;&apos; \vert / (\alpha^2 f&apos;&apos;)^{3/2} = \vert f&apos;&apos;&apos; \vert / (f&apos;&apos;)^{3/2}\) — tham số \(\alpha\) triệt tiêu hoàn toàn!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mở rộng sang \(\mathbb{R}^n\) qua lát cắt 1D:&lt;/strong&gt; \(f: \mathbb{R}^n \to \mathbb{R}\) tự hài hòa khi và chỉ khi với mọi \(x \in \operatorname{dom} f\) và mọi hướng \(v \in \mathbb{R}^n\), hàm \(g(t) = f(x + tv)\) tự hài hòa trên \(\mathbb{R}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các phép toán bảo toàn tính tự hài hòa:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tổng của các hàm tự hài hòa là hàm tự hài hòa.&lt;/li&gt;
      &lt;li&gt;Phép hợp với ánh xạ affine \(f(Ax + b)\) luôn giữ nguyên tính tự hài hòa.&lt;/li&gt;
      &lt;li&gt;Nhân một hàm tự hài hòa với hằng số \(c \ge 1\) giữ nguyên tính tự hài hòa (còn nếu \(0 &amp;lt; c &amp;lt; 1\) thì có thể phá vỡ bất đẳng thức vì vế trái nhân \(c\) còn vế phải nhân \(c^{3/2} &amp;lt; c\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các hàm tự hài hòa tiêu biểu:&lt;/strong&gt; Mọi hàm tuyến tính, hàm bậc hai lồi (\(f&apos;&apos;&apos; = 0\)), hàm \(-\log x\), hàm \(-\sum \log(b_i - a_i^T x)\), và \(-\log\det X\) trên nón ma trận xác định dương.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-tra-trực-tiếp-hai-hàm--một-hàm-tự-hài-hòa-và-một-hàm-không-tự-hài-hòa&quot;&gt;Giải thích: Kiểm tra trực tiếp hai hàm — một hàm tự hài hòa và một hàm KHÔNG tự hài hòa&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra \(f(x) = -\log(x) + 3x^2 - 5x\) trên \(x &amp;gt; 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;&apos;(x) = \frac{1}{x^2} + 6 &amp;gt; \frac{1}{x^2}\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;&apos;(x) = -\frac{2}{x^3} \implies \vert f&apos;&apos;&apos;(x) \vert = \frac{2}{x^3}\).&lt;/li&gt;
      &lt;li&gt;So sánh với \(2(f&apos;&apos;(x))^{3/2}\):
\(2(f&apos;&apos;(x))^{3/2} = 2\left(\frac{1}{x^2} + 6\right)^{3/2} &amp;gt; 2\left(\frac{1}{x^2}\right)^{3/2} = \frac{2}{x^3} = \vert f&apos;&apos;&apos;(x) \vert.\)
Bất đẳng thức thỏa mãn tại mọi \(x &amp;gt; 0\) → &lt;strong&gt;tự hài hòa!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra \(h(x) = e^x\) trên \(\mathbb{R}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(h&apos;&apos;(x) = e^x\), \(h&apos;&apos;&apos;(x) = e^x\).&lt;/li&gt;
      &lt;li&gt;Xét tỷ số: \(\frac{\vert h&apos;&apos;&apos;(x) \vert}{(h&apos;&apos;(x))^{3/2}} = \frac{e^x}{e^{3x/2}} = e^{-x/2}\).&lt;/li&gt;
      &lt;li&gt;Khi \(x = -4\), tỷ số bằng \(e^2 \approx 7.39 &amp;gt; 2\) (và khi \(x \to -\infty\), tỷ số vọt lên \(+\infty\)).
→ \(e^x\) &lt;strong&gt;KHÔNG&lt;/strong&gt; tự hài hòa trên \(\mathbb{R}\)! (Tuy nhiên \(e^x - \log x\) hay \(e^x\) trên nửa trục bị chặn dưới có thể xử lý bằng cách cộng thêm số hạng chắn hoặc giới hạn miền).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
    });
&lt;/script&gt;

&lt;h2 id=&quot;tự-hài-hòa-trên-mathbbr&quot;&gt;Tự hài hòa trên \(\mathbb{R}\)&lt;/h2&gt;
&lt;p&gt;Một hàm lồi \(f : \mathbb{R} \rightarrow \mathbb{R}\) được gọi là &lt;strong&gt;tự hài hòa (self-concordant)&lt;/strong&gt; nếu nó thỏa mãn bất đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
|f^{&apos;&apos;&apos;}(x)| \leq 2f^{&apos;&apos;}(x)^{3/2} \qquad \text{for all }x\in \text{dom }f.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ví dụ đơn giản: mọi hàm tuyến tính (\(ax+b\)) và hàm bậc hai lồi đều là hàm tự hài hòa vì đạo hàm bậc ba của chúng bằng \(0\).&lt;/p&gt;

&lt;h2 id=&quot;tự-hài-hòa-trên-mathbbrn&quot;&gt;Tự hài hòa trên \(\mathbb{R}^{n}\)&lt;/h2&gt;
&lt;p&gt;Một hàm \(f : \mathbb{R}^{n}\rightarrow \mathbb{R}\) được gọi là tự hài hòa nếu nó tự hài hòa dọc theo mọi đường thẳng cắt miền xác định của nó. Cụ thể, với mọi \(x\in \text{dom}\, f\) và mọi vector \(v\), nếu hàm một biến \(g(t) = f(x+tv)\) là tự hài hòa thì \(f\) là hàm tự hài hòa trên \(\mathbb{R}^{n}\).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-về-hàm-tự-hài-hòa&quot;&gt;Ví dụ về hàm tự hài hòa&lt;/h2&gt;

&lt;p&gt;1) \(f : \mathbb{R}^{n}_{++}\rightarrow \mathbb{R}\), \(f(x) = -\sum^{n}_{i=1}\log(x_{i})\).&lt;/p&gt;

&lt;p&gt;Ta có thể dễ dàng kiểm tra rằng hàm một biến \(f(t) = -\log{t}\) là tự hài hòa. Hơn nữa, tổng của các hàm tự hài hòa cũng là hàm tự hài hòa: với hai hàm tự hài hòa \(f_{1}, f_{2} : \mathbb{R}\rightarrow \mathbb{R}\), ta có [3]:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
|f_{1}^{&apos;&apos;&apos;}(x)+f_{2}^{&apos;&apos;&apos;}(x)|  \leq &amp;amp; |f^{&apos;&apos;&apos;}_{1}(x)|+|f^{&apos;&apos;&apos;}_{2}(x)|\\\\
\leq &amp;amp;2\big( f^{&apos;&apos;}_{1}(x)^{3/2}+f^{&apos;&apos;}_{2}(x)^{3/2}\big)\\\\
\leq &amp;amp;2\big( f^{&apos;&apos;}_{1}(x)+f^{&apos;&apos;}_{2}(x) \big)^{3/2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bước cuối sử dụng bất đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
(u^{3/2}+v^{3/2})^{2/3} \leq u+v, \qquad u, v \geq 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;góc-nhìn-nesterov-tự-tương-hợp-và-phương-pháp-newton-điều-chỉnh-bậc-ba-cubic-newton&quot;&gt;Góc nhìn Nesterov: Tự tương hợp và Phương pháp Newton Điều chỉnh Bậc ba (Cubic Newton)&lt;/h2&gt;

&lt;p&gt;Trong &lt;em&gt;Lectures on Convex Optimization&lt;/em&gt; (Chương 4), Nesterov phân tích hạn chế của định lý hội tụ Newton cổ điển (phụ thuộc vào các hằng số \(m, L\) chưa biết và không bất biến afin). Bên cạnh khung &lt;strong&gt;tự tương hợp (self-concordance)&lt;/strong&gt; dùng cho phương pháp điểm trong, Nesterov đề xuất &lt;strong&gt;Điều chỉnh Bậc ba (Cubic Regularization of Newton’s Method)&lt;/strong&gt;:
\(x_{k+1} = \arg\min_{y \in \mathbb{R}^n} \left\{ f(x_k) + \langle \nabla f(x_k), y - x_k \rangle + \frac{1}{2} \langle \nabla^2 f(x_k)(y - x_k), y - x_k \rangle + \frac{M}{6} \|y - x_k\|_2^3 \right\}.\)
Phiên bản gia tốc (&lt;em&gt;Accelerated Cubic Newton&lt;/em&gt;) đạt tốc độ toàn cục &lt;strong&gt;\(O(1/k^3)\)&lt;/strong&gt; cho hàm lồi có Hessian Lipschitz liên tục, nhanh hơn hẳn ngưỡng \(O(1/k^2)\) của phương pháp bậc nhất.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-05 Phân tích hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_05_convergence_analysis/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_05_convergence_analysis</id>
   <content type="html">&lt;p&gt;Khi ghép phương pháp Newton với tìm kiếm đường backtracking, một câu hỏi lớn đặt ra cho lý thuyết hội tụ: &lt;em&gt;liệu ta có thể đảm bảo thuật toán hội tụ từ MỌI điểm xuất phát \(x^{(0)}\), và tổng số vòng lặp để đạt sai số \(\epsilon\) là bao nhiêu?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Câu trả lời là một trong những định lý đẹp nhất của tối ưu lồi cổ điển: hành trình của Newton có giảm chấn luôn chia làm &lt;strong&gt;hai giai đoạn tách biệt rõ ràng&lt;/strong&gt;. Trong &lt;strong&gt;giai đoạn giảm chấn (damped phase)&lt;/strong&gt; khi gradient còn lớn, mỗi vòng lặp đảm bảo cắt giảm giá trị hàm mục tiêu ít nhất một hằng số dương \(\gamma\) (hội tụ tuyến tính chắc chắn). Ngay khi gradient tụt xuống dưới một ngưỡng tới hạn \(\eta\), thuật toán bước vào &lt;strong&gt;giai đoạn thuần túy (pure phase)&lt;/strong&gt; — bước \(t = 1\) luôn được chấp nhận và sai số rơi theo hàm mũ kép \(2^{2^k}\), nghĩa là chỉ cần thêm \(\log_2\log_2(1/\epsilon)\) vòng lặp (thực tế hầu như không bao giờ quá 6 bước!) để đạt độ chính xác máy tính.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-hai-giai-đoạn-hội-tụ-toàn-cục-của-newton&quot;&gt;Kiến thức cần nhớ: Giải phẫu hai giai đoạn hội tụ toàn cục của Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ba giả thiết tiêu chuẩn:&lt;/strong&gt; Hàm \(f\) khả vi hai lần, lồi mạnh với tham số \(m &amp;gt; 0\) (\(\nabla^2 f(x) \succeq mI\)), gradient Lipschitz \(L\) (\(\nabla^2 f(x) \preceq LI\)), và Hessian Lipschitz \(M\) (\(\|\nabla^2 f(x) - \nabla^2 f(y)\|_2 \le M\|x-y\|_2\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pha 1 — Giai đoạn giảm chấn (\(\|\nabla f(x)\|_2 \ge \eta\)):&lt;/strong&gt; Thuật toán có thể cần \(t &amp;lt; 1\), nhưng mỗi vòng lặp luôn giảm \(f(x)\) ít nhất một lượng hằng số \(\gamma &amp;gt; 0\). Do đó số vòng lặp ở Pha 1 bị chặn trên bởi \(\frac{f(x^{(0)}) - f^\star}{\gamma}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pha 2 — Giai đoạn thuần túy (\(\|\nabla f(x)\|_2 &amp;lt; \eta\)):&lt;/strong&gt; Ngay khi vượt ngưỡng \(\eta\), bước \(t = 1\) luôn thỏa Armijo và sai số giảm bình phương sau mỗi bước, nên chỉ cần thêm tối đa \(\log_2\log_2(\epsilon_0/\epsilon)\) vòng lặp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa thực tế của \(\log_2\log_2(1/\epsilon)\):&lt;/strong&gt; Ngay cả khi bạn đòi hỏi độ chính xác cực khắt khe \(\epsilon = 10^{-15}\), giá trị \(\log_2\log_2(10^{15}) \approx \log_2(50) \approx 5.6\) — tức là một khi đã vào vùng bậc hai, &lt;strong&gt;tối đa 6 bước Newton là xong!&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-đếm-số-vòng-lặp-qua-từng-pha-bằng-con-số-cụ-thể&quot;&gt;Giải thích: Đếm số vòng lặp qua từng pha bằng con số cụ thể&lt;/h3&gt;

&lt;p&gt;Giả sử một bài toán lồi mạnh có giá trị ban đầu \(f(x^{(0)}) - f^\star = 20\), mức giảm đảm bảo mỗi bước ở Pha 1 là \(\gamma = 2\), và ngưỡng chuyển pha tương ứng sai số mục tiêu \(\epsilon_0 = 0.5\). Hãy tính tổng số vòng lặp tối đa để đạt hai mức độ chính xác khác nhau: \(\epsilon = 10^{-4}\) và \(\epsilon = 10^{-16}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Số vòng lặp ở Pha 1 (giảm chấn):&lt;/strong&gt;
\(k_1 \le \frac{f(x^{(0)}) - f^\star}{\gamma} = \frac{20}{2} = 10 \text{ bước}.\)
Lưu ý \(k_1\) &lt;strong&gt;không hề phụ thuộc vào \(\epsilon\)&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số vòng lặp ở Pha 2 (hội tụ bậc hai) khi \(\epsilon = 10^{-4}\):&lt;/strong&gt;
Ta cần \(k_2 \approx \log_2\log_2\left(\frac{0.5}{10^{-4}}\right) = \log_2\log_2(5000) \approx \log_2(12.29) \approx 3.62 \implies 4 \text{ bước}.\)
Tổng: \(10 + 4 = 14\) bước.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số vòng lặp ở Pha 2 khi siết chặt sai số lên gấp một nghìn tỷ lần (\(\epsilon = 10^{-16}\)):&lt;/strong&gt;
Ta cần \(k_2 \approx \log_2\log_2\left(\frac{0.5}{10^{-16}}\right) = \log_2\log_2(5 \times 10^{15}) \approx \log_2(52.15) \approx 5.70 \implies 6 \text{ bước}.\)
Tổng: \(10 + 6 = 16\) bước!
&lt;strong&gt;So sánh ấn tượng:&lt;/strong&gt; Để tăng độ chính xác từ \(10^{-4}\) lên \(10^{-16}\) (tốt hơn \(10^{12}\) lần!), phương pháp Newton chỉ cần thêm đúng &lt;strong&gt;2 vòng lặp&lt;/strong&gt;, trong khi Gradient Descent cần tăng gấp &lt;strong&gt;4 lần&lt;/strong&gt; số vòng lặp!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
    });
&lt;/script&gt;

&lt;p&gt;Đến đây, ta đã xét phương pháp Newton thuần túy (chỉ đảm bảo hội tụ cục bộ) và phương pháp Newton có giảm chấn (kết hợp tìm kiếm đường backtracking nhằm đảm bảo hội tụ toàn cục với hàm lồi).&lt;/p&gt;

&lt;p&gt;Mục này phân tích tốc độ hội tụ của phương pháp Newton có giảm chấn. Cận hội tụ được tách thành hai giai đoạn: giai đoạn cần thu nhỏ bước bằng backtracking (giai đoạn giảm chấn, tiến bộ chậm hơn) và giai đoạn hội tụ cục bộ khi backtracking luôn chấp nhận \(t = 1\) (giai đoạn thuần túy, hội tụ bậc hai).&lt;/p&gt;

&lt;h2 id=&quot;các-điều-kiện-của-f-cho-phân-tích-hội-tụ&quot;&gt;Các điều kiện của \(f\) cho phân tích hội tụ&lt;/h2&gt;
&lt;p&gt;Giả sử \(f\) lồi, khả vi hai lần, có \(\text{dom}(f)=\mathbb{R}^{n}\) và thỏa mãn ba điều kiện sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;\(\nabla f\) liên tục Lipschitz với hằng số \(L\):
    &lt;blockquote&gt;
\[\begin{align}
\|\nabla f(x) - \nabla f(y)\|_{2} \leq L\|x-y\|_{2} \quad \forall x,y.
\end{align}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;\(f\) lồi mạnh với tham số \(m\) (xem thêm quan hệ giữa cận trên \(L\) và tính liên tục Lipschitz tại &lt;a href=&quot;https://xingyuzhou.org/blog/notes/strong-convexity&quot;&gt;nguồn&lt;/a&gt;, &lt;a href=&quot;/contents/vi/chapter06/06_03_05_look_at_the_conditions_and_practicalities/&quot;&gt;giáo trình này: 06-03-05&lt;/a&gt;):
    &lt;blockquote&gt;
\[\begin{align}
mI\preceq\nabla^{2}f(x)\preceq LI.
\end{align}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;\(\nabla^{2} f\) liên tục Lipschitz với hằng số \(M\):
    &lt;blockquote&gt;
\[\begin{align}
\|\nabla^{2}f(x)-\nabla^{2}f(y)\|_{2} \leq M\|x-y\|_{2} \quad \forall x,y.
\end{align}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;phân-tích-hội-tụ&quot;&gt;Phân tích hội tụ&lt;/h2&gt;
&lt;p&gt;Khi ba điều kiện trên được thỏa mãn, tồn tại \(\eta, \gamma\) với \(0&amp;lt;\eta \leq m^{2}/M\) và \(\gamma&amp;gt;0\) sao cho ở mỗi giai đoạn ta có:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Giai đoạn I: Giai đoạn “giảm chấn” (damped), \(\|\nabla f(x^{(k)})\|_{2} \geq \eta\),&lt;/p&gt;

\[\begin{align}
f(x^{(k+1)})-f(x^{(k)}) \leq -\gamma
\end{align}\]

  &lt;p&gt;Giai đoạn II: Giai đoạn “thuần túy” (pure), \(\|\nabla f(x^{(k)})\|_{2}&amp;lt;\eta\), backtracking chọn \(t = 1\):&lt;/p&gt;

\[\begin{align}
\frac{M}{2m^{2}}\|\nabla f(x^{(k+1)})\|_{2} \leq \bigg( \frac{M}{2m^{2}}\|\nabla f(x^{(k)})\|_{2} \bigg)^{2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Lưu ý rằng một khi thuật toán bước vào giai đoạn thuần túy — tức điều kiện \(\|\nabla f(x^{(k)})\|_{2}&amp;lt;\eta\) lần đầu được thỏa mãn tại vòng lặp \(k\) — thì điều kiện này tiếp tục được giữ nguyên ở mọi vòng lặp sau đó.&lt;/p&gt;

&lt;h2 id=&quot;phân-tích-hội-tụ-theo-giá-trị-tối-ưu&quot;&gt;Phân tích hội tụ theo giá trị tối ưu&lt;/h2&gt;
&lt;p&gt;Tiếp theo, ta biểu diễn cận hội tụ của từng giai đoạn theo hiệu so với giá trị tối ưu \(f^{\star}\).&lt;/p&gt;

&lt;p&gt;Với Giai đoạn I, cộng dồn bất đẳng thức qua \(k\) vòng lặp từ \(x^{(0)}\), ta thu được:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\require{cancel}
&amp;amp; &amp;amp;\cancel{f(x^{(1)})}-f(x^{(0)}) \leq -\gamma \\\\
&amp;amp; &amp;amp;\cancel{f(x^{(2)})}-\cancel{f(x^{(1)})} \leq -\gamma \\\\
&amp;amp; &amp;amp;\vdots \\\\
&amp;amp;+ &amp;amp;f(x^{(k)})-\cancel{f(x^{(k-1)})} \leq -\gamma \\\\
&amp;amp;= &amp;amp;f(x^{(k)})-f(x^{(0)})\leq -k\gamma.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trừ \(f^{\star}\) ở cả hai vế và gọi \(k_{0}\) là chỉ số đầu tiên thỏa mãn \(\|\nabla f(x^{(k)})\|_{2}&amp;lt;\eta\) (các bước \(k \le k_0\) thuộc giai đoạn giảm chấn):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)})-f^{\star} \leq (f(x^{(0)})-f^{\star})-\gamma k \qquad \text{if }k \leq k_{0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Với Giai đoạn II, xét \(k - k_{0}\) bước kể từ \(k_{0}\). Đặt \(a_k = \frac{M}{2m^{2}}\|\nabla f(x^{(k)})\|_{2}\). Từ \(\|\nabla f(x^{(k_0)})\|_2 &amp;lt; \eta \leq m^{2}/M\) ta có \(a_{k_0} \leq \frac{1}{2}\), nên:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;a_{k+1} \leq a_{k}^{2}\\\\
&amp;amp;\Rightarrow &amp;amp;a_{k} \leq a_{k_0}^{2^{k-k_{0}}} \leq \Big(\frac{1}{2}\Big)^{2^{k-k_{0}}}\\\\
&amp;amp;\Rightarrow &amp;amp;\|\nabla f(x^{(k)})\|_{2} \leq \frac{2m^{2}}{M}\Big(\frac{1}{2}\Big)^{2^{k-k_{0}}}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nhờ tính lồi mạnh, \(f(y)\geq f(x)+\nabla f(x)^{T}(y-x)+\frac{m}{2}\|y-x\|^{2}_{2}\geq f(x)-\frac{1}{2m}\|\nabla f(x)\|^{2}_{2}\) với mọi \(y\), suy ra:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)})-f^{\star} \leq \frac{1}{2m}\|\nabla f(x^{(k)})\|_{2}^{2}\leq \frac{2m^{3}}{M^{2}}\Big(\frac{1}{2}\Big)^{2^{k-k_{0}+1}}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Gộp hai giai đoạn với mốc chuyển tiếp \(k_{0}\), ta có định lý sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Định lý: Phương pháp Newton dùng tìm kiếm đường backtracking có cận hội tụ hai giai đoạn:
\(\begin{align}
&amp;amp;f(x^{(k)})-f^{\star} \leq \begin{cases} (f(x^{(0)})-f^{\star})-\gamma k \qquad &amp;amp;\text{if }k\leq k_{0}\\\\
\frac{2m^{3}}{M^{2}}(\frac{1}{2})^{2^{k-k_{0}+1}} \qquad &amp;amp;\text{if }k&amp;gt;k_{0}.
\end{cases}
\end{align}\)&lt;/p&gt;

  &lt;p&gt;Ở đây, \(\gamma = \frac{\alpha \beta \eta^{2}m}{L^{2}}\), \(\eta = \min\{1, 3(1-2\alpha)\}\frac{m^{2}}{M}\), và \(k_{0}\) là vòng lặp đầu tiên thỏa mãn \(\|\nabla f(x^{(k_0)})\|_{2}&amp;lt;\eta\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;chứng-minh-1-giai-đoạn-giảm-chấn-damped-phase&quot;&gt;Chứng minh 1. Giai đoạn giảm chấn (Damped phase)&lt;/h2&gt;
&lt;p&gt;Trước hết, xét trường hợp \(\|\nabla f(x)\|_{2} \geq \eta\). Ta chứng minh mức giảm giá trị hàm trong giai đoạn này thông qua cận dưới của kích thước bước \(t\) do tìm kiếm đường backtracking chọn, sử dụng các hệ thức của Newton decrement.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Bắt đầu bằng cách đặt \(y=x+t\Delta x_{nt}\) vào khai triển Taylor của \(f\) và áp dụng cận trên từ điều kiện liên tục Lipschitz của gradient:&lt;/p&gt;

\[\begin{align}
f(x+t\Delta x_{nt}) \leq f(x)+t\nabla f(x)^{T}\Delta x_{nt} + \frac{L \|\Delta x_{nt} \|^{2}_{2} }{2}t^{2},
\end{align}\]

  &lt;p&gt;Kết hợp các hệ thức giữa Newton decrement, bước cập nhật, ma trận Hessian và tính lồi mạnh:&lt;/p&gt;

\[\begin{align}
&amp;amp;\text{Vì }\lambda(x)^{2}=\Delta x_{nt}^{T} \nabla^{2} f(x) \Delta x_{nt} \geq m\|\Delta x_{nt}\|^{2}_{2}\text{ và }\nabla f(x)^{T}\Delta x_{nt} = -\lambda(x)^{2},\\\\
&amp;amp;f(x)+t\nabla f(x)^{T}\Delta x_{nt} + \frac{L \|\Delta x_{nt} \|^{2}_{2} }{2}t^{2} \leq f(x)-t\lambda(x)^{2} + \frac{L}{2m}t^{2}\lambda(x)^{2},
\end{align}\]

  &lt;p&gt;Để thỏa mãn điều kiện dừng của backtracking line search, ta xét các giá trị \(t\) thỏa bất đẳng thức:&lt;/p&gt;

\[\begin{align}
f(x+t\Delta x_{nt}) \leq f(x)-(1-\frac{L}{2m}t)t \lambda(x)^{2}, \qquad \text{ trong đó }1-\frac{L}{2m}t \geq \frac{1}{2}
\end{align}\]

  &lt;p&gt;Giá trị lớn nhất của \(t\) thỏa điều kiện trên là \(\hat{t} = \frac{m}{L}\). Thay \(\hat{t}\) vào bất đẳng thức, ta được:&lt;/p&gt;

\[\begin{align}
f(x+\hat{t}\Delta x_{nt})\leq f(x)-\frac{m}{2L}\lambda(x)^{2} \leq f(x) -\alpha \hat{t} \lambda(x)^{2},
\end{align}\]

  &lt;p&gt;(bất đẳng thức cuối đúng vì \(\alpha \leq 1/2\)). Do tham số thu nhỏ bước thỏa \(0&amp;lt;\beta&amp;lt;1\), bước \(t\) mà backtracking dừng lại luôn thỏa \(t\geq \beta \frac{m}{L}\), từ đó suy ra:&lt;/p&gt;

\[\begin{align}
f(x^{+})-f(x) &amp;amp;\leq -\alpha t \lambda(x)^{2}\\\\
&amp;amp;\leq -\alpha\beta \frac{m}{L}\lambda(x)^{2}\\\\
&amp;amp;\leq -\alpha\beta \frac{m}{L^{2}}\|\nabla f(x)\|^{2}_{2}\\\\
&amp;amp;\leq -\alpha\beta \eta^{2}\frac{m}{L^{2}},\\\\
&amp;amp;\gamma = \alpha\beta \eta^{2}\frac{m}{L^{2}}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;(Ở bước thứ ba ta dùng bất đẳng thức \(\lambda(x)^{2} = \nabla f(x)^{T}\nabla^{2}f(x)^{-1}\nabla f(x) \geq \|\nabla f(x)\|_2^2 / L\).)&lt;/p&gt;

&lt;h2 id=&quot;chứng-minh-2-giai-đoạn-thuần-túy-pure-phase&quot;&gt;Chứng minh 2. Giai đoạn thuần túy (Pure phase)&lt;/h2&gt;
&lt;p&gt;Bây giờ giả sử \(\|\nabla f(x)\|_{2} &amp;lt; \eta\). Chứng minh gồm hai phần: chỉ ra rằng bước đầy đủ \(t = 1\) luôn được chấp nhận bởi backtracking, và chứng minh tốc độ hội tụ là bậc hai.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Theo cách chọn \(\eta\), ta có:&lt;/p&gt;

\[\begin{align}
\eta \leq 3(1-2\alpha)\frac{m^{2}}{M}.
\end{align}\]

  &lt;p&gt;Từ điều kiện liên tục Lipschitz của Hessian, với mọi \(t \geq 0\):&lt;/p&gt;

\[\begin{align}
\|\nabla^{2}f(x+t\Delta x_{nt})-\nabla^{2}f(x)\|_{2} \leq tM \|\Delta x_{nt} \|_{2},\\\\
| \Delta x_{nt}^{T} \big( \nabla^{2}f(x+t\Delta x_{nt})-\nabla^{2}f(x) \big) \Delta x_{nt}| \leq tM \|\Delta x_{nt} \|_{2}^{3}.
\end{align}\]

  &lt;p&gt;Đặt \(\tilde{f}(t) = f(x+t\Delta x_{nt})\), khi đó \(\tilde{f}&apos;&apos;(t) = \Delta x_{nt}^{T} \nabla^{2}f(x+t\Delta x_{nt})\Delta x_{nt}\), nên:&lt;/p&gt;

\[\begin{align}
\tilde{f}&apos;&apos;(t) \leq \tilde{f}&apos;&apos;(0)+tM\|\Delta x_{nt}\|^{3}_{2}
\end{align}\]

  &lt;p&gt;Sử dụng \(\tilde{f}&apos;&apos;(0) = \lambda(x)^{2}\) và \(\lambda(x)^{2} \geq m\|\Delta x_{nt}\|_{2}^{2}\) (suy ra \(\|\Delta x_{nt}\|_2^3 \le \lambda(x)^3/m^{3/2}\)), đồng thời tích phân từ \(0\) đến \(t\) với \(\tilde{f}&apos;(0) = -\lambda(x)^{2}\):&lt;/p&gt;

\[\begin{align}
\tilde{f}&apos;&apos;(t) &amp;amp;\leq \lambda(x)^{2} + t\frac{M}{m^{3/2}}\lambda(x)^{3}, \\\\
\tilde{f}&apos;(t) &amp;amp;\leq \tilde{f}&apos;(0)+t\lambda(x)^{2} +t^{2}\frac{M}{2m^{3/2}}\lambda(x)^{3}\\\\
&amp;amp;= -\lambda(x)^{2}+t\lambda(x)^{2} + t^{2}\frac{M}{2m^{3/2}}\lambda(x)^{3}.
\end{align}\]

  &lt;p&gt;Tiếp tục lấy tích phân hai vế:&lt;/p&gt;

\[\begin{align}
\tilde{f}(t) \leq \tilde{f}(0) - t\lambda(x)^{2} + t^{2} \frac{1}{2}\lambda(x)^{2} + t^{3}\frac{M}{6m^{3/2}}\lambda(x)^{3}.
\end{align}\]

  &lt;p&gt;Thay \(t = 1\), ta thu được:&lt;/p&gt;

\[\begin{align}
f(x+\Delta x_{nt}) \leq f(x) -\frac{1}{2}\lambda(x)^{2} + \frac{M}{6m^{3/2}}\lambda(x)^{3}.
\end{align}\]

  &lt;p&gt;Với giả thiết \(\|\nabla f(x)\|_{2}\leq \eta \leq 3(1-2\alpha)\frac{m^{2}}{M}\) và tính lồi mạnh, ta có \(\lambda(x) \leq \|\nabla f(x)\|_{2}/m^{1/2} \leq 3(1-2\alpha)m^{3/2}/M\). Thay vào bất đẳng thức trên:&lt;/p&gt;

\[\begin{align}
f(x+\Delta x_{nt}) &amp;amp;\leq f(x) - \lambda(x)^{2}( \frac{1}{2}- \frac{M\lambda(x)}{6m^{3/2}} ) \\\\
&amp;amp;\leq f(x) -\alpha \lambda(x)^{2} \\\\
&amp;amp;= f(x) + \alpha \nabla f(x)^{T} \Delta x_{nt},
\end{align}\]

  &lt;p&gt;Điều này chứng tỏ điều kiện backtracking luôn thỏa mãn tại \(t = 1\), nên kích thước bước không bị thu nhỏ.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tiếp theo, ta chứng minh tốc độ hội tụ là bậc hai.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Từ \(\Delta x_{nt} = -(\nabla^{2}f(x))^{-1}\nabla f(x)\) và công thức tích phân \(\nabla f(x+\Delta x_{nt}) - \nabla f(x) = \int^{1}_{0}{\nabla^{2}f(x+t\Delta x_{nt})\Delta x_{nt}\, dt}\), áp dụng điều kiện liên tục Lipschitz của Hessian cùng tính lồi mạnh, ta thu được:&lt;/p&gt;

\[\begin{align}
\| \nabla f(x^{+}) \| _{2} &amp;amp;= \| \nabla f(x+\Delta x_{nt}) - \nabla f(x) - \nabla^{2}f(x)\Delta x_{nt} \|_{2}\\\\
&amp;amp;=\| \int^{1}_{0}{ \big( \nabla^{2}f(x+t\Delta x_{nt})-\nabla^{2} f(x) \big) \Delta x_{nt} dt } \|_{2}\\\\
&amp;amp; \leq \frac{M}{2}\|\Delta x_{nt} \|^{2}_{2}\\\\
&amp;amp; = \frac{M}{2}\|\nabla^{2}f(x)^{-1}\nabla f(x)\|^{2}_{2}\\\\
&amp;amp; \leq \frac{M}{2m^{2}}\|\nabla f(x)\|^{2}_{2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tóm lại, khi \(\eta = \min \{1, 3(1-2\alpha)\}\frac{m^{2}}{M}\) và \(\|\nabla f(x^{(k)}) \|_{2}&amp;lt;\eta\), backtracking luôn giữ \(t = 1\) và phương pháp Newton đạt hội tụ bậc hai.&lt;/p&gt;

&lt;h2 id=&quot;ước-lượng-độ-phức-tạp-tổng-thể&quot;&gt;Ước lượng độ phức tạp tổng thể&lt;/h2&gt;
&lt;p&gt;Từ các cận trên, ta ước lượng tổng số vòng lặp cần thiết để đi từ điểm khởi tạo đến độ chính xác mong muốn.
Trong giai đoạn giảm chấn, mỗi bước giảm giá trị hàm ít nhất \(\gamma\), nên tổng số bước của giai đoạn này không vượt quá:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\frac{f(x^{(0)})-p^{\star}}{\gamma}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Đối với giai đoạn thuần túy, đặt \(f(x)-p^{\star}\leq \epsilon\) và \(\epsilon_{0} = \frac{2m^{3}}{M^{2}}\), giải theo số bước lặp:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;\epsilon = \epsilon_{0} (\frac{1}{2})^{2^{k-k_{0}+1}}\\\\
&amp;amp;\Leftrightarrow &amp;amp;\frac{\epsilon_{0}}{\epsilon} = 2^{2^{k-k_{0}+1}}\\\\
&amp;amp;\Leftrightarrow &amp;amp;k-k_{0}+1 = \log_{2}\log_{2}(\frac{\epsilon_{0}}{\epsilon})
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó, số vòng lặp trong giai đoạn Newton thuần túy bị chặn bởi \(\log_{2}\log_{2}(\frac{\epsilon_{0}}{\epsilon})\).&lt;/p&gt;

&lt;p&gt;Cộng hai giai đoạn lại, ta được cận trên cho tổng số vòng lặp để đạt độ chính xác \(\epsilon\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\frac{f(x^{(0)})-p^{\star}}{\gamma} + \log_2 \log_2 (\frac{\epsilon_{0}}{\epsilon}).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì số hạng thứ hai tăng rất chậm theo độ chính xác \(\epsilon\) yêu cầu, trong thực hành người ta thường xem nó như một hằng số nhỏ; cụ thể, 6 vòng lặp đã đạt độ chính xác \(\epsilon \approx 5\cdot 10^{-20}\epsilon_{0}\).&lt;/p&gt;

&lt;p&gt;Do đó, tổng số vòng lặp thường được ước lượng là:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\frac{f(x^{(0)})-p^{\star}}{\gamma} + 6.
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>14-04 Tìm kiếm đường backtracking</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_04_backtracking_line_search/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_04_backtracking_line_search</id>
   <content type="html">&lt;p&gt;Như ta đã chứng kiến ở mục 14-02, phương pháp Newton thuần túy giống như một chiếc xe đua Công thức 1 không có phanh: trên đường thẳng gần đích nó đạt tốc độ không tưởng, nhưng chỉ cần vào cua khi còn xa đích là nó có thể lao thẳng ra khỏi đường đua và phân kỳ.&lt;/p&gt;

&lt;p&gt;Giải pháp cực kỳ gọn gàng để biến “xe đua mất phanh” thành thuật toán hội tụ toàn cục chính là &lt;strong&gt;tìm kiếm đường backtracking (backtracking line search)&lt;/strong&gt; — tạo nên &lt;strong&gt;phương pháp Newton có giảm chấn (damped Newton method)&lt;/strong&gt;. Thay vì nhắm mắt nhảy luôn một bước đầy đủ \(t = 1\), ta thử \(t = 1\) trước; nếu hàm mục tiêu chưa giảm đủ sâu theo điều kiện Armijo, ta thu ngắn bước đi theo hệ số \(\beta \in (0, 1)\) cho đến khi bước đi an toàn. Điểm tuyệt vời là khi đã vào gần nghiệm, bước \(t = 1\) tự động thỏa mãn ngay từ lần thử đầu tiên nên tốc độ hội tụ bậc hai vẫn được bảo toàn nguyên vẹn!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cơ-chế-hoạt-động-của-newton-có-giảm-chấn&quot;&gt;Kiến thức cần nhớ: Cơ chế hoạt động của Newton có giảm chấn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện giảm đủ Armijo cho Newton:&lt;/strong&gt; Với hướng Newton \(v = -(\nabla^2 f(x))^{-1}\nabla f(x)\) và đạo hàm theo hướng \(\nabla f(x)^T v = -\lambda(x)^2\), bước \(t\) được chấp nhận khi:
\(f(x + tv) \le f(x) - \alpha t \lambda(x)^2, \qquad \alpha \in (0, 0.5).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại sao luôn thử \(t = 1\) đầu tiên:&lt;/strong&gt; Khác với Gradient Descent (nơi bước \(t = 1\) thường quá lớn), bước Newton đã tự co giãn đúng tỷ lệ nhờ \((\nabla^2 f)^{-1}\). Thử \(t = 1\) trước đảm bảo thuật toán tự động chuyển sang Newton thuần túy ngay khi vào pha hội tụ bậc hai.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai tham số \(\alpha\) và \(\beta\):&lt;/strong&gt; Trong thực hành, \(\alpha \in [0.01, 0.3]\) (mức giảm tối thiểu yêu cầu so với đường tiếp tuyến) và \(\beta \in [0.1, 0.8]\) (tỷ lệ thu bước mỗi lần thất bại, phổ biến nhất là \(\beta = 0.5\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-một-vòng-backtracking-trên-hàm-fx--sqrt1--x2-để-cứu-bước-newton-phân-kỳ&quot;&gt;Giải thích: Chạy tay một vòng backtracking trên hàm \(f(x) = \sqrt{1 + x^2}\) để cứu bước Newton phân kỳ&lt;/h3&gt;

&lt;p&gt;Nhớ lại ở mục 14-02, với \(f(x) = \sqrt{1 + x^2}\) tại điểm khởi tạo \(x = 1.2\), bước Newton thuần túy nhảy sang \(-1.728\) và &lt;strong&gt;phân kỳ&lt;/strong&gt;! Giờ hãy lắp thêm backtracking với \(\alpha = 0.25\) và \(\beta = 0.5\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giá trị tại \(x = 1.2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(1.2) = \sqrt{1 + 1.44} = \sqrt{2.44} \approx 1.5620\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;(1.2) = \frac{1.2}{1.5620} \approx 0.7682\), \(f&apos;&apos;(1.2) = \frac{1}{(1.5620)^3} \approx 0.2624\).&lt;/li&gt;
      &lt;li&gt;Hướng Newton: \(v = -\frac{f&apos;(1.2)}{f&apos;&apos;(1.2)} = -1.2(2.44) = -2.928\).&lt;/li&gt;
      &lt;li&gt;\(\lambda(1.2)^2 = -f&apos;(1.2)v \approx 0.7682 \times 2.928 \approx 2.2494\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử \(t = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Điểm mới: \(x + v = 1.2 - 2.928 = -1.728 \implies f(-1.728) = \sqrt{1 + 2.986} \approx 1.9965\).&lt;/li&gt;
      &lt;li&gt;Ngưỡng Armijo: \(1.5620 - 0.25(1)(2.2494) = 0.9997\). Vì \(1.9965 &amp;gt; 0.9997\) (thậm chí tăng!), &lt;strong&gt;từ chối \(t = 1\)&lt;/strong&gt; và giảm \(t \leftarrow 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử \(t = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Điểm mới: \(x + 0.5v = 1.2 - 1.464 = -0.264 \implies f(-0.264) = \sqrt{1 + 0.0697} \approx 1.0343\).&lt;/li&gt;
      &lt;li&gt;Ngưỡng Armijo: \(1.5620 - 0.25(0.5)(2.2494) \approx 1.2808\).&lt;/li&gt;
      &lt;li&gt;Vì \(1.0343 \le 1.2808\), &lt;strong&gt;chấp nhận \(t = 0.5\)!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết quả kỳ diệu:&lt;/strong&gt; Điểm mới \(x^{(1)} = -0.264\) đã rơi gọn vào vùng hội tụ bậc hai (\(\vert x \vert &amp;lt; 1\)), nên từ vòng lặp tiếp theo trở đi, \(t = 1\) sẽ luôn được chấp nhận và hội tụ về \(0\) trong chớp mắt!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Đến đây, chúng ta mới xét phương pháp Newton thuần túy. Vì phương pháp này không đảm bảo hội tụ toàn cục, ta kết hợp thêm tìm kiếm đường backtracking để thu được phương pháp Newton có giảm chấn (damped Newton method).&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-newton-có-giảm-chấn&quot;&gt;Phương pháp Newton có giảm chấn&lt;/h2&gt;
&lt;p&gt;Phương pháp Newton thuần túy lặp lại công thức cập nhật sau với \(t = 1\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{+} = x -t(\nabla^{2}f(x))^{-1}\nabla f(x).
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Phương pháp Newton có giảm chấn sử dụng tìm kiếm đường backtracking: nếu giá trị hàm tại điểm cập nhật lớn hơn cận trên từ xấp xỉ tuyến tính có hệ số \(\alpha\) (điều kiện giảm đủ Armijo), ta thu nhỏ kích thước bước \(t\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{với các tham số }0&amp;lt;\alpha \leq \frac{1}{2}, 0&amp;lt;\beta&amp;lt;1, \\
&amp;amp;\text{trong khi } f(x+tv)&amp;gt;f(x)+\alpha t \nabla f(x)^{T}v\\
&amp;amp;\text{thu nhỏ }t=\beta t
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây, \(v=-(\nabla^{2}f(x))^{-1}\nabla f(x)\) và \(\nabla f(x)^{T}v = -\lambda^{2}(x)\).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-hồi-quy-logistic&quot;&gt;Ví dụ: hồi quy logistic&lt;/h2&gt;
&lt;p&gt;Xét bài toán hồi quy logistic với \(n = 500\) và \(p = 100\) để so sánh tốc độ hội tụ giữa gradient descent và phương pháp Newton kết hợp tìm kiếm đường backtracking.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter14/2.jpeg&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Hồi quy logistic [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Phương pháp Newton hội tụ nhanh hơn đáng kể so với gradient descent. Mục tiếp theo sẽ phân tích lý thuyết tốc độ hội tụ này.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-03 Newton decrement</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_03_newton_decrement/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_03_newton_decrement</id>
   <content type="html">&lt;p&gt;Khi chạy Gradient Descent, ta thường kiểm tra độ lớn gradient \(\|\nabla f(x)\|_2 \le \epsilon\) để biết mình đã gần đáy hay chưa. Nhưng trong thế giới của phương pháp Newton, chuẩn Euclid \(\|\nabla f(x)\|_2\) lại có một nhược điểm chí mạng: &lt;strong&gt;nó không bất biến affine!&lt;/strong&gt; Chỉ cần đổi đơn vị đo của một biến, \(\|\nabla f(x)\|_2\) có thể phình to gấp 1.000 lần dù bạn đang đứng ngay sát nghiệm tối ưu.&lt;/p&gt;

&lt;p&gt;Để giải quyết triệt để vấn đề này, các nhà toán học đã sáng chế ra một thước đo tự nhiên riêng cho phương pháp Newton: &lt;strong&gt;đại lượng giảm Newton (Newton decrement)&lt;/strong&gt; \(\lambda(x) = \sqrt{\nabla f(x)^T (\nabla^2 f(x))^{-1} \nabla f(x)}\). Không chỉ hoàn toàn bất biến affine, \(\frac{1}{2}\lambda(x)^2\) còn cho bạn biết ngay &lt;strong&gt;khoảng cách dự kiến từ vị trí hiện tại tới đáy của parabol xấp xỉ&lt;/strong&gt;, trở thành tiêu chí dừng tiêu chuẩn vàng cho mọi bộ giải Newton và phương pháp điểm trong.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-ý-nghĩa-đồng-thời-của-newton-decrement-lambdax&quot;&gt;Kiến thức cần nhớ: Bốn ý nghĩa đồng thời của Newton Decrement \(\lambda(x)\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng khoảng cách tới giá trị tối ưu:&lt;/strong&gt; Nếu thay \(f\) bằng xấp xỉ Taylor bậc hai \(\tilde{f}_x\), mức giảm cực đại có thể đạt được chính xác bằng:
\(f(x) - \min_y \tilde{f}_x(y) = \frac{1}{2}\lambda(x)^2.\)
Vì vậy, tiêu chí dừng \(\frac{1}{2}\lambda(x)^2 \le \epsilon\) có ý nghĩa trực tiếp là “còn cách đáy xấp xỉ không quá \(\epsilon\)”.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ dài bước Newton theo chuẩn Hessian:&lt;/strong&gt; Với bước Newton \(v = -(\nabla^2 f(x))^{-1}\nabla f(x)\), ta có \(\lambda(x) = \sqrt{v^T \nabla^2 f(x) v} = \|v\|_{\nabla^2 f(x)}\) — chuẩn tự nhiên gắn với độ cong tại \(x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đạo hàm theo hướng Newton:&lt;/strong&gt; Đạo hàm của \(f\) dọc theo hướng bước Newton \(v\) bằng đúng \(-\lambda(x)^2\): \(\nabla f(x)^T v = -\lambda(x)^2 &amp;lt; 0\). Đại lượng này dùng trực tiếp trong điều kiện dừng của tìm kiếm đường backtracking!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bất biến affine tuyệt đối:&lt;/strong&gt; Dưới mọi phép đổi tọa độ khả nghịch \(x = Ay\), giá trị \(\lambda(x)\) giữ nguyên không đổi, biến nó thành tiêu chí dừng đáng tin cậy bất kể bài toán có bị kéo giãn trục mạnh đến đâu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-lambdax-và-kiểm-chứng-ước-lượng-mức-giảm-frac12lambdax2&quot;&gt;Giải thích: Tính tay \(\lambda(x)\) và kiểm chứng ước lượng mức giảm \(\frac{1}{2}\lambda(x)^2\)&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai 2 chiều \(f(x_1, x_2) = 2x_1^2 + 8x_2^2 - 4x_1 - 16x_2 + 12\) tại điểm \(x = (2, 2)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giá trị hàm, gradient và Hessian tại \(x = (2, 2)^T\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(2, 2) = 2(4) + 8(4) - 8 - 32 + 12 = 12\).&lt;/li&gt;
      &lt;li&gt;\(\nabla f(x) = \begin{bmatrix} 4x_1 - 4 \\ 16x_2 - 16 \end{bmatrix} \implies \nabla f(2, 2) = \begin{bmatrix} 4 \\ 16 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;\(\nabla^2 f(x) = \begin{bmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 16 \end{bmatrix} \implies (\nabla^2 f)^{-1} = \begin{bmatrix} 1/4 &amp;amp; 0 \\ 0 &amp;amp; 1/16 \end{bmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bước Newton \(v\) và Newton decrement \(\lambda(x)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v = -(\nabla^2 f)^{-1}\nabla f = \begin{bmatrix} -1 \\ -1 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;\(\lambda(x)^2 = \nabla f^T (\nabla^2 f)^{-1} \nabla f = 4\left(\frac{1}{4}\right)4 + 16\left(\frac{1}{16}\right)16 = 4 + 16 = 20 \implies \lambda(x) = \sqrt{20} \approx 4.472\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng đồng thời hai hệ thức vàng:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đạo hàm theo hướng \(v\): \(\nabla f^T v = 4(-1) + 16(-1) = -20 = -\lambda(x)^2\).&lt;/li&gt;
      &lt;li&gt;Mức giảm tới đáy thật \(x^\star = (1, 1)^T\): ta có \(f(1, 1) = 2 + 8 - 4 - 16 + 12 = 2\), nên \(f(2, 2) - f(1, 1) = 12 - 2 = 10\). Đối chiếu với \(\frac{1}{2}\lambda(x)^2 = \frac{1}{2}(20) = 10\) — &lt;strong&gt;chính xác tuyệt đối!&lt;/strong&gt; (Với hàm phi tuyến tổng quát, \(\frac{1}{2}\lambda(x)^2\) là xấp xỉ cực sát của \(f(x) - f^\star\) khi gần nghiệm).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trong mục này, chúng ta định nghĩa đại lượng giảm Newton (Newton decrement) và phân tích ý nghĩa của nó.&lt;/p&gt;

&lt;p&gt;Đối với bài toán tối ưu hóa dưới đây, Newton decrement tại \(x\) được ký hiệu và định nghĩa là \(\lambda(x)\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\min_{x} \quad f(x),\&lt;br /&gt;
\end{align}
\begin{align}
\lambda(x) = (\nabla f(x)^{T}(\nabla^{2}f(x))^{-1}\nabla f(x))^{1/2}.
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;đặc-điểm-của-newton-decrement&quot;&gt;Đặc điểm của Newton decrement&lt;/h2&gt;
&lt;p&gt;Thứ nhất, Newton decrement liên hệ trực tiếp với hiệu giữa giá trị hàm \(f(x)\) và giá trị nhỏ nhất của xấp xỉ bậc hai của \(f\) tại \(x\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x)-&amp;amp;\min_{y} \big( f(x)+\nabla f(x)^{T}(y-x)+\frac{1}{2}(y-x)^{T}\nabla^{2}f(x)(y-x)\big),\\\\
f(x)-&amp;amp;\bigg( f(x) + \nabla f(x)^{T}\big( -(\nabla^{2} f(x) )^{-1} \nabla f(x)\big) + \frac{1}{2}\big( -(\nabla^{2}f(x))^{-1} \nabla f(x) \big)^{T} \nabla ^{2}f(x) \big( -(\nabla^{2}f(x))^{-1}\nabla f(x) \big) \bigg) \\\\ 
&amp;amp;= \frac{1}{2}\nabla f(x)^{T}(\nabla^{2} f(x) )^{-1}\nabla f(x) = \frac{1}{2}\lambda(x)^{2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó, \(\frac{1}{2}\lambda^{2}(x)\) có thể được dùng làm ước lượng cho khoảng cách tối ưu \(f(x)-f^{\star}\).&lt;/p&gt;

&lt;p&gt;Thứ hai, với hướng Newton ở mỗi vòng lặp là \(v = -(\nabla^{2}f(x))^{-1}\nabla f(x)\), Newton decrement chính là độ dài của bước Newton theo chuẩn cảm sinh bởi ma trận Hessian \(\nabla^{2}f(x)\).&lt;/p&gt;

&lt;p&gt;Đại lượng này cũng có thể hiểu như một dạng khoảng cách Mahalanobis [&lt;a href=&quot;https://en.wikipedia.org/wiki/Mahalanobis_distance&quot;&gt;Wikipedia&lt;/a&gt;], trong đó điểm mới \(y\) đóng vai trò quan sát, điểm hiện tại \(x\) là giá trị trung bình, còn ma trận Hessian tại \(x\) đóng vai trò nghịch đảo của ma trận hiệp phương sai. Khoảng cách Mahalanobis đo khoảng cách từ một điểm đến giá trị trung bình sau khi chuẩn hóa theo độ lệch chuẩn trên hướng tương ứng; tương tự, Newton decrement đo độ lớn của bước Newton tính từ điểm hiện tại trong hệ đo xác định bởi Hessian.&lt;/p&gt;

&lt;p&gt;Thứ ba, Newton decrement có thể biểu diễn qua bước cập nhật Newton \(\Delta x_{nt}\) và ma trận Hessian. Từ công thức cập nhật của phương pháp Newton:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{+} &amp;amp;= x-\big(\nabla^{2} f(x) \big)^{-1} \nabla f(x) &amp;amp;\ 
\end{align}
\begin{align}
\Delta x_{nt} &amp;amp;= -\big(\nabla^{2} f(x) \big)^{-1} \nabla f(x) &amp;amp;&lt;br /&gt;
\end{align}
\begin{align}
\nabla f(x)^{T} \Delta x_{nt} &amp;amp;= -\lambda (x)^{2}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Từ các hệ thức trên, ta viết lại Newton decrement dưới dạng:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\lambda(x) = (\Delta x_{nt}^{T}\nabla^{2} f(x) \Delta x_{nt})^{1/2}.
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Cuối cùng, tương tự bước Newton, Newton decrement cũng bất biến affine. Cụ thể, với mọi ma trận không suy biến \(A\), nếu đặt \(g(y) = f(Ay)\) thì tại \(x = Ay\) ta có \(\lambda_{g(y)} = \lambda_{f(x)}\).&lt;/p&gt;

&lt;h3 id=&quot;newton-decrement-trong-khoảng-3-phút&quot;&gt;Newton decrement trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/newton-decrement_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;½λ² là mức hạ của mô hình bậc hai, so với f − f* trên eˣ − 2x và trên hàm log-sum-exp, rồi so sánh tiêu chuẩn dừng λ với ‖∇f‖ khi đổi biến.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-02 Giải thích và Tính chất</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_02_interpretation_and_properties/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_02_interpretation_and_properties</id>
   <content type="html">&lt;p&gt;Một thuật toán chỉ thực sự đáng tin khi ta hiểu rõ &lt;strong&gt;bản chất, điểm mạnh và ranh giới sụp đổ&lt;/strong&gt; của nó. Trước khi gắn thêm các cơ chế bảo vệ như backtracking line search, mục 14-02 dừng lại để soi chiếu phương pháp Newton dưới ba góc độ nền tảng: mối quan hệ lịch sử với bài toán &lt;strong&gt;tìm nghiệm phương trình&lt;/strong&gt;, đặc quyền &lt;strong&gt;bất biến affine&lt;/strong&gt;, và tính &lt;strong&gt;hội tụ cục bộ&lt;/strong&gt; cực nhanh nhưng cũng cực kỳ đỏng đảnh khi đứng quá xa nghiệm.&lt;/p&gt;

&lt;p&gt;Nắm rõ bộ ba tính chất này sẽ giúp bạn giải thích ngay lập tức vì sao phương pháp Newton không cần chuẩn hóa dữ liệu (feature scaling) như Gradient Descent, nhưng lại có thể phân kỳ nổ tung nếu thiếu cơ chế giảm chấn.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-đặc-tính-cốt-lõi-định-danh-phương-pháp-newton&quot;&gt;Kiến thức cần nhớ: Ba đặc tính cốt lõi định danh phương pháp Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối tìm nghiệm ↔ tối ưu hóa:&lt;/strong&gt; Tìm cực tiểu của hàm trơn lồi \(f(x)\) chính là tìm nghiệm của hệ phương trình \(\nabla f(x) = 0\). Áp dụng Newton–Raphson cổ điển cho hàm vectơ \(F(x) = \nabla f(x)\) sinh ra đúng bước Newton tối ưu hóa!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bất biến affine (Affine Invariance):&lt;/strong&gt; Nếu đổi biến \(x = Ay\) (với \(A\) khả nghịch), dãy điểm Newton sinh ra trong không gian \(y\) khi nhân ngược lại với \(A\) sẽ trùng khít từng điểm với dãy Newton trong không gian \(x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ cục bộ bậc hai — con dao hai lưỡi:&lt;/strong&gt; Trong một bán kính đủ nhỏ quanh \(x^\star\), sai số giảm bình phương sau mỗi bước (\(\|x^+ - x^\star\| \le C\|x - x^\star\|^2\)). Nhưng bên ngoài bán kính đó, bước Newton thuần túy không hề có bảo chứng hội tụ và có thể nhảy ra vô cực.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-quan-sát-cả-hai-mặt--siêu-nhanh-gần-nghiệm-và-phân-kỳ-xa-nghiệm&quot;&gt;Giải thích: Quan sát cả hai mặt — siêu nhanh gần nghiệm và phân kỳ xa nghiệm&lt;/h3&gt;

&lt;p&gt;Xét hàm 1 chiều \(f(x) = \sqrt{1 + x^2}\) (hàm lồi chặt, đáy duy nhất tại \(x^\star = 0\)). Ta tính đạo hàm:
\(f&apos;(x) = \frac{x}{\sqrt{1 + x^2}}, \qquad f&apos;&apos;(x) = \frac{1}{(1 + x^2)^{3/2}}.\)
Bước cập nhật Newton thuần túy rút gọn cực đẹp:
\(x^+ = x - \frac{f&apos;(x)}{f&apos;&apos;(x)} = x - x(1 + x^2) = -x^3.\)&lt;/p&gt;

&lt;p&gt;Hãy thử hai điểm khởi tạo khác nhau:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khởi tạo gần nghiệm (\(x^{(0)} = 0.5\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = -(0.5)^3 = -0.125\).&lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = -(-0.125)^3 \approx +0.00195\).&lt;/li&gt;
      &lt;li&gt;\(x^{(3)} \approx -7.45 \times 10^{-9}\).
Tốc độ hội tụ thậm chí là &lt;strong&gt;bậc ba&lt;/strong&gt; — chỉ 3 bước đã chính xác tới 8 chữ số thập phân!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khởi tạo hơi xa nghiệm (\(x^{(0)} = 1.2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = -(1.2)^3 = -1.728\).&lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = -(-1.728)^3 \approx +5.16\).&lt;/li&gt;
      &lt;li&gt;\(x^{(3)} \approx -137.4\) — nổ tung ra vô cực!
Ranh giới hội tụ cục bộ ở đây là \(\vert x^{(0)} \vert &amp;lt; 1\); tại \(\vert x^{(0)} \vert = 1\), thuật toán dao động mãi mãi giữa \(1\) và \(-1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trong mục này, trước khi khảo sát các tính chất của phương pháp Newton, chúng ta tìm hiểu cách áp dụng phương pháp này cho bài toán tìm nghiệm.&lt;/p&gt;

&lt;p&gt;Tiếp theo, chúng ta sẽ phân tích hai tính chất quan trọng của phương pháp Newton: tính bất biến affine và hội tụ cục bộ.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-02-03 Phân tích hội tụ cục bộ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_02_03_local_convergence_analysis/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_02_03_local_convergence_analysis</id>
   <content type="html">&lt;p&gt;Phương pháp Newton nổi tiếng với tốc độ “thần thánh” — gọi là &lt;strong&gt;hội tụ bậc hai (quadratic convergence)&lt;/strong&gt; — nhưng định lý chỉ cấp giấy bảo hành tốc độ ấy khi bạn &lt;strong&gt;đã đứng đủ gần nghiệm tối ưu \(x^\star\)&lt;/strong&gt;. Câu hỏi tự nhiên là: &lt;em&gt;thế nào là “đủ gần”, và những giả thiết nào trên hàm \(f\) quyết định bán kính của vùng an toàn đó?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Mục này đặt nền tảng định lượng đầu tiên cho lý thuyết hội tụ Newton thuần túy. Bạn sẽ thấy ba điều kiện kinh điển (lồi mạnh \(m\), Hessian Lipschitz \(M\) và điểm khởi tạo đủ gần \(x^\star\)) kết hợp với nhau để tạo ra hệ số co rút bậc hai \(\|x^{(k+1)} - x^\star\|_2 \le \frac{M}{2m}\|x^{(k)} - x^\star\|_2^2\) — đồng thời cảnh báo một ví dụ phân kỳ điển hình khi vi phạm giả thiết khởi tạo.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-yếu-tố-quyết-định-vùng-hội-tụ-cục-bộ&quot;&gt;Kiến thức cần nhớ: Bốn yếu tố quyết định vùng hội tụ cục bộ&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi mạnh (hằng số \(m &amp;gt; 0\)):&lt;/strong&gt; Đảm bảo \(\nabla^2 f(x) \succeq m I\), tức là độ cong không bao giờ quá phẳng nên nghịch đảo Hessian bị chặn trên: \(\|(\nabla^2 f(x))^{-1}\|_2 \le \frac{1}{m}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính Lipschitz của Hessian (hằng số \(M &amp;gt; 0\)):&lt;/strong&gt; Đảm bảo độ cong không thay đổi quá đột ngột (\(\|\nabla^2 f(x) - \nabla^2 f(y)\|_2 \le M\|x - y\|_2\)), giúp mô hình parabol Taylor bậc hai bám sát hàm thật trong vùng lân cận.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý hội tụ cục bộ bậc hai:&lt;/strong&gt; Khi \(\|x^{(k)} - x^\star\|_2 &amp;lt; \frac{2m}{M}\), sai số bước sau thỏa \(\|x^{(k+1)} - x^\star\|_2 \le \frac{M}{2m}\|x^{(k)} - x^\star\|_2^2\). Sai số \(10^{-2}\) lập tức rơi xuống cỡ \(10^{-4}\), rồi \(10^{-8}\), rồi \(10^{-16}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nguy cơ phân kỳ ngoài bán kính hội tụ:&lt;/strong&gt; Nếu khởi tạo vượt quá ngưỡng \(\frac{2m}{M}\), hệ số co rút lớn hơn \(1\) khiến bước Newton thuần túy phóng vọt qua đáy và dao động hoặc phân kỳ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-trực-tiếp-bán-kính-hội-tụ-cục-bộ-và-theo-dõi-sai-số-bình-phương&quot;&gt;Giải thích: Tính trực tiếp bán kính hội tụ cục bộ và theo dõi sai số bình phương&lt;/h3&gt;

&lt;p&gt;Xét bài toán 1 chiều cực tiểu hóa \(f(x) = \frac{1}{2}x^2 + \frac{1}{6}x^3\) trên miền \(x \in (-0.5, 0.5)\), với nghiệm tối ưu là \(x^\star = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Xác định các hằng số \(m\) và \(M\) trên đoạn \([-0.5, 0.5]\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(x) = x + \frac{1}{2}x^2\), \(f&apos;&apos;(x) = 1 + x\), \(f&apos;&apos;&apos;(x) = 1\).&lt;/li&gt;
      &lt;li&gt;Trên \([-0.5, 0.5]\), độ cong nhỏ nhất là \(m = \min f&apos;&apos;(x) = 1 - 0.5 = 0.5\).&lt;/li&gt;
      &lt;li&gt;Hằng số Lipschitz của Hessian là \(M = \max \vert f&apos;&apos;&apos;(x) \vert = 1\).&lt;/li&gt;
      &lt;li&gt;Tỷ số hội tụ cục bộ: \(\frac{M}{2m} = \frac{1}{2(0.5)} = 1\), nên bán kính đảm bảo co rút chặt là \(\vert x^{(0)} - x^\star \vert &amp;lt; 1\) (nằm gọn trong miền xét).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra công thức sai số từng bước từ \(x^{(0)} = 0.2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; \(f&apos;(0.2) = 0.22\), \(f&apos;&apos;(0.2) = 1.2 \implies x^{(1)} = 0.2 - \frac{0.22}{1.2} = \frac{0.02}{1.2} \approx 0.01667\).
Đối chiếu cận lý thuyết: \(\frac{M}{2m}(0.2)^2 = 1 \cdot 0.04 = 0.04\) (thực tế \(0.01667 \le 0.04\)).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt; \(f&apos;(0.01667) \approx 0.01681\), \(f&apos;&apos;(0.01667) \approx 1.01667 \implies x^{(2)} \approx 0.000137\).
Đối chiếu cận lý thuyết: \(1 \cdot (0.01667)^2 \approx 0.000278\) (thực tế \(0.000137 \le 0.000278\)).
Chỉ sau 2 bước từ \(0.2\), sai số đã co lại hơn &lt;strong&gt;1.400 lần&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
});
&lt;/script&gt;

&lt;p&gt;Tính chất quan trọng thứ hai của phương pháp Newton là hội tụ cục bộ: sự hội tụ được đảm bảo khi điểm khởi tạo đủ gần nghiệm và các điều kiện thích hợp được thỏa mãn. Vì phương pháp Newton thuần túy trong &lt;a href=&quot;/contents/vi/chapter14/14_01_newton_method/&quot;&gt;14-01&lt;/a&gt; không đảm bảo hội tụ toàn cục, ở các mục sau ta sẽ xây dựng phương pháp Newton có giảm chấn (damped Newton method) bằng cách điều chỉnh kích thước bước với tìm kiếm đường backtracking như trong &lt;a href=&quot;/contents/vi/chapter06/06_00_gradient_descent/&quot;&gt;Chương 6&lt;/a&gt;, rồi phân tích tốc độ hội tụ của nó.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Định lý: Cho \(F : \mathbb{R}^{n}\, \rightarrow  \, \mathbb{R}^{n}\) khả vi liên tục và \(x^{\star} \in \mathbb{R}^{n}\) là một nghiệm của \(F\), tức \(F(x^{\star})=0\).
Nếu \(F^{&apos;}(x^{\star})\) không suy biến, thì hai khẳng định (a) và (b) sau đây đúng: &lt;br /&gt;
(a) Tồn tại \(\delta &amp;gt; 0\) sao cho nếu \(\| x^{(0)}-x^{\star} \|&amp;lt;\delta\) thì phương pháp Newton xác định và đạt hội tụ siêu tuyến tính:
\begin{align}
\lim_{ k \rightarrow \infty } \frac{ || x^{ (k+1) }-x^{ \star } || } { || x^{ (k) }-x^{ \star } || } =0.
\end{align} &lt;br /&gt;
(b) Nếu \(F^{&apos;}\) liên tục Lipschitz trong lân cận của \(x^{\star}\), thì tồn tại hằng số \(K &amp;gt; 0\) sao cho dãy nghiệm đạt hội tụ bậc hai:
\begin{align}
||x^{ (k+1) } - x^{ \star }|| \leq K || x^{ (k) }-x^{ \star }||^{2}.
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;chứng-minh-a&quot;&gt;Chứng minh (a)&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;Khai triển Taylor bậc nhất của \(F(x^{\star})\) quanh \(x^{k}\) với ký hiệu little-o cho phần dư bậc cao hơn:
\begin{align}
0=F(x^{\star}) = F(x^{k}) +\nabla F(x^{k})(x^{\star}-x^{k})+o(||x^{k}-x^{\star}||).&lt;br /&gt;
\end{align}
Nhân cả hai vế bên trái với \(\nabla F(x^{k})^{-1}\) rồi chuyển vế. Do \(\nabla F(x^{k})^{-1}\) bị chặn trong lân cận \(x^{\star}\), tích của nó với \(o(\|\|x^{k}-x^{\star}\|\|)\) vẫn là \(o(\|\|x^{k}-x^{\star}\|\|)\):
\begin{align}
x^{k}-x^{\star}-\nabla F(x^{k})^{-1} F(x^{k}) = o(||x^{k}-x^{\star}||).
\end{align}
Thay công thức cập nhật Newton \(x^{k+1}=x^{k}-\nabla F(x^{k})^{-1}F(x^{k})\), ta thu được:
\begin{align}
x^{k+1}-x^{\star}=o(||x^{k}-x^{\star}||).
\end{align}
Do đó, với \(x^{k} \neq x^{\star}\), từ định nghĩa giới hạn của ký hiệu little-o [&lt;a href=&quot;https://en.wikipedia.org/wiki/Big_O_notation&quot;&gt;wikipedia&lt;/a&gt;] ta suy ra (a):&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\lim_{k\rightarrow \infty} \frac{||x^{k+1}-x^{\star}||}{||x^{k}-x^{\star}||} = \lim_{k\rightarrow \infty}\frac{o(||x^{k}-x^{\star}||)}{||x^{k}-x^{\star}||} = 0.
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;chứng-minh-b&quot;&gt;Chứng minh (b)&lt;/h2&gt;
&lt;p&gt;Cách chứng minh tương tự như phần chứng minh tốc độ hội tụ bậc hai trong giai đoạn thuần túy (Pure phase) ở bài [&lt;a href=&quot;/contents/vi/chapter14/14_05_convergence_analysis/&quot;&gt;14-05&lt;/a&gt;], nên được lược bỏ tại đây.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-trường-hợp-phân-kỳ&quot;&gt;Ví dụ: trường hợp phân kỳ&lt;/h2&gt;
&lt;p&gt;Dưới đây là một ví dụ minh họa trường hợp phương pháp Newton thuần túy không hội tụ.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter14/1_.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Phương pháp Newton thuần túy áp dụng cho bài toán tìm nghiệm: trường hợp phân kỳ&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;a href=&quot;https://slideplayer.com/slide/4998677/&quot;&gt;image-link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Như minh họa trong hình, tùy thuộc vào điểm khởi tạo \(x_0\), dãy lặp có thể phân kỳ.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-02-02 Tính bất biến affine của phương pháp Newton</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_02_02_affine_invariance_of_newton_method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_02_02_affine_invariance_of_newton_method</id>
   <content type="html">&lt;p&gt;Trong học máy, một trong những quy tắc đầu tiên bạn được dặn khi chạy Gradient Descent là: &lt;em&gt;“Hãy chuẩn hóa (standardize) các đặc trưng về cùng thang đo!”&lt;/em&gt; Lý do rất đơn giản: nếu một biến đo bằng kilômét còn biến kia đo bằng milimét, đường đồng mức sẽ bị kéo dẹt thành một khe nứt hẹp, khiến Gradient Descent lê lết hàng nghìn bước.&lt;/p&gt;

&lt;p&gt;Thế nhưng, nếu bạn dùng &lt;strong&gt;Phương pháp Newton&lt;/strong&gt;, bạn có thể đổi đơn vị từ mét sang nanômét, xoay trục tọa độ hay kéo xiên hệ trục bằng bất kỳ phép biến đổi affine khả nghịch \(x = Ay\) nào — và &lt;strong&gt;quỹ đạo hội tụ của phương pháp Newton không hề thay đổi dù chỉ một phần tỷ&lt;/strong&gt;! Tính chất đáng kinh ngạc này gọi là &lt;strong&gt;tính bất biến affine (affine invariance)&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-vì-sao-phép-đổi-hệ-tọa-độ-không-làm-phương-pháp-newton-nao-núng&quot;&gt;Kiến thức cần nhớ: Vì sao phép đổi hệ tọa độ không làm phương pháp Newton nao núng?&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc dây chuyền cho gradient và Hessian:&lt;/strong&gt; Khi đặt \(x = Ay\) và xét hàm \(g(y) = f(Ay)\), ta có \(\nabla g(y) = A^T \nabla f(Ay)\) và \(\nabla^2 g(y) = A^T \nabla^2 f(Ay) A\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sự triệt tiêu kỳ diệu của ma trận \(A\):&lt;/strong&gt; Khi lấy nghịch đảo Hessian của \(g\) nhân với gradient của \(g\):
\((\nabla^2 g(y))^{-1}\nabla g(y) = A^{-1} (\nabla^2 f(Ay))^{-1} (A^T)^{-1} A^T \nabla f(Ay) = A^{-1}(\nabla^2 f(x))^{-1}\nabla f(x).\)
Do đó \(y^+ = y - A^{-1}\Delta x_{\text{nt}} \implies Ay^+ = x - \Delta x_{\text{nt}} = x^+\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại sao Gradient Descent thất bại:&lt;/strong&gt; Trong GD, bước cập nhật \(y^+ = y - t A^T \nabla f(Ay)\) khi nhân ngược với \(A\) trở thành \(Ay^+ = x - t (A A^T) \nabla f(x)\), bị méo đi bởi ma trận \(A A^T\) trừ khi \(A\) là ma trận trực giao.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-số-tính-bất-biến-affine-dưới-phép-kéo-giãn-trục-10-lần&quot;&gt;Giải thích: Kiểm chứng số tính bất biến affine dưới phép kéo giãn trục 10 lần&lt;/h3&gt;

&lt;p&gt;Xét hàm 1 chiều \(f(x) = e^x - 2x\) tại \(x^{(0)} = 1\), và thực hiện phép đổi đơn vị kéo giãn 10 lần \(x = 10y\) (tức \(A = 10\), điểm khởi tạo tương ứng \(y^{(0)} = 0.1\)). Hàm mới là \(g(y) = f(10y) = e^{10y} - 20y\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước Newton trong không gian gốc \(x\) (tại \(x^{(0)} = 1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(1) = e - 2 \approx 0.71828\), \(f&apos;&apos;(1) = e \approx 2.71828\).&lt;/li&gt;
      &lt;li&gt;\(x^{(1)} = 1 - \frac{e - 2}{e} = \frac{2}{e} \approx 0.73576\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước Newton trong không gian đổi đơn vị \(y\) (tại \(y^{(0)} = 0.1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g&apos;(0.1) = 10e^{1} - 20 = 10(e - 2)\).&lt;/li&gt;
      &lt;li&gt;\(g&apos;&apos;(0.1) = 100e^{1}\).&lt;/li&gt;
      &lt;li&gt;\(y^{(1)} = 0.1 - \frac{10(e - 2)}{100e} = 0.1 - \frac{e - 2}{10e} = \frac{2}{10e} \approx 0.073576\).&lt;/li&gt;
      &lt;li&gt;Đổi ngược sang không gian \(x\): \(10 y^{(1)} = \frac{2}{e} = x^{(1)}\) — &lt;strong&gt;khớp tuyệt đối!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh với Gradient Descent (cùng bước \(t = 0.1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Trong không gian \(x\): \(x^{(1)}_{\text{GD}} = 1 - 0.1(0.71828) = 0.92817\).&lt;/li&gt;
      &lt;li&gt;Trong không gian \(y\): \(y^{(1)}_{\text{GD}} = 0.1 - 0.1(7.1828) = -0.61828 \implies 10y^{(1)}_{\text{GD}} = -6.1828\) (bay vọt ra rất xa, khác hẳn \(0.92817\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Một tính chất quan trọng của phương pháp Newton là tính bất biến affine: hướng cập nhật không phụ thuộc vào các phép biến đổi affine của hệ tọa độ. Ngược lại, gradient descent không có tính chất này nên tốc độ hội tụ thay đổi tùy theo hệ tọa độ được chọn.&lt;/p&gt;

&lt;p&gt;Trang này chứng minh tính chất bất biến affine của phương pháp Newton.&lt;/p&gt;

&lt;h2 id=&quot;chứng-minh-tính-bất-biến-affine&quot;&gt;Chứng minh tính bất biến affine&lt;/h2&gt;
&lt;p&gt;Cho \(f:\mathbb{R}^{n}\rightarrow \mathbb{R}\) khả vi hai lần và ma trận không suy biến \(A\in \mathbb{R}^{n\times n}\). Định nghĩa hàm \(g(y) := f(Ay)\), tức là hàm \(g\) tại \(y\) có cùng giá trị với hàm \(f\) tại điểm biến đổi affine \(Ay\). Để tránh nhầm lẫn về ký hiệu và đối số của gradient, ta đặt \(x := Ay\).&lt;/p&gt;

&lt;p&gt;Áp dụng quy tắc chuỗi để lấy đạo hàm bậc nhất và bậc hai của \(g\), ta thu được:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\nabla g(y) &amp;amp;= A^{T} \nabla f(x)\\\\
\nabla^{2} g(y) &amp;amp;= A^{T}\nabla^{2}f(x)A,
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bước Newton của \(g\) theo biến \(y\) là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
y^{+}  = y-(\nabla^{2}g(y))^{-1}\nabla g(y).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Biểu diễn bước cập nhật này theo \(f\) và \(x\), ta suy ra bước Newton cho \(f\) tại \(x\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
y^{+} &amp;amp;= y-(A^{T}\nabla^{2}f(x)A)^{-1}A^{T} \nabla f(x)\\\\
\Leftrightarrow y^{+} &amp;amp;= y-A^{-1}(\nabla^{2}f(x))^{-1}(A^{T})^{-1}A^{T} \nabla f(x)\\\\
\Leftrightarrow Ay^{+} &amp;amp;= Ay-(\nabla^{2}f(x))^{-1}\nabla f(x)\\\\
\Leftrightarrow x^{+} &amp;amp;= x - \nabla^{2}f(x)^{-1}\nabla f(x).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Kết quả này cho thấy bước Newton bất biến affine: các bước cập nhật trong hệ tọa độ đã biến đổi bởi ma trận không suy biến \(A\) hoàn toàn tương đương với các bước cập nhật trong hệ tọa độ gốc.&lt;/p&gt;

&lt;p&gt;Thực hiện kiểm tra tương tự cho gradient descent, ta thu được:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
y^{+} &amp;amp;= y-t_{k}\cdot \nabla g(y)\\\\
\Leftrightarrow y^{+} &amp;amp;= y-t_{k}\cdot A^{T}\nabla f(x)\\\\
\Leftrightarrow x^{+} &amp;amp;= x - t_{k}\cdot AA^{T}\nabla f(x). 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Với gradient descent, do ma trận Hessian được xấp xỉ bởi \(\frac{1}{t}I\), hướng cập nhật bị thay đổi khi áp dụng phép biến đổi affine lên hệ tọa độ (trừ trường hợp đặc biệt \(AA^T\) tỉ lệ với ma trận đơn vị).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-02-01 Tìm nghiệm</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_02_01_root_finding/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_02_01_root_finding</id>
   <content type="html">&lt;p&gt;Vào thế kỷ 17, khi Isaac Newton và Joseph Raphson phát minh ra phương pháp lặp mang tên họ, mục tiêu ban đầu không phải là tối ưu hóa mà là &lt;strong&gt;tìm nghiệm của phương trình đại số&lt;/strong&gt; \(g(x) = 0\). Ý tưởng thật mộc mạc mà thiên tài: thay đường cong \(g(x)\) bằng đường tiếp tuyến tại điểm hiện tại \(x^{(k)}\), rồi xem tiếp tuyến cắt trục hoành ở đâu — điểm cắt đó chính là ước lượng mới \(x^{(k+1)}\).&lt;/p&gt;

&lt;p&gt;Khi bước sang thế giới tối ưu hóa, ta chỉ cần nhớ định lý Fermat cơ bản: điểm cực trị của hàm trơn \(f(x)\) là nghiệm của phương trình đạo hàm \(g(x) = f&apos;(x) = 0\). Thay \(g\) bằng \(f&apos;\) và \(g&apos;\) bằng \(f&apos;&apos;\) trong công thức tìm nghiệm Newton–Raphson, ta nhận ra &lt;strong&gt;tối ưu hóa Newton chính là tìm nghiệm Newton cho hàm gradient&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-tìm-nghiệm-newtonraphson-đến-tối-ưu-hóa-newton&quot;&gt;Kiến thức cần nhớ: Từ tìm nghiệm Newton–Raphson đến tối ưu hóa Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Công thức tìm nghiệm 1D và nhiều chiều:&lt;/strong&gt; Để giải \(g(x) = 0\), tuyến tính hóa \(g(x) + g&apos;(x)(y - x) = 0\) cho ra \(x^+ = x - \frac{g(x)}{g&apos;(x)}\) (hay \(x^+ = x - J_g(x)^{-1}g(x)\) với ma trận Jacobian \(J_g\) trong \(\mathbb{R}^n\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng cho điều kiện dừng \(\nabla f(x) = 0\):&lt;/strong&gt; Đặt \(g(x) = \nabla f(x)\), khi đó ma trận Jacobian của \(g\) chính là ma trận Hessian \(J_g(x) = \nabla^2 f(x)\), dẫn trực tiếp tới \(x^+ = x - (\nabla^2 f(x))^{-1}\nabla f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khác biệt quan trọng về bản chất điểm dừng:&lt;/strong&gt; Newton tìm nghiệm không phân biệt cực tiểu, cực đại hay điểm yên ngựa — vì cả ba đều thỏa \(\nabla f(x) = 0\)! Trong tối ưu hóa lồi, giả thiết \(\nabla^2 f(x) \succ 0\) mới đảm bảo nghiệm tìm được là cực tiểu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-sqrt10-bằng-newton-tìm-nghiệm-và-đối-chiếu-với-tối-ưu-hóa&quot;&gt;Giải thích: Tính tay \(\sqrt{10}\) bằng Newton tìm nghiệm và đối chiếu với tối ưu hóa&lt;/h3&gt;

&lt;p&gt;Giả sử ta muốn tính \(\sqrt{10} \approx 3.16227766\) — tức tìm nghiệm dương của \(g(x) = x^2 - 10 = 0\) (tương đương cực tiểu hóa hàm nguyên hàm \(f(x) = \frac{1}{3}x^3 - 10x\) trên \(x &amp;gt; 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập công thức lặp:&lt;/strong&gt; Vì \(g(x) = x^2 - 10\) và \(g&apos;(x) = 2x\):
\(x^{(k+1)} = x^{(k)} - \frac{(x^{(k)})^2 - 10}{2x^{(k)}} = \frac{1}{2}\left(x^{(k)} + \frac{10}{x^{(k)}}\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chạy từng bước từ \(x^{(0)} = 3\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; \(x^{(1)} = \frac{1}{2}\left(3 + \frac{10}{3}\right) = \frac{19}{6} \approx 3.166667\) (sai số: \(4.4 \times 10^{-3}\)).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt; \(x^{(2)} = \frac{1}{2}\left(3.166667 + \frac{10}{3.166667}\right) \approx 3.162281\) (sai số: \(3.0 \times 10^{-6}\)).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước 3:&lt;/strong&gt; \(x^{(3)} \approx 3.162277660168\) (sai số: \(&amp;lt; 10^{-12}\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhận xét về số chữ số đúng:&lt;/strong&gt; Từ \(2\) chữ số đúng (\(3.1\)) nhảy lên \(5\) chữ số đúng (\(3.1622\)) rồi \(11\) chữ số đúng — minh họa sống động quy luật bình phương sai số của Newton!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Mục này trình bày cách áp dụng phương pháp Newton cho bài toán tìm nghiệm và phân biệt nó với phương pháp Newton trong bài toán tối ưu hóa. [&lt;a href=&quot;https://en.wikipedia.org/wiki/Newton%27s_method_in_optimization&quot;&gt;Newton’s method in optimization&lt;/a&gt;][&lt;a href=&quot;https://en.wikipedia.org/wiki/Newton%27s_method&quot;&gt;Newton’s method in root finding&lt;/a&gt;]&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-newton-cho-bài-toán-tìm-nghiệm&quot;&gt;Phương pháp Newton cho bài toán tìm nghiệm&lt;/h2&gt;
&lt;p&gt;Xét hàm vector \(F:\mathbb{R}^{n}\rightarrow \mathbb{R}^{n}\). Bài toán tìm nghiệm yêu cầu tìm \(x\) thỏa mãn \(F(x) = 0\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
F(x) = 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Để giải bài toán này, ta chọn một điểm khởi tạo \(x^{(0)}\) và lặp theo công thức Newton:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{chọn điểm khởi tạo }x^{(0)}\in \mathbb{R}^{n},\\\\
&amp;amp;x^{(k)}=x^{(k-1)}-\nabla F(x^{(k-1)})^{-1}F(x^{(k-1)}), \qquad k=1,2,3,...\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây, \(\nabla F(x^{(k-1)})\) là ma trận Jacobian của \(F\) tại \(x^{(k-1)}\). Bước Newton \(x^{+}=x-\nabla F(x)^{-1}F(x)\) được dẫn xuất bằng cách cho xấp xỉ tuyến tính của \(F\) bằng không:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
F(y)\approx F(x) + F^{&apos;}(x)(y-x) = 0\\\\
y = x^{+}=x-F^{&apos;}(x)^{-1}F(x).
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;phương-pháp-newton-cho-bài-toán-tối-ưu-hóa&quot;&gt;Phương pháp Newton cho bài toán tối ưu hóa&lt;/h2&gt;
&lt;p&gt;Xét bài toán tối ưu hóa không ràng buộc:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} F(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Áp dụng phương pháp Newton cho bài toán này tương đương với việc áp dụng phương pháp Newton tìm nghiệm cho phương trình gradient \(\nabla{F(x)}=0\).&lt;/p&gt;

&lt;p&gt;Tóm lại, bài toán tìm nghiệm tìm không điểm của chính hàm \(F\) (\(F=0\)), còn bài toán tối ưu hóa tìm không điểm của đạo hàm \(\nabla F=0\). Vì thế, bậc đạo hàm xuất hiện trong công thức cập nhật \(x\) ở hai bài toán chênh nhau một bậc.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-tìm-nghiệm&quot;&gt;Ví dụ tìm nghiệm&lt;/h2&gt;
&lt;p&gt;Xét hàm \(F:\mathbb{R}\rightarrow\mathbb{R}\) định nghĩa bởi:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
F(x)=x^{2}-2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Xuất phát từ \(x^{(0)}=1\) và áp dụng phương pháp Newton thuần túy, ta thu được bảng kết quả sau:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter14/table1.jpeg&quot; alt=&quot;&quot; width=&quot;90%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Phương pháp Newton áp dụng cho ví dụ tìm nghiệm [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Khi số vòng lặp \(k\) tăng lên, giá trị \(x\) hội tụ nhanh về nghiệm \(\sqrt 2\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-01 Phương pháp Newton</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_01_newton_method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_01_newton_method</id>
   <content type="html">&lt;p&gt;Trong các chương trước, mọi biến thể của Gradient Descent đều có chung một công thức cốt lõi: đi ngược hướng đạo hàm bậc nhất \(-\nabla f(x)\). Cách đi ấy đơn giản và rẻ, nhưng nó hoàn toàn “mù” trước việc hàm số cong mạnh theo trục này và phẳng lỳ theo trục kia.&lt;/p&gt;

&lt;p&gt;Phương pháp Newton giải quyết điểm mù đó bằng một bước nhảy mang tính cách mạng: thay vì chỉ dùng gradient, nó nhân gradient với &lt;strong&gt;nghịch đảo ma trận Hessian&lt;/strong&gt; \((\nabla^2 f(x))^{-1}\). Bước cập nhật \(x^+ = x - (\nabla^2 f(x))^{-1}\nabla f(x)\) nghe có vẻ chỉ khác một ma trận, nhưng nó thay đổi hoàn toàn bản chất hình học và tốc độ hội tụ của thuật toán tối ưu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-bước-cập-nhật-newton-thuần-túy&quot;&gt;Kiến thức cần nhớ: Giải phẫu bước cập nhật Newton thuần túy&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ma trận Hessian \(\nabla^2 f(x)\):&lt;/strong&gt; Ma trận đối xứng cấp \(n \times n\) chứa tất cả các đạo hàm riêng cấp hai \(\frac{\partial^2 f}{\partial x_i \partial x_j}\). Khi \(f\) lồi mạnh, \(\nabla^2 f(x) \succ 0\) (xác định dương), đảm bảo nghịch đảo tồn tại và hướng Newton luôn là &lt;strong&gt;hướng giảm&lt;/strong&gt; (\(\nabla f(x)^T v_{\text{nt}} &amp;lt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hướng Newton và giải hệ tuyến tính:&lt;/strong&gt; Trong thực hành, người ta không bao giờ tính tường minh ma trận nghịch đảo \((\nabla^2 f(x))^{-1}\) mà giải hệ tuyến tính \(\nabla^2 f(x)\,\Delta x = -\nabla f(x)\) (ví dụ bằng phân rã Cholesky), vừa nhanh hơn vừa ổn định số hơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bậc nhất vs. Bậc hai:&lt;/strong&gt; Gradient Descent giả định độ cong đẳng hướng \(\frac{1}{t}I\) ở mọi hướng, còn phương pháp Newton dùng đúng ma trận độ cong cục bộ \(\nabla^2 f(x)\), nên tự động điều chỉnh kích thước bước khác nhau trên từng phương chính của thung lũng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-2-vòng-lặp-newton-cho-một-hàm-phi-tuyến-1-chiều&quot;&gt;Giải thích: Tính tay 2 vòng lặp Newton cho một hàm phi tuyến 1 chiều&lt;/h3&gt;

&lt;p&gt;Xét hàm lồi chặt không phải bậc hai:&lt;/p&gt;

\[f(x) = e^x + x^2 - 4x.\]

&lt;p&gt;Ta có \(f&apos;(x) = e^x + 2x - 4\) và \(f&apos;&apos;(x) = e^x + 2 &amp;gt; 0\) với mọi \(x\). Xuất phát từ \(x^{(0)} = 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 1 (tại \(x^{(0)} = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(0) = e^0 + 0 - 4 = -3\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;(0) = e^0 + 2 = 3\).&lt;/li&gt;
      &lt;li&gt;Bước Newton: \(x^{(1)} = 0 - \frac{-3}{3} = 1.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 2 (tại \(x^{(1)} = 1.0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(1) = e^1 + 2(1) - 4 \approx 2.71828 - 2 = 0.71828\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;(1) = e^1 + 2 \approx 4.71828\).&lt;/li&gt;
      &lt;li&gt;Bước Newton: \(x^{(2)} = 1.0 - \frac{0.71828}{4.71828} \approx 1.0 - 0.15223 = 0.84777\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra độ chính xác:&lt;/strong&gt; Tại \(x^{(2)} = 0.84777\), đạo hàm \(f&apos;(0.84777) \approx e^{0.84777} + 1.69554 - 4 \approx 2.33444 + 1.69554 - 4 = 0.02998\) (giảm từ \(-3\) xuống \(0.03\) chỉ sau 2 bước; nghiệm thật là \(x^\star \approx 0.8409\)!).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Các phương pháp gradient descent đã thảo luận ở các chương trước thuộc nhóm &lt;strong&gt;phương pháp bậc nhất&lt;/strong&gt;, vì bước cập nhật chỉ sử dụng đạo hàm bậc nhất của hàm mục tiêu. Ngược lại, phương pháp Newton là &lt;strong&gt;phương pháp bậc hai&lt;/strong&gt;, nghĩa là cần tính cả đạo hàm bậc hai.&lt;/p&gt;

&lt;p&gt;Xét bài toán tối ưu hóa không ràng buộc đối với hàm lồi, khả vi hai lần \(f\) có miền xác định \(\text{dom}(f) = \mathbb{R}^{n}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} f(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong &lt;a href=&quot;/contents/vi/chapter06/06_00_gradient_descent/&quot;&gt;Gradient descent&lt;/a&gt;, ta áp dụng quy trình sau cho hàm \(f\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Lập xấp xỉ Taylor bậc hai của \(f\).&lt;/li&gt;
  &lt;li&gt;Thay ma trận Hessian ở số hạng bậc hai bằng \(I/t\) (ma trận đơn vị chia cho kích thước bước \(t\)).&lt;/li&gt;
  &lt;li&gt;Cực tiểu hóa xấp xỉ bậc hai này để thu được bước cập nhật.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chi tiết cách dẫn xuất bước cập nhật của gradient descent được trình bày ở trang tiếp theo. Công thức cập nhật tại mỗi vòng lặp là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{chọn điểm khởi tạo } x^{(0)} \in \mathbb{R}^{n},\\\\
&amp;amp;x^{(k)} = x^{(k-1)} - t_{k} \cdot \nabla f(x^{(k-1)}), \qquad k = 1,2,3,...
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Phương pháp Newton (phương pháp Newton thuần túy) giữ nguyên số hạng đạo hàm bậc hai thực tế thay vì xấp xỉ bằng \(\frac{1}{t}I\) như trong gradient descent, rồi cực tiểu hóa xấp xỉ bậc hai để cập nhật nghiệm. Cách dẫn xuất cụ thể cũng được trình bày ở trang tiếp theo. Công thức cập nhật tại mỗi vòng lặp là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{chọn điểm khởi tạo } x^{(0)} \in \mathbb{R}^{n},\\\\
&amp;amp;x^{(k)} = x^{(k-1)} - \Big(\nabla^{2}f(x^{(k-1)})\Big)^{-1} \nabla f(x^{(k-1)}), \qquad k = 1,2,3,...
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>14-01-02 Phương Pháp Newton Có Di Chuyển Vuông Góc Với Đường Đồng Mức Hay Không?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_01_02_newton_perpendicular_analysis/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_01_02_newton_perpendicular_analysis</id>
   <content type="html">&lt;p&gt;Một hiểu lầm kinh điển mà rất nhiều người học tối ưu mắc phải là: &lt;em&gt;“Vì Gradient Descent đi vuông góc với đường đồng mức, nên phương pháp Newton — một thuật toán thông minh hơn — chắc cũng đi vuông góc với đường đồng mức, chỉ là bước dài hơn?”&lt;/em&gt; Câu trả lời là &lt;strong&gt;KHÔNG!&lt;/strong&gt; Và chính việc &lt;strong&gt;không&lt;/strong&gt; đi vuông góc với đường đồng mức mới là bí mật giúp phương pháp Newton thắng áp đảo Gradient Descent trong các thung lũng elip kéo dài.&lt;/p&gt;

&lt;p&gt;Khi đường đồng mức là những hình elip dẹt, hướng vuông góc với đường đồng mức (\(-\nabla f(x)\)) lại chỉ chéo vào thành hẻm núi chứ không hề chỉ về tâm elip. Phương pháp Newton bẻ lệch hướng đi bằng cách nhân với \((\nabla^2 f(x))^{-1}\), bỏ qua sự “cám dỗ” của hướng dốc cục bộ để ngắm thẳng vào tâm đáy.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-đường-đồng-mức-và-góc-lệch-của-hướng-newton&quot;&gt;Kiến thức cần nhớ: Hình học đường đồng mức và góc lệch của hướng Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trực giao của Gradient:&lt;/strong&gt; Đường đồng mức \(\{x : f(x) = c\}\) có vectơ pháp tuyến chính là \(\nabla f(x)\). Do đó \(-\nabla f(x)\) luôn vuông góc tuyệt đối với tiếp tuyến của đường đồng mức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện để hướng Newton vuông góc với đường đồng mức:&lt;/strong&gt; Hướng Newton \(d_{\text{nt}} = -(\nabla^2 f(x))^{-1}\nabla f(x)\) chỉ cùng phương với \(-\nabla f(x)\) (tức vuông góc đường đồng mức) khi và chỉ khi \(\nabla f(x)\) là một &lt;strong&gt;vectơ riêng&lt;/strong&gt; của ma trận Hessian \(\nabla^2 f(x)\) (chẳng hạn khi \(\nabla^2 f(x) = \lambda I\) đẳng hướng, hoặc \(x\) nằm đúng trên một trục chính của elip).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất hướng giảm bất chấp góc lệch:&lt;/strong&gt; Dù không vuông góc với đường đồng mức, miễn là \(\nabla^2 f(x) \succ 0\), góc giữa \(d_{\text{nt}}\) và \(-\nabla f(x)\) luôn là góc nhọn vì \((-\nabla f)^T d_{\text{nt}} = \nabla f^T (\nabla^2 f)^{-1}\nabla f &amp;gt; 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-góc-lệch-giữa-hướng-newton-và-pháp-tuyến-đường-đồng-mức&quot;&gt;Giải thích: Tính góc lệch giữa hướng Newton và pháp tuyến đường đồng mức&lt;/h3&gt;

&lt;p&gt;Xét hàm elip \(f(x_1, x_2) = \frac{1}{2}x_1^2 + 4x_2^2\) tại điểm \(x = (2, 1)^T\) (không nằm trên trục tọa độ).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính gradient và hướng Gradient Descent (vuông góc đường đồng mức):&lt;/strong&gt;
\(\nabla f(2, 1) = \begin{bmatrix} 2 \\ 8 \end{bmatrix} \implies d_{\text{GD}} = \begin{bmatrix} -2 \\ -8 \end{bmatrix}.\)
Lưu ý: vectơ tiếp tuyến đường đồng mức tại \((2, 1)\) là \(t = (8, -2)^T\), dễ thấy \(d_{\text{GD}}^T t = -16 + 16 = 0\) (vuông góc \(90^\circ\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hướng Newton:&lt;/strong&gt;
Hessian là \(H = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 8 \end{bmatrix}\), nên \(H^{-1} = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1/8 \end{bmatrix}\).
\(d_{\text{nt}} = -H^{-1}\nabla f(2, 1) = \begin{bmatrix} -2 \\ -1 \end{bmatrix}.\)
Chú ý \(x + d_{\text{nt}} = (2, 1)^T + (-2, -1)^T = (0, 0)^T\) — chỉ thẳng vào đáy!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra góc giữa \(d_{\text{nt}}\) và \(d_{\text{GD}}\) (và góc với tiếp tuyến \(t\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\cos\theta = \frac{d_{\text{GD}}^T d_{\text{nt}}}{\|d_{\text{GD}}\|_2 \|d_{\text{nt}}\|_2} = \frac{(-2)(-2) + (-8)(-1)}{\sqrt{68}\sqrt{5}} = \frac{12}{\sqrt{340}} \approx 0.6508 \implies \theta \approx 49.4^\circ\)!&lt;/li&gt;
      &lt;li&gt;Tích vô hướng với tiếp tuyến \(t = (8, -2)^T\): \(d_{\text{nt}}^T t = -16 + 2 = -14 \ne 0\).
Hướng Newton lệch gần \(50^\circ\) khỏi phương vuông góc đường đồng mức — và chính góc “bẻ lái” đó đưa nó đi thẳng một mạch tới nghiệm tối ưu!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;,
    tex2jax: {
        inlineMath: [[&apos;$&apos;, &apos;$&apos;], [&apos;\\(&apos;, &apos;\\)&apos;]],
        displayMath: [[&apos;$$&apos;, &apos;$$&apos;], [&apos;\\[&apos;, &apos;\\]&apos;]]
    }
});
&lt;/script&gt;

&lt;style&gt;
.interactive-container {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    align-items: center;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-weight: bold;
    font-size: 0.9em;
    color: #495057;
}

.control-group input[type=&quot;range&quot;] {
    width: 150px;
}

.control-group input[type=&quot;number&quot;] {
    width: 80px;
    padding: 4px;
    border: 1px solid #ced4da;
    border-radius: 4px;
}

button {
    background: #007bff;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}

button:hover {
    background: #0056b3;
}

button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

#canvas {
    border: 1px solid #dee2e6;
    border-radius: 4px;
    display: block;
    margin: 0 auto;
}

.info-panel {
    background: #e9ecef;
    padding: 15px;
    border-radius: 4px;
    margin-top: 15px;
    font-family: monospace;
    font-size: 0.85em;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
    font-size: 0.9em;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.legend-color {
    width: 20px;
    height: 3px;
    border-radius: 2px;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

.comparison-table th,
.comparison-table td {
    border: 1px solid #dee2e6;
    padding: 12px;
    text-align: left;
}

.comparison-table th {
    background: #f8f9fa;
    font-weight: bold;
}

.math-explanation {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    padding: 15px;
    margin: 15px 0;
}

.key-insight {
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    border-radius: 4px;
    padding: 15px;
    margin: 15px 0;
}
&lt;/style&gt;

&lt;p&gt;Trong bài học này, chúng ta xét một câu hỏi quan trọng trong tối ưu hóa: &lt;strong&gt;Phương pháp Newton có di chuyển vuông góc với đường đồng mức hay không?&lt;/strong&gt; Câu hỏi này làm rõ sự khác biệt hình học giữa phương pháp Newton và gradient descent.&lt;/p&gt;

&lt;h2 id=&quot;1-trực-giác-cơ-bản&quot;&gt;1. Trực giác cơ bản&lt;/h2&gt;

&lt;div class=&quot;key-insight&quot;&gt;
&lt;strong&gt;Câu trả lời ngắn gọn:&lt;/strong&gt; &lt;strong&gt;Không.&lt;/strong&gt; Khác với gradient descent, phương pháp Newton nhìn chung không di chuyển vuông góc với đường đồng mức.
&lt;/div&gt;

&lt;h3 id=&quot;so-sánh-với-gradient-descent&quot;&gt;So sánh với Gradient Descent&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent&lt;/strong&gt;: Luôn di chuyển theo hướng \(-
abla f\), vuông góc với đường đồng mức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp Newton&lt;/strong&gt;: Sử dụng thông tin đạo hàm bậc hai (ma trận Hessian) để điều chỉnh hướng di chuyển, nên hướng bước đi không còn vuông góc với đường đồng mức trong hệ tọa độ gốc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-giải-thích-toán-học&quot;&gt;2. Giải thích toán học&lt;/h2&gt;

&lt;h3 id=&quot;gradient-descent&quot;&gt;Gradient Descent&lt;/h3&gt;
&lt;p&gt;Hướng di chuyển trong gradient descent là:
\(\mathbf{d}_{GD} = -
abla f(\mathbf{x})\)&lt;/p&gt;

&lt;p&gt;Hướng này luôn vuông góc với đường đồng mức vì gradient là vector pháp tuyến của đường đồng mức.&lt;/p&gt;

&lt;h3 id=&quot;phương-pháp-newton&quot;&gt;Phương pháp Newton&lt;/h3&gt;
&lt;p&gt;Hướng di chuyển trong phương pháp Newton là:
\(\mathbf{d}_{Newton} = -[
abla^2 f(\mathbf{x})]^{-1} 
abla f(\mathbf{x})\)&lt;/p&gt;

&lt;div class=&quot;math-explanation&quot;&gt;
&lt;strong&gt;Giải thích:&lt;/strong&gt; Ma trận Hessian $$
abla^2 f$$ đóng vai trò biến đổi hình học không gian, làm cho hướng bước đi không còn vuông góc với đường đồng mức trong hệ tọa độ gốc. Phương pháp Newton thực chất đi theo hướng giảm nhanh nhất trong không gian đã được chuẩn hóa theo độ cong của Hessian.
&lt;/div&gt;

&lt;h3 id=&quot;khi-nào-hướng-newton-vuông-góc-với-đường-đồng-mức&quot;&gt;Khi nào hướng Newton vuông góc với đường đồng mức?&lt;/h3&gt;
&lt;p&gt;Khi ma trận Hessian tỉ lệ với ma trận đơn vị (\(abla^2 f = cI\) với hằng số \(c &amp;gt; 0\)), bước Newton trùng hướng với gradient descent (với kích thước bước \(1/c\)) và vuông góc với đường đồng mức. Tổng quát hơn, bước Newton chỉ vuông góc với đường đồng mức tại các điểm mà \(abla f\) là một vector riêng của Hessian (chẳng hạn dọc theo các trục tọa độ khi Hessian là ma trận đường chéo).&lt;/p&gt;

&lt;h2 id=&quot;3-minh-họa-tương-tác&quot;&gt;3. Minh họa tương tác&lt;/h2&gt;

&lt;div class=&quot;interactive-container&quot;&gt;
    &lt;h4&gt;So sánh quỹ đạo phương pháp Newton và Gradient Descent&lt;/h4&gt;
    
    &lt;div class=&quot;controls&quot;&gt;
        &lt;div class=&quot;control-group&quot;&gt;
            &lt;label for=&quot;a-param&quot;&gt;Tham số a (độ cong theo x):&lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;a-param&quot; min=&quot;1&quot; max=&quot;20&quot; value=&quot;10&quot; step=&quot;1&quot; /&gt;
            &lt;input type=&quot;number&quot; id=&quot;a-value&quot; min=&quot;1&quot; max=&quot;20&quot; value=&quot;10&quot; step=&quot;1&quot; /&gt;
        &lt;/div&gt;
        
        &lt;div class=&quot;control-group&quot;&gt;
            &lt;label for=&quot;b-param&quot;&gt;Tham số b (độ cong theo y):&lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;b-param&quot; min=&quot;1&quot; max=&quot;20&quot; value=&quot;1&quot; step=&quot;1&quot; /&gt;
            &lt;input type=&quot;number&quot; id=&quot;b-value&quot; min=&quot;1&quot; max=&quot;20&quot; value=&quot;1&quot; step=&quot;1&quot; /&gt;
        &lt;/div&gt;
        
        &lt;div class=&quot;control-group&quot;&gt;
            &lt;label for=&quot;start-x&quot;&gt;Điểm bắt đầu x:&lt;/label&gt;
            &lt;input type=&quot;number&quot; id=&quot;start-x&quot; min=&quot;-3&quot; max=&quot;3&quot; value=&quot;2&quot; step=&quot;0.1&quot; /&gt;
        &lt;/div&gt;
        
        &lt;div class=&quot;control-group&quot;&gt;
            &lt;label for=&quot;start-y&quot;&gt;Điểm bắt đầu y:&lt;/label&gt;
            &lt;input type=&quot;number&quot; id=&quot;start-y&quot; min=&quot;-3&quot; max=&quot;3&quot; value=&quot;1.5&quot; step=&quot;0.1&quot; /&gt;
        &lt;/div&gt;
        
        &lt;div class=&quot;control-group&quot;&gt;
            &lt;label for=&quot;learning-rate&quot;&gt;Kích thước bước (GD):&lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;learning-rate&quot; min=&quot;0.01&quot; max=&quot;0.5&quot; value=&quot;0.1&quot; step=&quot;0.01&quot; /&gt;
            &lt;input type=&quot;number&quot; id=&quot;lr-value&quot; min=&quot;0.01&quot; max=&quot;0.5&quot; value=&quot;0.1&quot; step=&quot;0.01&quot; /&gt;
        &lt;/div&gt;
        
        &lt;button id=&quot;start-btn&quot;&gt;Bắt đầu&lt;/button&gt;
        &lt;button id=&quot;step-btn&quot;&gt;Từng bước&lt;/button&gt;
        &lt;button id=&quot;reset-btn&quot;&gt;Đặt lại&lt;/button&gt;
        &lt;button id=&quot;toggle-contour&quot;&gt;Ẩn/Hiện đường đồng mức&lt;/button&gt;
    &lt;/div&gt;
    
    &lt;canvas id=&quot;canvas&quot; width=&quot;600&quot; height=&quot;500&quot;&gt;&lt;/canvas&gt;
    
    &lt;div class=&quot;legend&quot;&gt;
        &lt;div class=&quot;legend-item&quot;&gt;
            &lt;div class=&quot;legend-color&quot; style=&quot;background: #ff4444;&quot;&gt;&lt;/div&gt;
            &lt;span&gt;Gradient Descent (vuông góc với đường đồng mức)&lt;/span&gt;
        &lt;/div&gt;
        &lt;div class=&quot;legend-item&quot;&gt;
            &lt;div class=&quot;legend-color&quot; style=&quot;background: #4444ff;&quot;&gt;&lt;/div&gt;
            &lt;span&gt;Phương pháp Newton (cắt chéo qua đường đồng mức)&lt;/span&gt;
        &lt;/div&gt;
        &lt;div class=&quot;legend-item&quot;&gt;
            &lt;div class=&quot;legend-color&quot; style=&quot;background: #888888;&quot;&gt;&lt;/div&gt;
            &lt;span&gt;Đường đồng mức&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div id=&quot;info-panel&quot; class=&quot;info-panel&quot;&gt;
        Hàm mục tiêu: f(x,y) = (ax² + by²)/2&lt;br /&gt;
        Nhấn &quot;Bắt đầu&quot; để xem so sánh quỹ đạo của hai phương pháp
    &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;4-phân-tích-chi-tiết&quot;&gt;4. Phân tích chi tiết&lt;/h2&gt;

&lt;table class=&quot;comparison-table&quot;&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Đặc điểm&lt;/th&gt;
            &lt;th&gt;Gradient Descent&lt;/th&gt;
            &lt;th&gt;Phương pháp Newton&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;strong&gt;Hướng di chuyển&lt;/strong&gt;&lt;/td&gt;
            &lt;td&gt;$$-
abla f$$ (vuông góc với đường đồng mức)&lt;/td&gt;
            &lt;td&gt;$$-H^{-1}
abla f$$ (nhìn chung không vuông góc)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;strong&gt;Thông tin sử dụng&lt;/strong&gt;&lt;/td&gt;
            &lt;td&gt;Chỉ gradient (đạo hàm bậc nhất)&lt;/td&gt;
            &lt;td&gt;Gradient và Hessian (đạo hàm bậc hai)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;strong&gt;Tốc độ hội tụ&lt;/strong&gt;&lt;/td&gt;
            &lt;td&gt;Tuyến tính&lt;/td&gt;
            &lt;td&gt;Bậc hai (trong lân cận điểm tối ưu)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;strong&gt;Xử lý bài toán có số điều kiện xấu&lt;/strong&gt;&lt;/td&gt;
            &lt;td&gt;Kém (dễ dao động zíc-zắc)&lt;/td&gt;
            &lt;td&gt;Tốt (hướng trực tiếp về cực tiểu)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;strong&gt;Chi phí tính toán&lt;/strong&gt;&lt;/td&gt;
            &lt;td&gt;O(n) mỗi bước&lt;/td&gt;
            &lt;td&gt;O(n³) mỗi bước&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;5-ví-dụ-cụ-thể&quot;&gt;5. Ví dụ cụ thể&lt;/h2&gt;

&lt;p&gt;Xét hàm \(f(x,y) = x^2 + 10y^2\) có các đường đồng mức là các elip dẹt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tại điểm (1, 1):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient&lt;/strong&gt;: \(abla f = (2, 20)\) — vuông góc với đường elip.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hessian&lt;/strong&gt;: \(H = egin{pmatrix} 2 &amp;amp; 0 \ 0 &amp;amp; 20 \end{pmatrix}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hướng Newton&lt;/strong&gt;: \(\mathbf{d} = -H^{-1}
abla f = -egin{pmatrix} 1/2 &amp;amp; 0 \ 0 &amp;amp; 1/20 \end{pmatrix} egin{pmatrix} 2 \ 20 \end{pmatrix} = (-1, -1)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;key-insight&quot;&gt;
&lt;strong&gt;Quan sát:&lt;/strong&gt; Gradient descent đi theo hướng (-2, -20) (vuông góc với đường đồng mức), trong khi phương pháp Newton đi theo hướng (-1, -1) (cắt chéo qua các đường elip hướng thẳng về gốc tọa độ).
&lt;/div&gt;

&lt;h2 id=&quot;6-ý-nghĩa-thực-tiễn&quot;&gt;6. Ý nghĩa thực tiễn&lt;/h2&gt;

&lt;h3 id=&quot;ưu-điểm-của-phương-pháp-newton&quot;&gt;Ưu điểm của phương pháp Newton&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Xử lý tốt bài toán có số điều kiện xấu&lt;/strong&gt;: Hiệu quả khi hàm có độ cong chênh lệch lớn giữa các hướng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ nhanh&lt;/strong&gt;: Đạt tốc độ bậc hai khi gần điểm tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất biến affine&lt;/strong&gt;: Quỹ đạo không phụ thuộc vào phép biến đổi affine của hệ tọa độ.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;nhược-điểm&quot;&gt;Nhược điểm&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí tính toán cao&lt;/strong&gt;: Cần tính ma trận Hessian và giải hệ tuyến tính cỡ \(n 	imes n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhạy cảm với tính xác định dương&lt;/strong&gt;: Có thể không ổn định nếu Hessian không xác định dương.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khó mở rộng với số chiều rất lớn&lt;/strong&gt;: Chi phí \(O(n^3)\) mỗi bước trở nên tốn kém khi \(n\) lớn.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;7-ứng-dụng-trong-học-máy&quot;&gt;7. Ứng dụng trong học máy&lt;/h2&gt;

&lt;p&gt;Trong thực tế, người ta thường dùng các biến thể của phương pháp Newton:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;L-BFGS&lt;/strong&gt;: Xấp xỉ nghịch đảo Hessian với bộ nhớ giới hạn, tránh tính toán toàn bộ Hessian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gauss-Newton&lt;/strong&gt;: Dành cho các bài toán bình phương tối thiểu phi tuyến.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Levenberg-Marquardt&lt;/strong&gt;: Kết hợp ưu điểm của gradient descent và phương pháp Newton thông qua tham số điều chuẩn.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;math-explanation&quot;&gt;
&lt;strong&gt;Kết luận:&lt;/strong&gt; Phương pháp Newton không di chuyển vuông góc với đường đồng mức vì nó tối ưu hóa trong không gian đã được biến đổi theo độ cong của Hessian. Nhờ đó, thuật toán hội tụ nhanh hơn đáng kể dù chi phí tính toán mỗi bước cao hơn.
&lt;/div&gt;

&lt;script&gt;
class OptimizationVisualizer {
    constructor() {
        this.canvas = document.getElementById(&apos;canvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        // Parameters
        this.a = 10;
        this.b = 1;
        this.startX = 2;
        this.startY = 1.5;
        this.learningRate = 0.1;
        
        // Visualization settings
        this.scale = 80;
        this.centerX = this.width / 2;
        this.centerY = this.height / 2;
        this.showContour = true;
        
        // Animation state
        this.isRunning = false;
        this.gdPath = [];
        this.newtonPath = [];
        this.currentStep = 0;
        this.maxSteps = 20;
        
        this.setupEventListeners();
        this.reset();
    }
    
    setupEventListeners() {
        // Parameter controls
        const aParam = document.getElementById(&apos;a-param&apos;);
        const aValue = document.getElementById(&apos;a-value&apos;);
        const bParam = document.getElementById(&apos;b-param&apos;);
        const bValue = document.getElementById(&apos;b-value&apos;);
        const lrParam = document.getElementById(&apos;learning-rate&apos;);
        const lrValue = document.getElementById(&apos;lr-value&apos;);
        
        // Sync sliders with number inputs
        aParam.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.a = parseFloat(e.target.value);
            aValue.value = this.a;
            this.reset();
        });
        
        aValue.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.a = parseFloat(e.target.value);
            aParam.value = this.a;
            this.reset();
        });
        
        bParam.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.b = parseFloat(e.target.value);
            bValue.value = this.b;
            this.reset();
        });
        
        bValue.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.b = parseFloat(e.target.value);
            bParam.value = this.b;
            this.reset();
        });
        
        lrParam.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.learningRate = parseFloat(e.target.value);
            lrValue.value = this.learningRate;
        });
        
        lrValue.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.learningRate = parseFloat(e.target.value);
            lrParam.value = this.learningRate;
        });
        
        // Start position controls
        document.getElementById(&apos;start-x&apos;).addEventListener(&apos;input&apos;, (e) =&gt; {
            this.startX = parseFloat(e.target.value);
            this.reset();
        });
        
        document.getElementById(&apos;start-y&apos;).addEventListener(&apos;input&apos;, (e) =&gt; {
            this.startY = parseFloat(e.target.value);
            this.reset();
        });
        
        // Buttons
        document.getElementById(&apos;start-btn&apos;).addEventListener(&apos;click&apos;, () =&gt; this.startAnimation());
        document.getElementById(&apos;step-btn&apos;).addEventListener(&apos;click&apos;, () =&gt; this.stepAnimation());
        document.getElementById(&apos;reset-btn&apos;).addEventListener(&apos;click&apos;, () =&gt; this.reset());
        document.getElementById(&apos;toggle-contour&apos;).addEventListener(&apos;click&apos;, () =&gt; this.toggleContour());
    }
    
    // Objective function: f(x,y) = (ax² + by²)/2
    f(x, y) {
        return (this.a * x * x + this.b * y * y) / 2;
    }
    
    // Gradient: ∇f = (ax, by)
    gradient(x, y) {
        return [this.a * x, this.b * y];
    }
    
    // Hessian: H = [[a, 0], [0, b]]
    hessian(x, y) {
        return [[this.a, 0], [0, this.b]];
    }
    
    // Matrix inverse for 2x2
    inverse2x2(matrix) {
        const [[a, b], [c, d]] = matrix;
        const det = a * d - b * c;
        if (Math.abs(det) &lt; 1e-10) return null;
        return [[d/det, -b/det], [-c/det, a/det]];
    }
    
    // Matrix-vector multiplication
    matVecMul(matrix, vector) {
        const [x, y] = vector;
        return [
            matrix[0][0] * x + matrix[0][1] * y,
            matrix[1][0] * x + matrix[1][1] * y
        ];
    }
    
    // Gradient descent step
    gradientDescentStep(x, y) {
        const [gx, gy] = this.gradient(x, y);
        return [
            x - this.learningRate * gx,
            y - this.learningRate * gy
        ];
    }
    
    // Newton method step
    newtonStep(x, y) {
        const [gx, gy] = this.gradient(x, y);
        const H = this.hessian(x, y);
        const Hinv = this.inverse2x2(H);
        
        if (!Hinv) return [x, y]; // Fallback if Hessian is singular
        
        const [dx, dy] = this.matVecMul(Hinv, [gx, gy]);
        return [x - dx, y - dy];
    }
    
    // Convert world coordinates to canvas coordinates
    worldToCanvas(x, y) {
        return [
            this.centerX + x * this.scale,
            this.centerY - y * this.scale
        ];
    }
    
    // Convert canvas coordinates to world coordinates
    canvasToWorld(canvasX, canvasY) {
        return [
            (canvasX - this.centerX) / this.scale,
            -(canvasY - this.centerY) / this.scale
        ];
    }
    
    drawContourLines() {
        if (!this.showContour) return;
        
        this.ctx.strokeStyle = &apos;#888888&apos;;
        this.ctx.lineWidth = 1;
        
        const levels = [0.5, 1, 2, 4, 8, 16];
        
        for (const level of levels) {
            this.ctx.beginPath();
            
            // Draw ellipse for level set f(x,y) = level
            // (ax² + by²)/2 = level =&gt; ax² + by² = 2*level
            // x²/(2*level/a) + y²/(2*level/b) = 1
            const radiusX = Math.sqrt(2 * level / this.a) * this.scale;
            const radiusY = Math.sqrt(2 * level / this.b) * this.scale;
            
            this.ctx.ellipse(this.centerX, this.centerY, radiusX, radiusY, 0, 0, 2 * Math.PI);
            this.ctx.stroke();
        }
    }
    
    drawPath(path, color, label) {
        if (path.length &lt; 2) return;
        
        this.ctx.strokeStyle = color;
        this.ctx.lineWidth = 3;
        this.ctx.beginPath();
        
        const [startCanvasX, startCanvasY] = this.worldToCanvas(path[0][0], path[0][1]);
        this.ctx.moveTo(startCanvasX, startCanvasY);
        
        for (let i = 1; i &lt; path.length; i++) {
            const [canvasX, canvasY] = this.worldToCanvas(path[i][0], path[i][1]);
            this.ctx.lineTo(canvasX, canvasY);
        }
        this.ctx.stroke();
        
        // Draw points
        this.ctx.fillStyle = color;
        for (let i = 0; i &lt; path.length; i++) {
            const [canvasX, canvasY] = this.worldToCanvas(path[i][0], path[i][1]);
            this.ctx.beginPath();
            this.ctx.arc(canvasX, canvasY, i === 0 ? 6 : 4, 0, 2 * Math.PI);
            this.ctx.fill();
        }
        
        // Draw arrows for direction
        for (let i = 0; i &lt; path.length - 1; i++) {
            const [x1, y1] = this.worldToCanvas(path[i][0], path[i][1]);
            const [x2, y2] = this.worldToCanvas(path[i+1][0], path[i+1][1]);
            this.drawArrow(x1, y1, x2, y2, color);
        }
    }
    
    drawArrow(x1, y1, x2, y2, color) {
        const dx = x2 - x1;
        const dy = y2 - y1;
        const length = Math.sqrt(dx * dx + dy * dy);
        
        if (length &lt; 5) return;
        
        const angle = Math.atan2(dy, dx);
        const arrowLength = 10;
        const arrowAngle = Math.PI / 6;
        
        this.ctx.strokeStyle = color;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        
        // Arrow head
        const headX = x2 - arrowLength * Math.cos(angle - arrowAngle);
        const headY = y2 - arrowLength * Math.sin(angle - arrowAngle);
        this.ctx.moveTo(x2, y2);
        this.ctx.lineTo(headX, headY);
        
        const headX2 = x2 - arrowLength * Math.cos(angle + arrowAngle);
        const headY2 = y2 - arrowLength * Math.sin(angle + arrowAngle);
        this.ctx.moveTo(x2, y2);
        this.ctx.lineTo(headX2, headY2);
        
        this.ctx.stroke();
    }
    
    drawAxes() {
        this.ctx.strokeStyle = &apos;#cccccc&apos;;
        this.ctx.lineWidth = 1;
        
        // X axis
        this.ctx.beginPath();
        this.ctx.moveTo(0, this.centerY);
        this.ctx.lineTo(this.width, this.centerY);
        this.ctx.stroke();
        
        // Y axis
        this.ctx.beginPath();
        this.ctx.moveTo(this.centerX, 0);
        this.ctx.lineTo(this.centerX, this.height);
        this.ctx.stroke();
        
        // Origin
        this.ctx.fillStyle = &apos;#666666&apos;;
        this.ctx.beginPath();
        this.ctx.arc(this.centerX, this.centerY, 3, 0, 2 * Math.PI);
        this.ctx.fill();
    }
    
    draw() {
        // Clear canvas
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        // Draw axes
        this.drawAxes();
        
        // Draw contour lines
        this.drawContourLines();
        
        // Draw paths
        this.drawPath(this.gdPath, &apos;#ff4444&apos;, &apos;GD&apos;);
        this.drawPath(this.newtonPath, &apos;#4444ff&apos;, &apos;Newton&apos;);
        
        // Update info panel
        this.updateInfoPanel();
    }
    
    updateInfoPanel() {
        const panel = document.getElementById(&apos;info-panel&apos;);
        const gdCurrent = this.gdPath.length &gt; 0 ? this.gdPath[this.gdPath.length - 1] : [this.startX, this.startY];
        const newtonCurrent = this.newtonPath.length &gt; 0 ? this.newtonPath[this.newtonPath.length - 1] : [this.startX, this.startY];
        
        const gdValue = this.f(gdCurrent[0], gdCurrent[1]);
        const newtonValue = this.f(newtonCurrent[0], newtonCurrent[1]);
        
        panel.innerHTML = `
            Hàm mục tiêu: f(x,y) = (${this.a}x² + ${this.b}y²)/2&lt;br&gt;
            Bước hiện tại: ${this.currentStep}&lt;br&gt;
            GD - Vị trí: (${gdCurrent[0].toFixed(3)}, ${gdCurrent[1].toFixed(3)}), f = ${gdValue.toFixed(4)}&lt;br&gt;
            Newton - Vị trí: (${newtonCurrent[0].toFixed(3)}, ${newtonCurrent[1].toFixed(3)}), f = ${newtonValue.toFixed(4)}
        `;
    }
    
    reset() {
        this.isRunning = false;
        this.gdPath = [[this.startX, this.startY]];
        this.newtonPath = [[this.startX, this.startY]];
        this.currentStep = 0;
        
        document.getElementById(&apos;start-btn&apos;).disabled = false;
        document.getElementById(&apos;step-btn&apos;).disabled = false;
        
        this.draw();
    }
    
    stepAnimation() {
        if (this.currentStep &gt;= this.maxSteps) return;
        
        // Gradient descent step
        const gdCurrent = this.gdPath[this.gdPath.length - 1];
        const gdNext = this.gradientDescentStep(gdCurrent[0], gdCurrent[1]);
        this.gdPath.push(gdNext);
        
        // Newton step
        const newtonCurrent = this.newtonPath[this.newtonPath.length - 1];
        const newtonNext = this.newtonStep(newtonCurrent[0], newtonCurrent[1]);
        this.newtonPath.push(newtonNext);
        
        this.currentStep++;
        this.draw();
        
        // Check convergence
        const gdConverged = Math.abs(gdNext[0]) &lt; 0.01 &amp;&amp; Math.abs(gdNext[1]) &lt; 0.01;
        const newtonConverged = Math.abs(newtonNext[0]) &lt; 0.01 &amp;&amp; Math.abs(newtonNext[1]) &lt; 0.01;
        
        if (gdConverged &amp;&amp; newtonConverged || this.currentStep &gt;= this.maxSteps) {
            this.isRunning = false;
            document.getElementById(&apos;start-btn&apos;).disabled = false;
            document.getElementById(&apos;step-btn&apos;).disabled = true;
        }
    }
    
    startAnimation() {
        if (this.isRunning) return;
        
        this.isRunning = true;
        document.getElementById(&apos;start-btn&apos;).disabled = true;
        document.getElementById(&apos;step-btn&apos;).disabled = true;
        
        const animate = () =&gt; {
            if (!this.isRunning) return;
            
            this.stepAnimation();
            
            if (this.isRunning &amp;&amp; this.currentStep &lt; this.maxSteps) {
                setTimeout(animate, 500);
            } else {
                this.isRunning = false;
                document.getElementById(&apos;start-btn&apos;).disabled = false;
                document.getElementById(&apos;step-btn&apos;).disabled = false;
            }
        };
        
        animate();
    }
    
    toggleContour() {
        this.showContour = !this.showContour;
        this.draw();
    }
}

// Initialize when page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, () =&gt; {
    new OptimizationVisualizer();
});
&lt;/script&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004). &lt;em&gt;Convex optimization&lt;/em&gt;. Cambridge University Press.&lt;/li&gt;
  &lt;li&gt;Nocedal, J., &amp;amp; Wright, S. J. (2006). &lt;em&gt;Numerical optimization&lt;/em&gt; (2nd ed.). Springer.&lt;/li&gt;
  &lt;li&gt;Nesterov, Y. (2003). &lt;em&gt;Introductory lectures on convex optimization: A basic course&lt;/em&gt;. Springer.&lt;/li&gt;
  &lt;li&gt;Bertsekas, D. P. (1999). &lt;em&gt;Nonlinear programming&lt;/em&gt; (2nd ed.). Athena Scientific.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>14-01-01 Giải thích phương pháp Newton</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_01_01_newton_method_interpretation/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter14/14_01_01_newton_method_interpretation</id>
   <content type="html">&lt;p&gt;Nhiều sinh viên thuộc lòng công thức \(x^+ = x - (\nabla^2 f(x))^{-1}\nabla f(x)\) nhưng lại không hiểu &lt;em&gt;tại sao&lt;/em&gt; biểu thức đó lại có dạng như vậy. Cách hiểu đẹp nhất và tự nhiên nhất chính là đặt phương pháp Newton và Gradient Descent cạnh nhau trên cùng một khung hình: &lt;strong&gt;cả hai đều cực tiểu hóa một mô hình bậc hai cục bộ của \(f\)!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sự khác biệt duy nhất nằm ở chất lượng của mô hình xấp xỉ: Gradient Descent thay ma trận độ cong thật \(\nabla^2 f(x)\) bằng một quả cầu tròn đơn giản \(\frac{1}{2t}\|y - x\|_2^2\), còn phương pháp Newton giữ nguyên vẹn &lt;strong&gt;khai triển Taylor bậc hai đầy đủ&lt;/strong&gt; của \(f\) tại \(x\). Nhờ giữ đúng hình dạng hình học thực của hàm, đỉnh của parabol xấp xỉ nằm sát đáy thật hơn rất nhiều.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-diễn-giải-phương-pháp-newton-như-bài-toán-cực-tiểu-hóa-xấp-xỉ-bậc-hai&quot;&gt;Kiến thức cần nhớ: Diễn giải phương pháp Newton như bài toán cực tiểu hóa xấp xỉ bậc hai&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khai triển Taylor bậc hai:&lt;/strong&gt; Quanh điểm \(x\), \(\tilde{f}_x(y) = f(x) + \nabla f(x)^T(y-x) + \frac{1}{2}(y-x)^T \nabla^2 f(x)(y-x)\). Đặt \(\nabla_y \tilde{f}_x(y) = 0\) cho ra ngay \(\nabla f(x) + \nabla^2 f(x)(y - x) = 0 \implies y = x - (\nabla^2 f(x))^{-1}\nabla f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh trực tiếp với Gradient Descent:&lt;/strong&gt; Gradient Descent cực tiểu hóa \(f(x) + \nabla f(x)^T(y-x) + \frac{1}{2t}\|y-x\|_2^2\) — tương đương việc giả vờ rằng \(\nabla^2 f(x) \approx \frac{1}{t}I\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải theo chuẩn Hessian cục bộ:&lt;/strong&gt; Bước Newton cũng là hướng giảm dốc nhất nếu ta đo độ dài bước đi bằng &lt;strong&gt;chuẩn Hessian&lt;/strong&gt; \(\|v\|_{\nabla^2 f(x)} = \sqrt{v^T \nabla^2 f(x) v}\) thay vì chuẩn Euclid \(\|v\|_2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-dựng-tường-minh-parabol-taylor-bậc-hai-và-tìm-đỉnh-của-nó&quot;&gt;Giải thích: Dựng tường minh parabol Taylor bậc hai và tìm đỉnh của nó&lt;/h3&gt;

&lt;p&gt;Xét hàm 1 chiều \(f(x) = x^4 - 4x + 5\) tại điểm xuất phát \(x_0 = 2\) (nghiệm thật của \(f&apos;(x) = 4x^3 - 4 = 0\) là \(x^\star = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính các giá trị đạo hàm tại \(x_0 = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(2) = 16 - 8 + 5 = 13\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;(2) = 4(2)^3 - 4 = 28\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;(2) = 12(2)^2 = 48\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Viết tường minh mô hình parabol Taylor bậc hai quanh \(x_0 = 2\):&lt;/strong&gt;
\(\tilde{f}_2(y) = 13 + 28(y - 2) + \frac{1}{2}(48)(y - 2)^2 = 13 + 28(y - 2) + 24(y - 2)^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm cực tiểu của parabol \(\tilde{f}_2(y)\):&lt;/strong&gt;
Lấy đạo hàm theo \(y\):
\(\tilde{f}_2&apos;(y) = 28 + 48(y - 2) = 0 \implies y - 2 = -\frac{28}{48} = -\frac{7}{12} \approx -0.5833.\)
Vậy điểm tiếp theo là \(x_1 = 2 - \frac{7}{12} = \frac{17}{12} \approx 1.4167\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối chiếu với bước Gradient Descent dùng mô hình tròn \(\frac{1}{2t}(y-2)^2\):&lt;/strong&gt; Nếu chọn \(t = 1/48\) (khớp đúng độ cong tại \(x_0\)), GD trong 1 chiều trùng bước Newton; nhưng trong nhiều chiều với các hướng cong khác nhau (\(48\) và \(1\)), chỉ mô hình Taylor bậc hai đầy đủ mới co giãn đúng cả hai trục cùng lúc!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
});
&lt;/script&gt;

&lt;p&gt;Trang này trình bày cách dẫn xuất bước cập nhật Newton từ xấp xỉ bậc hai của hàm gốc \(f\), đồng thời so sánh với bước cập nhật của gradient descent trong &lt;a href=&quot;/contents/vi/chapter06/06_00_gradient_descent/&quot;&gt;Chương 6&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;bước-cập-nhật-của-phương-pháp-newton&quot;&gt;Bước cập nhật của phương pháp Newton&lt;/h2&gt;
&lt;p&gt;Xấp xỉ Taylor bậc hai của hàm \(f\) quanh điểm \(x\) có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(y)	\approx f(x) + \nabla f(x)^{T}(y-x) +\frac{1}{2}(y-x)^{T}\nabla^{2}f(x)(y-x),\\\\
f_{approx}(y)	= f(x) + \nabla f(x)^{T}(y-x) +\frac{1}{2}(y-x)^{T}\nabla^{2}f(x)(y-x).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong đó, \(y\) đại diện cho điểm ở bước tiếp theo (\(x^{+}\)), còn \(f_{approx}\) là hàm xấp xỉ bậc hai của \(f\).&lt;/p&gt;

&lt;p&gt;Ta cần tìm \(y\) để cực tiểu hóa \(f_{approx}(y)\). Đây là hàm bậc hai theo \(y\) với Hessian \(\nabla^2 f(x)\), nên nó lồi khi \(\nabla^2 f(x) \succeq 0\). Nếu \(\nabla^2 f(x) \succ 0\) thì \(f_{approx}\) lồi chặt và có đúng một điểm cực tiểu, chính là điểm làm gradient theo \(y\) bằng 0. (Nếu Hessian chỉ nửa xác định dương, mô hình có thể không có cực tiểu hoặc có vô số cực tiểu.) Từ đó ta có công thức cập nhật của phương pháp Newton:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\nabla f_{approx}(y)	&amp;amp;= \nabla f(x) +\frac{1}{2} \Big((\nabla^{2} f(x))^{T}(y-x)+(y-x)^{T}\nabla^{2}f(x)\Big)\\\\
&amp;amp;=\nabla f(x) +\nabla^{2} f(x)(y-x)\\\\
&amp;amp; = 0,\\\\
\Leftrightarrow y &amp;amp;= x-(\nabla^{2}f(x))^{-1}\nabla f(x).
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;bước-cập-nhật-của-gradient-descent&quot;&gt;Bước cập nhật của gradient descent&lt;/h2&gt;
&lt;p&gt;Trong gradient descent, ta cũng dùng khai triển bậc hai của \(f\), nhưng thay ma trận Hessian bằng ma trận đơn vị chia cho \(t\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(y)	\approx f(x) + \nabla f(x)^{T}(y-x) +\frac{1}{2t}\|{y-x}\|_{2}^{2},\\\\
f_{approx}(y)	= f(x) + \nabla f(x)^{T}(y-x) +\frac{1}{2t}\|{y-x}\|_{2}^{2}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tương tự phương pháp Newton, cho gradient của \(f_{approx}(y)\) theo \(y\) bằng không, ta tìm được điểm cập nhật \(x^{+}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\nabla f_{approx}(y) &amp;amp;= \nabla f(x) + \frac{1}{t}(y-x), \\\\
&amp;amp;= 0,\\\\
y &amp;amp;= x-t\nabla f(x).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Kết quả này trùng khớp với công thức cập nhật của gradient descent. Xem thêm chi tiết tại &lt;a href=&quot;/contents/vi/chapter06/06_00_gradient_descent/&quot;&gt;chương gradient descent&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;
&lt;p&gt;Xét hàm \(f = (10x_{1}^{2}+x_{2}^{2})/2+5\log(1+e^{-x_{1}-x_{2}})\). Giả sử tại mỗi vòng lặp, ta chọn kích thước bước của gradient descent sao cho độ dài bước đi xấp xỉ bằng độ dài bước cập nhật của phương pháp Newton, rồi so sánh hướng hội tụ của gradient descent (màu đen) và phương pháp Newton (màu xanh).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter14/gd.jpeg&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] So sánh giữa gradient descent (màu đen) và phương pháp Newton (màu xanh)[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Như minh họa trong Hình 1, vì thay đạo hàm bậc hai bằng một hằng số nhân ma trận đơn vị, gradient descent luôn di chuyển vuông góc với tiếp tuyến của các đường đồng mức và hội tụ chậm hơn phương pháp Newton. Các mục tiếp theo sẽ trình bày tính chất, đặc điểm, phân tích hội tụ và các ví dụ của phương pháp Newton.&lt;/p&gt;

&lt;h3 id=&quot;phương-pháp-newton-một-chiều-hai-chiều-và-khi-nào-thất-bại-video&quot;&gt;Phương pháp Newton: một chiều, hai chiều và khi nào thất bại (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/newton-parabola_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Mỗi bước cực tiểu hóa mô hình bậc hai \(f(x_k)+f&apos;(x_k)(x-x_k)+\tfrac12 f&apos;&apos;(x_k)(x-x_k)^2\), dẫn đến công thức cập nhật \(x_{k+1}=x_k-f&apos;(x_k)/f&apos;&apos;(x_k)\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14 Newton's Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_newton_method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_newton_method</id>
   <content type="html">&lt;p&gt;Picture descending a steep, narrow canyon in thick fog. Gradient descent feels only the local slope under your boots, so it zigzags endlessly from one canyon wall to the other. Newton’s method pulls out a curvature map—the Hessian matrix \(\nabla^2 f(x)\)—fits a local parabolic bowl to the terrain, and jumps directly to the bottom of that bowl, doubling the number of accurate decimal digits on every single step once you are close to the solution.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-architecture-of-second-order-optimization&quot;&gt;Key ideas: The Architecture of Second-Order Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Local Quadratic Modeling:&lt;/strong&gt; Replacing \(f\) at \(x\) with its second-order Taylor expansion turns a general nonlinear minimization into a closed-form linear system \(\nabla^2 f(x)\,\Delta x_{\text{nt}} = -\nabla f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Affine Invariance &amp;amp; Conditioning Immunity:&lt;/strong&gt; Because \(\nabla^2 f(x)^{-1}\) rescales every direction by its exact local curvature, Newton’s method is completely blind to poorly scaled coordinates or stretched level sets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Damped Global Convergence + Quadratic Local Finish:&lt;/strong&gt; Pairing Newton’s direction with backtracking line search guarantees steady global decrease first (damped phase) and explosive \(O(\log\log(1/\epsilon))\) quadratic convergence near \(x^\star\) (pure phase).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Self-Concordance &amp;amp; Practical Trade-Offs:&lt;/strong&gt; Self-concordant functions yield affine-invariant iteration bounds free of unknown Lipschitz constants, while structured Hessians and quasi-Newton methods tame the \(O(n^3)\) cost of solving dense linear systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-watching-quadratic-convergence-on-a-1d-convex-function&quot;&gt;Worked example: Watching Quadratic Convergence on a 1D Convex Function&lt;/h3&gt;

&lt;p&gt;Consider minimizing \(f(x) = e^x + e^{-x} - 2x\) (strictly convex, since \(f&apos;&apos;(x) = e^x + e^{-x} &amp;gt; 0\)) starting from \(x^{(0)} = 0\). Its exact minimizer satisfies \(f&apos;(x^\star) = e^{x^\star} - e^{-x^\star} - 2 = 0 \implies \sinh(x^\star) = 1 \implies x^\star = \ln(1 + \sqrt{2}) \approx 0.8813736\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 (at \(x^{(0)} = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(0) = 1 - 1 - 2 = -2\), \(\quad f&apos;&apos;(0) = 1 + 1 = 2\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Newton update: \(x^{(1)} = 0 - \frac{-2}{2} = 1.0\). Error drops from \(0.8814\) to $$&lt;/td&gt;
              &lt;td&gt;1.0 - 0.8814&lt;/td&gt;
              &lt;td&gt;= 0.1186$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2 (at \(x^{(1)} = 1.0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(1) = e - e^{-1} - 2 \approx 2.71828 - 0.36788 - 2 = 0.35040\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;(1) = e + e^{-1} \approx 3.08616\).&lt;/li&gt;
      &lt;li&gt;Newton update: \(x^{(2)} = 1.0 - \frac{0.35040}{3.08616} \approx 0.88646\). Error collapses from \(0.1186\) to \(0.00509\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 3 (at \(x^{(2)} \approx 0.88646\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(0.88646) \approx 0.01441\), \(\quad f&apos;&apos;(0.88646) \approx 2.8386\).&lt;/li&gt;
      &lt;li&gt;Newton update: \(x^{(3)} \approx 0.88646 - 0.00508 = 0.88138\). Error plunges to \(\approx 10^{-5}\)—doubling the accurate digits in a single step!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we look at Newton’s Method.&lt;/p&gt;

&lt;p&gt;Newton’s method is an approach for finding the minimum of a function with a twice differentiable function using the second-order Taylor expansion. It finds the minimum by approximating the function and iteratively updating the solution. Near the optimum, it achieves quadratic convergence and is much faster than gradient descent.&lt;/p&gt;

&lt;h2 id=&quot;references-and-further-readings&quot;&gt;References and further readings&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;S. Boyd and L. Vandenberghe (2004), “Convex optimization”, Chapter 9 and 10&lt;/li&gt;
  &lt;li&gt;Y. Nesterov (1998), “Introductory lectures on convex optimization: a basic course”, Chapter 2&lt;/li&gt;
  &lt;li&gt;Y. Nesterov and A. Nemirovskii (1994), “Interior-point polynomial methods in convex programming”, Chapter 2&lt;/li&gt;
  &lt;li&gt;J. Nocedal and S. Wright (2006), “Numerical optimization”, Chapters 6 and 7&lt;/li&gt;
  &lt;li&gt;L. Vandenberghe, Lecture notes for EE 236C, UCLA, Spring 2011-2012&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>14-12 Practical Exercises - Newton's Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_12_Practical_Exercises_Newton_Method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_12_Practical_Exercises_Newton_Method</id>
   <content type="html">&lt;p&gt;Mastering Newton’s method means being able to move effortlessly between algebra and computation: assembling gradients and Hessians cleanly, solving linear systems without unnecessary matrix inversions, checking self-concordance inequalities by hand, and formulating KKT block systems for equality constraints. Use this structured playbook and warm-up derivation before tackling the full exercise set below.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-exercise-solving-playbook-for-chapter-14&quot;&gt;Key ideas: Exercise-Solving Playbook for Chapter 14&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Matrix Calculus Discipline:&lt;/strong&gt; For \(f(x) = \frac{1}{2}x^T Q x + c^T x\) with symmetric \(Q\), \(\nabla f(x) = Qx + c\) and \(\nabla^2 f(x) = Q\); for log-sum-exp or logistic losses, express \(\nabla^2 f(x) = X^T W X\) to see positive semidefiniteness immediately.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Newton Decrement &amp;amp; Stopping Rules:&lt;/strong&gt; Always verify \(\lambda(x)^2 = -\nabla f(x)^T \Delta x_{\text{nt}} &amp;gt; 0\) as a built-in sign check—if you ever get a negative value for a convex function, you dropped a minus sign!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 3 — Verifying Self-Concordance:&lt;/strong&gt; For multivariate functions, restrict to a line \(g(t) = f(x + tv)\) and check $$&lt;/td&gt;
          &lt;td&gt;g’’‘(t)&lt;/td&gt;
          &lt;td&gt;\le 2 g’‘(t)^{3/2}\((or decompose\)f$$ into known self-concordant sums and affine compositions).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — KKT Systems for Equality Constraints:&lt;/strong&gt; Write \(\nabla^2 f(x)\,\Delta x + A^T w = -\nabla f(x)\) and \(A\Delta x = 0\); eliminate \(\Delta x = -H^{-1}(\nabla f + A^T w)\) via the Schur complement \(A H^{-1} A^T w = -A H^{-1}\nabla f\) when \(H\) is easily invertible.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-a-newton-step-for-1d-logistic-regression&quot;&gt;Worked example: Computing a Newton Step for 1D Logistic Regression&lt;/h3&gt;

&lt;p&gt;Consider the regularized logistic loss \(f(w) = \ln(1 + e^{-w}) + \frac{1}{2}w^2\) at \(w = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the sigmoid probability \(p(w) = \frac{1}{1 + e^w}\) and derivatives:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(w) = -\frac{e^{-w}}{1 + e^{-w}} + w = -\frac{1}{1 + e^w} + w\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;(w) = \frac{e^w}{(1 + e^w)^2} + 1 = p(w)(1 - p(w)) + 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate at \(w = 0\) (where \(p(0) = 0.5\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(0) = -0.5 + 0 = -0.5\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;(0) = (0.5)(0.5) + 1 = 1.25 = \frac{5}{4}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute Newton step and Newton decrement:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\Delta w_{\text{nt}} = -\frac{-0.5}{1.25} = +0.4\).&lt;/li&gt;
      &lt;li&gt;\(\lambda(0)^2 = -f&apos;(0)\Delta w_{\text{nt}} = -(-0.5)(0.4) = 0.20 \implies \lambda(0) \approx 0.4472\).&lt;/li&gt;
      &lt;li&gt;Predicted quadratic drop: \(\frac{1}{2}\lambda(0)^2 = 0.10\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify actual drop at \(w^{(1)} = 0.4\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(0) = \ln 2 \approx 0.6931\).&lt;/li&gt;
      &lt;li&gt;\(f(0.4) = \ln(1 + e^{-0.4}) + \frac{1}{2}(0.16) \approx 0.5130 + 0.0800 = 0.5930\).&lt;/li&gt;
      &lt;li&gt;Actual drop: \(0.6931 - 0.5930 = 0.1001\)—matching the quadratic prediction \(0.10\) to three decimal places!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---newtons-method&quot;&gt;Practical Exercises - Newton’s Method&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd &amp;amp; Vandenberghe (2004), Nocedal &amp;amp; Wright (2006), and Bertsekas (1999).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-i-basic-newtons-method&quot;&gt;&lt;strong&gt;Part I: Basic Newton’s Method&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-1-newton-step-computation-boyd--vandenberghe-ex-91&quot;&gt;&lt;strong&gt;Exercise 1: Newton Step Computation (Boyd &amp;amp; Vandenberghe, Ex. 9.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the objective function:&lt;/p&gt;

\[f(x) = \frac{1}{2}x^T Q x + c^T x\]

&lt;p&gt;where \(Q \succ 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Compute the gradient \(\nabla f(x)\) and the Hessian \(\nabla^2 f(x)\)
b) At \(x = (1, 2)^T\), compute the Newton step \(\Delta x_{nt}\)
c) Compute the Newton decrement \(\lambda(x) = \sqrt{\nabla f(x)^T (\nabla^2 f(x))^{-1} \nabla f(x)}\)
d) With \(Q = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}\), \(c = \begin{bmatrix} -1 \\ -1 \end{bmatrix}\), compute all of the quantities above&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Gradient and Hessian:&lt;/strong&gt;&lt;/p&gt;

\[\nabla f(x) = Qx + c\]

\[\nabla^2 f(x) = Q\]

  &lt;p&gt;(The Hessian does not depend on \(x\) because \(f\) is quadratic)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Newton step:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;The Newton step is defined as:&lt;/p&gt;

\[\Delta x_{nt} = -(\nabla^2 f(x))^{-1} \nabla f(x) = -Q^{-1}(Qx + c)\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Newton decrement:&lt;/strong&gt;&lt;/p&gt;

\[\lambda(x) = \sqrt{\nabla f(x)^T (\nabla^2 f(x))^{-1} \nabla f(x)}\]

\[= \sqrt{(Qx+c)^T Q^{-1} (Qx+c)}\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;d) Numerical computation:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Data:&lt;/p&gt;

\[Q = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}, \quad
c = \begin{bmatrix} -1 \\ -1 \end{bmatrix}, \quad
x = \begin{bmatrix} 1 \\ 2 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Compute \(Q^{-1}\):&lt;/strong&gt;&lt;/p&gt;

\[\det(Q) = 2 \times 2 - 1 \times 1 = 3\]

\[Q^{-1} = \frac{1}{3}\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Gradient at \(x\):&lt;/strong&gt;&lt;/p&gt;

\[\nabla f(x) = Qx + c = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix} \begin{bmatrix} 1 \\ 2 \end{bmatrix} + \begin{bmatrix} -1 \\ -1 \end{bmatrix}\]

\[= \begin{bmatrix} 4 \\ 5 \end{bmatrix} + \begin{bmatrix} -1 \\ -1 \end{bmatrix} = \begin{bmatrix} 3 \\ 4 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Newton step:&lt;/strong&gt;&lt;/p&gt;

\[\Delta x_{nt} = -Q^{-1} \nabla f(x) = -\frac{1}{3}\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix} \begin{bmatrix} 3 \\ 4 \end{bmatrix}\]

\[= -\frac{1}{3}\begin{bmatrix} 6-4 \\ -3+8 \end{bmatrix} = -\frac{1}{3}\begin{bmatrix} 2 \\ 5 \end{bmatrix} = \begin{bmatrix} -2/3 \\ -5/3 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Newton decrement:&lt;/strong&gt;&lt;/p&gt;

\[\lambda^2(x) = \nabla f(x)^T Q^{-1} \nabla f(x)\]

\[= \begin{bmatrix} 3 &amp;amp; 4 \end{bmatrix} \frac{1}{3}\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix} \begin{bmatrix} 3 \\ 4 \end{bmatrix}\]

\[= \frac{1}{3}\begin{bmatrix} 3 &amp;amp; 4 \end{bmatrix} \begin{bmatrix} 2 \\ 5 \end{bmatrix} = \frac{1}{3}(6 + 20) = \frac{26}{3}\]

\[\lambda(x) = \sqrt{\frac{26}{3}} \approx 2.944\]

  &lt;p&gt;&lt;strong&gt;Optimal solution:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Since \(f\) is quadratic, Newton’s method converges in 1 step:&lt;/p&gt;

\[x^+ = x + \Delta x_{nt} = \begin{bmatrix} 1 \\ 2 \end{bmatrix} + \begin{bmatrix} -2/3 \\ -5/3 \end{bmatrix} = \begin{bmatrix} 1/3 \\ 1/3 \end{bmatrix}\]

  &lt;p&gt;Check: \(\nabla f(x^*) = Q x^* + c = 0\) → \(x^* = -Q^{-1}c\):&lt;/p&gt;

\[x^* = -\frac{1}{3}\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix} \begin{bmatrix} -1 \\ -1 \end{bmatrix} = \frac{1}{3}\begin{bmatrix} -1 \\ -1 \end{bmatrix} = \begin{bmatrix} 1/3 \\ 1/3 \end{bmatrix}\]

  &lt;p&gt;✓ Correct!&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-2-newtons-method-for-logistic-regression-nocedal--wright-ex-81&quot;&gt;&lt;strong&gt;Exercise 2: Newton’s Method for Logistic Regression (Nocedal &amp;amp; Wright, Ex. 8.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the logistic regression problem:&lt;/p&gt;

\[\min_x \sum_{i=1}^m \log(1 + e^{-y_i (a_i^T x)})\]

&lt;p&gt;with data \((a_i, y_i)\) where \(y_i \in \{-1, +1\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Compute the gradient \(\nabla f(x)\)
b) Compute the Hessian \(\nabla^2 f(x)\)
c) Prove that \(\nabla^2 f(x) \succeq 0\) (the function is convex)
d) With data \(m=3\), \(n=2\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(a_1 = (1, 1)^T\), \(y_1 = +1\)&lt;/li&gt;
  &lt;li&gt;\(a_2 = (1, -1)^T\), \(y_2 = +1\)&lt;/li&gt;
  &lt;li&gt;\(a_3 = (-1, 0)^T\), \(y_3 = -1\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compute the Newton step at \(x = (0, 0)^T\)&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Gradient:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Define \(\phi(z) = \log(1 + e^{-z})\); then:&lt;/p&gt;

\[f(x) = \sum_{i=1}^m \phi(y_i a_i^T x)\]

\[\phi&apos;(z) = \frac{-e^{-z}}{1 + e^{-z}} = -\frac{1}{1 + e^z}\]

\[\nabla f(x) = \sum_{i=1}^m \phi&apos;(y_i a_i^T x) \cdot y_i a_i = -\sum_{i=1}^m \frac{y_i a_i}{1 + e^{y_i a_i^T x}}\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Hessian:&lt;/strong&gt;&lt;/p&gt;

\[\phi&apos;&apos;(z) = \frac{e^z}{(1 + e^z)^2}\]

\[\nabla^2 f(x) = \sum_{i=1}^m \phi&apos;&apos;(y_i a_i^T x) \cdot y_i^2 a_i a_i^T = \sum_{i=1}^m \frac{a_i a_i^T}{(1 + e^{y_i a_i^T x})^2} \cdot e^{y_i a_i^T x}\]

  &lt;p&gt;Simplifying (since \(y_i^2 = 1\)):&lt;/p&gt;

\[\nabla^2 f(x) = \sum_{i=1}^m w_i a_i a_i^T\]

  &lt;p&gt;where \(w_i = \frac{e^{y_i a_i^T x}}{(1 + e^{y_i a_i^T x})^2} &amp;gt; 0\).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Proof of convexity:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;\(\nabla^2 f(x) = \sum_{i=1}^m w_i a_i a_i^T\) with \(w_i &amp;gt; 0\).&lt;/p&gt;

  &lt;p&gt;For every \(v \in \mathbb{R}^n\):&lt;/p&gt;

\[v^T (\nabla^2 f(x)) v = \sum_{i=1}^m w_i (a_i^T v)^2 \geq 0\]

  &lt;p&gt;→ \(\nabla^2 f(x) \succeq 0\) → \(f\) is convex ✓&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;d) Numerical computation at \(x = (0,0)\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Gradient:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;At \(x = 0\): \(a_i^T x = 0\) for all \(i\).&lt;/p&gt;

\[\nabla f(0) = -\sum_{i=1}^3 \frac{y_i a_i}{1 + e^0} = -\frac{1}{2}\sum_{i=1}^3 y_i a_i\]

\[= -\frac{1}{2}\left( (+1)\begin{bmatrix} 1 \\ 1 \end{bmatrix} + (+1)\begin{bmatrix} 1 \\ -1 \end{bmatrix} + (-1)\begin{bmatrix} -1 \\ 0 \end{bmatrix} \right)\]

\[= -\frac{1}{2}\begin{bmatrix} 1+1+1 \\ 1-1+0 \end{bmatrix} = -\frac{1}{2}\begin{bmatrix} 3 \\ 0 \end{bmatrix} = \begin{bmatrix} -1.5 \\ 0 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Hessian:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;\(w_i = \frac{e^0}{(1+e^0)^2} = \frac{1}{4}\) for all \(i\).&lt;/p&gt;

\[\nabla^2 f(0) = \frac{1}{4}\sum_{i=1}^3 a_i a_i^T\]

\[= \frac{1}{4}\left( \begin{bmatrix} 1 \\ 1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix} + \begin{bmatrix} 1 \\ -1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; -1 \end{bmatrix} + \begin{bmatrix} -1 \\ 0 \end{bmatrix}\begin{bmatrix} -1 &amp;amp; 0 \end{bmatrix} \right)\]

\[= \frac{1}{4}\left( \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} + \begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix} + \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} \right) = \frac{1}{4}\begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Newton step:&lt;/strong&gt;&lt;/p&gt;

\[\Delta x_{nt} = -(\nabla^2 f(0))^{-1} \nabla f(0)\]

\[= -\frac{4}{1}\begin{bmatrix} 1/3 &amp;amp; 0 \\ 0 &amp;amp; 1/2 \end{bmatrix} \begin{bmatrix} -1.5 \\ 0 \end{bmatrix} = 4\begin{bmatrix} 0.5 \\ 0 \end{bmatrix} = \begin{bmatrix} 2 \\ 0 \end{bmatrix}\]

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-ii-backtracking-line-search&quot;&gt;&lt;strong&gt;Part II: Backtracking Line Search&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-3-armijo-condition-boyd--vandenberghe-ex-93&quot;&gt;&lt;strong&gt;Exercise 3: Armijo Condition (Boyd &amp;amp; Vandenberghe, Ex. 9.3)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the function \(f(x) = x^2\) and the point \(x = 2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Compute the gradient \(\nabla f(x)\) and the Hessian \(\nabla^2 f(x)\)
b) Compute the Newton direction \(\Delta x_{nt}\)
c) With Armijo parameters \(\alpha = 0.3\), \(\beta = 0.5\), find a step size \(t\) satisfying the Armijo condition:&lt;/p&gt;

\[f(x + t \Delta x) \leq f(x) + \alpha t \nabla f(x)^T \Delta x\]

&lt;p&gt;d) Draw an illustrative graph&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Gradient and Hessian:&lt;/strong&gt;&lt;/p&gt;

\[\nabla f(x) = 2x, \quad \nabla^2 f(x) = 2\]

  &lt;p&gt;At \(x = 2\):&lt;/p&gt;

\[\nabla f(2) = 4, \quad \nabla^2 f(2) = 2\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Newton direction:&lt;/strong&gt;&lt;/p&gt;

\[\Delta x_{nt} = -\frac{\nabla f(x)}{\nabla^2 f(x)} = -\frac{4}{2} = -2\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Backtracking line search:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Armijo condition:&lt;/p&gt;

\[f(x + t \Delta x) \leq f(x) + \alpha t \nabla f(x)^T \Delta x\]

  &lt;p&gt;Substituting the numbers:&lt;/p&gt;

\[(2 + t(-2))^2 \leq 4 + 0.3 \cdot t \cdot 4 \cdot (-2)\]

\[(2 - 2t)^2 \leq 4 - 2.4t\]

\[4 - 8t + 4t^2 \leq 4 - 2.4t\]

\[4t^2 - 5.6t \leq 0\]

\[t(4t - 5.6) \leq 0\]

  &lt;p&gt;Since \(t &amp;gt; 0\), we need \(4t - 5.6 \leq 0\) → \(t \leq 1.4\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Backtracking:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Try \(t = 1\):&lt;/p&gt;

\[f(2 - 2 \cdot 1) = f(0) = 0\]

\[4 + 0.3 \cdot 1 \cdot (-8) = 4 - 2.4 = 1.6\]

  &lt;p&gt;\(0 \leq 1.6\) ✓ Satisfied!&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; \(t = 1\) (full Newton step)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;d) Geometric interpretation:&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;\(f(x)\) is the parabola \(y = x^2\)&lt;/li&gt;
    &lt;li&gt;At \(x = 2\), the Newton step \(\Delta x = -2\) points to the minimum \(x^* = 0\)&lt;/li&gt;
    &lt;li&gt;The full step \(t = 1\) takes us to the optimal solution in a single step&lt;/li&gt;
    &lt;li&gt;The Armijo condition guarantees sufficient decrease&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Graph:&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;f(x) = x²

     4 |     • (2, 4)
       |    /
       |   /
       |  /
     1 |_/__________
       |/      
     0 •------------ x
      0  1   2
         ↑
      Newton step
      takes us to x=0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;

  &lt;p&gt;Armijo line: \(y = 4 - 2.4t\) (the scaled-down tangent line with slope \(\alpha \nabla f \Delta x\))&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-iii-convergence-analysis&quot;&gt;&lt;strong&gt;Part III: Convergence Analysis&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-4-quadratic-convergence-nocedal--wright-theorem-35&quot;&gt;&lt;strong&gt;Exercise 4: Quadratic Convergence (Nocedal &amp;amp; Wright, Theorem 3.5)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider Newton’s method for a strongly convex function \(f\) with:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[m I \preceq \nabla^2 f(x) \preceq M I\]
  &lt;/li&gt;
  &lt;li&gt;\(\nabla^2 f\) Lipschitz with constant \(L\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Prove that Newton’s method converges quadratically near the solution
b) Compute concretely for \(f(x) = \frac{1}{2}x^T Q x\) with \(Q = \begin{bmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\)
c) Compare with gradient descent&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Proof of quadratic convergence:&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-theorem&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Theorem:&lt;/strong&gt; If \(f\) is strongly convex and \(\nabla^2 f\) is Lipschitz continuous with constant \(L\), then there exists \(\delta &amp;gt; 0\) such that whenever \(\|x^{(k)} - x^*\| &amp;lt; \delta\):&lt;/p&gt;

    &lt;p&gt;\(\|x^{(k+1)} - x^*\| \leq \frac{L}{2m} \|x^{(k)} - x^*\|^2\)&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Proof (sketch):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Newton iteration:&lt;/p&gt;

\[x^{(k+1)} = x^{(k)} - (\nabla^2 f(x^{(k)}))^{-1} \nabla f(x^{(k)})\]

  &lt;p&gt;Taylor expansion at \(x^*\):&lt;/p&gt;

\[\nabla f(x^{(k)}) = \nabla f(x^*) + \int_0^1 \nabla^2 f(x^* + t(x^{(k)} - x^*)) (x^{(k)} - x^*) dt\]

  &lt;p&gt;Since \(\nabla f(x^*) = 0\):&lt;/p&gt;

\[\nabla f(x^{(k)}) = \int_0^1 \nabla^2 f(x^* + t(x^{(k)} - x^*)) (x^{(k)} - x^*) dt\]

  &lt;p&gt;Newton step:&lt;/p&gt;

\[x^{(k+1)} - x^* = x^{(k)} - x^* - (\nabla^2 f(x^{(k)}))^{-1} \nabla f(x^{(k)})\]

  &lt;p&gt;Using the Lipschitz property of \(\nabla^2 f\):&lt;/p&gt;

\[\|\nabla^2 f(x) - \nabla^2 f(y)\| \leq L \|x - y\|\]

  &lt;p&gt;After a careful estimate:&lt;/p&gt;

\[\|x^{(k+1)} - x^*\| \leq \frac{L}{2m} \|x^{(k)} - x^*\|^2\]

  &lt;p&gt;&lt;strong&gt;Meaning:&lt;/strong&gt; The error is squared at every iteration! (quadratic convergence)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Computation with \(Q = \text{diag}(4, 1)\):&lt;/strong&gt;&lt;/p&gt;

\[f(x) = \frac{1}{2}x^T Q x = 2x_1^2 + \frac{1}{2}x_2^2\]

  &lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[m = \lambda_{\min}(Q) = 1\]
    &lt;/li&gt;
    &lt;li&gt;
\[M = \lambda_{\max}(Q) = 4\]
    &lt;/li&gt;
    &lt;li&gt;\(L = 0\) (Hessian constant → \(\nabla^2 f(x) = Q\))&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Convergence:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;With \(L = 0\), Newton’s method converges in &lt;strong&gt;1 step&lt;/strong&gt; (because \(f\) is quadratic)!&lt;/p&gt;

  &lt;p&gt;From any \(x^{(0)}\):&lt;/p&gt;

\[x^{(1)} = x^{(0)} - Q^{-1} (Qx^{(0)}) = x^{(0)} - x^{(0)} = 0 = x^*\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Comparison with Gradient Descent:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;GD with step size \(t = \frac{2}{m + M} = \frac{2}{5} = 0.4\):&lt;/strong&gt;&lt;/p&gt;

\[x^{(k+1)} = x^{(k)} - 0.4 \nabla f(x^{(k)})\]

  &lt;p&gt;&lt;strong&gt;Convergence rate:&lt;/strong&gt;&lt;/p&gt;

\[\|x^{(k+1)} - x^*\| \leq \left(\frac{M - m}{M + m}\right) \|x^{(k)} - x^*\| = \frac{3}{5} \|x^{(k)} - x^*\|\]

  &lt;p&gt;&lt;strong&gt;Linear convergence&lt;/strong&gt; with ratio \(0.6\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Comparison:&lt;/strong&gt;&lt;/p&gt;

  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Method&lt;/th&gt;
        &lt;th&gt;Convergence&lt;/th&gt;
        &lt;th&gt;Iterations to \(10^{-6}\)&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;Newton&lt;/td&gt;
        &lt;td&gt;Quadratic&lt;/td&gt;
        &lt;td&gt;1 (quadratic function)&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;GD&lt;/td&gt;
        &lt;td&gt;Linear (\(0.6^k\))&lt;/td&gt;
        &lt;td&gt;\(k = 28\) (\(0.6^{27} \approx 1.03 \times 10^{-6}\))&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

  &lt;p&gt;Newton is &lt;strong&gt;much faster&lt;/strong&gt;!&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-iv-affine-invariance&quot;&gt;&lt;strong&gt;Part IV: Affine Invariance&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-5-affine-invariance-property-boyd--vandenberghe-ex-920&quot;&gt;&lt;strong&gt;Exercise 5: Affine Invariance Property (Boyd &amp;amp; Vandenberghe, Ex. 9.20)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Affine invariance of Newton’s method: if \(f\) is transformed by an affine change of variables, Newton’s method is unaffected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Prove: if \(\tilde{x} = Ax + b\) with \(A\) invertible, and \(\tilde{f}(\tilde{x}) = f(A^{-1}(\tilde{x} - b))\), then the Newton step is unchanged
b) Illustrate with a concrete example&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Proof of affine invariance:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Problem transformation:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Original: \(\min_x f(x)\)
New: \(\min_{\tilde{x}} \tilde{f}(\tilde{x})\) with \(\tilde{x} = Ax + b\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Gradient of \(\tilde{f}\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;By the chain rule:&lt;/p&gt;

\[\nabla \tilde{f}(\tilde{x}) = A^{-T} \nabla f(x)\]

  &lt;p&gt;(with \(x = A^{-1}(\tilde{x} - b)\))&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Hessian of \(\tilde{f}\):&lt;/strong&gt;&lt;/p&gt;

\[\nabla^2 \tilde{f}(\tilde{x}) = A^{-T} \nabla^2 f(x) A^{-1}\]

  &lt;p&gt;&lt;strong&gt;Newton step in the new coordinates:&lt;/strong&gt;&lt;/p&gt;

\[\Delta \tilde{x}_{nt} = -(\nabla^2 \tilde{f}(\tilde{x}))^{-1} \nabla \tilde{f}(\tilde{x})\]

\[= -(A \nabla^2 f(x)^{-1} A^T)(A^{-T} \nabla f(x))\]

\[= -A \nabla^2 f(x)^{-1} \nabla f(x) = A \Delta x_{nt}\]

  &lt;p&gt;&lt;strong&gt;Relationship:&lt;/strong&gt;&lt;/p&gt;

\[\Delta \tilde{x}_{nt} = A \Delta x_{nt}\]

  &lt;p&gt;In the original coordinates:&lt;/p&gt;

\[x^{(k+1)} = x^{(k)} + \Delta x_{nt}\]

  &lt;p&gt;In the new coordinates:&lt;/p&gt;

\[\tilde{x}^{(k+1)} = \tilde{x}^{(k)} + \Delta \tilde{x}_{nt} = A x^{(k)} + b + A \Delta x_{nt} = A x^{(k+1)} + b\]

  &lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; The Newton trajectory is &lt;strong&gt;unchanged&lt;/strong&gt; under affine transformations!&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Illustrative example:&lt;/strong&gt;&lt;/p&gt;

\[f(x) = x_1^2 + 4x_2^2\]

  &lt;p&gt;&lt;strong&gt;Transformation:&lt;/strong&gt; \(\tilde{x} = Ax\) with \(A = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}\)&lt;/p&gt;

\[\tilde{f}(\tilde{x}) = \tilde{x}_1^2 + \tilde{x}_2^2\]

  &lt;p&gt;(It turns the ellipse into a circle!)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;From \(x^{(0)} = (2, 1)^T\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Original coordinates:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[\nabla f = (4, 8)^T\]
    &lt;/li&gt;
    &lt;li&gt;
\[\nabla^2 f = \text{diag}(2, 8)\]
    &lt;/li&gt;
    &lt;li&gt;
\[\Delta x = -(2, 1)^T\]
    &lt;/li&gt;
    &lt;li&gt;\(x^{(1)} = (0, 0)^T\) ✓&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;New coordinates:&lt;/strong&gt; \(\tilde{x}^{(0)} = (2, 2)^T\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[\nabla \tilde{f} = (4, 4)^T\]
    &lt;/li&gt;
    &lt;li&gt;
\[\nabla^2 \tilde{f} = 2I\]
    &lt;/li&gt;
    &lt;li&gt;
\[\Delta \tilde{x} = -(2, 2)^T\]
    &lt;/li&gt;
    &lt;li&gt;\(\tilde{x}^{(1)} = (0, 0)^T\) ✓&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Same result!&lt;/strong&gt; The number of iterations does not change.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-v-real-world-problem&quot;&gt;&lt;strong&gt;Part V: Real-World Problem&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-6-optimal-control-bertsekas-ex-235&quot;&gt;&lt;strong&gt;Exercise 6: Optimal Control (Bertsekas, Ex. 2.3.5)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Discrete-time optimal control problem:&lt;/p&gt;

\[\min_{u_0,\ldots,u_{N-1}} \sum_{k=0}^{N-1} \left( x_k^T Q x_k + u_k^T R u_k \right) + x_N^T Q_f x_N\]

&lt;p&gt;with dynamics:&lt;/p&gt;

\[x_{k+1} = A x_k + B u_k, \quad x_0 = \bar{x}\]

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Write the problem as an unconstrained QP
b) Compute the gradient and Hessian
c) Apply Newton’s method with \(N = 3\), \(Q = I\), \(R = I\), \(Q_f = I\), \(A = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}\), \(B = \begin{bmatrix} 0 \\ 1 \end{bmatrix}\), \(\bar{x} = (1, 0)^T\)&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Formulation:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Decision variable:&lt;/strong&gt; \(z = (u_0, u_1, u_2)^T \in \mathbb{R}^{3}\) (since \(u_k \in \mathbb{R}\))&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Express \(x_k\) in terms of \(u\):&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
x_1 &amp;amp;= Ax_0 + Bu_0 \\
x_2 &amp;amp;= Ax_1 + Bu_1 = A^2 x_0 + AB u_0 + B u_1 \\
x_3 &amp;amp;= A^3 x_0 + A^2 B u_0 + AB u_1 + B u_2
\end{align}\]

  &lt;p&gt;&lt;strong&gt;Compact form:&lt;/strong&gt; \(x_k = \Phi_k x_0 + \sum_{j=0}^{k-1} \Psi_{kj} u_j\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Objective function:&lt;/strong&gt;&lt;/p&gt;

\[f(u) = \sum_{k=0}^{N-1} (x_k^T Q x_k + u_k^T R u_k) + x_N^T Q_f x_N\]

\[= \frac{1}{2} u^T H u + g^T u + \text{const}\]

  &lt;p&gt;where \(H\) and \(g\) are computed from the dynamics.&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Gradient and Hessian:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Since \(f\) is a QP:&lt;/p&gt;

\[\nabla f(u) = Hu + g\]

\[\nabla^2 f(u) = H\]

  &lt;p&gt;&lt;strong&gt;Newton step:&lt;/strong&gt;&lt;/p&gt;

\[\Delta u = -H^{-1}(Hu + g) = -u - H^{-1}g\]

  &lt;p&gt;(Converges in 1 step!)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Numerical computation with \(N=3\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Data:&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}, \quad
B = \begin{bmatrix} 0 \\ 1 \end{bmatrix}, \quad
x_0 = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Compute the dynamics:&lt;/strong&gt;&lt;/p&gt;

\[x_1 = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} 1 \\ 0 \end{bmatrix} + \begin{bmatrix} 0 \\ 1 \end{bmatrix} u_0 = \begin{bmatrix} 1 \\ u_0 \end{bmatrix}\]

\[x_2 = A x_1 + B u_1 = \begin{bmatrix} 1 + u_0 \\ u_0 + u_1 \end{bmatrix}\]

\[x_3 = A x_2 + B u_2 = \begin{bmatrix} 1 + 2u_0 + u_1 \\ u_0 + u_1 + u_2 \end{bmatrix}\]

  &lt;p&gt;&lt;strong&gt;Objective function (\(Q = R = Q_f = I\)):&lt;/strong&gt;&lt;/p&gt;

\[f = \sum_{k=0}^2 (\|x_k\|^2 + u_k^2) + \|x_3\|^2\]

\[= (1^2 + u_0^2) + ((1)^2 + (u_0)^2 + u_1^2) + \ldots\]

  &lt;p&gt;Expanding and differentiating: \(\nabla f(0) = (6, 2, 0)^T\), \(\nabla^2 f = \begin{bmatrix} 18 &amp;amp; 8 &amp;amp; 2 \\ 8 &amp;amp; 8 &amp;amp; 2 \\ 2 &amp;amp; 2 &amp;amp; 4 \end{bmatrix}\). Newton step from \(u = 0\): \(\Delta u = -(\nabla^2 f)^{-1}\nabla f(0)\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Optimal control: \(u^* = (-2/5,\ 4/35,\ 1/7)^T \approx (-0.4,\ 0.114,\ 0.143)^T\), \(f^* = 102/35 \approx 2.914\)&lt;/p&gt;

  &lt;p&gt;Newton’s method converges in 1 iteration because the problem is a QP.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;summary-and-strategy&quot;&gt;&lt;strong&gt;Summary and Strategy&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;newton-method&quot;&gt;&lt;strong&gt;Newton Method:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Newton step:&lt;/strong&gt; \(\Delta x = -(\nabla^2 f(x))^{-1} \nabla f(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton decrement:&lt;/strong&gt; \(\lambda(x) = \sqrt{\nabla f(x)^T (\nabla^2 f(x))^{-1} \nabla f(x)}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stopping criterion:&lt;/strong&gt; \(\lambda^2(x)/2 &amp;lt; \epsilon\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;backtracking-line-search&quot;&gt;&lt;strong&gt;Backtracking Line Search:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Armijo condition:&lt;/strong&gt; \(f(x + t\Delta x) \leq f(x) + \alpha t \nabla f(x)^T \Delta x\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; \(\alpha \in (0, 0.5)\), \(\beta \in (0, 1)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Typical:&lt;/strong&gt; \(\alpha = 0.3\), \(\beta = 0.8\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;convergence&quot;&gt;&lt;strong&gt;Convergence:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quadratic convergence:&lt;/strong&gt; \(\|x^{(k+1)} - x^*\| \leq C \|x^{(k)} - x^*\|^2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Near optimal:&lt;/strong&gt; Close to \(x^*\), Newton’s method is very fast&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quadratic function:&lt;/strong&gt; Converges in 1 step&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;affine-invariance&quot;&gt;&lt;strong&gt;Affine Invariance:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Newton’s method does not depend on the choice of coordinates&lt;/li&gt;
  &lt;li&gt;The number of iterations is unchanged under affine transformations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Benefit:&lt;/strong&gt; No preconditioning needed&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;when-to-use-newton&quot;&gt;&lt;strong&gt;When to use Newton:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Smooth functions (\(\nabla^2 f\) exists)&lt;/li&gt;
  &lt;li&gt;Near the solution (fast convergence)&lt;/li&gt;
  &lt;li&gt;Moderate dimension (the Hessian is \(n \times n\))&lt;/li&gt;
  &lt;li&gt;High accuracy is required&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 9.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nocedal, J., &amp;amp; Wright, S. J.&lt;/strong&gt; (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt; (2nd ed.). Springer. Chapters 3, 6.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bertsekas, D. P.&lt;/strong&gt; (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt; (2nd ed.). Athena Scientific. Chapter 1.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nesterov, Y.&lt;/strong&gt; (2004). &lt;em&gt;Introductory Lectures on Convex Optimization&lt;/em&gt;. Springer. Chapter 2.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Dennis, J. E., &amp;amp; Schnabel, R. B.&lt;/strong&gt; (1996). &lt;em&gt;Numerical Methods for Unconstrained Optimization and Nonlinear Equations&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

</content>
 </entry>
 
 <entry>
   <title>14-11 Multiple-Choice Quiz - Newton's Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_11_Quiz_Newton_Method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_11_Quiz_Newton_Method</id>
   <content type="html">&lt;p&gt;Newton’s method quizzes love testing the subtle distinctions between &lt;em&gt;local&lt;/em&gt; and &lt;em&gt;global&lt;/em&gt; properties: pure Newton is affine invariant, yet its classical \(m, L, M\) convergence bound is &lt;em&gt;not&lt;/em&gt;; Newton’s step is orthogonal to level curves in the &lt;em&gt;Hessian&lt;/em&gt; norm, yet &lt;em&gt;not&lt;/em&gt; in the Euclidean norm; and a quadratic error rate \(O(\log\log(1/\epsilon))\) only kicks in after the damped phase ends. Run through this concept map and 4-point warm-up before starting the quiz.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-high-yield-newtons-method-checkpoints&quot;&gt;Key ideas: High-Yield Newton’s Method Checkpoints&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Update &amp;amp; Geometry:&lt;/strong&gt; \(\Delta x_{\text{nt}} = -(\nabla^2 f(x))^{-1}\nabla f(x)\) minimizes the local quadratic model; it is strictly a descent direction whenever \(\nabla^2 f(x) \succ 0\) and is affine invariant.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Newton Decrement Identities:&lt;/strong&gt; \(\lambda(x)^2 = \nabla f(x)^T H^{-1}\nabla f(x) = \Delta x_{\text{nt}}^T H \Delta x_{\text{nt}} = -\nabla f(x)^T \Delta x_{\text{nt}}\), and \(\frac{1}{2}\lambda(x)^2\) estimates \(f(x) - f^\star\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 3 — Convergence Regimes &amp;amp; Self-Concordance:&lt;/strong&gt; Classical damped Newton has Phase I (constant drop \(-\gamma\)) and Phase II (quadratic \(O(\log\log(1/\epsilon))\)). Self-concordant functions ($$&lt;/td&gt;
          &lt;td&gt;f’’’&lt;/td&gt;
          &lt;td&gt;\le 2(f’’)^{3/2}\() eliminate\)m, L, M$$ and restore affine-invariant bounds.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Complexity &amp;amp; Extensions:&lt;/strong&gt; Dense Newton takes \(O(n^2)\) memory and \(O(n^3)\) flops per step; banded Hessians drop this to \(O(n)\); equality constraints use the block KKT system; quasi-Newton achieves superlinear convergence without Hessians.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-4-check-rapid-quiz-warm-up&quot;&gt;Worked example: 4-Check Rapid Quiz Warm-Up&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Newton step &amp;amp; decrement:&lt;/strong&gt; For \(f(x) = \frac{1}{2}x^2 + e^x\) at \(x = 0\), compute \(\Delta x_{\text{nt}}\) and \(\lambda(0)\).
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(0) = 0 + 1 = 1\), \(f&apos;&apos;(0) = 1 + 1 = 2\).&lt;/li&gt;
      &lt;li&gt;\(\Delta x_{\text{nt}} = -1/2 = -0.5\); \(\lambda(0) = \sqrt{1^2 / 2} = \frac{1}{\sqrt{2}} \approx 0.707\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-concordance check:&lt;/strong&gt; Is \(f(x) = -\log(x) + 3x^2\) self-concordant on \(x &amp;gt; 0\)?
    &lt;ul&gt;
      &lt;li&gt;Yes! Both \(-\log(x)\) and the convex quadratic \(3x^2\) are self-concordant, and self-concordance is closed under addition.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine invariance check:&lt;/strong&gt; If \(g(y) = f(10y)\), how does \(\lambda_g(y)\) compare to \(\lambda_f(10y)\)?
    &lt;ul&gt;
      &lt;li&gt;They are &lt;strong&gt;identical&lt;/strong&gt;: \(\lambda_g(y) = \lambda_f(10y)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equality-constrained feasibility check:&lt;/strong&gt; If \(Ax^{(0)} = b\) and \(A\Delta x_{\text{nt}} = 0\), is \(x^{(0)} + 0.5\Delta x_{\text{nt}}\) feasible?
    &lt;ul&gt;
      &lt;li&gt;Yes: \(A(x^{(0)} + 0.5\Delta x_{\text{nt}}) = b + 0 = b\) for every step size \(t\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-newtons-method&quot;&gt;⚡ &lt;strong&gt;Newton’s Method&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-first-order-to-second-order&quot;&gt;&lt;strong&gt;From First-Order to Second-Order&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;First-order methods:&lt;/strong&gt; Gradient Descent - uses \(\nabla f(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-order methods:&lt;/strong&gt; Newton’s Method - uses \(\nabla^2 f(x)\) (Hessian)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Idea:&lt;/strong&gt; Instead of approximating the Hessian by \(\frac{1}{t}I\), compute \(\nabla^2 f(x)\) exactly&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;problem&quot;&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x)\) with \(f\) convex, twice differentiable, \(\text{dom}(f) = \mathbb{R}^n\)&lt;/p&gt;

&lt;h4 id=&quot;newton-update-rule&quot;&gt;&lt;strong&gt;Newton update rule&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - (\nabla^2 f(x^{(k-1)}))^{-1} \nabla f(x^{(k-1)})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparison with Gradient Descent:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;GD:&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - t \nabla f(x^{(k-1)})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton:&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - (\nabla^2 f(x^{(k-1)}))^{-1} \nabla f(x^{(k-1)})\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-explanation-and-properties&quot;&gt;🔍 &lt;strong&gt;Explanation and Properties&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;newton-step-interpretation&quot;&gt;&lt;strong&gt;Newton step interpretation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Newton direction:&lt;/strong&gt; \(\Delta x_{nt} = -(\nabla^2 f(x))^{-1} \nabla f(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Geometric interpretation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Minimize quadratic approximation: \(f(x) + \nabla f(x)^T (y-x) + \frac{1}{2}(y-x)^T \nabla^2 f(x) (y-x)\)&lt;/li&gt;
  &lt;li&gt;Solution: \(y^* = x - (\nabla^2 f(x))^{-1} \nabla f(x)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;root-finding-connection&quot;&gt;&lt;strong&gt;Root finding connection&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Newton’s method for optimization ≡ Newton-Raphson root finding for \(\nabla f(x) = 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Newton-Raphson:&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - \frac{g(x^{(k-1)})}{g&apos;(x^{(k-1)})}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For \(g(x) = \nabla f(x)\):&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - (\nabla^2 f(x^{(k-1)}))^{-1} \nabla f(x^{(k-1)})\)&lt;/p&gt;

&lt;h4 id=&quot;affine-invariance&quot;&gt;&lt;strong&gt;Affine invariance&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Key property:&lt;/strong&gt; Newton’s method is unchanged under affine transformations&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If:&lt;/strong&gt; \(g(y) = f(Ay + b)\) with \(A\) nonsingular
&lt;strong&gt;Then:&lt;/strong&gt; The Newton steps for \(g\) and \(f\) are equivalent&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meaning:&lt;/strong&gt; Not affected by conditioning, unlike Gradient Descent&lt;/p&gt;

&lt;h3 id=&quot;-newton-decrement&quot;&gt;📐 &lt;strong&gt;Newton Decrement&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lambda(x) = (\nabla f(x)^T (\nabla^2 f(x))^{-1} \nabla f(x))^{1/2}\)&lt;/p&gt;

&lt;h4 id=&quot;physical-meaning&quot;&gt;&lt;strong&gt;Physical meaning&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Approximation quality:&lt;/strong&gt; \(\frac{1}{2}\lambda^2(x) = f(x) - \min_y \hat{f}(y)\)
    &lt;ul&gt;
      &lt;li&gt;\(\hat{f}(y)\): quadratic approximation of \(f\) at \(x\)&lt;/li&gt;
      &lt;li&gt;\(\frac{1}{2}\lambda^2(x)\): an estimate of \(f(x) - f^*\) (based on the quadratic approximation; not a rigorous upper bound)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Step length:&lt;/strong&gt; \(\lambda(x) = \lVert \Delta x_{nt} \rVert_{\nabla^2 f(x)}\) (Hessian norm)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mahalanobis distance:&lt;/strong&gt; Distance from the current point to the Newton step&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;alternative-expressions&quot;&gt;&lt;strong&gt;Alternative expressions&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\lambda(x) = (\Delta x_{nt}^T \nabla^2 f(x) \Delta x_{nt})^{1/2}\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla f(x)^T \Delta x_{nt} = -\lambda^2(x)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;affine-invariance-1&quot;&gt;&lt;strong&gt;Affine invariance&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The Newton decrement is also affine invariant: \(\lambda_g(y) = \lambda_f(x)\)&lt;/p&gt;

&lt;h3 id=&quot;-damped-newton-method&quot;&gt;🎯 &lt;strong&gt;Damped Newton Method&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;problems-with-pure-newton&quot;&gt;&lt;strong&gt;Problems with Pure Newton&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;No convergence guarantee:&lt;/strong&gt; \(f(x^{(k)})\) may increase&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Only local convergence:&lt;/strong&gt; Needs a starting point close to the optimum&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;backtracking-line-search&quot;&gt;&lt;strong&gt;Backtracking line search&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Algorithm:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Compute Newton direction: \(v = -(\nabla^2 f(x))^{-1} \nabla f(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Backtracking:&lt;/strong&gt; with parameters \(0 &amp;lt; \alpha \le 1/2\), \(0 &amp;lt; \beta &amp;lt; 1\)
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;t = 1
while f(x + tv) &amp;gt; f(x) + α t ∇f(x)^T v:
    t = βt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update:&lt;/strong&gt; \(x^+ = x + tv\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;armijo-condition&quot;&gt;&lt;strong&gt;Armijo condition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f(x + tv) \le f(x) + \alpha t \nabla f(x)^T v\)&lt;/p&gt;

&lt;p&gt;with \(\nabla f(x)^T v = -\lambda^2(x) &amp;lt; 0\)&lt;/p&gt;

&lt;h3 id=&quot;-convergence-analysis&quot;&gt;📊 &lt;strong&gt;Convergence Analysis&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;assumptions&quot;&gt;&lt;strong&gt;Assumptions&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(\nabla f\) Lipschitz:&lt;/strong&gt; \(\lVert \nabla f(x) - \nabla f(y) \rVert_2 \le L \lVert x-y \rVert_2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strong convexity:&lt;/strong&gt; \(mI \preceq \nabla^2 f(x) \preceq LI\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\nabla^2 f\) Lipschitz:&lt;/strong&gt; \(\lVert \nabla^2 f(x) - \nabla^2 f(y) \rVert_2 \le M \lVert x-y \rVert_2\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;two-phase-convergence&quot;&gt;&lt;strong&gt;Two-phase convergence&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Phase I - Damped phase:&lt;/strong&gt; \(\lVert \nabla f(x^{(k)}) \rVert_2 \ge \eta\)
\(f(x^{(k+1)}) - f(x^{(k)}) \le -\gamma\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase II - Pure phase:&lt;/strong&gt; \(\lVert \nabla f(x^{(k)}) \rVert_2 &amp;lt; \eta\)
\(\frac{M}{2m^2} \lVert \nabla f(x^{(k+1)}) \rVert_2 \le \left(\frac{M}{2m^2} \lVert \nabla f(x^{(k)}) \rVert_2\right)^2\)&lt;/p&gt;

&lt;h4 id=&quot;convergence-rates&quot;&gt;&lt;strong&gt;Convergence rates&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Phase I (damped phase):&lt;/strong&gt; The function value decreases by at least a fixed amount \(\gamma\) per step
\(f(x^{(k)}) - f^* \le (f(x^{(0)}) - f^*) - \gamma k\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase II:&lt;/strong&gt; Quadratic convergence
\(f(x^{(k)}) - f^* \le \frac{2m^3}{M^2}\left(\frac{1}{2}\right)^{2^{k-k_0+1}}\)&lt;/p&gt;

&lt;h4 id=&quot;total-complexity&quot;&gt;&lt;strong&gt;Total complexity&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\frac{f(x^{(0)}) - f^*}{\gamma} + \log\log\left(\frac{\epsilon_0}{\epsilon}\right)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practical estimate:&lt;/strong&gt; \(\frac{f(x^{(0)}) - f^*}{\gamma} + 6\)&lt;/p&gt;

&lt;h3 id=&quot;-self-concordant-functions&quot;&gt;🌟 &lt;strong&gt;Self-Concordant Functions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;motivation&quot;&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problems with the standard analysis:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hard to find constants:&lt;/strong&gt; \(L, m, M\) are hard to determine in practice&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Not affine invariant:&lt;/strong&gt; The analysis depends on the coordinate system&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;self-concordance-definition&quot;&gt;&lt;strong&gt;Self-concordance definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;A function \(f\) is &lt;strong&gt;self-concordant&lt;/strong&gt; if:
\(|f&apos;&apos;&apos;(x)| \le 2(f&apos;&apos;(x))^{3/2}\) (univariate case)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multivariate:&lt;/strong&gt; \(\lvert D^3 f(x)[h,h,h] \rvert \le 2(h^T \nabla^2 f(x) h)^{3/2}\)&lt;/p&gt;

&lt;h4 id=&quot;key-properties&quot;&gt;&lt;strong&gt;Key properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Affine invariant:&lt;/strong&gt; Self-concordance preserved under affine transformation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;No constants needed:&lt;/strong&gt; The analysis does not need \(L, m, M\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Barrier functions:&lt;/strong&gt; Logarithmic barriers are self-concordant&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;convergence-for-self-concordant&quot;&gt;&lt;strong&gt;Convergence for self-concordant&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Simpler analysis:&lt;/strong&gt; Only the Newton decrement \(\lambda(x)\) is needed&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Damped phase:&lt;/strong&gt; \(\lambda(x) \ge \eta\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pure phase:&lt;/strong&gt; \(\lambda(x) &amp;lt; \eta\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-newton-vs-gradient-descent&quot;&gt;🔄 &lt;strong&gt;Newton vs Gradient Descent&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;computational-comparison&quot;&gt;&lt;strong&gt;Computational comparison&lt;/strong&gt;&lt;/h4&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aspect&lt;/th&gt;
      &lt;th&gt;Newton Method&lt;/th&gt;
      &lt;th&gt;Gradient Descent&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Memory&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\) (Hessian storage)&lt;/td&gt;
      &lt;td&gt;\(O(n)\) (gradient storage)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Computation&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(O(n^3)\) (linear system)&lt;/td&gt;
      &lt;td&gt;\(O(n)\) (vector operations)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Convergence&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Quadratic (near optimum)&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Conditioning&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Affine invariant&lt;/td&gt;
      &lt;td&gt;Sensitive to conditioning&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Robustness&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Sensitive to numerical errors&lt;/td&gt;
      &lt;td&gt;More robust&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h4 id=&quot;when-to-use-newton&quot;&gt;&lt;strong&gt;When to use Newton&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Fast convergence:&lt;/strong&gt; Quadratic near optimum&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine invariant:&lt;/strong&gt; Not affected by conditioning&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fewer iterations:&lt;/strong&gt; Especially for high accuracy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Expensive per iteration:&lt;/strong&gt; \(O(n^3)\) cost&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Memory intensive:&lt;/strong&gt; \(O(n^2)\) storage&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical sensitivity:&lt;/strong&gt; Hessian inversion issues&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;practical-considerations&quot;&gt;&lt;strong&gt;Practical considerations&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Small to medium \(n\):&lt;/strong&gt; Newton often better&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Large \(n\):&lt;/strong&gt; Gradient descent or quasi-Newton&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High accuracy needed:&lt;/strong&gt; Newton’s quadratic convergence wins&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ill-conditioned:&lt;/strong&gt; Newton’s affine invariance helps&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-implementation-details&quot;&gt;🛠️ &lt;strong&gt;Implementation Details&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;computing-newton-step&quot;&gt;&lt;strong&gt;Computing Newton step&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form Hessian:&lt;/strong&gt; \(H = \nabla^2 f(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve linear system:&lt;/strong&gt; \(H \Delta x = -\nabla f(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Don’t invert explicitly:&lt;/strong&gt; Use Cholesky, LU, or CG&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;numerical-considerations&quot;&gt;&lt;strong&gt;Numerical considerations&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hessian positive definite:&lt;/strong&gt; Ensure convexity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization:&lt;/strong&gt; Add \(\epsilon I\) if needed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Condition number:&lt;/strong&gt; Monitor \(\kappa(H)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Line search:&lt;/strong&gt; Always use backtracking for global convergence&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;stopping-criteria&quot;&gt;&lt;strong&gt;Stopping criteria&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Newton decrement:&lt;/strong&gt; \(\lambda^2(x)/2 &amp;lt; \epsilon\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient norm:&lt;/strong&gt; \(\lVert \nabla f(x) \rVert_2 &amp;lt; \epsilon\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Function decrease:&lt;/strong&gt; \(\lvert f(x^{(k)}) - f(x^{(k-1)}) \rvert &amp;lt; \epsilon\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-special-cases-and-extensions&quot;&gt;🎯 &lt;strong&gt;Special Cases and Extensions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;quasi-newton-methods&quot;&gt;&lt;strong&gt;Quasi-Newton methods&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Motivation:&lt;/strong&gt; Avoid computing exact Hessian&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;BFGS update:&lt;/strong&gt;
\(B_{k+1} = B_k + \frac{y_k y_k^T}{y_k^T s_k} - \frac{B_k s_k s_k^T B_k}{s_k^T B_k s_k}\)&lt;/p&gt;

&lt;p&gt;with \(s_k = x_{k+1} - x_k\), \(y_k = \nabla f(x_{k+1}) - \nabla f(x_k)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;L-BFGS:&lt;/strong&gt; Limited-memory version for large-scale problems&lt;/p&gt;

&lt;h4 id=&quot;trust-region-methods&quot;&gt;&lt;strong&gt;Trust region methods&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Alternative to line search:&lt;/strong&gt;
\(\min_p f(x) + \nabla f(x)^T p + \frac{1}{2}p^T \nabla^2 f(x) p\)
subject to \(\lVert p \rVert \le \Delta\)&lt;/p&gt;

&lt;h3 id=&quot;-illustrative-examples&quot;&gt;💡 &lt;strong&gt;Illustrative Examples&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;logistic-regression&quot;&gt;&lt;strong&gt;Logistic regression&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(\min_\beta \sum_{i=1}^n \log(1 + \exp(-y_i x_i^T \beta))\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gradient:&lt;/strong&gt; \(\nabla f(\beta) = -\sum_{i=1}^n \frac{y_i x_i}{1 + \exp(y_i x_i^T \beta)}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hessian:&lt;/strong&gt; \(\nabla^2 f(\beta) = \sum_{i=1}^n \frac{\exp(y_i x_i^T \beta)}{(1 + \exp(y_i x_i^T \beta))^2} x_i x_i^T\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Newton step:&lt;/strong&gt; Solve \(\nabla^2 f(\beta) \Delta \beta = -\nabla f(\beta)\)&lt;/p&gt;

&lt;h4 id=&quot;quadratic-function&quot;&gt;&lt;strong&gt;Quadratic function&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(f(x) = \frac{1}{2}x^T Q x + b^T x + c\) with \(Q \succ 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Newton step:&lt;/strong&gt; \(\Delta x = -Q^{-1}(Qx + b) = -(x + Q^{-1}b)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One-step convergence:&lt;/strong&gt; \(x^{(1)} = x^{(0)} - (x^{(0)} + Q^{-1}b) = -Q^{-1}b = x^*\)&lt;/p&gt;

&lt;h3 id=&quot;-connections-to-other-chapters&quot;&gt;🎯 &lt;strong&gt;Connections to Other Chapters&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-the-previous-chapter&quot;&gt;&lt;strong&gt;From the previous chapter:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 06:&lt;/strong&gt; Gradient Descent - the first-order foundation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 13:&lt;/strong&gt; Duality uses - computational efficiency&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 12:&lt;/strong&gt; KKT conditions - optimality characterization&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;importance-of-newtons-method&quot;&gt;&lt;strong&gt;Importance of Newton’s Method:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Second-order information:&lt;/strong&gt; Uses curvature information&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quadratic convergence:&lt;/strong&gt; Fastest local convergence rate&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine invariance:&lt;/strong&gt; Robust to problem conditioning&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point foundation:&lt;/strong&gt; Basis for barrier methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;looking-ahead&quot;&gt;&lt;strong&gt;Looking ahead:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 15:&lt;/strong&gt; Barrier methods - Newton for constrained problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point methods:&lt;/strong&gt; Polynomial-time algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quasi-Newton methods:&lt;/strong&gt; Practical approximations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trust region methods:&lt;/strong&gt; Alternative globalization strategy&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-theoretical-significance&quot;&gt;🌟 &lt;strong&gt;Theoretical Significance&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;newton-as-the-optimal-second-order-method&quot;&gt;&lt;strong&gt;Newton as the optimal second-order method:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Natural step:&lt;/strong&gt; Minimizes quadratic approximation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine invariant:&lt;/strong&gt; Coordinate-free algorithm&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal convergence:&lt;/strong&gt; Fastest possible local rate&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-correcting:&lt;/strong&gt; Adapts to local curvature&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;computational-trade-offs&quot;&gt;&lt;strong&gt;Computational trade-offs:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Per-iteration cost:&lt;/strong&gt; \(O(n^3)\) vs \(O(n)\) for gradient&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Total iterations:&lt;/strong&gt; Much fewer than first-order&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Memory requirements:&lt;/strong&gt; \(O(n^2)\) vs \(O(n)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical stability:&lt;/strong&gt; More sensitive than gradient methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;theoretical-foundations&quot;&gt;&lt;strong&gt;Theoretical foundations:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quadratic approximation:&lt;/strong&gt; Natural extension of linear approximation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-concordance:&lt;/strong&gt; Elegant analysis framework&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine invariance:&lt;/strong&gt; Geometric rather than algebraic property&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Root finding connection:&lt;/strong&gt; Unifies optimization and equation solving&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;when-to-use-newton-1&quot;&gt;&lt;strong&gt;When to use Newton:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Medium-scale problems:&lt;/strong&gt; \(n \le 10^3\) typically&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High accuracy needed:&lt;/strong&gt; Quadratic convergence valuable&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Well-conditioned:&lt;/strong&gt; Or when affine invariance helps&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smooth problems:&lt;/strong&gt; Hessian computable and reliable&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;implementation-tips&quot;&gt;&lt;strong&gt;Implementation tips:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Never invert Hessian:&lt;/strong&gt; Always solve linear system&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check positive definiteness:&lt;/strong&gt; Ensure Hessian \(\succ 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Use regularization:&lt;/strong&gt; Add \(\epsilon I\) if needed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Monitor condition number:&lt;/strong&gt; Watch for numerical issues&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always use line search:&lt;/strong&gt; For global convergence&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;common-pitfalls&quot;&gt;&lt;strong&gt;Common pitfalls:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Singular Hessian:&lt;/strong&gt; At saddle points or boundaries&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Expensive Hessian:&lt;/strong&gt; When second derivatives costly&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Poor starting point:&lt;/strong&gt; May not reach quadratic phase&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical errors:&lt;/strong&gt; Hessian inversion amplifies errors&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-advanced-topics&quot;&gt;🔬 &lt;strong&gt;Advanced Topics&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;modified-newton-methods&quot;&gt;&lt;strong&gt;Modified Newton methods:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Regularized Newton:&lt;/strong&gt; \(H + \epsilon I\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Levenberg-Marquardt:&lt;/strong&gt; Adaptive regularization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cubic regularization:&lt;/strong&gt; Third-order methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inexact Newton:&lt;/strong&gt; Approximate linear system solution&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;large-scale-adaptations&quot;&gt;&lt;strong&gt;Large-scale adaptations:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quasi-Newton:&lt;/strong&gt; BFGS, L-BFGS approximations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gauss-Newton:&lt;/strong&gt; For least squares problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Truncated Newton:&lt;/strong&gt; CG for linear system&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Limited memory:&lt;/strong&gt; Avoid storing full Hessian&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;constrained-extensions&quot;&gt;&lt;strong&gt;Constrained extensions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sequential Quadratic Programming (SQP):&lt;/strong&gt; Newton for constrained&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point methods:&lt;/strong&gt; Barrier function approach&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Augmented Lagrangian:&lt;/strong&gt; Penalty method combination&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Active set methods:&lt;/strong&gt; Constraint identification&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-real-world-applications&quot;&gt;📈 &lt;strong&gt;Real-World Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;machine-learning&quot;&gt;&lt;strong&gt;Machine Learning:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Logistic regression:&lt;/strong&gt; Standard Newton application&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Neural network training:&lt;/strong&gt; Second-order optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gaussian processes:&lt;/strong&gt; Hyperparameter optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVM training:&lt;/strong&gt; Interior point methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;statistics&quot;&gt;&lt;strong&gt;Statistics:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Maximum likelihood estimation:&lt;/strong&gt; Natural Newton application&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Generalized linear models:&lt;/strong&gt; Iteratively reweighted least squares&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust regression:&lt;/strong&gt; M-estimators&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Survival analysis:&lt;/strong&gt; Cox regression&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;engineering&quot;&gt;&lt;strong&gt;Engineering:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Structural optimization:&lt;/strong&gt; Design optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Control systems:&lt;/strong&gt; Optimal control problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Signal processing:&lt;/strong&gt; Parameter estimation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Image processing:&lt;/strong&gt; Reconstruction problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;finance&quot;&gt;&lt;strong&gt;Finance:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Portfolio optimization:&lt;/strong&gt; Risk management&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Option pricing:&lt;/strong&gt; Calibration problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Risk modeling:&lt;/strong&gt; Parameter estimation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic trading:&lt;/strong&gt; Strategy optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-future-directions&quot;&gt;🔮 &lt;strong&gt;Future Directions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;emerging-developments&quot;&gt;&lt;strong&gt;Emerging developments:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic Newton:&lt;/strong&gt; Online second-order methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Distributed Newton:&lt;/strong&gt; Parallel computation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quantum Newton:&lt;/strong&gt; Quantum optimization algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive methods:&lt;/strong&gt; Problem-specific modifications&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;computational-advances&quot;&gt;&lt;strong&gt;Computational advances:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;GPU acceleration:&lt;/strong&gt; Parallel linear algebra&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Automatic differentiation:&lt;/strong&gt; Efficient Hessian computation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sparse methods:&lt;/strong&gt; Structured Hessian exploitation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Randomized algorithms:&lt;/strong&gt; Sketching techniques&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-key-insights&quot;&gt;💎 &lt;strong&gt;Key Insights&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;newtons-fundamental-contributions&quot;&gt;&lt;strong&gt;Newton’s fundamental contributions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Second-order information:&lt;/strong&gt; Uses curvature for faster convergence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine invariance:&lt;/strong&gt; Coordinate-free optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quadratic convergence:&lt;/strong&gt; Optimal local convergence rate&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Natural algorithm:&lt;/strong&gt; Minimizes quadratic approximation&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;practical-impact&quot;&gt;&lt;strong&gt;Practical impact:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Interior point revolution:&lt;/strong&gt; Enabled polynomial-time algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; Foundation for many optimization algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scientific computing:&lt;/strong&gt; Standard tool for nonlinear equations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Engineering design:&lt;/strong&gt; Enables complex optimization problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-legacy-of-chapter-14&quot;&gt;🌟 &lt;strong&gt;Legacy of Chapter 14:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic breakthrough:&lt;/strong&gt; Second-order optimization methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical foundation:&lt;/strong&gt; Convergence analysis framework&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical impact:&lt;/strong&gt; Enables the solution of complex problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Educational value:&lt;/strong&gt; Bridges linear algebra and optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scientific influence:&lt;/strong&gt; Foundation for modern optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Final message:&lt;/strong&gt; Newton’s method is not just a faster gradient descent - it is a &lt;strong&gt;paradigm shift&lt;/strong&gt; from first-order to second-order thinking, enabling quadratic convergence and affine invariance for optimization problems!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of Newton’s method, including second-order optimization, convergence analysis, backtracking line search, self-concordant functions and quasi-Newton methods.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🔢 Quiz: Newton&apos;s Method&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: The update formula of the pure Newton method (no line search) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(x^{(k+1)} = x^{(k)} - t_k \nabla f(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(x^{(k+1)} = x^{(k)} - t_k [\nabla^2 f(x^{(k)})]^{-1} \nabla f(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(x^{(k+1)} = x^{(k)} - [\nabla^2 f(x^{(k)})]^{-1} \nabla f(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(x^{(k+1)} = x^{(k)} - \nabla^2 f(x^{(k)}) \nabla f(x^{(k)})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) $$x^{(k+1)} = x^{(k)} - [\nabla^2 f(x^{(k)})]^{-1} \nabla f(x^{(k)})$$&lt;/strong&gt;&lt;br /&gt;
                The pure Newton method uses the full Newton step with step size = 1; no line search is needed near the optimum.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The Newton direction \(\Delta x_{nt}\) is computed by solving:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(\nabla^2 f(x) \Delta x_{nt} = \nabla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\nabla^2 f(x) \Delta x_{nt} = -\nabla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(\nabla f(x) \Delta x_{nt} = -\nabla^2 f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(\Delta x_{nt} = -\nabla f(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\nabla^2 f(x) \Delta x_{nt} = -\nabla f(x)$$&lt;/strong&gt;&lt;br /&gt;
                The Newton direction is found by solving a linear system with the Hessian matrix and the negative gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: Newton&apos;s method is called a second-order method because it:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) Uses second derivatives (the Hessian)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Converges in 2 steps&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Needs 2 gradient evaluations&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Has quadratic convergence&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Uses second derivatives (the Hessian)&lt;/strong&gt;&lt;br /&gt;
                Second-order methods use information from second derivatives, unlike first-order methods that only use the gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: The convergence rate of Newton&apos;s method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Superlinear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Quadratic&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Cubic&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) Quadratic&lt;/strong&gt;&lt;br /&gt;
                Newton&apos;s method has quadratic convergence near the optimal point: $$\lVert x^{(k+1)} - x^* \rVert \leq C \lVert x^{(k)} - x^* \rVert^2$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: The Newton decrement \(\lambda(x)\) is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(\lambda(x) = \sqrt{\nabla f(x)^T [\nabla^2 f(x)]^{-1} \nabla f(x)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(\lambda(x) = \nabla f(x)^T [\nabla^2 f(x)]^{-1} \nabla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) $$\lambda(x) = \lVert \nabla f(x) \rVert$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) $$\lambda(x) = \lVert \nabla^2 f(x) \rVert$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\lambda(x) = \sqrt{\nabla f(x)^T [\nabla^2 f(x)]^{-1} \nabla f(x)}$$&lt;/strong&gt;&lt;br /&gt;
                The Newton decrement is a natural, affine-invariant stopping criterion for Newton&apos;s method.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: Newton&apos;s method being affine invariant means that it:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) Does not change under affine coordinate transformations&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) Only works for affine functions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) Needs affine constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Converges linearly&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Does not change under affine coordinate transformations&lt;/strong&gt;&lt;br /&gt;
                Newton&apos;s method does not depend on the coordinate system: under the transformation $$x \mapsto Ax + b$$, the Newton steps transform accordingly.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: Backtracking line search in Newton&apos;s method uses:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) The Armijo condition with the Newton direction&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Exact line search&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Fixed step size&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Golden section search&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The Armijo condition with the Newton direction&lt;/strong&gt;&lt;br /&gt;
                Backtracking line search checks the sufficient-decrease condition: $$f(x + t\Delta x_{nt}) \leq f(x) + \alpha t \nabla f(x)^T \Delta x_{nt}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: Newton&apos;s method can fail when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) The Hessian is not positive definite&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) Starting point xa optimal&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Hessian singular&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) All of the above cases&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above cases&lt;/strong&gt;&lt;br /&gt;
                Newton&apos;s method needs a positive definite Hessian, can diverge from a distant starting point, and fails when the Hessian is singular.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: Self-concordant functions are important because of:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) Convergence analysis that does not depend on constants&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) Affine invariant analysis&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) Barrier functions in interior point methods&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) All of the above reasons&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above reasons&lt;/strong&gt;&lt;br /&gt;
                Self-concordant functions remove the constants problem from the analysis, are affine invariant, and appear naturally in barrier methods.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: A function \(f\) is self-concordant if:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(|f&apos;&apos;&apos;(x)[h,h,h]| \leq 2(f&apos;&apos;(x)[h,h])^{3/2}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(f&apos;&apos;(x) \succ 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(f\) is convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(f\) is smooth&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$|f&apos;&apos;&apos;(x)[h,h,h]| \leq 2(f&apos;&apos;(x)[h,h])^{3/2}$$&lt;/strong&gt;&lt;br /&gt;
                The self-concordance condition controls the third derivative relative to the second derivative.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: Quasi-Newton methods differ from Newton&apos;s method in that they:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Do not need to compute the exact Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Use an approximation of the Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Have lower computational cost&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                Quasi-Newton methods approximate the Hessian to reduce computational cost, which suits problems where the Hessian is expensive to compute.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The BFGS method updates an approximation of the:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Diagonal of the Hessian only&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Inverse Hessian matrix&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Gradient vector&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Objective function&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Inverse Hessian matrix&lt;/strong&gt;&lt;br /&gt;
                BFGS (in its commonly used form) directly updates an approximation $$H_k$$ of the inverse Hessian, avoiding solving a linear system. (There is also an equivalent form that updates an approximation $$B_k$$ of the Hessian itself.)
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The computational cost per iteration of Newton&apos;s method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(O(n)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(O(n^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(O(n^3)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(O(n^4)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) $$O(n^3)$$&lt;/strong&gt;&lt;br /&gt;
                Newton&apos;s method needs $$O(n^2)$$ to compute the Hessian and $$O(n^3)$$ to solve the linear system $$H \Delta x = -g$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: The damped Newton method uses:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) A small fixed step size&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Line search with the Newton direction&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Modified Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Gradient descent direction&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Line search with the Newton direction&lt;/strong&gt;&lt;br /&gt;
                The damped Newton method combines the Newton direction with a line search to guarantee global convergence.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: The trust-region Newton method differs from line-search Newton in that it:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Limits the step size to a region&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Modifies the direction instead of the step size&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Chooses the step by solving a subproblem with the constraint $$\lVert p \rVert \leq \Delta$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                Trust-region methods limit the step to a trusted region, may modify the direction, and choose the step by minimizing the quadratic model subject to the constraint $$\lVert p \rVert \leq \Delta$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: Newton&apos;s method for root finding \(g(x) = 0\) has the formula:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(x^{(k+1)} = x^{(k)} - \frac{g(x^{(k)})}{g&apos;(x^{(k)})}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(x^{(k+1)} = x^{(k)} - g(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(x^{(k+1)} = x^{(k)} - g&apos;(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(x^{(k+1)} = x^{(k)} + \frac{g(x^{(k)})}{g&apos;(x^{(k)})}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$x^{(k+1)} = x^{(k)} - \frac{g(x^{(k)})}{g&apos;(x^{(k)})}$$&lt;/strong&gt;&lt;br /&gt;
                Newton&apos;s method for root finding becomes the optimization case when $$g(x) = \nabla f(x)$$ and we seek $$\nabla f(x) = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: When the Hessian is not positive definite, we can:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Add regularization: \(H + \lambda I\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Use absolute eigenvalues&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Modified Cholesky decomposition&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) All of the above methods&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above methods&lt;/strong&gt;&lt;br /&gt;
                There are many ways to modify the Hessian to ensure positive definiteness: regularization, eigenvalue modification, modified Cholesky.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: The advantages of L-BFGS (Limited-memory BFGS) are:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Memory requirement \(O(n)\) instead of \(O(n^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Suitable for large-scale problems&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) No need to store the full matrix&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) All of the above advantages&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above advantages&lt;/strong&gt;&lt;br /&gt;
                L-BFGS stores only a limited history (usually 5-20 vectors) instead of the full matrix, making it very efficient for large-scale optimization.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: Newton&apos;s method is applied in:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Interior point methods&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Neural network training&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Maximum likelihood estimation&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) All of the above applications&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above applications&lt;/strong&gt;&lt;br /&gt;
                Newton&apos;s method has wide applications: interior point methods, second-order optimization in ML, statistical estimation.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: Compared with first-order methods, Newton&apos;s method has:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Fewer iterations but each iteration is more expensive&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Quadratic convergence vs linear convergence&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Affine invariant vs coordinate dependent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                The Newton trade-off: fewer iterations with faster convergence, but each iteration is more expensive. Affine invariance is a major advantage.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: Newton&apos;s method uses the information of:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Gradient and Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Only the gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Only the Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Only function values&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Gradient and Hessian&lt;/strong&gt;&lt;br /&gt;
                Newton method: $$x^{(k+1)} = x^{(k)} - [\nabla^2 f(x^{(k)})]^{-1} \nabla f(x^{(k)})$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: The convergence rate of Newton&apos;s method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Quadratic (second order)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Sublinear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Cubic&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Quadratic (second order)&lt;/strong&gt;&lt;br /&gt;
                Newton&apos;s method converges quadratically near the solution when the Hessian is invertible.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: Quasi-Newton methods differ from Newton&apos;s method in that they:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Approximate the Hessian instead of computing it exactly&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Do not use the gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Only work for linear functions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Are always slower&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Approximate the Hessian instead of computing it exactly&lt;/strong&gt;&lt;br /&gt;
                Quasi-Newton methods (BFGS, L-BFGS) build a Hessian approximation from gradient information.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The BFGS update formula updates:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) An approximation of the inverse Hessian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) The current point&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) The step size&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) An approximation of the inverse Hessian&lt;/strong&gt;&lt;br /&gt;
                BFGS updates the approximation matrix $$H_k \approx [\nabla^2 f]^{-1}$$ using gradient information.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: For $$f(x) = x^2$$, one Newton step from $$x_0 = 2$$ gives:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$x_1 = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$x_1 = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$x_1 = -2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$x_1 = 2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$x_1 = 0$$&lt;/strong&gt;&lt;br /&gt;
                $$\nabla f(2) = 4$$, $$\nabla^2 f(2) = 2$$. $$x_1 = 2 - 4/2 = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;c&apos;, q2: &apos;b&apos;, q3: &apos;a&apos;, q4: &apos;c&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;a&apos;, q8: &apos;d&apos;, q9: &apos;d&apos;, q10: &apos;a&apos;,
    q11: &apos;d&apos;, q12: &apos;b&apos;, q13: &apos;c&apos;, q14: &apos;b&apos;, q15: &apos;d&apos;,
    q16: &apos;a&apos;, q17: &apos;d&apos;, q18: &apos;d&apos;, q19: &apos;d&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered the Newton method and second-order optimization!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand the Newton method and its convergence analysis well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review self-concordance and quasi-Newton methods.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review the Newton direction and backtracking line search.&apos;;
    } else {
        message = &apos;📖 Study the Newton method again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>14-09 Quasi-Newton methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_09_quasi_newton_methods/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_09_quasi_newton_methods</id>
   <content type="html">&lt;p&gt;Computing and factoring a \(10{,}000 \times 10{,}000\) Hessian at every iteration is out of the question—yet throwing away all curvature information and falling back to plain gradient descent feels wasteful. &lt;strong&gt;Quasi-Newton methods&lt;/strong&gt; (like BFGS and L-BFGS) strike an ingenious compromise: they never compute a single second derivative, instead learning an approximate inverse Hessian \(B_k \approx (\nabla^2 f(x^{(k)}))^{-1}\) on the fly from the gradient differences you &lt;em&gt;already&lt;/em&gt; computed!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-learning-curvature-without-hessians&quot;&gt;Key ideas: Learning Curvature Without Hessians&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The Secant Equation:&lt;/strong&gt; Define step \(s_k = x^{(k+1)} - x^{(k)}\) and gradient change \(y_k = \nabla f(x^{(k+1)}) - \nabla f(x^{(k)})\). Any sensible Hessian approximation \(H_{k+1}\) must satisfy \(H_{k+1} s_k = y_k\) along the most recent step.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Low-Rank Updates Avoid \(O(n^3)\) Factorizations:&lt;/strong&gt; BFGS updates \(H_k^{-1}\) directly via a symmetric rank-2 update in \(O(n^2)\) flops (and L-BFGS in \(O(mn)\) flops using only the last \(m\) pairs \((s_i, y_i)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Curvature Condition Preserves Positive Definiteness:&lt;/strong&gt; Whenever \(s_k^T y_k &amp;gt; 0\) (guaranteed by Wolfe line search on convex functions), BFGS preserves \(H_{k+1} \succ 0\), guaranteeing every quasi-Newton step is a descent direction.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Superlinear Convergence Sweet Spot:&lt;/strong&gt; While slower than Newton’s quadratic rate per iteration, superlinear convergence at \(O(n^2)\) (or \(O(n)\)) per step makes L-BFGS the default workhorse for medium-to-large smooth optimization.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-secant--bfgs-curvature-update-in-1d--2d&quot;&gt;Worked example: One Secant / BFGS Curvature Update in 1D &amp;amp; 2D&lt;/h3&gt;

&lt;p&gt;Suppose we minimize a smooth function in 1D where we only observe gradients (no second derivatives): at \(x^{(0)} = 0\), \(f&apos;(0) = -4\); we take an initial step to \(x^{(1)} = 1\) and observe \(f&apos;(1) = -1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the secant pair \((s_0, y_0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Step: \(s_0 = x^{(1)} - x^{(0)} = 1 - 0 = 1\).&lt;/li&gt;
      &lt;li&gt;Gradient difference: \(y_0 = f&apos;(1) - f&apos;(0) = -1 - (-4) = 3\).&lt;/li&gt;
      &lt;li&gt;Check curvature condition: \(s_0 y_0 = 1 \times 3 = 3 &amp;gt; 0\) (positive curvature!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form the secant Hessian approximation \(H_1\):&lt;/strong&gt;
\(H_1 s_0 = y_0 \implies H_1 = \frac{y_0}{s_0} = \frac{3}{1} = 3 \qquad \left(H_1^{-1} = \frac{1}{3}\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take the quasi-Newton step from \(x^{(1)} = 1\):&lt;/strong&gt;
\(x^{(2)} = x^{(1)} - H_1^{-1} f&apos;(1) = 1 - \frac{1}{3}(-1) = \frac{4}{3} \approx 1.333.\)
Notice that if \(f(x) = \frac{3}{2}x^2 - 4x\) (true minimizer \(x^\star = \frac{4}{3}\)), the secant approximation recovered the &lt;em&gt;exact&lt;/em&gt; Hessian \(3\) from just two gradient evaluations and landed straight on \(x^\star\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
    });
&lt;/script&gt;

&lt;p&gt;If the computation of the Hessian is too expensive or the Hessian is singular, we use quasi-Newton methods to approximate the Hessian matrix, i.e., \(\nabla^{2}f(x)\) is replaced by \(H&amp;gt;0\), and we use \(H\) for the update:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{+} = x - tH^{-1}\nabla f(x)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Some features of quasi-Newton methods are as follows. For more details, see &lt;a href=&quot;/contents/en/chapter18/18_00_Quasi_Newton_methods/&quot;&gt;Chapter 18&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The approximate Hessian \(H\) is updated at each step. The goal is to use a relatively cheap computation for \(H^{-1}\).&lt;/li&gt;
  &lt;li&gt;The convergence rate is superlinear, but not as fast as Newton’s method. Typically, \(n\) steps of quasi-Newton are equivalent to one step of Newton in terms of progress.&lt;/li&gt;
  &lt;li&gt;Many quasi-Newton methods update \(H\) at each iteration using propagation techniques.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>14-08 Special cases</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_08_special_cases/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_08_special_cases</id>
   <content type="html">&lt;p&gt;Does Newton’s method always cost \(O(n^3)\) and work only on unconstrained problems? Not at all! Two industrial breakthroughs unlock Newton for massive real-world systems: exploiting &lt;strong&gt;sparse/banded Hessians&lt;/strong&gt; (dropping the solve cost from \(O(n^3)\) straight down to \(O(n)\)) and solving the &lt;strong&gt;KKT block linear system&lt;/strong&gt; directly for linear equality constraints \(Ax = b\) without ever computing a null-space basis.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-structured-and-equality-constrained-newton&quot;&gt;Key ideas: Structured and Equality-Constrained Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Banded &amp;amp; Sparse Hessians Yield \(O(n)\) Newton:&lt;/strong&gt; When \(\nabla^2 f(x)\) has bandwidth \(b \ll n\) (such as 1D trend filtering, spline smoothing, or trajectory optimization), banded Cholesky costs \(O(nb^2)\)—linear in \(n\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Equality-Constrained Newton via KKT Linearization:&lt;/strong&gt; Starting from a feasible \(x\) (\(Ax = b\)), minimizing the local quadratic subject to \(A\Delta x_{\text{nt}} = 0\) produces the symmetric block KKT system:
\(\begin{bmatrix} \nabla^2 f(x) &amp;amp; A^T \\ A &amp;amp; 0 \end{bmatrix}\begin{bmatrix} \Delta x_{\text{nt}} \\ w \end{bmatrix} = \begin{bmatrix} -\nabla f(x) \\ 0 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Feasibility Is Preserved Forever:&lt;/strong&gt; Because \(A(x + t\Delta x_{\text{nt}}) = Ax + t(0) = b\) for every step size \(t\), once you start feasible, every subsequent iterate stays strictly on the affine subspace \(Ax = b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Reduced-Space vs. Dual Alternatives:&lt;/strong&gt; When \(A\) has few rows (\(p \ll n\)), solving the KKT system or passing to the \(p\)-dimensional Fenchel dual \(\max_v -b^T v - f^*(-A^T v)\) is far cleaner than forming a dense null-space matrix \(F\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-an-equality-constrained-newton-step-via-the-kkt-system&quot;&gt;Worked example: Solving an Equality-Constrained Newton Step via the KKT System&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = x_1^2 + 2x_2^2 - 2x_1\) subject to \(x_1 + x_2 = 3\) (so \(A = [1,\ 1]\), \(b = 3\)), starting from the feasible point \(x^{(0)} = (2, 1)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute gradient and Hessian at \(x^{(0)} = (2, 1)^T\):&lt;/strong&gt;
\(\nabla f(2,1) = \begin{bmatrix} 2(2) - 2 \\ 4(1) \end{bmatrix} = \begin{bmatrix} 2 \\ 4 \end{bmatrix}, \qquad \nabla^2 f(2,1) = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 4 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assemble the \(3 \times 3\) KKT system for \((\Delta x_1, \Delta x_2, w)^T\):&lt;/strong&gt;
\(\begin{bmatrix} 2 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 4 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}\begin{bmatrix} \Delta x_1 \\ \Delta x_2 \\ w \end{bmatrix} = \begin{bmatrix} -2 \\ -4 \\ 0 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve by substitution:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Row 1: \(\Delta x_1 = \frac{-2 - w}{2}\). Row 2: \(\Delta x_2 = \frac{-4 - w}{4}\).&lt;/li&gt;
      &lt;li&gt;Plug into Row 3 (\(\Delta x_1 + \Delta x_2 = 0\)):
\(\frac{-2 - w}{2} + \frac{-4 - w}{4} = 0 \implies -4 - 2w - 4 - w = 0 \implies 3w = -8 \implies w = -\frac{8}{3}.\)&lt;/li&gt;
      &lt;li&gt;Back-substitute: \(\Delta x_1 = \frac{-2 + 8/3}{2} = \frac{1}{3}\), \(\quad \Delta x_2 = \frac{-4 + 8/3}{4} = -\frac{1}{3}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update and check feasibility:&lt;/strong&gt;
\(x^{(1)} = \begin{bmatrix} 2 \\ 1 \end{bmatrix} + \begin{bmatrix} 1/3 \\ -1/3 \end{bmatrix} = \begin{bmatrix} 7/3 \\ 2/3 \end{bmatrix}.\)
Check: \(x_1^{(1)} + x_2^{(1)} = 3\), and \(\nabla f(7/3, 2/3) = (8/3, 8/3)^T = -w A^T\)—exact global optimum in one step!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
    });
&lt;/script&gt;

&lt;h2 id=&quot;sparse-structured-problems&quot;&gt;Sparse, structured problems&lt;/h2&gt;
&lt;p&gt;If the linear system matrix in the problem is sparse and structured, and the Hessian can be efficiently computed, we can solve the problem more efficiently.&lt;/p&gt;

&lt;p&gt;For example, if \(\nabla^{2}f(x)\) is sparse and structured for all \(x\), such as a &lt;a href=&quot;https://en.wikipedia.org/wiki/Band_matrix&quot;&gt;band matrix&lt;/a&gt;, Newton’s method can achieve \(O(n)\) performance in memory and computation. (A band matrix is a matrix where nonzero entries are only near the diagonal.)&lt;/p&gt;

&lt;p&gt;Let’s look at two typical examples of functions with structured Hessians:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;If \(g(\beta) = f(X\beta)\), then \(\nabla^{2}g(\beta)=X^{T}\nabla^{2}f(X\beta)X\). If \(X\) is a structured predictor matrix and \(\nabla^{2}f\) (the Hessian of \(f\)) is diagonal, then \(\nabla^{2}g\) is also structured.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;If \(\nabla^{2}f\) is diagonal and \(g\) is non-smooth, consider minimizing \(f(\beta)+g(D\beta)\), where \(D\) is a structured penalty matrix. The Lagrange dual is \(-f^{*}(-D^{T}u)-g^{*}(-u)\). In general, \(-D\nabla^{2}f^{*}(-D^{T}u)D^{T}\) is also structured.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;equality-constrained-newtons-method&quot;&gt;Equality-constrained Newton’s method&lt;/h2&gt;
&lt;p&gt;Now let’s look at optimization problems with equality constraints. Generally, we can approach this problem in three ways:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} f(x) &amp;amp; \text{subject to }Ax=b.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;1) Reduced-space approach: Restrict the domain to the space satisfying the equality constraint. For the above problem, express \(x\) as \(x=Fy+x_{0}\), where \(F\) spans the null space of \(A\) and \(Ax_{0}=b\). Then solve for \(y\).&lt;/p&gt;

&lt;p&gt;2) Equality-constrained Newton’s method: Similar to unconstrained Newton’s method, but with two differences. First, the initial value must be feasible (\(x \in dom (f)\) and \(Ax = b\)). Second, the Newton step \(\Delta x_{nt}\) must satisfy \(A\Delta x_{nt}=0\). See below for details.&lt;/p&gt;

&lt;p&gt;3) Dual approach: The Fenchel dual is \(-f^{*}(-A^{T}v)-b^{T}v\), and strong duality holds. (&lt;a href=&quot;/contents/en/chapter16/16_03_fenchel_duality/&quot;&gt;16-03&lt;/a&gt; covers this in detail.) Use the conjugate function to solve the dual problem. Here, \(f^{*}\) is the conjugate of \(f\).&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
g(v) &amp;amp;= -b^{T}v + \min_{x}(f(x)+v^{T}Ax)\\\\
&amp;amp;= -b^{T}v - \max_{x}\big( (-A^{T}v)^{T}x - f(x) \big)\\\\
&amp;amp;= -b^{T}v - f^{*}(-A^{T}v),
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This leads to the following dual problem:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\max -b^{T}v-f^{*}(-A^{T}v). 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Assuming the optimal value exists, this problem is strictly feasible and satisfies Slater’s condition. Therefore, as mentioned earlier, strong duality holds, and there exists a \(v^{*}\) such that \(g(v^{*})=p^{*}\).[1, p.525]&lt;/p&gt;

&lt;p&gt;Now, let’s examine the second method.
To derive a feasible Newton step \(\Delta x_{nt}\), we replace the objective function in the original problem with a quadratic approximation around \(x\). This can be expressed as:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\text{minimize}\quad &amp;amp;\hat{f}(x+v) = f(x) + \nabla f(x)^{T}v + \frac{1}{2}v^{T}\nabla^{2} f(x) v\\\\
\text{subject to}\quad &amp;amp;A(x+v) = b,
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This can also be expressed as:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x^{+} = x + tv,\,\, \text{where}\\\\
v = \underset{A(x+z)=b}{\operatorname{argmin}}\big( f(x)+\nabla f(x)^{T}z+\frac{1}{2}z^{T}\nabla^{2} f(x)z \big)\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Since \(Ax^{+} = Ax+tAv = b\), the solution \(x\) remains within the constraint in the subsequent steps of the iteration.&lt;/p&gt;

&lt;p&gt;The KKT conditions for this problem can be expressed as follows, and by solving the linear system below, we can obtain the solution. Recall that \(v\) is the Newton step \(\Delta x_{nt}\).&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\begin{bmatrix}
\nabla^{2} f(x) &amp;amp; A^{T}\\\\
A &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
v\\\\
w
\end{bmatrix}
=-
\begin{bmatrix}
\nabla f(x)\\\\
Ax-b
\end{bmatrix}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(w\) is the optimal dual variable for the above quadratic problem.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-07 Comparison to first-order method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_07_comparison_to_first_order_method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_07_comparison_to_first_order_method</id>
   <content type="html">&lt;p&gt;If Newton’s method converges in 10 iterations while gradient descent needs 10,000, why doesn’t everyone use Newton’s method for deep learning? The answer lies in a single number: \(n^3\). When \(n = 500\), inverting a Hessian takes milliseconds and Newton crushes gradient descent; when \(n = 10^8\) (a neural network), storing the \(n \times n\) Hessian alone would require 40 petabytes of RAM!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-first-order-vs-second-order-trade-off&quot;&gt;Key ideas: The First-Order vs. Second-Order Trade-Off&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Memory Scaling (\(O(n^2)\) vs. \(O(n)\)):&lt;/strong&gt; Dense Newton must store \(\frac{n(n+1)}{2}\) Hessian entries, whereas gradient descent only stores an \(n\)-vector.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Per-Iteration Compute (\(O(n^3)\) vs. \(O(n)\)):&lt;/strong&gt; Dense Cholesky factorization costs \(\frac{1}{3}n^3\) flops per Newton step, versus \(O(n)\) flops for a gradient step.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Conditioning &amp;amp; Accuracy Regime:&lt;/strong&gt; Gradient descent stalls when the condition number \(\kappa = L/m\) is large or when high accuracy (\(\epsilon = 10^{-10}\)) is needed; Newton is immune to \(\kappa\) and thrives on high-precision targets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Crossover Dimension:&lt;/strong&gt; For moderate \(n\) (up to a few thousand) or sparse/structured Hessians, Newton wins in wall-clock time; for huge unstructured \(n\) with low-accuracy targets (e.g., \(\epsilon = 10^{-2}\)), first-order methods dominate.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-wall-clock-cost-crossover-between-gd-and-newton&quot;&gt;Worked example: Wall-Clock Cost Crossover Between GD and Newton&lt;/h3&gt;

&lt;p&gt;Compare solving a dense strongly convex problem of dimension \(n\) with condition number \(\kappa = 1000\) to accuracy \(\epsilon = 10^{-8}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Gradient descent needs roughly \(K_{\text{GD}} \approx \kappa \ln(1/\epsilon) \approx 1000 \times 18.4 \approx 18{,}400\) iterations, costing \(\approx 2n^2\) flops each (for a dense matrix-vector product) \(\implies \text{Total GD flops} \approx 36{,}800\,n^2\).&lt;/li&gt;
  &lt;li&gt;Newton’s method needs roughly \(K_{\text{NT}} \approx 12\) iterations, costing \(\approx \frac{1}{3}n^3\) flops each \(\implies \text{Total Newton flops} \approx 4\,n^3\).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Case 1: \(n = 100\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;GD: \(36{,}800 \times 10^4 = 3.68 \times 10^8\) flops.&lt;/li&gt;
      &lt;li&gt;Newton: \(4 \times 10^6\) flops. &lt;strong&gt;Newton is ~92× faster!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 2: \(n = 1{,}000\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;GD: \(3.68 \times 10^{10}\) flops.&lt;/li&gt;
      &lt;li&gt;Newton: \(4 \times 10^9\) flops. &lt;strong&gt;Newton is ~9× faster!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 3: \(n = 50{,}000\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;GD: \(9.2 \times 10^{13}\) flops (memory: 400 KB for vector).&lt;/li&gt;
      &lt;li&gt;Newton: \(5 \times 10^{14}\) flops (and &lt;strong&gt;20 GB&lt;/strong&gt; just to store the dense Hessian!). &lt;strong&gt;GD wins on both time and memory.&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
    });
&lt;/script&gt;

&lt;p&gt;In this chapter, we compare Newton’s method and gradient descent from a general perspective. Let the dimension of the domain be \(n\).&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Item&lt;/th&gt;
      &lt;th&gt;Newton’s method&lt;/th&gt;
      &lt;th&gt;Gradient descent&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Memory&lt;/td&gt;
      &lt;td&gt;\(O(n^{2})\) (storage for \(n \times n\) Hessian matrix)&lt;/td&gt;
      &lt;td&gt;\(O(n)\) (storage for \(n\)-dimensional gradient)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Computation&lt;/td&gt;
      &lt;td&gt;\(O(n^{3})\) flops (computation for \(n \times n\) linear system)&lt;/td&gt;
      &lt;td&gt;\(O(n)\) flops (computation for \(n\)-dimensional vector addition)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Backtracking&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Conditioning&lt;/td&gt;
      &lt;td&gt;Affine invariant, less affected by conditioning&lt;/td&gt;
      &lt;td&gt;Can be strongly affected by conditioning&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Fragility&lt;/td&gt;
      &lt;td&gt;Sensitive to bugs or numerical errors&lt;/td&gt;
      &lt;td&gt;More robust than Newton’s method&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;example&quot;&gt;Example&lt;/h2&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter14/gd(1).jpeg&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Logistic regression [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Figure 1 above is a logistic regression example discussed in &lt;a href=&quot;/contents/en/chapter14/14_04_backtracking_line_search/&quot;&gt;14-04&lt;/a&gt;. If you plot the x-axis as actual computation time, you see the following. In convergence analysis, Newton’s method has two phases. In practice, after a certain time, you can observe fast convergence (quadratic convergence). In the initial damped phase of Newton’s method, the convergence rate is similar to gradient descent. However, since \(O(n^{3})\) computation is required, the actual computation time may be slower. After backtracking line search is no longer needed, you observe quadratic convergence and very fast progress.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-newton-vs-gradient-descent&quot;&gt;Try it yourself: Newton vs. gradient descent&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;newton&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>14-06 Self concordance</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_06_self_concordance/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_06_self_concordance</id>
   <content type="html">&lt;p&gt;There is an embarrassing paradox in the classical convergence proof of Section 14-05: Newton’s method itself is completely affine invariant, yet its classical iteration bound depends heavily on the constants \(m, L, M\)—which change wildly whenever you rescale your coordinates, and are almost never known in practice (and blow up to \(\infty\) for log barriers!). Nesterov and Nemirovskii resolved this paradox with a single brilliant property: &lt;strong&gt;self-concordance&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-self-concordance-was-invented&quot;&gt;Key ideas: Why Self-Concordance Was Invented&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Eliminating Unknown Constants (\(m, L, M\)):&lt;/strong&gt; Classical bounds fail on functions like \(-\log(x)\) whose Hessian \(1/x^2\) is unbounded near \(0\); self-concordance bounds the third derivative &lt;em&gt;relative to the local second derivative&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Affine-Invariant Theory Matching an Affine-Invariant Algorithm:&lt;/strong&gt; Because self-concordance is preserved under all invertible affine maps \(x = Ay + b\), its iteration-complexity bound is completely independent of coordinate scaling.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — The Engine of Interior-Point Methods:&lt;/strong&gt; Logarithmic barrier functions \(-\sum \log(-h_i(x))\) are self-concordant, which is why interior-point methods enjoy polynomial-time global complexity guarantees in Chapter 15.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Scale-Free Neighborhoods via \(\lambda(x)\):&lt;/strong&gt; For self-concordant functions, the Newton decrement \(\lambda(x)\) alone dictates when backtracking stops and quadratic convergence begins—no \(m\) or \(M\) needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-classical-constants-fail-on-fx---log-x-while-self-concordance-succeeds&quot;&gt;Worked example: Why Classical Constants Fail on \(f(x) = -\log x\) While Self-Concordance Succeeds&lt;/h3&gt;

&lt;p&gt;Consider \(f(x) = -\log(x)\) on \(\operatorname{dom}(f) = (0, \infty)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test the classical Lipschitz conditions from Section 14-05:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;&apos;(x) = \frac{1}{x^2}\) and \(f&apos;&apos;&apos;(x) = -\frac{2}{x^3}\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;As \(x \to 0^+\), \(f&apos;&apos;(x) \to +\infty\) (so no finite upper bound \(L\) exists) and $$&lt;/td&gt;
              &lt;td&gt;f’’‘(x)&lt;/td&gt;
              &lt;td&gt;\to +\infty\((so no finite Hessian Lipschitz constant\)M$$ exists!).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;As \(x \to +\infty\), \(f&apos;&apos;(x) \to 0\) (so no positive strong-convexity constant \(m &amp;gt; 0\) exists!).&lt;/li&gt;
      &lt;li&gt;Conclusion: Classical \(m, L, M\) analysis says &lt;em&gt;nothing&lt;/em&gt; about \(-\log(x)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Test the self-concordance ratio $$\frac{&lt;/td&gt;
          &lt;td&gt;f’’‘(x)&lt;/td&gt;
          &lt;td&gt;}{2 (f’‘(x))^{3/2}}$$:**&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;$$\frac{&lt;/td&gt;
          &lt;td&gt;f’’‘(x)&lt;/td&gt;
          &lt;td&gt;}{2\,(f’‘(x))^{3/2}} = \frac{2/x^3}{2\,(1/x^2)^{3/2}} = \frac{2/x^3}{2/x^3} = 1 \quad \text{for ALL } x &amp;gt; 0!$$&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check affine invariance under \(g(y) = -\log(ay)\) (\(a &amp;gt; 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g&apos;&apos;(y) = 1/y^2\), \(g&apos;&apos;&apos;(y) = -2/y^3\)—the ratio is &lt;em&gt;still&lt;/em&gt; identically \(1\) for every \(a &amp;gt; 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the previous convergence analysis of Newton’s method, there are two major issues. [1]&lt;/p&gt;

&lt;p&gt;First, in practical problems, it is difficult to find the Lipschitz constant L, the lower and upper bounds of strong convexity m, M, etc., which are included in the formulas. Because of this, while we can observe convergence and convergence rate, it is almost impossible to analyze how many Newton steps are needed in practice.&lt;/p&gt;

&lt;p&gt;Second, although Newton’s method itself is affine invariant, the convergence analysis of Newton’s method is not affine invariant. For general functions, the values of the Lipschitz constant or strong convexity bounds change depending on the coordinate transformation.&lt;/p&gt;

&lt;p&gt;Therefore, in this chapter, we introduce self-concordant functions, which address the above two issues.&lt;/p&gt;

&lt;p&gt;Self-concordant functions are important and meaningful for three main reasons:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The log barrier functions used in interior-point methods are self-concordant functions.&lt;/li&gt;
  &lt;li&gt;In the analysis of Newton’s method for self-concordant functions, terms involving constants do not appear.&lt;/li&gt;
  &lt;li&gt;Self-concordance is affine-invariant. That is, the number of Newton iterations required is independent of affine transformations of the coordinate system.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>14-06-02 Convergence analysis for self-concordant functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_06_02_convergence_analysis_for_self_concordant_functions/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_06_02_convergence_analysis_for_self_concordant_functions</id>
   <content type="html">&lt;p&gt;With self-concordance in hand, Nesterov and Nemirovskii delivered one of the cleanest theorems in all of optimization: damped Newton’s method reaches \(\epsilon\)-accuracy in at most \(C(\alpha,\beta)(f(x^{(0)}) - f^\star) + \log_2\log_2(1/\epsilon)\) iterations. Notice what is &lt;em&gt;missing&lt;/em&gt; from that formula: no dimension \(n\), no condition number \(\kappa\), no Lipschitz constant \(L\), and no strong convexity \(m\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-scale-free-complexity-of-damped-newton&quot;&gt;Key ideas: Scale-Free Complexity of Damped Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Universal Damped-Phase Constant:&lt;/strong&gt; Whenever \(\lambda(x) &amp;gt; \eta\) (a pure numerical constant independent of \(f\)), backtracking reduces \(f(x)\) by at least a fixed constant \(\gamma(\alpha,\beta) &amp;gt; 0\) per step.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Universal Quadratic-Phase Threshold:&lt;/strong&gt; Once \(\lambda(x) \le \frac{1}{4}\) (or \(\eta\)), unit step \(t = 1\) is always accepted and \(\lambda(x^+) \le 2\lambda(x)^2\) (strictly quadratic contraction in the Newton decrement).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Suboptimality Bound Directly from \(\lambda(x)\):&lt;/strong&gt; When \(\lambda(x) &amp;lt; 1\), self-concordance guarantees \(f(x) - f^\star \le \lambda(x)^2\) (for \(\lambda(x) \le 0.68\)), turning \(\lambda(x)\) into an exact, rigorous stopping certificate.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Affine-Invariant Total Iteration Count:&lt;/strong&gt; Because \(f(x^{(0)}) - f^\star\) and \(\epsilon\) are unchanged under \(x = Ay + b\), the entire iteration bound is strictly affine invariant.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-estimating-total-newton-steps-from-the-self-concordant-bound&quot;&gt;Worked example: Estimating Total Newton Steps from the Self-Concordant Bound&lt;/h3&gt;

&lt;p&gt;Suppose a self-concordant problem starts with initial gap \(f(x^{(0)}) - f^\star = 5\), and we use standard backtracking parameters \(\alpha = 0.1, \beta = 0.5\) where the theoretical damped-phase constant is roughly \(C(\alpha,\beta) = \frac{1}{\gamma} \approx 20 / \alpha\beta\) (in Boyd &amp;amp; Vandenberghe, Theorem 9.6, \(C(\alpha,\beta) = \frac{20 - 8\alpha}{\alpha\beta(1-2\alpha)^2}\), while in practice the damped phase is even faster). Let’s trace the Phase-II quadratic finish from \(\lambda(x^{(k)}) = 0.25\) using the self-concordant recursion \(\lambda(x^+) \le \frac{\lambda(x)^2}{(1 - \lambda(x))^2}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Step 0:&lt;/strong&gt; \(\lambda_0 = 0.25\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; \(\lambda_1 \le \frac{0.25^2}{(0.75)^2} = \frac{1}{9} \approx 0.1111\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; \(\lambda_2 \le \frac{(1/9)^2}{(8/9)^2} = \frac{1}{64} \approx 0.01563\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; \(\lambda_3 \le \frac{(1/64)^2}{(63/64)^2} = \frac{1}{3969} \approx 2.52 \times 10^{-4}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; \(\lambda_4 \le \frac{(2.52 \times 10^{-4})^2}{(1 - 2.52 \times 10^{-4})^2} \approx 6.35 \times 10^{-8}\), giving \(f(x) - f^\star \le \lambda_4^2 \approx 4.0 \times 10^{-15}\)! Just 4 steps take you from \(0.25\) to machine precision, matching the \(\log_2\log_2(1/\epsilon)\) term.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For self-concordant functions, the result of convergence analysis is as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Theorem (Nesterov and Nemirovskii): Newton’s method with backtracking line search requires the following number of iterations to achieve \(f(x^{(k)})-f^{\star}\leq \epsilon\):
\begin{align}
C(\alpha, \beta)\big( f(x^{(0)}-f^{\star} \big) + \log\log{(1/\epsilon)},
\end{align}
where \(C(\alpha, \beta)\) is a constant depending on \(\alpha, \beta\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The proof above is similar to the convergence analysis for Newton’s method, but uses the properties of self-concordant functions to organize the steps. (See [1], p.503)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-06-01 Definition of self-concordant functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_06_01_definition_of_self_concordant_functions/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_06_01_definition_of_self_concordant_functions</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;How do you guarantee that a function’s curvature doesn’t change too violently as you take a Newton step, &lt;em&gt;without&lt;/em&gt; fixing a global Euclidean scale? You measure the rate of change of curvature ($$&lt;/td&gt;
      &lt;td&gt;f’’‘(x)&lt;/td&gt;
      &lt;td&gt;\() in units of the current curvature itself (\)f’‘(x)^{3/2}\(). That dimensionless inequality,\)&lt;/td&gt;
      &lt;td&gt;f’’‘(x)&lt;/td&gt;
      &lt;td&gt;\le 2 f’‘(x)^{3/2}$$, is the exact definition of a self-concordant function.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;key-ideas-calculus-of-self-concordant-functions&quot;&gt;Key ideas: Calculus of Self-Concordant Functions&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 1 — The 1D Defining Inequality:&lt;/strong&gt; A \(C^3\) convex function \(f: \mathbb{R} \to \mathbb{R}\) is self-concordant iff $$&lt;/td&gt;
          &lt;td&gt;f’’‘(x)&lt;/td&gt;
          &lt;td&gt;\le 2 f’‘(x)^{3/2}\(everywhere on its domain (equivalently,\)\left&lt;/td&gt;
          &lt;td&gt;\frac{d}{dx}\big(f’‘(x)^{-1/2}\big)\right&lt;/td&gt;
          &lt;td&gt;\le 1$$).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Lifting to \(\mathbb{R}^n\) via Line Restrictions:&lt;/strong&gt; A multivariate function \(f: \mathbb{R}^n \to \mathbb{R}\) is self-concordant iff every 1D slice \(g(t) = f(x + tv)\) is self-concordant in \(t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Closure Under Addition and Affine Composition:&lt;/strong&gt; Sums of self-concordant functions are self-concordant (via \((u^{3/2} + v^{3/2})^{2/3} \le u + v\)), and composing with \(Ax + b\) preserves self-concordance automatically.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Canonical Building Blocks:&lt;/strong&gt; Affine functions, convex quadratics (\(f&apos;&apos;&apos; = 0\)), \(-\log(x)\), and \(-\log\det(X)\) on \(\mathbb{S}^n_{++}\) are all self-concordant—forming the toolkit for LP, QP, SOCP, and SDP barriers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-checking-which-functions-are-self-concordant&quot;&gt;Worked example: Checking Which Functions Are Self-Concordant&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Test three 1D convex functions against $$&lt;/td&gt;
      &lt;td&gt;f’’‘(x)&lt;/td&gt;
      &lt;td&gt;\le 2 f’‘(x)^{3/2}$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Log-barrier of a linear inequality \(f(x) = -\log(b - ax)\) on \(ax &amp;lt; b\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(x) = \frac{a}{b-ax}\), \(\quad f&apos;&apos;(x) = \frac{a^2}{(b-ax)^2}\), \(\quad f&apos;&apos;&apos;(x) = \frac{2a^3}{(b-ax)^3}\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Check: $$&lt;/td&gt;
              &lt;td&gt;f’’‘(x)&lt;/td&gt;
              &lt;td&gt;= \frac{2&lt;/td&gt;
              &lt;td&gt;a&lt;/td&gt;
              &lt;td&gt;^3}{(b-ax)^3} = 2\left(\frac{a^2}{(b-ax)^2}\right)^{3/2} = 2 f’‘(x)^{3/2}$$. &lt;strong&gt;Self-concordant!&lt;/strong&gt;&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaled logarithm \(f(x) = -\alpha \log(x)\) (\(\alpha &amp;gt; 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;\(f&apos;&apos;(x) = \frac{\alpha}{x^2}\), $$\quad&lt;/td&gt;
              &lt;td&gt;f’’‘(x)&lt;/td&gt;
              &lt;td&gt;= \frac{2\alpha}{x^3}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Compare with \(2 f&apos;&apos;(x)^{3/2} = \frac{2\alpha^{3/2}}{x^3}\).&lt;/li&gt;
      &lt;li&gt;Holds iff \(\alpha \le \alpha^{3/2} \iff \alpha \ge 1\)! Thus \(-0.5\log(x)\) is &lt;em&gt;not&lt;/em&gt; self-concordant, while \(-2\log(x)\) is.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exponential \(f(x) = e^x\) on \(\mathbb{R}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;&apos;(x) = e^x\), \(f&apos;&apos;&apos;(x) = e^x\). Condition requires \(e^x \le 2 e^{3x/2} \iff e^{-x/2} \le 2\), which &lt;strong&gt;fails&lt;/strong&gt; as \(x \to -\infty\)! Thus \(e^x\) is &lt;em&gt;not&lt;/em&gt; self-concordant.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
    });
&lt;/script&gt;

&lt;h2 id=&quot;self-concordant-on-r&quot;&gt;Self-concordant on \(R\)&lt;/h2&gt;
&lt;p&gt;A convex function \(f : R \rightarrow R\) is defined as self-concordant when it satisfies the following equation:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\|f^{&apos;&apos;&apos;}(x)\| \leq 2f^{&apos;&apos;}(x)^{3/2} \qquad \text{for all }x\in \text{dom }f.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;As simple examples, linear functions (\(ax+b\)) and (convex) quadratic functions are self-concordant because their third derivative values are 0.&lt;/p&gt;

&lt;h2 id=&quot;self-concordant-on-rn&quot;&gt;Self-concordant on \(R^{n}\)&lt;/h2&gt;
&lt;p&gt;A function \(f : R^{n}\rightarrow R\) is defined as self-concordant when it is self-concordant for any line segment within the domain, that is, for all line segments included in the domain. For example, for all \(x\in dom\, f\) and all \(v\), when \(g(t) = f(x+tv)\) is defined, if \(g(t)\) is self-concordant, then f is defined as a self-concordant function in the domain of \(\mathbb{R}^{n}\).&lt;/p&gt;

&lt;h2 id=&quot;example-of-self-concordance-function&quot;&gt;Example of self-concordance function&lt;/h2&gt;

&lt;p&gt;1) \(f : \mathbb{R}^{n}_{++}\rightarrow \mathbb{R}\), \(f(x) = -\sum^{n}_{i=1}log(x_{i})\).&lt;/p&gt;

&lt;p&gt;It can be easily verified that \(f(t) = -\log{t}\). Furthermore, the sum of self-concordant functions is also self-concordant. When there are self-concordant functions \(f_{1}, f_{2} : R\rightarrow R\), the sum of self-concordant functions is also self-concordant as shown below.[3]&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
|f_{1}^{&apos;&apos;&apos;}(x)+f_{2}^{&apos;&apos;&apos;}(x)|  \leq &amp;amp; |f^{&apos;&apos;&apos;}_{1}(x)|+|f^{&apos;&apos;&apos;}_{2}(x)|\\\\
\leq &amp;amp;2\big( f^{&apos;&apos;}_{1}(x)^{3/2}+f^{&apos;&apos;}_{2}(x)^{3/2}\big)\\\\
\leq &amp;amp;2\big( f^{&apos;&apos;}_{1}(x)+f^{&apos;&apos;}_{2}(x) \big)^{3/2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The last step uses the following property:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
(u^{3/2}+v^{3/2})^{2/3} \leq u+v, \qquad u, v \geq 0.
\end{align}\]
&lt;/blockquote&gt;

</content>
 </entry>
 
 <entry>
   <title>14-05 Convergence analysis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_05_convergence_analysis/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_05_convergence_analysis</id>
   <content type="html">&lt;p&gt;Watch a plot of error versus iteration for damped Newton’s method on a log scale and you will always see a dramatic elbow: first a steady straight ramp downward, then suddenly a vertical cliff where the error drops from \(10^{-2}\) to \(10^{-15}\) in four iterations. Classical convergence theory explains that exact two-act structure by splitting the algorithm into the &lt;strong&gt;damped phase&lt;/strong&gt; (constant objective drop per step) and the &lt;strong&gt;quadratically convergent pure phase&lt;/strong&gt; (unit steps, digits doubling).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-two-phase-convergence-theorem&quot;&gt;Key ideas: The Two-Phase Convergence Theorem&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Three Smoothness Assumptions (\(m, L, M\)):&lt;/strong&gt; Strong convexity (\(mI \preceq \nabla^2 f(x)\)), gradient smoothness (\(\nabla^2 f(x) \preceq LI\)), and Hessian Lipschitz continuity (\(\|\nabla^2 f(x) - \nabla^2 f(y)\|_2 \le M\|x-y\|_2\)) control how faithfully the local quadratic tracks \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Phase I (Damped Phase, \(\|\nabla f(x^{(k)})\|_2 \ge \eta\)):&lt;/strong&gt; Backtracking guarantees a fixed minimum drop \(f(x^{(k+1)}) - f(x^{(k)}) \le -\gamma\) at every iteration, bounding the total number of damped steps by \((f(x^{(0)}) - f^\star)/\gamma\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Phase II (Pure Quadratic Phase, \(\|\nabla f(x^{(k)})\|_2 &amp;lt; \eta\)):&lt;/strong&gt; Once the gradient norm crosses below \(\eta \le \frac{m^2}{M}\), backtracking always accepts \(t = 1\) and the gradient norm squares at each step: \(\frac{M}{2m^2}\|\nabla f(x^{(k+1)})\|_2 \le \left(\frac{M}{2m^2}\|\nabla f(x^{(k)})\|_2\right)^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Total Iteration Complexity:&lt;/strong&gt; Combining both phases yields at most \(\frac{f(x^{(0)}) - f^\star}{\gamma} + \log_2 \log_2(\epsilon_0/\epsilon)\) iterations—notice that reaching \(10^{-12}\) accuracy instead of \(10^{-6}\) costs only &lt;strong&gt;one&lt;/strong&gt; extra Newton step!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-phase-ii-quadratic-contraction-numbers&quot;&gt;Worked example: Computing Phase-II Quadratic Contraction Numbers&lt;/h3&gt;

&lt;p&gt;Suppose a strongly convex function has \(m = 2\) and Hessian Lipschitz constant \(M = 1\), so the quadratic contraction constant is \(C = \frac{M}{2m^2} = \frac{1}{8} = 0.125\), and the Phase-II threshold is \(\eta = \frac{m^2}{M} = 4\) (we enter Phase II safely once \(C\|\nabla f(x^{(k)})\|_2 \le \frac{1}{2}\), i.e., \(\|\nabla f(x^{(k)})\|_2 \le 4\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Enter Phase II at \(\|\nabla f(x^{(0)})\|_2 = 2.0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Scaled gradient norm: \(e_0 = C\|\nabla f(x^{(0)})\|_2 = 0.125 \times 2.0 = 0.25 = \frac{1}{4}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Track the guaranteed upper bound \(e_{k+1} \le e_k^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Step 1: \(e_1 \le (0.25)^2 = 0.0625 \implies \|\nabla f(x^{(1)})\|_2 \le 0.5\).&lt;/li&gt;
      &lt;li&gt;Step 2: \(e_2 \le (0.0625)^2 \approx 3.91 \times 10^{-3} \implies \|\nabla f(x^{(2)})\|_2 \le 0.03125\).&lt;/li&gt;
      &lt;li&gt;Step 3: \(e_3 \le (3.91 \times 10^{-3})^2 \approx 1.53 \times 10^{-5} \implies \|\nabla f(x^{(3)})\|_2 \le 1.22 \times 10^{-4}\).&lt;/li&gt;
      &lt;li&gt;Step 4: \(e_4 \le (1.53 \times 10^{-5})^2 \approx 2.33 \times 10^{-10} \implies \|\nabla f(x^{(4)})\|_2 \le 1.86 \times 10^{-9}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suboptimality bound via strong convexity (\(f(x) - f^\star \le \frac{1}{2m}\|\nabla f(x)\|_2^2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;After just 4 pure Newton steps, \(f(x^{(4)}) - f^\star \le \frac{(1.86 \times 10^{-9})^2}{4} \approx 8.7 \times 10^{-19}\)—past double-precision machine epsilon!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
    });
&lt;/script&gt;

&lt;p&gt;So far, we have examined pure Newton’s method, which only has local convergence properties, and damped Newton’s method (Newton’s method with backtracking line search), which applies backtracking line search to ensure global convergence when convex.&lt;/p&gt;

&lt;p&gt;In this chapter, we analyze the convergence rate of damped Newton’s method. For damped Newton’s method, we examine convergence bounds divided into two phases: the phase where backtracking is applied (damped phase: slow progress) and the locally convergent phase where backtracking is no longer needed (pure phase: quadratic convergence).&lt;/p&gt;

&lt;h2 id=&quot;conditions-of-f-for-convergence-analysis&quot;&gt;Conditions of \(f\) for convergence analysis&lt;/h2&gt;
&lt;p&gt;Assume that \(f\) is convex, twice differentiable, has \(dom(f)=\mathbb{R}^{n}\), and satisfies the following three conditions:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;\(\nabla f\) is Lipschitz continuous with parameter L.
    &lt;blockquote&gt;
\[\begin{align}
\|\nabla f(x) - \nabla f(y)\|_{2} \leq L\|x-y\|_{2} \quad \forall x,y.
\end{align}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;\(f\) is strongly convex with parameter m. (Relationship between upper bound \(L\) and Lipschitz continuous: &lt;a href=&quot;https://xingyuzhou.org/blog/notes/strong-convexity&quot;&gt;source&lt;/a&gt;, &lt;a href=&quot;/contents/en/chapter06/06_03_05_look_at_the_conditions_and_practicalities/&quot;&gt;this book: 06-03-05&lt;/a&gt;)
    &lt;blockquote&gt;
\[\begin{align}
mI\preceq\nabla^{2}f(x)\preceq LI.
\end{align}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;\(\nabla^{2} f\) is Lipschitz continuous with parameter M.
    &lt;blockquote&gt;
\[\begin{align}
\|\nabla^{2}f(x)-\nabla^{2}f(y)\|_{2} \leq M\|x-y\|_{2} \quad \forall x,y.
\end{align}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;convergence-analysis&quot;&gt;Convergence analysis&lt;/h2&gt;
&lt;p&gt;If the above three conditions are satisfied, for \(\eta, \gamma\) satisfying \(0&amp;lt;\eta \leq m^{2}/M\) and \(\gamma&amp;gt;0\), the convergence for each phase can be obtained as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Phase I : “Damped” phase, \(\|\nabla f(x^{(k)})\|_{2} \geq \eta\),&lt;/p&gt;

\[\begin{align}
f(x^{(k+1)})-f(x^{(k)}) \leq -\gamma
\end{align}\]

  &lt;p&gt;Phase II : “Pure” phase, \(\|\nabla f(x^{(k)})\|_{2}&amp;lt;\eta\), backtracking selects \(t = 1\)&lt;/p&gt;

\[\begin{align}
\frac{M}{2m^{2}}\|\nabla f(x^{(k+1)})\|_{2} \leq \bigg( \frac{M}{2m^{2}}\|\nabla f(x^{(k)})\|_{2} \bigg)^{2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Note that once the Pure phase is reached when \(\|\nabla f(x^{(k)})\|_{2}&amp;lt;\eta\) is satisfied at the \(k\)-th iteration for the first time, this condition is always satisfied for subsequent iterations.&lt;/p&gt;

&lt;h2 id=&quot;convergence-analysis--written-in-optimal-value-term&quot;&gt;Convergence analysis : written in optimal value term&lt;/h2&gt;
&lt;p&gt;Now we want to compare the convergence of each phase in terms of the difference from the optimal value.&lt;/p&gt;

&lt;p&gt;For Phase I, if we perform \(k\) iterations starting from \(x^{(0)}\), we can organize the equation for each step and represent it as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\require{cancel}
&amp;amp; &amp;amp;\cancel{f(x^{(1)})}-f(x^{(0)}) \leq -\gamma \\\\
&amp;amp; &amp;amp;\cancel{f(x^{(2)})}-\cancel{f(x^{(1)})} \leq -\gamma \\\\
&amp;amp; &amp;amp;\vdots \\\\
&amp;amp;+ &amp;amp;f(x^{(k)})-\cancel{f(x^{(k-1)})} \leq -\gamma \\\\
&amp;amp;= &amp;amp;f(x^{(k)})-f(x^{(0)})\leq -k\gamma.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Subtracting \(f^{\star}\) from both sides, we obtain the following result. Let \(k_{0}\) be the first \(k\) that satisfies \(\|\nabla f(x^{(k)})\|_{2}&amp;lt;\eta\) (the iterations \(k \le k_0\) belong to the damped phase).&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)})-f^{\star} \leq (f(x^{(0)})-f^{\star})-\gamma k \qquad \text{if }k \leq k_{0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;For Phase II, assume that the iteration starts from \(k_{0}\) and proceeds for \(k-k_{0}\) steps. Also, using \(\|\nabla f(x^{(k_0)})\|_2&amp;lt;\eta \leq m^{2}/M\) from above and strong convexity, we can organize the equation as follows (set \(a_k = \frac{M}{2m^{2}}\|\nabla f(x^{(k)})\|_{2}\), so that \(a_{k_0} \leq \frac{1}{2}\)):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;a_{k+1} \leq a_{k}^{2}\\\\
&amp;amp;\Rightarrow &amp;amp;a_{k} \leq a_{k_0}^{2^{k-k_{0}}} \leq \Big(\frac{1}{2}\Big)^{2^{k-k_{0}}}\\\\
&amp;amp;\Rightarrow &amp;amp;\|\nabla f(x^{(k)})\|_{2} \leq \frac{2m^{2}}{M}\Big(\frac{1}{2}\Big)^{2^{k-k_{0}}}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;From strong convexity, \(f(y)\geq f(x)+\nabla f(x)^{T}(y-x)+\frac{m}{2}\|y-x\|^{2}_{2}\geq f(x)-\frac{1}{2m}\|\nabla f(x)\|^{2}_{2}\) for all \(y\), so&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)})-f^{\star} \leq \frac{1}{2m}\|\nabla f(x^{(k)})\|_{2}^{2}\leq \frac{2m^{3}}{M^{2}}\Big(\frac{1}{2}\Big)^{2^{k-k_{0}+1}}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore, we can summarize the convergence according to steps, with the \(k_{0}\)-th iteration as the branch point, as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Theorem: Newton’s method using backtracking line search has two-stage convergence bounds.
\(\begin{align}
&amp;amp;f(x^{(k)})-f^{\star} \leq \begin{cases} (f(x^{(0)})-f^{\star})-\gamma k \qquad &amp;amp;\text{if }k\leq k_{0}\\\\
\frac{2m^{3}}{M^{2}}(\frac{1}{2})^{2^{k-k_{0}+1}} \qquad &amp;amp;\text{if }k&amp;gt;k_{0}.
\end{cases}
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Here, \(\gamma = \frac{\alpha \beta \eta^{2}m}{L^{2}}\), \(\eta = \min\{1, 3(1-2\alpha)\}\frac{m^{2}}{M}\), and \(k_{0}\) is the step where the condition \(\|\nabla f(x^{(k_0)})\|_{2}&amp;lt;\eta\) starts to be satisfied.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;proof-1-damped-phase&quot;&gt;Proof 1. Damped phase&lt;/h2&gt;
&lt;p&gt;First, we derive the damped phase that satisfies \(\|\nabla f(x)\|_{2} \geq \eta\). We derive the convergence of the damped phase through the lower bound of the step size determined by the backtracking line search process. The Newton decrement relationship is frequently used in the proof.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;We start from the following inequality, where we set \(y=x+t\Delta x_{nt}\) in the Taylor approximation of \(f\) and apply the upper bound from the Lipschitz condition.&lt;/p&gt;

\[\begin{align}
f(x+t\Delta x_{nt}) \leq f(x)+t\nabla f(x)^{T}\Delta x_{nt} + \frac{L \|\Delta x_{nt} \|^{2}_{2} }{2}t^{2},
\end{align}\]

  &lt;p&gt;Using the relationship between the Newton decrement, the Newton step and the Hessian matrix, together with strong convexity, we can develop this as follows.&lt;/p&gt;

\[\begin{align}
&amp;amp;\text{Since }\lambda(x)^{2}=\Delta x_{nt}^{T} \nabla^{2} f(x) \Delta x_{nt} \geq m\|\Delta x_{nt}\|^{2}_{2}\text{ and }\nabla f(x)^{T}\Delta x_{nt} = -\lambda(x)^{2},\\\\
&amp;amp;f(x)+t\nabla f(x)^{T}\Delta x_{nt} + \frac{L \|\Delta x_{nt} \|^{2}_{2} }{2}t^{2} \leq f(x)-t\lambda(x)^{2} + \frac{L}{2m}t^{2}\lambda(x)^{2},
\end{align}\]

  &lt;p&gt;To satisfy the backtracking line search condition, we consider \(t\) satisfying the following inequality.&lt;/p&gt;

\[\begin{align}
f(x+t\Delta x_{nt}) \leq f(x)-(1-\frac{L}{2m}t)t \lambda(x)^{2}, \qquad \text{ where }0&amp;lt;1-\frac{L}{2m}t \leq \frac{1}{2}
\end{align}\]

  &lt;p&gt;Let \(\hat{t}\) be the largest \(t\) satisfying the above; then \(\hat{t} = \frac{m}{L}\), and substituting it into the original inequality gives&lt;/p&gt;

\[\begin{align}
f(x+\hat{t}\Delta x_{nt})\leq f(x)-\frac{m}{2L}\lambda(x)^{2} \leq f(x) -\alpha \hat{t} \lambda(x)^{2},
\end{align}\]

  &lt;p&gt;(the last inequality holds because \(\alpha &amp;lt; 1/2\)). Since \(0&amp;lt;\beta\leq 1\) in backtracking line search, we have \(t\geq \beta \frac{m}{L}\), and rearranging we obtain the final result.&lt;/p&gt;

\[\begin{align}
f(x^{+})-f(x) &amp;amp;\leq -\alpha t \lambda(x)^{2}\\\\
&amp;amp;\leq -\alpha\beta \frac{m}{L}\lambda(x)^{2}\\\\
&amp;amp;\leq -\alpha\beta \frac{m}{L^{2}}\|\nabla f(x)\|^{2}_{2}\\\\
&amp;amp;\leq -\alpha\beta \eta^{2}\frac{m}{L^{2}},\\\\
&amp;amp;\gamma = \alpha\beta \eta^{2}\frac{m}{L^{2}}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;(In the third step we used \(\lambda(x)^{2} = \nabla f(x)^{T}\nabla^{2}f(x)^{-1}\nabla f(x) \geq \|\nabla f(x)\|_2^2 / L\).)&lt;/p&gt;

&lt;h2 id=&quot;proof-2-pure-phase&quot;&gt;Proof 2. Pure phase&lt;/h2&gt;
&lt;p&gt;Now assume \(\|\nabla f(x)\|_{2} &amp;lt; \eta\) and consider the pure phase (the quadratically convergent phase). The proof has two parts: we show that the update of \(t\) in backtracking line search is not necessary, and that the convergence rate is quadratic.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;From backtracking line search, we have the following inequality.&lt;/p&gt;

\[\begin{align}
\eta \leq 3(1-2\alpha)\frac{m^{2}}{M}.
\end{align}\]

  &lt;p&gt;Also, by the Lipschitz condition, for \(t \geq 0\) the following conditions hold.&lt;/p&gt;

\[\begin{align}
\|\nabla^{2}f(x+t\Delta x_{nt})-\nabla^{2}f(x)\|_{2} \leq tM \|\Delta x_{nt} \|_{2},\\\\
| \Delta x_{nt}^{T} \big( \nabla^{2}f(x+t\Delta x_{nt})-\nabla^{2}f(x) \big) \Delta x_{nt}| \leq tM \|\Delta x_{nt} \|_{2}^{3}.
\end{align}\]

  &lt;p&gt;Let \(\tilde{f}(t) = f(x+t\Delta x_{nt})\); then \(\tilde{f}&apos;&apos;(t) = \Delta x_{nt}^{T} \nabla^{2}f(x+t\Delta x_{nt})\Delta x_{nt}\), and substituting this gives&lt;/p&gt;

\[\begin{align}
\tilde{f}&apos;&apos;(t) \leq \tilde{f}&apos;&apos;(0)+tM\|\Delta x_{nt}\|^{3}_{2}
\end{align}\]

  &lt;p&gt;Using \(\tilde{f}&apos;&apos;(0) = \lambda(x)^{2}\) and \(\lambda(x)^{2} \geq m\|\Delta x_{nt}\|_{2}^{2}\) (so \(\|\Delta x_{nt}\|_2^3 \le \lambda(x)^3/m^{3/2}\)), we combine the inequalities. Since \(\tilde{f}&apos;(0) = -\lambda(x)^{2}\), we can organize as follows.&lt;/p&gt;

\[\begin{align}
\tilde{f}&apos;&apos;(t) &amp;amp;\leq \lambda(x)^{2} + t\frac{M}{m^{3/2}}\lambda(x)^{3}, \\\\
\tilde{f}&apos;(t) &amp;amp;\leq \tilde{f}&apos;(0)+t\lambda(x)^{2} +t^{2}\frac{M}{2m^{3/2}}\lambda(x)^{3}\\\\
&amp;amp;= -\lambda(x)^{2}+t\lambda(x)^{2} + t^{2}\frac{M}{2m^{3/2}}\lambda(x)^{3}.
\end{align}\]

  &lt;p&gt;Now integrate both sides.&lt;/p&gt;

\[\begin{align}
\tilde{f}(t) \leq \tilde{f}(0) - t\lambda(x)^{2} + t^{2} \frac{1}{2}\lambda(x)^{2} + t^{3}\frac{M}{6m^{3/2}}\lambda(x)^{3}.
\end{align}\]

  &lt;p&gt;Setting \(t = 1\), we obtain the following result.&lt;/p&gt;

\[\begin{align}
f(x+\Delta x_{nt}) \leq f(x) -\frac{1}{2}\lambda(x)^{2} + \frac{M}{6m^{3/2}}\lambda(x)^{3}.
\end{align}\]

  &lt;p&gt;Now assume \(\|\nabla f(x)\|_{2}\leq \eta \leq 3(1-2\alpha)\frac{m^{2}}{M}\). By strong convexity, \(\lambda(x) \leq \|\nabla f(x)\|_{2}/m^{1/2} \leq 3(1-2\alpha)m^{3/2}/M\). Substituting this into the inequality above, we get&lt;/p&gt;

\[\begin{align}
f(x+\Delta x_{nt}) &amp;amp;\leq f(x) - \lambda(x)^{2}( \frac{1}{2}- \frac{M\lambda(x)}{6m^{3/2}} ) \\\\
&amp;amp;\leq f(x) -\alpha \lambda(x)^{2} \\\\
&amp;amp;= f(x) + \alpha \nabla f(x)^{T} \Delta x_{nt},
\end{align}\]

  &lt;p&gt;This means that for \(t=1\) the backtracking line search condition is always satisfied, so \(t\) is not decreased.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now we prove that the convergence rate is quadratic.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Use \(\Delta x_{nt} = -(\nabla^{2}f(x))^{-1}\nabla f(x)\) and the integral identity \(\nabla f(x+\Delta x_{nt}) - \nabla f(x) = \int^{1}_{0}{\nabla^{2}f(x+t\Delta x_{nt})\Delta x_{nt}\, dt}\), apply the Lipschitz condition of the Hessian to the integral and organize. Finally, applying the strong convexity condition completes the proof. The process is written out as follows.&lt;/p&gt;

\[\begin{align}
\| \nabla f(x^{+}) \| _{2} &amp;amp;= \| \nabla f(x+\Delta x_{nt}) - \nabla f(x) - \nabla^{2}f(x)\Delta x_{nt} \|_{2}\\\\
&amp;amp;=\| \int^{1}_{0}{ \big( \nabla^{2}f(x+t\Delta x_{nt})-\nabla^{2} f(x) \big) \Delta x_{nt} dt } \|_{2}\\\\
&amp;amp; \leq \frac{M}{2}\|\Delta x_{nt} \|^{2}_{2}\\\\
&amp;amp; = \frac{M}{2}\|\nabla^{2}f(x)^{-1}\nabla f(x)\|^{2}_{2}\\\\
&amp;amp; \leq \frac{M}{2m^{2}}\|\nabla f(x)\|^{2}_{2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;To summarize: when \(\eta = \min \{1, 3(1-2\alpha)\}\frac{m^{2}}{M}\) and \(\|\nabla f(x^{(k)}) \|_{2}&amp;lt;\eta\), Newton’s method no longer needs updates in backtracking line search and converges quadratically.&lt;/p&gt;

&lt;h2 id=&quot;estimating-total-complexity&quot;&gt;Estimating total complexity&lt;/h2&gt;
&lt;p&gt;Now we can estimate the bound on the complexity of the entire process, in other words, the number of iterations required to go from the initial value to the optimal value.
First, in the damped Newton phase above, \(f\) decreases by at least \(\gamma\) at each iteration, so the total number of damped Newton steps cannot exceed the value of the following expression.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\frac{f(x^{(0)})-p^{\star}}{\gamma}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The bound on the number of iterations in the pure Newton phase can also be calculated. Set \(f(x)-p^{\star}\leq \epsilon\) and \(\epsilon_{0} = \frac{2m^{3}}{M^{2}}\) in the formula above and solve for the number of iterations to obtain the following.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;\epsilon = \epsilon_{0} (\frac{1}{2})^{2^{k-k_{0}+1}}\\\\
&amp;amp;\Leftrightarrow &amp;amp;\frac{\epsilon_{0}}{\epsilon} = 2^{2^{k-k_{0}+1}}\\\\
&amp;amp;\Leftrightarrow &amp;amp;k-k_{0}+1 = \log_{2}\log_{2}(\frac{\epsilon_{0}}{\epsilon})
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore, the number of iterations in the pure Newton phase is bounded by \(\log \log(\frac{\epsilon_{0}}{\epsilon})\).&lt;/p&gt;

&lt;p&gt;Adding these two results, we obtain an upper bound on the number of iterations required to reach a solution of the desired precision with Newton’s method.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\frac{f(x^{(0)})-p^{\star}}{\gamma} + \log_2 \log_2 (\frac{\epsilon_{0}}{\epsilon}).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Compared with the change in the required precision \(\epsilon\), the second term on the right side changes very little, so in practice it is treated as a constant when estimating. It is generally known that 6 iterations give a precision of \(\epsilon \approx 5\cdot 10^{-20}\epsilon_{0}\).&lt;/p&gt;

&lt;p&gt;In general, the number of iterations required to minimize the objective function \(f\) is&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\frac{f(x^{(0)})-p^{\star}}{\gamma} + 6.
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>14-04 Backtracking line search</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_04_backtracking_line_search/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_04_backtracking_line_search</id>
   <content type="html">&lt;p&gt;Pure Newton’s method always takes a full step \(t = 1\)—which is brilliant inside the quadratic basin, yet reckless when far from the solution where the local quadratic bowl is a poor match for the true function. &lt;strong&gt;Backtracking line search&lt;/strong&gt; gives Newton a smart throttle: always &lt;em&gt;try&lt;/em&gt; the full unit step \(t = 1\) first, and only shrink \(t \leftarrow \beta t\) if the actual function drop falls short of a fraction \(\alpha\) of the predicted linear decrease.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-globalizing-newton-with-backtracking&quot;&gt;Key ideas: Globalizing Newton with Backtracking&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The Armijo Sufficient-Decrease Test:&lt;/strong&gt; Starting at \(t = 1\), accept \(t\) once \(f(x + tv) \le f(x) + \alpha t \nabla f(x)^T v = f(x) - \alpha t \lambda(x)^2\), with typical parameters \(\alpha \in (0.01, 0.3)\) and \(\beta \in (0.1, 0.8)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Why Always Start at \(t = 1\):&lt;/strong&gt; Near the optimum, the full Newton step \(t = 1\) automatically passes the backtracking test (for any \(\alpha &amp;lt; 1/2\)), so damped Newton transitions seamlessly into pure quadratic convergence with zero wasted evaluations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Domain Safety for Barriers:&lt;/strong&gt; When \(\operatorname{dom}(f) \subsetneq \mathbb{R}^n\) (as in log-barrier methods), backtracking first shrinks \(t\) until \(x + tv \in \operatorname{dom}(f)\) before checking the Armijo inequality.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Cheap Per-Step Cost:&lt;/strong&gt; Each backtracking trial only evaluates the scalar objective \(f(x + tv)\) (no Hessian or linear solve), costing \(O(n)\) compared to \(O(n^3)\) for the Newton direction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-executing-one-damped-newton-step-by-hand&quot;&gt;Worked example: Executing One Damped Newton Step by Hand&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = e^{x} + e^{-2x}\) starting from \(x = 2\), with backtracking parameters \(\alpha = 0.25\) and \(\beta = 0.5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(f\), \(f&apos;\), \(f&apos;&apos;\), and Newton step \(v\) at \(x = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(2) = e^2 + e^{-4} \approx 7.3891 + 0.0183 = 7.4074\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;(2) = e^2 - 2e^{-4} \approx 7.3891 - 0.0366 = 7.3525\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;(2) = e^2 + 4e^{-4} \approx 7.3891 + 0.0733 = 7.4624\).&lt;/li&gt;
      &lt;li&gt;Newton direction: \(v = -\frac{f&apos;(2)}{f&apos;&apos;(2)} \approx -\frac{7.3525}{7.4624} = -0.9853\).&lt;/li&gt;
      &lt;li&gt;Directional derivative: \(f&apos;(2)v = -\lambda(2)^2 \approx -(7.3525)(0.9853) = -7.244\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test \(t = 1\) (target RHS: \(f(2) + 0.25(1)(-7.244) = 7.4074 - 1.8110 = 5.5964\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Candidate point: \(x + v = 2 - 0.9853 = 1.0147\).&lt;/li&gt;
      &lt;li&gt;Objective value: \(f(1.0147) = e^{1.0147} + e^{-2.0294} \approx 2.7585 + 0.1314 = 2.8899 \le 5.5964\)!&lt;/li&gt;
      &lt;li&gt;Full step \(t = 1\) is accepted immediately on the first check, slashing \(f\) from \(7.41\) to \(2.89\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;What if we started at \(x = -2\) instead?&lt;/strong&gt; At \(x = -2\), \(f(-2) \approx 54.73\), \(v \approx +0.499\), and \(f(-2 + 0.499) \approx 20.37\); if a harsh non-quadratic spike caused \(f(x+v) &amp;gt; f(x) + \alpha f&apos;(x)v\), backtracking would test \(t = 0.5, 0.25, \dots\) until sufficient decrease holds.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;So far, we have examined pure Newton’s method. However, this method does not guarantee convergence, so we use backtracking line search to ensure convergence in the damped Newton’s method.&lt;/p&gt;

&lt;h2 id=&quot;damped-newtons-method&quot;&gt;Damped Newton’s method&lt;/h2&gt;
&lt;p&gt;The pure Newton’s method iteratively applies the following update (here \(t=1\)):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{+} = x -t(\nabla^{2}f(x))^{-1}\nabla f(x).
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Damped Newton’s method uses backtracking line search. If the function value at the updated position is greater than the quadratic approximation, we shrink the step size \(t\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{with parameters }0&amp;lt;\alpha \leq \frac{1}{2}, 0&amp;lt;\beta&amp;lt;1, \\
&amp;amp;\text{while } f(x+tv)&amp;gt;f(x)+\alpha t \nabla f(x)^{T}v\\
&amp;amp;\text{shrink }t=\beta t
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(v=-(\nabla^{2}f(x))^{-1}\nabla f(x)\) and \(\nabla f(x)^{T}v = -\lambda^{2}(x)\).&lt;/p&gt;

&lt;h2 id=&quot;example-logistic-regression&quot;&gt;Example: logistic regression&lt;/h2&gt;
&lt;p&gt;As an example, for logistic regression with n = 500, p = 100, we compare the convergence rate of gradient descent and Newton’s method with backtracking line search.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter14/2.jpeg&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Logistic regression [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Newton’s method shows a much faster convergence rate than gradient descent. From the next chapter, we will examine this convergence rate.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-03 Newton decrement</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_03_newton_decrement/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_03_newton_decrement</id>
   <content type="html">&lt;p&gt;In gradient descent, people often stop when \(\|\nabla f(x)\|_2 \le \epsilon\). That stopping rule has a fatal flaw: if you rescale your units by \(1000\), \(\|\nabla f(x)\|_2\) changes by \(1000\) even though you haven’t moved an inch closer to \(x^\star\)! The &lt;strong&gt;Newton decrement&lt;/strong&gt; \(\lambda(x) = (\nabla f(x)^T (\nabla^2 f(x))^{-1} \nabla f(x))^{1/2}\) fixes this completely: it measures the suboptimality gap in the function’s own curvature metric, making it dimensionless and affine invariant.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-faces-of-the-newton-decrement&quot;&gt;Key ideas: Four Faces of the Newton Decrement&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Quadratic Suboptimality Estimate:&lt;/strong&gt; The drop achieved by minimizing the local quadratic model equals exactly \(\frac{1}{2}\lambda(x)^2\), making \(\frac{1}{2}\lambda(x)^2 \le \epsilon\) Newton’s natural stopping criterion.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Hessian-Norm Step Length:&lt;/strong&gt; Because \(\Delta x_{\text{nt}} = -H^{-1}\nabla f(x)\), we have \(\lambda(x) = (\Delta x_{\text{nt}}^T H \Delta x_{\text{nt}})^{1/2} = \|\Delta x_{\text{nt}}\|_H\)—the Mahalanobis length of the Newton step.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Directional Derivative Link:&lt;/strong&gt; Along the Newton direction, \(\nabla f(x)^T \Delta x_{\text{nt}} = -\lambda(x)^2 \le 0\), which enters directly into the Armijo backtracking condition \(f(x + t\Delta x_{\text{nt}}) \le f(x) - \alpha t \lambda(x)^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Affine Invariance:&lt;/strong&gt; Under \(g(y) = f(Ay)\), the factors \(A\) and \(A^T\) cancel inside \(\lambda_g(y)\), guaranteeing \(\lambda_g(y) = \lambda_f(Ay)\) regardless of coordinate scaling.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-lambdax-and-checking-its-exact-suboptimality-bound&quot;&gt;Worked example: Computing \(\lambda(x)\) and Checking Its Exact Suboptimality Bound&lt;/h3&gt;

&lt;p&gt;Let \(f(x_1, x_2) = 2x_1^2 + x_1 x_2 + x_2^2 - 5x_1 - 3x_2\) at \(x = (0, 0)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute gradient and Hessian at \(x = (0,0)^T\):&lt;/strong&gt;
\(\nabla f(0,0) = \begin{bmatrix} -5 \\ -3 \end{bmatrix}, \qquad H = \nabla^2 f(x) = \begin{bmatrix} 4 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Invert \(H\) and find the Newton step \(\Delta x_{\text{nt}}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\det(H) = 8 - 1 = 7 \implies H^{-1} = \frac{1}{7}\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 4 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;\(\Delta x_{\text{nt}} = -H^{-1}\nabla f(0,0) = -\frac{1}{7}\begin{bmatrix} 2(-5) - (-3) \\ -(-5) + 4(-3) \end{bmatrix} = -\frac{1}{7}\begin{bmatrix} -7 \\ -7 \end{bmatrix} = \begin{bmatrix} 1 \\ 1 \end{bmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(\lambda(x)^2\) in two ways:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Via directional derivative: \(\lambda(0,0)^2 = -\nabla f(0,0)^T \Delta x_{\text{nt}} = -((-5)(1) + (-3)(1)) = 8\), so \(\lambda(0,0) = \sqrt{8} \approx 2.828\).&lt;/li&gt;
      &lt;li&gt;Via Hessian norm: \(\Delta x_{\text{nt}}^T H \Delta x_{\text{nt}} = \begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 4 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}\begin{bmatrix} 1 \\ 1 \end{bmatrix} = 5 + 3 = 8\). Exact match!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the suboptimality gap:&lt;/strong&gt; Since \(f\) is quadratic, \(x^\star = (1,1)^T\) with \(f(1,1) = 2 + 1 + 1 - 5 - 3 = -4\), and \(f(0,0) - f(1,1) = 0 - (-4) = 4 = \frac{1}{2}\lambda(0,0)^2\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In this chapter, we define the Newton decrement and examine its meaning.&lt;/p&gt;

&lt;p&gt;For the optimization problem below, the Newton decrement at \(x\) is defined as \(\lambda(x)\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\min_{x} \quad f(x),\&lt;br /&gt;
\end{align}
\begin{align}
\lambda(x) = (\nabla f(x)^{T}(\nabla^{2}f(x))^{-1}\nabla f(x))^{1/2}.
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;characteristics-of-newton-decrement&quot;&gt;Characteristics of Newton decrement&lt;/h2&gt;
&lt;p&gt;First, the Newton decrement is related to the difference between the function \(f(x)\) and the minimum of its quadratic approximation. Calculating this difference gives:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x)-&amp;amp;\min_{y} \big( f(x)+\nabla f(x)^{T}(y-x)+\frac{1}{2}(y-x)^{T}\nabla^{2}f(x)(y-x)\big),\\\\
f(x)-&amp;amp;\bigg( f(x) + \nabla f(x)^{T}\big( -(\nabla^{2} f(x) )^{-1} \nabla f(x)\big) + \frac{1}{2}\big( -(\nabla^{2}f(x))^{-1} \nabla f(x) \big)^{T} \nabla ^{2}f(x) \big( -(\nabla^{2}f(x))^{-1}\nabla f(x) \big) \bigg) \\\\ 
&amp;amp;= \frac{1}{2}\nabla f(x)^{T}(\nabla^{2} f(x) )^{-1}\nabla f(x) = \frac{1}{2}\lambda(x)^{2}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Thus, \(\frac{1}{2}\lambda^{2}(x)\) can be considered an approximate bound for the suboptimality gap \(f(x)-f^{\star}\).&lt;/p&gt;

&lt;p&gt;Second, the Newton direction in Newton’s method for each iteration is \(v = -(\nabla^{2}f(x))^{-1}\nabla f(x)\), and the Newton decrement is the length of the Newton step in the norm defined by the Hessian \(\nabla^{2}f(x)\).&lt;/p&gt;

&lt;p&gt;Alternatively, this can be viewed as a type of Mahalanobis distance [&lt;a href=&quot;https://en.wikipedia.org/wiki/Mahalanobis_distance&quot;&gt;Wikipedia&lt;/a&gt;], where the new step \(y\) is the observation, the current position \(x\) is the mean, and the Hessian of \(f\) at \(x\) plays the role of the inverse covariance (precision) matrix. The Mahalanobis distance measures the distance from a point to the mean after scaling by the standard deviation in each direction.&lt;/p&gt;

&lt;p&gt;If we consider the definition of Mahalanobis distance as the distance between a point and the mean of a distribution divided by the standard deviation in that direction, the Newton decrement represents the distance of the new step from the current position, with the Hessian playing the role of the inverse covariance matrix.&lt;/p&gt;

&lt;p&gt;Third, the Newton decrement can be expressed in terms of the increment and the Hessian. Starting from the step update in Newton’s method, we have:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{+} &amp;amp;= x-\big(\nabla^{2} f(x) \big)^{-1} \nabla f(x) &amp;amp;\ 
\end{align}
\begin{align}
\Delta x_{nt} &amp;amp;= -\big(\nabla^{2} f(x) \big)^{-1} \nabla f(x) &amp;amp;&lt;br /&gt;
\end{align}
\begin{align}
\nabla f(x)^{T} \Delta x_{nt} &amp;amp;= -\lambda (x)^{2}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Utilizing these relations, the Newton decrement can also be expressed as:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\lambda(x) = (\Delta x_{nt}^{T}\nabla^{2} f(x) \Delta x_{nt})^{1/2}.
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finally, like the Newton step, the Newton decrement is also affine invariant. In other words, for any nonsingular matrix, if the function \(g(y) = f(Ay)\) is defined, then at \(x = Ay\), it holds that \(\lambda_{g(y)} = \lambda_{f(x)}\).&lt;/p&gt;

&lt;h3 id=&quot;the-newton-decrement-in-about-3-minutes&quot;&gt;The Newton decrement in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/newton-decrement_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;½λ² as the drop of the quadratic model, compared with f − f* on eˣ − 2x and on the log-sum-exp function, then λ versus ‖∇f‖ as a stopping rule under a change of variables.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-02 Interpretation & Properties</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_02_interpretation_and_properties/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_02_interpretation_and_properties</id>
   <content type="html">&lt;p&gt;Why has a 300-year-old root-finding algorithm remained the gold standard of numerical optimization in the 21st century? Before diving into full convergence proofs, we step back to see the three conceptual pillars that make Newton’s method unique: its equivalence to finding a root of \(\nabla f(x) = 0\), its complete immunity to linear coordinate rescaling (affine invariance), and its explosive local convergence rate.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-core-structural-properties-of-newtons-method&quot;&gt;Key ideas: Core Structural Properties of Newton’s Method&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Optimization as Root Finding:&lt;/strong&gt; For unconstrained smooth convex functions, minimizing \(f(x)\) is identical to solving the nonlinear system \(F(x) = \nabla f(x) = 0\), where the Jacobian \(DF(x)\) is the Hessian \(\nabla^2 f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Affine Invariance:&lt;/strong&gt; Changing variables via \(x = Ay\) (for any invertible \(A\)) leaves the Newton trajectory completely unchanged: \(x^{(k)} = A y^{(k)}\) at every iteration \(k\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Local Quadratic Convergence:&lt;/strong&gt; Once \(x^{(k)}\) enters a neighborhood of \(x^\star\) with nonsingular, Lipschitz Hessian, the error shrinks like \(\|x^{(k+1)} - x^\star\| \le K \|x^{(k)} - x^\star\|^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — The Need for Globalization:&lt;/strong&gt; Because pure Newton can overshoot or diverge far from \(x^\star\), these local properties motivate adding backtracking line search in the next sections.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-seeing-root-finding-and-affine-invariance-together&quot;&gt;Worked example: Seeing Root-Finding and Affine Invariance Together&lt;/h3&gt;

&lt;p&gt;Consider minimizing \(f(x) = \frac{1}{2}x^2 - \ln(x)\) on \(x &amp;gt; 0\) (minimum at \(x^\star = 1\)) and its rescaled twin \(g(y) = f(5y) = \frac{25}{2}y^2 - \ln(5y)\) (minimum at \(y^\star = 0.2\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Root-finding view of \(f\):&lt;/strong&gt; Set \(F(x) = f&apos;(x) = x - \frac{1}{x} = 0\) with \(F&apos;(x) = f&apos;&apos;(x) = 1 + \frac{1}{x^2}\).
Starting at \(x^{(0)} = 2\):
\(x^{(1)} = 2 - \frac{2 - 0.5}{1 + 0.25} = 2 - \frac{1.5}{1.25} = 2 - 1.2 = 0.8.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Now run Newton on the rescaled function \(g(y)\) from \(y^{(0)} = \frac{x^{(0)}}{5} = 0.4\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g&apos;(y) = 25y - \frac{1}{y} \implies g&apos;(0.4) = 10 - 2.5 = 7.5\).&lt;/li&gt;
      &lt;li&gt;\(g&apos;&apos;(y) = 25 + \frac{1}{y^2} \implies g&apos;&apos;(0.4) = 25 + 6.25 = 31.25\).&lt;/li&gt;
      &lt;li&gt;
\[y^{(1)} = 0.4 - \frac{7.5}{31.25} = 0.4 - 0.24 = 0.16.\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check affine invariance:&lt;/strong&gt; \(5 y^{(1)} = 5(0.16) = 0.8 = x^{(1)}\)! Even though the gradient and curvature blew up by factors of \(5\) and \(25\), Newton’s path is mathematically identical.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In this chapter, before examining the properties of Newton’s method, we learn about applying Newton’s method to root finding problems of objective functions.&lt;/p&gt;

&lt;p&gt;Subsequently, we will examine two important properties of Newton’s method: Affine invariance and Local convergence.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-02-03 Local convergence analyisis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_02_03_local_convergence_analysis/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_02_03_local_convergence_analysis</id>
   <content type="html">&lt;p&gt;Pure Newton’s method is a high-performance race car with no brakes: start close enough to the finish line and it accelerates quadratically—turning an error of \(10^{-2}\) into \(10^{-4}\), then \(10^{-8}\), then \(10^{-16}\) in just three steps. Start too far away on a flat inflection region, however, and it can launch itself straight toward infinity. Local convergence theory draws the exact boundary between those two worlds.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-local-convergence&quot;&gt;Key ideas: Anatomy of Local Convergence&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Nonsingular Jacobian at the Root (\(F&apos;(x^\star)\) invertible):&lt;/strong&gt; Ensures the linear model around \(x^\star\) is well-posed and gives a local contraction radius \(\delta &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Superlinear Convergence from Continuity Alone:&lt;/strong&gt; Using first-order Taylor expansion \(0 = F(x^\star) = F(x^k) + F&apos;(x^k)(x^\star - x^k) + o(\|x^k - x^\star\|)\) immediately yields \(\|x^{k+1} - x^\star\| / \|x^k - x^\star\| \to 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Quadratic Convergence from Lipschitz Jacobian:&lt;/strong&gt; When \(\|F&apos;(x) - F&apos;(y)\| \le M\|x-y\|\), the Taylor remainder shrinks to \(O(\|x^k - x^\star\|^2)\), yielding \(\|x^{k+1} - x^\star\| \le K\|x^k - x^\star\|^2\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 4 — Failure Modes Outside the Local Basin:&lt;/strong&gt; If \(x^{(0)}\) lands where \(F&apos;(x^{(0)}) \approx 0\) or the curvature bends away from the root (such as \(F(x) = \arctan(x)\) at $$&lt;/td&gt;
          &lt;td&gt;x^{(0)}&lt;/td&gt;
          &lt;td&gt;&amp;gt; 1.3917$$), pure Newton oscillates or diverges.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-contrasting-quadratic-convergence-vs-divergence-on-fx--arctanx&quot;&gt;Worked example: Contrasting Quadratic Convergence vs. Divergence on \(F(x) = \arctan(x)\)&lt;/h3&gt;

&lt;p&gt;Consider finding the unique root \(x^\star = 0\) of \(F(x) = \arctan(x)\), where \(F&apos;(x) = \frac{1}{1+x^2}\). The Newton update is
\(x^{(k+1)} = x^{(k)} - (1 + (x^{(k)})^2)\arctan(x^{(k)}).\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Inside the local basin (\(x^{(0)} = 0.5\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = 0.5 - (1.25)\arctan(0.5) \approx 0.5 - 1.25(0.46365) = -0.07956\).&lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = -0.07956 - (1.00633)(-0.07939) \approx +0.000336\).&lt;/li&gt;
      &lt;li&gt;\(x^{(3)} \approx -2.5 \times 10^{-11}\)! (Here convergence is even &lt;em&gt;cubic&lt;/em&gt; because \(F&apos;&apos;(0) = 0\)!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Outside the local basin (\(x^{(0)} = 2.0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = 2.0 - (1 + 4)\arctan(2.0) \approx 2.0 - 5(1.10715) = -3.5357\).&lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = -3.5357 - (1 + 12.501)(-1.2951) \approx +13.95\).&lt;/li&gt;
      &lt;li&gt;The iterates explode alternating in sign! This exact failure is why we add backtracking line search in Section 14-04.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
});
&lt;/script&gt;

&lt;p&gt;The second important property of Newton’s method is that convergence is guaranteed near the solution when certain conditions are satisfied. This is called local convergence. Since the pure Newton’s method we have discussed from &lt;a href=&quot;/contents/en/chapter14/14_01_newton_method/&quot;&gt;14-01&lt;/a&gt; does not guarantee convergence, we later devise the damped Newton’s method that ensures convergence by adjusting the step size using the same backtracking line search covered in &lt;a href=&quot;/contents/en/chapter06/06_00_gradient_descent/&quot;&gt;Chapter 6&lt;/a&gt;, and analyze its convergence.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Theorem: Let \(F : \mathbb{R}^{n}\, \rightarrow  \, \mathbb{R}^{n}\) be continuously differentiable, and let \(x^{\star} \in \mathbb{R}^{n}\) be a root of function \(F\), i.e., \(F(x^{\star})=0\).
If \(F^{&apos;}(x^{\star})\) is non-singular, then the following (a) and (b) are satisfied: &lt;br /&gt;
(a) If there exists a positive \(\delta\) (&amp;gt;0) such that \(\| x^{(0)}-x^{\star} \|&amp;lt;\delta\) and Newton’s method is defined, then the following equation (converges superlinearly) is satisfied:
\begin{align}
\lim_{ k \rightarrow \infty } \frac{ || x^{ (k+1) }-x^{ \star } || } { || x^{ (k) }-x^{ \star } || } =0.
\end{align} &lt;br /&gt;
(b) If \(F^{&apos;}\) is Lipschitz continuous near \(x^{\star}\), then there exists a positive K (&amp;gt;0) such that the following equation (quadratic convergence) is satisfied:
\begin{align}
||x^{ (k+1) } - x^{ \star }|| \leq K || x^{ (k) }-x^{ \star }||^{2}.
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;proof-of-a&quot;&gt;Proof of (a)&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;We organize \(F(x^{\star})\) up to 1st order using Taylor expansion. Since 2nd order and higher terms are bounded by a constant multiple of the norm of the 1st order term, we can represent it using little-o notation as follows:
\begin{align}
0=F(x^{\star}) = F(x^{k}) +\nabla F(x^{k})(x^{\star}-x^{k})+o(||x^{k}-x^{\star}||).&lt;br /&gt;
\end{align}
Multiply both sides by \(\nabla F(x^{k})^{-1}\) and organize. Since little-o is treated as a constant term, it can be ignored.
\begin{align}
x^{k}-x^{\star}-\nabla F(x^{k})^{-1} F(x^{k}) = o(||x^{k}-x^{\star}||).
\end{align}
Using Newton’s method \(x^{k+1}=x^{k}-\nabla F(x^{k})^{-1}F(x^{k})\), we can obtain the following result:
\begin{align}
x^{k+1}-x^{\star}=o(||x^{k}-x^{\star}||),
\end{align}
Therefore, when \(x^{k} \neq x^{\star}\), we can prove (a) using the limit-definition of little-o [&lt;a href=&quot;https://en.wikipedia.org/wiki/Big_O_notation&quot;&gt;wikipedia&lt;/a&gt;].&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\lim_{k\rightarrow \infty} \frac{||x^{k+1}-x^{\star}||}{||x^{k}-x^{\star}||} = \lim_{k\rightarrow \infty}\frac{o(||x^{k}-x^{\star}||)}{||x^{k}-x^{\star}||}.
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;proof-of-b&quot;&gt;Proof of (b)&lt;/h2&gt;
&lt;p&gt;The process is identical to proving that the convergence rate in the Damped phase of [&lt;a href=&quot;/contents/en/chapter14/14_05_convergence_analysis/&quot;&gt;14-05&lt;/a&gt;] is quadratic. Therefore, it is omitted.&lt;/p&gt;

&lt;h2 id=&quot;example--divergence-case&quot;&gt;Example : divergence case&lt;/h2&gt;
&lt;p&gt;We briefly examine an example where convergence is not guaranteed with pure Newton’s method.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter14/1_.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] pure Newton&apos;s method applied on root finding : divergence case &lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;a href=&quot;https://slideplayer.com/slide/4998677/&quot;&gt;image-link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown in the figure, depending on the initial point \(x_0\), the solution can diverge.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-02-02 Affine invariance of Newton's method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_02_02_affine_invariance_of_newton_method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_02_02_affine_invariance_of_newton_method</id>
   <content type="html">&lt;p&gt;Imagine measuring house sizes in square meters versus square millimeters in a regression model. If you run gradient descent, switching units stretches one axis by a factor of \(10^6\) and completely ruins your step size and convergence speed. Run Newton’s method, and the trajectory doesn’t budge by a single millimeter—because Newton’s method is &lt;strong&gt;affine invariant&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-coordinate-changes-cannot-fool-newton&quot;&gt;Key ideas: Why Coordinate Changes Cannot Fool Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Chain Rule for Gradient &amp;amp; Hessian:&lt;/strong&gt; Under \(x = Ay\) (\(A\) nonsingular) and \(g(y) = f(Ay)\), the derivatives transform covariantly as \(\nabla g(y) = A^T \nabla f(x)\) and \(\nabla^2 g(y) = A^T \nabla^2 f(x) A\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Exact Cancellation of \(A^T\):&lt;/strong&gt; Inverting the transformed Hessian gives \((A^T \nabla^2 f(x) A)^{-1} = A^{-1} (\nabla^2 f(x))^{-1} (A^T)^{-1}\). Multiplying by \(A^T \nabla f(x)\) cancels \((A^T)^{-1} A^T = I\) cleanly!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Trajectory Identity (\(x^+ = A y^+\)):&lt;/strong&gt; Multiplying \(y^+ = y - A^{-1}(\nabla^2 f(x))^{-1}\nabla f(x)\) on the left by \(A\) recovers \(x^+ = x - (\nabla^2 f(x))^{-1}\nabla f(x)\) identically.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Contrast with Gradient Descent:&lt;/strong&gt; In \(x\)-coordinates, gradient descent on \(g(y)\) maps to \(x^+ = x - t A A^T \nabla f(x)\). Unless \(A\) is orthogonal (\(A A^T = I\)), changing coordinates warps the descent direction!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-comparing-newton-and-gd-under-a-non-orthogonal-change-of-basis&quot;&gt;Worked example: Comparing Newton and GD Under a Non-Orthogonal Change of Basis&lt;/h3&gt;

&lt;p&gt;Let \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + x_2^2)\) (perfectly circular) and apply the shear/scaling transformation \(A = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 1/2 \end{bmatrix}\), so \(x = Ay = (2y_1, \frac{1}{2}y_2)^T\) and \(g(y) = f(Ay) = 2y_1^2 + \frac{1}{8}y_2^2\). Start at \(x^{(0)} = (2, 2)^T\), which corresponds to \(y^{(0)} = A^{-1}x^{(0)} = (1, 4)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent (\(t = 0.2\)) in \(x\)-space vs. \(y\)-space:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;In \(x\)-space: \(\nabla f(2,2) = (2,2)^T \implies x^{(1)} = (2,2)^T - 0.2(2,2)^T = (1.6, 1.6)^T\) (straight toward the origin).&lt;/li&gt;
      &lt;li&gt;In \(y\)-space: $$\nabla g(1,4) = (4y_1, \frac{1}{4}y_2)^T = (4, 1)^T \implies y^{(1)} = (1,4)^T - 0.2(4,1)^T = (0.2, 3.8)^T$.&lt;/li&gt;
      &lt;li&gt;Map \(y^{(1)}\) back to \(x\)-space: \(A y^{(1)} = (0.4, 1.9)^T \ne (1.6, 1.6)^T\)! The direction is completely distorted.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton’s Method in \(x\)-space vs. \(y\)-space:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;In \(x\)-space: \(x^{(1)} = (2,2)^T - I^{-1}(2,2)^T = (0, 0)^T\).&lt;/li&gt;
      &lt;li&gt;In \(y\)-space: \(\nabla^2 g(y) = \operatorname{diag}(4, 1/4)\), so \(y^{(1)} = (1,4)^T - \operatorname{diag}(1/4, 4)(4, 1)^T = (1,4)^T - (1,4)^T = (0,0)^T\).&lt;/li&gt;
      &lt;li&gt;Map back: \(A y^{(1)} = (0,0)^T = x^{(1)}\)! Exact invariance verified.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;One of the important properties of Newton’s method is that it is affine invariant. This means that the direction of the update is independent of affine transformations of the coordinate system. For example, gradient descent is variant to affine transformations, so the convergence speed differs depending on the coordinate space.&lt;/p&gt;

&lt;p&gt;This page derives the affine invariance property.&lt;/p&gt;

&lt;h2 id=&quot;affine-invariance--proof&quot;&gt;Affine invariance : proof&lt;/h2&gt;
&lt;p&gt;Let \(f:\mathbb{R}^{n}\rightarrow \mathbb{R}\) be twice differentiable, and let \(A\in \mathbb{R}^{n\times n}\) be nonsingular. Also, define \(g(y)\) as \(f(Ay)\). \(g(y):=f(Ay)\). This means that some function \(g\) that takes \(y\) as input has the same output as function \(f\) that takes \(Ay\) (affine transformed by \(A\) with respect to \(y\)) as input. To reduce confusion about notation and gradient arguments, we define \(x:=Ay\).&lt;/p&gt;

&lt;p&gt;Using the chain rule to differentiate both sides once and twice, we get the following results:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\nabla g(y) &amp;amp;= A^{T} \nabla f(x)\\\\
\nabla^{2} g(y) &amp;amp;= A^{T}\nabla^{2}f(x)A,
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The Newton step of \(g\) with respect to \(y\) is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
y^{+}  = y-(\nabla^{2}g(y))^{-1}\nabla g(y).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, instead of function \(g\), if we transform and organize it in terms of function \(f\) with respect to \(x\), we can derive the Newton step for \(x\) and \(f\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
y^{+} &amp;amp;= y-(A^{T}\nabla^{2}f(x)A)^{-1}A^{T} \nabla f(x)\\\\
\Leftrightarrow y^{+} &amp;amp;= y-A^{-1}(\nabla^{2}f(x))^{-1}(A^{T})^{-1}A^{T} \nabla f(x)\\\\
\Leftrightarrow Ay^{+} &amp;amp;= Ay-(\nabla^{2}f(x))^{-1}\nabla f(x)\\\\
\Leftrightarrow x^{+} &amp;amp;= x - \nabla^{2}f(x)^{-1}\nabla f(x).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This means that the Newton step is affine invariant, i.e., the updates in coordinate systems transformed by affine transformations represented by non-singular matrices are identical to each other.&lt;/p&gt;

&lt;p&gt;Using the same method to check the affine invariance of gradient descent by deriving the step update, we can obtain the following result:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
y^{+} &amp;amp;= y-t_{k}\cdot \nabla g(y)\\\\
\Leftrightarrow y^{+} &amp;amp;= y-t_{k}\cdot \nabla f(x)A^{T}\\\\
\Leftrightarrow x^{+} &amp;amp;= x - t_{k}\cdot A\nabla f(x)A^{T}. 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In the case of gradient descent, since the Hessian matrix is approximated as \(\frac{1}{t}I\) for updates, we can see that the direction of the update changes for affine transformed coordinates.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-02-01 Root finding</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_02_01_root_finding/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_02_01_root_finding</id>
   <content type="html">&lt;p&gt;Long before modern optimization existed, Isaac Newton and Joseph Raphson wanted to find where a curve crosses zero: \(F(x) = 0\). Their trick was breathtakingly simple—replace the curved function \(F\) by its straight tangent line at \(x\) and walk to where that tangent hits zero. Applying that exact same tangent-line trick to the gradient \(F(x) = \nabla f(x) = 0\) gives Newton’s method for optimization!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-root-finding-to-optimization&quot;&gt;Key ideas: From Root Finding to Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Linearization of \(F(x) = 0\):&lt;/strong&gt; Approximating \(F(y) \approx F(x) + J_F(x)(y - x) = 0\) yields the root-finding update \(x^+ = x - J_F(x)^{-1}F(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Setting \(F = \nabla f\) Recovers Optimization Newton:&lt;/strong&gt; When \(F(x) = \nabla f(x)\), its Jacobian is the symmetric Hessian \(J_F(x) = \nabla^2 f(x)\), turning root-finding into stationary-point finding.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Stationary Points vs. Minima:&lt;/strong&gt; Root-finding does not distinguish between minima, maxima, and saddle points; convexity (\(\nabla^2 f(x) \succ 0\)) is what guarantees the root of \(\nabla f(x) = 0\) is a global minimum.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Nonlinear Systems in Interior-Point Methods:&lt;/strong&gt; Later in Chapters 15–17, primal-dual solvers apply root-finding Newton directly to the nonlinear KKT equations \(F(x, u, v) = 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-a-2d-nonlinear-system-with-root-finding-newton&quot;&gt;Worked example: Solving a 2D Nonlinear System with Root-Finding Newton&lt;/h3&gt;

&lt;p&gt;Find a root of \(F(x_1, x_2) = \begin{bmatrix} x_1^2 + x_2^2 - 5 \\ x_1 - x_2 - 1 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}\) (exact solution in the first quadrant: \(x^\star = (2, 1)^T\)), starting from \(x^{(0)} = (3, 1)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Jacobian matrix \(J_F(x)\):&lt;/strong&gt;
\(J_F(x) = \begin{bmatrix} 2x_1 &amp;amp; 2x_2 \\ 1 &amp;amp; -1 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate \(F\) and \(J_F\) at \(x^{(0)} = (3, 1)^T\):&lt;/strong&gt;
\(F(3, 1) = \begin{bmatrix} 9 + 1 - 5 \\ 3 - 1 - 1 \end{bmatrix} = \begin{bmatrix} 5 \\ 1 \end{bmatrix}, \qquad J_F(3, 1) = \begin{bmatrix} 6 &amp;amp; 2 \\ 1 &amp;amp; -1 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the linear system \(J_F(3,1)\,\Delta x = -F(3,1)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Determinant: \(\det(J_F) = 6(-1) - 2(1) = -8\).&lt;/li&gt;
      &lt;li&gt;Inverse: \(J_F^{-1} = -\frac{1}{8}\begin{bmatrix} -1 &amp;amp; -2 \\ -1 &amp;amp; 6 \end{bmatrix} = \frac{1}{8}\begin{bmatrix} 1 &amp;amp; 2 \\ 1 &amp;amp; -6 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;Step: \(\Delta x = -\frac{1}{8}\begin{bmatrix} 1 &amp;amp; 2 \\ 1 &amp;amp; -6 \end{bmatrix}\begin{bmatrix} 5 \\ 1 \end{bmatrix} = -\frac{1}{8}\begin{bmatrix} 7 \\ -1 \end{bmatrix} = \begin{bmatrix} -0.875 \\ 0.125 \end{bmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update:&lt;/strong&gt; \(x^{(1)} = (3, 1)^T + (-0.875, 0.125)^T = (2.125, 1.125)^T\). Notice the second residual \(x_1 - x_2 - 1 = 2.125 - 1.125 - 1 = 0\) is satisfied &lt;em&gt;exactly&lt;/em&gt; in one step because it is linear, while the nonlinear error drops from \(5\) to \(2.125^2 + 1.125^2 - 5 = 0.78125\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In this chapter, we apply Newton’s method to the root finding problem. The Newton’s method used in optimization problems has some differences, which are explained here. [&lt;a href=&quot;https://en.wikipedia.org/wiki/Newton%27s_method_in_optimization&quot;&gt;Newton’s method in optimization&lt;/a&gt;][&lt;a href=&quot;https://en.wikipedia.org/wiki/Newton%27s_method&quot;&gt;Newton’s method in root finding&lt;/a&gt;]&lt;/p&gt;

&lt;h2 id=&quot;newtons-method-for-root-finding&quot;&gt;Newton’s method for root finding&lt;/h2&gt;
&lt;p&gt;Suppose we have a vector function \(F:\mathbb{R}^{n}\rightarrow \mathbb{R}^{n}\). The root finding problem is to find \(x\) such that \(F(x) = 0\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
F(x) = 0.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This problem is solved by choosing an initial value \(x^{(0)}\) and applying Newton’s method iteratively:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{choose initial }x^{(0)}\in \mathbb{R}^{n},\\\\
&amp;amp;x^{(k)}=x^{(k-1)}-\nabla F(x^{(k-1)})^{-1}F(x^{(k-1)}), \qquad k=1,2,3,...\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(\nabla F(x^{(k-1)})\) is the Jacobian matrix of \(F\) at \(x^{(k-1)}\). The Newton step \(x^{+}=x-\nabla F(x)^{-1}F(x)\) can be derived using the linear approximation of \(F\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
F(y)\approx F(x) + F^{&apos;}(x)(y-x) = 0\\\\
y = x^{+}=x-F^{&apos;}(x)^{-1}F(x).
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;newtons-method-for-optimization-problem&quot;&gt;Newton’s method for optimization problem&lt;/h2&gt;
&lt;p&gt;Suppose we apply Newton’s method to an optimization problem formulated as:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} F(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This is equivalent to applying Newton’s method to the root finding problem for the gradient \(\nabla{F(x)}=0\) of the objective function \(F(x)\).&lt;/p&gt;

&lt;p&gt;In summary, unlike the problem of finding the root of a given function’s derivative (\(\nabla F=0\)) using Newton’s method in optimization problems, the root finding problem requires finding the root of the function value itself (\(F=0\)) using Newton’s method. This results in a difference of one order in the derivative term in the update formula for \(x\) in Newton’s method for each problem.&lt;/p&gt;

&lt;h2 id=&quot;root-finding-example&quot;&gt;Root finding example&lt;/h2&gt;
&lt;p&gt;Consider a function \(F:\mathbb{R}\rightarrow\mathbb{R}\) defined as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
F(x)=x^{2}-2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Starting with an initial guess of \(x^{(0)}=1\), we apply pure Newton’s method, yielding the following results:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter14/table1.jpeg&quot; alt=&quot;&quot; width=&quot;90%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Newton&apos;s method applied on example[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;As the iteration count \(k\) increases, we can see that the value of \(x\) approaches the root \(\sqrt 2\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>14-01 Newton's method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_01_newton_method/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_01_newton_method</id>
   <content type="html">&lt;p&gt;When gradient descent minimizes an ill-conditioned quadratic \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + 100 x_2^2)\), it must shrink the step size to \(t &amp;lt; \frac{2}{100}\) just to avoid exploding along \(x_2\)—forcing agonizingly tiny steps along \(x_1\). Pure Newton’s method refuses to guess a single isotropic curvature \(\frac{1}{t}I\): it computes the exact Hessian \(\nabla^2 f(x)\) and lands on the exact minimizer of &lt;em&gt;any&lt;/em&gt; convex quadratic in &lt;strong&gt;one&lt;/strong&gt; step.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-first-order-vs-second-order-updates&quot;&gt;Key ideas: First-Order vs. Second-Order Updates&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Isotropic vs. Exact Curvature:&lt;/strong&gt; Gradient descent implicitly replaces the true Hessian with \(\frac{1}{t}I\) (treating every direction as equally curved), whereas Newton’s method uses the exact \(\nabla^2 f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — The Pure Newton Update:&lt;/strong&gt; Solving \(\nabla^2 f(x^{(k-1)})\,\Delta x = -\nabla f(x^{(k-1)})\) produces \(x^{(k)} = x^{(k-1)} - (\nabla^2 f(x^{(k-1)}))^{-1}\nabla f(x^{(k-1)})\) with unit step size \(t = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Positive Definiteness Ensures Descent:&lt;/strong&gt; When \(f\) is strictly convex (\(\nabla^2 f(x) \succ 0\)), the directional derivative \(\nabla f(x)^T \Delta x_{\text{nt}} = -\nabla f(x)^T (\nabla^2 f(x))^{-1}\nabla f(x) &amp;lt; 0\) guarantees a strict descent direction.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Never Invert Explicitly in Code:&lt;/strong&gt; Mathematically we write \((\nabla^2 f)^{-1}\nabla f\), but numerically we solve the linear system \(\nabla^2 f(x)\,\Delta x = -\nabla f(x)\) via Cholesky factorization for speed and stability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-step-convergence-on-an-ill-conditioned-quadratic&quot;&gt;Worked example: One-Step Convergence on an Ill-Conditioned Quadratic&lt;/h3&gt;

&lt;p&gt;Consider \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + 100 x_2^2) - x_1 - 100 x_2\) starting from \(x^{(0)} = (0, 0)^T\). (True minimum is \(x^\star = (1, 1)^T\).)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute gradient and Hessian at \(x^{(0)} = (0,0)^T\):&lt;/strong&gt;
\(\nabla f(x) = \begin{bmatrix} x_1 - 1 \\ 100 x_2 - 100 \end{bmatrix} \implies \nabla f(0,0) = \begin{bmatrix} -1 \\ -100 \end{bmatrix}, \qquad \nabla^2 f(x) = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 100 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;One step of Gradient Descent (best safe step \(t = \frac{1}{100} = 0.01\)):&lt;/strong&gt;
\(x^{(1)}_{\text{GD}} = \begin{bmatrix} 0 \\ 0 \end{bmatrix} - 0.01 \begin{bmatrix} -1 \\ -100 \end{bmatrix} = \begin{bmatrix} 0.01 \\ 1.00 \end{bmatrix}.\)
Coordinate \(x_2\) hits \(1\), but \(x_1\) barely moves \(1\%\) of the way!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;One step of Pure Newton’s Method:&lt;/strong&gt;
\(x^{(1)}_{\text{NT}} = \begin{bmatrix} 0 \\ 0 \end{bmatrix} - \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1/100 \end{bmatrix}\begin{bmatrix} -1 \\ -100 \end{bmatrix} = \begin{bmatrix} 1 \\ 1 \end{bmatrix} = x^\star.\)
Newton’s method solves the problem to machine precision in a single iteration.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;The gradient descent methods we have discussed are called &lt;strong&gt;first-order methods&lt;/strong&gt; because the solutions are based on the first derivative of the function. Newton’s method is a &lt;strong&gt;second-order method&lt;/strong&gt;, meaning the solution requires computing the second derivative.&lt;/p&gt;

&lt;p&gt;Let us consider an optimization problem for a function \(f\) that is unconstrained, twice differentiable, convex, and has dom(\(f\)) = \(\mathbb{R}^{n}\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min_{x} f(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In &lt;a href=&quot;/contents/en/chapter06/06_00_gradient_descent/&quot;&gt;Gradient descent&lt;/a&gt;, we performed the following process for this function \(f\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Perform second-order Taylor approximation&lt;/li&gt;
  &lt;li&gt;Assume the Hessian matrix corresponding to the second derivative term as \(I/t\), i.e., the identity matrix divided by t (step size)&lt;/li&gt;
  &lt;li&gt;Perform quadratic approximation to proceed with the update step&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The detailed process is explained in the gradient descent update step on the next page. The update step formula at each iteration is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{choose initial } x^{(0)} \in \mathbb{R}^{n},\\\\
&amp;amp;x^{(k)} = x^{(k-1)} - t_{k} \cdot \nabla f(x^{(k-1)}), \qquad k = 1,2,3,...
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Newton’s method (pure Newton’s method) actually computes the second derivative term that was assumed as \(\frac{1}{t}I\) in gradient descent, performs quadratic approximation, and proceeds with the update step. This process is also explained in the Newton’s method update step on the next page. The update step formula at each iteration is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{choose initial } x^{(0)} \in \mathbb{R}^{n},\\\\
&amp;amp;x^{(k)} = x^{(k-1)} - \Big(\nabla^{2}f(x^{(k-1)})\Big)^{-1} \nabla f(x^{(k-1)}), \qquad k = 1,2,3,...
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>14-01-02 Does Newton's Method Move Perpendicular to the Level Curves?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_01_02_newton_perpendicular_analysis/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_01_02_newton_perpendicular_analysis</id>
   <content type="html">&lt;p&gt;Every calculus student learns that \(-\nabla f(x)\) points strictly perpendicular to the level curve \(f(x) = c\). So it is natural to assume that Newton’s method—being an “upgraded” gradient descent—also crosses level curves at \(90^\circ\). In fact, it almost &lt;strong&gt;never&lt;/strong&gt; does! On elongated elliptical valleys, the perpendicular direction misses the minimum completely, whereas Newton’s method deliberately tilts &lt;em&gt;away&lt;/em&gt; from the normal so it can aim directly at the valley floor.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-level-curve-geometry-of-newton-vs-gradient-descent&quot;&gt;Key ideas: Level-Curve Geometry of Newton vs. Gradient Descent&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Steepest Descent Is Euclidean-Orthogonal:&lt;/strong&gt; In the standard Euclidean inner product, \(-\nabla f(x)\) is orthogonal to the tangent space of the level set \(\{y : f(y) = f(x)\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Newton Is Steepest Descent in the Hessian Metric:&lt;/strong&gt; Defining the local inner product \(\langle u, v \rangle_H = u^T H v\) (where \(H = \nabla^2 f(x)\)), the Newton step \(-H^{-1}\nabla f(x)\) is orthogonal to the level curve &lt;em&gt;in the \(H\)-metric&lt;/em&gt;, not the Euclidean metric.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — When Does Newton Move Perpendicularly?:&lt;/strong&gt; The angle between \(-\nabla f(x)\) and \(-H^{-1}\nabla f(x)\) is \(0^\circ\) if and only if \(\nabla f(x)\) is an eigenvector of \(\nabla^2 f(x)\) (which happens everywhere only for isotropic \(H = cI\), or along principal axes of an ellipse).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Descent Guarantee Despite Large Angles:&lt;/strong&gt; Even when the Euclidean angle between \(\Delta x_{\text{nt}}\) and \(-\nabla f(x)\) approaches \(89^\circ\) on extreme canyons, \(\nabla f(x)^T \Delta x_{\text{nt}} = -\nabla f(x)^T H^{-1}\nabla f(x) &amp;lt; 0\) guarantees the angle is strictly acute (\(&amp;lt; 90^\circ\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-measuring-the-exact-angle-between-newton-and-the-level-curve-normal&quot;&gt;Worked example: Measuring the Exact Angle Between Newton and the Level-Curve Normal&lt;/h3&gt;

&lt;p&gt;Consider the elliptical bowl \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + 9x_2^2)\) at \(x = (3, 1)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the steepest-descent direction (perpendicular to the level curve):&lt;/strong&gt;
\(d_{\text{GD}} = -\nabla f(3, 1) = -\begin{bmatrix} 3 \\ 9 \end{bmatrix} = \begin{bmatrix} -3 \\ -9 \end{bmatrix}, \qquad \|d_{\text{GD}}\|_2 = \sqrt{9 + 81} = \sqrt{90} \approx 9.487.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Newton direction:&lt;/strong&gt; With \(H = \operatorname{diag}(1, 9)\),
\(d_{\text{NT}} = -H^{-1}\nabla f(3, 1) = -\begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1/9 \end{bmatrix}\begin{bmatrix} 3 \\ 9 \end{bmatrix} = \begin{bmatrix} -3 \\ -1 \end{bmatrix}, \qquad \|d_{\text{NT}}\|_2 = \sqrt{10} \approx 3.162.\)
Notice \(x + d_{\text{NT}} = (0, 0)^T\) hits the exact minimum!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Euclidean angle \(\theta\) between \(d_{\text{GD}}\) and \(d_{\text{NT}}\):&lt;/strong&gt;
\(\cos\theta = \frac{d_{\text{GD}}^T d_{\text{NT}}}{\|d_{\text{GD}}\|_2 \|d_{\text{NT}}\|_2} = \frac{(-3)(-3) + (-9)(-1)}{\sqrt{90}\cdot\sqrt{10}} = \frac{9 + 9}{30} = \frac{18}{30} = 0.6.\)
Therefore \(\theta = \arccos(0.6) \approx 53.13^\circ\)! Newton tilts \(53.13^\circ\) away from the perpendicular normal so it can shoot straight to the origin.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;,
    tex2jax: {
        inlineMath: [[&apos;$&apos;, &apos;$&apos;], [&apos;\\(&apos;, &apos;\\)&apos;]],
        displayMath: [[&apos;$$&apos;, &apos;$$&apos;], [&apos;\\[&apos;, &apos;\\]&apos;]]
    }
});
&lt;/script&gt;

&lt;style&gt;
.interactive-container {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    align-items: center;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-weight: bold;
    font-size: 0.9em;
    color: #495057;
}

.control-group input[type=&quot;range&quot;] {
    width: 150px;
}

.control-group input[type=&quot;number&quot;] {
    width: 80px;
    padding: 4px;
    border: 1px solid #ced4da;
    border-radius: 4px;
}

button {
    background: #007bff;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}

button:hover {
    background: #0056b3;
}

button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

#canvas {
    border: 1px solid #dee2e6;
    border-radius: 4px;
    display: block;
    margin: 0 auto;
}

.info-panel {
    background: #e9ecef;
    padding: 15px;
    border-radius: 4px;
    margin-top: 15px;
    font-family: monospace;
    font-size: 0.85em;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
    font-size: 0.9em;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.legend-color {
    width: 20px;
    height: 3px;
    border-radius: 2px;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

.comparison-table th,
.comparison-table td {
    border: 1px solid #dee2e6;
    padding: 12px;
    text-align: left;
}

.comparison-table th {
    background: #f8f9fa;
    font-weight: bold;
}

.math-explanation {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    padding: 15px;
    margin: 15px 0;
}

.key-insight {
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    border-radius: 4px;
    padding: 15px;
    margin: 15px 0;
}
&lt;/style&gt;

&lt;p&gt;In this lesson, we explore an important question in optimization: &lt;strong&gt;Does Newton’s method move perpendicular to the level curves?&lt;/strong&gt; This question helps us understand more deeply the difference between Newton’s method and gradient descent.&lt;/p&gt;

&lt;h2 id=&quot;1-basic-intuition&quot;&gt;1. Basic Intuition&lt;/h2&gt;

&lt;div class=&quot;key-insight&quot;&gt;
&lt;strong&gt;Short answer:&lt;/strong&gt; &lt;strong&gt;NO&lt;/strong&gt;, Newton&apos;s method generally does NOT move perpendicular to the level curves, unlike gradient descent.
&lt;/div&gt;

&lt;h3 id=&quot;comparison-with-gradient-descent&quot;&gt;Comparison with Gradient Descent&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent&lt;/strong&gt;: Always moves in the direction \(-\nabla f\), perpendicular to the level curves&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton’s Method&lt;/strong&gt;: Uses second-order information (the Hessian) to “adjust” the direction of movement, which is no longer perpendicular in the original space&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-mathematical-explanation&quot;&gt;2. Mathematical Explanation&lt;/h2&gt;

&lt;h3 id=&quot;gradient-descent&quot;&gt;Gradient Descent&lt;/h3&gt;
&lt;p&gt;The direction of movement in gradient descent:
\(\mathbf{d}_{GD} = -\nabla f(\mathbf{x})\)&lt;/p&gt;

&lt;p&gt;This direction is always perpendicular to the level curves because the gradient is the normal vector of the level curves.&lt;/p&gt;

&lt;h3 id=&quot;newtons-method&quot;&gt;Newton’s Method&lt;/h3&gt;
&lt;p&gt;The direction of movement in Newton’s method:
\(\mathbf{d}_{Newton} = -[\nabla^2 f(\mathbf{x})]^{-1} \nabla f(\mathbf{x})\)&lt;/p&gt;

&lt;div class=&quot;math-explanation&quot;&gt;
&lt;strong&gt;Explanation:&lt;/strong&gt; The Hessian $$\nabla^2 f$$ &quot;transforms&quot; the space, so that the direction of movement is no longer perpendicular to the level curves in the original coordinates. Newton optimizes along the &quot;steepest direction&quot; in the space transformed by the Hessian.
&lt;/div&gt;

&lt;h3 id=&quot;when-is-newton-perpendicular&quot;&gt;When Is Newton Perpendicular?&lt;/h3&gt;
&lt;p&gt;When the Hessian is a multiple of the identity matrix, \(\nabla^2 f = cI\) (with \(c\) a constant), Newton coincides with GD (with step size \(1/c\)) and moves perpendicular to the level curves. More generally, Newton is perpendicular only at points where \(\nabla f\) is an eigenvector of the Hessian (for example, along the coordinate axes when the Hessian is a diagonal matrix).&lt;/p&gt;

&lt;h2 id=&quot;3-interactive-illustration&quot;&gt;3. Interactive Illustration&lt;/h2&gt;

&lt;div class=&quot;interactive-container&quot;&gt;
    &lt;h4&gt;Comparing the Newton and Gradient Descent Trajectories&lt;/h4&gt;
    
    &lt;div class=&quot;controls&quot;&gt;
        &lt;div class=&quot;control-group&quot;&gt;
            &lt;label for=&quot;a-param&quot;&gt;Parameter a (curvature along x):&lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;a-param&quot; min=&quot;1&quot; max=&quot;20&quot; value=&quot;10&quot; step=&quot;1&quot; /&gt;
            &lt;input type=&quot;number&quot; id=&quot;a-value&quot; min=&quot;1&quot; max=&quot;20&quot; value=&quot;10&quot; step=&quot;1&quot; /&gt;
        &lt;/div&gt;
        
        &lt;div class=&quot;control-group&quot;&gt;
            &lt;label for=&quot;b-param&quot;&gt;Parameter b (curvature along y):&lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;b-param&quot; min=&quot;1&quot; max=&quot;20&quot; value=&quot;1&quot; step=&quot;1&quot; /&gt;
            &lt;input type=&quot;number&quot; id=&quot;b-value&quot; min=&quot;1&quot; max=&quot;20&quot; value=&quot;1&quot; step=&quot;1&quot; /&gt;
        &lt;/div&gt;
        
        &lt;div class=&quot;control-group&quot;&gt;
            &lt;label for=&quot;start-x&quot;&gt;Starting point x:&lt;/label&gt;
            &lt;input type=&quot;number&quot; id=&quot;start-x&quot; min=&quot;-3&quot; max=&quot;3&quot; value=&quot;2&quot; step=&quot;0.1&quot; /&gt;
        &lt;/div&gt;
        
        &lt;div class=&quot;control-group&quot;&gt;
            &lt;label for=&quot;start-y&quot;&gt;Starting point y:&lt;/label&gt;
            &lt;input type=&quot;number&quot; id=&quot;start-y&quot; min=&quot;-3&quot; max=&quot;3&quot; value=&quot;1.5&quot; step=&quot;0.1&quot; /&gt;
        &lt;/div&gt;
        
        &lt;div class=&quot;control-group&quot;&gt;
            &lt;label for=&quot;learning-rate&quot;&gt;Learning Rate (GD):&lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;learning-rate&quot; min=&quot;0.01&quot; max=&quot;0.5&quot; value=&quot;0.1&quot; step=&quot;0.01&quot; /&gt;
            &lt;input type=&quot;number&quot; id=&quot;lr-value&quot; min=&quot;0.01&quot; max=&quot;0.5&quot; value=&quot;0.1&quot; step=&quot;0.01&quot; /&gt;
        &lt;/div&gt;
        
        &lt;button id=&quot;start-btn&quot;&gt;Start&lt;/button&gt;
        &lt;button id=&quot;step-btn&quot;&gt;Step&lt;/button&gt;
        &lt;button id=&quot;reset-btn&quot;&gt;Reset&lt;/button&gt;
        &lt;button id=&quot;toggle-contour&quot;&gt;Show/Hide level curves&lt;/button&gt;
    &lt;/div&gt;
    
    &lt;canvas id=&quot;canvas&quot; width=&quot;600&quot; height=&quot;500&quot;&gt;&lt;/canvas&gt;
    
    &lt;div class=&quot;legend&quot;&gt;
        &lt;div class=&quot;legend-item&quot;&gt;
            &lt;div class=&quot;legend-color&quot; style=&quot;background: #ff4444;&quot;&gt;&lt;/div&gt;
            &lt;span&gt;Gradient Descent (perpendicular to the level curves)&lt;/span&gt;
        &lt;/div&gt;
        &lt;div class=&quot;legend-item&quot;&gt;
            &lt;div class=&quot;legend-color&quot; style=&quot;background: #4444ff;&quot;&gt;&lt;/div&gt;
            &lt;span&gt;Newton&apos;s Method (cuts across the level curves)&lt;/span&gt;
        &lt;/div&gt;
        &lt;div class=&quot;legend-item&quot;&gt;
            &lt;div class=&quot;legend-color&quot; style=&quot;background: #888888;&quot;&gt;&lt;/div&gt;
            &lt;span&gt;Level curves&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div id=&quot;info-panel&quot; class=&quot;info-panel&quot;&gt;
        Objective function: f(x,y) = (ax² + by²)/2&lt;br /&gt;
        Press &quot;Start&quot; to compare the trajectories of the two methods
    &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;4-detailed-analysis&quot;&gt;4. Detailed Analysis&lt;/h2&gt;

&lt;table class=&quot;comparison-table&quot;&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Property&lt;/th&gt;
            &lt;th&gt;Gradient Descent&lt;/th&gt;
            &lt;th&gt;Newton&apos;s Method&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;strong&gt;Direction of movement&lt;/strong&gt;&lt;/td&gt;
            &lt;td&gt;$$-\nabla f$$ (perpendicular to the level curves)&lt;/td&gt;
            &lt;td&gt;$$-H^{-1}\nabla f$$ (not perpendicular)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;strong&gt;Information used&lt;/strong&gt;&lt;/td&gt;
            &lt;td&gt;Gradient only (first order)&lt;/td&gt;
            &lt;td&gt;Gradient + Hessian (second order)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;strong&gt;Convergence rate&lt;/strong&gt;&lt;/td&gt;
            &lt;td&gt;Linear&lt;/td&gt;
            &lt;td&gt;Quadratic (near the optimum)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;strong&gt;Handling ill-conditioning&lt;/strong&gt;&lt;/td&gt;
            &lt;td&gt;Poor (zig-zag)&lt;/td&gt;
            &lt;td&gt;Good (goes straight)&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;strong&gt;Computational cost&lt;/strong&gt;&lt;/td&gt;
            &lt;td&gt;O(n) per step&lt;/td&gt;
            &lt;td&gt;O(n³) per step&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;5-a-concrete-example&quot;&gt;5. A Concrete Example&lt;/h2&gt;

&lt;p&gt;Consider the function \(f(x,y) = x^2 + 10y^2\), whose level curves are flat ellipses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;At the point (1,1):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient&lt;/strong&gt;: \(\nabla f = (2, 20)\) - perpendicular to the ellipse&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hessian&lt;/strong&gt;: \(H = \begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 20 \end{pmatrix}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton direction&lt;/strong&gt;: \(\mathbf{d} = -H^{-1}\nabla f = -\begin{pmatrix} 1/2 &amp;amp; 0 \\ 0 &amp;amp; 1/20 \end{pmatrix} \begin{pmatrix} 2 \\ 20 \end{pmatrix} = (-1, -1)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;key-insight&quot;&gt;
&lt;strong&gt;Observation:&lt;/strong&gt; Gradient descent moves in the direction (-2, -20) (perpendicular), while Newton moves in the direction (-1, -1) (cutting diagonally across the ellipse).
&lt;/div&gt;

&lt;h2 id=&quot;6-why-does-this-matter&quot;&gt;6. Why Does This Matter?&lt;/h2&gt;

&lt;h3 id=&quot;advantages-of-newton&quot;&gt;Advantages of Newton&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Handles ill-conditioning well&lt;/strong&gt;: when the function has different curvature in different directions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Faster convergence&lt;/strong&gt;: especially near the optimum&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine invariance&lt;/strong&gt;: independent of the coordinate system&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;disadvantages&quot;&gt;Disadvantages&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;High computational cost&lt;/strong&gt;: the Hessian must be computed and inverted&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Can be unstable&lt;/strong&gt;: if the Hessian is not positive definite&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Not suitable for large-scale data&lt;/strong&gt;: because of the O(n³) complexity&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;7-applications-in-machine-learning&quot;&gt;7. Applications in Machine Learning&lt;/h2&gt;

&lt;p&gt;In practice, variants of Newton’s method are used:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;L-BFGS&lt;/strong&gt;: approximates the Hessian, avoiding the full computation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gauss-Newton&lt;/strong&gt;: for least-squares problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Levenberg-Marquardt&lt;/strong&gt;: combines the advantages of GD and Newton&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;math-explanation&quot;&gt;
&lt;strong&gt;Conclusion:&lt;/strong&gt; Newton&apos;s method does not move perpendicular to the level curves because it optimizes in the space &quot;transformed&quot; by the Hessian. This allows it to converge faster, at a higher computational cost.
&lt;/div&gt;

&lt;script&gt;
class OptimizationVisualizer {
    constructor() {
        this.canvas = document.getElementById(&apos;canvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        // Parameters
        this.a = 10;
        this.b = 1;
        this.startX = 2;
        this.startY = 1.5;
        this.learningRate = 0.1;
        
        // Visualization settings
        this.scale = 80;
        this.centerX = this.width / 2;
        this.centerY = this.height / 2;
        this.showContour = true;
        
        // Animation state
        this.isRunning = false;
        this.gdPath = [];
        this.newtonPath = [];
        this.currentStep = 0;
        this.maxSteps = 20;
        
        this.setupEventListeners();
        this.reset();
    }
    
    setupEventListeners() {
        // Parameter controls
        const aParam = document.getElementById(&apos;a-param&apos;);
        const aValue = document.getElementById(&apos;a-value&apos;);
        const bParam = document.getElementById(&apos;b-param&apos;);
        const bValue = document.getElementById(&apos;b-value&apos;);
        const lrParam = document.getElementById(&apos;learning-rate&apos;);
        const lrValue = document.getElementById(&apos;lr-value&apos;);
        
        // Sync sliders with number inputs
        aParam.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.a = parseFloat(e.target.value);
            aValue.value = this.a;
            this.reset();
        });
        
        aValue.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.a = parseFloat(e.target.value);
            aParam.value = this.a;
            this.reset();
        });
        
        bParam.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.b = parseFloat(e.target.value);
            bValue.value = this.b;
            this.reset();
        });
        
        bValue.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.b = parseFloat(e.target.value);
            bParam.value = this.b;
            this.reset();
        });
        
        lrParam.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.learningRate = parseFloat(e.target.value);
            lrValue.value = this.learningRate;
        });
        
        lrValue.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.learningRate = parseFloat(e.target.value);
            lrParam.value = this.learningRate;
        });
        
        // Start position controls
        document.getElementById(&apos;start-x&apos;).addEventListener(&apos;input&apos;, (e) =&gt; {
            this.startX = parseFloat(e.target.value);
            this.reset();
        });
        
        document.getElementById(&apos;start-y&apos;).addEventListener(&apos;input&apos;, (e) =&gt; {
            this.startY = parseFloat(e.target.value);
            this.reset();
        });
        
        // Buttons
        document.getElementById(&apos;start-btn&apos;).addEventListener(&apos;click&apos;, () =&gt; this.startAnimation());
        document.getElementById(&apos;step-btn&apos;).addEventListener(&apos;click&apos;, () =&gt; this.stepAnimation());
        document.getElementById(&apos;reset-btn&apos;).addEventListener(&apos;click&apos;, () =&gt; this.reset());
        document.getElementById(&apos;toggle-contour&apos;).addEventListener(&apos;click&apos;, () =&gt; this.toggleContour());
    }
    
    // Objective function: f(x,y) = (ax² + by²)/2
    f(x, y) {
        return (this.a * x * x + this.b * y * y) / 2;
    }
    
    // Gradient: ∇f = (ax, by)
    gradient(x, y) {
        return [this.a * x, this.b * y];
    }
    
    // Hessian: H = [[a, 0], [0, b]]
    hessian(x, y) {
        return [[this.a, 0], [0, this.b]];
    }
    
    // Matrix inverse for 2x2
    inverse2x2(matrix) {
        const [[a, b], [c, d]] = matrix;
        const det = a * d - b * c;
        if (Math.abs(det) &lt; 1e-10) return null;
        return [[d/det, -b/det], [-c/det, a/det]];
    }
    
    // Matrix-vector multiplication
    matVecMul(matrix, vector) {
        const [x, y] = vector;
        return [
            matrix[0][0] * x + matrix[0][1] * y,
            matrix[1][0] * x + matrix[1][1] * y
        ];
    }
    
    // Gradient descent step
    gradientDescentStep(x, y) {
        const [gx, gy] = this.gradient(x, y);
        return [
            x - this.learningRate * gx,
            y - this.learningRate * gy
        ];
    }
    
    // Newton method step
    newtonStep(x, y) {
        const [gx, gy] = this.gradient(x, y);
        const H = this.hessian(x, y);
        const Hinv = this.inverse2x2(H);
        
        if (!Hinv) return [x, y]; // Fallback if Hessian is singular
        
        const [dx, dy] = this.matVecMul(Hinv, [gx, gy]);
        return [x - dx, y - dy];
    }
    
    // Convert world coordinates to canvas coordinates
    worldToCanvas(x, y) {
        return [
            this.centerX + x * this.scale,
            this.centerY - y * this.scale
        ];
    }
    
    // Convert canvas coordinates to world coordinates
    canvasToWorld(canvasX, canvasY) {
        return [
            (canvasX - this.centerX) / this.scale,
            -(canvasY - this.centerY) / this.scale
        ];
    }
    
    drawContourLines() {
        if (!this.showContour) return;
        
        this.ctx.strokeStyle = &apos;#888888&apos;;
        this.ctx.lineWidth = 1;
        
        const levels = [0.5, 1, 2, 4, 8, 16];
        
        for (const level of levels) {
            this.ctx.beginPath();
            
            // Draw ellipse for level set f(x,y) = level
            // (ax² + by²)/2 = level =&gt; ax² + by² = 2*level
            // x²/(2*level/a) + y²/(2*level/b) = 1
            const radiusX = Math.sqrt(2 * level / this.a) * this.scale;
            const radiusY = Math.sqrt(2 * level / this.b) * this.scale;
            
            this.ctx.ellipse(this.centerX, this.centerY, radiusX, radiusY, 0, 0, 2 * Math.PI);
            this.ctx.stroke();
        }
    }
    
    drawPath(path, color, label) {
        if (path.length &lt; 2) return;
        
        this.ctx.strokeStyle = color;
        this.ctx.lineWidth = 3;
        this.ctx.beginPath();
        
        const [startCanvasX, startCanvasY] = this.worldToCanvas(path[0][0], path[0][1]);
        this.ctx.moveTo(startCanvasX, startCanvasY);
        
        for (let i = 1; i &lt; path.length; i++) {
            const [canvasX, canvasY] = this.worldToCanvas(path[i][0], path[i][1]);
            this.ctx.lineTo(canvasX, canvasY);
        }
        this.ctx.stroke();
        
        // Draw points
        this.ctx.fillStyle = color;
        for (let i = 0; i &lt; path.length; i++) {
            const [canvasX, canvasY] = this.worldToCanvas(path[i][0], path[i][1]);
            this.ctx.beginPath();
            this.ctx.arc(canvasX, canvasY, i === 0 ? 6 : 4, 0, 2 * Math.PI);
            this.ctx.fill();
        }
        
        // Draw arrows for direction
        for (let i = 0; i &lt; path.length - 1; i++) {
            const [x1, y1] = this.worldToCanvas(path[i][0], path[i][1]);
            const [x2, y2] = this.worldToCanvas(path[i+1][0], path[i+1][1]);
            this.drawArrow(x1, y1, x2, y2, color);
        }
    }
    
    drawArrow(x1, y1, x2, y2, color) {
        const dx = x2 - x1;
        const dy = y2 - y1;
        const length = Math.sqrt(dx * dx + dy * dy);
        
        if (length &lt; 5) return;
        
        const angle = Math.atan2(dy, dx);
        const arrowLength = 10;
        const arrowAngle = Math.PI / 6;
        
        this.ctx.strokeStyle = color;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        
        // Arrow head
        const headX = x2 - arrowLength * Math.cos(angle - arrowAngle);
        const headY = y2 - arrowLength * Math.sin(angle - arrowAngle);
        this.ctx.moveTo(x2, y2);
        this.ctx.lineTo(headX, headY);
        
        const headX2 = x2 - arrowLength * Math.cos(angle + arrowAngle);
        const headY2 = y2 - arrowLength * Math.sin(angle + arrowAngle);
        this.ctx.moveTo(x2, y2);
        this.ctx.lineTo(headX2, headY2);
        
        this.ctx.stroke();
    }
    
    drawAxes() {
        this.ctx.strokeStyle = &apos;#cccccc&apos;;
        this.ctx.lineWidth = 1;
        
        // X axis
        this.ctx.beginPath();
        this.ctx.moveTo(0, this.centerY);
        this.ctx.lineTo(this.width, this.centerY);
        this.ctx.stroke();
        
        // Y axis
        this.ctx.beginPath();
        this.ctx.moveTo(this.centerX, 0);
        this.ctx.lineTo(this.centerX, this.height);
        this.ctx.stroke();
        
        // Origin
        this.ctx.fillStyle = &apos;#666666&apos;;
        this.ctx.beginPath();
        this.ctx.arc(this.centerX, this.centerY, 3, 0, 2 * Math.PI);
        this.ctx.fill();
    }
    
    draw() {
        // Clear canvas
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        // Draw axes
        this.drawAxes();
        
        // Draw contour lines
        this.drawContourLines();
        
        // Draw paths
        this.drawPath(this.gdPath, &apos;#ff4444&apos;, &apos;GD&apos;);
        this.drawPath(this.newtonPath, &apos;#4444ff&apos;, &apos;Newton&apos;);
        
        // Update info panel
        this.updateInfoPanel();
    }
    
    updateInfoPanel() {
        const panel = document.getElementById(&apos;info-panel&apos;);
        const gdCurrent = this.gdPath.length &gt; 0 ? this.gdPath[this.gdPath.length - 1] : [this.startX, this.startY];
        const newtonCurrent = this.newtonPath.length &gt; 0 ? this.newtonPath[this.newtonPath.length - 1] : [this.startX, this.startY];
        
        const gdValue = this.f(gdCurrent[0], gdCurrent[1]);
        const newtonValue = this.f(newtonCurrent[0], newtonCurrent[1]);
        
        panel.innerHTML = `
            Objective function: f(x,y) = (${this.a}x² + ${this.b}y²)/2&lt;br&gt;
            Current step: ${this.currentStep}&lt;br&gt;
            GD - Position: (${gdCurrent[0].toFixed(3)}, ${gdCurrent[1].toFixed(3)}), f = ${gdValue.toFixed(4)}&lt;br&gt;
            Newton - Position: (${newtonCurrent[0].toFixed(3)}, ${newtonCurrent[1].toFixed(3)}), f = ${newtonValue.toFixed(4)}
        `;
    }
    
    reset() {
        this.isRunning = false;
        this.gdPath = [[this.startX, this.startY]];
        this.newtonPath = [[this.startX, this.startY]];
        this.currentStep = 0;
        
        document.getElementById(&apos;start-btn&apos;).disabled = false;
        document.getElementById(&apos;step-btn&apos;).disabled = false;
        
        this.draw();
    }
    
    stepAnimation() {
        if (this.currentStep &gt;= this.maxSteps) return;
        
        // Gradient descent step
        const gdCurrent = this.gdPath[this.gdPath.length - 1];
        const gdNext = this.gradientDescentStep(gdCurrent[0], gdCurrent[1]);
        this.gdPath.push(gdNext);
        
        // Newton step
        const newtonCurrent = this.newtonPath[this.newtonPath.length - 1];
        const newtonNext = this.newtonStep(newtonCurrent[0], newtonCurrent[1]);
        this.newtonPath.push(newtonNext);
        
        this.currentStep++;
        this.draw();
        
        // Check convergence
        const gdConverged = Math.abs(gdNext[0]) &lt; 0.01 &amp;&amp; Math.abs(gdNext[1]) &lt; 0.01;
        const newtonConverged = Math.abs(newtonNext[0]) &lt; 0.01 &amp;&amp; Math.abs(newtonNext[1]) &lt; 0.01;
        
        if (gdConverged &amp;&amp; newtonConverged || this.currentStep &gt;= this.maxSteps) {
            this.isRunning = false;
            document.getElementById(&apos;start-btn&apos;).disabled = false;
            document.getElementById(&apos;step-btn&apos;).disabled = true;
        }
    }
    
    startAnimation() {
        if (this.isRunning) return;
        
        this.isRunning = true;
        document.getElementById(&apos;start-btn&apos;).disabled = true;
        document.getElementById(&apos;step-btn&apos;).disabled = true;
        
        const animate = () =&gt; {
            if (!this.isRunning) return;
            
            this.stepAnimation();
            
            if (this.isRunning &amp;&amp; this.currentStep &lt; this.maxSteps) {
                setTimeout(animate, 500);
            } else {
                this.isRunning = false;
                document.getElementById(&apos;start-btn&apos;).disabled = false;
                document.getElementById(&apos;step-btn&apos;).disabled = false;
            }
        };
        
        animate();
    }
    
    toggleContour() {
        this.showContour = !this.showContour;
        this.draw();
    }
}

// Initialize when page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, () =&gt; {
    new OptimizationVisualizer();
});
&lt;/script&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004). &lt;em&gt;Convex optimization&lt;/em&gt;. Cambridge University Press.&lt;/li&gt;
  &lt;li&gt;Nocedal, J., &amp;amp; Wright, S. J. (2006). &lt;em&gt;Numerical optimization&lt;/em&gt; (2nd ed.). Springer.&lt;/li&gt;
  &lt;li&gt;Nesterov, Y. (2003). &lt;em&gt;Introductory lectures on convex optimization: A basic course&lt;/em&gt;. Springer.&lt;/li&gt;
  &lt;li&gt;Bertsekas, D. P. (1999). &lt;em&gt;Nonlinear programming&lt;/em&gt; (2nd ed.). Athena Scientific.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>14-01-01 Newton's method interpretation</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_01_01_newton_method_interpretation/"/>
   <updated>2021-03-26T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter14/14_01_01_newton_method_interpretation</id>
   <content type="html">&lt;p&gt;Why does the formula \(x^+ = x - (\nabla^2 f(x))^{-1}\nabla f(x)\) look like a matrix-scaled gradient? Because it isn’t a heuristic rescaling at all—it is the exact minimizer of the best quadratic bowl tangent to \(f\) at your current position \(x\). Seeing both Gradient Descent and Newton’s method as “minimize a local quadratic surrogate” unifies first-order and second-order optimization into one crystal-clear geometric picture.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-surrogate-minimization-geometry&quot;&gt;Key ideas: Surrogate Minimization Geometry&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Second-Order Taylor Surrogate:&lt;/strong&gt; Near \(x\), \(f_{\text{approx}}(y) = f(x) + \nabla f(x)^T(y-x) + \frac{1}{2}(y-x)^T \nabla^2 f(x)(y-x)\) matches \(f\)’s value, slope, and curvature at \(x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Exact Minimization of the Surrogate:&lt;/strong&gt; Setting \(\nabla_y f_{\text{approx}}(y) = \nabla f(x) + \nabla^2 f(x)(y-x) = 0\) immediately yields the Newton update \(y = x - (\nabla^2 f(x))^{-1}\nabla f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Gradient Descent as a Spherical Surrogate:&lt;/strong&gt; Replacing \(\nabla^2 f(x)\) with \(\frac{1}{t}I\) approximates the terrain by a perfectly round paraboloid, whose minimizer is \(y = x - t\nabla f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Curvature-Matching Advantage:&lt;/strong&gt; When \(f\)’s level sets are elongated ellipses rather than circles, the true quadratic surrogate captures the eccentricity and aims straight at the center of the ellipse.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-building-and-minimizing-the-local-quadratic-surrogate&quot;&gt;Worked example: Building and Minimizing the Local Quadratic Surrogate&lt;/h3&gt;

&lt;p&gt;Let \(f(x) = x^4 - 4x + 5\) at \(x = 2\). We construct both the Newton surrogate and a Gradient Descent surrogate (with \(t = \frac{1}{50}\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate derivatives at \(x = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(2) = 16 - 8 + 5 = 13\),&lt;/li&gt;
      &lt;li&gt;\(f&apos;(2) = 4(2)^3 - 4 = 28\),&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;(2) = 12(2)^2 = 48\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write the exact local quadratic surrogate:&lt;/strong&gt;
\(f_{\text{approx}}(y) = 13 + 28(y - 2) + \frac{1}{2}(48)(y - 2)^2 = 13 + 28(y - 2) + 24(y - 2)^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize \(f_{\text{approx}}(y)\):&lt;/strong&gt; Set \(f&apos;_{\text{approx}}(y) = 28 + 48(y - 2) = 0$:\)y_{\text{NT}} = 2 - \frac{28}{48} = 2 - \frac{7}{12} = \frac{17}{12} \approx 1.4167.\((Note: the true minimum of\)f\(is at\)x^\star = 1\(, so one Newton step cuts the distance to\)x^\star\(by more than half, from\)1.0\(to\)0.4167$$.)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with the GD surrogate (\(\frac{1}{t} = 50\)):&lt;/strong&gt;
\(y_{\text{GD}} = 2 - \frac{28}{50} = 1.44.\)
Here \(\frac{1}{t} = 50\) happened to be close to \(f&apos;&apos;(2) = 48\); had we picked a conservative \(t = 0.005\) (\(\frac{1}{t} = 200\)), GD would only reach \(2 - 0.14 = 1.86\).&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
});
&lt;/script&gt;

&lt;p&gt;This page examines how the update step discussed earlier is derived from the quadratic approximation of the original function \(f\). We also compare it with the gradient descent update step covered in &lt;a href=&quot;/contents/en/chapter06/06_00_gradient_descent/&quot;&gt;Chapter 6&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;newtons-method-update-step&quot;&gt;Newton’s method update step&lt;/h2&gt;
&lt;p&gt;The second-order Taylor approximation (quadratic approximation) of function \(f\) is as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(y)	\approx f(x) + \nabla f(x)^{T}(y-x) +\frac{1}{2}(y-x)^{T}\nabla^{2}f(x)(y-x),\\\\
f_{approx}(y)	= f(x) + \nabla f(x)^{T}(y-x) +\frac{1}{2}(y-x)^{T}\nabla^{2}f(x)(y-x).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(y\) is the next step’s \(x\) value, which is \(x^{+}\). We also define the quadratic approximation as \(f_{approx}\).&lt;/p&gt;

&lt;p&gt;We want to find the input \(y\) that minimizes this \(f_{approx}\), i.e., the quadratic approximation. It is a quadratic in \(y\) with Hessian \(\nabla^2 f(x)\), so it is convex when \(\nabla^2 f(x) \succeq 0\). If \(\nabla^2 f(x) \succ 0\), it is strictly convex and has a unique minimizer: the \(y\) that makes its gradient zero. (If the Hessian is only positive semidefinite, the model may have no minimizer or infinitely many.) This result becomes the step update formula in Newton’s method. Remember that the differentiation in the equation below is with respect to y.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\nabla f_{approx}(y)	&amp;amp;= \nabla f(x) +\frac{1}{2} \Big((\nabla^{2} f(x))^{T}(y-x)+(y-x)^{T}\nabla^{2}f(x)\Big)\\\\
&amp;amp;=\nabla f(x) +\nabla^{2} f(x)(y-x)\\\\
&amp;amp; = 0,\\\\
\Leftrightarrow y &amp;amp;= x-(\nabla^{2}f(x))^{-1}\nabla f(x).
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;gradient-descent-update-step&quot;&gt;Gradient descent update step&lt;/h2&gt;
&lt;p&gt;In gradient descent, we use the second-order Taylor approximation terms of function \(f\), but for the second-order term, we assume it as the identity matrix divided by \(t\), rather than the actual second derivative result.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(y)	\approx f(x) + \nabla f(x)^{T}(y-x) +\frac{1}{2t}\|{y-x}\|_{2}^{2},\\\\
f_{approx}(y)	= f(x) + \nabla f(x)^{T}(y-x) +\frac{1}{2t}\|{y-x}\|_{2}^{2}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Similar to Newton’s method, we can determine the \(y\) value where the gradient of the above approximation is zero, i.e., \(x^{+}\).&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\nabla f(y) &amp;amp;= \nabla f(x) + \frac{1}{t}(y-x), \\\\
&amp;amp;= 0,\\\\
y &amp;amp;= x-t\nabla f(x).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This result is identical to the step update of gradient descent.&lt;/p&gt;

&lt;p&gt;For detailed information about gradient descent, refer to the &lt;a href=&quot;/contents/en/chapter06/06_00_gradient_descent/&quot;&gt;gradient descent chapter&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;example&quot;&gt;Example&lt;/h2&gt;
&lt;p&gt;As an example, for the function \(f = (10x_{1}^{2}+x_{2}^{2})/2+5log(1+e^{-x_{1}-x_{2}})\), we assume taking steps of approximately equal length. That is, we set the step size in gradient descent to match the update magnitude of Newton’s method at each iteration, and compare the convergence directions of gradient descent (black) and Newton’s method (blue) according to their steps.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter14/gd.jpeg&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Comparison between gradient descent(black) and Newton&apos;s method(blue)[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;As can be seen in Fig 1, gradient descent assumes the second derivative term as a constant multiplied by the identity matrix when calculating the gradient, so it converges perpendicularly to the tangent direction of the contour lines, and shows slower convergence speed compared to Newton’s method. The remaining chapters will cover the properties, characteristics, convergence, examples, etc. of Newton’s method.&lt;/p&gt;

&lt;h3 id=&quot;newtons-method-1d-2d-and-when-it-fails-video&quot;&gt;Newton’s method: 1D, 2D, and when it fails (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/newton-parabola_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Each step minimizes the quadratic model \(f(x_k)+f&apos;(x_k)(x-x_k)+\tfrac12 f&apos;&apos;(x_k)(x-x_k)^2\), so \(x_{k+1}=x_k-f&apos;(x_k)/f&apos;&apos;(x_k)\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>07-10 Bài Tập Thực Hành - Tối ưu Subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_10_Practical_Exercises_Subgradient_Optimization/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_10_Practical_Exercises_Subgradient_Optimization</id>
   <content type="html">&lt;p&gt;Khi lý thuyết Subgradient chuyển hóa thành thuật toán lặp \(x^{(k+1)} = x^{(k)} - t_k g^{(k)}\) (với \(g^{(k)} \in \partial f(x^{(k)})\)), ta bước vào một lãnh địa có luật chơi khác hẳn Gradient Descent ở Chương 06: không thể dùng Backtracking Line Search (vì \(-g^{(k)}\) chưa chắc là hướng giảm!), không thể dùng bước cố định để hội tụ chính xác về \(f^\star\), và tốc độ hội tụ chậm hơn đáng kể — chỉ đạt \(O(1/\sqrt{k})\) thay vì \(O(1/k)\)!&lt;/p&gt;

&lt;p&gt;Bộ bài tập thực hành này giúp bạn trực tiếp chạm tay vào cả hai mặt của Chương 07: tính chuẩn xác subgradient của các hàm không trơn phổ biến (chuẩn \(\ell_1, \ell_2, \ell_\infty\), hàm cực đại, hinge loss) và tự tay phân tích, cài đặt &lt;strong&gt;Phương pháp Subgradient&lt;/strong&gt; với các lịch bước giảm dần chuẩn xác!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-quy-tắc-thực-chiến-cho-phương-pháp-subgradient&quot;&gt;Kiến thức cần nhớ: Bốn quy tắc thực chiến cho Phương pháp Subgradient&lt;/h2&gt;

&lt;p&gt;Khi giải các bài tập thực hành tính subgradient và chạy thuật toán Subgradient Method, hãy nắm chắc bốn nguyên tắc sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Tính chất Lipschitz của hàm (không phải gradient!) $$&lt;/td&gt;
          &lt;td&gt;f(x) - f(y)&lt;/td&gt;
          &lt;td&gt;\le G|x - y|_2\(:** Điều kiện tương đương là mọi subgradient đều bị chặn chuẩn\)|g|_2 \le G \; \forall g \in \partial f(x)\(. (Ví dụ với\)f(x) = |x|_1\(trên\)\mathbb{R}^n\(,\)|g|_2 \le \sqrt{n} \implies G = \sqrt{n}$$.)&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theo dõi \(f_{\text{best}}^{(k)} = \min_{i=0,\dots,k} f(x^{(i)})\):&lt;/strong&gt; Vì phương pháp Subgradient &lt;strong&gt;không giảm đơn điệu&lt;/strong&gt; (\(f(x^{(k+1)})\) có thể lớn hơn \(f(x^{(k)})\)), ta luôn phải lưu kỷ lục tốt nhất trong suốt quá trình chạy!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn kích thước bước \(t_k\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Bước cố định \(t_k = t\):&lt;/strong&gt; Chỉ hội tụ vào lân cận \(f^\star + \frac{G^2 t}{2}\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước giảm dần không cộng dồn bình phương&lt;/strong&gt; (\(\sum t_k = \infty,\; \sum t_k^2 &amp;lt; \infty\), ví dụ \(t_k = \frac{c}{k}\) hoặc \(\frac{c}{\sqrt{k}}\)): Đảm bảo \(f_{\text{best}}^{(k)} \to f^\star\), với tốc độ tối ưu \(O\left(\frac{GR}{\sqrt{k}}\right)\) khi chọn \(t_k = \frac{R}{G\sqrt{k}}\) (trong đó \(R = \|x^{(0)} - x^\star\|_2\))!&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước Polyak (khi biết trước \(f^\star\)):&lt;/strong&gt; \(t_k = \frac{f(x^{(k)}) - f^\star}{\|g^{(k)}\|_2^2}\) — cực kỳ hiệu quả cho bài toán tìm điểm giao các tập lồi (nơi ta biết trước \(f^\star = 0\))!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ phức tạp \(O(1/\epsilon^2)\):&lt;/strong&gt; Để đạt độ chính xác \(\epsilon\), phương pháp Subgradient cần cỡ \(\frac{G^2 R^2}{\epsilon^2}\) vòng lặp (ví dụ \(\epsilon = 10^{-3}\) cần tới ~\(10^6\) bước — đó là động lực để sang các chương sau ta học Phương pháp Proximal!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-3-bước-phương-pháp-subgradient-với-bước-polyak-và-bước-1sqrtk&quot;&gt;Giải thích: Chạy tay 3 bước Phương pháp Subgradient với bước Polyak và bước \(1/\sqrt{k}\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét hàm không trơn $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 2&lt;/td&gt;
      &lt;td&gt;\((\)G = 1,\; x^\star = 2,\; f^\star = 0\(), xuất phát từ\)x^{(0)} = 0\((\)R = 2$$):&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Dùng lịch bước chuẩn \(t_k = \frac{R}{G\sqrt{k+1}} = \frac{2}{\sqrt{k+1}}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Bước \(k = 0\):&lt;/strong&gt; \(x^{(0)} = 0 \implies g^{(0)} = -1\), \(t_0 = 2\).
\(x^{(1)} = 0 - 2(-1) = 2 \implies f(2) = 0\) (may mắn chạm đúng đích!).&lt;/li&gt;
      &lt;li&gt;Thử xuất phát từ \(x^{(0)} = -1\) (\(R = 3\), dùng lịch \(t_k = \frac{1}{\sqrt{k+1}}\)):
        &lt;ul&gt;
          &lt;li&gt;\(k = 0\): \(x^{(0)} = -1,\; g^{(0)} = -1,\; t_0 = 1 \implies x^{(1)} = 0,\; f = 2\).&lt;/li&gt;
          &lt;li&gt;\(k = 1\): \(x^{(1)} = 0,\; g^{(1)} = -1,\; t_1 \approx 0.707 \implies x^{(2)} \approx 0.707,\; f \approx 1.293\).&lt;/li&gt;
          &lt;li&gt;\(k = 2\): \(x^{(2)} \approx 0.707,\; g^{(2)} = -1,\; t_2 \approx 0.577 \implies x^{(3)} \approx 1.284,\; f \approx 0.716\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng bước Polyak \(t_k = \frac{f(x^{(k)}) - f^\star}{\|g^{(k)}\|_2^2}\) từ \(x^{(0)} = -1\) (biết \(f^\star = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(k = 0\): \(f(-1) = 3,\; g^{(0)} = -1 \implies t_0 = \frac{3 - 0}{(-1)^2} = 3\).&lt;/li&gt;
      &lt;li&gt;Cập nhật: \(x^{(1)} = -1 - 3(-1) = 2 \implies f(2) = 0\) — chạm đúng cực tiểu toàn cục sau &lt;strong&gt;đúng 1 bước&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---tối-ưu-subgradient-subgradient-optimization&quot;&gt;Bài Tập Thực Hành - Tối ưu Subgradient (Subgradient Optimization)&lt;/h1&gt;

&lt;p&gt;Các bài tập được tham khảo từ Boyd &amp;amp; Vandenberghe (2004) và Shor (1985).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-i-tính-subgradient&quot;&gt;📝 &lt;strong&gt;Phần I: Tính Subgradient&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-subgradient-của-hàm-không-khả-vi&quot;&gt;&lt;strong&gt;Bài tập 1: Subgradient của hàm không khả vi&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Tính vi phân dưới (tập các subgradient) của các hàm sau tại điểm cho trước:&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;a)&lt;/strong&gt; $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(tại\)x = 0$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;b)&lt;/strong&gt; \(f(x) = \max\{x_1, x_2\}\) tại \(x = (1, 1)^T\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;c)&lt;/strong&gt; \(f(x) = \|x\|_1\) tại \(x = (0, 0)^T\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;d)&lt;/strong&gt; \(f(x) = \max\{x_1 + x_2, 2x_1 - x_2\}\) tại \(x = (1, 0)^T\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) $$f(x) = |x|$$ tại $$x = 0$$:**

**Định nghĩa:** $$g \in \partial f(0)$$ khi và chỉ khi

$$f(y) \geq f(0) + g(y - 0)$$ $$\forall y$$

$$|y| \geq 0 + gy \quad \forall y$$

- Với $$y &amp;gt; 0$$: $$y \geq gy$$ suy ra $$g \leq 1$$.
- Với $$y &amp;lt; 0$$: $$-y \geq gy$$ suy ra $$g \geq -1$$.

Do đó: $$\partial f(0) = [-1, 1]$$.

**Ý nghĩa hình học:** Tập hợp hệ số góc của tất cả các đường thẳng tựa đi qua đồ thị tại $$x = 0$$.

---

**b) $$f(x) = \max\{x_1, x_2\}$$ tại $$x = (1, 1)$$:**

Ta có $$f(1, 1) = 1$$ (cả hai thành phần đều đạt giá trị lớn nhất).

**Tập hoạt động (active set):** $$I = \{1, 2\}$$.

$$\partial f(x) = \text{conv}\{\nabla f_i(x) : i \in I\}$$

$$= \text{conv}\{(1, 0), (0, 1)\}$$

$$= \{(\lambda, 1-\lambda) : 0 \leq \lambda \leq 1\}$$

**Ý nghĩa hình học:** Đoạn thẳng nối hai điểm $$(1, 0)$$ và $$(0, 1)$$.

---

**c) $$f(x) = \|x\|_1 = |x_1| + |x_2|$$ tại $$x = (0, 0)$$:**

$$\partial f(0) = \partial |x_1| \times \partial |x_2|$$

$$= [-1, 1] \times [-1, 1]$$

$$= \{(g_1, g_2) : |g_1| \leq 1, |g_2| \leq 1\}$$

**Ý nghĩa hình học:** Hình vuông $$[-1, 1]^2$$.

---

**d) $$f(x) = \max\{x_1 + x_2, 2x_1 - x_2\}$$ tại $$x = (1, 0)$$:**

$$f_1(1, 0) = 1 + 0 = 1$$

$$f_2(1, 0) = 2 - 0 = 2$$

$$\Rightarrow f(1, 0) = 2$$ (chỉ có $$f_2$$ đạt giá trị lớn nhất).

$$\nabla f_2 = (2, -1)$$

$$\partial f(1, 0) = \{(2, -1)\}$$ (chỉ gồm một phần tử vì chỉ có một hàm thành phần hoạt động).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-ii-phương-pháp-subgradient&quot;&gt;📝 &lt;strong&gt;Phần II: Phương pháp Subgradient&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-2-phân-tích-hội-tụ&quot;&gt;&lt;strong&gt;Bài tập 2: Phân tích hội tụ&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Cho $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 2&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x + 1&lt;/td&gt;
      &lt;td&gt;$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tìm tập điểm cực tiểu \(x^*\).&lt;br /&gt;
b) Với kích thước bước \(\alpha_k = \frac{1}{\sqrt{k}}\), viết công thức lặp xuất phát từ \(x^{(0)} = 5\).&lt;br /&gt;
c) Tính \(x^{(1)}, x^{(2)}, x^{(3)}\).&lt;br /&gt;
d) Ước lượng tốc độ hội tụ.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Tìm $$x^*$$:**

$$f(x) = |x - 2| + |x + 1|$$

**Xét theo từng khoảng:**
- Với $$x &amp;lt; -1$$: $$f(x) = -(x-2) - (x+1) = -2x + 1$$ (hàm giảm).
- Với $$-1 \leq x \leq 2$$: $$f(x) = -(x-2) + (x+1) = 3$$ (hàm hằng).
- Với $$x &amp;gt; 2$$: $$f(x) = (x-2) + (x+1) = 2x - 1$$ (hàm tăng).

Do đó $$f^* = 3$$ và tập điểm cực tiểu là $$x^* \in [-1, 2]$$.

---

**b) Công thức lặp của phương pháp subgradient:**

$$x^{(k+1)} = x^{(k)} - \alpha_k g^{(k)}$$

với $$g^{(k)} \in \partial f(x^{(k)})$$.

---

**c) Tính các bước lặp đầu tiên:**

Tại $$x^{(0)} = 5 &amp;gt; 2$$:

$$\partial f(5) = \{\text{sign}(5-2)\} + \{\text{sign}(5+1)\} = \{1\} + \{1\} = \{2\}$$

$$g^{(0)} = 2$$

$$\alpha_0 = \frac{1}{\sqrt{1}} = 1$$

$$x^{(1)} = 5 - 1 \cdot 2 = 3$$

---

Tại $$x^{(1)} = 3 &amp;gt; 2$$:

$$g^{(1)} = 2$$

$$\alpha_1 = \frac{1}{\sqrt{2}} \approx 0.707$$

$$x^{(2)} = 3 - 0.707 \cdot 2 = 1.586$$

---

Tại $$x^{(2)} = 1.586 \in [-1, 2]$$ (đã nằm trong miền tối ưu):

$$\partial f(1.586) = \{\text{sign}(1.586 - 2) + \text{sign}(1.586 + 1)\} = \{-1 + 1\} = \{0\}$$ (trên khoảng $$(-1, 2)$$, $$f$$ là hàm hằng nên khả vi với đạo hàm bằng 0).

$$g^{(2)} = 0 \Rightarrow x^{(3)} = x^{(2)} = 1.586$$ (thuật toán đã hội tụ đến tập nghiệm tối ưu).

---

**d) Tốc độ hội tụ:**

Với $$\alpha_i = \frac{1}{\sqrt{i}}$$, từ bất đẳng thức cơ bản ta có:

$$f(x_{\text{best}}^{(k)}) - f^* \leq \frac{R^2 + G^2 \sum_{i=1}^k \alpha_i^2}{2\sum_{i=1}^k \alpha_i}$$

$$\sum_{i=1}^k \frac{1}{\sqrt{i}} \approx 2\sqrt{k}$$

$$\sum_{i=1}^k \frac{1}{i} \approx \log k$$

$$\Rightarrow f(x_{\text{best}}^{(k)}) - f^* = O\left(\frac{\log k}{\sqrt{k}}\right)$$

(Nếu chọn kích thước bước cố định theo tổng số bước $$k$$ dạng $$\alpha = \frac{R}{G\sqrt{k}}$$, cận sẽ bỏ được thừa số $$\log k$$ và đạt $$O(1/\sqrt{k})$$.)

Đây là **hội tụ dưới tuyến tính (sublinear)**, chậm hơn so với gradient descent trên hàm trơn.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iii-các-quy-tắc-chọn-kích-thước-bước&quot;&gt;📝 &lt;strong&gt;Phần III: Các quy tắc chọn kích thước bước&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-3-so-sánh-các-chiến-lược-kích-thước-bước&quot;&gt;&lt;strong&gt;Bài tập 3: So sánh các chiến lược kích thước bước&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho \(f(x) = \max\{x_1, x_2, -x_1 - x_2 + 1\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tìm nghiệm tối ưu \(x^*\).&lt;br /&gt;
b) So sánh 3 quy tắc kích thước bước:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Cố định: \(\alpha_k = 0.1\)&lt;/li&gt;
  &lt;li&gt;Giảm dần: \(\alpha_k = \frac{1}{k}\)&lt;/li&gt;
  &lt;li&gt;Tổng bình phương hội tụ: \(\alpha_k = \frac{1}{k^{0.6}}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Tìm nghiệm tối ưu:**

$$f(x) = \max\{x_1, x_2, 1 - x_1 - x_2\}$$

**Các đường giao nhau của ba hàm thành phần:**
- $$x_1 = x_2$$
- $$x_1 = 1 - x_1 - x_2 \iff 2x_1 + x_2 = 1$$
- $$x_2 = 1 - x_1 - x_2 \iff x_1 + 2x_2 = 1$$

Giải hệ $$x_1 = x_2$$ và $$2x_1 + x_2 = 1$$:

$$3x_1 = 1 \Rightarrow x_1 = \frac{1}{3}$$

Suy ra $$x^* = \left(\frac{1}{3}, \frac{1}{3}\right)$$ và $$f^* = \frac{1}{3}$$.

---

**b) So sánh các quy tắc kích thước bước:**

**Xuất phát từ $$x^{(0)} = (1, 1)$$:**

Ta có $$f_1 = 1$$, $$f_2 = 1$$, $$f_3 = -1$$ nên giá trị lớn nhất đạt tại cả $$f_1$$ và $$f_2$$:

$$\partial f(1, 1) = \text{conv}\{(1, 0), (0, 1)\}$$

Chọn trung điểm $$g = (0.5, 0.5)$$.

---

**Kích thước bước cố định $$\alpha_k = 0.1$$:**

$$x^{(1)} = (1, 1) - 0.1(0.5, 0.5) = (0.95, 0.95)$$

$$x^{(2)} = (0.90, 0.90)$$

$$x^{(3)} = (0.85, 0.85)$$

...

**Nhận xét:** Thuật toán hội tụ đến một lân cận của $$x^*$$ (bán kính cỡ $$O(\alpha)$$), nhưng không đạt tới nghiệm chính xác.

---

**Kích thước bước giảm dần $$\alpha_k = \frac{1}{k}$$:**

$$x^{(1)} = (1, 1) - 1 \cdot (0.5, 0.5) = (0.5, 0.5)$$

$$x^{(2)} = (0.5, 0.5) - 0.5 \cdot (0.5, 0.5) = (0.25, 0.25)$$ (với $$g^{(1)} = (0.5, 0.5)$$)

Tại $$(0.25, 0.25)$$, thành phần $$f_3 = 0.5$$ đạt giá trị lớn nhất nên $$g^{(2)} = (-1, -1)$$, suy ra $$x^{(3)} = (0.25, 0.25) + \frac{1}{3}(1, 1) \approx (0.583, 0.583)$$ (điểm lặp dao động quanh $$x^*$$ với biên độ giảm dần).

...

**Nhận xét:** Hội tụ đến $$x^*$$ nhưng rất chậm (cận $$O(1/\log k)$$ vì $$\sum_{i \le k} 1/i \approx \log k$$).

---

**Kích thước bước tổng bình phương hội tụ $$\alpha_k = \frac{1}{k^{0.6}}$$:**

$$\sum \alpha_k = \sum \frac{1}{k^{0.6}} = \infty$$ ✓

$$\sum \alpha_k^2 = \sum \frac{1}{k^{1.2}} &amp;lt; \infty$$ ✓

**Nhận xét:** Hội tụ đến $$x^*$$ với cận $$O(1/k^{0.4})$$ (vì $$\sum_{i \le k} \alpha_i \sim k^{0.4}$$), nhanh hơn quy tắc $$\alpha_k = 1/k$$ nhưng vẫn là tốc độ hội tụ dưới tuyến tính.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iv-kích-thước-bước-polyak&quot;&gt;📝 &lt;strong&gt;Phần IV: Kích thước bước Polyak&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-4-kích-thước-bước-polyak-cho-bài-toán-cực-tiểu-hóa-ell_1&quot;&gt;&lt;strong&gt;Bài tập 4: Kích thước bước Polyak cho bài toán cực tiểu hóa \(\ell_1\)&lt;/strong&gt;&lt;/h3&gt;

\[\min_{x} \|x\|_1 \quad \text{s.t.} \quad Ax = b\]

&lt;p&gt;với \(A = [1, 2, 3]\), \(b = 6\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết hàm Lagrangian.&lt;br /&gt;
b) Tìm hàm đối ngẫu.&lt;br /&gt;
c) Cực đại hóa hàm đối ngẫu bằng phương pháp subgradient với kích thước bước Polyak.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Hàm Lagrangian:**

$$L(x, \nu) = \|x\|_1 + \nu^T(Ax - b)$$

$$= \sum_i (|x_i| + \nu a_i x_i) - \nu b$$

---

**b) Hàm đối ngẫu:**

$$g(\nu) = \inf_x L(x, \nu)$$

$$= \inf_x \sum_i (|x_i| + \nu a_i x_i) - \nu b$$

Cực tiểu hóa độc lập theo từng biến $$x_i$$:

$$\inf_{x_i} (|x_i| + \nu a_i x_i) = \begin{cases}
0 &amp;amp; \text{nếu } |\nu a_i| \leq 1 \\
-\infty &amp;amp; \text{trường hợp khác}
\end{cases}$$

$$g(\nu) = \begin{cases}
-\nu b &amp;amp; \text{nếu } |\nu a_i| \leq 1 \, \forall i \\
-\infty &amp;amp; \text{trường hợp khác}
\end{cases}$$

Với $$A = [1, 2, 3]$$:

$$|\nu| \leq 1, \quad |2\nu| \leq 1, \quad |3\nu| \leq 1$$

$$\Rightarrow |\nu| \leq \frac{1}{3}$$

Do đó $$g(\nu) = -6\nu$$ với $$|\nu| \leq \frac{1}{3}$$.

---

**c) Cực đại hóa bài toán đối ngẫu:**

$$\max_{\nu} \quad -6\nu \quad \text{s.t.} \quad -\frac{1}{3} \leq \nu \leq \frac{1}{3}$$

Ta thấy ngay $$\nu^* = -\frac{1}{3}$$ và $$g^* = 2$$.

**Subgradient của $$g(\nu) = -6\nu$$:** $$s = -6$$ (vì đây là bài toán cực đại hóa hàm lõm $$g$$, ta áp dụng bước tăng subgradient).

**Kích thước bước Polyak** (khi đã biết $$g^* = 2$$):

$$\alpha_k = \frac{g^* - g(\nu^{(k)})}{\|s^{(k)}\|^2}, \qquad \nu^{(k+1)} = \Pi_{[-1/3,\,1/3]}\left(\nu^{(k)} + \alpha_k s^{(k)}\right)$$

Xuất phát từ $$\nu^{(0)} = 0$$ (có $$g(0) = 0$$):

$$\alpha_0 = \frac{2 - 0}{36} = \frac{1}{18}$$

$$\nu^{(1)} = 0 + \frac{1}{18} \cdot (-6) = -\frac{1}{3}$$ ✓ (thuộc miền xác định).

Thuật toán hội tụ chỉ sau 1 bước: $$g(-1/3) = 2 = g^*$$, tương ứng với nghiệm gốc $$x^* = (0, 0, 2)$$ có $$\|x^*\|_1 = 2$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-v-phương-pháp-subgradient-có-chiếu&quot;&gt;📝 &lt;strong&gt;Phần V: Phương pháp Subgradient có chiếu&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-5-subgradient-có-chiếu-cho-bài-toán-tối-ưu-có-ràng-buộc&quot;&gt;&lt;strong&gt;Bài tập 5: Subgradient có chiếu cho bài toán tối ưu có ràng buộc&lt;/strong&gt;&lt;/h3&gt;

\[\min_{x} \|x - c\|_1 \quad \text{s.t.} \quad \|x\|_2 \leq R\]

&lt;p&gt;với \(c = (2, 3)^T\), \(R = 2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết công thức cập nhật của phương pháp subgradient có chiếu.&lt;br /&gt;
b) Thực hiện các bước lặp xuất phát từ \(x^{(0)} = (0, 0)\).&lt;br /&gt;
c) Tìm nghiệm chính xác của bài toán.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Phương pháp subgradient có chiếu:**

$$x^{(k+1)} = \Pi_C\left(x^{(k)} - \alpha_k g^{(k)}\right)$$

với $$C = \{x : \|x\|_2 \leq R\}$$ và $$g^{(k)} \in \partial f(x^{(k)})$$.

**Phép chiếu lên hình cầu $$\ell_2$$:**

$$\Pi_C(y) = \begin{cases}
y &amp;amp; \text{nếu } \|y\| \leq R \\
R \frac{y}{\|y\|} &amp;amp; \text{nếu } \|y\| &amp;gt; R
\end{cases}$$

---

**b) Các bước lặp:**

Tại $$x^{(0)} = (0, 0)$$:

$$\partial f(0, 0) = \partial \|(0, 0) - (2, 3)\|_1 = \partial(|{-2}| + |{-3}|)$$

Subgradient: $$g = \text{sign}(x - c) = (-1, -1)$$.

Chọn $$\alpha_0 = 1$$:

$$\tilde{x}^{(1)} = (0, 0) - 1 \cdot (-1, -1) = (1, 1)$$

Vì $$\|\tilde{x}^{(1)}\| = \sqrt{2} &amp;lt; 2$$ nên điểm nằm trong $$C$$, không cần chiếu:

$$x^{(1)} = (1, 1)$$

---

Ở bước tiếp theo:

$$g^{(1)} = \text{sign}((1, 1) - (2, 3)) = (-1, -1)$$

$$\tilde{x}^{(2)} = (1, 1) + (1, 1) = (2, 2)$$

Vì $$\|\tilde{x}^{(2)}\| = 2\sqrt{2} &amp;gt; 2$$, ta chiếu lên biên của hình cầu $$C$$:

$$x^{(2)} = 2 \cdot \frac{(2, 2)}{2\sqrt{2}} = \frac{2}{\sqrt{2}}(1, 1) = (\sqrt{2}, \sqrt{2})$$

---

**c) Nghiệm chính xác:**

Ta cần cực tiểu hóa $$\|x - c\|_1$$ trên tập $$\|x\|_2 \leq 2$$.

**Nghiệm không ràng buộc:** $$x = c = (2, 3)$$, nhưng $$\|c\|_2 = \sqrt{13} &amp;gt; 2$$ nên không khả thi.

**Nghiệm có ràng buộc:** Vì $$c$$ nằm ngoài hình cầu, nghiệm tối ưu nằm trên biên $$\|x\|_2 = 2$$. (Lưu ý rằng phép chiếu $$c$$ lên hình cầu chỉ tối ưu cho khoảng cách $$\ell_2$$, không tối ưu cho chuẩn $$\ell_1$$.) Trên biên trong miền $$x_1 &amp;lt; 2$$, $$x_2 &amp;lt; 3$$:

$$f(x) = (2 - x_1) + (3 - x_2) = 5 - (x_1 + x_2)$$

Do đó bài toán tương đương với $$\max\; (x_1 + x_2)$$ trên đường tròn $$x_1^2 + x_2^2 = 4$$, đạt cực đại tại $$x_1 = x_2 = \sqrt{2}$$:

$$x^* = (\sqrt{2}, \sqrt{2}) \approx (1.414, 1.414)$$

**Giá trị hàm mục tiêu:** $$f(x^*) = 5 - 2\sqrt{2} \approx 2.172$$ (trong khi điểm chiếu $$\frac{2}{\sqrt{13}}(2,3)$$ cho giá trị $$2.227$$, lớn hơn). Điểm này trùng khớp với kết quả $$x^{(2)}$$ thu được ở câu b.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;so-sánh-gradient-descent-và-phương-pháp-subgradient&quot;&gt;&lt;strong&gt;So sánh Gradient Descent và Phương pháp Subgradient:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tiêu chí&lt;/th&gt;
      &lt;th&gt;Gradient Descent&lt;/th&gt;
      &lt;th&gt;Phương pháp Subgradient&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Phạm vi áp dụng&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hàm trơn \(f\)&lt;/td&gt;
      &lt;td&gt;Hàm lồi không trơn \(f\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tốc độ hội tụ&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tuyến tính (\(O(\rho^k)\), khi lồi mạnh)&lt;/td&gt;
      &lt;td&gt;Dưới tuyến tính (\(O(1/\sqrt{k})\))&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Kích thước bước&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Cố định hoặc tìm kiếm đường thẳng&lt;/td&gt;
      &lt;td&gt;Giảm dần hoặc bước Polyak&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tính giảm đơn điệu&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Luôn giảm (với bước phù hợp)&lt;/td&gt;
      &lt;td&gt;Có thể tăng ở một số bước&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ứng dụng điển hình&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hàm khả vi trơn&lt;/td&gt;
      &lt;td&gt;Phạt \(\ell_1\), hàm max, bài toán có ràng buộc&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;các-quy-tắc-chọn-kích-thước-bước&quot;&gt;&lt;strong&gt;Các quy tắc chọn kích thước bước:&lt;/strong&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước cố định \(\alpha\):&lt;/strong&gt; Hội tụ đến lân cận của nghiệm tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước giảm dần \(\frac{1}{k}\):&lt;/strong&gt; Hội tụ chính xác nhưng rất chậm (cận \(O(1/\log k)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng bình phương hội tụ \(\frac{1}{k^{0.6}}\):&lt;/strong&gt; Hội tụ chính xác với cận \(O(1/k^{0.4})\), nhanh hơn \(\frac{1}{k}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước Polyak:&lt;/strong&gt; Hội tụ nhanh khi biết trước \(f^*\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;khi-nào-nên-dùng-phương-pháp-subgradient&quot;&gt;&lt;strong&gt;Khi nào nên dùng phương pháp Subgradient:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu không khả vi (chứa chuẩn \(\ell_1\), hàm \(\max\)).&lt;/li&gt;
  &lt;li&gt;Cần chi phí tính toán mỗi bước lặp thấp và đơn giản.&lt;/li&gt;
  &lt;li&gt;Có thể chấp nhận tốc độ hội tụ chậm hơn.&lt;/li&gt;
  &lt;li&gt;Xử lý ràng buộc thông qua phép chiếu.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu Tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Section 3.1.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Shor, N. Z.&lt;/strong&gt; (1985). &lt;em&gt;Minimization Methods for Non-Differentiable Functions&lt;/em&gt;. Springer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Polyak, B. T.&lt;/strong&gt; (1987). &lt;em&gt;Introduction to Optimization&lt;/em&gt;. Optimization Software.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>07-09 Bài tập trắc nghiệm - Subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_09_Quiz_Subgradient/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_09_Quiz_Subgradient</id>
   <content type="html">&lt;p&gt;Chuyển từ đạo hàm cổ điển \(\nabla f(x)\) sang tập vi phân dưới \(\partial f(x)\) đòi hỏi một sự dịch chuyển tư duy rất thú vị: thay vì một vector duy nhất, giờ bạn làm việc với cả một tập hợp vector; thay vì hướng âm gradient luôn làm giảm hàm, giờ hướng âm subgradient đôi khi lại làm hàm &lt;strong&gt;tăng tạm thời&lt;/strong&gt;; và quy tắc nhân hằng số đột ngột mất hiệu lực với số âm!&lt;/p&gt;

&lt;p&gt;Bộ bài tập trắc nghiệm này giúp bạn kiểm tra sắc bén mọi định nghĩa, ví dụ mẫu, phép tính vi phân dưới và điều kiện tối ưu của Chương 07 — đảm bảo bạn không bao giờ rơi vào các bẫy trực giác từ giải tích trơn.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-điểm-dễ-nhầm-nhất-khi-làm-trắc-nghiệm-chương-07&quot;&gt;Kiến thức cần nhớ: Bốn điểm dễ nhầm nhất khi làm trắc nghiệm Chương 07&lt;/h2&gt;

&lt;p&gt;Trước khi bắt đầu trả lời các câu hỏi, hãy rà nhanh bốn quy tắc phân biệt sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 1 — Subgradient không nhất thiết là hướng giảm:&lt;/strong&gt; Tại điểm gãy khúc, chọn một \(g \in \partial f(x)\) rồi đi theo hướng \(-g\) có thể làm \(f(x - tg) &amp;gt; f(x)\) với mọi \(t &amp;gt; 0\)! Điều duy nhất được đảm bảo là \(-g\) tạo góc nhọn với hướng đi về nghiệm tối ưu \(x^\star - x\) (tức \(g^T(x - x^\star) \ge f(x) - f(x^\star) &amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 2 — Quy tắc nhân hằng số âm:&lt;/strong&gt; \(\partial(af) = a\partial f\) chỉ đúng với \(a &amp;gt; 0\)! Với \(a &amp;lt; 0\), hàm \(af\) chuyển sang lõm nên không còn áp dụng quy tắc vi phân dưới lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 3 — Cực đại hữu hạn chỉ lấy các nhánh TÍCH CỰC:&lt;/strong&gt; Với \(f(x) = \max(f_1(x), f_2(x), f_3(x))\), nếu tại \(x_0\) có \(f_1(x_0) = f_2(x_0) &amp;gt; f_3(x_0)\), thì \(\partial f(x_0) = \operatorname{conv}(\partial f_1(x_0) \cup \partial f_2(x_0))\) — &lt;strong&gt;tuyệt đối không&lt;/strong&gt; đưa \(\partial f_3(x_0)\) vào!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 4 — Hình dạng \(\partial \|x\|_2\) tại \(0\) vs. \(\partial \|x\|_1\) tại \(0\):&lt;/strong&gt; Tại \(x = 0\), \(\partial \|0\|_2\) là &lt;strong&gt;hình cầu Euclidean đơn vị&lt;/strong&gt; \(\{g : \|g\|_2 \le 1\}\), còn \(\partial \|0\|_1\) là &lt;strong&gt;hình lập phương đơn vị&lt;/strong&gt; \(\{g : \|g\|_\infty \le 1\}\) (tức là quả cầu đơn vị của &lt;em&gt;chuẩn đối ngẫu&lt;/em&gt;!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phản-ví-dụ-2-chiều-chứng-minh--g-có-thể-không-phải-hướng-giảm&quot;&gt;Giải thích: Phản ví dụ 2 chiều chứng minh \(-g\) có thể KHÔNG phải hướng giảm!&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét hàm lồi không trơn $$f(x_1, x_2) =&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+ 2&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\(tại điểm\)x = (0, 1)^T\((giá trị\)f(0, 1) = 2$$):&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tính vi phân dưới tại \((0, 1)\):&lt;/strong&gt;
Vì \(x_1 = 0\) và \(x_2 = 1 &amp;gt; 0\), ta có \(\partial f(0, 1) = [-1, 1] \times \{2\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Chọn một subgradient hợp lệ \(g = (1, 2)^T \in \partial f(0, 1)\) và thử bước đi theo hướng \(-g = (-1, -2)^T\):&lt;/strong&gt;
Điểm mới với bước nhỏ \(t &amp;gt; 0\) (ví dụ \(t = 0.1\)):
\(x_{\text{new}} = (0, 1) - 0.1(1, 2) = (-0.1,\; 0.8) \implies f(x_{\text{new}}) = 0.1 + 2(0.8) = 1.7 &amp;lt; 2\) (lần này giảm!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Bây giờ đổi hàm sang \(f(x_1, x_2) = |x_1| + 2|x_2 - x_1|\) tại \((1, 1)\) (nơi \(f(1,1) = 1\)):&lt;/strong&gt;
Tại \((1, 1)\), nhánh \(|x_1|\) có đạo hàm \((1, 0)\), nhánh \(2|x_2 - x_1|\) có subgradient \(2s(-1, 1)\) với \(s \in [-1, 1]\).
Chọn \(s = 1\) cho \(g = (1, 0) + (-2, 2) = (-1, 2)^T \in \partial f(1, 1)\).
Đi theo hướng \(-g = (1, -2)^T\) một bước nhỏ \(t &amp;gt; 0\) đến \((1 + t,\; 1 - 2t)\):
\(f(1 + t,\; 1 - 2t) = (1 + t) + 2|-3t| = 1 + 7t &amp;gt; 1 = f(1, 1) \quad \forall t &amp;gt; 0!\)
Hàm mục tiêu &lt;strong&gt;tăng lên với mọi bước \(t &amp;gt; 0\)&lt;/strong&gt;, nhưng khoảng cách bình phương tới nghiệm \((0,0)\) vẫn co lại với \(t\) đủ nhỏ! Đó là lý do Phương pháp Subgradient phải luôn lưu lại giá trị tốt nhất \(f_{\text{best}}^{(k)} = \min_{i \le k} f(x^{(i)})\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-gradient-dưới-subgradient&quot;&gt;📐 &lt;strong&gt;Gradient Dưới (Subgradient)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa&quot;&gt;&lt;strong&gt;Định nghĩa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Đối với hàm lồi \(f: \mathbb{R}^n \to \mathbb{R}\), gradient dưới tại \(x\) là vector \(g \in \mathbb{R}^n\) thỏa mãn:&lt;/p&gt;

\[f(y) \ge f(x) + g^T(y - x), \quad \forall y\]

&lt;p&gt;&lt;strong&gt;Ý nghĩa hình học:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g\) xác định một siêu phẳng tựa (supporting hyperplane) của \(f\) tại \(x\).&lt;/li&gt;
  &lt;li&gt;Siêu phẳng này nằm dưới đồ thị hàm số tại mọi điểm.&lt;/li&gt;
  &lt;li&gt;Tổng quát hóa khái niệm gradient cho các hàm không khả vi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tính-chất-cơ-bản&quot;&gt;&lt;strong&gt;Tính chất cơ bản&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính tồn tại:&lt;/strong&gt; Gradient dưới luôn tồn tại với mọi hàm lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính duy nhất:&lt;/strong&gt; Nếu \(f\) khả vi tại \(x\), thì \(g = \nabla f(x)\) là gradient dưới duy nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm không lồi:&lt;/strong&gt; Với hàm không lồi, gradient dưới có thể không tồn tại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-các-ví-dụ-quan-trọng&quot;&gt;📊 &lt;strong&gt;Các Ví Dụ Quan Trọng&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-hàm-giá-trị-tuyệt-đối-fx--lvert-x-rvert&quot;&gt;&lt;strong&gt;1. Hàm giá trị tuyệt đối: \(f(x) = \lvert x \rvert\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial f(x) = \begin{cases}
\{-1\} &amp;amp; \text{nếu } x &amp;lt; 0 \\
[-1, 1] &amp;amp; \text{nếu } x = 0 \\
\{1\} &amp;amp; \text{nếu } x &amp;gt; 0
\end{cases}\)&lt;/p&gt;

&lt;h4 id=&quot;2-chuẩn-l1-fx--lvert-x-rvert_1--sum_i1n-lvert-x_i-rvert&quot;&gt;&lt;strong&gt;2. Chuẩn L1: \(f(x) = \lVert x \rVert_1 = \sum_{i=1}^n \lvert x_i \rvert\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\((\partial f(x))_i = \begin{cases}
\{\text{sign}(x_i)\} &amp;amp; \text{nếu } x_i \neq 0 \\
[-1, 1] &amp;amp; \text{nếu } x_i = 0
\end{cases}\)&lt;/p&gt;

&lt;h4 id=&quot;3-chuẩn-l2-fx--lvert-x-rvert_2&quot;&gt;&lt;strong&gt;3. Chuẩn L2: \(f(x) = \lVert x \rVert_2\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial f(x) = \begin{cases}
\left\{\frac{x}{\lVert x \rVert_2}\right\} &amp;amp; \text{nếu } x \neq 0 \\
\{g : \lVert g \rVert_2 \le 1\} &amp;amp; \text{nếu } x = 0
\end{cases}\)&lt;/p&gt;

&lt;h4 id=&quot;4-hàm-max-fx--maxf_1x-f_2x&quot;&gt;&lt;strong&gt;4. Hàm max: \(f(x) = \max\{f_1(x), f_2(x)\}\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial f(x) = \begin{cases}
\{\nabla f_1(x)\} &amp;amp; \text{nếu } f_1(x) &amp;gt; f_2(x) \\
\{\nabla f_2(x)\} &amp;amp; \text{nếu } f_1(x) &amp;lt; f_2(x) \\
\text{conv}\{\nabla f_1(x), \nabla f_2(x)\} &amp;amp; \text{nếu } f_1(x) = f_2(x)
\end{cases}\)&lt;/p&gt;

&lt;h3 id=&quot;-vi-phân-dưới-subdifferential&quot;&gt;🔍 &lt;strong&gt;Vi Phân Dưới (Subdifferential)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa-1&quot;&gt;&lt;strong&gt;Định nghĩa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Vi phân dưới \(\partial f(x)\) là tập hợp tất cả các gradient dưới tại \(x\):&lt;/p&gt;

\[\partial f(x) = \{g \in \mathbb{R}^n : g \text{ là gradient dưới của } f \text{ tại } x\}\]

&lt;h4 id=&quot;tính-chất-quan-trọng&quot;&gt;&lt;strong&gt;Tính chất quan trọng&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tập lồi đóng:&lt;/strong&gt; \(\partial f(x)\) luôn là tập lồi đóng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khác rỗng:&lt;/strong&gt; Nếu \(f\) lồi thì \(\partial f(x) \neq \emptyset\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duy nhất:&lt;/strong&gt; Nếu \(f\) lồi và khả vi tại \(x\), thì \(\partial f(x) = \{\nabla f(x)\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả vi:&lt;/strong&gt; Nếu \(\partial f(x) = \{g\}\), thì \(f\) khả vi tại \(x\) và \(\nabla f(x) = g\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-điều-kiện-tối-ưu-gradient-dưới&quot;&gt;🎯 &lt;strong&gt;Điều Kiện Tối Ưu Gradient Dưới&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-lý-cơ-bản&quot;&gt;&lt;strong&gt;Định lý cơ bản&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^* \text{ là cực tiểu toàn cục của } f \quad \Longleftrightarrow \quad 0 \in \partial f(x^*)\)&lt;/p&gt;

&lt;h4 id=&quot;chứng-minh&quot;&gt;&lt;strong&gt;Chứng minh&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
f(x^*) = \min_x f(x) &amp;amp;\Longleftrightarrow f(y) \ge f(x^*) \text{ với mọi } y \\
&amp;amp;\Longleftrightarrow f(y) \ge f(x^*) + 0^T(y - x^*) \\
&amp;amp;\Longleftrightarrow 0 \in \partial f(x^*)
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Điều kiện này đúng cho cả hàm không lồi.&lt;/p&gt;

&lt;h3 id=&quot;-kết-nối-với-điều-kiện-tối-ưu-bậc-một&quot;&gt;🔗 &lt;strong&gt;Kết Nối với Điều Kiện Tối Ưu Bậc Một&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-có-ràng-buộc&quot;&gt;&lt;strong&gt;Bài toán có ràng buộc&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{x \in C} f(x)\)&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-tối-ưu-bậc-một&quot;&gt;&lt;strong&gt;Điều kiện tối ưu bậc một&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Nếu \(f\) lồi và khả vi trên tập lồi \(C\):
\(x^* \text{ tối ưu} \Longleftrightarrow \nabla f(x^*)^T(y - x^*) \ge 0, \quad \forall y \in C\)&lt;/p&gt;

&lt;h4 id=&quot;suy-dẫn-từ-gradient-dưới&quot;&gt;&lt;strong&gt;Suy dẫn từ gradient dưới&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
\min_{x \in C} f(x) &amp;amp;\Longleftrightarrow \min_x [f(x) + I_C(x)] \\
&amp;amp;\Longleftrightarrow 0 \in \partial[f(x^*) + I_C(x^*)] \\
&amp;amp;\Longleftrightarrow 0 \in \{\nabla f(x^*)\} + \mathcal{N}_C(x^*) \\
&amp;amp;\Longleftrightarrow -\nabla f(x^*) \in \mathcal{N}_C(x^*) \\
&amp;amp;\Longleftrightarrow \nabla f(x^*)^T(y - x^*) \ge 0, \quad \forall y \in C
\end{align}\)&lt;/p&gt;

&lt;h3 id=&quot;-quy-tắc-tính-toán-gradient-dưới&quot;&gt;📏 &lt;strong&gt;Quy Tắc Tính Toán Gradient Dưới&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-tổ-hợp-tuyến-tính&quot;&gt;&lt;strong&gt;1. Tổ hợp tuyến tính&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial(\alpha f + \beta g)(x) = \alpha \partial f(x) + \beta \partial g(x)\)
với \(\alpha, \beta \ge 0\).&lt;/p&gt;

&lt;h4 id=&quot;2-hàm-giá-trị-lớn-nhất&quot;&gt;&lt;strong&gt;2. Hàm giá trị lớn nhất&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial \max\{f_1, \ldots, f_m\}(x) = \text{conv}\{\partial f_i(x) : i \in I(x)\}\)
với \(I(x) = \{i : f_i(x) = \max_j f_j(x)\}\).&lt;/p&gt;

&lt;h4 id=&quot;3-hợp-thành-với-ánh-xạ-affine&quot;&gt;&lt;strong&gt;3. Hợp thành với ánh xạ affine&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Nếu \(h(x) = f(Ax + b)\):
\(\partial h(x) = A^T \partial f(Ax + b)\)&lt;/p&gt;

&lt;h4 id=&quot;4-hàm-chỉ-thị&quot;&gt;&lt;strong&gt;4. Hàm chỉ thị&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial I_C(x) = \begin{cases}
\mathcal{N}_C(x) &amp;amp; \text{nếu } x \in C \\
\emptyset &amp;amp; \text{nếu } x \notin C
\end{cases}\)&lt;/p&gt;

&lt;p&gt;với \(\mathcal{N}_C(x)\) là nón pháp tuyến của \(C\) tại \(x\).&lt;/p&gt;

&lt;h3 id=&quot;-ứng-dụng-thực-tế&quot;&gt;🎲 &lt;strong&gt;Ứng Dụng Thực Tế&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-hồi-quy-lasso&quot;&gt;&lt;strong&gt;1. Hồi quy LASSO&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_\beta \frac{1}{2}\lVert y - X\beta \rVert_2^2 + \lambda \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện tối ưu:&lt;/strong&gt;
\(0 \in X^T(X\beta^* - y) + \lambda \partial \lVert \beta^* \rVert_1\)&lt;/p&gt;

&lt;h4 id=&quot;2-toán-tử-ngưỡng-mềm-soft-thresholding&quot;&gt;&lt;strong&gt;2. Toán tử ngưỡng mềm (Soft-thresholding)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Nghiệm của \(\min_x \frac{1}{2}(x - a)^2 + \lambda \lvert x \rvert\):&lt;/p&gt;

\[x^* = \text{soft}(a, \lambda) = \begin{cases}
a - \lambda &amp;amp; \text{nếu } a &amp;gt; \lambda \\
0 &amp;amp; \text{nếu } \lvert a \rvert \le \lambda \\
a + \lambda &amp;amp; \text{nếu } a &amp;lt; -\lambda
\end{cases}\]

&lt;h4 id=&quot;3-phép-chiếu-lên-tập-lồi&quot;&gt;&lt;strong&gt;3. Phép chiếu lên tập lồi&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x \frac{1}{2}\lVert x - a \rVert_2^2 + I_C(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt; \(x^* = P_C(a)\) (phép chiếu Euclid của \(a\) lên \(C\)).&lt;/p&gt;

&lt;h3 id=&quot;-so-sánh-gradient-và-subgradient&quot;&gt;🔄 &lt;strong&gt;So Sánh Gradient và Subgradient&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khía cạnh&lt;/th&gt;
      &lt;th&gt;Gradient&lt;/th&gt;
      &lt;th&gt;Subgradient&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Điều kiện&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hàm khả vi&lt;/td&gt;
      &lt;td&gt;Hàm lồi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tính duy nhất&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Duy nhất&lt;/td&gt;
      &lt;td&gt;Có thể là một tập hợp&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tính tồn tại&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Không phải lúc nào cũng tồn tại&lt;/td&gt;
      &lt;td&gt;Luôn tồn tại với hàm lồi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Cách tính&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đạo hàm thông thường&lt;/td&gt;
      &lt;td&gt;Quy tắc vi phân dưới&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Phạm vi ứng dụng&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tối ưu hàm trơn&lt;/td&gt;
      &lt;td&gt;Tối ưu hàm không trơn&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-quy-trình-tính-toán&quot;&gt;🛠️ &lt;strong&gt;Quy Trình Tính Toán&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bước-1-xác-định-tính-khả-vi&quot;&gt;&lt;strong&gt;Bước 1: Xác định tính khả vi&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(f\) khả vi tại \(x\): \(\partial f(x) = \{\nabla f(x)\}\).&lt;/li&gt;
  &lt;li&gt;Nếu không khả vi: áp dụng các quy tắc phép tính vi phân dưới.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;bước-2-phân-tích-cấu-trúc&quot;&gt;&lt;strong&gt;Bước 2: Phân tích cấu trúc&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Tổ hợp tuyến tính không âm của các hàm lồi.&lt;/li&gt;
  &lt;li&gt;Hàm \(\max\) hữu hạn theo điểm.&lt;/li&gt;
  &lt;li&gt;Hàm hợp thành với ánh xạ affine.&lt;/li&gt;
  &lt;li&gt;Hàm chỉ thị của tập lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;bước-3-áp-dụng-quy-tắc&quot;&gt;&lt;strong&gt;Bước 3: Áp dụng quy tắc&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Tính vi phân dưới của từng thành phần.&lt;/li&gt;
  &lt;li&gt;Kết hợp kết quả theo các quy tắc tương ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-thuật-toán-phương-pháp-subgradient&quot;&gt;⚡ &lt;strong&gt;Thuật Toán Phương Pháp Subgradient&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;quy-tắc-cập-nhật&quot;&gt;&lt;strong&gt;Quy tắc cập nhật&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k+1)} = x^{(k)} - t_k g^{(k)}\)
với \(g^{(k)} \in \partial f(x^{(k)})\).&lt;/p&gt;

&lt;h4 id=&quot;lựa-chọn-kích-thước-bước&quot;&gt;&lt;strong&gt;Lựa chọn kích thước bước&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cố định:&lt;/strong&gt; \(t_k = t &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giảm dần:&lt;/strong&gt; \(t_k \to 0\), \(\sum t_k = \infty\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng bình phương hội tụ:&lt;/strong&gt; \(\sum t_k^2 &amp;lt; \infty\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tính-chất-hội-tụ&quot;&gt;&lt;strong&gt;Tính chất hội tụ&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Không đảm bảo giảm đơn điệu ở mọi bước.&lt;/li&gt;
  &lt;li&gt;Hội tụ về giá trị tối ưu (theo \(f(x_{\text{best}}^{(k)})\)).&lt;/li&gt;
  &lt;li&gt;Tốc độ hội tụ: \(O(1/\sqrt{k})\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ví-dụ-minh-họa&quot;&gt;🎯 &lt;strong&gt;Ví Dụ Minh Họa&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-min_x-lvert-x---2-rvert--lvert-x--1-rvert&quot;&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; \(\min_x \lvert x - 2 \rvert + \lvert x + 1 \rvert\)&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; Tính vi phân dưới
\(\partial f(x) = \partial \lvert x - 2 \rvert + \partial \lvert x + 1 \rvert\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt; Phân tích từng khoảng&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(x &amp;lt; -1\): \(\partial f(x) = \{-1 - 1\} = \{-2\}\)&lt;/li&gt;
  &lt;li&gt;\(-1 &amp;lt; x &amp;lt; 2\): \(\partial f(x) = \{-1 + 1\} = \{0\}\)&lt;/li&gt;
  &lt;li&gt;\(x &amp;gt; 2\): \(\partial f(x) = \{1 + 1\} = \{2\}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bước 3:&lt;/strong&gt; Điều kiện tối ưu
\(0 \in \partial f(x^*) \Rightarrow x^* \in [-1, 2]\)&lt;/p&gt;

&lt;h3 id=&quot;-mẹo-thực-hành&quot;&gt;💡 &lt;strong&gt;Mẹo Thực Hành&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;nhận-biết-hàm-không-khả-vi&quot;&gt;&lt;strong&gt;Nhận biết hàm không khả vi:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm chứa \(\lvert \cdot \rvert\), \(\max\{\cdot\}\), \(\min\{\cdot\}\).&lt;/li&gt;
  &lt;li&gt;Hàm chỉ thị \(I_C(\cdot)\).&lt;/li&gt;
  &lt;li&gt;Các chuẩn không trơn như \(\lVert \cdot \rVert_1\), \(\lVert \cdot \rVert_\infty\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tính-toán-hiệu-quả&quot;&gt;&lt;strong&gt;Tính toán hiệu quả:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Tận dụng quy tắc tổ hợp tuyến tính.&lt;/li&gt;
  &lt;li&gt;Phân tích độc lập theo từng tọa độ khi hàm tách biến được.&lt;/li&gt;
  &lt;li&gt;Khai thác trực giác hình học (siêu phẳng tựa, nón pháp tuyến).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;kiểm-tra-kết-quả&quot;&gt;&lt;strong&gt;Kiểm tra kết quả:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Xác minh bất đẳng thức định nghĩa gradient dưới.&lt;/li&gt;
  &lt;li&gt;Kiểm tra tính lồi đóng của tập kết quả.&lt;/li&gt;
  &lt;li&gt;Đối chiếu với trường hợp khả vi tại các điểm trơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Ghi chú:&lt;/strong&gt; Subgradient mở rộng khái niệm gradient sang lớp hàm không khả vi và là công cụ nền tảng trong tối ưu hóa lồi cũng như các bài toán học máy có chính quy hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra hiểu biết của bạn về gradient dưới (subgradient), subdifferential, các tính chất hình học và điều kiện tối ưu trong tối ưu hóa lồi.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🧮 Quiz: Subgradient và Subdifferential&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;25&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: Định nghĩa subgradient --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Gradient dưới (subgradient) của hàm lồi \\(f\\) tại điểm \\(x\\) là vector \\(g\\) thỏa mãn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \\(f(y) \leq f(x) + g^T(y-x)\\) với mọi \\(y\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \\(f(y) \geq f(x) + g^T(y-x)\\) với mọi \\(y\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \\(f(y) = f(x) + g^T(y-x)\\) với mọi \\(y\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \\(\nabla f(x) = g\\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$f(y) \geq f(x) + g^T(y-x)$$ với mọi $$y$$&lt;/strong&gt;&lt;br /&gt;
                Đây là định nghĩa chính xác của subgradient: hàm luôn nằm trên siêu phẳng tuyến tính được định nghĩa bởi subgradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Subdifferential --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Subdifferential \\(\partial f(x)\\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) Tập hợp tất cả các gradient tại \\(x\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) Tập hợp tất cả các subgradient tại \\(x\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Vector gradient duy nhất tại \\(x\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Đạo hàm bậc hai tại \\(x\\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tập hợp tất cả các subgradient tại $$x$$&lt;/strong&gt;&lt;br /&gt;
                Subdifferential $$\partial f(x)$$ là tập hợp tất cả các vector $$g$$ thỏa mãn điều kiện subgradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Subgradient của |x| --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Subgradient của hàm \\(f(x) = |x|\\) tại \\(x = 0\\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \\(\{0\}\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \\(\{1, -1\}\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \\([-1, 1]\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \\(\mathbb{R}\\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) $$[-1, 1]$$&lt;/strong&gt;&lt;br /&gt;
                Tại $$x = 0$$, hàm $$|x|$$ không khả vi và subdifferential là đoạn $$[-1, 1]$$ vì $$|y| \geq g \cdot y$$ với mọi $$y$$ khi $$g \in [-1, 1]$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Subgradient khi hàm khả vi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Nếu hàm lồi \\(f\\) khả vi tại \\(x\\), thì \\(\partial f(x)\\) bằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) \\(\{\nabla f(x)\}\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) \\(\emptyset\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) \\(\mathbb{R}^n\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Tập hợp vô hạn các vector&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\{\nabla f(x)\}$$&lt;/strong&gt;&lt;br /&gt;
                Khi hàm lồi khả vi tại một điểm, subdifferential chỉ chứa một phần tử duy nhất là gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Điều kiện tối ưu --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Điều kiện cần và đủ để \\(x^*\\) là điểm cực tiểu toàn cục của hàm lồi \\(f\\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \\(\nabla f(x^*) = 0\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \\(0 \in \partial f(x^*)\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \\(f(x^*) = 0\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \\(\partial f(x^*) = \mathbb{R}^n\\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$0 \in \partial f(x^*)$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện tối ưu subgradient: $$x^*$$ là cực tiểu toàn cục khi và chỉ khi $$0$$ thuộc subdifferential tại $$x^*$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Tính chất subdifferential --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Subdifferential \(\partial f(x)\) của hàm lồi luôn là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) Tập hợp rỗng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) Tập hợp đóng và lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) Tập hợp mở&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Chỉ chứa một phần tử&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tập hợp đóng và lồi&lt;/strong&gt;&lt;br /&gt;
                Subdifferential của hàm lồi luôn là tập hợp đóng, lồi và compact và khác rỗng (nếu $$x$$ thuộc phần trong của $$\text{dom} f$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Subgradient của max function --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Cho \(f(x) = \max\{x_1, x_2\}\) tại điểm \(x = (2, 2)\). Subdifferential \(\partial f(x)\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) \(\{(1, 0), (0, 1)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(\text{conv}\{(1, 0), (0, 1)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) \(\{(1, 1)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(\{(0, 0)\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) \(\text{conv}\{(1, 0), (0, 1)\}\)&lt;/strong&gt;&lt;br /&gt;
                Tại điểm có nhiều thành phần đạt maximum, subdifferential là bao lồi của các gradient của các thành phần active.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Quy tắc tổng --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Nếu \(f\) và \(g\) là hai hàm lồi, thì \(\partial(f + g)(x)\) bằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(\partial f(x) + \partial g(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(\partial f(x) \cup \partial g(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(\partial f(x) \cap \partial g(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(\max\{\partial f(x), \partial g(x)\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) \(\partial f(x) + \partial g(x)\)&lt;/strong&gt;&lt;br /&gt;
                Quy tắc tổng: subdifferential của tổng bằng tổng Minkowski của các subdifferential (đúng khi, chẳng hạn, $$\text{relint}\,\text{dom} f \cap \text{relint}\,\text{dom} g \neq \emptyset$$, ví dụ khi cả hai hàm hữu hạn trên toàn $$\mathbb{R}^n$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Subgradient của norm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Subdifferential của hàm \(f(x) = \|x\|_2\) tại \(x \neq 0\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(\{x/\|x\|_2\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(\{u : \|u\|_2 \leq 1\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(\{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(\mathbb{R}^n\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) \(\{x/\|x\|_2\}\)&lt;/strong&gt;&lt;br /&gt;
                Khi \(x \neq 0\), norm Euclidean khả vi và gradient là \(x/\|x\|_2\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Subgradient tại gốc --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Subdifferential của hàm \(f(x) = \|x\|_2\) tại \(x = 0\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(\{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(\{u : \|u\|_2 \leq 1\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(\{u : \|u\|_2 = 1\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(\mathbb{R}^n\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) \(\{u : \|u\|_2 \leq 1\}\)&lt;/strong&gt;&lt;br /&gt;
                Tại gốc, subdifferential của norm Euclidean là đơn vị ball đóng.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Quy tắc chain rule --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Cho \(f(x) = g(Ax + b)\) với \(g\) lồi và \(A\) là ma trận. Khi đó \(\partial f(x)\) bằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(A^T \partial g(Ax + b)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(A \partial g(Ax + b)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(\partial g(Ax + b) A^T\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(\partial g(Ax + b)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) \(A^T \partial g(Ax + b)\)&lt;/strong&gt;&lt;br /&gt;
                Chain rule cho subdifferential: \(\partial f(x) = A^T \partial g(Ax + b)\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Hàm chỉ thị --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Subdifferential của hàm chỉ thị \(I_C(x)\) của tập lồi \(C\) tại \(x \in C\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) \(\{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Nón pháp tuyến \(N_C(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Nón tiếp tuyến \(T_C(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) \(\mathbb{R}^n\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Nón pháp tuyến \(N_C(x)\)&lt;/strong&gt;&lt;br /&gt;
                Subdifferential của hàm chỉ thị bằng nón pháp tuyến của tập lồi tại điểm đó.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Tính đơn điệu --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Toán tử subdifferential \(\partial f\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Đơn điệu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Không đơn điệu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Liên tục&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Đơn điệu&lt;/strong&gt;&lt;br /&gt;
                Subdifferential của hàm lồi là toán tử đơn điệu: \((g_1 - g_2)^T(x_1 - x_2) \geq 0\) với \(g_i \in \partial f(x_i)\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Subgradient của hàm tuyến tính --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Subdifferential của hàm tuyến tính \(f(x) = c^T x\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) \(\{c\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) \(\{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) \(\mathbb{R}^n\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) \(\{tc : t \geq 0\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) \(\{c\}\)&lt;/strong&gt;&lt;br /&gt;
                Hàm tuyến tính khả vi mọi nơi với gradient không đổi bằng \(c\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Subgradient của hàm bậc hai --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Cho \(f(x) = \frac{1}{2}x^T Q x + c^T x\) với \(Q \succeq 0\). Subdifferential \(\partial f(x)\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(\{Qx + c\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(\{Qx\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(\{c\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) \(\{x\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) \(\{Qx + c\}\)&lt;/strong&gt;&lt;br /&gt;
                Hàm bậc hai lồi khả vi với gradient \(\nabla f(x) = Qx + c\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Điều kiện tối ưu có ràng buộc --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Cho bài toán \(\min f(x)\) s.t. \(x \in C\). Điều kiện tối ưu là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(0 \in \partial f(x^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(-\partial f(x^*) \cap N_C(x^*) \neq \emptyset\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(\nabla f(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(x^* \in C\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) \(-\partial f(x^*) \cap N_C(x^*) \neq \emptyset\)&lt;/strong&gt;&lt;br /&gt;
                Điều kiện tối ưu subgradient có ràng buộc: tồn tại subgradient âm thuộc nón pháp tuyến.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Subgradient của hàm lồi từng phần --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Cho \(f(x) = \max\{f_1(x), f_2(x)\}\) với \(f_1, f_2\) lồi và khả vi. Tại điểm \(x\) mà \(f_1(x) &amp;gt; f_2(x)\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) \(\partial f(x) = \{\nabla f_1(x)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) \(\partial f(x) = \{\nabla f_2(x)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) \(\partial f(x) = \text{conv}\{\nabla f_1(x), \nabla f_2(x)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) \(\partial f(x) = \emptyset\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) \(\partial f(x) = \{\nabla f_1(x)\}\)&lt;/strong&gt;&lt;br /&gt;
                Khi chỉ có một hàm đạt maximum, subdifferential chỉ chứa gradient của hàm đó.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Tính liên tục --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Subdifferential \(\partial f(x)\) của hàm lồi \(f\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Liên tục trên&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Nửa liên tục trên&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Liên tục dưới&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Không liên tục&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Nửa liên tục trên&lt;/strong&gt;&lt;br /&gt;
                Subdifferential là ánh xạ đa trị nửa liên tục trên (upper semicontinuous).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Subgradient của hàm khoảng cách --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Cho \(f(x) = d_C(x) = \inf_{y \in C} \|x - y\|_2\) với \(C\) lồi đóng. Khi \(x \notin C\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) \(\partial f(x) = \{(x - P_C(x))/\|x - P_C(x)\|_2\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) \(\partial f(x) = \{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) \(\partial f(x) = N_C(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) \(\partial f(x) = \{x\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) \(\partial f(x) = \{(x - P_C(x))/\|x - P_C(x)\|_2\}\)&lt;/strong&gt;&lt;br /&gt;
                Subgradient của hàm khoảng cách là vector đơn vị từ phép chiếu đến điểm gốc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Subgradient của hàm support --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Hàm support \(\sigma_C(x) = \sup_{y \in C} y^T x\) của tập lồi compact \(C\) có subdifferential:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) \(\partial \sigma_C(x) = \arg\max_{y \in C} y^T x\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) \(\partial \sigma_C(x) = C\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) \(\partial \sigma_C(x) = \{x\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) \(\partial \sigma_C(x) = \{0\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) \(\partial \sigma_C(x) = \arg\max_{y \in C} y^T x\)&lt;/strong&gt;&lt;br /&gt;
                Subdifferential của hàm support là tập các điểm đạt maximum trong định nghĩa supremum.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 21: Ứng dụng trong machine learning --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Trong SVM, hàm hinge loss \(f(t) = \max\{0, 1-t\}\) có subdifferential tại \(t = 1\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) \(\{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) \(\{-1\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) \([-1, 0]\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) \([0, 1]\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) \([-1, 0]\)&lt;/strong&gt;&lt;br /&gt;
                Tại điểm kink \(t = 1\), subdifferential là đoạn nối giữa đạo hàm trái (-1) và đạo hàm phải (0).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Subgradient của norm L1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Subdifferential của \(f(x) = \|x\|_1\) tại \(x\) với \(x_i \neq 0\) cho thành phần thứ \(i\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) \(\text{sign}(x_i)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) \([-1, 1]\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) \(x_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) \(|x_i|\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) \(\text{sign}(x_i)\)&lt;/strong&gt;&lt;br /&gt;
                Khi \(x_i \neq 0\), thành phần thứ \(i\) của subdifferential là \(\text{sign}(x_i)\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Subgradient tại điểm không khả vi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Nếu hàm lồi \(f\) không khả vi tại \(x\), thì \(\partial f(x)\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Là tập hợp rỗng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Chứa nhiều hơn một phần tử&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Chỉ chứa vector không&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Không xác định&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Chứa nhiều hơn một phần tử&lt;/strong&gt;&lt;br /&gt;
                Tại điểm không khả vi, subdifferential chứa nhiều subgradient, phản ánh sự &quot;góc cạnh&quot; của hàm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Ứng dụng trong tối ưu hóa --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Trong thuật toán subgradient method, hướng cập nhật được chọn là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Gradient \(\nabla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Âm của một subgradient bất kỳ: \(-g\) với \(g \in \partial f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Vector ngẫu nhiên&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Hướng Newton&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Âm của một subgradient bất kỳ: \(-g\) với \(g \in \partial f(x)\)&lt;/strong&gt;&lt;br /&gt;
                Subgradient method chọn bất kỳ subgradient $$g$$ nào tại điểm hiện tại và cập nhật $$x^{+} = x - t g$$. Lưu ý $$-g$$ không nhất thiết là hướng giảm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Tính chất hình học --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Về mặt hình học, subgradient \(g \in \partial f(x)\) định nghĩa:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Siêu phẳng nằm trên đồ thị hàm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Siêu phẳng nằm dưới đồ thị hàm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Siêu phẳng cắt đồ thị hàm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Siêu phẳng vuông góc với đồ thị hàm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Siêu phẳng nằm dưới đồ thị hàm&lt;/strong&gt;&lt;br /&gt;
                Subgradient định nghĩa siêu phẳng support: \(f(y) \geq f(x) + g^T(y-x)\) - đồ thị hàm nằm trên siêu phẳng này.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành Quiz!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;c&apos;, q4: &apos;a&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;b&apos;,
    q11: &apos;a&apos;, q12: &apos;b&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;b&apos;, q17: &apos;a&apos;, q18: &apos;b&apos;, q19: &apos;a&apos;, q20: &apos;a&apos;,
    q21: &apos;c&apos;, q22: &apos;a&apos;, q23: &apos;b&apos;, q24: &apos;b&apos;, q25: &apos;b&apos;
};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
    
    // Re-render MathJax cho câu hỏi hiện tại
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise([document.getElementById(`q${n}`)])).then(() =&gt; {
            // MathJax rendering complete
        });
    }
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã nắm vững kiến thức về subgradient!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu khá tốt về subgradient và subdifferential.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại một số khái niệm về điều kiện tối ưu.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Hãy ôn lại định nghĩa và tính chất cơ bản.&apos;;
    } else {
        message = &apos;📖 Hãy học lại từ đầu các khái niệm về subgradient nhé!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Re-render MathJax cho tất cả nội dung
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise()).then(() =&gt; {
            // MathJax rendering complete
        });
    }
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise()).then(() =&gt; {
            // MathJax rendering complete
        });
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>07-03 Điều kiện tối ưu gradient dưới</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_subgradient_optimality_condition/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_subgradient_optimality_condition</id>
   <content type="html">&lt;p&gt;Trong giải tích cổ điển, mọi bài toán tìm cực tiểu không ràng buộc đều hội tụ về một phương trình duy nhất: \(\nabla f(x^\star) = 0\). Khi bước sang thế giới hàm lồi không khả vi của Chương 07, ta chỉ cần thay dấu bằng “&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt;” bằng dấu thuộc “&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;∈&lt;/code&gt;” — và toàn bộ lý thuyết tối ưu hóa lồi (cả không ràng buộc lẫn có ràng buộc, cả trơn lẫn không trơn!) đồng loạt sụp gọn thành &lt;strong&gt;một biểu thức ba ký tự kinh điển&lt;/strong&gt;:
\(0 \in \partial f(x^\star).\)&lt;/p&gt;

&lt;p&gt;Mục 07-03 sẽ chứng minh định lý gọn nhẹ đến khó tin này, dùng nó để suy dẫn ngược lại điều kiện tối ưu bậc nhất của Chương 04 trong đúng 3 dòng, và giải tường minh ba ví dụ huyền thoại của học máy hiện đại: &lt;strong&gt;Lasso&lt;/strong&gt;, &lt;strong&gt;Ngưỡng mềm (Soft-Thresholding)&lt;/strong&gt; và &lt;strong&gt;Khoảng cách đến tập lồi&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-ứng-dụng-xuất-phát-từ-0-in-partial-fxstar&quot;&gt;Kiến thức cần nhớ: Bốn nhánh ứng dụng xuất phát từ \(0 \in \partial f(x^\star)\)&lt;/h2&gt;

&lt;p&gt;Mọi bài học con trong phần 07-03 đều là một lát cắt trực tiếp của công thức \(0 \in \partial f(x^\star)\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh 1 dòng của \(0 \in \partial f(x^\star)\):&lt;/strong&gt; Không cần đạo hàm, không cần giới hạn, thậm chí &lt;strong&gt;không cần \(f\) lồi&lt;/strong&gt;! Theo định nghĩa subgradient, \(0 \in \partial f(x^\star) \iff f(y) \ge f(x^\star) + 0^T(y - x^\star) \iff f(y) \ge f(x^\star) \; \forall y\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hợp nhất Tối ưu có ràng buộc (Chương 04):&lt;/strong&gt; Viết \(\min_{x \in C} f(x)\) thành \(\min_x (f(x) + I_C(x))\) rồi áp dụng \(0 \in \partial f(x^\star) + N_C(x^\star)\) cho ngay \(-\nabla f(x^\star) \in N_C(x^\star) \iff \nabla f(x^\star)^T(y - x^\star) \ge 0 \; \forall y \in C\)!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Giải mã Lasso &amp;amp; Soft-Thresholding:&lt;/strong&gt; Áp dụng \(0 \in X^T(X\beta - y) + \lambda \partial |\beta|_1\) giải thích chính xác tại sao \(\beta_j^\star = 0\) khi tương quan phần dư $$&lt;/td&gt;
          &lt;td&gt;X_j^T(y - X\beta^\star)&lt;/td&gt;
          &lt;td&gt;\le \lambda$$!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình học Phép chiếu (Khoảng cách đến tập lồi):&lt;/strong&gt; Tính subgradient của \(\operatorname{dist}(x, C) = \min_{y \in C} \|x - y\|_2\) cho thấy hướng ra xa tập lồi \(C\) chính là vector đơn vị \(\frac{x - P_C(x)}{\|x - P_C(x)\|_2}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-bài-toán-không-trơn-1-biến-bằng-0-in-partial-fxstar&quot;&gt;Giải thích: Giải bài toán không trơn 1 biến bằng \(0 \in \partial f(x^\star)\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Tìm cực tiểu toàn cục của hàm $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x - 3&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x - 8&lt;/td&gt;
      &lt;td&gt;\((bài toán tìm **trung vị — median** của 3 điểm\)1, 3, 8$$!):&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thử tại \(x = 3\) (điểm ở giữa):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Tại \(x = 3\): $$&lt;/td&gt;
              &lt;td&gt;x - 1&lt;/td&gt;
              &lt;td&gt;\(có đạo hàm\)+1\(;\)&lt;/td&gt;
              &lt;td&gt;x - 8&lt;/td&gt;
              &lt;td&gt;\(có đạo hàm\)-1\(; còn\)&lt;/td&gt;
              &lt;td&gt;x - 3&lt;/td&gt;
              &lt;td&gt;\(gãy khúc nên có vi phân dưới\)[-1, 1]$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Áp dụng quy tắc tổng:
\(\partial f(3) = \{+1\} + [-1, 1] + \{-1\} = [-1, 1].\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Kiểm tra điều kiện tối ưu:&lt;/strong&gt; Vì \(0 \in [-1, 1] = \partial f(3)\), ta khẳng định ngay \(x^\star = 3\) là &lt;strong&gt;điểm cực tiểu toàn cục&lt;/strong&gt; (với $$f^\star =&lt;/td&gt;
          &lt;td&gt;3-1&lt;/td&gt;
          &lt;td&gt;+ 0 +&lt;/td&gt;
          &lt;td&gt;3-8&lt;/td&gt;
          &lt;td&gt;= 7$$)!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử tại \(x = 4\) (trung bình cộng \(1+3+8 = 12 \implies 12/3 = 4\)):&lt;/strong&gt;
\(\partial f(4) = \{+1\} + \{+1\} + \{-1\} = \{+1\} \not\ni 0.\)
(Thật vậy, \(f(4) = 3 + 1 + 4 = 8 &amp;gt; 7\)!) Đó là chứng minh tuyệt đẹp nhất cho thấy &lt;strong&gt;trung vị&lt;/strong&gt; tối thiểu hóa tổng sai số tuyệt đối (\(\ell_1\)), còn &lt;strong&gt;trung bình&lt;/strong&gt; tối thiểu hóa tổng bình phương sai số (\(\ell_2\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong phần này, chúng ta trình bày điều kiện tối ưu phát biểu qua gradient dưới, đồng thời phân tích một số ví dụ cụ thể để minh họa cách áp dụng và vai trò của điều kiện này.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03-05 Ví dụ: Khoảng cách đến tập lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_05_example_distance_to_convex_set/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_05_example_distance_to_convex_set</id>
   <content type="html">&lt;p&gt;Trong robot học (tránh va chạm chướng ngại vật), đồ họa máy tính và tối ưu hóa chiếu (projected methods), ta thường xuyên gặp &lt;strong&gt;hàm khoảng cách đến một tập lồi đóng \(C\)&lt;/strong&gt;: \(\operatorname{dist}(x, C) = \min_{y \in C} \|x - y\|_2\). Hàm này luôn lồi, nhưng liệu nó có khả vi không và gradient (hay subgradient) của nó hướng về đâu?&lt;/p&gt;

&lt;p&gt;Trực giác hình học cho ta câu trả lời trong tích tắc: nếu bạn đang đứng ở điểm \(x\) nằm ngoài một hồ nước hình lồi \(C\), và điểm bờ hồ gần bạn nhất là hình chiếu \(P_C(x)\), thì hướng khiến bạn &lt;strong&gt;đi ra xa hồ nhanh nhất&lt;/strong&gt; chính là tia thẳng nối từ \(P_C(x)\) qua \(x\) — tức là vector đơn vị \(g = \frac{x - P_C(x)}{\|x - P_C(x)\|_2}\)! Bài học này chứng minh chặt chẽ kết quả hình học tuyệt đẹp đó bằng đúng công cụ subgradient và điều kiện tối ưu bậc nhất!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-phép-chiếu-và-subgradient-của-hàm-khoảng-cách&quot;&gt;Kiến thức cần nhớ: Hình học Phép chiếu và Subgradient của Hàm khoảng cách&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau tóm gọn toàn bộ chứng minh và ứng dụng của bài học này:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính duy nhất và đặc trưng của Hình chiếu \(P_C(x)\):&lt;/strong&gt; Vì \(y \mapsto \frac{1}{2}\|x - y\|_2^2\) là hàm lồi chặt trên tập lồi đóng \(C\), điểm chiếu \(P_C(x) = \arg\min_{y \in C} \|x - y\|_2\) luôn &lt;strong&gt;tồn tại duy nhất&lt;/strong&gt; và thỏa điều kiện tối ưu bậc nhất (góc tù):
\((x - P_C(x))^T (y - P_C(x)) \le 0 \quad \forall y \in C.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient của \(\operatorname{dist}(x, C)\) khi \(x \notin C\):&lt;/strong&gt; Khi \(x \notin C\), ta có \(\operatorname{dist}(x, C) &amp;gt; 0\) và hàm khả vi với gradient duy nhất có độ dài bằng \(1\):
\(\nabla \operatorname{dist}(x, C) = \frac{x - P_C(x)}{\|x - P_C(x)\|_2}.\)
(Còn hàm &lt;em&gt;bình phương khoảng cách&lt;/em&gt; \(\frac{1}{2}\operatorname{dist}^2(x, C)\) thì &lt;strong&gt;khả vi ở mọi nơi&lt;/strong&gt; kể cả trên biên và trong \(C\), với gradient \(x - P_C(x)\)!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất đối ngẫu của siêu phẳng đỡ:&lt;/strong&gt; Trong chứng minh, ta dùng bất đẳng thức \((x - P_C(x))^T (z - P_C(x)) \le (x - P_C(x))^T (z - P_C(z))\) cộng với Cauchy-Schwarz để xác nhận \(g^T(z - x) \le \operatorname{dist}(z, C) - \operatorname{dist}(x, C)\) cho mọi \(z \in \mathbb{R}^n\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-p_cx-operatornamedistx-c-và-kiểm-chứng-subgradient-g&quot;&gt;Giải thích: Tính tay \(P_C(x)\), \(\operatorname{dist}(x, C)\) và kiểm chứng subgradient \(g\)&lt;/h3&gt;

&lt;p&gt;Xét tập lồi đóng là hình tròn đơn vị \(C = \{y \in \mathbb{R}^2 : \|y\|_2 \le 1\}\) và điểm ngoài \(x = (3, 4)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tìm hình chiếu \(P_C(x)\) và khoảng cách \(\operatorname{dist}(x, C)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Chuẩn \(\|x\|_2 = \sqrt{3^2 + 4^2} = 5 &amp;gt; 1\).&lt;/li&gt;
      &lt;li&gt;Hình chiếu lên hình tròn đơn vị là điểm trên tia \(Ox\) có độ dài 1:
\(P_C(x) = \frac{x}{\|x\|_2} = (0.6,\; 0.8)^T.\)&lt;/li&gt;
      &lt;li&gt;Khoảng cách: \(\operatorname{dist}(x, C) = \|x - P_C(x)\|_2 = 5 - 1 = 4\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tính subgradient \(g = \frac{x - P_C(x)}{\|x - P_C(x)\|_2}\):&lt;/strong&gt;
\(x - P_C(x) = (2.4,\; 3.2)^T \implies g = \frac{1}{4}(2.4,\; 3.2)^T = (0.6,\; 0.8)^T.\)
Kiểm tra độ dài: \(\|g\|_2 = \sqrt{0.36 + 0.64} = 1\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kiểm chứng bất đẳng thức subgradient \(\operatorname{dist}(z, C) \ge \operatorname{dist}(x, C) + g^T(z - x)\) tại điểm thử \(z = (0, 2)^T\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vế trái: \(\operatorname{dist}(z, C) = \|(0, 2)\|_2 - 1 = 2 - 1 = 1\).&lt;/li&gt;
      &lt;li&gt;Vế phải: \(4 + (0.6, 0.8) \cdot (-3, -2)^T = 4 + (-1.8 - 1.6) = 4 - 3.4 = 0.6\).&lt;/li&gt;
      &lt;li&gt;So sánh: \(1 \ge 0.6\) — thỏa mãn hoàn hảo!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Hàm khoảng cách từ một điểm \(x\) đến một tập lồi đóng \(C\) được định nghĩa như sau:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{alignat}{1}
dist(x,C) &amp;amp; = \min_{y \in C} | y-x |_2 &lt;br /&gt;
      &amp;amp; = | x-P_C(x) |_2 &lt;br /&gt;
      &amp;amp; \geq 0 
\end{alignat}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Trong đó, \(P_C(x)\) là phép chiếu Euclid của \(x\) lên tập \(C\), tức là điểm trong \(C\) gần \(x\) nhất. Với \(x \notin C\) (nên \(\|x - P_C(x)\|_2 &amp;gt; 0\)), vi phân dưới của hàm khoảng cách là:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\partial dist(x,C) = {\frac{x-P_C(x)}{ | x-P_C(x) |_2}}
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h3&gt;

&lt;p&gt;Đặt \(u=P_C(x)\). Theo điều kiện tối ưu bậc một cho bài toán chiếu lên tập lồi \(C\), ta có:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
(x-u)^T(y-u) \leq 0 \ \text{ với mọi } y \in C
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Suy ra tập \(C\) nằm trong nửa không gian đóng \(H\):&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
C \subseteq H = {y:(x-u)^T(y-u) \leq 0 }
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ta xét hai trường hợp của \(y\):&lt;/p&gt;

&lt;p&gt;(i) Với \(y \in H\), ta có:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
(x-u)^T(y-u) \leq 0
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Do \(dist(y,C)\geq 0\), nên hiển nhiên:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
dist(y,C) \geq \frac{(x-u)^T(y-u)}{ | x-u |_2} \text{ với mọi } y \in H
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(ii) Với \(y \notin H\), ta viết:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
(x-u)^T(y-u) = | x-u |_2 | y-u |_2 \cos\theta,
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\theta\) là góc giữa hai vector \(x-u\) và \(y-u\). Khi đó:&lt;/p&gt;
&lt;blockquote&gt;

\[\eqalign{
dist(y,C) &amp;amp;\geq dist(y,H) \\
&amp;amp;= \| y-u \|_2 \cos \theta \\
&amp;amp;= \frac{(x-u)^T(y-u)}{ \| x-u \|_2} \text{ với mọi }y \notin H
}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ (i) và (ii), bất đẳng thức sau đúng với mọi \(y\):&lt;/p&gt;
&lt;blockquote&gt;

\[\eqalign{
dist(y,C) &amp;amp;\geq \frac{(x-u)^T(y-u)}{ \| x-u \|_2} \\
&amp;amp;= \frac{(x-u)^T(y-x+x-u)}{ \| x-u \|_2}\\
&amp;amp; = \| x-u \|_2 + \left(\frac{x-u}{ \| x-u \|_2}\right)^T(y-x)
}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó, tại \(x \notin C\), hàm \(dist(x,C)\) có gradient dưới là:&lt;/p&gt;
&lt;blockquote&gt;

\[g=\frac{x-u}{ \| x-u \|_2}=\frac{x-P_C(x)}{ \| x-P_C(x) \|_2}\]
&lt;/blockquote&gt;

&lt;p&gt;Hơn nữa, vì vi phân dưới \(\partial dist(x,C)\) tại \(x \notin C\) chỉ gồm một phần tử duy nhất, hàm \(dist(x,C)\) khả vi tại \(x\) và đạo hàm của nó trùng với gradient dưới nói trên.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03-04 Ví dụ: Ngưỡng mềm (Soft-Thresholding)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_04_example_soft-thresholding/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_04_example_soft-thresholding</id>
   <content type="html">&lt;p&gt;Nếu bạn từng nghe đến các thuật toán tối ưu không trơn nổi tiếng như &lt;strong&gt;ISTA / FISTA (Proximal Gradient)&lt;/strong&gt; hay &lt;strong&gt;ADMM&lt;/strong&gt; dùng để giải Lasso hàng triệu biến trong chớp mắt, thì trái tim của tất cả các thuật toán đó nằm gọn trong một toán tử 1 dòng cực kỳ duyên dáng: &lt;strong&gt;Ngưỡng mềm (Soft-Thresholding)&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Toán tử này xuất hiện ngay khi ta giải trường hợp đơn giản nhất của Lasso với ma trận trực giao \(X = I\): \(\min_\beta \frac{1}{2}\|y - \beta\|_2^2 + \lambda\|\beta\|_1\). Nhờ bài toán tách hoàn toàn thành \(p\) bài toán 1 chiều độc lập, điều kiện subgradient \(0 \in \partial f(\beta^\star)\) cho ta một &lt;strong&gt;công thức nghiệm đóng tuyệt đẹp&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-toán-tử-ngưỡng-mềm-s_lambday&quot;&gt;Kiến thức cần nhớ: Giải phẫu Toán tử Ngưỡng mềm \(S_\lambda(y)\)&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau làm rõ cấu trúc và ứng dụng rộng lớn của Soft-Thresholding:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Công thức tách tọa độ (Separability):&lt;/strong&gt; Vì $$\frac{1}{2}|y - \beta|&lt;em&gt;2^2 + \lambda|\beta|_1 = \sum&lt;/em&gt;{i=1}^p \left(\frac{1}{2}(y_i - \beta_i)^2 + \lambda&lt;/td&gt;
          &lt;td&gt;\beta_i&lt;/td&gt;
          &lt;td&gt;\right)\(, ta tối ưu độc lập từng tọa độ\)\beta_i$$!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Nghiệm đóng Ngưỡng mềm (Soft-Thresholding Operator):&lt;/strong&gt; Giải điều kiện $$y_i - \beta_i \in \lambda \partial&lt;/td&gt;
          &lt;td&gt;\beta_i&lt;/td&gt;
          &lt;td&gt;$$ cho đúng ba miền:&lt;/td&gt;
          &lt;td&gt; &lt;/td&gt;
          &lt;td&gt; &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;$$\beta_i^\star = S_\lambda(y_i) = \begin{cases} y_i - \lambda &amp;amp; \text{nếu } y_i &amp;gt; \lambda \ 0 &amp;amp; \text{nếu }&lt;/td&gt;
          &lt;td&gt;y_i&lt;/td&gt;
          &lt;td&gt;\le \lambda \ y_i + \lambda &amp;amp; \text{nếu } y_i &amp;lt; -\lambda \end{cases} = \operatorname{sign}(y_i)\max(&lt;/td&gt;
          &lt;td&gt;y_i&lt;/td&gt;
          &lt;td&gt;- \lambda,\; 0).$$&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Ngưỡng mềm (Soft) vs. Ngưỡng cứng (Hard) &amp;amp; Toán tử Proximal:&lt;/strong&gt; Khác với ngưỡng cứng (giữ nguyên \(y_i\) khi $$&lt;/td&gt;
          &lt;td&gt;y_i&lt;/td&gt;
          &lt;td&gt;&amp;gt; \lambda\(nên bị nhảy gián đoạn tại\)\pm \lambda\(), ngưỡng mềm là hàm **liên tục** kéo mọi giá trị về gần 0 một khoảng\)\lambda\(và dập tắt hoàn toàn mọi nhiễu nằm trong &quot;vùng chết&quot;\)[-\lambda, \lambda]\(. Đây chính là **toán tử proximal**\)\operatorname{prox}_{\lambda|\cdot|_1}(y)$$ dùng trong xử lý ảnh wavelet và thuật toán ISTA!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-áp-dụng-soft-thresholding-bằng-tay-lên-một-vector-tín-hiệu-có-nhiễu&quot;&gt;Giải thích: Áp dụng Soft-Thresholding bằng tay lên một vector tín hiệu có nhiễu&lt;/h3&gt;

&lt;p&gt;Giả sử ta đo được vector tín hiệu lẫn nhiễu \(y = (4.5,\; -0.8,\; 0.3,\; -3.2,\; 1.0)^T\) và áp dụng ngưỡng mềm với \(\lambda = 1.0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tọa độ 1 (\(y_1 = 4.5 &amp;gt; 1.0\)):&lt;/strong&gt; \(\beta_1^\star = 4.5 - 1.0 = 3.5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tọa độ 2 (\(y_2 = -0.8 \in [-1, 1]\)):&lt;/strong&gt; \(\beta_2^\star = 0\) (nhiễu âm nhỏ bị dập tắt!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tọa độ 3 (\(y_3 = 0.3 \in [-1, 1]\)):&lt;/strong&gt; \(\beta_3^\star = 0\) (nhiễu dương nhỏ bị dập tắt!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tọa độ 4 (\(y_4 = -3.2 &amp;lt; -1.0\)):&lt;/strong&gt; \(\beta_4^\star = -3.2 + 1.0 = -2.2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tọa độ 5 (\(y_5 = 1.0\) nằm đúng biên ngưỡng):&lt;/strong&gt; \(\beta_5^\star = 1.0 - 1.0 = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết quả cuối cùng:&lt;/strong&gt; \(\beta^\star = (3.5,\; 0,\; 0,\; -2.2,\; 0)^T\).
&lt;strong&gt;Kiểm tra điều kiện subgradient tại tọa độ 4:&lt;/strong&gt; \(y_4 - \beta_4^\star = -3.2 - (-2.2) = -1.0 = \lambda \cdot \operatorname{sign}(-2.2)\) — khớp tuyệt đối! Từ một vector dày đặc 5 phần tử khác 0, chỉ một phép tính tuyến tính \(O(p)\) đã lọc ra đúng 2 thành phần tín hiệu thưa thực sự!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Xét trường hợp đơn giản hơn của bài toán Lasso khi \(X=I\):&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\min_{\beta} \frac{1}{2} | y-\beta |_2^2 + \lambda | \beta |_1
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Từ ví dụ trước, điều kiện tối ưu theo gradient dưới của bài toán này là:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{cases}
y_i-\beta_i = \lambda \cdot \text{sign}(\beta_i) &amp;amp;\text{nếu } \beta_i \neq 0 \\
 |y_i-\beta_i| \leq \lambda &amp;amp;\text{nếu } \beta_i = 0
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;Giải điều kiện trên cho từng tọa độ, ta thu được nghiệm dạng đóng \(\beta = S_{\lambda}(y)\), với:&lt;/p&gt;
&lt;blockquote&gt;

\[[S_{\lambda}(y)]_{i} = 
\begin{cases}
y_i - \lambda &amp;amp;\text{nếu }y_i &amp;gt; \lambda \\
0             &amp;amp;\text{nếu }-\lambda \leq y_i \leq \lambda, \quad \quad i \in \{1,2,\dots,n \} \\
y_i + \lambda &amp;amp;\text{nếu } y_i &amp;lt; -\lambda
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;Toán tử \(S_{\lambda}\) được gọi là &lt;strong&gt;toán tử ngưỡng mềm (soft-thresholding operator)&lt;/strong&gt;.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter07/07_03_subgrad-6.png&quot; alt=&quot;connection_to_convexity_geometry&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Hình 1] Ngưỡng mềm, y (trục x), } \beta \text{ (trục y), } \lambda=1/2 \text{ [3]}$$ &lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03-03 Ví dụ: Điều kiện tối ưu Lasso</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_03_example_lasso_optimality_condition/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_03_example_lasso_optimality_condition</id>
   <content type="html">&lt;p&gt;Năm 1996, Robert Tibshirani giới thiệu &lt;strong&gt;Lasso&lt;/strong&gt; (\(\min_\beta \frac{1}{2}\|y - X\beta\|_2^2 + \lambda\|\beta\|_1\)) và làm thay đổi mãi mãi thống kê hiện đại: chỉ bằng việc thay phạt bình phương \(\|\beta\|_2^2\) thành chuẩn \(\ell_1\) \(\|\beta\|_1\), mô hình bỗng tự động phát hiện và giữ lại vài chục biến quan trọng nhất trong hàng chục nghìn biến nhiễu!&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Nhưng chính xác &lt;strong&gt;cơ chế toán học nào&lt;/strong&gt; khiến Lasso đặt hàng loạt hệ số \(\beta_j^\star\) về đúng số \(0\)? Câu trả lời không thể đến từ đạo hàm cổ điển (vì $$&lt;/td&gt;
      &lt;td&gt;\beta_j&lt;/td&gt;
      &lt;td&gt;\(không khả vi tại\)0\(), mà đến trực tiếp từ điều kiện tối ưu subgradient\)0 \in -X^T(y - X\beta^\star) + \lambda \partial|\beta^\star|_1$$!&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-đọc-hiểu-điều-kiện-kktsubgradient-của-lasso&quot;&gt;Kiến thức cần nhớ: Đọc hiểu Điều kiện KKT/Subgradient của Lasso&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau giải mã trọn vẹn phương trình tối ưu của Lasso:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tách điều kiện tối ưu theo từng đặc trưng \(j = 1, \dots, p\):&lt;/strong&gt; Ký hiệu \(X_j\) là cột thứ \(j\) của ma trận dữ liệu và \(r^\star = y - X\beta^\star\) là vector phần dư tối ưu. Điều kiện \(0 \in \partial f(\beta^\star)\) viết ra từng tọa độ trở thành:
\(X_j^T (y - X\beta^\star) = \lambda s_j, \qquad s_j \in \begin{cases} \{\operatorname{sign}(\beta_j^\star)\} &amp;amp; \text{nếu } \beta_j^\star \neq 0 \\ [-1, 1] &amp;amp; \text{nếu } \beta_j^\star = 0 \end{cases}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa thống kê tuyệt đẹp — Tương quan với phần dư:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Mọi biến được chọn (\(\beta_j^\star \neq 0\)) đều có tích vô hướng với phần dư đạt &lt;strong&gt;đúng ngưỡng tới hạn&lt;/strong&gt; $$&lt;/td&gt;
              &lt;td&gt;X_j^T r^\star&lt;/td&gt;
              &lt;td&gt;= \lambda\((cùng dấu với\)\beta_j^\star$$)!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Mọi biến bị loại về \(0\) (\(\beta_j^\star = 0\)) đều có tương quan với phần dư bị chặn dưới ngưỡng: $$&lt;/td&gt;
              &lt;td&gt;X_j^T r^\star&lt;/td&gt;
              &lt;td&gt;\le \lambda$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Ngưỡng \(\lambda_{\max}\) ép toàn bộ mô hình về \(0\):&lt;/strong&gt; Khi \(\beta^\star = 0\), phần dư là \(r^\star = y\). Do đó \(\beta^\star = 0\) là nghiệm tối ưu toàn cục khi và chỉ khi $$\lambda \ge |X^T y|_\infty = \max_j&lt;/td&gt;
          &lt;td&gt;X_j^T y&lt;/td&gt;
          &lt;td&gt;$$!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-trực-tiếp-nghiệm-lasso-bằng-điều-kiện-subgradient&quot;&gt;Giải thích: Kiểm chứng trực tiếp nghiệm Lasso bằng điều kiện subgradient&lt;/h3&gt;

&lt;p&gt;Cho \(X = \begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}\) (2 đặc trưng trực giao), \(y = \begin{pmatrix} 3 \\ 0.6 \end{pmatrix}\) và \(\lambda = 1\). Ta kiểm chứng nghiệm đề xuất \(\beta^\star = (2,\; 0)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tính vector phần dư \(r^\star = y - X\beta^\star\):&lt;/strong&gt;
\(r^\star = \begin{pmatrix} 3 \\ 0.6 \end{pmatrix} - \begin{pmatrix} 2 \\ 0 \end{pmatrix} = \begin{pmatrix} 1 \\ 0.6 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tính \(X^T r^\star\) cho từng tọa độ:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tọa độ 1 (có \(\beta_1^\star = 2 &amp;gt; 0\)): \(X_1^T r^\star = 1\). So sánh với \(\lambda \operatorname{sign}(\beta_1^\star) = 1 \cdot (+1) = 1\). &lt;strong&gt;Khớp chính xác!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Tọa độ 2 (có \(\beta_2^\star = 0\)): \(X_2^T r^\star = 0.6\). Kiểm tra điều kiện $$&lt;/td&gt;
              &lt;td&gt;X_2^T r^\star&lt;/td&gt;
              &lt;td&gt;\le \lambda\(:\)&lt;/td&gt;
              &lt;td&gt;0.6&lt;/td&gt;
              &lt;td&gt;\le 1\((tương ứng\)s_2 = 0.6 \in [-1, 1]$$). &lt;strong&gt;Khớp chính xác!&lt;/strong&gt;&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Tìm ngưỡng \(\lambda_{\max}\) để cả hai biến đều bằng 0:&lt;/strong&gt;
\(\lambda_{\max} = \max(|X_1^T y|,\; |X_2^T y|) = \max(3,\; 0.6) = 3.\)
Thật vậy, hễ \(\lambda \ge 3\), cả \(|3| \le \lambda\) lẫn \(|0.6| \le \lambda\) đều thỏa, nên \(\beta^\star = (0, 0)^T\) ngay lập tức!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Xét bài toán Lasso sau:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\min_{\beta} \frac{1}{2}  | y-X\beta |_2^2 + \lambda | \beta |_1
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(y \in \mathbb{R}^n\), \(X \in \mathbb{R}^{n \times p}\) và \(\lambda \geq 0\).&lt;/p&gt;

&lt;p&gt;Điều kiện tối ưu theo gradient dưới của bài toán này được viết như sau:&lt;/p&gt;
&lt;blockquote&gt;

\[\eqalign{
0 \in \partial\left(\frac{1}{2} \| y-X\beta \|_2^2 + \lambda \| \beta \|_1\right)
&amp;amp;\quad \Longleftrightarrow \quad 0 \in - X^T (y-X\beta) + \lambda \partial  \| \beta \|_1 \\
&amp;amp;\quad \Longleftrightarrow \quad X^T (y-X\beta)  = \lambda v \\
&amp;amp; \quad \text{với } v \in \partial  \| \beta \|_1 \text{ nào đó}
}\\\]
&lt;/blockquote&gt;

&lt;p&gt;Với \(\beta=(\beta_1,\beta_2,\dots,\beta_p )\), các thành phần của gradient dưới \(v=(v_1,v_2,\dots,v_p)\) thỏa mãn:&lt;/p&gt;

\[v_i = 
\begin{cases}
 1   &amp;amp;\text{nếu } \beta_i &amp;gt; 0 \\
-1   &amp;amp;\text{nếu } \beta_i &amp;lt; 0 \\
[-1,1]   &amp;amp;\text{nếu } \beta_i = 0
\end{cases}
, i \in \{1,2,\dots,p \}\]

&lt;p&gt;Bất kỳ \(\beta\) nào thỏa mãn phương trình sau đều là nghiệm tối ưu:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
X^T(y-X\beta) = \lambda v 
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Viết theo từng tọa độ, \(\beta\) là nghiệm tối ưu khi và chỉ khi:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{cases}
X_i^T(y-X\beta) = \lambda \cdot \text{sign}(\beta_i) &amp;amp;\text{nếu } \beta_i \neq 0 \\
 |X_i^T(y-X\beta)|  \leq \lambda &amp;amp;\text{nếu } \beta_i = 0 
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(X_i\) (\(i \in \{1,2,\dots, p \}\)) ký hiệu cột thứ \(i\) của ma trận \(X\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03-02 Suy dẫn điều kiện tối ưu bậc một</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_02_derivation_of_first-order_optimality_condition/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_02_derivation_of_first-order_optimality_condition</id>
   <content type="html">&lt;p&gt;Ở Chương 04, ta từng chứng minh điều kiện tối ưu bậc nhất cho bài toán có ràng buộc \(\min_{x \in C} f(x)\) là \(\nabla f(x^\star)^T(y - x^\star) \ge 0 \; \forall y \in C\) bằng lập luận đạo hàm theo hướng trên đoạn thẳng nối \(x^\star\) và \(y\). Giờ đây, với hai công cụ cực sắc của Chương 07 là &lt;strong&gt;hàm chỉ thị \(I_C\)&lt;/strong&gt; và &lt;strong&gt;điều kiện \(0 \in \partial \tilde{f}(x^\star)\)&lt;/strong&gt;, bạn sẽ thấy toàn bộ định lý Chương 04 rơi ra tự nhiên chỉ trong &lt;strong&gt;ba dòng đại số thuần túy&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Cách nhìn này không chỉ đẹp về mặt thẩm mỹ toán học: nó còn mở đường trực tiếp sang các bài toán có ràng buộc nhưng hàm mục tiêu &lt;strong&gt;không khả vi&lt;/strong&gt; (thay \(\nabla f(x^\star)\) bằng một subgradient \(g \in \partial f(x^\star)\) thỏa \(g^T(y - x^\star) \ge 0\)!).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-bước-hợp-nhất-tối-ưu-có-ràng-buộc-vào-subgradient&quot;&gt;Kiến thức cần nhớ: Ba bước hợp nhất Tối ưu có ràng buộc vào Subgradient&lt;/h2&gt;

&lt;p&gt;Chuỗi suy dẫn trong bài học này kết nối trọn vẹn Chương 04 và Chương 07 qua ba mắt xích:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mắt xích 1 — Nhúng tập ràng buộc vào hàm mục tiêu:&lt;/strong&gt; Biến \(\min_{x \in C} f(x)\) thành bài toán không ràng buộc \(\min_{x \in \mathbb{R}^n} \big(f(x) + I_C(x)\big)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mắt xích 2 — Áp dụng điều kiện tối ưu &amp;amp; Quy tắc tổng:&lt;/strong&gt;
\(0 \in \partial(f + I_C)(x^\star) = \partial f(x^\star) + \partial I_C(x^\star) = \{\nabla f(x^\star)\} + N_C(x^\star).\)
(Điều kiện chính quy đảm bảo quy tắc tổng: \(\operatorname{dom}(f) \cap C\) thỏa điều kiện tương đối trong — luôn đúng khi \(f\) xác định trên toàn \(\mathbb{R}^n\)!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mắt xích 3 — Dịch \(-\nabla f(x^\star) \in N_C(x^\star)\) sang bất đẳng thức:&lt;/strong&gt; Theo định nghĩa nón pháp tuyến, vector \(v = -\nabla f(x^\star) \in N_C(x^\star)\) có nghĩa là:
\((-\nabla f(x^\star))^T(y - x^\star) \le 0 \iff \nabla f(x^\star)^T(y - x^\star) \ge 0 \quad \forall y \in C.\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng--nabla-fxstar-in-n_cxstar-trên-một-bài-toán-có-ràng-buộc-cụ-thể&quot;&gt;Giải thích: Kiểm chứng \(-\nabla f(x^\star) \in N_C(x^\star)\) trên một bài toán có ràng buộc cụ thể&lt;/h3&gt;

&lt;p&gt;Xét bài toán \(\min_{x \in C} \; f(x_1, x_2) = \frac{1}{2}(x_1 - 3)^2 + \frac{1}{2}(x_2 - 2)^2\) trên hình vuông \(C = [0, 1] \times [0, 1]\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Đề xuất nghiệm tối ưu \(x^\star = (1, 1)\) (góc trên–phải của hình vuông):&lt;/strong&gt;
Tính gradient tại \(x^\star = (1, 1)\):
\(\nabla f(1, 1) = (1 - 3,\; 1 - 2)^T = (-2,\; -1)^T.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tính hướng âm gradient \(-\nabla f(x^\star)\):&lt;/strong&gt;
\(-\nabla f(1, 1) = (+2,\; +1)^T.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kiểm tra xem \(-\nabla f(x^\star)\) có nằm trong Nón pháp tuyến \(N_C(1, 1)\) không:&lt;/strong&gt;
Ở bài trước ta đã tính \(N_C(1, 1) = \{(g_1, g_2) : g_1 \ge 0,\; g_2 \ge 0\} = \mathbb{R}_+^2\).
Rõ ràng \((+2, +1)^T \in \mathbb{R}_+^2 = N_C(1, 1)\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Vì \(0 = \nabla f(1, 1) + (+2, +1)^T \in \partial f(1, 1) + \partial I_C(1, 1)\), điểm \((1, 1)\) là nghiệm tối ưu toàn cục duy nhất! Nếu thử điểm \((1, 0.5)\) (cạnh phải, nơi \(N_C = \{(g_1, 0) : g_1 \ge 0\}\)), ta có \(-\nabla f(1, 0.5) = (2, 1.5)^T \notin N_C(1, 0.5)\) (vì thành phần thứ 2 khác 0!), lập tức loại ngay!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Khi \(f\) là hàm lồi và khả vi trên tập lồi \(C\), điều kiện tối ưu theo gradient dưới trùng với điều kiện tối ưu bậc một như sau.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện tối ưu bậc một:&lt;/strong&gt;
\(x^* \text{ là tối ưu} \quad \Longleftrightarrow \quad \nabla f(x^*)^T(y - x^*) \geq 0, \text{ với mọi } y \in C\)&lt;/p&gt;

&lt;h3 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h3&gt;
&lt;blockquote&gt;

\[\begin{alignat}{2}
f(x^{*}) = \min_{x\in C} f(x)  \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp; \quad f(x^{*}) = \min_x f(x) + I_C(x) \\
                      \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp;\quad 0 \in \partial(f(x^{*}) + I_C(x^{*})) \\
                      \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp;\quad 0 \in \{\nabla f(x^{*}) \} + \mathcal{N}_C(x^{*}) \\
                      \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp;\quad - \nabla f(x^{*}) \in \mathcal{N}_C(x^{*}) \\
                      \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp;\quad - \nabla f(x^{*})^Tx^{*} \geq -\nabla f(x^{*})^Ty, \text{ với mọi }  y \in C \\
                      \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp;\quad \nabla f(x^{*})^T(y-x^{*}) \geq 0, \text{ với mọi } y \in C 
\end{alignat}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03-01 Điều kiện tối ưu gradient dưới</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_01_subgradient_optimality_condition/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_03_01_subgradient_optimality_condition</id>
   <content type="html">&lt;p&gt;Rất ít định lý trong toàn bộ lịch sử toán học vừa có &lt;strong&gt;chứng minh ngắn đúng 2 dòng&lt;/strong&gt;, vừa sở hữu sức mạnh bao quát từ bài toán tìm trung vị đến huấn luyện mạng nơ-ron và máy vector hỗ trợ. &lt;strong&gt;Điều kiện tối ưu gradient dưới&lt;/strong&gt; — phát biểu rằng \(x^\star\) là cực tiểu toàn cục của \(f\) &lt;strong&gt;khi và chỉ khi&lt;/strong&gt; \(0 \in \partial f(x^\star)\) — chính là một kiệt tác như thế!&lt;/p&gt;

&lt;p&gt;Một chi tiết cực kỳ thú vị mà nhiều người đọc lướt hay bỏ qua: chứng minh của bổ đề này &lt;strong&gt;thậm chí không cần dùng đến giả thiết \(f\) là hàm lồi&lt;/strong&gt;! Tính lồi chỉ đóng vai trò đảm bảo rằng tập \(\partial f(x)\) thực sự tồn tại (khác rỗng) để ta có thể tìm thấy vector \(0\) bên trong nó.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-điểm-tinh-tế-của-điều-kiện-0-in-partial-fxstar&quot;&gt;Kiến thức cần nhớ: Ba điểm tinh tế của Điều kiện \(0 \in \partial f(x^\star)\)&lt;/h2&gt;

&lt;p&gt;Để vận dụng bổ đề này không bao giờ sai sót, hãy nắm chắc ba điểm sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sự tương đương logic 2 chiều tuyệt đối:&lt;/strong&gt;
\(x^\star \in \arg\min_x f(x) \iff f(y) \ge f(x^\star) \; \forall y \iff f(y) \ge f(x^\star) + 0^T(y - x^\star) \; \forall y \iff 0 \in \partial f(x^\star).\)
Không có bất kỳ xấp xỉ hay điều kiện bậc hai nào cần kiểm tra thêm — đây là chứng chỉ &lt;strong&gt;tối ưu toàn cục&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tác dụng của Tính Lồi:&lt;/strong&gt; Với hàm phi lồi, có thể tồn tại cực tiểu địa phương mà \(\partial f(x) = \emptyset\) (không có mặt phẳng nào đỡ được toàn bộ đồ thị phía dưới). Tính lồi đảm bảo mọi cực tiểu địa phương đều là toàn cục và có mặt phẳng đỡ ngang (\(g = 0\))!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng quát hóa trực tiếp phương trình Fermat:&lt;/strong&gt; Khi \(f\) khả vi, \(\partial f(x^\star) = \{\nabla f(x^\star)\}\), nên \(0 \in \partial f(x^\star)\) lập tức trở về \(\nabla f(x^\star) = 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-0-in-partial-fxstar-để-tìm-cực-tiểu-toàn-cục-của-hàm-bậc-hai--trị-tuyệt-đối&quot;&gt;Giải thích: Kiểm chứng \(0 \in \partial f(x^\star)\) để tìm cực tiểu toàn cục của hàm bậc hai + trị tuyệt đối&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét bài toán $$f(x) = \frac{1}{2}(x - 5)^2 + 2&lt;/td&gt;
      &lt;td&gt;x - 1&lt;/td&gt;
      &lt;td&gt;\(trên\)\mathbb{R}\(. Ta tìm điểm\)x^\star\(thỏa\)0 \in \partial f(x^\star)$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Tính $$\partial f(x) = (x - 5) + 2\partial&lt;/td&gt;
          &lt;td&gt;x - 1&lt;/td&gt;
          &lt;td&gt;$$ theo 3 trường hợp:**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu \(x &amp;gt; 1\): \(\partial f(x) = \{x - 5 + 2\} = \{x - 3\}\). Cho \(0 \in \{x - 3\} \implies x^\star = 3\) (thỏa mãn điều kiện \(3 &amp;gt; 1\)!).&lt;/li&gt;
      &lt;li&gt;Nếu \(x = 1\): \(\partial f(1) = (1 - 5) + [-2, 2] = [-6, -2]\). Không chứa \(0\)!&lt;/li&gt;
      &lt;li&gt;Nếu \(x &amp;lt; 1\): \(\partial f(x) = \{x - 5 - 2\} = \{x - 7\}\). Cho \(x - 7 = 0 \implies x = 7\) (mâu thuẫn \(x &amp;lt; 1\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Thử tăng hệ số phạt từ \(2\) lên \(5\): $$f_2(x) = \frac{1}{2}(x - 5)^2 + 5&lt;/td&gt;
          &lt;td&gt;x - 1&lt;/td&gt;
          &lt;td&gt;$$:**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(x = 1\): \(\partial f_2(1) = (1 - 5) + [-5, 5] = [-9, +1]\) — &lt;strong&gt;CHỨA \(0\)&lt;/strong&gt;!&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Vậy ngay khi lực kéo của $$&lt;/td&gt;
              &lt;td&gt;x - 1&lt;/td&gt;
              &lt;td&gt;\(vượt ngưỡng\)4\(, nghiệm tối ưu bị &quot;hút dính&quot; ngay tại điểm gãy khúc\)x^\star = 1$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bổ-đề&quot;&gt;Bổ đề&lt;/h3&gt;

&lt;p&gt;Với bất kỳ hàm \(f\) nào, điều kiện \(x^*\) là điểm cực tiểu toàn cục của \(f\) tương đương với việc vector \(0\) là một gradient dưới của \(f\) tại \(x^*\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{equation}
f(x^*) = \min_x f(x) \Longleftrightarrow 0 \in \partial f(x^*)
\end{equation}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h3&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;f(x^*) = \min_x f(x)\\
\Longleftrightarrow &amp;amp;f(y) \geq f(x^*) \text{ với mọi } y\\
\Longleftrightarrow &amp;amp;f(y) \geq f(x^*) + 0^T(y-x^*)\\
\Longleftrightarrow &amp;amp;0 \in \partial f(x^*)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Lưu ý rằng chứng minh trên không sử dụng giả thiết lồi của \(f\), vì vậy điều kiện tối ưu này đúng ngay cả với các hàm không lồi.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>07-02 Vi phân dưới (Sub-differentials)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_02_subdifferentials/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_02_subdifferentials</id>
   <content type="html">&lt;p&gt;Nếu mỗi subgradient \(g\) là một “mặt phẳng đỡ” riêng lẻ, thì việc gom tất cả các mặt phẳng đỡ hợp lệ tại cùng một điểm \(x\) lại thành một tập hợp duy nhất sinh ra khái niệm &lt;strong&gt;Vi phân dưới (Subdifferential)&lt;/strong&gt; \(\partial f(x)\). Thay vì tư duy theo một vector đơn lẻ như đạo hàm cổ điển, ta chuyển sang làm việc với một &lt;strong&gt;ánh xạ đa trị&lt;/strong&gt; (set-valued map): mỗi điểm \(x\) ứng với một tập lồi đóng \(\partial f(x) \subseteq \mathbb{R}^n\).&lt;/p&gt;

&lt;p&gt;Điều kỳ diệu là dù hàm \(f\) không hề trơn (như đa diện hay hàm chỉ thị tập lồi), tập \(\partial f(x)\) lại luôn sở hữu những tính chất hình học cực kỳ ngăn nắp: luôn &lt;strong&gt;lồi&lt;/strong&gt;, luôn &lt;strong&gt;đóng&lt;/strong&gt;, và ở mọi điểm trong của miền xác định luôn &lt;strong&gt;khác rỗng và bị chặn&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-tính-chất-của-vi-phân-dưới-partial-fx&quot;&gt;Kiến thức cần nhớ: Bốn tính chất của Vi phân dưới \(\partial f(x)\)&lt;/h2&gt;

&lt;p&gt;Hiểu rõ cấu trúc tập hợp của \(\partial f(x)\) giúp bạn xử lý mượt mà các định lý tối ưu và phép tính ở phần sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính Lồi và Đóng (Closed &amp;amp; Convex Set):&lt;/strong&gt; Tập \(\partial f(x) = \bigcap_{y \in \mathbb{R}^n} \{g \in \mathbb{R}^n : g^T(y - x) \le f(y) - f(x)\}\) là giao của vô hạn nửa không gian đóng! Vì giao của các tập lồi đóng luôn là tập lồi đóng, \(\partial f(x)\) luôn lồi và đóng — kể cả khi \(f\) không lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính Khác rỗng trên Phần trong Miền xác định:&lt;/strong&gt; Nếu \(f\) lồi và \(x \in \operatorname{int}(\operatorname{dom} f)\), thì \(\partial f(x) \neq \emptyset\) và bị chặn (nhờ định lý siêu phẳng hỗ trợ áp dụng lên tập trên đồ thị \(\operatorname{epi}(f)\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chuẩn Khả vi tương đương:&lt;/strong&gt; Hàm lồi \(f\) khả vi tại \(x\) khi và chỉ khi \(\partial f(x)\) chỉ gồm &lt;strong&gt;đúng một phần tử duy nhất&lt;/strong&gt; (singleton): \(\partial f(x) = \{\nabla f(x)\}\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Trực giác Hình học ở 2D/3D:&lt;/strong&gt; Tại điểm gãy của $$f(x_1, x_2) =&lt;/td&gt;
          &lt;td&gt;x_1&lt;/td&gt;
          &lt;td&gt;+&lt;/td&gt;
          &lt;td&gt;x_2&lt;/td&gt;
          &lt;td&gt;\(ở gốc tọa độ\)(0,0)\(,\)\partial f(0,0)\(là cả **hình vuông đặc**\)[-1, 1] \times [-1, 1]\(; còn tại điểm trên cạnh\)(2, 0)\(,\)\partial f(2,0) = {1} \times [-1, 1]$$ là một &lt;strong&gt;đoạn thẳng đứng&lt;/strong&gt;!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-xác-định-chính-xác-hình-dạng-tập-partial-fx-tại-3-vị-trí-của-fx_1-x_2--x_1--2x_2&quot;&gt;Giải thích: Xác định chính xác hình dạng tập \(\partial f(x)\) tại 3 vị trí của \(f(x_1, x_2) = |x_1| + 2|x_2|\)&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tại điểm trơn \(x^{(1)} = (3, -1)\):&lt;/strong&gt; Cả hai tọa độ đều khác 0.
\(\partial f(3, -1) = \{(+1,\; -2)\} \quad (\text{1 điểm duy nhất!}).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại điểm nằm trên cạnh gãy \(x^{(2)} = (3, 0)\):&lt;/strong&gt; \(x_1 &amp;gt; 0\) (trơn theo \(x_1\)), \(x_2 = 0\) (gãy theo \(x_2\)).
    &lt;ul&gt;
      &lt;li&gt;Thành phần 1 cố định: \(g_1 = +1\).&lt;/li&gt;
      &lt;li&gt;Thành phần 2 chạy tự do trên đoạn \(2 \cdot [-1, 1] = [-2, 2]\).
\(\partial f(3, 0) = \{(1, g_2) : -2 \le g_2 \le 2\} \quad (\text{đoạn thẳng lồi đóng}).\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại đỉnh nhọn \(x^{(3)} = (0, 0)\):&lt;/strong&gt; Cả hai tọa độ đều bằng 0.
\(\partial f(0, 0) = [-1, 1] \times [-2, 2] \quad (\text{hình chữ nhật đặc lồi đóng}).\)
Kiểm tra: \((0, 0) \in [-1, 1] \times [-2, 2] \implies (0, 0)\) là nghiệm tối ưu toàn cục!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Vi phân dưới (subdifferential) \(\partial f(x)\) của một hàm lồi \(f\) tại điểm \(x\) là tập hợp tất cả các gradient dưới của \(f\) tại \(x\):&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\partial f(x) = {g \in \mathbb{R}^n | \text{g là gradient dưới của f tại x} }
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vi phân dưới có các tính chất cơ bản sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(\partial f(x)\) luôn là một tập lồi đóng, bất kể \(f\) có lồi hay không.&lt;/li&gt;
  &lt;li&gt;Nếu \(f\) lồi, \(\partial f(x)\) luôn khác rỗng (chứa ít nhất một phần tử); nếu \(f\) không lồi, \(\partial f(x)\) có thể rỗng.&lt;/li&gt;
  &lt;li&gt;Nếu \(f\) lồi và khả vi tại \(x\), thì \(\partial f(x) = \{\nabla f(x)\}\).&lt;/li&gt;
  &lt;li&gt;Ngược lại, nếu \(\partial f(x) = \{g\}\) (chỉ gồm một phần tử duy nhất), thì \(f\) khả vi tại \(x\) và \(\nabla f(x) = g\).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-02-02 Phép tính gradient dưới</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_02_02_subgradient_calculus/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_02_02_subgradient_calculus</id>
   <content type="html">&lt;p&gt;Nếu mỗi lần gặp một hàm tổng hợp như \(f(x) = \frac{1}{2}\|Ax - b\|_2^2 + \lambda\|x\|_1 + \max(x_1, 2x_2)\) ta đều phải quay về kiểm tra định nghĩa gốc \(f(y) \ge f(x) + g^T(y - x)\) với mọi \(y\), thì việc tính toán sẽ trở thành cơn ác mộng. May mắn thay, giống hệt bảng đạo hàm trong giải tích 1, vi phân dưới sở hữu một bộ &lt;strong&gt;Phép tính Vi phân dưới (Subgradient Calculus)&lt;/strong&gt; cực kỳ gọn gàng và trực quan!&lt;/p&gt;

&lt;p&gt;Tuy nhiên, hãy chú ý một khác biệt tinh tế: trong giải tích cổ điển, đạo hàm của \(-f\) là \(-\nabla f\), nhưng trong giải tích lồi, &lt;strong&gt;quy tắc nhân hằng số chỉ đúng với hằng số DƯƠNG \(a &amp;gt; 0\)&lt;/strong&gt; (vì nhân với số âm biến hàm lồi thành hàm lõm!). Nắm vững 5 quy tắc trong bài này sẽ giúp bạn tính \(\partial f(x)\) của mọi mô hình học máy trong vài giây.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-năm-quy-tắc-vàng-của-phép-tính-vi-phân-dưới&quot;&gt;Kiến thức cần nhớ: Năm quy tắc vàng của Phép tính Vi phân dưới&lt;/h2&gt;

&lt;p&gt;Hãy ghi nhớ năm quy tắc cốt lõi sau cùng trực giác đi kèm:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc 1 — Nhân hằng số dương (Scaling):&lt;/strong&gt; Với \(a &amp;gt; 0\), \(\partial (af)(x) = a \cdot \partial f(x)\). (Không áp dụng cho \(a &amp;lt; 0\) vì \(af\) không còn lồi!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc 2 — Phép cộng (Sum Rule / Tổng Minkowski):&lt;/strong&gt; \(\partial (f_1 + f_2)(x) = \partial f_1(x) + \partial f_2(x) = \{g_1 + g_2 : g_1 \in \partial f_1(x),\; g_2 \in \partial f_2(x)\}\) (đúng dưới điều kiện giao phần trong miền xác định khác rỗng — luôn đúng khi hàm xác định trên toàn \(\mathbb{R}^n\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc 3 — Hợp thành với ánh xạ affine (Affine Composition):&lt;/strong&gt; Nếu \(h(x) = f(Ax + b)\), thì \(\partial h(x) = A^T \partial f(Ax + b)\) — hoàn toàn giống quy tắc dây chuyền (chain rule)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc 4 — Cực đại hữu hạn theo điểm (Pointwise Maximum):&lt;/strong&gt; Nếu \(f(x) = \max_{i=1,\dots,m} f_i(x)\), gọi \(I(x) = \{i : f_i(x) = f(x)\}\) là tập các hàm &lt;strong&gt;đang tích cực&lt;/strong&gt; (đạt cực đại tại \(x\)). Khi đó:
\(\partial f(x) = \operatorname{conv}\left(\bigcup_{i \in I(x)} \partial f_i(x)\right)\)
— tức là &lt;strong&gt;bao lồi&lt;/strong&gt; của tất cả các subgradient thuộc các nhánh đang đạt cực đại tại \(x\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc 5 — Cực đại tổng quát (Supremum over infinite index set):&lt;/strong&gt; Mở rộng tương tự sang \(f(x) = \sup_{s \in S} f_s(x)\) bằng bao lồi đóng của các nhánh đạt cực đại (ví dụ tìm subgradient của trị riêng lớn nhất \(\lambda_{\max}(X) = \max_{\|v\|_2=1} v^T X v\)!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-áp-dụng-đồng-thời-3-quy-tắc-để-tính-partial-fx-của-một-hàm-hợp-phức-tạp&quot;&gt;Giải thích: Áp dụng đồng thời 3 quy tắc để tính \(\partial f(x)\) của một hàm hợp phức tạp&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét hàm $$f(x) = \max(0,\; 2x - 4) + 3&lt;/td&gt;
      &lt;td&gt;x - 2&lt;/td&gt;
      &lt;td&gt;\(tại điểm gãy khúc kép\)x = 2$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tách thành tổng \(f(x) = f_1(x) + f_2(x)\) (Quy tắc 2):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f_1(x) = \max(0,\; 2x - 4)\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;$$f_2(x) = 3&lt;/td&gt;
              &lt;td&gt;x - 2&lt;/td&gt;
              &lt;td&gt;$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tính \(\partial f_1(2)\) bằng Quy tắc cực đại hữu hạn (Quy tắc 4):&lt;/strong&gt;
Tại \(x = 2\): nhánh 1 bằng \(0\) (đạo hàm \(0\)), nhánh 2 bằng \(2(2) - 4 = 0\) (đạo hàm \(2\)). Cả hai nhánh đều đạt cực đại!
\(\partial f_1(2) = \operatorname{conv}\{0,\; 2\} = [0,\; 2].\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Tính \(\partial f_2(2)\) bằng Quy tắc nhân dương + hợp thành affine (Quy tắc 1 &amp;amp; 3):&lt;/strong&gt;
Vì \(x - 2 = 0\), \(\partial |x - 2|\big|_{x=2} = [-1, 1]\). Nhân với \(3 &amp;gt; 0\):
\(\partial f_2(2) = 3 \cdot [-1, 1] = [-3,\; 3].\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — Cộng Minkowski hai đoạn đóng:&lt;/strong&gt;
\(\partial f(2) = [0, 2] + [-3, 3] = [0 + (-3),\; 2 + 3] = [-3,\; 5].\)
Kiểm tra nhanh: \(0 \in [-3, 5] \implies x^\star = 2\) là điểm cực tiểu toàn cục của \(f(x)\) (với \(f^\star = 0\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Các quy tắc cơ bản sau đây áp dụng cho vi phân dưới của các hàm lồi:&lt;/p&gt;

&lt;h3 id=&quot;nhân-với-hằng-số-dương-tỷ-lệ&quot;&gt;Nhân với hằng số dương (Tỷ lệ)&lt;/h3&gt;

&lt;blockquote&gt;

\[\eqalign{
	\text{nếu } &amp;amp; a&amp;gt;0, \\
	\text{thì } &amp;amp;\partial (af) = a\cdot \partial f
}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;phép-cộng&quot;&gt;Phép cộng&lt;/h3&gt;

&lt;blockquote&gt;

\[\partial(f_1 + f_2) = \partial f_1 + \partial f_2\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây, tổng của hai tập hợp được định nghĩa theo nghĩa tổng Minkowski: \(A+B= \{a+b:a\in A, b \in B\}\).&lt;/p&gt;

&lt;h3 id=&quot;hợp-thành-với-ánh-xạ-affine&quot;&gt;Hợp thành với ánh xạ affine&lt;/h3&gt;

&lt;blockquote&gt;

\[\eqalign{
	\text{nếu } &amp;amp; g(x)=f(Ax+b), \\
	\text{thì } &amp;amp; \partial g(x) = A^T \partial f(Ax+b)
}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;giá-trị-lớn-nhất-hữu-hạn-theo-điểm&quot;&gt;Giá trị lớn nhất hữu hạn theo điểm&lt;/h3&gt;

&lt;blockquote&gt;

\[\eqalign{
	\text{nếu } &amp;amp; f(x)=\max_{i=1,\dots,m} f_i(x), \\
	\text{thì } &amp;amp; \partial f(x) = \text{conv}\left(\bigcup_{i:f_i(x)=f(x)} \partial f_i(x)\right)
}\]
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, \(\partial f(x)\) là bao lồi của hợp các vi phân dưới của những hàm thành phần đạt giá trị lớn nhất \(f(x)\) tại điểm \(x\).&lt;/p&gt;

&lt;h3 id=&quot;giá-trị-lớn-nhất-tổng-quát-theo-điểm&quot;&gt;Giá trị lớn nhất tổng quát theo điểm&lt;/h3&gt;

&lt;blockquote&gt;
\[\eqalign{
	\text{nếu } &amp;amp; f(x) = \max_{s \in S} f_s(x),\\ 
	\text{thì } &amp;amp; \partial f(x) \supseteq cl \left \{ \text{conv} \left(\bigcup_{s:f_s(x)=f(x)} \partial f_s(x)\right) \right\}
}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì \(S\) có thể là một tập vô hạn, hợp của vô số tập hợp chưa chắc đã là tập đóng. Do đó, cần lấy bao đóng để đảm bảo tập thu được là tập đóng giống như vi phân dưới.&lt;/p&gt;

&lt;p&gt;Nếu tập \(S\) compact (đóng và bị chặn) và các hàm \(f_s\) liên tục theo \(s\), thì dấu bao hàm trở thành đẳng thức.&lt;/p&gt;

&lt;p&gt;Ví dụ, xét chuẩn \(p\) của vector \(x\) viết dưới dạng giá trị lớn nhất theo điểm:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
f(x) =  \vert  \vert x \vert  \vert _p = \max_{ \vert  \vert z \vert  \vert _q \leq 1} z^Tx, \qquad 1/p + 1/q =1
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Đặt \(f_z(x)=z^Tx\). Khi đó, mọi \(z^*\) thỏa mãn \(f(x)=f_{z^*}(x)\) đều thuộc tập \(\arg\max_{ \vert  \vert z \vert  \vert _q \leq 1} z^Tx\). Vì \(\partial f_{z^*}(x)=\{z^*\}\), hợp \(\bigcup \partial f_{z^*}(x)\) chính là tập \(\arg\max_{ \vert  \vert z \vert  \vert _q \leq 1} z^Tx\).&lt;/p&gt;

&lt;p&gt;Do \(S=\{z: \vert  \vert z \vert  \vert _q \leq 1\}\) là tập compact và \(f_z(x)=z^Tx\) tuyến tính, theo quy tắc giá trị lớn nhất tổng quát theo điểm, việc lấy bao lồi rồi lấy bao đóng của \(\bigcup \partial f_{z^*}(x)\) không bổ sung thêm phần tử nào mới. Do đó, vi phân dưới của \(f(x)\) là:&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\partial f(x) = \arg\max_{ \vert  \vert z \vert  \vert _q \leq 1} z^T x
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>07-02-01 Liên hệ với hình học tập lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_02_01_connection_to_a_convexity_geometry/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_02_01_connection_to_a_convexity_geometry</id>
   <content type="html">&lt;p&gt;Làm thế nào để biến một bài toán tối ưu &lt;strong&gt;có ràng buộc&lt;/strong&gt; \(\min_{x \in C} f(x)\) thành một bài toán &lt;strong&gt;hoàn toàn không ràng buộc&lt;/strong&gt; trên toàn không gian \(\mathbb{R}^n\) mà không mất đi bất kỳ thông tin nào? Câu trả lời kinh điển của giải tích lồi chỉ cần đúng một hàm số kỳ lạ nhưng cực kỳ lợi hại: &lt;strong&gt;hàm chỉ thị (indicator function)&lt;/strong&gt; \(I_C(x)\), nhận giá trị \(0\) nếu \(x \in C\) và nhảy vọt lên \(+\infty\) ngay khi \(x\) bước ra ngoài \(C\)!&lt;/p&gt;

&lt;p&gt;Khi viết lại bài toán thành \(\min_{x \in \mathbb{R}^n} \big(f(x) + I_C(x)\big)\), một câu hỏi tuyệt đẹp lập tức hiện ra: &lt;em&gt;vi phân dưới \(\partial I_C(x)\) của hàm chỉ thị trông như thế nào?&lt;/em&gt; Bổ đề trong bài học này chứng minh một kết nối hình học ngoạn mục: &lt;strong&gt;\(\partial I_C(x)\) chính xác là Nón pháp tuyến (Normal Cone) \(N_C(x)\) của tập lồi \(C\) tại \(x\)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-nhịp-cầu-giữa-giải-tích-subgradient-và-hình-học-tập-lồi&quot;&gt;Kiến thức cần nhớ: Nhịp cầu giữa Giải tích Subgradient và Hình học Tập lồi&lt;/h2&gt;

&lt;p&gt;Ba trụ cột dưới đây giải thích trọn vẹn sức mạnh của đẳng thức \(\partial I_C(x) = N_C(x)\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chỉ thị \(I_C(x)\) là hàm lồi mở rộng:&lt;/strong&gt; Tập trên đồ thị \(\operatorname{epi}(I_C) = C \times [0, \infty)\) là một hình trụ lồi trên đáy \(C\), nên \(I_C\) là hàm lồi khi và chỉ khi \(C\) là tập lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa Nón pháp tuyến \(N_C(x)\):&lt;/strong&gt; Tại một điểm \(x \in C\), nón pháp tuyến là tập tất cả các vector \(g\) hướng ra ngoài \(C\) sao cho \(g^T(y - x) \le 0\) với mọi \(y \in C\) (tức góc giữa \(g\) và mọi hướng đi vào \(C\) đều \(\ge 90^\circ\)):
    &lt;ul&gt;
      &lt;li&gt;Nếu \(x \in \operatorname{int}(C)\) (bên trong \(C\)): không có vector khác 0 nào vuông góc/tù với mọi hướng \(\implies N_C(x) = \{0\}\).&lt;/li&gt;
      &lt;li&gt;Nếu \(x\) nằm trên biên trơn của \(C\): \(N_C(x)\) là &lt;strong&gt;tia pháp tuyến hướng ra ngoài&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Nếu \(x\) nằm ở góc nhọn (đỉnh đa giác) của \(C\): \(N_C(x)\) là một &lt;strong&gt;hình quạt (nón) rộng&lt;/strong&gt; chứa mọi tia pháp tuyến hướng ra ngoài!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đẳng thức \(\partial I_C(x) = N_C(x)\):&lt;/strong&gt; Viết định nghĩa subgradient cho \(I_C\) tại \(x \in C\) (nơi \(I_C(x) = 0\)):
\(I_C(y) \ge 0 + g^T(y - x) \; \forall y \in \mathbb{R}^n.\)
Với \(y \notin C\), vế trái là \(+\infty\) nên luôn đúng; với \(y \in C\), vế trái là \(0\) nên điều kiện rút gọn thành \(g^T(y - x) \le 0 \; \forall y \in C\) — chính xác là định nghĩa \(g \in N_C(x)\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tường-minh-nón-pháp-tuyến-n_cx--partial-i_cx-trên-hình-vuông-đơn-vị&quot;&gt;Giải thích: Tính tường minh Nón pháp tuyến \(N_C(x) = \partial I_C(x)\) trên hình vuông đơn vị&lt;/h3&gt;

&lt;p&gt;Xét tập lồi \(C = [0, 1] \times [0, 1] \subset \mathbb{R}^2\) (hình vuông đơn vị):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tại điểm bên trong \(x = (0.5, 0.5)\):&lt;/strong&gt;
Ta có thể đi theo cả 4 hướng \((\pm 0.1, 0)\) và \((0, \pm 0.1)\) vẫn ở trong \(C\). Điều kiện \(g^T(y - x) \le 0\) ép \(g_1 = 0\) và \(g_2 = 0\).
\(\partial I_C(0.5, 0.5) = N_C(0.5, 0.5) = \{(0, 0)\}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại điểm trên cạnh phải \(x = (1, 0.5)\):&lt;/strong&gt;
Mọi \(y = (y_1, y_2) \in C\) thỏa \(y_1 - 1 \le 0\) và \(y_2 - 0.5\) có thể âm hoặc dương.
Để \(g_1(y_1 - 1) + g_2(y_2 - 0.5) \le 0 \; \forall y \in C\), bắt buộc \(g_1 \ge 0\) và \(g_2 = 0\)!
\(\partial I_C(1, 0.5) = N_C(1, 0.5) = \{(g_1, 0) : g_1 \ge 0\} \quad (\text{tia ngang chỉ sang phải}).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại đỉnh trên–phải \(x = (1, 1)\):&lt;/strong&gt;
Mọi \(y \in C\) thỏa \(y_1 - 1 \le 0\) và \(y_2 - 1 \le 0\). Do đó mọi vector có \(g_1 \ge 0\) và \(g_2 \ge 0\) đều thỏa \(g_1(y_1 - 1) + g_2(y_2 - 1) \le 0\)!
\(\partial I_C(1, 1) = N_C(1, 1) = \mathbb{R}_+^2 \quad (\text{cả góc phần tư thứ nhất!}).\)&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Đối với một tập lồi \(C \subseteq \mathbb{R}^n\), xét hàm chỉ thị \(I_C: \mathbb{R}^n \to \mathbb{R}\) được định nghĩa như sau:&lt;/p&gt;

&lt;blockquote&gt;

\[I_C(x) = I\{x \in C \} =
\begin{cases}
0               &amp;amp;\text{nếu } x \in C \\
\infty         &amp;amp;\text{nếu } x \notin C 
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;Vi phân dưới của hàm chỉ thị có ý nghĩa hình học sau:&lt;/p&gt;

&lt;h3 id=&quot;bổ-đề&quot;&gt;Bổ đề&lt;/h3&gt;
&lt;p&gt;Với mọi \(x \in C\), vi phân dưới \(\partial I_C(x)\) trùng với nón pháp tuyến \(\mathcal{N}_C(x)\) của tập \(C\) tại \(x\):&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\mathcal{N}_C(x) = {g \in \mathbb{R}^n | g^Tx \geq g^Ty \text{  với mọi  } y \in C }
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h3&gt;

&lt;p&gt;Theo định nghĩa, một gradient dưới \(g\) của \(I_C\) tại \(x\) phải thỏa mãn:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
I_C(y) \geq I_C(x) + g^T(y-x) \text{ với mọi } y
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vì \(x \in C\) nên \(I_C(x)=0\), do đó bất đẳng thức trên trở thành:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
I_C(y) \geq g^T(y-x) \text{ với mọi } y
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ta xét hai trường hợp của \(y\):&lt;/p&gt;

&lt;p&gt;Thứ nhất, với mọi \(y \in C\), ta có \(I_C(y) = 0\), nên:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
I_C(y) = 0 \geq g^T(y-x)
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Điều này tương đương với \(g^Tx \geq g^Ty\) với mọi \(y \in C\).&lt;/p&gt;

&lt;p&gt;Thứ hai, với mọi \(y \notin C\), ta có \(I_C(y) = \infty\), nên bất đẳng thức&lt;/p&gt;
&lt;blockquote&gt;

\[I_C(y)=\infty \geq g^T(y-x)\]
&lt;/blockquote&gt;

&lt;p&gt;luôn đúng với mọi vector \(g\).&lt;/p&gt;

&lt;p&gt;Kết hợp cả hai trường hợp, tập hợp tất cả các gradient dưới của \(I_C\) tại \(x \in C\) chính là:&lt;/p&gt;
&lt;blockquote&gt;

\[\{g \in \mathbb{R}^n | g^Tx \geq g^Ty \text{ với mọi } y \in C\}\]
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter07/07_02_subgrad-5.png&quot; alt=&quot;connection_to_convexity_geometry&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Nón pháp tuyến [1]&lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>07-01 Gradient dưới (Subgradient)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_01_subgradient/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_01_subgradient</id>
   <content type="html">&lt;p&gt;Trong giải tích cổ điển, định nghĩa đạo hàm dựa trên giới hạn cục bộ \(\lim_{h \to 0} \frac{f(x+h) - f(x)}{h}\): hễ độ dốc bên trái khác độ dốc bên phải, giới hạn đứt gãy và ta “chịu thua”. Nhưng với hàm lồi, ta lại nhớ đến một tính chất toàn cục tuyệt đẹp từ Chương 03: tiếp tuyến của hàm lồi khả vi luôn nằm &lt;strong&gt;hoàn toàn bên dưới&lt;/strong&gt; đồ thị hàm số: \(f(y) \ge f(x) + \nabla f(x)^T(y - x)\).&lt;/p&gt;

&lt;p&gt;Nhà toán học R. Tyrrell Rockafellar và các bậc tiền bối đã lật ngược tính chất ấy thành chính &lt;strong&gt;định nghĩa&lt;/strong&gt; của &lt;strong&gt;Gradient dưới (Subgradient)&lt;/strong&gt;: không cần giới hạn, không cần khả vi — bất kỳ vector \(g\) nào tạo ra một mặt phẳng đỡ toàn cục nằm dưới đồ thị \(f\) đi qua \((x, f(x))\) đều xứng đáng được gọi là một subgradient!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-góc-nhìn-cốt-lõi-về-subgradient&quot;&gt;Kiến thức cần nhớ: Bốn góc nhìn cốt lõi về Subgradient&lt;/h2&gt;

&lt;p&gt;Để tính thành thạo subgradient trên mọi hàm không trơn (từ \(\ell_1\), \(\ell_2\) đến hàm cực đại), hãy nắm bốn trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa toàn cục bằng bất đẳng thức tuyến tính:&lt;/strong&gt; \(g \in \mathbb{R}^n\) là subgradient của \(f\) tại \(x\) nếu \(f(y) \ge f(x) + g^T(y - x)\) với mọi \(y \in \mathbb{R}^n\). Dù định nghĩa này có thể viết cho mọi hàm, với hàm &lt;strong&gt;lồi&lt;/strong&gt; trên phần trong miền xác định, subgradient &lt;em&gt;luôn luôn tồn tại&lt;/em&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trùng khớp hoàn toàn tại điểm khả vi:&lt;/strong&gt; Nếu \(f\) lồi và khả vi tại \(x\), thì subgradient tồn tại duy nhất và bằng chính \(\nabla f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bốn ví dụ khuôn mẫu bắt buộc nhớ:&lt;/strong&gt;
    &lt;ol&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Giá trị tuyệt đối $$&lt;/td&gt;
              &lt;td&gt;x&lt;/td&gt;
              &lt;td&gt;\(:\)g = \operatorname{sign}(x)\(khi\)x \neq 0\(, và\)g \in [-1, 1]\(khi\)x = 0$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Chuẩn Euclidean \(\|x\|_2\): \(g = x / \|x\|_2\) khi \(x \neq 0\), và \(\|g\|_2 \le 1\) khi \(x = 0\).&lt;/li&gt;
      &lt;li&gt;Chuẩn \(\ell_1\) \(\|x\|_1\): từng tọa độ \(g_i = \operatorname{sign}(x_i)\) nếu \(x_i \neq 0\), và \(g_i \in [-1, 1]\) nếu \(x_i = 0\).&lt;/li&gt;
      &lt;li&gt;Hàm cực đại \(f(x) = \max(f_1(x), f_2(x))\): tại điểm giao \(f_1(x) = f_2(x)\), mọi tổ hợp lồi của \(\nabla f_1(x)\) và \(\nabla f_2(x)\) đều là subgradient!&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khác biệt lớn với Gradient — Không phải hướng giảm!&lt;/strong&gt; Một cú sốc thú vị: \(-g\) với \(g \in \partial f(x)\) &lt;strong&gt;không nhất thiết&lt;/strong&gt; là hướng làm giảm \(f(x)\) (chỉ đảm bảo làm giảm &lt;em&gt;khoảng cách tới \(x^\star\)&lt;/em&gt; với bước đủ nhỏ!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-tập-subgradient-của-hàm-cực-đại-fx--max2x---1--x--2&quot;&gt;Giải thích: Tính tay tập subgradient của hàm cực đại \(f(x) = \max(2x - 1,\; -x + 2)\)&lt;/h3&gt;

&lt;p&gt;Xét hàm lồi từng mảnh \(f(x) = \max(f_1(x), f_2(x))\) với \(f_1(x) = 2x - 1\) (độ dốc \(2\)) và \(f_2(x) = -x + 2\) (độ dốc \(-1\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tìm điểm gãy khúc (nơi hai đường thẳng cắt nhau):&lt;/strong&gt;
\(2x - 1 = -x + 2 \iff 3x = 3 \implies x = 1.\)
Tại \(x = 1\), ta có \(f(1) = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tính subgradient tại 3 vùng:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Khi \(x &amp;gt; 1\): \(f(x) = 2x - 1\) khả vi \(\implies\) subgradient duy nhất \(g = 2\).&lt;/li&gt;
      &lt;li&gt;Khi \(x &amp;lt; 1\): \(f(x) = -x + 2\) khả vi \(\implies\) subgradient duy nhất \(g = -1\).&lt;/li&gt;
      &lt;li&gt;Tại điểm gãy khúc \(x = 1\): mọi tổ hợp lồi \(\theta(2) + (1-\theta)(-1)\) với \(\theta \in [0, 1]\), tức mọi \(g \in [-1, 2]\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kiểm chứng bằng số với \(g = 0.5 \in [-1, 2]\) tại \(x = 1\):&lt;/strong&gt;
Đường thẳng đỡ là \(L(y) = f(1) + 0.5(y - 1) = 1 + 0.5(y - 1)\).
    &lt;ul&gt;
      &lt;li&gt;Thử \(y = 3\): \(f(3) = \max(5, -1) = 5 \ge L(3) = 2\) (đúng!).&lt;/li&gt;
      &lt;li&gt;Thử \(y = -1\): \(f(-1) = \max(-3, 3) = 3 \ge L(-1) = 0\) (đúng!).&lt;/li&gt;
      &lt;li&gt;Thử \(g = 0 \in [-1, 2]\): vì \(0\) nằm trong \([-1, 2]\), ta biết ngay \(x^\star = 1\) là điểm cực tiểu toàn cục với \(f^\star = 1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;gradient-dưới-subgradient&quot;&gt;Gradient dưới (Subgradient)&lt;/h1&gt;

&lt;p&gt;Đối với một hàm lồi \(f:\mathbb{R}^n \to \mathbb{R}\), gradient dưới (subgradient) của \(f\) tại điểm \(x\) là bất kỳ vector \(g \in \mathbb{R}^n\) nào thỏa mãn:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{equation}\label{subgradient}
f(y) \geq f(x) + g^T(y-x), \text{ với mọi } y
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ định nghĩa trên, ta có một số nhận xét cơ bản về gradient dưới:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Đây là sự tổng quát hóa của gradient cho các hàm lồi trong trường hợp hàm không khả vi.&lt;/li&gt;
  &lt;li&gt;Với mọi hàm lồi, gradient dưới luôn tồn tại. Nếu \(f\) khả vi tại \(x\), thì \(\nabla f(x)\) là gradient dưới duy nhất tại điểm đó.&lt;/li&gt;
  &lt;li&gt;Với hàm không lồi, gradient dưới vẫn có thể được định nghĩa theo cùng bất đẳng thức trên, nhưng có thể không tồn tại tùy thuộc vào từng hàm cụ thể.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dưới đây là một số ví dụ về gradient dưới của các hàm thường gặp.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-1&quot;&gt;Ví dụ 1&lt;/h3&gt;

&lt;center&gt;
$$f:\mathbb{R} \to \mathbb{R}, f(x) =  \vert x \vert $$
&lt;/center&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter07/07_01_subgrad-1.png&quot; alt=&quot;Subgradient1&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Hình 1] Gradient dưới của } f(x)= \vert x \vert \text{ [3]}$$&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Với \(x \neq 0\), bất đẳng thức \(\vert y \vert \geq \vert x \vert + g^T(y-x)\) phải đúng với mọi \(y\), tương đương với \(\vert y \vert - g^Ty \geq \vert x \vert - g^Tx\). Khi \(\vert x \vert - g^Tx = 0\), tức là \(g=\text{sign}(x)\), bất đẳng thức này luôn thỏa mãn với mọi \(y\). Do đó, \(g=\text{sign}(x)\) (&lt;a href=&quot;https://en.wikipedia.org/wiki/Sign_function&quot;&gt;Wikipedia: Hàm dấu&lt;/a&gt;).&lt;/li&gt;
  &lt;li&gt;Với \(x=0\), điều kiện trở thành \(\vert y \vert \geq g^Ty\) với mọi \(y\), suy ra \(g \in [-1,1]\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-2&quot;&gt;Ví dụ 2&lt;/h3&gt;

&lt;center&gt;
$$f:\mathbb{R}^n \to \mathbb{R}, f(x) =  \| x \|_1$$ 
&lt;/center&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter07/07_01_subgrad-3.png&quot; alt=&quot;Subgradient2&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Hình 2] Gradient dưới của }f(x)= \| x \|_1\text{ [3]}$$&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Tại điểm \(x=(x_1,x_2,\dots,x_n)\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Với \(x_i \neq 0, i \in \{1,2,\dots,n\}\), vì hàm khả vi theo tọa độ \(x_i\), ta có \(g_i=\text{sign}(x_i)\).&lt;/li&gt;
  &lt;li&gt;Với \(x_i=0, i \in \{1,2,\dots,n\}\), ta có \(g_i \in [-1,1]\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-3&quot;&gt;Ví dụ 3&lt;/h3&gt;

&lt;center&gt;
$$f:\mathbb{R}^n \to \mathbb{R}, f(x) =  \vert x \vert _2$$
&lt;/center&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter07/07_01_subgrad-2.png&quot; alt=&quot;Subgradient3&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Hình 3] Gradient dưới của }f(x)= \vert x \vert _2\text{ [3]}$$&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Với \(x \neq 0\), hàm khả vi nên ta có \(g=\nabla \sqrt{x^Tx} = \frac{1}{2}(x^Tx)^{-\frac{1}{2}} (2x) = \frac{x}{\vert x \vert _2}\).&lt;/li&gt;
  &lt;li&gt;Với \(x=0\), điều kiện là \(\vert y \vert _2 \geq g^Ty \Longrightarrow  \vert y \vert _2 \geq  \vert g \vert _2 \vert y \vert _2 \cos \theta\) với mọi \(y\). Do đó, \(g \in \{z: \vert z \vert _2 \leq 1 \}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-4&quot;&gt;Ví dụ 4&lt;/h3&gt;

&lt;p&gt;Xét \(f(x) = \max f_1(x),f_2(x)\), trong đó \(f_1,f_2:\mathbb{R}^n \to \mathbb{R}\) đều là các hàm lồi và khả vi.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter07/07_01_subgrad-4.png&quot; alt=&quot;Subgradient4&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Hình 4] Gradient dưới của }f(x)=\max f_1(x),f_2(x) \text{ [3]}$$&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Với \(f_1(x) &amp;gt; f_2(x)\), ta có \(g = \nabla f_1(x)\).&lt;/li&gt;
  &lt;li&gt;Với \(f_1(x) &amp;lt; f_2(x)\), ta có \(g = \nabla f_2(x)\).&lt;/li&gt;
  &lt;li&gt;Với \(f_1(x) = f_2(x)\), ta có \(g \in \{\theta_1 \nabla f_1(x) + \theta_2 \nabla f_2(x): \theta_1 + \theta_2 = 1, \theta_1 \geq 0, \theta_2 \geq 0 \}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;gradient-dưới-tại-điểm-gấp-khúc&quot;&gt;Gradient dưới tại điểm gấp khúc&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/subgradient-fan_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Tại điểm gấp khúc của \(f(x)=\max_i f_i(x)\), có nhiều đường thẳng nằm dưới đồ thị và tiếp xúc với đồ thị tại điểm đó; hệ số góc của mỗi đường thẳng như vậy đều là một gradient dưới.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-gradient-dưới-tại-điểm-gấp-khúc&quot;&gt;Tự tay thử: gradient dưới tại điểm gấp khúc&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;subg&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>07 Gradient dưới (Subgradient)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_00_subgradient/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter07/07_00_subgradient</id>
   <content type="html">&lt;p&gt;Suốt Chương 06, Gradient Descent vận hành trơn tru như một cỗ máy đồng hồ Thụy Sĩ — nhưng nó đòi hỏi một điều kiện tiên quyết khắt khe: &lt;strong&gt;hàm mục tiêu phải khả vi ở mọi nơi&lt;/strong&gt;. Vậy điều gì xảy ra ngay khi ta chạm vào những bài toán thực tế hấp dẫn nhất của khoa học dữ liệu như &lt;strong&gt;Lasso&lt;/strong&gt; (\(\|w\|_1\) có góc nhọn tại \(0\)), &lt;strong&gt;SVM&lt;/strong&gt; (hàm mất mát bản lề \(\max(0, 1 - y_i w^T x_i)\) gãy khúc tại \(1\)), hay hàm cực đại \(\max_i f_i(x)\)? Đạo hàm cổ điển biến mất đúng tại điểm tối ưu quan trọng nhất!&lt;/p&gt;

&lt;p&gt;Chương 07 mở ra giải pháp thiên tài của giải tích lồi không trơn: &lt;strong&gt;Gradient dưới (Subgradient)&lt;/strong&gt; và &lt;strong&gt;Vi phân dưới (Subdifferential)&lt;/strong&gt;. Thay vì bất lực trước các điểm gãy khúc, ta nhận ra tại mỗi góc nhọn của hàm lồi không chỉ có một tiếp tuyến duy nhất, mà có cả một &lt;strong&gt;chùm siêu phẳng đỡ phía dưới&lt;/strong&gt; — và chỉ cần vector \(0\) nằm trong chùm đó, ta lập tức có chứng chỉ tối ưu toàn cục!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-kiến-trúc-của-giải-tích-lồi-không-trơn-chương-07&quot;&gt;Kiến thức cần nhớ: Kiến trúc của Giải tích Lồi Không Trơn (Chương 07)&lt;/h2&gt;

&lt;p&gt;Toàn bộ 15 bài học trong Chương 07 xây dựng trên bốn trụ cột mạch lạc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tổng quát hóa Gradient (Subgradient \(g\)):&lt;/strong&gt; Mọi vector \(g\) thỏa bất đẳng thức đỡ toàn cục \(f(y) \ge f(x) + g^T(y - x) \; \forall y\) đều là một subgradient tại \(x\). Tại điểm khả vi, \(g = \nabla f(x)\) là duy nhất; tại điểm gãy khúc, có vô số \(g\) hợp thành tập lồi đóng \(\partial f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối Hình học (Hàm chỉ thị &amp;amp; Nón pháp tuyến):&lt;/strong&gt; Vi phân dưới của hàm chỉ thị \(I_C(x)\) (bằng \(0\) trong tập lồi \(C\), bằng \(+\infty\) ngoài \(C\)) chính xác là &lt;strong&gt;nón pháp tuyến&lt;/strong&gt; \(N_C(x)\) — giúp hợp nhất tối ưu &lt;em&gt;có ràng buộc&lt;/em&gt; và &lt;em&gt;không ràng buộc&lt;/em&gt; vào chung một công thức duy nhất!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép tính Vi phân dưới (Subgradient Calculus):&lt;/strong&gt; Tương tự quy tắc đạo hàm tổng, nhân hằng số dương, hợp thành affine và hàm cực đại \(\max_i f_i(x)\) (bao lồi các subgradient của những hàm đang đạt cực đại).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện tối ưu \(0 \in \partial f(x^\star)\) &amp;amp; Ứng dụng kinh điển:&lt;/strong&gt; Công thức cực gọn \(0 \in \partial f(x^\star)\) lập tức suy ra điều kiện tối ưu bậc nhất của Chương 04, công thức tối ưu Lasso, phép toán &lt;strong&gt;Ngưỡng mềm (Soft-Thresholding)&lt;/strong&gt; và đạo hàm hàm khoảng cách đến tập lồi!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-khám-phá-trực-giác-subgradient-tại-điểm-gãy-khúc-của-fx--x&quot;&gt;Giải thích: Khám phá trực giác Subgradient tại điểm gãy khúc của \(f(x) = |x|\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét hàm lồi không khả vi nổi tiếng nhất: $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(tại điểm gãy khúc\)x = 0$$ (nơi đạo hàm cổ điển không tồn tại).&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện đỡ toàn cục tại \(x = 0\):&lt;/strong&gt; Ta cần tìm mọi số thực \(g \in \mathbb{R}\) sao cho
\(|y| \ge |0| + g(y - 0) \iff |y| \ge g \cdot y \quad \forall y \in \mathbb{R}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử giá trị cụ thể:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Chọn \(g = 0.5\): với \(y = 2\), $$&lt;/td&gt;
              &lt;td&gt;2&lt;/td&gt;
              &lt;td&gt;= 2 \ge 1\((đúng); với\)y = -2\(,\)&lt;/td&gt;
              &lt;td&gt;-2&lt;/td&gt;
              &lt;td&gt;= 2 \ge -1\((đúng!). Vậy\)g = 0.5$$ là một subgradient!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Chọn \(g = 0\): $$&lt;/td&gt;
              &lt;td&gt;y&lt;/td&gt;
              &lt;td&gt;\ge 0\(luôn đúng với mọi\)y\(! Vậy\)0 \in \partial f(0)\(— chứng nhận ngay\)x^\star = 0$$ là cực tiểu toàn cục!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Chọn \(g = 1.5\): thử \(y = 1\) cho $$&lt;/td&gt;
              &lt;td&gt;1&lt;/td&gt;
              &lt;td&gt;= 1 &amp;lt; 1.5$$ (sai!).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Tập tất cả các subgradient tại \(x = 0\) là cả đoạn đóng $$\partial&lt;/td&gt;
          &lt;td&gt;0&lt;/td&gt;
          &lt;td&gt;= [-1, 1]\(— mọi đường thẳng đi qua gốc tọa độ có độ dốc nằm giữa\)-1\(và\)+1$$ đều nâng đỡ hoàn toàn chữ V phía trên nó!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong chương này, chúng ta giới thiệu khái niệm gradient dưới (subgradient) và điều kiện tối ưu theo gradient dưới — sự tổng quát hóa của gradient và điều kiện tối ưu bậc một đã trình bày ở các chương trước. Đồng thời, chúng ta cũng sẽ xem xét một số ứng dụng và ví dụ minh họa cho các khái niệm này.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-hiện-đại-20222026&quot;&gt;Ứng dụng hiện đại (2022–2026)&lt;/h2&gt;

&lt;p&gt;Bài đọc tùy chọn đi kèm liên hệ trực tiếp các khái niệm vi phân dưới trong chương này với những quy trình khoa học máy tính và khoa học dữ liệu gần đây — bao gồm vi phân tự động cho mạng ReLU, đường chính quy hóa Lasso trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skglm&lt;/code&gt;, cũng như hồi quy phân vị với hàm mất mát pinball và dự báo conformal — trong khi vẫn giữ nguyên nền tảng lý thuyết. Xem &lt;a href=&quot;/contents/vi/chapter07/07_08_modern_applications/&quot;&gt;07-08 Ứng dụng hiện đại của subgradient&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>07-10 Practical Exercises - Subgradient Optimization</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_10_Practical_Exercises_Subgradient_Optimization/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_10_Practical_Exercises_Subgradient_Optimization</id>
   <content type="html">&lt;p&gt;Subgradient calculus only becomes second nature once you have computed subdifferentials of norms, piecewise maxima, and indicator functions with your own hands—and used \(0 \in \partial f(x^\star)\) to solve Lasso and constrained problems directly. These practical exercises build that exact hands-on command, preparing you for subgradient and proximal algorithms in the next chapters.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-problem-solving-playbook-for-subgradient-exercises&quot;&gt;Key ideas: Problem-Solving Playbook for Subgradient Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify Kinks vs. Smooth Regions First&lt;/strong&gt;: Before differentiating, locate every point where an absolute value hits zero, a norm hits zero, or two branches of a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;max&lt;/code&gt; tie. On smooth regions, \(\partial f(x) = \{\nabla f(x)\}\); at kinks, apply the calculus rules.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Use the Dual-Norm Formula for Any Norm \(\|x\|\)&lt;/strong&gt;: At \(x = 0\), \(\partial \|0\| = \{g : \|g\|_* \le 1\}\); at \(x \neq 0\), \(\partial \|x\| = \{g : \|g\|_* \le 1 \text{ and } g^T x = \|x\|\}\). (For \(\ell_2\), dual is \(\ell_2\); for \(\ell_1\), dual is \(\ell_\infty\); for \(\ell_\infty\), dual is \(\ell_1\).)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check Optimality by Case-Splitting Sign Regimes&lt;/strong&gt;: For \(\ell_1\)-regularized or piecewise objectives, test whether \(0 \in \partial f(x)\) at each kink first; if not, solve the smooth equation on the region where the sign of the subdifferential crosses zero.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify Subgradient Descent Step Sizes&lt;/strong&gt;: Unlike smooth gradient descent, subgradient descent \(x^{(k+1)} = x^{(k)} - t_k g^{(k)}\) is &lt;em&gt;not&lt;/em&gt; guaranteed to decrease \(f\) at every step—keep track of the best iterate \(f_{\mathrm{best}}^{(k)} = \min_{i \le k} f(x^{(i)})\) and use diminishing step sizes (e.g., \(t_k = c/\sqrt{k}\)).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-warm-up-subgradient-computation--optimality-test&quot;&gt;Worked example: Warm-Up Subgradient Computation &amp;amp; Optimality Test&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = \|x\|_1 + \frac{1}{2}\|x - a\|_2^2\) where \(a = (0.5,\; -2.0)^T\), and verify optimality directly via \(0 \in \partial f(x^\star)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Apply coordinate-wise soft-thresholding with \(\lambda = 1\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Coordinate 1: $$&lt;/td&gt;
              &lt;td&gt;a_1&lt;/td&gt;
              &lt;td&gt;= 0.5 \le 1 \implies x_1^\star = 0$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Coordinate 2: \(a_2 = -2.0 &amp;lt; -1 \implies x_2^\star = -2.0 + 1 = -1.0\).&lt;/li&gt;
      &lt;li&gt;Candidate: \(x^\star = (0,\; -1)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(\partial f(x^\star)\) explicitly&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Gradient of quadratic part: \(x^\star - a = (0 - 0.5,\; -1 - (-2.0))^T = (-0.5,\; +1.0)^T\).&lt;/li&gt;
      &lt;li&gt;Subdifferential of \(\|x\|_1\) at \((0, -1)^T\): \([-1, 1] \times \{-1\}\).&lt;/li&gt;
      &lt;li&gt;Minkowski sum: \(\partial f(x^\star) = ([-1, 1] - 0.5) \times \{-1 + 1\} = [-1.5,\; 0.5] \times \{0\}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Confirm \(0 \in \partial f(x^\star)\)&lt;/strong&gt;: Since \(0 \in [-1.5, 0.5]\) and \(0 \in \{0\}\), \((0, 0)^T \in \partial f(x^\star)\), certifying \(x^\star = (0, -1)^T\) as the unique global minimizer!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---subgradient-optimization&quot;&gt;Practical Exercises - Subgradient Optimization&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd &amp;amp; Vandenberghe (2004) and Shor (1985).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-i-computing-subgradients&quot;&gt;📝 &lt;strong&gt;Part I: Computing Subgradients&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-1-subgradients-of-non-differentiable-functions&quot;&gt;&lt;strong&gt;Exercise 1: Subgradients of Non-differentiable Functions&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Compute the subgradients of the following functions at the given points:&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;a)&lt;/strong&gt; $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(at\)x = 0$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;b)&lt;/strong&gt; \(f(x) = \max\{x_1, x_2\}\) at \(x = (1, 1)^T\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;c)&lt;/strong&gt; \(f(x) = \|x\|_1\) at \(x = (0, 0)^T\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;d)&lt;/strong&gt; \(f(x) = \max\{x_1 + x_2, 2x_1 - x_2\}\) at \(x = (1, 0)^T\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) $$f(x) = |x|$$ at $$x = 0$$:**

**Definition:** $$g \in \partial f(0)$$ if

$$f(y) \geq f(0) + g(y - 0)$$ $$\forall y$$

$$|y| \geq 0 + gy \quad \forall y$$

- For $$y &amp;gt; 0$$: $$y \geq gy$$ → $$g \leq 1$$
- For $$y &amp;lt; 0$$: $$-y \geq gy$$ → $$g \geq -1$$

$$\partial f(0) = [-1, 1]$$

**Geometric interpretation:** the set of all slopes of the supporting lines at $$x = 0$$.

---

**b) $$f(x) = \max\{x_1, x_2\}$$ at $$x = (1, 1)$$:**

$$f(1, 1) = 1$$ (both are active)

**Active set:** $$I = \{1, 2\}$$

$$\partial f(x) = \text{conv}\{\nabla f_i(x) : i \in I\}$$

$$= \text{conv}\{(1, 0), (0, 1)\}$$

$$= \{(\lambda, 1-\lambda) : 0 \leq \lambda \leq 1\}$$

**Geometry:** the line segment joining $$(1, 0)$$ and $$(0, 1)$$.

---

**c) $$f(x) = \|x\|_1 = |x_1| + |x_2|$$ at $$x = (0, 0)$$:**

$$\partial f(0) = \partial |x_1| \times \partial |x_2|$$

$$= [-1, 1] \times [-1, 1]$$

$$= \{(g_1, g_2) : |g_1| \leq 1, |g_2| \leq 1\}$$

**Geometry:** the square $$[-1, 1]^2$$.

---

**d) $$f(x) = \max\{x_1 + x_2, 2x_1 - x_2\}$$ at $$x = (1, 0)$$:**

$$f_1(1, 0) = 1 + 0 = 1$$

$$f_2(1, 0) = 2 - 0 = 2$$

$$\Rightarrow f(1, 0) = 2$$ (only $$f_2$$ is active)

$$\nabla f_2 = (2, -1)$$

$$\partial f(1, 0) = \{(2, -1)\}$$ (a singleton because only one function is active)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-ii-the-subgradient-method&quot;&gt;📝 &lt;strong&gt;Part II: The Subgradient Method&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-2-convergence-analysis&quot;&gt;&lt;strong&gt;Exercise 2: Convergence Analysis&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Cho $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 2&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x + 1&lt;/td&gt;
      &lt;td&gt;$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Find \(x^*\) (the minimizer)&lt;br /&gt;
b) With step size \(\alpha_k = \frac{1}{\sqrt{k}}\), iterate from \(x^{(0)} = 5\)&lt;br /&gt;
c) Compute \(x^{(1)}, x^{(2)}, x^{(3)}\)&lt;br /&gt;
d) Estimate the convergence rate&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Find $$x^*$$:**

$$f(x) = |x - 2| + |x + 1|$$

**Case analysis:**
- $$x &amp;lt; -1$$: $$f(x) = -(x-2) - (x+1) = -2x + 1$$ (decreasing)
- $$-1 \leq x \leq 2$$: $$f(x) = -(x-2) + (x+1) = 3$$ (constant!)
- $$x &amp;gt; 2$$: $$f(x) = (x-2) + (x+1) = 2x - 1$$ (increasing)

$$f^* = 3$$, $$x^* \in [-1, 2]$$

---

**b) Subgradient method:**

$$x^{(k+1)} = x^{(k)} - \alpha_k g^{(k)}$$

with $$g^{(k)} \in \partial f(x^{(k)})$$.

---

**c) Iterations:**

$$x^{(0)} = 5 &amp;gt; 2$$

$$\partial f(5) = \{\text{sign}(5-2)\} + \{\text{sign}(5+1)\} = \{1\} + \{1\} = \{2\}$$

$$g^{(0)} = 2$$

$$\alpha_0 = \frac{1}{\sqrt{1}} = 1$$

$$x^{(1)} = 5 - 1 \cdot 2 = 3$$

---

$$x^{(1)} = 3 &amp;gt; 2$$

$$g^{(1)} = 2$$

$$\alpha_1 = \frac{1}{\sqrt{2}} \approx 0.707$$

$$x^{(2)} = 3 - 0.707 \cdot 2 = 1.586$$

---

$$x^{(2)} = 1.586 \in [-1, 2]$$ (optimal region!)

$$\partial f(1.586) = \{\text{sign}(1.586 - 2) + \text{sign}(1.586 + 1)\} = \{-1 + 1\} = \{0\}$$ (on $$(-1, 2)$$, $$f$$ is constant, hence differentiable with gradient 0)

$$g^{(2)} = 0 \Rightarrow x^{(3)} = x^{(2)} = 1.586$$ (already converged to the optimal set)

---

**d) Convergence rate:**

With $$\alpha_k = \frac{1}{\sqrt{k}}$$:

$$f(x_{\text{best}}^{(k)}) - f^* \leq \frac{R^2 + G^2 \sum_{i=1}^k \alpha_i^2}{2\sum_{i=1}^k \alpha_i}$$

$$\sum_{i=1}^k \frac{1}{\sqrt{i}} \approx 2\sqrt{k}$$

$$\sum_{i=1}^k \frac{1}{i} \approx \log k$$

$$\Rightarrow O\left(\frac{\log k}{\sqrt{k}}\right) = O\left(\frac{1}{\sqrt{k}}\right)$$

**Sublinear convergence** (slower than gradient descent!)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iii-step-size-rules&quot;&gt;📝 &lt;strong&gt;Part III: Step Size Rules&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-3-comparing-step-size-strategies&quot;&gt;&lt;strong&gt;Exercise 3: Comparing Step Size Strategies&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho \(f(x) = \max\{x_1, x_2, -x_1 - x_2 + 1\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Find \(x^*\) graphically&lt;br /&gt;
b) Compare 3 step size rules:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Constant: \(\alpha_k = 0.1\)&lt;/li&gt;
  &lt;li&gt;Diminishing: \(\alpha_k = \frac{1}{k}\)&lt;/li&gt;
  &lt;li&gt;Square summable: \(\alpha_k = \frac{1}{k^{0.6}}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Graphical solution:**

$$f(x) = \max\{x_1, x_2, 1 - x_1 - x_2\}$$

**Intersection points:**
- $$x_1 = x_2$$: Line $$x_1 = x_2$$
- $$x_1 = 1 - x_1 - x_2$$: $$2x_1 + x_2 = 1$$
- $$x_2 = 1 - x_1 - x_2$$: $$x_1 + 2x_2 = 1$$

Solve the system $$x_1 = x_2$$ and $$2x_1 + x_2 = 1$$:

$$3x_1 = 1 \Rightarrow x_1 = \frac{1}{3}$$

$$x^* = \left(\frac{1}{3}, \frac{1}{3}\right)$$, $$f^* = \frac{1}{3}$$

---

**b) Step size comparison:**

**From $$x^{(0)} = (1, 1)$$:**

$$f_1 = 1$$, $$f_2 = 1$$, $$f_3 = -1$$ → the max is $$f_1, f_2$$ (tie)

$$\partial f(1, 1) = \text{conv}\{(1, 0), (0, 1)\}$$

Choose $$g = (0.5, 0.5)$$ (the midpoint)

---

**Constant $$\alpha_k = 0.1$$:**

$$x^{(1)} = (1, 1) - 0.1(0.5, 0.5) = (0.95, 0.95)$$

$$x^{(2)} = (0.90, 0.90)$$

$$x^{(3)} = (0.85, 0.85)$$

...

**Converges to a neighborhood of $$x^*$$ (radius $$O(\alpha)$$), but does not reach it exactly.**

---

**Diminishing $$\alpha_k = \frac{1}{k}$$:**

$$x^{(1)} = (1, 1) - 1 \cdot (0.5, 0.5) = (0.5, 0.5)$$

$$x^{(2)} = (0.5, 0.5) - 0.5 \cdot (0.5, 0.5) = (0.25, 0.25)$$ (with $$g^{(1)} = (0.5, 0.5)$$)

At $$(0.25, 0.25)$$: $$f_3 = 0.5$$ is the largest, $$g^{(2)} = (-1, -1)$$, so $$x^{(3)} = (0.25, 0.25) + \frac{1}{3}(1, 1) \approx (0.583, 0.583)$$ (the iterates oscillate around $$x^*$$ with decreasing amplitude).

...

**Converges to $$x^*$$, but very slowly (bound $$O(1/\log k)$$ since $$\sum_{i \le k} 1/i \approx \log k$$).**

---

**Square summable $$\alpha_k = \frac{1}{k^{0.6}}$$:**

$$\sum \alpha_k = \sum \frac{1}{k^{0.6}} = \infty$$ ✓

$$\sum \alpha_k^2 = \sum \frac{1}{k^{1.2}} &amp;lt; \infty$$ ✓

**Converges to $$x^*$$ with bound $$O(1/k^{0.4})$$ (since $$\sum_{i \le k} \alpha_i \sim k^{0.4}$$), faster than $$\alpha_k = 1/k$$ but still sublinear.**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iv-polyak-step-size&quot;&gt;📝 &lt;strong&gt;Part IV: Polyak Step Size&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-4-polyaks-step-size-for-ell_1-minimization&quot;&gt;&lt;strong&gt;Exercise 4: Polyak’s Step Size for \(\ell_1\) Minimization&lt;/strong&gt;&lt;/h3&gt;

\[\min_{x} \|x\|_1 \quad \text{s.t.} \quad Ax = b\]

&lt;p&gt;with \(A = [1, 2, 3]\), \(b = 6\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the Lagrangian&lt;br /&gt;
b) Find the dual function&lt;br /&gt;
c) Maximize the dual by subgradient method with Polyak step size&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Lagrangian:**

$$L(x, \nu) = \|x\|_1 + \nu^T(Ax - b)$$

$$= \sum_i (|x_i| + \nu a_i x_i) - \nu b$$

---

**b) Dual function:**

$$g(\nu) = \inf_x L(x, \nu)$$

$$= \inf_x \sum_i (|x_i| + \nu a_i x_i) - \nu b$$

Minimize over each $$x_i$$ independently:

$$\inf_{x_i} (|x_i| + \nu a_i x_i) = \begin{cases}
0 &amp;amp; \text{if } |\nu a_i| \leq 1 \\
-\infty &amp;amp; \text{otherwise}
\end{cases}$$

$$g(\nu) = \begin{cases}
-\nu b &amp;amp; \text{if } |\nu a_i| \leq 1 \, \forall i \\
-\infty &amp;amp; \text{otherwise}
\end{cases}$$

With $$A = [1, 2, 3]$$:

$$|\nu| \leq 1, \quad |2\nu| \leq 1, \quad |3\nu| \leq 1$$

$$\Rightarrow |\nu| \leq \frac{1}{3}$$

$$g(\nu) = -6\nu$$ for $$|\nu| \leq \frac{1}{3}$$

---

**c) Dual maximization:**

$$\max_{\nu} \quad -6\nu \quad \text{s.t.} \quad -\frac{1}{3} \leq \nu \leq \frac{1}{3}$$

**Obvious:** $$\nu^* = -\frac{1}{3}$$, $$g^* = 2$$

**Subgradient of $$g(\nu) = -6\nu$$:** $$s = -6$$ (since we maximize the concave function $$g$$, we use subgradient ascent).

**Polyak step size** (knowing $$g^* = 2$$):

$$\alpha_k = \frac{g^* - g(\nu^{(k)})}{\|s^{(k)}\|^2}, \qquad \nu^{(k+1)} = \Pi_{[-1/3,\,1/3]}\left(\nu^{(k)} + \alpha_k s^{(k)}\right)$$

From $$\nu^{(0)} = 0$$: $$g(0) = 0$$

$$\alpha_0 = \frac{2 - 0}{36} = \frac{1}{18}$$

$$\nu^{(1)} = 0 + \frac{1}{18} \cdot (-6) = -\frac{1}{3}$$ ✓ (inside the domain)

**Converged in 1 step!** ($$g(-1/3) = 2 = g^*$$, and the primal solution is $$x^* = (0, 0, 2)$$ with $$\|x^*\|_1 = 2$$.)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-v-projected-subgradient&quot;&gt;📝 &lt;strong&gt;Part V: Projected Subgradient&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-5-projected-subgradient-for-constrained-optimization&quot;&gt;&lt;strong&gt;Exercise 5: Projected Subgradient for Constrained Optimization&lt;/strong&gt;&lt;/h3&gt;

\[\min_{x} \|x - c\|_1 \quad \text{s.t.} \quad \|x\|_2 \leq R\]

&lt;p&gt;with \(c = (2, 3)^T\), \(R = 2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the projected subgradient update&lt;br /&gt;
b) Iterate from \(x^{(0)} = (0, 0)\)&lt;br /&gt;
c) Find the exact solution&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Projected subgradient:**

$$x^{(k+1)} = \Pi_C\left(x^{(k)} - \alpha_k g^{(k)}\right)$$

with $$C = \{x : \|x\|_2 \leq R\}$$, $$g^{(k)} \in \partial f(x^{(k)})$$.

**Projection onto $$\ell_2$$ ball:**

$$\Pi_C(y) = \begin{cases}
y &amp;amp; \text{if } \|y\| \leq R \\
R \frac{y}{\|y\|} &amp;amp; \text{if } \|y\| &amp;gt; R
\end{cases}$$

---

**b) Iterations:**

$$x^{(0)} = (0, 0)$$

$$\partial f(0, 0) = \partial \|(0, 0) - (2, 3)\|_1 = \partial(|{-2}| + |{-3}|)$$

Subgradient: $$g = \text{sign}(x - c) = (-1, -1)$$

Choose $$\alpha_0 = 1$$:

$$\tilde{x}^{(1)} = (0, 0) - 1 \cdot (-1, -1) = (1, 1)$$

$$\|\tilde{x}^{(1)}\| = \sqrt{2} &amp;lt; 2$$ → no projection needed

$$x^{(1)} = (1, 1)$$

---

$$g^{(1)} = \text{sign}((1, 1) - (2, 3)) = (-1, -1)$$

$$\tilde{x}^{(2)} = (1, 1) + (1, 1) = (2, 2)$$

$$\|\tilde{x}^{(2)}\| = 2\sqrt{2} &amp;gt; 2$$ → project!

$$x^{(2)} = 2 \cdot \frac{(2, 2)}{2\sqrt{2}} = \frac{2}{\sqrt{2}}(1, 1) = (\sqrt{2}, \sqrt{2})$$

---

**c) Exact solution:**

Minimize $$\|x - c\|_1$$ over $$\|x\| \leq 2$$.

**Unconstrained optimum:** $$x = c = (2, 3)$$

$$\|c\| = \sqrt{13} &amp;gt; 2$$ → infeasible!

**Constrained optimum:** since $$c$$ lies outside the ball, the solution lies on the boundary $$\|x\|_2 = 2$$. (Note: projecting $$c$$ onto the ball is optimal only for the $$\ell_2$$ distance, not for $$\ell_1$$.) On the boundary with $$x_1 &amp;lt; 2$$, $$x_2 &amp;lt; 3$$:

$$f(x) = (2 - x_1) + (3 - x_2) = 5 - (x_1 + x_2)$$

so the problem becomes $$\max\; x_1 + x_2$$ on the circle $$x_1^2 + x_2^2 = 4$$, attained at $$x_1 = x_2 = \sqrt{2}$$:

$$x^* = (\sqrt{2}, \sqrt{2}) \approx (1.414, 1.414)$$

**Objective:** $$f(x^*) = 5 - 2\sqrt{2} \approx 2.172$$ (the projected point $$\frac{2}{\sqrt{13}}(2,3)$$ gives $$2.227$$, which is worse). This is exactly the point reached by projected subgradient at $$x^{(2)}$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;subgradient-method-properties&quot;&gt;&lt;strong&gt;Subgradient Method Properties:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aspect&lt;/th&gt;
      &lt;th&gt;Gradient Descent&lt;/th&gt;
      &lt;th&gt;Subgradient Method&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Applicability&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Smooth \(f\)&lt;/td&gt;
      &lt;td&gt;Non-smooth \(f\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Convergence&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear (\(O(\rho^k)\))&lt;/td&gt;
      &lt;td&gt;Sublinear (\(O(1/\sqrt{k})\))&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Step size&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Fixed or line search&lt;/td&gt;
      &lt;td&gt;Diminishing or Polyak&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Descent&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Always decreases&lt;/td&gt;
      &lt;td&gt;May increase!&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Usage&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Well-behaved \(f\)&lt;/td&gt;
      &lt;td&gt;\(\ell_1\), max, constraints&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;step-size-rules&quot;&gt;&lt;strong&gt;Step Size Rules:&lt;/strong&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Constant \(\alpha\):&lt;/strong&gt; Converges to neighborhood&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diminishing \(\frac{1}{k}\):&lt;/strong&gt; Converges exactly but very slowly (bound \(O(1/\log k)\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Square summable \(\frac{1}{k^{0.6}}\):&lt;/strong&gt; Converges exactly with bound \(O(1/k^{0.4})\), faster than \(\frac{1}{k}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polyak:&lt;/strong&gt; Fast if \(f^*\) known&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;when-to-use-the-subgradient-method&quot;&gt;&lt;strong&gt;When to use the subgradient method:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Non-differentiable \(f\) (\(\ell_1\), max)&lt;/li&gt;
  &lt;li&gt;Simple per-iteration cost needed&lt;/li&gt;
  &lt;li&gt;Willing to accept slow convergence&lt;/li&gt;
  &lt;li&gt;Constraints via projection&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Section 3.1.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Shor, N. Z.&lt;/strong&gt; (1985). &lt;em&gt;Minimization Methods for Non-Differentiable Functions&lt;/em&gt;. Springer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Polyak, B. T.&lt;/strong&gt; (1987). &lt;em&gt;Introduction to Optimization&lt;/em&gt;. Optimization Software.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

</content>
 </entry>
 
 <entry>
   <title>07-09 Multiple-Choice Quiz - Subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_09_Quiz_Subgradient/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_09_Quiz_Subgradient</id>
   <content type="html">&lt;p&gt;Working with sets of slopes instead of single numbers requires a subtle shift in intuition: addition becomes Minkowski set addition, gradients become convex hulls of active branches, and \(f&apos;(x^\star) = 0\) becomes set membership \(0 \in \partial f(x^\star)\). This Chapter 07 quiz tests your fluency across subgradient definitions, normal cones, calculus rules, Lasso optimality, soft-thresholding, and distance-function subgradients.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-chapter-07-assessment-pillars&quot;&gt;Key ideas: Chapter 07 Assessment Pillars&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Definition &amp;amp; Existence&lt;/strong&gt;: Checking \(f(y) \ge f(x) + g^T(y - x)\) globally, knowing \(\partial f(x)\) is always closed and convex, and recognizing when \(\partial f(x) = \{\nabla f(x)\}\) vs. an interval or ball.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Subgradient Calculus&lt;/strong&gt;: Applying positive scaling (\(a &amp;gt; 0\)), Minkowski addition, affine composition (\(A^T \partial f(Ax + b)\)), and the active-set convex-hull rule for pointwise maxima.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Indicator Functions &amp;amp; Normal Cones&lt;/strong&gt;: Translating constrained problems into \(f + I_C\) using \(\partial I_C(x) = N_C(x)\) and verifying \(-\nabla f(x^\star) \in N_C(x^\star)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Universal Optimality &amp;amp; Canonical Examples&lt;/strong&gt;: Testing \(0 \in \partial f(x^\star)\) to solve Lasso correlation conditions, soft-thresholding \(S_\lambda(y)\), and Euclidean distance gradients \((x - P_C(x))/\|x - P_C(x)\|_2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-pre-quiz-subdifferential-check-on-x_infty&quot;&gt;Worked example: Pre-Quiz Subdifferential Check on \(\|x\|_\infty\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Warm-Up Question&lt;/strong&gt;: Compute \(\partial f(x)\) for $$f(x_1, x_2) = |x|_\infty = \max{&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;,&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;}\(at the point\)x = (2, -2)$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Rewrite as a pointwise maximum of 4 linear functions&lt;/strong&gt;:
\(f(x) = \max\{x_1,\; -x_1,\; x_2,\; -x_2\}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Identify the active branches at \(x = (2, -2)\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(x_1 = 2\) (active! gradient \((1, 0)\)),&lt;/li&gt;
      &lt;li&gt;\(-x_1 = -2\) (inactive),&lt;/li&gt;
      &lt;li&gt;\(x_2 = -2\) (inactive),&lt;/li&gt;
      &lt;li&gt;\(-x_2 = 2\) (active! gradient \((0, -1)\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take the convex hull of active gradients&lt;/strong&gt;:
\(\partial f(2, -2) = \operatorname{conv}\!\left\{\begin{bmatrix} 1 \\ 0 \end{bmatrix},\; \begin{bmatrix} 0 \\ -1 \end{bmatrix}\right\} = \left\{\begin{bmatrix} \theta \\ -(1 - \theta) \end{bmatrix} : 0 \le \theta \le 1\right\}.\)
Notice every vector \(g \in \partial f(2, -2)\) satisfies \(\|g\|_1 = \theta + (1 - \theta) = 1\) (the dual norm of \(\|\cdot\|_\infty\)!) and \(g^T x = 2\theta + 2(1 - \theta) = 2 = \|x\|_\infty\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-subgradients&quot;&gt;📐 &lt;strong&gt;Subgradients&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;For a convex function \(f: \mathbb{R}^n \to \mathbb{R}\), a subgradient at \(x\) is a vector \(g \in \mathbb{R}^n\) satisfying:&lt;/p&gt;

\[f(y) \ge f(x) + g^T(y - x), \quad \forall y\]

&lt;p&gt;&lt;strong&gt;Geometric meaning:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g\) defines a supporting hyperplane of \(f\) at \(x\)&lt;/li&gt;
  &lt;li&gt;This hyperplane lies below the graph of the function at every point&lt;/li&gt;
  &lt;li&gt;It generalizes the gradient to non-differentiable functions&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;basic-properties&quot;&gt;&lt;strong&gt;Basic properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Existence:&lt;/strong&gt; A subgradient always exists for a convex function&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Uniqueness:&lt;/strong&gt; If \(f\) is differentiable at \(x\), then \(g = \nabla f(x)\) is the unique subgradient&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-convex:&lt;/strong&gt; For non-convex functions, a subgradient may not exist&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-important-examples&quot;&gt;📊 &lt;strong&gt;Important Examples&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-absolute-value-fx--lvert-x-rvert&quot;&gt;&lt;strong&gt;1. Absolute value: \(f(x) = \lvert x \rvert\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial f(x) = \begin{cases}
\{-1\} &amp;amp; \text{if } x &amp;lt; 0 \\
[-1, 1] &amp;amp; \text{if } x = 0 \\
\{1\} &amp;amp; \text{if } x &amp;gt; 0
\end{cases}\)&lt;/p&gt;

&lt;h4 id=&quot;2-l1-norm-fx--lvert-x-rvert_1--sum_i1n-lvert-x_i-rvert&quot;&gt;&lt;strong&gt;2. L1 norm: \(f(x) = \lVert x \rVert_1 = \sum_{i=1}^n \lvert x_i \rvert\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\((\partial f(x))_i = \begin{cases}
\{\text{sign}(x_i)\} &amp;amp; \text{if } x_i \neq 0 \\
[-1, 1] &amp;amp; \text{if } x_i = 0
\end{cases}\)&lt;/p&gt;

&lt;h4 id=&quot;3-l2-norm-fx--lvert-x-rvert_2&quot;&gt;&lt;strong&gt;3. L2 norm: \(f(x) = \lVert x \rVert_2\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial f(x) = \begin{cases}
\left\{\frac{x}{\lVert x \rVert_2}\right\} &amp;amp; \text{if } x \neq 0 \\
\{g : \lVert g \rVert_2 \le 1\} &amp;amp; \text{if } x = 0
\end{cases}\)&lt;/p&gt;

&lt;h4 id=&quot;4-max-function-fx--maxf_1x-f_2x&quot;&gt;&lt;strong&gt;4. Max function: \(f(x) = \max\{f_1(x), f_2(x)\}\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial f(x) = \begin{cases}
\{\nabla f_1(x)\} &amp;amp; \text{if } f_1(x) &amp;gt; f_2(x) \\
\{\nabla f_2(x)\} &amp;amp; \text{if } f_1(x) &amp;lt; f_2(x) \\
\text{conv}\{\nabla f_1(x), \nabla f_2(x)\} &amp;amp; \text{if } f_1(x) = f_2(x)
\end{cases}\)&lt;/p&gt;

&lt;h3 id=&quot;-the-subdifferential&quot;&gt;🔍 &lt;strong&gt;The Subdifferential&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition-1&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The subdifferential \(\partial f(x)\) is the set of all subgradients at \(x\):&lt;/p&gt;

\[\partial f(x) = \{g \in \mathbb{R}^n : g \text{ is a subgradient of } f \text{ at } x\}\]

&lt;h4 id=&quot;important-properties&quot;&gt;&lt;strong&gt;Important properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Closed convex set:&lt;/strong&gt; \(\partial f(x)\) is always a closed convex set&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nonempty:&lt;/strong&gt; If \(f\) is convex, then \(\partial f(x) \neq \emptyset\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Uniqueness:&lt;/strong&gt; If \(f\) is differentiable at \(x\), then \(\partial f(x) = \{\nabla f(x)\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Differentiability:&lt;/strong&gt; If \(\partial f(x) = \{g\}\), then \(f\) is differentiable at \(x\) and \(\nabla f(x) = g\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-subgradient-optimality-condition&quot;&gt;🎯 &lt;strong&gt;Subgradient Optimality Condition&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;fundamental-theorem&quot;&gt;&lt;strong&gt;Fundamental theorem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^* \text{ is a global minimizer of } f \quad \Longleftrightarrow \quad 0 \in \partial f(x^*)\)&lt;/p&gt;

&lt;h4 id=&quot;proof&quot;&gt;&lt;strong&gt;Proof&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
f(x^*) = \min_x f(x) &amp;amp;\Longleftrightarrow f(y) \ge f(x^*) \text{ for all } y \\
&amp;amp;\Longleftrightarrow f(y) \ge f(x^*) + 0^T(y - x^*) \\
&amp;amp;\Longleftrightarrow 0 \in \partial f(x^*)
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important note:&lt;/strong&gt; This condition holds even for non-convex functions!&lt;/p&gt;

&lt;h3 id=&quot;-connection-with-the-first-order-optimality-condition&quot;&gt;🔗 &lt;strong&gt;Connection with the First-Order Optimality Condition&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;constrained-problem&quot;&gt;&lt;strong&gt;Constrained problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{x \in C} f(x)\)&lt;/p&gt;

&lt;h4 id=&quot;first-order-optimality-condition&quot;&gt;&lt;strong&gt;First-order optimality condition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;If \(f\) is convex and differentiable:
\(x^* \text{ optimal} \Longleftrightarrow \nabla f(x^*)^T(y - x^*) \ge 0, \quad \forall y \in C\)&lt;/p&gt;

&lt;h4 id=&quot;derivation-from-subgradients&quot;&gt;&lt;strong&gt;Derivation from subgradients&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
\min_{x \in C} f(x) &amp;amp;\Longleftrightarrow \min_x [f(x) + I_C(x)] \\
&amp;amp;\Longleftrightarrow 0 \in \partial[f(x^*) + I_C(x^*)] \\
&amp;amp;\Longleftrightarrow 0 \in \{\nabla f(x^*)\} + \mathcal{N}_C(x^*) \\
&amp;amp;\Longleftrightarrow -\nabla f(x^*) \in \mathcal{N}_C(x^*) \\
&amp;amp;\Longleftrightarrow \nabla f(x^*)^T(y - x^*) \ge 0, \quad \forall y \in C
\end{align}\)&lt;/p&gt;

&lt;h3 id=&quot;-subgradient-calculus-rules&quot;&gt;📏 &lt;strong&gt;Subgradient Calculus Rules&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-linear-combinations&quot;&gt;&lt;strong&gt;1. Linear combinations&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial(\alpha f + \beta g)(x) = \alpha \partial f(x) + \beta \partial g(x)\)
with \(\alpha, \beta \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;2-max-functions&quot;&gt;&lt;strong&gt;2. Max functions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial \max\{f_1, \ldots, f_m\}(x) = \text{conv}\{\partial f_i(x) : i \in I(x)\}\)
with \(I(x) = \{i : f_i(x) = \max_j f_j(x)\}\)&lt;/p&gt;

&lt;h4 id=&quot;3-composition&quot;&gt;&lt;strong&gt;3. Composition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;If \(h(x) = f(Ax + b)\):
\(\partial h(x) = A^T \partial f(Ax + b)\)&lt;/p&gt;

&lt;h4 id=&quot;4-indicator-functions&quot;&gt;&lt;strong&gt;4. Indicator functions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\partial I_C(x) = \begin{cases}
\mathcal{N}_C(x) &amp;amp; \text{if } x \in C \\
\emptyset &amp;amp; \text{if } x \notin C
\end{cases}\)&lt;/p&gt;

&lt;p&gt;where \(\mathcal{N}_C(x)\) is the normal cone of \(C\) at \(x\)&lt;/p&gt;

&lt;h3 id=&quot;-practical-applications&quot;&gt;🎲 &lt;strong&gt;Practical Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-lasso-regression&quot;&gt;&lt;strong&gt;1. LASSO Regression&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_\beta \frac{1}{2}\lVert y - X\beta \rVert_2^2 + \lambda \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimality conditions:&lt;/strong&gt;
\(0 \in X^T(X\beta^* - y) + \lambda \partial \lVert \beta^* \rVert_1\)&lt;/p&gt;

&lt;h4 id=&quot;2-soft-thresholding&quot;&gt;&lt;strong&gt;2. Soft-thresholding&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The solution of \(\min_x \frac{1}{2}(x - a)^2 + \lambda \lvert x \rvert\):&lt;/p&gt;

\[x^* = \text{soft}(a, \lambda) = \begin{cases}
a - \lambda &amp;amp; \text{if } a &amp;gt; \lambda \\
0 &amp;amp; \text{if } \lvert a \rvert \le \lambda \\
a + \lambda &amp;amp; \text{if } a &amp;lt; -\lambda
\end{cases}\]

&lt;h4 id=&quot;3-distance-to-a-convex-set&quot;&gt;&lt;strong&gt;3. Distance to a convex set&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x \frac{1}{2}\lVert x - a \rVert_2^2 + I_C(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; \(x^* = P_C(a)\) (the projection of \(a\) onto \(C\))&lt;/p&gt;

&lt;h3 id=&quot;-gradient-vs-subgradient&quot;&gt;🔄 &lt;strong&gt;Gradient vs Subgradient&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aspect&lt;/th&gt;
      &lt;th&gt;Gradient&lt;/th&gt;
      &lt;th&gt;Subgradient&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Condition&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Differentiable function&lt;/td&gt;
      &lt;td&gt;Convex function&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Unique&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Yes&lt;/td&gt;
      &lt;td&gt;No (may be a set)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Existence&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Not always&lt;/td&gt;
      &lt;td&gt;Always (for convex functions)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Computation&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Derivatives&lt;/td&gt;
      &lt;td&gt;Subdifferential rules&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Application&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Smooth optimization&lt;/td&gt;
      &lt;td&gt;Non-smooth optimization&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-computation-techniques&quot;&gt;🛠️ &lt;strong&gt;Computation Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;step-1-check-differentiability&quot;&gt;&lt;strong&gt;Step 1: Check differentiability&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;If \(f\) is differentiable at \(x\): \(\partial f(x) = \{\nabla f(x)\}\)&lt;/li&gt;
  &lt;li&gt;If not differentiable: use the calculus rules&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;step-2-analyze-the-structure&quot;&gt;&lt;strong&gt;Step 2: Analyze the structure&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Linear combinations of convex functions&lt;/li&gt;
  &lt;li&gt;Max/min functions&lt;/li&gt;
  &lt;li&gt;Compositions&lt;/li&gt;
  &lt;li&gt;Indicator functions&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;step-3-apply-the-rules&quot;&gt;&lt;strong&gt;Step 3: Apply the rules&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Use the subdifferential calculus rules&lt;/li&gt;
  &lt;li&gt;Combine the partial results&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-the-subgradient-method&quot;&gt;⚡ &lt;strong&gt;The Subgradient Method&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;update-rule&quot;&gt;&lt;strong&gt;Update rule&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k+1)} = x^{(k)} - t_k g^{(k)}\)
with \(g^{(k)} \in \partial f(x^{(k)})\)&lt;/p&gt;

&lt;h4 id=&quot;choosing-the-step-size&quot;&gt;&lt;strong&gt;Choosing the step size&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Fixed:&lt;/strong&gt; \(t_k = t &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diminishing:&lt;/strong&gt; \(t_k \to 0\), \(\sum t_k = \infty\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Square summable:&lt;/strong&gt; \(\sum t_k^2 &amp;lt; \infty\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;convergence&quot;&gt;&lt;strong&gt;Convergence&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Monotonic decrease is not guaranteed&lt;/li&gt;
  &lt;li&gt;Converges to the optimal value (not necessarily to an optimal point)&lt;/li&gt;
  &lt;li&gt;Convergence rate: \(O(1/\sqrt{k})\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-illustrative-examples&quot;&gt;🎯 &lt;strong&gt;Illustrative Examples&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;problem-min_x-lvert-x---2-rvert--lvert-x--1-rvert&quot;&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(\min_x \lvert x - 2 \rvert + \lvert x + 1 \rvert\)&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Compute the subdifferential
\(\partial f(x) = \partial \lvert x - 2 \rvert + \partial \lvert x + 1 \rvert\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Analyze each interval&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(x &amp;lt; -1\): \(\partial f(x) = \{-1 - 1\} = \{-2\}\)&lt;/li&gt;
  &lt;li&gt;\(-1 &amp;lt; x &amp;lt; 2\): \(\partial f(x) = \{-1 + 1\} = \{0\}\)&lt;/li&gt;
  &lt;li&gt;\(x &amp;gt; 2\): \(\partial f(x) = \{1 + 1\} = \{2\}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Optimality condition
\(0 \in \partial f(x^*) \Rightarrow x^* \in [-1, 2]\)&lt;/p&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;recognizing-non-differentiable-functions&quot;&gt;&lt;strong&gt;Recognizing non-differentiable functions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Functions containing \(\lvert \cdot \rvert\), \(\max\{\cdot\}\), \(\min\{\cdot\}\)&lt;/li&gt;
  &lt;li&gt;Indicator functions \(I_C(\cdot)\)&lt;/li&gt;
  &lt;li&gt;The norms \(\lVert \cdot \rVert_1\), \(\lVert \cdot \rVert_\infty\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;efficient-computation&quot;&gt;&lt;strong&gt;Efficient computation:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Use the linear-combination rule&lt;/li&gt;
  &lt;li&gt;Analyze component by component&lt;/li&gt;
  &lt;li&gt;Apply geometric properties&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;checking-results&quot;&gt;&lt;strong&gt;Checking results:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Verify the subdifferential condition&lt;/li&gt;
  &lt;li&gt;Check that the resulting set is convex&lt;/li&gt;
  &lt;li&gt;Compare with the differentiable case (if applicable)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; Subgradients extend the gradient to non-differentiable functions; they are a powerful tool in convex optimization and in machine learning with regularization!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of subgradients, subdifferentials, their geometric properties and optimality conditions in convex optimization.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🧮 Quiz: Subgradients and Subdifferentials&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;25&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: A subgradient of a convex function \\(f\\) at a point \\(x\\) is a vector \\(g\\) satisfying:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \\(f(y) \leq f(x) + g^T(y-x)\\) for all \\(y\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \\(f(y) \geq f(x) + g^T(y-x)\\) for all \\(y\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \\(f(y) = f(x) + g^T(y-x)\\) for all \\(y\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \\(\nabla f(x) = g\\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$f(y) \geq f(x) + g^T(y-x)$$ for all $$y$$&lt;/strong&gt;&lt;br /&gt;
                This is the exact definition of a subgradient: the function always lies above the affine function defined by the subgradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The subdifferential \\(\partial f(x)\\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) The set of all gradients at \\(x\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) The set of all subgradients at \\(x\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) The unique gradient vector at \\(x\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) The second derivative at \\(x\\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The set of all subgradients at $$x$$&lt;/strong&gt;&lt;br /&gt;
                The subdifferential $$\partial f(x)$$ is the set of all vectors $$g$$ satisfying the subgradient condition.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: The subgradients of \\(f(x) = |x|\\) at \\(x = 0\\) are:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \\(\{0\}\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \\(\{1, -1\}\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \\([-1, 1]\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \\(\mathbb{R}\\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) $$[-1, 1]$$&lt;/strong&gt;&lt;br /&gt;
                At $$x = 0$$, $$|x|$$ is not differentiable and the subdifferential is the interval $$[-1, 1]$$, because $$|y| \geq g \cdot y$$ for all $$y$$ when $$g \in [-1, 1]$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: If a convex function \\(f\\) is differentiable at \\(x\\), then \\(\partial f(x)\\) equals:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) \\(\{\nabla f(x)\}\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) \\(\emptyset\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) \\(\mathbb{R}^n\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) An infinite set of vectors&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\{\nabla f(x)\}$$&lt;/strong&gt;&lt;br /&gt;
                When a convex function is differentiable at a point, its subdifferential contains a single element: the gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: A necessary and sufficient condition for \\(x^*\\) to be a global minimizer of a convex function \\(f\\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \\(\nabla f(x^*) = 0\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \\(0 \in \partial f(x^*)\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \\(f(x^*) = 0\\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \\(\partial f(x^*) = \mathbb{R}^n\\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$0 \in \partial f(x^*)$$&lt;/strong&gt;&lt;br /&gt;
                Subgradient optimality condition: $$x^*$$ is a global minimizer if and only if $$0$$ belongs to the subdifferential at $$x^*$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: The subdifferential \(\partial f(x)\) of a convex function is always:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) The empty set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) A closed convex set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) An open set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) A single element&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) A closed convex set&lt;/strong&gt;&lt;br /&gt;
                The subdifferential of a convex function is always closed and convex, and it is also compact and nonempty (if $$x$$ lies in the interior of $$\text{dom} f$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: Let \(f(x) = \max\{x_1, x_2\}\) at the point \(x = (2, 2)\). The subdifferential \(\partial f(x)\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) \(\{(1, 0), (0, 1)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(\text{conv}\{(1, 0), (0, 1)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) \(\{(1, 1)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(\{(0, 0)\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) \(\text{conv}\{(1, 0), (0, 1)\}\)&lt;/strong&gt;&lt;br /&gt;
                At a point where several components attain the maximum, the subdifferential is the convex hull of the gradients of the active components.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: If \(f\) and \(g\) are two convex functions, then \(\partial(f + g)(x)\) equals:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(\partial f(x) + \partial g(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(\partial f(x) \cup \partial g(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(\partial f(x) \cap \partial g(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(\max\{\partial f(x), \partial g(x)\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) \(\partial f(x) + \partial g(x)\)&lt;/strong&gt;&lt;br /&gt;
                Sum rule: the subdifferential of a sum is the Minkowski sum of the subdifferentials (valid, for example, when $$\text{relint}\,\text{dom} f \cap \text{relint}\,\text{dom} g \neq \emptyset$$, e.g. when both functions are finite on all of $$\mathbb{R}^n$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The subdifferential of \(f(x) = \|x\|_2\) at \(x \neq 0\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(\{x/\|x\|_2\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(\{u : \|u\|_2 \leq 1\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(\{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(\mathbb{R}^n\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) \(\{x/\|x\|_2\}\)&lt;/strong&gt;&lt;br /&gt;
                When \(x \neq 0\), the Euclidean norm is differentiable with gradient \(x/\|x\|_2\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: The subdifferential of \(f(x) = \|x\|_2\) at \(x = 0\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(\{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(\{u : \|u\|_2 \leq 1\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(\{u : \|u\|_2 = 1\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(\mathbb{R}^n\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) \(\{u : \|u\|_2 \leq 1\}\)&lt;/strong&gt;&lt;br /&gt;
                At the origin, the subdifferential of the Euclidean norm is the closed unit ball.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: Let \(f(x) = g(Ax + b)\) with \(g\) convex and \(A\) a matrix. Then \(\partial f(x)\) equals:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(A^T \partial g(Ax + b)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(A \partial g(Ax + b)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(\partial g(Ax + b) A^T\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(\partial g(Ax + b)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) \(A^T \partial g(Ax + b)\)&lt;/strong&gt;&lt;br /&gt;
                Chain rule for subdifferentials: \(\partial f(x) = A^T \partial g(Ax + b)\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The subdifferential of the indicator function \(I_C(x)\) of a convex set \(C\) at \(x \in C\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) \(\{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) The normal cone \(N_C(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) The tangent cone \(T_C(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) \(\mathbb{R}^n\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The normal cone \(N_C(x)\)&lt;/strong&gt;&lt;br /&gt;
                The subdifferential of the indicator function equals the normal cone of the convex set at that point.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The subdifferential operator \(\partial f\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Monotone&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Not monotone&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Continuous&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Monotone&lt;/strong&gt;&lt;br /&gt;
                The subdifferential of a convex function is a monotone operator: \((g_1 - g_2)^T(x_1 - x_2) \geq 0\) for \(g_i \in \partial f(x_i)\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: The subdifferential of the linear function \(f(x) = c^T x\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) \(\{c\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) \(\{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) \(\mathbb{R}^n\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) \(\{tc : t \geq 0\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) \(\{c\}\)&lt;/strong&gt;&lt;br /&gt;
                A linear function is differentiable everywhere with constant gradient \(c\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: Let \(f(x) = \frac{1}{2}x^T Q x + c^T x\) with \(Q \succeq 0\). The subdifferential \(\partial f(x)\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(\{Qx + c\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(\{Qx\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(\{c\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) \(\{x\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) \(\{Qx + c\}\)&lt;/strong&gt;&lt;br /&gt;
                A convex quadratic is differentiable with gradient \(\nabla f(x) = Qx + c\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: Consider the problem \(\min f(x)\) s.t. \(x \in C\). The optimality condition is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(0 \in \partial f(x^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(-\partial f(x^*) \cap N_C(x^*) \neq \emptyset\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(\nabla f(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(x^* \in C\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) \(-\partial f(x^*) \cap N_C(x^*) \neq \emptyset\)&lt;/strong&gt;&lt;br /&gt;
                Constrained subgradient optimality condition: the negative of some subgradient lies in the normal cone.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: Let \(f(x) = \max\{f_1(x), f_2(x)\}\) with \(f_1, f_2\) convex and differentiable. At a point \(x\) where \(f_1(x) &amp;gt; f_2(x)\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) \(\partial f(x) = \{\nabla f_1(x)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) \(\partial f(x) = \{\nabla f_2(x)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) \(\partial f(x) = \text{conv}\{\nabla f_1(x), \nabla f_2(x)\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) \(\partial f(x) = \emptyset\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) \(\partial f(x) = \{\nabla f_1(x)\}\)&lt;/strong&gt;&lt;br /&gt;
                When only one function attains the maximum, the subdifferential contains only the gradient of that function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: The subdifferential \(\partial f(x)\) of a convex function \(f\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Upper continuous&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Upper semicontinuous&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Lower continuous&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Discontinuous&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Upper semicontinuous&lt;/strong&gt;&lt;br /&gt;
                The subdifferential is an upper semicontinuous set-valued map.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: Let \(f(x) = d_C(x) = \inf_{y \in C} \|x - y\|_2\) with \(C\) closed and convex. When \(x \notin C\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) \(\partial f(x) = \{(x - P_C(x))/\|x - P_C(x)\|_2\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) \(\partial f(x) = \{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) \(\partial f(x) = N_C(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) \(\partial f(x) = \{x\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) \(\partial f(x) = \{(x - P_C(x))/\|x - P_C(x)\|_2\}\)&lt;/strong&gt;&lt;br /&gt;
                The subgradient of the distance function is the unit vector pointing from the projection to the point.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: The support function \(\sigma_C(x) = \sup_{y \in C} y^T x\) of a compact convex set \(C\) has subdifferential:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) \(\partial \sigma_C(x) = \arg\max_{y \in C} y^T x\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) \(\partial \sigma_C(x) = C\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) \(\partial \sigma_C(x) = \{x\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) \(\partial \sigma_C(x) = \{0\}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) \(\partial \sigma_C(x) = \arg\max_{y \in C} y^T x\)&lt;/strong&gt;&lt;br /&gt;
                The subdifferential of the support function is the set of points attaining the maximum in the supremum.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 21 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: In SVM, the hinge loss \(f(t) = \max\{0, 1-t\}\) has subdifferential at \(t = 1\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) \(\{0\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) \(\{-1\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) \([-1, 0]\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) \([0, 1]\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) \([-1, 0]\)&lt;/strong&gt;&lt;br /&gt;
                At the kink \(t = 1\), the subdifferential is the interval between the left derivative (-1) and the right derivative (0).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: The subdifferential of \(f(x) = \|x\|_1\) at \(x\) with \(x_i \neq 0\), for the \(i\)-th component, is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) \(\text{sign}(x_i)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) \([-1, 1]\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) \(x_i\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) \(|x_i|\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) \(\text{sign}(x_i)\)&lt;/strong&gt;&lt;br /&gt;
                When \(x_i \neq 0\), the \(i\)-th component of the subdifferential is \(\text{sign}(x_i)\).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: If a convex function \(f\) is not differentiable at \(x\), then \(\partial f(x)\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Is the empty set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Contains more than one element&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Contains only the zero vector&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Is undefined&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Contains more than one element&lt;/strong&gt;&lt;br /&gt;
                At a point of non-differentiability, the subdifferential contains several subgradients, reflecting the &quot;kink&quot; of the function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: In the subgradient method, the update direction is chosen as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Gradient \(\nabla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) The negative of any subgradient: \(-g\) with \(g \in \partial f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) A random vector&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) The Newton direction&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The negative of any subgradient: \(-g\) with \(g \in \partial f(x)\)&lt;/strong&gt;&lt;br /&gt;
                The subgradient method picks any subgradient $$g$$ at the current point and updates $$x^{+} = x - t g$$. Note that $$-g$$ is not necessarily a descent direction.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: Geometrically, a subgradient \(g \in \partial f(x)\) defines:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) A hyperplane lying above the graph of the function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) A hyperplane lying below the graph of the function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) A hyperplane cutting the graph of the function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) A hyperplane perpendicular to the graph of the function&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) A hyperplane lying below the graph of the function&lt;/strong&gt;&lt;br /&gt;
                A subgradient defines a supporting hyperplane: \(f(y) \geq f(x) + g^T(y-x)\) - the graph of the function lies above this hyperplane.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;c&apos;, q4: &apos;a&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;b&apos;,
    q11: &apos;a&apos;, q12: &apos;b&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;b&apos;, q17: &apos;a&apos;, q18: &apos;b&apos;, q19: &apos;a&apos;, q20: &apos;a&apos;,
    q21: &apos;c&apos;, q22: &apos;a&apos;, q23: &apos;b&apos;, q24: &apos;b&apos;, q25: &apos;b&apos;
};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
    
    // Re-render MathJax for the current question
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise([document.getElementById(`q${n}`)])).then(() =&gt; {
            // MathJax rendering complete
        });
    }
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered subgradients!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand subgradients and subdifferentials quite well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review a few concepts about optimality conditions.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review the definitions and basic properties.&apos;;
    } else {
        message = &apos;📖 Study the concepts of subgradients again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Re-render MathJax for all content
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise()).then(() =&gt; {
            // MathJax rendering complete
        });
    }
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise()).then(() =&gt; {
            // MathJax rendering complete
        });
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>07-03 Subgradient Optimality Condition</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_subgradient_optimality_condition/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_subgradient_optimality_condition</id>
   <content type="html">&lt;p&gt;In smooth unconstrained calculus, the crown jewel is Fermat’s rule: \(f&apos;(x^\star) = 0\). In convex optimization—even with sharp corners, norms, and hard constraints—that entire theory collapses into a single, astonishingly clean statement: \(x^\star\) is a global minimizer &lt;strong&gt;if and only if&lt;/strong&gt; \(0 \in \partial f(x^\star)\). Section 07-03 unpacks this universal optimality law and applies it to constrained optimization, Lasso regression, soft-thresholding, and set-distance functions.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-roadmap-of-subgradient-optimality&quot;&gt;Key ideas: Roadmap of Subgradient Optimality&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Universal Necessary &amp;amp; Sufficient Condition&lt;/strong&gt;: \(f(x^\star) = \min_x f(x) \iff 0 \in \partial f(x^\star)\). Remarkably, this equivalence holds for &lt;em&gt;any&lt;/em&gt; function \(f\) (even nonconvex!), though for nonconvex functions \(\partial f(x^\star)\) may be empty at local minima—whereas for convex functions it characterizes every global minimizer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recovering Constrained First-Order Optimality&lt;/strong&gt;: Writing \(\min_{x \in C} f(x)\) as \(\min_x (f(x) + I_C(x))\) gives \(0 \in \partial f(x^\star) + N_C(x^\star)\). When \(f\) is smooth, \(-\nabla f(x^\star) \in N_C(x^\star) \iff \nabla f(x^\star)^T(y - x^\star) \ge 0\;\forall y \in C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Deriving Closed-Form Proximal &amp;amp; Sparsity Operators&lt;/strong&gt;: Applying \(0 \in \partial\bigl(\frac{1}{2}\|y - \beta\|_2^2 + \lambda\|\beta\|_1\bigr)\) immediately yields the &lt;strong&gt;soft-thresholding&lt;/strong&gt; operator, explaining mathematically why Lasso zeroes out weak features.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric Applications&lt;/strong&gt;: Computing \(\partial\,\mathrm{dist}(x, C)\) connects subgradients directly to Euclidean projections \(P_C(x)\), underpinning projection and splitting algorithms in later chapters.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-solving-a-constrained-nonsmooth-problem-via-0-in-partial-f--n_c&quot;&gt;Worked example: Solving a Constrained Nonsmooth Problem via \(0 \in \partial f + N_C\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 3&lt;/td&gt;
      &lt;td&gt;\(subject to\)x \in C = [-1, 2]$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Convert to unconstrained form using \(I_C(x)\)&lt;/strong&gt;: Minimize $$F(x) =&lt;/td&gt;
          &lt;td&gt;x - 3&lt;/td&gt;
          &lt;td&gt;+ I_{[-1, 2]}(x)\(, so optimality requires\)0 \in \partial&lt;/td&gt;
          &lt;td&gt;x^\star - 3&lt;/td&gt;
          &lt;td&gt;+ N_{[-1, 2]}(x^\star)$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the interior \(x \in (-1, 2)\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Here \(x &amp;lt; 3\), so $$\partial&lt;/td&gt;
              &lt;td&gt;x - 3&lt;/td&gt;
              &lt;td&gt;= {-1}\(, and since\)x\(is interior to\)C\(,\)N_C(x) = {0}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Sum: \(\{-1\} + \{0\} = \{-1\} \not\ni 0\) (no interior optimum).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the right boundary \(x^\star = 2\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Here \(2 &amp;lt; 3\), so $$\partial&lt;/td&gt;
              &lt;td&gt;x - 3&lt;/td&gt;
              &lt;td&gt;\big&lt;/td&gt;
              &lt;td&gt;_{x=2} = {-1}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;The normal cone at the right endpoint of \([-1, 2]\) is \(N_{[-1, 2]}(2) = [0, +\infty)\).&lt;/li&gt;
      &lt;li&gt;Sum: \(\{-1\} + [0, +\infty) = [-1, +\infty) \ni 0\)! (Explicitly, \(-1 + (+1) = 0\) with \(+1 \in N_C(2)\).)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;: \(x^\star = 2\) is certified as the global minimizer, with $$f^\star =&lt;/td&gt;
          &lt;td&gt;2 - 3&lt;/td&gt;
          &lt;td&gt;= 1$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we examine optimality conditions using subgradients, and provide several examples to illustrate their application and usefulness.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03-05 Example: Distance to a Convex Set</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_05_example_distance_to_convex_set/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_05_example_distance_to_convex_set</id>
   <content type="html">&lt;p&gt;Suppose a drone flies outside a convex safe-flight corridor \(C\) and needs to know the fastest direction back to safety. Its distance to the corridor is \(\operatorname{dist}(x, C) = \min_{y \in C} \|x - y\|_2 = \|x - P_C(x)\|_2\). Remarkably, this distance function is convex, smooth everywhere &lt;em&gt;outside&lt;/em&gt; \(C\) with a unit-length gradient pointing straight away from its projection \(P_C(x)\), and nonsmooth right on the boundary of \(C\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-convexity-and-subgradients-of-the-distance-function&quot;&gt;Key ideas: Convexity and Subgradients of the Distance Function&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Convexity via Partial Minimization&lt;/strong&gt;: Because \(h(x, y) = \|x - y\|_2\) is jointly convex in \((x, y)\) and \(C\) is a closed convex set, the partial minimum \(\operatorname{dist}(x, C) = \min_{y \in C}\|x - y\|_2\) is guaranteed to be convex in \(x\). Moreover, the closest point \(P_C(x) = \arg\min_{y \in C}\|x - y\|_2\) is always &lt;strong&gt;unique&lt;/strong&gt; (strict convexity of \(\|\cdot\|_2^2\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Projection Optimality (Obtuse-Angle Theorem)&lt;/strong&gt;: By Chapter 04’s first-order optimality applied to \(\frac{1}{2}\|x - y\|_2^2\) over \(y \in C\), \(u = P_C(x)\) if and only if
\((x - u)^T (y - u) \le 0 \quad \text{for all } y \in C\)
(equivalently, \(x - P_C(x) \in N_C(P_C(x))\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Subgradient Outside \(C\)&lt;/strong&gt;: For any \(x \notin C\), \(\operatorname{dist}(x, C)\) is actually &lt;strong&gt;differentiable&lt;/strong&gt; with unit-norm gradient:
\(\nabla \operatorname{dist}(x, C) = \frac{x - P_C(x)}{\|x - P_C(x)\|_2}.\)
Moving opposite this gradient walks in a straight line directly toward the closest safe point \(P_C(x)\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Subdifferential Inside and on the Boundary of \(C\)&lt;/strong&gt;: For \(x \in C\), \(\operatorname{dist}(x, C) = 0\) is minimized, so \(0 \in \partial \operatorname{dist}(x, C)\). Specifically, \(\partial \operatorname{dist}(x, C) = N_C(x) \cap B_2(0, 1)\) (outward normal vectors of length at most 1).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-computing-projection-and-subgradient-for-a-disk&quot;&gt;Worked example: Computing Projection and Subgradient for a Disk&lt;/h3&gt;

&lt;p&gt;Let \(C = \{y \in \mathbb{R}^2 : \|y\|_2 \le 2\}\) be the closed disk of radius \(2\) centered at the origin, and evaluate \(\operatorname{dist}(x, C)\) and its subgradient at \(x = (3, 4)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find the Euclidean projection \(P_C(x)\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Since \(\|x\|_2 = \sqrt{3^2 + 4^2} = 5 &amp;gt; 2\), \(x\) lies outside \(C\).&lt;/li&gt;
      &lt;li&gt;Scaling \(x\) radially down to radius \(2\) gives
\(P_C(x) = \frac{2}{5}(3, 4) = (1.2,\; 1.6).\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the distance and gradient vector \(g\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Displacement: \(x - P_C(x) = (3 - 1.2,\; 4 - 1.6) = (1.8,\; 2.4)\).&lt;/li&gt;
      &lt;li&gt;Distance: \(\operatorname{dist}(x, C) = \sqrt{1.8^2 + 2.4^2} = \sqrt{3.24 + 5.76} = \sqrt{9} = 3\) (which also equals \(5 - 2 = 3\)!).&lt;/li&gt;
      &lt;li&gt;Gradient:
\(g = \frac{x - P_C(x)}{\|x - P_C(x)\|_2} = \frac{(1.8, 2.4)}{3} = (0.6,\; 0.8).\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the subgradient inequality at a test point \(z = (0, 2) \in C\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Left-hand side: \(\operatorname{dist}(z, C) = 0\).&lt;/li&gt;
      &lt;li&gt;Right-hand side: \(\operatorname{dist}(x, C) + g^T(z - x) = 3 + (0.6, 0.8)\cdot(-3, -2) = 3 + (-1.8 - 1.6) = -0.4\).&lt;/li&gt;
      &lt;li&gt;Indeed \(0 \ge -0.4\)! And checking the obtuse-angle property: \((x - P_C(x))^T(z - P_C(x)) = (1.8, 2.4)\cdot(-1.2, 0.4) = -2.16 + 0.96 = -1.2 \le 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The distance function to a closed convex set \(C\) is defined as:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{alignat}{1}
dist(x,C) &amp;amp; = \min_{y \in C} | y-x |_2 &lt;br /&gt;
      &amp;amp; = | x-P_C(x) |_2 &lt;br /&gt;
      &amp;amp; \geq 0 
\end{alignat}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, \(P_C(x)\) is the projection of the point \(x\) onto the set \(C\), i.e., the closest point in \(C\) to \(x\). The subgradient of the distance function is:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\partial dist(x,C) = {\frac{x-P_C(x)}{ | x-P_C(x) |_2}}
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;proof&quot;&gt;Proof&lt;/h3&gt;

&lt;p&gt;If \(u=P_C(x)\), then by the first-order optimality condition,&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
(x-u)^T(y-u) \leq 0 \ \text{ for all } y \in C
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thus,&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
C \subseteq H = {y:(x-u)^T(y-u) \leq 0 }
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(i) For \(y \in H\),&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
(x-u)^T(y-u) \leq 0
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;On the other hand, since \(dist(y,C)\geq 0\),&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
dist(y,C) \geq \frac{(x-u)^T(y-u)}{ | x-u |_2} \text{ for all } y \in H
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(ii) For \(y \notin H\),&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
(x-u)^T(y-u) = | x-u |_2 | y-u |_2 \cos\theta,
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;where \(\theta\) is the angle between \(x-u\) and \(y-u\). Then,&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;$$
\eqalign{
dist(y,C) &amp;amp;\geq dist(y,H) \&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&amp;amp;= | y-u |_2 \cos \theta &lt;br /&gt;
&amp;amp;= \frac{(x-u)^T(y-u)}{ | x-u |_2} \text{ for all }y \notin H
}
$$&lt;/p&gt;

&lt;p&gt;Therefore, from (i) and (ii), for all \(y\),&lt;/p&gt;
&lt;blockquote&gt;

\[\eqalign{
dist(y,C) &amp;amp;\geq \frac{(x-u)^T(y-u)}{ \| x-u \|_2} \\
&amp;amp;= \frac{(x-u)^T(y-x+x-u)}{ \| x-u \|_2}\\
&amp;amp; = \| x-u \|_2 + \left(\frac{x-u}{ \| x-u \|_2}\right)^T(y-x)
}\]
&lt;/blockquote&gt;

&lt;p&gt;In conclusion, \(dist(x,C)\) has the following subgradient at \(x\):&lt;/p&gt;
&lt;blockquote&gt;

\[g=\frac{x-u}{ \| x-u \|_2}=\frac{x-P_C(x)}{ \| x-P_C(x) \|_2}\]
&lt;/blockquote&gt;

&lt;p&gt;Moreover, the subdifferential \(\partial dist(x,C)\) contains only one element, so \(dist(x,C)\) is differentiable and its derivative coincides with the subgradient.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03-04 Example: Soft-Thresholding</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_04_example_soft-thresholding/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_04_example_soft-thresholding</id>
   <content type="html">&lt;p&gt;Take the Lasso problem and simplify the design matrix to the identity \(X = I\): \(\min_\beta \frac{1}{2}\|y - \beta\|_2^2 + \lambda\|\beta\|_1\). Not only does subgradient optimality solve this in closed form—it produces one of the most famous building blocks in modern signal processing and convex optimization: the &lt;strong&gt;Soft-Thresholding Operator&lt;/strong&gt; \(S_\lambda(y)\), the exact proximal operator of the \(\ell_1\) norm that powers ISTA, FISTA, and wavelet denoising.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-soft-thresholding-and-proximal-sparsity&quot;&gt;Key ideas: Soft-Thresholding and Proximal Sparsity&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Complete Coordinate Separability&lt;/strong&gt;: When \(X = I\), the objective splits into \(p\) independent 1D problems:
\(\min_{\beta_i \in \mathbb{R}} \quad \frac{1}{2}(y_i - \beta_i)^2 + \lambda |\beta_i|.\)
We solve each coordinate \(\beta_i^\star\) independently via \(0 \in (\beta_i - y_i) + \lambda \partial |\beta_i|\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Three-Regime Closed-Form Solution&lt;/strong&gt;:
\(S_\lambda(y_i) = \begin{cases} y_i - \lambda &amp;amp; \text{if } y_i &amp;gt; \lambda, \\ 0 &amp;amp; \text{if } |y_i| \le \lambda, \\ y_i + \lambda &amp;amp; \text{if } y_i &amp;lt; -\lambda, \end{cases}\)
written compactly as \(S_\lambda(y_i) = \operatorname{sign}(y_i)\max(|y_i| - \lambda, 0)\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Soft vs. Hard Thresholding&lt;/strong&gt;: &lt;em&gt;Hard&lt;/em&gt; thresholding keeps \(y_i\) unchanged for $$&lt;/td&gt;
          &lt;td&gt;y_i&lt;/td&gt;
          &lt;td&gt;&amp;gt; \lambda\(and jumps discontinuously to\)0\(at\)\pm\lambda\((nonconvex!). *Soft* thresholding is continuous everywhere—it shrinks surviving entries toward zero by\)\lambda$$, trading a tiny bias for convexity and stability.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Role in Iterative Solvers (ISTA / Proximal Gradient)&lt;/strong&gt;: Even when \(X \neq I\), proximal gradient descent for general Lasso simply alternates one ordinary gradient step \(z = \beta - t X^T(X\beta - y)\) with one soft-thresholding call \(\beta^+ = S_{t\lambda}(z)\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-applying-soft-thresholding-to-a-noisy-signal&quot;&gt;Worked example: Applying Soft-Thresholding to a Noisy Signal&lt;/h3&gt;

&lt;p&gt;Denoise the 4-entry signal \(y = (4.5,\; -0.8,\; 1.5,\; -3.2)^T\) by solving \(\min_\beta \frac{1}{2}\|y - \beta\|_2^2 + \lambda\|\beta\|_1\) with \(\lambda = 1.5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate 1 (\(y_1 = 4.5 &amp;gt; 1.5\))&lt;/strong&gt;:
\(\beta_1^\star = 4.5 - 1.5 = 3.0.\)
Check optimality: \(y_1 - \beta_1^\star = 1.5 = \lambda \operatorname{sign}(3.0)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate 2 (\(y_2 = -0.8\), \(|-0.8| = 0.8 \le 1.5\))&lt;/strong&gt;:
\(\beta_2^\star = 0.\)
Check optimality: \(|y_2 - 0| = 0.8 \le 1.5\) (subgradient \(v_2 = -0.8/1.5 \approx -0.533 \in [-1, 1]\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate 3 (\(y_3 = 1.5\), right on the boundary \(|1.5| = 1.5\))&lt;/strong&gt;:
\(\beta_3^\star = 1.5 - 1.5 = 0.\)
Check optimality: \(|y_3 - 0| = 1.5 \le 1.5\) (subgradient \(v_3 = +1 \in [-1, 1]\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate 4 (\(y_4 = -3.2 &amp;lt; -1.5\))&lt;/strong&gt;:
\(\beta_4^\star = -3.2 + 1.5 = -1.7.\)
Check optimality: \(y_4 - \beta_4^\star = -1.5 = \lambda \operatorname{sign}(-1.7)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Final denoised vector&lt;/strong&gt;: \(\beta^\star = (3.0,\; 0,\; 0,\; -1.7)^T\) — two weak/borderline noise components snapped cleanly to exact zero!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the simpler lasso problem with \(X=I\):&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\min_{\beta} \frac{1}{2} | y-\beta |_2^2 + \lambda | \beta |_1
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From the previous example, the subgradient optimality condition is:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{cases}
y_i-\beta_i = \lambda \cdot \text{sign}(\beta_i) &amp;amp;\text{if } \beta_i \neq 0 \\
 |y_i-\beta_i| \leq \lambda &amp;amp;\text{if } \beta_i = 0
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;From this condition, the solution \(\beta = S_{\lambda}(y)\) can be found, where&lt;/p&gt;
&lt;blockquote&gt;

\[[S_{\lambda}(y)]_{i} = 
\begin{cases}
y_i - \lambda &amp;amp;\text{if }y_i &amp;gt; \lambda \\
0             &amp;amp;\text{if }-\lambda \leq y_i \leq \lambda, \quad \quad i \in \{1,2,\dots,n \} \\
y_i + \lambda &amp;amp;\text{if } y_i &amp;lt; -\lambda
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(S_{\lambda}\) is called the soft-thresholding operator.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter07/07_03_subgrad-6.png&quot; alt=&quot;connection_to_convexity_geometry&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig 1] Soft-thresholding, y (x-axis), } \beta \text{ (y-axis), } \lambda=1/2 \text{ [3]}$$ &lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03-03 Example: Lasso Optimality Condition</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_03_example_lasso_optimality_condition/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_03_example_lasso_optimality_condition</id>
   <content type="html">&lt;p&gt;Why does Lasso regression—introduced by Robert Tibshirani in 1996—automatically zero out irrelevant features while Ridge regression keeps every feature nonzero? The secret isn’t heuristic magic; it sits right inside the subgradient optimality condition \(0 \in \partial\bigl(\frac{1}{2}\|y - X\beta\|_2^2 + \lambda\|\beta\|_1\bigr)\), which turns feature selection into a crisp correlation threshold between each predictor column \(X_j\) and the residual \(y - X\beta\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-subgradient-anatomy-of-the-lasso&quot;&gt;Key ideas: Subgradient Anatomy of the Lasso&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Decomposing the Lasso Objective&lt;/strong&gt;: \(F(\beta) = \frac{1}{2}\|y - X\beta\|_2^2 + \lambda\|\beta\|_1\) sums a smooth quadratic data-fit term (gradient \(-X^T(y - X\beta)\)) and a nonsmooth separable \(\ell_1\) penalty (subdifferential \(\lambda v\) where \(v_j = \operatorname{sign}(\beta_j)\) if \(\beta_j \neq 0\), and \(v_j \in [-1, 1]\) if \(\beta_j = 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate-Wise Optimality (The Correlation Law)&lt;/strong&gt;: Setting \(0 \in -X^T(y - X\beta) + \lambda v\) gives, for every feature \(j = 1, \dots, p\):
    &lt;ul&gt;
      &lt;li&gt;If \(\beta_j^\star \neq 0\): \(X_j^T(y - X\beta^\star) = \lambda \operatorname{sign}(\beta_j^\star)\) (residual correlation hits &lt;em&gt;exactly&lt;/em&gt; \(\pm \lambda\)).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;If \(\beta_j^\star = 0\): $$&lt;/td&gt;
              &lt;td&gt;X_j^T(y - X\beta^\star)&lt;/td&gt;
              &lt;td&gt;\le \lambda\((residual correlation is too weak to overcome the\)\lambda$$ threshold!).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;The Critical Regularization Threshold \(\lambda_{\max}\)&lt;/strong&gt;: Plugging \(\beta^\star = 0\) into the condition shows that &lt;strong&gt;all&lt;/strong&gt; coefficients are zero if and only if $$\lambda \ge \lambda_{\max} = |X^T y|_\infty = \max_j&lt;/td&gt;
          &lt;td&gt;X_j^T y&lt;/td&gt;
          &lt;td&gt;$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equicorrelation &amp;amp; Active Set&lt;/strong&gt;: Every selected (nonzero) feature has the exact same absolute inner product \(\lambda\) with the final residual—the geometric foundation of LARS and coordinate-descent Lasso solvers (like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-checking-lasso-optimality-and-finding-lambda_max&quot;&gt;Worked example: Checking Lasso Optimality and Finding \(\lambda_{\max}\)&lt;/h3&gt;

&lt;p&gt;Consider a 2-feature Lasso problem with orthogonal columns:
\(X = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}, \qquad y = \begin{bmatrix} 5 \\ 1 \end{bmatrix}, \qquad \lambda = 2.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(\lambda_{\max} = \|X^T y\|_\infty\)&lt;/strong&gt;:
\(X^T y = (5, 1)^T \implies \lambda_{\max} = \max(|5|, |1|) = 5.\)
Since \(\lambda = 2 &amp;lt; 5\), at least one feature will be nonzero.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the candidate solution \(\beta^\star = (3, 0)^T\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Residual: \(r = y - X\beta^\star = (5 - 3,\; 1 - 0)^T = (2,\; 1)^T\).&lt;/li&gt;
      &lt;li&gt;Feature correlations \(X^T r = (2,\; 1)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify both coordinate optimality rules at \(\lambda = 2\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Feature 1 (\(\beta_1^\star = 3 &amp;gt; 0\)): \(X_1^T r = 2 = \lambda \operatorname{sign}(3) = +2\) — &lt;strong&gt;satisfied!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Feature 2 (\(\beta_2^\star = 0\)): $$&lt;/td&gt;
              &lt;td&gt;X_2^T r&lt;/td&gt;
              &lt;td&gt;=&lt;/td&gt;
              &lt;td&gt;1&lt;/td&gt;
              &lt;td&gt;= 1 \le \lambda = 2$$ — &lt;strong&gt;satisfied!&lt;/strong&gt;&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;: \(\beta^\star = (3, 0)^T\) satisfies \(0 \in \partial F(\beta^\star)\), so it is the exact global Lasso solution—Feature 2 is cleanly eliminated because its signal (\(1\)) falls below the threshold \(\lambda = 2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the lasso problem given below,&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\min_{\beta} \frac{1}{2}  | y-X\beta |_2^2 + \lambda | \beta |_1
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;where \(y \in \mathbb{R}^n\), \(X \in \mathbb{R}^{n \times p}\), \(\lambda \geq 0\).&lt;/p&gt;

&lt;p&gt;The subgradient optimality condition for this problem can be expressed as:&lt;/p&gt;
&lt;blockquote&gt;

\[\eqalign{
0 \in \partial\left(\frac{1}{2} \| y-X\beta \|_2^2 + \lambda \| \beta \|_1\right)
&amp;amp;\quad \Longleftrightarrow \quad 0 \in - X^T (y-X\beta) + \lambda \partial  \| \beta \|_1 \\
&amp;amp;\quad \Longleftrightarrow \quad X^T (y-X\beta)  = \lambda v \\
&amp;amp; \quad \text{for some } v \in \partial  \| \beta \|_1
}\\\]
&lt;/blockquote&gt;

&lt;p&gt;Here, for a point \(\beta=(\beta_1,\beta_2,\dots,\beta_p )\), the subgradient \(v=(v_1,v_2,\dots,v_p)\) is given by:&lt;/p&gt;

\[v_i = 
\begin{cases}
 1   &amp;amp;\text{if } \beta_i &amp;gt; 0 \\
-1   &amp;amp;\text{if } \beta_i &amp;lt; 0 \\
[-1,1]   &amp;amp;\text{if } \beta_i = 0
\end{cases}
, i \in \{1,2,\dots,p \}\]

&lt;p&gt;Any \(\beta\) satisfying the following is optimal:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
X^T(y-X\beta) = \lambda v 
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is, for the optimal \(\beta\), the following conditions hold:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{cases}
X_i^T(y-X\beta) = \lambda \cdot \text{sign}(\beta_i) &amp;amp;\text{if } \beta_i \neq 0 \\
 |X_i^T(y-X\beta)|  \leq \lambda &amp;amp;\text{if } \beta_i = 0 
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(X_i, i \in \{1,2,\dots, p \}\) denotes the \(i\)th column of the matrix \(X\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03-02 Derivation of First-Order Optimality Condition</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_02_derivation_of_first-order_optimality_condition/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_02_derivation_of_first-order_optimality_condition</id>
   <content type="html">&lt;p&gt;Back in Chapter 04, we proved the constrained first-order optimality condition \(\nabla f(x^\star)^T(y - x^\star) \ge 0\) for all \(y \in C\) using a directional-derivative argument along line segments. Now watch how the machinery of Chapter 07—indicator functions, the sum rule, and normal cones—re-derives that exact theorem in three effortless algebraic lines, revealing it as a special case of \(0 \in \partial(f + I_C)(x^\star)\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-bridging-nonsmooth-calculus-and-constrained-optimality&quot;&gt;Key ideas: Bridging Nonsmooth Calculus and Constrained Optimality&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Encoding Constraints Inside the Objective&lt;/strong&gt;: Rewrite \(\min_{x \in C} f(x)\) as \(\min_{x \in \mathbb{R}^n} \bigl(f(x) + I_C(x)\bigr)\). No constraints remain—only an extended-real-valued convex objective.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Applying the Sum Rule (Under Qualification)&lt;/strong&gt;: Assuming \(f\) is convex and differentiable (and \(C\) is convex), \(\partial(f + I_C)(x^\star) = \{\nabla f(x^\star)\} + \partial I_C(x^\star) = \{\nabla f(x^\star)\} + N_C(x^\star)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unpacking \(0 \in \{\nabla f(x^\star)\} + N_C(x^\star)\)&lt;/strong&gt;: This says precisely that \(-\nabla f(x^\star) \in N_C(x^\star)\). By the definition of the normal cone, \((-\nabla f(x^\star))^T(y - x^\star) \le 0\) for all \(y \in C\)—flipping the sign gives \(\nabla f(x^\star)^T(y - x^\star) \ge 0\) for all \(y \in C\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Immediate Generalization to Nonsmooth Constrained Problems&lt;/strong&gt;: If \(f\) is &lt;em&gt;not&lt;/em&gt; differentiable, the exact same derivation works unchanged: \(x^\star\) minimizes \(f\) over \(C\) iff there exists a subgradient \(g \in \partial f(x^\star)\) such that \(g^T(y - x^\star) \ge 0\) for all \(y \in C\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-deriving-optimality-on-the-probability-simplex&quot;&gt;Worked example: Deriving Optimality on the Probability Simplex&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = \frac{1}{2}(x_1 - 2)^2 + \frac{1}{2}(x_2 - 0)^2\) over the 2D probability simplex \(C = \{x \in \mathbb{R}^2 : x_1 \ge 0,\; x_2 \ge 0,\; x_1 + x_2 = 1\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(\nabla f(x)\)&lt;/strong&gt;: \(\nabla f(x) = (x_1 - 2,\; x_2)^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the candidate vertex \(x^\star = (1, 0) \in C\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Gradient at \(x^\star\): \(\nabla f(1, 0) = (-1,\; 0)^T\), so \(-\nabla f(1, 0) = (1,\; 0)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify \(-\nabla f(x^\star) \in N_C(x^\star)\) directly&lt;/strong&gt;:
For any feasible \(y = (y_1, y_2) \in C\), we have \(y_1 \le 1\), so \(y_1 - 1 \le 0\). Therefore:
\((-\nabla f(x^\star))^T (y - x^\star) = 1(y_1 - 1) + 0(y_2 - 0) = y_1 - 1 \le 0.\)
Equivalently, \(\nabla f(x^\star)^T(y - x^\star) = 1 - y_1 \ge 0\) for every \(y \in C\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;: Because \(0 = \nabla f(1, 0) + (-\nabla f(1, 0)) \in \{\nabla f(1, 0)\} + N_C(1, 0)\), \(x^\star = (1, 0)\) is the exact constrained minimizer (with \(f^\star = 0.5\)).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;first-order-optimality-condition&quot;&gt;&lt;strong&gt;First-order optimality condition:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;If \(f\) is convex and differentiable, the subgradient optimality condition coincides with the first-order optimality condition, as shown below.&lt;/p&gt;

\[x^* \text{ is optimal} \quad \Longleftrightarrow \quad \nabla f(x^*)^T(y - x^*) \geq 0, \text{ for all } y \in C\]

&lt;h3 id=&quot;proof&quot;&gt;Proof&lt;/h3&gt;
&lt;blockquote&gt;

\[\begin{alignat}{2}
f(x^{*}) = \min_{x\in C} f(x)  \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp; \quad f(x^{*}) = \min_x f(x) + I_C(x) \\
                      \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp;\quad 0 \in \partial(f(x^{*}) + I_C(x^{*})) \\
                      \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp;\quad 0 \in \{\nabla f(x^{*}) \} + \mathcal{N}_C(x^{*}) \\
                      \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp;\quad - \nabla f(x^{*}) \in \mathcal{N}_C(x^{*}) \\
                      \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp;\quad - \nabla f(x^{*})^Tx^{*} \geq -\nabla f(x^{*})^Ty, \text{ for all }  y \in C \\
                      \quad &amp;amp; \Longleftrightarrow &amp;amp; &amp;amp;\quad \nabla f(x^{*})^T(y-x^{*}) \geq 0, \text{ for all } y \in C 
\end{alignat}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03-01 Subgradient Optimality Condition</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_01_subgradient_optimality_condition/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_03_01_subgradient_optimality_condition</id>
   <content type="html">&lt;p&gt;Some of the deepest theorems in mathematics have the shortest proofs. The &lt;strong&gt;Subgradient Optimality Condition&lt;/strong&gt;—\(x^\star\) minimizes \(f\) globally if and only if \(0 \in \partial f(x^\star)\)—takes literally two lines to prove straight from the definition of a subgradient, yet it replaces separate optimality tests for smooth, nonsmooth, and constrained convex problems with one unified criterion.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-0-in-partial-fxstar-works-universally&quot;&gt;Key ideas: Why \(0 \in \partial f(x^\star)\) Works Universally&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Direct Equivalence with the Definition&lt;/strong&gt;: Plugging \(g = 0\) into the subgradient inequality \(f(y) \ge f(x^\star) + g^T(y - x^\star)\) gives \(f(y) \ge f(x^\star) + 0 = f(x^\star)\) for all \(y\)—which is &lt;em&gt;literally&lt;/em&gt; the definition of \(x^\star\) being a global minimizer!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;No Differentiability Needed&lt;/strong&gt;: Unlike Fermat’s theorem \(f&apos;(x^\star) = 0\), which fails at kinks (like $$&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;\(at\)0\(),\)0 \in \partial f(x^\star)$$ handles smooth valleys, sharp V-shaped bottoms, and flat plateaus identically.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric Meaning — Horizontal Supporting Hyperplane&lt;/strong&gt;: Saying \(0 \in \partial f(x^\star)\) means you can slide a completely &lt;em&gt;flat, horizontal&lt;/em&gt; plane \(z = f(x^\star)\) underneath the graph of \(f\) touching at \(x^\star\)—proving no point of the graph dips below \(f(x^\star)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Convexity Still Matters for Computation&lt;/strong&gt;: Although the two-line equivalence holds for any function, a nonconvex function has an &lt;em&gt;empty&lt;/em&gt; global subdifferential at local (non-global) minima. Convexity guarantees \(\partial f(x)\) is non-empty and computable via local calculus rules.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-finding-the-geometric-median-in-1d-via-0-in-partial-fxstar&quot;&gt;Worked example: Finding the Geometric Median in 1D via \(0 \in \partial f(x^\star)\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize the sum of absolute deviations $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x - 4&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x - 10&lt;/td&gt;
      &lt;td&gt;\(over\)x \in \mathbb{R}$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the subdifferential \(\partial f(x)\) using the addition rule&lt;/strong&gt;:
\(\partial f(x) = \partial |x - 1| + \partial |x - 4| + \partial |x - 10|.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the candidate \(x = 4\) (the median of \(\{1, 4, 10\}\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Since \(4 &amp;gt; 1\): $$\partial&lt;/td&gt;
              &lt;td&gt;x - 1&lt;/td&gt;
              &lt;td&gt;\big&lt;/td&gt;
              &lt;td&gt;_{x=4} = {+1}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Since \(4 = 4\): $$\partial&lt;/td&gt;
              &lt;td&gt;x - 4&lt;/td&gt;
              &lt;td&gt;\big&lt;/td&gt;
              &lt;td&gt;_{x=4} = [-1, 1]$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Since \(4 &amp;lt; 10\): $$\partial&lt;/td&gt;
              &lt;td&gt;x - 10&lt;/td&gt;
              &lt;td&gt;\big&lt;/td&gt;
              &lt;td&gt;_{x=4} = {-1}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Minkowski sum: \(\partial f(4) = \{1\} + [-1, 1] + \{-1\} = [-1, 1]\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify \(0 \in \partial f(4)\)&lt;/strong&gt;: Since \(0 \in [-1, 1]\) (picking \(g_1 = 1, g_2 = 0, g_3 = -1\) sums to \(0\)), \(x^\star = 4\) is certified as the &lt;strong&gt;exact global minimizer&lt;/strong&gt; with \(f(4) = 3 + 0 + 6 = 9\)! (Notice that for an even number of points, say \(\{1, 4, 6, 10\}\), \(0 \in \partial f(x)\) holds on the entire median interval \([4, 6]\).)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;lemma&quot;&gt;Lemma&lt;/h3&gt;

&lt;p&gt;For any function \(f\), the condition that \(x^*\) is a minimizer of \(f\) and that \(0\) is a subgradient at \(x^*\) are equivalent:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{equation}
f(x^*) = \min_x f(x) \Longleftrightarrow 0 \in \partial f(x^*)
\end{equation}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;proof&quot;&gt;Proof&lt;/h3&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp;f(x^*) = \min_x f(x)\\
\Longleftrightarrow &amp;amp;f(y) \geq f(x^*) \text{ for all } y\\
\Longleftrightarrow &amp;amp;f(y) \geq f(x^*) + 0^T(y-x^*)\\
\Longleftrightarrow &amp;amp;0 \in \partial f(x^*)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Note that convexity of \(f\) is not used in this proof, so this optimality condition applies even to non-convex functions.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>07-02 Sub-differentials</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_02_subdifferentials/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_02_subdifferentials</id>
   <content type="html">&lt;p&gt;At a kink, picking just one subgradient tells only part of the story—to test optimality or combine functions algebraically, we need the &lt;em&gt;entire collection&lt;/em&gt; of valid slopes at once. That set, denoted \(\partial f(x)\), is the &lt;strong&gt;subdifferential&lt;/strong&gt;. Even when \(f\) is nonsmooth (or even nonconvex!), \(\partial f(x)\) obeys remarkably clean topological laws that make set-valued calculus possible.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-structural-properties-of-the-subdifferential&quot;&gt;Key ideas: Structural Properties of the Subdifferential&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always Closed and Convex&lt;/strong&gt;: By definition, \(\partial f(x) = \bigcap_{y \in \operatorname{dom}(f)} \{g \in \mathbb{R}^n : g^T(y - x) \le f(y) - f(x)\}\). Because it is an intersection of closed halfspaces in \(g\), \(\partial f(x)\) is &lt;em&gt;always&lt;/em&gt; a closed convex set—even if \(f\) itself is nonconvex!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-Empty and Bounded on the Interior&lt;/strong&gt;: For any finite convex function \(f: \mathbb{R}^n \to \mathbb{R}\), \(\partial f(x)\) is guaranteed to be non-empty and compact (closed and bounded) at every \(x \in \mathbb{R}^n\). (At boundary points of a restricted domain, \(\partial f(x)\) can be empty—for instance, \(f(x) = -\sqrt{x}\) on \(x \ge 0\) has \(\partial f(0) = \emptyset\) because its slope is \(-\infty\).)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Singleton Characterization of Differentiability&lt;/strong&gt;: For a convex function \(f\), \(f\) is differentiable at \(x\) if and only if \(\partial f(x)\) contains exactly one element, in which case \(\partial f(x) = \{\nabla f(x)\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Directional Derivatives via Support Function&lt;/strong&gt;: The directional derivative of \(f\) at \(x\) in direction \(v\) equals the maximum inner product over the subdifferential: \(f&apos;(x; v) = \max_{g \in \partial f(x)} g^T v\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-computing-the-full-subdifferential-of-a-piecewise-linear-function&quot;&gt;Worked example: Computing the Full Subdifferential of a Piecewise-Linear Function&lt;/h3&gt;

&lt;p&gt;Compute \(\partial f(x)\) at every point \(x \in \mathbb{R}\) for \(f(x) = \max\{-2x,\; x - 3,\; 3x - 9\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Locate where the three linear branches intersect&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(-2x = x - 3 \implies 3x = 3 \implies x = 1\) (value \(-2\); third branch is \(3(1) - 9 = -6 &amp;lt; -2\)).&lt;/li&gt;
      &lt;li&gt;\(x - 3 = 3x - 9 \implies 2x = 6 \implies x = 3\) (value \(0\); first branch is \(-6 &amp;lt; 0\)).&lt;/li&gt;
      &lt;li&gt;Therefore:
\(f(x) = \begin{cases} -2x &amp;amp; x &amp;lt; 1, \\ x - 3 &amp;amp; 1 \le x \le 3, \\ 3x - 9 &amp;amp; x &amp;gt; 3. \end{cases}\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write \(\partial f(x)\) on each smooth interval and each kink&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(x &amp;lt; 1\): \(\partial f(x) = \{-2\}\).&lt;/li&gt;
      &lt;li&gt;\(x = 1\) (branches \(-2x\) and \(x - 3\) tie): \(\partial f(1) = \operatorname{conv}\{-2, 1\} = [-2, 1]\).&lt;/li&gt;
      &lt;li&gt;\(1 &amp;lt; x &amp;lt; 3\): \(\partial f(x) = \{1\}\).&lt;/li&gt;
      &lt;li&gt;\(x = 3\) (branches \(x - 3\) and \(3x - 9\) tie): \(\partial f(3) = \operatorname{conv}\{1, 3\} = [1, 3]\).&lt;/li&gt;
      &lt;li&gt;\(x &amp;gt; 3\): \(\partial f(x) = \{3\}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Spot the global minimizer immediately&lt;/strong&gt;: The only point where \(0 \in \partial f(x)\) is \(x^\star = 1\) (since \(0 \in [-2, 1]\)), giving \(f^\star = -2\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The subdifferential \(\partial f(x)\) of a convex function \(f\) at a point \(x\) is the set of all subgradients at \(x\):&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\partial f(x) = {g \in \mathbb{R}^n | \text{g is a subgradient of f at x} }
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The subdifferential has the following properties:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(\partial f(x)\) is always a closed convex set, whether \(f\) is convex or not.&lt;/li&gt;
  &lt;li&gt;If \(f\) is convex, \(\partial f(x)\) always contains at least one element; if \(f\) is not convex, it may be empty.&lt;/li&gt;
  &lt;li&gt;If \(f\) is differentiable and convex at \(x\), then \(\partial f(x) = \{\nabla f(x)\}\).&lt;/li&gt;
  &lt;li&gt;If \(\partial f(x) = \{g\}\), then \(f\) is differentiable at \(x\) and \(\nabla f(x) = g\).&lt;/li&gt;
&lt;/ul&gt;

</content>
 </entry>
 
 <entry>
   <title>07-02-02 Subgradient Calculus</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_02_02_subgradient_calculus/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_02_02_subgradient_calculus</id>
   <content type="html">&lt;p&gt;Nobody computes ordinary derivatives of complicated expressions by taking \(\lim_{h \to 0}\) from scratch every time—we use the sum rule, chain rule, and product rule. Subgradients have their own compact &lt;strong&gt;subgradient calculus&lt;/strong&gt; (scaling, Minkowski addition, affine composition, and pointwise maxima) that lets you assemble \(\partial f(x)\) for Lasso, SVMs, and composite losses in seconds.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-five-workhorse-rules-of-subgradient-calculus&quot;&gt;Key ideas: The Five Workhorse Rules of Subgradient Calculus&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nonnegative Scaling&lt;/strong&gt;: For \(a &amp;gt; 0\), \(\partial(af)(x) = a\,\partial f(x)\). (Crucial warning: multiplying by \(a &amp;lt; 0\) flips convexity to concavity, so scaling only holds for \(a &amp;gt; 0\)!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minkowski Addition&lt;/strong&gt;: For convex functions \(f_1, f_2\) (whose domains overlap properly, e.g., finite on \(\mathbb{R}^n\)), \(\partial(f_1 + f_2)(x) = \partial f_1(x) + \partial f_2(x) = \{g_1 + g_2 : g_1 \in \partial f_1(x),\; g_2 \in \partial f_2(x)\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine Composition (Chain Rule)&lt;/strong&gt;: If \(h(x) = f(Ax + b)\), then \(\partial h(x) = A^T \partial f(Ax + b) = \{A^T g : g \in \partial f(Ax + b)\}\). This single rule handles \(\|Ax - b\|_1\) and hinge losses \(\max(0, 1 - y_i w^T x_i)\) effortlessly.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Finite Pointwise Maximum&lt;/strong&gt;: If \(f(x) = \max_{i=1,\dots,m} f_i(x)\), let \(I(x) = \{i : f_i(x) = f(x)\}\) be the &lt;em&gt;active&lt;/em&gt; indices achieving the max at \(x\). Then
\(\partial f(x) = \operatorname{conv}\!\left(\bigcup_{i \in I(x)} \partial f_i(x)\right).\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-combining-affine-composition-and-addition&quot;&gt;Worked example: Combining Affine Composition and Addition&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Compute the subdifferential of $$f(x_1, x_2) = 3&lt;/td&gt;
      &lt;td&gt;x_1 - x_2&lt;/td&gt;
      &lt;td&gt;+ \frac{1}{2}x_1^2\(at the kink point\)x = (2, 2)$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Decompose \(f = f_1 + f_2\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;$$f_1(x) = 3&lt;/td&gt;
              &lt;td&gt;a^T x&lt;/td&gt;
              &lt;td&gt;\(where\)a = (1, -1)^T\((scaling + affine composition of\)&lt;/td&gt;
              &lt;td&gt;\cdot&lt;/td&gt;
              &lt;td&gt;$$).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;\(f_2(x) = \frac{1}{2}x_1^2\) (smooth convex function).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(\partial f_1(2, 2)\) via affine composition and scaling&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Evaluate \(a^T x = 2 - 2 = 0\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Since $$\partial&lt;/td&gt;
              &lt;td&gt;\cdot&lt;/td&gt;
              &lt;td&gt;(0) = [-1, 1]\(, the affine composition rule gives\)\partial&lt;/td&gt;
              &lt;td&gt;a^T x&lt;/td&gt;
              &lt;td&gt;\big&lt;/td&gt;
              &lt;td&gt;_{(2,2)} = {s a : s \in [-1, 1]}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Scaling by \(3 &amp;gt; 0\) gives
\(\partial f_1(2, 2) = \left\{\begin{bmatrix} 3s \\ -3s \end{bmatrix} : s \in [-1, 1]\right\}\)
(the line segment connecting \((-3, 3)\) and \((3, -3)\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(\partial f_2(2, 2)\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Since \(f_2\) is differentiable, \(\partial f_2(2, 2) = \{\nabla f_2(2, 2)\} = \{(2, 0)^T\}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Add the two sets (Minkowski sum)&lt;/strong&gt;:
\(\partial f(2, 2) = \left\{\begin{bmatrix} 2 + 3s \\ -3s \end{bmatrix} : s \in [-1, 1]\right\},\)
which is the line segment from \((-1, 3)\) to \((5, -3)\). (Notice \((0, 0)\) is &lt;em&gt;not&lt;/em&gt; on this segment because setting \(-3s = 0 \implies s = 0$ gives\)(2, 0) \neq (0, 0)\(, proving\)(2, 2)$$ is not the minimizer.)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The following basic rules hold for the subdifferential of convex functions:&lt;/p&gt;

&lt;h3 id=&quot;scaling&quot;&gt;Scaling&lt;/h3&gt;

&lt;blockquote&gt;

\[\eqalign{
	ext{if } &amp;amp; a&amp;gt;0, \\
	ext{then } &amp;amp;\partial (af) = a\cdot \partial f
}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;addition&quot;&gt;Addition&lt;/h3&gt;

&lt;blockquote&gt;

\[\partial(f_1 + f_2) = \partial f_1 + \partial f_2\]
&lt;/blockquote&gt;

&lt;p&gt;Here, the sum of two sets \(A+B= \{a+b:a\in A, b \in B\}\) is defined as the set of all possible sums.&lt;/p&gt;

&lt;h3 id=&quot;affine-composition&quot;&gt;Affine composition&lt;/h3&gt;

&lt;blockquote&gt;

\[\eqalign{
	ext{if } &amp;amp; g(x)=f(Ax+b), \\
	ext{then } &amp;amp; \partial g(x) = A^T \partial f(Ax+b)
}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;finite-pointwise-maximum&quot;&gt;Finite pointwise maximum&lt;/h3&gt;

&lt;blockquote&gt;

\[\eqalign{
	ext{if } &amp;amp; f(x)=\max_{i=1,\dots,m} f_i(x), \\
	ext{then } &amp;amp; \partial f(x) = \text{conv}\left(\bigcup_{i:f_i(x)=f(x)} \partial f_i(x)\right)
}\]
&lt;/blockquote&gt;

&lt;p&gt;That is, \(\partial f(x)\) is defined as the convex hull of the union of the subdifferentials of the functions attaining the value \(f(x)\) at \(x\).&lt;/p&gt;

&lt;h3 id=&quot;general-pointwise-maximum&quot;&gt;General pointwise maximum&lt;/h3&gt;

&lt;blockquote&gt;
\[\eqalign{
	ext{if } &amp;amp; f(x) = \max_{s \in S} f_s(x),\\ 
	ext{then } &amp;amp; \partial f(x) \supseteq cl \left \{ \text{conv} \left(\bigcup_{s:f_s(x)=f(x)} \partial f_s(x)\right) \right\}
}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(S\) may be an infinite set, so the union of infinitely many sets may not be closed. Therefore, we take the closure to ensure the subdifferential is a closed set.&lt;/p&gt;

&lt;p&gt;On the other hand, if the set \(S\) is compact (closed and bounded) and the functions \(f_s\) are continuous with respect to \(s\), then the equality holds.&lt;/p&gt;

&lt;p&gt;For example, consider the following p-norm function \(f(x)\):&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
f(x) =  \vert  \vert x \vert  \vert _p = \max_{ \vert  \vert z \vert  \vert _q \leq 1} z^Tx, \qquad 1/p + 1/q =1
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If we let \(f_z(x)=z^Tx\), then \(z^*\) such that \(f(x)=f_{z^*}(x)\) belongs to \(\arg\max_{ \vert  \vert z \vert  \vert _q \leq 1} z^Tx\).&lt;/p&gt;

&lt;p&gt;Since \(\partial f_{z^*}(x)=z^*\), the union \(\bigcup \partial f_{z^*}(x)\) is the union of all \(z^*\), which gives us \(\partial f(x) = \arg\max_{ \vert  \vert z \vert  \vert _q \leq 1} z^Tx\).&lt;/p&gt;

&lt;p&gt;Here, \(S=\{z: \vert  \vert z \vert  \vert _q \leq 1\}\) is a compact set, and \(f_z(x)=z^Tx\) is linear.&lt;/p&gt;

&lt;p&gt;By the general pointwise maximum rule, taking the convex hull and then the closure of \(\bigcup \partial f_{z^*}(x)\) does not add any additional elements to the set.&lt;/p&gt;

&lt;p&gt;Therefore, the subgradient of the function \(f(x)\) is as follows:&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\partial f(x) = \arg\max_{ \vert  \vert z \vert  \vert _q \leq 1} z^T x
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>07-02-01 Connection to a Convexity Geometry</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_02_01_connection_to_a_convexity_geometry/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_02_01_connection_to_a_convexity_geometry</id>
   <content type="html">&lt;p&gt;At first, &lt;em&gt;constrained&lt;/em&gt; optimization (staying inside a convex set \(C\)) and &lt;em&gt;nonsmooth unconstrained&lt;/em&gt; optimization seem like two different worlds. A single brilliant trick from convex analysis unifies them completely: encode the constraint \(x \in C\) as the &lt;strong&gt;indicator function&lt;/strong&gt; \(I_C(x)\) (which equals \(0\) inside \(C\) and \(+\infty\) outside \(C\)). The moment you take the subdifferential of \(I_C(x)\), pure geometry jumps off the page—\(\partial I_C(x)\) is literally the &lt;strong&gt;normal cone&lt;/strong&gt; \(N_C(x)\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-indicator-functions-and-normal-cones&quot;&gt;Key ideas: Indicator Functions and Normal Cones&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;The Indicator Function \(I_C(x)\)&lt;/strong&gt;: Defined as \(I_C(x) = 0\) for \(x \in C\) and \(I_C(x) = +\infty\) for \(x \notin C\). It is convex if and only if \(C\) is a convex set, and turns any constrained problem \(\min_{x \in C} f(x)\) into the unconstrained problem \(\min_{x \in \mathbb{R}^n} \bigl(f(x) + I_C(x)\bigr)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Identity \(\partial I_C(x) = N_C(x)\)&lt;/strong&gt;: For \(x \in C\), \(g \in \partial I_C(x)\) means \(I_C(y) \ge 0 + g^T(y - x)\) for all \(y\). For \(y \notin C\) this holds automatically (\(+\infty \ge \text{finite}\)); for \(y \in C\) it reduces to \(g^T(y - x) \le 0\)—the exact definition of the &lt;strong&gt;normal cone&lt;/strong&gt; \(N_C(x)\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior vs. Boundary Geometry&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;At an &lt;em&gt;interior&lt;/em&gt; point \(x \in \operatorname{int}(C)\), you can move in every direction inside \(C\), forcing \(N_C(x) = \{0\}\).&lt;/li&gt;
      &lt;li&gt;At a &lt;em&gt;boundary&lt;/em&gt; point \(x \in \partial C\), \(N_C(x)\) is the outward-pointing cone of vectors forming an obtuse or right angle with every feasible direction \(y - x\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why This Connection Matters&lt;/strong&gt;: Adding \(I_C(x)\) to \(f(x)\) and applying \(0 \in \partial(f + I_C)(x^\star) = \partial f(x^\star) + N_C(x^\star)\) immediately derives the first-order constrained optimality condition of Chapter 04 and powers Proximal Gradient Descent (where the prox of \(I_C\) is Euclidean projection \(P_C\)!).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-computing-normal-cones-of-the-unit-box-c--0-12&quot;&gt;Worked example: Computing Normal Cones of the Unit Box \(C = [0, 1]^2\)&lt;/h3&gt;

&lt;p&gt;Let \(C = [0, 1] \times [0, 1]\) be the unit square in \(\mathbb{R}^2\). Compute \(\partial I_C(x) = N_C(x)\) at three distinct points: an interior point, an edge midpoint, and a corner.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Interior point \(x = (0.5, 0.5)\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Small perturbations \(y = x \pm \epsilon e_1\) and \(y = x \pm \epsilon e_2\) all stay in \(C\).&lt;/li&gt;
      &lt;li&gt;Requiring \(g^T(\pm \epsilon e_i) \le 0\) forces \(g_1 = 0\) and \(g_2 = 0\). Thus \(N_C(0.5, 0.5) = \{(0, 0)\}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Right-edge midpoint \(x = (1, 0.5)\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;For any \(y \in [0, 1]^2\), we have \(y_1 - 1 \le 0\) while \(y_2 - 0.5\) can be either positive or negative.&lt;/li&gt;
      &lt;li&gt;To ensure \(g_1(y_1 - 1) + g_2(y_2 - 0.5) \le 0\) for all \(y \in C\), we must have \(g_1 \ge 0\) and \(g_2 = 0\).&lt;/li&gt;
      &lt;li&gt;Thus \(N_C(1, 0.5) = \{(g_1, 0) : g_1 \ge 0\}\) (the horizontal ray pointing straight out to the right).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Top-right corner \(x = (1, 1)\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;For all \(y \in [0, 1]^2\), both \(y_1 - 1 \le 0\) and \(y_2 - 1 \le 0\).&lt;/li&gt;
      &lt;li&gt;Hence \(g_1(y_1 - 1) + g_2(y_2 - 1) \le 0\) holds for &lt;em&gt;all&lt;/em&gt; \(g_1 \ge 0, g_2 \ge 0\)!&lt;/li&gt;
      &lt;li&gt;Thus \(N_C(1, 1) = \mathbb{R}^2_+\) (the entire first quadrant, fanning out at \(90^\circ\) from the corner).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For a convex set \(C \subseteq \mathbb{R}^n\), consider the indicator function \(I_C: \mathbb{R}^n \to \mathbb{R}\) defined as:&lt;/p&gt;

&lt;blockquote&gt;

\[I_C(x) = I\{x \in C \} =
\begin{cases}
0               &amp;amp;\text{if } x \in C \\
\infty         &amp;amp;\text{if } x \notin C 
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;The subdifferential of this function has the following geometric meaning:&lt;/p&gt;

&lt;h3 id=&quot;lemma&quot;&gt;Lemma&lt;/h3&gt;
&lt;p&gt;For \(x \in C\), the subdifferential \(\partial I_C(x)\) coincides with the normal cone \(\mathcal{N}_C(x)\) to the set \(C\) at \(x\):&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
\mathcal{N}_C(x) = {g \in \mathbb{R}^n | g^Tx \geq g^Ty \text{  for all  } y \in C }
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;proof&quot;&gt;Proof&lt;/h3&gt;

&lt;p&gt;By definition, the subgradient must satisfy:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
I_C(y) \geq I_C(x) + g^T(y-x) \text{ for all } y
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, \(x \in C\) and \(I_C(x)=0\), so:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
I_C(y) \geq g^T(y-x) \text{ for all } y
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First, for all \(y \in C\), we have:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
I_C(y) = 0 \geq g^T(y-x)
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thus, the subgradient \(g\) must satisfy \(g^Tx \geq g^Ty\).&lt;/p&gt;

&lt;p&gt;Second, for all \(y \notin C\), \(I_C(y) = \infty\), so the inequality holds for any value of \(g\):&lt;/p&gt;
&lt;blockquote&gt;

\[I_C(y)=\infty \geq g^T(y-x)\]
&lt;/blockquote&gt;

&lt;p&gt;which is always true.&lt;/p&gt;

&lt;p&gt;Since the subgradient must satisfy both conditions above, the subgradient for this function becomes:&lt;/p&gt;
&lt;blockquote&gt;

\[\{g \in \mathbb{R}^n | g^Tx \geq g^Ty\}\]
&lt;/blockquote&gt;

&lt;p&gt;This completes the proof.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter07/07_02_subgrad-5.png&quot; alt=&quot;connection_to_convexity_geometry&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Normal cone [1]&lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>07-01 Subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_01_subgradient/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_01_subgradient</id>
   <content type="html">&lt;p&gt;At a smooth point on a convex bowl, you can lay a flat wooden board underneath the bowl and there is only one angle that touches it without poking through—the tangent plane. Now press that same board underneath the sharp tip of a V-shaped cone: suddenly you can rock the board back and forth across a whole range of angles, and &lt;em&gt;every&lt;/em&gt; tilt still supports the cone from below! Every valid tilt is a &lt;strong&gt;subgradient&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-definition-and-geometry-of-subgradients&quot;&gt;Key ideas: Definition and Geometry of Subgradients&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;The Global Underestimator Inequality&lt;/strong&gt;: A vector \(g \in \mathbb{R}^n\) is a subgradient of \(f\) at \(x\) if
\(f(y) \ge f(x) + g^T(y - x) \quad \text{for all } y \in \operatorname{dom}(f).\)
Notice this is a &lt;em&gt;global&lt;/em&gt; inequality—not a local limit—which is why it works cleanly at corners where two-sided limits fail to exist.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Consistency with Gradients&lt;/strong&gt;: If \(f\) is convex and differentiable at \(x\), then \(\nabla f(x)\) is the &lt;em&gt;unique&lt;/em&gt; subgradient at \(x\). Conversely, if a convex function has a unique subgradient at an interior point \(x\), then \(f\) is differentiable at \(x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Existence Everywhere in the Interior&lt;/strong&gt;: Every convex function has at least one subgradient at every point in the relative interior of its domain (guaranteed by the Supporting Hyperplane Theorem applied to the convex epigraph \(\operatorname{epi}(f)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Canonical Nonsmooth Building Blocks&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Absolute value $$&lt;/td&gt;
              &lt;td&gt;x&lt;/td&gt;
              &lt;td&gt;\(:\)g = \operatorname{sign}(x)\(for\)x \neq 0\(, and any\)g \in [-1, 1]\(at\)x = 0$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Euclidean norm \(\|x\|_2\): \(g = x/\|x\|_2\) for \(x \neq 0\), and any \(\|g\|_2 \le 1\) at \(x = 0\).&lt;/li&gt;
      &lt;li&gt;Pointwise maximum \(\max\{f_1(x), f_2(x)\}\): any convex combination of gradients of the &lt;em&gt;active&lt;/em&gt; branches achieving the maximum.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-verifying-subgradients-of-fx--x_2-at-x--0&quot;&gt;Worked example: Verifying Subgradients of \(f(x) = \|x\|_2\) at \(x = 0\)&lt;/h3&gt;

&lt;p&gt;For the Euclidean norm \(f(x) = \|x\|_2\) on \(\mathbb{R}^2\), verify directly from the definition which vectors \(g \in \mathbb{R}^2\) are subgradients at \(x = (0, 0)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Plug \(x = 0\) into the subgradient inequality&lt;/strong&gt;:
\(\|y\|_2 \ge \|0\|_2 + g^T(y - 0) \iff g^T y \le \|y\|_2 \quad \text{for all } y \in \mathbb{R}^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test a valid vector \(g = (0.6, 0.8)\)&lt;/strong&gt; (with \(\|g\|_2 = \sqrt{0.36 + 0.64} = 1\)):
    &lt;ul&gt;
      &lt;li&gt;By Cauchy–Schwarz, \(g^T y \le \|g\|_2 \|y\|_2 = 1 \cdot \|y\|_2 = \|y\|_2\) for every \(y \in \mathbb{R}^2\).&lt;/li&gt;
      &lt;li&gt;Hence \(g = (0.6, 0.8)\) &lt;strong&gt;is a valid subgradient&lt;/strong&gt; at \(0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test an invalid vector \(g = (1, 1)\)&lt;/strong&gt; (with \(\|g\|_2 = \sqrt{2} &amp;gt; 1\)):
    &lt;ul&gt;
      &lt;li&gt;Choose \(y = g = (1, 1)\). Then \(g^T y = 1 + 1 = 2\), whereas \(\|y\|_2 = \sqrt{2} \approx 1.414 &amp;lt; 2\).&lt;/li&gt;
      &lt;li&gt;The inequality \(f(y) \ge g^T y\) fails! Thus \(g = (1, 1)\) pokes &lt;em&gt;above&lt;/em&gt; the cone and is &lt;strong&gt;not&lt;/strong&gt; a subgradient.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;: \(\partial \|0\|_2 = \{g \in \mathbb{R}^2 : \|g\|_2 \le 1\}\), the closed unit Euclidean ball.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;subgradient&quot;&gt;Subgradient&lt;/h1&gt;

&lt;p&gt;For a convex function \(f:\mathbb{R}^n \to \mathbb{R}\), a subgradient at \(x\) is any vector \(g \in \mathbb{R}^n\) that satisfies:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{equation}\label{subgradient}
f(y) \geq f(x) + g^T(y-x), \text{ for all } y
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;The subgradient defined above:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Generalizes the gradient for convex functions to cases where the function is not differentiable.&lt;/li&gt;
  &lt;li&gt;For convex functions, a subgradient always exists. If \(f\) is differentiable at \(x\), then \(\nabla f(x)\) is the unique subgradient.&lt;/li&gt;
  &lt;li&gt;For non-convex functions, a subgradient may be defined similarly, but it may not always exist depending on the function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below are examples of subgradients for some functions.&lt;/p&gt;

&lt;h3 id=&quot;example-1&quot;&gt;Example 1&lt;/h3&gt;

&lt;center&gt;
$$f:\mathbb{R} \to \mathbb{R}, f(x) =  \vert x \vert $$
&lt;/center&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter07/07_01_subgrad-1.png&quot; alt=&quot;Subgradient1&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig 1] Subgradient of } f(x)= \vert x \vert \text{ [3]}$$&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;For \(x \neq 0\), \(\vert y \vert \geq \vert x \vert + g^T(y-x)\) must hold. That is,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;\(\vert y \vert - g^Ty \geq \vert x \vert - g^Tx\). If \(\vert x \vert - g^Tx = 0\), i.e., \(g=\text{sign}(x)\), then the condition holds for all \(y\). Thus, \(g=\text{sign}(x)\) (&lt;a href=&quot;https://en.wikipedia.org/wiki/Sign_function&quot;&gt;Wikipedia: Sign function&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;For \(x=0\), \(\vert y \vert \geq g^Ty\) must hold. Therefore, \(g \in [-1,1]\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example-2&quot;&gt;Example 2&lt;/h3&gt;

&lt;center&gt;
$$f:\mathbb{R}^n \to \mathbb{R}, f(x) =  \| x \|_1$$ 
&lt;/center&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter07/07_01_subgrad-3.png&quot; alt=&quot;Subgradient2&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig 2] Subgradient of }f(x)= \| x \|_1\text{ [3]}$$&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;At a point \(x=(x_1,x_2,\dots,x_n)\),&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;For \(x_i \neq 0, i \in \{1,2,\dots,n\}\), since it is differentiable at \(x_i\), we have \(g_i=\text{sign}(x_i)\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;For \(x_i=0, i \in \{1,2,\dots,n\}\), we have \(g_i \in [-1,1]\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example3&quot;&gt;Example3&lt;/h3&gt;

&lt;center&gt;
$$f:\mathbb{R}^n \to \mathbb{R}, f(x) =  \vert x \vert _2$$
&lt;/center&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter07/07_01_subgrad-2.png&quot; alt=&quot;Subgradient3&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig 3] Subgradient of }f(x)= \vert x \vert _2\text{ [3]}$$&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;For \(x \neq 0\), since it is differentiable, we have \(g=\nabla \sqrt{x^Tx} = \frac{1}{2}(x^Tx)^{-\frac{1}{2}} (2x) = \frac{x}{\vert x \vert _2}\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;For \(x=0\), we have \(\vert y \vert _2 \geq g^Ty \Longrightarrow  \vert y \vert _2 \geq  \vert g \vert _2 \vert y \vert _2 \cos \theta\). Therefore, \(g \in \{z: \vert z \vert _2 \leq 1 \}\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example4&quot;&gt;Example4&lt;/h3&gt;

&lt;p&gt;\(f(x) = \max f_1(x),f_2(x)\), where \(f_1,f_2:\mathbb{R}^n \to \mathbb{R}\) are both convex and differentiable functions.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter07/07_01_subgrad-4.png&quot; alt=&quot;Subgradient4&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig 4] Subgradient of }f(x)=\max f_1(x),f_2(x) \text{ [3]}$$&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;For \(f_1(x) &amp;gt; f_2(x)\), we have \(g = \nabla f_1(x)\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;For \(f_1(x) &amp;lt; f_2(x)\), we have \(g = \nabla f_2(x)\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;For \(f_1(x) = f_2(x)\), we have \(g \in \{\theta_1 \nabla f_1(x) + \theta_2 \nabla f_2(x): \theta_1 + \theta_2 = 1, \theta_1 \geq 0, \theta_2 \geq 0 \}\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;subgradients-at-a-kink&quot;&gt;Subgradients at a kink&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/subgradient-fan_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;At a kink of \(f(x)=\max_i f_i(x)\), many lines stay below the graph and touch it at that point; every one of their slopes is a subgradient.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-subgradients-at-a-kink&quot;&gt;Try it yourself: subgradients at a kink&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;subg&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>07 Subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_00_subgradient/"/>
   <updated>2021-03-25T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter07/07_00_subgradient</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Smooth curves are comfortable, but the most powerful models in modern data science are full of sharp corners: the kink of $$&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(at zero in Lasso, the hinge of\)\max(0, 1 - z)\(in SVMs, the bend of\)\mathrm{ReLU}(z) = \max(0, z)$$ in every deep neural network, and the hard walls of constrained sets. Ordinary derivatives shatter at every corner. Chapter 07 introduces the &lt;strong&gt;subgradient&lt;/strong&gt;—the exact geometric generalization of the derivative that keeps global optimality alive even when functions have kinks!&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;key-ideas-navigating-nonsmooth-convex-analysis&quot;&gt;Key ideas: Navigating Nonsmooth Convex Analysis&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Supporting Hyperplanes Replace Tangent Planes&lt;/strong&gt;: Where a smooth convex function has one unique tangent hyperplane (defined by \(\nabla f(x)\)), a convex function at a kink admits an entire fan of &lt;em&gt;supporting hyperplanes&lt;/em&gt; staying globally below its graph: \(f(y) \ge f(x) + g^T(y - x)\) for all \(y\). Every such slope vector \(g\) is a &lt;strong&gt;subgradient&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;The Subdifferential \(\partial f(x)\)&lt;/strong&gt;: Collecting all subgradients at \(x\) forms a closed, convex set \(\partial f(x)\). At differentiable points, \(\partial f(x) = \{\nabla f(x)\}\) is a singleton; at kinks, \(\partial f(x)\) is a convex hull of active slopes (such as \([-1, 1]\) for $$&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;\(at\)0$$).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Subgradient Calculus &amp;amp; Normal Cones&lt;/strong&gt;: Rules for scaling, addition, affine composition, and pointwise maxima let you compute \(\partial f(x)\) algebraically without returning to the definition. Even constraints fit inside this framework: the subdifferential of the set indicator \(I_C(x)\) is the &lt;em&gt;normal cone&lt;/em&gt; \(N_C(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Universal Optimality (\(0 \in \partial f(x^\star)\))&lt;/strong&gt;: Replacing \(\nabla f(x^\star) = 0\) with \(0 \in \partial f(x^\star)\) gives a necessary and sufficient condition for global optimality of &lt;em&gt;any&lt;/em&gt; convex function—unlocking closed-form soft-thresholding for Lasso, optimality for SVMs, and modern nonsmooth automatic differentiation.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-finding-a-minimum-at-a-non-differentiable-kink&quot;&gt;Worked example: Finding a Minimum at a Non-Differentiable Kink&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize the nonsmooth convex function $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 2&lt;/td&gt;
      &lt;td&gt;+ \frac{1}{2}x^2\(over\)x \in \mathbb{R}$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the subdifferential \(\partial f(x)\) everywhere&lt;/strong&gt; using the sum rule \(\partial(f_1 + f_2) = \partial f_1 + \partial f_2\):
    &lt;ul&gt;
      &lt;li&gt;For \(x &amp;gt; 2\): \(f&apos;(x) = 1 + x\) (unique slope).&lt;/li&gt;
      &lt;li&gt;For \(x &amp;lt; 2\): \(f&apos;(x) = -1 + x\) (unique slope).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;At the kink \(x = 2\): $$\partial&lt;/td&gt;
              &lt;td&gt;x - 2&lt;/td&gt;
              &lt;td&gt;\big&lt;/td&gt;
              &lt;td&gt;_{x=2} = [-1, 1]\(, so\)\partial f(2) = [-1, 1] + 2 = [1, 3]$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the universal optimality condition \(0 \in \partial f(x^\star)\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;At \(x = 2\): \(0 \notin [1, 3]\), so the minimum is &lt;em&gt;not&lt;/em&gt; at the kink.&lt;/li&gt;
      &lt;li&gt;For \(x &amp;gt; 2\): \(1 + x &amp;gt; 3 &amp;gt; 0\), never zero.&lt;/li&gt;
      &lt;li&gt;For \(x &amp;lt; 2\): \(-1 + x = 0 \implies x^\star = 1 &amp;lt; 2\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Now shift the kink to \(x = 0.5\)&lt;/strong&gt;: minimize $$h(x) =&lt;/td&gt;
          &lt;td&gt;x - 0.5&lt;/td&gt;
          &lt;td&gt;+ \frac{1}{2}x^2$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;At \(x = 0.5\): \(\partial h(0.5) = [-1, 1] + 0.5 = [-0.5,\; 1.5]\).&lt;/li&gt;
      &lt;li&gt;Since \(0 \in [-0.5, 1.5]\), the global minimizer lands &lt;strong&gt;right on the kink&lt;/strong&gt; \(x^\star = 0.5\)—something ordinary calculus \(h&apos;(x) = 0\) could never even express!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we introduce the concept of subgradient and subgradient optimality conditions, which generalize the gradient and first-order optimality conditions discussed previously. We also explore several applications and examples related to these concepts.&lt;/p&gt;

&lt;h2 id=&quot;modern-applications-20222026&quot;&gt;Modern applications (2022–2026)&lt;/h2&gt;

&lt;p&gt;An optional companion lesson maps the same subdifferential objects onto recent CS / data-science pipelines — ReLU autodiff, glmnet / skglm Lasso paths, and pinball + conformal quantiles — without changing the theory below. See &lt;a href=&quot;/contents/en/chapter07/07_08_modern_applications/&quot;&gt;07-08 Modern applications of the subgradient&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>19-09 Bài Tập Thực Hành - Proximal Newton Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_09_Practical_Exercises_Proximal_Newton_Methods/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_09_Practical_Exercises_Proximal_Newton_Methods</id>
   <content type="html">&lt;p&gt;Lý thuyết về ánh xạ proximal có tỉ lệ, backtracking tổng hợp và Projected Newton chỉ thực sự “ngấm” khi bạn tự tay thiết lập bài toán con bậc hai, tính ngưỡng mềm có trọng số Hessian và trực tiếp kiểm chứng xem Proximal Newton rút ngắn bao nhiêu vòng lặp so với ISTA/FISTA. Bộ bài tập thực hành dưới đây giúp bạn rèn luyện trọn vẹn kỹ năng từ giải tay 1 chiều đến phân tích tốc độ hội tụ trên bài toán thực.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-kỹ-năng-trọng-tâm-cần-vận-dụng-trong-bài-tập-chương-19&quot;&gt;Kiến thức cần nhớ: Bốn kỹ năng trọng tâm cần vận dụng trong bài tập Chương 19&lt;/h2&gt;

&lt;p&gt;Trước khi bắt tay giải các bài tập bên dưới, hãy kiểm tra nhanh bốn bước kỹ thuật cốt lõi:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập đúng bài toán con bậc hai tổng hợp:&lt;/strong&gt; Viết đầy đủ \(\nabla g(x^{(k)})^T v + \frac{1}{2}v^T H^{(k)} v + h(x^{(k)} + v)\) và lưu ý biến tối ưu có thể viết theo độ dời \(v\) hoặc trực tiếp theo biến mới \(z = x^{(k)} + v\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đưa bài toán con 1 chiều/đường chéo về ngưỡng mềm chuẩn:&lt;/strong&gt; Khi \(H\) là số dương (hoặc đường chéo), luôn chia cả hai số hạng cho \(H\) để thấy ngay điểm tâm \(x - H^{-1}\nabla g(x)\) và ngưỡng co mới \(\lambda / H\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Kiểm tra điều kiện tối ưu bậc nhất tổng hợp:&lt;/strong&gt; Điểm \(x^\star\) là nghiệm tối ưu khi và chỉ khi \(0 \in \nabla g(x^\star) + \partial h(x^\star)\); với $$h(x) = \lambda&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;\(, điều này có nghĩa\)&lt;/td&gt;
          &lt;td&gt;g’(x^\star)&lt;/td&gt;
          &lt;td&gt;\le \lambda\(nếu\)x^\star = 0\(, và\)g’(x^\star) = -\lambda\operatorname{sign}(x^\star)\(nếu\)x^\star \ne 0$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân biệt rõ Newton proximal và Newton chiếu ngây thơ:&lt;/strong&gt; Luôn kiểm tra giá trị hàm \(f(x + tv)\) sau mỗi bước để xác nhận hướng đi thực sự là hướng giảm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-khởi-động-bằng-1-bước-newton-proximal-trên-hàm-bậc-4-có-phạt-ell_1&quot;&gt;Giải thích: Khởi động bằng 1 bước Newton proximal trên hàm bậc 4 có phạt \(\ell_1\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét bài toán $$f(x) = \underbrace{\frac{1}{4}x^4}_{g(x)} + \underbrace{&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;}_{h(x)}\((nghiệm tối ưu duy nhất là\)x^\star = 0\(vì\)0 \in g’(0) + [-1, 1]\(). Thử tính 1 bước Newton proximal từ\)x^{(0)} = 1$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính đạo hàm bậc nhất và bậc hai của \(g\) tại \(x^{(0)} = 1\):&lt;/strong&gt;
\(g&apos;(1) = 1^3 = 1, \qquad H^{(0)} = g&apos;&apos;(1) = 3(1)^2 = 3.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đưa về dạng ánh xạ proximal có tỉ lệ:&lt;/strong&gt;
\(x^{(1)} = \operatorname{prox}_{H^{(0)}}\!\left(x^{(0)} - (H^{(0)})^{-1} g&apos;(x^{(0)})\right) = \operatorname{prox}_{3}\!\left(1 - \frac{1}{3}\right) = S_{1/3}\!\left(\frac{2}{3}\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính kết quả ngưỡng mềm:&lt;/strong&gt;
\(x^{(1)} = \frac{2}{3} - \frac{1}{3} = \frac{1}{3} \approx 0.3333.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra mức giảm hàm mục tiêu:&lt;/strong&gt; \(f(1) = 0.25 + 1 = 1.25\) sụt mạnh xuống \(f(1/3) = \frac{1}{324} + \frac{1}{3} \approx 0.3364\)! Và chỉ cần thêm 1 bước nữa tại \(x^{(1)} = 1/3\) (\(g&apos;(1/3) = 1/27, H^{(1)} = 1/3\)), ta có \(x^{(2)} = S_{3}(1/3 - 1/9) = S_3(2/9) = 0 = x^\star\) — chạm chính xác nghiệm tối ưu sau đúng 2 bước!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---phương-pháp-proximal-newton&quot;&gt;Bài Tập Thực Hành - Phương pháp Proximal Newton&lt;/h1&gt;

&lt;p&gt;Các bài tập được tham khảo từ Lee et al. (2014) và Rakotomamonjy et al. (2016).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-1-bước-proximal-newton&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Bước Proximal Newton&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Cho hàm mục tiêu tổng hợp \(f(x) + g(x)\) với \(f(x) = x^2\) và $$g(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán con của phương pháp Proximal Newton.&lt;br /&gt;
b) Giải bài toán con tại \(x^{(k)} = 2\).&lt;br /&gt;
c) So sánh kết quả với phương pháp proximal gradient descent.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Bài toán con Proximal Newton:**

$$x^{(k+1)} = \arg\min_x \left\{ f(x^{(k)}) + \nabla f(x^{(k)})^T(x - x^{(k)}) + \frac{1}{2}(x - x^{(k)})^T \nabla^2 f(x^{(k)})(x - x^{(k)}) + g(x) \right\}$$

$$= \arg\min_x \left\{ \frac{H_k}{2}(x - x^{(k)})^2 + \nabla f(x^{(k)})(x - x^{(k)}) + g(x) \right\}$$

---

**b) Giải tại $$x^{(k)} = 2$$:**

Ta có $$\nabla f(2) = 4$$ và $$\nabla^2 f(2) = 2$$, nên bài toán con là:

$$\min_x \left\{ (x - 2)^2 + 4(x - 2) + |x| \right\}$$

$$= \min_x \left\{ x^2 - 4x + 4 + 4x - 8 + |x| \right\}$$

$$= \min_x \left\{ x^2 - 4 + |x| \right\}$$

- **Trường hợp 1 ($$x \geq 0$$):** $$\min_{x \ge 0} (x^2 + x - 4)$$; điểm dừng $$x = -0.5$$ nằm ngoài miền $$x \ge 0$$ nên đạt cực tiểu tại biên $$x = 0$$.
- **Trường hợp 2 ($$x &amp;lt; 0$$):** $$\min_{x &amp;lt; 0} (x^2 - x - 4)$$; điểm dừng $$x = 0.5$$ nằm ngoài miền $$x &amp;lt; 0$$ nên hàm giảm dần về biên $$x = 0$$.
- **Kiểm tra tại biên $$x = 0$$:** giá trị hàm mục tiêu bằng $$-4$$.

**Nghiệm tối ưu:** $$x^{(1)} = 0$$.

---

**c) So sánh với Proximal Gradient Descent:**

$$x^{(k+1)} = \text{prox}_{t|\cdot|}(x^{(k)} - t\nabla f(x^{(k)})) = S_t(2 - 4t)$$

Với độ dài bước $$t = 0.5$$ (bằng $$1/H_k$$): $$S_{0.5}(0) = 0$$.

Trong bài toán bậc hai 1 chiều đơn giản này, hai phương pháp cho cùng kết quả vì Hessian là hằng số $$H_k = 2$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-proximal-newton-cho-lasso&quot;&gt;📝 &lt;strong&gt;Bài tập 2: Proximal Newton cho LASSO&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét bài toán:&lt;/p&gt;

\[\min \frac{1}{2}\|Ax - b\|^2 + \lambda\|x\|_1\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Xác định tập biến hoạt động (active set) và không hoạt động (inactive set).&lt;br /&gt;
b) Viết bước Newton trên tập biến hoạt động.&lt;br /&gt;
c) Xử lý trường hợp biến đổi dấu trong quá trình cập nhật.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Tập hoạt động:**

$$\mathcal{A} = \{i : x_i \neq 0\}, \qquad \mathcal{I} = \{i : x_i = 0\}$$

**Điều kiện KKT trên $$\mathcal{A}$$:** $$\nabla f(x)_{\mathcal{A}} + \lambda \cdot \text{sign}(x_{\mathcal{A}}) = 0$$.

---

**b) Bước Newton trên $$\mathcal{A}$$:**

Xét bài toán thu gọn trên tập hoạt động:

$$\min_{x_{\mathcal{A}}} \frac{1}{2}\|A_{\mathcal{A}}x_{\mathcal{A}} - b\|^2 + \lambda\|x_{\mathcal{A}}\|_1$$

Khi cố định dấu $$\text{sign}(x_{\mathcal{A}})$$, hệ phương trình Newton là:

$$\nabla^2 f_{\mathcal{A}} \Delta x_{\mathcal{A}} = -\nabla f_{\mathcal{A}} - \lambda \cdot \text{sign}(x_{\mathcal{A}})$$

$$\Delta x_{\mathcal{A}} = -(A_{\mathcal{A}}^T A_{\mathcal{A}})^{-1}\big(A_{\mathcal{A}}^T(A_{\mathcal{A}}x_{\mathcal{A}} - b) + \lambda \cdot \text{sign}(x_{\mathcal{A}})\big)$$

---

**c) Xử lý khi biến đổi dấu:**

Nếu một thành phần đổi dấu ($$x_i^{\text{new}} \cdot x_i^{\text{old}} &amp;lt; 0$$), ta cắt ngắn độ dài bước để dừng trước (hoặc tại) điểm $$0$$:

$$\alpha_{\max} = \min_{\{i \in \mathcal{A} \,:\, x_i^{\text{old}} \Delta x_i &amp;lt; 0\}} \frac{-x_i^{\text{old}}}{\Delta x_i}$$

**Cập nhật an toàn:** $$x^{(k+1)} = x^{(k)} + \min(1, 0.99\alpha_{\max}) \Delta x$$ (hoặc đặt tọa độ chạm $$0$$ về đúng $$0$$ và cập nhật lại tập hoạt động).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-phương-pháp-newton-bán-trơn-semismooth-newton&quot;&gt;📝 &lt;strong&gt;Bài tập 3: Phương pháp Newton bán trơn (Semismooth Newton)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét điều kiện tối ưu dạng bao hàm: \(F(x) = \nabla f(x) + \partial g(x) \ni 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Nêu khái niệm ma trận Jacobi tổng quát (generalized Jacobian).&lt;br /&gt;
b) Minh họa với \(g(x) = \|x\|_1\).&lt;br /&gt;
c) Nêu điều kiện để phương pháp đạt hội tụ siêu tuyến tính.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Ma trận Jacobi tổng quát:**

$$\partial F(x) = \nabla^2 f(x) + \partial^2 g(x)$$

trong đó $$\partial^2 g$$ ký hiệu đạo hàm bậc hai dạng ánh xạ đa trị (trong cài đặt thực tế thường áp dụng trực tiếp cho phương trình điểm bất động không trơn $$x - \text{prox}_g(x - \nabla f(x)) = 0$$).

---

**b) Với $$g(x) = \|x\|_1$$:**

$$\partial g(x)_i = \begin{cases}
\text{sign}(x_i) &amp;amp; \text{if } x_i \neq 0 \\
[-1, 1] &amp;amp; \text{if } x_i = 0
\end{cases}$$

$$\partial^2 g(x)_i = \begin{cases}
0 &amp;amp; \text{if } x_i \neq 0 \\
\{0\} \cup \{\infty \cdot \text{sign}\} &amp;amp; \text{if } x_i = 0
\end{cases}$$

**Hướng Newton:** Chọn một phần tử đại diện $$V_x \in \partial F(x)$$ và giải hệ tuyến tính tương ứng.

---

**c) Tốc độ hội tụ:**

Nếu ánh xạ $$F$$ thỏa mãn tính chất bán trơn (semismooth):

$$\|F(x + d) - F(x) - V_x d\| = o(\|d\|)$$

với $$V_x \in \partial F(x)$$ (và $$V_x$$ khả nghịch đều quanh nghiệm), thì phương pháp Newton bán trơn đạt **hội tụ siêu tuyến tính cục bộ** tương tự phương pháp Newton trơn.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-đường-điều-chuẩn-regularization-path&quot;&gt;📝 &lt;strong&gt;Bài tập 4: Đường điều chuẩn (Regularization Path)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Theo dõi quỹ đạo nghiệm \(x^*(\lambda)\) khi tham số điều chuẩn \(\lambda\) thay đổi.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tính đạo hàm dọc đường điều chuẩn \(\frac{dx^*}{d\lambda}\).&lt;br /&gt;
b) Dự báo nghiệm mới khi thay đổi \(\lambda \to \lambda + \Delta\lambda\).&lt;br /&gt;
c) Áp dụng vào kỹ thuật khởi động ấm (warm-start).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Đạo hàm hàm ẩn:**

Từ điều kiện KKT: $$\nabla f(x^*) + \lambda v^* = 0$$ với $$v^* \in \partial g(x^*)$$.

Lấy đạo hàm hai vế theo $$\lambda$$:

$$\nabla^2 f(x^*) \frac{dx^*}{d\lambda} + v^* + \lambda \frac{dv^*}{d\lambda} = 0$$

Trên tập hoạt động (nơi $$v^*$$ không đổi cục bộ, chẳng hạn $$v_i^* = \text{sign}(x_i^*)$$ với phạt $$\ell_1$$ nên $$\frac{dv^*}{d\lambda} = 0$$):

$$\frac{dx^*}{d\lambda} = -(\nabla^2 f)^{-1} v^*$$

---

**b) Dự báo nghiệm mới:**

$$x^*(\lambda + \Delta\lambda) \approx x^*(\lambda) + \frac{dx^*}{d\lambda} \Delta\lambda = x^*(\lambda) - (\nabla^2 f)^{-1} v^* \Delta\lambda$$

---

**c) Khởi động ấm (Warm-start):**

Sử dụng giá trị dự báo trên làm điểm khởi tạo cho bài toán tại $$\lambda + \Delta\lambda$$ giúp giảm đáng kể số vòng lặp Newton cần thiết.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-điều-chuẩn-thích-nghi-adaptive-regularization&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Điều chuẩn thích nghi (Adaptive Regularization)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Điều chỉnh tham số điều chuẩn \(\mu\) trong vòng lặp để đảm bảo tính ổn định.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán con kiểu Levenberg–Marquardt với ma trận \(\nabla^2 f + \mu I\).&lt;br /&gt;
b) Nêu quy tắc cập nhật \(\mu\) dựa trên tỷ số giảm thực tế trên giảm dự báo.&lt;br /&gt;
c) So sánh với việc dùng Hessian cố định không điều chuẩn.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Bài toán con có điều chuẩn:**

$$\min_d \left\{ \frac{1}{2}d^T(\nabla^2 f + \mu I)d + \nabla f^T d + g(x + d) \right\}$$

Tham số $$\mu &amp;gt; 0$$ đủ lớn đảm bảo ma trận bậc hai xác định dương.

---

**b) Quy tắc kiểu miền tin cậy (Trust region):**

Tính tỷ số giảm:

$$\rho = \frac{\text{mức giảm thực tế}}{\text{mức giảm dự báo}}$$

- Nếu $$\rho &amp;gt; 0.75$$: giảm $$\mu$$ (tiến gần hơn tới bước Newton đầy đủ).
- Nếu $$\rho &amp;lt; 0.25$$: tăng $$\mu$$ (thận trọng hơn, tiến gần về bước proximal gradient).

---

**c) Lợi ích so với Hessian cố định:**

- **Hessian cố định:** Có thể không hội tụ hoặc bài toán con không bị chặn nếu $$\nabla^2 f$$ không xác định dương.
- **Điều chuẩn thích nghi $$\mu$$:** Đảm bảo luôn thu được hướng giảm và ổn định trên các bài toán có số điều kiện xấu.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Đặc điểm chính&lt;/th&gt;
      &lt;th&gt;Phù hợp với&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Proximal Newton&lt;/td&gt;
      &lt;td&gt;Mô hình bậc hai + toán tử prox&lt;/td&gt;
      &lt;td&gt;Phạt \(\ell_1\), thưa theo nhóm (group sparsity)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tập hoạt động (Active set)&lt;/td&gt;
      &lt;td&gt;Cố định dấu, giải Newton trơn trên biến khác 0&lt;/td&gt;
      &lt;td&gt;Đường điều chuẩn LASSO&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Newton bán trơn (Semismooth)&lt;/td&gt;
      &lt;td&gt;Dùng ma trận Jacobi tổng quát&lt;/td&gt;
      &lt;td&gt;Hệ phương trình tối ưu không trơn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Điều chuẩn thích nghi&lt;/td&gt;
      &lt;td&gt;Dùng \(\nabla^2 f + \mu I\)&lt;/td&gt;
      &lt;td&gt;Bài toán có số điều kiện xấu&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Lee, J. D., et al. (2014). “Proximal Newton-type methods”. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Rakotomamonjy, A., et al. (2016). “Efficient Proximal Newton”. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>19-07 Phương pháp Newton chiếu (Projected Newton)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_07_Projected_Newton_method/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_07_Projected_Newton_method</id>
   <content type="html">&lt;p&gt;Khi \(h(x) = I_C(x)\) là hàm chỉ thị của một tập ràng buộc lồi \(C\), ta dễ bị cám dỗ bởi một suy nghĩ tưởng chừng hiển nhiên: &lt;em&gt;ở phương pháp bậc nhất, ta chỉ việc bước một bước gradient rồi chiếu Euclid lên \(C\); vậy ở phương pháp bậc hai, sao không bước một bước Newton \(-H^{-1}\nabla g(x)\) rồi chiếu Euclid lên \(C\)?&lt;/em&gt; Cú sốc toán học của bài 19-07 là: &lt;strong&gt;cách chiếu ngây thơ đó SAI HOÀN TOÀN — nó có thể dẫn bạn đi ngược lên dốc và làm tăng hàm mục tiêu!&lt;/strong&gt; Để có một phương pháp Newton chiếu đúng đắn, phép chiếu phải được thực hiện trong chuẩn \(H\) (chính là Newton proximal), hoặc dùng chiến lược tách tập ràng buộc hoạt động thông minh của Bertsekas (1982).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-để-tránh-bẫy-newton-chiếu-ngây-thơ&quot;&gt;Kiến thức cần nhớ: Ba trụ cột để tránh bẫy “Newton chiếu ngây thơ”&lt;/h2&gt;

&lt;p&gt;Hãy nắm rõ ba khái niệm sau để không bao giờ mắc lỗi khi kết hợp Newton với ràng buộc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chiếu Euclid vs. Chiếu theo chuẩn \(H\):&lt;/strong&gt; Phép chiếu Euclid \(P_C(x - H^{-1}\nabla g(x))\) không nhất thiết tạo ra hướng giảm khi \(H\) không phải bội của ma trận đơn vị. Ngược lại, chiếu theo chuẩn \(H\) — tức \(\arg\min_{z \in C} \frac{1}{2}\|z - (x - H^{-1}\nabla g(x))\|_H^2\) — chính là Newton proximal với \(h = I_C\) và &lt;strong&gt;luôn&lt;/strong&gt; đảm bảo hướng giảm!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc hộp (Box Constraints, \(l \le x \le u\)) và hai tập biến của Bertsekas:&lt;/strong&gt; Với ràng buộc đơn giản \(x \ge 0\), Bertsekas (1982) chia các tọa độ thành hai nhóm: &lt;strong&gt;tập ràng buộc hoạt động&lt;/strong&gt; \(\mathcal{B}\) (các biến đang chạm biên \(x_i = 0\) và gradient đẩy ra ngoài \(\nabla_i g(x) &amp;gt; 0\)) và &lt;strong&gt;tập biến tự do&lt;/strong&gt; \(\mathcal{F}\) (phần còn lại).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tách khối Hessian để chiếu Euclid trở nên hợp lệ:&lt;/strong&gt; Bằng cách xóa sạch các phần tử chéo giữa khối \(\mathcal{B}\) và khối \(\mathcal{F}\) trong ma trận nghịch đảo độ cong \(D_k\) (dùng \(H_{\mathcal{F}\mathcal{F}}^{-1}\) trên tập tự do và ma trận đường chéo dương trên tập hoạt động), Bertsekas chứng minh phép chiếu Euclid \(P_C(x - t D_k \nabla g(x))\) &lt;strong&gt;luôn là hướng giảm&lt;/strong&gt; và vẫn giữ tốc độ hội tụ bậc hai khi tập hoạt động ổn định!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phản-ví-dụ-tính-tay-cho-thấy-chiếu-euclid-bước-newton-làm-tăng-hàm-mục-tiêu&quot;&gt;Giải thích: Phản ví dụ tính tay cho thấy chiếu Euclid bước Newton làm TĂNG hàm mục tiêu&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai lồi chặt 2 biến trên góc phần tư không âm \(C = \{x \in \mathbb{R}^2 : x_1 \ge 0, x_2 \ge 0\}\):&lt;/p&gt;

\[g(x) = \frac{1}{2}x^T H x - b^T x, \qquad H = \begin{bmatrix} 2 &amp;amp; 1.5 \\ 1.5 &amp;amp; 2 \end{bmatrix} \succ 0, \qquad b = \begin{bmatrix} 1 \\ -1 \end{bmatrix}.\]

&lt;p&gt;Xuất phát tại điểm biên \(x^{(0)} = (0, 0)^T \in C\), ta có \(g(0, 0) = 0\) và \(\nabla g(0) = -b = (-1, 1)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cách ngây thơ (tính bước Newton không ràng buộc rồi chiếu Euclid lên \(C\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ma trận nghịch đảo: \(H^{-1} = \frac{1}{4 - 2.25}\begin{bmatrix} 2 &amp;amp; -1.5 \\ -1.5 &amp;amp; 2 \end{bmatrix} = \frac{1}{1.75}\begin{bmatrix} 2 &amp;amp; -1.5 \\ -1.5 &amp;amp; 2 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;Bước Newton không ràng buộc: \(x_{\text{Newton}} = 0 - H^{-1}\nabla g(0) = H^{-1}b = \frac{1}{1.75}\begin{bmatrix} 3.5 \\ -3.5 \end{bmatrix} = \begin{bmatrix} 2 \\ -2 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;Chiếu Euclid lên \(x \ge 0\): \(z_{\text{ngây thơ}} = P_C(2, -2) = (2, 0)^T\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Kiểm tra giá trị hàm mục tiêu:&lt;/strong&gt;
\(g(2, 0) = \frac{1}{2}(2)(2^2) - (1)(2) = 4 - 2 = +2 &amp;gt; 0 = g(0, 0)!\)
Thậm chí dọc theo tia \(x(t) = (2t, 0)\) với \(t = 1\), hàm mục tiêu tăng vọt từ \(0\) lên \(+2\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách đúng (Newton proximal / chiếu theo chuẩn \(H\) hoặc Projected Newton Bertsekas):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tọa độ \(x_2 = 0\) có \(\nabla_2 g(0) = +1 &amp;gt; 0\) (nằm trong tập hoạt động \(\mathcal{B} = \{2\}\)), còn \(x_1\) có \(\nabla_1 g(0) = -1 &amp;lt; 0\) (tự do \(\mathcal{F} = \{1\}\)).&lt;/li&gt;
      &lt;li&gt;Giải trên tập tự do \(x_2 = 0\) với độ cong \(H_{11} = 2\): \(z_1 = 0 - H_{11}^{-1}(-1) = 0.5 \implies z_{\text{đúng}} = (0.5, 0)^T\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Kiểm tra giá trị hàm:&lt;/strong&gt; \(g(0.5, 0) = \frac{1}{2}(2)(0.25) - (1)(0.5) = 0.25 - 0.5 = -0.25 &amp;lt; 0\) — đạt đúng cực tiểu toàn cục trên \(C\) ngay sau 1 bước!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;vấn-đề-đặt-ra-với-phương-pháp-newton-chiếu&quot;&gt;Vấn đề đặt ra với phương pháp Newton chiếu&lt;/h2&gt;
&lt;p&gt;Khi \(h\) là hàm chỉ thị \(h(x) = I_C(x)\) của một tập lồi \(C\), bài toán tổng hợp trở thành bài toán tối ưu có ràng buộc:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} \ g(x) \quad  \text{subject to}  \quad  x \in C\]
&lt;/blockquote&gt;

&lt;p&gt;Trong trường hợp này, proximal gradient descent suy biến chính xác thành &lt;strong&gt;hạ gradient chiếu (projected gradient descent)&lt;/strong&gt; — tức projected gradient descent là một trường hợp đặc biệt của proximal gradient descent.&lt;/p&gt;

&lt;p&gt;Tuy nhiên, điều tương tự không xảy ra với Newton proximal khi \(h(x) = I_C(x)\). Khi đó, bài toán con của Newton proximal có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
z^{+} &amp;amp; =\underset{z \in C}{\text{argmin}} \ \frac{1}{2} \parallel x - H^{-1} \nabla g(x) - z \parallel_H^2  \\\\
&amp;amp;= \underset{z \in C}{\text{argmin}} \ \nabla g(x)^T (z - x) + \frac{1}{2} (z - x)^T H (z - x)  \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Chỉ khi \(H = I\) biểu thức này mới là phép chiếu Euclid của \(x - \nabla g(x)\) lên tập \(C\); với ma trận \(H \neq I\) tổng quát, đây là phép chiếu theo chuẩn \(H\) (tức một bài toán quy hoạch bậc hai trên \(C\)) chứ không phải phép chiếu theo chuẩn \(\ell_2\) thông thường. Vì vậy, phương pháp Newton chiếu không phải là trường hợp đặc biệt của phương pháp Newton proximal.&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-newton-chiếu-cho-ràng-buộc-hộp-box-constraints&quot;&gt;Phương pháp Newton chiếu cho ràng buộc hộp (Box Constraints)&lt;/h2&gt;
&lt;p&gt;Với trường hợp đặc biệt là ràng buộc hộp, có thể xây dựng thuật toán Newton chiếu hiệu quả (Bertsekas, 1982; Kim et al., 2010; Schmidt et al., 2011).&lt;/p&gt;

&lt;p&gt;Xét bài toán:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} \ g(x) \quad  \text{subject to}  \quad  l \le x \le u\]
&lt;/blockquote&gt;

&lt;p&gt;Với điểm khởi tạo \(x^{(0)}\) và hằng số nhỏ \(\epsilon \gt 0\), thuật toán lặp các bước sau (\(k = 1, 2, 3, \dots\)):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; Xác định tập chỉ số bị ràng buộc chặt (binding set):&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
B_{k-1} &amp;amp; = \{ i : x_i^{(k-1)} \le l_i + \epsilon \quad \text{and} \quad  \nabla_i g(x^{(k-1)}) \gt 0 \} \quad  \cup \quad 
\{ i : x_i^{(k-1)} \ge u_i - \epsilon  \quad \text{and} \quad  \nabla_i g(x^{(k-1)}) \lt 0 \} 
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Đây là các tọa độ đang nằm sát biên hộp và có hướng giảm \(-\nabla_i g\) chỉ ra ngoài tập khả thi.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt; Xác định tập biến tự do (free set) \(F_{k-1} = \left\{1, \dots, n \right\} \setminus B_{k-1}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3:&lt;/strong&gt; Tính nghịch đảo của khối ma trận con chính của Hessian trên tập biến tự do:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[S^{(k-1)} = [(\nabla^2 g(x^{(k-1)}))_{F_{k-1}}]^{-1}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4:&lt;/strong&gt; Thực hiện bước Newton trên các biến tự do, bước gradient trên các biến bị ràng buộc chặt, rồi chiếu lên hộp:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\begin{align}
x^{(k)} = P_{[l, u]} \left( x^{(k-1)} - t_k \begin{bmatrix} S^{(k-1)} &amp;amp; 0 \\
0 &amp;amp; I \end{bmatrix} 
\begin{bmatrix} \nabla_{F_{k-1}} g(x^{(k-1)}) \\ \nabla_{B_{k-1}} g(x^{(k-1)}) \end{bmatrix}
\right)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(P_{[l,u]}\) là phép chiếu lên hình hộp \([l, u] = [l_1, u_1] \times \cdots \times [l_n, u_n]\).&lt;/p&gt;

&lt;p&gt;Phép chiếu lên hộp rất đơn giản: với mỗi tọa độ vượt ra ngoài đoạn \([l_i, u_i]\), ta chỉ cần cắt về đúng biên \(l_i\) hoặc \(u_i\) tương ứng. Phương pháp này đặc biệt hiệu quả với bài toán có số chiều lớn mà đa số biến nằm sát biên, khiến tập biến tự do \(F_{k-1}\) nhỏ và việc nghịch đảo Hessian trên \(F_{k-1}\) có chi phí thấp.&lt;/p&gt;

&lt;p&gt;Một số bài toán tiêu biểu có dạng ràng buộc hộp:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Bình phương tối thiểu không âm (nonnegative least squares)&lt;/li&gt;
  &lt;li&gt;Bài toán đối ngẫu của máy vector hỗ trợ (SVM dual)&lt;/li&gt;
  &lt;li&gt;Bài toán đối ngẫu của graphical lasso&lt;/li&gt;
  &lt;li&gt;Bài toán đối ngẫu của fused lasso (khử nhiễu biến phân toàn phần — total variation denoising)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;tính-chất-hội-tụ&quot;&gt;Tính chất hội tụ&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Bertsekas (1982) chứng minh rằng dưới các giả thiết thích hợp, phương pháp Newton chiếu nhận diện đúng tập ràng buộc chặt sau một số hữu hạn vòng lặp; từ thời điểm đó trở đi, thuật toán trùng với phương pháp Newton trên các biến tự do.&lt;/li&gt;
  &lt;li&gt;Bertsekas (1982) cũng chứng minh tốc độ hội tụ siêu tuyến tính (và bậc hai khi dùng Hessian chính xác).&lt;/li&gt;
  &lt;li&gt;Kim et al. (2010) và Schmidt et al. (2011) phát triển thêm các phương pháp quasi-Newton chiếu sử dụng cập nhật kiểu BFGS.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>19-06 Các phương pháp quasi-Newton proximal</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_06_Proximal_quasi_Newton_methods/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_06_Proximal_quasi_Newton_methods</id>
   <content type="html">&lt;p&gt;Ở bài 19-03 ta đã thấy điểm yếu lớn nhất của Newton proximal: khi số chiều \(n\) lên đến hàng chục nghìn, ngay cả việc tính và lưu ma trận Hessian chính xác \(H = \nabla^2 g(x)\) đã bất khả thi, chưa nói đến giải bài toán con bậc hai dày đặc bên trong. Một ý tưởng hết sức tự nhiên nảy ra từ Chương 18: &lt;strong&gt;ta thay Hessian chính xác \(\nabla^2 g(x)\) bằng một ma trận xấp xỉ rẻ tiền hơn \(B_k\) (BFGS, L-BFGS, hoặc đường chéo/theo khối)!&lt;/strong&gt; Đó chính là họ &lt;strong&gt;phương pháp Quasi-Newton proximal&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-hướng-thiết-kế-ma-trận-xấp-xỉ-độ-cong-cho-bài-toán-tổng-hợp&quot;&gt;Kiến thức cần nhớ: Ba hướng thiết kế ma trận xấp xỉ độ cong cho bài toán tổng hợp&lt;/h2&gt;

&lt;p&gt;Tùy vào cấu trúc của hàm không trơn \(h\) và kích thước bài toán, người ta chọn một trong ba chiến lược xấp xỉ Hessian sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Proximal BFGS / L-BFGS (Lee, Sun &amp;amp; Saunders, 2014):&lt;/strong&gt; Xây dựng \(B_k\) từ các cặp \((s_i, y_i)\) của hàm trơn \(g\) (chú ý chỉ dùng biến thiên gradient của phần trơn \(y_k = \nabla g(x_{k+1}) - \nabla g(x_k)\)!). Phương pháp đạt hội tụ &lt;strong&gt;siêu tuyến tính cục bộ&lt;/strong&gt; mà không cần tính đạo hàm bậc hai.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ theo khối (Blockwise Coordinate Gradient — Tseng &amp;amp; Yun, 2009):&lt;/strong&gt; Khi \(h(x) = \sum_b h_b(x_b)\) tách được theo từng khối biến (như Group Lasso), ta chọn \(B_k\) là ma trận khối đường chéo. Bài toán con lập tức tách thành nhiều bài toán nhỏ độc lập nhau, giải song song cực nhanh và đảm bảo hội tụ tuyến tính toàn cục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ đường chéo cộng hạng thấp (Diagonal + Low-Rank):&lt;/strong&gt; Đặc biệt với L-BFGS, vì \(B_k = \gamma_k I + U M U^T\) có cấu trúc đường chéo cộng hạng \(2m\), ta có thể giải bài toán con \(\operatorname{prox}_{B_k}\) bằng thuật toán hạ tọa độ hoặc bài toán đối ngẫu chỉ cỡ \(2m\) biến (với \(m \approx 10\))!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-chi-phí-giải-bài-toán-con-khi-b_k-là-ma-trận-đường-chéo-vs-ma-trận-đầy-đủ&quot;&gt;Giải thích: So sánh chi phí giải bài toán con khi \(B_k\) là ma trận đường chéo vs. ma trận đầy đủ&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét bài toán 2 biến với $$h(x) =&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\(tại\)x = (1, 1)^T\(,\)\nabla g(x) = (2, 4)^T$$, và xét hai lựa chọn ma trận xấp xỉ Hessian:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn 1 — Xấp xỉ đường chéo (Barzilai–Borwein / đường chéo Hessian) \(B_{\text{diag}} = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 8 \end{bmatrix}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bài toán con tách rời hoàn toàn từng biến:
\(v_1 = S_{1/2}(1 - 2/2) - 1 = 0 - 1 = -1 \implies x_1^+ = 0,\)
\(v_2 = S_{1/8}(1 - 4/8) - 1 = S_{0.125}(0.5) - 1 = -0.625 \implies x_2^+ = 0.375.\)&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Chi phí:&lt;/strong&gt; Nghiệm dạng đóng chính xác ngay trong \(O(n)\) phép toán, không cần vòng lặp bên trong!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn 2 — Xấp xỉ BFGS đầy đủ \(B_{\text{BFGS}} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 8 \end{bmatrix}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vì có phần tử ngoài đường chéo \(1\) (tạo số hạng chéo \(v_1 v_2\)), hai biến \(v_1\) và \(v_2\) &lt;strong&gt;dính chặt vào nhau&lt;/strong&gt; nên không còn công thức đóng theo từng tọa độ nữa; ta phải chạy vài vòng lặp hạ tọa độ bên trong (cố định \(v_2\) cập nhật \(v_1\) rồi ngược lại).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Đổi lại:&lt;/strong&gt; Nắm bắt được tương quan chéo giữa \(x_1\) và \(x_2\), giúp hội tụ siêu tuyến tính thay vì tuyến tính!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Khi quy mô bài toán tăng lên, việc tính trực tiếp ma trận Hessian trở nên rất tốn kém. &lt;strong&gt;Các phương pháp quasi-Newton proximal&lt;/strong&gt; tránh tính Hessian chính xác \(H^{(k-1)} = \nabla^2 g(x^{(k-1)})\) ở mỗi vòng lặp nhưng vẫn duy trì được tốc độ hội tụ siêu tuyến tính hoặc tuyến tính.&lt;/p&gt;

&lt;h2 id=&quot;các-hướng-tiếp-cận-quasi-newton-proximal&quot;&gt;Các hướng tiếp cận quasi-Newton proximal&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lee, Sun và Saunders (2014):&lt;/strong&gt; Đề xuất cập nhật ma trận xấp xỉ Hessian theo kiểu BFGS. Phương pháp này hoạt động hiệu quả và đạt tốc độ hội tụ siêu tuyến tính cục bộ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tseng và Yun (2009):&lt;/strong&gt; Đề xuất xấp xỉ Hessian theo khối (blockwise). Cách này áp dụng khi hàm \(f = g + h\) có cấu trúc tách khối sao cho \(h\) chỉ phụ thuộc từng nhóm biến riêng biệt. Chi phí tính Hessian theo khối giảm đi đáng kể và phương pháp đạt tốc độ hội tụ tuyến tính.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Các phương pháp quasi-Newton proximal không chỉ hữu ích khi Hessian khó tính toán, mà còn rất giá trị trên những bài toán có số điều kiện xấu (ill-conditioned), nơi ma trận Hessian bị suy biến hoặc gần suy biến.&lt;/p&gt;

&lt;h4 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;J. Lee and Y. Sun and M. Saunders (2014), “Proximal Newton-type methods for minimizing composite functions”&lt;/li&gt;
  &lt;li&gt;P. Tseng and S. Yun (2009), “A coordinate gradient descent method for nonsmooth separable minimization”&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>19-05 Các ví dụ đáng chú ý</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_05_Notable_examples/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_05_Notable_examples</id>
   <content type="html">&lt;p&gt;Nếu cần bằng chứng thuyết phục nhất chứng minh phương pháp Newton proximal không chỉ đẹp trên giấy mà còn thống trị thực tế, hãy nhìn vào hai “huyền thoại phần mềm” trong thống kê học máy: &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;&lt;/strong&gt; (Friedman, Hastie, Tibshirani, 2009 — một trong những gói R/Python được trích dẫn nhiều nhất thế kỷ XXI) và &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt;&lt;/strong&gt; (Hsieh et al., 2011 — chuẩn vàng cho bài toán ước lượng ma trận chính xác thưa graphical lasso). Cả hai đều có chung một bí quyết: dùng &lt;strong&gt;Newton proximal ở vòng lặp ngoài&lt;/strong&gt; kết hợp &lt;strong&gt;hạ tọa độ trên tập hoạt động ở vòng lặp trong&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-kiến-trúc-của-glmnet-và-quic&quot;&gt;Kiến thức cần nhớ: Giải phẫu kiến trúc của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;Bốn mảnh ghép sau cho thấy cách các tác giả biến lý thuyết Chương 19 thành bộ giải nhanh gấp hàng chục lần đối thủ:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bình phương tối thiểu có trọng số lặp (IRLS) trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;:&lt;/strong&gt; Với hồi quy logistic có phạt \(\ell_1\), khai triển Taylor bậc hai của hàm log-likelihood quanh \(\beta^{(k)}\) tạo ra chính xác một bài toán &lt;strong&gt;Lasso có trọng số&lt;/strong&gt; \(\min_\beta \frac{1}{2n}\sum_{i=1}^n w_i (z_i - x_i^T\beta)^2 + \lambda\|\beta\|_1\), giải cực nhanh bằng hạ tọa độ!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đường điều chuẩn và khởi động nóng (Warm Starts):&lt;/strong&gt; Thay vì giải ở một giá trị \(\lambda\) đơn lẻ, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; giải dọc theo cả dãy \(\lambda_1 &amp;gt; \lambda_2 &amp;gt; \dots &amp;gt; \lambda_K\), lấy nghiệm của \(\lambda_{j-1}\) làm điểm khởi tạo cho \(\lambda_j\) — giúp Newton proximal rơi thẳng vào vùng hội tụ bậc hai chỉ sau 1–2 bước!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Graphical Lasso và bài toán con bậc hai trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt;:&lt;/strong&gt; Hàm mục tiêu \(-\log\det\Theta + \operatorname{tr}(S\Theta) + \lambda\|\Theta\|_1\) có gradient \(S - \Theta^{-1}\) và Hessian \(\Theta^{-1} \otimes \Theta^{-1}\). &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt; khai triển bậc hai \(-\log\det(\Theta + \Delta)\) thành một bài toán Lasso ma trận đối xứng theo \(\Delta\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập tự do (Free Set) giúp cắt giảm kích thước bài toán con:&lt;/strong&gt; Nhờ tính thưa của \(\ell_1\), phần lớn phần tử của \(\Theta\) thỏa mãn điều kiện tối ưu tại \(0\) và bị khóa cố định. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt; chỉ chạy hạ tọa độ trên tập nhỏ các biến tự do, giúp tốc độ tăng vọt hàng chục lần.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-lập-bài-toán-con-lasso-có-trọng-số-của-glmnet-trên-2-mẫu-dữ-liệu&quot;&gt;Giải thích: Tự tay lập bài toán con Lasso có trọng số của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; trên 2 mẫu dữ liệu&lt;/h3&gt;

&lt;p&gt;Xét bài toán hồi quy logistic 1 biến có phạt \(\ell_1\) với \(n = 2\) mẫu: \((x_1, y_1) = (1, 1)\) và \((x_2, y_2) = (-1, 0)\), tham số phạt \(\lambda = 0.1\). Ta muốn lập bài toán con Newton proximal tại \(\beta^{(0)} = 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính xác suất dự đoán \(p_i = \frac{1}{1 + e^{-x_i \beta^{(0)}}}\):&lt;/strong&gt;
Tại \(\beta^{(0)} = 0\), cả hai mẫu đều cho \(p_1 = p_2 = 0.5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính trọng số Hessian \(w_i = p_i(1 - p_i)\):&lt;/strong&gt;
\(w_1 = 0.5(1 - 0.5) = 0.25, \qquad w_2 = 0.5(1 - 0.5) = 0.25.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính biến phản hồi làm việc (working response) \(z_i = x_i \beta^{(0)} + \frac{y_i - p_i}{w_i}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Mẫu 1: \(z_1 = 0 + \frac{1 - 0.5}{0.25} = +2\).&lt;/li&gt;
      &lt;li&gt;Mẫu 2: \(z_2 = 0 + \frac{0 - 0.5}{0.25} = -2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lập và giải bài toán con Lasso có trọng số:&lt;/strong&gt;
\(\beta^{(1)} = \arg\min_{\beta} \left\{ \frac{1}{4}\left[ 0.25(2 - \beta)^2 + 0.25(-2 + \beta)^2 \right] + 0.1|\beta| \right\} = \arg\min_{\beta} \left\{ \frac{1}{8}(\beta - 2)^2 + 0.1|\beta| \right\}.\)
Chia cho độ cong \(0.25\) ta có bài toán chuẩn \(\frac{1}{2}(\beta - 2)^2 + 0.4|\beta|\), suy ra nghiệm ngay lập tức bằng ngưỡng mềm:
\(\beta^{(1)} = S_{0.4}(2) = 1.6.\)
Đó chính xác là những gì &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; làm bên trong mỗi vòng lặp ngoài trước khi cập nhật lại \(p_i, w_i, z_i\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;glmnet-và-quic&quot;&gt;Glmnet và QUIC&lt;/h2&gt;
&lt;p&gt;Có hai thư viện phần mềm nổi tiếng được xây dựng dựa trên phương pháp Newton proximal:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;glmnet&lt;/strong&gt; (Friedman et al., 2009): Cài đặt Newton proximal cho các mô hình tuyến tính tổng quát (generalized linear models) có phạt \(\ell_1\), với bài toán con bên trong giải bằng hạ theo tọa độ (coordinate descent).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;QUIC&lt;/strong&gt; (Hsieh et al., 2011): Cài đặt Newton proximal cho bài toán graphical lasso, kết hợp kỹ thuật phân rã ma trận và giải bài toán con bên trong bằng hạ theo tọa độ.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cả hai thư viện đều được sử dụng rộng rãi và là chuẩn tham chiếu trong lĩnh vực ứng dụng tương ứng.&lt;/p&gt;

&lt;p&gt;Phương pháp Newton proximal đánh giá gradient của \(g\) ít lần hơn nhiều so với proximal gradient descent. Do đó, chi phí tính \(g\) và \(\nabla g\) càng lớn thì Newton proximal càng phát huy lợi thế, đặc biệt khi kết hợp với một bộ giải bên trong phù hợp.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-hồi-quy-logistic-lasso&quot;&gt;Ví dụ: hồi quy logistic lasso&lt;/h2&gt;
&lt;p&gt;Xét thí nghiệm thực nghiệm trong Lee et al. (2012) trên bài toán hồi quy logistic có điều chuẩn \(\ell_1\), so sánh ba thuật toán:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;FISTA:&lt;/strong&gt; Proximal gradient tăng tốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;spaRSA:&lt;/strong&gt; Phương pháp gradient chiếu phổ (spectral projected gradient).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;PN:&lt;/strong&gt; Phương pháp Newton proximal.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;trường-hợp-hessian-dày-đặc-n--5000-p--6000&quot;&gt;Trường hợp Hessian dày đặc (\(n = 5000, p = 6000\))&lt;/h4&gt;
&lt;p&gt;Bài toán đầu tiên có ma trận đặc trưng dày đặc \(X\) với \(n = 5000\) mẫu và \(p = 6000\) đặc trưng. Do Hessian dày đặc, đây là trường hợp rất thách thức. Kết quả hiệu năng như sau:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter19/09.05_Lasso_Example1.png&quot; alt=&quot;[Hình 1] Hessian dày đặc X (n=5000, p=6000) [2]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Hessian dày đặc X (n=5000, p=6000) [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Đồ thị bên phải đo hiệu năng theo số lần đánh giá hàm và đồ thị bên trái đo theo thời gian chạy. Xét theo số lần đánh giá hàm, PN vượt trội rõ rệt. Trong bài toán này, phần lớn thời gian nằm ở việc tính \(g\) và \(\nabla g\) (đặc biệt là các hàm \(\exp\) và \(\log\)).&lt;/p&gt;

&lt;h4 id=&quot;trường-hợp-hessian-thưa-n--542000-p--47000&quot;&gt;Trường hợp Hessian thưa (\(n = 542{,}000, p = 47{,}000\))&lt;/h4&gt;

&lt;p&gt;Trong thí nghiệm thứ hai, ma trận đặc trưng \(X\) thưa nên thời gian tính \(g\) và \(\nabla g\) giảm đáng kể:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter19/09.05_Lasso_Example-sparse.png&quot; alt=&quot;[Hình 2] Hessian thưa X (n=542,000, p=47,000) [2]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Hessian thưa X (n=542,000, p=47,000) [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;tính-toán-tử-prox-không-chính-xác&quot;&gt;Tính toán tử prox không chính xác&lt;/h2&gt;
&lt;p&gt;Trong phương pháp Newton proximal, toán tử prox có tỉ lệ nhìn chung không có nghiệm dạng đóng nên phải giải gần đúng bằng thuật toán lặp bên trong. Tuy vậy, ta vẫn muốn giữ được tốc độ hội tụ nhanh mà không lãng phí công tính toán ở các vòng ngoài đầu tiên.&lt;/p&gt;

&lt;p&gt;Lee, Sun và Saunders (2014) đề xuất các quy tắc dừng cho bộ giải bên trong nhằm vẫn bảo đảm hội tụ toàn cục và tốc độ hội tụ siêu tuyến tính (hoặc bậc hai) cục bộ.&lt;/p&gt;

&lt;h4 id=&quot;so-sánh-ba-quy-tắc-dừng&quot;&gt;So sánh ba quy tắc dừng&lt;/h4&gt;
&lt;p&gt;Ba quy tắc dừng cho bài toán con bên trong được so sánh trên bài toán ước lượng graphical lasso với \(n = 72\) mẫu và \(p = 1255\) đặc trưng:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter19/09.05_Inexact_prox.png&quot; alt=&quot;[Hình 3] Ba quy tắc dừng [2]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 3] Ba quy tắc dừng [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Ba quy tắc dừng gồm: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;adaptive&lt;/code&gt; (thích nghi), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;maxiter = 10&lt;/code&gt; (chạy tối đa 10 vòng lặp bên trong) và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exact&lt;/code&gt; (giải đến độ chính xác rất cao).&lt;/p&gt;

&lt;p&gt;Quy tắc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exact&lt;/code&gt; thể hiện rõ tốc độ hội tụ bậc hai nhưng tốn nhiều thời gian cho mỗi bước ngoài. Với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;maxiter = 10&lt;/code&gt;, số vòng lặp bên trong không đủ để duy trì hội tụ bậc hai. Trong khi đó, quy tắc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;adaptive&lt;/code&gt; vừa giữ được hội tụ bậc hai vừa đạt thời gian chạy nhanh nhất trong ba phương án.&lt;/p&gt;

&lt;h4 id=&quot;quy-tắc-dừng-trong-phương-pháp-newton-cổ-điển&quot;&gt;Quy tắc dừng trong phương pháp Newton cổ điển&lt;/h4&gt;
&lt;p&gt;Trong phương pháp Newton không chính xác cổ điển, bài toán con bên trong cực tiểu hóa mô hình bậc hai \(\tilde{g}_{k-1}\) của \(g\) tại \(x^{(k-1)}\). Ta chọn một dãy cưỡng bức (forcing sequence) \(\eta_k \ (k = 1, 2, 3, \dots)\) và dừng giải bài toán con khi:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\parallel \nabla \tilde{g}_{k-1}(x^{(k)}) \parallel_2 &amp;amp; \le \eta_k \parallel  \nabla g(x^{(k-1)})  \parallel_2 \&lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Điều kiện này yêu cầu chuẩn gradient của mô hình bậc hai tại điểm mới nhỏ hơn tối đa \(\eta_k\) lần chuẩn gradient hiện tại, trong đó \(\tilde{g}_{k-1}(z) = \nabla g(x^{(k-1)})^T (z-x^{(k-1)}) + \frac{1}{2} (z - x^{(k-1)})^T \nabla^2 g(x^{(k-1)}) (z - x^{(k-1)})\).&lt;/p&gt;

&lt;h4 id=&quot;quy-tắc-dừng-trong-phương-pháp-newton-proximal&quot;&gt;Quy tắc dừng trong phương pháp Newton proximal&lt;/h4&gt;
&lt;p&gt;Lee et al. (2012) mở rộng quy tắc trên cho trường hợp bài toán tổng hợp bằng cách thay gradient bằng ánh xạ gradient tổng quát:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\parallel G_{\tilde{f}_{k-1}/M}(x^{(k)}) \parallel_2 &amp;amp; \le \eta_k \parallel  G_{f/M}(x^{(k-1)})  \parallel_2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\tilde{f}_{k-1} = \tilde{g}_{k-1} + h\) và \(mI \preceq \nabla^2 g \preceq MI\).&lt;/p&gt;

&lt;p&gt;Các tác giả chứng minh rằng nếu chọn dãy \(\eta_k\) thỏa mãn điều kiện dưới đây, phương pháp Newton proximal không chính xác vẫn đạt tốc độ hội tụ siêu tuyến tính cục bộ:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\eta_k \le \min \left\{ \frac{m}{2},  \frac{\parallel  G_{\tilde{f}_{k-2}/M}(x^{(k-1)}) - G_{f/M}(x^{(k-1)})  \parallel_2}{\parallel  G_{f/M}(x^{(k-2)})  \parallel_2} \right\}
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>19-04 Phân tích hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_04_Convergence_analysis/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_04_Convergence_analysis</id>
   <content type="html">&lt;p&gt;Nhìn vào bài toán tổng hợp \(f(x) = g(x) + h(x)\), nhiều người từng nghi ngờ: &lt;em&gt;sự có mặt của hàm không khả vi \(h(x)\) có phá hỏng tốc độ hội tụ bậc hai trứ danh của phương pháp Newton không?&lt;/em&gt; Định lý kinh điển của Lee, Sun và Saunders (2014) đã đưa ra câu trả lời đầy bất ngờ: &lt;strong&gt;KHÔNG!&lt;/strong&gt; Miễn là phần trơn \(g\) lồi mạnh và có Hessian liên tục Lipschitz, phương pháp Newton proximal vẫn thừa kế nguyên vẹn hai giai đoạn hội tụ của Newton cổ điển — hội tụ toàn cục nhờ backtracking, rồi bứt tốc &lt;strong&gt;hội tụ bậc hai cục bộ&lt;/strong&gt; với bước đơn vị \(t_k = 1\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-giả-thiết-và-cơ-chế-chứng-minh-hội-tụ-bậc-hai&quot;&gt;Kiến thức cần nhớ: Bốn giả thiết và cơ chế chứng minh hội tụ bậc hai&lt;/h2&gt;

&lt;p&gt;Để nắm chắc định lý hội tụ của Lee, Sun và Saunders (2014), hãy xem vai trò chính xác của từng giả thiết:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lồi mạnh và trơn của \(g\) (\(mI \preceq \nabla^2 g(x) \preceq LI\)):&lt;/strong&gt; Đảm bảo Hessian \(H_k\) luôn khả nghịch và có số điều kiện bị chặn bởi \(L/m\), đồng thời nghiệm tối ưu \(x^\star\) là duy nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hessian liên tục Lipschitz (\(\|\nabla^2 g(x) - \nabla^2 g(y)\|_2 \le M\|x - y\|_2\)):&lt;/strong&gt; Khống chế sai số của mô hình bậc hai cục bộ ở bậc \(O(\|x - x^\star\|^2)\), là nguồn gốc trực tiếp tạo ra số mũ bình phương trong hội tụ bậc hai.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính điểm bất động và không giãn của \(\operatorname{prox}_H\):&lt;/strong&gt; Nghiệm tối ưu \(x^\star\) chính là điểm bất động \(x^\star = \operatorname{prox}_H(x^\star - H^{-1}\nabla g(x^\star))\). Kết hợp với tính không giãn theo chuẩn \(H\) giúp đánh giá trực tiếp \(\|x^+ - x^\star\|_H\) theo sai số bậc hai của gradient!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp giải gần đúng bài toán con (Inexact Proximal Newton):&lt;/strong&gt; Trong thực tế không ai giải bài toán con chính xác tuyệt đối. Miễn là sai số bài toán con giảm nhanh tỉ lệ với \(\|v^{(k)}\|\) (tiêu chuẩn cưỡng bức Eisenstat–Walker), thuật toán vẫn giữ được hội tụ siêu tuyến tính hoặc bậc hai!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-theo-dõi-con-số-hội-tụ-bậc-hai-qua-công-thức-xk1---xstar-le-fracm2mxk---xstar2&quot;&gt;Giải thích: Theo dõi con số hội tụ bậc hai qua công thức \(\|x^{(k+1)} - x^\star\| \le \frac{M}{2m}\|x^{(k)} - x^\star\|^2\)&lt;/h3&gt;

&lt;p&gt;Giả sử một bài toán tổng hợp có các hằng số \(m = 1\) (lồi mạnh), \(M = 2\) (Lipschitz của Hessian). Khi đó hệ số hội tụ bậc hai là \(C = \frac{M}{2m} = \frac{2}{2(1)} = 1\), và vùng hội tụ bậc hai bắt đầu khi \(e_k = \|x^{(k)} - x^\star\|_2 &amp;lt; \frac{1}{C} = 1\) (với \(t_k = 1\)).&lt;/p&gt;

&lt;p&gt;Hãy theo dõi sai số \(e_k\) bắt đầu từ lúc thuật toán vừa bước vào vùng cục bộ với \(e_0 = 0.1\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 1:&lt;/strong&gt; \(e_1 \le 1 \cdot (0.1)^2 = 10^{-2}\) (2 chữ số chính xác).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 2:&lt;/strong&gt; \(e_2 \le 1 \cdot (10^{-2})^2 = 10^{-4}\) (4 chữ số chính xác).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 3:&lt;/strong&gt; \(e_3 \le 1 \cdot (10^{-4})^2 = 10^{-8}\) (8 chữ số chính xác).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 4:&lt;/strong&gt; \(e_4 \le 1 \cdot (10^{-8})^2 = 10^{-16}\) — &lt;strong&gt;chạm giới hạn độ chính xác dấu phẩy động 64-bit (machine epsilon) chỉ sau 4 vòng lặp!&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So sánh với Proximal Gradient trên cùng bài toán (giả sử \(L = 10\), tỉ lệ co \(1 - m/L = 0.9\)): muốn giảm sai số từ \(0.1\) xuống \(10^{-16}\), PGD cần tới \(\frac{\ln(10^{15})}{\ln(1/0.9)} \approx \mathbf{328}\) vòng lặp! Đó chính là sức mạnh của tốc độ \(O(\log\log(1/\epsilon))\).&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Để phân tích sự hội tụ của phương pháp Newton proximal, chúng ta trình bày theo chứng minh của Lee, Sun và Saunders (2014) [1].&lt;/p&gt;

&lt;p&gt;[1] J. Lee, Y. Sun and M. Saunders (2014), “Proximal Newton-type methods for minimizing composite functions”.&lt;/p&gt;

&lt;p&gt;Xét các giả thiết sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(f = g + h\), trong đó \(g\) và \(h\) lồi, còn \(g\) khả vi hai lần (trơn).&lt;/li&gt;
  &lt;li&gt;\(mI \preceq \nabla^2 g(x) \preceq LI\) (với \(0 &amp;lt; m \le L\)).&lt;/li&gt;
  &lt;li&gt;Hessian \(\nabla^2 g(x)\) liên tục Lipschitz với hằng số \(M\).&lt;/li&gt;
  &lt;li&gt;Ánh xạ \(\text{prox}_H(\cdot)\) được tính chính xác ở mỗi vòng lặp.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Các giả thiết trên kéo theo \(f\) lồi mạnh (nên có nghiệm tối ưu duy nhất); giả thiết tính chính xác \(\text{prox}_H(\cdot)\) được đặt ra để thuận tiện cho phân tích lý thuyết (trường hợp tính gần đúng sẽ xét ở phần sau).&lt;/p&gt;

&lt;h2 id=&quot;định-lý-hội-tụ&quot;&gt;Định lý hội tụ&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Phương pháp Newton proximal&lt;/strong&gt; kết hợp backtracking line search hội tụ toàn cục, và đạt tốc độ hội tụ bậc hai cục bộ:
\begin{align}
\parallel x^{(k)} - x^{\star} \parallel_2 \le \frac{M}{2m} \parallel x^{(k-1)} - x^{\star} \parallel_2^2
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sau một số hữu hạn bước \(k \ge k_0\), để đạt \(f(x^{(k)}) - f^{\star} \le \epsilon\) chỉ cần \(O(\log \log (1/\epsilon))\) vòng lặp ngoài (lưu ý mỗi vòng lặp đòi hỏi đánh giá một ánh xạ prox có tỉ lệ).&lt;/p&gt;

&lt;h2 id=&quot;phác-thảo-chứng-minh&quot;&gt;Phác thảo chứng minh&lt;/h2&gt;
&lt;p&gt;Để chứng minh &lt;strong&gt;hội tụ toàn cục&lt;/strong&gt;, ta chỉ ra rằng ở mọi vòng lặp, điều kiện dừng của backtracking line search luôn được thỏa mãn khi độ dài bước \(t\) thỏa mãn:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
t \le \min \left\{ 1, \frac{2m}{L} (1-\alpha) \right\} \&lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Từ cận dưới dương này của độ dài bước, có thể suy ra hướng cập nhật hội tụ về \(0\) và dãy lặp hội tụ về cực tiểu toàn cục \(x^{\star}\).&lt;/p&gt;

&lt;p&gt;Để chứng minh &lt;strong&gt;hội tụ bậc hai cục bộ&lt;/strong&gt;, khi điểm lặp đã đủ gần \(x^{\star}\), bước đơn vị \(t = 1\) luôn được chấp nhận bởi backtracking line search và bất đẳng thức sau được thỏa mãn:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\parallel x^{+} - x^{\star} \parallel_2 &amp;amp; \le \frac{1}{\sqrt{m}} \parallel x^{+} - x^{\star} \parallel_H \\\\
&amp;amp; =  \frac{1}{\sqrt{m}} \parallel \text{prox}_H(x - H^{-1} \nabla g(x) )  - \text{prox}_H(x^{\star} - H^{-1} \nabla g(x^{\star}) )  \parallel_H \\\\
&amp;amp; \le \frac{M}{2m} \parallel x - x^{\star} \parallel_2^2 \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tóm gọn lại:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\parallel x^{+} - x^{\star} \parallel_2 \ \le \ \frac{1}{\sqrt{m}} \parallel x^{+} - x^{\star} \parallel_H \  \le \ \frac{M}{2m} \parallel x - x^{\star} \parallel_2^2
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Bất đẳng thức đầu tiên sử dụng cận dưới trị riêng \(mI \preceq H\), còn đẳng thức suy ra từ định nghĩa của \(x^+\) và tính chất điểm bất động của nghiệm tối ưu \(x^{\star} = \text{prox}_H(x^{\star} - H^{-1}\nabla g(x^{\star}))\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Bất đẳng thức thứ hai sử dụng tính không giãn của toán tử proximal theo chuẩn \(H\), tính chất Lipschitz bậc hai với hằng số \(M\) của \(\nabla^2 g\) và cận dưới trị riêng \(m\).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>19-03 Khi nào nên dùng Newton proximal?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_03_When_would_we_use_proximal_Newton/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_03_When_would_we_use_proximal_Newton</id>
   <content type="html">&lt;p&gt;Trong tối ưu hóa, không có thuật toán nào là “chén thánh” thắng ở mọi bài toán. Proximal Newton hội tụ siêu nhanh về số vòng lặp ngoài (\(O(\log\log(1/\epsilon))\) so với \(O(1/\epsilon)\) của proximal gradient), nhưng cái giá phải trả lại vô cùng đắt đỏ: &lt;strong&gt;mỗi một vòng lặp ngoài của nó lại phải giải cả một bài toán tối ưu bậc hai có phạt bên trong!&lt;/strong&gt; Vậy ranh giới nào phân định lúc nào nên dùng Proximal Newton và lúc nào nên trung thành với Proximal Gradient?&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-tiêu-chí-quyết-định-chọn-proximal-newton-hay-proximal-gradient&quot;&gt;Kiến thức cần nhớ: Bốn tiêu chí quyết định chọn Proximal Newton hay Proximal Gradient&lt;/h2&gt;

&lt;p&gt;Để đưa ra quyết định kiến trúc bộ giải chính xác trong thực tế, hãy cân đo bốn yếu tố sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí đánh giá hàm \(g\) và gradient \(\nabla g\):&lt;/strong&gt; Nếu tính \(\nabla g(x)\) rất đắt (ví dụ duyệt qua tập dữ liệu hàng triệu mẫu trong hồi quy logistic, hoặc tính nghịch đảo ma trận log-det \(O(p^3)\) trong graphical lasso), thì việc giảm số vòng lặp ngoài từ 2.000 xuống còn 10 vòng của Proximal Newton sẽ tiết kiệm thời gian khổng lồ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ thưa của nghiệm và tập hoạt động (Active Set):&lt;/strong&gt; Khi \(h(x) = \lambda\|x\|_1\) tạo ra nghiệm rất thưa (hầu hết tọa độ bằng \(0\)), bộ giải hạ tọa độ bên trong chỉ cần chạy trên tập nhỏ các biến khác \(0\) — biến bài toán con bậc hai tưởng chừng đắt đỏ trở nên cực rẻ!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Yêu cầu độ chính xác cuối cùng \(\epsilon\):&lt;/strong&gt; Nếu chỉ cần sai số thô \(10^{-2}\) (như nhiều bài toán học sâu), bậc nhất là đủ nhanh; nhưng nếu cần sai số chính xác \(10^{-8}\text{–}10^{-12}\) (thống kê, điều khiển, tài chính), hội tụ bậc hai của Newton proximal bỏ xa hoàn toàn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số điều kiện của Hessian \(\nabla^2 g\):&lt;/strong&gt; Khi các đặc trưng tương quan mạnh làm số điều kiện \(\kappa = L/m\) rất lớn, PGD bị dao động hình răng cưa suốt hàng nghìn bước, còn Proximal Newton triệt tiêu hoàn toàn độ lệch trục.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-nhanh-bài-toán-chi-phí-thực-tế-giữa-pgd-và-proximal-newton&quot;&gt;Giải thích: Tính nhanh bài toán chi phí thực tế giữa PGD và Proximal Newton&lt;/h3&gt;

&lt;p&gt;Giả sử bạn giải một bài toán hồi quy logistic có phạt \(\ell_1\) với \(n = 50{,}000\) mẫu và \(p = 500\) đặc trưng (nhưng chỉ có khoảng \(s = 25\) đặc trưng thực sự khác \(0\) ở nghiệm):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí mỗi vòng lặp của Proximal Gradient (PGD):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đánh giá \(\nabla g(x)\) cần nhân ma trận \(X^T(p - y)\) tốn cỡ \(2np = 5 \times 10^7\) phép toán; bước ngưỡng mềm chỉ tốn \(500\) phép toán (không đáng kể).&lt;/li&gt;
      &lt;li&gt;Giả sử bài toán có số điều kiện xấu khiến PGD cần &lt;strong&gt;400 vòng lặp&lt;/strong&gt; để đạt \(\epsilon = 10^{-6}\): tổng chi phí \(\approx 400 \times 5 \times 10^7 = 2.0 \times 10^{10}\) phép toán.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí mỗi vòng lặp của Proximal Newton (kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đánh giá \(\nabla g(x)\) và ma trận trọng số đường chéo \(W\) tốn cỡ \(5 \times 10^7\) phép toán.&lt;/li&gt;
      &lt;li&gt;Bài toán con bậc hai được giải bằng hạ tọa độ trên tập hoạt động \(s = 25\) biến (chỉ lập ma trận Hessian con \(25 \times 25\)), tốn cỡ \(3 \times 10^6\) phép toán (chỉ bằng &lt;strong&gt;6%&lt;/strong&gt; chi phí tính gradient!).&lt;/li&gt;
      &lt;li&gt;Proximal Newton chỉ cần &lt;strong&gt;8 vòng lặp ngoài&lt;/strong&gt; để đạt \(\epsilon = 10^{-6}\): tổng chi phí \(\approx 8 \times 5.3 \times 10^7 = 4.24 \times 10^8\) phép toán — &lt;strong&gt;nhanh gấp gần 47 lần so với PGD!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Khi nào phương pháp Newton proximal là lựa chọn phù hợp?&lt;/p&gt;

&lt;p&gt;Để trả lời câu hỏi này, ta so sánh phương pháp Newton proximal với proximal gradient descent trên bài toán tổng hợp:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; \(\min_x g(x) + h(x)\)&lt;/p&gt;

&lt;h2 id=&quot;so-sánh-proximal-gradient-descent-và-newton-proximal&quot;&gt;So sánh Proximal gradient descent và Newton proximal&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;strong&gt;Proximal gradient descent&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Newton proximal&lt;/strong&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Ở mỗi bước cực tiểu hóa \(\frac{1}{2} \parallel b - x \parallel_2^2 + h(x)\)&lt;/td&gt;
      &lt;td&gt;Ở mỗi bước cực tiểu hóa \(b^T x + x^T A x + h(x)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Toán tử prox thường có nghiệm dạng đóng&lt;/td&gt;
      &lt;td&gt;Toán tử prox thường không có nghiệm dạng đóng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Chi phí mỗi vòng lặp thấp&lt;/td&gt;
      &lt;td&gt;Chi phí mỗi vòng lặp rất cao (cao hơn cả phương pháp Newton)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tốc độ hội tụ tương tự gradient descent: &lt;br /&gt; \(O(1/\epsilon)\)&lt;/td&gt;
      &lt;td&gt;Tốc độ hội tụ tương tự phương pháp Newton: &lt;br /&gt; \(O(\log \log (1/\epsilon))\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Dù có dạng công thức tương đồng, hai phương pháp vận hành rất khác nhau về đánh đổi chi phí.&lt;/p&gt;

&lt;p&gt;Vì vậy, phương pháp Newton proximal đặc biệt đáng dùng khi ta có một bộ giải bên trong đủ nhanh cho bài toán prox có tỉ lệ (dạng toàn phương \(+\ h\)), nhờ đó tận dụng ưu thế chỉ cần rất ít vòng lặp ngoài. Khi \(h\) là hàm tách biến (separable), bộ giải bên trong phổ biến nhất là phương pháp hạ theo tọa độ (coordinate descent).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>19-02 Backtracking line search</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_02_Backtracking_line_search/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_02_Backtracking_line_search</id>
   <content type="html">&lt;p&gt;Cũng giống như phương pháp Newton cổ điển có thể “nhảy vọt” ra xa vô cùng nếu xuất phát ở vùng xa nghiệm và cứ cố chấp lấy bước đơn vị \(t_k = 1\), phương pháp Newton proximal cũng cần một “bộ phanh” bảo đảm hội tụ toàn cục. Bộ phanh đó chính là &lt;strong&gt;tìm kiếm theo đường lui (backtracking line search)&lt;/strong&gt; phiên bản tổng hợp: vì hàm \(h\) không khả vi nên không thể thay bằng \(\nabla h(x)^T v\), ta giữ nguyên độ chênh lệch thực \(h(x + tv) - h(x)\) (hoặc cận trên tuyến tính \(t(h(x+v) - h(x))\)) trong điều kiện Armijo!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-cơ-chế-bảo-đảm-an-toàn-của-backtracking-tổng-hợp&quot;&gt;Kiến thức cần nhớ: Ba cơ chế bảo đảm an toàn của Backtracking tổng hợp&lt;/h2&gt;

&lt;p&gt;Để hiểu vì sao điều kiện dừng backtracking trong bài vừa luôn kết thúc sau hữu hạn bước, vừa tự động nhận \(t = 1\) khi gần nghiệm, hãy chú ý ba điểm:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đạo hàm có hướng của hàm tổng hợp \(f = g + h\):&lt;/strong&gt; Với mọi \(t \in (0, 1]\), nhờ tính lồi của \(h\), ta luôn có \(h(x + tv) - h(x) \le t(h(x + v) - h(x))\). Do đó, đại lượng \(\Delta(x, v) = \nabla g(x)^T v + h(x + v) - h(x) \le -v^T H v &amp;lt; 0\) đóng vai trò tốc độ giảm kỳ vọng theo hướng \(v\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện giảm đủ Armijo tổng hợp:&lt;/strong&gt; Yêu cầu \(f(x + tv) \le f(x) + \alpha t \nabla g(x)^T v + \alpha(h(x + tv) - h(x))\) (với \(0 &amp;lt; \alpha \le 1/2\)) đảm bảo mức giảm thực tế đạt ít nhất một tỉ lệ \(\alpha\) của mức giảm mô hình bậc nhất–tổng hợp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển pha tự động sang bước đơn vị \(t = 1\):&lt;/strong&gt; Khi \(x\) tiến đủ gần \(x^\star\) và \(\alpha &amp;lt; 1/2\), khai triển Taylor bậc hai cho thấy điều kiện Armijo &lt;strong&gt;luôn được thỏa mãn ngay tại \(t = 1\)&lt;/strong&gt;. Nhờ vậy, backtracking không bao giờ cản trở tốc độ hội tụ bậc hai cục bộ của Newton proximal!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-backtracking-line-search-trên-hàm-mũ-có-phạt-ell_1&quot;&gt;Giải thích: Chạy tay backtracking line search trên hàm mũ có phạt \(\ell_1\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét bài toán $$f(x) = \underbrace{e^x - x}_{g(x)} + \underbrace{0.5&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;}_{h(x)}\(tại\)x = 2\(, với\)\alpha = 0.25, \beta = 0.5$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giá trị ban đầu và hướng Newton proximal \(v\) tại \(x = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g(2) = e^2 - 2 \approx 5.3891\), \(h(2) = 1.0 \implies f(2) \approx 6.3891\).&lt;/li&gt;
      &lt;li&gt;\(g&apos;(2) = e^2 - 1 \approx 6.3891\), \(H = g&apos;&apos;(2) = e^2 \approx 7.3891\).&lt;/li&gt;
      &lt;li&gt;Hướng Newton proximal: \(x + v = S_{0.5/7.3891}\!\left(2 - \frac{6.3891}{7.3891}\right) = S_{0.0677}(1.1353) = 1.0676 \implies v = -0.9324\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử bước đơn vị \(t = 1\) (\(x^+ = 1.0676\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giá trị thực mới: \(f(1.0676) = e^{1.0676} - 1.0676 + 0.5(1.0676) \approx 2.9084 - 1.0676 + 0.5338 = 2.3746\).&lt;/li&gt;
      &lt;li&gt;Ngưỡng vế phải Armijo:
\(f(2) + 0.25(1)(6.3891)(-0.9324) + 0.25(0.5338 - 1.0) = 6.3891 - 1.4893 - 0.1166 = 4.7832.\)&lt;/li&gt;
      &lt;li&gt;So sánh: \(2.3746 \le 4.7832\) — &lt;strong&gt;thỏa mãn ngay ở lần thử đầu tiên!&lt;/strong&gt; Bước \(t = 1\) được chấp nhận ngay lập tức.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khi nào backtracking phải thu nhỏ \(t\)?&lt;/strong&gt; Nếu hàm \(g\) có độ cong tăng vọt đột ngột ở phía bước đi (ví dụ \(g(x) = e^{-5x} + x^2\) tại \(x = 1\) khiến bước \(t = 1\) nhảy sang vùng \(x &amp;lt; 0\) nơi \(e^{-5x}\) bùng nổ), thì \(f(x + v) &amp;gt; \text{ngưỡng}\), và vòng lặp sẽ tự động giảm \(t = 0.5, 0.25, \dots\) cho tới khi rơi vào vùng giảm thực sự.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Tương tự phương pháp Newton cổ điển, &lt;strong&gt;phương pháp Newton proximal&lt;/strong&gt; có thể không hội tụ nếu luôn dùng bước đơn vị \(t_k = 1\) (\(k = 1, 2, 3, \dots\)). Vì vậy, cần chọn độ dài bước phù hợp bằng tìm kiếm theo đường lui (backtracking line search).&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán-tìm-kiếm-theo-đường-lui-backtracking-line-search&quot;&gt;Thuật toán tìm kiếm theo đường lui (Backtracking line search)&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Khởi tạo các tham số \(0 \lt \alpha \le 1/2\) và \(0 \lt \beta \lt 1\).&lt;/li&gt;
  &lt;li&gt;Ở mỗi vòng lặp, tính hướng Newton proximal \(v = \text{prox}_{H} ( x - H^{-1} \nabla g (x) ) - x\).&lt;/li&gt;
  &lt;li&gt;Khởi tạo \(t = 1\).&lt;/li&gt;
  &lt;li&gt;Khi điều kiện \(f(x + tv) \gt f(x) + \alpha t \nabla g(x)^T v + \alpha (h(x + tv) - h(x))\) còn đúng, giảm \(t = \beta t\) và lặp lại kiểm tra (với \(f = g + h\)).&lt;/li&gt;
  &lt;li&gt;Cập nhật nghiệm \(x^+ = x + tv\).&lt;/li&gt;
  &lt;li&gt;Nếu chưa đạt điều kiện dừng, quay lại bước 2.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Về mặt trực giác, ta tìm độ dài bước \(t\) sao cho mức giảm thực tế của \(f = g + h\) dọc theo hướng \(v\) đạt ít nhất tỷ lệ \(\alpha\) so với mức giảm dự báo cục bộ. Do phần \(h\) không khả vi, sự thay đổi của nó được đánh giá trực tiếp qua hiệu \(h(x + tv) - h(x)\) thay vì đạo hàm.&lt;/p&gt;

&lt;h2 id=&quot;hiệu-quả-tính-toán&quot;&gt;Hiệu quả tính toán&lt;/h2&gt;
&lt;p&gt;Có nhiều biến thể của backtracking line search; cách trình bày ở trên có một ưu điểm tính toán rất đáng chú ý: toán tử prox chỉ cần tính &lt;strong&gt;một lần duy nhất&lt;/strong&gt; để xác định hướng \(v\) trước khi vào vòng lặp giảm \(t\). Trái lại, trong proximal gradient descent tiêu chuẩn, toán tử prox thường phải được tính lại ở mỗi lần thử độ dài bước bên trong vòng lặp. Nhờ đó, lược đồ này đặc biệt hiệu quả khi việc đánh giá toán tử prox có tỉ lệ tốn kém.&lt;/p&gt;

&lt;h3 id=&quot;tham-khảo-backtracking-line-search-cho-các-phương-pháp-khác&quot;&gt;[Tham khảo] Backtracking line search cho các phương pháp khác&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Gradient descent: &lt;a href=&quot;/contents/vi/chapter06/06_02_02_backtracking_line_search/&quot;&gt;06-02-02 Backtracking line search&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Proximal gradient descent: &lt;a href=&quot;/contents/vi/chapter09/09_02_convergence_analysis/&quot;&gt;09-02 Phân tích hội tụ&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Phương pháp Newton: &lt;a href=&quot;/contents/vi/chapter14/14_04_backtracking_line_search/&quot;&gt;14-04 Backtracking line search&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>19-01-03 Ánh xạ proximal có tỉ lệ (Scaled proximal map)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_01_03_Scaled_proximal_map/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_01_03_Scaled_proximal_map</id>
   <content type="html">&lt;p&gt;Một trong những nét thanh lịch nhất của giải tích lồi là khi ta đổi góc nhìn bằng đúng ký hiệu, cả một thuật toán phức tạp đột nhiên trở nên gọn gàng như một dòng thơ. Bằng cách định nghĩa &lt;strong&gt;ánh xạ proximal có tỉ lệ&lt;/strong&gt; \(\operatorname{prox}_H(x) = \arg\min_z \frac{1}{2}\|x - z\|_H^2 + h(z)\), toàn bộ bước cập nhật của phương pháp Newton proximal được viết lại thành đúng một dòng y hệt proximal gradient descent — chỉ thay \(t\) bằng \(H^{-1}\)! Hơn thế nữa, ánh xạ mới này bảo toàn trọn vẹn các tính chất của toán tử prox chuẩn trong không gian trang bị tích vô hướng \(\langle u, v \rangle_H = u^T H v\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-hình-học-của-ánh-xạ-proximal-có-tỉ-lệ&quot;&gt;Kiến thức cần nhớ: Ba trụ cột hình học của ánh xạ proximal có tỉ lệ&lt;/h2&gt;

&lt;p&gt;Để hiểu sâu chứng minh tính duy nhất và tính không giãn (non-expansiveness) trong bài, hãy nắm chắc ba khái niệm sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không gian Euclid biến dạng bởi ma trận \(H \succ 0\):&lt;/strong&gt; Đặt tích vô hướng mới \(\langle u, v \rangle_H = u^T H v\) và chuẩn \(\|u\|_H = \sqrt{u^T H u}\). Hình cầu đơn vị trong chuẩn này là một hình elip trong không gian gốc; phép đổi biến \(y = H^{1/2} x\) biến chuẩn \(H\) trở về chuẩn Euclid thông thường!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính duy nhất và điều kiện tối ưu bậc nhất:&lt;/strong&gt; Vì \(H \succ 0\) nên \(\frac{1}{2}\|x - z\|_H^2\) lồi mạnh, kéo theo \(\operatorname{prox}_H(x)\) luôn tồn tại và &lt;strong&gt;duy nhất&lt;/strong&gt;, đặc trưng bởi bao hàm thức dưới vi phân \(H(x - z) \in \partial h(z)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính không giãn vững (Firm Non-Expansiveness) theo chuẩn \(H\):&lt;/strong&gt; Bất đẳng thức \(\|\operatorname{prox}_H(x) - \operatorname{prox}_H(y)\|_H \le \|x - y\|_H\) đảm bảo ánh xạ không khuếch đại sai số — công cụ cốt lõi để chứng minh định lý hội tụ của Newton proximal ở bài 19-04.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-operatornameprox_hx-và-kiểm-chứng-tính-không-giãn-trong-chuẩn-h&quot;&gt;Giải thích: Tính tay \(\operatorname{prox}_H(x)\) và kiểm chứng tính không giãn trong chuẩn \(H\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét $$h(z) = |z|_1 =&lt;/td&gt;
      &lt;td&gt;z_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;z_2&lt;/td&gt;
      &lt;td&gt;\(và ma trận độ cong đường chéo\)H = \begin{bmatrix} 2 &amp;amp; 0 \ 0 &amp;amp; 8 \end{bmatrix} \succ 0$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(\operatorname{prox}_H(x)\) tại \(x = (1, 1)^T\):&lt;/strong&gt;
\(\operatorname{prox}_H(x) = \arg\min_{z_1, z_2} \left\{ \frac{1}{2}\left[2(z_1 - 1)^2 + 8(z_2 - 1)^2\right] + |z_1| + |z_2| \right\}.\)
Bài toán tách theo từng tọa độ:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Tọa độ 1: $$\min_{z_1} (z_1 - 1)^2 +&lt;/td&gt;
              &lt;td&gt;z_1&lt;/td&gt;
              &lt;td&gt;\iff \min_{z_1} \frac{1}{2}(z_1 - 1)^2 + \frac{1}{2}&lt;/td&gt;
              &lt;td&gt;z_1&lt;/td&gt;
              &lt;td&gt;\implies z_1^\star = S_{1/2}(1) = 0.5$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Tọa độ 2: \(\min_{z_2} 4(z_2 - 1)^2 + |z_2| \iff \min_{z_2} \frac{1}{2}(z_2 - 1)^2 + \frac{1}{8}|z_2| \implies z_2^\star = S_{1/8}(1) = 0.875\).
Vậy \(\operatorname{prox}_H(1, 1) = (0.5, \; 0.875)^T\). Chú ý: trục có độ cong lớn hơn (\(H_{22} = 8\)) có ngưỡng co nhỏ hơn gấp 4 lần (\(1/8\) so với \(1/2\))!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng tính không giãn giữa \(x = (1, 1)^T\) và \(y = (0, 0)^T\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ta có \(\operatorname{prox}_H(0, 0) = (0, 0)^T\).&lt;/li&gt;
      &lt;li&gt;Khoảng cách đầu vào theo chuẩn \(H\): \(\|x - y\|_H^2 = 2(1)^2 + 8(1)^2 = 10 \implies \|x - y\|_H = \sqrt{10} \approx 3.162\).&lt;/li&gt;
      &lt;li&gt;Khoảng cách đầu ra theo chuẩn \(H\): \(\|\operatorname{prox}_H(x) - \operatorname{prox}_H(y)\|_H^2 = 2(0.5)^2 + 8(0.875)^2 = 0.5 + 6.125 = 6.625 \implies \sqrt{6.625} \approx 2.574 \le 3.162\)!
Ánh xạ \(\operatorname{prox}_H\) thực sự co khoảng cách lại trong đúng hình học chuẩn \(H\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp Newton proximal&lt;/strong&gt; có thể được viết lại dưới dạng hoàn toàn tương đồng với &lt;strong&gt;proximal gradient descent&lt;/strong&gt; nhờ khái niệm ánh xạ proximal có tỉ lệ.&lt;/p&gt;

&lt;h2 id=&quot;ánh-xạ-proximal-có-tỉ-lệ&quot;&gt;Ánh xạ proximal có tỉ lệ&lt;/h2&gt;
&lt;p&gt;Với ma trận xác định dương \(H \succ 0\), &lt;strong&gt;ánh xạ proximal có tỉ lệ (scaled proximal map)&lt;/strong&gt; ứng với hàm \(h\) được định nghĩa là:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\text{prox}_{H}(x) = \underset{z}{\text{argmin}} \ \frac{1}{2} \parallel x - z \parallel_H^2 + h(z)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\parallel x \parallel_H^2 = x^THx\) là bình phương chuẩn cảm sinh bởi \(H\). Khi \(H = \frac{1}{t} I\), biểu thức này quay về &lt;strong&gt;ánh xạ proximal thông thường&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Nhìn chung, &lt;strong&gt;ánh xạ proximal có tỉ lệ&lt;/strong&gt; giữ nguyên các tính chất tốt của toán tử prox chuẩn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính duy nhất:&lt;/strong&gt; Nghiệm cực tiểu là duy nhất vì \(H \succ 0\) làm bài toán con lồi chặt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính không giãn (non-expansiveness):&lt;/strong&gt; Ánh xạ không làm tăng khoảng cách theo chuẩn \(H\) (tổng quát hóa trực tiếp tính không giãn của phép chiếu lên tập lồi).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;ghi-chú-tính-không-giãn-của-toán-tử-chiếu&quot;&gt;[Ghi chú] Tính không giãn của toán tử chiếu&lt;/h4&gt;
&lt;p&gt;Với hai điểm \(x, y\) và toán tử chiếu Euclid \(P_C\) lên tập lồi \(C\), tính không giãn có nghĩa là \(\parallel P_C(x) - P_C(y) \parallel_2 \le \parallel x - y \parallel_2\). Nói cách khác, \(P_C\) là ánh xạ 1-Lipschitz với mọi tập lồi \(C\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter19/09.01_03_projection_operator.png&quot; alt=&quot;[Hình 1] Phép chiếu lên tập lồi C [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Phép chiếu lên tập lồi C [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;biểu-diễn-cập-nhật-newton-proximal&quot;&gt;Biểu diễn cập nhật Newton proximal&lt;/h2&gt;
&lt;p&gt;Sử dụng &lt;strong&gt;ánh xạ proximal có tỉ lệ&lt;/strong&gt;, bài toán con của phương pháp Newton proximal có thể viết gọn lại như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
z^{+} &amp;amp; = \underset{z}{\text{argmin}} \ \nabla g(x)^T (z - x) + \frac{1}{2} (z - x)^T H (z - x) + h(z) \\\\
&amp;amp; =\underset{z}{\text{argmin}} \ \frac{1}{2} \parallel x - H^{-1} \nabla g(x) - z \parallel_H^2 + h(z)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó, phép cập nhật Newton proximal tương đương với:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
z^{(k)} &amp;amp; = \text{prox}_{H^{(k-1)}} ( x^{(k-1)} - (H^{(k-1)})^{-1} \nabla g (x^{(k-1)}) ) \\\\
x^{(k)} &amp;amp; =x^{(k-1)} + t_k (z^{(k)} - x^{(k-1)} )
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Về mặt trực giác, thuật toán thực hiện một bước Newton trên phần trơn \(g\), áp dụng toán tử proximal có tỉ lệ theo ma trận \(H^{(k-1)}\), rồi di chuyển theo hướng thu được.&lt;/p&gt;

&lt;p&gt;Từ công thức trên có thể rút ra ba nhận xét quan trọng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Khi \(h(z) = 0\), toán tử proximal trở thành phép đồng nhất và ta thu lại phương pháp Newton cổ điển.&lt;/li&gt;
  &lt;li&gt;Khi thay \(H^{(k-1)}\) bằng \(\frac{1}{r_k} I\) và đặt \(t_k = 1\), ta thu lại proximal gradient descent với kích thước bước \(r_k\).&lt;/li&gt;
  &lt;li&gt;Độ khó tính toán của toán tử prox không chỉ phụ thuộc vào \(h\) mà còn phụ thuộc mạnh vào cấu trúc của ma trận \(H\): nếu \(H\) là ma trận đường chéo hoặc ma trận dải (banded), việc giải bài toán con dễ hơn nhiều so với khi \(H\) dày đặc (dense).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Như vậy, phương pháp Newton proximal thống nhất cả proximal gradient descent và phương pháp Newton trong cùng một khuôn khổ.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>19-01-02 Phương pháp Newton proximal</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_01_02_Proximal_Newton_method/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_01_02_Proximal_Newton_method</id>
   <content type="html">&lt;p&gt;Ở bài 19-01-01, ta thấy proximal gradient descent chỉ đơn giản là cực tiểu hóa xấp xỉ bậc hai đẳng hướng của \(g\) cộng với \(h\). Bây giờ hãy thực hiện một cú nâng cấp trực diện: giữ nguyên hoàn toàn triết lý đó, nhưng thay ma trận đơn vị tỉ lệ \(\frac{1}{t}I\) bằng &lt;strong&gt;ma trận Hessian thực&lt;/strong&gt; \(H^{(k-1)} = \nabla^2 g(x^{(k-1)})\)! Kết quả là &lt;strong&gt;phương pháp Newton proximal&lt;/strong&gt;: một thuật toán từng xuất hiện sớm trong thống kê dưới tên gọi &lt;em&gt;local score&lt;/em&gt;, nay trở thành trụ cột của tối ưu hóa tổng hợp bậc hai.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-cấu-thành-thuật-toán-newton-proximal&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép cấu thành thuật toán Newton proximal&lt;/h2&gt;

&lt;p&gt;Để hiểu thấu đáo cấu trúc hai bước (tìm hướng \(v^{(k)}\) rồi chọn bước \(t_k\)) của thuật toán trong bài, hãy tách riêng bốn yếu tố:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán con tìm hướng \(v^{(k)}\):&lt;/strong&gt; Thay vì cộng \(v^{(k)}\) trực tiếp từ một công thức đóng như Newton cổ điển \(-H^{-1}\nabla g\), ta giải \(\min_v \nabla g(x)^T v + \frac{1}{2}v^T H v + h(x + v)\). Lưu ý phần không trơn \(h(x + v)\) được giữ nguyên không hề xấp xỉ!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hướng giảm (Descent Direction):&lt;/strong&gt; Khi \(H \succ 0\), hướng \(v^{(k)}\) thu được luôn thỏa mãn \(\nabla g(x)^T v + h(x + v) - h(x) \le -v^T H v &amp;lt; 0\) (nếu \(x\) chưa tối ưu). Nhờ vậy, chắc chắn tồn tại độ dài bước \(t_k &amp;gt; 0\) làm giảm chặt hàm tổng hợp \(f = g + h\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ dài bước \(t_k \in (0, 1]\):&lt;/strong&gt; Ta cập nhật \(x^{(k)} = x^{(k-1)} + t_k v^{(k)}\). Vì \(h\) lồi, phép tổ hợp lồi \(x + t_k v = (1 - t_k)x + t_k(x + v)\) luôn bảo toàn miền xác định của \(h\) (ví dụ luôn giữ nghiệm khả thi nếu \(h = I_C\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khi \(h \equiv 0\):&lt;/strong&gt; Bài toán con rút gọn về \(\min_v \nabla g(x)^T v + \frac{1}{2}v^T H v \implies v = -H^{-1}\nabla g(x)\), quay về chính xác phương pháp Newton cổ điển!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-1-bước-newton-proximal-cho-hồi-quy-logistic-có-phạt-ell_1&quot;&gt;Giải thích: Tính tay 1 bước Newton proximal cho hồi quy Logistic có phạt \(\ell_1\)&lt;/h3&gt;

&lt;p&gt;Xét bài toán 1 chiều mô phỏng hồi quy logistic có điều chuẩn Lasso:&lt;/p&gt;

\[\min_{x \in \mathbb{R}} \; \underbrace{\log(1 + e^{-x})}_{g(x)} + \underbrace{0.2 |x|}_{h(x)}.\]

&lt;p&gt;Ta có \(g&apos;(x) = \frac{-e^{-x}}{1 + e^{-x}} = -\frac{1}{1 + e^x}\) và \(g&apos;&apos;(x) = \frac{e^x}{(1 + e^x)^2}\). Hãy tính một bước Newton proximal xuất phát từ \(x^{(0)} = 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính đạo hàm bậc nhất và bậc hai của \(g\) tại \(x^{(0)} = 0\):&lt;/strong&gt;
\(g&apos;(0) = -\frac{1}{2} = -0.5, \qquad H^{(0)} = g&apos;&apos;(0) = \frac{1}{4} = 0.25.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập bài toán con tìm hướng \(v^{(1)}\):&lt;/strong&gt;
\(v^{(1)} = \arg\min_{v} \left\{ -0.5 v + \frac{1}{2}(0.25) v^2 + 0.2 |0 + v| \right\} = \arg\min_{v} \left\{ 0.125(v - 2)^2 + 0.2|v| \right\}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải chính xác bài toán con bằng ngưỡng mềm:&lt;/strong&gt; Chia hàm mục tiêu con cho \(H^{(0)} = 0.25\) cho dạng chuẩn \(\frac{1}{2}(v - 2)^2 + \frac{0.2}{0.25}|v| = \frac{1}{2}(v - 2)^2 + 0.8|v|\). Suy ra:
\(v^{(1)} = S_{0.8}(2) = 2 - 0.8 = 1.2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra độ giảm hàm mục tiêu với bước đơn vị \(t_1 = 1\) (\(x^{(1)} = 1.2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(x^{(0)} = 0\): \(f(0) = \log(2) + 0 \approx 0.6931\).&lt;/li&gt;
      &lt;li&gt;Tại \(x^{(1)} = 1.2\): \(f(1.2) = \log(1 + e^{-1.2}) + 0.2(1.2) \approx 0.2633 + 0.2400 = 0.5033\) (giảm rất mạnh!).&lt;/li&gt;
      &lt;li&gt;Kiểm tra độ gần nghiệm tối ưu thực \(x^\star = \ln(4) \approx 1.3863\) (nơi \(g&apos;(x^\star) = -0.2\)): chỉ sau &lt;strong&gt;1 bước&lt;/strong&gt;, ta đã nhảy từ \(0\) lên \(1.2\), sát nghiệm thực \(1.3863\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Ở phần trước, ta đã thấy &lt;strong&gt;phương pháp Newton proximal&lt;/strong&gt; thay thế độ cong đẳng hướng \(\frac{1}{t} I\) trong &lt;strong&gt;proximal gradient descent&lt;/strong&gt; bằng ma trận Hessian cục bộ \(\nabla^2 g(x)\). Ý tưởng này từng được nghiên cứu sớm trong thống kê dưới tên gọi “local score”.&lt;/p&gt;

&lt;p&gt;Dưới đây là cách xây dựng tường minh thuật toán &lt;strong&gt;Newton proximal&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán&quot;&gt;Thuật toán&lt;/h2&gt;
&lt;p&gt;Mỗi vòng lặp của phương pháp Newton proximal gồm hai bước: tìm hướng cập nhật \(v\) và chọn độ dài bước \(t_k\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; Khởi tạo từ điểm ban đầu \(x^{(0)}\) và lặp với \(k = 1, 2, 3, \dots\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt; Tìm hướng bước \(v^{(k)}\) bằng cách giải bài toán con bậc hai có điều chuẩn:&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
v^{(k)} &amp;amp; = \underset{v}{\text{argmin}} \ \nabla g(x^{(k-1)})^T v + \frac{1}{2} v^T H^{(k-1)} v + h(x^{(k-1)} + v)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(H^{(k-1)} = \nabla^2 g(x^{(k-1)})\) là ma trận Hessian của \(g\) tại \(x^{(k-1)}\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3:&lt;/strong&gt; Cập nhật điểm lặp theo hướng \(v^{(k)}\) với độ dài bước \(t_k\):&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{(k)} &amp;amp; =x^{(k-1)} + t_k v^{(k)}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Khi chọn cố định \(t_k = 1\), ta thu được phương pháp Newton proximal thuần túy. Trong thực tế, độ dài bước \(t_k\) thường được xác định qua tìm kiếm theo đường lui (backtracking line search).&lt;/p&gt;

&lt;h4 id=&quot;cách-viết-theo-điểm-đích-z&quot;&gt;Cách viết theo điểm đích \(z\)&lt;/h4&gt;
&lt;p&gt;Nếu biểu diễn bài toán con theo điểm đích \(z = x^{(k-1)} + v\) thay vì hướng \(v\), công thức cập nhật trở thành:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
z^{(k)} &amp;amp; = \underset{z}{\text{argmin}} \ \nabla g(x^{(k-1)})^T (z - x^{(k-1)}) + \frac{1}{2} (z - x^{(k-1)})^T H^{(k-1)} (z - x^{(k-1)}) + h(z) \\\\
x^{(k)} &amp;amp; =x^{(k-1)} + t_k (z^{(k)} - x^{(k-1)} )
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Về mặt trực giác, ở bước đầu ta tìm điểm trung gian \(z^{(k)}\) cực tiểu hóa mô hình bậc hai của \(g\) cộng với \(h\), sau đó di chuyển từ \(x^{(k-1)}\) về phía \(z^{(k)}\) theo tỷ lệ \(t_k \in (0, 1]\) (không nhất thiết đi trọn bước tới \(z^{(k)}\)).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>19-01-01 Nhắc lại: proximal gradient descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_01_01_Reminder-_proximal_gradient_descent/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_01_01_Reminder:_proximal_gradient_descent</id>
   <content type="html">&lt;p&gt;Trước khi leo lên bậc thang của phương pháp bậc hai, ta cần đứng thật vững trên bậc thang bậc nhất. Proximal gradient descent (PGD) không chỉ là một công thức mẹo vặt ghép bước gradient với toán tử \(\operatorname{prox}_t\) — đằng sau nó là một diễn giải hình học tuyệt đẹp: ở mỗi bước, ta thay thế hàm trơn \(g\) bằng xấp xỉ bậc hai cầu (isotropic quadratic approximation) có độ cong \(\frac{1}{t}I\), giữ nguyên hàm không trơn \(h\), rồi tìm cực tiểu chính xác của mô hình đó. Chính diễn giải “xấp xỉ bậc hai cộng \(h\)” này là cầu nối tự nhiên nhất sang Newton proximal.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-proximal-gradient-descent&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của Proximal Gradient Descent&lt;/h2&gt;

&lt;p&gt;Ôn lại nhanh ba khái niệm cốt lõi từ Chương 9 dưới góc nhìn mở đường cho Chương 19:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Toán tử proximal \(\operatorname{prox}_t(x)\):&lt;/strong&gt; Định nghĩa là \(\arg\min_z \left(\frac{1}{2t}\|x - z\|_2^2 + h(z)\right)\), dung hòa giữa việc giữ \(z\) gần điểm tham chiếu \(x\) và việc làm nhỏ hàm không trơn \(h(z)\). Với \(h(z) = \lambda\|z\|_1\), nó là phép ngưỡng mềm (soft-thresholding); với \(h(z) = I_C(z)\), nó là phép chiếu Euclid lên tập lồi \(C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải cực tiểu hóa mô hình thay thế (Majorization–Minimization):&lt;/strong&gt; Nếu \(\nabla g\) liên tục Lipschitz với hằng số \(L\) và chọn \(t \le 1/L\), mô hình \(g(x) + \nabla g(x)^T(y-x) + \frac{1}{2t}\|y-x\|_2^2 + h(y)\) luôn nằm phía trên hàm thực \(g(y) + h(y)\), nên mỗi bước PGD chắc chắn làm giảm giá trị hàm mục tiêu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giới hạn của độ cong đẳng hướng \(\frac{1}{t}I\):&lt;/strong&gt; Dùng chung một vô hướng \(1/t\) cho mọi chiều buộc thuật toán phải thu nhỏ bước đi theo chiều cong gắt nhất (\(L\)), gây chậm trễ nghiêm trọng trên các chiều thoải hơn — tạo ra khoảng trống để Newton proximal thay \(\frac{1}{t}I\) bằng \(\nabla^2 g(x)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-bước-pgd-với-ngưỡng-mềm-soft-thresholding&quot;&gt;Giải thích: Tính tay bước PGD với ngưỡng mềm (Soft-Thresholding)&lt;/h3&gt;

&lt;p&gt;Xét bài toán Lasso 1 chiều:&lt;/p&gt;

\[\min_{x \in \mathbb{R}} \; f(x) = \underbrace{\frac{1}{2}(x - 3)^2}_{g(x)} + \underbrace{1.5 |x|}_{h(x)}.\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Ta có \(\nabla g(x) = x - 3\) (hằng số Lipschitz \(L = 1\)). Nghiệm tối ưu chính xác thỏa mãn $$0 \in (x^\star - 3) + 1.5\,\partial&lt;/td&gt;
      &lt;td&gt;x^\star&lt;/td&gt;
      &lt;td&gt;\implies x^\star = 1.5\(. Hãy chạy tay PGD từ\)x^{(0)} = 0$$ với hai lựa chọn bước học:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Với bước học \(t = 0.5\) (nhỏ hơn \(1/L = 1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient tại \(x^{(0)} = 0\) là \(\nabla g(0) = -3\).&lt;/li&gt;
      &lt;li&gt;Bước gradient trơn: \(u = x^{(0)} - t\nabla g(0) = 0 - 0.5(-3) = 1.5\).&lt;/li&gt;
      &lt;li&gt;Áp dụng toán tử proximal với ngưỡng \(\lambda t = 1.5 \times 0.5 = 0.75\):
\(x^{(1)} = S_{0.75}(1.5) = \operatorname{sign}(1.5)\max(|1.5| - 0.75, \; 0) = 0.75.\)&lt;/li&gt;
      &lt;li&gt;Kiểm tra giá trị hàm: \(f(0) = 4.5\) giảm mạnh xuống \(f(0.75) = \frac{1}{2}(-2.25)^2 + 1.5(0.75) = 2.53125 + 1.125 = 3.65625\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Với bước học tối ưu \(t = 1/L = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bước gradient trơn: \(u = 0 - 1(-3) = 3\).&lt;/li&gt;
      &lt;li&gt;Ngưỡng mềm với \(\lambda t = 1.5\): \(x^{(1)} = S_{1.5}(3) = 3 - 1.5 = 1.5 = x^\star\)!
Lưu ý: khi \(g(x)\) là hàm bậc hai 1 chiều, chọn \(t = 1/g&apos;&apos;(x)\) khiến mô hình bậc hai của PGD trùng khớp hoàn toàn với Newton proximal!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trước khi đi vào &lt;strong&gt;phương pháp Newton proximal (proximal Newton method)&lt;/strong&gt;, hãy ôn lại ngắn gọn &lt;strong&gt;proximal gradient descent&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Xem chi tiết tại &lt;a href=&quot;/contents/vi/chapter09/09_proximal_gradient_descent_and_acceleration/&quot;&gt;09 Proximal Gradient Descent and Acceleration&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;proximal-gradient-descent&quot;&gt;Proximal gradient descent&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Proximal gradient descent&lt;/strong&gt; áp dụng cho bài toán tối ưu hàm tổng hợp có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[f(x) = g(x) + h(x)\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;\(g\) lồi và khả vi với \(\operatorname{dom}(g) = \mathbb{R}^n\).&lt;/li&gt;
  &lt;li&gt;\(h\) lồi, có thể không khả vi nhưng có cấu trúc “đơn giản”.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;thuật-toán&quot;&gt;Thuật toán&lt;/h4&gt;
&lt;p&gt;Bắt đầu từ điểm khởi tạo \(x^{(0)}\), thuật toán lặp lại phép cập nhật:&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = \text{prox}_{t_k}(x^{(k-1)} - t_k \nabla g(x^{(k-1)}) ),\quad k=1,2,3,\dots\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\text{prox}_{t}(\cdot)\) là toán tử proximal ứng với hàm \(h\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\text{prox}_{t}(x) = \underset{z}{\text{argmin}} \ \frac{1}{2t} \parallel x - z \parallel_2^2 + h(z)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Phép cập nhật này cũng có thể được viết lại dưới dạng tương tự gradient descent nhờ ánh xạ gradient tổng quát \(G_{t}\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{(k)} = x^{(k-1)} - t_k \cdot G_{t_k}(x^{(k-1)}), \space \space \text{với} \space G_{t}(x) = \frac{x-\text{prox}_{t} (x - t \nabla g(x))}{t} \&lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;hiệu-năng&quot;&gt;Hiệu năng&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Hiệu năng của &lt;strong&gt;proximal gradient descent&lt;/strong&gt; phụ thuộc trực tiếp vào \(h\). Nếu \(h\) phức tạp — đặc biệt khi toán tử prox không có nghiệm dạng đóng — thì mỗi vòng lặp sẽ tốn kém và thuật toán chạy chậm.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Thuật toán có cùng tốc độ hội tụ theo số vòng lặp với gradient descent trên \(g\), nhưng chỉ thực sự hiệu quả khi toán tử prox được tính nhanh ở mỗi bước.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;động-lực&quot;&gt;Động lực&lt;/h2&gt;
&lt;p&gt;Trong &lt;strong&gt;proximal gradient descent&lt;/strong&gt;, ở mỗi bước ta xấp xỉ hàm khả vi \(g\) bằng mô hình bậc hai cục bộ, giữ nguyên phần không khả vi \(h\) và cực tiểu hóa tổng hai thành phần đó (xem chi tiết tại &lt;a href=&quot;/contents/vi/chapter09/09_01_proximal_gradient_descent/&quot;&gt;09-01 Proximal gradient descent&lt;/a&gt;):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^+ &amp;amp; = \underset{z}{\text{argmin}}  \, \frac{1}{2t} \parallel x - t \nabla g(x) - z \parallel_2 ^2 + h(z) \\\\
&amp;amp; = \underset{z}{\text{argmin}} \ \nabla g(x)^T (z - x) + \frac{1}{2t} \parallel z - x \parallel_2 ^2 + h(z) \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Hai số hạng đầu tiên của biểu thức thứ hai xuất phát từ khai triển Taylor bậc hai của \(g\) (bỏ hằng số \(g(x)\)), trong đó ma trận Hessian \(\nabla^2 g(x)\) được thay đơn giản bằng \(\frac{1}{t} I\) (độ cong đẳng hướng — spherical curvature).&lt;/p&gt;

&lt;p&gt;Hình dưới đây minh họa cách xấp xỉ bậc hai được dùng để cập nhật nghiệm trong proximal gradient descent.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter19/09.01_01_proximal_gradient_descent.png&quot; alt=&quot;[Hình 1] Các bước cập nhật của proximal gradient descent [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Các bước cập nhật của proximal gradient descent [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Điểm khác biệt cốt lõi giữa gradient descent và phương pháp Newton là việc sử dụng Hessian cục bộ \(\nabla^2 g(x)\) trong mô hình bậc hai. Nếu thay \(\frac{1}{t} I\) bằng đúng ma trận Hessian \(\nabla^2 g(x)\) trong bài toán con ở trên, ta thu được &lt;strong&gt;phương pháp Newton proximal&lt;/strong&gt;, sẽ được trình bày ở phần tiếp theo.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>19-01 Phương pháp Newton proximal</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_01_00_Proximal_Newton_method/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_01_00_Proximal_Newton_method</id>
   <content type="html">&lt;p&gt;Nếu ví proximal gradient descent như việc đặt một cái bát hình tròn đều \(\frac{1}{2t}\|y - x\|_2^2\) lên bề mặt hàm trơn \(g\) để tìm đáy cục bộ, thì khi thung lũng của \(g\) bị kéo dãn thành một khe hẹp hình elip, chiếc bát tròn buộc phải co thật nhỏ mới nằm gọn được bên trong — khiến bước đi trở nên li ti. Phương pháp Newton proximal thay chiếc bát tròn ấy bằng một &lt;strong&gt;chiếc bát elip&lt;/strong&gt; khớp đúng với độ cong thực \(\nabla^2 g(x)\) theo mọi phương, đồng thời giữ nguyên cấu trúc không trơn của \(h\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-viên-gạch-mở-đường-cho-newton-proximal&quot;&gt;Kiến thức cần nhớ: Ba viên gạch mở đường cho Newton proximal&lt;/h2&gt;

&lt;p&gt;Phần 19-01 dẫn dắt người học qua ba bước nâng cấp liên tiếp cực kỳ mạch lạc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ôn tập Proximal Gradient (19-01-01):&lt;/strong&gt; Nhận diện bài toán tổng hợp \(f = g + h\) dưới góc nhìn cực tiểu hóa mô hình bậc hai đẳng hướng \(\hat{g}_t(y) + h(y)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thay độ cong vô hướng bằng Hessian thực (19-01-02):&lt;/strong&gt; Đổi \(\frac{1}{t}I\) thành \(H = \nabla^2 g(x)\) để định nghĩa hướng Newton proximal \(v^{(k)}\) thông qua một bài toán con lồi bậc hai có điều chuẩn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn hóa bằng ánh xạ proximal có tỉ lệ (19-01-03):&lt;/strong&gt; Đóng gói toàn bộ phép cập nhật vào toán tử \(\operatorname{prox}_H(x - H^{-1}\nabla g(x))\) và kiểm chứng hai tính chất nền tảng: tính duy nhất của nghiệm và tính không giãn trong chuẩn \(H\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-hình-tròn-vs-elip-trong-bài-toán-con-2-chiều&quot;&gt;Giải thích: Hình tròn vs. Elip trong bài toán con 2 chiều&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét hàm tổng hợp 2 chiều \(g(x_1, x_2) = \frac{1}{2}(x_1^2 + 10x_2^2) - x_1 - 10x_2\) và $$h(x) =&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\(. Độ cong dọc trục\)x_2\(lớn gấp 10 lần trục\)x_1\((\)H = \operatorname{diag}(1, 10)\(, số điều kiện\)\kappa = 10\(). Tại điểm\)x = (2, 2)^T\(, ta có\)\nabla g(x) = (1, 10)^T$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Với Proximal Gradient:&lt;/strong&gt; Để hội tụ ổn định, bước học phải thỏa mãn \(t \le \frac{1}{L} = \frac{1}{10} = 0.1\).
    &lt;ul&gt;
      &lt;li&gt;Theo trục \(x_2\): \(x_2^+ = S_{0.1}(2 - 0.1 \times 10) = S_{0.1}(1) = 0.9\) (tiến sát nghiệm tối ưu \(x_2^\star = 0.9\) ngay!).&lt;/li&gt;
      &lt;li&gt;Nhưng theo trục \(x_1\): \(x_1^+ = S_{0.1}(2 - 0.1 \times 1) = S_{0.1}(1.9) = 1.8\) (còn cách rất xa nghiệm tối ưu \(x_1^\star = 0\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Với Proximal Newton:&lt;/strong&gt; Ma trận \(H = \operatorname{diag}(1, 10)\) tự động cấp bước \(1/1 = 1\) cho trục \(x_1\) và bước \(1/10 = 0.1\) cho trục \(x_2\):
    &lt;ul&gt;
      &lt;li&gt;\(x_1^+ = S_1(2 - 1 \times 1) = S_1(1) = 0 = x_1^\star\).&lt;/li&gt;
      &lt;li&gt;\(x_2^+ = S_{0.1}(2 - 0.1 \times 10) = S_{0.1}(1) = 0.9 = x_2^\star\).
Cả hai tọa độ đều chạm đích chính xác ngay ở vòng lặp đầu tiên!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong phần này, chúng ta ôn lại &lt;strong&gt;phương pháp hạ gradient lân cận (proximal gradient descent)&lt;/strong&gt; và xem &lt;strong&gt;phương pháp Newton proximal&lt;/strong&gt; được mở rộng tự nhiên từ đó như thế nào.&lt;/p&gt;

&lt;p&gt;Chúng ta cũng tìm hiểu định nghĩa của &lt;strong&gt;phương pháp Newton proximal&lt;/strong&gt; và &lt;strong&gt;ánh xạ proximal có tỉ lệ (scaled proximal map)&lt;/strong&gt; — toán tử kế thừa những tính chất quan trọng như tính duy nhất và tính không giãn (non-expansiveness) của ánh xạ proximal thông thường.&lt;/p&gt;

&lt;h3 id=&quot;newton-gần-kề-so-với-gradient-gần-kề-video&quot;&gt;Newton gần kề so với gradient gần kề (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/prox-newton_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Gradient gần kề chỉ dùng kích thước bước vô hướng; Newton gần kề cực tiểu hóa mô hình bậc hai sử dụng ma trận Hessian thực cộng thêm \(\lambda\|x\|_1\), nhờ đó cần ít bước lặp hơn đáng kể.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-gradient-gần-kề-so-với-newton-gần-kề&quot;&gt;Tự tay thử: gradient gần kề so với Newton gần kề&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;pn&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>19 Phương pháp Proximal Newton</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_00_Proximal_Newton_Method/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter19/19_00_Proximal_Newton_Method</id>
   <content type="html">&lt;p&gt;Trong học máy hiện đại, hiếm khi nào hàm mục tiêu hoàn toàn trơn tru: một bài toán hồi quy logistic có phạt Lasso \(\ell_1\), hay ước lượng ma trận hiệp phương sai thưa (graphical lasso), luôn là phép cộng của hai thế giới đối lập — một hàm mất mát trơn \(g(x)\) và một hàm điều chuẩn sắc cạnh, không khả vi \(h(x)\). Phương pháp hạ gradient proximal (Chương 9) xử lý được \(h(x)\) nhưng lại chỉ dùng một hằng số bước vô hướng, nên ì ạch khi \(g(x)\) cong lệch theo các trục khác nhau. Chương 19 mang sức mạnh độ cong bậc hai của phương pháp Newton ghép trực tiếp vào khung proximal: ta xấp xỉ bậc hai phần trơn \(g(x)\) bằng đúng ma trận Hessian \(\nabla^2 g(x)\), nhưng giữ nguyên vẹn phần không trơn \(h(x)\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-kiến-thức-hội-tụ-trong-chương-19&quot;&gt;Kiến thức cần nhớ: Bốn nhánh kiến thức hội tụ trong Chương 19&lt;/h2&gt;

&lt;p&gt;Trước khi đi sâu vào các bài học của chương này, hãy xem bốn mảng kiến thức kết nối với nhau ra sao:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa hàm tổng hợp (Composite Optimization):&lt;/strong&gt; Tách hàm mục tiêu \(f(x) = g(x) + h(x)\) thành phần trơn \(g\) (khả vi hai lần) và phần không trơn \(h\) (lồi, có cấu trúc đặc biệt như \(\lambda\|x\|_1\) hay hàm chỉ thị \(I_C(x)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ánh xạ proximal có tỉ lệ (Scaled Proximal Map):&lt;/strong&gt; Tổng quát hóa khoảng cách Euclid \(\frac{1}{2t}\|z - x\|_2^2\) thành chuẩn cảm sinh bởi ma trận Hessian \(\frac{1}{2}\|z - x\|_H^2\), giúp bước đi uốn lượn đúng theo hình dạng elip độ cong cục bộ của \(g\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán hai tầng (Outer Newton + Inner Solver):&lt;/strong&gt; Khác với proximal gradient vốn có công thức đóng, bài toán con bậc hai có phạt \(h\) thường không có nghiệm đóng và phải giải bằng một bộ giải bên trong cực nhanh (như hạ tọa độ trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt;).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến thể Quasi-Newton và Newton chiếu:&lt;/strong&gt; Khi Hessian quá đắt, ta thay bằng xấp xỉ BFGS hoặc xấp xỉ theo khối (Proximal Quasi-Newton); khi \(h = I_C\) là hàm chỉ thị ràng buộc, ta cần cẩn trọng để có phiên bản &lt;strong&gt;Projected Newton&lt;/strong&gt; thực sự giảm hàm mục tiêu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-1-bước-proximal-gradient-và-1-bước-proximal-newton-trên-cùng-bài-toán&quot;&gt;Giải thích: So sánh 1 bước Proximal Gradient và 1 bước Proximal Newton trên cùng bài toán&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét bài toán hàm tổng hợp 1 chiều \(f(x) = g(x) + h(x)\) với \(g(x) = 2x^2\) (độ cong không đổi \(g&apos;&apos;(x) = 4\)) và $$h(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(, có nghiệm tối ưu chính xác là\)x^\star = 0\(. Bắt đầu từ\)x^{(0)} = 1\((\)g’(1) = 4$$):&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Một bước Proximal Gradient với bước học bảo thủ \(t = 0.1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bước gradient trơn: \(z = x^{(0)} - t g&apos;(x^{(0)}) = 1 - 0.1(4) = 0.6\).&lt;/li&gt;
      &lt;li&gt;Ngưỡng mềm (soft-thresholding) với ngưỡng \(t = 0.1\): \(x^{(1)}_{\text{PGD}} = S_{0.1}(0.6) = 0.6 - 0.1 = 0.5\).
(Nghiệm mới chỉ đi được nửa đường về \(0\).)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Một bước Proximal Newton với độ cong chính xác \(H = g&apos;&apos;(1) = 4\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Giải bài toán con: $$v^{(1)} = \arg\min_v \left(4v + \frac{1}{2}(4)v^2 +&lt;/td&gt;
              &lt;td&gt;1 + v&lt;/td&gt;
              &lt;td&gt;\right)$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Đặt \(y = 1 + v\), bài toán viết lại thành $$\arg\min_y \left(2y^2 +&lt;/td&gt;
              &lt;td&gt;y&lt;/td&gt;
              &lt;td&gt;\right) = \operatorname{prox}_{&lt;/td&gt;
              &lt;td&gt;\cdot&lt;/td&gt;
              &lt;td&gt;/4}(0) = S_{0.25}(0) = 0$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Suy ra \(v^{(1)} = -1\) và \(x^{(1)}_{\text{PN}} = 1 + (-1) = 0 = x^\star\) — &lt;strong&gt;chạm trúng nghiệm tối ưu chính xác chỉ sau 1 bước duy nhất!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong chương này, chúng ta tìm hiểu &lt;strong&gt;phương pháp Proximal Newton&lt;/strong&gt;, &lt;strong&gt;phương pháp Proximal Quasi-Newton&lt;/strong&gt; và &lt;strong&gt;phương pháp Projected Newton&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h3&gt;

&lt;p&gt;Phương pháp Proximal Newton:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;J. Friedman and T. Hastie and R. Tibshirani (2009), “Regularization paths for generalized linear models via coordinate descent”&lt;/li&gt;
  &lt;li&gt;C.J. Hsieh and M.A. Sustik and I. Dhillon and P. Ravikumar (2011), “Sparse inverse covariance matrix estimation using quadratic approximation”&lt;/li&gt;
  &lt;li&gt;M. Patriksson (1998), “Cost approximation: a unified framework of descent algorithms for nonlinear programs”&lt;/li&gt;
  &lt;li&gt;J. Lee and Y. Sun and M. Saunders (2014), “Proximal Newton-type methods for minimizing composite functions”&lt;/li&gt;
  &lt;li&gt;P. Tseng and S. Yun (2009), “A coordinate gradient descent method for nonsmooth separable minimization”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Phương pháp Projected Newton:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A. Barbero and S. Sra (2011), “Fast Newton-type methods for total variation regularization”&lt;/li&gt;
  &lt;li&gt;D. Bertsekas (1982), “Projected Newton methods for optimization problems with simple constraints”&lt;/li&gt;
  &lt;li&gt;D. Kim and S. Sra. and I. Dhillon (2010), “Tackling box-constrained optimization via a new projected quasi-Newton approach”&lt;/li&gt;
  &lt;li&gt;M. Schmidt and D. Kim and S. Sra (2011), “Projected Newton-type methods in machine learning”&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>11-10 Bài Tập Thực Hành - Tính Đối Ngẫu Tổng Quát</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_10_Practical_Exercises_General_Duality/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_10_Practical_Exercises_General_Duality</id>
   <content type="html">&lt;p&gt;Nếu muốn thực sự làm chủ đối ngẫu Lagrange — để gặp bất kỳ bài toán quy hoạch bậc hai, bài toán có hàm logarit, hay bài toán ràng buộc chuẩn nào cũng tự tin viết ra ngay hàm đối ngẫu và kiểm tra điều kiện Slater — không có con đường nào hiệu quả hơn là tự tay giải các bài tập kinh điển từ Boyd &amp;amp; Vandenberghe, Rockafellar và Bertsekas trong bài thực hành này!&lt;/p&gt;

&lt;p&gt;Điểm thú vị nhất trong quá trình tự giải bài tập đối ngẫu là xử lý những &lt;strong&gt;trường hợp biên (edge cases)&lt;/strong&gt; khi tính \(\inf_x L(x, u, v)\): một biến mất bậc hai khiến biểu thức trở thành tuyến tính, hay miền xác định của \(\log(x)\) đòi hỏi \(x &amp;gt; 0\). Khung tính tay dưới đây chạy thử đúng tình huống kinh điển đó trên quy hoạch bậc hai 1 biến (gần với Bài tập 4) để bạn làm nóng tay trước khi vào bài!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-bước-chuẩn-mực-để-giải-mọi-bài-tập-đối-ngẫu-lagrange&quot;&gt;Kiến thức cần nhớ: Bốn bước chuẩn mực để giải mọi bài tập đối ngẫu Lagrange&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Đưa về dạng chuẩn và xác định miền \(\mathcal{D}\):&lt;/strong&gt; Viết mọi bất đẳng thức về dạng \(h_i(x) \le 0\), đẳng thức về \(l_j(x) = 0\), và ghi rõ miền xác định ẩn (ví dụ \(x &amp;gt; 0\) cho \(\log x\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Lập \(L(x, u, v)\) và tìm \(\inf_x L(x, u, v)\) cẩn thận theo từng miền tham số:&lt;/strong&gt; Giải \(\nabla_x L = 0\) khi \(L\) lồi và bức (coercive); luôn kiểm tra các giá trị \((u, v)\) làm cho \(\inf_x L = -\infty\) để ghi rõ ràng buộc miền hữu dụng của bài toán đối ngẫu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kiểm tra tính lồi và điều kiện Slater:&lt;/strong&gt; Xác nhận \(f, h_i\) lồi và \(l_j\) affine, sau đó chỉ ra tường minh một điểm \(\tilde{x}\) thỏa \(h_i(\tilde{x}) &amp;lt; 0\) (với \(h_i\) phi tuyến) và \(l_j(\tilde{x}) = 0\) để chốt đối ngẫu mạnh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — Khôi phục nghiệm gốc \(x^*\) từ nghiệm đối ngẫu \((u^*, v^*)\):&lt;/strong&gt; Khi \(L(x, u^*, v^*)\) có cực tiểu duy nhất theo \(x\) (chẳng hạn lồi chặt), điểm \(x^* = \arg\min_x L(x, u^*, v^*)\) chính là nghiệm tối ưu gốc!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-trọn-vẹn-qp-1-biến-với-hai-trường-hợp-q--0-và-q--0&quot;&gt;Giải thích: Giải tay trọn vẹn QP 1 biến với hai trường hợp \(q &amp;gt; 0\) và \(q = 0\)&lt;/h3&gt;

&lt;p&gt;Xét bài toán \(\min_{x \in \mathbb{R}} \frac{1}{2}q x^2 + c x\) với ràng buộc \(-x \le 0\) (tức \(x \ge 0\)), trong đó \(q \ge 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập hàm Lagrangian (nhân tử \(u \ge 0\)):&lt;/strong&gt;
\(L(x, u) = \frac{1}{2}q x^2 + (c - u)x.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp \(q &amp;gt; 0\) (parabol lồi chặt):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đạo hàm theo \(x\) bằng \(0\): \(qx + (c - u) = 0 \implies x(u) = -\frac{c - u}{q} = \frac{u - c}{q}\).&lt;/li&gt;
      &lt;li&gt;Hàm đối ngẫu: \(g(u) = -\frac{(u - c)^2}{2q}\) (xác định với mọi \(u \ge 0\)).&lt;/li&gt;
      &lt;li&gt;Cực đại hóa \(g(u)\) trên \(u \ge 0\):
        &lt;ul&gt;
          &lt;li&gt;Nếu \(c \ge 0\): đỉnh parabol tại \(u^* = c \ge 0\), cho \(g^* = 0\) và \(x^* = (c - c)/q = 0\).&lt;/li&gt;
          &lt;li&gt;Nếu \(c &amp;lt; 0\): cực đại trên \(u \ge 0\) đạt tại biên \(u^* = 0\), cho \(g^* = -\frac{c^2}{2q}\) và \(x^* = -c/q &amp;gt; 0\)!&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp suy biến \(q = 0\) (quay về LP!):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(L(x, u) = (c - u)x\).&lt;/li&gt;
      &lt;li&gt;Infimum theo \(x \in \mathbb{R}\) chỉ hữu hạn khi \(c - u = 0 \implies u = c\)!&lt;/li&gt;
      &lt;li&gt;Vì ta đòi \(u \ge 0\), bài toán đối ngẫu chỉ khả thi khi \(c \ge 0\) (cho \(g^* = 0\)), còn khi \(c &amp;lt; 0\) thì đối ngẫu vô nghiệm (khớp hoàn toàn với việc bài toán gốc \(\min_{x \ge 0} cx = -\infty\) không bị chặn dưới!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---tính-đối-ngẫu-tổng-quát&quot;&gt;Bài Tập Thực Hành - Tính Đối Ngẫu Tổng Quát&lt;/h1&gt;

&lt;p&gt;Các bài tập dưới đây được tham khảo từ Boyd &amp;amp; Vandenberghe (2004), Rockafellar (1970) và Bertsekas (1999).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-i-hàm-lagrangian-và-hàm-đối-ngẫu&quot;&gt;Phần I: Hàm Lagrangian và hàm đối ngẫu&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-xây-dựng-hàm-lagrangian-boyd--vandenberghe-ex-51&quot;&gt;Bài tập 1: Xây dựng hàm Lagrangian (Boyd &amp;amp; Vandenberghe, Ex. 5.1)&lt;/h3&gt;

&lt;p&gt;Cho bài toán tối ưu tổng quát:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; f_0(x) \\
\text{s.t.} \quad &amp;amp; f_i(x) \leq 0, \quad i = 1, \ldots, m \\
&amp;amp; h_j(x) = 0, \quad j = 1, \ldots, p
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Viết hàm Lagrangian \(L(x, \lambda, \nu)\).
b) Định nghĩa hàm đối ngẫu \(g(\lambda, \nu)\).
c) Cho \(f_0(x) = x_1^2 + x_2^2\), \(f_1(x) = x_1 + x_2 - 1\), \(h_1(x) = x_1 - x_2\). Tính \(L\) và \(g\).&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Hàm Lagrangian:&lt;/strong&gt;&lt;/p&gt;

\[L(x, \lambda, \nu) = f_0(x) + \sum_{i=1}^m \lambda_i f_i(x) + \sum_{j=1}^p \nu_j h_j(x)\]

  &lt;p&gt;với:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\lambda \in \mathbb{R}^m, \lambda \geq 0\): vector biến đối ngẫu cho các ràng buộc bất đẳng thức.&lt;/li&gt;
    &lt;li&gt;\(\nu \in \mathbb{R}^p\): vector biến đối ngẫu cho các ràng buộc đẳng thức (không ràng buộc dấu).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Hàm đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[g(\lambda, \nu) = \inf_x L(x, \lambda, \nu) = \inf_x \left( f_0(x) + \sum_i \lambda_i f_i(x) + \sum_j \nu_j h_j(x) \right)\]

  &lt;p&gt;&lt;strong&gt;Tính chất:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(g(\lambda, \nu)\) luôn là hàm &lt;strong&gt;lõm&lt;/strong&gt; theo \((\lambda, \nu)\).&lt;/li&gt;
    &lt;li&gt;\(g(\lambda, \nu) \leq p^*\) với mọi \(\lambda \geq 0\) (tính đối ngẫu yếu).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Tính cụ thể:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Với \(f_0(x) = x_1^2 + x_2^2\), \(f_1(x) = x_1 + x_2 - 1\) và \(h_1(x) = x_1 - x_2\):&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Hàm Lagrangian:&lt;/strong&gt;&lt;/p&gt;

\[L(x, \lambda, \nu) = x_1^2 + x_2^2 + \lambda(x_1 + x_2 - 1) + \nu(x_1 - x_2)\]

  &lt;p&gt;&lt;strong&gt;Tìm \(\inf_x L\):&lt;/strong&gt; Điều kiện đạo hàm bậc nhất (FOC):&lt;/p&gt;

\[\frac{\partial L}{\partial x_1} = 2x_1 + \lambda + \nu = 0 \Rightarrow x_1 = -\frac{\lambda + \nu}{2}\]

\[\frac{\partial L}{\partial x_2} = 2x_2 + \lambda - \nu = 0 \Rightarrow x_2 = -\frac{\lambda - \nu}{2}\]

  &lt;p&gt;Thế vào \(L\), ta thu được:&lt;/p&gt;

\[g(\lambda, \nu) = -\frac{\lambda^2 + \nu^2}{2} - \lambda\]

  &lt;p&gt;với \(\lambda \geq 0\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-2-đối-ngẫu-yếu-và-mạnh-boyd--vandenberghe-ex-52&quot;&gt;Bài tập 2: Đối ngẫu yếu và mạnh (Boyd &amp;amp; Vandenberghe, Ex. 5.2)&lt;/h3&gt;

&lt;p&gt;Xét bài toán gốc và hàm đối ngẫu từ Bài tập 1c.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Giải bài toán gốc.
b) Giải bài toán đối ngẫu \(\max_{\lambda \geq 0, \nu} g(\lambda, \nu)\).
c) Kiểm tra tính đối ngẫu mạnh.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Giải bài toán gốc:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x_1^2 + x_2^2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 \leq 1 \\
&amp;amp; x_1 - x_2 = 0
\end{align}\]

  &lt;p&gt;Từ \(x_1 = x_2\) và \(x_1 + x_2 \leq 1\) suy ra \(x_1 \leq 0.5\). Hàm mục tiêu trở thành \(2x_1^2\), đạt cực tiểu tại \(x_1 = 0\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm bài toán gốc:&lt;/strong&gt; \(x^* = (0, 0)\), \(p^* = 0\).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Giải bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\max_{\lambda \geq 0, \nu} \quad -\frac{\lambda^2 + \nu^2}{2} - \lambda\]

  &lt;p&gt;Điều kiện đạo hàm bậc nhất:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\frac{\partial g}{\partial \lambda} = -\lambda - 1 = 0 \Rightarrow \lambda = -1\). Vì ràng buộc \(\lambda \geq 0\) và \(g\) giảm trên \([0, +\infty)\), nên \(\lambda^* = 0\).&lt;/li&gt;
    &lt;li&gt;\(\frac{\partial g}{\partial \nu} = -\nu = 0 \Rightarrow \nu^* = 0\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm bài toán đối ngẫu:&lt;/strong&gt; \(\lambda^* = 0\), \(\nu^* = 0\), \(d^* = 0\).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Kiểm tra đối ngẫu mạnh:&lt;/strong&gt;&lt;/p&gt;

\[p^* = 0 = d^*\]

  &lt;p&gt;Tính đối ngẫu mạnh được thỏa mãn ✓ (bài toán lồi và thỏa mãn điều kiện Slater).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-ii-điều-kiện-slater-và-tính-đối-ngẫu-mạnh&quot;&gt;Phần II: Điều kiện Slater và tính đối ngẫu mạnh&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-3-kiểm-tra-điều-kiện-slater-rockafellar-ex-283&quot;&gt;Bài tập 3: Kiểm tra điều kiện Slater (Rockafellar, Ex. 28.3)&lt;/h3&gt;

&lt;p&gt;Kiểm tra điều kiện Slater cho các bài toán sau:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; \(\min x^2\) s.t. \(x^2 \leq 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;b)&lt;/strong&gt; \(\min x^2\) s.t. \(x^2 \leq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;c)&lt;/strong&gt; \(\min \frac{1}{2}x^T Q x\) s.t. \(Ax \leq b\) với \(Q \succ 0\)&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Điều kiện Slater:&lt;/strong&gt; Tồn tại điểm khả thi chặt \(\tilde{x}\) sao cho:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(f_i(\tilde{x}) &amp;lt; 0\) với mọi ràng buộc bất đẳng thức phi tuyến \(i\) (ràng buộc bất đẳng thức affine chỉ cần \(\leq 0\)),&lt;/li&gt;
    &lt;li&gt;\(h_j(\tilde{x}) = 0\) với mọi ràng buộc đẳng thức \(j\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;a) \(\min x^2\) s.t. \(x^2 \leq 1\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Điều kiện khả thi chặt là \(\tilde{x}^2 &amp;lt; 1\); chọn \(\tilde{x} = 0\) thỏa mãn ✓.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Điều kiện Slater thỏa mãn&lt;/strong&gt;, nên tính đối ngẫu mạnh đúng.&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) \(\min x^2\) s.t. \(x^2 \leq 0\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Bất đẳng thức \(\tilde{x}^2 &amp;lt; 0\) vô nghiệm, nên &lt;strong&gt;điều kiện Slater không thỏa mãn&lt;/strong&gt;.&lt;/p&gt;

  &lt;p&gt;Miền khả thi chỉ gồm một điểm duy nhất \(x = 0\). Tuy nhiên, trong ví dụ cụ thể này tính đối ngẫu mạnh vẫn đúng (\(p^* = d^* = 0\)), minh họa rằng điều kiện Slater chỉ là điều kiện đủ.&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) QP với \(Q \succ 0\), \(Ax \leq b\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Dạng nguyên bản của điều kiện Slater đòi hỏi tồn tại \(\tilde{x}\) thỏa \(A\tilde{x} &amp;lt; b\) (tức \(\{x : Ax &amp;lt; b\} \neq \emptyset\)). Tuy nhiên, vì các ràng buộc \(Ax \leq b\) đều là hàm &lt;strong&gt;affine&lt;/strong&gt;, theo dạng mở rộng (refined Slater’s condition), chỉ cần miền khả thi \(\{x : Ax \leq b\}\) khác rỗng là đã đủ đảm bảo tính đối ngẫu mạnh.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-iii-quy-hoạch-bậc-hai-quadratic-programming&quot;&gt;Phần III: Quy hoạch bậc hai (Quadratic Programming)&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-4-quy-hoạch-bậc-hai-một-biến&quot;&gt;Bài tập 4: Quy hoạch bậc hai một biến&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt;
\(\min_x \frac{1}{2}x^2 + x \quad \text{s.t.} \quad x \geq 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Viết lại bài toán ở dạng chuẩn.&lt;/li&gt;
  &lt;li&gt;Xây dựng hàm Lagrangian.&lt;/li&gt;
  &lt;li&gt;Tính hàm đối ngẫu \(g(u)\).&lt;/li&gt;
  &lt;li&gt;Giải bài toán đối ngẫu.&lt;/li&gt;
  &lt;li&gt;So sánh nghiệm gốc và nghiệm đối ngẫu.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Viết lại ở dạng chuẩn&lt;/strong&gt;
\(\min_x \frac{1}{2}x^2 + x \quad \text{s.t.} \quad -x + 1 \leq 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Hàm Lagrangian&lt;/strong&gt;
\(L(x,u) = \frac{1}{2}x^2 + x + u(-x + 1) = \frac{1}{2}x^2 + (1-u)x + u\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Hàm đối ngẫu&lt;/strong&gt;
\(g(u) = \inf_x L(x,u)\)&lt;/p&gt;

  &lt;p&gt;Lấy đạo hàm theo \(x\): \(\frac{\partial L}{\partial x} = x + (1 - u) = 0 \Rightarrow x^* = u - 1\).&lt;/p&gt;

  &lt;p&gt;Thay vào \(L\): \(g(u) = -\frac{1}{2}(u - 1)^2 + u\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 4: Giải bài toán đối ngẫu&lt;/strong&gt;
\(\max_u g(u) \quad \text{s.t.} \quad u \geq 0\)&lt;/p&gt;

  &lt;p&gt;Ta có \(g&apos;(u) = -(u - 1) + 1 = 2 - u = 0 \Rightarrow u^* = 2\) (thỏa \(u^* \geq 0\)).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 5: So sánh nghiệm&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Nghiệm đối ngẫu: \(u^* = 2\), \(g^* = \frac{3}{2}\).&lt;/li&gt;
    &lt;li&gt;Nghiệm gốc: \(x^* = 1\), \(f^* = \frac{3}{2}\).&lt;/li&gt;
    &lt;li&gt;Tính đối ngẫu mạnh thỏa mãn: \(f^* = g^*\) ✓.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-5-quy-hoạch-bậc-hai-nhiều-ràng-buộc&quot;&gt;Bài tập 5: Quy hoạch bậc hai nhiều ràng buộc&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt;
\(\min_{x,y} x^2 + y^2 \quad \text{s.t.} \quad x + y \geq 2, \quad x \geq 0, \quad y \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Xây dựng hàm Lagrangian đầy đủ.&lt;/li&gt;
  &lt;li&gt;Viết các điều kiện KKT.&lt;/li&gt;
  &lt;li&gt;Giải tìm nghiệm tối ưu gốc và đối ngẫu.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Hàm Lagrangian:&lt;/strong&gt;
\(L(x,y,u_1,u_2,u_3) = x^2 + y^2 + u_1(-x - y + 2) + u_2(-x) + u_3(-y)\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Điều kiện KKT:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Dừng (stationarity): \(\frac{\partial L}{\partial x} = 2x - u_1 - u_2 = 0\) và \(\frac{\partial L}{\partial y} = 2y - u_1 - u_3 = 0\).&lt;/li&gt;
    &lt;li&gt;Điều kiện bù: \(u_1(-x - y + 2) = 0\), \(u_2 x = 0\), \(u_3 y = 0\).&lt;/li&gt;
    &lt;li&gt;Khả thi gốc và đối ngẫu (\(u_1, u_2, u_3 \geq 0\)).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt; \(x^* = y^* = 1\), \((u_1^*, u_2^*, u_3^*) = (2, 0, 0)\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-iv-đối-ngẫu-của-support-vector-machine-svm&quot;&gt;Phần IV: Đối ngẫu của Support Vector Machine (SVM)&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-6-dạng-đối-ngẫu-của-svm-boyd--vandenberghe-ex-86&quot;&gt;Bài tập 6: Dạng đối ngẫu của SVM (Boyd &amp;amp; Vandenberghe, Ex. 8.6)&lt;/h3&gt;

&lt;p&gt;Cho bài toán SVM lề cứng:&lt;/p&gt;

\[\begin{align}
\min_{w, b} \quad &amp;amp; \frac{1}{2}\|w\|^2 \\
\text{s.t.} \quad &amp;amp; y_i(w^T x_i + b) \geq 1, \quad i = 1, \ldots, m
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Viết hàm Lagrangian.
b) Tính hàm đối ngẫu \(g(\alpha)\).
c) Viết bài toán đối ngẫu.
d) Với 3 điểm dữ liệu \((1, 1, +1)\), \((1, -1, +1)\) và \((-1, 0, -1)\), tìm nghiệm đối ngẫu tối ưu.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Hàm Lagrangian:&lt;/strong&gt;&lt;/p&gt;

\[L(w, b, \alpha) = \frac{1}{2}\|w\|^2 - \sum_{i=1}^m \alpha_i (y_i(w^T x_i + b) - 1)\]

  &lt;p&gt;&lt;strong&gt;b) Hàm đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Điều kiện dừng theo \(w\) và \(b\) cho: \(w = \sum_i \alpha_i y_i x_i\) và \(\sum_i \alpha_i y_i = 0\).&lt;/p&gt;

  &lt;p&gt;Thế vào \(L\), ta được:&lt;/p&gt;

\[g(\alpha) = \sum_i \alpha_i - \frac{1}{2}\sum_{i,j} \alpha_i \alpha_j y_i y_j x_i^T x_j\]

  &lt;p&gt;&lt;strong&gt;c) Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\boxed{
\begin{align}
\max_{\alpha} \quad &amp;amp; \sum_i \alpha_i - \frac{1}{2}\sum_{i,j} \alpha_i \alpha_j y_i y_j x_i^T x_j \\
\text{s.t.} \quad &amp;amp; \sum_i \alpha_i y_i = 0 \\
&amp;amp; \alpha_i \geq 0
\end{align}
}\]

  &lt;p&gt;&lt;strong&gt;d) Tính cụ thể:&lt;/strong&gt; Cả 3 điểm đều là vector hỗ trợ (support vector). Từ \(w = \sum_i \alpha_i y_i x_i\), \(\sum_i \alpha_i y_i = 0\) và \(y_i(w^T x_i + b) = 1\), ta giải được \(\alpha^* = (1/4,\ 1/4,\ 1/2)\), \(w^* = (1, 0)^T\), \(b^* = 0\), với giá trị đối ngẫu \(1 - \frac{1}{2}\|w^*\|^2 = \frac{1}{2}\). Biên quyết định là đường thẳng \(x_1 = 0\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-v-điều-kiện-bù-và-khoảng-cách-đối-ngẫu&quot;&gt;Phần V: Điều kiện bù và khoảng cách đối ngẫu&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-7-áp-dụng-điều-kiện-bù&quot;&gt;Bài tập 7: Áp dụng điều kiện bù&lt;/h3&gt;

&lt;p&gt;Cho bài toán LP:&lt;/p&gt;

\[\begin{align}
\min_x \quad &amp;amp; c^T x \\
\text{s.t.} \quad &amp;amp; Ax = b \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Viết điều kiện bù (complementary slackness).
b) Cho \(c = \begin{bmatrix} -1 \\ -2 \end{bmatrix}\), \(A = \begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix}\), \(b = 1\), tìm nghiệm tối ưu gốc và đối ngẫu.
c) Kiểm tra điều kiện bù.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Điều kiện bù:&lt;/strong&gt;&lt;/p&gt;

\[\lambda_i^* \cdot (-x_i^*) = 0\]

  &lt;p&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Nếu \(x_i^* &amp;gt; 0\) thì \(\lambda_i^* = 0\).&lt;/li&gt;
    &lt;li&gt;Nếu \(\lambda_i^* &amp;gt; 0\) thì \(x_i^* = 0\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Giải bài toán:&lt;/strong&gt;&lt;/p&gt;

\[\min \quad -x_1 - 2x_2 \quad \text{s.t.} \quad x_1 + x_2 = 1, \quad x \geq 0\]

  &lt;p&gt;Tương đương với cực đại hóa \(x_1 + 2x_2\) trên đoạn \(x_1 + x_2 = 1, x \geq 0\).&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Nghiệm gốc:&lt;/strong&gt; \(x^* = (0, 1)^T\), \(p^* = -2\).&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Nghiệm đối ngẫu:&lt;/strong&gt; \(\nu^* = -2\), \(\lambda^* = (1, 0)^T\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;c) Kiểm tra điều kiện bù:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\lambda_1^* \cdot 0 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;\(\lambda_2^* \cdot (-1) = 0\) ✓&lt;/li&gt;
  &lt;/ul&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-8-phân-tích-khoảng-cách-đối-ngẫu-bertsekas-ex-612&quot;&gt;Bài tập 8: Phân tích khoảng cách đối ngẫu (Bertsekas, Ex. 6.1.2)&lt;/h3&gt;

&lt;p&gt;Cho bài toán (lưu ý \(x(x-2) = x^2 - 2x\) là hàm lồi):&lt;/p&gt;

\[\min_{x \in [0,2]} \quad x(x-2)\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Giải bài toán gốc.
b) Viết hàm Lagrangian và tìm hàm đối ngẫu.
c) Giải bài toán đối ngẫu.
d) Tính khoảng cách đối ngẫu.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Giải bài toán gốc:&lt;/strong&gt;&lt;/p&gt;

\[f(x) = x^2 - 2x = (x-1)^2 - 1\]

  &lt;p&gt;Hàm đạt cực tiểu tại \(x = 1 \in [0, 2]\) với \(p^* = -1\).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Hàm Lagrangian:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Viết lại bài toán: \(\min_x x^2 - 2x\) s.t. \(-x \leq 0\), \(x - 2 \leq 0\).&lt;/p&gt;

\[L(x, \lambda_1, \lambda_2) = x^2 - 2x - \lambda_1 x + \lambda_2(x - 2)\]

  &lt;p&gt;&lt;strong&gt;c) Giải bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Cực tiểu hóa theo \(x\) cho \(x = \frac{2 + \lambda_1 - \lambda_2}{2}\), suy ra \(g(\lambda_1, \lambda_2) = -\frac{(2 + \lambda_1 - \lambda_2)^2}{4} - 2\lambda_2\). Trên miền \(\lambda \geq 0\), \(g\) đạt cực đại tại \(\lambda_1 = \lambda_2 = 0\) với \(d^* = g(0, 0) = -1\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Khoảng cách đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;\(\text{Gap} = p^* - d^* = -1 - (-1) = 0\). Bài toán lồi và thỏa mãn điều kiện Slater (ví dụ \(x = 1\) thỏa chặt cả hai bất đẳng thức), nên tính đối ngẫu mạnh đúng. Vì nghiệm \(x^* = 1\) nằm trong phần trong của miền khả thi, cả hai ràng buộc đều lỏng nên \(\lambda^* = 0\) (phù hợp điều kiện bù).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-vi-xấp-xỉ-chuẩn-và-tối-ưu-entropy&quot;&gt;Phần VI: Xấp xỉ chuẩn và tối ưu entropy&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-9-xấp-xỉ-chuẩn-boyd--vandenberghe-ex-53&quot;&gt;Bài tập 9: Xấp xỉ chuẩn (Boyd &amp;amp; Vandenberghe, Ex. 5.3)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt;
\(\min_x \lVert Ax - b \rVert\)&lt;/p&gt;

&lt;p&gt;với chuẩn lần lượt là \(\ell_1, \ell_2\) và \(\ell_\infty\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Biến đổi thành bài toán có ràng buộc.&lt;/li&gt;
  &lt;li&gt;Xây dựng bài toán đối ngẫu cho từng trường hợp.&lt;/li&gt;
  &lt;li&gt;So sánh các bài toán đối ngẫu thu được.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Trường hợp 1: Chuẩn \(\ell_1\)&lt;/strong&gt;&lt;/p&gt;

\[\min_{x,t} \mathbf{1}^T t \quad \text{s.t.} \quad -t \leq Ax - b \leq t\]

  &lt;p&gt;Bài toán đối ngẫu:
\(\max_{\lambda,\mu} -b^T(\lambda - \mu) \quad \text{s.t.} \quad A^T(\lambda - \mu) = 0, \quad \lambda + \mu = \mathbf{1}, \quad \lambda,\mu \geq 0\)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Trường hợp 2: Chuẩn \(\ell_2\)&lt;/strong&gt;&lt;/p&gt;

\[\min_{x,t} t \quad \text{s.t.} \quad \lVert Ax - b \rVert_2 \leq t\]

  &lt;p&gt;Bài toán đối ngẫu:
\(\max_{\nu} -b^T \nu \quad \text{s.t.} \quad A^T \nu = 0, \quad \lVert \nu \rVert_2 \leq 1\)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Trường hợp 3: Chuẩn \(\ell_\infty\)&lt;/strong&gt;&lt;/p&gt;

\[\min_{x,t} t \quad \text{s.t.} \quad -t\mathbf{1} \leq Ax - b \leq t\mathbf{1}\]

  &lt;p&gt;Bài toán đối ngẫu:
\(\max_{\lambda,\mu} -b^T(\lambda - \mu) \quad \text{s.t.} \quad A^T(\lambda - \mu) = 0, \quad \lVert \lambda - \mu \rVert_1 \leq 1\)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-10-cực-đại-hóa-entropy-boyd--vandenberghe-ex-54&quot;&gt;Bài tập 10: Cực đại hóa entropy (Boyd &amp;amp; Vandenberghe, Ex. 5.4)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt;
\(\max_x -\sum_{i=1}^n x_i \log x_i \quad \text{s.t.} \quad Ax = b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chuyển về bài toán cực tiểu hóa.&lt;/li&gt;
  &lt;li&gt;Xây dựng hàm Lagrangian.&lt;/li&gt;
  &lt;li&gt;Tính hàm đối ngẫu.&lt;/li&gt;
  &lt;li&gt;Tìm dạng nghiệm tối ưu.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Chuyển đổi:&lt;/strong&gt;
\(\min_x \sum_{i=1}^n x_i \log x_i \quad \text{s.t.} \quad Ax = b, \quad x \geq 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Hàm Lagrangian:&lt;/strong&gt;
\(L(x,\nu,\lambda) = \sum_{i=1}^n x_i \log x_i + \nu^T(Ax - b) - \lambda^T x\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt;
\(\frac{\partial L}{\partial x_i} = \log x_i + 1 + (A^T \nu)_i - \lambda_i = 0\)&lt;/p&gt;

  &lt;p&gt;Suy ra: \(x_i = e^{-(A^T \nu)_i + \lambda_i - 1}\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Điều kiện bù:&lt;/strong&gt;
Vì \(x_i = e^{\cdots} &amp;gt; 0\) nên \(\lambda_i = 0\), dẫn đến \(x_i = e^{-(A^T \nu)_i - 1}\). Hàm đối ngẫu là \(g(\nu) = -b^T \nu - \sum_{i=1}^n e^{-(A^T \nu)_i - 1}\); ta giải bài toán không ràng buộc \(\max_\nu g(\nu)\) rồi thế ngược lại để thu được \(x^*\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-vii-bài-tập-tính-toán-cụ-thể-với-nhân-tử-lagrange&quot;&gt;Phần VII: Bài tập tính toán cụ thể với nhân tử Lagrange&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-11-tối-ưu-danh-mục-đầu-tư-với-biến-đối-ngẫu&quot;&gt;Bài tập 11: Tối ưu danh mục đầu tư với biến đối ngẫu&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Một nhà đầu tư có 100 triệu đồng muốn phân bổ vào 3 tài sản với:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Vector lợi nhuận kỳ vọng: \(r = (12\%, 8\%, 5\%)^T\)&lt;/li&gt;
  &lt;li&gt;Ma trận hiệp phương sai rủi ro: \(\Sigma = \begin{bmatrix} 0.04 &amp;amp; 0.01 &amp;amp; 0 \\ 0.01 &amp;amp; 0.02 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0.01 \end{bmatrix}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bài toán: \(\min_x \frac{1}{2}x^T \Sigma x\) s.t. \(r^T x \geq 10\%\), \(\mathbf{1}^T x = 1\), \(x \geq 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Viết hàm Lagrangian với đầy đủ các ràng buộc.
b) Viết hệ điều kiện KKT.
c) Giải tìm phân bổ tối ưu \(x^*\).
d) Tính các biến đối ngẫu và giải thích ý nghĩa kinh tế.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết từng bước&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Hàm Lagrangian:&lt;/strong&gt;&lt;/p&gt;

\[L(x, \lambda_1, \nu, \lambda_2) = \frac{1}{2}x^T \Sigma x - \lambda_1(r^T x - 0.1) + \nu(\mathbf{1}^T x - 1) - \lambda_2^T x\]

  &lt;p&gt;với \(\lambda_1, \lambda_2 \geq 0\).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Điều kiện KKT:&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Điều kiện dừng (Stationarity):&lt;/strong&gt; \(\nabla_x L = \Sigma x - \lambda_1 r + \nu \mathbf{1} - \lambda_2 = 0\).&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Khả thi gốc:&lt;/strong&gt; \(r^T x \geq 0.1\), \(\mathbf{1}^T x = 1\), \(x \geq 0\).&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Khả thi đối ngẫu:&lt;/strong&gt; \(\lambda_1, \lambda_2 \geq 0\).&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Điều kiện bù:&lt;/strong&gt; \(\lambda_1(r^T x - 0.1) = 0\) và \(\lambda_{2i} x_i = 0\) với mọi \(i\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Giải bài toán:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Giả sử ràng buộc lợi nhuận chặt (\(r^T x = 0.1\)) và mọi \(x_i &amp;gt; 0\) (không bán khống). Khi đó từ điều kiện bù suy ra \(\lambda_2 = 0\), và điều kiện dừng trở thành \(\Sigma x = \lambda_1 r - \nu \mathbf{1}\):&lt;/p&gt;

\[\begin{bmatrix} 0.04 &amp;amp; 0.01 &amp;amp; 0 \\ 0.01 &amp;amp; 0.02 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0.01 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \lambda_1 \begin{bmatrix} 0.12 \\ 0.08 \\ 0.05 \end{bmatrix} - \nu \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}\]

  &lt;p&gt;Kết hợp với hai ràng buộc \(x_1 + x_2 + x_3 = 1\) và \(0.12x_1 + 0.08x_2 + 0.05x_3 = 0.1\) (suy ra \(x_3 = 1 - x_1 - x_2\) và \(0.07x_1 + 0.03x_2 = 0.05\)), ta giải hệ 5 phương trình tuyến tính 5 ẩn:&lt;/p&gt;

\[x^* = \begin{bmatrix} 7/12 \\ 11/36 \\ 1/9 \end{bmatrix} \approx \begin{bmatrix} 0.583 \\ 0.306 \\ 0.111 \end{bmatrix}, \quad \lambda_1^* = \frac{13}{36} \approx 0.361, \quad \nu^* = \frac{61}{3600} \approx 0.017\]

  &lt;p&gt;&lt;strong&gt;Kiểm tra:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Lợi nhuận: \(0.12 \cdot \frac{7}{12} + 0.08 \cdot \frac{11}{36} + 0.05 \cdot \frac{1}{9} = 0.1\) ✓; tổng tỷ trọng \(= 1\) ✓; mọi \(x_i &amp;gt; 0\) ✓ (giả thiết ban đầu đúng).&lt;/li&gt;
    &lt;li&gt;Giá trị hàm mục tiêu rủi ro: \(\frac{1}{2}x^{*T}\Sigma x^* = \frac{23}{2400} \approx 0.00958\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;d) Ý nghĩa kinh tế:&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;\(\lambda_1^* \approx 0.361\) là &lt;strong&gt;giá bóng của ràng buộc lợi nhuận&lt;/strong&gt;: nếu nâng yêu cầu lợi nhuận từ 10% lên 11%, giá trị rủi ro tối ưu tăng thêm khoảng \(0.361 \times 0.01 \approx 0.0036\).&lt;/li&gt;
    &lt;li&gt;\(\nu^* \approx 0.017\) là &lt;strong&gt;độ nhạy theo ràng buộc ngân sách&lt;/strong&gt;: nếu thay \(\mathbf{1}^T x = 1\) bằng \(1 + \delta\) (với \(\delta\) nhỏ), rủi ro tối ưu thay đổi khoảng \(-\nu^* \delta\).&lt;/li&gt;
    &lt;li&gt;\(\lambda_2 = 0\): không có tài sản nào chạm biên không bán khống.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Phân bổ tối ưu:&lt;/strong&gt; khoảng 58,3% vào tài sản 1, 30,6% vào tài sản 2 và 11,1% vào tài sản 3 (tương ứng khoảng 58,3 / 30,6 / 11,1 triệu đồng).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-12-sản-xuất-tối-ưu-với-nhân-tử-lagrange&quot;&gt;Bài tập 12: Sản xuất tối ưu với nhân tử Lagrange&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Một công ty sản xuất 2 sản phẩm A và B:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Lợi nhuận: sản phẩm A đạt 40 nghìn/đơn vị, sản phẩm B đạt 30 nghìn/đơn vị.&lt;/li&gt;
  &lt;li&gt;Ràng buộc nguồn lực:
    &lt;ul&gt;
      &lt;li&gt;Lao động: \(2A + B \leq 100\) giờ&lt;/li&gt;
      &lt;li&gt;Vật liệu: \(A + 2B \leq 80\) kg&lt;/li&gt;
      &lt;li&gt;Máy móc: \(A \leq 40\) sản phẩm&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bài toán: \(\max_{x_1, x_2} 40x_1 + 30x_2\) với các ràng buộc trên và \(x_1, x_2 \geq 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Chuyển về bài toán cực tiểu hóa và viết hàm Lagrangian.
b) Tìm nghiệm tối ưu bằng điều kiện KKT.
c) Tính giá bóng của từng nguồn lực.
d) Nếu có thể mua thêm 10 giờ lao động với giá 8 nghìn/giờ, có nên mua không?&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Chuyển về bài toán cực tiểu hóa:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;\(\min_{x_1, x_2} -40x_1 - 30x_2\)
\(\text{s.t.} \quad 2x_1 + x_2 \leq 100, \quad x_1 + 2x_2 \leq 80, \quad x_1 \leq 40, \quad x_1, x_2 \geq 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Hàm Lagrangian:&lt;/strong&gt;&lt;/p&gt;

\[L(x, \lambda) = -40x_1 - 30x_2 + \lambda_1(2x_1 + x_2 - 100) + \lambda_2(x_1 + 2x_2 - 80) + \lambda_3(x_1 - 40)\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Điều kiện KKT:&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Điều kiện dừng:&lt;/strong&gt;
\(\frac{\partial L}{\partial x_1} = -40 + 2\lambda_1 + \lambda_2 + \lambda_3 = 0\)
\(\frac{\partial L}{\partial x_2} = -30 + \lambda_1 + 2\lambda_2 = 0\)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Điều kiện bù:&lt;/strong&gt;
\(\lambda_1(2x_1 + x_2 - 100) = 0\)
\(\lambda_2(x_1 + 2x_2 - 80) = 0\)
\(\lambda_3(x_1 - 40) = 0\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Nhận xét:&lt;/strong&gt; Đỉnh \((40, 20)\) làm &lt;strong&gt;cả ba&lt;/strong&gt; ràng buộc đều chặt cùng lúc: \(2(40) + 20 = 100\), \(40 + 2(20) = 80\), \(x_1 = 40\). Đây là một đỉnh suy biến (degenerate).&lt;/p&gt;

  &lt;p&gt;So sánh giá trị lợi nhuận tại các đỉnh của miền khả thi: \((0, 0) \to 0\), \((0, 40) \to 1200\), \((40, 20) \to 2200\), \((40, 0) \to 1600\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm tối ưu:&lt;/strong&gt; \(x_1^* = 40\), \(x_2^* = 20\), lợi nhuận \(40(40) + 30(20) = 2200\) nghìn đồng.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Nhân tử KKT:&lt;/strong&gt; Vì \(x_1^*, x_2^* &amp;gt; 0\), điều kiện dừng cho hệ:&lt;/p&gt;

  &lt;p&gt;\(2\lambda_1 + \lambda_2 + \lambda_3 = 40\)
\(\lambda_1 + 2\lambda_2 = 30\)&lt;/p&gt;

  &lt;p&gt;Đặt \(\lambda_2 = s\), ta có \(\lambda_1 = 30 - 2s\) và \(\lambda_3 = 3s - 20\). Điều kiện \(\lambda \geq 0\) suy ra \(20/3 \leq s \leq 15\), nên tập nhân tử đối ngẫu &lt;strong&gt;không duy nhất&lt;/strong&gt; (do suy biến). Ví dụ:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(s = 20/3\): \(\lambda = (50/3,\ 20/3,\ 0)\)&lt;/li&gt;
    &lt;li&gt;\(s = 10\): \(\lambda = (10,\ 10,\ 10)\)&lt;/li&gt;
    &lt;li&gt;\(s = 15\): \(\lambda = (0,\ 15,\ 25)\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Mọi lựa chọn hợp lệ đều cho cùng giá trị đối ngẫu \(100\lambda_1 + 80\lambda_2 + 40\lambda_3 = 2200\) ✓ (đối ngẫu mạnh).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Giá bóng của từng nguồn lực:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Vì nhân tử đối ngẫu không duy nhất, giá bóng chỉ có ý nghĩa &lt;strong&gt;một phía&lt;/strong&gt;:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Lao động:&lt;/strong&gt; \(\lambda_1 \in [0,\ 50/3]\). Giảm 1 giờ lao động làm lợi nhuận giảm \(50/3 \approx 16{,}7\) nghìn đồng, nhưng &lt;strong&gt;tăng&lt;/strong&gt; thêm 1 giờ thì lợi nhuận tăng &lt;strong&gt;0&lt;/strong&gt;.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Vật liệu:&lt;/strong&gt; \(\lambda_2 \in [20/3,\ 15]\). Tăng 1 kg làm lợi nhuận tăng \(20/3 \approx 6{,}7\) nghìn đồng; giảm 1 kg làm lợi nhuận giảm 15 nghìn đồng.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Máy móc:&lt;/strong&gt; \(\lambda_3 \in [0,\ 25]\). Nới \(x_1 \leq 40\) thêm 1 đơn vị không làm tăng lợi nhuận (vì ràng buộc lao động lập tức chặn lại); siết lại 1 đơn vị làm giảm 25 nghìn đồng.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;d) Quyết định mua thêm lao động:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Khi tăng quỹ lao động lên 110 giờ, hai ràng buộc \(x_1 \leq 40\) và \(x_1 + 2x_2 \leq 80\) vẫn giữ nguyên nghiệm tối ưu tại \((40, 20)\) với lợi nhuận 2200 nghìn đồng; tức giá bóng &lt;strong&gt;theo chiều tăng&lt;/strong&gt; của lao động bằng 0.&lt;/p&gt;

  &lt;p&gt;Chi phí bỏ ra là \(10 \times 8 = 80\) nghìn đồng trong khi lợi ích thu thêm bằng 0.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; ❌ &lt;strong&gt;Không nên mua.&lt;/strong&gt; Việc mua thêm 10 giờ lao động gây lỗ 80 nghìn đồng; nút thắt thực sự nằm ở vật liệu và máy móc.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Tại đỉnh suy biến, đạo hàm trái và đạo hàm phải của giá trị tối ưu theo từng nguồn lực có thể khác nhau, nên cần kiểm tra miền độ nhạy trước khi áp dụng giá bóng.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tổng-kết-chiến-lược-giải-bài-tập&quot;&gt;Tổng kết chiến lược giải bài tập&lt;/h2&gt;

&lt;h3 id=&quot;đối-ngẫu-lagrange&quot;&gt;Đối ngẫu Lagrange&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm Lagrangian:&lt;/strong&gt; \(L(x, \lambda, \nu) = f_0(x) + \sum_i \lambda_i f_i(x) + \sum_j \nu_j h_j(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm đối ngẫu:&lt;/strong&gt; \(g(\lambda, \nu) = \inf_x L(x, \lambda, \nu)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt; \(\max_{\lambda \geq 0, \nu} g(\lambda, \nu)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;quan-hệ-đối-ngẫu&quot;&gt;Quan hệ đối ngẫu&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu yếu:&lt;/strong&gt; \(d^* \leq p^*\) luôn đúng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu mạnh:&lt;/strong&gt; \(d^* = p^*\) (ví dụ khi bài toán lồi và thỏa điều kiện Slater).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu:&lt;/strong&gt; \(p^* - d^* \geq 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;điều-kiện-bù&quot;&gt;Điều kiện bù&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;\(\lambda_i^* f_i(x^*) = 0\) với mọi \(i\).&lt;/li&gt;
  &lt;li&gt;Ràng buộc chặt (active) có thể có \(\lambda_i^* &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;Ràng buộc lỏng (inactive) bắt buộc có \(\lambda_i^* = 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;khi-nào-nên-giải-qua-bài-toán-đối-ngẫu&quot;&gt;Khi nào nên giải qua bài toán đối ngẫu&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Bài toán đối ngẫu có cấu trúc đơn giản hơn hoặc ít biến hơn (ví dụ SVM khi số mẫu nhỏ hơn số đặc trưng).&lt;/li&gt;
  &lt;li&gt;Cần phân tích độ nhạy thông qua giá bóng.&lt;/li&gt;
  &lt;li&gt;Cần khoảng cách đối ngẫu làm tiêu chí dừng trong các thuật toán điểm trong (interior-point).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 5.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Rockafellar, R. T.&lt;/strong&gt; (1970). &lt;em&gt;Convex Analysis&lt;/em&gt;. Princeton University Press. Chapter 28.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bertsekas, D. P.&lt;/strong&gt; (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt; (2nd ed.). Athena Scientific. Chapter 6.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Luenberger, D. G., &amp;amp; Ye, Y.&lt;/strong&gt; (2008). &lt;em&gt;Linear and Nonlinear Programming&lt;/em&gt; (3rd ed.). Springer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bazaraa, M. S., Sherali, H. D., &amp;amp; Shetty, C. M.&lt;/strong&gt; (2006). &lt;em&gt;Nonlinear Programming: Theory and Algorithms&lt;/em&gt; (3rd ed.). Wiley.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>11-09 Bài tập trắc nghiệm - Tính Đối Ngẫu trong Chương Trình Tổng Quát</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_09_Quiz_General_Duality/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_09_Quiz_General_Duality</id>
   <content type="html">&lt;p&gt;Chương 11 là bước chuyển quan trọng nhất từ thế giới tuyến tính (Chương 10) sang thế giới phi tuyến và tối ưu lồi tổng quát. Chính vì có sự chuyển pha này, các câu hỏi trắc nghiệm thường nhắm thẳng vào những điểm dễ nhầm lẫn giữa LP và bài toán tổng quát: chẳng hạn tưởng rằng bài toán lồi &lt;em&gt;luôn&lt;/em&gt; có đối ngẫu mạnh (quên điều kiện Slater!), tưởng rằng bài toán gốc không lồi thì bài toán đối ngẫu cũng không lồi, hay nhầm dấu của nhân tử \(u\) và \(v\) trong hàm Lagrangian.&lt;/p&gt;

&lt;p&gt;Hãy lướt nhanh qua bản đồ bốn cụm kiến thức trọng tâm và bốn phép thử nhanh dưới đây trước khi bắt đầu bộ câu hỏi trắc nghiệm để đạt độ chính xác tối đa.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-cụm-kiến-thức-trọng-tâm-cho-bài-trắc-nghiệm-chương-11&quot;&gt;Kiến thức cần nhớ: Bốn cụm kiến thức trọng tâm cho bài trắc nghiệm Chương 11&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc và tính chất hàm Lagrangian \(L(x, u, v)\):&lt;/strong&gt; Nhớ chuẩn dấu \(h_i(x) \le 0 \Rightarrow u_i \ge 0\) và \(l_j(x) = 0 \Rightarrow v_j \in \mathbb{R}\) tự do; luôn có \(L(x, u, v) \le f(x)\) trên tập khả thi \(C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lõm vô điều kiện của \(g(u, v)\):&lt;/strong&gt; Hàm đối ngẫu \(g(u, v) = \inf_x L(x, u, v)\) &lt;strong&gt;luôn lõm&lt;/strong&gt; và bài toán đối ngẫu \(\max_{u \ge 0, v} g(u, v)\) &lt;strong&gt;luôn là bài toán tối ưu lồi&lt;/strong&gt;, bất kể bài toán gốc lồi hay không lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu yếu, đối ngẫu mạnh và điều kiện Slater:&lt;/strong&gt; Đối ngẫu yếu (\(g^* \le f^*\)) luôn đúng; đối ngẫu mạnh (\(g^* = f^*\)) cần tính lồi + điều kiện chuẩn hóa (Slater: tồn tại điểm khả thi chặt cho các ràng buộc bất đẳng thức phi tuyến; ràng buộc affine chỉ cần \(\le 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu và hàm liên hợp Fenchel:&lt;/strong&gt; Hiệu \(f(x) - g(u, v) \ge f(x) - f^*\) là tiêu chuẩn dừng có chứng chỉ; hàm liên hợp \(f^*(y) = \sup_x (y^T x - f(x))\) giúp tính nhanh \(g(u, v)\) và chứng minh tính đối ngẫu kép \(f^{**} = f\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bốn-phép-thử-nhanh-né-bẫy-trắc-nghiệm-chương-11&quot;&gt;Giải thích: Bốn phép thử nhanh né bẫy trắc nghiệm Chương 11&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 1 — Bài toán gốc cực kỳ không lồi (ví dụ \(\min \sin(x) + x^4\) s.t. \(x^3 - x \le 0\)), bài toán đối ngẫu Lagrange có lồi không?&lt;/strong&gt;
&lt;strong&gt;CÓ!&lt;/strong&gt; Bài toán đối ngẫu \(\max_{u \ge 0} g(u)\) luôn là bài toán tối ưu lồi (cực đại hóa hàm lõm \(g(u)\) trên miền lồi \(u \ge 0\)), không phụ thuộc vào tính lồi của bài toán gốc!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 2 — Kiểm tra điều kiện Slater cho bài toán lồi \(\min x^2\) s.t. \(x^2 \le 0\):&lt;/strong&gt;
Ràng buộc \(h(x) = x^2 \le 0\) là phi tuyến và chỉ có duy nhất điểm \(x = 0\) thỏa \(h(0) = 0\) (không có điểm nào làm \(x^2 &amp;lt; 0\)) \(\implies\) &lt;strong&gt;Slater không thỏa mãn!&lt;/strong&gt; (Dù trong bài toán riêng này tình cờ vẫn có \(f^* = g^* = 0\) — nhớ rằng Slater là điều kiện &lt;em&gt;đủ&lt;/em&gt;, không phải điều kiện &lt;em&gt;cần&lt;/em&gt;!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 3 — Đọc khoảng cách đối ngẫu:&lt;/strong&gt; Nếu \(x\) khả thi gốc cho \(f(x) = 8.4\) và \(u \ge 0\) khả thi đối ngẫu cho \(g(u) = 8.1\), khoảng cách đối ngẫu là \(0.3\). Kết luận nào đúng?
\(f(x) - f^* \le 0.3\) và \(8.1 \le f^* \le 8.4\) (đừng nhầm rằng \(f^* = 8.1\) hay \(f(x) - f^* = 0.3\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 4 — Liên hợp của hàm tuyến tính \(f(x) = c^T x\):&lt;/strong&gt;
\(f^*(y) = \sup_x (y - c)^T x = 0\) nếu \(y = c\) và \(+\infty\) nếu \(y \ne c\) — chính là hàm chỉ thị \(I_{\{c\}}(y)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-tính-đối-ngẫu-tổng-quát-general-duality&quot;&gt;⚡ Tính đối ngẫu tổng quát (General Duality)&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-tối-ưu-tổng-quát&quot;&gt;Bài toán tối ưu tổng quát&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) \quad \text{s.t.} \quad h_i(x) \le 0, \quad l_j(x) = 0\)&lt;/p&gt;

&lt;p&gt;trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(x)\): hàm mục tiêu (không nhất thiết lồi),&lt;/li&gt;
  &lt;li&gt;\(h_i(x) \le 0\): các ràng buộc bất đẳng thức (\(i = 1,\ldots,m\)),&lt;/li&gt;
  &lt;li&gt;\(l_j(x) = 0\): các ràng buộc đẳng thức (\(j = 1,\ldots,r\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;mở-rộng-từ-đối-ngẫu-lp&quot;&gt;Mở rộng từ đối ngẫu LP&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu LP (Chương 10):&lt;/strong&gt; chỉ áp dụng cho quy hoạch tuyến tính.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu tổng quát (Chương 11):&lt;/strong&gt; áp dụng cho mọi bài toán tối ưu nhờ sử dụng hàm Lagrangian thay cho tổ hợp tuyến tính trực tiếp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-hàm-lagrangian&quot;&gt;📏 Hàm Lagrangian&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h4&gt;
&lt;p&gt;\(L(x,u,v) = f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x)\)&lt;/p&gt;

&lt;p&gt;trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(u \in \mathbb{R}^m, u \ge 0\): biến đối ngẫu cho các ràng buộc bất đẳng thức,&lt;/li&gt;
  &lt;li&gt;\(v \in \mathbb{R}^r\): biến đối ngẫu cho các ràng buộc đẳng thức (không ràng buộc dấu).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tính-chất-cơ-bản&quot;&gt;Tính chất cơ bản&lt;/h4&gt;
&lt;p&gt;Với mọi điểm khả thi \(x\) và mọi \(u \ge 0, v\):
\(L(x,u,v) = f(x) + \sum_{i=1}^m u_i \underbrace{h_i(x)}_{\le 0} + \sum_{j=1}^r v_j \underbrace{l_j(x)}_{= 0} \le f(x)\)&lt;/p&gt;

&lt;p&gt;Như vậy, hàm Lagrangian luôn là &lt;strong&gt;cận dưới&lt;/strong&gt; của \(f(x)\) tại mọi điểm khả thi, với các biến đối ngẫu đóng vai trò như hệ số phạt (hoặc giá biên) đối với việc vi phạm ràng buộc.&lt;/p&gt;

&lt;h3 id=&quot;-hàm-đối-ngẫu-lagrange&quot;&gt;🎯 Hàm đối ngẫu Lagrange&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa-1&quot;&gt;Định nghĩa&lt;/h4&gt;
&lt;p&gt;\(g(u,v) = \min_x L(x,u,v) = \min_x \left\{ f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x) \right\}\)&lt;/p&gt;

&lt;h4 id=&quot;tính-chất-quan-trọng&quot;&gt;Tính chất quan trọng&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cận dưới (đối ngẫu yếu):&lt;/strong&gt; \(g(u,v) \le f^*\) với mọi \(u \ge 0, v\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lõm:&lt;/strong&gt; \(g(u,v)\) luôn là hàm &lt;strong&gt;lõm&lt;/strong&gt; theo \((u,v)\), ngay cả khi bài toán gốc không lồi.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;chứng-minh-tính-lõm&quot;&gt;Chứng minh tính lõm&lt;/h4&gt;
&lt;p&gt;\(g(u,v) = \min_x L(x,u,v) = -\max_x \{-L(x,u,v)\}\)&lt;/p&gt;

&lt;p&gt;Vì \(-L(x,u,v)\) là hàm affine (nên lồi) theo \((u,v)\), cực đại theo từng điểm của một họ hàm lồi là hàm lồi, do đó \(g(u,v)\) là hàm lõm.&lt;/p&gt;

&lt;h3 id=&quot;-bài-toán-đối-ngẫu-lagrange&quot;&gt;📊 Bài toán đối ngẫu Lagrange&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa-2&quot;&gt;Định nghĩa&lt;/h4&gt;
&lt;p&gt;\(\max_{u,v} g(u,v) \quad \text{s.t.} \quad u \ge 0\)&lt;/p&gt;

&lt;p&gt;Mục tiêu của bài toán là tìm &lt;strong&gt;cận dưới lớn nhất&lt;/strong&gt; cho \(f^*\). Vì cực đại hóa hàm lõm trên tập lồi \(u \ge 0\), &lt;strong&gt;bài toán đối ngẫu luôn là bài toán tối ưu lồi&lt;/strong&gt;, bất kể bài toán gốc có lồi hay không.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu yếu:&lt;/strong&gt; \(g^* \le f^*\) luôn đúng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu:&lt;/strong&gt; \(f^* - g^* \ge 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ví-dụ-quy-hoạch-bậc-hai-quadratic-programming&quot;&gt;🔄 Ví dụ: Quy hoạch bậc hai (Quadratic Programming)&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán&quot;&gt;Bài toán&lt;/h4&gt;
&lt;p&gt;\(\min_x \frac{1}{2}x^T Q x + c^T x \quad \text{s.t.} \quad Ax = b, \quad x \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;trường-hợp-1-q-succ-0-xác-định-dương&quot;&gt;Trường hợp 1: \(Q \succ 0\) (xác định dương)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm Lagrangian:&lt;/strong&gt; \(L(x,u,v) = \frac{1}{2}x^T Q x + c^T x - u^T x + v^T(Ax - b)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa theo \(x\):&lt;/strong&gt; \(\nabla_x L = Qx + c - u + A^T v = 0 \Rightarrow x^* = Q^{-1}(u - c - A^T v)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm đối ngẫu:&lt;/strong&gt; \(g(u,v) = -\frac{1}{2}(c - u + A^T v)^T Q^{-1}(c - u + A^T v) - b^T v\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;trường-hợp-2-q-succeq-0-nửa-xác-định-dương&quot;&gt;Trường hợp 2: \(Q \succeq 0\) (nửa xác định dương)&lt;/h4&gt;
&lt;p&gt;\(g(u,v) = \begin{cases}
-\frac{1}{2}(c - u + A^T v)^T Q^+(c - u + A^T v) - b^T v &amp;amp; \text{if } c - u + A^T v \perp \text{null}(Q) \\
-\infty &amp;amp; \text{otherwise}
\end{cases}\)&lt;/p&gt;

&lt;p&gt;với \(Q^+\) là nghịch đảo giả Moore–Penrose của \(Q\).&lt;/p&gt;

&lt;h3 id=&quot;-đối-ngẫu-mạnh-strong-duality&quot;&gt;💪 Đối ngẫu mạnh (Strong Duality)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; Đối ngẫu mạnh xảy ra khi \(f^* = g^*\) (khoảng cách đối ngẫu bằng 0).&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-slater&quot;&gt;Điều kiện Slater&lt;/h4&gt;
&lt;p&gt;Nếu bài toán gốc là &lt;strong&gt;lồi&lt;/strong&gt; và tồn tại điểm \(x\) &lt;strong&gt;khả thi chặt&lt;/strong&gt;:
\(h_i(x) &amp;lt; 0 \quad \forall i, \quad l_j(x) = 0 \quad \forall j\)
thì tính đối ngẫu mạnh được thỏa mãn. Lưu ý rằng với các ràng buộc bất đẳng thức affine, không cần dấu bất đẳng thức chặt.&lt;/p&gt;

&lt;h3 id=&quot;-ví-dụ-support-vector-machine-svm&quot;&gt;🎯 Ví dụ: Support Vector Machine (SVM)&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-gốc&quot;&gt;Bài toán gốc&lt;/h4&gt;
&lt;p&gt;\(\min_{\beta,\beta_0,\xi} \frac{1}{2}\|\beta\|_2^2 + C\sum_{i=1}^n \xi_i\)
\(\text{s.t.} \quad \xi_i \ge 0, \quad y_i(x_i^T\beta + \beta_0) \ge 1 - \xi_i\)&lt;/p&gt;

&lt;h4 id=&quot;hàm-lagrangian&quot;&gt;Hàm Lagrangian&lt;/h4&gt;
&lt;p&gt;\(L(\beta,\beta_0,\xi,v,w) = \frac{1}{2}\|\beta\|_2^2 + C\sum_{i=1}^n \xi_i - \sum_{i=1}^n v_i \xi_i + \sum_{i=1}^n w_i(1 - \xi_i - y_i(x_i^T\beta + \beta_0))\)&lt;/p&gt;

&lt;h4 id=&quot;bài-toán-đối-ngẫu-sau-khi-khử-các-biến-gốc&quot;&gt;Bài toán đối ngẫu (sau khi khử các biến gốc)&lt;/h4&gt;
&lt;p&gt;\(\max_w -\frac{1}{2}w^T \tilde{X}\tilde{X}^T w + \mathbf{1}^T w\)
\(\text{s.t.} \quad 0 \le w \le C\mathbf{1}, \quad w^T y = 0\)&lt;/p&gt;

&lt;p&gt;với \(\tilde{X} = \text{diag}(y)X\). Bài toán thỏa mãn điều kiện Slater nên đối ngẫu mạnh đúng (\(f^* = g^*\)).&lt;/p&gt;

&lt;h3 id=&quot;-khoảng-cách-đối-ngẫu-duality-gap&quot;&gt;📐 Khoảng cách đối ngẫu (Duality Gap)&lt;/h3&gt;

&lt;p&gt;Cho \(x\) khả thi gốc và \((u,v)\) khả thi đối ngẫu:
\(\text{Duality gap} = f(x) - g(u,v)\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cận trên của sai số nghiệm:&lt;/strong&gt; \(f(x) - f^* \le f(x) - g(u,v)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chí dừng:&lt;/strong&gt; Nếu \(f(x) - g(u,v) \le \epsilon\) thì chắc chắn \(f(x) - f^* \le \epsilon\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra tối ưu:&lt;/strong&gt; \(f(x) - g(u,v) = 0 \Leftrightarrow x\) và \((u,v)\) đều tối ưu.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-so-sánh-đối-ngẫu-lp-và-đối-ngẫu-tổng-quát&quot;&gt;🔄 So sánh đối ngẫu LP và đối ngẫu tổng quát&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;strong&gt;Khía cạnh&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Đối ngẫu LP (Chương 10)&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Đối ngẫu tổng quát (Chương 11)&lt;/strong&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Phạm vi&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Chỉ quy hoạch tuyến tính&lt;/td&gt;
      &lt;td&gt;Mọi bài toán tối ưu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Phương pháp&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tổ hợp tuyến tính các ràng buộc&lt;/td&gt;
      &lt;td&gt;Hàm Lagrangian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tính lồi của bài toán đối ngẫu&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Luôn lồi (LP)&lt;/td&gt;
      &lt;td&gt;Luôn lồi (hàm \(g\) lõm)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Đối ngẫu mạnh&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đúng nếu ít nhất một bài toán khả thi&lt;/td&gt;
      &lt;td&gt;Cần điều kiện Slater (hoặc CQ tương đương)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ứng dụng tiêu biểu&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;LP, luồng trên mạng, trò chơi ma trận&lt;/td&gt;
      &lt;td&gt;SVM, QP, tối ưu có ràng buộc tổng quát&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;-ví-dụ-minh-họa-nhanh&quot;&gt;💡 Ví dụ minh họa nhanh&lt;/h3&gt;

&lt;p&gt;Xét \(\min_x x^2 \quad \text{s.t.} \quad x \ge 1\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm Lagrangian:&lt;/strong&gt; \(L(x,u) = x^2 - u(x - 1) = x^2 - ux + u\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa theo \(x\):&lt;/strong&gt; \(\frac{\partial L}{\partial x} = 2x - u = 0 \Rightarrow x = \frac{u}{2}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm đối ngẫu:&lt;/strong&gt; \(g(u) = L\left(\frac{u}{2}, u\right) = \frac{u^2}{4} - u \cdot \frac{u}{2} + u = -\frac{u^2}{4} + u\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt; \(\max_{u \ge 0} \left(-\frac{u^2}{4} + u\right)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt; \(u^* = 2, g^* = 1\) và \(x^* = 1, f^* = 1\) (đối ngẫu mạnh ✓).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;lưu-ý-khi-giải-bài-tập&quot;&gt;Lưu ý khi giải bài tập&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Các bước chuẩn:&lt;/strong&gt; Lập hàm Lagrangian → cực tiểu hóa theo \(x\) để tìm \(g(u,v)\) → cực đại hóa \(g(u,v)\) với \(u \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lỗi thường gặp:&lt;/strong&gt; Nhầm quy ước dấu (\(u \ge 0\) ứng với ràng buộc dạng \(h(x) \le 0\)); quên kiểm tra điều kiện Slater; mặc định bài toán không lồi có đối ngẫu mạnh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết nối với chương tiếp theo:&lt;/strong&gt; Điều kiện tối ưu KKT và điều kiện bù (Chương 12), cùng các mở rộng như đối ngẫu Fenchel và đối ngẫu hình nón (SOCP, SDP).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Ghi chú:&lt;/strong&gt; Đối ngẫu tổng quát chuyển bài toán từ việc tìm trực tiếp nghiệm gốc sang tìm cận dưới chặt nhất và khai thác cấu trúc lồi của bài toán đối ngẫu.&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra kiến thức về tính đối ngẫu trong tối ưu tổng quát, bao gồm hàm Lagrangian, hàm đối ngẫu, đối ngẫu mạnh, điều kiện Slater và điều kiện KKT.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🎯 Quiz: Tính Đối Ngẫu trong Chương Trình Tổng Quát&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;25&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: Lagrangian definition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Cho bài toán \(\min f(x)\) s.t. \(h_i(x) \leq 0, l_j(x) = 0\). Lagrangian được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(L(x,u,v) = f(x) + \sum u_i h_i(x) + \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(L(x,u,v) = f(x) - \sum u_i h_i(x) - \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(L(x,u,v) = f(x) + \sum u_i h_i(x) - \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(L(x,u,v) = f(x) - \sum u_i h_i(x) + \sum v_j l_j(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$L(x,u,v) = f(x) + \sum u_i h_i(x) + \sum v_j l_j(x)$$&lt;/strong&gt;&lt;br /&gt;
                Hàm Lagrangian kết hợp hàm mục tiêu với các số hạng ràng buộc có trọng số, trong đó $$u_i \geq 0$$ ứng với các ràng buộc bất đẳng thức.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Dual variables constraints --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Trong Lagrangian, dual variables phải thỏa mãn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(u \geq 0, v\) không ràng buộc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(u\) không ràng buộc, \(v \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(u \geq 0, v \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(u\) và \(v\) đều không ràng buộc&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$u \geq 0, v$$ không ràng buộc&lt;/strong&gt;&lt;br /&gt;
                Biến đối ngẫu $$u_i$$ cho ràng buộc bất đẳng thức phải không âm, còn $$v_j$$ cho ràng buộc đẳng thức không bị ràng buộc dấu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Lagrange dual function --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Lagrange dual function \(g(u,v)\) được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(g(u,v) = \max_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(g(u,v) = \min_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \(g(u,v) = L(x^*,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \(g(u,v) = \nabla_x L(x,u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$g(u,v) = \min_x L(x,u,v)$$&lt;/strong&gt;&lt;br /&gt;
                Hàm đối ngẫu là infimum của hàm Lagrangian theo biến gốc $$x$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Weak duality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Định lý đối ngẫu yếu phát biểu rằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) \(g(u,v) \geq f^*\) với mọi \(u \geq 0, v\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) \(g(u,v) \leq f^*\) với mọi \(u \geq 0, v\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) \(g(u,v) = f^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) \(g(u,v) &amp;gt; f^*\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$g(u,v) \leq f^*$$ với mọi $$u \geq 0, v$$&lt;/strong&gt;&lt;br /&gt;
                Hàm đối ngẫu cung cấp cận dưới cho giá trị tối ưu của bài toán gốc: $$g^* \leq f^*$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Dual problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Lagrange dual problem là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(\min_{u \geq 0, v} g(u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(\max_{u \geq 0, v} g(u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(\min_{u, v \geq 0} g(u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \(\max_{u, v} g(u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\max_{u \geq 0, v} g(u,v)$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán đối ngẫu cực đại hóa hàm đối ngẫu để tìm cận dưới tốt nhất cho bài toán gốc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Strong duality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Tính đối ngẫu mạnh xảy ra khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(f^* &amp;gt; g^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(f^* = g^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(f^* &amp;lt; g^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Duality gap &amp;gt; 0&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$f^* = g^*$$&lt;/strong&gt;&lt;br /&gt;
                Đối ngẫu mạnh có nghĩa là khoảng cách đối ngẫu bằng 0: giá trị tối ưu của bài toán gốc và bài toán đối ngẫu bằng nhau.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Slater condition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Slater condition yêu cầu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Tồn tại \(x\) sao cho \(h_i(x) \leq 0, l_j(x) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Tồn tại \(x\) sao cho \(h_i(x) &amp;lt; 0, l_j(x) = 0\) (strictly feasible)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Tồn tại \(x\) sao cho \(h_i(x) = 0, l_j(x) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Tất cả constraints đều active&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tồn tại $$x$$ sao cho $$h_i(x) &amp;lt; 0, l_j(x) = 0$$ (strictly feasible)&lt;/strong&gt;&lt;br /&gt;
                Điều kiện Slater yêu cầu tồn tại điểm khả thi chặt để đảm bảo tính đối ngẫu mạnh cho bài toán lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Duality gap --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Duality gap được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(g^* - f^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(f^* - g^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(|f^* - g^*|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(f^* + g^*\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$f^* - g^*$$&lt;/strong&gt;&lt;br /&gt;
                Khoảng cách đối ngẫu là hiệu giữa giá trị tối ưu gốc và đối ngẫu, luôn không âm theo tính đối ngẫu yếu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: KKT stationarity --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: KKT stationarity condition là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(\nabla f(x^*) + \sum u_i^* \nabla h_i(x^*) + \sum v_j^* \nabla l_j(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(\nabla f(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(u_i^* h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(h_i(x^*) \leq 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\nabla f(x^*) + \sum u_i^* \nabla h_i(x^*) + \sum v_j^* \nabla l_j(x^*) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện dừng (stationarity): gradient của hàm Lagrangian theo $$x$$ bằng 0 tại điểm tối ưu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: KKT complementary slackness --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: KKT complementary slackness condition là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(u_i^* \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(h_i(x^*) \leq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(u_i^* h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(l_j(x^*) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) $$u_i^* h_i(x^*) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện bù: nếu ràng buộc lỏng (không chặt) thì biến đối ngẫu bằng 0; nếu biến đối ngẫu dương thì ràng buộc tương ứng chặt.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: KKT conditions sufficiency --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: KKT conditions là điều kiện đủ cho optimality khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Bài toán là convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Bài toán là non-convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Luôn luôn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Không bao giờ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Bài toán là convex&lt;/strong&gt;&lt;br /&gt;
                Điều kiện KKT là điều kiện cần cho cực trị địa phương (khi thỏa điều kiện chuẩn hóa ràng buộc), và là điều kiện đủ cho cực trị toàn cục khi bài toán lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Dual function properties --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Dual function \(g(u,v)\) có tính chất:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Luôn concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Luôn convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Có thể không concave hoặc convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Luôn linear&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Luôn concave&lt;/strong&gt;&lt;br /&gt;
                Hàm đối ngẫu luôn lõm vì là infimum theo từng điểm của một họ các hàm affine theo $$(u,v)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Constraint qualification --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Constraint qualification cần thiết để:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Đảm bảo KKT conditions là necessary&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Đảm bảo hàm dual là concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Đảm bảo convexity&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Đảm bảo uniqueness&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Đảm bảo KKT conditions là necessary&lt;/strong&gt;&lt;br /&gt;
                Điều kiện chuẩn hóa ràng buộc (như LICQ, MFCQ) đảm bảo điều kiện KKT là điều kiện cần cho tính tối ưu địa phương.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: SVM dual problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Trong SVM, dual problem có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Quadratic programming với linear constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Linear programming&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Nonlinear programming&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Integer programming&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Quadratic programming với linear constraints&lt;/strong&gt;&lt;br /&gt;
                Bài toán đối ngẫu của SVM là một bài toán quy hoạch bậc hai: cực đại hóa hàm bậc hai dưới các ràng buộc tuyến tính và ràng buộc hộp.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Lagrangian saddle point --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Tại optimal point, Lagrangian có tính chất saddle point:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(L(x^*,u,v) \leq L(x^*,u^*,v^*) \leq L(x,u^*,v^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(L(x^*,u,v) \geq L(x^*,u^*,v^*) \geq L(x,u^*,v^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(L(x^*,u^*,v^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) \(L(x,u,v)\) là constant&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$L(x^*,u,v) \leq L(x^*,u^*,v^*) \leq L(x,u^*,v^*)$$&lt;/strong&gt;&lt;br /&gt;
                Tính chất điểm yên ngựa: hàm Lagrangian đạt cực tiểu theo $$x$$ và cực đại theo $$(u,v)$$ tại cặp nghiệm tối ưu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Convex optimization duality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Trong convex optimization, nếu Slater condition thỏa mãn thì:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Weak duality holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Strong duality holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) KKT conditions sufficient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Tất cả các điều trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các điều trên&lt;/strong&gt;&lt;br /&gt;
                Với bài toán lồi thỏa mãn điều kiện Slater: đối ngẫu yếu và đối ngẫu mạnh đều đúng, và điều kiện KKT là điều kiện cần và đủ.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Dual optimal solution --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Nếu \(x^*\) là primal optimal và \((u^*,v^*)\) là dual optimal với strong duality, thì:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) \(f(x^*) = g(u^*,v^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) \(f(x^*) &amp;gt; g(u^*,v^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) \(f(x^*) &amp;lt; g(u^*,v^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Không thể xác định&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f(x^*) = g(u^*,v^*)$$&lt;/strong&gt;&lt;br /&gt;
                Đối ngẫu mạnh có nghĩa là giá trị tối ưu của bài toán gốc và bài toán đối ngẫu bằng nhau.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Lagrangian relaxation --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Lagrangian relaxation được sử dụng để:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Tìm upper bound cho minimization problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Tìm lower bound cho minimization problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Giải chính xác bài toán gốc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Chuyển đổi sang maximization&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tìm lower bound cho minimization problem&lt;/strong&gt;&lt;br /&gt;
                Nới lỏng Lagrangian chuyển các ràng buộc vào hàm mục tiêu để thu được cận dưới thông qua hàm đối ngẫu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Geometric interpretation --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Về mặt hình học, duality gap bằng 0 có nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Feasible set rỗng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Supporting hyperplane tách hoàn hảo epigraph và feasible set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Bài toán unbounded&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Constraints redundant&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Supporting hyperplane tách hoàn hảo epigraph và feasible set&lt;/strong&gt;&lt;br /&gt;
                Về mặt hình học, đối ngẫu mạnh tương ứng với sự tồn tại của siêu phẳng tựa (supporting hyperplane) tách phần trên đồ thị và miền ràng buộc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Lagrangian duality có ứng dụng trong:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Machine learning (SVM, neural networks)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Economics (utility maximization)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Engineering (optimal control, signal processing)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các lĩnh vực trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các lĩnh vực trên&lt;/strong&gt;&lt;br /&gt;
                Đối ngẫu Lagrange là công cụ nền tảng trong tối ưu hóa, được ứng dụng trong học máy, kinh tế học, kỹ thuật và nhiều lĩnh vực khác.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Hàm đối ngẫu Lagrange $$g(\lambda, \nu)$$ được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$\inf_x L(x, \lambda, \nu)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$\sup_x L(x, \lambda, \nu)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$\nabla_x L(x, \lambda, \nu)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$L(x^*, \lambda, \nu)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\inf_x L(x, \lambda, \nu)$$&lt;/strong&gt;&lt;br /&gt;
                Hàm đối ngẫu Lagrange: $$g(\lambda, \nu) = \inf_x L(x, \lambda, \nu)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Đối ngẫu yếu khẳng định:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$g(\lambda, \nu) \leq p^*$$ với $$\lambda \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$g(\lambda, \nu) \geq p^*$$ với $$\lambda \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$g(\lambda, \nu) = p^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Không có mối quan hệ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$g(\lambda, \nu) \leq p^*$$ với $$\lambda \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Đối ngẫu yếu: giá trị dual luôn là cận dưới của giá trị primal.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Duality gap bằng 0 khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Đối ngẫu mạnh thỏa mãn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Bài toán lồi và thỏa Slater condition&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Bài toán là LP khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Tất cả các điều trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các điều trên&lt;/strong&gt;&lt;br /&gt;
                Duality gap = 0 chính là đối ngẫu mạnh; bài toán lồi + Slater condition là điều kiện đủ; LP khả thi luôn có đối ngẫu mạnh. Lưu ý: chỉ riêng tính lồi thì chưa đủ.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Slater condition yêu cầu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Tồn tại $$x$$ khả thi với $$g_i(x) &amp;lt; 0$$ (strict)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Tồn tại $$x$$ với $$g_i(x) \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Hàm mục tiêu lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Ràng buộc tuyến tính&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Tồn tại $$x$$ khả thi với $$g_i(x) &amp;lt; 0$$ (strict)&lt;/strong&gt;&lt;br /&gt;
                Slater condition: tồn tại điểm strictly feasible $$x$$ với $$g_i(x) &amp;lt; 0$$ cho tất cả $$i$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Bài toán dual của $$\min f(x)$$ với $$h(x) \leq 0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$\max g(\lambda)$$ với $$\lambda \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$\min g(\lambda)$$ với $$\lambda \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$\max g(\lambda)$$ với $$\lambda \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$\sup g(\lambda)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max g(\lambda)$$ với $$\lambda \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán dual: $$\max_{\lambda \geq 0} g(\lambda)$$ với $$g(\lambda) = \inf_x L(x,\lambda)$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành Quiz!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;a&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;b&apos;, q9: &apos;a&apos;, q10: &apos;c&apos;,
    q11: &apos;a&apos;, q12: &apos;a&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;d&apos;, q17: &apos;a&apos;, q18: &apos;b&apos;, q19: &apos;b&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;d&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã nắm vững lý thuyết đối ngẫu Lagrange.&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu tốt về điều kiện KKT và tính đối ngẫu mạnh.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại điều kiện Slater và điều kiện bù.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Ôn lại hàm Lagrangian và hàm đối ngẫu.&apos;;
    } else {
        message = &apos;📖 Hãy ôn lại từ đầu lý thuyết đối ngẫu tổng quát.&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>11-07 Dual của Dual trong Tối Ưu Convex Tổng Quát</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_07_Dual_of_Dual_General_Case/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_07_Dual_of_Dual_General_Case</id>
   <content type="html">&lt;p&gt;Ở Chương 10, ta đã tận hưởng cảm giác đối xứng hoàn hảo của Quy hoạch tuyến tính: lấy đối ngẫu hai lần luôn quay về chính xác bài toán gốc. Bước sang Chương 11 với các hàm phi tuyến tổng quát, một câu hỏi vừa sâu sắc vừa tinh tế xuất hiện: &lt;strong&gt;trong tối ưu lồi tổng quát, “đối ngẫu của đối ngẫu” có còn là bài toán gốc nữa không?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Câu trả lời là một kiệt tác của giải tích lồi hiện đại (Định lý Fenchel–Moreau): &lt;strong&gt;CÓ&lt;/strong&gt;, miễn là bài toán gốc lồi, các hàm đóng (nửa liên tục dưới) và thỏa điều kiện chuẩn hóa (như Slater)! Còn nếu bài toán gốc &lt;em&gt;không lồi&lt;/em&gt; thì sao? Khi đó, phép lấy đối ngẫu hai lần không quay về bài toán gốc gồ ghề ban đầu nữa, mà trả về &lt;strong&gt;bản bao lồi đóng chặt nhất nằm dưới bài toán gốc (convex relaxation / biconjugate \(f^{**}\))&lt;/strong&gt;! Khám phá này giải thích lý do vì sao trong tối ưu tổ hợp và học máy không lồi, việc lấy đối ngẫu kép là cách tự động tạo ra bản nới lỏng lồi tốt nhất!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tính-đối-ngẫu-kép-tổng-quát&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tính đối ngẫu kép tổng quát&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định lý Fenchel–Moreau (Liên hợp kép \(f^{**} = f\)):&lt;/strong&gt; Nếu \(f\) là hàm lồi, chính quy (proper) và đóng (lower semicontinuous), thì hàm liên hợp của hàm liên hợp bằng chính nó: \((f^*)^*(x) = f(x)\). Nếu \(f\) không lồi, \(f^{**}\) là hàm lồi đóng lớn nhất nằm dưới \(f\) (bao lồi đóng — closed convex envelope).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển bài toán đối ngẫu \(\max_{u \ge 0} g(u)\) về dạng \(\min\) để lấy đối ngẫu lần 2:&lt;/strong&gt; Viết lại thành \(\min_{u} (-g(u))\) với ràng buộc \(-u \le 0\), rồi đưa thêm nhân tử Lagrange mới \(\tilde{x}\) (chính là biến gốc hồi sinh!) để lập Lagrangian bậc hai.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vai trò của điều kiện Slater trong đối ngẫu kép:&lt;/strong&gt; Để không xuất hiện khe hở khi đảo thứ tự \(\min_x \max_u\) và \(\max_u \min_x\) (định lý điểm yên ngựa Sion / minimax), điều kiện Slater bảo đảm giá trị tối ưu và tập nghiệm được bảo toàn trọn vẹn khi quay về bài toán gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa cho bài toán không lồi (Convexification):&lt;/strong&gt; Khi áp dụng quy trình Primal \(\to\) Dual \(\to\) Bi-dual lên một bài toán không lồi, ta tự động nhận được bản nới lỏng lồi chặt nhất của nó (ví dụ nới lỏng chuẩn hạt nhân cho bài toán hạng thấp hay SDP relaxation cho Max-Cut!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tay-fx--fx-cho-hàm-mũ-phi-tuyến-fx--ex&quot;&gt;Giải thích: Kiểm chứng tay \(f^{**}(x) = f(x)\) cho hàm mũ phi tuyến \(f(x) = e^x\)&lt;/h3&gt;

&lt;p&gt;Hàm \(f(x) = e^x\) là hàm lồi, trơn, đóng trên toàn \(\mathbb{R}\). Hãy tự tay thực hiện phép biến đổi liên hợp Fenchel hai lần liên tiếp!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lần 1 — Tính hàm liên hợp \(f^*(y) = \sup_{x \in \mathbb{R}} (yx - e^x)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu \(y &amp;lt; 0\): cho \(x \to -\infty\) thì \(yx \to +\infty\) và \(e^x \to 0\), nên \(f^*(y) = +\infty\).&lt;/li&gt;
      &lt;li&gt;Nếu \(y = 0\): \(\sup_x (-e^x) = 0\) (khi \(x \to -\infty\)).&lt;/li&gt;
      &lt;li&gt;Nếu \(y &amp;gt; 0\): cho đạo hàm theo \(x\) bằng \(0\): \(y - e^x = 0 \implies x = \ln y\). Thay lại:
\(f^*(y) = y\ln y - y \quad (\text{hàm entropy âm!}).\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lần 2 — Tính hàm liên hợp kép \(f^{**}(x) = \sup_{y &amp;gt; 0} \big(xy - (y\ln y - y)\big)\):&lt;/strong&gt;
Lấy đạo hàm theo \(y &amp;gt; 0\) và cho bằng \(0\):
\(\frac{d}{dy}\big(xy - y\ln y + y\big) = x - (\ln y + 1) + 1 = x - \ln y = 0 \implies y^* = e^x &amp;gt; 0.\)
Thay \(y^* = e^x\) trở lại biểu thức:
\(f^{**}(x) = x e^x - e^x \ln(e^x) + e^x = x e^x - x e^x + e^x = e^x = f(x)!\)
Ta quay trở về &lt;strong&gt;đúng từng ký tự của hàm gốc \(e^x\)&lt;/strong&gt; — minh họa sống động nhất cho định lý Fenchel–Moreau và tính đối ngẫu kép trong tối ưu lồi!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Trong Chương 10, chúng ta đã chứng minh rằng đối với quy hoạch tuyến tính (LP), đối ngẫu của bài toán đối ngẫu luôn quay trở về đúng bài toán gốc. Bài học này làm rõ câu hỏi mở rộng: tính chất đó có còn đúng trong tối ưu lồi tổng quát hay không và cần thêm những điều kiện nào.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;nhắc-lại-đối-ngẫu-kép-trong-quy-hoạch-tuyến-tính&quot;&gt;Nhắc lại: Đối ngẫu kép trong quy hoạch tuyến tính&lt;/h2&gt;

&lt;p&gt;Với cặp bài toán LP:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán gốc (Primal):&lt;/strong&gt;
\(\begin{align}
\text{minimize} \quad &amp;amp; c^T x \\
\text{subject to} \quad &amp;amp; Ax \geq b, \\
&amp;amp; x \geq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu (Dual):&lt;/strong&gt;
\(\begin{align}
\text{maximize} \quad &amp;amp; b^T y \\
\text{subject to} \quad &amp;amp; A^T y \leq c, \\
&amp;amp; y \geq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;Ta luôn có &lt;strong&gt;Đối ngẫu của đối ngẫu = Bài toán gốc&lt;/strong&gt;. Hãy xem điều gì xảy ra khi mở rộng sang bài toán tối ưu lồi tổng quát.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-toán-tối-ưu-lồi-tổng-quát&quot;&gt;Bài toán tối ưu lồi tổng quát&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối ưu lồi tổng quát:&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; f_0(x) \\
\text{subject to} \quad &amp;amp; f_i(x) \leq 0, \; i = 1, \ldots, m, \\
&amp;amp; h_j(x) = 0, \; j = 1, \ldots, p,
\end{align}\]

&lt;p&gt;trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f_0, f_1, \ldots, f_m\) là các hàm lồi,&lt;/li&gt;
  &lt;li&gt;\(h_1, \ldots, h_p\) là các hàm affine,&lt;/li&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) là vector biến quyết định.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;xây-dựng-bài-toán-đối-ngẫu&quot;&gt;Xây dựng bài toán đối ngẫu&lt;/h2&gt;

&lt;h3 id=&quot;hàm-lagrangian&quot;&gt;Hàm Lagrangian&lt;/h3&gt;

&lt;p&gt;Hàm Lagrangian được định nghĩa là:&lt;/p&gt;

\[\mathcal{L}(x, \lambda, \nu) = f_0(x) + \sum_{i=1}^m \lambda_i f_i(x) + \sum_{j=1}^p \nu_j h_j(x)\]

&lt;p&gt;với:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\lambda \in \mathbb{R}^m, \lambda \geq 0\): vector nhân tử Lagrange cho các ràng buộc bất đẳng thức,&lt;/li&gt;
  &lt;li&gt;\(\nu \in \mathbb{R}^p\): vector nhân tử Lagrange cho các ràng buộc đẳng thức.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;hàm-đối-ngẫu&quot;&gt;Hàm đối ngẫu&lt;/h3&gt;

\[g(\lambda, \nu) = \inf_x \mathcal{L}(x, \lambda, \nu)\]

&lt;h3 id=&quot;bài-toán-đối-ngẫu&quot;&gt;Bài toán đối ngẫu&lt;/h3&gt;

\[\begin{align}
\text{maximize} \quad &amp;amp; g(\lambda, \nu) \\
\text{subject to} \quad &amp;amp; \lambda \geq 0
\end{align}\]

&lt;hr /&gt;

&lt;h2 id=&quot;đối-ngẫu-của-đối-ngẫu-cho-bài-toán-lồi&quot;&gt;Đối ngẫu của đối ngẫu cho bài toán lồi&lt;/h2&gt;

&lt;p&gt;Khi lấy đối ngẫu thêm một lần nữa từ bài toán đối ngẫu ở trên, ta có thu lại được bài toán gốc ban đầu hay không?&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; Nếu bài toán thỏa mãn các điều kiện sau:&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;Bài toán gốc là &lt;strong&gt;lồi&lt;/strong&gt; (và hàm mục tiêu đóng / nửa liên tục dưới),&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Tính đối ngẫu mạnh&lt;/strong&gt; thỏa mãn (khoảng cách đối ngẫu bằng 0),&lt;/li&gt;
    &lt;li&gt;Thỏa mãn một &lt;strong&gt;điều kiện chuẩn hóa ràng buộc&lt;/strong&gt; (constraint qualification, chẳng hạn điều kiện Slater),&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;thì:&lt;/p&gt;

\[\boxed{\text{Dual của Dual} = \text{Primal}}\]

&lt;h3 id=&quot;điều-kiện-slater&quot;&gt;Điều kiện Slater&lt;/h3&gt;

&lt;p&gt;Điều kiện Slater yêu cầu tồn tại một điểm khả thi chặt \(\tilde{x}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f_i(\tilde{x}) &amp;lt; 0\) với mọi \(i = 1, \ldots, m\) (không bắt buộc chặt đối với các ràng buộc affine),&lt;/li&gt;
  &lt;li&gt;\(h_j(\tilde{x}) = 0\) với mọi \(j = 1, \ldots, p\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý về độ chặt chẽ:&lt;/strong&gt; Điều kiện Slater đảm bảo tính đối ngẫu mạnh. Để bài toán đối ngẫu kép (bidual) khôi phục chính xác bài toán gốc, bài toán gốc cần có thêm tính lồi và tính đóng (hàm mục tiêu nửa liên tục dưới). Với các bài toán không lồi, đối ngẫu kép nói chung chỉ cho ra bản lồi hóa (convex relaxation) của bài toán gốc.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;so-sánh-quy-hoạch-tuyến-tính-và-tối-ưu-lồi-tổng-quát&quot;&gt;So sánh: Quy hoạch tuyến tính và tối ưu lồi tổng quát&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tính chất&lt;/th&gt;
      &lt;th&gt;Quy hoạch tuyến tính (LP)&lt;/th&gt;
      &lt;th&gt;Tối ưu lồi tổng quát&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dual của Dual = Primal&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Luôn đúng&lt;/td&gt;
      &lt;td&gt;Cần thêm điều kiện&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Đối ngẫu mạnh&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đúng nếu ít nhất một bài toán khả thi&lt;/td&gt;
      &lt;td&gt;Cần điều kiện Slater (hoặc CQ tương đương)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Cấu trúc&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đối xứng trực tiếp&lt;/td&gt;
      &lt;td&gt;Đối xứng có điều kiện&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Điều kiện ràng buộc (CQ)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tự động thỏa mãn (ràng buộc affine)&lt;/td&gt;
      &lt;td&gt;Cần kiểm tra&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;vì-sao-lp-là-trường-hợp-đặc-biệt&quot;&gt;Vì sao LP là trường hợp đặc biệt?&lt;/h2&gt;

&lt;p&gt;Trong LP, tính chất đối ngẫu kép luôn đúng nhờ bốn đặc điểm sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Luôn là bài toán lồi:&lt;/strong&gt; Hàm mục tiêu tuyến tính và miền khả thi là đa diện lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu mạnh không cần điều kiện chặt:&lt;/strong&gt; Chỉ cần bài toán gốc hoặc bài toán đối ngẫu khả thi, khoảng cách đối ngẫu bằng 0 khi tồn tại nghiệm tối ưu hữu hạn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc ma trận đối xứng:&lt;/strong&gt; Phép chuyển vị hai lần trả về ma trận ban đầu (\((A^T)^T = A\)), và việc hoán đổi \((b, c)\) hai lần khôi phục đúng vị trí cũ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc đều là affine:&lt;/strong&gt; Điều kiện chuẩn hóa ràng buộc dạng mở rộng tự động được thỏa mãn khi bài toán khả thi.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ví-dụ-minh-họa&quot;&gt;Ví dụ minh họa&lt;/h2&gt;

&lt;h3 id=&quot;ví-dụ-1-quy-hoạch-bậc-hai-lồi-convex-qp&quot;&gt;Ví dụ 1: Quy hoạch bậc hai lồi (Convex QP)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán gốc:&lt;/strong&gt;
\(\begin{align}
\text{minimize} \quad &amp;amp; \frac{1}{2}x^T Q x + c^T x \\
\text{subject to} \quad &amp;amp; Ax \leq b
\end{align}\)&lt;/p&gt;

&lt;p&gt;với \(Q \succ 0\) (xác định dương).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu lồi chặt và các ràng buộc là affine.&lt;/li&gt;
  &lt;li&gt;Khi bài toán khả thi, điều kiện Slater dạng mở rộng được thỏa mãn.&lt;/li&gt;
  &lt;li&gt;Do đó &lt;strong&gt;Đối ngẫu của đối ngẫu = Bài toán gốc&lt;/strong&gt; ✓.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-2-bài-toán-không-lồi&quot;&gt;Ví dụ 2: Bài toán không lồi&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán gốc:&lt;/strong&gt;
\(\text{minimize} \quad -x^2 \quad \text{subject to} \quad 0 \leq x \leq 1\)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu \(-x^2\) là hàm lõm (không lồi).&lt;/li&gt;
  &lt;li&gt;Nghiệm tối ưu gốc: \(x^* = 1\), \(p^* = -1\).&lt;/li&gt;
  &lt;li&gt;Với nhân tử \(\lambda_1 \geq 0\) (cho \(-x \leq 0\)) và \(\lambda_2 \geq 0\) (cho \(x - 1 \leq 0\)), hàm đối ngẫu là:&lt;/li&gt;
&lt;/ul&gt;

\[g(\lambda_1, \lambda_2) = \inf_{x \in \mathbb{R}} \left( -x^2 - \lambda_1 x + \lambda_2 (x - 1) \right) = -\infty \quad \text{với mọi } \lambda_1, \lambda_2 \geq 0,\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;vì \(-x^2 \to -\infty\) khi $$&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\to \infty$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;Giá trị tối ưu đối ngẫu là \(d^* = -\infty &amp;lt; p^* = -1\). Khoảng cách đối ngẫu bằng vô hạn, đối ngẫu mạnh không xảy ra và đối ngẫu kép không quay về bài toán gốc ✗.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-3-bài-toán-lồi-không-thỏa-điều-kiện-slater&quot;&gt;Ví dụ 3: Bài toán lồi không thỏa điều kiện Slater&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán gốc:&lt;/strong&gt;
\(\text{minimize} \quad x^2 \quad \text{subject to} \quad x^2 \leq 0\)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu và hàm ràng buộc đều lồi, nhưng miền khả thi chỉ gồm đúng một điểm \(x = 0\) nên không tồn tại điểm khả thi chặt (\(x^2 &amp;lt; 0\) vô nghiệm).&lt;/li&gt;
  &lt;li&gt;Điều kiện Slater &lt;strong&gt;không thỏa mãn&lt;/strong&gt; ✗.&lt;/li&gt;
  &lt;li&gt;Dù vậy, trong trường hợp cụ thể này ta vẫn có \(p^* = d^* = 0\) (đối ngẫu mạnh vẫn xảy ra vì điều kiện Slater chỉ là điều kiện đủ, không phải điều kiện cần).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ứng-dụng-và-ý-nghĩa&quot;&gt;Ứng dụng và ý nghĩa&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích khoảng cách đối ngẫu:&lt;/strong&gt; Khi đối ngẫu kép không trùng với bài toán gốc, khoảng cách đối ngẫu thường dương; ta cần kiểm tra lại tính lồi hoặc sử dụng các phương pháp nới lỏng lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn chiến lược giải:&lt;/strong&gt; Với LP, có thể giải bài toán gốc hay bài toán đối ngẫu tùy theo kích thước. Với bài toán lồi tổng quát, cần kiểm tra điều kiện đối ngẫu mạnh trước khi chuyển sang giải đối ngẫu. Với bài toán không lồi, bài toán đối ngẫu chỉ bảo đảm cung cấp cận dưới.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cơ sở lý thuyết:&lt;/strong&gt; Tính chất này gắn trực tiếp với điều kiện tối ưu KKT (Chương 12) và thiết kế các thuật toán gốc – đối ngẫu.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-thực-hành&quot;&gt;Bài tập thực hành&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-kiểm-tra-điều-kiện-slater&quot;&gt;Bài tập 1: Kiểm tra điều kiện Slater&lt;/h3&gt;

&lt;p&gt;Kiểm tra điều kiện Slater và xác định xem đối ngẫu kép có trùng với bài toán gốc không đối với các bài toán sau:&lt;/p&gt;

&lt;p&gt;a) \(\min x^2 + y^2\) s.t. \(x + y \geq 2\)&lt;/p&gt;

&lt;p&gt;b) \(\min e^x\) s.t. \(x \geq 0\)&lt;/p&gt;

&lt;p&gt;c) \(\min -\log x\) s.t. \(x \leq 1\), \(x &amp;gt; 0\)&lt;/p&gt;

&lt;h3 id=&quot;bài-tập-2-so-sánh-lp-và-qp&quot;&gt;Bài tập 2: So sánh LP và QP&lt;/h3&gt;

&lt;p&gt;Cho hai bài toán:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP:&lt;/strong&gt; \(\min c^T x\) s.t. \(Ax \leq b\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QP:&lt;/strong&gt; \(\min \frac{1}{2}x^T Q x\) s.t. \(Ax \leq b\) với \(Q \succ 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;a) Xây dựng bài toán đối ngẫu của mỗi bài toán.
b) Kiểm tra tính chất đối ngẫu kép.
c) So sánh các điều kiện cần thiết giữa hai bài toán.&lt;/p&gt;

&lt;h3 id=&quot;bài-tập-3-ví-dụ-không-lồi&quot;&gt;Bài tập 3: Ví dụ không lồi&lt;/h3&gt;

&lt;p&gt;Xét bài toán:&lt;/p&gt;

\[\min_{x \in \mathbb{R}} x^3 \quad \text{s.t.} \quad x \geq 1\]

&lt;p&gt;a) Giải bài toán gốc.
b) Xây dựng bài toán đối ngẫu.
c) Chứng minh đối ngẫu kép không quay về bài toán gốc.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Điều kiện&lt;/th&gt;
      &lt;th&gt;LP&lt;/th&gt;
      &lt;th&gt;Tối ưu lồi&lt;/th&gt;
      &lt;th&gt;Không lồi&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Tính lồi&lt;/td&gt;
      &lt;td&gt;✓ (tự động)&lt;/td&gt;
      &lt;td&gt;✓ (cần kiểm tra)&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đối ngẫu mạnh&lt;/td&gt;
      &lt;td&gt;✓ (nếu khả thi)&lt;/td&gt;
      &lt;td&gt;✓ (cần điều kiện Slater)&lt;/td&gt;
      &lt;td&gt;✗ (nói chung)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual của Dual = Primal&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
      &lt;td&gt;✓ (có điều kiện)&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004).&lt;/strong&gt; &lt;em&gt;Convex Optimization.&lt;/em&gt; Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 5: Duality (đặc biệt Section 5.2 và 5.3)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rockafellar, R. T. (1970).&lt;/strong&gt; &lt;em&gt;Convex Analysis.&lt;/em&gt; Princeton University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 31: Duality correspondences&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bertsekas, D. P. (1999).&lt;/strong&gt; &lt;em&gt;Nonlinear Programming&lt;/em&gt; (2nd ed.). Athena Scientific.
    &lt;ul&gt;
      &lt;li&gt;Chapter 6: Duality and convex analysis&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov, Y. (2018).&lt;/strong&gt; &lt;em&gt;Lectures on Convex Optimization.&lt;/em&gt; Springer.
    &lt;ul&gt;
      &lt;li&gt;Chapter 3: Duality Theory (Section 3.4)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Kết nối với các chương khác:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chương 10:&lt;/strong&gt; Đối ngẫu kép trong LP (trường hợp đặc biệt).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chương 12:&lt;/strong&gt; Điều kiện KKT.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chương 15 và 17:&lt;/strong&gt; Phương pháp hàm rào (barrier method) và phương pháp điểm trong gốc – đối ngẫu (primal-dual interior-point methods).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>11-06 Trực Quan về Lagrange Duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_06_Lagrange_Duality_Intuition/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_06_Lagrange_Duality_Intuition</id>
   <content type="html">&lt;p&gt;Rất nhiều người học tối ưu có thể viết vanh vách công thức \(L(x, u, v)\) và lấy đạo hàm tìm \(g(u, v)\), nhưng tận sâu bên trong vẫn thấy một câu hỏi lơ lửng: &lt;em&gt;“Về mặt hình học, ta thực sự đang làm cái gì khi lấy \(\max_u \inf_x L(x, u)\)? Và hàm liên hợp lồi (conjugate function) \(f^*(y)\) liên quan gì tới bài toán đối ngẫu?”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bài học chuyên sâu này mở toang bức màn hình học đằng sau toàn bộ Chương 11. Nếu bạn chiếu mọi điểm \(x\) của bài toán xuống mặt phẳng 2 chiều gồm trục hoành là mức vi phạm ràng buộc \(u = h(x)\) và trục tung là giá trị mục tiêu \(t = f(x)\), thì bài toán gốc chỉ đơn giản là tìm &lt;strong&gt;điểm thấp nhất cắt trục tung \(u = 0\)&lt;/strong&gt;; còn bài toán đối ngẫu hóa ra là trò chơi &lt;strong&gt;nghiêng một đường thẳng đỡ có độ dốc \(-u\) nằm hoàn toàn dưới đám mây điểm rồi đẩy giao điểm của nó với trục tung lên cao nhất có thể!&lt;/strong&gt; Khi bức tranh hình học ấy bật sáng, mọi bí ẩn về đối ngẫu yếu, đối ngẫu mạnh, điều kiện Slater và hàm liên hợp bỗng trở nên hiển nhiên như nhìn một bức tranh vẽ tay!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-lăng-kính-trực-quan-về-đối-ngẫu-lagrange&quot;&gt;Kiến thức cần nhớ: Bốn lăng kính trực quan về đối ngẫu Lagrange&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đồ thị ràng buộc–mục tiêu \(\mathcal{G} = \{(h(x), f(x)) : x \in \mathcal{D}\}\):&lt;/strong&gt; Bài toán gốc là tìm tung độ thấp nhất của \(\mathcal{G}\) bên trái trục tung (\(u \le 0\)). Nhân tử Lagrange \(u \ge 0\) xác định pháp tuyến \((u, 1)\) của một siêu phẳng đỡ nghiêng dưới \(\mathcal{G}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm đối ngẫu \(g(u)\) = tung độ gốc của siêu phẳng đỡ thấp nhất:&lt;/strong&gt; Vì \(\inf_x (f(x) + u h(x))\) chính là giao điểm với trục tung của đường thẳng có độ dốc \(-u\) chạm đáy tập \(\mathcal{G}\), cực đại hóa \(g(u)\) chính là xoay độ dốc \(-u\) để nâng giao điểm trục tung lên sát đáy \(f^*\) nhất có thể!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm nhiễu loạn (Perturbation Function) \(p^*(u)\):&lt;/strong&gt; Định nghĩa \(p^*(u) = \inf \{f(x) : h(x) \le u\}\) là giá trị tối ưu khi nới ràng buộc thêm lượng \(u\). Đối ngẫu mạnh tương đương với việc \(p^*(u)\) có một siêu phẳng đỡ không thẳng đứng tại \(u = 0\), và độ dốc của \(p^*(u)\) tại \(0\) chính là \(-u^*\) (ý nghĩa độ nhạy toàn cục!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối hàm liên hợp Fenchel \(f^*(y) = \sup_x (y^T x - f(x))\):&lt;/strong&gt; Với bài toán \(\min f(x)\) s.t. \(Ax \le b\), ta viết lại ngay hàm đối ngẫu bằng hàm liên hợp:
\(g(u) = \inf_x (f(x) + u^T(Ax - b)) = -b^T u - \sup_x \big((-A^T u)^T x - f(x)\big) = -b^T u - f^*(-A^T u)!\)
Nhờ công thức thần kỳ này, chỉ cần tra bảng hàm liên hợp \(f^*\) là viết ra ngay bài toán đối ngẫu cho hàng chục bài toán lớn!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-hàm-liên-hợp-fy-và-suy-ra-hàm-đối-ngẫu-chỉ-trong-2-dòng&quot;&gt;Giải thích: Tính tay hàm liên hợp \(f^*(y)\) và suy ra hàm đối ngẫu chỉ trong 2 dòng&lt;/h3&gt;

&lt;p&gt;Xét bài toán \(\min_x f(x) = \frac{1}{2}x^2\) với ràng buộc \(Ax \le b\) dạng 1D là \(-x \le -3\) (tức \(A = -1, b = -3\), tương đương \(x \ge 3\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính hàm liên hợp của \(f(x) = \frac{1}{2}x^2\):&lt;/strong&gt;
\(f^*(y) = \sup_{x \in \mathbb{R}} \left(yx - \frac{1}{2}x^2\right).\)
Đạo hàm theo \(x\) bằng \(0 \implies y - x = 0 \implies x = y\). Thay lại:
\(f^*(y) = y^2 - \frac{1}{2}y^2 = \frac{1}{2}y^2.\)
(Thật đẹp: \(\frac{1}{2}x^2\) là hàm tự liên hợp của chính nó!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ráp thẳng vào công thức liên hợp \(g(u) = -b u - f^*(-A u)\) với \(A = -1, b = -3, u \ge 0\):&lt;/strong&gt;
\(g(u) = -(-3)u - f^*(+u) = 3u - \frac{1}{2}u^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng cực đại của \(g(u)\) và độ nhạy \(p^*(u)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Cực đại hóa \(3u - \frac{1}{2}u^2\) cho \(u^* = 3\) và \(g^* = 3(3) - 4.5 = 4.5 = \frac{1}{2}(3)^2 = f^*\)!&lt;/li&gt;
      &lt;li&gt;Kiểm tra độ nhạy: nếu nới ràng buộc \(-x \le -3 + \delta\) (tức \(x \ge 3 - \delta\)), giá trị tối ưu mới là \(p^*(\delta) = \frac{1}{2}(3 - \delta)^2\), đạo hàm tại \(\delta = 0\) là \((p^*)&apos;(0) = -(3 - 0) = -3 = -u^*\)! Mọi mảnh ghép hình học và giải tích ăn khớp nhau tuyệt đối!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;trực-quan-về-lagrange-duality&quot;&gt;Trực Quan về Lagrange Duality&lt;/h1&gt;

&lt;h2 id=&quot;-bài-toán-tối-ưu-tổng-quát&quot;&gt;🔍 Bài toán tối ưu tổng quát&lt;/h2&gt;

&lt;p&gt;Giả sử chúng ta cần giải bài toán tối ưu:&lt;/p&gt;

\[\begin{align}
\min_x f(x) \\
\text{s.t. } h_i(x) \leq 0, \quad i=1,\ldots,m \\
\mathcal{D} = \text{dom } f \cap \bigcap_{i=1}^{m} \text{dom } h_i
\end{align}\]

&lt;p&gt;&lt;em&gt;Lưu ý: Để đơn giản, ta chỉ xét các ràng buộc bất đẳng thức; mỗi ràng buộc đẳng thức có thể viết tương đương thành hai ràng buộc bất đẳng thức.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;-ý-tưởng-của-bài-toán-đối-ngẫu&quot;&gt;🎭 Ý tưởng của bài toán đối ngẫu&lt;/h2&gt;

&lt;p&gt;Theo quy trình chuẩn, ta xây dựng hàm Lagrangian:&lt;/p&gt;

\[L(x, \lambda) = f(x) + \lambda^T h(x), \quad \lambda \succeq 0\]

&lt;p&gt;Sau đó định nghĩa hàm đối ngẫu Lagrange:&lt;/p&gt;

\[\begin{align}
g(\lambda) &amp;amp;= \inf_{x \in \mathcal{D}} L(x, \lambda) \\
&amp;amp;= \inf_{x \in \mathcal{D}} (f(x) + \lambda^T h(x))
\end{align}\]

&lt;p&gt;&lt;em&gt;Lưu ý: Phép lấy infimum được thực hiện trên toàn bộ miền xác định \(\mathcal{D}\), chứ không giới hạn trong tập khả thi của các ràng buộc.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Cuối cùng, bằng cách giải bài toán đối ngẫu:&lt;/p&gt;

\[\max_{\lambda} g(\lambda) \quad \text{s.t. } \lambda \succeq 0\]

&lt;p&gt;ta thu được cận dưới tốt nhất có thể cho giá trị tối ưu của bài toán gốc.&lt;/p&gt;

&lt;h2 id=&quot;-tại-sao-cần-hàm-lagrangian&quot;&gt;🤔 Tại sao cần hàm Lagrangian?&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Câu hỏi:&lt;/strong&gt; Vì sao ta cần xây dựng hàm Lagrangian?&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Trả lời:&lt;/strong&gt; Để xử lý các ràng buộc thông qua &lt;strong&gt;nhiễu động (perturbation)&lt;/strong&gt; của hàm mục tiêu.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ta không thể giải bài toán gốc chỉ bằng cách đặt \(\frac{\partial f(x)}{\partial x} = 0\) vì biến \(x\) bị giới hạn bởi tập khả thi của các ràng buộc. Một hướng tiếp cận là đưa các ràng buộc vào hàm mục tiêu như những số hạng phạt/nhiễu động, rồi tìm cận dưới chặt nhất.&lt;/p&gt;

&lt;h3 id=&quot;-ví-dụ-minh-họa&quot;&gt;💡 Ví dụ minh họa&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu:&lt;/p&gt;

\[\begin{align}
\min_x x^2 \\
\text{s.t. } x - 1 \leq 0 \\
\mathcal{D} = \mathbb{R}
\end{align}\]

&lt;p&gt;Nghiệm tối ưu của bài toán gốc là \(x^* = 0\) với giá trị \(p^* = 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm Lagrangian:&lt;/strong&gt;
\(L(x, \lambda) = x^2 + \lambda(x - 1), \quad \lambda \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm dual:&lt;/strong&gt;
\(g(\lambda) = \inf_{x \in \mathcal{D}} (x^2 + \lambda(x - 1)), \quad \lambda \geq 0\)&lt;/p&gt;

&lt;p&gt;Để tìm \(\inf_{x \in \mathcal{D}} (x^2 + \lambda(x - 1))\), ta cần \(\frac{\partial L(x,\lambda)}{\partial x} = 0\).&lt;/p&gt;

&lt;p&gt;Do đó: \(2x + \lambda = 0 \Rightarrow x = -\frac{\lambda}{2}\)&lt;/p&gt;

&lt;p&gt;Thay ngược lại vào hàm dual:
\(g(\lambda) = \frac{\lambda^2}{4} - \lambda \cdot \frac{\lambda}{2} - \lambda = -\frac{\lambda^2}{4} - \lambda, \quad \lambda \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán dual:&lt;/strong&gt;
\(\max_{\lambda} g(\lambda) \quad \text{s.t. } \lambda \geq 0\)&lt;/p&gt;

&lt;p&gt;Điểm cực đại không ràng buộc của \(g\) là \(\lambda = -2\) (với \(g(-2) = 1\)), nhưng không hợp lệ do ràng buộc \(\lambda \geq 0\). Trên miền \(\lambda \geq 0\), \(g\) giảm dần nên nghiệm đối ngẫu tối ưu là \(\lambda^* = 0\) với \(d^* = g(0) = 0 = p^*\) (tính đối ngẫu mạnh).&lt;/p&gt;

&lt;div id=&quot;lagrangian-visualization&quot; style=&quot;margin: 20px 0; padding: 20px; background: #f8f9fa; border-radius: 10px;&quot;&gt;
    &lt;canvas id=&quot;lagrangianCanvas&quot; width=&quot;900&quot; height=&quot;500&quot; style=&quot;border: 2px solid #dee2e6; display: block; margin: 0 auto; background: white; border-radius: 5px;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin: 15px 0;&quot;&gt;
        &lt;div style=&quot;display: inline-block; padding: 10px 20px; background: white; border-radius: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
            &lt;label style=&quot;font-size: 18px; font-weight: bold;&quot;&gt;λ = &lt;span id=&quot;lambdaValue&quot; style=&quot;color: #007bff;&quot;&gt;0.0&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
            &lt;input type=&quot;range&quot; id=&quot;lambdaSlider&quot; min=&quot;0&quot; max=&quot;4&quot; step=&quot;0.05&quot; value=&quot;0&quot; style=&quot;width: 400px; margin-top: 10px;&quot; /&gt;
            &lt;div style=&quot;margin-top: 10px; font-size: 14px; color: #666;&quot;&gt;
                &lt;span&gt;Kéo thanh trượt để thay đổi hệ số Lagrange&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div id=&quot;lagrangianInfo&quot; style=&quot;text-align: center; margin-top: 15px; padding: 10px; background: white; border-radius: 5px;&quot;&gt;
        &lt;p style=&quot;margin: 5px 0; font-size: 16px;&quot;&gt;&lt;strong&gt;Giá trị dual:&lt;/strong&gt; &lt;span id=&quot;dualValue&quot; style=&quot;color: #28a745; font-weight: bold;&quot;&gt;g(0) = 0&lt;/span&gt;&lt;/p&gt;
        &lt;p style=&quot;margin: 5px 0; font-size: 14px; color: #666;&quot;&gt;&lt;span id=&quot;lowerBoundInfo&quot;&gt;Cận dưới của bài toán&lt;/span&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    // Wait for DOM to be ready
    if (document.readyState === &apos;loading&apos;) {
        document.addEventListener(&apos;DOMContentLoaded&apos;, initLagrangianViz);
    } else {
        initLagrangianViz();
    }
    
    function initLagrangianViz() {
    const canvas = document.getElementById(&apos;lagrangianCanvas&apos;);
        if (!canvas) return;
        
    const ctx = canvas.getContext(&apos;2d&apos;);
    const slider = document.getElementById(&apos;lambdaSlider&apos;);
    const valueSpan = document.getElementById(&apos;lambdaValue&apos;);
        const dualValueSpan = document.getElementById(&apos;dualValue&apos;);
        const lowerBoundInfo = document.getElementById(&apos;lowerBoundInfo&apos;);
        
        // Animation state
        let animationFrame = null;
        
        function drawGrid(centerX, centerY, scale) {
            ctx.strokeStyle = &apos;#e9ecef&apos;;
            ctx.lineWidth = 1;
            ctx.setLineDash([2, 2]);
            
            // Vertical grid lines
            for (let x = -8; x &lt;= 8; x++) {
                if (x === 0) continue;
                const screenX = centerX + x * scale;
                ctx.beginPath();
                ctx.moveTo(screenX, 0);
                ctx.lineTo(screenX, canvas.height);
                ctx.stroke();
            }
            
            // Horizontal grid lines
            for (let y = -4; y &lt;= 4; y++) {
                if (y === 0) continue;
                const screenY = centerY - y * scale;
                ctx.beginPath();
                ctx.moveTo(0, screenY);
                ctx.lineTo(canvas.width, screenY);
                ctx.stroke();
            }
            
            ctx.setLineDash([]);
        }
        
        function drawAxes(centerX, centerY, scale) {
            // Draw axes
            ctx.strokeStyle = &apos;#495057&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.moveTo(0, centerY);
            ctx.lineTo(canvas.width, centerY);
            ctx.moveTo(centerX, 0);
            ctx.lineTo(centerX, canvas.height);
            ctx.stroke();
            
            // Draw axis labels
            ctx.fillStyle = &apos;#495057&apos;;
            ctx.font = &apos;bold 14px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            
            // X-axis labels
            for (let x = -8; x &lt;= 8; x += 2) {
                if (x === 0) continue;
                const screenX = centerX + x * scale;
                ctx.fillText(x.toString(), screenX, centerY + 20);
            }
            
            // Y-axis labels
            ctx.textAlign = &apos;right&apos;;
            for (let y = -4; y &lt;= 4; y += 2) {
                if (y === 0) continue;
                const screenY = centerY - y * scale;
                ctx.fillText(y.toString(), centerX - 10, screenY + 5);
            }
            
            // Axis names
            ctx.font = &apos;bold 16px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;x&apos;, canvas.width - 20, centerY - 10);
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(&apos;y&apos;, centerX + 10, 20);
        }
    
    function drawVisualization() {
        const lambda = parseFloat(slider.value);
            valueSpan.textContent = lambda.toFixed(2);
        
        // Clear canvas
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Set up coordinate system
        const centerX = canvas.width / 2;
            const centerY = canvas.height * 0.6;
        const scale = 50;
            
            // Draw grid
            drawGrid(centerX, centerY, scale);
        
        // Draw axes
            drawAxes(centerX, centerY, scale);
        
        // Draw original function f(x) = x^2
            ctx.strokeStyle = &apos;#212529&apos;;
            ctx.lineWidth = 3;
        ctx.beginPath();
        let first = true;
            for (let x = -8; x &lt;= 8; x += 0.05) {
                const y = x * x;
            const screenX = centerX + x * scale;
                const screenY = centerY - y * scale / 4;
                if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height &amp;&amp; screenX &gt;= 0 &amp;&amp; screenX &lt;= canvas.width) {
                if (first) {
                    ctx.moveTo(screenX, screenY);
                    first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
        
        // Draw Lagrangian L(x,λ) = x^2 + λ(x-1)
            if (lambda &gt; 0.01) {
                ctx.strokeStyle = &apos;#007bff&apos;;
                ctx.lineWidth = 3;
            ctx.beginPath();
            first = true;
                for (let x = -8; x &lt;= 8; x += 0.05) {
                const lagrangian = x * x + lambda * (x - 1);
                const screenX = centerX + x * scale;
                const screenY = centerY - lagrangian * scale / 4;
                    if (screenY &gt;= -50 &amp;&amp; screenY &lt;= canvas.height + 50 &amp;&amp; screenX &gt;= 0 &amp;&amp; screenX &lt;= canvas.width) {
                    if (first) {
                        ctx.moveTo(screenX, screenY);
                        first = false;
                    } else {
                        ctx.lineTo(screenX, screenY);
                    }
                }
            }
            ctx.stroke();
            
                // Calculate minimum point
            const minX = -lambda / 2;
            const minY = -lambda * lambda / 4 - lambda;
            const screenMinX = centerX + minX * scale;
            const screenMinY = centerY - minY * scale / 4;
            
                // Draw vertical line from minimum to x-axis
            if (screenMinY &gt;= 0 &amp;&amp; screenMinY &lt;= canvas.height) {
                    ctx.strokeStyle = &apos;#007bff&apos;;
                    ctx.lineWidth = 1;
                    ctx.setLineDash([3, 3]);
                ctx.beginPath();
                    ctx.moveTo(screenMinX, screenMinY);
                    ctx.lineTo(screenMinX, centerY);
                    ctx.stroke();
                    ctx.setLineDash([]);
                    
                    // Mark minimum point with glow effect
                    ctx.shadowBlur = 10;
                    ctx.shadowColor = &apos;#007bff&apos;;
                    ctx.fillStyle = &apos;#007bff&apos;;
                    ctx.beginPath();
                    ctx.arc(screenMinX, screenMinY, 7, 0, 2 * Math.PI);
                ctx.fill();
                    ctx.shadowBlur = 0;
                    
                    // Add label for minimum
                    ctx.fillStyle = &apos;#007bff&apos;;
                    ctx.font = &apos;bold 13px Arial&apos;;
                    ctx.textAlign = &apos;center&apos;;
                    ctx.fillText(`x* = ${minX.toFixed(2)}`, screenMinX, centerY + 35);
                    ctx.fillText(`g(λ) = ${minY.toFixed(2)}`, screenMinX, screenMinY - 15);
                }
                
                // Update dual value display
                dualValueSpan.textContent = `g(${lambda.toFixed(2)}) = ${minY.toFixed(3)}`;
                
                // Update lower bound info
                if (minY &lt;= 0) {
                    lowerBoundInfo.textContent = `✓ g(λ) = ${minY.toFixed(3)} ≤ p* = 0 (cận dưới hợp lệ)`;
                    lowerBoundInfo.style.color = &apos;#28a745&apos;;
                } else {
                    lowerBoundInfo.textContent = `⚠ Cận dưới không chặt`;
                    lowerBoundInfo.style.color = &apos;#ffc107&apos;;
                }
            } else {
                dualValueSpan.textContent = &apos;g(0) = 0&apos;;
                lowerBoundInfo.textContent = &apos;Kéo thanh trượt để thấy hàm Lagrangian&apos;;
                lowerBoundInfo.style.color = &apos;#666&apos;;
        }
        
        // Draw constraint boundary x = 1
            ctx.strokeStyle = &apos;#dc3545&apos;;
            ctx.lineWidth = 3;
            ctx.setLineDash([8, 4]);
        ctx.beginPath();
        ctx.moveTo(centerX + scale, 0);
        ctx.lineTo(centerX + scale, canvas.height);
        ctx.stroke();
        ctx.setLineDash([]);
        
            // Mark optimal point (x=1, f(1)=1)
            const optX = 1;
            const optY = 1;
            const screenOptX = centerX + optX * scale;
            const screenOptY = centerY - optY * scale / 4;
            
            ctx.shadowBlur = 15;
            ctx.shadowColor = &apos;#dc3545&apos;;
            ctx.fillStyle = &apos;#dc3545&apos;;
        ctx.beginPath();
            ctx.arc(screenOptX, screenOptY, 8, 0, 2 * Math.PI);
        ctx.fill();
            ctx.shadowBlur = 0;
            
            // Draw legend box
            const legendX = 20;
            const legendY = 20;
            const legendWidth = 250;
            const legendHeight = 115;
            
            ctx.fillStyle = &apos;rgba(255, 255, 255, 0.95)&apos;;
            ctx.strokeStyle = &apos;#dee2e6&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.roundRect(legendX, legendY, legendWidth, legendHeight, 5);
            ctx.fill();
            ctx.stroke();
            
            // Legend content
            let yPos = legendY + 25;
            ctx.textAlign = &apos;left&apos;;
            
            // Original function
            ctx.strokeStyle = &apos;#212529&apos;;
            ctx.lineWidth = 3;
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 40, yPos);
            ctx.stroke();
            ctx.fillStyle = &apos;#212529&apos;;
        ctx.font = &apos;14px Arial&apos;;
            ctx.fillText(&apos;f(x) = x²&apos;, legendX + 50, yPos + 5);
            
            yPos += 25;
            
            // Lagrangian
            if (lambda &gt; 0.01) {
                ctx.strokeStyle = &apos;#007bff&apos;;
                ctx.lineWidth = 3;
                ctx.beginPath();
                ctx.moveTo(legendX + 10, yPos);
                ctx.lineTo(legendX + 40, yPos);
                ctx.stroke();
                ctx.fillStyle = &apos;#007bff&apos;;
                ctx.fillText(`L(x,λ) = x² + λ(x-1)`, legendX + 50, yPos + 5);
                yPos += 25;
            }
            
            // Constraint
            ctx.strokeStyle = &apos;#dc3545&apos;;
            ctx.lineWidth = 3;
            ctx.setLineDash([8, 4]);
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 40, yPos);
            ctx.stroke();
            ctx.setLineDash([]);
            ctx.fillStyle = &apos;#dc3545&apos;;
            ctx.fillText(&apos;Ràng buộc: x ≤ 1&apos;, legendX + 50, yPos + 5);
            
            yPos += 25;
            
            // Optimal point
            ctx.fillStyle = &apos;#dc3545&apos;;
            ctx.beginPath();
            ctx.arc(legendX + 25, yPos, 6, 0, 2 * Math.PI);
            ctx.fill();
            ctx.fillStyle = &apos;#dc3545&apos;;
            ctx.fillText(&apos;Nghiệm tối ưu: p* = 0&apos;, legendX + 50, yPos + 5);
        }
        
        // Debounce function for smoother performance
        let debounceTimer;
        function debouncedDraw() {
            clearTimeout(debounceTimer);
            debounceTimer = setTimeout(drawVisualization, 10);
        }
        
        slider.addEventListener(&apos;input&apos;, debouncedDraw);
    drawVisualization();
    }
})();
&lt;/script&gt;

&lt;p&gt;&lt;strong&gt;Hình 1:&lt;/strong&gt; &lt;em&gt;Hàm Lagrangian và hàm đối ngẫu. Đường cong đen biểu thị hàm mục tiêu gốc, các đường cong xanh dương và xanh lá biểu thị hàm Lagrangian khi thêm nhiễu động. Có thể thấy giá trị \(\inf_{x \in \mathcal{D}} L(x, \lambda)\) (điểm cực tiểu của các đường cong xanh dương và xanh lá) luôn nhỏ hơn hoặc bằng giá trị tối ưu gốc \(p^*\).&lt;/em&gt;&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;img src=&quot;/img/chapter_img/chapter11/lagrangian_function_example.svg&quot; alt=&quot;Lagrangian Function Example&quot; style=&quot;max-width: 100%; height: auto;&quot; /&gt;
    &lt;p&gt;&lt;em&gt;Nguồn: &lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Zhiliang Zhou&apos;s Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;-vì-sao-nên-giải-bài-toán-đối-ngẫu&quot;&gt;🎯 Vì sao nên giải bài toán đối ngẫu?&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Câu hỏi:&lt;/strong&gt; Vì sao ta giải bài toán đối ngẫu để tìm cận dưới? Bài toán này có dễ giải hơn không?&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Trả lời:&lt;/strong&gt; Có, về mặt cấu trúc toán học nó luôn là bài toán tối ưu lồi.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thật vậy, hàm đối ngẫu \(g(\lambda)\) luôn là hàm &lt;strong&gt;lõm (concave)&lt;/strong&gt;, tức \(-g(\lambda)\) là hàm &lt;strong&gt;lồi (convex)&lt;/strong&gt;. Từ định nghĩa của \(g(\lambda)\), ta thấy \(-g(\lambda)\) là supremum theo từng điểm của một họ các hàm affine theo \(\lambda\), do đó luôn lồi.&lt;/p&gt;

&lt;div id=&quot;dual-function-visualization&quot; style=&quot;margin: 20px 0; padding: 20px; background: #f8f9fa; border-radius: 10px;&quot;&gt;
    &lt;canvas id=&quot;dualCanvas&quot; width=&quot;800&quot; height=&quot;450&quot; style=&quot;border: 2px solid #dee2e6; display: block; margin: 0 auto; background: white; border-radius: 5px;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin-top: 15px;&quot;&gt;
        &lt;button id=&quot;animateSupremum&quot; style=&quot;padding: 10px 25px; font-size: 16px; background: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.2);&quot;&gt;
            ▶ Chạy Animation
        &lt;/button&gt;
        &lt;button id=&quot;resetSupremum&quot; style=&quot;padding: 10px 25px; font-size: 16px; background: #6c757d; color: white; border: none; border-radius: 5px; cursor: pointer; margin-left: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.2);&quot;&gt;
            🔄 Reset
        &lt;/button&gt;
    &lt;/div&gt;
    &lt;div style=&quot;margin-top: 15px; padding: 15px; background: white; border-radius: 5px; border-left: 4px solid #007bff;&quot;&gt;
        &lt;p style=&quot;margin: 0; font-size: 14px; color: #666;&quot;&gt;
            &lt;strong&gt;Giải thích:&lt;/strong&gt; Hàm dual -g(λ) là supremum theo từng điểm của tập các hàm affine, 
            do đó nó là hàm lồi. Điều này có nghĩa là bài toán dual luôn lồi, bất kể bài toán gốc có lồi hay không.
        &lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    if (document.readyState === &apos;loading&apos;) {
        document.addEventListener(&apos;DOMContentLoaded&apos;, initDualViz);
    } else {
        initDualViz();
    }
    
    function initDualViz() {
    const canvas = document.getElementById(&apos;dualCanvas&apos;);
        if (!canvas) return;
        
    const ctx = canvas.getContext(&apos;2d&apos;);
        const animateBtn = document.getElementById(&apos;animateSupremum&apos;);
        const resetBtn = document.getElementById(&apos;resetSupremum&apos;);
        
        let animationProgress = 0;
        let isAnimating = false;
        let animationId = null;
        
        const affineFunctions = [
            { a: -2, b: 3.5, color: &apos;#ff6b6b&apos;, label: &apos;f₁&apos; },
            { a: -1, b: 3, color: &apos;#4ecdc4&apos;, label: &apos;f₂&apos; },
            { a: 0, b: 2.5, color: &apos;#45b7d1&apos;, label: &apos;f₃&apos; },
            { a: 1, b: 2, color: &apos;#96ceb4&apos;, label: &apos;f₄&apos; },
            { a: 2, b: 1.5, color: &apos;#ffeaa7&apos;, label: &apos;f₅&apos; }
        ];
        
        function drawDualVisualization(progress = 1) {
        // Clear canvas
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Set up coordinate system
            const margin = 80;
            const centerX = margin;
            const centerY = canvas.height - margin;
            const scaleX = (canvas.width - margin - 40) / 5;
            const scaleY = 60;
            
            // Draw grid
            ctx.strokeStyle = &apos;#e9ecef&apos;;
        ctx.lineWidth = 1;
            ctx.setLineDash([2, 2]);
            for (let i = 0; i &lt;= 5; i++) {
                const x = centerX + i * scaleX;
                ctx.beginPath();
                ctx.moveTo(x, 0);
                ctx.lineTo(x, centerY);
                ctx.stroke();
            }
            for (let i = -2; i &lt;= 4; i++) {
                const y = centerY - i * scaleY;
                ctx.beginPath();
                ctx.moveTo(centerX, y);
                ctx.lineTo(canvas.width - 20, y);
                ctx.stroke();
            }
            ctx.setLineDash([]);
            
            // Draw axes
            ctx.strokeStyle = &apos;#495057&apos;;
            ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.moveTo(centerX, 0);
            ctx.lineTo(centerX, centerY);
            ctx.moveTo(centerX, centerY);
            ctx.lineTo(canvas.width - 20, centerY);
        ctx.stroke();
        
            // Draw axis labels
            ctx.fillStyle = &apos;#495057&apos;;
            ctx.font = &apos;bold 14px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            
            // X-axis labels
            for (let i = 0; i &lt;= 5; i++) {
                const x = centerX + i * scaleX;
                ctx.fillText(i.toString(), x, centerY + 25);
            }
            
            // Y-axis labels
            ctx.textAlign = &apos;right&apos;;
            for (let i = -2; i &lt;= 4; i++) {
                const y = centerY - i * scaleY;
                ctx.fillText(i.toString(), centerX - 10, y + 5);
            }
            
            // Axis names
            ctx.fillStyle = &apos;#212529&apos;;
            ctx.font = &apos;bold 18px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;λ&apos;, canvas.width - 10, centerY + 25);
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(&apos;-g(λ)&apos;, centerX - 50, 20);
            
            // Draw affine functions with animation
            const numFunctionsToShow = Math.ceil(progress * affineFunctions.length);
            
            for (let i = 0; i &lt; numFunctionsToShow; i++) {
                const func = affineFunctions[i];
                const alpha = (i &lt; numFunctionsToShow - 1) ? 1 : (progress * affineFunctions.length - i);
                
                ctx.strokeStyle = func.color;
                ctx.globalAlpha = alpha;
                ctx.lineWidth = 2;
            ctx.beginPath();
            
                let first = true;
                for (let lambda = 0; lambda &lt;= 5; lambda += 0.05) {
                    const y = func.a * lambda + func.b;
                const screenX = centerX + lambda * scaleX;
                const screenY = centerY - y * scaleY;
                
                    if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height) {
                        if (first) {
                    ctx.moveTo(screenX, screenY);
                            first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                        }
                }
            }
            ctx.stroke();
                
                // Draw function label
                const labelX = centerX + 4.5 * scaleX;
                const labelY = centerY - (func.a * 4.5 + func.b) * scaleY;
                if (labelY &gt;= 0 &amp;&amp; labelY &lt;= canvas.height) {
                    ctx.fillStyle = func.color;
                    ctx.font = &apos;bold 14px Arial&apos;;
                    ctx.textAlign = &apos;left&apos;;
                    ctx.fillText(func.label, labelX + 10, labelY + 5);
                }
            }
            
            ctx.globalAlpha = 1;
            
            // Draw pointwise supremum (envelope) if animation is complete
            if (progress &gt;= 0.9) {
                const envelopeAlpha = (progress - 0.9) / 0.1;
                ctx.globalAlpha = envelopeAlpha;
                
                ctx.strokeStyle = &apos;#dc3545&apos;;
                ctx.lineWidth = 4;
                ctx.shadowBlur = 10;
                ctx.shadowColor = &apos;#dc3545&apos;;
        ctx.beginPath();
        
                let first = true;
                const supremumPoints = [];
                
                for (let lambda = 0; lambda &lt;= 5; lambda += 0.02) {
            let maxY = -Infinity;
                    for (const func of affineFunctions) {
                        const y = func.a * lambda + func.b;
                maxY = Math.max(maxY, y);
            }
                    
                    supremumPoints.push({ lambda, y: maxY });
            
            const screenX = centerX + lambda * scaleX;
            const screenY = centerY - maxY * scaleY;
            
                    if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height) {
                        if (first) {
                ctx.moveTo(screenX, screenY);
                            first = false;
            } else {
                ctx.lineTo(screenX, screenY);
                        }
            }
        }
        ctx.stroke();
                ctx.shadowBlur = 0;
                
                // Highlight some key points on the envelope
                if (envelopeAlpha &gt; 0.5) {
                    const keyLambdas = [0.5, 1.5, 2.5, 3.5, 4.5];
                    for (const lambda of keyLambdas) {
                        let maxY = -Infinity;
                        for (const func of affineFunctions) {
                            const y = func.a * lambda + func.b;
                            maxY = Math.max(maxY, y);
                        }
                        
                        const screenX = centerX + lambda * scaleX;
                        const screenY = centerY - maxY * scaleY;
                        
                        if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height) {
                            ctx.fillStyle = &apos;#dc3545&apos;;
                            ctx.beginPath();
                            ctx.arc(screenX, screenY, 5, 0, 2 * Math.PI);
                            ctx.fill();
                        }
                    }
                }
                
                ctx.globalAlpha = 1;
                
                // Add annotation
                ctx.fillStyle = &apos;#dc3545&apos;;
                ctx.font = &apos;bold 16px Arial&apos;;
                ctx.textAlign = &apos;left&apos;;
                ctx.fillText(&apos;Supremum theo từng điểm&apos;, 200, 30);
        ctx.font = &apos;14px Arial&apos;;
                ctx.fillText(&apos;(Đường bao lồi)&apos;, 200, 50);
            }
            
            // Draw legend
            const legendX = canvas.width - 180;
            const legendY = 80;
            const legendWidth = 160;
            const legendHeight = 80;
            
            ctx.fillStyle = &apos;rgba(255, 255, 255, 0.95)&apos;;
            ctx.strokeStyle = &apos;#dee2e6&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.roundRect(legendX, legendY, legendWidth, legendHeight, 5);
            ctx.fill();
            ctx.stroke();
            
            // Legend title
            ctx.fillStyle = &apos;#212529&apos;;
            ctx.font = &apos;bold 14px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;Hàm Affine&apos;, legendX + legendWidth/2, legendY + 20);
            
            // Legend items
            ctx.font = &apos;12px Arial&apos;;
            ctx.textAlign = &apos;left&apos;;
            for (let i = 0; i &lt; Math.min(3, numFunctionsToShow); i++) {
                const func = affineFunctions[i];
                const yPos = legendY + 40 + i * 15;
                
                ctx.strokeStyle = func.color;
                ctx.lineWidth = 2;
                ctx.beginPath();
                ctx.moveTo(legendX + 10, yPos);
                ctx.lineTo(legendX + 30, yPos);
                ctx.stroke();
                
                ctx.fillStyle = &apos;#495057&apos;;
                ctx.fillText(`${func.a}λ + ${func.b}`, legendX + 35, yPos + 4);
            }
        }
        
        function animate() {
            if (!isAnimating) return;
            
            animationProgress += 0.008;
            if (animationProgress &gt;= 1) {
                animationProgress = 1;
                isAnimating = false;
                animateBtn.innerHTML = &apos;▶ Chạy Lại&apos;;
                animateBtn.style.background = &apos;#28a745&apos;;
            }
            
            drawDualVisualization(animationProgress);
            
            if (isAnimating) {
                animationId = requestAnimationFrame(animate);
            }
        }
        
        animateBtn.addEventListener(&apos;click&apos;, function() {
            if (animationProgress &gt;= 1) {
                animationProgress = 0;
            }
            
            if (isAnimating) {
                isAnimating = false;
                if (animationId) cancelAnimationFrame(animationId);
                animateBtn.innerHTML = &apos;▶ Tiếp Tục&apos;;
                animateBtn.style.background = &apos;#007bff&apos;;
            } else {
                isAnimating = true;
                animateBtn.innerHTML = &apos;⏸ Tạm Dừng&apos;;
                animateBtn.style.background = &apos;#ffc107&apos;;
                animate();
            }
        });
        
        resetBtn.addEventListener(&apos;click&apos;, function() {
            isAnimating = false;
            if (animationId) cancelAnimationFrame(animationId);
            animationProgress = 0;
            animateBtn.innerHTML = &apos;▶ Chạy Animation&apos;;
            animateBtn.style.background = &apos;#007bff&apos;;
            drawDualVisualization(0);
        });
        
        // Initial draw
        drawDualVisualization(1);
    }
})();
&lt;/script&gt;

&lt;p&gt;&lt;strong&gt;Hình 2:&lt;/strong&gt; &lt;em&gt;Supremum theo từng điểm của tập các hàm affine là hàm lồi&lt;/em&gt;&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;img src=&quot;/img/chapter_img/chapter11/pointwise_supremum_convex.svg&quot; alt=&quot;Pointwise Supremum of Affine Functions&quot; style=&quot;max-width: 100%; height: auto;&quot; /&gt;
    &lt;p&gt;&lt;em&gt;Nguồn: &lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Zhiliang Zhou&apos;s Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hình 2 minh họa một họ các hàm affine và đường màu đỏ là supremum theo từng điểm của chúng — rõ ràng là một hàm lồi. Với hàm mục tiêu và tập ràng buộc lồi, cực trị địa phương cũng là cực trị toàn cục. Nhờ đó, bất kể \(f(x)\) có lồi hay không, hàm đối ngẫu \(g(\lambda)\) luôn lõm.&lt;/p&gt;

&lt;h2 id=&quot;-kết-nối-với-hàm-liên-hợp-conjugate-function&quot;&gt;🔗 Kết nối với hàm liên hợp (Conjugate Function)&lt;/h2&gt;

&lt;p&gt;Khi các ràng buộc trong bài toán gốc là tuyến tính, hàm đối ngẫu liên hệ trực tiếp với hàm liên hợp (conjugate function).&lt;/p&gt;

&lt;h3 id=&quot;-hàm-liên-hợp&quot;&gt;📐 Hàm liên hợp&lt;/h3&gt;

&lt;p&gt;Hàm liên hợp của \(f(x)\) được định nghĩa là:&lt;/p&gt;

\[f^*(λ) = \sup_x (λ^T x - f(x))\]

&lt;div id=&quot;conjugate-visualization&quot; style=&quot;margin: 20px 0; padding: 20px; background: #f8f9fa; border-radius: 10px;&quot;&gt;
    &lt;canvas id=&quot;conjugateCanvas&quot; width=&quot;900&quot; height=&quot;550&quot; style=&quot;border: 2px solid #dee2e6; display: block; margin: 0 auto; background: white; border-radius: 5px;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin: 15px 0;&quot;&gt;
        &lt;div style=&quot;display: inline-block; padding: 10px 20px; background: white; border-radius: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
            &lt;label style=&quot;font-size: 18px; font-weight: bold;&quot;&gt;Độ dốc λ = &lt;span id=&quot;slopeValue&quot; style=&quot;color: #6f42c1;&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
            &lt;input type=&quot;range&quot; id=&quot;slopeSlider&quot; min=&quot;-4&quot; max=&quot;4&quot; step=&quot;0.05&quot; value=&quot;1&quot; style=&quot;width: 400px; margin-top: 10px;&quot; /&gt;
            &lt;div style=&quot;margin-top: 10px; font-size: 14px; color: #666;&quot;&gt;
                &lt;span&gt;Thay đổi độ dốc của đường thẳng λx&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div id=&quot;conjugateInfo&quot; style=&quot;text-align: center; margin-top: 15px; padding: 15px; background: white; border-radius: 5px; border-left: 4px solid #6f42c1;&quot;&gt;
        &lt;p style=&quot;margin: 5px 0; font-size: 16px;&quot;&gt;&lt;strong&gt;Hàm liên hợp:&lt;/strong&gt; &lt;span id=&quot;conjugateValue&quot; style=&quot;color: #6f42c1; font-weight: bold;&quot;&gt;f*(1.0) = 0.50&lt;/span&gt;&lt;/p&gt;
        &lt;p style=&quot;margin: 5px 0; font-size: 14px; color: #666;&quot;&gt;&lt;span id=&quot;conjugateExplanation&quot;&gt;Khoảng cách lớn nhất giữa λx và f(x)&lt;/span&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    if (document.readyState === &apos;loading&apos;) {
        document.addEventListener(&apos;DOMContentLoaded&apos;, initConjugateViz);
    } else {
        initConjugateViz();
    }
    
    function initConjugateViz() {
    const canvas = document.getElementById(&apos;conjugateCanvas&apos;);
        if (!canvas) return;
        
    const ctx = canvas.getContext(&apos;2d&apos;);
    const slider = document.getElementById(&apos;slopeSlider&apos;);
    const valueSpan = document.getElementById(&apos;slopeValue&apos;);
        const conjugateValueSpan = document.getElementById(&apos;conjugateValue&apos;);
        const explanationSpan = document.getElementById(&apos;conjugateExplanation&apos;);
        
        function drawGrid(centerX, centerY, scale) {
            ctx.strokeStyle = &apos;#f1f3f5&apos;;
            ctx.lineWidth = 1;
            ctx.setLineDash([2, 2]);
            
            // Vertical grid
            for (let x = -10; x &lt;= 10; x++) {
                if (x === 0) continue;
                const screenX = centerX + x * scale;
                if (screenX &gt;= 0 &amp;&amp; screenX &lt;= canvas.width) {
                    ctx.beginPath();
                    ctx.moveTo(screenX, 0);
                    ctx.lineTo(screenX, canvas.height);
                    ctx.stroke();
                }
            }
            
            // Horizontal grid
            for (let y = -5; y &lt;= 15; y++) {
                if (y === 0) continue;
                const screenY = centerY - y * scale;
                if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height) {
                    ctx.beginPath();
                    ctx.moveTo(0, screenY);
                    ctx.lineTo(canvas.width, screenY);
                    ctx.stroke();
                }
            }
            
            ctx.setLineDash([]);
        }
        
        function drawAxes(centerX, centerY, scale) {
            // Axes
            ctx.strokeStyle = &apos;#495057&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.moveTo(0, centerY);
            ctx.lineTo(canvas.width, centerY);
            ctx.moveTo(centerX, 0);
            ctx.lineTo(centerX, canvas.height);
            ctx.stroke();
            
            // Axis labels
            ctx.fillStyle = &apos;#495057&apos;;
            ctx.font = &apos;bold 13px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            
            // X-axis
            for (let x = -10; x &lt;= 10; x += 2) {
                if (x === 0) continue;
                const screenX = centerX + x * scale;
                if (screenX &gt;= 0 &amp;&amp; screenX &lt;= canvas.width) {
                    ctx.fillText(x.toString(), screenX, centerY + 20);
                }
            }
            
            // Y-axis
            ctx.textAlign = &apos;right&apos;;
            for (let y = -4; y &lt;= 14; y += 2) {
                if (y === 0) continue;
                const screenY = centerY - y * scale;
                if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height) {
                    ctx.fillText(y.toString(), centerX - 10, screenY + 5);
                }
            }
            
            // Axis names
            ctx.font = &apos;bold 16px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;x&apos;, canvas.width - 20, centerY - 10);
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(&apos;y&apos;, centerX + 10, 20);
        }
    
    function drawConjugateVisualization() {
        const slope = parseFloat(slider.value);
            valueSpan.textContent = slope.toFixed(2);
        
        // Clear canvas
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Set up coordinate system
        const centerX = canvas.width / 2;
            const centerY = canvas.height * 0.75;
            const scale = 35;
            
            // Draw grid
            drawGrid(centerX, centerY, scale);
        
        // Draw axes
            drawAxes(centerX, centerY, scale);
        
        // Draw function f(x) = x^2/2
            ctx.strokeStyle = &apos;#20c997&apos;;
            ctx.lineWidth = 4;
            ctx.shadowBlur = 5;
            ctx.shadowColor = &apos;#20c997&apos;;
        ctx.beginPath();
        let first = true;
            for (let x = -10; x &lt;= 10; x += 0.05) {
            const y = x * x / 2;
            const screenX = centerX + x * scale;
            const screenY = centerY - y * scale;
                if (screenY &gt;= -10 &amp;&amp; screenY &lt;= canvas.height &amp;&amp; screenX &gt;= 0 &amp;&amp; screenX &lt;= canvas.width) {
                if (first) {
                    ctx.moveTo(screenX, screenY);
                    first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
            ctx.shadowBlur = 0;
        
        // Draw line λx with given slope
            ctx.strokeStyle = &apos;#6f42c1&apos;;
            ctx.lineWidth = 3;
        ctx.beginPath();
            first = true;
            for (let x = -10; x &lt;= 10; x += 0.1) {
            const y = slope * x;
            const screenX = centerX + x * scale;
            const screenY = centerY - y * scale;
                if (screenY &gt;= -10 &amp;&amp; screenY &lt;= canvas.height + 10 &amp;&amp; screenX &gt;= -10 &amp;&amp; screenX &lt;= canvas.width + 10) {
                    if (first) {
                    ctx.moveTo(screenX, screenY);
                        first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
        
        // Find and mark the point where λx - f(x) is maximized
        let maxDiff = -Infinity;
        let maxX = 0;
            for (let x = -10; x &lt;= 10; x += 0.01) {
            const diff = slope * x - x * x / 2;
            if (diff &gt; maxDiff) {
                maxDiff = diff;
                maxX = x;
            }
        }
        
            const conjugateValue = slope * slope / 2;
            
            // Draw tangent line at optimal point (parallel to λx)
            ctx.strokeStyle = &apos;#fd7e14&apos;;
            ctx.lineWidth = 3;
            ctx.setLineDash([8, 4]);
            ctx.shadowBlur = 5;
            ctx.shadowColor = &apos;#fd7e14&apos;;
            ctx.beginPath();
            first = true;
            for (let x = -10; x &lt;= 10; x += 0.1) {
                const y = slope * x - conjugateValue;
            const screenX = centerX + x * scale;
            const screenY = centerY - y * scale;
                if (screenY &gt;= -10 &amp;&amp; screenY &lt;= canvas.height + 10 &amp;&amp; screenX &gt;= -10 &amp;&amp; screenX &lt;= canvas.width + 10) {
                    if (first) {
                    ctx.moveTo(screenX, screenY);
                        first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
        ctx.setLineDash([]);
            ctx.shadowBlur = 0;
            
            // Mark tangent point on f(x)
            const tangentY = maxX * maxX / 2;
            const tangentScreenX = centerX + maxX * scale;
            const tangentScreenY = centerY - tangentY * scale;
            
            if (tangentScreenY &gt;= 0 &amp;&amp; tangentScreenY &lt;= canvas.height) {
                // Draw vertical line to show the contact point
                ctx.strokeStyle = &apos;#e63946&apos;;
                ctx.lineWidth = 2;
                ctx.setLineDash([3, 3]);
        ctx.beginPath();
                ctx.moveTo(tangentScreenX, tangentScreenY);
                ctx.lineTo(tangentScreenX, centerY);
                ctx.stroke();
                ctx.setLineDash([]);
                
                // Mark point with glow
                ctx.shadowBlur = 15;
                ctx.shadowColor = &apos;#e63946&apos;;
                ctx.fillStyle = &apos;#e63946&apos;;
                ctx.beginPath();
                ctx.arc(tangentScreenX, tangentScreenY, 8, 0, 2 * Math.PI);
        ctx.fill();
                ctx.shadowBlur = 0;
                
                // Label the contact point
                ctx.fillStyle = &apos;#e63946&apos;;
                ctx.font = &apos;bold 14px Arial&apos;;
                ctx.textAlign = &apos;center&apos;;
                ctx.fillText(`x* = ${maxX.toFixed(2)}`, tangentScreenX, centerY + 35);
            }
            
            // Draw vertical distance visualization (f*(λ))
            if (Math.abs(maxX) &lt;= 10 &amp;&amp; tangentScreenY &gt;= 0) {
                const lineY = slope * maxX;
                const lineScreenY = centerY - lineY * scale;
                
                if (lineScreenY &gt;= 0 &amp;&amp; lineScreenY &lt;= canvas.height) {
                    // Draw vertical arrow showing the distance
                    ctx.strokeStyle = &apos;#6f42c1&apos;;
                    ctx.fillStyle = &apos;#6f42c1&apos;;
                    ctx.lineWidth = 3;
                    
                    // Draw arrow
                    const arrowX = tangentScreenX + 50;
                    ctx.beginPath();
                    ctx.moveTo(arrowX, tangentScreenY);
                    ctx.lineTo(arrowX, lineScreenY);
                    ctx.stroke();
                    
                    // Arrowheads
                    ctx.beginPath();
                    ctx.moveTo(arrowX - 5, tangentScreenY + 10);
                    ctx.lineTo(arrowX, tangentScreenY);
                    ctx.lineTo(arrowX + 5, tangentScreenY + 10);
                    ctx.fill();
                    
                    ctx.beginPath();
                    ctx.moveTo(arrowX - 5, lineScreenY - 10);
                    ctx.lineTo(arrowX, lineScreenY);
                    ctx.lineTo(arrowX + 5, lineScreenY - 10);
                    ctx.fill();
                    
                    // Label the distance
                    const midY = (tangentScreenY + lineScreenY) / 2;
                    ctx.font = &apos;bold 14px Arial&apos;;
                    ctx.textAlign = &apos;left&apos;;
                    ctx.fillText(`f*(λ) = ${conjugateValue.toFixed(2)}`, arrowX + 10, midY + 5);
                }
            }
            
            // Update info display
            conjugateValueSpan.textContent = `f*(${slope.toFixed(2)}) = ${conjugateValue.toFixed(3)}`;
            explanationSpan.textContent = `Tại x* = ${maxX.toFixed(2)}, khoảng cách λx - f(x) đạt cực đại = ${conjugateValue.toFixed(3)}`;
            
            // Draw legend box
            const legendX = 20;
            const legendY = 20;
            const legendWidth = 280;
            const legendHeight = 135;
            
            ctx.fillStyle = &apos;rgba(255, 255, 255, 0.95)&apos;;
            ctx.strokeStyle = &apos;#dee2e6&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.roundRect(legendX, legendY, legendWidth, legendHeight, 5);
            ctx.fill();
            ctx.stroke();
            
            // Legend content
            let yPos = legendY + 25;
            ctx.textAlign = &apos;left&apos;;
            
            // f(x)
            ctx.strokeStyle = &apos;#20c997&apos;;
            ctx.lineWidth = 3;
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 45, yPos);
            ctx.stroke();
            ctx.fillStyle = &apos;#20c997&apos;;
            ctx.font = &apos;15px Arial&apos;;
            ctx.fillText(&apos;f(x) = x²/2&apos;, legendX + 55, yPos + 5);
            yPos += 28;
            
            // λx
            ctx.strokeStyle = &apos;#6f42c1&apos;;
            ctx.lineWidth = 3;
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 45, yPos);
            ctx.stroke();
            ctx.fillStyle = &apos;#6f42c1&apos;;
            ctx.fillText(`λx (λ = ${slope.toFixed(2)})`, legendX + 55, yPos + 5);
            yPos += 28;
            
            // Tangent
            ctx.strokeStyle = &apos;#fd7e14&apos;;
            ctx.lineWidth = 3;
            ctx.setLineDash([8, 4]);
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 45, yPos);
            ctx.stroke();
            ctx.setLineDash([]);
            ctx.fillStyle = &apos;#fd7e14&apos;;
            ctx.fillText(&apos;Đường tiếp xúc&apos;, legendX + 55, yPos + 5);
            yPos += 28;
            
            // Contact point
            ctx.fillStyle = &apos;#e63946&apos;;
            ctx.beginPath();
            ctx.arc(legendX + 27, yPos - 3, 6, 0, 2 * Math.PI);
            ctx.fill();
            ctx.fillStyle = &apos;#e63946&apos;;
            ctx.fillText(&apos;Điểm tiếp xúc&apos;, legendX + 55, yPos + 2);
        }
        
        // Debounce for performance
        let debounceTimer;
        function debouncedDraw() {
            clearTimeout(debounceTimer);
            debounceTimer = setTimeout(drawConjugateVisualization, 5);
        }
        
        slider.addEventListener(&apos;input&apos;, debouncedDraw);
    drawConjugateVisualization();
    }
})();
&lt;/script&gt;

&lt;p&gt;&lt;strong&gt;Hình 3:&lt;/strong&gt; &lt;em&gt;Minh họa hình học hàm liên hợp. Đường cong xanh lá biểu thị \(f(x)\), đường thẳng đen biểu thị \(\lambda^T x\), và độ chênh lệch có dấu theo phương thẳng đứng là \(\lambda^T x - f(x)\). Hàm liên hợp \(f^*(\lambda)\) chính là giá trị lớn nhất của khoảng cách có dấu này.&lt;/em&gt;&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;img src=&quot;/img/chapter_img/chapter11/conjugate_function_geometric.svg&quot; alt=&quot;Conjugate Function Geometric Interpretation&quot; style=&quot;max-width: 100%; height: auto;&quot; /&gt;
    &lt;p&gt;&lt;em&gt;Nguồn: &lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Zhiliang Zhou&apos;s Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;-khi-ràng-buộc-là-tuyến-tính&quot;&gt;🔄 Khi ràng buộc là tuyến tính&lt;/h3&gt;

&lt;p&gt;Khi các ràng buộc là tuyến tính, bài toán tối ưu có dạng:&lt;/p&gt;

\[\min_x f(x) \quad \text{s.t. } Ax \preceq b\]

&lt;p&gt;Hàm dual Lagrange là:&lt;/p&gt;

\[\begin{align}
g(λ) &amp;amp;= \inf_x (f(x) + λ^T(Ax - b)) \quad \text{với } λ \succeq 0 \\
&amp;amp;= -\sup_x (-λ^T A x - f(x)) - λ^T b \\
&amp;amp;= -f^*(-λ^T A) - λ^T b \quad \text{theo phương trình (9)}
\end{align}\]

&lt;p&gt;Trong biểu thức trên, khi xét riêng số hạng \(-f^*(-\lambda^T A)\), việc cực đại hóa \(g(\lambda)\) gắn trực tiếp với việc cực tiểu hóa hàm liên hợp \(f^*(-\lambda^T A)\) cộng thêm số hạng tuyến tính \(\lambda^T b\).&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;img src=&quot;/img/chapter_img/chapter11/conjugate_minimum_example.svg&quot; alt=&quot;Minimum of Conjugate Function&quot; style=&quot;max-width: 100%; height: auto;&quot; /&gt;
    &lt;p&gt;&lt;em&gt;Hình 4: Minimum của hàm liên hợp - Nguồn: &lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Zhiliang Zhou&apos;s Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;-ví-dụ-tương-tác&quot;&gt;💻 Ví dụ tương tác&lt;/h2&gt;

&lt;p&gt;Hãy xem một ví dụ cụ thể với bài toán:&lt;/p&gt;

\[\min x^2 \quad \text{s.t. } x \leq 1\]

&lt;div id=&quot;complete-example&quot; style=&quot;margin: 20px 0; padding: 25px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.3);&quot;&gt;
    &lt;h4 style=&quot;color: white; text-align: center; margin-bottom: 20px; font-size: 22px; text-shadow: 2px 2px 4px rgba(0,0,0,0.3);&quot;&gt;🎬 Minh họa Tổng hợp: Primal-Dual Relationship&lt;/h4&gt;
    &lt;canvas id=&quot;completeCanvas&quot; width=&quot;1100&quot; height=&quot;600&quot; style=&quot;border: 3px solid white; display: block; margin: 0 auto; background: white; border-radius: 8px; box-shadow: 0 5px 15px rgba(0,0,0,0.3);&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
        &lt;button id=&quot;animateBtn&quot; style=&quot;padding: 12px 30px; font-size: 17px; background: #28a745; color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: bold; box-shadow: 0 4px 6px rgba(0,0,0,0.2); transition: all 0.3s;&quot;&gt;
            ▶ Chạy Animation
        &lt;/button&gt;
        &lt;button id=&quot;resetBtn&quot; style=&quot;padding: 12px 30px; font-size: 17px; background: #6c757d; color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: bold; margin-left: 15px; box-shadow: 0 4px 6px rgba(0,0,0,0.2); transition: all 0.3s;&quot;&gt;
            🔄 Reset
        &lt;/button&gt;
        &lt;div style=&quot;margin-top: 15px; padding: 10px 20px; background: rgba(255,255,255,0.9); border-radius: 8px; display: inline-block;&quot;&gt;
            &lt;span style=&quot;font-size: 18px; font-weight: bold; color: #495057;&quot;&gt;λ = &lt;span id=&quot;currentLambdaDisplay&quot; style=&quot;color: #007bff;&quot;&gt;0.00&lt;/span&gt;&lt;/span&gt;
            &lt;span style=&quot;margin: 0 15px; color: #dee2e6;&quot;&gt;|&lt;/span&gt;
            &lt;span style=&quot;font-size: 18px; font-weight: bold; color: #495057;&quot;&gt;g(λ) = &lt;span id=&quot;currentDualDisplay&quot; style=&quot;color: #dc3545;&quot;&gt;0.000&lt;/span&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;div id=&quot;explanation&quot; style=&quot;margin-top: 20px; padding: 20px; background: rgba(255,255,255,0.95); border-radius: 10px; box-shadow: 0 3px 10px rgba(0,0,0,0.2);&quot;&gt;
        &lt;p style=&quot;margin: 0 0 15px 0; font-size: 16px; font-weight: bold; color: #495057;&quot;&gt;📖 Hướng dẫn đọc biểu đồ:&lt;/p&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 15px; font-size: 14px; line-height: 1.8;&quot;&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #212529;&quot;&gt;
                &lt;span style=&quot;color: #212529; font-weight: bold;&quot;&gt;● Đường đen đậm:&lt;/span&gt; Hàm mục tiêu f(x) = x²
            &lt;/div&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #007bff;&quot;&gt;
                &lt;span style=&quot;color: #007bff; font-weight: bold;&quot;&gt;● Đường xanh dương:&lt;/span&gt; Hàm Lagrangian L(x,λ)
            &lt;/div&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #dc3545;&quot;&gt;
                &lt;span style=&quot;color: #dc3545; font-weight: bold;&quot;&gt;⊥ Đường đỏ đứt:&lt;/span&gt; Ràng buộc x ≤ 1
            &lt;/div&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #ff0000;&quot;&gt;
                &lt;span style=&quot;color: #ff0000; font-weight: bold;&quot;&gt;◉ Điểm đỏ lớn:&lt;/span&gt; Nghiệm tối ưu p* = 0
            &lt;/div&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #007bff;&quot;&gt;
                &lt;span style=&quot;color: #007bff; font-weight: bold;&quot;&gt;◉ Điểm xanh:&lt;/span&gt; Min của L(x,λ) → g(λ)
            &lt;/div&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #28a745;&quot;&gt;
                &lt;span style=&quot;color: #28a745; font-weight: bold;&quot;&gt;📊 Đường cong phải:&lt;/span&gt; Hàm dual g(λ)
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;margin-top: 15px; padding: 12px; background: #fff3cd; border-left: 4px solid #ffc107; border-radius: 5px;&quot;&gt;
            &lt;p style=&quot;margin: 0; color: #856404; font-size: 14px;&quot;&gt;
                &lt;strong&gt;💡 Quan sát chính:&lt;/strong&gt; Khi λ tăng từ 0, điểm minimum của Lagrangian (xanh) di chuyển sang trái, 
                và giá trị g(λ) giảm xuống (cận dưới kém chặt hơn). Giá trị lớn nhất của g(λ) trên λ ≥ 0 (ở đây là tại λ = 0) cho ta cận dưới tốt nhất!
            &lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    if (document.readyState === &apos;loading&apos;) {
        document.addEventListener(&apos;DOMContentLoaded&apos;, initCompleteViz);
    } else {
        initCompleteViz();
    }
    
    function initCompleteViz() {
    const canvas = document.getElementById(&apos;completeCanvas&apos;);
        if (!canvas) return;
        
    const ctx = canvas.getContext(&apos;2d&apos;);
    const animateBtn = document.getElementById(&apos;animateBtn&apos;);
    const resetBtn = document.getElementById(&apos;resetBtn&apos;);
        const lambdaDisplay = document.getElementById(&apos;currentLambdaDisplay&apos;);
        const dualDisplay = document.getElementById(&apos;currentDualDisplay&apos;);
    
    let animationId = null;
    let currentLambda = 0;
    let isAnimating = false;
    
    function drawCompleteExample(lambda) {
        // Clear canvas
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
            // Set up panels
            const leftPanel = { x: 60, y: 60, width: 500, height: 450 };
            const rightPanel = { x: 600, y: 60, width: 450, height: 450 };
            
            // Draw panel backgrounds
            ctx.fillStyle = &apos;#f8f9fa&apos;;
            ctx.fillRect(leftPanel.x - 10, leftPanel.y - 10, leftPanel.width + 20, leftPanel.height + 20);
            ctx.fillRect(rightPanel.x - 10, rightPanel.y - 10, rightPanel.width + 20, rightPanel.height + 20);
            
            // Draw panels
            drawPrimalSpace(leftPanel, lambda);
        drawDualSpace(rightPanel, lambda);
        
            // Add panel titles
            ctx.fillStyle = &apos;#212529&apos;;
            ctx.font = &apos;bold 20px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;Không Gian Primal&apos;, leftPanel.x + leftPanel.width/2, leftPanel.y - 25);
            ctx.fillText(&apos;Không Gian Dual&apos;, rightPanel.x + rightPanel.width/2, rightPanel.y - 25);
            
            // Update displays
            lambdaDisplay.textContent = lambda.toFixed(2);
        const dualValue = -lambda * lambda / 4 - lambda;
            dualDisplay.textContent = dualValue.toFixed(3);
    }
    
    function drawPrimalSpace(panel, lambda) {
        const centerX = panel.x + panel.width / 2;
            const centerY = panel.y + panel.height - 70;
            const scale = 50;
        
            // Draw grid
            ctx.strokeStyle = &apos;#e9ecef&apos;;
        ctx.lineWidth = 1;
            ctx.setLineDash([2, 2]);
            for (let x = -4; x &lt;= 4; x++) {
                if (x === 0) continue;
                const screenX = centerX + x * scale;
                ctx.beginPath();
                ctx.moveTo(screenX, panel.y);
                ctx.lineTo(screenX, panel.y + panel.height);
                ctx.stroke();
            }
            for (let y = -2; y &lt;= 6; y++) {
                if (y === 0) continue;
                const screenY = centerY - y * scale / 2;
                ctx.beginPath();
                ctx.moveTo(panel.x, screenY);
                ctx.lineTo(panel.x + panel.width, screenY);
                ctx.stroke();
            }
            ctx.setLineDash([]);
            
            // Draw axes
            ctx.strokeStyle = &apos;#495057&apos;;
            ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.moveTo(panel.x, centerY);
        ctx.lineTo(panel.x + panel.width, centerY);
        ctx.moveTo(centerX, panel.y);
        ctx.lineTo(centerX, panel.y + panel.height);
        ctx.stroke();
            
            // Axis labels
            ctx.fillStyle = &apos;#495057&apos;;
            ctx.font = &apos;bold 13px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            for (let x = -4; x &lt;= 4; x += 2) {
                if (x === 0) continue;
                ctx.fillText(x.toString(), centerX + x * scale, centerY + 20);
            }
            ctx.font = &apos;bold 16px Arial&apos;;
            ctx.fillText(&apos;x&apos;, panel.x + panel.width - 15, centerY - 10);
            ctx.fillText(&apos;y&apos;, centerX + 15, panel.y + 20);
        
        // Draw original function f(x) = x^2
            ctx.strokeStyle = &apos;#212529&apos;;
            ctx.lineWidth = 4;
            ctx.shadowBlur = 5;
            ctx.shadowColor = &apos;#212529&apos;;
        ctx.beginPath();
        let first = true;
            for (let x = -4; x &lt;= 4; x += 0.05) {
            const y = x * x;
            const screenX = centerX + x * scale;
            const screenY = centerY - y * scale / 2;
            if (screenY &gt;= panel.y &amp;&amp; screenY &lt;= panel.y + panel.height) {
                if (first) {
                    ctx.moveTo(screenX, screenY);
                    first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
            ctx.shadowBlur = 0;
        
        // Draw Lagrangian if lambda &gt; 0
            if (lambda &gt; 0.01) {
                ctx.strokeStyle = &apos;#007bff&apos;;
                ctx.lineWidth = 3;
                ctx.shadowBlur = 5;
                ctx.shadowColor = &apos;#007bff&apos;;
            ctx.beginPath();
            first = true;
                for (let x = -4; x &lt;= 4; x += 0.05) {
                const lagrangian = x * x + lambda * (x - 1);
                const screenX = centerX + x * scale;
                const screenY = centerY - lagrangian * scale / 2;
                    if (screenY &gt;= panel.y - 20 &amp;&amp; screenY &lt;= panel.y + panel.height + 20) {
                    if (first) {
                        ctx.moveTo(screenX, screenY);
                        first = false;
                    } else {
                        ctx.lineTo(screenX, screenY);
                    }
                }
            }
            ctx.stroke();
                ctx.shadowBlur = 0;
            
            // Mark minimum of Lagrangian
            const minX = -lambda / 2;
            const minY = -lambda * lambda / 4 - lambda;
            const screenMinX = centerX + minX * scale;
            const screenMinY = centerY - minY * scale / 2;
            
            if (screenMinY &gt;= panel.y &amp;&amp; screenMinY &lt;= panel.y + panel.height) {
                    // Vertical line to axis
                    ctx.strokeStyle = &apos;#007bff&apos;;
                    ctx.lineWidth = 2;
                    ctx.setLineDash([3, 3]);
                ctx.beginPath();
                    ctx.moveTo(screenMinX, screenMinY);
                    ctx.lineTo(screenMinX, centerY);
                    ctx.stroke();
                    ctx.setLineDash([]);
                    
                    // Glow effect
                    ctx.shadowBlur = 15;
                    ctx.shadowColor = &apos;#007bff&apos;;
                    ctx.fillStyle = &apos;#007bff&apos;;
                    ctx.beginPath();
                    ctx.arc(screenMinX, screenMinY, 8, 0, 2 * Math.PI);
                ctx.fill();
                    ctx.shadowBlur = 0;
                    
                    // Label
                    ctx.fillStyle = &apos;#007bff&apos;;
                    ctx.font = &apos;bold 13px Arial&apos;;
                    ctx.textAlign = &apos;center&apos;;
                    ctx.fillText(`x*=${minX.toFixed(2)}`, screenMinX, screenMinY - 15);
                    ctx.fillText(`g(λ)=${minY.toFixed(2)}`, screenMinX, centerY + 35);
            }
        }
        
        // Draw constraint x = 1
            ctx.strokeStyle = &apos;#dc3545&apos;;
            ctx.lineWidth = 4;
            ctx.setLineDash([10, 5]);
            ctx.shadowBlur = 5;
            ctx.shadowColor = &apos;#dc3545&apos;;
        ctx.beginPath();
        ctx.moveTo(centerX + scale, panel.y);
        ctx.lineTo(centerX + scale, panel.y + panel.height);
        ctx.stroke();
        ctx.setLineDash([]);
            ctx.shadowBlur = 0;
            
            // Shade feasible region
            ctx.fillStyle = &apos;rgba(220, 53, 69, 0.1)&apos;;
            ctx.fillRect(panel.x, panel.y, centerX + scale - panel.x, panel.height);
        
        // Mark optimal point
            ctx.shadowBlur = 20;
            ctx.shadowColor = &apos;#ff0000&apos;;
        ctx.fillStyle = &apos;#ff0000&apos;;
        ctx.beginPath();
            ctx.arc(centerX, centerY, 10, 0, 2 * Math.PI);
        ctx.fill();
            ctx.shadowBlur = 0;
            
            // Label optimal
            ctx.fillStyle = &apos;#ff0000&apos;;
            ctx.font = &apos;bold 14px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;p* = 0&apos;, centerX, centerY - 20);
            
            // Legend
            const legendX = panel.x + 15;
            const legendY = panel.y + 15;
            ctx.fillStyle = &apos;rgba(255, 255, 255, 0.95)&apos;;
            ctx.strokeStyle = &apos;#dee2e6&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.roundRect(legendX, legendY, 160, 90, 5);
            ctx.fill();
            ctx.stroke();
            
            ctx.font = &apos;13px Arial&apos;;
            ctx.textAlign = &apos;left&apos;;
            let yPos = legendY + 20;
            
            ctx.strokeStyle = &apos;#212529&apos;;
            ctx.lineWidth = 3;
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 35, yPos);
            ctx.stroke();
            ctx.fillStyle = &apos;#212529&apos;;
            ctx.fillText(&apos;f(x) = x²&apos;, legendX + 45, yPos + 4);
            yPos += 22;
            
            if (lambda &gt; 0.01) {
                ctx.strokeStyle = &apos;#007bff&apos;;
                ctx.beginPath();
                ctx.moveTo(legendX + 10, yPos);
                ctx.lineTo(legendX + 35, yPos);
                ctx.stroke();
                ctx.fillStyle = &apos;#007bff&apos;;
                ctx.fillText(&apos;L(x,λ)&apos;, legendX + 45, yPos + 4);
                yPos += 22;
            }
            
            ctx.strokeStyle = &apos;#dc3545&apos;;
            ctx.setLineDash([8, 4]);
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 35, yPos);
            ctx.stroke();
            ctx.setLineDash([]);
            ctx.fillStyle = &apos;#dc3545&apos;;
            ctx.fillText(&apos;x ≤ 1&apos;, legendX + 45, yPos + 4);
    }
    
    function drawDualSpace(panel, currentLambda) {
            const margin = 50;
            const centerX = panel.x + margin;
            const centerY = panel.y + panel.height - 70;
            const scaleX = (panel.width - margin - 30) / 4;
            const scaleY = 60;
            
            // Draw grid
            ctx.strokeStyle = &apos;#e9ecef&apos;;
        ctx.lineWidth = 1;
            ctx.setLineDash([2, 2]);
            for (let i = 0; i &lt;= 4; i++) {
                const x = centerX + i * scaleX;
                ctx.beginPath();
                ctx.moveTo(x, panel.y);
                ctx.lineTo(x, centerY);
                ctx.stroke();
            }
            for (let i = -5; i &lt;= 1; i++) {
                const y = centerY + i * scaleY;
                ctx.beginPath();
                ctx.moveTo(centerX, y);
                ctx.lineTo(panel.x + panel.width - 20, y);
                ctx.stroke();
            }
            ctx.setLineDash([]);
            
            // Draw axes
            ctx.strokeStyle = &apos;#495057&apos;;
            ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.moveTo(centerX, panel.y);
            ctx.lineTo(centerX, centerY);
        ctx.moveTo(centerX, centerY);
            ctx.lineTo(panel.x + panel.width - 20, centerY);
        ctx.stroke();
            
            // Axis labels
            ctx.fillStyle = &apos;#495057&apos;;
            ctx.font = &apos;bold 13px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            for (let i = 0; i &lt;= 4; i++) {
                ctx.fillText(i.toString(), centerX + i * scaleX, centerY + 20);
            }
            ctx.textAlign = &apos;right&apos;;
            for (let i = -5; i &lt;= 0; i++) {
                ctx.fillText(i.toString(), centerX - 10, centerY + i * scaleY + 5);
            }
            
            ctx.font = &apos;bold 16px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;λ&apos;, panel.x + panel.width - 10, centerY + 20);
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(&apos;g(λ)&apos;, centerX - 40, panel.y + 20);
        
        // Draw dual function g(λ) = -λ²/4 - λ
            ctx.strokeStyle = &apos;#28a745&apos;;
            ctx.lineWidth = 4;
            ctx.shadowBlur = 5;
            ctx.shadowColor = &apos;#28a745&apos;;
        ctx.beginPath();
        let first = true;
            for (let lambda = 0; lambda &lt;= 4; lambda += 0.02) {
            const g = -lambda * lambda / 4 - lambda;
            const screenX = centerX + lambda * scaleX;
            const screenY = centerY - g * scaleY;
                if (screenY &gt;= panel.y &amp;&amp; screenY &lt;= centerY + 10) {
                if (first) {
                    ctx.moveTo(screenX, screenY);
                    first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
            ctx.shadowBlur = 0;
            
            // Mark current point with trail effect
            if (currentLambda &gt; 0) {
                // Draw trail
                ctx.strokeStyle = &apos;rgba(220, 53, 69, 0.3)&apos;;
                ctx.lineWidth = 2;
                ctx.setLineDash([5, 5]);
                ctx.beginPath();
                for (let lambda = 0; lambda &lt;= currentLambda; lambda += 0.05) {
                    const g = -lambda * lambda / 4 - lambda;
                    const screenX = centerX + lambda * scaleX;
                    const screenY = centerY - g * scaleY;
                    if (lambda === 0) {
                        ctx.moveTo(screenX, screenY);
                    } else {
                        ctx.lineTo(screenX, screenY);
                    }
                }
                ctx.stroke();
                ctx.setLineDash([]);
            }
        
        // Mark current point
        const currentG = -currentLambda * currentLambda / 4 - currentLambda;
        const currentScreenX = centerX + currentLambda * scaleX;
        const currentScreenY = centerY - currentG * scaleY;
        
            if (currentScreenY &gt;= panel.y &amp;&amp; currentScreenY &lt;= centerY) {
                // Vertical line
                ctx.strokeStyle = &apos;#dc3545&apos;;
                ctx.lineWidth = 2;
                ctx.setLineDash([3, 3]);
            ctx.beginPath();
                ctx.moveTo(currentScreenX, currentScreenY);
                ctx.lineTo(currentScreenX, centerY);
                ctx.stroke();
                ctx.setLineDash([]);
                
                // Glow point
                ctx.shadowBlur = 20;
                ctx.shadowColor = &apos;#dc3545&apos;;
                ctx.fillStyle = &apos;#dc3545&apos;;
                ctx.beginPath();
                ctx.arc(currentScreenX, currentScreenY, 10, 0, 2 * Math.PI);
            ctx.fill();
                ctx.shadowBlur = 0;
            }
            
            // Show p* = 0 reference line
            ctx.strokeStyle = &apos;#ff0000&apos;;
            ctx.lineWidth = 2;
            ctx.setLineDash([8, 4]);
            const pStarY = centerY - 0 * scaleY;
            ctx.beginPath();
            ctx.moveTo(centerX, pStarY);
            ctx.lineTo(panel.x + panel.width - 20, pStarY);
            ctx.stroke();
            ctx.setLineDash([]);
            
            ctx.fillStyle = &apos;#ff0000&apos;;
            ctx.font = &apos;bold 13px Arial&apos;;
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(&apos;p* = 0&apos;, panel.x + panel.width - 70, pStarY - 5);
    }
    
    function animate() {
        if (!isAnimating) return;
        
            currentLambda += 0.015;
        if (currentLambda &gt; 4) {
            currentLambda = 0;
        }
        
        drawCompleteExample(currentLambda);
        animationId = requestAnimationFrame(animate);
    }
    
    animateBtn.addEventListener(&apos;click&apos;, function() {
        if (isAnimating) {
            isAnimating = false;
                if (animationId) cancelAnimationFrame(animationId);
                animateBtn.innerHTML = &apos;▶ Tiếp Tục&apos;;
                animateBtn.style.background = &apos;#007bff&apos;;
        } else {
            isAnimating = true;
                animateBtn.innerHTML = &apos;⏸ Tạm Dừng&apos;;
                animateBtn.style.background = &apos;#ffc107&apos;;
            animate();
        }
    });
    
    resetBtn.addEventListener(&apos;click&apos;, function() {
        isAnimating = false;
            if (animationId) cancelAnimationFrame(animationId);
        currentLambda = 0;
            animateBtn.innerHTML = &apos;▶ Chạy Animation&apos;;
            animateBtn.style.background = &apos;#28a745&apos;;
        drawCompleteExample(currentLambda);
    });
    
    // Initial draw
    drawCompleteExample(currentLambda);
    }
})();
&lt;/script&gt;

&lt;h2 id=&quot;-kết-luận&quot;&gt;🎓 Kết luận&lt;/h2&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;img src=&quot;/img/chapter_img/chapter11/lagrange_duality_framework.svg&quot; alt=&quot;Lagrange Duality Framework Overview&quot; style=&quot;max-width: 100%; height: auto;&quot; /&gt;
    &lt;p&gt;&lt;em&gt;Hình 5: Tổng quan về Framework Lagrange Duality - Nguồn: &lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Zhiliang Zhou&apos;s Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Đối ngẫu Lagrange cung cấp một khung phân tích thống nhất cho các bài toán tối ưu có ràng buộc thông qua bốn ý chính:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Đưa ràng buộc vào hàm mục tiêu:&lt;/strong&gt; Hàm Lagrangian chuyển ràng buộc thành các số hạng phạt có trọng số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cung cấp cận dưới:&lt;/strong&gt; Hàm đối ngẫu luôn cho một cận dưới hợp lệ của giá trị tối ưu gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Luôn là bài toán lồi:&lt;/strong&gt; Bài toán đối ngẫu luôn lồi bất kể bài toán gốc có lồi hay không.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hệ hình học:&lt;/strong&gt; Hàm liên hợp giải thích rõ mối quan hệ giữa tiếp tuyến và hàm đối ngẫu khi ràng buộc tuyến tính.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-ý-nghĩa-thực-tiễn&quot;&gt;🔍 Ý nghĩa thực tiễn&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thiết kế thuật toán:&lt;/strong&gt; Nhiều thuật toán tối ưu (như phương pháp gốc – đối ngẫu) khai thác đồng thời cả hai bài toán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích độ nhạy:&lt;/strong&gt; Biến đối ngẫu phản ánh mức thay đổi của giá trị tối ưu khi nới lỏng hoặc siết chặt ràng buộc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chí dừng:&lt;/strong&gt; Khoảng cách đối ngẫu giúp đánh giá cận trên của sai số nghiệm hiện tại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;️-ghi-chú-về-hình-ảnh&quot;&gt;🖼️ Ghi chú về hình ảnh&lt;/h2&gt;

&lt;p&gt;Các hình vẽ tĩnh trong bài học này được tham khảo từ bài viết gốc của Zhiliang Zhou; các minh họa tương tác bằng JavaScript được bổ sung để hỗ trợ quan sát trực tiếp sự thay đổi của hàm Lagrangian và hàm đối ngẫu.&lt;/p&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 Tài liệu tham khảo&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;“Convex Optimization” - Stephen Boyd &amp;amp; Lieven Vandenberghe&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Intuition behind Lagrange Duality&lt;/a&gt; - Zhiliang Zhou’s Blog&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://masszhou.github.io/&quot;&gt;Zhiliang’s Blog and Notes&lt;/a&gt; - Another External Brain Drive&lt;/li&gt;
  &lt;li&gt;Các chương trước trong khóa học về Linear Programming Duality và General Duality&lt;/li&gt;
  &lt;li&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004). Convex optimization. Cambridge University Press&lt;/li&gt;
  &lt;li&gt;Rockafellar, R. T. (1970). Convex analysis. Princeton University Press&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>11-05 Khoảng cách đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_05_Duality_gap/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_05_Duality_gap</id>
   <content type="html">&lt;p&gt;Khi chạy một thuật toán tối ưu lặp như gradient descent hay phương pháp điểm trong trên máy tính, một câu hỏi thực dụng nhưng cực kỳ hóc búa luôn xuất hiện: &lt;strong&gt;lúc nào thì được phép bấm nút “Dừng”?&lt;/strong&gt; Bạn đâu có biết trước giá trị tối ưu thật \(f^*\) là bao nhiêu! Nếu chỉ dừng khi \(\|x^{(k+1)} - x^{(k)}\|_2\) nhỏ, thuật toán có thể mới đang đi chậm trên một sườn phẳng rất xa đáy thật sự.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Khoảng cách đối ngẫu (Duality Gap)&lt;/strong&gt; \(f(x) - g(u, v)\) chính là “chiếc thước đo tuyệt đối” giải quyết triệt để bài toán dừng thuật toán! Nhờ bất đẳng thức kẹp \(g(u, v) \le f^* \le f(x)\), hiệu \(f(x) - g(u, v)\) luôn chặn trên sai số thật \(f(x) - f^*\). Nói cách khác, ngay giây phút bạn quan sát thấy \(f(x) - g(u, v) \le 10^{-6}\), bạn có ngay một &lt;strong&gt;chứng chỉ toán học 100% chắc chắn&lt;/strong&gt; rằng nghiệm \(x\) hiện tại cách đáy toàn cục \(f^*\) không quá \(10^{-6}\) — mà chẳng hề cần biết \(f^*\) bằng bao nhiêu!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-về-khoảng-cách-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Ba trụ cột về khoảng cách đối ngẫu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân biệt Khoảng cách đối ngẫu tại điểm \((x, u, v)\) và Khoảng cách đối ngẫu tối ưu:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Khoảng cách tại một cặp khả thi:&lt;/em&gt; \(f(x) - g(u, v) \ge 0\) (luôn không âm nhờ đối ngẫu yếu).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Khoảng cách tối ưu (Optimal Duality Gap):&lt;/em&gt; \(f^* - g^* \ge 0\). Khi đối ngẫu mạnh thỏa mãn, \(f^* - g^* = 0\), nên tồn tại cặp điểm làm khoảng cách tại điểm tiến sát về \(0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức kẹp và tiêu chuẩn dừng không cần biết \(f^*\):&lt;/strong&gt;
\(0 \le f(x) - f^* \le f(x) - g(u, v), \qquad 0 \le g^* - g(u, v) \le f(x) - g(u, v).\)
Một con số duy nhất \(f(x) - g(u, v) \le \epsilon\) đồng thời bảo chứng cả \(x\) là \(\epsilon\)-tối ưu gốc lẫn \((u, v)\) là \(\epsilon\)-tối ưu đối ngẫu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng trong thuật toán giải thực tế:&lt;/strong&gt; Các bộ giải hiện đại (CVXOPT, ECOS, SCS, Clarabel, hay thuật toán Dual Coordinate Descent cho SVM/Lasso) đều theo dõi khoảng cách đối ngẫu sau mỗi vài vòng lặp để quyết định hội tụ chính xác thay vì đoán mò.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-chứng-chỉ-dừng-bằng-khoảng-cách-đối-ngẫu&quot;&gt;Giải thích: Tính tay chứng chỉ dừng bằng khoảng cách đối ngẫu&lt;/h3&gt;

&lt;p&gt;Quay lại bài toán \(\min_x f(x) = x^2\) với ràng buộc \(x \ge 1\) (tức \(1 - x \le 0\)). Ở bài 11-02 ta đã tính được hàm đối ngẫu \(g(u) = u - \frac{u^2}{4}\) với \(u \ge 0\). Giả sử thuật toán đang chạy dở và ta giả vờ &lt;em&gt;chưa biết&lt;/em&gt; \(f^* = 1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp sớm — ta đang có điểm khả thi gốc \(x = 1.4\) và điểm khả thi đối ngẫu \(u = 1.0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giá trị gốc: \(f(1.4) = 1.4^2 = 1.96\).&lt;/li&gt;
      &lt;li&gt;Giá trị đối ngẫu: \(g(1.0) = 1.0 - \frac{1.0^2}{4} = 0.75\).&lt;/li&gt;
      &lt;li&gt;Khoảng cách đối ngẫu: \(1.96 - 0.75 = 1.21\) (còn quá lớn, chưa thể dừng! Chỉ biết \(0.75 \le f^* \le 1.96\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp sau — thuật toán cải thiện tới \(x = 1.05\) và \(u = 1.90\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giá trị gốc: \(f(1.05) = 1.05^2 = 1.1025\).&lt;/li&gt;
      &lt;li&gt;Giá trị đối ngẫu: \(g(1.90) = 1.90 - \frac{3.61}{4} = 1.90 - 0.9025 = 0.9975\).&lt;/li&gt;
      &lt;li&gt;Khoảng cách đối ngẫu: \(1.1025 - 0.9975 = 0.105\).
Không cần biết \(f^* = 1\), ta chứng nhận chắc chắn \(0.9975 \le f^* \le 1.1025\) và sai số của \(x = 1.05\) không vượt quá \(0.105\) (thực tế sai số thật là \(0.1025 \le 0.105\))!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khi chạm nghiệm \(x^* = 1, u^* = 2\):&lt;/strong&gt; \(f(1) = 1\), \(g(2) = 1\), khoảng cách đối ngẫu bằng đúng \(0\) — bộ giải dừng tức thì với chứng chỉ tối ưu tuyệt đối!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nếu \(x\) là một nghiệm khả thi của bài toán gốc với giá trị mục tiêu \(f(x)\), và \((u,v)\) là một nghiệm khả thi của bài toán đối ngẫu với giá trị \(g(u,v)\), thì hiệu số \(f(x) - g(u,v)\) được gọi là &lt;strong&gt;khoảng cách đối ngẫu (duality gap)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Theo tính đối ngẫu yếu, cặp giá trị khả thi này luôn thỏa mãn bất đẳng thức:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
f(x) - f^* \leq f(x) - g(u,v).
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu khoảng cách đối ngẫu bằng \(0\), thì \(x\) là nghiệm tối ưu của bài toán gốc và \((u,v)\) là nghiệm tối ưu của bài toán đối ngẫu.&lt;/p&gt;

&lt;p&gt;Hơn nữa, nếu tại một bước lặp ta thu được \(f(x) - g(u,v) \leq \epsilon\), thì điều này đảm bảo ngay \(f(x) - f^* \leq \epsilon\). Nhờ tính chất này, các thuật toán tối ưu lặp thường dùng khoảng cách đối ngẫu làm &lt;strong&gt;tiêu chí dừng&lt;/strong&gt; đáng tin cậy để kiểm soát sai số nghiệm.&lt;/p&gt;

&lt;h3 id=&quot;đối-ngẫu-mạnh-và-slater-trong-khoảng-3-phút&quot;&gt;Đối ngẫu mạnh và Slater trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/strong-duality-slater_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Hàm đối ngẫu g(λ) nằm dưới p*, khoảng cách đối ngẫu làm chứng chỉ, hình (u, t) của đường tì, và một bài lồi không thỏa Slater có khoảng cách bằng 1.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>11-04 Tính đối ngẫu mạnh</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_04_Strong_duality/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_04_Strong_duality</id>
   <content type="html">&lt;p&gt;Đối ngẫu yếu (\(g^* \le f^*\)) luôn đúng nhưng chưa đủ để ta yên tâm thay thế bài toán gốc bằng bài toán đối ngẫu — nếu khoảng cách \(f^* - g^*\) vẫn lớn, giải xong đối ngẫu ta chỉ biết một cận dưới lỏng lẻo chứ không chạm được tới đáy thực sự \(f^*\). Câu hỏi quan trọng của Chương 11 là: &lt;strong&gt;khi nào khoảng cách ấy thu về đúng bằng \(0\) (\(f^* = g^*\) — tính đối ngẫu mạnh)?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Trong quy hoạch tuyến tính, tính lồi tự nó là đủ. Nhưng với bài toán lồi phi tuyến tổng quát, điều bất ngờ là tính lồi &lt;em&gt;chưa hoàn toàn đủ&lt;/em&gt; — vẫn tồn tại những bài toán lồi “kỳ dị” trên biên khiến \(g^* &amp;lt; f^*\)! Để loại trừ những điểm kỳ dị đó, ta chỉ cần thêm một điều kiện chuẩn hóa cực kỳ nhẹ gọi là &lt;strong&gt;điều kiện Slater&lt;/strong&gt;: tồn tại ít nhất một điểm khả thi chặt nằm &lt;em&gt;hẳn bên trong&lt;/em&gt; các ràng buộc bất đẳng thức phi tuyến (\(h_i(\tilde{x}) &amp;lt; 0\)). Khi điều kiện Slater thỏa mãn (như trong bài toán SVM lừng danh ở cuối bài), tính đối ngẫu mạnh được bảo chứng 100%!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tính-đối-ngẫu-mạnh-và-điều-kiện-slater&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tính đối ngẫu mạnh và điều kiện Slater&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa tính đối ngẫu mạnh:&lt;/strong&gt; Xảy ra khi \(f^* = g^*\) (khoảng cách đối ngẫu tối ưu bằng \(0\)). Điều này cho phép ta giải bài toán đối ngẫu (thường đơn giản hơn hoặc có ít biến hơn, hoặc hỗ trợ thủ thuật nhân — kernel trick trong SVM!) rồi khôi phục nghiệm gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện Slater (dạng chuẩn và dạng tinh gọn cho ràng buộc affine):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Dạng chuẩn:&lt;/em&gt; Bài toán gốc lồi và tồn tại \(\tilde{x} \in \operatorname{relint}(\mathcal{D})\) sao cho \(h_i(\tilde{x}) &amp;lt; 0\) với mọi \(i\) và \(l_j(\tilde{x}) = 0\) với mọi \(j\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Dạng tinh gọn (rất hay dùng!):&lt;/em&gt; Các ràng buộc bất đẳng thức &lt;strong&gt;tuyến tính (affine)&lt;/strong&gt; chỉ cần thỏa \(h_i(\tilde{x}) \le 0\) (không cần dấu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; chặt!); chỉ những ràng buộc &lt;em&gt;phi tuyến&lt;/em&gt; mới đòi hỏi dấu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; chặt! Đó là lý do LP (toàn ràng buộc affine) không cần điểm chặt vẫn có đối ngẫu mạnh!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý tách siêu phẳng — gốc rễ hình học của Slater:&lt;/strong&gt; Điều kiện Slater đảm bảo siêu phẳng đỡ tập \(\mathcal{A} = \{(u, t) : \exists x, h(x) \le u, f(x) \le t\}\) tại \((0, f^*)\) không bị “dựng đứng” song song trục \(t\), nhờ đó hệ số của \(f(x)\) khác \(0\) và chia chuẩn hóa ra được nhân tử Lagrange hữu hạn \((u^*, v^*)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng vàng — Bài toán đối ngẫu SVM:&lt;/strong&gt; Trong SVM, mọi ràng buộc \(1 - y_i(x_i^T\beta + \beta_0) - \xi_i \le 0\) và \(-\xi_i \le 0\) đều là &lt;strong&gt;ràng buộc affine&lt;/strong&gt;! Do đó bài toán SVM tự động thỏa điều kiện Slater tinh gọn và luôn có đối ngẫu mạnh \(f^* = g^*\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-đối-chiếu-1-bài-toán-thỏa-slater-và-1-bài-toán-lồi-vi-phạm-slater&quot;&gt;Giải thích: Đối chiếu 1 bài toán thỏa Slater và 1 bài toán lồi vi phạm Slater&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Trường hợp 1 (Thỏa Slater \(\implies f^* = g^*\)):&lt;/strong&gt;
\(\min_{x_1, x_2} \; x_1^2 + x_2^2 \quad \text{s.t.} \quad h_1(x) = 2 - x_1 - x_2 \le 0, \quad h_2(x) = x_1^2 - 4 \le 0.\)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Chọn điểm thử \(\tilde{x} = (1.5, 1.5)\): ta có \(h_1(\tilde{x}) = 2 - 3 = -1 &amp;lt; 0\) và \(h_2(\tilde{x}) = 2.25 - 4 = -1.75 &amp;lt; 0\).&lt;/li&gt;
  &lt;li&gt;Tồn tại điểm khả thi chặt \(\implies\) điều kiện Slater thỏa mãn \(\implies\) chắc chắn có &lt;strong&gt;đối ngẫu mạnh&lt;/strong&gt; (thực tế \(x^* = (1, 1), f^* = g^* = 2\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trường hợp 2 (Bài toán lồi nổi tiếng của Boyd–Vandenberghe &lt;em&gt;vi phạm&lt;/em&gt; Slater \(\implies g^* &amp;lt; f^*\)):&lt;/strong&gt;
\(\min_{x_1 \in \mathbb{R},\; x_2 &amp;gt; 0} \; f(x_1, x_2) = e^{-x_1} \quad \text{s.t.} \quad h(x_1, x_2) = \frac{x_1^2}{x_2} \le 0.\)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Đây là bài toán &lt;strong&gt;lồi&lt;/strong&gt; (hàm bậc hai chia tuyến tính \(x_1^2/x_2\) lồi trên \(x_2 &amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;Vì \(x_1^2 \ge 0\) và \(x_2 &amp;gt; 0\), ràng buộc \(x_1^2/x_2 \le 0\) ép buộc \(x_1 = 0\) (không hề tồn tại điểm nào làm \(x_1^2/x_2 &amp;lt; 0\) \(\implies\) &lt;strong&gt;Slater thất bại!&lt;/strong&gt;).&lt;/li&gt;
  &lt;li&gt;Giá trị tối ưu gốc: \(f^* = e^0 = 1\).&lt;/li&gt;
  &lt;li&gt;Hàm đối ngẫu với mọi \(u \ge 0\): \(g(u) = \inf_{x_1, x_2 &amp;gt; 0} \left(e^{-x_1} + u\frac{x_1^2}{x_2}\right) = 0\) (chỉ cần cho \(x_1\) lớn tùy ý để \(e^{-x_1} \to 0\), rồi chọn \(x_2 = x_1^3\) để \(\frac{x_1^2}{x_2} = \frac{1}{x_1} \to 0\)!).&lt;/li&gt;
  &lt;li&gt;Vậy \(g^* = 0 &amp;lt; 1 = f^*\) — khoảng cách đối ngẫu bằng \(1\) ngay cả khi bài toán hoàn toàn lồi!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Khi giá trị tối ưu của bài toán gốc và bài toán đối ngẫu bằng nhau (\(f^* = g^*\)), ta nói &lt;strong&gt;tính đối ngẫu mạnh (strong duality)&lt;/strong&gt; thỏa mãn. &lt;strong&gt;Điều kiện Slater&lt;/strong&gt; là một điều kiện đủ phổ biến bảo đảm tính đối ngẫu mạnh.&lt;/p&gt;

&lt;h2 id=&quot;điều-kiện-slater&quot;&gt;Điều kiện Slater&lt;/h2&gt;

&lt;p&gt;Nếu bài toán gốc là bài toán tối ưu lồi và tồn tại ít nhất một điểm \(x \in \mathbb{R}^n\) &lt;strong&gt;khả thi chặt&lt;/strong&gt; (strictly feasible), tức thỏa mãn:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
h_1(x)&amp;lt;0,\dots,h_m(x)&amp;lt;0, \text{ and } l_1(x) = 0,\dots,l_r(x) = 0,
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;thì tính đối ngẫu mạnh được thỏa mãn (\(f^* = g^*\)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý quan trọng:&lt;/strong&gt; Đối với các ràng buộc bất đẳng thức là hàm affine, điều kiện bất đẳng thức chặt (\(&amp;lt; 0\)) không bắt buộc — chỉ cần thỏa mãn bất đẳng thức không chặt (\(\leq 0\)).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-bài-toán-đối-ngẫu-của-support-vector-machine-svm&quot;&gt;Ví dụ: Bài toán đối ngẫu của Support Vector Machine (SVM)&lt;/h2&gt;

&lt;p&gt;Cho \(y \in \{-1, 1\}^n\) và ma trận dữ liệu \(X \in \mathbb{R}^{n \times p}\) (với các hàng của \(X\) là các mẫu \(x_1^T, \dots, x_n^T\)), bài toán SVM lề mềm được phát biểu như sau:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{alignat}{1}
\min_{\beta, \beta_0, \xi} &amp;amp; \quad \frac{1}{2}\parallel\beta\parallel_2^2 + C \sum_{i=1}^n \xi_i   \\\\
                                  s.t. &amp;amp; \quad \xi_i \geq 0, i=1,\dots,n   \\\\
                                       &amp;amp; \quad y_i(x_i^T \beta + \beta_0) \geq 1 - \xi_i, i=1,\dots,n
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Đưa vào các biến đối ngẫu \(v, w \geq 0\), ta lập hàm Lagrangian:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
L(\beta,\beta_0,\xi,v,w) = \frac{1}{2} \parallel\beta\parallel_2^2 + C\sum_{i=1}^n \xi_i - \sum_{i=1}^n v_i \xi_i +  \sum_{i=1}^n w_i (1-\xi_i - y_i(x_i^T\beta + \beta_0))
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Cực tiểu hóa theo \(\beta, \beta_0, \xi\), ta thu được hàm đối ngẫu Lagrange:&lt;/p&gt;

&lt;blockquote&gt;

\[g(v,w) = 
\begin{cases}
-\frac{1}{2} w^T\tilde{X}\tilde{X}^T w +  1^Tw, &amp;amp;\text{if $w=C1-v, w^Ty=0$} \\\\
-\infty, &amp;amp;\text{otherwise}
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\tilde{X} = \text{diag}(y) X\). Khử biến bù \(v \geq 0\) (từ \(w = C\mathbf{1} - v\) suy ra \(w \leq C\mathbf{1}\)), ta thu được bài toán đối ngẫu của SVM:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{alignat}{1}
\max_{w}  &amp;amp; \quad -\frac{1}{2} w^T\tilde{X}\tilde{X}^T w +  1^Tw \\\\
     s.t. &amp;amp;  \quad 0 \leq w \leq C1, w^Ty = 0
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì bài toán gốc có hàm mục tiêu lồi, các ràng buộc bất đẳng thức đều là hàm affine theo \((\beta, \beta_0, \xi)\) và luôn tồn tại điểm khả thi, nên điều kiện Slater được thỏa mãn và tính đối ngẫu mạnh đúng đối với SVM.&lt;/p&gt;

&lt;h3 id=&quot;đối-ngẫu-mạnh-và-slater-trong-khoảng-3-phút&quot;&gt;Đối ngẫu mạnh và Slater trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/strong-duality-slater_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Hàm đối ngẫu g(λ) nằm dưới p*, khoảng cách đối ngẫu làm chứng chỉ, hình (u, t) của đường tì, và một bài lồi không thỏa Slater có khoảng cách bằng 1.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>11-03 Bài toán đối ngẫu Lagrange</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_03_Lagrange_dual_problem/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_03_Lagrange_dual_problem</id>
   <content type="html">&lt;p&gt;Sau khi đã có trong tay hàm đối ngẫu \(g(u, v)\) — cỗ máy sản xuất vô số cận dưới \(g(u, v) \le f^*\) — câu hỏi tiếp theo gần như tự bật ra: &lt;em&gt;trong tất cả các cận dưới ấy, cận dưới nào là &lt;strong&gt;tốt nhất (lớn nhất)&lt;/strong&gt;?&lt;/em&gt; Để tìm nó, ta chỉ việc cực đại hóa \(g(u, v)\) theo \(u \ge 0\) và \(v \in \mathbb{R}^r\). Đó chính xác là &lt;strong&gt;bài toán đối ngẫu Lagrange&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Điều kỳ diệu biến bài toán đối ngẫu thành vũ khí hạng nặng trong tối ưu hóa không lồi (như quy hoạch nguyên, bài toán phân cụm, hay hàm bậc bốn đa đỉnh trong bài học này) là: dù bài toán gốc không lồi và đầy rẫy cực tiểu địa phương, &lt;strong&gt;bài toán đối ngẫu Lagrange luôn là một bài toán tối ưu lồi&lt;/strong&gt; (cực đại hóa hàm lõm trên miền lồi \(u \ge 0\))! Nhờ vậy, ta luôn có thể giải bài toán đối ngẫu tới tối ưu toàn cục \(g^*\) một cách đáng tin cậy để lấy cận dưới chặt nhất cho \(f^*\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-bài-toán-đối-ngẫu-lagrange&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của bài toán đối ngẫu Lagrange&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phát biểu chuẩn của bài toán đối ngẫu:&lt;/strong&gt;
\(\max_{u, v} \; g(u, v) \quad \text{s.t.} \quad u \ge 0 \quad (\text{và ẩn ý } (u, v) \in \operatorname{dom} g).\)
Tối ưu hóa bài toán này cho ta giá trị đối ngẫu tối ưu \(g^* = d^*\), luôn thỏa &lt;strong&gt;đối ngẫu yếu&lt;/strong&gt; \(g^* \le f^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi tuyệt đối của bài toán đối ngẫu:&lt;/strong&gt; Vì \(g(u, v)\) lõm nên \(-g(u, v)\) lồi, và tập ràng buộc \(u \ge 0\) (cùng miền hữu dụng \(\operatorname{dom} g\)) là tập lồi. Do đó, mọi thuật toán tối ưu lồi (như subgradient, proximal, điểm trong) đều áp dụng được trực tiếp lên bài toán đối ngẫu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển ràng buộc ẩn thành ràng buộc tường minh:&lt;/strong&gt; Khi viết bài toán đối ngẫu trên giấy, ta thường đưa các điều kiện làm cho \(g(u, v) &amp;gt; -\infty\) (như \(-A^T u - G^T v = c\) trong LP hay \(p \in \operatorname{col}(Q)\) trong QP) ra làm ràng buộc tường minh để dễ giải và dễ nhìn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-bài-toán-đối-ngẫu-cho-một-bài-toán-gốc-không-lồi&quot;&gt;Giải thích: Giải tay bài toán đối ngẫu cho một bài toán gốc &lt;em&gt;không lồi&lt;/em&gt;&lt;/h3&gt;

&lt;p&gt;Xét bài toán không lồi 1 biến (vì miền khả thi là hai điểm rời rạc \(x = \pm 1\)):
\(\min_{x \in \mathbb{R}} \; f(x) = x \quad \text{s.t.} \quad l(x) = x^2 - 1 = 0.\)
Dễ thấy miền khả thi chỉ gồm \(x = -1\) và \(x = 1\), nên giá trị tối ưu gốc là \(f^* = -1\) (tại \(x^* = -1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập hàm Lagrangian và tìm hàm đối ngẫu \(g(v)\) (\(v \in \mathbb{R}\)):&lt;/strong&gt;
\(L(x, v) = x + v(x^2 - 1) = v x^2 + x - v.\)
    &lt;ul&gt;
      &lt;li&gt;Nếu \(v \le 0\): đồ thị là đường thẳng hoặc parabol úp xuống, nên \(\inf_x L(x, v) = -\infty\)!&lt;/li&gt;
      &lt;li&gt;Nếu \(v &amp;gt; 0\): parabol ngửa lên, đạt cực tiểu tại \(2vx + 1 = 0 \implies x = -\frac{1}{2v}\). Thay vào:
\(g(v) = v\left(\frac{1}{4v^2}\right) - \frac{1}{2v} - v = -\frac{1}{4v} - v.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán đối ngẫu (hoàn toàn lồi!):&lt;/strong&gt;
\(\max_{v &amp;gt; 0} \; g(v) = -\frac{1}{4v} - v.\)
Kiểm tra tính lõm: \(g&apos;&apos;(v) = -\frac{1}{2v^3} &amp;lt; 0\) với mọi \(v &amp;gt; 0\)!
Cho đạo hàm \(g&apos;(v) = \frac{1}{4v^2} - 1 = 0 \implies v^* = \frac{1}{2} &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh \(g^*\) và \(f^*\):&lt;/strong&gt;
\(g^* = g\left(\frac{1}{2}\right) = -\frac{1}{2} - \frac{1}{2} = -1 = f^*!\)
Dù bài toán gốc không lồi (hai điểm rời rạc!), bài toán đối ngẫu lại trơn, lõm, và trong ví dụ đặc biệt này thậm chí đạt \(g^* = f^*\) (trong khi với nhiều bài toán không lồi khác như hàm bậc bốn ở phần thân bài, ta sẽ gặp \(g^* &amp;lt; f^*\)).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Xét bài toán tối ưu tổng quát sau:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{alignat}{1}
\min_x &amp;amp; \quad f(x)  \\
s.t.   &amp;amp; \quad h_i(x) \leq 0, i=1,\dots,m  \\
       &amp;amp; \quad l_j(x) = 0, j=1,\dots,r
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Hàm đối ngẫu \(g(u,v)\) thỏa mãn \(f^* \geq g(u,v)\) với mọi \(u \geq 0\) và \(v\). Để tìm cận dưới chặt nhất có thể cho \(f^*\), ta cực đại hóa \(g(u,v)\) trên miền \(u \geq 0\). Bài toán thu được gọi là &lt;strong&gt;bài toán đối ngẫu Lagrange&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{alignat}{1}
\max_{u,v} &amp;amp; \quad g(u,v)   \\
           s.t. &amp;amp; \quad u \geq 0
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Ký hiệu giá trị tối ưu của bài toán đối ngẫu là \(g^*\), khi đó ta luôn có \(f^* \geq g^*\). Tính chất này được gọi là &lt;strong&gt;tính đối ngẫu yếu (weak duality)&lt;/strong&gt; và luôn đúng bất kể bài toán gốc có lồi hay không. Hơn nữa, &lt;strong&gt;bài toán đối ngẫu luôn là một bài toán tối ưu lồi&lt;/strong&gt;, ngay cả khi bài toán gốc không lồi.&lt;/p&gt;

&lt;p&gt;Thật vậy, theo định nghĩa, \(g(u,v)\) là hàm lõm theo \((u,v)\) và ràng buộc \(u \geq 0\) xác định một tập lồi, nên bài toán đối ngẫu là bài toán cực đại hóa một hàm lõm trên một tập lồi:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{alignat}{1}
 g(u,v) &amp;amp; = \min_x \{ f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x) \}  \\ 
        &amp;amp; = - \underbrace{\max_x \{ -f(x) - \sum_{i=1}^m u_i h_i(x) - \sum_{j=1}^r v_j l_j(x) \}}_{\text{pointwise maximum of convex functions in $(u,v)$}}
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;ví-dụ-cực-tiểu-hóa-hàm-bậc-bốn-không-lồi&quot;&gt;Ví dụ: Cực tiểu hóa hàm bậc bốn không lồi&lt;/h2&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa hàm không lồi \(f(x) = x^4 - 50x^2 + 100x\) với ràng buộc \(x \geq -4.5\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter11/dual-gen_13.png&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 4] Ví dụ về tối thiểu hóa hàm bậc bốn không lồi&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Trong ví dụ này, hàm đối ngẫu \(g(u)\) có biểu thức phức tạp:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
 g(u) = \min_{i=1,2,3} \{F_i^4(u) - 50 F_i^2(u) + 100 F_i(u) \}
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó, với \(i = 1, 2, 3\):&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{alignat}{1}
F_i(u) = &amp;amp; \frac{- a_i}{12\cdot 2^{1/3}} \left( 432(100-u)-(432^2(100-u)^2 - 4\cdot 1200^3)^{1/2} \right )^{1/3} \\ 
           &amp;amp; - 100 \cdot 2^{1/3} \frac{1}{\left( 432(100-u)-(432^2(100-u)^2 - 4\cdot 1200^3)^{1/2} \right )^{1/3}}
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;và \(a_1 = 1\), \(a_2 = (-1 + i\sqrt{3})/2\), \(a_3 = (-1 - i\sqrt{3})/2\).&lt;/p&gt;

&lt;p&gt;Nếu chỉ nhìn vào công thức giải tích trên thì rất khó kiểm tra trực tiếp tính lõm của \(g\); tuy nhiên, theo tính chất tổng quát của hàm đối ngẫu Lagrange, ta biết chắc chắn rằng \(g(u)\) là một hàm lõm.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>11-02 Hàm đối ngẫu Lagrange</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_02_Lagrange_dual_function/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_02_Lagrange_dual_function</id>
   <content type="html">&lt;p&gt;Nếu hàm Lagrangian \(L(x, u, v)\) là bản phác thảo biến bài toán có ràng buộc thành bài toán phạt mềm, thì &lt;strong&gt;hàm đối ngẫu Lagrange&lt;/strong&gt; \(g(u, v) = \inf_{x} L(x, u, v)\) chính là bước chuyển hóa kỳ diệu loại bỏ hoàn toàn biến gốc \(x\)! Ở mỗi bộ giá phạt \((u, v)\), ta thả tự do cho \(x\) chạy khắp không gian để tìm đáy thấp nhất của \(L(x, u, v)\). Đáy ấy chắc chắn không vượt quá giá trị tối ưu gốc \(f^*\) — nghĩa là mỗi cặp \((u, v)\) với \(u \ge 0\) tặng cho ta ngay một &lt;strong&gt;cận dưới hợp lệ&lt;/strong&gt; \(g(u, v) \le f^*\).&lt;/p&gt;

&lt;p&gt;Điều làm giới toán học kinh ngạc nhất ở hàm \(g(u, v)\) là một tính chất hình học bất biến: &lt;strong&gt;\(g(u, v)\) luôn là hàm lõm theo \((u, v)\), ngay cả khi hàm mục tiêu \(f\) và các ràng buộc \(h_i, l_j\) của bài toán gốc cực kỳ không lồi!&lt;/strong&gt; Bài học này chứng minh trực quan sự thật tuyệt đẹp đó và thực hành tính tường minh \(g(u, v)\) trên hai trường hợp quan trọng của Quy hoạch bậc hai (QP): ma trận \(Q \succ 0\) xác định dương và \(Q \succeq 0\) nửa xác định dương (dùng nghịch đảo giả Moore–Penrose \(Q^+\)).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-hàm-đối-ngẫu-lagrange&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của hàm đối ngẫu Lagrange&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa và bất đẳng thức chặn dưới toàn cục:&lt;/strong&gt;
\(g(u, v) = \inf_{x \in \mathcal{D}} L(x, u, v) \le \inf_{x \in C} L(x, u, v) \le \inf_{x \in C} f(x) = f^* \quad (\forall u \ge 0).\)
Bất đẳng thức này đúng vô điều kiện, không cần tính lồi hay tính khả vi của bài toán gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vì sao \(g(u, v)\) luôn lõm?&lt;/strong&gt; Với mỗi \(x\) cố định, \(L(x, u, v)\) là một siêu phẳng (hàm affine) theo \((u, v)\). Lấy infimum theo mọi \(x\) tương đương lấy “bọc dưới” của một họ siêu phẳng — mà bọc dưới của các siêu phẳng thì &lt;strong&gt;luôn luôn lõm&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Miền hữu dụng (Dual Feasibility Domain):&lt;/strong&gt; Đôi khi với một số giá trị \((u, v)\), \(L(x, u, v)\) không bị chặn dưới theo \(x\) nên \(g(u, v) = -\infty\). Tập các điểm \((u, v)\) sao cho \(u \ge 0\) và \(g(u, v) &amp;gt; -\infty\) chính là miền ràng buộc ẩn của bài toán đối ngẫu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy hoạch bậc hai với \(Q \succ 0\) vs. \(Q \succeq 0\):&lt;/strong&gt; Khi \(Q \succ 0\), cực tiểu của \(\frac{1}{2}x^T Q x + p^T x\) đạt tại \(x = -Q^{-1} p\) cho mọi \(p\). Khi \(Q \succeq 0\) suy biến (có không gian hạch \(\operatorname{null}(Q) \ne \{0\}\)), cực tiểu chỉ hữu hạn khi \(p \perp \operatorname{null}(Q)\) (tức \(p \in \operatorname{col}(Q)\)), khi đó nghiệm cho bằng nghịch đảo giả \(x = -Q^+ p\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-gu-v-cho-qp-suy-biến-2-times-2-q-succeq-0&quot;&gt;Giải thích: Tính tay \(g(u, v)\) cho QP suy biến \(2 \times 2\) (\(Q \succeq 0\))&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai suy biến trong \(\mathbb{R}^2\) với \(Q = \begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{pmatrix} \succeq 0\) (cột 2 bằng 0!):
\(\min_{x_1, x_2} \; x_1^2 + 3x_2 \quad \text{s.t.} \quad x_1 + x_2 = 1.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập hàm Lagrangian (nhân tử \(v \in \mathbb{R}\)):&lt;/strong&gt;
\(L(x_1, x_2, v) = x_1^2 + 3x_2 + v(x_1 + x_2 - 1) = (x_1^2 + v x_1) + (3 + v)x_2 - v.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa tự do theo từng biến \(x_1, x_2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Theo \(x_1\) (phần xác định dương \(2 &amp;gt; 0\)): đạt cực tiểu tại \(x_1 = -v/2\), giá trị \(-v^2/4\).&lt;/li&gt;
      &lt;li&gt;Theo \(x_2\) (phần suy biến \(0 \cdot x_2^2 + (3 + v)x_2\)):
        &lt;ul&gt;
          &lt;li&gt;Nếu \(3 + v \ne 0\), cho \(x_2 \to \pm\infty\) làm \(L \to -\infty\)!&lt;/li&gt;
          &lt;li&gt;Chỉ khi \(3 + v = 0\) (tức \(v = -3\), tương ứng điều kiện \(p \in \operatorname{col}(Q)\)) thì phần \(x_2\) mới bằng \(0\)!&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Viết gọn hàm đối ngẫu \(g(v)\):&lt;/strong&gt;
\(g(v) = \begin{cases} -\frac{(-3)^2}{4} - (-3) = -2.25 + 3 = 0.75 &amp;amp; \text{nếu } v = -3, \\ -\infty &amp;amp; \text{nếu } v \ne -3. \end{cases}\)
Kiểm tra lại bài toán gốc: thay \(x_2 = 1 - x_1\) vào mục tiêu được \(x_1^2 + 3(1 - x_1) = (x_1 - 1.5)^2 + 0.75 \ge 0.75\) (đạt tại \(x_1^* = 1.5, x_2^* = -0.5\)). Khớp chính xác \(0.75\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Gọi \(C\) là tập khả thi của bài toán gốc và \(f^*\) là giá trị tối ưu gốc. Khi cực tiểu hóa \(L(x,u,v)\) trên toàn bộ biến \(x\), ta thu được cận dưới sau:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
f^* \geq \min_{x \in C} L(x,u,v) \geq \min_x L(x,u,v) := g(u,v)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Hàm \(g(u,v)\) được gọi là &lt;strong&gt;hàm đối ngẫu Lagrange&lt;/strong&gt; và cung cấp một cận dưới cho \(f^*\) với mọi cặp đối ngẫu khả thi \(u \geq 0, v\).&lt;/p&gt;

&lt;p&gt;Minh họa trong Hình 2:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter11/dual-gen_7.png&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Ví dụ về hàm đối ngẫu Lagrangian[1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Đường ngang đứt nét biểu thị giá trị tối ưu gốc \(f^*\).&lt;/li&gt;
  &lt;li&gt;Trục hoành là biến đối ngẫu \(\lambda\).&lt;/li&gt;
  &lt;li&gt;Đường liền nét biểu thị đồ thị hàm đối ngẫu \(g(\lambda)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ví-dụ-quy-hoạch-bậc-hai-quadratic-program&quot;&gt;Ví dụ: Quy hoạch bậc hai (Quadratic Program)&lt;/h2&gt;

&lt;h3 id=&quot;1-trường-hợp-xác-định-dương-q-succ-0&quot;&gt;1) Trường hợp xác định dương (\(Q \succ 0\))&lt;/h3&gt;

&lt;p&gt;Xét bài toán quy hoạch bậc hai với ma trận đối xứng xác định dương \(Q \succ 0\):&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{alignat}{1}
\min_x  &amp;amp; \quad \frac{1}{2}x^T Q x + c^T x \\\\
       s.t. &amp;amp; \quad Ax = b, \\\\
            &amp;amp; \quad x \geq 0
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;hàm-lagrangian&quot;&gt;Hàm Lagrangian&lt;/h4&gt;
&lt;blockquote&gt;

\[\begin{equation}
L(x,u,v) = \frac{1}{2}x^T Q x + c^T x - u^Tx + v^T (Ax-b)
\end{equation}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;hàm-đối-ngẫu-lagrange&quot;&gt;Hàm đối ngẫu Lagrange&lt;/h4&gt;

&lt;p&gt;Để cực tiểu hóa \(L(x,u,v)\) theo \(x\), ta lấy đạo hàm theo \(x\) và cho bằng không:&lt;/p&gt;

\[\begin{equation}
Qx + (c - u + A^T v) = 0,
\end{equation}\]

&lt;p&gt;tức là:&lt;/p&gt;

\[\begin{equation}
Qx = -(c - u + A^T v).
\end{equation}\]

&lt;p&gt;Vì \(Q \succ 0\) là ma trận xác định dương nên khả nghịch, suy ra \(x^* = -Q^{-1}(c - u + A^T v)\). Thay \(x^*\) vào hàm Lagrangian, ta thu được:&lt;/p&gt;

\[\begin{alignat}{1}
&amp;amp; \frac{1}{2} (c - u + A^T v)^T (Q^{-1})^T Q Q^{-1}(c - u + A^T v) - (c - u + A^T v)^T Q^{-1} (c - u + A^T v) - b^T v \\\
= &amp;amp; \frac{1}{2} (c - u + A^T v)^T Q^{-1}(c - u + A^T v) - (c - u + A^T v)^T Q^{-1} (c - u + A^T v) - b^T v \\\
= &amp;amp; -\frac{1}{2} (c-u+A^Tv)^T Q^{-1} (c-u+A^T v) - b^T v
\end{alignat}\]

&lt;p&gt;Do đó:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
g(u,v) = \min_x L(x,u,v) = -\frac{1}{2} (c-u+A^Tv)^T Q^{-1} (c-u+A^T v) - b^T v
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Với mọi \(u \geq 0\) và \(v\), biểu thức này cho một cận dưới của giá trị tối ưu gốc \(f^*\).&lt;/p&gt;

&lt;h3 id=&quot;2-trường-hợp-nửa-xác-định-dương-q-succeq-0&quot;&gt;2) Trường hợp nửa xác định dương (\(Q \succeq 0\))&lt;/h3&gt;

&lt;p&gt;Xét lại bài toán trên khi \(Q \succeq 0\) là ma trận nửa xác định dương.&lt;/p&gt;

&lt;h4 id=&quot;hàm-lagrangian-1&quot;&gt;Hàm Lagrangian&lt;/h4&gt;
&lt;blockquote&gt;

\[\begin{equation}
L(x,u,v) = \frac{1}{2}x^T Q x + c^T x - u^Tx + v^T (Ax-b)
\end{equation}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;hàm-đối-ngẫu-lagrange-1&quot;&gt;Hàm đối ngẫu Lagrange&lt;/h4&gt;

&lt;p&gt;Tương tự trường hợp xác định dương, điều kiện cực tiểu theo \(x\) là:&lt;/p&gt;

\[\begin{equation}
Qx = -(c-u+A^T v)
\end{equation}\]

&lt;p&gt;Vì \(Q \succeq 0\) có thể suy biến (không khả nghịch), ta chia thành hai trường hợp:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;\(c - u + A^T v \in \operatorname{col}(Q)\) (tương đương \(c - u + A^T v \perp \operatorname{null}(Q)\) do \(Q\) đối xứng): phương trình có nghiệm \(x^* = -Q^+(c - u + A^T v)\), trong đó \(Q^+\) là nghịch đảo giả Moore–Penrose của \(Q\).&lt;/li&gt;
  &lt;li&gt;\(c - u + A^T v \notin \operatorname{col}(Q)\): phương trình vô nghiệm và \(L(x,u,v)\) không bị chặn dưới theo \(x\), nên giá trị cực tiểu bằng \(-\infty\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tóm lại, hàm đối ngẫu Lagrange là:&lt;/p&gt;

&lt;blockquote&gt;

\[g(u,v) =
\begin{cases}
-\frac{1}{2} (c-u+A^T v)^T Q^{+} (c - u + A^T v) - b^T v  &amp;amp; \text{if $c-u+A^T v \perp \text{null}(Q)$} \\\\
-\infty  &amp;amp; \text{otherwise}
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;Với mọi \(u \geq 0\) và \(v\) thỏa mãn \(c - u + A^T v \perp \operatorname{null}(Q)\), \(g(u,v)\) là một cận dưới hữu hạn (không tầm thường) của \(f^*\).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-quy-hoạch-bậc-hai-trong-không-gian-2-chiều&quot;&gt;Ví dụ: Quy hoạch bậc hai trong không gian 2 chiều&lt;/h2&gt;

&lt;p&gt;Trong Hình 3, \(f(x_1, x_2)\) là một hàm bậc hai xét trên miền không âm (\(x \ge 0\)), và hàm đối ngẫu \(g(u_1, u_2)\) là một hàm bậc hai xét trên miền \(u \ge 0\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter11/dual-gen_10.png&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 3] Ví dụ về chương trình bậc hai trong 2D&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Điểm màu xanh biểu thị giá trị tối ưu đối ngẫu, còn điểm màu đỏ biểu thị giá trị tối ưu gốc.&lt;/li&gt;
  &lt;li&gt;Với mọi \(u \ge 0\), hàm đối ngẫu \(g(u)\) luôn cho một cận dưới của \(f^*\).&lt;/li&gt;
  &lt;li&gt;Giá trị cực đại của hàm đối ngẫu \(g(u)\) trùng khớp với giá trị tối ưu gốc \(f^*\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;hàm-đối-ngẫu-luôn-là-một-cận-dưới-video&quot;&gt;Hàm đối ngẫu luôn là một cận dưới (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/dual-lower-bound_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Với mọi \(\lambda\ge 0\), giá trị nhỏ nhất của hàm Lagrange \(g(\lambda)=\min_x L(x,\lambda)\) là một cận dưới của \(p^*\), và bài toán đối ngẫu cực đại hóa cận dưới đó.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-kéo-nhân-tử&quot;&gt;Tự tay thử: kéo nhân tử&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;d1&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>11-01 Hàm Lagrangian</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_01_Lagrangian/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_01_Lagrangian</id>
   <content type="html">&lt;p&gt;Trong giải tích năm nhất đại học, bạn hẳn từng học phương pháp &lt;strong&gt;nhân tử Lagrange&lt;/strong&gt; của Joseph-Louis Lagrange (1788) để tìm cực trị có ràng buộc đẳng thức \(l(x) = 0\) bằng cách đặt \(\nabla f(x) + v \nabla l(x) = 0\). Sang tối ưu hóa hiện đại, hàm Lagrangian được mở rộng mạnh mẽ hơn nhiều: nó không chỉ xử lý thêm các ràng buộc bất đẳng thức \(h_i(x) \le 0\) với dấu nhân tử bắt buộc \(u_i \ge 0\), mà còn đóng vai trò như một &lt;strong&gt;“hàm phạt mềm” (soft penalty)&lt;/strong&gt; giúp ta thả lỏng các bức tường ràng buộc cứng nhắc để xây dựng bài toán đối ngẫu!&lt;/p&gt;

&lt;p&gt;Hãy hình dung mỗi ràng buộc \(h_i(x) \le 0\) như một luật giao thông và nhân tử \(u_i \ge 0\) là mức tiền phạt cho mỗi đơn vị vi phạm. Nếu bạn tuân thủ luật (\(h_i(x) \le 0\)), khoản cộng \(u_i h_i(x) \le 0\) thậm chí còn như một khoản “hoàn tiền” làm giá trị hàm Lagrangian nhỏ hơn hoặc bằng chi phí thật \(f(x)\); còn nếu bạn vượt rào (\(h_i(x) &amp;gt; 0\)), khoản phạt \(u_i h_i(x) &amp;gt; 0\) lập tức kéo giá trị Lagrangian vọt lên cao!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-đằng-sau-định-nghĩa-hàm-lagrangian&quot;&gt;Kiến thức cần nhớ: Ba trụ cột đằng sau định nghĩa hàm Lagrangian&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc của hàm Lagrangian \(L(x, u, v)\):&lt;/strong&gt; Cho bài toán \(\min_x f(x)\) với \(h_i(x) \le 0 \; (i=1,\dots,m)\) và \(l_j(x) = 0 \; (j=1,\dots,r)\):
\(L(x, u, v) = f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x).\)
Biến \(u \in \mathbb{R}_+^m\) (không âm) và \(v \in \mathbb{R}^r\) (tự do dấu) gọi là các &lt;strong&gt;nhân tử Lagrange&lt;/strong&gt; hay &lt;strong&gt;biến đối ngẫu&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất chặn dưới trên tập khả thi \(C\):&lt;/strong&gt; Với mọi \(x \in C\) (thỏa \(h_i(x) \le 0, l_j(x) = 0\)) và mọi \(u \ge 0, v \in \mathbb{R}^r\), ta luôn có:
\(L(x, u, v) \le f(x).\)
Đây chính là mầm mống trực tiếp sinh ra tính đối ngẫu yếu ở bài tiếp theo!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính affine theo \((u, v)\) khi cố định \(x\):&lt;/strong&gt; Dù \(f, h_i, l_j\) có phi tuyến và phức tạp đến mức nào theo \(x\), nếu giữ cố định \(x\) thì \(L(x, u, v)\) chỉ là một &lt;strong&gt;hàm bậc nhất (affine)&lt;/strong&gt; theo \((u, v)\). Tính chất đơn giản này là chìa khóa giải thích vì sao hàm đối ngẫu luôn lõm!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-quan-sát-cơ-chế-thưởngphạt-của-lx-u-bằng-con-số-cụ-thể&quot;&gt;Giải thích: Quan sát cơ chế “thưởng–phạt” của \(L(x, u)\) bằng con số cụ thể&lt;/h3&gt;

&lt;p&gt;Xét bài toán \(\min_x f(x) = x^2\) với ràng buộc bất đẳng thức \(h(x) = 1 - x \le 0\) (miền khả thi \(C = [1, +\infty)\)).
Hàm Lagrangian với \(u \ge 0\) là:
\(L(x, u) = x^2 + u(1 - x).\)
Cố định mức giá phạt \(u = 2\), ta được \(L(x, 2) = x^2 - 2x + 2\). So sánh \(L(x, 2)\) với \(f(x) = x^2\) tại ba điểm:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điểm vi phạm ràng buộc \(x = 0 \notin C\) (\(h(0) = +1 &amp;gt; 0\)):&lt;/strong&gt;
\(f(0) = 0, \quad L(0, 2) = 0 + 2(+1) = 2 &amp;gt; f(0).\)
Điểm bất hợp lệ bị cộng thêm khoản phạt \(+2\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm nằm đúng trên biên khả thi \(x = 1 \in C\) (\(h(1) = 0\)):&lt;/strong&gt;
\(f(1) = 1, \quad L(1, 2) = 1 + 2(0) = 1 = f(1).\)
Đồ thị \(L(x, 2)\) chạm tiếp xúc hoàn hảo với \(f(x)\) ngay tại nghiệm tối ưu \(x^* = 1\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm nằm sâu bên trong miền khả thi \(x = 3 \in C\) (\(h(3) = -2 &amp;lt; 0\)):&lt;/strong&gt;
\(f(3) = 9, \quad L(3, 2) = 9 + 2(-2) = 5 &amp;lt; f(3).\)
Trên toàn bộ miền khả thi \(x \ge 1\), ta thấy \(L(x, 2) \le f(x)\), và đáng kinh ngạc hơn nữa: cực tiểu tự do của \(L(x, 2) = (x - 1)^2 + 1\) trên toàn \(\mathbb{R}\) đạt đúng tại \(x = 1\) với giá trị \(1 = f^*\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Xét bài toán tối ưu tổng quát sau (không nhất thiết phải là bài toán lồi):&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{alignat}{1}
\min_x &amp;amp; \quad f(x)  \\\
s.t.   &amp;amp; \quad h_i(x) \leq 0, i = 1,\dots,m \\\
       &amp;amp; \quad l_j(x) = 0, j=1,\dots,r
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Hàm Lagrangian&lt;/strong&gt; tương ứng được định nghĩa như sau:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
L(x,u,v) = f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(u \in \mathbb{R}^m\), \(v \in \mathbb{R}^r\) và \(u \geq 0\) (với quy ước \(L(x,u,v) = -\infty\) nếu có thành phần \(u_i &amp;lt; 0\)).&lt;/p&gt;

&lt;p&gt;Với mọi điểm khả thi \(x\) (thỏa mãn \(h_i(x) \leq 0\) và \(l_j(x) = 0\)) và mọi \(u \geq 0, v\), ta có:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
L(x,u,v) =  f(x) + \sum_{i=1}^{m} u_i \underbrace{h_i(x)}_{\leq 0} + \sum_{j=1}^r v_j \underbrace{l_j(x)}_{=0} \leq f(x)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, hàm Lagrangian có tính chất cơ bản sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Với mọi \(u \geq 0\) và \(v\), ta luôn có \(f(x) \geq L(x,u,v)\) tại mọi điểm khả thi \(x\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Minh họa trong Hình 1:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter11/dual-gen_6.png&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Ví dụ về hàm Lagrangian[1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Đường liền nét biểu diễn hàm mục tiêu \(f\).&lt;/li&gt;
  &lt;li&gt;Đường đứt nét biểu diễn hàm ràng buộc \(h\); tập khả thi xấp xỉ là đoạn \([-0.46, 0.46]\).&lt;/li&gt;
  &lt;li&gt;Các đường chấm biểu diễn hàm \(L(x,u,v)\) ứng với các giá trị \(u \geq 0\) khác nhau.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>11 Tính đối ngẫu trong chương trình tổng quát</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_00_Duality_in_General_Programs/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter11/11_00_Duality_in_General_Programs</id>
   <content type="html">&lt;p&gt;Ở Chương 10, tính đối ngẫu trong quy hoạch tuyến tính hiện lên đẹp như một bộ máy đồng hồ Thụy Sĩ: mọi hàm đều thẳng tắp, mọi ràng buộc đều phẳng lì, và chỉ cần nhân tổ hợp tuyến tính là ta có ngay bài toán đối ngẫu khớp chặt \(p^* = d^*\). Nhưng bước ra ngoài thế giới thực — từ huấn luyện máy vector hỗ trợ (SVM) bậc hai, phân bổ công suất truyền thông logarit, đến tối ưu bền vững theo phân phối (DRO) — hàm mục tiêu và ràng buộc không còn tuyến tính nữa. Liệu phép màu đối ngẫu có sụp đổ khi đường thẳng uốn cong thành parabol, logarit hay thậm chí là những hàm không lồi gồ ghề?&lt;/p&gt;

&lt;p&gt;Chương 11 trả lời câu hỏi đó bằng một trong những khung lý thuyết vĩ đại nhất của giải tích hiện đại: &lt;strong&gt;tính đối ngẫu Lagrange (Lagrange Duality)&lt;/strong&gt;. Bằng cách đưa mọi ràng buộc vào hàm mục tiêu qua &lt;strong&gt;hàm Lagrangian&lt;/strong&gt; \(L(x, u, v)\) rồi cực tiểu hóa tự do theo \(x\), ta không những mở rộng trọn vẹn đối ngẫu LP sang &lt;em&gt;mọi&lt;/em&gt; bài toán tối ưu tổng quát (kể cả không lồi!), mà còn phát hiện ra một sự thật phi thường: &lt;strong&gt;bài toán đối ngẫu Lagrange luôn là bài toán tối ưu lồi&lt;/strong&gt;, bất kể bài toán gốc có rối rắm hay không lồi đến đâu!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tính-đối-ngẫu-trong-bài-toán-tổng-quát&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tính đối ngẫu trong bài toán tổng quát&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Từ đối ngẫu LP đến hàm Lagrangian tổng quát:&lt;/strong&gt; Thay vì chỉ dùng phép tổ hợp tuyến tính cho \(Ax = b, Gx \le h\), hàm Lagrangian \(L(x, u, v) = f(x) + \sum u_i h_i(x) + \sum v_j l_j(x)\) áp dụng cho mọi hàm mục tiêu \(f\) và ràng buộc phi tuyến \(h_i, l_j\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm đối ngẫu Lagrange \(g(u, v) = \inf_x L(x, u, v)\) luôn lõm:&lt;/strong&gt; Vì \(g(u, v)\) là infimum theo từng điểm của một họ các hàm &lt;em&gt;affine&lt;/em&gt; theo \((u, v)\), nó luôn là hàm lõm! Nhờ đó bài toán đối ngẫu \(\max_{u \ge 0, v} g(u, v)\) luôn là bài toán tối ưu lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu yếu (luôn đúng) vs. Đối ngẫu mạnh (cần điều kiện Slater):&lt;/strong&gt; Ta luôn có \(d^* \le p^*\) cho mọi bài toán tối ưu (kể cả không lồi). Với bài toán gốc lồi, chỉ cần tồn tại một điểm khả thi chặt (điều kiện Slater), khoảng cách đối ngẫu bằng đúng \(0\) (\(d^* = p^*\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu và đối ngẫu kép:&lt;/strong&gt; Hiệu \(f(x) - g(u, v)\) vừa là thước đo chất lượng nghiệm trực tuyến để dừng thuật toán, vừa mở đường dẫn sang hệ điều kiện tối ưu KKT ở Chương 12.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bước-nhảy-từ-lp-sang-bài-toán-bậc-hai-qua-hàm-lagrangian&quot;&gt;Giải thích: Bước nhảy từ LP sang bài toán bậc hai qua hàm Lagrangian&lt;/h3&gt;

&lt;p&gt;Xét bài toán phi tuyến đơn giản nhất:
\(\min_{x \in \mathbb{R}} \; f(x) = x^2 \quad \text{s.t.} \quad h(x) = 2 - x \le 0 \; (\text{tức } x \ge 2).\)
Rõ ràng nghiệm gốc là \(x^* = 2\) với \(p^* = 4\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập hàm Lagrangian (nhân tử \(u \ge 0\)):&lt;/strong&gt;
\(L(x, u) = x^2 + u(2 - x) = x^2 - ux + 2u.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm hàm đối ngẫu \(g(u) = \min_{x \in \mathbb{R}} L(x, u)\):&lt;/strong&gt;
Lấy đạo hàm theo \(x\) bằng \(0\): \(2x - u = 0 \implies x(u) = \frac{u}{2}\).
Thay lại vào \(L\):
\(g(u) = \left(\frac{u}{2}\right)^2 - u\left(\frac{u}{2}\right) + 2u = 2u - \frac{u^2}{4}.\)
Chú ý: dù \(f(x) = x^2\) là hàm lồi, \(g(u) = 2u - \frac{u^2}{4}\) là một parabol úp ngược (&lt;strong&gt;hàm lõm&lt;/strong&gt;!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán đối ngẫu \(\max_{u \ge 0} \left(2u - \frac{u^2}{4}\right)\):&lt;/strong&gt;
Đạo hàm \(g&apos;(u) = 2 - \frac{u}{2} = 0 \implies u^* = 4 \ge 0\).
Giá trị đối ngẫu tối ưu: \(d^* = g(4) = 2(4) - \frac{16}{4} = 4 = p^*\)! Không cần bất kỳ ràng buộc tuyến tính nào, cỗ máy Lagrange vẫn bắt chính xác đáy \(4\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;ôn-tập-tính-đối-ngẫu-trong-quy-hoạch-tuyến-tính&quot;&gt;Ôn tập: Tính đối ngẫu trong quy hoạch tuyến tính&lt;/h3&gt;

&lt;p&gt;Cho \(c \in \mathbb{R}^n\), \(A \in \mathbb{R}^{m \times n}\), \(b \in \mathbb{R}^m\), \(G \in \mathbb{R}^{r \times n}\), \(h \in \mathbb{R}^r\).&lt;/p&gt;

&lt;h4 id=&quot;bài-toán-gốc-primal-lp&quot;&gt;Bài toán gốc (Primal LP)&lt;/h4&gt;
&lt;blockquote&gt;

\[\begin{alignat}{1}
\min_{x} &amp;amp; \quad c^T x   \\\\ 
  s.t.   &amp;amp; \quad Ax = b  \\\\
         &amp;amp; \quad Gx \leq h 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;bài-toán-đối-ngẫu-dual-lp&quot;&gt;Bài toán đối ngẫu (Dual LP)&lt;/h4&gt;
&lt;blockquote&gt;

\[\begin{alignat}{1}
\max_{u,v} &amp;amp; \quad -b^T u - h^T v   \\\\
         s.t. &amp;amp; \quad - A^T u - G^T v = c  \\\\
             &amp;amp; \quad v \geq 0 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;cách-giải-thích-1&quot;&gt;Cách giải thích 1&lt;/h3&gt;

&lt;p&gt;Với mọi \(u\), mọi \(v \geq 0\) và mọi \(x\) khả thi của bài toán gốc, ta có:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
u^T (Ax-b) + v^T(Gx-h) \leq 0
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Biến đổi bất đẳng thức này, ta thu được:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
(-A^Tu - G^Tv)^T x \geq -b^Tu - h^T v
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó, nếu \(c = -A^Tu - G^Tv\), thì \(-b^Tu - h^Tv\) là một cận dưới cho giá trị tối ưu của bài toán gốc.&lt;/p&gt;

&lt;h3 id=&quot;cách-giải-thích-2&quot;&gt;Cách giải thích 2&lt;/h3&gt;

&lt;p&gt;Với mọi \(u\), mọi \(v \geq 0\) và mọi \(x\) khả thi của bài toán gốc, ta có:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
c^T x \geq c^T x + u^T (Ax-b) + v^T (Gx -h) := L(x,u,v)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Gọi \(C\) là tập khả thi của bài toán gốc và \(f^*\) là giá trị tối ưu gốc, khi đó:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
f^* \geq \min_{x \in C} L(x,u,v) \geq \min_x L(x,u,v) := g(u,v)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, \(g(u,v)\) luôn là một cận dưới của \(f^*\), với biểu thức tường minh:&lt;/p&gt;

&lt;blockquote&gt;

\[g(u,v) =
\begin{cases}
-b^T u - h^T v &amp;amp; \text{nếu $c=-A^Tu - G^T v$} \\\\
-\infty            &amp;amp; \text{trường hợp khác} 
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;Cách giải thích thứ hai cho ra cùng bài toán đối ngẫu như cách thứ nhất, nhưng hoàn toàn tổng quát và áp dụng được cho mọi bài toán tối ưu bất kỳ (kể cả các bài toán không lồi).&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-hiện-đại-20222026&quot;&gt;Ứng dụng hiện đại (2022–2026)&lt;/h2&gt;

&lt;p&gt;Bài đọc tùy chọn đi kèm trình bày cách sử dụng đối ngẫu Lagrange như tín hiệu huấn luyện hoặc chứng chỉ trong tối ưu bền vững theo phân phối (DRO), mạng nơ-ron giải AC-OPF (DC3 / OPF-DNN), phương pháp quy giảm công bằng của Fairlearn và SVM nhân (kernel SVM). Xem &lt;a href=&quot;/contents/vi/chapter11/11_08_modern_applications/&quot;&gt;11-08 Ứng dụng hiện đại của đối ngẫu Lagrange&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>19-09 Practical Exercises - Proximal Newton Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_09_Practical_Exercises_Proximal_Newton_Methods/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_09_Practical_Exercises_Proximal_Newton_Methods</id>
   <content type="html">&lt;p&gt;When you move from 1D textbook examples to 2D or \(p\)-dimensional composite problems, the biggest practical hurdle is solving the &lt;strong&gt;inner scaled proximal subproblem&lt;/strong&gt; \(\min_v g^T v + \frac{1}{2} v^T H v + \lambda\|x + v\|_1\) when \(H\) has off-diagonal entries. Before tackling the exercises below, walk through this concrete 2D warm-up showing how cyclic coordinate descent solves a coupled scaled prox in closed-form scalar steps—the exact inner loop inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-core-skills-for-the-proximal-newton-exercises&quot;&gt;Key ideas: Core Skills for the Proximal Newton Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Formulating the Subproblem:&lt;/strong&gt; Extract \(\nabla g(x^k)\) and \(H_k = \nabla^2 g(x^k)\) cleanly, then write the composite quadratic model in either displacement form (\(v\)) or next-iterate form (\(z = x^k + v\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solving Coupled Scaled Prox via Coordinate Descent:&lt;/strong&gt; Holding all coordinates \(v_j \; (j \neq i)\) fixed turns coordinate \(i\)’s subproblem into a 1D soft-thresholding step with denominator \(H_{ii}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Backtracking &amp;amp; Convergence Diagnostics:&lt;/strong&gt; Implement the single-prox backtracking check \(f(x + tv) \le f(x) + \alpha t \nabla g(x)^T v + \alpha(h(x + tv) - h(x))\) and verify quadratic error contraction on log-scale plots.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Projected Newton Safeguards:&lt;/strong&gt; Recognize when binding-set diagonalization is needed for box constraints \(x \ge 0\) to prevent Euclidean projection from destroying descent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-coordinate-descent-sweep-on-a-coupled-2d-scaled-prox&quot;&gt;Worked example: One Coordinate-Descent Sweep on a Coupled 2D Scaled Prox&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Suppose at \(x = (0, 0)^T\) we must solve the coupled proximal Newton subproblem with \(\nabla g(0) = (-3, -3)^T\), \(H = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}\), and $$h(v) =&lt;/td&gt;
      &lt;td&gt;v_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;v_2&lt;/td&gt;
      &lt;td&gt;$$:&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;$$\min_{v_1, v_2} \; -3v_1 - 3v_2 + v_1^2 + v_1 v_2 + v_2^2 +&lt;/td&gt;
      &lt;td&gt;v_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;v_2&lt;/td&gt;
      &lt;td&gt;.$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Update coordinate \(v_1\) (holding \(v_2 = 0\)):&lt;/strong&gt;
\(\min_{v_1} \; (-3 + 1 \cdot 0)v_1 + \frac{1}{2}(2)v_1^2 + |v_1| \implies v_1 = S_{1/2}\!\left(\frac{3 - 0}{2}\right) = S_{0.5}(1.5) = 1.0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update coordinate \(v_2\) (holding \(v_1 = 1.0\)):&lt;/strong&gt;
The linear term shifts to \(-3 + H_{21} v_1 = -3 + 1(1.0) = -2\):
\(\min_{v_2} \; -2v_2 + \frac{1}{2}(2)v_2^2 + |v_2| \implies v_2 = S_{1/2}\!\left(\frac{2}{2}\right) = S_{0.5}(1.0) = 0.5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with the exact subproblem solution:&lt;/strong&gt;
By symmetry, the exact solution satisfies \(2v^\star + v^\star - 3 + 1 = 0 \implies v_1^\star = v_2^\star = \frac{2}{3} \approx 0.667\). Just &lt;em&gt;one&lt;/em&gt; coordinate sweep brought \((0, 0) \to (1.0, 0.5)\), and a second sweep gives \((0.75, 0.625)\)—converging geometrically in microseconds without ever inverting \(H\)! Now dive into the exercises below.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---proximal-newton-methods&quot;&gt;Practical Exercises - Proximal Newton Methods&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Lee et al. (2014) and Rakotomamonjy et al. (2016).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-1-proximal-newton-step&quot;&gt;📝 &lt;strong&gt;Exercise 1: Proximal Newton Step&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Given \(f(x) + g(x)\) with \(f(x) = x^2\), $$g(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the proximal Newton subproblem&lt;br /&gt;
b) Solve it at \(x^{(k)} = 2\)&lt;br /&gt;
c) Compare with proximal gradient&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Proximal Newton:**

$$x^{(k+1)} = \arg\min_x \left\{ f(x^{(k)}) + \nabla f(x^{(k)})^T(x - x^{(k)}) + \frac{1}{2}(x - x^{(k)})^T \nabla^2 f(x^{(k)})(x - x^{(k)}) + g(x) \right\}$$

$$= \arg\min_x \left\{ \frac{H_k}{2}(x - x^{(k)})^2 + \nabla f(x^{(k)})(x - x^{(k)}) + g(x) \right\}$$

---

**b) At $$x^{(k)} = 2$$:**

$$\nabla f(2) = 4$$, $$\nabla^2 f(2) = 2$$

$$\min_x \left\{ (x - 2)^2 + 4(x - 2) + |x| \right\}$$

$$= \min_x \left\{ x^2 - 4x + 4 + 4x - 8 + |x| \right\}$$

$$= \min_x \left\{ x^2 - 4 + |x| \right\}$$

**Case 1:** $$x \geq 0$$: $$\min x^2 + x - 4$$, the unconstrained minimizer is $$x = -0.5$$ (infeasible)

**Case 2:** $$x &amp;lt; 0$$: $$\min x^2 - x - 4$$, the unconstrained minimizer is $$x = 0.5$$ (infeasible)

**Check the boundary:** $$x = 0$$: $$-4$$

**Optimal:** $$x^{(1)} = 0$$

---

**c) Proximal GD:**

$$x^{(k+1)} = \text{prox}_{t|·|}(x^{(k)} - t\nabla f(x^{(k)}))$$

$$= \text{prox}_{t|·|}(2 - 4t) = S_t(2 - 4t)$$

With $$t = 0.5$$: $$S_{0.5}(0) = 0$$

**Same result!** (for this simple case)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-lasso-proximal-newton&quot;&gt;📝 &lt;strong&gt;Exercise 2: LASSO Proximal Newton&lt;/strong&gt;&lt;/h2&gt;

\[\min \frac{1}{2}\|Ax - b\|^2 + \lambda\|x\|_1\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Identify the active/inactive variables&lt;br /&gt;
b) Apply Newton on the active set&lt;br /&gt;
c) Handle sign changes&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Active set:**

$$\mathcal{A} = \{i : x_i \neq 0\}$$, $$\mathcal{I} = \{i : x_i = 0\}$$

**KKT:** $$\nabla f(x) + \lambda \cdot \text{sign}(x) = 0$$ on $$\mathcal{A}$$

---

**b) Newton on $$\mathcal{A}$$:**

$$\min_{x_{\mathcal{A}}} \frac{1}{2}\|A_{\mathcal{A}}x_{\mathcal{A}} - b\|^2 + \lambda\|x_{\mathcal{A}}\|_1$$

with $$\text{sign}(x_{\mathcal{A}})$$ fixed:

$$\nabla^2 f_{\mathcal{A}} \Delta x = -\nabla f_{\mathcal{A}} - \lambda \cdot \text{sign}(x_{\mathcal{A}})$$

$$\Delta x = -(A_{\mathcal{A}}^T A_{\mathcal{A}})^{-1}(A_{\mathcal{A}}^T(A_{\mathcal{A}}x - b) + \lambda \cdot \text{sign}(x_{\mathcal{A}}))$$

---

**c) Sign changes:**

If $$x_i^{\text{new}} \cdot x_i^{\text{old}} &amp;lt; 0$$ → truncate the step:

$$\alpha_{\max} = \min_{i:\, x_i^{\text{old}} \Delta x_i &amp;lt; 0} \frac{-x_i^{\text{old}}}{\Delta x_i}$$

**Safe update:** $$x^{(k+1)} = x^{(k)} + 0.99\,\min(1, \alpha_{\max}) \Delta x$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-semismooth-newton&quot;&gt;📝 &lt;strong&gt;Exercise 3: Semismooth Newton&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Given \(F(x) = \nabla f(x) + \partial g(x) \ni 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Define the generalized Jacobian&lt;br /&gt;
b) Apply it to \(g(x) = \|x\|_1\)&lt;br /&gt;
c) Show superlinear convergence&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Generalized Jacobian:**

$$\partial F(x) = \nabla^2 f(x) + \partial^2 g(x)$$

where $$\partial^2 g$$ is a set-valued second derivative (informal notation; in practice one works with the generalized Jacobian of the proximal-map residual).

---

**b) For $$g(x) = \|x\|_1$$:**

$$\partial g(x)_i = \begin{cases}
\text{sign}(x_i) &amp;amp; \text{if } x_i \neq 0 \\
[-1, 1] &amp;amp; \text{if } x_i = 0
\end{cases}$$

$$\partial^2 g(x)_i = \begin{cases}
0 &amp;amp; \text{if } x_i \neq 0 \\
\{0\} \cup \{\infty \cdot \text{sign}\} &amp;amp; \text{if } x_i = 0
\end{cases}$$

**Newton direction:** choose an element of $$\partial F(x)$$.

---

**c) Convergence:**

**Semismooth:** $$\|F(x + d) - F(x) - V_x d\| = o(\|d\|)$$

with $$V_x \in \partial F(x)$$.

**Result:** superlinear convergence, as for the smooth Newton method!

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-regularization-path&quot;&gt;📝 &lt;strong&gt;Exercise 4: Regularization Path&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Track the solution \(x^*(\lambda)\) as \(\lambda\) varies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Derive the path derivative \(\frac{dx^*}{d\lambda}\)&lt;br /&gt;
b) Predict the new solution&lt;br /&gt;
c) Apply warm-start&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Implicit differentiation:**

KKT: $$\nabla f(x^*) + \lambda v^* = 0$$ with $$v^* \in \partial g(x^*)$$

Differentiate with respect to $$\lambda$$:

$$\nabla^2 f(x^*) \frac{dx^*}{d\lambda} + v^* + \lambda \frac{dv^*}{d\lambda} = 0$$

On the active set ($$v^* = \text{sign}(x^*)$$ is locally constant, so $$\frac{dv^*}{d\lambda} = 0$$):

$$\frac{dx^*_{\mathcal{A}}}{d\lambda} = -(\nabla^2 f_{\mathcal{A}\mathcal{A}})^{-1} v^*_{\mathcal{A}}$$

---

**b) Prediction:**

$$x^*(\lambda + \Delta\lambda) \approx x^*(\lambda) + \frac{dx^*}{d\lambda} \Delta\lambda$$

$$= x^*(\lambda) - (\nabla^2 f)^{-1} v^* \Delta\lambda$$

---

**c) Warm-start:**

Use the prediction as the initial point for $$\lambda + \Delta\lambda$$.

**Fewer iterations needed!**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-adaptive-regularization&quot;&gt;📝 &lt;strong&gt;Exercise 5: Adaptive Regularization&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Adjust the regularization in the inner loop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Levenberg-Marquardt style: \(\nabla^2 f + \mu I\)&lt;br /&gt;
b) Choose \(\mu\) based on the reduction ratio&lt;br /&gt;
c) Compare with a fixed Hessian&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Modified subproblem:**

$$\min_d \left\{ \frac{1}{2}d^T(\nabla^2 f + \mu I)d + \nabla f^T d + g(x + d) \right\}$$

$$\mu &amp;gt; 0$$ ensures positive definiteness.

---

**b) Trust-region logic:**

$$\rho = \frac{\text{actual reduction}}{\text{predicted reduction}}$$

- $$\rho &amp;gt; 0.75$$: decrease $$\mu$$ (closer to Newton)
- $$\rho &amp;lt; 0.25$$: increase $$\mu$$ (closer to GD)

---

**c) Benefits:**

**Fixed Hessian:** may fail if $$\nabla^2 f$$ is indefinite.

**Adaptive $$\mu$$:** guaranteed descent, robust.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Key Feature&lt;/th&gt;
      &lt;th&gt;Best for&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Proximal Newton&lt;/td&gt;
      &lt;td&gt;Quadratic model + prox&lt;/td&gt;
      &lt;td&gt;\(\ell_1\), group sparsity&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Active set&lt;/td&gt;
      &lt;td&gt;Fix signs, smooth Newton&lt;/td&gt;
      &lt;td&gt;LASSO path&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Semismooth&lt;/td&gt;
      &lt;td&gt;Generalized Jacobian&lt;/td&gt;
      &lt;td&gt;Non-differentiable&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Regularized&lt;/td&gt;
      &lt;td&gt;\(\nabla^2 f + \mu I\)&lt;/td&gt;
      &lt;td&gt;Ill-conditioned&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Lee, J. D., et al. (2014). “Proximal Newton-type methods”. &lt;em&gt;NeurIPS&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Rakotomamonjy, A., et al. (2016). “Efficient Proximal Newton”. &lt;em&gt;ICML&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>19-07 Projected Newton method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_07_Projected_Newton_method/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_07_Projected_Newton_method</id>
   <content type="html">&lt;p&gt;Here is a trap that catches almost every graduate student the first time they try to add box constraints \(x \ge 0\) to Newton’s method: &lt;em&gt;“For gradient descent, we just project \(x - t\nabla g(x)\) onto \(C\). So for Newton’s method, can’t we just project \(x - H^{-1}\nabla g(x)\) onto \(C\)?”&lt;/em&gt; &lt;strong&gt;NO!&lt;/strong&gt; Because the Newton direction is only guaranteed to descend in the &lt;em&gt;\(H\)-metric&lt;/em&gt;, applying a &lt;em&gt;Euclidean&lt;/em&gt; projection \(\Pi_C\) can twist the direction past \(90^\circ\) from \(-\nabla g(x)\) and turn it into an &lt;strong&gt;ascent direction&lt;/strong&gt;! Dimitri Bertsekas’s &lt;strong&gt;Projected Newton method&lt;/strong&gt; fixes this brilliantly by decoupling the &lt;em&gt;binding&lt;/em&gt; (active) coordinates from the &lt;em&gt;free&lt;/em&gt; coordinates.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-naive-projection-fails-and-how-bertsekas-fixes-it&quot;&gt;Key ideas: Why Naive Projection Fails and How Bertsekas Fixes It&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Metric Mismatch of Naive Projected Newton:&lt;/strong&gt; Proximal Newton for \(h = I_C\) solves \(\min_{z \in C} \|x - H^{-1}\nabla g(x) - z\|_H^2\) (an oblique \(H\)-projection, which is a full QP). Replacing \(\|\cdot\|_H\) with Euclidean \(\|\cdot\|_2\) breaks the optimality geometry and can increase \(g(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Binding vs. Free Variables (\(x \ge 0\)):&lt;/strong&gt; For nonnegativity constraints, a coordinate \(i\) is in the &lt;strong&gt;binding set&lt;/strong&gt; \(\mathcal{B}(x)\) if \(x_i = 0\) (or \(\le \epsilon\)) &lt;em&gt;and&lt;/em&gt; \(\nabla_i g(x) &amp;gt; 0\) (meaning the negative gradient pushes it straight into the wall). All other coordinates are &lt;strong&gt;free&lt;/strong&gt; (\(\mathcal{F}(x)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Block-Diagonal Hessian Scaling (Bertsekas 1982):&lt;/strong&gt; By zeroing out the off-diagonal couplings between \(\mathcal{B}(x)\) and \(\mathcal{F}(x)\) in the Hessian inverse (keeping a positive diagonal on \(\mathcal{B}\) and the exact inverse \(H_{\mathcal{F}\mathcal{F}}^{-1}\) on \(\mathcal{F}\)), Euclidean projection \(\Pi_C(x - t D \nabla g(x))\) is &lt;em&gt;mathematically guaranteed&lt;/em&gt; to be a descent direction!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Superlinear Speed on Box Constraints:&lt;/strong&gt; Once the active face \(\mathcal{B}(x^\star)\) is identified, Bertsekas’s projected Newton takes exact full Newton steps on the free subspace \(\mathcal{F}(x^\star)\) while clamping \(\mathcal{B}(x^\star)\) at zero—giving quadratic local convergence with trivial \(O(n)\) Euclidean projection!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-catching-naive-projected-newton-going-uphill&quot;&gt;Worked example: Catching Naive Projected Newton Going Uphill!&lt;/h3&gt;

&lt;p&gt;Minimize \(g(x) = \frac{1}{2} x^T H x + c^T x\) over the nonnegative orthant \(C = \{x \in \mathbb{R}^2 : x_1 \ge 0, x_2 \ge 0\}\), where:
\(H = \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 5 \end{bmatrix} \succ 0, \qquad c = \begin{bmatrix} 1 \\ 1 \end{bmatrix}.\)
Notice at \(x = (0, 0)^T\), \(\nabla g(0) = (1, 1)^T &amp;gt; 0\), so \(x = (0, 0)^T\) is &lt;strong&gt;already the unique global minimizer&lt;/strong&gt; (\(g(0) = 0\), and \(g(x) &amp;gt; 0\) for all \(x \ge 0, x \neq 0\))!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the unconstrained Newton step from \(x = (0, 0)^T\):&lt;/strong&gt;
Since \(\det(H) = 5 - 4 = 1\), \(H^{-1} = \begin{bmatrix} 5 &amp;amp; -2 \\ -2 &amp;amp; 1 \end{bmatrix}\). Thus:
\(p_N = -H^{-1}\nabla g(0) = -\begin{bmatrix} 5 &amp;amp; -2 \\ -2 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} -3 \\ +1 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply naive Euclidean projection \(\Pi_C(x + t p_N)\) for any \(t &amp;gt; 0\):&lt;/strong&gt;
\(z_{\text{naive}}(t) = \Pi_{\mathbb{R}_+^2}\!\begin{bmatrix} -3t \\ t \end{bmatrix} = \begin{bmatrix} 0 \\ t \end{bmatrix}.\)
Evaluate the objective at \(z_{\text{naive}}(t)\):
\(g(0, t) = \frac{5}{2} t^2 + t &amp;gt; 0 = g(0, 0) \quad \text{for ALL } t &amp;gt; 0!\)
Naive projected Newton walks strictly &lt;strong&gt;uphill&lt;/strong&gt; from the exact optimum for &lt;em&gt;every&lt;/em&gt; positive step size!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply Bertsekas’s Projected Newton fix:&lt;/strong&gt;
At \(x = (0, 0)^T\), both \(x_1 = 0, \nabla_1 g = 1 &amp;gt; 0\) and \(x_2 = 0, \nabla_2 g = 1 &amp;gt; 0\) belong to the binding set \(\mathcal{B} = \{1, 2\}\). Bertsekas replaces \(H\) on \(\mathcal{B}\) by its positive diagonal \(D_{\mathcal{B}} = \operatorname{diag}(1, 5)\), giving direction \(-D_{\mathcal{B}}^{-1}\nabla g(0) = (-1, -0.2)^T\). Projecting onto \(\mathbb{R}_+^2\) yields \((0, 0)^T\)—staying locked at the true optimum immediately!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;whats-wrong-with-projected-newton&quot;&gt;What’s wrong with projected Newton?&lt;/h2&gt;
&lt;p&gt;When \(h\) is the indicator function \(h = I_C(x)\) of a convex set \(C\), the problem becomes&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} \ g(x) \quad  \text{subject to}  \quad  x \in C\]
&lt;/blockquote&gt;

&lt;p&gt;Hence, when \(h(x) = I_C(x)\), proximal gradient descent becomes &lt;strong&gt;projected gradient descent&lt;/strong&gt;. That is, projected gradient descent is a special case of proximal gradient descent.&lt;/p&gt;

&lt;p&gt;What about proximal Newton when \(h(x) = I_C(x)\)? In this case the update is&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
z^{+} &amp;amp; =\underset{z \in C}{\text{argmin}} \ \frac{1}{2} \parallel x - H^{-1} \nabla g(x) - z \parallel_H^2  \\\\
&amp;amp;= \underset{z \in C}{\text{argmin}} \ \nabla g(x)^T (z - x) + \frac{1}{2} (z - x)^T H (z - x)  \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;If \(H = I\), this is the projection of \(x - \nabla g(x)\) onto the set \(C\), but for a general \(H \neq I\) it is not a projection. (If \(H = I\) the \(H\)-norm is the \(l_2\)-norm; a projection would require the plain \(l_2\)-norm rather than the \(H\)-norm.)
Therefore, the projected Newton method is not a special case of the proximal Newton method.&lt;/p&gt;

&lt;h2 id=&quot;projected-newton-for-box-constraints&quot;&gt;Projected Newton for box constraints&lt;/h2&gt;
&lt;p&gt;In the special case of box constraints, projected Newton can be applied (Bertsekas, 1982; Kim et al., 2010; Schmidt et al., 2011).&lt;/p&gt;

&lt;p&gt;Consider the problem&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x} \ g(x) \quad  \text{subject to}  \quad  l \le x \le u\]
&lt;/blockquote&gt;

&lt;p&gt;Given a starting point \(x^{(0)}\) and a small constant \(\epsilon \gt 0\), the projected Newton method repeats the following steps (\(k = 1, 2, 3, ...\)).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Step 1: Define the binding set.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
B_{k-1} &amp;amp; = \{ i : x_i^{(k-1)} \le l_i + \epsilon \quad \text{and} \quad  \nabla_i g(x^{(k-1)}) \gt 0 \} \quad  \cup \quad 
\{ i : x_i^{(k-1)} \ge u_i - \epsilon  \quad \text{and} \quad  \nabla_i g(x^{(k-1)}) \lt 0 \} 
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the optimization step, these variables are pushed to the boundary of the box. The more of them we push, the smaller the objective becomes.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Step 2: Define the free set \(F_{k-1} = \left\{1,....,n \right\} \backslash B_{k-1}\).&lt;/li&gt;
  &lt;li&gt;Step 3: Compute the inverse of the principal submatrix of the Hessian over the free variables.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[S^{(k-1)} = [(\nabla^2 g(x^{(k-1)}))_{F_{k-1}}]^{-1}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Step 4: Take a Newton step over the free variables and project.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\begin{align}
x^{(k)} = P_{[l, u]} \left( x^{(k-1)} - t_k \begin{bmatrix} S^{(k-1)} &amp;amp; 0 \\
0 &amp;amp; I \end{bmatrix} 
\begin{bmatrix} \nabla_{F_{k-1}} g(x^{(k-1)}) \\ \nabla_{B_{k-1}} g(x^{(k-1)}) \end{bmatrix}
\right)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(P_{[l,u]}\) is the projection onto \([l, u] = [l_1, u_1] \times \cdots \times [l_n, u_n]\).&lt;/p&gt;

&lt;p&gt;In the matrix expression, a Newton step is taken for the free variables, while for the binding variables a plain gradient step is taken. Also, the projection is a simple operation: for each coordinate outside the box, we simply set it to the appropriate \(l_i\) or \(u_i\).&lt;/p&gt;

&lt;p&gt;This method is appropriate when the problem is very large (e.g., high-dimensional) and most variables are near the boundary, so that the free set is very small.&lt;/p&gt;

&lt;p&gt;What kinds of problems have box constraints? Quite a lot of them do, for example:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nonnegative least squares&lt;/li&gt;
  &lt;li&gt;Support vector machine dual&lt;/li&gt;
  &lt;li&gt;Graphical lasso dual&lt;/li&gt;
  &lt;li&gt;Fused lasso (total variation denoising) dual&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;convergence-properties&quot;&gt;Convergence properties&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Bertsekas (1982) showed that, under suitable assumptions, projected Newton identifies the correct binding constraints after a finite number of iterations. From then on it coincides with Newton’s method on the free variables.&lt;/li&gt;
  &lt;li&gt;Bertsekas (1982) also proved superlinear convergence.&lt;/li&gt;
  &lt;li&gt;Kim et al. (2010) and Schmidt et al. (2011) proposed projected quasi-Newton methods using BFGS-style updates.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>19-06 Proximal quasi-Newton methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_06_Proximal_quasi_Newton_methods/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_06_Proximal_quasi_Newton_methods</id>
   <content type="html">&lt;p&gt;What happens when \(g(x)\) has \(p = 50{,}000\) variables, so computing and storing \(\nabla^2 g(x)\) is out of the question, yet proximal gradient descent is still crawling? You marry Chapter 18 (Quasi-Newton) with Chapter 19 (Proximal Newton) to obtain &lt;strong&gt;Proximal Quasi-Newton methods&lt;/strong&gt;: replace the exact Hessian \(\nabla^2 g(x)\) inside the scaled proximal map by a BFGS, L-BFGS, or block-diagonal curvature matrix \(B_k\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-replacing-exact-hessians-in-composite-optimization&quot;&gt;Key ideas: Replacing Exact Hessians in Composite Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Proximal BFGS &amp;amp; L-BFGS (Lee, Sun, Saunders 2014):&lt;/strong&gt; Maintains a positive-definite secant matrix \(B_k\) using only gradients of \(g\), solving \(\min_v \nabla g(x^k)^T v + \frac{1}{2} v^T B_k v + h(x^k + v)\). When \(B_k\) satisfies the Dennis–Moré condition, it achieves &lt;strong&gt;local superlinear convergence&lt;/strong&gt; without ever computing a second derivative!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Blockwise / Diagonal Hessian Approximations (Tseng &amp;amp; Yun 2009):&lt;/strong&gt; When \(h(x) = \sum_b h_b(x_b)\) is block-separable, choosing \(B_k\) to be block-diagonal decouples the scaled proximal subproblem into tiny independent blocks—combining fast per-iteration cost with linear convergence.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Handling Singular or Indefinite Hessians:&lt;/strong&gt; On high-dimensional problems with \(p &amp;gt; n\), the true Hessian \(\nabla^2 g(x)\) is rank-deficient (singular), causing exact proximal Newton subproblems to become unbounded unless regularized; BFGS automatically stays strictly positive definite (\(B_k \succ 0\)) whenever \(y_k^T s_k &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fast Subproblem Solves with L-BFGS Compact Form:&lt;/strong&gt; Because an L-BFGS matrix \(B_k = \gamma_k I - U_k M_k U_k^T\) is a diagonal matrix plus a rank-\(2m\) update, its scaled proximal subproblem can be solved efficiently in the dual space of dimension \(2m \ll p\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-proximal-bfgs-step-without-second-derivatives&quot;&gt;Worked example: One Proximal-BFGS Step Without Second Derivatives&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize $$f(x) = g(x) +&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\(where we only observe gradients of\)g\(. Suppose from step 0 we recorded\)s_0 = (1, 0)^T\(and\)y_0 = \nabla g(x^1) - \nabla g(x^0) = (4, 0)^T\(starting from\)B_0 = I_2\(, and at\)x^1 = (1, 1)^T\(the gradient is\)\nabla g(x^1) = (3, 2)^T$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Update the Hessian approximation \(B_1\) via BFGS (no second derivatives!):&lt;/strong&gt;
With \(s_0^T B_0 s_0 = 1\) and \(y_0^T s_0 = 4 &amp;gt; 0\):
\(B_1 = I_2 - \frac{s_0 s_0^T}{1} + \frac{y_0 y_0^T}{4} = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} - \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} + \frac{1}{4}\begin{bmatrix} 16 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form the Proximal-BFGS subproblem at \(x^1 = (1, 1)^T\):&lt;/strong&gt;
\(v^{(1)} = \arg\min_{v_1, v_2} \; \left(3v_1 + 2v_1^2 + |1 + v_1|\right) + \left(2v_2 + \tfrac{1}{2}v_2^2 + |1 + v_2|\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve using the scaled prox formula \(z = \operatorname{prox}_{B_1}(x^1 - B_1^{-1}\nabla g(x^1))\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Unconstrained quasi-Newton target: \(x^1 - B_1^{-1}\nabla g(x^1) = \begin{bmatrix} 1 \\ 1 \end{bmatrix} - \begin{bmatrix} 3/4 \\ 2 \end{bmatrix} = \begin{bmatrix} 0.25 \\ -1.0 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;Apply coordinate-wise soft-thresholding with thresholds \(1/B_{1,11} = 0.25\) and \(1/B_{1,22} = 1.0\):
\(z_1 = S_{0.25}(0.25) = 0, \qquad z_2 = S_{1.0}(-1.0) = 0!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Result:&lt;/strong&gt;
The BFGS curvature estimate \(B_{1,11} = 4\) prevented overshooting coordinate 1 and landed cleanly at \(x^2 = (0, 0)^T\)—identifying the exact sparse support \(\emptyset\) in a single proximal quasi-Newton step!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As problems grow larger, computing the Hessian becomes very expensive. &lt;strong&gt;Proximal quasi-Newton methods&lt;/strong&gt; avoid computing the Hessian \(H^{(k-1)} = \nabla^2 g(x^{(k-1)})\) at each step, while still achieving a superlinear or linear convergence rate.&lt;/p&gt;

&lt;h2 id=&quot;proximal-quasi-newton-method&quot;&gt;Proximal quasi-Newton method&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Lee (2014) proposed updating the Hessian approximation in the BFGS style. This method works very well and has a local superlinear convergence rate.&lt;/li&gt;
  &lt;li&gt;Tseng and Yun (2009) proposed approximating the Hessian blockwise. This works only when \(f = g + h\) can be split into parts in which \(h\) depends on only some of the optimization variables. Computing the Hessian blockwise is much faster. This method has a linear convergence rate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quasi-Newton methods are useful not only when the Hessian is hard to compute, but also in ill-conditioned problems where the Hessian is singular or nearly singular.&lt;/p&gt;

&lt;h4 id=&quot;references&quot;&gt;References&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;J. Lee and Y. Sun and M. Saunders (2014), “Proximal Newton-type methods for minimizing composite functions”&lt;/li&gt;
  &lt;li&gt;P. Tseng and S. Yun (2009), “A coordinate gradient descent method for nonsmooth separable minimization”&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>19-05 Notable examples</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_05_Notable_examples/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_05_Notable_examples</id>
   <content type="html">&lt;p&gt;Two of the most widely downloaded statistical software packages in history—&lt;strong&gt;glmnet&lt;/strong&gt; (for \(\ell_1\)-penalized generalized linear models) and &lt;strong&gt;QUIC&lt;/strong&gt; (for sparse inverse covariance estimation, or Graphical Lasso)—are not mysterious black boxes; both are pure, textbook instances of &lt;strong&gt;Proximal Newton&lt;/strong&gt; paired with fast coordinate descent for the inner quadratic subproblem! Seeing how each one builds its local quadratic model reveals why proximal Newton crushed first-order competitors on real statistical benchmarks.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-inside-glmnet-and-quic&quot;&gt;Key ideas: Inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt;&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;IRLS Meets Lasso (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;):&lt;/strong&gt; For \(\ell_1\)-penalized logistic regression, the second-order Taylor expansion of the negative log-likelihood around \(\beta^k\) is literally a &lt;em&gt;weighted least-squares&lt;/em&gt; (Lasso) objective with diagonal weights \(W_{ii} = p_i(1 - p_i)\), solved rapidly by warm-started cyclic coordinate descent.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrix-Valued Proximal Newton (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt;):&lt;/strong&gt; Graphical Lasso minimizes \(-\log\det\Theta + \operatorname{tr}(S\Theta) + \lambda\|\Theta\|_1\) over \(\Theta \succ 0\). Its Hessian is the Kronecker operator \(\Theta^{-1} \otimes \Theta^{-1}\); QUIC exploits Cholesky factors \(W = \Theta^{-1}\) to run coordinate descent on the free active set of off-diagonal entries without ever forming the \(p^2 \times p^2\) Hessian!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Active-Set Shrinking:&lt;/strong&gt; In both &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt;, KKT conditions identify coordinates that are guaranteed to remain zero (the “fixed set”), allowing coordinate descent to work solely on the tiny free set of nonzero parameters.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why PN Beats FISTA &amp;amp; SpaRSA on Logistic Lasso:&lt;/strong&gt; When the data matrix \(X\) is large or correlated, FISTA must recompute full exponentials \(e^{X\beta}\) hundreds of times; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; evaluates exponentials only a handful of outer Newton iterations while letting cheap linear coordinate updates do the heavy lifting.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-glmnet-outer-iteration-for-ell_1-logistic-regression&quot;&gt;Worked example: One &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; Outer Iteration for \(\ell_1\) Logistic Regression&lt;/h3&gt;

&lt;p&gt;Consider 1D \(\ell_1\)-penalized logistic regression with \(\lambda = 0.2\) on two data points \((a_1, y_1) = (1, 1)\) and \((a_2, y_2) = (-1, 0)\):
\(f(\beta) = \underbrace{\sum_{i=1}^2 \Big[\log(1 + e^{a_i \beta}) - y_i a_i \beta\Big]}_{g(\beta)} + \underbrace{0.2|\beta|}_{h(\beta)}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate probabilities, gradient, and Hessian at \(\beta^0 = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Predicted probabilities: \(p_1 = p_2 = \frac{1}{1 + e^0} = 0.5\).&lt;/li&gt;
      &lt;li&gt;IRLS weights: \(w_1 = w_2 = p_i(1 - p_i) = 0.25\).&lt;/li&gt;
      &lt;li&gt;Gradient: \(g&apos;(0) = (p_1 - y_1)a_1 + (p_2 - y_2)a_2 = (0.5 - 1)(1) + (0.5 - 0)(-1) = -1.0\).&lt;/li&gt;
      &lt;li&gt;Hessian: \(H(0) = w_1 a_1^2 + w_2 a_2^2 = 0.25(1) + 0.25(1) = 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; inner weighted-Lasso subproblem:&lt;/strong&gt;
\(v^{(1)} = \arg\min_v \; g&apos;(0) v + \frac{1}{2} H(0) v^2 + 0.2|0 + v| = \arg\min_v \; -v + 0.25 v^2 + 0.2|v|.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve via soft-thresholding:&lt;/strong&gt;
For \(v &amp;gt; 0\), \(-1 + 0.5v + 0.2 = 0 \implies v^{(1)} = \frac{0.8}{0.5} = +1.6\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify decrease at \(\beta^1 = 1.6\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(0) = 2\ln 2 \approx 1.3863\).&lt;/li&gt;
      &lt;li&gt;\(f(1.6) = 2\ln(1 + e^{-1.6}) + 0.2(1.6) \approx 2(0.1839) + 0.32 = 0.6878 &amp;lt; 1.3863\) \(\checkmark\)!
(Exact optimum is \(\beta^\star = \ln(9) \approx 2.1972\) with \(f(\beta^\star) \approx 0.6502\)—just one &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; step captured \(95\%\) of the total objective reduction!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;glmnet-and-quic&quot;&gt;Glmnet and QUIC&lt;/h2&gt;
&lt;p&gt;There are two very well-known packages built on the proximal Newton method.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;glmnet&lt;/strong&gt; (Friedman et al., 2009): implements prox Newton for \(l_1\)-penalized generalized linear models. The inner problem is solved with coordinate descent.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;QUIC&lt;/strong&gt; (Hsieh et al., 2011): implements prox Newton for the graphical lasso problem. It uses a factorization trick and solves the inner problem with coordinate descent.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both packages are widely used for their respective purposes and can be regarded as state of the art.&lt;/p&gt;

&lt;p&gt;The proximal Newton method evaluates the gradient of \(g\) less often than proximal gradient descent. Therefore, the more expensive \(g\) is to compute, the more advantageous proximal Newton becomes. Careful choice of the inner solver also leads to better performance.&lt;/p&gt;

&lt;h2 id=&quot;example-lasso-logistic-regression&quot;&gt;Example: lasso logistic regression&lt;/h2&gt;
&lt;p&gt;Let us look at the example from Lee et al. (2012).&lt;/p&gt;

&lt;p&gt;For \(l_1\)-regularized logistic regression, the following three methods were compared:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;FISTA: accelerated proximal gradient 2. spaRSA: spectral projected gradient method 3. PN: proximal Newton&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;dense-hessian-n5000-p6000&quot;&gt;Dense Hessian (n=5000, p=6000)&lt;/h4&gt;
&lt;p&gt;The first problem has a dense feature matrix \(X\) with n = 5000 samples and p = 6000 features. Because the Hessian is dense, this is a very challenging problem. The following performance was observed.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter19/09.05_Lasso_Example1.png&quot; alt=&quot;[Fig 1] Dense hessian X (n=5000, p=6000) [2]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Dense hessian X (n=5000, p=6000) [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The right plot measures performance by the number of function evaluations and the left plot by time. In terms of function evaluations, PN is clearly superior.&lt;/p&gt;

&lt;p&gt;Here most of the cost is spent computing \(g\) and \(\nabla g\), in particular evaluating the \(\exp\) and \(\log\) functions.&lt;/p&gt;

&lt;h4 id=&quot;sparse-hessian-n542000-p47000&quot;&gt;Sparse Hessian (n=542,000, p=47,000)&lt;/h4&gt;

&lt;p&gt;In the next case \(X\) is sparse, so computing \(g\) and \(\nabla g\) takes less time.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter19/09.05_Lasso_Example-sparse.png&quot; alt=&quot;[Fig 2] Sparse hessian X (n=542,000, p=47,000) [2]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 2] Sparse hessian X (n=542,000, p=47,000) [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;inexact-prox-evaluations&quot;&gt;Inexact prox evaluations&lt;/h2&gt;
&lt;p&gt;When the proximal Newton method evaluates the proximal operator, the prox generally has no closed form and cannot be computed exactly. Even so, it is a very good property if the prox is computed to high accuracy.&lt;/p&gt;

&lt;p&gt;Lee (2014) proposed stopping rules for the inner problem that guarantee global convergence and local superlinear convergence.&lt;/p&gt;

&lt;h4 id=&quot;three-stopping-rules&quot;&gt;Three stopping rules&lt;/h4&gt;
&lt;p&gt;Three stopping rules for the inner optimization were compared on a graphical lasso estimation problem with n = 72 samples and p = 1255 features.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter19/09.05_Inexact_prox.png&quot; alt=&quot;[Fig 3] Three stopping rules [2]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 3] Three stopping rules [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The three stopping rules are adaptive, maxiter = 10, and exact. Maxiter performs at most 10 inner iterations; exact iterates until the exact solution is found.&lt;/p&gt;

&lt;p&gt;Since the proximal Newton method converges quadratically, the exact rule exhibits quadratic convergence. With maxiter = 10, at most 10 inner iterations are not enough to retain quadratic convergence, whereas the adaptive rule does achieve quadratic convergence and is the fastest of the three.&lt;/p&gt;

&lt;h4 id=&quot;stopping-rule-of-the-usual-newton-method&quot;&gt;Stopping rule of the usual Newton method&lt;/h4&gt;
&lt;p&gt;In the usual Newton’s method, the inner problem minimizes the quadratic approximation \(\tilde{g}_{k-1}\) of \(g\) at \(x^{(k-1)}\). We choose a sequence \(\eta_k, k=1,2,3,...\) (called the forcing sequence) and stop when the following condition holds.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\parallel \nabla \tilde{g}_{k-1}(x^{(k)}) \parallel_2 &amp;amp; \le \eta_k \parallel  \nabla g(x^{(k-1)})  \parallel_2 \&lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This condition says that the gradient of the model at the next point is at most \(\eta_k\) times the gradient at the current point. Here the quadratic approximation is \(\tilde{g}_{k-1}(z) = \nabla g(x^{(k-1)})^T (z-x^{(k-1)}) + \frac{1}{2} (z - x^{(k-1)})^T \nabla^2 g(x^{(k-1)}) (z - x^{(k-1)})\).&lt;/p&gt;

&lt;h4 id=&quot;stopping-rule-of-the-proximal-newton-method&quot;&gt;Stopping rule of the proximal Newton method&lt;/h4&gt;
&lt;p&gt;Lee et al. (2012) proposed using the generalized gradient instead of the gradient for the proximal case.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\parallel G_{\tilde{f}_{k-1}/M}(x^{(k)}) \parallel_2 &amp;amp; \le \eta_k \parallel  G_{f/M}(x^{(k-1)})  \parallel_2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(\tilde{f}_{k-1} = \tilde{g}_{k-1} + h\) and \(mI \preceq \nabla^2 g \preceq MI\).&lt;/p&gt;

&lt;p&gt;They then proved that, if \(\eta_k\) is chosen as follows, the inexact proximal Newton method has a local superlinear rate.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\eta_k \le \min \left\{ \frac{m}{2},  \frac{\parallel  G_{\tilde{f}_{k-2}/M}(x^{(k-1)}) - G_{f/M}(x^{(k-1)})  \parallel_2}{\parallel  G_{f/M}(x^{(k-2)})  \parallel_2} \right\}
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>19-04 Convergence analysis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_04_Convergence_analysis/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_04_Convergence_analysis</id>
   <content type="html">&lt;p&gt;At first glance, proving &lt;strong&gt;quadratic local convergence&lt;/strong&gt; for a nonsmooth function \(f = g + h\) seems impossible—after all, classical Newton’s quadratic proof expands \(\nabla f(x^\star) = 0\) in a Taylor series, and \(\nabla h(x^\star)\) does not even exist! Lee, Sun, and Saunders (2014) cracked this cleanly with one masterstroke: rewrite the optimality condition as a fixed point of the &lt;strong&gt;scaled proximal operator&lt;/strong&gt; \(x^\star = \operatorname{prox}_H(x^\star - H^{-1}\nabla g(x^\star))\), and use its &lt;em&gt;non-expansiveness&lt;/em&gt; to peel \(h\) completely out of the error bound!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-the-leesunsaunders-convergence-proof&quot;&gt;Key ideas: Anatomy of the Lee–Sun–Saunders Convergence Proof&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Regularity Assumptions:&lt;/strong&gt; \(g\) is \(m\)-strongly convex (\(mI \preceq \nabla^2 g(x) \preceq LI\)) with \(M\)-Lipschitz Hessian \(\|\nabla^2 g(x) - \nabla^2 g(y)\| \le M\|x - y\|\), and \(\operatorname{prox}_H\) is solved accurately.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Global Convergence via Composite Backtracking:&lt;/strong&gt; Because \(v^{(k)}\) satisfies \(\Delta_k \le -v_k^T H_k v_k \le -m\|v_k\|_2^2\), backtracking always terminates with a uniformly bounded step size \(t_k \ge \min(1, \beta m / L)\), forcing \(\|v_k\| \to 0\) and therefore global convergence \(x^k \to x^\star\) from any starting point.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-Expansiveness Eliminates \(h\):&lt;/strong&gt; Comparing \(x^{k+1} = \operatorname{prox}_{H_k}(x^k - H_k^{-1}\nabla g(x^k))\) against the fixed point \(x^\star = \operatorname{prox}_{H_k}(x^\star - H_k^{-1}\nabla g(x^\star))\) lets firm non-expansiveness in \(\|\cdot\|_{H_k}\) cancel \(h\) completely, leaving only the smooth Taylor remainder \(\|\nabla g(x^\star) - \nabla g(x^k) - H_k(x^\star - x^k)\| \le \frac{M}{2}\|x^k - x^\star\|^2\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Local Quadratic Rate:&lt;/strong&gt; Combining the non-expansiveness bound with \(mI \preceq H_k\) yields \(\|x^{k+1} - x^\star\|_2 \le \frac{M}{2m}\sqrt{\frac{L}{m}}\|x^k - x^\star\|_2^2\) (and \(\frac{M}{2m}\|x^k - x^\star\|_2^2\) in 1D), matching unconstrained Newton’s method despite the nonsmooth kink!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-local-quadratic-contraction-numerically&quot;&gt;Worked example: Verifying Local Quadratic Contraction Numerically&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Return to $$f(x) = e^x - 4x +&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((exact optimum\)x^\star = \ln 3 \approx 1.0986123\(), starting inside the local quadratic basin at\)x^0 = 1.0\((error\)e_0 =&lt;/td&gt;
      &lt;td&gt;x^0 - x^\star&lt;/td&gt;
      &lt;td&gt;\approx 0.0986123$$).&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute Iteration 1 with unit step \(t = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g&apos;(1.0) = e - 4 \approx -1.2817182\), \(H_0 = g&apos;&apos;(1.0) = e \approx 2.7182818\).&lt;/li&gt;
      &lt;li&gt;Solving \(-1.2817182 + e v_0 + 1 = 0 \implies v_0 = \frac{3 - e}{e} \approx +0.1036383\).&lt;/li&gt;
      &lt;li&gt;\(x^1 = 1.0 + 0.1036383 = 1.1036383\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;New error: $$e_1 =&lt;/td&gt;
              &lt;td&gt;x^1 - x^\star&lt;/td&gt;
              &lt;td&gt;\approx 0.0050260\(! (Error shrank by almost\)20\times$$ in one step!)&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute Iteration 2 with unit step \(t = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g&apos;(1.1036383) = e^{1.1036383} - 4 \approx 3.015116 - 4 = -0.984884\), \(H_1 = 3.015116\).&lt;/li&gt;
      &lt;li&gt;\(v_1 = \frac{3 - 3.015116}{3.015116} \approx -0.0050134 \implies x^2 = 1.0986249\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;New error: $$e_2 =&lt;/td&gt;
              &lt;td&gt;x^2 - x^\star&lt;/td&gt;
              &lt;td&gt;\approx 0.0000126\(! (Error shrank by\)400\times$$—doubling the number of accurate decimal digits!)&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check against the theoretical bound \(e_{k+1} \le \frac{M}{2m} e_k^2\):&lt;/strong&gt;
On \([1.0, 1.11]\), \(m = e^{1.0} \approx 2.718\) and \(M = \sup g&apos;&apos;&apos;(x) = e^{1.11} \approx 3.034\), so \(\frac{M}{2m} \approx 0.558\).
    &lt;ul&gt;
      &lt;li&gt;Predicted bound for \(e_1\): \(0.558 \times (0.0986123)^2 \approx 0.00543 \ge 0.00503 = e_1\) \(\checkmark\).&lt;/li&gt;
      &lt;li&gt;Predicted bound for \(e_2\): \(0.558 \times (0.005026)^2 \approx 0.0000141 \ge 0.0000126 = e_2\) \(\checkmark\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To analyze the convergence of the Proximal Newton method, we will follow the proof from Lee (2014) [1].&lt;/p&gt;

&lt;p&gt;[1] J. Lee and Y. Sun and M. Saunders (2014), Proximal Newton-type methods for minimizing&lt;/p&gt;

&lt;p&gt;To prove convergence, we make the following assumptions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(f = g + h\), \(g\) and \(h\) are convex and \(g\) is twice differentiable (smooth)&lt;/li&gt;
  &lt;li&gt;\(mI \preceq \nabla^2 g(x) \preceq LI\).&lt;/li&gt;
  &lt;li&gt;\(\nabla^2 g(x)\) is Lipschitz with constant \(M\)&lt;/li&gt;
  &lt;li&gt;\(\text{prox}_H(\cdot)\) can be computed exactly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The above three assumptions imply that the function is strictly convex, and assuming that \(\text{prox}_H(\cdot)\) can be computed exactly is because this is not easy to achieve in practice.&lt;/p&gt;

&lt;h2 id=&quot;convergence-theorem&quot;&gt;Convergence Theorem&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Proximal Newton method&lt;/strong&gt; converges globally using backtracking line search.
\begin{align}
\parallel x^{(k)} - x^{\star} \parallel_2 \le \frac{M}{2m} \parallel x^{(k-1)} - x^{\star} \parallel_2^2
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is called &lt;strong&gt;local quadratic convergence&lt;/strong&gt;. After \(k \ge k_0\), to satisfy \(f(x^{(k)}) - f^{\star} \le \epsilon\), \(O(\log \log (1/\epsilon))\) iterations are needed. However, each iteration uses a scaled prox.&lt;/p&gt;

&lt;h2 id=&quot;proof-sketch&quot;&gt;Proof sketch&lt;/h2&gt;
&lt;p&gt;To show &lt;strong&gt;global convergence&lt;/strong&gt;, we can show that at any step, the backtracking exit condition for step size \(t\) is satisfied as follows.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
t \le \min \left\{ 1, \frac{2m}{L} (1-\alpha) \right\} \&lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With this equation, we can show that when the global minimum is reached, the update direction converges to 0.&lt;/p&gt;

&lt;p&gt;To show &lt;strong&gt;local quadratic convergence&lt;/strong&gt;, after sufficiently many iterations, the pure Newton step \(t=1\) satisfies the backtracking exit conditions, and the following equation holds.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\parallel x^{+} - x^{\star} \parallel_2 &amp;amp; \le \frac{1}{\sqrt(m)} \parallel x^{+} - x^{\star} \parallel_H \\\\
&amp;amp; =  \frac{1}{\sqrt(m)} \parallel \text{prox}_H(x - H^{-1} \nabla g(x) )  - \text{prox}_H(x^{\star} - H^{-1} \nabla g(x^{\star}) )  \parallel_H \\\\
&amp;amp; \le \frac{M}{2m} \parallel x - x^{\star} \parallel_2^2 \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Summarizing this, we get the following:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\parallel x^{+} - x^{\star} \parallel_2 \ \le \ \frac{1}{\sqrt(m)} \parallel x^{+} - x^{\star} \parallel_H \  \le \ \frac{M}{2m} \parallel x - x^{\star} \parallel_2^2
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;The first inequality holds due to the lowest eigenvalue bound, and the equality holds by the fact that \(\text{prox}_H(\cdot)\) becomes the identity at the definition of \(x^+\) and global minimum \(x^{\star}\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The second inequality holds due to the nonexpansiveness of the proximal operator, the Lipschitz assumption, and the largest eigenvalue bound.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>19-03 When would we use proximal Newton?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_03_When_would_we_use_proximal_Newton/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_03_When_would_we_use_proximal_Newton</id>
   <content type="html">&lt;p&gt;Knowing &lt;em&gt;how&lt;/em&gt; proximal Newton works is only half the battle—a seasoned optimization engineer also knows &lt;em&gt;when not to use it&lt;/em&gt;. If solving the scaled proximal subproblem costs 100 times more than a proximal gradient step, does \(O(\log\log(1/\epsilon))\) outer convergence still win? The answer depends sharply on two structural levers: how expensive it is to evaluate \(\nabla g(x)\) relative to the inner subproblem, and how severely ill-conditioned \(g\) is.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-practical-decision-matrix-for-proximal-newton&quot;&gt;Key ideas: The Practical Decision Matrix for Proximal Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Expensive Smooth Oracle (\(\nabla g\) Bottleneck):&lt;/strong&gt; In logistic Lasso with \(n \gg p\) (e.g., \(10^5\) rows, \(200\) features) or graphical Lasso (where evaluating \(-\log\det\Theta\) costs \(O(p^3)\) Cholesky work), every outer gradient evaluation is costly—making proximal Newton’s tiny outer iteration count a massive win.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cheap Inner Quadratic Subproblem:&lt;/strong&gt; When \(h(x) = \lambda \|x\|_1\) and active-set screening shrinks the working set to \(s \ll p\) nonzero variables, coordinate descent solves the inner quadratic subproblem in microseconds—far cheaper than touching the full dataset again.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High-Accuracy vs. Low-Accuracy Regimes:&lt;/strong&gt; If you only need \(10^{-2}\) relative accuracy (e.g., early-stopped deep learning), first-order FISTA wins; if you need \(10^{-8}\) accuracy for statistical inference or dual certificates, proximal Newton’s quadratic local convergence dominates.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inexact Subproblem Solves (Warm-Started Inner Loops):&lt;/strong&gt; In practice you never solve the inner subproblem to machine precision at iteration 1; warm-starting coordinate descent from the previous outer step and tightening inner tolerance progressively preserves superlinear outer speed at minimal cost.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-break-even-flop-audit-pg-vs-proximal-newton&quot;&gt;Worked example: Break-Even FLOP Audit (PG vs. Proximal Newton)&lt;/h3&gt;

&lt;p&gt;Suppose you are fitting an \(\ell_1\)-penalized logistic regression with \(n = 100{,}000\) samples, \(p = 200\) features, condition number \(\kappa = 10^4\), and target accuracy \(\epsilon = 10^{-8}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cost of one Proximal Gradient (FISTA) iteration:&lt;/strong&gt;
Computing \(X \beta\) and \(X^T(p - y)\) costs \(\approx 2np = 4 \times 10^7\) FLOPs; soft-thresholding costs \(O(p) \approx 200\) FLOPs (negligible).
To reach \(\epsilon = 10^{-8}\) with condition number \(\kappa = 10^4\), accelerated proximal gradient needs roughly \(\sqrt{\kappa}\log(1/\epsilon) \approx 100 \times 18.4 \approx 1{,}840\) iterations:
\(\text{Total FISTA cost} \approx 1{,}840 \times (4 \times 10^7) \approx 7.4 \times 10^{10} \text{ FLOPs}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cost of one Proximal Newton (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt;) iteration:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Computing \(\nabla g\) and \(H = X^T W X\) costs \(\approx np^2 = 4 \times 10^9\) FLOPs? Wait—we don’t even form \(H\) densely for all \(p\) if only \(s = 20\) features are active, or even &lt;em&gt;if&lt;/em&gt; we form the full \(200 \times 200\) matrix \(X^T W X\) via BLAS-3: \(np^2/2 \approx 2 \times 10^9\) FLOPs.&lt;/li&gt;
      &lt;li&gt;Solving the \(200 \times 200\) inner Lasso via 20 sweeps of coordinate descent costs \(20 \times p^2 = 8 \times 10^5\) FLOPs (four orders of magnitude smaller!).&lt;/li&gt;
      &lt;li&gt;Reaching \(\epsilon = 10^{-8}\) takes only \(\approx 6\) outer Newton iterations:
\(\text{Total Proximal Newton cost} \approx 6 \times (2 \times 10^9) \approx 1.2 \times 10^{10} \text{ FLOPs}.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verdict:&lt;/strong&gt;
Even forming the full dense Hessian, Proximal Newton is &lt;strong&gt;6× faster&lt;/strong&gt; in FLOPs (and often &lt;strong&gt;20× faster&lt;/strong&gt; in wall-clock time due to cache-friendly BLAS-3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X^T W X&lt;/code&gt; and active-set screening). Flip the dimensions to \(n = 200, p = 100{,}000\), however, and forming \(H \in \mathbb{R}^{p \times p}\) becomes impossible—immediately tipping the choice back to FISTA or L-BFGS!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When is the proximal Newton method a good choice?&lt;/p&gt;

&lt;p&gt;To understand when it is useful, let us compare the proximal Newton method with proximal gradient descent on the following problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: \(\min_x g(x) + h(x)\)&lt;/p&gt;

&lt;h2 id=&quot;proximal-gradient-descent-vs-proximal-newton&quot;&gt;Proximal gradient descent vs. proximal Newton&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;strong&gt;Proximal gradient descent&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Proximal Newton&lt;/strong&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimizes \(\frac{1}{2} \parallel b - x \parallel_2^2 + h(x)\) at each step&lt;/td&gt;
      &lt;td&gt;Minimizes \(b^T x + x^T A x + h(x)\) at each step&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;The prox operator is usually available in closed form&lt;/td&gt;
      &lt;td&gt;The prox operator usually has no closed form&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Cheap iterations&lt;/td&gt;
      &lt;td&gt;Very expensive iterations (more expensive than Newton’s method)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Convergence rate of gradient descent &lt;br /&gt; \(O(1/\epsilon)\)&lt;/td&gt;
      &lt;td&gt;Convergence rate of Newton’s method &lt;br /&gt; \(O(\log \log 1/\epsilon)\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The two methods look similar, but they actually do very different things.&lt;/p&gt;

&lt;p&gt;Therefore, the proximal Newton method is worth using when we have a fast inner optimizer for the scaled prox problem (quadratic \(+\ h\)), so that very few outer iterations are needed. When \(h\) is a separable function, the most commonly used inner optimizer is coordinate descent.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>19-02 Backtracking line search</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_02_Backtracking_line_search/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_02_Backtracking_line_search</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;In Lesson 19-01-02 we saw that a pure unit proximal Newton step on $$e^x - 4x +&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(can actually *increase* the objective when started far from the solution. Fixing that with backtracking line search raises an immediate design question: should we recompute the expensive scaled prox\)\operatorname{prox}_H\(at every trial step size\)t\(, or compute the direction\)v\(*once* and search along the straight ray\)x + tv\(? Computing\)v$$ once and backtracking along the ray saves massive computation while still guaranteeing global convergence and eventual unit-step acceptance!&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;key-ideas-composite-backtracking-without-repeated-prox-solves&quot;&gt;Key ideas: Composite Backtracking Without Repeated Prox Solves&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Composite Directional Derivative Proxy:&lt;/strong&gt; Because \(h\) is nonsmooth, the classical Armijo slope \(\nabla f(x)^T v\) does not exist. By convexity of \(h\), \(\Delta = \nabla g(x)^T v + h(x + v) - h(x)\) serves as a valid, strictly negative descent measure (\(\Delta \le -v^T H v &amp;lt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Modified Armijo Sufficient Decrease:&lt;/strong&gt; We accept \(t \in (0, 1]\) as soon as \(f(x + tv) \le f(x) + \alpha t \nabla g(x)^T v + \alpha\big(h(x + tv) - h(x)\big)\) (or equivalently using \(\alpha t \Delta\), since \(h(x + tv) - h(x) \le t(h(x + v) - h(x))\) by convexity!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Single-Prox Efficiency Advantage:&lt;/strong&gt; Unlike proximal gradient backtracking (which re-evaluates \(\operatorname{prox}_{t h}\) for every shrunk \(t\)), proximal Newton solves the expensive scaled prox &lt;em&gt;only once&lt;/em&gt; per outer iteration to get \(v\), then only evaluates scalar function values \(f(x + tv)\) during backtracking.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Automatic Transition to Unit Steps:&lt;/strong&gt; Near \(x^\star\), once \(\|x - x^\star\|\) is small enough, the quadratic Taylor remainder becomes negligible compared to \(-\frac{1}{2} v^T H v\), so \(t = 1\) passes the Armijo check immediately for any \(\alpha \le 1/2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-executing-composite-backtracking-on-ex---4x--x&quot;&gt;Worked example: Executing Composite Backtracking on \(e^x - 4x + |x|\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Resume directly from Lesson 19-01-02: $$f(x) = e^x - 4x +&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(at\)x = 0\((\)f(0) = 1\(,\)g’(0) = -3\(), with the single precomputed proximal Newton direction\)v = +2\(. Choose backtracking parameters\)\alpha = 0.25\(and\)\beta = 0.5$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trial 1 (\(t = 1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Candidate point: \(x + 1 \cdot v = 2\).&lt;/li&gt;
      &lt;li&gt;Actual objective: \(f(2) = e^2 - 8 + 2 = e^2 - 6 \approx 1.3891\).&lt;/li&gt;
      &lt;li&gt;Armijo threshold: \(f(0) + \alpha t g&apos;(0) v + \alpha(h(2) - h(0)) = 1 + 0.25(1)(-3)(2) + 0.25(2 - 0) = 1 - 1.5 + 0.5 = 0.0\).&lt;/li&gt;
      &lt;li&gt;Check: \(1.3891 &amp;gt; 0.0\) \(\implies\) &lt;strong&gt;FAIL!&lt;/strong&gt; Shrink \(t \leftarrow \beta t = 0.5\) (without re-solving any proximal subproblem!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trial 2 (\(t = 0.5\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Candidate point: \(x + 0.5 \cdot v = 1\).&lt;/li&gt;
      &lt;li&gt;Actual objective: \(f(1) = e^1 - 4 + 1 = e - 3 \approx -0.2817\).&lt;/li&gt;
      &lt;li&gt;Armijo threshold: \(f(0) + \alpha t g&apos;(0) v + \alpha(h(1) - h(0)) = 1 + 0.25(0.5)(-3)(2) + 0.25(1 - 0) = 1 - 0.75 + 0.25 = 0.50\).&lt;/li&gt;
      &lt;li&gt;Check: \(-0.2817 \le 0.50\) \(\implies\) &lt;strong&gt;PASS!&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update and verify:&lt;/strong&gt;
Accept \(x^1 = 1.0\). Notice \(f\) plunged from \(+1.0000\) to \(-0.2817\) (within \(0.014\) of the global optimum \(f(\ln 3) \approx -0.2958\)!) using just &lt;em&gt;one&lt;/em&gt; proximal Newton solve and &lt;em&gt;two&lt;/em&gt; scalar evaluations of \(f\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Proximal newton method&lt;/strong&gt; may not converge in cases with pure step size \(t_k=1, k=1,2,3, \cdots\) like newton’s method. Therefore, we need to optimize the step size through backtracking line search.&lt;/p&gt;

&lt;h2 id=&quot;backtracking-line-search-algorithm&quot;&gt;Backtracking line search algorithm&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Initialize parameters. (\(0 \lt \alpha \le 1/2, 0 \lt \beta \lt 1\))&lt;/li&gt;
  &lt;li&gt;At each iteration, compute the Proximal newton direction as \(v = \text{prox}_{H} ( x - H^{-1} \nabla g (x) ) - x\).&lt;/li&gt;
  &lt;li&gt;Initialize \(t=1\).&lt;/li&gt;
  &lt;li&gt;If the condition \(f(x + tv) \gt f(x) + \alpha t \nabla g(x)^T v + \alpha (h(x + tv) - h(x))\) is satisfied, reduce \(t=\beta t\). Iterate step 4 while this condition is satisfied. (\(f = g + h\))&lt;/li&gt;
  &lt;li&gt;Execute the Proximal newton update \(x^+ = x + tv\).&lt;/li&gt;
  &lt;li&gt;If the termination condition is not satisfied, go to step 2.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Intuitively, we find a step size \(t\) such that we move along direction \(v\) to a position where the linear approximation of function \(f\) at \(x\) is reduced by a factor of \(\alpha\). Since the \(h\) part of \(f\) is not differentiable, we use the discrete derivative \(h(x + tv) - h(x)\).&lt;/p&gt;

&lt;h2 id=&quot;efficiency-of-algorithm&quot;&gt;Efficiency of algorithm&lt;/h2&gt;
&lt;p&gt;There are many methods for performing backtracking line search, and here we have introduced one of them.&lt;/p&gt;

&lt;p&gt;In this method, when computing \(v\), the prox operator is computed only once. In the case of proximal gradient descent, the prox operator had to be computed iteratively in the inner loop, which is a distinctly different characteristic. Therefore, this method can perform backtracking line search very efficiently when the computation of the prox operator is complex.&lt;/p&gt;

&lt;h3 id=&quot;reference-backtracking-line-search-by-method&quot;&gt;[reference] Backtracking line search by method&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Gradient descent &lt;a href=&quot;/contents/en/chapter06/06_02_02_backtracking_line_search/&quot;&gt;06-02-02 Backtracking line search&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Proximal gradient descent &lt;a href=&quot;/contents/en/chapter09/09_02_convergence_analysis/&quot;&gt;09-02 Convergence analysis&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Newton’s method &lt;a href=&quot;/contents/en/chapter14/14_04_backtracking_line_search/&quot;&gt;14-04 Backtracking line search&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>19-01-03 Scaled proximal map</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_01_03_Scaled_proximal_map/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_01_03_Scaled_proximal_map</id>
   <content type="html">&lt;p&gt;At first sight, the proximal Newton subproblem looks much messier than proximal gradient descent—a full quadratic form \(\frac{1}{2} v^T H v\) entangled with a nonsmooth function \(h(x + v)\). Yet if you simply change your ruler from the Euclidean norm \(\|z\|_2\) to the &lt;strong&gt;\(H\)-norm&lt;/strong&gt; \(\|z\|_H = \sqrt{z^T H z}\), the entire proximal Newton update collapses back into the familiar one-line formula \(x^+ = \operatorname{prox}_H(x - H^{-1}\nabla g(x))\). Even better, every geometric superpower of the ordinary prox—uniqueness and firm non-expansiveness—survives intact in the \(H\)-norm!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-of-the-h-scaled-proximal-map&quot;&gt;Key ideas: Geometry of the \(H\)-Scaled Proximal Map&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Change of Inner Product (\(H\)-Norm):&lt;/strong&gt; For any \(H \succ 0\), \(\langle a, b \rangle_H = a^T H b\) defines a valid inner product on \(\mathbb{R}^n\) whose unit balls are ellipsoids aligned with the local curvature of \(g\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Definition &amp;amp; Uniqueness:&lt;/strong&gt; \(\operatorname{prox}_H(x) = \arg\min_z \frac{1}{2}\|x - z\|_H^2 + h(z)\). Because \(H \succ 0\) makes the quadratic term strictly convex and \(h\) is convex, the minimizer exists and is strictly unique.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Firm Non-Expansiveness in \(\|\cdot\|_H\):&lt;/strong&gt; Using subgradient monotonicity of \(h\), one proves \(\|\operatorname{prox}_H(x) - \operatorname{prox}_H(y)\|_H^2 \le \langle x - y, \; \operatorname{prox}_H(x) - \operatorname{prox}_H(y) \rangle_H\), which by Cauchy–Schwarz implies \(\|\operatorname{prox}_H(x) - \operatorname{prox}_H(y)\|_H \le \|x - y\|_H\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Scaled Prox Usually Lacks a Closed Form:&lt;/strong&gt; When \(H\) is diagonal and \(h\) is separable (like \(\|z\|_1\)), \(\operatorname{prox}_H\) reduces to coordinate-wise soft-thresholding with per-coordinate thresholds \(1/H_{ii}\). When \(H\) has off-diagonal couplings, coordinates interact and an inner solver (such as coordinate descent) is required.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-operatornameprox_h-and-verifying-h-non-expansiveness&quot;&gt;Worked example: Computing \(\operatorname{prox}_H\) and Verifying \(H\)-Non-Expansiveness&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Let $$h(z) =&lt;/td&gt;
      &lt;td&gt;z_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;z_2&lt;/td&gt;
      &lt;td&gt;\(and\)H = \begin{bmatrix} 1 &amp;amp; 0 \ 0 &amp;amp; 4 \end{bmatrix} \succ 0\(. Evaluate\)\operatorname{prox}_H\(at\)x = (2, 1)^T\(and\)y = (0, 0)^T$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write out the scaled proximal subproblem at \(x = (2, 1)^T\):&lt;/strong&gt;
\(\operatorname{prox}_H(x) = \arg\min_{z_1, z_2} \left[\frac{1}{2}(1)(z_1 - 2)^2 + |z_1|\right] + \left[\frac{1}{2}(4)(z_2 - 1)^2 + |z_2|\right].\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve each coordinate exactly:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Coordinate 1: \(z_1 - 2 + \operatorname{sign}(z_1) = 0 \implies z_1^\star = S_{1/1}(2) = 1\).&lt;/li&gt;
      &lt;li&gt;Coordinate 2: \(4(z_2 - 1) + \operatorname{sign}(z_2) = 0 \implies z_2^\star = S_{1/4}(1) = 1 - 0.25 = 0.75\).
Thus \(\operatorname{prox}_H(x) = (1, \; 0.75)^T\). (By symmetry, \(\operatorname{prox}_H(0, 0) = (0, 0)^T\).)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify non-expansiveness in the \(H\)-norm:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Input \(H\)-distance squared:
\(\|x - y\|_H^2 = (2)^2(1) + (1)^2(4) = 4 + 4 = 8 \implies \|x - y\|_H = \sqrt{8} \approx 2.8284.\)&lt;/li&gt;
      &lt;li&gt;Output \(H\)-distance squared:
\(\|\operatorname{prox}_H(x) - \operatorname{prox}_H(y)\|_H^2 = (1)^2(1) + (0.75)^2(4) = 1 + 2.25 = 3.25 \implies \|\operatorname{prox}_H(x) - \operatorname{prox}_H(y)\|_H \approx 1.8028.\)
Clearly \(1.8028 \le 2.8284\)—and notice it even satisfies &lt;em&gt;firm&lt;/em&gt; non-expansiveness: \(\langle x - y, \operatorname{prox}_H(x) - \operatorname{prox}_H(y) \rangle_H = (2)(1)(1) + (1)(0.75)(4) = 5 \ge 3.25\) \(\checkmark\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;strong&gt;proximal Newton method&lt;/strong&gt; can be rewritten in the same form as &lt;strong&gt;proximal gradient descent&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;scaled-proximal-map&quot;&gt;Scaled proximal map&lt;/h2&gt;
&lt;p&gt;If \(H \succ 0\), the &lt;strong&gt;scaled proximal map&lt;/strong&gt; is defined as follows.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\text{prox}_{H}(x) = \underset{z}{\text{argmin}}  \frac{1}{2} \parallel x - z \parallel_H^2 + h(z)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here \(\parallel x\parallel_H^2 = x^THx\) is the squared \(H\text{-norm}\). When \(H = \frac{1}{t} I\), this becomes the usual &lt;strong&gt;unscaled proximal map&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In general, the &lt;strong&gt;scaled proximal map&lt;/strong&gt; has the same nice properties as the ordinary prox.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;uniqueness&lt;/strong&gt;: the solution is unique (this holds because \(H \succ 0\) makes the problem strictly convex).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;non-expansiveness&lt;/strong&gt;: the map does not expand distances (this holds because the scaled proximal map generalizes the projection operator, which is non-expansive).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;note-non-expansiveness-of-the-projection-operator&quot;&gt;[Note] Non-expansiveness of the projection operator&lt;/h4&gt;
&lt;p&gt;For two points \(x\), \(y\) and the projection operator \(P_C\) onto a convex set \(C\), non-expansiveness means \(\parallel P_C(x) - P_C(y) \parallel_2 \le \parallel x - y \parallel_2\). In other words, \(P_C\) is 1-Lipschitz, which holds whenever \(C\) is convex.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter19/09.01_03_projection_operator.png&quot; alt=&quot;[Fig 1] Projection onto a convex set C [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Projection onto a convex set C [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;proximal-newton-update&quot;&gt;Proximal Newton update&lt;/h2&gt;
&lt;p&gt;Using the &lt;strong&gt;scaled proximal map&lt;/strong&gt;, the proximal Newton update can be rewritten as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
z^{+} &amp;amp; = \underset{z}{\text{argmin}} \ \nabla g(x)^T (z - x) + \frac{1}{2} (z - x)^T H (z - x) + h(z) \\\\
&amp;amp; =\underset{z}{\text{argmin}} \ \frac{1}{2} \parallel x - H^{-1} \nabla g(x) - z \parallel_H^2 + h(z)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Equivalently:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
z^{(k)} &amp;amp; = \text{prox}_{H^{(k-1)}} ( x^{(k-1)} - (H^{(k-1)})^{-1} \nabla g (x^{(k-1)}) ) \\\\
x^{(k)} &amp;amp; =x^{(k-1)} + t_k (z^{(k)} - x^{(k-1)} )
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Intuitively, we take a Newton step on \(g\), apply the scaled prox operator with respect to \(H^{(k-1)}\), and move in that direction.&lt;/p&gt;

&lt;p&gt;From this we see the following.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;When \(h(z) = 0\), the proximal operator is the identity, and we recover the ordinary Newton update.&lt;/li&gt;
  &lt;li&gt;If we replace \(H^{(k-1)}\) by \(\frac{1}{r_k} I\) and set \(t_k = 1\), we obtain the proximal gradient update with step size \(r_k\).&lt;/li&gt;
  &lt;li&gt;The difficulty of the prox depends not only on \(h\) but also on the structure of the Hessian of \(g\). For example, if \(H\) is diagonal or banded, the problem is much easier than when \(H\) is dense.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thus, the proximal Newton method generalizes both proximal gradient descent and Newton’s method.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>19-01-02 Proximal Newton method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_01_02_Proximal_Newton_method/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_01_02_Proximal_Newton_method</id>
   <content type="html">&lt;p&gt;In statistics, minimizing a locally quadratic approximation to a log-likelihood plus a penalty has been used for decades under names like &lt;em&gt;local scoring&lt;/em&gt; and &lt;em&gt;iteratively reweighted least squares (IRLS)&lt;/em&gt;. In convex optimization, Lee, Sun, and Saunders unified these ideas into the &lt;strong&gt;Proximal Newton Method&lt;/strong&gt;: at every iterate \(x^{(k-1)}\), form the exact second-order Taylor model of \(g\), add \(h(x^{(k-1)} + v)\), solve for the descent direction \(v^{(k)}\), and damp with a line-search step \(t_k\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-the-proximal-newton-iteration&quot;&gt;Key ideas: Anatomy of the Proximal Newton Iteration&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Composite Quadratic Subproblem:&lt;/strong&gt; The search direction \(v^{(k)} = \arg\min_v \nabla g(x^{(k-1)})^T v + \frac{1}{2} v^T H^{(k-1)} v + h(x^{(k-1)} + v)\) minimizes the true second-order model of \(g\) coupled with the exact nonsmooth penalty \(h\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Guaranteed Descent Direction:&lt;/strong&gt; Whenever \(H^{(k-1)} \succ 0\) and \(v^{(k)} \neq 0\), optimality of the subproblem proves \(\nabla g(x)^T v + h(x + v) - h(x) \le -v^T H v &amp;lt; 0\), guaranteeing that \(v^{(k)}\) is a strict descent direction for \(f = g + h\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fixed-Point Optimality Characterization:&lt;/strong&gt; \(v^{(k)} = 0\) if and only if \(0 \in \nabla g(x^{(k-1)}) + \partial h(x^{(k-1)})\), meaning \(x^{(k-1)}\) is already a global minimizer of \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Damping (\(t_k \in (0, 1]\)) Is Essential:&lt;/strong&gt; Just like classical Newton’s method on \(e^x - 4x\), taking a full unit step \(t_k = 1\) far from the solution can overshoot and increase \(f\); pairing \(v^{(k)}\) with backtracking guarantees global convergence while still accepting \(t_k = 1\) near \(x^\star\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-proximal-newton-direction-on-a-non-quadratic-objective&quot;&gt;Worked example: One Proximal Newton Direction on a Non-Quadratic Objective&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider the 1D non-quadratic composite objective $$f(x) = \underbrace{e^x - 4x}_{g(x)} + \underbrace{&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;}_{h(x)}\(starting at\)x^0 = 0\((where\)f(0) = 1\(). Note the exact optimum satisfies\)e^{x^\star} - 4 + 1 = 0 \implies x^\star = \ln 3 \approx 1.0986\(with\)f(x^\star) = 3 - 3\ln 3 \approx -0.2958$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute local gradient and Hessian of \(g\) at \(x^0 = 0\):&lt;/strong&gt;
\(g&apos;(0) = e^0 - 4 = -3, \qquad H^{(0)} = g&apos;&apos;(0) = e^0 = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form and solve the proximal Newton subproblem:&lt;/strong&gt;
\(v^{(1)} = \arg\min_v \; -3v + \frac{1}{2}(1)v^2 + |0 + v|.\)
Test \(v &amp;gt; 0\): derivative is \(-3 + v + 1 = 0 \implies v^{(1)} = 2\) (valid since \(2 &amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the descent-direction inequality:&lt;/strong&gt;
\(\nabla g(0)^T v^{(1)} + h(0 + v^{(1)}) - h(0) = (-3)(2) + 2 - 0 = -4 = -(v^{(1)})^T H^{(0)} v^{(1)} &amp;lt; 0 \quad \checkmark\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check why a full unit step \(t = 1\) overshoots here:&lt;/strong&gt;
At \(x^0 + v^{(1)} = 2\), \(f(2) = e^2 - 8 + 2 = e^2 - 6 \approx +1.3891 &amp;gt; f(0) = 1.0000\)!
The direction \(v^{(1)} = +2\) points directly toward \(x^\star \approx 1.0986\), but because \(e^x\) curves up sharply past \(x = 1\), we must damp \(t_1 &amp;lt; 1\) via backtracking (which we will compute explicitly in Lesson 19-02!).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the previous section, we explained that the &lt;strong&gt;proximal Newton method&lt;/strong&gt; uses the local Hessian \(\nabla^2 g(x)\) in place of the spherical curvature \(\frac{1}{t} I\) in the &lt;strong&gt;proximal gradient descent&lt;/strong&gt; formula. The proximal Newton method is an old idea, studied in statistics under the name “local score”.&lt;/p&gt;

&lt;p&gt;Now let us see how the &lt;strong&gt;proximal Newton method&lt;/strong&gt; can be formulated.&lt;/p&gt;

&lt;h2 id=&quot;algorithm&quot;&gt;Algorithm&lt;/h2&gt;
&lt;p&gt;The proximal Newton algorithm consists of finding the direction \(v\) of the next step and then choosing the step size \(t_k\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Step 1: Starting from the initial point \(x^{(0)}\), repeat the following steps. (\(k=1,2,3,...\))&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Step 2: Find the direction \(v\) of the next step.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
v^{(k)} &amp;amp; = \underset{v}{\text{argmin}} \ \nabla g(x^{(k-1)})^T v + \frac{1}{2} v^T H^{(k-1)} v + h(x^{(k-1)} + v)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here \(H^{(k-1)} = \nabla^2 g(x^{(k-1)})\) is the Hessian of \(g\) at \(x^{(k-1)}\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Step 3: Choose a step size to move along the direction \(v^{(k)}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{(k)} &amp;amp; =x^{(k-1)} + t_k v^{(k)}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here \(t_k\) is the step size; with \(t_k=1\) this is the pure proximal Newton method.&lt;/p&gt;

&lt;p&gt;Unlike proximal gradient descent, the step size is chosen by backtracking line search.&lt;/p&gt;

&lt;h4 id=&quot;next-position-view&quot;&gt;Next position view&lt;/h4&gt;
&lt;p&gt;If we express the above in terms of the next position \(z\) rather than the direction \(v\), we get the following.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
z^{(k)} &amp;amp; = \underset{z}{\text{argmin}} \ \nabla g(x^{(k-1)})^T (z - x^{(k-1)}) + \frac{1}{2} (z - x^{(k-1)})^T H^{(k-1)} (z - x^{(k-1)}) + h(z) \\\\
x^{(k)} &amp;amp; =x^{(k-1)} + t_k (z^{(k)} - x^{(k-1)} )
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Intuitively, in the first step we find the surrogate point \(z\) that minimizes the quadratic model of the objective. We then move from \(x^{(k-1)}\) in the direction of \(z\), but we do not always move all the way to \(z\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>19-01-01 Reminder - proximal gradient descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_01_01_Reminder-_proximal_gradient_descent/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_01_01_Reminder:_proximal_gradient_descent</id>
   <content type="html">&lt;p&gt;Before generalizing proximal gradient descent to use Hessians, it pays to pause and see proximal gradient descent through the &lt;em&gt;quadratic-model lens&lt;/em&gt;. Most students memorize the two-step recipe—”take a gradient step on \(g\), then apply \(\operatorname{prox}_{t h}\)“—as a mechanical formula. Once you rewrite it as minimizing a &lt;em&gt;majorizing quadratic approximation&lt;/em&gt; of \(g\) plus \(h\), the leap to proximal Newton becomes completely inevitable.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-re-viewing-proximal-gradient-as-a-quadratic-model&quot;&gt;Key ideas: Re-Viewing Proximal Gradient as a Quadratic Model&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Composite Problem Template:&lt;/strong&gt; Minimize \(f(x) = g(x) + h(x)\) where \(g\) is convex and \(L\)-smooth, and \(h\) is convex, closed, and proximable (its proximal map has a cheap closed form, like soft-thresholding for \(\ell_1\) or Euclidean projection for \(I_C\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Majorization–Minimization View:&lt;/strong&gt; Because \(\nabla g\) is \(L\)-Lipschitz, \(g(z) \le g(x) + \nabla g(x)^T(z - x) + \frac{1}{2t}\|z - x\|_2^2\) whenever \(t \le 1/L\). Minimizing this upper bound plus \(h(z)\) guarantees monotonic descent \(f(x^+) \le f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Completing the Square:&lt;/strong&gt; Adding and subtracting \(\frac{t}{2}\|\nabla g(x)\|_2^2\) turns the quadratic-model minimization identically into \(\operatorname{prox}_{t h}(x - t\nabla g(x))\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Limitation:&lt;/strong&gt; Because the quadratic term \(\frac{1}{2t} I\) uses the &lt;em&gt;worst-case&lt;/em&gt; global curvature \(L\) in every direction, proximal gradient converges at \(O(1/k)\) (or \(O(1/k^2)\) with Nesterov acceleration)—slow whenever \(g\) is ill-conditioned.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-proximal-gradient-step-via-both-views&quot;&gt;Worked example: One Proximal Gradient Step via Both Views&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Solve the 1D Lasso $$\min_x f(x) = \underbrace{\frac{1}{2}(2x - 6)^2}_{g(x)} + \underbrace{2&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;}_{h(x)}\(starting from\)x^0 = 0$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute derivatives and smoothness constant \(L\):&lt;/strong&gt;
\(g&apos;(x) = 2(2x - 6) = 4x - 12, \qquad g&apos;&apos;(x) = 4 \implies L = 4, \; t = \frac{1}{L} = \frac{1}{4}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;View 1 (Forward–Backward formula):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient step: \(y = x^0 - t g&apos;(x^0) = 0 - \frac{1}{4}(-12) = 3\).&lt;/li&gt;
      &lt;li&gt;Soft-threshold with threshold \(\lambda t = 2 \cdot \frac{1}{4} = 0.5\):
\(x^1 = S_{0.5}(3) = \max(3 - 0.5, 0) = 2.5.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;View 2 (Quadratic model minimization):&lt;/strong&gt;
\(\min_z \; g&apos;(0)(z - 0) + \frac{1}{2(1/4)}(z - 0)^2 + 2|z| = \min_z \; -12z + 2z^2 + 2|z|.\)
For \(z &amp;gt; 0\), setting the derivative \(-12 + 4z + 2 = 0\) gives \(z = 2.5\)—identical to View 1!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify optimality:&lt;/strong&gt;
At \(x^1 = 2.5\), \(g&apos;(2.5) + 2 = 4(2.5) - 12 + 2 = 0\). (Because \(g\) is 1D quadratic with \(L = g&apos;&apos;\), the isotropic model happened to be exact here; in \(n \ge 2\) dimensions with unequal eigenvalues, \(L I \neq \nabla^2 g\), which is why we need Proximal Newton next!)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before looking at the &lt;strong&gt;proximal Newton method&lt;/strong&gt; that we study in this chapter, let us first review &lt;strong&gt;proximal gradient descent&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For details, see &lt;a href=&quot;/contents/en/chapter09/09_proximal_gradient_descent_and_acceleration/&quot;&gt;09 Proximal Gradient Descent and Acceleration&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;proximal-gradient-descent&quot;&gt;Proximal gradient descent&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Proximal gradient descent&lt;/strong&gt; works on problems of the following form.&lt;/p&gt;

&lt;blockquote&gt;
\[f(x) = g(x) + h(x)\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;\(g\) is convex and differentiable. (&lt;strong&gt;dom&lt;/strong&gt;\((g) = \mathbb{R}^n\))&lt;/li&gt;
  &lt;li&gt;\(h\) is convex, non-differentiable, and “simple”.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;algorithm&quot;&gt;Algorithm&lt;/h4&gt;
&lt;p&gt;Proximal gradient descent starts from an initial point \(x^{(0)}\) and repeats the following update.&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = \text{prox}_{t_k}(x^{(k-1)} - t_k \nabla g(x^{(k-1)}) ),\quad k=1,2,3,...\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(\text{prox}_{t}(\cdot)\) is the proximal operator associated with \(h\).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\text{prox}_{t}(x) = \underset{z}{\text{argmin}}  \frac{1}{2t} \parallel x - z \parallel_2^2 + h(z)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The update can also be written in a standardized form using the generalized gradient \(G_{t}\).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{(k)} = x^{(k-1)} - t_k \cdot G_{t_k}(x^{(k-1)}), \space \space \text{where} \space G_{t}(x) = \frac{x-\text{prox}_{t} (x - t \nabla g(x))}{t} \&lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;performance&quot;&gt;Performance&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;The performance of &lt;strong&gt;proximal gradient descent&lt;/strong&gt; depends on \(h\). If \(h\) is a complicated function, and in particular if its prox has no closed form, then each minimization requires a lot of computation and the method can be very slow.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;It has the same convergence rate as gradient descent on \(g\). However, since the prox operator is evaluated at every iteration, the method is only useful when the prox can be computed efficiently.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;motivation&quot;&gt;Motivation&lt;/h2&gt;
&lt;p&gt;In &lt;strong&gt;proximal gradient descent&lt;/strong&gt;, the differentiable function \(g\) is approximated by its second-order Taylor expansion, the non-differentiable function \(h\) is added to it to form the objective, and this objective is minimized repeatedly. This can be written as the following quadratic problem.&lt;/p&gt;

&lt;p&gt;For the detailed derivation, see &lt;a href=&quot;/contents/en/chapter09/09_01_proximal_gradient_descent/&quot;&gt;09-01 Proximal gradient descent&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^+ &amp;amp; = \underset{z}{\text{argmin}}  \, \frac{1}{2t} \parallel x - t \nabla g(x) - z \parallel_2 ^2 + h(z) \\\\
&amp;amp; = \underset{z}{\text{argmin}} \ \nabla g(x)^T (z - x) + \frac{1}{2t} \parallel z - x \parallel_2 ^2 + h(z) \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The first and second terms of the second expression come from the second-order Taylor approximation of \(g\): we drop the constant term \(g(x)\) and (as in gradient descent) replace the Hessian \(\nabla^2 g(x)\) with \(\frac{1}{t} I\) (spherical curvature).&lt;/p&gt;

&lt;p&gt;The following figure shows how \(g\) is minimized through this quadratic approximation in each update step of proximal gradient descent.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter19/09.01_01_proximal_gradient_descent.png&quot; alt=&quot;[Fig 1] Proximal gradient descent updates [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Proximal gradient descent updates [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The difference between gradient descent and Newton’s method is whether the local Hessian \(\nabla^2 g(x)\) is used in the quadratic approximation. So what happens if we use \(\nabla^2 g(x)\) instead of \(\frac{1}{t} I\) in the expression above?&lt;/p&gt;

&lt;p&gt;This is exactly the idea behind the &lt;strong&gt;proximal Newton method&lt;/strong&gt;, which we describe in the next section.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>19-01 Proximal Newton method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_01_00_Proximal_Newton_method/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_01_00_Proximal_Newton_method</id>
   <content type="html">&lt;p&gt;If you already know proximal gradient descent (Chapter 9), you are literally one matrix away from the &lt;strong&gt;proximal Newton method&lt;/strong&gt;. Proximal gradient approximates the smooth function \(g\) at each step by a &lt;em&gt;round, isotropic bowl&lt;/em&gt; \(\frac{1}{2t}\|z - x\|_2^2\); proximal Newton replaces that isotropic sphere with the &lt;em&gt;true elliptical bowl&lt;/em&gt; \(\frac{1}{2}(z - x)^T \nabla^2 g(x)(z - x)\). That geometric upgrade—from spheres to curvature-matched ellipsoids—is the unifying thread of Section 19-01.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-spherical-to-ellipsoidal-proximal-models&quot;&gt;Key ideas: From Spherical to Ellipsoidal Proximal Models&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Local Quadratic Approximation of \(g\):&lt;/strong&gt; Proximal gradient replaces \(g(z)\) by \(g(x) + \nabla g(x)^T(z - x) + \frac{1}{2t}\|z - x\|_2^2\); proximal Newton replaces \(\frac{1}{t} I\) by the local Hessian \(H = \nabla^2 g(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Preservation of \(h\):&lt;/strong&gt; Neither method linearizes the nonsmooth part \(h(z)\); keeping \(h(z)\) exact inside the subproblem preserves sparsity, low-rank structure, or constraint feasibility at every iteration.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Scaled Proximal Operator:&lt;/strong&gt; Completing the square in the proximal Newton subproblem rewrites the update compactly as \(x^+ = \operatorname{prox}_H(x - H^{-1}\nabla g(x))\), mirroring proximal gradient’s \(x^+ = \operatorname{prox}_{t h}(x - t \nabla g(x))\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Ellipsoidal Geometry Matters:&lt;/strong&gt; When features are strongly correlated or differently scaled, isotropic spheres bounce back and forth across valleys; Hessian-shaped ellipsoids point straight down the ravine toward the nonsmooth optimum.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-spherical-vs-ellipsoidal-model-at-the-origin&quot;&gt;Worked example: Spherical vs. Ellipsoidal Model at the Origin&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider \(g(x) = \frac{1}{2}(x_1^2 + 100 x_2^2) - 2x_1 - 200 x_2\) and $$h(x) =&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\(at\)x^0 = (0, 0)^T\(. Here\)\nabla g(0) = (-2, -200)^T\(and\)\nabla^2 g(0) = \operatorname{diag}(1, 100)$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Exact optimum (for reference):&lt;/strong&gt;
Stationarity gives \(x_1 - 2 + \operatorname{sign}(x_1) = 0 \implies x_1^\star = 1\) and \(100x_2 - 200 + \operatorname{sign}(x_2) = 0 \implies x_2^\star = 1.99\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Spherical model (Proximal Gradient with \(t = 1/L = 0.01\)):&lt;/strong&gt;
\(x^0 - t\nabla g(0) = (0.02, 2.00)^T \xrightarrow{S_{0.01}} x^1_{\text{PG}} = (0.01, 1.99)^T.\)
Coordinate \(x_2\) hits \(1.99\) immediately, but \(x_1\) only reaches \(0.01\) (\(1\%\) of the way to \(x_1^\star = 1\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ellipsoidal model (Proximal Newton with \(H = \operatorname{diag}(1, 100)\)):&lt;/strong&gt;
Compute the Newton target \(x^0 - H^{-1}\nabla g(0) = (2, 2)^T\) and apply \(\operatorname{prox}_H\):
\(z_1 = S_{1/1}(2) = 1.00, \qquad z_2 = S_{1/100}(2) = 1.99.\)
In one ellipsoidal step, &lt;em&gt;both&lt;/em&gt; coordinates hit the exact optimum \((1.00, 1.99)^T\) simultaneously!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we will review the &lt;strong&gt;proximal gradient method&lt;/strong&gt; and examine how the &lt;strong&gt;proximal newton method&lt;/strong&gt; emerged from it.&lt;/p&gt;

&lt;p&gt;We will also examine the definition of the &lt;strong&gt;proximal newton method&lt;/strong&gt; and the scaled proximal map that has good properties such as uniqueness and non-expansiveness compared to the general proximal map.&lt;/p&gt;

&lt;h3 id=&quot;proximal-newton-vs-proximal-gradient-video&quot;&gt;Proximal Newton vs. proximal gradient (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/prox-newton_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Proximal gradient uses a scalar step; proximal Newton minimises the quadratic model with the true Hessian plus \(\lambda\|x\|_1\), so it needs far fewer iterations.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-proximal-gradient-vs-proximal-newton&quot;&gt;Try it yourself: proximal gradient vs proximal Newton&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;pn&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>19 Proximal Newton Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_00_Proximal_Newton_Method/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter19/19_00_Proximal_Newton_Method</id>
   <content type="html">&lt;p&gt;Classical Newton’s method is the Ferrari of smooth optimization—quadratic convergence, effortless immunity to ill-conditioning—until a single sharp corner like \(\lambda \|x\|_1\) or a box constraint \(x \in C\) enters the objective. Suddenly \(\nabla^2 f(x)\) does not even exist at the solution! &lt;strong&gt;Proximal Newton methods&lt;/strong&gt; rescue second-order speed for composite nonsmooth problems \(\min_x g(x) + h(x)\) by applying a full Hessian quadratic model &lt;em&gt;only&lt;/em&gt; to the smooth loss \(g\) while keeping the nonsmooth regularizer \(h\) intact inside the subproblem. That simple split powers modern workhorses from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glmnet&lt;/code&gt; to graphical Lasso (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QUIC&lt;/code&gt;).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-extending-second-order-methods-to-composite-objectives&quot;&gt;Key ideas: Extending Second-Order Methods to Composite Objectives&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Composite Splitting (\(f = g + h\)):&lt;/strong&gt; Separating a twice-differentiable data-fidelity term \(g\) from a simple convex nonsmooth term \(h\) (such as \(\ell_1\) sparsity or a set indicator \(I_C\)) lets us exploit second-order curvature where it exists without smoothing away the exact corners where sparsity lives.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaled Proximal Operators (\(\operatorname{prox}_H\)):&lt;/strong&gt; Replacing the Euclidean metric \(\frac{1}{2t}\|x - z\|_2^2\) of proximal gradient descent with the Hessian metric \(\frac{1}{2}\|x - z\|_H^2\) generalizes the proximal map while preserving uniqueness and firm non-expansiveness in the \(H\)-norm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Outer Superlinear/Quadratic Speed vs. Inner Subproblem Cost:&lt;/strong&gt; Proximal Newton slashes outer gradient/Hessian evaluations from \(O(1/\epsilon)\) to \(O(\log\log(1/\epsilon))\), at the price of solving a composite quadratic subproblem (typically via fast coordinate descent or active-set methods) at each outer step.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quasi-Newton &amp;amp; Projected Variants:&lt;/strong&gt; When forming \(\nabla^2 g(x)\) is too costly, BFGS-style approximations yield &lt;em&gt;proximal quasi-Newton&lt;/em&gt; methods; when \(h = I_C\) is a box indicator, Bertsekas’s &lt;em&gt;projected Newton&lt;/em&gt; method avoids the ascent trap of naive Euclidean projection.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-proximal-gradient-vs-proximal-newton-in-2d&quot;&gt;Worked example: Proximal Gradient vs. Proximal Newton in 2D&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize the composite objective \(f(x) = g(x) + h(x)\) with \(g(x) = \frac{1}{2}(x_1^2 + 10 x_2^2)\) and $$h(x) =&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\((exact optimum\)x^\star = (0, 0)^T\(), starting from\)x^0 = (5, 5)^T$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;One Proximal Gradient (ISTA) step:&lt;/strong&gt;
Here \(\nabla g(x) = (x_1, 10 x_2)^T\) has Lipschitz constant \(L = 10\), so we must take step size \(t = \frac{1}{L} = 0.1\):
\(x^0 - t\nabla g(x^0) = \begin{bmatrix} 5 \\ 5 \end{bmatrix} - 0.1\begin{bmatrix} 5 \\ 50 \end{bmatrix} = \begin{bmatrix} 4.5 \\ 0 \end{bmatrix}.\)
Applying soft-thresholding \(S_{0.1}(\cdot)\) coordinate-wise yields \(x^1_{\text{PG}} = (4.4, 0)^T\). Because the steep \(x_2\) curvature forced \(t = 0.1\), coordinate \(x_1\) barely budged (\(5 \to 4.4\))!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;One Proximal Newton step:&lt;/strong&gt;
The exact Hessian is \(H = \nabla^2 g(x^0) = \operatorname{diag}(1, 10)\). The proximal Newton subproblem minimizes:
\(\min_{v_1, v_2} \; \left(5v_1 + \tfrac{1}{2}v_1^2 + |5 + v_1|\right) + \left(50v_2 + 5v_2^2 + |5 + v_2|\right).\)
Substituting \(z = x^0 + v\), this decouples into \(\min_{z_1} \frac{1}{2}z_1^2 + |z_1| \implies z_1 = 0\) and \(\min_{z_2} 5z_2^2 + |z_2| \implies z_2 = 0\)!
Thus \(v = (-5, -5)^T\) and \(x^1_{\text{PN}} = (0, 0)^T = x^\star\) in &lt;strong&gt;one single step&lt;/strong&gt;—completely eliminating the \(10\times\) ill-conditioning!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we will examine &lt;strong&gt;Proximal Newton Method&lt;/strong&gt;, &lt;strong&gt;Proximal quasi-Newton method&lt;/strong&gt;, and &lt;strong&gt;Projected Newton method&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;reference-papers&quot;&gt;Reference Papers&lt;/h3&gt;

&lt;p&gt;Proximal Newton method:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;J. Friedman and T. Hastie and R. Tibshirani (2009), “Regularization paths for generalized linear models via coordinate descent”&lt;/li&gt;
  &lt;li&gt;C.J. Hsiesh and M.A. Sustik and I. Dhillon and P. Ravikumar (2011), “Sparse inverse covariance matrix estimation using quadratic approximation”&lt;/li&gt;
  &lt;li&gt;M. Patriksson (1998), “Cost approximation: a unified framework of descent algorithms for nonlinear programs”&lt;/li&gt;
  &lt;li&gt;J. Lee and Y. Sun and M. Saunders (2014), “Proximal Newton-type methods for minimizing composite functions”&lt;/li&gt;
  &lt;li&gt;P. Tseng and S. Yun (2009), “A coordinate gradient descent method for nonsmooth separable minimization”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Projected Newton method:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A. Barbero and S. Sra (2011), “Fast Newton-type methods for total variation regularization”&lt;/li&gt;
  &lt;li&gt;D. Bertsekas (1982), “Projected Newton methods for optimization problems with simple constraints”&lt;/li&gt;
  &lt;li&gt;D. Kim and S. Sra. and I. Dhillon (2010), “Tackling box-constrained optimization via a new projected
quasi-Newton approach”&lt;/li&gt;
  &lt;li&gt;M. Schmidt and D. Kim and S. Sra (2011), “Projected Newton-type methods in machine learning”&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>11-10 Practical Exercises - General Duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_10_Practical_Exercises_General_Duality/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_10_Practical_Exercises_General_Duality</id>
   <content type="html">&lt;p&gt;Working through Lagrangian duality exercises by hand builds a skill no software package can replace: the ability to spot hidden structure in a constrained problem and transform an awkward primal into a clean, tractable dual. In the exercises below—adapted from Boyd &amp;amp; Vandenberghe, Rockafellar, and Bertsekas—you will build Lagrangians from scratch, test Slater’s condition on tricky boundary cases, dualize quadratic programs, and use weak duality to bound nonconvex problems.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-tactical-moves-for-general-duality-exercises&quot;&gt;Key ideas: Four Tactical Moves for General Duality Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Standardizing Constraint Signs First:&lt;/strong&gt; Always rewrite every inequality as \(h_i(x) \le 0\) before attaching \(u_i \ge 0\). Flipping a single \(\ge\) sign reverses the sign of \(u_i\) and breaks weak duality.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Splitting \(\inf_x L(x, u, v)\) by Separability:&lt;/strong&gt; Whenever \(L(x, u, v) = \sum_{j=1}^n L_j(x_j, u, v)\) decouples across coordinates, minimize each scalar function \(L_j\) independently—and carefully record the domain conditions where \(\inf_{x_j} L_j &amp;gt; -\infty\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Testing Slater’s Condition Systematically:&lt;/strong&gt; Check (1) convexity of \(f\) and every \(h_i\), (2) affinity of every \(l_j\), and (3) existence of a single \(x\) strictly satisfying all &lt;em&gt;non-affine&lt;/em&gt; inequalities while satisfying affine equalities and inequalities.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Recovering Primal Solutions from the Dual:&lt;/strong&gt; Once you find \((u^\star, v^\star)\), if \(L(x, u^\star, v^\star)\) has a &lt;em&gt;unique&lt;/em&gt; minimizer \(x^\star\) (e.g., strictly convex \(f\)) and strong duality holds, that unique minimizer is automatically the primal optimal solution!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-dualizing-an-equality-constrained-entropy-problem&quot;&gt;Worked example: Dualizing an Equality-Constrained Entropy Problem&lt;/h3&gt;

&lt;p&gt;Solve \(\min_{x \in \mathbb{R}_{++}^2}\; x_1 \ln x_1 + x_2 \ln x_2\) subject to \(x_1 + x_2 = 1\) via its Lagrange dual.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the Lagrangian with free equality multiplier \(v \in \mathbb{R}\):&lt;/strong&gt;
\(L(x, v) = x_1 \ln x_1 + x_2 \ln x_2 + v(x_1 + x_2 - 1) = \sum_{i=1}^2 (x_i \ln x_i + v x_i) - v.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize separably over \(x_i &amp;gt; 0\):&lt;/strong&gt;
\(\frac{\partial L}{\partial x_i} = \ln x_i + 1 + v = 0 \implies x_i(v) = e^{-1 - v}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Substitute back to get the dual function \(g(v)\):&lt;/strong&gt;
Since \(x_i \ln x_i + v x_i = e^{-1-v}(-1 - v) + v e^{-1-v} = -e^{-1-v}\), we get:
\(g(v) = -2 e^{-1 - v} - v.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Maximize \(g(v)\) over \(v \in \mathbb{R}\):&lt;/strong&gt;
\(g&apos;(v) = 2 e^{-1 - v} - 1 = 0 \implies e^{-1 - v^\star} = \frac{1}{2} \implies v^\star = \ln(2) - 1.\)
    &lt;ul&gt;
      &lt;li&gt;Dual optimal value: \(g(v^\star) = -2(1/2) - (\ln 2 - 1) = -\ln 2\).&lt;/li&gt;
      &lt;li&gt;Recover unique primal optimum: \(x_1^\star = x_2^\star = e^{-1 - v^\star} = \frac{1}{2}\), with \(f^\star = \frac{1}{2}\ln\frac{1}{2} + \frac{1}{2}\ln\frac{1}{2} = -\ln 2 = g^\star\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---general-duality&quot;&gt;Practical Exercises - General Duality&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd &amp;amp; Vandenberghe (2004), Rockafellar (1970), and Bertsekas (1999).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-i-the-lagrangian-and-the-dual-function---foundations&quot;&gt;&lt;strong&gt;Part I: The Lagrangian and the Dual Function - Foundations&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-1-building-the-lagrangian-boyd--vandenberghe-ex-51&quot;&gt;&lt;strong&gt;Exercise 1: Building the Lagrangian (Boyd &amp;amp; Vandenberghe, Ex. 5.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the general problem:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; f_0(x) \\
\text{s.t.} \quad &amp;amp; f_i(x) \leq 0, \quad i = 1, \ldots, m \\
&amp;amp; h_j(x) = 0, \quad j = 1, \ldots, p
\end{align}\]

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Write the Lagrangian \(L(x, \lambda, \nu)\)
b) Define the dual function \(g(\lambda, \nu)\)
c) Let \(f_0(x) = x_1^2 + x_2^2\), \(f_1(x) = x_1 + x_2 - 1\), \(h_1(x) = x_1 - x_2\). Compute \(L\) and \(g\)&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Lagrangian:&lt;/strong&gt;&lt;/p&gt;

\[L(x, \lambda, \nu) = f_0(x) + \sum_{i=1}^m \lambda_i f_i(x) + \sum_{j=1}^p \nu_j h_j(x)\]

  &lt;p&gt;where:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\lambda \in \mathbb{R}^m\), \(\lambda \geq 0\): dual variables for the inequality constraints&lt;/li&gt;
    &lt;li&gt;\(\nu \in \mathbb{R}^p\): dual variables for the equality constraints (no sign restriction)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Dual function:&lt;/strong&gt;&lt;/p&gt;

\[g(\lambda, \nu) = \inf_x L(x, \lambda, \nu) = \inf_x \left( f_0(x) + \sum_i \lambda_i f_i(x) + \sum_j \nu_j h_j(x) \right)\]

  &lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(g(\lambda, \nu)\) is always &lt;strong&gt;concave&lt;/strong&gt; in \((\lambda, \nu)\)&lt;/li&gt;
    &lt;li&gt;\(g(\lambda, \nu) \leq p^*\) (weak duality) for every \(\lambda \geq 0\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Concrete computation:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Data:&lt;/p&gt;

\[f_0(x) = x_1^2 + x_2^2, \quad f_1(x) = x_1 + x_2 - 1, \quad h_1(x) = x_1 - x_2\]

  &lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt;&lt;/p&gt;

\[L(x, \lambda, \nu) = x_1^2 + x_2^2 + \lambda(x_1 + x_2 - 1) + \nu(x_1 - x_2)\]

  &lt;p&gt;&lt;strong&gt;Find \(\inf_x L\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;FOC:&lt;/p&gt;

\[\frac{\partial L}{\partial x_1} = 2x_1 + \lambda + \nu = 0 \Rightarrow x_1 = -\frac{\lambda + \nu}{2}\]

\[\frac{\partial L}{\partial x_2} = 2x_2 + \lambda - \nu = 0 \Rightarrow x_2 = -\frac{\lambda - \nu}{2}\]

  &lt;p&gt;Substituting into \(L\), we get:&lt;/p&gt;

\[g(\lambda, \nu) = -\frac{\lambda^2 + \nu^2}{2} - \lambda\]

  &lt;p&gt;with \(\lambda \geq 0\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-2-weak-duality-boyd--vandenberghe-ex-52&quot;&gt;&lt;strong&gt;Exercise 2: Weak Duality (Boyd &amp;amp; Vandenberghe, Ex. 5.2)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Take the problem and the dual function from Exercise 1c.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Solve the primal problem
b) Solve the dual problem: \(\max_{\lambda \geq 0, \nu} g(\lambda, \nu)\)
c) Check strong duality&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Solving the primal:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x_1^2 + x_2^2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 \leq 1 \\
&amp;amp; x_1 - x_2 = 0
\end{align}\]

  &lt;p&gt;From \(x_1 = x_2\) and \(x_1 + x_2 \leq 1\) → \(2x_1 \leq 1\) → \(x_1 \leq 0.5\).&lt;/p&gt;

  &lt;p&gt;Minimize \(2x_1^2\) → the minimum is at \(x_1 = 0\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Primal solution:&lt;/strong&gt; \(x^* = (0, 0)\), \(p^* = 0\)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Solving the dual:&lt;/strong&gt;&lt;/p&gt;

\[\max_{\lambda \geq 0, \nu} \quad -\frac{\lambda^2 + \nu^2}{2} - \lambda\]

  &lt;p&gt;FOC: \(\frac{\partial g}{\partial \lambda} = -\lambda - 1 = 0\) → \(\lambda = -1\) (but \(\lambda \geq 0\) → \(\lambda^* = 0\))&lt;/p&gt;

  &lt;p&gt;\(\frac{\partial g}{\partial \nu} = -\nu = 0\) → \(\nu^* = 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Dual solution:&lt;/strong&gt; \(\lambda^* = 0\), \(\nu^* = 0\), \(d^* = 0\)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Strong Duality:&lt;/strong&gt;&lt;/p&gt;

\[p^* = 0 = d^*\]

  &lt;p&gt;&lt;strong&gt;Strong duality holds!&lt;/strong&gt; ✓ (The problem is convex and satisfies Slater’s condition)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-ii-slaters-condition-and-strong-duality&quot;&gt;&lt;strong&gt;Part II: Slater’s Condition and Strong Duality&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-3-checking-slaters-condition-rockafellar-ex-283&quot;&gt;&lt;strong&gt;Exercise 3: Checking Slater’s Condition (Rockafellar, Ex. 28.3)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;For each of the following problems, check Slater’s condition:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; \(\min x^2\) s.t. \(x^2 \leq 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;b)&lt;/strong&gt; \(\min x^2\) s.t. \(x^2 \leq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;c)&lt;/strong&gt; \(\min \frac{1}{2}x^T Q x\) s.t. \(Ax \leq b\) with \(Q \succ 0\)&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Slater’s condition:&lt;/strong&gt; There exists a strictly feasible \(\tilde{x}\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(f_i(\tilde{x}) &amp;lt; 0\) for all \(i\)&lt;/li&gt;
    &lt;li&gt;\(h_j(\tilde{x}) = 0\) for all \(j\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;a) \(\min x^2\) s.t. \(x^2 \leq 1\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Strictly feasible: \(\tilde{x}^2 &amp;lt; 1\), e.g. \(\tilde{x} = 0\) ✓&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Slater’s condition holds&lt;/strong&gt; → strong duality.&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) \(\min x^2\) s.t. \(x^2 \leq 0\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Strictly feasible: \(\tilde{x}^2 &amp;lt; 0\) → &lt;strong&gt;does not exist&lt;/strong&gt;!&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Slater’s condition does NOT hold&lt;/strong&gt;.&lt;/p&gt;

  &lt;p&gt;The feasible set is only \(x = 0\) (a single point). Strong duality nevertheless still holds (\(p^* = d^* = 0\)).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) QP with \(Q \succ 0\), \(Ax \leq b\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Strictly feasible: \(A\tilde{x} &amp;lt; b\) (component-wise).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Slater holds&lt;/strong&gt; if \(\{x : Ax &amp;lt; b\} \neq \emptyset\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-iii-quadratic-programming&quot;&gt;&lt;strong&gt;Part III: Quadratic Programming&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-4-a-simple-quadratic-program&quot;&gt;&lt;strong&gt;Exercise 4: A simple Quadratic Program&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;
\(\min_x \frac{1}{2}x^2 + x \quad \text{s.t.} \quad x \geq 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Rewrite the problem in standard form&lt;/li&gt;
  &lt;li&gt;Build the Lagrangian&lt;/li&gt;
  &lt;li&gt;Compute the dual function \(g(u)\)&lt;/li&gt;
  &lt;li&gt;Solve the dual problem&lt;/li&gt;
  &lt;li&gt;Compare the primal and dual solutions&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Rewrite the problem&lt;/strong&gt;
\(\min_x \frac{1}{2}x^2 + x \quad \text{s.t.} \quad -x + 1 \leq 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: The Lagrangian&lt;/strong&gt;
\(L(x,u) = \frac{1}{2}x^2 + x + u(-x + 1) = \frac{1}{2}x^2 + (1-u)x + u\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: Compute the dual function&lt;/strong&gt;
\(g(u) = \inf_x L(x,u)\)&lt;/p&gt;

  &lt;p&gt;Derivative: \(\frac{\partial L}{\partial x} = x + (1-u) = 0\) → \(x^* = u - 1\)&lt;/p&gt;

  &lt;p&gt;Substituting: \(g(u) = -\frac{1}{2}(u-1)^2 + u\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 4: The dual problem&lt;/strong&gt;
\(\max_u g(u) \quad \text{s.t.} \quad u \geq 0\)&lt;/p&gt;

  &lt;p&gt;\(g&apos;(u) = 2 - u = 0\) → \(u^* = 2\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 5: Compare the solutions&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Dual optimal: \(u^* = 2\), \(g^* = \frac{3}{2}\)&lt;/li&gt;
    &lt;li&gt;Primal optimal: \(x^* = 1\), \(f^* = \frac{3}{2}\)&lt;/li&gt;
    &lt;li&gt;Strong duality: \(f^* = g^*\) ✓&lt;/li&gt;
  &lt;/ul&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-5-qp-with-several-constraints&quot;&gt;&lt;strong&gt;Exercise 5: QP with several constraints&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;
\(\min_{x,y} x^2 + y^2 \quad \text{s.t.} \quad x + y \geq 2, \quad x \geq 0, \quad y \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Build the full Lagrangian&lt;/li&gt;
  &lt;li&gt;Compute the dual function&lt;/li&gt;
  &lt;li&gt;Find the KKT conditions&lt;/li&gt;
  &lt;li&gt;Solve the problem&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Lagrangian function:&lt;/strong&gt;
\(L(x,y,u_1,u_2,u_3) = x^2 + y^2 + u_1(-x - y + 2) + u_2(-x) + u_3(-y)\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;KKT conditions:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[\frac{\partial L}{\partial x} = 2x - u_1 - u_2 = 0\]
    &lt;/li&gt;
    &lt;li&gt;
\[\frac{\partial L}{\partial y} = 2y - u_1 - u_3 = 0\]
    &lt;/li&gt;
    &lt;li&gt;Complementary slackness&lt;/li&gt;
    &lt;li&gt;Primal and dual feasibility&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; \(x^* = y^* = 1\), \((u_1^*, u_2^*, u_3^*) = (2, 0, 0)\)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-iv-support-vector-machine-svm-dual&quot;&gt;&lt;strong&gt;Part IV: Support Vector Machine (SVM) Dual&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-6-svm-dual-formulation-boyd--vandenberghe-ex-86&quot;&gt;&lt;strong&gt;Exercise 6: SVM Dual Formulation (Boyd &amp;amp; Vandenberghe, Ex. 8.6)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the SVM problem:&lt;/p&gt;

\[\begin{align}
\min_{w, b} \quad &amp;amp; \frac{1}{2}\|w\|^2 \\
\text{s.t.} \quad &amp;amp; y_i(w^T x_i + b) \geq 1, \quad i = 1, \ldots, m
\end{align}\]

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Write the Lagrangian
b) Compute the dual function \(g(\alpha)\)
c) Write the dual problem
d) With 3 points \((1, 1, +1)\), \((1, -1, +1)\), \((-1, 0, -1)\), find the dual optimum&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Lagrangian:&lt;/strong&gt;&lt;/p&gt;

\[L(w, b, \alpha) = \frac{1}{2}\|w\|^2 - \sum_{i=1}^m \alpha_i (y_i(w^T x_i + b) - 1)\]

  &lt;p&gt;&lt;strong&gt;b) Dual function:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;FOC: \(w = \sum_i \alpha_i y_i x_i\), \(\sum_i \alpha_i y_i = 0\)&lt;/p&gt;

  &lt;p&gt;Substituting back:&lt;/p&gt;

\[g(\alpha) = \sum_i \alpha_i - \frac{1}{2}\sum_{i,j} \alpha_i \alpha_j y_i y_j x_i^T x_j\]

  &lt;p&gt;&lt;strong&gt;c) Dual problem:&lt;/strong&gt;&lt;/p&gt;

\[\boxed{
\begin{align}
\max_{\alpha} \quad &amp;amp; \sum_i \alpha_i - \frac{1}{2}\sum_{i,j} \alpha_i \alpha_j y_i y_j x_i^T x_j \\
\text{s.t.} \quad &amp;amp; \sum_i \alpha_i y_i = 0 \\
&amp;amp; \alpha_i \geq 0
\end{align}
}\]

  &lt;p&gt;&lt;strong&gt;d) Numerical computation:&lt;/strong&gt; All 3 points are support vectors. From \(w = \sum_i \alpha_i y_i x_i\), \(\sum_i \alpha_i y_i = 0\) and \(y_i(w^T x_i + b) = 1\) we get \(\alpha^* = (1/4,\ 1/4,\ 1/2)\), \(w^* = (1, 0)^T\), \(b^* = 0\), and dual value \(= 1 - \frac{1}{2}\|w^*\|^2 = \frac{1}{2}\).
Decision boundary: \(x_1 = 0\)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-v-complementary-slackness&quot;&gt;&lt;strong&gt;Part V: Complementary Slackness&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-7-applying-complementary-slackness&quot;&gt;&lt;strong&gt;Exercise 7: Applying Complementary Slackness&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the LP:&lt;/p&gt;

\[\begin{align}
\min_x \quad &amp;amp; c^T x \\
\text{s.t.} \quad &amp;amp; Ax = b \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Write the complementary slackness conditions
b) With \(c = \begin{bmatrix} -1 \\ -2 \end{bmatrix}\), \(A = \begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix}\), \(b = 1\), find the solution
c) Check complementary slackness&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Complementary Slackness:&lt;/strong&gt;&lt;/p&gt;

\[\lambda_i^* \cdot (-x_i^*) = 0\]

  &lt;p&gt;&lt;strong&gt;Meaning:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;If \(x_i^* &amp;gt; 0\): \(\lambda_i^* = 0\)&lt;/li&gt;
    &lt;li&gt;If \(\lambda_i^* &amp;gt; 0\): \(x_i^* = 0\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Solving the problem:&lt;/strong&gt;&lt;/p&gt;

\[\min \quad -x_1 - 2x_2 \quad \text{s.t.} \quad x_1 + x_2 = 1, \quad x \geq 0\]

  &lt;p&gt;Maximize \(x_1 + 2x_2\) subject to \(x_1 + x_2 = 1\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Primal solution:&lt;/strong&gt; \(x^* = (0, 1)^T\), \(p^* = -2\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Dual solution:&lt;/strong&gt; \(\nu^* = -2\), \(\lambda^* = (1, 0)^T\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Check:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\lambda_1^* \cdot 0 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;\(\lambda_2^* \cdot (-1) = 0\) ✓&lt;/li&gt;
  &lt;/ul&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-8-duality-gap-analysis-bertsekas-ex-612&quot;&gt;&lt;strong&gt;Exercise 8: Duality Gap Analysis (Bertsekas, Ex. 6.1.2)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the problem (note: \(x(x-2) = x^2 - 2x\) is a convex function):&lt;/p&gt;

\[\min_{x \in [0,2]} \quad x(x-2)\]

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Solve the primal problem
b) Write the Lagrangian and find the dual function
c) Solve the dual problem
d) Compute the duality gap&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Solving the primal:&lt;/strong&gt;&lt;/p&gt;

\[f(x) = x^2 - 2x = (x-1)^2 - 1\]

  &lt;p&gt;The minimum is at \(x = 1\) in \([0, 2]\): \(p^* = -1\)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) Lagrangian:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Rewrite: \(\min_x x^2 - 2x\) s.t. \(-x \leq 0\), \(x - 2 \leq 0\)&lt;/p&gt;

\[L(x, \lambda_1, \lambda_2) = x^2 - 2x - \lambda_1 x + \lambda_2(x - 2)\]

  &lt;p&gt;&lt;strong&gt;c) Dual analysis:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Minimizing over \(x\): \(x = \frac{2 + \lambda_1 - \lambda_2}{2}\), so \(g(\lambda_1, \lambda_2) = -\frac{(2 + \lambda_1 - \lambda_2)^2}{4} - 2\lambda_2\). Over \(\lambda \geq 0\), \(g\) is maximized at \(\lambda_1 = \lambda_2 = 0\): \(d^* = g(0, 0) = -1\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Duality gap:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Gap \(= p^* - d^* = -1 - (-1) = 0\). The problem is convex and satisfies Slater’s condition (e.g. \(x = 1\) satisfies both constraints strictly), so strong duality holds. The solution \(x^* = 1\) lies in the interior, neither constraint is active, so \(\lambda^* = 0\) (consistent with complementary slackness).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-vi-norm-approximation-and-related-problems&quot;&gt;&lt;strong&gt;Part VI: Norm Approximation and Related Problems&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-9-norm-approximation-boyd--vandenberghe-ex-53&quot;&gt;&lt;strong&gt;Exercise 9: Norm Approximation (Boyd &amp;amp; Vandenberghe, Ex. 5.3)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;
\(\min_x \lVert Ax - b \rVert\)&lt;/p&gt;

&lt;p&gt;where the norm is \(\ell_1, \ell_2,\) or \(\ell_\infty\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Reformulate as a constrained problem&lt;/li&gt;
  &lt;li&gt;Derive the dual for each case&lt;/li&gt;
  &lt;li&gt;Compare the dual problems&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Case 1: \(\ell_1\) norm&lt;/strong&gt;&lt;/p&gt;

\[\min_{x,t} \mathbf{1}^T t \quad \text{s.t.} \quad -t \leq Ax - b \leq t\]

  &lt;p&gt;Dual:
\(\max_{\lambda,\mu} -b^T(\lambda - \mu) \quad \text{s.t.} \quad A^T(\lambda - \mu) = 0, \quad \lambda + \mu = \mathbf{1}, \quad \lambda,\mu \geq 0\)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Case 2: \(\ell_2\) norm&lt;/strong&gt;&lt;/p&gt;

\[\min_{x,t} t \quad \text{s.t.} \quad \lVert Ax - b \rVert_2 \leq t\]

  &lt;p&gt;Dual:
\(\max_{\nu} -b^T \nu \quad \text{s.t.} \quad A^T \nu = 0, \quad \lVert \nu \rVert_2 \leq 1\)&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Case 3: \(\ell_\infty\) norm&lt;/strong&gt;&lt;/p&gt;

\[\min_{x,t} t \quad \text{s.t.} \quad -t\mathbf{1} \leq Ax - b \leq t\mathbf{1}\]

  &lt;p&gt;Dual:
\(\max_{\lambda,\mu} -b^T(\lambda - \mu) \quad \text{s.t.} \quad A^T(\lambda - \mu) = 0, \quad \lVert \lambda - \mu \rVert_1 \leq 1\)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-10-entropy-maximization-boyd--vandenberghe-ex-54&quot;&gt;&lt;strong&gt;Exercise 10: Entropy Maximization (Boyd &amp;amp; Vandenberghe, Ex. 5.4)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;
\(\max_x -\sum_{i=1}^n x_i \log x_i \quad \text{s.t.} \quad Ax = b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Convert to a minimization problem&lt;/li&gt;
  &lt;li&gt;Build the Lagrangian&lt;/li&gt;
  &lt;li&gt;Compute the dual function&lt;/li&gt;
  &lt;li&gt;Find the optimal solution&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Conversion:&lt;/strong&gt;
\(\min_x \sum_{i=1}^n x_i \log x_i \quad \text{s.t.} \quad Ax = b, \quad x \geq 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Lagrangian function:&lt;/strong&gt;
\(L(x,\nu,\lambda) = \sum_{i=1}^n x_i \log x_i + \nu^T(Ax - b) - \lambda^T x\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Optimality conditions:&lt;/strong&gt;
\(\frac{\partial L}{\partial x_i} = \log x_i + 1 + (A^T \nu)_i - \lambda_i = 0\)&lt;/p&gt;

  &lt;p&gt;Suy ra: \(x_i = e^{-(A^T \nu)_i + \lambda_i - 1}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt;
Since \(x_i = e^{\cdots} &amp;gt; 0\), we have \(\lambda_i = 0\): \(x_i = e^{-(A^T \nu)_i - 1}\). Dual function: \(g(\nu) = -b^T \nu - \sum_{i=1}^n e^{-(A^T \nu)_i - 1}\); solve \(\max_\nu g(\nu)\) (unconstrained) and substitute back to obtain \(x^*\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-vii-concrete-computations-with-lagrange-multipliers&quot;&gt;&lt;strong&gt;Part VII: Concrete Computations with Lagrange Multipliers&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-11-portfolio-optimization-with-dual-variables&quot;&gt;&lt;strong&gt;Exercise 11: Portfolio Optimization with Dual Variables&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; An investor with 100 million VND wants to invest in 3 assets with:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Expected returns: \(r = (12\%, 8\%, 5\%)^T\)&lt;/li&gt;
  &lt;li&gt;Risk covariance matrix: \(\Sigma = \begin{bmatrix} 0.04 &amp;amp; 0.01 &amp;amp; 0 \\ 0.01 &amp;amp; 0.02 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0.01 \end{bmatrix}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Problem: \(\min_x \frac{1}{2}x^T \Sigma x\) s.t. \(r^T x \geq 10\%\), \(\mathbf{1}^T x = 1\), \(x \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Write the Lagrangian with all constraints
b) Derive the KKT conditions
c) Solve for the optimal allocation \(x^*\)
d) Compute the dual variables and explain their economic meaning&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Step-by-step solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Lagrangian:&lt;/strong&gt;&lt;/p&gt;

\[L(x, \lambda_1, \nu, \lambda_2) = \frac{1}{2}x^T \Sigma x - \lambda_1(r^T x - 0.1) + \nu(\mathbf{1}^T x - 1) - \lambda_2^T x\]

  &lt;p&gt;with \(\lambda_1, \lambda_2 \geq 0\).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) KKT conditions:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt;
\(\nabla_x L = \Sigma x - \lambda_1 r + \nu \mathbf{1} - \lambda_2 = 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Primal feasibility:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[r^T x \geq 0.1\]
    &lt;/li&gt;
    &lt;li&gt;
\[\mathbf{1}^T x = 1\]
    &lt;/li&gt;
    &lt;li&gt;
\[x \geq 0\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Dual feasibility:&lt;/strong&gt;
\(\lambda_1, \lambda_2 \geq 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[\lambda_1(r^T x - 0.1) = 0\]
    &lt;/li&gt;
    &lt;li&gt;\(\lambda_{2i} x_i = 0\) for all \(i\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Solving the problem:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Assume the return constraint is active (\(r^T x = 0.1\)) and all \(x_i &amp;gt; 0\) (no short positions).&lt;/p&gt;

  &lt;p&gt;From complementary slackness: \(\lambda_2 = 0\).&lt;/p&gt;

  &lt;p&gt;From stationarity:
\(\Sigma x = \lambda_1 r - \nu \mathbf{1}\)&lt;/p&gt;

\[\begin{bmatrix} 0.04 &amp;amp; 0.01 &amp;amp; 0 \\ 0.01 &amp;amp; 0.02 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0.01 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \lambda_1 \begin{bmatrix} 0.12 \\ 0.08 \\ 0.05 \end{bmatrix} - \nu \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}\]

  &lt;p&gt;Combined with:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[x_1 + x_2 + x_3 = 1\]
    &lt;/li&gt;
    &lt;li&gt;
\[0.12x_1 + 0.08x_2 + 0.05x_3 = 0.1\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Solving the system:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;From equation 3: \(0.01x_3 = 0.05\lambda_1 - \nu\)&lt;/p&gt;

  &lt;p&gt;From the 2 constraints:
\(x_3 = 1 - x_1 - x_2\)
\(0.12x_1 + 0.08x_2 + 0.05(1 - x_1 - x_2) = 0.1\)
\(0.07x_1 + 0.03x_2 = 0.05\)&lt;/p&gt;

  &lt;p&gt;Combining the 3 stationarity equations with the 2 constraints (5 linear equations, 5 unknowns) and solving exactly:&lt;/p&gt;

\[x^* = \begin{bmatrix} 7/12 \\ 11/36 \\ 1/9 \end{bmatrix} \approx \begin{bmatrix} 0.583 \\ 0.306 \\ 0.111 \end{bmatrix}, \quad \lambda_1^* = \frac{13}{36} \approx 0.361, \quad \nu^* = \frac{61}{3600} \approx 0.017\]

  &lt;p&gt;&lt;strong&gt;Check:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Return: \(0.12 \cdot \frac{7}{12} + 0.08 \cdot \frac{11}{36} + 0.05 \cdot \frac{1}{9} = 0.1\) ✓, weights sum to \(1\) ✓, all \(x_i &amp;gt; 0\) ✓ (the assumption holds)&lt;/li&gt;
    &lt;li&gt;Risk: \(\frac{1}{2}x^{*T}\Sigma x^* = \frac{23}{2400} \approx 0.00958\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;d) Economic interpretation:&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;\(\lambda_1^* \approx 0.361\): &lt;strong&gt;Shadow price of the return constraint&lt;/strong&gt;&lt;/li&gt;
    &lt;li&gt;Raising the required return from 10% to 11% increases the risk by about \(0.361 \times 0.01 \approx 0.0036\)&lt;/li&gt;
    &lt;li&gt;\(\nu^* \approx 0.017\): &lt;strong&gt;Sensitivity to the budget constraint&lt;/strong&gt;&lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Relaxing \(\mathbf{1}^T x = 1\) to \(1 + \delta\) (small \(\delta\)) changes the optimal risk by about \(-\nu^* \delta\)&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;\(\lambda_2 = 0\): No asset is at the short-selling boundary&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Optimal allocation:&lt;/strong&gt; about 58.3% in asset 1, 30.6% in asset 2, 11.1% in asset 3 (i.e. about 58.3 / 30.6 / 11.1 million VND).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-12-optimal-production-with-lagrange-multipliers&quot;&gt;&lt;strong&gt;Exercise 12: Optimal Production with Lagrange Multipliers&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; A company makes 2 products, A and B:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Profit: A = 40 thousand/unit, B = 30 thousand/unit&lt;/li&gt;
  &lt;li&gt;Limited resources:
    &lt;ul&gt;
      &lt;li&gt;Labor: 2A + B ≤ 100 hours&lt;/li&gt;
      &lt;li&gt;Material: A + 2B ≤ 80 kg&lt;/li&gt;
      &lt;li&gt;Machines: A ≤ 40 units&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Problem: \(\max_{x_1, x_2} 40x_1 + 30x_2\) subject to the constraints above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;
a) Convert to a minimization and write the Lagrangian
b) Find the optimal solution using KKT
c) Compute the shadow price of each resource
d) If 10 extra labor hours can be bought at 8 thousand/hour, should we buy them?&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Converting to minimization:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;\(\min_{x_1, x_2} -40x_1 - 30x_2\)
\(\text{s.t.} \quad 2x_1 + x_2 \leq 100, \quad x_1 + 2x_2 \leq 80, \quad x_1 \leq 40, \quad x_1, x_2 \geq 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt;&lt;/p&gt;

\[L(x, \lambda) = -40x_1 - 30x_2 + \lambda_1(2x_1 + x_2 - 100) + \lambda_2(x_1 + 2x_2 - 80) + \lambda_3(x_1 - 40)\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;b) KKT conditions:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Stationarity:&lt;/strong&gt;
\(\frac{\partial L}{\partial x_1} = -40 + 2\lambda_1 + \lambda_2 + \lambda_3 = 0\)
\(\frac{\partial L}{\partial x_2} = -30 + \lambda_1 + 2\lambda_2 = 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt;
\(\lambda_1(2x_1 + x_2 - 100) = 0\)
\(\lambda_2(x_1 + 2x_2 - 80) = 0\)
\(\lambda_3(x_1 - 40) = 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Observation:&lt;/strong&gt; The vertex \((40, 20)\) makes &lt;strong&gt;all three&lt;/strong&gt; constraints active at once: \(2(40) + 20 = 100\), \(40 + 2(20) = 80\), \(x_1 = 40\). This is a degenerate vertex.&lt;/p&gt;

  &lt;p&gt;Comparing the vertices of the feasible region: \((0, 0) \to 0\), \((0, 40) \to 1200\), \((40, 20) \to 2200\), \((40, 0) \to 1600\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Optimal solution:&lt;/strong&gt; \(x_1^* = 40\), \(x_2^* = 20\), profit \(40(40) + 30(20) = 2200\) thousand&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;KKT multipliers:&lt;/strong&gt; Since \(x_1^*, x_2^* &amp;gt; 0\), stationarity gives:&lt;/p&gt;

  &lt;p&gt;\(2\lambda_1 + \lambda_2 + \lambda_3 = 40\)
\(\lambda_1 + 2\lambda_2 = 30\)&lt;/p&gt;

  &lt;p&gt;Let \(\lambda_2 = s\): \(\lambda_1 = 30 - 2s\), \(\lambda_3 = 3s - 20\). The condition \(\lambda \geq 0\) gives \(20/3 \leq s \leq 15\), so the multipliers are &lt;strong&gt;not unique&lt;/strong&gt; (because of degeneracy). For example:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(s = 20/3\): \(\lambda = (50/3,\ 20/3,\ 0)\)&lt;/li&gt;
    &lt;li&gt;\(s = 10\): \(\lambda = (10,\ 10,\ 10)\)&lt;/li&gt;
    &lt;li&gt;\(s = 15\): \(\lambda = (0,\ 15,\ 25)\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Every choice gives the dual value \(100\lambda_1 + 80\lambda_2 + 40\lambda_3 = 2200\) ✓ (strong duality).&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;c) Shadow prices (Dual variables):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Because the multipliers are not unique, each shadow price is only meaningful &lt;strong&gt;in one direction&lt;/strong&gt;:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Labor:&lt;/strong&gt; \(\lambda_1 \in [0,\ 50/3]\). Losing 1 labor hour lowers profit by about \(50/3 \approx 16.7\) thousand, but &lt;strong&gt;adding&lt;/strong&gt; 1 hour raises profit by &lt;strong&gt;0&lt;/strong&gt;.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Material:&lt;/strong&gt; \(\lambda_2 \in [20/3,\ 15]\). Adding 1 kg raises profit by about \(20/3 \approx 6.7\) thousand; removing 1 kg lowers it by about 15 thousand.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Machines:&lt;/strong&gt; \(\lambda_3 \in [0,\ 25]\). Relaxing \(x_1 \leq 40\) by 1 unit raises profit by &lt;strong&gt;0&lt;/strong&gt; (labor immediately becomes the limit); tightening it costs about 25 thousand.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;d) Decision on buying labor:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;With 110 labor hours, the constraints \(x_1 \leq 40\) and \(x_1 + 2x_2 \leq 80\) still keep the solution at \((40, 20)\), and profit stays at 2200 thousand. The shadow price &lt;strong&gt;for an increase&lt;/strong&gt; in labor is 0.&lt;/p&gt;

  &lt;p&gt;Cost: \(10 \times 8 = 80\) thousand; benefit: 0.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; ❌ &lt;strong&gt;DO NOT BUY.&lt;/strong&gt; Buying 10 hours loses 80 thousand. The real bottlenecks are material and machines.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; At a degenerate vertex, the derivative of the optimal profit with respect to a resource differs on the two sides, so always check the range in sensitivity analysis before using a shadow price.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;summary-of-strategy&quot;&gt;&lt;strong&gt;Summary of Strategy&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;lagrangian-duality&quot;&gt;&lt;strong&gt;Lagrangian Duality:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt; \(L(x, \lambda, \nu) = f_0(x) + \sum_i \lambda_i f_i(x) + \sum_j \nu_j h_j(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual function:&lt;/strong&gt; \(g(\lambda, \nu) = \inf_x L(x, \lambda, \nu)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual problem:&lt;/strong&gt; \(\max_{\lambda \geq 0, \nu} g(\lambda, \nu)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;duality-relations&quot;&gt;&lt;strong&gt;Duality Relations:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Weak duality:&lt;/strong&gt; \(d^* \leq p^*\) always holds&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; \(d^* = p^*\) (requires Slater’s condition)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duality gap:&lt;/strong&gt; \(p^* - d^* \geq 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;complementary-slackness&quot;&gt;&lt;strong&gt;Complementary Slackness:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;\(\lambda_i^* f_i(x^*) = 0\) for all \(i\)&lt;/li&gt;
  &lt;li&gt;Active constraints may have \(\lambda_i^* &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;Inactive constraints have \(\lambda_i^* = 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;when-to-use-the-dual&quot;&gt;&lt;strong&gt;When to use the dual:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;The dual problem is easier to solve&lt;/li&gt;
  &lt;li&gt;Sensitivity analysis is needed (shadow prices)&lt;/li&gt;
  &lt;li&gt;Algorithm efficiency (interior point methods)&lt;/li&gt;
  &lt;li&gt;Fewer variables (as in SVM: \(m &amp;lt; n\))&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 5.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Rockafellar, R. T.&lt;/strong&gt; (1970). &lt;em&gt;Convex Analysis&lt;/em&gt;. Princeton University Press. Chapter 28.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bertsekas, D. P.&lt;/strong&gt; (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt; (2nd ed.). Athena Scientific. Chapter 6.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Luenberger, D. G., &amp;amp; Ye, Y.&lt;/strong&gt; (2008). &lt;em&gt;Linear and Nonlinear Programming&lt;/em&gt; (3rd ed.). Springer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bazaraa, M. S., Sherali, H. D., &amp;amp; Shetty, C. M.&lt;/strong&gt; (2006). &lt;em&gt;Nonlinear Programming: Theory and Algorithms&lt;/em&gt; (3rd ed.). Wiley.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>11-09 Multiple-Choice Quiz - Duality in General Programs</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_09_Quiz_General_Duality/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_09_Quiz_General_Duality</id>
   <content type="html">&lt;p&gt;Before starting the Chapter 11 multiple-choice quiz, pause to separate the &lt;em&gt;always-true&lt;/em&gt; laws of Lagrangian duality from the &lt;em&gt;conditional&lt;/em&gt; ones. The single most common exam mistake is thinking that \(g(u, v)\) is only concave when the primal is convex (false—\(g\) is &lt;em&gt;always&lt;/em&gt; concave!), or thinking convexity alone guarantees strong duality (false—you also need a constraint qualification like Slater’s condition!). Use the four diagnostic pillars and rapid warm-up below to calibrate your intuition.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-chapter-11-mastery-checklist&quot;&gt;Key ideas: Chapter 11 Mastery Checklist&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Universal Laws (No Convexity Needed):&lt;/strong&gt; For &lt;em&gt;any&lt;/em&gt; optimization problem, (i) \(L(x, u, v)\) is affine in \((u, v)\), (ii) \(g(u, v) = \inf_x L(x, u, v)\) is concave, (iii) the dual problem \(\max_{u \ge 0, v} g(u, v)\) is convex, and (iv) weak duality \(g^\star \le f^\star\) holds.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Strong Duality &amp;amp; Slater’s Condition:&lt;/strong&gt; Strong duality (\(g^\star = f^\star\)) is guaranteed for convex problems admitting a strictly feasible point \(x\) (\(h_i(x) &amp;lt; 0\) for non-affine inequalities, \(h_k(x) \le 0\) for affine inequalities, \(l_j(x) = 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Duality Gap &amp;amp; Certification:&lt;/strong&gt; For any feasible \(x\) and \((u, v)\) with \(u \ge 0\), \(f(x) - f^\star \le f(x) - g(u, v)\). Zero duality gap proves both \(x\) and \((u, v)\) are globally optimal.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Double Duality &amp;amp; Perturbation:&lt;/strong&gt; The dual of the dual recovers the primal when the problem is closed and convex; for nonconvex problems it yields the convex envelope (biconjugate), explaining why a strict duality gap \(f^\star - g^\star &amp;gt; 0\) can persist.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-quick-3-part-diagnostic-on-a-constrained-exponential-problem&quot;&gt;Worked example: Quick 3-Part Diagnostic on a Constrained Exponential Problem&lt;/h3&gt;

&lt;p&gt;Consider \(\min_{x \in \mathbb{R}} e^x\) subject to \(x \ge 0\) (i.e., \(-x \le 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Lagrangian and dual function:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(L(x, u) = e^x - u x\) for \(u \ge 0\).&lt;/li&gt;
      &lt;li&gt;Minimize over \(x \in \mathbb{R}\):
        &lt;ul&gt;
          &lt;li&gt;If \(u = 0\): \(\inf_x e^x = 0\) (approached as \(x \to -\infty\)).&lt;/li&gt;
          &lt;li&gt;If \(u &amp;gt; 0\): set \(e^x - u = 0 \implies x = \ln u\), giving \(g(u) = u - u \ln u\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Verify concavity of \(g(u) = u - u\ln u\): \(g&apos;&apos;(u) = -1/u &amp;lt; 0\) on \(u &amp;gt; 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the dual problem \(\max_{u \ge 0} (u - u\ln u)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Set \(g&apos;(u) = 1 - (\ln u + 1) = -\ln u = 0 \implies u^\star = 1\).&lt;/li&gt;
      &lt;li&gt;Dual optimal value: \(g^\star = 1 - 1\ln(1) = 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify Slater’s condition and strong duality:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal is convex and \(x = 1\) satisfies \(-1 &amp;lt; 0\) (Slater holds!).&lt;/li&gt;
      &lt;li&gt;Primal minimum is at \(x^\star = 0\) with \(f^\star = e^0 = 1 = g^\star\) (zero gap!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-general-duality&quot;&gt;⚡ &lt;strong&gt;General Duality&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;general-optimization-problem&quot;&gt;&lt;strong&gt;General optimization problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) \quad \text{s.t.} \quad h_i(x) \le 0, \quad l_j(x) = 0\)&lt;/p&gt;

&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(x)\): the objective function (not necessarily convex)&lt;/li&gt;
  &lt;li&gt;\(h_i(x) \le 0\): inequality constraints (\(i = 1,\ldots,m\))&lt;/li&gt;
  &lt;li&gt;\(l_j(x) = 0\): equality constraints (\(j = 1,\ldots,r\))&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;extending-lp-duality&quot;&gt;&lt;strong&gt;Extending LP Duality&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP Duality (Chapter 10):&lt;/strong&gt; Applies only to linear programs&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;General Duality (Chapter 11):&lt;/strong&gt; Applies to &lt;strong&gt;any&lt;/strong&gt; optimization problem&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Main tool:&lt;/strong&gt; The Lagrangian function instead of a linear combination&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-the-lagrangian-function&quot;&gt;📏 &lt;strong&gt;The Lagrangian Function&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(L(x,u,v) = f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x)\)&lt;/p&gt;

&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(u \in \mathbb{R}^m, u \ge 0\): dual variables for the inequality constraints&lt;/li&gt;
  &lt;li&gt;\(v \in \mathbb{R}^r\): dual variables for the equality constraints (no sign constraint)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;basic-properties&quot;&gt;&lt;strong&gt;Basic properties&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;For every feasible \(x\) and every \(u \ge 0, v\):
\(L(x,u,v) = f(x) + \sum_{i=1}^m u_i \underbrace{h_i(x)}_{\le 0} + \sum_{j=1}^r v_j \underbrace{l_j(x)}_{= 0} \le f(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meaning:&lt;/strong&gt; The Lagrangian provides a &lt;strong&gt;lower bound&lt;/strong&gt; on \(f(x)\) at every feasible point.&lt;/p&gt;

&lt;h4 id=&quot;geometric-interpretation&quot;&gt;&lt;strong&gt;Geometric interpretation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal problem:&lt;/strong&gt; Find the minimum directly in the feasible region&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt; “Penalty method” - adds a penalty for constraint violations&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual variables:&lt;/strong&gt; “Prices” for violating the constraints&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-the-lagrange-dual-function&quot;&gt;🎯 &lt;strong&gt;The Lagrange Dual Function&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition-1&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(g(u,v) = \min_x L(x,u,v) = \min_x \left\{ f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x) \right\}\)&lt;/p&gt;

&lt;h4 id=&quot;important-properties&quot;&gt;&lt;strong&gt;Important properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lower bound:&lt;/strong&gt; \(g(u,v) \le f^*\) for all \(u \ge 0, v\) (weak duality)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Concavity:&lt;/strong&gt; \(g(u,v)\) is a &lt;strong&gt;concave&lt;/strong&gt; function of \((u,v)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Independent of convexity:&lt;/strong&gt; \(g\) is concave even when \(f\) is not convex&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;proof-of-concavity&quot;&gt;&lt;strong&gt;Proof of concavity&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(g(u,v) = \min_x L(x,u,v) = -\max_x \{-L(x,u,v)\}\)&lt;/p&gt;

&lt;p&gt;Since \(-L(x,u,v)\) is &lt;strong&gt;convex&lt;/strong&gt; in \((u,v)\) (linear), and the \(\max_x\) of convex functions is convex, \(g(u,v)\) is concave.&lt;/p&gt;

&lt;h3 id=&quot;-the-lagrange-dual-problem&quot;&gt;📊 &lt;strong&gt;The Lagrange Dual Problem&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition-2&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max_{u,v} g(u,v) \quad \text{s.t.} \quad u \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Find the &lt;strong&gt;best lower bound&lt;/strong&gt; on \(f^*\)&lt;/p&gt;

&lt;h4 id=&quot;special-properties&quot;&gt;&lt;strong&gt;Special properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always a convex problem:&lt;/strong&gt; Maximize a concave function over a convex set&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Independent of the primal:&lt;/strong&gt; The dual is always convex even when the primal is non-convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational advantage:&lt;/strong&gt; May be easier to solve than the primal&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;weak-duality&quot;&gt;&lt;strong&gt;Weak Duality&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Always true:&lt;/strong&gt; \(g^* \le f^*\) (dual optimal ≤ primal optimal)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Duality gap:&lt;/strong&gt; \(f^* - g^* \ge 0\)&lt;/p&gt;

&lt;h3 id=&quot;-example-quadratic-programming&quot;&gt;🔄 &lt;strong&gt;Example: Quadratic Programming&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;problem&quot;&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x \frac{1}{2}x^T Q x + c^T x \quad \text{s.t.} \quad Ax = b, \quad x \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;case-1-q-succ-0-positive-definite&quot;&gt;&lt;strong&gt;Case 1: \(Q \succ 0\) (positive definite)&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt;
\(L(x,u,v) = \frac{1}{2}x^T Q x + c^T x - u^T x + v^T(Ax - b)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Minimizing over \(x\):&lt;/strong&gt;
\(\nabla_x L = Qx + c - u + A^T v = 0\)
\(\Rightarrow x^* = Q^{-1}(u - c - A^T v)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual function:&lt;/strong&gt;
\(g(u,v) = -\frac{1}{2}(c - u + A^T v)^T Q^{-1}(c - u + A^T v) - b^T v\)&lt;/p&gt;

&lt;h4 id=&quot;case-2-q-succeq-0-positive-semidefinite&quot;&gt;&lt;strong&gt;Case 2: \(Q \succeq 0\) (positive semidefinite)&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Dual function:&lt;/strong&gt;
\(g(u,v) = \begin{cases}
-\frac{1}{2}(c - u + A^T v)^T Q^+(c - u + A^T v) - b^T v &amp;amp; \text{if } c - u + A^T v \perp \text{null}(Q) \\
-\infty &amp;amp; \text{otherwise}
\end{cases}\)&lt;/p&gt;

&lt;p&gt;where \(Q^+\) is the Moore-Penrose pseudoinverse.&lt;/p&gt;

&lt;h3 id=&quot;-strong-duality&quot;&gt;💪 &lt;strong&gt;Strong Duality&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition-3&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Strong duality holds when:&lt;/strong&gt; \(f^* = g^*\) (duality gap = 0)&lt;/p&gt;

&lt;h4 id=&quot;slaters-condition&quot;&gt;&lt;strong&gt;Slater’s Condition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Sufficient condition for strong duality:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the primal problem is &lt;strong&gt;convex&lt;/strong&gt; and there exists a &lt;strong&gt;strictly feasible&lt;/strong&gt; \(x\):
\(h_i(x) &amp;lt; 0 \quad \forall i, \quad l_j(x) = 0 \quad \forall j\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Strict inequality is not needed for affine constraints.&lt;/p&gt;

&lt;h4 id=&quot;meaning-of-strong-duality&quot;&gt;&lt;strong&gt;Meaning of Strong Duality&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Perfect correspondence:&lt;/strong&gt; The primal and dual have the same optimal value&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational:&lt;/strong&gt; We can solve the dual instead of the primal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical:&lt;/strong&gt; Enables the KKT conditions (Chapter 12)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-example-support-vector-machine-svm&quot;&gt;🎯 &lt;strong&gt;Example: Support Vector Machine (SVM)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;primal-problem&quot;&gt;&lt;strong&gt;Primal problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{\beta,\beta_0,\xi} \frac{1}{2}\|\beta\|_2^2 + C\sum_{i=1}^n \xi_i\)
\(\text{s.t.} \quad \xi_i \ge 0, \quad y_i(x_i^T\beta + \beta_0) \ge 1 - \xi_i\)&lt;/p&gt;

&lt;h4 id=&quot;lagrangian&quot;&gt;&lt;strong&gt;Lagrangian&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(L(\beta,\beta_0,\xi,v,w) = \frac{1}{2}\|\beta\|_2^2 + C\sum_{i=1}^n \xi_i - \sum_{i=1}^n v_i \xi_i + \sum_{i=1}^n w_i(1 - \xi_i - y_i(x_i^T\beta + \beta_0))\)&lt;/p&gt;

&lt;h4 id=&quot;dual-problem-after-eliminating-the-primal-variables&quot;&gt;&lt;strong&gt;Dual problem&lt;/strong&gt; (after eliminating the primal variables)&lt;/h4&gt;
&lt;p&gt;\(\max_w -\frac{1}{2}w^T \tilde{X}\tilde{X}^T w + \mathbf{1}^T w\)
\(\text{s.t.} \quad 0 \le w \le C\mathbf{1}, \quad w^T y = 0\)&lt;/p&gt;

&lt;p&gt;with \(\tilde{X} = \text{diag}(y)X\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; Slater’s condition holds → \(f^* = g^*\)&lt;/p&gt;

&lt;h3 id=&quot;-duality-gap&quot;&gt;📐 &lt;strong&gt;Duality Gap&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition-4&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Given a primal feasible \(x\) and a dual feasible \((u,v)\):
\(\text{Duality gap} = f(x) - g(u,v)\)&lt;/p&gt;

&lt;h4 id=&quot;properties&quot;&gt;&lt;strong&gt;Properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Upper bound on suboptimality:&lt;/strong&gt; \(f(x) - f^* \le f(x) - g(u,v)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stopping criterion:&lt;/strong&gt; If \(f(x) - g(u,v) \le \epsilon\) then \(f(x) - f^* \le \epsilon\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimality test:&lt;/strong&gt; \(f(x) - g(u,v) = 0 \Leftrightarrow x, (u,v)\) optimal&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;use-in-algorithms&quot;&gt;&lt;strong&gt;Use in algorithms&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual methods:&lt;/strong&gt; Simultaneously update the primal and dual variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence monitoring:&lt;/strong&gt; Track the duality gap instead of objective values&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Early stopping:&lt;/strong&gt; Stop when the duality gap is small enough&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-comparing-lp-duality-and-general-duality&quot;&gt;🔄 &lt;strong&gt;Comparing LP Duality and General Duality&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;strong&gt;Aspect&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;LP Duality (Ch 10)&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;General Duality (Ch 11)&lt;/strong&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Scope&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear programs only&lt;/td&gt;
      &lt;td&gt;Any optimization problem&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Method&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear combination of constraints&lt;/td&gt;
      &lt;td&gt;Lagrangian function&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dual convexity&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Always convex (LP)&lt;/td&gt;
      &lt;td&gt;Always convex (concave \(g\))&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Strong duality&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;If one feasible → strong duality&lt;/td&gt;
      &lt;td&gt;Slater’s condition needed&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Applications&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;LP, network flows, games&lt;/td&gt;
      &lt;td&gt;SVM, QP, general constrained&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-practical-techniques&quot;&gt;🛠️ &lt;strong&gt;Practical Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;constructing-the-dual-problem&quot;&gt;&lt;strong&gt;Constructing the dual problem:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write Lagrangian:&lt;/strong&gt; \(L(x,u,v) = f(x) + u^T h(x) + v^T l(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize over \(x\):&lt;/strong&gt; \(g(u,v) = \min_x L(x,u,v)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the optimization:&lt;/strong&gt; \(\nabla_x L = 0\) (if unconstrained)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Substitute back:&lt;/strong&gt; Get \(g(u,v)\) explicitly&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Maximize \(g\):&lt;/strong&gt; Subject to \(u \ge 0\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;checking-strong-duality&quot;&gt;&lt;strong&gt;Checking strong duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Verify convexity:&lt;/strong&gt; Primal problem convex?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check Slater’s condition:&lt;/strong&gt; Strictly feasible point exists?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Special cases:&lt;/strong&gt; LP, QP with \(Q \succ 0\), etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;computational-strategies&quot;&gt;&lt;strong&gt;Computational strategies:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dual easier:&lt;/strong&gt; When the dual has fewer variables or a simpler structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual methods:&lt;/strong&gt; Update both simultaneously&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duality gap monitoring:&lt;/strong&gt; For convergence assessment&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-illustrative-examples&quot;&gt;💡 &lt;strong&gt;Illustrative Examples&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;simple-problem&quot;&gt;&lt;strong&gt;Simple problem:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x x^2 \quad \text{s.t.} \quad x \ge 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt;
\(L(x,u) = x^2 - u(x - 1) = x^2 - ux + u\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Minimize over \(x\):&lt;/strong&gt;
\(\frac{\partial L}{\partial x} = 2x - u = 0 \Rightarrow x = \frac{u}{2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual function:&lt;/strong&gt;
\(g(u) = L\left(\frac{u}{2}, u\right) = \frac{u^2}{4} - u \cdot \frac{u}{2} + u = -\frac{u^2}{4} + u\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual problem:&lt;/strong&gt;
\(\max_u -\frac{u^2}{4} + u \quad \text{s.t.} \quad u \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; \(u^* = 2\), \(g^* = 1\), \(x^* = 1\), \(f^* = 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; \(f^* = g^* = 1\) ✓&lt;/p&gt;

&lt;h3 id=&quot;-connections-to-other-chapters&quot;&gt;🎯 &lt;strong&gt;Connections to Other Chapters&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-the-previous-chapter&quot;&gt;&lt;strong&gt;From the previous chapter:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 10:&lt;/strong&gt; LP duality as a special case&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 09:&lt;/strong&gt; Proximal gradient for composite problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 05:&lt;/strong&gt; QP as a canonical problem&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;importance-of-general-duality&quot;&gt;&lt;strong&gt;Importance of General Duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical foundation:&lt;/strong&gt; For modern optimization theory&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;KKT conditions:&lt;/strong&gt; Optimality conditions (Chapter 12)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithms:&lt;/strong&gt; Primal-dual methods, interior point&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; SVM, neural networks, regularization&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;looking-ahead&quot;&gt;&lt;strong&gt;Looking ahead:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 12:&lt;/strong&gt; KKT conditions and complementary slackness&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Advanced topics:&lt;/strong&gt; Robust optimization, semidefinite programming&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Applications:&lt;/strong&gt; Deep learning, reinforcement learning&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-theoretical-significance&quot;&gt;🌟 &lt;strong&gt;Theoretical Significance&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;duality-as-a-universal-principle&quot;&gt;&lt;strong&gt;Duality as a universal principle:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Every optimization problem&lt;/strong&gt; has a dual perspective&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The dual is always convex&lt;/strong&gt; even when the primal is non-convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Provides bounds&lt;/strong&gt; and &lt;strong&gt;optimality conditions&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enables algorithms&lt;/strong&gt; that are impossible with the primal alone&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;geometric-interpretation-1&quot;&gt;&lt;strong&gt;Geometric interpretation:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal:&lt;/strong&gt; Direct search in the feasible region&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual:&lt;/strong&gt; Indirect approach qua “supporting hyperplanes”&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; Perfect geometric correspondence&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;computational-significance&quot;&gt;&lt;strong&gt;Computational significance:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Alternative solution path:&lt;/strong&gt; The dual can be easier than the primal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parallel computation:&lt;/strong&gt; Primal-dual methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence monitoring:&lt;/strong&gt; The duality gap as a stopping criterion&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;when-to-use-duality&quot;&gt;&lt;strong&gt;When to use duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Primal hard to solve:&lt;/strong&gt; Many variables, complex constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual structure simpler:&lt;/strong&gt; Fewer dual variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bounds needed:&lt;/strong&gt; Duality gap for convergence assessment&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical analysis:&lt;/strong&gt; Optimality conditions, sensitivity&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;common-pitfalls&quot;&gt;&lt;strong&gt;Common pitfalls:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Forget constraint qualifications:&lt;/strong&gt; Slater’s condition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Wrong sign conventions:&lt;/strong&gt; \(u \ge 0\) for \(h(x) \le 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-convex primal:&lt;/strong&gt; Strong duality is not guaranteed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational issues:&lt;/strong&gt; The dual may be numerically unstable&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;debugging-strategies&quot;&gt;&lt;strong&gt;Debugging strategies:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Verify weak duality:&lt;/strong&gt; \(g^* \le f^*\) always holds&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check Slater’s condition:&lt;/strong&gt; For strong duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with known results:&lt;/strong&gt; LP, QP special cases&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical verification:&lt;/strong&gt; Small examples&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-advanced-topics&quot;&gt;🔬 &lt;strong&gt;Advanced Topics&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;fenchel-duality&quot;&gt;&lt;strong&gt;Fenchel duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Conjugate functions:&lt;/strong&gt; Alternative duality framework&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Applications:&lt;/strong&gt; Convex analysis, variational problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;conic-duality&quot;&gt;&lt;strong&gt;Conic duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Semidefinite programming:&lt;/strong&gt; Matrix optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-order cone programming:&lt;/strong&gt; Robust optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;stochastic-duality&quot;&gt;&lt;strong&gt;Stochastic duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Robust optimization:&lt;/strong&gt; Worst-case analysis&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chance constraints:&lt;/strong&gt; Probabilistic optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; General duality is a &lt;strong&gt;paradigm shift&lt;/strong&gt; from “solving the problem directly” to “finding the best bound and exploiting structure”. It is the foundation of all of modern optimization theory!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of duality for general programs, including the Lagrangian, the dual function, strong duality, the Slater condition and the KKT conditions.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🎯 Quiz: Duality in General Programs&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1: Lagrangian definition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: Given the problem \(\min f(x)\) s.t. \(h_i(x) \leq 0, l_j(x) = 0\). The Lagrangian is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(L(x,u,v) = f(x) + \sum u_i h_i(x) + \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(L(x,u,v) = f(x) - \sum u_i h_i(x) - \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(L(x,u,v) = f(x) + \sum u_i h_i(x) - \sum v_j l_j(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(L(x,u,v) = f(x) - \sum u_i h_i(x) + \sum v_j l_j(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$L(x,u,v) = f(x) + \sum u_i h_i(x) + \sum v_j l_j(x)$$&lt;/strong&gt;&lt;br /&gt;
                The Lagrangian combines the objective function with penalty terms for the constraints, with $$u_i \geq 0$$ for the inequality constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: In the Lagrangian, the dual variables must satisfy:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(u \geq 0, v\) unconstrained&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(u\) unconstrained, \(v \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(u \geq 0, v \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(u\) and \(v\) both unconstrained&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$u \geq 0, v$$ unconstrained&lt;/strong&gt;&lt;br /&gt;
                The dual variables $$u_i$$ for inequality constraints must be non-negative; $$v_j$$ for equality constraints have no sign constraint.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: The Lagrange dual function \(g(u,v)\) is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(g(u,v) = \max_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(g(u,v) = \min_x L(x,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \(g(u,v) = L(x^*,u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \(g(u,v) = \nabla_x L(x,u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$g(u,v) = \min_x L(x,u,v)$$&lt;/strong&gt;&lt;br /&gt;
                The dual function is the infimum of the Lagrangian over the primal variables $$x$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: The weak duality theorem states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) \(g(u,v) \geq f^*\) for all \(u \geq 0, v\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) \(g(u,v) \leq f^*\) for all \(u \geq 0, v\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) \(g(u,v) = f^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) \(g(u,v) &amp;gt; f^*\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$g(u,v) \leq f^*$$ for all $$u \geq 0, v$$&lt;/strong&gt;&lt;br /&gt;
                The dual function provides a lower bound on the primal optimal value: $$g^* \leq f^*$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: The Lagrange dual problem is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(\min_{u \geq 0, v} g(u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(\max_{u \geq 0, v} g(u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(\min_{u, v \geq 0} g(u,v)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \(\max_{u, v} g(u,v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\max_{u \geq 0, v} g(u,v)$$&lt;/strong&gt;&lt;br /&gt;
                The dual problem maximizes the dual function to find the best lower bound for the primal problem.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: Strong duality holds when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(f^* &amp;gt; g^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(f^* = g^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(f^* &amp;lt; g^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Duality gap &amp;gt; 0&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$f^* = g^*$$&lt;/strong&gt;&lt;br /&gt;
                Strong duality means there is no duality gap: the primal and dual optimal values are equal.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: The Slater condition requires:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) There exists \(x\) such that \(h_i(x) \leq 0, l_j(x) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) There exists \(x\) such that \(h_i(x) &amp;lt; 0, l_j(x) = 0\) (strictly feasible)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) There exists \(x\) such that \(h_i(x) = 0, l_j(x) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) All constraints are active&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) There exists $$x$$ such that $$h_i(x) &amp;lt; 0, l_j(x) = 0$$ (strictly feasible)&lt;/strong&gt;&lt;br /&gt;
                The Slater condition requires a strictly feasible (interior) point in order to guarantee strong duality.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8: Duality gap --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The duality gap is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(g^* - f^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(f^* - g^*\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(|f^* - g^*|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(f^* + g^*\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$f^* - g^*$$&lt;/strong&gt;&lt;br /&gt;
                The duality gap is the difference between the primal and dual optimal values, always non-negative by weak duality.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The KKT stationarity condition is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(\nabla f(x^*) + \sum u_i^* \nabla h_i(x^*) + \sum v_j^* \nabla l_j(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(\nabla f(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(u_i^* h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(h_i(x^*) \leq 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\nabla f(x^*) + \sum u_i^* \nabla h_i(x^*) + \sum v_j^* \nabla l_j(x^*) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Stationarity: the gradient of the Lagrangian with respect to $$x$$ is 0 at the optimal point.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: The KKT complementary slackness condition is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(u_i^* \geq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(h_i(x^*) \leq 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(u_i^* h_i(x^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(l_j(x^*) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) $$u_i^* h_i(x^*) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Complementary slackness: if a constraint is not active then its dual variable = 0; if a dual variable &amp;gt; 0 then its constraint is active.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: The KKT conditions are sufficient for optimality when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) The problem is convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) The problem is non-convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Always&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Never&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The problem is convex&lt;/strong&gt;&lt;br /&gt;
                The KKT conditions are necessary for every problem (under a constraint qualification), but only sufficient when the problem is convex.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The dual function \(g(u,v)\) has the property of being:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Always concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Always convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Possibly neither concave nor convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Always linear&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Always concave&lt;/strong&gt;&lt;br /&gt;
                The dual function is always concave because it is a pointwise minimum of linear functions of $$(u,v)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: A constraint qualification is needed to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Guarantee that the KKT conditions are necessary&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Guarantee that the dual function is concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Guarantee convexity&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Guarantee uniqueness&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Guarantee that the KKT conditions are necessary&lt;/strong&gt;&lt;br /&gt;
                A constraint qualification (such as LICQ, MFCQ) guarantees that the KKT conditions are necessary conditions for local optimality.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: In SVM, the dual problem has the form of:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Quadratic programming with linear constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Linear programming&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Nonlinear programming&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Integer programming&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Quadratic programming with linear constraints&lt;/strong&gt;&lt;br /&gt;
                The SVM dual is a QP: maximize a quadratic objective subject to linear constraints and box constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: At the optimal point, the Lagrangian has the saddle-point property:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(L(x^*,u,v) \leq L(x^*,u^*,v^*) \leq L(x,u^*,v^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(L(x^*,u,v) \geq L(x^*,u^*,v^*) \geq L(x,u^*,v^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(L(x^*,u^*,v^*) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) \(L(x,u,v)\) is constant&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$L(x^*,u,v) \leq L(x^*,u^*,v^*) \leq L(x,u^*,v^*)$$&lt;/strong&gt;&lt;br /&gt;
                Saddle-point property: the Lagrangian is minimized over $$x$$ and maximized over $$(u,v)$$ at the optimal point.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: In convex optimization, if the Slater condition holds then:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Weak duality holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Strong duality holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) KKT conditions sufficient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                For a convex problem with the Slater condition: weak duality always holds, strong duality holds, and KKT is necessary and sufficient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: If \(x^*\) is primal optimal and \((u^*,v^*)\) is dual optimal with strong duality, then:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) \(f(x^*) = g(u^*,v^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) \(f(x^*) &amp;gt; g(u^*,v^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) \(f(x^*) &amp;lt; g(u^*,v^*)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) It cannot be determined&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f(x^*) = g(u^*,v^*)$$&lt;/strong&gt;&lt;br /&gt;
                Strong duality means that the primal and dual optimal values are equal.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: Lagrangian relaxation is used to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Find an upper bound for a minimization problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Find a lower bound for a minimization problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Solve the original problem exactly&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Convert to a maximization problem&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Find a lower bound for a minimization problem&lt;/strong&gt;&lt;br /&gt;
                Lagrangian relaxation &quot;relaxes&quot; the constraints and provides a lower bound through the dual function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: Geometrically, a zero duality gap means:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) The feasible set is empty&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) A supporting hyperplane perfectly separates the epigraph and the feasible set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) The problem is unbounded&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Constraints redundant&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) A supporting hyperplane perfectly separates the epigraph and the feasible set&lt;/strong&gt;&lt;br /&gt;
                Strong duality corresponds to the existence of a supporting hyperplane separating the epigraph of the objective and the feasible region.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20: Applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: Lagrangian duality has applications in:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Machine learning (SVM, neural networks)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Economics (utility maximization)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Engineering (optimal control, signal processing)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above fields&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above fields&lt;/strong&gt;&lt;br /&gt;
                Lagrangian duality is a fundamental tool in optimization with wide applications in ML, economics, engineering and many other fields.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: The Lagrange dual function $$g(\lambda, \nu)$$ is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$\inf_x L(x, \lambda, \nu)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$\sup_x L(x, \lambda, \nu)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$\nabla_x L(x, \lambda, \nu)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$L(x^*, \lambda, \nu)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\inf_x L(x, \lambda, \nu)$$&lt;/strong&gt;&lt;br /&gt;
                Lagrange dual function: $$g(\lambda, \nu) = \inf_x L(x, \lambda, \nu)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: Weak duality states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$g(\lambda, \nu) \leq p^*$$ for $$\lambda \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$g(\lambda, \nu) \geq p^*$$ for $$\lambda \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$g(\lambda, \nu) = p^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) There is no relationship&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$g(\lambda, \nu) \leq p^*$$ for $$\lambda \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Weak duality: the dual value is always a lower bound on the primal value.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: The duality gap is zero when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Strong duality holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) The problem is convex and satisfies the Slater condition&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) The problem is a feasible LP&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                A zero duality gap is exactly strong duality; convexity + the Slater condition is a sufficient condition; a feasible LP always has strong duality. Note: convexity alone is not enough.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The Slater condition requires:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) There exists a feasible $$x$$ with $$g_i(x) &amp;lt; 0$$ (strict)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) There exists $$x$$ with $$g_i(x) \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) The objective function is convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) The constraints are linear&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) There exists a feasible $$x$$ with $$g_i(x) &amp;lt; 0$$ (strict)&lt;/strong&gt;&lt;br /&gt;
                Slater condition: there exists a strictly feasible point $$x$$ with $$g_i(x) &amp;lt; 0$$ for all $$i$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: The dual problem of $$\min f(x)$$ subject to $$h(x) \leq 0$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$\max g(\lambda)$$ subject to $$\lambda \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$\min g(\lambda)$$ subject to $$\lambda \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$\max g(\lambda)$$ subject to $$\lambda \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$\sup g(\lambda)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max g(\lambda)$$ subject to $$\lambda \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Dual problem: $$\max_{\lambda \geq 0} g(\lambda)$$ with $$g(\lambda) = \inf_x L(x,\lambda)$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;a&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;b&apos;, q9: &apos;a&apos;, q10: &apos;c&apos;,
    q11: &apos;a&apos;, q12: &apos;a&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;d&apos;, q17: &apos;a&apos;, q18: &apos;b&apos;, q19: &apos;b&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;d&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered Lagrangian duality theory!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand the KKT conditions and strong duality well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review the Slater condition and complementary slackness.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review the Lagrangian and the dual function.&apos;;
    } else {
        message = &apos;📖 Study general duality theory again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>11-07 The Dual of the Dual in General Convex Optimization</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_07_Dual_of_Dual_General_Case/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_07_Dual_of_Dual_General_Case</id>
   <content type="html">&lt;p&gt;In Chapter 10, taking the dual of an LP twice brought us right back to the original primal LP—perfect symmetry. Does that same involution hold for general optimization problems? The answer reveals one of the deepest structural truths in convex analysis (&lt;strong&gt;Fenchel–Moreau biconjugation&lt;/strong&gt;): if your primal problem is closed and convex (and satisfies strong duality), the dual of the dual &lt;em&gt;does&lt;/em&gt; recover the primal; if your primal is &lt;strong&gt;nonconvex&lt;/strong&gt;, taking the dual twice does &lt;em&gt;not&lt;/em&gt; return the original problem—it returns its &lt;strong&gt;convex hull / biconjugate relaxation&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-biconjugation-and-double-duality-in-general-programs&quot;&gt;Key ideas: Biconjugation and Double Duality in General Programs&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Fenchel Conjugate Machinery (\(f^\star\) and \(f^{\star\star}\)):&lt;/strong&gt; The conjugate \(f^\star(y) = \sup_x (y^\top x - f(x))\) encodes all supporting hyperplanes to the epigraph of \(f\). Applying conjugation twice gives \(f^{\star\star}(x) = \sup_y (x^\top y - f^\star(y))\), which is the largest closed convex function everywhere \(\le f\) (the convex envelope of \(f\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Fenchel–Moreau Theorem:&lt;/strong&gt; \(f^{\star\star} = f\) &lt;em&gt;if and only if&lt;/em&gt; \(f\) is proper, convex, and lower semicontinuous (closed). This single theorem is the exact engine behind the dual-of-the-dual property for general convex programs.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Perturbation Function View:&lt;/strong&gt; Writing the primal as \(p^\star(0)\) via \(p(w) = \inf_x \{ f(x) : h(x) \le w \}\), the Lagrange dual maximizes \(-p^\star(-u)\), and taking the dual a second time computes \(p^{\star\star}(0)\). Hence dual-of-dual equals primal &lt;em&gt;iff&lt;/em&gt; the optimal-value perturbation function is convex and closed at \(0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Automatic Convexification of Nonconvex Problems:&lt;/strong&gt; When applied to a nonconvex problem (such as integer programming or nonconvex quadratic minimization), double duality acts as a mathematical “ironing machine” that flattens every nonconvex dent into its tightest convex lower envelope.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-fstarstar-on-a-convex-vs-nonconvex-function&quot;&gt;Worked example: Computing \(f^{\star\star}\) on a Convex vs. Nonconvex Function&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Convex case: \(f(x) = \frac{1}{2}x^2\) on \(\mathbb{R}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;First conjugate: \(f^\star(y) = \sup_x (yx - \frac{1}{2}x^2)\). Setting \(y - x = 0 \implies x = y$, so\)f^\star(y) = \frac{1}{2}y^2$$.&lt;/li&gt;
      &lt;li&gt;Second conjugate: \(f^{\star\star}(x) = \sup_y (xy - \frac{1}{2}y^2) = \frac{1}{2}x^2 = f(x)\). Exact recovery!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nonconvex case: \(f(x) = (x^2 - 1)^2\) (a double-well potential with minima at \(x = \pm 1\) and a hump \(f(0) = 1\) at the origin):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(y = 0\), \(f^\star(0) = \sup_x (-(x^2 - 1)^2) = 0\) (attained at \(x = \pm 1\)).&lt;/li&gt;
      &lt;li&gt;For any \(x \in [-1, 1]\), every affine lower bound \(yx - f^\star(y)\) that stays \(\le 0\) at both \(x = -1\) and \(x = +1\) must stay \(\le 0\) on the entire interval \([-1, 1]\)! Meanwhile \(y = 0\) gives the lower bound \(0 \cdot x - 0 = 0\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Therefore, \(f^{\star\star}(x) = 0\) for all \(x \in [-1, 1]\), and \(f^{\star\star}(x) = (x^2 - 1)^2\) for $$&lt;/td&gt;
              &lt;td&gt;x&lt;/td&gt;
              &lt;td&gt;&amp;gt; 1$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Taking the dual twice completely flattened the nonconvex middle hump \(f(0) = 1\) down to \(f^{\star\star}(0) = 0\)—recovering the exact convex envelope rather than the original nonconvex function!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the previous chapter, we saw that for Linear Programming the property “the dual of the dual is the primal” always holds. Does this property still hold for general convex optimization problems? This lesson clarifies the question.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;recap-the-dual-of-the-dual-in-lp&quot;&gt;&lt;strong&gt;Recap: The Dual of the Dual in LP&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;In Linear Programming we have the following beautiful property:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primal problem:&lt;/strong&gt;
\(\begin{align}
\text{minimize} \quad &amp;amp; c^T x \\
\text{subject to} \quad &amp;amp; Ax \geq b, \\
&amp;amp; x \geq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual problem:&lt;/strong&gt;
\(\begin{align}
\text{maximize} \quad &amp;amp; b^T y \\
\text{subject to} \quad &amp;amp; A^T y \leq c, \\
&amp;amp; y \geq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual of the dual = Primal&lt;/strong&gt; (always true for LP)&lt;/p&gt;

&lt;p&gt;But does this still hold for general convex problems?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;the-general-convex-problem&quot;&gt;&lt;strong&gt;The General Convex Problem&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;the-general-case&quot;&gt;&lt;strong&gt;The General Case&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider a general convex problem (not only LP):&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; f_0(x) \\
\text{subject to} \quad &amp;amp; f_i(x) \leq 0, \; i = 1, \ldots, m, \\
&amp;amp; h_j(x) = 0, \; j = 1, \ldots, p,
\end{align}\]

&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;$f_0, f_1, \ldots, f_m$ are convex functions&lt;/li&gt;
  &lt;li&gt;$h_1, \ldots, h_p$ are affine functions&lt;/li&gt;
  &lt;li&gt;$x \in \mathbb{R}^n$ is the decision variable&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;constructing-the-dual-problem&quot;&gt;&lt;strong&gt;Constructing the Dual Problem&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;the-lagrangian&quot;&gt;&lt;strong&gt;The Lagrangian&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The dual is defined through the Lagrangian:&lt;/p&gt;

\[\mathcal{L}(x, \lambda, \nu) = f_0(x) + \sum_{i=1}^m \lambda_i f_i(x) + \sum_{j=1}^p \nu_j h_j(x)\]

&lt;p&gt;with:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;$\lambda \in \mathbb{R}^m$, $\lambda \geq 0$: Lagrange multipliers for the inequalities&lt;/li&gt;
  &lt;li&gt;$\nu \in \mathbb{R}^p$: Lagrange multipliers for the equalities&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;the-dual-function&quot;&gt;&lt;strong&gt;The Dual Function&lt;/strong&gt;&lt;/h3&gt;

\[g(\lambda, \nu) = \inf_x \mathcal{L}(x, \lambda, \nu)\]

&lt;h3 id=&quot;the-dual-problem&quot;&gt;&lt;strong&gt;The Dual Problem&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\text{maximize} \quad &amp;amp; g(\lambda, \nu) \\
\text{subject to} \quad &amp;amp; \lambda \geq 0
\end{align}\]

&lt;hr /&gt;

&lt;h2 id=&quot;the-dual-of-the-dual-for-a-convex-problem&quot;&gt;&lt;strong&gt;The Dual of the Dual for a Convex Problem&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;the-key-question&quot;&gt;&lt;strong&gt;The Key Question&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;If we take the dual of the dual problem, do we get back the original primal problem?&lt;/p&gt;

&lt;h3 id=&quot;the-result&quot;&gt;&lt;strong&gt;The Result&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem:&lt;/strong&gt; If the following conditions are satisfied:&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;The primal problem is &lt;strong&gt;convex&lt;/strong&gt;&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Strong duality&lt;/strong&gt; holds (duality gap = 0)&lt;/li&gt;
    &lt;li&gt;A &lt;strong&gt;constraint qualification&lt;/strong&gt; (such as Slater’s condition) holds&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;Then:&lt;/p&gt;

\[\boxed{\text{Dual of the dual} = \text{Primal}}\]

&lt;h3 id=&quot;important-conditions&quot;&gt;&lt;strong&gt;Important Conditions&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Slater’s Condition:&lt;/strong&gt; There exists a strictly feasible point:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;$f_i(\tilde{x}) &amp;lt; 0$ for all $i = 1, \ldots, m$&lt;/li&gt;
  &lt;li&gt;$h_j(\tilde{x}) = 0$ for all $j = 1, \ldots, p$&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Important note:&lt;/strong&gt; This does &lt;strong&gt;not always hold&lt;/strong&gt; for non-convex problems!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A remark on rigor:&lt;/strong&gt; Slater’s condition guarantees strong duality; for the dual of the dual (the “bidual”) to really recover exactly the primal problem, the primal problem must additionally be convex and “closed” (that is, the objective must be lower semicontinuous). For a non-convex problem, the dual of the dual in general only gives the convexified version of the primal problem (a convex relaxation).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;comparison-lp-vs-convex-optimization&quot;&gt;&lt;strong&gt;Comparison: LP vs Convex Optimization&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Property&lt;/th&gt;
      &lt;th&gt;Linear Programming&lt;/th&gt;
      &lt;th&gt;Convex Optimization&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dual of the dual = Primal&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Always true&lt;/td&gt;
      &lt;td&gt;Needs conditions&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Strong Duality&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Always true (if feasible)&lt;/td&gt;
      &lt;td&gt;Needs Slater’s condition&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Structure&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Perfect symmetry&lt;/td&gt;
      &lt;td&gt;Conditional symmetry&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Constraint Qualification&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Automatically satisfied&lt;/td&gt;
      &lt;td&gt;Must be checked&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;why-is-lp-special&quot;&gt;&lt;strong&gt;Why Is LP Special?&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;LP has special properties that make “dual of the dual = primal” always true:&lt;/p&gt;

&lt;h3 id=&quot;1-always-convex&quot;&gt;&lt;strong&gt;1. Always Convex&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Linear objective → convex&lt;/li&gt;
  &lt;li&gt;The feasible region is a polyhedron → convex&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-strong-duality-is-automatic&quot;&gt;&lt;strong&gt;2. Strong Duality Is Automatic&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;No need for Slater’s condition&lt;/li&gt;
  &lt;li&gt;It is enough that one of the two problems is feasible&lt;/li&gt;
  &lt;li&gt;Duality gap = 0 (if an optimum exists)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-perfectly-symmetric-structure&quot;&gt;&lt;strong&gt;3. Perfectly Symmetric Structure&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Matrix: $(A^T)^T = A$&lt;/li&gt;
  &lt;li&gt;Transposing twice returns the original&lt;/li&gt;
  &lt;li&gt;Swapping $(b, c)$ twice returns $(b, c)$&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-constraint-qualification&quot;&gt;&lt;strong&gt;4. Constraint Qualification&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Slater’s condition is automatically satisfied for LP&lt;/li&gt;
  &lt;li&gt;No need to check strict feasibility&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;illustrative-examples&quot;&gt;&lt;strong&gt;Illustrative Examples&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;example-1-quadratic-programming---convex-case&quot;&gt;&lt;strong&gt;Example 1: Quadratic Programming - Convex Case&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Primal problem:&lt;/strong&gt;
\(\begin{align}
\text{minimize} \quad &amp;amp; \frac{1}{2}x^T Q x + c^T x \\
\text{subject to} \quad &amp;amp; Ax \leq b
\end{align}\)&lt;/p&gt;

&lt;p&gt;with $Q \succ 0$ (positive definite).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The objective is strictly convex&lt;/li&gt;
  &lt;li&gt;The constraints are affine&lt;/li&gt;
  &lt;li&gt;If feasible → Slater’s condition holds&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual of the dual = Primal&lt;/strong&gt; ✓&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example-2-non-convex-case&quot;&gt;&lt;strong&gt;Example 2: Non-Convex Case&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Primal problem:&lt;/strong&gt;
\(\text{minimize} \quad -x^2 \quad \text{subject to} \quad 0 \leq x \leq 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The problem:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The objective $-x^2$ is concave, not convex&lt;/li&gt;
  &lt;li&gt;Strong duality fails&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual of the dual ≠ Primal&lt;/strong&gt; ✗&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Demonstration:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Primal optimal: $x^* = 1$, $p^* = -1$&lt;/p&gt;

&lt;p&gt;Dual (with $\lambda_1 \geq 0$ for the constraint $-x \leq 0$ and $\lambda_2 \geq 0$ for the constraint $x - 1 \leq 0$):
\(g(\lambda_1, \lambda_2) = \inf_{x \in \mathbb{R}} \left( -x^2 - \lambda_1 x + \lambda_2 (x - 1) \right) = -\infty \quad \text{for all } \lambda_1, \lambda_2 \geq 0,\)
because $-x^2 \to -\infty$ as $|x| \to \infty$.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The dual problem has optimal value $d^* = -\infty$&lt;/li&gt;
  &lt;li&gt;$d^* = -\infty &amp;lt; p^* = -1$&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;→ The duality gap is positive (in fact infinite), and the dual of the dual does not return to the primal&lt;/p&gt;

&lt;h3 id=&quot;example-3-convex-but-slater-fails&quot;&gt;&lt;strong&gt;Example 3: Convex but Slater Fails&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The problem:&lt;/strong&gt;
\(\text{minimize} \quad x^2 \quad \text{subject to} \quad x^2 \leq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analysis:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The objective is convex ✓&lt;/li&gt;
  &lt;li&gt;The feasible region consists of a single point: $x = 0$&lt;/li&gt;
  &lt;li&gt;There is no strictly feasible point&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Slater’s condition fails&lt;/strong&gt; ✗&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Primal: $p^* = 0$&lt;/li&gt;
  &lt;li&gt;Dual: $d^* = 0$&lt;/li&gt;
  &lt;li&gt;Strong duality still holds (by luck)&lt;/li&gt;
  &lt;li&gt;But the structure is not perfectly symmetric&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;applications-and-significance&quot;&gt;&lt;strong&gt;Applications and Significance&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;1-analyzing-the-duality-gap&quot;&gt;&lt;strong&gt;1. Analyzing the Duality Gap&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;When the dual of the dual does not return to the primal:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The duality gap &amp;gt; 0&lt;/li&gt;
  &lt;li&gt;We need to check the convexity conditions&lt;/li&gt;
  &lt;li&gt;Consider relaxation methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-algorithm-design&quot;&gt;&lt;strong&gt;2. Algorithm Design&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP&lt;/strong&gt;: We may choose to solve the primal or the dual freely&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex&lt;/strong&gt;: We must check the conditions before choosing&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-convex&lt;/strong&gt;: The dual only gives a lower bound&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-optimization-theory&quot;&gt;&lt;strong&gt;3. Optimization Theory&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;This property helps:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Understand the structure of problems more deeply&lt;/li&gt;
  &lt;li&gt;Develop optimality conditions (KKT)&lt;/li&gt;
  &lt;li&gt;Design primal-dual algorithms&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;practice-exercises&quot;&gt;&lt;strong&gt;Practice Exercises&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-1-checking-slaters-condition&quot;&gt;&lt;strong&gt;Exercise 1: Checking Slater’s Condition&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;For the following problems, check Slater’s condition and decide whether the dual of the dual equals the primal:&lt;/p&gt;

&lt;p&gt;a) $\min x^2 + y^2$ s.t. $x + y \geq 2$&lt;/p&gt;

&lt;p&gt;b) $\min e^x$ s.t. $x \geq 0$&lt;/p&gt;

&lt;p&gt;c) $\min -\log x$ s.t. $x \leq 1$, $x &amp;gt; 0$&lt;/p&gt;

&lt;h3 id=&quot;exercise-2-comparing-lp-and-qp&quot;&gt;&lt;strong&gt;Exercise 2: Comparing LP and QP&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the two problems:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LP:&lt;/strong&gt; $\min c^T x$ s.t. $Ax \leq b$&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;QP:&lt;/strong&gt; $\min \frac{1}{2}x^T Q x$ s.t. $Ax \leq b$ with $Q \succ 0$&lt;/p&gt;

&lt;p&gt;a) Construct the dual of each problem&lt;/p&gt;

&lt;p&gt;b) Check the property “dual of the dual = primal”&lt;/p&gt;

&lt;p&gt;c) Compare the required conditions&lt;/p&gt;

&lt;h3 id=&quot;exercise-3-a-non-convex-example&quot;&gt;&lt;strong&gt;Exercise 3: A Non-Convex Example&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the problem:
\(\min_{x \in \mathbb{R}} x^3 \quad \text{s.t.} \quad x \geq 1\)&lt;/p&gt;

&lt;p&gt;a) Solve the primal problem&lt;/p&gt;

&lt;p&gt;b) Construct the dual problem&lt;/p&gt;

&lt;p&gt;c) Show that the dual of the dual does not return to the primal&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;summary&quot;&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;main-conclusions&quot;&gt;&lt;strong&gt;Main Conclusions&lt;/strong&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;LP&lt;/strong&gt;: Dual of the dual = Primal (always true)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Optimization&lt;/strong&gt;: Dual of the dual = Primal (needs conditions)
    &lt;ul&gt;
      &lt;li&gt;Needs: Convexity + Strong duality + Constraint qualification&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-Convex&lt;/strong&gt;: Dual of the dual ≠ Primal (usually not true)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;important-conditions-1&quot;&gt;&lt;strong&gt;Important Conditions&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Condition&lt;/th&gt;
      &lt;th&gt;LP&lt;/th&gt;
      &lt;th&gt;Convex&lt;/th&gt;
      &lt;th&gt;Non-Convex&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Convexity&lt;/td&gt;
      &lt;td&gt;✓ (automatic)&lt;/td&gt;
      &lt;td&gt;✓ (must check)&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Strong Duality&lt;/td&gt;
      &lt;td&gt;✓ (if feasible)&lt;/td&gt;
      &lt;td&gt;✓ (needs Slater)&lt;/td&gt;
      &lt;td&gt;✗ (usually)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual = Dual = Primal&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
      &lt;td&gt;✓ (conditional)&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;applications&quot;&gt;&lt;strong&gt;Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Designing primal-dual algorithms&lt;/li&gt;
  &lt;li&gt;Sensitivity analysis&lt;/li&gt;
  &lt;li&gt;Checking optimality&lt;/li&gt;
  &lt;li&gt;Relaxation methods&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004).&lt;/strong&gt; &lt;em&gt;Convex Optimization.&lt;/em&gt; Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 5: Duality (especially Sections 5.2 and 5.3)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rockafellar, R. T. (1970).&lt;/strong&gt; &lt;em&gt;Convex Analysis.&lt;/em&gt; Princeton University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 31: Duality correspondences&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bertsekas, D. P. (1999).&lt;/strong&gt; &lt;em&gt;Nonlinear Programming&lt;/em&gt; (2nd ed.). Athena Scientific.
    &lt;ul&gt;
      &lt;li&gt;Chapter 6: Duality and convex analysis&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov, Y. (2018).&lt;/strong&gt; &lt;em&gt;Lectures on Convex Optimization.&lt;/em&gt; Springer.
    &lt;ul&gt;
      &lt;li&gt;Chapter 3: Duality Theory (Section 3.4)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Connections with other chapters:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 10&lt;/strong&gt;: The dual of the dual in LP (a special case)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 12&lt;/strong&gt;: KKT conditions (an application of duality)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapters 15 and 17&lt;/strong&gt;: The barrier method and primal-dual interior-point methods (algorithms based on duality)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>11-06 Intuition Behind Lagrange Duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_06_Lagrange_Duality_Intuition/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_06_Lagrange_Duality_Intuition</id>
   <content type="html">&lt;p&gt;Many students can mechanically write down \(L(x, u, v)\) and compute \(g(u, v)\), yet still feel a nagging mystery: &lt;em&gt;where did this dual problem actually come from geometrically?&lt;/em&gt; Picture plotting the set \(\mathcal{G} = \{ (h(x), f(x)) : x \in \mathcal{D} \}\) of all achievable (constraint-value, objective-value) pairs in the 2D plane. The primal optimum \(f^\star\) is the lowest point of \(\mathcal{G}\) on or to the left of the vertical axis \(h \le 0\); the dual optimum \(g^\star\) is the highest vertical-axis intercept of any &lt;strong&gt;non-vertical supporting line&lt;/strong&gt; lying underneath \(\mathcal{G}\)! This lesson unpacks that geometric lens—and connects it to economics, game theory, and Fenchel conjugates.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-intuitive-lenses-on-lagrange-duality&quot;&gt;Key ideas: Four Intuitive Lenses on Lagrange Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Geometric Lens (Supporting Hyperplanes to \(\mathcal{G}\)):&lt;/strong&gt; Minimizing \(f(x) + u^\top h(x)\) over \(x\) slides a hyperplane with slope \(-u\) upward from \(-\infty\) until it just touches the achievable set \(\mathcal{G} = \{(h(x), f(x))\}\). Its vertical-axis intercept is \(g(u)\); strong duality holds precisely when \(\mathcal{G}\)’s convex epigraph admits a non-vertical supporting hyperplane at \((0, f^\star)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Economic Lens (Resource Pricing &amp;amp; Sensitivity):&lt;/strong&gt; Viewing \(h_i(x) \le 0\) as a resource budget, \(u_i \ge 0\) is the market price per unit of resource \(i\). An entrepreneur choosing \(x\) to minimize \(f(x) + u^\top h(x)\) sells unused quota (\(h_i &amp;lt; 0\)) or buys extra quota (\(h_i &amp;gt; 0\)); at the optimal dual price \(u^\star\), the market clears with zero net excess demand.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Game-Theoretic Lens (Minimax Saddle Points):&lt;/strong&gt; The primal is \(\min_x \max_{u \ge 0} L(x, u)\) (the primal player moves first, then the dual adversary penalizes violations), while the dual is \(\max_{u \ge 0} \min_x L(x, u)\) (the dual player commits to prices first). Strong duality means the Lagrangian has a Nash equilibrium saddle point \((x^\star, u^\star)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Conjugate / Perturbation Lens:&lt;/strong&gt; Defining the optimal-value perturbation function \(p^\star(w) = \inf \{ f(x) : h(x) \le w \}\), the dual value is literally its biconjugate at zero: \(g^\star = p^{\star\star}(0)\). Thus strong duality is equivalent to \(p^\star\) being convex and lower semicontinuous at \(w = 0\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-tracing-the-supporting-line-in-the-h-f-plane&quot;&gt;Worked example: Tracing the Supporting Line in the \((h, f)\) Plane&lt;/h3&gt;

&lt;p&gt;Consider \(\min_{x \in \mathbb{R}} f(x) = x^2\) subject to \(h(x) = 1 - x \le 0\) (so \(x \ge 1\), \(x^\star = 1, f^\star = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Map out the achievable curve \(\mathcal{G} = \{(h(x), f(x))\}\) in the \((w, t)\) plane:&lt;/strong&gt;
Since \(w = 1 - x \implies x = 1 - w\), the curve is the parabola \(t = (1 - w)^2\)!
    &lt;ul&gt;
      &lt;li&gt;The feasible region \(h(x) \le 0\) is the left half-plane \(w \le 0\).&lt;/li&gt;
      &lt;li&gt;The lowest point of the parabola in \(w \le 0\) occurs at \(w = 0\) (i.e., \(x = 1\)), with height \(t = f^\star = 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Slide a supporting line \(t + u w = c\) (slope \(-u \le 0\)) up from below:&lt;/strong&gt;
The line touches the parabola \(t = (1 - w)^2\) where its slope matches the parabola’s derivative:
\(\frac{dt}{dw} = -2(1 - w) = -u \implies 1 - w = \frac{u}{2} \implies w = 1 - \frac{u}{2}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Read off the vertical-axis intercept (\(w = 0\)) of this tangent line:&lt;/strong&gt;
At the tangency point \((w, t) = (1 - u/2,\; u^2/4)\), the intercept \(c = t + u w\) is:
\(g(u) = \frac{u^2}{4} + u\left(1 - \frac{u}{2}\right) = u - \frac{u^2}{4}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Maximize the intercept over \(u \ge 0\):&lt;/strong&gt; The highest intercept occurs at \(u^\star = 2\) (the exact negative slope of the parabola at \(w = 0\): \(-(-2(1 - 0)) = 2\)!), giving \(g(2) = 2 - 1 = 1 = f^\star\)—making the geometric meaning of both \(g(u)\) and \(u^\star\) crystal clear!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;intuition-behind-lagrange-duality&quot;&gt;Intuition Behind Lagrange Duality&lt;/h1&gt;

&lt;h2 id=&quot;-the-general-optimization-problem&quot;&gt;🔍 The General Optimization Problem&lt;/h2&gt;

&lt;p&gt;Suppose we need to solve the optimization problem:&lt;/p&gt;

\[\begin{align}
\min_x f(x) \\
\text{s.t. } h_i(x) \leq 0, \quad i=1,\ldots,m \\
\mathcal{D} = \text{dom } f \cap \bigcap_{i=1}^{m} \text{dom } h_i
\end{align}\]

&lt;p&gt;&lt;em&gt;Note: For simplicity, we only consider inequality constraints. Equality constraints can be expressed as two inequality constraints.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;-the-mystery-of-the-dual&quot;&gt;🎭 The “Mystery” of the Dual&lt;/h2&gt;

&lt;p&gt;Following the standard procedure, we construct the Lagrangian function:&lt;/p&gt;

\[L(x, \lambda) = f(x) + \lambda^T h(x), \quad \lambda \succeq 0\]

&lt;p&gt;Then we define the “mysterious” dual function:&lt;/p&gt;

\[\begin{align}
g(\lambda) &amp;amp;= \inf_{x \in \mathcal{D}} L(x, \lambda) \\
&amp;amp;= \inf_{x \in \mathcal{D}} (f(x) + \lambda^T h(x))
\end{align}\]

&lt;p&gt;&lt;em&gt;Note: To find the infimum, \(x\) still ranges over the domain \(\mathcal{D}\), not over the feasible region defined by the constraints.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Finally, by solving the dual problem:&lt;/p&gt;

\[\max_{\lambda} g(\lambda) \quad \text{s.t. } \lambda \succeq 0\]

&lt;p&gt;we can find a good lower bound for the primal problem.&lt;/p&gt;

&lt;h2 id=&quot;-why-do-we-need-the-lagrangian&quot;&gt;🤔 Why Do We Need the Lagrangian?&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; Why do we need to construct this Lagrangian function?&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt; Because of the issue of &lt;strong&gt;perturbation&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We cannot solve the primal problem by simply computing \(\frac{\partial f(x)}{\partial x} = 0\), because the constraints define a feasible region. One feasible approach is to add the constraints as perturbation terms, and then estimate the best lower bound.&lt;/p&gt;

&lt;h3 id=&quot;-illustrative-example&quot;&gt;💡 Illustrative Example&lt;/h3&gt;

&lt;p&gt;Consider the optimization problem:&lt;/p&gt;

\[\begin{align}
\min_x x^2 \\
\text{s.t. } x - 1 \leq 0 \\
\mathcal{D} = \mathbb{R}
\end{align}\]

&lt;p&gt;The optimal solution is easy to guess: \(p^* = 0\) at \(x = 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Lagrangian:&lt;/strong&gt;
\(L(x, \lambda) = x^2 + \lambda(x - 1), \quad \lambda \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The dual function:&lt;/strong&gt;
\(g(\lambda) = \inf_{x \in \mathcal{D}} (x^2 + \lambda(x - 1)), \quad \lambda \geq 0\)&lt;/p&gt;

&lt;p&gt;To find \(\inf_{x \in \mathcal{D}} (x^2 + \lambda(x - 1))\), we need \(\frac{\partial L(x,\lambda)}{\partial x} = 0\).&lt;/p&gt;

&lt;p&gt;Therefore: \(2x + \lambda = 0 \Rightarrow x = -\frac{\lambda}{2}\)&lt;/p&gt;

&lt;p&gt;Substituting back into the dual function:
\(g(\lambda) = \frac{\lambda^2}{4} - \lambda \cdot \frac{\lambda}{2} - \lambda = -\frac{\lambda^2}{4} - \lambda, \quad \lambda \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The dual problem:&lt;/strong&gt;
\(\max_{\lambda} g(\lambda) \quad \text{s.t. } \lambda \geq 0\)&lt;/p&gt;

&lt;p&gt;The unconstrained maximizer of \(g\) is \(\lambda = -2\) (with \(g(-2) = 1\)), but this is not allowed because \(\lambda \geq 0\). On the domain \(\lambda \geq 0\), \(g\) is decreasing, so the dual solution is \(\lambda = 0\) with \(d^* = g(0) = 0 = p^*\) (strong duality)&lt;/p&gt;

&lt;div id=&quot;lagrangian-visualization&quot; style=&quot;margin: 20px 0; padding: 20px; background: #f8f9fa; border-radius: 10px;&quot;&gt;
    &lt;canvas id=&quot;lagrangianCanvas&quot; width=&quot;900&quot; height=&quot;500&quot; style=&quot;border: 2px solid #dee2e6; display: block; margin: 0 auto; background: white; border-radius: 5px;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin: 15px 0;&quot;&gt;
        &lt;div style=&quot;display: inline-block; padding: 10px 20px; background: white; border-radius: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
            &lt;label style=&quot;font-size: 18px; font-weight: bold;&quot;&gt;λ = &lt;span id=&quot;lambdaValue&quot; style=&quot;color: #007bff;&quot;&gt;0.0&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
            &lt;input type=&quot;range&quot; id=&quot;lambdaSlider&quot; min=&quot;0&quot; max=&quot;4&quot; step=&quot;0.05&quot; value=&quot;0&quot; style=&quot;width: 400px; margin-top: 10px;&quot; /&gt;
            &lt;div style=&quot;margin-top: 10px; font-size: 14px; color: #666;&quot;&gt;
                &lt;span&gt;Drag the slider to change the Lagrange multiplier&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div id=&quot;lagrangianInfo&quot; style=&quot;text-align: center; margin-top: 15px; padding: 10px; background: white; border-radius: 5px;&quot;&gt;
        &lt;p&gt;&lt;strong&gt;Dual value:&lt;/strong&gt; &lt;span id=&quot;dualValue&quot;&gt;g(0) = 0&lt;/span&gt;&lt;/p&gt;
        &lt;p&gt;&lt;span id=&quot;lowerBoundInfo&quot;&gt;Lower bound of the problem&lt;/span&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    // Wait for DOM to be ready
    if (document.readyState === &apos;loading&apos;) {
        document.addEventListener(&apos;DOMContentLoaded&apos;, initLagrangianViz);
    } else {
        initLagrangianViz();
    }
    
    function initLagrangianViz() {
    const canvas = document.getElementById(&apos;lagrangianCanvas&apos;);
        if (!canvas) return;
        
    const ctx = canvas.getContext(&apos;2d&apos;);
    const slider = document.getElementById(&apos;lambdaSlider&apos;);
    const valueSpan = document.getElementById(&apos;lambdaValue&apos;);
        const dualValueSpan = document.getElementById(&apos;dualValue&apos;);
        const lowerBoundInfo = document.getElementById(&apos;lowerBoundInfo&apos;);
        
        // Animation state
        let animationFrame = null;
        
        function drawGrid(centerX, centerY, scale) {
            ctx.strokeStyle = &apos;#e9ecef&apos;;
            ctx.lineWidth = 1;
            ctx.setLineDash([2, 2]);
            
            // Vertical grid lines
            for (let x = -8; x &lt;= 8; x++) {
                if (x === 0) continue;
                const screenX = centerX + x * scale;
                ctx.beginPath();
                ctx.moveTo(screenX, 0);
                ctx.lineTo(screenX, canvas.height);
                ctx.stroke();
            }
            
            // Horizontal grid lines
            for (let y = -4; y &lt;= 4; y++) {
                if (y === 0) continue;
                const screenY = centerY - y * scale;
                ctx.beginPath();
                ctx.moveTo(0, screenY);
                ctx.lineTo(canvas.width, screenY);
                ctx.stroke();
            }
            
            ctx.setLineDash([]);
        }
        
        function drawAxes(centerX, centerY, scale) {
            // Draw axes
            ctx.strokeStyle = &apos;#495057&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.moveTo(0, centerY);
            ctx.lineTo(canvas.width, centerY);
            ctx.moveTo(centerX, 0);
            ctx.lineTo(centerX, canvas.height);
            ctx.stroke();
            
            // Draw axis labels
            ctx.fillStyle = &apos;#495057&apos;;
            ctx.font = &apos;bold 14px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            
            // X-axis labels
            for (let x = -8; x &lt;= 8; x += 2) {
                if (x === 0) continue;
                const screenX = centerX + x * scale;
                ctx.fillText(x.toString(), screenX, centerY + 20);
            }
            
            // Y-axis labels
            ctx.textAlign = &apos;right&apos;;
            for (let y = -4; y &lt;= 4; y += 2) {
                if (y === 0) continue;
                const screenY = centerY - y * scale;
                ctx.fillText(y.toString(), centerX - 10, screenY + 5);
            }
            
            // Axis names
            ctx.font = &apos;bold 16px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;x&apos;, canvas.width - 20, centerY - 10);
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(&apos;y&apos;, centerX + 10, 20);
        }
    
    function drawVisualization() {
        const lambda = parseFloat(slider.value);
            valueSpan.textContent = lambda.toFixed(2);
        
        // Clear canvas
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Set up coordinate system
        const centerX = canvas.width / 2;
            const centerY = canvas.height * 0.6;
        const scale = 50;
            
            // Draw grid
            drawGrid(centerX, centerY, scale);
        
        // Draw axes
            drawAxes(centerX, centerY, scale);
        
        // Draw original function f(x) = x^2
            ctx.strokeStyle = &apos;#212529&apos;;
            ctx.lineWidth = 3;
        ctx.beginPath();
        let first = true;
            for (let x = -8; x &lt;= 8; x += 0.05) {
                const y = x * x;
            const screenX = centerX + x * scale;
                const screenY = centerY - y * scale / 4;
                if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height &amp;&amp; screenX &gt;= 0 &amp;&amp; screenX &lt;= canvas.width) {
                if (first) {
                    ctx.moveTo(screenX, screenY);
                    first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
        
        // Draw Lagrangian L(x,λ) = x^2 + λ(x-1)
            if (lambda &gt; 0.01) {
                ctx.strokeStyle = &apos;#007bff&apos;;
                ctx.lineWidth = 3;
            ctx.beginPath();
            first = true;
                for (let x = -8; x &lt;= 8; x += 0.05) {
                const lagrangian = x * x + lambda * (x - 1);
                const screenX = centerX + x * scale;
                const screenY = centerY - lagrangian * scale / 4;
                    if (screenY &gt;= -50 &amp;&amp; screenY &lt;= canvas.height + 50 &amp;&amp; screenX &gt;= 0 &amp;&amp; screenX &lt;= canvas.width) {
                    if (first) {
                        ctx.moveTo(screenX, screenY);
                        first = false;
                    } else {
                        ctx.lineTo(screenX, screenY);
                    }
                }
            }
            ctx.stroke();
            
                // Calculate minimum point
            const minX = -lambda / 2;
            const minY = -lambda * lambda / 4 - lambda;
            const screenMinX = centerX + minX * scale;
            const screenMinY = centerY - minY * scale / 4;
            
                // Draw vertical line from minimum to x-axis
            if (screenMinY &gt;= 0 &amp;&amp; screenMinY &lt;= canvas.height) {
                    ctx.strokeStyle = &apos;#007bff&apos;;
                    ctx.lineWidth = 1;
                    ctx.setLineDash([3, 3]);
                ctx.beginPath();
                    ctx.moveTo(screenMinX, screenMinY);
                    ctx.lineTo(screenMinX, centerY);
                    ctx.stroke();
                    ctx.setLineDash([]);
                    
                    // Mark minimum point with glow effect
                    ctx.shadowBlur = 10;
                    ctx.shadowColor = &apos;#007bff&apos;;
                    ctx.fillStyle = &apos;#007bff&apos;;
                    ctx.beginPath();
                    ctx.arc(screenMinX, screenMinY, 7, 0, 2 * Math.PI);
                ctx.fill();
                    ctx.shadowBlur = 0;
                    
                    // Add label for minimum
                    ctx.fillStyle = &apos;#007bff&apos;;
                    ctx.font = &apos;bold 13px Arial&apos;;
                    ctx.textAlign = &apos;center&apos;;
                    ctx.fillText(`x* = ${minX.toFixed(2)}`, screenMinX, centerY + 35);
                    ctx.fillText(`g(λ) = ${minY.toFixed(2)}`, screenMinX, screenMinY - 15);
                }
                
                // Update dual value display
                dualValueSpan.textContent = `g(${lambda.toFixed(2)}) = ${minY.toFixed(3)}`;
                
                // Update lower bound info
                if (minY &lt;= 0) {
                    lowerBoundInfo.textContent = `✓ g(λ) = ${minY.toFixed(3)} ≤ p* = 0 (valid lower bound)`;
                    lowerBoundInfo.style.color = &apos;#28a745&apos;;
                } else {
                    lowerBoundInfo.textContent = `⚠ The lower bound is not tight`;
                    lowerBoundInfo.style.color = &apos;#ffc107&apos;;
                }
            } else {
                dualValueSpan.textContent = &apos;g(0) = 0&apos;;
                lowerBoundInfo.textContent = &apos;Drag the slider to see the Lagrangian function&apos;;
                lowerBoundInfo.style.color = &apos;#666&apos;;
        }
        
        // Draw constraint boundary x = 1
            ctx.strokeStyle = &apos;#dc3545&apos;;
            ctx.lineWidth = 3;
            ctx.setLineDash([8, 4]);
        ctx.beginPath();
        ctx.moveTo(centerX + scale, 0);
        ctx.lineTo(centerX + scale, canvas.height);
        ctx.stroke();
        ctx.setLineDash([]);
        
            // Mark optimal point (x=1, f(1)=1)
            const optX = 1;
            const optY = 1;
            const screenOptX = centerX + optX * scale;
            const screenOptY = centerY - optY * scale / 4;
            
            ctx.shadowBlur = 15;
            ctx.shadowColor = &apos;#dc3545&apos;;
            ctx.fillStyle = &apos;#dc3545&apos;;
        ctx.beginPath();
            ctx.arc(screenOptX, screenOptY, 8, 0, 2 * Math.PI);
        ctx.fill();
            ctx.shadowBlur = 0;
            
            // Draw legend box
            const legendX = 20;
            const legendY = 20;
            const legendWidth = 250;
            const legendHeight = 115;
            
            ctx.fillStyle = &apos;rgba(255, 255, 255, 0.95)&apos;;
            ctx.strokeStyle = &apos;#dee2e6&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.roundRect(legendX, legendY, legendWidth, legendHeight, 5);
            ctx.fill();
            ctx.stroke();
            
            // Legend content
            let yPos = legendY + 25;
            ctx.textAlign = &apos;left&apos;;
            
            // Original function
            ctx.strokeStyle = &apos;#212529&apos;;
            ctx.lineWidth = 3;
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 40, yPos);
            ctx.stroke();
            ctx.fillStyle = &apos;#212529&apos;;
        ctx.font = &apos;14px Arial&apos;;
            ctx.fillText(&apos;f(x) = x²&apos;, legendX + 50, yPos + 5);
            
            yPos += 25;
            
            // Lagrangian
            if (lambda &gt; 0.01) {
                ctx.strokeStyle = &apos;#007bff&apos;;
                ctx.lineWidth = 3;
                ctx.beginPath();
                ctx.moveTo(legendX + 10, yPos);
                ctx.lineTo(legendX + 40, yPos);
                ctx.stroke();
                ctx.fillStyle = &apos;#007bff&apos;;
                ctx.fillText(`L(x,λ) = x² + λ(x-1)`, legendX + 50, yPos + 5);
                yPos += 25;
            }
            
            // Constraint
            ctx.strokeStyle = &apos;#dc3545&apos;;
            ctx.lineWidth = 3;
            ctx.setLineDash([8, 4]);
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 40, yPos);
            ctx.stroke();
            ctx.setLineDash([]);
            ctx.fillStyle = &apos;#dc3545&apos;;
        ctx.fillText(&apos;Constraint: x ≤ 1&apos;, legendX + 50, yPos + 5);
            
            yPos += 25;
            
            // Optimal point
            ctx.fillStyle = &apos;#dc3545&apos;;
            ctx.beginPath();
            ctx.arc(legendX + 25, yPos, 6, 0, 2 * Math.PI);
            ctx.fill();
            ctx.fillStyle = &apos;#dc3545&apos;;
            ctx.fillText(&apos;Optimal solution: p* = 0&apos;, legendX + 50, yPos + 5);
        }
        
        // Debounce function for smoother performance
        let debounceTimer;
        function debouncedDraw() {
            clearTimeout(debounceTimer);
            debounceTimer = setTimeout(drawVisualization, 10);
        }
        
        slider.addEventListener(&apos;input&apos;, debouncedDraw);
    drawVisualization();
    }
})();
&lt;/script&gt;

&lt;p&gt;&lt;strong&gt;Figure 1:&lt;/strong&gt; &lt;em&gt;The Lagrangian function and the dual function. The black curve is the original problem; the blue and green curves are the original problem with perturbation. We can see that the values of \(\inf_{x \in \mathcal{D}} L(x, \lambda)\) (the saddle points on the blue and green curves) are always less than or equal to the optimal solution \(p^*\).&lt;/em&gt;&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;img src=&quot;/img/chapter_img/chapter11/lagrangian_function_example.svg&quot; alt=&quot;Lagrangian Function Example&quot; style=&quot;max-width: 100%; height: auto;&quot; /&gt;
    &lt;p&gt;&lt;em&gt;Source: &lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Zhiliang Zhou&apos;s Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;-why-solve-the-dual-problem&quot;&gt;🎯 Why Solve the Dual Problem?&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; Why do we choose to solve the dual problem to estimate the lower bound? Is it easier?&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt; &lt;strong&gt;YES&lt;/strong&gt;. It is easier to solve.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In fact, the dual function \(g(\lambda)\) is &lt;strong&gt;concave&lt;/strong&gt;; in other words, \(-g(\lambda)\) is &lt;strong&gt;convex&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;From equation (3), we know that \(-g(\lambda)\) is a pointwise supremum of a set of functions that are affine in \(\lambda\), which means \(-g(\lambda)\) is convex.&lt;/p&gt;

&lt;div id=&quot;dual-function-visualization&quot; style=&quot;margin: 20px 0; padding: 20px; background: #f8f9fa; border-radius: 10px;&quot;&gt;
    &lt;canvas id=&quot;dualCanvas&quot; width=&quot;800&quot; height=&quot;450&quot; style=&quot;border: 2px solid #dee2e6; display: block; margin: 0 auto; background: white; border-radius: 5px;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin-top: 15px;&quot;&gt;
        &lt;button id=&quot;animateSupremum&quot; style=&quot;padding: 10px 25px; font-size: 16px; background: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.2);&quot;&gt;
            ▶ Run Animation
        &lt;/button&gt;
        &lt;button id=&quot;resetSupremum&quot; style=&quot;padding: 10px 25px; font-size: 16px; background: #6c757d; color: white; border: none; border-radius: 5px; cursor: pointer; margin-left: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.2);&quot;&gt;
            🔄 Reset
        &lt;/button&gt;
    &lt;/div&gt;
    &lt;div style=&quot;margin-top: 15px; padding: 15px; background: white; border-radius: 5px; border-left: 4px solid #007bff;&quot;&gt;
        &lt;p style=&quot;margin: 0; font-size: 14px; color: #666;&quot;&gt;
            &lt;strong&gt;Explanation:&lt;/strong&gt; The dual function -g(λ) is the pointwise supremum of a set of affine functions, 
            and is therefore a convex function. This means the dual problem is always convex, whether or not the original problem is convex.
        &lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    if (document.readyState === &apos;loading&apos;) {
        document.addEventListener(&apos;DOMContentLoaded&apos;, initDualViz);
    } else {
        initDualViz();
    }
    
    function initDualViz() {
    const canvas = document.getElementById(&apos;dualCanvas&apos;);
        if (!canvas) return;
        
    const ctx = canvas.getContext(&apos;2d&apos;);
        const animateBtn = document.getElementById(&apos;animateSupremum&apos;);
        const resetBtn = document.getElementById(&apos;resetSupremum&apos;);
        
        let animationProgress = 0;
        let isAnimating = false;
        let animationId = null;
        
        const affineFunctions = [
            { a: -2, b: 3.5, color: &apos;#ff6b6b&apos;, label: &apos;f₁&apos; },
            { a: -1, b: 3, color: &apos;#4ecdc4&apos;, label: &apos;f₂&apos; },
            { a: 0, b: 2.5, color: &apos;#45b7d1&apos;, label: &apos;f₃&apos; },
            { a: 1, b: 2, color: &apos;#96ceb4&apos;, label: &apos;f₄&apos; },
            { a: 2, b: 1.5, color: &apos;#ffeaa7&apos;, label: &apos;f₅&apos; }
        ];
        
        function drawDualVisualization(progress = 1) {
        // Clear canvas
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Set up coordinate system
            const margin = 80;
            const centerX = margin;
            const centerY = canvas.height - margin;
            const scaleX = (canvas.width - margin - 40) / 5;
            const scaleY = 60;
            
            // Draw grid
            ctx.strokeStyle = &apos;#e9ecef&apos;;
        ctx.lineWidth = 1;
            ctx.setLineDash([2, 2]);
            for (let i = 0; i &lt;= 5; i++) {
                const x = centerX + i * scaleX;
                ctx.beginPath();
                ctx.moveTo(x, 0);
                ctx.lineTo(x, centerY);
                ctx.stroke();
            }
            for (let i = -2; i &lt;= 4; i++) {
                const y = centerY - i * scaleY;
                ctx.beginPath();
                ctx.moveTo(centerX, y);
                ctx.lineTo(canvas.width - 20, y);
                ctx.stroke();
            }
            ctx.setLineDash([]);
            
            // Draw axes
            ctx.strokeStyle = &apos;#495057&apos;;
            ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.moveTo(centerX, 0);
            ctx.lineTo(centerX, centerY);
            ctx.moveTo(centerX, centerY);
            ctx.lineTo(canvas.width - 20, centerY);
        ctx.stroke();
        
            // Draw axis labels
            ctx.fillStyle = &apos;#495057&apos;;
            ctx.font = &apos;bold 14px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            
            // X-axis labels
            for (let i = 0; i &lt;= 5; i++) {
                const x = centerX + i * scaleX;
                ctx.fillText(i.toString(), x, centerY + 25);
            }
            
            // Y-axis labels
            ctx.textAlign = &apos;right&apos;;
            for (let i = -2; i &lt;= 4; i++) {
                const y = centerY - i * scaleY;
                ctx.fillText(i.toString(), centerX - 10, y + 5);
            }
            
            // Axis names
            ctx.fillStyle = &apos;#212529&apos;;
            ctx.font = &apos;bold 18px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;λ&apos;, canvas.width - 10, centerY + 25);
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(&apos;-g(λ)&apos;, centerX - 50, 20);
            
            // Draw affine functions with animation
            const numFunctionsToShow = Math.ceil(progress * affineFunctions.length);
            
            for (let i = 0; i &lt; numFunctionsToShow; i++) {
                const func = affineFunctions[i];
                const alpha = (i &lt; numFunctionsToShow - 1) ? 1 : (progress * affineFunctions.length - i);
                
                ctx.strokeStyle = func.color;
                ctx.globalAlpha = alpha;
                ctx.lineWidth = 2;
            ctx.beginPath();
            
                let first = true;
                for (let lambda = 0; lambda &lt;= 5; lambda += 0.05) {
                    const y = func.a * lambda + func.b;
                const screenX = centerX + lambda * scaleX;
                const screenY = centerY - y * scaleY;
                
                    if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height) {
                        if (first) {
                    ctx.moveTo(screenX, screenY);
                            first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                        }
                }
            }
            ctx.stroke();
                
                // Draw function label
                const labelX = centerX + 4.5 * scaleX;
                const labelY = centerY - (func.a * 4.5 + func.b) * scaleY;
                if (labelY &gt;= 0 &amp;&amp; labelY &lt;= canvas.height) {
                    ctx.fillStyle = func.color;
                    ctx.font = &apos;bold 14px Arial&apos;;
                    ctx.textAlign = &apos;left&apos;;
                    ctx.fillText(func.label, labelX + 10, labelY + 5);
                }
            }
            
            ctx.globalAlpha = 1;
            
            // Draw pointwise supremum (envelope) if animation is complete
            if (progress &gt;= 0.9) {
                const envelopeAlpha = (progress - 0.9) / 0.1;
                ctx.globalAlpha = envelopeAlpha;
                
                ctx.strokeStyle = &apos;#dc3545&apos;;
                ctx.lineWidth = 4;
                ctx.shadowBlur = 10;
                ctx.shadowColor = &apos;#dc3545&apos;;
        ctx.beginPath();
        
                let first = true;
                const supremumPoints = [];
                
                for (let lambda = 0; lambda &lt;= 5; lambda += 0.02) {
            let maxY = -Infinity;
                    for (const func of affineFunctions) {
                        const y = func.a * lambda + func.b;
                maxY = Math.max(maxY, y);
            }
                    
                    supremumPoints.push({ lambda, y: maxY });
            
            const screenX = centerX + lambda * scaleX;
            const screenY = centerY - maxY * scaleY;
            
                    if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height) {
                        if (first) {
                ctx.moveTo(screenX, screenY);
                            first = false;
            } else {
                ctx.lineTo(screenX, screenY);
                        }
            }
        }
        ctx.stroke();
                ctx.shadowBlur = 0;
                
                // Highlight some key points on the envelope
                if (envelopeAlpha &gt; 0.5) {
                    const keyLambdas = [0.5, 1.5, 2.5, 3.5, 4.5];
                    for (const lambda of keyLambdas) {
                        let maxY = -Infinity;
                        for (const func of affineFunctions) {
                            const y = func.a * lambda + func.b;
                            maxY = Math.max(maxY, y);
                        }
                        
                        const screenX = centerX + lambda * scaleX;
                        const screenY = centerY - maxY * scaleY;
                        
                        if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height) {
                            ctx.fillStyle = &apos;#dc3545&apos;;
                            ctx.beginPath();
                            ctx.arc(screenX, screenY, 5, 0, 2 * Math.PI);
                            ctx.fill();
                        }
                    }
                }
                
                ctx.globalAlpha = 1;
                
                // Add annotation
                ctx.fillStyle = &apos;#dc3545&apos;;
                ctx.font = &apos;bold 16px Arial&apos;;
                ctx.textAlign = &apos;left&apos;;
        ctx.fillText(&apos;Pointwise supremum&apos;, 200, 30);
        ctx.font = &apos;14px Arial&apos;;
        ctx.fillText(&apos;(Convex envelope)&apos;, 200, 50);
            }
            
            // Draw legend
            const legendX = canvas.width - 180;
            const legendY = 80;
            const legendWidth = 160;
            const legendHeight = 80;
            
            ctx.fillStyle = &apos;rgba(255, 255, 255, 0.95)&apos;;
            ctx.strokeStyle = &apos;#dee2e6&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.roundRect(legendX, legendY, legendWidth, legendHeight, 5);
            ctx.fill();
            ctx.stroke();
            
            // Legend title
            ctx.fillStyle = &apos;#212529&apos;;
            ctx.font = &apos;bold 14px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
        ctx.fillText(&apos;Affine functions&apos;, legendX + legendWidth/2, legendY + 20);
            
            // Legend items
            ctx.font = &apos;12px Arial&apos;;
            ctx.textAlign = &apos;left&apos;;
            for (let i = 0; i &lt; Math.min(3, numFunctionsToShow); i++) {
                const func = affineFunctions[i];
                const yPos = legendY + 40 + i * 15;
                
                ctx.strokeStyle = func.color;
                ctx.lineWidth = 2;
                ctx.beginPath();
                ctx.moveTo(legendX + 10, yPos);
                ctx.lineTo(legendX + 30, yPos);
                ctx.stroke();
                
                ctx.fillStyle = &apos;#495057&apos;;
                ctx.fillText(`${func.a}λ + ${func.b}`, legendX + 35, yPos + 4);
            }
        }
        
        function animate() {
            if (!isAnimating) return;
            
            animationProgress += 0.008;
            if (animationProgress &gt;= 1) {
                animationProgress = 1;
                isAnimating = false;
                animateBtn.innerHTML = &apos;▶ Run Again&apos;;
                animateBtn.style.background = &apos;#28a745&apos;;
            }
            
            drawDualVisualization(animationProgress);
            
            if (isAnimating) {
                animationId = requestAnimationFrame(animate);
            }
        }
        
        animateBtn.addEventListener(&apos;click&apos;, function() {
            if (animationProgress &gt;= 1) {
                animationProgress = 0;
            }
            
            if (isAnimating) {
                isAnimating = false;
                if (animationId) cancelAnimationFrame(animationId);
                animateBtn.innerHTML = &apos;▶ Resume&apos;;
                animateBtn.style.background = &apos;#007bff&apos;;
            } else {
                isAnimating = true;
                animateBtn.innerHTML = &apos;⏸ Pause&apos;;
                animateBtn.style.background = &apos;#ffc107&apos;;
                animate();
            }
        });
        
        resetBtn.addEventListener(&apos;click&apos;, function() {
            isAnimating = false;
            if (animationId) cancelAnimationFrame(animationId);
            animationProgress = 0;
                animateBtn.innerHTML = &apos;▶ Run Animation&apos;;
            animateBtn.style.background = &apos;#007bff&apos;;
            drawDualVisualization(0);
        });
        
        // Initial draw
        drawDualVisualization(1);
    }
})();
&lt;/script&gt;

&lt;p&gt;&lt;strong&gt;Figure 2:&lt;/strong&gt; &lt;em&gt;The pointwise supremum of a set of affine functions is a convex function&lt;/em&gt;&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;img src=&quot;/img/chapter_img/chapter11/pointwise_supremum_convex.svg&quot; alt=&quot;Pointwise Supremum of Affine Functions&quot; style=&quot;max-width: 100%; height: auto;&quot; /&gt;
    &lt;p&gt;&lt;em&gt;Source: &lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Zhiliang Zhou&apos;s Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Figure 2 shows a set of affine functions, with the red line representing the pointwise supremum. Clearly, in this figure the red line is a convex function. We know that for convex functions and convex sets, finding the global extremum is easy. Whether or not \(f(x)\) is convex, its dual function is always concave, which is a convenient property.&lt;/p&gt;

&lt;h2 id=&quot;-connection-with-the-conjugate-function&quot;&gt;🔗 Connection with the Conjugate Function&lt;/h2&gt;

&lt;p&gt;When the constraints in equation (1) are linear, the dual function often looks like the conjugate function.&lt;/p&gt;

&lt;h3 id=&quot;-the-conjugate-function&quot;&gt;📐 The Conjugate Function&lt;/h3&gt;

&lt;p&gt;The conjugate function of \(f(x)\) is defined as:&lt;/p&gt;

\[f^*(λ) = \sup_x (λ^T x - f(x))\]

&lt;div id=&quot;conjugate-visualization&quot; style=&quot;margin: 20px 0; padding: 20px; background: #f8f9fa; border-radius: 10px;&quot;&gt;
    &lt;canvas id=&quot;conjugateCanvas&quot; width=&quot;900&quot; height=&quot;550&quot; style=&quot;border: 2px solid #dee2e6; display: block; margin: 0 auto; background: white; border-radius: 5px;&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin: 15px 0;&quot;&gt;
        &lt;div style=&quot;display: inline-block; padding: 10px 20px; background: white; border-radius: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
            &lt;label&gt;Slope λ = &lt;span id=&quot;slopeValue&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
            &lt;input type=&quot;range&quot; id=&quot;slopeSlider&quot; min=&quot;-4&quot; max=&quot;4&quot; step=&quot;0.05&quot; value=&quot;1&quot; style=&quot;width: 400px; margin-top: 10px;&quot; /&gt;
            &lt;div style=&quot;margin-top: 10px; font-size: 14px; color: #666;&quot;&gt;
                &lt;span&gt;Change the slope of the line λx&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div id=&quot;conjugateInfo&quot; style=&quot;text-align: center; margin-top: 15px; padding: 15px; background: white; border-radius: 5px; border-left: 4px solid #6f42c1;&quot;&gt;
        &lt;p&gt;&lt;strong&gt;Conjugate function:&lt;/strong&gt; &lt;span id=&quot;conjugateValue&quot;&gt;f*(1.0) = 0.50&lt;/span&gt;&lt;/p&gt;
        &lt;p&gt;&lt;span id=&quot;conjugateExplanation&quot;&gt;The largest distance between λx and f(x)&lt;/span&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    if (document.readyState === &apos;loading&apos;) {
        document.addEventListener(&apos;DOMContentLoaded&apos;, initConjugateViz);
    } else {
        initConjugateViz();
    }
    
    function initConjugateViz() {
    const canvas = document.getElementById(&apos;conjugateCanvas&apos;);
        if (!canvas) return;
        
    const ctx = canvas.getContext(&apos;2d&apos;);
    const slider = document.getElementById(&apos;slopeSlider&apos;);
    const valueSpan = document.getElementById(&apos;slopeValue&apos;);
        const conjugateValueSpan = document.getElementById(&apos;conjugateValue&apos;);
        const explanationSpan = document.getElementById(&apos;conjugateExplanation&apos;);
        
        function drawGrid(centerX, centerY, scale) {
            ctx.strokeStyle = &apos;#f1f3f5&apos;;
            ctx.lineWidth = 1;
            ctx.setLineDash([2, 2]);
            
            // Vertical grid
            for (let x = -10; x &lt;= 10; x++) {
                if (x === 0) continue;
                const screenX = centerX + x * scale;
                if (screenX &gt;= 0 &amp;&amp; screenX &lt;= canvas.width) {
                    ctx.beginPath();
                    ctx.moveTo(screenX, 0);
                    ctx.lineTo(screenX, canvas.height);
                    ctx.stroke();
                }
            }
            
            // Horizontal grid
            for (let y = -5; y &lt;= 15; y++) {
                if (y === 0) continue;
                const screenY = centerY - y * scale;
                if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height) {
                    ctx.beginPath();
                    ctx.moveTo(0, screenY);
                    ctx.lineTo(canvas.width, screenY);
                    ctx.stroke();
                }
            }
            
            ctx.setLineDash([]);
        }
        
        function drawAxes(centerX, centerY, scale) {
            // Axes
            ctx.strokeStyle = &apos;#495057&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.moveTo(0, centerY);
            ctx.lineTo(canvas.width, centerY);
            ctx.moveTo(centerX, 0);
            ctx.lineTo(centerX, canvas.height);
            ctx.stroke();
            
            // Axis labels
            ctx.fillStyle = &apos;#495057&apos;;
            ctx.font = &apos;bold 13px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            
            // X-axis
            for (let x = -10; x &lt;= 10; x += 2) {
                if (x === 0) continue;
                const screenX = centerX + x * scale;
                if (screenX &gt;= 0 &amp;&amp; screenX &lt;= canvas.width) {
                    ctx.fillText(x.toString(), screenX, centerY + 20);
                }
            }
            
            // Y-axis
            ctx.textAlign = &apos;right&apos;;
            for (let y = -4; y &lt;= 14; y += 2) {
                if (y === 0) continue;
                const screenY = centerY - y * scale;
                if (screenY &gt;= 0 &amp;&amp; screenY &lt;= canvas.height) {
                    ctx.fillText(y.toString(), centerX - 10, screenY + 5);
                }
            }
            
            // Axis names
            ctx.font = &apos;bold 16px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;x&apos;, canvas.width - 20, centerY - 10);
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(&apos;y&apos;, centerX + 10, 20);
        }
    
    function drawConjugateVisualization() {
        const slope = parseFloat(slider.value);
            valueSpan.textContent = slope.toFixed(2);
        
        // Clear canvas
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Set up coordinate system
        const centerX = canvas.width / 2;
            const centerY = canvas.height * 0.75;
            const scale = 35;
            
            // Draw grid
            drawGrid(centerX, centerY, scale);
        
        // Draw axes
            drawAxes(centerX, centerY, scale);
        
        // Draw function f(x) = x^2/2
            ctx.strokeStyle = &apos;#20c997&apos;;
            ctx.lineWidth = 4;
            ctx.shadowBlur = 5;
            ctx.shadowColor = &apos;#20c997&apos;;
        ctx.beginPath();
        let first = true;
            for (let x = -10; x &lt;= 10; x += 0.05) {
            const y = x * x / 2;
            const screenX = centerX + x * scale;
            const screenY = centerY - y * scale;
                if (screenY &gt;= -10 &amp;&amp; screenY &lt;= canvas.height &amp;&amp; screenX &gt;= 0 &amp;&amp; screenX &lt;= canvas.width) {
                if (first) {
                    ctx.moveTo(screenX, screenY);
                    first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
            ctx.shadowBlur = 0;
        
        // Draw line λx with given slope
            ctx.strokeStyle = &apos;#6f42c1&apos;;
            ctx.lineWidth = 3;
        ctx.beginPath();
            first = true;
            for (let x = -10; x &lt;= 10; x += 0.1) {
            const y = slope * x;
            const screenX = centerX + x * scale;
            const screenY = centerY - y * scale;
                if (screenY &gt;= -10 &amp;&amp; screenY &lt;= canvas.height + 10 &amp;&amp; screenX &gt;= -10 &amp;&amp; screenX &lt;= canvas.width + 10) {
                    if (first) {
                    ctx.moveTo(screenX, screenY);
                        first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
        
        // Find and mark the point where λx - f(x) is maximized
        let maxDiff = -Infinity;
        let maxX = 0;
            for (let x = -10; x &lt;= 10; x += 0.01) {
            const diff = slope * x - x * x / 2;
            if (diff &gt; maxDiff) {
                maxDiff = diff;
                maxX = x;
            }
        }
        
            const conjugateValue = slope * slope / 2;
            
            // Draw tangent line at optimal point (parallel to λx)
            ctx.strokeStyle = &apos;#fd7e14&apos;;
            ctx.lineWidth = 3;
            ctx.setLineDash([8, 4]);
            ctx.shadowBlur = 5;
            ctx.shadowColor = &apos;#fd7e14&apos;;
            ctx.beginPath();
            first = true;
            for (let x = -10; x &lt;= 10; x += 0.1) {
                const y = slope * x - conjugateValue;
            const screenX = centerX + x * scale;
            const screenY = centerY - y * scale;
                if (screenY &gt;= -10 &amp;&amp; screenY &lt;= canvas.height + 10 &amp;&amp; screenX &gt;= -10 &amp;&amp; screenX &lt;= canvas.width + 10) {
                    if (first) {
                    ctx.moveTo(screenX, screenY);
                        first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
        ctx.setLineDash([]);
            ctx.shadowBlur = 0;
            
            // Mark tangent point on f(x)
            const tangentY = maxX * maxX / 2;
            const tangentScreenX = centerX + maxX * scale;
            const tangentScreenY = centerY - tangentY * scale;
            
            if (tangentScreenY &gt;= 0 &amp;&amp; tangentScreenY &lt;= canvas.height) {
                // Draw vertical line to show the contact point
                ctx.strokeStyle = &apos;#e63946&apos;;
                ctx.lineWidth = 2;
                ctx.setLineDash([3, 3]);
        ctx.beginPath();
                ctx.moveTo(tangentScreenX, tangentScreenY);
                ctx.lineTo(tangentScreenX, centerY);
                ctx.stroke();
                ctx.setLineDash([]);
                
                // Mark point with glow
                ctx.shadowBlur = 15;
                ctx.shadowColor = &apos;#e63946&apos;;
                ctx.fillStyle = &apos;#e63946&apos;;
                ctx.beginPath();
                ctx.arc(tangentScreenX, tangentScreenY, 8, 0, 2 * Math.PI);
        ctx.fill();
                ctx.shadowBlur = 0;
                
                // Label the contact point
                ctx.fillStyle = &apos;#e63946&apos;;
                ctx.font = &apos;bold 14px Arial&apos;;
                ctx.textAlign = &apos;center&apos;;
                ctx.fillText(`x* = ${maxX.toFixed(2)}`, tangentScreenX, centerY + 35);
            }
            
            // Draw vertical distance visualization (f*(λ))
            if (Math.abs(maxX) &lt;= 10 &amp;&amp; tangentScreenY &gt;= 0) {
                const lineY = slope * maxX;
                const lineScreenY = centerY - lineY * scale;
                
                if (lineScreenY &gt;= 0 &amp;&amp; lineScreenY &lt;= canvas.height) {
                    // Draw vertical arrow showing the distance
                    ctx.strokeStyle = &apos;#6f42c1&apos;;
                    ctx.fillStyle = &apos;#6f42c1&apos;;
                    ctx.lineWidth = 3;
                    
                    // Draw arrow
                    const arrowX = tangentScreenX + 50;
                    ctx.beginPath();
                    ctx.moveTo(arrowX, tangentScreenY);
                    ctx.lineTo(arrowX, lineScreenY);
                    ctx.stroke();
                    
                    // Arrowheads
                    ctx.beginPath();
                    ctx.moveTo(arrowX - 5, tangentScreenY + 10);
                    ctx.lineTo(arrowX, tangentScreenY);
                    ctx.lineTo(arrowX + 5, tangentScreenY + 10);
                    ctx.fill();
                    
                    ctx.beginPath();
                    ctx.moveTo(arrowX - 5, lineScreenY - 10);
                    ctx.lineTo(arrowX, lineScreenY);
                    ctx.lineTo(arrowX + 5, lineScreenY - 10);
                    ctx.fill();
                    
                    // Label the distance
                    const midY = (tangentScreenY + lineScreenY) / 2;
                    ctx.font = &apos;bold 14px Arial&apos;;
                    ctx.textAlign = &apos;left&apos;;
                    ctx.fillText(`f*(λ) = ${conjugateValue.toFixed(2)}`, arrowX + 10, midY + 5);
                }
            }
            
            // Update info display
            conjugateValueSpan.textContent = `f*(${slope.toFixed(2)}) = ${conjugateValue.toFixed(3)}`;
                explanationSpan.textContent = `At x* = ${maxX.toFixed(2)}, the distance λx - f(x) reaches its maximum = ${conjugateValue.toFixed(3)}`;
            
            // Draw legend box
            const legendX = 20;
            const legendY = 20;
            const legendWidth = 280;
            const legendHeight = 135;
            
            ctx.fillStyle = &apos;rgba(255, 255, 255, 0.95)&apos;;
            ctx.strokeStyle = &apos;#dee2e6&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.roundRect(legendX, legendY, legendWidth, legendHeight, 5);
            ctx.fill();
            ctx.stroke();
            
            // Legend content
            let yPos = legendY + 25;
            ctx.textAlign = &apos;left&apos;;
            
            // f(x)
            ctx.strokeStyle = &apos;#20c997&apos;;
            ctx.lineWidth = 3;
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 45, yPos);
            ctx.stroke();
            ctx.fillStyle = &apos;#20c997&apos;;
            ctx.font = &apos;15px Arial&apos;;
            ctx.fillText(&apos;f(x) = x²/2&apos;, legendX + 55, yPos + 5);
            yPos += 28;
            
            // λx
            ctx.strokeStyle = &apos;#6f42c1&apos;;
            ctx.lineWidth = 3;
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 45, yPos);
            ctx.stroke();
            ctx.fillStyle = &apos;#6f42c1&apos;;
            ctx.fillText(`λx (λ = ${slope.toFixed(2)})`, legendX + 55, yPos + 5);
            yPos += 28;
            
            // Tangent
            ctx.strokeStyle = &apos;#fd7e14&apos;;
            ctx.lineWidth = 3;
            ctx.setLineDash([8, 4]);
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 45, yPos);
            ctx.stroke();
            ctx.setLineDash([]);
            ctx.fillStyle = &apos;#fd7e14&apos;;
        ctx.fillText(&apos;Tangent line&apos;, legendX + 55, yPos + 5);
            yPos += 28;
            
            // Contact point
            ctx.fillStyle = &apos;#e63946&apos;;
            ctx.beginPath();
            ctx.arc(legendX + 27, yPos - 3, 6, 0, 2 * Math.PI);
            ctx.fill();
            ctx.fillStyle = &apos;#e63946&apos;;
        ctx.fillText(&apos;Tangent point&apos;, legendX + 55, yPos + 2);
        }
        
        // Debounce for performance
        let debounceTimer;
        function debouncedDraw() {
            clearTimeout(debounceTimer);
            debounceTimer = setTimeout(drawConjugateVisualization, 5);
        }
        
        slider.addEventListener(&apos;input&apos;, debouncedDraw);
    drawConjugateVisualization();
    }
})();
&lt;/script&gt;

&lt;p&gt;&lt;strong&gt;Figure 3:&lt;/strong&gt; &lt;em&gt;The conjugate function. The green curve is \(f(x)\), the black line is \(λ^T x\), and the (signed) vectors between \(λ^T x\) and \(f(x)\) are \(λ^T x - f(x)\). So the conjugate function \(f^*(λ)\) is about the largest distance between the line \(λ^T x\) and \(f(x)\).&lt;/em&gt;&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;img src=&quot;/img/chapter_img/chapter11/conjugate_function_geometric.svg&quot; alt=&quot;Conjugate Function Geometric Interpretation&quot; style=&quot;max-width: 100%; height: auto;&quot; /&gt;
    &lt;p&gt;&lt;em&gt;Source: &lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Zhiliang Zhou&apos;s Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;-when-the-constraints-are-linear&quot;&gt;🔄 When the Constraints Are Linear&lt;/h3&gt;

&lt;p&gt;When the constraints are linear, the optimization problem has the form:&lt;/p&gt;

\[\min_x f(x) \quad \text{s.t. } Ax \preceq b\]

&lt;p&gt;The Lagrange dual function is:&lt;/p&gt;

\[\begin{align}
&amp;amp;g(λ) = \inf_x (f(x) + λ^T(Ax - b)) \quad \text{for } λ \succeq 0 \\
&amp;amp;= -\sup_x (-λ^T A x - f(x)) - λ^T b \\
&amp;amp;= -f^*(-A^T λ) - λ^T b \quad \text{by equation (9)}
\end{align}\]

&lt;p&gt;Intuitively, since \(-λ^T b\) is a linear term, the extreme values are affected only by the domain, so if we focus on the term \(-f^*(-A^T λ)\), solving \(\max_λ g(λ)\) means solving \(\min f^*(-A^T λ)\).&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;img src=&quot;/img/chapter_img/chapter11/conjugate_minimum_example.svg&quot; alt=&quot;Minimum of Conjugate Function&quot; style=&quot;max-width: 100%; height: auto;&quot; /&gt;
    &lt;p&gt;&lt;em&gt;Figure 4: The minimum of the conjugate function - Source: &lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Zhiliang Zhou&apos;s Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;-interactive-example&quot;&gt;💻 Interactive Example&lt;/h2&gt;

&lt;p&gt;Let us look at a concrete example with the problem:&lt;/p&gt;

\[\min x^2 \quad \text{s.t. } x \leq 1\]

&lt;div id=&quot;complete-example&quot; style=&quot;margin: 20px 0; padding: 25px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.3);&quot;&gt;
    &lt;h4&gt;🎬 Combined Illustration: The Primal-Dual Relationship&lt;/h4&gt;
    &lt;canvas id=&quot;completeCanvas&quot; width=&quot;1100&quot; height=&quot;600&quot; style=&quot;border: 3px solid white; display: block; margin: 0 auto; background: white; border-radius: 8px; box-shadow: 0 5px 15px rgba(0,0,0,0.3);&quot;&gt;&lt;/canvas&gt;
    &lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
        &lt;button id=&quot;animateBtn&quot; style=&quot;padding: 12px 30px; font-size: 17px; background: #28a745; color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: bold; box-shadow: 0 4px 6px rgba(0,0,0,0.2); transition: all 0.3s;&quot;&gt;
            ▶ Run Animation
        &lt;/button&gt;
        &lt;button id=&quot;resetBtn&quot; style=&quot;padding: 12px 30px; font-size: 17px; background: #6c757d; color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: bold; margin-left: 15px; box-shadow: 0 4px 6px rgba(0,0,0,0.2); transition: all 0.3s;&quot;&gt;
            🔄 Reset
        &lt;/button&gt;
        &lt;div style=&quot;margin-top: 15px; padding: 10px 20px; background: rgba(255,255,255,0.9); border-radius: 8px; display: inline-block;&quot;&gt;
            &lt;span style=&quot;font-size: 18px; font-weight: bold; color: #495057;&quot;&gt;λ = &lt;span id=&quot;currentLambdaDisplay&quot; style=&quot;color: #007bff;&quot;&gt;0.00&lt;/span&gt;&lt;/span&gt;
            &lt;span style=&quot;margin: 0 15px; color: #dee2e6;&quot;&gt;|&lt;/span&gt;
            &lt;span style=&quot;font-size: 18px; font-weight: bold; color: #495057;&quot;&gt;g(λ) = &lt;span id=&quot;currentDualDisplay&quot; style=&quot;color: #dc3545;&quot;&gt;0.000&lt;/span&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;div id=&quot;explanation&quot; style=&quot;margin-top: 20px; padding: 20px; background: rgba(255,255,255,0.95); border-radius: 10px; box-shadow: 0 3px 10px rgba(0,0,0,0.2);&quot;&gt;
        &lt;p&gt;📖 How to read the chart:&lt;/p&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 15px; font-size: 14px; line-height: 1.8;&quot;&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #212529;&quot;&gt;
                &lt;span&gt;● Bold black line:&lt;/span&gt; The objective function f(x) = x²
            &lt;/div&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #007bff;&quot;&gt;
                &lt;span&gt;● Blue line:&lt;/span&gt; The Lagrangian L(x,λ)
            &lt;/div&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #dc3545;&quot;&gt;
                &lt;span&gt;⊥ Dashed red line:&lt;/span&gt; The constraint x ≤ 1
            &lt;/div&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #ff0000;&quot;&gt;
                &lt;span&gt;◉ Large red point:&lt;/span&gt; The optimal solution p* = 0
            &lt;/div&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #007bff;&quot;&gt;
                &lt;span&gt;◉ Green point:&lt;/span&gt; Min of L(x,λ) → g(λ)
            &lt;/div&gt;
            &lt;div style=&quot;padding: 10px; background: #f8f9fa; border-radius: 5px; border-left: 4px solid #28a745;&quot;&gt;
                &lt;span&gt;📊 Right curve:&lt;/span&gt; The dual function g(λ)
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;margin-top: 15px; padding: 12px; background: #fff3cd; border-left: 4px solid #ffc107; border-radius: 5px;&quot;&gt;
            &lt;p style=&quot;margin: 0; color: #856404; font-size: 14px;&quot;&gt;
                &lt;strong&gt;💡 Key observation:&lt;/strong&gt; As λ increases from 0, the minimum point of the Lagrangian (green) moves to the left, 
                and the value of g(λ) decreases (a looser lower bound). The maximum of g(λ) over λ ≥ 0 (here at λ = 0) gives us the best lower bound!
            &lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
(function() {
    if (document.readyState === &apos;loading&apos;) {
        document.addEventListener(&apos;DOMContentLoaded&apos;, initCompleteViz);
    } else {
        initCompleteViz();
    }
    
    function initCompleteViz() {
    const canvas = document.getElementById(&apos;completeCanvas&apos;);
        if (!canvas) return;
        
    const ctx = canvas.getContext(&apos;2d&apos;);
    const animateBtn = document.getElementById(&apos;animateBtn&apos;);
    const resetBtn = document.getElementById(&apos;resetBtn&apos;);
        const lambdaDisplay = document.getElementById(&apos;currentLambdaDisplay&apos;);
        const dualDisplay = document.getElementById(&apos;currentDualDisplay&apos;);
    
    let animationId = null;
    let currentLambda = 0;
    let isAnimating = false;
    
    function drawCompleteExample(lambda) {
        // Clear canvas
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
            // Set up panels
            const leftPanel = { x: 60, y: 60, width: 500, height: 450 };
            const rightPanel = { x: 600, y: 60, width: 450, height: 450 };
            
            // Draw panel backgrounds
            ctx.fillStyle = &apos;#f8f9fa&apos;;
            ctx.fillRect(leftPanel.x - 10, leftPanel.y - 10, leftPanel.width + 20, leftPanel.height + 20);
            ctx.fillRect(rightPanel.x - 10, rightPanel.y - 10, rightPanel.width + 20, rightPanel.height + 20);
            
            // Draw panels
            drawPrimalSpace(leftPanel, lambda);
        drawDualSpace(rightPanel, lambda);
        
            // Add panel titles
            ctx.fillStyle = &apos;#212529&apos;;
            ctx.font = &apos;bold 20px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
        ctx.fillText(&apos;Primal Space&apos;, leftPanel.x + leftPanel.width/2, leftPanel.y - 25);
        ctx.fillText(&apos;Dual Space&apos;, rightPanel.x + rightPanel.width/2, rightPanel.y - 25);
            
            // Update displays
            lambdaDisplay.textContent = lambda.toFixed(2);
        const dualValue = -lambda * lambda / 4 - lambda;
            dualDisplay.textContent = dualValue.toFixed(3);
    }
    
    function drawPrimalSpace(panel, lambda) {
        const centerX = panel.x + panel.width / 2;
            const centerY = panel.y + panel.height - 70;
            const scale = 50;
        
            // Draw grid
            ctx.strokeStyle = &apos;#e9ecef&apos;;
        ctx.lineWidth = 1;
            ctx.setLineDash([2, 2]);
            for (let x = -4; x &lt;= 4; x++) {
                if (x === 0) continue;
                const screenX = centerX + x * scale;
                ctx.beginPath();
                ctx.moveTo(screenX, panel.y);
                ctx.lineTo(screenX, panel.y + panel.height);
                ctx.stroke();
            }
            for (let y = -2; y &lt;= 6; y++) {
                if (y === 0) continue;
                const screenY = centerY - y * scale / 2;
                ctx.beginPath();
                ctx.moveTo(panel.x, screenY);
                ctx.lineTo(panel.x + panel.width, screenY);
                ctx.stroke();
            }
            ctx.setLineDash([]);
            
            // Draw axes
            ctx.strokeStyle = &apos;#495057&apos;;
            ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.moveTo(panel.x, centerY);
        ctx.lineTo(panel.x + panel.width, centerY);
        ctx.moveTo(centerX, panel.y);
        ctx.lineTo(centerX, panel.y + panel.height);
        ctx.stroke();
            
            // Axis labels
            ctx.fillStyle = &apos;#495057&apos;;
            ctx.font = &apos;bold 13px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            for (let x = -4; x &lt;= 4; x += 2) {
                if (x === 0) continue;
                ctx.fillText(x.toString(), centerX + x * scale, centerY + 20);
            }
            ctx.font = &apos;bold 16px Arial&apos;;
            ctx.fillText(&apos;x&apos;, panel.x + panel.width - 15, centerY - 10);
            ctx.fillText(&apos;y&apos;, centerX + 15, panel.y + 20);
        
        // Draw original function f(x) = x^2
            ctx.strokeStyle = &apos;#212529&apos;;
            ctx.lineWidth = 4;
            ctx.shadowBlur = 5;
            ctx.shadowColor = &apos;#212529&apos;;
        ctx.beginPath();
        let first = true;
            for (let x = -4; x &lt;= 4; x += 0.05) {
            const y = x * x;
            const screenX = centerX + x * scale;
            const screenY = centerY - y * scale / 2;
            if (screenY &gt;= panel.y &amp;&amp; screenY &lt;= panel.y + panel.height) {
                if (first) {
                    ctx.moveTo(screenX, screenY);
                    first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
            ctx.shadowBlur = 0;
        
        // Draw Lagrangian if lambda &gt; 0
            if (lambda &gt; 0.01) {
                ctx.strokeStyle = &apos;#007bff&apos;;
                ctx.lineWidth = 3;
                ctx.shadowBlur = 5;
                ctx.shadowColor = &apos;#007bff&apos;;
            ctx.beginPath();
            first = true;
                for (let x = -4; x &lt;= 4; x += 0.05) {
                const lagrangian = x * x + lambda * (x - 1);
                const screenX = centerX + x * scale;
                const screenY = centerY - lagrangian * scale / 2;
                    if (screenY &gt;= panel.y - 20 &amp;&amp; screenY &lt;= panel.y + panel.height + 20) {
                    if (first) {
                        ctx.moveTo(screenX, screenY);
                        first = false;
                    } else {
                        ctx.lineTo(screenX, screenY);
                    }
                }
            }
            ctx.stroke();
                ctx.shadowBlur = 0;
            
            // Mark minimum of Lagrangian
            const minX = -lambda / 2;
            const minY = -lambda * lambda / 4 - lambda;
            const screenMinX = centerX + minX * scale;
            const screenMinY = centerY - minY * scale / 2;
            
            if (screenMinY &gt;= panel.y &amp;&amp; screenMinY &lt;= panel.y + panel.height) {
                    // Vertical line to axis
                    ctx.strokeStyle = &apos;#007bff&apos;;
                    ctx.lineWidth = 2;
                    ctx.setLineDash([3, 3]);
                ctx.beginPath();
                    ctx.moveTo(screenMinX, screenMinY);
                    ctx.lineTo(screenMinX, centerY);
                    ctx.stroke();
                    ctx.setLineDash([]);
                    
                    // Glow effect
                    ctx.shadowBlur = 15;
                    ctx.shadowColor = &apos;#007bff&apos;;
                    ctx.fillStyle = &apos;#007bff&apos;;
                    ctx.beginPath();
                    ctx.arc(screenMinX, screenMinY, 8, 0, 2 * Math.PI);
                ctx.fill();
                    ctx.shadowBlur = 0;
                    
                    // Label
                    ctx.fillStyle = &apos;#007bff&apos;;
                    ctx.font = &apos;bold 13px Arial&apos;;
                    ctx.textAlign = &apos;center&apos;;
                    ctx.fillText(`x*=${minX.toFixed(2)}`, screenMinX, screenMinY - 15);
                    ctx.fillText(`g(λ)=${minY.toFixed(2)}`, screenMinX, centerY + 35);
            }
        }
        
        // Draw constraint x = 1
            ctx.strokeStyle = &apos;#dc3545&apos;;
            ctx.lineWidth = 4;
            ctx.setLineDash([10, 5]);
            ctx.shadowBlur = 5;
            ctx.shadowColor = &apos;#dc3545&apos;;
        ctx.beginPath();
        ctx.moveTo(centerX + scale, panel.y);
        ctx.lineTo(centerX + scale, panel.y + panel.height);
        ctx.stroke();
        ctx.setLineDash([]);
            ctx.shadowBlur = 0;
            
            // Shade feasible region
            ctx.fillStyle = &apos;rgba(220, 53, 69, 0.1)&apos;;
            ctx.fillRect(panel.x, panel.y, centerX + scale - panel.x, panel.height);
        
        // Mark optimal point
            ctx.shadowBlur = 20;
            ctx.shadowColor = &apos;#ff0000&apos;;
        ctx.fillStyle = &apos;#ff0000&apos;;
        ctx.beginPath();
            ctx.arc(centerX, centerY, 10, 0, 2 * Math.PI);
        ctx.fill();
            ctx.shadowBlur = 0;
            
            // Label optimal
            ctx.fillStyle = &apos;#ff0000&apos;;
            ctx.font = &apos;bold 14px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;p* = 0&apos;, centerX, centerY - 20);
            
            // Legend
            const legendX = panel.x + 15;
            const legendY = panel.y + 15;
            ctx.fillStyle = &apos;rgba(255, 255, 255, 0.95)&apos;;
            ctx.strokeStyle = &apos;#dee2e6&apos;;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.roundRect(legendX, legendY, 160, 90, 5);
            ctx.fill();
            ctx.stroke();
            
            ctx.font = &apos;13px Arial&apos;;
            ctx.textAlign = &apos;left&apos;;
            let yPos = legendY + 20;
            
            ctx.strokeStyle = &apos;#212529&apos;;
            ctx.lineWidth = 3;
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 35, yPos);
            ctx.stroke();
            ctx.fillStyle = &apos;#212529&apos;;
            ctx.fillText(&apos;f(x) = x²&apos;, legendX + 45, yPos + 4);
            yPos += 22;
            
            if (lambda &gt; 0.01) {
                ctx.strokeStyle = &apos;#007bff&apos;;
                ctx.beginPath();
                ctx.moveTo(legendX + 10, yPos);
                ctx.lineTo(legendX + 35, yPos);
                ctx.stroke();
                ctx.fillStyle = &apos;#007bff&apos;;
                ctx.fillText(&apos;L(x,λ)&apos;, legendX + 45, yPos + 4);
                yPos += 22;
            }
            
            ctx.strokeStyle = &apos;#dc3545&apos;;
            ctx.setLineDash([8, 4]);
            ctx.beginPath();
            ctx.moveTo(legendX + 10, yPos);
            ctx.lineTo(legendX + 35, yPos);
            ctx.stroke();
            ctx.setLineDash([]);
            ctx.fillStyle = &apos;#dc3545&apos;;
            ctx.fillText(&apos;x ≤ 1&apos;, legendX + 45, yPos + 4);
    }
    
    function drawDualSpace(panel, currentLambda) {
            const margin = 50;
            const centerX = panel.x + margin;
            const centerY = panel.y + panel.height - 70;
            const scaleX = (panel.width - margin - 30) / 4;
            const scaleY = 60;
            
            // Draw grid
            ctx.strokeStyle = &apos;#e9ecef&apos;;
        ctx.lineWidth = 1;
            ctx.setLineDash([2, 2]);
            for (let i = 0; i &lt;= 4; i++) {
                const x = centerX + i * scaleX;
                ctx.beginPath();
                ctx.moveTo(x, panel.y);
                ctx.lineTo(x, centerY);
                ctx.stroke();
            }
            for (let i = -5; i &lt;= 1; i++) {
                const y = centerY + i * scaleY;
                ctx.beginPath();
                ctx.moveTo(centerX, y);
                ctx.lineTo(panel.x + panel.width - 20, y);
                ctx.stroke();
            }
            ctx.setLineDash([]);
            
            // Draw axes
            ctx.strokeStyle = &apos;#495057&apos;;
            ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.moveTo(centerX, panel.y);
            ctx.lineTo(centerX, centerY);
        ctx.moveTo(centerX, centerY);
            ctx.lineTo(panel.x + panel.width - 20, centerY);
        ctx.stroke();
            
            // Axis labels
            ctx.fillStyle = &apos;#495057&apos;;
            ctx.font = &apos;bold 13px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            for (let i = 0; i &lt;= 4; i++) {
                ctx.fillText(i.toString(), centerX + i * scaleX, centerY + 20);
            }
            ctx.textAlign = &apos;right&apos;;
            for (let i = -5; i &lt;= 0; i++) {
                ctx.fillText(i.toString(), centerX - 10, centerY + i * scaleY + 5);
            }
            
            ctx.font = &apos;bold 16px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(&apos;λ&apos;, panel.x + panel.width - 10, centerY + 20);
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(&apos;g(λ)&apos;, centerX - 40, panel.y + 20);
        
        // Draw dual function g(λ) = -λ²/4 - λ
            ctx.strokeStyle = &apos;#28a745&apos;;
            ctx.lineWidth = 4;
            ctx.shadowBlur = 5;
            ctx.shadowColor = &apos;#28a745&apos;;
        ctx.beginPath();
        let first = true;
            for (let lambda = 0; lambda &lt;= 4; lambda += 0.02) {
            const g = -lambda * lambda / 4 - lambda;
            const screenX = centerX + lambda * scaleX;
            const screenY = centerY - g * scaleY;
                if (screenY &gt;= panel.y &amp;&amp; screenY &lt;= centerY + 10) {
                if (first) {
                    ctx.moveTo(screenX, screenY);
                    first = false;
                } else {
                    ctx.lineTo(screenX, screenY);
                }
            }
        }
        ctx.stroke();
            ctx.shadowBlur = 0;
            
            // Mark current point with trail effect
            if (currentLambda &gt; 0) {
                // Draw trail
                ctx.strokeStyle = &apos;rgba(220, 53, 69, 0.3)&apos;;
                ctx.lineWidth = 2;
                ctx.setLineDash([5, 5]);
                ctx.beginPath();
                for (let lambda = 0; lambda &lt;= currentLambda; lambda += 0.05) {
                    const g = -lambda * lambda / 4 - lambda;
                    const screenX = centerX + lambda * scaleX;
                    const screenY = centerY - g * scaleY;
                    if (lambda === 0) {
                        ctx.moveTo(screenX, screenY);
                    } else {
                        ctx.lineTo(screenX, screenY);
                    }
                }
                ctx.stroke();
                ctx.setLineDash([]);
            }
        
        // Mark current point
        const currentG = -currentLambda * currentLambda / 4 - currentLambda;
        const currentScreenX = centerX + currentLambda * scaleX;
        const currentScreenY = centerY - currentG * scaleY;
        
            if (currentScreenY &gt;= panel.y &amp;&amp; currentScreenY &lt;= centerY) {
                // Vertical line
                ctx.strokeStyle = &apos;#dc3545&apos;;
                ctx.lineWidth = 2;
                ctx.setLineDash([3, 3]);
            ctx.beginPath();
                ctx.moveTo(currentScreenX, currentScreenY);
                ctx.lineTo(currentScreenX, centerY);
                ctx.stroke();
                ctx.setLineDash([]);
                
                // Glow point
                ctx.shadowBlur = 20;
                ctx.shadowColor = &apos;#dc3545&apos;;
                ctx.fillStyle = &apos;#dc3545&apos;;
                ctx.beginPath();
                ctx.arc(currentScreenX, currentScreenY, 10, 0, 2 * Math.PI);
            ctx.fill();
                ctx.shadowBlur = 0;
            }
            
            // Show p* = 0 reference line
            ctx.strokeStyle = &apos;#ff0000&apos;;
            ctx.lineWidth = 2;
            ctx.setLineDash([8, 4]);
            const pStarY = centerY - 0 * scaleY;
            ctx.beginPath();
            ctx.moveTo(centerX, pStarY);
            ctx.lineTo(panel.x + panel.width - 20, pStarY);
            ctx.stroke();
            ctx.setLineDash([]);
            
            ctx.fillStyle = &apos;#ff0000&apos;;
            ctx.font = &apos;bold 13px Arial&apos;;
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(&apos;p* = 0&apos;, panel.x + panel.width - 70, pStarY - 5);
    }
    
    function animate() {
        if (!isAnimating) return;
        
            currentLambda += 0.015;
        if (currentLambda &gt; 4) {
            currentLambda = 0;
        }
        
        drawCompleteExample(currentLambda);
        animationId = requestAnimationFrame(animate);
    }
    
    animateBtn.addEventListener(&apos;click&apos;, function() {
        if (isAnimating) {
            isAnimating = false;
                if (animationId) cancelAnimationFrame(animationId);
                animateBtn.innerHTML = &apos;▶ Resume&apos;;
                animateBtn.style.background = &apos;#007bff&apos;;
        } else {
            isAnimating = true;
                animateBtn.innerHTML = &apos;⏸ Pause&apos;;
                animateBtn.style.background = &apos;#ffc107&apos;;
            animate();
        }
    });
    
    resetBtn.addEventListener(&apos;click&apos;, function() {
        isAnimating = false;
            if (animationId) cancelAnimationFrame(animationId);
        currentLambda = 0;
                animateBtn.innerHTML = &apos;▶ Run Animation&apos;;
            animateBtn.style.background = &apos;#28a745&apos;;
        drawCompleteExample(currentLambda);
    });
    
    // Initial draw
    drawCompleteExample(currentLambda);
    }
})();
&lt;/script&gt;

&lt;h2 id=&quot;-conclusion&quot;&gt;🎓 Conclusion&lt;/h2&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;img src=&quot;/img/chapter_img/chapter11/lagrange_duality_framework.svg&quot; alt=&quot;Lagrange Duality Framework Overview&quot; style=&quot;max-width: 100%; height: auto;&quot; /&gt;
    &lt;p&gt;&lt;em&gt;Figure 5: Overview of the Lagrange Duality Framework - Source: &lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Zhiliang Zhou&apos;s Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Lagrange Duality provides a powerful approach to solving complex optimization problems by:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Turning constraints into perturbations:&lt;/strong&gt; The Lagrangian adds the constraints as penalty terms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Producing a lower bound:&lt;/strong&gt; The dual function always provides a lower bound for the original problem&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Guaranteeing convexity:&lt;/strong&gt; The dual problem is always convex, and easier to solve&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Connecting with geometry:&lt;/strong&gt; The conjugate function gives an intuitive geometric view&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-practical-significance&quot;&gt;🔍 Practical Significance&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algorithms:&lt;/strong&gt; Many modern optimization algorithms are based on duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity analysis:&lt;/strong&gt; Dual variables tell the “price” of changing a constraint&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimality checking:&lt;/strong&gt; The duality gap helps assess the quality of a solution&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm design:&lt;/strong&gt; Primal-dual methods combine both viewpoints&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lagrange Duality is not just an abstract mathematical tool, but a powerful framework that helps us understand the nature of optimization problems more deeply and design efficient algorithms to solve them.&lt;/p&gt;

&lt;h2 id=&quot;️-a-note-on-the-images&quot;&gt;🖼️ A Note on the Images&lt;/h2&gt;

&lt;p&gt;The images in this lesson are inspired by and refer to the original article by Zhiliang Zhou. The interactive visualizations were created with JavaScript to supplement and clarify the concepts presented in the original article.&lt;/p&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 References&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;“Convex Optimization” - Stephen Boyd &amp;amp; Lieven Vandenberghe&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://masszhou.github.io/2016/09/10/Lagrange-Duality/&quot;&gt;Intuition behind Lagrange Duality&lt;/a&gt; - Zhiliang Zhou’s Blog&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://masszhou.github.io/&quot;&gt;Zhiliang’s Blog and Notes&lt;/a&gt; - Another External Brain Drive&lt;/li&gt;
  &lt;li&gt;The previous chapters of the course on Linear Programming Duality and General Duality&lt;/li&gt;
  &lt;li&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004). Convex optimization. Cambridge University Press&lt;/li&gt;
  &lt;li&gt;Rockafellar, R. T. (1970). Convex analysis. Princeton University Press&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>11-05 Duality gap</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_05_Duality_gap/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_05_Duality_gap</id>
   <content type="html">&lt;p&gt;In unconstrained optimization, knowing when to stop an iterative solver is notoriously tricky: a tiny gradient \(\|\nabla f(x)\| \le 10^{-5}\) does not by itself tell you how close \(f(x)\) is to \(f^\star\) if the function is very flat. Duality solves this stopping problem with mathematical perfection: whenever an algorithm produces a primal-feasible \(x\) and a dual-feasible \((u, v)\), the observable &lt;strong&gt;duality gap&lt;/strong&gt; \(f(x) - g(u, v)\) rigorously upper-bounds the unobservable true error \(f(x) - f^\star\)!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-duality-gap-as-an-exact-stopping-certificate&quot;&gt;Key ideas: The Duality Gap as an Exact Stopping Certificate&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The Sandwich Inequality:&lt;/strong&gt; Weak duality \(g(u, v) \le f^\star \le f(x)\) immediately implies \(0 \le f(x) - f^\star \le f(x) - g(u, v)\) and \(0 \le g^\star - g(u, v) \le f(x) - g(u, v)\). Both primal and dual errors are simultaneously bounded by one computable number!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Zero Gap Implies Joint Optimality:&lt;/strong&gt; If you ever find a feasible pair \((x, u, v)\) with \(f(x) - g(u, v) = 0\), then \(f(x) = f^\star = g^\star = g(u, v)\): &lt;em&gt;both&lt;/em&gt; \(x\) and \((u, v)\) are guaranteed globally optimal, and strong duality holds automatically.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Non-Asymptotic Stopping Rule in Solvers:&lt;/strong&gt; Modern convex solvers (interior-point methods, coordinate descent for Lasso, dual ascent) terminate as soon as \(f(x^{(k)}) - g(u^{(k)}, v^{(k)}) \le \varepsilon\), guaranteeing \(\varepsilon\)-suboptimality with zero heuristic guesswork.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Constructing Dual-Feasible Points from Primal Iterates:&lt;/strong&gt; Even in primal-only solvers (like ISTA for Lasso), simple dual scaling projects the residual onto the dual feasible set in \(O(n)\) time, unlocking real-time duality-gap monitoring and safe feature screening (GAP Safe rules).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-certifying-varepsilon-optimality-without-knowing-fstar&quot;&gt;Worked example: Certifying \(\varepsilon\)-Optimality Without Knowing \(f^\star\)&lt;/h3&gt;

&lt;p&gt;Suppose we minimize \(f(x) = \frac{1}{2}x^2 - 4x\) subject to \(x \le 2\) (i.e., \(h(x) = x - 2 \le 0\)). From \(L(x, u) = \frac{1}{2}x^2 - (4 - u)x - 2u\), minimizing over \(x\) gives \(x = 4 - u\) and dual function \(g(u) = -\frac{1}{2}(4 - u)^2 - 2u\) for \(u \ge 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate at an intermediate primal–dual iterate \(x^{(k)} = 1.8\) (feasible: \(1.8 \le 2\)) and \(u^{(k)} = 1.5\) (feasible: \(1.5 \ge 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal value: \(f(1.8) = \frac{1}{2}(1.8)^2 - 4(1.8) = 1.62 - 7.20 = -5.58\).&lt;/li&gt;
      &lt;li&gt;Dual value: \(g(1.5) = -\frac{1}{2}(4 - 1.5)^2 - 2(1.5) = -\frac{1}{2}(6.25) - 3.0 = -3.125 - 3.0 = -6.125\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Duality gap:&lt;/strong&gt; \(f(1.8) - g(1.5) = -5.58 - (-6.125) = 0.545\).&lt;/li&gt;
      &lt;li&gt;Without knowing \(f^\star\), we immediately know \(f^\star \in [-6.125,\; -5.58]\) and \(f(1.8) - f^\star \le 0.545\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate at \(x^\star = 2\) and \(u^\star = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Primal value: \(f(2) = \frac{1}{2}(4) - 8 = -6.0\).&lt;/li&gt;
      &lt;li&gt;Dual value: \(g(2) = -\frac{1}{2}(2)^2 - 2(2) = -2 - 4 = -6.0\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Duality gap:&lt;/strong&gt; \(-6.0 - (-6.0) = 0\), certifying exact optimality of both \(x^\star = 2\) and \(u^\star = 2\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the primal problem has value \(f(x)\) at \(x\), and the dual problem has value \(g(u,v)\) at \(u,v\), then the difference \(f(x) - g(u,v)\) is called the duality gap.&lt;/p&gt;

&lt;p&gt;Meanwhile, these feasible values always satisfy the following relation&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{equation}
f(x) - f^* \leq f(x) - g(u,v), 
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;If the duality gap is \(0\), then \(x\) is an optimal solution of the primal problem and \(u,v\) are optimal for the dual problem.&lt;/p&gt;

&lt;p&gt;Also, if the duality gap satisfies \(f(x)-g(u,v) \leq \epsilon\), it implies \(f(x) -f^* \leq \epsilon\), so algorithms that solve problems iteratively can use the duality gap as a stopping criterion.&lt;/p&gt;

&lt;h3 id=&quot;strong-duality-and-slater-in-about-3-minutes&quot;&gt;Strong duality and Slater in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/strong-duality-slater_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The dual function g(λ) below p*, the duality gap as a certificate, the (u, t) picture of supporting lines, and a convex problem without Slater whose gap is 1.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>11-04 Strong duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_04_Strong_duality/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_04_Strong_duality</id>
   <content type="html">&lt;p&gt;Weak duality (\(g^\star \le f^\star\)) is free, but &lt;strong&gt;strong duality&lt;/strong&gt; (\(g^\star = f^\star\))—the guarantee that solving the dual gives the &lt;em&gt;exact&lt;/em&gt; primal optimal value—is the crown jewel that makes dual solvers and KKT conditions work. Does convexity alone guarantee strong duality? Surprisingly, &lt;em&gt;no&lt;/em&gt;! There exist tiny, smooth convex problems with a nonzero duality gap when the feasible set lacks an interior. &lt;strong&gt;Slater’s condition&lt;/strong&gt; fixes this with one breathtakingly simple geometric check: if the problem is convex and there exists even &lt;em&gt;one&lt;/em&gt; strictly feasible point \(x\) with \(h_i(x) &amp;lt; 0\) (and \(l_j(x) = 0\)), strong duality holds!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-when-the-duality-gap-vanishes-completely&quot;&gt;Key ideas: When the Duality Gap Vanishes Completely&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Convexity Is Necessary in General, Not Alone Sufficient:&lt;/strong&gt; Without a constraint qualification, the epigraph of the optimal-value function can have a vertical tangent at zero perturbation, preventing any finite Lagrange multiplier from supporting it and creating a nonzero gap even for convex problems.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Slater’s Condition (Strict Feasibility):&lt;/strong&gt; For a convex problem, if there exists \(x \in \operatorname{relint}(\mathcal{D})\) such that \(h_i(x) &amp;lt; 0\) for all &lt;em&gt;non-affine&lt;/em&gt; inequality constraints and \(l_j(x) = 0\) (plus affine inequalities \(h_k(x) \le 0\) need not be strict!), then \(g^\star = f^\star\) and the dual optimum is attained whenever \(f^\star &amp;gt; -\infty\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Affine Refinement (Why LPs Need No Strict Interior):&lt;/strong&gt; Because linear inequalities need not be strictly satisfied in refined Slater’s condition, every feasible linear program automatically satisfies strong duality without needing an interior point.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — SVM Dual &amp;amp; the Kernel Trick:&lt;/strong&gt; In Support Vector Machines, the primal is a convex QP with purely affine constraints (\(y_i(x_i^\top \beta + \beta_0) \ge 1 - \xi_i, \xi_i \ge 0\)). Slater’s condition holds trivially (just pick \(\beta = 0, \beta_0 = 0, \xi_i = 2\)!), guaranteeing strong duality and letting us replace inner products \(x_i^\top x_j\) with nonlinear kernels \(K(x_i, x_j)\) in the dual!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-checking-slaters-condition-on-a-convex-problem-pass-vs-fail&quot;&gt;Worked example: Checking Slater’s Condition on a Convex Problem (Pass vs. Fail)&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Example A — Slater’s Condition Passes (Convex QCQP):&lt;/strong&gt;
\(\min_{x \in \mathbb{R}^2}\; x_1 + x_2 \quad \text{s.t.} \quad x_1^2 + x_2^2 - 4 \le 0, \quad x_1 - x_2 = 0.\)
    &lt;ul&gt;
      &lt;li&gt;Check convexity: objective is linear (convex), \(h_1(x) = x_1^2 + x_2^2 - 4\) is convex, \(l_1(x) = x_1 - x_2\) is affine.&lt;/li&gt;
      &lt;li&gt;Test \(x = (0, 0)^\top\): \(h_1(0, 0) = -4 &amp;lt; 0\) (strictly negative!) and \(l_1(0, 0) = 0\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Verdict:&lt;/strong&gt; Slater’s condition holds \(\implies\) strong duality \(g^\star = f^\star = -2\sqrt{2}\) is guaranteed!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Example B — Slater’s Condition Fails (Boundary-Only Feasible Set):&lt;/strong&gt;
\(\min_{x \in \mathbb{R}^2}\; e^{-x_1} \quad \text{s.t.} \quad x_1^2 / x_2 \le 0, \quad x_2 &amp;gt; 0.\)
    &lt;ul&gt;
      &lt;li&gt;Wait: \(h_1(x) = x_1^2 / x_2\) is convex on \(x_2 &amp;gt; 0\), and \(x_1^2 / x_2 \le 0\) forces \(x_1 = 0\)—so &lt;strong&gt;no&lt;/strong&gt; point can make \(h_1(x) &amp;lt; 0\)! Slater fails!&lt;/li&gt;
      &lt;li&gt;Primal value: since \(x_1 = 0\) on the entire feasible set, \(f^\star = e^0 = 1\).&lt;/li&gt;
      &lt;li&gt;Dual value: \(L(x, u) = e^{-x_1} + u x_1^2 / x_2\). For any \(u \ge 0\), send \(x_2 \to +\infty\) with fixed \(x_1 &amp;gt; 0\) to get \(\inf_{x_2 &amp;gt; 0} L(x, u) = e^{-x_1}\), and then send \(x_1 \to +\infty\) to get \(g(u) = 0\) for all \(u \ge 0\)!&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Verdict:&lt;/strong&gt; \(g^\star = 0 &amp;lt; 1 = f^\star\)—a genuine nonzero duality gap in a &lt;strong&gt;convex&lt;/strong&gt; problem because Slater’s condition failed!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When a problem satisfies \(f^* = g^*\), this is called &lt;strong&gt;strong duality&lt;/strong&gt;. The &lt;strong&gt;Slater condition&lt;/strong&gt; is a sufficient condition for strong duality.&lt;/p&gt;

&lt;h2 id=&quot;slater-condition&quot;&gt;Slater condition:&lt;/h2&gt;
&lt;p&gt;If the primal problem is convex and there exists at least one strictly feasible \(x \in \mathbb{R}^n\), then strong duality holds.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{equation}
h_1(x)&amp;lt;0,\dots,h_m(x)&amp;lt;0, \text{ and } l_1(x) = 0,\dots,l_r(x) = 0,
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Important refinement: Strict inequality need not be satisfied when the function is affine.&lt;/p&gt;
&lt;h2 id=&quot;example-support-vector-machine-dual&quot;&gt;Example: Support Vector Machine Dual&lt;/h2&gt;
&lt;p&gt;Given \(y \in \{-1,1\}^n\), \(X \in \mathbb{R}^{n \times p}\) (where the columns of \(X\) are \(x_1, ..., x_n\)), the SVM (Support Vector Machine) problem is defined as follows.&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{alignat}{1}
\min_{\beta, \beta_0, \xi} &amp;amp; \quad \frac{1}{2}\parallel\beta\parallel_2^2 + C \sum_{i=1}^n \xi_i   \\\\
                                  s.t. &amp;amp; \quad \xi_i \geq 0, i=1,\dots,n   \\\\
                                       &amp;amp; \quad y_i(x_i^T \beta + \beta_0) \geq 1 - \xi_i, i=1,\dots,n
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Using dual variables \(v, w \geq 0\), let us define the Lagrangian:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{equation}
L(\beta,\beta_0,\xi,v,w) = \frac{1}{2} \parallel\beta\parallel_2^2 + C\sum_{i=1}^n \xi_i - \sum_{i=1}^n v_i \xi_i +  \sum_{i=1}^n w_i (1-\xi_i - y_i(x_i^T\beta + \beta_0))
\end{equation}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By minimizing with respect to \(\beta, \beta_0, \xi\), we can obtain the following Lagrangian dual function:&lt;/p&gt;
&lt;blockquote&gt;

\[g(v,w) = 
\begin{cases}
-\frac{1}{2} w^T\tilde{X}\tilde{X}^T w +  1^Tw, &amp;amp;\text{if $w=C1-v, w^Ty=0$} \\\\
-\infty, &amp;amp;\text{otherwise}
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;Here \(\tilde{X}=\text{diag}(y) X\). Therefore, the SVM dual problem (after eliminating the slack variable \(v\)) becomes the following.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{alignat}{1}
\max_{w}  &amp;amp; \quad -\frac{1}{2} w^T\tilde{X}\tilde{X}^T w +  1^Tw \\\\
     s.t. &amp;amp;  \quad 0 \leq w \leq C1, w^Ty = 0
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Since the primal problem satisfies the Slater condition, strong duality holds. (That is, the objective is convex and the inequality constraints are affine in \(\beta, \beta_0, \xi\).)&lt;/p&gt;

&lt;h3 id=&quot;strong-duality-and-slater-in-about-3-minutes&quot;&gt;Strong duality and Slater in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/strong-duality-slater_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The dual function g(λ) below p*, the duality gap as a certificate, the (u, t) picture of supporting lines, and a convex problem without Slater whose gap is 1.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>11-03 Lagrange dual problem</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_03_Lagrange_dual_problem/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_03_Lagrange_dual_problem</id>
   <content type="html">&lt;p&gt;Every dual-feasible pair \((u, v)\) with \(u \ge 0\) hands us a guaranteed lower bound \(g(u, v) \le f^\star\). Naturally, we want the &lt;em&gt;tightest&lt;/em&gt; possible lower bound—so we define the &lt;strong&gt;Lagrange dual problem&lt;/strong&gt; \(\max_{u, v} \{ g(u, v) : u \ge 0 \}\). Even if the primal problem is a bumpy, multi-modal nonconvex quartic with traps everywhere, this dual problem is a clean &lt;strong&gt;convex optimization problem&lt;/strong&gt; (maximizing a concave function over a convex cone), giving us a tractable way to compute rigorous lower bounds!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-structure--geometry-of-the-lagrange-dual-problem&quot;&gt;Key ideas: Structure &amp;amp; Geometry of the Lagrange Dual Problem&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Always a Convex Optimization Problem:&lt;/strong&gt; Maximizing the concave function \(g(u, v)\) over the convex set \(\{(u, v) : u \ge 0\}\) (equivalently minimizing \(-g(u, v)\)) is &lt;em&gt;always&lt;/em&gt; convex, regardless of whether the primal is convex, discrete, or nonconvex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Weak Duality (\(g^\star \le f^\star\)):&lt;/strong&gt; Since \(g(u, v) \le f^\star\) for all \(u \ge 0, v \in \mathbb{R}^r\), taking the supremum over \(u \ge 0, v\) gives \(g^\star \le f^\star\) unconditionally. The nonnegative difference \(f^\star - g^\star \ge 0\) is the &lt;strong&gt;optimal duality gap&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Implicit Domain Constraints:&lt;/strong&gt; When \(g(u, v) = -\infty\) outside some set (as in LPs or singular QPs), making those domain conditions explicit turns \(\max_{u \ge 0} g(u, v)\) into a standard constrained convex program.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Nonconvex Primal Caveat (Strict Duality Gap):&lt;/strong&gt; For nonconvex problems (like a double-well quartic on a constrained interval), the dual finds the best supporting hyperplane to the primal’s nonconvex optimal-value curve—which can sit strictly below \(f^\star\) (\(g^\star &amp;lt; f^\star\)), yielding a valuable lower bound but not necessarily the exact primal optimum.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-a-strict-duality-gap-on-a-nonconvex-problem&quot;&gt;Worked example: Computing a Strict Duality Gap on a Nonconvex Problem&lt;/h3&gt;

&lt;p&gt;Consider the nonconvex discrete-domain optimization problem:
\(\min_{x \in \{0, 2\}}\; f(x) = x - 2 \quad \text{s.t.} \quad 1 - x \le 0 \text{ (i.e., } x \ge 1\text{)}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the primal directly:&lt;/strong&gt; Between the two domain points \(\{0, 2\}\), only \(x^\star = 2\) satisfies \(x \ge 1\), giving:
\(f^\star = f(2) = 2 - 2 = 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form the Lagrangian \(L(x, u) = (x - 2) + u(1 - x)\) for \(u \ge 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;At \(x = 0\): \(L(0, u) = -2 + u\).&lt;/li&gt;
      &lt;li&gt;At \(x = 2\): \(L(2, u) = 0 - u = -u\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the concave Lagrange dual function \(g(u) = \min_{x \in \{0, 2\}} L(x, u)\):&lt;/strong&gt;
\(g(u) = \min\{ -2 + u,\; -u \}, \qquad u \ge 0.\)
As the pointwise minimum of two affine functions, \(g(u)\) is concave even though the primal domain \(\{0, 2\}\) is nonconvex!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the Lagrange dual problem \(\max_{u \ge 0} g(u)\):&lt;/strong&gt;
Equate the increasing line \(-2 + u\) and the decreasing line \(-u\):
\(-2 + u = -u \implies 2u = 2 \implies u^\star = 1 \ge 0, \qquad g^\star = g(1) = -1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Measure the strict duality gap:&lt;/strong&gt; \(f^\star - g^\star = 0 - (-1) = 1 &amp;gt; 0\)! Geometrically, the dual automatically solved the &lt;em&gt;convex relaxation&lt;/em&gt; \(x \in [0, 2]\) (where \(x = 1\) achieves \(f(1) = -1\)), showing concretely why nonconvexity can leave a strict gap \(g^\star &amp;lt; f^\star\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Consider the following optimization problem:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{alignat}{1}
\min_x &amp;amp; \quad f(x)  \\
s.t.   &amp;amp; \quad h_i(x) \leq 0, i=1,\dots,m  \\
       &amp;amp; \quad l_j(x) = 0, j=1,\dots,r
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;The dual function \(g(u,v)\) satisfies \(f^* \geq g(u,v)\) for all \(u\geq 0\) and \(v\). Therefore, we can obtain the best lower bound by maximizing \(g(u,v)\) over all feasible \(u\) and \(v\). This is called the Lagrange dual problem.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{alignat}{1}
\max_{u,v} &amp;amp; \quad g(u,v)   \\
           s.t. &amp;amp; \quad u \geq 0
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, if we denote the dual optimal value as \(g^*\), then \(f^* \geq g^*\). This is called weak duality. This property always holds even when the primal problem is not convex. Moreover, the dual problem is always a convex optimization problem, even when the primal problem is not convex.&lt;/p&gt;

&lt;p&gt;By definition, \(g\) is concave with respect to \((u,v)\), and \(u \geq 0\) is a convex constraint. Therefore, the dual problem corresponds to a concave maximization problem.&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{alignat}{1}
 g(u,v) &amp;amp; = \min_x { f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x) }  \ 
        &amp;amp; = - \underbrace{\max_x { -f(x) - \sum_{i=1}^m u_i h_i(x) - \sum_{j=1}^r v_j l_j(x) }}_{\text{pointwise maximum of convex functions in $(u,v)$}}
\end{alignat}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;example-nonconvex-quartic-minimization&quot;&gt;Example: nonconvex quartic minimization&lt;/h2&gt;
&lt;p&gt;Let us minimize the function \(f(x)=x^4 - 50 x^2 + 100 x\) subject to \(x \geq -4.5\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter11/dual-gen_13.png&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 4] Example of nonconvex quadratic minimization&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;In this case, the dual function \(g\) is as follows:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{equation}
 g(u) = \min_{i=1,2,3} \{F_i^4(u) - 50 F_i^2(u) + 100 F_i(u) \}
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;where, for \(i=1,2,3\),&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{alignat}{1}
F_i(u) = &amp;amp; \frac{- a_i}{12\cdot 2^{1/3}} \left( 432(100-u)-(432^2(100-u)^2 - 4\cdot 1200^3)^{1/2} \right )^{1/3} \\ 
           &amp;amp; - 100 \cdot 2^{1/3} \frac{1}{\left( 432(100-u)-(432^2(100-u)^2 - 4\cdot 1200^3)^{1/2} \right )^{1/3}}
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;and \(a_1=1, a_2 = (-1+i\sqrt{3})/2, a_3 = (-1-i \sqrt{3})/2\).
While it is difficult to determine whether \(g\) is concave just by looking at the function, we can know that \(g\) is concave under the convexity property of duality.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>11-02 Lagrange dual function</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_02_Lagrange_dual_function/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_02_Lagrange_dual_function</id>
   <content type="html">&lt;p&gt;Once you form the Lagrangian \(L(x, u, v)\), how do you turn it into a concrete lower bound on \(f^\star\) that does not depend on \(x\)? You simply drop all constraints and take the unconstrained infimum over \(x\): \(g(u, v) = \inf_x L(x, u, v)\). This &lt;strong&gt;Lagrange dual function&lt;/strong&gt; is one of the cleanest miracles in mathematics: even when the original primal problem is nonconvex and NP-hard, \(g(u, v)\) is &lt;em&gt;guaranteed&lt;/em&gt; to be a concave function of \((u, v)\) that lower-bounds \(f^\star\) everywhere!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-properties--computation-of-the-dual-function&quot;&gt;Key ideas: Properties &amp;amp; Computation of the Dual Function&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Universal Lower-Bound Inequality:&lt;/strong&gt; For any \(u \ge 0\) and \(v\), \(f^\star = \min_{x \in C} f(x) \ge \min_{x \in C} L(x, u, v) \ge \inf_x L(x, u, v) = g(u, v)\). Notice the two distinct relaxations: first replacing \(f\) by \(L \le f\) on \(C\), then enlarging the minimization domain from \(C\) to all of \(\mathbb{R}^n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Guaranteed Concavity:&lt;/strong&gt; Because \(L(x, u, v)\) is affine in \((u, v)\) for each fixed \(x\), \(g(u, v) = \inf_x L(x, u, v)\) is the pointwise infimum of affine functions—hence &lt;strong&gt;always concave&lt;/strong&gt;, with a convex effective domain \(\operatorname{dom}(g) = \{(u, v) : g(u, v) &amp;gt; -\infty\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Quadratic Program (QP) Duals (\(Q \succ 0\) vs. \(Q \succeq 0\)):&lt;/strong&gt; For \(\frac{1}{2}x^\top Q x + c^\top x\) subject to \(Ax = b, x \ge 0\), when \(Q \succ 0\) the unique minimizer \(x = -Q^{-1}(c - u + A^\top v)\) gives a closed-form concave quadratic \(g(u, v)\). When \(Q \succeq 0\) is singular, \(g(u, v)\) is finite &lt;em&gt;only&lt;/em&gt; when \(c - u + A^\top v \in \operatorname{col}(Q)\), using the Moore–Penrose pseudoinverse \(Q^+\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Connection to Fenchel Conjugates:&lt;/strong&gt; For linear constraints \(Ax = b, Gx \le h\), \(g(u, v) = -f^\star(-A^\top v - G^\top u) - b^\top v - h^\top u\), showing that computing a dual function is mathematically equivalent to computing the Fenchel conjugate \(f^\star\) of the objective.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-gu-v-for-a-positive-definite-vs-singular-qp&quot;&gt;Worked example: Computing \(g(u, v)\) for a Positive Definite vs. Singular QP&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + \alpha x_2^2) - 2x_1 - 4x_2\) subject to \(x_1 + x_2 = 1\) (with equality multiplier \(v \in \mathbb{R}\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Case A — Strictly Positive Definite (\(\alpha = 2\), so \(Q = \operatorname{diag}(1, 2) \succ 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Lagrangian: \(L(x, v) = \frac{1}{2}x_1^2 + x_2^2 - 2x_1 - 4x_2 + v(x_1 + x_2 - 1)\).&lt;/li&gt;
      &lt;li&gt;Stationarity in \(x\): \(x_1 - 2 + v = 0 \implies x_1 = 2 - v\); \(2x_2 - 4 + v = 0 \implies x_2 = 2 - \frac{v}{2}\).&lt;/li&gt;
      &lt;li&gt;Substitute back:
\(g(v) = -\frac{1}{2}(2 - v)^2 - \left(2 - \frac{v}{2}\right)^2 - v = -\frac{3}{4}v^2 + 3v - 6.\)&lt;/li&gt;
      &lt;li&gt;Note \(g(v)\) is finite for &lt;em&gt;all&lt;/em&gt; \(v \in \mathbb{R}\) and strictly concave (\(g&apos;&apos;(v) = -3/2 &amp;lt; 0\))!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case B — Positive Semidefinite / Singular (\(\alpha = 0\), so \(Q = \operatorname{diag}(1, 0) \succeq 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Lagrangian: \(L(x, v) = \frac{1}{2}x_1^2 + (v - 2)x_1 + (v - 4)x_2 - v\).&lt;/li&gt;
      &lt;li&gt;Minimize over \(x_2 \in \mathbb{R}\): linear in \(x_2\), so bounded below &lt;strong&gt;if and only if&lt;/strong&gt; \(v - 4 = 0 \implies v = 4\)!&lt;/li&gt;
      &lt;li&gt;At \(v = 4\), minimize over \(x_1\): \(x_1 = 2 - 4 = -2\), giving \(g(4) = \frac{1}{2}(-2)^2 + 2(-2) - 4 = 2 - 4 - 4 = -6\).&lt;/li&gt;
      &lt;li&gt;Thus \(g(v) = -6\) if \(v = 4\), and \(-\infty\) otherwise—illustrating how singularity of \(Q\) creates an implicit equality constraint on the dual variable!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let \(C\) be the primal feasible set and \(f^*\) the primal optimal value. Minimizing \(L(x,u,v)\) over all \(x\) yields the following lower bound.&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
f^* \geq \min_{x \in C} L(x,u,v) \geq \min_x L(x,u,v) := g(u,v)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(g(u,v)\) is called the Lagrange dual function and provides a lower bound on \(f^*\) for any dual feasible \(u\geq 0\), \(v\).&lt;/p&gt;

&lt;p&gt;For example, in the figure below&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter11/dual-gen_7.png&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 2] Example of Lagrangian dual function[1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;The dashed horizontal line indicates the function \(f^*\).&lt;/li&gt;
  &lt;li&gt;The dual variable is \(\lambda\).&lt;/li&gt;
  &lt;li&gt;The solid line indicates \(g(\lambda)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;example-quadratic-program&quot;&gt;Example: Quadratic Program&lt;/h2&gt;
&lt;h3 id=&quot;1-positive-definite-q-succ-0&quot;&gt;1) Positive Definite (\(Q \succ 0\))&lt;/h3&gt;

&lt;p&gt;Consider the following quadratic problem (here \(Q \succ 0\))&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{alignat}{1}
\min_x  &amp;amp; \quad \frac{1}{2}x^T Q x + c^T x \\\\
       s.t. &amp;amp; \quad Ax = b, \\\\
            &amp;amp; \quad x \geq 0
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Then,&lt;/p&gt;

&lt;h4 id=&quot;lagrangian&quot;&gt;Lagrangian:&lt;/h4&gt;
&lt;blockquote&gt;

\[\begin{equation}
L(x,u,v) = \frac{1}{2}x^T Q x + c^T x - u^Tx + v^T (Ax-b)
\end{equation}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;lagrangian-dual-function&quot;&gt;Lagrangian dual function:&lt;/h4&gt;

&lt;p&gt;From the expression above, to minimize the Lagrangian function, differentiate with respect to \(x\) and find \(x^*\) such that the derivative is zero.
\begin{equation}
Qx - (c-u+A^T v) = 0,
\end{equation}
That is,
\begin{equation}
Qx = (c-u+A^T v)
\end{equation}
Since \(Q\) is positive definite, its inverse exists, so we can find \(x^*\) as \(x^* = Q^{-1}(c - u + A^Tv)\). Therefore, substituting \(x^*\) into the Lagrangian function, we obtain the following.&lt;/p&gt;

\[\begin{alignat}{1}
&amp;amp; (c - u + A^T v)^T (Q^{-1})^T Q Q^{-1}(c - u + A^T v) - (c - u + A^T v)^T Q^{-1} (c - u + A^T v) - b^T v \\\
= &amp;amp; (c - u + A^T v)^T Q^{-1}(c - u + A^T v) - (c - u + A^T v)^T Q^{-1} (c - u + A^T v) - b^T v \\\
= &amp;amp; -\frac{1}{2} (c-u+A^Tv)^T Q^{-1} (c-u+A^T v) - b^T v
\end{alignat}\]

&lt;p&gt;Therefore,&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{equation}
g(u,v) = \min_x L(x,u,v) = -\frac{1}{2} (c-u+A^Tv)^T Q^{-1} (c-u+A^T v) - b^T v
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;For all \(u \geq 0\) and \(v\), this corresponds to a lower bound on the primal optimum \(f^*\).&lt;/p&gt;

&lt;h3 id=&quot;2-positive-semidefinite-q-succeq-0&quot;&gt;2) Positive Semidefinite (\(Q \succeq 0\))&lt;/h3&gt;
&lt;p&gt;For the same problem as above, but this time if \(Q \succeq 0\),&lt;/p&gt;

&lt;h4 id=&quot;lagrangian-1&quot;&gt;Lagrangian:&lt;/h4&gt;
&lt;blockquote&gt;

\[\begin{equation}
L(x,u,v) = \frac{1}{2}x^T Q x + c^T x - u^Tx + v^T (Ax-b)
\end{equation}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;lagrangian-dual-function-1&quot;&gt;Lagrangian dual function:&lt;/h4&gt;
&lt;p&gt;As in the case when \(Q\) is positive definite, we need to find \(x^*\) that satisfies the following equation.&lt;/p&gt;

&lt;p&gt;\(\begin{equation}
Qx = (c-u+A^T v)
\end{equation}\)
At this point, since \(Q\) is positive semi-definite, its inverse may not exist. Therefore, we need to consider the following two cases.&lt;/p&gt;

&lt;p&gt;(1) \(c-u+A^T v \in col(Q)\). In this case, there exists \(x^*\) satisfying \(Qx = (c-u+A^T v)\), which can be found using the generalized inverse \(Q^+\) (the Moore-Penrose pseudo-inverse, \(Q^+ = (Q^TQ)^{-1}Q^T\)).
(2) \(c-u+A^T v \notin col(Q)\). In this case, there is no \(x^*\) satisfying \(Qx = (c-u+A^T v)\), meaning there is no \(x^*\) that minimizes \(L(x,u,v)\), and the minimum of \(L(x,u,v)\) is \(-\infty\).&lt;/p&gt;

&lt;p&gt;From these two cases, the Lagrangian dual function can be summarized as follows.&lt;/p&gt;
&lt;blockquote&gt;

\[g(u,v) =
\begin{cases}
-\frac{1}{2} (c-u+A^T v)^T Q^{+} (c - u + A^T v) - b^T v  &amp;amp; \text{if $c-u+A^T v \perp \text{null}(Q)$} \\\\
-\infty  &amp;amp; \text{otherwise}
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;For all \(u\geq 0\), \(v\) with \(c-u+A^Tv \perp \text{null}(Q)\), \(g(u,v)\) is a nontrivial lower bound on \(f^*\).&lt;/p&gt;

&lt;h2 id=&quot;example-quadratic-program-in-2d&quot;&gt;Example: Quadratic Program in 2D&lt;/h2&gt;

&lt;p&gt;For example, in the following figure, \(f(x_1,x_2)\) is a quadratic function over variables greater than 0 (\(x\ge0\)), and the dual function \(g(u_1,u_2)\) is a quadratic function over variables greater than 0 (\(u\ge0\)).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter11/dual-gen_10.png&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 3] Example of quadratic program in 2D&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;The blue point is the optimal dual value, and the red point is the optimal primal value.&lt;/li&gt;
  &lt;li&gt;For all \(u&amp;gt;0\), the dual function \(g(u)\) provides a lower bound on \(f^*\).&lt;/li&gt;
  &lt;li&gt;The maximum of the dual function \(g(u)\) matches exactly the value \(f^*\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;the-dual-function-is-a-lower-bound-video&quot;&gt;The dual function is a lower bound (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/dual-lower-bound_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;For every \(\lambda\ge 0\) the minimum of the Lagrangian, \(g(\lambda)=\min_x L(x,\lambda)\), is a lower bound on \(p^*\). The dual problem maximises that bound.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-slide-the-multiplier&quot;&gt;Try it yourself: slide the multiplier&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;d1&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>11-01 Lagrangian</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_01_Lagrangian/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_01_Lagrangian</id>
   <content type="html">&lt;p&gt;When Joseph-Louis Lagrange introduced multipliers in 1788 to analyze constrained mechanical systems, he replaced rigid physical walls with virtual restoring forces. In modern optimization, the &lt;strong&gt;Lagrangian&lt;/strong&gt; \(L(x, u, v) = f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x)\) plays the exact same economic role: instead of forbidding constraint violations outright (an infinite wall), it charges a linear fee \(u_i \ge 0\) per unit of inequality violation \(h_i(x) &amp;gt; 0\) (and offers a rebate when \(h_i(x) &amp;lt; 0\)). That simple soft-pricing reformulation is the foundation of all nonlinear duality and KKT theory.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-anatomy-and-geometry-of-the-lagrangian&quot;&gt;Key ideas: The Anatomy and Geometry of the Lagrangian&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Exact Hard-Wall Representation via Supremum:&lt;/strong&gt; Notice that \(\sup_{u \ge 0,\; v} L(x, u, v)\) equals \(f(x)\) if \(x\) is primal feasible (since \(u_i h_i(x) \le 0\) is maximized at \(u_i = 0\) and \(v_j l_j(x) = 0\)), and equals \(+\infty\) if &lt;em&gt;any&lt;/em&gt; constraint is violated! Thus \(\min_x \sup_{u \ge 0, v} L(x, u, v)\) is &lt;em&gt;exact&lt;/em&gt; and equivalent to the primal problem.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Lower-Bound Property on the Feasible Set \(C\):&lt;/strong&gt; For every feasible \(x \in C\) and every \(u \ge 0, v \in \mathbb{R}^r\), \(h_i(x) \le 0\) and \(l_j(x) = 0\) force \(L(x, u, v) \le f(x)\). Therefore, \(L(\cdot, u, v)\) is a global underestimator of \(f\) on \(C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Affine Dependence on Dual Multipliers:&lt;/strong&gt; For any &lt;em&gt;fixed&lt;/em&gt; \(x\), \(L(x, u, v)\) is an affine (linear + constant) function of \((u, v)\), regardless of whether \(f, h_i, l_j\) are convex, trigonometric, or combinatorial.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Min-Max vs. Max-Min Game:&lt;/strong&gt; The primal problem is \(\min_x \sup_{u \ge 0, v} L(x, u, v)\); swapping the order of \(\min\) and \(\sup\) yields the dual problem \(\max_{u \ge 0, v} \inf_x L(x, u, v)\), immediately revealing weak duality via the elementary max-min inequality.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-watching-sup_u-ge-0-lx-u-enforce-a-hard-constraint&quot;&gt;Worked example: Watching \(\sup_{u \ge 0} L(x, u)\) Enforce a Hard Constraint&lt;/h3&gt;

&lt;p&gt;Consider minimizing \(f(x) = (x - 3)^2\) subject to \(h(x) = x - 1 \le 0\) (feasible set \(C = (-\infty, 1]\), optimal \(x^\star = 1, f^\star = 4\)). Its Lagrangian is \(L(x, u) = (x - 3)^2 + u(x - 1)\) for \(u \ge 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test a feasible point \(x = 0 \in C\) (so \(h(0) = -1 &amp;lt; 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(L(0, u) = 9 - u\).&lt;/li&gt;
      &lt;li&gt;For any \(u \ge 0\), \(L(0, u) = 9 - u \le 9 = f(0)\) (underestimates \(f\)!).&lt;/li&gt;
      &lt;li&gt;Taking \(\sup_{u \ge 0} (9 - u)\) attains its maximum at \(u = 0\), giving exactly \(9 = f(0)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test a boundary point \(x = 1 \in C\) (so \(h(1) = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(L(1, u) = 4 + u(0) = 4\) for &lt;em&gt;all&lt;/em&gt; \(u \ge 0\), so \(\sup_{u \ge 0} L(1, u) = 4 = f(1)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test an infeasible point \(x = 2 \notin C\) (so \(h(2) = +1 &amp;gt; 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(L(2, u) = 1 + u\).&lt;/li&gt;
      &lt;li&gt;Taking \(\sup_{u \ge 0} (1 + u) = +\infty\)! The dual player drives the penalty to infinity, ruthlessly eliminating every infeasible \(x\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We now look at the Lagrangian form for the following optimization problem. Here, the optimization problem need not be convex.&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{alignat}{1}
\min_x &amp;amp; \quad f(x)  \\\
s.t.   &amp;amp; \quad h_i(x) \leq 0, i = 1,\dots,m \\\
       &amp;amp; \quad l_j(x) = 0, j=1,\dots,r
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;The Lagrangian is defined as follows.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{equation}
L(x,u,v) = f(x) + \sum_{i=1}^m u_i h_i(x) + \sum_{j=1}^r v_j l_j(x)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(u \in \mathbb{R}^m\), \(v \in \mathbb{R}^r\), \(u \geq 0\) (implicitly, \(L(x,u,v) = - \infty\) for \(u &amp;lt;0\)).&lt;/p&gt;

&lt;p&gt;Since in the constraints we have \(h_i(x) \leq 0\) and \(l_j(x)=0\),&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
L(x,u,v) =  f(x) + \sum_{i=1}^{m} u_i \underbrace{h_i(x)}_{\leq 0} + \sum_{j=1}^r v_j \underbrace{l_j(x)}_{=0} \leq f(x)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;In other words, the Lagrangian has the following important property.&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;For all \(u \geq 0\), \(v\), we have \(f(x) \geq L(x,u,v) \text{ at each feasible } x\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example, in the figure below,&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter11/dual-gen_6.png&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Example of Lagrangian[1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;The solid line indicates the function \(f\).&lt;/li&gt;
  &lt;li&gt;The dashed line indicates the function \(h\). Here, the feasible set is roughly \([-0.46,0.46]\).&lt;/li&gt;
  &lt;li&gt;Each dotted line indicates the function \(L(x,u,v)\) for \(u \geq 0\), \(v\).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>11 Duality in General Programs</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_00_Duality_in_General_Programs/"/>
   <updated>2021-03-24T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter11/11_00_Duality_in_General_Programs</id>
   <content type="html">&lt;p&gt;In Chapter 10, linear programming duality gave us a remarkable mirror world: every LP has a dual LP whose feasible solutions certify lower bounds, and strong duality closes the gap completely. What happens when the objective and constraints are no longer linear—when they are quadratic, logarithmic, semidefinite, or even &lt;strong&gt;nonconvex&lt;/strong&gt;? Chapter 11 lifts duality to &lt;em&gt;completely general&lt;/em&gt; optimization problems using the &lt;strong&gt;Lagrangian&lt;/strong&gt; \(L(x, u, v)\), revealing a deep surprise: even when the original primal problem is wildly nonconvex, its Lagrange dual problem is &lt;strong&gt;always concave (convex to maximize)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-lifting-duality-beyond-linear-programs&quot;&gt;Key ideas: Lifting Duality Beyond Linear Programs&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The Universal Lagrangian \(L(x, u, v)\):&lt;/strong&gt; Attaching nonnegative prices \(u_i \ge 0\) to inequalities \(h_i(x) \le 0\) and free prices \(v_j \in \mathbb{R}\) to equalities \(l_j(x) = 0\) transforms &lt;em&gt;any&lt;/em&gt; constrained problem—convex or nonconvex—into a parameterized unconstrained objective.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Concavity of the Dual Function \(g(u, v)\):&lt;/strong&gt; Because \(g(u, v) = \inf_x L(x, u, v)\) is the pointwise infimum of a family of affine functions of \((u, v)\), \(g\) is &lt;em&gt;always concave&lt;/em&gt;, regardless of how complicated or nonconvex \(f, h_i, l_j\) are.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Weak Duality Always, Strong Duality Under Slater’s Condition:&lt;/strong&gt; Weak duality (\(g^\star \le f^\star\)) holds universally with zero convexity assumptions. Strong duality (\(g^\star = f^\star\)) requires convexity plus a regularity condition—most famously &lt;strong&gt;Slater’s condition&lt;/strong&gt; (existence of a strictly feasible interior point).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Duality Gap as a Real-Time Stopping Criterion:&lt;/strong&gt; For any primal-feasible \(x\) and dual-feasible \((u, v)\), \(f(x) - f^\star \le f(x) - g(u, v)\), giving interior-point and primal–dual solvers an exact, provable certificate of suboptimality without ever knowing \(f^\star\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-from-general-lp-duality-to-nonlinear-quadratic-duality&quot;&gt;Worked example: From General LP Duality to Nonlinear Quadratic Duality&lt;/h3&gt;

&lt;p&gt;Contrast how the Lagrangian works on an LP vs. a nonlinear quadratic problem: minimize \(f(x) = x^2\) subject to \(x \ge 2\) (i.e., \(h(x) = 2 - x \le 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the Lagrangian with multiplier \(u \ge 0\):&lt;/strong&gt;
\(L(x, u) = x^2 + u(2 - x) = x^2 - ux + 2u.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize \(L(x, u)\) over unconstrained \(x \in \mathbb{R}\):&lt;/strong&gt;
Unlike an LP (where \(\inf_x L\) was \(-\infty\) unless a linear constraint held), here \(L(x, u)\) is a strictly convex parabola in \(x\)! Setting \(\frac{\partial L}{\partial x} = 2x - u = 0\) gives \(x(u) = \frac{u}{2}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Substitute \(x(u) = u/2\) to obtain the smooth concave dual function:&lt;/strong&gt;
\(g(u) = \left(\frac{u}{2}\right)^2 - u\left(\frac{u}{2}\right) + 2u = -\frac{u^2}{4} + 2u.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Maximize \(g(u)\) over \(u \ge 0\):&lt;/strong&gt; Setting \(g&apos;(u) = -\frac{u}{2} + 2 = 0\) gives \(u^\star = 4 \ge 0\), yielding \(g^\star = -\frac{16}{4} + 8 = 4 = 2^2 = f^\star\)! Strong duality holds because the problem is convex and \(x = 3\) strictly satisfies \(2 - 3 = -1 &amp;lt; 0\) (Slater’s condition).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;review-duality-in-linear-program&quot;&gt;Review: duality in linear program&lt;/h3&gt;

&lt;p&gt;Given \(c \in \mathbb{R}^n\), \(A \in \mathbb{R}^{m \times n}\), \(b \in \mathbb{R}^m\), \(G \in \mathbb{R}^{r \times n}\), \(h \in \mathbb{R}^r\),&lt;/p&gt;

&lt;h4 id=&quot;primal-lp&quot;&gt;Primal LP:&lt;/h4&gt;
&lt;blockquote&gt;

\[\begin{alignat}{1}
\min_{x} &amp;amp; \quad c^T x   \\\\ 
  s.t.   &amp;amp; \quad Ax = b  \\\\
         &amp;amp; \quad Gx \leq h 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;dual-lp&quot;&gt;Dual LP:&lt;/h4&gt;
&lt;blockquote&gt;

\[\begin{alignat}{1}
\max_{u,b} &amp;amp; \quad -b^T u - h^T v   \\\\
         s.t. &amp;amp; \quad - A^T u - G^T v = c  \\\\
             &amp;amp; \quad v \geq 0 
\end{alignat}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;explanation-1&quot;&gt;Explanation 1:&lt;/h3&gt;

&lt;p&gt;For all \(u\) and \(v \geq 0\), and for any primal feasible \(x\), the following holds.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{equation}
u^T (Ax-b) + v^T(Gx-h) \leq 0
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;That is,&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
(-A^Tu - G^Tv)^T x \geq -b^Tu - h^T v
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;By this relationship, if \(c=-A^Tu - G^Tv\), we obtain a lower bound on the primal optimum.&lt;/p&gt;

&lt;h3 id=&quot;explanation-2&quot;&gt;Explanation 2:&lt;/h3&gt;

&lt;p&gt;For all \(u\) and \(v \geq 0\), and for any primal feasible \(x\),&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
c^T x \geq c^T x + u^T (Ax-b) + v^T (Gx -h) := L(x,u,v)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Thus, if \(C\) is the primal feasible set and \(f^*\) is the primal optimum, then&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
f^* \geq \min_{x \in C} L(x,u,v) \geq \min_x L(x,u,v) := g(u,v)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;In other words, \(g(u,v)\) is a lower bound on \(f^*\).&lt;/p&gt;

&lt;blockquote&gt;

\[g(u,v) =
\begin{cases}
-b^T u - h^T v &amp;amp; \text{if $c=-A^Tu - G^T v$} \\\\
-\infty            &amp;amp; \text{otherwise} 
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;The second explanation yields the same dual as the first, but it is completely general and applies to arbitrary optimization problems (including nonconvex ones).&lt;/p&gt;

&lt;h2 id=&quot;modern-applications-20222026&quot;&gt;Modern applications (2022–2026)&lt;/h2&gt;

&lt;p&gt;An optional companion lesson uses the same Lagrangian dual as a training signal or certificate in DRO, AC-OPF networks (DC3 / OPF-DNN), Fairlearn reductions, and kernel SVMs. See &lt;a href=&quot;/contents/en/chapter11/11_08_modern_applications/&quot;&gt;11-08 Modern applications of Lagrangian duality&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>18-09 Bài Tập Thực Hành - Quasi-Newton Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_09_Practical_Exercises_Quasi_Newton_Methods/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_09_Practical_Exercises_Quasi_Newton_Methods</id>
   <content type="html">&lt;p&gt;Để thực sự tin tưởng các công thức cập nhật ma trận phức tạp như SR1, DFP, BFGS hay vòng lặp hai chiều L-BFGS, không gì thay thế được việc tự tay tính thử từng ma trận \(2 \times 2\), kiểm chứng phương trình secant bằng phép nhân trực tiếp và đối chiếu số vòng lặp của chúng trên các hàm kiểm chuẩn khét tiếng như thung lũng cong Rosenbrock. Bộ bài tập thực hành này giúp bạn biến các ký hiệu \(B_k, H_k, s_k, y_k\) thành kỹ năng tính toán và lập trình sắc bén.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nguyên-tắc-kiểm-tra-chéo-khi-làm-bài-tập-quasi-newton&quot;&gt;Kiến thức cần nhớ: Bốn nguyên tắc kiểm tra chéo khi làm bài tập Quasi-Newton&lt;/h2&gt;

&lt;p&gt;Trước khi giải từng bài tập tính tay và viết mã bên dưới, hãy giữ sẵn bốn phép kiểm chứng nhanh này như một “bộ công cụ gỡ lỗi”:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra dấu điều kiện độ cong trước mọi phép cập nhật:&lt;/strong&gt; Luôn tính \(y_k^T s_k\) đầu tiên. Nếu \(y_k^T s_k \le 0\), cập nhật BFGS/DFP không còn đảm bảo tính xác định dương và bạn cần kiểm tra lại hướng bước đi hoặc điều kiện Wolfe.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng phương trình secant ngay sau khi tính \(B_{k+1}\) hoặc \(H_{k+1}\):&lt;/strong&gt; Phép nhân \(B_{k+1} s_k\) &lt;strong&gt;bắt buộc&lt;/strong&gt; phải ra đúng \(y_k\) (và \(H_{k+1} y_k = s_k\)). Nếu lệch dù chỉ ở một phần tử, chắc chắn đã có lỗi dấu hoặc lỗi hệ số \(\rho = 1/(y_k^T s_k)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra tính đối xứng và trị riêng dương:&lt;/strong&gt; Với ma trận \(2 \times 2\) dạng \(\begin{bmatrix} a &amp;amp; b \\ b &amp;amp; c \end{bmatrix}\), kiểm tra nhanh \(a &amp;gt; 0\) và \(ac - b^2 &amp;gt; 0\) là đủ khẳng định ma trận xác định dương.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối chiếu L-BFGS với BFGS đầy đủ:&lt;/strong&gt; Khi lập trình L-BFGS, đặt lịch sử \(m\) lớn hơn số vòng lặp chạy thử (và dùng cùng khởi tạo \(H_0 = I\), tắt tỉ lệ động \(\gamma_k\)) thì hướng bước đi của L-BFGS phải trùng khớp tuyệt đối với BFGS đầy đủ tới sai số máy \(10^{-14}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-thử-kiểm-tra-nhanh-tính-tương-thích-giữa-b_1-và-h_1-trên-một-ví-dụ-nhỏ&quot;&gt;Giải thích: Thử kiểm tra nhanh tính tương thích giữa \(B_1\) và \(H_1\) trên một ví dụ nhỏ&lt;/h3&gt;

&lt;p&gt;Giả sử trên hàm \(f(x_1, x_2) = 2x_1^2 + x_2^2\), bạn đi từ \(x^0 = (1, 2)^T\) tới \(x^1 = (0.5, 1)^T\) với \(H_0 = I\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính cặp \((s, y)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(s = x^1 - x^0 = (-0.5, \; -1)^T\).&lt;/li&gt;
      &lt;li&gt;\(\nabla f(x^0) = (4, 4)^T\), \(\nabla f(x^1) = (2, 2)^T \implies y = (-2, \; -2)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện độ cong:&lt;/strong&gt; \(y^T s = (-2)(-0.5) + (-2)(-1) = 1 + 2 = 3 &amp;gt; 0 \implies \rho = \frac{1}{3}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(B_1^{\text{BFGS}}\):&lt;/strong&gt; Với \(B_0 = I\), \(s^T B_0 s = 0.25 + 1 = 1.25\):
\(B_1 = I - \frac{1}{1.25}\begin{bmatrix} 0.25 &amp;amp; 0.5 \\ 0.5 &amp;amp; 1 \end{bmatrix} + \frac{1}{3}\begin{bmatrix} 4 &amp;amp; 4 \\ 4 &amp;amp; 4 \end{bmatrix} = \begin{bmatrix} 0.8 &amp;amp; -0.4 \\ -0.4 &amp;amp; 0.2 \end{bmatrix} + \begin{bmatrix} 4/3 &amp;amp; 4/3 \\ 4/3 &amp;amp; 4/3 \end{bmatrix} \approx \begin{bmatrix} 2.1333 &amp;amp; 0.9333 \\ 0.9333 &amp;amp; 1.5333 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng chéo secant:&lt;/strong&gt;
\(B_1 s = \begin{bmatrix} 2.1333(-0.5) + 0.9333(-1) \\ 0.9333(-0.5) + 1.5333(-1) \end{bmatrix} = \begin{bmatrix} -2.0000 \\ -2.0000 \end{bmatrix} = y, \qquad \det(B_1) \approx 2.40 &amp;gt; 0.\)
Mọi phép kiểm tra đều khớp hoàn hảo — bạn đã sẵn sàng chinh phục trọn bộ bài tập thực hành của Chương 18!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---phương-pháp-quasi-newton&quot;&gt;Bài Tập Thực Hành - Phương pháp Quasi-Newton&lt;/h1&gt;

&lt;p&gt;Các bài tập được tham khảo từ Nocedal &amp;amp; Wright (2006).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-1-cập-nhật-bfgs&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Cập nhật BFGS&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho hàm mục tiêu \(f(x) = x_1^2 + 4x_2^2\), \(x^{(k)} = (2, 1)\), \(x^{(k+1)} = (1.6, 0.7)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tính \(s^{(k)} = x^{(k+1)} - x^{(k)}\) và \(y^{(k)} = \nabla f(x^{(k+1)}) - \nabla f(x^{(k)})\).&lt;br /&gt;
b) Áp dụng công thức cập nhật BFGS cho xấp xỉ nghịch đảo Hessian: \(H_{k+1} = \left(I - \rho s y^T\right) H_k \left(I - \rho y s^T\right) + \rho s s^T\), với \(\rho = \frac{1}{y^Ts}\) và khởi tạo \(H_0 = I\).&lt;br /&gt;
c) Kiểm chứng phương trình secant \(H_{k+1}y = s\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Tính $$s$$ và $$y$$:**

$$s = (1.6, 0.7) - (2, 1) = (-0.4, -0.3)$$

$$\nabla f(x) = (2x_1, 8x_2)$$

$$\nabla f(x^{(k)}) = (4, 8)$$, $$\nabla f(x^{(k+1)}) = (3.2, 5.6)$$

$$y = (3.2, 5.6) - (4, 8) = (-0.8, -2.4)$$

---

**b) Cập nhật BFGS (khởi tạo $$H_0 = I$$):**

$$y^Ts = (-0.8)(-0.4) + (-2.4)(-0.3) = 0.32 + 0.72 = 1.04$$, suy ra $$\rho = 1/1.04 \approx 0.9615$$.

$$I - \rho s y^T = \begin{bmatrix} 0.692 &amp;amp; -0.923 \\ -0.231 &amp;amp; 0.308 \end{bmatrix}$$

$$H_1 = (I - \rho s y^T)(I - \rho y s^T) + \rho s s^T$$

$$\approx \begin{bmatrix} 1.331 &amp;amp; -0.444 \\ -0.444 &amp;amp; 0.148 \end{bmatrix} + \begin{bmatrix} 0.154 &amp;amp; 0.115 \\ 0.115 &amp;amp; 0.087 \end{bmatrix} \approx \begin{bmatrix} 1.485 &amp;amp; -0.328 \\ -0.328 &amp;amp; 0.234 \end{bmatrix}$$

---

**c) Kiểm chứng điều kiện secant:**

$$H_1 y = \begin{bmatrix} 1.485 &amp;amp; -0.328 \\ -0.328 &amp;amp; 0.234 \end{bmatrix} \begin{bmatrix} -0.8 \\ -2.4 \end{bmatrix} \approx \begin{bmatrix} -0.4 \\ -0.3 \end{bmatrix} = s$$ ✓

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-so-sánh-sr1-và-bfgs&quot;&gt;📝 &lt;strong&gt;Bài tập 2: So sánh SR1 và BFGS&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Xét công thức cập nhật SR1: \(H_{k+1} = H_k + \frac{(s - H_k y)(s - H_k y)^T}{(s - H_k y)^T y}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) So sánh độ ổn định của SR1 với BFGS.&lt;br /&gt;
b) Khi nào cập nhật SR1 thất bại?&lt;br /&gt;
c) Tính ma trận cập nhật SR1 cho dữ liệu từ Bài tập 1.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Độ ổn định:**

- **BFGS:** Luôn bảo toàn tính xác định dương khi điều kiện độ cong $$y^Ts &amp;gt; 0$$ được thỏa mãn.
- **SR1:** Có thể tạo ra ma trận suy biến (singular) hoặc không xác định (indefinite).

**b) SR1 gặp sự cố khi:**

$$(s - H_k y)^T y \approx 0$$, gây hiện tượng chia cho số gần $$0$$.

**Quy tắc bảo vệ:** Bỏ qua bước cập nhật nếu $$|(s - H_k y)^T y| &amp;lt; \epsilon \|s - H_k y\| \|y\|$$ (hoặc theo ngưỡng $$\epsilon \|s\| \|y\|$$).

---

**c) Tính cập nhật SR1:**

$$s - H_0 y = (-0.4, -0.3) - (-0.8, -2.4) = (0.4, 2.1)$$

$$(s - H_0 y)^T y = 0.4(-0.8) + 2.1(-2.4) = -0.32 - 5.04 = -5.36$$

$$H_1^{\text{SR1}} = I + \frac{1}{-5.36}\begin{bmatrix} 0.16 &amp;amp; 0.84 \\ 0.84 &amp;amp; 4.41 \end{bmatrix}$$

$$\approx \begin{bmatrix} 0.970 &amp;amp; -0.157 \\ -0.157 &amp;amp; 0.177 \end{bmatrix}$$

Ma trận này thỏa mãn phương trình secant $$H_1 y = s$$. Trong ví dụ cụ thể này, $$H_1^{\text{SR1}}$$ vẫn xác định dương (định thức xấp xỉ $$0.147 &amp;gt; 0$$), nhưng tổng quát SR1 **không** đảm bảo tính xác định dương vì mẫu số có thể âm hoặc tiến gần $$0$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-l-bfgs-cho-bài-toán-quy-mô-lớn&quot;&gt;📝 &lt;strong&gt;Bài tập 3: L-BFGS cho bài toán quy mô lớn&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;L-BFGS chỉ lưu trữ \(m\) cặp \((s, y)\) gần nhất thay vì toàn bộ ma trận \(H_k\) kích thước \(n \times n\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Trình bày thuật toán đệ quy hai vòng (two-loop recursion).&lt;br /&gt;
b) Viết tường minh cách tính \(H_k \nabla f\) với \(m = 2\) cặp lưu trữ.&lt;br /&gt;
c) Ước lượng bộ nhớ cần thiết khi \(n = 10^6\) và \(m = 10\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Thuật toán đệ quy hai vòng:**

```
q = ∇f(x_k)
for i = k-1, ..., k-m:
    α_i = ρ_i s_i^T q
    q = q - α_i y_i
r = H_0 q  (often H_0 = γI)
for i = k-m, ..., k-1:
    β = ρ_i y_i^T r
    r = r + s_i(α_i - β)
return r = H_k ∇f
```

---

**b) Minh họa với $$m = 2$$:**

Giả sử lưu hai cặp $$\{(s_1, y_1), (s_2, y_2)\}$$ với $$\rho_i = \frac{1}{y_i^T s_i}$$.

**Vòng lặp 1 (ngược):**

$$\alpha_2 = \rho_2 s_2^T \nabla f$$, $$q_1 = \nabla f - \alpha_2 y_2$$

$$\alpha_1 = \rho_1 s_1^T q_1$$, $$q_0 = q_1 - \alpha_1 y_1$$

**Khởi tạo:** $$r_0 = \gamma q_0$$

**Vòng lặp 2 (xuôi):**

$$\beta_1 = \rho_1 y_1^T r_0$$, $$r_1 = r_0 + s_1(\alpha_1 - \beta_1)$$

$$\beta_2 = \rho_2 y_2^T r_1$$, $$r_2 = r_1 + s_2(\alpha_2 - \beta_2)$$

Hướng giảm thu được: $$d = -r_2$$.

---

**c) Ước lượng bộ nhớ (dùng số thực 64-bit / 8 byte):**

- **BFGS đầy đủ:** $$n^2 = 10^{12}$$ phần tử $$\approx$$ **8 TB**.
- **L-BFGS:** $$2mn = 2 \cdot 10 \cdot 10^6 = 2 \times 10^7$$ phần tử $$\approx$$ **160 MB**.

Mức giảm bộ nhớ đạt **$$50{,}000\times$$**.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-tốc-độ-hội-tụ&quot;&gt;📝 &lt;strong&gt;Bài tập 4: Tốc độ hội tụ&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Phương pháp Newton: \(\|x^{(k+1)} - x^*\| \leq C\|x^{(k)} - x^*\|^2\) (hội tụ bậc hai).&lt;br /&gt;
b) Phương pháp BFGS: tốc độ hội tụ tương ứng thuộc loại nào?&lt;br /&gt;
c) So sánh số vòng lặp ước lượng giữa GD, BFGS và Newton.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Phương pháp Newton:**

Hội tụ **bậc hai** ($$p = 2$$), với hằng số $$C \approx \frac{1}{2} \|\nabla^2 f(x^*)^{-1}\| \|\nabla^3 f(x^*)\|$$.

Số vòng lặp cần thiết trong vùng hội tụ cục bộ tỉ lệ với $$\log\log(1/\epsilon)$$.

---

**b) Phương pháp BFGS:**

Hội tụ **siêu tuyến tính** (nhanh hơn hội tụ tuyến tính nhưng chậm hơn hội tụ bậc hai), nghĩa là:

$$\lim_{k \to \infty} \frac{\|x^{(k+1)} - x^*\|}{\|x^{(k)} - x^*\|} = 0$$

---

**c) So sánh số vòng lặp minh họa (để đạt độ chính xác $$10^{-10}$$):**

| Phương pháp | Tốc độ hội tụ | Số vòng lặp ước lượng |
|--------|------|------------|
| GD | Tuyến tính ($$0.9^k$$) | ~230 |
| BFGS | Siêu tuyến tính | ~15 |
| Newton | Bậc hai | ~5 |

BFGS đạt sự cân bằng tốt giữa chi phí mỗi vòng lặp và tốc độ hội tụ.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-các-chi-tiết-cài-đặt-thực-tế&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Các chi tiết cài đặt thực tế&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Khi nào nên bỏ qua bước cập nhật BFGS?&lt;br /&gt;
b) Cách chọn hệ số co giãn cho ma trận khởi đầu \(H_0\).&lt;br /&gt;
c) Yêu cầu đối với thuật toán tìm kiếm theo đường thẳng (line search).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Bỏ qua bước cập nhật khi:**

$$y^Ts \leq \epsilon_s \|s\|^2$$ (vi phạm điều kiện độ cong).

**Lý do:** Đảm bảo ma trận xấp xỉ luôn xác định dương và tránh mất ổn định số học.

---

**b) Xấp xỉ Hessian khởi đầu:**

$$H_0 = \gamma I$$ với $$\gamma = \frac{y_{k-1}^T s_{k-1}}{y_{k-1}^T y_{k-1}}$$.

Hệ số co giãn thích nghi này phản ánh tỷ lệ độ cong cục bộ từ bước lặp gần nhất.

---

**c) Yêu cầu tìm kiếm theo đường thẳng:**

Sử dụng **điều kiện Wolfe mạnh (Strong Wolfe conditions)**:

1. $$f(x + \alpha d) \leq f(x) + c_1 \alpha \nabla f^T d$$ (điều kiện giảm đủ)
2. $$|\nabla f(x + \alpha d)^T d| \leq c_2 |\nabla f^T d|$$ (điều kiện độ cong)

Thường chọn $$c_1 = 10^{-4}$$ và $$c_2 = 0.9$$. Điều kiện này đảm bảo $$y^Ts &amp;gt; 0$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Bộ nhớ&lt;/th&gt;
      &lt;th&gt;Tốc độ hội tụ&lt;/th&gt;
      &lt;th&gt;Phù hợp với&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Newton&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\)&lt;/td&gt;
      &lt;td&gt;Bậc hai&lt;/td&gt;
      &lt;td&gt;Bài toán kích thước nhỏ (\(n\) nhỏ)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;BFGS&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\)&lt;/td&gt;
      &lt;td&gt;Siêu tuyến tính&lt;/td&gt;
      &lt;td&gt;Bài toán kích thước trung bình&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;L-BFGS&lt;/td&gt;
      &lt;td&gt;\(O(mn)\)&lt;/td&gt;
      &lt;td&gt;Siêu tuyến tính&lt;/td&gt;
      &lt;td&gt;Bài toán quy mô lớn (\(n\) lớn)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SR1&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\)&lt;/td&gt;
      &lt;td&gt;Siêu tuyến tính&lt;/td&gt;
      &lt;td&gt;Chấp nhận Hessian không xác định dương&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Nocedal, J., &amp;amp; Wright, S. J. (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt;. Springer. Chapter 6.&lt;/li&gt;
  &lt;li&gt;Liu, D. C., &amp;amp; Nocedal, J. (1989). “On the Limited Memory BFGS Method”.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>18-07 BFGS Bộ nhớ Hạn chế (LBFGS)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_07_Limited_Memory_BFGS_(LBFGS)/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_07_Limited_Memory_BFGS_(LBFGS)</id>
   <content type="html">&lt;p&gt;Khi số biến \(n\) vượt ngưỡng vài chục nghìn hay vài triệu (như trong hồi quy logistic nhiều đặc trưng, mạng nơ-ron vật lý PINN hay tái tạo ảnh y tế), ngay cả việc lưu trữ một ma trận \(H_k\) dày đặc kích thước \(n \times n\) cũng trở nên bất khả thi vì tràn bộ nhớ RAM. &lt;strong&gt;L-BFGS&lt;/strong&gt; (Nocedal, 1980) giải quyết triệt để nút thắt này bằng một nhận xét xuất sắc: ta &lt;strong&gt;không bao giờ cần tạo ra ma trận \(H_k\) tường minh&lt;/strong&gt; — ta chỉ cần lưu đúng \(m\) cặp vector gần nhất \((s_i, y_i)\) (thường \(m = 5\text{–}20\)) rồi chạy một &lt;strong&gt;vòng lặp hai chiều (two-loop recursion)&lt;/strong&gt; để tính thẳng tích \(H_k \nabla f(x_k)\) chỉ trong \(O(mn)\) phép toán!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-l-bfgs-và-thuật-toán-hai-vòng-lặp&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của L-BFGS và thuật toán hai vòng lặp&lt;/h2&gt;

&lt;p&gt;Để hiểu rõ cách L-BFGS giữ lại gần như trọn vẹn sức mạnh của BFGS với bộ nhớ tí hon, hãy nắm vững bốn ý tưởng sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quên có chọn lọc (Sliding Window of Curvature Pairs):&lt;/strong&gt; Chỉ giữ lại \(m\) cặp \((s_i, y_i)\) gần nhất và loại bỏ các cặp cũ. Điều này không chỉ giảm bộ nhớ từ \(O(n^2)\) xuống \(O(mn)\) mà còn giúp loại bỏ thông tin độ cong đã lỗi thời ở xa điểm lặp hiện tại.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khởi tạo tỉ lệ động \(H_k^0 = \gamma_k I\):&lt;/strong&gt; Ở mỗi vòng lặp, thay vì bắt đầu từ ma trận đơn vị \(I\), L-BFGS chọn hệ số tỉ lệ \(\gamma_k = \frac{s_{k-1}^T y_{k-1}}{y_{k-1}^T y_{k-1}}\) phản ánh quy mô độ cong cục bộ gần nhất, giúp bước đơn vị \(t = 1\) được chấp nhận gần như ngay lập tức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán đệ quy hai vòng lặp (Two-Loop Recursion):&lt;/strong&gt; Khai triển đệ quy công thức BFGS hai bên \(H^+ = V^T H V + \rho s s^T\) cho phép tính trực tiếp vector \(r = H_k q\) qua một vòng lặp đi lùi (từ mới nhất về cũ nhất) và một vòng lặp đi tới (từ cũ nhất lên mới nhất), chỉ dùng tích vô hướng và cộng vector!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ tuyến tính mạnh (Strong Linear Convergence):&lt;/strong&gt; Dù không đạt hội tụ siêu tuyến tính như BFGS đầy đủ (vì bộ nhớ hữu hạn \(m\) không tích lũy đủ toàn bộ phổ độ cong khi \(n \gg m\)), L-BFGS vẫn hội tụ nhanh vượt trội so với hạ gradient và là thuật toán bậc nhất–giả bậc hai tin cậy bậc nhất cho tối ưu quy mô lớn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-thuật-toán-two-loop-recursion-với-m--1-và-kiểm-chứng-khớp-tuyệt-đối&quot;&gt;Giải thích: Chạy tay thuật toán Two-Loop Recursion với \(m = 1\) và kiểm chứng khớp tuyệt đối&lt;/h3&gt;

&lt;p&gt;Giả sử ta chỉ lưu \(m = 1\) cặp lịch sử \(s_0 = (1, 0)^T, y_0 = (2, 1)^T\) (\(\rho_0 = \frac{1}{y_0^T s_0} = \frac{1}{2} = 0.5\)), và cần tính tích \(r = H_1 q\) tại vector gradient hiện tại \(q = (4, 2)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 1 (đi lùi — cập nhật \(q\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tính \(\alpha_0 = \rho_0 (s_0^T q) = 0.5 \times [(1)(4) + (0)(2)] = 2.0\).&lt;/li&gt;
      &lt;li&gt;Cập nhật \(q \leftarrow q - \alpha_0 y_0 = \begin{bmatrix} 4 \\ 2 \end{bmatrix} - 2.0\begin{bmatrix} 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước tỉ lệ khởi tạo \(r = H_1^0 q = \gamma_1 q\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hệ số tỉ lệ \(\gamma_1 = \frac{s_0^T y_0}{y_0^T y_0} = \frac{2}{2^2 + 1^2} = 0.4\).&lt;/li&gt;
      &lt;li&gt;Nhân tỉ lệ: \(r = 0.4 \times (0, 0)^T = (0, 0)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp 2 (đi tới — khôi phục \(r\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tính \(\beta_0 = \rho_0 (y_0^T r) = 0.5 \times 0 = 0\).&lt;/li&gt;
      &lt;li&gt;Cập nhật \(r \leftarrow r + (\alpha_0 - \beta_0) s_0 = \begin{bmatrix} 0 \\ 0 \end{bmatrix} + (2.0 - 0)\begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 2 \\ 0 \end{bmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng độc lập không cần thuật toán hai vòng lặp:&lt;/strong&gt; Để ý rằng \(q = (4, 2)^T = 2 y_0\)! Vì mọi ma trận BFGS \(H_1\) đều phải thỏa mãn phương trình secant \(H_1 y_0 = s_0\), ta chắc chắn phải có \(H_1 q = 2 H_1 y_0 = 2 s_0 = (2, 0)^T\) — trùng khớp hoàn toàn với kết quả two-loop recursion mà không hề phải lập ma trận \(H_1\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;giới-thiệu&quot;&gt;Giới thiệu&lt;/h1&gt;

&lt;p&gt;L-BFGS (Limited-memory BFGS) là đại diện tiêu biểu của lớp phương pháp Quasi-Newton bộ nhớ hạn chế, đặc biệt hữu ích khi chi phí tính toán hoặc lưu trữ ma trận Hessian dày đặc kích thước \(n \times n\) quá lớn. Thay vì lưu toàn bộ ma trận \(n \times n\), L-BFGS chỉ lưu một số ít vector \(n\)-chiều để biểu diễn ngầm xấp xỉ nghịch đảo Hessian.&lt;/p&gt;

&lt;p&gt;Như tên gọi, L-BFGS được xây dựng trực tiếp từ BFGS. Ý tưởng cốt lõi là chỉ sử dụng thông tin độ cong từ \(m\) vòng lặp gần nhất để xấp xỉ Hessian nghịch đảo, đồng thời loại bỏ thông tin từ các vòng lặp quá cũ — vừa tiết kiệm bộ nhớ, vừa tránh dùng thông tin độ cong đã không còn phản ánh đúng tính chất cục bộ tại điểm lặp hiện tại.&lt;/p&gt;

&lt;p&gt;Ngoài ra, phiên bản bộ nhớ hạn chế của các thuật toán Quasi-Newton khác (chẳng hạn SR1) cũng có thể được xây dựng theo cùng nguyên lý [14].&lt;/p&gt;

&lt;h1 id=&quot;l-bfgs&quot;&gt;L-BFGS&lt;/h1&gt;

&lt;p&gt;Để hiểu L-BFGS, trước hết nhắc lại phép cập nhật của BFGS ở mỗi vòng lặp:&lt;/p&gt;

&lt;blockquote&gt;
\[x^+ = x - t H \nabla f, \\\\
\text{trong đó } t \text{ là độ dài bước và } H \text{ được cập nhật theo công thức:}\\\\
\text{ }\\\\
H^+ = \big( I - \frac{sy^T}{y^Ts} \big) H \big( I - \frac{ys^T}{y^Ts} \big) + \frac{ss^T}{y^Ts}. \\\\\]
&lt;/blockquote&gt;

&lt;p&gt;Với cấu trúc trên, tích ma trận–vector \(H^+q\) (với \(q \in \mathbb{R}^n\)) có thể được tính chỉ bằng các phép tích vô hướng tạo thành các đại lượng vô hướng \(\alpha, \beta \in \mathbb{R}\) và các phép cộng vector theo \(p, s \in \mathbb{R}^n\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
H^+q &amp;amp;= \big( I - \frac{sy^T}{y^Ts} \big) H \big( I - \frac{ys^T}{y^Ts} \big)q + \frac{ss^Tq}{y^Ts}\\\\
&amp;amp;= \big( I - \frac{sy^T}{y^Ts} \big) \underbrace{H \big( q - \frac{s^T q}{y^Ts} y \big)}_{p} + \underbrace{\frac{s^Tq}{y^Ts}}_{\alpha} s\\\\
&amp;amp;= \big( I - \frac{sy^T}{y^Ts} \big) p + \alpha s\\\\
&amp;amp;= p - \underbrace{\frac{y^Tp}{y^Ts}}_{\beta}s + \alpha s \\\\
&amp;amp;= p + (\alpha - \beta) s, \\\\
&amp;amp; \text{trong đó } \alpha = \frac{s^Tq}{y^Ts}, \ q^+ = q - \alpha y, \ p = Hq^+, \ \beta = \frac{y^Tp}{y^Ts}.
\end{align} \\\\\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu \(H\) được hình thành sau \(k\) bước cập nhật BFGS, thì hướng bước \(-H\nabla f(x)\) có thể được tính trực tiếp với độ phức tạp \(O(kn)\) mà không cần tạo tường minh ma trận \(H\) (xem thuật toán đệ quy hai vòng bên dưới). Để tiết kiệm bộ nhớ khi \(k\) lớn, L-BFGS chỉ giữ lại thông tin độ cong từ \(m\) vòng lặp gần nhất (với \(k \ge m\)), đưa chi phí mỗi bước xuống \(O(mn)\).&lt;/p&gt;

&lt;h1 id=&quot;thuật-toán&quot;&gt;Thuật toán&lt;/h1&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter18/algorithm_quasi-newton.png&quot; alt=&quot;[Fig1] Thuật toán LBFGS [3]&quot; width=&quot;90%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Thuật toán LBFGS [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Ma trận xấp xỉ nghịch đảo Hessian \(H_k\) nhìn chung là ma trận dày đặc nên phép nhân ma trận trực tiếp rất tốn kém khi số biến lớn. L-BFGS tính trực tiếp tích \(H_k \nabla f_k\) thông qua chuỗi các tích vô hướng và phép cộng vector, khắc phục hoàn toàn nút thắt bộ nhớ và tính toán của \(H_k\).&lt;/p&gt;

&lt;p&gt;Trong thực hành, xấp xỉ khởi đầu \(H^{0, k}\) ở mỗi vòng lặp thường được chọn là bội số của ma trận đơn vị \(H^{0, k} = \gamma_k I\) — lựa chọn đơn giản nhưng đã được chứng minh rất hiệu quả ([14] mục 7.2):&lt;/p&gt;

&lt;blockquote&gt;
\[H^{0, k} = \gamma_k I, \\\\
\text{trong đó } \: \gamma_k = \frac{s^T_{k-1}y_{k-1}}{y^T_{k-1}y_{k-1}}.\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Hệ số co giãn \(\gamma_k\) (và do đó \(H^{0, k}\)) được cập nhật lại ở mỗi vòng lặp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;l-bfgs-trong-khoảng-3-phút&quot;&gt;L-BFGS trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/l-bfgs_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Vì sao BFGS tốn n² bộ nhớ, m cặp (s, y) và H₀ = γI, làm tay đệ quy hai vòng trong 2 chiều, rồi so sánh số bước trên hồi quy logistic.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>18-06 Hội tụ Siêu tuyến tính</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_06_Superlinear_convergence/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_06_Superlinear_convergence</id>
   <content type="html">&lt;p&gt;Phương pháp Quasi-Newton không hề tính đạo hàm bậc hai, vậy tại sao nó lại có thể bỏ xa hạ gradient (hội tụ tuyến tính) và tiến gần sát tốc độ của phương pháp Newton (hội tụ bậc hai)? Câu trả lời nằm ở &lt;strong&gt;hội tụ siêu tuyến tính (superlinear convergence)&lt;/strong&gt; và một định lý kiệt tác của Dennis và Moré (1974): để đạt hội tụ siêu tuyến tính, ta &lt;strong&gt;không cần&lt;/strong&gt; ma trận xấp xỉ \(B_k\) phải hội tụ về toàn bộ Hessian thực \(G(x^\star)\) — ta chỉ cần \(B_k\) xấp xỉ chính xác \(G(x^\star)\) &lt;strong&gt;dọc theo hướng bước đi \(p_k\)&lt;/strong&gt; là đủ!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-của-lý-thuyết-hội-tụ-siêu-tuyến-tính&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép của lý thuyết hội tụ siêu tuyến tính&lt;/h2&gt;

&lt;p&gt;Để đọc hiểu các giả thiết và Định lý Dennis–Moré trong bài, hãy đặt bốn khái niệm này vào đúng vị trí của chúng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hệ thang tốc độ hội tụ (Linear → Superlinear → Quadratic):&lt;/strong&gt; Hội tụ tuyến tính giữ tỉ số sai số \(\|e_{k+1}\| / \|e_k\| \le c &amp;lt; 1\) không đổi; hội tụ siêu tuyến tính đưa tỉ số đó về \(0\) khi \(k \to \infty\); còn hội tụ bậc hai đòi hỏi \(\|e_{k+1}\| \le M\|e_k\|^2\) (gấp đôi số chữ số đúng sau mỗi bước).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính liên tục Lipschitz của Hessian:&lt;/strong&gt; Đảm bảo độ cong thực không biến đổi đột ngột quanh nghiệm \(x^\star\), nhờ đó thông tin secant thu thập từ các bước gần nhất phản ánh trung thực ma trận \(G(x^\star)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện Wolfe hai vế (Armijo + Độ cong):&lt;/strong&gt; Đảm bảo đồng thời hai mục tiêu quan trọng: giá trị hàm giảm đủ (không nhảy quá lố) và \(y_k^T s_k &amp;gt; 0\) (không dừng quá non và giữ \(B_k \succ 0\)), đồng thời chấp nhận độ dài bước đơn vị \(t_k = 1\) khi đủ gần \(x^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý Dennis–Moré:&lt;/strong&gt; Khẳng định rằng bước \(x_{k+1} = x_k + p_k\) hội tụ siêu tuyến tính khi và chỉ khi \(\lim_{k \to \infty} \frac{\|(B_k - G(x^\star)) p_k\|}{\|p_k\|} = 0\) — tức \(B_k\) chỉ cần khớp \(G(x^\star)\) trên đúng hướng mà thuật toán đang đi!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-tốc-độ-giảm-sai-số-bằng-số-thực-và-kiểm-tra-tỉ-số-dennismoré&quot;&gt;Giải thích: So sánh tốc độ giảm sai số bằng số thực và kiểm tra tỉ số Dennis–Moré&lt;/h3&gt;

&lt;p&gt;Hãy quan sát sự khác biệt kịch tính giữa ba tốc độ hội tụ cùng xuất phát từ sai số ban đầu \(e_0 = 0.5\) sau 5 vòng lặp:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Vòng lặp \(k\)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Tuyến tính (\(e_{k+1} = 0.5 e_k\))&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Siêu tuyến tính (\(e_{k+1} = e_k^{1.5}\))&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Bậc hai (\(e_{k+1} = e_k^2\))&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.500000\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.500000\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.500000\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(1\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.250000\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.353553\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.250000\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(2\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.125000\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.210224\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.062500\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(3\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.062500\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.096385\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.003906\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(4\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.031250\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.029924\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(1.5 \times 10^{-5}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(5\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.015625\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0.005177\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(2.3 \times 10^{-10}\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Và đây là phép kiểm tra trực giác cho &lt;strong&gt;Định lý Dennis–Moré&lt;/strong&gt;: giả sử \(G(x^\star) = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 10 \end{bmatrix}\), ma trận xấp xỉ \(B_k = \begin{bmatrix} 2 + 10^{-3} &amp;amp; 0 \\ 0 &amp;amp; 99 \end{bmatrix}\) (sai lệch khổng lồ ở thành phần thứ hai: \(99\) so với \(10\)!), nhưng hướng bước đi hiện tại là \(p_k = (1, \; 10^{-5})^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính tử số:&lt;/strong&gt; \((B_k - G(x^\star))p_k = \begin{bmatrix} 10^{-3} &amp;amp; 0 \\ 0 &amp;amp; 89 \end{bmatrix}\begin{bmatrix} 1 \\ 10^{-5} \end{bmatrix} = \begin{bmatrix} 10^{-3} \\ 8.9 \times 10^{-4} \end{bmatrix}\), có chuẩn \(\approx 1.34 \times 10^{-3}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chia cho \(\|p_k\| \approx 1\):&lt;/strong&gt; Tỉ số Dennis–Moré chỉ khoảng \(0.00134 \ll 1\)! Dù \(B_k\) ước lượng sai hoàn toàn độ cong dọc trục \(x_2\), thuật toán vẫn thực hiện một bước đi gần như hoàn hảo giống bước Newton vì \(p_k\) hầu như nằm dọc trục \(x_1\) — nơi \(B_k\) đã học chính xác!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;giả-thiết-1&quot;&gt;Giả thiết 1:&lt;/h1&gt;
&lt;blockquote&gt;
  &lt;p&gt;Ma trận Hessian \(G\) liên tục Lipschitz tại \(x^*\), nghĩa là tồn tại hằng số dương \(L\) sao cho:
\(\| G(x) - G(x^*) \| \le L \| x - x^* \|\)
với mọi \(x\) đủ gần \(x^*\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;giả-thiết-2-điều-kiện-wolfe&quot;&gt;Giả thiết 2: Điều kiện Wolfe&lt;/h1&gt;
&lt;blockquote&gt;
  &lt;p&gt;Giả sử độ dài bước \(t\) được chọn (thông qua tìm kiếm theo đường thẳng) sao cho thỏa mãn đồng thời hai bất đẳng thức:
\(f(x + tp) \le f(x) + \alpha_1 t \nabla f(x)^T p\)
và
\(\nabla f(x + tp)^T p \ge \alpha_2 \nabla f(x)^T p\)
với \(0 &amp;lt; \alpha_1 &amp;lt; \alpha_2 &amp;lt; 1\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Điều kiện Wolfe thứ nhất (điều kiện giảm đủ) đảm bảo độ dài bước \(t\) không quá lớn.&lt;/li&gt;
  &lt;li&gt;Điều kiện Wolfe thứ hai (điều kiện độ cong) đảm bảo độ dài bước \(t\) không quá nhỏ.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dưới hai giả thiết trên, cả DFP và BFGS đều đạt tốc độ hội tụ siêu tuyến tính (tham khảo: &lt;a href=&quot;https://en.wikipedia.org/wiki/Rate_of_convergence&quot;&gt;Tốc độ hội tụ trên Wikipedia&lt;/a&gt;):&lt;/p&gt;

&lt;blockquote&gt;
\[\lim_{k \rightarrow \infty} \frac{ \| x^{k+1} - x^\ast \| }{ \| x^k - x^\ast \| } = 0.\]
&lt;/blockquote&gt;

&lt;h1 id=&quot;định-lý-dennismoré&quot;&gt;Định lý Dennis–Moré&lt;/h1&gt;

&lt;p&gt;Định lý Dennis–Moré cung cấp điều kiện đủ (và cần) cho hướng tìm kiếm của phương pháp Quasi-Newton đạt hội tụ siêu tuyến tính khi hướng đó tiệm cận đủ sát hướng Newton gần nghiệm [14]:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Giả sử \(f\) khả vi liên tục hai lần, dãy \(x^k \rightarrow x^\ast\) với \(\nabla f(x^\ast) = 0\) và \(\nabla^2 f(x^\ast)\) xác định dương. Xét điều kiện:&lt;/p&gt;

\[\lim_{k \rightarrow \infty} \frac{\| \nabla f(x^k) + \nabla^2 f(x^k) p^k \| }{\| p^k \|} = 0.\]

  &lt;p&gt;Nếu hướng tìm kiếm \(p^k\) thỏa mãn điều kiện trên, thì tồn tại chỉ số \(k_0\) sao cho:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Với mọi \(k \ge k_0\), độ dài bước đơn vị \(t_k = 1\) thỏa mãn điều kiện Wolfe.&lt;/li&gt;
    &lt;li&gt;Khi chọn \(t_k = 1\) với mọi \(k \ge k_0\), dãy \(x^k\) hội tụ siêu tuyến tính về \(x^\ast\).&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>18-05 Lớp Broyden</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_05_The_Broyden_Class/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_05_The_Broyden_Class</id>
   <content type="html">&lt;p&gt;Sau khi thấy SR1, DFP và BFGS lần lượt xuất hiện với những công thức trông vừa giống vừa khác nhau, một câu hỏi rất tự nhiên của người làm toán là: &lt;em&gt;chúng là ba thuật toán rời rạc, hay thực ra chỉ là ba điểm nằm trên cùng một đường thẳng?&lt;/em&gt; Câu trả lời của Charles Broyden là một bức tranh thống nhất tuyệt đẹp: mọi tổ hợp affine \((1 - \phi) B^+_{\text{BFGS}} + \phi B^+_{\text{DFP}}\) đều tạo thành một họ duy nhất gọi là &lt;strong&gt;lớp Broyden&lt;/strong&gt;, trong đó BFGS (\(\phi=0\)), DFP (\(\phi=1\)) và thậm chí cả SR1 đều chỉ là những điểm đặc biệt trên cùng một trục tham số \(\phi\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bức-tranh-thống-nhất-của-lớp-broyden&quot;&gt;Kiến thức cần nhớ: Bức tranh thống nhất của lớp Broyden&lt;/h2&gt;

&lt;p&gt;Ba ý tưởng dưới đây giúp bạn nắm trọn ý nghĩa hình học và lý thuyết hội tụ của lớp Broyden:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp affine bảo toàn phương trình secant:&lt;/strong&gt; Vì cả \(B^+_{\text{BFGS}}\) và \(B^+_{\text{DFP}}\) đều đối xứng và thỏa mãn \(B^+ s = y\), nên mọi tổ hợp \((1-\phi) B^+_{\text{BFGS}} + \phi B^+_{\text{DFP}}\) với \(\phi \in \mathbb{R}\) tự động kế thừa tính đối xứng và phương trình secant.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lớp Broyden hạn chế (\(\phi \in [0, 1]\)):&lt;/strong&gt; Khi \(\phi \in [0, 1]\), ma trận \(B^+\) là tổ hợp lồi của hai ma trận xác định dương nên &lt;strong&gt;luôn bảo toàn tính xác định dương&lt;/strong&gt; dưới điều kiện \(y^T s &amp;gt; 0\). Mọi phương pháp trong lớp hạn chế đều có tính bất biến đáng kinh ngạc: trên hàm bậc hai với tìm kiếm đường thẳng chính xác, chúng sinh ra &lt;strong&gt;cùng một dãy điểm lặp&lt;/strong&gt; \(x_k\) (định lý Dixon, 1972)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SR1 nằm ngoài đoạn \([0, 1]\):&lt;/strong&gt; Tham số \(\phi_{\text{SR1}} = \frac{y^T s}{y^T s - s^T B s}\) có thể nhỏ hơn \(0\) hoặc lớn hơn \(1\) (thậm chí tiến tới vô cùng khi \(y^T s = s^T B s\)). Đó chính là lý do sâu xa giải thích vì sao SR1 không đảm bảo giữ được tính xác định dương như lớp hạn chế.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-nội-suy-trực-tiếp-trên-trục-phi-nối-bfgs-dfp-và-sr1&quot;&gt;Giải thích: Nội suy trực tiếp trên trục \(\phi\) nối BFGS, DFP và SR1&lt;/h3&gt;

&lt;p&gt;Tiếp nối đúng hai ma trận ta vừa tính tay ở Bài 18-03 và 18-04 với \(B_0 = I, s = (1, 0)^T, y = (2, 1)^T\) (\(s^T B_0 s = 1, y^T s = 2\)):&lt;/p&gt;

\[B_1^{\text{BFGS}} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix}, \qquad B_1^{\text{DFP}} = (H_1^{\text{DFP}})^{-1} = \frac{1}{0.4}\begin{bmatrix} 0.8 &amp;amp; 0.4 \\ 0.4 &amp;amp; 0.7 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.75 \end{bmatrix}.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính công thức tổng quát lớp Broyden theo \(\phi\):&lt;/strong&gt;
\(B_1(\phi) = (1 - \phi)\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix} + \phi\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.75 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 + 0.25\phi \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử điểm giữa lớp hạn chế (\(\phi = 0.5\)):&lt;/strong&gt;
\(B_1(0.5) = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.625 \end{bmatrix}, \qquad \det = 3.25 - 1 = 2.25 &amp;gt; 0 \quad (\text{xác định dương}).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử thay công thức tham số SR1:&lt;/strong&gt;
\(\phi_{\text{SR1}} = \frac{y^T s}{y^T s - s^T B_0 s} = \frac{2}{2 - 1} = 2.\)
Thay \(\phi = 2\) vào \(B_1(\phi)\) ta được:
\(B_1(2) = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 + 0.25(2) \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng độc lập bằng công thức SR1 gốc:&lt;/strong&gt; Với \(y - B_0 s = (1, 1)^T\) và \((y - B_0 s)^T s = 1\), công thức SR1 cho \(B_1^{\text{SR1}} = I + \frac{1}{1}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}\) — trùng khớp từng phần tử một! Và nhìn vào \(1.5 + 0.25\phi\), bạn cũng thấy ngay nếu \(\phi \le -4\) thì \(\det(B_1(\phi)) \le 0\), ma trận sẽ mất tính xác định dương.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Lớp Broyden (Broyden class) là họ công thức tổng quát hóa cả BFGS, DFP và SR1 theo biểu thức tổ hợp tuyến tính sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; \(B^+_{\text{BFGS}}\) và \(B^+_{\text{DFP}}\) lần lượt ký hiệu ma trận \(B^+\) thu được từ công thức cập nhật BFGS và DFP.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[B^+ = (1 - \phi)B^+_{\text{BFGS}} + \phi B^+_{\text{DFP}}, \text{ với } \phi \in \mathbb{R}.\]
&lt;/blockquote&gt;

&lt;p&gt;Đặt \(v = \frac{y}{y^Ts} - \frac{Bs}{s^TBs}\), công thức trên có thể viết lại thành:&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = B - \frac{Bss^TB}{s^TBs} + \frac{yy^T}{y^Ts} + \phi(s^TBs)vv^T.\]
&lt;/blockquote&gt;

&lt;p&gt;Nhận xét:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Khi \(\phi = 0\), công thức trùng với cập nhật BFGS.&lt;/li&gt;
  &lt;li&gt;Khi \(\phi = 1\), công thức trùng với cập nhật DFP.&lt;/li&gt;
  &lt;li&gt;Khi \(\phi = \frac{y^Ts}{y^Ts - s^TBs}\), công thức trùng với cập nhật SR1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tham khảo:&lt;/strong&gt; Trường hợp giới hạn tham số \(\phi \in [0, 1]\) được gọi là &lt;strong&gt;lớp Broyden hạn chế (restricted Broyden class)&lt;/strong&gt; [14].&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>18-04 Cập nhật Broyden-Fletcher-Goldfarb-Shanno (BFGS)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_04_Broyden_Fletcher_Goldfarb_Shanno_(BFGS)_update/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_04_Broyden_Fletcher_Goldfarb_Shanno_(BFGS)_update</id>
   <content type="html">&lt;p&gt;Năm 1970, một sự trùng hợp kỳ diệu xảy ra trong lịch sử tối ưu hóa: bốn nhà toán học — Charles Broyden, Roger Fletcher, Donald Goldfarb và David Shanno — đã độc lập công bố cùng một công thức cập nhật chỉ trong vòng vài tháng! Họ đơn giản chỉ hoán đổi vai trò của \(B\) và \(H\) trong công thức DFP, đặt bài toán “thay đổi ít nhất” lên ma trận nghịch đảo \(H^+\) thay vì \(B^+\). Thế nhưng sự hoán đổi tưởng chừng đối xứng hoàn toàn ấy lại tạo ra &lt;strong&gt;thuật toán Quasi-Newton thành công nhất mọi thời đại&lt;/strong&gt;: BFGS tự hiệu chỉnh sai số độ cong vượt trội hơn hẳn DFP và vẫn là bộ giải mặc định trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.optimize&lt;/code&gt; suốt hơn nửa thế kỷ.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-vì-sao-bfgs-trở-thành-tiêu-chuẩn-vàng-của-tối-ưu-hóa-trơn&quot;&gt;Kiến thức cần nhớ: Vì sao BFGS trở thành tiêu chuẩn vàng của tối ưu hóa trơn?&lt;/h2&gt;

&lt;p&gt;Bốn trụ cột sau giải thích sức mạnh cả về đại số lẫn thực nghiệm của công thức BFGS:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu cấu trúc với DFP:&lt;/strong&gt; Công thức BFGS cho \(B^+\) có dạng y hệt công thức DFP cho \(H^+\) (chỉ đổi \(H \leftrightarrow B, s \leftrightarrow y\)), và ngược lại công thức BFGS cho \(H^+\) là dạng nhân hai bên \((I - \rho s y^T) H (I - \rho y s^T) + \rho s s^T\) với \(\rho = 1/(y^T s)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bảo toàn tính xác định dương miễn là \(y^T s &amp;gt; 0\):&lt;/strong&gt; Viết \(z^T H^+ z = [(I - \rho y s^T)z]^T H [(I - \rho y s^T)z] + \rho (s^T z)^2\) cho thấy ngay tổng hai số hạng không âm chỉ bằng \(0\) khi \(z = 0\) (vì \(H \succ 0\) và \(\rho &amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả năng tự hiệu chỉnh (Self-Correcting Property):&lt;/strong&gt; Khi xấp xỉ Hessian \(B_k\) dự đoán độ cong quá lớn (hoặc \(H_k\) có trị riêng quá nhỏ làm bước đi bị kẹt), BFGS tự động sửa lại trị riêng xấu chỉ sau vài vòng lặp dưới tìm kiếm đường thẳng không chính xác, trong khi DFP có thể ì ạch rất lâu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nền tảng cho L-BFGS quy mô lớn:&lt;/strong&gt; Dạng nhân hai bên \(H^+ = V^T H V + \rho s s^T\) cho phép khai triển đệ quy \(H_k \nabla f_k\) mà không cần lưu ma trận \(n \times n\) — chìa khóa trực tiếp dẫn sang L-BFGS ở bài 18-07.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-một-bước-bfgs-trên-đúng-dữ-liệu-bài-dfp-và-so-sánh-trực-tiếp&quot;&gt;Giải thích: Tính tay một bước BFGS trên đúng dữ liệu bài DFP và so sánh trực tiếp&lt;/h3&gt;

&lt;p&gt;Dùng lại đúng dữ liệu ở bài 18-03: \(B_0 = H_0 = I\), \(s = (1, 0)^T\), \(y = (2, 1)^T\) (\(y^T s = 2 \implies \rho = 0.5\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(B_1\) theo công thức BFGS:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ta có \(s^T B_0 s = 1\), \(B_0 s = (1, 0)^T\).&lt;/li&gt;
      &lt;li&gt;
\[B_1 = I - \frac{(B_0 s)(B_0 s)^T}{s^T B_0 s} + \frac{yy^T}{y^T s} = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} - \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} + \frac{1}{2}\begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix}.\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng phương trình secant và tính xác định dương:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(B_1 s = (2, 1)^T = y\) — khớp chính xác!&lt;/li&gt;
      &lt;li&gt;\(\det(B_1) = (2)(1.5) - 1 = 2 &amp;gt; 0\), vết \(= 3.5 &amp;gt; 0 \implies B_1 \succ 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(H_1\) trực tiếp bằng công thức BFGS hai bên và đối chiếu với \(B_1^{-1}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ma trận \(V = I - \rho s y^T = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} - 0.5\begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 0 &amp;amp; -0.5 \\ 0 &amp;amp; 1 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;
\[H_1 = V I V^T + 0.5 s s^T = \begin{bmatrix} 0.25 &amp;amp; -0.5 \\ -0.5 &amp;amp; 1 \end{bmatrix} + \begin{bmatrix} 0.5 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 0.75 &amp;amp; -0.5 \\ -0.5 &amp;amp; 1 \end{bmatrix}.\]
      &lt;/li&gt;
      &lt;li&gt;Nhân thử kiểm chứng: \(B_1 H_1 = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix}\begin{bmatrix} 0.75 &amp;amp; -0.5 \\ -0.5 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} = I\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh với DFP:&lt;/strong&gt; Trên cùng dữ liệu, DFP cho \(H_1^{\text{DFP}} = \begin{bmatrix} 0.7 &amp;amp; -0.4 \\ -0.4 &amp;amp; 0.8 \end{bmatrix}\) (tức \(B_1^{\text{DFP}} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.75 \end{bmatrix}\)), còn BFGS cho \(B_1^{\text{BFGS}} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix}\) — hai ma trận chỉ khác nhau ở phần tử góc dưới bên phải, chính là hướng vuông góc với \(s\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Ý tưởng của cập nhật BFGS hoàn toàn tương tự DFP, chỉ khác ở chỗ vai trò của \(B\) và \(H\) được hoán đổi cho nhau. Công thức BFGS được suy ra bằng cách giải bài toán tối ưu sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Giải bài toán:
\(\begin{align}
&amp;amp; \min_{H^+} \: \: &amp;amp;&amp;amp; {\|W^{1/2} (H^+ - H) W^{1/2} \|_F} \\\\
&amp;amp; \text{thỏa mãn } &amp;amp;&amp;amp; {H^+ = (H^+)^T} \\\\
   &amp;amp;&amp;amp;&amp;amp; {H^+y = s}  \\\\
&amp;amp; \text{trong đó } &amp;amp;&amp;amp; W \in \mathbb{R}^{n \; \times \;n} \text{ là ma trận đối xứng xác định dương thỏa mãn } Ws_k = y_k.
\end{align}\\\\\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Từ đây, ta thu được công thức cập nhật cho \(B\) và \(H\):&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = B - \frac{Bss^TB}{s^TBs} + \frac{yy^T}{y^Ts}\]
&lt;/blockquote&gt;

&lt;p&gt;và&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
H^+ &amp;amp;= H + \frac{(s-Hy)s^T}{y^Ts} + \frac{s(s-Hy)^T}{y^Ts} - \frac{(s-Hy)^Ty}{(y^Ts)^2} ss^T\\\\
&amp;amp;= \big( I - \frac{sy^T}{y^Ts} \big) H \big( I - \frac{ys^T}{y^Ts} \big) + \frac{ss^T}{y^Ts}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tương tự DFP, BFGS bảo toàn tính xác định dương: nếu \(B \succ 0\) và điều kiện độ cong \(s^Ty &amp;gt; 0\) được thỏa mãn, thì \(B^+ \succ 0\) (và tương ứng \(H \succ 0 \Rightarrow H^+ \succ 0\)).&lt;/p&gt;

&lt;p&gt;Ưu điểm nổi bật của BFGS là &lt;strong&gt;khả năng tự hiệu chỉnh (self-correcting)&lt;/strong&gt;: nếu ma trận \(H\) ở một vòng lặp là xấp xỉ kém của Hessian nghịch đảo, các bước cập nhật tiếp theo có thể nhanh chóng điều chỉnh lại sai lệch này. Trong khi đó, DFP kém hiệu quả hơn nhiều trong việc tự hiệu chỉnh xấp xỉ Hessian kém, nên trên thực tế BFGS thường cho hiệu năng vượt trội hơn [14].&lt;/p&gt;

&lt;h3 id=&quot;bfgs-so-với-gradient-descent-video&quot;&gt;BFGS so với gradient descent (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/bfgs-vs-gd_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;BFGS chỉ dùng thông tin gradient để dựng dần ma trận xấp xỉ Hessian nghịch đảo \(H\), giúp bước đi \(-H\nabla f\) tiệm cận hướng Newton mà không cần tính trực tiếp Hessian.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-bfgs-so-với-gradient-descent&quot;&gt;Tự tay thử: BFGS so với gradient descent&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;bfgs&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>18-03 Cập nhật Davidon-Fletcher-Powell (DFP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_03_Davidon_Fletcher_Powell_(DFP)_Update/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_03_Davidon_Fletcher_Powell_(DFP)_Update</id>
   <content type="html">&lt;p&gt;Vì cập nhật hạng 1 (SR1) không đủ bậc tự do để vừa khớp phương trình secant vừa luôn bảo toàn tính xác định dương, W. C. Davidon (1959) — sau đó được R. Fletcher và M. J. D. Powell (1963) làm sáng tỏ và phổ biến — đã chuyển sang &lt;strong&gt;cập nhật đối xứng hạng 2&lt;/strong&gt; trực tiếp trên ma trận nghịch đảo Hessian \(H = B^{-1}\). Công thức DFP mở ra một bước ngoặt lịch sử: chỉ cần điều kiện độ cong \(y^T s &amp;gt; 0\) được giữ vững, ma trận \(H^+\) &lt;strong&gt;luôn luôn&lt;/strong&gt; xác định dương, đảm bảo hướng tìm kiếm \(-H^+ \nabla f\) không bao giờ đi ngược lên dốc!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-góc-nhìn-giúp-hiểu-trọn-vẹn-công-thức-dfp&quot;&gt;Kiến thức cần nhớ: Bốn góc nhìn giúp hiểu trọn vẹn công thức DFP&lt;/h2&gt;

&lt;p&gt;Thay vì học thuộc lòng hai phân số trong công thức DFP, hãy nhìn bản chất hình học và biến phân đằng sau nó:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật trực tiếp nghịch đảo Hessian \(H^+ = H + auu^T + bvv^T\):&lt;/strong&gt; Chọn hai hướng tự nhiên nhất là \(u = s\) (bước đi thực tế) và \(v = Hy\) (bước đi mà xấp xỉ cũ \(H\) dự đoán) cho phép trừ đi phần sai lệch cũ \(-\frac{Hyy^T H}{y^T H y}\) và cộng vào thông tin độ cong mới \(+\frac{ss^T}{y^T s}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bảo toàn tính xác định dương (Hereditary Positive Definiteness):&lt;/strong&gt; Nhờ bất đẳng thức Cauchy–Schwarz trên tích vô hướng cảm sinh bởi \(H \succ 0\), nếu \(y^T s &amp;gt; 0\) thì \(z^T H^+ z &amp;gt; 0\) với mọi \(z \ne 0\). Không còn nỗi lo hướng đi bị đảo dấu như ở SR1!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải biến phân (Minimum-Change Principle):&lt;/strong&gt; Công thức DFP cho \(B^+\) thực chất là nghiệm duy nhất của bài toán tìm ma trận đối xứng \(B^+\) thỏa mãn \(B^+ s = y\) có khoảng cách chuẩn Frobenius có trọng số \(\|W^{1/2}(B^+ - B)W^{1/2}\|_F\) nhỏ nhất — tức “sửa đổi \(B\) ít nhất có thể”.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hạn chế thực nghiệm so với BFGS:&lt;/strong&gt; Dù đẹp về lý thuyết, DFP nhạy cảm hơn với tìm kiếm đường thẳng không chính xác (inexact line search) và đôi khi bị kẹt khi xấp xỉ Hessian sinh ra trị riêng quá nhỏ — lý do mà BFGS dần thay thế nó ở bài tiếp theo.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-một-bước-dfp-cho-h-và-kiểm-tra-h-y--s&quot;&gt;Giải thích: Tính tay một bước DFP cho \(H\) và kiểm tra \(H^+ y = s\)&lt;/h3&gt;

&lt;p&gt;Khởi tạo \(H_0 = I = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\) với cặp bước đi và biến thiên gradient \(s = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\), \(y = \begin{bmatrix} 2 \\ 1 \end{bmatrix}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện độ cong và tính các đại lượng vô hướng:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(y^T s = (2)(1) + (1)(0) = 2 &amp;gt; 0\) (đảm bảo \(H_1 \succ 0\)!).&lt;/li&gt;
      &lt;li&gt;\(H_0 y = y = (2, 1)^T \implies y^T H_0 y = 2^2 + 1^2 = 5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hai số hạng hiệu chỉnh hạng 1:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Số hạng trừ: \(-\frac{(H_0 y)(H_0 y)^T}{y^T H_0 y} = -\frac{1}{5}\begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} -0.8 &amp;amp; -0.4 \\ -0.4 &amp;amp; -0.2 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;Số hạng cộng: \(+\frac{ss^T}{y^T s} = +\frac{1}{2}\begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 0.5 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cộng vào \(H_0 = I\) để thu được \(H_1\):&lt;/strong&gt;
\(H_1 = \begin{bmatrix} 1 - 0.8 + 0.5 &amp;amp; 0 - 0.4 + 0 \\ 0 - 0.4 + 0 &amp;amp; 1 - 0.2 + 0 \end{bmatrix} = \begin{bmatrix} 0.7 &amp;amp; -0.4 \\ -0.4 &amp;amp; 0.8 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng phương trình secant ngược \(H_1 y = s\) và tính xác định dương:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(H_1 y = \begin{bmatrix} 0.7 &amp;amp; -0.4 \\ -0.4 &amp;amp; 0.8 \end{bmatrix}\begin{bmatrix} 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 1.4 - 0.4 \\ -0.8 + 0.8 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} = s\) — chính xác tuyệt đối!&lt;/li&gt;
      &lt;li&gt;Định thức \(\det(H_1) = (0.7)(0.8) - (-0.4)^2 = 0.56 - 0.16 = 0.40 &amp;gt; 0\) và vết \(= 1.5 &amp;gt; 0\), khẳng định \(H_1 \succ 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Cập nhật DFP là phương pháp cập nhật ma trận xấp xỉ nghịch đảo Hessian \(H = B^{-1}\) bằng một ma trận đối xứng hạng 2:&lt;/p&gt;

&lt;blockquote&gt;
\[H^+ = H + auu^T + bvv^T.\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu \(H^+\) thỏa mãn phương trình secant (\(B^+ s = y \Leftrightarrow H^+ y = s\)), thì \(s - Hy\) phải là một tổ hợp tuyến tính của \(u\) và \(v\):&lt;/p&gt;

&lt;blockquote&gt;
\[H^+y = Hy + auu^Ty + bvv^Ty = Hy + (au^Ty)u + (bv^Ty)v = s\]

\[\Rightarrow s - Hy = (au^Ty)u + (bv^Ty)v\]
&lt;/blockquote&gt;

&lt;p&gt;Chọn \(u = s, v = Hy\) rồi giải tìm hai hệ số \(a\) và \(b\), ta thu được công thức cập nhật DFP cho \(H\):&lt;/p&gt;
&lt;blockquote&gt;
\[H^+ = H - \frac{Hyy^TH}{y^THy} + \frac{ss^T}{y^Ts}\]
&lt;/blockquote&gt;

&lt;p&gt;Tương tự trường hợp SR1, áp dụng &lt;a href=&quot;https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula&quot;&gt;công thức Sherman–Morrison&lt;/a&gt; (hai lần), ta suy ra công thức cập nhật tương ứng cho \(B\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
B^+ &amp;amp;= B + \frac{(y-Bs)y^T}{y^Ts} + \frac{y(y-Bs)^T}{y^Ts} - \frac{(y-Bs)^Ts}{(y^Ts)^2} yy^T\\\\
&amp;amp;= \big( I - \frac{ys^T}{y^Ts} \big) B \big( I - \frac{sy^T}{y^Ts} \big) + \frac{yy^T}{y^Ts} 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Khi \(B\) xác định dương và điều kiện độ cong \(y^Ts &amp;gt; 0\) được thỏa mãn, số hạng thứ nhất \(\big( I - \frac{ys^T}{y^Ts} \big) B \big( I - \frac{sy^T}{y^Ts} \big)\) và số hạng thứ hai \(\frac{yy^T}{y^Ts}\) đều nửa xác định dương, đồng thời với mọi \(z \neq 0\) hai dạng toàn phương tương ứng không thể đồng thời triệt tiêu (vì \(y^Tz = 0 \Rightarrow z^TB^+z = z^TBz &amp;gt; 0\)). Nhờ đó, \(B^+\) luôn được đảm bảo xác định dương, khắc phục nhược điểm của SR1.&lt;/p&gt;

&lt;h2 id=&quot;suy-luận-thay-thế-cho-cập-nhật-dfp&quot;&gt;Suy luận thay thế cho cập nhật DFP&lt;/h2&gt;

&lt;p&gt;Nhắc lại rằng nếu điều kiện độ cong \(y^Ts &amp;gt; 0\) (\(y, s \in \mathbb{R}^n\)) được thỏa mãn, thì tồn tại ma trận đối xứng xác định dương thỏa mãn phương trình secant.&lt;/p&gt;

&lt;p&gt;Cập nhật DFP còn có thể được suy ra trực tiếp bằng cách cực tiểu hóa khoảng cách theo chuẩn Frobenius có trọng số giữa \(B^+\) và \(B\) dưới hai ràng buộc: (1) \(B^+\) đối xứng và (2) \(B^+\) thỏa mãn phương trình secant. (Mỗi chuẩn ma trận khác nhau dẫn tới một công thức Quasi-Newton khác nhau; chuẩn Frobenius có trọng số vừa dễ giải giải tích vừa đảm bảo tính bất biến theo tỷ lệ của phương pháp.)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Giải bài toán:
\(\begin{align}
&amp;amp; \min_{B^+} \: \: &amp;amp;&amp;amp; {\|W^{1/2} (B^+ - B) W^{1/2} \|_F} \\\\
&amp;amp; \text{thỏa mãn } &amp;amp;&amp;amp; {B^+ = (B^+)^T} \\\\
   &amp;amp;&amp;amp;&amp;amp; {B^+s = y}  \\\\
&amp;amp; \text{trong đó } &amp;amp;&amp;amp; W \in \mathbb{R}^{n \; \times \;n} \text{ là ma trận đối xứng xác định dương thỏa mãn } Wy_k = s_k.
\end{align}\\\\\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Tham khảo:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Chuẩn Frobenius:&lt;/strong&gt; Chuẩn Frobenius của ma trận \(A\) được định nghĩa là:
\(\| A \|_{F}  \doteq \left( \sum_{i,j} A_{i,j}^2 \right)^{1/2}\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Chuẩn Frobenius có trọng số:&lt;/strong&gt; Với ma trận trọng số \(W \succ 0\), chuẩn Frobenius có trọng số của \(A\) được định nghĩa là:
\(\|A\|_W \doteq \| W^{1/2} A W^{1/2} \|_F\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>18-02 Cập nhật Hạng-một Đối xứng (SR1)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_02_Symmetric_Rank_One_Update_(SR1)/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_02_Symmetric_Rank_One_Update_(SR1)</id>
   <content type="html">&lt;p&gt;Nếu muốn chỉnh sửa ma trận đối xứng \(B\) theo cách tiết kiệm nhất có thể để nó thỏa mãn phương trình secant \(B^+ s = y\), lựa chọn tối giản nhất là cộng thêm một ma trận đối xứng &lt;strong&gt;hạng 1&lt;/strong&gt; có dạng \(a u u^T\). Điều kỳ diệu là chỉ riêng yêu cầu đối xứng và hạng 1 đã khóa chặt hoàn toàn công thức cập nhật — chỉ có &lt;strong&gt;duy nhất một&lt;/strong&gt; công thức SR1! Dù có điểm yếu chí mạng là có thể làm mất tính xác định dương hoặc chia cho mẫu số gần bằng không, SR1 lại sở hữu một siêu năng lực đặc biệt: nó xấp xỉ rất sát cả những Hessian không xác định (indefinite) trong các phương pháp vùng tin cậy (trust-region).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-đặc-tính-toán-học-làm-nên-cá-tính-của-sr1&quot;&gt;Kiến thức cần nhớ: Ba đặc tính toán học làm nên cá tính của SR1&lt;/h2&gt;

&lt;p&gt;Trước khi đi vào phép suy diễn đại số của SR1, hãy nắm rõ ba điểm mạnh và giới hạn của công thức hạng-một này:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính duy nhất của cập nhật đối xứng hạng 1:&lt;/strong&gt; Thay \(B^+ = B + auu^T\) vào \(B^+ s = y\) ép vector \(u\) phải song song với vector sai lệch \(y - Bs\). Khi mẫu số \((y - Bs)^T s \ne 0\), công thức \(B^+ = B + \frac{(y-Bs)(y-Bs)^T}{(y-Bs)^T s}\) là nghiệm duy nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bất biến qua phép nghịch đảo (Self-Duality):&lt;/strong&gt; Khi áp dụng công thức Sherman–Morrison để lấy nghịch đảo \(H^+ = (B^+)^{-1}\), công thức cập nhật cho \(H\) có hình dạng hoàn toàn y hệt công thức cho \(B\) (chỉ đổi chỗ \(B \leftrightarrow H\) và \(s \leftrightarrow y\)).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Mất tính xác định dương và cơ chế bỏ qua bước (Skipping):&lt;/strong&gt; Ngay cả khi \(B \succ 0\) và \(y^T s &amp;gt; 0\), mẫu số \((y - Bs)^T s\) vẫn có thể âm (làm \(B^+\) mất tính xác định dương) hoặc gần bằng \(0\) (làm \(B^+\) nổ lớn). Trong thực hành, ta bỏ qua cập nhật nếu $$&lt;/td&gt;
          &lt;td&gt;s^T(y - Bs)&lt;/td&gt;
          &lt;td&gt;&amp;lt; r |s| |y - Bs|\((thường\)r = 10^{-8}$$), và kết hợp SR1 với vùng tin cậy thay vì line search thuần túy.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-một-bước-sr1-trên-ma-trận-2-times-2-và-kiểm-chứng-secant&quot;&gt;Giải thích: Tính tay một bước SR1 trên ma trận \(2 \times 2\) và kiểm chứng secant&lt;/h3&gt;

&lt;p&gt;Giả sử ta bắt đầu với xấp xỉ Hessian \(B_0 = I = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\), và sau một bước tối ưu thu được \(s = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\), \(y = \begin{bmatrix} 3 \\ 1 \end{bmatrix}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính vector sai lệch secant \(v = y - B_0 s\):&lt;/strong&gt;
\(v = \begin{bmatrix} 3 \\ 1 \end{bmatrix} - \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 2 \\ 1 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính mẫu số \(v^T s\):&lt;/strong&gt;
\(v^T s = (2)(1) + (1)(0) = 2 \ne 0.\)
(Mẫu số dương và cách xa \(0\) nên phép cập nhật hoàn toàn an toàn!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính ma trận hiệu chỉnh hạng 1 và \(B_1\):&lt;/strong&gt;
\(\frac{vv^T}{v^T s} = \frac{1}{2}\begin{bmatrix} 2 \\ 1 \end{bmatrix}\begin{bmatrix} 2 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 0.5 \end{bmatrix} \implies B_1 = I + \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 0.5 \end{bmatrix} = \begin{bmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng phương trình secant và tính xác định dương:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(B_1 s = \begin{bmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix}\begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 3 \\ 1 \end{bmatrix} = y\) — khớp chính xác!&lt;/li&gt;
      &lt;li&gt;Định thức \(\det(B_1) = (3)(1.5) - 1^2 = 3.5 &amp;gt; 0\) và vết \(= 4.5 &amp;gt; 0\), nên trong ví dụ này \(B_1 \succ 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử đổi \(y = (0.5, 1)^T\) để thấy rủi ro của SR1:&lt;/strong&gt; Khi đó \(v = (-0.5, 1)^T\), \(v^T s = -0.5 &amp;lt; 0\) dù \(y^T s = 0.5 &amp;gt; 0\)! Ta được \(B_1 = \begin{bmatrix} 0.5 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}\) có \(\det = -1.5 &amp;lt; 0\) — &lt;strong&gt;mất tính xác định dương&lt;/strong&gt;! Đây chính là động lực để Davidon, Fletcher và Powell nâng cấp lên cập nhật hạng 2 ở bài tiếp theo.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Cập nhật hạng-một đối xứng (Symmetric Rank-One — SR1) cộng thêm vào \(B\) một ma trận đối xứng hạng 1 sao cho \(B^+\) giữ được tính đối xứng và thỏa mãn phương trình secant. Biểu diễn ma trận đối xứng hạng 1 dưới dạng tích của \(a \in \left\{-1, 1\right\}\) và vector \(u \in \mathbb{R}^n\), công thức cập nhật có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = B + auu^T.\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;quan-sát-chính&quot;&gt;Quan sát chính&lt;/h2&gt;
&lt;p&gt;Ta cần chọn \(a\) và \(u\) để \(B^+\) thỏa mãn phương trình secant \(y = B^+s\). Thay dạng cập nhật trên vào phương trình secant:&lt;/p&gt;

&lt;blockquote&gt;
\[y = B^+s \Rightarrow y = Bs + (au^Ts)u. \quad \text{--- (1)}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì \(au^Ts\) là một đại lượng vô hướng, vector \(u\) phải cùng phương với \(y - Bs\), tức là \(u = \delta(y - Bs)\) với \(\delta\) là một số thực khác 0. Thay \(u = \delta(y - Bs)\) vào (1):&lt;/p&gt;

&lt;blockquote&gt;
\[y-Bs = a\delta^2 \big[ s^T(y - Bs) \big] (y -Bs),\]
&lt;/blockquote&gt;

&lt;p&gt;Để đẳng thức trên đúng (khi \(y - Bs \neq 0\) và \(s^T(y - Bs) \neq 0\)), ta cần chọn \(a\) và \(\delta\) như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[a = \text{sign} \big[ s^T (y - Bs) \big], \quad \delta = \pm | s^T(y-Bs) |^{-1/2}. \quad \text{--- (2)}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;công-thức-cập-nhật-sr1-duy-nhất&quot;&gt;Công thức cập nhật SR1 duy nhất&lt;/h2&gt;
&lt;p&gt;Thay \(u = \delta (y - Bs)\) cùng các giá trị trong (2) vào \(B^+ = B + auu^T\), ta thu được công thức cập nhật SR1 duy nhất ([14] mục 6.2):&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = B + \frac{(y-Bs)(y-Bs)^T}{(y-Bs)^Ts}.\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;công-thức-cập-nhật-cho-xấp-xỉ-nghịch-đảo-hessian&quot;&gt;Công thức cập nhật cho xấp xỉ nghịch đảo Hessian&lt;/h2&gt;

&lt;p&gt;Để tính bước cập nhật \(x^+\), ta cần tác động của \(B^{-1}\):&lt;/p&gt;

&lt;blockquote&gt;
\[x^+ = x + tp = x - tB^{-1}\nabla f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu có thể cập nhật trực tiếp \(H = B^{-1}\) thay vì cập nhật \(B\) rồi giải hệ tuyến tính, ta sẽ tránh được chi phí nghịch đảo ma trận ở mỗi vòng lặp. Áp dụng &lt;a href=&quot;https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula&quot;&gt;công thức Sherman–Morrison&lt;/a&gt;, ta thu được công thức cập nhật tương ứng cho \(H = B^{-1}\) có cấu trúc hoàn toàn tương tự:&lt;/p&gt;

&lt;blockquote&gt;
\[H^+ = H + \frac{(s-Hy)(s-Hy)^T}{(s-Hy)^Ty}.\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;nhược-điểm-của-sr1&quot;&gt;Nhược điểm của SR1&lt;/h2&gt;

&lt;p&gt;Dù rất đơn giản, cập nhật SR1 có hai nhược điểm đáng kể:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Phép cập nhật có thể mất ổn định hoặc không xác định khi mẫu số \((y - Bs)^Ts\) tiến về \(0\).&lt;/li&gt;
  &lt;li&gt;Không đảm bảo bảo toàn tính xác định dương của \(B\) và \(H\) (ngay cả khi điều kiện độ cong \(s^Ty &amp;gt; 0\) được thỏa mãn).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các phần tiếp theo sẽ trình bày những công thức cập nhật khắc phục hai hạn chế này của SR1.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>18-01 Phương trình Secant và Điều kiện Độ cong</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_01_Secant_Equation_and_Curvature_Condition/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_01_Secant_Equation_and_Curvature_Condition</id>
   <content type="html">&lt;p&gt;Trong không gian 1 chiều, biết hai điểm liên tiếp trên đồ thị đạo hàm là đủ xác định duy nhất một đường cát tuyến có độ dốc \(B_{k+1} = y_k / s_k\). Nhưng khi bước sang không gian \(n\) chiều, phương trình cát tuyến \(B_{k+1} s_k = y_k\) chỉ cung cấp \(n\) phương trình tuyến tính, trong khi một ma trận đối xứng \(B_{k+1}\) có tới \(\frac{n(n+1)}{2}\) ẩn số! Chính sự “thiếu phương trình” này đã mở ra bài toán thú vị nhất của Chương 18: cần bổ sung những điều kiện hình học nào (như điều kiện độ cong \(y_k^T s_k &amp;gt; 0\)) để ma trận \(B_{k+1}\) vừa xác định dương, vừa giữ lại được tri thức độ cong tích lũy từ các bước trước?&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-phương-trình-secant-và-điều-kiện-độ-cong&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của phương trình Secant và điều kiện độ cong&lt;/h2&gt;

&lt;p&gt;Để hiểu sâu cơ sở toán học của mọi công thức cập nhật Quasi-Newton, hãy nắm rõ ba ý tưởng sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định lý giá trị trung bình cho ánh xạ gradient:&lt;/strong&gt; Theo công thức tích phân Taylor, \(y_k = \nabla f(x_{k+1}) - \nabla f(x_k) = \left(\int_0^1 \nabla^2 f(x_k + \tau s_k)\,d\tau\right) s_k\). Như vậy, phương trình secant \(B_{k+1} s_k = y_k\) yêu cầu \(B_{k+1}\) khớp chính xác với &lt;strong&gt;Hessian trung bình&lt;/strong&gt; dọc theo đoạn bước đi \(s_k\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện độ cong \(y_k^T s_k &amp;gt; 0\) và tính xác định dương:&lt;/strong&gt; Muốn tồn tại ma trận đối xứng xác định dương \(B_{k+1} \succ 0\) thỏa mãn \(B_{k+1} s_k = y_k\), điều kiện cần và đủ là \(s_k^T y_k = s_k^T B_{k+1} s_k &amp;gt; 0\). Về mặt hình học, điều này nghĩa là đạo hàm theo hướng \(s_k\) phải tăng lên khi ta đi từ \(x_k\) sang \(x_{k+1}\) (hàm cong lên dọc theo hướng đi).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vai trò của điều kiện Wolfe với hàm không lồi:&lt;/strong&gt; Với hàm lồi chặt, \(y_k^T s_k &amp;gt; 0\) luôn tự động đúng. Với hàm không lồi tổng quát, điều kiện độ cong Wolfe \(\nabla f(x_{k+1})^T s_k \ge c_2 \nabla f(x_k)^T s_k\) (với \(c_2 \in (0, 1)\)) chính là chốt chặn bảo đảm \(y_k^T s_k \ge (c_2 - 1)\nabla f(x_k)^T s_k &amp;gt; 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-cặp-s-y-và-kiểm-chứng-điều-kiện-độ-cong-trên-mặt-paraboloid-2d&quot;&gt;Giải thích: Tính tay cặp \((s, y)\) và kiểm chứng điều kiện độ cong trên mặt paraboloid 2D&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai lồi chặt 2 biến \(f(x_1, x_2) = x_1^2 + 3x_2^2\), có gradient \(\nabla f(x) = (2x_1, \; 6x_2)^T\) và Hessian thực không đổi \(G = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 6 \end{bmatrix}\). Giả sử ta bước từ \(x^0 = (1, 1)^T\) tới \(x^1 = (0, 0.5)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính vector bước đi \(s^0\) và biến thiên gradient \(y^0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(s^0 = x^1 - x^0 = (0 - 1, \; 0.5 - 1)^T = (-1, \; -0.5)^T\).&lt;/li&gt;
      &lt;li&gt;\(\nabla f(x^0) = (2, 6)^T\), \(\nabla f(x^1) = (0, 3)^T\).&lt;/li&gt;
      &lt;li&gt;\(y^0 = \nabla f(x^1) - \nabla f(x^0) = (-2, \; -3)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện độ cong:&lt;/strong&gt;
\((y^0)^T s^0 = (-2)(-1) + (-3)(-0.5) = 2 + 1.5 = 3.5 &amp;gt; 0.\)
Điều kiện độ cong thỏa mãn chặt chẽ, chứng tỏ chắc chắn tồn tại ma trận đối xứng xác định dương \(B^1\) thỏa mãn phương trình secant!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra phương trình secant với Hessian thực:&lt;/strong&gt;
\(G s^0 = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 6 \end{bmatrix} \begin{bmatrix} -1 \\ -0.5 \end{bmatrix} = \begin{bmatrix} -2 \\ -3 \end{bmatrix} = y^0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thấy ngay tính “thiếu ẩn”:&lt;/strong&gt; Ma trận đường chéo \(B_{\text{khác}} = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 6 \end{bmatrix}\) không phải nghiệm duy nhất! Chẳng hạn \(B_{\text{mới}} = \begin{bmatrix} 1.5 &amp;amp; 1 \\ 1 &amp;amp; 8 \end{bmatrix}\) cũng đối xứng, xác định dương (\(\det = 12 - 1 = 11 &amp;gt; 0\)) và thỏa mãn \(B_{\text{mới}} s^0 = (-1.5 - 0.5, \; -1 - 4)^T = (-2, \; -5)^T\) (chưa khớp), còn nếu chọn \(B_{\text{mới}} = \begin{bmatrix} 1.5 &amp;amp; 1 \\ 1 &amp;amp; 4 \end{bmatrix}\) thì \(B_{\text{mới}} s^0 = (-2, \; -3)^T = y^0\) và \(\det = 6 - 1 = 5 &amp;gt; 0\)! Vì có vô số ma trận \(B^1 \succ 0\) thỏa mãn secant, các bài tiếp theo (SR1, DFP, BFGS) sẽ đặt thêm nguyên lý “thay đổi ít nhất so với \(B^0\)”.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;phương-trình-secant&quot;&gt;Phương trình Secant&lt;/h1&gt;

&lt;p&gt;Như đã trình bày ở phần trước, \(B\) là ma trận xấp xỉ Hessian \(\nabla^2 f(x)\). Để \(B\) mang các tính chất tương tự Hessian thực, nó cần thỏa mãn một điều kiện gọi là &lt;strong&gt;phương trình secant (secant equation)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Với \(x^{k+1} = x^k + s^k\) và \(f\) khả vi hai lần, khai triển Taylor bậc nhất của \(\nabla f(x^k + s^k)\) cho thấy Hessian thực thỏa mãn xấp xỉ:&lt;/p&gt;

&lt;blockquote&gt;
\[\nabla f(x^k + s^k) \approx \nabla f(x^k) + \nabla^2 f(x^k) s^k\]
&lt;/blockquote&gt;

&lt;p&gt;Thay \(\nabla^2 f(x^k)\) bằng ma trận xấp xỉ mới \(B^{k+1}\), ta yêu cầu phương trình sau được thỏa mãn chính xác:&lt;/p&gt;

&lt;blockquote&gt;
\[\nabla f(x^k + s^k) = \nabla f(x^k) + B^{k+1} s^k\]
&lt;/blockquote&gt;

&lt;p&gt;Đặt \(s^k = x^{k+1} - x^k\) và \(y^k = \nabla f(x^{k+1}) - \nabla f(x^k)\), phương trình trên được viết gọn thành &lt;strong&gt;phương trình secant&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
\[B^{k+1} s^k = y^k\]
&lt;/blockquote&gt;

&lt;h1 id=&quot;ý-nghĩa-hình-học-của-phương-trình-secant&quot;&gt;Ý nghĩa hình học của phương trình Secant&lt;/h1&gt;

&lt;p&gt;Trong trường hợp một chiều với \(x\) là trục hoành và \(\nabla f(x)\) là trục tung, \(B^{k+1}\) chính là hệ số góc của cát tuyến đi qua hai điểm \((x^k, \nabla f(x^k))\) và \((x^{k+1}, \nabla f(x^{k+1}))\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter18/intuition_of_secant_eq.png&quot; alt=&quot;[Fig1] Trực quan về phương trình secant&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Trực quan về phương trình secant&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h1 id=&quot;các-điều-kiện-xác-định-b&quot;&gt;Các điều kiện xác định \(B^+\)&lt;/h1&gt;

&lt;p&gt;Từ ma trận \(B\) hiện tại, ta đặt ra ba yêu cầu để xác định ma trận cập nhật \(B^+\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(B^+\) đối xứng:&lt;/strong&gt; Phản ánh tính đối xứng của ma trận Hessian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(B^+\) gần \(B\) nhất:&lt;/strong&gt; Giúp xác định duy nhất \(B^+\). Vì \(B\) đã tích lũy thông tin độ cong từ các bước trước, ta chọn ma trận gần \(B\) nhất (theo một chuẩn thích hợp) trong số các ma trận thỏa mãn phương trình secant.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bảo toàn tính xác định dương (\(B \succ 0 \Rightarrow B^+ \succ 0\)):&lt;/strong&gt; Đảm bảo hướng cập nhật \(p = -(B^+)^{-1}\nabla f(x)\) luôn là hướng giảm của hàm mục tiêu (tham khảo: &lt;a href=&quot;https://web.stanford.edu/group/sisl/k12/optimization/MO-unit4-pdfs/4.10applicationsofhessians.pdf&quot;&gt;Phân tích Hessian&lt;/a&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;điều-kiện-độ-cong-curvature-condition&quot;&gt;Điều kiện độ cong (Curvature Condition)&lt;/h1&gt;

&lt;p&gt;Nếu \(B^+\) xác định dương và thỏa mãn phương trình secant \(B^+ s = y\), thì nhất thiết phải có:&lt;/p&gt;

&lt;blockquote&gt;
\[s^T y = s^T B^+ s &amp;gt; 0.\]
&lt;/blockquote&gt;

&lt;p&gt;(tham khảo: &lt;a href=&quot;https://en.wikipedia.org/wiki/Positive-definite_matrix&quot;&gt;Ma trận xác định dương trên Wikipedia&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Bất đẳng thức \(s^T y &amp;gt; 0\) được gọi là &lt;strong&gt;điều kiện độ cong (curvature condition)&lt;/strong&gt;. Khi điều kiện này thỏa mãn (và \(s \neq 0\)), luôn tồn tại ma trận đối xứng xác định dương \(B^+\) thỏa mãn phương trình secant \(B^+ s = y\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>18-00 Phương pháp Quasi-Newton</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_00_Quasi_Newton_methods/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter18/18_00_Quasi_Newton_methods</id>
   <content type="html">&lt;p&gt;Vào giữa thập niên 1950, máy tính điện tử vẫn chạy bằng đèn chân không và thường xuyên sập nguồn sau vài giờ hoạt động. Nhà vật lý William Davidon khi giải bài toán tối ưu nhiều chiều tại Phòng thí nghiệm Quốc gia Argonne đã bị đẩy vào thế bí: phương pháp hạ gradient thì quá chậm (máy sập trước khi hội tụ), còn phương pháp Newton thì đòi hỏi tính và nghịch đảo ma trận Hessian cỡ \(n \times n\) quá sức chịu đựng của máy tính. Trong cái khó ló cái khôn, ông nảy ra một ý tưởng thiên tài: &lt;strong&gt;chỉ cần nhìn cách gradient thay đổi sau mỗi bước đi, ta có thể tự “học” dần độ cong của hàm mà không bao giờ phải tính đạo hàm bậc hai!&lt;/strong&gt; Đó là sự ra đời của họ phương pháp Quasi-Newton.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tối-ưu-hóa-quasi-newton&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tối ưu hóa Quasi-Newton&lt;/h2&gt;

&lt;p&gt;Để nắm trọn bức tranh của Chương 18, hãy nhìn cách phương pháp Quasi-Newton đứng đúng ở “điểm ngọt” giữa phương pháp bậc nhất và phương pháp bậc hai:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí tính toán theo kích thước bài toán (Complexity Trade-off):&lt;/strong&gt; Hạ gradient chỉ tốn \(O(n)\) mỗi bước nhưng hội tụ tuyến tính chậm chạp khi số điều kiện xấu; Newton hội tụ bậc hai nhưng tốn \(O(n^3)\) để giải hệ tuyến tính Hessian; Quasi-Newton tốn \(O(n^2)\) (và L-BFGS chỉ tốn \(O(mn)\)) nhưng vẫn đạt hội tụ siêu tuyến tính.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương trình Secant (Secant Equation):&lt;/strong&gt; Thay vì đo độ cong tại một điểm bằng đạo hàm bậc hai, ta buộc ma trận xấp xỉ \(B_{k+1}\) khớp đúng với biến thiên gradient \(y_k = \nabla f(x_{k+1}) - \nabla f(x_k)\) dọc theo bước đi \(s_k = x_{k+1} - x_k\), tức \(B_{k+1} s_k = y_k\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật hạng thấp bảo toàn cấu trúc (Low-Rank Updates):&lt;/strong&gt; Để ma trận xấp xỉ luôn đối xứng, xác định dương (đảm bảo hướng đi luôn là hướng giảm) và không phải tính lại từ đầu, các công thức SR1, DFP, BFGS chỉ cộng thêm một ma trận hiệu chỉnh hạng 1 hoặc hạng 2.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghịch đảo trực tiếp nhờ công thức Sherman–Morrison–Woodbury:&lt;/strong&gt; Thay vì cập nhật \(B_k\) rồi giải hệ tuyến tính \(O(n^3)\), ta cập nhật trực tiếp ma trận nghịch đảo \(H_k \approx (\nabla^2 f)^{-1}\) chỉ bằng vài phép nhân vector–ma trận tốn \(O(n^2)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-chi-phí-on3-vs-on2-và-một-bước-cát-tuyến-1-chiều&quot;&gt;Giải thích: So sánh chi phí \(O(n^3)\) vs \(O(n^2)\) và một bước cát tuyến 1 chiều&lt;/h3&gt;

&lt;p&gt;Hãy cảm nhận hai ưu điểm của Quasi-Newton bằng hai phép tính nhỏ:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chênh lệch chi phí khi \(n = 10{,}000\) biến:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Newton chính xác:&lt;/strong&gt; Phân tích Cholesky ma trận Hessian dày đặc tốn cỡ \(\frac{1}{3}n^3 \approx 3.3 \times 10^{11}\) phép tính mỗi vòng lặp — và riêng việc lưu trữ ma trận \(10^4 \times 10^4\) số thực 64-bit đã ngốn \(800\text{ MB}\) RAM.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;BFGS:&lt;/strong&gt; Mỗi vòng lặp chỉ cần vài phép nhân ma trận–vector tốn \(O(n^2) \approx 10^8\) phép tính (nhanh hơn &lt;strong&gt;hơn 3.000 lần&lt;/strong&gt; so với Newton!).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;L-BFGS (với \(m = 10\) cặp lịch sử):&lt;/strong&gt; Chỉ tốn \(O(mn) \approx 10^5\) phép tính và dưới \(2\text{ MB}\) RAM.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trực giác 1 chiều trên hàm \(f(x) = \frac{1}{4}x^4 - x\)&lt;/strong&gt; (nghiệm tối ưu \(x^\star = 1\), gradient \(f&apos;(x) = x^3 - 1\)):
    &lt;ul&gt;
      &lt;li&gt;Khởi tạo tại \(x_0 = 2\) (\(f&apos;(2) = 7\)) và bước tới \(x_1 = 1.5\) (\(f&apos;(1.5) = 2.375\)).&lt;/li&gt;
      &lt;li&gt;Không cần tính đạo hàm bậc hai \(f&apos;&apos;(x) = 3x^2\), ta đo độ cong trung bình qua tỉ số cát tuyến:
\(B_1 = \frac{f&apos;(1.5) - f&apos;(2)}{1.5 - 2} = \frac{2.375 - 7}{-0.5} = 9.25.\)&lt;/li&gt;
      &lt;li&gt;Bước Quasi-Newton tiếp theo là \(x_2 = x_1 - \frac{f&apos;(x_1)}{B_1} = 1.5 - \frac{2.375}{9.25} \approx 1.2432\) — tiến rất nhanh về \(x^\star = 1\) mà chưa hề đụng tới đạo hàm bậc hai!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Vào giữa thập niên 1950, nhà vật lý W.C. Davidon khi làm việc tại Phòng thí nghiệm Quốc gia Argonne đã giải các bài toán tối ưu có khối lượng tính toán lớn bằng phương pháp hạ theo tọa độ (coordinate descent). Do máy tính thời đó thiếu ổn định và thường xuyên gặp sự cố trước khi phép tính hoàn tất, Davidon tìm cách tăng tốc độ hội tụ. Kết quả là thuật toán Quasi-Newton đầu tiên ra đời, mở ra bước tiến quan trọng cho tối ưu phi tuyến và kéo theo hàng loạt công trình nghiên cứu trong hai thập kỷ sau đó.&lt;/p&gt;

&lt;p&gt;Trớ trêu thay, &lt;a href=&quot;http://www.math.mcgill.ca/dstephens/680/Papers/Davidon91.pdf&quot;&gt;nghiên cứu của Davidon&lt;/a&gt; khi ấy không được chấp nhận đăng và chỉ lưu hành dưới dạng báo cáo kỹ thuật suốt hơn 30 năm, trước khi chính thức được xuất bản trong &lt;a href=&quot;https://epubs.siam.org/toc/sjope8/1/1&quot;&gt;số đầu tiên của SIAM Journal on Optimization&lt;/a&gt; vào năm 1991.&lt;/p&gt;

&lt;p&gt;Các phương pháp Quasi-Newton chỉ cần tính gradient của hàm mục tiêu ở mỗi vòng lặp. Nhờ đó, chi phí tính toán thấp hơn nhiều so với phương pháp Newton (vốn đòi hỏi đạo hàm bậc hai), đồng thời vẫn đạt tốc độ hội tụ siêu tuyến tính (superlinear convergence) [14].&lt;/p&gt;

&lt;h2 id=&quot;động-lực-của-phương-pháp-quasi-newton&quot;&gt;Động lực của phương pháp Quasi-Newton&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối ưu trơn không ràng buộc:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_x \: f(x), \\\\
\text{trong đó } f \text{ khả vi hai lần, và } \operatorname{dom} f = \mathbb{R}^n.\]
&lt;/blockquote&gt;

&lt;p&gt;Công thức cập nhật \(x\) của phương pháp hạ gradient (Gradient Descent) và phương pháp Newton cho bài toán trên lần lượt là:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Phương pháp Gradient descent:&lt;/strong&gt;
\(x^+ = x - t \nabla f(x)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Phương pháp Newton:&lt;/strong&gt;
\(x^+ = x - t \nabla^2 f(x)^{-1} \nabla f(x)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Phương pháp Newton có ưu điểm là đạt tốc độ hội tụ bậc hai (\(O(\log \log (1/\epsilon))\)), nhưng gặp trở ngại lớn về chi phí tính toán ở hai bước sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính và lưu trữ ma trận Hessian \(\nabla^2 f(x)\):&lt;/strong&gt; Việc tính và lưu trữ Hessian đòi hỏi bộ nhớ \(O(n^2)\), không phù hợp khi làm việc với các bài toán có số chiều lớn (tham khảo: &lt;a href=&quot;https://en.wikipedia.org/wiki/Hessian_matrix#Use_in_optimization&quot;&gt;Ma trận Hessian&lt;/a&gt; trên Wikipedia).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải hệ phương trình \(\nabla^2 f(x) p = -\nabla f(x)\):&lt;/strong&gt; Chi phí giải hệ tuyến tính (hoặc nghịch đảo Hessian) lên tới \(O(n^3)\) ở mỗi bước (tham khảo: &lt;a href=&quot;https://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations#Matrix_algebra&quot;&gt;Độ phức tạp tính toán của Đại số Ma trận&lt;/a&gt; trên Wikipedia).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Phương pháp Quasi-Newton khắc phục điều này bằng cách dùng một ma trận xấp xỉ \(B\) thay cho \(\nabla^2 f(x)\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Phương pháp Quasi-Newton:&lt;/strong&gt;
\(x^+ = x + tp \\\\
\text{trong đó } Bp = -\nabla f(x).\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ở đây, ma trận \(B\) cần dễ cập nhật và cho phép giải nhanh hệ phương trình \(Bp = g\).&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán-quasi-newton&quot;&gt;Thuật toán Quasi-Newton&lt;/h2&gt;
&lt;p&gt;Khung thuật toán Quasi-Newton tổng quát gồm các bước:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Chọn điểm khởi tạo \(x^0\) và ma trận \(B^0\) ban đầu.&lt;/li&gt;
  &lt;li&gt;Với \(k = 0, 1, \dots\):
    &lt;ul&gt;
      &lt;li&gt;Giải hệ \(B^k p^k = - \nabla f(x^k)\).&lt;/li&gt;
      &lt;li&gt;Chọn độ dài bước \(t_k\) và đặt \(x^{k+1} = x^{k} + t_k p^k\).&lt;/li&gt;
      &lt;li&gt;Cập nhật \(B^k\) thành \(B^{k+1}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Kết thúc khi đạt điều kiện dừng.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Điểm cốt lõi của lớp phương pháp này là cách cập nhật \(B\) qua từng vòng lặp để ngày càng xấp xỉ tốt hơn độ cong của hàm mục tiêu quanh nghiệm tối ưu. Cách xây dựng \(B^+\) từ \(B\) sẽ là nội dung trọng tâm xuyên suốt chương này. (&lt;strong&gt;Lưu ý:&lt;/strong&gt; Để trình bày gọn gàng, chúng ta dùng song song hai cặp ký hiệu \(B^{k+1}, B^k\) và \(B^+, B\).)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>18-09 Practical Exercises - Quasi-Newton Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_09_Practical_Exercises_Quasi_Newton_Methods/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_09_Practical_Exercises_Quasi_Newton_Methods</id>
   <content type="html">&lt;p&gt;Quasi-Newton methods look deceptively tidy in matrix notation, yet a single sign error in \(y^T s\) or a forgotten Wolfe curvature check can turn a positive-definite BFGS matrix into an uphill ascent step. These practical exercises—adapted from Nocedal &amp;amp; Wright—walk you through hand-verifying secant updates, checking positive definiteness, and implementing L-BFGS. Before starting Exercise 1, run through this quick warm-up proving &lt;em&gt;why&lt;/em&gt; the Wolfe curvature condition is the exact mathematical lock that keeps \(y^T s &amp;gt; 0\) alive on nonconvex functions.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-essential-skills-for-the-quasi-newton-exercises&quot;&gt;Key ideas: Essential Skills for the Quasi-Newton Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Matrix Update Fluency:&lt;/strong&gt; Be comfortable computing rank-1 (SR1) and rank-2 (DFP, BFGS) updates both on \(B_k\) and directly on \(H_k\), and verifying the secant identity \(H_{k+1} y_k = s_k\) as an arithmetic sanity check.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Curvature Condition &amp;amp; Wolfe Line Search:&lt;/strong&gt; Understand how Armijo sufficient decrease prevents overly long steps while the Wolfe curvature condition prevents overly short steps &lt;em&gt;and&lt;/em&gt; guarantees \(y_k^T s_k &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Two-Loop L-BFGS Implementation:&lt;/strong&gt; Translate the \(O(mn)\) backward/forward dot-product loops into clean vector code without forming any \(n \times n\) matrices.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Empirical Rate Diagnosis:&lt;/strong&gt; Distinguish linear convergence (GD), superlinear convergence (BFGS), and quadratic convergence (Newton) from log-error plots on Rosenbrock and ill-conditioned quadratics.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-wolfe-curvature-guarantees-yt-s--0&quot;&gt;Worked example: Why Wolfe Curvature Guarantees \(y^T s &amp;gt; 0\)&lt;/h3&gt;

&lt;p&gt;Consider the nonconvex 1D double-well potential \(f(x) = x^4 - 2x^2\) (\(f&apos;(x) = 4x^3 - 4x\)) at \(x^0 = 0.5\), where \(f&apos;(0.5) = -1.5 &amp;lt; 0\), so \(p = +1\) is a descent direction. Set Wolfe parameters \(c_1 = 0.1, \; c_2 = 0.9\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test a short step \(\alpha = 0.1\) (passes Armijo, fails Wolfe curvature):&lt;/strong&gt;
At \(x^1 = 0.5 + 0.1 = 0.6\), \(f&apos;(0.6) = 4(0.216) - 2.4 = -1.536\).
    &lt;ul&gt;
      &lt;li&gt;Check Armijo: \(f(0.6) = -0.5904 \le f(0.5) + 0.1(0.1)(-1.5) = -0.4375 - 0.015 = -0.4525\) \(\checkmark\).&lt;/li&gt;
      &lt;li&gt;Check curvature: \(s = 0.1\), \(y = f&apos;(0.6) - f&apos;(0.5) = -1.536 - (-1.5) = -0.036 \implies y^T s = -0.0036 &amp;lt; 0\)!
Armijo &lt;em&gt;accepted&lt;/em&gt; this step, yet BFGS would break because \(f\) is still concave at \(x = 0.6\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test \(\alpha = 0.5\) (passes both Armijo and Wolfe curvature):&lt;/strong&gt;
At \(x^1 = 1.0\), \(f&apos;(1.0) = 0\).
    &lt;ul&gt;
      &lt;li&gt;Check Wolfe curvature: \(f&apos;(1.0) \cdot p = 0 \ge c_2 f&apos;(0.5) \cdot p = 0.9(-1.5) = -1.35\) \(\checkmark\).&lt;/li&gt;
      &lt;li&gt;Check \(y^T s\) automatically:
\(y^T s = \alpha \big(f&apos;(x^1) - f&apos;(x^0)\big) p \ge \alpha (c_2 - 1) f&apos;(x^0) p = 0.5(-0.1)(-1.5) = +0.075 &amp;gt; 0.\)
(Actual value: \(y^T s = (0 - (-1.5))(0.5) = +0.75 &amp;gt; 0\).)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway for the exercises:&lt;/strong&gt;
Whenever a Wolfe line search succeeds on a descent direction, \(y^T s &amp;gt; 0\) is guaranteed &lt;em&gt;even on nonconvex functions&lt;/em&gt;—ensuring your BFGS update in the exercises below remains strictly positive definite!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---quasi-newton-methods&quot;&gt;Practical Exercises - Quasi-Newton Methods&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Nocedal &amp;amp; Wright (2006). Throughout, \(H_k\) denotes the approximation of the &lt;strong&gt;inverse&lt;/strong&gt; Hessian.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-1-bfgs-update&quot;&gt;📝 &lt;strong&gt;Exercise 1: BFGS Update&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Given \(f(x) = x_1^2 + 4x_2^2\), \(x^{(k)} = (2, 1)\), \(x^{(k+1)} = (1.6, 0.7)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Compute \(s^{(k)} = x^{(k+1)} - x^{(k)}\), \(y^{(k)} = \nabla f(x^{(k+1)}) - \nabla f(x^{(k)})\)&lt;br /&gt;
b) Apply the BFGS update of the inverse Hessian: \(H_{k+1} = \left(I - \rho s y^T\right) H_k \left(I - \rho y s^T\right) + \rho s s^T\), \(\rho = \frac{1}{y^Ts}\)&lt;br /&gt;
c) Verify \(H_{k+1}y = s\) (secant condition)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Compute $$s, y$$:**

$$s = (1.6, 0.7) - (2, 1) = (-0.4, -0.3)$$

$$\nabla f(x) = (2x_1, 8x_2)$$

$$\nabla f(x^{(k)}) = (4, 8)$$, $$\nabla f(x^{(k+1)}) = (3.2, 5.6)$$

$$y = (3.2, 5.6) - (4, 8) = (-0.8, -2.4)$$

---

**b) BFGS update (start with $$H_0 = I$$):**

$$y^Ts = (-0.8)(-0.4) + (-2.4)(-0.3) = 0.32 + 0.72 = 1.04$$, so $$\rho = 1/1.04 \approx 0.9615$$

$$I - \rho s y^T = \begin{bmatrix} 0.692 &amp;amp; -0.923 \\ -0.231 &amp;amp; 0.308 \end{bmatrix}$$

$$H_1 = (I - \rho s y^T)(I - \rho y s^T) + \rho s s^T$$

$$\approx \begin{bmatrix} 1.331 &amp;amp; -0.444 \\ -0.444 &amp;amp; 0.148 \end{bmatrix} + \begin{bmatrix} 0.154 &amp;amp; 0.115 \\ 0.115 &amp;amp; 0.087 \end{bmatrix} \approx \begin{bmatrix} 1.485 &amp;amp; -0.328 \\ -0.328 &amp;amp; 0.234 \end{bmatrix}$$

---

**c) Verify the secant condition:**

$$H_1 y = \begin{bmatrix} 1.485 &amp;amp; -0.328 \\ -0.328 &amp;amp; 0.234 \end{bmatrix} \begin{bmatrix} -0.8 \\ -2.4 \end{bmatrix} \approx \begin{bmatrix} -0.4 \\ -0.3 \end{bmatrix} = s$$ ✓

(Remark: the simpler formula $$H - \frac{Hyy^TH}{y^THy} + \frac{ss^T}{y^Ts}$$ is the DFP update of the inverse Hessian; it also satisfies the secant condition, giving $$H_1 \approx \begin{bmatrix} 1.054 &amp;amp; -0.185 \\ -0.185 &amp;amp; 0.187 \end{bmatrix}$$ here.)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-sr1-vs-bfgs&quot;&gt;📝 &lt;strong&gt;Exercise 2: SR1 vs BFGS&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;SR1 update: \(H_{k+1} = H_k + \frac{(s - H_k y)(s - H_k y)^T}{(s - H_k y)^T y}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Compare stability with BFGS&lt;br /&gt;
b) When does SR1 fail?&lt;br /&gt;
c) Compute SR1 for the data of Exercise 1&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Stability:**

- **BFGS:** always positive definite (if $$y^Ts &amp;gt; 0$$)
- **SR1:** may be singular/indefinite

**b) SR1 fails when:**

$$(s - H_k y)^T y \approx 0$$ → division by zero

**Skip the update** if $$|(s - H_k y)^T y| &amp;lt; \epsilon \|s - H_k y\| \|y\|$$

---

**c) SR1 update:**

$$s - H_0 y = (-0.4, -0.3) - (-0.8, -2.4) = (0.4, 2.1)$$

$$(s - H_0 y)^T y = 0.4(-0.8) + 2.1(-2.4) = -0.32 - 5.04 = -5.36$$

$$H_1^{\text{SR1}} = I + \frac{1}{-5.36}\begin{bmatrix} 0.16 &amp;amp; 0.84 \\ 0.84 &amp;amp; 4.41 \end{bmatrix}$$

$$\approx \begin{bmatrix} 0.970 &amp;amp; -0.157 \\ -0.157 &amp;amp; 0.177 \end{bmatrix}$$

It satisfies the secant condition $$H_1 y = s$$. Here it happens to stay positive definite (its determinant is about $$0.147 &amp;gt; 0$$), but SR1 does **not** guarantee this in general, and its denominator can be negative or near zero.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-l-bfgs-for-large-scale-problems&quot;&gt;📝 &lt;strong&gt;Exercise 3: L-BFGS for Large-Scale Problems&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;L-BFGS stores the \(m\) most recent \((s, y)\) pairs instead of the full \(H_k\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Derive the two-loop recursion&lt;br /&gt;
b) Compute \(H_k \nabla f\) with \(m = 2\) stored pairs&lt;br /&gt;
c) Estimate the memory: \(n = 10^6\), \(m = 10\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Two-loop recursion:**

```
q = ∇f(x_k)
for i = k-1, ..., k-m:
    α_i = ρ_i s_i^T q
    q = q - α_i y_i
r = H_0 q  (often H_0 = γI)
for i = k-m, ..., k-1:
    β = ρ_i y_i^T r
    r = r + s_i(α_i - β)
return r = H_k ∇f
```

---

**b) Example with $$m = 2$$:**

$$\{(s_1, y_1), (s_2, y_2)\}$$, $$\rho_i = \frac{1}{y_i^T s_i}$$

**Loop 1 (backward):**

$$\alpha_2 = \rho_2 s_2^T \nabla f$$, $$q_1 = \nabla f - \alpha_2 y_2$$

$$\alpha_1 = \rho_1 s_1^T q_1$$, $$q_0 = q_1 - \alpha_1 y_1$$

**Initialize:** $$r_0 = \gamma q_0$$

**Loop 2 (forward):**

$$\beta_1 = \rho_1 y_1^T r_0$$, $$r_1 = r_0 + s_1(\alpha_1 - \beta_1)$$

$$\beta_2 = \rho_2 y_2^T r_1$$, $$r_2 = r_1 + s_2(\alpha_2 - \beta_2)$$

$$d = -r_2$$

---

**c) Memory (64-bit floats):**

**Full BFGS:** $$n^2$$ entries → $$10^{12}$$ floats ≈ **8 TB**

**L-BFGS:** $$2mn$$ entries → $$2 \cdot 10 \cdot 10^6 = 2 \times 10^7$$ floats ≈ **160 MB**

**$$50{,}000\times$$ reduction!**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-convergence-rate&quot;&gt;📝 &lt;strong&gt;Exercise 4: Convergence Rate&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Newton: \(\|x^{(k+1)} - x^*\| \leq C\|x^{(k)} - x^*\|^2\) (quadratic)&lt;br /&gt;
b) BFGS: \(\|x^{(k+1)} - x^*\| \leq C_k\|x^{(k)} - x^*\|\) with \(C_k \to 0\) — what is the order?&lt;br /&gt;
c) Compare the number of iterations needed&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Newton:**

**Quadratic:** $$p = 2$$, with $$C \propto \frac{M}{2m}$$ ($$M$$: Lipschitz constant of the Hessian, $$m$$: strong convexity constant)

For accuracy $$\epsilon$$: about $$\log\log(1/\epsilon)$$ iterations

---

**b) BFGS:**

**Superlinear:** $$p = 1 + o(1)$$ (between linear and quadratic)

$$\|H_k - \nabla^2 f^{-1}\| \to 0$$ along the iterates → eventually quadratic-like

---

**c) Iteration count (to reach $$10^{-10}$$, illustrative):**

| Method | Rate | Iterations |
|--------|------|------------|
| GD | Linear ($$0.9^k$$) | ~220 |
| BFGS | Superlinear | ~15 |
| Newton | Quadratic | ~5 |

**BFGS: a good balance!**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-practical-implementation&quot;&gt;📝 &lt;strong&gt;Exercise 5: Practical Implementation&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) When should the BFGS update be skipped?&lt;br /&gt;
b) Scaling of \(H_0\)&lt;br /&gt;
c) Line search requirements&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Skip the update when:**

$$y^Ts \leq \epsilon_s \|s\|^2$$ (curvature condition violated)

**Reason:** maintain positive definiteness

---

**b) Initial Hessian approximation:**

$$H_0 = \gamma I$$ with $$\gamma = \frac{y_{k-1}^T s_{k-1}}{y_{k-1}^T y_{k-1}}$$

**Adaptive scaling** based on the most recent curvature.

---

**c) Line search:**

**Strong Wolfe conditions:**

1. $$f(x + \alpha d) \leq f(x) + c_1 \alpha \nabla f^T d$$ (sufficient decrease)
2. $$|\nabla f(x + \alpha d)^T d| \leq c_2 |\nabla f^T d|$$ (curvature)

With $$c_1 = 10^{-4}$$, $$c_2 = 0.9$$.

**Ensures $$y^Ts &amp;gt; 0$$!**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Storage&lt;/th&gt;
      &lt;th&gt;Rate&lt;/th&gt;
      &lt;th&gt;Best for&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Newton&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\)&lt;/td&gt;
      &lt;td&gt;Quadratic&lt;/td&gt;
      &lt;td&gt;Small \(n\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;BFGS&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\)&lt;/td&gt;
      &lt;td&gt;Superlinear&lt;/td&gt;
      &lt;td&gt;Medium \(n\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;L-BFGS&lt;/td&gt;
      &lt;td&gt;\(O(mn)\)&lt;/td&gt;
      &lt;td&gt;Superlinear&lt;/td&gt;
      &lt;td&gt;Large \(n\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SR1&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\)&lt;/td&gt;
      &lt;td&gt;Superlinear&lt;/td&gt;
      &lt;td&gt;Non-PD is acceptable&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Nocedal, J., &amp;amp; Wright, S. J. (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt;. Springer. Chapter 6.&lt;/li&gt;
  &lt;li&gt;Liu, D. C., &amp;amp; Nocedal, J. (1989). “On the Limited Memory BFGS Method”.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>18-07 Limited Memory BFGS (LBFGS)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_07_Limited_Memory_BFGS_(LBFGS)/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_07_Limited_Memory_BFGS_(LBFGS)</id>
   <content type="html">&lt;p&gt;Standard BFGS is a triumph—until your problem has \(n = 1{,}000{,}000\) variables. Storing a dense \(10^6 \times 10^6\) inverse Hessian \(H_k\) in double precision would require &lt;strong&gt;8 terabytes of RAM&lt;/strong&gt;, crashing before iteration 1 even finishes. &lt;strong&gt;Limited-Memory BFGS (L-BFGS)&lt;/strong&gt; solves this memory wall with a breathtakingly simple observation: you never actually &lt;em&gt;need&lt;/em&gt; the matrix \(H_k\); you only ever need its action on a single vector, \(H_k \nabla f(x^k)\). By keeping only the last \(m\) curvature pairs \((s_i, y_i)\) (typically \(m = 5\text{–}20\)), the &lt;strong&gt;two-loop recursion&lt;/strong&gt; computes the exact L-BFGS search direction in \(O(mn)\) time and \(O(mn)\) memory!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-breaking-the-on2-memory-barrier&quot;&gt;Key ideas: Breaking the \(O(n^2)\) Memory Barrier&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Implicit Operator Representation:&lt;/strong&gt; Instead of storing \(H_k \in \mathbb{R}^{n \times n}\), L-BFGS stores a rolling FIFO buffer of the \(m\) most recent vector pairs \(\{(s_i, y_i)\}_{i=k-m}^{k-1}\) and applies the BFGS congruence formula on the fly to a simple diagonal seed \(H_k^0 = \gamma_k I\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-Scaled Initial Seed (\(\gamma_k = \frac{s_{k-1}^T y_{k-1}}{y_{k-1}^T y_{k-1}}\)):&lt;/strong&gt; Choosing \(\gamma_k\) as the Barzilai–Borwein inverse-curvature estimate scales the initial identity matrix to match the local Hessian magnitude, dramatically improving unit-step acceptance.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Two-Loop Recursion (\(4mn\) FLOPs):&lt;/strong&gt; The backward loop peels off projections \(\alpha_i = \rho_i s_i^T q\) from newest to oldest; the middle step multiplies by \(H_k^0\); and the forward loop reconstructs \(r = H_k g_k\) from oldest to newest via \(\beta_i = \rho_i y_i^T r\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trade-Off Between \(m\) and Convergence:&lt;/strong&gt; L-BFGS forfeits full-memory superlinear convergence (converging linearly, like preconditioned CG), yet \(m = 10\) typically captures the dominant Hessian eigenvalues and outperforms first-order methods by orders of magnitude on smooth, ill-conditioned large-scale objectives.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-tracing-the-two-loop-recursion-by-hand-m--2&quot;&gt;Worked example: Tracing the Two-Loop Recursion by Hand (\(m = 2\))&lt;/h3&gt;

&lt;p&gt;Suppose \(n = 2\) and our memory buffer holds \(m = 2\) pairs:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Older pair \(i = 0\): \(s_0 = (1, 0)^T, \; y_0 = (2, 0)^T \implies \rho_0 = \frac{1}{y_0^T s_0} = \frac{1}{2}\).&lt;/li&gt;
  &lt;li&gt;Newer pair \(i = 1\): \(s_1 = (0, 1)^T, \; y_1 = (0, 4)^T \implies \rho_1 = \frac{1}{y_1^T s_1} = \frac{1}{4}\).
We want to compute \(r = H_2 q\) for the current gradient \(q = g_2 = (4, 8)^T\). (Notice the true underlying Hessian here is \(\operatorname{diag}(2, 4)\), so the exact Newton vector \(Q^{-1} g_2\) should be $$(2, 2)^T$!)&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Backward loop (\(i = 1\), then \(i = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(i = 1\): \(\alpha_1 = \rho_1 (s_1^T q) = \frac{1}{4}(8) = 2\). Update \(q \leftarrow q - \alpha_1 y_1 = \begin{bmatrix}4\\8\end{bmatrix} - 2\begin{bmatrix}0\\4\end{bmatrix} = \begin{bmatrix}4\\0\end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;\(i = 0\): \(\alpha_0 = \rho_0 (s_0^T q) = \frac{1}{2}(4) = 2\). Update \(q \leftarrow q - \alpha_0 y_0 = \begin{bmatrix}4\\0\end{bmatrix} - 2\begin{bmatrix}2\\0\end{bmatrix} = \begin{bmatrix}0\\0\end{bmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Initial seed multiplication:&lt;/strong&gt;
\(\gamma_2 = \frac{s_1^T y_1}{y_1^T y_1} = \frac{4}{16} = \frac{1}{4}, \qquad r \leftarrow \gamma_2 q = \frac{1}{4}\begin{bmatrix}0\\0\end{bmatrix} = \begin{bmatrix}0\\0\end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Forward loop (\(i = 0\), then \(i = 1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(i = 0\): \(\beta_0 = \rho_0 (y_0^T r) = 0\). Update \(r \leftarrow r + (\alpha_0 - \beta_0) s_0 = \begin{bmatrix}0\\0\end{bmatrix} + (2 - 0)\begin{bmatrix}1\\0\end{bmatrix} = \begin{bmatrix}2\\0\end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;\(i = 1\): \(\beta_1 = \rho_1 (y_1^T r) = \frac{1}{4}(0) = 0\). Update \(r \leftarrow r + (\alpha_1 - \beta_1) s_1 = \begin{bmatrix}2\\0\end{bmatrix} + (2 - 0)\begin{bmatrix}0\\1\end{bmatrix} = \begin{bmatrix}2\\2\end{bmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify:&lt;/strong&gt;
The two-loop recursion returned \(r = (2, 2)^T = Q^{-1} g_2\) &lt;strong&gt;identically&lt;/strong&gt; using only dot products and vector additions—without ever forming a \(2 \times 2\) matrix!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;introduction&quot;&gt;Introduction&lt;/h1&gt;

&lt;p&gt;LBFGS is an example of limited-memory quasi-Newton methods, and is useful when the cost of computing or storing the Hessian matrix is not reasonable. The method estimates (approximates) the Hessian matrix by maintaining only a few \(n\)-dimensional vectors instead of storing a dense \(n \times n\) Hessian matrix.&lt;/p&gt;

&lt;p&gt;The LBFGS algorithm is based on BFGS, as its name suggests. The main idea is to use curvature information from the most recent iterations to estimate the Hessian. On the other hand, curvature information from older iterations is not used, in order to save storage space, as it may be somewhat distant from the behavior shown by the Hessian of the current iteration.&lt;/p&gt;

&lt;p&gt;As a side note, limited-memory versions of other quasi-Newton algorithms (e.g., SR1) can also be derived using the same technique [14].&lt;/p&gt;

&lt;h1 id=&quot;lbfgs&quot;&gt;LBFGS&lt;/h1&gt;

&lt;p&gt;To explain LBFGS, let us first look at the BFGS method. At each step, BFGS updates \(x\) as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[x^+ = x - t H \nabla f, \\\\
\text{where } t \text{ is the step length and } H \text{ is updated at every iteration by means of the formula, }\\\\
\text{ }\\\\
H^+ = \big( I - \frac{sy^T}{y^Ts} \big) H \big( I - \frac{ys^T}{y^Ts} \big) + \frac{ss^T}{y^Ts}. \\\\\]
&lt;/blockquote&gt;

&lt;p&gt;For \(H\) as above, \(H^+q, q \in \mathbb{R}^n\) can be expressed using scalars \(\alpha, \beta \in \mathbb{R}\) and vectors \(p, s \in \mathbb{R}^n\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
H^+q &amp;amp;= \big( I - \frac{sy^T}{y^Ts} \big) H \big( I - \frac{ys^T}{y^Ts} \big)q + \frac{ss^Tq}{y^Ts}\\\\
&amp;amp;= \big( I - \frac{sy^T}{y^Ts} \big) \underbrace{H \big( q - \frac{s^T q}{y^Ts} y \big)}_{p} + \underbrace{\frac{s^Tq}{y^Ts}}_{\alpha} s\\\\
&amp;amp;= \big( I - \frac{sy^T}{y^Ts} \big) p + \alpha s\\\\
&amp;amp;= p - \underbrace{\frac{y^Tp}{y^Ts}}_{\beta}s + \alpha s \\\\
&amp;amp;= p + (\alpha - \beta) s, \\\\
&amp;amp; \text{where } \alpha = \frac{s^Tq}{y^Ts}, q^+ = q - \alpha y, p = Hq^+, \beta = \frac{y^Tp}{y^Ts}.
\end{align} \\\\\]
&lt;/blockquote&gt;

&lt;p&gt;When \(H\) is obtained through \(k\) BFGS updates, \(Hq = -H\nabla f(x)\) can be computed in \(O(kn)\) operations (see the algorithm below). To use memory efficiently, we only use curvature information from the \(m\) most recent iterations (for \(k \ge m\)).&lt;/p&gt;

&lt;h1 id=&quot;algorithm&quot;&gt;Algorithm&lt;/h1&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter18/algorithm_quasi-newton.png&quot; alt=&quot;[Fig1] The algorithm of LBFGS [3]&quot; width=&quot;90%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] The algorithm of LBFGS [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Usually, the inverse Hessian approximation \(H_k\) is dense, and when there are many variables the computation becomes very heavy. LBFGS obtains \(H_k \nabla f_k\) through sums and products of successive vectors, which resolves the computational problem of \(H_k\).&lt;/p&gt;

&lt;p&gt;In the computation, the initial Hessian approximation \(H^{0, k}\) is usually (and has been verified to be very effective) the identity matrix multiplied by a constant (\(H^{0, k} = \gamma_k I\)), so the computation is not too large ([14], Section 7.2).&lt;/p&gt;

&lt;blockquote&gt;
\[H^{0, k} = \gamma_k I, \\\\
\text{where } \: \gamma_k = \frac{s^T_{k-1}y_{k-1}}{y^T_{k-1}y_{k-1}}.\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Note:&lt;/strong&gt; \(H^{0, k}\) changes at every iteration.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;l-bfgs-in-about-3-minutes&quot;&gt;L-BFGS in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/l-bfgs_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Why BFGS needs n² memory, m pairs (s, y) and H₀ = γI, the two-loop recursion by hand in 2D, then step counts on logistic regression.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>18-06 Superlinear convergence</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_06_Superlinear_convergence/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_06_Superlinear_convergence</id>
   <content type="html">&lt;p&gt;Here is one of the most counterintuitive facts in all of optimization theory: &lt;strong&gt;BFGS converges superlinearly even though its Hessian approximation \(B_k\) almost never converges to the true Hessian \(\nabla^2 f(x^\star)\)!&lt;/strong&gt; How can an algorithm mimic Newton’s method so closely that \(\|x^{k+1} - x^\star\| / \|x^k - x^\star\| \to 0\) while getting the Hessian wrong in almost every direction? The answer is the celebrated &lt;strong&gt;Dennis–Moré characterization&lt;/strong&gt;: \(B_k\) only needs to match the true Hessian &lt;em&gt;along the search direction \(p_k\) itself&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-machinery-behind-superlinear-convergence&quot;&gt;Key ideas: The Machinery Behind Superlinear Convergence&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Q-Superlinear Convergence:&lt;/strong&gt; A sequence converges Q-superlinearly if \(\lim_{k\to\infty} \frac{\|x^{k+1} - x^\star\|}{\|x^k - x^\star\|} = 0\)—strictly faster than any linear rate \(\rho^k\), meaning the number of accurate digits accelerates at every iteration.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Dennis–Moré Necessary &amp;amp; Sufficient Condition:&lt;/strong&gt; For \(x^{k+1} = x^k + p_k\) with \(p_k = -B_k^{-1} \nabla f(x^k)\), the iterates converge superlinearly &lt;em&gt;if and only if&lt;/em&gt;:
\(\lim_{k \to \infty} \frac{\|(B_k - \nabla^2 f(x^\star))\, p_k\|}{\|p_k\|} = 0.\)
Notice this is a &lt;em&gt;directional&lt;/em&gt; condition, vastly weaker than \(\|B_k - \nabla^2 f(x^\star)\| \to 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unit Step Acceptance (\(\alpha_k = 1\)):&lt;/strong&gt; Superlinear convergence requires the line search to eventually accept the full quasi-Newton step \(\alpha_k = 1\) without damping; under the Wolfe conditions with \(c_1 &amp;lt; 1/2\), the Dennis–Moré condition guarantees \(\alpha_k = 1\) is accepted for all sufficiently large \(k\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trace–Determinant Potential Function (Byrd–Nocedal):&lt;/strong&gt; Proving BFGS satisfies Dennis–Moré uses the Lyapunov potential \(\psi(B) = \operatorname{tr}(B) - \log \det(B)\), showing that even if \(B_k\) starts poorly scaled, the sum \(\sum_k \|(B_k - G^\star) s_k\|^2 / \|s_k\|^2\) is finite—forcing its terms to vanish!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-satisfying-dennismoré-without-b_k-to-gstar&quot;&gt;Worked example: Satisfying Dennis–Moré Without \(B_k \to G^\star\)&lt;/h3&gt;

&lt;p&gt;Suppose the true Hessian at \(x^\star\) is \(G^\star = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}\), and at iteration \(k \ge 1\) our quasi-Newton matrix and step direction are:
\(B_k = \begin{bmatrix} 1 + \frac{1}{k} &amp;amp; 0 \\ 0 &amp;amp; 5 \end{bmatrix}, \qquad p_k = \begin{bmatrix} 1 \\ \frac{1}{k} \end{bmatrix}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check whether \(B_k\) converges to \(G^\star\):&lt;/strong&gt;
\(B_k - G^\star = \begin{bmatrix} \frac{1}{k} &amp;amp; 0 \\ 0 &amp;amp; 3 \end{bmatrix} \implies \|B_k - G^\star\|_2 = 3 \quad \text{for all } k \ge 1.\)
So \(B_k\) &lt;em&gt;never&lt;/em&gt; converges to \(G^\star\)—its second diagonal entry is permanently off by \(150\%\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Now evaluate the Dennis–Moré ratio:&lt;/strong&gt;
\((B_k - G^\star) p_k = \begin{bmatrix} \frac{1}{k} &amp;amp; 0 \\ 0 &amp;amp; 3 \end{bmatrix}\begin{bmatrix} 1 \\ \frac{1}{k} \end{bmatrix} = \begin{bmatrix} \frac{1}{k} \\ \frac{3}{k} \end{bmatrix} \implies \|(B_k - G^\star) p_k\|_2 = \frac{\sqrt{1^2 + 3^2}}{k} = \frac{\sqrt{10}}{k}.\)
Meanwhile, \(\|p_k\|_2 = \sqrt{1 + \frac{1}{k^2}} \ge 1\). Therefore:
\(\frac{\|(B_k - G^\star) p_k\|_2}{\|p_k\|_2} = \frac{\sqrt{10}}{k \sqrt{1 + 1/k^2}} \;\xrightarrow{k \to \infty}\; 0!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical check at \(k = 100\):&lt;/strong&gt;
Matrix error is still \(3.0\), yet the directional Dennis–Moré error is only \(\frac{3.162}{100.005} \approx 0.0316\)—confirming that BFGS only needs accurate curvature in the subspace where the steps actually move!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;assumption-1&quot;&gt;Assumption 1:&lt;/h1&gt;

&lt;blockquote&gt;
  &lt;p&gt;The Hessian matrix \(G\) is Lipschitz continuous at \(x^\ast\), that is,&lt;/p&gt;

\[\| G(x) - G(x^\ast) \| \le L \| x - x^\ast \|,\]

  &lt;p&gt;for all \(x\) near \(x^\ast\), where \(L\) is a positive constant.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;assumption-2-wolfe-conditions&quot;&gt;Assumption 2: Wolfe conditions&lt;/h1&gt;

&lt;blockquote&gt;
  &lt;p&gt;Assume \(t\) is chosen (via backtracking) so that&lt;/p&gt;

\[f(x + tp) \le f(x) + \alpha_1 t \nabla f(x)^T p\]

  &lt;p&gt;and&lt;/p&gt;

\[\nabla f(x + tp)^T p \ge \alpha_2 \nabla f(x)^T p\]

  &lt;p&gt;for \(0 &amp;lt; \alpha_1 &amp;lt; \alpha_2 &amp;lt; 1.\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;The first condition of the Wolfe conditions ensures that too large a \(t\) is not selected.&lt;/li&gt;
  &lt;li&gt;The second condition of the Wolfe conditions ensures that too small a \(t\) is not selected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DFP and BFGS show superlinear convergence under the above two assumptions. (reference: &lt;a href=&quot;https://en.wikipedia.org/wiki/Rate_of_convergence&quot;&gt;Rate of convergence on Wikipedia&lt;/a&gt;)&lt;/p&gt;

&lt;blockquote&gt;
\[\lim_{k \rightarrow \infty} \frac{ \| x^{k+1} - x^\ast \| }{ \| x^k - x^\ast \| } = 0.\]
&lt;/blockquote&gt;

&lt;h1 id=&quot;dennis-moré-theorem&quot;&gt;Dennis-Moré Theorem&lt;/h1&gt;

&lt;p&gt;When the search direction of a quasi-Newton method approximates the Newton direction well enough near the solution, and the step length satisfies the Wolfe conditions during convergence, there is a sufficient condition on the search direction for superlinear convergence [14].&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Assume \(f\) is twice continuously differentiable and \(x^k \rightarrow x^\ast\) such that \(\nabla f(x^\ast) = 0\) and \(\nabla^2 f(x^\ast)\) is positive definite. Suppose&lt;/p&gt;

\[\lim_{k \rightarrow \infty} \frac{\| \nabla f(x^k) + \nabla^2 f(x^k) p^k \| }{\| p^k \|} = 0.\]

  &lt;p&gt;If the search direction \(p^k\) satisfies the condition above, then there is a \(k_0\) such that:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;For \(k \ge k_0\), the step length \(t_k = 1\) satisfies the Wolfe conditions.&lt;/li&gt;
    &lt;li&gt;In that case, for \(k \ge k_0\) with \(t_k = 1\), \(x^k \rightarrow x^\ast\) with superlinear convergence.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>18-05 The Broyden Class</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_05_The_Broyden_Class/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_05_The_Broyden_Class</id>
   <content type="html">&lt;p&gt;Looking at SR1, DFP, and BFGS side by side, it is easy to think of them as three separate algebraic inventions discovered by three different groups of mathematicians. In reality, they are all points on a single one-dimensional line! Any affine combination of \(B^+_{\text{BFGS}}\) and \(B^+_{\text{DFP}}\) still preserves symmetry and still satisfies the secant equation \(B^+ s = y\). That one-parameter family—the &lt;strong&gt;Broyden class&lt;/strong&gt;—unifies almost all classical quasi-Newton methods and reveals a surprising theorem: with exact line searches on a convex quadratic, &lt;em&gt;every&lt;/em&gt; member of the Broyden class generates the exact same sequence of iterates!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-unifying-quasi-newton-updates&quot;&gt;Key ideas: Unifying Quasi-Newton Updates&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Affine Invariance of the Secant Set:&lt;/strong&gt; Because \(\{B^+ : B^+ = (B^+)^T, \; B^+ s = y\}\) is an affine subspace, any combination \(B^+(\phi) = (1 - \phi) B^+_{\text{BFGS}} + \phi B^+_{\text{DFP}}\) automatically stays symmetric and satisfies \(B^+(\phi) s = y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rank-1 Deviation Structure:&lt;/strong&gt; Rewriting the combination as \(B^+(\phi) = B^+_{\text{BFGS}} + \phi (s^T B s)\, v v^T\) with \(v = \frac{y}{y^T s} - \frac{B s}{s^T B s}\) shows that every Broyden-class member differs from BFGS by a single positive semidefinite rank-1 term (for \(\phi \ge 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Restricted Broyden Class (\(\phi \in [0, 1]\)):&lt;/strong&gt; Because both \(B^+_{\text{BFGS}}\) and \(B^+_{\text{DFP}}\) are positive definite when \(B \succ 0\) and \(y^T s &amp;gt; 0\), every convex combination \(\phi \in [0, 1]\) inherits positive definiteness automatically—and enjoys global convergence on convex functions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SR1 as an Exterior Point:&lt;/strong&gt; Setting \(\phi_{\text{SR1}} = \frac{y^T s}{y^T s - s^T B s}\) recovers SR1 identically. Because \(\phi_{\text{SR1}}\) can lie outside \([0, 1]\) (even becoming negative when \(y^T s &amp;lt; s^T B s\)), we see immediately &lt;em&gt;why&lt;/em&gt; SR1 can lose positive definiteness while BFGS and DFP cannot.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-generating-bfgs-dfp-and-sr1-from-one-formula&quot;&gt;Worked example: Generating BFGS, DFP, and SR1 from One Formula&lt;/h3&gt;

&lt;p&gt;Continue with \(B_0 = I_2\), \(s = (1, 0)^T\), \(y = (2, 1)^T\) (so \(y^T s = 2\) and \(s^T B_0 s = 1\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Broyden difference vector \(v\):&lt;/strong&gt;
\(v = \frac{y}{y^T s} - \frac{B_0 s}{s^T B_0 s} = \frac{1}{2}\begin{bmatrix} 2 \\ 1 \end{bmatrix} - \frac{1}{1}\begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ 0.5 \end{bmatrix}.\)
Notice \(v^T s = 0\) automatically—which is why adding any multiple of \(v v^T\) preserves \(B^+(\phi) s = y\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write the entire Broyden family in closed form:&lt;/strong&gt;
Using \(B_1^{\text{BFGS}} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix}\) and \((s^T B_0 s) v v^T = \begin{bmatrix} 0 &amp;amp; 0 \\ 0 &amp;amp; 0.25 \end{bmatrix}\):
\(B_1(\phi) = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 + 0.25\phi \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate at the three landmark values of \(\phi\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;\(\phi = 0\) (BFGS):&lt;/strong&gt; \(B_1(0) = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix}\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;\(\phi = 1\) (DFP):&lt;/strong&gt; \(B_1(1) = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.75 \end{bmatrix}\). (Verify: \(B_1(1)^{-1} = \frac{1}{2.5}\begin{bmatrix} 1.75 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix} = \begin{bmatrix} 0.7 &amp;amp; -0.4 \\ -0.4 &amp;amp; 0.8 \end{bmatrix} = H_1^{\text{DFP}}\)!)&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;\(\phi = \frac{y^T s}{y^T s - s^T B_0 s} = \frac{2}{2 - 1} = 2\) (SR1):&lt;/strong&gt; \(B_1(2) = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}\) — matching our SR1 worked example identically!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bonus check on positive definiteness threshold:&lt;/strong&gt;
\(\det(B_1(\phi)) = 2(1.5 + 0.25\phi) - 1 = 2 + 0.5\phi &amp;gt; 0 \iff \phi &amp;gt; -4\), illustrating that positive definiteness actually persists slightly into \(\phi &amp;lt; 0\) up to the critical threshold \(\phi_c\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Broyden class generalizes BFGS, DFP, and SR1 with the following formula.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Note:&lt;/strong&gt; \(B^+_{\text{BFGS}}\) and \(B^+_{\text{DFP}}\) are the \(B^+\) computed by BFGS and DFP, respectively.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[B^+ = (1 - \phi)B^+_{\text{BFGS}} + \phi B^+_{\text{DFP}}, \text{ for } \phi \in \mathbb{R}.\]
&lt;/blockquote&gt;

&lt;p&gt;Defining \(v\) as \(\frac{y}{y^Ts} - \frac{Bs}{s^TBs}\), the formula above becomes the formula below.&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = B - \frac{Bss^TB}{s^TBs} + \frac{yy^T}{y^Ts} + \phi(s^TBs)vv^T.\]
&lt;/blockquote&gt;

&lt;p&gt;Observe:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;When \(\phi = 0\), the update above is the same as BFGS.&lt;/li&gt;
  &lt;li&gt;When \(\phi = 1\), the update above is the same as DFP.&lt;/li&gt;
  &lt;li&gt;When \(\phi = \frac{y^Ts}{y^Ts - s^TBs}\), the update above is the same as SR1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;*Reference&lt;/strong&gt;: The case where the range of \(\phi\) is restricted to \([0, 1]\) is called the restricted Broyden class [14].&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>18-04 Broyden-Fletcher-Goldfarb-Shanno (BFGS) update</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_04_Broyden_Fletcher_Goldfarb_Shanno_(BFGS)_update/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_04_Broyden_Fletcher_Goldfarb_Shanno_(BFGS)_update</id>
   <content type="html">&lt;p&gt;In 1970, four researchers working independently—Charles Broyden, Roger Fletcher, Donald Goldfarb, and David Shanno—published the exact same algebraic twist on DFP: instead of applying the rank-2 formula to \(H\) (and inverting to get \(B\)), apply it to \(B\) (and invert to get \(H\)). That seemingly innocent symmetry swap created &lt;strong&gt;BFGS&lt;/strong&gt;, widely regarded as the most effective general-purpose smooth unconstrained optimization algorithm of the past half-century, famous for its remarkable ability to self-correct bad Hessian estimates on the fly.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-bfgs-is-the-gold-standard-of-quasi-newton-methods&quot;&gt;Key ideas: Why BFGS Is the Gold Standard of Quasi-Newton Methods&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Exact Algebraic Duality with DFP:&lt;/strong&gt; Swapping \((B, s, y) \leftrightarrow (H, y, s)\) in the DFP formula immediately produces the BFGS Hessian update \(B^+ = B - \frac{B s s^T B}{s^T B s} + \frac{y y^T}{y^T s}\) and its Sherman–Morrison–Woodbury inverse \(H^+ = (I - \rho s y^T) H (I - \rho y s^T) + \rho s s^T\), where \(\rho = 1/(y^T s)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimum-Change Principle on \(H^+\):&lt;/strong&gt; Whereas DFP minimizes the weighted Frobenius change in \(B\), BFGS minimizes \(\|W^{1/2}(H^+ - H)W^{1/2}\|_F\) subject to symmetry and \(H^+ y = s\) (with \(W s = y\)), directly stabilizing the &lt;em&gt;inverse&lt;/em&gt; operator used to generate search steps.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hereditary Positive Definiteness:&lt;/strong&gt; For any \(v \neq 0\), letting \(w = (I - \rho y s^T) v\) gives \(v^T H^+ v = w^T H w + \rho (v^T s)^2 &amp;gt; 0\) whenever \(H \succ 0\) and \(\rho = (y^T s)^{-1} &amp;gt; 0\)—an even cleaner congruence proof than DFP’s.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Superior Self-Correction Property:&lt;/strong&gt; When \(H_k\) has an erroneously large eigenvalue along a step direction, BFGS corrects it in a single update (whereas DFP can take many steps to shrink it), making BFGS far more robust with inexact Wolfe line searches.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-both-b_1-and-h_1-in-bfgs-and-checking-b_1-h_1--i&quot;&gt;Worked example: Computing Both \(B_1\) and \(H_1\) in BFGS and Checking \(B_1 H_1 = I\)&lt;/h3&gt;

&lt;p&gt;Use the exact same inputs as the DFP lesson so you can compare them directly: \(B_0 = H_0 = I_2\), \(s = (1, 0)^T\), \(y = (2, 1)^T\), \(\rho = \frac{1}{y^T s} = \frac{1}{2}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(B_1^{\text{BFGS}}\):&lt;/strong&gt;
With \(s^T B_0 s = 1\) and \(y^T s = 2\):
\(B_1^{\text{BFGS}} = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} - \frac{1}{1}\begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} + \frac{1}{2}\begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix}.\)
Verify secant equation: \(B_1^{\text{BFGS}} s = (2, 1)^T = y\) \(\checkmark\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(H_1^{\text{BFGS}}\) via the congruence formula:&lt;/strong&gt;
First form \(V = I - \rho s y^T = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} - \frac{1}{2}\begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 0 &amp;amp; -0.5 \\ 0 &amp;amp; 1 \end{bmatrix}\).
Since \(H_0 = I\):
\(H_1^{\text{BFGS}} = V V^T + \rho s s^T = \begin{bmatrix} 0.25 &amp;amp; -0.5 \\ -0.5 &amp;amp; 1 \end{bmatrix} + \begin{bmatrix} 0.5 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 0.75 &amp;amp; -0.5 \\ -0.5 &amp;amp; 1.0 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify exact inverse consistency \(B_1^{\text{BFGS}} H_1^{\text{BFGS}} = I_2\):&lt;/strong&gt;
\(\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1.5 \end{bmatrix}\begin{bmatrix} 0.75 &amp;amp; -0.5 \\ -0.5 &amp;amp; 1.0 \end{bmatrix} = \begin{bmatrix} 1.5 - 0.5 &amp;amp; -1 + 1 \\ 0.75 - 0.75 &amp;amp; -0.5 + 1.5 \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} \quad \checkmark\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare directly against DFP:&lt;/strong&gt;
Notice \(H_1^{\text{BFGS}} = \begin{bmatrix} 0.75 &amp;amp; -0.5 \\ -0.5 &amp;amp; 1.0 \end{bmatrix}\) differs from \(H_1^{\text{DFP}} = \begin{bmatrix} 0.7 &amp;amp; -0.4 \\ -0.4 &amp;amp; 0.8 \end{bmatrix}\) even after a &lt;em&gt;single&lt;/em&gt; step from \(I_2\)! Their difference is a pure rank-1 matrix \(\begin{bmatrix} 0.05 &amp;amp; -0.1 \\ -0.1 &amp;amp; 0.2 \end{bmatrix} = 0.2 \begin{bmatrix} -0.5 \\ 1 \end{bmatrix}\begin{bmatrix} -0.5 &amp;amp; 1 \end{bmatrix}\)—which leads directly into the Broyden class!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The idea of BFGS is the same as DFP. The only difference is that the roles of \(B\) and \(H\) are reversed. BFGS is derived by solving the following problem.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Solve
\(\begin{align}
&amp;amp; \min_{H^+} \: \: &amp;amp;&amp;amp; {\|W^{1/2} (H^+ - H) W^{1/2} \|_F} \\\\
&amp;amp; \text{subject to } &amp;amp;&amp;amp; {H^+ = (H^+)^T} \\\\
&amp;amp;&amp;amp;&amp;amp; {H^+y = s}  \\\\
&amp;amp; \text{where } &amp;amp;&amp;amp; W \in \mathbb{R}^{n \; \times \; n} \text{ is nonsingular and such that } Ws_k = y_k.
\end{align}\\\\\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The derived updating formulas for \(H\) and \(B\) are as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = B - \frac{Bss^TB}{s^TBs} + \frac{yy^T}{y^Ts}\]
&lt;/blockquote&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
H^+ &amp;amp;= H + \frac{(s-Hy)s^T}{y^Ts} + \frac{s(s-Hy)^T}{y^Ts} - \frac{(s-Hy)^Ty}{(y^Ts)^2} ss^T\\\\
&amp;amp;= \big( I - \frac{sy^T}{y^Ts} \big) H \big( I - \frac{ys^T}{y^Ts} \big) + \frac{ss^T}{y^Ts}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;BFGS also preserves positive definiteness, just like DFP. (If \(B\) is positive definite and \(s^Ty &amp;gt; 0\), then \(B^+\) is positive definite.)&lt;/p&gt;

&lt;p&gt;An advantage of BFGS is its self-correcting property. If the matrix \(H\) in some iteration is a poor approximation of the inverse Hessian, \(H\) can correct itself within a few more steps. DFP cannot correct itself when the Hessian approximation is wrong, so BFGS usually performs better [14].&lt;/p&gt;

&lt;h3 id=&quot;bfgs-vs-gradient-descent-video&quot;&gt;BFGS vs. gradient descent (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/bfgs-vs-gd_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;BFGS builds up an approximation \(H\) of the inverse Hessian using only gradients, so the step \(-H\nabla f\) behaves like Newton’s step without ever forming the Hessian.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-bfgs-vs-gradient-descent&quot;&gt;Try it yourself: BFGS vs. gradient descent&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;bfgs&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>18-03 Davidon-Fletcher-Powell (DFP) Update</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_03_Davidon_Fletcher_Powell_(DFP)_Update/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_03_Davidon_Fletcher_Powell_(DFP)_Update</id>
   <content type="html">&lt;p&gt;When William Davidon’s 1959 Argonne report was later formalized and publicized by Roger Fletcher and Michael Powell in 1963, the &lt;strong&gt;DFP update&lt;/strong&gt; became the very first practical quasi-Newton algorithm to guarantee &lt;strong&gt;hereditary positive definiteness&lt;/strong&gt;. By upgrading from a rank-1 correction to a carefully crafted &lt;strong&gt;rank-2&lt;/strong&gt; symmetric update directly on the inverse Hessian \(H = B^{-1}\), DFP ensured that every search direction \(p_k = -H_k \nabla f(x^k)\) is automatically a strict descent direction—as long as \(y_k^T s_k &amp;gt; 0\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-mechanics-and-geometry-of-dfp&quot;&gt;Key ideas: The Mechanics and Geometry of DFP&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Direct Inverse-Hessian Updating (\(H^+\)):&lt;/strong&gt; Updating \(H = B^{-1}\) via \(H^+ = H - \frac{H y y^T H}{y^T H y} + \frac{s s^T}{y^T s}\) removes a rank-1 piece along \(Hy\) and adds a rank-1 piece along \(s\), delivering the search direction \(p^+ = -H^+ \nabla f\) in \(O(n^2)\) time with zero linear solves.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hereditary Positive Definiteness:&lt;/strong&gt; If \(H \succ 0\) and \(y^T s &amp;gt; 0\), Cauchy–Schwarz gives \((v^T H v)(y^T H y) \ge (v^T H y)^2\) for all \(v \neq 0\), proving \(v^T H^+ v &amp;gt; 0\) strictly. Descent is mathematically guaranteed at every step.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Variational Minimum-Change Interpretation:&lt;/strong&gt; DFP is the unique symmetric matrix \(B^+\) satisfying \(B^+ s = y\) that minimizes the weighted Frobenius distance \(\|W^{1/2}(B^+ - B)W^{1/2}\|_F\) for any \(W \succ 0\) with \(W y = s\) (for instance, the average inverse Hessian \(\bar{G}^{-1}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why BFGS Eventually Surpassed DFP:&lt;/strong&gt; Although DFP is superlinearly convergent on convex problems, it tends to struggle with large eigenvalues of \(H_k\) (self-correcting slowly when initial curvature is overestimated), motivating its dual twin, BFGS.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-full-dfp-update-and-positive-definiteness-check&quot;&gt;Worked example: One Full DFP Update and Positive-Definiteness Check&lt;/h3&gt;

&lt;p&gt;Start with \(H_0 = I_2\) and observe a step \(s = (1, 0)^T\) with gradient difference \(y = (2, 1)^T\) (curvature \(y^T s = 2 &amp;gt; 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the scalar denominators:&lt;/strong&gt;
\(y^T H_0 y = y^T y = 2^2 + 1^2 = 5, \qquad y^T s = 2(1) + 1(0) = 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the two rank-1 outer products:&lt;/strong&gt;
\(H_0 y (H_0 y)^T = \begin{bmatrix} 2 \\ 1 \end{bmatrix}\begin{bmatrix} 2 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}, \qquad s s^T = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assemble \(H_1^{\text{DFP}}\):&lt;/strong&gt;
\(H_1^{\text{DFP}} = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} - \frac{1}{5}\begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix} + \frac{1}{2}\begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 1 - 0.8 + 0.5 &amp;amp; -0.4 \\ -0.4 &amp;amp; 1 - 0.2 \end{bmatrix} = \begin{bmatrix} 0.7 &amp;amp; -0.4 \\ -0.4 &amp;amp; 0.8 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the inverse secant equation \(H_1^{\text{DFP}} y = s\):&lt;/strong&gt;
\(\begin{bmatrix} 0.7 &amp;amp; -0.4 \\ -0.4 &amp;amp; 0.8 \end{bmatrix}\begin{bmatrix} 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 1.4 - 0.4 \\ -0.8 + 0.8 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} = s \quad \checkmark\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify strict positive definiteness via Sylvester’s criterion:&lt;/strong&gt;
Leading minor \(0.7 &amp;gt; 0\), and determinant \(\det(H_1^{\text{DFP}}) = (0.7)(0.8) - (-0.4)^2 = 0.56 - 0.16 = 0.40 &amp;gt; 0\). Both eigenvalues are strictly positive (\(\lambda_{1,2} = \frac{1.5 \pm \sqrt{0.65}}{2} \approx 1.153, \; 0.347\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The DFP update is a method that updates \(H (=B^{-1})\) with a rank-2 symmetric matrix.&lt;/p&gt;

&lt;blockquote&gt;
\[H^+ = H + auu^T + bvv^T.\]
&lt;/blockquote&gt;

&lt;p&gt;If \(H^+\) computed through the DFP update satisfies the secant equation, then \(s-Hy\) can be expressed as a linear combination of \(u\) and \(v\). (reference: by the secant equation, \(B^+ s =y \Leftrightarrow H^+ y = s\))&lt;/p&gt;

&lt;blockquote&gt;
\[H^+y = Hy + auu^Ty + bvv^Ty = Hy + (au^Ty)u + (bv^Ty)v = s\]

\[\Rightarrow s - Hy = (au^Ty)u + (bv^Ty)v\]
&lt;/blockquote&gt;

&lt;p&gt;Setting \(u=s, v=Hy\) and solving for \(a\) and \(b\), we derive the updating formula for \(H\).&lt;/p&gt;
&lt;blockquote&gt;
\[H^+ = H - \frac{Hyy^TH}{y^THy} + \frac{ss^T}{y^Ts}\]
&lt;/blockquote&gt;

&lt;p&gt;Similar to the SR1 update, we can derive the updating formula for \(B\) using the &lt;a href=&quot;https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula&quot;&gt;Sherman–Morrison formula&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
B^+ &amp;amp;= B + \frac{(y-Bs)y^T}{y^Ts} + \frac{y(y-Bs)^T}{y^Ts} - \frac{(y-Bs)^Ts}{(y^Ts)^2} yy^T\\\\
&amp;amp;= \big( I - \frac{ys^T}{y^Ts} \big) B \big( I - \frac{sy^T}{y^Ts} \big) + \frac{yy^T}{y^Ts} 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;If \(B\) is positive definite, then \(\big( I - \frac{ys^T}{y^Ts} \big) B \big( I - \frac{sy^T}{y^Ts} \big)\) becomes positive semidefinite. In this case, if \(\frac{yy^T}{y^Ts}\) is positive definite, then \(B^+ = \big( I - \frac{ys^T}{y^Ts} \big) B \big( I - \frac{sy^T}{y^Ts} \big) + \frac{yy^T}{y^Ts}\) is guaranteed to be positive definite. This solves the problem of maintaining positive definiteness that was raised with SR1.&lt;/p&gt;

&lt;h2 id=&quot;dfp-update---alternate-derivation&quot;&gt;DFP Update - Alternate Derivation&lt;/h2&gt;

&lt;p&gt;Recall: if the curvature condition (\(y^Ts &amp;gt; 0, y,s \in \mathbb{R}^n\)) is satisfied, then there exists a symmetric positive definite matrix that satisfies the secant equation.&lt;/p&gt;

&lt;p&gt;The DFP update can also be derived by solving the problem of minimizing the weighted Frobenius norm between matrix \(B^+\) and \(B\) where \(B^+\) 1. satisfies symmetry and 2. satisfies the secant equation. (Each different matrix norm corresponds to each different Quasi-Newton method. Among them, the norm that makes it easy to solve this problem while also making it work as a scale-invariant optimization method is the weighted Frobenius norm.)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Solve
\(\begin{align}
&amp;amp; \min_{B^+} \: \: &amp;amp;&amp;amp; {\|W^{1/2} (B^+ - B) W^{1/2} \|_F} \\\\
&amp;amp; \text{subject to } &amp;amp;&amp;amp; {B^+ = (B^+)^T} \\\\
   &amp;amp;&amp;amp;&amp;amp; {B^+s = y}  \\\\
&amp;amp; \text{where } &amp;amp;&amp;amp; W \in \mathbb{R}^{n \; \times \;n} \text{ is nonsingular and such that } Wy_k = s_k.
\end{align}\\\\\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;*reference&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Frobenius norm: The Frobenius norm of matrix \(A\) is defined as follows.
\(\| A \|_{F}  \doteq ( \sum_{i,j} A_{i,j}^2 )^{1/2}\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Weighted Frobenius norm: The weighted Frobenius norm of matrix \(A\) with weight matrix \(W(W \succ 0)\) is defined as follows. 
\(\|A\|_W \doteq \| W^{1/2} A W^{1/2} \|_F\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>18-02 Symmetric Rank-One Update (SR1)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_02_Symmetric_Rank_One_Update_(SR1)/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_02_Symmetric_Rank_One_Update_(SR1)</id>
   <content type="html">&lt;p&gt;Suppose you want the absolute simplest symmetric correction to your Hessian approximation \(B\) that enforces the secant equation \(B^+ s = y\): adding just a &lt;strong&gt;rank-1&lt;/strong&gt; symmetric matrix \(a u u^T\). Remarkably, imposing symmetry and the secant equation leaves &lt;em&gt;zero&lt;/em&gt; free parameters—the &lt;strong&gt;Symmetric Rank-One (SR1)&lt;/strong&gt; formula is completely unique! Even more remarkably, while SR1 can lose positive definiteness (which once made practitioners nervous), that very freedom lets SR1 capture negative curvature in nonconvex trust-region optimization better than BFGS ever could.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-uniqueness-finite-termination-and-trust-region-power&quot;&gt;Key ideas: Uniqueness, Finite Termination, and Trust-Region Power&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Uniqueness of Rank-1 Secant Updates:&lt;/strong&gt; Requiring \(B^+ = B + a u u^T\) to satisfy \(B^+ s = y\) forces \(u\) to be collinear with the secant residual \(y - Bs\), uniquely determining \(B^+ = B + \frac{(y - Bs)(y - Bs)^T}{(y - Bs)^T s}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-Duality Under Sherman–Morrison:&lt;/strong&gt; Applying the Sherman–Morrison formula to \(B^+\) yields the exact same rank-1 template for the inverse Hessian \(H^+ = H + \frac{(s - Hy)(s - Hy)^T}{(s - Hy)^T y}\), just swapping \((B, s, y) \leftrightarrow (H, y, s)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Hessian Recovery on Quadratics:&lt;/strong&gt; For any \(n\)-dimensional quadratic with linearly independent steps (even without exact line searches!), SR1 recovers the &lt;em&gt;exact&lt;/em&gt; Hessian \(B_n = Q\) in at most \(n\) steps—a stronger approximation property than BFGS.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Denominator Breakdown &amp;amp; Safeguard:&lt;/strong&gt; Because \((y - Bs)^T s\) can vanish or change sign even when \(y^T s &amp;gt; 0\), SR1 does not preserve positive definiteness and skips updates whenever $$&lt;/td&gt;
          &lt;td&gt;(y - Bs)^T s&lt;/td&gt;
          &lt;td&gt;&amp;lt; r |s| |y - Bs|\((typically\)r = 10^{-8}$$), making it a natural partner for trust-region methods rather than line search.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-exact-hessian-recovery-in-n--2-sr1-steps&quot;&gt;Worked example: Exact Hessian Recovery in \(n = 2\) SR1 Steps&lt;/h3&gt;

&lt;p&gt;Let \(f(x) = \frac{1}{2} x^T Q x\) with \(Q = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 3 \end{bmatrix}\), and start with \(B_0 = I_2\). Take two arbitrary linearly independent steps \(s_0 = (1, 0)^T\) and \(s_1 = (0, 1)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Step 1 (\(s_0 = (1, 0)^T\)):&lt;/strong&gt;
The true gradient change is \(y_0 = Q s_0 = (2, 1)^T\). Compute the secant residual:
\(r_0 = y_0 - B_0 s_0 = \begin{bmatrix} 2 \\ 1 \end{bmatrix} - \begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 1 \\ 1 \end{bmatrix}.\)
Denominator: \(r_0^T s_0 = (1)(1) + (1)(0) = 1 \neq 0\). Update \(B_1\):
\(B_1 = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} + \frac{1}{1}\begin{bmatrix} 1 \\ 1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}.\)
Verify: \(B_1 s_0 = (2, 1)^T = y_0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 2 (\(s_1 = (0, 1)^T\)):&lt;/strong&gt;
The true gradient change is \(y_1 = Q s_1 = (1, 3)^T\). Compute the new secant residual:
\(r_1 = y_1 - B_1 s_1 = \begin{bmatrix} 1 \\ 3 \end{bmatrix} - \begin{bmatrix} 1 \\ 2 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \end{bmatrix}.\)
Denominator: \(r_1^T s_1 = (0)(0) + (1)(1) = 1 \neq 0\). Update \(B_2\):
\(B_2 = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix} + \frac{1}{1}\begin{bmatrix} 0 \\ 1 \end{bmatrix}\begin{bmatrix} 0 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 3 \end{bmatrix} = Q!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Key insight:&lt;/strong&gt;
In exactly \(n = 2\) rank-1 updates—without needing exact line searches or conjugate directions—SR1 reconstructed the entire \(2 \times 2\) Hessian \(Q\) identically!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The SR1 update is a method that updates \(B\) with a rank-1 symmetric matrix so that \(B^+\) maintains symmetry and continues to satisfy the secant equation. If a rank-1 symmetric matrix is decomposed as a product of \(a \in \left\{-1, 1\right\}\) and \(u \in \mathbb{R^n}\), the update form would be as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = B + auu^T.\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;key-observation&quot;&gt;Key Observation&lt;/h2&gt;
&lt;p&gt;\(a\) and \(u\) must be chosen so that \(B^+\) satisfies the secant equation. Thus, let’s substitute the update form introduced above into the secant equation \(y = B^+s\).&lt;/p&gt;

&lt;blockquote&gt;
\[y = B^+s \Rightarrow y = Bs + (au^Ts)u. \quad \text{--- (1)}\]
&lt;/blockquote&gt;

&lt;p&gt;Since \((au^Ts)\) is a scalar, \(u\) can also be expressed as a product of \(y-Bs\) and an arbitrary scalar \(\delta\) \(\big( u = \delta(y - Bs) \big)\). Let’s substitute \(u\) in (1) with \(\delta(y - Bs)\).&lt;/p&gt;

&lt;blockquote&gt;
\[y-Bs = a\delta^2 \big[ s^T(y - Bs) \big] (y -Bs),\]
&lt;/blockquote&gt;

&lt;p&gt;The parameters \(\delta\) and \(a\) that satisfy the above equation are as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[a = \text{sign} \big[ s^T (y - Bs) \big], \quad \delta = \pm | s^T(y-Bs) |^{-1/2}. \quad \text{--- (2)}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;the-only-sr1-updating-formula&quot;&gt;The Only SR1 Updating Formula&lt;/h2&gt;
&lt;p&gt;Using the information obtained from the key observation, we can derive the unique form of SR1 update ([14] section 6.2). &lt;br /&gt;
\(\big( u = \delta (y - Bs)\) and substituting (2) into \(B^+ = B + auu^T\). \(\big)\)&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = B + \frac{(y-Bs)(y-Bs)^T}{(y-Bs)^Ts}.\]

&lt;/blockquote&gt;

&lt;h2 id=&quot;the-update-formula-for-the-inverse-hessian-approximation&quot;&gt;The Update Formula for the Inverse Hessian Approximation&lt;/h2&gt;

&lt;p&gt;To find \(x^+\), we need to compute \(B^{-1}\).&lt;/p&gt;

&lt;blockquote&gt;
\[x^+ = x + tp = x - tB^{-1}\nabla f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;If we can update \(B^{-1}\) instead of \(B\), wouldn’t we be able to reduce the cost of computing \(B^{-1}\) every time?&lt;/p&gt;

&lt;p&gt;Using the &lt;a href=&quot;https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula&quot;&gt;Sherman–Morrison formula&lt;/a&gt;, we can see through the derivation process that \(B^{-1}\) can also be updated in the same form. (\(H = B^{-1}\))&lt;/p&gt;

&lt;blockquote&gt;
\[H^+ = H + \frac{(s-Hy)(s-Hy)^T}{(s-Hy)^Ty}.\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;shortcomings-of-sr1&quot;&gt;Shortcomings of SR1&lt;/h2&gt;

&lt;p&gt;SR1 has the advantage of being very simple, but it has two critical shortcomings.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The update can fail when \((y-Bs)^Ts\) approaches 0.&lt;/li&gt;
  &lt;li&gt;It cannot maintain the positive definiteness of \(B\) and \(H\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The following sections introduce methods that complement the shortcomings of SR1.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>18-01 Secant Equation and Curvature Condition</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_01_Secant_Equation_and_Curvature_Condition/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_01_Secant_Equation_and_Curvature_Condition</id>
   <content type="html">&lt;p&gt;In single-variable calculus, when you do not know the second derivative \(f&apos;&apos;(x)\), you approximate it by the slope of the secant line connecting two gradients: \(b_{k+1} = \frac{f&apos;(x^{k+1}) - f&apos;(x^k)}{x^{k+1} - x^k}\). Lifting that elementary ratio to \(\mathbb{R}^n\) yields the &lt;strong&gt;secant equation&lt;/strong&gt; \(B_{k+1} s_k = y_k\)—a linear system that is &lt;em&gt;wildly&lt;/em&gt; underdetermined in high dimensions (only \(n\) equations for \(n(n+1)/2\) symmetric entries) and has a positive-definite solution if and only if the &lt;strong&gt;curvature condition&lt;/strong&gt; \(y_k^T s_k &amp;gt; 0\) holds.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-of-the-secant--curvature-conditions&quot;&gt;Key ideas: Geometry of the Secant &amp;amp; Curvature Conditions&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Multivariate Secant Equation (\(B_{k+1} s_k = y_k\)):&lt;/strong&gt; By Taylor’s theorem, \(y_k = \nabla f(x^{k+1}) - \nabla f(x^k) = \left(\int_0^1 \nabla^2 f(x^k + \tau s_k)\,d\tau\right) s_k\). Requiring \(B_{k+1} s_k = y_k\) forces our Hessian model to match the exact &lt;em&gt;average&lt;/em&gt; curvature along the most recent step \(s_k\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why \(B_{k+1}\) Is Underdetermined:&lt;/strong&gt; In \(\mathbb{R}^n\), symmetry leaves \(\frac{n(n+1)}{2}\) unknowns while \(B_{k+1} s_k = y_k\) supplies only \(n\) scalar equations. Different quasi-Newton updates (SR1, DFP, BFGS) differ purely in &lt;em&gt;how&lt;/em&gt; they resolve the remaining \(\frac{n(n-1)}{2}\) degrees of freedom (e.g., minimum Frobenius-norm change from \(B_k\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Curvature Condition (\(y_k^T s_k &amp;gt; 0\)):&lt;/strong&gt; If \(B_{k+1} \succ 0\) satisfies \(B_{k+1} s_k = y_k\), then necessarily \(s_k^T y_k = s_k^T B_{k+1} s_k &amp;gt; 0\). Conversely, whenever \(y_k^T s_k &amp;gt; 0\), infinitely many SPD matrices satisfy the secant equation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Line Search as the Guardian of Positive Definiteness:&lt;/strong&gt; For strictly convex functions, \(y_k^T s_k &amp;gt; 0\) holds automatically; for nonconvex objectives, enforcing the &lt;strong&gt;Wolfe curvature condition&lt;/strong&gt; \(\nabla f(x^{k+1})^T s_k \ge c_2 \nabla f(x^k)^T s_k\) (with \(c_2 \in (0, 1)\)) guarantees \(y_k^T s_k \ge (c_2 - 1)\nabla f(x^k)^T s_k &amp;gt; 0\) whenever \(s_k\) is a descent direction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-checking-the-secant--curvature-conditions&quot;&gt;Worked example: Checking the Secant &amp;amp; Curvature Conditions&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Part A (Convex 2D quadratic):&lt;/strong&gt; Let \(f(x) = \frac{1}{2}x_1^2 + 2x_2^2 + x_1 x_2\), so \(\nabla f(x) = \begin{bmatrix} x_1 + x_2 \\ x_1 + 4x_2 \end{bmatrix}\). Suppose we step from \(x^0 = (1, 1)^T\) to \(x^1 = (0, 0.5)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute displacement \(s_0\) and gradient difference \(y_0\):&lt;/strong&gt;
\(s_0 = x^1 - x^0 = \begin{bmatrix} -1 \\ -0.5 \end{bmatrix}, \qquad \nabla f(x^0) = \begin{bmatrix} 2 \\ 5 \end{bmatrix}, \quad \nabla f(x^1) = \begin{bmatrix} 0.5 \\ 2 \end{bmatrix} \implies y_0 = \begin{bmatrix} -1.5 \\ -3 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the curvature condition:&lt;/strong&gt;
\(y_0^T s_0 = (-1.5)(-1) + (-3)(-0.5) = 1.5 + 1.5 = 3.0 &amp;gt; 0.\)
Because \(y_0^T s_0 &amp;gt; 0\), an SPD secant matrix exists—for example, the true Hessian \(Q = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 4 \end{bmatrix}\) satisfies \(Q s_0 = \begin{bmatrix} -1.5 \\ -3 \end{bmatrix} = y_0\), and even the diagonal matrix \(D = \operatorname{diag}(1.5, 6)\) satisfies \(D s_0 = y_0\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Part B (Nonconvex breakdown):&lt;/strong&gt; Now test \(g(x) = x^3 - 3x\) (\(g&apos;(x) = 3x^2 - 3\)) from \(x^0 = -1\) to \(x^1 = 0\).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(s_0 = 1\), \(y_0 = g&apos;(0) - g&apos;(-1) = -3 - 0 = -3\).&lt;/li&gt;
  &lt;li&gt;Here \(y_0^T s_0 = -3 &amp;lt; 0\) because \(g\) is &lt;em&gt;concave&lt;/em&gt; on \([-1, 0]\). No positive-definite \(B_1 &amp;gt; 0\) can satisfy \(B_1(1) = -3\), which is why BFGS either relies on a Wolfe line search to avoid this region or skips the update.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;secant-equation&quot;&gt;Secant Equation&lt;/h1&gt;

&lt;p&gt;As mentioned earlier, \(B\) is a matrix that approximates \(\nabla^2 f(x)\). For the matrix \(B\) to have properties similar to the Hessian \(\nabla^2 f(x)\), it must satisfy a condition called the secant equation.&lt;/p&gt;

&lt;p&gt;When \(x^{k+1} = x^k + s^k\) and \(f\) is twice differentiable, the first-order Taylor expansion of \(\nabla f(x^k + s^k)\) shows that the true Hessian has the following property.&lt;/p&gt;

&lt;blockquote&gt;
\[\nabla f(x^k + s^k) \approx \nabla f(x^k) + \nabla^2 f(x^k) s^k\]
&lt;/blockquote&gt;

&lt;p&gt;Here, we call the approximation matrix of \(\nabla^2 f(x^k)\) as \(B^{k+1}\). This matrix satisfies the following equation.&lt;/p&gt;

&lt;blockquote&gt;
\[\nabla f(x^k + s^k) = \nabla f(x^k) + B^{k+1} s^k\]
&lt;/blockquote&gt;

&lt;p&gt;If \(x^{k+1} = x^k + s^k\) and \(y^k = \nabla f(x^{k+1}) - \nabla f(x^k)\), the equation above can be rearranged as follows, and this is called the secant equation.&lt;/p&gt;

&lt;blockquote&gt;
\[B^{k+1} s^k = y^k\]
&lt;/blockquote&gt;

&lt;h1 id=&quot;the-intuition-of-the-secant-equation&quot;&gt;The Intuition of the Secant Equation&lt;/h1&gt;

&lt;p&gt;When \(x\) is the horizontal axis and \(\nabla f(x)\) is the vertical axis, \(B^{k+1}\) equals the slope of the line through the two points \((x^k, \nabla f(x^k))\) and \((x^{k+1}, \nabla f(x^{k+1}))\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter18/intuition_of_secant_eq.png&quot; alt=&quot;[Fig1] The intuition of the secant equation&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] The intuition of the secant equation&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h1 id=&quot;conditions-to-determine-the-matrix-b&quot;&gt;Conditions to Determine the Matrix \(B^+\)&lt;/h1&gt;

&lt;p&gt;Starting from the current matrix \(B\), there are three conditions for computing the next matrix \(B^+\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;\(B^+\) is symmetric: because it is an approximation of the Hessian.&lt;/li&gt;
  &lt;li&gt;\(B^+\) is close to \(B\): a condition that determines a unique \(B^+\). Since \(B\) already contains useful information, we choose the matrix closest to \(B\) among those \(B^+\) that satisfy the secant equation.&lt;/li&gt;
  &lt;li&gt;\(B\) is positive definite \(\Rightarrow B^+\) is positive definite: to guarantee a global optimum, we maintain the convexity of the problem. (reference: &lt;a href=&quot;https://web.stanford.edu/group/sisl/k12/optimization/MO-unit4-pdfs/4.10applicationsofhessians.pdf&quot;&gt;Analyzing the Hessian&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;curvature-condition&quot;&gt;Curvature Condition&lt;/h1&gt;

&lt;p&gt;The fact that \(B^+\) is positive definite and \(B^+ s = y\) implies the following.&lt;/p&gt;

&lt;blockquote&gt;
\[s^T y = s^T B^+ s &amp;gt; 0.\]
&lt;/blockquote&gt;

&lt;p&gt;(reference: &lt;a href=&quot;https://en.wikipedia.org/wiki/Positive-definite_matrix&quot;&gt;Positive-definite matrix on Wikipedia&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Here, \(s^T y &amp;gt; 0\) is called the curvature condition. If the curvature condition is satisfied, the secant equation \(B^+ s = y\) always has a solution \(B^+\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>18-00 Quasi-Newton methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_00_Quasi_Newton_methods/"/>
   <updated>2021-03-23T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter18/18_00_Quasi_Newton_methods</id>
   <content type="html">&lt;p&gt;Picture yourself descending a misty mountain valley shaped like a long, narrow banana. Gradient descent looks only at the local slope under your boots and zig-zags endlessly from wall to wall. Newton’s method surveys the entire bowl’s exact curvature—computing all \(n(n+1)/2\) second derivatives and inverting an \(n \times n\) Hessian at every step—which is miraculous in \(n = 10\) dimensions and completely infeasible in \(n = 50{,}000\) dimensions. &lt;strong&gt;Quasi-Newton methods&lt;/strong&gt; pull off one of the greatest bargains in numerical optimization: using &lt;em&gt;only&lt;/em&gt; the gradients you already compute, they build a running low-rank portrait of the curvature that achieves superlinear convergence at \(O(n^2)\) (or even \(O(n)\)) cost per step.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-quasi-newton-sits-between-gd-and-newton&quot;&gt;Key ideas: Why Quasi-Newton Sits Between GD and Newton&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;The Curvature–Cost Trade-Off:&lt;/strong&gt; First-order methods cost \(O(n)\) per step but suffer slow linear convergence \(O(\kappa \log(1/\epsilon))\) when the condition number \(\kappa = L/\mu\) is large. Exact Newton eliminates \(\kappa\)-dependence (quadratic local convergence) but pays \(O(n^3)\) to factor \(\nabla^2 f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Learning Curvature from Gradient Differences:&lt;/strong&gt; Every step \(s_k = x^{k+1} - x^k\) produces a gradient change \(y_k = \nabla f(x^{k+1}) - \nabla f(x^k)\), which reveals the directional curvature \(\nabla^2 f(x^k)\, s_k \approx y_k\) for free.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Low-Rank Symmetric Updates (\(O(n^2)\) per step):&lt;/strong&gt; Instead of recomputing a Hessian from scratch, methods like SR1, DFP, and BFGS apply a rank-1 or rank-2 update to the current approximation \(B_k\) (or directly to its inverse \(H_k = B_k^{-1}\)), avoiding \(O(n^3)\) matrix inversions altogether.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Superlinear Convergence Without Second Derivatives:&lt;/strong&gt; Under mild smoothness and Wolfe line-search conditions, BFGS attains &lt;em&gt;superlinear&lt;/em&gt; convergence—closing the gap between linear gradient descent and quadratic Newton while never differentiating twice.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-comparing-gd-newton-and-quasi-newton-on-an-ill-conditioned-bowl&quot;&gt;Worked example: Comparing GD, Newton, and Quasi-Newton on an Ill-Conditioned Bowl&lt;/h3&gt;

&lt;p&gt;Consider \(f(x) = \frac{1}{2}(x_1^2 + 100 x_2^2)\) starting at \(x^0 = (10, 1)^T\) (exact optimum \(x^\star = (0, 0)\), condition number \(\kappa = 100\)). Here \(\nabla f(x^0) = (10, 100)^T\) and \(f(x^0) = 100\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Exact-line-search Gradient Descent step:&lt;/strong&gt;
Along \(p_{\text{GD}} = -\nabla f(x^0) = (-10, -100)^T\), the exact optimal step size is:
\(t^\star = \frac{p^T p}{p^T Q p} = \frac{100 + 10{,}000}{100 + 1{,}000{,}000} = \frac{10{,}100}{1{,}000{,}100} \approx 0.0101.\)
Thus \(x^1_{\text{GD}} \approx (9.899, -0.010)^T\), with \(f(x^1_{\text{GD}}) \approx 49.0\)—barely halving the loss because \(x_1\) moved by only \(1\%\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Newton step:&lt;/strong&gt;
Using \(Q^{-1} = \operatorname{diag}(1, 0.01)\), \(p_{\text{N}} = -Q^{-1}\nabla f(x^0) = (-10, -1)^T\), reaching \(x^1_{\text{N}} = (0, 0)\) in &lt;strong&gt;one step&lt;/strong&gt;—at the price of knowing and inverting \(Q\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quasi-Newton intuition (2 steps without knowing \(Q\)):&lt;/strong&gt;
Starting from \(H_0 = I\), the first step \(s_0 = x^1_{\text{GD}} - x^0 \approx (-0.101, -1.010)^T\) observes \(y_0 = \nabla f(x^1) - \nabla f(x^0) \approx (-0.101, -101.0)^T\). Instantly, the ratio \(y_{0,2}/s_{0,2} = 100\) tells the BFGS update that the \(x_2\) direction is \(100\times\) steeper than \(x_1\), reshaping \(H_1\) so the &lt;em&gt;very next&lt;/em&gt; step points straight to \((0, 0)\)—solving this \(2\)-variable quadratic exactly in \(2\) gradient evaluations!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the mid-1950s, physicist W.C. Davidon, who was working at Argonne National Laboratory, was solving optimization problems with large computational requirements using coordinate descent methods. Unfortunately, due to the instability of computers at the time, system crashes frequently occurred before computations could be completed, and frustrated by this, Davidon decided to find methods that could improve computational speed. This led to the birth of the first Quasi-Newton algorithm. This became a catalyst for dramatic progress in nonlinear optimization, and subsequently, various follow-up studies on this method emerged over the next 20 years.&lt;/p&gt;

&lt;p&gt;Ironically, &lt;a href=&quot;http://www.math.mcgill.ca/dstephens/680/Papers/Davidon91.pdf&quot;&gt;Davidon’s research&lt;/a&gt; was not published at the time and remained as a technical report for more than 30 years. It was finally published in the &lt;a href=&quot;https://epubs.siam.org/toc/sjope8/1/1&quot;&gt;first issue of SIAM Journal on Optimization&lt;/a&gt; in 1991.&lt;/p&gt;

&lt;p&gt;Quasi-Newton methods require only the gradient of the objective function at each iteration. This has much less computational burden than Newton methods that require second derivatives, and moreover shows superlinear convergence, making it a sufficiently attractive method [14].&lt;/p&gt;

&lt;h2 id=&quot;motivation-for-quasi-newton-methods&quot;&gt;Motivation for Quasi-Newton methods&lt;/h2&gt;

&lt;p&gt;Consider the following unconstrained, smooth optimization problem:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_x \: f(x), \\\\
\text{where } f \text{ is twice differentiable, and } dom \; f = \mathbb{R}^n.\]
&lt;/blockquote&gt;

&lt;p&gt;The update methods for x in Gradient descent method and Newton’s method for the above problem are as follows:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Gradient descent method:&lt;/strong&gt;
\(x^+ = x - t \nabla f(x)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Newton’s method:&lt;/strong&gt;
\(x^+ = x - t \nabla^2 f(x)^{-1} \nabla f(x)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Newton’s method has the advantage of showing quadratic convergence rate (\(O(\log \log 1/ \epsilon)\)), but there are problems with significantly high computational costs in the following two processes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Computing the Hessian \(\nabla^2 f(x)\): Computing and storing the Hessian matrix requires \(O(n^2)\) memory. This is not suitable performance for handling high-dimensional functions. (reference: &lt;a href=&quot;https://en.wikipedia.org/wiki/Hessian_matrix#Use_in_optimization&quot;&gt;Hessian matrix&lt;/a&gt; in Wikipedia)&lt;/li&gt;
  &lt;li&gt;Solving the equation \(\nabla^2 f(x) p = -\nabla f(x)\): To solve this equation, we must compute the inverse matrix of the Hessian \(\nabla^2 f(x)\). (reference: &lt;a href=&quot;https://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations#Matrix_algebra&quot;&gt;Computational complexity of Matrix algebra&lt;/a&gt; in Wikipedia)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quasi-Newton methods use an approximation \(B\) instead of \(\nabla^2 f(x)\).&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Quasi-Newton method:&lt;/strong&gt;
\(x^+ = x + tp \\\\
\text{where } Bp = -\nabla f(x).\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, B should be easy to compute, and it should also be easy to solve the equation \(Bp = g\).&lt;/p&gt;

&lt;h2 id=&quot;quasi-newton-algorithm&quot;&gt;Quasi-Newton Algorithm&lt;/h2&gt;
&lt;p&gt;The Quasi-Newton algorithm is as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Pick initial \(x^0\) and \(B^0\)&lt;/li&gt;
  &lt;li&gt;For \(k = 0, 1, \dots\)
    &lt;ul&gt;
      &lt;li&gt;Solve \(B^k p^k = - \nabla f(x^k)\)&lt;/li&gt;
      &lt;li&gt;Pick \(t_k\) and let \(x^{k+1} = x^{k} + t_k p^k\)&lt;/li&gt;
      &lt;li&gt;Update \(B^k\) to \(B^{k+1}\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;End for&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A major characteristic of this method is updating \(B\) so that we can gradually approach the optimal point. That is, the method of obtaining the next step \(B^+\) from \(B\) will be the main topic of discussion in this chapter. (&lt;strong&gt;Note:&lt;/strong&gt; For convenience, we will use the two notations \(B^{k+1}, B^k\) and \(B^+, B\) interchangeably.)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>10 Tính Đối Ngẫu trong Quy Hoạch Tuyến Tính</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_Duality_in_Linear_Programs/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_Duality_in_Linear_Programs</id>
   <content type="html">&lt;p&gt;Mùa thu năm 1947, khi George Dantzig — cha đẻ của thuật toán đơn hình (simplex) — đến thăm Viện Nghiên cứu Cao cấp Princeton để trình bày mô hình quy hoạch tuyến tính (LP) vừa phát minh cho huyền thoại John von Neumann, một khoảnh khắc lịch sử đã xảy ra. Nghe Dantzig trình bày chưa đầy nửa giờ, von Neumann lập tức phác thảo ngay trên bảng đen một “bài toán song sinh” đi kèm mọi bài toán LP — bài toán mà sau này cả thế giới gọi là &lt;strong&gt;bài toán đối ngẫu (dual problem)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Tính đối ngẫu là một trong những phép màu kỳ diệu nhất của toán học hiện đại: nó biến câu hỏi &lt;em&gt;“Làm sao phân bổ tài nguyên để tối đa hóa lợi nhuận?”&lt;/em&gt; thành câu hỏi gương phản chiếu &lt;em&gt;“Mỗi đơn vị tài nguyên thực sự đáng giá bao nhiêu (giá bóng — shadow price)?”&lt;/em&gt; Chương 10 sẽ dẫn bạn đi từ trực giác sơ cấp về cận dưới, sang định lý đối ngẫu mạnh, rồi chứng kiến cách một khái niệm duy nhất thống nhất cả định lý luồng cực đại – lát cắt cực tiểu trong lý thuyết đồ thị lẫn định lý minimax của von Neumann trong lý thuyết trò chơi!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tính-đối-ngẫu-trong-quy-hoạch-tuyến-tính&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tính đối ngẫu trong Quy hoạch tuyến tính&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán gốc (Primal) và bài toán đối ngẫu (Dual):&lt;/strong&gt; Mọi bài toán LP đều có một bản sao đối ngẫu được xây dựng thuần túy từ ma trận ràng buộc và vector mục tiêu: biến gốc ứng với ràng buộc đối ngẫu, và ràng buộc gốc ứng với biến đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính đối ngẫu yếu và mạnh (Weak &amp;amp; Strong Duality):&lt;/strong&gt; Giá trị khả thi bất kỳ của bài toán đối ngẫu (cực đại hóa) luôn chặn dưới mọi giá trị khả thi của bài toán gốc (cực tiểu hóa): \(d \le p\). Với LP, chỉ cần một trong hai bài toán có nghiệm tối ưu hữu hạn, khoảng cách giữa chúng bằng đúng \(0\) (\(d^* = p^*\))!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa kinh tế — Giá bóng (Shadow Prices):&lt;/strong&gt; Nghiệm đối ngẫu tối ưu \(u_i^*\) đo chính xác độ nhạy \(\frac{\partial p^*}{\partial b_i}\) — tức mức tăng giá trị tối ưu nếu ta nới thêm một đơn vị tài nguyên thứ \(i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù (Complementary Slackness) và tính đối hợp:&lt;/strong&gt; Ở điểm tối ưu, ràng buộc gốc nào còn dư thừa thì giá bóng tương ứng bằng \(0\) (và ngược lại); đồng thời lấy đối ngẫu của bài toán đối ngẫu sẽ quay về đúng bài toán gốc ban đầu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-cặp-bài-toán-gốc--đối-ngẫu-trên-một-xưởng-mộc-nhỏ&quot;&gt;Giải thích: Cặp bài toán gốc – đối ngẫu trên một xưởng mộc nhỏ&lt;/h3&gt;

&lt;p&gt;Một xưởng mộc làm bàn (\(x_1\)) và ghế (\(x_2\)) từ một nguồn gỗ duy nhất có trữ lượng \(10\) m³:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Mỗi bàn cần \(2\) m³ gỗ, lãi \(4\) triệu đồng.&lt;/li&gt;
  &lt;li&gt;Mỗi ghế cần \(1\) m³ gỗ, lãi \(1.5\) triệu đồng.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán gốc (Góc nhìn chủ xưởng — tối đa hóa lợi nhuận):&lt;/strong&gt;
\(\max_{x_1, x_2 \ge 0} \; 4 x_1 + 1.5 x_2 \quad \text{s.t.} \quad 2 x_1 + x_2 \le 10.\)
Vì bàn mang lại \(4/2 = 2\) triệu/m³ còn ghế chỉ \(1.5/1 = 1.5\) triệu/m³, chủ xưởng đóng toàn bộ \(5\) bàn (\(x^* = (5, 0)\)) và thu lợi nhuận tối đa \(p^* = 20\) triệu đồng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán đối ngẫu (Góc nhìn nhà đầu tư muốn mua lại toàn bộ kho gỗ với giá \(u \ge 0\) triệu/m³):&lt;/strong&gt;
Để chủ xưởng đồng ý bán gỗ thay vì tự đóng đồ, giá \(u\) phải hấp dẫn hơn cả hai phương án sản xuất:
    &lt;ul&gt;
      &lt;li&gt;Bán \(2\) m³ gỗ phải thu ít nhất bằng lãi 1 bàn: \(2u \ge 4 \implies u \ge 2\).&lt;/li&gt;
      &lt;li&gt;Bán \(1\) m³ gỗ phải thu ít nhất bằng lãi 1 ghế: \(u \ge 1.5\).
Nhà đầu tư muốn chi ít nhất để mua \(10\) m³ gỗ: \(\min_{u \ge 0} 10u\) sao cho \(u \ge 2, u \ge 1.5\).
Nghiệm tối ưu là \(u^* = 2\) triệu/m³, tổng chi phí \(d^* = 10 \times 2 = 20\) triệu đồng = \(p^*\)! Giá trị kho gỗ dưới hai góc nhìn khớp nhau tuyệt đối.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Từ chương này, chúng ta bắt đầu tìm hiểu về tính đối ngẫu (duality) — một khái niệm nền tảng trong lý thuyết tối ưu hóa. Trong tối ưu hóa, tính đối ngẫu cho phép xem xét một bài toán từ hai góc độ song hành: bài toán gốc (primal problem) và bài toán đối ngẫu (dual problem).&lt;/p&gt;

&lt;p&gt;Trong chương này, chúng ta tập trung vào tính đối ngẫu trong quy hoạch tuyến tính (LP). Thay vì xét ngay các bài toán lồi tổng quát, ta sẽ xây dựng bài toán đối ngẫu trực tiếp từ bài toán quy hoạch tuyến tính gốc, đồng thời làm rõ mối liên hệ giữa hai bài toán và các tính chất tương ứng trong những điều kiện cụ thể.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-hiện-đại-20222026&quot;&gt;Ứng dụng hiện đại (2022–2026)&lt;/h2&gt;

&lt;p&gt;Bài đọc tùy chọn đi kèm trình bày vai trò của đối ngẫu LP như một chứng chỉ trong kiểm chứng mạng nơ-ron (α,β-CROWN), định giá biên theo vị trí (LMP) trên thị trường điện, bài toán luồng cực đại – lát cắt cực tiểu và vận chuyển tối ưu Kantorovich. Xem &lt;a href=&quot;/contents/vi/chapter10/10_07_modern_applications/&quot;&gt;10-07 Ứng dụng hiện đại của đối ngẫu LP&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>10-09 Bài Tập Thực Hành - Tính Đối Ngẫu trong Quy Hoạch Tuyến Tính</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_09_Practical_Exercises_LP_Duality/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_09_Practical_Exercises_LP_Duality</id>
   <content type="html">&lt;p&gt;Biết viết bài toán đối ngẫu trên giấy mới chỉ là bước khởi động; sức mạnh thực sự của đối ngẫu LP nằm ở việc &lt;strong&gt;dùng nó để giải nhanh bài toán, phân tích độ nhạy kinh tế và kiểm định tính tối ưu&lt;/strong&gt; trong thực hành. Bộ bài tập thực hành Chương 10 dưới đây tuyển chọn những bài toán kinh điển nhất từ Boyd &amp;amp; Vandenberghe, Bertsimas &amp;amp; Tsitsiklis và Dantzig — trải dài từ lập kế hoạch sản xuất, tối ưu danh mục đầu tư, đến chứng minh tối ưu bằng điều kiện bù.&lt;/p&gt;

&lt;p&gt;Điểm đặc biệt giúp bạn giải nhanh bộ bài tập này là kỹ năng &lt;strong&gt;đọc nghiệm đối ngẫu từ nghiệm gốc bằng điều kiện bù (Complementary Slackness)&lt;/strong&gt; mà không cần chạy lại thuật toán đơn hình từ đầu. Khung tính tay dưới đây minh họa trọn vẹn kỹ thuật cực kỳ hữu ích ấy chỉ trong vài dòng!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-kỹ-năng-thực-chiến-cần-dùng-trong-bộ-bài-tập-thực-hành&quot;&gt;Kiến thức cần nhớ: Bốn kỹ năng thực chiến cần dùng trong bộ bài tập thực hành&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển đổi dạng hỗn hợp sang bài toán đối ngẫu không sai dấu:&lt;/strong&gt; Thành thạo viết bảng đối chiếu giữa 3 loại ràng buộc gốc (\(\le, =, \ge\)) và 3 loại miền biến gốc (\(\ge 0, \text{tự do}, \le 0\)) sang bài toán đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm định tối ưu bằng chứng chỉ cặp Primal–Dual:&lt;/strong&gt; Để chứng minh \(x^*\) là tối ưu, chỉ cần tìm một điểm đối ngẫu khả thi \(u^*\) sao cho \(c^T x^* = b^T u^*\) — phương pháp ngắn gọn và thuyết phục tuyệt đối.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khai thác hệ phương trình điều kiện bù (Complementary Slackness):&lt;/strong&gt; Tại nghiệm tối ưu, \(u_i^*(a_i^T x^* - b_i) = 0\) và \(x_j^*(c_j - (A^T u^*)_j) = 0\). Khi biết các biến gốc dương và ràng buộc gốc chặt, hệ bất đẳng thức đối ngẫu thu gọn thành một &lt;strong&gt;hệ phương trình tuyến tính&lt;/strong&gt; giải ra ngay \(u^*\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích độ nhạy (Sensitivity Analysis):&lt;/strong&gt; Dùng nghiệm đối ngẫu \(u^*\) để trả lời các câu hỏi kinh doanh như &lt;em&gt;“Nên mua thêm bao nhiêu nguyên liệu với giá tối đa bao nhiêu?”&lt;/em&gt; hay &lt;em&gt;“Nên mở thêm sản phẩm mới không?”&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-dùng-điều-kiện-bù-để-tìm-nhanh-giá-bóng-u-từ-nghiệm-gốc&quot;&gt;Giải thích: Dùng điều kiện bù để tìm nhanh giá bóng \(u^*\) từ nghiệm gốc&lt;/h3&gt;

&lt;p&gt;Giả sử trong bài toán lập kế hoạch sản xuất:
\(\max_{x_1, x_2 \ge 0} \; 5x_1 + 4x_2 \quad \text{s.t.} \quad \begin{cases} x_1 + x_2 \le 6 &amp;amp; (\text{nguyên liệu A, giá bóng } u_1 \ge 0) \\ 2x_1 + x_2 \le 10 &amp;amp; (\text{giờ máy B, giá bóng } u_2 \ge 0) \\ x_2 \le 5 &amp;amp; (\text{hạn mức thị trường, giá bóng } u_3 \ge 0) \end{cases}\)
Bạn đã tìm ra nghiệm gốc tối ưu là \(x^* = (4, 2)\) với lợi nhuận \(5(4) + 4(2) = 28\). Hãy tìm nhanh \(u^* = (u_1^*, u_2^*, u_3^*)\) mà không cần giải lại LP đối ngẫu!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra độ chặt của các ràng buộc gốc tại \(x^* = (4, 2)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ràng buộc 1: \(4 + 2 = 6\) (&lt;strong&gt;chặt&lt;/strong&gt;).&lt;/li&gt;
      &lt;li&gt;Ràng buộc 2: \(2(4) + 2 = 10\) (&lt;strong&gt;chặt&lt;/strong&gt;).&lt;/li&gt;
      &lt;li&gt;Ràng buộc 3: \(x_2^* = 2 &amp;lt; 5\) (&lt;strong&gt;lỏng&lt;/strong&gt;, dư 3 đơn vị) \(\implies\) theo điều kiện bù, chắc chắn \(u_3^* = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng điều kiện bù cho các biến gốc dương (\(x_1^* = 4 &amp;gt; 0, x_2^* = 2 &amp;gt; 0\)):&lt;/strong&gt;
Hai ràng buộc đối ngẫu tương ứng phải trở thành &lt;strong&gt;đẳng thức&lt;/strong&gt;:
\(\begin{cases} u_1^* + 2u_2^* = 5 \\ u_1^* + u_2^* + u_3^* = 4 \end{cases}\)
Thay \(u_3^* = 0\) vào hệ, trừ vế theo vế ta được ngay: \(u_2^* = 1\) và \(u_1^* = 3\) (cả hai đều \(\ge 0\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng đối ngẫu mạnh:&lt;/strong&gt;
Giá trị hàm mục tiêu đối ngẫu: \(6 u_1^* + 10 u_2^* + 5 u_3^* = 6(3) + 10(1) + 5(0) = 28 = p^*\)!
Ý nghĩa kinh tế đọc ngay ra được: mỗi đơn vị nguyên liệu A tăng thêm mang lại \(3\) đơn vị lợi nhuận, mỗi giờ máy B thêm mang lại \(1\) đơn vị, còn tăng hạn mức thị trường \(x_2 \le 5\) chẳng tăng thêm đồng nào (\(u_3^* = 0\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các bài tập dưới đây được tham khảo từ Boyd &amp;amp; Vandenberghe (2004), Bertsimas &amp;amp; Tsitsiklis (1997) và Dantzig (1963), giúp rèn luyện các kỹ năng xây dựng và vận dụng tính đối ngẫu trong quy hoạch tuyến tính (LP).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-i-xây-dựng-bài-toán-đối-ngẫu&quot;&gt;Phần I: Xây dựng bài toán đối ngẫu&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-các-dạng-lp-cơ-bản-boyd--vandenberghe-ex-51&quot;&gt;Bài tập 1: Các dạng LP cơ bản (Boyd &amp;amp; Vandenberghe, Ex. 5.1)&lt;/h3&gt;

&lt;p&gt;Với các bài toán LP sau, hãy lập bài toán đối ngẫu và nêu ý nghĩa của các biến đối ngẫu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a) Dạng chuẩn:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; 3x_1 + 5x_2 + 2x_3 \\
\text{s.t.} \quad &amp;amp; x_1 + 2x_2 + x_3 = 4 \\
&amp;amp; 2x_1 + x_2 + 3x_3 = 5 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;b) Dạng bất đẳng thức:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; 2x_1 + 4x_2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 \geq 3 \\
&amp;amp; 2x_1 + x_2 \geq 5 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;c) Dạng hỗn hợp:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x_1 + 2x_2 + 3x_3 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 = 2 \\
&amp;amp; x_2 + x_3 \leq 3 \\
&amp;amp; x_1 + x_3 \geq 1 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bài a) Dạng chuẩn:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Quy tắc:&lt;/strong&gt; Với bài toán cực tiểu hóa có ràng buộc đẳng thức và biến không âm (\(x \geq 0\)):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Mỗi ràng buộc đẳng thức ứng với một biến đối ngẫu không ràng buộc dấu.&lt;/li&gt;
    &lt;li&gt;Mỗi biến gốc không âm ứng với một ràng buộc đối ngẫu dạng \(\leq\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; 4u_1 + 5u_2 \\
\text{s.t.} \quad &amp;amp; u_1 + 2u_2 \leq 3 \\
&amp;amp; 2u_1 + u_2 \leq 5 \\
&amp;amp; u_1 + 3u_2 \leq 2 \\
&amp;amp; u_1, u_2 \in \mathbb{R}
\end{align}\]

  &lt;p&gt;&lt;strong&gt;Giải thích:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(u_1, u_2\) là giá bóng (shadow prices) của ràng buộc thứ nhất và thứ hai, cho biết mức thay đổi biên của giá trị tối ưu khi vế phải tăng thêm một đơn vị.&lt;/li&gt;
    &lt;li&gt;Hai biến đối ngẫu không ràng buộc dấu vì các ràng buộc gốc là đẳng thức.&lt;/li&gt;
    &lt;li&gt;Mỗi biến của bài toán gốc tạo ra một ràng buộc tương ứng trong bài toán đối ngẫu.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Bài b) Dạng bất đẳng thức:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Quy tắc:&lt;/strong&gt; Với bài toán cực tiểu hóa có ràng buộc \(\geq\) và biến \(x \geq 0\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Mỗi ràng buộc \(\geq\) ứng với một biến đối ngẫu \(\geq 0\).&lt;/li&gt;
    &lt;li&gt;Mỗi biến \(x_i \geq 0\) ứng với một ràng buộc đối ngẫu \(\leq\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; 3u_1 + 5u_2 \\
\text{s.t.} \quad &amp;amp; u_1 + 2u_2 \leq 2 \\
&amp;amp; u_1 + u_2 \leq 4 \\
&amp;amp; u_1, u_2 \geq 0
\end{align}\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Bài c) Dạng hỗn hợp:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Phân tích:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Ràng buộc 1 (\(=\)): biến đối ngẫu \(u_1 \in \mathbb{R}\).&lt;/li&gt;
    &lt;li&gt;Ràng buộc 2 (\(\leq\)): biến đối ngẫu \(u_2 \leq 0\).&lt;/li&gt;
    &lt;li&gt;Ràng buộc 3 (\(\geq\)): biến đối ngẫu \(u_3 \geq 0\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; 2u_1 + 3u_2 + u_3 \\
\text{s.t.} \quad &amp;amp; u_1 + u_3 \leq 1 \\
&amp;amp; u_1 + u_2 \leq 2 \\
&amp;amp; u_2 + u_3 \leq 3 \\
&amp;amp; u_1 \in \mathbb{R}, \quad u_2 \leq 0, \quad u_3 \geq 0
\end{align}\]

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-2-lập-kế-hoạch-sản-xuất-boyd--vandenberghe-ex-52&quot;&gt;Bài tập 2: Lập kế hoạch sản xuất (Boyd &amp;amp; Vandenberghe, Ex. 5.2)&lt;/h3&gt;

&lt;p&gt;Một xí nghiệp sản xuất 2 sản phẩm A và B với các thông số sau:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Sản phẩm&lt;/th&gt;
      &lt;th&gt;Lợi nhuận (nghìn đồng)&lt;/th&gt;
      &lt;th&gt;Lao động (giờ)&lt;/th&gt;
      &lt;th&gt;Máy móc (giờ)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;A&lt;/td&gt;
      &lt;td&gt;40&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;B&lt;/td&gt;
      &lt;td&gt;30&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nguồn lực hiện có: 100 giờ lao động và 80 giờ máy móc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Lập bài toán LP cực đại hóa lợi nhuận.
b) Xây dựng bài toán đối ngẫu.
c) Giải thích ý nghĩa kinh tế của các biến đối ngẫu.
d) Nếu có thêm 1 giờ lao động, lợi nhuận tăng thêm tối đa bao nhiêu?&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Bài toán gốc:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Đặt \(x_1, x_2\) lần lượt là số lượng sản phẩm A và B cần sản xuất:&lt;/p&gt;

\[\begin{align}
\max_{x} \quad &amp;amp; 40x_1 + 30x_2 \\
\text{s.t.} \quad &amp;amp; 2x_1 + x_2 \leq 100 \quad \text{(Lao động)} \\
&amp;amp; x_1 + 2x_2 \leq 80 \quad \text{(Máy móc)} \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Chuyển về dạng cực tiểu hóa \(\min -40x_1 - 30x_2\) rồi lập đối ngẫu, ta thu được:&lt;/p&gt;

\[\begin{align}
\min_{u} \quad &amp;amp; 100u_1 + 80u_2 \\
\text{s.t.} \quad &amp;amp; 2u_1 + u_2 \geq 40 \\
&amp;amp; u_1 + 2u_2 \geq 30 \\
&amp;amp; u_1, u_2 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;c) Ý nghĩa kinh tế:&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;\(u_1\): &lt;strong&gt;Giá bóng của lao động&lt;/strong&gt; — mức tăng lợi nhuận biên khi có thêm 1 giờ lao động.&lt;/li&gt;
    &lt;li&gt;\(u_2\): &lt;strong&gt;Giá bóng của máy móc&lt;/strong&gt; — mức tăng lợi nhuận biên khi có thêm 1 giờ máy móc.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Các ràng buộc đối ngẫu có nghĩa là tổng giá trị nguồn lực dùng để sản xuất mỗi đơn vị sản phẩm A (\(2u_1 + u_2\)) phải lớn hơn hoặc bằng lợi nhuận của sản phẩm A (40), và tương tự cho sản phẩm B (\(u_1 + 2u_2 \geq 30\)).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Mức tăng lợi nhuận khi có thêm 1 giờ lao động:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Giải hệ hai ràng buộc đối ngẫu chặt \(2u_1 + u_2 = 40\) và \(u_1 + 2u_2 = 30\), ta được \(u_1^* = 50/3 \approx 16.67\) và \(u_2^* = 20/3 \approx 6.67\) nghìn đồng/giờ. Kiểm tra lại: nghiệm gốc \(x^* = (40, 20)\) cho giá trị \(40 \cdot 40 + 30 \cdot 20 = 2200\), bằng giá trị đối ngẫu \(100 \cdot \frac{50}{3} + 80 \cdot \frac{20}{3} = 2200\) ✓.&lt;/p&gt;

  &lt;p&gt;Do đó, thêm 1 giờ lao động giúp lợi nhuận tăng tối đa \(50/3 \approx 16.67\) nghìn đồng.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-3-tối-ưu-danh-mục-đầu-tư-boyd--vandenberghe-ex-53&quot;&gt;Bài tập 3: Tối ưu danh mục đầu tư (Boyd &amp;amp; Vandenberghe, Ex. 5.3)&lt;/h3&gt;

&lt;p&gt;Một nhà đầu tư có 1000 triệu đồng muốn phân bổ vào 3 loại tài sản với các thông số sau:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tài sản&lt;/th&gt;
      &lt;th&gt;Lợi nhuận (%)&lt;/th&gt;
      &lt;th&gt;Rủi ro (độ lệch chuẩn)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Cổ phiếu&lt;/td&gt;
      &lt;td&gt;15&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Trái phiếu&lt;/td&gt;
      &lt;td&gt;8&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tiền mặt&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Yêu cầu: lợi nhuận đạt ít nhất 10% và tổng rủi ro không vượt quá 12%.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Lập bài toán LP cực tiểu hóa rủi ro.
b) Xây dựng bài toán đối ngẫu.
c) Giải thích ý nghĩa của các biến đối ngẫu.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Bài toán gốc:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Đặt \(x_1, x_2, x_3\) là tỷ trọng đầu tư vào cổ phiếu, trái phiếu và tiền mặt:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; 20x_1 + 5x_2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 + x_3 = 1 \quad \text{(Tổng vốn)} \\
&amp;amp; 15x_1 + 8x_2 + 3x_3 \geq 10 \quad \text{(Lợi nhuận)} \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; u_1 + 10u_2 \\
\text{s.t.} \quad &amp;amp; u_1 + 15u_2 \leq 20 \\
&amp;amp; u_1 + 8u_2 \leq 5 \\
&amp;amp; u_1 + 3u_2 \leq 0 \\
&amp;amp; u_1 \in \mathbb{R}, \quad u_2 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;c) Ý nghĩa và nghiệm:&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;\(u_1\): giá trị biên của ràng buộc tổng vốn (độ nhạy của rủi ro tối ưu khi thay đổi vế phải ràng buộc tổng tỷ trọng).&lt;/li&gt;
    &lt;li&gt;\(u_2\): giá trị biên của ràng buộc lợi nhuận, phản ánh sự đánh đổi giữa yêu cầu lợi nhuận và mức rủi ro.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt; Danh mục tối ưu chỉ phân bổ vào cổ phiếu và trái phiếu: \(15x_1 + 8(1 - x_1) = 10 \Rightarrow x_1 = 2/7\), nên \(x^* = (2/7, 5/7, 0)\) với mức rủi ro \(20(2/7) + 5(5/7) = 65/7 \approx 9.29\% \leq 12\%\) ✓ (ràng buộc trần rủi ro 12% không chặt). Nghiệm đối ngẫu là \(u_1^* = -85/7\), \(u_2^* = 15/7 \approx 2.14\) (giá trị đối ngẫu \(-85/7 + 150/7 = 65/7\) ✓), cho thấy khi tăng yêu cầu lợi nhuận thêm 1 điểm phần trăm, rủi ro tối ưu tăng khoảng 2,14 điểm phần trăm.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-ii-tính-đối-ngẫu-yếu-và-đối-ngẫu-mạnh&quot;&gt;Phần II: Tính đối ngẫu yếu và đối ngẫu mạnh&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-4-đối-ngẫu-yếu-boyd--vandenberghe-ex-55&quot;&gt;Bài tập 4: Đối ngẫu yếu (Boyd &amp;amp; Vandenberghe, Ex. 5.5)&lt;/h3&gt;

&lt;p&gt;Cho bài toán:&lt;/p&gt;

\[\begin{align}
\text{(P)} \quad \min_{x} \quad &amp;amp; 2x_1 + 3x_2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 \geq 4 \\
&amp;amp; 2x_1 + x_2 \geq 6 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Xây dựng bài toán đối ngẫu (D).
&lt;strong&gt;b)&lt;/strong&gt; Cho \(x = (3, 1)\). Kiểm tra tính khả thi của \(x\) và tìm một nghiệm khả thi \(u\) của (D).
&lt;strong&gt;c)&lt;/strong&gt; Kiểm chứng bất đẳng thức đối ngẫu yếu \(c^T x \geq b^T u\).
&lt;strong&gt;d)&lt;/strong&gt; Chứng minh \(x^* = (4, 0)\) là nghiệm tối ưu.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\text{(D)} \quad \max_{u} \quad &amp;amp; 4u_1 + 6u_2 \\
\text{s.t.} \quad &amp;amp; u_1 + 2u_2 \leq 2 \\
&amp;amp; u_1 + u_2 \leq 3 \\
&amp;amp; u_1, u_2 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Kiểm tra \(x = (3, 1)\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Tính khả thi gốc:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(3 + 1 = 4 \geq 4\) ✓&lt;/li&gt;
    &lt;li&gt;\(2(3) + 1 = 7 \geq 6\) ✓&lt;/li&gt;
    &lt;li&gt;\(x \geq 0\) ✓&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Giá trị mục tiêu gốc: \(f(x) = 2(3) + 3(1) = 9\).&lt;/p&gt;

  &lt;p&gt;Chọn nghiệm đối ngẫu khả thi \(u = (0, 1)\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(0 + 2(1) = 2 \leq 2\) ✓&lt;/li&gt;
    &lt;li&gt;\(0 + 1 = 1 \leq 3\) ✓&lt;/li&gt;
    &lt;li&gt;Giá trị mục tiêu đối ngẫu: \(g(u) = 4(0) + 6(1) = 6\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;c) Kiểm chứng đối ngẫu yếu:&lt;/strong&gt;&lt;/p&gt;

\[c^Tx = 9 \geq 6 = b^Tu\]

  &lt;p&gt;Bất đẳng thức đối ngẫu yếu được thỏa mãn ✓.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Chứng minh \(x^* = (4, 0)\) tối ưu:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Kiểm tra tính khả thi gốc:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(4 + 0 = 4 \geq 4\) ✓ (ràng buộc chặt)&lt;/li&gt;
    &lt;li&gt;\(2(4) + 0 = 8 \geq 6\) ✓ (ràng buộc lỏng, độ dư bằng 2)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Giá trị mục tiêu gốc: \(f(x^*) = 2(4) + 3(0) = 8\).&lt;/p&gt;

  &lt;p&gt;Tìm \(u^*\) theo điều kiện bù: vì ràng buộc gốc thứ hai lỏng nên \(u_2^* = 0\); vì \(x_1^* &amp;gt; 0\) nên ràng buộc đối ngẫu thứ nhất chặt: \(u_1^* + 2u_2^* = 2 \Rightarrow u_1^* = 2\).&lt;/p&gt;

  &lt;p&gt;Kiểm tra tính khả thi đối ngẫu: \(u_1^* + u_2^* = 2 \leq 3\) ✓ (lỏng, khớp với \(x_2^* = 0\)). Giá trị mục tiêu đối ngẫu: \(g(u^*) = 4(2) + 6(0) = 8 = f(x^*)\) ✓.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Theo đối ngẫu yếu, mọi \(x\) khả thi đều thỏa \(f(x) \geq g(u^*) = 8\), do đó \(x^* = (4, 0)\) là nghiệm tối ưu. Lưu ý rằng điểm \((2, 2)\) khả thi nhưng cho \(f = 10 &amp;gt; 8\), còn \(x = (3, 1)\) cho \(f = 9\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-5-đối-ngẫu-mạnh-boyd--vandenberghe-ex-56&quot;&gt;Bài tập 5: Đối ngẫu mạnh (Boyd &amp;amp; Vandenberghe, Ex. 5.6)&lt;/h3&gt;

&lt;p&gt;Cho bài toán:&lt;/p&gt;

\[\begin{align}
\text{(P)} \quad \min_{x} \quad &amp;amp; x_1 + 2x_2 + x_3 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 = 3 \\
&amp;amp; x_2 + x_3 = 2 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Tìm nghiệm tối ưu bằng phương pháp đại số.
&lt;strong&gt;b)&lt;/strong&gt; Xây dựng và giải bài toán đối ngẫu.
&lt;strong&gt;c)&lt;/strong&gt; Tính khoảng cách đối ngẫu.
&lt;strong&gt;d)&lt;/strong&gt; Giải thích vì sao tính đối ngẫu mạnh đúng trong trường hợp này.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Giải bài toán gốc:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Từ hai ràng buộc đẳng thức, ta có \(x_1 = 3 - x_2\) và \(x_3 = 2 - x_2\). Thế vào hàm mục tiêu:&lt;/p&gt;

\[f = (3 - x_2) + 2x_2 + (2 - x_2) = 5\]

  &lt;p&gt;Hàm mục tiêu có giá trị không đổi bằng \(5\) trên toàn bộ tập khả thi, nên giá trị tối ưu là \(f^* = 5\). Điều kiện không âm của các biến cho \(0 \leq x_2 \leq 2\); chẳng hạn \(x^* = (2, 1, 1)\) là một nghiệm tối ưu.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;b) Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; 3u_1 + 2u_2 \\
\text{s.t.} \quad &amp;amp; u_1 \leq 1 \\
&amp;amp; u_1 + u_2 \leq 2 \\
&amp;amp; u_2 \leq 1 \\
&amp;amp; u_1, u_2 \in \mathbb{R}
\end{align}\]

  &lt;p&gt;Để cực đại hóa \(3u_1 + 2u_2\), chọn \(u_1 = 1\) và \(u_2 = 1\). Kiểm tra các ràng buộc: \(1 \leq 1\) ✓, \(1 + 1 = 2 \leq 2\) ✓, \(1 \leq 1\) ✓. Giá trị tối ưu đối ngẫu: \(g^* = 3(1) + 2(1) = 5\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Khoảng cách đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\text{Gap} = f^* - g^* = 5 - 5 = 0\]

  &lt;p&gt;Tính đối ngẫu mạnh được thỏa mãn ✓.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Giải thích:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Đối với quy hoạch tuyến tính, tính đối ngẫu mạnh luôn đúng khi một trong hai bài toán có nghiệm tối ưu hữu hạn (khi đó bài toán còn lại cũng có nghiệm tối ưu với cùng giá trị mục tiêu):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Nếu bài toán gốc không bị chặn thì bài toán đối ngẫu vô nghiệm (và ngược lại).&lt;/li&gt;
    &lt;li&gt;Ngoại lệ duy nhất là trường hợp cả hai bài toán đều vô nghiệm.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Với LP khả thi, các ràng buộc đều là hàm affine nên điều kiện Slater dạng mở rộng tự động thỏa mãn.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-iii-điều-kiện-bù-complementary-slackness&quot;&gt;Phần III: Điều kiện bù (Complementary Slackness)&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-6-áp-dụng-điều-kiện-bù-bertsimas--tsitsiklis-ex-43&quot;&gt;Bài tập 6: Áp dụng điều kiện bù (Bertsimas &amp;amp; Tsitsiklis, Ex. 4.3)&lt;/h3&gt;

&lt;p&gt;Cho bài toán gốc và ba cặp nghiệm thử:&lt;/p&gt;

\[\begin{align}
\text{(P)} \quad \min_{x} \quad &amp;amp; 3x_1 + 2x_2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 \geq 4 \\
&amp;amp; 2x_1 + x_2 \geq 6 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Các cặp nghiệm:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;\(x = (2, 2)\), \(u = (1, 1)\)&lt;/li&gt;
  &lt;li&gt;\(x = (3, 1)\), \(u = (0, 3/2)\)&lt;/li&gt;
  &lt;li&gt;\(x = (0, 6)\), \(u = (0, 2)\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Kiểm tra cặp nghiệm nào tối ưu bằng điều kiện bù.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; 4u_1 + 6u_2 \\
\text{s.t.} \quad &amp;amp; u_1 + 2u_2 \leq 3 \\
&amp;amp; u_1 + u_2 \leq 2 \\
&amp;amp; u_1, u_2 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;Hệ điều kiện bù:&lt;/strong&gt;&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;
\[u_1 \cdot [x_1 + x_2 - 4] = 0\]
    &lt;/li&gt;
    &lt;li&gt;
\[u_2 \cdot [2x_1 + x_2 - 6] = 0\]
    &lt;/li&gt;
    &lt;li&gt;
\[x_1 \cdot [u_1 + 2u_2 - 3] = 0\]
    &lt;/li&gt;
    &lt;li&gt;
\[x_2 \cdot [u_1 + u_2 - 2] = 0\]
    &lt;/li&gt;
  &lt;/ol&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Cặp 1: \(x = (2,2)\), \(u = (1,1)\)&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Tính khả thi gốc:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(2 + 2 = 4 \geq 4\) ✓ (chặt)&lt;/li&gt;
    &lt;li&gt;\(4 + 2 = 6 \geq 6\) ✓ (chặt)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Tính khả thi đối ngẫu:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(1 + 2 = 3 \leq 3\) ✓ (chặt)&lt;/li&gt;
    &lt;li&gt;\(1 + 1 = 2 \leq 2\) ✓ (chặt)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Điều kiện bù:&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;\(1 \cdot 0 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;\(1 \cdot 0 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;\(2 \cdot 0 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;\(2 \cdot 0 = 0\) ✓&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Cặp 1 là cặp nghiệm tối ưu ✓. Giá trị mục tiêu: \(f = 3(2) + 2(2) = 10 = 4(1) + 6(1) = g\) ✓.&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Cặp 2: \(x = (3,1)\), \(u = (0, 3/2)\)&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Khả thi gốc: \(3 + 1 = 4\) ✓, \(6 + 1 = 7 &amp;gt; 6\) (độ dư bằng 1).&lt;/li&gt;
    &lt;li&gt;Khả thi đối ngẫu: \(0 + 3 = 3\) ✓, \(0 + 3/2 = 3/2 \leq 2\) ✓.&lt;/li&gt;
    &lt;li&gt;Điều kiện bù thứ 2: \(u_2 \cdot [7 - 6] = (3/2)(1) = 3/2 \neq 0\) ✗.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Không tối ưu.&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Cặp 3: \(x = (0,6)\), \(u = (0,2)\)&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Kiểm tra khả thi đối ngẫu: \(0 + 2(2) = 4 \not\leq 3\) ✗.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Nghiệm đối ngẫu không khả thi, nên cặp 3 không tối ưu.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-7-giá-bóng-bertsimas--tsitsiklis-ex-47&quot;&gt;Bài tập 7: Giá bóng (Bertsimas &amp;amp; Tsitsiklis, Ex. 4.7)&lt;/h3&gt;

&lt;p&gt;Xét lại bài toán sản xuất ở Bài tập 2 với hàm mục tiêu \(\max 40x_1 + 30x_2\) và nghiệm tối ưu \(x^* = (40, 20)\), tại đó hai ràng buộc đều chặt:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Lao động: \(2(40) + 20 = 100\)&lt;/li&gt;
  &lt;li&gt;Máy móc: \(40 + 2(20) = 80\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Tính giá bóng của từng nguồn lực.
&lt;strong&gt;b)&lt;/strong&gt; Nếu có thể mua thêm 1 giờ lao động với giá 12 nghìn đồng, có nên mua không?
&lt;strong&gt;c)&lt;/strong&gt; Phân tích độ nhạy khi quỹ lao động tăng lên 105 giờ.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Tính giá bóng:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Vì cả hai biến gốc đều dương và cả hai ràng buộc đều chặt, theo điều kiện bù ta có hệ:&lt;/p&gt;

\[\begin{cases}
2u_1 + u_2 = 40 \\
u_1 + 2u_2 = 30
\end{cases}\]

  &lt;p&gt;Giải hệ phương trình:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Từ phương trình (1): \(u_2 = 40 - 2u_1\).&lt;/li&gt;
    &lt;li&gt;Thế vào phương trình (2): \(u_1 + 2(40 - 2u_1) = 30 \Rightarrow -3u_1 = -50 \Rightarrow u_1^* = 50/3 \approx 16.67\).&lt;/li&gt;
    &lt;li&gt;Suy ra \(u_2^* = 40 - 2(50/3) = 20/3 \approx 6.67\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Giá bóng:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Lao động: \(u_1^* = 50/3 \approx 16.67\) nghìn đồng/giờ.&lt;/li&gt;
    &lt;li&gt;Máy móc: \(u_2^* = 20/3 \approx 6.67\) nghìn đồng/giờ.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;b) Quyết định mua thêm lao động:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Giá mua là 12 nghìn đồng/giờ, thấp hơn giá trị biên \(u_1^* \approx 16.67\) nghìn đồng/giờ. Vì \(12 &amp;lt; 16.67\), doanh nghiệp &lt;strong&gt;nên mua&lt;/strong&gt; (lợi nhuận ròng tăng thêm khoảng 4,67 nghìn đồng/giờ).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Phân tích độ nhạy:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Khi tăng thêm 5 giờ lao động (từ 100 lên 105 giờ, vẫn nằm trong khoảng ổn định cơ sở tối ưu):&lt;/p&gt;

\[\Delta f = u_1^* \times 5 = \frac{50}{3} \times 5 = \frac{250}{3} \approx 83.33 \text{ nghìn đồng}\]

  &lt;p&gt;Lợi nhuận hiện tại là \(40(40) + 30(20) = 2200\) nghìn đồng, nên lợi nhuận mới đạt khoảng \(2283.33\) nghìn đồng.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;(Lưu ý: Giá bóng chỉ có hiệu lực trong khoảng độ nhạy mà tập ràng buộc chặt không đổi.)&lt;/em&gt;&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-iv-luồng-cực-đại-và-lát-cắt-cực-tiểu&quot;&gt;Phần IV: Luồng cực đại và lát cắt cực tiểu&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-8-bài-toán-luồng-cực-đại-bertsimas--tsitsiklis-ex-72&quot;&gt;Bài tập 8: Bài toán luồng cực đại (Bertsimas &amp;amp; Tsitsiklis, Ex. 7.2)&lt;/h3&gt;

&lt;p&gt;Cho mạng có hướng với dung lượng các cung như sau:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    s --10--&amp;gt; a --8--&amp;gt; t
    |        / \       ^
    8      5    3     10
    |    /        \    |
    v  /            \  |
    b ---------------&amp;gt; c
          10
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Viết bài toán luồng cực đại dưới dạng LP.
&lt;strong&gt;b)&lt;/strong&gt; Tìm một luồng khả thi.
&lt;strong&gt;c)&lt;/strong&gt; Tìm một lát cắt và tính dung lượng của nó.
&lt;strong&gt;d)&lt;/strong&gt; Kiểm chứng bất đẳng thức: giá trị luồng \(\leq\) dung lượng lát cắt.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Bài toán LP luồng cực đại:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Đặt \(f_{ij}\) là luồng trên cung \((i, j)\):&lt;/p&gt;

\[\begin{align}
\max \quad &amp;amp; f_{sa} + f_{sb} \\
\text{s.t.} \quad &amp;amp; f_{sa} - f_{ab} - f_{at} - f_{ac} = 0 \quad \text{(nút a)} \\
&amp;amp; f_{sb} + f_{ab} - f_{bc} = 0 \quad \text{(nút b)} \\
&amp;amp; f_{ac} + f_{bc} - f_{ct} = 0 \quad \text{(nút c)} \\
&amp;amp; 0 \leq f_{sa} \leq 10, \quad 0 \leq f_{sb} \leq 8 \\
&amp;amp; 0 \leq f_{at} \leq 8, \quad 0 \leq f_{ab} \leq 5 \\
&amp;amp; 0 \leq f_{ac} \leq 3, \quad 0 \leq f_{bc} \leq 10 \\
&amp;amp; 0 \leq f_{ct} \leq 10
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Luồng khả thi:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Xét luồng:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(f_{sa} = 10\), \(f_{sb} = 8\)&lt;/li&gt;
    &lt;li&gt;\(f_{at} = 8\), \(f_{ab} = 0\), \(f_{ac} = 2\)&lt;/li&gt;
    &lt;li&gt;\(f_{bc} = 8\), \(f_{ct} = 10\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Kiểm tra điều kiện bảo toàn luồng tại các nút trung gian:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Nút \(a\): \(10 - 0 - 8 - 2 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;Nút \(b\): \(8 + 0 - 8 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;Nút \(c\): \(2 + 8 - 10 = 0\) ✓&lt;/li&gt;
  &lt;/ul&gt;

  &lt;table&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;Giá trị luồng: $$&lt;/td&gt;
        &lt;td&gt;f&lt;/td&gt;
        &lt;td&gt;= 10 + 8 = 18$$.&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

  &lt;p&gt;&lt;strong&gt;c) Lát cắt:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Xét lát cắt \(S = \{s\}\), \(T = \{a, b, c, t\}\). Các cung đi từ \(S\) sang \(T\) gồm:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\((s, a)\) có dung lượng 10&lt;/li&gt;
    &lt;li&gt;\((s, b)\) có dung lượng 8&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Dung lượng lát cắt: \(C(S, T) = 10 + 8 = 18\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Kiểm chứng:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Ta có giá trị luồng bằng \(18\), đúng bằng dung lượng lát cắt \(C(S, T) = 18\). Theo định lý luồng cực đại – lát cắt cực tiểu, đây đồng thời là luồng cực đại và lát cắt cực tiểu ✓.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-v-trò-chơi-ma-trận&quot;&gt;Phần V: Trò chơi ma trận&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-9-trò-chơi-tổng-bằng-không-dantzig-ex-81&quot;&gt;Bài tập 9: Trò chơi tổng bằng không (Dantzig, Ex. 8.1)&lt;/h3&gt;

&lt;p&gt;Cho ma trận chi trả (tính theo phần thưởng của người chơi hàng):&lt;/p&gt;

\[P = \begin{bmatrix}
3 &amp;amp; -1 &amp;amp; 2 \\
1 &amp;amp; 4 &amp;amp; -2 \\
0 &amp;amp; 2 &amp;amp; 3
\end{bmatrix}\]

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Kiểm tra xem trò chơi có điểm cân bằng Nash thuần túy hay không.
&lt;strong&gt;b)&lt;/strong&gt; Viết bài toán LP tìm chiến lược hỗn hợp tối ưu cho người chơi hàng.
&lt;strong&gt;c)&lt;/strong&gt; Viết bài toán LP đối ngẫu cho người chơi cột.
&lt;strong&gt;d)&lt;/strong&gt; Giải thích giá trị của trò chơi.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Kiểm tra cân bằng Nash thuần túy:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Giá trị nhỏ nhất của từng hàng:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Hàng 1: \(\min\{3, -1, 2\} = -1\)&lt;/li&gt;
    &lt;li&gt;Hàng 2: \(\min\{1, 4, -2\} = -2\)&lt;/li&gt;
    &lt;li&gt;Hàng 3: \(\min\{0, 2, 3\} = 0\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Suy ra \(\text{Maxmin} = \max\{-1, -2, 0\} = 0\) (hàng 3).&lt;/p&gt;

  &lt;p&gt;Giá trị lớn nhất của từng cột:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Cột 1: \(\max\{3, 1, 0\} = 3\)&lt;/li&gt;
    &lt;li&gt;Cột 2: \(\max\{-1, 4, 2\} = 4\)&lt;/li&gt;
    &lt;li&gt;Cột 3: \(\max\{2, -2, 3\} = 3\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Suy ra \(\text{Minmax} = \min\{3, 4, 3\} = 3\).&lt;/p&gt;

  &lt;p&gt;Vì \(\text{Maxmin} \neq \text{Minmax}\), trò chơi &lt;strong&gt;không có điểm cân bằng Nash thuần túy&lt;/strong&gt;.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;b) Bài toán LP cho người chơi hàng:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Cực đại hóa mức thưởng đảm bảo \(v\):&lt;/p&gt;

\[\begin{align}
\max_{x, v} \quad &amp;amp; v \\
\text{s.t.} \quad &amp;amp; 3x_1 + x_2 + 0x_3 \geq v \\
&amp;amp; -x_1 + 4x_2 + 2x_3 \geq v \\
&amp;amp; 2x_1 - 2x_2 + 3x_3 \geq v \\
&amp;amp; x_1 + x_2 + x_3 = 1 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;c) Bài toán LP cho người chơi cột:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Cực tiểu hóa mức lỗ tối đa \(u\):&lt;/p&gt;

\[\begin{align}
\min_{y, u} \quad &amp;amp; u \\
\text{s.t.} \quad &amp;amp; 3y_1 - y_2 + 2y_3 \leq u \\
&amp;amp; y_1 + 4y_2 - 2y_3 \leq u \\
&amp;amp; 0y_1 + 2y_2 + 3y_3 \leq u \\
&amp;amp; y_1 + y_2 + y_3 = 1 \\
&amp;amp; y_1, y_2, y_3 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;d) Giá trị trò chơi:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Theo định lý minimax của von Neumann:&lt;/p&gt;

\[v^* = \max_x \min_y x^T P y = \min_y \max_x x^T P y\]

  &lt;p&gt;Giá trị \(v^*\) là mức chi trả tại cân bằng Nash trong chiến lược hỗn hợp.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Thử nghiệm với chiến lược đều&lt;/strong&gt; \(x = y = (1/3, 1/3, 1/3)\): chi trả kỳ vọng ứng với ba cột lần lượt là \((1/3)(3 + 1 + 0) = 4/3\), \((1/3)(-1 + 4 + 2) = 5/3\) và \((1/3)(2 - 2 + 3) = 1\). Giá trị nhỏ nhất là \(1\), nên \(v^* \geq 1\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm tối ưu (giải LP):&lt;/strong&gt; \(x^* = (3/8, 1/4, 3/8)\), \(y^* = (17/40, 7/20, 9/40)\), giá trị trò chơi \(v^* = 11/8 = 1.375\). Kiểm tra: với \(x^*\), chi trả kỳ vọng theo từng cột đều bằng \(\frac{11}{8}\) (cột 1: \(\frac{9}{8} + \frac{2}{8}\); cột 2: \(-\frac{3}{8} + \frac{8}{8} + \frac{6}{8}\); cột 3: \(\frac{6}{8} - \frac{4}{8} + \frac{9}{8}\)). Ta thấy \(\text{Maxmin} = 0 &amp;lt; v^* = 1.375 &amp;lt; \text{Minmax} = 3\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phần-vi-bài-tập-nâng-cao-từ-boyd--vandenberghe&quot;&gt;Phần VI: Bài tập nâng cao từ Boyd &amp;amp; Vandenberghe&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-10-quy-hoạch-tuyến-tính-bền-vững-robust-lp--boyd--vandenberghe-ex-511&quot;&gt;Bài tập 10: Quy hoạch tuyến tính bền vững (Robust LP – Boyd &amp;amp; Vandenberghe, Ex. 5.11)&lt;/h3&gt;

&lt;p&gt;Xét bài toán LP có hệ số bất định:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; c^T x \\
\text{s.t.} \quad &amp;amp; a_i^T x \leq b_i, \quad i = 1, \ldots, m \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;trong đó mỗi vector \(a_i\) biến thiên trong ellipsoid \(\{a_i + P_i u : \|u\| \leq 1\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Viết dạng tương đương của bài toán bền vững (robust).
b) Chỉ ra đây là một bài toán quy hoạch nón bậc hai (SOCP), không còn là LP thuần túy.
c) Nhận xét về bài toán đối ngẫu.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Dạng tương đương bền vững:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Ràng buộc bền vững đòi hỏi:&lt;/p&gt;

\[(a_i + P_i u)^T x \leq b_i, \quad \forall \|u\| \leq 1\]

  &lt;p&gt;Điều này tương đương với:&lt;/p&gt;

\[a_i^T x + \max_{\|u\| \leq 1} u^T P_i^T x \leq b_i\]

  &lt;p&gt;Theo bất đẳng thức Cauchy–Schwarz:&lt;/p&gt;

\[\max_{\|u\| \leq 1} u^T P_i^T x = \|P_i^T x\|\]

  &lt;p&gt;Do đó, ràng buộc bền vững trở thành:&lt;/p&gt;

\[a_i^T x + \|P_i^T x\| \leq b_i\]

  &lt;p&gt;&lt;strong&gt;b) Đây là bài toán SOCP:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Bài toán tương đương có dạng quy hoạch nón bậc hai (Second-Order Cone Program – SOCP):&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; c^T x \\
\text{s.t.} \quad &amp;amp; a_i^T x + \|P_i^T x\| \leq b_i, \quad i = 1, \ldots, m \\
&amp;amp; x \geq 0
\end{align}\]

  &lt;p&gt;Khi \(P_i = 0\) (không có bất định), bài toán quay về LP thông thường.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Bài toán đối ngẫu được xây dựng theo lý thuyết đối ngẫu của SOCP (có chứa ràng buộc chuẩn Euclide của các biến đối ngẫu) chứ không còn là một LP thuần túy.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-11-tâm-chebyshev-boyd--vandenberghe-ex-85&quot;&gt;Bài tập 11: Tâm Chebyshev (Boyd &amp;amp; Vandenberghe, Ex. 8.5)&lt;/h3&gt;

&lt;p&gt;Tìm tâm \(x_c\) và bán kính \(r\) lớn nhất sao cho hình cầu Euclide \(\{x : \|x - x_c\| \leq r\}\) nằm trọn trong đa diện \(\{x : a_i^T x \leq b_i, i = 1, \ldots, m\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;
a) Lập bài toán tối ưu.
b) Chứng minh đây là một bài toán LP.
c) Giải cho một đa diện cụ thể.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Lập bài toán tối ưu:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Điều kiện để hình cầu nằm trong đa diện là:&lt;/p&gt;

\[a_i^T x \leq b_i, \quad \forall x : \|x - x_c\| \leq r\]

  &lt;p&gt;Điều này tương đương với:&lt;/p&gt;

\[\max_{\|x - x_c\| \leq r} a_i^T x \leq b_i\]

\[a_i^T x_c + r\|a_i\| \leq b_i\]

  &lt;p&gt;Vậy bài toán tìm tâm Chebyshev là:&lt;/p&gt;

\[\begin{align}
\max_{x_c, r} \quad &amp;amp; r \\
\text{s.t.} \quad &amp;amp; a_i^T x_c + r\|a_i\| \leq b_i, \quad i = 1, \ldots, m
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Chứng minh là bài toán LP:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Vì các chuẩn \(\|a_i\|\) là hằng số đã biết, cả hàm mục tiêu lẫn các ràng buộc đều tuyến tính theo biến \((x_c, r)\), nên đây là một bài toán LP.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Ví dụ cụ thể:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Xét đa diện xác định bởi bốn bất đẳng thức:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[x_1 + x_2 \leq 4\]
    &lt;/li&gt;
    &lt;li&gt;
\[x_1 - x_2 \leq 2\]
    &lt;/li&gt;
    &lt;li&gt;
\[-x_1 + x_2 \leq 2\]
    &lt;/li&gt;
    &lt;li&gt;
\[-x_1 - x_2 \leq 2\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Bài toán LP tương ứng (với \(\|a_i\| = \sqrt{2}\) cho cả bốn ràng buộc):&lt;/p&gt;

\[\begin{align}
\max \quad &amp;amp; r \\
\text{s.t.} \quad &amp;amp; x_{c1} + x_{c2} + r\sqrt{2} \leq 4 \\
&amp;amp; x_{c1} - x_{c2} + r\sqrt{2} \leq 2 \\
&amp;amp; -x_{c1} + x_{c2} + r\sqrt{2} \leq 2 \\
&amp;amp; -x_{c1} - x_{c2} + r\sqrt{2} \leq 2
\end{align}\]

  &lt;p&gt;Giải bài toán ta thu được \(r\sqrt{2} = 2\), tức \(r = \sqrt{2} \approx 1.414\), với tâm \(x_c = (t, t)\) với \(0 \leq t \leq 1\) (ví dụ \(x_c = (0, 0)\)); nghiệm không duy nhất vì ràng buộc thứ nhất không chặt. Kiểm tra tại \(x_c = (0, 0)\): vế trái của 4 ràng buộc đều bằng \(2\), thỏa mãn \(\leq 4, 2, 2, 2\) ✓ (ba ràng buộc cuối chặt).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;bài-tập-12-phân-bổ-tài-nguyên&quot;&gt;Bài tập 12: Phân bổ tài nguyên&lt;/h3&gt;

&lt;p&gt;Một công ty sản xuất 3 sản phẩm A, B, C với các thông số:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Sản phẩm&lt;/th&gt;
      &lt;th&gt;Lợi nhuận&lt;/th&gt;
      &lt;th&gt;Lao động&lt;/th&gt;
      &lt;th&gt;Máy&lt;/th&gt;
      &lt;th&gt;Nguyên liệu&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;A&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;B&lt;/td&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;C&lt;/td&gt;
      &lt;td&gt;6&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nguồn lực hiện có: 100 giờ lao động, 80 giờ máy và 90 kg nguyên liệu. Biết rằng tại phương án tối ưu, cả ba sản phẩm đều được sản xuất và cả ba nguồn lực đều dùng hết.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Lập bài toán LP gốc và bài toán đối ngẫu.
&lt;strong&gt;b)&lt;/strong&gt; Tìm phương án sản xuất tối ưu và giá bóng của từng nguồn lực.
&lt;strong&gt;c)&lt;/strong&gt; Có nên mua thêm 10 giờ lao động (giá 1,5 triệu/giờ) hay 10 kg nguyên liệu (giá 1 triệu/kg) không?&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Bài toán LP gốc:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{x} \quad &amp;amp; 5x_1 + 4x_2 + 6x_3 \\
\text{s.t.} \quad &amp;amp; 2x_1 + x_2 + 3x_3 \leq 100 \\
&amp;amp; x_1 + 2x_2 + 2x_3 \leq 80 \\
&amp;amp; 3x_1 + 2x_2 + x_3 \leq 90 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{u} \quad &amp;amp; 100u_1 + 80u_2 + 90u_3 \\
\text{s.t.} \quad &amp;amp; 2u_1 + u_2 + 3u_3 \geq 5 \\
&amp;amp; u_1 + 2u_2 + 2u_3 \geq 4 \\
&amp;amp; 3u_1 + 2u_2 + u_3 \geq 6 \\
&amp;amp; u_1, u_2, u_3 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Phương án tối ưu và giá bóng:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Vì cả ba ràng buộc nguồn lực đều chặt, \(x^*\) là nghiệm của hệ \(Ax = b\):&lt;/p&gt;

\[x^* = \left(\tfrac{160}{11}, \tfrac{150}{11}, \tfrac{210}{11}\right) \approx (14{,}55;\ 13{,}64;\ 19{,}09), \qquad 5x_1 + 4x_2 + 6x_3 = \tfrac{2660}{11} \approx 241{,}82\]

  &lt;p&gt;Kiểm tra ràng buộc lao động: \(2 \cdot 160 + 150 + 3 \cdot 210 = 1100\), chia cho 11 được 100 ✓.&lt;/p&gt;

  &lt;p&gt;Vì \(x_1, x_2, x_3 &amp;gt; 0\), theo điều kiện bù cả ba ràng buộc đối ngẫu đều chặt:&lt;/p&gt;

\[\begin{cases}
2u_1 + u_2 + 3u_3 = 5 \\
u_1 + 2u_2 + 2u_3 = 4 \\
3u_1 + 2u_2 + u_3 = 6
\end{cases}
\quad\Longrightarrow\quad
u^* = \left(\tfrac{14}{11}, \tfrac{9}{11}, \tfrac{6}{11}\right) \approx (1{,}27;\ 0{,}82;\ 0{,}55)\]

  &lt;p&gt;Kiểm tra: \(100u_1 + 80u_2 + 90u_3 = \tfrac{1400 + 720 + 540}{11} = \tfrac{2660}{11}\), khớp với giá trị tối ưu bài toán gốc ✓ (đối ngẫu mạnh). Mọi \(u_i \ge 0\) nên \(u^*\) khả thi.&lt;/p&gt;

  &lt;p&gt;Ý nghĩa: thêm 1 giờ lao động tăng lợi nhuận khoảng 1,27; thêm 1 giờ máy tăng khoảng 0,82; thêm 1 kg nguyên liệu tăng khoảng 0,55.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Quyết định mua thêm nguồn lực:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Giá bóng chỉ còn đúng khi cơ sở tối ưu không thay đổi. Với \(A^{-1} = \tfrac{1}{11}\begin{pmatrix} 2 &amp;amp; -5 &amp;amp; 4 \\ -5 &amp;amp; 7 &amp;amp; 1 \\ 4 &amp;amp; 1 &amp;amp; -3 \end{pmatrix}\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Thêm 10 giờ lao động: \(x = A^{-1}(110, 80, 90) = \left(\tfrac{180}{11}, \tfrac{100}{11}, \tfrac{250}{11}\right) &amp;gt; 0\), cơ sở giữ nguyên.&lt;/li&gt;
    &lt;li&gt;Thêm 10 kg nguyên liệu: \(x = A^{-1}(100, 80, 100) = \left(\tfrac{200}{11}, \tfrac{160}{11}, \tfrac{180}{11}\right) &amp;gt; 0\), cơ sở giữ nguyên.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Phương án 1 (lao động):&lt;/strong&gt; lợi nhuận tăng \(10 \cdot \tfrac{14}{11} \approx 12{,}7\) triệu, chi phí 15 triệu → &lt;strong&gt;lỗ khoảng 2,3 triệu&lt;/strong&gt;.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Phương án 2 (nguyên liệu):&lt;/strong&gt; lợi nhuận tăng \(10 \cdot \tfrac{6}{11} \approx 5{,}5\) triệu, chi phí 10 triệu → &lt;strong&gt;lỗ khoảng 4,5 triệu&lt;/strong&gt;.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Giá mua của cả hai nguồn lực đều cao hơn giá bóng tương ứng, nên không nên mua thêm. Nếu bắt buộc phải chọn một trong hai, phương án 1 lỗ ít hơn.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tổng-kết-và-chiến-lược-giải-bài-tập&quot;&gt;Tổng kết và chiến lược giải bài tập&lt;/h2&gt;

&lt;h3 id=&quot;xây-dựng-bài-toán-đối-ngẫu&quot;&gt;Xây dựng bài toán đối ngẫu&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Xác định rõ dạng bài toán gốc (cực tiểu hay cực đại, loại ràng buộc và dấu biến).&lt;/li&gt;
  &lt;li&gt;Áp dụng quy tắc tương ứng gốc – đối ngẫu: số biến đối ngẫu bằng số ràng buộc gốc, và số ràng buộc đối ngẫu bằng số biến gốc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;kiểm-tra-tính-tối-ưu&quot;&gt;Kiểm tra tính tối ưu&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Kiểm tra tính khả thi của cả nghiệm gốc và nghiệm đối ngẫu.&lt;/li&gt;
  &lt;li&gt;Kiểm tra điều kiện bù: \(u_i(a_i^T x - b_i) = 0\).&lt;/li&gt;
  &lt;li&gt;Đối chiếu giá trị mục tiêu: \(f^* = g^*\) (đối ngẫu mạnh).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giá-bóng-shadow-price&quot;&gt;Giá bóng (Shadow price)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Biểu thị giá trị biên của từng nguồn lực.&lt;/li&gt;
  &lt;li&gt;Chỉ chính xác trong khoảng độ nhạy mà cơ sở tối ưu không đổi.&lt;/li&gt;
  &lt;li&gt;Ràng buộc lỏng (độ dư dương) có giá bóng bằng 0.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;luồng-cực-đại--lát-cắt-cực-tiểu&quot;&gt;Luồng cực đại – lát cắt cực tiểu&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Kiểm tra điều kiện bảo toàn luồng tại mọi nút trung gian.&lt;/li&gt;
  &lt;li&gt;Luôn có giá trị luồng \(\leq\) dung lượng lát cắt (đối ngẫu yếu).&lt;/li&gt;
  &lt;li&gt;Khi dấu bằng xảy ra, cả luồng và lát cắt đều tối ưu (đối ngẫu mạnh).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;trò-chơi-ma-trận&quot;&gt;Trò chơi ma trận&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Kiểm tra điểm yên ngựa (cân bằng Nash thuần túy) trước.&lt;/li&gt;
  &lt;li&gt;Nếu không có, lập bài toán LP để tìm chiến lược hỗn hợp tối ưu.&lt;/li&gt;
  &lt;li&gt;Theo định lý minimax của von Neumann: \(\max_x \min_y = \min_y \max_x\).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 5: Duality.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bertsimas, D., &amp;amp; Tsitsiklis, J. N.&lt;/strong&gt; (1997). &lt;em&gt;Introduction to Linear Optimization&lt;/em&gt;. Athena Scientific. Chapters 4, 7.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Dantzig, G. B.&lt;/strong&gt; (1963). &lt;em&gt;Linear Programming and Extensions&lt;/em&gt;. Princeton University Press. Chapters 5-8.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Luenberger, D. G., &amp;amp; Ye, Y.&lt;/strong&gt; (2008). &lt;em&gt;Linear and Nonlinear Programming&lt;/em&gt; (3rd ed.). Springer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Vanderbei, R. J.&lt;/strong&gt; (2020). &lt;em&gt;Linear Programming: Foundations and Extensions&lt;/em&gt; (5th ed.). Springer.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Ghi chú:&lt;/strong&gt; Các bài tập trên được sắp xếp từ cơ bản đến nâng cao theo các giáo trình chuẩn về quy hoạch tuyến tính và tối ưu lồi.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>10-08 Bài tập trắc nghiệm - Tính Đối Ngẫu trong Quy Hoạch Tuyến Tính</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_08_Quiz_LP_Duality/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_08_Quiz_LP_Duality</id>
   <content type="html">&lt;p&gt;Đối ngẫu trong quy hoạch tuyến tính có một điểm rất dễ gây “xoắn não” khi làm bài kiểm tra: chỉ cần nhầm một dấu trừ, lộn chiều bất đẳng thức \(\le\) thành \(\ge\), hoặc quên điều kiện dấu của biến đối ngẫu cho ràng buộc đẳng thức là cả bài toán đối ngẫu lập tức sai lệch hoàn toàn! Ngoài ra, các câu hỏi khái niệm về 4 tổ hợp trạng thái Primal–Dual (nhất là trường hợp &lt;em&gt;cả hai đều vô nghiệm&lt;/em&gt;) cũng là cái bẫy kinh điển mà rất nhiều người học mắc phải.&lt;/p&gt;

&lt;p&gt;Trước khi bắt tay vào bộ câu hỏi trắc nghiệm Chương 10 dưới đây, hãy điểm qua bản đồ bốn cụm kiến thức cốt lõi và kiểm chứng bốn phép thử ngắn để chắc tay trước mọi câu hỏi bẫy dấu và lý thuyết.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-cụm-kiến-thức-trọng-tâm-cho-bài-trắc-nghiệm-chương-10&quot;&gt;Kiến thức cần nhớ: Bốn cụm kiến thức trọng tâm cho bài trắc nghiệm Chương 10&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bảng chuyển đổi Primal \(\leftrightarrow\) Dual (S-O-B / quy tắc dấu):&lt;/strong&gt; Với Primal dạng \(\min\): ràng buộc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt; \(\leftrightarrow\) biến đối ngẫu tự do; ràng buộc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\ge&lt;/code&gt; \(\leftrightarrow\) biến đối ngẫu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\ge 0&lt;/code&gt;; ràng buộc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\le&lt;/code&gt; \(\leftrightarrow\) biến đối ngẫu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\le 0&lt;/code&gt; (hoặc đặt biến \(v \ge 0\) rồi đổi dấu trước \(h^T v\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu yếu, đối ngẫu mạnh và 4 trạng thái khả dĩ:&lt;/strong&gt; Luôn có \(d \le p\) (với Primal \(\min\), Dual \(\max\)). Nếu Primal không bị chặn dưới \(\Rightarrow\) Dual chắc chắn vô nghiệm; nhưng ngược lại Primal vô nghiệm có thể dẫn tới Dual không bị chặn &lt;strong&gt;hoặc&lt;/strong&gt; Dual cũng vô nghiệm!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù (Complementary Slackness):&lt;/strong&gt; Tại cặp nghiệm tối ưu \((x^*, u^*)\), mọi ràng buộc bất đẳng thức gốc còn “lỏng” (\(a_i^T x^* &amp;lt; b_i\)) bắt buộc có biến đối ngẫu \(u_i^* = 0\); và mọi biến đối ngẫu dương (\(u_i^* &amp;gt; 0\)) bắt buộc kéo theo ràng buộc gốc tương ứng phải chặt (\(a_i^T x^* = b_i\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai ứng dụng kinh điển — Max Flow/Min Cut và Matrix Games:&lt;/strong&gt; Ghi nhớ rằng lát cắt cực tiểu là đối ngẫu của luồng cực đại, và định lý minimax \(\min_x \max_y x^T P y = \max_y \min_x x^T P y\) là hệ quả trực tiếp của đối ngẫu mạnh LP.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bốn-phép-thử-số-nhanh-né-bẫy-trắc-nghiệm-chương-10&quot;&gt;Giải thích: Bốn phép thử số nhanh né bẫy trắc nghiệm Chương 10&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 1 — Kiểm tra đối ngẫu yếu nhanh:&lt;/strong&gt; Một bài toán Primal \(\min\) có nghiệm khả thi đạt \(p = 12\), bài toán Dual \(\max\) có nghiệm khả thi đạt \(d = 10\). Ta kết luận được gì về \(p^*\)?
Chắc chắn \(10 \le d^* = p^* \le 12\) (giá trị tối ưu nằm trong đoạn \([10, 12]\); nếu có cặp nào đạt \(d = 12\) thì lập tức kết luận tối ưu!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 2 — Ví dụ cả Primal lẫn Dual đều vô nghiệm:&lt;/strong&gt;
Xét Primal: \(\min x_1 - x_2\) s.t. \(x_1 - x_2 \ge 1\) và \(-x_1 + x_2 \ge 1\) (hai ràng buộc mâu thuẫn nhau nên Primal vô nghiệm!).
Dual: \(\max u_1 + u_2\) s.t. \(u_1 - u_2 = 1\), \(-u_1 + u_2 = -1\)? Nếu đổi hàm mục tiêu Primal thành \(x_1 + x_2\) thì Dual đòi \(u_1 - u_2 = 1\) và \(-u_1 + u_2 = 1\) (vô nghiệm nốt!). Vậy cả hai cùng vô nghiệm là &lt;strong&gt;hoàn toàn có thể xảy ra&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 3 — Đọc nhanh biến đối ngẫu từ điều kiện bù:&lt;/strong&gt;
Giả sử tại nghiệm tối ưu \(x^* = (2, 1)\), ràng buộc \(x_1 + 2x_2 \le 10\) có vế trái \(2 + 2 = 4 &amp;lt; 10\) (còn dư \(6\) đơn vị). Không cần giải bài toán đối ngẫu, ta biết ngay giá bóng tương ứng \(v^* = 0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 4 — Giá trị trò chơi ma trận đối xứng:&lt;/strong&gt; Với ma trận chi trả phản đối xứng \(P^T = -P\) (như Oẳn Tù Tì), giá trị trò chơi \(v^*\) luôn bằng đúng \(0\) vì hai người chơi có vai trò hoàn toàn bình đẳng.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;ôn-tập-lý-thuyết&quot;&gt;Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;tính-đối-ngẫu-trong-quy-hoạch-tuyến-tính-lp-duality&quot;&gt;Tính đối ngẫu trong quy hoạch tuyến tính (LP Duality)&lt;/h3&gt;

&lt;h4 id=&quot;ý-tưởng-cơ-bản&quot;&gt;Ý tưởng cơ bản&lt;/h4&gt;
&lt;p&gt;Tính đối ngẫu trong LP xuất phát từ bài toán tìm &lt;strong&gt;cận dưới&lt;/strong&gt; cho giá trị tối ưu của bài toán gốc (primal).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nguyên lý:&lt;/strong&gt; Nếu biểu diễn được hàm mục tiêu dưới dạng &lt;strong&gt;tổ hợp tuyến tính&lt;/strong&gt; (với hệ số phù hợp) của các ràng buộc, ta thu được một cận dưới cho bài toán gốc.&lt;/p&gt;

&lt;h4 id=&quot;từ-ví-dụ-đơn-giản-đến-tổng-quát&quot;&gt;Từ ví dụ đơn giản đến tổng quát&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 1:&lt;/strong&gt; Ràng buộc chứa trực tiếp hàm mục tiêu
\(\min_{x,y} x + y \quad \text{s.t.} \quad x + y \ge 2, \quad x,y \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cận dưới trực tiếp:&lt;/strong&gt; \(B = 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 2:&lt;/strong&gt; Biểu diễn hàm mục tiêu qua tổ hợp tuyến tính của các ràng buộc
\(\min_{x,y} x + 3y \quad \text{s.t.} \quad x + y \ge 2, \quad x,y \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tổ hợp tuyến tính:&lt;/strong&gt;
\(1 \cdot (x + y) + 0 \cdot x + 2 \cdot y = x + 3y \ge 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cận dưới:&lt;/strong&gt; \(B = 2\)&lt;/p&gt;

&lt;h3 id=&quot;-xây-dựng-bài-toán-đối-ngẫu&quot;&gt;📏 Xây dựng bài toán đối ngẫu&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-gốc-tổng-quát&quot;&gt;Bài toán gốc tổng quát&lt;/h4&gt;
&lt;p&gt;\(\min_x c^T x \quad \text{s.t.} \quad Ax = b, \quad Gx \le h\)&lt;/p&gt;

&lt;h4 id=&quot;các-bước-xây-dựng-bài-toán-đối-ngẫu&quot;&gt;Các bước xây dựng bài toán đối ngẫu&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa biến đối ngẫu:&lt;/strong&gt; \(u\) (cho ràng buộc đẳng thức), \(v \ge 0\) (cho ràng buộc bất đẳng thức).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lập tổ hợp tuyến tính:&lt;/strong&gt; \(u^T(Ax - b) + v^T(Gx - h) \le 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến đổi để tách hàm mục tiêu:&lt;/strong&gt; \((-A^T u - G^T v)^T x \ge -b^T u - h^T v\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện khớp hệ số:&lt;/strong&gt; \(c = -A^T u - G^T v\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;bài-toán-đối-ngẫu&quot;&gt;Bài toán đối ngẫu&lt;/h4&gt;
&lt;p&gt;\(\max_{u,v} -b^T u - h^T v \quad \text{s.t.} \quad c = -A^T u - G^T v, \quad v \ge 0\)&lt;/p&gt;

&lt;h3 id=&quot;-quy-tắc-chuyển-đổi-gốc--đối-ngẫu&quot;&gt;🔄 Quy tắc chuyển đổi gốc – đối ngẫu&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;strong&gt;Bài toán gốc (Primal)&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Bài toán đối ngẫu (Dual)&lt;/strong&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;\(\min\)&lt;/td&gt;
      &lt;td&gt;\(\max\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(Ax = b\)&lt;/td&gt;
      &lt;td&gt;\(u\) không ràng buộc dấu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(Gx \le h\)&lt;/td&gt;
      &lt;td&gt;\(v \ge 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(x \ge 0\)&lt;/td&gt;
      &lt;td&gt;Ràng buộc bất đẳng thức trong bài toán đối ngẫu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(x\) không ràng buộc dấu&lt;/td&gt;
      &lt;td&gt;Ràng buộc đẳng thức trong bài toán đối ngẫu&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h4 id=&quot;ví-dụ-chuyển-đổi&quot;&gt;Ví dụ chuyển đổi&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Bài toán gốc:&lt;/strong&gt;
\(\min_{x,y} px + qy \quad \text{s.t.} \quad x \ge 0, \quad y \le 1, \quad 3x + y = 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;
\(\max_{a,b,c} 2c - b \quad \text{s.t.} \quad a + 3c = p, \quad -b + c = q, \quad a,b \ge 0\)&lt;/p&gt;

&lt;h3 id=&quot;-ví-dụ-luồng-cực-đại--lát-cắt-cực-tiểu&quot;&gt;🌊 Ví dụ: Luồng cực đại – lát cắt cực tiểu&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-luồng-cực-đại-max-flow&quot;&gt;Bài toán luồng cực đại (Max Flow)&lt;/h4&gt;
&lt;p&gt;Tìm luồng lớn nhất từ nguồn \(s\) đến đích \(t\) trong đồ thị có hướng:&lt;/p&gt;

\[\max \sum_{(s,j) \in E} f_{sj} \quad \text{s.t.} \begin{cases}
f_{ij} \ge 0, \quad f_{ij} \le c_{ij} &amp;amp; \forall (i,j) \in E \\
\sum_{(i,k) \in E} f_{ik} = \sum_{(k,j) \in E} f_{kj} &amp;amp; \forall k \in V \setminus \{s,t\}
\end{cases}\]

&lt;h4 id=&quot;bài-toán-lát-cắt-cực-tiểu-min-cut&quot;&gt;Bài toán lát cắt cực tiểu (Min Cut)&lt;/h4&gt;
&lt;p&gt;Tìm lát cắt có dung lượng nhỏ nhất phân tách \(s\) và \(t\):&lt;/p&gt;

\[\min \sum_{(i,j) \in E} b_{ij} c_{ij} \quad \text{s.t.} \begin{cases}
b_{ij} \ge x_i - x_j &amp;amp; \forall (i,j) \in E \\
x_i, b_{ij} \in \{0,1\} &amp;amp; \forall i,j \\
x_s = 1, x_t = 0
\end{cases}\]

&lt;h4 id=&quot;mối-quan-hệ-đối-ngẫu&quot;&gt;Mối quan hệ đối ngẫu&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Đối ngẫu của luồng cực đại = Bản nới lỏng LP của lát cắt cực tiểu&lt;/strong&gt;&lt;/p&gt;

\[\text{Max Flow Value} \le \text{Dual LP} = \text{LP Relaxed Min Cut} \le \text{Min Cut Capacity}\]

&lt;p&gt;&lt;strong&gt;Định lý luồng cực đại – lát cắt cực tiểu:&lt;/strong&gt; Cả ba giá trị trên đều bằng nhau.&lt;/p&gt;

&lt;h3 id=&quot;cách-tiếp-cận-lagrangian&quot;&gt;Cách tiếp cận Lagrangian&lt;/h3&gt;

&lt;h4 id=&quot;hàm-lagrangian&quot;&gt;Hàm Lagrangian&lt;/h4&gt;
&lt;p&gt;Với bài toán tối ưu tổng quát:
\(\min_x f(x) \quad \text{s.t.} \quad Ax = b, \quad Gx \le h\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm Lagrangian:&lt;/strong&gt;
\(L(x,u,v) = f(x) + u^T(Ax - b) + v^T(Gx - h)\)&lt;/p&gt;

&lt;h4 id=&quot;hàm-đối-ngẫu&quot;&gt;Hàm đối ngẫu&lt;/h4&gt;
&lt;p&gt;\(g(u,v) = \min_x L(x,u,v)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất:&lt;/strong&gt; \(g(u,v) \le f^*\) với mọi \(v \ge 0\) (đối ngẫu yếu).&lt;/p&gt;

&lt;h4 id=&quot;bài-toán-đối-ngẫu-lagrangian&quot;&gt;Bài toán đối ngẫu Lagrangian&lt;/h4&gt;
&lt;p&gt;\(\max_{u,v} g(u,v) \quad \text{s.t.} \quad v \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;áp-dụng-cho-lp&quot;&gt;Áp dụng cho LP&lt;/h4&gt;
&lt;p&gt;\(g(u,v) = \min_x (c + A^T u + G^T v)^T x - b^T u - h^T v\)&lt;/p&gt;

\[= \begin{cases}
-b^T u - h^T v &amp;amp; \text{if } c + A^T u + G^T v = 0 \\
-\infty &amp;amp; \text{otherwise}
\end{cases}\]

&lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt; Trùng khớp với bài toán LP đối ngẫu xây dựng theo tổ hợp tuyến tính.&lt;/p&gt;

&lt;h3 id=&quot;-trò-chơi-ma-trận&quot;&gt;🎮 Trò chơi ma trận&lt;/h3&gt;

&lt;h4 id=&quot;thiết-lập-trò-chơi&quot;&gt;Thiết lập trò chơi&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hai người chơi:&lt;/strong&gt; \(J\) (chọn hàng) và \(R\) (chọn cột).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ma trận chi trả:&lt;/strong&gt; \(P\) (khoản tiền \(J\) trả cho \(R\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược hỗn hợp:&lt;/strong&gt; phân phối xác suất \(x\) (của \(J\)) và \(y\) (của \(R\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi trả kỳ vọng:&lt;/strong&gt; \(x^T P y\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;góc-nhìn-của-j-người-cực-tiểu-hóa&quot;&gt;Góc nhìn của J (người cực tiểu hóa)&lt;/h4&gt;
&lt;p&gt;Khi \(R\) biết trước chiến lược của \(J\), \(J\) muốn cực tiểu hóa chi trả kỳ vọng trong trường hợp xấu nhất:
\(\min_x \max_{i=1,\ldots,n} (P^T x)_i \quad \text{s.t.} \quad x \ge 0, \quad \mathbf{1}^T x = 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dạng LP tương đương:&lt;/strong&gt;
\(\min_{x,t} t \quad \text{s.t.} \quad x \ge 0, \quad \mathbf{1}^T x = 1, \quad P^T x \preceq t \mathbf{1}\)&lt;/p&gt;

&lt;h4 id=&quot;góc-nhìn-của-r-người-cực-đại-hóa&quot;&gt;Góc nhìn của R (người cực đại hóa)&lt;/h4&gt;
&lt;p&gt;Khi \(J\) biết trước chiến lược của \(R\), \(R\) muốn cực đại hóa chi trả kỳ vọng trong trường hợp xấu nhất:
\(\max_y \min_{j=1,\ldots,m} (Py)_j \quad \text{s.t.} \quad y \ge 0, \quad \mathbf{1}^T y = 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dạng LP tương đương:&lt;/strong&gt;
\(\max_{y,v} v \quad \text{s.t.} \quad y \ge 0, \quad \mathbf{1}^T y = 1, \quad Py \succeq v \mathbf{1}\)&lt;/p&gt;

&lt;h4 id=&quot;định-lý-minimax-của-von-neumann&quot;&gt;Định lý minimax của von Neumann&lt;/h4&gt;
&lt;p&gt;Hai bài toán trên là cặp &lt;strong&gt;gốc – đối ngẫu&lt;/strong&gt; của nhau và có cùng giá trị tối ưu:
\(\min_x \max_y x^T P y = \max_y \min_x x^T P y\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lý do:&lt;/strong&gt; \(x^T P y\) là hàm song tuyến tính (lồi theo \(x\), lõm theo \(y\)) trên các đơn hình lồi compact; đồng thời đây là một cặp LP đối ngẫu khả thi nên tính đối ngẫu mạnh luôn đúng.&lt;/p&gt;

&lt;h3 id=&quot;đối-ngẫu-yếu-và-đối-ngẫu-mạnh&quot;&gt;Đối ngẫu yếu và đối ngẫu mạnh&lt;/h3&gt;

&lt;h4 id=&quot;đối-ngẫu-yếu-weak-duality&quot;&gt;Đối ngẫu yếu (Weak Duality)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Luôn đúng:&lt;/strong&gt; giá trị đối ngẫu \(\le\) giá trị gốc:
\(\max_{u,v} g(u,v) \le \min_x f(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Khoảng cách đối ngẫu (Duality gap):&lt;/strong&gt; \(f^* - g^* \ge 0\).&lt;/p&gt;

&lt;h4 id=&quot;đối-ngẫu-mạnh-strong-duality&quot;&gt;Đối ngẫu mạnh (Strong Duality)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Đẳng thức:&lt;/strong&gt; giá trị đối ngẫu = giá trị gốc:
\(\max_{u,v} g(u,v) = \min_x f(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Khoảng cách đối ngẫu:&lt;/strong&gt; \(f^* - g^* = 0\).&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-đối-ngẫu-mạnh-trong-lp&quot;&gt;Điều kiện đối ngẫu mạnh trong LP&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu ít nhất một trong hai bài toán (gốc hoặc đối ngẫu) khả thi thì tính đối ngẫu mạnh luôn đúng.&lt;/li&gt;
  &lt;li&gt;Trường hợp ngoại lệ duy nhất: cả hai bài toán đều vô nghiệm (infeasible).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-các-dạng-chuẩn-của-lp&quot;&gt;🔄 Các dạng chuẩn của LP&lt;/h3&gt;

&lt;h4 id=&quot;dạng-chuẩn-standard-form&quot;&gt;Dạng chuẩn (Standard form)&lt;/h4&gt;
&lt;p&gt;\(\min c^T x \quad \text{s.t.} \quad Ax = b, \quad x \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đối ngẫu:&lt;/strong&gt;
\(\max b^T u \quad \text{s.t.} \quad A^T u \le c\)&lt;/p&gt;

&lt;h4 id=&quot;dạng-bất-đẳng-thức-inequality-form&quot;&gt;Dạng bất đẳng thức (Inequality form)&lt;/h4&gt;
&lt;p&gt;\(\min c^T x \quad \text{s.t.} \quad Ax \le b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đối ngẫu:&lt;/strong&gt;
\(\max -b^T u \quad \text{s.t.} \quad A^T u = -c, \quad u \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;dạng-tổng-quát-general-form&quot;&gt;Dạng tổng quát (General form)&lt;/h4&gt;
&lt;p&gt;\(\min c^T x \quad \text{s.t.} \quad Ax = b, \quad Gx \le h\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đối ngẫu:&lt;/strong&gt;
\(\max -b^T u - h^T v \quad \text{s.t.} \quad -A^T u - G^T v = c, \quad v \ge 0\)&lt;/p&gt;

&lt;h3 id=&quot;️-kỹ-năng-thực-hành&quot;&gt;🛠️ Kỹ năng thực hành&lt;/h3&gt;

&lt;h4 id=&quot;xây-dựng-bài-toán-đối-ngẫu-từ-bài-toán-gốc&quot;&gt;Xây dựng bài toán đối ngẫu từ bài toán gốc&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;Xác định dạng bài toán (cực tiểu hay cực đại, loại ràng buộc).&lt;/li&gt;
  &lt;li&gt;Áp dụng bảng quy tắc chuyển đổi gốc – đối ngẫu.&lt;/li&gt;
  &lt;li&gt;Kiểm tra lại tính hợp lý bằng bất đẳng thức đối ngẫu yếu.&lt;/li&gt;
  &lt;li&gt;Xác định điều kiện để đối ngẫu mạnh thỏa mãn.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;ý-nghĩa-kinh-tế&quot;&gt;Ý nghĩa kinh tế&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Biến gốc:&lt;/strong&gt; mức sản xuất hoặc phương án phân bổ nguồn lực.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến đối ngẫu:&lt;/strong&gt; giá bóng (shadow prices), phản ánh giá trị biên của từng ràng buộc nguồn lực.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách đối ngẫu:&lt;/strong&gt; độ chênh lệch giữa giá trị mục tiêu gốc và đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;một-số-ứng-dụng-tiêu-biểu&quot;&gt;Một số ứng dụng tiêu biểu&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Luồng trên mạng:&lt;/strong&gt; định tuyến mạng, vận tải.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết trò chơi:&lt;/strong&gt; chiến lược hỗn hợp, thiết kế đấu giá.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kinh tế học:&lt;/strong&gt; cân bằng thị trường, phân bổ tài nguyên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học máy:&lt;/strong&gt; dạng đối ngẫu của máy vector hỗ trợ (SVM).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-minh-họa&quot;&gt;Ví dụ minh họa&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-đơn-giản&quot;&gt;Bài toán đơn giản&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Bài toán gốc:&lt;/strong&gt;
\(\min 2x_1 + 3x_2 \quad \text{s.t.} \quad x_1 + x_2 \ge 1, \quad x_1, x_2 \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt;
\(\max u \quad \text{s.t.} \quad u \le 2, \quad u \le 3, \quad u \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nghiệm tối ưu gốc: \(x_1^* = 1, x_2^* = 0\), \(f^* = 2\).&lt;/li&gt;
  &lt;li&gt;Nghiệm tối ưu đối ngẫu: \(u^* = 2\), \(g^* = 2\).&lt;/li&gt;
  &lt;li&gt;Đối ngẫu mạnh: \(f^* = g^* = 2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;điều-kiện-bù-complementary-slackness&quot;&gt;Điều kiện bù (Complementary slackness)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(x_1^* &amp;gt; 0 \Rightarrow u^* = 2\) (ràng buộc đối ngẫu chặt).&lt;/li&gt;
  &lt;li&gt;\(x_2^* = 0 \Rightarrow u^* \le 3\) (ràng buộc đối ngẫu được phép lỏng).&lt;/li&gt;
  &lt;li&gt;\(u^* &amp;gt; 0 \Rightarrow x_1^* + x_2^* = 1\) (ràng buộc gốc chặt).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;kết-nối-với-các-chương-khác&quot;&gt;Kết nối với các chương khác&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Các chương trước:&lt;/strong&gt; LP như bài toán chuẩn (Chương 05), điều kiện tối ưu (Chương 04), hàm lồi và tính chất (Chương 03).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hướng phát triển:&lt;/strong&gt; Lý thuyết đối ngẫu tổng quát (Chương 11), điều kiện KKT (Chương 12), cùng các ứng dụng trong tối ưu có ràng buộc và lý thuyết trò chơi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;lưu-ý-khi-làm-bài&quot;&gt;Lưu ý khi làm bài&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lỗi thường gặp:&lt;/strong&gt; Nhầm chiều bất đẳng thức (\(\le / \ge\)) hoặc nhầm \(\min / \max\) khi chuyển đổi; quên điều kiện dấu không âm của biến đối ngẫu; không kiểm tra tính khả thi của cả hai bài toán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách tự kiểm tra:&lt;/strong&gt; Luôn kiểm tra bất đẳng thức đối ngẫu yếu \(g^* \le f^*\), kiểm tra điều kiện bù tại nghiệm tối ưu, và đối chiếu ý nghĩa kinh tế của biến đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Ghi chú:&lt;/strong&gt; Tính đối ngẫu LP là cơ sở trực tiếp cho lý thuyết đối ngẫu tổng quát ở Chương 11.&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra kiến thức về tính đối ngẫu trong quy hoạch tuyến tính (LP), đối ngẫu yếu và mạnh, điều kiện bù, định lý luồng cực đại – lát cắt cực tiểu và trò chơi ma trận.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🔄 Quiz: Tính Đối Ngẫu trong Quy Hoạch Tuyến Tính&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;25&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: Primal LP form --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Cho bài toán LP primal: $$\min c^T x$$ s.t. $$Ax = b, Gx \leq h$$. Bài toán dual có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) $$\max -b^T u - h^T v$$ s.t. $$-A^T u - G^T v = c, v \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) $$\min -b^T u - h^T v$$ s.t. $$-A^T u - G^T v = c, v \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) $$\max -b^T u - h^T v$$ s.t. $$-A^T u - G^T v = c, v \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) $$\max c^T x$$ s.t. $$Ax \geq b, Gx = h$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max -b^T u - h^T v$$ s.t. $$-A^T u - G^T v = c, v \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Đối ngẫu của bài toán cực tiểu hóa là bài toán cực đại hóa. Biến đối ngẫu $$u$$ ứng với ràng buộc đẳng thức không bị ràng buộc dấu, còn $$v$$ ứng với ràng buộc bất đẳng thức phải không âm. Từ Lagrangian $$L = c^Tx + u^T(Ax-b) + v^T(Gx-h)$$, cực tiểu theo $$x$$ hữu hạn khi và chỉ khi $$c + A^Tu + G^Tv = 0$$, khi đó $$g(u,v) = -b^Tu - h^Tv$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Weak duality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Định lý đối ngẫu yếu (weak duality) phát biểu rằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) Giá trị tối ưu của bài toán gốc bằng giá trị tối ưu của bài toán đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) Giá trị tối ưu của bài toán gốc luôn lớn hơn hoặc bằng giá trị tối ưu của bài toán đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Giá trị tối ưu của bài toán gốc luôn nhỏ hơn giá trị tối ưu của bài toán đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Bài toán gốc và bài toán đối ngẫu không thể cùng có nghiệm tối ưu&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Giá trị tối ưu của bài toán gốc luôn lớn hơn hoặc bằng giá trị tối ưu của bài toán đối ngẫu&lt;/strong&gt;&lt;br /&gt;
                Đối ngẫu yếu: $$p^* \geq d^*$$, trong đó $$p^*$$ là giá trị tối ưu của bài toán gốc (cực tiểu hóa) và $$d^*$$ là giá trị tối ưu của bài toán đối ngẫu (cực đại hóa).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Strong duality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Tính đối ngẫu mạnh (strong duality) xảy ra khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) $$p^* &amp;lt; d^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) $$p^* = d^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) $$p^* &amp;gt; d^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Primal không có nghiệm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$p^* = d^*$$&lt;/strong&gt;&lt;br /&gt;
                Đối ngẫu mạnh có nghĩa là khoảng cách đối ngẫu bằng 0: giá trị tối ưu của bài toán gốc bằng giá trị tối ưu của bài toán đối ngẫu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Complementary slackness --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Với cặp LP $$\min c^T x$$ s.t. $$Ax \geq b, x \geq 0$$ và $$\max b^T y$$ s.t. $$A^T y \leq c, y \geq 0$$, complementary slackness phát biểu rằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$x_i &amp;gt; 0 \Rightarrow (A^T y)_i = c_i$$ và $$y_j &amp;gt; 0 \Rightarrow (Ax)_j = b_j$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) $$x_i = 0$$ và $$y_j = 0$$ với mọi $$i, j$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Primal và dual cùng feasible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) $$Ax \geq b$$ và $$x \geq 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$x_i &amp;gt; 0 \Rightarrow (A^T y)_i = c_i$$ và $$y_j &amp;gt; 0 \Rightarrow (Ax)_j = b_j$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện bù (complementary slackness): nếu biến gốc dương thì ràng buộc đối ngẫu tương ứng chặt, và nếu biến đối ngẫu dương thì ràng buộc gốc tương ứng chặt.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Duality gap --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Duality gap được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) $$d^* - p^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) $$p^* - d^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) $$p^* + d^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) $$|p^* - d^*|$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$p^* - d^*$$&lt;/strong&gt;&lt;br /&gt;
                Khoảng cách đối ngẫu là hiệu giữa giá trị tối ưu của bài toán gốc và bài toán đối ngẫu; theo đối ngẫu yếu, hiệu này luôn không âm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Standard form LP dual --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Cho LP ở dạng chuẩn: $$\min c^T x$$ s.t. $$Ax = b, x \geq 0$$. Bài toán dual là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) $$\max b^T y$$ s.t. $$A^T y \leq c$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) $$\max b^T y$$ s.t. $$A^T y = c$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) $$\min b^T y$$ s.t. $$A^T y \geq c$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) $$\max b^T y$$ s.t. $$A^T y \geq c$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max b^T y$$ s.t. $$A^T y \leq c$$&lt;/strong&gt;&lt;br /&gt;
                Đối ngẫu của LP dạng chuẩn: biến đối ngẫu $$y$$ không bị ràng buộc dấu vì bài toán gốc chỉ có ràng buộc đẳng thức.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Max flow problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Trong bài toán max flow, mục tiêu là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Cực tiểu hóa tổng dung lượng của các cạnh&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Cực đại hóa luồng từ nguồn đến đích&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Cực tiểu hóa số cạnh trong đường đi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Cực đại hóa số đỉnh được ghé thăm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Cực đại hóa luồng từ nguồn đến đích&lt;/strong&gt;&lt;br /&gt;
                Bài toán luồng cực đại tìm tổng lưu lượng lớn nhất có thể truyền từ đỉnh nguồn đến đỉnh đích qua mạng.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Min cut problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Bài toán lát cắt cực tiểu (min cut) tìm:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) Tập cạnh có tổng dung lượng nhỏ nhất để tách rời nguồn và đích&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) Đường đi ngắn nhất từ nguồn đến đích&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Số cạnh tối thiểu để kết nối tất cả đỉnh&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) Cây khung nhỏ nhất của đồ thị&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Tập cạnh có tổng dung lượng nhỏ nhất để tách rời nguồn và đích&lt;/strong&gt;&lt;br /&gt;
                Lát cắt cực tiểu tìm phân hoạch tập đỉnh thành hai tập chứa nguồn và đích sao cho tổng dung lượng các cạnh đi từ tập nguồn sang tập đích là nhỏ nhất.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Max flow min cut theorem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Định lý luồng cực đại – lát cắt cực tiểu phát biểu rằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) Giá trị luồng cực đại bằng dung lượng của lát cắt cực tiểu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) Max flow luôn nhỏ hơn min cut&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) Min cut luôn nhỏ hơn max flow&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) Max flow và min cut không liên quan&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Giá trị luồng cực đại bằng dung lượng của lát cắt cực tiểu&lt;/strong&gt;&lt;br /&gt;
                Đây là một ví dụ kinh điển về tính đối ngẫu mạnh giữa bài toán luồng cực đại và lát cắt cực tiểu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Matrix games --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Trong trò chơi ma trận với ma trận chi trả $$P$$, người chơi J muốn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) Cực đại hóa chi trả kỳ vọng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) Cực tiểu hóa mức lỗ tối đa (minimax)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Cực đại hóa mức lãi tối thiểu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) Cực tiểu hóa chi trả kỳ vọng&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Cực tiểu hóa mức lỗ tối đa (minimax)&lt;/strong&gt;&lt;br /&gt;
                Người chơi J (người chọn hàng) tìm chiến lược hỗn hợp để cực tiểu hóa mức chi trả xấu nhất có thể phải trả cho R.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Feasible region --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Nếu LP gốc có miền khả thi rỗng (vô nghiệm), thì LP đối ngẫu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Cũng có miền khả thi rỗng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Có thể không bị chặn (unbounded) hoặc vô nghiệm (infeasible)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Luôn có nghiệm tối ưu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Luôn không bị chặn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Có thể không bị chặn (unbounded) hoặc vô nghiệm (infeasible)&lt;/strong&gt;&lt;br /&gt;
                Khi bài toán gốc vô nghiệm, bài toán đối ngẫu có thể không bị chặn (nếu khả thi) hoặc cũng vô nghiệm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Economic interpretation --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Trong kinh tế học, các biến đối ngẫu thường được hiểu là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Giá bóng (shadow prices)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Production quantities&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Market demands&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Cost coefficients&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Giá bóng (shadow prices)&lt;/strong&gt;&lt;br /&gt;
                Biến đối ngẫu biểu thị giá trị biên của nguồn lực, tức mức thay đổi của hàm mục tiêu khi tăng thêm một đơn vị nguồn lực.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Dual of dual --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Dual của dual problem là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Một bài toán hoàn toàn khác&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Primal problem ban đầu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Không tồn tại&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Bằng dual problem&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Primal problem ban đầu&lt;/strong&gt;&lt;br /&gt;
                Tính chất đối xứng: dual của dual chính là primal problem ban đầu (có thể cần chuyển đổi dạng).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: LP duality conditions --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Để có strong duality trong LP, điều kiện cần là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Cả primal và dual đều có nghiệm optimal&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Primal hoặc dual có interior point (Slater condition)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Feasible region là bounded&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Không cần điều kiện gì, LP luôn có strong duality&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Không cần điều kiện gì, LP luôn có strong duality&lt;/strong&gt;&lt;br /&gt;
                Trong LP, nếu ít nhất một trong hai bài toán gốc hoặc đối ngẫu khả thi thì đối ngẫu mạnh luôn thỏa mãn mà không cần thêm điều kiện Slater; ngoại lệ duy nhất là khi cả hai bài toán đều vô nghiệm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Primal-dual algorithm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Các thuật toán gốc – đối ngẫu (primal-dual) giải LP bằng cách:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Chỉ giải primal problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Chỉ giải dual problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Đồng thời cập nhật cả biến gốc và biến đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Giải tuần tự primal rồi dual&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Đồng thời cập nhật cả biến gốc và biến đối ngẫu&lt;/strong&gt;&lt;br /&gt;
                Các phương pháp gốc – đối ngẫu duy trì và cập nhật đồng thời cả nghiệm gốc lẫn nghiệm đối ngẫu, sử dụng khoảng cách đối ngẫu để kiểm soát hội tụ.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Sensitivity analysis --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Nghiệm tối ưu đối ngẫu cung cấp thông tin về:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Độ nhạy của giá trị mục tiêu đối với sự thay đổi của các ràng buộc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Số lượng iterations cần thiết&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Complexity của algorithm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Condition number của matrix&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Độ nhạy của giá trị mục tiêu đối với sự thay đổi của các ràng buộc&lt;/strong&gt;&lt;br /&gt;
                Biến đối ngẫu cho biết giá trị tối ưu thay đổi như thế nào khi vế phải của các ràng buộc biến động.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Game theory equilibrium --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Cân bằng Nash trong trò chơi ma trận tương ứng với:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Primal optimal solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Dual optimal solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Cặp nghiệm tối ưu của bài toán gốc và bài toán đối ngẫu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Feasible solution bất kỳ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Cặp nghiệm tối ưu của bài toán gốc và bài toán đối ngẫu&lt;/strong&gt;&lt;br /&gt;
                Cặp chiến lược hỗn hợp ở cân bằng Nash tương ứng với cặp nghiệm tối ưu của hai bài toán LP gốc – đối ngẫu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Unbounded LP --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Nếu LP gốc không bị chặn dưới (unbounded below), thì LP đối ngẫu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Cũng unbounded&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Infeasible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Có nghiệm optimal&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Bounded&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Infeasible&lt;/strong&gt;&lt;br /&gt;
                Nếu bài toán gốc (cực tiểu hóa) không bị chặn dưới, bài toán đối ngẫu (cực đại hóa) bắt buộc phải vô nghiệm theo định lý đối ngẫu yếu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Flow conservation --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Trong bài toán luồng cực đại, ràng buộc bảo toàn luồng yêu cầu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Tổng luồng vào mỗi nút bằng tổng luồng ra (trừ nguồn và đích)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Luồng trên mỗi cạnh không vượt quá dung lượng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Luồng phải không âm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Tất cả các điều kiện trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Tổng luồng vào mỗi nút bằng tổng luồng ra (trừ nguồn và đích)&lt;/strong&gt;&lt;br /&gt;
                Bảo toàn luồng: $$\sum_{i} f_{ij} = \sum_{k} f_{jk}$$ tại mọi nút trung gian $$j$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: LP duality applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: LP duality có ứng dụng trong:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Kinh tế học (resource allocation)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Network flows và transportation&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Game theory và decision making&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các lĩnh vực trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các lĩnh vực trên&lt;/strong&gt;&lt;br /&gt;
                Tính đối ngẫu LP được ứng dụng trong kinh tế học (giá bóng), mạng luồng (luồng cực đại – lát cắt cực tiểu), lý thuyết trò chơi (định lý minimax) và nhiều lĩnh vực khác.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Bài toán đối ngẫu của LP $$\min c^T x$$ với $$Ax \geq b, x \geq 0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$\max b^T y$$ với $$A^T y \leq c, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$\max b^T y$$ với $$A^T y \geq c, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$\min b^T y$$ với $$A^T y \leq c, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$\max c^T y$$ với $$A^T y \leq b, y \geq 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max b^T y$$ với $$A^T y \leq c, y \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán đối ngẫu của LP có dạng $$\max b^T y$$ với $$A^T y \leq c, y \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Định lý đối ngẫu mạnh trong LP khẳng định:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$c^T x^* = b^T y^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$c^T x^* \leq b^T y^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$c^T x^* \geq b^T y^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Không có mối quan hệ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$c^T x^* = b^T y^*$$&lt;/strong&gt;&lt;br /&gt;
                Khi cả primal và dual đều có nghiệm tối ưu, giá trị tối ưu của chúng bằng nhau.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Theo điều kiện bù trong LP, nếu $$x_i &amp;gt; 0$$ thì:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Ràng buộc đối ngẫu tương ứng chặt (active)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Ràng buộc đối ngẫu tương ứng lỏng (inactive)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$y_i = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$y_i &amp;gt; 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Ràng buộc đối ngẫu tương ứng chặt (active)&lt;/strong&gt;&lt;br /&gt;
                Điều kiện bù: nếu $$x_i &amp;gt; 0$$ thì ràng buộc đối ngẫu $$\sum_j a_{ji}y_j = c_i$$ phải xảy ra dấu bằng (chặt).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Duality gap trong LP bằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$c^T x - b^T y$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$b^T y - c^T x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$|c^T x - b^T y|$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) $$\max\{c^T x, b^T y\}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$c^T x - b^T y$$&lt;/strong&gt;&lt;br /&gt;
                Duality gap = giá trị primal - giá trị dual = $$c^T x - b^T y \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Cho LP: $$\min 2x_1 + 3x_2$$ với $$x_1 + x_2 \geq 1, x_1, x_2 \geq 0$$. Bài toán dual là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$\max y$$ với $$y \leq 2, y \leq 3, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$\max y$$ với $$y \geq 2, y \geq 3, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$\min y$$ với $$y \leq 2, y \leq 3, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$\max 2y + 3y$$ với $$y \geq 1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\max y$$ với $$y \leq 2, y \leq 3, y \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Dual: $$\max y$$ với $$y \leq 2$$ (từ $$x_1 \geq 0$$), $$y \leq 3$$ (từ $$x_2 \geq 0$$), $$y \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành Quiz!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;a&apos;, q5: &apos;b&apos;,
    q6: &apos;a&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;b&apos;,
    q11: &apos;b&apos;, q12: &apos;a&apos;, q13: &apos;b&apos;, q14: &apos;d&apos;, q15: &apos;c&apos;,
    q16: &apos;a&apos;, q17: &apos;c&apos;, q18: &apos;b&apos;, q19: &apos;a&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã nắm vững lý thuyết đối ngẫu LP.&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu tốt mối quan hệ gốc – đối ngẫu.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại điều kiện bù và các ứng dụng.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Ôn lại đối ngẫu yếu/mạnh và cách lập bài toán đối ngẫu.&apos;;
    } else {
        message = &apos;📖 Hãy ôn lại từ đầu các khái niệm về đối ngẫu LP.&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>10-06 Tính Chất Đối Ngẫu Kép - Dual của Dual là Primal</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_06_Dual_of_Dual_Property/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_06_Dual_of_Dual_Property</id>
   <content type="html">&lt;p&gt;Trong toán học, có những phép biến đổi “hai lần thì trở về chính mình” — gọi là &lt;strong&gt;phép đối hợp (involution)&lt;/strong&gt; — giống như phép lấy đối xứng qua gương, phép nghịch đảo \(1/(1/x) = x\) hay phép chuyển vị ma trận \((A^T)^T = A\). Trong quy hoạch tuyến tính, phép lấy bài toán đối ngẫu cũng sở hữu vẻ đẹp đối xứng tuyệt đối đó: &lt;strong&gt;đối ngẫu của bài toán đối ngẫu chính là bài toán gốc (Dual of Dual = Primal)&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Tại sao tính chất này lại quan trọng chứ không chỉ là một trò đố đại số? Bởi vì nó biến mọi định lý một chiều thành định lý hai chiều đối xứng hoàn toàn! Chẳng hạn, khi bạn biết “Primal khả thi và bị chặn \(\implies\) Dual có nghiệm”, nhờ tính đối hợp bạn suy ra ngay chiều ngược lại mà không cần chứng minh thêm dòng nào. Và trong thuật toán thực hành (như Dual Simplex), nếu bài toán gốc có ít biến nhưng cả triệu ràng buộc, ta chỉ việc giải bài toán đối ngẫu có ít ràng buộc rồi chuyển ngược về nghiệm gốc mà không lo mất thông tin.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-tính-chất-đối-ngẫu-kép-trong-lp&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của tính chất đối ngẫu kép trong LP&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn hóa bài toán đối ngẫu về dạng cực tiểu:&lt;/strong&gt; Bài toán đối ngẫu sinh ra ở dạng \(\max\) với ràng buộc \(\le\) hoặc \(=\). Để áp dụng lại đúng cùng một quy tắc lấy đối ngẫu, ta đổi \(\max f \leftrightarrow -\min(-f)\) và đổi chiều mọi ràng buộc \(\ge\) sang \(\le\) bằng cách nhân \(-1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép chuyển vị kép và bảo toàn dấu biến:&lt;/strong&gt; Ma trận ràng buộc bị chuyển vị hai lần \((A^T)^T = A\) nên cấu trúc hệ số quay lại y nguyên; biến đối ngẫu không âm \(v \ge 0\) tạo ra ràng buộc bất đẳng thức, rồi bất đẳng thức ấy lại sinh ra biến không âm (hoặc biến tự do tạo ràng buộc đẳng thức rồi đẳng thức lại tạo biến tự do).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối xứng toàn diện trong bảng phân loại 4 trạng thái LP:&lt;/strong&gt; Nhờ tính đối hợp, cặp Primal–Dual chỉ có thể rơi vào 4 tổ hợp hợp lệ: (1) Cả hai tối ưu với \(p^* = d^*\); (2) Primal không bị chặn và Dual vô nghiệm; (3) Dual không bị chặn và Primal vô nghiệm; (4) Cả hai đều vô nghiệm. (Không bao giờ có chuyện một bên tối ưu hữu hạn mà bên kia vô nghiệm!)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-thực-hiện-tay-hai-lần-lấy-đối-ngẫu-trên-một-lp-2-biến&quot;&gt;Giải thích: Thực hiện tay hai lần lấy đối ngẫu trên một LP 2 biến&lt;/h3&gt;

&lt;p&gt;Xét bài toán gốc &lt;strong&gt;(P)&lt;/strong&gt;:
\(\min_{x_1, x_2} \; 2x_1 + 3x_2 \quad \text{s.t.} \quad x_1 + x_2 \ge 4, \quad x_1 \ge 0, \; x_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lần 1 — Lấy đối ngẫu của (P) để thu được (D):&lt;/strong&gt;
Nhân ràng buộc \(x_1 + x_2 \ge 4\) với \(u \ge 0\) để chặn dưới \(2x_1 + 3x_2\):
&lt;strong&gt;(D):&lt;/strong&gt; \(\max_u \; 4u \quad \text{s.t.} \quad u \le 2, \quad u \le 3, \quad u \ge 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đưa (D) về dạng cực tiểu hóa chuẩn để chuẩn bị lấy đối ngẫu lần 2:&lt;/strong&gt;
\(\min_u \; -4u \quad \text{s.t.} \quad \begin{cases} -u \ge -2 &amp;amp; (\text{biến đối ngẫu } y_1 \ge 0) \\ -u \ge -3 &amp;amp; (\text{biến đối ngẫu } y_2 \ge 0) \\ u \ge 0. \end{cases}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lần 2 — Lấy đối ngẫu của (D) để thu được (DD):&lt;/strong&gt;
Nhân hai ràng buộc với \(y_1, y_2 \ge 0\) sao cho tổ hợp tuyến tính \(-(y_1 + y_2)u \le -4u\) (vì \(u \ge 0\), điều này tương đương \(-y_1 - y_2 \le -4 \iff y_1 + y_2 \ge 4\)):
    &lt;ul&gt;
      &lt;li&gt;Hàm mục tiêu (vế phải của tổ hợp): \(\max_{y_1, y_2 \ge 0} \; (-2y_1 - 3y_2)\).&lt;/li&gt;
      &lt;li&gt;Đổi dấu về dạng cực tiểu hóa (nhớ rằng ta đã đảo dấu mục tiêu từ \(\max 4u\) sang \(\min -4u\) ở bước 2):
&lt;strong&gt;(DD):&lt;/strong&gt; \(\min_{y_1, y_2 \ge 0} \; 2y_1 + 3y_2 \quad \text{s.t.} \quad y_1 + y_2 \ge 4!\)
Đổi tên biến \((y_1, y_2) \to (x_1, x_2)\), ta thu lại &lt;strong&gt;chính xác 100% bài toán gốc (P)&lt;/strong&gt; ban đầu!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Trong quy hoạch tuyến tính (LP), một tính chất cơ bản của phép lấy đối ngẫu là: &lt;strong&gt;đối ngẫu của bài toán đối ngẫu chính là bài toán gốc (primal)&lt;/strong&gt;. Tính chất này được gọi là &lt;strong&gt;tính đối hợp (involution)&lt;/strong&gt; của phép đối ngẫu, hay thường gọi ngắn gọn là tính chất &lt;strong&gt;dual của dual là primal&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Tính chất này thể hiện sự đối xứng giữa bài toán gốc và bài toán đối ngẫu trong LP, có vai trò quan trọng trong cả phân tích lý thuyết lẫn thiết kế thuật toán.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;nhắc-lại-dạng-chuẩn-của-bài-toán-quy-hoạch-tuyến-tính-gốc&quot;&gt;Nhắc lại dạng chuẩn của bài toán quy hoạch tuyến tính gốc&lt;/h2&gt;

&lt;p&gt;Xét một bài toán quy hoạch tuyến tính ở dạng gốc:&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; c^T x \label{eq:primal-obj} \\
\text{subject to} \quad &amp;amp; A x \geq b, \label{eq:primal-ineq} \\
&amp;amp; x \geq 0, \label{eq:primal-nonneg}
\end{align}\]

&lt;p&gt;trong đó:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) là vector biến quyết định,&lt;/li&gt;
  &lt;li&gt;\(c \in \mathbb{R}^n\) là vector hệ số hàm mục tiêu,&lt;/li&gt;
  &lt;li&gt;\(A \in \mathbb{R}^{m \times n}\) là ma trận ràng buộc,&lt;/li&gt;
  &lt;li&gt;\(b \in \mathbb{R}^m\) là vector vế phải.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Một bài toán LP có thể được viết dưới nhiều dạng khác nhau (cực đại hóa, ràng buộc đẳng thức, biến tự do…), nhưng luôn có thể quy về dạng trên mà không làm mất tính tổng quát.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-minh-họa&quot;&gt;Ví dụ minh họa&lt;/h3&gt;

&lt;p&gt;Xét bài toán:&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; 2x_1 + 3x_2 \\
\text{subject to} \quad &amp;amp; x_1 + x_2 \geq 4, \\
&amp;amp; 2x_1 + x_2 \geq 5, \\
&amp;amp; x_1, x_2 \geq 0.
\end{align}\]

&lt;p&gt;Ở đây:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[c = \begin{bmatrix} 2 \\ 3 \end{bmatrix}\]
  &lt;/li&gt;
  &lt;li&gt;
\[A = \begin{bmatrix} 1 &amp;amp; 1 \\ 2 &amp;amp; 1 \end{bmatrix}\]
  &lt;/li&gt;
  &lt;li&gt;
\[b = \begin{bmatrix} 4 \\ 5 \end{bmatrix}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;xây-dựng-bài-toán-đối-ngẫu&quot;&gt;Xây dựng bài toán đối ngẫu&lt;/h2&gt;

&lt;p&gt;Bài toán đối ngẫu được lập từ bài toán gốc nhằm cung cấp cận dưới cho giá trị tối ưu cũng như thông tin về độ nhạy và điều kiện tối ưu. Với bài toán gốc ở trên, bài toán đối ngẫu tương ứng là:&lt;/p&gt;

\[\begin{align}
\text{maximize} \quad &amp;amp; b^T y \label{eq:dual-obj} \\
\text{subject to} \quad &amp;amp; A^T y \leq c, \label{eq:dual-ineq} \\
&amp;amp; y \geq 0, \label{eq:dual-nonneg}
\end{align}\]

&lt;p&gt;trong đó \(y \in \mathbb{R}^m\) là vector biến đối ngẫu.&lt;/p&gt;

&lt;h3 id=&quot;ý-nghĩa&quot;&gt;Ý nghĩa&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Bài toán đối ngẫu cũng là một bài toán quy hoạch tuyến tính.&lt;/li&gt;
  &lt;li&gt;Theo &lt;strong&gt;đối ngẫu yếu&lt;/strong&gt; (weak duality), giá trị mục tiêu của mọi nghiệm đối ngẫu khả thi đều là cận dưới của giá trị tối ưu bài toán gốc.&lt;/li&gt;
  &lt;li&gt;Khi &lt;strong&gt;đối ngẫu mạnh&lt;/strong&gt; (strong duality) thỏa mãn (luôn đúng với LP nếu ít nhất một trong hai bài toán khả thi), giá trị tối ưu của hai bài toán bằng nhau.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-tiếp-theo&quot;&gt;Ví dụ (tiếp theo)&lt;/h3&gt;

&lt;p&gt;Bài toán đối ngẫu của ví dụ trên là:&lt;/p&gt;

\[\begin{align}
\text{maximize} \quad &amp;amp; 4y_1 + 5y_2 \\
\text{subject to} \quad &amp;amp; y_1 + 2y_2 \leq 2, \\
&amp;amp; y_1 + y_2 \leq 3, \\
&amp;amp; y_1, y_2 \geq 0.
\end{align}\]

&lt;hr /&gt;

&lt;h2 id=&quot;xây-dựng-đối-ngẫu-của-bài-toán-đối-ngẫu&quot;&gt;Xây dựng đối ngẫu của bài toán đối ngẫu&lt;/h2&gt;

&lt;p&gt;Bây giờ, ta coi bài toán đối ngẫu vừa lập như một bài toán gốc mới và áp dụng quy tắc lấy đối ngẫu thêm một lần nữa.&lt;/p&gt;

&lt;h3 id=&quot;bước-1-đưa-bài-toán-đối-ngẫu-về-dạng-cực-tiểu-hóa&quot;&gt;Bước 1: Đưa bài toán đối ngẫu về dạng cực tiểu hóa&lt;/h3&gt;

&lt;p&gt;Đổi dấu hàm mục tiêu và nhân hai vế ràng buộc với \(-1\) để chuyển về dạng chuẩn cực tiểu hóa với ràng buộc \(\geq\):&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; -b^T y \\
\text{subject to} \quad &amp;amp; -A^T y \geq -c, \\
&amp;amp; y \geq 0.
\end{align}\]

&lt;h3 id=&quot;bước-2-áp-dụng-quy-tắc-lấy-đối-ngẫu&quot;&gt;Bước 2: Áp dụng quy tắc lấy đối ngẫu&lt;/h3&gt;

&lt;p&gt;Áp dụng quy tắc đối ngẫu cho bài toán vừa biến đổi:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Biến đối ngẫu mới: \(z \in \mathbb{R}^n\) (cùng số chiều với \(x\) trong bài toán gốc).&lt;/li&gt;
  &lt;li&gt;Hàm mục tiêu mới: cực đại hóa \((-c)^T z\), tương đương với cực tiểu hóa \(c^T z\) sau khi đổi dấu lại.&lt;/li&gt;
  &lt;li&gt;Ràng buộc mới: ma trận ràng buộc là \((-A^T)^T = -A\), nên ràng buộc là \(-A z \leq -b\), tương đương với \(A z \geq b\).&lt;/li&gt;
  &lt;li&gt;Điều kiện dấu: \(z \geq 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bước-3-kết-quả&quot;&gt;Bước 3: Kết quả&lt;/h3&gt;

&lt;p&gt;Đối ngẫu của bài toán đối ngẫu là:&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; c^T z \\
\text{subject to} \quad &amp;amp; A z \geq b, \\
&amp;amp; z \geq 0.
\end{align}\]

&lt;p&gt;Đây chính là bài toán gốc ban đầu (chỉ khác tên biến \(z\) thay cho \(x\)).&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-tiếp-theo-1&quot;&gt;Ví dụ (tiếp theo)&lt;/h3&gt;

&lt;p&gt;Xuất phát từ bài toán đối ngẫu của ví dụ trên:&lt;/p&gt;

\[\text{maximize } 4y_1 + 5y_2 \text{ s.t. } y_1 + 2y_2 \leq 2, \; y_1 + y_2 \leq 3, \; y_1, y_2 \geq 0\]

&lt;p&gt;Đưa về dạng cực tiểu hóa:&lt;/p&gt;

\[\text{minimize } -4y_1 - 5y_2 \text{ s.t. } -y_1 - 2y_2 \geq -2, \; -y_1 - y_2 \geq -3, \; y_1, y_2 \geq 0\]

&lt;p&gt;Lấy đối ngẫu (với biến \(z_1, z_2\)), ta được bài toán cực đại hóa \(-2z_1 - 3z_2\), tức cực tiểu hóa \(2z_1 + 3z_2\):&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; 2z_1 + 3z_2 \\
\text{subject to} \quad &amp;amp; z_1 + z_2 \geq 4, \\
&amp;amp; 2z_1 + z_2 \geq 5, \\
&amp;amp; z_1, z_2 \geq 0.
\end{align}\]

&lt;p&gt;Kết quả quay trở về đúng bài toán gốc ban đầu.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;giải-thích-toán-học&quot;&gt;Giải thích toán học&lt;/h2&gt;

&lt;p&gt;Tính chất đối ngẫu kép bắt nguồn từ tính đối xứng của hàm Lagrangian trong LP.&lt;/p&gt;

&lt;h3 id=&quot;1-hàm-lagrangian&quot;&gt;1. Hàm Lagrangian&lt;/h3&gt;

&lt;p&gt;Hàm Lagrangian của bài toán gốc là:&lt;/p&gt;

\[\mathcal{L}(x, y) = c^T x - y^T (A x - b),\]

&lt;p&gt;trong đó \(y \geq 0\) là vector nhân tử Lagrange cho các ràng buộc bất đẳng thức.&lt;/p&gt;

&lt;h3 id=&quot;2-quan-hệ-gốc--đối-ngẫu&quot;&gt;2. Quan hệ gốc – đối ngẫu&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán gốc:&lt;/strong&gt; \(\min_{x \geq 0} \sup_{y \geq 0} \mathcal{L}(x, y)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt; \(\max_{y \geq 0} \inf_{x \geq 0} \mathcal{L}(x, y)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Với hàm song tuyến tính (lồi theo \(x\), lõm theo \(y\)) như Lagrangian của LP, ta có quan hệ min-max:&lt;/p&gt;

\[\min_x \max_y \mathcal{L}(x, y) = \max_y \min_x \mathcal{L}(x, y)\]

&lt;p&gt;Mỗi lần lấy đối ngẫu tương ứng với một lần hoán đổi vai trò giữa cực tiểu hóa và cực đại hóa; áp dụng hai lần sẽ đưa bài toán về đúng vị trí ban đầu.&lt;/p&gt;

&lt;h3 id=&quot;3-góc-nhìn-ma-trận&quot;&gt;3. Góc nhìn ma trận&lt;/h3&gt;

&lt;p&gt;Phép lấy đối ngẫu thực hiện ba thao tác:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Chuyển vị ma trận ràng buộc: \(A \to A^T\).&lt;/li&gt;
  &lt;li&gt;Đổi chiều bất đẳng thức: \(\geq\) thành \(\leq\) (và ngược lại).&lt;/li&gt;
  &lt;li&gt;Hoán đổi vai trò giữa \(b\) và \(c\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Khi áp dụng liên tiếp hai lần, \((A^T)^T = A\), chiều bất đẳng thức quay về như cũ và cặp \((b, c)\) trở lại đúng thứ tự ban đầu.&lt;/p&gt;

&lt;h3 id=&quot;4-minh-họa-hình-học&quot;&gt;4. Minh họa hình học&lt;/h3&gt;

&lt;p&gt;Có thể hình dung phép lấy đối ngẫu tương tự như phép lấy đối xứng qua một mặt phẳng: áp dụng một lần cho ảnh đối xứng, áp dụng lần thứ hai quay về đúng điểm xuất phát. Trong toán học, phép biến đổi mà áp dụng hai lần trở về chính nó được gọi là một &lt;strong&gt;phép đối hợp (involution)&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ví-dụ-chi-tiết-bài-toán-sản-xuất&quot;&gt;Ví dụ chi tiết: Bài toán sản xuất&lt;/h2&gt;

&lt;h3 id=&quot;bài-toán-gốc-p&quot;&gt;Bài toán gốc (P)&lt;/h3&gt;

&lt;p&gt;Một công ty sản xuất hai sản phẩm A và B với lợi nhuận lần lượt là 3 triệu và 5 triệu cho mỗi đơn vị, dưới hai ràng buộc nguồn lực:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nguyên liệu: sản phẩm A cần 2 kg/đơn vị, sản phẩm B cần 1 kg/đơn vị; tổng nguồn cung là 8 kg.&lt;/li&gt;
  &lt;li&gt;Thời gian: sản phẩm A cần 1 giờ/đơn vị, sản phẩm B cần 2 giờ/đơn vị; tổng quỹ thời gian là 10 giờ.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bài toán tìm số lượng sản phẩm \(x_1, x_2\) để cực đại hóa lợi nhuận:&lt;/p&gt;

\[\begin{align}
\text{maximize} \quad &amp;amp; 3x_1 + 5x_2 \\
\text{subject to} \quad &amp;amp; 2x_1 + x_2 \leq 8, \\
&amp;amp; x_1 + 2x_2 \leq 10, \\
&amp;amp; x_1, x_2 \geq 0.
\end{align}\]

&lt;p&gt;Chuyển về dạng chuẩn cực tiểu hóa:&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; -3x_1 - 5x_2 \\
\text{subject to} \quad &amp;amp; -2x_1 - x_2 \geq -8, \\
&amp;amp; -x_1 - 2x_2 \geq -10, \\
&amp;amp; x_1, x_2 \geq 0.
\end{align}\]

&lt;h3 id=&quot;bài-toán-đối-ngẫu-d&quot;&gt;Bài toán đối ngẫu (D)&lt;/h3&gt;

&lt;p&gt;Về mặt kinh tế, bài toán đối ngẫu tìm &lt;strong&gt;giá bóng (shadow price)&lt;/strong&gt; của từng nguồn lực sao cho tổng giá trị nguồn lực là nhỏ nhất, đồng thời tổng giá trị nguồn lực tiêu hao cho mỗi đơn vị sản phẩm không thấp hơn lợi nhuận của sản phẩm đó. Vì (P) là bài toán cực đại hóa với ràng buộc \(\leq\), bài toán đối ngẫu (D) là bài toán cực tiểu hóa với ràng buộc \(\geq\):&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; 8y_1 + 10y_2 \\
\text{subject to} \quad &amp;amp; 2y_1 + y_2 \geq 3, \\
&amp;amp; y_1 + 2y_2 \geq 5, \\
&amp;amp; y_1, y_2 \geq 0.
\end{align}\]

&lt;h3 id=&quot;đối-ngẫu-của-bài-toán-đối-ngẫu-dd&quot;&gt;Đối ngẫu của bài toán đối ngẫu (DD)&lt;/h3&gt;

&lt;p&gt;Bài toán (D) đã ở dạng chuẩn (cực tiểu hóa, ràng buộc \(\geq\), biến không âm) với vector mục tiêu \((8, 10)\), ma trận ràng buộc \(\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}\) và vế phải \((3, 5)\). Áp dụng quy tắc lấy đối ngẫu với biến mới \(z_1, z_2\), ta thu được:&lt;/p&gt;

\[\begin{align}
\text{maximize} \quad &amp;amp; 3z_1 + 5z_2 \\
\text{subject to} \quad &amp;amp; 2z_1 + z_2 \leq 8, \\
&amp;amp; z_1 + 2z_2 \leq 10, \\
&amp;amp; z_1, z_2 \geq 0.
\end{align}\]

&lt;p&gt;Kết quả trùng khớp hoàn toàn với bài toán gốc (P).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kiểm tra bằng số:&lt;/strong&gt; Bài toán (P) đạt tối ưu tại \((x_1, x_2) = (2, 4)\) với lợi nhuận \(3 \cdot 2 + 5 \cdot 4 = 26\). Bài toán (D) đạt tối ưu tại \((y_1, y_2) = (\tfrac{1}{3}, \tfrac{7}{3})\) với giá trị mục tiêu \(8 \cdot \tfrac{1}{3} + 10 \cdot \tfrac{7}{3} = 26\). Hai giá trị bằng nhau, phù hợp với tính đối ngẫu mạnh.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mở-rộng-tối-ưu-lồi-tổng-quát&quot;&gt;Mở rộng: Tối ưu lồi tổng quát&lt;/h2&gt;

&lt;p&gt;Tính chất đối ngẫu kép luôn đúng đối với quy hoạch tuyến tính. Tuy nhiên, trong tối ưu lồi tổng quát, tính chất này chỉ đúng khi thỏa mãn thêm các điều kiện nhất định:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bài toán gốc là lồi (và đóng).&lt;/li&gt;
  &lt;li&gt;Thỏa mãn điều kiện Slater (hoặc một điều kiện chuẩn hóa ràng buộc tương đương).&lt;/li&gt;
  &lt;li&gt;Tính đối ngẫu mạnh được bảo đảm.&lt;/li&gt;
  &lt;li&gt;Tính chất này nói chung &lt;strong&gt;không đúng&lt;/strong&gt; cho các bài toán không lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Để tìm hiểu chi tiết hơn, xem &lt;strong&gt;Chương 11, Bài 11-07&lt;/strong&gt;: “Dual của Dual trong Tối Ưu Convex Tổng Quát”, trong đó trình bày các điều kiện cần thiết, so sánh giữa LP và tối ưu lồi tổng quát, ví dụ khi đối ngẫu kép không quay về bài toán gốc và ứng dụng trong thiết kế thuật toán.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004).&lt;/strong&gt; &lt;em&gt;Convex Optimization.&lt;/em&gt; Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 5: Duality (đặc biệt Section 5.2 về LP duality)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bertsimas, D., &amp;amp; Tsitsiklis, J. N. (1997).&lt;/strong&gt; &lt;em&gt;Introduction to Linear Optimization.&lt;/em&gt; Athena Scientific.
    &lt;ul&gt;
      &lt;li&gt;Chapter 4: Duality Theory&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov, Y. (2018).&lt;/strong&gt; &lt;em&gt;Lectures on Convex Optimization.&lt;/em&gt; Springer.
    &lt;ul&gt;
      &lt;li&gt;Chapter 3: Duality in Convex Optimization&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dantzig, G. B. (1963).&lt;/strong&gt; &lt;em&gt;Linear Programming and Extensions.&lt;/em&gt; Princeton University Press.
    &lt;ul&gt;
      &lt;li&gt;Foundational work on LP duality&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>10-05 Trò chơi ma trận</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_05_Matrix_Games/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_05_Matrix_Games</id>
   <content type="html">&lt;p&gt;Trong trò chơi oẳn tù tì hay một ván bài poker đối kháng, nếu bạn luôn trung thành với một nước đi cố định (chiến lược thuần túy), đối thủ sẽ lập tức bắt bài và khai thác triệt để. Cách duy nhất để trở nên “bất khả xâm phạm” là tung xúc xắc chọn nước đi theo một phân phối xác suất khéo léo — gọi là &lt;strong&gt;chiến lược hỗn hợp (mixed strategy)&lt;/strong&gt;. Năm 1928, rất lâu trước khi quy hoạch tuyến tính ra đời, John von Neumann đã chứng minh một định lý chấn động: trong mọi trò chơi tổng bằng không hai người, &lt;strong&gt;mức lỗ tối đa nhỏ nhất mà người đi trước phải chịu&lt;/strong&gt; luôn bằng chính xác &lt;strong&gt;mức thưởng tối thiểu lớn nhất mà người đi sau có thể đảm bảo&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Hai mươi năm sau, chính von Neumann và Dantzig nhận ra một bí mật tuyệt đẹp mà bài học này trình bày: bài toán tìm chiến lược hỗn hợp tối ưu cho hai người chơi J và R không phải hai bài toán độc lập, mà chính là &lt;strong&gt;một cặp bài toán quy hoạch tuyến tính gốc – đối ngẫu&lt;/strong&gt;! Định lý Minimax lừng danh của lý thuyết trò chơi hóa ra chỉ là một hệ quả trực tiếp của tính đối ngẫu mạnh trong LP!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-trò-chơi-ma-trận-và-định-lý-minimax&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của trò chơi ma trận và định lý Minimax&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ma trận chi trả \(P\) và chi trả kỳ vọng \(x^T P y\):&lt;/strong&gt; Người chơi cột J chọn phân phối \(x \in \Delta_m\) (muốn &lt;em&gt;cực tiểu hóa&lt;/em&gt; số tiền phải trả), người chơi hàng R chọn phân phối \(y \in \Delta_n\) (muốn &lt;em&gt;cực đại hóa&lt;/em&gt; số tiền nhận được). Chi trả kỳ vọng song tuyến tính là \(x^T P y = \sum_{i,j} x_i P_{ij} y_j\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến bài toán Minimax thành LP bằng biến phụ \(t\):&lt;/strong&gt; Khi J công bố trước chiến lược \(x\), R sẽ chọn nước đi thuần túy làm J mất nhiều tiền nhất: \(\max_{j} (P^T x)_j\). Để cực tiểu hóa hàm max không trơn này, J đưa thêm biến vô hướng \(t\) và giải LP: \(\min_{x, t} t\) sao cho \(P^T x \le t \mathbf{1}, \; \mathbf{1}^T x = 1, \; x \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Góc nhìn đối lập (R công bố trước) = Chính xác bài toán đối ngẫu LP:&lt;/strong&gt; Khi R công bố trước \(y\), R giải \(\max_{y, s} s\) sao cho \(P y \ge s \mathbf{1}, \; \mathbf{1}^T y = 1, \; y \ge 0\). Kiểm tra đại số cho thấy đây chính là bài toán đối ngẫu của LP phía J!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý Minimax von Neumann và cân bằng Nash:&lt;/strong&gt; Nhờ đối ngẫu mạnh LP, \(\min_x \max_y x^T P y = \max_y \min_x x^T P y = v^*\) (giá trị trò chơi). Cặp \((x^*, y^*)\) tạo thành một cân bằng Nash: không ai có lợi nếu đơn phương đổi chiến lược.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-trò-chơi-ma-trận-2-times-2-từ-cả-hai-góc-nhìn&quot;&gt;Giải thích: Giải tay trò chơi ma trận \(2 \times 2\) từ cả hai góc nhìn&lt;/h3&gt;

&lt;p&gt;Xét ma trận chi trả (J trả cho R) kích thước \(2 \times 2\):
\(P = \begin{pmatrix} 3 &amp;amp; 0 \\ 1 &amp;amp; 2 \end{pmatrix}.\)
(Kiểm tra nhanh không có điểm yên ngựa thuần túy: min hàng là \(0, 1 \Rightarrow \max\min = 1$; max cột là\)3, 2 \Rightarrow \min\max = 2$; vì \(1 &amp;lt; 2\) nên cần chiến lược hỗn hợp!)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán gốc — J chọn \(x = (x_1, 1 - x_1)\) để tối thiểu hóa mức lỗ xấu nhất:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu R chọn cột 1, J trả: \(3x_1 + 1(1 - x_1) = 1 + 2x_1\).&lt;/li&gt;
      &lt;li&gt;Nếu R chọn cột 2, J trả: \(0x_1 + 2(1 - x_1) = 2 - 2x_1\).&lt;/li&gt;
      &lt;li&gt;Để cực tiểu hóa \(\max(1 + 2x_1, 2 - 2x_1)\), J cân bằng hai nhánh:
\(1 + 2x_1 = 2 - 2x_1 \implies 4x_1 = 1 \implies x_1^* = 0.25, \; x_2^* = 0.75.\)&lt;/li&gt;
      &lt;li&gt;Mức lỗ tối đa của J: \(t^* = 1 + 2(0.25) = 1.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán đối ngẫu — R chọn \(y = (y_1, 1 - y_1)\) để tối đa hóa mức thưởng đảm bảo:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu J chọn hàng 1, R nhận: \(3y_1 + 0(1 - y_1) = 3y_1\).&lt;/li&gt;
      &lt;li&gt;Nếu J chọn hàng 2, R nhận: \(1y_1 + 2(1 - y_1) = 2 - y_1\).&lt;/li&gt;
      &lt;li&gt;Để cực đại hóa \(\min(3y_1, 2 - y_1)\), R cân bằng hai nhánh:
\(3y_1 = 2 - y_1 \implies 4y_1 = 2 \implies y_1^* = 0.5, \; y_2^* = 0.5.\)&lt;/li&gt;
      &lt;li&gt;Mức thưởng đảm bảo của R: \(s^* = 3(0.5) = 1.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng định lý Minimax:&lt;/strong&gt; \(t^* = s^* = 1.5\)! Dù ai công bố chiến lược hỗn hợp trước, giá trị kỳ vọng của trò chơi vẫn khóa chặt tại \(1.5\).&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trong bài này, chúng ta xét bài toán chiến lược hỗn hợp (mixed strategy) trong trò chơi ma trận — một ví dụ tiêu biểu về cặp bài toán LP gốc và đối ngẫu trong lý thuyết trò chơi. Xét trò chơi gồm hai người chơi \(J\) và \(R\) cùng một ma trận chi trả \(P\).&lt;/p&gt;

&lt;h2 id=&quot;thiết-lập-trò-chơi&quot;&gt;Thiết lập trò chơi&lt;/h2&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter10/matrix_game.png&quot; alt=&quot;Thiết lập trò chơi&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Thiết lập trò chơi [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Phần tử \(P_{ij}\) của ma trận chi trả biểu thị số tiền mà \(J\) phải trả cho \(R\) khi \(J\) chọn chiến lược \(i\) (hàng) và \(R\) chọn chiến lược \(j\) (cột). Nếu \(P_{ij} &amp;gt; 0\), \(J\) trả cho \(R\) một khoản bằng \(P_{ij}\); nếu \(P_{ij} &amp;lt; 0\), \(R\) trả cho \(J\) một khoản bằng $$&lt;/td&gt;
      &lt;td&gt;P_{ij}&lt;/td&gt;
      &lt;td&gt;$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Đây là trò chơi tổng bằng không (zero-sum): gọi phần thưởng của \(R\) là \(r_R\) và của \(J\) là \(r_J\), thì ở mọi ván đấu ta luôn có \(r_R = -r_J\), tức tổng phần thưởng của hai người chơi bằng \(0\).&lt;/p&gt;

&lt;p&gt;Giả sử cả hai người chơi đều sử dụng chiến lược hỗn hợp, nghĩa là lựa chọn của mỗi người được rút ngẫu nhiên theo một phân phối xác suất:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x : P(\text{J chooses i}) = x_{i}, \qquad i=1,...m\\\\
y : P(\text{R chooses j}) = y_{j}, \qquad j=1,...n.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Khi biết phân phối xác suất của đối phương, mỗi người chơi có thể tính được chi trả kỳ vọng (expected payout):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\sum_{i=1}^{m}\sum_{j=1}^{n}x_{i}y_{j}P_{ij} = x^{T}Py.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì \(P_{ij}\) là khoản tiền \(J\) trả cho \(R\), nên \(J\) muốn cực tiểu hóa chi trả kỳ vọng, còn \(R\) muốn cực đại hóa chi trả kỳ vọng.&lt;/p&gt;

&lt;p&gt;Bây giờ, ta xét bài toán từ góc nhìn của từng người chơi với giả định cả hai đều hành động tối ưu. Ta sẽ lập bài toán tối ưu cho từng phía, rồi chỉ ra rằng theo định lý minimax của von Neumann, hai giá trị tối ưu thu được bằng nhau.&lt;/p&gt;

&lt;h2 id=&quot;cực-tiểu-hóa-chi-trả-kỳ-vọng-góc-nhìn-của-j&quot;&gt;Cực tiểu hóa chi trả kỳ vọng: góc nhìn của J&lt;/h2&gt;

&lt;p&gt;Trước hết, giả sử \(R\) biết trước chiến lược \(x\) của \(J\). Khi đó \(R\) sẽ chọn \(y\) để cực đại hóa chi trả kỳ vọng \(x^T P y\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\max\{x^{T}Py : y\geq0, 1^{T}y = 1\} = \max_{j=1,...,n}(P^{T}x)_{j}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Theo biểu thức trên, chiến lược tối ưu của \(R\) là chọn chỉ số \(j\) làm cực đại \((P^T x)_j\) (tức đặt \(y_j = 1\) tại chỉ số đó và bằng \(0\) ở các chỉ số còn lại).&lt;/p&gt;

&lt;p&gt;Biết rằng \(R\) sẽ phản ứng tối ưu như vậy, \(J\) chọn phân phối \(x\) nhằm giải bài toán:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \min_{x}
&amp;amp; &amp;amp;\max_{j=1,...,n} (P^{T}x)_{j}\\\\
&amp;amp; \text{thỏa mãn}
&amp;amp; &amp;amp; x\geq 0, 1^{T}x =1.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì cực đại theo từng điểm của các hàm tuyến tính là một hàm lồi, đây là một bài toán tối ưu lồi. Ta gọi giá trị tối ưu của bài toán này là \(f_1^*\). Lưu ý rằng giả định mọi người chơi đều hành động tối ưu là giả định cơ bản của mô hình trò chơi hai người tổng bằng không.&lt;/p&gt;

&lt;h2 id=&quot;cực-đại-hóa-chi-trả-kỳ-vọng-góc-nhìn-của-r&quot;&gt;Cực đại hóa chi trả kỳ vọng: góc nhìn của R&lt;/h2&gt;

&lt;p&gt;Ngược lại, giả sử \(J\) biết trước chiến lược \(y\) của \(R\). Khi đó \(J\) sẽ chọn \(x\) để cực tiểu hóa chi trả kỳ vọng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min \{x^{T}Py : x\geq0, 1^{T}x = 1\} = \min_{i=1,...,m}(Py)_{i}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Biết rằng \(J\) sẽ phản ứng tối ưu như vậy, \(R\) chọn phân phối \(y\) để giải bài toán:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \max_{y}  
&amp;amp; &amp;amp; \min_{i=1,...,m} (Py)_{i}\\\\
&amp;amp;\text{thỏa mãn}
&amp;amp; &amp;amp;y\geq 0, 1^{T}y =1.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Gọi giá trị tối ưu của bài toán này là \(f_2^*\). Vì ở góc nhìn thứ nhất \(R\) có lợi thế biết trước chiến lược của \(J\), ta dễ thấy \(f_1^* \geq f_2^*\).&lt;/p&gt;

&lt;h2 id=&quot;định-lý-minimax-của-von-neumann&quot;&gt;Định lý minimax của von Neumann&lt;/h2&gt;

&lt;p&gt;Theo định lý minimax của von Neumann, dấu bằng thực sự xảy ra: \(f_1^* = f_2^*\). Định lý được phát biểu như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{Cho } X\subset \mathbb{R}^{m} \text{ và }Y\subset \mathbb{R}^{n} \text{ là các tập lồi compact. }\\\\
&amp;amp;\text{Nếu } f:X\times Y\rightarrow \mathbb{R} \text{ là hàm liên tục lồi-lõm, tức là}\\\\
&amp;amp;\qquad f(\cdot, y): X\rightarrow\mathbb{R} \text{ lồi với } y \text{ cố định, và}\\\\
&amp;amp;\qquad f(x, \cdot): Y\rightarrow\mathbb{R} \text{ lõm với } x \text{ cố định.}\\\\
&amp;amp;\text{Khi đó ta có} \\\\ 
&amp;amp;\min_{x\in X} \max_{y\in Y} f(x,y) = \max_{y\in Y} \min_{x\in X} f(x,y).\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Phần chứng minh định lý này được lược bỏ.&lt;/p&gt;

&lt;h2 id=&quot;chứng-minh-hai-góc-nhìn-tạo-thành-cặp-bài-toán-gốc--đối-ngẫu&quot;&gt;Chứng minh hai góc nhìn tạo thành cặp bài toán gốc – đối ngẫu&lt;/h2&gt;

&lt;p&gt;Ta sẽ chứng minh hai bài toán trên là cặp bài toán LP gốc – đối ngẫu của nhau; khi kết hợp với định lý minimax của von Neumann (\(f_1^* = f_2^*\)), điều này cho thấy tính đối ngẫu mạnh được thỏa mãn.&lt;/p&gt;

&lt;p&gt;Trước hết, viết lại bài toán từ góc nhìn của \(J\) dưới dạng LP bằng cách đưa thêm biến phụ \(t\) biểu thị giá trị lớn nhất của các thành phần trong \(P^T x\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \min_{x} \max_{j=1,...,n} 
&amp;amp; &amp;amp;(P^{T}x)_{j}\\\\
&amp;amp;\text{thỏa mãn } 
&amp;amp; &amp;amp;x\geq 0, 1^{T}x = 1\\\\
\end{align}\]

\[\begin{align}
\Leftrightarrow{} \\\\
&amp;amp; \min_{x,t}
&amp;amp; &amp;amp; t \\\\
&amp;amp;\text{thỏa mãn } 
&amp;amp; &amp;amp;x\geq0, 1^{T}x = 1, P^{T}x \preceq t. \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Áp dụng phương pháp Lagrangian đã học ở bài 10-04 để lập hàm Lagrange và hàm đối ngẫu \(g(u, v, y)\) (với \(u \geq 0, y \geq 0\)):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;L(x, t, u, v, y) &amp;amp;&amp;amp;= t-u^{T}x+v(1-1^{T}x)+y^{T}(P^{T}x-t1)\\\\
&amp;amp;g(u, v, y) &amp;amp;&amp;amp;= \min_{x,t} \quad L(x, t, u, v, y)\\\\
&amp;amp;&amp;amp;&amp;amp;= \begin{cases} v \qquad &amp;amp;\text{if } 1-1^{T}y = 0, Py-u-v1=0\\\\
-\infty \qquad &amp;amp;\text{trường hợp khác.} \end{cases}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Khử biến bù \(u \geq 0\) từ điều kiện \(Py - u - v\mathbf{1} = 0\) (tức \(Py \geq v\mathbf{1}\)), ta thu được bài toán đối ngẫu:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{y,v} \qquad \quad &amp;amp;&amp;amp; v\\\\
&amp;amp;\text{thỏa mãn }\quad &amp;amp;&amp;amp; y\geq0, 1^{T}y = 1\\\\
&amp;amp;&amp;amp;&amp;amp; Py\geq v.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Đây chính là dạng LP tương đương với bài toán từ góc nhìn của \(R\). Như vậy, hai góc nhìn của trò chơi ma trận tạo thành một cặp bài toán gốc – đối ngẫu và có cùng giá trị tối ưu (đối ngẫu mạnh).&lt;/p&gt;

&lt;p&gt;Tổng quát đối với quy hoạch tuyến tính (sẽ được trình bày kỹ hơn ở Chương 11), chỉ cần bài toán gốc hoặc bài toán đối ngẫu khả thi thì tính đối ngẫu mạnh luôn được bảo đảm.&lt;/p&gt;

&lt;h3 id=&quot;trò-chơi-ma-trận-minimax-và-đối-ngẫu-video&quot;&gt;Trò chơi ma trận: minimax và đối ngẫu (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/matrix-game_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;\(J\) cực tiểu hóa đường cao nhất, \(R\) cực đại hóa đường thấp nhất, và cả hai đạt cùng một giá trị: định lý minimax chính là đối ngẫu LP.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-trò-chơi-nhìn-từ-hai-phía&quot;&gt;Tự tay thử: trò chơi nhìn từ hai phía&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;mgame&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>10-04 Góc nhìn khác về tính đối ngẫu LP</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_04_Another_Perspective_on_LP_duality/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_04_Another_Perspective_on_LP_duality</id>
   <content type="html">&lt;p&gt;Ở các bài đầu chương, ta xây dựng bài toán đối ngẫu LP bằng một “mẹo đại số” rất khéo: nhân các ràng buộc với biến đối ngẫu rồi cộng vế theo vế để ghép thành hàm mục tiêu. Mẹo đó chạy rất trơn trên hàm tuyến tính, nhưng hãy thử đặt câu hỏi: &lt;em&gt;nếu sang Chương 11 hàm mục tiêu là \(x^4 + e^x\) và ràng buộc là hình cầu \(\|x\|_2^2 \le 1\) thì cộng tuyến tính sao nổi?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bài học này mở ra &lt;strong&gt;góc nhìn thứ hai — góc nhìn hàm Lagrangian&lt;/strong&gt; — chiếc cầu vàng nối thẳng Chương 10 sang toàn bộ lý thuyết đối ngẫu phi tuyến ở Chương 11 và điều kiện KKT ở Chương 12! Thay vì coi ràng buộc như bức tường cứng nhắc, ta chuyển chúng thành “khoản phạt mềm” cộng thẳng vào hàm mục tiêu \(L(x, u, v) = c^T x + u^T(Ax - b) + v^T(Gx - h)\), rồi cực tiểu hóa tự do theo \(x \in \mathbb{R}^n\). Phép cực tiểu hóa một hàm tuyến tính trên toàn không gian có tính chất cực kỳ sắc bén: nó chỉ hữu hạn khi độ dốc bằng \(0\) (sinh ra đúng ràng buộc đối ngẫu!), còn ngược lại thì tụt thẳng xuống \(-\infty\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-góc-nhìn-lagrangian-cho-lp&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của góc nhìn Lagrangian cho LP&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm Lagrangian và trò chơi phạt mềm:&lt;/strong&gt; Định nghĩa \(L(x, u, v) = c^T x + u^T(Ax - b) + v^T(Gx - h)\) với \(v \ge 0\). Với mọi điểm \(x\) khả thi (\(Ax = b\) và \(Gx \le h\)), ta luôn có \(u^T(Ax - b) = 0\) và \(v^T(Gx - h) \le 0\), nên \(L(x, u, v) \le c^T x\) — tức \(L\) luôn là một bản xấp xỉ nằm dưới hàm mục tiêu gốc trên miền khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng miền lấy cực tiểu (\(\min_{x \in C} \ge \min_{x \in \mathbb{R}^n}\)):&lt;/strong&gt; Bằng cách bỏ hoàn toàn ràng buộc \(x \in C\) và lấy cực tiểu hóa tự do \(g(u, v) = \min_{x \in \mathbb{R}^n} L(x, u, v)\), ta chắc chắn thu được một cận dưới \(g(u, v) \le p^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện hữu hạn của infimum tuyến tính (Đọc ra miền khả thi đối ngẫu):&lt;/strong&gt; Gom nhóm theo \(x\):
\(L(x, u, v) = (c + A^T u + G^T v)^T x - b^T u - h^T v.\)
Một hàm tuyến tính \(w^T x\) trên toàn \(\mathbb{R}^n\) có infimum bằng \(0\) nếu \(w = 0\), và bằng \(-\infty\) nếu \(w \ne 0\)! Chính điều kiện \(w = c + A^T u + G^T v = 0\) lập tức tạo ra ràng buộc của bài toán đối ngẫu LP!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-hàm-đối-ngẫu-gv--inf_x-lx-v-cho-một-lp-1-biến&quot;&gt;Giải thích: Tính tay hàm đối ngẫu \(g(v) = \inf_x L(x, v)\) cho một LP 1 biến&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa 1 biến:
\(\min_{x \in \mathbb{R}} \; 4x \quad \text{s.t.} \quad 2 - x \le 0 \; (\text{tức } x \ge 2).\)
(Hiển nhiên nghiệm gốc là \(x^* = 2\), \(p^* = 8\).)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập hàm Lagrangian với biến đối ngẫu \(v \ge 0\):&lt;/strong&gt;
\(L(x, v) = 4x + v(2 - x) = (4 - v)x + 2v.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa tự do theo \(x \in \mathbb{R}\) để tìm hàm đối ngẫu \(g(v)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu \(v \ne 4\) (ví dụ \(v = 2\)): \(L(x, 2) = 2x + 4\). Cho \(x \to -\infty\) thì \(L(x, 2) \to -\infty\)! Vậy \(g(v) = -\infty\) (cận dưới vô dụng).&lt;/li&gt;
      &lt;li&gt;Nếu \(v = 4\): hệ số của \(x\) triệt tiêu sạch (\(4 - 4 = 0\)), nên \(L(x, 4) = 0 \cdot x + 2(4) = 8\) với mọi \(x \in \mathbb{R}\)! Vậy \(g(4) = 8\).
Tóm lại:
\(g(v) = \begin{cases} 8 &amp;amp; \text{nếu } v = 4, \\ -\infty &amp;amp; \text{nếu } v \ne 4. \end{cases}\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực đại hóa \(g(v)\) theo \(v \ge 0\):&lt;/strong&gt;
Ta buộc phải đặt ràng buộc ẩn \(4 - v = 0\) (để tránh \(-\infty\)) và tối đa hóa \(2v\), cho nghiệm \(v^* = 4\) và \(d^* = 8 = p^*\)! Đây chính là cầu nối trực tiếp sang bài toán tổng quát của Chương 11.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trong cách tiếp cận ở các bài trước, để xây dựng đối ngẫu của một LP, ta nhân các ràng buộc của bài toán gốc với các biến đối ngẫu, lấy tổ hợp tuyến tính rồi biến đổi để tách riêng hàm mục tiêu gốc nhằm thu được một cận dưới. Phần số hạng còn lại (ký hiệu là \(\text{something}\) trong biểu thức dưới đây) đóng vai trò là cận dưới của bài toán gốc — tức hàm mục tiêu của bài toán đối ngẫu — còn các điều kiện phát sinh trong quá trình biến đổi trở thành ràng buộc của bài toán đối ngẫu.&lt;/p&gt;

&lt;p&gt;Tóm tắt lại quá trình này bằng công thức:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x)\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;Ax = b\\\\
&amp;amp; &amp;amp;&amp;amp;Gx \leq h\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;\text{for any }u,\, v\geq 0,\\\\
&amp;amp; &amp;amp;u^{T}(Ax-b) = 0\\\\
&amp;amp;{+} &amp;amp;v^{T}(Gx-h)\leq 0\\\\
&amp;amp;{=} &amp;amp;u^{T}(Ax-b) + v^{T}(Gx-h)\leq 0\\\\
&amp;amp;{\approx} &amp;amp;f(x)+\text{something}. \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tuy nhiên, với các bài toán tối ưu không phải là quy hoạch tuyến tính, nhìn chung ta không thể biểu diễn hàm mục tiêu dưới dạng tổ hợp tuyến tính của các ràng buộc.&lt;/p&gt;

&lt;p&gt;Trong bài này, chúng ta xét một góc nhìn tổng quát hơn về tính đối ngẫu, áp dụng được cho mọi bài toán tối ưu (cả lồi lẫn không lồi): phương pháp &lt;strong&gt;Lagrangian&lt;/strong&gt;. Ta sẽ dùng cách tiếp cận này để xây dựng lại đối ngẫu của LP, trước khi nghiên cứu sâu hơn trong Chương 11.&lt;/p&gt;

&lt;p&gt;Từ tổ hợp tuyến tính của các ràng buộc trong bài toán LP gốc, với mọi \(x\) khả thi và mọi \(u\), \(v \geq 0\), ta có bất đẳng thức:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
c^{T}x\geq c^{T}x+\overbrace{u^{T} \underbrace{(Ax-b)} _ {=0}+\underbrace{v^{T}} _ {\geq 0} \underbrace{(Gx-h)} _ {\leq 0}} ^ {\leq 0} := L(x,u,v).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do \(Ax - b = 0\), \(Gx - h \leq 0\) và \(v \geq 0\), vế phải luôn nhỏ hơn hoặc bằng vế trái. Ta định nghĩa vế phải là hàm \(L(x, u, v)\) theo các biến \(x, u, v\). Gọi \(C\) là tập khả thi của LP gốc, ta suy ra chuỗi bất đẳng thức:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
C =  \{ x: Ax=b, Gx\leq h \},
\end{align}\)
\(\begin{align}
f^{*}=\min_{x\in C} f(x) \geq \min_{x\in C}L(x,u,v)\geq \min_{x}L(x,u,v):=g(u,v).\\\\
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, với mọi \(u\) và \(v \geq 0\), giá trị \(g(u, v)\) luôn là một cận dưới của giá trị tối ưu gốc \(f^{*}\). Hãy tính tường minh hàm \(g(u, v)\) đối với LP:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
g(u,v) = min_{x} c^{T}x+u^{T}(Ax-b) + v^{T}(Gx-h) \\\\
= \min_{x} (c+A^{T}u+G^{T}v)^{T}x - b^{T}u-h^{T}v \\\\
\begin{cases}= -b^{T}u-h^{T}v \qquad &amp;amp;\text{if }\ c = -A^{T}u-G^{T}v \\\\
-\infty \qquad &amp;amp;\text{otherwise}.
\end{cases}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ biểu thức trên, nếu \(c + A^{T}u + G^{T}v \neq 0\) thì hàm tuyến tính theo \(x\) không bị chặn dưới, nên giá trị cực tiểu bằng \(-\infty\). Để tìm cận dưới chặt nhất cho \(f^{*}\), ta cực đại hóa \(g(u, v)\) trên miền \(v \geq 0\). Khi đó, ta buộc phải có \(c = -A^{T}u - G^{T}v\) và hàm mục tiêu trở thành \(-b^{T}u - h^{T}v\) — trùng khớp hoàn toàn với bài toán LP đối ngẫu thu được theo cách tiếp cận đầu tiên:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f^{*} \geq g(u,v), \qquad \text{provided } v \geq 0\\\\
\text{find the biggest lowerbound  } g(u,v)\\\\
\max_{u,v} g(u,v)\\\\
\text{s.t. }v \geq 0. 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ưu điểm của cách tiếp cận này là nó có thể mở rộng trực tiếp cho các bài toán tối ưu tổng quát ngoài LP.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>10-03 Luồng cực đại và lát cắt cực tiểu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_03_Max_flow_and_min_cut/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_03_Max_flow_and_min_cut</id>
   <content type="html">&lt;p&gt;Năm 1956, hai nhà toán học Lester Ford và Delbert Fulkerson chứng minh một trong những định lý đẹp nhất của toán rời rạc: trong bất kỳ mạng đường ống nào nối từ nguồn \(s\) đến đích \(t\), &lt;strong&gt;lượng nước tối đa chảy qua được mạng (max flow)&lt;/strong&gt; luôn bằng chính xác &lt;strong&gt;tổng sức chứa nhỏ nhất của một lát cắt chia đôi mạng ngăn cách \(s\) khỏi \(t\) (min cut)&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Ở môn Cấu trúc dữ liệu &amp;amp; Giải thuật, người ta thường chứng minh định lý này bằng thuật toán đường tăng luồng (augmenting paths). Nhưng góc nhìn của Chương 10 còn ngoạn mục hơn thế: khi viết bài toán luồng cực đại dưới dạng một quy hoạch tuyến tính rồi bật “cỗ máy lấy đối ngẫu LP” lên một cách hoàn toàn cơ học, &lt;strong&gt;bài toán lát cắt cực tiểu tự động hiện ra ngay trước mắt như bản sao đối ngẫu của luồng cực đại!&lt;/strong&gt; Sự đồng nhất giữa hai bài toán tưởng chừng thuộc hai nhánh khác nhau của lý thuyết đồ thị hóa ra chỉ là một hệ quả thanh lịch của đối ngẫu mạnh LP.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-nối-lý-thuyết-đồ-thị-với-đối-ngẫu-lp&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột nối lý thuyết đồ thị với đối ngẫu LP&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình LP của bài toán luồng cực đại (Max Flow):&lt;/strong&gt; Biến gốc là lưu lượng \(f_{ij}\) trên mỗi cung \((i, j) \in E\), bị chặn sức chứa \(0 \le f_{ij} \le c_{ij}\) và thỏa định luật bảo toàn luồng tại mọi đỉnh trung gian (tổng vào = tổng ra). Mục tiêu là cực đại hóa tổng lưu lượng rời nguồn \(s\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa biến đối ngẫu — Thế năng đỉnh \(b_i\) và giá nghẽn cung \(a_{ij}\):&lt;/strong&gt; Khi lấy đối ngẫu LP, ràng buộc bảo toàn luồng ở mỗi đỉnh \(i\) sinh ra một biến đối ngẫu \(b_i\) (như “nhãn” phân chia đỉnh vào phía nguồn \(S\) hay phía đích \(T\)), còn ràng buộc sức chứa cung \(f_{ij} \le c_{ij}\) sinh ra biến \(a_{ij} \ge 0\) (bằng \(1\) nếu cung \((i, j)\) bị cắt ngang từ \(S\) sang \(T\), bằng \(0\) nếu không).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính toàn nguyên (Total Unimodularity):&lt;/strong&gt; Một phép màu đại số của ma trận liên thuộc đỉnh–cung: dù ta giải bản nới lỏng LP liên tục (\(a_{ij}, b_i \in \mathbb{R}\)), mọi đỉnh cực biên của đa diện đối ngẫu đều có tọa độ &lt;strong&gt;nguyên \(0\) hoặc \(1\)&lt;/strong&gt;! Vì thế giá trị tối ưu LP liên tục trùng khít với lát cắt cực tiểu rời rạc!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu yếu = Lát cắt luôn chặn trên luồng:&lt;/strong&gt; Bất kỳ lát cắt nào cũng chặn trên mọi luồng hợp lệ (\(\text{flow} \le \text{cut}\)); đối ngẫu mạnh khẳng định dấu bằng luôn đạt được (\(\max\text{flow} = \min\text{cut}\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-max-flow-và-min-cut-trên-mạng-4-đỉnh&quot;&gt;Giải thích: Tính tay Max Flow và Min Cut trên mạng 4 đỉnh&lt;/h3&gt;

&lt;p&gt;Xét đồ thị có hướng gồm 4 đỉnh \(\{s, a, b, t\}\) và 5 cung với sức chứa:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(s \to a\) (cap \(3\)), \(s \to b\) (cap \(2\)),&lt;/li&gt;
  &lt;li&gt;\(a \to b\) (cap \(1\)),&lt;/li&gt;
  &lt;li&gt;\(a \to t\) (cap \(2\)), \(b \to t\) (cap \(3\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tìm một luồng khả thi (Bài toán gốc — Max Flow):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đẩy \(2\) đơn vị theo đường \(s \to a \to t\).&lt;/li&gt;
      &lt;li&gt;Đẩy \(1\) đơn vị theo đường \(s \to a \to b \to t\).&lt;/li&gt;
      &lt;li&gt;Đẩy \(2\) đơn vị theo đường \(s \to b \to t\).
Kiểm tra sức chứa từng cung: \(f_{sa} = 3 \le 3\), \(f_{sb} = 2 \le 2\), \(f_{ab} = 1 \le 1\), \(f_{at} = 2 \le 2\), \(f_{bt} = 3 \le 3\) (tất cả đều bão hòa!). Bảo toàn luồng tại \(a\) (vào \(3\), ra \(2+1=3\)) và tại \(b\) (vào \(2+1=3\), ra \(3\)). Tổng luồng rời \(s\) là \(3 + 2 = 5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm lát cắt (Bài toán đối ngẫu — Min Cut):&lt;/strong&gt;
Gán nhãn đối ngẫu: \(b_s = 1\) (phía nguồn \(S = \{s\}\)), và \(b_a = b_b = b_t = 0\) (phía đích \(T = \{a, b, t\}\)).
Các cung đi từ \(S\) sang \(T\) là \((s, a)\) và \((s, b)\) (nên \(a_{sa} = 1, a_{sb} = 1\), các cung khác \(a_{ij} = 0\)).
Tổng sức chứa lát cắt: \(c_{sa} + c_{sb} = 3 + 2 = 5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chốt đối ngẫu mạnh:&lt;/strong&gt; Vì \(\text{Flow} = 5 \le \text{Max Flow} \le \text{Min Cut} \le 5\), ta chứng minh ngay lập tức luồng \(5\) là cực đại và lát cắt \(\{s\} \mid \{a, b, t\}\) là cực tiểu!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Để minh họa tính đối ngẫu trong quy hoạch tuyến tính, bài học này sẽ phân tích cặp bài toán luồng cực đại (max flow) và lát cắt cực tiểu (min cut).&lt;/p&gt;

&lt;h2 id=&quot;đồ-thị-có-hướng-và-các-điều-kiện-của-luồng&quot;&gt;Đồ thị có hướng và các điều kiện của luồng&lt;/h2&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter10/max_flow.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Đồ thị có hướng[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Xét một đồ thị có hướng \(G = (V, E)\) như Hình 1. Trên mỗi cạnh có hướng \((i, j) \in E\) nối từ đỉnh \(i\) đến đỉnh \(j\), ta ký hiệu \(f_{ij}\) là lượng luồng chảy qua cạnh đó và \(c_{ij}\) là dung lượng (lượng luồng tối đa mà cạnh có thể tải).&lt;/p&gt;

&lt;p&gt;Mô hình đồ thị này biểu diễn sự lưu chuyển từ một đỉnh nguồn \(s\) đến một đỉnh đích \(t\), thường gặp trong các bài toán thực tế như quy hoạch thoát nước đô thị, truyền tải điện năng hay vận chuyển hàng hóa.&lt;/p&gt;

&lt;p&gt;Một luồng hợp lệ phải thỏa mãn ba điều kiện sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Luồng trên mỗi cạnh không âm: \(f_{ij} \geq 0,\, (i,j)\in E\).&lt;/li&gt;
  &lt;li&gt;Luồng trên mỗi cạnh không vượt quá dung lượng của cạnh đó: \(f_{ij} \leq c_{ij}, \, (i,j)\in E\).&lt;/li&gt;
  &lt;li&gt;Bảo toàn luồng tại các đỉnh trung gian: với mọi đỉnh \(k\) khác nguồn \(s\) và đích \(t\), tổng luồng đi vào \(k\) bằng tổng luồng đi ra khỏi \(k\): \(\sum_{(i,k)\in E}f_{ik} = \sum_{(k,j)\in E}f_{kj}, \, k\in V\backslash\{s,t\}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mối-quan-hệ-giữa-bài-toán-luồng-cực-đại-và-lát-cắt-cực-tiểu-1&quot;&gt;Mối quan hệ giữa bài toán luồng cực đại và lát cắt cực tiểu (1)&lt;/h2&gt;

&lt;p&gt;Trên đồ thị có hướng đã định nghĩa, ta xét hai bài toán kinh điển là bài toán luồng cực đại và bài toán lát cắt cực tiểu.&lt;/p&gt;

&lt;p&gt;Tóm tắt kết quả chính trước khi đi vào chứng minh: bài toán luồng cực đại là một bài toán quy hoạch tuyến tính (LP), còn bài toán lát cắt cực tiểu là một bài toán quy hoạch nguyên (integer program). Khi lập bài toán đối ngẫu của luồng cực đại, ta thu được đúng bài toán nới lỏng tuyến tính (LP relaxation) của lát cắt cực tiểu:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{Giá trị luồng cực đại} &amp;amp;\leq \text{LP đối ngẫu của luồng cực đại}\\
&amp;amp;= \text{Giá trị tối ưu của lát cắt cực tiểu nới lỏng LP}\\
&amp;amp;\leq \text{Dung lượng của lát cắt cực tiểu}\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong bài này, chúng ta sẽ chứng minh chuỗi bất đẳng thức trên bằng cách lập đối ngẫu và thực hiện quá trình ngược của phép nới lỏng (tức là bổ sung ràng buộc nguyên vào LP để thu được bài toán quy hoạch nguyên). Dù không chứng minh chi tiết tại đây, trên thực tế cả ba giá trị trong chuỗi trên đều bằng nhau. Kết quả đó chính là &lt;strong&gt;định lý luồng cực đại – lát cắt cực tiểu&lt;/strong&gt;: giá trị luồng cực đại trong một mạng bằng dung lượng của lát cắt cực tiểu.&lt;/p&gt;

&lt;p&gt;Tổng quát hơn, khi giá trị tối ưu của bài toán gốc và bài toán đối ngẫu bằng nhau, ta nói &lt;strong&gt;tính đối ngẫu mạnh (strong duality)&lt;/strong&gt; thỏa mãn. Đối với quy hoạch tuyến tính, tính đối ngẫu mạnh luôn đúng ngoại trừ trường hợp cả bài toán gốc lẫn bài toán đối ngẫu đều vô nghiệm (không khả thi); nội dung này sẽ được phân tích kỹ hơn ở Chương 11.&lt;/p&gt;

&lt;p&gt;Trước hết, ta phát biểu chính xác hai bài toán, suy ra đối ngẫu của bài toán luồng cực đại, rồi chỉ ra cách thêm ràng buộc nguyên để đưa bài toán đối ngẫu về bài toán lát cắt cực tiểu.&lt;/p&gt;

&lt;h2 id=&quot;bài-toán-luồng-cực-đại&quot;&gt;Bài toán luồng cực đại&lt;/h2&gt;

&lt;p&gt;Bài toán luồng cực đại yêu cầu tìm tổng lượng luồng lớn nhất đi từ nguồn \(s\) đến đích \(t\) thỏa mãn ba điều kiện của luồng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{f\in {\mathbb{R}^{|E|}}} &amp;amp;&amp;amp;{\sum_{(s,j)\in E} f_{sj}}\\
&amp;amp;\text{với điều kiện} &amp;amp;&amp;amp;{f_{ij}\geq 0,\,f_{ij}\leq c_{i,j}\,\, \text{với mọi }(i, j)\in E}\\
&amp;amp;&amp;amp;&amp;amp;{\sum_{(i, k)\in E}f_{ik}=\sum_{(k,j)\in E}f_{kj}}\,\, \text{với mọi }k\in V \backslash \{s,t\}.\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;bài-toán-lát-cắt-cực-tiểu&quot;&gt;Bài toán lát cắt cực tiểu&lt;/h2&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter10/min_cut.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Ví dụ Cắt Đồ thị[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Bài toán lát cắt cực tiểu phân hoạch tập đỉnh của đồ thị thành hai tập hợp rời nhau (vùng tô đậm và vùng không tô đậm trong Hình 2): tập \(A\) chứa nguồn \(s\), tập \(B\) chứa đích \(t\), còn các đỉnh khác được xếp vào \(A\) hoặc \(B\). Tổng dung lượng của tất cả các cạnh có hướng đi từ \(A\) sang \(B\) được gọi là &lt;strong&gt;dung lượng của lát cắt&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Nói cách khác, một lát cắt là một cách phân hoạch tập đỉnh sao cho nguồn và đích nằm ở hai phía khác nhau, và bài toán lát cắt cực tiểu tìm lát cắt có dung lượng nhỏ nhất. Trong dạng phát biểu dưới đây, ta gán \(x_i = 1\) nếu \(i \in A\) và \(x_i = 0\) nếu \(i \in B\), với điều kiện cố định \(x_s = 1\) và \(x_t = 0\) (được ngầm hiểu trong công thức):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{b\in {\mathbb{R}^{|E|}},\, x \in {\mathbb{R}^{|V|}} } &amp;amp;&amp;amp;{\sum_{(i,j)\in E} b_{ij}c_{ij}}\\
&amp;amp;\text{với điều kiện} &amp;amp;&amp;amp;{b_{ij} \geq x_{i}-x_{j}}\\
&amp;amp;&amp;amp;&amp;amp;{b_{ij},\,x_{i},\,x_{j}\,\in \{ 0,1 \} }\\
&amp;amp;&amp;amp;&amp;amp;\text{với mọi }i, j.\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Về mặt trực quan, bài toán luồng cực đại tìm lưu lượng lớn nhất truyền được từ nguồn sang đích, còn bài toán lát cắt cực tiểu tìm “nút thắt cổ chai” có tổng dung lượng nhỏ nhất ngăn cách nguồn với đích, nên hai bài toán này liên hệ chặt chẽ với nhau.&lt;/p&gt;

&lt;h2 id=&quot;bài-toán-đối-ngẫu-của-luồng-cực-đại&quot;&gt;Bài toán đối ngẫu của luồng cực đại&lt;/h2&gt;

&lt;p&gt;Bây giờ ta xây dựng bài toán đối ngẫu cho bài toán luồng cực đại.&lt;/p&gt;

&lt;p&gt;Đặt các biến đối ngẫu lần lượt là \(a_{ij} \geq 0\) (cho ràng buộc \(f_{ij} \geq 0\)), \(b_{ij} \geq 0\) (cho ràng buộc \(f_{ij} \leq c_{ij}\)) và \(x_k \in \mathbb{R}\) (cho ràng buộc bảo toàn luồng tại đỉnh \(k \in V \setminus \{s, t\}\)). Vì bài toán gốc là bài toán cực đại hóa, bài toán đối ngẫu sẽ đi tìm cận trên nhỏ nhất cho hàm mục tiêu gốc. Ta lập tổ hợp tuyến tính của các ràng buộc như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\sum_{(i,j)\in E} {\Big(-a_{ij}f_{ij}+b_{ij}(f_{ij}-c_{ij})\Big)} + \sum_{k \in V\backslash \{s,t\}} x_{k}\Big( \sum_{(i,k)\in E} f_{ik} - \sum_{(k,j)\in E } f_{kj} \Big)\leq 0\\
\text{với bất kỳ }a_{ij}, b_{ij} \geq 0, (i, j)\in E, \text{ và } x_{k}, k\in V \backslash \{s,t\}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Chuyển các số hạng chứa biến \(f\) sang vế trái và phần hằng số sang vế phải, ta được:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\sum_{(i,j)\in E}{\Big((b_{ij}-a_{ij})f_{ij}\Big)}+\sum_{k\in V\backslash \{s,t\}}{x_{k}\Big(\sum_{(i,k)\in E}{f_{ik}}-\sum_{(k,j)\in E}{f_{kj}}\Big)} \leq \sum_{(i,j)\in E}b_{ij}c_{ij}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Để vế trái trùng khớp với hàm mục tiêu của LP gốc là \(\sum_{(s,j)\in E} f_{sj}\), hệ số của \(f_{ij}\) ở vế trái phải bằng \(1\) khi \(i = s\) và bằng \(0\) với mọi cạnh khác. Các điều kiện hệ số này chính là ràng buộc của bài toán đối ngẫu.&lt;/p&gt;

&lt;p&gt;Vì chỉ số \(k\) trong tổng thứ hai không bao gồm \(s\) và \(t\), ta xét hệ số của \(f_{ij}\) theo ba trường hợp:&lt;/p&gt;

&lt;h3 id=&quot;trường-hợp-1-i--s-j-neq-t&quot;&gt;Trường hợp 1. \(i = s, j \neq t.\)&lt;/h3&gt;

&lt;p&gt;Trong tổng theo \(x_k\), mọi số hạng với \(k \neq j\) đều triệt tiêu (do điều kiện bảo toàn luồng), chỉ còn lại phần tử ứng với \(k = j\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;=\sum_{(s,j)\in E}{\Big((b_{sj}-a_{sj})f_{sj}\Big)}+x_{j}\sum_{(s,j)\in E}{f_{sj}}+\sum_{k\in V\backslash \{s,t,j\}}{x_{k}\Big(\underbrace{\sum_{(s,k)\in E}{f_{sk}}-\sum_{(k,j)\in E}{f_{kj}}}_{=0}\Big)} \\\\
&amp;amp;=\sum_{(s,j)\in E}{\Big(b_{sj}-a_{sj}+x_{j}\Big)f_{sj}}, \ j \in V \backslash \{s,t\},\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;trường-hợp-2-i-neq-s-j--t&quot;&gt;Trường hợp 2. \(i \neq s, j = t.\)&lt;/h3&gt;

&lt;p&gt;Tương tự, trong tổng theo \(x_k\) chỉ còn lại phần tử ứng với \(k = i\) (với dấu trừ):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;=\sum_{(i,t)\in E}{\Big((b_{it}-a_{it})f_{it}\Big)}-x_{i}\sum_{(i,t)\in E}{f_{it}}+\sum_{k\in V\backslash \{s,t,i\}}{x_{k}\Big(\underbrace{\sum_{(i,k)\in E}{f_{ik}}-\sum_{(k,t)\in E}{f_{kt}}}_{=0}\Big)} \\\\
&amp;amp;=\sum_{(i,t)\in E}{\Big(b_{it}-a_{it}-x_{i}\Big)f_{it}}, \ i \in V\backslash \{s,t\},\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;trường-hợp-3-i-neq-s-j-neq-t&quot;&gt;Trường hợp 3. \(i \neq s, j \neq t.\)&lt;/h3&gt;

&lt;p&gt;Trong trường hợp này, tổng theo \(x_k\) giữ lại cả hai phần tử ứng với \(k = j\) và \(k = i\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;=\sum_{(i,j)\in E}{\Big((b_{ij}-a_{ij})f_{ij}\Big)}+x_{j}\sum_{(i,j)\in E}{f_{ij}}-x_{i}\sum_{(i,j)\in E}{f_{ij}}+\sum_{k\in V\backslash \{s,t,i,j\}}{x_{k}\Big(\underbrace{\sum_{(i,k)\in E}{f_{ik}}-\sum_{(k,j)\in E}{f_{kj}}}_{=0}\Big)} \\\\
&amp;amp;=\sum_{(i,j)\in E}{\Big(b_{ij}-a_{ij}+x_{j}-x_{i}\Big)f_{ij}}, \ i, j \in V \backslash \{s,t\}. \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Đặt hệ số ở Trường hợp 1 bằng \(1\) và ở hai trường hợp còn lại bằng \(0\), ta thu được cận trên cho hàm mục tiêu gốc:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;b_{sj}-a_{sj}+x_{j} = 1\\\\
&amp;amp;b_{it}-a_{it}-x_{i} = 0\\\\
&amp;amp;b_{ij}-a_{ij}+x_{j}-x_{i} = 0\\\\
&amp;amp;\text{Do đó,} \\\\
&amp;amp;\sum_{(s,j)\in E}{f_{sj}} \leq \sum_{(i,j)\in E}{b_{ij}c_{ij}}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán đối ngẫu nhằm cực tiểu hóa cận trên \(\sum_{(i,j)\in E} b_{ij} c_{ij}\). Vì \(a_{ij} \geq 0\) chỉ đóng vai trò biến bù (slack variable), ta có thể khử \(a_{ij}\) để viết lại các đẳng thức thành bất đẳng thức. Đồng thời, khi đặt thêm quy ước \(x_s = 1\) và \(x_t = 0\), cả ba điều kiện trên gộp thành một dạng thống nhất:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{b\in {\mathbb{R}^{|E|}},\, x\in{\mathbb{R}^{|V|}}}  &amp;amp;&amp;amp;{\sum_{(i,j)\in E} b_{ij}c_{ij}} \\\\
&amp;amp;\text{với điều kiện} &amp;amp;&amp;amp;{b_{ij}+x_{j}-x_{i}\geq 0 \,\, \text{với mọi } (i,j)\in E}\\\\
&amp;amp;&amp;amp;&amp;amp;{b\geq 0, x_{s}=1,x_{t}=0}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;từ-lp-đối-ngẫu-đến-bài-toán-quy-hoạch-nguyên&quot;&gt;Từ LP đối ngẫu đến bài toán quy hoạch nguyên&lt;/h2&gt;

&lt;p&gt;Bây giờ ta chỉ ra rằng LP đối ngẫu trên chính là bản nới lỏng tuyến tính của bài toán lát cắt cực tiểu. Để chuyển bài toán LP đối ngẫu này về bài toán quy hoạch nguyên, ta bổ sung điều kiện nhị phân cho các biến \(x_i\) (tức là ép mọi đỉnh ngoài \(s\) và \(t\) chỉ được nhận giá trị \(0\) hoặc \(1\), tương ứng với việc phân hoạch tập đỉnh thành hai nhóm):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x_{i} \in \{0,1 \} \ \ \text{ với mọi }i\in V.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Đặt \(A = \{i : x_i = 1\}\) (chứa nguồn \(s\)) và \(B = \{i : x_i = 0\}\) (chứa đích \(t\)). Khi đó, với mục tiêu cực tiểu hóa \(\sum_{(i,j)\in E} b_{ij} c_{ij}\) cùng các ràng buộc \(b_{ij} \geq x_i - x_j\) và \(b_{ij} \geq 0\), biến \(b_{ij}\) nhận giá trị \(1\) nếu cạnh \((i, j)\) đi từ \(A\) sang \(B\) và bằng \(0\) trong mọi trường hợp còn lại:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\text{Đặt } A= \{ i:x_{i}=1 \} ,\, B= \{ i:x_{i}=0 \} \\\\
&amp;amp;\text{khi đó } s \in A, \,t \in B, \text{ và }b_{ij}\geq x_{i}-x_{j} \,\,\,\, \text{với }\,(i,j) \in E, \,\, b\geq 0,\\\\
\end{align}\)
\(\begin{align}
\text{Nói gọn, } \qquad \begin{cases} b_{ij}=1 \qquad \text{nếu } i\in A, j\in B\\\\
0 \qquad\qquad \text{trường hợp còn lại}.\end{cases}
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Đây chính xác là bài toán lát cắt cực tiểu đã phát biểu ở trên.&lt;/p&gt;

&lt;h2 id=&quot;mối-quan-hệ-giữa-bài-toán-luồng-cực-đại-và-lát-cắt-cực-tiểu-2&quot;&gt;Mối quan hệ giữa bài toán luồng cực đại và lát cắt cực tiểu (2)&lt;/h2&gt;

&lt;p&gt;Như vậy, LP đối ngẫu của bài toán luồng cực đại thu được từ bài toán lát cắt cực tiểu bằng cách bỏ ràng buộc nhị phân \(x_i \in \{0, 1\}\) (phép nới lỏng LP). Theo tính đối ngẫu yếu, giá trị luồng cực đại không vượt quá giá trị tối ưu của LP đối ngẫu. Mặt khác, vì phép nới lỏng mở rộng tập khả thi, giá trị tối ưu của bài toán lát cắt cực tiểu nới lỏng không vượt quá dung lượng lát cắt cực tiểu. Tóm lại, ta có:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{Giá trị luồng cực đại} &amp;amp;\leq \text{LP đối ngẫu của luồng cực đại}\\\\
&amp;amp;= \text{Giá trị tối ưu của lát cắt cực tiểu nới lỏng LP}\\\\
&amp;amp;\leq \text{Dung lượng của lát cắt cực tiểu}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Để xem chứng minh dấu bằng xảy ra cho cả chuỗi trên, bạn đọc có thể tham khảo định lý luồng cực đại – lát cắt cực tiểu [11]; về thuật toán tiêu biểu để giải bài toán này, xem thuật toán Ford–Fulkerson [12].&lt;/p&gt;

&lt;h3 id=&quot;luồng-cực-đại-và-lát-cắt-cực-tiểu-trong-khoảng-3-phút&quot;&gt;Luồng cực đại và lát cắt cực tiểu trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/max-flow-min-cut_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Một mạng 6 đỉnh: đường tăng luồng, đồ thị dư với cạnh ngược, lát cắt cực tiểu bằng giá trị luồng, và liên hệ với đối ngẫu LP.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>10-02 Tính đối ngẫu trong LP tổng quát</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_02_Duality_in_general_LPs/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_02_Duality_in_general_LPs</id>
   <content type="html">&lt;p&gt;Ở bài 10-01, ta đã tìm cận dưới bằng tay cho vài ví dụ hai biến đơn giản. Nhưng khi đối mặt với một bài toán quy hoạch tuyến tính tổng quát ngoài đời thực — có hàng nghìn biến, pha trộn cả ràng buộc đẳng thức \(Ax = b\) lẫn bất đẳng thức \(Gx \le h\) — ta cần một “cỗ máy đại số” tổng quát biến mọi bài toán LP dạng ma trận thành bài toán đối ngẫu chỉ trong một bước duy nhất mà không lo nhầm dấu!&lt;/p&gt;

&lt;p&gt;Bài học này thiết lập đúng cỗ máy chuẩn mực đó. Chỉ cần nhớ một quy tắc vàng duy nhất về dấu của biến đối ngẫu (ràng buộc đẳng thức \(\leftrightarrow\) biến đối ngẫu tự do; ràng buộc bất đẳng thức \(\leftrightarrow\) biến đối ngẫu không âm) và phép chuyển vị ma trận (\(A \to A^T, G \to G^T\)), bạn có thể viết ngay bài toán đối ngẫu cho bất kỳ LP nào dù cồng kềnh đến đâu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-quy-tắc-tổng-quát-hóa-đối-ngẫu-lp&quot;&gt;Kiến thức cần nhớ: Bốn quy tắc tổng quát hóa đối ngẫu LP&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cặp dạng chuẩn tổng quát:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Primal:&lt;/em&gt; \(\min_x c^T x \;\text{ s.t. }\; Ax = b,\; Gx \le h\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Dual:&lt;/em&gt; \(\max_{u, v} -b^T u - h^T v \;\text{ s.t. }\; -A^T u - G^T v = c,\; v \ge 0\) (với \(u\) tự do dấu).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc chuyển đổi trực giác (nhân ràng buộc với biến đối ngẫu):&lt;/strong&gt; Cộng \(u^T(Ax - b) = 0\) và \(v^T(Gx - h) \le 0\) (với \(v \ge 0\)) vào hàm mục tiêu \(c^T x\), rồi gom hệ số của \(x\) thành \((c + A^T u + G^T v)^T x - b^T u - h^T v\). Để chặn dưới không phụ thuộc vào \(x \in \mathbb{R}^n\) tự do, hệ số đứng trước \(x\) bắt buộc phải bằng \(0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính đối ngẫu yếu (luôn đúng không điều kiện):&lt;/strong&gt; Với mọi \(x\) khả thi gốc và \((u, v)\) khả thi đối ngẫu, ta luôn có \(-b^T u - h^T v \le c^T x\). Hệ quả tức thì: nếu bài toán gốc không bị chặn dưới (\(p^* = -\infty\)) thì bài toán đối ngẫu chắc chắn &lt;strong&gt;vô nghiệm&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính đối ngẫu mạnh trong LP:&lt;/strong&gt; Miễn là bài toán gốc khả thi và có giá trị tối ưu hữu hạn, bài toán đối ngẫu cũng có nghiệm tối ưu và \(p^* = d^*\) (chứng minh nhờ Bổ đề Farkas / Định lý tách siêu phẳng).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chuyển-đổi-tay-một-lp-hỗn-hợp-có-cả--và-le-sang-đối-ngẫu&quot;&gt;Giải thích: Chuyển đổi tay một LP hỗn hợp (có cả &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\le&lt;/code&gt;) sang đối ngẫu&lt;/h3&gt;

&lt;p&gt;Xét LP 2 biến có cả ràng buộc đẳng thức lẫn bất đẳng thức:
\(\min_{x_1, x_2 \in \mathbb{R}} \; 2x_1 + x_2 \quad \text{s.t.} \quad x_1 + x_2 = 3, \quad -x_1 \le -1 \; (\text{tức } x_1 \ge 1).\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhận diện ma trận chuẩn:&lt;/strong&gt;
\(c = \begin{pmatrix} 2 \\ 1 \end{pmatrix}, \quad A = \begin{pmatrix} 1 &amp;amp; 1 \end{pmatrix}, \; b = 3, \quad G = \begin{pmatrix} -1 &amp;amp; 0 \end{pmatrix}, \; h = -1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Viết bài toán đối ngẫu theo công thức ma trận (\(u \in \mathbb{R}, v \ge 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hàm mục tiêu đối ngẫu: \(\max -b^T u - h^T v = \max \; -3u + v\).&lt;/li&gt;
      &lt;li&gt;Ràng buộc \(-A^T u - G^T v = c\):
\(\begin{cases} -u + v = 2 \\ -u = 1 \end{cases} \quad \text{với } v \ge 0.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải tay cả hai bài toán để đối chiếu đối ngẫu mạnh:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Giải Dual:&lt;/em&gt; Từ \(-u = 1 \implies u^* = -1\); thay vào \(-(-1) + v = 2 \implies v^* = 1 \ge 0\). Giá trị đối ngẫu tối ưu: \(d^* = -3(-1) + 1 = 4\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Giải Primal:&lt;/em&gt; Vì \(x_2 = 3 - x_1\), hàm mục tiêu trở thành \(2x_1 + (3 - x_1) = x_1 + 3\) với ràng buộc \(x_1 \ge 1\). Nghiệm tối ưu là \(x_1^* = 1, x_2^* = 2\), giá trị gốc tối ưu \(p^* = 2(1) + 2 = 4 = d^*\)!
Cả hai khớp nhau tuyệt đối từng dấu trừ!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trong bài &lt;a href=&quot;/contents/vi/chapter10/10_01_Lower_Bounds_in_Linear_Programs/&quot;&gt;10-01&lt;/a&gt;, chúng ta đã tìm hiểu bài toán gốc và bài toán đối ngẫu cho các bài toán LP đơn giản với biến vô hướng. Trong bài này, ta sẽ mở rộng cách xây dựng đối ngẫu cho LP ở dạng tổng quát.&lt;/p&gt;

&lt;p&gt;Xét bài toán LP tổng quát với \(c\in\mathbb{R}^{n},\, A\in\mathbb{R}^{m\times n},\, b\in\mathbb{R}^{m},\, G\in\mathbb{R}^{r\times n},\, h\in\mathbb{R}^{r}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;c^{T}x\\\\
&amp;amp;\text{với điều kiện} &amp;amp;&amp;amp;Ax = b\\\\
&amp;amp; &amp;amp;&amp;amp;Gx \leq h.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tương tự như trong bài 10-01, ta đưa vào các biến đối ngẫu \(u \in \mathbb{R}^m\) và \(v \in \mathbb{R}^r\) tương ứng với từng nhóm ràng buộc, rồi nhân các ràng buộc với biến đối ngẫu tương ứng và cộng lại:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;u^{T}(Ax-b) = 0\\\\
&amp;amp;{+} &amp;amp;v^{T}(Gx-h)\leq 0\\\\
&amp;amp;{=} &amp;amp;u^{T}(Ax-b) + v^{T}(Gx-h)\leq 0.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Lưu ý rằng biến đối ngẫu \(u\) ứng với ràng buộc đẳng thức không bị ràng buộc về dấu, trong khi \(v\) ứng với ràng buộc bất đẳng thức phải thỏa mãn điều kiện không âm (\(v \geq 0\)). Biến đổi bất đẳng thức cuối để làm xuất hiện hàm mục tiêu của LP gốc, ta thu được cận dưới:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
u^{T}(Ax-b) + v^{T}(Gx-h)\leq 0 \\\\
\underbrace{(-A^{T}u-G^{T}v)^{T}}_{=c^{T}}x\geq-b^{T}u-h^{T}v \\\\
\text{Cận dưới là} -b^{T}u-h^{T}v \\\\ 
\text{với } x \text{ khả thi nguyên thủy, và bất kỳ u, v thỏa mãn,} \\\\
c = -A^{T}u-G^{T}v \\\\
v\geq 0. \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Như vậy, với mọi cặp \((u, v)\) thỏa mãn \(c = -A^{T}u - G^{T}v\) và \(v \geq 0\), biểu thức \(-b^{T}u - h^{T}v\) là một cận dưới của giá trị tối ưu bài toán gốc.&lt;/p&gt;

&lt;p&gt;Cực đại hóa cận dưới này, ta thu được bài toán LP đối ngẫu:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{u,v} &amp;amp;&amp;amp;-b^{T}u-h^{T}v \\\\
&amp;amp;\text{với điều kiện} &amp;amp;&amp;amp;c = -A^{T}u-G^{T}v \\\\
&amp;amp; &amp;amp;&amp;amp;v\geq 0.
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>10-01 Cận dưới trong Chương trình Tuyến tính</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_01_Lower_Bounds_in_Linear_Programs/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter10/10_01_Lower_Bounds_in_Linear_Programs</id>
   <content type="html">&lt;p&gt;Giả sử đồng nghiệp đưa cho bạn một bài toán tối ưu cực tiểu hóa \(\min c^T x\) và tuyên bố: &lt;em&gt;“Tôi chạy máy tính cả đêm tìm được nghiệm \(x\) cho giá trị bằng \(14\), chắc chắn là tối ưu rồi!”&lt;/em&gt; Làm thế nào bạn có thể &lt;strong&gt;chứng minh chắc nịch&lt;/strong&gt; rằng không tồn tại một nghiệm nào khác cho giá trị \(13.99\) mà không cần phải vét cạn vô số điểm trong không gian nhiều chiều?&lt;/p&gt;

&lt;p&gt;Câu trả lời đầy tinh tế của bài học này là: hãy đi tìm một &lt;strong&gt;chứng chỉ cận dưới (lower bound certificate)&lt;/strong&gt;! Nếu bạn có thể nhân các bất đẳng thức ràng buộc của bài toán với những hệ số không âm khéo chọn rồi cộng vế theo vế để thu được đúng hàm mục tiêu \(c^T x \ge 14\), thì bất kỳ ai cũng phải tâm phục khẩu phục rằng \(14\) là đáy tuyệt đối. Và tuyệt vời hơn nữa: chính bài toán đi tìm bộ hệ số nhân cho cận dưới &lt;em&gt;lớn nhất có thể&lt;/em&gt; đó chính là &lt;strong&gt;bài toán đối ngẫu của LP&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trực-giác-từ-bài-toán-tìm-cận-dưới&quot;&gt;Kiến thức cần nhớ: Ba trực giác từ bài toán tìm cận dưới&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp tuyến tính bảo toàn dấu bất đẳng thức:&lt;/strong&gt; Nếu ta có các ràng buộc \(a_i^T x \ge b_i\) và nhân từng bất đẳng thức với trọng số &lt;strong&gt;không âm&lt;/strong&gt; \(u_i \ge 0\) rồi cộng lại, chiều bất đẳng thức được bảo toàn hoàn toàn: \(\left(\sum u_i a_i\right)^T x \ge \sum u_i b_i\). (Còn với ràng buộc đẳng thức \(a_j^T x = b_j\), trọng số \(v_j\) có thể mang dấu tùy ý vì đẳng thức nhân số âm vẫn là đẳng thức!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khớp hệ số hàm mục tiêu:&lt;/strong&gt; Khi chọn \((u, v)\) sao cho tổ hợp tuyến tính vế trái bằng đúng \(c^T x\) (hoặc nhỏ hơn \(c^T x\) nếu \(x \ge 0\)), vế phải \(b^T u\) lập tức trở thành một cận dưới hợp lệ cho mọi \(x\) khả thi — tức là \(b^T u \le \min c^T x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối đa hóa cận dưới \(\implies\) Bài toán đối ngẫu:&lt;/strong&gt; Vì ta muốn chứng chỉ cận dưới mạnh nhất (chặt nhất) có thể, ta cực đại hóa \(b^T u\) trên tất cả các bộ nhân hợp lệ. Đó chính là cách bài toán đối ngẫu ra đời một cách hoàn toàn tự nhiên, không hề gượng ép!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-dựng-chứng-chỉ-cận-dưới-cho-một-lp-2-biến&quot;&gt;Giải thích: Tự tay dựng chứng chỉ cận dưới cho một LP 2 biến&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa:
\(\min_{x_1, x_2 \ge 0} \; 3x_1 + 5x_2 \quad \text{s.t.} \quad \begin{cases} x_1 + x_2 \ge 4 &amp;amp; \text{(nhân với } u_1 \ge 0\text{)} \\ x_1 + 3x_2 \ge 6 &amp;amp; \text{(nhân với } u_2 \ge 0\text{)} \end{cases}\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thử một nghiệm khả thi để lấy cận trên:&lt;/strong&gt; Chọn \(x = (3, 1)\): kiểm tra \(3+1 = 4 \ge 4\) và \(3+3 = 6 \ge 6\) (khả thi!). Giá trị hàm mục tiêu là \(3(3) + 5(1) = 14\). Vậy ta biết chắc \(p^* \le 14\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dựng cận dưới bằng cách cộng hai ràng buộc:&lt;/strong&gt;
Nhân ràng buộc (1) với \(u_1 \ge 0\) và ràng buộc (2) với \(u_2 \ge 0\) rồi cộng vế theo vế:
\((u_1 + u_2)x_1 + (u_1 + 3u_2)x_2 \ge 4u_1 + 6u_2.\)
Để vế trái chặn dưới \(3x_1 + 5x_2\) với mọi \(x_1, x_2 \ge 0\), ta chỉ cần:
\(u_1 + u_2 \le 3 \quad \text{và} \quad u_1 + 3u_2 \le 5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn bộ nhân tối ưu và chốt chứng chỉ:&lt;/strong&gt;
Giải hệ \(u_1 + u_2 = 3, \; u_1 + 3u_2 = 5\) ta được \(u_1 = 2 \ge 0, \; u_2 = 1 \ge 0\).
Thay vào bất đẳng thức:
\(2(x_1 + x_2) + 1(x_1 + 3x_2) = 3x_1 + 5x_2 \ge 2(4) + 1(6) = 14!\)
Vì vừa có cận trên \(p^* \le 14\) (tại \(x = (3, 1)\)), vừa có cận dưới \(p^* \ge 14\) (chứng chỉ \(u = (2, 1)\)), ta kết luận chắc chắn 100% rằng \(p^* = 14\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;h2 id=&quot;ví-dụ-1-trường-hợp-ràng-buộc-chứa-trực-tiếp-hàm-mục-tiêu&quot;&gt;Ví dụ 1: Trường hợp ràng buộc chứa trực tiếp hàm mục tiêu&lt;/h2&gt;

&lt;p&gt;Giả sử chúng ta muốn tìm một cận dưới \(B\) cho giá trị tối ưu của một bài toán lồi cho trước:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
B \leq \min_{x} f(x).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Hãy xét cụ thể bài toán tìm cận dưới trong quy hoạch tuyến tính (LP), đi từ các trường hợp đơn giản đến dạng tổng quát. Trước hết, xét ví dụ LP đơn giản nhất:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y}  
&amp;amp; &amp;amp;{x+y} \\\\
&amp;amp;\text{với điều kiện} 
&amp;amp; &amp;amp;{x + y \geq 2}\\\\
&amp;amp; &amp;amp; &amp;amp;{x, y \geq 0.}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong bài toán này, chính ràng buộc đã cung cấp trực tiếp cận dưới cho hàm mục tiêu, nên ta dễ dàng thấy ngay \(B = 2\).&lt;/p&gt;

&lt;p&gt;Tiếp theo, hãy xét trường hợp ràng buộc không cho sẵn cận dưới một cách trực tiếp như vậy.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-2-trường-hợp-hàm-mục-tiêu-là-tổ-hợp-tuyến-tính-của-các-ràng-buộc-1&quot;&gt;Ví dụ 2: Trường hợp hàm mục tiêu là tổ hợp tuyến tính của các ràng buộc (1)&lt;/h2&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y}  
&amp;amp; &amp;amp; {x+3y} \\\\
&amp;amp;\text{với điều kiện} 
&amp;amp; &amp;amp;{x + y \geq 2}\\\\
&amp;amp; &amp;amp; &amp;amp;{x, y \geq 0.}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu \(x,\, y\) là một nghiệm khả thi, thì khi nhân các bất đẳng thức ràng buộc với những hằng số không âm rồi cộng lại, ta vẫn thu được một bất đẳng thức đúng. Do đó, bằng cách chọn hệ số thích hợp để biểu diễn hàm mục tiêu dưới dạng tổ hợp tuyến tính không âm của các ràng buộc, ta có thể suy ra cận dưới \(B\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;{x + y \geq 2}\\\\
&amp;amp;{+} &amp;amp;{0x \geq 0}\\\\
&amp;amp;{+} &amp;amp;{2y \geq 0}\\\\
&amp;amp;{=} &amp;amp;{x + 3y \geq 2}\\\\

&amp;amp; &amp;amp;{\text{Cận dưới}\ B = 2.}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tổng quát hóa hơn nữa với các hệ số tùy ý \(p, q\) trong hàm mục tiêu, ta xét bài toán:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y}  
&amp;amp; &amp;amp;{px+qy} \\\\
&amp;amp;\text{với điều kiện} 
&amp;amp; &amp;amp;{x + y \geq 2}\\\\
&amp;amp; &amp;amp; &amp;amp;{x, y \geq 0.}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tương tự như trên, ta nhân ba ràng buộc lần lượt với các hằng số \(a, b, c\) rồi cộng lại để khớp với hàm mục tiêu:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;{a(x+y) \geq 2a} \\\\
&amp;amp;{+} &amp;amp;{bx \geq 0} \\\\
&amp;amp;{+} &amp;amp;{cy \geq 0} \\\\
&amp;amp;{=} &amp;amp;{(a+b)x+(a+c)y \geq 2a} \\\\
&amp;amp;&amp;amp;\text{Cận dưới}\ B=2a, \\
&amp;amp;&amp;amp;\text{với bất kỳ a,b,c thỏa mãn điều kiện dưới đây}\\\\
&amp;amp; &amp;amp;{a + b = p}\\\\
&amp;amp; &amp;amp;{a + c = q}\\\\
&amp;amp; &amp;amp;{a,b,c \geq 0.}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Để \(2a\) thực sự là một cận dưới, các hệ số \(a, b, c\) phải không âm (vì nhân bất đẳng thức với số âm sẽ làm đổi chiều dấu), đồng thời hệ số của \(x\) và \(y\) sau khi cộng phải trùng với hàm mục tiêu, tức là \(a + b = p\) và \(a + c = q\).&lt;/p&gt;

&lt;p&gt;Để tìm cận dưới chặt nhất (lớn nhất), ta lập một bài toán tối ưu mới với mục tiêu cực đại hóa \(2a\), trong đó các điều kiện đảm bảo cận dưới trở thành ràng buộc của bài toán mới:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{a, b, c}  
&amp;amp; &amp;amp;{2a} \\\\
&amp;amp;\text{với điều kiện} 
&amp;amp; &amp;amp;{a + b = p}\\\\
&amp;amp; &amp;amp; &amp;amp;{a + c = q}\\\\
&amp;amp; &amp;amp; &amp;amp;{a, b, c \geq 0}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán LP ban đầu được gọi là &lt;strong&gt;LP gốc (primal LP)&lt;/strong&gt;, còn bài toán cực đại hóa cận dưới vừa xây dựng được gọi là &lt;strong&gt;LP đối ngẫu (dual LP)&lt;/strong&gt;. Lưu ý rằng số biến của bài toán đối ngẫu bằng số ràng buộc của bài toán gốc.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{LP Nguyên thủy}\qquad
&amp;amp;\qquad \min_{x, y}  &amp;amp;{px+qy} \\\\
&amp;amp;\qquad \text{với điều kiện} &amp;amp;{x + y \geq 2}\\\\
&amp;amp;\qquad &amp;amp;{x, y \geq 0}\\\\
\\\\
\\\\
\text{LP Đối ngẫu}\qquad
&amp;amp;\qquad \max_{a, b, c}  &amp;amp;{2a} \\\\
&amp;amp;\qquad \text{với điều kiện} &amp;amp;{a + b = p}\\\\
&amp;amp;\qquad &amp;amp;{a + c = q}\\\\
&amp;amp;\qquad &amp;amp;{a, b, c \geq 0}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;ví-dụ-3-trường-hợp-hàm-mục-tiêu-là-tổ-hợp-tuyến-tính-của-các-ràng-buộc-2&quot;&gt;Ví dụ 3: Trường hợp hàm mục tiêu là tổ hợp tuyến tính của các ràng buộc (2)&lt;/h2&gt;

&lt;p&gt;Xét ví dụ cuối cùng, trong đó có cả bất đẳng thức ngược chiều (\(\leq\)) và ràng buộc đẳng thức (\(=\)):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y}  &amp;amp;{px+qy} \\\\
&amp;amp;\text{với điều kiện} &amp;amp;{x \geq 0}\\\\
&amp;amp; &amp;amp;{y \leq 1}\\\\
&amp;amp; &amp;amp;{3x + y = 2}\\\\
\\\\
&amp;amp; &amp;amp;{ax \geq 0}\\\\
&amp;amp;{+} &amp;amp;{-by \geq -b}\\\\
&amp;amp;{+} &amp;amp;{3cx + cy = 2c}\\\\
&amp;amp;{=} &amp;amp;{(a+3c)x+(-b+c)y \geq 2c-b}
\\\\
\\\\
&amp;amp;&amp;amp; \text{Cận dưới}  \ B=2c-b, \\
&amp;amp;&amp;amp; \text{với bất kỳ a,b,c thỏa mãn điều kiện dưới đây}\\\\
&amp;amp; &amp;amp;{a + 3c = p}\\\\
&amp;amp; &amp;amp;{-b + c = q}\\\\
&amp;amp; &amp;amp;{a,b \geq 0}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây, vì \(c\) nhân với hai vế của một phương trình đẳng thức nên \(c\) có thể nhận bất kỳ giá trị thực nào (không bị ràng buộc dấu).&lt;/p&gt;

&lt;p&gt;Từ đó, bài toán LP đối ngẫu được viết như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\qquad \max_{a, b, c}  &amp;amp;{2c-b} \\\\
&amp;amp;\qquad \text{với điều kiện} &amp;amp;{a + 3c = p}\\\\
&amp;amp;\qquad &amp;amp;{-b + c = q}\\\\
&amp;amp;\qquad &amp;amp;{a, b \geq 0}\\\\
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>10 Duality in Linear Programs</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_Duality_in_Linear_Programs/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_Duality_in_Linear_Programs</id>
   <content type="html">&lt;p&gt;Suppose a logistics team hands you a shipping schedule costing $4.2 million and claims it is the absolute cheapest plan possible. How could they &lt;em&gt;prove&lt;/em&gt; to a skeptical CFO that no hidden route combination in a billion-variable network could shave off even $1? Checking every feasible plan is impossible, yet &lt;strong&gt;Linear Programming (LP) duality&lt;/strong&gt; provides an astonishingly compact certificate: a set of nonnegative resource “shadow prices” whose weighted sum of constraints produces a mathematical lower bound equal to $4.2 million. Chapter 10 unpacks this primal–dual mirror world—from elementary lower bounds to max-flow/min-cut and von Neumann’s minimax theorem.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-architecture-of-lp-duality&quot;&gt;Key ideas: The Architecture of LP Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Primal Plans vs. Dual Certificates:&lt;/strong&gt; Every minimization LP (the &lt;em&gt;primal&lt;/em&gt;) seeks the lowest-cost feasible decision \(x\); its companion maximization LP (the &lt;em&gt;dual&lt;/em&gt;) combines the primal constraints with multipliers \((u, v)\) to build the tightest possible lower bound \(B \le c^\top x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Weak vs. Strong Duality:&lt;/strong&gt; Weak duality (\(d^\star \le p^\star\)) holds universally by construction of valid constraint combinations. For feasible, bounded LPs, &lt;strong&gt;strong duality&lt;/strong&gt; (\(d^\star = p^\star\)) closes the gap completely, guaranteeing that an exact optimality certificate always exists.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Combinatorial &amp;amp; Game-Theoretic Dual Pairs:&lt;/strong&gt; LP duality unifies crown jewels across mathematics and computer science: the dual of maximum network flow is the minimum \(s\text{–}t\) cut, and the dual of one player’s minimax strategy in a zero-sum matrix game is the opponent’s maximin strategy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Perfect Symmetry (Involution):&lt;/strong&gt; Taking the dual of the dual LP recovers the original primal LP verbatim—meaning neither problem is inherently “primary”; they are two equivalent views of the same polyhedral geometry.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-certifying-optimality-of-a-2-variable-lp-in-three-lines&quot;&gt;Worked example: Certifying Optimality of a 2-Variable LP in Three Lines&lt;/h3&gt;

&lt;p&gt;Consider the primal LP: minimize \(x_1 + 2x_2\) subject to \(x_1 + x_2 \ge 3\), \(x_1 \ge 1\), and \(x_2 \ge 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test a candidate primal solution:&lt;/strong&gt; Try \(x^\star = (3, 0)^\top\).
    &lt;ul&gt;
      &lt;li&gt;Check feasibility: \(3 + 0 = 3 \ge 3\), \(3 \ge 1\), \(0 \ge 0\) (all satisfied!).&lt;/li&gt;
      &lt;li&gt;Primal objective value: \(p = 1(3) + 2(0) = 3\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Construct a lower bound directly from the constraints:&lt;/strong&gt;
Notice that since \(x_2 \ge 0\), adding \(1 \cdot (x_1 + x_2 \ge 3)\) and \(1 \cdot (x_2 \ge 0)\) gives:
\(x_1 + 2x_2 = (x_1 + x_2) + x_2 \ge 3 + 0 = 3.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Read off the certificate:&lt;/strong&gt; For &lt;em&gt;every&lt;/em&gt; feasible \((x_1, x_2)\), the objective is at least \(3\) (weak duality), and \(x^\star = (3, 0)^\top\) achieves \(3\) (strong duality). That single nonnegative combination of constraints proves global optimality without inspecting any other point in the feasible region!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Starting from this chapter, we will examine duality, which plays a significant role in optimization theory.
From an optimization perspective, duality can be simply described as the concept that a single optimization problem can be viewed from two perspectives: the primal problem and the dual problem.&lt;/p&gt;

&lt;p&gt;In this chapter, we specifically explore duality in linear programs.
Rather than directly applying it to general convex problems, we will derive the dual problem from the primal problem by applying it to linear programs, and organize how the relationship between these two problems is established and what properties they have under specific conditions.&lt;/p&gt;

&lt;h2 id=&quot;modern-applications-20222026&quot;&gt;Modern applications (2022–2026)&lt;/h2&gt;

&lt;p&gt;An optional companion lesson reads the same LP dual as a certificate in neural-network verification (α,β-CROWN), electricity LMPs, max-flow cuts, and Kantorovich optimal transport. See &lt;a href=&quot;/contents/en/chapter10/10_07_modern_applications/&quot;&gt;10-07 Modern applications of LP duality&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>10-09 Practical Exercises - Duality in Linear Programming</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_09_Practical_Exercises_LP_Duality/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_09_Practical_Exercises_LP_Duality</id>
   <content type="html">&lt;p&gt;Knowing the LP duality theorem is one thing; being able to dualize a messy production-planning model, interpret shadow prices for a portfolio manager, or verify complementary slackness on a network flow is what turns theory into engineering skill. The exercises below—adapted from Boyd &amp;amp; Vandenberghe, Bertsimas &amp;amp; Tsitsiklis, and Dantzig—walk you progressively from mechanical dual construction through economic sensitivity analysis and strong duality proofs.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-problem-solving-toolkit-for-lp-duality-exercises&quot;&gt;Key ideas: Problem-Solving Toolkit for LP Duality Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Systematic Dual Construction via Lagrangian:&lt;/strong&gt; When faced with mixed \(\le\), \(\ge\), and \(=\) constraints alongside bounded or free variables, write \(L(x, u, v)\) explicitly, collect terms multiplying each \(x_j\), and set \(\inf_{x_j} (\text{coeff}_j) x_j\) finite—this eliminates sign errors completely.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Shadow Prices (Economic Interpretation):&lt;/strong&gt; At a nondegenerate optimum, the optimal dual variable \(y_i^\star\) equals \(\frac{\partial p^\star}{\partial b_i}\), the exact marginal value of relaxing resource constraint \(i\) by one unit. A zero dual variable means that resource has surplus capacity.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Complementary Slackness Verification:&lt;/strong&gt; To test if a candidate primal vertex \(x\) is optimal without solving the dual from scratch, force \(y_i = 0\) on every non-binding primal constraint and force the dual constraint tight for every \(x_j &amp;gt; 0\), then solve the tiny resulting linear system for \(y\) and check dual feasibility!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Duality-Based Feasibility Certificates (Farkas’ Lemma):&lt;/strong&gt; Proving an LP is infeasible reduces to exhibiting a ray in the dual—a nonnegative combination of constraints that yields the contradiction \(0 \ge 1\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-using-shadow-prices-to-value-an-extra-unit-of-resource&quot;&gt;Worked example: Using Shadow Prices to Value an Extra Unit of Resource&lt;/h3&gt;

&lt;p&gt;A factory solves the profit-maximization LP: \(\max 3x_1 + 2x_2\) s.t. \(x_1 + x_2 \le 4\) (labor hours), \(2x_1 + x_2 \le 6\) (machine hours), \(x_1, x_2 \ge 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the primal at the intersection of both resource constraints:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x_1 + x_2 = 4\) and \(2x_1 + x_2 = 6 \implies x_1^\star = 2,\; x_2^\star = 2\).&lt;/li&gt;
      &lt;li&gt;Optimal profit: \(p^\star = 3(2) + 2(2) = 10\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find the shadow prices \((y_1^\star, y_2^\star)\) via complementary slackness:&lt;/strong&gt;
Since \(x_1^\star &amp;gt; 0\) and \(x_2^\star &amp;gt; 0\), both dual constraints must be tight:
\(y_1 + 2y_2 = 3, \qquad y_1 + y_2 = 2.\)
    &lt;ul&gt;
      &lt;li&gt;Subtracting gives \(y_2^\star = 1\) (machine-hour shadow price) and \(y_1^\star = 1\) (labor-hour shadow price).&lt;/li&gt;
      &lt;li&gt;Dual objective check: \(4(1) + 6(1) = 10 = p^\star\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Predict the profit gain if machine capacity rises from \(6\) to \(7\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Shadow-price prediction: \(\Delta p^\star = y_2^\star \cdot 1 = +1\), predicting new profit \(11\).&lt;/li&gt;
      &lt;li&gt;Exact verification: solving \(x_1 + x_2 = 4\) and \(2x_1 + x_2 = 7\) gives \(x_1 = 3, x_2 = 1\), with profit \(3(3) + 2(1) = 11\)—an exact match!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The following exercises are adapted from Boyd &amp;amp; Vandenberghe (2004), Bertsimas &amp;amp; Tsitsiklis (1997), and Dantzig (1963), and help students master the concepts of duality in LP.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-i-constructing-dual-problems&quot;&gt;&lt;strong&gt;Part I: Constructing Dual Problems&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-1-basic-lp-forms-boyd--vandenberghe-ex-51&quot;&gt;&lt;strong&gt;Exercise 1: Basic LP Forms (Boyd &amp;amp; Vandenberghe, Ex. 5.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;For each of the following LPs, construct the dual problem and explain the meaning of the dual variables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a) Standard form:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; 3x_1 + 5x_2 + 2x_3 \\
\text{s.t.} \quad &amp;amp; x_1 + 2x_2 + x_3 = 4 \\
&amp;amp; 2x_1 + x_2 + 3x_3 = 5 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;b) Inequality form:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; 2x_1 + 4x_2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 \geq 3 \\
&amp;amp; 2x_1 + x_2 \geq 5 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;c) Mixed form:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; x_1 + 2x_2 + 3x_3 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 = 2 \\
&amp;amp; x_2 + x_3 \leq 3 \\
&amp;amp; x_1 + x_3 \geq 1 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Part a) Standard form:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Rule:&lt;/strong&gt; For a min problem with equality constraints and variables \(\geq 0\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Each equality constraint → a free (unrestricted-sign) dual variable&lt;/li&gt;
    &lt;li&gt;Each variable \(\geq 0\) → a dual constraint \(\leq\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Dual problem:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; 4u_1 + 5u_2 \\
\text{s.t.} \quad &amp;amp; u_1 + 2u_2 \leq 3 \\
&amp;amp; 2u_1 + u_2 \leq 5 \\
&amp;amp; u_1 + 3u_2 \leq 2 \\
&amp;amp; u_1, u_2 \in \mathbb{R}
\end{align}\]

  &lt;p&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(u_1, u_2\): shadow prices of constraints 1 and 2 (marginal value of increasing the RHS)&lt;/li&gt;
    &lt;li&gt;Unrestricted in sign because the primal constraints are equalities&lt;/li&gt;
    &lt;li&gt;Each primal variable produces one dual constraint&lt;/li&gt;
  &lt;/ul&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Part b) Inequality form:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Rule:&lt;/strong&gt; Min with \(\geq\) and \(x \geq 0\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;A \(\geq\) constraint → a dual variable \(\geq 0\)&lt;/li&gt;
    &lt;li&gt;A variable \(\geq 0\) → a dual constraint \(\leq\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Dual problem:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; 3u_1 + 5u_2 \\
\text{s.t.} \quad &amp;amp; u_1 + 2u_2 \leq 2 \\
&amp;amp; u_1 + u_2 \leq 4 \\
&amp;amp; u_1, u_2 \geq 0
\end{align}\]

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Part c) Mixed form:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Analysis:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Constraint 1 (\(=\)): dual variable \(u_1 \in \mathbb{R}\)&lt;/li&gt;
    &lt;li&gt;Constraint 2 (\(\leq\)): dual variable \(u_2 \leq 0\)&lt;/li&gt;
    &lt;li&gt;Constraint 3 (\(\geq\)): dual variable \(u_3 \geq 0\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Dual problem:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; 2u_1 + 3u_2 + u_3 \\
\text{s.t.} \quad &amp;amp; u_1 + u_3 \leq 1 \\
&amp;amp; u_1 + u_2 \leq 2 \\
&amp;amp; u_2 + u_3 \leq 3 \\
&amp;amp; u_1 \in \mathbb{R}, \quad u_2 \leq 0, \quad u_3 \geq 0
\end{align}\]

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-2-production-planning-boyd--vandenberghe-ex-52&quot;&gt;&lt;strong&gt;Exercise 2: Production Planning (Boyd &amp;amp; Vandenberghe, Ex. 5.2)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;A factory produces 2 products A and B:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Product&lt;/th&gt;
      &lt;th&gt;Profit (thousand VND)&lt;/th&gt;
      &lt;th&gt;Labor (hours)&lt;/th&gt;
      &lt;th&gt;Machine (hours)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;A&lt;/td&gt;
      &lt;td&gt;40&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;B&lt;/td&gt;
      &lt;td&gt;30&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Resources: 100 labor hours, 80 machine hours.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Formulate the LP that maximizes profit  &lt;br /&gt;
b) Construct the dual problem  &lt;br /&gt;
c) Explain the economic meaning of the dual variables  &lt;br /&gt;
d) If one more labor hour is available, what is the maximum increase in profit?&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Primal problem:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Let \(x_1, x_2\) be the quantities of products A and B.&lt;/p&gt;

\[\begin{align}
\max_{x} \quad &amp;amp; 40x_1 + 30x_2 \\
\text{s.t.} \quad &amp;amp; 2x_1 + x_2 \leq 100 \quad \text{(Labor)} \\
&amp;amp; x_1 + 2x_2 \leq 80 \quad \text{(Machine)} \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Dual problem:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Convert to a min problem: \(\min -40x_1 - 30x_2\)&lt;/p&gt;

\[\begin{align}
\min_{u} \quad &amp;amp; 100u_1 + 80u_2 \\
\text{s.t.} \quad &amp;amp; 2u_1 + u_2 \geq 40 \\
&amp;amp; u_1 + 2u_2 \geq 30 \\
&amp;amp; u_1, u_2 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;c) Economic meaning:&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;\(u_1\): &lt;strong&gt;Shadow price of labor&lt;/strong&gt; - the marginal value of one more labor hour&lt;/li&gt;
    &lt;li&gt;\(u_2\): &lt;strong&gt;Shadow price of machine time&lt;/strong&gt; - the marginal value of one more machine hour&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Dual constraints:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(2u_1 + u_2 \geq 40\): the value of the resources used to make 1 unit of product A must be \(\geq\) its profit&lt;/li&gt;
    &lt;li&gt;\(u_1 + 2u_2 \geq 30\): similarly for product B&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;d) Profit increase:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;To answer, solve the system of active dual constraints: \(2u_1 + u_2 = 40\), \(u_1 + 2u_2 = 30\) → \(u_1^* = 50/3 \approx 16.67\), \(u_2^* = 20/3 \approx 6.67\) thousand VND/hour (check: primal \(x^* = (40, 20)\) gives \(40 \cdot 40 + 30 \cdot 20 = 2200\) = dual \(100 \cdot \frac{50}{3} + 80 \cdot \frac{20}{3} = 2200\) ✓).&lt;/p&gt;

  &lt;p&gt;→ One more labor hour increases profit by about &lt;strong&gt;16.67 thousand VND&lt;/strong&gt; (\(50/3\)).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-3-portfolio-optimization-boyd--vandenberghe-ex-53&quot;&gt;&lt;strong&gt;Exercise 3: Portfolio Optimization (Boyd &amp;amp; Vandenberghe, Ex. 5.3)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;An investor has 1000 million VND to invest in 3 assets with the following expected returns:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Asset&lt;/th&gt;
      &lt;th&gt;Return (%)&lt;/th&gt;
      &lt;th&gt;Risk (standard deviation)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Stocks&lt;/td&gt;
      &lt;td&gt;15&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bonds&lt;/td&gt;
      &lt;td&gt;8&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Cash&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Requirements: a return of at least 10% and a total risk of at most 12%.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Formulate the LP that minimizes risk&lt;br /&gt;
b) Construct the dual problem&lt;br /&gt;
c) Explain the meaning of the dual variables&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Primal problem:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Let \(x_1, x_2, x_3\) be the fractions invested in stocks, bonds, and cash.&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; 20x_1 + 5x_2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 + x_3 = 1 \quad \text{(Total capital)} \\
&amp;amp; 15x_1 + 8x_2 + 3x_3 \geq 10 \quad \text{(Return)} \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Dual problem:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; u_1 + 10u_2 \\
\text{s.t.} \quad &amp;amp; u_1 + 15u_2 \leq 20 \\
&amp;amp; u_1 + 8u_2 \leq 5 \\
&amp;amp; u_1 + 3u_2 \leq 0 \\
&amp;amp; u_1 \in \mathbb{R}, \quad u_2 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;c) Meaning:&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;\(u_1\): the marginal value of capital - how much the risk decreases if there is 1% more capital&lt;/li&gt;
    &lt;li&gt;\(u_2\): the value of relaxing the return constraint - the trade-off between return and risk&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; only stocks and bonds are needed: \(15x_1 + 8(1-x_1) = 10 \Rightarrow x_1 = 2/7\), so \(x^* = (2/7, 5/7, 0)\) with risk \(20(2/7) + 5(5/7) = 65/7 \approx 9.29\% \leq 12\%\) ✓ (the maximum-risk constraint of 12% is not active). Dual solution: \(u_1^* = -85/7\), \(u_2^* = 15/7 \approx 2.14\) (dual value \(-85/7 + 150/7 = 65/7\) ✓), meaning that raising the required return by 1% increases the risk by about 2.14%.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-ii-weak-and-strong-duality&quot;&gt;&lt;strong&gt;Part II: Weak and Strong Duality&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-4-weak-duality-boyd--vandenberghe-ex-55&quot;&gt;&lt;strong&gt;Exercise 4: Weak Duality (Boyd &amp;amp; Vandenberghe, Ex. 5.5)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the problem:&lt;/p&gt;

\[\begin{align}
\text{(P)} \quad \min_{x} \quad &amp;amp; 2x_1 + 3x_2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 \geq 4 \\
&amp;amp; 2x_1 + x_2 \geq 6 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Construct the dual problem (D)  &lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Let \(x = (3, 1)\). Check feasibility and find a feasible solution \(u\) of (D)  &lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Check \(c^Tx \geq b^Tu\) (weak duality)  &lt;br /&gt;
&lt;strong&gt;d)&lt;/strong&gt; Prove that \(x^* = (4, 0)\) is an optimal solution&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) The dual problem:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\text{(D)} \quad \max_{u} \quad &amp;amp; 4u_1 + 6u_2 \\
\text{s.t.} \quad &amp;amp; u_1 + 2u_2 \leq 2 \\
&amp;amp; u_1 + u_2 \leq 3 \\
&amp;amp; u_1, u_2 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Check \(x = (3, 1)\):&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Primal feasibility:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(3 + 1 = 4 \geq 4\) ✓&lt;/li&gt;
    &lt;li&gt;\(2(3) + 1 = 7 \geq 6\) ✓&lt;/li&gt;
    &lt;li&gt;\(x \geq 0\) ✓&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Primal value: \(f(x) = 2(3) + 3(1) = 9\)&lt;/p&gt;

  &lt;p&gt;Try \(u = (0, 1)\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(0 + 2(1) = 2 \leq 2\) ✓&lt;/li&gt;
    &lt;li&gt;\(0 + 1 = 1 \leq 3\) ✓&lt;/li&gt;
    &lt;li&gt;Dual value: \(g(u) = 4(0) + 6(1) = 6\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;c) Weak duality:&lt;/strong&gt;&lt;/p&gt;

\[c^Tx = 9 \geq 6 = b^Tu\]

  &lt;p&gt;✓ Satisfied!&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Prove that \(x^* = (4, 0)\) is optimal:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Check feasibility:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(4 + 0 = 4 \geq 4\) ✓ (active)&lt;/li&gt;
    &lt;li&gt;\(2(4) + 0 = 8 \geq 6\) ✓ (inactive, slack = 2)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Value: \(f(x^*) = 2(4) + 3(0) = 8\)&lt;/p&gt;

  &lt;p&gt;Find \(u^*\) satisfying complementary slackness: constraint 2 is inactive so \(u_2^* = 0\); \(x_1^* &amp;gt; 0\) so dual constraint 1 is active: \(u_1^* + 2u_2^* = 2 \Rightarrow u_1^* = 2\).&lt;/p&gt;

  &lt;p&gt;Check dual feasibility: \(u_1^* + u_2^* = 2 \leq 3\) ✓ (inactive, consistent with \(x_2^* = 0\)). Dual value: \(g(u^*) = 4(2) + 6(0) = 8 = f(x^*)\) ✓&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; \(x^* = (4, 0)\) is optimal (by weak duality, every feasible \(x\) has \(f(x) \geq g(u^*) = 8\)). Note that \((2,2)\) is feasible but \(f = 10 &amp;gt; 8\), so it is not optimal; \(x = (3,1)\) gives \(f = 9\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-5-strong-duality-boyd--vandenberghe-ex-56&quot;&gt;&lt;strong&gt;Exercise 5: Strong Duality (Boyd &amp;amp; Vandenberghe, Ex. 5.6)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho:&lt;/p&gt;

\[\begin{align}
\text{(P)} \quad \min_{x} \quad &amp;amp; x_1 + 2x_2 + x_3 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 = 3 \\
&amp;amp; x_2 + x_3 = 2 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Find the optimal solution algebraically  &lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Construct and solve the dual problem  &lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Compute the duality gap  &lt;br /&gt;
&lt;strong&gt;d)&lt;/strong&gt; Explain why strong duality holds&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Solve the primal:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;From the constraints: \(x_1 = 3 - x_2\), \(x_3 = 2 - x_2\)&lt;/p&gt;

  &lt;p&gt;Substitute into the objective:&lt;/p&gt;

\[f = (3 - x_2) + 2x_2 + (2 - x_2) = 5\]

  &lt;p&gt;The objective &lt;strong&gt;does not depend on \(x_2\)&lt;/strong&gt;! Optimal value: \(f^* = 5\)&lt;/p&gt;

  &lt;p&gt;Condition: \(0 \leq x_2 \leq 2\) (from \(x_3 \geq 0\))&lt;/p&gt;

  &lt;p&gt;Example solution: \(x^* = (2, 1, 1)\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;b) Dual:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; 3u_1 + 2u_2 \\
\text{s.t.} \quad &amp;amp; u_1 \leq 1 \\
&amp;amp; u_1 + u_2 \leq 2 \\
&amp;amp; u_2 \leq 1 \\
&amp;amp; u_1, u_2 \in \mathbb{R}
\end{align}\]

  &lt;p&gt;Maximize: choose \(u_1 = 1\), \(u_2 = 1\)&lt;/p&gt;

  &lt;p&gt;Check: \(1 \leq 1\) ✓, \(1 + 1 = 2 \leq 2\) ✓, \(1 \leq 1\) ✓&lt;/p&gt;

  &lt;p&gt;Value: \(g^* = 3(1) + 2(1) = 5\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Duality gap:&lt;/strong&gt;&lt;/p&gt;

\[\text{Gap} = f^* - g^* = 5 - 5 = 0\]

  &lt;p&gt;Strong duality holds! ✓&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Explanation:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;In LP, strong duality holds when one of the two problems has a finite optimal solution (then the other one also has an optimal solution and the two values are equal):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;If the primal is unbounded then the dual is infeasible (and vice versa)&lt;/li&gt;
    &lt;li&gt;Both problems can be infeasible at the same time&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;The Slater condition is automatically satisfied for a feasible LP.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-iii-complementary-slackness&quot;&gt;&lt;strong&gt;Part III: Complementary Slackness&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-6-applying-cs-bertsimas--tsitsiklis-ex-43&quot;&gt;&lt;strong&gt;Exercise 6: Applying CS (Bertsimas &amp;amp; Tsitsiklis, Ex. 4.3)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the problem and the following pairs of solutions:&lt;/p&gt;

\[\begin{align}
\text{(P)} \quad \min_{x} \quad &amp;amp; 3x_1 + 2x_2 \\
\text{s.t.} \quad &amp;amp; x_1 + x_2 \geq 4 \\
&amp;amp; 2x_1 + x_2 \geq 6 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Pairs of solutions:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;\(x = (2, 2)\), \(u = (1, 1)\)&lt;/li&gt;
  &lt;li&gt;\(x = (3, 1)\), \(u = (0, 3/2)\)&lt;/li&gt;
  &lt;li&gt;\(x = (0, 6)\), \(u = (0, 2)\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt; Check which pair is optimal using complementary slackness.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{u} \quad &amp;amp; 4u_1 + 6u_2 \\
\text{s.t.} \quad &amp;amp; u_1 + 2u_2 \leq 3 \\
&amp;amp; u_1 + u_2 \leq 2 \\
&amp;amp; u_1, u_2 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;Complementary slackness conditions:&lt;/strong&gt;&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;
\[u_1 \cdot [x_1 + x_2 - 4] = 0\]
    &lt;/li&gt;
    &lt;li&gt;
\[u_2 \cdot [2x_1 + x_2 - 6] = 0\]
    &lt;/li&gt;
    &lt;li&gt;
\[x_1 \cdot [u_1 + 2u_2 - 3] = 0\]
    &lt;/li&gt;
    &lt;li&gt;
\[x_2 \cdot [u_1 + u_2 - 2] = 0\]
    &lt;/li&gt;
  &lt;/ol&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Pair 1: \(x = (2,2)\), \(u = (1,1)\)&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Primal feasible:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(2 + 2 = 4 \geq 4\) ✓ (active)&lt;/li&gt;
    &lt;li&gt;\(4 + 2 = 6 \geq 6\) ✓ (active)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Dual feasible:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(1 + 2 = 3 \leq 3\) ✓ (active)&lt;/li&gt;
    &lt;li&gt;\(1 + 1 = 2 \leq 2\) ✓ (active)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Complementary slackness:&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;\(1 \cdot 0 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;\(1 \cdot 0 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;\(2 \cdot 0 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;\(2 \cdot 0 = 0\) ✓&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; Pair 1 is optimal! ✓✓✓&lt;/p&gt;

  &lt;p&gt;Value: \(f = 3(2) + 2(2) = 10 = 4(1) + 6(1) = g\) ✓&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Pair 2: \(x = (3,1)\), \(u = (0, 3/2)\)&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Primal: \(3+1=4\) ✓, \(6+1=7 &amp;gt; 6\) (slack = 1)&lt;/p&gt;

  &lt;p&gt;Dual: \(0+3=3\) ✓, \(0+3/2=3/2\) ✓&lt;/p&gt;

  &lt;p&gt;CS 2: \(u_2 \cdot [7-6] = (3/2)(1) = 3/2 \neq 0\) ✗&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; Not optimal!&lt;/p&gt;

  &lt;hr /&gt;

  &lt;p&gt;&lt;strong&gt;Pair 3: \(x = (0,6)\), \(u = (0,2)\)&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Dual: \(0 + 4 = 4 \not\leq 3\) ✗&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; The dual is infeasible!&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-7-shadow-prices-bertsimas--tsitsiklis-ex-47&quot;&gt;&lt;strong&gt;Exercise 7: Shadow Prices (Bertsimas &amp;amp; Tsitsiklis, Ex. 4.7)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The production problem has the optimal solution \(x^* = (40, 20)\) with:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Labor: \(2(40) + 20 = 100\) (active)&lt;/li&gt;
  &lt;li&gt;Machine: \(40 + 2(20) = 80\) (active)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Compute the shadow price of each resource  &lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; If one more labor hour can be bought for 12 thousand, is it worth buying?  &lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Sensitivity analysis when labor increases to 105 hours&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Compute the shadow prices:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Objective: \(\max 40x_1 + 30x_2\)&lt;/p&gt;

  &lt;p&gt;From complementary slackness (both constraints active, both variables positive):&lt;/p&gt;

\[\begin{cases}
2u_1 + u_2 = 40 \\
u_1 + 2u_2 = 30
\end{cases}\]

  &lt;p&gt;Solve the system:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;From (1): \(u_2 = 40 - 2u_1\)&lt;/li&gt;
    &lt;li&gt;Substitute into (2): \(u_1 + 2(40 - 2u_1) = 30\)&lt;/li&gt;
    &lt;li&gt;
\[u_1 + 80 - 4u_1 = 30\]
    &lt;/li&gt;
    &lt;li&gt;
\[-3u_1 = -50\]
    &lt;/li&gt;
    &lt;li&gt;
\[u_1 = 50/3 \approx 16.67\]
    &lt;/li&gt;
    &lt;li&gt;
\[u_2 = 40 - 2(50/3) = 40 - 100/3 = 20/3 \approx 6.67\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Shadow prices:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Labor: \(u_1^* = 16.67\) thousand VND/hour&lt;/li&gt;
    &lt;li&gt;Machine: \(u_2^* = 6.67\) thousand VND/hour&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;b) Purchase decision:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Purchase price: 12 thousand VND/hour  &lt;br /&gt;
Marginal value: \(u_1^* = 16.67\) thousand VND/hour&lt;/p&gt;

  &lt;p&gt;\(12 &amp;lt; 16.67\) → &lt;strong&gt;Worth buying&lt;/strong&gt; (a gain of 4.67 thousand/hour)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Sensitivity:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Increasing labor by 5 hours:&lt;/p&gt;

\[\Delta f \approx u_1^* \times 5 = 16.67 \times 5 = 83.35 \text{ thousand VND}\]

  &lt;p&gt;Current profit: \(40(40) + 30(20) = 2200\) thousand&lt;/p&gt;

  &lt;p&gt;New profit: \(2200 + 83.35 = 2283.35\) thousand VND&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;(Note: the shadow price is only exact within the sensitivity range)&lt;/em&gt;&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-iv-max-flow-and-min-cut&quot;&gt;&lt;strong&gt;Part IV: Max Flow and Min Cut&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-8-max-flow-problem-bertsimas--tsitsiklis-ex-72&quot;&gt;&lt;strong&gt;Exercise 8: Max Flow Problem (Bertsimas &amp;amp; Tsitsiklis, Ex. 7.2)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider a network with the following capacities:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    s --10--&amp;gt; a --8--&amp;gt; t
    |        / \       ^
    8      5    3     10
    |    /        \    |
    v  /            \  |
    b ---------------&amp;gt; c
          10
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Write the max flow problem as an LP  &lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Find a feasible flow  &lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Find a cut and compute its capacity  &lt;br /&gt;
&lt;strong&gt;d)&lt;/strong&gt; Verify: flow value \(\leq\) cut capacity&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Max Flow LP:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Variables: \(f_{ij}\) is the flow on arc \((i,j)\)&lt;/p&gt;

\[\begin{align}
\max \quad &amp;amp; f_{sa} + f_{sb} \\
\text{s.t.} \quad &amp;amp; f_{sa} - f_{ab} - f_{at} - f_{ac} = 0 \quad \text{(node a)} \\
&amp;amp; f_{sb} + f_{ab} - f_{bc} = 0 \quad \text{(node b)} \\
&amp;amp; f_{ac} + f_{bc} - f_{ct} = 0 \quad \text{(node c)} \\
&amp;amp; 0 \leq f_{sa} \leq 10, \quad 0 \leq f_{sb} \leq 8 \\
&amp;amp; 0 \leq f_{at} \leq 8, \quad 0 \leq f_{ab} \leq 5 \\
&amp;amp; 0 \leq f_{ac} \leq 3, \quad 0 \leq f_{bc} \leq 10 \\
&amp;amp; 0 \leq f_{ct} \leq 10
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Feasible flow:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Try:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(f_{sa} = 10\), \(f_{sb} = 8\)&lt;/li&gt;
    &lt;li&gt;\(f_{at} = 8\), \(f_{ab} = 0\), \(f_{ac} = 2\)&lt;/li&gt;
    &lt;li&gt;\(f_{bc} = 8\), \(f_{ct} = 10\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Check conservation:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Node a: \(10 - 0 - 8 - 2 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;Node b: \(8 + 0 - 8 = 0\) ✓&lt;/li&gt;
    &lt;li&gt;Node c: \(2 + 8 - 10 = 0\) ✓&lt;/li&gt;
  &lt;/ul&gt;

  &lt;table&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;Flow value: $$&lt;/td&gt;
        &lt;td&gt;f&lt;/td&gt;
        &lt;td&gt;= 10 + 8 = 18$$&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

  &lt;p&gt;&lt;strong&gt;c) Cut:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Cut \(S = \{s\}\), \(T = \{a,b,c,t\}\):&lt;/p&gt;

  &lt;p&gt;Arcs from \(S\) to \(T\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\((s,a)\): capacity 10&lt;/li&gt;
    &lt;li&gt;\((s,b)\): capacity 8&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Capacity: \(C(S,T) = 10 + 8 = 18\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Verification:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Flow value = 18 = cut capacity&lt;/p&gt;

  &lt;p&gt;By the Max-Flow Min-Cut theorem: this is a maximum flow and a minimum cut! ✓&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-v-matrix-games&quot;&gt;&lt;strong&gt;Part V: Matrix Games&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-9-zero-sum-game-dantzig-ex-81&quot;&gt;&lt;strong&gt;Exercise 9: Zero-Sum Game (Dantzig, Ex. 8.1)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Payoff matrix (from the row player’s perspective):&lt;/p&gt;

\[P = \begin{bmatrix}
3 &amp;amp; -1 &amp;amp; 2 \\
1 &amp;amp; 4 &amp;amp; -2 \\
0 &amp;amp; 2 &amp;amp; 3
\end{bmatrix}\]

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Check for a pure Nash equilibrium  &lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Write the LP for the mixed strategy (row player)  &lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Write the dual LP (column player)  &lt;br /&gt;
&lt;strong&gt;d)&lt;/strong&gt; Explain the value of the game&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Pure Nash equilibrium:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Find the minimum of each row:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Row 1: \(\min\{3, -1, 2\} = -1\)&lt;/li&gt;
    &lt;li&gt;Row 2: \(\min\{1, 4, -2\} = -2\)&lt;/li&gt;
    &lt;li&gt;Row 3: \(\min\{0, 2, 3\} = 0\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Maxmin: \(\max\{-1, -2, 0\} = 0\) (row 3)&lt;/p&gt;

  &lt;p&gt;Find the maximum of each column:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Column 1: \(\max\{3, 1, 0\} = 3\)&lt;/li&gt;
    &lt;li&gt;Column 2: \(\max\{-1, 4, 2\} = 4\)&lt;/li&gt;
    &lt;li&gt;Column 3: \(\max\{2, -2, 3\} = 3\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Minmax: \(\min\{3, 4, 3\} = 3\)&lt;/p&gt;

  &lt;p&gt;\(\text{Maxmin} \neq \text{Minmax}\) → &lt;strong&gt;There is no pure Nash equilibrium&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;b) LP for the row player:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Maximize guaranteed payoff \(v\):&lt;/p&gt;

\[\begin{align}
\max_{x, v} \quad &amp;amp; v \\
\text{s.t.} \quad &amp;amp; 3x_1 + x_2 + 0x_3 \geq v \\
&amp;amp; -x_1 + 4x_2 + 2x_3 \geq v \\
&amp;amp; 2x_1 - 2x_2 + 3x_3 \geq v \\
&amp;amp; x_1 + x_2 + x_3 = 1 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;c) LP for the column player:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Minimize max loss \(u\):&lt;/p&gt;

\[\begin{align}
\min_{y, u} \quad &amp;amp; u \\
\text{s.t.} \quad &amp;amp; 3y_1 - y_2 + 2y_3 \leq u \\
&amp;amp; y_1 + 4y_2 - 2y_3 \leq u \\
&amp;amp; 0y_1 + 2y_2 + 3y_3 \leq u \\
&amp;amp; y_1 + y_2 + y_3 = 1 \\
&amp;amp; y_1, y_2, y_3 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;d) Value of the game:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Theo Von Neumann minimax theorem:&lt;/p&gt;

\[v^* = \max_x \min_y x^T P y = \min_y \max_x x^T P y\]

  &lt;p&gt;This value is the Nash equilibrium in mixed strategies.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Experiment:&lt;/strong&gt; \(x = y = (1/3, 1/3, 1/3)\)&lt;/p&gt;

  &lt;p&gt;Expected payoff for each column:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Column 1: \((1/3)(3+1+0) = 4/3\)&lt;/li&gt;
    &lt;li&gt;Column 2: \((1/3)(-1+4+2) = 5/3\)&lt;/li&gt;
    &lt;li&gt;Column 3: \((1/3)(2-2+3) = 1\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Min = 1, so \(v^* \geq 1\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Optimal solution (solving the LP):&lt;/strong&gt; \(x^* = (3/8, 1/4, 3/8)\), \(y^* = (17/40, 7/20, 9/40)\), \(v^* = 11/8 = 1.375\). Check: with \(x^*\), the payoff of every column equals \(\frac{11}{8}\) (column 1: \(\frac{9}{8}+\frac{2}{8}\); column 2: \(-\frac{3}{8}+\frac{8}{8}+\frac{6}{8}\); column 3: \(\frac{6}{8}-\frac{4}{8}+\frac{9}{8}\)). Note that \(\text{Maxmin} = 0 &amp;lt; v^* = 1.375 &amp;lt; \text{Minmax} = 3\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;part-vi-advanced-exercises-from-boyd--vandenberghe&quot;&gt;&lt;strong&gt;Part VI: Advanced Exercises from Boyd &amp;amp; Vandenberghe&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-10-robust-lp-boyd--vandenberghe-ex-511&quot;&gt;&lt;strong&gt;Exercise 10: Robust LP (Boyd &amp;amp; Vandenberghe, Ex. 5.11)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider an LP with uncertain coefficients:&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; c^T x \\
\text{s.t.} \quad &amp;amp; a_i^T x \leq b_i, \quad i = 1, \ldots, m \\
&amp;amp; x \geq 0
\end{align}\]

&lt;p&gt;where \(a_i\) may vary within an ellipsoid: \(\{a_i + P_i u : \|u\| \leq 1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;  &lt;br /&gt;
a) Write the equivalent robust problem  &lt;br /&gt;
b) Show that this is an SOCP (no longer a pure LP)  &lt;br /&gt;
c) Construct the dual problem&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Robust formulation:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;The robust constraint requires:&lt;/p&gt;

\[(a_i + P_i u)^T x \leq b_i, \quad \forall \|u\| \leq 1\]

  &lt;p&gt;Equivalently:&lt;/p&gt;

\[a_i^T x + \max_{\|u\| \leq 1} u^T P_i^T x \leq b_i\]

  &lt;p&gt;Theo Cauchy-Schwarz:&lt;/p&gt;

\[\max_{\|u\| \leq 1} u^T P_i^T x = \|P_i^T x\|\]

  &lt;p&gt;Hence the robust constraint is:&lt;/p&gt;

\[a_i^T x + \|P_i^T x\| \leq b_i\]

  &lt;p&gt;&lt;strong&gt;b) This is an SOCP, not an LP:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;The equivalent form is an SOCP (Second-Order Cone Program):&lt;/p&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; c^T x \\
\text{s.t.} \quad &amp;amp; a_i^T x + \|P_i^T x\| \leq b_i, \quad i = 1, \ldots, m \\
&amp;amp; x \geq 0
\end{align}\]

  &lt;p&gt;If \(P_i = 0\) (no uncertainty), we recover an ordinary LP.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) The dual problem:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Using SOCP duality, the dual problem is rather complicated and is no longer a pure LP.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-11-chebyshev-center-boyd--vandenberghe-ex-85&quot;&gt;&lt;strong&gt;Exercise 11: Chebyshev Center (Boyd &amp;amp; Vandenberghe, Ex. 8.5)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Find the point \(x_c\) and the largest radius \(r\) such that the ball \(\{x : \|x - x_c\| \leq r\}\) lies inside the polyhedron \(\{x : a_i^T x \leq b_i, i = 1, \ldots, m\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;  &lt;br /&gt;
a) Write the optimization problem  &lt;br /&gt;
b) Show that this is an LP  &lt;br /&gt;
c) Solve for a specific polyhedron&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) Formulation:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;The condition for the ball to lie inside the polyhedron:&lt;/p&gt;

\[a_i^T x \leq b_i, \quad \forall x : \|x - x_c\| \leq r\]

  &lt;p&gt;Equivalently:&lt;/p&gt;

\[\max_{\|x - x_c\| \leq r} a_i^T x \leq b_i\]

\[a_i^T x_c + r\|a_i\| \leq b_i\]

  &lt;p&gt;&lt;strong&gt;The problem:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{x_c, r} \quad &amp;amp; r \\
\text{s.t.} \quad &amp;amp; a_i^T x_c + r\|a_i\| \leq b_i, \quad i = 1, \ldots, m
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Proof that it is an LP:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;This is an LP in the variables \((x_c, r)\). The coefficients \(\|a_i\|\) are constants.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) A concrete example:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Given the polyhedron:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[x_1 + x_2 \leq 4\]
    &lt;/li&gt;
    &lt;li&gt;
\[x_1 - x_2 \leq 2\]
    &lt;/li&gt;
    &lt;li&gt;
\[-x_1 + x_2 \leq 2\]
    &lt;/li&gt;
    &lt;li&gt;
\[-x_1 - x_2 \leq 2\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;LP:&lt;/p&gt;

\[\begin{align}
\max \quad &amp;amp; r \\
\text{s.t.} \quad &amp;amp; x_{c1} + x_{c2} + r\sqrt{2} \leq 4 \\
&amp;amp; x_{c1} - x_{c2} + r\sqrt{2} \leq 2 \\
&amp;amp; -x_{c1} + x_{c2} + r\sqrt{2} \leq 2 \\
&amp;amp; -x_{c1} - x_{c2} + r\sqrt{2} \leq 2
\end{align}\]

  &lt;p&gt;Solving (by hand or with a solver): \(r\sqrt{2} = 2\), i.e. \(r = \sqrt{2} \approx 1.414\), with center \(x_c = (t, t)\), \(0 \leq t \leq 1\) (e.g. \(x_c = (0, 0)\)); the solution is not unique because constraint 1 is not active. Check with \(x_c = (0,0)\): the left-hand sides of the 4 constraints equal \(2, 2, 2, 2\), i.e. \(\leq 4, 2, 2, 2\) ✓ (constraints 2, 3, 4 are active).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exercise-12-resource-allocation&quot;&gt;&lt;strong&gt;Exercise 12: Resource Allocation&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;A company makes 3 products:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Product&lt;/th&gt;
      &lt;th&gt;Profit&lt;/th&gt;
      &lt;th&gt;Labor&lt;/th&gt;
      &lt;th&gt;Machine&lt;/th&gt;
      &lt;th&gt;Material&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;A&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;B&lt;/td&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;C&lt;/td&gt;
      &lt;td&gt;6&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Resources: 100 labor hours, 80 machine hours, 90 kg of material. At the optimal plan all three products are produced and all three resources are used up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Write the LP and its dual.&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Find the optimal production plan and the shadow price of each resource.&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Is it worth buying 10 more labor hours (1.5 million per hour) or 10 more kg of material (1 million per kg)?&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;a) LP:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\max_{x} \quad &amp;amp; 5x_1 + 4x_2 + 6x_3 \\
\text{s.t.} \quad &amp;amp; 2x_1 + x_2 + 3x_3 \leq 100 \\
&amp;amp; x_1 + 2x_2 + 2x_3 \leq 80 \\
&amp;amp; 3x_1 + 2x_2 + x_3 \leq 90 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\min_{u} \quad &amp;amp; 100u_1 + 80u_2 + 90u_3 \\
\text{s.t.} \quad &amp;amp; 2u_1 + u_2 + 3u_3 \geq 5 \\
&amp;amp; u_1 + 2u_2 + 2u_3 \geq 4 \\
&amp;amp; 3u_1 + 2u_2 + u_3 \geq 6 \\
&amp;amp; u_1, u_2, u_3 \geq 0
\end{align}\]

  &lt;p&gt;&lt;strong&gt;b) Optimal plan and shadow prices:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;All three resource constraints are tight, so \(x^*\) solves \(Ax = b\):&lt;/p&gt;

\[x^* = \left(\tfrac{160}{11}, \tfrac{150}{11}, \tfrac{210}{11}\right) \approx (14.55,\ 13.64,\ 19.09), \qquad 5x_1 + 4x_2 + 6x_3 = \tfrac{2660}{11} \approx 241.82\]

  &lt;p&gt;Labor check: \(2 \cdot 160 + 150 + 3 \cdot 210 = 1100\), divided by 11 gives 100 ✓.&lt;/p&gt;

  &lt;p&gt;Since \(x_1, x_2, x_3 &amp;gt; 0\), complementary slackness makes all three dual constraints tight:&lt;/p&gt;

\[\begin{cases}
2u_1 + u_2 + 3u_3 = 5 \\
u_1 + 2u_2 + 2u_3 = 4 \\
3u_1 + 2u_2 + u_3 = 6
\end{cases}
\quad\Longrightarrow\quad
u^* = \left(\tfrac{14}{11}, \tfrac{9}{11}, \tfrac{6}{11}\right) \approx (1.27,\ 0.82,\ 0.55)\]

  &lt;p&gt;Check: \(100u_1 + 80u_2 + 90u_3 = \tfrac{1400 + 720 + 540}{11} = \tfrac{2660}{11}\), equal to the primal optimum ✓ (strong duality). All \(u_i \ge 0\), so \(u^*\) is feasible.&lt;/p&gt;

  &lt;p&gt;Meaning: one more labor hour adds about 1.27 to profit, one more machine hour about 0.82, one more kg of material about 0.55.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Decision:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Shadow prices are valid only while the optimal basis stays the same. With \(A^{-1} = \tfrac{1}{11}\begin{pmatrix} 2 &amp;amp; -5 &amp;amp; 4 \\ -5 &amp;amp; 7 &amp;amp; 1 \\ 4 &amp;amp; 1 &amp;amp; -3 \end{pmatrix}\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;10 more labor hours: \(x = A^{-1}(110, 80, 90) = \left(\tfrac{180}{11}, \tfrac{100}{11}, \tfrac{250}{11}\right) &amp;gt; 0\), same basis.&lt;/li&gt;
    &lt;li&gt;10 more kg of material: \(x = A^{-1}(100, 80, 100) = \left(\tfrac{200}{11}, \tfrac{160}{11}, \tfrac{180}{11}\right) &amp;gt; 0\), same basis.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Option 1 (labor):&lt;/strong&gt; profit rises by \(10 \cdot \tfrac{14}{11} \approx 12.7\) million at a cost of 15 million, &lt;strong&gt;a loss of about 2.3 million&lt;/strong&gt;.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Option 2 (material):&lt;/strong&gt; profit rises by \(10 \cdot \tfrac{6}{11} \approx 5.5\) million at a cost of 10 million, &lt;strong&gt;a loss of about 4.5 million&lt;/strong&gt;.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; both purchase prices exceed the shadow prices, so neither purchase is worth it. If one must be chosen, option 1 loses less.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;summary-and-strategy&quot;&gt;&lt;strong&gt;Summary and Strategy&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;constructing-the-dual&quot;&gt;&lt;strong&gt;Constructing the dual:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Identify the problem type (min/max, constraints)&lt;/li&gt;
  &lt;li&gt;Apply the corresponding primal-dual rules&lt;/li&gt;
  &lt;li&gt;Number of dual variables = number of primal constraints&lt;/li&gt;
  &lt;li&gt;Number of dual constraints = number of primal variables&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;checking-optimality&quot;&gt;&lt;strong&gt;Checking optimality:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Primal + Dual feasibility&lt;/li&gt;
  &lt;li&gt;Complementary slackness: \(u_i(a_i^T x - b_i) = 0\)&lt;/li&gt;
  &lt;li&gt;Compare values: \(f^* = g^*\) (strong duality)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;shadow-price&quot;&gt;&lt;strong&gt;Shadow price:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Marginal value of a resource&lt;/li&gt;
  &lt;li&gt;Only exact within the sensitivity range&lt;/li&gt;
  &lt;li&gt;Slack &amp;gt; 0 → shadow price = 0&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;max-flow---min-cut&quot;&gt;&lt;strong&gt;Max Flow - Min Cut:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Flow conservation at intermediate nodes&lt;/li&gt;
  &lt;li&gt;Flow value \(\leq\) cut capacity (weak duality)&lt;/li&gt;
  &lt;li&gt;If equal → both are optimal (strong duality)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;matrix-games&quot;&gt;&lt;strong&gt;Matrix Games:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Check for a saddle point first&lt;/li&gt;
  &lt;li&gt;If there is none, solve an LP for the mixed strategy&lt;/li&gt;
  &lt;li&gt;Von Neumann minimax: \(\max_x \min_y = \min_y \max_x\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 5: Duality.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bertsimas, D., &amp;amp; Tsitsiklis, J. N.&lt;/strong&gt; (1997). &lt;em&gt;Introduction to Linear Optimization&lt;/em&gt;. Athena Scientific. Chapters 4, 7.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Dantzig, G. B.&lt;/strong&gt; (1963). &lt;em&gt;Linear Programming and Extensions&lt;/em&gt;. Princeton University Press. Chapters 5-8.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Luenberger, D. G., &amp;amp; Ye, Y.&lt;/strong&gt; (2008). &lt;em&gt;Linear and Nonlinear Programming&lt;/em&gt; (3rd ed.). Springer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Vanderbei, R. J.&lt;/strong&gt; (2020). &lt;em&gt;Linear Programming: Foundations and Extensions&lt;/em&gt; (5th ed.). Springer.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The exercises are arranged from basic to advanced and are drawn directly from classic textbooks. Practice them thoroughly to master duality in LP!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>10-08 Multiple-Choice Quiz - Duality in Linear Programming</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_08_Quiz_LP_Duality/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_08_Quiz_LP_Duality</id>
   <content type="html">&lt;p&gt;Before you jump into the Chapter 10 multiple-choice quiz, run a quick mental check on the sign rules and structural theorems of LP duality. Most quiz mistakes come from flipping a sign on \(Gx \le h\) vs. \(Gx \ge h\), forgetting that an unbounded primal forces an infeasible dual (while an infeasible primal can have &lt;em&gt;either&lt;/em&gt; an unbounded or infeasible dual!), or losing track of how max-flow and matrix games dualize. Use the four pillars and quick dual-check below to lock everything in place.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-chapter-10-quiz-readiness-pillars&quot;&gt;Key ideas: Chapter 10 Quiz Readiness Pillars&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Mechanical Dualization Dictionary:&lt;/strong&gt; For a minimization primal: \(=\) constraint \(\leftrightarrow\) free dual variable; \(\le\) constraint \(\leftrightarrow\) \(u \ge 0\) (in \(-h^\top u\)) or \(y \le 0\) (in \(h^\top y\)); free primal variable \(\leftrightarrow\) equality dual constraint; \(x \ge 0\) \(\leftrightarrow\) inequality dual constraint.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Weak, Strong, and Infeasibility Outcomes:&lt;/strong&gt; Weak duality (\(d^\star \le p^\star\)) &lt;em&gt;always&lt;/em&gt; holds. Strong duality (\(d^\star = p^\star\)) holds whenever either primal or dual is feasible and bounded. Remember the one-way trap: primal infeasible does &lt;em&gt;not&lt;/em&gt; automatically imply dual unbounded (both can be infeasible!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Complementary Slackness Preview:&lt;/strong&gt; At any optimal pair \((x^\star, u^\star)\), every strictly slack primal inequality (\((Gx^\star)_i &amp;lt; h_i\)) must have zero dual price (\(u_i^\star = 0\)), and every strictly positive dual variable (\(u_i^\star &amp;gt; 0\)) forces its primal constraint to be tight.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Canonical Applications:&lt;/strong&gt; Max-flow dualizes to min-cut (via node potentials \(b_i\) and edge weights \(a_{ij}\)); zero-sum matrix games dualize player \(J\)’s minimax LP into player \(R\)’s maximin LP (proving von Neumann’s theorem).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-spot-checking-a-primaldual-pair-for-optimality&quot;&gt;Worked example: Spot-Checking a Primal–Dual Pair for Optimality&lt;/h3&gt;

&lt;p&gt;Primal \((P)\): \(\min 5x_1 + 4x_2\) s.t. \(x_1 + x_2 \ge 3\), \(2x_1 + x_2 \ge 4\), \(x_1, x_2 \ge 0\).
Dual \((D)\): \(\max 3y_1 + 4y_2\) s.t. \(y_1 + 2y_2 \le 5\), \(y_1 + y_2 \le 4\), \(y_1, y_2 \ge 0\).
Someone proposes \(x = (1, 2)^\top\) and \(y = (3, 1)^\top\). Are they optimal?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check primal feasibility of \(x = (1, 2)^\top\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(1 + 2 = 3 \ge 3\) (tight!), \(2(1) + 2 = 4 \ge 4\) (tight!), \(x \ge 0\). Feasible!&lt;/li&gt;
      &lt;li&gt;Primal objective: \(5(1) + 4(2) = 13\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check dual feasibility of \(y = (3, 1)^\top\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(3 + 2(1) = 5 \le 5\) (tight!), \(3 + 1 = 4 \le 4\) (tight!), \(y \ge 0\). Feasible!&lt;/li&gt;
      &lt;li&gt;Dual objective: \(3(3) + 4(1) = 13\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclude by Weak Duality:&lt;/strong&gt; Since \(x\) is primal feasible, \(y\) is dual feasible, and \(c^\top x = 13 = b^\top y\), &lt;strong&gt;both&lt;/strong&gt; \(x = (1, 2)^\top\) and \(y = (3, 1)^\top\) are certified globally optimal—zero simplex pivots required!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;theory-review&quot;&gt;Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;duality-in-linear-programming-lp-duality&quot;&gt;&lt;strong&gt;Duality in Linear Programming (LP Duality)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;basic-idea&quot;&gt;&lt;strong&gt;Basic idea&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;LP duality arises from looking for a &lt;strong&gt;lower bound&lt;/strong&gt; on the optimal value of the primal problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Principle:&lt;/strong&gt; If the objective can be written as a &lt;strong&gt;linear combination&lt;/strong&gt; of the constraints, we obtain a lower bound.&lt;/p&gt;

&lt;h4 id=&quot;from-simple-examples-to-the-general-case&quot;&gt;&lt;strong&gt;From simple examples to the general case&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt; The constraint contains the objective
\(\min_{x,y} x + y \quad \text{s.t.} \quad x + y \ge 2, \quad x,y \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Obvious lower bound:&lt;/strong&gt; \(B = 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt; Writing the objective as a linear combination
\(\min_{x,y} x + 3y \quad \text{s.t.} \quad x + y \ge 2, \quad x,y \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linear combination:&lt;/strong&gt;
\(1 \cdot (x + y) + 0 \cdot x + 2 \cdot y = x + 3y \ge 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lower bound:&lt;/strong&gt; \(B = 2\)&lt;/p&gt;

&lt;h3 id=&quot;-constructing-the-dual-problem&quot;&gt;📏 &lt;strong&gt;Constructing the Dual Problem&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;general-primal-problem&quot;&gt;&lt;strong&gt;General primal problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x c^T x \quad \text{s.t.} \quad Ax = b, \quad Gx \le h\)&lt;/p&gt;

&lt;h4 id=&quot;method-for-constructing-the-dual&quot;&gt;&lt;strong&gt;Method for constructing the dual&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Define dual variables:&lt;/strong&gt; \(u\) (for equality constraints), \(v \ge 0\) (for inequality constraints)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form a linear combination:&lt;/strong&gt; \(u^T(Ax - b) + v^T(Gx - h) \le 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rearrange to isolate the objective:&lt;/strong&gt; \((-A^T u - G^T v)^T x \ge -b^T u - h^T v\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matching condition:&lt;/strong&gt; \(c = -A^T u - G^T v\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;the-dual-problem&quot;&gt;&lt;strong&gt;The dual problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max_{u,v} -b^T u - h^T v \quad \text{s.t.} \quad c = -A^T u - G^T v, \quad v \ge 0\)&lt;/p&gt;

&lt;h3 id=&quot;-primal-dual-conversion-rules&quot;&gt;🔄 &lt;strong&gt;Primal-Dual Conversion Rules&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;strong&gt;Primal&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Dual&lt;/strong&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;\(\min\)&lt;/td&gt;
      &lt;td&gt;\(\max\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(Ax = b\)&lt;/td&gt;
      &lt;td&gt;\(u\) unconstrained&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(Gx \le h\)&lt;/td&gt;
      &lt;td&gt;\(v \ge 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(x \ge 0\)&lt;/td&gt;
      &lt;td&gt;Inequality constraint in the dual&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(x\) unconstrained&lt;/td&gt;
      &lt;td&gt;Equality constraint in the dual&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h4 id=&quot;conversion-example&quot;&gt;&lt;strong&gt;Conversion example&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Primal:&lt;/strong&gt;
\(\min_{x,y} px + qy \quad \text{s.t.} \quad x \ge 0, \quad y \le 1, \quad 3x + y = 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt;
\(\max_{a,b,c} 2c - b \quad \text{s.t.} \quad a + 3c = p, \quad -b + c = q, \quad a,b \ge 0\)&lt;/p&gt;

&lt;h3 id=&quot;-example-max-flow---min-cut&quot;&gt;🌊 &lt;strong&gt;Example: Max Flow - Min Cut&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;the-max-flow-problem&quot;&gt;&lt;strong&gt;The Max Flow problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Find the maximum flow from the source \(s\) to the sink \(t\) in a directed graph.&lt;/p&gt;

\[\max \sum_{(s,j) \in E} f_{sj} \quad \text{s.t.} \begin{cases}
f_{ij} \ge 0, \quad f_{ij} \le c_{ij} &amp;amp; \forall (i,j) \in E \\
\sum_{(i,k) \in E} f_{ik} = \sum_{(k,j) \in E} f_{kj} &amp;amp; \forall k \in V \setminus \{s,t\}
\end{cases}\]

&lt;h4 id=&quot;the-min-cut-problem&quot;&gt;&lt;strong&gt;The Min Cut problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Find a cut of minimum capacity separating \(s\) and \(t\).&lt;/p&gt;

\[\min \sum_{(i,j) \in E} b_{ij} c_{ij} \quad \text{s.t.} \begin{cases}
b_{ij} \ge x_i - x_j &amp;amp; \forall (i,j) \in E \\
x_i, b_{ij} \in \{0,1\} &amp;amp; \forall i,j \\
x_s = 1, x_t = 0
\end{cases}\]

&lt;h4 id=&quot;dual-relationship&quot;&gt;&lt;strong&gt;Dual relationship&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Dual of Max Flow = LP relaxation of Min Cut&lt;/strong&gt;&lt;/p&gt;

\[\text{Max Flow Value} \le \text{Dual LP} = \text{LP Relaxed Min Cut} \le \text{Min Cut Capacity}\]

&lt;p&gt;&lt;strong&gt;Max-Flow Min-Cut theorem:&lt;/strong&gt; All three values are equal!&lt;/p&gt;

&lt;h3 id=&quot;lagrangian-approach&quot;&gt;&lt;strong&gt;Lagrangian Approach&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;the-lagrangian&quot;&gt;&lt;strong&gt;The Lagrangian&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;For the general optimization problem:
\(\min_x f(x) \quad \text{s.t.} \quad Ax = b, \quad Gx \le h\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lagrangian function:&lt;/strong&gt;
\(L(x,u,v) = f(x) + u^T(Ax - b) + v^T(Gx - h)\)&lt;/p&gt;

&lt;h4 id=&quot;dual-function&quot;&gt;&lt;strong&gt;Dual function&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(g(u,v) = \min_x L(x,u,v)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; \(g(u,v) \le f^*\) for all \(v \ge 0\) (weak duality)&lt;/p&gt;

&lt;h4 id=&quot;the-lagrangian-dual-problem&quot;&gt;&lt;strong&gt;The Lagrangian dual problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\max_{u,v} g(u,v) \quad \text{s.t.} \quad v \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;for-lp&quot;&gt;&lt;strong&gt;For LP:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(g(u,v) = \min_x (c + A^T u + G^T v)^T x - b^T u - h^T v\)&lt;/p&gt;

\[= \begin{cases}
-b^T u - h^T v &amp;amp; \text{if } c + A^T u + G^T v = 0 \\
-\infty &amp;amp; \text{otherwise}
\end{cases}\]

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; The same as the classical LP dual!&lt;/p&gt;

&lt;h3 id=&quot;-matrix-games&quot;&gt;🎮 &lt;strong&gt;Matrix Games&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;game-setup&quot;&gt;&lt;strong&gt;Game setup&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Two players:&lt;/strong&gt; J (rows) and R (columns)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Payout matrix:&lt;/strong&gt; \(P\) (J pays R)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mixed strategies:&lt;/strong&gt; \(x\) (J), \(y\) (R)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Expected payout:&lt;/strong&gt; \(x^T P y\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;js-perspective-minimizer&quot;&gt;&lt;strong&gt;J’s perspective (minimizer)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;R gets to know J’s strategy in advance, so J wants to minimize the worst-case expected payout:
\(\min_x \max_{i=1,\ldots,n} (P^T x)_i \quad \text{s.t.} \quad x \ge 0, \quad \mathbf{1}^T x = 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reformulation:&lt;/strong&gt;
\(\min_{x,t} t \quad \text{s.t.} \quad x \ge 0, \quad \mathbf{1}^T x = 1, \quad P^T x \preceq t \mathbf{1}\)&lt;/p&gt;

&lt;h4 id=&quot;rs-perspective-maximizer&quot;&gt;&lt;strong&gt;R’s perspective (maximizer)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;J gets to know R’s strategy in advance, so R wants to maximize the worst-case expected payout:
\(\max_y \min_{j=1,\ldots,m} (Py)_j \quad \text{s.t.} \quad y \ge 0, \quad \mathbf{1}^T y = 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reformulation:&lt;/strong&gt;
\(\max_{y,v} v \quad \text{s.t.} \quad y \ge 0, \quad \mathbf{1}^T y = 1, \quad Py \succeq v \mathbf{1}\)&lt;/p&gt;

&lt;h4 id=&quot;von-neumanns-minimax-theorem&quot;&gt;&lt;strong&gt;Von Neumann’s Minimax Theorem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The two problems above are &lt;strong&gt;primal-dual&lt;/strong&gt; to each other and have the same optimal value:
\(\min_x \max_y x^T P y = \max_y \min_x x^T P y\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reason:&lt;/strong&gt; \(x^T P y\) is bilinear (convex in \(x\), concave in \(y\)) and the simplices are compact and convex; moreover this is a pair of dual LPs, so strong duality always holds.&lt;/p&gt;

&lt;h3 id=&quot;weak-vs-strong-duality&quot;&gt;&lt;strong&gt;Weak vs Strong Duality&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;weak-duality&quot;&gt;&lt;strong&gt;Weak Duality&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Always true:&lt;/strong&gt; Dual value ≤ Primal value
\(\max_{u,v} g(u,v) \le \min_x f(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Duality gap:&lt;/strong&gt; \(f^* - g^* \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;strong-duality&quot;&gt;&lt;strong&gt;Strong Duality&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Special condition:&lt;/strong&gt; Dual value = Primal value
\(\max_{u,v} g(u,v) = \min_x f(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Duality gap:&lt;/strong&gt; \(f^* - g^* = 0\)&lt;/p&gt;

&lt;h4 id=&quot;when-strong-duality-holds-in-lp&quot;&gt;&lt;strong&gt;When Strong Duality holds in LP:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Slater’s condition:&lt;/strong&gt; A strictly feasible point exists&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;For LP:&lt;/strong&gt; If either the primal or the dual is feasible, strong duality holds&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exception:&lt;/strong&gt; Both primal and dual are infeasible&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-standard-forms-of-lp&quot;&gt;🔄 &lt;strong&gt;Standard Forms of LP&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;standard-form&quot;&gt;&lt;strong&gt;Standard form&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min c^T x \quad \text{s.t.} \quad Ax = b, \quad x \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt;
\(\max b^T u \quad \text{s.t.} \quad A^T u \le c\)&lt;/p&gt;

&lt;h4 id=&quot;inequality-form&quot;&gt;&lt;strong&gt;Inequality form&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min c^T x \quad \text{s.t.} \quad Ax \le b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt;
\(\max -b^T u \quad \text{s.t.} \quad A^T u = -c, \quad u \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;general-form&quot;&gt;&lt;strong&gt;General form&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min c^T x \quad \text{s.t.} \quad Ax = b, \quad Gx \le h\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt;
\(\max -b^T u - h^T v \quad \text{s.t.} \quad -A^T u - G^T v = c, \quad v \ge 0\)&lt;/p&gt;

&lt;h3 id=&quot;️-practical-techniques&quot;&gt;🛠️ &lt;strong&gt;Practical Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;building-the-dual-from-the-primal&quot;&gt;&lt;strong&gt;Building the dual from the primal:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify the problem type:&lt;/strong&gt; Min or max, equality or inequality constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the conversion rules:&lt;/strong&gt; Following the primal-dual table&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check correctness:&lt;/strong&gt; Weak duality must hold&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find strong duality conditions:&lt;/strong&gt; Slater’s condition or feasibility&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;economic-interpretation&quot;&gt;&lt;strong&gt;Economic interpretation:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal variables:&lt;/strong&gt; Production decisions, resource allocation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual variables:&lt;/strong&gt; Shadow prices, marginal values of the constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duality gap:&lt;/strong&gt; The difference between the upper and lower bounds&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;practical-applications&quot;&gt;&lt;strong&gt;Practical applications:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Network flows:&lt;/strong&gt; Internet routing, transportation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Game theory:&lt;/strong&gt; Strategic decision making, auction design&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Economics:&lt;/strong&gt; Market equilibrium, resource allocation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; SVM dual formulation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;illustrative-example&quot;&gt;&lt;strong&gt;Illustrative Example&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;simple-problem&quot;&gt;&lt;strong&gt;Simple problem:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Primal:&lt;/strong&gt;
\(\min 2x_1 + 3x_2 \quad \text{s.t.} \quad x_1 + x_2 \ge 1, \quad x_1, x_2 \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt;
\(\max u \quad \text{s.t.} \quad u \le 2, \quad u \le 3, \quad u \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal optimal:&lt;/strong&gt; \(x_1^* = 1, x_2^* = 0\), \(f^* = 2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual optimal:&lt;/strong&gt; \(u^* = 2\), \(g^* = 2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; \(f^* = g^* = 2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;complementary-slackness&quot;&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(x_1^* &amp;gt; 0 \Rightarrow u^* = 2\) (tight)&lt;/li&gt;
  &lt;li&gt;\(x_2^* = 0 \Rightarrow u^* \le 3\) (slack OK)&lt;/li&gt;
  &lt;li&gt;\(u^* &amp;gt; 0 \Rightarrow x_1^* + x_2^* = 1\) (primal constraint tight)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;connections-to-other-chapters&quot;&gt;&lt;strong&gt;Connections to Other Chapters&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-the-previous-chapter&quot;&gt;&lt;strong&gt;From the previous chapter:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 05:&lt;/strong&gt; LP as a canonical problem&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 04:&lt;/strong&gt; Optimality conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 03:&lt;/strong&gt; Convex functions and their properties&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;importance-of-lp-duality&quot;&gt;&lt;strong&gt;Importance of LP Duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical foundation:&lt;/strong&gt; For general duality (Chapter 11)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational:&lt;/strong&gt; Dual simplex, interior point methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Economic interpretation:&lt;/strong&gt; Shadow prices, sensitivity analysis&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine learning:&lt;/strong&gt; SVM, robust optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;looking-ahead&quot;&gt;&lt;strong&gt;Looking ahead:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 11:&lt;/strong&gt; General duality theory&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 12:&lt;/strong&gt; KKT conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Applications:&lt;/strong&gt; Constrained optimization, game theory&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;theoretical-significance&quot;&gt;&lt;strong&gt;Theoretical Significance&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;duality-as-an-analysis-tool&quot;&gt;&lt;strong&gt;Duality as an analysis tool:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bounds:&lt;/strong&gt; Upper and lower bounds on the optimal value&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity:&lt;/strong&gt; Effect of changes in the constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimality:&lt;/strong&gt; Necessary and sufficient conditions for an optimal solution&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithms:&lt;/strong&gt; Dual-based methods (dual simplex, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;geometric-interpretation&quot;&gt;&lt;strong&gt;Geometric interpretation:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal:&lt;/strong&gt; Find a point in the feasible region&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual:&lt;/strong&gt; Find a hyperplane supporting the optimal value&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; Hyperplane touches feasible region&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;economic-interpretation-1&quot;&gt;&lt;strong&gt;Economic interpretation:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal:&lt;/strong&gt; Direct resource allocation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual:&lt;/strong&gt; Price-based market mechanism&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equilibrium:&lt;/strong&gt; Primal-dual optimal solutions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;practical-tips&quot;&gt;&lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;recognizing-when-to-use-duality&quot;&gt;&lt;strong&gt;Recognizing when to use duality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Primal is hard to solve:&lt;/strong&gt; The dual may be simpler&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity analysis:&lt;/strong&gt; Dual variables give shadow prices&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bounds:&lt;/strong&gt; The dual provides bounds for the primal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm design:&lt;/strong&gt; Primal-dual methods&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;common-mistakes&quot;&gt;&lt;strong&gt;Common mistakes:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Wrong conversion rules:&lt;/strong&gt; Mixing up min/max, ≤/≥&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Forgetting non-negativity conditions:&lt;/strong&gt; On dual variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Not checking feasibility:&lt;/strong&gt; Of both primal and dual&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Misinterpretation:&lt;/strong&gt; Dual variables are not primal variables&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;debugging-tips&quot;&gt;&lt;strong&gt;Debugging tips:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Verify weak duality:&lt;/strong&gt; \(g^* \le f^*\) always holds&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check complementary slackness:&lt;/strong&gt; At the optimal solutions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric intuition:&lt;/strong&gt; Visualize in 2D when possible&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Economic meaning:&lt;/strong&gt; Dual variables as prices&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; LP duality is the foundation of all duality theory in optimization. Understanding LP duality well will help you master the more advanced duality concepts!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of duality in linear programming (LP duality), weak/strong duality, complementary slackness, the max flow-min cut theorem and matrix games.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🔄 Quiz: Duality in Linear Programming&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: Given the primal LP: $$\min c^T x$$ s.t. $$Ax = b, Gx \leq h$$. The dual problem has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) $$\max -b^T u - h^T v$$ s.t. $$-A^T u - G^T v = c, v \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) $$\min -b^T u - h^T v$$ s.t. $$-A^T u - G^T v = c, v \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) $$\max -b^T u - h^T v$$ s.t. $$-A^T u - G^T v = c, v \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) $$\max c^T x$$ s.t. $$Ax \geq b, Gx = h$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max -b^T u - h^T v$$ s.t. $$-A^T u - G^T v = c, v \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                The dual of a minimization problem is a maximization problem. The dual variable $$u$$ for the equality constraints has no sign constraint, and $$v$$ for the inequality constraints must be non-negative. From the Lagrangian $$L = c^Tx + u^T(Ax-b) + v^T(Gx-h)$$, the minimum over $$x$$ is finite if and only if $$c + A^Tu + G^Tv = 0$$, in which case $$g(u,v) = -b^Tu - h^Tv$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The weak duality theorem states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) The primal optimal value equals the dual optimal value&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) The primal optimal value is always greater than or equal to the dual optimal value&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) The primal optimal value is always less than the dual optimal value&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) The primal and dual cannot both have optimal solutions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The primal optimal value is always greater than or equal to the dual optimal value&lt;/strong&gt;&lt;br /&gt;
                Weak duality: $$p^* \geq d^*$$, where $$p^*$$ is the primal (minimization) optimal value and $$d^*$$ is the dual (maximization) optimal value.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: Strong duality holds when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) $$p^* &amp;lt; d^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) $$p^* = d^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) $$p^* &amp;gt; d^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) The primal has no solution&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$p^* = d^*$$&lt;/strong&gt;&lt;br /&gt;
                Strong duality means there is no duality gap: the primal optimal value equals the dual optimal value.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: For the LP pair $$\min c^T x$$ s.t. $$Ax \geq b, x \geq 0$$ and $$\max b^T y$$ s.t. $$A^T y \leq c, y \geq 0$$, complementary slackness states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$x_i &amp;gt; 0 \Rightarrow (A^T y)_i = c_i$$ and $$y_j &amp;gt; 0 \Rightarrow (Ax)_j = b_j$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) $$x_i = 0$$ and $$y_j = 0$$ for all $$i, j$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) The primal and dual are both feasible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) $$Ax \geq b$$ and $$x \geq 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$x_i &amp;gt; 0 \Rightarrow (A^T y)_i = c_i$$ and $$y_j &amp;gt; 0 \Rightarrow (Ax)_j = b_j$$&lt;/strong&gt;&lt;br /&gt;
                Complementary slackness: if a primal variable is positive then the corresponding dual constraint is tight; if a dual variable is positive then the corresponding primal constraint is tight.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: The duality gap is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) $$d^* - p^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) $$p^* - d^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) $$p^* + d^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) $$|p^* - d^*|$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$p^* - d^*$$&lt;/strong&gt;&lt;br /&gt;
                The duality gap is the difference between the primal and dual optimal values. By weak duality, this gap is always non-negative.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: Given an LP in standard form: $$\min c^T x$$ s.t. $$Ax = b, x \geq 0$$. The dual problem is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) $$\max b^T y$$ s.t. $$A^T y \leq c$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) $$\max b^T y$$ s.t. $$A^T y = c$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) $$\min b^T y$$ s.t. $$A^T y \geq c$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) $$\max b^T y$$ s.t. $$A^T y \geq c$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max b^T y$$ s.t. $$A^T y \leq c$$&lt;/strong&gt;&lt;br /&gt;
                Dual of the standard-form LP: the dual variable $$y$$ has no sign constraint because the primal has equality constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: In the max flow problem, the goal is to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Minimize the total capacity of the edges&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Maximize the flow from source to sink&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Minimize the number of edges in a path&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Maximize the number of vertices visited&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Maximize the flow from source to sink&lt;/strong&gt;&lt;br /&gt;
                The max flow problem finds the largest flow that can be sent from the source node to the sink node through the network.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The min cut problem finds:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) A set of edges with minimum total capacity that disconnects the source from the sink&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) The shortest path from source to sink&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) The minimum number of edges connecting all vertices&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) The minimum spanning tree of the graph&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) A set of edges with minimum total capacity that disconnects the source from the sink&lt;/strong&gt;&lt;br /&gt;
                Min cut finds a partition of the vertices into two sets such that the total capacity of the edges between them is minimal.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The max flow-min cut theorem states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) The max flow value equals the capacity of the min cut&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) Max flow is always less than min cut&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) Min cut is always less than max flow&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) Max flow and min cut are unrelated&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The max flow value equals the capacity of the min cut&lt;/strong&gt;&lt;br /&gt;
                This is a classic example of strong duality: the max flow problem and the min cut problem are duals of each other.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: In a matrix game with payout matrix $$P$$, player J wants to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) Maximize the expected payout&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) Minimize the maximum loss (minimax)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Maximize the minimum gain&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) Minimize the expected payout&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Minimize the maximum loss (minimax)&lt;/strong&gt;&lt;br /&gt;
                Player J (row player) wants to minimize the maximum possible loss, i.e. find a mixed strategy that minimizes the worst-case payout.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: If the primal LP has an empty feasible region, then the dual LP:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Also has an empty feasible region&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) May be unbounded or infeasible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Always has an optimal solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Is always unbounded&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) May be unbounded or infeasible&lt;/strong&gt;&lt;br /&gt;
                When the primal is infeasible, the dual may be unbounded (if the dual is feasible) or also infeasible.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: In economics, dual variables are usually interpreted as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Shadow prices&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Production quantities&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Market demands&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Cost coefficients&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Shadow prices&lt;/strong&gt;&lt;br /&gt;
                Dual variables represent the marginal value of resources, i.e. the value gained by increasing a resource constraint by one unit.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The dual of the dual problem is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) A completely different problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) The original primal problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) It does not exist&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Equal to the dual problem&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The original primal problem&lt;/strong&gt;&lt;br /&gt;
                Symmetry property: the dual of the dual is the original primal problem (possibly after a change of form).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: For strong duality in LP, the required condition is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Both the primal and the dual have optimal solutions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) The primal or dual has an interior point (Slater condition)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) The feasible region is bounded&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) No condition is needed, LP always has strong duality&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) No condition is needed, LP always has strong duality&lt;/strong&gt;&lt;br /&gt;
                Linear programs always satisfy strong duality (unless both are infeasible) thanks to the special nature of linear constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: Primal-dual algorithms solve LPs by:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Solving only the primal problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Solving only the dual problem&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Updating both the primal and dual variables simultaneously&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Solving the primal and then the dual sequentially&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) Updating both the primal and dual variables simultaneously&lt;/strong&gt;&lt;br /&gt;
                Primal-dual methods maintain and update both primal and dual solutions, using duality to guide convergence.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: The dual optimal solution provides information about:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) The sensitivity of the objective value to changes in the constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) The number of iterations needed&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) The complexity of the algorithm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) The condition number of the matrix&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The sensitivity of the objective value to changes in the constraints&lt;/strong&gt;&lt;br /&gt;
                Dual variables tell how much the objective value changes when the right-hand side of the constraints changes.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: A Nash equilibrium in a matrix game corresponds to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Primal optimal solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Dual optimal solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) A pair of primal-dual optimal solutions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Any feasible solution&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) A pair of primal-dual optimal solutions&lt;/strong&gt;&lt;br /&gt;
                Nash equilibrium mixed strategies correspond to the optimal solutions of a primal-dual pair of LP problems.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: If the primal LP is unbounded below, then the dual LP:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Is also unbounded&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Infeasible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Has an optimal solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Bounded&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Infeasible&lt;/strong&gt;&lt;br /&gt;
                If the primal (minimization) is unbounded below, then the dual (maximization) must be infeasible by weak duality.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: In the max flow problem, the flow conservation constraint requires:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Total flow into each node equals total flow out (except source/sink)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) The flow on each edge does not exceed its capacity&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) The flow must be non-negative&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) All of the above conditions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Total flow into each node equals total flow out (except source/sink)&lt;/strong&gt;&lt;br /&gt;
                Flow conservation: $$\sum_{i} f_{ij} = \sum_{k} f_{jk}$$ at each intermediate node $$j$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: LP duality has applications in:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Economics (resource allocation)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Network flows and transportation&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Game theory and decision making&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above fields&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above fields&lt;/strong&gt;&lt;br /&gt;
                LP duality has wide applications: economics (shadow prices), networks (max flow-min cut), game theory (minimax), and many other fields.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: The dual of the LP $$\min c^T x$$ subject to $$Ax \geq b, x \geq 0$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$\max b^T y$$ subject to $$A^T y \leq c, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$\max b^T y$$ subject to $$A^T y \geq c, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$\min b^T y$$ subject to $$A^T y \leq c, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$\max c^T y$$ subject to $$A^T y \leq b, y \geq 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max b^T y$$ subject to $$A^T y \leq c, y \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                The dual of this LP has the form $$\max b^T y$$ subject to $$A^T y \leq c, y \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: The strong duality theorem in LP states:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$c^T x^* = b^T y^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$c^T x^* \leq b^T y^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$c^T x^* \geq b^T y^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) There is no relationship&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$c^T x^* = b^T y^*$$&lt;/strong&gt;&lt;br /&gt;
                When both the primal and dual have optimal solutions, their optimal values are equal.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: Complementary slackness in LP: if $$x_i &amp;gt; 0$$ then:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) The corresponding dual constraint is active&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) The corresponding dual constraint is inactive&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$y_i = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$y_i &amp;gt; 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The corresponding dual constraint is active&lt;/strong&gt;&lt;br /&gt;
                Complementary slackness: if $$x_i &amp;gt; 0$$ then the dual constraint $$\sum_j a_{ji}y_j = c_i$$ must be active.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The duality gap in LP equals:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$c^T x - b^T y$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$b^T y - c^T x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$|c^T x - b^T y|$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) $$\max\{c^T x, b^T y\}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$c^T x - b^T y$$&lt;/strong&gt;&lt;br /&gt;
                Duality gap = primal value - dual value = $$c^T x - b^T y \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: Given the LP: $$\min 2x_1 + 3x_2$$ subject to $$x_1 + x_2 \geq 1, x_1, x_2 \geq 0$$. The dual problem is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$\max y$$ subject to $$y \leq 2, y \leq 3, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$\max y$$ subject to $$y \geq 2, y \geq 3, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$\min y$$ subject to $$y \leq 2, y \leq 3, y \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$\max 2y + 3y$$ subject to $$y \geq 1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\max y$$ subject to $$y \leq 2, y \leq 3, y \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Dual: $$\max y$$ subject to $$y \leq 2$$ (from $$x_1 \geq 0$$), $$y \leq 3$$ (from $$x_2 \geq 0$$), $$y \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;a&apos;, q5: &apos;b&apos;,
    q6: &apos;a&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;b&apos;,
    q11: &apos;b&apos;, q12: &apos;a&apos;, q13: &apos;b&apos;, q14: &apos;d&apos;, q15: &apos;c&apos;,
    q16: &apos;a&apos;, q17: &apos;c&apos;, q18: &apos;b&apos;, q19: &apos;a&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered LP duality theory!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand primal-dual relationships well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review complementary slackness and the applications.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review weak/strong duality and the formulations.&apos;;
    } else {
        message = &apos;📖 Study LP duality again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>10-06 The Double Duality Property: The Dual of the Dual Is the Primal</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_06_Dual_of_Dual_Property/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_06_Dual_of_Dual_Property</id>
   <content type="html">&lt;p&gt;In linear algebra, transposing a matrix twice returns the exact original matrix: \((A^\top)^\top = A\). Linear programming duality obeys an equally striking symmetry called the &lt;strong&gt;involution property&lt;/strong&gt;: if you take a primal LP, form its dual LP, and then take the dual of &lt;em&gt;that&lt;/em&gt; dual LP, you land right back on the original primal problem! Far from being a mere algebraic curiosity, this symmetry proves that every theorem you prove for primal-to-dual relationships automatically works in reverse.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-lp-duality-is-an-exact-involution&quot;&gt;Key ideas: Why LP Duality Is an Exact Involution&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Standardizing the Dual Back to Minimization:&lt;/strong&gt; Because the dual of a minimization LP is a maximization LP, taking the dual a second time requires rewriting \(\max b^\top y\) as \(-\min (-b^\top y)\) and converting \(\le\) inequalities into standard form—every sign flip cancels out cleanly on the second pass.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Double Transposition of Matrices:&lt;/strong&gt; The constraint matrix \(A\) transposes to \(A^\top\) in the first dual and back to \((A^\top)^\top = A\) in the second dual; similarly, the objective vector \(c\) and right-hand side \(b\) swap places twice and return to their starting positions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Complete Primal–Dual Feasibility Classification:&lt;/strong&gt; Because the dual of the dual is the primal, the 4 possible status combinations of \((P, D)\) are symmetric: (Optimal, Optimal), (Unbounded, Infeasible), (Infeasible, Unbounded), or (Infeasible, Infeasible). Neither LP can be bounded-feasible while the other is infeasible!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Contrast with General Nonlinear Optimization (Preview of Ch. 11):&lt;/strong&gt; In Chapter 11, we will see that the dual of the dual of a &lt;em&gt;nonconvex&lt;/em&gt; problem does &lt;strong&gt;not&lt;/strong&gt; recover the original problem—it recovers its &lt;em&gt;convexified&lt;/em&gt; (biconjugate) envelope instead! Involution holds unconditionally for LPs precisely because linear functions and polyhedra are already closed and convex.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-taking-the-dual-twice-on-a-standard-form-lp&quot;&gt;Worked example: Taking the Dual Twice on a Standard-Form LP&lt;/h3&gt;

&lt;p&gt;Start with the standard-form primal LP \((P)\):
\(\min_{x}\; 2x_1 + 5x_2 \quad \text{s.t.} \quad x_1 + 3x_2 = 7, \quad x_1, x_2 \ge 0.\)
Here \(c = (2, 5)^\top\), \(A = (1, 3)\), \(b = 7\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;First Dual \((D)\):&lt;/strong&gt;
\(\max_{y \in \mathbb{R}}\; 7y \quad \text{s.t.} \quad \begin{pmatrix}1 \\ 3\end{pmatrix} y \le \begin{pmatrix}2 \\ 5\end{pmatrix} \iff y \le 2,\; 3y \le 5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rewrite \((D)\) as a minimization LP with \(\le\) constraints:&lt;/strong&gt;
\(-\min_{y \in \mathbb{R}}\; (-7y) \quad \text{s.t.} \quad y \le 2,\quad 3y \le 5.\)
Here \(\tilde{c} = (-7)\), \(\tilde{G} = \begin{pmatrix}1 \\ 3\end{pmatrix}\), \(\tilde{h} = \begin{pmatrix}2 \\ 5\end{pmatrix}\) (and no equality constraints).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take the dual of the inner minimization (with multipliers \(z = (z_1, z_2)^\top \ge 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Dual objective: \(-\tilde{h}^\top z = -(2z_1 + 5z_2)\).&lt;/li&gt;
      &lt;li&gt;Dual constraint \(-\tilde{G}^\top z = \tilde{c}\): \(-(z_1 + 3z_2) = -7 \iff z_1 + 3z_2 = 7\).&lt;/li&gt;
      &lt;li&gt;Inner dual is \(\max_{z \ge 0} \{ -(2z_1 + 5z_2) : z_1 + 3z_2 = 7 \}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Restore the outer minus sign:&lt;/strong&gt;
\(-\max_{z \ge 0} \{ -(2z_1 + 5z_2) : z_1 + 3z_2 = 7 \} = \min_{z \ge 0} \{ 2z_1 + 5z_2 : z_1 + 3z_2 = 7 \},\)
which is &lt;strong&gt;symbol-for-symbol identical&lt;/strong&gt; to the original primal \((P)\) (with \(z\) renamed to \(x\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Linear Programming, a beautiful and important mathematical property is that &lt;strong&gt;the dual of the dual problem is the original (primal) problem&lt;/strong&gt;. This property is called the &lt;strong&gt;“involution” of duality&lt;/strong&gt; or the &lt;strong&gt;“dual-of-the-dual theorem”&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is a basic property that expresses the perfect symmetry of LP duality theory, and it has deep significance in both theory and applications.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;recap-the-standard-form-of-a-linear-program-the-primal-problem&quot;&gt;Recap: The Standard Form of a Linear Program (the Primal Problem)&lt;/h2&gt;

&lt;p&gt;A linear program in primal form is usually written as follows:&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; c^T x \label{eq:primal-obj} \\
\text{subject to} \quad &amp;amp; A x \geq b, \label{eq:primal-ineq} \\
&amp;amp; x \geq 0, \label{eq:primal-nonneg}
\end{align}\]

&lt;p&gt;where:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) is the vector of decision variables&lt;/li&gt;
  &lt;li&gt;\(c \in \mathbb{R}^n\) is the vector of objective coefficients&lt;/li&gt;
  &lt;li&gt;\(A \in \mathbb{R}^{m \times n}\) is the constraint matrix&lt;/li&gt;
  &lt;li&gt;\(b \in \mathbb{R}^m\) is the right-hand-side vector&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; An LP can be written in many different forms (maximization, equality constraints, etc.), but we can always convert it to this standard form without loss of generality.&lt;/p&gt;

&lt;h3 id=&quot;illustrative-example&quot;&gt;&lt;strong&gt;Illustrative Example:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the simple problem:&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; 2x_1 + 3x_2 \\
\text{subject to} \quad &amp;amp; x_1 + x_2 \geq 4, \\
&amp;amp; 2x_1 + x_2 \geq 5, \\
&amp;amp; x_1, x_2 \geq 0.
\end{align}\]

&lt;p&gt;Here:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;$c = \begin{bmatrix} 2 \ 3 \end{bmatrix}$&lt;/li&gt;
  &lt;li&gt;$A = \begin{bmatrix} 1 &amp;amp; 1 \ 2 &amp;amp; 1 \end{bmatrix}$&lt;/li&gt;
  &lt;li&gt;$b = \begin{bmatrix} 4 \ 5 \end{bmatrix}$&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;constructing-the-dual-problem&quot;&gt;Constructing the Dual Problem&lt;/h2&gt;

&lt;p&gt;The dual problem is constructed from the primal problem to provide bounds and information about optimality (for example, sensitivity analysis and optimality conditions).&lt;/p&gt;

&lt;p&gt;For the primal problem above, the dual problem is defined as follows:&lt;/p&gt;

\[\begin{align}
\text{maximize} \quad &amp;amp; b^T y \label{eq:dual-obj} \\
\text{subject to} \quad &amp;amp; A^T y \leq c, \label{eq:dual-ineq} \\
&amp;amp; y \geq 0, \label{eq:dual-nonneg}
\end{align}\]

&lt;p&gt;where $y \in \mathbb{R}^m$ is the vector of dual variables.&lt;/p&gt;

&lt;h3 id=&quot;meaning&quot;&gt;&lt;strong&gt;Meaning:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;The dual problem is also an LP&lt;/li&gt;
  &lt;li&gt;By &lt;strong&gt;weak duality&lt;/strong&gt;: the optimal value of the dual gives a lower bound on the optimal value of the primal&lt;/li&gt;
  &lt;li&gt;If &lt;strong&gt;strong duality&lt;/strong&gt; holds (it always does for feasible LPs, under mild conditions such as Slater’s condition), the optimal values of the two problems are equal&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example-continued&quot;&gt;&lt;strong&gt;Example (continued):&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The dual of the problem above is:&lt;/p&gt;

\[\begin{align}
\text{maximize} \quad &amp;amp; 4y_1 + 5y_2 \\
\text{subject to} \quad &amp;amp; y_1 + 2y_2 \leq 2, \\
&amp;amp; y_1 + y_2 \leq 3, \\
&amp;amp; y_1, y_2 \geq 0.
\end{align}\]

&lt;hr /&gt;

&lt;h2 id=&quot;step-3-constructing-the-dual-of-the-dual&quot;&gt;&lt;strong&gt;Step 3: Constructing the Dual of the Dual&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Now we treat the dual problem we just constructed as a new primal problem and apply the duality rules once more.&lt;/p&gt;

&lt;h3 id=&quot;step-31-convert-the-dual-to-primal-like-form&quot;&gt;&lt;strong&gt;Step 3.1: Convert the Dual to “Primal-Like” Form&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;To make the duality rules easier to apply, we turn the maximization problem into a minimization problem by flipping the sign of the objective:&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; -b^T y \\
\text{subject to} \quad &amp;amp; -A^T y \geq -c, \\
&amp;amp; y \geq 0.
\end{align}\]

&lt;h3 id=&quot;step-32-apply-the-duality-rules&quot;&gt;&lt;strong&gt;Step 3.2: Apply the Duality Rules&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Applying the duality rules to this problem:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;New dual variable: $z \in \mathbb{R}^n$ (same dimension as $x$ in the original primal problem)&lt;/li&gt;
  &lt;li&gt;New objective: maximize $(-c)^T z$ (that is, $-\min c^T z$; after flipping the sign back, we get minimize $c^T z$)&lt;/li&gt;
  &lt;li&gt;New constraints: from $-A^T y \geq -c$ and the duality rules, we get:
    &lt;ul&gt;
      &lt;li&gt;The constraint matrix of the new dual is $(-A^T)^T = -A$&lt;/li&gt;
      &lt;li&gt;The constraint becomes: $-A z \leq -b$&lt;/li&gt;
      &lt;li&gt;Simplifying: $A z \geq b$&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Non-negativity: $z \geq 0$&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;step-33-the-result&quot;&gt;&lt;strong&gt;Step 3.3: The Result&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The dual of the dual is:&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; c^T z \\
\text{subject to} \quad &amp;amp; A z \geq b, \\
&amp;amp; z \geq 0.
\end{align}\]

&lt;p&gt;&lt;strong&gt;This is exactly the original primal problem!&lt;/strong&gt; (with $z$ simply being another name for $x$)&lt;/p&gt;

&lt;h3 id=&quot;example-continued-1&quot;&gt;&lt;strong&gt;Example (continued):&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The dual of the dual for the example problem:&lt;/p&gt;

&lt;p&gt;From the dual:
\(\text{maximize } 4y_1 + 5y_2 \text{ s.t. } y_1 + 2y_2 \leq 2, \; y_1 + y_2 \leq 3, \; y_1, y_2 \geq 0\)&lt;/p&gt;

&lt;p&gt;Convert to minimization form:
\(\text{minimize } -4y_1 - 5y_2 \text{ s.t. } -y_1 - 2y_2 \geq -2, \; -y_1 - y_2 \geq -3, \; y_1, y_2 \geq 0\)&lt;/p&gt;

&lt;p&gt;Its dual (with variables $z_1, z_2$) is the problem of maximizing $-2z_1 - 3z_2$ (equivalent to minimizing $2z_1 + 3z_2$ after flipping the sign of the objective):
\(\begin{align}
\text{minimize} \quad &amp;amp; 2z_1 + 3z_2 \\
\text{subject to} \quad &amp;amp; z_1 + z_2 \geq 4, \\
&amp;amp; 2z_1 + z_2 \geq 5, \\
&amp;amp; z_1, z_2 \geq 0.
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It is indeed the original primal problem!&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;step-4-why-is-this-property-true-mathematical-explanation&quot;&gt;&lt;strong&gt;Step 4: Why Is This Property True? (Mathematical Explanation)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;This property comes from the &lt;strong&gt;symmetry in the Lagrangian formulation&lt;/strong&gt; of LP.&lt;/p&gt;

&lt;h3 id=&quot;41-the-lagrangian&quot;&gt;&lt;strong&gt;4.1. The Lagrangian&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The Lagrangian of the primal problem is:&lt;/p&gt;

\[\mathcal{L}(x, y) = c^T x - y^T (A x - b),\]

&lt;p&gt;where $y \geq 0$ are the Lagrange multipliers of the inequalities.&lt;/p&gt;

&lt;h3 id=&quot;42-the-primal-dual-relationship&quot;&gt;&lt;strong&gt;4.2. The Primal-Dual Relationship&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primal problem&lt;/strong&gt;: $\min_{x \geq 0} \sup_{y \geq 0} \mathcal{L}(x, y)$&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual problem&lt;/strong&gt;: $\max_{y \geq 0} \inf_{x \geq 0} \mathcal{L}(x, y)$&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The min-max theorem (for convex-concave functions such as this linear Lagrangian) gives a symmetry:&lt;/p&gt;

\[\min_x \max_y \mathcal{L}(x, y) = \max_y \min_x \mathcal{L}(x, y)\]

&lt;p&gt;When we apply duality twice, we swap min and max twice and return to the starting position.&lt;/p&gt;

&lt;h3 id=&quot;43-the-matrix-view&quot;&gt;&lt;strong&gt;4.3. The Matrix View&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The dualization process consists of:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Transposing the matrix: $A \to A^T$&lt;/li&gt;
  &lt;li&gt;Reversing the direction of the inequalities: $\geq$ becomes $\leq$ (or vice versa)&lt;/li&gt;
  &lt;li&gt;Swapping the roles of $b$ and $c$&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When applied twice:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;$(A^T)^T = A$ (transposing twice returns the original matrix)&lt;/li&gt;
  &lt;li&gt;Reversing the direction twice returns the original direction&lt;/li&gt;
  &lt;li&gt;Swapping $(b, c)$ twice returns $(b, c)$&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; The mathematical structure returns to where it started!&lt;/p&gt;

&lt;h3 id=&quot;44-a-geometric-illustration&quot;&gt;&lt;strong&gt;4.4. A Geometric Illustration&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Imagine a geometric transformation (such as a reflection across a plane):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Applied once: we get the mirror image&lt;/li&gt;
  &lt;li&gt;Applied twice: we return to the original position&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The property “the dual of the dual is the primal” is similar: it is an &lt;strong&gt;involution&lt;/strong&gt; (a transformation that gives the original result when applied twice).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;detailed-example-a-production-problem&quot;&gt;&lt;strong&gt;Detailed Example: A Production Problem&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;primal-problem-p&quot;&gt;&lt;strong&gt;Primal Problem (P)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;A company produces two products, A and B. The profit from each unit of A is 3 million and from B is 5 million. There are two limited resources:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Material: A needs 2 kg/unit, B needs 1 kg/unit, with 8 kg in total&lt;/li&gt;
  &lt;li&gt;Time: A needs 1 hour/unit, B needs 2 hours/unit, with 10 hours in total&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Find the production quantities that maximize profit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Formulation:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\text{maximize} \quad &amp;amp; 3x_1 + 5x_2 \\
\text{subject to} \quad &amp;amp; 2x_1 + x_2 \leq 8, \\
&amp;amp; x_1 + 2x_2 \leq 10, \\
&amp;amp; x_1, x_2 \geq 0.
\end{align}\]

&lt;p&gt;Converted to standard form (minimize):&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; -3x_1 - 5x_2 \\
\text{subject to} \quad &amp;amp; -2x_1 - x_2 \geq -8, \\
&amp;amp; -x_1 - 2x_2 \geq -10, \\
&amp;amp; x_1, x_2 \geq 0.
\end{align}\]

&lt;h3 id=&quot;dual-problem-d&quot;&gt;&lt;strong&gt;Dual Problem (D)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The dual has an economic meaning: find the shadow prices of the resources that &lt;strong&gt;minimize&lt;/strong&gt; the total value of the resources, while ensuring that the resource value used by each unit of a product is not less than that product’s profit. Since (P) is a maximization problem with \(\leq\) constraints, its dual is a &lt;strong&gt;minimization&lt;/strong&gt; problem with \(\geq\) constraints:&lt;/p&gt;

\[\begin{align}
\text{minimize} \quad &amp;amp; 8y_1 + 10y_2 \\
\text{subject to} \quad &amp;amp; 2y_1 + y_2 \geq 3, \\
&amp;amp; y_1 + 2y_2 \geq 5, \\
&amp;amp; y_1, y_2 \geq 0.
\end{align}\]

&lt;h3 id=&quot;dual-of-the-dual-dd&quot;&gt;&lt;strong&gt;Dual of the Dual (DD)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;(D) is already in the standard form “minimize, \(\geq\) constraints, non-negative variables”, with objective coefficients \((8, 10)\), constraint matrix \(\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}\) and right-hand side \((3, 5)\). Applying the duality rules (new variables \(z_1, z_2\)):&lt;/p&gt;

\[\begin{align}
\text{maximize} \quad &amp;amp; 3z_1 + 5z_2 \\
\text{subject to} \quad &amp;amp; 2z_1 + z_2 \leq 8, \\
&amp;amp; z_1 + 2z_2 \leq 10, \\
&amp;amp; z_1, z_2 \geq 0.
\end{align}\]

&lt;p&gt;&lt;strong&gt;This is exactly the original primal problem (P)!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Numerical check:&lt;/strong&gt; (P) is optimal at \((x_1, x_2) = (2, 4)\) with profit \(3 \cdot 2 + 5 \cdot 4 = 26\). (D) is optimal at \((y_1, y_2) = (\tfrac{1}{3}, \tfrac{7}{3})\) with value \(8 \cdot \tfrac{1}{3} + 10 \cdot \tfrac{7}{3} = 26\). The two values are equal, as strong duality predicts.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;extension-general-convex-optimization&quot;&gt;&lt;strong&gt;Extension: General Convex Optimization&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;The property “the dual of the dual is the primal” has been proved for Linear Programming. Does it still hold for general convex optimization problems?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; For convex optimization, the property is &lt;strong&gt;conditional&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Slater’s condition must hold&lt;/li&gt;
  &lt;li&gt;Strong duality is required&lt;/li&gt;
  &lt;li&gt;It does &lt;strong&gt;not hold&lt;/strong&gt; for non-convex problems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;For details&lt;/strong&gt;, see &lt;strong&gt;Chapter 11, Lesson 11-09&lt;/strong&gt;: “The Dual of the Dual in General Convex Optimization”, where we analyze in depth:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The conditions required for this property&lt;/li&gt;
  &lt;li&gt;LP vs convex optimization&lt;/li&gt;
  &lt;li&gt;Examples where the dual of the dual ≠ the primal&lt;/li&gt;
  &lt;li&gt;Applications in algorithm design&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L. (2004).&lt;/strong&gt; &lt;em&gt;Convex Optimization.&lt;/em&gt; Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 5: Duality (especially Section 5.2 on LP duality)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bertsimas, D., &amp;amp; Tsitsiklis, J. N. (1997).&lt;/strong&gt; &lt;em&gt;Introduction to Linear Optimization.&lt;/em&gt; Athena Scientific.
    &lt;ul&gt;
      &lt;li&gt;Chapter 4: Duality Theory&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov, Y. (2018).&lt;/strong&gt; &lt;em&gt;Lectures on Convex Optimization.&lt;/em&gt; Springer.
    &lt;ul&gt;
      &lt;li&gt;Chapter 3: Duality in Convex Optimization&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dantzig, G. B. (1963).&lt;/strong&gt; &lt;em&gt;Linear Programming and Extensions.&lt;/em&gt; Princeton University Press.
    &lt;ul&gt;
      &lt;li&gt;Foundational work on LP duality&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>10-05 Matrix Games</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_05_Matrix_Games/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_05_Matrix_Games</id>
   <content type="html">&lt;p&gt;In 1928, John von Neumann proved a theorem that launched modern game theory: in any two-player zero-sum game (like Rock-Paper-Scissors or Matching Pennies), if both players are allowed to randomize using &lt;strong&gt;mixed strategies&lt;/strong&gt;, it makes &lt;em&gt;no difference&lt;/em&gt; who reveals their probability distribution first—the best worst-case payout guaranteed by the maximizer equals the lowest worst-case loss guaranteed by the minimizer! Remarkably, once each player’s problem is written as a linear program, von Neumann’s minimax theorem turns out to be an immediate one-line corollary of LP strong duality.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-zero-sum-games-as-primaldual-linear-programs&quot;&gt;Key ideas: Zero-Sum Games as Primal–Dual Linear Programs&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Mixed Strategies &amp;amp; Expected Payoff:&lt;/strong&gt; Players \(J\) and \(R\) choose probability vectors \(x \in \Delta_m\) (\(x \ge 0, \mathbf{1}^\top x = 1\)) and \(y \in \Delta_n\) (\(y \ge 0, \mathbf{1}^\top y = 1\)). The expected payout from \(J\) to \(R\) is the bilinear form \(x^\top P y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Epigraph Reformulation to LP:&lt;/strong&gt; When \(J\) commits to \(x\) first, \(R\)’s best response is \(\max_{y \in \Delta_n} x^\top P y = \max_{1 \le j \le n} (P^\top x)_j\) (attained at a pure strategy). Introducing a scalar epigraph variable \(t\) converts \(J\)’s minimax problem into the LP \(\min_{x, t} \{ t : P^\top x \le t \mathbf{1},\; \mathbf{1}^\top x = 1,\; x \ge 0 \}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Opponent’s Problem = Exact LP Dual:&lt;/strong&gt; Taking the LP dual of \(J\)’s minimization LP introduces multipliers \(y \ge 0\) (for \(P^\top x \le t\mathbf{1}\)) and \(s \in \mathbb{R}\) (for \(\mathbf{1}^\top x = 1\)), yielding \(\max_{y, s} \{ s : P y \ge s \mathbf{1},\; \mathbf{1}^\top y = 1,\; y \ge 0 \}\)—which is literally \(R\)’s maximin problem!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 4 — Von Neumann Minimax Theorem via Strong Duality:&lt;/strong&gt; Because both LPs are feasible (any uniform distribution works) and bounded (by $$\max&lt;/td&gt;
          &lt;td&gt;P_{ij}&lt;/td&gt;
          &lt;td&gt;\(), LP strong duality guarantees\)\min_{x \in \Delta_m} \max_{y \in \Delta_n} x^\top P y = \max_{y \in \Delta_n} \min_{x \in \Delta_m} x^\top P y = v^\star$$, the unique value of the game.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-an-asymmetric-2-times-2-matrix-game-from-both-sides&quot;&gt;Worked example: Solving an Asymmetric \(2 \times 2\) Matrix Game from Both Sides&lt;/h3&gt;

&lt;p&gt;Consider the payout matrix (from \(J\) to \(R\)): \(P = \begin{pmatrix} 3 &amp;amp; 0 \\ 1 &amp;amp; 4 \end{pmatrix}\). Notice there is no pure-strategy saddle point (row maxes are \(3, 4 \implies \min = 3\); column mins are \(1, 0 \implies \max = 1 &amp;lt; 3\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(J\)’s primal LP (choose \(x = (x_1, 1 - x_1)^\top\) to minimize \(\max\{3x_1 + (1 - x_1),\; 0x_1 + 4(1 - x_1)\}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Column 1 expected payout: \(1 + 2x_1\).&lt;/li&gt;
      &lt;li&gt;Column 2 expected payout: \(4 - 4x_1\).&lt;/li&gt;
      &lt;li&gt;To minimize the maximum of an increasing line and a decreasing line, set them equal:
\(1 + 2x_1 = 4 - 4x_1 \implies 6x_1 = 3 \implies x_1^\star = \frac{1}{2},\; x_2^\star = \frac{1}{2}.\)&lt;/li&gt;
      &lt;li&gt;Primal value: \(t^\star = 1 + 2(0.5) = 2.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(R\)’s dual LP (choose \(y = (y_1, 1 - y_1)^\top\) to maximize \(\min\{3y_1 + 0(1 - y_1),\; 1y_1 + 4(1 - y_1)\}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Row 1 expected payout: \(3y_1\).&lt;/li&gt;
      &lt;li&gt;Row 2 expected payout: \(4 - 3y_1\).&lt;/li&gt;
      &lt;li&gt;Equating both lines:
\(3y_1 = 4 - 3y_1 \implies 6y_1 = 4 \implies y_1^\star = \frac{2}{3},\; y_2^\star = \frac{1}{3}.\)&lt;/li&gt;
      &lt;li&gt;Dual value: \(s^\star = 3(2/3) = 2.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify von Neumann’s theorem:&lt;/strong&gt; \(t^\star = 2.0 = s^\star\)! Even though pure strategies had a gap \(1 &amp;lt; 3\), mixed strategies closed the gap completely via LP strong duality.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In this chapter, we examine mixed strategies for matrix games, which is an example of primal LP and dual LP in game theory. The setup assumes two players, J and R, and a payout matrix \(P\).&lt;/p&gt;

&lt;h2 id=&quot;game-setup&quot;&gt;Game Setup&lt;/h2&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter10/matrix_game.png&quot; alt=&quot;Line Segment&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Game Setup[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The payout matrix is the amount of reward J must give to R when J chooses strategy \(i\) (row) and R chooses strategy \(j\) (column) (\(P_{ij}\)). However, if this value is positive, J gives R a reward equal to the size of the corresponding matrix, and if negative, R gives J a reward equal to the size of the corresponding matrix.&lt;/p&gt;

&lt;p&gt;This setting is also called a zero-sum setting, where if the reward R will receive or must pay is \(r_{R}\) and J’s reward is \(r_{J}\), then in each game the result of the rewards is \(r_{R} = - r_{J}\), and the total sum of the two rewards is always 0.&lt;/p&gt;

&lt;p&gt;Also, we assume that both players use mixed strategies. Mixed strategies is the assumption that each player’s choice follows a specific probability distribution (or is sampled from a specific probability distribution).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x : P(\text{J chooses i}) = x_{i}, \qquad i=1,...,m\\\\
y : P(\text{R chooses j}) = y_{j}, \qquad j=1,...,n.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;If they know each other’s mixed strategy, i.e., probability distribution, each player can calculate the payout they expect to get, i.e., the expected payout.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\sum_{i=1}^{m}\sum_{j=1}^{n}x_{i}y_{j}P_{ij} = x^{T}Py.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Considering that the sign of the payout matrix is defined as the amount J gives to R, J will try to minimize this expected payout because J wants to give as little as possible to R, and R will try to maximize this expected payout because R wants to receive as much as possible from J.&lt;/p&gt;

&lt;p&gt;Now we will examine the perspective where each player considers the opponent’s mixed strategy to maximize (from R’s perspective) or minimize (from J’s perspective) this expected payout. Under the assumption that both players act optimally against each other, we will derive the optimal strategies from both perspectives and ultimately confirm that the two results are equal according to Von Neumann’s minimax theorem.&lt;/p&gt;

&lt;h2 id=&quot;minimizing-expected-payout--js-perspective&quot;&gt;Minimizing Expected Payout : J’s Perspective&lt;/h2&gt;
&lt;p&gt;First, assume that R knows J’s strategy \(x\). R will want to maximize the expected payout \(x^{T}Py\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\max\{x^{T}Py : y\geq0, 1^{T}y = 1\} = \max_{j=1,...,n}(P^{T}x)_{j}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;At this point, R will find the i (row index) that has the largest value among \((P^{T}x)_{i}\) as shown in the equation, and the strategy that sets the corresponding \(y_{i}\) to 1 and sets 0 for the remaining row indices will be the strategy that maximizes the expected payout for R.&lt;/p&gt;

&lt;p&gt;Knowing that R will act optimally as described above, J’s optimal strategy will be the distribution \(x\) that satisfies the following equation.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \min_{x}
&amp;amp; &amp;amp;\max_{j=1,...,n} (P^{T}x)_{j}\\\\
&amp;amp; \text{subject to}
&amp;amp; &amp;amp; x\geq 0, 1^{T}x =1.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The maximization of a convex function is also a convex function. We will call this the problem definition from the first perspective. Also, let’s define the solution to this optimization problem as the optimal expected payout \(f^{*}_{1}\). Another point to note is that the assumption that all game participants, i.e., players, act optimally is a fundamental assumption in basic game theory formulations.&lt;/p&gt;

&lt;h2 id=&quot;maximizing-expected-payout--rs-perspective&quot;&gt;Maximizing Expected Payout : R’s Perspective&lt;/h2&gt;
&lt;p&gt;From the second perspective, assume that J knows R’s strategy \(y\). J will want to minimize the expected payout.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\min \{x^{T}Py : x\geq0, 1^{T}x = 1\} = \min_{i=1,...,m}(Py)_{i}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;By the same logic, knowing that J will act optimally as described above, R’s optimal strategy is the distribution \(y\) that satisfies the following equation.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \max_{y}  
&amp;amp; &amp;amp; \min_{i=1,...,m} (Py)_{i}\\\\
&amp;amp;\text{subject to}
&amp;amp; &amp;amp;y\geq 0, 1^{T}y =1.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Similarly, we will call this the problem definition from the second perspective, and let the solution to this optimization problem be \(f^{*}_{2}\). Since player R wants to maximize this expected payout, we can easily expect that the expected payout \(f^{*}_{1}\) determined under the first assumption, i.e., that R knows J’s strategy in advance, will have a value greater than or equal to the second assumption. (\(f^{*}_{1}\geq f^{*}_{2}\))&lt;/p&gt;

&lt;h2 id=&quot;von-neumanns-minimax-theorem&quot;&gt;Von Neumann’s minimax theorem&lt;/h2&gt;
&lt;p&gt;However, according to Von Neumann’s minimax theorem, \(f^{*}_{1} = f^{*}_{2}\). The actual minimax theorem is as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\text{Let } X\subset \mathbb{R}^{m} \text{ and }Y\subset \mathbb{R}^{n} \text{ be compact convex sets. }\\\\
&amp;amp;\text{If } f:X\times Y\rightarrow \mathbb{R} \text{ is a continuous function that is convex-concave, i.e.}\\\\
&amp;amp;\qquad f(\cdot, y): X\rightarrow\mathbb{R} \text{ is convex for fixed }y, \text{ and}\\\\
&amp;amp;\qquad f(x, \cdot): Y\rightarrow\mathbb{R} \text{ is concave for fixed }x.\\\\
&amp;amp;\text{Then we have that} \\\\ 
&amp;amp;\min_{x\in X} \max_{y\in Y} f(x,y) = \max_{y\in Y} \min_{x\in X} f(x,y).\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The proof of this content is omitted.&lt;/p&gt;

&lt;h2 id=&quot;proof-of-each-perspective-having-primal-and-dual-relationship&quot;&gt;Proof of each perspective having Primal and Dual relationship&lt;/h2&gt;
&lt;p&gt;Now we want to show that the expected payouts for the above two perspectives have a primal-dual relationship as LP problems, and that strong duality is satisfied by using the fact that the two results are equal according to Von Neumann’s minimax theorem.&lt;/p&gt;

&lt;p&gt;First, the problem from the first perspective can be reformulated as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; \min_{x} \max_{j=1,...,n} 
&amp;amp; &amp;amp;(P^{T}x)_{j}\\\\
&amp;amp;\text{subject to } 
&amp;amp; &amp;amp;x\geq 0, 1^{T}x = 1\\\\
\end{align}\]

\[\begin{align}
\Leftrightarrow{} \\\\
&amp;amp; \min_{x,t}
&amp;amp; &amp;amp; t \\\\
&amp;amp;\text{subject to } 
&amp;amp; &amp;amp;x\geq0, 1^{T}x = 1, P^{T}x \preceq t. \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;We have reformulated the problem to make \(t\) equal to the largest value among the terms of \(P^{T}x\).&lt;/p&gt;

&lt;p&gt;Now, applying the second method of duality we learned earlier, we construct the Lagrangian and obtain the Lagrange dual function \(g\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;L(x, t, u, v, y) &amp;amp;&amp;amp;= t-u^{T}x+v(1-1^{T}x)+y^{T}(P^{T}x-t1)\\\\
&amp;amp;g(u, v, y) &amp;amp;&amp;amp;= \min_{x,t} \quad L(x, t, u, v, y)\\\\
&amp;amp;&amp;amp;&amp;amp;= \begin{cases} v \qquad &amp;amp;\text{if } 1-1^{T}y = 0, Py-u-v1=0\\\\
-\infty \qquad &amp;amp;\text{otherwise.} \end{cases}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Since \(u\) is a slack variable, removing it and organizing the equation gives us the following.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{y,v} \qquad \quad &amp;amp;&amp;amp; v\\\\
&amp;amp;\text{subject to }\quad &amp;amp;&amp;amp; y\geq0, 1^{T}y = 1\\\\
&amp;amp;&amp;amp;&amp;amp; Py\geq v.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This is the primal LP of the problem from the second perspective. Therefore, the two perspectives are in a dual relationship and since the optimal values of the two problems are equal, strong duality holds.&lt;/p&gt;

&lt;p&gt;In general, for LP problems, as we will cover in future content, strong duality holds if only one of the primal and dual is feasible.&lt;/p&gt;

&lt;h3 id=&quot;a-matrix-game-minimax-and-duality-video&quot;&gt;A matrix game: minimax and duality (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/matrix-game_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;J minimises the highest line, R maximises the lowest one, and both reach the same value: the minimax theorem, which is LP duality.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-the-game-from-both-sides&quot;&gt;Try it yourself: the game from both sides&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;mgame&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>10-04 Another Perspective on LP duality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_04_Another_Perspective_on_LP_duality/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_04_Another_Perspective_on_LP_duality</id>
   <content type="html">&lt;p&gt;Up to now, we derived the LP dual by manually combining inequalities—a clean trick for linear programs, but one that stops working the moment constraints become nonlinear. Here we unlock a far more powerful viewpoint: fold the constraints directly into the objective via a &lt;strong&gt;Lagrangian&lt;/strong&gt; \(L(x, u, v) = c^\top x + u^\top(Gx - h) + v^\top(Ax - b)\), and minimize \(L\) over &lt;em&gt;unconstrained&lt;/em&gt; \(x \in \mathbb{R}^n\)! Not only does this reproduce the exact same LP dual in two lines—it serves as the universal bridge to general nonlinear and convex duality in Chapter 11.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-lagrangian-bridge-from-lps-to-general-duality&quot;&gt;Key ideas: The Lagrangian Bridge from LPs to General Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Soft Penalty Relaxation:&lt;/strong&gt; For any primal-feasible \(x\) (\(Ax = b, Gx \le h\)) and any \(u \ge 0\), the extra terms \(u^\top(Gx - h) \le 0\) and \(v^\top(Ax - b) = 0\) can only &lt;em&gt;decrease&lt;/em&gt; the objective: \(L(x, u, v) \le c^\top x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Unconstrained Infimum as Dual Function:&lt;/strong&gt; Minimizing \(L(x, u, v)\) over all \(x \in \mathbb{R}^n\) (dropping constraints entirely!) gives \(g(u, v) = \inf_x L(x, u, v) \le \min_{x \in C} L(x, u, v) \le p^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Why Linear Infima Create Hard Dual Constraints:&lt;/strong&gt; Rewriting \(L(x, u, v) = (c + G^\top u + A^\top v)^\top x - h^\top u - b^\top v\) shows that a linear function of \(x\) is bounded below on \(\mathbb{R}^n\) &lt;em&gt;if and only if&lt;/em&gt; its slope is zero: \(c + G^\top u + A^\top v = 0\). Otherwise \(\inf_x L = -\infty\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Domain Restriction = Dual Feasibility:&lt;/strong&gt; Maximizing \(g(u, v)\) over \(u \ge 0\) automatically restricts \((u, v)\) to the finite domain \(c + G^\top u + A^\top v = 0\), recovering the exact LP dual without guessing a single multiplier sign.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-inf_x-lx-u-v-explicitly&quot;&gt;Worked example: Computing \(\inf_x L(x, u, v)\) Explicitly&lt;/h3&gt;

&lt;p&gt;Consider the 1D LP: minimize \(3x\) subject to \(x \ge 2\) (written as \(-x + 2 \le 0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the Lagrangian with dual multiplier \(u \ge 0\):&lt;/strong&gt;
\(L(x, u) = 3x + u(-x + 2) = (3 - u)x + 2u.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize \(L(x, u)\) over all unconstrained \(x \in \mathbb{R}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;If \(3 - u &amp;gt; 0\) (i.e., \(u &amp;lt; 3\)), sending \(x \to -\infty\) drives \(L(x, u) \to -\infty\).&lt;/li&gt;
      &lt;li&gt;If \(3 - u &amp;lt; 0\) (i.e., \(u &amp;gt; 3\)), sending \(x \to +\infty\) drives \(L(x, u) \to -\infty\).&lt;/li&gt;
      &lt;li&gt;If \(3 - u = 0\) (i.e., \(u = 3\)), the \(x\)-term vanishes completely and \(L(x, 3) \equiv 6\) for every \(x \in \mathbb{R}\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write down the Lagrange dual function \(g(u)\):&lt;/strong&gt;
\(g(u) = \inf_{x \in \mathbb{R}} L(x, u) = \begin{cases} 6 &amp;amp; \text{if } u = 3, \\ -\infty &amp;amp; \text{otherwise.} \end{cases}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Maximize \(g(u)\) over \(u \ge 0\):&lt;/strong&gt; The only finite point is \(u^\star = 3\), yielding \(d^\star = 6 = 3(2) = p^\star\)! This exact mechanism—where an unbounded linear infimum enforces an equality constraint—generalizes seamlessly to nonlinear functions in Chapter 11.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In the case of duality discussed earlier, for LP, we multiplied the constraints of the primal problem by dual variables, obtained their linear combination, and then organized it to separate out the primal’s objective function to obtain a bound. The separated remaining terms (something in the formula below) served as the bound for the primal problem. That is, they became the objective function of the dual problem, and the conditions created during the formula development process became the constraints of the dual problem.
Writing this partial process (the part of the above content that separates out the primal objective function to obtain a bound) as a formula, it looks like this:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x)\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;Ax = b\\\\
&amp;amp; &amp;amp;&amp;amp;Gx \leq h\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;\text{for any }u,\, v\geq 0,\\\\
&amp;amp; &amp;amp;u^{T}(Ax-b) = 0\\\\
&amp;amp;{+} &amp;amp;v^{T}(Gx-h)\leq 0\\\\
&amp;amp;{=} &amp;amp;u^{T}(Ax-b) + v^{T}(Gx-h)\leq 0\\\\
&amp;amp;{\approx} &amp;amp;f(x)+\text{something}. \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;However, for optimization problems that are not linear programs, most cannot express the objective function as a linear combination of constraints.&lt;/p&gt;

&lt;p&gt;In this chapter, we examine the perspective of duality that is applicable to more universally common problems (all convex, most non-convex). We will find the duality of LP using this method called Lagrangian, and examine more detailed discussions in Chapter 11.&lt;/p&gt;

&lt;p&gt;Looking at the equations up to the linear combination form for the primal LP problem described above, we can understand the following relationship:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
c^{T}x\geq c^{T}x+\overbrace{u^{T} \underbrace{(Ax-b)} _ {=0}+\underbrace{v^{T}} _ {\geq 0} \underbrace{(Gx-h)} _ {\leq 0}} ^ {\leq 0} := L(x,u,v).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The right side of the inequality has a value less than or equal to the left side according to the conditions. Also, we define this expression as a function \(L(x, u, v)\) for x, u, v.
Here, if we call the set satisfying the constraints of the primal LP (primal feasible set) C, we can understand the following relationship:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
C =  \{ x: Ax=b, Gx\leq h \},
\end{align}\)
\(\begin{align}
f^{*}=\min_{x\in C} f(x) \geq \min_{x\in C}L(x,u,v)\geq \min_{x}L(x,u,v):=g(u,v).\\\\
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, \(g(u,v)\) becomes a lower bound of \(f^{*}\) for any u or \(v\) satisfying \(v\geq0\).
Let’s examine the lower bound value determined by \(g(u,v)\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
g(u,v) = min_{x} c^{T}x+u^{T}(Ax-b) + v^{T}(Gx-h) \\\\
= \min_{x} (c+A^{T}u+G^{T}v)^{T}x - b^{T}u-h^{T}v \\\\
\begin{cases}= -b^{T}u-h^{T}v \qquad &amp;amp;\text{if }\ c = -A^{T}u-G^{T}v \\\\
-\infty \qquad &amp;amp;\text{otherwise}.
\end{cases}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;As can be seen from the equation, when \(c = -A^{T}u-G^{T}v\) is not satisfied, it has a value of \(-\infty\) due to the \(x\) term.
Since we want to find the lower bound closest to \(f^{*}\), we want to find the value that maximizes \(g(u, v)\). This is \(-b^{T}u-h^{T}v\), the value when \(c = -A^{T}u-G^{T}v\) is satisfied, and this matches the Dual LP we obtained with the first method.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f^{*} \geq g(u,v), \qquad \text{provided } v \geq 0\\\\
\text{find the biggest lowerbound  } g(u,v)\\\\
\max_{u,v} g(u,v)\\\\
\text{s.t. }v \geq 0. 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This method is also applicable to other types of optimization problems that are not in LP form.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>10-03 Max flow and min cut</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_03_Max_flow_and_min_cut/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_03_Max_flow_and_min_cut</id>
   <content type="html">&lt;p&gt;In 1955, Soviet railway planners and RAND Corporation researchers independently asked two seemingly different questions about a directed transportation network: &lt;em&gt;What is the maximum tonnage of goods we can ship from source \(s\) to sink \(t\) without exceeding any link’s capacity?&lt;/em&gt; And &lt;em&gt;What is the smallest total capacity of edges an adversary would need to destroy to disconnect \(s\) from \(t\) completely?&lt;/em&gt; Ford and Fulkerson proved that these two numbers are always &lt;strong&gt;identical&lt;/strong&gt;—and through the lens of Chapter 10, that celebrated theorem is nothing other than LP strong duality combined with total unimodularity!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-max-flow--min-cut-through-lp-duality&quot;&gt;Key ideas: Max-Flow / Min-Cut Through LP Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Flow Conservation as Linear Equalities:&lt;/strong&gt; Modeling edge flows \(f_{ij} \in [0, c_{ij}]\) with \(\sum_i f_{ik} = \sum_j f_{kj}\) at every intermediate node \(k \notin \{s, t\}\) turns maximum flow into a pure linear program whose constraint matrix is a node-arc incidence matrix.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Dual Variables as Node Potentials &amp;amp; Cut Indicators:&lt;/strong&gt; Dualizing the max-flow LP assigns a potential \(b_i\) to each node (from flow conservation) and a nonnegative weight \(a_{ij} \ge 0\) to each edge (from capacity bounds \(f_{ij} \le c_{ij}\)), yielding the LP relaxation of minimum \(s\text{–}t\) cut: \(\min \sum_{(i,j)\in E} c_{ij} a_{ij}\) subject to \(a_{ij} \ge b_j - b_i\) with \(b_s = 0, b_t = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Weak Duality = Any Flow \(\le\) Any Cut:&lt;/strong&gt; Setting \(b_i = 0\) on the source side \(S\) and \(b_i = 1\) on the sink side \(T\) makes \(a_{ij} = 1\) precisely on edges crossing from \(S\) to \(T\), giving an immediate LP proof that \(\text{max flow} \le \text{min cut}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Integrality &amp;amp; Strong Duality:&lt;/strong&gt; Because the node-arc incidence matrix is totally unimodular (or by thresholding any optimal fractional potential \(b_i\) at a random level \(\theta \in (0, 1)\)), the dual LP always admits an exact \(0\text{–}1\) cut solution, proving \(\text{max flow} = \text{min cut}\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-max-flow-and-dual-min-cut-on-a-4-node-diamond-network&quot;&gt;Worked example: Computing Max-Flow and Dual Min-Cut on a 4-Node Diamond Network&lt;/h3&gt;

&lt;p&gt;Consider a directed graph with nodes \(\{s, u, v, t\}\) and five directed edges with capacities:
\((s, u): 3, \quad (s, v): 2, \quad (u, v): 1, \quad (u, t): 2, \quad (v, t): 3.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find a maximum primal flow \(f\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Send \(2\) units along \(s \to u \to t\).&lt;/li&gt;
      &lt;li&gt;Send \(1\) unit along \(s \to u \to v \to t\).&lt;/li&gt;
      &lt;li&gt;Send \(2\) units along \(s \to v \to t\).&lt;/li&gt;
      &lt;li&gt;Check capacities: \(f_{su} = 3 \le 3\), \(f_{sv} = 2 \le 2\), \(f_{uv} = 1 \le 1\), \(f_{ut} = 2 \le 2\), \(f_{vt} = 3 \le 3\) (every edge is saturated!).&lt;/li&gt;
      &lt;li&gt;Check conservation: at \(u\), in \(= 3\), out \(= 2 + 1 = 3\); at \(v\), in \(= 1 + 2 = 3\), out \(= 3\).&lt;/li&gt;
      &lt;li&gt;Total primal flow value: \(F = f_{su} + f_{sv} = 3 + 2 = 5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Construct a dual feasible solution (minimum \(s\text{–}t\) cut):&lt;/strong&gt;
Choose the cut \(S = \{s\}\), \(T = \{u, v, t\}\), which corresponds to node potentials \(b_s = 0\) and \(b_u = b_v = b_t = 1\).
    &lt;ul&gt;
      &lt;li&gt;Dual edge weights \(a_{ij} = \max(0, b_j - b_i)\): \(a_{su} = 1\), \(a_{sv} = 1\), and \(a_{uv} = a_{ut} = a_{vt} = 0\).&lt;/li&gt;
      &lt;li&gt;Dual objective (cut capacity): \(c_{su} a_{su} + c_{sv} a_{sv} = 3(1) + 2(1) = 5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Certify optimality:&lt;/strong&gt; Primal flow \(= 5 =\) dual cut capacity! Notice that \(S&apos; = \{s, u, v\}, T&apos; = \{t\}\) also has capacity \(c_{ut} + c_{vt} = 2 + 3 = 5\), showing that an LP dual can have multiple optimal minimum cuts.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;As an example of duality in linear programs, we want to examine the max flow min cut problem.&lt;/p&gt;

&lt;h2 id=&quot;directed-graph-condition-of-flow&quot;&gt;Directed Graph, Condition of flow&lt;/h2&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter10/max_flow.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Directed Graph[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;There is a directed graph \(G = (V, E)\) as shown above, and let the edge connecting vertex i and vertex j, \((i,j)\in E\), i.e., the flow from i to j, be \(f_{ij}\). Each edge has a capacity, i.e., the maximum flow that can flow through it. Let this be \(c_{ij}\).&lt;/p&gt;

&lt;p&gt;As a simple example, this can be understood as a graph representation of some flow from a source(s) flowing out to a sink(t). It is a graph form that can be applied to various problems such as urban drainage/power transmission planning, material transportation, etc.&lt;/p&gt;

&lt;p&gt;Here, the flow satisfies three conditions.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;\(f_{ij}\) is always a positive number greater than or equal to 0: \(f_{ij} \geq 0,\, (i,j)\in E\)&lt;/li&gt;
  &lt;li&gt;\(f_{ij}\) must not exceed the maximum flow allowed on the edge, i.e., the capacity \(c_{ij}\): \(f_{ij}\leq c_{ij}, \, (i,j)\in E\)&lt;/li&gt;
  &lt;li&gt;For vertex k excluding the source (the point where flow comes out, s) or sink (the point where flow goes out, t), the total amount of flow entering k equals the total amount of flow leaving k: \(\sum_{(i,k)\in E}f_{ik} = \sum_{(k,j)\in E}f_{kj}, \, k\in V\backslash{s,t}\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;relationship-between-max-flow-and-min-cut-problem1&quot;&gt;Relationship between Max flow and Min cut problem(1)&lt;/h2&gt;

&lt;p&gt;For the graph and flow defined above, we will examine two well-known problems, the max flow problem and the min cut problem, and the relationship between them.&lt;/p&gt;

&lt;p&gt;To conclude first, the max flow problem is an LP problem, and the min cut problem is an integer program, where the dual of the max flow problem has the same problem form as the LP relaxation of the min cut problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{Value of max flow} &amp;amp;\leq \text{dual LP of max flow}\\
&amp;amp;= \text{Optimal value for LP relaxed min cut}\\
&amp;amp;\leq \text{Capacity of min cut}\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In this page, we will show the inequality relationship by the reverse process of dual and relaxation (adding constraints to the LP problem to convert it to an integer program). Although not covered here, in reality, all three results are equal.&lt;/p&gt;

&lt;p&gt;This is called the max flow min cut theorem, which states that the maximum flow in a network is equal to the minimum capacity of a cut.&lt;/p&gt;

&lt;p&gt;More generally, under certain conditions, the optimal values of the primal and dual problems are equal, which is called strong duality.&lt;/p&gt;

&lt;p&gt;In LP problems, except for the case where both the primal and dual problems are infeasible, strong duality holds. This will be discussed in Chapter 11.&lt;/p&gt;

&lt;p&gt;First, let’s look at the two problems, derive the dual from the max flow problem, and show that by adding specific conditions to the dual problem (reverse of relaxation), it transforms into the min cut problem.&lt;/p&gt;

&lt;h2 id=&quot;max-flow-problem&quot;&gt;Max flow problem&lt;/h2&gt;

&lt;p&gt;The max flow problem is to find the maximum flow from s to t in a graph that satisfies the above conditions.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{f\in {\mathbb{R}^{|E|}}} &amp;amp;&amp;amp;{\sum_{(s,j)\in E} f_{sj}}\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;{f_{ij}\geq 0,\,f_{ij}\leq c_{i,j}\,\, \text{for all }(i, j)\in E}\\
&amp;amp;&amp;amp;&amp;amp;{\sum_{(i, k)\in E}f_{ik}=\sum_{(k,j)\in E}f_{kj}}\,\, \text{for all }k\in V \backslash \{s,t\}.\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;min-cut-problem&quot;&gt;Min cut problem&lt;/h2&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter10/min_cut.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 2] Graph Cut Example[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The min cut problem divides all vertices of the graph into two sets: the shaded region and the unshaded region, as shown in the figure. One set contains the source, and the other contains the sink, while the remaining vertices are arbitrarily assigned to either set (here, the set containing the source is called A, and the set containing the sink is called B). The sum of the capacities of the edges going from set A to set B is defined as the cut.&lt;/p&gt;

&lt;p&gt;In other words, a cut is a partition of the graph’s vertices such that the source and sink are in different partitions. The min cut problem is to find the minimum value of this cut for a given graph. In the general definition of the min cut problem, since it is defined on a directed graph, it always satisfies source \(x_{s}=1\), sink \(x_{t}=0\). This part is omitted in the problem definition below.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{b\in {\mathbb{R}^{|E|}},\, x \in {\mathbb{R}^{|V|}} } &amp;amp;&amp;amp;{\sum_{(i,j)\in E} b_{ij}c_{ij}}\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;{b_{ij} \geq x_{i}-x_{j}}\\
&amp;amp;&amp;amp;&amp;amp;{b_{ij},\,x_{i},\,x_{j}\,\in \{ 0,1 \} }\\
&amp;amp;&amp;amp;&amp;amp;\text{for all }i, j.\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Intuitively, the max flow problem is to find the maximum flow from the source, and the min cut problem is to find the minimum total capacity that can be sent from the source set to the sink set, so it is clear that these two problems are closely related.&lt;/p&gt;

&lt;h2 id=&quot;dual-of-max-flow-problem&quot;&gt;Dual of Max flow problem&lt;/h2&gt;
&lt;p&gt;Let’s derive the dual for the max flow optimization problem.&lt;/p&gt;

&lt;p&gt;First, define the dual variables for the constraints in order as \(a_{ij}, b_{ij}, x_{k}\). In the dual of the max problem, the upper bound will be minimized, so the organized form should be in the form of primal objective \(\leq\) something. Therefore, organize the equation to find the upper bound of \(f_{ij}\) for the constraints.
This can be organized as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\sum_{(i,j)\in E} {\Big(-a_{ij}f_{ij}+b_{ij}(f_{ij}-c_{ij})\Big)} + \sum_{k \in V\backslash \{s,t\}} x_{k}\Big( \sum_{(i,k)\in E} f_{ik} - \sum_{(k,j)\in E } f_{kj} \Big)\leq 0\\
\text{for any }a_{ij}, b_{ij} \geq 0, (i, j)\in E, \text{ and } x_{k}, k\in V \backslash \{s,t\}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Organize the \(f\) terms related to the primal LP objective function on the left, and the rest on the right.&lt;/p&gt;

&lt;p&gt;Next, since we want the upper bound of the primal LP, find the equation such that the terms multiplied by \(f\) on the left match the primal LP objective function.&lt;/p&gt;

&lt;p&gt;The condition that satisfies this equation becomes the constraint in the dual LP.&lt;/p&gt;

&lt;p&gt;That is, organize the equation so that the \(f_{ij}\) term is 1 only in \(\sum_{(s,j)\in E}f_{sj}\) and 0 elsewhere.&lt;/p&gt;

&lt;p&gt;This process is detailed as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\sum_{(i,j)\in E}{\Big((b_{ij}-a_{ij})f_{ij}\Big)}+\sum_{k\in V\backslash \{s,t\}}{x_{k}\Big(\sum_{(i,k)\in E}{f_{ik}}-\sum_{(k,j)\in E}{f_{kj}}\Big)} \leq \sum_{(i,j)\in E}b_{ij}c_{ij}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, our goal is to make the result of the left side when \(i=s\) be \(\sum_{(s,j)\in E}f_{sj}\) and 0 for other cases.&lt;/p&gt;

&lt;p&gt;The k in the x term of the second sigma does not include the source and sink, and can be divided into three cases: when \(i=s, j\neq t\), when \(i\neq s, j=t\), and when \(i\neq s,j\neq t\).&lt;/p&gt;

&lt;h3 id=&quot;case-1-i--s-j-neq-t&quot;&gt;Case 1. \(i = s, j \neq t.\)&lt;/h3&gt;

&lt;p&gt;For the term multiplied by \(x_{k}\), it is eliminated by the third condition of flow except for the case of \(k=j\).
Therefore, the sigma for the x term of the second term can be organized as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;=\sum_{(s,j)\in E}{\Big((b_{sj}-a_{sj})f_{sj}\Big)}+x_{j}\sum_{(s,j)\in E}{f_{sj}}+\sum_{k\in V\backslash \{s,t,j\}}{x_{k}\Big(\underbrace{\sum_{(s,k)\in E}{f_{sk}}-\sum_{(k,j)\in E}{f_{kj}}}_{=0}\Big)} \\\\
&amp;amp;=\sum_{(s,j)\in E}{\Big(b_{sj}-a_{sj}+x_{j}\Big)f_{sj}}, \ j \in V \backslash \{s,t\},\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;case-2-i-neq-s-j--t&quot;&gt;Case 2. \(i \neq s, j = t.\)&lt;/h3&gt;
&lt;p&gt;For the term multiplied by \(x_{k}\), it is eliminated by the third condition of flow except for the case of \(k=i\).
Therefore, the sigma for the x term of the second term can be organized as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;=\sum_{(i,t)\in E}{\Big((b_{it}-a_{it})f_{it}\Big)}-x_{i}\sum_{(i,t)\in E}{f_{it}}+\sum_{k\in V\backslash \{s,t,i\}}{x_{k}\Big(\underbrace{\sum_{(i,k)\in E}{f_{ik}}-\sum_{(k,t)\in E}{f_{kt}}}_{=0}\Big)} \\\\
&amp;amp;=\sum_{(i,t)\in E}{\Big(b_{it}-a_{it}-x_{i}\Big)f_{it}}, \ i \in V\backslash \{s,t\},\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;case-3-i-neq-s-j-neq-t&quot;&gt;Case 3. \(i \neq s, j \neq t.\)&lt;/h3&gt;
&lt;p&gt;For the term multiplied by \(x_{k}\), it is eliminated by the third condition of flow except for the cases of \(k=i\) and \(k=j\).
Therefore, the sigma for the x term of the second term can be organized as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;=\sum_{(i,j)\in E}{\Big((b_{ij}-a_{ij})f_{ij}\Big)}+x_{j}\sum_{(i,j)\in E}{f_{ij}}-x_{i}\sum_{(i,j)\in E}{f_{ij}}+\sum_{k\in V\backslash \{s,t,i,j\}}{x_{k}\Big(\underbrace{\sum_{(i,k)\in E}{f_{ik}}-\sum_{(k,j)\in E}{f_{kj}}}_{=0}\Big)} \\\\
&amp;amp;=\sum_{(i,j)\in E}{\Big(b_{ij}-a_{ij}+x_{j}-x_{i}\Big)f_{ij}}, \ i, j \in V \backslash \{s,t\}. \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The objective function of the primal LP matches with the case 1 of the above, where the term is 1 in \(b_{sj}-a_{sj}+x_{j}\), and for the other cases, it makes the multiplied term 0, completing the form of left side being the objective function and the right side being the upper bound.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;b_{sj}-a_{sj}+x_{j} = 1\\\\
&amp;amp;b_{it}-a_{it}-x_{i} = 0\\\\
&amp;amp;b_{ij}-a_{ij}+x_{j}-x_{i} = 0\\\\
&amp;amp;\text{Result in,} \\\\
&amp;amp;\sum_{(s,j)\in E}{f_{sj}} \leq \sum_{(i,j)\in E}{b_{ij}c_{ij}}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore, the dual problem is to find the minimum value of the upper bound (objective function of dual LP) for the dual variables \(a, b, x\), and this minimum value becomes the best upper bound. A dummy variable \(a\) is eliminated while maintaining the conditions. Additionally, by adding the condition that flow occurs from source to sink in the directed graph, the equation becomes:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{b\in {\mathbb{R}^{|E|}},\, x\in{\mathbb{R}^{|V|}}}  &amp;amp;&amp;amp;{\sum_{(i,j)\in E} b_{ij}c_{ij}} \\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;{b_{ij}+x_{j}-x_{i}\geq 0 \,\, \text{for all } (i,j)\in E}\\\\
&amp;amp;&amp;amp;&amp;amp;{b\geq 0, x_{s}=1,x_{t}=0}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;dual-lp-to-integer-program&quot;&gt;Dual LP to Integer program&lt;/h2&gt;
&lt;p&gt;Now, we want to show that this dual LP is the same as the LP relaxation of the min cut problem.
Therefore, we will go through the process of converting it to an integer program by adding conditions to the above dual LP problem.
The variable \(x\) is not defined for vertices other than s and t.
Therefore, to narrow the scope of the problem, let’s add a condition that the remaining vertices except s and t belong to either group s or t.
In other words, let’s assume that all vertices belong to either group 0 or 1. This is equivalent to determining the vertex partition for the min cut.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x_{i} \in \{0,1 \} \ \ \text{ for all }i\in V.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Let’s define the group that belongs to 1 as set A, and the group that belongs to 0 as set B. Also, let’s define that the source (s) belongs to A, and the sink (t) belongs to B.&lt;/p&gt;

&lt;p&gt;With the above definitions, \(b_{ij}\) acts as an on/off switch, being 1 for edges going from set A to set B, and 0 otherwise.&lt;/p&gt;

&lt;p&gt;This can be organized as follows.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\begin{align}
&amp;amp;\text{Let } A= \{ i:x_{i}=1 \} ,\, B= \{ i:x_{i}=0 \} \\\\
&amp;amp;\text{note that  } s \in A, \,t \in B, \text{ and  }b_{ij}\geq x_{i}-x_{j} \,\,\,\, \text{for }\,(i,j) \in E, \,\, b\geq 0,\\\\
\end{align}\)
\(\begin{align}
\text{Simply say, } \qquad \begin{cases} b_{ij}=1 \qquad \text{if } i\in A, j\in B\\\\
0 \qquad\qquad \text{otherwise}.\end{cases}
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The above result is the same as the formulation of the min cut problem.&lt;/p&gt;

&lt;h2 id=&quot;relationship-between-max-flow-and-min-cut-problem2&quot;&gt;Relationship between Max flow and Min cut problem(2)&lt;/h2&gt;
&lt;p&gt;That is, the dual problem of the max flow problem is the result of removing the condition that the vertices except s and t in the min cut problem are included in 0 or 1 (relaxation). The optimal value of max flow \(\leq\) dual LP (upper bound), and this relaxation expands the domain scope of the optimization variable, so the optimal value LP relaxed min cut \(\leq\) capacity of min cut. Summarizing these three results, we get the following result.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{Value of max flow} &amp;amp;\leq \text{Dual LP of max flow}\\\\
&amp;amp;= \text{Optimal value for LP relaxed min cut}\\\\
&amp;amp;\leq \text{Capacity of min cut}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;For the equality of these three results, refer to the max-flow min-cut theorem[11], and for a representative algorithm for solving the max flow min cut problem, refer to the Ford-Fulkerson algorithm[12].&lt;/p&gt;

&lt;h3 id=&quot;max-flow-and-min-cut-in-about-3-minutes&quot;&gt;Max flow and min cut in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/max-flow-min-cut_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;A 6-node network: augmenting paths, the residual graph with reverse edges, the min cut equal to the flow value, and the link to LP duality.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>10-02 Duality in general LPs</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_02_Duality_in_general_LPs/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_02_Duality_in_general_LPs</id>
   <content type="html">&lt;p&gt;Once you see how multiplier weights generate lower bounds on 2-variable examples, lifting the same construction to general matrix-vector linear programs \(\min \{c^\top x : Ax = b,\; Gx \le h\}\) takes just three lines of linear algebra. Instead of memorizing arbitrary sign tables, writing the constraints in matrix form shows immediately how \(A\) and \(G\) transpose into the dual constraints \(-A^\top v - G^\top u = c\) and why the dual objective becomes \(-b^\top v - h^\top u\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-matrix-mechanics-of-general-lp-duality&quot;&gt;Key ideas: Matrix Mechanics of General LP Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Transposition of Constraint Matrices:&lt;/strong&gt; Primal constraints map \(x \in \mathbb{R}^n\) to \(m\) equalities (\(Ax = b\)) and \(r\) inequalities (\(Gx \le h\)). Dual multipliers \(v \in \mathbb{R}^m\) and \(u \in \mathbb{R}_+^r\) map back via \(A^\top\) and \(G^\top\) into \(\mathbb{R}^n\), coupling every primal variable to one dual constraint.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Sign Correspondence Dictionary:&lt;/strong&gt; Equality primal constraints (\(Ax = b\)) yield &lt;em&gt;unconstrained&lt;/em&gt; dual variables \(v \in \mathbb{R}^m\); inequality primal constraints (\(Gx \le h\)) yield &lt;em&gt;nonnegative&lt;/em&gt; dual variables \(u \ge 0\). Conversely, unrestricted primal variables \(x \in \mathbb{R}^n\) yield &lt;em&gt;equality&lt;/em&gt; dual constraints \(-A^\top v - G^\top u = c\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Standard Form Special Case:&lt;/strong&gt; When the primal is \(\min \{c^\top x : Ax = b,\; x \ge 0\}\) (i.e., \(G = -I, h = 0\)), eliminating \(u \ge 0\) from \(-A^\top v + u = c\) produces the famous compact dual \(\max \{b^\top y : A^\top y \le c\}\) (where \(y = -v\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Primal–Dual Dimension Swap:&lt;/strong&gt; A primal with \(n\) variables and \(m + r\) constraints produces a dual with \(m + r\) variables and \(n\) constraints—so when \(n \gg m + r\), solving the dual can be dramatically faster than solving the primal directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-dualizing-a-mixed-equalityinequality-lp-in-matrix-form&quot;&gt;Worked example: Dualizing a Mixed Equality/Inequality LP in Matrix Form&lt;/h3&gt;

&lt;p&gt;Consider the primal LP:
\(\min_{x \in \mathbb{R}^2}\; 2x_1 - x_2 \quad \text{s.t.} \quad x_1 + x_2 = 4, \quad x_1 \le 3, \quad -x_2 \le 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify the matrices \(c, A, b, G, h\):&lt;/strong&gt;
\(c = \begin{pmatrix}2 \\ -1\end{pmatrix}, \quad A = \begin{pmatrix}1 &amp;amp; 1\end{pmatrix}, \quad b = (4), \quad G = \begin{pmatrix}1 &amp;amp; 0 \\ 0 &amp;amp; -1\end{pmatrix}, \quad h = \begin{pmatrix}3 \\ 0\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Introduce dual variables \(v \in \mathbb{R}\) (for \(Ax = b\)) and \(u = (u_1, u_2)^\top \ge 0\) (for \(Gx \le h\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Dual objective: \(-b^\top v - h^\top u = -4v - 3u_1 - 0 \cdot u_2 = -4v - 3u_1\).&lt;/li&gt;
      &lt;li&gt;Dual constraints \(-A^\top v - G^\top u = c\):
\(-\begin{pmatrix}1\\1\end{pmatrix} v - \begin{pmatrix}u_1 \\ -u_2\end{pmatrix} = \begin{pmatrix}2 \\ -1\end{pmatrix} \implies \begin{cases} -v - u_1 = 2, \\ -v + u_2 = -1, \end{cases} \quad u_1, u_2 \ge 0.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the dual by inspection:&lt;/strong&gt; From the second equation, \(v = 1 + u_2 \ge 1\); from the first, \(u_1 = -2 - v \ge 0 \implies v \le -2\)… wait: \(v \ge 1\) and \(v \le -2\) cannot both hold! Let’s check why:
Wait—in the primal, \(x_1 + x_2 = 4\), \(x_1 \le 3\), \(x_2 \ge 0\) gives \(x_2 = 4 - x_1 \ge 1\), so \(x_1\) can go to \(-\infty\) (\(x_1 = -100, x_2 = 104\) is feasible with objective \(2(-100) - 104 = -304 \to -\infty\))!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Aha! Duality caught unboundedness automatically:&lt;/strong&gt; The primal is &lt;strong&gt;unbounded below&lt;/strong&gt; (\(p^\star = -\infty\)), which by weak duality &lt;em&gt;forces&lt;/em&gt; the dual to be &lt;strong&gt;infeasible&lt;/strong&gt;—a textbook demonstration of how dual feasibility certifies primal boundedness!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In &lt;a href=&quot;/contents/en/chapter10/10_01_Lower_Bounds_in_Linear_Programs/&quot;&gt;10-01&lt;/a&gt;, we examined the primal and dual of LP problems with single-dimensional variables. In 10-02, we want to examine the dual for LPs in general form.&lt;/p&gt;

&lt;p&gt;The general form of LP is as follows:&lt;/p&gt;

&lt;p&gt;Given \(c\in\mathbb{R}^{n},\, A\in\mathbb{R}^{m\times n},\, b\in\mathbb{R}^{m},\, G\in\mathbb{R}^{r\times n},\, h\in\mathbb{R}^{r}\),&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;c^{T}x\\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;Ax = b\\\\
&amp;amp; &amp;amp;&amp;amp;Gx \leq h.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Similar to the example in 10-01, we define dual variables \(u, v\) equal in number to the number of constraints,
and can define the objective function of the dual problem and constraints as the sum of products of constraints and each dual variable.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;u^{T}(Ax-b) = 0\\\\
&amp;amp;{+} &amp;amp;v^{T}(Gx-h)\leq 0\\\\
&amp;amp;{=} &amp;amp;u^{T}(Ax-b) + v^{T}(Gx-h)\leq 0.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Remember that the dual variable \(u\) for equality has no constraints, while \(v\) is a dual variable for inequality and thus has the additional constraint of being positive.
By organizing the last equation to represent the objective function of the primal LP, we get the dual LP.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
u^{T}(Ax-b) + v^{T}(Gx-h)\leq 0 \\\\
\underbrace{(-A^{T}u-G^{T}v)^{T}}_{=c^{T}}x\geq-b^{T}u-h^{T}v \\\\
\text{Lower bound is} -b^{T}u-h^{T}v \\\\ 
\text{for } x \text{ primal feasible, and any u, v satisfies,} \\\\
c = -A^{T}u-G^{T}v \\\\
v\geq 0. \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;That is, when \(c = -A^{T}u-G^{T}v\), the optimal value of the primal has a lower bound of \(-b^{T}u-h^{T}v\).&lt;/p&gt;

&lt;p&gt;Consequently, the dual LP can be defined as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{u,v} &amp;amp;&amp;amp;-b^{T}u-h^{T}v \\\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;c = -A^{T}u-G^{T}v \\\\
&amp;amp; &amp;amp;&amp;amp;v\geq 0.
\end{align}\]
&lt;/blockquote&gt;

</content>
 </entry>
 
 <entry>
   <title>10-01 Lower Bounds in Linear Programs</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_01_Lower_Bounds_in_Linear_Programs/"/>
   <updated>2021-03-22T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter10/10_01_Lower_Bounds_in_Linear_Programs</id>
   <content type="html">&lt;p&gt;How do you prove a lower bound on the minimum value of a linear program without ever running the simplex method? The trick is as elementary as high-school algebra, yet it is the entire conceptual seed of duality theory: multiply each inequality constraint by a &lt;strong&gt;nonnegative&lt;/strong&gt; weight (so the inequality sign never flips), add them up so the left-hand side matches the objective function \(c^\top x\), and read off the resulting number on the right-hand side! Maximizing that right-hand side over all valid multiplier weights &lt;em&gt;is&lt;/em&gt; the dual linear program.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-building-lower-bounds-from-linear-combinations&quot;&gt;Key ideas: Building Lower Bounds from Linear Combinations&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Sign Preservation Under Nonnegative Multipliers:&lt;/strong&gt; Multiplying \(a^\top x \ge b\) by \(u \ge 0\) preserves the direction \(u a^\top x \ge u b\); multiplying an equality \(a^\top x = b\) by &lt;em&gt;any&lt;/em&gt; \(v \in \mathbb{R}\) preserves equality. This sign discipline is why inequality dual variables are constrained (\(u \ge 0\)) while equality dual variables are free (\(v \in \mathbb{R}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Matching Objective Coefficients (Dual Feasibility):&lt;/strong&gt; To conclude \(c^\top x \ge B\) for all feasible \(x\), the combined constraint coefficients on \(x\) must match \(c\) (or be \(\le c\) when \(x \ge 0\)). Those coefficient-matching equations are literally the &lt;strong&gt;dual constraints&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Tightening the Lower Bound (Dual Objective):&lt;/strong&gt; Any valid choice of multipliers yields &lt;em&gt;some&lt;/em&gt; lower bound \(B(u, v) \le p^\star\). Searching for the &lt;em&gt;best&lt;/em&gt; (largest) lower bound turns the bound-finding game into a maximization LP: \(\max_{u, v} B(u, v)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Weak Duality as an Immediate Corollary:&lt;/strong&gt; Because every dual-feasible \((u, v)\) constructs a valid inequality \(c^\top x \ge B(u, v)\) for every primal-feasible \(x\), we obtain \(d^\star \le p^\star\) automatically with zero extra proof machinery.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-deriving-the-tightest-lower-bound-by-hand&quot;&gt;Worked example: Deriving the Tightest Lower Bound by Hand&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x, y) = 4x + 5y\) subject to \(x + 2y \ge 6\), \(3x + y \ge 8\), and \(x, y \ge 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Assign nonnegative multipliers \(u_1, u_2 \ge 0\) to the two resource constraints:&lt;/strong&gt;
\(u_1(x + 2y) + u_2(3x + y) \ge 6u_1 + 8u_2 \implies (u_1 + 3u_2)x + (2u_1 + u_2)y \ge 6u_1 + 8u_2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enforce the bound \(4x + 5y \ge (u_1 + 3u_2)x + (2u_1 + u_2)y\) for all \(x, y \ge 0\):&lt;/strong&gt;
Since \(x \ge 0\) and \(y \ge 0\), this holds whenever:
\(u_1 + 3u_2 \le 4 \quad \text{and} \quad 2u_1 + u_2 \le 5, \qquad u_1, u_2 \ge 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Maximize the lower bound \(6u_1 + 8u_2\):&lt;/strong&gt;
At the intersection of both dual constraints: \(u_1 + 3u_2 = 4\) and \(2u_1 + u_2 = 5\).
    &lt;ul&gt;
      &lt;li&gt;From the first: \(u_1 = 4 - 3u_2\).&lt;/li&gt;
      &lt;li&gt;Substitute into the second: \(2(4 - 3u_2) + u_2 = 5 \implies 8 - 5u_2 = 5 \implies u_2^\star = 0.6\), and \(u_1^\star = 4 - 1.8 = 2.2\).&lt;/li&gt;
      &lt;li&gt;Best lower bound: \(6(2.2) + 8(0.6) = 13.2 + 4.8 = 18.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify against the primal intersection:&lt;/strong&gt; Solving \(x + 2y = 6\) and \(3x + y = 8\) gives \(x^\star = 2, y^\star = 2\), with primal value \(4(2) + 5(2) = 18.0\)—matching the dual bound to the last decimal!&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;h2 id=&quot;example-1-form-where-the-constraint-contains-the-objective-function&quot;&gt;Example 1: Form where the constraint contains the objective function&lt;/h2&gt;

&lt;p&gt;Suppose we want to find the lower bound value B of the optimal value for a given convex problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
B \leq \min_{x} f(x).
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Let’s specifically consider the lower bound of linear programs. We will examine cases ranging from simple cases to generalized forms in order.
First, taking the simplest form of LP problem as an example&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y}  
&amp;amp; &amp;amp;{x+y} \\\\
&amp;amp;\text{subject to} 
&amp;amp; &amp;amp;{x + y \geq 2}\\\\
&amp;amp; &amp;amp; &amp;amp;{x, y \geq 0.}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The above problem already includes the lower bound of the objective function in the constraint, so we can easily see that \(B=2\).&lt;/p&gt;

&lt;p&gt;Furthermore, let’s examine the case where the constraint does not include a lower bound.&lt;/p&gt;

&lt;h2 id=&quot;example-2-form-where-the-objective-function-can-be-expressed-as-a-linear-combination-of-constraints-1&quot;&gt;Example 2: Form where the objective function can be expressed as a linear combination of constraints (1)&lt;/h2&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y}  
&amp;amp; &amp;amp; {x+3y} \\\\
&amp;amp;\text{subject to} 
&amp;amp; &amp;amp;{x + y \geq 2}\\\\
&amp;amp; &amp;amp; &amp;amp;{x, y \geq 0.}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;If \(x,\, y\) are feasible, then multiplying the three constraints by scalar values and adding or subtracting them still satisfies all three constraints. Therefore, for such an LP problem, the process of multiplying constraints by scalar values and adding or subtracting them, i.e., expressing the objective function as a linear combination of constraints, is possible, and as a result, we can find \(B\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;{x + y \geq 2}\\\\
&amp;amp;{+} &amp;amp;{0x \geq 0}\\\\
&amp;amp;{+} &amp;amp;{2y \geq 0}\\\\
&amp;amp;{=} &amp;amp;{x + 3y \geq 2}\\\\

&amp;amp; &amp;amp;{\text{Lower bound}\ B = 2.}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Generalizing further by applying arbitrary variables to represent the objective function, we get the following:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y}  
&amp;amp; &amp;amp;{px+qy} \\\\
&amp;amp;\text{subject to} 
&amp;amp; &amp;amp;{x + y \geq 2}\\\\
&amp;amp; &amp;amp; &amp;amp;{x, y \geq 0.}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Similar to the second example, by multiplying the constraints by scalar values a, b, c respectively, the objective function can be expressed as a linear combination of these three.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; &amp;amp;{a(x+y) \geq 2a} \\\\
&amp;amp;{+} &amp;amp;{bx \geq 0} \\\\
&amp;amp;{+} &amp;amp;{cy \geq 0} \\\\
&amp;amp;{=} &amp;amp;{(a+b)x+(a+c)y \geq 2a} \\\\
&amp;amp;&amp;amp;\text{Lower bound}\ B=2a, \\
&amp;amp;&amp;amp;\text{for any satisfying a,b,c below}\\\\
&amp;amp; &amp;amp;{a + b = p}\\\\
&amp;amp; &amp;amp;{a + c = q}\\\\
&amp;amp; &amp;amp;{a,b,c \geq 0.}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;For the lower bound to satisfy being 2a as above, since the inequality sign would be reversed in the process of multiplying by scalar values and this would not hold, the conditions \(a, b, c\) must be positive and the sum of scalar values must equal the objective function, i.e., the conditions \(a+b = p\) and \(a+c = q\) must be satisfied.&lt;/p&gt;

&lt;p&gt;A new optimization problem can be defined by maximizing the lower bound result obtained as above. In this case, the conditions that satisfy the lower bound become the constraints in this problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\max_{a, b, c}  
&amp;amp; &amp;amp;{2a} \\\\
&amp;amp;\text{subject to} 
&amp;amp; &amp;amp;{a + b = p}\\\\
&amp;amp; &amp;amp; &amp;amp;{a + c = q}\\\\
&amp;amp; &amp;amp; &amp;amp;{a, b, c \geq 0}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The original LP problem above is called the primal LP, and the form that redefines the optimization problem by maximizing the lower bound in the primal LP is called the dual LP. Note that the number of optimization variables in the dual problem equals the number of constraints in the primal problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{Primal LP}\qquad
&amp;amp;\qquad \min_{x, y}  &amp;amp;{px+qy} \\\\
&amp;amp;\qquad \text{subject to} &amp;amp;{x + y \geq 2}\\\\
&amp;amp;\qquad &amp;amp;{x, y \geq 0}\\\\
\\\\
\\\\
\text{Dual LP}\qquad
&amp;amp;\qquad \max_{a, b, c}  &amp;amp;{2a} \\\\
&amp;amp;\qquad \text{subject to} &amp;amp;{a + b = p}\\\\
&amp;amp;\qquad &amp;amp;{a + c = q}\\\\
&amp;amp;\qquad &amp;amp;{a, b, c \geq 0}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;example-3-form-where-the-objective-function-can-be-expressed-as-a-linear-combination-of-constraints-2&quot;&gt;Example 3: Form where the objective function can be expressed as a linear combination of constraints (2)&lt;/h2&gt;

&lt;p&gt;As a final example, let’s examine a form where the inequality signs in the constraints are reversed and equality constraints are included.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x, y}  &amp;amp;{px+qy} \\\\
&amp;amp;\text{subject to} &amp;amp;{x \geq 0}\\\\
&amp;amp; &amp;amp;{y \leq 1}\\\\
&amp;amp; &amp;amp;{3x + y = 2}\\\\
\\\\
&amp;amp; &amp;amp;{ax \geq 0}\\\\
&amp;amp;{+} &amp;amp;{-by \geq -b}\\\\
&amp;amp;{+} &amp;amp;{3cx + cy = 2c}\\\\
&amp;amp;{=} &amp;amp;{(a+3c)x+(-b+c)y \geq 2c-b}
\\\\
\\\\
&amp;amp;&amp;amp; \text{Lower bound}  \ B=2c-b, \\
&amp;amp;&amp;amp; \text{for any satisfying a,b,c below}\\\\
&amp;amp; &amp;amp;{a + 3c = p}\\\\
&amp;amp; &amp;amp;{-b + c = q}\\\\
&amp;amp; &amp;amp;{a,b \geq 0}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, c is a scalar value multiplied to both sides of the equality, so any value can be multiplied without restriction.&lt;/p&gt;

&lt;p&gt;Consequently, the dual LP can be defined as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\qquad \max_{a, b, c}  &amp;amp;{2c-b} \\\\
&amp;amp;\qquad \text{subject to} &amp;amp;{a + 3c = p}\\\\
&amp;amp;\qquad &amp;amp;{-b + c = q}\\\\
&amp;amp;\qquad &amp;amp;{a, b \geq 0}\\\\
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>06-11 Bài Tập Thực Hành - Thuật toán Tối ưu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_11_Practical_Exercises_Optimization_Algorithms/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_11_Practical_Exercises_Optimization_Algorithms</id>
   <content type="html">&lt;p&gt;Đọc định lý rằng Heavy Ball (Momentum) tăng tốc từ \(\kappa\) xuống \(\sqrt{\kappa}\) hay Backtracking tự thích ứng bước luôn thú vị, nhưng chỉ khi bạn tự tay viết vòng lặp tính số, vẽ đường cong log-sai số \(\log(f(x^{(k)}) - f^\star)\) và chứng kiến đường thẳng dốc đứng của hội tụ tuyến tính cắt mặt đường cong thoải của hội tụ \(O(1/k)\), trực giác thuật toán mới thực sự ngấm vào máu!&lt;/p&gt;

&lt;p&gt;Bộ bài tập thực hành này tập trung vào các kỹ năng định lượng cốt lõi của Chương 06: phân tích tốc độ hội tụ thực nghiệm, so sánh trực tiếp Gradient Descent vs. Heavy Ball Momentum trên ma trận điều kiện xấu, cài đặt Backtracking Line Search và đánh giá nhiễu của SGD.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-thói-quen-vàng-khi-thực-nghiệm-thuật-toán-tối-ưu&quot;&gt;Kiến thức cần nhớ: Bốn thói quen vàng khi thực nghiệm thuật toán tối ưu&lt;/h2&gt;

&lt;p&gt;Trước khi giải bài tập trên giấy hoặc viết mã Python mô phỏng, hãy ghi nhớ bốn quy chuẩn thực nghiệm sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Luôn vẽ sai số trên thang bán logarit (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;semilogy&lt;/code&gt;):&lt;/strong&gt; Trên biểu đồ \(\log_{10}(f(x^{(k)}) - f^\star)\) theo số vòng lặp \(k\), &lt;strong&gt;hội tụ tuyến tính \(O(c^k)\) hiện ra thành một đường thẳng&lt;/strong&gt; có độ dốc \(\log_{10}(c)\), còn hội tụ \(O(1/k)\) hiện ra thành một đường cong phẳng dần rất dễ phân biệt bằng mắt!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra gradient bằng sai phân hữu hạn (Gradient Checking):&lt;/strong&gt; Trước khi đổ lỗi cho thuật toán không hội tụ, luôn kiểm tra công thức \(\nabla f(x)\) của bạn bằng \(\frac{f(x + \varepsilon e_i) - f(x - \varepsilon e_i)}{2\varepsilon}\) (\(\varepsilon = 10^{-6}\)); 80% lỗi thuật toán trong thực tế đến từ tính sai gradient!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh công bằng theo số phép tính gradient (Oracle Calls):&lt;/strong&gt; Khi so sánh Batch GD, Backtracking và SGD, đừng chỉ đếm số vòng lặp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;k&lt;/code&gt; — hãy đếm tổng số lượt duyệt dữ liệu (epochs) hoặc số lần đánh giá hàm/gradient!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm soát chỉ số điều kiện \(\kappa\) khi tạo bài test:&lt;/strong&gt; Để thấy rõ sự khác biệt giữa GD và Momentum, hãy thử nghiệm trên ma trận \(Q\) có \(\kappa \in \{10, 100, 1000\}\) (vì tại \(\kappa = 1\) cả hai đều hội tụ sau đúng 1 bước!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-trước-độ-dốc-đường-semilogy-để-đối-chiếu-với-kết-quả-chạy-code&quot;&gt;Giải thích: Tính trước độ dốc đường &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;semilogy&lt;/code&gt; để đối chiếu với kết quả chạy code&lt;/h3&gt;

&lt;p&gt;Giả sử bạn chạy bài tập so sánh GD và Momentum trên bài toán bậc hai có \(m = 1,\; L = 100\) (\(\kappa = 100\)) với bước tối ưu:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Dự đoán lý thuyết cho GD (\(t^\star = \frac{2}{101} \approx 0.0198\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hệ số co khoảng cách: \(\rho_{\text{GD}} = \frac{100 - 1}{100 + 1} = \frac{99}{101} \approx 0.9802\).&lt;/li&gt;
      &lt;li&gt;Hệ số co sai số hàm: \(\rho_{\text{GD}}^2 \approx 0.9608\).&lt;/li&gt;
      &lt;li&gt;Số bước để sai số hàm giảm &lt;strong&gt;10 lần&lt;/strong&gt; (1 bậc trên thang &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log10&lt;/code&gt;):
\(k_{10\times}^{\text{GD}} = \frac{\ln 10}{-\ln(0.9608)} \approx \frac{2.3026}{0.0400} \approx 58 \text{ bước!}\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dự đoán lý thuyết cho Heavy Ball Momentum (\(\alpha^\star = \frac{4}{121},\; \beta^\star = \frac{81}{121}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hệ số co khoảng cách: \(\rho_{\text{HB}} = \frac{\sqrt{100} - 1}{\sqrt{100} + 1} = \frac{9}{11} \approx 0.8182\).&lt;/li&gt;
      &lt;li&gt;Hệ số co sai số hàm: \(\rho_{\text{HB}}^2 \approx 0.6694\).&lt;/li&gt;
      &lt;li&gt;Số bước để sai số hàm giảm &lt;strong&gt;10 lần&lt;/strong&gt;:
\(k_{10\times}^{\text{HB}} = \frac{\ln 10}{-\ln(0.6694)} \approx \frac{2.3026}{0.4013} \approx 6 \text{ bước!}\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng:&lt;/strong&gt; Khi chạy code vẽ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;semilogy&lt;/code&gt;, nếu bạn thấy Momentum cần khoảng 60 bước để giảm sai số xuống \(10^{-10}\) còn GD cần gần 580 bước (chênh đúng ~10 lần \(= \sqrt{\kappa}\)!), bạn biết chắc chắn code của mình đã chính xác 100%!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành--thuật-toán-tối-ưu-hóa&quot;&gt;Bài tập Thực hành — Thuật toán Tối ưu hóa&lt;/h1&gt;

&lt;p&gt;Các bài tập dưới đây được tham khảo từ Boyd &amp;amp; Vandenberghe (2004) và Nocedal &amp;amp; Wright (2006).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-i-gradient-descent&quot;&gt;📝 &lt;strong&gt;Phần I: Gradient Descent&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-phân-tích-tốc-độ-hội-tụ&quot;&gt;&lt;strong&gt;Bài tập 1: Phân tích Tốc độ Hội tụ&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho hàm số \(f(x) = \frac{1}{2}x^TQx\) với \(Q = \text{diag}(1, 4, 10)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tính gradient \(\nabla f(x)\).&lt;br /&gt;
b) Với kích thước bước \(t = \frac{2}{m + L}\) (trong đó \(m = \lambda_{\min}(Q)\), \(L = \lambda_{\max}(Q)\)), tính hệ số hội tụ.&lt;br /&gt;
c) Xuất phát từ \(x^{(0)} = (1, 1, 1)^T\), tính \(x^{(1)}\) và \(x^{(2)}\).&lt;br /&gt;
d) Ước lượng số vòng lặp cần thiết để đạt \(\|x^{(k)}\| &amp;lt; 10^{-6}\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Gradient:**

$$\nabla f(x) = Qx = \begin{bmatrix} x_1 \\ 4x_2 \\ 10x_3 \end{bmatrix}$$

---

**b) Hệ số hội tụ:**

$$m = 1, \quad L = 10$$

$$t = \frac{2}{1 + 10} = \frac{2}{11}$$

**Đánh giá tốc độ hội tụ:**

$$\|x^{(k+1)} - x^*\| \leq \left(\frac{L - m}{L + m}\right) \|x^{(k)} - x^*\|$$

$$= \frac{10 - 1}{10 + 1} \|x^{(k)} - x^*\| = \frac{9}{11} \|x^{(k)} - x^*\|$$

Thuật toán đạt **hội tụ tuyến tính** với hệ số co $$\frac{9}{11} \approx 0.818$$.

---

**c) Các bước lặp đầu tiên:**

$$x^{(0)} = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}, \quad \nabla f(x^{(0)}) = \begin{bmatrix} 1 \\ 4 \\ 10 \end{bmatrix}$$

$$x^{(1)} = x^{(0)} - t \nabla f(x^{(0)}) = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix} - \frac{2}{11} \begin{bmatrix} 1 \\ 4 \\ 10 \end{bmatrix} = \begin{bmatrix} 1 - \frac{2}{11} \\ 1 - \frac{8}{11} \\ 1 - \frac{20}{11} \end{bmatrix} = \begin{bmatrix} \frac{9}{11} \\ \frac{3}{11} \\ -\frac{9}{11} \end{bmatrix}$$

$$\nabla f(x^{(1)}) = \begin{bmatrix} \frac{9}{11} \\ \frac{12}{11} \\ -\frac{90}{11} \end{bmatrix}$$

$$x^{(2)} = x^{(1)} - \frac{2}{11} \nabla f(x^{(1)}) = \begin{bmatrix} \frac{9}{11} - \frac{18}{121} \\ \frac{3}{11} - \frac{24}{121} \\ -\frac{9}{11} + \frac{180}{121} \end{bmatrix} = \begin{bmatrix} \frac{81}{121} \\ \frac{9}{121} \\ \frac{81}{121} \end{bmatrix}$$

---

**d) Số vòng lặp ước lượng:**

$$\|x^{(k)}\| \leq \left(\frac{9}{11}\right)^k \|x^{(0)}\|, \quad \|x^{(0)}\| = \sqrt{3}$$

Cần thỏa mãn: $$\left(\frac{9}{11}\right)^k \sqrt{3} &amp;lt; 10^{-6}$$

$$k &amp;gt; \frac{\ln(10^{-6}/\sqrt{3})}{\ln(9/11)} = \frac{\ln(10^{-6}) - 0.5\ln(3)}{\ln(9/11)} \approx \frac{-13.816 - 0.549}{-0.201} \approx 71.6$$

Do đó cần khoảng **72 vòng lặp**.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-ii-các-phương-pháp-momentum&quot;&gt;📝 &lt;strong&gt;Phần II: Các Phương pháp Momentum&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-2-so-sánh-heavy-ball-và-gradient-descent&quot;&gt;&lt;strong&gt;Bài tập 2: So sánh Heavy Ball và Gradient Descent&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho hàm \(f(x) = x_1^2 + 9x_2^2\) (điều kiện xấu với chỉ số điều kiện \(\kappa = 9\)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) So sánh các bước lặp đầu của GD và Heavy Ball xuất phát từ \(x^{(0)} = (3, 1)^T\).&lt;br /&gt;
b) Tính hệ số momentum tối ưu \(\beta\).&lt;br /&gt;
c) So sánh tốc độ hội tụ của hai phương pháp.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Gradient Descent:**

$$\nabla f(x) = \begin{bmatrix} 2x_1 \\ 18x_2 \end{bmatrix}$$

Kích thước bước tối ưu: $$t = \frac{2}{2 + 18} = 0.1$$.

$$x^{(1)} = (3, 1) - 0.1(6, 18) = (2.4, -0.8)$$

$$x^{(2)} = (2.4, -0.8) - 0.1(4.8, -14.4) = (1.92, 0.64)$$

**Nhận xét:** Quỹ đạo dao động đổi dấu liên tục theo trục $$x_2$$ và tiến chậm về $$(0, 0)$$.

---

**Phương pháp Heavy Ball:**

$$x^{(k+1)} = x^{(k)} - t\nabla f(x^{(k)}) + \beta(x^{(k)} - x^{(k-1)})$$

**Hệ số momentum tối ưu $$\beta$$:**

$$\beta = \left(\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\right)^2 = \left(\frac{3 - 1}{3 + 1}\right)^2 = \left(\frac{1}{2}\right)^2 = 0.25$$

---

**b) Minh họa bước lặp Heavy Ball (với cùng $$t = 0.1$$):**

$$x^{(1)} = (2.4, -0.8), \quad x^{(2)} = (1.92, 0.64)$$ (ở các bước khởi đầu chưa tích lũy momentum)

$$x^{(3)} = (1.92, 0.64) - 0.1(3.84, 11.52) + 0.25\big((1.92, 0.64) - (2.4, -0.8)\big)$$

$$= (1.92, 0.64) - (0.384, 1.152) + 0.25(-0.48, 1.44)$$

$$= (1.92, 0.64) - (0.384, 1.152) + (-0.12, 0.36) = (1.416, -0.152)$$

---

**c) So sánh tốc độ hội tụ:**

- **GD:** $$\left(\frac{\kappa - 1}{\kappa + 1}\right)^k = \left(\frac{8}{10}\right)^k = 0.8^k$$
- **Heavy Ball (với bộ tham số tối ưu):** $$\left(\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\right)^{k} = 0.5^k$$

Ở mỗi vòng lặp, Heavy Ball co sai số theo hệ số $$0.5$$ so với $$0.8$$ của GD, tức số vòng lặp cần thiết giảm khoảng $$\frac{\ln 0.5}{\ln 0.8} \approx 3.1$$ lần.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iii-tăng-tốc-nesterov&quot;&gt;📝 &lt;strong&gt;Phần III: Tăng tốc Nesterov&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-3-so-sánh-nesterov-và-gradient-descent-chuẩn&quot;&gt;&lt;strong&gt;Bài tập 3: So sánh Nesterov và Gradient Descent Chuẩn&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho \(f(x) = \frac{1}{2}\|Ax - b\|^2\) với \(A = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\) và \(b = (2, 1)^T\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Tìm nghiệm chính xác \(x^*\).&lt;br /&gt;
b) Viết công thức và tính các bước đầu của phương pháp Nesterov.&lt;br /&gt;
c) So sánh kết quả với GD sau 5 vòng lặp.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Nghiệm chính xác:**

$$\nabla f(x) = A^T(Ax - b) = 0 \Leftrightarrow A^TAx = A^Tb$$

$$\begin{bmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} x = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 4 \\ 1 \end{bmatrix} \Rightarrow x^* = (1, 1)^T$$

---

**b) Phương pháp Nesterov:**

$$
\begin{align}
y^{(k)} &amp;amp;= x^{(k)} + \frac{k-1}{k+2}(x^{(k)} - x^{(k-1)}) \\
x^{(k+1)} &amp;amp;= y^{(k)} - t\nabla f(y^{(k)})
\end{align}
$$

Với $$L = \lambda_{\max}(A^TA) = 4$$, chọn $$t = \frac{1}{L} = 0.25$$.

Xuất phát từ $$x^{(0)} = (0, 0)$$ và $$x^{(1)} = (0, 0)$$:
- Tại $$k=1$$: $$y^{(1)} = (0, 0)$$, $$\nabla f(y^{(1)}) = A^T(A(0,0) - (2,1)) = -A^Tb = (-4, -1)$$, nên $$x^{(2)} = (0, 0) - 0.25(-4, -1) = (1, 0.25)$$.
- Tại $$k=2$$: $$y^{(2)} = (1, 0.25) + \frac{1}{4}\big((1, 0.25) - (0, 0)\big) = (1.25, 0.3125)$$.

(Tiếp tục tương tự cho các bước tiếp theo.)

---

**c) So sánh sau 5 vòng lặp:**

| Phương pháp | $$x$$ sau 5 vòng lặp | $$\|x^{(5)} - x^*\|$$ |
|-------------|----------------------|-----------------------|
| GD | $$(1, 0.763)$$ | $$0.237$$ |
| Nesterov | $$(1, 0.944)$$ | $$0.056$$ |

Sai số của phương pháp Nesterov nhỏ hơn khoảng 4 lần so với GD (với GD, sai số ở tọa độ thứ hai bằng $$0.75^5 \approx 0.237$$).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iv-gradient-gần-kề-proximal-gradient&quot;&gt;📝 &lt;strong&gt;Phần IV: Gradient Gần kề (Proximal Gradient)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-4-bài-toán-lasso-với-toán-tử-ngưỡng-mềm&quot;&gt;&lt;strong&gt;Bài tập 4: Bài toán LASSO với Toán tử Ngưỡng mềm&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho bài toán LASSO: \(\min_x \frac{1}{2}\|Ax - b\|^2 + \lambda\|x\|_1\)&lt;/p&gt;

&lt;p&gt;với \(A = I\), \(b = (2, -1, 0.5)^T\) và \(\lambda = 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết quy tắc cập nhật gradient gần kề.&lt;br /&gt;
b) Xác định toán tử ngưỡng mềm (soft-thresholding operator).&lt;br /&gt;
c) Thực hiện lặp xuất phát từ \(x^{(0)} = 0\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Quy tắc gradient gần kề:**

Đặt $$f(x) = \frac{1}{2}\|x - b\|^2$$ (phần trơn) và $$g(x) = \lambda\|x\|_1$$ (phần không trơn):

$$x^{(k+1)} = \text{prox}_{tg}\big(x^{(k)} - t\nabla f(x^{(k)})\big) = \text{prox}_{t\lambda\|\cdot\|_1}\big(x^{(k)} - t(x^{(k)} - b)\big)$$

Với $$t = 1$$:

$$x^{(k+1)} = \text{prox}_{\lambda\|\cdot\|_1}(b)$$

---

**b) Toán tử ngưỡng mềm (Soft-thresholding):**

$$\text{prox}_{\lambda\|\cdot\|_1}(y) = S_\lambda(y)$$

trong đó theo từng thành phần:

$$S_\lambda(y_i) = \begin{cases}
y_i - \lambda &amp;amp; \text{nếu } y_i &amp;gt; \lambda \\
0 &amp;amp; \text{nếu } |y_i| \leq \lambda \\
y_i + \lambda &amp;amp; \text{nếu } y_i &amp;lt; -\lambda
\end{cases}$$

---

**c) Kết quả lặp:**

Với $$x^{(0)} = (0, 0, 0)$$, $$b = (2, -1, 0.5)$$ và $$\lambda = 1$$:

$$x^{(1)} = S_1(b) = \big(S_1(2), S_1(-1), S_1(0.5)\big) = (2 - 1, 0, 0) = (1, 0, 0)$$

Do $$A = I$$, thuật toán hội tụ chỉ sau đúng **1 bước**, cho nghiệm tối ưu $$x^* = (1, 0, 0)^T$$:
- $$b_1 = 2 &amp;gt; \lambda$$ được co về $$1$$.
- $$|b_2| = 1 = \lambda$$ được đưa về $$0$$.
- $$|b_3| = 0.5 &amp;lt; \lambda$$ được đưa về $$0$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-v-hạ-tọa-độ-coordinate-descent&quot;&gt;📝 &lt;strong&gt;Phần V: Hạ Tọa độ (Coordinate Descent)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-5-hạ-tọa-độ-cho-bài-toán-toàn-phương&quot;&gt;&lt;strong&gt;Bài tập 5: Hạ Tọa độ cho Bài toán Toàn phương&lt;/strong&gt;&lt;/h3&gt;

\[\min_x \quad x_1^2 + 2x_2^2 + x_1x_2 - 3x_1 - 4x_2\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Cực tiểu hóa theo \(x_1\) khi cố định \(x_2\).&lt;br /&gt;
b) Cực tiểu hóa theo \(x_2\) khi cố định \(x_1\).&lt;br /&gt;
c) Lặp từ \((0, 0)\) và đối chiếu với nghiệm chính xác.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Cực tiểu hóa theo $$x_1$$:**

$$f(x_1, x_2) = x_1^2 + x_1x_2 - 3x_1 + (2x_2^2 - 4x_2)$$

$$\frac{\partial f}{\partial x_1} = 2x_1 + x_2 - 3 = 0 \Rightarrow x_1^* = \frac{3 - x_2}{2}$$

---

**b) Cực tiểu hóa theo $$x_2$$:**

$$\frac{\partial f}{\partial x_2} = 4x_2 + x_1 - 4 = 0 \Rightarrow x_2^* = \frac{4 - x_1}{4}$$

---

**c) Các bước hạ tọa độ:**

**Bước 0:** $$(x_1, x_2) = (0, 0)$$

**Bước 1:**
- Cố định $$x_2 = 0$$: $$x_1 = \frac{3 - 0}{2} = 1.5$$
- Cố định $$x_1 = 1.5$$: $$x_2 = \frac{4 - 1.5}{4} = 0.625$$

**Bước 2:**
- Cố định $$x_2 = 0.625$$: $$x_1 = \frac{3 - 0.625}{2} = 1.1875$$
- Cố định $$x_1 = 1.1875$$: $$x_2 = \frac{4 - 1.1875}{4} \approx 0.703$$

**Bước 3:**
- $$x_1 \approx 1.148$$, $$x_2 \approx 0.713$$

Dãy lặp tiến dần về $$x^* \approx (1.143, 0.714)$$.

**Nghiệm chính xác (giải hệ phương trình đồng thời):**

$$
\begin{cases}
2x_1 + x_2 = 3 \\
x_1 + 4x_2 = 4
\end{cases}
\Rightarrow x^* = \left(\frac{8}{7}, \frac{5}{7}\right) \approx (1.143, 0.714)$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;so-sánh-các-thuật-toán&quot;&gt;&lt;strong&gt;So sánh Các Thuật toán&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Tốc độ hội tụ&lt;/th&gt;
      &lt;th&gt;Chi phí mỗi vòng lặp&lt;/th&gt;
      &lt;th&gt;Phù hợp nhất với&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;GD&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
      &lt;td&gt;Bài toán có chỉ số điều kiện tốt&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Heavy Ball&lt;/td&gt;
      &lt;td&gt;\(O(\rho^k)\), \(\rho &amp;lt; 1\)&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
      &lt;td&gt;Bài toán bậc hai / lồi mạnh điều kiện xấu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Nesterov&lt;/td&gt;
      &lt;td&gt;\(O(1/k^2)\)&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
      &lt;td&gt;Bài toán lồi trơn cần hội tụ nhanh&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Proximal GD&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;\(O(n)\) + phép chiếu/prox&lt;/td&gt;
      &lt;td&gt;Bài toán hợp (phần trơn + phần không trơn)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Coordinate Descent&lt;/td&gt;
      &lt;td&gt;Tùy cấu trúc&lt;/td&gt;
      &lt;td&gt;\(O(n/m)\)&lt;/td&gt;
      &lt;td&gt;Bài toán quy mô lớn, tách biến được&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;gợi-ý-lựa-chọn-phương-pháp&quot;&gt;&lt;strong&gt;Gợi ý Lựa chọn Phương pháp&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;GD:&lt;/strong&gt; Bài toán đơn giản, chỉ số điều kiện nhỏ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Momentum (Heavy Ball):&lt;/strong&gt; Hàm bậc hai hoặc lồi mạnh có điều kiện xấu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov:&lt;/strong&gt; Cần tăng tốc hội tụ trên hàm lồi trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Proximal GD:&lt;/strong&gt; Bài toán có số hạng điều chuẩn không trơn (chuẩn \(\ell_1\), chuẩn hạt nhân…).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate Descent:&lt;/strong&gt; Số chiều rất lớn và bước tối ưu theo từng tọa độ tính nhanh.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu Tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 9.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nocedal, J., &amp;amp; Wright, S. J.&lt;/strong&gt; (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt;. Springer. Chapters 2-3.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nesterov, Y.&lt;/strong&gt; (2004). &lt;em&gt;Introductory Lectures on Convex Optimization&lt;/em&gt;. Springer.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>06-10 Ôn tập tổng hợp - Nền tảng Tối ưu hóa Lồi (Chương 00-06)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_10_Comprehensive_Review_Ch00-06/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_10_Comprehensive_Review_Ch00-06</id>
   <content type="html">&lt;p&gt;Bạn vừa đi qua gần một phần tư chặng đường đồ sộ nhất của khóa học: từ những định nghĩa nền móng về tích trong, ma trận đối xứng (Chương 00), sang bài toán tối ưu tổng quát (Chương 01), hình học Tập lồi (Chương 02), Giải tích Hàm lồi (Chương 03), Cấu trúc bài toán tối ưu lồi (Chương 04), Hệ phân cấp các bài toán chuẩn LP–QP–SOCP–SDP (Chương 05), và thuật toán bậc nhất Gradient Descent (Chương 06).&lt;/p&gt;

&lt;p&gt;Nếu từng chương riêng lẻ giống như những mảnh ghép tinh xảo, thì bài ôn tập tổng hợp này chính là lúc ta &lt;strong&gt;lùi lại nhìn toàn bộ bức tranh ghép hình&lt;/strong&gt;: bạn sẽ thấy mọi định lý ở Chương 06 thực chất đều mọc rễ trực tiếp từ tập lồi của Chương 02 và hàm lồi của Chương 03!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-sợi-chỉ-đỏ-xuyên-suốt-từ-chương-00-đến-chương-06&quot;&gt;Kiến thức cần nhớ: Sợi chỉ đỏ xuyên suốt từ Chương 00 đến Chương 06&lt;/h2&gt;

&lt;p&gt;Hãy xâu chuỗi toàn bộ 7 chương đầu thành bốn cầu nối không thể tách rời:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối 1 (Chương 00 → 02 → 03): Từ Đại số tuyến tính đến Độ cong Lồi.&lt;/strong&gt; Khái niệm ma trận nửa xác định dương \(H \succeq 0\) (Chương 00) định nghĩa nón \(\mathbb{S}_+^n\) (Chương 02), trở thành tiêu chuẩn kiểm tra hàm lồi bậc hai \(\nabla^2 f(x) \succeq 0\) (Chương 03), và trực tiếp định nghĩa tính lồi của QP/QCQP/SDP (Chương 05).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối 2 (Chương 02–03 → 04): Từ Tập/Hàm lồi đến Điều kiện Tối ưu Toàn cục.&lt;/strong&gt; Nhờ tập khả thi lồi và hàm mục tiêu lồi, mọi cực tiểu địa phương đều là toàn cục, và bất đẳng thức biến phân \(\nabla f(x^\star)^T(y - x^\star) \ge 0\) trở thành điều kiện vừa cần vừa đủ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối 3 (Chương 04 → 05): Từ Phép biến đổi tương đương đến Hệ phân cấp Nón.&lt;/strong&gt; Kỹ thuật đổi biến, thêm biến phụ, epigraph và bổ đề Schur ở Chương 04 chính là cầu nối chứng minh \(\text{LP} \subset \text{QP} \subset \text{QCQP} \subset \text{SOCP} \subset \text{SDP} \subset \text{CP}\) và vận hành bộ biên dịch DCP của CVXPY.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối 4 (Chương 03 → 06): Từ Cận dưới/Cận trên bậc hai đến Tốc độ Thuật toán.&lt;/strong&gt; Tính \(L\)-trơn và tính lồi mạnh \(m\) của hàm lồi quyết định trọn vẹn tốc độ hội tụ của Gradient Descent (\(O(1/k)\) vs. \(O((1 - m/L)^k)\)), Momentum và SGD!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-phẫu-trọn-gói-một-bài-toán-duy-nhất-qua-ống-kính-cả-7-chương&quot;&gt;Giải thích: Giải phẫu trọn gói một bài toán duy nhất qua ống kính cả 7 chương&lt;/h3&gt;

&lt;p&gt;Xét bài toán Hồi quy Ridge: \(\min_{w \in \mathbb{R}^2} \; f(w) = \frac{1}{2}\|Xw - y\|_2^2 + \frac{1}{2}\|w\|_2^2\) với \(X = \begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix},\; y = \begin{pmatrix} 2 \\ 5 \end{pmatrix}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chương 00–03 (Tính lồi &amp;amp; Độ cong):&lt;/strong&gt; \(H = \nabla^2 f(w) = X^T X + I = \operatorname{diag}(2, 5)\). Mọi trị riêng dương (\(m = 2, L = 5\)) \(\implies f\) lồi mạnh và \(5\)-trơn!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chương 04 (Điều kiện tối ưu):&lt;/strong&gt; Không ràng buộc nên \(\nabla f(w^\star) = (X^T X + I)w^\star - X^T y = 0 \implies (2w_1^\star, 5w_2^\star) = (2, 10) \implies w^\star = (1, 2)^T\) (nghiệm toàn cục duy nhất!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chương 05 (Bài toán chuẩn):&lt;/strong&gt; Đây là một bài &lt;strong&gt;QP không ràng buộc&lt;/strong&gt; (hay Bình phương tối thiểu mở rộng), đồng thời là ước lượng &lt;strong&gt;MAP&lt;/strong&gt; dưới nhiễu Gaussian và tiên nghiệm Gaussian!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chương 06 (Thuật toán lặp):&lt;/strong&gt; Nếu giải bằng GD với bước \(t = 1/L = 0.2\), chỉ số điều kiện \(\kappa = 5/2 = 2.5\) cho hệ số co \(1 - m/L = 1 - 0.4 = 0.6\) mỗi bước — chỉ cần 14 vòng lặp để giảm sai số đi \(1\,000\) lần! Một bài toán nhỏ đã hội tụ trọn vẹn tinh hoa của 7 chương!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script&gt;
window.MathJax = {
  tex: {
    inlineMath: [[&apos;\\(&apos;, &apos;\\)&apos;]],
    displayMath: [[&apos;\\[&apos;, &apos;\\]&apos;], [&apos;$$&apos;, &apos;$$&apos;]],
    processEscapes: true,
    processEnvironments: true
  },
  options: {
    ignoreHtmlClass: &quot;.*|&quot;,
    processHtmlClass: &quot;arithmatex&quot;
  }
};
&lt;/script&gt;

&lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?features=es6&quot;&gt;&lt;/script&gt;

&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;h1 id=&quot;-ôn-tập-tổng-hợp-nền-tảng-tối-ưu-hóa-lồi&quot;&gt;📚 Ôn tập Tổng hợp: Nền tảng Tối ưu hóa Lồi&lt;/h1&gt;

&lt;p&gt;Bài viết này hệ thống hóa các khái niệm cốt lõi từ chương 00 đến chương 06, trình bày theo trình tự từ nền tảng toán học đến các bài toán và thuật toán tối ưu hóa thực tế.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;️-phần-i-nền-tảng-toán-học-chương-00&quot;&gt;🏗️ &lt;strong&gt;PHẦN I: NỀN TẢNG TOÁN HỌC (Chương 00)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-1-giải-tích-cơ-bản&quot;&gt;🔢 &lt;strong&gt;1. Giải tích cơ bản&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;đạo-hàm-và-gradient&quot;&gt;&lt;strong&gt;Đạo hàm và Gradient&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đạo hàm:&lt;/strong&gt; \(f&apos;(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đạo hàm riêng:&lt;/strong&gt; \(\frac{\partial f}{\partial x_i}\) — đạo hàm theo biến \(x_i\) khi cố định các biến còn lại.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient:&lt;/strong&gt; \(\nabla f = \begin{pmatrix} \frac{\partial f}{\partial x_1} \\ \vdots \\ \frac{\partial f}{\partial x_n} \end{pmatrix}\) — vector chỉ hướng tăng dốc nhất của hàm số.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;đạo-hàm-theo-hướng-và-khai-triển-taylor&quot;&gt;&lt;strong&gt;Đạo hàm theo hướng và Khai triển Taylor&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đạo hàm theo hướng đơn vị \(\mathbf{u}\):&lt;/strong&gt; \(D_{\mathbf{u}}f = \nabla f \cdot \mathbf{u} = \|\nabla f\| \cos \theta\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khai triển Taylor bậc 1:&lt;/strong&gt; \(f(\mathbf{x}) \approx f(\mathbf{x}_0) + \nabla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khai triển Taylor bậc 2:&lt;/strong&gt; \(f(\mathbf{x}) \approx f(\mathbf{x}_0) + \nabla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0) + \frac{1}{2} (\mathbf{x} - \mathbf{x}_0)^T \nabla^2 f(\mathbf{x}_0) (\mathbf{x} - \mathbf{x}_0)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-2-đại-số-tuyến-tính&quot;&gt;📐 &lt;strong&gt;2. Đại số tuyến tính&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;vector-và-chuẩn&quot;&gt;&lt;strong&gt;Vector và Chuẩn&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tích vô hướng:&lt;/strong&gt; \(\mathbf{u} \cdot \mathbf{v} = \sum_{i=1}^n u_i v_i = \|\mathbf{u}\| \|\mathbf{v}\| \cos \theta\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn vector:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;L2 (Euclid): \(\|\mathbf{x}\|_2 = \sqrt{\sum_{i=1}^n x_i^2}\)&lt;/li&gt;
      &lt;li&gt;L1 (Manhattan): \(\|\mathbf{x}\|_1 = \sum_{i=1}^n \lvert x_i \rvert\)&lt;/li&gt;
      &lt;li&gt;L∞ (cực đại): \(\|\mathbf{x}\|_\infty = \max_i \lvert x_i \rvert\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;ma-trận-và-trị-riêng&quot;&gt;&lt;strong&gt;Ma trận và Trị riêng&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phép nhân ma trận:&lt;/strong&gt; \((AB)_{ij} = \sum_{k} A_{ik} B_{kj}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trị riêng / vector riêng:&lt;/strong&gt; \(A\mathbf{v} = \lambda \mathbf{v}\) với \(\mathbf{v} \neq \mathbf{0}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ma trận xác định dương:&lt;/strong&gt; \(A \succ 0 \Leftrightarrow \mathbf{x}^T A \mathbf{x} &amp;gt; 0, \forall \mathbf{x} \neq 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-3-giải-tích-tập-hợp&quot;&gt;📊 &lt;strong&gt;3. Giải tích tập hợp&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;các-tập-hợp-cơ-bản&quot;&gt;&lt;strong&gt;Các tập hợp cơ bản&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tập mở:&lt;/strong&gt; Mọi điểm thuộc tập đều có một lân cận nằm trọn trong tập.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập đóng:&lt;/strong&gt; Chứa toàn bộ các điểm biên của nó.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập compact:&lt;/strong&gt; Đóng và bị chặn trong \(\mathbb{R}^n\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tính-liên-tục&quot;&gt;&lt;strong&gt;Tính liên tục&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Liên tục:&lt;/strong&gt; \(\lim_{x \to x_0} f(x) = f(x_0)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên tục đều:&lt;/strong&gt; \(\forall \epsilon &amp;gt; 0, \exists \delta &amp;gt; 0\) sao cho \(\lvert x-y \rvert &amp;lt; \delta \Rightarrow \lvert f(x)-f(y) \rvert &amp;lt; \epsilon\).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-ii-khái-niệm-tối-ưu-hóa-chương-01&quot;&gt;🎯 &lt;strong&gt;PHẦN II: KHÁI NIỆM TỐI ƯU HÓA (Chương 01)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-4-bài-toán-tối-ưu-hóa-tổng-quát&quot;&gt;🔍 &lt;strong&gt;4. Bài toán Tối ưu hóa Tổng quát&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;dạng-chuẩn&quot;&gt;&lt;strong&gt;Dạng chuẩn&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align} 
&amp;amp;\min_{x\in D}\ &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{với điều kiện} &amp;amp;&amp;amp; g_i(x) \le 0,\ i = 1, ..., m \\
&amp;amp;&amp;amp;&amp;amp; h_j(x) = 0,\ j = 1,\ ..., r
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Các thành phần:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\): biến tối ưu.&lt;/li&gt;
  &lt;li&gt;\(f(x)\): hàm mục tiêu.&lt;/li&gt;
  &lt;li&gt;\(g_i(x) \le 0\): các ràng buộc bất đẳng thức.&lt;/li&gt;
  &lt;li&gt;\(h_j(x) = 0\): các ràng buộc đẳng thức.&lt;/li&gt;
  &lt;li&gt;\(x^*\): nghiệm tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-5-tối-ưu-hóa-lồi&quot;&gt;🌟 &lt;strong&gt;5. Tối ưu hóa Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa-bài-toán-lồi&quot;&gt;&lt;strong&gt;Định nghĩa bài toán lồi&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Bài toán tối ưu hóa là bài toán lồi khi:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu \(f\) là hàm lồi.&lt;/li&gt;
  &lt;li&gt;Các hàm ràng buộc bất đẳng thức \(g_i\) là hàm lồi.&lt;/li&gt;
  &lt;li&gt;Các hàm ràng buộc đẳng thức \(h_j\) là hàm affine.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tính-chất-cốt-lõi&quot;&gt;&lt;strong&gt;Tính chất cốt lõi&lt;/strong&gt;&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Mọi cực tiểu cục bộ của bài toán tối ưu hóa lồi đều là cực tiểu toàn cục.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tính chất này đảm bảo bài toán lồi có thể được giải một cách đáng tin cậy và hiệu quả.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iii-tập-lồi-chương-02&quot;&gt;🔵 &lt;strong&gt;PHẦN III: TẬP LỒI (Chương 02)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-6-từ-tập-affine-đến-tập-lồi&quot;&gt;📏 &lt;strong&gt;6. Từ Tập Affine đến Tập Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;tập-affine&quot;&gt;&lt;strong&gt;Tập Affine&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; \(\theta x_1 + (1-\theta)x_2 \in C\) với mọi \(\theta \in \mathbb{R}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp affine:&lt;/strong&gt; \(\sum_{i=1}^k \theta_i x_i\) với \(\sum_{i=1}^k \theta_i = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa hình học:&lt;/strong&gt; Chứa trọn đường thẳng đi qua hai điểm bất kỳ thuộc tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tập-lồi&quot;&gt;&lt;strong&gt;Tập Lồi&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; \(\theta x_1 + (1-\theta)x_2 \in C\) với mọi \(0 \le \theta \le 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp lồi:&lt;/strong&gt; \(\sum_{i=1}^k \theta_i x_i\) với \(\sum_{i=1}^k \theta_i = 1, \theta_i \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa hình học:&lt;/strong&gt; Chứa trọn đoạn thẳng nối hai điểm bất kỳ thuộc tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;nón-lồi&quot;&gt;&lt;strong&gt;Nón Lồi&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; Vừa là nón vừa là tập lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp nón:&lt;/strong&gt; \(\sum_{i=1}^k \theta_i x_i\) với \(\theta_i \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa hình học:&lt;/strong&gt; Chứa các tia xuất phát từ gốc tọa độ đi qua điểm thuộc tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-7-các-tập-lồi-quan-trọng&quot;&gt;🏗️ &lt;strong&gt;7. Các Tập Lồi Quan trọng&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;tập-hợp-cơ-bản&quot;&gt;&lt;strong&gt;Tập hợp cơ bản&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Siêu phẳng:&lt;/strong&gt; \(\{x \mid a^T x = b\}\) — vừa affine vừa lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nửa không gian:&lt;/strong&gt; \(\{x \mid a^T x \le b\}\) — lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình cầu Euclid:&lt;/strong&gt; \(\{x \mid \lVert x - x_c \rVert_2 \le r\}\) — lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ellipsoid:&lt;/strong&gt; \(\{x \mid (x-x_c)^T P^{-1} (x-x_c) \le 1\}\) với \(P \succ 0\) — lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;các-phép-toán-bảo-toàn-tính-lồi&quot;&gt;&lt;strong&gt;Các phép toán bảo toàn tính lồi&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phép giao:&lt;/strong&gt; Giao của họ các tập lồi bất kỳ là tập lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp affine:&lt;/strong&gt; \(\alpha C + \beta D\) lồi nếu \(C, D\) lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ảnh affine:&lt;/strong&gt; \(f(C) = \{Ax + b \mid x \in C\}\) lồi nếu \(C\) lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iv-hàm-lồi-chương-03&quot;&gt;📈 &lt;strong&gt;PHẦN IV: HÀM LỒI (Chương 03)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-8-định-nghĩa-và-phân-loại&quot;&gt;🔍 &lt;strong&gt;8. Định nghĩa và Phân loại&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;hàm-lồi&quot;&gt;&lt;strong&gt;Hàm lồi&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y)\)
với mọi \(x, y \in \text{dom}(f)\) và \(0 \le \theta \le 1\).&lt;/p&gt;

&lt;h4 id=&quot;các-lớp-hàm-liên-quan&quot;&gt;&lt;strong&gt;Các lớp hàm liên quan&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lồi chặt:&lt;/strong&gt; Bất đẳng thức nghiêm ngặt với mọi \(x \neq y, 0 &amp;lt; \theta &amp;lt; 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lồi mạnh:&lt;/strong&gt; \(f(x) - \frac{m}{2}\lVert x \rVert_2^2\) là hàm lồi với hằng số \(m &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm lõm:&lt;/strong&gt; \(f\) lõm \(\Longleftrightarrow\) \(-f\) lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-9-các-đặc-trưng-của-hàm-lồi&quot;&gt;🎯 &lt;strong&gt;9. Các Đặc trưng của Hàm Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;đặc-trưng-trên-đồ-thị-epigraph&quot;&gt;&lt;strong&gt;Đặc trưng trên đồ thị (Epigraph)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f\) lồi \(\Longleftrightarrow\) \(\text{epi}(f) = \{(x,t) \mid f(x) \le t\}\) là tập lồi.&lt;/p&gt;

&lt;h4 id=&quot;đặc-trưng-bậc-nhất-hàm-khả-vi&quot;&gt;&lt;strong&gt;Đặc trưng bậc nhất (hàm khả vi)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f\) lồi \(\Longleftrightarrow\) \(f(y) \ge f(x) + \nabla f(x)^T (y-x)\) với mọi \(x, y\).&lt;/p&gt;

&lt;h4 id=&quot;đặc-trưng-bậc-hai-hàm-khả-vi-hai-lần&quot;&gt;&lt;strong&gt;Đặc trưng bậc hai (hàm khả vi hai lần)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f\) lồi \(\Longleftrightarrow\) \(\nabla^2 f(x) \succeq 0\) với mọi \(x\) (khi \(\text{dom}(f)\) lồi).&lt;/p&gt;

&lt;h3 id=&quot;-10-hàm-liên-hợp-conjugate-function&quot;&gt;⭐ &lt;strong&gt;10. Hàm Liên hợp (Conjugate Function)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa&quot;&gt;&lt;strong&gt;Định nghĩa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f^*(y) = \sup_{x \in \text{dom}(f)} \{y^T x - f(x)\}\)&lt;/p&gt;

&lt;h4 id=&quot;tính-chất-quan-trọng&quot;&gt;&lt;strong&gt;Tính chất quan trọng&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(f^*\) luôn là hàm lồi (không phụ thuộc vào việc \(f\) có lồi hay không).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Fenchel:&lt;/strong&gt; \(f(x) + f^*(y) \ge x^T y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm liên hợp bậc hai (biconjugate):&lt;/strong&gt; Nếu \(f\) đóng và lồi thì \(f^{**} = f\).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-v-cơ-bản-về-tối-ưu-hóa-lồi-chương-04&quot;&gt;🏆 &lt;strong&gt;PHẦN V: CƠ BẢN VỀ TỐI ƯU HÓA LỒI (Chương 04)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-11-điều-kiện-tối-ưu&quot;&gt;✅ &lt;strong&gt;11. Điều kiện Tối ưu&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;điều-kiện-bậc-nhất-không-ràng-buộc&quot;&gt;&lt;strong&gt;Điều kiện bậc nhất (không ràng buộc)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\nabla f(x^*) = 0\)&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-bậc-nhất-có-ràng-buộc&quot;&gt;&lt;strong&gt;Điều kiện bậc nhất (có ràng buộc)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Với bài toán \(\min_x f(x)\) thỏa mãn \(x \in C\):
\(\nabla f(x^*)^T (y - x^*) \ge 0 \quad \forall y \in C\)&lt;/p&gt;

&lt;h4 id=&quot;điều-kiện-bậc-hai&quot;&gt;&lt;strong&gt;Điều kiện bậc hai&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện cần:&lt;/strong&gt; \(\nabla f(x^*) = 0\) và \(\nabla^2 f(x^*) \succeq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện đủ:&lt;/strong&gt; \(\nabla f(x^*) = 0\) và \(\nabla^2 f(x^*) \succ 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-12-kỹ-thuật-biến-đổi-bài-toán&quot;&gt;🔄 &lt;strong&gt;12. Kỹ thuật Biến đổi Bài toán&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;biến-phụ-slack-variables&quot;&gt;&lt;strong&gt;Biến phụ (Slack Variables)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(g_i(x) \le 0 \quad \Rightarrow \quad g_i(x) + s_i = 0, \quad s_i \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;nới-lỏng-relaxation&quot;&gt;&lt;strong&gt;Nới lỏng (Relaxation)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Thay thế tập khả thi \(C\) bằng một tập lớn hơn \(\tilde{C} \supseteq C\).&lt;/p&gt;

&lt;h4 id=&quot;loại-bỏ-ràng-buộc-đẳng-thức&quot;&gt;&lt;strong&gt;Loại bỏ ràng buộc đẳng thức&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Nếu hệ \(Ax = b\) có nghiệm riêng \(x_0\), tham số hóa nghiệm dưới dạng \(x = x_0 + Fz\) với \(\text{range}(F) = \text{null}(A)\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-vi-các-bài-toán-kinh-điển-chương-05&quot;&gt;📊 &lt;strong&gt;PHẦN VI: CÁC BÀI TOÁN KINH ĐIỂN (Chương 05)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-13-phân-cấp-bài-toán-tối-ưu-lồi&quot;&gt;🎯 &lt;strong&gt;13. Phân cấp Bài toán Tối ưu Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;LP ⊆ QP ⊆ QCQP ⊆ SOCP ⊆ SDP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;quy-hoạch-tuyến-tính-lp&quot;&gt;&lt;strong&gt;Quy hoạch Tuyến tính (LP)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;c^T x \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;Ax = b \\
&amp;amp;&amp;amp;&amp;amp;x \succeq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu và mọi ràng buộc đều affine.&lt;/li&gt;
  &lt;li&gt;Nếu bài toán có nghiệm tối ưu và đa diện khả thi có đỉnh, luôn tồn tại ít nhất một nghiệm tối ưu tại đỉnh.&lt;/li&gt;
  &lt;li&gt;Có thể giải bằng thuật toán đơn hình (Simplex) hoặc phương pháp điểm trong.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;quy-hoạch-toàn-phương-qp&quot;&gt;&lt;strong&gt;Quy hoạch Toàn phương (QP)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;\frac{1}{2}x^T P x + q^T x \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;Gx \preceq h \\
&amp;amp;&amp;amp;&amp;amp;Ax = b
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện lồi:&lt;/strong&gt; \(P \succeq 0\).&lt;/p&gt;

&lt;h3 id=&quot;-14-bình-phương-tối-thiểu-least-squares&quot;&gt;🎯 &lt;strong&gt;14. Bình phương Tối thiểu (Least Squares)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-cơ-bản&quot;&gt;&lt;strong&gt;Bài toán cơ bản&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{x} \lVert Ax - b \rVert_2^2\)&lt;/p&gt;

&lt;h4 id=&quot;nghiệm-dạng-đóng-hệ-phương-trình-chuẩn&quot;&gt;&lt;strong&gt;Nghiệm dạng đóng (Hệ phương trình chuẩn)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^* = (A^T A)^{-1} A^T b\)&lt;/p&gt;

&lt;h4 id=&quot;hồi-quy-tuyến-tính&quot;&gt;&lt;strong&gt;Hồi quy tuyến tính&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Một biến:&lt;/strong&gt; \(m = \frac{\sum(x_i - \bar{x})(y_i - \bar{y})}{\sum(x_i - \bar{x})^2}\), \(c = \bar{y} - m\bar{x}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhiều biến:&lt;/strong&gt; \(\beta^* = (X^T X)^{-1} X^T y\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-vii-gradient-descent-chương-06&quot;&gt;⚡ &lt;strong&gt;PHẦN VII: GRADIENT DESCENT (Chương 06)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-15-thuật-toán-cơ-bản&quot;&gt;🎯 &lt;strong&gt;15. Thuật toán Cơ bản&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;quy-tắc-cập-nhật&quot;&gt;&lt;strong&gt;Quy tắc cập nhật&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t \nabla f(x^{(k-1)})\)&lt;/p&gt;

&lt;h4 id=&quot;diễn-giải&quot;&gt;&lt;strong&gt;Diễn giải&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Gradient \(\nabla f(x)\) chỉ hướng tăng dốc nhất.&lt;/li&gt;
  &lt;li&gt;Gradient âm \(-\nabla f(x)\) chỉ hướng giảm dốc nhất.&lt;/li&gt;
  &lt;li&gt;Tại điểm cực tiểu: \(\nabla f(x^*) = 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-16-lựa-chọn-kích-thước-bước&quot;&gt;📏 &lt;strong&gt;16. Lựa chọn Kích thước Bước&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;kích-thước-bước-cố-định&quot;&gt;&lt;strong&gt;Kích thước bước cố định&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t = \text{const} &amp;gt; 0\)&lt;/p&gt;

&lt;h4 id=&quot;tìm-kiếm-đường-lùi-backtracking-line-search&quot;&gt;&lt;strong&gt;Tìm kiếm đường lùi (Backtracking Line Search)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Điều kiện Armijo:&lt;/strong&gt; \(f(x + t\Delta x) \le f(x) + \alpha t \nabla f(x)^T \Delta x\)&lt;/p&gt;

&lt;h4 id=&quot;tìm-kiếm-đường-chính-xác-exact-line-search&quot;&gt;&lt;strong&gt;Tìm kiếm đường chính xác (Exact Line Search)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t^* = \arg\min_{t &amp;gt; 0} f(x + t\Delta x)\)&lt;/p&gt;

&lt;h3 id=&quot;-17-phân-tích-hội-tụ&quot;&gt;📊 &lt;strong&gt;17. Phân tích Hội tụ&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;điều-kiện-lipschitz&quot;&gt;&lt;strong&gt;Điều kiện Lipschitz&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lVert \nabla f(x) - \nabla f(y) \rVert_2 \le L \lVert x - y \rVert_2\)&lt;/p&gt;

&lt;h4 id=&quot;hội-tụ-cho-hàm-lồi&quot;&gt;&lt;strong&gt;Hội tụ cho hàm lồi&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f(x^{(k)}) - f^* \le \frac{\lVert x^{(0)} - x^* \rVert_2^2}{2tk}\)
&lt;strong&gt;Tốc độ:&lt;/strong&gt; \(O(1/k)\) — dưới tuyến tính (sublinear).&lt;/p&gt;

&lt;h4 id=&quot;hội-tụ-cho-hàm-lồi-mạnh&quot;&gt;&lt;strong&gt;Hội tụ cho hàm lồi mạnh&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f(x^{(k)}) - f^* \le \left(1 - \frac{m}{L}\right)^k \left(f(x^{(0)}) - f^*\right) \quad (t = 1/L)\)
&lt;strong&gt;Tốc độ:&lt;/strong&gt; \(O(\rho^k)\) với \(\rho &amp;lt; 1\) — tuyến tính (linear).&lt;/p&gt;

&lt;h3 id=&quot;-18-stochastic-gradient-descent-sgd&quot;&gt;🎲 &lt;strong&gt;18. Stochastic Gradient Descent (SGD)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-tổng&quot;&gt;&lt;strong&gt;Bài toán tổng&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) = \min_x \sum_{i=1}^m f_i(x)\)&lt;/p&gt;

&lt;h4 id=&quot;so-sánh-batch-gd-và-sgd&quot;&gt;&lt;strong&gt;So sánh Batch GD và SGD&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Batch GD:&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - t_k \sum_{i=1}^m \nabla f_i(x^{(k-1)})\) — chi phí \(O(m)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SGD:&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - t_k \nabla f_{i_k}(x^{(k-1)})\) — chi phí \(O(1)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;mini-batch-sgd&quot;&gt;&lt;strong&gt;Mini-batch SGD&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k \frac{1}{b} \sum_{i \in \mathcal{B}_k} \nabla f_i(x^{(k-1)})\)&lt;/p&gt;

&lt;h3 id=&quot;-19-momentum-và-các-kỹ-thuật-nâng-cao&quot;&gt;⚡ &lt;strong&gt;19. Momentum và Các Kỹ thuật Nâng cao&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;momentum-cổ-điển&quot;&gt;&lt;strong&gt;Momentum cổ điển&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
v^{(k)} &amp;amp;= \beta v^{(k-1)} + \nabla f(x^{(k-1)}) \\
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;các-phương-pháp-thích-ứng&quot;&gt;&lt;strong&gt;Các phương pháp thích ứng&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;AdaGrad:&lt;/strong&gt; Điều chỉnh tốc độ học theo tổng bình phương gradient quá khứ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;RMSprop:&lt;/strong&gt; Dùng trung bình trượt có trọng số mũ cho bình phương gradient.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adam:&lt;/strong&gt; Kết hợp momentum và tốc độ học thích ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-viii-kết-nối-và-tổng-hợp&quot;&gt;🔗 &lt;strong&gt;PHẦN VIII: KẾT NỐI VÀ TỔNG HỢP&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-20-mối-liên-hệ-giữa-các-khái-niệm&quot;&gt;🌟 &lt;strong&gt;20. Mối liên hệ giữa Các Khái niệm&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;chuỗi-logic-xây-dựng&quot;&gt;&lt;strong&gt;Chuỗi logic xây dựng&lt;/strong&gt;&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Nền tảng toán học (Ch 00)
    ↓
Khái niệm tối ưu hóa (Ch 01)
    ↓
Tập lồi (Ch 02) → Hàm lồi (Ch 03)
    ↓
Điều kiện tối ưu (Ch 04)
    ↓
Bài toán cụ thể (Ch 05) → Thuật toán (Ch 06)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;các-kết-nối-chính&quot;&gt;&lt;strong&gt;Các kết nối chính&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient&lt;/strong&gt; (Ch 00) → &lt;strong&gt;Điều kiện tối ưu bậc nhất&lt;/strong&gt; (Ch 04) → &lt;strong&gt;Gradient descent&lt;/strong&gt; (Ch 06).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập lồi&lt;/strong&gt; (Ch 02) + &lt;strong&gt;Hàm lồi&lt;/strong&gt; (Ch 03) → &lt;strong&gt;Bài toán lồi&lt;/strong&gt; (Ch 01, 04, 05).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khai triển Taylor&lt;/strong&gt; (Ch 00) → &lt;strong&gt;Diễn giải gradient descent&lt;/strong&gt; (Ch 06).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trị riêng&lt;/strong&gt; (Ch 00) → &lt;strong&gt;Ma trận xác định dương&lt;/strong&gt; (Ch 03) → &lt;strong&gt;Ma trận Hessian&lt;/strong&gt; (Ch 04).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-21-quy-trình-ứng-dụng-thống-nhất&quot;&gt;🎯 &lt;strong&gt;21. Quy trình Ứng dụng Thống nhất&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;quy-trình-trong-học-máy&quot;&gt;&lt;strong&gt;Quy trình trong Học máy&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình hóa:&lt;/strong&gt; Chuyển bài toán học máy thành bài toán tối ưu (Ch 01, 05).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích:&lt;/strong&gt; Kiểm tra tính lồi của hàm mục tiêu và tập ràng buộc (Ch 02, 03).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện tối ưu:&lt;/strong&gt; Thiết lập điều kiện bậc nhất / bậc hai (Ch 04).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán giải:&lt;/strong&gt; Áp dụng gradient descent hoặc biến thể phù hợp (Ch 06).&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;ví-dụ-hồi-quy-tuyến-tính&quot;&gt;&lt;strong&gt;Ví dụ: Hồi quy Tuyến tính&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; \(\min_w \lVert Xw - y \rVert_2^2\) (Ch 05 — Bình phương tối thiểu).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi:&lt;/strong&gt; Hàm mục tiêu là hàm lồi (Ch 03).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện tối ưu:&lt;/strong&gt; \(\nabla f(w^*) = 2X^T(Xw^* - y) = 0\) (Ch 04).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiệm đóng:&lt;/strong&gt; \(w^* = (X^TX)^{-1}X^Ty\) (Ch 05).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán lặp:&lt;/strong&gt; Gradient descent với \(\nabla f(w) = 2X^T(Xw - y)\) (Ch 06).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-22-so-sánh-và-lựa-chọn-phương-pháp&quot;&gt;🔄 &lt;strong&gt;22. So sánh và Lựa chọn Phương pháp&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Bài toán&lt;/th&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Ưu điểm&lt;/th&gt;
      &lt;th&gt;Nhược điểm&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;LP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Simplex&lt;/td&gt;
      &lt;td&gt;Chính xác, hiệu quả&lt;/td&gt;
      &lt;td&gt;Chỉ áp dụng cho LP&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Active Set&lt;/td&gt;
      &lt;td&gt;Chính xác&lt;/td&gt;
      &lt;td&gt;Phức tạp khi số ràng buộc lớn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Least Squares&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hệ phương trình chuẩn&lt;/td&gt;
      &lt;td&gt;Có nghiệm đóng&lt;/td&gt;
      &lt;td&gt;Độ phức tạp \(O(n^3)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Lồi tổng quát&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Gradient Descent&lt;/td&gt;
      &lt;td&gt;Đơn giản, tổng quát&lt;/td&gt;
      &lt;td&gt;Hội tụ chậm khi điều kiện xấu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Quy mô lớn&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;SGD&lt;/td&gt;
      &lt;td&gt;Nhanh, dễ mở rộng&lt;/td&gt;
      &lt;td&gt;Dao động do nhiễu&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;-23-nguyên-tắc-thiết-kế-và-vận-dụng-thuật-toán&quot;&gt;💡 &lt;strong&gt;23. Nguyên tắc Thiết kế và Vận dụng Thuật toán&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;từ-lý-thuyết-đến-thực-hành&quot;&gt;&lt;strong&gt;Từ lý thuyết đến thực hành&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích bài toán:&lt;/strong&gt; Xác định tính lồi, độ trơn và điều kiện tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn thuật toán:&lt;/strong&gt; Dựa trên cấu trúc và kích thước bài toán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tinh chỉnh tham số:&lt;/strong&gt; Tốc độ học, kích thước lô và tiêu chí dừng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh giá hiệu năng:&lt;/strong&gt; Theo dõi tốc độ hội tụ và chi phí tính toán.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;các-đánh-đổi-quan-trọng&quot;&gt;&lt;strong&gt;Các đánh đổi quan trọng&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Độ chính xác và tốc độ:&lt;/strong&gt; Phương pháp giải chính xác so với phương pháp lặp bậc nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bộ nhớ và chi phí tính toán:&lt;/strong&gt; Batch GD so với SGD.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ đơn giản và hiệu năng:&lt;/strong&gt; GD cơ bản so với các bộ tối ưu thích ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-ix-tổng-kết-và-hướng-mở-rộng&quot;&gt;🎓 &lt;strong&gt;PHẦN IX: TỔNG KẾT VÀ HƯỚNG MỞ RỘNG&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-24-những-điểm-mấu-chốt&quot;&gt;🌟 &lt;strong&gt;24. Những Điểm Mấu chốt&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;vai-trò-của-tối-ưu-hóa-lồi&quot;&gt;&lt;strong&gt;Vai trò của tối ưu hóa lồi&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Đảm bảo cực tiểu toàn cục:&lt;/strong&gt; Không gặp bẫy cực tiểu cục bộ giả.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán hiệu quả:&lt;/strong&gt; Nhiều lớp bài toán giải được trong thời gian đa thức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cơ sở lý thuyết chặt chẽ:&lt;/strong&gt; Có các cận tốc độ hội tụ rõ ràng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng rộng rãi:&lt;/strong&gt; Học máy, xử lý tín hiệu, tài chính và kỹ thuật.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;gradient-descent-trong-học-máy&quot;&gt;&lt;strong&gt;Gradient descent trong học máy&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Backpropagation&lt;/strong&gt; = Quy tắc dây chuyền + Gradient descent.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học sâu&lt;/strong&gt; = Mini-batch SGD + Momentum + Các phương pháp thích ứng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các bộ tối ưu hiện đại&lt;/strong&gt; = Các biến thể mở rộng từ nền tảng gradient descent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-25-nội-dung-tiếp-theo&quot;&gt;🚀 &lt;strong&gt;25. Nội dung Tiếp theo&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;từ-chương-07-trở-đi&quot;&gt;&lt;strong&gt;Từ Chương 07 trở đi&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp dưới gradient (Subgradient):&lt;/strong&gt; Tối ưu hóa hàm không trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp gradient gần kề (Proximal methods):&lt;/strong&gt; Tối ưu hóa hàm hợp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết đối ngẫu (Duality):&lt;/strong&gt; Hàm Lagrange và điều kiện KKT.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp điểm trong (Interior-point methods):&lt;/strong&gt; Thuật toán thời gian đa thức cho bài toán có ràng buộc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;các-lĩnh-vực-ứng-dụng&quot;&gt;&lt;strong&gt;Các lĩnh vực ứng dụng&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Học sâu:&lt;/strong&gt; Mạng nơ-ron sâu, Transformer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học tăng cường:&lt;/strong&gt; Tối ưu hóa chính sách (policy optimization).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa phân tán:&lt;/strong&gt; Học liên kết (federated learning).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa lượng tử:&lt;/strong&gt; Các thuật toán tối ưu lượng tử.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-26-kinh-nghiệm-học-tập-và-thực-hành&quot;&gt;🎯 &lt;strong&gt;26. Kinh nghiệm Học tập và Thực hành&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;cách-tiếp-cận-hiệu-quả&quot;&gt;&lt;strong&gt;Cách tiếp cận hiệu quả&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Củng cố nền tảng:&lt;/strong&gt; Nắm chắc giải tích và đại số tuyến tính.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên kết kiến thức:&lt;/strong&gt; Theo dõi mạch kết nối xuyên suốt giữa các chương.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thực hành cài đặt:&lt;/strong&gt; Tự lập trình và đối chiếu kết quả thực nghiệm với lý thuyết.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng thực tế:&lt;/strong&gt; Gắn các bài toán tối ưu vào mô hình học máy cụ thể.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;kiểm-tra-khi-cài-đặt&quot;&gt;&lt;strong&gt;Kiểm tra khi cài đặt&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra tính lồi:&lt;/strong&gt; Xác minh bài toán được phát biểu đúng và có nghiệm ổn định.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra gradient:&lt;/strong&gt; So sánh gradient giải tích với sai phân hữu hạn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theo dõi hội tụ:&lt;/strong&gt; Quan sát đường cong mất mát và chuẩn gradient.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tinh chỉnh siêu tham số:&lt;/strong&gt; Điều chỉnh tốc độ học và kích thước lô hợp lý.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-kết-luận&quot;&gt;💡 &lt;strong&gt;KẾT LUẬN&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Mạch kiến thức từ chương 00 đến chương 06 đi theo trình tự thống nhất:&lt;/p&gt;

&lt;p&gt;🔢 &lt;strong&gt;Nền tảng toán học&lt;/strong&gt; → 🎯 &lt;strong&gt;Khái niệm tối ưu hóa&lt;/strong&gt; → 🔵 &lt;strong&gt;Tập lồi&lt;/strong&gt; → 📈 &lt;strong&gt;Hàm lồi&lt;/strong&gt; → 🏆 &lt;strong&gt;Điều kiện tối ưu&lt;/strong&gt; → 📊 &lt;strong&gt;Bài toán kinh điển&lt;/strong&gt; → ⚡ &lt;strong&gt;Thuật toán thực tế&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hệ thống kiến thức này tạo nền tảng trực tiếp cho việc hiểu, phân tích và triển khai các thuật toán tối ưu hóa trong học máy và các lĩnh vực kỹ thuật hiện đại.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;em&gt;“Optimization is the engine of machine learning, and convex optimization is its most reliable and well-understood component.”&lt;/em&gt;&lt;/p&gt;

&lt;style&gt;
/* Custom styling for comprehensive review */
.MathJax {
    vertical-align: baseline !important;
}

h2 {
    color: #2c3e50;
    border-bottom: 2px solid #3498db;
    padding-bottom: 10px;
}

h3 {
    color: #34495e;
    margin-top: 25px;
}

h4 {
    color: #7f8c8d;
    margin-top: 20px;
}

blockquote {
    background-color: #f8f9fa;
    border-left: 4px solid #3498db;
    padding: 15px;
    margin: 20px 0;
    font-style: italic;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

table th, table td {
    border: 1px solid #ddd;
    padding: 12px;
    text-align: left;
}

table th {
    background-color: #f2f2f2;
    font-weight: bold;
}

.highlight-box {
    background-color: #e8f4fd;
    border: 1px solid #bee5eb;
    border-radius: 5px;
    padding: 15px;
    margin: 15px 0;
}

.formula-box {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    padding: 10px;
    margin: 10px 0;
    text-align: center;
}

code {
    background-color: #f1f1f1;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
}

pre {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 5px;
    padding: 15px;
    overflow-x: auto;
}
&lt;/style&gt;

</content>
 </entry>
 
 <entry>
   <title>06-09 Bài tập trắc nghiệm - Gradient Descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_09_Quiz_Gradient_Descent/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_09_Quiz_Gradient_Descent</id>
   <content type="html">&lt;p&gt;Chương 06 là chương dài và giàu kỹ thuật nhất từ đầu khóa học đến nay: từ cận trên bậc hai, điều kiện Armijo, tốc độ \(O(1/k)\) vs. \(O(c^k)\), cận dưới Nesterov, cho đến SGD, Momentum, Gradient Boosting và Điều chuẩn. Khi quá nhiều định lý đứng cạnh nhau, não bộ rất dễ trộn lẫn các giả thiết — ví dụ nhầm lẫn điều kiện cần của hội tụ tuyến tính, hay nhầm giữa bước cố định an toàn \(1/L\) và ngưỡng ổn định \(2/L\).&lt;/p&gt;

&lt;p&gt;Bộ bài tập trắc nghiệm này là bài kiểm tra tổng lực giúp bạn khóa chặt mọi định lý, công thức và trực giác hình học của Chương 06 trước khi sang thế giới không khả vi của Chương 07!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bảng-tra-nhanh-4-điểm-dễ-nhầm-nhất-của-chương-06&quot;&gt;Kiến thức cần nhớ: Bảng tra nhanh 4 điểm dễ nhầm nhất của Chương 06&lt;/h2&gt;

&lt;p&gt;Hãy rà soát nhanh bốn phân biệt cốt lõi trước khi trả lời các câu hỏi trắc nghiệm:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ hội tụ theo lớp hàm (với GD chuẩn):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Lồi + \(L\)-trơn: \(O(1/k)\) (cần \(O(1/\epsilon)\) bước).&lt;/li&gt;
      &lt;li&gt;Lồi mạnh \(m\) + \(L\)-trơn: hội tụ tuyến tính \(O\big((1 - m/L)^k\big)\) (cần \(O(\kappa \log(1/\epsilon))\) bước).&lt;/li&gt;
      &lt;li&gt;Tăng tốc Nesterov: cải thiện thành \(O(1/k^2)\) (lồi trơn) và \(O(\sqrt{\kappa} \log(1/\epsilon))\) (lồi mạnh).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước an toàn vs. Ngưỡng phân kỳ (trên hàm bậc hai \(L\)-trơn):&lt;/strong&gt; \(t \le 1/L\) đảm bảo giảm đơn điệu theo Bổ đề Giảm; \(1/L &amp;lt; t &amp;lt; 2/L\) vẫn hội tụ nhưng có dao động; \(t \ge 2/L\) không hội tụ / phân kỳ!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SGD vs. Batch GD:&lt;/strong&gt; SGD có chi phí mỗi bước \(O(p)\) (độc lập với \(N\)) thay vì \(O(Np)\), nhưng với bước cố định chỉ hội tụ vào vùng lân cận nghiệm; muốn hội tụ chính xác về \(x^\star\) cần giảm bước theo điều kiện Robbins–Monro (\(\sum t_k = \infty, \sum t_k^2 &amp;lt; \infty\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Line Search:&lt;/strong&gt; Hai bước liên tiếp luôn trực giao (\(\nabla f(x_{k+1})^T \nabla f(x_k) = 0\)), nên vẫn có thể đi zíc-zắc chậm trên thung lũng hẹp có \(\kappa\) lớn!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chẩn-đoán-nhanh-một-câu-hỏi-trắc-nghiệm-điển-hình-về-số-vòng-lặp&quot;&gt;Giải thích: Chẩn đoán nhanh một câu hỏi trắc nghiệm điển hình về số vòng lặp&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi mẫu:&lt;/strong&gt; &lt;em&gt;Hàm \(f\) lồi mạnh với \(m = 2\) và gradient Lipschitz \(L = 20\). Nếu dùng Gradient Descent bước cố định \(t = 1/L\), sau mỗi bước lặp sai số \(f(x^{(k)}) - f^\star\) giảm đi ít nhất bao nhiêu phần trăm?&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Áp dụng công thức hội tụ tuyến tính:&lt;/strong&gt;
\(f(x^{(k+1)}) - f^\star \le (1 - mt)\big(f(x^{(k)}) - f^\star\big).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Thay số \(m = 2,\; t = 1/L = 1/20 = 0.05\):&lt;/strong&gt;
\(1 - mt = 1 - 2(0.05) = 1 - 0.1 = 0.9.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Đọc kết quả chính xác:&lt;/strong&gt; Sai số sau bước mới bằng tối đa \(90\%\) sai số cũ — tức là &lt;strong&gt;giảm ít nhất \(10\%\)&lt;/strong&gt; sau mỗi vòng lặp! (Mẹo nhanh: với \(t = 1/L\), tỷ lệ giảm mỗi bước luôn là \(1/\kappa = m/L\)!)&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập Lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-gradient-descent-cơ-bản&quot;&gt;🎯 &lt;strong&gt;Gradient Descent Cơ bản&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán tối ưu:&lt;/strong&gt;
\(\min_x f(x), \quad f 	ext{ khả vi và } 	ext{dom}(f) = \mathbb{R}^n\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quy tắc cập nhật:&lt;/strong&gt;
\(x^{(k)} = x^{(k-1)} - t 
abla f(x^{(k-1)}), \quad k = 1, 2, 3, \ldots\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mã giả:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cho điểm khởi tạo&lt;/strong&gt; \(x \in 	ext{dom}(f)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lặp lại:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Xác định hướng giảm: \(\Delta x = -
abla f(x)\)&lt;/li&gt;
      &lt;li&gt;Tìm kiếm đường: chọn kích thước bước \(t &amp;gt; 0\)&lt;/li&gt;
      &lt;li&gt;Cập nhật: \(x = x + t \Delta x\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cho đến khi&lt;/strong&gt; tiêu chuẩn dừng được thỏa mãn&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Diễn giải hình học:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Gradient \(abla f(x)\) chỉ hướng tăng dốc nhất.&lt;/li&gt;
  &lt;li&gt;Gradient âm \(-
abla f(x)\) chỉ hướng giảm dốc nhất.&lt;/li&gt;
  &lt;li&gt;Tại điểm cực tiểu không ràng buộc: \(abla f(x^*) = 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-cách-chọn-kích-thước-bước&quot;&gt;📏 &lt;strong&gt;Cách Chọn Kích thước Bước&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-kích-thước-bước-cố-định&quot;&gt;&lt;strong&gt;1. Kích thước bước cố định&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t = 	ext{const} &amp;gt; 0\)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Đơn giản, chi phí mỗi bước thấp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhược điểm:&lt;/strong&gt; Khó chọn trước giá trị phù hợp cho mọi bài toán.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-tìm-kiếm-đường-lùi-backtracking-line-search&quot;&gt;&lt;strong&gt;2. Tìm kiếm đường lùi (Backtracking Line Search)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Điều kiện Armijo:&lt;/strong&gt;
\(f(x + t\Delta x) \le f(x) + lpha t 
abla f(x)^T \Delta x\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thuật toán:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Khởi tạo \(t = t_0\).&lt;/li&gt;
  &lt;li&gt;Nếu điều kiện Armijo chưa thỏa mãn: giảm \(t := eta t\) (với \(0 &amp;lt; eta &amp;lt; 1\)).&lt;/li&gt;
  &lt;li&gt;Lặp lại cho đến khi điều kiện được đáp ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tham số thường dùng:&lt;/strong&gt; \(lpha = 0.01 \div 0.3\), \(eta = 0.1 \div 0.8\).&lt;/p&gt;

&lt;h4 id=&quot;3-tìm-kiếm-đường-chính-xác-exact-line-search&quot;&gt;&lt;strong&gt;3. Tìm kiếm đường chính xác (Exact Line Search)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t^* = rg\min_{t &amp;gt; 0} f(x + t\Delta x)\)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Tối ưu theo hướng hiện tại.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhược điểm:&lt;/strong&gt; Tốn kém về tính toán với hàm phi tuyến tổng quát.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-phân-tích-hội-tụ&quot;&gt;📊 &lt;strong&gt;Phân tích Hội tụ&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;điều-kiện-lipschitz&quot;&gt;&lt;strong&gt;Điều kiện Lipschitz&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Gradient \(abla f\) liên tục Lipschitz với hằng số \(L &amp;gt; 0\):
\(\lVert 
abla f(x) - 
abla f(y) 
Vert_2 \le L \lVert x - y 
Vert_2\)&lt;/p&gt;

&lt;h4 id=&quot;định-lý-hội-tụ-cho-hàm-lồi&quot;&gt;&lt;strong&gt;Định lý hội tụ cho hàm lồi&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Với kích thước bước cố định \(t \le rac{1}{L}\):
\(f(x^{(k)}) - f^* \le rac{\lVert x^{(0)} - x^* 
Vert_2^2}{2tk}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tốc độ hội tụ:&lt;/strong&gt; \(O(1/k)\) — hội tụ dưới tuyến tính (sublinear).&lt;/p&gt;

&lt;h4 id=&quot;định-lý-hội-tụ-cho-hàm-lồi-mạnh&quot;&gt;&lt;strong&gt;Định lý hội tụ cho hàm lồi mạnh&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Nếu \(f\) lồi mạnh với hằng số \(m &amp;gt; 0\):
\(f(x^{(k)}) - f^* \le \left(1 - rac{m}{L}
ight)^k \left(f(x^{(0)}) - f^*
ight) \quad (t = 1/L)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tốc độ hội tụ:&lt;/strong&gt; \(O(
ho^k)\) với \(ho &amp;lt; 1\) — hội tụ tuyến tính (linear).&lt;/p&gt;

&lt;h4 id=&quot;chỉ-số-điều-kiện&quot;&gt;&lt;strong&gt;Chỉ số điều kiện&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\kappa = rac{L}{m}\) — tỉ số giữa hằng số Lipschitz và hằng số lồi mạnh:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\kappa\) nhỏ: hội tụ nhanh.&lt;/li&gt;
  &lt;li&gt;\(\kappa\) lớn: hội tụ chậm (bài toán điều kiện xấu).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-stochastic-gradient-descent-sgd&quot;&gt;🎲 &lt;strong&gt;Stochastic Gradient Descent (SGD)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-tổng&quot;&gt;&lt;strong&gt;Bài toán tổng&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) = \min_x \sum_{i=1}^m f_i(x)\)&lt;/p&gt;

&lt;h4 id=&quot;batch-gradient-descent&quot;&gt;&lt;strong&gt;Batch Gradient Descent&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k \sum_{i=1}^m 
abla f_i(x^{(k-1)})\)
&lt;strong&gt;Chi phí:&lt;/strong&gt; \(O(m)\) lần tính gradient trên mỗi bước lặp.&lt;/p&gt;

&lt;h4 id=&quot;stochastic-gradient-descent&quot;&gt;&lt;strong&gt;Stochastic Gradient Descent&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k 
abla f_{i_k}(x^{(k-1)})\)
&lt;strong&gt;Chi phí:&lt;/strong&gt; \(O(1)\) lần tính gradient trên mỗi bước lặp.&lt;/p&gt;

&lt;h4 id=&quot;chiến-lược-chọn-chỉ-số&quot;&gt;&lt;strong&gt;Chiến lược chọn chỉ số&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc tuần hoàn:&lt;/strong&gt; \(i_k = 1, 2, \ldots, m, 1, 2, \ldots\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc ngẫu nhiên:&lt;/strong&gt; Chọn \(i_k\) ngẫu nhiên đều từ \(\{1, 2, \ldots, m\}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;mini-batch-sgd&quot;&gt;&lt;strong&gt;Mini-batch SGD&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k rac{1}{b} \sum_{i \in \mathcal{B}_k} 
abla f_i(x^{(k-1)})\)
trong đó \(\mathcal{B}_k\) là mini-batch gồm \(b\) mẫu.&lt;/p&gt;

&lt;h3 id=&quot;-gradient-descent-có-momentum&quot;&gt;⚡ &lt;strong&gt;Gradient Descent có Momentum&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;momentum-cổ-điển&quot;&gt;&lt;strong&gt;Momentum cổ điển&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(egin{align}
v^{(k)} &amp;amp;= eta v^{(k-1)} + 
abla f(x^{(k-1)}) \
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;nesterov-accelerated-gradient-nag&quot;&gt;&lt;strong&gt;Nesterov Accelerated Gradient (NAG)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(egin{align}
v^{(k)} &amp;amp;= eta v^{(k-1)} + 
abla f(x^{(k-1)} - teta v^{(k-1)}) \
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tham số thường dùng:&lt;/strong&gt; \(eta = 0.9\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tăng tốc độ hội tụ dọc theo các hướng nhất quán.&lt;/li&gt;
  &lt;li&gt;Giảm dao động cục bộ.&lt;/li&gt;
  &lt;li&gt;Hạn chế ảnh hưởng của nhiễu gradient.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-so-sánh-các-phương-pháp&quot;&gt;🔄 &lt;strong&gt;So sánh Các Phương pháp&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Tốc độ/lần lặp&lt;/th&gt;
      &lt;th&gt;Bộ nhớ&lt;/th&gt;
      &lt;th&gt;Hội tụ&lt;/th&gt;
      &lt;th&gt;Ứng dụng phù hợp&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Batch GD&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Chậm&lt;/td&gt;
      &lt;td&gt;Cao&lt;/td&gt;
      &lt;td&gt;Ổn định&lt;/td&gt;
      &lt;td&gt;Tập dữ liệu nhỏ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SGD&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Nhanh&lt;/td&gt;
      &lt;td&gt;Thấp&lt;/td&gt;
      &lt;td&gt;Có nhiễu&lt;/td&gt;
      &lt;td&gt;Tập dữ liệu lớn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Mini-batch&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Trung bình&lt;/td&gt;
      &lt;td&gt;Trung bình&lt;/td&gt;
      &lt;td&gt;Cân bằng&lt;/td&gt;
      &lt;td&gt;Thực tế phổ biến&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Momentum&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Nhanh&lt;/td&gt;
      &lt;td&gt;Thấp&lt;/td&gt;
      &lt;td&gt;Tăng tốc&lt;/td&gt;
      &lt;td&gt;Học sâu (deep learning)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-các-kỹ-thuật-thực-tế&quot;&gt;🛠️ &lt;strong&gt;Các Kỹ thuật Thực tế&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;lập-lịch-tốc-độ-học-learning-rate-scheduling&quot;&gt;&lt;strong&gt;Lập lịch tốc độ học (Learning Rate Scheduling)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Giảm theo bậc (Step decay):&lt;/strong&gt; \(t_k = t_0 \cdot \gamma^{\lfloor k/s 
floor}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giảm theo hàm mũ (Exponential decay):&lt;/strong&gt; \(t_k = t_0 \cdot e^{-\lambda k}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giảm theo đa thức (Polynomial decay):&lt;/strong&gt; \(t_k = t_0 \cdot (1 + \lambda k)^{-p}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;phương-pháp-thích-ứng-adaptive-methods&quot;&gt;&lt;strong&gt;Phương pháp thích ứng (Adaptive Methods)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;AdaGrad:&lt;/strong&gt; Điều chỉnh tốc độ học dựa trên tổng bình phương gradient quá khứ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;RMSprop:&lt;/strong&gt; Cải tiến AdaGrad bằng trung bình trượt có trọng số mũ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adam:&lt;/strong&gt; Kết hợp momentum và tốc độ học thích ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;điều-chuẩn-regularization&quot;&gt;&lt;strong&gt;Điều chuẩn (Regularization)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều chuẩn L1:&lt;/strong&gt; \(f(x) + \lambda \lVert x 
Vert_1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều chuẩn L2:&lt;/strong&gt; \(f(x) + rac{\lambda}{2} \lVert x 
Vert_2^2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dropout:&lt;/strong&gt; Tắt ngẫu nhiên các nút trong mạng nơ-ron khi huấn luyện.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ứng-dụng-thực-tế&quot;&gt;📈 &lt;strong&gt;Ứng dụng Thực tế&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;học-máy-machine-learning&quot;&gt;&lt;strong&gt;Học máy (Machine Learning)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hồi quy tuyến tính:&lt;/strong&gt; \(\min_w \lVert Xw - y 
Vert_2^2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hồi quy logistic:&lt;/strong&gt; \(\min_w \sum_i \log(1 + e^{-y_i w^T x_i})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mạng nơ-ron:&lt;/strong&gt; Lan truyền ngược (backpropagation) kết hợp SGD.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;học-sâu-deep-learning&quot;&gt;&lt;strong&gt;Học sâu (Deep Learning)&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mạng tích chập (CNNs)&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mạng hồi quy (RNNs)&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình Transformer&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;các-bài-toán-tối-ưu-hóa-khác&quot;&gt;&lt;strong&gt;Các bài toán tối ưu hóa khác&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa danh mục đầu tư&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xử lý tín hiệu&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thị giác máy tính&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-tiêu-chí-dừng&quot;&gt;🔍 &lt;strong&gt;Tiêu chí Dừng&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;theo-chuẩn-gradient&quot;&gt;&lt;strong&gt;Theo chuẩn gradient&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lVert 
abla f(x^{(k)}) 
Vert_2 &amp;lt; \epsilon\)&lt;/p&gt;

&lt;h4 id=&quot;theo-độ-thay-đổi-giá-trị-hàm&quot;&gt;&lt;strong&gt;Theo độ thay đổi giá trị hàm&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(|f(x^{(k)}) - f(x^{(k-1)})| &amp;lt; \epsilon\)&lt;/p&gt;

&lt;h4 id=&quot;theo-độ-thay-đổi-tham-số&quot;&gt;&lt;strong&gt;Theo độ thay đổi tham số&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lVert x^{(k)} - x^{(k-1)} 
Vert_2 &amp;lt; \epsilon\)&lt;/p&gt;

&lt;h4 id=&quot;theo-số-lần-lặp-tối-đa&quot;&gt;&lt;strong&gt;Theo số lần lặp tối đa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(k &amp;gt; k_{\max}\)&lt;/p&gt;

&lt;h3 id=&quot;️-thách-thức-và-giải-pháp&quot;&gt;⚠️ &lt;strong&gt;Thách thức và Giải pháp&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;các-vấn-đề-thường-gặp&quot;&gt;&lt;strong&gt;Các vấn đề thường gặp:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient tiêu biến / bùng nổ (Vanishing/exploding gradients):&lt;/strong&gt; Gradient quá nhỏ hoặc quá lớn qua nhiều tầng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm yên ngựa (Saddle points):&lt;/strong&gt; Xuất hiện phổ biến trong không gian nhiều chiều.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu cục bộ (Local minima):&lt;/strong&gt; Với các hàm mục tiêu không lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện xấu (Ill-conditioning):&lt;/strong&gt; Chỉ số điều kiện \(\kappa\) lớn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;các-giải-pháp-phổ-biến&quot;&gt;&lt;strong&gt;Các giải pháp phổ biến:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cắt ngưỡng gradient (Gradient clipping):&lt;/strong&gt; Giới hạn chuẩn của gradient.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn hóa theo lô (Batch normalization):&lt;/strong&gt; Ổn định phân phối đầu vào của từng tầng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết nối tắt (Residual connections):&lt;/strong&gt; Giúp lan truyền gradient ổn định hơn trong mạng sâu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiền điều kiện hóa (Preconditioning):&lt;/strong&gt; Biến đổi thang đo không gian tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-kinh-nghiệm-thực-hành&quot;&gt;💡 &lt;strong&gt;Kinh nghiệm Thực hành&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;chọn-tốc-độ-học&quot;&gt;&lt;strong&gt;Chọn tốc độ học:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;Bắt đầu thử từ \(t = 0.01\).&lt;/li&gt;
  &lt;li&gt;Điều chỉnh tăng hoặc giảm theo lũy thừa của 10.&lt;/li&gt;
  &lt;li&gt;Theo dõi đường cong mất mát (loss curve).&lt;/li&gt;
  &lt;li&gt;Kết hợp lập lịch giảm tốc độ học.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;kiểm-tra-và-gỡ-lỗi&quot;&gt;&lt;strong&gt;Kiểm tra và gỡ lỗi:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Kiểm tra lại công thức tính gradient (so sánh với đạo hàm số).&lt;/li&gt;
  &lt;li&gt;Trực quan hóa đường cong mất mát.&lt;/li&gt;
  &lt;li&gt;Theo dõi chuẩn của gradient trong quá trình huấn luyện.&lt;/li&gt;
  &lt;li&gt;Đánh giá định kỳ trên tập thẩm định (validation set).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tăng-tốc-huấn-luyện&quot;&gt;&lt;strong&gt;Tăng tốc huấn luyện:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Dùng mini-batch thay vì toàn tập.&lt;/li&gt;
  &lt;li&gt;Huấn luyện song song hoặc phân tán.&lt;/li&gt;
  &lt;li&gt;Tận dụng phần cứng tăng tốc (GPU).&lt;/li&gt;
  &lt;li&gt;Huấn luyện với độ chính xác hỗn hợp (mixed precision).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Ghi chú:&lt;/strong&gt; Gradient descent là nền tảng của phần lớn thuật toán học máy hiện đại. Nắm vững các biến thể và kỹ thuật điều chỉnh sẽ giúp huấn luyện mô hình ổn định và hiệu quả hơn.&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra hiểu biết của bạn về thuật toán gradient descent và các biến thể, bao gồm lựa chọn kích thước bước, phân tích hội tụ, SGD và momentum.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Bài tập trắc nghiệm: Gradient Descent&lt;/h2&gt;
        &lt;p&gt;Chọn đáp án đúng nhất cho mỗi câu hỏi. Bài tập tập trung vào các khái niệm cơ bản và ứng dụng thực tế của gradient descent.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Câu hỏi 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Câu hỏi 1: Quy tắc cập nhật gradient descent --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Câu 1: Quy tắc cập nhật cơ bản của gradient descent là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(x^{(k)} = x^{(k-1)} + t \nabla f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(x^{(k)} = x^{(k-1)} - t \nabla f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(x^{(k)} = x^{(k-1)} - t \nabla^2 f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(x^{(k)} = x^{(k-1)} + t f(x^{(k-1)})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$x^{(k)} = x^{(k-1)} - t \nabla f(x^{(k-1)})$$&lt;/strong&gt;&lt;br /&gt;
                Gradient descent di chuyển theo hướng ngược với gradient để giảm giá trị hàm mục tiêu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Hướng giảm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Hướng giảm trong gradient descent là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(\Delta x = \nabla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\Delta x = -\nabla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(\Delta x = \nabla^2 f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(\Delta x = f(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\Delta x = -\nabla f(x)$$&lt;/strong&gt;&lt;br /&gt;
                Hướng giảm là âm của gradient, chỉ hướng giảm nhanh nhất của hàm số.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Tác động của kích thước bước --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Nếu kích thước bước $$t$$ quá lớn, gradient descent có thể:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) Hội tụ nhanh hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Vượt quá cực tiểu và phân kỳ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Dừng lại ngay lập tức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Tìm được nghiệm chính xác&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Vượt quá cực tiểu và phân kỳ&lt;/strong&gt;&lt;br /&gt;
                Kích thước bước quá lớn có thể làm thuật toán dao động hoặc phân kỳ khỏi nghiệm tối ưu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Kích thước bước quá nhỏ --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Nếu kích thước bước $$t$$ quá nhỏ, gradient descent sẽ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Hội tụ rất chậm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Phân kỳ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Dao động&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Dừng ngay lập tức&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Hội tụ rất chậm&lt;/strong&gt;&lt;br /&gt;
                Kích thước bước quá nhỏ làm thuật toán cập nhật rất chậm, cần nhiều lần lặp để hội tụ.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Tìm kiếm đường lùi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Tìm kiếm đường lùi (backtracking line search) hoạt động bằng cách:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Tăng dần kích thước bước&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Bắt đầu với kích thước bước lớn và giảm dần&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Sử dụng kích thước bước cố định&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Tính toán đạo hàm bậc hai&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Bắt đầu với kích thước bước lớn và giảm dần&lt;/strong&gt;&lt;br /&gt;
                Backtracking bắt đầu với bước lớn và giảm dần cho đến khi đạt được mức giảm đủ (điều kiện Armijo).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Điều kiện Armijo --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Điều kiện Armijo trong backtracking yêu cầu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(f(x + t\Delta x) \leq f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(f(x + t\Delta x) \leq f(x) + \alpha t \nabla f(x)^T \Delta x\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(f(x + t\Delta x) = f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(\nabla f(x + t\Delta x) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$f(x + t\Delta x) \leq f(x) + \alpha t \nabla f(x)^T \Delta x$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện Armijo đảm bảo sự giảm đủ với tham số $$\alpha \in (0, 0.5)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Tìm kiếm đường chính xác --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Tìm kiếm đường chính xác (exact line search) tìm kích thước bước bằng cách:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Sử dụng công thức cố định&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Tối thiểu hóa \(f(x - t \nabla f(x))\) theo \(t\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Chọn ngẫu nhiên&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Sử dụng đạo hàm bậc hai&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tối thiểu hóa $$f(x - t \nabla f(x))$$ theo $$t$$&lt;/strong&gt;&lt;br /&gt;
                Exact line search tìm kích thước bước tối ưu bằng cách giải bài toán tối ưu hóa một chiều.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Điều kiện Lipschitz --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Điều kiện Lipschitz cho gradient có nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(\|\nabla f(x) - \nabla f(y)\| \leq L \|x - y\|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(\|f(x) - f(y)\| \leq L \|x - y\|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(\nabla f(x) = L\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(f(x) \leq L\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\|\nabla f(x) - \nabla f(y)\| \leq L \|x - y\|$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện Lipschitz đảm bảo gradient không thay đổi quá nhanh, quan trọng cho phân tích hội tụ.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Tốc độ hội tụ gradient descent --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Với hàm lồi và gradient Lipschitz, gradient descent có tốc độ hội tụ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(O(\log k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(O(e^{-k})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$O(1/k)$$&lt;/strong&gt;&lt;br /&gt;
                Gradient descent có tốc độ hội tụ dưới tuyến tính (sublinear) $$O(1/k)$$ cho hàm lồi với gradient Lipschitz.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: SGD vs Batch GD --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Stochastic Gradient Descent (SGD) khác với Batch GD ở chỗ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) SGD sử dụng tất cả dữ liệu mỗi lần cập nhật&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) SGD chỉ sử dụng một mẫu dữ liệu mỗi lần cập nhật&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) SGD không sử dụng gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) SGD luôn hội tụ nhanh hơn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) SGD chỉ sử dụng một mẫu dữ liệu mỗi lần cập nhật&lt;/strong&gt;&lt;br /&gt;
                SGD cập nhật tham số dựa trên gradient của một mẫu duy nhất thay vì toàn bộ tập dữ liệu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Ưu điểm của SGD --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Ưu điểm chính của SGD so với Batch GD là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Độ chính xác cao hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Chi phí tính toán thấp hơn mỗi lần cập nhật&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Luôn hội tụ đến nghiệm tối ưu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Không cần điều chỉnh tốc độ học&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Chi phí tính toán thấp hơn mỗi lần cập nhật&lt;/strong&gt;&lt;br /&gt;
                SGD có độ phức tạp $$O(1)$$ mỗi lần cập nhật so với $$O(m)$$ của Batch GD, rất hiệu quả với tập dữ liệu lớn.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Mini-batch GD --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Mini-batch Gradient Descent là sự kết hợp giữa:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) SGD và Newton method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Batch GD và SGD&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Gradient descent và momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Line search và fixed step&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Batch GD và SGD&lt;/strong&gt;&lt;br /&gt;
                Mini-batch sử dụng một tập con nhỏ dữ liệu (thường 32-256 mẫu) để cân bằng giữa hiệu quả và ổn định.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Quy tắc cập nhật momentum --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Quy tắc cập nhật của Gradient Descent với momentum là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(v^{(k)} = \beta v^{(k-1)} + \nabla f(x^{(k-1)})\), \(x^{(k)} = x^{(k-1)} + t v^{(k)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(v^{(k)} = \beta v^{(k-1)} + (1-\beta) \nabla f(x^{(k-1)})\), \(x^{(k)} = x^{(k-1)} - t v^{(k)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(x^{(k)} = x^{(k-1)} - t \beta \nabla f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(x^{(k)} = \beta x^{(k-1)} - t \nabla f(x^{(k-1)})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$v^{(k)} = \beta v^{(k-1)} + (1-\beta) \nabla f(x^{(k-1)})$$, $$x^{(k)} = x^{(k-1)} - t v^{(k)}$$&lt;/strong&gt;&lt;br /&gt;
                Momentum tích lũy vận tốc với trung bình động có trọng số mũ của các gradient. (Dạng cổ điển $$v^{(k)} = \beta v^{(k-1)} + \nabla f(x^{(k-1)})$$, $$x^{(k)} = x^{(k-1)} - t v^{(k)}$$ cũng đúng, chỉ khác thang đo của $$t$$; phương án A sai vì đi theo hướng $$+v$$, tức là tăng hàm mục tiêu.)
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Hệ số momentum --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Hệ số momentum $$\beta$$ thường được chọn trong khoảng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) [0.1, 0.3]&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) [0.5, 0.7]&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) [0.9, 0.99]&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) [1.0, 1.5]&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) [0.9, 0.99]&lt;/strong&gt;&lt;br /&gt;
                Hệ số momentum thường được chọn cao (0.9 hoặc 0.99) để duy trì &quot;bộ nhớ&quot; lâu dài của các gradient trước đó.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Ưu điểm của momentum --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Momentum giúp gradient descent:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Giảm dao động và tăng tốc hội tụ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Tăng độ chính xác tính toán&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Giảm bộ nhớ sử dụng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Loại bỏ hoàn toàn cực tiểu cục bộ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Giảm dao động và tăng tốc hội tụ&lt;/strong&gt;&lt;br /&gt;
                Momentum làm mượt quá trình tối ưu hóa, giảm dao động và giúp tăng tốc trong các hướng nhất quán.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Nesterov Accelerated Gradient --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Nesterov Accelerated Gradient (NAG) khác với momentum thông thường ở chỗ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Sử dụng hệ số momentum khác&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Tính gradient tại vị trí &quot;nhìn trước&quot;&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Không sử dụng momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Chỉ áp dụng cho hàm lồi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tính gradient tại vị trí &quot;nhìn trước&quot;&lt;/strong&gt;&lt;br /&gt;
                NAG tính gradient tại $$x^{(k-1)} - t\beta v^{(k-1)}$$ thay vì $$x^{(k-1)}$$, cho phép &quot;nhìn trước&quot; hướng di chuyển.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Ứng dụng gradient descent --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Gradient descent KHÔNG được sử dụng trực tiếp trong:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Huấn luyện neural networks&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Linear regression&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Logistic regression&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Integer programming&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Integer programming&lt;/strong&gt;&lt;br /&gt;
                Integer programming là bài toán tối ưu rời rạc, không thể sử dụng gradient descent vì không có gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Điều kiện dừng --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Điều kiện dừng phổ biến cho gradient descent là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) \(\|\nabla f(x)\| &amp;lt; \epsilon\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) \(f(x) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) \(x = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) \(t = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\|\nabla f(x)\| &amp;lt; \epsilon$$&lt;/strong&gt;&lt;br /&gt;
                Thuật toán dừng khi độ lớn gradient nhỏ hơn ngưỡng $$\epsilon$$, cho thấy đã gần đạt cực tiểu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Hàm lồi mạnh --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Với hàm lồi mạnh, gradient descent có tốc độ hội tụ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) \(O(\rho^k)\) với \(\rho &amp;lt; 1\) (linear)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) \(O(\log k)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) $$O(\rho^k)$$ với $$\rho &amp;lt; 1$$ (linear)&lt;/strong&gt;&lt;br /&gt;
                Hàm lồi mạnh cho phép gradient descent đạt tốc độ hội tụ tuyến tính (geometric), nhanh hơn nhiều so với tốc độ dưới tuyến tính.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Backpropagation --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Backpropagation trong neural networks về bản chất là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Một thuật toán tối ưu hóa mới&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Cách hiệu quả để tính gradient cho gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Thay thế cho gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Chỉ áp dụng cho hàm tuyến tính&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Cách hiệu quả để tính gradient cho gradient descent&lt;/strong&gt;&lt;br /&gt;
                Backpropagation sử dụng quy tắc dây chuyền (chain rule) để tính gradient hiệu quả trong mạng nơ-ron, sau đó dùng gradient descent để cập nhật trọng số.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Trong gradient descent, kích thước bước $$t = 0.01$$ có nghĩa là gì?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Di chuyển 1% theo hướng gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Di chuyển theo hướng $$-\nabla f$$ một bước bằng 0.01 lần gradient (độ dài $$0.01\lVert\nabla f\rVert$$)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Chia gradient cho 100&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Số lần lặp tối đa&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Di chuyển theo hướng $$-\nabla f$$ một bước bằng 0.01 lần gradient (độ dài $$0.01\lVert\nabla f\rVert$$)&lt;/strong&gt;&lt;br /&gt;
                Kích thước bước $$t$$ xác định độ dài di chuyển theo hướng $$-\nabla f$$: $$x^{(k+1)} = x^{(k)} - t\nabla f(x^{(k)})$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Điều kiện Armijo trong line search kiểm tra:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Giảm đủ của hàm mục tiêu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Độ dốc của gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Tính lồi của hàm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Hội tụ của thuật toán&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Giảm đủ của hàm mục tiêu&lt;/strong&gt;&lt;br /&gt;
                Điều kiện Armijo đảm bảo $$f(x + t\Delta x) \leq f(x) + c_1 t \nabla f(x)^T \Delta x$$ với $$c_1 \in (0,1)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: SGD khác với GD ở chỗ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Sử dụng toàn bộ dữ liệu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Sử dụng một mẫu ngẫu nhiên&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Có kích thước bước cố định&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Luôn hội tụ nhanh hơn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Sử dụng một mẫu ngẫu nhiên&lt;/strong&gt;&lt;br /&gt;
                Stochastic Gradient Descent sử dụng một mẫu (hoặc mini-batch) ngẫu nhiên thay vì toàn bộ tập dữ liệu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Momentum trong gradient descent giúp:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Tăng tốc độ hội tụ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Vượt qua cực tiểu cục bộ nông&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Giảm dao động&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Tất cả các lý do trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các lý do trên&lt;/strong&gt;&lt;br /&gt;
                Momentum giúp tăng tốc hội tụ, giảm dao động và có thể vượt qua một số cực tiểu cục bộ nông.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Với hàm $$f(x) = x^2$$, gradient descent từ $$x_0 = 4$$ với $$t = 0.1$$ cho $$x_1 = ?$$&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$3.2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$4.8$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$3.6$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$2.4$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$3.2$$&lt;/strong&gt;&lt;br /&gt;
                $$\nabla f(4) = 2 \cdot 4 = 8$$. $$x_1 = 4 - 0.1 \cdot 8 = 4 - 0.8 = 3.2$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Câu trước&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Câu tiếp&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Kết quả bài tập&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #2196F3, #00BCD4);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #2196F3;
    background-color: #e3f2fd;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #2196F3;
    background-color: #bbdefb;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #e3f2fd;
    border-left: 4px solid #2196F3;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #1565C0;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #2196F3;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #1976D2;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #e3f2fd;
    border-radius: 8px;
    border: 2px solid #2196F3;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #1565C0;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng cho từng câu hỏi
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;a&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;b&apos;, q10: &apos;b&apos;,
    q11: &apos;b&apos;, q12: &apos;b&apos;, q13: &apos;b&apos;, q14: &apos;c&apos;, q15: &apos;a&apos;,
    q16: &apos;b&apos;, q17: &apos;d&apos;, q18: &apos;a&apos;, q19: &apos;c&apos;, q20: &apos;b&apos;
,
    q21: &apos;b&apos;, q22: &apos;a&apos;, q23: &apos;b&apos;, q24: &apos;d&apos;, q25: &apos;a&apos;};

/**
 * Cập nhật thanh tiến trình và hiển thị câu hỏi hiện tại
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Câu hỏi ${currentQuestion}/${totalQuestions}`;
}

/**
 * Hiển thị câu hỏi theo số thứ tự
 */
function showQuestion(questionNum) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Cập nhật trạng thái nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
    
    // Re-render MathJax for the newly displayed question
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise([document.getElementById(`q${questionNum}`)]));
    }
}

/**
 * Chuyển đến câu hỏi tiếp theo
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Quay lại câu hỏi trước
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Lưu đáp án của người dùng
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Cập nhật giao diện để hiển thị đáp án đã chọn
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Nộp bài và hiển thị kết quả
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Tính điểm và tạo báo cáo chi tiết
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Hiển thị giải thích cho tất cả câu hỏi
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Tạo báo cáo chi tiết
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Câu ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Đúng&apos; : &apos;Sai&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Đáp án của bạn: ${userAnswer || &apos;Chưa trả lời&apos;} | Đáp án đúng: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Hiển thị kết quả
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Điểm số: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Xuất sắc! Bạn đã nắm vững gradient descent và các biến thể!&apos; : 
              scorePercentage &gt;= 60 ? &apos;👍 Khá tốt! Hãy ôn lại một số khái niệm về SGD và momentum.&apos; : 
              scorePercentage &gt;= 40 ? &apos;📚 Cần ôn tập thêm về thuật toán gradient descent.&apos; : &apos;💪 Hãy đọc lại lý thuyết về gradient descent từ đầu!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Khởi động lại bài tập
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn kết quả và hiển thị lại điều hướng
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Xóa tất cả lựa chọn
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>06-07 Điều Chuẩn và Hàm Mất Mát</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_07_regularization_and_loss_functions/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_07_regularization_and_loss_functions</id>
   <content type="html">&lt;p&gt;Một mô hình học máy đạt sai số bằng \(0\) trên tập huấn luyện có phải là mô hình tốt nhất không? Hoàn toàn ngược lại: nó có thể đang &lt;strong&gt;học thuộc lòng cả nhiễu ngẫu nhiên&lt;/strong&gt; (quá khớp — overfitting) và sụp đổ thảm hại khi gặp dữ liệu mới! Để dạy mô hình biết “tổng quát hóa”, tối ưu hóa học máy kết hợp hai thành phần như hai đĩa cân: &lt;strong&gt;Hàm mất mát (Loss Function)&lt;/strong&gt; đo độ khớp với dữ liệu, và &lt;strong&gt;Số hạng Điều chuẩn (Regularization)&lt;/strong&gt; phạt độ phức tạp của trọng số.&lt;/p&gt;

&lt;p&gt;Điều kỳ diệu là cả hai lựa chọn đó đều mang ý nghĩa sâu sắc dưới lăng kính tối ưu hóa lồi: thêm Ridge (\(\ell_2\)) lập tức biến bài toán thành &lt;strong&gt;lồi mạnh&lt;/strong&gt; (nghiệm duy nhất, hội tụ tuyến tính); thêm Lasso (\(\ell_1\)) tạo ra các &lt;strong&gt;góc nhọn trên trục tọa độ&lt;/strong&gt; tự động ép trọng số thừa về đúng \(0\) (chọn đặc trưng thưa); còn đổi hàm mất mát từ MSE sang Huber hay Hinge giúp mô hình miễn nhiễm với dữ liệu ngoại lai!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-của-điều-chuẩn-và-hàm-mất-mát&quot;&gt;Kiến thức cần nhớ: Hình học của Điều chuẩn và Hàm mất mát&lt;/h2&gt;

&lt;p&gt;Bốn trụ cột dưới đây giúp bạn chọn đúng hàm mục tiêu cho mọi bài toán học máy:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều chuẩn \(\ell_2\) (Ridge) — Độ trơn &amp;amp; Lồi mạnh:&lt;/strong&gt; Cộng \(\frac{\lambda}{2}\|w\|_2^2\) vào hàm mất mát. Hình học: miền ràng buộc \(\|w\|_2 \le r\) là hình cầu trơn, co đều mọi trọng số về gần 0 nhưng hiếm khi bằng 0 tuyệt đối. Lợi ích tối ưu: đảm bảo \(X^T X + \lambda I \succ 0\) luôn khả nghịch và cải thiện chỉ số điều kiện \(\kappa\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều chuẩn \(\ell_1\) (Lasso) — Tính thưa (Sparsity):&lt;/strong&gt; Cộng \(\lambda \|w\|_1\). Hình học: miền ràng buộc \(\|w\|_1 \le r\) là khối bát diện (hình thoi trong 2D) có các &lt;strong&gt;đỉnh nhọn nằm đúng trên các trục tọa độ&lt;/strong&gt;, nên đường đồng mức elip rất dễ chạm đúng đỉnh và triệt tiêu hoàn toàn các biến vô ích! (Nhưng hàm không khả vi tại 0 — mở đường sang Chương 07: Subgradient!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Elastic Net (Kết hợp \(\ell_1 + \ell_2\)):&lt;/strong&gt; Cộng \(\lambda_1 \|w\|_1 + \frac{\lambda_2}{2}\|w\|_2^2\) để vừa giữ tính thưa của Lasso, vừa có tính lồi mạnh và xử lý tốt nhóm đặc trưng tương quan cao như Ridge.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn Hàm mất mát theo bản chất nhiễu &amp;amp; tác vụ:&lt;/strong&gt; Hồi quy chuẩn dùng &lt;strong&gt;MSE&lt;/strong&gt; (trơn, nhạy ngoại lai), dữ liệu nhiều ngoại lai dùng &lt;strong&gt;MAE&lt;/strong&gt; hoặc &lt;strong&gt;Huber Loss&lt;/strong&gt; (bậc hai quanh 0, tuyến tính ở xa); phân loại dùng &lt;strong&gt;Log-Loss&lt;/strong&gt; (xác suất trơn) hoặc &lt;strong&gt;Hinge Loss&lt;/strong&gt; (biên lớn của SVM).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-trực-tiếp-nghiệm-ols-ridge-và-lasso-trên-bài-toán-1-chiều&quot;&gt;Giải thích: So sánh trực tiếp nghiệm OLS, Ridge và Lasso trên bài toán 1 chiều&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa 1 biến với dữ liệu chuẩn hóa \(y = 3\) (tức nghiệm không điều chuẩn là \(w_{\text{OLS}} = 3\)) và hệ số điều chuẩn \(\lambda = 1\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;OLS (Không điều chuẩn):&lt;/strong&gt;
\(\min_w \; \frac{1}{2}(w - 3)^2 \implies w_{\text{OLS}}^\star = 3.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ridge (\(\ell_2\)):&lt;/strong&gt;
\(\min_w \; \frac{1}{2}(w - 3)^2 + \frac{1}{2}(1)w^2 = w^2 - 3w + 4.5.\)
Đạo hàm \(2w - 3 = 0 \implies w_{\text{Ridge}}^\star = \frac{3}{1 + 1} = 1.5\).
(Tỷ lệ co đều: \(w_{\text{Ridge}} = \frac{y}{1 + \lambda}\) — chỉ bằng \(0\) khi \(y = 0\)!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lasso (\(\ell_1\)):&lt;/strong&gt;
\(\min_w \; \frac{1}{2}(w - 3)^2 + 1 \cdot |w|.\)
Với \(w &amp;gt; 0\), đạo hàm \(w - 3 + 1 = 0 \implies w_{\text{Lasso}}^\star = 3 - 1 = 2\) (dịch về 0 đúng \(\lambda = 1\) đơn vị).
Bây giờ thử với một đặc trưng yếu có \(y = 0.7 &amp;lt; \lambda = 1\):
    &lt;ul&gt;
      &lt;li&gt;Ridge vẫn cho \(w_{\text{Ridge}}^\star = \frac{0.7}{2} = 0.35 \neq 0\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Lasso ép &lt;strong&gt;chính xác về \(w_{\text{Lasso}}^\star = 0\)&lt;/strong&gt; (ngưỡng mềm: $$\operatorname{sign}(y)\max(&lt;/td&gt;
              &lt;td&gt;y&lt;/td&gt;
              &lt;td&gt;- \lambda, 0) = 0$$)! Đó là lý do Lasso tự động loại bỏ đặc trưng nhiễu!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script src=&quot;../../../public/js/script.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;

&lt;h2 id=&quot;giới-thiệu-vấn-đề-quá-khớp-overfitting-trong-học-máy&quot;&gt;Giới thiệu: Vấn đề Quá khớp (Overfitting) trong Học máy&lt;/h2&gt;

&lt;p&gt;Trong học máy, một thách thức phổ biến là hiện tượng &lt;strong&gt;quá khớp (overfitting)&lt;/strong&gt; — khi mô hình khớp quá sát vào nhiễu của dữ liệu huấn luyện, dẫn đến khả năng tổng quát hóa kém trên dữ liệu mới. &lt;strong&gt;Điều chuẩn (regularization)&lt;/strong&gt; là kỹ thuật nền tảng giúp kiểm soát độ phức tạp của mô hình và giảm thiểu quá khớp.&lt;/p&gt;

&lt;h3 id=&quot;vì-sao-cần-điều-chuẩn&quot;&gt;Vì sao cần Điều chuẩn?&lt;/h3&gt;

&lt;p&gt;Xét bài toán hồi quy tuyến tính cơ bản:
\(\min_{\mathbf{w}} rac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vấn đề&lt;/strong&gt;: Khi số lượng đặc trưng lớn hoặc số mẫu ít, mô hình có thể đạt sai số huấn luyện gần bằng 0 nhưng lại cho sai số lớn trên dữ liệu kiểm tra.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giải pháp&lt;/strong&gt;: Bổ sung một &lt;strong&gt;số hạng điều chuẩn (regularization term)&lt;/strong&gt; để phạt các trọng số có độ lớn quá cao:
\(\min_{\mathbf{w}} rac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2 + \lambda R(\mathbf{w})\)&lt;/p&gt;

&lt;p&gt;trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\lambda &amp;gt; 0\) là &lt;strong&gt;tham số điều chuẩn&lt;/strong&gt; (kiểm soát mức độ phạt).&lt;/li&gt;
  &lt;li&gt;\(R(\mathbf{w})\) là &lt;strong&gt;hàm điều chuẩn&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;hồi-quy-ridge-điều-chuẩn-l2&quot;&gt;Hồi quy Ridge (Điều chuẩn L2)&lt;/h2&gt;

&lt;h3 id=&quot;định-nghĩa-toán-học&quot;&gt;Định nghĩa Toán học&lt;/h3&gt;

&lt;p&gt;Hồi quy Ridge sử dụng bình phương chuẩn L2 làm số hạng điều chuẩn:&lt;/p&gt;

\[\min_{\mathbf{w}} rac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2 + rac{\lambda}{2} \|\mathbf{w}\|_2^2\]

&lt;p&gt;&lt;strong&gt;Các thành phần của hàm mục tiêu:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mất mát&lt;/strong&gt;: \(rac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2\) đo độ lệch giữa giá trị dự đoán và giá trị thực.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số hạng điều chuẩn&lt;/strong&gt;: \(rac{\lambda}{2} \|\mathbf{w}\|_2^2 = rac{\lambda}{2} \sum_{j=1}^p w_j^2\) phạt các trọng số có độ lớn cao.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cường độ điều chuẩn&lt;/strong&gt;: \(\lambda\) điều chỉnh sự đánh đổi giữa độ khớp dữ liệu và độ nhỏ của trọng số.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;nghiệm-giải-tích&quot;&gt;Nghiệm Giải tích&lt;/h3&gt;

&lt;p&gt;Hồi quy Ridge có nghiệm dạng đóng:
\(\mathbf{w}^* = (\mathbf{X}^T\mathbf{X} + n\lambda \mathbf{I})^{-1} \mathbf{X}^T \mathbf{y}\)
(Nếu bỏ hệ số \(rac{1}{n}\) ở hàm mất mát, nghiệm có dạng gọn là \(\mathbf{w}^* = (\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})^{-1} \mathbf{X}^T \mathbf{y}\).)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm của nghiệm này:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Ma trận \((\mathbf{X}^T\mathbf{X} + n\lambda \mathbf{I})\) luôn khả nghịch với mọi \(\lambda &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;Khắc phục hiệu quả hiện tượng đa cộng tuyến (multicollinearity).&lt;/li&gt;
  &lt;li&gt;Tính toán trực tiếp được bằng các thuật toán đại số tuyến tính chuẩn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;minh-họa-hiệu-ứng-điều-chuẩn-ridge&quot;&gt;Minh họa Hiệu ứng Điều chuẩn Ridge&lt;/h3&gt;

&lt;div id=&quot;ridge-effect-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9;&quot;&gt;
        &lt;h4&gt;Điều khiển Ridge Regularization&lt;/h4&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;&quot;&gt;
            &lt;div&gt;
                &lt;label for=&quot;ridge-lambda&quot;&gt;Lambda (λ): &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;ridge-lambda&quot; min=&quot;0&quot; max=&quot;10&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;
                &lt;span id=&quot;ridge-lambda-value&quot;&gt;1.0&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;ridge-noise&quot;&gt;Noise Level: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;ridge-noise&quot; min=&quot;0&quot; max=&quot;0.5&quot; step=&quot;0.05&quot; value=&quot;0.1&quot; /&gt;
                &lt;span id=&quot;ridge-noise-value&quot;&gt;0.1&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;ridge-features&quot;&gt;Number of Features: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;ridge-features&quot; min=&quot;5&quot; max=&quot;20&quot; step=&quot;1&quot; value=&quot;10&quot; /&gt;
                &lt;span id=&quot;ridge-features-value&quot;&gt;10&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
            &lt;button id=&quot;ridge-regenerate&quot; style=&quot;background-color: #4CAF50; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Tạo dữ liệu mới&lt;/button&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Coefficients Path&lt;/h4&gt;
            &lt;svg id=&quot;ridge-coefficients&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;ridge-coeff-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;L2 Norm của coefficients: 0&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Training vs Validation Error&lt;/h4&gt;
            &lt;svg id=&quot;ridge-error&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;ridge-error-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;Optimal λ: 0&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-thực-tế-cực-tiểu-hóa-hàm-bậc-hai&quot;&gt;Ví dụ Thực tế: Cực tiểu hóa Hàm Bậc hai&lt;/h2&gt;

&lt;p&gt;Để thấy rõ tác động toán học của điều chuẩn, ta xét bài toán cực tiểu hóa hàm bậc hai — cấu trúc nền tảng của nhiều mô hình học máy và tài chính định lượng.&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-tối-ưu-hóa-danh-mục-đầu-tư-có-điều-chuẩn&quot;&gt;Bài toán: Tối ưu hóa Danh mục Đầu tư có Điều chuẩn&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu hóa danh mục đầu tư:&lt;/p&gt;

\[\min_{\mathbf{w}} rac{1}{2} \mathbf{w}^T \mathbf{Q} \mathbf{w} - \mathbf{\mu}^T \mathbf{w} + rac{\lambda}{2} \|\mathbf{w}\|_2^2\]

&lt;p&gt;trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{w} \in \mathbb{R}^n\): vector trọng số đầu tư cho \(n\) tài sản.&lt;/li&gt;
  &lt;li&gt;\(\mathbf{Q} \in \mathbb{R}^{n 	imes n}\): ma trận hiệp phương sai (đo rủi ro).&lt;/li&gt;
  &lt;li&gt;\(\mathbf{\mu} \in \mathbb{R}^n\): vector lợi suất kỳ vọng.&lt;/li&gt;
  &lt;li&gt;\(\lambda &amp;gt; 0\): tham số điều chuẩn (phản ánh mức độ ngại rủi ro hoặc ổn định hóa trọng số).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phân-tích-toán-học&quot;&gt;Phân tích Toán học&lt;/h3&gt;

&lt;h4 id=&quot;1-gradient-của-hàm-mục-tiêu&quot;&gt;1. Gradient của Hàm Mục tiêu&lt;/h4&gt;

\[abla f(\mathbf{w}) = \mathbf{Q}\mathbf{w} - \mathbf{\mu} + \lambda \mathbf{w} = (\mathbf{Q} + \lambda \mathbf{I})\mathbf{w} - \mathbf{\mu}\]

&lt;h4 id=&quot;2-ma-trận-hessian&quot;&gt;2. Ma trận Hessian&lt;/h4&gt;

\[abla^2 f(\mathbf{w}) = \mathbf{Q} + \lambda \mathbf{I}\]

&lt;p&gt;&lt;strong&gt;Nhận xét quan trọng&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Khi \(\lambda &amp;gt; 0\) và \(\mathbf{Q}\) nửa xác định dương, ma trận Hessian \(\mathbf{Q} + \lambda \mathbf{I}\) luôn xác định dương.&lt;/li&gt;
  &lt;li&gt;Hàm mục tiêu trở nên lồi mạnh.&lt;/li&gt;
  &lt;li&gt;Nghiệm tối ưu tồn tại và là duy nhất.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-nghiệm-tối-ưu&quot;&gt;3. Nghiệm Tối ưu&lt;/h4&gt;

&lt;p&gt;Đặt gradient bằng 0:
\((\mathbf{Q} + \lambda \mathbf{I})\mathbf{w}^* = \mathbf{\mu}\)&lt;/p&gt;

\[\mathbf{w}^* = (\mathbf{Q} + \lambda \mathbf{I})^{-1} \mathbf{\mu}\]

&lt;h3 id=&quot;minh-họa-tương-tác-cho-hàm-bậc-hai&quot;&gt;Minh họa Tương tác cho Hàm Bậc hai&lt;/h3&gt;

&lt;div id=&quot;quadratic-function-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9;&quot;&gt;
        &lt;h4&gt;Quadratic Function Parameters&lt;/h4&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;&quot;&gt;
            &lt;div&gt;
                &lt;label for=&quot;quad-lambda&quot;&gt;Regularization λ: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;quad-lambda&quot; min=&quot;0&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;
                &lt;span id=&quot;quad-lambda-value&quot;&gt;1.0&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;quad-condition&quot;&gt;Condition Number: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;quad-condition&quot; min=&quot;1&quot; max=&quot;50&quot; step=&quot;1&quot; value=&quot;10&quot; /&gt;
                &lt;span id=&quot;quad-condition-value&quot;&gt;10&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;quad-dimension&quot;&gt;Dimension: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;quad-dimension&quot; min=&quot;2&quot; max=&quot;5&quot; step=&quot;1&quot; value=&quot;2&quot; /&gt;
                &lt;span id=&quot;quad-dimension-value&quot;&gt;2&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
            &lt;button id=&quot;quad-optimize&quot; style=&quot;background-color: #4CAF50; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Run Optimization&lt;/button&gt;
            &lt;button id=&quot;quad-reset&quot; style=&quot;background-color: #f44336; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Reset&lt;/button&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;2D Contour Plot&lt;/h4&gt;
            &lt;svg id=&quot;quadratic-contour&quot; width=&quot;400&quot; height=&quot;400&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;quad-contour-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;Click to set starting point&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Convergence Analysis&lt;/h4&gt;
            &lt;svg id=&quot;quadratic-convergence&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;quad-convergence-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;Convergence rate: -&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin-top: 20px;&quot;&gt;
        &lt;h4&gt;Eigenvalue Analysis&lt;/h4&gt;
        &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
            &lt;div style=&quot;text-align: center;&quot;&gt;
                &lt;h5&gt;Original Matrix Q&lt;/h5&gt;
                &lt;svg id=&quot;eigenvalue-original&quot; width=&quot;300&quot; height=&quot;200&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;/div&gt;
            &lt;div style=&quot;text-align: center;&quot;&gt;
                &lt;h5&gt;Regularized Matrix Q + λI&lt;/h5&gt;
                &lt;svg id=&quot;eigenvalue-regularized&quot; width=&quot;300&quot; height=&quot;200&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; padding: 10px; background-color: #e3f2fd; border-radius: 4px;&quot;&gt;
            &lt;p id=&quot;eigenvalue-analysis&quot; style=&quot;margin: 0; font-size: 14px;&quot;&gt;
                &lt;strong&gt;Analysis:&lt;/strong&gt; Regularization improves condition number from ∞ to finite value
            &lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;gradient-descent-trên-hàm-bậc-hai&quot;&gt;Gradient Descent trên Hàm Bậc hai&lt;/h3&gt;

&lt;p&gt;Với hàm mục tiêu bậc hai có điều chuẩn, bước lặp gradient descent có dạng:&lt;/p&gt;

\[\mathbf{w}^{(k+1)} = \mathbf{w}^{(k)} - lpha [(\mathbf{Q} + \lambda \mathbf{I})\mathbf{w}^{(k)} - \mathbf{\mu}]\]

&lt;h4 id=&quot;phân-tích-tốc-độ-hội-tụ&quot;&gt;Phân tích Tốc độ Hội tụ&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân rã trị riêng&lt;/strong&gt;: \(\mathbf{Q} + \lambda \mathbf{I} = \mathbf{V} \mathbf{\Lambda} \mathbf{V}^T\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ số co&lt;/strong&gt;: \(ho = \max_i \left|1 - lpha \lambda_i
ight|\), trong đó \(\lambda_i\) là các trị riêng của \(\mathbf{Q} + \lambda \mathbf{I}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bước tối ưu&lt;/strong&gt;: \(lpha^* = rac{2}{\lambda_{\min} + \lambda_{\max}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ số hội tụ tối ưu&lt;/strong&gt;: \(ho^* = rac{\kappa - 1}{\kappa + 1}\), trong đó \(\kappa = rac{\lambda_{\max}}{\lambda_{\min}}\) là chỉ số điều kiện.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ảnh-hưởng-của-điều-chuẩn-lên-tốc-độ-hội-tụ&quot;&gt;Ảnh hưởng của Điều chuẩn lên Tốc độ Hội tụ&lt;/h3&gt;

&lt;div id=&quot;regularization-convergence-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #fff3e0;&quot;&gt;
        &lt;h4&gt;Convergence Rate Analysis&lt;/h4&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;&quot;&gt;
            &lt;div&gt;
                &lt;label for=&quot;conv-lambda&quot;&gt;Lambda: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;conv-lambda&quot; min=&quot;0.01&quot; max=&quot;3&quot; step=&quot;0.01&quot; value=&quot;0.1&quot; /&gt;
                &lt;span id=&quot;conv-lambda-value&quot;&gt;0.1&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;conv-step-size&quot;&gt;Step Size: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;conv-step-size&quot; min=&quot;0.01&quot; max=&quot;0.5&quot; step=&quot;0.01&quot; value=&quot;0.1&quot; /&gt;
                &lt;span id=&quot;conv-step-size-value&quot;&gt;0.1&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;button id=&quot;conv-optimal-step&quot; style=&quot;background-color: #FF9800; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Optimal Step Size&lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Convergence Comparison&lt;/h4&gt;
            &lt;svg id=&quot;convergence-comparison&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;div style=&quot;display: flex; gap: 15px; justify-content: center; font-size: 12px;&quot;&gt;
                    &lt;span style=&quot;color: #1f77b4;&quot;&gt;■ No Regularization&lt;/span&gt;
                    &lt;span style=&quot;color: #ff7f0e;&quot;&gt;■ With Regularization&lt;/span&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Condition Number vs λ&lt;/h4&gt;
            &lt;svg id=&quot;condition-number-plot&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;condition-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;Current κ: ∞&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;tình-huống-minh-họa-bài-toán-điều-kiện-xấu&quot;&gt;Tình huống Minh họa: Bài toán Điều kiện Xấu&lt;/h3&gt;

&lt;h4 id=&quot;vấn-đề-đa-cộng-tuyến-trong-hồi-quy-tuyến-tính&quot;&gt;Vấn đề: Đa cộng tuyến trong Hồi quy Tuyến tính&lt;/h4&gt;

&lt;p&gt;Xét ma trận đặc trưng \(\mathbf{X}\) có các cột gần như phụ thuộc tuyến tính:&lt;/p&gt;

\[\mathbf{X} = egin{bmatrix}
1 &amp;amp; 1 &amp;amp; 1.001 \
1 &amp;amp; 2 &amp;amp; 2.001 \
1 &amp;amp; 3 &amp;amp; 3.001 \
dots &amp;amp; dots &amp;amp; dots
\end{bmatrix}\]

&lt;p&gt;&lt;strong&gt;Hệ phương trình chuẩn (normal equations)&lt;/strong&gt;: \(\mathbf{X}^T\mathbf{X} \mathbf{w} = \mathbf{X}^T \mathbf{y}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vấn đề&lt;/strong&gt;: Ma trận \(\mathbf{X}^T\mathbf{X}\) có chỉ số điều kiện rất lớn, gây mất ổn định số học khi nghịch đảo.&lt;/p&gt;

&lt;h4 id=&quot;giải-pháp-điều-chuẩn-ridge&quot;&gt;Giải pháp: Điều chuẩn Ridge&lt;/h4&gt;

\[(\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I}) \mathbf{w} = \mathbf{X}^T \mathbf{y}\]

&lt;p&gt;&lt;strong&gt;Tác dụng&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Giảm mạnh chỉ số điều kiện (chẳng hạn từ \(10^{12}\) xuống \(10^2\)).&lt;/li&gt;
  &lt;li&gt;Cải thiện rõ rệt độ ổn định số học.&lt;/li&gt;
  &lt;li&gt;Đánh đổi hợp lý: chấp nhận tăng nhẹ độ chệch (bias) để giảm đáng kể phương sai (variance).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phân-tích-thống-kê&quot;&gt;Phân tích Thống kê&lt;/h3&gt;

&lt;h4 id=&quot;1-phân-tích-độ-chệch--phương-sai-biasvariance&quot;&gt;1. Phân tích Độ chệch – Phương sai (Bias–Variance)&lt;/h4&gt;

&lt;p&gt;Đối với hồi quy Ridge:&lt;/p&gt;

\[ext{MSE} = 	ext{Bias}^2 + 	ext{Variance} + 	ext{Noise}\]

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Độ chệch (Bias)&lt;/strong&gt;: \(\mathbb{E}[\hat{\mathbf{w}}] - \mathbf{w}^* = -\lambda (\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})^{-1} \mathbf{w}^*\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương sai (Variance)&lt;/strong&gt;: \(ext{Var}[\hat{\mathbf{w}}] = \sigma^2 (\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})^{-1} \mathbf{X}^T\mathbf{X} (\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})^{-1}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-bậc-tự-do-hiệu-dụng-effective-degrees-of-freedom&quot;&gt;2. Bậc Tự do Hiệu dụng (Effective Degrees of Freedom)&lt;/h4&gt;

\[ext{df}(\lambda) = 	ext{tr}[\mathbf{X}(\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})^{-1}\mathbf{X}^T] = \sum_{i=1}^p rac{\sigma_i^2}{\sigma_i^2 + \lambda}\]

&lt;p&gt;trong đó \(\sigma_i\) là các giá trị kỳ dị của \(\mathbf{X}\) (và \(\sigma_i^2\) là các trị riêng của \(\mathbf{X}^T\mathbf{X}\)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa&lt;/strong&gt;: Tăng \(\lambda\) làm giảm bậc tự do hiệu dụng, qua đó thu hẹp độ phức tạp của mô hình.&lt;/p&gt;

&lt;h3 id=&quot;cân-nhắc-về-tính-toán&quot;&gt;Cân nhắc về Tính toán&lt;/h3&gt;

&lt;h4 id=&quot;1-giải-trực-tiếp-so-với-phương-pháp-lặp&quot;&gt;1. Giải Trực tiếp so với Phương pháp Lặp&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Giải trực tiếp (phân rã Cholesky)&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Độ phức tạp: \(O(p^3)\).&lt;/li&gt;
  &lt;li&gt;Phù hợp khi số đặc trưng \(p &amp;lt; 10^4\).&lt;/li&gt;
  &lt;li&gt;Ổn định số học tốt nhờ số hạng điều chuẩn.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp lặp (Gradient descent)&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Độ phức tạp mỗi bước lặp: \(O(np)\).&lt;/li&gt;
  &lt;li&gt;Phù hợp khi số đặc trưng \(p\) lớn.&lt;/li&gt;
  &lt;li&gt;Tốc độ hội tụ phụ thuộc vào chỉ số điều kiện.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-tiền-điều-kiện-hóa-preconditioning&quot;&gt;2. Tiền điều kiện hóa (Preconditioning)&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tiền điều kiện Jacobi&lt;/strong&gt;: \(\mathbf{P} = 	ext{diag}(\mathbf{Q} + \lambda \mathbf{I})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ sau tiền điều kiện&lt;/strong&gt;: \(\mathbf{P}^{-1}(\mathbf{Q} + \lambda \mathbf{I})\mathbf{w} = \mathbf{P}^{-1}\mathbf{\mu}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lợi ích&lt;/strong&gt;: Cải thiện chỉ số điều kiện của hệ phương trình, giúp phương pháp lặp hội tụ nhanh hơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;hồi-quy-lasso-điều-chuẩn-l1&quot;&gt;Hồi quy Lasso (Điều chuẩn L1)&lt;/h2&gt;

&lt;h3 id=&quot;định-nghĩa-toán-học-1&quot;&gt;Định nghĩa Toán học&lt;/h3&gt;

&lt;p&gt;Lasso (Least Absolute Shrinkage and Selection Operator) sử dụng chuẩn L1 làm số hạng điều chuẩn:&lt;/p&gt;

\[\min_{\mathbf{w}} rac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2 + \lambda \|\mathbf{w}\|_1\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;trong đó $$|\mathbf{w}|&lt;em&gt;1 = \sum&lt;/em&gt;{j=1}^p&lt;/td&gt;
      &lt;td&gt;w_j&lt;/td&gt;
      &lt;td&gt;$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;đặc-điểm-chính-của-lasso&quot;&gt;Đặc điểm Chính của Lasso&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Nghiệm thưa (Sparse Solutions):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Lasso có thể đưa nhiều hệ số về &lt;strong&gt;chính xác bằng 0&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Tự động thực hiện &lt;strong&gt;chọn lọc đặc trưng (feature selection)&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Tạo ra mô hình gọn nhẹ và dễ diễn giải hơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Không có nghiệm dạng đóng tổng quát:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Cần giải bằng các thuật toán tối ưu lặp (như hạ tọa độ — coordinate descent, hoặc gradient gần kề — proximal gradient).&lt;/li&gt;
  &lt;li&gt;Chi phí tối ưu thường phức tạp hơn hồi quy Ridge.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;so-sánh-ridge-và-lasso&quot;&gt;So sánh Ridge và Lasso&lt;/h3&gt;

&lt;div id=&quot;ridge-lasso-comparison&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f0f8ff;&quot;&gt;
        &lt;h4&gt;So sánh Ridge và Lasso Regularization&lt;/h4&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 20px;&quot;&gt;
            &lt;div&gt;
                &lt;label for=&quot;comparison-lambda&quot;&gt;Lambda (λ): &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;comparison-lambda&quot; min=&quot;0&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;
                &lt;span id=&quot;comparison-lambda-value&quot;&gt;1.0&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;comparison-correlation&quot;&gt;Feature Correlation: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;comparison-correlation&quot; min=&quot;0&quot; max=&quot;0.9&quot; step=&quot;0.1&quot; value=&quot;0.5&quot; /&gt;
                &lt;span id=&quot;comparison-correlation-value&quot;&gt;0.5&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
            &lt;button id=&quot;comparison-update&quot; style=&quot;background-color: #2196F3; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Cập nhật So sánh&lt;/button&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Ridge Coefficients&lt;/h4&gt;
            &lt;svg id=&quot;ridge-comparison&quot; width=&quot;300&quot; height=&quot;250&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 5px; padding: 5px; background-color: #e8f5e8; border-radius: 4px;&quot;&gt;
                &lt;p style=&quot;margin: 0; font-size: 12px;&quot;&gt;Shrinkage: Đều, không về 0&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Lasso Coefficients&lt;/h4&gt;
            &lt;svg id=&quot;lasso-comparison&quot; width=&quot;300&quot; height=&quot;250&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 5px; padding: 5px; background-color: #fff3e0; border-radius: 4px;&quot;&gt;
                &lt;p style=&quot;margin: 0; font-size: 12px;&quot;&gt;Sparsity: Một số về chính xác 0&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Regularization Geometry&lt;/h4&gt;
            &lt;svg id=&quot;regularization-geometry&quot; width=&quot;300&quot; height=&quot;250&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 5px; padding: 5px; background-color: #f3e5f5; border-radius: 4px;&quot;&gt;
                &lt;p style=&quot;margin: 0; font-size: 12px;&quot;&gt;L1: Diamond, L2: Circle&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;diễn-giải-hình-học-của-điều-chuẩn&quot;&gt;Diễn giải Hình học của Điều chuẩn&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vì sao Lasso tạo ra nghiệm thưa:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Miền ràng buộc L1&lt;/strong&gt;: \(\|\mathbf{w}\|_1 \leq t\) có dạng &lt;strong&gt;hình thoi&lt;/strong&gt; trong không gian hai chiều (có các đỉnh nhọn nằm trên trục tọa độ).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Miền ràng buộc L2&lt;/strong&gt;: \(\|\mathbf{w}\|_2 \leq t\) có dạng &lt;strong&gt;hình tròn&lt;/strong&gt; trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm tiếp xúc với đường đồng mức hàm mất mát&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Với L1, đường đồng mức elip rất dễ tiếp xúc tại các đỉnh nhọn trên trục tọa độ, khiến một số thành phần của \(\mathbf{w}\) bằng 0.&lt;/li&gt;
      &lt;li&gt;Với L2, biên hình tròn trơn nên điểm tiếp xúc thường nằm ngoài các trục tọa độ (các hệ số đều co nhỏ nhưng hiếm khi bằng 0 tuyệt đối).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;elastic-net-kết-hợp-ridge-và-lasso&quot;&gt;Elastic Net: Kết hợp Ridge và Lasso&lt;/h2&gt;

&lt;p&gt;Elastic Net kết hợp đồng thời hai số hạng phạt L1 và L2:&lt;/p&gt;

\[\min_{\mathbf{w}} rac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2 + \lambda \left[ lpha \|\mathbf{w}\|_1 + rac{1-lpha}{2} \|\mathbf{w}\|_2^2 
ight]\]

&lt;p&gt;&lt;strong&gt;Vai trò tham số trộn \(lpha \in [0, 1]\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(lpha = 1\): Trở về hồi quy Lasso thuần túy.&lt;/li&gt;
  &lt;li&gt;\(lpha = 0\): Trở về hồi quy Ridge thuần túy.&lt;/li&gt;
  &lt;li&gt;\(0 &amp;lt; lpha &amp;lt; 1\): Kết hợp cả hai cơ chế.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Kết hợp tính thưa của Lasso với độ ổn định của Ridge.&lt;/li&gt;
  &lt;li&gt;Xử lý tốt các nhóm biến có tương quan cao.&lt;/li&gt;
  &lt;li&gt;Hoạt động ổn định cả khi số đặc trưng vượt quá số mẫu (\(p &amp;gt; n\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;các-hàm-mất-mát-trong-học-máy&quot;&gt;Các Hàm Mất mát trong Học máy&lt;/h2&gt;

&lt;h3 id=&quot;1-hàm-mất-mát-cho-hồi-quy&quot;&gt;1. Hàm Mất mát cho Hồi quy&lt;/h3&gt;

&lt;h4 id=&quot;sai-số-bình-phương-trung-bình-mse&quot;&gt;Sai số Bình phương Trung bình (MSE)&lt;/h4&gt;
&lt;p&gt;\(L_{MSE}(\mathbf{w}) = rac{1}{n} \sum_{i=1}^n (y_i - \mathbf{w}^T \mathbf{x}_i)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Trơn và khả vi tại mọi điểm.&lt;/li&gt;
  &lt;li&gt;Nhạy cảm với các điểm ngoại lai (outliers) do bình phương sai số.&lt;/li&gt;
  &lt;li&gt;Tạo thành bài toán tối ưu lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;sai-số-tuyệt-đối-trung-bình-mae&quot;&gt;Sai số Tuyệt đối Trung bình (MAE)&lt;/h4&gt;
&lt;p&gt;\(L_{MAE}(\mathbf{w}) = rac{1}{n} \sum_{i=1}^n |y_i - \mathbf{w}^T \mathbf{x}_i|\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bền vững hơn trước các điểm ngoại lai.&lt;/li&gt;
  &lt;li&gt;Không khả vi tại điểm sai số bằng 0.&lt;/li&gt;
  &lt;li&gt;Lồi nhưng cần phương pháp dưới gradient (subgradient) hoặc quy hoạch tuyến tính.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;hàm-mất-mát-huber-huber-loss&quot;&gt;Hàm Mất mát Huber (Huber Loss)&lt;/h4&gt;
&lt;p&gt;\(L_{Huber}(\mathbf{w}) = rac{1}{n} \sum_{i=1}^n egin{cases}
rac{1}{2}(y_i - \mathbf{w}^T \mathbf{x}_i)^2 &amp;amp; 	ext{nếu } |y_i - \mathbf{w}^T \mathbf{x}_i| \leq \delta \
\delta |y_i - \mathbf{w}^T \mathbf{x}_i| - rac{1}{2}\delta^2 &amp;amp; 	ext{ngược lại}
\end{cases}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Kết hợp ưu điểm của MSE (với sai số nhỏ) và MAE (với sai số lớn).&lt;/li&gt;
  &lt;li&gt;Vừa trơn (khả vi liên tục) vừa bền vững trước ngoại lai.&lt;/li&gt;
  &lt;li&gt;Tham số \(\delta\) kiểm soát ngưỡng chuyển tiếp giữa phần bậc hai và phần tuyến tính.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-hàm-mất-mát-cho-phân-lớp&quot;&gt;2. Hàm Mất mát cho Phân lớp&lt;/h3&gt;

&lt;h4 id=&quot;hàm-mất-mát-logistic-cross-entropy&quot;&gt;Hàm Mất mát Logistic (Cross-Entropy)&lt;/h4&gt;
&lt;p&gt;\(L_{logistic}(\mathbf{w}) = rac{1}{n} \sum_{i=1}^n \log(1 + \exp(-y_i \mathbf{w}^T \mathbf{x}_i))\)&lt;/p&gt;

&lt;h4 id=&quot;hàm-mất-mát-hinge-svm&quot;&gt;Hàm Mất mát Hinge (SVM)&lt;/h4&gt;
&lt;p&gt;\(L_{hinge}(\mathbf{w}) = rac{1}{n} \sum_{i=1}^n \max(0, 1 - y_i \mathbf{w}^T \mathbf{x}_i)\)&lt;/p&gt;

&lt;h3 id=&quot;minh-họa-tương-tác-so-sánh-các-hàm-mất-mát&quot;&gt;Minh họa Tương tác: So sánh Các Hàm Mất mát&lt;/h3&gt;

&lt;div id=&quot;loss-functions-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9;&quot;&gt;
        &lt;h4&gt;So sánh các Loss Functions&lt;/h4&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;&quot;&gt;
            &lt;div&gt;
                &lt;label for=&quot;loss-delta&quot;&gt;Huber Delta (δ): &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;loss-delta&quot; min=&quot;0.5&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;
                &lt;span id=&quot;loss-delta-value&quot;&gt;1.0&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;loss-range&quot;&gt;Error Range: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;loss-range&quot; min=&quot;2&quot; max=&quot;8&quot; step=&quot;0.5&quot; value=&quot;4&quot; /&gt;
                &lt;span id=&quot;loss-range-value&quot;&gt;4.0&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label&gt;
                    &lt;input type=&quot;checkbox&quot; id=&quot;show-derivatives&quot; /&gt; Show Derivatives
                &lt;/label&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Regression Loss Functions&lt;/h4&gt;
            &lt;svg id=&quot;regression-losses&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;div style=&quot;display: flex; gap: 15px; justify-content: center; font-size: 12px;&quot;&gt;
                    &lt;span style=&quot;color: #1f77b4;&quot;&gt;■ MSE&lt;/span&gt;
                    &lt;span style=&quot;color: #ff7f0e;&quot;&gt;■ MAE&lt;/span&gt;
                    &lt;span style=&quot;color: #2ca02c;&quot;&gt;■ Huber&lt;/span&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Classification Loss Functions&lt;/h4&gt;
            &lt;svg id=&quot;classification-losses&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;div style=&quot;display: flex; gap: 15px; justify-content: center; font-size: 12px;&quot;&gt;
                    &lt;span style=&quot;color: #d62728;&quot;&gt;■ Logistic&lt;/span&gt;
                    &lt;span style=&quot;color: #9467bd;&quot;&gt;■ Hinge&lt;/span&gt;
                    &lt;span style=&quot;color: #8c564b;&quot;&gt;■ 0-1 Loss&lt;/span&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;đường-điều-chuẩn-regularization-path-và-chọn-mô-hình&quot;&gt;Đường Điều chuẩn (Regularization Path) và Chọn Mô hình&lt;/h2&gt;

&lt;h3 id=&quot;kiểm-định-chéo-cross-validation-để-chọn-lambda&quot;&gt;Kiểm định Chéo (Cross-Validation) để Chọn \(\lambda\)&lt;/h3&gt;

&lt;p&gt;Giá trị \(\lambda\) tối ưu thường được xác định bằng kiểm định chéo:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chia tập dữ liệu&lt;/strong&gt;: Tách thành các tập huấn luyện (training), thẩm định (validation) và kiểm tra (test).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm lưới (grid search)&lt;/strong&gt;: Khảo sát dãy giá trị \(\lambda\) theo thang logarit.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh giá&lt;/strong&gt;: Tính sai số trên tập thẩm định cho từng giá trị \(\lambda\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn&lt;/strong&gt;: Chọn \(\lambda\) cho sai số thẩm định thấp nhất.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;minh-họa-đường-điều-chuẩn&quot;&gt;Minh họa Đường Điều chuẩn&lt;/h3&gt;

&lt;div id=&quot;regularization-path-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f0f8ff;&quot;&gt;
        &lt;h4&gt;Regularization Path Analysis&lt;/h4&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;&quot;&gt;
            &lt;div&gt;
                &lt;label for=&quot;path-method&quot;&gt;Method: &lt;/label&gt;
                &lt;select id=&quot;path-method&quot;&gt;
                    &lt;option value=&quot;ridge&quot;&gt;Ridge&lt;/option&gt;
                    &lt;option value=&quot;lasso&quot;&gt;Lasso&lt;/option&gt;
                    &lt;option value=&quot;elastic&quot;&gt;Elastic Net&lt;/option&gt;
                &lt;/select&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;path-alpha&quot;&gt;Elastic Net α: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;path-alpha&quot; min=&quot;0&quot; max=&quot;1&quot; step=&quot;0.1&quot; value=&quot;0.5&quot; /&gt;
                &lt;span id=&quot;path-alpha-value&quot;&gt;0.5&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;button id=&quot;path-animate&quot; style=&quot;background-color: #FF9800; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Animate Path&lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Coefficient Path&lt;/h4&gt;
            &lt;svg id=&quot;coefficient-path&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;path-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;Current λ: 0, Active features: 0&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Cross-Validation Curve&lt;/h4&gt;
            &lt;svg id=&quot;cv-curve&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;cv-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;Optimal λ: 0, CV Score: 0&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;hướng-dẫn-thực-hành&quot;&gt;Hướng dẫn Thực hành&lt;/h2&gt;

&lt;h3 id=&quot;1-khi-nào-chọn-ridge-hay-lasso&quot;&gt;1. Khi nào chọn Ridge hay Lasso?&lt;/h3&gt;

&lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;border: 1px solid #4CAF50; padding: 15px; border-radius: 5px; background-color: #f1f8e9;&quot;&gt;
        &lt;h4 style=&quot;color: #4CAF50;&quot;&gt;Nên dùng Ridge khi:&lt;/h4&gt;
        &lt;ul&gt;
            &lt;li&gt;Phần lớn đặc trưng đều đóng góp thông tin&lt;/li&gt;
            &lt;li&gt;Có hiện tượng đa cộng tuyến cao&lt;/li&gt;
            &lt;li&gt;Ưu tiên tính ổn định của ước lượng&lt;/li&gt;
            &lt;li&gt;Tập dữ liệu nhỏ nhưng nhiều đặc trưng&lt;/li&gt;
            &lt;li&gt;Không cần loại bỏ đặc trưng tự động&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
    &lt;div style=&quot;border: 1px solid #FF9800; padding: 15px; border-radius: 5px; background-color: #fff8e1;&quot;&gt;
        &lt;h4 style=&quot;color: #FF9800;&quot;&gt;Nên dùng Lasso khi:&lt;/h4&gt;
        &lt;ul&gt;
            &lt;li&gt;Cần chọn lọc đặc trưng tự động&lt;/li&gt;
            &lt;li&gt;Nhiều đặc trưng thừa hoặc không liên quan&lt;/li&gt;
            &lt;li&gt;Ưu tiên mô hình gọn nhẹ, dễ diễn giải&lt;/li&gt;
            &lt;li&gt;Mong muốn nghiệm thưa&lt;/li&gt;
            &lt;li&gt;Dữ liệu số chiều cao&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;2-chiến-lược-tinh-chỉnh-siêu-tham-số&quot;&gt;2. Chiến lược Tinh chỉnh Siêu tham số&lt;/h3&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Mã giả tinh chỉnh tham số điều chuẩn
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;tune_regularization&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;lambda_values&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;logspace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Các giá trị cách đều theo thang log
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;best_lambda&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;best_score&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;inf&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lambda_val&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lambda_values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;model&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fit_regularized_model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lambda_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;val_score&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;evaluate_model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;val_score&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;best_score&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;best_score&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;val_score&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;best_lambda&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lambda_val&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;best_lambda&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;best_score&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-chuẩn-hóa-đặc-trưng-feature-scaling&quot;&gt;3. Chuẩn hóa Đặc trưng (Feature Scaling)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý quan trọng&lt;/strong&gt;: Các phương pháp điều chuẩn rất nhạy cảm với thang đo của đặc trưng.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ridge/Lasso&lt;/strong&gt;: Cần chuẩn hóa đặc trưng (standardization) trước khi huấn luyện.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lý do&lt;/strong&gt;: Số hạng phạt phụ thuộc trực tiếp vào độ lớn của các hệ số \(w_j\); nếu các đặc trưng có đơn vị đo chênh lệch lớn, mức phạt sẽ không công bằng giữa chúng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách xử lý&lt;/strong&gt;: Đưa các đặc trưng về trung bình 0 và độ lệch chuẩn 1 trước khi áp dụng điều chuẩn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;h3 id=&quot;những-điểm-chính&quot;&gt;Những Điểm Chính&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điều chuẩn (Regularization)&lt;/strong&gt; giúp kiểm soát độ phức tạp mô hình và hạn chế quá khớp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ridge (L2)&lt;/strong&gt; co nhỏ đồng đều các hệ số và tăng tính ổn định số học.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lasso (L1)&lt;/strong&gt; tạo ra nghiệm thưa và thực hiện chọn lọc đặc trưng tự động.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Elastic Net&lt;/strong&gt; kết hợp ưu điểm của cả L1 và L2.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn hàm mất mát&lt;/strong&gt; quyết định tính trơn và độ bền vững của mô hình trước nhiễu ngoại lai.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm định chéo (Cross-validation)&lt;/strong&gt; là công cụ tiêu chuẩn để chọn siêu tham số \(\lambda\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;quy-trình-thực-hành&quot;&gt;Quy trình Thực hành&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tiền xử lý dữ liệu&lt;/strong&gt;: Chuẩn hóa thang đo các đặc trưng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn phương pháp&lt;/strong&gt;: Dựa trên cấu trúc dữ liệu và mục tiêu bài toán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tinh chỉnh siêu tham số&lt;/strong&gt;: Dùng kiểm định chéo trên lưới giá trị \(\lambda\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh giá mô hình&lt;/strong&gt;: Kiểm tra trên tập dữ liệu độc lập (test set).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích kết quả&lt;/strong&gt;: Kiểm tra độ lớn và độ thưa của các hệ số học được.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Điều chuẩn là công cụ hiệu quả nhưng không thay thế được việc hiểu rõ dữ liệu và bản chất bài toán.&lt;/p&gt;

&lt;script&gt;
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    // Quadratic Function Demo
    initializeQuadraticFunctionDemo();
    
    // Regularization Convergence Demo
    initializeRegularizationConvergenceDemo();
    
    // Ridge Effect Demo
    initializeRidgeEffectDemo();
    
    // Ridge vs Lasso Comparison
    initializeRidgeLassoComparison();
    
    // Loss Functions Demo
    initializeLossFunctionsDemo();
    
    // Regularization Path Demo
    initializeRegularizationPathDemo();
    
    function initializeRidgeEffectDemo() {
        const lambdaSlider = document.getElementById(&apos;ridge-lambda&apos;);
        const noiseSlider = document.getElementById(&apos;ridge-noise&apos;);
        const featuresSlider = document.getElementById(&apos;ridge-features&apos;);
        const regenerateBtn = document.getElementById(&apos;ridge-regenerate&apos;);
        
        let currentData = generateRidgeData();
        
        function generateRidgeData() {
            const n = 50; // samples
            const p = parseInt(featuresSlider.value); // features
            const noise = parseFloat(noiseSlider.value);
            
            // Generate true coefficients (sparse)
            const trueCoeffs = Array(p).fill(0).map((_, i) =&gt; 
                i &lt; 3 ? (Math.random() - 0.5) * 4 : 0
            );
            
            // Generate X matrix
            const X = Array(n).fill().map(() =&gt; 
                Array(p).fill().map(() =&gt; Math.random() * 2 - 1)
            );
            
            // Generate y with noise
            const y = X.map(row =&gt; 
                row.reduce((sum, x, i) =&gt; sum + x * trueCoeffs[i], 0) + 
                (Math.random() - 0.5) * noise * 2
            );
            
            return { X, y, trueCoeffs, n, p };
        }
        
        function updateRidgeDemo() {
            const lambda = parseFloat(lambdaSlider.value);
            document.getElementById(&apos;ridge-lambda-value&apos;).textContent = lambda.toFixed(1);
            
            // Compute Ridge coefficients for different lambda values
            const lambdaRange = Array(50).fill().map((_, i) =&gt; i * 0.2);
            const coeffPaths = computeRidgeCoefficients(currentData, lambdaRange);
            
            // Update visualizations
            updateRidgeCoefficientsPlot(coeffPaths, lambdaRange, lambda);
            updateRidgeErrorPlot(currentData, lambdaRange);
        }
        
        function computeRidgeCoefficients(data, lambdaRange) {
            const { X, y, p } = data;
            const paths = Array(p).fill().map(() =&gt; []);
            
            lambdaRange.forEach(lambda =&gt; {
                const coeffs = solveRidge(X, y, lambda);
                coeffs.forEach((coeff, i) =&gt; paths[i].push(coeff));
            });
            
            return paths;
        }
        
        function solveRidge(X, y, lambda) {
            // Simplified Ridge solution: w = (X&apos;X + λI)^(-1) X&apos;y
            const p = X[0].length;
            const n = X.length;
            
            // Compute X&apos;X
            const XtX = Array(p).fill().map(() =&gt; Array(p).fill(0));
            for (let i = 0; i &lt; p; i++) {
                for (let j = 0; j &lt; p; j++) {
                    for (let k = 0; k &lt; n; k++) {
                        XtX[i][j] += X[k][i] * X[k][j];
                    }
                }
            }
            
            // Add λI
            for (let i = 0; i &lt; p; i++) {
                XtX[i][i] += lambda;
            }
            
            // Compute X&apos;y
            const Xty = Array(p).fill(0);
            for (let i = 0; i &lt; p; i++) {
                for (let k = 0; k &lt; n; k++) {
                    Xty[i] += X[k][i] * y[k];
                }
            }
            
            // Solve linear system (simplified - using pseudo-inverse)
            return solveLinearSystem(XtX, Xty);
        }
        
        function solveLinearSystem(A, b) {
            // Simplified solution using Gaussian elimination
            const n = A.length;
            const coeffs = Array(n).fill(0);
            
            // For demo purposes, use a simplified approach
            for (let i = 0; i &lt; n; i++) {
                coeffs[i] = b[i] / (A[i][i] + 1e-10);
            }
            
            return coeffs;
        }
        
        function updateRidgeCoefficientsPlot(coeffPaths, lambdaRange, currentLambda) {
            const svg = d3.select(&apos;#ridge-coefficients&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain(d3.extent(lambdaRange))
                .range([0, width]);
            
            const allCoeffs = coeffPaths.flat();
            const yScale = d3.scaleLinear()
                .domain(d3.extent(allCoeffs))
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Lambda (λ)&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Coefficient Value&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(lambdaRange[i]))
                .y(d =&gt; yScale(d));
            
            // Draw coefficient paths
            const colors = d3.schemeCategory10;
            coeffPaths.forEach((path, i) =&gt; {
                g.append(&apos;path&apos;)
                    .datum(path)
                    .attr(&apos;fill&apos;, &apos;none&apos;)
                    .attr(&apos;stroke&apos;, colors[i % colors.length])
                    .attr(&apos;stroke-width&apos;, 2)
                    .attr(&apos;d&apos;, line);
            });
            
            // Current lambda line
            g.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, xScale(currentLambda))
                .attr(&apos;x2&apos;, xScale(currentLambda))
                .attr(&apos;y1&apos;, 0)
                .attr(&apos;y2&apos;, height)
                .attr(&apos;stroke&apos;, &apos;red&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;stroke-dasharray&apos;, &apos;5,5&apos;);
            
            // Update info
            const currentIndex = Math.round(currentLambda / 0.2);
            const currentCoeffs = coeffPaths.map(path =&gt; path[currentIndex] || 0);
            const l2Norm = Math.sqrt(currentCoeffs.reduce((sum, c) =&gt; sum + c*c, 0));
            document.getElementById(&apos;ridge-coeff-info&apos;).textContent = 
                `L2 Norm của coefficients: ${l2Norm.toFixed(3)}`;
        }
        
        function updateRidgeErrorPlot(data, lambdaRange) {
            // Simplified error computation for demo
            const svg = d3.select(&apos;#ridge-error&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Generate synthetic error curves
            const trainErrors = lambdaRange.map(lambda =&gt; 
                0.1 + 0.5 * lambda + Math.random() * 0.1
            );
            const valErrors = lambdaRange.map(lambda =&gt; 
                0.3 + 0.2 * Math.abs(lambda - 2) + Math.random() * 0.1
            );
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain(d3.extent(lambdaRange))
                .range([0, width]);
            
            const yScale = d3.scaleLinear()
                .domain([0, Math.max(...trainErrors, ...valErrors)])
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Lambda (λ)&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Error&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(lambdaRange[i]))
                .y(d =&gt; yScale(d));
            
            // Draw error curves
            g.append(&apos;path&apos;)
                .datum(trainErrors)
                .attr(&apos;fill&apos;, &apos;none&apos;)
                .attr(&apos;stroke&apos;, &apos;blue&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;d&apos;, line);
            
            g.append(&apos;path&apos;)
                .datum(valErrors)
                .attr(&apos;fill&apos;, &apos;none&apos;)
                .attr(&apos;stroke&apos;, &apos;red&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;d&apos;, line);
            
            // Legend
            const legend = g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${width - 100}, 20)`);
            
            legend.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, 0).attr(&apos;x2&apos;, 20)
                .attr(&apos;y1&apos;, 0).attr(&apos;y2&apos;, 0)
                .attr(&apos;stroke&apos;, &apos;blue&apos;).attr(&apos;stroke-width&apos;, 2);
            legend.append(&apos;text&apos;)
                .attr(&apos;x&apos;, 25).attr(&apos;y&apos;, 5)
                .text(&apos;Training&apos;);
            
            legend.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, 0).attr(&apos;x2&apos;, 20)
                .attr(&apos;y1&apos;, 15).attr(&apos;y2&apos;, 15)
                .attr(&apos;stroke&apos;, &apos;red&apos;).attr(&apos;stroke-width&apos;, 2);
            legend.append(&apos;text&apos;)
                .attr(&apos;x&apos;, 25).attr(&apos;y&apos;, 20)
                .text(&apos;Validation&apos;);
            
            // Find optimal lambda
            const optimalIndex = valErrors.indexOf(Math.min(...valErrors));
            const optimalLambda = lambdaRange[optimalIndex];
            document.getElementById(&apos;ridge-error-info&apos;).textContent = 
                `Optimal λ: ${optimalLambda.toFixed(2)}`;
        }
        
        // Event listeners
        lambdaSlider.addEventListener(&apos;input&apos;, updateRidgeDemo);
        noiseSlider.addEventListener(&apos;input&apos;, function() {
            document.getElementById(&apos;ridge-noise-value&apos;).textContent = this.value;
        });
        featuresSlider.addEventListener(&apos;input&apos;, function() {
            document.getElementById(&apos;ridge-features-value&apos;).textContent = this.value;
        });
        
        regenerateBtn.addEventListener(&apos;click&apos;, function() {
            currentData = generateRidgeData();
            updateRidgeDemo();
        });
        
        // Initial update
        updateRidgeDemo();
    }
    
    function initializeRidgeLassoComparison() {
        const lambdaSlider = document.getElementById(&apos;comparison-lambda&apos;);
        const correlationSlider = document.getElementById(&apos;comparison-correlation&apos;);
        const updateBtn = document.getElementById(&apos;comparison-update&apos;);
        
        function updateComparison() {
            const lambda = parseFloat(lambdaSlider.value);
            const correlation = parseFloat(correlationSlider.value);
            
            document.getElementById(&apos;comparison-lambda-value&apos;).textContent = lambda.toFixed(1);
            document.getElementById(&apos;comparison-correlation-value&apos;).textContent = correlation.toFixed(1);
            
            // Generate synthetic data with controlled correlation
            const p = 8; // features
            const trueCoeffs = [2, -1.5, 1, 0.5, -0.8, 0, 0, 0];
            
            // Compute Ridge and Lasso coefficients
            const ridgeCoeffs = computeRidgeCoeffs(trueCoeffs, lambda, correlation);
            const lassoCoeffs = computeLassoCoeffs(trueCoeffs, lambda, correlation);
            
            // Update visualizations
            updateComparisonPlot(&apos;ridge-comparison&apos;, ridgeCoeffs, &apos;Ridge&apos;);
            updateComparisonPlot(&apos;lasso-comparison&apos;, lassoCoeffs, &apos;Lasso&apos;);
            updateGeometryPlot(lambda);
        }
        
        function computeRidgeCoeffs(trueCoeffs, lambda, correlation) {
            // Simplified Ridge shrinkage
            const shrinkageFactor = 1 / (1 + lambda);
            return trueCoeffs.map(coeff =&gt; coeff * shrinkageFactor);
        }
        
        function computeLassoCoeffs(trueCoeffs, lambda, correlation) {
            // Simplified Lasso soft thresholding
            return trueCoeffs.map(coeff =&gt; {
                const absCoeff = Math.abs(coeff);
                if (absCoeff &lt;= lambda) return 0;
                return Math.sign(coeff) * (absCoeff - lambda);
            });
        }
        
        function updateComparisonPlot(svgId, coeffs, title) {
            const svg = d3.select(`#${svgId}`);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 40};
            const width = 300 - margin.left - margin.right;
            const height = 250 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Scales
            const xScale = d3.scaleBand()
                .domain(coeffs.map((_, i) =&gt; `w${i+1}`))
                .range([0, width])
                .padding(0.1);
            
            const yScale = d3.scaleLinear()
                .domain(d3.extent(coeffs))
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Bars
            const color = title === &apos;Ridge&apos; ? &apos;#4CAF50&apos; : &apos;#FF9800&apos;;
            g.selectAll(&apos;.bar&apos;)
                .data(coeffs)
                .enter().append(&apos;rect&apos;)
                .attr(&apos;class&apos;, &apos;bar&apos;)
                .attr(&apos;x&apos;, (d, i) =&gt; xScale(`w${i+1}`))
                .attr(&apos;width&apos;, xScale.bandwidth())
                .attr(&apos;y&apos;, d =&gt; d &gt;= 0 ? yScale(d) : yScale(0))
                .attr(&apos;height&apos;, d =&gt; Math.abs(yScale(d) - yScale(0)))
                .attr(&apos;fill&apos;, color);
            
            // Zero line
            g.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, 0)
                .attr(&apos;x2&apos;, width)
                .attr(&apos;y1&apos;, yScale(0))
                .attr(&apos;y2&apos;, yScale(0))
                .attr(&apos;stroke&apos;, &apos;black&apos;)
                .attr(&apos;stroke-width&apos;, 1);
        }
        
        function updateGeometryPlot(lambda) {
            const svg = d3.select(&apos;#regularization-geometry&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 40};
            const width = 300 - margin.left - margin.right;
            const height = 250 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            const centerX = width / 2;
            const centerY = height / 2;
            const radius = Math.min(width, height) / 3;
            
            // L2 constraint (circle)
            g.append(&apos;circle&apos;)
                .attr(&apos;cx&apos;, centerX)
                .attr(&apos;cy&apos;, centerY)
                .attr(&apos;r&apos;, radius)
                .attr(&apos;fill&apos;, &apos;none&apos;)
                .attr(&apos;stroke&apos;, &apos;#4CAF50&apos;)
                .attr(&apos;stroke-width&apos;, 3)
                .attr(&apos;opacity&apos;, 0.7);
            
            // L1 constraint (diamond)
            const diamondPoints = [
                [centerX, centerY - radius],
                [centerX + radius, centerY],
                [centerX, centerY + radius],
                [centerX - radius, centerY]
            ];
            
            const line = d3.line()
                .x(d =&gt; d[0])
                .y(d =&gt; d[1]);
            
            g.append(&apos;path&apos;)
                .datum([...diamondPoints, diamondPoints[0]])
                .attr(&apos;d&apos;, line)
                .attr(&apos;fill&apos;, &apos;none&apos;)
                .attr(&apos;stroke&apos;, &apos;#FF9800&apos;)
                .attr(&apos;stroke-width&apos;, 3)
                .attr(&apos;opacity&apos;, 0.7);
            
            // Contour lines (ellipses)
            for (let i = 1; i &lt;= 3; i++) {
                g.append(&apos;ellipse&apos;)
                    .attr(&apos;cx&apos;, centerX + 20)
                    .attr(&apos;cy&apos;, centerY - 10)
                    .attr(&apos;rx&apos;, i * 15)
                    .attr(&apos;ry&apos;, i * 25)
                    .attr(&apos;fill&apos;, &apos;none&apos;)
                    .attr(&apos;stroke&apos;, &apos;#666&apos;)
                    .attr(&apos;stroke-width&apos;, 1)
                    .attr(&apos;stroke-dasharray&apos;, &apos;3,3&apos;)
                    .attr(&apos;opacity&apos;, 0.5);
            }
            
            // Labels
            g.append(&apos;text&apos;)
                .attr(&apos;x&apos;, centerX + radius + 10)
                .attr(&apos;y&apos;, centerY + 5)
                .text(&apos;L2&apos;)
                .attr(&apos;fill&apos;, &apos;#4CAF50&apos;)
                .attr(&apos;font-weight&apos;, &apos;bold&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;x&apos;, centerX + radius/Math.sqrt(2) + 5)
                .attr(&apos;y&apos;, centerY - radius/Math.sqrt(2) - 5)
                .text(&apos;L1&apos;)
                .attr(&apos;fill&apos;, &apos;#FF9800&apos;)
                .attr(&apos;font-weight&apos;, &apos;bold&apos;);
        }
        
        // Event listeners
        lambdaSlider.addEventListener(&apos;input&apos;, updateComparison);
        correlationSlider.addEventListener(&apos;input&apos;, updateComparison);
        updateBtn.addEventListener(&apos;click&apos;, updateComparison);
        
        // Initial update
        updateComparison();
    }
    
    function initializeLossFunctionsDemo() {
        const deltaSlider = document.getElementById(&apos;loss-delta&apos;);
        const rangeSlider = document.getElementById(&apos;loss-range&apos;);
        const derivativesCheckbox = document.getElementById(&apos;show-derivatives&apos;);
        
        function updateLossFunctions() {
            const delta = parseFloat(deltaSlider.value);
            const range = parseFloat(rangeSlider.value);
            const showDerivatives = derivativesCheckbox.checked;
            
            document.getElementById(&apos;loss-delta-value&apos;).textContent = delta.toFixed(1);
            document.getElementById(&apos;loss-range-value&apos;).textContent = range.toFixed(1);
            
            updateRegressionLosses(delta, range, showDerivatives);
            updateClassificationLosses(range, showDerivatives);
        }
        
        function updateRegressionLosses(delta, range, showDerivatives) {
            const svg = d3.select(&apos;#regression-losses&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Generate error values
            const errors = d3.range(-range, range, 0.1);
            
            // Loss functions
            const mseLoss = errors.map(e =&gt; 0.5 * e * e);
            const maeLoss = errors.map(e =&gt; Math.abs(e));
            const huberLoss = errors.map(e =&gt; 
                Math.abs(e) &lt;= delta ? 0.5 * e * e : delta * Math.abs(e) - 0.5 * delta * delta
            );
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain([-range, range])
                .range([0, width]);
            
            const maxLoss = Math.max(...mseLoss, ...maeLoss, ...huberLoss);
            const yScale = d3.scaleLinear()
                .domain([0, maxLoss])
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Prediction Error&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Loss&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(errors[i]))
                .y(d =&gt; yScale(d));
            
            // Draw loss functions
            const colors = [&apos;#1f77b4&apos;, &apos;#ff7f0e&apos;, &apos;#2ca02c&apos;];
            const losses = [mseLoss, maeLoss, huberLoss];
            const names = [&apos;MSE&apos;, &apos;MAE&apos;, &apos;Huber&apos;];
            
            losses.forEach((loss, i) =&gt; {
                g.append(&apos;path&apos;)
                    .datum(loss)
                    .attr(&apos;fill&apos;, &apos;none&apos;)
                    .attr(&apos;stroke&apos;, colors[i])
                    .attr(&apos;stroke-width&apos;, 3)
                    .attr(&apos;d&apos;, line);
            });
            
            // Legend
            const legend = g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${width - 80}, 20)`);
            
            names.forEach((name, i) =&gt; {
                legend.append(&apos;line&apos;)
                    .attr(&apos;x1&apos;, 0).attr(&apos;x2&apos;, 20)
                    .attr(&apos;y1&apos;, i * 20).attr(&apos;y2&apos;, i * 20)
                    .attr(&apos;stroke&apos;, colors[i]).attr(&apos;stroke-width&apos;, 3);
                legend.append(&apos;text&apos;)
                    .attr(&apos;x&apos;, 25).attr(&apos;y&apos;, i * 20 + 5)
                    .text(name);
            });
        }
        
        function updateClassificationLosses(range, showDerivatives) {
            const svg = d3.select(&apos;#classification-losses&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Generate margin values (y * f(x))
            const margins = d3.range(-range, range, 0.1);
            
            // Loss functions
            const logisticLoss = margins.map(m =&gt; Math.log(1 + Math.exp(-m)));
            const hingeLoss = margins.map(m =&gt; Math.max(0, 1 - m));
            const zeroOneLoss = margins.map(m =&gt; m &lt;= 0 ? 1 : 0);
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain([-range, range])
                .range([0, width]);
            
            const maxLoss = Math.max(...logisticLoss, ...hingeLoss, ...zeroOneLoss);
            const yScale = d3.scaleLinear()
                .domain([0, maxLoss])
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Margin (y × f(x))&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Loss&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(margins[i]))
                .y(d =&gt; yScale(d));
            
            // Draw loss functions
            const colors = [&apos;#d62728&apos;, &apos;#9467bd&apos;, &apos;#8c564b&apos;];
            const losses = [logisticLoss, hingeLoss, zeroOneLoss];
            const names = [&apos;Logistic&apos;, &apos;Hinge&apos;, &apos;0-1 Loss&apos;];
            
            losses.forEach((loss, i) =&gt; {
                g.append(&apos;path&apos;)
                    .datum(loss)
                    .attr(&apos;fill&apos;, &apos;none&apos;)
                    .attr(&apos;stroke&apos;, colors[i])
                    .attr(&apos;stroke-width&apos;, 3)
                    .attr(&apos;d&apos;, line);
            });
            
            // Legend
            const legend = g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${width - 80}, 20)`);
            
            names.forEach((name, i) =&gt; {
                legend.append(&apos;line&apos;)
                    .attr(&apos;x1&apos;, 0).attr(&apos;x2&apos;, 20)
                    .attr(&apos;y1&apos;, i * 20).attr(&apos;y2&apos;, i * 20)
                    .attr(&apos;stroke&apos;, colors[i]).attr(&apos;stroke-width&apos;, 3);
                legend.append(&apos;text&apos;)
                    .attr(&apos;x&apos;, 25).attr(&apos;y&apos;, i * 20 + 5)
                    .text(name);
            });
        }
        
        // Event listeners
        deltaSlider.addEventListener(&apos;input&apos;, updateLossFunctions);
        rangeSlider.addEventListener(&apos;input&apos;, updateLossFunctions);
        derivativesCheckbox.addEventListener(&apos;change&apos;, updateLossFunctions);
        
        // Initial update
        updateLossFunctions();
    }
    
    function initializeRegularizationPathDemo() {
        const methodSelect = document.getElementById(&apos;path-method&apos;);
        const alphaSlider = document.getElementById(&apos;path-alpha&apos;);
        const animateBtn = document.getElementById(&apos;path-animate&apos;);
        
        let isAnimating = false;
        let animationId = null;
        
        function updateRegularizationPath() {
            const method = methodSelect.value;
            const alpha = parseFloat(alphaSlider.value);
            
            document.getElementById(&apos;path-alpha-value&apos;).textContent = alpha.toFixed(1);
            
            // Generate regularization path
            const lambdaRange = d3.range(0, 5, 0.1);
            const coeffPaths = generateRegularizationPath(method, alpha, lambdaRange);
            
            updateCoefficientPathPlot(coeffPaths, lambdaRange, method);
            updateCVCurvePlot(lambdaRange, method);
        }
        
        function generateRegularizationPath(method, alpha, lambdaRange) {
            const p = 6; // features
            const trueCoeffs = [2, -1.5, 1, 0.5, -0.8, 0.3];
            
            const paths = Array(p).fill().map(() =&gt; []);
            
            lambdaRange.forEach(lambda =&gt; {
                let coeffs;
                if (method === &apos;ridge&apos;) {
                    coeffs = trueCoeffs.map(c =&gt; c / (1 + lambda));
                } else if (method === &apos;lasso&apos;) {
                    coeffs = trueCoeffs.map(c =&gt; {
                        const abs_c = Math.abs(c);
                        return abs_c &gt; lambda ? Math.sign(c) * (abs_c - lambda) : 0;
                    });
                } else { // elastic net
                    coeffs = trueCoeffs.map(c =&gt; {
                        const abs_c = Math.abs(c);
                        const l1_part = abs_c &gt; alpha * lambda ? Math.sign(c) * (abs_c - alpha * lambda) : 0;
                        return l1_part / (1 + (1 - alpha) * lambda);
                    });
                }
                
                coeffs.forEach((coeff, i) =&gt; paths[i].push(coeff));
            });
            
            return paths;
        }
        
        function updateCoefficientPathPlot(coeffPaths, lambdaRange, method) {
            const svg = d3.select(&apos;#coefficient-path&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain(d3.extent(lambdaRange))
                .range([0, width]);
            
            const allCoeffs = coeffPaths.flat();
            const yScale = d3.scaleLinear()
                .domain(d3.extent(allCoeffs))
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Lambda (λ)&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Coefficient Value&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(lambdaRange[i]))
                .y(d =&gt; yScale(d));
            
            // Draw coefficient paths
            const colors = d3.schemeCategory10;
            coeffPaths.forEach((path, i) =&gt; {
                g.append(&apos;path&apos;)
                    .datum(path)
                    .attr(&apos;fill&apos;, &apos;none&apos;)
                    .attr(&apos;stroke&apos;, colors[i % colors.length])
                    .attr(&apos;stroke-width&apos;, 2)
                    .attr(&apos;d&apos;, line);
                
                // Add feature label at the end
                const lastValue = path[path.length - 1];
                if (Math.abs(lastValue) &gt; 0.01) {
                    g.append(&apos;text&apos;)
                        .attr(&apos;x&apos;, width + 5)
                        .attr(&apos;y&apos;, yScale(lastValue) + 3)
                        .attr(&apos;font-size&apos;, &apos;10px&apos;)
                        .text(`f${i+1}`);
                }
            });
            
            // Update info
            const currentLambda = 1.0; // example
            const activeFeatures = coeffPaths.filter(path =&gt; Math.abs(path[Math.floor(currentLambda * 10)]) &gt; 0.01).length;
            document.getElementById(&apos;path-info&apos;).textContent = 
                `Current λ: ${currentLambda.toFixed(1)}, Active features: ${activeFeatures}`;
        }
        
        function updateCVCurvePlot(lambdaRange, method) {
            const svg = d3.select(&apos;#cv-curve&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Generate synthetic CV scores
            const cvScores = lambdaRange.map(lambda =&gt; {
                const base = 0.2 + 0.1 * Math.abs(lambda - 1.5);
                return base + (Math.random() - 0.5) * 0.05;
            });
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain(d3.extent(lambdaRange))
                .range([0, width]);
            
            const yScale = d3.scaleLinear()
                .domain(d3.extent(cvScores))
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Lambda (λ)&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;CV Score&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(lambdaRange[i]))
                .y(d =&gt; yScale(d));
            
            // Draw CV curve
            g.append(&apos;path&apos;)
                .datum(cvScores)
                .attr(&apos;fill&apos;, &apos;none&apos;)
                .attr(&apos;stroke&apos;, &apos;#2196F3&apos;)
                .attr(&apos;stroke-width&apos;, 3)
                .attr(&apos;d&apos;, line);
            
            // Find and mark optimal lambda
            const minIndex = cvScores.indexOf(Math.min(...cvScores));
            const optimalLambda = lambdaRange[minIndex];
            
            g.append(&apos;circle&apos;)
                .attr(&apos;cx&apos;, xScale(optimalLambda))
                .attr(&apos;cy&apos;, yScale(cvScores[minIndex]))
                .attr(&apos;r&apos;, 5)
                .attr(&apos;fill&apos;, &apos;red&apos;);
            
            // Update info
            document.getElementById(&apos;cv-info&apos;).textContent = 
                `Optimal λ: ${optimalLambda.toFixed(2)}, CV Score: ${cvScores[minIndex].toFixed(3)}`;
        }
        
        function animatePath() {
            if (isAnimating) {
                // Stop animation
                isAnimating = false;
                if (animationId) clearInterval(animationId);
                animateBtn.textContent = &apos;Animate Path&apos;;
                return;
            }
            
            // Start animation
            isAnimating = true;
            animateBtn.textContent = &apos;Stop Animation&apos;;
            
            const lambdaRange = d3.range(0, 5, 0.1);
            let currentIndex = 0;
            
            animationId = setInterval(() =&gt; {
                if (currentIndex &gt;= lambdaRange.length) {
                    currentIndex = 0;
                }
                
                // Update visualization for current lambda
                const currentLambda = lambdaRange[currentIndex];
                // Add animation logic here
                
                currentIndex++;
            }, 100);
        }
        
        // Event listeners
        methodSelect.addEventListener(&apos;change&apos;, updateRegularizationPath);
        alphaSlider.addEventListener(&apos;input&apos;, updateRegularizationPath);
        animateBtn.addEventListener(&apos;click&apos;, animatePath);
        
        // Initial update
        updateRegularizationPath();
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>06-06 Gradient descent with momentum</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_06_gradent_descent_with_momentum/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_06_gradent_descent_with_momentum</id>
   <content type="html">&lt;p&gt;Hãy hình dung một hòn bi thép nặng lăn xuống một khe núi hẹp và dài: ở hai vách núi dốc đứng bên trái–phải, lực kéo đổi chiều liên tục nên tự triệt tiêu lẫn nhau; còn dọc theo lòng khe thoai thoải đi xuống đáy, gia tốc tích tụ liên tục làm hòn bi lao vút về phía trước! Gradient Descent thuần túy giống như một người đi bộ “mất trí nhớ” — sau mỗi bước lại dừng hẳn về vận tốc 0 rồi mới tính lại hướng; còn &lt;strong&gt;Momentum (Động lượng / Heavy Ball của Polyak, 1964)&lt;/strong&gt; trao cho thuật toán chính &lt;strong&gt;quán tính vật lý&lt;/strong&gt; của hòn bi thép ấy!&lt;/p&gt;

&lt;p&gt;Kết quả là một sự tăng tốc ngoạn mục: trên các hàm lồi mạnh có chỉ số điều kiện xấu \(\kappa = L/m\), Momentum rút gọn số vòng lặp từ \(O(\kappa \log(1/\epsilon))\) xuống còn \(O(\sqrt{\kappa} \log(1/\epsilon))\) — hoàn toàn tương đương bước nhảy của tăng tốc Nesterov trên hàm bậc hai!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-vật-lý-và-đại-số-của-phương-pháp-momentum&quot;&gt;Kiến thức cần nhớ: Vật lý và Đại số của Phương pháp Momentum&lt;/h2&gt;

&lt;p&gt;Ba trụ cột dưới đây giải mã trọn vẹn cách hệ số quán tính \(\beta\) điều khiển quỹ đạo hội tụ:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương trình Động lượng &amp;amp; Trung bình trượt lũy thừa (EMA):&lt;/strong&gt; Quy tắc cập nhật:
\(v_{k+1} = \beta v_k + \nabla f(x_k), \qquad x_{k+1} = x_k - \alpha v_{k+1}.\)
Khai triển đệ quy cho thấy \(v_{k+1} = \sum_{j=0}^k \beta^{k-j} \nabla f(x_j)\): vận tốc hiện tại là tổng trọng số suy giảm theo hàm mũ của toàn bộ lịch sử gradient!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cơ chế “Triệt tiêu dao động – Khuếch đại hướng ổn định”:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Theo phương thung lũng dài (gradient cùng dấu liên tục \(g\)): vận tốc tích tụ lên đến \(\frac{g}{1 - \beta}\) — với \(\beta = 0.9\), tốc độ tiến dọc thung lũng được khuếch đại gấp &lt;strong&gt;10 lần&lt;/strong&gt;!&lt;/li&gt;
      &lt;li&gt;Theo phương vách dốc (gradient đổi dấu \(+g, -g, +g, -g\)): các số hạng ngược dấu triệt tiêu nhau, dập tắt hiện tượng zíc-zắc!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tham số tối ưu cho hàm bậc hai:&lt;/strong&gt; Với hàm bậc hai có trị riêng nằm trong \([m, L]\), cặp tham số tối ưu của Polyak là:
\(\alpha^\star = \left(\frac{2}{\sqrt{L} + \sqrt{m}}\right)^2, \qquad \beta^\star = \left(\frac{\sqrt{L} - \sqrt{m}}{\sqrt{L} + \sqrt{m}}\right)^2 = \left(\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\right)^2,\)
đạt hệ số co mỗi bước là \(\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-3-bước-momentum-vs-gd-thường-trên-thung-lũng-hẹp&quot;&gt;Giải thích: Chạy tay 3 bước Momentum vs. GD thường trên thung lũng hẹp&lt;/h3&gt;

&lt;p&gt;Xét hàm \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + 9x_2^2)\) (\(m = 1,\; L = 9,\; \kappa = 9\)).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Với &lt;strong&gt;GD thường&lt;/strong&gt; dùng bước tối ưu \(t^\star = \frac{2}{9+1} = 0.2\), hệ số co là \(\frac{9-1}{9+1} = 0.8\).&lt;/li&gt;
  &lt;li&gt;Với &lt;strong&gt;Momentum Polyak&lt;/strong&gt;, tính ngay tham số tối ưu:
\(\alpha^\star = \left(\frac{2}{3 + 1}\right)^2 = 0.25, \qquad \beta^\star = \left(\frac{3 - 1}{3 + 1}\right)^2 = 0.25.\)
Hệ số co lý thuyết giảm từ \(0.8\) xuống còn \(\frac{\sqrt{9} - 1}{\sqrt{9} + 1} = 0.5\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hãy chạy tay từ \(x_0 = (1, 1)^T,\; v_0 = (0, 0)^T\) với \(x_{k+1} = x_k - 0.25 \nabla f(x_k) + 0.25(x_k - x_{k-1})\):&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; \(g_0 = (1, 9)^T \implies x_1 = (1, 1)^T - 0.25(1, 9)^T = (0.75,\; -1.25)^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt; \(g_1 = (0.75,\; -11.25)^T\), độ dịch trước \(x_1 - x_0 = (-0.25,\; -2.25)^T\).
    &lt;ul&gt;
      &lt;li&gt;\(x_{2,1} = 0.75 - 0.25(0.75) + 0.25(-0.25) = 0.50\) (trong khi GD thường mới ở \(0.8^2 = 0.64\)!).&lt;/li&gt;
      &lt;li&gt;\(x_{2,2} = -1.25 - 0.25(-11.25) + 0.25(-2.25) = -1.25 + 2.8125 - 0.5625 = 1.00\) (đang hãm dao động mạnh).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3:&lt;/strong&gt; \(g_2 = (0.50,\; 9.0)^T\), \(x_2 - x_1 = (-0.25,\; 2.25)^T\).
    &lt;ul&gt;
      &lt;li&gt;\(x_{3,1} = 0.50 - 0.25(0.50) + 0.25(-0.25) = 0.3125\) (so với GD thường \(0.8^3 = 0.512\)!).&lt;/li&gt;
      &lt;li&gt;\(x_{3,2} = 1.00 - 0.25(9.0) + 0.25(2.25) = -0.6875\).
Chỉ sau vài bước, quán tính đã kéo trục thoai thoải \(x_1\) về đích nhanh vượt trội!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;Hình minh họa trên trang này mô phỏng trường hợp toàn tập (full-batch) với hệ số momentum \(\beta\) không đổi. Phân tích phổ theo phong cách Distill — bao gồm đa thức đặc trưng, giá trị \(\beta^\star\) tối ưu, so sánh nhìn trước (look-ahead) với heavy ball, và lý do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nesterov=True&lt;/code&gt; không tương đương FISTA — được trình bày trong bài hiện đại &lt;a href=&quot;/contents/vi/chapter26/26_02_momentum_and_nesterov/&quot;&gt;26-02&lt;/a&gt;; phiên bản gradient gần kề có lập lịch tham số nằm tại &lt;a href=&quot;/contents/vi/chapter09/09_05_acceleration/&quot;&gt;09-05&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;hạn-chế-của-gradient-descent-thuần-túy&quot;&gt;Hạn chế của Gradient Descent Thuần túy&lt;/h2&gt;

&lt;p&gt;Hãy hình dung một quả bóng lăn xuống đáy thung lũng. Gradient descent tiêu chuẩn giống như một quả bóng không có quán tính: tại mỗi bước, nó chỉ dựa vào độ dốc tức thời để di chuyển. Điều này dẫn tới một số hạn chế:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ chậm trong các thung lũng hẹp&lt;/strong&gt;: Khi hàm số rất dốc theo một số phương nhưng lại rất thoải theo các phương khác.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dao động mạnh&lt;/strong&gt;: Quỹ đạo thường nảy qua lại giữa hai sườn thung lũng thay vì tiến thẳng về phía cực tiểu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dễ dừng sớm tại cực tiểu cục bộ nông&lt;/strong&gt;: Thiếu quán tính khiến thuật toán khó vượt qua các vùng trũng cục bộ nhỏ.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi đặt ra&lt;/strong&gt;: Điều gì xảy ra nếu ta cho thuật toán “ghi nhớ” hướng di chuyển trước đó và duy trì một phần vận tốc?&lt;/p&gt;

&lt;h2 id=&quot;momentum-bổ-sung-quán-tính-cho-gradient-descent&quot;&gt;Momentum: Bổ sung Quán tính cho Gradient Descent&lt;/h2&gt;

&lt;p&gt;Gradient descent có momentum lấy cảm hứng từ cơ học cổ điển — cụ thể là chuyển động của một vật lăn xuống dốc có lực cản ma sát. Ý tưởng cốt lõi là tích lũy một vector vận tốc kết hợp giữa hướng di chuyển trước đó và gradient hiện tại.&lt;/p&gt;

&lt;h3 id=&quot;thuật-toán-momentum&quot;&gt;Thuật toán Momentum&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Quy tắc cập nhật:&lt;/strong&gt;
\(\begin{align}
v^{(k)} &amp;amp;= \beta v^{(k-1)} + (1-\beta) \nabla f(x^{(k-1)}) \\
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\)&lt;/p&gt;

&lt;p&gt;trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(v^{(k)}\) là vector momentum (vận tốc) tại lần lặp \(k\).&lt;/li&gt;
  &lt;li&gt;\(\beta \in [0,1)\) là hệ số momentum (thường chọn \(0.9\) hoặc \(0.99\)).&lt;/li&gt;
  &lt;li&gt;\(t &amp;gt; 0\) là tốc độ học.&lt;/li&gt;
  &lt;li&gt;\(v^{(0)} = 0\) (vận tốc khởi tạo bằng 0).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;dạng-công-thức-tương-đương-không-nhân-hệ-số-1-beta&quot;&gt;Dạng công thức tương đương (không nhân hệ số \(1-\beta\))&lt;/h3&gt;

&lt;p&gt;Một số cài đặt sử dụng dạng tương đương sau (khác ở hệ số tỉ lệ tốc độ học):
\(\begin{align}
v^{(k)} &amp;amp;= \beta v^{(k-1)} + \nabla f(x^{(k-1)}) \\
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa chính&lt;/strong&gt;: Ở cả hai dạng, \(v^{(k)}\) là tổ hợp có trọng số mũ của các gradient trước đó: dạng đầu là trung bình trượt, dạng sau là tổng có trọng số. Cả hai vẫn là phương pháp heavy ball thông thường, không phải Nesterov.&lt;/p&gt;

&lt;h2 id=&quot;ý-nghĩa-của-hệ-số-momentum-beta&quot;&gt;Ý nghĩa của Hệ số Momentum \(\beta\)&lt;/h2&gt;

&lt;p&gt;Hệ số \(\beta\) kiểm soát mức độ “ghi nhớ” của thuật toán:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(\beta = 0\)&lt;/strong&gt;: Không có momentum, thuật toán trở về gradient descent tiêu chuẩn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\beta = 0.9\)&lt;/strong&gt;: Mức momentum trung bình, được sử dụng phổ biến trong thực tế.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\beta = 0.99\)&lt;/strong&gt;: Mức momentum cao, thường dùng trong một số bài toán học sâu có bề mặt mất mát trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\beta \to 1\)&lt;/strong&gt;: Quán tính rất lớn, nhưng dễ gây mất ổn định nếu tốc độ học không đủ nhỏ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;trung-bình-trượt-có-trọng-số-mũ&quot;&gt;Trung bình Trượt có Trọng số Mũ&lt;/h3&gt;

&lt;p&gt;Khai triển đệ quy công thức momentum đầu tiên cho ta:
\(v^{(k)} = (1-\beta) \sum_{i=0}^{k-1} \beta^i \nabla f(x^{(k-1-i)})\)&lt;/p&gt;

&lt;p&gt;Công thức này cho thấy trọng số của các gradient cũ giảm dần theo hàm mũ theo thời gian.&lt;/p&gt;

&lt;h2 id=&quot;trực-quan-hóa-tương-tác-gradient-descent-và-momentum&quot;&gt;Trực quan hóa Tương tác: Gradient Descent và Momentum&lt;/h2&gt;

&lt;div id=&quot;momentum-comparison&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;!-- Parameter Controls --&gt;
    &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9;&quot;&gt;
        &lt;div&gt;
            &lt;label for=&quot;momentum-lr&quot;&gt;Tốc độ học: &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;momentum-lr&quot; min=&quot;0.01&quot; max=&quot;0.3&quot; step=&quot;0.01&quot; value=&quot;0.1&quot; /&gt;
            &lt;span id=&quot;momentum-lr-value&quot;&gt;0.1&lt;/span&gt;
        &lt;/div&gt;
        &lt;div&gt;
            &lt;label for=&quot;momentum-beta&quot;&gt;Momentum (β): &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;momentum-beta&quot; min=&quot;0&quot; max=&quot;0.99&quot; step=&quot;0.01&quot; value=&quot;0.9&quot; /&gt;
            &lt;span id=&quot;momentum-beta-value&quot;&gt;0.9&lt;/span&gt;
        &lt;/div&gt;
        &lt;div&gt;
            &lt;label for=&quot;momentum-speed&quot;&gt;Tốc độ hoạt ảnh: &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;momentum-speed&quot; min=&quot;1&quot; max=&quot;10&quot; step=&quot;1&quot; value=&quot;5&quot; /&gt;
            &lt;span id=&quot;momentum-speed-value&quot;&gt;5&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;!-- Control Buttons --&gt;
    &lt;div style=&quot;display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap;&quot;&gt;
        &lt;button id=&quot;start-vanilla-gd&quot; style=&quot;background-color: #4CAF50; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Chạy GD thường&lt;/button&gt;
        &lt;button id=&quot;start-momentum-gd&quot; style=&quot;background-color: #FF9800; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Chạy GD momentum&lt;/button&gt;
        &lt;button id=&quot;start-both&quot; style=&quot;background-color: #2196F3; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;So sánh cả hai&lt;/button&gt;
        &lt;button id=&quot;reset-momentum&quot; style=&quot;background-color: #f44336; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Đặt lại&lt;/button&gt;
    &lt;/div&gt;
    
    &lt;!-- Visualization Canvas --&gt;
    &lt;div id=&quot;momentum-canvas&quot; style=&quot;border: 1px solid #ccc; border-radius: 5px; background-color: white; position: relative; overflow: hidden;&quot;&gt;
        &lt;svg width=&quot;800&quot; height=&quot;500&quot; id=&quot;momentum-svg&quot;&gt;&lt;/svg&gt;
    &lt;/div&gt;
    
    &lt;!-- Algorithm Status --&gt;
    &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 15px;&quot;&gt;
        &lt;div style=&quot;padding: 10px; border: 1px solid #4CAF50; border-radius: 5px; background-color: #f1f8e9;&quot;&gt;
            &lt;h4 style=&quot;margin: 0 0 5px 0; color: #4CAF50;&quot;&gt;Gradient Descent thường&lt;/h4&gt;
            &lt;p id=&quot;vanilla-gd-info&quot; style=&quot;margin: 0; font-size: 14px;&quot;&gt;Sẵn sàng&lt;/p&gt;
        &lt;/div&gt;
        &lt;div style=&quot;padding: 10px; border: 1px solid #FF9800; border-radius: 5px; background-color: #fff8e1;&quot;&gt;
            &lt;h4 style=&quot;margin: 0 0 5px 0; color: #FF9800;&quot;&gt;Gradient Descent với momentum&lt;/h4&gt;
            &lt;p id=&quot;momentum-gd-info&quot; style=&quot;margin: 0; font-size: 14px;&quot;&gt;Sẵn sàng&lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    // Momentum visualization implementation
    const svg = d3.select(&quot;#momentum-svg&quot;);
    const width = 800, height = 500;
    const margin = {top: 20, right: 20, bottom: 40, left: 40};
    
    // Function to optimize: f(x,y) = 0.5*x^2 + 5*y^2 (elongated bowl)
    function f(x, y) {
        return 0.5 * x * x + 5 * y * y;
    }
    
    function gradient(x, y) {
        return [x, 10 * y];
    }
    
    // Scale setup
    const xScale = d3.scaleLinear()
        .domain([-6, 6])
        .range([margin.left, width - margin.right]);
    
    const yScale = d3.scaleLinear()
        .domain([-3, 3])
        .range([height - margin.bottom, margin.top]);
    
    // Create contour plot
    function createContours() {
        // Create a simple grid-based contour visualization
        const gridSize = 20;
        const contourLevels = [1, 4, 9, 16, 25, 36, 49];
        
        svg.selectAll(&quot;.contour&quot;).remove();
        
        // Draw contour ellipses for the function f(x,y) = 0.5*x^2 + 5*y^2
        contourLevels.forEach(level =&gt; {
            // For f(x,y) = 0.5*x^2 + 5*y^2 = level
            // This is an ellipse: x^2/(2*level) + y^2/(level/5) = 1
            const a = Math.sqrt(2 * level); // semi-major axis in x direction
            const b = Math.sqrt(level / 5); // semi-minor axis in y direction
            
            if (a &lt;= 6 &amp;&amp; b &lt;= 3) { // Only draw if within our domain
                svg.append(&quot;ellipse&quot;)
                    .attr(&quot;class&quot;, &quot;contour&quot;)
                    .attr(&quot;cx&quot;, xScale(0))
                    .attr(&quot;cy&quot;, yScale(0))
                    .attr(&quot;rx&quot;, xScale(a) - xScale(0))
                    .attr(&quot;ry&quot;, yScale(0) - yScale(b))
                    .attr(&quot;fill&quot;, &quot;none&quot;)
                    .attr(&quot;stroke&quot;, &quot;#ddd&quot;)
                    .attr(&quot;stroke-width&quot;, 1)
                    .attr(&quot;opacity&quot;, 0.6);
            }
        });
    }
    
    createContours();
    
    // Add global minimum marker
    svg.append(&quot;circle&quot;)
        .attr(&quot;cx&quot;, xScale(0))
        .attr(&quot;cy&quot;, yScale(0))
        .attr(&quot;r&quot;, 8)
        .attr(&quot;fill&quot;, &quot;red&quot;)
        .attr(&quot;stroke&quot;, &quot;white&quot;)
        .attr(&quot;stroke-width&quot;, 2)
        .attr(&quot;opacity&quot;, 0.8);
    
    svg.append(&quot;text&quot;)
        .attr(&quot;x&quot;, xScale(0))
        .attr(&quot;y&quot;, yScale(0) - 15)
        .attr(&quot;text-anchor&quot;, &quot;middle&quot;)
        .attr(&quot;font-size&quot;, &quot;12px&quot;)
        .attr(&quot;font-weight&quot;, &quot;bold&quot;)
        .attr(&quot;fill&quot;, &quot;red&quot;)
        .text(&quot;Cực tiểu toàn cục&quot;);
    
    // Add axes
    svg.append(&quot;g&quot;)
        .attr(&quot;transform&quot;, `translate(0,${height - margin.bottom})`)
        .call(d3.axisBottom(xScale));
    
    svg.append(&quot;g&quot;)
        .attr(&quot;transform&quot;, `translate(${margin.left},0)`)
        .call(d3.axisLeft(yScale));
    
    // Add axis labels
    svg.append(&quot;text&quot;)
        .attr(&quot;x&quot;, width / 2)
        .attr(&quot;y&quot;, height - 5)
        .attr(&quot;text-anchor&quot;, &quot;middle&quot;)
        .attr(&quot;font-size&quot;, &quot;14px&quot;)
        .text(&quot;x&quot;);
    
    svg.append(&quot;text&quot;)
        .attr(&quot;x&quot;, 15)
        .attr(&quot;y&quot;, height / 2)
        .attr(&quot;text-anchor&quot;, &quot;middle&quot;)
        .attr(&quot;font-size&quot;, &quot;14px&quot;)
        .attr(&quot;transform&quot;, `rotate(-90, 15, ${height / 2})`)
        .text(&quot;y&quot;);
    
    // Add title
    svg.append(&quot;text&quot;)
        .attr(&quot;x&quot;, width / 2)
        .attr(&quot;y&quot;, 15)
        .attr(&quot;text-anchor&quot;, &quot;middle&quot;)
        .attr(&quot;font-size&quot;, &quot;16px&quot;)
        .attr(&quot;font-weight&quot;, &quot;bold&quot;)
        .text(&quot;f(x,y) = 0.5x² + 5y² - So sánh đường đi tối ưu&quot;);
    
    // Variables for animation
    let vanillaPath = [], momentumPath = [];
    let vanillaRunning = false, momentumRunning = false;
    let vanillaInterval, momentumInterval;
    
    // Algorithm implementations
    function runVanillaGD() {
        const lr = parseFloat(document.getElementById(&apos;momentum-lr&apos;).value);
        let x = -4, y = 2; // Starting point
        let iteration = 0;
        const maxIterations = 500;
        vanillaPath = [{x: x, y: y}];
        vanillaRunning = true;
        
        vanillaInterval = setInterval(() =&gt; {
            const grad = gradient(x, y);
            x -= lr * grad[0];
            y -= lr * grad[1];
            vanillaPath.push({x: x, y: y});
            iteration++;
            
            updateVisualization();
            updateStatus();
            
            // Stop if converged or max iterations reached
            if ((Math.abs(grad[0]) &lt; 0.01 &amp;&amp; Math.abs(grad[1]) &lt; 0.01) || iteration &gt;= maxIterations) {
                clearInterval(vanillaInterval);
                vanillaRunning = false;
            }
        }, 1000 / parseFloat(document.getElementById(&apos;momentum-speed&apos;).value));
    }
    
    function runMomentumGD() {
        const lr = parseFloat(document.getElementById(&apos;momentum-lr&apos;).value);
        const beta = parseFloat(document.getElementById(&apos;momentum-beta&apos;).value);
        let x = -4, y = 2; // Starting point
        let vx = 0, vy = 0; // Initial velocity
        let iteration = 0;
        const maxIterations = 500;
        momentumPath = [{x: x, y: y}];
        momentumRunning = true;
        
        momentumInterval = setInterval(() =&gt; {
            const grad = gradient(x, y);
            vx = beta * vx + (1 - beta) * grad[0];
            vy = beta * vy + (1 - beta) * grad[1];
            x -= lr * vx;
            y -= lr * vy;
            momentumPath.push({x: x, y: y});
            iteration++;
            
            updateVisualization();
            updateStatus();
            
            // Stop if converged or max iterations reached
            if ((Math.abs(grad[0]) &lt; 0.01 &amp;&amp; Math.abs(grad[1]) &lt; 0.01) || iteration &gt;= maxIterations) {
                clearInterval(momentumInterval);
                momentumRunning = false;
            }
        }, 1000 / parseFloat(document.getElementById(&apos;momentum-speed&apos;).value));
    }
    
    function updateVisualization() {
        // Remove existing paths
        svg.selectAll(&quot;.vanilla-path&quot;).remove();
        svg.selectAll(&quot;.momentum-path&quot;).remove();
        svg.selectAll(&quot;.vanilla-point&quot;).remove();
        svg.selectAll(&quot;.momentum-point&quot;).remove();
        
        // Draw vanilla GD path
        if (vanillaPath.length &gt; 1) {
            const line = d3.line()
                .x(d =&gt; xScale(d.x))
                .y(d =&gt; yScale(d.y));
            
            svg.append(&quot;path&quot;)
                .datum(vanillaPath)
                .attr(&quot;class&quot;, &quot;vanilla-path&quot;)
                .attr(&quot;d&quot;, line)
                .attr(&quot;fill&quot;, &quot;none&quot;)
                .attr(&quot;stroke&quot;, &quot;#4CAF50&quot;)
                .attr(&quot;stroke-width&quot;, 2);
            
            // Current point
            const current = vanillaPath[vanillaPath.length - 1];
            svg.append(&quot;circle&quot;)
                .attr(&quot;class&quot;, &quot;vanilla-point&quot;)
                .attr(&quot;cx&quot;, xScale(current.x))
                .attr(&quot;cy&quot;, yScale(current.y))
                .attr(&quot;r&quot;, 5)
                .attr(&quot;fill&quot;, &quot;#4CAF50&quot;);
        }
        
        // Draw momentum GD path
        if (momentumPath.length &gt; 1) {
            const line = d3.line()
                .x(d =&gt; xScale(d.x))
                .y(d =&gt; yScale(d.y));
            
            svg.append(&quot;path&quot;)
                .datum(momentumPath)
                .attr(&quot;class&quot;, &quot;momentum-path&quot;)
                .attr(&quot;d&quot;, line)
                .attr(&quot;fill&quot;, &quot;none&quot;)
                .attr(&quot;stroke&quot;, &quot;#FF9800&quot;)
                .attr(&quot;stroke-width&quot;, 2);
            
            // Current point
            const current = momentumPath[momentumPath.length - 1];
            svg.append(&quot;circle&quot;)
                .attr(&quot;class&quot;, &quot;momentum-point&quot;)
                .attr(&quot;cx&quot;, xScale(current.x))
                .attr(&quot;cy&quot;, yScale(current.y))
                .attr(&quot;r&quot;, 5)
                .attr(&quot;fill&quot;, &quot;#FF9800&quot;);
        }
    }
    
    function updateStatus() {
        // Update vanilla GD status
        if (vanillaPath.length &gt; 0) {
            const current = vanillaPath[vanillaPath.length - 1];
            const fValue = f(current.x, current.y);
            document.getElementById(&apos;vanilla-gd-info&apos;).innerHTML = 
                `Vòng lặp: ${vanillaPath.length - 1}&lt;br&gt;Vị trí: (${current.x.toFixed(3)}, ${current.y.toFixed(3)})&lt;br&gt;f(x,y): ${fValue.toFixed(4)}`;
        }
        
        // Update momentum GD status
        if (momentumPath.length &gt; 0) {
            const current = momentumPath[momentumPath.length - 1];
            const fValue = f(current.x, current.y);
            document.getElementById(&apos;momentum-gd-info&apos;).innerHTML = 
                `Vòng lặp: ${momentumPath.length - 1}&lt;br&gt;Vị trí: (${current.x.toFixed(3)}, ${current.y.toFixed(3)})&lt;br&gt;f(x,y): ${fValue.toFixed(4)}`;
        }
    }
    
    // Event listeners
    document.getElementById(&apos;start-vanilla-gd&apos;).addEventListener(&apos;click&apos;, () =&gt; {
        if (!vanillaRunning) {
            vanillaRunning = true;
            runVanillaGD();
        }
    });
    
    document.getElementById(&apos;start-momentum-gd&apos;).addEventListener(&apos;click&apos;, () =&gt; {
        if (!momentumRunning) {
            momentumRunning = true;
            runMomentumGD();
        }
    });
    
    document.getElementById(&apos;start-both&apos;).addEventListener(&apos;click&apos;, () =&gt; {
        if (!vanillaRunning &amp;&amp; !momentumRunning) {
            vanillaRunning = true;
            momentumRunning = true;
            runVanillaGD();
            runMomentumGD();
        }
    });
    
    document.getElementById(&apos;reset-momentum&apos;).addEventListener(&apos;click&apos;, () =&gt; {
        clearInterval(vanillaInterval);
        clearInterval(momentumInterval);
        vanillaRunning = false;
        momentumRunning = false;
        vanillaPath = [];
        momentumPath = [];
        updateVisualization();
        document.getElementById(&apos;vanilla-gd-info&apos;).innerHTML = &apos;Sẵn sàng&apos;;
        document.getElementById(&apos;momentum-gd-info&apos;).innerHTML = &apos;Sẵn sàng&apos;;
    });
    
    // Update display values
    document.getElementById(&apos;momentum-lr&apos;).addEventListener(&apos;input&apos;, function() {
        document.getElementById(&apos;momentum-lr-value&apos;).textContent = this.value;
    });
    
    document.getElementById(&apos;momentum-beta&apos;).addEventListener(&apos;input&apos;, function() {
        document.getElementById(&apos;momentum-beta-value&apos;).textContent = this.value;
    });
    
    document.getElementById(&apos;momentum-speed&apos;).addEventListener(&apos;input&apos;, function() {
        document.getElementById(&apos;momentum-speed-value&apos;).textContent = this.value;
    });
});
&lt;/script&gt;

&lt;h2 id=&quot;ưu-điểm-của-momentum&quot;&gt;Ưu điểm của Momentum&lt;/h2&gt;

&lt;h3 id=&quot;1-hội-tụ-nhanh-hơn&quot;&gt;1. &lt;strong&gt;Hội tụ nhanh hơn&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Momentum tích lũy vận tốc dọc theo các hướng có gradient nhất quán, nhờ đó đẩy nhanh quá trình hội tụ đặc biệt trên:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Các hàm có thung lũng hoặc khe hẹp.&lt;/li&gt;
  &lt;li&gt;Các bài toán có chỉ số điều kiện lớn.&lt;/li&gt;
  &lt;li&gt;Các bề mặt hàm phức tạp có nhiều cực tiểu cục bộ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-giảm-dao-động&quot;&gt;2. &lt;strong&gt;Giảm dao động&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Theo các phương mà gradient liên tục đổi dấu, việc lấy trung bình các gradient quá khứ giúp triệt tiêu bớt thành phần dao động qua lại.&lt;/p&gt;

&lt;h3 id=&quot;3-khả-năng-vượt-qua-cực-tiểu-cục-bộ-nông&quot;&gt;3. &lt;strong&gt;Khả năng vượt qua cực tiểu cục bộ nông&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Quán tính tích lũy giúp quỹ đạo có thể lăn qua các vùng trũng cục bộ nhỏ để tiếp tục hướng tới nghiệm tốt hơn.&lt;/p&gt;

&lt;h2 id=&quot;các-biến-thể-và-mở-rộng&quot;&gt;Các Biến thể và Mở rộng&lt;/h2&gt;

&lt;h3 id=&quot;1-nesterov-accelerated-gradient-nag&quot;&gt;1. &lt;strong&gt;Nesterov Accelerated Gradient (NAG)&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Thay vì tính gradient tại vị trí hiện tại, NAG đánh giá gradient tại vị trí “nhìn trước” (look-ahead):&lt;/p&gt;

\[\begin{align}
v^{(k)} &amp;amp;= \beta v^{(k-1)} + \nabla f(x^{(k-1)} - t \beta v^{(k-1)}) \\
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\]

&lt;p&gt;&lt;strong&gt;Trực giác&lt;/strong&gt;: Đánh giá độ dốc tại vị trí dự kiến mà bước momentum sắp đưa ta tới, từ đó điều chỉnh sớm hơn.&lt;/p&gt;

&lt;h4 id=&quot;hạn-chế-của-momentum-thông-thường&quot;&gt;Hạn chế của Momentum Thông thường&lt;/h4&gt;

&lt;p&gt;Dù momentum giúp tăng tốc trên thung lũng hẹp, khi tiến gần đến điểm cực tiểu, quán tính tích lũy có thể khiến quỹ đạo vượt quá mục tiêu và cần thêm nhiều bước để giảm tốc.&lt;/p&gt;

&lt;h4 id=&quot;ý-tưởng-cốt-lõi-của-nag&quot;&gt;Ý tưởng Cốt lõi của NAG&lt;/h4&gt;

&lt;p&gt;Ý tưởng của NAG là &lt;strong&gt;dự đoán trước vị trí kế tiếp&lt;/strong&gt;: vì thành phần momentum sẽ dịch chuyển điểm lặp đi một đoạn \(-t\beta v^{(k-1)}\), ta xấp xỉ vị trí sắp tới là \(x^{(k-1)} - t\beta v^{(k-1)}\) rồi tính gradient ngay tại điểm nhìn trước đó để hiệu chỉnh bước đi.&lt;/p&gt;

&lt;h4 id=&quot;so-sánh-trực-quan&quot;&gt;So sánh Trực quan&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Momentum thông thường&lt;/strong&gt;: Bước cập nhật kết hợp vector momentum từ bước trước và gradient tại &lt;strong&gt;vị trí hiện tại&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov momentum&lt;/strong&gt;: Bước cập nhật kết hợp vector momentum từ bước trước và gradient tại &lt;strong&gt;vị trí nhìn trước&lt;/strong&gt; (nơi momentum dự kiến sẽ đưa tới).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cơ chế nhìn trước này giúp NAG hiệu chỉnh kịp thời khi độ dốc đổi chiều, giảm hiện tượng vượt quá cực tiểu và thường hội tụ nhanh hơn.&lt;/p&gt;

&lt;h3 id=&quot;2-adaptive-moment-estimation-adam&quot;&gt;2. &lt;strong&gt;Adaptive Moment Estimation (Adam)&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Adam kết hợp momentum (mô-men bậc nhất) với tốc độ học thích ứng cho từng tham số (dựa trên mô-men bậc hai):&lt;/p&gt;

\[\begin{align}
m^{(k)} &amp;amp;= \beta_1 m^{(k-1)} + (1-\beta_1) \nabla f(x^{(k-1)}) \\
v^{(k)} &amp;amp;= \beta_2 v^{(k-1)} + (1-\beta_2) (\nabla f(x^{(k-1)}))^2 \\
x^{(k)} &amp;amp;= x^{(k-1)} - t \frac{m^{(k)}}{\sqrt{v^{(k)}} + \epsilon}
\end{align}\]

&lt;h2 id=&quot;kinh-nghiệm-cài-đặt-thực-tế&quot;&gt;Kinh nghiệm Cài đặt Thực tế&lt;/h2&gt;

&lt;h3 id=&quot;1-chọn-hệ-số-momentum&quot;&gt;1. &lt;strong&gt;Chọn Hệ số Momentum&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bắt đầu với \(\beta = 0.9\)&lt;/strong&gt;: Lựa chọn mặc định phù hợp cho đa số bài toán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tăng lên \(\beta = 0.99\)&lt;/strong&gt;: Khi bề mặt hàm mục tiêu rất trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giảm xuống \(\beta = 0.5\text{--}0.7\)&lt;/strong&gt;: Khi gradient có nhiều nhiễu hoặc hàm kém trơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-điều-chỉnh-tốc-độ-học&quot;&gt;2. &lt;strong&gt;Điều chỉnh Tốc độ Học&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Khi dùng momentum (đặc biệt dạng không nhân \(1-\beta\)), cần cân nhắc giảm tốc độ học so với gradient descent thường vì momentum làm tăng kích thước bước hiệu dụng.&lt;/p&gt;

&lt;h3 id=&quot;3-giai-đoạn-khởi-động-warm-up&quot;&gt;3. &lt;strong&gt;Giai đoạn Khởi động (Warm-up)&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Có thể khởi đầu với hệ số momentum nhỏ rồi tăng dần để thuật toán tích lũy vận tốc ổn định hơn ở những vòng lặp đầu.&lt;/p&gt;

&lt;h2 id=&quot;phân-tích-toán-học&quot;&gt;Phân tích Toán học&lt;/h2&gt;

&lt;h3 id=&quot;tính-chất-hội-tụ&quot;&gt;Tính chất Hội tụ&lt;/h3&gt;

&lt;p&gt;Đối với hàm lồi mạnh có gradient liên tục Lipschitz (và chọn tham số phù hợp trên lớp hàm bậc hai), gradient descent có momentum đạt được:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ tuyến tính&lt;/strong&gt;: \(f(x^{(k)}) - f^* \leq C \rho^k\) với một hằng số \(\rho &amp;lt; 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cải thiện sự phụ thuộc vào chỉ số điều kiện&lt;/strong&gt;: Tốc độ phụ thuộc vào \(\sqrt{\kappa}\) thay vì \(\kappa\) như gradient descent chuẩn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;liên-hệ-với-phương-pháp-quả-cầu-nặng-heavy-ball&quot;&gt;Liên hệ với Phương pháp Quả cầu Nặng (Heavy Ball)&lt;/h3&gt;

&lt;p&gt;Gradient descent có momentum gắn chặt với phương trình vi phân chuyển động của quả cầu nặng có ma sát trong cơ học cổ điển:
\(mx&apos;&apos; + \gamma x&apos; + \nabla f(x) = 0\)&lt;/p&gt;

&lt;p&gt;Khi rời rạc hóa phương trình vi phân này theo thời gian, ta thu được quy tắc cập nhật momentum.&lt;/p&gt;

&lt;h3 id=&quot;momentum-và-nesterov-trong-khoảng-4-phút&quot;&gt;Momentum và Nesterov trong khoảng 4 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/momentum-nesterov_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Heavy ball và Nesterov trên thung lũng ½(w₁² + 100w₂²): đếm số bước, quét β, và trường hợp Nesterov phân kỳ khi η quá lớn.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt-so-sánh&quot;&gt;Tóm tắt So sánh&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khía cạnh&lt;/th&gt;
      &lt;th&gt;Vanilla GD&lt;/th&gt;
      &lt;th&gt;Momentum GD&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Bộ nhớ&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Không&lt;/td&gt;
      &lt;td&gt;Có (trọng số giảm mũ)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hội tụ&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Có thể chậm&lt;/td&gt;
      &lt;td&gt;Thường nhanh hơn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dao động&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Dễ xảy ra hơn&lt;/td&gt;
      &lt;td&gt;Giảm đáng kể&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Cực tiểu cục bộ&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Dễ bị giữ lại&lt;/td&gt;
      &lt;td&gt;Có khả năng vượt qua tốt hơn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Siêu tham số&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tốc độ học&lt;/td&gt;
      &lt;td&gt;Tốc độ học + hệ số momentum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Chi phí tính toán&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Thấp&lt;/td&gt;
      &lt;td&gt;Cao hơn không đáng kể&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;những-điểm-chính&quot;&gt;Những Điểm Chính&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bổ sung quán tính&lt;/strong&gt;: Momentum lưu giữ thông tin về hướng cập nhật của các bước trước.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tăng tốc hội tụ&lt;/strong&gt;: Đặc biệt hữu ích trên các hàm có thung lũng hẹp hoặc chỉ số điều kiện lớn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giảm dao động&lt;/strong&gt;: Làm mượt quỹ đạo zig-zag dọc theo các phương có độ cong lớn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính ứng dụng rộng&lt;/strong&gt;: Là nền tảng của nhiều bộ tối ưu hiện đại trong học máy và học sâu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linh hoạt điều chỉnh&lt;/strong&gt;: Hệ số \(\beta\) cho phép cân bằng giữa tốc độ tích lũy vận tốc và độ ổn định.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tóm lại, momentum là một cải tiến đơn giản nhưng hiệu quả đối với gradient descent và vẫn giữ vai trò quan trọng trong các hệ thống tối ưu hóa hiện đại.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-05 Stochastic gradient descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_05_stochastic_gradient_descent/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_05_stochastic_gradient_descent</id>
   <content type="html">&lt;p&gt;Giả sử bạn đang huấn luyện một mô hình nhận diện ảnh trên 10 triệu bức ảnh. Nếu dùng Batch Gradient Descent chuẩn, chỉ để nhích trọng số đi &lt;strong&gt;đúng một bước duy nhất&lt;/strong&gt;, máy tính phải đọc và tính đạo hàm trên cả 10 triệu bức ảnh — có khi mất hàng giờ đồng hồ! Trong khi đó, ngay sau khi mới xem qua 64 bức ảnh ngẫu nhiên, hướng dốc trung bình đã chỉ gần đúng về phía đáy thung lũng rồi!&lt;/p&gt;

&lt;p&gt;Đó chính là triết lý làm nên sức mạnh của &lt;strong&gt;Stochastic Gradient Descent (SGD)&lt;/strong&gt; — động cơ cốt lõi đằng sau toàn bộ kỷ nguyên dữ liệu lớn và Học sâu. Thay vì tính gradient chính xác trên toàn bộ \(N\) mẫu, SGD dùng một &lt;strong&gt;ước lượng không chệch (unbiased estimator)&lt;/strong&gt; từ 1 mẫu hoặc một mini-batch nhỏ \(B\) mẫu — chấp nhận một chút “nhiễu” ở mỗi bước để đổi lấy tốc độ cập nhật nhanh hơn hàng chục nghìn lần!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-toán-học-của-nhiễu-và-hội-tụ-trong-sgd&quot;&gt;Kiến thức cần nhớ: Toán học của Nhiễu và Hội tụ trong SGD&lt;/h2&gt;

&lt;p&gt;Bốn trụ cột sau giải thích cơ chế hoạt động và cách điều khiển SGD hiệu quả:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng Gradient không chệch (Unbiased Gradient Estimator):&lt;/strong&gt; Với hàm mục tiêu dạng tổng hữu hạn \(f(x) = \frac{1}{N}\sum_{i=1}^N f_i(x)\), nếu chọn ngẫu nhiên đều chỉ số \(i_k \in \{1, \dots, N\}\), thì kỳ vọng của gradient ngẫu nhiên đúng bằng gradient thật:
\(\mathbb{E}[\nabla f_{i_k}(x)] = \frac{1}{N}\sum_{i=1}^N \nabla f_i(x) = \nabla f(x).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sự đánh đổi Phương sai – Chi phí (Mini-Batch SGD):&lt;/strong&gt; Dùng mini-batch cỡ \(B\) giảm phương sai nhiễu đi \(B\) lần (\(\operatorname{Var}(\bar{g}_B) = \sigma^2 / B\)) trong khi tận dụng tối đa khả năng tính toán song song của GPU!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại sao SGD bước cố định không hội tụ về đúng \(x^\star\)?&lt;/strong&gt; Ngay cả khi bạn đang đứng chính xác tại \(x^\star\) (nơi \(\nabla f(x^\star) = 0\)), từng thành phần riêng lẻ \(\nabla f_i(x^\star)\) thường vẫn &lt;strong&gt;khác 0&lt;/strong&gt;! Vì vậy SGD bước cố định chỉ hội tụ vào một “quả cầu nhiễu” bán kính tỷ lệ với \(t \sigma^2\) quanh \(x^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện Robbins–Monro để hội tụ chính xác:&lt;/strong&gt; Để triệt tiêu nhiễu mà vẫn đủ sức đi tới đích, kích thước bước \(t_k\) phải giảm dần sao cho \(\sum_{k=1}^\infty t_k = \infty\) và \(\sum_{k=1}^\infty t_k^2 &amp;lt; \infty\) (ví dụ \(t_k = \frac{c}{k}\) hoặc \(t_k = \frac{c}{\sqrt{k}}\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-trực-tiếp-1-bước-batch-gd-vs-2-bước-sgd-trên-2-mẫu-dữ-liệu&quot;&gt;Giải thích: So sánh trực tiếp 1 bước Batch GD vs. 2 bước SGD trên 2 mẫu dữ liệu&lt;/h3&gt;

&lt;p&gt;Xét hàm mục tiêu tổng hữu hạn \(f(x) = \frac{1}{2}\big[f_1(x) + f_2(x)\big]\) với:
\(f_1(x) = \frac{1}{2}(x - 2)^2, \qquad f_2(x) = \frac{1}{2}(x - 6)^2.\)
Dễ thấy \(f(x)\) đạt cực tiểu toàn cục tại trung bình \(x^\star = 4\) (với \(f_1&apos;(4) = +2,\; f_2&apos;(4) = -2,\; f&apos;(4) = 0\)). Bắt đầu từ \(x_0 = 0\) với bước \(t = 0.5\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Batch GD (dùng cả 2 mẫu cho 1 bước):&lt;/strong&gt;
\(f&apos;(0) = \frac{1}{2}[(0 - 2) + (0 - 6)] = -4 \implies x_1^{\text{GD}} = 0 - 0.5(-4) = 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SGD (tốn cùng tổng số lượt duyệt 2 mẫu: mẫu 1 trước, mẫu 2 sau):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Dùng mẫu 1 tại \(x_0 = 0\): \(f_1&apos;(0) = -2 \implies x_{0.5} = 0 - 0.5(-2) = 1\).&lt;/li&gt;
      &lt;li&gt;Dùng mẫu 2 tại \(x_{0.5} = 1\): \(f_2&apos;(1) = 1 - 6 = -5 \implies x_1^{\text{SGD}} = 1 - 0.5(-5) = 3.5\)!
Chỉ sau đúng 1 lượt duyệt dữ liệu (1 epoch), SGD đã nhảy lên \(3.5\) (rất sát \(x^\star = 4\)!), trong khi Batch GD mới ở \(2\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan sát “quả cầu nhiễu” tại chính nghiệm đúng \(x = 4\):&lt;/strong&gt;
Nếu SGD bước cố định \(t = 0.5\) đang ở đúng \(x = 4\) và bốc trúng mẫu 1, nó sẽ bị đẩy lùi về \(4 - 0.5(2) = 3\)! Chỉ khi ta giảm bước \(t_k \to 0\), dao động quanh \(x^\star = 4\) mới tắt hẳn!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script src=&quot;../../../public/js/script.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;

&lt;h2 id=&quot;động-lực-thách-thức-của-dữ-liệu-lớn&quot;&gt;Động lực: Thách thức của Dữ liệu Lớn&lt;/h2&gt;

&lt;p&gt;Hãy hình dung bài toán huấn luyện một mô hình học máy trên hàng triệu điểm dữ liệu. Gradient descent truyền thống yêu cầu tính gradient trên &lt;strong&gt;toàn bộ&lt;/strong&gt; tập dữ liệu trước khi thực hiện một bước cập nhật duy nhất. Cách làm này nhanh chóng trở nên tốn kém cả về thời gian tính toán lẫn bộ nhớ khi quy mô dữ liệu lớn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi đặt ra&lt;/strong&gt;: Liệu ta có thể cập nhật tham số dần dần bằng cách chỉ xét một điểm dữ liệu tại mỗi bước hay không?&lt;/p&gt;

&lt;h2 id=&quot;nền-tảng-toán-học&quot;&gt;Nền tảng Toán học&lt;/h2&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa tổng của nhiều hàm thành phần:&lt;/p&gt;

\[\begin{equation}
\min_x f(x) = \min_x \sum_{i=1}^m f_i(x)
\end{equation}\]

&lt;p&gt;&lt;strong&gt;Ý nghĩa thực tế&lt;/strong&gt;: Trong học máy, \(f_i(x)\) thường là hàm mất mát trên mẫu huấn luyện thứ \(i\), còn \(x\) là vector tham số của mô hình.&lt;/p&gt;

&lt;h3 id=&quot;batch-gradient-descent-phương-pháp-toàn-tập&quot;&gt;Batch Gradient Descent (Phương pháp Toàn tập)&lt;/h3&gt;

&lt;p&gt;Gradient của tổng bằng tổng các gradient thành phần:
\(\nabla f(x) = \nabla \sum_{i=1}^m f_i(x) = \sum_{i=1}^m \nabla f_i(x)\)&lt;/p&gt;

&lt;p&gt;Quy tắc cập nhật của batch gradient descent là:
\(\begin{equation}
x^{(k)} = x^{(k-1)} - t_k \cdot \sum_{i=1}^{m} \nabla f_i (x^{(k-1)}), \quad k=1,2,3,\dots
\end{equation}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chi phí tính toán&lt;/strong&gt;: \(O(m)\) lần tính gradient trên mỗi bước lặp, trong đó \(m\) là số hàm thành phần (hoặc số mẫu dữ liệu).&lt;/p&gt;

&lt;h2 id=&quot;stochastic-gradient-descent-giải-pháp-thay-thế-hiệu-quả&quot;&gt;Stochastic Gradient Descent: Giải pháp Thay thế Hiệu quả&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Ý tưởng cốt lõi&lt;/strong&gt;: Thay vì tính gradient của toàn bộ \(m\) hàm thành phần, Stochastic Gradient Descent (SGD) chỉ sử dụng &lt;strong&gt;một&lt;/strong&gt; hàm tại mỗi lần lặp:&lt;/p&gt;

\[\begin{equation}
x^{(k)} = x^{(k-1)} - t_k \cdot \nabla f_{i_k} (x^{(k-1)}), \quad i_k \in \{1,2,\dots,m\}
\end{equation}\]

&lt;p&gt;&lt;strong&gt;Chi phí tính toán&lt;/strong&gt;: Chỉ \(O(1)\) lần tính gradient cho mỗi lần lặp, giảm đáng kể chi phí trên mỗi bước cập nhật.&lt;/p&gt;

&lt;h3 id=&quot;trực-quan-hóa-tương-tác-so-sánh-gd-và-sgd-theo-từng-bước&quot;&gt;Trực quan hóa Tương tác: So sánh GD và SGD theo Từng Bước&lt;/h3&gt;

&lt;div id=&quot;gd-sgd-comparison&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;!-- Parameter Controls --&gt;
    &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9;&quot;&gt;
        &lt;div&gt;
            &lt;label for=&quot;learning-rate&quot;&gt;Tốc độ học: &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;learning-rate&quot; min=&quot;0.01&quot; max=&quot;0.5&quot; step=&quot;0.01&quot; value=&quot;0.1&quot; /&gt;
            &lt;span id=&quot;lr-value&quot;&gt;0.1&lt;/span&gt;
        &lt;/div&gt;
        &lt;div&gt;
            &lt;label for=&quot;num-functions&quot;&gt;Số hàm thành phần (m): &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;num-functions&quot; min=&quot;3&quot; max=&quot;10&quot; step=&quot;1&quot; value=&quot;5&quot; /&gt;
            &lt;span id=&quot;m-value&quot;&gt;5&lt;/span&gt;
        &lt;/div&gt;
        &lt;div&gt;
            &lt;label for=&quot;animation-speed&quot;&gt;Tốc độ hoạt ảnh: &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;animation-speed&quot; min=&quot;1&quot; max=&quot;10&quot; step=&quot;1&quot; value=&quot;5&quot; /&gt;
            &lt;span id=&quot;speed-value&quot;&gt;5&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;!-- Execution Mode Selection --&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 10px; border: 1px solid #ddd; border-radius: 5px; background-color: #f0f8ff;&quot;&gt;
        &lt;h4 style=&quot;margin: 0 0 10px 0;&quot;&gt;Chế độ chạy:&lt;/h4&gt;
        &lt;div style=&quot;display: flex; gap: 15px;&quot;&gt;
            &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;exec-mode&quot; value=&quot;auto&quot; checked=&quot;&quot; /&gt; Tự động chạy&lt;/label&gt;
            &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;exec-mode&quot; value=&quot;manual&quot; /&gt; Chạy từng bước&lt;/label&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;!-- Control Buttons --&gt;
    &lt;div style=&quot;display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap;&quot;&gt;
        &lt;button id=&quot;start-gd&quot; style=&quot;background-color: #4CAF50; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Chạy Gradient Descent&lt;/button&gt;
        &lt;button id=&quot;start-sgd&quot; style=&quot;background-color: #FF9800; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Chạy SGD&lt;/button&gt;
        &lt;button id=&quot;pause-resume&quot; style=&quot;background-color: #2196F3; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot; disabled=&quot;&quot;&gt;Tạm dừng&lt;/button&gt;
        &lt;button id=&quot;step-forward&quot; style=&quot;background-color: #9C27B0; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot; disabled=&quot;&quot;&gt;Bước tiếp&lt;/button&gt;
        &lt;button id=&quot;reset-demo&quot; style=&quot;background-color: #f44336; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Đặt lại&lt;/button&gt;
    &lt;/div&gt;
    
    &lt;!-- Algorithm Status --&gt;
    &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 15px;&quot;&gt;
        &lt;div style=&quot;padding: 10px; border: 1px solid #4CAF50; border-radius: 5px; background-color: #f1f8e9;&quot;&gt;
            &lt;h4 style=&quot;margin: 0 0 5px 0; color: #4CAF50;&quot;&gt;Trạng thái Gradient Descent&lt;/h4&gt;
            &lt;p id=&quot;gd-detailed-info&quot; style=&quot;margin: 0; font-size: 14px;&quot;&gt;Sẵn sàng&lt;/p&gt;
        &lt;/div&gt;
        &lt;div style=&quot;padding: 10px; border: 1px solid #FF9800; border-radius: 5px; background-color: #fff8e1;&quot;&gt;
            &lt;h4 style=&quot;margin: 0 0 5px 0; color: #FF9800;&quot;&gt;Trạng thái SGD&lt;/h4&gt;
            &lt;p id=&quot;sgd-detailed-info&quot; style=&quot;margin: 0; font-size: 14px;&quot;&gt;Sẵn sàng&lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;!-- Visualization Plots --&gt;
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Gradient Descent (toàn bộ dữ liệu)&lt;/h4&gt;
            &lt;svg id=&quot;gd-plot&quot; width=&quot;350&quot; height=&quot;350&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;gd-info&quot; style=&quot;margin: 0; font-weight: bold;&quot;&gt;Số vòng lặp: 0, Chi phí: 0&lt;/p&gt;
                &lt;p id=&quot;gd-gradient-info&quot; style=&quot;margin: 5px 0 0 0; font-size: 12px; color: #666;&quot;&gt;Gradient: [0, 0]&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Gradient Descent ngẫu nhiên (SGD)&lt;/h4&gt;
            &lt;svg id=&quot;sgd-plot&quot; width=&quot;350&quot; height=&quot;350&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;sgd-info&quot; style=&quot;margin: 0; font-weight: bold;&quot;&gt;Số vòng lặp: 0, Chi phí: 0&lt;/p&gt;
                &lt;p id=&quot;sgd-gradient-info&quot; style=&quot;margin: 5px 0 0 0; font-size: 12px; color: #666;&quot;&gt;Hàm được chọn: -, Gradient: [0, 0]&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;!-- Progress Visualization --&gt;
    &lt;div style=&quot;margin-top: 20px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #fafafa;&quot;&gt;
        &lt;h4&gt;Quá trình hội tụ&lt;/h4&gt;
        &lt;div style=&quot;display: flex; gap: 20px;&quot;&gt;
            &lt;div style=&quot;flex: 1;&quot;&gt;
                &lt;p&gt;&lt;strong&gt;Tiến trình GD:&lt;/strong&gt;&lt;/p&gt;
                &lt;div style=&quot;width: 100%; background-color: #e0e0e0; border-radius: 10px; height: 20px;&quot;&gt;
                    &lt;div id=&quot;gd-progress&quot; style=&quot;width: 0%; background-color: #4CAF50; height: 100%; border-radius: 10px; transition: width 0.3s;&quot;&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div style=&quot;flex: 1;&quot;&gt;
                &lt;p&gt;&lt;strong&gt;Tiến trình SGD:&lt;/strong&gt;&lt;/p&gt;
                &lt;div style=&quot;width: 100%; background-color: #e0e0e0; border-radius: 10px; height: 20px;&quot;&gt;
                    &lt;div id=&quot;sgd-progress&quot; style=&quot;width: 0%; background-color: #FF9800; height: 100%; border-radius: 10px; transition: width 0.3s;&quot;&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;các-chiến-lược-chọn-mẫu-trong-sgd&quot;&gt;Các Chiến lược Chọn Mẫu trong SGD&lt;/h3&gt;

&lt;p&gt;Chỉ số hàm \(i_k\) có thể được lựa chọn theo hai quy tắc phổ biến:&lt;/p&gt;

&lt;h4 id=&quot;1-quy-tắc-tuần-hoàn-cyclic-rule&quot;&gt;1. Quy tắc Tuần hoàn (Cyclic Rule)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Thứ tự&lt;/strong&gt;: \(i_k = 1,2,\dots,m, 1,2,\dots,m, \ldots\)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ưu điểm&lt;/strong&gt;: Có tính tất định, đảm bảo mọi hàm thành phần đều được duyệt qua đều đặn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhược điểm&lt;/strong&gt;: Có thể chịu ảnh hưởng của chu kỳ lặp cố định nếu thứ tự dữ liệu có quy luật.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-quy-tắc-ngẫu-nhiên-randomized-rule&quot;&gt;2. Quy tắc Ngẫu nhiên (Randomized Rule)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Thứ tự&lt;/strong&gt;: Chọn \(i_k\) ngẫu nhiên đều từ \(\{1,2,\dots,m\}\).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ưu điểm&lt;/strong&gt;: Tránh chu kỳ cố định và có đảm bảo lý thuyết về hội tụ tốt hơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhược điểm&lt;/strong&gt;: Trong ngắn hạn, một số hàm thành phần có thể được chọn nhiều lần hơn các hàm khác.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trong thực tế&lt;/strong&gt;: Quy tắc ngẫu nhiên (hoặc xáo trộn ngẫu nhiên tập dữ liệu ở đầu mỗi epoch) được ưu tiên sử dụng vì mang lại tính chất hội tụ tốt hơn.&lt;/p&gt;

&lt;h2 id=&quot;phân-tích-hội-tụ-lý-thuyết-và-thực-tế&quot;&gt;Phân tích Hội tụ: Lý thuyết và Thực tế&lt;/h2&gt;

&lt;h3 id=&quot;so-sánh-công-thức-cập-nhật&quot;&gt;So sánh Công thức Cập nhật&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Batch GD (một epoch)&lt;/strong&gt;:
\(x^{(k+1)} = x^{(k)} - t_k \cdot \sum_{i=1}^{m} \nabla f_i (x^{(k)})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SGD (một epoch với quy tắc tuần hoàn, kích thước bước cố định \(t_k\) trong epoch)&lt;/strong&gt;:
\(x^{(k+m)} = x^{(k)} - t_k \cdot \sum_{i=1}^{m} \nabla f_i (x^{(k+i-1)})\)&lt;/p&gt;

&lt;h3 id=&quot;phân-tích-quy-tắc-tuần-hoàn-của-sgd&quot;&gt;Phân tích Quy tắc Tuần hoàn của SGD&lt;/h3&gt;

&lt;p&gt;Hãy xem xét chi tiết điều gì diễn ra trong một epoch hoàn chỉnh của SGD theo quy tắc tuần hoàn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Epoch là gì?&lt;/strong&gt; Một epoch tương ứng với việc thuật toán duyệt qua toàn bộ \(m\) hàm thành phần đúng một lần.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trình tự cập nhật trong một epoch:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Xuất phát tại điểm \(x^{(k)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1&lt;/strong&gt;: Dùng \(f_1\), tính \(\nabla f_1(x^{(k)})\), cập nhật sang \(x^{(k+1)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2&lt;/strong&gt;: Dùng \(f_2\), tính \(\nabla f_2(x^{(k+1)})\), cập nhật sang \(x^{(k+2)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3&lt;/strong&gt;: Dùng \(f_3\), tính \(\nabla f_3(x^{(k+2)})\), cập nhật sang \(x^{(k+3)}\).&lt;/li&gt;
  &lt;li&gt;…&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(m\)&lt;/strong&gt;: Dùng \(f_m\), tính \(\nabla f_m(x^{(k+m-1)})\), cập nhật sang \(x^{(k+m)}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các bước cập nhật riêng lẻ:&lt;/strong&gt;
\(\begin{align}
x^{(k+1)} &amp;amp;= x^{(k)} - t_k \nabla f_1(x^{(k)}) \\
x^{(k+2)} &amp;amp;= x^{(k+1)} - t_k \nabla f_2(x^{(k+1)}) \\
x^{(k+3)} &amp;amp;= x^{(k+2)} - t_k \nabla f_3(x^{(k+2)}) \\
&amp;amp;\vdots \\
x^{(k+m)} &amp;amp;= x^{(k+m-1)} - t_k \nabla f_m(x^{(k+m-1)})
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gộp các bước cập nhật:&lt;/strong&gt;
Thay thế liên tiếp các biểu thức trên, ta thu được:
\(x^{(k+m)} = x^{(k)} - t_k \left[ \nabla f_1(x^{(k)}) + \nabla f_2(x^{(k+1)}) + \cdots + \nabla f_m(x^{(k+m-1)}) \right]\)&lt;/p&gt;

&lt;p&gt;Viết gọn lại:
\(x^{(k+m)} = x^{(k)} - t_k \cdot \sum_{i=1}^{m} \nabla f_i (x^{(k+i-1)})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điểm cốt lõi:&lt;/strong&gt; Mỗi gradient \(\nabla f_i\) được tính tại một vị trí &lt;strong&gt;khác nhau&lt;/strong&gt; \(x^{(k+i-1)}\), thay vì cùng tính tại điểm đầu \(x^{(k)}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Độ lệch giữa hướng cập nhật của SGD và Batch GD&lt;/strong&gt;:
\(\sum_{i=1}^{m}[ \nabla f_i (x^{(k+i-1)}) - \nabla f_i (x^{(k)})]\)&lt;/p&gt;

&lt;p&gt;Biểu thức này đo mức độ sai lệch của quỹ đạo SGD so với bước cập nhật của batch GD. Nếu các hàm thành phần biến thiên chậm cục bộ (gradient liên tục Lipschitz), độ lệch này nhỏ và SGD hành xử gần với batch GD.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-cụ-thể-với-m--3-hàm-thành-phần&quot;&gt;Ví dụ Cụ thể với \(m = 3\) Hàm Thành phần&lt;/h3&gt;

&lt;p&gt;Xét trường hợp \(m = 3\) để thấy rõ sự khác biệt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điểm xuất phát:&lt;/strong&gt; \(x^{(k)} = [1, 2]\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm cụ thể (để kiểm tra bằng số):&lt;/strong&gt; khớp đường thẳng \(y \approx w s + c\) qua ba điểm \((s_i, y_i) = (0, 1), (1, 3), (2, 2)\). Với \(x = [w, c]\), đặt
\(f_i(x) = \tfrac{1}{2}(w s_i + c - y_i)^2, \qquad \nabla f_i(x) = (w s_i + c - y_i)\,[s_i, 1].\)
Tại \(x^{(k)} = [1, 2]\): \(\nabla f_1 = [0, 1]\), \(\nabla f_2 = [0, 0]\), \(\nabla f_3 = [4, 2]\) và \(f(x^{(k)}) = 2.5\). Nghiệm tối ưu là \(x^\star = [0.5, 1.5]\) với \(f(x^\star) = 0.75\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quá trình SGD theo quy tắc tuần hoàn:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Dùng \(f_1\)&lt;/strong&gt;: Tính \(\nabla f_1(x^{(k)}) = \nabla f_1([1,2])\), cập nhật:
\(x^{(k+1)} = x^{(k)} - t_k \nabla f_1(x^{(k)}) = [1,2] - t_k \nabla f_1([1,2])\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng \(f_2\)&lt;/strong&gt;: Tính \(\nabla f_2(x^{(k+1)})\) tại vị trí &lt;strong&gt;mới&lt;/strong&gt;, cập nhật:
\(x^{(k+2)} = x^{(k+1)} - t_k \nabla f_2(x^{(k+1)})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng \(f_3\)&lt;/strong&gt;: Tính \(\nabla f_3(x^{(k+2)})\) tại vị trí &lt;strong&gt;mới nhất&lt;/strong&gt;, cập nhật:
\(x^{(k+3)} = x^{(k+2)} - t_k \nabla f_3(x^{(k+2)})\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Kết quả SGD sau một epoch:&lt;/strong&gt;
\(x^{(k+3)} = x^{(k)} - t_k[\nabla f_1(x^{(k)}) + \nabla f_2(x^{(k+1)}) + \nabla f_3(x^{(k+2)})]\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So sánh với Batch GD:&lt;/strong&gt;
\(x^{(k+1)} = x^{(k)} - t_k[\nabla f_1(x^{(k)}) + \nabla f_2(x^{(k)}) + \nabla f_3(x^{(k)})]\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Với các hàm cụ thể ở trên và \(t_k = 0.15\):&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Bước&lt;/th&gt;
      &lt;th&gt;Gradient dùng&lt;/th&gt;
      &lt;th&gt;Điểm mới&lt;/th&gt;
      &lt;th&gt;\(f\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Batch GD&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;\([4, 3]\) (tổng tại \([1, 2]\))&lt;/td&gt;
      &lt;td&gt;\([0.4, 1.55]\)&lt;/td&gt;
      &lt;td&gt;0.76375&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SGD&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;\(\nabla f_1([1, 2]) = [0, 1]\)&lt;/td&gt;
      &lt;td&gt;\([1, 1.85]\)&lt;/td&gt;
      &lt;td&gt;2.08375&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SGD&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;\(\nabla f_2([1, 1.85]) = [-0.15, -0.15]\)&lt;/td&gt;
      &lt;td&gt;\([1.0225, 1.8725]\)&lt;/td&gt;
      &lt;td&gt;2.2245&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SGD&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;\(\nabla f_3([1.0225, 1.8725]) = [3.835, 1.9175]\)&lt;/td&gt;
      &lt;td&gt;\([0.44725, 1.584875]\)&lt;/td&gt;
      &lt;td&gt;0.7543&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Tổng các gradient SGD đã dùng là \([3.685, 2.7675]\) thay vì \([4, 3]\). Hiệu \([-0.315, -0.2325]\) chính là độ lệch ở công thức trên. Để ý rằng bước 2 làm \(f\) &lt;em&gt;tăng&lt;/em&gt;: gradient của một hàm \(f_i\) không phải lúc nào cũng là hướng giảm của cả tổng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sự khác biệt then chốt:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Batch GD&lt;/strong&gt;: Toàn bộ gradient được tính tại &lt;strong&gt;cùng một điểm&lt;/strong&gt; \(x^{(k)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SGD&lt;/strong&gt;: Mỗi gradient được tính tại một điểm &lt;strong&gt;cập nhật liên tiếp&lt;/strong&gt; dọc theo quỹ đạo tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vì vậy, SGD thường giảm mất mát rất nhanh ở giai đoạn đầu nhưng dao động nhiều hơn khi tiến gần tới điểm cực tiểu.&lt;/p&gt;

&lt;h3 id=&quot;tính-chất-hội-tụ&quot;&gt;Tính chất Hội tụ&lt;/h3&gt;

&lt;div id=&quot;convergence-analysis&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 20px;&quot;&gt;
        &lt;div style=&quot;border: 1px solid #ddd; padding: 15px; border-radius: 5px;&quot;&gt;
            &lt;h4&gt;Batch Gradient Descent&lt;/h4&gt;
            &lt;ul&gt;
                &lt;li&gt;&lt;strong&gt;Hướng di chuyển&lt;/strong&gt;: Luôn theo hướng giảm dốc nhất chính xác&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Hội tụ&lt;/strong&gt;: Mượt mà, giảm đơn điệu&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Tốc độ&lt;/strong&gt;: Chậm hơn trên mỗi epoch, nhưng ổn định&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Bộ nhớ&lt;/strong&gt;: Cần nạp toàn bộ tập dữ liệu để tính gradient đầy đủ&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/div&gt;
        &lt;div style=&quot;border: 1px solid #ddd; padding: 15px; border-radius: 5px;&quot;&gt;
            &lt;h4&gt;Gradient Descent ngẫu nhiên (SGD)&lt;/h4&gt;
            &lt;ul&gt;
                &lt;li&gt;&lt;strong&gt;Hướng di chuyển&lt;/strong&gt;: Có nhiễu, xấp xỉ hướng giảm&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Hội tụ&lt;/strong&gt;: Có dao động, nhưng tiến triển nhanh ở giai đoạn đầu&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Tốc độ&lt;/strong&gt;: Nhanh hơn rõ rệt trên mỗi epoch với tập dữ liệu lớn&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Bộ nhớ&lt;/strong&gt;: Chỉ cần xử lý từng mẫu một&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;đảm-bảo-lý-thuyết&quot;&gt;Đảm bảo Lý thuyết&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện liên tục Lipschitz&lt;/strong&gt;: Nếu mỗi \(\nabla f_i(x)\) liên tục Lipschitz với hằng số \(L\):
\(\|\nabla f_i(x) - \nabla f_i(y)\| \leq L \|x - y\|\)&lt;/p&gt;

&lt;p&gt;thì SGD hội tụ về cùng nghiệm tối ưu với batch GD khi tốc độ học thỏa mãn các điều kiện giảm dần phù hợp.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quan sát thực tế&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;SGD hoạt động hiệu quả trong &lt;strong&gt;giai đoạn đầu&lt;/strong&gt; (khi còn ở xa nghiệm tối ưu).&lt;/li&gt;
  &lt;li&gt;SGD gặp khó khăn hơn trong &lt;strong&gt;giai đoạn tinh chỉnh&lt;/strong&gt; (khi ở gần nghiệm tối ưu) do nhiễu gradient.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-batch-gradient-descent-dung-hòa-hai-phương-pháp&quot;&gt;Mini-Batch Gradient Descent: Dung hòa Hai Phương pháp&lt;/h2&gt;

&lt;p&gt;Một phương án trung gian giữa batch GD và SGD là sử dụng các &lt;strong&gt;mini-batch&lt;/strong&gt; kích thước \(b\):&lt;/p&gt;

\[x^{(k)} = x^{(k-1)} - t_k \cdot \frac{1}{b} \sum_{i \in \mathcal{B}_k} \nabla f_i (x^{(k-1)})\]

&lt;p&gt;trong đó \(\mathcal{B}_k\) là tập con gồm \(b\) chỉ số được chọn ngẫu nhiên.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tổng hay trung bình?&lt;/strong&gt; Ở trên, batch GD dùng &lt;strong&gt;tổng&lt;/strong&gt; \(\sum_{i=1}^m \nabla f_i\), tức gradient của \(f = \sum_i f_i\). Công thức mini-batch dùng &lt;strong&gt;trung bình&lt;/strong&gt; trên \(b\) chỉ số. Đây là ước lượng không chệch của gradient trung bình \(\frac{1}{m}\sum_{i=1}^m \nabla f_i\), cách viết quen thuộc trong học máy khi ta cực tiểu hóa mất mát trung bình. Hai cách viết chỉ khác nhau một hằng số, và hằng số này được gộp vào kích thước bước. Nếu muốn ước lượng tổng thì dùng \(\frac{m}{b}\sum_{i \in \mathcal{B}_k} \nabla f_i\). Với \(b = m\) và cách viết trung bình, mini-batch GD chính là batch GD với bước \(t_k/m\).&lt;/p&gt;

&lt;div id=&quot;minibatch-comparison&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;h4&gt;So sánh: Batch GD, Mini-batch GD và SGD&lt;/h4&gt;
    &lt;table style=&quot;width: 100%; border-collapse: collapse; margin: 15px 0;&quot;&gt;
        &lt;thead&gt;
            &lt;tr style=&quot;background-color: #f5f5f5;&quot;&gt;
                &lt;th style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Phương pháp&lt;/th&gt;
                &lt;th style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Kích thước lô (Batch Size)&lt;/th&gt;
                &lt;th style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Chi phí / Cập nhật&lt;/th&gt;
                &lt;th style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Hành vi hội tụ&lt;/th&gt;
                &lt;th style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Mức dùng bộ nhớ&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;tr&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;&lt;strong&gt;Batch GD&lt;/strong&gt;&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;$$m$$ (toàn bộ tập dữ liệu)&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;$$O(m)$$&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Mượt, ổn định&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Cao&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;&lt;strong&gt;Mini-batch GD&lt;/strong&gt;&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;$$b$$ (thường 32–256)&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;$$O(b)$$&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Cân bằng&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Trung bình&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;&lt;strong&gt;SGD&lt;/strong&gt;&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;1&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;$$O(1)$$&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Nhanh nhưng nhiều nhiễu&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Thấp&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/tbody&gt;
    &lt;/table&gt;
&lt;/div&gt;

&lt;h2 id=&quot;tổng-kết-và-kinh-nghiệm-thực-hành&quot;&gt;Tổng kết và Kinh nghiệm Thực hành&lt;/h2&gt;

&lt;h3 id=&quot;khi-nào-nên-dùng-sgd&quot;&gt;Khi nào nên dùng SGD&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tập dữ liệu lớn&lt;/strong&gt; (hàng triệu mẫu).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán học trực tuyến (online learning)&lt;/strong&gt; khi dữ liệu đến theo luồng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Môi trường hạn chế bộ nhớ&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giai đoạn huấn luyện đầu&lt;/strong&gt; cần giảm nhanh hàm mất mát.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;khi-nào-nên-dùng-batch-gd&quot;&gt;Khi nào nên dùng Batch GD&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tập dữ liệu nhỏ đến trung bình&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Yêu cầu độ chính xác nghiệm cao&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cần quỹ đạo hội tụ ổn định, không nhiễu&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giai đoạn tinh chỉnh cuối&lt;/strong&gt; sau khi đã tiến gần nghiệm.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;thực-hành-khuyến-nghị&quot;&gt;Thực hành Khuyến nghị&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lập lịch tốc độ học&lt;/strong&gt;: Bắt đầu với bước lớn vừa phải rồi giảm dần theo thời gian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xáo trộn dữ liệu&lt;/strong&gt;: Đảo ngẫu nhiên thứ tự mẫu trước mỗi epoch.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mini-batch&lt;/strong&gt;: Thường là lựa chọn thực tế tốt nhất nhờ tận dụng tính toán song song trên phần cứng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Momentum&lt;/strong&gt;: Giúp SGD giảm dao động do nhiễu và tăng tốc hội tụ.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trong thực tế hiện đại&lt;/strong&gt;: Hầu hết các thư viện học sâu đều sử dụng mini-batch SGD kết hợp với các thuật toán tối ưu thích ứng (như Adam, RMSprop) để tự động điều chỉnh tốc độ học cho từng tham số.&lt;/p&gt;

&lt;script&gt;
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    // Global variables for demos
    let gdData = [], sgdData = [];
    let gdPosition = [2, 2], sgdPosition = [2, 2];
    let isRunning = false;
    let isPaused = false;
    let isManualMode = false;
    let animationId;
    let currentAlgorithm = null; // &apos;gd&apos; or &apos;sgd&apos;
    let algorithmState = {
        gd: { iteration: 0, position: [2, 2], path: [], functions: [], totalCost: 0, gradient: [0, 0] },
        sgd: { iteration: 0, position: [2, 2], path: [], functions: [], totalCost: 0, gradient: [0, 0], selectedFunc: -1 }
    };
    
    // Initialize sliders
    const learningRateSlider = document.getElementById(&apos;learning-rate&apos;);
    const numFunctionsSlider = document.getElementById(&apos;num-functions&apos;);
    const animationSpeedSlider = document.getElementById(&apos;animation-speed&apos;);
    const lrValue = document.getElementById(&apos;lr-value&apos;);
    const mValue = document.getElementById(&apos;m-value&apos;);
    const speedValue = document.getElementById(&apos;speed-value&apos;);
    
    if (learningRateSlider) {
        learningRateSlider.addEventListener(&apos;input&apos;, function() {
            lrValue.textContent = this.value;
        });
    }
    
    if (numFunctionsSlider) {
        numFunctionsSlider.addEventListener(&apos;input&apos;, function() {
            mValue.textContent = this.value;
        });
    }
    
    if (animationSpeedSlider) {
        animationSpeedSlider.addEventListener(&apos;input&apos;, function() {
            speedValue.textContent = this.value;
        });
    }
    
    // Execution mode radio buttons
    const execModeRadios = document.querySelectorAll(&apos;input[name=&quot;exec-mode&quot;]&apos;);
    execModeRadios.forEach(radio =&gt; {
        radio.addEventListener(&apos;change&apos;, function() {
            isManualMode = this.value === &apos;manual&apos;;
            updateControlButtons();
        });
    });
    
    // Simple quadratic functions for demonstration
    function createFunctions(m) {
        const functions = [];
        for (let i = 0; i &lt; m; i++) {
            const centerX = (Math.random() - 0.5) * 4;
            const centerY = (Math.random() - 0.5) * 4;
            functions.push({
                center: [centerX, centerY],
                gradient: function(x, y) {
                    return [2 * (x - centerX), 2 * (y - centerY)];
                },
                value: function(x, y) {
                    return (x - centerX) ** 2 + (y - centerY) ** 2;
                }
            });
        }
        return functions;
    }
    
    // Setup SVG plots
    function setupPlot(svgId, width = 300, height = 300) {
        const svg = d3.select(`#${svgId}`);
        if (svg.empty()) return null;
        
        svg.selectAll(&quot;*&quot;).remove();
        
        const margin = {top: 20, right: 20, bottom: 30, left: 40};
        const plotWidth = width - margin.left - margin.right;
        const plotHeight = height - margin.top - margin.bottom;
        
        const xScale = d3.scaleLinear()
            .domain([-3, 3])
            .range([0, plotWidth]);
            
        const yScale = d3.scaleLinear()
            .domain([-3, 3])
            .range([plotHeight, 0]);
        
        const g = svg.append(&quot;g&quot;)
            .attr(&quot;transform&quot;, `translate(${margin.left},${margin.top})`);
        
        // Add axes
        g.append(&quot;g&quot;)
            .attr(&quot;transform&quot;, `translate(0,${plotHeight})`)
            .call(d3.axisBottom(xScale));
            
        g.append(&quot;g&quot;)
            .call(d3.axisLeft(yScale));
        
        // Add contour background
        const contourData = [];
        for (let i = 0; i &lt; 20; i++) {
            for (let j = 0; j &lt; 20; j++) {
                const x = -3 + (i / 19) * 6;
                const y = -3 + (j / 19) * 6;
                contourData.push({x, y, z: x*x + y*y});
            }
        }
        
        return {svg, g, xScale, yScale, plotWidth, plotHeight};
    }
    
    // Control button functions
    function updateControlButtons() {
        const pauseResumeBtn = document.getElementById(&apos;pause-resume&apos;);
        const stepForwardBtn = document.getElementById(&apos;step-forward&apos;);
        
        if (pauseResumeBtn) {
            pauseResumeBtn.disabled = !isRunning;
            pauseResumeBtn.textContent = isPaused ? &apos;Tiếp tục&apos; : &apos;Tạm dừng&apos;;
        }
        
        if (stepForwardBtn) {
            stepForwardBtn.disabled = !isManualMode &amp;&amp; !isPaused;
        }
    }
    
    // GD vs SGD Comparison Demo
    const startGDBtn = document.getElementById(&apos;start-gd&apos;);
    const startSGDBtn = document.getElementById(&apos;start-sgd&apos;);
    const pauseResumeBtn = document.getElementById(&apos;pause-resume&apos;);
    const stepForwardBtn = document.getElementById(&apos;step-forward&apos;);
    const resetBtn = document.getElementById(&apos;reset-demo&apos;);
    
    if (startGDBtn) {
        startGDBtn.addEventListener(&apos;click&apos;, function() {
            if (isRunning &amp;&amp; currentAlgorithm === &apos;gd&apos;) return;
            initializeAlgorithm(&apos;gd&apos;);
            if (!isManualMode) {
                runAlgorithm(&apos;gd&apos;);
            }
        });
    }
    
    if (startSGDBtn) {
        startSGDBtn.addEventListener(&apos;click&apos;, function() {
            if (isRunning &amp;&amp; currentAlgorithm === &apos;sgd&apos;) return;
            initializeAlgorithm(&apos;sgd&apos;);
            if (!isManualMode) {
                runAlgorithm(&apos;sgd&apos;);
            }
        });
    }
    
    if (pauseResumeBtn) {
        pauseResumeBtn.addEventListener(&apos;click&apos;, function() {
            if (isPaused) {
                isPaused = false;
                if (currentAlgorithm) {
                    runAlgorithm(currentAlgorithm);
                }
            } else {
                isPaused = true;
                if (animationId) {
                    cancelAnimationFrame(animationId);
                }
            }
            updateControlButtons();
        });
    }
    
    if (stepForwardBtn) {
        stepForwardBtn.addEventListener(&apos;click&apos;, function() {
            if (currentAlgorithm &amp;&amp; (isManualMode || isPaused)) {
                performSingleStep(currentAlgorithm);
            }
        });
    }
    
    if (resetBtn) {
        resetBtn.addEventListener(&apos;click&apos;, function() {
            resetDemo();
        });
    }
    
    // Initialize algorithm state
    function initializeAlgorithm(algorithm) {
        const m = parseInt(numFunctionsSlider.value);
        const functions = createFunctions(m);
        
        algorithmState[algorithm] = {
            iteration: 0,
            position: [2, 2],
            path: [[2, 2]],
            functions: functions,
            totalCost: 0,
            gradient: [0, 0],
            selectedFunc: algorithm === &apos;sgd&apos; ? -1 : undefined
        };
        
        currentAlgorithm = algorithm;
        isRunning = true;
        isPaused = false;
        
        // Setup plot
        const plotId = algorithm === &apos;gd&apos; ? &apos;gd-plot&apos; : &apos;sgd-plot&apos;;
        const plot = setupPlot(plotId, 350, 350);
        
        // Update status
        updateAlgorithmDisplay(algorithm);
        updateControlButtons();
        
        // Update detailed info
        const detailedInfoId = algorithm === &apos;gd&apos; ? &apos;gd-detailed-info&apos; : &apos;sgd-detailed-info&apos;;
        document.getElementById(detailedInfoId).textContent = 
            isManualMode ? &apos;Sẵn sàng chạy từng bước&apos; : &apos;Đang tự động chạy...&apos;;
    }
    
    // Run algorithm in auto mode
    function runAlgorithm(algorithm) {
        if (isPaused || isManualMode) return;
        
        const speed = parseInt(animationSpeedSlider.value);
        const delay = 1100 - speed * 100; // Convert speed to delay (higher speed = lower delay)
        
        function step() {
            if (isPaused || !isRunning) return;
            
            const shouldContinue = performSingleStep(algorithm);
            
            if (shouldContinue &amp;&amp; !isPaused) {
                setTimeout(() =&gt; {
                    animationId = requestAnimationFrame(step);
                }, delay);
            } else {
                isRunning = false;
                updateControlButtons();
                
                const detailedInfoId = algorithm === &apos;gd&apos; ? &apos;gd-detailed-info&apos; : &apos;sgd-detailed-info&apos;;
                document.getElementById(detailedInfoId).textContent = &apos;Đã hội tụ!&apos;;
            }
        }
        
        step();
    }
    
    // Perform a single step of the algorithm
    function performSingleStep(algorithm) {
        const state = algorithmState[algorithm];
        const lr = parseFloat(learningRateSlider.value);
        
        if (algorithm === &apos;gd&apos;) {
            return performGDStep(state, lr);
        } else {
            return performSGDStep(state, lr);
        }
    }
    
    function performGDStep(state, lr) {
        // Compute full gradient (sum of all function gradients)
        let gradX = 0, gradY = 0;
        for (const func of state.functions) {
            const grad = func.gradient(state.position[0], state.position[1]);
            gradX += grad[0];
            gradY += grad[1];
        }
        
        // Average the gradients
        gradX /= state.functions.length;
        gradY /= state.functions.length;
        
        state.gradient = [gradX, gradY];
        
        // Update position
        state.position[0] -= lr * gradX;
        state.position[1] -= lr * gradY;
        state.path.push(state.position.slice());
        
        // Compute total cost
        state.totalCost = 0;
        for (const func of state.functions) {
            state.totalCost += func.value(state.position[0], state.position[1]);
        }
        state.totalCost /= state.functions.length;
        
        state.iteration++;
        
        // Update visualization
        updateAlgorithmDisplay(&apos;gd&apos;);
        
        // Check convergence
        const gradientMagnitude = Math.sqrt(gradX * gradX + gradY * gradY);
        return state.iteration &lt; 100 &amp;&amp; gradientMagnitude &gt; 0.01;
    }
    
    function performSGDStep(state, lr) {
        // Select random function
        const funcIndex = Math.floor(Math.random() * state.functions.length);
        const func = state.functions[funcIndex];
        state.selectedFunc = funcIndex;
        
        // Compute gradient for selected function only
        const grad = func.gradient(state.position[0], state.position[1]);
        state.gradient = grad;
        
        // Update position
        state.position[0] -= lr * grad[0];
        state.position[1] -= lr * grad[1];
        state.path.push(state.position.slice());
        
        // Compute total cost
        state.totalCost = 0;
        for (const func of state.functions) {
            state.totalCost += func.value(state.position[0], state.position[1]);
        }
        state.totalCost /= state.functions.length;
        
        state.iteration++;
        
        // Update visualization
        updateAlgorithmDisplay(&apos;sgd&apos;);
        
        // Check convergence (SGD needs more iterations)
        return state.iteration &lt; 300 &amp;&amp; state.totalCost &gt; 0.01;
    }
    
    function updateAlgorithmDisplay(algorithm) {
        const state = algorithmState[algorithm];
        const plotId = algorithm === &apos;gd&apos; ? &apos;gd-plot&apos; : &apos;sgd-plot&apos;;
        const color = algorithm === &apos;gd&apos; ? &apos;steelblue&apos; : &apos;orange&apos;;
        
        // Update path visualization
        const plot = {
            svg: d3.select(`#${plotId}`),
            g: d3.select(`#${plotId} g`),
            xScale: d3.scaleLinear().domain([-3, 3]).range([0, 270]),
            yScale: d3.scaleLinear().domain([-3, 3]).range([270, 0])
        };
        
        if (!plot.g.empty()) {
            updatePath(plot, state.path, color);
        }
        
        // Update info displays
        const infoId = algorithm === &apos;gd&apos; ? &apos;gd-info&apos; : &apos;sgd-info&apos;;
        const gradientInfoId = algorithm === &apos;gd&apos; ? &apos;gd-gradient-info&apos; : &apos;sgd-gradient-info&apos;;
        
        document.getElementById(infoId).textContent = 
            `Số vòng lặp: ${state.iteration}, Chi phí: ${state.totalCost.toFixed(4)}`;
        
        if (algorithm === &apos;gd&apos;) {
            document.getElementById(gradientInfoId).textContent = 
                `Gradient: [${state.gradient[0].toFixed(3)}, ${state.gradient[1].toFixed(3)}]`;
        } else {
            document.getElementById(gradientInfoId).textContent = 
                `Hàm được chọn: f${state.selectedFunc + 1}, Gradient: [${state.gradient[0].toFixed(3)}, ${state.gradient[1].toFixed(3)}]`;
        }
        
        // Update progress bar
        const progressId = algorithm === &apos;gd&apos; ? &apos;gd-progress&apos; : &apos;sgd-progress&apos;;
        const maxIterations = algorithm === &apos;gd&apos; ? 100 : 300;
        const progress = Math.min((state.iteration / maxIterations) * 100, 100);
        document.getElementById(progressId).style.width = `${progress}%`;
        
        // Update detailed status
        const detailedInfoId = algorithm === &apos;gd&apos; ? &apos;gd-detailed-info&apos; : &apos;sgd-detailed-info&apos;;
        const gradMagnitude = Math.sqrt(state.gradient[0] ** 2 + state.gradient[1] ** 2);
        document.getElementById(detailedInfoId).textContent = 
            `Bước ${state.iteration}: Vị trí [${state.position[0].toFixed(3)}, ${state.position[1].toFixed(3)}], |∇| = ${gradMagnitude.toFixed(4)}`;
    }
    
    function updatePath(plot, path, color) {
        const line = d3.line()
            .x(d =&gt; plot.xScale(d[0]))
            .y(d =&gt; plot.yScale(d[1]));
        
        plot.g.selectAll(&apos;.path&apos;).remove();
        plot.g.append(&apos;path&apos;)
            .datum(path)
            .attr(&apos;class&apos;, &apos;path&apos;)
            .attr(&apos;fill&apos;, &apos;none&apos;)
            .attr(&apos;stroke&apos;, color)
            .attr(&apos;stroke-width&apos;, 2)
            .attr(&apos;d&apos;, line);
        
        // Add current position
        const current = path[path.length - 1];
        plot.g.selectAll(&apos;.current-pos&apos;).remove();
        plot.g.append(&apos;circle&apos;)
            .attr(&apos;class&apos;, &apos;current-pos&apos;)
            .attr(&apos;cx&apos;, plot.xScale(current[0]))
            .attr(&apos;cy&apos;, plot.yScale(current[1]))
            .attr(&apos;r&apos;, 5)
            .attr(&apos;fill&apos;, color);
    }
    
    function resetDemo() {
        if (animationId) {
            cancelAnimationFrame(animationId);
        }
        
        isRunning = false;
        isPaused = false;
        currentAlgorithm = null;
        
        // Reset algorithm states
        algorithmState = {
            gd: { iteration: 0, position: [2, 2], path: [], functions: [], totalCost: 0, gradient: [0, 0] },
            sgd: { iteration: 0, position: [2, 2], path: [], functions: [], totalCost: 0, gradient: [0, 0], selectedFunc: -1 }
        };
        
        // Clear plots
        d3.select(&apos;#gd-plot&apos;).selectAll(&quot;*&quot;).remove();
        d3.select(&apos;#sgd-plot&apos;).selectAll(&quot;*&quot;).remove();
        
        // Reset info displays
        document.getElementById(&apos;gd-info&apos;).textContent = &apos;Số vòng lặp: 0, Chi phí: 0&apos;;
        document.getElementById(&apos;sgd-info&apos;).textContent = &apos;Số vòng lặp: 0, Chi phí: 0&apos;;
        document.getElementById(&apos;gd-gradient-info&apos;).textContent = &apos;Gradient: [0, 0]&apos;;
        document.getElementById(&apos;sgd-gradient-info&apos;).textContent = &apos;Hàm được chọn: -, Gradient: [0, 0]&apos;;
        
        // Reset detailed info
        document.getElementById(&apos;gd-detailed-info&apos;).textContent = &apos;Sẵn sàng&apos;;
        document.getElementById(&apos;sgd-detailed-info&apos;).textContent = &apos;Sẵn sàng&apos;;
        
        // Reset progress bars
        document.getElementById(&apos;gd-progress&apos;).style.width = &apos;0%&apos;;
        document.getElementById(&apos;sgd-progress&apos;).style.width = &apos;0%&apos;;
        
        // Update control buttons
        updateControlButtons();
    }
    
});
&lt;/script&gt;

&lt;h3 id=&quot;sgd-và-minibatch-trong-khoảng-3-phút&quot;&gt;SGD và minibatch trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/sgd-minibatch_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Ví dụ m = 3 điểm: một bước GD so với một epoch SGD, bước hằng so với bước giảm dần, rồi ảnh hưởng của kích thước batch.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-04 Gradient boosting</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_04_gradient_boosting/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_04_gradient_boosting</id>
   <content type="html">&lt;p&gt;Trong các cuộc thi dữ liệu dạng bảng (tabular data) như Kaggle, hay trong các hệ thống chấm điểm tín dụng, xếp hạng tìm kiếm và dự báo nhu cầu của các tập đoàn công nghệ lớn, thuật toán thống trị suốt nhiều năm qua không phải mạng nơ-ron sâu mà là &lt;strong&gt;XGBoost, LightGBM và CatBoost&lt;/strong&gt; — tất cả đều là con đẻ của &lt;strong&gt;Gradient Boosting&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Điều thú vị đến bất ngờ là: Gradient Boosting thực chất chính là &lt;strong&gt;Gradient Descent&lt;/strong&gt;, nhưng không chạy trong không gian tham số \(\mathbb{R}^p\) mà chạy trực tiếp trong &lt;strong&gt;không gian các hàm số&lt;/strong&gt;! Ở mỗi bước lặp, thay vì cập nhật một vector trọng số \(w \leftarrow w - \eta \nabla L(w)\), ta cộng thêm một cây quyết định nhỏ \(h_m(x)\) được huấn luyện để xấp xỉ đúng &lt;strong&gt;âm gradient (pseudo-residual)&lt;/strong&gt; của hàm mất mát hiện tại!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-gradient-descent-trong-mathbbrp-sang-không-gian-hàm&quot;&gt;Kiến thức cần nhớ: Từ Gradient Descent trong \(\mathbb{R}^p\) sang Không gian Hàm&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau làm sáng tỏ bản chất tối ưu hóa của Gradient Boosting:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Hạ Gradient trong Không gian Hàm (Functional Gradient Descent):&lt;/strong&gt; Coi bộ dự đoán hiện tại \(F = (F(x_1), \dots, F(x_n))\) như một điểm trong \(\mathbb{R}^n\). Hướng giảm nhanh nhất cho hàm mất mát \(\sum_{i=1}^n L(y_i, F(x_i))\) chính là vector âm gradient $$r_i^{(m)} = -\left.\frac{\partial L(y_i, F)}{\partial F}\right&lt;/td&gt;
          &lt;td&gt;&lt;em&gt;{F = F&lt;/em&gt;{m-1}(x_i)}$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pseudo-Residual (Phần dư giả):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với hàm mất mát bình phương \(L(y, F) = \frac{1}{2}(y - F)^2\): âm gradient chính là phần dư thông thường \(r_i = y_i - F(x_i)\)!&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Với hàm mất mát trị tuyệt đối $$L(y, F) =&lt;/td&gt;
              &lt;td&gt;y - F&lt;/td&gt;
              &lt;td&gt;\(: âm gradient là\)\operatorname{sign}(y_i - F(x_i))$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Với hàm mất mát Cross-Entropy (phân loại): âm gradient là \(y_i - \hat{p}_i\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khớp cây yếu &amp;amp; Tốc độ học (Shrinkage \(\eta\)):&lt;/strong&gt; Vì không thể lưu riêng từng số \(r_i\) cho dữ liệu mới chưa gặp, ta huấn luyện một cây quyết định nông \(h_m(x)\) khớp với \(r_i^{(m)}\), rồi cập nhật \(F_m(x) = F_{m-1}(x) + \eta h_m(x)\). Hệ số \(\eta \in (0, 1)\) đóng vai trò hệt như tốc độ học trong GD để chống quá khớp!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-chạy-2-vòng-lặp-gradient-boosting-cho-bài-toán-hồi-quy-3-mẫu&quot;&gt;Giải thích: Tự tay chạy 2 vòng lặp Gradient Boosting cho bài toán hồi quy 3 mẫu&lt;/h3&gt;

&lt;p&gt;Cho 3 mẫu dữ liệu \((x_i, y_i)\): \((1, 10),\; (2, 12),\; (3, 20)\), dùng hàm mất mát bình phương \(L(y, F) = \frac{1}{2}(y - F)^2\) và tốc độ học \(\eta = 0.5\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khởi tạo \(F_0(x)\) bằng hằng số tối ưu (trung bình của \(y\)):&lt;/strong&gt;
\(F_0(x) = \frac{10 + 12 + 20}{3} = 14.\)
Tổng sai số bình phương ban đầu: \(\frac{1}{2}[(10-14)^2 + (12-14)^2 + (20-14)^2] = \frac{1}{2}(16 + 4 + 36) = 28\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(m = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tính âm gradient (phần dư) \(r_i^{(1)} = y_i - F_0(x_i)\):
\(r^{(1)} = (10 - 14,\; 12 - 14,\; 20 - 14) = (-4,\; -2,\; +6).\)&lt;/li&gt;
      &lt;li&gt;Huấn luyện cây gốc nông (decision stump) chia tại \(x \le 2.5\):
        &lt;ul&gt;
          &lt;li&gt;Nhánh trái (\(x \le 2.5\)): trung bình của \((-4, -2)\) là \(-3\).&lt;/li&gt;
          &lt;li&gt;Nhánh phải (\(x &amp;gt; 2.5\)): trung bình của \((+6)\) là \(+6\).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Cập nhật \(F_1(x) = F_0(x) + 0.5 h_1(x)\):
\(F_1(1) = 14 + 0.5(-3) = 12.5,\quad F_1(2) = 12.5,\quad F_1(3) = 14 + 0.5(6) = 17.\)&lt;/li&gt;
      &lt;li&gt;Sai số mới: \(\frac{1}{2}[(-2.5)^2 + (-0.5)^2 + (3)^2] = \frac{1}{2}(6.25 + 0.25 + 9) = 7.75\) (giảm từ \(28\) xuống \(7.75\) chỉ sau 1 cây!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng lặp \(m = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Phần dư mới: \(r^{(2)} = (10 - 12.5,\; 12 - 12.5,\; 20 - 17) = (-2.5,\; -0.5,\; +3)\) — nhỏ đi đúng một nửa, và cây tiếp theo lại tiếp tục gọt sạch sai số còn sót lại!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;gradient-boosting&quot;&gt;Gradient boosting&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Gradient boosting&lt;/strong&gt; là phương pháp học tập hợp (ensemble) sử dụng ý tưởng gradient descent để xây dựng các cây quyết định theo trình tự nối tiếp, trong đó mỗi cây mới học cách bù đắp sai số còn lại của các cây trước đó. Phương pháp này có thể áp dụng cho cả bài toán hồi quy và phân lớp.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tham khảo thêm: &lt;a href=&quot;https://medium.com/mlreview/gradient-boosting-from-scratch-1e317ae4587d&quot;&gt;Gradient Boosting from scratch&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tham-khảo-thuật-toán-functional-gradient-descent&quot;&gt;[Tham khảo] Thuật toán Functional Gradient Descent&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Gradient boosting&lt;/strong&gt; được Llew Mason, Jonathan Baxter, Peter Bartlett và Marcus Frean diễn giải như một thuật toán &lt;em&gt;functional gradient descent&lt;/em&gt; (hạ gradient trong không gian hàm). Thuật toán này cực tiểu hóa hàm mất mát trực tiếp trên không gian hàm bằng cách liên tiếp bổ sung các hàm có hướng xấp xỉ hướng ngược chiều gradient.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tham khảo thêm: &lt;a href=&quot;https://en.wikipedia.org/wiki/Gradient_boosting&quot;&gt;Gradient Boosting&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tham-khảo-boosting-và-bagging&quot;&gt;[Tham khảo] Boosting và Bagging&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Boosting&lt;/strong&gt; là kỹ thuật học tập hợp xây dựng các mô hình yếu (weak learner) một cách tuần tự: mỗi mô hình ở giai đoạn sau tập trung khắc phục sai số mà các mô hình trước đó gây ra, rồi kết hợp tất cả thành dự đoán cuối cùng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bagging&lt;/strong&gt; là kỹ thuật học tập hợp huấn luyện các mô hình yếu một cách độc lập và song song trên các tập mẫu con khác nhau, sau đó tổng hợp kết quả của chúng.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tham khảo thêm: &lt;a href=&quot;https://quantdare.com/what-is-the-difference-between-bagging-and-boosting/&quot;&gt;What is the difference between Bagging and Boosting?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ý-tưởng-của-gradient-boosting&quot;&gt;Ý tưởng của Gradient Boosting&lt;/h2&gt;

&lt;p&gt;Hãy xem xét cách bài toán &lt;strong&gt;Gradient Boosting&lt;/strong&gt; được hình thành.&lt;/p&gt;

&lt;p&gt;Giả sử ta có một mô hình tập hợp gồm nhiều cây quyết định nhằm dự đoán đầu ra sao cho cực tiểu hóa sai số so với các giá trị quan sát được. Ký hiệu các giá trị thực là \(y_i\), dữ liệu đầu vào là \(x_i\), và giá trị dự đoán là \(u_i\) với \(i=1,\dots,n\).&lt;/p&gt;

&lt;p&gt;Như minh họa trong hình dưới đây, mỗi cây trong tập hợp nhận đầu vào \(x_i \in \mathbb{R}^p\) và trả về giá trị dự đoán theo các điều kiện phân nhánh tại các nút của cây.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_04_tree_O9zyAlk.png&quot; alt=&quot;tree_O9zyAlk&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig 1] Example of Tree }T_j\text{ [3]}$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Giá trị dự đoán \(u_i\) của mô hình tập hợp là tổng có trọng số đầu ra của các cây (trong đó \(T_j(x_i)\) là đầu ra của cây thứ \(j\) với đầu vào \(x_i\)):&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
u_i = \sum_{j=1}^M \beta_j T_j(x_i)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Chẳng hạn, với hàm mất mát bình phương \(L(y_i, u_i) = (y_i - u_i)^2\), bài toán tối ưu hóa là cực tiểu hóa tổng mất mát trên tập dữ liệu:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{equation}
\min_{\beta} \sum_{i=1}^n L\left(y_i, \sum_{j=1}^M \beta_j T_j(x_i)\right)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong thực tế, các mô hình tập hợp thường sử dụng nhiều cây nhỏ có độ sâu cố định (thường từ 5 trở xuống) để tiết kiệm bộ nhớ, tăng tốc độ dự đoán và cải thiện hiệu năng dần khi tăng số lượng cây.&lt;/p&gt;

&lt;p&gt;Tuy nhiên, do cấu trúc phân nhánh của từng cây rất đa dạng và số lượng cây kết hợp rất lớn, không gian tìm kiếm trở nên khổng lồ, khiến việc tối ưu trực tiếp trở nên rất khó khăn.&lt;/p&gt;

&lt;p&gt;Để giải quyết, ta chuyển bài toán sang một góc nhìn đơn giản hơn: thay vì tối ưu đồng thời \(M\) trọng số \(\beta_j\) và cấu trúc cây, hãy xem đây là bài toán cực tiểu hóa \(\min_{u} f(u)\) theo vector dự đoán \(u \in \mathbb{R}^n\) với \(f(u) = \sum_{i=1}^n L(y_i, u_i)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gradient boosting&lt;/strong&gt; chính là kỹ thuật giải bài toán \(\min_{u} f(u)\) này bằng thuật toán gradient descent trong không gian hàm.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán&quot;&gt;Thuật toán&lt;/h2&gt;

&lt;p&gt;Thuật toán &lt;strong&gt;Gradient boosting&lt;/strong&gt; thực hiện hạ gradient theo từng bước để tìm dự đoán tối ưu \(u^*\) cho \(\min_u L(y, u)\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Khởi tạo dự đoán ban đầu bằng một cây tùy chọn \(u^{(0)} = T_0\), sau đó lặp các bước 2–4 cho \(k = 1, \dots, M\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Tính hướng ngược chiều gradient (pseudo-residual) tại dự đoán hiện tại \(u^{(k-1)}\) cho \(n\) điểm dữ liệu:
    &lt;blockquote&gt;

\[\begin{equation}
d_i = - \left . \left[ \frac{\partial L(y_i,u_i)}{\partial u_i} \right] \right|_{u_i = u_i^{(k-1)}}, \quad i=1,\dots,n
\end{equation}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Tìm cây quyết định \(T_k\) khớp nhất với vector gradient âm \(d\) theo nghĩa bình phương tối thiểu:
    &lt;blockquote&gt;

\[\begin{equation}
\min_{\text{trees } T} \sum_{i=1}^n (d_i - T(x_i))^2
\end{equation}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Chọn kích thước bước \(\alpha_k\) và cập nhật giá trị dự đoán bằng cây \(T_k\) vừa tìm được:
    &lt;blockquote&gt;

\[u^{(k)} = u^{(k-1)} + \alpha_k T_k\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Như vậy, ở mỗi vòng lặp, thuật toán tính hướng giảm \(d\) theo \(u\), xấp xỉ \(d\) bằng một cây \(T_k\), rồi dùng \(T_k\) thay cho gradient trong bước cập nhật.&lt;/p&gt;

&lt;p&gt;Khi khai triển ngược công thức truy hồi \(u^{(k)} = u^{(k-1)} + \alpha_k T_k\) về \(k = 0\), dự đoán cuối cùng có dạng \(u^{(M)} = T_0 + \sum_{k=1}^M \alpha_k T_k\), hoàn toàn khớp với dạng tổng có trọng số các cây quyết định đã định nghĩa ở trên.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03 Phân tích hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_convergence_analysis/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_convergence_analysis</id>
   <content type="html">&lt;p&gt;Một thuật toán nhìn trên đồ thị có vẻ đang giảm dần giá trị hàm mất mát, nhưng làm sao ta biết chắc nó sẽ thực sự chạm tới \(f^\star\) chứ không dừng lơ lửng giữa chừng? Và quan trọng hơn: muốn giảm sai số từ \(10^{-2}\) xuống \(10^{-6}\), ta cần thêm bao nhiêu vòng lặp — gấp 10 lần, gấp 10.000 lần, hay chỉ gấp 3 lần?&lt;/p&gt;

&lt;p&gt;Mục 06-03 mở ra &lt;strong&gt;Phân tích hội tụ (Convergence Analysis)&lt;/strong&gt; — phần toán học sâu sắc nhất của Chương 06. Bạn sẽ chứng kiến sự khác biệt một trời một vực giữa hai thế giới: hàm &lt;strong&gt;lồi trơn&lt;/strong&gt; (hội tụ dưới tuyến tính \(O(1/k)\) — cần \(O(1/\epsilon)\) bước) và hàm &lt;strong&gt;lồi mạnh &amp;amp; trơn&lt;/strong&gt; (hội tụ tuyến tính \(O(c^k)\) — chỉ cần \(O(\log(1/\epsilon))\) bước), đồng thời hiểu giới hạn tự nhiên của mọi thuật toán bậc nhất qua Định lý Nesterov!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-tầng-phân-tích-tốc-độ-hội-tụ&quot;&gt;Kiến thức cần nhớ: Bốn tầng phân tích tốc độ hội tụ&lt;/h2&gt;

&lt;p&gt;Toàn bộ phần 06-03 được xây dựng theo một chuỗi suy luận bốn tầng cực kỳ chặt chẽ:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tầng 1 — Vũ khí nền tảng (Cận trên bậc hai / \(L\)-smoothness):&lt;/strong&gt; Giả thiết \(\|\nabla f(x) - \nabla f(y)\|_2 \le L\|x - y\|_2\) cho phép kẹp hàm \(f\) dưới một parabol bậc hai, sinh ra &lt;strong&gt;Bổ đề Giảm (Descent Lemma)&lt;/strong&gt;: mỗi bước GD với \(t \le 1/L\) giảm ít nhất \(\frac{t}{2}\|\nabla f(x)\|_2^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tầng 2 — Hội tụ của hàm lồi trơn (\(O(1/k)\)):&lt;/strong&gt; Kết hợp Bổ đề Giảm với bất đẳng thức lồi bậc nhất và kỹ thuật tổng lồng nhau (telescoping sum) chứng minh \(f(x^{(k)}) - f^\star \le \frac{\|x^{(0)} - x^\star\|_2^2}{2tk}\) cho cả bước cố định lẫn Backtracking!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tầng 3 — Bứt tốc nhờ Lồi mạnh (\(O(c^k)\)):&lt;/strong&gt; Khi hàm có thêm cận dưới bậc hai với độ cong \(m &amp;gt; 0\), sai số giảm theo cấp số nhân với hệ số co \(c = 1 - m/L = 1 - 1/\kappa\) — tức là đạt thêm 1 chữ số chính xác chỉ tốn thêm một số hằng bước lặp!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tầng 4 — Giới hạn lý thuyết &amp;amp; Tăng tốc Nesterov:&lt;/strong&gt; Nesterov chứng minh mọi thuật toán bậc nhất trên hàm lồi \(L\)-trơn đều không thể nhanh hơn \(\Omega(1/k^2)\) — và Gradient Descent thường (\(O(1/k)\)) chưa chạm ngưỡng đó, mở đường cho phương pháp tăng tốc Nesterov!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-trực-quan-số-vòng-lặp-giữa-o1epsilon-và-olog1epsilon&quot;&gt;Giải thích: So sánh trực quan số vòng lặp giữa \(O(1/\epsilon)\) và \(O(\log(1/\epsilon))\)&lt;/h3&gt;

&lt;p&gt;Giả sử bài toán có hằng số trơn \(L = 10\), khoảng cách ban đầu \(\|x^{(0)} - x^\star\|_2 = 1\), và ta cần đạt độ chính xác \(\epsilon\) (tức \(f(x^{(k)}) - f^\star \le \epsilon\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 1 — Chỉ lồi &amp;amp; \(L\)-trơn (tốc độ \(O(1/k)\), cận \(k \approx \frac{L \|x^{(0)} - x^\star\|_2^2}{2\epsilon} = \frac{5}{\epsilon}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Muốn \(\epsilon = 10^{-2}\): cần khoảng \(500\) vòng lặp.&lt;/li&gt;
      &lt;li&gt;Muốn \(\epsilon = 10^{-4}\): cần khoảng \(50\,000\) vòng lặp (tăng &lt;strong&gt;100 lần&lt;/strong&gt;!).&lt;/li&gt;
      &lt;li&gt;Muốn \(\epsilon = 10^{-6}\): cần khoảng \(5\,000\,000\) vòng lặp!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 2 — Lồi mạnh với \(m = 1\) (\(\kappa = L/m = 10\), cận \(k \approx \kappa \ln\frac{f(x^{(0)}) - f^\star}{\epsilon}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(f(x^{(0)}) - f^\star = 5\) và \(\epsilon = 10^{-2}\): \(k \approx 10 \ln(500) \approx 62\) vòng lặp.&lt;/li&gt;
      &lt;li&gt;Muốn \(\epsilon = 10^{-4}\): \(k \approx 10 \ln(50\,000) \approx 108\) vòng lặp (chỉ tăng thêm 46 bước!).&lt;/li&gt;
      &lt;li&gt;Muốn \(\epsilon = 10^{-6}\): \(k \approx 10 \ln(5\,000\,000) \approx 154\) vòng lặp!
&lt;strong&gt;Kết luận sâu sắc:&lt;/strong&gt; Tính lồi mạnh (chẳng hạn nhờ cộng thêm điều chuẩn Ridge \(\frac{\lambda}{2}\|x\|_2^2\)) biến bài toán tốn 5 triệu vòng lặp thành bài toán giải xong trong 154 bước!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong phần này, chúng ta sẽ phân tích tốc độ hội tụ của thuật toán Gradient Descent. Cụ thể, ta sẽ xem xét các cận sai số trong trường hợp dùng kích thước bước cố định, trường hợp dùng tìm kiếm đường lùi (backtracking line search), và trường hợp hàm mục tiêu thỏa mãn điều kiện lồi mạnh.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-06 Can we do better?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_06_can_we_do_better/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_06_can_we_do_better</id>
   <content type="html">&lt;p&gt;Gradient Descent đạt tốc độ \(O(1/k)\) trên hàm lồi \(L\)-trơn và \(O\big((1 - 1/\kappa)^k\big)\) trên hàm lồi mạnh. Đến đây, một câu hỏi đầy tham vọng tự nhiên vang lên: &lt;em&gt;nếu ta chỉ được phép dùng đúng thông tin bậc nhất (giá trị hàm và gradient \(\nabla f\)), liệu ta có thể làm nhanh hơn Gradient Descent không? Và giới hạn tốc độ ánh sáng của mọi thuật toán bậc nhất là bao nhiêu?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Năm 1983, nhà toán học trẻ người Nga Yurii Nesterov đã làm rung chuyển giới tối ưu hóa bằng hai kết quả song sinh: (1) chứng minh &lt;strong&gt;cận dưới bất khả xâm phạm&lt;/strong&gt; \(\Omega(1/k^2)\) cho mọi thuật toán bậc nhất trên hàm lồi \(L\)-trơn, và (2) sáng chế ngay thuật toán &lt;strong&gt;Nesterov Accelerated Gradient (NAG)&lt;/strong&gt; chạm đúng cận tối ưu \(O(1/k^2)\) — chỉ bằng vài phép cộng vector miễn phí!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giới-hạn-thông-tin-bậc-nhất-và-bước-nhảy-nesterov&quot;&gt;Kiến thức cần nhớ: Giới hạn Thông tin Bậc nhất và Bước nhảy Nesterov&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau tóm tắt bước ngoặt lịch sử trong lý thuyết độ phức tạp tối ưu hóa:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình Hộp đen Bậc nhất (First-Order Oracle Model):&lt;/strong&gt; Thuật toán chỉ được phép truy vấn \(\nabla f(x^{(i)})\) và tạo điểm mới \(x^{(k)}\) nằm trong không gian con sinh bởi các gradient đã thấy: \(x^{(k)} \in x^{(0)} + \operatorname{span}\{\nabla f(x^{(0)}), \dots, \nabla f(x^{(k-1)})\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm “Xấu nhất Thế giới” của Nesterov (Worst-Case Quadratic Chain):&lt;/strong&gt; Nesterov xây dựng một hàm bậc hai dạng chuỗi khớp nối \(f(x) = \frac{L}{4}\left[\frac{1}{2}(x_1^2 + \sum (x_i - x_{i+1})^2 + x_n^2) - x_1\right]\) mà sau \(k\) bước truy vấn gradient, mọi thuật toán bậc nhất chỉ có thể “đánh thức” được tối đa \(k\) tọa độ đầu tiên! Từ đó ông chứng minh &lt;strong&gt;không một thuật toán bậc nhất nào&lt;/strong&gt; thắng được cận dưới \(\Omega(L\|x^{(0)} - x^\star\|^2 / k^2)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng trống giữa GD và Cận tối ưu:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hàm lồi \(L\)-trơn: GD tốn \(O(1/\epsilon)\) bước, còn Nesterov tăng tốc chỉ tốn \(O(1/\sqrt{\epsilon})\) bước!&lt;/li&gt;
      &lt;li&gt;Hàm lồi mạnh (\(\kappa = L/m\)): GD tốn \(O(\kappa \log(1/\epsilon))\) bước, còn Nesterov chỉ tốn \(O(\sqrt{\kappa} \log(1/\epsilon))\) bước!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-sức-mạnh-của-o1k-vs-o1k2-và-kappa-vs-sqrtkappa-bằng-con-số-thật&quot;&gt;Giải thích: So sánh sức mạnh của \(O(1/k)\) vs. \(O(1/k^2)\) và \(\kappa\) vs. \(\sqrt{\kappa}\) bằng con số thật&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trên bài toán lồi trơn cần sai số \(\epsilon = 10^{-4}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient Descent thường (\(O(1/\epsilon)\)): cần cỡ \(10\,000\) vòng lặp.&lt;/li&gt;
      &lt;li&gt;Tăng tốc Nesterov (\(O(1/\sqrt{\epsilon})\)): chỉ cần cỡ \(\sqrt{10\,000} = 100\) vòng lặp — &lt;strong&gt;nhanh hơn gấp 100 lần&lt;/strong&gt; với chi phí mỗi vòng lặp gần như bằng nhau!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trên bài toán lồi mạnh điều kiện xấu với \(\kappa = 10\,000\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient Descent thường phụ thuộc \(\kappa = 10\,000\): hệ số co \(1 - 1/10\,000 = 0.9999\).&lt;/li&gt;
      &lt;li&gt;Tăng tốc Nesterov phụ thuộc \(\sqrt{\kappa} = 100\): hệ số co \(1 - 1/100 = 0.99\) — &lt;strong&gt;giảm số vòng lặp đúng 100 lần&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bí quyết đằng sau tốc độ đó:&lt;/strong&gt; Thay vì chỉ đi từ \(x^{(k)}\), Nesterov tạo điểm “nhìn trước” \(y^{(k)} = x^{(k)} + \beta_k (x^{(k)} - x^{(k-1)})\) rồi mới tính gradient tại \(y^{(k)}\) — trực giác của phương pháp &lt;strong&gt;Momentum&lt;/strong&gt; mà ta sẽ khám phá ngay ở các bài sau!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Gradient descent đạt tốc độ hội tụ \(O(1/k)\) (tương ứng cần \(O(1/\epsilon)\) vòng lặp để đạt sai số \(\epsilon\)) đối với các hàm lồi, khả vi và có gradient liên tục Lipschitz. Câu hỏi đặt ra là liệu có phương pháp bậc nhất nào đạt tốc độ hội tụ nhanh hơn gradient descent hay không.&lt;/p&gt;

&lt;h3 id=&quot;phương-pháp-bậc-nhất&quot;&gt;Phương pháp Bậc nhất&lt;/h3&gt;

&lt;p&gt;Một phương pháp bậc nhất tạo ra điểm lặp \(x^{(k)}\) sao cho \(x^{(k)}\) nằm trong không gian tuyến tính sinh bởi các gradient đã tính từ điểm khởi tạo \(x^{(0)}\) đến \(x^{(k-1)}\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x^{(k)} \in x^{(0)} +\) &lt;strong&gt;span&lt;/strong&gt;\(\{\nabla f(x^{(0)}),\nabla f(x^{(1)}),...,\nabla f(x^{(k-1)})\}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;định-lý-nesterov&quot;&gt;Định lý Nesterov&lt;/h3&gt;

&lt;p&gt;Định lý của Nesterov thiết lập một cận dưới cho tốc độ hội tụ tốt nhất có thể của mọi phương pháp bậc nhất.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Định lý Nesterov&lt;/strong&gt;: Với mọi \(k \le (n-1)/2\) và mọi điểm xuất phát \(x^{(0)}\), tồn tại một hàm lồi trơn \(f\) có gradient \(L\)-Lipschitz sao cho mọi phương pháp bậc nhất đều thỏa mãn (với \(n\) là số chiều):&lt;br /&gt;
\begin{align}
f(x^{(k)}) - f^{\star} \ge \frac{3L \lVert x^{(0)} - x^{\star} \rVert_2^2}{32(k + 1)^2}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vì cận dưới trong định lý Nesterov có \(k^2\) ở mẫu số, tốc độ hội tụ tối ưu về mặt lý thuyết của lớp phương pháp bậc nhất là \(O(1/k^2)\), tương ứng chỉ cần \(O(1/\sqrt{\epsilon})\) vòng lặp. Các thuật toán tăng tốc đạt được cận này sẽ được trình bày chi tiết hơn ở các phần sau.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-05 Xem xét điều kiện & Tính thực tiễn</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_05_look_at_the_conditions_and_practicalities/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_05_look_at_the_conditions_and_practicalities</id>
   <content type="html">&lt;p&gt;Định lý hội tụ trên bảng trắng đẹp như mơ, nhưng khi đem vào thực tế lập trình, hàng loạt câu hỏi “trần trụi” lập tức xuất hiện: &lt;em&gt;làm sao biết một bài toán thực tế như Hồi quy tuyến tính có \(L\) và \(m\) bằng bao nhiêu? Nếu số đặc trưng \(p\) lớn hơn số mẫu \(n\) thì tính lồi mạnh có biến mất không? Và vì ta không bao giờ biết trước \(f^\star\), làm sao biết lúc nào nên dừng vòng lặp?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bài học này nối liền lý thuyết hội tụ với kỹ nghệ lập trình tối ưu hóa thực tế: tính cụ thể \(L\) và \(m\) từ giá trị kỳ dị (singular values) của ma trận dữ liệu \(X\), phân tích chi phí mỗi vòng lặp \(O(np)\), và xây dựng các &lt;strong&gt;tiêu chí dừng (stopping criteria)&lt;/strong&gt; đáng tin cậy.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-định-lý-sang-code-thực-chiến&quot;&gt;Kiến thức cần nhớ: Từ Định lý sang Code thực chiến&lt;/h2&gt;

&lt;p&gt;Bốn trụ cột dưới đây là hành trang bắt buộc khi triển khai Gradient Descent trên dữ liệu thật:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(L\) và \(m\) của Bình phương tối thiểu qua Giá trị kỳ dị:&lt;/strong&gt; Với \(f(\beta) = \frac{1}{2}\|y - X\beta\|_2^2\), ma trận Hessian là hằng số \(\nabla^2 f(\beta) = X^T X\). Do đó:
\(L = \lambda_{\max}(X^T X) = \sigma_{\max}^2(X), \qquad m = \lambda_{\min}(X^T X) = \sigma_{\min}^2(X).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thảm họa mất tính lồi mạnh khi \(p &amp;gt; n\):&lt;/strong&gt; Nếu số đặc trưng \(p\) lớn hơn số mẫu \(n\) (ví dụ dữ liệu gen học có 20.000 gen nhưng chỉ 200 bệnh nhân), ma trận \(X^T X \in \mathbb{R}^{p \times p}\) có hạng tối đa là \(n &amp;lt; p\), nên chắc chắn có trị riêng bằng \(0\) (\(m = 0\))! Hàm mất tính lồi mạnh — và cách cứu duy nhất là cộng thêm điều chuẩn Ridge \(\frac{\lambda}{2}\|\beta\|_2^2\) để đẩy \(m\) lên \(\ge \lambda &amp;gt; 0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chí dừng thực tế (Stopping Criteria):&lt;/strong&gt; Không biết \(f^\star\), ta dùng độ lớn gradient \(\|\nabla f(x^{(k)})\|_2 \le \epsilon_{\text{grad}}\) (nhờ bất đẳng thức PL, với hàm lồi mạnh \(m\) ta biết ngay \(f(x^{(k)}) - f^\star \le \frac{1}{2m}\|\nabla f(x^{(k)})\|_2^2\)!), kết hợp với kiểm tra mức thay đổi tương đối của \(f\) hoặc \(x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ưu &amp;amp; Nhược điểm cốt lõi của GD:&lt;/strong&gt; Mỗi bước cực rẻ (chỉ \(O(np)\), không cần lập hay nghịch đảo ma trận Hessian \(O(p^3)\) như Newton), rất dễ cài đặt, nhưng cực nhạy cảm với chỉ số điều kiện \(\kappa = (\sigma_{\max}/\sigma_{\min})^2\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-l-m-kappa-và-chứng-nhận-độ-chính-xác-dừng-qua-nabla-f_2&quot;&gt;Giải thích: Tính \(L, m, \kappa\) và chứng nhận độ chính xác dừng qua \(\|\nabla f\|_2\)&lt;/h3&gt;

&lt;p&gt;Cho ma trận dữ liệu 2 mẫu, 2 đặc trưng \(X = \begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 0.5 \end{pmatrix}\) và bài toán \(f(\beta) = \frac{1}{2}\|y - X\beta\|_2^2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(L\), \(m\) và \(\kappa\) không có điều chuẩn:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(X^T X = \begin{pmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 0.25 \end{pmatrix} \implies L = 4,\; m = 0.25\).&lt;/li&gt;
      &lt;li&gt;Chỉ số điều kiện: \(\kappa = \frac{4}{0.25} = 16\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xem hiệu ứng khi thêm điều chuẩn Ridge \(\frac{1}{2}\lambda\|\beta\|_2^2\) với \(\lambda = 0.75\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hessian mới: \(X^T X + 0.75 I = \operatorname{diag}(4.75,\; 1.0)\).&lt;/li&gt;
      &lt;li&gt;\(L_{\text{new}} = 4.75,\; m_{\text{new}} = 1.0 \implies \kappa_{\text{new}} = 4.75\) (giảm hơn &lt;strong&gt;3.3 lần&lt;/strong&gt;!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng tiêu chí dừng \(\|\nabla f(\beta^{(k)})\|_2 \le 0.02\) để chứng nhận sai số hàm mục tiêu:&lt;/strong&gt;
Nhờ bất đẳng thức PL với \(m_{\text{new}} = 1.0\):
\(f(\beta^{(k)}) - f^\star \le \frac{1}{2 m_{\text{new}}} \|\nabla f(\beta^{(k)})\|_2^2 \le \frac{1}{2(1.0)} (0.02)^2 = 0.0002.\)
Dù không hề biết \(f^\star\) bằng bao nhiêu, chỉ cần nhìn norm gradient xuống dưới \(0.02\) là ta có &lt;strong&gt;chứng chỉ toán học&lt;/strong&gt; rằng mình đang cách đáy toàn cục không quá \(0.0002\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;điều-kiện-liên-tục-lipschitz--tính-lồi-mạnh&quot;&gt;Điều kiện Liên tục Lipschitz &amp;amp; Tính Lồi mạnh&lt;/h2&gt;

&lt;p&gt;Xét bài toán hồi quy bình phương tối thiểu \(f(\beta) = \frac{1}{2} \lVert y - X\beta \rVert_2^2\) để minh họa các điều kiện liên tục Lipschitz và tính lồi mạnh.&lt;/p&gt;

&lt;h3 id=&quot;tính-liên-tục-lipschitz-của-nabla-f&quot;&gt;Tính liên tục Lipschitz của \(\nabla f\):&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Điều kiện này tương đương với \(\nabla^2 f(x) \preceq LI\).&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Vì \(\nabla^2 f(\beta) = X^TX\), ta có \(L = \sigma^2_{\max}(X)\).&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tính-lồi-mạnh-của-f&quot;&gt;Tính lồi mạnh của \(f\):&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Điều kiện này tương đương với \(\nabla^2 f(x) \succeq mI\).&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Vì \(\nabla^2 f(\beta) = X^TX\), ta có \(m = \sigma_{\min}^2(X)\).&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Nếu \(X\) có kích thước \(n \times p\) với \(p &amp;gt; n\), thì \(\sigma_{\min}(X) = 0\), nên \(f\) không thể lồi mạnh.&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Ngay cả khi \(\sigma_{\min}(X) &amp;gt; 0\), chỉ số điều kiện \(L/m = \sigma_{\max}^2(X)/\sigma_{\min}^2(X)\) vẫn có thể rất lớn.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Khi \(f\) vừa lồi mạnh vừa có gradient liên tục Lipschitz, hàm số thỏa mãn điều kiện kẹp sau (tức đồ thị của \(f\) nằm giữa hai hàm bậc hai):&lt;/p&gt;

&lt;blockquote&gt;
\[mI \preceq \nabla^2 f(x) \preceq LI \quad \text{với mọi } x \in \mathbb{R}^n \text{ và } L &amp;gt; m &amp;gt; 0\]
&lt;/blockquote&gt;

&lt;p&gt;Việc đòi hỏi cả hai điều kiện đúng với mọi \(x \in \mathbb{R}^n\) khá chặt. Tuy nhiên, trên thực tế các điều kiện này chỉ cần thỏa mãn trên tập mức dưới (sublevel set):&lt;/p&gt;

&lt;blockquote&gt;
\[S = \{x : f(x) \leq f(x^{(0)})\}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;tính-thực-tiễn&quot;&gt;Tính Thực tiễn&lt;/h2&gt;

&lt;h3 id=&quot;tiêu-chí-dừng-cho-thuật-toán-tối-ưu-hóa&quot;&gt;Tiêu chí Dừng cho Thuật toán Tối ưu hóa&lt;/h3&gt;

&lt;p&gt;Trong thực tế, thuật toán tối ưu cần các tiêu chí dừng rõ ràng để quyết định thời điểm kết thúc quá trình lặp. Dưới đây là những điều kiện dừng thường dùng nhất:&lt;/p&gt;

&lt;h4 id=&quot;1-độ-lớn-gradient-gần-bằng-không&quot;&gt;1. &lt;strong&gt;Độ lớn Gradient gần bằng không:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Đây là tiêu chí dừng tự nhiên cho bài toán tối ưu không ràng buộc, dựa trên điều kiện tối ưu bậc nhất \(\nabla f(x^{\star}) = 0\) tại điểm cực trị:
\(\|\nabla f(\mathbf{x}_k)\| \leq \epsilon_1\)
trong đó \(\mathbf{x}_k\) là điểm tại lần lặp \(k\) và \(\epsilon_1 &amp;gt; 0\) là ngưỡng sai số nhỏ.&lt;/p&gt;

&lt;p&gt;Nếu \(f\) lồi mạnh với hằng số \(m &amp;gt; 0\), ta có đảm bảo trực tiếp về sai số giá trị hàm:&lt;/p&gt;
&lt;blockquote&gt;
\[\lVert \nabla f(x) \rVert_2 \leq \sqrt{2m \epsilon} \Rightarrow f(x) - f^{\star} \leq \epsilon\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;2-thay-đổi-nhỏ-ở-giá-trị-hàm-mục-tiêu&quot;&gt;2. &lt;strong&gt;Thay đổi nhỏ ở giá trị hàm mục tiêu:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Dừng thuật toán khi giá trị hàm mục tiêu không còn thay đổi đáng kể giữa hai lần lặp liên tiếp:
\(|f(\mathbf{x}_{k+1}) - f(\mathbf{x}_k)| \leq \epsilon_2\)
trong đó \(\epsilon_2 &amp;gt; 0\) là một ngưỡng nhỏ.&lt;/p&gt;

&lt;h4 id=&quot;3-thay-đổi-nhỏ-ở-biến-tối-ưu&quot;&gt;3. &lt;strong&gt;Thay đổi nhỏ ở biến tối ưu:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Dừng thuật toán khi các tham số không còn dịch chuyển đáng kể giữa các lần lặp:
\(\|\mathbf{x}_{k+1} - \mathbf{x}_k\| \leq \epsilon_3\)
trong đó \(\epsilon_3 &amp;gt; 0\) là một ngưỡng nhỏ.&lt;/p&gt;

&lt;h4 id=&quot;4-số-lần-lặp-tối-đa&quot;&gt;4. &lt;strong&gt;Số lần lặp tối đa:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Đặt giới hạn trên cho tổng số vòng lặp để tránh vòng lặp vô hạn hoặc chạy quá lâu:
\(k \geq \text{MaxIterations}\)
Đây là điều kiện dừng an toàn, đảm bảo thuật toán kết thúc trong thời gian hữu hạn ngay cả khi chưa đạt độ chính xác mong muốn.&lt;/p&gt;

&lt;h4 id=&quot;5-thời-gian-chạy-tối-đa&quot;&gt;5. &lt;strong&gt;Thời gian chạy tối đa:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Tương tự giới hạn số lần lặp, thuật toán sẽ dừng nếu vượt quá ngân sách thời gian cho phép:
\(\text{ElapsedTime} \geq \text{MaxTime}\)&lt;/p&gt;

&lt;h4 id=&quot;6-điều-kiện-dừng-kết-hợp&quot;&gt;6. &lt;strong&gt;Điều kiện dừng kết hợp:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Trong thực tế, nhiều tiêu chí dừng thường được kết hợp với nhau (ví dụ: dừng ngay khi &lt;em&gt;một trong các&lt;/em&gt; điều kiện trên được thỏa mãn) nhằm cân bằng giữa độ chính xác và chi phí tính toán.&lt;/p&gt;

&lt;h3 id=&quot;tham-khảo-chứng-minh-điều-kiện-dừng-dưới-tính-lồi-mạnh&quot;&gt;[Tham khảo] Chứng minh Điều kiện Dừng dưới Tính Lồi mạnh&lt;/h3&gt;

&lt;p&gt;Cách suy ra tiêu chí dừng theo chuẩn gradient ở mục 1 như sau.&lt;/p&gt;

&lt;p&gt;Vì \(f\) lồi mạnh với hằng số \(m &amp;gt; 0\), ma trận Hessian thỏa mãn:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\nabla^2 f(x) \succeq mI
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ định nghĩa tính lồi mạnh (hay khai triển Taylor bậc hai với \(\nabla^2 f(\xi) \succeq mI\)), ta có cận dưới bậc hai:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) &amp;amp; \ge f(x) + \nabla f(x)^T(y-x) + \frac{m}{2} \lVert y-x \rVert_2^2, \quad \forall x, y
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Lấy đạo hàm vế phải theo \(y\) và đặt bằng 0, ta thu được điểm cực tiểu của cận dưới bậc hai là \(\tilde{y} = x - (1/m) \nabla f(x)\). Thay \(\tilde{y}\) vào vế phải của bất đẳng thức trên:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(y) &amp;amp; \ge f(x) + \nabla f(x)^T(\tilde{y}-x) + \frac{m}{2} \lVert \tilde{y}-x \rVert_2^2 \\
&amp;amp; = f(x) - \frac{1}{2m} \lVert \nabla f(x) \rVert_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Lấy cực tiểu theo \(y\) ở vế trái (thay \(f(y)\) bằng \(f^{*}\)), ta được:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f^{*} \ge f(x) - \frac{1}{2m} \lVert \nabla f(x) \rVert_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ đó suy ra tiêu chí dừng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(x) - f^{*} \le \frac{1}{2m} \lVert \nabla f(x) \rVert^2_2 &amp;amp; \le \epsilon \\
\lVert \nabla f(x) \rVert^2_2 &amp;amp; \le 2m\epsilon \\
\lVert \nabla f(x) \rVert_2 &amp;amp; \le \sqrt{2m\epsilon}
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;ưu-điểm-và-nhược-điểm-của-gradient-descent&quot;&gt;Ưu điểm và Nhược điểm của Gradient Descent&lt;/h3&gt;

&lt;h3 id=&quot;ưu-điểm&quot;&gt;Ưu điểm&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Thuật toán đơn giản, dễ cài đặt và chi phí tính toán trên mỗi vòng lặp thấp.&lt;/li&gt;
  &lt;li&gt;Hội tụ nhanh đối với các bài toán lồi mạnh và có chỉ số điều kiện tốt.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;nhược-điểm&quot;&gt;Nhược điểm&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Hội tụ chậm trong trường hợp tổng quát vì nhiều bài toán thực tế không lồi mạnh hoặc có chỉ số điều kiện xấu.&lt;/li&gt;
  &lt;li&gt;Không áp dụng trực tiếp được cho các hàm mục tiêu không khả vi.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-04 Convergence analysis under strong convexity</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_04_convergence_analysis_under_strong_convexity/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_04_convergence_analysis_under_strong_convexity</id>
   <content type="html">&lt;p&gt;Nếu tốc độ hội tụ \(O(1/k)\) của hàm lồi trơn giống như việc bạn bước đi đều đặn về phía đích, thì khi hàm sở hữu thêm tính &lt;strong&gt;lồi mạnh (strong convexity)&lt;/strong&gt;, hành trình ấy biến thành một chuyến tàu siêu tốc: khoảng cách đến nghiệm co lại theo &lt;strong&gt;cấp số nhân&lt;/strong&gt; — mỗi vài vòng lặp lại gặt thêm một chữ số thập phân chính xác!&lt;/p&gt;

&lt;p&gt;Tại sao một điều kiện tưởng chừng nhỏ như \(\nabla^2 f(x) \succeq m I\) (\(m &amp;gt; 0\)) lại tạo ra bước nhảy vọt từ \(O(1/\epsilon)\) xuống \(O(\log(1/\epsilon))\)? Bởi vì tính lồi mạnh đảm bảo &lt;strong&gt;đáy hàm không bao giờ bị bẹt phẳng&lt;/strong&gt;: hễ bạn còn cách xa nghiệm tối ưu, độ dốc \(\|\nabla f(x)\|_2\) chắc chắn còn đủ lớn để đẩy bạn đi nhanh về phía đích (bất đẳng thức Polyak–Łojasiewicz)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-của-hội-tụ-tuyến-tính&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép của Hội tụ Tuyến tính&lt;/h2&gt;

&lt;p&gt;Để hiểu tận gốc định lý hội tụ dưới tính lồi mạnh, hãy ghép bốn trụ cột sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa Lồi mạnh \(m\) (Cận dưới bậc hai):&lt;/strong&gt; \(f(y) \ge f(x) + \nabla f(x)^T(y-x) + \frac{m}{2}\|y-x\|_2^2 \; \forall x, y\) (tương đương \(\nabla^2 f(x) \succeq m I\) hay \(f(x) - \frac{m}{2}\|x\|_2^2\) là hàm lồi). Nói trực quan: luôn có thể lót một chiếc bát parabol độ cong \(m\) nằm gọn &lt;em&gt;dưới&lt;/em&gt; đồ thị \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Polyak–Łojasiewicz (PL):&lt;/strong&gt; Cực tiểu hóa hai vế của cận dưới bậc hai theo \(y\) cho ta mối liên hệ vàng giữa độ lớn gradient và sai số hàm mục tiêu:
\(\|\nabla f(x)\|_2^2 \ge 2m \big(f(x) - f^\star\big).\)
Hễ còn cách đáy xa, gradient không bao giờ được phép quá nhỏ!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ghép Bổ đề Giảm + Bất đẳng thức PL:&lt;/strong&gt; Từ \(f(x^+) \le f(x) - \frac{t}{2}\|\nabla f(x)\|_2^2\) (với \(t \le 1/L\)), thay \(\|\nabla f(x)\|_2^2 \ge 2m(f(x) - f^\star)\) cho ngay trong 1 dòng:
\(f(x^+) - f^\star \le (1 - mt)\big(f(x) - f^\star\big) \implies f(x^{(k)}) - f^\star \le (1 - mt)^k \big(f(x^{(0)}) - f^\star\big).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vai trò của Chỉ số điều kiện \(\kappa = L/m\):&lt;/strong&gt; Đặt \(t = 1/L\), hệ số co là \(c = 1 - m/L = 1 - 1/\kappa\). Muốn sai số nhỏ hơn \(\epsilon\), số vòng lặp cần thiết là \(k = O\big(\kappa \log(1/\epsilon)\big)\) — phụ thuộc &lt;em&gt;logarit&lt;/em&gt; vào \(\epsilon\) nhưng &lt;em&gt;tuyến tính&lt;/em&gt; vào \(\kappa\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chứng-minh-và-tính-số-cụ-thể-tốc-độ-co-lũy-thừa-theo-kappa&quot;&gt;Giải thích: Chứng minh và tính số cụ thể tốc độ co lũy thừa theo \(\kappa\)&lt;/h3&gt;

&lt;p&gt;Xét hàm Ridge Regression 2 biến \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + 5x_2^2) + \frac{1}{2}\lambda(x_1^2 + x_2^2)\) với \(\lambda = 1\).
Ta có \(f(x) = \frac{1}{2}(2x_1^2 + 6x_2^2)\), Hessian \(H = \operatorname{diag}(2, 6)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Xác định \(m\), \(L\) và \(\kappa\):&lt;/strong&gt;
\(m = 2, \qquad L = 6, \qquad \kappa = \frac{L}{m} = 3.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tính hệ số co với bước chuẩn \(t = 1/L = 1/6\):&lt;/strong&gt;
\(1 - mt = 1 - \frac{2}{6} = \frac{2}{3} \approx 0.6667.\)
(Thậm chí nếu dùng bước \(t = \frac{2}{L+m} = \frac{2}{8} = 0.25\), khoảng cách co với hệ số \(\frac{\kappa-1}{\kappa+1} = 0.5\) và sai số hàm co với hệ số \(0.25\) mỗi bước!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kiểm chứng bằng số tại \(x^{(0)} = (3, 1)^T\) với \(t = 1/6\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(x^{(0)}) = 9 + 3 = 12\).&lt;/li&gt;
      &lt;li&gt;\(\nabla f(x^{(0)}) = (6, 6)^T \implies x^{(1)} = (3, 1)^T - \frac{1}{6}(6, 6)^T = (2, 0)^T\).&lt;/li&gt;
      &lt;li&gt;\(f(x^{(1)}) = 4 + 0 = 4\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra bất đẳng thức lý thuyết: \(f(x^{(1)}) = 4 \le \frac{2}{3} \cdot 12 = 8\) — hoàn toàn đúng! Chỉ cần \(k = \left\lceil \frac{\ln(12 / 10^{-6})}{\ln(3/2)} \right\rceil = 41\) bước là chắc chắn đạt sai số \(10^{-6}\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Một hàm \(f\) khả vi được gọi là lồi mạnh với hằng số \(m &amp;gt; 0\) nếu thỏa mãn điều kiện sau:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) \ge f(x) + \nabla f(x)^T(y-x) + \frac{m}{2} \| y-x \|_2^2, \quad \forall x, y
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, \(f\) có một cận dưới bậc hai. Khi \(f\) khả vi hai lần, hằng số \(m\) được chặn trên bởi giá trị riêng nhỏ nhất của ma trận Hessian của \(f\).&lt;/p&gt;

&lt;p&gt;Tổng quát hơn, hàm \(f\) lồi mạnh với hằng số \(m &amp;gt; 0\) khi và chỉ khi:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
g(x) = f(x) - \frac{m}{2} \| x \|_2^2 \quad \text{là hàm lồi trên miền xác định của } f
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;định-lý-hội-tụ&quot;&gt;Định lý Hội tụ&lt;/h2&gt;

&lt;p&gt;Khi \(f\) vừa có gradient liên tục Lipschitz với hằng số \(L\) vừa lồi mạnh với hằng số \(m\), ta có kết quả sau:&lt;/p&gt;

&lt;p&gt;Thuật toán &lt;strong&gt;gradient descent&lt;/strong&gt; với kích thước bước cố định (\(t \le 2/(m + L)\)) hoặc tìm kiếm đường lùi thỏa mãn:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f^* \le c^k \frac{L}{2} \| x^{(0)} - x^* \|_2^2, \quad c = 1 - \frac{m}{L}, \quad 0 &amp;lt; c &amp;lt; 1
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h2&gt;

&lt;p&gt;Vì \(f\) có gradient liên tục Lipschitz với hằng số \(L\), hàm \(f\) thỏa mãn cận trên bậc hai (xem &lt;a href=&quot;#post-not-found&quot;&gt;06-03-01&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Với bước cập nhật gradient descent \(x^+ = x - t \nabla f(x)\) và chọn kích thước bước \(t = 1/L\), ta thu được:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^+) \le f(x) - \frac{1}{2L} \| \nabla f(x) \|_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trừ hai vế cho \(f(x^*)\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^+) - f(x^*) \le f(x) - f(x^*) - \frac{1}{2L} \| \nabla f(x) \|_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do \(f\) lồi mạnh với hằng số \(m\), ta có bất đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x) - f(x^*) \le \frac{1}{2m} \| \nabla f(x) \|_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Thay bất đẳng thức này vào vế phải ở trên, ta được:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^+) - f(x^*) &amp;amp; \le f(x) - f(x^*) - \frac{m}{L} ( f(x) - f(x^*) ) \\
&amp;amp; = \left(1 - \frac{m}{L} \right) ( f(x) - f(x^*) ) \\
&amp;amp; = c ( f(x) - f(x^*) )
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Áp dụng quy nạp qua \(k\) bước lặp:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f(x^*) \le c^k ( f(x^{(0)}) - f(x^*) )
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Mặt khác, từ cận trên bậc hai áp dụng tại \(y = x^{(0)}\) và \(x = x^*\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) \le f(x) + \nabla f(x)^T (y-x) + \frac{L}{2} \lVert y - x \rVert^2_2 \quad \forall x, y
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì \(\nabla f(x^*) = 0\), ta thu được:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(0)}) &amp;amp; \le f(x^{*}) + \nabla f(x^{*})^T (x^{(0)}- x^{*} ) + \frac{L}{2} \lVert x^{(0)} - x^{*} \rVert^2_2 \\
&amp;amp; = f(x^{*}) + \frac{L}{2} \lVert x^{(0)} - x^{*} \rVert^2_2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Suy ra:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(0)}) - f(x^{*}) &amp;amp; \le \frac{L}{2} \lVert x^{(0)} - x^{*} \rVert^2_2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Thay vào bất đẳng thức quy nạp trước đó, ta có:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f(x^{*}) &amp;amp; \le c^k \frac{L}{2} \lVert x^{(0)} - x^{*} \rVert^2_2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Điều này hoàn tất chứng minh định lý hội tụ của gradient descent dưới giả thiết lồi mạnh.&lt;/p&gt;

&lt;h2 id=&quot;hội-tụ-tuyến-tính&quot;&gt;Hội tụ Tuyến tính&lt;/h2&gt;

&lt;p&gt;Khi \(f\) lồi mạnh, sai số giảm theo tốc độ \(O(c^k)\), tức là hội tụ theo cấp số nhân (hội tụ tuyến tính). Để đạt \(f(x^{(k)}) - f^{*} \le \epsilon\), thuật toán chỉ cần \(O(\log(1/\epsilon))\) vòng lặp (so với \(O(1/\epsilon)\) vòng lặp khi không có tính lồi mạnh).&lt;/p&gt;

&lt;p&gt;Trên đồ thị bán logarit, tốc độ hội tụ \(O(c^k)\) có dạng một đường thẳng như minh họa dưới đây.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06.03_01_01_Line_Convergence.png&quot; alt=&quot;Line_Convergence&quot; width=&quot;60%&quot; height=&quot;60%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Hội tụ tuyến tính [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Ở đây, hằng số \(c = 1 - \frac{m}{L}\) phụ thuộc trực tiếp vào chỉ số điều kiện \(L/m\) (tỉ số giữa giá trị riêng lớn nhất và nhỏ nhất của Hessian). Chỉ số điều kiện càng lớn thì \(c\) càng gần 1 và tốc độ hội tụ càng chậm.&lt;/p&gt;

&lt;p&gt;Cấu trúc đại số của chứng minh này — kết hợp bổ đề giảm (descent lemma) với một cận dưới liên hệ \(\|\nabla f\|^2\) và độ chênh lệch giá trị hàm — vẫn giữ nguyên hiệu lực khi giả thiết lồi mạnh được nới lỏng thành bất đẳng thức Polyak–Łojasiewicz. Nội dung mở rộng tùy chọn về tốc độ hội tụ hiện đại này, cùng ví dụ bài toán bình phương tối thiểu quá tham số (nơi nghiệm cực tiểu không duy nhất), được trình bày tại &lt;a href=&quot;/contents/vi/chapter28/28_05_pl_condition/&quot;&gt;28-05 Điều kiện PL và câu chuyện tốc độ hiện đại&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-03 Convergence analysis for backtracking</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_03_convergence_analysis_for_backtracking/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_03_convergence_analysis_for_backtracking</id>
   <content type="html">&lt;p&gt;Ở bài trước ta đã chứng minh Gradient Descent bước cố định \(t \le 1/L\) đạt tốc độ hội tụ \(O(1/k)\), nhưng ta phải biết trước hằng số \(L\). Vậy nếu ta dùng &lt;strong&gt;Backtracking Line Search&lt;/strong&gt; (tự động chọn bước \(t_k\) khác nhau ở mỗi vòng lặp mà không hề biết \(L\)), liệu tốc độ hội tụ \(O(1/k)\) có bị suy giảm hay không?&lt;/p&gt;

&lt;p&gt;Câu trả lời là một trong những tin vui lớn nhất của tối ưu hóa thực hành: &lt;strong&gt;Backtracking Line Search giữ nguyên trọn vẹn tốc độ hội tụ \(O(1/k)\)&lt;/strong&gt;, chỉ trả thêm một hệ số hằng nhỏ cỡ \(1/\beta\) (ví dụ gấp đôi khi \(\beta = 0.5\)) — trong khi đổi lại bạn &lt;strong&gt;không bao giờ phải ước lượng \(L\) bằng tay&lt;/strong&gt; và thường chạy nhanh hơn bước cố định rất nhiều trên vùng phẳng!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-vì-sao-backtracking-luôn-có-cận-dưới-cho-bước-t_k&quot;&gt;Kiến thức cần nhớ: Vì sao Backtracking luôn có cận dưới cho bước \(t_k\)?&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau giải thích gọn gàng chứng minh hội tụ của Backtracking Line Search:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chặn dưới kích thước bước \(t_{\min}\):&lt;/strong&gt; Khi \(\alpha \le 0.5\), mọi bước \(t \le 1/L\) đều tự động thỏa điều kiện Armijo \(f(x - tg) \le f(x) - \frac{t}{2}\|g\|_2^2\). Do Backtracking chỉ nhân thêm \(\beta\) mỗi lần thử thất bại, nên bước cuối cùng được chấp nhận chắc chắn thỏa:
\(t_k \ge \min\left(1,\; \frac{\beta}{L}\right) = t_{\min}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh tương tự bước cố định:&lt;/strong&gt; Vì mỗi bước đều thỏa \(f(x^+) \le f(x) - \frac{t_k}{2}\|\nabla f(x)\|_2^2\) (khi chọn \(\alpha = 0.5\)) và \(t_k \ge t_{\min}\), ta thay \(t\) bằng \(t_{\min}\) trong chuỗi tổng lồng nhau và thu ngay:
\(f(x^{(k)}) - f^\star \le \frac{\|x^{(0)} - x^\star\|_2^2}{2 t_{\min} k}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ưu thế ẩn của độ cong địa phương:&lt;/strong&gt; Cận lý thuyết dùng \(L\) toàn cục, nhưng thực tế tại những vùng hàm có độ cong địa phương \(L_{\text{loc}} \ll L\), Backtracking chấp nhận bước \(t_k \approx 1/L_{\text{loc}} \gg 1/L\) — giúp chạy nhanh vượt trội so với bước cố định \(1/L\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-cận-dưới-t_min-và-so-sánh-cận-sai-số-với-bước-cố-định&quot;&gt;Giải thích: Tính cận dưới \(t_{\min}\) và so sánh cận sai số với bước cố định&lt;/h3&gt;

&lt;p&gt;Giả sử một bài toán hồi quy có hằng số trơn thật (nhưng ta không biết) là \(L = 20\), và khoảng cách ban đầu \(\|x^{(0)} - x^\star\|_2 = 2\). Ta dùng Backtracking với \(t_0 = 1,\; \alpha = 0.5,\; \beta = 0.5\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tính cận dưới bước chấp nhận \(t_{\min}\):&lt;/strong&gt;
\(t_{\min} = \min\left(1,\; \frac{\beta}{L}\right) = \min\left(1,\; \frac{0.5}{20}\right) = 0.025.\)
Điều này có nghĩa là trong quá trình co bước \(1 \to 0.5 \to 0.25 \to 0.125 \to 0.0625 \to 0.03125\), vòng lặp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;while&lt;/code&gt; &lt;strong&gt;chắc chắn dừng chậm nhất ở \(t = 0.03125\)&lt;/strong&gt; (chỉ tối đa 5 phép thử, vì \(0.03125 \le 1/20 = 0.05\) đã thỏa Armijo!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — So sánh cận sai số tại \(k = 100\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bước cố định biết trước \(L\) (\(t = 1/L = 0.05\)):
\(f(x^{(100)}) - f^\star \le \frac{2^2}{2(0.05)(100)} = \frac{4}{10} = 0.4.\)&lt;/li&gt;
      &lt;li&gt;Backtracking không cần biết \(L\) (\(t_{\min} = 0.025\)):
\(f(x^{(100)}) - f^\star \le \frac{2^2}{2(0.025)(100)} = \frac{4}{5} = 0.8.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Không cần biết trước \(L = 20\), Backtracking chỉ trả tối đa hệ số \(2\times\) trong trường hợp xấu nhất — một mức giá quá hời cho sự an toàn và khả năng tự thích ứng!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Giả sử \(f\) lồi, khả vi với \(dom(f) = \mathbb{R}^n\) và \(\nabla f\) liên tục Lipschitz với hằng số \(L &amp;gt; 0\):&lt;/p&gt;
&lt;blockquote&gt;
\[\| \nabla f(x) - \nabla f(y) \|_2 \le L \| x - y \|_2 \quad \text{với mọi } x, y\]
&lt;/blockquote&gt;

&lt;p&gt;Tham khảo: [&lt;a href=&quot;https://en.wikipedia.org/wiki/Lipschitz_continuity&quot;&gt;Wikipedia: Lipschitz continuity&lt;/a&gt;]&lt;/p&gt;

&lt;h2 id=&quot;định-lý-hội-tụ&quot;&gt;Định lý Hội tụ&lt;/h2&gt;

&lt;p&gt;Thuật toán &lt;strong&gt;gradient descent&lt;/strong&gt; kết hợp tìm kiếm đường lùi (backtracking line search) thỏa mãn:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f^* \le \frac{\| x^{(0)} - x^* \|_2^2}{2 t_{min} k}, \quad t_{min} = \min \{ 1, \beta/L \}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Tốc độ hội tụ của tìm kiếm đường lùi có cùng bậc \(O(1/k)\) như trường hợp kích thước bước cố định, trong đó \(t\) được thay bởi \(t_{min}\). Nếu \(\beta\) không quá nhỏ thì cận hội tụ tương đương với kích thước bước cố định (\(\beta/L\) so với \(1/L\)), trong khi không cần biết trước hằng số \(L\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-02 Phân Tích Hội Tụ & Chứng Minh</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_02_convergence_analysis_and_proof/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_02_convergence_analysis_and_proof</id>
   <content type="html">&lt;p&gt;Rất nhiều sinh viên toán và khoa học máy tính lần đầu đọc chứng minh tốc độ hội tụ \(O(1/k)\) của Gradient Descent thường thắc mắc: &lt;em&gt;tại sao chứng minh lại đột nhiên khai triển hiệu khoảng cách \(\|x^{(i)} - x^\star\|_2^2 - \|x^{(i+1)} - x^\star\|_2^2\) rồi cộng dồn từ \(i=0\) đến \(k-1\)?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bí mật nằm ở kỹ thuật &lt;strong&gt;hàm thế năng (Lyapunov / Potential Function)&lt;/strong&gt; — một trong những công cụ đẹp nhất của giải tích thuật toán. Mỗi bước GD đổi một phần khoảng cách bình phương tới nghiệm \(\|x^{(i)} - x^\star\|_2^2\) để lấy mức giảm sai số hàm mục tiêu \(f(x^{(i+1)}) - f^\star\). Khi cộng dồn \(k\) bước lại, các số hạng trung gian tự triệt tiêu sạch sẽ (telescoping sum), để lại ngay cận trên gọn gàng \(\frac{\|x^{(0)} - x^\star\|_2^2}{2tk}\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-mắt-xích-trong-chứng-minh-tốc-độ-hội-tụ-o1k&quot;&gt;Kiến thức cần nhớ: Ba mắt xích trong chứng minh tốc độ hội tụ \(O(1/k)\)&lt;/h2&gt;

&lt;p&gt;Chứng minh kinh điển này chỉ dựa trên đúng ba bất đẳng thức ghép nối nhau như bánh răng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mắt xích 1 — Cận trên bậc hai (Bổ đề giảm):&lt;/strong&gt; Với \(t \le 1/L\), mỗi bước thỏa \(f(x^+) \le f(x) - \frac{t}{2}\|\nabla f(x)\|_2^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mắt xích 2 — Cận dưới lồi tại nghiệm \(x^\star\):&lt;/strong&gt; Vì \(f\) lồi, \(f(x) \le f(x^\star) + \nabla f(x)^T(x - x^\star)\). Thay vào Mắt xích 1 rồi hoàn thành bình phương theo \(x - t\nabla f(x) - x^\star = x^+ - x^\star\) thu ngay:
\(f(x^+) - f^\star \le \frac{1}{2t}\left(\|x - x^\star\|_2^2 - \|x^+ - x^\star\|_2^2\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mắt xích 3 — Tổng lồng nhau &amp;amp; Tính đơn điệu giảm của \(f(x^{(i)})\):&lt;/strong&gt; Cộng bất đẳng thức trên từ \(i = 0\) đến \(k - 1\) cho \(\sum_{i=1}^k (f(x^{(i)}) - f^\star) \le \frac{1}{2t}\|x^{(0)} - x^\star\|_2^2\). Vì \(f(x^{(k)})\) nhỏ nhất trong cả dãy, ta chia cả hai vế cho \(k\) và thu được ngay:
\(f(x^{(k)}) - f^\star \le \frac{\|x^{(0)} - x^\star\|_2^2}{2tk}.\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-từng-mắt-xích-của-chứng-minh-bằng-số-cụ-thể&quot;&gt;Giải thích: Kiểm chứng từng mắt xích của chứng minh bằng số cụ thể&lt;/h3&gt;

&lt;p&gt;Xét \(f(x) = \frac{1}{2} x^2\) (\(L = 1,\; x^\star = 0,\; f^\star = 0\)), bước \(t = 0.5 \le 1/L\), xuất phát từ \(x^{(0)} = 2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Quỹ đạo 3 bước đầu:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(0)} = 2,\; f = 2,\; \|x^{(0)} - x^\star\|^2 = 4\).&lt;/li&gt;
      &lt;li&gt;\(x^{(1)} = 1,\; f = 0.5,\; \|x^{(1)} - x^\star\|^2 = 1\).&lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = 0.5,\; f = 0.125,\; \|x^{(2)} - x^\star\|^2 = 0.25\).&lt;/li&gt;
      &lt;li&gt;\(x^{(3)} = 0.25,\; f = 0.03125,\; \|x^{(3)} - x^\star\|^2 = 0.0625\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra Mắt xích 2 tại bước \(i = 0 \to 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vế trái: \(f(x^{(1)}) - f^\star = 0.5\).&lt;/li&gt;
      &lt;li&gt;Vế phải: \(\frac{1}{2(0.5)}(4 - 1) = 3\). Quả nhiên \(0.5 \le 3\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra Tổng lồng nhau tại \(k = 3\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tổng sai số 3 bước: \(0.5 + 0.125 + 0.03125 = 0.65625\).&lt;/li&gt;
      &lt;li&gt;Vế phải telescoping: \(\frac{1}{2(0.5)}(4 - 0.0625) = 3.9375 \le 4\).&lt;/li&gt;
      &lt;li&gt;Cận cuối cùng tại \(k = 3\): \(f(x^{(3)}) - f^\star = 0.03125 \le \frac{4}{2(0.5)(3)} = 1.3333\).
&lt;strong&gt;Nhận xét:&lt;/strong&gt; Cận \(O(1/k)\) là cận &lt;em&gt;trường hợp xấu nhất&lt;/em&gt; cho mọi hàm lồi \(L\)-trơn; vì \(f(x) = \frac{1}{2}x^2\) còn lồi mạnh nên thực tế nó hội tụ nhanh hơn cận \(O(1/k)\) rất nhiều!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Giả sử \(f\) lồi, khả vi với \(dom(f) = \mathbb{R}^n\) và \(\nabla f\) liên tục Lipschitz với hằng số \(L &amp;gt; 0\):&lt;/p&gt;

&lt;blockquote&gt;
\[\| \nabla f(x) - \nabla f(y) \|_2 \le L \| x - y \|_2 \quad \text{với mọi } x, y\]
&lt;/blockquote&gt;

&lt;p&gt;Tham khảo: [&lt;a href=&quot;https://en.wikipedia.org/wiki/Lipschitz_continuity&quot;&gt;Wikipedia: Lipschitz continuity&lt;/a&gt;]&lt;/p&gt;

&lt;h2 id=&quot;định-lý-hội-tụ&quot;&gt;Định lý Hội tụ&lt;/h2&gt;

&lt;p&gt;Thuật toán &lt;strong&gt;gradient descent&lt;/strong&gt; với kích thước bước cố định \(t \le 1/L\) thỏa mãn:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f^* \le \frac{ \| x^{(0)} - x^* \|^2_2 }{2tk}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Với kích thước bước cố định, tốc độ hội tụ là \(O(1/k)\). Do đó, để đạt sai số \(f(x^{(k)}) - f^* \le \epsilon\), thuật toán cần \(O(1/\epsilon)\) vòng lặp.&lt;/p&gt;

&lt;h2 id=&quot;chứng-minh-bổ-đề-giảm&quot;&gt;Chứng minh (Bổ đề giảm)&lt;/h2&gt;

&lt;p&gt;Vì \(f\) lồi và \(\nabla f\) liên tục Lipschitz với hằng số \(L\), hàm \(f\) thỏa mãn cận trên bậc hai (xem &lt;a href=&quot;#post-not-found&quot;&gt;06-03-01&lt;/a&gt;):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(y) \le f(x) + \nabla f(x)^T (y-x) + \frac{L}{2} \| y - x \|^2_2 \quad \forall x, y
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Với bước cập nhật gradient descent \(x^+ = x - t \nabla f(x)\), thay \(y = x^+\) vào bất đẳng thức trên, ta được:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(x^+) &amp;amp; \le f(x) - t \left( 1 - \frac{Lt}{2} \right)\| \nabla f(x) \|^2_2 \\
&amp;amp; \le f(x) - \frac{t}{2} \| \nabla f(x) \|^2_2 \quad \text{nếu } t \le 1/L
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó \(f(x^+) &amp;lt; f(x)\) mỗi khi \(\nabla f(x) \neq 0\), cho thấy giá trị hàm mục tiêu giảm nghiêm ngặt qua từng bước lặp và tiến tới hội tụ.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-01 Cận trên bậc hai của hàm lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_01_convex_function_quadratic_upper_bound/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_03_01_convex_function_quadratic_upper_bound</id>
   <content type="html">&lt;p&gt;Khi học Chương 03, ta đã quá quen với &lt;strong&gt;cận dưới tuyến tính&lt;/strong&gt; của hàm lồi: đồ thị của \(f\) luôn nằm phía trên mọi mặt phẳng tiếp tuyến của nó, \(f(y) \ge f(x) + \nabla f(x)^T(y - x)\). Nhưng một mình cận dưới không đủ để đảm bảo thuật toán Gradient Descent không bị “vượt rào” khi bước đi — ta cần thêm một &lt;strong&gt;chiếc trần bảo vệ phía trên&lt;/strong&gt; khống chế tốc độ uốn cong của hàm!&lt;/p&gt;

&lt;p&gt;Chiếc trần ấy chính là &lt;strong&gt;Cận trên bậc hai (Quadratic Upper Bound)&lt;/strong&gt; xuất phát từ điều kiện gradient liên tục Lipschitz với hằng số \(L\). Nó khẳng định rằng tại mọi điểm \(x\), nếu bạn úp một chiếc bát parabol có độ cong \(L\) tiếp xúc với \(f\) tại \(x\), thì toàn bộ đồ thị của \(f\) sẽ nằm gọn bên dưới chiếc bát ấy!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-sức-mạnh-của-tính-l-trơn-l-smoothness&quot;&gt;Kiến thức cần nhớ: Sức mạnh của tính \(L\)-trơn (\(L\)-Smoothness)&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau tóm tắt những đặc trưng tương đương quan trọng nhất của cận trên bậc hai:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa Gradient \(L\)-Lipschitz:&lt;/strong&gt; \(\|\nabla f(y) - \nabla f(x)\|_2 \le L \|y - x\|_2 \; \forall x, y\). Trực giác: độ dốc của hàm không bao giờ thay đổi đột ngột quá \(L\) đơn vị trên mỗi đơn vị khoảng cách!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cận trên bậc hai (Bổ đề Descent):&lt;/strong&gt; Từ điều kiện \(L\)-Lipschitz suy ra ngay
\(f(y) \le f(x) + \nabla f(x)^T(y - x) + \frac{L}{2}\|y - x\|_2^2 \quad \forall x, y.\)
Nếu \(f\) khả vi bậc hai, điều này tương đương chính xác với \(\nabla^2 f(x) \preceq L I\) — tức mọi trị riêng của ma trận Hessian không bao giờ vượt quá \(L\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ quả trực tiếp cho bước GD \(y = x - t\nabla f(x)\):&lt;/strong&gt; Thay \(y - x = -t\nabla f(x)\) vào cận trên bậc hai cho ngay:
\(f(x^+) \le f(x) - t\left(1 - \frac{Lt}{2}\right)\|\nabla f(x)\|_2^2.\)
Chọn \(t = 1/L\) làm cực đại hệ số \(t(1 - Lt/2)\) và cho mức giảm bảo đảm tối thiểu \(\frac{1}{2L}\|\nabla f(x)\|_2^2\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-hằng-số-l-và-kiểm-chứng-cận-trên-bậc-hai-cho-hồi-quy-logistic-1-biến&quot;&gt;Giải thích: Tính hằng số \(L\) và kiểm chứng cận trên bậc hai cho Hồi quy Logistic 1 biến&lt;/h3&gt;

&lt;p&gt;Xét hàm mất mát logistic \(f(x) = \log(1 + e^x)\) trên \(\mathbb{R}\) (tương ứng 1 mẫu dữ liệu có \(a = 1, y = 0\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tìm hằng số \(L\) từ đạo hàm bậc hai:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(x) = \frac{e^x}{1 + e^x} = \sigma(x)\).&lt;/li&gt;
      &lt;li&gt;\(f&apos;&apos;(x) = \sigma(x)(1 - \sigma(x))\).
Vì \(\sigma(x) \in (0, 1)\), tích \(p(1 - p)\) đạt cực đại bằng \(\frac{1}{4} = 0.25\) tại \(p = 0.5\) (tức \(x = 0\)).
Vậy \(0 &amp;lt; f&apos;&apos;(x) \le 0.25\) với mọi \(x \in \mathbb{R} \implies L = 0.25\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Kiểm chứng cận trên bậc hai tại \(x = 0\) và \(y = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giá trị thật: \(f(2) = \log(1 + e^2) \approx \log(8.3891) \approx 2.1269\).&lt;/li&gt;
      &lt;li&gt;Cận dưới tuyến tính tại \(x = 0\) (với \(f(0) = \log 2 \approx 0.6931,\; f&apos;(0) = 0.5\)):
\(f(0) + f&apos;(0)(2 - 0) = 0.6931 + 1 = 1.6931.\)&lt;/li&gt;
      &lt;li&gt;Cận trên bậc hai với \(L = 0.25\):
\(f(0) + f&apos;(0)(2 - 0) + \frac{0.25}{2}(2 - 0)^2 = 1.6931 + 0.5 = 2.1931.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kiểm tra kẹp 2 phía:&lt;/strong&gt; \(1.6931 \le 2.1269 \le 2.1931\) — cực kỳ chặt! Và bước cố định an toàn bảo đảm hội tụ là \(t = 1/L = 4\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;giới-thiệu&quot;&gt;Giới thiệu&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Cận trên bậc hai&lt;/strong&gt; là một tính chất nền tảng của các hàm lồi trơn, đóng vai trò công cụ cốt lõi trong việc phân tích và thiết kế thuật toán tối ưu hóa. Tính chất này khẳng định rằng mọi hàm lồi có gradient liên tục Lipschitz đều có thể được chặn trên bởi một hàm bậc hai, tạo cơ sở trực tiếp cho việc phân tích hội tụ của các phương pháp dựa trên gradient.&lt;/p&gt;

&lt;h2 id=&quot;vai-trò-và-ý-nghĩa&quot;&gt;Vai trò và Ý nghĩa&lt;/h2&gt;

&lt;p&gt;Vì sao cận trên bậc hai lại quan trọng trong tối ưu hóa?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Thiết kế thuật toán&lt;/strong&gt;: Nhiều thuật toán tối ưu (như gradient descent) xây dựng bước cập nhật dựa trên xấp xỉ cục bộ của hàm mục tiêu. Cận trên bậc hai cung cấp một khuôn khổ nhất quán để thiết lập các xấp xỉ này.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Phân tích hội tụ&lt;/strong&gt;: Bất đẳng thức cận trên bậc hai giúp chặn mức thay đổi giá trị hàm sau mỗi bước lặp, từ đó chứng minh tốc độ hội tụ của thuật toán.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Lựa chọn kích thước bước&lt;/strong&gt;: Hằng số Lipschitz \(L\) trong cận trên trực tiếp xác định ngưỡng kích thước bước an toàn cho gradient descent.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;tính-chất-cận-trên-bậc-hai&quot;&gt;Tính chất Cận trên Bậc hai&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý&lt;/strong&gt;: Nếu \(f\) là hàm lồi và \(\nabla f\) liên tục Lipschitz với hằng số \(L\), thì \(f\) thỏa mãn cận trên bậc hai:&lt;/p&gt;

  &lt;blockquote&gt;
\[\begin{align}
f(y) &amp;amp; \le f(x) + \nabla f(x)^T (y-x) + \frac{L}{2} \| y - x \|^2_2 \quad \forall x, y
\end{align}\]
  &lt;/blockquote&gt;
&lt;/div&gt;

&lt;h3 id=&quot;diễn-giải-hình-học&quot;&gt;Diễn giải Hình học&lt;/h3&gt;

&lt;p&gt;Bất đẳng thức trên cho thấy:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ tuyến tính&lt;/strong&gt; \(f(x) + \nabla f(x)^T (y-x)\) (khai triển Taylor bậc nhất) luôn nằm dưới \(f(y)\) nhờ tính lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cận trên bậc hai&lt;/strong&gt; \(f(x) + \nabla f(x)^T (y-x) + \frac{L}{2} \| y - x \|^2_2\) luôn nằm trên \(f(y)\).&lt;/li&gt;
  &lt;li&gt;Đồ thị của \(f(y)\) được kẹp giữa hai cận này.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;đặc-trưng-tương-đương&quot;&gt;Đặc trưng Tương đương&lt;/h3&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Hệ quả&lt;/strong&gt;: Đối với mọi hàm lồi trơn \(f\) có gradient \(L\)-Lipschitz, hàm số sau đây là hàm lồi:&lt;/p&gt;

  &lt;blockquote&gt;
\[\begin{align}
g(x) &amp;amp; = \frac{L}{2} \| x \|^2_2 - f(x) \quad \text{với } dom(g) = dom(f)
\end{align}\]
  &lt;/blockquote&gt;
&lt;/div&gt;

&lt;p&gt;Nói cách khác, \(f(x)\) có thể biểu diễn dưới dạng hiệu giữa một hàm bậc hai và một hàm lồi.&lt;/p&gt;

&lt;h2 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h2&gt;

&lt;p&gt;Ta sẽ chứng minh cả cận trên bậc hai lẫn đặc trưng tương đương dựa trên hai tính chất cơ bản của hàm lồi trơn.&lt;/p&gt;

&lt;h3 id=&quot;kiến-thức-chuẩn-bị&quot;&gt;Kiến thức Chuẩn bị&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Toán tử đơn điệu)&lt;/strong&gt;: Trên không gian vector \(X\), toán tử \(T : X \to X^*\) được gọi là đơn điệu nếu:&lt;/p&gt;
  &lt;blockquote&gt;
\[(Tu - Tv, u-v) \ge 0, \quad \forall u, v \in X\]
  &lt;/blockquote&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Tính chất 1 (Tính đơn điệu của gradient)&lt;/strong&gt;: Nếu \(f\) lồi và khả vi thì \(\nabla f\) là toán tử đơn điệu:&lt;/p&gt;
&lt;blockquote&gt;
\[(\nabla f(y) - \nabla f(x))^T (y-x) \ge 0, \quad \forall x, y\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Tính chất 2 (Tính liên tục Lipschitz)&lt;/strong&gt;: \(\nabla f\) liên tục Lipschitz với hằng số \(L\):&lt;/p&gt;
&lt;blockquote&gt;
\[\| \nabla f(x) - \nabla f(y) \|_2 \le L \| x - y \|_2, \quad \forall x, y\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;chứng-minh-cận-trên-bậc-hai&quot;&gt;Chứng minh Cận trên Bậc hai&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bước 1&lt;/strong&gt;: Xét hàm một biến \(h(t) = f(x + t(y-x))\) trên \(t \in [0,1]\). Theo định lý cơ bản của giải tích:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(y) - f(x) &amp;amp;= h(1) - h(0) = \int_0^1 h&apos;(t) dt \\
&amp;amp;= \int_0^1 \nabla f(x + t(y-x))^T (y-x) dt
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 2&lt;/strong&gt;: Tách số hạng \(\nabla f(x)^T (y-x)\) ra ngoài dấu tích phân:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) - f(x) &amp;amp;= \nabla f(x)^T (y-x) + \int_0^1 [\nabla f(x + t(y-x)) - \nabla f(x)]^T (y-x) dt
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 3&lt;/strong&gt;: Áp dụng bất đẳng thức Cauchy–Schwarz và tính liên tục Lipschitz của \(\nabla f\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;[\nabla f(x + t(y-x)) - \nabla f(x)]^T (y-x) \\
&amp;amp;\le \|\nabla f(x + t(y-x)) - \nabla f(x)\| \cdot \|y-x\| \\
&amp;amp;\le L \cdot t\|y-x\| \cdot \|y-x\| = Lt\|y-x\|^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 4&lt;/strong&gt;: Lấy tích phân trên \(t \in [0,1]\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) - f(x) &amp;amp;\le \nabla f(x)^T (y-x) + \int_0^1 Lt\|y-x\|^2 dt \\
&amp;amp;= \nabla f(x)^T (y-x) + L\|y-x\|^2 \int_0^1 t dt \\
&amp;amp;= \nabla f(x)^T (y-x) + \frac{L}{2}\|y-x\|^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Suy ra \(f(y) \le f(x) + \nabla f(x)^T (y-x) + \frac{L}{2}\|y-x\|^2\).&lt;/p&gt;

&lt;h3 id=&quot;chứng-minh-đặc-trưng-tương-đương&quot;&gt;Chứng minh Đặc trưng Tương đương&lt;/h3&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý&lt;/strong&gt;: Hàm \(g(x) = \frac{L}{2} \| x \|^2_2 - f(x)\) là hàm lồi.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Chứng minh&lt;/strong&gt;: Ta cần chứng minh \(\nabla^2 g(x) \succeq 0\) (nửa xác định dương).&lt;/p&gt;

&lt;p&gt;Từ \(g(x) = \frac{L}{2} \| x \|^2_2 - f(x)\), ta có:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\nabla g(x) = Lx - \nabla f(x)\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla^2 g(x) = LI - \nabla^2 f(x)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Với mọi vector \(v\), xét dạng toàn phương \(v^T \nabla^2 g(x) v\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
v^T \nabla^2 g(x) v &amp;amp;= v^T (LI - \nabla^2 f(x)) v \\
&amp;amp;= L\|v\|^2 - v^T \nabla^2 f(x) v
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do \(\nabla f\) liên tục Lipschitz với hằng số \(L\), ta có \(\nabla^2 f(x) \preceq LI\), nghĩa là:
\(v^T \nabla^2 f(x) v \le L\|v\|^2\)&lt;/p&gt;

&lt;p&gt;Từ đó suy ra \(v^T \nabla^2 g(x) v = L\|v\|^2 - v^T \nabla^2 f(x) v \ge 0\).&lt;/p&gt;

&lt;p&gt;Vậy \(g\) là hàm lồi. \(\square\)&lt;/p&gt;

&lt;h2 id=&quot;các-ví-dụ&quot;&gt;Các Ví dụ&lt;/h2&gt;

&lt;h3 id=&quot;ví-dụ-1-hàm-bậc-hai&quot;&gt;Ví dụ 1: Hàm Bậc hai&lt;/h3&gt;

&lt;p&gt;Xét \(f(x) = \frac{1}{2}x^T A x + b^T x + c\) với \(A \succeq 0\) (nửa xác định dương).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[\nabla f(x) = Ax + b\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla^2 f(x) = A\]
  &lt;/li&gt;
  &lt;li&gt;Với \(\lambda_{max}(A) = L\), ta có \(\|\nabla f(x) - \nabla f(y)\| = \|A(x-y)\| \le L\|x-y\|\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cận trên bậc hai có dạng:
\(f(y) \le f(x) + (Ax + b)^T(y-x) + \frac{L}{2}\|y-x\|^2\)&lt;/p&gt;

&lt;p&gt;Đối với hàm bậc hai, cận này là &lt;strong&gt;chặt&lt;/strong&gt; khi \(L = \lambda_{max}(A)\).&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-2-hàm-mất-mát-logistic&quot;&gt;Ví dụ 2: Hàm Mất mát Logistic&lt;/h3&gt;

&lt;p&gt;Xét hàm mất mát logistic \(f(x) = \log(1 + e^{a^T x})\) với \(a \in \mathbb{R}^n\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[\nabla f(x) = \frac{e^{a^T x}}{1 + e^{a^T x}} a = \sigma(a^T x) a\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla^2 f(x) = \sigma(a^T x)(1 - \sigma(a^T x)) aa^T\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vì \(\sigma(t)(1-\sigma(t)) \le \frac{1}{4}\) với mọi \(t\), ta có:
\(\nabla^2 f(x) \preceq \frac{1}{4} aa^T \preceq \frac{\|a\|^2}{4} I\)&lt;/p&gt;

&lt;p&gt;Do đó, \(L = \frac{\|a\|^2}{4}\) và cận trên bậc hai là:
\(f(y) \le f(x) + \sigma(a^T x) a^T(y-x) + \frac{\|a\|^2}{8}\|y-x\|^2\)&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-3-bài-toán-bình-phương-tối-thiểu&quot;&gt;Ví dụ 3: Bài toán Bình phương Tối thiểu&lt;/h3&gt;

&lt;p&gt;Với \(f(x) = \frac{1}{2}\|Ax - b\|^2\) trong đó \(A \in \mathbb{R}^{m \times n}\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[\nabla f(x) = A^T(Ax - b)\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla^2 f(x) = A^T A\]
  &lt;/li&gt;
  &lt;li&gt;\(L = \lambda_{max}(A^T A) = \sigma_{max}^2(A)\) (bình phương giá trị kỳ dị lớn nhất của \(A\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cận trên bậc hai có dạng:
\(f(y) \le f(x) + (A^T(Ax - b))^T(y-x) + \frac{\sigma_{max}^2(A)}{2}\|y-x\|^2\)&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong Tối ưu hóa&lt;/h2&gt;

&lt;h3 id=&quot;1-chọn-kích-thước-bước-cho-gradient-descent&quot;&gt;1. Chọn Kích thước Bước cho Gradient Descent&lt;/h3&gt;

&lt;p&gt;Cận trên bậc hai cho phép xác định trực tiếp ngưỡng kích thước bước an toàn. Nếu chọn \(\alpha \le \frac{1}{L}\), ta có:&lt;/p&gt;

\[f(x - \alpha \nabla f(x)) \le f(x) - \alpha \|\nabla f(x)\|^2 + \frac{L\alpha^2}{2}\|\nabla f(x)\|^2\]

&lt;p&gt;Khi \(\alpha \le \frac{1}{L}\), vế phải được thu gọn thành:
\(f(x - \alpha \nabla f(x)) \le f(x) - \frac{\alpha}{2}\|\nabla f(x)\|^2\)&lt;/p&gt;

&lt;p&gt;Bất đẳng thức này đảm bảo hàm mục tiêu &lt;strong&gt;giảm đủ&lt;/strong&gt; sau mỗi lần lặp.&lt;/p&gt;

&lt;h3 id=&quot;2-phân-tích-tốc-độ-hội-tụ&quot;&gt;2. Phân tích Tốc độ Hội tụ&lt;/h3&gt;

&lt;p&gt;Với gradient descent dùng bước \(\alpha = \frac{1}{L}\) trên hàm \(\mu\)-lồi mạnh, cận trên bậc hai giúp chứng minh:&lt;/p&gt;

\[f(x_{k+1}) - f^* \le \left(1 - \frac{\mu}{L}\right)(f(x_k) - f^*)\]

&lt;p&gt;trong đó \(\mu\) là hằng số lồi mạnh. Kết quả này cho thấy thuật toán đạt &lt;strong&gt;hội tụ tuyến tính&lt;/strong&gt; với hệ số co \(\left(1 - \frac{\mu}{L}\right)\).&lt;/p&gt;

&lt;h3 id=&quot;3-phương-pháp-gradient-gần-kề-proximal-gradient&quot;&gt;3. Phương pháp Gradient Gần kề (Proximal Gradient)&lt;/h3&gt;

&lt;p&gt;Đối với bài toán tối ưu hợp \(\min_x f(x) + g(x)\) gồm phần trơn \(f\) và phần không trơn \(g\), cận trên bậc hai của \(f\) dẫn đến bước cập nhật gradient gần kề:&lt;/p&gt;

\[x_{k+1} = \text{prox}_{\alpha g}\left(x_k - \alpha \nabla f(x_k)\right)\]

&lt;p&gt;trong đó điều kiện \(\alpha \le \frac{1}{L}\) đảm bảo hội tụ.&lt;/p&gt;

&lt;h3 id=&quot;4-các-phương-pháp-tăng-tốc&quot;&gt;4. Các Phương pháp Tăng tốc&lt;/h3&gt;

&lt;p&gt;Những thuật toán tăng tốc như &lt;strong&gt;gradient tăng tốc Nesterov&lt;/strong&gt; và &lt;strong&gt;FISTA&lt;/strong&gt; cũng dựa trên cận trên bậc hai để đạt tốc độ hội tụ tối ưu \(O(1/k^2)\) trên lớp hàm lồi trơn.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt-các-điểm-chính&quot;&gt;Tóm tắt Các Điểm Chính&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất nền tảng&lt;/strong&gt;: Cận trên bậc hai là trụ cột của lý thuyết tối ưu hóa lồi trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thiết kế thuật toán&lt;/strong&gt;: Cung cấp cơ sở lý thuyết để chọn kích thước bước trong các phương pháp bậc nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích hội tụ&lt;/strong&gt;: Cho phép chứng minh chặt chẽ tốc độ hội tụ của nhiều thuật toán tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa thực hành&lt;/strong&gt;: Ước lượng hằng số \(L\) giúp điều chỉnh siêu tham số hiệu quả hơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trực giác hình học&lt;/strong&gt;: Hình thức hóa nhận định rằng hàm lồi trơn có độ cong bị chặn trên và luôn nằm dưới một parabol bậc hai.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;minh-họa-hình-học&quot;&gt;Minh họa Hình học&lt;/h2&gt;

&lt;p&gt;Sơ đồ dưới đây minh họa quan hệ giữa hàm thực, xấp xỉ tuyến tính và cận trên bậc hai:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;      f(y)
        |
        |     Cận Trên Bậc Hai
        |    f(x) + ∇f(x)ᵀ(y-x) + (L/2)||y-x||²
        |   /
        |  /
        | /     Hàm thực f(y)
        |/     /
       /|     /
      / |    /
     /  |   /    Xấp xỉ Tuyến tính
    /   |  /     f(x) + ∇f(x)ᵀ(y-x)
   /    | /
  /     |/
 /      x        y
/       |         →
        |
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Nhận xét chính&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ tuyến tính&lt;/strong&gt; (đường tiếp tuyến) luôn nằm dưới \(f(y)\) do tính lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cận trên bậc hai&lt;/strong&gt; luôn nằm trên \(f(y)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm thực&lt;/strong&gt; \(f(y)\) nằm kẹp giữa hai cận này.&lt;/li&gt;
  &lt;li&gt;Khoảng cách giữa hai cận phụ thuộc vào hằng số Lipschitz \(L\) và bình phương khoảng cách \(\|y-x\|^2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;cân-nhắc-khi-triển-khai&quot;&gt;Cân nhắc khi Triển khai&lt;/h2&gt;

&lt;h3 id=&quot;ước-lượng-hằng-số-lipschitz&quot;&gt;Ước lượng Hằng số Lipschitz&lt;/h3&gt;

&lt;p&gt;Trong thực tế, việc xác định chính xác hằng số Lipschitz \(L\) thường không đơn giản. Các cách tiếp cận phổ biến gồm:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giải tích&lt;/strong&gt;: Áp dụng cho các lớp hàm cụ thể (bậc hai, logistic, bình phương tối thiểu…).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp phổ&lt;/strong&gt;: Tính \(L = \lambda_{max}(\nabla^2 f)\) khi có thể tính ma trận Hessian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng thích ứng&lt;/strong&gt;: Khởi tạo một ước lượng ban đầu rồi điều chỉnh dần dựa trên điều kiện giảm đủ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường&lt;/strong&gt;: Dùng tìm kiếm đường lùi (backtracking) để tự động tìm bước nhảy phù hợp.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;cài-đặt-minh-họa&quot;&gt;Cài đặt Minh họa&lt;/h3&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gradient_descent_with_lipschitz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grad_f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L_estimate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;
    Gradient descent với ước lượng hằng số Lipschitz thích ứng
    &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L_estimate&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;grad_f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;c1&quot;&gt;# Thử bước với ước lượng L hiện tại
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x_new&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;
        
        &lt;span class=&quot;c1&quot;&gt;# Kiểm tra điều kiện giảm đủ
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x_new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x_new&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Chấp nhận bước
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Tăng ước lượng L và thử lại
&lt;/span&gt;            &lt;span class=&quot;k&quot;&gt;continue&lt;/span&gt;
            
        &lt;span class=&quot;c1&quot;&gt;# Tùy chọn: giảm L nếu bước quá bảo thủ
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.9&lt;/span&gt;
            
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Cách tiếp cận thích ứng này đảm bảo hàm mục tiêu giảm ổn định đồng thời tự động hiệu chỉnh ước lượng hằng số Lipschitz \(L\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-02 Cách chọn kích thước bước</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_02_how_to_choose_step_sizes/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_02_how_to_choose_step_sizes</id>
   <content type="html">&lt;p&gt;Biết hướng đi \(-\nabla f(x)\) mới chỉ là một nửa câu chuyện của Gradient Descent; nửa quyết định thành bại còn lại là câu hỏi: &lt;strong&gt;đi theo hướng đó bao xa?&lt;/strong&gt; Một tay đua công thức 1 không thể giữ cùng một tốc độ trên đường thẳng và khúc cua gắt; tương tự, một thuật toán tối ưu giỏi phải biết lúc nào nên sải bước dài và lúc nào phải hãm phanh lại.&lt;/p&gt;

&lt;p&gt;Mục 06-02 đặt ba chiến lược chọn kích thước bước lên cùng một bàn cân so sánh: &lt;strong&gt;bước cố định (Fixed Step Size)&lt;/strong&gt; đơn giản nhưng mạo hiểm nếu không biết \(L\), &lt;strong&gt;Tìm kiếm đường lùi (Backtracking Line Search)&lt;/strong&gt; linh hoạt và cực kỳ phổ biến trong thực chiến, và &lt;strong&gt;Tìm kiếm đường chính xác (Exact Line Search)&lt;/strong&gt; lý tưởng về mặt lý thuyết nhưng đắt đỏ ở bài toán tổng quát.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-triết-lý-chọn-kích-thước-bước-trong-gradient-descent&quot;&gt;Kiến thức cần nhớ: Ba triết lý chọn kích thước bước trong Gradient Descent&lt;/h2&gt;

&lt;p&gt;Để chọn đúng chiến lược cho từng bài toán thực tế, hãy nhìn rõ sự đánh đổi giữa ba phương pháp:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bước cố định (Fixed Step Size):&lt;/strong&gt; Đặt \(t_k = t\) cho mọi bước. Chi phí chọn bước bằng \(0\), nhưng đòi hỏi biết trước hằng số trơn \(L\) (để chọn \(t \le 1/L\)). Nếu đoán sai \(t &amp;gt; 2/L\), thuật toán phân kỳ ngay lập tức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường lùi (Backtracking / Armijo Line Search):&lt;/strong&gt; Bắt đầu thử bước lớn \(t = 1\) (hoặc \(t_0\)), rồi nhân thu nhỏ dần \(t \leftarrow \beta t\) cho đến khi thỏa điều kiện giảm đủ \(f(x - t\nabla f(x)) \le f(x) - \alpha t \|\nabla f(x)\|_2^2\). Không cần biết \(L\) trước, tự động thích ứng với độ cong địa phương!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường chính xác (Exact Line Search):&lt;/strong&gt; Giải bài toán tối ưu 1 chiều \(t_k = \arg\min_{s &amp;gt; 0} f(x_k - s\nabla f(x_k))\) tại mỗi bước. Chỉ dùng hiệu quả khi có công thức đóng (như hàm bậc hai \(f(x) = \frac{1}{2}x^T Q x + b^T x\)); trên hàm phi tuyến tổng quát, chi phí giải bài toán 1D thường tốn kém hơn lợi ích mang lại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-3-chiến-lược-bước-trên-cùng-một-điểm-xuất-phát&quot;&gt;Giải thích: So sánh 3 chiến lược bước trên cùng một điểm xuất phát&lt;/h3&gt;

&lt;p&gt;Xét hàm \(f(x) = \frac{1}{2} x^2\) tại \(x_0 = 4\), nơi \(f(4) = 8\) và \(f&apos;(4) = 4\) (nghiệm đúng là \(x^\star = 0\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước cố định \(t = 0.25\):&lt;/strong&gt;
\(x_1 = 4 - 0.25(4) = 3, \qquad f(x_1) = 4.5\) (giảm \(3.5\) đơn vị).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường lùi với \(t_0 = 2,\; \alpha = 0.5,\; \beta = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Thử \(t = 2\): \(x_{\text{try}} = 4 - 8 = -4\), \(f(-4) = 8\). Kiểm tra Armijo: \(8 \le 8 - 0.5(2)(16) = -8\)? &lt;strong&gt;Sai!&lt;/strong&gt; Thu nhỏ \(t \leftarrow 1\).&lt;/li&gt;
      &lt;li&gt;Thử \(t = 1\): \(x_{\text{try}} = 4 - 4 = 0\), \(f(0) = 0\). Kiểm tra Armijo: \(0 \le 8 - 0.5(1)(16) = 0\)? &lt;strong&gt;Đúng!&lt;/strong&gt; Chấp nhận \(t_0 = 1 \implies x_1 = 0\) (đạt đích ngay!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường chính xác:&lt;/strong&gt;
Giải \(\min_{s &amp;gt; 0} \frac{1}{2}(4 - 4s)^2\) cho đạo hàm \(-4(4 - 4s) = 0 \implies s^\star = 1 \implies x_1 = 0\).
Nhận xét: Backtracking tự động “cứu” thuật toán khỏi bước phân kỳ \(t_0 = 2\) chỉ sau 1 lần co bước mà không hề cần biết trước \(L = 1\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Khi thực hiện gradient descent, &lt;strong&gt;kích thước bước&lt;/strong&gt; quyết định mức độ cập nhật của biến \(x\) ở mỗi lần lặp, qua đó ảnh hưởng trực tiếp đến tốc độ và khả năng hội tụ về nghiệm tối ưu. Mục này giới thiệu ba phương pháp chính để lựa chọn kích thước bước:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Kích thước bước cố định (fixed step size)&lt;/li&gt;
  &lt;li&gt;Tìm kiếm đường lùi (backtracking line search)&lt;/li&gt;
  &lt;li&gt;Tìm kiếm đường chính xác (exact line search)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-02-03 Tìm kiếm đường chính xác</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_02_03_exact_line_search/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_02_03_exact_line_search</id>
   <content type="html">&lt;p&gt;Nếu bạn đứng trên sườn núi và đã chọn xong hướng đi \(-\nabla f(x_k)\), câu hỏi tham lam nhất có thể đặt ra là: &lt;em&gt;trên tia thẳng xuất phát từ \(x_k\) theo hướng \(-\nabla f(x_k)\), điểm nào có cao độ thấp nhất tuyệt đối?&lt;/em&gt; Tìm ra chính xác điểm đáy dọc theo tia đó gọi là &lt;strong&gt;Tìm kiếm đường chính xác (Exact Line Search)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Nghe qua tưởng chừng đây phải là chiến lược “vô địch” — nhưng hình học lại dành cho ta một cú ngoặt đầy bất ngờ: vì tại điểm đáy của tia tìm kiếm, tia đó &lt;strong&gt;tiếp xúc&lt;/strong&gt; với đường đồng mức của \(f\), nên gradient ở bước kế tiếp sẽ &lt;strong&gt;vuông góc hoàn toàn&lt;/strong&gt; với gradient bước hiện tại (\(\nabla f(x_{k+1})^T \nabla f(x_k) = 0\))! Kết quả là quỹ đạo của Exact Line Search trên các thung lũng elip hẹp tạo thành những đường gấp khúc &lt;strong&gt;vuông góc 90°&lt;/strong&gt; kinh điển!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-trực-giao-và-công-thức-đóng-của-exact-line-search&quot;&gt;Kiến thức cần nhớ: Hình học trực giao và Công thức đóng của Exact Line Search&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau tóm gọn toàn bộ bản chất toán học của Exact Line Search:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện trực giao giữa hai bước liên tiếp:&lt;/strong&gt; Đặt \(\phi(s) = f(x_k - s g_k)\) với \(g_k = \nabla f(x_k)\). Tại bước tối ưu \(t_k = \arg\min_{s &amp;gt; 0} \phi(s)\), đạo hàm \(\phi&apos;(t_k) = -\nabla f(x_k - t_k g_k)^T g_k = -g_{k+1}^T g_k = 0\). Vậy hai hướng bước liên tiếp luôn &lt;strong&gt;vuông góc tuyệt đối&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Công thức đóng cho hàm bậc hai:&lt;/strong&gt; Với \(f(x) = \frac{1}{2} x^T Q x - b^T x\) (\(Q \succ 0\)), giải \(\phi&apos;(s) = 0\) cho ngay công thức nghiệm đóng tuyệt đẹp:
\(t_k = \frac{g_k^T g_k}{g_k^T Q g_k} = \frac{\|g_k\|_2^2}{g_k^T Q g_k}.\)
Lưu ý: chỉ cần 1 phép nhân ma trận–vector \(Q g_k\) để tính chính xác \(t_k\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ hội tụ &amp;amp; Bất đẳng thức Kantorovich:&lt;/strong&gt; Với hàm bậc hai có chỉ số điều kiện \(\kappa = \lambda_{\max}/\lambda_{\min}\), Exact Line Search đạt tỷ lệ giảm sai số mỗi bước bị chặn bởi \(\left(\frac{\kappa - 1}{\kappa + 1}\right)^2\). Nếu \(\kappa = 1000\), tỷ lệ này là \(0.996\) — dù tìm bước chính xác 100%, thuật toán vẫn bị bẫy zíc-zắc vuông góc làm chậm lại!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-2-bước-exact-line-search-và-kiểm-chứng-góc-vuông-90&quot;&gt;Giải thích: Chạy tay 2 bước Exact Line Search và kiểm chứng góc vuông 90°&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + 4x_2^2)\) với \(Q = \begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 4 \end{pmatrix}\), xuất phát từ \(x_0 = (4, 1)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(k = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient: \(g_0 = Q x_0 = (4,\; 4)^T \implies \|g_0\|_2^2 = 16 + 16 = 32\).&lt;/li&gt;
      &lt;li&gt;Mẫu số: \(g_0^T Q g_0 = 1(4)^2 + 4(4)^2 = 16 + 64 = 80\).&lt;/li&gt;
      &lt;li&gt;Bước tối ưu chính xác: \(t_0 = \frac{32}{80} = 0.4\).&lt;/li&gt;
      &lt;li&gt;Cập nhật: \(x_1 = (4, 1)^T - 0.4(4, 4)^T = (2.4,\; -0.6)^T\).&lt;/li&gt;
      &lt;li&gt;Giá trị hàm: giảm từ \(f(x_0) = \frac{1}{2}(16 + 4) = 10\) xuống \(f(x_1) = \frac{1}{2}(5.76 + 1.44) = 3.6\) (tỷ lệ \(3.6/10 = 0.36 = \left(\frac{4-1}{4+1}\right)^2\) — khớp chính xác tuyệt đối với định lý Kantorovich!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(k = 1\) &amp;amp; Kiểm chứng trực giao:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient mới: \(g_1 = Q x_1 = (2.4,\; -2.4)^T\).&lt;/li&gt;
      &lt;li&gt;Tích vô hướng \(g_1^T g_0 = (2.4)(4) + (-2.4)(4) = 9.6 - 9.6 = 0\)! Hai hướng đi &lt;strong&gt;vuông góc chính xác 90°&lt;/strong&gt;!&lt;/li&gt;
      &lt;li&gt;Bước mới: \(t_1 = \frac{2.4^2 + 2.4^2}{1(2.4)^2 + 4(2.4)^2} = \frac{2}{5} = 0.4\), cho \(x_2 = (1.44,\; 0.36)^T\) và \(f(x_2) = 1.296 = 0.36 \cdot f(x_1)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Một cách tiếp cận khác để chọn kích thước bước thích ứng trong gradient descent là &lt;strong&gt;tìm kiếm đường chính xác (exact line search)&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;tìm-kiếm-đường-chính-xác-là-gì&quot;&gt;Tìm kiếm Đường chính xác là gì?&lt;/h3&gt;

&lt;p&gt;Trong tìm kiếm đường chính xác, tại mỗi bước lặp ta di chuyển dọc theo hướng ngược chiều gradient và chọn kích thước bước tối ưu nhất trên tia tìm kiếm đó.&lt;/p&gt;

&lt;p&gt;Với \(s \ge 0\), điểm \(x - s \nabla f(x)\) dịch chuyển từ vị trí hiện tại theo hướng \(-\nabla f(x)\). Bằng cách cực tiểu hóa hàm mục tiêu theo \(s\), ta xác định kích thước bước \(t\) tối ưu:&lt;/p&gt;

&lt;blockquote&gt;
\[t = \arg\min_{s \ge 0} f(x - s \nabla f(x))\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;thuật-toán-exact-line-search&quot;&gt;Thuật toán Exact Line Search&lt;/h2&gt;

&lt;p&gt;Thuật toán gồm bốn bước lặp:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1&lt;/strong&gt;: Tại điểm hiện tại \(x^{(k)}\), tính gradient \(\nabla f(x^{(k)})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2&lt;/strong&gt;: Định nghĩa hàm một biến \(\phi(t) = f(x^{(k)} - t \nabla f(x^{(k)}))\) với \(t \geq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3&lt;/strong&gt;: Tìm \(t^* = \arg\min_{t \geq 0} \phi(t)\) bằng cách giải phương trình \(\phi&apos;(t) = 0\) (và kiểm tra điều kiện cực tiểu).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4&lt;/strong&gt;: Cập nhật \(x^{(k+1)} = x^{(k)} - t^* \nabla f(x^{(k)})\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;các-ví-dụ-minh-họa&quot;&gt;Các Ví dụ Minh họa&lt;/h2&gt;

&lt;h3 id=&quot;ví-dụ-1-hàm-bậc-hai-một-biến-cơ-bản&quot;&gt;Ví dụ 1: Hàm Bậc hai Một biến (Cơ bản)&lt;/h3&gt;

&lt;p&gt;Xét hàm mục tiêu:
\(f(x) = \frac{1}{2}x^2 - 3x + 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 1&lt;/strong&gt;: Tính gradient
\(\nabla f(x) = x - 3\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 2&lt;/strong&gt;: Tại điểm xuất phát \(x^{(0)} = 0\), ta có \(\nabla f(0) = -3\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 3&lt;/strong&gt;: Xây dựng hàm tìm kiếm đường
\(\phi(t) = f(0 - t(-3)) = f(3t) = \frac{1}{2}(3t)^2 - 3(3t) + 2 = \frac{9t^2}{2} - 9t + 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 4&lt;/strong&gt;: Tìm cực tiểu bằng cách lấy đạo hàm
\(\phi&apos;(t) = 9t - 9 = 0 \Rightarrow t^* = 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 5&lt;/strong&gt;: Cập nhật
\(x^{(1)} = 0 - 1 \cdot (-3) = 3\)&lt;/p&gt;

&lt;p&gt;Kết quả: Chỉ sau một bước, thuật toán đã tìm được nghiệm tối ưu \(x^* = 3\) (vì \(\nabla f(3) = 0\)).&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-2-hàm-bậc-hai-nhiều-biến-trung-bình&quot;&gt;Ví dụ 2: Hàm Bậc hai Nhiều biến (Trung bình)&lt;/h3&gt;

&lt;p&gt;Xét hàm mục tiêu:
\(f(x_1, x_2) = x_1^2 + 2x_2^2 - 2x_1 - 4x_2 + 3\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 1&lt;/strong&gt;: Tính gradient
\(\nabla f(x_1, x_2) = \begin{pmatrix} 2x_1 - 2 \\ 4x_2 - 4 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 2&lt;/strong&gt;: Tại điểm xuất phát \(x^{(0)} = (0, 0)\)
\(\nabla f(0, 0) = \begin{pmatrix} -2 \\ -4 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 3&lt;/strong&gt;: Xây dựng hàm tìm kiếm đường
\(x^{(0)} - t \nabla f(x^{(0)}) = \begin{pmatrix} 0 \\ 0 \end{pmatrix} - t \begin{pmatrix} -2 \\ -4 \end{pmatrix} = \begin{pmatrix} 2t \\ 4t \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;\(\phi(t) = f(2t, 4t) = (2t)^2 + 2(4t)^2 - 2(2t) - 4(4t) + 3\)
\(= 4t^2 + 32t^2 - 4t - 16t + 3 = 36t^2 - 20t + 3\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 4&lt;/strong&gt;: Tìm cực tiểu
\(\phi&apos;(t) = 72t - 20 = 0 \Rightarrow t^* = \frac{20}{72} = \frac{5}{18}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 5&lt;/strong&gt;: Cập nhật
\(x^{(1)} = \begin{pmatrix} 2 \cdot \frac{5}{18} \\ 4 \cdot \frac{5}{18} \end{pmatrix} = \begin{pmatrix} \frac{5}{9} \\ \frac{10}{9} \end{pmatrix}\)&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-3-hàm-rosenbrock-2d-khó&quot;&gt;Ví dụ 3: Hàm Rosenbrock 2D (Khó)&lt;/h3&gt;

&lt;p&gt;Xét hàm Rosenbrock:
\(f(x_1, x_2) = 100(x_2 - x_1^2)^2 + (1 - x_1)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 1&lt;/strong&gt;: Tính gradient
\(\nabla f(x_1, x_2) = \begin{pmatrix} -400x_1(x_2 - x_1^2) - 2(1 - x_1) \\ 200(x_2 - x_1^2) \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 2&lt;/strong&gt;: Tại điểm xuất phát \(x^{(0)} = (-1, 1)\)
\(\nabla f(-1, 1) = \begin{pmatrix} -400(-1)(1 - 1) - 2(1 - (-1)) \\ 200(1 - 1) \end{pmatrix} = \begin{pmatrix} -4 \\ 0 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 3&lt;/strong&gt;: Xây dựng hàm tìm kiếm đường
\(x^{(0)} - t \nabla f(x^{(0)}) = \begin{pmatrix} -1 \\ 1 \end{pmatrix} - t \begin{pmatrix} -4 \\ 0 \end{pmatrix} = \begin{pmatrix} -1 + 4t \\ 1 \end{pmatrix}\)&lt;/p&gt;

\[\phi(t) = f(-1 + 4t, 1) = 100(1 - (-1 + 4t)^2)^2 + (1 - (-1 + 4t))^2\]

&lt;p&gt;Hàm một biến này là đa thức bậc bốn phức tạp, nên cần dùng phương pháp số để tìm cực tiểu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nhận xét&lt;/strong&gt;: Với hàm Rosenbrock, tìm kiếm đường chính xác trở nên tốn kém vì:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu không có dạng bậc hai đơn giản.&lt;/li&gt;
  &lt;li&gt;Cần áp dụng phương pháp số như Newton–Raphson để giải \(\phi&apos;(t) = 0\).&lt;/li&gt;
  &lt;li&gt;Có thể tồn tại nhiều điểm dừng cục bộ dọc theo tia tìm kiếm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-4-bài-toán-có-ràng-buộc-miền-rất-khó&quot;&gt;Ví dụ 4: Bài toán Có Ràng buộc Miền (Rất khó)&lt;/h3&gt;

&lt;p&gt;Xét bài toán:
\(\min f(x) = x_1^2 + x_2^2 - 2x_1x_2\)
với ràng buộc \(x_1, x_2 \geq 0\).&lt;/p&gt;

&lt;p&gt;Trong trường hợp này, tìm kiếm đường chính xác phải giải bài toán có ràng buộc:
\(t^* = \arg\min_{t \geq 0} f(x^{(k)} - t \nabla f(x^{(k)}))\)
sao cho \(x^{(k)} - t \nabla f(x^{(k)}) \geq 0\).&lt;/p&gt;

&lt;p&gt;Ràng buộc miền làm cho việc xác định kích thước bước chính xác trở nên phức tạp hơn.&lt;/p&gt;

&lt;h2 id=&quot;ưu-điểm-và-nhược-điểm&quot;&gt;Ưu điểm và Nhược điểm&lt;/h2&gt;

&lt;h3 id=&quot;ưu-điểm&quot;&gt;Ưu điểm:&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu theo hướng hiện tại&lt;/strong&gt;: Mỗi bước đảm bảo giảm tối đa giá trị hàm mục tiêu dọc theo hướng ngược chiều gradient.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ nhanh trong trường hợp đặc biệt&lt;/strong&gt;: Đối với hàm bậc hai một biến hoặc hàm bậc hai đẳng hướng, thuật toán hội tụ chỉ sau một bước.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không cần tinh chỉnh tốc độ học&lt;/strong&gt;: Loại bỏ nhu cầu chọn trước tham số tốc độ học cố định.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;nhược-điểm&quot;&gt;Nhược điểm:&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí tính toán cao&lt;/strong&gt;: Mỗi lần lặp đòi hỏi giải một bài toán tối ưu một biến.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phức tạp với hàm phi tuyến&lt;/strong&gt;: Cần dùng phương pháp giải số để tìm cực tiểu của \(\phi(t)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kém thực tế với bài toán quy mô lớn&lt;/strong&gt;: Chi phí đánh giá hàm ở mỗi bước quá cao.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;khi-nào-nên-dùng-tìm-kiếm-đường-chính-xác&quot;&gt;Khi nào Nên Dùng Tìm kiếm Đường chính xác?&lt;/h2&gt;

&lt;p&gt;Tìm kiếm đường chính xác phù hợp khi:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mục tiêu đơn giản&lt;/strong&gt; (ví dụ: hàm bậc hai có công thức nghiệm đóng cho \(t^*\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số chiều nhỏ&lt;/strong&gt; (thường \(\le 10\) biến).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Yêu cầu độ chính xác cao&lt;/strong&gt; và có thể chấp nhận chi phí tính toán lớn hơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mục tiêu có cấu trúc đặc biệt&lt;/strong&gt; cho phép giải tích trực tiếp.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Trong thực tế, &lt;strong&gt;tìm kiếm đường lùi (backtracking line search)&lt;/strong&gt; thường hiệu quả hơn và được sử dụng phổ biến hơn cho đa số ứng dụng.&lt;/p&gt;

&lt;h3 id=&quot;tìm-kiếm-đường-lùi-và-chính-xác-trong-khoảng-3-phút&quot;&gt;Tìm kiếm đường lùi và chính xác trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/line-search_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Bước cố định quá nhỏ hay quá lớn, điều kiện Armijo và các lần lùi t ← βt, so với tìm kiếm chính xác trên ví dụ của bài.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-02-02 Tìm kiếm đường lùi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_02_02_backtracking_line_search/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_02_02_backtracking_line_search</id>
   <content type="html">&lt;p&gt;Trong hầu hết các bài toán tối ưu phi tuyến thực tế (như hồi quy logistic hay tối ưu hàm log-sum-exp), việc tính trước hằng số Lipschitz toàn cục \(L\) rất khó, hoặc \(L\) toàn cục quá lớn so với độ cong thực tế ở vùng thuật toán đang đi qua. Nếu chọn bước cố định \(1/L\) toàn cục, bạn buộc phải “bò từng milimet” ngay cả trên những vùng phẳng rộng thênh thang!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tìm kiếm đường lùi (Backtracking Line Search / Điều kiện Armijo)&lt;/strong&gt; giải quyết triệt để vấn đề này bằng một cơ chế thông minh đến kinh ngạc: ở mỗi bước, cứ mạnh dạn thử bước dài \(t = 1\) trước; chỉ khi thấy hàm mục tiêu &lt;em&gt;không giảm đủ mạnh&lt;/em&gt; so với kỳ vọng tuyến tính, ta mới rút ngắn bước đi theo hệ số \(\beta \in (0, 1)\) cho đến khi đạt chuẩn!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cơ-chế-đường-thẳng-armijo-trong-backtracking&quot;&gt;Kiến thức cần nhớ: Cơ chế “Đường thẳng Armijo” trong Backtracking&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/chapter06/06_02_02_f_geq_app.png&quot; alt=&quot;Cận dưới tuyến tính và điều kiện Armijo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/chapter06/06_02_02_f_leq_app.png&quot; alt=&quot;Cận trên bậc hai cho bước nhảy hợp lệ&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Ba trụ cột sau làm rõ ý nghĩa hình học và cách chọn tham số của Backtracking Line Search:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện giảm đủ Armijo (Sufficient Decrease Condition):&lt;/strong&gt; Với \(\alpha \in (0, 0.5]\) (thường chọn \(\alpha = 0.01 \text{ đến } 0.3\)), ta chấp nhận bước \(t\) khi:
\(f(x - t\nabla f(x)) \le f(x) - \alpha t \|\nabla f(x)\|_2^2.\)
Về mặt hình học, vế phải là một đường thẳng có độ dốc &lt;em&gt;thoai thoải hơn&lt;/em&gt; tiếp tuyến tại \(x\) (chỉ lấy một phần \(\alpha\) của độ dốc ban đầu). Ta chỉ cần đồ thị hàm số nằm &lt;strong&gt;dưới&lt;/strong&gt; đường thẳng này!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại sao vòng lặp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;while&lt;/code&gt; luôn dừng sau hữu hạn bước?&lt;/strong&gt; Vì theo khai triển Taylor bậc nhất, với \(t\) đủ nhỏ ta có \(f(x - t\nabla f(x)) \approx f(x) - t\|\nabla f(x)\|_2^2 &amp;lt; f(x) - \alpha t\|\nabla f(x)\|_2^2\) (do \(\alpha &amp;lt; 1\)). Thậm chí với hàm \(L\)-trơn, điều kiện chắc chắn thỏa mãn ngay khi \(t \le \frac{2(1-\alpha)}{L}\) (hoặc \(t \le 1/L\) khi \(\alpha \le 0.5\))!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn tham số \(\alpha\) và \(\beta\) trong thực tế:&lt;/strong&gt; \(\beta \in (0, 1)\) là hệ số co bước (thường chọn \(\beta = 0.5\) hoặc \(0.8\)). Chọn \(\beta\) lớn (như \(0.8\)) tìm được bước sát tối ưu hơn nhưng tốn nhiều lần thử hàm hơn; \(\beta = 0.5\) là điểm cân bằng kinh điển vừa nhanh vừa chắc chắn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-vòng-lặp-backtracking-line-search-từng-phép-thử&quot;&gt;Giải thích: Chạy tay vòng lặp Backtracking Line Search từng phép thử&lt;/h3&gt;

&lt;p&gt;Xét hàm \(f(x) = x^2 + e^x\) tại \(x = 1\). Ta có:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(1) = 1 + e \approx 3.7183\).&lt;/li&gt;
  &lt;li&gt;\(f&apos;(1) = 2(1) + e \approx 4.7183\), suy ra \((f&apos;(1))^2 \approx 22.262\).
Dùng Backtracking với \(t_{\text{init}} = 1,\; \alpha = 0.3,\; \beta = 0.5\). Điều kiện cần thỏa:
\(f(1 - 4.7183 t) \le 3.7183 - 0.3 \cdot t \cdot 22.262 = 3.7183 - 6.6786 t.\)&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lần thử 1 (\(t = 1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Điểm thử: \(x_{\text{try}} = 1 - 4.7183 = -3.7183\).&lt;/li&gt;
      &lt;li&gt;Vế trái: \(f(-3.7183) = (-3.7183)^2 + e^{-3.7183} \approx 13.826 + 0.024 = 13.850\).&lt;/li&gt;
      &lt;li&gt;Vế phải: \(3.7183 - 6.6786 = -2.960\).&lt;/li&gt;
      &lt;li&gt;So sánh: \(13.850 \le -2.960\)? &lt;strong&gt;Sai!&lt;/strong&gt; (Bước \(t=1\) nhảy quá đà lên tận \(13.85\)!). Co bước \(t \leftarrow 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lần thử 2 (\(t = 0.5\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Điểm thử: \(x_{\text{try}} = 1 - 2.3591 = -1.3591\).&lt;/li&gt;
      &lt;li&gt;Vế trái: \(f(-1.3591) \approx 1.847 + 0.257 = 2.104\).&lt;/li&gt;
      &lt;li&gt;Vế phải: \(3.7183 - 3.3393 = 0.379\).&lt;/li&gt;
      &lt;li&gt;So sánh: \(2.104 \le 0.379\)? &lt;strong&gt;Sai!&lt;/strong&gt; (Dù hàm đã giảm từ \(3.72\) xuống \(2.10\), mức giảm chưa đạt chuẩn Armijo!). Co bước \(t \leftarrow 0.25\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lần thử 3 (\(t = 0.25\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Điểm thử: \(x_{\text{try}} = 1 - 1.1796 = -0.1796\).&lt;/li&gt;
      &lt;li&gt;Vế trái: \(f(-0.1796) \approx 0.032 + 0.836 = 0.868\).&lt;/li&gt;
      &lt;li&gt;Vế phải: \(3.7183 - 1.6697 = 2.049\).&lt;/li&gt;
      &lt;li&gt;So sánh: \(0.868 \le 2.049\)? &lt;strong&gt;ĐÚNG!&lt;/strong&gt; Dừng vòng lặp, chấp nhận \(t = 0.25\) và cập nhật \(x_1 = -0.1796\) (giảm hàm mục tiêu hơn 4 lần ngay bước đầu tiên!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Quy tắc cập nhật cơ bản của gradient descent là:
\(x_{k+1} = x_k - t_k \nabla f(x_k),\)
trong đó \(x_k\) là vector tham số tại lần lặp \(k\), \(\nabla f(x_k)\) là gradient và \(t_k &amp;gt; 0\) là kích thước bước (tốc độ học).&lt;/p&gt;

&lt;p&gt;Nếu sử dụng kích thước bước cố định, mức cập nhật không thích nghi với sự thay đổi độ cong của hàm số, dễ dẫn đến vượt quá cực tiểu hoặc tiến triển chậm ở các vùng điều kiện xấu. Để khắc phục, ta có thể chọn kích thước bước một cách thích ứng tại từng bước lặp. Một phương pháp phổ biến là &lt;strong&gt;tìm kiếm đường lùi (backtracking line search)&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;tìm-kiếm-đường-lùi-là-gì&quot;&gt;Tìm kiếm Đường lùi là gì?&lt;/h3&gt;

&lt;p&gt;Phương pháp này thử một kích thước bước từ vị trí hiện tại; nếu bước thử quá lớn (không làm hàm mục tiêu giảm đủ mức yêu cầu), thuật toán sẽ thu nhỏ kích thước bước lại. Hình dưới đây minh họa cách tìm kiếm đường lùi xác định kích thước bước.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_02_02_Backtracking_Line_Search.png&quot; alt=&quot;backtrackinglinesearch1&quot; width=&quot;100%&quot; height=&quot;100%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Tìm kiếm đường lùi [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Các phương pháp tìm kiếm đường (line search) chọn \(t_k\) nhằm đảm bảo mức giảm đủ lớn của \(f\) dọc theo hướng giảm \(d_k = -\nabla f(x_k)\). Tìm kiếm đường chính xác giải bài toán \(t_k = \arg\min_{t &amp;gt; 0} f(x_k + t d_k)\), nhưng việc này tốn kém về tính toán đối với các hàm \(f\) không phải bậc hai. Tìm kiếm đường không chính xác (inexact line search) khắc phục bằng cách chỉ đòi hỏi mức giảm vừa đủ; trong đó, tìm kiếm đường lùi được dùng rộng rãi nhờ tính đơn giản và đảm bảo lý thuyết tốt.&lt;/p&gt;

&lt;p&gt;Trên hàm lồi \(f\), xét mặt cắt dọc theo hướng giảm \(\Delta x\). Đường tiếp tuyến phía dưới luôn nằm dưới đồ thị hàm lồi nên không thể dùng làm ngưỡng kiểm tra bước nhảy. Do đó, tìm kiếm đường lùi sử dụng một đường thẳng phía trên có độ dốc thoải hơn (nhân thêm hệ số \(\alpha \in (0, 1/2]\)). Nếu \(f(x + t \Delta x)\) nằm phía trên đường thẳng này thì bước \(t\) quá lớn; ngược lại, nếu nằm phía dưới thì bước \(t\) được chấp nhận.&lt;/p&gt;

&lt;p&gt;Khi bước thử quá lớn, \(t\) được nhân liên tiếp với \(\beta \in (0, 1)\) cho đến khi giá trị hàm rơi xuống dưới đường thẳng kiểm tra. Giá trị \(t\) cuối cùng luôn nằm trong khoảng \(0 &amp;lt; t \le t_0\).&lt;/p&gt;

&lt;h3 id=&quot;thuật-toán-tìm-kiếm-đường-lùi&quot;&gt;Thuật toán Tìm kiếm Đường lùi&lt;/h3&gt;

&lt;p&gt;Với hướng giảm \(\Delta x = - \nabla f(x)\), thuật toán được tóm tắt như sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Khởi tạo các tham số \(0 &amp;lt; \beta &amp;lt; 1\) và \(0 &amp;lt; \alpha \le 1/2\).&lt;/li&gt;
  &lt;li&gt;Tại mỗi lần lặp, đặt \(t = t_{\text{init}}\) (thường chọn \(t_{\text{init}} = 1\)).&lt;/li&gt;
  &lt;li&gt;Trong khi \(f(x - t \nabla f(x)) &amp;gt; f(x) - \alpha t \|\nabla f(x)\|_2^2\), cập nhật \(t = \beta t\).&lt;/li&gt;
  &lt;li&gt;Cập nhật \(x^+ = x - t \nabla f(x)\).&lt;/li&gt;
  &lt;li&gt;Nếu tiêu chuẩn dừng chưa được thỏa mãn, quay lại bước 2.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tìm kiếm đường lùi đơn giản và hiệu quả trong thực tế. Tham số \(\alpha\) kiểm soát độ dốc của đường thẳng điều kiện giảm đủ, còn \(\beta\) xác định mức độ thu nhỏ bước ở mỗi lần lùi. Thông thường, người ta chọn \(\alpha = 1/2\) và \(\beta\) gần với 1.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-về-tìm-kiếm-đường-lùi&quot;&gt;Ví dụ về Tìm kiếm Đường lùi&lt;/h3&gt;

&lt;p&gt;Nhờ kích thước bước thích ứng, số bước cập nhật chính giảm đáng kể so với kích thước bước cố định (ví dụ: 12 bước cập nhật so với 100 bước trên cùng bài toán). Kể cả khi tính thêm các bước thử lùi, tổng số lần đánh giá hàm để hội tụ vào khoảng 40 bước.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_02_02_Convergence.png&quot; alt=&quot;backtrackinglinesearch1&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Hội tụ với tìm kiếm đường lùi [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;trực-giác-của-điều-kiện-giảm-đủ&quot;&gt;Trực giác của Điều kiện Giảm đủ&lt;/h3&gt;

&lt;p&gt;Xét xấp xỉ bậc hai của \(f\) quanh \(x\):&lt;/p&gt;
&lt;blockquote&gt;
\[f(y) \approx f(x) + \nabla f(x)^T(y-x) + \frac{1}{2t} \|y - x\|_2^2\]
&lt;/blockquote&gt;

&lt;p&gt;Thay \(y = x - t \nabla f(x)\) vào vế phải, ta được:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x - t \nabla f(x)) &amp;amp;\approx f(x) - t \|\nabla f(x)\|_2^2 + \frac{1}{2}t \|\nabla f(x)\|_2^2 = f(x) - \frac{t}{2} \|\nabla f(x)\|_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;tìm-kiếm-đường-lùi-và-chính-xác-trong-khoảng-3-phút&quot;&gt;Tìm kiếm đường lùi và chính xác trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/line-search_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Bước cố định quá nhỏ hay quá lớn, điều kiện Armijo và các lần lùi t ← βt, so với tìm kiếm chính xác trên ví dụ của bài.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-02-01 Kích thước bước cố định</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_02_01_fixed_step_size/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_02_01_fixed_step_size</id>
   <content type="html">&lt;p&gt;Chọn một con số \(t\) cố định rồi chạy thẳng từ đầu đến cuối vòng lặp là cách tiếp cận giản dị nhất thế giới — không tốn thêm bất kỳ phép tính hàm mục tiêu nào để dò bước. Chính sự gọn nhẹ ấy khiến kích thước bước cố định (hoặc lịch giảm bước định sẵn) trở thành lựa chọn số một khi huấn luyện mạng nơ-ron trên hàng triệu mẫu dữ liệu, nơi đánh giá lại toàn bộ hàm mất mát cho line search là quá đắt đỏ.&lt;/p&gt;

&lt;p&gt;Nhưng sự đơn giản đi kèm một lằn ranh sinh tử sắc như dao cạo: chỉ cần bước cố định vượt quá ngưỡng \(2/L\) một chút thôi, thuật toán chuyển ngay từ hội tụ êm ả sang dao động bùng nổ! Bài học này làm rõ chính xác ba vùng hành vi của bước cố định: quá nhỏ, vừa đủ, và quá lớn.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-chế-độ-động-lực-của-bước-cố-định&quot;&gt;Kiến thức cần nhớ: Ba chế độ động lực của Bước cố định&lt;/h2&gt;

&lt;p&gt;Hiểu kích thước bước cố định qua ba trụ cột định lượng sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vùng an toàn \(0 &amp;lt; t \le 1/L\) (Đảm bảo giảm đơn điệu):&lt;/strong&gt; Khi \(f\) có gradient \(L\)-Lipschitz, mọi bước \(t \le 1/L\) đều bảo đảm \(f(x_{k+1}) \le f(x_k) - \frac{t}{2}\|\nabla f(x_k)\|_2^2\) — hàm mục tiêu giảm nghiêm ngặt sau từng bước mà không bao giờ bật lên!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Vùng dao động nhưng vẫn hội tụ \(1/L &amp;lt; t &amp;lt; 2/L\):&lt;/strong&gt; Trên hàm bậc hai \(L\)-trơn, bước đi vượt qua đáy theo phương dốc nhất nên quỹ đạo nhảy qua nhảy lại (overshoot), nhưng biên độ vẫn co dần vì $$&lt;/td&gt;
          &lt;td&gt;1 - tL&lt;/td&gt;
          &lt;td&gt;&amp;lt; 1$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Vùng phân kỳ \(t \ge 2/L\):&lt;/strong&gt; Khi \(t = 2/L\), thuật toán nhảy qua lại vô hạn giữa \(+x_0\) và \(-x_0\) mà không giảm thêm chút nào. Khi \(t &amp;gt; 2/L\), biên độ nhân lên theo cấp số nhân $$&lt;/td&gt;
          &lt;td&gt;1 - tL&lt;/td&gt;
          &lt;td&gt;^k \to \infty$$!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-quan-sát-chính-xác-4-kịch-bản-bước-cố-định-trên-fx--2x2&quot;&gt;Giải thích: Quan sát chính xác 4 kịch bản bước cố định trên \(f(x) = 2x^2\)&lt;/h3&gt;

&lt;p&gt;Với \(f(x) = 2x^2\), ta có \(f&apos;(x) = 4x\) và độ cong \(L = f&apos;&apos;(x) = 4\). Vậy \(1/L = 0.25\) và ngưỡng tới hạn \(2/L = 0.5\). Xuất phát từ \(x_0 = 1\), quy tắc cập nhật là \(x_{k+1} = x_k - 4t x_k = (1 - 4t)x_k\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(t = 0.05\) (quá nhỏ, \(t \ll 1/L\)):&lt;/strong&gt; \(x_k = (0.8)^k\). Sau 3 bước: \(1 \to 0.8 \to 0.64 \to 0.512\) (hội tụ đơn điệu nhưng chậm rề rề).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(t = 0.25\) (lý tưởng, \(t = 1/L\)):&lt;/strong&gt; \(x_k = (0)^k\). Sau 1 bước: \(1 \to 0\) (chạm đáy tức thì!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(t = 0.45\) (vùng dao động, \(1/L &amp;lt; t &amp;lt; 2/L\)):&lt;/strong&gt; \(x_k = (-0.8)^k\). Sau 3 bước: \(1 \to -0.8 \to 0.64 \to -0.512\) (vượt đáy liên tục nhưng biên độ vẫn thu hẹp về \(0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(t = 0.55\) (quá lớn, \(t &amp;gt; 2/L\)):&lt;/strong&gt; \(x_k = (-1.2)^k\). Sau 3 bước: \(1 \to -1.2 \to 1.44 \to -1.728 \to \dots\) (bùng nổ ra vô cực!).
&lt;strong&gt;Bài học thực hành:&lt;/strong&gt; Trong thực tế không biết chính xác \(L\), hãy bắt đầu với \(t\) nhỏ theo thang log (\(10^{-4}, 10^{-3}, 10^{-2}, \dots\)) và theo dõi đường cong loss ngay trong 10 bước đầu!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Cách đơn giản nhất để chọn kích thước bước trong gradient descent là giữ nguyên một giá trị cố định cho mọi lần lặp: \(t_k = t\) với \(k = 1, 2, 3, ...\). Tuy nhiên, tốc độ và khả năng hội tụ của thuật toán phụ thuộc rất lớn vào việc lựa chọn \(t\).&lt;/p&gt;

&lt;p&gt;Ví dụ, hình dưới đây minh họa gradient descent áp dụng cho hàm \(f(x) = (10 x_1^2 + x_2^2) / 2\) với ba kích thước bước khác nhau:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_02_01_gradientdescent4.png&quot; alt=&quot;gradientdescent4&quot; width=&quot;100%&quot; height=&quot;100%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Các trường hợp lựa chọn kích thước bước [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Trong trường hợp A, kích thước bước \(t\) quá lớn, khiến thuật toán phân kỳ sau 8 bước và không thể tiến tới điểm cực tiểu.&lt;/li&gt;
  &lt;li&gt;Trong trường hợp B, kích thước bước \(t\) quá nhỏ, khiến tốc độ hội tụ rất chậm và chưa đạt được điểm cực tiểu ngay cả sau 100 bước.&lt;/li&gt;
  &lt;li&gt;Trong trường hợp C, kích thước bước có độ lớn phù hợp, giúp thuật toán hội tụ trong khoảng 40 bước. (Cách xác định khoảng giá trị phù hợp này sẽ được phân tích ở các mục sau trong chương.)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;kích-thước-bước-ổn-định-quá-lớn-quá-nhỏ-video&quot;&gt;Kích thước bước: ổn định, quá lớn, quá nhỏ (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/gd-step-sizes_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Trên mặt hàm có đường đồng mức kéo dài, bước quá lớn gây dao động zig-zag hoặc phân kỳ, còn bước quá nhỏ khiến thuật toán tiến rất chậm. Backtracking line search và exact line search giúp tự động chọn kích thước bước phù hợp.&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-kích-thước-bước&quot;&gt;Tự tay thử: kích thước bước&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;gd&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>06-01 Gradient Descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_01_gradient_descent/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_01_gradient_descent</id>
   <content type="html">&lt;p&gt;Năm 1847, nhà toán học Pháp Augustin-Louis Cauchy đối mặt với hệ phương trình phi tuyến khổng lồ trong tính toán quỹ đạo thiên thể mà các công thức nghiệm đóng hoàn toàn bất lực. Ông đề xuất một ý tưởng táo bạo đến mức tối giản: đi ngược chiều vector đạo hàm riêng từng bước nhỏ — và &lt;strong&gt;Gradient Descent&lt;/strong&gt; ra đời. Hơn 175 năm sau, chính ý tưởng 1 dòng công thức của Cauchy vẫn là trái tim huấn luyện mọi mô hình học máy từ hồi quy logistic đến các mô hình ngôn ngữ lớn hàng trăm tỷ tham số.&lt;/p&gt;

&lt;p&gt;Bài học này đi sâu vào bản chất hình học và giải tích của Gradient Descent trên cả hàm một biến lẫn nhiều biến: vì sao \(-\nabla f(x)\) là hướng giảm cục bộ nhanh nhất theo chuẩn Euclidean, và cách tốc độ học \(t\) biến đổi hoàn toàn quỹ đạo của thuật toán.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-cơ-chế-hạ-gradient&quot;&gt;Kiến thức cần nhớ: Giải phẫu cơ chế Hạ Gradient&lt;/h2&gt;

&lt;p&gt;Ba trụ cột dưới đây giải thích trọn vẹn sức mạnh và giới hạn của Gradient Descent chuẩn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hướng dốc xuống nhanh nhất (Steepest Descent Direction):&lt;/strong&gt; Theo khai triển Taylor bậc nhất \(f(x + \Delta x) \approx f(x) + \nabla f(x)^T \Delta x\). Với độ dài bước cố định \(\|\Delta x\|_2 = \epsilon\), bất đẳng thức Cauchy-Schwarz khẳng định \(\nabla f(x)^T \Delta x \ge -\|\nabla f(x)\|_2 \|\Delta x\|_2\), dấu bằng đạt được duy nhất khi \(\Delta x\) ngược chiều \(\nabla f(x)\)!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Tốc độ học \(t\) (Step Size / Learning Rate):&lt;/strong&gt; Quyết định trực tiếp hành vi hội tụ. Với hàm bậc hai \(f(x) = \frac{1}{2} x^T Q x\), sai số dọc theo mỗi trục riêng \(\lambda_i\) nhân với thừa số \((1 - t\lambda_i)\). Để hội tụ, bắt buộc $$&lt;/td&gt;
          &lt;td&gt;1 - t\lambda_{\max}&lt;/td&gt;
          &lt;td&gt;&amp;lt; 1 \iff t &amp;lt; \frac{2}{\lambda_{\max}}$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ toàn cục nhờ Tính Lồi:&lt;/strong&gt; Trên hàm phi lồi, Gradient Descent có thể kẹt ở cực tiểu địa phương hoặc điểm yên ngựa. Trên hàm lồi khả vi, mọi điểm dừng \(\nabla f(x^\star) = 0\) đều là cực tiểu toàn cục — nên chỉ cần bước hợp lý, GD chắc chắn tiến về đáy toàn cục!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-2-bước-gradient-descent-trên-hàm-2-biến-dạng-thung-lũng-hẹp&quot;&gt;Giải thích: Chạy tay 2 bước Gradient Descent trên hàm 2 biến dạng thung lũng hẹp&lt;/h3&gt;

&lt;p&gt;Xét hàm lồi bậc hai \(f(x_1, x_2) = x_1^2 + 4x_2^2\) có nghiệm tối ưu \(x^\star = (0, 0)\), gradient \(\nabla f(x) = (2x_1,\; 8x_2)^T\) và Hessian \(H = \operatorname{diag}(2, 8)\) (nên \(\lambda_{\max} = 8\), ngưỡng ổn định là \(t &amp;lt; 2/8 = 0.25\)). Khởi tạo tại \(x^{(0)} = (2, 1)^T\) với \(t = 0.2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giá trị ban đầu:&lt;/strong&gt; \(f(2, 1) = 4 + 4 = 8\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; \(\nabla f(2, 1) = (4,\; 8)^T\).
\(x^{(1)} = \begin{pmatrix} 2 \\ 1 \end{pmatrix} - 0.2 \begin{pmatrix} 4 \\ 8 \end{pmatrix} = \begin{pmatrix} 1.2 \\ -0.6 \end{pmatrix}, \qquad f(x^{(1)}) = 1.44 + 4(0.36) = 2.88.\)
Chú ý: \(x_2\) đã &lt;strong&gt;đổi dấu&lt;/strong&gt; từ \(+1\) nhảy qua đáy sang \(-0.6\) (bắt đầu zíc-zắc theo phương dốc gắt!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt; \(\nabla f(1.2, -0.6) = (2.4,\; -4.8)^T\).
\(x^{(2)} = \begin{pmatrix} 1.2 \\ -0.6 \end{pmatrix} - 0.2 \begin{pmatrix} 2.4 \\ -4.8 \end{pmatrix} = \begin{pmatrix} 0.72 \\ 0.36 \end{pmatrix}, \qquad f(x^{(2)}) = 0.5184 + 4(0.1296) = 1.0368.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhận xét cốt lõi:&lt;/strong&gt; Dù giá trị hàm giảm đẹp (\(8 \to 2.88 \to 1.037\)), hãy nhìn hai hệ số co: theo trục \(x_1\) mỗi bước nhân \(1 - 0.2(2) = 0.6\), còn theo trục \(x_2\) mỗi bước nhân \(1 - 0.2(8) = -0.6\) (dao động đổi dấu liên tục). Khi hai độ cong chênh lệch quá lớn (thung lũng hẹp), GD buộc phải đi bước rất nhỏ theo hướng dốc và lê bước theo hướng thoai thoải!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Gradient descent là thuật toán cơ bản nhất để giải các bài toán tối ưu hóa lồi, khả vi và không ràng buộc:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\min_x f(x),\)
trong đó \(f\) khả vi và \(dom(f) = \mathbb{R}^n\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Giá trị tối ưu được ký hiệu là \(f^* = \min_x f(x)\) và điểm tối ưu tương ứng là \(x^*\).&lt;/p&gt;

&lt;h2 id=&quot;vai-trò-của-gradient-descent-trong-khoa-học-dữ-liệu&quot;&gt;Vai trò của Gradient Descent trong Khoa học Dữ liệu&lt;/h2&gt;

&lt;p&gt;Gradient descent là một trong những thuật toán nền tảng của học máy (machine learning), được sử dụng rộng rãi trong:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Huấn luyện mạng nơ-ron&lt;/strong&gt;: Thuật toán lan truyền ngược (backpropagation) kết hợp với gradient descent để cập nhật trọng số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hồi quy tuyến tính&lt;/strong&gt;: Tìm bộ hệ số tối ưu nhằm cực tiểu hóa sai số bình phương trung bình (MSE).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hồi quy logistic&lt;/strong&gt;: Tối ưu hóa tham số cho bài toán phân loại.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Học sâu (Deep learning)&lt;/strong&gt;: Huấn luyện các mô hình lớn với hàng triệu tham số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ thống gợi ý&lt;/strong&gt;: Học biểu diễn sở thích người dùng và đặc trưng sản phẩm.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý&lt;/strong&gt;: Trong hầu hết các bài toán huấn luyện mô hình học máy, gradient descent hoặc các biến thể của nó đều đóng vai trò thuật toán tối ưu cốt lõi.&lt;/p&gt;

&lt;h2 id=&quot;gradient-descent-cho-hàm-một-biến&quot;&gt;Gradient Descent cho Hàm Một Biến&lt;/h2&gt;

&lt;p&gt;Đối với hàm một biến \(f: \mathbb{R} \to \mathbb{R}\), gradient descent có dạng rất đơn giản. Gradient lúc này chính là đạo hàm bậc nhất, và quy tắc cập nhật được viết như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = x^{(k-1)} - t f&apos;(x^{(k-1)}), \quad k = 1, 2, 3, ...\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(f&apos;(x)\) là đạo hàm của \(f\) tại điểm \(x\).&lt;/p&gt;

&lt;h3 id=&quot;diễn-giải-hình-học&quot;&gt;Diễn giải Hình học&lt;/h3&gt;

&lt;p&gt;Trong trường hợp một biến, đạo hàm \(f&apos;(x)\) là độ dốc của đường tiếp tuyến với đồ thị hàm số tại điểm \(x\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(f&apos;(x) &amp;gt; 0\), hàm số đang tăng tại \(x\), nên ta di chuyển sang trái (trừ đi một đại lượng dương).&lt;/li&gt;
  &lt;li&gt;Nếu \(f&apos;(x) &amp;lt; 0\), hàm số đang giảm tại \(x\), nên ta di chuyển sang phải (trừ đi một đại lượng âm).&lt;/li&gt;
  &lt;li&gt;Nếu \(f&apos;(x) = 0\), ta đã đạt tới điểm dừng (ứng viên cực tiểu).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tốc-độ-học-t&quot;&gt;Tốc độ học \(t\)&lt;/h3&gt;

&lt;p&gt;Tốc độ học \(t\) (còn gọi là kích thước bước) là siêu tham số quan trọng do người thiết kế thuật toán lựa chọn. Tham số này quyết định độ dài mỗi bước di chuyển theo hướng ngược chiều gradient.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ảnh hưởng của tốc độ học:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quá nhỏ (\(t \ll 1\))&lt;/strong&gt;: Các bước cập nhật rất nhỏ, đòi hỏi nhiều lần lặp để tiến tới nghiệm tối ưu. Dù đảm bảo tính ổn định, cách chọn này có thể tốn kém về chi phí tính toán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quá lớn (\(t \gg 1\))&lt;/strong&gt;: Thuật toán có thể nhảy vượt qua điểm cực tiểu, dẫn đến dao động quanh nghiệm tối ưu hoặc thậm chí phân kỳ ra xa nghiệm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phù hợp&lt;/strong&gt;: Thuật toán hội tụ nhanh và ổn định về nghiệm tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các chiến lược phổ biến để chọn tốc độ học:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bước cố định&lt;/strong&gt;: Giữ nguyên một giá trị \(t\) không đổi trong suốt quá trình tối ưu hóa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường chính xác (exact line search)&lt;/strong&gt;: Tại mỗi bước lặp, chọn \(t\) sao cho cực tiểu hóa \(f(x^{(k-1)} - t\nabla f(x^{(k-1)}))\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường lùi (backtracking line search)&lt;/strong&gt;: Bắt đầu với kích thước bước lớn rồi giảm dần cho đến khi đạt được mức giảm đủ lớn của hàm mục tiêu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp thích ứng&lt;/strong&gt;: Tự động điều chỉnh tốc độ học dựa trên lịch sử cập nhật (ví dụ: Adam, RMSprop).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;ví-dụ-hàm-bậc-hai&quot;&gt;Ví dụ: Hàm Bậc Hai&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai \(f(x) = \frac{1}{2}(x - 2)^2 + 1\) với đạo hàm \(f&apos;(x) = x - 2\).&lt;/p&gt;

&lt;p&gt;Quy tắc cập nhật của gradient descent là:&lt;/p&gt;
&lt;blockquote&gt;
\[x^{(k)} = x^{(k-1)} - t(x^{(k-1)} - 2)\]
&lt;/blockquote&gt;

&lt;p&gt;Bắt đầu từ \(x^{(0)} = 0\) với kích thước bước \(t = 0.1\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(x^{(1)} = 0 - 0.1(0 - 2) = 0.2\)
\(x^{(2)} = 0.2 - 0.1(0.2 - 2) = 0.38\)
\(x^{(3)} = 0.38 - 0.1(0.38 - 2) = 0.542\)
…&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Dãy lặp này hội tụ về \(x^* = 2\), cũng là điểm cực tiểu toàn cục của hàm số.&lt;/p&gt;

&lt;h3 id=&quot;lựa-chọn-kích-thước-bước&quot;&gt;Lựa chọn Kích thước Bước&lt;/h3&gt;

&lt;p&gt;Việc chọn kích thước bước \(t\) ảnh hưởng trực tiếp đến quá trình hội tụ:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quá nhỏ&lt;/strong&gt;: Hội tụ rất chậm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quá lớn&lt;/strong&gt;: Có thể vượt quá cực tiểu và phân kỳ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu&lt;/strong&gt;: Với hàm bậc hai một biến \(f(x) = \frac{1}{2}ax^2 + bx + c\) (\(a &amp;gt; 0\)), kích thước bước tối ưu là \(t = \frac{1}{a}\), giúp đạt cực tiểu chỉ sau một bước.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;trực-quan-hóa-tương-tác&quot;&gt;Trực quan Hóa Tương tác&lt;/h3&gt;

&lt;div id=&quot;single-var-gradient-descent&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
        &lt;label for=&quot;step-size-slider&quot;&gt;Kích thước Bước (t): &lt;span id=&quot;step-size-value&quot;&gt;0.1&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;step-size-slider&quot; min=&quot;0.01&quot; max=&quot;0.5&quot; step=&quot;0.01&quot; value=&quot;0.1&quot; style=&quot;width: 300px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
        &lt;label for=&quot;start-point-slider&quot;&gt;Điểm Bắt đầu: &lt;span id=&quot;start-point-value&quot;&gt;-3&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;start-point-slider&quot; min=&quot;-5&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;-3&quot; style=&quot;width: 300px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
        &lt;button id=&quot;start-animation&quot;&gt;Bắt đầu Animation&lt;/button&gt;
        &lt;button id=&quot;reset-animation&quot;&gt;Reset&lt;/button&gt;
        &lt;button id=&quot;step-once&quot;&gt;Một Bước&lt;/button&gt;
    &lt;/div&gt;
    
    &lt;canvas id=&quot;gradient-canvas&quot; width=&quot;600&quot; height=&quot;400&quot; style=&quot;border: 1px solid #ccc; display: block; margin: 0 auto;&quot;&gt;&lt;/canvas&gt;
    
    &lt;div id=&quot;iteration-info&quot; style=&quot;text-align: center; margin-top: 10px; font-family: monospace;&quot;&gt;
Lần lặp: 0, x = -3.000, f(x) = 13.500, f&apos;(x) = -5.000
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
class SingleVarGradientDescent {
    constructor() {
        this.canvas = document.getElementById(&apos;gradient-canvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.stepSizeSlider = document.getElementById(&apos;step-size-slider&apos;);
        this.startPointSlider = document.getElementById(&apos;start-point-slider&apos;);
        this.stepSizeValue = document.getElementById(&apos;step-size-value&apos;);
        this.startPointValue = document.getElementById(&apos;start-point-value&apos;);
        this.iterationInfo = document.getElementById(&apos;iteration-info&apos;);
        
        // Animation state
        this.isAnimating = false;
        this.currentX = -3;
        this.iteration = 0;
        this.history = [];
        this.animationId = null;
        
        // Function parameters: f(x) = 0.5 * (x - 2)^2 + 1
        this.a = 0.5;
        this.b = 2;
        this.c = 1;
        
        this.setupEventListeners();
        this.reset();
    }
    
    setupEventListeners() {
        this.stepSizeSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.stepSizeValue.textContent = e.target.value;
        });
        
        this.startPointSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.startPointValue.textContent = e.target.value;
            if (!this.isAnimating) {
                this.reset();
            }
        });
        
        document.getElementById(&apos;start-animation&apos;).addEventListener(&apos;click&apos;, () =&gt; {
            this.startAnimation();
        });
        
        document.getElementById(&apos;reset-animation&apos;).addEventListener(&apos;click&apos;, () =&gt; {
            this.reset();
        });
        
        document.getElementById(&apos;step-once&apos;).addEventListener(&apos;click&apos;, () =&gt; {
            this.singleStep();
        });
    }
    
    // Function: f(x) = 0.5 * (x - 2)^2 + 1
    f(x) {
        return this.a * Math.pow(x - this.b, 2) + this.c;
    }
    
    // Derivative: f&apos;(x) = (x - 2)
    fprime(x) {
        return 2 * this.a * (x - this.b);
    }
    
    // Convert x coordinate to canvas coordinate
    xToCanvas(x) {
        const xMin = -5, xMax = 5;
        return (x - xMin) / (xMax - xMin) * this.canvas.width;
    }
    
    // Convert y coordinate to canvas coordinate
    yToCanvas(y) {
        const yMin = 0, yMax = 15;
        return this.canvas.height - (y - yMin) / (yMax - yMin) * this.canvas.height;
    }
    
    // Convert canvas x to actual x
    canvasToX(canvasX) {
        const xMin = -5, xMax = 5;
        return xMin + (canvasX / this.canvas.width) * (xMax - xMin);
    }
    
    drawFunction() {
        this.ctx.strokeStyle = &apos;#2196F3&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        
        for (let canvasX = 0; canvasX &lt;= this.canvas.width; canvasX += 2) {
            const x = this.canvasToX(canvasX);
            const y = this.f(x);
            const canvasY = this.yToCanvas(y);
            
            if (canvasX === 0) {
                this.ctx.moveTo(canvasX, canvasY);
            } else {
                this.ctx.lineTo(canvasX, canvasY);
            }
        }
        this.ctx.stroke();
    }
    
    drawAxes() {
        this.ctx.strokeStyle = &apos;#666&apos;;
        this.ctx.lineWidth = 1;
        
        // X-axis
        const yZero = this.yToCanvas(0);
        this.ctx.beginPath();
        this.ctx.moveTo(0, yZero);
        this.ctx.lineTo(this.canvas.width, yZero);
        this.ctx.stroke();
        
        // Y-axis
        const xZero = this.xToCanvas(0);
        this.ctx.beginPath();
        this.ctx.moveTo(xZero, 0);
        this.ctx.lineTo(xZero, this.canvas.height);
        this.ctx.stroke();
        
        // Labels
        this.ctx.fillStyle = &apos;#666&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;center&apos;;
        
        // X-axis labels
        for (let x = -4; x &lt;= 4; x += 2) {
            const canvasX = this.xToCanvas(x);
            this.ctx.fillText(x.toString(), canvasX, yZero + 15);
        }
        
        // Y-axis labels
        this.ctx.textAlign = &apos;right&apos;;
        for (let y = 2; y &lt;= 14; y += 2) {
            const canvasY = this.yToCanvas(y);
            this.ctx.fillText(y.toString(), xZero - 5, canvasY + 4);
        }
    }
    
    drawCurrentPoint() {
        const canvasX = this.xToCanvas(this.currentX);
        const canvasY = this.yToCanvas(this.f(this.currentX));
        
        // Current point
        this.ctx.fillStyle = &apos;#F44336&apos;;
        this.ctx.beginPath();
        this.ctx.arc(canvasX, canvasY, 6, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Tangent line
        const derivative = this.fprime(this.currentX);
        const tangentLength = 1;
        const x1 = this.currentX - tangentLength;
        const x2 = this.currentX + tangentLength;
        const y1 = this.f(this.currentX) + derivative * (x1 - this.currentX);
        const y2 = this.f(this.currentX) + derivative * (x2 - this.currentX);
        
        this.ctx.strokeStyle = &apos;#FF9800&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        this.ctx.moveTo(this.xToCanvas(x1), this.yToCanvas(y1));
        this.ctx.lineTo(this.xToCanvas(x2), this.yToCanvas(y2));
        this.ctx.stroke();
    }
    
    drawHistory() {
        if (this.history.length &lt; 2) return;
        
        this.ctx.strokeStyle = &apos;#4CAF50&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.setLineDash([5, 5]);
        this.ctx.beginPath();
        
        for (let i = 0; i &lt; this.history.length; i++) {
            const x = this.history[i];
            const canvasX = this.xToCanvas(x);
            const canvasY = this.yToCanvas(this.f(x));
            
            if (i === 0) {
                this.ctx.moveTo(canvasX, canvasY);
            } else {
                this.ctx.lineTo(canvasX, canvasY);
            }
        }
        this.ctx.stroke();
        this.ctx.setLineDash([]);
        
        // Draw history points
        this.ctx.fillStyle = &apos;#4CAF50&apos;;
        for (let i = 0; i &lt; this.history.length - 1; i++) {
            const x = this.history[i];
            const canvasX = this.xToCanvas(x);
            const canvasY = this.yToCanvas(this.f(x));
            
            this.ctx.beginPath();
            this.ctx.arc(canvasX, canvasY, 3, 0, 2 * Math.PI);
            this.ctx.fill();
        }
    }
    
    draw() {
        // Clear canvas
        this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
        
        // Draw components
        this.drawAxes();
        this.drawFunction();
        this.drawHistory();
        this.drawCurrentPoint();
        
        // Update iteration info
        this.iterationInfo.textContent = 
            `Lần lặp: ${this.iteration}, x = ${this.currentX.toFixed(3)}, ` +
            `f(x) = ${this.f(this.currentX).toFixed(3)}, f&apos;(x) = ${this.fprime(this.currentX).toFixed(3)}`;
    }
    
    singleStep() {
        if (Math.abs(this.fprime(this.currentX)) &lt; 1e-6) {
            return; // Already at minimum
        }
        
        const stepSize = parseFloat(this.stepSizeSlider.value);
        const newX = this.currentX - stepSize * this.fprime(this.currentX);
        
        this.history.push(this.currentX);
        this.currentX = newX;
        this.iteration++;
        
        this.draw();
    }
    
    startAnimation() {
        if (this.isAnimating) {
            this.stopAnimation();
            return;
        }
        
        this.isAnimating = true;
        document.getElementById(&apos;start-animation&apos;).textContent = &apos;Dừng Animation&apos;;
        
        const animate = () =&gt; {
            if (!this.isAnimating) return;
            
            if (Math.abs(this.fprime(this.currentX)) &gt; 1e-6 &amp;&amp; this.iteration &lt; 100) {
                this.singleStep();
                this.animationId = setTimeout(animate, 500);
            } else {
                this.stopAnimation();
            }
        };
        
        animate();
    }
    
    stopAnimation() {
        this.isAnimating = false;
        document.getElementById(&apos;start-animation&apos;).textContent = &apos;Bắt đầu Animation&apos;;
        if (this.animationId) {
            clearTimeout(this.animationId);
            this.animationId = null;
        }
    }
    
    reset() {
        this.stopAnimation();
        this.currentX = parseFloat(this.startPointSlider.value);
        this.iteration = 0;
        this.history = [];
        this.draw();
    }
}

// Initialize when DOM is loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    new SingleVarGradientDescent();
});
&lt;/script&gt;

&lt;h2 id=&quot;phương-pháp-gradient-descent-cho-hàm-nhiều-biến&quot;&gt;Phương pháp Gradient Descent cho Hàm Nhiều Biến&lt;/h2&gt;

&lt;p&gt;Gradient descent bắt đầu từ một điểm khởi tạo \(x^{(0)} \in \mathbb{R}^n\) và cập nhật lặp cho đến khi tiêu chuẩn dừng được thỏa mãn:&lt;/p&gt;
&lt;blockquote&gt;
\[x^{(k)} = x^{(k-1)} - t \nabla f(x^{(k-1)}), \quad k = 1, 2, 3, ..., \quad t &amp;gt; 0\]
&lt;/blockquote&gt;

&lt;p&gt;Mã giả:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Cho điểm khởi tạo&lt;/strong&gt; \(x \in dom(f)\) &lt;br /&gt;
&lt;strong&gt;Lặp lại&lt;/strong&gt; &lt;br /&gt;&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;Xác định hướng giảm \(\Delta x = -\nabla f(x)\). &lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;Tìm kiếm đường (line search): chọn kích thước bước \(t &amp;gt; 0\). &lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;Cập nhật \(x = x + t \Delta x\). &lt;br /&gt;
&lt;strong&gt;Cho đến khi&lt;/strong&gt; tiêu chuẩn dừng được thỏa mãn &lt;br /&gt;&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h3&gt;

&lt;p&gt;Hình dưới đây minh họa gradient descent trên một hàm lồi. Trong trường hợp này, mọi cực tiểu cục bộ đều là cực tiểu toàn cục.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_01_gradientdescent1.png&quot; alt=&quot;gradientdescent1&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Gradient descent trên hàm lồi [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Hình tiếp theo minh họa gradient descent trên một hàm không lồi. Khi đó, điểm khởi tạo quyết định thuật toán sẽ hội tụ về cực tiểu cục bộ nào.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_01_gradientdescent2.png&quot; alt=&quot;gradientdescent2&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Gradient descent trên hàm không lồi [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;diễn-giải-gradient-descent&quot;&gt;Diễn giải Gradient Descent&lt;/h2&gt;

&lt;p&gt;Gradient descent có thể được hiểu như quá trình chọn điểm tiếp theo bằng cách cực tiểu hóa một xấp xỉ bậc hai cục bộ của hàm mục tiêu.&lt;/p&gt;

&lt;p&gt;Đối với hàm \(f\), khai triển Taylor bậc hai quanh điểm \(x\) có dạng:&lt;/p&gt;
&lt;blockquote&gt;
\[f(y) \approx f(x) + \nabla f(x)^T (y - x) + \frac{1}{2} (y - x)^T \nabla^2 f(x) (y - x)\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu ta xấp xỉ ma trận Hessian \(\nabla^2 f(x)\) bằng \(\frac{1}{t}I\), ta thu được:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(y) \approx f(x) + \nabla f(x)^T (y - x) + \frac{1}{2t} \|y - x\|_2^2\)
trong đó \(t\) là kích thước bước.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Như vậy, gradient descent xấp xỉ hàm mục tiêu bằng một hàm bậc hai có ma trận Hessian đẳng hướng với mọi giá trị riêng đều bằng \(\frac{1}{t}\). Biểu thức \(f(x) + \nabla f(x)^T (y - x)\) là xấp xỉ tuyến tính của \(f\) quanh \(x\), còn \(\frac{1}{2t} \|y - x\|_2^2\) đóng vai trò là số hạng gần kề (proximal term), kiểm soát khoảng cách giữa \(y\) và \(x\).&lt;/p&gt;

&lt;p&gt;Điểm tiếp theo \(y = x^+\) được chọn làm cực tiểu của hàm bậc hai xấp xỉ này. Đặt gradient theo \(y\) bằng 0, ta thu được:&lt;/p&gt;

&lt;blockquote&gt;
\[x^+ = x - t \nabla f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Trong hình minh họa bên dưới, chấm xanh biểu diễn vị trí hiện tại \(x\) và chấm đỏ biểu diễn vị trí tiếp theo \(x^+\). Đường cong phía dưới là hàm thực \(f\), còn đường cong phía trên là hàm bậc hai xấp xỉ của \(f\); chấm đỏ chính là điểm cực tiểu của hàm bậc hai xấp xỉ đó.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_01_gradientdescent3.png&quot; alt=&quot;gradientdescent3&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$ \text{[Hình 3] Thuật toán Gradient descent : chấm đỏ là } x^+ \text{ và chấm xanh là } x \text{ [3]} $$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Khoảng cách từ vị trí mới \(y\) tới vị trí hiện tại \(x\) chịu ảnh hưởng trực tiếp bởi trọng số \(\frac{1}{2t}\) của số hạng gần kề. Khi \(t\) nhỏ, trọng số này lớn hơn, buộc thuật toán chỉ thực hiện các bước nhỏ quanh \(x\). Quy tắc cập nhật này có thể viết gọn dưới dạng bài toán tối ưu:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^+ = \underset{y}{\arg \min} \ f(x) + \nabla f(x)^T (y - x) + \frac{1}{2t} \parallel y - x \parallel_2^2
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>06-01-06 Bài tập: Hiểu về Kích thước Bước và Độ cong</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_01_06_hessian_exercises/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_01_06_hessian_exercises</id>
   <content type="html">&lt;p&gt;Hiểu bằng mắt rằng \(1/t\) đóng vai trò xấp xỉ Hessian là một chuyện, nhưng tự tay đạo hàm mô hình bậc hai, tính chỉ số điều kiện \(\kappa = \lambda_{\max}/\lambda_{\min}\) và thấy tận mắt vì sao đổi tỷ lệ trục (preconditioning) làm tốc độ hội tụ tăng gấp hàng trăm lần lại là một trải nghiệm khai sáng hoàn toàn khác.&lt;/p&gt;

&lt;p&gt;Bộ bài tập chuyên sâu này dẫn bạn đi từng bước từ chứng minh đại số quy tắc cập nhật GD, phân tích ảnh hưởng của độ cong địa phương đến từng tọa độ, cho đến việc thiết kế bước thích ứng theo đường chéo Hessian — tiền đề trực tiếp cho các thuật toán AdaGrad và Adam trong học sâu!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-công-cụ-cần-dùng-để-giải-trọn-bộ-bài-tập-độ-cong&quot;&gt;Kiến thức cần nhớ: Bốn công cụ cần dùng để giải trọn bộ bài tập độ cong&lt;/h2&gt;

&lt;p&gt;Trước khi bắt tay vào 5 bài tập bên dưới, hãy đặt sẵn bốn công thức trụ cột lên bàn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đạo hàm dạng toàn phương:&lt;/strong&gt; Với \(q(y) = f(x) + g^T(y - x) + \frac{1}{2t}\|y - x\|_2^2\), lấy gradient theo \(y\) cho \(\nabla q(y) = g + \frac{1}{t}(y - x) = 0 \implies y^\star = x - tg\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện ổn định &amp;amp; Bước tối ưu cho hàm bậc hai:&lt;/strong&gt; Với \(f(x) = \frac{1}{2} x^T Q x\) có các trị riêng \(0 &amp;lt; m = \lambda_{\min} \le \dots \le \lambda_{\max} = L\), bước cố định tốt nhất cho bài toán bậc hai là \(t^\star = \frac{2}{L + m}\), cho hệ số co tối ưu là \(\rho^\star = \frac{\kappa - 1}{\kappa + 1}\) với \(\kappa = \frac{L}{m}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tách biến theo từng tọa độ (Diagonal Preconditioning):&lt;/strong&gt; Nếu thay \(\frac{1}{t} I\) bằng ma trận đường chéo \(D = \operatorname{diag}(1/t_1, \dots, 1/t_n)\) khớp với từng phần tử đường chéo \(H_{ii}\) của Hessian, ta thu được bước cập nhật riêng cho từng tọa độ \(x_i^+ = x_i - \frac{1}{H_{ii}} \frac{\partial f}{\partial x_i}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hệ trực tiếp với Chuẩn hóa đặc trưng (Feature Scaling):&lt;/strong&gt; Trong học máy, chuẩn hóa các cột dữ liệu về cùng phương sai chính là cách giảm chỉ số điều kiện \(\kappa(X^T X)\) từ hàng triệu xuống gần \(1\), biến đường đồng mức ellipsoid dẹt thành hình tròn để GD đi thẳng vào tâm!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-bước-tối-ưu-và-số-vòng-lặp-theo-chỉ-số-điều-kiện-kappa&quot;&gt;Giải thích: Tính bước tối ưu và số vòng lặp theo chỉ số điều kiện \(\kappa\)&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + 9x_2^2)\) với \(Q = \operatorname{diag}(1, 9)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Xác định trị riêng và chỉ số điều kiện:&lt;/strong&gt;
\(m = \lambda_{\min} = 1, \qquad L = \lambda_{\max} = 9, \qquad \kappa = \frac{L}{m} = 9.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tính bước tối ưu \(t^\star = \frac{2}{L + m}\) và hệ số co \(\rho^\star\):&lt;/strong&gt;
\(t^\star = \frac{2}{9 + 1} = 0.2.\)
Kiểm tra hai hệ số co theo từng trục tại \(t^\star = 0.2\):
    &lt;ul&gt;
      &lt;li&gt;Trục \(x_1\): \(1 - 0.2(1) = +0.8\).&lt;/li&gt;
      &lt;li&gt;Trục \(x_2\): \(1 - 0.2(9) = -0.8\).
Cả hai đều có trị tuyệt đối bằng \(\rho^\star = \frac{9 - 1}{9 + 1} = 0.8\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — So sánh nếu dùng bước riêng theo từng tọa độ \(t_1 = 1/1 = 1,\; t_2 = 1/9\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Trục \(x_1\): \(1 - 1(1) = 0\).&lt;/li&gt;
      &lt;li&gt;Trục \(x_2\): \(1 - \frac{1}{9}(9) = 0\).
Chỉ cần đúng &lt;strong&gt;1 bước duy nhất&lt;/strong&gt; thay vì \(\approx 31\) bước (để \(0.8^k &amp;lt; 10^{-3}\)) để chạm nghiệm \(x^\star = (0, 0)\)! Đó là sức mạnh thực sự của việc ước lượng đúng độ cong!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;h2 id=&quot;bài-tập-1-suy-ra-quy-tắc-cập-nhật-từ-xấp-xỉ-bậc-hai&quot;&gt;Bài tập 1: Suy ra Quy tắc Cập nhật từ Xấp xỉ Bậc hai&lt;/h2&gt;

&lt;p&gt;Xét xấp xỉ bậc hai được sử dụng trong gradient descent:
\(f(y) \approx f(x) + \nabla f(x)^T (y - x) + \frac{1}{2t} \|y - x\|_2^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần A&lt;/strong&gt;: Chứng minh rằng việc cực tiểu hóa xấp xỉ này theo \(y\) cho ta quy tắc cập nhật gradient descent \(y = x - t\nabla f(x)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần B&lt;/strong&gt;: Điều gì xảy ra nếu ta thay hệ số \(\frac{1}{2t}\) bằng \(\frac{\alpha}{2t}\) (với \(\alpha &amp;gt; 0\))? Thay đổi này ảnh hưởng như thế nào đến kích thước bước hiệu dụng?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần C&lt;/strong&gt;: Hãy diễn giải ý nghĩa hình học của số hạng \(\frac{1}{2t} \|y - x\|_2^2\). Số hạng này giúp ngăn chặn hiện tượng gì?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-2-kích-thước-bước-và-độ-cong-hàm-số&quot;&gt;Bài tập 2: Kích thước Bước và Độ cong Hàm số&lt;/h2&gt;

&lt;p&gt;Xét hai hàm bậc hai:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[f_1(x_1, x_2) = \frac{1}{2}(x_1^2 + x_2^2)\]
  &lt;/li&gt;
  &lt;li&gt;
\[f_2(x_1, x_2) = \frac{1}{2}(4x_1^2 + x_2^2)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phần A&lt;/strong&gt;: Tính ma trận Hessian (ma trận các đạo hàm riêng bậc hai) của cả hai hàm số.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần B&lt;/strong&gt;: Nếu xấp xỉ mỗi ma trận Hessian bằng \(\frac{1}{t}I\), giá trị \(t\) nào cho xấp xỉ tốt nhất đối với từng hàm?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần C&lt;/strong&gt;: Xuất phát từ điểm \((2, 2)\), thực hiện 3 bước lặp gradient descent trên cả hai hàm với kích thước bước vừa tìm được và so sánh hành vi hội tụ.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-3-chỉ-số-điều-kiện-và-tốc-độ-hội-tụ&quot;&gt;Bài tập 3: Chỉ số Điều kiện và Tốc độ Hội tụ&lt;/h2&gt;

&lt;p&gt;Xét hàm số \(f(x_1, x_2) = \frac{1}{2}(ax_1^2 + bx_2^2)\) với \(a &amp;gt; b &amp;gt; 0\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần A&lt;/strong&gt;: Chỉ số điều kiện \(\kappa = \frac{a}{b}\) đo lường đại lượng nào và liên quan ra sao đến hình dạng đường đồng mức của hàm số?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần B&lt;/strong&gt;: Chứng minh rằng kích thước bước cố định tối ưu cho tốc độ hội tụ nhanh nhất là \(t^* = \frac{2}{a + b}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần C&lt;/strong&gt;: So sánh tốc độ hội tụ trong ba trường hợp:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\kappa = 1\) (\(a = b = 1\))&lt;/li&gt;
  &lt;li&gt;\(\kappa = 4\) (\(a = 4, b = 1\))&lt;/li&gt;
  &lt;li&gt;\(\kappa = 100\) (\(a = 100, b = 1\))&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Điều gì xảy ra khi chỉ số điều kiện tăng lên?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-4-kích-thước-bước-theo-từng-tọa-độ&quot;&gt;Bài tập 4: Kích thước Bước theo Từng Tọa độ&lt;/h2&gt;

&lt;p&gt;Thay vì dùng chung một kích thước bước cho mọi tọa độ, xét quy tắc cập nhật:
\(x_1^{(k+1)} = x_1^{(k)} - t_1 \frac{\partial f}{\partial x_1}\)
\(x_2^{(k+1)} = x_2^{(k)} - t_2 \frac{\partial f}{\partial x_2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần A&lt;/strong&gt;: Với \(f(x_1, x_2) = \frac{1}{2}(ax_1^2 + bx_2^2)\), cần chọn \(t_1, t_2\) bằng bao nhiêu để mỗi tọa độ hội tụ sau đúng một bước?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần B&lt;/strong&gt;: Cách chọn này liên hệ như thế nào với việc xấp xỉ Hessian bằng một ma trận đường chéo thay vì \(\frac{1}{t}I\)?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần C&lt;/strong&gt;: Cài đặt phương pháp cập nhật theo tọa độ này và so sánh với gradient descent chuẩn trên một hàm bậc hai có chỉ số điều kiện lớn.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-5-trực-quan-hóa-chất-lượng-xấp-xỉ&quot;&gt;Bài tập 5: Trực quan hóa Chất lượng Xấp xỉ&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Phần A&lt;/strong&gt;: Với hàm \(f(x_1, x_2) = \frac{1}{2}(4x_1^2 + x_2^2)\), vẽ đường đồng mức của hàm thực và đường đồng mức của xấp xỉ bậc hai \(f(x) + \nabla f(x)^T (y - x) + \frac{1}{2t} \|y - x\|_2^2\) quanh điểm \(x = (1, 1)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần B&lt;/strong&gt;: Thử nghiệm nhiều giá trị \(t\) khác nhau và quan sát sự thay đổi về chất lượng xấp xỉ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần C&lt;/strong&gt;: Giá trị \(t\) nào làm cho đường đồng mức của hàm xấp xỉ bám sát đường đồng mức hàm thực nhất?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-6-so-sánh-chiến-lược-chọn-kích-thước-bước&quot;&gt;Bài tập 6: So sánh Chiến lược Chọn Kích thước Bước&lt;/h2&gt;

&lt;p&gt;So sánh ba chiến lược chọn kích thước bước trên hàm \(f(x) = \frac{1}{2}x^T A x\) với:
\(A = \begin{bmatrix} 10 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước cố định nhỏ&lt;/strong&gt;: \(t = 0.1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước cố định lớn&lt;/strong&gt;: \(t = 0.5\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước tối ưu theo trị riêng&lt;/strong&gt;: \(t = \frac{2}{\lambda_{\max} + \lambda_{\min}}\), trong đó \(\lambda_{\max}, \lambda_{\min}\) lần lượt là trị riêng lớn nhất và nhỏ nhất của \(A\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Phần A&lt;/strong&gt;: Tính các trị riêng của \(A\) và xác định kích thước bước tối ưu ở chiến lược 3.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần B&lt;/strong&gt;: Xuất phát từ điểm \((5, 5)\), chạy gradient descent với từng chiến lược trong 20 lần lặp.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần C&lt;/strong&gt;: Vẽ đường cong hội tụ và quỹ đạo di chuyển. Chiến lược nào đạt hiệu quả tốt nhất và vì sao?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-7-hàm-phi-tuyến-và-xấp-xỉ-bậc-hai&quot;&gt;Bài tập 7: Hàm Phi tuyến và Xấp xỉ Bậc hai&lt;/h2&gt;

&lt;p&gt;Xét hàm không phải bậc hai \(f(x) = e^{x_1} + x_2^2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần A&lt;/strong&gt;: Tính gradient và ma trận Hessian của hàm số.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phần B&lt;/strong&gt;: Tại điểm \(x = (0, 1)\), hãy so sánh kết quả sau một bước của ba cách cập nhật:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Một bước gradient descent với \(t = 0.1\).&lt;/li&gt;
  &lt;li&gt;Một bước cực tiểu hóa xấp xỉ bậc hai sử dụng Hessian thực.&lt;/li&gt;
  &lt;li&gt;Một bước cực tiểu hóa xấp xỉ bậc hai sử dụng \(\frac{1}{t}I\) với \(t = 0.1\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phần C&lt;/strong&gt;: Xấp xỉ nào đưa điểm lặp lại gần hướng cực tiểu thực hơn?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-lập-trình&quot;&gt;Bài tập Lập trình&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-8-cài-đặt-và-so-sánh&quot;&gt;Bài tập 8: Cài đặt và So sánh&lt;/h3&gt;

&lt;p&gt;Cài đặt và so sánh hiệu năng của hai biến thể gradient descent bằng đoạn mã sau:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;quadratic_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Tính f(x) = 0.5 * x^T A x&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gradient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Tính gradient của f(x) = 0.5 * x^T A x&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;standard_gd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;step_size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Gradient descent chuẩn&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;history&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()]&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gradient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;step_size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
        
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;coordinate_wise_gd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;step_sizes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Gradient descent theo tọa độ&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;history&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()]&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gradient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# Áp dụng kích thước bước khác nhau cho mỗi tọa độ
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;step_sizes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
        
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# Kiểm tra trên các số điều kiện khác nhau
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;condition_numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kappa&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;condition_numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kappa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;# Kích thước bước tối ưu cho GD chuẩn
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;eigenvals&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;eigvals&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t_optimal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eigenvals&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eigenvals&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;# Kích thước bước tối ưu theo tọa độ
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;t_coord&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;diag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;# Chạy cả hai phương pháp
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;history_std&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;standard_gd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t_optimal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;history_coord&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;coordinate_wise_gd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t_coord&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;# Vẽ kết quả
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subplot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;semilogy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;quadratic_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;history_std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;b-&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;GD Chuẩn&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;semilogy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;quadratic_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;history_coord&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;r--&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;GD Theo tọa độ&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Lần lặp&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Giá trị Hàm&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Hội tụ (κ = &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kappa&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subplot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;history_std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;history_std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;b-o&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;GD Chuẩn&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;markersize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;history_coord&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;history_coord&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;r--s&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;GD Theo tọa độ&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;markersize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;x₁&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;x₂&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Quỹ đạo (κ = &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kappa&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;equal&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tight_layout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;bài-tập-9-trực-quan-hóa-tương-tác&quot;&gt;Bài tập 9: Trực quan hóa Tương tác&lt;/h3&gt;

&lt;p&gt;Xây dựng một biểu đồ tương tác hiển thị:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Đường đồng mức của hàm thực.&lt;/li&gt;
  &lt;li&gt;Đường đồng mức của xấp xỉ bậc hai.&lt;/li&gt;
  &lt;li&gt;Quỹ đạo của gradient descent.&lt;/li&gt;
  &lt;li&gt;Thanh trượt cho phép điều chỉnh kích thước bước để quan sát tác động lên quá trình hội tụ.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Sử dụng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;matplotlib&lt;/code&gt; widgets hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;plotly&lt;/code&gt; để tạo tương tác.&lt;/li&gt;
  &lt;li&gt;Minh họa cả trường hợp điều kiện tốt và điều kiện xấu.&lt;/li&gt;
  &lt;li&gt;Hiển thị sai số xấp xỉ khi thay đổi kích thước bước.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;gợi-ý-lời-giải&quot;&gt;Gợi ý Lời giải&lt;/h2&gt;

&lt;h3 id=&quot;lời-giải-bài-tập-1&quot;&gt;Lời giải Bài tập 1:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;: Lấy đạo hàm theo \(y\): \(\frac{\partial}{\partial y}\left[f(x) + \nabla f(x)^T (y - x) + \frac{1}{2t} \|y - x\|_2^2\right] = \nabla f(x) + \frac{1}{t}(y-x) = 0\). Giải phương trình thu được \(y = x - t\nabla f(x)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B&lt;/strong&gt;: Kích thước bước hiệu dụng trở thành \(\frac{t}{\alpha}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C&lt;/strong&gt;: Số hạng này đóng vai trò là số hạng phạt gần kề (proximal penalty), giúp hạn chế việc thực hiện bước nhảy quá xa khỏi điểm hiện tại.&lt;/p&gt;

&lt;h3 id=&quot;lời-giải-bài-tập-2&quot;&gt;Lời giải Bài tập 2:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\nabla^2 f_1 = I\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla^2 f_2 = \begin{bmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;B&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Với \(f_1\): \(t = 1\).&lt;/li&gt;
  &lt;li&gt;Với \(f_2\): \(t = 0.4\) (cực tiểu hóa sai số xấp xỉ \((4-\frac{1}{t})^2 + (1-\frac{1}{t})^2\) theo \(\frac{1}{t}\), thu được \(\frac{1}{t} = \frac{4+1}{2} = 2.5\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;lời-giải-bài-tập-3&quot;&gt;Lời giải Bài tập 3:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;: \(\kappa = \frac{a}{b}\) đo lường mức độ kéo dài (dẹt) của các đường đồng mức hình elip.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B&lt;/strong&gt;: Cực tiểu hóa hệ số co tối đa theo hai trục cho ta hệ số hội tụ tối ưu \(\frac{\kappa-1}{\kappa+1}\) tại \(t^* = \frac{2}{a+b}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C&lt;/strong&gt;: Chỉ số điều kiện càng lớn thì hội tụ càng chậm và quỹ đạo càng dễ dao động.&lt;/p&gt;

&lt;h3 id=&quot;lời-giải-bài-tập-4&quot;&gt;Lời giải Bài tập 4:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;: Chọn \(t_1 = \frac{1}{a}\), \(t_2 = \frac{1}{b}\); khi đó \(x_1^{+} = x_1 - \frac{1}{a}\cdot a x_1 = 0\) và \(x_2^{+} = 0\), tức hội tụ sau đúng một bước.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B&lt;/strong&gt;: Cách làm này tương ứng với việc xấp xỉ Hessian bằng ma trận đường chéo \(\text{diag}(a, b)\) (chính xác với hàm bậc hai tách biến này), thay vì dùng ma trận đẳng hướng \(\frac{1}{t}I\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C&lt;/strong&gt;: Cần dùng \(t_i = 1/A_{ii}\) (không dùng \(2/A_{ii}\), vì kích thước bước \(2/A_{ii}\) chỉ làm tọa độ đổi dấu và dao động mà không giảm về 0).&lt;/p&gt;

&lt;h3 id=&quot;lời-giải-bài-tập-6&quot;&gt;Lời giải Bài tập 6:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;: \(\lambda_{\max} \approx 10.424\), \(\lambda_{\min} \approx 0.576\), nên \(t = \frac{2}{11} \approx 0.182\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B–C&lt;/strong&gt;: Vì \(t = 0.5 &amp;gt; \frac{2}{\lambda_{\max}} \approx 0.192\) nên gradient descent với bước cố định lớn bị &lt;strong&gt;phân kỳ&lt;/strong&gt;; \(t = 0.1\) hội tụ nhưng chậm theo phương có độ cong nhỏ; \(t = \frac{2}{11}\) cho tốc độ hội tụ tốt nhất trong ba chiến lược.&lt;/p&gt;

&lt;h3 id=&quot;mục-tiêu-học-tập-chính&quot;&gt;Mục tiêu Học tập Chính:&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hiểu biết trực quan&lt;/strong&gt;: Mối liên hệ giữa kích thước bước và độ cong giả định của hàm số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kỹ năng thực hành&lt;/strong&gt;: Lựa chọn kích thước bước phù hợp cho các dạng bài toán khác nhau.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nền tảng lý thuyết&lt;/strong&gt;: Liên kết tính chất hình học của hàm mục tiêu với hành vi hội tụ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thực hành lập trình&lt;/strong&gt;: Cài đặt và so sánh trực tiếp các chiến lược cập nhật.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các bài tập trên giúp xây dựng nền tảng vững chắc về mối quan hệ giữa kích thước bước, độ cong và tốc độ hội tụ mà chưa cần sử dụng các phương pháp bậc hai nâng cao như phương pháp Newton.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-01-05 Tại sao Kích thước Bước lại Quan trọng?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_01_05_hessian_approximation/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_01_05_hessian_approximation</id>
   <content type="html">&lt;p&gt;Nhiều người mới học tối ưu hóa thường nghĩ công thức \(x^+ = x - t \nabla f(x)\) chỉ là một quy tắc kinh nghiệm: &lt;em&gt;“đi ngược hướng dốc nhân với một hệ số \(t\) chọn đại”&lt;/em&gt;. Thực tế sâu sắc hơn nhiều! Ẩn sau công thức tưởng chừng ngây thơ ấy là một &lt;strong&gt;mô hình xấp xỉ bậc hai thay thế cho ma trận Hessian&lt;/strong&gt;: ta thay ma trận độ cong thật \(\nabla^2 f(x)\) bằng một ma trận cầu đẳng hướng \(\frac{1}{t} I\)!&lt;/p&gt;

&lt;p&gt;Nhìn Gradient Descent dưới lăng kính &lt;strong&gt;xấp xỉ Hessian&lt;/strong&gt; sẽ giải đáp ngay lập tức câu hỏi lớn nhất của mọi người dùng thực tế: &lt;em&gt;tại sao cùng một kích thước bước \(t\) lại quá lớn ở chỗ cong gắt, quá nhỏ ở chỗ bằng phẳng, và vì sao chỉ số điều kiện \(\kappa\) lại quyết định sinh tử tốc độ hội tụ?&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hiểu-kích-thước-bước-qua-lăng-kính-độ-cong-bậc-hai&quot;&gt;Kiến thức cần nhớ: Hiểu kích thước bước qua lăng kính độ cong bậc hai&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau nối liền Gradient Descent (bậc nhất) với Phương pháp Newton (bậc hai):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình xấp xỉ bậc hai đẳng hướng (Isotropic Quadratic Model):&lt;/strong&gt; Tại điểm \(x\), thay vì dùng khai triển Taylor bậc hai đầy đủ \(f(x) + \nabla f(x)^T(y-x) + \frac{1}{2}(y-x)^T \nabla^2 f(x)(y-x)\) (phương pháp Newton), Gradient Descent thay \(\nabla^2 f(x)\) bằng \(\frac{1}{t} I\) rồi cực tiểu hóa mô hình:
\(x^+ = \arg\min_y \left\{ f(x) + \nabla f(x)^T(y - x) + \frac{1}{2t}\|y - x\|_2^2 \right\} = x - t\nabla f(x).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa hình học của \(1/t\):&lt;/strong&gt; Nghịch đảo kích thước bước \(1/t\) chính là &lt;strong&gt;độ cong giả định&lt;/strong&gt; của mặt parabol tròn xấp xỉ hàm \(f\)! Để parabol này nằm &lt;em&gt;phía trên&lt;/em&gt; hàm thật (đảm bảo bước đi chắc chắn làm giảm \(f\)), ta cần \(\frac{1}{t} I \succeq \nabla^2 f(x)\), tức là \(t \le \frac{1}{\lambda_{\max}(\nabla^2 f(x))}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gốc rễ của hiện tượng chậm trên hàm điều kiện xấu:&lt;/strong&gt; Khi hàm có độ cong cực lớn theo một phương (\(\lambda_{\max}\)) và cực nhỏ theo phương vuông góc (\(\lambda_{\min}\)), việc ép dùng chung một hình cầu bán kính \(1/t \ge \lambda_{\max}\) khiến mô hình trở nên quá “bảo thủ” theo phương thoai thoải!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-mô-hình-xấp-xỉ-với-hàm-thật-tại-hai-giá-trị-t&quot;&gt;Giải thích: So sánh mô hình xấp xỉ với hàm thật tại hai giá trị \(t\)&lt;/h3&gt;

&lt;p&gt;Xét hàm 1 biến \(f(y) = 2y^2\) (độ cong thật \(f&apos;&apos;(y) = 4\)) tại điểm \(x = 1\), nơi \(f(1) = 2\) và \(f&apos;(1) = 4\).
Mô hình xấp xỉ bậc hai của GD là \(q_t(y) = 2 + 4(y - 1) + \frac{1}{2t}(y - 1)^2\), đạt đáy tại \(x^+ = 1 - 4t\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chọn \(t = 0.25\) (tức \(1/t = 4 = f&apos;&apos;\), khớp chính xác độ cong thật):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(q_{0.25}(y) = 2 + 4(y-1) + 2(y-1)^2 = 2y^2\) — trùng khít 100% với hàm thật!&lt;/li&gt;
      &lt;li&gt;Đáy mô hình: \(x^+ = 1 - 4(0.25) = 0\) — chạm ngay nghiệm tối ưu chỉ sau &lt;strong&gt;1 bước&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn \(t = 0.1\) (tức \(1/t = 10 &amp;gt; 4\), parabol xấp xỉ cong gắt hơn hàm thật):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(q_{0.1}(y) \ge f(y)\) với mọi \(y\) (an toàn tuyệt đối!).&lt;/li&gt;
      &lt;li&gt;Đáy mô hình: \(x^+ = 1 - 4(0.1) = 0.6\), cho \(f(0.6) = 0.72 &amp;lt; 2\) (giảm đều nhưng chậm).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn \(t = 0.6\) (tức \(1/t \approx 1.67 &amp;lt; 4\), parabol xấp xỉ quá phẳng so với hàm thật):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(q_{0.6}(y)\) tụt xuống &lt;em&gt;dưới&lt;/em&gt; hàm thật, đánh lừa thuật toán nhảy quá đà: \(x^+ = 1 - 4(0.6) = -1.4\).&lt;/li&gt;
      &lt;li&gt;Giá trị hàm thật tăng vọt: \(f(-1.4) = 2(1.96) = 3.92 &amp;gt; 2\) — &lt;strong&gt;phân kỳ&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;Trong gradient descent, việc chọn kích thước bước \(t\) phù hợp có ý nghĩa rất quan trọng. Lý do nằm ở bản chất hình học của thuật toán: &lt;strong&gt;gradient descent ngầm đặt một giả định đơn giản về độ cong của hàm mục tiêu&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;ý-tưởng-cốt-lõi&quot;&gt;Ý tưởng Cốt lõi&lt;/h2&gt;

&lt;p&gt;Khi thực hiện cập nhật gradient descent:&lt;/p&gt;
&lt;blockquote&gt;
\[x^{(k+1)} = x^{(k)} - t \nabla f(x^{(k)})\]
&lt;/blockquote&gt;

&lt;p&gt;thực chất ta đang giải bài toán tối ưu cục bộ sau:&lt;/p&gt;
&lt;blockquote&gt;
\[x^{(k+1)} = \arg\min_y \left\{ \nabla f(x^{(k)})^T (y - x^{(k)}) + \frac{1}{2t} \|y - x^{(k)}\|^2 \right\}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa của từng thành phần:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Số hạng thứ nhất thúc đẩy di chuyển theo hướng giảm dốc nhất.&lt;/li&gt;
  &lt;li&gt;Số hạng thứ hai phạt các bước nhảy quá xa khỏi vị trí hiện tại \(x^{(k)}\).&lt;/li&gt;
  &lt;li&gt;Tham số \(t\) điều chỉnh sự cân bằng giữa hai xu hướng này.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kích-thước-bước-và-ước-lượng-độ-cong&quot;&gt;Kích thước Bước và Ước lượng Độ cong&lt;/h2&gt;

&lt;p&gt;Có thể hình dung kích thước bước theo mối quan hệ nghịch đảo với độ cong ước lượng của hàm số:&lt;/p&gt;
&lt;blockquote&gt;
\[t = \frac{1}{\text{độ cong ước lượng của hàm số}}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(t\) lớn&lt;/strong&gt;: Tương ứng với giả định hàm số tương đối phẳng tại vùng lân cận, cho phép thực hiện bước dài.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(t\) nhỏ&lt;/strong&gt;: Tương ứng với giả định hàm số cong mạnh tại vùng lân cận, buộc thuật toán thực hiện các bước ngắn và thận trọng hơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ví-dụ-minh-họa&quot;&gt;Ví dụ Minh họa&lt;/h2&gt;

&lt;p&gt;Xét hai hàm bậc hai:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hàm phẳng (đẳng hướng)&lt;/strong&gt;: \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + x_2^2)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm dốc (dị hướng)&lt;/strong&gt;: \(f(x_1, x_2) = \frac{1}{2}(100x_1^2 + x_2^2)\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Với hàm thứ nhất, ta có thể chọn \(t = 1\) (bước lớn). Với hàm thứ hai, ta cần chọn \(t = 0.01\) (bước nhỏ) để tránh vượt quá điểm cực tiểu theo phương \(x_1\).&lt;/p&gt;

&lt;h2 id=&quot;suy-ra-quy-tắc-cập-nhật&quot;&gt;Suy ra Quy tắc Cập nhật&lt;/h2&gt;

&lt;p&gt;Để cực tiểu hóa biểu thức bậc hai:&lt;/p&gt;
&lt;blockquote&gt;
\[\nabla f(x)^T (y - x) + \frac{1}{2t} \|y - x\|^2\]
&lt;/blockquote&gt;

&lt;p&gt;ta lấy đạo hàm theo \(y\) và đặt bằng 0:&lt;/p&gt;
&lt;blockquote&gt;
\[\nabla f(x) + \frac{1}{t}(y - x) = 0\]
&lt;/blockquote&gt;

&lt;p&gt;Giải phương trình theo \(y\) thu được:&lt;/p&gt;
&lt;blockquote&gt;
\[y = x - t \nabla f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Đây chính là công thức cập nhật của gradient descent. Hệ số \(\frac{1}{2t}\) hoạt động như một lực đàn hồi kéo \(y\) về gần \(x\), hạn chế các bước nhảy quá lớn.&lt;/p&gt;

&lt;h2 id=&quot;khi-nào-gradient-descent-hoạt-động-hiệu-quả&quot;&gt;Khi nào Gradient Descent Hoạt động Hiệu quả?&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Trường hợp thuận lợi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm số có độ cong tương đương nhau theo mọi hướng.&lt;/li&gt;
  &lt;li&gt;Ví dụ: hàm có dạng hình bát tròn như \(f(x_1, x_2) = x_1^2 + x_2^2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trường hợp kém thuận lợi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm số rất dốc theo một hướng nhưng lại rất phẳng theo hướng khác.&lt;/li&gt;
  &lt;li&gt;Ví dụ: hàm có dạng thung lũng hẹp như \(f(x_1, x_2) = 100x_1^2 + x_2^2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;nguyên-tắc-chọn-kích-thước-bước&quot;&gt;Nguyên tắc Chọn Kích thước Bước&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Quy tắc thực hành&lt;/strong&gt;: Có thể bắt đầu thử từ \(t = 0.1\) và điều chỉnh theo hành vi hội tụ:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu quá trình lặp dao động mạnh: giảm \(t\).&lt;/li&gt;
  &lt;li&gt;Nếu quá trình lặp hội tụ quá chậm: tăng \(t\).&lt;/li&gt;
  &lt;li&gt;Nếu biết rõ độ cong lớn nhất và nhỏ nhất của hàm số: chọn \(t \approx \frac{2}{\text{độ cong lớn nhất} + \text{độ cong nhỏ nhất}}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;trực-quan-hình-học&quot;&gt;Trực quan Hình học&lt;/h2&gt;

&lt;p&gt;Hãy hình dung việc đi xuống một sườn đồi trong bóng tối với ánh đèn pin hạn chế:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bước lớn&lt;/strong&gt;: Khi giả định địa hình phía trước bằng phẳng, ta bước dài hơn (nhưng có rủi ro bước hụt nếu địa hình thay đổi đột ngột).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bước nhỏ&lt;/strong&gt;: Khi giả định địa hình gồ ghề, ta bước ngắn hơn (an toàn nhưng tốn nhiều thời gian).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Gradient descent vận hành theo cơ chế tương tự về mặt toán học.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt-quy-trình&quot;&gt;Tóm tắt Quy trình&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Cơ chế của gradient descent:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Tính độ dốc cục bộ (gradient).&lt;/li&gt;
  &lt;li&gt;Xấp xỉ hàm số quanh điểm hiện tại bằng một mặt bậc hai dạng hình bát.&lt;/li&gt;
  &lt;li&gt;Di chuyển tới đáy của mặt bậc hai xấp xỉ đó.&lt;/li&gt;
  &lt;li&gt;Lặp lại cho đến khi hội tụ.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tác động của kích thước bước:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Quá lớn: vượt quá điểm cực tiểu và dao động hoặc phân kỳ.&lt;/li&gt;
  &lt;li&gt;Quá nhỏ: tiến độ hội tụ rất chậm.&lt;/li&gt;
  &lt;li&gt;Phù hợp: hội tụ nhanh và ổn định.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;điểm-mấu-chốt&quot;&gt;Điểm Mấu chốt&lt;/h2&gt;

&lt;p&gt;Kích thước bước phản ánh &lt;strong&gt;ước lượng của ta về độ cong cục bộ của hàm mục tiêu&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(t = 0.01\) tương ứng với hàm có độ cong rất lớn.&lt;/li&gt;
  &lt;li&gt;\(t = 1.0\) tương ứng với hàm tương đối phẳng.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ước lượng độ cong càng sát với thực tế, gradient descent hội tụ càng nhanh.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06 Gradient Descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_00_gradient_descent/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter06/06_00_gradient_descent</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng bạn bị thả xuống một sườn núi mịt mù sương trắng vào lúc chập tối, không có bản đồ toàn cảnh, chỉ có chiếc đèn pin rọi đủ thấy độ dốc ngay dưới chân mình. Làm sao để đi xuống tận đáy thung lũng? Quy tắc trực giác nhất của con người cũng chính là thuật toán làm nên cuộc cách mạng trí tuệ nhân tạo hiện đại: &lt;strong&gt;cảm nhận hướng dốc xuống gắt nhất tại chỗ đang đứng, bước đi một bước vừa phải, rồi lặp lại&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Chương 06 mở ra thế giới của các &lt;strong&gt;thuật toán tối ưu hóa bậc nhất&lt;/strong&gt; bắt đầu từ &lt;strong&gt;Gradient Descent (Hạ Gradient)&lt;/strong&gt;. Nếu các chương trước trả lời câu hỏi &lt;em&gt;“thế nào là một bài toán lồi đẹp và điều kiện tối ưu trông ra sao?”&lt;/em&gt;, thì từ chương này trở đi ta trả lời câu hỏi thực chiến hơn nhiều: &lt;em&gt;“làm sao máy tính thực sự tìm ra nghiệm \(x^\star\) với hàng triệu hay hàng tỷ biến?”&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-chương-06--gradient-descent&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của Chương 06 — Gradient Descent&lt;/h2&gt;

&lt;p&gt;Toàn bộ 23 bài học trong chương này xoay quanh bốn câu hỏi cốt lõi của phương pháp hạ gradient:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cơ chế bước nhảy &amp;amp; Hình học độ cong:&lt;/strong&gt; Tại sao quy tắc \(x^{(k+1)} = x^{(k)} - t_k \nabla f(x^{(k)})\) lại xuất phát từ việc cực tiểu hóa một parabol xấp xỉ địa phương thay cho ma trận Hessian đầy đủ?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược chọn kích thước bước (Step Size Selection):&lt;/strong&gt; Bước quá nhỏ thì đi mãi không tới đích; bước quá lớn thì vọt qua đáy và phân kỳ. Chương này phân tích ba chiến lược kinh điển: bước cố định (fixed), tìm kiếm đường lùi (backtracking) và tìm kiếm đường chính xác (exact line search).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết hội tụ định lượng (Convergence Analysis):&lt;/strong&gt; Dưới điều kiện \(L\)-trơn (gradient Lipschitz), GD hội tụ với tốc độ \(O(1/k)\); nếu thêm tính lồi mạnh \(m\), tốc độ nhảy vọt lên hội tụ tuyến tính \(O(c^k)\) phụ thuộc vào chỉ số điều kiện \(\kappa = L/m\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mở rộng thực chiến cho Học máy quy mô lớn:&lt;/strong&gt; Từ Gradient Boosting (hạ gradient trong không gian hàm), Stochastic Gradient Descent (SGD cho dữ liệu lớn), Momentum (quán tính phá thế zíc-zắc), cho đến Điều chuẩn (Ridge/Lasso) và các thuật toán hiện đại như Lion hay Schedule-Free.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-3-bước-gradient-descent-để-cảm-nhận-nhịp-hội-tụ&quot;&gt;Giải thích: Chạy tay 3 bước Gradient Descent để cảm nhận nhịp hội tụ&lt;/h3&gt;

&lt;p&gt;Xét hàm lồi bậc hai đơn giản \(f(x) = \frac{1}{2}(x - 4)^2\) với đạo hàm \(f&apos;(x) = x - 4\) và nghiệm tối ưu \(x^\star = 4,\; f^\star = 0\). Bắt đầu từ \(x^{(0)} = 0\) với kích thước bước cố định \(t = 0.5\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(k = 0\):&lt;/strong&gt; \(x^{(0)} = 0 \implies f&apos;(0) = -4\). Cập nhật:
\(x^{(1)} = 0 - 0.5(-4) = 2, \qquad f(2) = \frac{1}{2}(-2)^2 = 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(k = 1\):&lt;/strong&gt; \(x^{(1)} = 2 \implies f&apos;(2) = -2\). Cập nhật:
\(x^{(2)} = 2 - 0.5(-2) = 3, \qquad f(3) = \frac{1}{2}(-1)^2 = 0.5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(k = 2\):&lt;/strong&gt; \(x^{(2)} = 3 \implies f&apos;(3) = -1\). Cập nhật:
\(x^{(3)} = 3 - 0.5(-1) = 3.5, \qquad f(3.5) = \frac{1}{2}(-0.5)^2 = 0.125.\)&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Quy luật hiện ra:&lt;/strong&gt; Sau mỗi bước, khoảng cách tới nghiệm $$&lt;/td&gt;
          &lt;td&gt;x^{(k)} - 4&lt;/td&gt;
          &lt;td&gt;\(giảm đúng một nửa (\)4 \to 2 \to 1 \to 0.5\(), còn sai số hàm mục tiêu giảm đi **4 lần** (\)8 \to 2 \to 0.5 \to 0.125\()! Nhưng nếu ta chọn tham lam\)t = 2.5\(, thì\)x^{(1)} = 10,\; x^{(2)} = -5,\; x^{(3)} = 17.5 \to \infty$$ — phân kỳ ngay lập tức!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong chương này, chúng ta sẽ tìm hiểu &lt;strong&gt;Gradient Descent&lt;/strong&gt; (thuật toán hạ gradient), một trong những phương pháp cơ bản và quan trọng nhất trong tối ưu hóa.&lt;/p&gt;

&lt;p&gt;Trong các thuật toán tối ưu hóa, việc lựa chọn hướng tìm kiếm và kích thước bước đóng vai trò quyết định đối với tốc độ và khả năng hội tụ. Gradient descent di chuyển theo hướng ngược chiều gradient (hướng gradient âm). Kích thước bước có thể được giữ cố định hoặc điều chỉnh thích ứng, và cả hai cách tiếp cận này sẽ được trình bày trong chương này.&lt;/p&gt;

&lt;p&gt;Để gradient descent hội tụ, hàm mục tiêu cần thỏa mãn một số điều kiện nhất định. Khi các điều kiện này được đáp ứng, ta có thể phân tích tốc độ hội tụ của thuật toán. Nếu hàm mục tiêu có thêm tính lồi mạnh, quá trình hội tụ sẽ diễn ra nhanh hơn đáng kể; chương này cũng sẽ phân tích cụ thể tốc độ hội tụ trong trường hợp đó.&lt;/p&gt;

&lt;p&gt;Bên cạnh nền tảng lý thuyết, chúng ta sẽ xem xét các ứng dụng và biến thể quan trọng của gradient descent, bao gồm gradient boosting và stochastic gradient descent.&lt;/p&gt;

&lt;p&gt;Bài đọc tùy chọn &lt;a href=&quot;/contents/vi/chapter06/06_08_Applications_Recent/&quot;&gt;06-08 Ứng dụng và phát triển gần đây&lt;/a&gt; đối chiếu lý thuyết Lipschitz cổ điển với hiện tượng mép ổn định (edge of stability), thuật toán Lion và phương pháp trung bình không lịch bước (schedule-free averaging) giai đoạn 2021–2024. Tốc độ hội tụ tuyến tính ở mục 06-03-04 vẫn có thể áp dụng cho một số bài toán cực tiểu hóa rủi ro thực nghiệm (ERM) &lt;em&gt;không lồi&lt;/em&gt; thỏa mãn điều kiện Polyak–Łojasiewicz; nội dung liên kết này được trình bày trong ghi chú tùy chọn &lt;a href=&quot;/contents/vi/chapter28/28_05_pl_condition/&quot;&gt;28-05&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-11 Practical Exercises - Optimization Algorithms</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_11_Practical_Exercises_Optimization_Algorithms/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_11_Practical_Exercises_Optimization_Algorithms</id>
   <content type="html">&lt;p&gt;Reading convergence proofs builds intuition, but actually computing Hessian eigenvalues, running backtracking trials by hand, diagnosing SGD variance, and comparing momentum against vanilla gradient descent is what turns theory into engineering fluency. These practical exercises challenge you to execute, analyze, and tune every major first-order algorithm from Chapter 06.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-algorithmic-analysis-toolkit-for-these-exercises&quot;&gt;Key ideas: Algorithmic Analysis Toolkit for These Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Exact Quadratic Diagnostics&lt;/strong&gt;: For \(f(x) = \frac{1}{2}x^T Q x + c^T x\), immediately extract \(L = \lambda_{\max}(Q)\), \(m = \lambda_{\min}(Q)\), \(\kappa = L/m\), stability limit \(2/L\), and optimal fixed step \(t^\star = \frac{2}{L + m}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step-by-Step Line Search Verification&lt;/strong&gt;: Always write the Armijo RHS \(f(x_k) - \alpha t \|\nabla f(x_k)\|_2^2\) explicitly as a function of \(t\) before testing \(t = 1, \beta, \beta^2, \dots\) so each trial is a single clean comparison.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SGD &amp;amp; Momentum Tuning Checks&lt;/strong&gt;: Track both bias (mean iterate) and variance (spread across random draws) for SGD, and verify that momentum \(\beta \in [0, 1)\) stays below the stability ceiling \(\beta &amp;lt; 1\) with \(t &amp;lt; \frac{2(1 + \beta)}{L}\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Regularization Path Analysis&lt;/strong&gt;: When comparing Ridge vs. Lasso, check the optimality condition at \(w = 0\) (whether $$&lt;/td&gt;
          &lt;td&gt;g_j(0)&lt;/td&gt;
          &lt;td&gt;\le \lambda$$) to predict which features drop out to exact zero.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-warm-up-convergence-rate-calculation&quot;&gt;Worked example: Warm-Up Convergence Rate Calculation&lt;/h3&gt;

&lt;p&gt;Before starting Exercise 1, analyze \(f(x) = \frac{1}{2}x^T Q x\) with \(Q = \operatorname{diag}(2, 8)\) from \(x^{(0)} = (1, 1)\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Extract spectral parameters&lt;/strong&gt;: \(m = 2\), \(L = 8\), \(\kappa = L/m = 4\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the optimal fixed step size and contraction factor&lt;/strong&gt;:
\(t^\star = \frac{2}{L + m} = \frac{2}{10} = 0.20, \qquad \rho = \frac{\kappa - 1}{\kappa + 1} = \frac{3}{5} = 0.60.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the exact iterate formula&lt;/strong&gt;:
\(x^{(k)} = \bigl((1 - 0.2 \cdot 2)^k,\; (1 - 0.2 \cdot 8)^k\bigr) = \bigl(0.6^k,\; (-0.6)^k\bigr).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find the exact iteration \(k\) where \(\|x^{(k)}\|_2 \le 0.01\|x^{(0)}\|_2\)&lt;/strong&gt;:
Since \(\|x^{(k)}\|_2 = 0.6^k \|x^{(0)}\|_2\), we need \(0.6^k \le 0.01 \implies k \ge \frac{\ln(0.01)}{\ln(0.6)} = \frac{-4.6052}{-0.5108} \approx 9.02 \implies k = 10\) iterations!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---optimization-algorithms&quot;&gt;Practical Exercises - Optimization Algorithms&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd &amp;amp; Vandenberghe (2004) and Nocedal &amp;amp; Wright (2006).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-i-gradient-descent&quot;&gt;📝 &lt;strong&gt;Part I: Gradient Descent&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-1-convergence-rate-analysis&quot;&gt;&lt;strong&gt;Exercise 1: Convergence Rate Analysis&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider the function \(f(x) = \frac{1}{2}x^TQx\) with \(Q = \text{diag}(1, 4, 10)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Compute the gradient \(\nabla f(x)\)&lt;br /&gt;
b) With step size \(t = \frac{2}{m + L}\) (\(m = \lambda_{\min}(Q)\), \(L = \lambda_{\max}(Q)\)), compute the convergence rate&lt;br /&gt;
c) Starting from \(x^{(0)} = (1, 1, 1)^T\), compute \(x^{(1)}\), \(x^{(2)}\)&lt;br /&gt;
d) Estimate the number of iterations needed to reach \(\|x^{(k)}\| &amp;lt; 10^{-6}\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Gradient:**

$$\nabla f(x) = Qx = \begin{bmatrix} x_1 \\ 4x_2 \\ 10x_3 \end{bmatrix}$$

---

**b) Convergence rate:**

$$m = 1$$, $$L = 10$$

$$t = \frac{2}{1 + 10} = \frac{2}{11}$$

**Convergence rate:**

$$\|x^{(k+1)} - x^*\| \leq \left(\frac{L - m}{L + m}\right) \|x^{(k)} - x^*\|$$

$$= \frac{10 - 1}{10 + 1} \|x^{(k)} - x^*\| = \frac{9}{11} \|x^{(k)} - x^*\|$$

**Linear convergence** with ratio $$\approx 0.818$$.

---

**c) Iterations:**

$$x^{(0)} = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}$$

$$\nabla f(x^{(0)}) = \begin{bmatrix} 1 \\ 4 \\ 10 \end{bmatrix}$$

$$x^{(1)} = x^{(0)} - t \nabla f(x^{(0)}) = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix} - \frac{2}{11} \begin{bmatrix} 1 \\ 4 \\ 10 \end{bmatrix}$$

$$= \begin{bmatrix} 1 - \frac{2}{11} \\ 1 - \frac{8}{11} \\ 1 - \frac{20}{11} \end{bmatrix} = \begin{bmatrix} \frac{9}{11} \\ \frac{3}{11} \\ -\frac{9}{11} \end{bmatrix}$$

$$\nabla f(x^{(1)}) = \begin{bmatrix} \frac{9}{11} \\ \frac{12}{11} \\ -\frac{90}{11} \end{bmatrix}$$

$$x^{(2)} = x^{(1)} - \frac{2}{11} \nabla f(x^{(1)})$$

$$= \begin{bmatrix} \frac{9}{11} - \frac{18}{121} \\ \frac{3}{11} - \frac{24}{121} \\ -\frac{9}{11} + \frac{180}{121} \end{bmatrix} = \begin{bmatrix} \frac{81}{121} \\ \frac{9}{121} \\ -\frac{81}{121} \end{bmatrix}$$

---

**d) Number of iterations:**

$$\|x^{(k)}\| \leq \left(\frac{9}{11}\right)^k \|x^{(0)}\|$$

$$\|x^{(0)}\| = \sqrt{3}$$

Needed: $$\left(\frac{9}{11}\right)^k \sqrt{3} &amp;lt; 10^{-6}$$

$$k &amp;gt; \frac{\log(10^{-6}/\sqrt{3})}{\log(9/11)} = \frac{\log(10^{-6}) - 0.5\log(3)}{\log(9/11)}$$

$$\approx \frac{-13.8 - 0.55}{-0.20} \approx 72$$

**About 72 iterations are needed.**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-ii-momentum-methods&quot;&gt;📝 &lt;strong&gt;Part II: Momentum Methods&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-2-heavy-ball-vs-gradient-descent&quot;&gt;&lt;strong&gt;Exercise 2: Heavy Ball vs Gradient Descent&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider \(f(x) = x_1^2 + 9x_2^2\) (ill-conditioned with \(\kappa = 9\)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Compare GD and Heavy Ball starting from \(x^{(0)} = (3, 1)^T\)&lt;br /&gt;
b) Compute the optimal momentum parameter \(\beta\)&lt;br /&gt;
c) Compare the convergence rates&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Gradient Descent:**

$$\nabla f(x) = \begin{bmatrix} 2x_1 \\ 18x_2 \end{bmatrix}$$

Step size: $$t = \frac{2}{2 + 18} = 0.1$$

$$x^{(1)} = (3, 1) - 0.1(6, 18) = (2.4, -0.8)$$

$$x^{(2)} = (2.4, -0.8) - 0.1(4.8, -14.4) = (1.92, 0.64)$$

**Pattern:** Oscillates slowly toward $$(0, 0)$$.

---

**Heavy Ball:**

$$x^{(k+1)} = x^{(k)} - t\nabla f(x^{(k)}) + \beta(x^{(k)} - x^{(k-1)})$$

**Optimal $$\beta$$:**

$$\beta = \left(\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\right)^2 = \left(\frac{3 - 1}{3 + 1}\right)^2 = \left(\frac{1}{2}\right)^2 = 0.25$$

---

**b) Heavy Ball iterations:**

$$x^{(1)} = (2.4, -0.8)$$, $$x^{(2)} = (1.92, 0.64)$$ (the same as GD in the first steps, since there is no momentum yet)

$$x^{(3)} = (1.92, 0.64) - 0.1(3.84, 11.52) + 0.25((1.92, 0.64) - (2.4, -0.8))$$

$$= (1.92, 0.64) - (0.384, 1.152) + 0.25(-0.48, 1.44)$$

$$= (1.92, 0.64) - (0.384, 1.152) + (-0.12, 0.36)$$

$$= (1.416, -0.152)$$

---

**c) Convergence rate comparison:**

**GD:** $$\left(\frac{\kappa - 1}{\kappa + 1}\right)^k = \left(\frac{8}{10}\right)^k = 0.8^k$$

**Heavy Ball:** $$\left(\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\right)^{k} = 0.5^k$$

**Each Heavy Ball iteration shrinks the error by a factor of 0.5 (versus 0.8 for GD), so it needs about $$\ln 0.8 / \ln 0.5 \approx 3$$ times fewer iterations!**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iii-nesterovs-acceleration&quot;&gt;📝 &lt;strong&gt;Part III: Nesterov’s Acceleration&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-3-nesterov-vs-standard-gd&quot;&gt;&lt;strong&gt;Exercise 3: Nesterov vs Standard GD&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider \(f(x) = \frac{1}{2}\|Ax - b\|^2\) with \(A = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\), \(b = (2, 1)^T\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Compute the exact solution \(x^*\)&lt;br /&gt;
b) Implement Nesterov’s method&lt;br /&gt;
c) Compare with GD after 5 iterations&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Exact solution:**

$$\nabla f(x) = A^T(Ax - b) = 0$$

$$A^TAx = A^Tb$$

$$\begin{bmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} x = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 4 \\ 1 \end{bmatrix}$$

$$x^* = (1, 1)^T$$

---

**b) Nesterov&apos;s method:**

$$
\begin{align}
y^{(k)} &amp;amp;= x^{(k)} + \frac{k-1}{k+2}(x^{(k)} - x^{(k-1)}) \\
x^{(k+1)} &amp;amp;= y^{(k)} - t\nabla f(y^{(k)})
\end{align}
$$

With $$t = \frac{1}{L}$$, $$L = \lambda_{\max}(A^TA) = 4$$ → $$t = 0.25$$.

**From $$x^{(0)} = (0, 0)$$, $$x^{(1)} = (0, 0)$$:**

$$k=1$$: $$y^{(1)} = (0, 0)$$

$$\nabla f(y^{(1)}) = A^T(A(0,0) - (2,1)) = -A^Tb = (-4, -1)$$

$$x^{(2)} = (0, 0) - 0.25(-4, -1) = (1, 0.25)$$

$$k=2$$: $$y^{(2)} = (1, 0.25) + \frac{1}{4}((1, 0.25) - (0, 0)) = (1.25, 0.3125)$$

(Continue...)

---

**c) Comparison (after 5 iterations):**

| Method | $$x$$ after 5 iterations | $$\|x - x^*\|$$ |
|--------|-------------|----------------------|
| GD | $$(1, 0.763)$$ | $$0.237$$ |
| Nesterov | $$(1, 0.944)$$ | $$0.056$$ |

**Nesterov&apos;s error is about 4× smaller!** (GD: the error in the second coordinate is $$0.75^5 \approx 0.237$$)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iv-proximal-gradient&quot;&gt;📝 &lt;strong&gt;Part IV: Proximal Gradient&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-4-lasso-with-soft-thresholding&quot;&gt;&lt;strong&gt;Exercise 4: LASSO with Soft Thresholding&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consider LASSO: \(\min_x \frac{1}{2}\|Ax - b\|^2 + \lambda\|x\|_1\)&lt;/p&gt;

&lt;p&gt;With \(A = I\), \(b = (2, -1, 0.5)^T\), \(\lambda = 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the proximal gradient update&lt;br /&gt;
b) Compute the soft-thresholding operator&lt;br /&gt;
c) Iterate from \(x^{(0)} = 0\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Proximal gradient:**

$$f(x) = \frac{1}{2}\|x - b\|^2$$ (smooth), $$g(x) = \lambda\|x\|_1$$ (non-smooth)

$$x^{(k+1)} = \text{prox}_{tg}(x^{(k)} - t\nabla f(x^{(k)}))$$

$$= \text{prox}_{t\lambda\|\cdot\|_1}(x^{(k)} - t(x^{(k)} - b))$$

With $$t = 1$$:

$$x^{(k+1)} = \text{prox}_{\lambda\|\cdot\|_1}(b)$$

---

**b) Soft-thresholding:**

$$\text{prox}_{\lambda\|\cdot\|_1}(y) = S_\lambda(y)$$

$$S_\lambda(y_i) = \begin{cases}
y_i - \lambda &amp;amp; \text{if } y_i &amp;gt; \lambda \\
0 &amp;amp; \text{if } |y_i| \leq \lambda \\
y_i + \lambda &amp;amp; \text{if } y_i &amp;lt; -\lambda
\end{cases}$$

---

**c) Iteration:**

$$x^{(0)} = (0, 0, 0)$$

$$b = (2, -1, 0.5)$$, $$\lambda = 1$$

$$x^{(1)} = S_1(b) = (S_1(2), S_1(-1), S_1(0.5))$$

$$= (2-1, 0, 0) = (1, 0, 0)$$

**Converged in 1 step!** (because $$A = I$$)

**Solution:** $$x^* = (1, 0, 0)^T$$

**Explanation:**
- $$b_1 = 2 &amp;gt; \lambda$$ → shrink to $$1$$
- $$|b_2| = 1 = \lambda$$ → shrink to $$0$$
- $$|b_3| = 0.5 &amp;lt; \lambda$$ → shrink to $$0$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-v-coordinate-descent&quot;&gt;📝 &lt;strong&gt;Part V: Coordinate Descent&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-5-coordinate-descent-for-qp&quot;&gt;&lt;strong&gt;Exercise 5: Coordinate Descent for QP&lt;/strong&gt;&lt;/h3&gt;

\[\min_x \quad x_1^2 + 2x_2^2 + x_1x_2 - 3x_1 - 4x_2\]

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Minimize w.r.t. \(x_1\) (fix \(x_2\))&lt;br /&gt;
b) Minimize w.r.t. \(x_2\) (fix \(x_1\))&lt;br /&gt;
c) Iterate from \((0, 0)\) until convergence&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Minimize w.r.t. $$x_1$$:**

$$f(x_1, x_2) = x_1^2 + x_1x_2 - 3x_1 + (2x_2^2 - 4x_2)$$

$$\frac{\partial f}{\partial x_1} = 2x_1 + x_2 - 3 = 0$$

$$x_1^* = \frac{3 - x_2}{2}$$

---

**b) Minimize w.r.t. $$x_2$$:**

$$\frac{\partial f}{\partial x_2} = 4x_2 + x_1 - 4 = 0$$

$$x_2^* = \frac{4 - x_1}{4}$$

---

**c) Coordinate descent:**

**Iteration 0:** $$(x_1, x_2) = (0, 0)$$

**Iter 1:**
- Fix $$x_2 = 0$$: $$x_1 = \frac{3-0}{2} = 1.5$$
- Fix $$x_1 = 1.5$$: $$x_2 = \frac{4-1.5}{4} = 0.625$$

**Iter 2:**
- Fix $$x_2 = 0.625$$: $$x_1 = \frac{3-0.625}{2} = 1.1875$$
- Fix $$x_1 = 1.1875$$: $$x_2 = \frac{4-1.1875}{4} = 0.703$$

**Iter 3:**
- $$x_1 = 1.148$$, $$x_2 = 0.713$$

**Converging to:** $$x^* \approx (1.143, 0.714)$$

**Exact solution (solve simultaneously):**

$$
\begin{cases}
2x_1 + x_2 = 3 \\
x_1 + 4x_2 = 4
\end{cases}
\Rightarrow x^* = (\frac{8}{7}, \frac{5}{7}) = (1.143, 0.714)$$

✓

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;algorithm-comparison&quot;&gt;&lt;strong&gt;Algorithm Comparison:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Convergence&lt;/th&gt;
      &lt;th&gt;Per-iter cost&lt;/th&gt;
      &lt;th&gt;Best for&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;GD&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
      &lt;td&gt;Well-conditioned&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Heavy Ball&lt;/td&gt;
      &lt;td&gt;\(O(\rho^k)\), \(\rho &amp;lt; 1\)&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
      &lt;td&gt;Ill-conditioned&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Nesterov&lt;/td&gt;
      &lt;td&gt;\(O(1/k^2)\)&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
      &lt;td&gt;Smooth convex&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Proximal GD&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;\(O(n)\) + prox&lt;/td&gt;
      &lt;td&gt;Composite (smooth + non-smooth)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Coordinate Descent&lt;/td&gt;
      &lt;td&gt;Varies&lt;/td&gt;
      &lt;td&gt;\(O(n/m)\)&lt;/td&gt;
      &lt;td&gt;Large-scale, separable&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;when-to-use-what&quot;&gt;&lt;strong&gt;When to use what:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;GD:&lt;/strong&gt; Simple, well-conditioned&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Momentum:&lt;/strong&gt; Ill-conditioned quadratics&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov:&lt;/strong&gt; Need fast convergence, can afford acceleration overhead&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Proximal:&lt;/strong&gt; Non-smooth regularization (\(\ell_1\), nuclear norm)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate:&lt;/strong&gt; Huge dimension, coordinate-wise cheap&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 9.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nocedal, J., &amp;amp; Wright, S. J.&lt;/strong&gt; (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt;. Springer. Chapters 2-3.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nesterov, Y.&lt;/strong&gt; (2004). &lt;em&gt;Introductory Lectures on Convex Optimization&lt;/em&gt;. Springer.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

</content>
 </entry>
 
 <entry>
   <title>06-10 Comprehensive Review - Foundations of Convex Optimization (Chapters 00-06)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_10_Comprehensive_Review_Ch00-06/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_10_Comprehensive_Review_Ch00-06</id>
   <content type="html">&lt;p&gt;Six chapters in, you have climbed from basic multivariable derivatives and convex sets all the way to canonical conic programs and first-order optimization theory. Before advancing to nonsmooth subgradients and duality in the second half of the course, this comprehensive review weaves Chapters 00 through 06 into one unified mental map—so you can see how linear algebra, convexity, canonical classes, and gradient descent fit together as a single coherent machine.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-unified-arc-of-chapters-0006&quot;&gt;Key ideas: The Unified Arc of Chapters 00–06&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Foundations (Chapters 00–03)&lt;/strong&gt;: Positive semidefinite matrices (\(H \succeq 0\)), affine/convex sets, epigraphs, Jensen’s inequality, and convexity-preserving operations (nonnegative sums, affine composition, pointwise maxima, partial minimization).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Problem Contract (Chapter 04)&lt;/strong&gt;: Standard form (convex \(f, g_i\); affine \(h_j\)), local-implies-global optimality, variational optimality \(\nabla f(x^\star)^T(y - x^\star) \ge 0\), and legal rewrites (monotone maps, variable changes, slacks, relaxations).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Canonical Taxonomy (Chapter 05)&lt;/strong&gt;: The nested solver hierarchy \(\mathrm{LP} \subset \mathrm{QP} \subset \mathrm{QCQP} \subset \mathrm{SOCP} \subset \mathrm{SDP} \subset \mathrm{CP}\), plus log-convex Geometric Programming, Gaussian-MLE Least Squares, and Logistic Regression.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Algorithms (Chapter 06)&lt;/strong&gt;: Gradient descent, Armijo backtracking, exact line search, \(L\)-smoothness (\(O(1/k)\)), \(m\)-strong convexity (linear convergence governed by \(\kappa = L/m\)), SGD, Momentum, and L1/L2 regularization.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-one-end-to-end-problem-connecting-chapters-0006&quot;&gt;Worked example: One End-to-End Problem Connecting Chapters 00–06&lt;/h3&gt;

&lt;p&gt;Consider Ridge regression with design matrix \(A = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\), target \(b = \begin{bmatrix} 4 \\ 3 \end{bmatrix}\), and \(\lambda = 1\):
\(\min_{x \in \mathbb{R}^2} \quad f(x) = \frac{1}{2}\|Ax - b\|_2^2 + \frac{1}{2}\|x\|_2^2.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 00–03 (Calculus &amp;amp; Convexity)&lt;/strong&gt;: Expand \(f(x) = \frac{1}{2}x^T(A^T A + I)x - (A^T b)^T x + \frac{1}{2}\|b\|_2^2\). The Hessian is \(H = A^T A + I = \operatorname{diag}(5, 2) \succ 0\), proving strict and \(2\)-strong convexity.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 04 (Optimality Condition)&lt;/strong&gt;: Since \(C = \mathbb{R}^2\) is unconstrained, global optimality is \(\nabla f(x^\star) = Hx^\star - A^T b = 0\), where \(A^T b = (8, 3)^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 05 (Canonical Form &amp;amp; Closed-Form QP)&lt;/strong&gt;: This is an unconstrained strictly convex QP (regularized least squares) with unique solution \(x^\star = H^{-1} A^T b = (8/5,\; 3/2)^T = (1.6,\; 1.5)^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 06 (Gradient Descent Rate)&lt;/strong&gt;: Here \(L = 5\), \(m = 2\), \(\kappa = 2.5\). Starting from \(x^{(0)} = (0, 0)\) with optimal fixed step \(t^\star = \frac{2}{5 + 2} = \frac{2}{7}\), the distance to \(x^\star\) contracts by \(\frac{5 - 2}{5 + 2} = \frac{3}{7} \approx 0.429\) every single iteration!&lt;/li&gt;
&lt;/ol&gt;

&lt;script&gt;
window.MathJax = {
  tex: {
    inlineMath: [[&apos;\\(&apos;, &apos;\\)&apos;]],
    displayMath: [[&apos;\\[&apos;, &apos;\\]&apos;], [&apos;$$&apos;, &apos;$$&apos;]],
    processEscapes: true,
    processEnvironments: true
  },
  options: {
    ignoreHtmlClass: &quot;.*|&quot;,
    processHtmlClass: &quot;arithmatex&quot;
  }
};
&lt;/script&gt;

&lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?features=es6&quot;&gt;&lt;/script&gt;

&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;h1 id=&quot;-comprehensive-review-foundations-of-convex-optimization&quot;&gt;📚 Comprehensive Review: Foundations of Convex Optimization&lt;/h1&gt;

&lt;p&gt;This is a comprehensive review of the core concepts from chapter 00 to chapter 06, arranged to build knowledge logically from the mathematical foundations up to practical algorithms.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;️-part-i-mathematical-foundations-chapter-00&quot;&gt;🏗️ &lt;strong&gt;PART I: MATHEMATICAL FOUNDATIONS (Chapter 00)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-1-basic-calculus&quot;&gt;🔢 &lt;strong&gt;1. Basic Calculus&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;derivatives-and-gradients&quot;&gt;&lt;strong&gt;Derivatives and Gradients&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Derivative:&lt;/strong&gt; \(f&apos;(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Partial derivative:&lt;/strong&gt; \(\frac{\partial f}{\partial x_i}\) - the derivative with respect to \(x_i\) when the other variables are held fixed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient:&lt;/strong&gt; \(\nabla f = \begin{pmatrix} \frac{\partial f}{\partial x_1} \\ \vdots \\ \frac{\partial f}{\partial x_n} \end{pmatrix}\) - the vector pointing in the direction of steepest ascent&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;directional-derivatives-and-taylor-series&quot;&gt;&lt;strong&gt;Directional Derivatives and Taylor Series&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Directional derivative:&lt;/strong&gt; \(D_{\mathbf{u}}f = \nabla f \cdot \mathbf{u} = \|\nabla f\| \cos \theta\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;First-order Taylor series:&lt;/strong&gt; \(f(\mathbf{x}) \approx f(\mathbf{x}_0) + \nabla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-order Taylor series:&lt;/strong&gt; \(f(\mathbf{x}) \approx f(\mathbf{x}_0) + \nabla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0) + \frac{1}{2} (\mathbf{x} - \mathbf{x}_0)^T \nabla^2 f(\mathbf{x}_0) (\mathbf{x} - \mathbf{x}_0)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-2-linear-algebra&quot;&gt;📐 &lt;strong&gt;2. Linear Algebra&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;vectors-and-operations&quot;&gt;&lt;strong&gt;Vectors and Operations&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dot product:&lt;/strong&gt; \(\mathbf{u} \cdot \mathbf{v} = \sum_{i=1}^n u_i v_i = \|\mathbf{u}\| \|\mathbf{v}\| \cos \theta\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vector norms:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;L2 (Euclid): \(\|\mathbf{x}\|_2 = \sqrt{\sum_{i=1}^n x_i^2}\)&lt;/li&gt;
      &lt;li&gt;L1 (Manhattan): \(\|\mathbf{x}\|_1 = \sum_{i=1}^n \lvert x_i \rvert\)&lt;/li&gt;
      &lt;li&gt;L∞ (Max): \(\|\mathbf{x}\|_\infty = \max_i \lvert x_i \rvert\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;matrices-and-eigenvalues&quot;&gt;&lt;strong&gt;Matrices and Eigenvalues&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Matrix multiplication:&lt;/strong&gt; \((AB)_{ij} = \sum_{k} A_{ik} B_{kj}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Eigenvalue/eigenvector:&lt;/strong&gt; \(A\mathbf{v} = \lambda \mathbf{v}\) with \(\mathbf{v} \neq \mathbf{0}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Positive definite matrix:&lt;/strong&gt; \(A \succ 0 \Leftrightarrow \mathbf{x}^T A \mathbf{x} &amp;gt; 0, \forall \mathbf{x} \neq 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-3-set-theory&quot;&gt;📊 &lt;strong&gt;3. Set Theory&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;basic-sets&quot;&gt;&lt;strong&gt;Basic Sets&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Open set:&lt;/strong&gt; Every point has a neighborhood contained in the set&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closed set:&lt;/strong&gt; Contains all of its boundary points&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compact set:&lt;/strong&gt; Closed and bounded in \(\mathbb{R}^n\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;continuity&quot;&gt;&lt;strong&gt;Continuity&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Continuous:&lt;/strong&gt; \(\lim_{x \to x_0} f(x) = f(x_0)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Uniformly continuous:&lt;/strong&gt; \(\forall \epsilon &amp;gt; 0, \exists \delta &amp;gt; 0\) such that \(\lvert x-y \rvert &amp;lt; \delta \Rightarrow \lvert f(x)-f(y) \rvert &amp;lt; \epsilon\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-ii-optimization-concepts-chapter-01&quot;&gt;🎯 &lt;strong&gt;PART II: OPTIMIZATION CONCEPTS (Chapter 01)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-4-the-general-optimization-problem&quot;&gt;🔍 &lt;strong&gt;4. The General Optimization Problem&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;standard-form&quot;&gt;&lt;strong&gt;Standard Form&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align} 
&amp;amp;\min_{x\in D}\ &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp; g_i(x) \le 0,\ i = 1, ..., m \\
&amp;amp;&amp;amp;&amp;amp; h_j(x) = 0,\ j = 1,\ ..., r
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Components:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\): optimization variable&lt;/li&gt;
  &lt;li&gt;\(f(x)\): objective function&lt;/li&gt;
  &lt;li&gt;\(g_i(x) \le 0\): inequality constraints&lt;/li&gt;
  &lt;li&gt;\(h_j(x) = 0\): equality constraints&lt;/li&gt;
  &lt;li&gt;\(x^*\): optimal solution&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-5-convex-optimization---the-golden-property&quot;&gt;🌟 &lt;strong&gt;5. Convex Optimization - The Golden Property&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition-of-a-convex-problem&quot;&gt;&lt;strong&gt;Definition of a Convex Problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;An optimization problem is convex when:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The objective function \(f\) is convex&lt;/li&gt;
  &lt;li&gt;The inequality constraint functions \(g_i\) are convex&lt;/li&gt;
  &lt;li&gt;The equality constraint functions \(h_j\) are affine&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;important-properties&quot;&gt;&lt;strong&gt;Important properties&lt;/strong&gt;&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Every local minimum of a convex optimization problem is a global minimum&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is what makes convex optimization reliable and efficient!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iii-convex-sets-chapter-02&quot;&gt;🔵 &lt;strong&gt;PART III: CONVEX SETS (Chapter 02)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-6-from-affine-to-convex&quot;&gt;📏 &lt;strong&gt;6. From Affine to Convex&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;affine-sets&quot;&gt;&lt;strong&gt;Affine Sets&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Definition:&lt;/strong&gt; \(\theta x_1 + (1-\theta)x_2 \in C\) for all \(\theta \in \mathbb{R}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine combination:&lt;/strong&gt; \(\sum_{i=1}^k \theta_i x_i\) with \(\sum_{i=1}^k \theta_i = 1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Meaning:&lt;/strong&gt; The line through two points&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;convex-sets&quot;&gt;&lt;strong&gt;Convex Sets&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Definition:&lt;/strong&gt; \(\theta x_1 + (1-\theta)x_2 \in C\) for all \(0 \le \theta \le 1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex combination:&lt;/strong&gt; \(\sum_{i=1}^k \theta_i x_i\) with \(\sum_{i=1}^k \theta_i = 1, \theta_i \ge 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Meaning:&lt;/strong&gt; The line segment joining two points&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;convex-cones&quot;&gt;&lt;strong&gt;Convex Cones&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Definition:&lt;/strong&gt; Both a cone and convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic combination:&lt;/strong&gt; \(\sum_{i=1}^k \theta_i x_i\) with \(\theta_i \ge 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Meaning:&lt;/strong&gt; Rays from the origin through the points&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-7-important-convex-sets&quot;&gt;🏗️ &lt;strong&gt;7. Important Convex Sets&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;basic-sets-1&quot;&gt;&lt;strong&gt;Basic Sets&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hyperplane:&lt;/strong&gt; \(\{x \mid a^T x = b\}\) - affine and convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Halfspace:&lt;/strong&gt; \(\{x \mid a^T x \le b\}\) - convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Euclidean ball:&lt;/strong&gt; \(\{x \mid \lVert x - x_c \rVert_2 \le r\}\) - convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ellipsoid:&lt;/strong&gt; \(\{x \mid (x-x_c)^T P^{-1} (x-x_c) \le 1\}\) with \(P \succ 0\) - convex&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;operations-that-preserve-convexity&quot;&gt;&lt;strong&gt;Operations that Preserve Convexity&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Intersection:&lt;/strong&gt; The intersection of convex sets is convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine combination:&lt;/strong&gt; \(\alpha C + \beta D\) is convex if \(C, D\) are convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine image:&lt;/strong&gt; \(f(C) = \{Ax + b \mid x \in C\}\) is convex if \(C\) is convex&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iv-convex-functions-chapter-03&quot;&gt;📈 &lt;strong&gt;PART IV: CONVEX FUNCTIONS (Chapter 03)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-8-definition-and-characterization&quot;&gt;🔍 &lt;strong&gt;8. Definition and Characterization&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;convex-functions&quot;&gt;&lt;strong&gt;Convex Functions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y)\)
for all \(x, y \in \text{dom}(f), 0 \le \theta \le 1\)&lt;/p&gt;

&lt;h4 id=&quot;types-of-convex-functions&quot;&gt;&lt;strong&gt;Types of Convex Functions&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Strictly convex:&lt;/strong&gt; Strict inequality for \(x \neq y, 0 &amp;lt; \theta &amp;lt; 1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strongly convex:&lt;/strong&gt; \(f - \frac{m}{2}\lVert x \rVert_2^2\) is convex for some \(m &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Concave function:&lt;/strong&gt; \(f\) is concave ⟺ \(-f\) is convex&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-9-characterizations-of-convex-functions&quot;&gt;🎯 &lt;strong&gt;9. Characterizations of Convex Functions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;epigraph-characterization&quot;&gt;&lt;strong&gt;Epigraph characterization&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f\) convex ⟺ \(\text{epi}(f) = \{(x,t) \mid f(x) \le t\}\) is a convex set&lt;/p&gt;

&lt;h4 id=&quot;first-order-characterization-differentiable-functions&quot;&gt;&lt;strong&gt;First-order characterization (differentiable functions)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f\) is convex ⟺ \(f(y) \ge f(x) + \nabla f(x)^T (y-x)\) for all \(x,y\)&lt;/p&gt;

&lt;h4 id=&quot;second-order-characterization-twice-differentiable-functions&quot;&gt;&lt;strong&gt;Second-order characterization (twice-differentiable functions)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f\) convex ⟺ \(\nabla^2 f(x) \succeq 0\) for all \(x\) (with \(\text{dom}(f)\) convex)&lt;/p&gt;

&lt;h3 id=&quot;-10-conjugate-functions&quot;&gt;⭐ &lt;strong&gt;10. Conjugate Functions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f^*(y) = \sup_{x \in \text{dom}(f)} \{y^T x - f(x)\}\)&lt;/p&gt;

&lt;h4 id=&quot;important-properties-1&quot;&gt;&lt;strong&gt;Important properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(f^*\) is always convex (whether or not \(f\) is convex)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel’s inequality:&lt;/strong&gt; \(f(x) + f^*(y) \ge x^T y\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel biconjugate:&lt;/strong&gt; If \(f\) is closed and convex: \(f^{**} = f\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-v-convex-optimization-basics-chapter-04&quot;&gt;🏆 &lt;strong&gt;PART V: CONVEX OPTIMIZATION BASICS (Chapter 04)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-11-optimality-conditions&quot;&gt;✅ &lt;strong&gt;11. Optimality Conditions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;first-order-condition-unconstrained&quot;&gt;&lt;strong&gt;First-order condition (unconstrained)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\nabla f(x^*) = 0\)&lt;/p&gt;

&lt;h4 id=&quot;first-order-condition-constrained&quot;&gt;&lt;strong&gt;First-order condition (constrained)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;For the problem \(\min_x f(x)\) s.t. \(x \in C\):
\(\nabla f(x^*)^T (y - x^*) \ge 0 \quad \forall y \in C\)&lt;/p&gt;

&lt;h4 id=&quot;second-order-conditions&quot;&gt;&lt;strong&gt;Second-order conditions&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Necessary condition:&lt;/strong&gt; \(\nabla f(x^*) = 0\) and \(\nabla^2 f(x^*) \succeq 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sufficient condition:&lt;/strong&gt; \(\nabla f(x^*) = 0\) and \(\nabla^2 f(x^*) \succ 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-12-problem-transformation-techniques&quot;&gt;🔄 &lt;strong&gt;12. Problem Transformation Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;slack-variables&quot;&gt;&lt;strong&gt;Slack Variables&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(g_i(x) \le 0 \quad \Rightarrow \quad g_i(x) + s_i = 0, \quad s_i \ge 0\)&lt;/p&gt;

&lt;h4 id=&quot;relaxation&quot;&gt;&lt;strong&gt;Relaxation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Replace the feasible set \(C\) with a superset \(\tilde{C} \supseteq C\)&lt;/p&gt;

&lt;h4 id=&quot;eliminating-equality-constraints&quot;&gt;&lt;strong&gt;Eliminating equality constraints&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;If \(Ax = b\) is solvable: \(x = x_0 + Fz\) with \(Ax_0 = b\) and \(\text{range}(F) = \text{null}(A)\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-vi-canonical-problems-chapter-05&quot;&gt;📊 &lt;strong&gt;PART VI: CANONICAL PROBLEMS (Chapter 05)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-13-hierarchy-of-optimization-problems&quot;&gt;🎯 &lt;strong&gt;13. Hierarchy of Optimization Problems&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;LP ⊆ QP ⊆ QCQP ⊆ SOCP ⊆ SDP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;linear-programming-lp&quot;&gt;&lt;strong&gt;Linear Programming (LP)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;c^T x \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;Ax = b \\
&amp;amp;&amp;amp;&amp;amp;x \succeq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The objective and constraints are all affine&lt;/li&gt;
  &lt;li&gt;If an optimal solution exists and the polyhedron has a vertex, there is always an optimal solution at a vertex&lt;/li&gt;
  &lt;li&gt;Solved by the Simplex algorithm&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;quadratic-programming-qp&quot;&gt;&lt;strong&gt;Quadratic Programming (QP)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;\frac{1}{2}x^T P x + q^T x \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;Gx \preceq h \\
&amp;amp;&amp;amp;&amp;amp;Ax = b
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convexity condition:&lt;/strong&gt; \(P \succeq 0\)&lt;/p&gt;

&lt;h3 id=&quot;-14-least-squares&quot;&gt;🎯 &lt;strong&gt;14. Least Squares&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;basic-problem&quot;&gt;&lt;strong&gt;Basic problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{x} \lVert Ax - b \rVert_2^2\)&lt;/p&gt;

&lt;h4 id=&quot;closed-form-solution-normal-equation&quot;&gt;&lt;strong&gt;Closed-form solution (Normal Equation)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^* = (A^T A)^{-1} A^T b\)&lt;/p&gt;

&lt;h4 id=&quot;linear-regression&quot;&gt;&lt;strong&gt;Linear regression&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Single variable:&lt;/strong&gt; \(m = \frac{\sum(x_i - \bar{x})(y_i - \bar{y})}{\sum(x_i - \bar{x})^2}\), \(c = \bar{y} - m\bar{x}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multiple variables:&lt;/strong&gt; \(\beta^* = (X^T X)^{-1} X^T y\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-vii-gradient-descent-chapter-06&quot;&gt;⚡ &lt;strong&gt;PART VII: GRADIENT DESCENT (Chapter 06)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-15-the-basic-algorithm&quot;&gt;🎯 &lt;strong&gt;15. The Basic Algorithm&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;update-rule&quot;&gt;&lt;strong&gt;Update rule&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t \nabla f(x^{(k-1)})\)&lt;/p&gt;

&lt;h4 id=&quot;explanation&quot;&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;The gradient \(\nabla f(x)\) points in the direction of steepest ascent&lt;/li&gt;
  &lt;li&gt;The negative gradient \(-\nabla f(x)\) points in the direction of steepest descent&lt;/li&gt;
  &lt;li&gt;At a minimum: \(\nabla f(x^*) = 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-16-choosing-the-step-size&quot;&gt;📏 &lt;strong&gt;16. Choosing the Step Size&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;fixed-step-size&quot;&gt;&lt;strong&gt;Fixed step size&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t = \text{const} &amp;gt; 0\)&lt;/p&gt;

&lt;h4 id=&quot;backtracking-line-search&quot;&gt;&lt;strong&gt;Backtracking line search&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Armijo condition:&lt;/strong&gt; \(f(x + t\Delta x) \le f(x) + \alpha t \nabla f(x)^T \Delta x\)&lt;/p&gt;

&lt;h4 id=&quot;exact-line-search&quot;&gt;&lt;strong&gt;Exact line search&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t^* = \arg\min_{t &amp;gt; 0} f(x + t\Delta x)\)&lt;/p&gt;

&lt;h3 id=&quot;-17-convergence-analysis&quot;&gt;📊 &lt;strong&gt;17. Convergence Analysis&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;lipschitz-condition&quot;&gt;&lt;strong&gt;Lipschitz condition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lVert \nabla f(x) - \nabla f(y) \rVert_2 \le L \lVert x - y \rVert_2\)&lt;/p&gt;

&lt;h4 id=&quot;convergence-for-convex-functions&quot;&gt;&lt;strong&gt;Convergence for convex functions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f(x^{(k)}) - f^* \le \frac{\lVert x^{(0)} - x^* \rVert_2^2}{2tk}\)
&lt;strong&gt;Rate:&lt;/strong&gt; \(O(1/k)\) - sublinear&lt;/p&gt;

&lt;h4 id=&quot;convergence-for-strongly-convex-functions&quot;&gt;&lt;strong&gt;Convergence for strongly convex functions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f(x^{(k)}) - f^* \le \left(1 - \frac{m}{L}\right)^k \left(f(x^{(0)}) - f^*\right) \quad (t = 1/L)\)
&lt;strong&gt;Rate:&lt;/strong&gt; \(O(\rho^k)\) with \(\rho &amp;lt; 1\) - linear&lt;/p&gt;

&lt;h3 id=&quot;-18-stochastic-gradient-descent&quot;&gt;🎲 &lt;strong&gt;18. Stochastic Gradient Descent&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;sum-problem&quot;&gt;&lt;strong&gt;Sum problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) = \min_x \sum_{i=1}^m f_i(x)\)&lt;/p&gt;

&lt;h4 id=&quot;batch-vs-sgd&quot;&gt;&lt;strong&gt;Batch vs SGD&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Batch GD:&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - t_k \sum_{i=1}^m \nabla f_i(x^{(k-1)})\) - Cost \(O(m)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SGD:&lt;/strong&gt; \(x^{(k)} = x^{(k-1)} - t_k \nabla f_{i_k}(x^{(k-1)})\) - Cost \(O(1)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;mini-batch-sgd&quot;&gt;&lt;strong&gt;Mini-batch SGD&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k \frac{1}{b} \sum_{i \in \mathcal{B}_k} \nabla f_i(x^{(k-1)})\)&lt;/p&gt;

&lt;h3 id=&quot;-19-momentum-and-advanced-techniques&quot;&gt;⚡ &lt;strong&gt;19. Momentum and Advanced Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;classical-momentum&quot;&gt;&lt;strong&gt;Classical Momentum&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
v^{(k)} &amp;amp;= \beta v^{(k-1)} + \nabla f(x^{(k-1)}) \\
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;adaptive-methods&quot;&gt;&lt;strong&gt;Adaptive Methods&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;AdaGrad:&lt;/strong&gt; Adapts the learning rate based on the gradient history&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;RMSprop:&lt;/strong&gt; Exponential moving average&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adam:&lt;/strong&gt; Combines momentum with an adaptive learning rate&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-viii-connections-and-synthesis&quot;&gt;🔗 &lt;strong&gt;PART VIII: CONNECTIONS AND SYNTHESIS&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-20-how-the-concepts-relate&quot;&gt;🌟 &lt;strong&gt;20. How the Concepts Relate&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;the-logical-build-up&quot;&gt;&lt;strong&gt;The logical build-up&lt;/strong&gt;&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Mathematical foundations (Ch 00)
    ↓
Optimization concepts (Ch 01)
    ↓
Convex sets (Ch 02) → Convex functions (Ch 03)
    ↓
Optimality conditions (Ch 04)
    ↓
Specific problems (Ch 05) → Algorithms (Ch 06)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;key-connections&quot;&gt;&lt;strong&gt;Key connections&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient&lt;/strong&gt; (Ch 00) → &lt;strong&gt;First-order optimality condition&lt;/strong&gt; (Ch 04) → &lt;strong&gt;Gradient descent&lt;/strong&gt; (Ch 06)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex sets&lt;/strong&gt; (Ch 02) + &lt;strong&gt;Convex functions&lt;/strong&gt; (Ch 03) → &lt;strong&gt;Convex problems&lt;/strong&gt; (Ch 01,04,05)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Taylor series&lt;/strong&gt; (Ch 00) → &lt;strong&gt;Explaining gradient descent&lt;/strong&gt; (Ch 06)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Eigenvalue&lt;/strong&gt; (Ch 00) → &lt;strong&gt;Positive definite matrices&lt;/strong&gt; (Ch 03) → &lt;strong&gt;Hessian&lt;/strong&gt; (Ch 04)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-21-unified-applications&quot;&gt;🎯 &lt;strong&gt;21. Unified Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;machine-learning-pipeline&quot;&gt;&lt;strong&gt;Machine Learning Pipeline&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Formulation:&lt;/strong&gt; Turn the ML problem into an optimization problem (Ch 01, 05)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Analysis:&lt;/strong&gt; Check convexity (Ch 02, 03)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimality:&lt;/strong&gt; Apply the optimality conditions (Ch 04)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm:&lt;/strong&gt; Use gradient descent (Ch 06)&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;example-linear-regression&quot;&gt;&lt;strong&gt;Example: Linear Regression&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(\min_w \lVert Xw - y \rVert_2^2\) (Ch 05 - Least Squares)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convexity:&lt;/strong&gt; The objective function is convex (Ch 03)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimality condition:&lt;/strong&gt; \(\nabla f(w^*) = 2X^T(Xw^* - y) = 0\) (Ch 04)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solution:&lt;/strong&gt; \(w^* = (X^TX)^{-1}X^Ty\) (Ch 05)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm:&lt;/strong&gt; Gradient descent with \(\nabla f(w) = 2X^T(Xw - y)\) (Ch 06)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-22-comparing-and-choosing-methods&quot;&gt;🔄 &lt;strong&gt;22. Comparing and Choosing Methods&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Problem&lt;/th&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Advantages&lt;/th&gt;
      &lt;th&gt;Disadvantages&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;LP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Simplex&lt;/td&gt;
      &lt;td&gt;Exact, efficient&lt;/td&gt;
      &lt;td&gt;LP only&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Active Set&lt;/td&gt;
      &lt;td&gt;Exact&lt;/td&gt;
      &lt;td&gt;Complex&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Least Squares&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Normal Equation&lt;/td&gt;
      &lt;td&gt;Closed-form solution&lt;/td&gt;
      &lt;td&gt;\(O(n^3)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;General Convex&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Gradient Descent&lt;/td&gt;
      &lt;td&gt;Simple, general&lt;/td&gt;
      &lt;td&gt;Slow&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Large Scale&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;SGD&lt;/td&gt;
      &lt;td&gt;Fast, scalable&lt;/td&gt;
      &lt;td&gt;Noisy&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;-23-principles-of-algorithm-design&quot;&gt;💡 &lt;strong&gt;23. Principles of Algorithm Design&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-theory-to-practice&quot;&gt;&lt;strong&gt;From theory to practice&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Analyze the problem:&lt;/strong&gt; Convexity, optimality conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choose the algorithm:&lt;/strong&gt; Based on the problem structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tune the parameters:&lt;/strong&gt; Learning rate, stopping criteria&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate performance:&lt;/strong&gt; Convergence rate, computational cost&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;important-trade-offs&quot;&gt;&lt;strong&gt;Important trade-offs&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Accuracy vs Speed:&lt;/strong&gt; Exact methods vs Gradient methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Memory vs Computation:&lt;/strong&gt; Batch vs SGD&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simplicity vs Performance:&lt;/strong&gt; Basic GD vs Advanced optimizers&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-ix-summary-and-next-directions&quot;&gt;🎓 &lt;strong&gt;PART IX: SUMMARY AND NEXT DIRECTIONS&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;-24-key-takeaways&quot;&gt;🌟 &lt;strong&gt;24. Key Takeaways&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;why-does-convex-optimization-matter&quot;&gt;&lt;strong&gt;Why does convex optimization matter?&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Guaranteed global optimality:&lt;/strong&gt; No “spurious” local minima&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Efficient algorithms:&lt;/strong&gt; Polynomial time algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rigorous theory:&lt;/strong&gt; Convergence guarantees&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Wide applications:&lt;/strong&gt; ML, signal processing, finance, engineering&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;gradient-descent---the-heart-of-ml&quot;&gt;&lt;strong&gt;Gradient descent - The heart of ML&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Backpropagation&lt;/strong&gt; = Gradient descent + Chain rule&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Deep learning&lt;/strong&gt; = SGD + Momentum + Adaptive methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Modern optimizers&lt;/strong&gt; = Sophisticated variants of gradient descent&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-25-next-directions&quot;&gt;🚀 &lt;strong&gt;25. Next Directions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;chapter-07-extending-the-theory&quot;&gt;&lt;strong&gt;Chapter 07+: Extending the theory&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Subgradient:&lt;/strong&gt; Non-smooth optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Proximal methods:&lt;/strong&gt; Composite optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duality:&lt;/strong&gt; Lagrangian and KKT conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point methods:&lt;/strong&gt; Polynomial-time algorithms&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;modern-applications&quot;&gt;&lt;strong&gt;Modern applications&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Deep learning:&lt;/strong&gt; Neural networks, transformers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reinforcement learning:&lt;/strong&gt; Policy optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Distributed optimization:&lt;/strong&gt; Federated learning&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quantum optimization:&lt;/strong&gt; Quantum algorithms&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-26-study-advice&quot;&gt;🎯 &lt;strong&gt;26. Study Advice&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;an-effective-approach&quot;&gt;&lt;strong&gt;An effective approach&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Master the foundations:&lt;/strong&gt; Basic mathematics is the key&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Connect the concepts:&lt;/strong&gt; Understand how the chapters relate&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practice computation:&lt;/strong&gt; Do exercises and implement algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply to real problems:&lt;/strong&gt; Use them on ML/AI problems&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;debugging-and-troubleshooting&quot;&gt;&lt;strong&gt;Debugging and troubleshooting&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Check convexity:&lt;/strong&gt; Make sure the problem is well-posed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify gradients:&lt;/strong&gt; Numerical vs analytical gradients&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Monitor convergence:&lt;/strong&gt; Loss curves, gradient norms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tune hyperparameters:&lt;/strong&gt; Learning rate, batch size&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-conclusion&quot;&gt;💡 &lt;strong&gt;CONCLUSION&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;The journey from chapter 00 to 06 has taken us through:&lt;/p&gt;

&lt;p&gt;🔢 &lt;strong&gt;Mathematical foundations&lt;/strong&gt; → 🎯 &lt;strong&gt;Optimization concepts&lt;/strong&gt; → 🔵 &lt;strong&gt;Convex sets&lt;/strong&gt; → 📈 &lt;strong&gt;Convex functions&lt;/strong&gt; → 🏆 &lt;strong&gt;Optimality conditions&lt;/strong&gt; → 📊 &lt;strong&gt;Specific problems&lt;/strong&gt; → ⚡ &lt;strong&gt;Practical algorithms&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is not just theoretical knowledge but &lt;strong&gt;the foundation of modern AI and machine learning&lt;/strong&gt;. Every concept plays an important role in understanding and developing advanced optimization algorithms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convex optimization&lt;/strong&gt; is the bridge between pure mathematics and practical applications, helping us solve complex problems efficiently and reliably.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;em&gt;“Optimization is the engine of machine learning, and convex optimization is its most reliable and well-understood component.”&lt;/em&gt;&lt;/p&gt;

&lt;style&gt;
/* Custom styling for comprehensive review */
.MathJax {
    vertical-align: baseline !important;
}

h2 {
    color: #2c3e50;
    border-bottom: 2px solid #3498db;
    padding-bottom: 10px;
}

h3 {
    color: #34495e;
    margin-top: 25px;
}

h4 {
    color: #7f8c8d;
    margin-top: 20px;
}

blockquote {
    background-color: #f8f9fa;
    border-left: 4px solid #3498db;
    padding: 15px;
    margin: 20px 0;
    font-style: italic;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

table th, table td {
    border: 1px solid #ddd;
    padding: 12px;
    text-align: left;
}

table th {
    background-color: #f2f2f2;
    font-weight: bold;
}

.highlight-box {
    background-color: #e8f4fd;
    border: 1px solid #bee5eb;
    border-radius: 5px;
    padding: 15px;
    margin: 15px 0;
}

.formula-box {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    padding: 10px;
    margin: 10px 0;
    text-align: center;
}

code {
    background-color: #f1f1f1;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
}

pre {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 5px;
    padding: 15px;
    overflow-x: auto;
}
&lt;/style&gt;

</content>
 </entry>
 
 <entry>
   <title>06-09 Multiple-Choice Quiz - Gradient Descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_09_Quiz_Gradient_Descent/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_09_Quiz_Gradient_Descent</id>
   <content type="html">&lt;p&gt;Knowing the formula \(x_{k+1} = x_k - t\nabla f(x_k)\) takes ten seconds; knowing &lt;em&gt;why&lt;/em&gt; it converges at \(O(1/k)\) versus \(O((1 - m/L)^k)\), when backtracking beats fixed steps, why SGD needs diminishing step sizes, and how momentum or L1/L2 penalties reshape the trajectory takes deep conceptual clarity. This quiz puts your entire Chapter 06 toolkit to the test.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-chapter-06-mastery-checklist&quot;&gt;Key ideas: Chapter 06 Mastery Checklist&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm &amp;amp; Step-Size Rules&lt;/strong&gt;: Gradient descent update mechanics, stability threshold \(t &amp;lt; 2/L\), Armijo backtracking condition \(f(x - t\nabla f) \le f(x) - \alpha t\|\nabla f\|_2^2\), and exact line-search orthogonality \(\nabla f(x_{k+1})^T \nabla f(x_k) = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence Theory&lt;/strong&gt;: \(L\)-smoothness quadratic upper bound, \(O(1/k)\) sublinear rate for convex functions, \(O(\kappa \log(1/\varepsilon))\) linear rate under \(m\)-strong convexity, and Nesterov’s \(\Omega(1/k^2)\) lower bound for first-order methods.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic &amp;amp; Accelerated Variants&lt;/strong&gt;: Unbiasedness and variance floor of SGD, Robbins–Monro step-size conditions, Heavy-Ball/Nesterov momentum mechanics, and functional gradient descent in Gradient Boosting.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization &amp;amp; Loss Geometry&lt;/strong&gt;: How L2 (Ridge) guarantees strong convexity and shrinks weights smoothly, while L1 (Lasso) induces exact sparsity via sharp coordinate corners.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-pre-quiz-diagnostic-on-convergence-rates&quot;&gt;Worked example: Pre-Quiz Diagnostic on Convergence Rates&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Warm-Up Question&lt;/strong&gt;: A twice-differentiable objective \(f: \mathbb{R}^2 \to \mathbb{R}\) has Hessian \(\nabla^2 f(x) = \begin{bmatrix} 6 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}\) everywhere. If we run fixed-step GD with \(t = 1/L\), what is the exact per-iteration contraction factor on \(\|x^{(k)} - x^\star\|_2\)?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Read off \(L\) and \(m\)&lt;/strong&gt;: \(L = \lambda_{\max} = 6\) and \(m = \lambda_{\min} = 2\), so \(\kappa = 3\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the step size&lt;/strong&gt;: \(t = 1/L = 1/6\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the iteration matrix \(I - t\nabla^2 f\)&lt;/strong&gt;:
\(I - \frac{1}{6}\begin{bmatrix} 6 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix} = \begin{bmatrix} 0 &amp;amp; 0 \\ 0 &amp;amp; 2/3 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Read off the worst-case spectral contraction&lt;/strong&gt;: The largest eigenvalue magnitude is \(\frac{2}{3} = 1 - \frac{m}{L} = 1 - \frac{2}{6}\). (Along \(x_1\) it hits \(x_1^\star\) in 1 step; along \(x_2\) it shrinks by \(2/3\) every step.) Keep this spectral picture handy for the quiz questions below!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-basic-gradient-descent&quot;&gt;🎯 &lt;strong&gt;Basic Gradient Descent&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Optimization problem:&lt;/strong&gt;
\(\min_x f(x), \quad f \text{ differentiable and } \text{dom}(f) = \mathbb{R}^n\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update rule:&lt;/strong&gt;
\(x^{(k)} = x^{(k-1)} - t \nabla f(x^{(k-1)}), \quad k = 1, 2, 3, \ldots\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pseudocode:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Given a starting point&lt;/strong&gt; \(x \in \text{dom}(f)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Repeat:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Determine the descent direction: \(\Delta x = -\nabla f(x)\)&lt;/li&gt;
      &lt;li&gt;Line search: choose a step size \(t &amp;gt; 0\)&lt;/li&gt;
      &lt;li&gt;Update: \(x = x + t \Delta x\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Until&lt;/strong&gt; the stopping criterion is satisfied&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Geometric interpretation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The gradient \(\nabla f(x)\) points in the direction of steepest ascent&lt;/li&gt;
  &lt;li&gt;The negative gradient \(-\nabla f(x)\) points in the direction of steepest descent&lt;/li&gt;
  &lt;li&gt;At a minimum: \(\nabla f(x^*) = 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-choosing-the-step-size&quot;&gt;📏 &lt;strong&gt;Choosing the Step Size&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-fixed-step-size&quot;&gt;&lt;strong&gt;1. Fixed step size&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t = \text{const} &amp;gt; 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Simple, fast to compute
&lt;strong&gt;Disadvantages:&lt;/strong&gt; Hard to choose a suitable value&lt;/p&gt;

&lt;h4 id=&quot;2-backtracking-line-search&quot;&gt;&lt;strong&gt;2. Backtracking line search&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Armijo condition:&lt;/strong&gt;
\(f(x + t\Delta x) \le f(x) + \alpha t \nabla f(x)^T \Delta x\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algorithm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Start with \(t = t_0\)&lt;/li&gt;
  &lt;li&gt;If the Armijo condition is not satisfied: \(t := \beta t\) (with \(0 &amp;lt; \beta &amp;lt; 1\))&lt;/li&gt;
  &lt;li&gt;Repeat until it is satisfied&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common parameters:&lt;/strong&gt; \(\alpha = 0.01 \div 0.3\), \(\beta = 0.1 \div 0.8\)&lt;/p&gt;

&lt;h4 id=&quot;3-exact-line-search&quot;&gt;&lt;strong&gt;3. Exact line search&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t^* = \arg\min_{t &amp;gt; 0} f(x + t\Delta x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Theoretically optimal
&lt;strong&gt;Disadvantages:&lt;/strong&gt; Computationally expensive&lt;/p&gt;

&lt;h3 id=&quot;-convergence-analysis&quot;&gt;📊 &lt;strong&gt;Convergence Analysis&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;lipschitz-condition&quot;&gt;&lt;strong&gt;Lipschitz condition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The gradient \(\nabla f\) is Lipschitz continuous with constant \(L &amp;gt; 0\):
\(\lVert \nabla f(x) - \nabla f(y) \rVert_2 \le L \lVert x - y \rVert_2\)&lt;/p&gt;

&lt;h4 id=&quot;convergence-theorem-for-convex-functions&quot;&gt;&lt;strong&gt;Convergence theorem for convex functions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;With a fixed step size \(t \le \frac{1}{L}\):
\(f(x^{(k)}) - f^* \le \frac{\lVert x^{(0)} - x^* \rVert_2^2}{2tk}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convergence rate:&lt;/strong&gt; \(O(1/k)\) - sublinear convergence&lt;/p&gt;

&lt;h4 id=&quot;convergence-theorem-for-strongly-convex-functions&quot;&gt;&lt;strong&gt;Convergence theorem for strongly convex functions&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;If \(f\) is strongly convex with parameter \(m &amp;gt; 0\):
\(f(x^{(k)}) - f^* \le \left(1 - \frac{m}{L}\right)^k \left(f(x^{(0)}) - f^*\right) \quad (t = 1/L)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convergence rate:&lt;/strong&gt; \(O(\rho^k)\) with \(\rho &amp;lt; 1\) - linear convergence&lt;/p&gt;

&lt;h4 id=&quot;condition-number&quot;&gt;&lt;strong&gt;Condition number&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\kappa = \frac{L}{m}\) - the ratio of the Lipschitz constant to the strong convexity parameter&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Small \(\kappa\): fast convergence&lt;/li&gt;
  &lt;li&gt;Large \(\kappa\): slow convergence (ill-conditioned)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-stochastic-gradient-descent-sgd&quot;&gt;🎲 &lt;strong&gt;Stochastic Gradient Descent (SGD)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;sum-problem&quot;&gt;&lt;strong&gt;Sum problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) = \min_x \sum_{i=1}^m f_i(x)\)&lt;/p&gt;

&lt;h4 id=&quot;batch-gradient-descent&quot;&gt;&lt;strong&gt;Batch Gradient Descent&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k \sum_{i=1}^m \nabla f_i(x^{(k-1)})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cost:&lt;/strong&gt; \(O(m)\) gradient evaluations per iteration&lt;/p&gt;

&lt;h4 id=&quot;stochastic-gradient-descent&quot;&gt;&lt;strong&gt;Stochastic Gradient Descent&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k \nabla f_{i_k}(x^{(k-1)})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cost:&lt;/strong&gt; \(O(1)\) gradient evaluations per iteration&lt;/p&gt;

&lt;h4 id=&quot;index-selection-strategies&quot;&gt;&lt;strong&gt;Index selection strategies&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cyclic rule:&lt;/strong&gt; \(i_k = 1, 2, \ldots, m, 1, 2, \ldots\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Randomized rule:&lt;/strong&gt; \(i_k\) chosen at random from \(\{1, 2, \ldots, m\}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;mini-batch-sgd&quot;&gt;&lt;strong&gt;Mini-batch SGD&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k \frac{1}{b} \sum_{i \in \mathcal{B}_k} \nabla f_i(x^{(k-1)})\)&lt;/p&gt;

&lt;p&gt;With \(\mathcal{B}_k\) a mini-batch of size \(b\)&lt;/p&gt;

&lt;h3 id=&quot;-gradient-descent-with-momentum&quot;&gt;⚡ &lt;strong&gt;Gradient Descent with Momentum&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;classical-momentum&quot;&gt;&lt;strong&gt;Classical Momentum&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
v^{(k)} &amp;amp;= \beta v^{(k-1)} + \nabla f(x^{(k-1)}) \\
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\)&lt;/p&gt;

&lt;h4 id=&quot;nesterov-accelerated-gradient&quot;&gt;&lt;strong&gt;Nesterov Accelerated Gradient&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\begin{align}
v^{(k)} &amp;amp;= \beta v^{(k-1)} + \nabla f(x^{(k-1)} - t\beta v^{(k-1)}) \\
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common parameter:&lt;/strong&gt; \(\beta = 0.9\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Accelerates convergence&lt;/li&gt;
  &lt;li&gt;Dampens local oscillations&lt;/li&gt;
  &lt;li&gt;Reduces the effect of noise&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-comparing-the-methods&quot;&gt;🔄 &lt;strong&gt;Comparing the Methods&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Speed/iteration&lt;/th&gt;
      &lt;th&gt;Memory&lt;/th&gt;
      &lt;th&gt;Convergence&lt;/th&gt;
      &lt;th&gt;Use case&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Batch GD&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Slow&lt;/td&gt;
      &lt;td&gt;High&lt;/td&gt;
      &lt;td&gt;Stable&lt;/td&gt;
      &lt;td&gt;Small datasets&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SGD&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Fast&lt;/td&gt;
      &lt;td&gt;Low&lt;/td&gt;
      &lt;td&gt;Noisy&lt;/td&gt;
      &lt;td&gt;Large datasets&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Mini-batch&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Medium&lt;/td&gt;
      &lt;td&gt;Medium&lt;/td&gt;
      &lt;td&gt;Balanced&lt;/td&gt;
      &lt;td&gt;Practice&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Momentum&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Fast&lt;/td&gt;
      &lt;td&gt;Low&lt;/td&gt;
      &lt;td&gt;Accelerated&lt;/td&gt;
      &lt;td&gt;Deep learning&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-practical-techniques&quot;&gt;🛠️ &lt;strong&gt;Practical Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;learning-rate-scheduling&quot;&gt;&lt;strong&gt;Learning Rate Scheduling&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Step decay:&lt;/strong&gt; \(t_k = t_0 \cdot \gamma^{\lfloor k/s \rfloor}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exponential decay:&lt;/strong&gt; \(t_k = t_0 \cdot e^{-\lambda k}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polynomial decay:&lt;/strong&gt; \(t_k = t_0 \cdot (1 + \lambda k)^{-p}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;adaptive-methods&quot;&gt;&lt;strong&gt;Adaptive Methods&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;AdaGrad:&lt;/strong&gt; Adapts the learning rate based on the gradient history&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;RMSprop:&lt;/strong&gt; Improves AdaGrad with an exponential moving average&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adam:&lt;/strong&gt; Combines momentum with an adaptive learning rate&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;regularization&quot;&gt;&lt;strong&gt;Regularization&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;L1 regularization:&lt;/strong&gt; \(f(x) + \lambda \lVert x \rVert_1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;L2 regularization:&lt;/strong&gt; \(f(x) + \frac{\lambda}{2} \lVert x \rVert_2^2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dropout:&lt;/strong&gt; Randomization in neural networks&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-real-world-applications&quot;&gt;📈 &lt;strong&gt;Real-World Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;machine-learning&quot;&gt;&lt;strong&gt;Machine Learning&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Linear regression:&lt;/strong&gt; \(\min_w \lVert Xw - y \rVert_2^2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Logistic regression:&lt;/strong&gt; \(\min_w \sum_i \log(1 + e^{-y_i w^T x_i})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Neural networks:&lt;/strong&gt; Backpropagation + SGD&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;deep-learning&quot;&gt;&lt;strong&gt;Deep Learning&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Convolutional Neural Networks (CNNs)&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recurrent Neural Networks (RNNs)&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Transformer models&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;optimization-problems&quot;&gt;&lt;strong&gt;Optimization Problems&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Portfolio optimization&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Signal processing&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computer vision&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-stopping-criteria&quot;&gt;🔍 &lt;strong&gt;Stopping Criteria&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;gradient-based&quot;&gt;&lt;strong&gt;Gradient-based&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lVert \nabla f(x^{(k)}) \rVert_2 &amp;lt; \epsilon\)&lt;/p&gt;

&lt;h4 id=&quot;function-value-based&quot;&gt;&lt;strong&gt;Function value-based&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(|f(x^{(k)}) - f(x^{(k-1)})| &amp;lt; \epsilon\)&lt;/p&gt;

&lt;h4 id=&quot;parameter-based&quot;&gt;&lt;strong&gt;Parameter-based&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lVert x^{(k)} - x^{(k-1)} \rVert_2 &amp;lt; \epsilon\)&lt;/p&gt;

&lt;h4 id=&quot;maximum-iterations&quot;&gt;&lt;strong&gt;Maximum iterations&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(k &amp;gt; k_{\max}\)&lt;/p&gt;

&lt;h3 id=&quot;️-challenges-and-solutions&quot;&gt;⚠️ &lt;strong&gt;Challenges and Solutions&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;common-problems&quot;&gt;&lt;strong&gt;Common problems:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vanishing/exploding gradients:&lt;/strong&gt; Gradients that are too small or too large&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Saddle points:&lt;/strong&gt; Saddle points in high-dimensional spaces&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Local minima:&lt;/strong&gt; Local minima (for non-convex functions)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ill-conditioning:&lt;/strong&gt; Large condition number&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;solutions&quot;&gt;&lt;strong&gt;Solutions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient clipping:&lt;/strong&gt; Limit the gradient magnitude&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Batch normalization:&lt;/strong&gt; Normalize the input of each layer&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Residual connections:&lt;/strong&gt; Skip connections in deep networks&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preconditioning:&lt;/strong&gt; Transform the optimization space&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;choosing-the-learning-rate&quot;&gt;&lt;strong&gt;Choosing the learning rate:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;Start with \(t = 0.01\)&lt;/li&gt;
  &lt;li&gt;Increase/decrease by powers of 10&lt;/li&gt;
  &lt;li&gt;Watch the loss curve&lt;/li&gt;
  &lt;li&gt;Use learning rate scheduling&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;debugging&quot;&gt;&lt;strong&gt;Debugging:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Check the gradient implementation&lt;/li&gt;
  &lt;li&gt;Visualize loss curve&lt;/li&gt;
  &lt;li&gt;Monitor gradient norms&lt;/li&gt;
  &lt;li&gt;Use validation set&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;speeding-up&quot;&gt;&lt;strong&gt;Speeding up:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Use mini-batches instead of the full batch&lt;/li&gt;
  &lt;li&gt;Parallel/distributed training&lt;/li&gt;
  &lt;li&gt;GPU acceleration&lt;/li&gt;
  &lt;li&gt;Mixed precision training&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; Gradient descent is the foundation of modern machine learning. Understanding its variants and optimization techniques will help you train models more effectively!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the gradient descent algorithm and its variants, including step-size selection, convergence analysis, SGD and momentum.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Multiple-Choice Quiz: Gradient Descent&lt;/h2&gt;
        &lt;p&gt;Choose the best answer for each question. The quiz focuses on the basic concepts and practical applications of gradient descent.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Question 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Question 1: The basic update rule of gradient descent is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(x^{(k)} = x^{(k-1)} + t \nabla f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(x^{(k)} = x^{(k-1)} - t \nabla f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(x^{(k)} = x^{(k-1)} - t \nabla^2 f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(x^{(k)} = x^{(k-1)} + t f(x^{(k-1)})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$x^{(k)} = x^{(k-1)} - t \nabla f(x^{(k-1)})$$&lt;/strong&gt;&lt;br /&gt;
                Gradient descent moves in the direction opposite to the gradient to decrease the objective value.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The descent direction in gradient descent is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(\Delta x = \nabla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\Delta x = -\nabla f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(\Delta x = \nabla^2 f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(\Delta x = f(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\Delta x = -\nabla f(x)$$&lt;/strong&gt;&lt;br /&gt;
                The descent direction is the negative gradient, the direction of fastest decrease of the function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: If the step size $$t$$ is too large, gradient descent may:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) Converge faster&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Overshoot the minimum and diverge&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Stop immediately&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Find the exact solution&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Overshoot the minimum and diverge&lt;/strong&gt;&lt;br /&gt;
                A step size that is too large can make the algorithm oscillate or diverge away from the optimal solution.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: If the step size $$t$$ is too small, gradient descent will:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Converge very slowly&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Diverge&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Oscillate&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Stop immediately&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Converge very slowly&lt;/strong&gt;&lt;br /&gt;
                A step size that is too small makes the algorithm update very slowly, needing many iterations to converge.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: Backtracking line search works by:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Gradually increasing the step size&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Starting with a large step size and gradually decreasing it&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Using a fixed step size&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Computing second derivatives&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Starting with a large step size and gradually decreasing it&lt;/strong&gt;&lt;br /&gt;
                Backtracking starts with a large step and shrinks it until sufficient decrease is achieved (the Armijo condition).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: The Armijo condition in backtracking requires:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(f(x + t\Delta x) \leq f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(f(x + t\Delta x) \leq f(x) + \alpha t \nabla f(x)^T \Delta x\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(f(x + t\Delta x) = f(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(\nabla f(x + t\Delta x) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$f(x + t\Delta x) \leq f(x) + \alpha t \nabla f(x)^T \Delta x$$&lt;/strong&gt;&lt;br /&gt;
                The Armijo condition guarantees sufficient decrease with parameter $$\alpha \in (0, 0.5)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: Exact line search finds the step size by:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Using a fixed formula&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Minimizing \(f(x - t \nabla f(x))\) over \(t\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Choosing at random&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Using second derivatives&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Minimizing $$f(x - t \nabla f(x))$$ over $$t$$&lt;/strong&gt;&lt;br /&gt;
                Exact line search finds the optimal step size by solving a one-dimensional optimization problem.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The Lipschitz condition on the gradient means:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(\|\nabla f(x) - \nabla f(y)\| \leq L \|x - y\|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(\|f(x) - f(y)\| \leq L \|x - y\|\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(\nabla f(x) = L\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(f(x) \leq L\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\|\nabla f(x) - \nabla f(y)\| \leq L \|x - y\|$$&lt;/strong&gt;&lt;br /&gt;
                The Lipschitz condition ensures the gradient does not change too fast, which is important for convergence analysis.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: For a convex function with Lipschitz gradient, gradient descent converges at the rate:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(O(\log k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(O(e^{-k})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$O(1/k)$$&lt;/strong&gt;&lt;br /&gt;
                Gradient descent has a sublinear convergence rate $$O(1/k)$$ for convex functions with Lipschitz gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: Stochastic Gradient Descent (SGD) differs from Batch GD in that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) SGD uses all the data in each update&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) SGD uses only one data sample in each update&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) SGD does not use gradients&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) SGD always converges faster&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) SGD uses only one data sample in each update&lt;/strong&gt;&lt;br /&gt;
                SGD updates the parameters using the gradient of a single sample instead of the whole dataset.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: The main advantage of SGD over Batch GD is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Higher accuracy&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Lower computational cost per update&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) It always converges to the optimal solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) No need to tune the learning rate&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Lower computational cost per update&lt;/strong&gt;&lt;br /&gt;
                SGD costs O(1) per update compared with O(m) for Batch GD, which is very efficient for big data.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: Mini-batch Gradient Descent is a combination of:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) SGD and Newton&apos;s method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Batch GD and SGD&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Gradient descent and momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Line search and a fixed step&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Batch GD and SGD&lt;/strong&gt;&lt;br /&gt;
                Mini-batch uses a small subset of the data (typically 32-256 samples) to balance efficiency and stability.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The update rule of Gradient Descent with momentum is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) \(v^{(k)} = \beta v^{(k-1)} + \nabla f(x^{(k-1)})\), \(x^{(k)} = x^{(k-1)} + t v^{(k)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) \(v^{(k)} = \beta v^{(k-1)} + (1-\beta) \nabla f(x^{(k-1)})\), \(x^{(k)} = x^{(k-1)} - t v^{(k)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) \(x^{(k)} = x^{(k-1)} - t \beta \nabla f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) \(x^{(k)} = \beta x^{(k-1)} - t \nabla f(x^{(k-1)})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$v^{(k)} = \beta v^{(k-1)} + (1-\beta) \nabla f(x^{(k-1)})$$, $$x^{(k)} = x^{(k-1)} - t v^{(k)}$$&lt;/strong&gt;&lt;br /&gt;
                Momentum accumulates a velocity as an exponentially weighted moving average of the gradients. (The classical form $$v^{(k)} = \beta v^{(k-1)} + \nabla f(x^{(k-1)})$$, $$x^{(k)} = x^{(k-1)} - t v^{(k)}$$ is also correct and only rescales $$t$$; option A is wrong because it moves along $$+v$$, which increases the objective.)
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: The momentum coefficient $$\beta$$ is usually chosen in the range:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) [0.1, 0.3]&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) [0.5, 0.7]&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) [0.9, 0.99]&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) [1.0, 1.5]&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) [0.9, 0.99]&lt;/strong&gt;&lt;br /&gt;
                The momentum coefficient is usually chosen large (0.9 or 0.99) to keep a long &quot;memory&quot; of previous gradients.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: Momentum helps gradient descent to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Reduce oscillations and accelerate convergence&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Improve numerical accuracy&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Reduce memory usage&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Eliminate local minima completely&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Reduce oscillations and accelerate convergence&lt;/strong&gt;&lt;br /&gt;
                Momentum smooths the optimization process, reduces oscillations and accelerates progress along consistent directions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: Nesterov Accelerated Gradient (NAG) differs from ordinary momentum in that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) It uses a different momentum coefficient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) It computes the gradient at a &quot;look-ahead&quot; position&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) It does not use momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) It only applies to convex functions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) It computes the gradient at a &quot;look-ahead&quot; position&lt;/strong&gt;&lt;br /&gt;
                NAG computes the gradient at $$x^{(k-1)} - t\beta v^{(k-1)}$$ instead of $$x^{(k-1)}$$, allowing it to &quot;look ahead&quot; in the direction of motion.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: Gradient descent is NOT used directly in:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Training neural networks&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Linear regression&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Logistic regression&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Integer programming&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) Integer programming&lt;/strong&gt;&lt;br /&gt;
                Integer programming is a discrete optimization problem; gradient descent cannot be used because there is no gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: A common stopping criterion for gradient descent is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) \(\|\nabla f(x)\| &amp;lt; \epsilon\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) \(f(x) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) \(x = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) \(t = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\|\nabla f(x)\| &amp;lt; \epsilon$$&lt;/strong&gt;&lt;br /&gt;
                The algorithm stops when the gradient norm falls below a threshold $$\epsilon$$, indicating it is close to a minimum.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: For a strongly convex function, gradient descent converges at the rate:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) \(O(\rho^k)\) with \(\rho &amp;lt; 1\) (linear)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) \(O(\log k)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) $$O(\rho^k)$$ with $$\rho &amp;lt; 1$$ (linear)&lt;/strong&gt;&lt;br /&gt;
                Strong convexity lets gradient descent achieve a linear (geometric) convergence rate, which is much faster.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: Backpropagation in neural networks is essentially:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) A new optimization algorithm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) An efficient way to compute gradients for gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) A replacement for gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Only applicable to linear functions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) An efficient way to compute gradients for gradient descent&lt;/strong&gt;&lt;br /&gt;
                Backpropagation uses the chain rule to compute gradients efficiently in neural networks; gradient descent then uses them to update the weights.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: In gradient descent, what does a step size $$t = 0.01$$ mean?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Move 1% in the gradient direction&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Move in the direction $$-\nabla f$$ by a step equal to 0.01 times the gradient (length $$0.01\lVert\nabla f\rVert$$)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Divide the gradient by 100&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) The maximum number of iterations&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Move in the direction $$-\nabla f$$ by a step equal to 0.01 times the gradient (length $$0.01\lVert\nabla f\rVert$$)&lt;/strong&gt;&lt;br /&gt;
                The step size $$t$$ scales the move along $$-\nabla f$$: $$x^{(k+1)} = x^{(k)} - t\nabla f(x^{(k)})$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: The Armijo condition in line search checks:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Sufficient decrease of the objective&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) The slope of the gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Convexity of the function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Convergence of the algorithm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Sufficient decrease of the objective&lt;/strong&gt;&lt;br /&gt;
                The Armijo condition ensures $$f(x + t\Delta x) \leq f(x) + c_1 t \nabla f(x)^T \Delta x$$ with $$c_1 \in (0,1)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: SGD differs from GD in that it:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Uses the whole dataset&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Uses a random sample&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Has a fixed step size&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Always converges faster&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Uses a random sample&lt;/strong&gt;&lt;br /&gt;
                Stochastic Gradient Descent uses a random sample (or mini-batch) instead of the whole dataset.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: Momentum in gradient descent helps to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Accelerate convergence&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Escape local minima&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Reduce oscillations&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above reasons&lt;/strong&gt;&lt;br /&gt;
                Momentum helps accelerate convergence, reduce oscillations and can escape some small local minima.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: For $$f(x) = x^2$$, gradient descent from $$x_0 = 4$$ with $$t = 0.1$$ gives $$x_1 = ?$$&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$3.2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$4.8$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$3.6$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$2.4$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$3.2$$&lt;/strong&gt;&lt;br /&gt;
                $$\nabla f(4) = 2 \cdot 4 = 8$$. $$x_1 = 4 - 0.1 \cdot 8 = 4 - 0.8 = 3.2$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Previous&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Next&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Exercise Results&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #2196F3, #00BCD4);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #2196F3;
    background-color: #e3f2fd;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #2196F3;
    background-color: #bbdefb;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #e3f2fd;
    border-left: 4px solid #2196F3;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #1565C0;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #2196F3;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #1976D2;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #e3f2fd;
    border-radius: 8px;
    border: 2px solid #2196F3;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #1565C0;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answer for each question
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;a&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;b&apos;, q10: &apos;b&apos;,
    q11: &apos;b&apos;, q12: &apos;b&apos;, q13: &apos;b&apos;, q14: &apos;c&apos;, q15: &apos;a&apos;,
    q16: &apos;b&apos;, q17: &apos;d&apos;, q18: &apos;a&apos;, q19: &apos;c&apos;, q20: &apos;b&apos;
,
    q21: &apos;b&apos;, q22: &apos;a&apos;, q23: &apos;b&apos;, q24: &apos;d&apos;, q25: &apos;a&apos;};

/**
 * Update the progress bar and show the current question
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Question ${currentQuestion}/${totalQuestions}`;
}

/**
 * Show a question by its number
 */
function showQuestion(questionNum) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Update the state of the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
    
    // Re-render MathJax for the newly displayed question
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise([document.getElementById(`q${questionNum}`)]));
    }
}

/**
 * Go to the next question
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Go back to the previous question
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Store the user&apos;s answer
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Update the UI to show the selected answer
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Submit and show the results
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Compute the score and build the detailed report
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Show explanations for all questions
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Build the detailed report
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Question ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Correct&apos; : &apos;Incorrect&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Your answer: ${userAnswer || &apos;Not answered&apos;} | Correct answer: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Show the results
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Score: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Excellent! You have mastered gradient descent and its variants!&apos; :
              scorePercentage &gt;= 60 ? &apos;👍 Pretty good! Review a few concepts about SGD and momentum.&apos; :
              scorePercentage &gt;= 40 ? &apos;📚 You need more review of the gradient descent algorithm.&apos; : &apos;💪 Reread the theory of gradient descent from the beginning!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Restart the exercise
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide the results and show the navigation again
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Clear all selections
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>06-07 Regularization and Loss Functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_07_regularization_and_loss_functions/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_07_regularization_and_loss_functions</id>
   <content type="html">&lt;p&gt;A high-degree polynomial can pass through every single training point with zero error—and then fail catastrophically on the very next unseen test point. Regularization fixes this by adding a convex complexity penalty \(\lambda R(w)\) to the data-fit loss, turning an ill-posed memorization task into a well-conditioned convex optimization problem whose geometry (smooth L2 spheres vs. sharp L1 diamonds) directly shapes the learned model.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-of-losses-and-regularizers&quot;&gt;Key ideas: Geometry of Losses and Regularizers&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Empirical Risk + Regularizer&lt;/strong&gt;: Training solves \(\min_w \frac{1}{n}\sum_{i=1}^n \ell(y_i, f_w(x_i)) + \lambda R(w)\). The hyperparameter \(\lambda \ge 0\) traces the exact Pareto frontier between training fit (bias) and parameter complexity (variance).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ridge (L2) vs. Lasso (L1) Geometry&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Ridge (\(\frac{\lambda}{2}\|w\|_2^2\))&lt;/strong&gt;: Smooth and strictly convex; adds \(\lambda I\) to the Hessian (guaranteeing strong convexity and a unique closed-form solution \((X^T X + \lambda I)^{-1}X^T y\)); shrinks correlated weights smoothly toward zero without setting them exactly to zero.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Lasso (\(\lambda\|w\|_1\))&lt;/strong&gt;: Convex but &lt;em&gt;nonsmooth&lt;/em&gt; at coordinate axes; the sharp corners of the \(\ell_1\) diamond \(\{w : \|w\|_1 \le t\}\) intersect elliptical loss contours right on the axes, producing exact sparsity (automatic feature selection).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Elastic Net (Best of Both Worlds)&lt;/strong&gt;: Combining \(\lambda_1 \|w\|_1 + \frac{\lambda_2}{2}\|w\|_2^2\) yields both sparsity and strong convexity, stabilizing selection among highly correlated predictors.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choosing the Loss Function for Outliers and Tasks&lt;/strong&gt;: Squared loss penalizes large errors quadratically (sensitive to outliers); Huber loss blends quadratic smoothness near zero with linear robustness in the tails; hinge and cross-entropy losses drive large-margin and probabilistic classification.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-ridge-vs-lasso-on-a-1d-estimation-problem&quot;&gt;Worked example: Ridge vs. Lasso on a 1D Estimation Problem&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize \(\frac{1}{2}(w - 3)^2 + R(w)\) with regularization strength \(\lambda = 1\) under (a) Ridge \(R(w) = \frac{1}{2}w^2\) and (b) Lasso $$R(w) =&lt;/td&gt;
      &lt;td&gt;w&lt;/td&gt;
      &lt;td&gt;\(, and repeat when the data target is small (\)y = 0.6\(instead of\)3$$).&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Ridge solution (\(w_{\mathrm{Ridge}} = \frac{y}{1 + \lambda}\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;For \(y = 3, \lambda = 1\): derivative \((w - 3) + w = 0 \implies w_{\mathrm{Ridge}} = \frac{3}{2} = 1.5\).&lt;/li&gt;
      &lt;li&gt;For \(y = 0.6, \lambda = 1\): \(w_{\mathrm{Ridge}} = \frac{0.6}{2} = 0.3 \neq 0\) (shrunk by 50%, never zero!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Lasso solution (soft-thresholding $$w_{\mathrm{Lasso}} = \operatorname{sign}(y)\max(&lt;/td&gt;
          &lt;td&gt;y&lt;/td&gt;
          &lt;td&gt;- \lambda, 0)$$)**:&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(y = 3, \lambda = 1\): for \(w &amp;gt; 0\), derivative \((w - 3) + 1 = 0 \implies w_{\mathrm{Lasso}} = 3 - 1 = 2.0\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;For \(y = 0.6, \lambda = 1\): at \(w = 0\), the data slope is \(-0.6\) while the L1 penalty slope is \(\pm 1\). Because $$&lt;/td&gt;
              &lt;td&gt;-0.6&lt;/td&gt;
              &lt;td&gt;\le 1\(, moving in *either* direction increases the objective! Hence\)w_{\mathrm{Lasso}} = 0$$ &lt;strong&gt;exactly&lt;/strong&gt;!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric takeaway&lt;/strong&gt;: Ridge shrinks every weight proportionally; Lasso subtracts a constant threshold \(\lambda\) and snaps small noisy coefficients strictly to zero.&lt;/li&gt;
&lt;/ol&gt;

&lt;script src=&quot;../../../public/js/script.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;

&lt;h2 id=&quot;introduction-the-overfitting-problem-in-machine-learning&quot;&gt;Introduction: The Overfitting Problem in Machine Learning&lt;/h2&gt;

&lt;p&gt;In machine learning, one of the biggest challenges is &lt;strong&gt;overfitting&lt;/strong&gt; - when a model learns too much detail from training data, leading to poor performance on new data. &lt;strong&gt;Regularization&lt;/strong&gt; is a crucial technique to address this problem.&lt;/p&gt;

&lt;h3 id=&quot;why-do-we-need-regularization&quot;&gt;Why do we need Regularization?&lt;/h3&gt;

&lt;p&gt;Consider the basic linear regression problem:
\(\min_{\mathbf{w}} \frac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: When the number of features is large or data is scarce, the model can find solutions with training error = 0 but poor generalization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: Add a &lt;strong&gt;regularization term&lt;/strong&gt; to “penalize” large weights:
\(\min_{\mathbf{w}} \frac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2 + \lambda R(\mathbf{w})\)&lt;/p&gt;

&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\lambda &amp;gt; 0\) is the &lt;strong&gt;regularization parameter&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;\(R(\mathbf{w})\) is the &lt;strong&gt;regularization function&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ridge-regression-l2-regularization&quot;&gt;Ridge Regression (L2 Regularization)&lt;/h2&gt;

&lt;h3 id=&quot;mathematical-definition&quot;&gt;Mathematical Definition&lt;/h3&gt;

&lt;p&gt;Ridge regression uses the L2 norm as the regularization term:&lt;/p&gt;

\[\min_{\mathbf{w}} \frac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2 + \frac{\lambda}{2} \|\mathbf{w}\|_2^2\]

&lt;p&gt;&lt;strong&gt;Component explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Loss term&lt;/strong&gt;: \(\frac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2\) - measures deviation between predictions and actual values&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization term&lt;/strong&gt;: \(\frac{\lambda}{2} \|\mathbf{w}\|_2^2 = \frac{\lambda}{2} \sum_{j=1}^p w_j^2\) - penalizes large weights&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization strength&lt;/strong&gt;: \(\lambda\) controls the amount of regularization&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;analytical-solution&quot;&gt;Analytical Solution&lt;/h3&gt;

&lt;p&gt;Ridge regression has a closed-form solution:
\(\mathbf{w}^* = (\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})^{-1} \mathbf{X}^T \mathbf{y}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of this solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The matrix \((\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})\) is always invertible when \(\lambda &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;Solves multicollinearity problems&lt;/li&gt;
  &lt;li&gt;Computationally efficient&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;effects-of-ridge-regularization&quot;&gt;Effects of Ridge Regularization&lt;/h3&gt;

&lt;div id=&quot;ridge-effect-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9;&quot;&gt;
        &lt;h4&gt;Ridge Regularization Controls&lt;/h4&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;&quot;&gt;
            &lt;div&gt;
                &lt;label for=&quot;ridge-lambda&quot;&gt;Lambda (λ): &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;ridge-lambda&quot; min=&quot;0&quot; max=&quot;10&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;
                &lt;span id=&quot;ridge-lambda-value&quot;&gt;1.0&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;ridge-noise&quot;&gt;Noise Level: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;ridge-noise&quot; min=&quot;0&quot; max=&quot;0.5&quot; step=&quot;0.05&quot; value=&quot;0.1&quot; /&gt;
                &lt;span id=&quot;ridge-noise-value&quot;&gt;0.1&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;ridge-features&quot;&gt;Number of Features: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;ridge-features&quot; min=&quot;5&quot; max=&quot;20&quot; step=&quot;1&quot; value=&quot;10&quot; /&gt;
                &lt;span id=&quot;ridge-features-value&quot;&gt;10&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
            &lt;button id=&quot;ridge-regenerate&quot; style=&quot;background-color: #4CAF50; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Generate New Data&lt;/button&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Coefficients Path&lt;/h4&gt;
            &lt;svg id=&quot;ridge-coefficients&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;ridge-coeff-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;L2 Norm of coefficients: 0&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Training vs Validation Error&lt;/h4&gt;
            &lt;svg id=&quot;ridge-error&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;ridge-error-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;Optimal λ: 0&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;lasso-regression-l1-regularization&quot;&gt;Lasso Regression (L1 Regularization)&lt;/h2&gt;

&lt;h3 id=&quot;mathematical-definition-1&quot;&gt;Mathematical Definition&lt;/h3&gt;

&lt;p&gt;Lasso (Least Absolute Shrinkage and Selection Operator) uses the L1 norm:&lt;/p&gt;

\[\min_{\mathbf{w}} \frac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2 + \lambda \|\mathbf{w}\|_1\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;where $$|\mathbf{w}|&lt;em&gt;1 = \sum&lt;/em&gt;{j=1}^p&lt;/td&gt;
      &lt;td&gt;w_j&lt;/td&gt;
      &lt;td&gt;$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;key-properties-of-lasso&quot;&gt;Key Properties of Lasso&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Sparse Solutions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Lasso can set some coefficients to &lt;strong&gt;exactly zero&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Automatically performs &lt;strong&gt;feature selection&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Creates simple, interpretable models&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. No closed-form solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Requires optimization algorithms (coordinate descent, proximal gradient)&lt;/li&gt;
  &lt;li&gt;More computationally complex than Ridge&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ridge-vs-lasso-comparison&quot;&gt;Ridge vs Lasso Comparison&lt;/h3&gt;

&lt;div id=&quot;ridge-lasso-comparison&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f0f8ff;&quot;&gt;
        &lt;h4&gt;Ridge vs Lasso Regularization Comparison&lt;/h4&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 20px;&quot;&gt;
            &lt;div&gt;
                &lt;label for=&quot;comparison-lambda&quot;&gt;Lambda (λ): &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;comparison-lambda&quot; min=&quot;0&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;
                &lt;span id=&quot;comparison-lambda-value&quot;&gt;1.0&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;comparison-correlation&quot;&gt;Feature Correlation: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;comparison-correlation&quot; min=&quot;0&quot; max=&quot;0.9&quot; step=&quot;0.1&quot; value=&quot;0.5&quot; /&gt;
                &lt;span id=&quot;comparison-correlation-value&quot;&gt;0.5&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
            &lt;button id=&quot;comparison-update&quot; style=&quot;background-color: #2196F3; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Update Comparison&lt;/button&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Ridge Coefficients&lt;/h4&gt;
            &lt;svg id=&quot;ridge-comparison&quot; width=&quot;300&quot; height=&quot;250&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 5px; padding: 5px; background-color: #e8f5e8; border-radius: 4px;&quot;&gt;
                &lt;p style=&quot;margin: 0; font-size: 12px;&quot;&gt;Shrinkage: Uniform, never zero&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Lasso Coefficients&lt;/h4&gt;
            &lt;svg id=&quot;lasso-comparison&quot; width=&quot;300&quot; height=&quot;250&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 5px; padding: 5px; background-color: #fff3e0; border-radius: 4px;&quot;&gt;
                &lt;p style=&quot;margin: 0; font-size: 12px;&quot;&gt;Sparsity: Some exactly zero&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Regularization Geometry&lt;/h4&gt;
            &lt;svg id=&quot;regularization-geometry&quot; width=&quot;300&quot; height=&quot;250&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 5px; padding: 5px; background-color: #f3e5f5; border-radius: 4px;&quot;&gt;
                &lt;p style=&quot;margin: 0; font-size: 12px;&quot;&gt;L1: Diamond, L2: Circle&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;geometry-of-regularization&quot;&gt;Geometry of Regularization&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Intuitive understanding of why Lasso creates sparse solutions:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;L1 constraint&lt;/strong&gt;: \(\|\mathbf{w}\|_1 \leq t\) creates a &lt;strong&gt;diamond shape&lt;/strong&gt; in 2D&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;L2 constraint&lt;/strong&gt;: \(\|\mathbf{w}\|_2 \leq t\) creates a &lt;strong&gt;circular shape&lt;/strong&gt; in 2D&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Intersection with loss contours&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;L1: High probability of intersecting contours at corners (sparse solutions)&lt;/li&gt;
      &lt;li&gt;L2: Usually intersects at smooth points (non-sparse solutions)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;elastic-net-combining-ridge-and-lasso&quot;&gt;Elastic Net: Combining Ridge and Lasso&lt;/h2&gt;

&lt;p&gt;Elastic Net combines both L1 and L2 regularization:&lt;/p&gt;

\[\min_{\mathbf{w}} \frac{1}{2n} \|\mathbf{X}\mathbf{w} - \mathbf{y}\|_2^2 + \lambda \left[ \alpha \|\mathbf{w}\|_1 + \frac{1-\alpha}{2} \|\mathbf{w}\|_2^2 \right]\]

&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\alpha \in [0,1]\): mixing parameter&lt;/li&gt;
  &lt;li&gt;\(\alpha = 1\): Pure Lasso&lt;/li&gt;
  &lt;li&gt;\(\alpha = 0\): Pure Ridge&lt;/li&gt;
  &lt;li&gt;\(0 &amp;lt; \alpha &amp;lt; 1\): Combination&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Combines Lasso’s sparsity with Ridge’s stability&lt;/li&gt;
  &lt;li&gt;Handles grouped variables well&lt;/li&gt;
  &lt;li&gt;Works well when \(p &amp;gt; n\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;loss-functions-in-machine-learning&quot;&gt;Loss Functions in Machine Learning&lt;/h2&gt;

&lt;h3 id=&quot;1-regression-loss-functions&quot;&gt;1. Regression Loss Functions&lt;/h3&gt;

&lt;h4 id=&quot;mean-squared-error-mse&quot;&gt;Mean Squared Error (MSE)&lt;/h4&gt;
&lt;p&gt;\(L_{MSE}(\mathbf{w}) = \frac{1}{n} \sum_{i=1}^n (y_i - \mathbf{w}^T \mathbf{x}_i)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Smooth, differentiable everywhere&lt;/li&gt;
  &lt;li&gt;Sensitive to outliers&lt;/li&gt;
  &lt;li&gt;Convex optimization problem&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;mean-absolute-error-mae&quot;&gt;Mean Absolute Error (MAE)&lt;/h4&gt;
&lt;p&gt;\(L_{MAE}(\mathbf{w}) = \frac{1}{n} \sum_{i=1}^n |y_i - \mathbf{w}^T \mathbf{x}_i|\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Robust to outliers&lt;/li&gt;
  &lt;li&gt;Non-differentiable at zero&lt;/li&gt;
  &lt;li&gt;Convex but requires subgradient methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;huber-loss&quot;&gt;Huber Loss&lt;/h4&gt;
&lt;p&gt;\(L_{Huber}(\mathbf{w}) = \frac{1}{n} \sum_{i=1}^n \begin{cases}
\frac{1}{2}(y_i - \mathbf{w}^T \mathbf{x}_i)^2 &amp;amp; \text{if } |y_i - \mathbf{w}^T \mathbf{x}_i| \leq \delta \\
\delta |y_i - \mathbf{w}^T \mathbf{x}_i| - \frac{1}{2}\delta^2 &amp;amp; \text{otherwise}
\end{cases}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Combines MSE (small errors) and MAE (large errors)&lt;/li&gt;
  &lt;li&gt;Smooth and robust&lt;/li&gt;
  &lt;li&gt;Parameter \(\delta\) controls transition point&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-classification-loss-functions&quot;&gt;2. Classification Loss Functions&lt;/h3&gt;

&lt;h4 id=&quot;logistic-loss-cross-entropy&quot;&gt;Logistic Loss (Cross-entropy)&lt;/h4&gt;
&lt;p&gt;\(L_{logistic}(\mathbf{w}) = \frac{1}{n} \sum_{i=1}^n \log(1 + \exp(-y_i \mathbf{w}^T \mathbf{x}_i))\)&lt;/p&gt;

&lt;h4 id=&quot;hinge-loss-svm&quot;&gt;Hinge Loss (SVM)&lt;/h4&gt;
&lt;p&gt;\(L_{hinge}(\mathbf{w}) = \frac{1}{n} \sum_{i=1}^n \max(0, 1 - y_i \mathbf{w}^T \mathbf{x}_i)\)&lt;/p&gt;

&lt;h3 id=&quot;interactive-loss-functions-comparison&quot;&gt;Interactive Loss Functions Comparison&lt;/h3&gt;

&lt;div id=&quot;loss-functions-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9;&quot;&gt;
        &lt;h4&gt;Loss Functions Comparison&lt;/h4&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;&quot;&gt;
            &lt;div&gt;
                &lt;label for=&quot;loss-delta&quot;&gt;Huber Delta (δ): &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;loss-delta&quot; min=&quot;0.5&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;
                &lt;span id=&quot;loss-delta-value&quot;&gt;1.0&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;loss-range&quot;&gt;Error Range: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;loss-range&quot; min=&quot;2&quot; max=&quot;8&quot; step=&quot;0.5&quot; value=&quot;4&quot; /&gt;
                &lt;span id=&quot;loss-range-value&quot;&gt;4.0&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label&gt;
                    &lt;input type=&quot;checkbox&quot; id=&quot;show-derivatives&quot; /&gt; Show Derivatives
                &lt;/label&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Regression Loss Functions&lt;/h4&gt;
            &lt;svg id=&quot;regression-losses&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;div style=&quot;display: flex; gap: 15px; justify-content: center; font-size: 12px;&quot;&gt;
                    &lt;span style=&quot;color: #1f77b4;&quot;&gt;■ MSE&lt;/span&gt;
                    &lt;span style=&quot;color: #ff7f0e;&quot;&gt;■ MAE&lt;/span&gt;
                    &lt;span style=&quot;color: #2ca02c;&quot;&gt;■ Huber&lt;/span&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Classification Loss Functions&lt;/h4&gt;
            &lt;svg id=&quot;classification-losses&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;div style=&quot;display: flex; gap: 15px; justify-content: center; font-size: 12px;&quot;&gt;
                    &lt;span style=&quot;color: #d62728;&quot;&gt;■ Logistic&lt;/span&gt;
                    &lt;span style=&quot;color: #9467bd;&quot;&gt;■ Hinge&lt;/span&gt;
                    &lt;span style=&quot;color: #8c564b;&quot;&gt;■ 0-1 Loss&lt;/span&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;regularization-path-and-model-selection&quot;&gt;Regularization Path and Model Selection&lt;/h2&gt;

&lt;h3 id=&quot;cross-validation-for-regularization&quot;&gt;Cross-Validation for Regularization&lt;/h3&gt;

&lt;p&gt;Choosing optimal \(\lambda\) is typically done through cross-validation:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Split data&lt;/strong&gt;: Training, validation, test sets&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Grid search&lt;/strong&gt;: Try multiple \(\lambda\) values&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate&lt;/strong&gt;: Compute validation error for each \(\lambda\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Select&lt;/strong&gt;: Choose \(\lambda\) with lowest validation error&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;regularization-path-visualization&quot;&gt;Regularization Path Visualization&lt;/h3&gt;

&lt;div id=&quot;regularization-path-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f0f8ff;&quot;&gt;
        &lt;h4&gt;Regularization Path Analysis&lt;/h4&gt;
        &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;&quot;&gt;
            &lt;div&gt;
                &lt;label for=&quot;path-method&quot;&gt;Method: &lt;/label&gt;
                &lt;select id=&quot;path-method&quot;&gt;
                    &lt;option value=&quot;ridge&quot;&gt;Ridge&lt;/option&gt;
                    &lt;option value=&quot;lasso&quot;&gt;Lasso&lt;/option&gt;
                    &lt;option value=&quot;elastic&quot;&gt;Elastic Net&lt;/option&gt;
                &lt;/select&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;path-alpha&quot;&gt;Elastic Net α: &lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;path-alpha&quot; min=&quot;0&quot; max=&quot;1&quot; step=&quot;0.1&quot; value=&quot;0.5&quot; /&gt;
                &lt;span id=&quot;path-alpha-value&quot;&gt;0.5&lt;/span&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;button id=&quot;path-animate&quot; style=&quot;background-color: #FF9800; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Animate Path&lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Coefficient Path&lt;/h4&gt;
            &lt;svg id=&quot;coefficient-path&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;path-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;Current λ: 0, Active features: 0&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Cross-Validation Curve&lt;/h4&gt;
            &lt;svg id=&quot;cv-curve&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;cv-info&quot; style=&quot;margin: 0; font-size: 12px;&quot;&gt;Optimal λ: 0, CV Score: 0&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;practical-guidelines-and-best-practices&quot;&gt;Practical Guidelines and Best Practices&lt;/h2&gt;

&lt;h3 id=&quot;1-when-to-use-ridge-vs-lasso&quot;&gt;1. When to use Ridge vs Lasso?&lt;/h3&gt;

&lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;border: 1px solid #4CAF50; padding: 15px; border-radius: 5px; background-color: #f1f8e9;&quot;&gt;
        &lt;h4 style=&quot;color: #4CAF50;&quot;&gt;Use Ridge when:&lt;/h4&gt;
        &lt;ul&gt;
            &lt;li&gt;All features are meaningful&lt;/li&gt;
            &lt;li&gt;High multicollinearity&lt;/li&gt;
            &lt;li&gt;Need stability in predictions&lt;/li&gt;
            &lt;li&gt;Small dataset, many features&lt;/li&gt;
            &lt;li&gt;Don&apos;t need automatic feature selection&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
    &lt;div style=&quot;border: 1px solid #FF9800; padding: 15px; border-radius: 5px; background-color: #fff8e1;&quot;&gt;
        &lt;h4 style=&quot;color: #FF9800;&quot;&gt;Use Lasso when:&lt;/h4&gt;
        &lt;ul&gt;
            &lt;li&gt;Need automatic feature selection&lt;/li&gt;
            &lt;li&gt;Many irrelevant features&lt;/li&gt;
            &lt;li&gt;Want simple, interpretable models&lt;/li&gt;
            &lt;li&gt;Sparse solutions are preferred&lt;/li&gt;
            &lt;li&gt;High-dimensional data&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;2-hyperparameter-tuning-strategy&quot;&gt;2. Hyperparameter Tuning Strategy&lt;/h3&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Pseudo-code for regularization tuning
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;tune_regularization&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;lambda_values&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;logspace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Log-spaced values
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;best_lambda&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;best_score&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;inf&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lambda_val&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lambda_values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;model&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fit_regularized_model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lambda_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;val_score&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;evaluate_model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;val_score&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;best_score&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;best_score&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;val_score&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;best_lambda&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lambda_val&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;best_lambda&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;best_score&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-feature-scaling&quot;&gt;3. Feature Scaling&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;: Regularization is sensitive to feature scales!&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ridge/Lasso&lt;/strong&gt;: Require feature scaling (standardization)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reason&lt;/strong&gt;: Regularization penalty depends on coefficient magnitudes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solution&lt;/strong&gt;: Standardize features before applying regularization&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;conclusion-and-takeaways&quot;&gt;Conclusion and Takeaways&lt;/h2&gt;

&lt;h3 id=&quot;key-points&quot;&gt;Key Points:&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Regularization&lt;/strong&gt; is a powerful tool to prevent overfitting&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ridge (L2)&lt;/strong&gt; creates smooth shrinkage, good for stability&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lasso (L1)&lt;/strong&gt; creates sparse solutions, good for feature selection&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Elastic Net&lt;/strong&gt; combines advantages of both&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Loss function choice&lt;/strong&gt; greatly affects model behavior&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cross-validation&lt;/strong&gt; is key for hyperparameter tuning&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;practical-workflow&quot;&gt;Practical Workflow:&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Data preprocessing&lt;/strong&gt;: Scale features appropriately&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Method selection&lt;/strong&gt;: Choose based on problem characteristics&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hyperparameter tuning&lt;/strong&gt;: Use cross-validation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Model evaluation&lt;/strong&gt;: Test on held-out data&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interpretation&lt;/strong&gt;: Analyze coefficient patterns&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Remember&lt;/strong&gt;: Regularization is not a magic bullet - understanding your data and problem domain is still most important!&lt;/p&gt;

&lt;script&gt;
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    // Ridge Effect Demo
    initializeRidgeEffectDemo();
    
    // Ridge vs Lasso Comparison
    initializeRidgeLassoComparison();
    
    // Loss Functions Demo
    initializeLossFunctionsDemo();
    
    // Regularization Path Demo
    initializeRegularizationPathDemo();
    
    function initializeRidgeEffectDemo() {
        const lambdaSlider = document.getElementById(&apos;ridge-lambda&apos;);
        const noiseSlider = document.getElementById(&apos;ridge-noise&apos;);
        const featuresSlider = document.getElementById(&apos;ridge-features&apos;);
        const regenerateBtn = document.getElementById(&apos;ridge-regenerate&apos;);
        
        let currentData = generateRidgeData();
        
        function generateRidgeData() {
            const n = 50; // samples
            const p = parseInt(featuresSlider.value); // features
            const noise = parseFloat(noiseSlider.value);
            
            // Generate true coefficients (sparse)
            const trueCoeffs = Array(p).fill(0).map((_, i) =&gt; 
                i &lt; 3 ? (Math.random() - 0.5) * 4 : 0
            );
            
            // Generate X matrix
            const X = Array(n).fill().map(() =&gt; 
                Array(p).fill().map(() =&gt; Math.random() * 2 - 1)
            );
            
            // Generate y with noise
            const y = X.map(row =&gt; 
                row.reduce((sum, x, i) =&gt; sum + x * trueCoeffs[i], 0) + 
                (Math.random() - 0.5) * noise * 2
            );
            
            return { X, y, trueCoeffs, n, p };
        }
        
        function updateRidgeDemo() {
            const lambda = parseFloat(lambdaSlider.value);
            document.getElementById(&apos;ridge-lambda-value&apos;).textContent = lambda.toFixed(1);
            
            // Compute Ridge coefficients for different lambda values
            const lambdaRange = Array(50).fill().map((_, i) =&gt; i * 0.2);
            const coeffPaths = computeRidgeCoefficients(currentData, lambdaRange);
            
            // Update visualizations
            updateRidgeCoefficientsPlot(coeffPaths, lambdaRange, lambda);
            updateRidgeErrorPlot(currentData, lambdaRange);
        }
        
        function computeRidgeCoefficients(data, lambdaRange) {
            const { X, y, p } = data;
            const paths = Array(p).fill().map(() =&gt; []);
            
            lambdaRange.forEach(lambda =&gt; {
                const coeffs = solveRidge(X, y, lambda);
                coeffs.forEach((coeff, i) =&gt; paths[i].push(coeff));
            });
            
            return paths;
        }
        
        function solveRidge(X, y, lambda) {
            // Simplified Ridge solution: w = (X&apos;X + λI)^(-1) X&apos;y
            const p = X[0].length;
            const n = X.length;
            
            // Compute X&apos;X
            const XtX = Array(p).fill().map(() =&gt; Array(p).fill(0));
            for (let i = 0; i &lt; p; i++) {
                for (let j = 0; j &lt; p; j++) {
                    for (let k = 0; k &lt; n; k++) {
                        XtX[i][j] += X[k][i] * X[k][j];
                    }
                }
            }
            
            // Add λI
            for (let i = 0; i &lt; p; i++) {
                XtX[i][i] += lambda;
            }
            
            // Compute X&apos;y
            const Xty = Array(p).fill(0);
            for (let i = 0; i &lt; p; i++) {
                for (let k = 0; k &lt; n; k++) {
                    Xty[i] += X[k][i] * y[k];
                }
            }
            
            // Solve linear system (simplified - using pseudo-inverse)
            return solveLinearSystem(XtX, Xty);
        }
        
        function solveLinearSystem(A, b) {
            // Simplified solution using Gaussian elimination
            const n = A.length;
            const coeffs = Array(n).fill(0);
            
            // For demo purposes, use a simplified approach
            for (let i = 0; i &lt; n; i++) {
                coeffs[i] = b[i] / (A[i][i] + 1e-10);
            }
            
            return coeffs;
        }
        
        function updateRidgeCoefficientsPlot(coeffPaths, lambdaRange, currentLambda) {
            const svg = d3.select(&apos;#ridge-coefficients&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain(d3.extent(lambdaRange))
                .range([0, width]);
            
            const allCoeffs = coeffPaths.flat();
            const yScale = d3.scaleLinear()
                .domain(d3.extent(allCoeffs))
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Lambda (λ)&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Coefficient Value&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(lambdaRange[i]))
                .y(d =&gt; yScale(d));
            
            // Draw coefficient paths
            const colors = d3.schemeCategory10;
            coeffPaths.forEach((path, i) =&gt; {
                g.append(&apos;path&apos;)
                    .datum(path)
                    .attr(&apos;fill&apos;, &apos;none&apos;)
                    .attr(&apos;stroke&apos;, colors[i % colors.length])
                    .attr(&apos;stroke-width&apos;, 2)
                    .attr(&apos;d&apos;, line);
            });
            
            // Current lambda line
            g.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, xScale(currentLambda))
                .attr(&apos;x2&apos;, xScale(currentLambda))
                .attr(&apos;y1&apos;, 0)
                .attr(&apos;y2&apos;, height)
                .attr(&apos;stroke&apos;, &apos;red&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;stroke-dasharray&apos;, &apos;5,5&apos;);
            
            // Update info
            const currentIndex = Math.round(currentLambda / 0.2);
            const currentCoeffs = coeffPaths.map(path =&gt; path[currentIndex] || 0);
            const l2Norm = Math.sqrt(currentCoeffs.reduce((sum, c) =&gt; sum + c*c, 0));
            document.getElementById(&apos;ridge-coeff-info&apos;).textContent = 
                `L2 Norm of coefficients: ${l2Norm.toFixed(3)}`;
        }
        
        function updateRidgeErrorPlot(data, lambdaRange) {
            // Simplified error computation for demo
            const svg = d3.select(&apos;#ridge-error&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Generate synthetic error curves
            const trainErrors = lambdaRange.map(lambda =&gt; 
                0.1 + 0.5 * lambda + Math.random() * 0.1
            );
            const valErrors = lambdaRange.map(lambda =&gt; 
                0.3 + 0.2 * Math.abs(lambda - 2) + Math.random() * 0.1
            );
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain(d3.extent(lambdaRange))
                .range([0, width]);
            
            const yScale = d3.scaleLinear()
                .domain([0, Math.max(...trainErrors, ...valErrors)])
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Lambda (λ)&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Error&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(lambdaRange[i]))
                .y(d =&gt; yScale(d));
            
            // Draw error curves
            g.append(&apos;path&apos;)
                .datum(trainErrors)
                .attr(&apos;fill&apos;, &apos;none&apos;)
                .attr(&apos;stroke&apos;, &apos;blue&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;d&apos;, line);
            
            g.append(&apos;path&apos;)
                .datum(valErrors)
                .attr(&apos;fill&apos;, &apos;none&apos;)
                .attr(&apos;stroke&apos;, &apos;red&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;d&apos;, line);
            
            // Legend
            const legend = g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${width - 100}, 20)`);
            
            legend.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, 0).attr(&apos;x2&apos;, 20)
                .attr(&apos;y1&apos;, 0).attr(&apos;y2&apos;, 0)
                .attr(&apos;stroke&apos;, &apos;blue&apos;).attr(&apos;stroke-width&apos;, 2);
            legend.append(&apos;text&apos;)
                .attr(&apos;x&apos;, 25).attr(&apos;y&apos;, 5)
                .text(&apos;Training&apos;);
            
            legend.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, 0).attr(&apos;x2&apos;, 20)
                .attr(&apos;y1&apos;, 15).attr(&apos;y2&apos;, 15)
                .attr(&apos;stroke&apos;, &apos;red&apos;).attr(&apos;stroke-width&apos;, 2);
            legend.append(&apos;text&apos;)
                .attr(&apos;x&apos;, 25).attr(&apos;y&apos;, 20)
                .text(&apos;Validation&apos;);
            
            // Find optimal lambda
            const optimalIndex = valErrors.indexOf(Math.min(...valErrors));
            const optimalLambda = lambdaRange[optimalIndex];
            document.getElementById(&apos;ridge-error-info&apos;).textContent = 
                `Optimal λ: ${optimalLambda.toFixed(2)}`;
        }
        
        // Event listeners
        lambdaSlider.addEventListener(&apos;input&apos;, updateRidgeDemo);
        noiseSlider.addEventListener(&apos;input&apos;, function() {
            document.getElementById(&apos;ridge-noise-value&apos;).textContent = this.value;
        });
        featuresSlider.addEventListener(&apos;input&apos;, function() {
            document.getElementById(&apos;ridge-features-value&apos;).textContent = this.value;
        });
        
        regenerateBtn.addEventListener(&apos;click&apos;, function() {
            currentData = generateRidgeData();
            updateRidgeDemo();
        });
        
        // Initial update
        updateRidgeDemo();
    }
    
    function initializeRidgeLassoComparison() {
        const lambdaSlider = document.getElementById(&apos;comparison-lambda&apos;);
        const correlationSlider = document.getElementById(&apos;comparison-correlation&apos;);
        const updateBtn = document.getElementById(&apos;comparison-update&apos;);
        
        function updateComparison() {
            const lambda = parseFloat(lambdaSlider.value);
            const correlation = parseFloat(correlationSlider.value);
            
            document.getElementById(&apos;comparison-lambda-value&apos;).textContent = lambda.toFixed(1);
            document.getElementById(&apos;comparison-correlation-value&apos;).textContent = correlation.toFixed(1);
            
            // Generate synthetic data with controlled correlation
            const p = 8; // features
            const trueCoeffs = [2, -1.5, 1, 0.5, -0.8, 0, 0, 0];
            
            // Compute Ridge and Lasso coefficients
            const ridgeCoeffs = computeRidgeCoeffs(trueCoeffs, lambda, correlation);
            const lassoCoeffs = computeLassoCoeffs(trueCoeffs, lambda, correlation);
            
            // Update visualizations
            updateComparisonPlot(&apos;ridge-comparison&apos;, ridgeCoeffs, &apos;Ridge&apos;);
            updateComparisonPlot(&apos;lasso-comparison&apos;, lassoCoeffs, &apos;Lasso&apos;);
            updateGeometryPlot(lambda);
        }
        
        function computeRidgeCoeffs(trueCoeffs, lambda, correlation) {
            // Simplified Ridge shrinkage
            const shrinkageFactor = 1 / (1 + lambda);
            return trueCoeffs.map(coeff =&gt; coeff * shrinkageFactor);
        }
        
        function computeLassoCoeffs(trueCoeffs, lambda, correlation) {
            // Simplified Lasso soft thresholding
            return trueCoeffs.map(coeff =&gt; {
                const absCoeff = Math.abs(coeff);
                if (absCoeff &lt;= lambda) return 0;
                return Math.sign(coeff) * (absCoeff - lambda);
            });
        }
        
        function updateComparisonPlot(svgId, coeffs, title) {
            const svg = d3.select(`#${svgId}`);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 40};
            const width = 300 - margin.left - margin.right;
            const height = 250 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Scales
            const xScale = d3.scaleBand()
                .domain(coeffs.map((_, i) =&gt; `w${i+1}`))
                .range([0, width])
                .padding(0.1);
            
            const yScale = d3.scaleLinear()
                .domain(d3.extent(coeffs))
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Bars
            const color = title === &apos;Ridge&apos; ? &apos;#4CAF50&apos; : &apos;#FF9800&apos;;
            g.selectAll(&apos;.bar&apos;)
                .data(coeffs)
                .enter().append(&apos;rect&apos;)
                .attr(&apos;class&apos;, &apos;bar&apos;)
                .attr(&apos;x&apos;, (d, i) =&gt; xScale(`w${i+1}`))
                .attr(&apos;width&apos;, xScale.bandwidth())
                .attr(&apos;y&apos;, d =&gt; d &gt;= 0 ? yScale(d) : yScale(0))
                .attr(&apos;height&apos;, d =&gt; Math.abs(yScale(d) - yScale(0)))
                .attr(&apos;fill&apos;, color);
            
            // Zero line
            g.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, 0)
                .attr(&apos;x2&apos;, width)
                .attr(&apos;y1&apos;, yScale(0))
                .attr(&apos;y2&apos;, yScale(0))
                .attr(&apos;stroke&apos;, &apos;black&apos;)
                .attr(&apos;stroke-width&apos;, 1);
        }
        
        function updateGeometryPlot(lambda) {
            const svg = d3.select(&apos;#regularization-geometry&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 40};
            const width = 300 - margin.left - margin.right;
            const height = 250 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            const centerX = width / 2;
            const centerY = height / 2;
            const radius = Math.min(width, height) / 3;
            
            // L2 constraint (circle)
            g.append(&apos;circle&apos;)
                .attr(&apos;cx&apos;, centerX)
                .attr(&apos;cy&apos;, centerY)
                .attr(&apos;r&apos;, radius)
                .attr(&apos;fill&apos;, &apos;none&apos;)
                .attr(&apos;stroke&apos;, &apos;#4CAF50&apos;)
                .attr(&apos;stroke-width&apos;, 3)
                .attr(&apos;opacity&apos;, 0.7);
            
            // L1 constraint (diamond)
            const diamondPoints = [
                [centerX, centerY - radius],
                [centerX + radius, centerY],
                [centerX, centerY + radius],
                [centerX - radius, centerY]
            ];
            
            const line = d3.line()
                .x(d =&gt; d[0])
                .y(d =&gt; d[1]);
            
            g.append(&apos;path&apos;)
                .datum([...diamondPoints, diamondPoints[0]])
                .attr(&apos;d&apos;, line)
                .attr(&apos;fill&apos;, &apos;none&apos;)
                .attr(&apos;stroke&apos;, &apos;#FF9800&apos;)
                .attr(&apos;stroke-width&apos;, 3)
                .attr(&apos;opacity&apos;, 0.7);
            
            // Contour lines (ellipses)
            for (let i = 1; i &lt;= 3; i++) {
                g.append(&apos;ellipse&apos;)
                    .attr(&apos;cx&apos;, centerX + 20)
                    .attr(&apos;cy&apos;, centerY - 10)
                    .attr(&apos;rx&apos;, i * 15)
                    .attr(&apos;ry&apos;, i * 25)
                    .attr(&apos;fill&apos;, &apos;none&apos;)
                    .attr(&apos;stroke&apos;, &apos;#666&apos;)
                    .attr(&apos;stroke-width&apos;, 1)
                    .attr(&apos;stroke-dasharray&apos;, &apos;3,3&apos;)
                    .attr(&apos;opacity&apos;, 0.5);
            }
            
            // Labels
            g.append(&apos;text&apos;)
                .attr(&apos;x&apos;, centerX + radius + 10)
                .attr(&apos;y&apos;, centerY + 5)
                .text(&apos;L2&apos;)
                .attr(&apos;fill&apos;, &apos;#4CAF50&apos;)
                .attr(&apos;font-weight&apos;, &apos;bold&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;x&apos;, centerX + radius/Math.sqrt(2) + 5)
                .attr(&apos;y&apos;, centerY - radius/Math.sqrt(2) - 5)
                .text(&apos;L1&apos;)
                .attr(&apos;fill&apos;, &apos;#FF9800&apos;)
                .attr(&apos;font-weight&apos;, &apos;bold&apos;);
        }
        
        // Event listeners
        lambdaSlider.addEventListener(&apos;input&apos;, updateComparison);
        correlationSlider.addEventListener(&apos;input&apos;, updateComparison);
        updateBtn.addEventListener(&apos;click&apos;, updateComparison);
        
        // Initial update
        updateComparison();
    }
    
    function initializeLossFunctionsDemo() {
        const deltaSlider = document.getElementById(&apos;loss-delta&apos;);
        const rangeSlider = document.getElementById(&apos;loss-range&apos;);
        const derivativesCheckbox = document.getElementById(&apos;show-derivatives&apos;);
        
        function updateLossFunctions() {
            const delta = parseFloat(deltaSlider.value);
            const range = parseFloat(rangeSlider.value);
            const showDerivatives = derivativesCheckbox.checked;
            
            document.getElementById(&apos;loss-delta-value&apos;).textContent = delta.toFixed(1);
            document.getElementById(&apos;loss-range-value&apos;).textContent = range.toFixed(1);
            
            updateRegressionLosses(delta, range, showDerivatives);
            updateClassificationLosses(range, showDerivatives);
        }
        
        function updateRegressionLosses(delta, range, showDerivatives) {
            const svg = d3.select(&apos;#regression-losses&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Generate error values
            const errors = d3.range(-range, range, 0.1);
            
            // Loss functions
            const mseLoss = errors.map(e =&gt; 0.5 * e * e);
            const maeLoss = errors.map(e =&gt; Math.abs(e));
            const huberLoss = errors.map(e =&gt; 
                Math.abs(e) &lt;= delta ? 0.5 * e * e : delta * Math.abs(e) - 0.5 * delta * delta
            );
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain([-range, range])
                .range([0, width]);
            
            const maxLoss = Math.max(...mseLoss, ...maeLoss, ...huberLoss);
            const yScale = d3.scaleLinear()
                .domain([0, maxLoss])
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Prediction Error&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Loss&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(errors[i]))
                .y(d =&gt; yScale(d));
            
            // Draw loss functions
            const colors = [&apos;#1f77b4&apos;, &apos;#ff7f0e&apos;, &apos;#2ca02c&apos;];
            const losses = [mseLoss, maeLoss, huberLoss];
            const names = [&apos;MSE&apos;, &apos;MAE&apos;, &apos;Huber&apos;];
            
            losses.forEach((loss, i) =&gt; {
                g.append(&apos;path&apos;)
                    .datum(loss)
                    .attr(&apos;fill&apos;, &apos;none&apos;)
                    .attr(&apos;stroke&apos;, colors[i])
                    .attr(&apos;stroke-width&apos;, 3)
                    .attr(&apos;d&apos;, line);
            });
            
            // Legend
            const legend = g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${width - 80}, 20)`);
            
            names.forEach((name, i) =&gt; {
                legend.append(&apos;line&apos;)
                    .attr(&apos;x1&apos;, 0).attr(&apos;x2&apos;, 20)
                    .attr(&apos;y1&apos;, i * 20).attr(&apos;y2&apos;, i * 20)
                    .attr(&apos;stroke&apos;, colors[i]).attr(&apos;stroke-width&apos;, 3);
                legend.append(&apos;text&apos;)
                    .attr(&apos;x&apos;, 25).attr(&apos;y&apos;, i * 20 + 5)
                    .text(name);
            });
        }
        
        function updateClassificationLosses(range, showDerivatives) {
            const svg = d3.select(&apos;#classification-losses&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Generate margin values (y * f(x))
            const margins = d3.range(-range, range, 0.1);
            
            // Loss functions
            const logisticLoss = margins.map(m =&gt; Math.log(1 + Math.exp(-m)));
            const hingeLoss = margins.map(m =&gt; Math.max(0, 1 - m));
            const zeroOneLoss = margins.map(m =&gt; m &lt;= 0 ? 1 : 0);
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain([-range, range])
                .range([0, width]);
            
            const maxLoss = Math.max(...logisticLoss, ...hingeLoss, ...zeroOneLoss);
            const yScale = d3.scaleLinear()
                .domain([0, maxLoss])
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Margin (y × f(x))&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Loss&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(margins[i]))
                .y(d =&gt; yScale(d));
            
            // Draw loss functions
            const colors = [&apos;#d62728&apos;, &apos;#9467bd&apos;, &apos;#8c564b&apos;];
            const losses = [logisticLoss, hingeLoss, zeroOneLoss];
            const names = [&apos;Logistic&apos;, &apos;Hinge&apos;, &apos;0-1 Loss&apos;];
            
            losses.forEach((loss, i) =&gt; {
                g.append(&apos;path&apos;)
                    .datum(loss)
                    .attr(&apos;fill&apos;, &apos;none&apos;)
                    .attr(&apos;stroke&apos;, colors[i])
                    .attr(&apos;stroke-width&apos;, 3)
                    .attr(&apos;d&apos;, line);
            });
            
            // Legend
            const legend = g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${width - 80}, 20)`);
            
            names.forEach((name, i) =&gt; {
                legend.append(&apos;line&apos;)
                    .attr(&apos;x1&apos;, 0).attr(&apos;x2&apos;, 20)
                    .attr(&apos;y1&apos;, i * 20).attr(&apos;y2&apos;, i * 20)
                    .attr(&apos;stroke&apos;, colors[i]).attr(&apos;stroke-width&apos;, 3);
                legend.append(&apos;text&apos;)
                    .attr(&apos;x&apos;, 25).attr(&apos;y&apos;, i * 20 + 5)
                    .text(name);
            });
        }
        
        // Event listeners
        deltaSlider.addEventListener(&apos;input&apos;, updateLossFunctions);
        rangeSlider.addEventListener(&apos;input&apos;, updateLossFunctions);
        derivativesCheckbox.addEventListener(&apos;change&apos;, updateLossFunctions);
        
        // Initial update
        updateLossFunctions();
    }
    
    function initializeRegularizationPathDemo() {
        const methodSelect = document.getElementById(&apos;path-method&apos;);
        const alphaSlider = document.getElementById(&apos;path-alpha&apos;);
        const animateBtn = document.getElementById(&apos;path-animate&apos;);
        
        let isAnimating = false;
        let animationId = null;
        
        function updateRegularizationPath() {
            const method = methodSelect.value;
            const alpha = parseFloat(alphaSlider.value);
            
            document.getElementById(&apos;path-alpha-value&apos;).textContent = alpha.toFixed(1);
            
            // Generate regularization path
            const lambdaRange = d3.range(0, 5, 0.1);
            const coeffPaths = generateRegularizationPath(method, alpha, lambdaRange);
            
            updateCoefficientPathPlot(coeffPaths, lambdaRange, method);
            updateCVCurvePlot(lambdaRange, method);
        }
        
        function generateRegularizationPath(method, alpha, lambdaRange) {
            const p = 6; // features
            const trueCoeffs = [2, -1.5, 1, 0.5, -0.8, 0.3];
            
            const paths = Array(p).fill().map(() =&gt; []);
            
            lambdaRange.forEach(lambda =&gt; {
                let coeffs;
                if (method === &apos;ridge&apos;) {
                    coeffs = trueCoeffs.map(c =&gt; c / (1 + lambda));
                } else if (method === &apos;lasso&apos;) {
                    coeffs = trueCoeffs.map(c =&gt; {
                        const abs_c = Math.abs(c);
                        return abs_c &gt; lambda ? Math.sign(c) * (abs_c - lambda) : 0;
                    });
                } else { // elastic net
                    coeffs = trueCoeffs.map(c =&gt; {
                        const abs_c = Math.abs(c);
                        const l1_part = abs_c &gt; alpha * lambda ? Math.sign(c) * (abs_c - alpha * lambda) : 0;
                        return l1_part / (1 + (1 - alpha) * lambda);
                    });
                }
                
                coeffs.forEach((coeff, i) =&gt; paths[i].push(coeff));
            });
            
            return paths;
        }
        
        function updateCoefficientPathPlot(coeffPaths, lambdaRange, method) {
            const svg = d3.select(&apos;#coefficient-path&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain(d3.extent(lambdaRange))
                .range([0, width]);
            
            const allCoeffs = coeffPaths.flat();
            const yScale = d3.scaleLinear()
                .domain(d3.extent(allCoeffs))
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Lambda (λ)&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Coefficient Value&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(lambdaRange[i]))
                .y(d =&gt; yScale(d));
            
            // Draw coefficient paths
            const colors = d3.schemeCategory10;
            coeffPaths.forEach((path, i) =&gt; {
                g.append(&apos;path&apos;)
                    .datum(path)
                    .attr(&apos;fill&apos;, &apos;none&apos;)
                    .attr(&apos;stroke&apos;, colors[i % colors.length])
                    .attr(&apos;stroke-width&apos;, 2)
                    .attr(&apos;d&apos;, line);
                
                // Add feature label at the end
                const lastValue = path[path.length - 1];
                if (Math.abs(lastValue) &gt; 0.01) {
                    g.append(&apos;text&apos;)
                        .attr(&apos;x&apos;, width + 5)
                        .attr(&apos;y&apos;, yScale(lastValue) + 3)
                        .attr(&apos;font-size&apos;, &apos;10px&apos;)
                        .text(`f${i+1}`);
                }
            });
            
            // Update info
            const currentLambda = 1.0; // example
            const activeFeatures = coeffPaths.filter(path =&gt; Math.abs(path[Math.floor(currentLambda * 10)]) &gt; 0.01).length;
            document.getElementById(&apos;path-info&apos;).textContent = 
                `Current λ: ${currentLambda.toFixed(1)}, Active features: ${activeFeatures}`;
        }
        
        function updateCVCurvePlot(lambdaRange, method) {
            const svg = d3.select(&apos;#cv-curve&apos;);
            svg.selectAll(&apos;*&apos;).remove();
            
            const margin = {top: 20, right: 20, bottom: 40, left: 50};
            const width = 400 - margin.left - margin.right;
            const height = 300 - margin.top - margin.bottom;
            
            const g = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},${margin.top})`);
            
            // Generate synthetic CV scores
            const cvScores = lambdaRange.map(lambda =&gt; {
                const base = 0.2 + 0.1 * Math.abs(lambda - 1.5);
                return base + (Math.random() - 0.5) * 0.05;
            });
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain(d3.extent(lambdaRange))
                .range([0, width]);
            
            const yScale = d3.scaleLinear()
                .domain(d3.extent(cvScores))
                .nice()
                .range([height, 0]);
            
            // Axes
            g.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height})`)
                .call(d3.axisBottom(xScale));
            
            g.append(&apos;g&apos;)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, `translate(${width/2},${height + 35})`)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;Lambda (λ)&apos;);
            
            g.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;y&apos;, 0 - margin.left)
                .attr(&apos;x&apos;, 0 - height/2)
                .attr(&apos;dy&apos;, &apos;1em&apos;)
                .style(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;CV Score&apos;);
            
            // Line generator
            const line = d3.line()
                .x((d, i) =&gt; xScale(lambdaRange[i]))
                .y(d =&gt; yScale(d));
            
            // Draw CV curve
            g.append(&apos;path&apos;)
                .datum(cvScores)
                .attr(&apos;fill&apos;, &apos;none&apos;)
                .attr(&apos;stroke&apos;, &apos;#2196F3&apos;)
                .attr(&apos;stroke-width&apos;, 3)
                .attr(&apos;d&apos;, line);
            
            // Find and mark optimal lambda
            const minIndex = cvScores.indexOf(Math.min(...cvScores));
            const optimalLambda = lambdaRange[minIndex];
            
            g.append(&apos;circle&apos;)
                .attr(&apos;cx&apos;, xScale(optimalLambda))
                .attr(&apos;cy&apos;, yScale(cvScores[minIndex]))
                .attr(&apos;r&apos;, 5)
                .attr(&apos;fill&apos;, &apos;red&apos;);
            
            // Update info
            document.getElementById(&apos;cv-info&apos;).textContent = 
                `Optimal λ: ${optimalLambda.toFixed(2)}, CV Score: ${cvScores[minIndex].toFixed(3)}`;
        }
        
        function animatePath() {
            if (isAnimating) {
                // Stop animation
                isAnimating = false;
                if (animationId) clearInterval(animationId);
                animateBtn.textContent = &apos;Animate Path&apos;;
                return;
            }
            
            // Start animation
            isAnimating = true;
            animateBtn.textContent = &apos;Stop Animation&apos;;
            
            const lambdaRange = d3.range(0, 5, 0.1);
            let currentIndex = 0;
            
            animationId = setInterval(() =&gt; {
                if (currentIndex &gt;= lambdaRange.length) {
                    currentIndex = 0;
                }
                
                // Update visualization for current lambda
                const currentLambda = lambdaRange[currentIndex];
                // Add animation logic here
                
                currentIndex++;
            }, 100);
        }
        
        // Event listeners
        methodSelect.addEventListener(&apos;change&apos;, updateRegularizationPath);
        alphaSlider.addEventListener(&apos;input&apos;, updateRegularizationPath);
        animateBtn.addEventListener(&apos;click&apos;, animatePath);
        
        // Initial update
        updateRegularizationPath();
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>06-06 Gradient descent with momentum</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_06_gradent_descent_with_momentum/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_06_gradent_descent_with_momentum</id>
   <content type="html">&lt;p&gt;Picture rolling a heavy iron ball down a narrow canyon whose walls are steep and whose floor slopes gently toward the sea. A massless marble (vanilla gradient descent) bounces wildly from wall to wall and barely moves forward; the heavy ball cancels out the opposing left-right bounces and builds speed smoothly down the canyon floor. That physical inertia is &lt;strong&gt;Gradient Descent with Momentum&lt;/strong&gt; (Polyak’s Heavy Ball), turning \(O(\kappa)\) zig-zagging into \(O(\sqrt{\kappa})\) acceleration.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-physics-and-algebra-of-momentum&quot;&gt;Key ideas: Physics and Algebra of Momentum&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Velocity Recursion (Exponential Moving Average)&lt;/strong&gt;: Momentum maintains a velocity vector \(v_k\) that blends past velocity with the current gradient:
\(v_k = \beta v_{k-1} + \nabla f(x_{k-1}), \qquad x_k = x_{k-1} - t v_k,\)
where \(\beta \in [0, 1)\) is the momentum (damping) coefficient (typically \(\beta = 0.9\)). Unrolling gives \(v_k = \sum_{j=0}^{k-1} \beta^j \nabla f(x_{k-1-j})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Directional Amplification vs. Cancellation&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Along a &lt;em&gt;consistent&lt;/em&gt; flat direction where \(\nabla f \approx g\) stays constant, the velocity builds up to the geometric series sum \(\frac{1}{1 - \beta} g\) (a \(10\times\) boost when \(\beta = 0.9\)!).&lt;/li&gt;
      &lt;li&gt;Along an &lt;em&gt;oscillating&lt;/em&gt; steep direction where gradients alternate \(+g, -g, +g, \dots\), consecutive terms cancel out, damping the zig-zag!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal Spectral Rate on Quadratics&lt;/strong&gt;: On an \(m\)-strongly convex, \(L\)-smooth quadratic, choosing \(t^\star = \frac{4}{(\sqrt{L} + \sqrt{m})^2}\) and \(\beta^\star = \left(\frac{\sqrt{L} - \sqrt{m}}{\sqrt{L} + \sqrt{m}}\right)^2\) cuts the contraction factor from \(\frac{\kappa - 1}{\kappa + 1}\) down to \(\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Heavy Ball vs. Nesterov Look-Ahead&lt;/strong&gt;: Heavy Ball evaluates the gradient at the current position \(x_{k-1}\); Nesterov momentum peeks ahead to \(x_{k-1} - t\beta v_{k-1}\) before computing the gradient, acting as a corrective brake that prevents overshooting on general non-quadratic convex functions.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-watching-momentum-damp-zig-zag-and-boost-forward-progress&quot;&gt;Worked example: Watching Momentum Damp Zig-Zag and Boost Forward Progress&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + 16x_2^2)\) (so \(m = 1, L = 16, \kappa = 16\)) starting at \(x^{(0)} = (10, 1)\) with \(v^{(0)} = (0, 0)\), using step size \(t = 0.1\) and momentum \(\beta = 0.5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Gradient: \(g_0 = (10,\; 16)\).&lt;/li&gt;
      &lt;li&gt;Velocity: \(v^{(1)} = 0.5(0, 0) + (10, 16) = (10,\; 16)\).&lt;/li&gt;
      &lt;li&gt;Position: \(x^{(1)} = (10, 1) - 0.1(10, 16) = (9.0,\; -0.6)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Gradient at \(x^{(1)}\): \(g_1 = (9.0,\; -9.6)\). Notice \(g_1\) flipped sign along \(x_2\)!&lt;/li&gt;
      &lt;li&gt;Velocity: \(v^{(2)} = 0.5(10, 16) + (9.0, -9.6) = (5.0 + 9.0,\; 8.0 - 9.6) = (14.0,\; -1.6)\).&lt;/li&gt;
      &lt;li&gt;Look at what just happened: along the flat axis \(x_1\), velocity &lt;em&gt;grew&lt;/em&gt; from \(10\) to \(14\); along the steep axis \(x_2\), opposite signs canceled, slashing velocity from \(16\) down to \(-1.6\)!&lt;/li&gt;
      &lt;li&gt;Position: \(x^{(2)} = (9.0, -0.6) - 0.1(14.0, -1.6) = (7.6,\; -0.44)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with vanilla GD (\(\beta = 0, t = 0.1\))&lt;/strong&gt;: After 2 steps, vanilla GD sits at \((8.1,\; +0.36)\) — slower progress along \(x_1\) (\(8.1\) vs. \(7.6\)). With optimal Heavy-Ball parameters \(\beta^\star = (\frac{4-1}{4+1})^2 = 0.36\) and \(t^\star = \frac{4}{25} = 0.16\), the contraction rate is \(\frac{3}{5} = 0.60\) vs. vanilla GD’s \(\frac{15}{17} \approx 0.882\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;The animation on this page is the full-batch, constant-\(\beta\) picture. The Distill-style spectral story — characteristic polynomial, optimal \(\beta^\star\), look-ahead versus heavy ball, and why &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nesterov=True&lt;/code&gt; is not FISTA — is the modern-track lesson &lt;a href=&quot;/contents/en/chapter26/26_02_momentum_and_nesterov/&quot;&gt;26-02&lt;/a&gt;; the proximal / scheduled sibling is &lt;a href=&quot;/contents/en/chapter09/09_05_acceleration/&quot;&gt;09-05&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;the-problem-with-vanilla-gradient-descent&quot;&gt;The Problem with Vanilla Gradient Descent&lt;/h2&gt;

&lt;p&gt;Imagine you’re rolling a ball down a valley. Standard gradient descent is like a ball with no memory - at each step, it only considers the current slope and moves accordingly. This can lead to several problems:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Slow convergence in ravines&lt;/strong&gt;: When the function has steep gradients in some directions and shallow gradients in others&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Oscillations&lt;/strong&gt;: The algorithm may zigzag back and forth across the valley instead of making steady progress&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Getting stuck in poor local minima&lt;/strong&gt;: Without momentum, the algorithm may settle in suboptimal solutions&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Question&lt;/strong&gt;: What if our ball could “remember” its previous direction and maintain some velocity?&lt;/p&gt;

&lt;h2 id=&quot;momentum-adding-memory-to-gradient-descent&quot;&gt;Momentum: Adding Memory to Gradient Descent&lt;/h2&gt;

&lt;p&gt;Gradient descent with momentum is inspired by physics - specifically, the motion of a ball rolling down a hill with friction. The key insight is to accumulate a velocity vector that combines the current gradient with the previous momentum.&lt;/p&gt;

&lt;h3 id=&quot;the-momentum-algorithm&quot;&gt;The Momentum Algorithm&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Update rules:&lt;/strong&gt;
\(\begin{align}
v^{(k)} &amp;amp;= \beta v^{(k-1)} + (1-\beta) \nabla f(x^{(k-1)}) \\
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\)&lt;/p&gt;

&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(v^{(k)}\) is the momentum (velocity) at iteration \(k\)&lt;/li&gt;
  &lt;li&gt;\(\beta \in [0,1)\) is the momentum coefficient (typically 0.9 or 0.99)&lt;/li&gt;
  &lt;li&gt;\(t &amp;gt; 0\) is the learning rate&lt;/li&gt;
  &lt;li&gt;\(v^{(0)} = 0\) (initial velocity is zero)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;equivalent-formulation-without-the-factor-1-beta&quot;&gt;Equivalent Formulation (without the factor \(1-\beta\))&lt;/h3&gt;

&lt;p&gt;Some implementations (for example PyTorch’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SGD&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;momentum&lt;/code&gt;) use a slightly different form. It is still the plain heavy-ball method, not Nesterov; it only rescales the learning rate (by a factor \(1/(1-\beta)\) in the long run):
\(\begin{align}
v^{(k)} &amp;amp;= \beta v^{(k-1)} + \nabla f(x^{(k-1)}) \\
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key insight&lt;/strong&gt;: In both forms, \(v^{(k)}\) is an exponentially weighted combination of past gradients: a moving average in the first form, and a weighted sum in the second form.&lt;/p&gt;

&lt;h2 id=&quot;understanding-the-momentum-coefficient-beta&quot;&gt;Understanding the Momentum Coefficient \(\beta\)&lt;/h2&gt;

&lt;p&gt;The momentum coefficient \(\beta\) controls how much “memory” the algorithm has:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(\beta = 0\)&lt;/strong&gt;: No momentum, reduces to standard gradient descent&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\beta = 0.9\)&lt;/strong&gt;: Moderate momentum, commonly used in practice&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\beta = 0.99\)&lt;/strong&gt;: High momentum, used in some deep learning applications&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\beta \to 1\)&lt;/strong&gt;: Maximum momentum, but may cause instability&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;exponentially-weighted-moving-average&quot;&gt;Exponentially Weighted Moving Average&lt;/h3&gt;

&lt;p&gt;The momentum \(v^{(k)}\) can be expanded as:
\(v^{(k)} = (1-\beta) \sum_{i=0}^{k-1} \beta^i \nabla f(x^{(k-1-i)})\)&lt;/p&gt;

&lt;p&gt;This shows that momentum gives exponentially decreasing weights to older gradients.&lt;/p&gt;

&lt;h2 id=&quot;interactive-visualization-gradient-descent-vs-momentum&quot;&gt;Interactive Visualization: Gradient Descent vs Momentum&lt;/h2&gt;

&lt;div id=&quot;momentum-comparison&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;!-- Parameter Controls --&gt;
    &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9;&quot;&gt;
        &lt;div&gt;
            &lt;label for=&quot;momentum-lr&quot;&gt;Learning Rate: &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;momentum-lr&quot; min=&quot;0.01&quot; max=&quot;0.3&quot; step=&quot;0.01&quot; value=&quot;0.1&quot; /&gt;
            &lt;span id=&quot;momentum-lr-value&quot;&gt;0.1&lt;/span&gt;
        &lt;/div&gt;
        &lt;div&gt;
            &lt;label for=&quot;momentum-beta&quot;&gt;Momentum (β): &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;momentum-beta&quot; min=&quot;0&quot; max=&quot;0.99&quot; step=&quot;0.01&quot; value=&quot;0.9&quot; /&gt;
            &lt;span id=&quot;momentum-beta-value&quot;&gt;0.9&lt;/span&gt;
        &lt;/div&gt;
        &lt;div&gt;
            &lt;label for=&quot;momentum-speed&quot;&gt;Animation Speed: &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;momentum-speed&quot; min=&quot;1&quot; max=&quot;10&quot; step=&quot;1&quot; value=&quot;5&quot; /&gt;
            &lt;span id=&quot;momentum-speed-value&quot;&gt;5&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;!-- Control Buttons --&gt;
    &lt;div style=&quot;display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap;&quot;&gt;
        &lt;button id=&quot;start-vanilla-gd&quot; style=&quot;background-color: #4CAF50; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Start Vanilla GD&lt;/button&gt;
        &lt;button id=&quot;start-momentum-gd&quot; style=&quot;background-color: #FF9800; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Start Momentum GD&lt;/button&gt;
        &lt;button id=&quot;start-both&quot; style=&quot;background-color: #2196F3; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Compare Both&lt;/button&gt;
        &lt;button id=&quot;reset-momentum&quot; style=&quot;background-color: #f44336; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Reset&lt;/button&gt;
    &lt;/div&gt;
    
    &lt;!-- Visualization Canvas --&gt;
    &lt;div id=&quot;momentum-canvas&quot; style=&quot;border: 1px solid #ccc; border-radius: 5px; background-color: white; position: relative; overflow: hidden;&quot;&gt;
        &lt;svg width=&quot;800&quot; height=&quot;500&quot; id=&quot;momentum-svg&quot;&gt;&lt;/svg&gt;
    &lt;/div&gt;
    
    &lt;!-- Algorithm Status --&gt;
    &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 15px;&quot;&gt;
        &lt;div style=&quot;padding: 10px; border: 1px solid #4CAF50; border-radius: 5px; background-color: #f1f8e9;&quot;&gt;
            &lt;h4 style=&quot;margin: 0 0 5px 0; color: #4CAF50;&quot;&gt;Vanilla Gradient Descent&lt;/h4&gt;
            &lt;p id=&quot;vanilla-gd-info&quot; style=&quot;margin: 0; font-size: 14px;&quot;&gt;Ready to start&lt;/p&gt;
        &lt;/div&gt;
        &lt;div style=&quot;padding: 10px; border: 1px solid #FF9800; border-radius: 5px; background-color: #fff8e1;&quot;&gt;
            &lt;h4 style=&quot;margin: 0 0 5px 0; color: #FF9800;&quot;&gt;Momentum Gradient Descent&lt;/h4&gt;
            &lt;p id=&quot;momentum-gd-info&quot; style=&quot;margin: 0; font-size: 14px;&quot;&gt;Ready to start&lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    // Momentum visualization implementation
    const svg = d3.select(&quot;#momentum-svg&quot;);
    const width = 800, height = 500;
    const margin = {top: 20, right: 20, bottom: 40, left: 40};
    
    // Function to optimize: f(x,y) = 0.5*x^2 + 5*y^2 (elongated bowl)
    function f(x, y) {
        return 0.5 * x * x + 5 * y * y;
    }
    
    function gradient(x, y) {
        return [x, 10 * y];
    }
    
    // Scale setup
    const xScale = d3.scaleLinear()
        .domain([-6, 6])
        .range([margin.left, width - margin.right]);
    
    const yScale = d3.scaleLinear()
        .domain([-3, 3])
        .range([height - margin.bottom, margin.top]);
    
    // Create contour plot
    function createContours() {
        // Create a simple grid-based contour visualization
        const gridSize = 20;
        const contourLevels = [1, 4, 9, 16, 25, 36, 49];
        
        svg.selectAll(&quot;.contour&quot;).remove();
        
        // Draw contour ellipses for the function f(x,y) = 0.5*x^2 + 5*y^2
        contourLevels.forEach(level =&gt; {
            // For f(x,y) = 0.5*x^2 + 5*y^2 = level
            // This is an ellipse: x^2/(2*level) + y^2/(level/5) = 1
            const a = Math.sqrt(2 * level); // semi-major axis in x direction
            const b = Math.sqrt(level / 5); // semi-minor axis in y direction
            
            if (a &lt;= 6 &amp;&amp; b &lt;= 3) { // Only draw if within our domain
                svg.append(&quot;ellipse&quot;)
                    .attr(&quot;class&quot;, &quot;contour&quot;)
                    .attr(&quot;cx&quot;, xScale(0))
                    .attr(&quot;cy&quot;, yScale(0))
                    .attr(&quot;rx&quot;, xScale(a) - xScale(0))
                    .attr(&quot;ry&quot;, yScale(0) - yScale(b))
                    .attr(&quot;fill&quot;, &quot;none&quot;)
                    .attr(&quot;stroke&quot;, &quot;#ddd&quot;)
                    .attr(&quot;stroke-width&quot;, 1)
                    .attr(&quot;opacity&quot;, 0.6);
            }
        });
    }
    
    createContours();
    
    // Add global minimum marker
    svg.append(&quot;circle&quot;)
        .attr(&quot;cx&quot;, xScale(0))
        .attr(&quot;cy&quot;, yScale(0))
        .attr(&quot;r&quot;, 8)
        .attr(&quot;fill&quot;, &quot;red&quot;)
        .attr(&quot;stroke&quot;, &quot;white&quot;)
        .attr(&quot;stroke-width&quot;, 2)
        .attr(&quot;opacity&quot;, 0.8);
    
    svg.append(&quot;text&quot;)
        .attr(&quot;x&quot;, xScale(0))
        .attr(&quot;y&quot;, yScale(0) - 15)
        .attr(&quot;text-anchor&quot;, &quot;middle&quot;)
        .attr(&quot;font-size&quot;, &quot;12px&quot;)
        .attr(&quot;font-weight&quot;, &quot;bold&quot;)
        .attr(&quot;fill&quot;, &quot;red&quot;)
        .text(&quot;Global Minimum&quot;);
    
    // Add axes
    svg.append(&quot;g&quot;)
        .attr(&quot;transform&quot;, `translate(0,${height - margin.bottom})`)
        .call(d3.axisBottom(xScale));
    
    svg.append(&quot;g&quot;)
        .attr(&quot;transform&quot;, `translate(${margin.left},0)`)
        .call(d3.axisLeft(yScale));
    
    // Add axis labels
    svg.append(&quot;text&quot;)
        .attr(&quot;x&quot;, width / 2)
        .attr(&quot;y&quot;, height - 5)
        .attr(&quot;text-anchor&quot;, &quot;middle&quot;)
        .attr(&quot;font-size&quot;, &quot;14px&quot;)
        .text(&quot;x&quot;);
    
    svg.append(&quot;text&quot;)
        .attr(&quot;x&quot;, 15)
        .attr(&quot;y&quot;, height / 2)
        .attr(&quot;text-anchor&quot;, &quot;middle&quot;)
        .attr(&quot;font-size&quot;, &quot;14px&quot;)
        .attr(&quot;transform&quot;, `rotate(-90, 15, ${height / 2})`)
        .text(&quot;y&quot;);
    
    // Add title
    svg.append(&quot;text&quot;)
        .attr(&quot;x&quot;, width / 2)
        .attr(&quot;y&quot;, 15)
        .attr(&quot;text-anchor&quot;, &quot;middle&quot;)
        .attr(&quot;font-size&quot;, &quot;16px&quot;)
        .attr(&quot;font-weight&quot;, &quot;bold&quot;)
        .text(&quot;f(x,y) = 0.5x² + 5y² - Optimization Paths Comparison&quot;);
    
    // Variables for animation
    let vanillaPath = [], momentumPath = [];
    let vanillaRunning = false, momentumRunning = false;
    let vanillaInterval, momentumInterval;
    
    // Algorithm implementations
    function runVanillaGD() {
        const lr = parseFloat(document.getElementById(&apos;momentum-lr&apos;).value);
        let x = -4, y = 2; // Starting point
        let iteration = 0;
        const maxIterations = 500;
        vanillaPath = [{x: x, y: y}];
        vanillaRunning = true;
        
        vanillaInterval = setInterval(() =&gt; {
            const grad = gradient(x, y);
            x -= lr * grad[0];
            y -= lr * grad[1];
            vanillaPath.push({x: x, y: y});
            iteration++;
            
            updateVisualization();
            updateStatus();
            
            // Stop if converged or max iterations reached
            if ((Math.abs(grad[0]) &lt; 0.01 &amp;&amp; Math.abs(grad[1]) &lt; 0.01) || iteration &gt;= maxIterations) {
                clearInterval(vanillaInterval);
                vanillaRunning = false;
            }
        }, 1000 / parseFloat(document.getElementById(&apos;momentum-speed&apos;).value));
    }
    
    function runMomentumGD() {
        const lr = parseFloat(document.getElementById(&apos;momentum-lr&apos;).value);
        const beta = parseFloat(document.getElementById(&apos;momentum-beta&apos;).value);
        let x = -4, y = 2; // Starting point
        let vx = 0, vy = 0; // Initial velocity
        let iteration = 0;
        const maxIterations = 500;
        momentumPath = [{x: x, y: y}];
        momentumRunning = true;
        
        momentumInterval = setInterval(() =&gt; {
            const grad = gradient(x, y);
            vx = beta * vx + (1 - beta) * grad[0];
            vy = beta * vy + (1 - beta) * grad[1];
            x -= lr * vx;
            y -= lr * vy;
            momentumPath.push({x: x, y: y});
            iteration++;
            
            updateVisualization();
            updateStatus();
            
            // Stop if converged or max iterations reached
            if ((Math.abs(grad[0]) &lt; 0.01 &amp;&amp; Math.abs(grad[1]) &lt; 0.01) || iteration &gt;= maxIterations) {
                clearInterval(momentumInterval);
                momentumRunning = false;
            }
        }, 1000 / parseFloat(document.getElementById(&apos;momentum-speed&apos;).value));
    }
    
    function updateVisualization() {
        // Remove existing paths
        svg.selectAll(&quot;.vanilla-path&quot;).remove();
        svg.selectAll(&quot;.momentum-path&quot;).remove();
        svg.selectAll(&quot;.vanilla-point&quot;).remove();
        svg.selectAll(&quot;.momentum-point&quot;).remove();
        
        // Draw vanilla GD path
        if (vanillaPath.length &gt; 1) {
            const line = d3.line()
                .x(d =&gt; xScale(d.x))
                .y(d =&gt; yScale(d.y));
            
            svg.append(&quot;path&quot;)
                .datum(vanillaPath)
                .attr(&quot;class&quot;, &quot;vanilla-path&quot;)
                .attr(&quot;d&quot;, line)
                .attr(&quot;fill&quot;, &quot;none&quot;)
                .attr(&quot;stroke&quot;, &quot;#4CAF50&quot;)
                .attr(&quot;stroke-width&quot;, 2);
            
            // Current point
            const current = vanillaPath[vanillaPath.length - 1];
            svg.append(&quot;circle&quot;)
                .attr(&quot;class&quot;, &quot;vanilla-point&quot;)
                .attr(&quot;cx&quot;, xScale(current.x))
                .attr(&quot;cy&quot;, yScale(current.y))
                .attr(&quot;r&quot;, 5)
                .attr(&quot;fill&quot;, &quot;#4CAF50&quot;);
        }
        
        // Draw momentum GD path
        if (momentumPath.length &gt; 1) {
            const line = d3.line()
                .x(d =&gt; xScale(d.x))
                .y(d =&gt; yScale(d.y));
            
            svg.append(&quot;path&quot;)
                .datum(momentumPath)
                .attr(&quot;class&quot;, &quot;momentum-path&quot;)
                .attr(&quot;d&quot;, line)
                .attr(&quot;fill&quot;, &quot;none&quot;)
                .attr(&quot;stroke&quot;, &quot;#FF9800&quot;)
                .attr(&quot;stroke-width&quot;, 2);
            
            // Current point
            const current = momentumPath[momentumPath.length - 1];
            svg.append(&quot;circle&quot;)
                .attr(&quot;class&quot;, &quot;momentum-point&quot;)
                .attr(&quot;cx&quot;, xScale(current.x))
                .attr(&quot;cy&quot;, yScale(current.y))
                .attr(&quot;r&quot;, 5)
                .attr(&quot;fill&quot;, &quot;#FF9800&quot;);
        }
    }
    
    function updateStatus() {
        // Update vanilla GD status
        if (vanillaPath.length &gt; 0) {
            const current = vanillaPath[vanillaPath.length - 1];
            const fValue = f(current.x, current.y);
            document.getElementById(&apos;vanilla-gd-info&apos;).innerHTML = 
                `Iteration: ${vanillaPath.length - 1}&lt;br&gt;Position: (${current.x.toFixed(3)}, ${current.y.toFixed(3)})&lt;br&gt;f(x,y): ${fValue.toFixed(4)}`;
        }
        
        // Update momentum GD status
        if (momentumPath.length &gt; 0) {
            const current = momentumPath[momentumPath.length - 1];
            const fValue = f(current.x, current.y);
            document.getElementById(&apos;momentum-gd-info&apos;).innerHTML = 
                `Iteration: ${momentumPath.length - 1}&lt;br&gt;Position: (${current.x.toFixed(3)}, ${current.y.toFixed(3)})&lt;br&gt;f(x,y): ${fValue.toFixed(4)}`;
        }
    }
    
    // Event listeners
    document.getElementById(&apos;start-vanilla-gd&apos;).addEventListener(&apos;click&apos;, () =&gt; {
        if (!vanillaRunning) {
            vanillaRunning = true;
            runVanillaGD();
        }
    });
    
    document.getElementById(&apos;start-momentum-gd&apos;).addEventListener(&apos;click&apos;, () =&gt; {
        if (!momentumRunning) {
            momentumRunning = true;
            runMomentumGD();
        }
    });
    
    document.getElementById(&apos;start-both&apos;).addEventListener(&apos;click&apos;, () =&gt; {
        if (!vanillaRunning &amp;&amp; !momentumRunning) {
            vanillaRunning = true;
            momentumRunning = true;
            runVanillaGD();
            runMomentumGD();
        }
    });
    
    document.getElementById(&apos;reset-momentum&apos;).addEventListener(&apos;click&apos;, () =&gt; {
        clearInterval(vanillaInterval);
        clearInterval(momentumInterval);
        vanillaRunning = false;
        momentumRunning = false;
        vanillaPath = [];
        momentumPath = [];
        updateVisualization();
        document.getElementById(&apos;vanilla-gd-info&apos;).innerHTML = &apos;Ready to start&apos;;
        document.getElementById(&apos;momentum-gd-info&apos;).innerHTML = &apos;Ready to start&apos;;
    });
    
    // Update display values
    document.getElementById(&apos;momentum-lr&apos;).addEventListener(&apos;input&apos;, function() {
        document.getElementById(&apos;momentum-lr-value&apos;).textContent = this.value;
    });
    
    document.getElementById(&apos;momentum-beta&apos;).addEventListener(&apos;input&apos;, function() {
        document.getElementById(&apos;momentum-beta-value&apos;).textContent = this.value;
    });
    
    document.getElementById(&apos;momentum-speed&apos;).addEventListener(&apos;input&apos;, function() {
        document.getElementById(&apos;momentum-speed-value&apos;).textContent = this.value;
    });
});
&lt;/script&gt;

&lt;h2 id=&quot;advantages-of-momentum&quot;&gt;Advantages of Momentum&lt;/h2&gt;

&lt;h3 id=&quot;1-faster-convergence&quot;&gt;1. &lt;strong&gt;Faster Convergence&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Momentum helps the algorithm build up speed in consistent directions, leading to faster convergence especially in:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Functions with valleys or ravines&lt;/li&gt;
  &lt;li&gt;Ill-conditioned problems (high condition number)&lt;/li&gt;
  &lt;li&gt;Functions with many local minima&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-reduced-oscillations&quot;&gt;2. &lt;strong&gt;Reduced Oscillations&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;In directions where the gradient changes sign frequently, momentum helps smooth out the oscillations by averaging past gradients.&lt;/p&gt;

&lt;h3 id=&quot;3-escape-from-local-minima&quot;&gt;3. &lt;strong&gt;Escape from Local Minima&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The accumulated momentum can help the algorithm “roll through” small local minima and continue toward better solutions.&lt;/p&gt;

&lt;h2 id=&quot;variants-and-extensions&quot;&gt;Variants and Extensions&lt;/h2&gt;

&lt;h3 id=&quot;1-nesterov-accelerated-gradient-nag&quot;&gt;1. &lt;strong&gt;Nesterov Accelerated Gradient (NAG)&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Instead of computing the gradient at the current position, NAG computes it at the “look-ahead” position:&lt;/p&gt;

\[\begin{align}
v^{(k)} &amp;amp;= \beta v^{(k-1)} + \nabla f(x^{(k-1)} - t\beta v^{(k-1)}) \\
x^{(k)} &amp;amp;= x^{(k-1)} - t v^{(k)}
\end{align}\]

&lt;p&gt;&lt;strong&gt;Intuition&lt;/strong&gt;: “Look before you leap” - check the gradient at where momentum would take you.&lt;/p&gt;

&lt;h4 id=&quot;the-problem-with-regular-momentum&quot;&gt;The Problem with Regular Momentum&lt;/h4&gt;

&lt;p&gt;While momentum helps the ball overcome local minima, there’s a limitation we can observe: when approaching the target, momentum still takes considerable time before stopping. The reason is precisely because of the accumulated velocity.&lt;/p&gt;

&lt;h4 id=&quot;the-key-insight&quot;&gt;The Key Insight&lt;/h4&gt;

&lt;p&gt;The fundamental idea is to &lt;strong&gt;predict the future direction&lt;/strong&gt; - essentially looking ahead one step! Specifically, the momentum part of the update moves the iterate by \(-t\beta v^{(k-1)}\), so we can approximate the next position as \(x^{(k-1)} - t\beta v^{(k-1)}\) (we don’t include the gradient term here as we’ll use it in the final step).&lt;/p&gt;

&lt;p&gt;Instead of using the gradient at the current position, NAG takes a step forward and uses the gradient at the anticipated next position.&lt;/p&gt;

&lt;h4 id=&quot;visual-comparison&quot;&gt;Visual Comparison&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;With regular momentum&lt;/strong&gt;: The update is the sum of two vectors:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Momentum vector (from previous step)&lt;/li&gt;
  &lt;li&gt;Gradient at the current position&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;With Nesterov momentum&lt;/strong&gt;: The update is the sum of two vectors:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Momentum vector (from previous step)&lt;/li&gt;
  &lt;li&gt;Gradient at the &lt;strong&gt;look-ahead&lt;/strong&gt; position (where momentum would take us)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This “look-ahead” approach allows NAG to make more informed corrections and often leads to faster convergence.&lt;/p&gt;

&lt;h3 id=&quot;2-adaptive-moment-estimation-adam&quot;&gt;2. &lt;strong&gt;Adaptive Moment Estimation (Adam)&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Adam combines momentum with adaptive learning rates for each parameter:&lt;/p&gt;

\[\begin{align}
m^{(k)} &amp;amp;= \beta_1 m^{(k-1)} + (1-\beta_1) \nabla f(x^{(k-1)}) \\
v^{(k)} &amp;amp;= \beta_2 v^{(k-1)} + (1-\beta_2) (\nabla f(x^{(k-1)}))^2 \\
x^{(k)} &amp;amp;= x^{(k-1)} - t \frac{m^{(k)}}{\sqrt{v^{(k)}} + \epsilon}
\end{align}\]

&lt;h2 id=&quot;practical-implementation-tips&quot;&gt;Practical Implementation Tips&lt;/h2&gt;

&lt;h3 id=&quot;1-choosing-the-momentum-coefficient&quot;&gt;1. &lt;strong&gt;Choosing the Momentum Coefficient&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Start with \(\beta = 0.9\)&lt;/strong&gt;: A good default for most problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Increase to \(\beta = 0.99\)&lt;/strong&gt;: For very smooth optimization landscapes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Decrease to \(\beta = 0.5-0.7\)&lt;/strong&gt;: For noisy or non-smooth functions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-learning-rate-adjustment&quot;&gt;2. &lt;strong&gt;Learning Rate Adjustment&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;When using momentum, you may need to reduce the learning rate compared to vanilla gradient descent, as momentum amplifies the effective step size.&lt;/p&gt;

&lt;h3 id=&quot;3-warm-up-period&quot;&gt;3. &lt;strong&gt;Warm-up Period&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Consider starting with lower momentum and gradually increasing it, as momentum needs time to build up effective velocity.&lt;/p&gt;

&lt;h2 id=&quot;mathematical-analysis&quot;&gt;Mathematical Analysis&lt;/h2&gt;

&lt;h3 id=&quot;convergence-properties&quot;&gt;Convergence Properties&lt;/h3&gt;

&lt;p&gt;For strongly convex functions with Lipschitz gradients, momentum gradient descent achieves:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Linear convergence&lt;/strong&gt;: \(f(x^{(k)}) - f^* \leq C \rho^k\) for some \(\rho &amp;lt; 1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Improved condition number&lt;/strong&gt;: Effective condition number can be improved from \(\kappa\) to \(\sqrt{\kappa}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;heavy-ball-method-connection&quot;&gt;Heavy Ball Method Connection&lt;/h3&gt;

&lt;p&gt;Momentum gradient descent is closely related to the heavy ball method from classical mechanics:
\(mx&apos;&apos; + \gamma x&apos; + \nabla f(x) = 0\)&lt;/p&gt;

&lt;p&gt;This differential equation, when discretized, leads to the momentum update rules.&lt;/p&gt;

&lt;h3 id=&quot;momentum-and-nesterov-in-about-4-minutes&quot;&gt;Momentum and Nesterov in about 4 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/momentum-nesterov_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Heavy ball and Nesterov on the valley ½(w₁² + 100w₂²): step counts, a β sweep, and a case where Nesterov diverges because η is too large.&lt;/p&gt;

&lt;h2 id=&quot;comparison-summary&quot;&gt;Comparison Summary&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aspect&lt;/th&gt;
      &lt;th&gt;Vanilla GD&lt;/th&gt;
      &lt;th&gt;Momentum GD&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Memory&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;No&lt;/td&gt;
      &lt;td&gt;Yes (exponential decay)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Convergence&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Can be slow&lt;/td&gt;
      &lt;td&gt;Often faster&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Oscillations&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;More prone&lt;/td&gt;
      &lt;td&gt;Reduced&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Local minima&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;May get stuck&lt;/td&gt;
      &lt;td&gt;Better escape&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hyperparameters&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Learning rate&lt;/td&gt;
      &lt;td&gt;Learning rate + momentum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Computational cost&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Low&lt;/td&gt;
      &lt;td&gt;Slightly higher&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;key-takeaways&quot;&gt;Key Takeaways&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Momentum adds memory&lt;/strong&gt;: It remembers the direction of previous steps&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Faster convergence&lt;/strong&gt;: Especially effective for functions with valleys or ravines&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reduced oscillations&lt;/strong&gt;: Smooths out zigzag behavior&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Widely used&lt;/strong&gt;: Foundation for many modern optimization algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tunable&lt;/strong&gt;: The momentum coefficient \(\beta\) allows fine-tuning for different problems&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Bottom line&lt;/strong&gt;: Momentum is a simple yet powerful enhancement to gradient descent that has stood the test of time and remains relevant in modern machine learning applications.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-05 Stochastic gradient descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_05_stochastic_gradient_descent/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_05_stochastic_gradient_descent</id>
   <content type="html">&lt;p&gt;Suppose your training set has 100 million images. Full-batch gradient descent forces you to process all 100 million images just to take &lt;em&gt;one&lt;/em&gt; tiny parameter step—a computational catastrophe. &lt;strong&gt;Stochastic Gradient Descent (SGD)&lt;/strong&gt; makes a radical bargain: estimate the gradient from a single random sample (or small mini-batch), take a noisy step right away, and trade exact direction for a million-fold speedup per update.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-mathematics-of-stochastic-gradient-descent&quot;&gt;Key ideas: Mathematics of Stochastic Gradient Descent&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Finite-Sum Structure &amp;amp; Unbiased Gradient Oracle&lt;/strong&gt;: Machine-learning objectives have the form \(F(x) = \frac{1}{n}\sum_{i=1}^n f_i(x)\). Sampling \(i_k \sim \mathrm{Uniform}\{1, \dots, n\}\) gives a stochastic gradient \(g_k = \nabla f_{i_k}(x_k)\) that is &lt;em&gt;unbiased&lt;/em&gt;: \(\mathbb{E}[g_k \mid x_k] = \nabla F(x_k)\), at \(1/n\) the cost of a full gradient.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Variance Floor Under Constant Step Size&lt;/strong&gt;: Because individual sample gradients \(\nabla f_i(x^\star) \neq 0\) even at the global optimum \(x^\star\), SGD with a fixed step size \(t\) does not converge to \(x^\star\)—it converges rapidly to a &lt;em&gt;noise ball&lt;/em&gt; of radius \(O(t\sigma^2)\) around \(x^\star\), where \(\sigma^2 = \mathbb{E}\|\nabla f_i(x^\star)\|_2^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robbins–Monro Diminishing Step-Size Rule&lt;/strong&gt;: To shrink the noise ball to zero while still reaching any point in space, step sizes must satisfy \(\sum_{k=1}^\infty t_k = \infty\) and \(\sum_{k=1}^\infty t_k^2 &amp;lt; \infty\) (for example, \(t_k = c / k\) or \(t_k = c / \sqrt{k}\)), yielding \(O(1/\sqrt{k})\) expected error on convex functions and \(O(1/k)\) on strongly convex functions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mini-Batch Variance Reduction&lt;/strong&gt;: Averaging over a mini-batch of size \(B\) cuts gradient variance by \(1/B\) while utilizing GPU vector parallelism—balancing hardware throughput against per-epoch statistical efficiency.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-computing-unbiasedness-and-variance-of-a-stochastic-gradient&quot;&gt;Worked example: Computing Unbiasedness and Variance of a Stochastic Gradient&lt;/h3&gt;

&lt;p&gt;Minimize the finite-sum objective \(F(x) = \frac{1}{2}\Bigl[(x - 1)^2 + (x - 5)^2\Bigr]\), where \(f_1(x) = (x - 1)^2\) and \(f_2(x) = (x - 5)^2\). The exact minimizer is \(x^\star = 3\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check unbiasedness at \(x_0 = 0\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Individual gradients: \(f_1&apos;(0) = 2(0 - 1) = -2\), \(f_2&apos;(0) = 2(0 - 5) = -10\).&lt;/li&gt;
      &lt;li&gt;Expected stochastic gradient: \(\mathbb{E}[g_0] = \frac{1}{2}(-2) + \frac{1}{2}(-10) = -6\).&lt;/li&gt;
      &lt;li&gt;Full gradient: \(F&apos;(0) = \frac{1}{2}(-2 - 10) = -6\) — exact match!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take one SGD step with \(t = 0.2\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;If sample \(i = 1\) is picked: \(x_1 = 0 - 0.2(-2) = 0.4\).&lt;/li&gt;
      &lt;li&gt;If sample \(i = 2\) is picked: \(x_1 = 0 - 0.2(-10) = 2.0\).&lt;/li&gt;
      &lt;li&gt;Expected next iterate: \(\mathbb{E}[x_1] = \frac{0.4 + 2.0}{2} = 1.2 = 0 - 0.2(-6)\), matching one full-batch step on average.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Observe non-zero variance AT the optimum \(x^\star = 3\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(f_1&apos;(3) = 2(3 - 1) = +4\) and \(f_2&apos;(3) = 2(3 - 5) = -4\).&lt;/li&gt;
      &lt;li&gt;Even though \(F&apos;(3) = 0\), the gradient variance is \(\sigma^2 = \frac{1}{2}(4^2 + (-4)^2) = 16 &amp;gt; 0\)! A fixed step \(t = 0.2\) kicks \(x\) away from \(3\) to \(3 \pm 0.8\), proving why \(t_k \to 0\) is needed for exact convergence.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script src=&quot;../../../public/js/script.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;

&lt;h2 id=&quot;motivation-the-big-data-challenge&quot;&gt;Motivation: The Big Data Challenge&lt;/h2&gt;

&lt;p&gt;Imagine you’re training a machine learning model on millions of data points. Traditional gradient descent requires computing gradients for &lt;strong&gt;all&lt;/strong&gt; data points before making a single update. This becomes computationally expensive and memory-intensive for large datasets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question&lt;/strong&gt;: What if we could make progress by looking at just one data point at a time?&lt;/p&gt;

&lt;h2 id=&quot;the-mathematical-foundation&quot;&gt;The Mathematical Foundation&lt;/h2&gt;

&lt;p&gt;Consider the optimization problem of minimizing a sum of functions:&lt;/p&gt;

\[\begin{equation}
\min_x f(x) = \min_x \sum_{i=1}^m f_i(x)
\end{equation}\]

&lt;p&gt;&lt;strong&gt;Real-world interpretation&lt;/strong&gt;: In machine learning, \(f_i(x)\) often represents the loss on the \(i\)-th training example, where \(x\) are the model parameters.&lt;/p&gt;

&lt;h3 id=&quot;batch-gradient-descent-traditional-approach&quot;&gt;Batch Gradient Descent (Traditional Approach)&lt;/h3&gt;

&lt;p&gt;The gradient of the sum equals the sum of gradients:
\(\nabla f(x) = \nabla \sum_{i=1}^m f_i(x) = \sum_{i=1}^m \nabla f_i(x)\)&lt;/p&gt;

&lt;p&gt;The update rule becomes:
\(\begin{equation}
x^{(k)} = x^{(k-1)} - t_k \cdot \sum_{i=1}^{m} \nabla f_i (x^{(k-1)}), \,  k=1,2,3,\dots
\end{equation}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Computational cost&lt;/strong&gt;: \(O(m)\) gradient evaluations per iteration, where \(m\) is the number of functions (or data points).&lt;/p&gt;

&lt;h2 id=&quot;stochastic-gradient-descent-the-efficient-alternative&quot;&gt;Stochastic Gradient Descent: The Efficient Alternative&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Key Insight&lt;/strong&gt;: Instead of computing gradients for all \(m\) functions, SGD uses only &lt;strong&gt;one&lt;/strong&gt; function at each iteration.&lt;/p&gt;

\[\begin{equation}
x^{(k)} = x^{(k-1)} - t_k \cdot \nabla f_{i_k} (x^{(k-1)}), \quad i_k \in \{1,2,\dots,m\}
\end{equation}\]

&lt;p&gt;&lt;strong&gt;Computational cost&lt;/strong&gt;: \(O(1)\) gradient evaluation per iteration - a massive improvement!&lt;/p&gt;

&lt;h3 id=&quot;interactive-visualization-gd-vs-sgd-with-step-control&quot;&gt;Interactive Visualization: GD vs SGD with Step Control&lt;/h3&gt;

&lt;div id=&quot;gd-sgd-comparison&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;!-- Parameter Controls --&gt;
    &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9;&quot;&gt;
        &lt;div&gt;
            &lt;label for=&quot;learning-rate&quot;&gt;Learning Rate: &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;learning-rate&quot; min=&quot;0.01&quot; max=&quot;0.5&quot; step=&quot;0.01&quot; value=&quot;0.1&quot; /&gt;
            &lt;span id=&quot;lr-value&quot;&gt;0.1&lt;/span&gt;
        &lt;/div&gt;
        &lt;div&gt;
            &lt;label for=&quot;num-functions&quot;&gt;Number of Functions (m): &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;num-functions&quot; min=&quot;3&quot; max=&quot;10&quot; step=&quot;1&quot; value=&quot;5&quot; /&gt;
            &lt;span id=&quot;m-value&quot;&gt;5&lt;/span&gt;
        &lt;/div&gt;
        &lt;div&gt;
            &lt;label for=&quot;animation-speed&quot;&gt;Animation Speed: &lt;/label&gt;
            &lt;input type=&quot;range&quot; id=&quot;animation-speed&quot; min=&quot;1&quot; max=&quot;10&quot; step=&quot;1&quot; value=&quot;5&quot; /&gt;
            &lt;span id=&quot;speed-value&quot;&gt;5&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;!-- Execution Mode Selection --&gt;
    &lt;div style=&quot;margin-bottom: 15px; padding: 10px; border: 1px solid #ddd; border-radius: 5px; background-color: #f0f8ff;&quot;&gt;
        &lt;h4 style=&quot;margin: 0 0 10px 0;&quot;&gt;Execution Mode:&lt;/h4&gt;
        &lt;div style=&quot;display: flex; gap: 15px;&quot;&gt;
            &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;exec-mode&quot; value=&quot;auto&quot; checked=&quot;&quot; /&gt; Auto Run&lt;/label&gt;
            &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;exec-mode&quot; value=&quot;manual&quot; /&gt; Manual Step-by-Step&lt;/label&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;!-- Control Buttons --&gt;
    &lt;div style=&quot;display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap;&quot;&gt;
        &lt;button id=&quot;start-gd&quot; style=&quot;background-color: #4CAF50; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Start Gradient Descent&lt;/button&gt;
        &lt;button id=&quot;start-sgd&quot; style=&quot;background-color: #FF9800; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Start SGD&lt;/button&gt;
        &lt;button id=&quot;pause-resume&quot; style=&quot;background-color: #2196F3; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot; disabled=&quot;&quot;&gt;Pause&lt;/button&gt;
        &lt;button id=&quot;step-forward&quot; style=&quot;background-color: #9C27B0; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot; disabled=&quot;&quot;&gt;Step Forward&lt;/button&gt;
        &lt;button id=&quot;reset-demo&quot; style=&quot;background-color: #f44336; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Reset&lt;/button&gt;
    &lt;/div&gt;
    
    &lt;!-- Algorithm Status --&gt;
    &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 15px;&quot;&gt;
        &lt;div style=&quot;padding: 10px; border: 1px solid #4CAF50; border-radius: 5px; background-color: #f1f8e9;&quot;&gt;
            &lt;h4 style=&quot;margin: 0 0 5px 0; color: #4CAF50;&quot;&gt;Gradient Descent Status&lt;/h4&gt;
            &lt;p id=&quot;gd-detailed-info&quot; style=&quot;margin: 0; font-size: 14px;&quot;&gt;Ready to start&lt;/p&gt;
        &lt;/div&gt;
        &lt;div style=&quot;padding: 10px; border: 1px solid #FF9800; border-radius: 5px; background-color: #fff8e1;&quot;&gt;
            &lt;h4 style=&quot;margin: 0 0 5px 0; color: #FF9800;&quot;&gt;SGD Status&lt;/h4&gt;
            &lt;p id=&quot;sgd-detailed-info&quot; style=&quot;margin: 0; font-size: 14px;&quot;&gt;Ready to start&lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;!-- Visualization Plots --&gt;
    &lt;div style=&quot;display: flex; gap: 20px; justify-content: center;&quot;&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Gradient Descent (Batch)&lt;/h4&gt;
            &lt;svg id=&quot;gd-plot&quot; width=&quot;350&quot; height=&quot;350&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;gd-info&quot; style=&quot;margin: 0; font-weight: bold;&quot;&gt;Iterations: 0, Cost: 0&lt;/p&gt;
                &lt;p id=&quot;gd-gradient-info&quot; style=&quot;margin: 5px 0 0 0; font-size: 12px; color: #666;&quot;&gt;Gradient: [0, 0]&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;text-align: center;&quot;&gt;
            &lt;h4&gt;Stochastic Gradient Descent&lt;/h4&gt;
            &lt;svg id=&quot;sgd-plot&quot; width=&quot;350&quot; height=&quot;350&quot; style=&quot;border: 1px solid #ddd;&quot;&gt;&lt;/svg&gt;
            &lt;div style=&quot;margin-top: 10px; padding: 8px; background-color: #f5f5f5; border-radius: 4px;&quot;&gt;
                &lt;p id=&quot;sgd-info&quot; style=&quot;margin: 0; font-weight: bold;&quot;&gt;Iterations: 0, Cost: 0&lt;/p&gt;
                &lt;p id=&quot;sgd-gradient-info&quot; style=&quot;margin: 5px 0 0 0; font-size: 12px; color: #666;&quot;&gt;Selected Function: -, Gradient: [0, 0]&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;!-- Progress Visualization --&gt;
    &lt;div style=&quot;margin-top: 20px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #fafafa;&quot;&gt;
        &lt;h4&gt;Convergence Progress&lt;/h4&gt;
        &lt;div style=&quot;display: flex; gap: 20px;&quot;&gt;
            &lt;div style=&quot;flex: 1;&quot;&gt;
                &lt;p&gt;&lt;strong&gt;GD Progress:&lt;/strong&gt;&lt;/p&gt;
                &lt;div style=&quot;width: 100%; background-color: #e0e0e0; border-radius: 10px; height: 20px;&quot;&gt;
                    &lt;div id=&quot;gd-progress&quot; style=&quot;width: 0%; background-color: #4CAF50; height: 100%; border-radius: 10px; transition: width 0.3s;&quot;&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div style=&quot;flex: 1;&quot;&gt;
                &lt;p&gt;&lt;strong&gt;SGD Progress:&lt;/strong&gt;&lt;/p&gt;
                &lt;div style=&quot;width: 100%; background-color: #e0e0e0; border-radius: 10px; height: 20px;&quot;&gt;
                    &lt;div id=&quot;sgd-progress&quot; style=&quot;width: 0%; background-color: #FF9800; height: 100%; border-radius: 10px; transition: width 0.3s;&quot;&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;selection-strategies-for-sgd&quot;&gt;Selection Strategies for SGD&lt;/h3&gt;

&lt;p&gt;The function index \(i_k\) can be selected using different strategies:&lt;/p&gt;

&lt;h4 id=&quot;1-cyclic-rule&quot;&gt;1. Cyclic Rule&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Pattern&lt;/strong&gt;: \(i_k = 1,2,\dots,m, 1,2,\dots,m, \ldots\)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Advantages&lt;/strong&gt;: Deterministic, ensures all functions are visited&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;: May get stuck in periodic patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-randomized-rule&quot;&gt;2. Randomized Rule&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Pattern&lt;/strong&gt;: \(i_k\) chosen uniformly at random from \(\{1,2,\dots,m\}\)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Advantages&lt;/strong&gt;: Avoids periodic patterns, better theoretical guarantees&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;: Some functions may be visited more frequently than others&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In practice&lt;/strong&gt;: Randomized selection is preferred due to better convergence properties and ability to escape local patterns.&lt;/p&gt;

&lt;h2 id=&quot;convergence-analysis-theory-vs-practice&quot;&gt;Convergence Analysis: Theory vs Practice&lt;/h2&gt;

&lt;h3 id=&quot;mathematical-comparison&quot;&gt;Mathematical Comparison&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Batch GD (one epoch)&lt;/strong&gt;: 
\(x^{(k+1)} = x^{(k)} - t_k \cdot \sum_{i=1}^{m} \nabla f_i (x^{(k)})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SGD (one epoch with cyclic rule)&lt;/strong&gt;:
\(x^{(k+m)} = x^{(k)} - t_k \cdot \sum_{i=1}^{m} \nabla f_i (x^{(k+i-1)})\)&lt;/p&gt;

&lt;h3 id=&quot;understanding-the-sgd-cyclic-rule-formula&quot;&gt;Understanding the SGD Cyclic Rule Formula&lt;/h3&gt;

&lt;p&gt;Let’s break down this formula step by step to understand what happens during one complete epoch of SGD with cyclic rule:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is an epoch?&lt;/strong&gt; One epoch means we’ve processed all \(m\) functions exactly once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The cyclic rule process:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Start at position \(x^{(k)}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Use function \(f_1\), compute \(\nabla f_1(x^{(k)})\), update to \(x^{(k+1)}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Use function \(f_2\), compute \(\nabla f_2(x^{(k+1)})\), update to \(x^{(k+2)}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Use function \(f_3\), compute \(\nabla f_3(x^{(k+2)})\), update to \(x^{(k+3)}\)&lt;/li&gt;
  &lt;li&gt;…&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step m&lt;/strong&gt;: Use function \(f_m\), compute \(\nabla f_m(x^{(k+m-1)})\), update to \(x^{(k+m)}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Individual SGD updates:&lt;/strong&gt;
\(\begin{align}
x^{(k+1)} &amp;amp;= x^{(k)} - t_k \nabla f_1(x^{(k)}) \\
x^{(k+2)} &amp;amp;= x^{(k+1)} - t_k \nabla f_2(x^{(k+1)}) \\
x^{(k+3)} &amp;amp;= x^{(k+2)} - t_k \nabla f_3(x^{(k+2)}) \\
&amp;amp;\vdots \\
x^{(k+m)} &amp;amp;= x^{(k+m-1)} - t_k \nabla f_m(x^{(k+m-1)})
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Telescoping the updates:&lt;/strong&gt;
If we substitute recursively and collect all terms, we get:
\(x^{(k+m)} = x^{(k)} - t_k \left[ \nabla f_1(x^{(k)}) + \nabla f_2(x^{(k+1)}) + \cdots + \nabla f_m(x^{(k+m-1)}) \right]\)&lt;/p&gt;

&lt;p&gt;This can be written compactly as:
\(x^{(k+m)} = x^{(k)} - t_k \cdot \sum_{i=1}^{m} \nabla f_i (x^{(k+i-1)})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key insight:&lt;/strong&gt; Each gradient \(\nabla f_i\) is evaluated at a &lt;strong&gt;different&lt;/strong&gt; position \(x^{(k+i-1)}\), not at the same starting position \(x^{(k)}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key difference in update directions&lt;/strong&gt;:
\(\sum_{i=1}^{m}[ \nabla f_i (x^{(k+i-1)}) - \nabla f_i (x^{(k)})]\)&lt;/p&gt;

&lt;p&gt;This difference represents how much the SGD path deviates from what batch GD would do. If the functions don’t change much locally (Lipschitz continuous gradients), this difference is small and SGD behaves similarly to batch GD.&lt;/p&gt;

&lt;h3 id=&quot;concrete-example-with-m--3-functions&quot;&gt;Concrete Example with m = 3 Functions&lt;/h3&gt;

&lt;p&gt;Let’s illustrate with \(m = 3\) functions to make this crystal clear:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Starting position:&lt;/strong&gt; \(x^{(k)} = [1, 2]\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Concrete functions (optional, to check the numbers):&lt;/strong&gt; fit a line \(y \approx w s + c\) through the three points \((s_i, y_i) = (0, 1), (1, 3), (2, 2)\). With \(x = [w, c]\), take
\(f_i(x) = \tfrac{1}{2}(w s_i + c - y_i)^2, \qquad \nabla f_i(x) = (w s_i + c - y_i)\,[s_i, 1].\)
At \(x^{(k)} = [1, 2]\): \(\nabla f_1 = [0, 1]\), \(\nabla f_2 = [0, 0]\), \(\nabla f_3 = [4, 2]\), and \(f(x^{(k)}) = 2.5\). The minimizer is \(x^\star = [0.5, 1.5]\) with \(f(x^\star) = 0.75\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SGD Cyclic Rule Process:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Use \(f_1\)&lt;/strong&gt;: Compute \(\nabla f_1(x^{(k)}) = \nabla f_1([1,2])\), update:
\(x^{(k+1)} = x^{(k)} - t_k \nabla f_1(x^{(k)}) = [1,2] - t_k \nabla f_1([1,2])\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Use \(f_2\)&lt;/strong&gt;: Compute \(\nabla f_2(x^{(k+1)})\) at the &lt;strong&gt;new&lt;/strong&gt; position, update:
\(x^{(k+2)} = x^{(k+1)} - t_k \nabla f_2(x^{(k+1)})\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Use \(f_3\)&lt;/strong&gt;: Compute \(\nabla f_3(x^{(k+2)})\) at the &lt;strong&gt;newest&lt;/strong&gt; position, update:
\(x^{(k+3)} = x^{(k+2)} - t_k \nabla f_3(x^{(k+2)})\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Final SGD result after one epoch:&lt;/strong&gt;
\(x^{(k+3)} = x^{(k)} - t_k[\nabla f_1(x^{(k)}) + \nabla f_2(x^{(k+1)}) + \nabla f_3(x^{(k+2)})]\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compare with Batch GD:&lt;/strong&gt;
\(x^{(k+1)} = x^{(k)} - t_k[\nabla f_1(x^{(k)}) + \nabla f_2(x^{(k)}) + \nabla f_3(x^{(k)})]\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With the concrete functions and \(t_k = 0.15\):&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Step&lt;/th&gt;
      &lt;th&gt;Gradient used&lt;/th&gt;
      &lt;th&gt;New point&lt;/th&gt;
      &lt;th&gt;\(f\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Batch GD&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;\([4, 3]\) (sum at \([1, 2]\))&lt;/td&gt;
      &lt;td&gt;\([0.4, 1.55]\)&lt;/td&gt;
      &lt;td&gt;0.76375&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SGD&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;\(\nabla f_1([1, 2]) = [0, 1]\)&lt;/td&gt;
      &lt;td&gt;\([1, 1.85]\)&lt;/td&gt;
      &lt;td&gt;2.08375&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SGD&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;\(\nabla f_2([1, 1.85]) = [-0.15, -0.15]\)&lt;/td&gt;
      &lt;td&gt;\([1.0225, 1.8725]\)&lt;/td&gt;
      &lt;td&gt;2.2245&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SGD&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;\(\nabla f_3([1.0225, 1.8725]) = [3.835, 1.9175]\)&lt;/td&gt;
      &lt;td&gt;\([0.44725, 1.584875]\)&lt;/td&gt;
      &lt;td&gt;0.7543&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The SGD gradients add up to \([3.685, 2.7675]\) instead of \([4, 3]\). The difference \([-0.315, -0.2325]\) is exactly the deviation term above. Notice that step 2 &lt;em&gt;increases&lt;/em&gt; \(f\): a single \(f_i\) does not always point downhill for the full sum.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The crucial difference:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Batch GD&lt;/strong&gt;: All gradients evaluated at the &lt;strong&gt;same&lt;/strong&gt; starting point \(x^{(k)}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SGD&lt;/strong&gt;: Each gradient evaluated at a &lt;strong&gt;different&lt;/strong&gt; point along the optimization path&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why SGD can make faster initial progress (it’s already “exploring” the landscape) but can be noisier near the optimum.&lt;/p&gt;

&lt;h3 id=&quot;convergence-properties&quot;&gt;Convergence Properties&lt;/h3&gt;

&lt;div id=&quot;convergence-analysis&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr; gap: 20px;&quot;&gt;
        &lt;div style=&quot;border: 1px solid #ddd; padding: 15px; border-radius: 5px;&quot;&gt;
            &lt;h4&gt;Batch Gradient Descent&lt;/h4&gt;
            &lt;ul&gt;
                &lt;li&gt;&lt;strong&gt;Direction&lt;/strong&gt;: Always in steepest descent direction&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Convergence&lt;/strong&gt;: Smooth, monotonic decrease&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Speed&lt;/strong&gt;: Slower per epoch, but stable&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Memory&lt;/strong&gt;: Requires full dataset in memory&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/div&gt;
        &lt;div style=&quot;border: 1px solid #ddd; padding: 15px; border-radius: 5px;&quot;&gt;
            &lt;h4&gt;Stochastic Gradient Descent&lt;/h4&gt;
            &lt;ul&gt;
                &lt;li&gt;&lt;strong&gt;Direction&lt;/strong&gt;: Noisy, approximate descent direction&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Convergence&lt;/strong&gt;: Oscillatory, but faster initial progress&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Speed&lt;/strong&gt;: Faster per epoch, especially for large datasets&lt;/li&gt;
                &lt;li&gt;&lt;strong&gt;Memory&lt;/strong&gt;: Processes one sample at a time&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;theoretical-guarantees&quot;&gt;Theoretical Guarantees&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Lipschitz Continuity Condition&lt;/strong&gt;: If \(\nabla f_i(x)\) is Lipschitz continuous with constant \(L\):
\(\|\nabla f_i(x) - \nabla f_i(y)\| \leq L \|x - y\|\)&lt;/p&gt;

&lt;p&gt;Then SGD converges to the same optimal solution as batch GD, provided the learning rate satisfies appropriate conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practical Observation&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;SGD excels in the &lt;strong&gt;exploration phase&lt;/strong&gt; (far from optimum)&lt;/li&gt;
  &lt;li&gt;SGD struggles in the &lt;strong&gt;exploitation phase&lt;/strong&gt; (near optimum) due to noise&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-batch-gradient-descent-the-best-of-both-worlds&quot;&gt;Mini-Batch Gradient Descent: The Best of Both Worlds&lt;/h2&gt;

&lt;p&gt;A compromise between batch GD and SGD uses &lt;strong&gt;mini-batches&lt;/strong&gt; of size \(b\):&lt;/p&gt;

\[x^{(k)} = x^{(k-1)} - t_k \cdot \frac{1}{b} \sum_{i \in \mathcal{B}_k} \nabla f_i (x^{(k-1)})\]

&lt;p&gt;where \(\mathcal{B}_k\) is a mini-batch of \(b\) randomly selected indices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sum or mean?&lt;/strong&gt; Above, batch GD used the &lt;strong&gt;sum&lt;/strong&gt; \(\sum_{i=1}^m \nabla f_i\), the gradient of \(f = \sum_i f_i\). The mini-batch formula uses a &lt;strong&gt;mean&lt;/strong&gt; over \(b\) indices, which is an unbiased estimate of the mean gradient \(\frac{1}{m}\sum_{i=1}^m \nabla f_i\) (the usual convention in machine learning, where we minimize the average loss). The two only differ by a constant factor that goes into the step size: to estimate the sum instead, use \(\frac{m}{b}\sum_{i \in \mathcal{B}_k} \nabla f_i\). With \(b = m\) and the mean convention, mini-batch GD is batch GD with step \(t_k/m\).&lt;/p&gt;

&lt;div id=&quot;minibatch-comparison&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;h4&gt;Comparison: Batch vs Mini-batch vs SGD&lt;/h4&gt;
    &lt;table style=&quot;width: 100%; border-collapse: collapse; margin: 15px 0;&quot;&gt;
        &lt;thead&gt;
            &lt;tr style=&quot;background-color: #f5f5f5;&quot;&gt;
                &lt;th style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Method&lt;/th&gt;
                &lt;th style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Batch Size&lt;/th&gt;
                &lt;th style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Computation/Update&lt;/th&gt;
                &lt;th style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Convergence&lt;/th&gt;
                &lt;th style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Memory Usage&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;tr&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;&lt;strong&gt;Batch GD&lt;/strong&gt;&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;$$m$$ (full dataset)&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;$$O(m)$$&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Smooth, stable&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;High&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;&lt;strong&gt;Mini-batch GD&lt;/strong&gt;&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;$$b$$ (typically 32-256)&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;$$O(b)$$&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Balanced&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Medium&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;&lt;strong&gt;SGD&lt;/strong&gt;&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;1&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;$$O(1)$$&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Fast but noisy&lt;/td&gt;
                &lt;td style=&quot;border: 1px solid #ddd; padding: 10px;&quot;&gt;Low&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/tbody&gt;
    &lt;/table&gt;
&lt;/div&gt;

&lt;h2 id=&quot;key-takeaways-and-practical-insights&quot;&gt;Key Takeaways and Practical Insights&lt;/h2&gt;

&lt;h3 id=&quot;when-to-use-sgd&quot;&gt;When to Use SGD&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Large datasets&lt;/strong&gt; (millions of samples)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Online learning&lt;/strong&gt; scenarios&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Limited memory&lt;/strong&gt; environments&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Early training phases&lt;/strong&gt; for quick progress&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;when-to-use-batch-gd&quot;&gt;When to Use Batch GD&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Small to medium datasets&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High precision requirements&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stable convergence needed&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Final fine-tuning phases&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;best-practices&quot;&gt;Best Practices&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Learning rate scheduling&lt;/strong&gt;: Start high, decay over time&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Shuffling&lt;/strong&gt;: Randomize data order each epoch&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mini-batches&lt;/strong&gt;: Often the best practical choice&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Momentum&lt;/strong&gt;: Helps SGD overcome noise and accelerate convergence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Modern reality&lt;/strong&gt;: Most deep learning frameworks use mini-batch SGD with sophisticated optimizers (Adam, RMSprop) that adapt the learning rate automatically.&lt;/p&gt;

&lt;script&gt;
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    // Global variables for demos
    let gdData = [], sgdData = [];
    let gdPosition = [2, 2], sgdPosition = [2, 2];
    let isRunning = false;
    let isPaused = false;
    let isManualMode = false;
    let animationId;
    let currentAlgorithm = null; // &apos;gd&apos; or &apos;sgd&apos;
    let algorithmState = {
        gd: { iteration: 0, position: [2, 2], path: [], functions: [], totalCost: 0, gradient: [0, 0] },
        sgd: { iteration: 0, position: [2, 2], path: [], functions: [], totalCost: 0, gradient: [0, 0], selectedFunc: -1 }
    };
    
    // Initialize sliders
    const learningRateSlider = document.getElementById(&apos;learning-rate&apos;);
    const numFunctionsSlider = document.getElementById(&apos;num-functions&apos;);
    const animationSpeedSlider = document.getElementById(&apos;animation-speed&apos;);
    const lrValue = document.getElementById(&apos;lr-value&apos;);
    const mValue = document.getElementById(&apos;m-value&apos;);
    const speedValue = document.getElementById(&apos;speed-value&apos;);
    
    if (learningRateSlider) {
        learningRateSlider.addEventListener(&apos;input&apos;, function() {
            lrValue.textContent = this.value;
        });
    }
    
    if (numFunctionsSlider) {
        numFunctionsSlider.addEventListener(&apos;input&apos;, function() {
            mValue.textContent = this.value;
        });
    }
    
    if (animationSpeedSlider) {
        animationSpeedSlider.addEventListener(&apos;input&apos;, function() {
            speedValue.textContent = this.value;
        });
    }
    
    // Execution mode radio buttons
    const execModeRadios = document.querySelectorAll(&apos;input[name=&quot;exec-mode&quot;]&apos;);
    execModeRadios.forEach(radio =&gt; {
        radio.addEventListener(&apos;change&apos;, function() {
            isManualMode = this.value === &apos;manual&apos;;
            updateControlButtons();
        });
    });
    
    // Simple quadratic functions for demonstration
    function createFunctions(m) {
        const functions = [];
        for (let i = 0; i &lt; m; i++) {
            const centerX = (Math.random() - 0.5) * 4;
            const centerY = (Math.random() - 0.5) * 4;
            functions.push({
                center: [centerX, centerY],
                gradient: function(x, y) {
                    return [2 * (x - centerX), 2 * (y - centerY)];
                },
                value: function(x, y) {
                    return (x - centerX) ** 2 + (y - centerY) ** 2;
                }
            });
        }
        return functions;
    }
    
    // Setup SVG plots
    function setupPlot(svgId, width = 300, height = 300) {
        const svg = d3.select(`#${svgId}`);
        if (svg.empty()) return null;
        
        svg.selectAll(&quot;*&quot;).remove();
        
        const margin = {top: 20, right: 20, bottom: 30, left: 40};
        const plotWidth = width - margin.left - margin.right;
        const plotHeight = height - margin.top - margin.bottom;
        
        const xScale = d3.scaleLinear()
            .domain([-3, 3])
            .range([0, plotWidth]);
            
        const yScale = d3.scaleLinear()
            .domain([-3, 3])
            .range([plotHeight, 0]);
        
        const g = svg.append(&quot;g&quot;)
            .attr(&quot;transform&quot;, `translate(${margin.left},${margin.top})`);
        
        // Add axes
        g.append(&quot;g&quot;)
            .attr(&quot;transform&quot;, `translate(0,${plotHeight})`)
            .call(d3.axisBottom(xScale));
            
        g.append(&quot;g&quot;)
            .call(d3.axisLeft(yScale));
        
        // Add contour background
        const contourData = [];
        for (let i = 0; i &lt; 20; i++) {
            for (let j = 0; j &lt; 20; j++) {
                const x = -3 + (i / 19) * 6;
                const y = -3 + (j / 19) * 6;
                contourData.push({x, y, z: x*x + y*y});
            }
        }
        
        return {svg, g, xScale, yScale, plotWidth, plotHeight};
    }
    
    // Control button functions
    function updateControlButtons() {
        const pauseResumeBtn = document.getElementById(&apos;pause-resume&apos;);
        const stepForwardBtn = document.getElementById(&apos;step-forward&apos;);
        
        if (pauseResumeBtn) {
            pauseResumeBtn.disabled = !isRunning;
            pauseResumeBtn.textContent = isPaused ? &apos;Resume&apos; : &apos;Pause&apos;;
        }
        
        if (stepForwardBtn) {
            stepForwardBtn.disabled = !isManualMode &amp;&amp; !isPaused;
        }
    }
    
    // GD vs SGD Comparison Demo
    const startGDBtn = document.getElementById(&apos;start-gd&apos;);
    const startSGDBtn = document.getElementById(&apos;start-sgd&apos;);
    const pauseResumeBtn = document.getElementById(&apos;pause-resume&apos;);
    const stepForwardBtn = document.getElementById(&apos;step-forward&apos;);
    const resetBtn = document.getElementById(&apos;reset-demo&apos;);
    
    if (startGDBtn) {
        startGDBtn.addEventListener(&apos;click&apos;, function() {
            if (isRunning &amp;&amp; currentAlgorithm === &apos;gd&apos;) return;
            initializeAlgorithm(&apos;gd&apos;);
            if (!isManualMode) {
                runAlgorithm(&apos;gd&apos;);
            }
        });
    }
    
    if (startSGDBtn) {
        startSGDBtn.addEventListener(&apos;click&apos;, function() {
            if (isRunning &amp;&amp; currentAlgorithm === &apos;sgd&apos;) return;
            initializeAlgorithm(&apos;sgd&apos;);
            if (!isManualMode) {
                runAlgorithm(&apos;sgd&apos;);
            }
        });
    }
    
    if (pauseResumeBtn) {
        pauseResumeBtn.addEventListener(&apos;click&apos;, function() {
            if (isPaused) {
                isPaused = false;
                if (currentAlgorithm) {
                    runAlgorithm(currentAlgorithm);
                }
            } else {
                isPaused = true;
                if (animationId) {
                    cancelAnimationFrame(animationId);
                }
            }
            updateControlButtons();
        });
    }
    
    if (stepForwardBtn) {
        stepForwardBtn.addEventListener(&apos;click&apos;, function() {
            if (currentAlgorithm &amp;&amp; (isManualMode || isPaused)) {
                performSingleStep(currentAlgorithm);
            }
        });
    }
    
    if (resetBtn) {
        resetBtn.addEventListener(&apos;click&apos;, function() {
            resetDemo();
        });
    }
    
    // Initialize algorithm state
    function initializeAlgorithm(algorithm) {
        const m = parseInt(numFunctionsSlider.value);
        const functions = createFunctions(m);
        
        algorithmState[algorithm] = {
            iteration: 0,
            position: [2, 2],
            path: [[2, 2]],
            functions: functions,
            totalCost: 0,
            gradient: [0, 0],
            selectedFunc: algorithm === &apos;sgd&apos; ? -1 : undefined
        };
        
        currentAlgorithm = algorithm;
        isRunning = true;
        isPaused = false;
        
        // Setup plot
        const plotId = algorithm === &apos;gd&apos; ? &apos;gd-plot&apos; : &apos;sgd-plot&apos;;
        const plot = setupPlot(plotId, 350, 350);
        
        // Update status
        updateAlgorithmDisplay(algorithm);
        updateControlButtons();
        
        // Update detailed info
        const detailedInfoId = algorithm === &apos;gd&apos; ? &apos;gd-detailed-info&apos; : &apos;sgd-detailed-info&apos;;
        document.getElementById(detailedInfoId).textContent = 
            isManualMode ? &apos;Ready for manual stepping&apos; : &apos;Running automatically...&apos;;
    }
    
    // Run algorithm in auto mode
    function runAlgorithm(algorithm) {
        if (isPaused || isManualMode) return;
        
        const speed = parseInt(animationSpeedSlider.value);
        const delay = 1100 - speed * 100; // Convert speed to delay (higher speed = lower delay)
        
        function step() {
            if (isPaused || !isRunning) return;
            
            const shouldContinue = performSingleStep(algorithm);
            
            if (shouldContinue &amp;&amp; !isPaused) {
                setTimeout(() =&gt; {
                    animationId = requestAnimationFrame(step);
                }, delay);
            } else {
                isRunning = false;
                updateControlButtons();
                
                const detailedInfoId = algorithm === &apos;gd&apos; ? &apos;gd-detailed-info&apos; : &apos;sgd-detailed-info&apos;;
                document.getElementById(detailedInfoId).textContent = &apos;Converged!&apos;;
            }
        }
        
        step();
    }
    
    // Perform a single step of the algorithm
    function performSingleStep(algorithm) {
        const state = algorithmState[algorithm];
        const lr = parseFloat(learningRateSlider.value);
        
        if (algorithm === &apos;gd&apos;) {
            return performGDStep(state, lr);
        } else {
            return performSGDStep(state, lr);
        }
    }
    
    function performGDStep(state, lr) {
        // Compute full gradient (sum of all function gradients)
        let gradX = 0, gradY = 0;
        for (const func of state.functions) {
            const grad = func.gradient(state.position[0], state.position[1]);
            gradX += grad[0];
            gradY += grad[1];
        }
        
        // Average the gradients
        gradX /= state.functions.length;
        gradY /= state.functions.length;
        
        state.gradient = [gradX, gradY];
        
        // Update position
        state.position[0] -= lr * gradX;
        state.position[1] -= lr * gradY;
        state.path.push(state.position.slice());
        
        // Compute total cost
        state.totalCost = 0;
        for (const func of state.functions) {
            state.totalCost += func.value(state.position[0], state.position[1]);
        }
        state.totalCost /= state.functions.length;
        
        state.iteration++;
        
        // Update visualization
        updateAlgorithmDisplay(&apos;gd&apos;);
        
        // Check convergence
        const gradientMagnitude = Math.sqrt(gradX * gradX + gradY * gradY);
        return state.iteration &lt; 100 &amp;&amp; gradientMagnitude &gt; 0.01;
    }
    
    function performSGDStep(state, lr) {
        // Select random function
        const funcIndex = Math.floor(Math.random() * state.functions.length);
        const func = state.functions[funcIndex];
        state.selectedFunc = funcIndex;
        
        // Compute gradient for selected function only
        const grad = func.gradient(state.position[0], state.position[1]);
        state.gradient = grad;
        
        // Update position
        state.position[0] -= lr * grad[0];
        state.position[1] -= lr * grad[1];
        state.path.push(state.position.slice());
        
        // Compute total cost
        state.totalCost = 0;
        for (const func of state.functions) {
            state.totalCost += func.value(state.position[0], state.position[1]);
        }
        state.totalCost /= state.functions.length;
        
        state.iteration++;
        
        // Update visualization
        updateAlgorithmDisplay(&apos;sgd&apos;);
        
        // Check convergence (SGD needs more iterations)
        return state.iteration &lt; 300 &amp;&amp; state.totalCost &gt; 0.01;
    }
    
    function updateAlgorithmDisplay(algorithm) {
        const state = algorithmState[algorithm];
        const plotId = algorithm === &apos;gd&apos; ? &apos;gd-plot&apos; : &apos;sgd-plot&apos;;
        const color = algorithm === &apos;gd&apos; ? &apos;steelblue&apos; : &apos;orange&apos;;
        
        // Update path visualization
        const plot = {
            svg: d3.select(`#${plotId}`),
            g: d3.select(`#${plotId} g`),
            xScale: d3.scaleLinear().domain([-3, 3]).range([0, 270]),
            yScale: d3.scaleLinear().domain([-3, 3]).range([270, 0])
        };
        
        if (!plot.g.empty()) {
            updatePath(plot, state.path, color);
        }
        
        // Update info displays
        const infoId = algorithm === &apos;gd&apos; ? &apos;gd-info&apos; : &apos;sgd-info&apos;;
        const gradientInfoId = algorithm === &apos;gd&apos; ? &apos;gd-gradient-info&apos; : &apos;sgd-gradient-info&apos;;
        
        document.getElementById(infoId).textContent = 
            `Iterations: ${state.iteration}, Cost: ${state.totalCost.toFixed(4)}`;
        
        if (algorithm === &apos;gd&apos;) {
            document.getElementById(gradientInfoId).textContent = 
                `Gradient: [${state.gradient[0].toFixed(3)}, ${state.gradient[1].toFixed(3)}]`;
        } else {
            document.getElementById(gradientInfoId).textContent = 
                `Selected Function: f${state.selectedFunc + 1}, Gradient: [${state.gradient[0].toFixed(3)}, ${state.gradient[1].toFixed(3)}]`;
        }
        
        // Update progress bar
        const progressId = algorithm === &apos;gd&apos; ? &apos;gd-progress&apos; : &apos;sgd-progress&apos;;
        const maxIterations = algorithm === &apos;gd&apos; ? 100 : 300;
        const progress = Math.min((state.iteration / maxIterations) * 100, 100);
        document.getElementById(progressId).style.width = `${progress}%`;
        
        // Update detailed status
        const detailedInfoId = algorithm === &apos;gd&apos; ? &apos;gd-detailed-info&apos; : &apos;sgd-detailed-info&apos;;
        const gradMagnitude = Math.sqrt(state.gradient[0] ** 2 + state.gradient[1] ** 2);
        document.getElementById(detailedInfoId).textContent = 
            `Step ${state.iteration}: Position [${state.position[0].toFixed(3)}, ${state.position[1].toFixed(3)}], |∇| = ${gradMagnitude.toFixed(4)}`;
    }
    
    function updatePath(plot, path, color) {
        const line = d3.line()
            .x(d =&gt; plot.xScale(d[0]))
            .y(d =&gt; plot.yScale(d[1]));
        
        plot.g.selectAll(&apos;.path&apos;).remove();
        plot.g.append(&apos;path&apos;)
            .datum(path)
            .attr(&apos;class&apos;, &apos;path&apos;)
            .attr(&apos;fill&apos;, &apos;none&apos;)
            .attr(&apos;stroke&apos;, color)
            .attr(&apos;stroke-width&apos;, 2)
            .attr(&apos;d&apos;, line);
        
        // Add current position
        const current = path[path.length - 1];
        plot.g.selectAll(&apos;.current-pos&apos;).remove();
        plot.g.append(&apos;circle&apos;)
            .attr(&apos;class&apos;, &apos;current-pos&apos;)
            .attr(&apos;cx&apos;, plot.xScale(current[0]))
            .attr(&apos;cy&apos;, plot.yScale(current[1]))
            .attr(&apos;r&apos;, 5)
            .attr(&apos;fill&apos;, color);
    }
    
    function resetDemo() {
        if (animationId) {
            cancelAnimationFrame(animationId);
        }
        
        isRunning = false;
        isPaused = false;
        currentAlgorithm = null;
        
        // Reset algorithm states
        algorithmState = {
            gd: { iteration: 0, position: [2, 2], path: [], functions: [], totalCost: 0, gradient: [0, 0] },
            sgd: { iteration: 0, position: [2, 2], path: [], functions: [], totalCost: 0, gradient: [0, 0], selectedFunc: -1 }
        };
        
        // Clear plots
        d3.select(&apos;#gd-plot&apos;).selectAll(&quot;*&quot;).remove();
        d3.select(&apos;#sgd-plot&apos;).selectAll(&quot;*&quot;).remove();
        
        // Reset info displays
        document.getElementById(&apos;gd-info&apos;).textContent = &apos;Iterations: 0, Cost: 0&apos;;
        document.getElementById(&apos;sgd-info&apos;).textContent = &apos;Iterations: 0, Cost: 0&apos;;
        document.getElementById(&apos;gd-gradient-info&apos;).textContent = &apos;Gradient: [0, 0]&apos;;
        document.getElementById(&apos;sgd-gradient-info&apos;).textContent = &apos;Selected Function: -, Gradient: [0, 0]&apos;;
        
        // Reset detailed info
        document.getElementById(&apos;gd-detailed-info&apos;).textContent = &apos;Ready to start&apos;;
        document.getElementById(&apos;sgd-detailed-info&apos;).textContent = &apos;Ready to start&apos;;
        
        // Reset progress bars
        document.getElementById(&apos;gd-progress&apos;).style.width = &apos;0%&apos;;
        document.getElementById(&apos;sgd-progress&apos;).style.width = &apos;0%&apos;;
        
        // Update control buttons
        updateControlButtons();
    }
    
});
&lt;/script&gt;

&lt;h3 id=&quot;sgd-and-minibatches-in-about-3-minutes&quot;&gt;SGD and minibatches in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/sgd-minibatch_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The m = 3 example: one GD step versus one SGD epoch, constant versus decaying steps, then the effect of the batch size.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-04 Gradient boosting</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_04_gradient_boosting/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_04_gradient_boosting</id>
   <content type="html">&lt;p&gt;Up to now, gradient descent has updated a finite vector of numbers \(x \in \mathbb{R}^n\). Now make a dazzling conceptual leap due to Jerome Friedman (2001): what if the object you are optimizing is not a vector of weights, but an entire &lt;em&gt;prediction function&lt;/em&gt; \(F(x)\)? Take gradient descent in function space—fitting each new decision tree to the negative gradient of the loss—and you have &lt;strong&gt;Gradient Boosting&lt;/strong&gt; (XGBoost, LightGBM, CatBoost), the reigning champion of tabular machine learning.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-gradient-descent-in-function-space&quot;&gt;Key ideas: Gradient Descent in Function Space&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Functional Gradient Descent&lt;/strong&gt;: Given data \(\{(x_i, y_i)\}_{i=1}^N\) and differentiable loss \(\mathcal{L}(F) = \sum_{i=1}^N L(y_i, F(x_i))\), treat the vector of predictions \(\mathbf{f} = (F(x_1), \dots, F(x_N))^T \in \mathbb{R}^N\) as the optimization variable. The negative functional gradient at sample \(i\) is the &lt;em&gt;pseudo-residual&lt;/em&gt;
\(r_{im} = -\left[\frac{\partial L(y_i, F(x_i))}{\partial F(x_i)}\right]_{F = F_{m-1}}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Projecting onto Weak Learners (Trees)&lt;/strong&gt;: An arbitrary vector \(r_m \in \mathbb{R}^N\) cannot predict on unseen test points. Gradient boosting projects \(r_m\) onto the space of shallow regression trees by fitting a tree \(h_m(x)\) to the targets \(\{(x_i, r_{im})\}\), then updating \(F_m(x) = F_{m-1}(x) + \eta h_m(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Special Case — Squared Error = Residual Fitting&lt;/strong&gt;: For \(L(y, \hat{y}) = \frac{1}{2}(y - \hat{y})^2\), the negative gradient is simply \(r_i = y_i - F_{m-1}(x_i)\), the ordinary residual! Changing \(L\) to logistic loss or Huber loss immediately yields classification or robust regression with the exact same algorithm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Boosting vs. Bagging (Bias vs. Variance)&lt;/strong&gt;: Random Forests (Bagging) average &lt;em&gt;independent&lt;/em&gt; deep trees in parallel to cut variance; Gradient Boosting adds &lt;em&gt;sequential&lt;/em&gt; shallow trees along negative gradients to systematically eliminate bias (while learning rate \(\eta \ll 1\) prevents overfitting).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-one-boosting-round-for-squared-error-regression&quot;&gt;Worked example: One Boosting Round for Squared-Error Regression&lt;/h3&gt;

&lt;p&gt;Given four data points with targets \(y = (10, 12, 20, 22)\) at features \(x = (1, 2, 5, 6)\), run Round 0 and Round 1 of Gradient Boosting with squared loss \(L(y, \hat{y}) = \frac{1}{2}(y - \hat{y})^2\), learning rate \(\eta = 0.5\), and decision stumps (depth-1 trees).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Initialize \(F_0(x)\) with the constant minimizing total squared loss&lt;/strong&gt;:
\(F_0(x) = \bar{y} = \frac{10 + 12 + 20 + 22}{4} = 16.\)
Initial squared loss: \(\frac{1}{2}\bigl((-6)^2 + (-4)^2 + 4^2 + 6^2\bigr) = \frac{1}{2}(36 + 16 + 16 + 36) = 52.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute pseudo-residuals (negative gradients) \(r_{i1} = y_i - F_0(x_i)\)&lt;/strong&gt;:
\(r_1 = (-6,\; -4,\; +4,\; +6).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fit a depth-1 regression stump \(h_1(x)\) to \(r_1\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Split at \(x \le 3.5\): left leaf averages \(\{-6, -4\} \to -5\); right leaf averages \(\{+4, +6\} \to +5\).&lt;/li&gt;
      &lt;li&gt;Thus \(h_1(x) = -5\) if \(x \le 3.5\), else \(+5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update the ensemble with shrinkage \(\eta = 0.5\)&lt;/strong&gt;:
\(F_1(x) = F_0(x) + 0.5 h_1(x) = \begin{cases} 16 - 2.5 = 13.5 &amp;amp; \text{if } x \le 3.5, \\ 16 + 2.5 = 18.5 &amp;amp; \text{if } x &amp;gt; 3.5. \end{cases}\)
New residuals: \((-3.5, -1.5, +1.5, +3.5)\); new loss: \(\frac{1}{2}(12.25 + 2.25 + 2.25 + 12.25) = 14.5\) — cutting the loss by &lt;strong&gt;72%&lt;/strong&gt; in one stump!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;gradient-boosting&quot;&gt;Gradient boosting&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Gradient boosting&lt;/strong&gt; is a method that uses gradient descent to sequentially create trees while compensating for the errors of previous trees when trying to predict results with an ensemble model composed of multiple trees. &lt;strong&gt;Gradient Boosting&lt;/strong&gt; can be used for both regression and classification.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For detailed information, refer to the &lt;a href=&quot;https://medium.com/mlreview/gradient-boosting-from-scratch-1e317ae4587d&quot;&gt;Gradient Boosting from scratch&lt;/a&gt; blog&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;reference-functional-gradient-descent-algorithm&quot;&gt;[Reference] Functional gradient descent algorithm&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Gradient boosting&lt;/strong&gt; was introduced as a functional gradient descent algorithm by Llew Mason, Jonathan Baxter, Peter Bartlett and Marcus Frean. The functional gradient descent algorithm optimizes the loss function over function space by repeatedly selecting functions that have the negative direction of the gradient, thus performing gradient descent.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For detailed information, refer to &lt;a href=&quot;https://en.wikipedia.org/wiki/Gradient_boosting&quot;&gt;Gradient Boosting&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;reference-boosting-vs-bagging&quot;&gt;[Reference] Boosting vs Bagging&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Boosting&lt;/strong&gt; is an ensemble technique that sequentially generates weak learners to predict results. The next stage learner learns from the data that the previous stage learner predicted incorrectly, and the results of sequentially generated learners are combined to create the final result.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bagging&lt;/strong&gt; is an ensemble technique that generates weak learners independently from each other to predict results. Therefore, each learner runs in parallel and their results are combined to create the final result.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For detailed information, refer to the &lt;a href=&quot;https://quantdare.com/what-is-the-difference-between-bagging-and-boosting/&quot;&gt;What is the difference between Bagging and Boosting?&lt;/a&gt; blog
    &lt;h2 id=&quot;gradient-boosting-1&quot;&gt;Gradient Boosting&lt;/h2&gt;
    &lt;p&gt;Let’s examine the background of how &lt;strong&gt;Gradient Boosting&lt;/strong&gt; came to be developed.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Suppose there is an ensemble model composed of trees that is used for classification. This model will want to predict results that minimize the error with the observed values. Let the observed values be \(y_i\), \(i=1,\dots,n\), the input data be \(x_i, i=1,\dots,n\), and the predicted values be \(u_i\), \(i=1,\dots,n\).&lt;/p&gt;

&lt;p&gt;As shown in the figure below, each tree belonging to the ensemble receives \(x_i \in R^p\) as input and outputs results according to the branching conditions in the tree’s nodes.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_04_tree_O9zyAlk.png&quot; alt=&quot;tree_O9zyAlk&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig 1] Example of Tree }T_j\text{ [3]}$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The predicted value \(u_i\) of the ensemble model can be calculated by weighted summation of each tree’s results. (Here, \(T_j(x_i)\) is the result output by tree \(j\) when it receives \(x_i\) as input.)&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{equation}
u_i = \sum_{j=1}^M \beta_j T_j(x_i)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;For the loss function, it can be defined as \(L=(y_i,u_i)=(y_i - u_i)^2\) in the form of sum of squared errors to minimize the error between observed and predicted values.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{equation}
\min_{\beta} \sum_{i=1}^n L\left(y_i, \sum_{j=1}^M \beta_j T_j(x_i)\right)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Generally, when constructing trees in ensemble models, many small trees with fixed depth are created. This is because making trees smaller uses less memory and enables faster prediction, and as the number of trees increases, the performance of the ensemble improves. Generally, the depth of trees is fixed at 5 or less.&lt;/p&gt;

&lt;p&gt;Therefore, in this problem, the node conditions defined in each tree are very diverse and the results of very many trees are linearly combined, making the tree space quite large. Thus, it can be said that this is a very difficult problem to optimize.&lt;/p&gt;

&lt;p&gt;To solve this problem, the optimization problem must be transformed into an easier one. The original optimization problem is to find \(M\) weights \(\beta_j\) that minimize the loss function. Let’s think of this problem as a minimization problem \(\min_{u} f(u)\) of function \(f(u)\) with respect to predicted values \(u\). If function \(f(u)\) is the loss function \(L(y,u)\), then finding \(u\) that minimizes the loss function can be said to be an easily redefined problem. (Here, \(n\) is the number of data points.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gradient boosting&lt;/strong&gt; refers to the technique of solving the redefined minimization problem \(\min_{u} f(u)\) using gradient descent.&lt;/p&gt;

&lt;h2 id=&quot;algorithm&quot;&gt;Algorithm&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;Gradient boosting&lt;/strong&gt; algorithm performs gradient descent in the following way to find the optimal solution \(u^*\) of \(\min_u L(y, u)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Set the initial value as the result of an arbitrary tree: \(u^{(0)}=T_0\). Then repeat the following steps 2~4.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Calculate the negative gradient for \(u^{(k-1)}\), which is the most recent predicted value for \(n\) data points.
    &lt;blockquote&gt;

\[\begin{equation}
d_i = - \left . \left[ \frac{\partial L(y_i,u_i)}{\partial u_i} \right] \right|_{u_i = u_i^{(k-1)}}, i=1,\dots,n
\end{equation}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Find the tree \(T_k\) whose results \(T(x_i)\) are most similar to the gradients \(d_i\) for \(n\) data points.
    &lt;blockquote&gt;

\[\begin{equation}
\min_{\text{trees } T} \sum_{i=1}^n (d_i-T(x_i))^2
\end{equation}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Calculate the step size \(a_k\) and update the predicted values using the \(T_k\) found above.
    &lt;blockquote&gt;

\[u^{(k)}=u^{(k-1)} + \alpha_k T_k\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This algorithm finds the gradient \(d\) with respect to \(u\) to find the optimal solution \(u^*\) through gradient descent, finds \(T_k\) closest to \(d\), and substitutes \(T_k\) instead of gradient in the update equation to find the next position.&lt;/p&gt;

&lt;p&gt;The final predicted value \(u^*\) obtained in this way can be seen to be identical to the weighted summation of tree results defined earlier. (That is, if we expand the recursive update equation \(u^{(k)}=u^{(k-1)} + \alpha_k T_k\) back to \(k=0\), we get \(u^* = \sum_{k=1}^n \alpha_k T_k\), which can be made into the form of weighted summation of tree results.)&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>06-03 Convergence analysis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_convergence_analysis/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_convergence_analysis</id>
   <content type="html">&lt;p&gt;Watching a loss curve drop on one dataset is encouraging, but engineering critical systems demands &lt;em&gt;guarantees&lt;/em&gt;: how many iterations does gradient descent take to reach accuracy \(\varepsilon\), and how does that number depend on the problem’s geometry? Section 06-03 builds the classical convergence theory of gradient descent—from the quadratic upper bound of \(L\)-smoothness to \(O(1/k)\) sublinear rates and exponential linear rates under strong convexity.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-roadmap-of-gradient-descent-convergence-theory&quot;&gt;Key ideas: Roadmap of Gradient Descent Convergence Theory&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;The Smoothness Pillar (\(L\)-Lipschitz Gradient)&lt;/strong&gt;: Assuming \(\|\nabla f(x) - \nabla f(y)\|_2 \le L\|x - y\|_2\) yields the &lt;strong&gt;Descent Lemma&lt;/strong&gt;: \(f(y) \le f(x) + \nabla f(x)^T(y-x) + \frac{L}{2}\|y-x\|_2^2\). Every convergence proof in this section starts from this single quadratic upper bound.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sublinear \(O(1/k)\) Rate for Smooth Convex Functions&lt;/strong&gt;: With fixed step \(t \le 1/L\) (or backtracking with \(t_{\min} = \min(1, \beta/L)\)), gradient descent guarantees \(f(x^{(k)}) - f^\star \le \frac{\|x^{(0)} - x^\star\|_2^2}{2 t k}\), meaning \(O(1/\varepsilon)\) iterations to reach \(\varepsilon\)-suboptimality.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear (Exponential) Rate under \(m\)-Strong Convexity&lt;/strong&gt;: Adding a quadratic &lt;em&gt;lower&lt;/em&gt; bound \(f(y) \ge f(x) + \nabla f(x)^T(y-x) + \frac{m}{2}\|y-x\|_2^2\) upgrades the rate to \(f(x^{(k)}) - f^\star \le \left(1 - \frac{m}{L}\right)^k (f(x^{(0)}) - f^\star)\), requiring only \(O\bigl(\kappa \log(1/\varepsilon)\bigr)\) iterations!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lower Bounds and Acceleration&lt;/strong&gt;: Nesterov proved that &lt;em&gt;no&lt;/em&gt; first-order method can beat \(\Omega(1/k^2)\) on smooth convex functions (or \(\Omega(\sqrt{\kappa}\log(1/\varepsilon))\) under strong convexity)—motivating Nesterov Accelerated Gradient and momentum methods.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-comparing-iteration-budgets-at-varepsilon--10-4&quot;&gt;Worked example: Comparing Iteration Budgets at \(\varepsilon = 10^{-4}\)&lt;/h3&gt;

&lt;p&gt;Suppose a problem has smoothness constant \(L = 10\), initial distance \(\|x^{(0)} - x^\star\|_2 = 1\), and initial suboptimality \(f(x^{(0)}) - f^\star = 5\). Using fixed step size \(t = 1/L = 0.1\), compare the theoretical iteration count to guarantee \(f(x^{(k)}) - f^\star \le 10^{-4}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Case A — Smooth Convex Only (\(m = 0\))&lt;/strong&gt;:
\(\frac{\|x^{(0)} - x^\star\|_2^2}{2 t k} = \frac{1}{0.2 k} = \frac{5}{k} \le 10^{-4} \implies k \ge 50{,}000 \text{ iterations}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case B — Smooth + Strongly Convex with \(m = 1\) (\(\kappa = L/m = 10\))&lt;/strong&gt;:
\(\left(1 - \frac{1}{10}\right)^k \cdot 5 = 0.9^k \cdot 5 \le 10^{-4} \implies 0.9^k \le 2 \times 10^{-5}.\)
Taking natural logs:
\(k \ge \frac{\ln(2 \times 10^{-5})}{\ln(0.9)} = \frac{-10.8198}{-0.10536} \approx 102.7 \implies k = 103 \text{ iterations}!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway&lt;/strong&gt;: Strong convexity (for example, adding even a modest L2 regularizer) slashes the guaranteed iteration budget from &lt;strong&gt;50,000&lt;/strong&gt; down to &lt;strong&gt;103&lt;/strong&gt;—nearly a &lt;strong&gt;500×&lt;/strong&gt; speedup!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we analyze the convergence of Gradient Descent. We will examine the error bounds for convergence in the case of a fixed step size and in the case of backtracking. In addition, we will analyze the error bounds when the strong convexity condition is satisfied.”&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-06 Can we do better?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_06_can_we_do_better/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_06_can_we_do_better</id>
   <content type="html">&lt;p&gt;Gradient descent achieves \(O(1/k)\) on smooth convex functions. Is that a fundamental speed limit of nature, or are we leaving performance on the table? In 1983, Arkadi Nemirovski and Yurii Nesterov answered both halves of that question: &lt;em&gt;no&lt;/em&gt; first-order method can beat \(\Omega(1/k^2)\)—and Nesterov constructed an accelerated algorithm that actually hits that optimal \(O(1/k^2)\) limit!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-information-based-complexity-and-optimal-first-order-rates&quot;&gt;Key ideas: Information-Based Complexity and Optimal First-Order Rates&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;What Defines a First-Order Method?&lt;/strong&gt;: Every iterate \(x^{(k)}\) lies in the linear span of the starting point and all past gradients:
\(x^{(k)} \in x^{(0)} + \operatorname{span}\{\nabla f(x^{(0)}), \nabla f(x^{(1)}), \dots, \nabla f(x^{(k-1)})\}.\)
Gradient descent uses only the &lt;em&gt;latest&lt;/em&gt; gradient; accelerated methods combine past iterates (momentum) to exploit the full Krylov subspace.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov’s Worst-Case Lower Bound&lt;/strong&gt;: There exists an \(L\)-smooth convex quadratic (a tridiagonal chain where each gradient evaluation unlocks only one new coordinate per iteration!) such that &lt;strong&gt;every&lt;/strong&gt; first-order method satisfies
\(f(x^{(k)}) - f^\star \ge \frac{3L\|x^{(0)} - x^\star\|_2^2}{32(k + 1)^2} = \Omega\!\left(\frac{1}{k^2}\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Gap Between GD and Optimal First-Order Methods&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Smooth convex&lt;/em&gt;: GD gets \(O(1/\varepsilon)\) iterations; Nesterov Accelerated Gradient (NAG) achieves the optimal \(O(1/\sqrt{\varepsilon})\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Smooth \(m\)-strongly convex&lt;/em&gt;: GD gets \(O(\kappa \log(1/\varepsilon))\); NAG achieves the optimal \(O(\sqrt{\kappa}\log(1/\varepsilon))\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Momentum Breaks Monotonicity to Go Faster&lt;/strong&gt;: Unlike vanilla GD, accelerated methods can briefly &lt;em&gt;increase&lt;/em&gt; \(f(x^{(k)})\) (non-monotone oscillations), trading strict per-step descent for dramatically faster global convergence.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-comparing-gd-vs-nesterov-iteration-complexity&quot;&gt;Worked example: Comparing GD vs. Nesterov Iteration Complexity&lt;/h3&gt;

&lt;p&gt;Suppose you need to solve a large smooth convex problem to suboptimality \(\varepsilon = 10^{-6}\) (with \(L\|x^{(0)} - x^\star\|_2^2 = 1\)), and also consider a strongly convex version with condition number \(\kappa = 10{,}000\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Smooth convex regime (\(\varepsilon = 10^{-6}\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Vanilla Gradient Descent (\(O(1/\varepsilon)\))&lt;/strong&gt;: requires roughly \(\frac{1}{2\varepsilon} = 500{,}000\) iterations.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Nesterov Accelerated Gradient (\(O(1/\sqrt{\varepsilon})\))&lt;/strong&gt;: requires roughly \(\sqrt{\frac{2}{\varepsilon}} \approx 1{,}414\) iterations — more than &lt;strong&gt;350× faster&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strongly convex regime (\(\kappa = 10{,}000\), \(\varepsilon = 10^{-6}\), \(\ln(1/\varepsilon) \approx 13.8\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Vanilla Gradient Descent (\(\kappa \ln(1/\varepsilon)\))&lt;/strong&gt;: \(\approx 10{,}000 \times 13.8 = 138{,}000\) iterations.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Nesterov Accelerated Gradient (\(\sqrt{\kappa}\ln(1/\varepsilon)\))&lt;/strong&gt;: \(\approx 100 \times 13.8 = 1{,}380\) iterations — a &lt;strong&gt;100× speedup&lt;/strong&gt; purely from using past gradient history!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Gradient descent has a convergence rate of \(O(1/\epsilon)\) for problems represented by functions that have Lipschitz gradients and are convex and differentiable. Are there first-order methods that are faster than gradient descent?&lt;/p&gt;

&lt;h3 id=&quot;first-order-method&quot;&gt;First-order method&lt;/h3&gt;
&lt;p&gt;A first-order method can express changes at the \(x^{(k)}\)-th iteration as follows. Therefore, the change at the \(x^{(k)}\)-th iteration is expressed as the span of gradients from the initial position \(x^{(0)}\) to \(x^{(k−1)}\).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x^{(0)} +\) &lt;strong&gt;span&lt;/strong&gt;\(\{∇f(x^{(0)}),∇f(x^{(1)}),...,∇f(x^{(k−1)})\}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;theorem-nesterov&quot;&gt;Theorem (Nesterov)&lt;/h3&gt;
&lt;p&gt;Nesterov’s theorem provides a lower bound for the convergence of first-order methods.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Nesterov Theorem&lt;/strong&gt; For any \(k ≤ (n−1)/2\) and starting point \(x^{(0)}\), there exists a function \(f\) such that any first-order method satisfies the following condition (where \(n\) denotes the dimension):&lt;br /&gt;
\begin{align}
f(x^{(k)})−f^{\star} ≥ \frac{3L \lVert x^{(0)} −x^{\star} \rVert_2^2}{32(k + 1)^2 }\&lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since Nesterov’s theorem has \(k^2\) in the denominator of the lower bound, the convergence rate becomes \(O(1/k^2)\). Furthermore, the number of iterations becomes \(O(1/\sqrt{\epsilon})\). We will examine this content in detail later.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-05 A look at the conditions & Practicalities</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_05_look_at_the_conditions_and_practicalities/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_05_look_at_the_conditions_and_practicalities</id>
   <content type="html">&lt;p&gt;Convergence theorems look pristine on a chalkboard: “Assume \(f\) is \(m\)-strongly convex and \(L\)-smooth.” Then you open a real dataset with 10,000 features and 500 samples, run least squares, and suddenly \(m = 0\)! This lesson bridges theory and practice by computing exact \(L\) and \(m\) values for real machine-learning objectives and revealing what happens when conditions break.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-computing-l-and-m-in-practice&quot;&gt;Key ideas: Computing \(L\) and \(m\) in Practice&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Least Squares \(f(\beta) = \frac{1}{2}\|y - X\beta\|_2^2\)&lt;/strong&gt;: The Hessian is \(\nabla^2 f(\beta) = X^T X\), so \(L = \sigma_{\max}^2(X)\) and \(m = \sigma_{\min}^2(X)\). Whenever \(p &amp;gt; n\) (more features than samples) or columns are collinear, \(\sigma_{\min}(X) = 0\), so strong convexity &lt;strong&gt;fails&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;How Ridge Regularization Restores Strong Convexity&lt;/strong&gt;: Adding \(\frac{\lambda}{2}\|\beta\|_2^2\) shifts every Hessian eigenvalue up by \(\lambda\): \(L = \sigma_{\max}^2(X) + \lambda\) and \(m = \sigma_{\min}^2(X) + \lambda \ge \lambda &amp;gt; 0\). The condition number improves dramatically to \(\kappa = \frac{\sigma_{\max}^2(X) + \lambda}{\sigma_{\min}^2(X) + \lambda}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feature Scaling Directly Controls \(\kappa\)&lt;/strong&gt;: If Feature 1 is measured in millimeters (\(10^3\)) and Feature 2 in kilometers (\(10^{-3}\)), the ratio of singular values squared explodes by \(10^{12}\), crippling gradient descent. Standardizing features to zero mean and unit variance is actually &lt;em&gt;diagonal preconditioning&lt;/em&gt; that slashes \(\kappa\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cost per Iteration vs. Accuracy Regime&lt;/strong&gt;: Each gradient step on least squares costs \(O(np)\), whereas Newton’s method or Cholesky costs \(O(np^2 + p^3)\). Gradient descent wins when \(p\) is huge and moderate accuracy (\(\varepsilon \approx 10^{-3}\)) suffices; second-order methods win when \(p\) is moderate and high accuracy (\(\varepsilon \approx 10^{-10}\)) or high \(\kappa\) dominates.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-how-feature-scaling-and-ridge-shrink-kappa&quot;&gt;Worked example: How Feature Scaling and Ridge Shrink \(\kappa\)&lt;/h3&gt;

&lt;p&gt;Consider a two-feature design matrix where Feature 1 is in meters and Feature 2 is in millimeters:
\(X = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 100 \end{bmatrix}, \qquad X^T X = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 10{,}000 \end{bmatrix}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Raw unscaled OLS (\(\lambda = 0\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(L = 10{,}000\), \(m = 1\), so \(\kappa = 10{,}000\).&lt;/li&gt;
      &lt;li&gt;Safe step size \(t = 1/L = 10^{-4}\) shrinks the error along Feature 1 by only \(1 - 10^{-4} = 0.9999\) per step—needing \(\approx 23{,}000\) iterations to cut error by \(10\times\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Add Ridge regularization \(\lambda = 99\) (still unscaled)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(L = 10{,}099\), \(m = 100\), so \(\kappa = 100.99\) — a &lt;strong&gt;100×&lt;/strong&gt; reduction in condition number just from \(\lambda\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Standardize features first&lt;/strong&gt; (divide column 2 by \(100\) so \(\tilde{X} = I_2\)):
    &lt;ul&gt;
      &lt;li&gt;\(\tilde{X}^T \tilde{X} = I_2 \implies L = 1, m = 1, \kappa = 1\)!&lt;/li&gt;
      &lt;li&gt;Gradient descent with \(t = 1\) converges to the &lt;strong&gt;exact&lt;/strong&gt; global optimum in &lt;strong&gt;1 single iteration&lt;/strong&gt; instead of 23,000!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;lipschitz-continuity--strong-convexity-conditions&quot;&gt;Lipschitz continuity &amp;amp; Strong convexity conditions&lt;/h2&gt;
&lt;p&gt;Let’s examine the conditions for Lipschitz continuity and Strong convexity using \(f(β) = \frac{1}{2} \lVert y−Xβ \rVert_2^2\) as an example.&lt;/p&gt;

&lt;h3 id=&quot;lipschitz-continuity-of-f-&quot;&gt;Lipschitz continuity of \(∇f\) :&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;This means \(\nabla^2f(x) \preceq LI\). &lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Since \(∇^2f(β) = X^TX\), we have \(L = \sigma^2_{max}(X)\).&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;strong-convexity-of-f-&quot;&gt;Strong convexity of \(f\) :&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;This means \(\nabla^2f(x) \succeq mI\).&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Since \(\nabla^2f(β) = X^TX\), we have \(m = \sigma_{min}^2(X)\).&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;If \(X\) is an \(n \times p\) matrix and \(p &amp;gt; n\), then \(\sigma_{min}(X) = 0\), so \(f\) cannot be strongly convex.&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Even if \(\sigma_{min}(X) &amp;gt; 0\), the condition number \(L/m = \sigma_{max}^2(X)/\sigma_{min}^2(X)\) can be very large.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If function \(f\) is strongly convex and has a Lipschitz gradient, then it satisfies the following. You can think of \(f\) as being sandwiched between two quadratic functions.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(mI \preceq \nabla^2f(x) \preceq LI \text{ for all } x ∈ \mathbb{R}^n\) and \(L &amp;gt; m &amp;gt; 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Satisfying both conditions for all \(x\) can be very strong. However, if we think more carefully, we can see that this condition is only needed for the following sublevel set.&lt;/p&gt;

&lt;blockquote&gt;
\[S = \{x : f(x) \leq f(x^{(0)})\}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;practicalities&quot;&gt;Practicalities&lt;/h2&gt;

&lt;h3 id=&quot;stopping-criteria-for-optimization-algorithms&quot;&gt;Stopping Criteria for Optimization Algorithms&lt;/h3&gt;

&lt;p&gt;In practice, optimization algorithms need well-defined stopping criteria to determine when to terminate the iterative process. Here are the most common stopping conditions:&lt;/p&gt;

&lt;h4 id=&quot;1-gradient-magnitude-near-zero&quot;&gt;1. &lt;strong&gt;Gradient Magnitude Near Zero:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;This is the ideal stopping condition for unconstrained optimization problems, based on the fact that the gradient of the objective function equals zero at local extrema.
\(\|\nabla f(\mathbf{x}_k)\| \leq \epsilon_1\)
where \(\mathbf{x}_k\) is the current point at iteration \(k\), and \(\epsilon_1\) is a small positive threshold.&lt;/p&gt;

&lt;p&gt;If \(x^{\star}\) is the solution, then \(\nabla f(x^{\star}) = 0\). If \(f\) is strongly convex, then:&lt;/p&gt;
&lt;blockquote&gt;
\[\lVert \nabla f(x) \rVert_2 ≤ \sqrt{2m \epsilon} ⇒ f(x)−f^{\star} ≤ \epsilon\]
&lt;/blockquote&gt;

&lt;h4 id=&quot;2-small-change-in-objective-function-value&quot;&gt;2. &lt;strong&gt;Small Change in Objective Function Value:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The algorithm stops when the objective function value no longer changes significantly between consecutive iterations.
\(|f(\mathbf{x}_{k+1}) - f(\mathbf{x}_k)| \leq \epsilon_2\)
where \(\epsilon_2\) is a small positive threshold.&lt;/p&gt;

&lt;h4 id=&quot;3-small-change-in-variables-parameters&quot;&gt;3. &lt;strong&gt;Small Change in Variables (Parameters):&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The algorithm stops when the model parameters no longer change significantly between iterations.
\(\|\mathbf{x}_{k+1} - \mathbf{x}_k\| \leq \epsilon_3\)
where \(\epsilon_3\) is a small positive threshold.&lt;/p&gt;

&lt;h4 id=&quot;4-maximum-number-of-iterations&quot;&gt;4. &lt;strong&gt;Maximum Number of Iterations:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;To prevent the algorithm from running indefinitely or for too long, an upper limit on the number of iterations is set.
\(k \geq \text{MaxIterations}\)
This is a safety stopping condition that ensures the algorithm will terminate within a reasonable time, even if it hasn’t achieved perfect convergence.&lt;/p&gt;

&lt;h4 id=&quot;5-maximum-runtime&quot;&gt;5. &lt;strong&gt;Maximum Runtime:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Similar to the maximum iteration limit, the algorithm can be stopped if it has been running for more than an allowed time period.
\(\text{ElapsedTime} \geq \text{MaxTime}\)&lt;/p&gt;

&lt;h4 id=&quot;6-combined-conditions&quot;&gt;6. &lt;strong&gt;Combined Conditions:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;In practice, multiple stopping conditions are often used in combination. For example, the algorithm stops if &lt;em&gt;any&lt;/em&gt; of the above conditions is satisfied. This helps balance between accuracy and computational efficiency.&lt;/p&gt;

&lt;h3 id=&quot;reference-derivation-process&quot;&gt;[Reference] Derivation Process&lt;/h3&gt;
&lt;p&gt;The derivation process for the above equation is as follows.
Since \(f\) satisfies Strong Convexity, there exists a constant \(m \ge 0\) such that:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
\nabla^2 f(x) \succeq mI \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Let’s expand function \(f\) using the second-order Taylor series.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) = f(x) + \nabla f(x)^T(y−x) + \frac{1}{2} (y−x)^T \nabla^2 f(x) (y−x), \space \forall x, y
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Then, according to the above \(\nabla f(x) \succeq mI\), we can arrange the last term as a lower bound condition.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) &amp;amp;  \ge f(x) + \nabla f(x)^T(y−x) + \frac{m}{2} \lVert y−x \rVert_2^2, \space \forall x, y
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Differentiating \(f(y)\) with respect to \(y\) gives \(\tilde{y} = x - (1/m) \nabla f(x)\). Substituting \(\tilde{y}\) into the Taylor expansion gives:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(y) &amp;amp;  \ge f(x) + \nabla f(x)^T(\tilde{y}−x) + \frac{m}{2} \lVert \tilde{y}−x \rVert_2^2 \\
&amp;amp;  = f(x) - \frac{1}{2m} \lVert \nabla f(x) \rVert_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore, replacing \(f(y)\) with \(f^{*}\) gives:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
 f^{*}  \ge f(x) - \frac{1}{2m} \lVert \nabla f(x) \rVert_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The above stopping rule is derived as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(x) - f^{*} \le \frac{1}{2m} \lVert \nabla f(x) \rVert^2_2 &amp;amp; \le \epsilon \\
\lVert \nabla f(x) \rVert^2_2 &amp;amp; \le 2m\epsilon \\
\lVert \nabla f(x) \rVert_2 &amp;amp; \le \sqrt{2m\epsilon} \\
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;advantages-and-disadvantages-of-gradient-descent&quot;&gt;Advantages and Disadvantages of Gradient Descent&lt;/h3&gt;

&lt;h3 id=&quot;pros&quot;&gt;Pros&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;The algorithm is simple and the cost per iteration is low.&lt;/li&gt;
  &lt;li&gt;Very fast for well-conditioned, strongly convex problems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;cons&quot;&gt;Cons&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Generally slow because many problems are not strongly convex or well-conditioned.&lt;/li&gt;
  &lt;li&gt;Cannot handle non-differentiable functions.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-04 Convergence analysis under strong convexity</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_04_convergence_analysis_under_strong_convexity/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_04_convergence_analysis_under_strong_convexity</id>
   <content type="html">&lt;p&gt;On a flat-bottomed convex valley, gradients fade gently near the minimum and gradient descent slows to \(O(1/k)\). Now give the valley a guaranteed minimum upward curvature \(m &amp;gt; 0\)—strong convexity—and everything changes: gradients stay steep all the way to \(x^\star\), and the error plummets &lt;em&gt;exponentially&lt;/em&gt; fast, cutting digits of precision at a constant rate every few steps.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-strong-convexity-and-linear-convergence&quot;&gt;Key ideas: Strong Convexity and Linear Convergence&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Quadratic Lower Bound (\(m\)-Strong Convexity)&lt;/strong&gt;: A function \(f\) is \(m\)-strongly convex if \(f(x) - \frac{m}{2}\|x\|_2^2\) is convex, equivalently
\(f(y) \ge f(x) + \nabla f(x)^T(y - x) + \frac{m}{2}\|y - x\|_2^2 \quad \forall x, y\)
(or \(\nabla^2 f(x) \succeq mI\) when twice differentiable). This guarantees a &lt;em&gt;unique&lt;/em&gt; global minimizer \(x^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Polyak–Łojasiewicz (PL) Inequality&lt;/strong&gt;: Minimizing the quadratic lower bound over \(y\) yields the crucial gradient-dominance bound
\(\|\nabla f(x)\|_2^2 \ge 2m\bigl(f(x) - f^\star\bigr).\)
In words: wherever you are still far from \(f^\star\), the gradient &lt;em&gt;cannot&lt;/em&gt; be tiny!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;One-Line Linear Convergence Proof&lt;/strong&gt;: Combining the \(L\)-smoothness drop \(f(x^+) - f^\star \le f(x) - f^\star - \frac{1}{2L}\|\nabla f(x)\|_2^2\) with the PL inequality immediately gives
\(f(x^{(k)}) - f^\star \le \left(1 - \frac{m}{L}\right)^k \bigl(f(x^{(0)}) - f^\star\bigr).\)
With the tighter step \(t = \frac{2}{m + L}\), the distance to \(x^\star\) contracts even faster: \(\|x^{(k)} - x^\star\|_2 \le \left(\frac{L - m}{L + m}\right)^k \|x^{(0)} - x^\star\|_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Role of the Condition Number \(\kappa = L/m\)&lt;/strong&gt;: Every \(\kappa\) iterations cuts the error by a factor of \(e \approx 2.718\), so achieving \(\varepsilon\) accuracy requires only \(O(\kappa \log(1/\varepsilon))\) steps—logarithmic in \(1/\varepsilon\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-applying-the-pl-inequality-to-ridge-regression&quot;&gt;Worked example: Applying the PL Inequality to Ridge Regression&lt;/h3&gt;

&lt;p&gt;Consider the 1D Ridge objective \(f(x) = \frac{1}{2}(2x - 6)^2 + \frac{1}{2}(2)x^2 = 3x^2 - 12x + 18\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Determine \(m\), \(L\), and \(x^\star\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(x) = 6x - 12\), \(f&apos;&apos;(x) = 6\). Here \(m = L = 6\) (so \(\kappa = 1\)).&lt;/li&gt;
      &lt;li&gt;Setting \(f&apos;(x) = 0\) gives \(x^\star = 2\) and \(f^\star = 3(4) - 24 + 18 = 6\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the PL inequality at \(x^{(0)} = 5\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Suboptimality: \(f(5) - f^\star = (75 - 60 + 18) - 6 = 33 - 6 = 27\).&lt;/li&gt;
      &lt;li&gt;Gradient squared: \(\|f&apos;(5)\|_2^2 = (30 - 12)^2 = 18^2 = 324\).&lt;/li&gt;
      &lt;li&gt;PL right-hand side: \(2m(f(5) - f^\star) = 2(6)(27) = 324\) — exact equality!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify linear convergence with conservative step \(t = 1/12\)&lt;/strong&gt; (pretending we overestimated \(L_{\mathrm{est}} = 12\)):
    &lt;ul&gt;
      &lt;li&gt;Guaranteed factor: \(1 - \frac{m}{L_{\mathrm{est}}} = 1 - \frac{6}{12} = 0.5\).&lt;/li&gt;
      &lt;li&gt;Step 1: \(x^{(1)} = 5 - \frac{1}{12}(18) = 3.5\), giving \(f(3.5) - f^\star = 3(3.5 - 2)^2 = 3(2.25) = 6.75\).&lt;/li&gt;
      &lt;li&gt;Ratio: \(\frac{6.75}{27} = 0.25 \le 0.5\) — geometric contraction verified!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If \(f\) satisfies the following condition, it is strongly convex (assuming \(f\) is twice differentiable and \(m &amp;gt; 0\)):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) \ge f(x) + \nabla f(x)^T(y-x) + \frac{m}{2} \| y-x \|_2^2, \quad \forall x, y
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(f\) has a quadratic lower bound, and the constant \(m\) is determined by the minimum eigenvalue of the Hessian of \(f\).&lt;/p&gt;

&lt;p&gt;For any convex function \(g\), \(f\) is strongly convex if:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
g(x) = f(x) - \frac{m}{2} \| x \|_2^2 \quad \text{is convex for all } x \text{ and } m &amp;gt; 0
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;convergence-theorem&quot;&gt;Convergence Theorem&lt;/h2&gt;
&lt;p&gt;Given Lipschitz continuity and strong convexity, the following theorem holds (where \(L\) is the Lipschitz constant and \(m\) is the strong convexity constant):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gradient descent&lt;/strong&gt; with fixed step size (\(t \le 2/(m + L)\)) or backtracking line search satisfies:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f^* \le c^k \frac{L}{2} \| x^{(0)} - x^* \|_2^2, \quad c = (1 - \frac{m}{L}), \quad 0 &amp;lt; c &amp;lt; 1
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;proof&quot;&gt;Proof&lt;/h2&gt;
&lt;p&gt;If \(\nabla f\) is Lipschitz continuous and \(f\) is strongly convex, then \(f\) has a quadratic upper bound (see &lt;a href=&quot;#post-not-found&quot;&gt;06-03-02&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;For gradient descent \(x^+ = x - t \nabla f(x)\), the optimal \(t\) is \(1/L\), yielding:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^+) \le f(x) -  \frac{1}{2L} \| \nabla f(x) \|_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Subtracting \(f(x^*)\) from both sides:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^+) - f(x^*) \le f(x) - f(x^*) -  \frac{1}{2L} \| \nabla f(x) \|_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Since Gradient Descent satisfies the condition:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x) - f(x^*) \le \frac{1}{2m} \| \nabla f(x) \|_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;We can substitute to get:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^+) - f(x^*) &amp;amp; \le f(x) - f(x^*) -  \frac{m}{L} ( f(x) - f(x^*) ) \\
&amp;amp; =  (1 -  \frac{m}{L} ) ( f(x) - f(x^*) ) \\
&amp;amp; = c  ( f(x) - f(x^*) ) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Iterating this process gives:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f(x^*) \le c^k ( f(x^{(0)}) - f(x^*) ) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;From the Taylor expansion of the function with \(y = x^{(0)}\) and \(x = x^*\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) \le f(x) + \nabla f(x)^T (y-x) + \frac{L}{2} \lVert y - x \rVert^2_2  \space \space \forall x, y
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;And since the function is convex, we have:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(0)}) &amp;amp; \le f(x^{*}) + \nabla f(x^{*})^T (x^{(0)}- x^{*} ) + \frac{L}{2} \lVert x^{(0)} - x^{*} \rVert^2_2 \\\\
&amp;amp; =  f(x^{*}) + \frac{L}{2} \lVert x^{(0)} - x^{*} \rVert^2_2 \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Rearranging gives:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(0)}) - f(x^{*}) &amp;amp; \le \frac{L}{2} \lVert x^{(0)} - x^{*} \rVert^2_2 \\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Substituting this into the previous inequality results in:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f(x^{*}) &amp;amp; \le c^k \frac{L}{2} \lVert x^{(0)} - x^{*} \rVert^2_2  \\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;This proves the Convergence Theorem for Gradient Descent under Strong Convexity.&lt;/p&gt;

&lt;h2 id=&quot;linear-convergence&quot;&gt;Linear convergence&lt;/h2&gt;
&lt;p&gt;When \(f\) is strongly convex, the convergence rate becomes \(O(c^k)\), which is exponential.
To achieve \(f(x^{(k)}) - f^{*} \le \epsilon\), it requires \(O(\log(1/\epsilon)\) iterations.
(Without strong convexity, it would require \(O(1/\epsilon)\) iterations.)&lt;/p&gt;

&lt;p&gt;The convergence rate \(O(c^k)\) appears linear on a semi-log plot, as shown below.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06.03_01_01_Line_Convergence.png&quot; alt=&quot;Line_Convergence&quot; width=&quot;60%&quot; height=&quot;60%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Linear convergence [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Here, the constant \(c\) in \(O(c^k)\) is given by \(1 - \frac{m}{L}\) and depends on the condition number \(L/m\). A larger condition number results in slower convergence (where the condition number is the ratio of the largest eigenvalue to the smallest eigenvalue).&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;algebra&lt;/em&gt; of this proof — descent lemma plus a lower bound that turns \(\|\nabla f\|^2\) into a function-value gap — still works if strong convexity is weakened to the Polyak–Łojasiewicz inequality. That optional modern-rate story, and the overparameterized least-squares example where minimizers are not unique, is &lt;a href=&quot;/contents/en/chapter28/28_05_pl_condition/&quot;&gt;28-05 The PL condition and modern rates&lt;/a&gt;.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>06-03-03 Convergence analysis for backtracking</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_03_convergence_analysis_for_backtracking/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_03_convergence_analysis_for_backtracking</id>
   <content type="html">&lt;p&gt;You might worry that replacing a known fixed step size \(t = 1/L\) with Armijo backtracking could wreck the \(O(1/k)\) convergence theorem—after all, backtracking doesn’t even know \(L\)! Remarkably, the convergence rate stays &lt;strong&gt;exactly \(O(1/k)\)&lt;/strong&gt;, paying at most a tiny constant factor \(1/\beta\) because backtracking is mathematically guaranteed never to shrink the step size below \(\min(1, \beta/L)\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-backtracking-preserves-the-o1k-rate&quot;&gt;Key ideas: Why Backtracking Preserves the \(O(1/k)\) Rate&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lower Bound on Accepted Step Size \(t_k\)&lt;/strong&gt;: For an \(L\)-smooth function and \(\alpha \le \frac{1}{2}\), any \(t \le 1/L\) satisfies \(f(x - t\nabla f) \le f(x) - \frac{t}{2}\|\nabla f\|_2^2 \le f(x) - \alpha t\|\nabla f\|_2^2\). Therefore, either the initial step \(t_0 = 1\) is accepted immediately, or the last rejected step had \(t_{\mathrm{rej}} &amp;gt; 1/L\), forcing the accepted step to satisfy \(t_k = \beta t_{\mathrm{rej}} &amp;gt; \beta / L\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unified Effective Step Size \(t_{\min}\)&lt;/strong&gt;: Defining \(t_{\min} = \min(1, \beta/L)\), every single iteration satisfies \(f(x^{(i+1)}) \le f(x^{(i)}) - \frac{t_{\min}}{2}\|\nabla f(x^{(i)})\|_2^2\) (for \(\alpha = 1/2\), or with \(\alpha\) in place of \(1/2\) in general).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Identical Telescoping Proof&lt;/strong&gt;: Plugging \(t_{\min}\) into the exact same telescoping sum as fixed-step gradient descent yields
\(f(x^{(k)}) - f^\star \le \frac{\|x^{(0)} - x^\star\|_2^2}{2 t_{\min} k} = \frac{\|x^{(0)} - x^\star\|_2^2}{2 \min(1, \beta/L)\, k}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Often Faster Than Theory Predicts&lt;/strong&gt;: Because backtracking adapts to &lt;em&gt;local&lt;/em&gt; curvature rather than the global worst-case \(L\), it routinely takes steps much larger than \(1/L\) across flat regions, outperforming fixed-step GD in practice.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-computing-t_min-and-backtracking-overhead&quot;&gt;Worked example: Computing \(t_{\min}\) and Backtracking Overhead&lt;/h3&gt;

&lt;p&gt;Suppose \(f\) is convex with global Lipschitz constant \(L = 10\) (unknown to the algorithm), and we run Armijo backtracking with \(t_0 = 1\), \(\alpha = 0.5\), and \(\beta = 0.5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the theoretical floor \(t_{\min}\)&lt;/strong&gt;:
\(t_{\min} = \min\!\left(1, \frac{\beta}{L}\right) = \min\!\left(1, \frac{0.5}{10}\right) = 0.05.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the sequence of candidate steps \(t = \beta^m\)&lt;/strong&gt;:
\(t \in \{1,\; 0.5,\; 0.25,\; 0.125,\; 0.0625,\; \dots\}.\)
Notice that \(t = 0.125 &amp;gt; 1/L = 0.1\) might fail in the steepest region, but the very next shrink gives \(t = 0.0625 \le 0.1 = 1/L\), which is &lt;strong&gt;guaranteed&lt;/strong&gt; to pass Armijo!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Count the worst-case evaluations per iteration&lt;/strong&gt;: Reaching \(0.0625 = 2^{-4}\) takes at most \(4\) shrinks (\(5\) function evaluations total), regardless of dimension \(n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare the convergence constant against oracle fixed step \(t = 1/L = 0.1\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Fixed \(t = 1/L\): bound is \(\frac{\|x^{(0)} - x^\star\|^2}{0.2 k}\).&lt;/li&gt;
      &lt;li&gt;Backtracking (\(t_{\min} = 0.05\)): bound is \(\frac{\|x^{(0)} - x^\star\|^2}{0.1 k}\) — at most a \(2\times\) constant factor without ever needing to know \(L = 10\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Suppose \(f\) is convex and differentiable with \(dom(f) = \mathbb{R}^n\), and \(\nabla f\) is Lipschitz continuous with constant \(L &amp;gt; 0\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\| \nabla f(x) - \nabla f(y) \|_2 \le L \| x - y \|_2\) for any \(x, y\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reference: [&lt;a href=&quot;https://en.wikipedia.org/wiki/Lipschitz_continuity&quot;&gt;Wikipedia: Lipschitz continuity&lt;/a&gt;]&lt;/p&gt;

&lt;h2 id=&quot;convergence-theorem&quot;&gt;Convergence Theorem&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Gradient descent&lt;/strong&gt; with backtracking line search satisfies:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f^* \le \frac{\| x^{(0)} - x^* \|_2^2}{2 t_{min} k}, \quad t_{min} = \min \{ 1, \beta/L \}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The convergence rate for backtracking line search is similar to that for fixed step size, with the step size \(t\) replaced by \(t_{min}\). If \(\beta\) is not too small, the performance is comparable to fixed step size (\(\beta/L\) vs. \(1/L\)).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-02 Convergence analysis & Proof</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_02_convergence_analysis_and_proof/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_02_convergence_analysis_and_proof</id>
   <content type="html">&lt;p&gt;How do you prove that a greedy local rule—just following the negative gradient—must eventually land arbitrarily close to the global minimum? The proof is one of the crown jewels of convex analysis: combine the quadratic upper bound with convexity’s linear lower bound, and watch the squared distances \(\|x^{(i)} - x^\star\|_2^2\) telescope like a collapsing accordion, leaving a clean \(O(1/k)\) error bound.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-the-o1k-telescoping-proof&quot;&gt;Key ideas: Anatomy of the \(O(1/k)\) Telescoping Proof&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Step 1 — Smoothness Gives a Drop&lt;/strong&gt;: From \(t \le 1/L\), each step reduces the objective by at least \(\frac{t}{2}\|\nabla f(x^{(i)})\|_2^2\):
\(f(x^{(i+1)}) \le f(x^{(i)}) - \frac{t}{2}\|\nabla f(x^{(i)})\|_2^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 2 — Convexity Bridges to \(x^\star\)&lt;/strong&gt;: Convexity gives \(f(x^{(i)}) \le f(x^\star) + \nabla f(x^{(i)})^T(x^{(i)} - x^\star)\). Substituting this into Step 1 expresses \(f(x^{(i+1)}) - f(x^\star)\) purely in terms of \(\nabla f(x^{(i)})\) and \((x^{(i)} - x^\star)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 3 — Completing the Square Creates a Telescope&lt;/strong&gt;: Using the algebraic identity
\(u^T v - \frac{t}{2}\|u\|_2^2 = \frac{1}{2t}\Bigl(\|v\|_2^2 - \|v - tu\|_2^2\Bigr)\)
with \(u = \nabla f(x^{(i)})\) and \(v = x^{(i)} - x^\star\) yields
\(f(x^{(i+1)}) - f(x^\star) \le \frac{1}{2t}\Bigl(\|x^{(i)} - x^\star\|_2^2 - \|x^{(i+1)} - x^\star\|_2^2\Bigr).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 4 — Summing &amp;amp; Monotonicity&lt;/strong&gt;: Summing from \(i = 0\) to \(k - 1\) cancels all intermediate distance terms, and because \(f(x^{(k)}) \le f(x^{(i)})\) for all \(i \le k\), we get \(f(x^{(k)}) - f(x^\star) \le \frac{\|x^{(0)} - x^\star\|_2^2}{2tk}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-checking-the-telescoping-inequality-numerically&quot;&gt;Worked example: Checking the Telescoping Inequality Numerically&lt;/h3&gt;

&lt;p&gt;Apply gradient descent to \(f(x) = \frac{1}{2}x^2\) (so \(L = 1\), \(x^\star = 0\), \(f^\star = 0\)) from \(x^{(0)} = 4\) with \(t = 0.5 \le 1/L\) for \(k = 3\) steps, and verify every term of the telescoping proof!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the iterates and objective values&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(x^{(0)} = 4\), \(f(x^{(0)}) = 8\), \(\|x^{(0)} - x^\star\|^2 = 16\).&lt;/li&gt;
      &lt;li&gt;\(x^{(1)} = 4 - 0.5(4) = 2\), \(f(x^{(1)}) = 2\), \(\|x^{(1)} - x^\star\|^2 = 4\).&lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = 2 - 0.5(2) = 1\), \(f(x^{(2)}) = 0.5\), \(\|x^{(2)} - x^\star\|^2 = 1\).&lt;/li&gt;
      &lt;li&gt;\(x^{(3)} = 1 - 0.5(1) = 0.5\), \(f(x^{(3)}) = 0.125\), \(\|x^{(3)} - x^\star\|^2 = 0.25\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the single-step telescoping inequality \(f(x^{(i+1)}) - f^\star \le \frac{1}{2t}(\|x^{(i)}\|^2 - \|x^{(i+1)}\|^2)\)&lt;/strong&gt; (with \(\frac{1}{2t} = 1\)):
    &lt;ul&gt;
      &lt;li&gt;\(i = 0\): \(2 \le 1(16 - 4) = 12\) (holds!).&lt;/li&gt;
      &lt;li&gt;\(i = 1\): \(0.5 \le 1(4 - 1) = 3\) (holds!).&lt;/li&gt;
      &lt;li&gt;\(i = 2\): \(0.125 \le 1(1 - 0.25) = 0.75\) (holds!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sum all three inequalities and check the final \(O(1/k)\) bound&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Left sum: \(2 + 0.5 + 0.125 = 2.625 \ge 3 \cdot f(x^{(3)}) = 0.375\).&lt;/li&gt;
      &lt;li&gt;Right telescoping sum: \((16 - 4) + (4 - 1) + (1 - 0.25) = 16 - 0.25 = 15.75 \le 16\).&lt;/li&gt;
      &lt;li&gt;Final bound at \(k = 3\): \(f(x^{(3)}) = 0.125 \le \frac{16}{2(0.5)(3)} = \frac{16}{3} \approx 5.333\) — verified!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Suppose \(f\) is convex and differentiable with \(dom(f) = \mathbb{R}^n\), and \(\nabla f\) is Lipschitz continuous with constant \(L &amp;gt; 0\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\| \nabla f(x) - \nabla f(y) \|_2 \le L \| x - y \|_2\) for any \(x, y\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reference: [&lt;a href=&quot;https://en.wikipedia.org/wiki/Lipschitz_continuity&quot;&gt;Wikipedia: Lipschitz continuity&lt;/a&gt;]&lt;/p&gt;

&lt;h2 id=&quot;convergence-theorem&quot;&gt;Convergence Theorem&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Gradient descent&lt;/strong&gt; with fixed step size \(t \le 1/L\) satisfies:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(x^{(k)}) - f^* \le  \frac{ \| x^{(0)} - x^* \|^2_2 }{2tk}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;With fixed step size, the convergence rate is \(O(1/k)\). To achieve \(f(x^{(k)}) - f^* \le \epsilon\), \(O(1/\epsilon)\) iterations are needed.&lt;/p&gt;

&lt;h2 id=&quot;proof&quot;&gt;Proof&lt;/h2&gt;
&lt;p&gt;If \(\nabla f\) is Lipschitz continuous and \(f\) is convex, then \(f\) has a quadratic upper bound (see &lt;a href=&quot;#post-not-found&quot;&gt;06-03-02&lt;/a&gt;).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(y) \le f(x) + \nabla f(x)^T (y-x) + \frac{L}{2} \| y - x \|^2_2 \quad \forall x, y
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;For gradient descent \(x^+ = x - t \nabla f(x)\), substitute \(y = x^+\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(x^+) &amp;amp; \le f(x) - t ( 1 - \frac{Lt}{2} )\| \nabla f(x) \|^2_2 \\\
&amp;amp; \le f(x) -  \frac{t}{2} \| \nabla f(x) \|^2_2 \quad \text{if } t \le 1/L
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Thus, \(f(x^+) &amp;lt; f(x)\) and gradient descent converges.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03-01 Convex function quadratic upper bound</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_01_convex_function_quadratic_upper_bound/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_03_01_convex_function_quadratic_upper_bound</id>
   <content type="html">&lt;p&gt;Every proof in smooth optimization hinges on one deceptively simple picture: if a function’s slope cannot change faster than rate \(L\), then at any point \(x\) you can park an upward-opening parabola of curvature \(L\) right on top of the graph—touching it at \(x\) and staying &lt;em&gt;above&lt;/em&gt; it everywhere else. That parabola is the &lt;strong&gt;Quadratic Upper Bound&lt;/strong&gt; (also called the &lt;em&gt;Descent Lemma&lt;/em&gt;), and minimizing it produces gradient descent with guaranteed progress.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-descent-lemma-and-l-smoothness&quot;&gt;Key ideas: The Descent Lemma and \(L\)-Smoothness&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lipschitz Continuity of the Gradient&lt;/strong&gt;: A differentiable function \(f\) is \(L\)-smooth if \(\|\nabla f(x) - \nabla f(y)\|_2 \le L\|x - y\|_2\) for all \(x, y\). When \(f\) is twice differentiable, this is equivalent to \(\nabla^2 f(x) \preceq L I\) everywhere (eigenvalues capped by \(L\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Fundamental Quadratic Upper Bound&lt;/strong&gt;: Integrating the gradient difference along the line segment from \(x\) to \(y\) yields
\(f(y) \le f(x) + \nabla f(x)^T(y - x) + \frac{L}{2}\|y - x\|_2^2, \quad \forall x, y.\)
Notice that this inequality does &lt;em&gt;not&lt;/em&gt; even require convexity—only \(L\)-smoothness!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;One-Step Guaranteed Descent&lt;/strong&gt;: Plugging the gradient step \(y = x - t\nabla f(x)\) into the upper bound gives
\(f(x^+) \le f(x) - t\left(1 - \frac{Lt}{2}\right)\|\nabla f(x)\|_2^2.\)
Choosing \(t = 1/L\) maximizes the bracket \(t(1 - Lt/2)\) to \(\frac{1}{2L}\), yielding the iconic descent inequality \(f(x^+) \le f(x) - \frac{1}{2L}\|\nabla f(x)\|_2^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Co-coercivity Bonus under Convexity&lt;/strong&gt;: When \(f\) is &lt;em&gt;both&lt;/em&gt; convex and \(L\)-smooth, minimizing the upper bound over \(y\) also implies \(\frac{1}{2L}\|\nabla f(x)\|_2^2 \le f(x) - f^\star\), giving a direct bridge between gradient norms and suboptimality.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-verifying-the-quadratic-upper-bound-for-logistic-loss&quot;&gt;Worked example: Verifying the Quadratic Upper Bound for Logistic Loss&lt;/h3&gt;

&lt;p&gt;Consider the 1D logistic loss \(f(x) = \ln(1 + e^{-x})\). Let us compute its exact \(L\)-smoothness constant and verify the quadratic upper bound numerically at \(x = 0\) and \(y = 2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute first and second derivatives&lt;/strong&gt;:
\(f&apos;(x) = \frac{-e^{-x}}{1 + e^{-x}} = -\sigma(-x), \qquad f&apos;&apos;(x) = \sigma(-x)\bigl(1 - \sigma(-x)\bigr).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find the global Lipschitz constant \(L = \sup_x f&apos;&apos;(x)\)&lt;/strong&gt;:
Since \(p(1 - p) \le \frac{1}{4}\) for all \(p \in (0, 1)\) (attained at \(p = \frac{1}{2}\), i.e., \(x = 0\)), we have \(L = \frac{1}{4} = 0.25\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write the quadratic upper bound centered at \(x = 0\)&lt;/strong&gt;:
At \(x = 0\), \(f(0) = \ln 2 \approx 0.6931\) and \(f&apos;(0) = -0.5\), so
\(Q(y) = \ln 2 - 0.5y + \frac{0.25}{2}y^2 = 0.6931 - 0.5y + 0.125y^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check at \(y = 2\) and check the one-step descent guarantee&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;True value: \(f(2) = \ln(1 + e^{-2}) \approx \ln(1.1353) \approx 0.1269\).&lt;/li&gt;
      &lt;li&gt;Upper bound: \(Q(2) = 0.6931 - 1.0 + 0.5 = 0.1931 \ge 0.1269\) (strictly above \(f(2)\)!).&lt;/li&gt;
      &lt;li&gt;With \(t = 1/L = 4\), the step from \(x = 0\) lands at \(x^+ = 0 - 4(-0.5) = 2\), achieving an actual drop of \(0.6931 - 0.1269 = 0.5662\), comfortably exceeding the guaranteed drop \(\frac{1}{2L}\|f&apos;(0)\|^2 = \frac{1}{0.5}(0.25) = 0.5000\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;quadratic upper bound&lt;/strong&gt; is a fundamental property of smooth convex functions that provides a crucial tool for analyzing and designing optimization algorithms. This property establishes that any smooth convex function can be bounded above by a quadratic function, which has important implications for convergence analysis of gradient-based methods.&lt;/p&gt;

&lt;h2 id=&quot;motivation&quot;&gt;Motivation&lt;/h2&gt;

&lt;p&gt;Why do we care about quadratic upper bounds?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Algorithm Design&lt;/strong&gt;: Many optimization algorithms (like gradient descent) rely on local approximations of the objective function. The quadratic upper bound provides a systematic way to construct these approximations.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Convergence Analysis&lt;/strong&gt;: The quadratic upper bound allows us to prove convergence rates for optimization algorithms by bounding how much the function can change.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Step Size Selection&lt;/strong&gt;: The Lipschitz constant \(L\) in the bound directly determines safe step sizes for gradient descent.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;quadratic-upper-bound-property&quot;&gt;Quadratic Upper Bound Property&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem&lt;/strong&gt;: If \(f\) is convex and \(\nabla f\) is Lipschitz continuous with constant \(L\), then \(f\) satisfies the quadratic upper bound:&lt;/p&gt;

  &lt;blockquote&gt;
\[\begin{align}
f(y) &amp;amp; \le f(x) + \nabla f(x)^T (y-x) + \frac{L}{2} \| y - x \|^2_2 \quad \forall x, y
\end{align}\]
  &lt;/blockquote&gt;
&lt;/div&gt;

&lt;h3 id=&quot;geometric-interpretation&quot;&gt;Geometric Interpretation&lt;/h3&gt;

&lt;p&gt;This inequality states that:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The &lt;strong&gt;linear approximation&lt;/strong&gt; \(f(x) + \nabla f(x)^T (y-x)\) (first-order Taylor expansion) underestimates \(f(y)\) due to convexity&lt;/li&gt;
  &lt;li&gt;The &lt;strong&gt;quadratic upper bound&lt;/strong&gt; \(f(x) + \nabla f(x)^T (y-x) + \frac{L}{2} \| y - x \|^2_2\) overestimates \(f(y)\)&lt;/li&gt;
  &lt;li&gt;The function \(f(y)\) is “sandwiched” between these two bounds&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;equivalent-characterization&quot;&gt;Equivalent Characterization&lt;/h3&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Corollary&lt;/strong&gt;: For any smooth convex function \(f\), the following function is convex:&lt;/p&gt;

  &lt;blockquote&gt;
\[\begin{align}
g(x) &amp;amp; = \frac{L}{2} \| x \|^2_2 - f(x) \quad \text{where } dom(g) = dom(f)
\end{align}\]
  &lt;/blockquote&gt;
&lt;/div&gt;

&lt;p&gt;This means that \(f(x)\) can be written as the difference between a quadratic function and a convex function.&lt;/p&gt;

&lt;h2 id=&quot;proof&quot;&gt;Proof&lt;/h2&gt;

&lt;p&gt;We will prove both the quadratic upper bound and the equivalent characterization. The proof relies on two key properties of smooth convex functions.&lt;/p&gt;

&lt;h3 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Monotone Operator)&lt;/strong&gt;: In vector space \(X\), an operator \(T : X \to X^*\) is monotone if:&lt;/p&gt;
  &lt;blockquote&gt;
\[(Tu - Tv, u-v) \ge 0, \quad \forall u, v \in X\]
  &lt;/blockquote&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Property 1 (Monotonicity of Gradient)&lt;/strong&gt;: If \(f\) is convex and differentiable, then \(\nabla f\) is a monotone operator:&lt;/p&gt;
&lt;blockquote&gt;
\[(\nabla f(y) - \nabla f(x))^T (y-x) \ge 0, \quad \forall x, y\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Property 2 (Lipschitz Continuity)&lt;/strong&gt;: \(\nabla f\) is Lipschitz continuous with constant \(L\):&lt;/p&gt;
&lt;blockquote&gt;
\[\| \nabla f(x) - \nabla f(y) \|_2 \le L \| x - y \|_2, \quad \forall x, y\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;proof-of-quadratic-upper-bound&quot;&gt;Proof of Quadratic Upper Bound&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Consider the function \(h(t) = f(x + t(y-x))\) for \(t \in [0,1]\). By the fundamental theorem of calculus:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
f(y) - f(x) &amp;amp;= h(1) - h(0) = \int_0^1 h&apos;(t) dt \\
&amp;amp;= \int_0^1 \nabla f(x + t(y-x))^T (y-x) dt
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: We can rewrite this as:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) - f(x) &amp;amp;= \nabla f(x)^T (y-x) + \int_0^1 [\nabla f(x + t(y-x)) - \nabla f(x)]^T (y-x) dt
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Using the Cauchy-Schwarz inequality and Lipschitz continuity:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;[\nabla f(x + t(y-x)) - \nabla f(x)]^T (y-x) \\
&amp;amp;\le \|\nabla f(x + t(y-x)) - \nabla f(x)\| \cdot \|y-x\| \\
&amp;amp;\le L \cdot t\|y-x\| \cdot \|y-x\| = Lt\|y-x\|^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Integrating over \(t \in [0,1]\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
f(y) - f(x) &amp;amp;\le \nabla f(x)^T (y-x) + \int_0^1 Lt\|y-x\|^2 dt \\
&amp;amp;= \nabla f(x)^T (y-x) + L\|y-x\|^2 \int_0^1 t dt \\
&amp;amp;= \nabla f(x)^T (y-x) + \frac{L}{2}\|y-x\|^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore: \(f(y) \le f(x) + \nabla f(x)^T (y-x) + \frac{L}{2}\|y-x\|^2\)&lt;/p&gt;

&lt;h3 id=&quot;proof-of-equivalent-characterization&quot;&gt;Proof of Equivalent Characterization&lt;/h3&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem&lt;/strong&gt;: The function \(g(x) = \frac{L}{2} \| x \|^2_2 - f(x)\) is convex.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Proof&lt;/strong&gt;: We need to show that \(\nabla^2 g(x) \succeq 0\) (positive semidefinite).&lt;/p&gt;

&lt;p&gt;Since \(g(x) = \frac{L}{2} \| x \|^2_2 - f(x)\), we have:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\nabla g(x) = Lx - \nabla f(x)\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla^2 g(x) = LI - \nabla^2 f(x)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For any vector \(v\), we need to show \(v^T \nabla^2 g(x) v \ge 0\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
v^T \nabla^2 g(x) v &amp;amp;= v^T (LI - \nabla^2 f(x)) v \\
&amp;amp;= L\|v\|^2 - v^T \nabla^2 f(x) v
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;From the Lipschitz continuity of \(\nabla f\), we can show that \(\nabla^2 f(x) \preceq LI\), which means:
\(v^T \nabla^2 f(x) v \le L\|v\|^2\)&lt;/p&gt;

&lt;p&gt;Therefore: \(v^T \nabla^2 g(x) v = L\|v\|^2 - v^T \nabla^2 f(x) v \ge 0\)&lt;/p&gt;

&lt;p&gt;This proves that \(g\) is convex. \(\square\)&lt;/p&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;h3 id=&quot;example-1-quadratic-function&quot;&gt;Example 1: Quadratic Function&lt;/h3&gt;

&lt;p&gt;Consider \(f(x) = \frac{1}{2}x^T A x + b^T x + c\) where \(A \succeq 0\) (positive semidefinite).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[\nabla f(x) = Ax + b\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla^2 f(x) = A\]
  &lt;/li&gt;
  &lt;li&gt;If \(\lambda_{max}(A) = L\), then \(\|\nabla f(x) - \nabla f(y)\| = \|A(x-y)\| \le L\|x-y\|\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The quadratic upper bound becomes:
\(f(y) \le f(x) + (Ax + b)^T(y-x) + \frac{L}{2}\|y-x\|^2\)&lt;/p&gt;

&lt;p&gt;For quadratic functions, this bound is &lt;strong&gt;tight&lt;/strong&gt; when \(L = \lambda_{max}(A)\).&lt;/p&gt;

&lt;h3 id=&quot;example-2-logistic-loss&quot;&gt;Example 2: Logistic Loss&lt;/h3&gt;

&lt;p&gt;Consider the logistic loss \(f(x) = \log(1 + e^{a^T x})\) where \(a \in \mathbb{R}^n\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[\nabla f(x) = \frac{e^{a^T x}}{1 + e^{a^T x}} a = \sigma(a^T x) a\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla^2 f(x) = \sigma(a^T x)(1 - \sigma(a^T x)) aa^T\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since \(\sigma(t)(1-\sigma(t)) \le \frac{1}{4}\) for all \(t\), we have:
\(\nabla^2 f(x) \preceq \frac{1}{4} aa^T \preceq \frac{\|a\|^2}{4} I\)&lt;/p&gt;

&lt;p&gt;Therefore, \(L = \frac{\|a\|^2}{4}\) and the quadratic upper bound is:
\(f(y) \le f(x) + \sigma(a^T x) a^T(y-x) + \frac{\|a\|^2}{8}\|y-x\|^2\)&lt;/p&gt;

&lt;h3 id=&quot;example-3-least-squares&quot;&gt;Example 3: Least Squares&lt;/h3&gt;

&lt;p&gt;For \(f(x) = \frac{1}{2}\|Ax - b\|^2\) where \(A \in \mathbb{R}^{m \times n}\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[\nabla f(x) = A^T(Ax - b)\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla^2 f(x) = A^T A\]
  &lt;/li&gt;
  &lt;li&gt;\(L = \lambda_{max}(A^T A) = \sigma_{max}^2(A)\) (largest singular value squared)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The quadratic upper bound is:
\(f(y) \le f(x) + (A^T(Ax - b))^T(y-x) + \frac{\sigma_{max}^2(A)}{2}\|y-x\|^2\)&lt;/p&gt;

&lt;h2 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h2&gt;

&lt;h3 id=&quot;1-gradient-descent-step-size&quot;&gt;1. Gradient Descent Step Size&lt;/h3&gt;

&lt;p&gt;The quadratic upper bound directly determines the &lt;strong&gt;maximum safe step size&lt;/strong&gt; for gradient descent. If we use step size \(\alpha \le \frac{1}{L}\), then:&lt;/p&gt;

\[f(x - \alpha \nabla f(x)) \le f(x) - \alpha \|\nabla f(x)\|^2 + \frac{L\alpha^2}{2}\|\nabla f(x)\|^2\]

&lt;p&gt;When \(\alpha \le \frac{1}{L}\), the right-hand side simplifies to:
\(f(x - \alpha \nabla f(x)) \le f(x) - \frac{\alpha}{2}\|\nabla f(x)\|^2\)&lt;/p&gt;

&lt;p&gt;This guarantees &lt;strong&gt;sufficient decrease&lt;/strong&gt; at each iteration.&lt;/p&gt;

&lt;h3 id=&quot;2-convergence-rate-analysis&quot;&gt;2. Convergence Rate Analysis&lt;/h3&gt;

&lt;p&gt;For gradient descent with step size \(\alpha = \frac{1}{L}\), the quadratic upper bound enables us to prove:&lt;/p&gt;

\[f(x_{k+1}) - f^* \le \left(1 - \frac{\mu}{L}\right)(f(x_k) - f^*)\]

&lt;p&gt;where \(\mu\) is the strong convexity parameter. This gives &lt;strong&gt;linear convergence&lt;/strong&gt; with rate \(\left(1 - \frac{\mu}{L}\right)\).&lt;/p&gt;

&lt;h3 id=&quot;3-proximal-gradient-methods&quot;&gt;3. Proximal Gradient Methods&lt;/h3&gt;

&lt;p&gt;In composite optimization \(\min_x f(x) + g(x)\) where \(f\) is smooth and \(g\) is non-smooth, the quadratic upper bound of \(f\) leads to the proximal gradient update:&lt;/p&gt;

\[x_{k+1} = \text{prox}_{\alpha g}\left(x_k - \alpha \nabla f(x_k)\right)\]

&lt;p&gt;where \(\alpha \le \frac{1}{L}\) ensures convergence.&lt;/p&gt;

&lt;h3 id=&quot;4-accelerated-methods&quot;&gt;4. Accelerated Methods&lt;/h3&gt;

&lt;p&gt;Advanced methods like &lt;strong&gt;Nesterov’s accelerated gradient&lt;/strong&gt; and &lt;strong&gt;FISTA&lt;/strong&gt; also rely on the quadratic upper bound to achieve optimal \(O(1/k^2)\) convergence rates for smooth convex functions.&lt;/p&gt;

&lt;h2 id=&quot;key-takeaways&quot;&gt;Key Takeaways&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Fundamental Property&lt;/strong&gt;: The quadratic upper bound is a cornerstone of smooth convex optimization theory.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Algorithm Design&lt;/strong&gt;: It provides the theoretical foundation for choosing step sizes in gradient-based methods.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Convergence Analysis&lt;/strong&gt;: It enables rigorous proofs of convergence rates for optimization algorithms.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Practical Impact&lt;/strong&gt;: Understanding \(L\) helps practitioners tune algorithms effectively.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Geometric Intuition&lt;/strong&gt;: It formalizes the idea that smooth convex functions don’t “curve too much” - they’re bounded above by parabolas.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;interactive-visualization&quot;&gt;Interactive Visualization&lt;/h2&gt;

&lt;p&gt;The following diagram illustrates the quadratic upper bound property:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;      f(y)
        |
        |     Quadratic Upper Bound
        |    f(x) + ∇f(x)ᵀ(y-x) + (L/2)||y-x||²
        |   /
        |  /
        | /     True function f(y)
        |/     /
       /|     /
      / |    /
     /  |   /    Linear Approximation
    /   |  /     f(x) + ∇f(x)ᵀ(y-x)
   /    | /
  /     |/
 /      x        y
/       |         →
        |
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Key Observations&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The &lt;strong&gt;linear approximation&lt;/strong&gt; (tangent line) lies below \(f(y)\) due to convexity&lt;/li&gt;
  &lt;li&gt;The &lt;strong&gt;quadratic upper bound&lt;/strong&gt; lies above \(f(y)\)&lt;/li&gt;
  &lt;li&gt;The &lt;strong&gt;true function&lt;/strong&gt; \(f(y)\) is sandwiched between these bounds&lt;/li&gt;
  &lt;li&gt;The gap between bounds depends on \(L\) (Lipschitz constant) and \(\|y-x\|^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;computational-considerations&quot;&gt;Computational Considerations&lt;/h2&gt;

&lt;h3 id=&quot;estimating-the-lipschitz-constant&quot;&gt;Estimating the Lipschitz Constant&lt;/h3&gt;

&lt;p&gt;In practice, finding the exact Lipschitz constant \(L\) can be challenging. Common approaches:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical Analysis&lt;/strong&gt;: For specific function classes (quadratic, logistic, etc.)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Spectral Methods&lt;/strong&gt;: \(L = \lambda_{max}(\nabla^2 f)\) when Hessian is available&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive Methods&lt;/strong&gt;: Start with estimate and adjust based on sufficient decrease condition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Line Search&lt;/strong&gt;: Use backtracking to find appropriate step sizes&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;practical-algorithm-implementation&quot;&gt;Practical Algorithm Implementation&lt;/h3&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gradient_descent_with_lipschitz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grad_f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L_estimate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;
    Gradient descent with adaptive Lipschitz constant estimation
    &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L_estimate&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;grad_f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;c1&quot;&gt;# Try step with current L estimate
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x_new&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;
        
        &lt;span class=&quot;c1&quot;&gt;# Check sufficient decrease condition
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x_new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x_new&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Accept step
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Increase L estimate and retry
&lt;/span&gt;            &lt;span class=&quot;k&quot;&gt;continue&lt;/span&gt;
            
        &lt;span class=&quot;c1&quot;&gt;# Optional: decrease L if step was very conservative
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.9&lt;/span&gt;
            
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This adaptive approach ensures convergence while automatically tuning the Lipschitz constant estimate.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-02 How to choose step sizes</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_02_how_to_choose_step_sizes/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_02_how_to_choose_step_sizes</id>
   <content type="html">&lt;p&gt;Giving an optimizer the steepest-descent direction without a good step-size rule is like handing a driver a steering wheel with no gas pedal or brake. Step too small and your run burns hours making microscopic progress; step too big and the iterates rocket out of the valley. Section 06-02 compares the three classical step-size strategies—fixed step sizes, backtracking line search, and exact line search—so you know when each one wins.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-three-classical-step-size-paradigms&quot;&gt;Key ideas: Three Classical Step-Size Paradigms&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fixed Step Size (\(t_k = t\))&lt;/strong&gt;: Zero extra function evaluations per iteration and trivial to implement, provided you know (or can bound) the global smoothness constant \(L\) so that \(t \le 1/L\). Fails or crawls when curvature varies wildly across the domain.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Backtracking (Armijo) Line Search&lt;/strong&gt;: Starts each iteration with an optimistic step \(t = 1\) and shrinks \(t \leftarrow \beta t\) (with \(\beta \in (0, 1)\)) until the sufficient-decrease test \(f(x - t\nabla f(x)) \le f(x) - \alpha t\|\nabla f(x)\|_2^2\) passes. Adapts automatically to &lt;em&gt;local&lt;/em&gt; curvature without ever needing to know \(L\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact Line Search&lt;/strong&gt;: Solves the 1D subproblem \(t_k = \arg\min_{s \ge 0} f(x_k - s\nabla f(x_k))\) at every step. Achieves the steepest single-step drop (and makes consecutive steps orthogonal), but is only economical when the 1D minimization has a closed form—most notably for quadratic objectives.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cost-per-Iteration vs. Iteration-Count Trade-Off&lt;/strong&gt;: Fixed steps have the cheapest iterations; exact line search takes the fewest iterations (on well-behaved quadratics); backtracking hits the practical sweet spot for general smooth convex objectives.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-comparing-all-three-rules-on-one-quadratic-step&quot;&gt;Worked example: Comparing All Three Rules on One Quadratic Step&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = \frac{1}{2}(x_1^2 + 9x_2^2)\) from \(x^{(0)} = (3, 1)\), where \(\nabla f(x^{(0)}) = (3, 9)\) and \(f(x^{(0)}) = \frac{1}{2}(9 + 9) = 9\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fixed step size (\(t = 1/L = 1/9\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)}_{\mathrm{fixed}} = (3, 1) - \frac{1}{9}(3, 9) = (\tfrac{8}{3},\; 0)\).&lt;/li&gt;
      &lt;li&gt;New objective: \(f = \frac{1}{2}\bigl(\tfrac{64}{9} + 0\bigr) = \frac{32}{9} \approx 3.556\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact line search&lt;/strong&gt;: Minimize \(\phi(s) = f(3 - 3s,\; 1 - 9s) = \frac{1}{2}\bigl[(3 - 3s)^2 + 9(1 - 9s)^2\bigr]\).
    &lt;ul&gt;
      &lt;li&gt;Differentiate: \(\phi&apos;(s) = -3(3 - 3s) - 81(1 - 9s) = -90 + 738s = 0 \implies s^\star = \frac{90}{738} = \frac{5}{41} \approx 0.1220\).&lt;/li&gt;
      &lt;li&gt;New point: \(x^{(1)}_{\mathrm{exact}} = (3 - \tfrac{15}{41},\; 1 - \tfrac{45}{41}) = (\tfrac{108}{41},\; -\tfrac{4}{41})\), giving \(f = \frac{1}{2}\cdot\frac{11664 + 144}{1681} = \frac{5904}{1681} \approx 3.512\) (slightly better than fixed \(1/9\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Backtracking line search (\(\alpha = 0.5, \beta = 0.5\), starting from \(t = 1\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Target condition: \(f(x - t\nabla f) \le 9 - 0.5 t (3^2 + 9^2) = 9 - 45t\).&lt;/li&gt;
      &lt;li&gt;\(t = 1\): \(f(0, -8) = 288 &amp;gt; -36\) (reject).&lt;/li&gt;
      &lt;li&gt;\(t = 0.5\): \(f(1.5, -3.5) = 56.25 &amp;gt; -13.5\) (reject).&lt;/li&gt;
      &lt;li&gt;\(t = 0.25\): \(f(2.25, -1.25) = 9.5625 &amp;gt; -2.25\) (reject).&lt;/li&gt;
      &lt;li&gt;\(t = 0.125\): \(f(2.625, -0.125) = 3.5156 \le 9 - 5.625 = 3.375\)? Slightly above (\(3.5156 &amp;gt; 3.375\)), so shrink once more to \(t = 0.0625\): \(f(2.8125, 0.4375) = 4.816 \le 9 - 2.8125 = 6.1875\) (accept!). No knowledge of \(L = 9\) was needed!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When performing gradient descent, the &lt;strong&gt;step size&lt;/strong&gt; determines how the variable \(x\) is updated and affects the speed and success of finding the optimal value. This section introduces three main methods for choosing the step size to help gradient descent find the optimum more quickly:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Fixed step size&lt;/li&gt;
  &lt;li&gt;Backtracking line search&lt;/li&gt;
  &lt;li&gt;Exact line search&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-02-03 Exact line search</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_02_03_exact_line_search/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_02_03_exact_line_search</id>
   <content type="html">&lt;p&gt;If you are walking straight down a canyon trail along \(-\nabla f(x_k)\), the greedily optimal place to stop is the lowest point along that exact straight line—before the trail starts climbing the opposite wall. That is &lt;strong&gt;Exact Line Search&lt;/strong&gt;: at every step, solve the 1D minimization \(s_k = \arg\min_{s \ge 0} f(x_k - s\nabla f(x_k))\). It produces a striking geometric signature—every consecutive step makes a perfect \(90^\circ\) right angle!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-and-closed-forms-of-exact-line-search&quot;&gt;Key ideas: Geometry and Closed Forms of Exact Line Search&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Orthogonality of Consecutive Gradients&lt;/strong&gt;: Setting \(\frac{d}{ds} f(x_k - s\nabla f(x_k)) = -\nabla f(x_k - s\nabla f(x_k))^T \nabla f(x_k) = 0\) shows that \(\nabla f(x_{k+1})^T \nabla f(x_k) = 0\). Geometrically, the search ray stops at the exact point where it is &lt;em&gt;tangent&lt;/em&gt; to a level curve of \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closed-Form Step Size for Quadratics&lt;/strong&gt;: For \(f(x) = \frac{1}{2}x^T Q x - b^T x\) (\(Q \succ 0\)) with gradient \(g_k = Qx_k - b\), differentiating \(\phi(s) = f(x_k - s g_k)\) yields the exact closed-form step:
\(s_k = \frac{g_k^T g_k}{g_k^T Q g_k}.\)
Notice this is the reciprocal of the Rayleigh quotient of \(Q\) along \(g_k\), always lying in \([1/\lambda_{\max}, 1/\lambda_{\min}]\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Exact Line Search Can Still Zig-Zag&lt;/strong&gt;: Because consecutive steps are forced to be orthogonal, on an elongated ellipse (\(\kappa \gg 1\)) exact line search bounces back and forth at \(90^\circ\) angles down the narrow valley—still converging at rate \(\left(\frac{\kappa - 1}{\kappa + 1}\right)^2\) in objective value (Kantorovich inequality).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;When to Use It&lt;/strong&gt;: Exact line search shines for quadratic objectives (where \(s_k = \|g_k\|^2 / g_k^T Q g_k\) costs just one matrix-vector product), whereas for general non-quadratic functions solving the 1D subproblem exactly rarely beats fast Armijo backtracking.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-two-exact-line-search-steps-and-the-90circ-orthogonality-check&quot;&gt;Worked example: Two Exact Line-Search Steps and the \(90^\circ\) Orthogonality Check&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + 4x_2^2)\) starting from \(x^{(0)} = (4, 1)\), where \(Q = \operatorname{diag}(1, 4)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Gradient: \(g_0 = Qx^{(0)} = (4, 4)^T\), with \(f(x^{(0)}) = \frac{1}{2}(16 + 4) = 10\).&lt;/li&gt;
      &lt;li&gt;Exact step size:
\(s_0 = \frac{g_0^T g_0}{g_0^T Q g_0} = \frac{4^2 + 4^2}{1(4^2) + 4(4^2)} = \frac{32}{16 + 64} = \frac{32}{80} = 0.4.\)&lt;/li&gt;
      &lt;li&gt;Update: \(x^{(1)} = (4, 1) - 0.4(4, 4) = (2.4,\; -0.6)\), with \(f(x^{(1)}) = \frac{1}{2}(5.76 + 1.44) = 3.6\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify orthogonality between \(g_0\) and \(g_1\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;New gradient: \(g_1 = Qx^{(1)} = (2.4,\; -2.4)^T\).&lt;/li&gt;
      &lt;li&gt;Dot product: \(g_0^T g_1 = 4(2.4) + 4(-2.4) = 9.6 - 9.6 = 0\) — an exact \(90^\circ\) turn!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Exact step size:
\(s_1 = \frac{2.4^2 + (-2.4)^2}{1(2.4^2) + 4(2.4^2)} = \frac{2}{5} = 0.4.\)&lt;/li&gt;
      &lt;li&gt;Update: \(x^{(2)} = (2.4, -0.6) - 0.4(2.4, -2.4) = (1.44,\; 0.36)\), with \(f(x^{(2)}) = \frac{1}{2}(2.0736 + 0.5184) = 1.296\).&lt;/li&gt;
      &lt;li&gt;Check Kantorovich bound: \(\frac{f(x^{(1)})}{f(x^{(0)})} = \frac{3.6}{10} = 0.36 = \left(\frac{4 - 1}{4 + 1}\right)^2 = \left(\frac{3}{5}\right)^2\) — exact equality with the worst-case bound!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Another way to adapt the step size in gradient descent is &lt;strong&gt;exact line search&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;what-is-exact-line-search&quot;&gt;What is Exact Line Search?&lt;/h3&gt;
&lt;p&gt;In exact line search, we move in the direction of the negative gradient and choose the best possible step size.&lt;/p&gt;

&lt;p&gt;For the following expression, if \(s &amp;gt; 0\), the next step \(x - s \nabla f(x)\) moves away from the current position. By varying \(s\), we find the step size \(t\) that minimizes \(f\):&lt;/p&gt;

&lt;blockquote&gt;
\[t = \arg\min_{s \ge 0} f(x - s \nabla f(x))\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;exact-line-search-algorithm&quot;&gt;Exact Line Search Algorithm&lt;/h2&gt;

&lt;p&gt;The exact line search algorithm can be described as follows:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: At current point \(x^{(k)}\), compute gradient \(\nabla f(x^{(k)})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Define univariate function \(\phi(t) = f(x^{(k)} - t \nabla f(x^{(k)}))\) with \(t \geq 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Find \(t^* = \arg\min_{t \geq 0} \phi(t)\) by solving \(\phi&apos;(t) = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Update \(x^{(k+1)} = x^{(k)} - t^* \nabla f(x^{(k)})\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;concrete-examples&quot;&gt;Concrete Examples&lt;/h2&gt;

&lt;h3 id=&quot;example-1-simple-quadratic-function-easy&quot;&gt;Example 1: Simple Quadratic Function (Easy)&lt;/h3&gt;

&lt;p&gt;Consider the simple objective function:
\(f(x) = \frac{1}{2}x^2 - 3x + 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Compute gradient
\(\nabla f(x) = x - 3\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: At starting point \(x^{(0)} = 0\), we have \(\nabla f(0) = -3\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Define line search function
\(\phi(t) = f(0 - t(-3)) = f(3t) = \frac{1}{2}(3t)^2 - 3(3t) + 2 = \frac{9t^2}{2} - 9t + 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Find minimum by taking derivative
\(\phi&apos;(t) = 9t - 9 = 0 \Rightarrow t^* = 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Update
\(x^{(1)} = 0 - 1 \cdot (-3) = 3\)&lt;/p&gt;

&lt;p&gt;Result: In just one step, we found the optimal solution \(x^* = 3\) (since \(\nabla f(3) = 0\)).&lt;/p&gt;

&lt;h3 id=&quot;example-2-multivariable-quadratic-function-medium&quot;&gt;Example 2: Multivariable Quadratic Function (Medium)&lt;/h3&gt;

&lt;p&gt;Consider the objective function:
\(f(x_1, x_2) = x_1^2 + 2x_2^2 - 2x_1 - 4x_2 + 3\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Compute gradient
\(\nabla f(x_1, x_2) = \begin{pmatrix} 2x_1 - 2 \\ 4x_2 - 4 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: At starting point \(x^{(0)} = (0, 0)\)
\(\nabla f(0, 0) = \begin{pmatrix} -2 \\ -4 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Define line search function
\(x^{(0)} - t \nabla f(x^{(0)}) = \begin{pmatrix} 0 \\ 0 \end{pmatrix} - t \begin{pmatrix} -2 \\ -4 \end{pmatrix} = \begin{pmatrix} 2t \\ 4t \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;\(\phi(t) = f(2t, 4t) = (2t)^2 + 2(4t)^2 - 2(2t) - 4(4t) + 3\)
\(= 4t^2 + 32t^2 - 4t - 16t + 3 = 36t^2 - 20t + 3\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Find minimum
\(\phi&apos;(t) = 72t - 20 = 0 \Rightarrow t^* = \frac{20}{72} = \frac{5}{18}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Update
\(x^{(1)} = \begin{pmatrix} 2 \cdot \frac{5}{18} \\ 4 \cdot \frac{5}{18} \end{pmatrix} = \begin{pmatrix} \frac{5}{9} \\ \frac{10}{9} \end{pmatrix}\)&lt;/p&gt;

&lt;h3 id=&quot;example-3-rosenbrock-function-2d-hard&quot;&gt;Example 3: Rosenbrock Function 2D (Hard)&lt;/h3&gt;

&lt;p&gt;Consider the famous Rosenbrock function:
\(f(x_1, x_2) = 100(x_2 - x_1^2)^2 + (1 - x_1)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Compute gradient
\(\nabla f(x_1, x_2) = \begin{pmatrix} -400x_1(x_2 - x_1^2) - 2(1 - x_1) \\ 200(x_2 - x_1^2) \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: At starting point \(x^{(0)} = (-1, 1)\)
\(\nabla f(-1, 1) = \begin{pmatrix} -400(-1)(1 - 1) - 2(1 - (-1)) \\ 200(1 - 1) \end{pmatrix} = \begin{pmatrix} -4 \\ 0 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Define line search function
\(x^{(0)} - t \nabla f(x^{(0)}) = \begin{pmatrix} -1 \\ 1 \end{pmatrix} - t \begin{pmatrix} -4 \\ 0 \end{pmatrix} = \begin{pmatrix} -1 + 4t \\ 1 \end{pmatrix}\)&lt;/p&gt;

\[\phi(t) = f(-1 + 4t, 1) = 100(1 - (-1 + 4t)^2)^2 + (1 - (-1 + 4t))^2\]

&lt;p&gt;This is a more complex function requiring numerical methods to find the minimum.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analysis&lt;/strong&gt;: With the Rosenbrock function, exact line search becomes complex because:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The function doesn’t have a simple quadratic form&lt;/li&gt;
  &lt;li&gt;Numerical methods like Newton-Raphson are needed to solve \(\phi&apos;(t) = 0\)&lt;/li&gt;
  &lt;li&gt;There may be multiple local stationary points&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example-4-constrained-domain-function-very-hard&quot;&gt;Example 4: Constrained Domain Function (Very Hard)&lt;/h3&gt;

&lt;p&gt;Consider the problem:
\(\min f(x) = x_1^2 + x_2^2 - 2x_1x_2\)
subject to \(x_1, x_2 \geq 0\)&lt;/p&gt;

&lt;p&gt;In this case, exact line search must consider:
\(t^* = \arg\min_{t \geq 0} f(x^{(k)} - t \nabla f(x^{(k)}))\)
such that \(x^{(k)} - t \nabla f(x^{(k)}) \geq 0\)&lt;/p&gt;

&lt;p&gt;This leads to a more complex constrained optimization problem.&lt;/p&gt;

&lt;h2 id=&quot;advantages-and-disadvantages&quot;&gt;Advantages and Disadvantages&lt;/h2&gt;

&lt;h3 id=&quot;advantages&quot;&gt;Advantages:&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Theoretically optimal&lt;/strong&gt;: Each step ensures maximum decrease in objective function along gradient direction&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fast convergence&lt;/strong&gt;: For quadratic functions, can converge in one step&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;No parameter tuning&lt;/strong&gt;: No need to choose learning rate&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;disadvantages&quot;&gt;Disadvantages:&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;High computational cost&lt;/strong&gt;: Each step requires solving a univariate optimization problem&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complex for nonlinear functions&lt;/strong&gt;: Requires numerical methods to find minimum&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Impractical for large problems&lt;/strong&gt;: Computation time becomes prohibitive&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;when-to-use-exact-line-search&quot;&gt;When to Use Exact Line Search?&lt;/h2&gt;

&lt;p&gt;Exact line search is suitable when:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Simple objective functions&lt;/strong&gt; (e.g., quadratic)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Small dimensions&lt;/strong&gt; (typically ≤ 10 variables)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High accuracy required&lt;/strong&gt; and computational cost is acceptable&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Special structure&lt;/strong&gt; in objective function allows analytical solution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In practice, &lt;strong&gt;backtracking line search&lt;/strong&gt; is more efficient and commonly used for most applications.&lt;/p&gt;

&lt;h3 id=&quot;backtracking-and-exact-line-search-in-about-3-minutes&quot;&gt;Backtracking and exact line search in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/line-search_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Fixed steps that are too small or too large, the Armijo condition and the shrinks t ← βt, compared with exact search on the lesson’s examples.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-02-02 Backtracking line search</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_02_02_backtracking_line_search/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_02_02_backtracking_line_search</id>
   <content type="html">&lt;p&gt;In real-world optimization, you almost never know the global Lipschitz constant \(L\) in advance—and even when you do, \(L\) reflects the &lt;em&gt;worst&lt;/em&gt; curvature anywhere in \(\mathbb{R}^n\), forcing tiny steps even across flat plateaus. Backtracking line search (Armijo’s rule) solves both problems in five lines of code: try a bold step first, check if the objective dropped by a fair fraction of the linear prediction, and geometrically shrink the step until it passes.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-inside-armijo-backtracking-line-search&quot;&gt;Key ideas: Inside Armijo Backtracking Line Search&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;The Sufficient-Decrease (Armijo) Condition&lt;/strong&gt;: Given parameters \(\alpha \in (0, 0.5]\) and \(\beta \in (0, 1)\), we accept step size \(t\) when
\(f(x - t\nabla f(x)) \le f(x) - \alpha t \|\nabla f(x)\|_2^2.\)
Geometrically, the point \((t, f(x - t\nabla f(x)))\) must lie below a shallower secant line of slope \(-\alpha\|\nabla f(x)\|_2^2\) drawn from \((0, f(x))\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Simply Requiring \(f(x^+) &amp;lt; f(x)\) Fails&lt;/strong&gt;: Merely demanding strict decrease allows tiny steps that stall far from the minimum (or huge steps that barely drop \(f\)). The \(\alpha t\|\nabla f(x)\|_2^2\) margin guarantees progress proportional to both the step size and the squared gradient norm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Guaranteed Finite Termination&lt;/strong&gt;: Because \(f(x - t\nabla f(x)) \le f(x) - t(1 - \frac{Lt}{2})\|\nabla f(x)\|_2^2\) for \(L\)-smooth functions, any \(t \le \frac{2(1-\alpha)}{L}\) (in particular \(t \le 1/L\) when \(\alpha \le 0.5\)) automatically satisfies Armijo! Hence backtracking stops with \(t \ge \min(t_0, \beta/L)\) in at most \(O(\log(L))\) evaluations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Typical Hyperparameter Choices&lt;/strong&gt;: In practice, \(\alpha \in [0.01, 0.3]\) (very permissive so large steps are accepted) and \(\beta \in [0.5, 0.8]\) (halving or gently shrinking \(t\)) work reliably across convex and smooth nonconvex objectives.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-tracing-every-backtracking-trial-on-fx--x4---4x&quot;&gt;Worked example: Tracing Every Backtracking Trial on \(f(x) = x^4 - 4x\)&lt;/h3&gt;

&lt;p&gt;Run one iteration of Armijo backtracking on \(f(x) = x^4 - 4x\) starting at \(x = 0\), with initial step \(t = 1\), \(\alpha = 0.25\), and \(\beta = 0.5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate \(f(x)\) and \(f&apos;(x)\) at \(x = 0\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(f(0) = 0\), and \(f&apos;(x) = 4x^3 - 4 \implies f&apos;(0) = -4\).&lt;/li&gt;
      &lt;li&gt;Descent direction is \(-f&apos;(0) = +4\), and \(\|f&apos;(0)\|_2^2 = 16\).&lt;/li&gt;
      &lt;li&gt;Armijo threshold for any candidate \(t\):
\(f(0 + 4t) \le 0 - 0.25 \cdot t \cdot 16 = -4t.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trial 1 (\(t = 1\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Candidate point: \(x_{\mathrm{try}} = 4\), where \(f(4) = 4^4 - 4(4) = 256 - 16 = 240\).&lt;/li&gt;
      &lt;li&gt;Threshold: \(-4(1) = -4\). Since \(240 &amp;gt; -4\), &lt;strong&gt;reject&lt;/strong&gt; and shrink \(t \leftarrow 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trial 2 (\(t = 0.5\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Candidate point: \(x_{\mathrm{try}} = 2\), where \(f(2) = 16 - 8 = 8\).&lt;/li&gt;
      &lt;li&gt;Threshold: \(-4(0.5) = -2\). Since \(8 &amp;gt; -2\), &lt;strong&gt;reject&lt;/strong&gt; and shrink \(t \leftarrow 0.25\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trial 3 (\(t = 0.25\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Candidate point: \(x_{\mathrm{try}} = 1\), where \(f(1) = 1 - 4 = -3\).&lt;/li&gt;
      &lt;li&gt;Threshold: \(-4(0.25) = -1\). Since \(-3 \le -1\), &lt;strong&gt;ACCEPT!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;Notice \(x = 1\) happens to be the exact global minimizer of \(x^4 - 4x\) (where \(f&apos;(1) = 0\)), reached in one adaptive iteration without ever knowing a global Lipschitz constant!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;introduction-the-step-size-problem&quot;&gt;Introduction: The Step Size Problem&lt;/h2&gt;

&lt;p&gt;In gradient descent, we use the update rule:
\(x_{k+1} = x_k - t_k \nabla f(x_k)\)&lt;/p&gt;

&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(x_k\) is our current position at iteration \(k\)&lt;/li&gt;
  &lt;li&gt;\(\nabla f(x_k)\) is the gradient (tells us the direction of steepest ascent)&lt;/li&gt;
  &lt;li&gt;\(t_k &amp;gt; 0\) is the &lt;strong&gt;step size&lt;/strong&gt; (how far we move in that direction)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;why-do-we-need-adaptive-step-sizes&quot;&gt;Why Do We Need Adaptive Step Sizes?&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The Problem with Fixed Step Sizes:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;If \(t_k\) is too small → we make slow progress (many tiny steps)&lt;/li&gt;
  &lt;li&gt;If \(t_k\) is too large → we might overshoot the minimum or even diverge&lt;/li&gt;
  &lt;li&gt;A fixed step size can’t adapt to different regions of the function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Solution:&lt;/strong&gt; Use an &lt;strong&gt;adaptive step size&lt;/strong&gt; that automatically adjusts based on the function’s behavior. One of the most popular methods is &lt;strong&gt;backtracking line search&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;what-is-backtracking-line-search&quot;&gt;What is Backtracking Line Search?&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Core Idea:&lt;/strong&gt; Start with a large step size and progressively make it smaller until we find a “good enough” step.&lt;/p&gt;

&lt;p&gt;Think of it like this:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Try a big step&lt;/strong&gt; - Maybe we can make fast progress!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check if it’s too big&lt;/strong&gt; - Did we overshoot or not improve enough?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;If yes, backtrack&lt;/strong&gt; - Make the step smaller and try again&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Repeat until satisfied&lt;/strong&gt; - Stop when we find an acceptable step&lt;/li&gt;
&lt;/ol&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_02_02_Backtracking_Line_Search.png&quot; alt=&quot;backtrackinglinesearch1&quot; width=&quot;100%&quot; height=&quot;100%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Backtracking Line Search: The red line shows the &quot;acceptance threshold&quot; - if our function value (blue curve) goes below this line, we accept the step size [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;the-mathematical-condition&quot;&gt;The Mathematical Condition&lt;/h3&gt;

&lt;p&gt;We accept a step size \(t\) if it provides &lt;strong&gt;sufficient decrease&lt;/strong&gt; in the function value:&lt;/p&gt;

\[f(x - t \nabla f(x)) \leq f(x) - \alpha t \|\nabla f(x)\|_2^2\]

&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Left side:&lt;/strong&gt; The actual function value after taking the step&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Right side:&lt;/strong&gt; The current function value minus a threshold for “sufficient decrease”&lt;/li&gt;
  &lt;li&gt;\(\alpha \in (0, 0.5]\) is a parameter that controls how much decrease we require (typically \(\alpha = 0.5\))&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Intuition:&lt;/strong&gt; The right side represents a linear approximation of how much the function &lt;em&gt;should&lt;/em&gt; decrease. If the actual decrease (left side) is at least this much, we accept the step.&lt;/p&gt;

&lt;h2 id=&quot;the-backtracking-line-search-algorithm&quot;&gt;The Backtracking Line Search Algorithm&lt;/h2&gt;

&lt;h3 id=&quot;parameters&quot;&gt;Parameters&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;\(\alpha \in (0, 0.5]\): Controls how much decrease we require (typically \(\alpha = 0.5\))&lt;/li&gt;
  &lt;li&gt;\(\beta \in (0, 1)\): Controls how much we shrink the step size when backtracking (typically \(\beta = 0.8\) or \(\beta = 0.9\))&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;algorithm-steps&quot;&gt;Algorithm Steps&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt; Current point \(x\), gradient \(\nabla f(x)\)
&lt;strong&gt;Output:&lt;/strong&gt; Good step size \(t\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Initialize:&lt;/strong&gt; Set \(t = 1\) (start with a full step)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Check the condition:&lt;/strong&gt; While the sufficient decrease condition is NOT satisfied:
\(f(x - t \nabla f(x)) &amp;gt; f(x) - \alpha t \|\nabla f(x)\|_2^2\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Backtrack:&lt;/strong&gt; Set \(t = \beta \cdot t\) (shrink the step size)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Use the final \(t\) to update: \(x^+ = x - t \nabla f(x)\)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;step-by-step-example&quot;&gt;Step-by-Step Example&lt;/h3&gt;

&lt;p&gt;Let’s say we’re at point \(x\) with gradient \(\nabla f(x)\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Try \(t = 1\):&lt;/strong&gt; Check if \(f(x - 1 \cdot \nabla f(x)) \leq f(x) - \alpha \|\nabla f(x)\|_2^2\)
    &lt;ul&gt;
      &lt;li&gt;If YES → Accept \(t = 1\)&lt;/li&gt;
      &lt;li&gt;If NO → Continue to step 2&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Try \(t = 0.8\):&lt;/strong&gt; Check if \(f(x - 0.8 \nabla f(x)) \leq f(x) - 0.8\alpha \|\nabla f(x)\|_2^2\)
    &lt;ul&gt;
      &lt;li&gt;If YES → Accept \(t = 0.8\)&lt;/li&gt;
      &lt;li&gt;If NO → Continue to step 3&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Try \(t = 0.64\):&lt;/strong&gt; Check if \(f(x - 0.64 \nabla f(x)) \leq f(x) - 0.64\alpha \|\nabla f(x)\|_2^2\)
    &lt;ul&gt;
      &lt;li&gt;And so on…&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;why-does-this-work-the-mathematical-intuition&quot;&gt;Why Does This Work? The Mathematical Intuition&lt;/h2&gt;

&lt;h3 id=&quot;the-sufficient-decrease-condition-explained&quot;&gt;The Sufficient Decrease Condition Explained&lt;/h3&gt;

&lt;p&gt;The condition \(f(x - t \nabla f(x)) \leq f(x) - \alpha t \|\nabla f(x)\|_2^2\) can be understood as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Left side:&lt;/strong&gt; \(f(x - t \nabla f(x))\) = The actual function value after taking the step&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Right side:&lt;/strong&gt; \(f(x) - \alpha t \|\nabla f(x)\|_2^2\) = Current value minus expected decrease&lt;/p&gt;

&lt;p&gt;The expected decrease \(\alpha t \|\nabla f(x)\|_2^2\) comes from the &lt;strong&gt;linear approximation&lt;/strong&gt;:
\(f(x - t \nabla f(x)) \approx f(x) - t \|\nabla f(x)\|_2^2\)&lt;/p&gt;

&lt;p&gt;We require the actual decrease to be at least a fraction \(\alpha\) of this predicted decrease.&lt;/p&gt;

&lt;h3 id=&quot;why-this-guarantees-progress&quot;&gt;Why This Guarantees Progress&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Prevents tiny steps:&lt;/strong&gt; The condition ensures we don’t accept arbitrarily small step sizes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Prevents overshooting:&lt;/strong&gt; If we overshoot, the function value won’t decrease enough&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Balances speed and stability:&lt;/strong&gt; We get reasonably large steps while maintaining convergence&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;performance-comparison&quot;&gt;Performance Comparison&lt;/h3&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_02_02_Convergence.png&quot; alt=&quot;backtrackinglinesearch1&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Convergence comparison: Backtracking line search (adaptive) vs Fixed step size. Notice how the adaptive method converges much faster! [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;practical-example-minimizing-a-quadratic-function&quot;&gt;Practical Example: Minimizing a Quadratic Function&lt;/h2&gt;

&lt;p&gt;Let’s work through a detailed example to see backtracking line search in action!&lt;/p&gt;

&lt;h3 id=&quot;example-1-simple-quadratic-lucky-case&quot;&gt;Example 1: Simple Quadratic (Lucky Case)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Minimize \(f(x) = \frac{1}{2}x^2\) starting from \(x_0 = 4\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Parameters: \(\alpha = 0.5\), \(\beta = 0.8\)&lt;/li&gt;
  &lt;li&gt;Gradient: \(\nabla f(x) = x\)&lt;/li&gt;
  &lt;li&gt;Optimal solution: \(x^* = 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Iteration 1:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Current: \(x = 4\), \(\nabla f(x) = 4\), \(f(x) = 8\)&lt;/li&gt;
  &lt;li&gt;Try \(t = 1\):
    &lt;ul&gt;
      &lt;li&gt;New point: \(x - t\nabla f(x) = 4 - 1 \cdot 4 = 0\)&lt;/li&gt;
      &lt;li&gt;Function value: \(f(0) = 0\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check sufficient decrease:&lt;/strong&gt; \(f(0) \leq f(4) - \alpha t \|\nabla f(4)\|^2\)
    &lt;ul&gt;
      &lt;li&gt;Left side: \(0\)&lt;/li&gt;
      &lt;li&gt;Right side: \(8 - 0.5 \cdot 1 \cdot 16 = 0\)&lt;/li&gt;
      &lt;li&gt;\(0 \leq 0\) ✓ (Accept \(t = 1\))&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Update: \(x_1 = 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; We reached the optimum in one step! This is because the quadratic function is “well-behaved.”&lt;/p&gt;

&lt;h3 id=&quot;example-2-a-non-convex-function&quot;&gt;Example 2: A Non-Convex Function&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Minimize \(f(x) = x^2 + 10\sin(x)\) starting from \(x_0 = 3\)&lt;/p&gt;

&lt;p&gt;This function is not convex. It has a local minimum near \(x \approx 3.84\) and its global minimum near \(x \approx -1.31\). Let’s see what backtracking does here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Parameters: \(\alpha = 0.3\), \(\beta = 0.7\)&lt;/li&gt;
  &lt;li&gt;Gradient: \(\nabla f(x) = 2x + 10\cos(x)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Iteration 1:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Current: \(x = 3\), \(\nabla f(3) = 6 + 10\cos(3) \approx -3.900\), \(\vert\nabla f(3)\vert^2 \approx 15.21\), \(f(3) = 9 + 10\sin(3) \approx 10.41\)&lt;/li&gt;
  &lt;li&gt;The gradient is negative, so the step \(-t\nabla f(x)\) moves to the right.&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Try&lt;/th&gt;
      &lt;th&gt;\(t\)&lt;/th&gt;
      &lt;th&gt;\(x - t\nabla f(x)\)&lt;/th&gt;
      &lt;th&gt;\(f(x - t\nabla f(x))\)&lt;/th&gt;
      &lt;th&gt;\(f(x) - \alpha t \vert\nabla f(x)\vert^2\)&lt;/th&gt;
      &lt;th&gt;Accept?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;6.900&lt;/td&gt;
      &lt;td&gt;53.39&lt;/td&gt;
      &lt;td&gt;5.85&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;0.7&lt;/td&gt;
      &lt;td&gt;5.730&lt;/td&gt;
      &lt;td&gt;27.58&lt;/td&gt;
      &lt;td&gt;7.22&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;0.49&lt;/td&gt;
      &lt;td&gt;4.911&lt;/td&gt;
      &lt;td&gt;14.31&lt;/td&gt;
      &lt;td&gt;8.18&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;0.343&lt;/td&gt;
      &lt;td&gt;4.338&lt;/td&gt;
      &lt;td&gt;9.51&lt;/td&gt;
      &lt;td&gt;8.85&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;0.2401&lt;/td&gt;
      &lt;td&gt;3.936&lt;/td&gt;
      &lt;td&gt;8.36&lt;/td&gt;
      &lt;td&gt;9.32&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;After 4 backtracking steps we accept \(t = 0.2401\) and move to \(x_1 \approx 3.936\), with \(f(x_1) \approx 8.36\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Iteration 2:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Current: \(x_1 \approx 3.936\), \(\nabla f(x_1) \approx 0.868\) (now positive, so we step to the left).&lt;/li&gt;
  &lt;li&gt;The trials \(t = 1, 0.7, 0.49, 0.343, 0.2401, 0.168\) are all rejected. The step \(t = 0.7^6 \approx 0.1176\) is accepted, which gives \(x_2 \approx 3.834\), \(f(x_2) \approx 8.3156\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Next iterations:&lt;/strong&gt; the gradient drops quickly: \(\vert\nabla f(x_3)\vert \approx 3 \times 10^{-4}\) and \(\vert\nabla f(x_4)\vert \approx 3 \times 10^{-6}\). The method converges to \(x \approx 3.8375\) with \(f \approx 8.3156\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; Backtracking always gives a decrease in \(f\), but on a non-convex function it only finds the &lt;strong&gt;local&lt;/strong&gt; minimum near the starting point. The global minimum \(f(-1.3064) \approx -7.946\) is on the other side of a hill, and gradient descent from \(x_0 = 3\) never gets there.&lt;/p&gt;

&lt;h3 id=&quot;example-3-a-smooth-convex-function&quot;&gt;Example 3: A Smooth Convex Function&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Minimize \(f(x) = x^2 + 0.1x^4\) starting from \(x_0 = 2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Parameters: \(\alpha = 0.5\), \(\beta = 0.8\)&lt;/li&gt;
  &lt;li&gt;Gradient: \(\nabla f(x) = 2x + 0.4x^3\)&lt;/li&gt;
  &lt;li&gt;At \(x = 2\): \(\nabla f(2) = 4 + 3.2 = 7.2\), \(\vert\nabla f(2)\vert^2 = 51.84\), \(f(2) = 4 + 1.6 = 5.6\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Iteration 1:&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Try&lt;/th&gt;
      &lt;th&gt;\(t\)&lt;/th&gt;
      &lt;th&gt;\(2 - 7.2\,t\)&lt;/th&gt;
      &lt;th&gt;\(f(2 - 7.2\,t)\)&lt;/th&gt;
      &lt;th&gt;\(5.6 - 0.5 \cdot 51.84\, t\)&lt;/th&gt;
      &lt;th&gt;Accept?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;-5.200&lt;/td&gt;
      &lt;td&gt;100.16&lt;/td&gt;
      &lt;td&gt;-20.32&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;0.8&lt;/td&gt;
      &lt;td&gt;-3.760&lt;/td&gt;
      &lt;td&gt;34.12&lt;/td&gt;
      &lt;td&gt;-15.14&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;0.64&lt;/td&gt;
      &lt;td&gt;-2.608&lt;/td&gt;
      &lt;td&gt;11.43&lt;/td&gt;
      &lt;td&gt;-10.99&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;0.512&lt;/td&gt;
      &lt;td&gt;-1.686&lt;/td&gt;
      &lt;td&gt;3.653&lt;/td&gt;
      &lt;td&gt;-7.671&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;0.4096&lt;/td&gt;
      &lt;td&gt;-0.949&lt;/td&gt;
      &lt;td&gt;0.982&lt;/td&gt;
      &lt;td&gt;-5.017&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;6&lt;/td&gt;
      &lt;td&gt;0.3277&lt;/td&gt;
      &lt;td&gt;-0.359&lt;/td&gt;
      &lt;td&gt;0.131&lt;/td&gt;
      &lt;td&gt;-2.893&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;7&lt;/td&gt;
      &lt;td&gt;0.2621&lt;/td&gt;
      &lt;td&gt;0.113&lt;/td&gt;
      &lt;td&gt;0.0127&lt;/td&gt;
      &lt;td&gt;-1.195&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;8&lt;/td&gt;
      &lt;td&gt;0.2097&lt;/td&gt;
      &lt;td&gt;0.490&lt;/td&gt;
      &lt;td&gt;0.246&lt;/td&gt;
      &lt;td&gt;0.164&lt;/td&gt;
      &lt;td&gt;✗&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;9&lt;/td&gt;
      &lt;td&gt;0.1678&lt;/td&gt;
      &lt;td&gt;0.792&lt;/td&gt;
      &lt;td&gt;0.667&lt;/td&gt;
      &lt;td&gt;1.251&lt;/td&gt;
      &lt;td&gt;✓ &lt;strong&gt;Accept!&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; After 8 backtracking steps, we accept \(t = 0.8^8 \approx 0.168\) and update to \(x_1 \approx 0.792\).&lt;/p&gt;

&lt;p&gt;Note that some rejected steps (for example \(t = 0.2621\), which lands at \(x \approx 0.113\)) give a much smaller \(f\) than the accepted one. They are rejected because the right-hand side is negative there, and \(f \ge 0\) everywhere. With \(\alpha = 0.5\), the condition demands a large decrease, so it only accepts small enough steps.&lt;/p&gt;

&lt;h3 id=&quot;key-insights-from-these-examples&quot;&gt;Key Insights from These Examples&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Simple functions&lt;/strong&gt; (like pure quadratics) may converge in one step&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complex functions&lt;/strong&gt; require multiple backtracking steps to find safe step sizes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The algorithm is robust&lt;/strong&gt; - it automatically finds appropriate step sizes without manual tuning&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Each backtracking iteration&lt;/strong&gt; makes the step size smaller by factor \(\beta\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The sufficient decrease condition&lt;/strong&gt; prevents both overshooting and accepting tiny progress&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;why-this-beats-fixed-step-sizes&quot;&gt;Why This Beats Fixed Step Sizes&lt;/h3&gt;

&lt;p&gt;Let’s see a head-to-head comparison! We’ll minimize \(f(x) = x^2 - 2x + 5\) starting from \(x_0 = 4\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function details:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Gradient: \(\nabla f(x) = 2x - 2\)&lt;/li&gt;
  &lt;li&gt;Optimal solution: \(x^* = 1\) with \(f(x^*) = 4\)&lt;/li&gt;
  &lt;li&gt;Starting point: \(x_0 = 4\), \(f(x_0) = 13\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;comparison-fixed-step-size-vs-backtracking-line-search&quot;&gt;Comparison: Fixed Step Size vs Backtracking Line Search&lt;/h2&gt;

&lt;h3 id=&quot;method-1-fixed-small-step-size-t--01&quot;&gt;Method 1: Fixed Small Step Size (\(t = 0.1\))&lt;/h3&gt;

&lt;p&gt;Here \(x_{k+1} - 1 = 0.8\,(x_k - 1)\), so the error shrinks by only 20% per step.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Iteration&lt;/th&gt;
      &lt;th&gt;\(x_k\)&lt;/th&gt;
      &lt;th&gt;\(\nabla f(x_k)\)&lt;/th&gt;
      &lt;th&gt;\(x_{k+1} = x_k - 0.1 \nabla f(x_k)\)&lt;/th&gt;
      &lt;th&gt;\(f(x_{k+1})\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;4.0&lt;/td&gt;
      &lt;td&gt;6.0&lt;/td&gt;
      &lt;td&gt;3.4&lt;/td&gt;
      &lt;td&gt;9.76&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;3.4&lt;/td&gt;
      &lt;td&gt;4.8&lt;/td&gt;
      &lt;td&gt;2.92&lt;/td&gt;
      &lt;td&gt;7.6864&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;2.92&lt;/td&gt;
      &lt;td&gt;3.84&lt;/td&gt;
      &lt;td&gt;2.536&lt;/td&gt;
      &lt;td&gt;6.359296&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;2.536&lt;/td&gt;
      &lt;td&gt;3.072&lt;/td&gt;
      &lt;td&gt;2.2288&lt;/td&gt;
      &lt;td&gt;5.509949&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;2.2288&lt;/td&gt;
      &lt;td&gt;2.4576&lt;/td&gt;
      &lt;td&gt;1.98304&lt;/td&gt;
      &lt;td&gt;4.966368&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;1.98304&lt;/td&gt;
      &lt;td&gt;1.96608&lt;/td&gt;
      &lt;td&gt;1.786432&lt;/td&gt;
      &lt;td&gt;4.618475&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;…&lt;/td&gt;
      &lt;td&gt;…&lt;/td&gt;
      &lt;td&gt;…&lt;/td&gt;
      &lt;td&gt;…&lt;/td&gt;
      &lt;td&gt;…&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;20&lt;/td&gt;
      &lt;td&gt;1.034588&lt;/td&gt;
      &lt;td&gt;0.069175&lt;/td&gt;
      &lt;td&gt;1.027670&lt;/td&gt;
      &lt;td&gt;4.000766&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;…&lt;/td&gt;
      &lt;td&gt;…&lt;/td&gt;
      &lt;td&gt;…&lt;/td&gt;
      &lt;td&gt;…&lt;/td&gt;
      &lt;td&gt;…&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;50&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;1.000043&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;0.000086&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;1.000034&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;4.000000001&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; It does converge, but slowly: it needs 36 iterations to reach \(\vert x_k - 1\vert &amp;lt; 10^{-3}\) and 67 iterations to reach \(\vert x_k - 1\vert &amp;lt; 10^{-6}\).&lt;/p&gt;

&lt;h3 id=&quot;method-2-fixed-large-step-size-t--15&quot;&gt;Method 2: Fixed Large Step Size (\(t = 1.5\))&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Iteration&lt;/th&gt;
      &lt;th&gt;\(x_k\)&lt;/th&gt;
      &lt;th&gt;\(\nabla f(x_k)\)&lt;/th&gt;
      &lt;th&gt;\(x_{k+1} = x_k - 1.5 \nabla f(x_k)\)&lt;/th&gt;
      &lt;th&gt;\(f(x_{k+1})\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;4.0&lt;/td&gt;
      &lt;td&gt;6.0&lt;/td&gt;
      &lt;td&gt;-5.0&lt;/td&gt;
      &lt;td&gt;40&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;-5.0&lt;/td&gt;
      &lt;td&gt;-12.0&lt;/td&gt;
      &lt;td&gt;13.0&lt;/td&gt;
      &lt;td&gt;148&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;13.0&lt;/td&gt;
      &lt;td&gt;24.0&lt;/td&gt;
      &lt;td&gt;-23.0&lt;/td&gt;
      &lt;td&gt;580&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;-23.0&lt;/td&gt;
      &lt;td&gt;-48.0&lt;/td&gt;
      &lt;td&gt;49.0&lt;/td&gt;
      &lt;td&gt;2308&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;49.0&lt;/td&gt;
      &lt;td&gt;96.0&lt;/td&gt;
      &lt;td&gt;-95.0&lt;/td&gt;
      &lt;td&gt;9220&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; Diverges! Here \(x_{k+1} - 1 = -2\,(x_k - 1)\), so the error doubles and changes sign at every step.&lt;/p&gt;

&lt;h3 id=&quot;method-3-fixed-medium-step-size-t--05&quot;&gt;Method 3: Fixed Medium Step Size (\(t = 0.5\))&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Iteration&lt;/th&gt;
      &lt;th&gt;\(x_k\)&lt;/th&gt;
      &lt;th&gt;\(\nabla f(x_k)\)&lt;/th&gt;
      &lt;th&gt;\(x_{k+1} = x_k - 0.5 \nabla f(x_k)\)&lt;/th&gt;
      &lt;th&gt;\(f(x_{k+1})\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;4.0&lt;/td&gt;
      &lt;td&gt;6.0&lt;/td&gt;
      &lt;td&gt;1.0&lt;/td&gt;
      &lt;td&gt;4.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;1.0&lt;/td&gt;
      &lt;td&gt;0.0&lt;/td&gt;
      &lt;td&gt;1.0&lt;/td&gt;
      &lt;td&gt;4.0&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; Lucky guess! It reaches the optimum in one step, because \(t = 0.5 = 1/f&apos;&apos;(x)\) is exactly the Newton step for this quadratic. For another function, \(t = 0.5\) could be too small or too large.&lt;/p&gt;

&lt;h3 id=&quot;method-4-backtracking-line-search-alpha--05-beta--08&quot;&gt;Method 4: Backtracking Line Search (\(\alpha = 0.5\), \(\beta = 0.8\))&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Iteration 1:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Current: \(x = 4\), \(\nabla f(x) = 6\), \(\vert\nabla f(x)\vert^2 = 36\), \(f(x) = 13\)&lt;/li&gt;
  &lt;li&gt;Try \(t = 1\): \(x - t\nabla f(x) = 4 - 6 = -2\), \(f(-2) = 13\)&lt;/li&gt;
  &lt;li&gt;Check: \(13 \leq 13 - 0.5 \cdot 1 \cdot 36 = -5\) ✗ (Too big!)&lt;/li&gt;
  &lt;li&gt;Try \(t = 0.8\): \(x - t\nabla f(x) = 4 - 4.8 = -0.8\), \(f(-0.8) = 7.24\)&lt;/li&gt;
  &lt;li&gt;Check: \(7.24 \leq 13 - 0.5 \cdot 0.8 \cdot 36 = -1.4\) ✗ (Still too big!)&lt;/li&gt;
  &lt;li&gt;Try \(t = 0.64\): \(x - t\nabla f(x) = 4 - 3.84 = 0.16\), \(f(0.16) = 4.7056\)&lt;/li&gt;
  &lt;li&gt;Check: \(4.7056 \leq 13 - 0.5 \cdot 0.64 \cdot 36 = 1.48\) ✗ (Still too big!)&lt;/li&gt;
  &lt;li&gt;Try \(t = 0.512\): \(x - t\nabla f(x) = 4 - 3.072 = 0.928\), \(f(0.928) = 4.005184\)&lt;/li&gt;
  &lt;li&gt;Check: \(4.005184 \leq 13 - 0.5 \cdot 0.512 \cdot 36 = 3.784\) ✗ (Rejected, even though \(x = 0.928\) is close to the optimum!)&lt;/li&gt;
  &lt;li&gt;Try \(t = 0.4096\): \(x - t\nabla f(x) = 4 - 2.4576 = 1.5424\), \(f(1.5424) \approx 4.2942\)&lt;/li&gt;
  &lt;li&gt;Check: \(4.2942 \leq 13 - 0.5 \cdot 0.4096 \cdot 36 = 5.6272\) ✓ &lt;strong&gt;Accept!&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Update: \(x_1 = 1.5424\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why is \(t = 0.512\) rejected?&lt;/strong&gt; For this function, \(f(x - tg) = f(x) - t g^2 + t^2 g^2\) with \(g = \nabla f(x)\). The condition \(f(x - tg) \leq f(x) - 0.5\, t g^2\) is then the same as \(t \leq 0.5\). So at every iteration, the trials \(1, 0.8, 0.64, 0.512\) are rejected and \(t = 0.4096\) is accepted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Iteration 2:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Current: \(x = 1.5424\), \(\nabla f(x) = 1.0848\), \(f(x) \approx 4.2942\)&lt;/li&gt;
  &lt;li&gt;Again \(t = 1, 0.8, 0.64, 0.512\) are rejected, and \(t = 0.4096\) is accepted.&lt;/li&gt;
  &lt;li&gt;Update: \(x_2 = 1.5424 - 0.4096 \cdot 1.0848 \approx 1.0981\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Next iterations:&lt;/strong&gt; each iteration multiplies the error by \(\vert 1 - 2 \cdot 0.4096\vert = 0.1808\):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Iteration \(k\)&lt;/th&gt;
      &lt;th&gt;1&lt;/th&gt;
      &lt;th&gt;2&lt;/th&gt;
      &lt;th&gt;3&lt;/th&gt;
      &lt;th&gt;4&lt;/th&gt;
      &lt;th&gt;5&lt;/th&gt;
      &lt;th&gt;6&lt;/th&gt;
      &lt;th&gt;7&lt;/th&gt;
      &lt;th&gt;8&lt;/th&gt;
      &lt;th&gt;9&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;\(x_k\)&lt;/td&gt;
      &lt;td&gt;1.5424&lt;/td&gt;
      &lt;td&gt;1.0981&lt;/td&gt;
      &lt;td&gt;1.0177&lt;/td&gt;
      &lt;td&gt;1.0032&lt;/td&gt;
      &lt;td&gt;1.00058&lt;/td&gt;
      &lt;td&gt;1.000105&lt;/td&gt;
      &lt;td&gt;1.000019&lt;/td&gt;
      &lt;td&gt;1.0000034&lt;/td&gt;
      &lt;td&gt;1.0000006&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; Backtracking reaches \(\vert x_k - 1\vert &amp;lt; 10^{-3}\) after 5 iterations and \(\vert x_k - 1\vert &amp;lt; 10^{-6}\) after &lt;strong&gt;9 iterations&lt;/strong&gt;, using 45 function evaluations in total (5 trials per iteration). It needs no tuning, while the fixed step \(t = 0.1\) needs 67 iterations for the same accuracy.&lt;/p&gt;

&lt;h2 id=&quot;performance-summary&quot;&gt;Performance Summary&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Iterations to \(\vert x_k - 1\vert &amp;lt; 10^{-6}\)&lt;/th&gt;
      &lt;th&gt;Comments&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Fixed Small (\(t = 0.1\))&lt;/td&gt;
      &lt;td&gt;67&lt;/td&gt;
      &lt;td&gt;Safe but slow&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Fixed Large (\(t = 1.5\))&lt;/td&gt;
      &lt;td&gt;∞&lt;/td&gt;
      &lt;td&gt;Diverges&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Fixed Medium (\(t = 0.5\))&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;Lucky guess only!&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Backtracking&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;9&lt;/strong&gt; (45 function evaluations)&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Robust, no tuning&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;key-insights&quot;&gt;Key Insights&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fixed small steps:&lt;/strong&gt; Safe but painfully slow&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fixed large steps:&lt;/strong&gt; Fast when they work, catastrophic when they don’t&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fixed “perfect” steps:&lt;/strong&gt; Impossible to find without knowing the answer&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Backtracking:&lt;/strong&gt; Automatically finds good step sizes, robust across different functions&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;the-real-power-robustness-across-functions&quot;&gt;The Real Power: Robustness Across Functions&lt;/h3&gt;

&lt;p&gt;The magic of backtracking line search is that it works well for ANY function:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gentle functions:&lt;/strong&gt; Takes appropriately large steps for fast progress&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Steep functions:&lt;/strong&gt; Automatically reduces step size to prevent overshooting&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Varying functions:&lt;/strong&gt; Adapts step size throughout the optimization process&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unknown functions:&lt;/strong&gt; No need to guess the “right” step size beforehand&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bottom line:&lt;/strong&gt; Backtracking line search gives you the speed of large steps when safe, and the stability of small steps when necessary - automatically!&lt;/p&gt;

&lt;h2 id=&quot;advantages-and-practical-considerations&quot;&gt;Advantages and Practical Considerations&lt;/h2&gt;

&lt;h3 id=&quot;advantages&quot;&gt;Advantages:&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Automatic adaptation:&lt;/strong&gt; No need to manually tune step sizes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence guarantees:&lt;/strong&gt; Theoretical guarantees for convex functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simple implementation:&lt;/strong&gt; Easy to code and understand&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust:&lt;/strong&gt; Works well across different types of problems&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;practical-tips&quot;&gt;Practical Tips:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Typical parameter values:&lt;/strong&gt; \(\alpha = 0.5\), \(\beta = 0.8\) or \(\beta = 0.9\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational cost:&lt;/strong&gt; Each backtracking step requires one function evaluation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;When to use:&lt;/strong&gt; Especially useful when the function’s “landscape” varies significantly&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Backtracking line search&lt;/strong&gt; solves the fundamental problem of choosing good step sizes in gradient descent:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Start optimistic:&lt;/strong&gt; Try a large step size (\(t = 1\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test rigorously:&lt;/strong&gt; Check if the step provides sufficient decrease&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adapt intelligently:&lt;/strong&gt; If not, shrink the step size and try again&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Guarantee progress:&lt;/strong&gt; The mathematical condition ensures we always make meaningful progress&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This simple yet powerful technique transforms gradient descent from a method that requires careful tuning into a robust, adaptive algorithm that works well out of the box.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next time&lt;/strong&gt; you implement gradient descent, consider adding backtracking line search - your algorithm will converge faster and be much more reliable!&lt;/p&gt;

&lt;h3 id=&quot;backtracking-and-exact-line-search-in-about-3-minutes&quot;&gt;Backtracking and exact line search in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/line-search_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Fixed steps that are too small or too large, the Armijo condition and the shrinks t ← βt, compared with exact search on the lesson’s examples.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-02-01 Fixed step size</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_02_01_fixed_step_size/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_02_01_fixed_step_size</id>
   <content type="html">&lt;p&gt;Fixed step-size gradient descent—setting \(t_k = t\) once and never touching it again—is the simplest possible optimizer. Yet that single number \(t\) walks a razor’s edge: nudge it slightly too high and your iterates explode exponentially; set it too low and you watch the loss crawl at a snail’s pace. This lesson pins down the exact mathematical boundary between convergence, oscillation, and divergence.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-stability-and-speed-of-fixed-step-sizes&quot;&gt;Key ideas: Stability and Speed of Fixed Step Sizes&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;The Sufficient-Decrease Guarantee (\(t \le 1/L\))&lt;/strong&gt;: When \(\nabla f\) is \(L\)-Lipschitz, every step with \(t \le 1/L\) guarantees \(f(x_{k+1}) \le f(x_k) - \frac{t}{2}\|\nabla f(x_k)\|_2^2\). Setting \(t = 1/L\) maximizes this worst-case guaranteed single-step drop.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;The Exact Stability Limit (\(t &amp;lt; 2/L\))&lt;/strong&gt;: On a quadratic \(f(x) = \frac{1}{2}x^T Q x\), the error along the steepest eigenvector scales by \((1 - tL)\) per step. For \(1/L &amp;lt; t &amp;lt; 2/L\), the iterates oscillate across the valley but still decay ($$&lt;/td&gt;
          &lt;td&gt;1 - tL&lt;/td&gt;
          &lt;td&gt;&amp;lt; 1\(); at\)t = 2/L\(they bounce forever; for\)t &amp;gt; 2/L$$ they diverge exponentially.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why \(t = 1/L\) Can Still Be Slow&lt;/strong&gt;: On ill-conditioned bowls like \(f(x) = \frac{1}{2}(10x_1^2 + x_2^2)\), the steep coordinate forces \(t \le 0.1\), so the flat coordinate only shrinks by \((1 - 0.1) = 0.9\) per iteration—requiring \(\approx 22\) steps just to cut the flat error by \(10\times\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;When Fixed Step Size Is Preferred&lt;/strong&gt;: Whenever \(L\) is cheap to compute (e.g., \(L = \|X\|_2^2\) in least squares or \(L = \frac{1}{4}\|X\|_2^2\) in logistic regression), fixed \(t = 1/L\) eliminates line-search overhead and is easy to parallelize.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-mapping-all-four-regimes-on-fx--frac1210x_12--x_22&quot;&gt;Worked example: Mapping All Four Regimes on \(f(x) = \frac{1}{2}(10x_1^2 + x_2^2)\)&lt;/h3&gt;

&lt;p&gt;For \(f(x_1, x_2) = \frac{1}{2}(10x_1^2 + x_2^2)\) starting at \(x^{(0)} = (1, 1)\), we have \(\nabla f(x) = (10x_1, x_2)\), so \(L = 10\) and \(m = 1\). Watch the first two iterates under four different fixed step sizes:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Too small (\(t = 0.01 \ll 1/L\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = (0.90, 0.99)\), \(x^{(2)} = (0.81, 0.9801)\). Completely monotone, but \(x_2\) barely moves (1% per step).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Standard safe choice (\(t = 1/L = 0.10\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = (0,\; 0.90)\), \(x^{(2)} = (0,\; 0.81)\). Exact zero along \(x_1\) in one step, steady 10% decay along \(x_2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Oscillatory but convergent (\(t = 0.18 \in (1/L, 2/L)\))&lt;/strong&gt; — close to optimal \(t^\star = \frac{2}{11} \approx 0.1818\):
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = (1 - 1.8,\; 1 - 0.18) = (-0.80,\; 0.82)\), \(x^{(2)} = (0.64,\; 0.6724)\). Despite zig-zagging in \(x_1\), both coordinates shrink by \(\approx 0.82\)—&lt;strong&gt;nearly twice as fast&lt;/strong&gt; as \(t = 0.10\) along the slow axis!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Divergent (\(t = 0.25 &amp;gt; 2/L = 0.20\))&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = (-1.50,\; 0.75)\), \(x^{(2)} = (+2.25,\; 0.5625)\), \(x^{(3)} = (-3.375,\; 0.4219)\). Exponential blow-up along \(x_1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The simplest way to choose the step size in gradient descent is to use a fixed value for all iterations: \(t_k = t\) for \(k = 1, 2, 3, ...\). However, the convergence and behavior depend heavily on the choice of \(t\).&lt;/p&gt;

&lt;p&gt;For example, in the figure below, gradient descent is applied to \(f(x) = (10 x_1^2 + x_2^2) / 2\) with different step sizes:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_02_01_gradientdescent4.png&quot; alt=&quot;gradientdescent4&quot; width=&quot;100%&quot; height=&quot;100%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Step size scenarios [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;In case A, the step size \(t\) is too large, causing divergence after 8 steps. The minimum cannot be reached.&lt;/li&gt;
  &lt;li&gt;In case B, the step size \(t\) is too small, so convergence is very slow and the minimum is not reached even after 100 steps.&lt;/li&gt;
  &lt;li&gt;In case C, the step size is “appropriate,” and convergence is achieved in about 40 steps. (How to find this “appropriate” value is discussed later in this chapter.)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;step-size-stable-too-large-too-small-video&quot;&gt;Step size: stable, too large, too small (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/gd-step-sizes_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;On a stretched bowl, a step that is too large zig-zags or diverges, and one that is too small crawls. Backtracking and exact line search pick the step for you.&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-step-size&quot;&gt;Try it yourself: step size&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;gd&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>06-01 Gradient Descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_01_gradient_descent/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_01_gradient_descent</id>
   <content type="html">&lt;p&gt;Why does moving directly opposite the gradient always decrease a smooth function—at least for a small enough step? By Taylor’s theorem, the gradient points strictly in the direction of steepest local ascent, so \(-\nabla f(x)\) is the unique unit direction that drops the objective fastest to first order. This lesson builds the complete mathematical and geometric foundation of unconstrained gradient descent from 1D parabolas to high-dimensional data-science models.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-mechanics-of-steepest-descent&quot;&gt;Key ideas: Mechanics of Steepest Descent&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Taylor Justification&lt;/strong&gt;: For a small step \(t &amp;gt; 0\) along \(d = -\nabla f(x)\),
\(f(x - t\nabla f(x)) = f(x) - t\|\nabla f(x)\|_2^2 + O(t^2).\)
Whenever \(\nabla f(x) \neq 0\), the linear term \(-t\|\nabla f(x)\|_2^2\) is strictly negative, guaranteeing strict descent for sufficiently small \(t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Orthogonality to Level Curves&lt;/strong&gt;: The gradient \(\nabla f(x)\) is always perpendicular to the contour \(\{y : f(y) = f(x)\}\). Consequently, gradient descent cuts across level sets at right angles—explaining why elongated elliptical contours cause characteristic zig-zag trajectories.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quadratic Surrogate Interpretation&lt;/strong&gt;: The update \(x^+ = x - t\nabla f(x)\) is the exact minimizer of the local isotropic quadratic model
\(q_t(y) = f(x) + \nabla f(x)^T(y - x) + \frac{1}{2t}\|y - x\|_2^2.\)
Smaller \(t\) means a steeper quadratic penalty (shorter, cautious step); larger \(t\) trusts the linear slope farther.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stopping Criteria in Practice&lt;/strong&gt;: Because iterative methods rarely hit \(\nabla f(x) = 0\) in finite steps, algorithms terminate when \(\|\nabla f(x^{(k)})\|_2 \le \varepsilon\), when relative function decrease falls below a tolerance, or when a step-count budget is reached.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-minimizing-a-1d-non-quadratic-convex-function&quot;&gt;Worked example: Minimizing a 1D Non-Quadratic Convex Function&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x) = e^x + e^{-2x}\) starting from \(x^{(0)} = 0\) with step size \(t = 0.1\) for two iterations, and compare with the exact analytical minimum.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find the exact analytical optimum&lt;/strong&gt;:
\(f&apos;(x) = e^x - 2e^{-2x} = 0 \implies e^{3x} = 2 \implies x^\star = \frac{\ln 2}{3} \approx 0.2310, \quad f(x^\star) \approx 1.8899.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 from \(x^{(0)} = 0\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(f(0) = 1 + 1 = 2.0000\), and \(f&apos;(0) = 1 - 2 = -1.0000\).&lt;/li&gt;
      &lt;li&gt;Update: \(x^{(1)} = 0 - 0.1(-1) = 0.1000\).&lt;/li&gt;
      &lt;li&gt;Value: \(f(0.1) = e^{0.1} + e^{-0.2} \approx 1.1052 + 0.8187 = 1.9239 &amp;lt; 2.0000\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2 from \(x^{(1)} = 0.1\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Derivative: \(f&apos;(0.1) = e^{0.1} - 2e^{-0.2} \approx 1.1052 - 1.6375 = -0.5323\).&lt;/li&gt;
      &lt;li&gt;Update: \(x^{(2)} = 0.1 - 0.1(-0.5323) = 0.1532\).&lt;/li&gt;
      &lt;li&gt;Value: \(f(0.1532) = e^{0.1532} + e^{-0.3064} \approx 1.1656 + 0.7361 = 1.9017\), steadily closing in on \(f^\star \approx 1.8899\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Gradient descent is the simplest algorithm for solving unconstrained convex and differentiable optimization problems.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\min_x f(x),\)
where \(f\) is differentiable and \(dom(f) = \mathbb{R}^n\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The optimal value is \(f^* = \min_x f(x)\), and the optimizer is \(x^*\).&lt;/p&gt;

&lt;h2 id=&quot;why-gradient-descent-matters-in-data-science&quot;&gt;Why Gradient Descent Matters in Data Science&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Gradient descent is the workhorse of machine learning!&lt;/strong&gt; It’s the algorithm behind:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Training neural networks&lt;/strong&gt;: Backpropagation uses gradient descent to update weights&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear regression&lt;/strong&gt;: Finding optimal coefficients to minimize MSE&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Logistic regression&lt;/strong&gt;: Optimizing parameters for classification&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Deep learning&lt;/strong&gt;: Training complex models with millions of parameters&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recommendation systems&lt;/strong&gt;: Learning user preferences and item features&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key insight&lt;/strong&gt;: Every time you see “training” or “learning” in ML, gradient descent (or its variants) is likely involved!&lt;/p&gt;

&lt;h2 id=&quot;gradient-descent-for-single-variable-functions&quot;&gt;Gradient Descent for Single Variable Functions&lt;/h2&gt;

&lt;p&gt;For functions of a single variable \(f: \mathbb{R} \to \mathbb{R}\), gradient descent simplifies significantly. The gradient becomes the derivative, and the update rule becomes:&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = x^{(k-1)} - t f&apos;(x^{(k-1)}), \quad k = 1, 2, 3, ...\]
&lt;/blockquote&gt;

&lt;p&gt;where \(f&apos;(x)\) is the derivative of \(f\) at point \(x\).&lt;/p&gt;

&lt;h3 id=&quot;geometric-interpretation&quot;&gt;Geometric Interpretation&lt;/h3&gt;

&lt;p&gt;In the single variable case, the derivative \(f&apos;(x)\) represents the slope of the tangent line at point \(x\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;If \(f&apos;(x) &amp;gt; 0\), the function is increasing, so we move left (subtract a positive value)&lt;/li&gt;
  &lt;li&gt;If \(f&apos;(x) &amp;lt; 0\), the function is decreasing, so we move right (subtract a negative value)&lt;/li&gt;
  &lt;li&gt;If \(f&apos;(x) = 0\), we have reached a critical point (potential minimum)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;learning-rate-t&quot;&gt;Learning rate \(t\)&lt;/h3&gt;

&lt;p&gt;The learning rate \(t\) (also called step size) is a crucial hyperparameter that can be set by the algorithm designer. It controls how large steps we take in the direction of the negative gradient.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Impact of Learning Rate:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Too small (\(t \ll 1\))&lt;/strong&gt;: The algorithm will update very slowly, requiring many iterations to converge to the optimal solution. While this ensures stability, it can be computationally expensive.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Too large (\(t \gg 1\))&lt;/strong&gt;: The algorithm may overshoot the minimum and potentially diverge, oscillating around the optimal point or even moving away from it.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Just right&lt;/strong&gt;: The algorithm converges quickly and smoothly to the optimal solution.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common strategies for choosing learning rate:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fixed step size&lt;/strong&gt;: Use a constant value throughout the optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exact line search&lt;/strong&gt;: At each iteration, choose \(t\) to minimize \(f(x^{(k-1)} - t\nabla f(x^{(k-1)}))\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Backtracking line search&lt;/strong&gt;: Start with a large step size and reduce it until sufficient decrease is achieved&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive methods&lt;/strong&gt;: Adjust the learning rate based on the optimization progress (e.g., Adam, RMSprop)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;example-quadratic-function&quot;&gt;Example: Quadratic Function&lt;/h3&gt;

&lt;p&gt;Consider the quadratic function \(f(x) = \frac{1}{2}(x - 2)^2 + 1\) with derivative \(f&apos;(x) = x - 2\).&lt;/p&gt;

&lt;p&gt;The gradient descent update becomes:&lt;/p&gt;
&lt;blockquote&gt;
\[x^{(k)} = x^{(k-1)} - t(x^{(k-1)} - 2)\]
&lt;/blockquote&gt;

&lt;p&gt;Starting from \(x^{(0)} = 0\) with step size \(t = 0.1\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(x^{(1)} = 0 - 0.1(0 - 2) = 0.2 \\\) 
\(x^{(2)} = 0.2 - 0.1(0.2 - 2) = 0.38\)
\(x^{(3)} = 0.38 - 0.1(0.38 - 2) = 0.542\)
…&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The sequence converges to \(x^* = 2\), which is the global minimum.&lt;/p&gt;

&lt;h3 id=&quot;step-size-selection&quot;&gt;Step Size Selection&lt;/h3&gt;

&lt;p&gt;The choice of step size \(t\) is crucial:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Too small&lt;/strong&gt;: Convergence is very slow&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Too large&lt;/strong&gt;: The algorithm may overshoot and diverge&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal&lt;/strong&gt;: For quadratic functions \(f(x) = \frac{1}{2}ax^2 + bx + c\) with \(a &amp;gt; 0\), the optimal step size is \(t = \frac{1}{a}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;interactive-visualization&quot;&gt;Interactive Visualization&lt;/h3&gt;

&lt;div id=&quot;single-var-gradient-descent&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
        &lt;label for=&quot;step-size-slider&quot;&gt;Step Size (t): &lt;span id=&quot;step-size-value&quot;&gt;0.1&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;step-size-slider&quot; min=&quot;0.01&quot; max=&quot;0.5&quot; step=&quot;0.01&quot; value=&quot;0.1&quot; style=&quot;width: 300px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
        &lt;label for=&quot;start-point-slider&quot;&gt;Starting Point: &lt;span id=&quot;start-point-value&quot;&gt;-3&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;start-point-slider&quot; min=&quot;-5&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;-3&quot; style=&quot;width: 300px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
        &lt;button id=&quot;start-animation&quot;&gt;Start Animation&lt;/button&gt;
        &lt;button id=&quot;reset-animation&quot;&gt;Reset&lt;/button&gt;
        &lt;button id=&quot;step-once&quot;&gt;Single Step&lt;/button&gt;
    &lt;/div&gt;
    
    &lt;canvas id=&quot;gradient-canvas&quot; width=&quot;600&quot; height=&quot;400&quot; style=&quot;border: 1px solid #ccc; display: block; margin: 0 auto;&quot;&gt;&lt;/canvas&gt;
    
    &lt;div id=&quot;iteration-info&quot; style=&quot;text-align: center; margin-top: 10px; font-family: monospace;&quot;&gt;
        Iteration: 0, x = -3.000, f(x) = 13.500, f&apos;(x) = -5.000
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
class SingleVarGradientDescent {
    constructor() {
        this.canvas = document.getElementById(&apos;gradient-canvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.stepSizeSlider = document.getElementById(&apos;step-size-slider&apos;);
        this.startPointSlider = document.getElementById(&apos;start-point-slider&apos;);
        this.stepSizeValue = document.getElementById(&apos;step-size-value&apos;);
        this.startPointValue = document.getElementById(&apos;start-point-value&apos;);
        this.iterationInfo = document.getElementById(&apos;iteration-info&apos;);
        
        // Animation state
        this.isAnimating = false;
        this.currentX = -3;
        this.iteration = 0;
        this.history = [];
        this.animationId = null;
        
        // Function parameters: f(x) = 0.5 * (x - 2)^2 + 1
        this.a = 0.5;
        this.b = 2;
        this.c = 1;
        
        this.setupEventListeners();
        this.reset();
    }
    
    setupEventListeners() {
        this.stepSizeSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.stepSizeValue.textContent = e.target.value;
        });
        
        this.startPointSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.startPointValue.textContent = e.target.value;
            if (!this.isAnimating) {
                this.reset();
            }
        });
        
        document.getElementById(&apos;start-animation&apos;).addEventListener(&apos;click&apos;, () =&gt; {
            this.startAnimation();
        });
        
        document.getElementById(&apos;reset-animation&apos;).addEventListener(&apos;click&apos;, () =&gt; {
            this.reset();
        });
        
        document.getElementById(&apos;step-once&apos;).addEventListener(&apos;click&apos;, () =&gt; {
            this.singleStep();
        });
    }
    
    // Function: f(x) = 0.5 * (x - 2)^2 + 1
    f(x) {
        return this.a * Math.pow(x - this.b, 2) + this.c;
    }
    
    // Derivative: f&apos;(x) = (x - 2)
    fprime(x) {
        return 2 * this.a * (x - this.b);
    }
    
    // Convert x coordinate to canvas coordinate
    xToCanvas(x) {
        const xMin = -5, xMax = 5;
        return (x - xMin) / (xMax - xMin) * this.canvas.width;
    }
    
    // Convert y coordinate to canvas coordinate
    yToCanvas(y) {
        const yMin = 0, yMax = 15;
        return this.canvas.height - (y - yMin) / (yMax - yMin) * this.canvas.height;
    }
    
    // Convert canvas x to actual x
    canvasToX(canvasX) {
        const xMin = -5, xMax = 5;
        return xMin + (canvasX / this.canvas.width) * (xMax - xMin);
    }
    
    drawFunction() {
        this.ctx.strokeStyle = &apos;#2196F3&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        
        for (let canvasX = 0; canvasX &lt;= this.canvas.width; canvasX += 2) {
            const x = this.canvasToX(canvasX);
            const y = this.f(x);
            const canvasY = this.yToCanvas(y);
            
            if (canvasX === 0) {
                this.ctx.moveTo(canvasX, canvasY);
            } else {
                this.ctx.lineTo(canvasX, canvasY);
            }
        }
        this.ctx.stroke();
    }
    
    drawAxes() {
        this.ctx.strokeStyle = &apos;#666&apos;;
        this.ctx.lineWidth = 1;
        
        // X-axis
        const yZero = this.yToCanvas(0);
        this.ctx.beginPath();
        this.ctx.moveTo(0, yZero);
        this.ctx.lineTo(this.canvas.width, yZero);
        this.ctx.stroke();
        
        // Y-axis
        const xZero = this.xToCanvas(0);
        this.ctx.beginPath();
        this.ctx.moveTo(xZero, 0);
        this.ctx.lineTo(xZero, this.canvas.height);
        this.ctx.stroke();
        
        // Labels
        this.ctx.fillStyle = &apos;#666&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;center&apos;;
        
        // X-axis labels
        for (let x = -4; x &lt;= 4; x += 2) {
            const canvasX = this.xToCanvas(x);
            this.ctx.fillText(x.toString(), canvasX, yZero + 15);
        }
        
        // Y-axis labels
        this.ctx.textAlign = &apos;right&apos;;
        for (let y = 2; y &lt;= 14; y += 2) {
            const canvasY = this.yToCanvas(y);
            this.ctx.fillText(y.toString(), xZero - 5, canvasY + 4);
        }
    }
    
    drawCurrentPoint() {
        const canvasX = this.xToCanvas(this.currentX);
        const canvasY = this.yToCanvas(this.f(this.currentX));
        
        // Current point
        this.ctx.fillStyle = &apos;#F44336&apos;;
        this.ctx.beginPath();
        this.ctx.arc(canvasX, canvasY, 6, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Tangent line
        const derivative = this.fprime(this.currentX);
        const tangentLength = 1;
        const x1 = this.currentX - tangentLength;
        const x2 = this.currentX + tangentLength;
        const y1 = this.f(this.currentX) + derivative * (x1 - this.currentX);
        const y2 = this.f(this.currentX) + derivative * (x2 - this.currentX);
        
        this.ctx.strokeStyle = &apos;#FF9800&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        this.ctx.moveTo(this.xToCanvas(x1), this.yToCanvas(y1));
        this.ctx.lineTo(this.xToCanvas(x2), this.yToCanvas(y2));
        this.ctx.stroke();
    }
    
    drawHistory() {
        if (this.history.length &lt; 2) return;
        
        this.ctx.strokeStyle = &apos;#4CAF50&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.setLineDash([5, 5]);
        this.ctx.beginPath();
        
        for (let i = 0; i &lt; this.history.length; i++) {
            const x = this.history[i];
            const canvasX = this.xToCanvas(x);
            const canvasY = this.yToCanvas(this.f(x));
            
            if (i === 0) {
                this.ctx.moveTo(canvasX, canvasY);
            } else {
                this.ctx.lineTo(canvasX, canvasY);
            }
        }
        this.ctx.stroke();
        this.ctx.setLineDash([]);
        
        // Draw history points
        this.ctx.fillStyle = &apos;#4CAF50&apos;;
        for (let i = 0; i &lt; this.history.length - 1; i++) {
            const x = this.history[i];
            const canvasX = this.xToCanvas(x);
            const canvasY = this.yToCanvas(this.f(x));
            
            this.ctx.beginPath();
            this.ctx.arc(canvasX, canvasY, 3, 0, 2 * Math.PI);
            this.ctx.fill();
        }
    }
    
    draw() {
        // Clear canvas
        this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
        
        // Draw components
        this.drawAxes();
        this.drawFunction();
        this.drawHistory();
        this.drawCurrentPoint();
        
        // Update iteration info
        this.iterationInfo.textContent = 
            `Iteration: ${this.iteration}, x = ${this.currentX.toFixed(3)}, ` +
            `f(x) = ${this.f(this.currentX).toFixed(3)}, f&apos;(x) = ${this.fprime(this.currentX).toFixed(3)}`;
    }
    
    singleStep() {
        if (Math.abs(this.fprime(this.currentX)) &lt; 1e-6) {
            return; // Already at minimum
        }
        
        const stepSize = parseFloat(this.stepSizeSlider.value);
        const newX = this.currentX - stepSize * this.fprime(this.currentX);
        
        this.history.push(this.currentX);
        this.currentX = newX;
        this.iteration++;
        
        this.draw();
    }
    
    startAnimation() {
        if (this.isAnimating) {
            this.stopAnimation();
            return;
        }
        
        this.isAnimating = true;
        document.getElementById(&apos;start-animation&apos;).textContent = &apos;Stop Animation&apos;;
        
        const animate = () =&gt; {
            if (!this.isAnimating) return;
            
            if (Math.abs(this.fprime(this.currentX)) &gt; 1e-6 &amp;&amp; this.iteration &lt; 100) {
                this.singleStep();
                this.animationId = setTimeout(animate, 500);
            } else {
                this.stopAnimation();
            }
        };
        
        animate();
    }
    
    stopAnimation() {
        this.isAnimating = false;
        document.getElementById(&apos;start-animation&apos;).textContent = &apos;Start Animation&apos;;
        if (this.animationId) {
            clearTimeout(this.animationId);
            this.animationId = null;
        }
    }
    
    reset() {
        this.stopAnimation();
        this.currentX = parseFloat(this.startPointSlider.value);
        this.iteration = 0;
        this.history = [];
        this.draw();
    }
}

// Initialize when DOM is loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    new SingleVarGradientDescent();
});
&lt;/script&gt;

&lt;h2 id=&quot;gradient-descent-method-for-multivariables-function&quot;&gt;Gradient Descent Method for Multivariables function&lt;/h2&gt;

&lt;p&gt;Gradient descent starts from an initial point \(x^{(0)} \in \mathbb{R}^n\) and iteratively updates as follows until a stopping criterion is met:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(x^{(k)} = x^{(k-1)} - t \nabla f(x^{(k-1)}), \quad k = 1, 2, 3, ...\), \(t &amp;gt; 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Pseudocode:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Given a starting point&lt;/strong&gt; \(x \in dom(f)\) &lt;br /&gt;
&lt;strong&gt;Repeat&lt;/strong&gt;  &lt;br /&gt;&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;Determine descent direction \(\Delta x = -\nabla f(x)\). &lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;Line search: choose step size \(t &amp;gt; 0\). &lt;br /&gt;&lt;/li&gt;
    &lt;li&gt;Update \(x = x + t \Delta x\). &lt;br /&gt;
&lt;strong&gt;Until&lt;/strong&gt; stopping criterion is satisfied &lt;br /&gt;&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;examples&quot;&gt;Examples&lt;/h3&gt;

&lt;p&gt;The figure below shows gradient descent on a convex function. In this case, the local minimum is also the global minimum.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_01_gradientdescent1.png&quot; alt=&quot;gradientdescent1&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Gradient descent in convex functions[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The next figure shows gradient descent on a non-convex function. Here, the initial point determines which local minimum is reached.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_01_gradientdescent2.png&quot; alt=&quot;gradientdescent2&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 2] Gradient descent in non-convex functions[3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;gradient-descent-interpretation&quot;&gt;Gradient Descent Interpretation&lt;/h2&gt;
&lt;p&gt;Gradient descent can be interpreted as choosing the next point by minimizing a quadratic approximation of the function.&lt;/p&gt;

&lt;p&gt;For a function \(f\), the second-order Taylor expansion around \(x\) is:&lt;/p&gt;

&lt;blockquote&gt;
\[f(y) = f(x) + \nabla f(x)^T (y - x) + \frac{1}{2} (y - x)^T \nabla^2 f(x) (y - x) + \text{higher-order terms}.\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
\[f(y) \approx f(x) + \nabla f(x)^T (y - x) +  \frac{1}{2} \nabla^2 f(x)  \|y - x\|_2^2\]
&lt;/blockquote&gt;

&lt;p&gt;If we approximate the Hessian \(\nabla^2 f(x)\) by \(\frac{1}{t}I\), then:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(y) \approx f(x) + \nabla f(x)^T (y - x) +  \frac{1}{2t}  \|y - x\|_2^2\)
where \(t\) is the step size.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thus, in gradient descent, the function is approximated by a quadratic function whose Hessian matrix has eigenvalues equal to the reciprocal of the step size. The term \(f(x) + \nabla f(x)^T (y - x)\) represents a linear approximation of \(f\), and \(\frac{1}{2t}  \|y - x\|_2^2\) serves as a proximity term indicating how close \(y\) is to \(x\).&lt;/p&gt;

&lt;p&gt;The next position is chosen as the minimum of this approximated quadratic function. Setting the gradient of \(f(y)\) to zero to find the next position \(y = x^+\) leads to:&lt;/p&gt;

&lt;blockquote&gt;
\[x^+ = x - t \nabla f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;In the illustration below, the blue dot represents the current position \(x\), and the red dot represents the next position \(y\). The curve below is the actual function \(f\), and the curve above is the quadratic approximation of \(f\). Hence, the red dot indicates the minimum of the quadratic approximation.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter06/06_01_gradientdescent3.png&quot; alt=&quot;gradientdescent3&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$ \text{[Fig 3] Gradient descent algorithm : red dot is } x^+ \text{ and blue dot } x \text{ [3]} $$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The proximity of the next position \(y\) to the current position \(x\) is influenced by the weight of the proximity term \(\frac{1}{2t}\). A smaller \(t\) results in a larger weight for the proximity term, leading to smaller steps. This process can be expressed as:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^+ = \underset{y}{\arg \min} \ f(x) + \nabla f(x)^T (y - x) + \frac{1}{2t} \parallel y - x \parallel_2^2
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>06-01-06 Exercises: Step Size and Curvature</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_01_06_hessian_exercises/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_01_06_hessian_exercises</id>
   <content type="html">&lt;p&gt;Knowing that \(t \le 1/L\) guarantees descent is one thing; deriving the quadratic surrogate minimizer, computing condition numbers of real Hessians, and seeing how curvature dictates iteration counts is how you internalize second-order geometry. These exercises turn the curvature-approximation intuition of Lesson 06-01-05 into concrete algebraic muscle memory.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-core-formulas-for-curvature-exercises&quot;&gt;Key ideas: Core Formulas for Curvature Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Minimizing the Isotropic Quadratic Surrogate&lt;/strong&gt;: Setting the gradient of \(q_t(y) = f(x) + \nabla f(x)^T(y-x) + \frac{1}{2t}\|y-x\|_2^2\) with respect to \(y\) to zero gives \(\nabla f(x) + \frac{1}{t}(y - x) = 0 \implies y^\star = x - t\nabla f(x)\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Spectral Contraction on Quadratics&lt;/strong&gt;: For \(f(x) = \frac{1}{2}x^T Q x\) with \(Q = V\Lambda V^T \succ 0\), gradient descent multiplies the \(i\)-th eigencomponent by \((1 - t\lambda_i)\) each step. Convergence holds iff $$&lt;/td&gt;
          &lt;td&gt;1 - t\lambda_i&lt;/td&gt;
          &lt;td&gt;&amp;lt; 1\(for every eigenvalue, i.e.,\)0 &amp;lt; t &amp;lt; 2/\lambda_{\max}(Q)$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Condition Number and Iteration Complexity&lt;/strong&gt;: With optimal step size \(t^\star = \frac{2}{\lambda_{\max} + \lambda_{\min}}\), the worst-case error shrinks by \(\rho = \frac{\kappa - 1}{\kappa + 1}\) per step, where \(\kappa = \lambda_{\max}/\lambda_{\min}\). Reaching accuracy \(\varepsilon\) requires roughly \(\frac{\kappa}{2}\ln(1/\varepsilon)\) iterations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preconditioning Preview&lt;/strong&gt;: Changing coordinates via \(x = D^{-1/2}z\) (where \(D = \operatorname{diag}(Q)\)) or Newton’s full \(Q^{-1/2}\) reduces \(\kappa\) toward \(1\), dramatically accelerating convergence.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-warm-up-eigenvalue--step-size-analysis&quot;&gt;Worked example: Warm-Up Eigenvalue &amp;amp; Step-Size Analysis&lt;/h3&gt;

&lt;p&gt;For \(f(x) = \frac{1}{2}x^T Q x\) with \(Q = \begin{bmatrix} 5 &amp;amp; 3 \\ 3 &amp;amp; 5 \end{bmatrix}\), find the condition number \(\kappa\) and the exact maximum stable step size.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the eigenvalues of \(Q\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Trace: \(\lambda_1 + \lambda_2 = 5 + 5 = 10\).&lt;/li&gt;
      &lt;li&gt;Determinant: \(\lambda_1 \lambda_2 = 25 - 9 = 16\).&lt;/li&gt;
      &lt;li&gt;Solving \(\lambda^2 - 10\lambda + 16 = (\lambda - 8)(\lambda - 2) = 0\) gives \(\lambda_{\max} = 8\) and \(\lambda_{\min} = 2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the condition number&lt;/strong&gt;:
\(\kappa(Q) = \frac{\lambda_{\max}}{\lambda_{\min}} = \frac{8}{2} = 4.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Determine the stability interval and optimal fixed step size&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Stability requires \(0 &amp;lt; t &amp;lt; \frac{2}{\lambda_{\max}} = \frac{2}{8} = 0.25\).&lt;/li&gt;
      &lt;li&gt;Optimal fixed step size: \(t^\star = \frac{2}{8 + 2} = 0.20\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Per-step spectral contraction factor at \(t^\star = 0.20\): $$&lt;/td&gt;
              &lt;td&gt;1 - 0.20(8)&lt;/td&gt;
              &lt;td&gt;=&lt;/td&gt;
              &lt;td&gt;-0.6&lt;/td&gt;
              &lt;td&gt;= 0.6\(and\)&lt;/td&gt;
              &lt;td&gt;1 - 0.20(2)&lt;/td&gt;
              &lt;td&gt;= 0.6\(, matching\)\frac{\kappa - 1}{\kappa + 1} = \frac{3}{5} = 0.6$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;h2 id=&quot;exercise-1-deriving-the-quadratic-approximation&quot;&gt;Exercise 1: Deriving the Quadratic Approximation&lt;/h2&gt;

&lt;p&gt;Consider the quadratic approximation used in gradient descent:
\(f(y) \approx f(x) + \nabla f(x)^T (y - x) + \frac{1}{2t} \|y - x\|_2^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part A&lt;/strong&gt;: Show that minimizing this approximation over \(y\) gives the gradient descent update \(y = x - t\nabla f(x)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part B&lt;/strong&gt;: What happens if we change the coefficient to \(\frac{\alpha}{2t}\) instead of \(\frac{1}{2t}\)? How does this affect the step size?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part C&lt;/strong&gt;: Interpret the term \(\frac{1}{2t} \|y - x\|_2^2\) geometrically. What does it prevent?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-2-step-size-and-function-curvature&quot;&gt;Exercise 2: Step Size and Function Curvature&lt;/h2&gt;

&lt;p&gt;Consider two quadratic functions:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[f_1(x_1, x_2) = \frac{1}{2}(x_1^2 + x_2^2)\]
  &lt;/li&gt;
  &lt;li&gt;
\[f_2(x_1, x_2) = \frac{1}{2}(4x_1^2 + x_2^2)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Part A&lt;/strong&gt;: Compute the Hessian matrix (the matrix of second partial derivatives) of both functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part B&lt;/strong&gt;: If we approximate both Hessians by \(\frac{1}{t}I\), which value of \(t\) gives the best approximation for each function?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part C&lt;/strong&gt;: Starting from the point \((2, 2)\), perform 3 gradient descent iterations on both functions using your optimal step sizes. Compare the convergence behavior.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-3-condition-number-and-convergence&quot;&gt;Exercise 3: Condition Number and Convergence&lt;/h2&gt;

&lt;p&gt;For the function \(f(x_1, x_2) = \frac{1}{2}(ax_1^2 + bx_2^2)\) with \(a &amp;gt; b &amp;gt; 0\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part A&lt;/strong&gt;: What is the condition number \(\kappa = \frac{a}{b}\)? How does it relate to the “shape” of the function?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part B&lt;/strong&gt;: Show that the optimal step size for the fastest convergence is \(t^* = \frac{2}{a + b}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part C&lt;/strong&gt;: Compare the convergence speed for:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\kappa = 1\) (\(a = b = 1\))&lt;/li&gt;
  &lt;li&gt;\(\kappa = 4\) (\(a = 4, b = 1\))&lt;/li&gt;
  &lt;li&gt;\(\kappa = 100\) (\(a = 100, b = 1\))&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What happens as the condition number grows?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-4-coordinate-wise-step-sizes&quot;&gt;Exercise 4: Coordinate-wise Step Sizes&lt;/h2&gt;

&lt;p&gt;Instead of using the same step size for all coordinates, consider:
\(x_1^{(k+1)} = x_1^{(k)} - t_1 \frac{\partial f}{\partial x_1}\)
\(x_2^{(k+1)} = x_2^{(k)} - t_2 \frac{\partial f}{\partial x_2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part A&lt;/strong&gt;: For \(f(x_1, x_2) = \frac{1}{2}(ax_1^2 + bx_2^2)\), which choice of \(t_1, t_2\) makes each coordinate converge in exactly one step?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part B&lt;/strong&gt;: How does this relate to approximating the Hessian by a diagonal matrix instead of \(\frac{1}{t}I\)?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part C&lt;/strong&gt;: Implement this coordinate-wise approach and compare it with standard gradient descent on an ill-conditioned quadratic.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-5-visualizing-the-quality-of-the-approximation&quot;&gt;Exercise 5: Visualizing the Quality of the Approximation&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Part A&lt;/strong&gt;: For \(f(x_1, x_2) = \frac{1}{2}(4x_1^2 + x_2^2)\), plot the contour lines of the true function and of the quadratic approximation \(f(x) + \nabla f(x)^T (y - x) + \frac{1}{2t} \|y - x\|_2^2\) around the point \(x = (1, 1)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part B&lt;/strong&gt;: Try different values of \(t\) and observe how the quality of the approximation changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part C&lt;/strong&gt;: Which value of \(t\) makes the approximation’s contours look most like those of the true function?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-6-strategies-for-choosing-the-step-size&quot;&gt;Exercise 6: Strategies for Choosing the Step Size&lt;/h2&gt;

&lt;p&gt;Compare three step-size strategies on the function \(f(x) = \frac{1}{2}x^T A x\) with:
\(A = \begin{bmatrix} 10 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Small fixed step&lt;/strong&gt;: \(t = 0.1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Large fixed step&lt;/strong&gt;: \(t = 0.5\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive step&lt;/strong&gt;: \(t = \frac{2}{\lambda_{\max} + \lambda_{\min}}\), where \(\lambda_{\max}, \lambda_{\min}\) are the largest and smallest eigenvalues of \(A\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Part A&lt;/strong&gt;: Compute the eigenvalues of \(A\) and determine the adaptive step size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part B&lt;/strong&gt;: Starting from \((5, 5)\), run gradient descent with each strategy for 20 iterations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part C&lt;/strong&gt;: Plot the convergence curves and trajectories. Which strategy works best, and why?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-7-true-function-vs-quadratic-approximation&quot;&gt;Exercise 7: True Function vs Quadratic Approximation&lt;/h2&gt;

&lt;p&gt;Consider the non-quadratic function \(f(x) = e^{x_1} + x_2^2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part A&lt;/strong&gt;: Compute the gradient and the Hessian of this function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part B&lt;/strong&gt;: At the point \(x = (0, 1)\), compare:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;One gradient descent step with step size \(t = 0.1\)&lt;/li&gt;
  &lt;li&gt;One step using the quadratic approximation with the true Hessian&lt;/li&gt;
  &lt;li&gt;One step using the quadratic approximation with \(\frac{1}{t}I\) for \(t = 0.1\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Part C&lt;/strong&gt;: Which approximation gives a result closer to the true minimizing direction?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;programming-exercises&quot;&gt;Programming Exercises&lt;/h2&gt;

&lt;h3 id=&quot;exercise-8-implement-and-compare&quot;&gt;Exercise 8: Implement and Compare&lt;/h3&gt;

&lt;p&gt;Implement the following and compare their performance:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;quadratic_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Compute f(x) = 0.5 * x^T A x&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gradient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Compute the gradient of f(x) = 0.5 * x^T A x&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;standard_gd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;step_size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Standard gradient descent&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;history&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()]&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gradient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;step_size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
        
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;coordinate_wise_gd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;step_sizes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Coordinate-wise gradient descent&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;history&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()]&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_iter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gradient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# Apply a different step size to each coordinate
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;step_sizes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
        
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;history&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# Test on different condition numbers
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;condition_numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kappa&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;condition_numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kappa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;# Optimal step size for standard GD
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;eigenvals&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;eigvals&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t_optimal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eigenvals&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eigenvals&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;# Optimal coordinate-wise step sizes
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;t_coord&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;diag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;# Run both methods
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;history_std&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;standard_gd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t_optimal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;history_coord&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;coordinate_wise_gd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t_coord&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;# Plot the results
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subplot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;semilogy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;quadratic_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;history_std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;b-&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Standard GD&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;semilogy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;quadratic_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;history_coord&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;r--&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Coordinate-wise GD&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Iteration&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Function value&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Convergence (κ = &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kappa&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subplot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;history_std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;history_std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;b-o&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Standard GD&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;markersize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;history_coord&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;history_coord&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;r--s&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Coordinate-wise GD&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;markersize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;x₁&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;x₂&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Trajectory (κ = &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kappa&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;equal&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tight_layout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;exercise-9-interactive-visualization&quot;&gt;Exercise 9: Interactive Visualization&lt;/h3&gt;

&lt;p&gt;Create an interactive plot that shows:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;The contour lines of the true function&lt;/li&gt;
  &lt;li&gt;The contour lines of the quadratic approximation&lt;/li&gt;
  &lt;li&gt;The gradient descent trajectory&lt;/li&gt;
  &lt;li&gt;A slider to adjust the step size and see how it affects convergence&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Use matplotlib widgets or plotly for interactivity&lt;/li&gt;
  &lt;li&gt;Show both well-conditioned and ill-conditioned examples&lt;/li&gt;
  &lt;li&gt;Display the approximation error as the step size changes&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;solution-outline&quot;&gt;Solution Outline&lt;/h2&gt;

&lt;h3 id=&quot;solution-to-exercise-1&quot;&gt;Solution to Exercise 1:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;: Take \(\frac{\partial}{\partial y}[f(x) + \nabla f(x)^T (y - x) + \frac{1}{2t} \|y - x\|_2^2] = \nabla f(x) + \frac{1}{t}(y-x) = 0\)
Solving gives \(y = x - t\nabla f(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B&lt;/strong&gt;: The effective step size becomes \(\frac{t}{\alpha}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C&lt;/strong&gt;: The term acts as a “proximity penalty” - it prevents taking a step that is too far from the current point&lt;/p&gt;

&lt;h3 id=&quot;solution-to-exercise-2&quot;&gt;Solution to Exercise 2:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\nabla^2 f_1 = I\]
  &lt;/li&gt;
  &lt;li&gt;
\[\nabla^2 f_2 = \begin{bmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;B&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;For \(f_1\): \(t = 1\)&lt;/li&gt;
  &lt;li&gt;For \(f_2\): \(t = 0.4\) (minimize the approximation error \((4-\frac{1}{t})^2 + (1-\frac{1}{t})^2\) over \(\frac{1}{t}\), giving \(\frac{1}{t} = \frac{4+1}{2} = 2.5\))&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;solution-to-exercise-3&quot;&gt;Solution to Exercise 3:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;: \(\kappa = \frac{a}{b}\) measures how “stretched” the elliptical contour lines are&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B&lt;/strong&gt;: Minimize the convergence factor \(\frac{\kappa-1}{\kappa+1}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C&lt;/strong&gt;: A higher condition number → slower convergence, more oscillatory behavior&lt;/p&gt;

&lt;h3 id=&quot;solution-to-exercise-4&quot;&gt;Solution to Exercise 4:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;: \(t_1 = \frac{1}{a}\), \(t_2 = \frac{1}{b}\): then \(x_1^{+} = x_1 - \frac{1}{a}\cdot a x_1 = 0\) and \(x_2^{+} = 0\), i.e. convergence in exactly one step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B&lt;/strong&gt;: This corresponds to approximating the Hessian by the diagonal matrix \(\text{diag}(a, b)\) (an exact approximation) instead of \(\frac{1}{t}I\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C&lt;/strong&gt;: Use \(t_i = 1/A_{ii}\) (not \(2/A_{ii}\); a step size of \(2/A_{ii}\) only flips the sign of the coordinate and oscillates).&lt;/p&gt;

&lt;h3 id=&quot;solution-to-exercise-6&quot;&gt;Solution to Exercise 6:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;: \(\lambda_{\max} \approx 10.42\), \(\lambda_{\min} \approx 0.575\), so \(t = \frac{2}{11} \approx 0.18\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B–C&lt;/strong&gt;: Note that \(t = 0.5 &amp;gt; \frac{2}{\lambda_{\max}} \approx 0.19\), so gradient descent with the large fixed step &lt;strong&gt;diverges&lt;/strong&gt;; \(t = 0.1\) converges but slowly along the low-curvature direction; \(t = \frac{2}{11}\) gives the best rate.&lt;/p&gt;

&lt;h3 id=&quot;key-learning-outcomes&quot;&gt;Key Learning Outcomes:&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Intuition&lt;/strong&gt;: the step size is related to an assumed curvature&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical skill&lt;/strong&gt;: how to choose the step size for different problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical understanding&lt;/strong&gt;: the connection between function properties and optimization behavior&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Programming experience&lt;/strong&gt;: coding and comparing different approaches&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These exercises build understanding without requiring advanced concepts such as Newton’s method, focusing instead on the basic relationship between step size, curvature, and convergence behavior.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06-01-05 Why Does the Step Size Matter?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_01_05_hessian_approximation/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_01_05_hessian_approximation</id>
   <content type="html">&lt;p&gt;At first glance, the gradient descent step size \(t\) looks like an arbitrary hyperparameter you tune by guesswork. Look one layer deeper through Taylor’s second-order expansion and a striking truth emerges: choosing \(t\) is equivalent to approximating the true curvature matrix \(\nabla^2 f(x)\) by a single scalar multiple of the identity, \(\frac{1}{t}I\)! Understanding this curvature picture explains &lt;em&gt;why&lt;/em&gt; steep valleys force tiny steps and &lt;em&gt;why&lt;/em&gt; condition number controls convergence speed.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-curvature-hessian-bounds-and-step-sizes&quot;&gt;Key ideas: Curvature, Hessian Bounds, and Step Sizes&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent as Isotropic Hessian Replacement&lt;/strong&gt;: Newton’s method minimizes \(f(x) + \nabla f(x)^T(y-x) + \frac{1}{2}(y-x)^T \nabla^2 f(x)(y-x)\). Gradient descent replaces the full Hessian \(\nabla^2 f(x)\) with \(\frac{1}{t}I\), assuming identical curvature \(1/t\) in every coordinate direction.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Upper-Bound Safety Condition (\(1/t \ge L\))&lt;/strong&gt;: Whenever \(\frac{1}{t}I \succeq \nabla^2 f(x)\) (i.e., \(t \le 1/L\) where \(L = \sup_x \lambda_{\max}(\nabla^2 f(x))\)), the quadratic surrogate sits &lt;em&gt;above&lt;/em&gt; the true function \(f(y)\) everywhere. Minimizing an upper bound guarantees strict monotonic decrease \(f(x^+) \le f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Overshooting When Curvature Is Underestimated&lt;/strong&gt;: If \(t &amp;gt; 2/\lambda_{\max}\), the surrogate bowl is too flat along the steepest eigenvector—gradient descent leaps past the valley floor to a higher point on the opposite wall, causing divergence.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ill-Conditioning (\(\kappa = L/m \gg 1\))&lt;/strong&gt;: When one direction has huge curvature \(L\) and another has tiny curvature \(m\), the single scalar \(1/t\) must be large enough to stay safe along the steep direction (\(t \le 1/L\)), which forces painfully tiny progress \(m/L = 1/\kappa\) along the flat direction.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-computing-the-safe-step-size-limit-from-curvature&quot;&gt;Worked example: Computing the Safe Step-Size Limit from Curvature&lt;/h3&gt;

&lt;p&gt;Consider the quadratic function \(f(x_1, x_2) = \frac{1}{2}(2x_1^2 + 20x_2^2)\), whose exact Hessian is \(\nabla^2 f(x) = \operatorname{diag}(2, 20)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify minimum and maximum curvature&lt;/strong&gt;:
\(m = \lambda_{\min}(\nabla^2 f) = 2, \qquad L = \lambda_{\max}(\nabla^2 f) = 20, \qquad \kappa = \frac{L}{m} = 10.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the conservative upper-bound step size \(t = 1/L = 0.05\)&lt;/strong&gt; from \(x^{(0)} = (1, 1)\):
    &lt;ul&gt;
      &lt;li&gt;Here \(\frac{1}{t}I = 20I \succeq \operatorname{diag}(2, 20)\).&lt;/li&gt;
      &lt;li&gt;Update: \(x^{(1)} = (1 - 0.05\cdot 2,\; 1 - 0.05\cdot 20) = (0.9,\; 0)\). The steep direction hits \(0\) in one step, while the flat direction shrinks by \(0.9\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test an overly aggressive step size \(t = 0.12 &amp;gt; 2/L = 0.10\)&lt;/strong&gt; from \(x^{(0)} = (1, 1)\):
    &lt;ul&gt;
      &lt;li&gt;Along \(x_2\): \(x_2^{(1)} = 1 - 0.12(20) = 1 - 2.4 = -1.4\).&lt;/li&gt;
      &lt;li&gt;Next step: \(x_2^{(2)} = -1.4(1 - 2.4) = +1.96\). The magnitude grows by \(1.4\times\) every iteration and diverges to \(\infty\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal fixed step size&lt;/strong&gt;: Balancing both eigenvalues via \(t^\star = \frac{2}{L + m} = \frac{2}{22} = \frac{1}{11} \approx 0.0909\) gives contraction factor \(\frac{\kappa - 1}{\kappa + 1} = \frac{9}{11} \approx 0.818\) in &lt;em&gt;both&lt;/em&gt; directions simultaneously.&lt;/li&gt;
&lt;/ol&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
    displayAlign: &quot;center&quot;
});
&lt;/script&gt;

&lt;p&gt;In gradient descent, choosing the right step size \(t\) is very important. But why? The answer lies in understanding what gradient descent is really doing: &lt;strong&gt;it is making a simple assumption about the curvature of the function&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;the-core-idea&quot;&gt;The Core Idea&lt;/h2&gt;

&lt;p&gt;When we perform gradient descent:&lt;/p&gt;
&lt;blockquote&gt;
\[x^{(k+1)} = x^{(k)} - t \nabla f(x^{(k)})\]
&lt;/blockquote&gt;

&lt;p&gt;we are actually solving this problem:&lt;/p&gt;
&lt;blockquote&gt;
\[x^{(k+1)} = \arg\min_y \left\{ \nabla f(x^{(k)})^T (y - x^{(k)}) + \frac{1}{2t} \|y - x^{(k)}\|^2 \right\}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;What does this mean?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The first term: “Go in the steepest-descent direction”&lt;/li&gt;
  &lt;li&gt;The second term: “But do not go too far from the current position”&lt;/li&gt;
  &lt;li&gt;The parameter \(t\) controls this balance&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;step-size--trust-in-flatness&quot;&gt;Step Size = Trust in Flatness&lt;/h2&gt;

&lt;p&gt;Think of the step size this way:&lt;/p&gt;
&lt;blockquote&gt;
\[t = \frac{1}{\text{how curved you think the function is}}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Large \(t\)&lt;/strong&gt;: “I think the function is quite flat here” → take a big step&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Small \(t\)&lt;/strong&gt;: “I think the function is very curved here” → take a small, careful step&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;a-simple-example&quot;&gt;A Simple Example&lt;/h2&gt;

&lt;p&gt;Consider two functions:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;A flat function&lt;/strong&gt;: \(f(x_1, x_2) = \frac{1}{2}(x_1^2 + x_2^2)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;A steep function&lt;/strong&gt;: \(f(x_1, x_2) = \frac{1}{2}(100x_1^2 + x_2^2)\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the flat function you can use \(t = 1\) (a big step).
For the steep function you need \(t = 0.01\) (a small step) to avoid overshooting the target.&lt;/p&gt;

&lt;h2 id=&quot;why-this-works&quot;&gt;Why This Works&lt;/h2&gt;

&lt;p&gt;Let us see why this gives the gradient descent formula.&lt;/p&gt;

&lt;p&gt;We want to minimize:&lt;/p&gt;
&lt;blockquote&gt;
\[\nabla f(x)^T (y - x) + \frac{1}{2t} \|y - x\|^2\]
&lt;/blockquote&gt;

&lt;p&gt;Take the derivative with respect to \(y\) and set it to zero:&lt;/p&gt;
&lt;blockquote&gt;
\[\nabla f(x) + \frac{1}{t}(y - x) = 0\]
&lt;/blockquote&gt;

&lt;p&gt;Solving for \(y\):&lt;/p&gt;
&lt;blockquote&gt;
\[y = x - t \nabla f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;That is exactly the gradient descent update! The term \(\frac{1}{2t}\) acts like a “spring” pulling you back toward \(x\), preventing steps that are too large.&lt;/p&gt;

&lt;h2 id=&quot;when-does-it-work-well&quot;&gt;When Does It Work Well?&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Good cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The function has about the same “steepness” in every direction&lt;/li&gt;
  &lt;li&gt;Bowl-shaped functions such as \(f(x_1, x_2) = x_1^2 + x_2^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bad cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The function is very steep in one direction but flat in another&lt;/li&gt;
  &lt;li&gt;“Valley”-shaped functions such as \(f(x_1, x_2) = 100x_1^2 + x_2^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;how-to-choose-the-step-size&quot;&gt;How to Choose the Step Size&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Rule of thumb&lt;/strong&gt;: start with \(t = 0.1\) and adjust:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;If gradient descent oscillates strongly → make \(t\) smaller&lt;/li&gt;
  &lt;li&gt;If gradient descent converges very slowly → make \(t\) larger&lt;/li&gt;
  &lt;li&gt;If you understand the function well → use \(t \approx \frac{2}{\text{steepest curvature} + \text{flattest curvature}}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;a-visual-intuition&quot;&gt;A Visual Intuition&lt;/h2&gt;

&lt;p&gt;Imagine walking down a hill in the dark with a flashlight:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;A large step size&lt;/strong&gt;: “I think the path ahead is smooth” → take a long stride (risk: you may step into a hole)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;A small step size&lt;/strong&gt;: “I think the path ahead is bumpy” → take small steps (safe but slow)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Gradient descent does the same thing mathematically!&lt;/p&gt;

&lt;h2 id=&quot;the-big-picture&quot;&gt;The Big Picture&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What gradient descent really does:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Look at the slope (gradient)&lt;/li&gt;
  &lt;li&gt;Assume the function is “bowl”-shaped around you&lt;/li&gt;
  &lt;li&gt;Take a step toward the bottom of that imaginary bowl&lt;/li&gt;
  &lt;li&gt;Repeat&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Why the step size matters:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Too large → you overshoot and bounce back and forth&lt;/li&gt;
  &lt;li&gt;Too small → it takes forever to arrive&lt;/li&gt;
  &lt;li&gt;Just right → smooth, fast convergence&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;key-takeaway&quot;&gt;Key Takeaway&lt;/h2&gt;

&lt;p&gt;The step size is not magic - it is &lt;strong&gt;your guess about the curvature of the function&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(t = 0.01\) means “I think this function is very curved”&lt;/li&gt;
  &lt;li&gt;\(t = 1.0\) means “I think this function is quite flat”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The more accurate the guess, the faster gradient descent converges!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>06 Gradient Descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_00_gradient_descent/"/>
   <updated>2021-03-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter06/06_00_gradient_descent</id>
   <content type="html">&lt;p&gt;Imagine you are blindfolded on a vast mountain slope and want to reach the lowest valley floor. You cannot see the whole map, so you feel the slope under your boots, take a careful step downhill, and repeat. That humble idea—invented by Augustin-Louis Cauchy in 1847 to compute planetary orbits—is &lt;strong&gt;Gradient Descent&lt;/strong&gt;, the engine driving modern machine learning, deep learning, and large-scale convex optimization.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-anatomy-of-gradient-descent&quot;&gt;Key ideas: The Anatomy of Gradient Descent&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Oracle Model&lt;/strong&gt;: Gradient descent needs only function values \(f(x)\) and gradients \(\nabla f(x)\), avoiding the \(O(n^3)\) cost of inverting an \(n \times n\) Hessian matrix. That makes it feasible even when \(n\) reaches billions of parameters.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step-Size Selection (The Throttle of Convergence)&lt;/strong&gt;: Moving in the steepest-descent direction \(-\nabla f(x_k)\) is only half the algorithm—choosing how far to step (\(t_k\)) determines whether you crawl, converge cleanly, or explode to infinity. Fixed step sizes, backtracking line search, and exact line search balance per-step cost against reliability.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smoothness vs. Strong Convexity (Convergence Rates)&lt;/strong&gt;: When \(\nabla f\) is \(L\)-Lipschitz continuous, gradient descent reduces error at rate \(O(1/k)\) on general convex functions. Add \(m\)-strong convexity and the rate jumps to &lt;em&gt;linear&lt;/em&gt; (exponential) convergence \(O\bigl((1 - m/L)^k\bigr)\), governed by the condition number \(\kappa = L/m\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Modern Extensions&lt;/strong&gt;: From functional gradient descent (Gradient Boosting) to mini-batch Stochastic Gradient Descent (SGD), Heavy-Ball/Nesterov Momentum, and L1/L2 regularized objectives, virtually every workhorse optimizer in data science is a direct descendant of this chapter’s core update \(x_{k+1} = x_k - t_k \nabla f(x_k)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-three-iterations-of-gradient-descent-on-a-2d-bowl&quot;&gt;Worked example: Three Iterations of Gradient Descent on a 2D Bowl&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = x_1^2 + 4x_2^2\) starting from \(x^{(0)} = (4, 1)\) with fixed step size \(t = 0.2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the gradient and smoothness constant&lt;/strong&gt;:
\(\nabla f(x_1, x_2) = (2x_1,\; 8x_2), \qquad \nabla^2 f = \operatorname{diag}(2, 8) \implies L = 8.\)
The stability threshold is \(t &amp;lt; 2/L = 0.25\), and our choice \(t = 0.2\) satisfies it.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Gradient at \(x^{(0)} = (4, 1)\): \(\nabla f(x^{(0)}) = (8, 8)\), \(f(x^{(0)}) = 16 + 4 = 20\).&lt;/li&gt;
      &lt;li&gt;Update: \(x^{(1)} = (4, 1) - 0.2(8, 8) = (2.4,\; -0.6)\), with \(f(x^{(1)}) = 5.76 + 1.44 = 7.20\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 2&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Gradient at \(x^{(1)} = (2.4, -0.6)\): \(\nabla f(x^{(1)}) = (4.8,\; -4.8)\).&lt;/li&gt;
      &lt;li&gt;Update: \(x^{(2)} = (2.4, -0.6) - 0.2(4.8, -4.8) = (1.44,\; 0.36)\), with \(f(x^{(2)}) = 2.0736 + 0.5184 = 2.592\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Observe the exact contraction factor&lt;/strong&gt;: Along \(x_1\), each step multiplies by \(1 - 2(0.2) = 0.6\); along \(x_2\), each step multiplies by \(1 - 8(0.2) = -0.6\) (oscillating across the steeper valley!). Thus \(f(x^{(k)}) = 0.36^k \cdot 20\) shrinks geometrically toward \(f^\star = 0\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we explore &lt;strong&gt;Gradient Descent&lt;/strong&gt;, one of the most fundamental and important methods in optimization.&lt;/p&gt;

&lt;p&gt;In optimization algorithms, choosing the search direction and step size is crucial for convergence speed and success. Gradient descent moves in the direction of the negative gradient. The step size can be fixed or adaptively chosen, and we will discuss both approaches in this chapter.&lt;/p&gt;

&lt;p&gt;For gradient descent to converge, certain preconditions must be met. If these conditions are satisfied, we can analyze how quickly gradient descent converges. If strong convexity holds, convergence is even faster, and we will examine the convergence rate in such cases.&lt;/p&gt;

&lt;p&gt;We will also look at applications of gradient descent, including gradient boosting and stochastic gradient descent.&lt;/p&gt;

&lt;p&gt;A later optional lesson, &lt;a href=&quot;/contents/en/chapter06/06_08_Applications_Recent/&quot;&gt;06-08 Applications and recent developments&lt;/a&gt;, contrasts the Lipschitz theory with the edge of stability, Lion, and schedule-free averaging (2021–2024). The linear rate of 06-03-04 can be reused on some &lt;em&gt;nonconvex&lt;/em&gt; ERMs under the Polyak–Łojasiewicz condition; that bridge is the optional note &lt;a href=&quot;/contents/en/chapter28/28_05_pl_condition/&quot;&gt;28-05&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-10 Bài Tập Thực Hành - Hàm Convex</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_10_Practical_Exercises_Convex_Functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_10_Practical_Exercises_Convex_Functions</id>
   <content type="html">&lt;p&gt;Khi rời khỏi các hàm trơn đẹp như \(x^2\) để chạm vào những bài toán thực tế như Lasso (\(\frac{1}{2}\|Ax - b\|_2^2 + \lambda\|x\|_1\)) hay SVM (Hinge loss \(\max(0, 1 - y_i w^T x_i)\)), đạo hàm thông thường biến mất tại các điểm gấp khúc! Lúc đó, &lt;strong&gt;dưới vi phân (subdifferential \(\partial f(x)\))&lt;/strong&gt; — tập hợp tất cả các độ dốc của đường tiếp tuyến nằm dưới đồ thị tại điểm gấp khúc — thay thế hoàn toàn cho gradient, với điều kiện tối ưu toàn cục kinh điển: \(0 \in \partial f(x^*)\).&lt;/p&gt;

&lt;p&gt;Bộ bài tập thực hành cuối Chương 03 giúp bạn thành thạo cả 5 trụ cột: kiểm tra tính lồi, phép toán bảo toàn, hàm liên hợp, dưới vi phân và bất đẳng thức Jensen. Dưới đây là một ví dụ tính tay dưới vi phân tại điểm gấp khúc để khởi động.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-năm-kỹ-năng-thực-hành-cốt-lõi-của-chương-03&quot;&gt;Kiến thức cần nhớ: Năm kỹ năng thực hành cốt lõi của Chương 03&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh tính lồi đa chiến lược:&lt;/strong&gt; Kết hợp linh hoạt tiêu chuẩn Hessian, quy tắc hợp thành DCP và phép chiếu lát cắt 1D.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính tường minh hàm liên hợp \(f^*(y)\):&lt;/strong&gt; Giải \(\sup_x (y^T x - f(x))\) cho cả hàm trơn (bậc hai, âm log, entropy) lẫn hàm không trơn (chuẩn \(\ell_1, \ell_2, \ell_\infty\)) và xác định đúng miền hữu hạn \(\operatorname{dom} f^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính dưới vi phân \(\partial f(x)\) tại điểm không khả vi:&lt;/strong&gt; Tại điểm trơn \(\partial f(x) = \{\nabla f(x)\}\); tại điểm gấp khúc của \(\max(f_1, f_2)\), \(\partial f(x)\) là &lt;strong&gt;bao lồi&lt;/strong&gt; của các gradient nhánh hoạt động!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện tối ưu không trơn (\(0 \in \partial f(x^*)\)):&lt;/strong&gt; Là điều kiện cần và đủ để \(x^*\) là cực tiểu toàn cục của hàm lồi (trơn hoặc không trơn).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khai thác bất đẳng thức Jensen:&lt;/strong&gt; Chứng minh các bất đẳng thức kinh điển (AM–GM, Hölder, phân kỳ KL không âm \(D_{\mathrm{KL}}(p\|q) \ge 0\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-dưới-vi-phân-và-tìm-cực-tiểu-của-hàm-không-trơn-fx--x---2--x2&quot;&gt;Giải thích: Tính dưới vi phân và tìm cực tiểu của hàm không trơn \(f(x) = |x - 2| + x^2\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét hàm lồi mạnh nhưng không khả vi tại \(x = 2\): $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 2&lt;/td&gt;
      &lt;td&gt;+ x^2$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Phân nhánh theo dấu của \(x - 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Khi \(x &amp;lt; 2\): \(f(x) = -(x - 2) + x^2 = x^2 - x + 2 \implies f&apos;(x) = 2x - 1\).&lt;/li&gt;
      &lt;li&gt;Khi \(x &amp;gt; 2\): \(f(x) = (x - 2) + x^2 = x^2 + x - 2 \implies f&apos;(x) = 2x + 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính tập dưới vi phân \(\partial f(2)\) ngay tại điểm gấp khúc \(x = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đạo hàm trái khi \(x \to 2^-\): \(2(2) - 1 = 3\).&lt;/li&gt;
      &lt;li&gt;Đạo hàm phải khi \(x \to 2^+\): \(2(2) + 1 = 5\).&lt;/li&gt;
      &lt;li&gt;Vậy \(\partial f(2) = [3, 5]\) (mọi đường thẳng qua \((2, 4)\) có độ dốc từ \(3\) đến \(5\) đều nằm dưới đồ thị \(f\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm cực tiểu toàn cục bằng điều kiện \(0 \in \partial f(x^*)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(x = 2\): \(0 \notin [3, 5] \implies x = 2\) &lt;strong&gt;không phải&lt;/strong&gt; cực tiểu!&lt;/li&gt;
      &lt;li&gt;Trên nhánh \(x &amp;gt; 2\): \(2x + 1 &amp;gt; 5 &amp;gt; 0\) (vô nghiệm).&lt;/li&gt;
      &lt;li&gt;Trên nhánh \(x &amp;lt; 2\): \(2x - 1 = 0 \implies x^* = 0.5 &amp;lt; 2\) (thỏa mãn!).
Giá trị tối ưu toàn cục là \(f(0.5) = |0.5 - 2| + 0.5^2 = 1.5 + 0.25 = 1.75\) (thấp hơn hẳn \(f(2) = 4\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---hàm-lồi&quot;&gt;Bài tập thực hành - Hàm lồi&lt;/h1&gt;

&lt;h2 id=&quot;-bài-tập-1-kiểm-tra-tính-lồi-của-hàm-số&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Kiểm tra tính lồi của hàm số&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 3.1 từ Boyd &amp;amp; Vandenberghe)
Xác định tính lồi của các hàm sau trên miền xác định tương ứng:&lt;/p&gt;

&lt;p&gt;a) \(f(x) = x^2\) trên \(\mathbb{R}\)&lt;/p&gt;

&lt;p&gt;b) \(f(x) = e^{ax}\) trên \(\mathbb{R}\)&lt;/p&gt;

&lt;p&gt;c) \(f(x) = x \log x\) trên \(\mathbb{R}_{++}\)&lt;/p&gt;

&lt;p&gt;d) \(f(x) = -\log x\) trên \(\mathbb{R}_{++}\)&lt;/p&gt;

&lt;p&gt;e) \(f(x) = x^p\) với \(p \geq 1\) trên \(\mathbb{R}_+\)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;f) $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;^p\(với\)p \geq 1\(trên\)\mathbb{R}$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Kiểm tra bằng định nghĩa hàm lồi&lt;/li&gt;
  &lt;li&gt;Dùng điều kiện bậc hai khi hàm khả vi hai lần&lt;/li&gt;
  &lt;li&gt;Phân tích điều kiện của miền xác định&lt;/li&gt;
  &lt;li&gt;Minh họa đồ thị và tính lồi của các hàm&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: $$f(x) = x^2$$**

**Điều kiện bậc hai:** $$f&apos;&apos;(x) = 2 &amp;gt; 0$$ với mọi $$x \in \mathbb{R}$$ $$\Rightarrow$$ lồi chặt trên $$\mathbb{R}$$.

**Kiểm tra bằng định nghĩa:**
$$f(\theta x + (1-\theta) y) = (\theta x + (1-\theta) y)^2 = \theta^2 x^2 + 2\theta(1-\theta)xy + (1-\theta)^2 y^2$$

$$\theta f(x) + (1-\theta) f(y) = \theta x^2 + (1-\theta) y^2$$

$$f(\theta x + (1-\theta) y) - [\theta f(x) + (1-\theta) f(y)] = -\theta(1-\theta)(x-y)^2 \leq 0$$

**Bước 2: $$f(x) = e^{ax}$$**

**Điều kiện bậc hai:** $$f&apos;&apos;(x) = a^2 e^{ax} \geq 0$$ với mọi $$x \in \mathbb{R}$$ $$\Rightarrow$$ lồi trên $$\mathbb{R}$$ (lồi chặt khi $$a \neq 0$$).

**Bước 3: $$f(x) = x \log x$$**

**Miền xác định:** $$\mathbb{R}_{++}$$ ($$x &amp;gt; 0$$).

**Đạo hàm:** $$f&apos;(x) = \log x + 1$$, $$f&apos;&apos;(x) = \frac{1}{x} &amp;gt; 0$$ với $$x &amp;gt; 0$$ $$\Rightarrow$$ lồi chặt trên $$\mathbb{R}_{++}$$.

**Bước 4: $$f(x) = -\log x$$**

**Đạo hàm bậc hai:** $$f&apos;&apos;(x) = \frac{1}{x^2} &amp;gt; 0$$ với $$x &amp;gt; 0$$ $$\Rightarrow$$ lồi chặt trên $$\mathbb{R}_{++}$$.

**Bước 5: $$f(x) = x^p$$ với $$p \geq 1$$**

- **Khi $$p = 1$$:** $$f(x) = x$$ là hàm tuyến tính $$\Rightarrow$$ lồi.
- **Khi $$p &amp;gt; 1$$:** $$f&apos;&apos;(x) = p(p-1)x^{p-2} \geq 0$$ với $$x &amp;gt; 0$$ (và liên tục tại $$0$$) $$\Rightarrow$$ lồi trên $$\mathbb{R}_+$$.

**Bước 6: $$f(x) = |x|^p$$ với $$p \geq 1$$**

Hàm có tính đối xứng $$f(-x) = f(x)$$, tuy nhiên lồi trên từng nửa trục chưa đủ để kết luận lồi trên toàn bộ $$\mathbb{R}$$. Lập luận chặt chẽ: viết $$f(x) = g(|x|)$$ với $$g(t) = t^p$$ là hàm lồi và **không giảm** trên $$\mathbb{R}_+$$, còn $$|x|$$ là hàm lồi trên $$\mathbb{R}$$. Theo quy tắc hợp thành, hợp thành của hàm lồi không giảm với hàm lồi là hàm lồi, nên $$|x|^p$$ lồi trên $$\mathbb{R}$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-các-phép-toán-bảo-toàn-tính-lồi&quot;&gt;📝 &lt;strong&gt;Bài tập 2: Các phép toán bảo toàn tính lồi&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 3.2 từ Boyd &amp;amp; Vandenberghe)
Cho các hàm lồi \(f, g: \mathbb{R}^n \to \mathbb{R}\). Xét tính lồi của:&lt;/p&gt;

&lt;p&gt;a) \(h(x) = \alpha f(x) + \beta g(x)\) với \(\alpha, \beta \geq 0\)&lt;/p&gt;

&lt;p&gt;b) \(h(x) = \max\{f(x), g(x)\}\)&lt;/p&gt;

&lt;p&gt;c) \(h(x) = f(Ax + b)\) với \(A \in \mathbb{R}^{n \times m}\), \(b \in \mathbb{R}^n\)&lt;/p&gt;

&lt;p&gt;d) \(h(x) = \inf_{y \in C} f(x, y)\) với \(C\) là tập lồi và \(f(x, y)\) lồi đồng thời theo \((x, y)\)&lt;/p&gt;

&lt;p&gt;e) \(h(x) = \int_0^\infty f(x, t)\, dt\) (khi tích phân tồn tại và \(f(x, t)\) lồi theo \(x\) với mọi \(t \ge 0\))&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh tính lồi cho từng phép toán&lt;/li&gt;
  &lt;li&gt;Nêu phản ví dụ khi bỏ đi các giả thiết cần thiết&lt;/li&gt;
  &lt;li&gt;Đưa ra ví dụ cụ thể minh họa&lt;/li&gt;
  &lt;li&gt;Phân tích điều kiện để thu được tính lồi chặt&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Tổng trọng số không âm — LỒI**

**Định lý:** Nếu $$f, g$$ lồi và $$\alpha, \beta \geq 0$$, thì $$h(x) = \alpha f(x) + \beta g(x)$$ lồi.

**Chứng minh:**
$$h(\theta x + (1-\theta) y) = \alpha f(\theta x + (1-\theta) y) + \beta g(\theta x + (1-\theta) y)$$
$$\leq \alpha[\theta f(x) + (1-\theta) f(y)] + \beta[\theta g(x) + (1-\theta) g(y)]$$
$$= \theta[\alpha f(x) + \beta g(x)] + (1-\theta)[\alpha f(y) + \beta g(y)]$$
$$= \theta h(x) + (1-\theta) h(y)$$

**Bước 2: Maximum theo điểm — LỒI**

**Định lý:** $$h(x) = \max\{f(x), g(x)\}$$ lồi nếu $$f, g$$ lồi.

**Chứng minh:**
$$h(\theta x + (1-\theta) y) = \max\{f(\theta x + (1-\theta) y), g(\theta x + (1-\theta) y)\}$$
$$\leq \max\{\theta f(x) + (1-\theta) f(y), \theta g(x) + (1-\theta) g(y)\}$$
$$\leq \theta \max\{f(x), g(x)\} + (1-\theta) \max\{f(y), g(y)\}$$
$$= \theta h(x) + (1-\theta) h(y)$$

**Tổng quát hóa:** $$\sup_{t \in T} f_t(x)$$ lồi nếu mỗi $$f_t$$ đều lồi.

**Bước 3: Hợp thành với ánh xạ affine — LỒI**

**Định lý:** $$h(x) = f(Ax + b)$$ lồi nếu $$f$$ lồi.

**Chứng minh:**
$$h(\theta x + (1-\theta) y) = f(A(\theta x + (1-\theta) y) + b)$$
$$= f(\theta(Ax + b) + (1-\theta)(Ay + b))$$
$$\leq \theta f(Ax + b) + (1-\theta) f(Ay + b)$$
$$= \theta h(x) + (1-\theta) h(y)$$

**Bước 4: Cực tiểu hóa từng phần — LỒI**

**Định lý:** $$h(x) = \inf_{y \in C} f(x, y)$$ lồi theo $$x$$ nếu $$f(x, y)$$ lồi đồng thời theo $$(x, y)$$ và $$C$$ là tập lồi.

**Chứng minh:** Với mọi $$\epsilon &amp;gt; 0$$, chọn $$y_1, y_2 \in C$$ sao cho $$f(x_k, y_k) \leq h(x_k) + \epsilon$$ ($$k = 1, 2$$). Vì $$C$$ lồi nên $$\bar{y} = \theta y_1 + (1-\theta) y_2 \in C$$, do đó:
$$h(\theta x_1 + (1-\theta) x_2) \leq f(\theta x_1 + (1-\theta) x_2, \bar{y})$$
$$\leq \theta f(x_1, y_1) + (1-\theta) f(x_2, y_2) \leq \theta h(x_1) + (1-\theta) h(x_2) + \epsilon$$
Cho $$\epsilon \to 0$$, ta thu được:
$$h(\theta x_1 + (1-\theta) x_2) \leq \theta h(x_1) + (1-\theta) h(x_2)$$
(Lưu ý: cần chọn hai điểm $$y_1, y_2$$ riêng biệt và dùng tính lồi **đồng thời** theo $$(x, y)$$; dùng chung một $$y$$ không đủ để chứng minh.)

**Bước 5: Tích phân — LỒI**

**Định lý:** $$h(x) = \int_0^\infty f(x, t)\, dt$$ lồi nếu $$f(x, t)$$ lồi theo $$x$$ với mọi $$t \ge 0$$.

**Chứng minh:** Với mỗi $$t \ge 0$$, $$f(\theta x + (1-\theta) y, t) \leq \theta f(x, t) + (1-\theta) f(y, t)$$. Lấy tích phân hai vế theo $$t$$ (tích phân có tính tuyến tính và bảo toàn bất đẳng thức), ta thu được $$h(\theta x + (1-\theta) y) \leq \theta h(x) + (1-\theta) h(y)$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-hàm-liên-hợp&quot;&gt;📝 &lt;strong&gt;Bài tập 3: Hàm liên hợp&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 3.3 từ Boyd &amp;amp; Vandenberghe)
Tính hàm liên hợp \(f^*(y) = \sup_x (y^T x - f(x))\) cho các hàm sau:&lt;/p&gt;

&lt;p&gt;a) \(f(x) = \frac{1}{2}x^T Q x\) với \(Q \succ 0\)&lt;/p&gt;

&lt;p&gt;b) \(f(x) = \lVert x \rVert_2\)&lt;/p&gt;

&lt;p&gt;c) \(f(x) = \lVert x \rVert_1\)&lt;/p&gt;

&lt;p&gt;d) \(f(x) = \log \sum_{i=1}^n e^{x_i}\) (log-sum-exp)&lt;/p&gt;

&lt;p&gt;e) \(f(x) = \max_{i=1,\ldots,n} x_i\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Tính hàm liên hợp bằng cách giải bài toán cực đại hóa&lt;/li&gt;
  &lt;li&gt;Kiểm tra các tính chất đối ngẫu liên hợp&lt;/li&gt;
  &lt;li&gt;Xác định miền xác định của từng hàm liên hợp&lt;/li&gt;
  &lt;li&gt;Giải thích ý nghĩa hình học&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Hàm bậc hai**
$$f(x) = \frac{1}{2}x^T Q x$$ với $$Q \succ 0$$

**Bài toán tối ưu:** $$\sup_x (y^T x - \frac{1}{2}x^T Q x)$$

**Điều kiện bậc nhất:** $$y - Qx = 0 \Rightarrow x^* = Q^{-1} y$$

**Hàm liên hợp:**
$$f^*(y) = y^T Q^{-1} y - \frac{1}{2}y^T Q^{-1} Q Q^{-1} y = \frac{1}{2}y^T Q^{-1} y$$

**Miền xác định:** $$\mathbb{R}^n$$ (do $$Q \succ 0$$).

**Bước 2: Chuẩn Euclidean**
$$f(x) = \lVert x \rVert_2$$

**Bài toán tối ưu:** $$\sup_x (y^T x - \lVert x \rVert_2)$$

**Phân tích các trường hợp:**
- Nếu $$\lVert y \rVert_2 \leq 1$$: theo bất đẳng thức Cauchy–Schwarz, $$y^T x - \lVert x \rVert_2 \leq (\lVert y \rVert_2 - 1)\lVert x \rVert_2 \leq 0$$, nên supremum bằng $$0$$ (đạt tại $$x = 0$$).
- Nếu $$\lVert y \rVert_2 &amp;gt; 1$$: chọn $$x = t y$$ với $$t \to +\infty$$, biểu thức tiến tới $$+\infty$$.

**Hàm liên hợp:**
$$f^*(y) = \begin{cases} 0 &amp;amp; \text{nếu } \lVert y \rVert_2 \leq 1 \\ +\infty &amp;amp; \text{nếu } \lVert y \rVert_2 &amp;gt; 1 \end{cases}$$

**Miền xác định:** Hình cầu đơn vị $$\{y : \lVert y \rVert_2 \leq 1\}$$.

**Bước 3: Chuẩn $$\ell_1$$**
$$f(x) = \lVert x \rVert_1 = \sum_{i=1}^n |x_i|$$

Bài toán tách rời theo từng tọa độ: $$\sup_{x_i} (y_i x_i - |x_i|)$$ cho mỗi $$i$$.
- Nếu $$|y_i| \leq 1$$: supremum bằng 0 (đạt tại $$x_i = 0$$).
- Nếu $$|y_i| &amp;gt; 1$$: supremum bằng $$+\infty$$.

**Hàm liên hợp:**
$$f^*(y) = \begin{cases} 0 &amp;amp; \text{nếu } \lVert y \rVert_\infty \leq 1 \\ +\infty &amp;amp; \text{nếu } \lVert y \rVert_\infty &amp;gt; 1 \end{cases}$$

**Bước 4: Hàm log-sum-exp**
$$f(x) = \log \sum_{i=1}^n e^{x_i}$$

**Bài toán tối ưu:** $$\sup_x \left(\sum_{i=1}^n y_i x_i - \log \sum_{i=1}^n e^{x_i}\right)$$

**Điều kiện bậc nhất:** $$y_i = \frac{e^{x_i}}{\sum_j e^{x_j}}$$, suy ra $$y$$ phải là vector xác suất ($$y \geq 0$$, $$\sum y_i = 1$$).

**Hàm liên hợp:** $$f^*(y) = \sum_{i=1}^n y_i \log y_i$$ (hàm entropy âm, với quy ước $$0 \log 0 = 0$$).

**Miền xác định:** Đơn hình xác suất $$\{y : y \geq 0, \sum y_i = 1\}$$.

**Bước 5: Hàm max**
$$f(x) = \max_{i=1,\ldots,n} x_i$$

**Hàm liên hợp:**
$$f^*(y) = \begin{cases} 0 &amp;amp; \text{nếu } y \geq 0, \sum y_i = 1 \\ +\infty &amp;amp; \text{trường hợp khác} \end{cases}$$

**Miền xác định:** Đơn hình xác suất.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-dưới-vi-phân-và-điều-kiện-tối-ưu&quot;&gt;📝 &lt;strong&gt;Bài tập 4: Dưới vi phân và điều kiện tối ưu&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 3.4 từ Boyd &amp;amp; Vandenberghe)
Tính tập dưới vi phân \(\partial f(x) = \{g : f(y) \geq f(x) + g^T(y - x), \forall y\}\) cho:&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;a) $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;b) \(f(x) = \max\{0, x\}\) (hàm ReLU)&lt;/p&gt;

&lt;p&gt;c) \(f(x) = \lVert x \rVert_1\)&lt;/p&gt;

&lt;p&gt;d) \(f(x) = \lVert x \rVert_2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Tính tường minh các tập dưới vi phân&lt;/li&gt;
  &lt;li&gt;Kiểm tra điều kiện tối ưu \(0 \in \partial f(x^*)\)&lt;/li&gt;
  &lt;li&gt;Phân tích tại các điểm không khả vi&lt;/li&gt;
  &lt;li&gt;Áp dụng vào bài toán tối ưu&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Giá trị tuyệt đối $$f(x) = |x|$$**

- **Khi $$x &amp;gt; 0$$:** $$f$$ khả vi, $$\partial f(x) = \{1\}$$.
- **Khi $$x &amp;lt; 0$$:** $$f$$ khả vi, $$\partial f(x) = \{-1\}$$.
- **Khi $$x = 0$$:** Điểm không khả vi. Điều kiện $$\partial f(0) = \{g : |y| \geq g \cdot y, \forall y\}$$ tương đương $$|g| \leq 1$$, suy ra $$\partial f(0) = [-1, 1]$$.

**Bước 2: Hàm ReLU $$f(x) = \max\{0, x\}$$**

- **Khi $$x &amp;gt; 0$$:** $$f(x) = x$$, $$\partial f(x) = \{1\}$$.
- **Khi $$x &amp;lt; 0$$:** $$f(x) = 0$$, $$\partial f(x) = \{0\}$$.
- **Khi $$x = 0$$:** $$\partial f(0) = \{g : \max\{0, y\} \geq g \cdot y, \forall y\}$$.
  - Với $$y &amp;gt; 0$$: $$y \geq g \cdot y \Rightarrow g \leq 1$$.
  - Với $$y &amp;lt; 0$$: $$0 \geq g \cdot y \Rightarrow g \geq 0$$.
  - Suy ra $$\partial f(0) = [0, 1]$$.

**Bước 3: Chuẩn $$\ell_1$$ $$f(x) = \lVert x \rVert_1$$**

Viết $$f(x) = \sum_{i=1}^n |x_i|$$. Vì hàm tách rời theo từng tọa độ nên:
$$\partial f(x) = \partial f_1(x_1) \times \cdots \times \partial f_n(x_n)$$

với $$\partial f_i(x_i) = \begin{cases} \{1\} &amp;amp; \text{nếu } x_i &amp;gt; 0 \\ \{-1\} &amp;amp; \text{nếu } x_i &amp;lt; 0 \\ [-1, 1] &amp;amp; \text{nếu } x_i = 0 \end{cases}$$

Tóm lại: $$\partial f(x) = \{g : g_i = \text{sign}(x_i) \text{ nếu } x_i \neq 0,\; |g_i| \leq 1 \text{ nếu } x_i = 0\}$$.

**Bước 4: Chuẩn Euclidean $$f(x) = \lVert x \rVert_2$$**

- **Khi $$x \neq 0$$:** $$f$$ khả vi, $$\partial f(x) = \left\{\frac{x}{\lVert x \rVert_2}\right\}$$.
- **Khi $$x = 0$$:** $$\partial f(0) = \{g : \lVert y \rVert_2 \geq g^T y, \forall y\}$$. Theo bất đẳng thức Cauchy–Schwarz, điều kiện này tương đương $$\lVert g \rVert_2 \leq 1$$, nên $$\partial f(0) = \{g : \lVert g \rVert_2 \leq 1\}$$ (hình cầu đơn vị).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-bất-đẳng-thức-jensen-và-ứng-dụng&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Bất đẳng thức Jensen và ứng dụng&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 3.5 từ Boyd &amp;amp; Vandenberghe)
a) Chứng minh bất đẳng thức Jensen: Nếu \(f\) là hàm lồi, \(\lambda_i \geq 0\) và \(\sum_{i=1}^n \lambda_i = 1\), thì:
\(f\left(\sum_{i=1}^n \lambda_i x_i\right) \leq \sum_{i=1}^n \lambda_i f(x_i)\)&lt;/p&gt;

&lt;p&gt;b) Áp dụng bất đẳng thức Jensen để chứng minh:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bất đẳng thức trung bình cộng – trung bình nhân (AM–GM): \(\frac{x_1 + \cdots + x_n}{n} \geq \sqrt[n]{x_1 \cdots x_n}\) (với \(x_i &amp;gt; 0\))&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Bất đẳng thức Hölder: $$\sum_{i=1}^n&lt;/td&gt;
          &lt;td&gt;x_i y_i&lt;/td&gt;
          &lt;td&gt;\leq \left(\sum_{i=1}^n&lt;/td&gt;
          &lt;td&gt;x_i&lt;/td&gt;
          &lt;td&gt;^p\right)^{1/p} \left(\sum_{i=1}^n&lt;/td&gt;
          &lt;td&gt;y_i&lt;/td&gt;
          &lt;td&gt;^q\right)^{1/q}\((với\)p, q &amp;gt; 1, \frac{1}{p} + \frac{1}{q} = 1$$)&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c) Suy ra bất đẳng thức log-sum&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh chặt chẽ bằng quy nạp&lt;/li&gt;
  &lt;li&gt;Giải thích ý nghĩa hình học&lt;/li&gt;
  &lt;li&gt;Nêu ứng dụng trong lý thuyết xác suất&lt;/li&gt;
  &lt;li&gt;Mở rộng sang trường hợp liên tục&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Chứng minh bất đẳng thức Jensen**

**Trường hợp cơ sở ($$n = 2$$):** Chính là định nghĩa hàm lồi.

**Bước quy nạp:** Giả sử bất đẳng thức đúng với $$n-1$$ điểm, ta chứng minh cho $$n$$ điểm. Nếu $$\lambda_n = 1$$ thì các $$\lambda_i = 0$$ ($$i &amp;lt; n$$) nên bất đẳng thức hiển nhiên đúng. Ngược lại, đặt $$\mu = \sum_{i=1}^{n-1} \lambda_i = 1 - \lambda_n &amp;gt; 0$$:

$$f\left(\sum_{i=1}^n \lambda_i x_i\right) = f\left(\mu \cdot \frac{\sum_{i=1}^{n-1} \lambda_i x_i}{\mu} + (1-\mu) x_n\right)$$

Theo tính lồi của $$f$$:
$$\leq \mu f\left(\frac{\sum_{i=1}^{n-1} \lambda_i x_i}{\mu}\right) + (1-\mu) f(x_n)$$

Theo giả thiết quy nạp:
$$\leq \mu \sum_{i=1}^{n-1} \frac{\lambda_i}{\mu} f(x_i) + \lambda_n f(x_n) = \sum_{i=1}^n \lambda_i f(x_i)$$

**Bước 2: Bất đẳng thức AM–GM**

Xét hàm lồi $$f(x) = -\log x$$ trên $$\mathbb{R}_{++}$$ với các trọng số bằng nhau $$\lambda_i = \frac{1}{n}$$:

$$-\log\left(\frac{x_1 + \cdots + x_n}{n}\right) \leq \frac{1}{n}\sum_{i=1}^n (-\log x_i) = -\frac{1}{n}\log(x_1 \cdots x_n)$$

Đổi dấu hai vế và lấy hàm mũ:
$$\log\left(\frac{x_1 + \cdots + x_n}{n}\right) \geq \log\sqrt[n]{x_1 \cdots x_n} \Rightarrow \frac{x_1 + \cdots + x_n}{n} \geq \sqrt[n]{x_1 \cdots x_n}$$

**Bước 3: Bất đẳng thức Hölder**

Với hai số mũ liên hợp $$\frac{1}{p} + \frac{1}{q} = 1$$ ($$p, q &amp;gt; 1$$), áp dụng bất đẳng thức Jensen cho hàm lồi $$f(t) = e^t$$ với trọng số $$\frac{1}{p}$$ và $$\frac{1}{q}$$ thu được **bất đẳng thức Young** cho mọi $$a, b &amp;gt; 0$$:
$$ab = e^{\frac{1}{p}\log a^p + \frac{1}{q}\log b^q} \leq \frac{1}{p}a^p + \frac{1}{q}b^q$$

Chuẩn hóa bằng cách đặt $$a_i = \frac{|x_i|}{\lVert x \rVert_p}$$ và $$b_i = \frac{|y_i|}{\lVert y \rVert_q}$$ rồi cộng theo $$i$$:
$$\sum_i a_i b_i \leq \frac{1}{p}\sum_i a_i^p + \frac{1}{q}\sum_i b_i^q = \frac{1}{p} + \frac{1}{q} = 1$$
hay tương đương:
$$\sum |x_i y_i| \leq \left(\sum |x_i|^p\right)^{1/p} \left(\sum |y_i|^q\right)^{1/q}$$

**Bước 4: Bất đẳng thức log-sum**

**Phát biểu:** Với mọi $$a_i, b_i &amp;gt; 0$$:
$$\sum_{i=1}^n a_i \log \frac{a_i}{b_i} \geq \left(\sum_{i=1}^n a_i\right) \log \frac{\sum_{i=1}^n a_i}{\sum_{i=1}^n b_i}$$

**Chứng minh:** Áp dụng bất đẳng thức Jensen cho hàm lồi $$f(t) = t \log t$$ tại các điểm $$t_i = \frac{a_i}{b_i}$$ với các trọng số $$\lambda_i = \frac{b_i}{\sum_j b_j}$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-6-hàm-giả-lồi&quot;&gt;📝 &lt;strong&gt;Bài tập 6: Hàm giả lồi&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 3.6 từ Boyd &amp;amp; Vandenberghe)
a) Kiểm tra tính giả lồi của các hàm sau:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(x) = \frac{x_1}{x_2}\) trên \(\{x : x_2 &amp;gt; 0\}\)&lt;/li&gt;
  &lt;li&gt;\(f(x) = x_1^2 / x_2\) trên \(\{x : x_2 &amp;gt; 0\}\)&lt;/li&gt;
  &lt;li&gt;\(f(x) = \log(x_1) - \log(x_2)\) trên \(\mathbb{R}_{++}^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;b) Chứng minh \(f\) giả lồi \(\Leftrightarrow\) mọi tập mức dưới \(\{x \in \text{dom}f : f(x) \leq \alpha\}\) đều là tập lồi&lt;/p&gt;

&lt;p&gt;c) Nêu các phép toán bảo toàn tính giả lồi&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Kiểm tra bằng phương pháp phân tích tập mức dưới&lt;/li&gt;
  &lt;li&gt;Kiểm tra điều kiện bậc nhất&lt;/li&gt;
  &lt;li&gt;Phân tích các phép biến đổi đơn điệu&lt;/li&gt;
  &lt;li&gt;So sánh với tính lồi thông thường&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Hàm tỉ số $$f(x) = \frac{x_1}{x_2}$$**

**Tập mức dưới:** $$S_\alpha = \{x : x_1 \leq \alpha x_2,\; x_2 &amp;gt; 0\} = \{x : x_1 - \alpha x_2 \leq 0,\; x_2 &amp;gt; 0\}$$.

Đây là giao của hai nửa không gian nên là tập lồi với mọi $$\alpha \in \mathbb{R}$$ $$\Rightarrow f$$ là hàm giả lồi.

**Bước 2: Hàm $$f(x) = \frac{x_1^2}{x_2}$$**

**Tập mức dưới:** $$S_\alpha = \{x : x_1^2 \leq \alpha x_2,\; x_2 &amp;gt; 0\}$$.
- **Với $$\alpha &amp;lt; 0$$:** $$S_\alpha = \emptyset$$ (tập rỗng, là tập lồi).
- **Với $$\alpha = 0$$:** $$S_0 = \{x : x_1 = 0,\; x_2 &amp;gt; 0\}$$ (một tia mở, là tập lồi).
- **Với $$\alpha &amp;gt; 0$$:** $$S_\alpha = \{x : |x_1| \leq \sqrt{\alpha x_2},\; x_2 &amp;gt; 0\}$$ là tập lồi (thực tế $$x_1^2/x_2$$ còn là hàm lồi, vì là hàm phối cảnh của $$x_1^2$$).

$$\Rightarrow f$$ là hàm giả lồi.

**Bước 3: Hiệu logarithm $$f(x) = \log x_1 - \log x_2$$**

Viết lại thành $$f(x) = \log\left(\frac{x_1}{x_2}\right)$$. Vì $$\log$$ là hàm đơn điệu tăng và $$\frac{x_1}{x_2}$$ là hàm giả lồi trên $$\mathbb{R}_{++}^2$$, nên $$f$$ cũng là hàm giả lồi.

**Bước 4: Định lý đặc trưng**

**Định lý:** $$f$$ thỏa mãn bất đẳng thức Jensen biến đổi $$\Leftrightarrow$$ mọi tập mức dưới $$S_\alpha$$ đều là tập lồi.

**Chứng minh ($$\Rightarrow$$):** Với mọi $$x, y \in S_\alpha$$, ta có $$f(x) \leq \alpha$$ và $$f(y) \leq \alpha$$. Khi đó:
$$f(\theta x + (1-\theta) y) \leq \max\{f(x), f(y)\} \leq \alpha \Rightarrow \theta x + (1-\theta) y \in S_\alpha$$

**Chứng minh ($$\Leftarrow$$):** Đặt $$\alpha = \max\{f(x), f(y)\}$$, khi đó $$x, y \in S_\alpha$$. Vì $$S_\alpha$$ lồi nên $$\theta x + (1-\theta) y \in S_\alpha$$, suy ra:
$$f(\theta x + (1-\theta) y) \leq \alpha = \max\{f(x), f(y)\}$$

**Bước 5: Các phép toán bảo toàn tính giả lồi**
- **Maximum trọng số không âm:** $$\max\{w_1 f_1, w_2 f_2\}$$ ($$w_1, w_2 \ge 0$$) là giả lồi.
- **Hợp thành với hàm không giảm:** $$g \circ f$$ là giả lồi nếu $$g$$ không giảm và $$f$$ giả lồi.
- **Cực tiểu hóa từng phần:** $$\inf_{y \in C} f(x, y)$$ là giả lồi nếu $$f(x, y)$$ giả lồi đồng thời theo $$(x, y)$$ và $$C$$ lồi.
- **Lưu ý về phép cộng:** Tổng của hai hàm giả lồi nhìn chung **không** bảo toàn tính giả lồi.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-7-hàm-log-lõm-và-log-lồi&quot;&gt;📝 &lt;strong&gt;Bài tập 7: Hàm log-lõm và log-lồi&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 3.7 từ Boyd &amp;amp; Vandenberghe)
a) Kiểm tra tính log-lõm / log-lồi của:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Mật độ Gauss: \(f(x) = e^{-\frac{1}{2}(x-\mu)^T \Sigma^{-1} (x-\mu)}\) (với \(\Sigma \succ 0\))&lt;/li&gt;
  &lt;li&gt;Hàm Gamma: \(\Gamma(x) = \int_0^\infty t^{x-1} e^{-t}\, dt\) (lưu ý: \(\Gamma\) thực ra &lt;strong&gt;log-lồi&lt;/strong&gt;, không phải log-lõm, trên \(x &amp;gt; 0\): mỗi hàm \(x \mapsto t^{x-1}e^{-t} = e^{(x-1)\log t - t}\) là log-affine, và tích phân của họ hàm log-lồi là log-lồi)&lt;/li&gt;
  &lt;li&gt;Định thức: \(\det(X)\) trên \(\mathbb{S}_{++}^n\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;b) Nêu ứng dụng trong xác suất và thống kê&lt;/p&gt;

&lt;p&gt;c) Phân tích mối liên hệ với tính lồi&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Kiểm tra bằng điều kiện bậc hai&lt;/li&gt;
  &lt;li&gt;Phân tích các phép toán bảo toàn&lt;/li&gt;
  &lt;li&gt;Nêu các ứng dụng thống kê&lt;/li&gt;
  &lt;li&gt;Phân tích ý nghĩa đối với tối ưu hóa&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Mật độ Gauss**

$$f(x) = e^{-\frac{1}{2}(x-\mu)^T \Sigma^{-1} (x-\mu)} \implies \log f(x) = -\frac{1}{2}(x-\mu)^T \Sigma^{-1} (x-\mu)$$

**Hessian:** $$\nabla^2 \log f(x) = -\Sigma^{-1} \preceq 0 \Rightarrow \log f$$ lõm $$\Rightarrow f$$ là hàm log-lõm.

**Bước 2: Hàm định thức**

$$f(X) = \det(X)$$ trên $$\mathbb{S}_{++}^n \implies \log f(X) = \log \det(X)$$

Vì $$\log \det(X)$$ là hàm lõm trên $$\mathbb{S}_{++}^n$$ (có thể chứng minh qua phép hạn chế lên đường thẳng $$X + tV$$ và tính đạo hàm bậc hai), nên $$\det(X)$$ là hàm log-lõm.

**Bước 3: Các tính chất bảo toàn**
- **Phép nhân:** Nếu $$f, g$$ log-lõm thì $$fg$$ log-lõm (vì $$\log(fg) = \log f + \log g$$ là tổng hai hàm lõm).
- **Lũy thừa không âm:** Nếu $$f$$ log-lõm và $$\alpha \geq 0$$ thì $$f^\alpha$$ log-lõm.
- **Tích phân:** Tính log-lõm được bảo toàn khi lấy tích phân theo một nhóm biến (phân phối biên).

**Bước 4: Ứng dụng trong thống kê**
- **Ước lượng hợp lý cực đại (MLE):** Hàm hợp lý log-lõm dẫn đến hàm log-likelihood lõm, đưa bài toán MLE về bài toán tối ưu lồi.
- **Tính đơn đỉnh:** Mọi hàm mật độ log-lõm đều đơn đỉnh (giả lõm).
- **Bất đẳng thức tập trung:** Các độ đo xác suất log-lõm thỏa mãn nhiều bất đẳng thức tập trung chuẩn mực.

**Bước 5: Ý nghĩa trong tối ưu hóa**
- **Quy hoạch hình học (GP):** Sử dụng các hàm log-lồi.
- **Phương pháp hàm rào cản (barrier):** Hàm $$-\log \det(X)$$ là hàm rào cản chuẩn cho hình nón nửa xác định dương.
- **Họ phân phối mũ:** Hàm phân hoạch logarithm (log-partition function) là hàm lồi theo tham số tự nhiên.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-8-hàm-phối-cảnh-và-epigraph&quot;&gt;📝 &lt;strong&gt;Bài tập 8: Hàm phối cảnh và epigraph&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 3.8 từ Boyd &amp;amp; Vandenberghe)
a) Cho hàm lồi \(f: \mathbb{R}^n \to \mathbb{R}\). Chứng minh hàm phối cảnh:
\(g(x, t) = t f(x/t)\) với \(t &amp;gt; 0\)
là hàm lồi trên \(\{(x, t) : x/t \in \text{dom}(f),\; t &amp;gt; 0\}\)&lt;/p&gt;

&lt;p&gt;b) Áp dụng cho các ví dụ:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[f(x) = \lVert x \rVert_2 \Rightarrow g(x,t) = \lVert x \rVert_2\]
  &lt;/li&gt;
  &lt;li&gt;
\[f(x) = x^2 \Rightarrow g(x,t) = x^2/t\]
  &lt;/li&gt;
  &lt;li&gt;
\[f(x) = e^x \Rightarrow g(x,t) = t e^{x/t}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c) Chứng minh đặc trưng epigraph của tính lồi&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh chặt chẽ tính lồi của hàm phối cảnh&lt;/li&gt;
  &lt;li&gt;Giải thích ý nghĩa hình học&lt;/li&gt;
  &lt;li&gt;Liên hệ với hình nón bậc hai&lt;/li&gt;
  &lt;li&gt;Phân tích đặc trưng epigraph&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Tính lồi của hàm phối cảnh**

**Định lý:** Nếu $$f$$ lồi thì $$g(x,t) = tf(x/t)$$ lồi trên $$\text{dom}(g) = \{(x,t) : x/t \in \text{dom}(f),\; t &amp;gt; 0\}$$.

**Chứng minh:** Với mọi $$(x_1, t_1), (x_2, t_2) \in \text{dom}(g)$$ và $$\theta \in [0,1]$$:

$$g(\theta(x_1, t_1) + (1-\theta)(x_2, t_2)) = (\theta t_1 + (1-\theta) t_2) f\left(\frac{\theta x_1 + (1-\theta) x_2}{\theta t_1 + (1-\theta) t_2}\right)$$

Nhận xét rằng:
$$\frac{\theta x_1 + (1-\theta) x_2}{\theta t_1 + (1-\theta) t_2} = \frac{\theta t_1}{\theta t_1 + (1-\theta) t_2} \cdot \frac{x_1}{t_1} + \frac{(1-\theta) t_2}{\theta t_1 + (1-\theta) t_2} \cdot \frac{x_2}{t_2}$$

Đây là một tổ hợp lồi của $$\frac{x_1}{t_1}$$ và $$\frac{x_2}{t_2}$$ vì hai trọng số đều không âm và có tổng bằng 1. Do $$f$$ lồi:
$$f\left(\frac{\theta x_1 + (1-\theta) x_2}{\theta t_1 + (1-\theta) t_2}\right) \leq \frac{\theta t_1}{\theta t_1 + (1-\theta) t_2} f(x_1/t_1) + \frac{(1-\theta) t_2}{\theta t_1 + (1-\theta) t_2} f(x_2/t_2)$$

Nhân hai vế với $$\theta t_1 + (1-\theta) t_2 &amp;gt; 0$$, ta thu được:
$$g(\theta(x_1, t_1) + (1-\theta)(x_2, t_2)) \leq \theta t_1 f(x_1/t_1) + (1-\theta) t_2 f(x_2/t_2) = \theta g(x_1, t_1) + (1-\theta) g(x_2, t_2)$$

**Bước 2: Các ví dụ ứng dụng**

- **Ví dụ 1:** $$f(x) = \lVert x \rVert_2 \Rightarrow g(x,t) = t \lVert x/t \rVert_2 = \lVert x \rVert_2$$ (chuẩn bất biến qua phép phối cảnh).
- **Ví dụ 2:** $$f(x) = x^2 \Rightarrow g(x,t) = t(x/t)^2 = x^2/t$$. Epigraph của nó liên hệ trực tiếp với hình nón bậc hai:
  $$\{(x,t,s) : x^2/t \leq s,\; t &amp;gt; 0\} = \{(x,t,s) : \lVert (2x,\ s-t) \rVert_2 \leq s+t,\; t &amp;gt; 0\}$$
  (do $$(2x)^2 + (s-t)^2 \leq (s+t)^2 \Leftrightarrow x^2 \leq st$$).
- **Ví dụ 3:** $$f(x) = e^x \Rightarrow g(x,t) = te^{x/t}$$, dẫn tới hình nón mũ (exponential cone) trong tối ưu hóa hình nón.

**Bước 3: Đặc trưng epigraph**

**Định lý:** $$f$$ lồi $$\Leftrightarrow$$ $$\text{epi}(f) = \{(x,t) : x \in \text{dom}(f),\; f(x) \leq t\}$$ là tập lồi.

- **Chiều thuận ($$\Rightarrow$$):** Với $$(x_1, t_1), (x_2, t_2) \in \text{epi}(f)$$, ta có:
  $$f(\theta x_1 + (1-\theta) x_2) \leq \theta f(x_1) + (1-\theta) f(x_2) \leq \theta t_1 + (1-\theta) t_2$$
  suy ra $$(\theta x_1 + (1-\theta) x_2, \theta t_1 + (1-\theta) t_2) \in \text{epi}(f)$$.
- **Chiều đảo ($$\Leftarrow$$):** Với mọi $$x_1, x_2 \in \text{dom}(f)$$, chọn $$t_1 = f(x_1)$$ và $$t_2 = f(x_2)$$; tính lồi của $$\text{epi}(f)$$ suy ra ngay $$(\theta x_1 + (1-\theta)x_2, \theta f(x_1) + (1-\theta)f(x_2)) \in \text{epi}(f)$$, tức $$f(\theta x_1 + (1-\theta)x_2) \leq \theta f(x_1) + (1-\theta)f(x_2)$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-9-hàm-ma-trận-và-tính-lồi&quot;&gt;📝 &lt;strong&gt;Bài tập 9: Hàm ma trận và tính lồi&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 3.9 từ Boyd &amp;amp; Vandenberghe)
Phân tích tính lồi của các hàm ma trận sau:&lt;/p&gt;

&lt;p&gt;a) \(f(X) = \text{tr}(X)\) trên \(\mathbb{S}^n\)&lt;/p&gt;

&lt;p&gt;b) \(f(X) = \text{tr}(X^2)\) trên \(\mathbb{S}^n\)&lt;/p&gt;

&lt;p&gt;c) \(f(X) = \lambda_{\max}(X)\) trên \(\mathbb{S}^n\)&lt;/p&gt;

&lt;p&gt;d) \(f(X) = \det(X)\) trên \(\mathbb{S}_{++}^n\)&lt;/p&gt;

&lt;p&gt;e) \(f(X) = -\log \det(X)\) trên \(\mathbb{S}_{++}^n\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Kiểm tra tính lồi / lõm&lt;/li&gt;
  &lt;li&gt;Tính tập dưới vi phân&lt;/li&gt;
  &lt;li&gt;Nêu ứng dụng trong quy hoạch nửa xác định (SDP)&lt;/li&gt;
  &lt;li&gt;Liên hệ với các thuật toán tối ưu&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Hàm vết $$f(X) = \text{tr}(X)$$**

Hàm tuyến tính: $$\text{tr}(\theta X + (1-\theta) Y) = \theta \text{tr}(X) + (1-\theta) \text{tr}(Y)$$, nên vừa lồi vừa lõm. Dưới vi phân: $$\partial f(X) = \{I\}$$.

**Bước 2: Vết của bình phương $$f(X) = \text{tr}(X^2)$$**

Trên $$\mathbb{S}^n$$, $$\text{tr}(X^2) = \sum_{i,j} X_{ij}^2$$ là tổng các hàm bình phương lồi nên là hàm lồi chặt. Dưới vi phân: $$\partial f(X) = \{2X\}$$.

**Bước 3: Giá trị riêng lớn nhất $$f(X) = \lambda_{\max}(X)$$**

Theo đặc trưng biến phân: $$\lambda_{\max}(X) = \max_{\lVert v \rVert_2 = 1} v^T X v$$. Đây là giá trị lớn nhất theo điểm của họ các hàm tuyến tính $$X \mapsto v^T X v$$ nên là hàm lồi.

**Dưới vi phân:** $$\partial f(X) = \text{conv}\{vv^T : v \text{ là vector riêng đơn vị ứng với } \lambda_{\max}(X)\}$$.

**Bước 4: Hàm định thức $$f(X) = \det(X)$$**

Vì $$\log \det(X)$$ lõm trên $$\mathbb{S}_{++}^n$$ nên $$\det(X)$$ là hàm log-lõm, nhưng bản thân $$\det(X)$$ không lồi cũng không lõm trên $$\mathbb{S}_{++}^n$$ (khi $$n \ge 2$$). Tuy nhiên, trung bình nhân các giá trị riêng $$\det(X)^{1/n} = (\prod \lambda_i)^{1/n}$$ là hàm lõm.

**Bước 5: Logarithm âm của định thức $$f(X) = -\log \det(X)$$**

Hàm $$-\log \det(X)$$ lồi chặt trên $$\mathbb{S}_{++}^n$$, với đạo hàm $$\partial f(X) = \{-X^{-1}\}$$ và dạng bậc hai của Hessian:
$$\nabla^2 f(X)[H, H] = \text{tr}(X^{-1} H X^{-1} H) &amp;gt; 0 \quad \text{với mọi } H \in \mathbb{S}^n, H \neq 0$$

**Ứng dụng:**
- **Hàm rào cản trong SDP:** $$-\log \det(X)$$ làm hàm rào cản cho ràng buộc $$X \succ 0$$ trong các phương pháp điểm trong.
- **Ước lượng hợp lý cực đại:** Ước lượng ma trận hiệp phương sai.
- **Thiết kế thí nghiệm tối ưu:** Thiết kế tối ưu kiểu D (D-optimal design).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-10-ứng-dụng-trong-tối-ưu-hóa-lồi&quot;&gt;📝 &lt;strong&gt;Bài tập 10: Ứng dụng trong tối ưu hóa lồi&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 3.10 từ Boyd &amp;amp; Vandenberghe)
Phát biểu các bài toán sau dưới dạng bài toán tối ưu lồi:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Hồi quy vững (robust regression):&lt;/strong&gt; Cực tiểu hóa tổng các hàm mất mát Huber
b) &lt;strong&gt;Cực đại hóa entropy:&lt;/strong&gt; Với các ràng buộc mô-men tuyến tính
c) &lt;strong&gt;Cực đại hóa trung bình nhân:&lt;/strong&gt; \(\max \prod_{i=1}^n x_i^{1/n}\) với ràng buộc tuyến tính
d) &lt;strong&gt;Cực tiểu hóa entropy tương đối:&lt;/strong&gt; \(\min \sum_{i=1}^n x_i \log(x_i/y_i)\) với ràng buộc tuyến tính&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Xây dựng dạng bài toán tối ưu lồi tương ứng&lt;/li&gt;
  &lt;li&gt;Phân tích điều kiện tối ưu&lt;/li&gt;
  &lt;li&gt;Đề xuất thuật toán giải&lt;/li&gt;
  &lt;li&gt;Nêu ứng dụng thực tế&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Hồi quy vững**

**Bài toán:** $$\min_\beta \sum_{i=1}^n \phi(y_i - x_i^T \beta)$$ với hàm mất mát Huber:
$$\phi(u) = \begin{cases} \frac{1}{2}u^2 &amp;amp; |u| \leq M \\ M|u| - \frac{1}{2}M^2 &amp;amp; |u| &amp;gt; M \end{cases}$$

Hàm $$\phi$$ lồi vì là hàm bậc hai từng khúc có đạo hàm không giảm. Có thể viết lại thành bài toán quy hoạch bậc hai (QP):
$$\min_{\beta,r,s} \frac{1}{2}\sum_{i=1}^n r_i^2 + M\sum_{i=1}^n s_i$$
$$\text{với ràng buộc} \quad |y_i - x_i^T \beta| \leq r_i + s_i, \quad 0 \leq r_i \leq M, \quad s_i \geq 0$$

**Bước 2: Cực đại hóa entropy**

**Bài toán:** $$\max_x -\sum_{i=1}^n x_i \log x_i \quad \text{với ràng buộc} \quad \sum_{i=1}^n a_{ij} x_i = b_j, \quad x_i \geq 0$$

**Dạng tối ưu lồi:** $$\min_x \sum_{i=1}^n x_i \log x_i$$

**Điều kiện tối ưu (khi nghiệm nằm trong miền dương):**
$$\log x_i + 1 + \sum_{j=1}^m \lambda_j a_{ij} = 0 \Rightarrow x_i^* = e^{-1 - \sum_j \lambda_j a_{ij}}$$
(phân phối cực đại entropy có dạng họ hàm mũ).

**Bước 3: Cực đại hóa trung bình nhân**

**Bài toán:** $$\max_{x \geq 0} \prod_{i=1}^n x_i^{1/n} \quad \text{với ràng buộc} \quad Ax \leq b$$

Lấy logarithm để chuyển về bài toán tương đương $$\max_x \frac{1}{n}\sum_{i=1}^n \log x_i$$, hay dạng tối ưu lồi:
$$\min_x -\sum_{i=1}^n \log x_i \quad \text{với ràng buộc} \quad Ax \leq b, \quad x &amp;gt; 0$$

Bài toán này phù hợp tự nhiên với phương pháp rào cản logarithm, và xuất hiện trong thiết kế thí nghiệm tối ưu cũng như bài toán thương lượng Nash.

**Bước 4: Cực tiểu hóa entropy tương đối**

**Bài toán:** $$\min_x \sum_{i=1}^n x_i \log \frac{x_i}{y_i} \quad \text{với ràng buộc} \quad Ax = b, \quad x \geq 0$$

Phân kỳ Kullback–Leibler (entropy tương đối) là hàm lồi theo biến thứ nhất $$x$$.

**Điều kiện tối ưu:**
$$\log \frac{x_i}{y_i} + 1 + (A^T \lambda)_i - \mu_i = 0$$ (với $$\mu \geq 0$$ là nhân tử của $$x \geq 0$$; khi nghiệm có $$x_i &amp;gt; 0$$ thì $$\mu_i = 0$$).

**Dạng nghiệm:** $$x_i^* = y_i e^{-(A^T \lambda^*)_i - 1}$$.

**Ứng dụng:** Lý thuyết thông tin (dung lượng kênh), thống kê (ước lượng hợp lý cực đại có phân phối tiên nghiệm) và học máy (tối ưu hóa có chuẩn hóa).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-mẹo-thực-hành&quot;&gt;💡 Mẹo thực hành&lt;/h2&gt;

&lt;h4 id=&quot;khi-kiểm-tra-tính-lồi&quot;&gt;&lt;strong&gt;Khi kiểm tra tính lồi:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bậc hai:&lt;/strong&gt; Kiểm tra \(f&apos;&apos;(x) \geq 0\) hoặc \(\nabla^2 f(x) \succeq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa trực tiếp:&lt;/strong&gt; Kiểm tra \(f(\theta x + (1-\theta) y) \leq \theta f(x) + (1-\theta) f(y)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc hợp thành:&lt;/strong&gt; Áp dụng các phép toán bảo toàn tính lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;khi-tính-hàm-liên-hợp&quot;&gt;&lt;strong&gt;Khi tính hàm liên hợp:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dùng định nghĩa:&lt;/strong&gt; Giải bài toán \(f^*(y) = \sup_x (y^T x - f(x))\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bậc nhất:&lt;/strong&gt; Tìm \(x^*\) thỏa mãn \(y \in \partial f(x^*)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa hình học:&lt;/strong&gt; Liên hệ với các siêu phẳng hỗ trợ epigraph của \(f\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;khi-làm-việc-với-dưới-vi-phân&quot;&gt;&lt;strong&gt;Khi làm việc với dưới vi phân:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp khả vi:&lt;/strong&gt; \(\partial f(x) = \{\nabla f(x)\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp không khả vi:&lt;/strong&gt; Áp dụng định nghĩa hoặc các quy tắc tính dưới vi phân.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện tối ưu:&lt;/strong&gt; \(x^*\) là điểm cực tiểu toàn cục khi và chỉ khi \(0 \in \partial f(x^*)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;định-nghĩa-và-tiêu-chuẩn-kiểm-tra-tính-lồi&quot;&gt;&lt;strong&gt;Định nghĩa và tiêu chuẩn kiểm tra tính lồi:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Điều kiện&lt;/th&gt;
      &lt;th&gt;Khi nào dùng&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Định nghĩa&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)\)&lt;/td&gt;
      &lt;td&gt;Chứng minh trực tiếp&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Bậc nhất&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(y) \geq f(x) + \nabla f(x)^T(y-x)\)&lt;/td&gt;
      &lt;td&gt;Hàm khả vi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Bậc hai&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\nabla^2 f(x) \succeq 0\)&lt;/td&gt;
      &lt;td&gt;Hàm khả vi hai lần&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Epigraph&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\text{epi}(f)\) là tập lồi&lt;/td&gt;
      &lt;td&gt;Tiếp cận hình học&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;các-phép-toán-bảo-toàn-tính-lồi&quot;&gt;&lt;strong&gt;Các phép toán bảo toàn tính lồi:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phép toán&lt;/th&gt;
      &lt;th&gt;Kết quả&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tổng trọng số không âm&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\sum \alpha_i f_i\) với \(\alpha_i \geq 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hợp thành với ánh xạ affine&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(Ax + b)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Maximum theo điểm&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(x) = \max\{f_1(x), \ldots, f_m(x)\}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Supremum theo điểm&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(g(x) = \sup_{y \in \mathcal{A}} f(x, y)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hợp thành tổng quát&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(h \circ g\) (\(h\) lồi không giảm, \(g\) lồi)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Cực tiểu hóa từng phần&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(g(x) = \inf_y f(x, y)\) nếu \(f\) lồi đồng thời theo \((x,y)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm phối cảnh&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(g(x, t) = tf(x/t)\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;các-ví-dụ-hàm-lồi-tiêu-biểu&quot;&gt;&lt;strong&gt;Các ví dụ hàm lồi tiêu biểu:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tên hàm&lt;/th&gt;
      &lt;th&gt;Biểu thức&lt;/th&gt;
      &lt;th&gt;Miền xác định&lt;/th&gt;
      &lt;th&gt;Lồi?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm mũ&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(e^{ax}\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}\)&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm lũy thừa&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(x^a\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}_{++}\)&lt;/td&gt;
      &lt;td&gt;✓ (\(a \geq 1\) hoặc \(a \leq 0\))&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Logarithm âm&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(-\log x\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}_{++}\)&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Chuẩn&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(|x|_p\) (\(p \ge 1\))&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^n\)&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm max&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\max\{x_1, \ldots, x_n\}\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^n\)&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm bậc hai&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(x^TQx\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^n\)&lt;/td&gt;
      &lt;td&gt;✓ (nếu \(Q \succeq 0\))&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Log-sum-exp&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\log(\sum e^{x_i})\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^n\)&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;hàm-liên-hợp&quot;&gt;&lt;strong&gt;Hàm liên hợp:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; \(f^*(y) = \sup_x (y^Tx - f(x))\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Fenchel:&lt;/strong&gt; \(f(x) + f^*(y) \geq x^Ty\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hợp kép:&lt;/strong&gt; \(f^{**} = f\) (nếu \(f\) đóng và lồi)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[(x^2/2)^* = y^2/2\]
      &lt;/li&gt;
      &lt;li&gt;\((\|x\|)^* = I_{\|y\|_* \leq 1}\) (hàm chỉ thị hình cầu đơn vị theo chuẩn đối ngẫu)&lt;/li&gt;
      &lt;li&gt;\((-\log x)^* = -\log(-y) - 1\) (với \(y &amp;lt; 0\))&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;dưới-vi-phân&quot;&gt;&lt;strong&gt;Dưới vi phân:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; \(g \in \partial f(x)\) nếu \(f(y) \geq f(x) + g^T(y-x)\) với mọi \(y\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện tối ưu:&lt;/strong&gt; \(x^*\) tối ưu \(\Leftrightarrow\) \(0 \in \partial f(x^*)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc tính toán:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\partial(\alpha f) = \alpha \partial f\) (với \(\alpha &amp;gt; 0\))&lt;/li&gt;
      &lt;li&gt;
\[\partial(f_1 + f_2) = \partial f_1 + \partial f_2\]
      &lt;/li&gt;
      &lt;li&gt;
\[\partial \max\{f_1, f_2\} = \text{conv}\{\partial f_i : f_i(x) = f(x)\}\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 Tài liệu tham khảo&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 3: Convex Functions&lt;/li&gt;
      &lt;li&gt;Exercises 3.1-3.54&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Rockafellar, R. T.&lt;/strong&gt; (1970). &lt;em&gt;Convex Analysis&lt;/em&gt;. Princeton University Press.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiriart-Urruty, J.-B., &amp;amp; Lemaréchal, C.&lt;/strong&gt; (1993). &lt;em&gt;Convex Analysis and Minimization Algorithms&lt;/em&gt;. Springer.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>03-09 Bài tập trắc nghiệm - Hàm lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_09_Quiz_Convex_Functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_09_Quiz_Convex_Functions</id>
   <content type="html">&lt;p&gt;Chương 03 là nơi tập trung nhiều câu hỏi “gài bẫy” kinh điển nhất trong các kỳ thi tối ưu hóa lồi: phân biệt lồi – lồi chặt – lồi mạnh, phân biệt hàm lồi với hàm giả lồi, nhớ đúng chiều quy tắc hợp thành \(h(g(x))\), và tính nhanh hàm liên hợp Fenchel \(f^*(y)\). Chỉ cần quên một điều kiện đơn điệu (như \(h\) phải &lt;em&gt;không giảm&lt;/em&gt;) là kết luận tính lồi có thể sai hoàn toàn!&lt;/p&gt;

&lt;p&gt;Trước khi bước vào bộ câu hỏi trắc nghiệm, hãy quét nhanh 4 chốt kiểm tra và tự tay phân loại 3 hàm số mẫu ngay bên dưới.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-chốt-kiểm-tra-nhanh-trước-khi-làm-quiz-chương-03&quot;&gt;Kiến thức cần nhớ: Bốn chốt kiểm tra nhanh trước khi làm Quiz Chương 03&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chốt 1 — Phân cấp lồi:&lt;/strong&gt; Lồi mạnh (\(f&apos;&apos; \ge m &amp;gt; 0\)) \(\implies\) Lồi chặt (\(f&apos;&apos; &amp;gt; 0\)) \(\implies\) Lồi (\(f&apos;&apos; \ge 0\)) \(\implies\) Giả lồi (mọi tập mức dưới lồi). Các chiều ngược lại đều &lt;strong&gt;sai&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chốt 2 — Quy tắc hợp thành \(h(g(x))\):&lt;/strong&gt; \(h\) lồi + không giảm + \(g\) lồi \(\implies\) lồi; \(h\) lồi + không tăng + \(g\) lõm \(\implies\) lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chốt 3 — Hàm liên hợp \(f^*(y)\):&lt;/strong&gt; Luôn là hàm lồi với &lt;em&gt;mọi&lt;/em&gt; \(f\); liên hợp của \(\frac{1}{2}x^T Q x\) (\(Q \succ 0\)) là \(\frac{1}{2}y^T Q^{-1} y\); liên hợp của chuẩn \(\|x\|\) là hàm chỉ thị của hình cầu đơn vị chuẩn đối ngẫu \(\|y\|_* \le 1\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chốt 4 — Log-lõm và Log-lồi:&lt;/strong&gt; Mọi hàm log-lồi đều lồi, nhưng hàm log-lõm &lt;em&gt;chưa chắc&lt;/em&gt; lõm (ví dụ mật độ Gauss hay \(x^2\) trên \(x &amp;gt; 0\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phân-loại-nhanh-3-hàm-bẫy-kinh-điển&quot;&gt;Giải thích: Phân loại nhanh 3 hàm bẫy kinh điển&lt;/h3&gt;

&lt;p&gt;Hãy kiểm tra tính lồi của 3 hàm sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hàm \(f(x) = -\sqrt{x}\) trên \(x &amp;gt; 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;(x) = -\frac{1}{2}x^{-1/2}\), \(f&apos;&apos;(x) = +\frac{1}{4}x^{-3/2} &amp;gt; 0\ \forall x &amp;gt; 0\).&lt;/li&gt;
      &lt;li&gt;Kết luận: &lt;strong&gt;Hàm lồi chặt&lt;/strong&gt; (đừng nhầm dấu trừ mà tưởng là lõm!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm \(g(x_1, x_2) = x_1 x_2\) trên \(\mathbb{R}^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ma trận Hessian: \(\nabla^2 g = \begin{pmatrix}0 &amp;amp; 1\\ 1 &amp;amp; 0\end{pmatrix}\), có hai giá trị riêng \(\lambda_1 = +1\) và \(\lambda_2 = -1\).&lt;/li&gt;
      &lt;li&gt;Kết luận: &lt;strong&gt;Không lồi, cũng không lõm&lt;/strong&gt; (mặt yên ngựa).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm \(h(x, y) = \frac{x^2}{y}\) trên miền \(y &amp;gt; 0\) (hàm quadratic-over-linear):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ma trận Hessian: \(\nabla^2 h(x, y) = \frac{2}{y^3}\begin{pmatrix}y^2 &amp;amp; -xy\\ -xy &amp;amp; x^2\end{pmatrix} = \frac{2}{y^3}\begin{pmatrix}y\\ -x\end{pmatrix}\begin{pmatrix}y &amp;amp; -x\end{pmatrix} \succeq 0\).&lt;/li&gt;
      &lt;li&gt;Kết luận: &lt;strong&gt;Hàm lồi&lt;/strong&gt; trên toàn nửa mặt phẳng \(y &amp;gt; 0\) (cũng chính là hàm phối cảnh của \(x^2\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra hiểu biết của bạn về hàm lồi, các tính chất cơ bản, phép toán bảo toàn tính lồi và hàm liên hợp.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-định-nghĩa-hàm-lồi&quot;&gt;📈 &lt;strong&gt;Định nghĩa Hàm Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hàm lồi:&lt;/strong&gt;
Hàm \(f: \mathbb{R}^n \to \mathbb{R}\) là lồi nếu:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;\(\text{dom}(f)\) là tập lồi&lt;/li&gt;
  &lt;li&gt;\(f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y)\)
với mọi \(x, y \in \text{dom}(f), 0 \le \theta \le 1\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Các loại hàm lồi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lồi chặt:&lt;/strong&gt; \(f(\theta x + (1-\theta)y) &amp;lt; \theta f(x) + (1-\theta)f(y)\) với \(x \neq y, 0 &amp;lt; \theta &amp;lt; 1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lồi mạnh:&lt;/strong&gt; \(f - \frac{m}{2}\lVert x \rVert_2^2\) lồi với \(m &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm lõm:&lt;/strong&gt; \(f\) lõm ⟺ \(-f\) lồi&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Mối quan hệ:&lt;/strong&gt; Lồi mạnh ⟹ Lồi chặt ⟹ Lồi&lt;/p&gt;

&lt;h3 id=&quot;-các-ví-dụ-quan-trọng&quot;&gt;🔢 &lt;strong&gt;Các Ví Dụ Quan Trọng&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hàm một biến:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mũ: \(e^{ax}\) lồi với mọi \(a \in \mathbb{R}\)&lt;/li&gt;
  &lt;li&gt;Hàm lũy thừa: \(x^a\) lồi trên \(\mathbb{R}_{++}\) khi \(a \ge 1\) hoặc \(a \le 0\)&lt;/li&gt;
  &lt;li&gt;Hàm lũy thừa: \(x^a\) lõm trên \(\mathbb{R}_{++}\) khi \(0 \le a \le 1\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hàm nhiều biến:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm affine: \(a^T x + b\) vừa lồi vừa lõm&lt;/li&gt;
  &lt;li&gt;Hàm bậc hai: \(\frac{1}{2}x^T P x + q^T x + r\) lồi khi \(P \succeq 0\)&lt;/li&gt;
  &lt;li&gt;Chuẩn: \(\lVert x \rVert_p\) lồi với mọi \(p \ge 1\)&lt;/li&gt;
  &lt;li&gt;Hàm mất mát bình phương: \(\lVert Ax - b \rVert_2^2\) luôn lồi&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hàm đặc biệt:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm chỉ thị: \(I_C(x) = \begin{cases} 0 &amp;amp; x \in C \\ +\infty &amp;amp; x \notin C \end{cases}\) lồi nếu \(C\) lồi&lt;/li&gt;
  &lt;li&gt;Hàm hỗ trợ: \(I_C^*(x) = \sup_{y \in C} x^T y\) luôn lồi&lt;/li&gt;
  &lt;li&gt;Hàm max: \(\max\{f_1(x), \ldots, f_m(x)\}\) lồi nếu \(f_i\) lồi&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-tính-chất-đặc-trưng&quot;&gt;🔍 &lt;strong&gt;Tính Chất Đặc Trưng&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Đặc trưng epigraph:&lt;/strong&gt;
\(f\) lồi ⟺ \(\text{epi}(f) = \{(x,t) \mid x \in \text{dom}(f), f(x) \le t\}\) là tập lồi&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tập mức dưới:&lt;/strong&gt;
Nếu \(f\) lồi thì \(\{x \mid f(x) \le \alpha\}\) lồi với mọi \(\alpha\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đặc trưng bậc nhất (hàm khả vi):&lt;/strong&gt;
\(f\) lồi ⟺ \(f(y) \ge f(x) + \nabla f(x)^T (y-x)\) với mọi \(x,y\)
(Hàm nằm trên đường tiếp tuyến)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đặc trưng bậc hai (hàm khả vi hai lần):&lt;/strong&gt;
\(f\) lồi ⟺ \(\nabla^2 f(x) \succeq 0\) với mọi \(x\) (Hessian nửa xác định dương, với \(\text{dom}(f)\) lồi)&lt;/p&gt;

&lt;h3 id=&quot;-phép-toán-bảo-toàn-tính-lồi&quot;&gt;🔄 &lt;strong&gt;Phép Toán Bảo Toàn Tính Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Tổ hợp tuyến tính:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\alpha f\) lồi nếu \(f\) lồi và \(\alpha \ge 0\)&lt;/li&gt;
  &lt;li&gt;\(f_1 + f_2\) lồi nếu \(f_1, f_2\) lồi&lt;/li&gt;
  &lt;li&gt;\(\sum_{i=1}^m \alpha_i f_i\) lồi nếu \(f_i\) lồi và \(\alpha_i \ge 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hợp thành affine:&lt;/strong&gt;
\(f(Ax + b)\) lồi nếu \(f\) lồi&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hợp thành tổng quát:&lt;/strong&gt; \(h(g(x))\) lồi nếu:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g\) lồi, \(h\) lồi và không giảm&lt;/li&gt;
  &lt;li&gt;\(g\) lõm, \(h\) lồi và không tăng&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Maximum theo điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\max\{f_1(x), f_2(x)\}\) lồi nếu \(f_1, f_2\) lồi&lt;/li&gt;
  &lt;li&gt;\(\sup_{y \in A} f(x,y)\) lồi theo \(x\) nếu \(f(x,y)\) lồi theo \(x\) với mọi \(y\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phép biến đổi phối cảnh:&lt;/strong&gt;
\(g(x,t) = tf(\frac{x}{t})\) lồi nếu \(f\) lồi và \(t &amp;gt; 0\)&lt;/p&gt;

&lt;h3 id=&quot;-hàm-liên-hợp-conjugate&quot;&gt;⭐ &lt;strong&gt;Hàm Liên Hợp (Conjugate)&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt;
\(f^*(y) = \sup_{x \in \text{dom}(f)} \{y^T x - f(x)\}\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Tính chất quan trọng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f^*\) luôn lồi (dù \(f\) có lồi hay không)&lt;/li&gt;
  &lt;li&gt;Bất đẳng thức Fenchel: \(f(x) + f^*(y) \ge x^T y\)&lt;/li&gt;
  &lt;li&gt;Nếu \(f\) đóng và lồi: \(f^{**} = f\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các ví dụ:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(x) = \frac{1}{2}x^T Q x \Rightarrow f^*(y) = \frac{1}{2}y^T Q^{-1} y\) (\(Q \succ 0\))&lt;/li&gt;
  &lt;li&gt;
\[f(x) = \lvert x \rvert \Rightarrow f^*(y) = \begin{cases} 0 &amp;amp; \lvert y \rvert \le 1 \\ +\infty &amp;amp; \lvert y \rvert &amp;gt; 1 \end{cases}\]
  &lt;/li&gt;
  &lt;li&gt;
\[f(x) = e^x \Rightarrow f^*(y) = \begin{cases} y \log y - y &amp;amp; y &amp;gt; 0 \\ 0 &amp;amp; y = 0 \\ +\infty &amp;amp; y &amp;lt; 0 \end{cases}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-bất-đẳng-thức-jensen&quot;&gt;📊 &lt;strong&gt;Bất Đẳng Thức Jensen&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Dạng tổng quát:&lt;/strong&gt;
Nếu \(f\) lồi và \(\sum_{i=1}^n w_i = 1, w_i \ge 0\):
\(f\left(\sum_{i=1}^n w_i x_i\right) \le \sum_{i=1}^n w_i f(x_i)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dạng xác suất:&lt;/strong&gt;
Nếu \(X\) là biến ngẫu nhiên: \(f(E[X]) \le E[f(X)]\)&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Mẹo:&lt;/strong&gt; Hàm lồi có tính chất “cong lên” - đoạn thẳng nối hai điểm bất kỳ trên đồ thị luôn nằm phía trên (hoặc trùng với) đồ thị, giúp việc tối ưu hóa trở nên thuận lợi hơn.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Bài tập trắc nghiệm: Hàm lồi&lt;/h2&gt;
        &lt;p&gt;Chọn đáp án đúng nhất cho mỗi câu hỏi. Bài tập tập trung vào các khái niệm cơ bản về hàm lồi và các phép toán liên quan.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Câu hỏi 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Câu hỏi 1: Định nghĩa hàm lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Câu 1: Hàm $$f: \mathbb{R}^n \to \mathbb{R}$$ là lồi nếu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Miền xác định là tập lồi và $$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Chỉ cần $$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Miền xác định là tập lồi và hàm khả vi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Hàm liên tục trên miền xác định&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Miền xác định là tập lồi và $$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$&lt;/strong&gt;&lt;br /&gt;
                Định nghĩa hàm lồi yêu cầu cả hai điều kiện: miền xác định phải là tập lồi và bất đẳng thức Jensen phải thỏa mãn với $$0 \leq \theta \leq 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Hàm lồi chặt --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Hàm lồi chặt khác với hàm lồi ở điểm nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) Sử dụng bất đẳng thức nghiêm ngặt $$&amp;lt;$$ thay vì $$\leq$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) Chỉ áp dụng cho $$0 &amp;lt; \theta &amp;lt; 1$$ và $$x \neq y$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Cả A và B đều đúng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Không có sự khác biệt&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Cả A và B đều đúng&lt;/strong&gt;&lt;br /&gt;
                Hàm lồi chặt yêu cầu $$f(\theta x + (1-\theta)y) &amp;lt; \theta f(x) + (1-\theta)f(y)$$ với $$0 &amp;lt; \theta &amp;lt; 1$$ và $$x \neq y$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Mối quan hệ giữa các loại hàm lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Mối quan hệ giữa các loại hàm lồi là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) Lồi mạnh ⇒ Lồi chặt ⇒ Lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Lồi ⇒ Lồi chặt ⇒ Lồi mạnh&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Lồi chặt ⇒ Lồi mạnh ⇒ Lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Tất cả đều tương đương&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Lồi mạnh ⇒ Lồi chặt ⇒ Lồi&lt;/strong&gt;&lt;br /&gt;
                Đây là thứ tự từ mạnh nhất đến yếu nhất: lồi mạnh là điều kiện mạnh nhất, sau đó đến lồi chặt, và cuối cùng là lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Hàm affine --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Hàm affine $$f(x) = a^T x + b$$ có tính chất:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Chỉ lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Chỉ lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Vừa lồi vừa lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Không lồi cũng không lõm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Vừa lồi vừa lõm&lt;/strong&gt;&lt;br /&gt;
                Hàm affine thỏa mãn $$f(\theta x + (1-\theta)y) = \theta f(x) + (1-\theta)f(y)$$ (đẳng thức), nên vừa lồi vừa lõm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Hàm mũ --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Hàm $$f(x) = e^{ax}$$ với $$a \in \mathbb{R}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Lồi với mọi $$a$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Lồi chỉ khi $$a &amp;gt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Lõm với mọi $$a$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Phụ thuộc vào dấu của $$a$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Lồi với mọi $$a$$&lt;/strong&gt;&lt;br /&gt;
                Hàm mũ $$e^{ax}$$ là hàm lồi với mọi giá trị thực của $$a$$, bao gồm cả $$a$$ âm, bằng 0 và dương.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Hàm lũy thừa --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Trên $$\mathbb{R}_{++}$$, hàm $$f(x) = x^a$$ là lồi khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) $$a \geq 1$$ hoặc $$a \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) $$0 \leq a \leq 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) $$a &amp;gt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Với mọi $$a$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$a \geq 1$$ hoặc $$a \leq 0$$&lt;/strong&gt;&lt;br /&gt;
                Hàm $$x^a$$ lồi trên $$\mathbb{R}_{++}$$ khi $$a \geq 1$$ hoặc $$a \leq 0$$, và lõm khi $$0 \leq a \leq 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Hàm bậc hai --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Hàm bậc hai $$f(x) = \frac{1}{2}x^T P x + q^T x + r$$ là lồi khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) $$P$$ là ma trận xác định dương&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) $$P$$ là ma trận nửa xác định dương&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) $$P$$ là ma trận đối xứng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) $$P$$ là ma trận khả nghịch&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$P$$ là ma trận nửa xác định dương&lt;/strong&gt;&lt;br /&gt;
                Hàm bậc hai lồi khi ma trận Hessian $$P$$ là nửa xác định dương ($$P \succeq 0$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Chuẩn --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Tất cả các chuẩn trên $$\mathbb{R}^n$$ đều:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) Lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) Lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Vừa lồi vừa lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) Phụ thuộc vào loại chuẩn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Lồi&lt;/strong&gt;&lt;br /&gt;
                Theo định nghĩa, tất cả các chuẩn đều thỏa mãn bất đẳng thức tam giác, dẫn đến tính lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Tổng trọng số không âm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Nếu $$f_1, f_2, ..., f_n$$ là các hàm lồi, thì $$\sum_{i=1}^n \alpha_i f_i$$ lồi khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) $$\alpha_i \geq 0$$ với mọi $$i$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) $$\sum_{i=1}^n \alpha_i = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) $$\alpha_i &amp;gt; 0$$ với mọi $$i$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) Với mọi $$\alpha_i \in \mathbb{R}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\alpha_i \geq 0$$ với mọi $$i$$&lt;/strong&gt;&lt;br /&gt;
                Tổng trọng số không âm của các hàm lồi vẫn là hàm lồi. Không cần điều kiện $$\sum \alpha_i = 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Hợp thành affine --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Nếu $$f$$ là hàm lồi, thì $$g(x) = f(Ax + b)$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) Luôn lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) Lồi chỉ khi $$A$$ khả nghịch&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Lồi chỉ khi $$A$$ là ma trận vuông&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) Không nhất thiết lồi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Luôn lồi&lt;/strong&gt;&lt;br /&gt;
                Hợp thành của hàm lồi với hàm affine luôn bảo toàn tính lồi, với mọi ma trận $$A$$ và vector $$b$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Hợp thành tổng quát --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Cho $$g$$ lồi và $$h$$ lồi không giảm. Hàm $$f(x) = h(g(x))$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Không xác định được&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Vừa lồi vừa lõm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Lồi&lt;/strong&gt;&lt;br /&gt;
                Khi $$g$$ lồi, $$h$$ lồi và không giảm, thì hàm hợp thành $$h(g(x))$$ là lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Maximum theo điểm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Nếu $$f_1, f_2$$ là các hàm lồi, thì $$f(x) = \max\{f_1(x), f_2(x)\}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Không lồi cũng không lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Phụ thuộc vào $$f_1, f_2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Lồi&lt;/strong&gt;&lt;br /&gt;
                Maximum theo điểm của các hàm lồi luôn là hàm lồi. Đây là một tính chất quan trọng bảo toàn tính lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Hàm liên hợp --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Hàm liên hợp $$f^*(y) = \sup_x \{y^T x - f(x)\}$$ có tính chất:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Luôn lồi, bất kể $$f$$ có lồi hay không&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Lồi chỉ khi $$f$$ lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Có cùng tính lồi với $$f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Luôn lõm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Luôn lồi, bất kể $$f$$ có lồi hay không&lt;/strong&gt;&lt;br /&gt;
                Hàm liên hợp luôn lồi vì nó là supremum của các hàm affine $$y^T x - f(x)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Bất đẳng thức Fenchel --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Bất đẳng thức Fenchel phát biểu rằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) $$f(x) + f^*(y) \geq x^T y$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) $$f(x) + f^*(y) \leq x^T y$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) $$f(x) \cdot f^*(y) \geq x^T y$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) $$f(x) = f^*(y) + x^T y$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f(x) + f^*(y) \geq x^T y$$&lt;/strong&gt;&lt;br /&gt;
                Bất đẳng thức Fenchel là một bất đẳng thức cơ bản trong lý thuyết hàm liên hợp.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Liên hợp kép --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Với hàm $$f$$ đóng và lồi, liên hợp kép $$f^{**}$$ thỏa mãn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) $$f^{**} = f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) $$f^{**} \leq f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) $$f^{**} \geq f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Không có mối quan hệ cố định&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$f^{**} = f$$&lt;/strong&gt;&lt;br /&gt;
                Với hàm đóng và lồi, liên hợp kép bằng chính hàm gốc. Đây là định lý Fenchel-Moreau.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Ví dụ hàm liên hợp --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Liên hợp của hàm $$f(x) = |x|$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Hàm chỉ thị của $$[-1,1]$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) $$|y|$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) $$y^2/2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) $$\log|y|$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Hàm chỉ thị của $$[-1,1]$$&lt;/strong&gt;&lt;br /&gt;
                Liên hợp của $$|x|$$ là $$f^*(y) = 0$$ nếu $$|y| \leq 1$$ và $$+\infty$$ nếu $$|y| &amp;gt; 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Hàm chỉ thị --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Hàm chỉ thị $$I_C(x)$$ của tập lồi $$C$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Không lồi cũng không lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Phụ thuộc vào tập $$C$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Lồi&lt;/strong&gt;&lt;br /&gt;
                Hàm chỉ thị của tập lồi luôn là hàm lồi: $$I_C(x) = 0$$ nếu $$x \in C$$, $$+\infty$$ nếu $$x \notin C$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Hàm hỗ trợ --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Hàm hỗ trợ $$S_C(x) = \sup_{y \in C} x^T y$$ của tập $$C$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Lồi bất kể $$C$$ có lồi hay không&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Lồi chỉ khi $$C$$ lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Lõm bất kể $$C$$ có lồi hay không&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Có cùng tính lồi với $$C$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Lồi bất kể $$C$$ có lồi hay không&lt;/strong&gt;&lt;br /&gt;
                Hàm hỗ trợ luôn lồi vì nó là supremum của các hàm tuyến tính $$x^T y$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Hàm mất mát bình phương --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Hàm $$f(x) = \|Ax - b\|_2^2$$ với ma trận $$A$$ bất kỳ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Luôn lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Lồi chỉ khi $$A$$ vuông&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Lồi chỉ khi $$A$$ khả nghịch&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Không nhất thiết lồi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Luôn lồi&lt;/strong&gt;&lt;br /&gt;
                Vì $$A^T A$$ luôn nửa xác định dương với mọi ma trận $$A$$, nên $$\|Ax - b\|_2^2$$ luôn lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Ứng dụng --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Tại sao việc nhận biết hàm lồi quan trọng trong tối ưu hóa?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Mọi cực tiểu địa phương đều là cực tiểu toàn cục&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Có nhiều thuật toán hiệu quả&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Lý thuyết đối ngẫu áp dụng được&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các lý do trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các lý do trên&lt;/strong&gt;&lt;br /&gt;
                Hàm lồi có nhiều tính chất tốt: mọi cực tiểu địa phương đều là cực tiểu toàn cục, có nhiều thuật toán giải hiệu quả và áp dụng được lý thuyết đối ngẫu.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Cho hàm $$f(x) = e^x$$. Hàm này có lồi không?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Có, vì $$f&apos;&apos;(x) = e^x &amp;gt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Không, vì tăng quá nhanh&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Chỉ lồi trên $$(0, \infty)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Không xác định được&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Có, vì $$f&apos;&apos;(x) = e^x &amp;gt; 0$$&lt;/strong&gt;&lt;br /&gt;
                $$f&apos;(x) = e^x$$, $$f&apos;&apos;(x) = e^x &amp;gt; 0$$ với mọi $$x$$, nên hàm lồi trên toàn bộ $$\mathbb{R}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Hàm $$g(x) = \max\{x, 0\}$$ (ReLU) có phải là hàm lồi không?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Có, theo định nghĩa hàm lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Không, vì không khả vi tại $$x = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Chỉ lồi trên $$[0, \infty)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Không, vì có góc nhọn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Có, theo định nghĩa hàm lồi&lt;/strong&gt;&lt;br /&gt;
                Hàm ReLU thỏa mãn định nghĩa hàm lồi. Tính không khả vi tại một điểm không ảnh hưởng đến tính lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Cho $$f(x,y) = x^2 + y^2$$. Ma trận Hessian của $$f$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 2x &amp;amp; 0 \\ 0 &amp;amp; 2y \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} x &amp;amp; y \\ y &amp;amp; x \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                $$\frac{\partial^2 f}{\partial x^2} = 2$$, $$\frac{\partial^2 f}{\partial y^2} = 2$$, $$\frac{\partial^2 f}{\partial x \partial y} = 0$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Tổng của hai hàm lồi $$f$$ và $$g$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Luôn lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Có thể lồi hoặc không&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Luôn lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Phụ thuộc vào miền xác định&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Luôn lồi&lt;/strong&gt;&lt;br /&gt;
                Tổng của hai hàm lồi luôn là hàm lồi. Đây là một trong những phép toán bảo toàn tính lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Hàm $$h(x) = |x|^p$$ với $$p \geq 1$$ có tính chất gì?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Lồi trên $$\mathbb{R}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Lõm trên $$\mathbb{R}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Lồi chỉ khi $$p = 2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Không lồi không lõm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Lồi trên $$\mathbb{R}$$&lt;/strong&gt;&lt;br /&gt;
                Với $$p \geq 1$$, hàm $$|x|^p$$ là lồi trên toàn bộ $$\mathbb{R}$$. Đây là một ví dụ quan trọng của hàm lồi.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Câu trước&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Câu tiếp&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Kết quả bài tập&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #00BCD4, #009688);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #00BCD4;
    background-color: #e0f2f1;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #00BCD4;
    background-color: #b2dfdb;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #e0f2f1;
    border-left: 4px solid #00BCD4;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #00695C;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #00BCD4;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #00ACC1;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #e0f2f1;
    border-radius: 8px;
    border: 2px solid #00BCD4;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #00695C;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng cho từng câu hỏi
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;c&apos;, q3: &apos;a&apos;, q4: &apos;c&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;a&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;a&apos;, q17: &apos;a&apos;, q18: &apos;a&apos;, q19: &apos;a&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

/**
 * Cập nhật thanh tiến trình và hiển thị câu hỏi hiện tại
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Câu hỏi ${currentQuestion}/${totalQuestions}`;
}

/**
 * Hiển thị câu hỏi theo số thứ tự
 */
function showQuestion(questionNum) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Cập nhật trạng thái nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Chuyển đến câu hỏi tiếp theo
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Quay lại câu hỏi trước
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Lưu đáp án của người dùng
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Cập nhật giao diện để hiển thị đáp án đã chọn
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Nộp bài và hiển thị kết quả
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Tính điểm và tạo báo cáo chi tiết
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Hiển thị giải thích cho tất cả câu hỏi
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Tạo báo cáo chi tiết
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Câu ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Đúng&apos; : &apos;Sai&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Đáp án của bạn: ${userAnswer || &apos;Chưa trả lời&apos;} | Đáp án đúng: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Hiển thị kết quả
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Điểm số: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Xuất sắc! Bạn đã nắm vững lý thuyết hàm lồi!&apos; : 
              scorePercentage &gt;= 60 ? &apos;👍 Khá tốt! Hãy ôn lại một số khái niệm về hàm lồi.&apos; : 
              scorePercentage &gt;= 40 ? &apos;📚 Cần ôn tập thêm về định nghĩa và tính chất hàm lồi.&apos; : &apos;💪 Hãy đọc lại lý thuyết về hàm lồi và các phép toán!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Khởi động lại bài tập
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn kết quả và hiển thị lại điều hướng
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Xóa tất cả lựa chọn
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>03-07 Chuẩn Euclidean - L2 - là Lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_07_euclidean_norm_convexity_proof/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_07_euclidean_norm_convexity_proof</id>
   <content type="html">&lt;p&gt;Chuẩn Euclid \(f(x) = \|x\|_2 = \sqrt{x_1^2 + \cdots + x_n^2}\) là một trong những hàm xuất hiện dày đặc nhất trong tối ưu hóa — từ phạt điều chuẩn Group Lasso, bài toán định vị cơ sở Fermat–Weber, cho đến các ràng buộc hình nón bậc hai (SOCP). Thế nhưng một câu hỏi rất thú vị là: đồ thị của \(\|x\|_2\) có dạng một &lt;strong&gt;hình nón nhọn ở gốc tọa độ&lt;/strong&gt; (không khả vi tại \(x = 0\)!), vậy làm sao chứng minh chặt chẽ nó là hàm lồi trên toàn \(\mathbb{R}^n\)?&lt;/p&gt;

&lt;p&gt;Bài học này trình bày cả ba phương pháp chứng minh kinh điển (định nghĩa + Cauchy–Schwarz, phân tích Hessian tại \(x \ne 0\), và bất đẳng thức tam giác) — một bài tập tuyệt vời để luyện đủ mọi góc nhìn giải tích lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-góc-nhìn-chứng-minh-x_2-là-hàm-lồi&quot;&gt;Kiến thức cần nhớ: Ba góc nhìn chứng minh \(\|x\|_2\) là hàm lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Góc nhìn 1 — Đại số (Định nghĩa + Cauchy–Schwarz):&lt;/strong&gt; Bình phương hai vế của bất đẳng thức Jensen rồi áp dụng \(x^T y \le \|x\|_2 \|y\|_2\); ngắn gọn, không cần đạo hàm và đúng luôn tại điểm nhọn \(x = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Góc nhìn 2 — Giải tích bậc hai (Hessian trên \(\mathbb{R}^n \setminus \{0\}\)):&lt;/strong&gt; Tính tường minh \(\nabla^2 f(x) = \frac{1}{\|x\|_2}\left(I - \frac{x x^T}{\|x\|_2^2}\right)\) — chính là phép chiếu trực giao lên không gian vuông góc với \(x\) chia cho \(\|x\|_2\), nên luôn bán xác định dương!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Góc nhìn 3 — Hình học chuẩn (Bất đẳng thức tam giác + Đồng nhất dương):&lt;/strong&gt; Áp dụng ngay cho &lt;strong&gt;mọi chuẩn&lt;/strong&gt; \(\|\cdot\|\) bất kỳ (\(\ell_1, \ell_2, \ell_\infty, \ell_p\)) chỉ trong đúng 2 dòng!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý phân biệt quan trọng:&lt;/strong&gt; \(\|x\|_2\) lồi nhưng &lt;strong&gt;không lồi chặt&lt;/strong&gt; (dọc theo bất kỳ tia \(t v\) nào với \(t \ge 0\), hàm là đường thẳng tuyến tính!); ngược lại bình phương chuẩn \(\|x\|_2^2\) là &lt;strong&gt;2-lồi mạnh&lt;/strong&gt; và trơn khắp nơi!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-ma-trận-hessian-của-fx--x_2-tại-x--3-4t&quot;&gt;Giải thích: Tính tay ma trận Hessian của \(f(x) = \|x\|_2\) tại \(x = (3, 4)^T\)&lt;/h3&gt;

&lt;p&gt;Xét \(f(x_1, x_2) = \sqrt{x_1^2 + x_2^2}\) tại điểm \(x = (3, 4)^T\) (có \(\|x\|_2 = 5\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính vector gradient:&lt;/strong&gt;
\(\nabla f(x) = \frac{x}{\|x\|_2} = \begin{pmatrix}3/5\\ 4/5\end{pmatrix} = \begin{pmatrix}0.6\\ 0.8\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính ma trận Hessian \(\nabla^2 f(x) = \frac{1}{\|x\|_2}\left(I - \frac{x x^T}{\|x\|_2^2}\right)\):&lt;/strong&gt;
\(\frac{x x^T}{\|x\|_2^2} = \frac{1}{25}\begin{pmatrix}9 &amp;amp; 12\\ 12 &amp;amp; 16\end{pmatrix} \implies \nabla^2 f(3, 4) = \frac{1}{5}\left[\begin{pmatrix}1 &amp;amp; 0\\ 0 &amp;amp; 1\end{pmatrix} - \frac{1}{25}\begin{pmatrix}9 &amp;amp; 12\\ 12 &amp;amp; 16\end{pmatrix}\right] = \frac{1}{125}\begin{pmatrix}16 &amp;amp; -12\\ -12 &amp;amp; 9\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích giá trị riêng và ý nghĩa hình học:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vết: \(\operatorname{tr} = \frac{16 + 9}{125} = \frac{25}{125} = \frac{1}{5} = 0.2\); định thức: \(\det = \frac{16\cdot 9 - (-12)^2}{125^2} = \frac{144 - 144}{125^2} = 0\).&lt;/li&gt;
      &lt;li&gt;Hai giá trị riêng là \(\lambda_1 = 0.2 &amp;gt; 0\) (theo phương tiếp tuyến vuông góc với \(x\), nơi mặt nón cong tròn) và \(\lambda_2 = 0\) (theo phương bán kính \(x = (3, 4)^T\), nơi mặt nón là đường thẳng không cong!).
Vì \(\lambda_1, \lambda_2 \ge 0\), ta có \(\nabla^2 f(3, 4) \succeq 0\) — khớp tuyệt đối với hình học mặt nón!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Chuẩn Euclidean&lt;/strong&gt; (hay chuẩn \(\ell_2\)) của một vector \(x \in \mathbb{R}^n\) được định nghĩa là:&lt;/p&gt;

\[\|x\|_2 = \sqrt{x_1^2 + x_2^2 + \cdots + x_n^2} = \sqrt{x^T x}\]

&lt;p&gt;Trong bài này, chúng ta chứng minh hàm chuẩn Euclidean là hàm lồi bằng ba cách khác nhau:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh trực tiếp từ định nghĩa&lt;/strong&gt; kết hợp bất đẳng thức Cauchy–Schwarz&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện bậc hai&lt;/strong&gt; (phân tích ma trận Hessian)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sử dụng bất đẳng thức tam giác&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;phương-pháp-1-chứng-minh-dựa-trên-định-nghĩa&quot;&gt;Phương pháp 1: Chứng minh dựa trên định nghĩa&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý&lt;/strong&gt;: Chuẩn Euclidean \(f(x) = \|x\|_2\) là hàm lồi trên \(\mathbb{R}^n\).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Chứng minh&lt;/strong&gt;:
Cần chỉ ra rằng với mọi \(x, y \in \mathbb{R}^n\) và mọi \(\theta \in [0,1]\):&lt;/p&gt;

\[\|\theta x + (1-\theta) y\|_2 \leq \theta \|x\|_2 + (1-\theta) \|y\|_2\]

&lt;p&gt;Đặt \(z = \theta x + (1-\theta) y\). Ta có:&lt;/p&gt;

\[\begin{align}
\|z\|_2^2 &amp;amp;= \|\theta x + (1-\theta) y\|_2^2 \\
&amp;amp;= (\theta x + (1-\theta) y)^T (\theta x + (1-\theta) y) \\
&amp;amp;= \theta^2 x^T x + 2\theta(1-\theta) x^T y + (1-\theta)^2 y^T y \\
&amp;amp;= \theta^2 \|x\|_2^2 + 2\theta(1-\theta) x^T y + (1-\theta)^2 \|y\|_2^2
\end{align}\]

&lt;p&gt;Theo &lt;strong&gt;bất đẳng thức Cauchy–Schwarz&lt;/strong&gt;, \(x^T y \leq \|x\|_2 \|y\|_2\), nên:&lt;/p&gt;

\[\|z\|_2^2 \leq \theta^2 \|x\|_2^2 + 2\theta(1-\theta) \|x\|_2 \|y\|_2 + (1-\theta)^2 \|y\|_2^2 = (\theta \|x\|_2 + (1-\theta) \|y\|_2)^2\]

&lt;p&gt;Vì hai vế đều không âm, lấy căn bậc hai hai vế ta thu được:&lt;/p&gt;

\[\|\theta x + (1-\theta) y\|_2 \leq \theta \|x\|_2 + (1-\theta) \|y\|_2\]

&lt;p&gt;Điều này chứng minh chuẩn Euclidean là hàm lồi. \(\square\)&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-2-kiểm-tra-điều-kiện-bậc-hai-phân-tích-hessian&quot;&gt;Phương pháp 2: Kiểm tra điều kiện bậc hai (phân tích Hessian)&lt;/h2&gt;

&lt;p&gt;Đối với hàm khả vi hai lần trên miền lồi, ta có thể kiểm tra tính lồi bằng cách chứng minh ma trận Hessian nửa xác định dương.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phân tích&lt;/strong&gt;:
Hàm \(f(x) = \|x\|_2 = \sqrt{x^T x}\) không khả vi tại gốc tọa độ \(x = 0\). Với mọi \(x \neq 0\), các đạo hàm riêng bậc nhất và bậc hai là:&lt;/p&gt;

\[\frac{\partial f}{\partial x_i} = \frac{x_i}{\|x\|_2}\]

\[\frac{\partial^2 f}{\partial x_i \partial x_j} = \frac{1}{\|x\|_2} \delta_{ij} - \frac{x_i x_j}{\|x\|_2^3}\]

&lt;p&gt;Do đó ma trận Hessian là:
\(H = \frac{1}{\|x\|_2} I - \frac{1}{\|x\|_2^3} x x^T = \frac{1}{\|x\|_2} \left( I - \frac{x x^T}{\|x\|_2^2} \right)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kiểm tra tính nửa xác định dương&lt;/strong&gt;:
Với mọi vector \(v \in \mathbb{R}^n\):
\(v^T H v = \frac{1}{\|x\|_2} \left( \|v\|_2^2 - \frac{(x^T v)^2}{\|x\|_2^2} \right)\)&lt;/p&gt;

&lt;p&gt;Theo bất đẳng thức Cauchy–Schwarz, \((x^T v)^2 \leq \|x\|_2^2 \|v\|_2^2\), suy ra:
\(\|v\|_2^2 - \frac{(x^T v)^2}{\|x\|_2^2} \geq 0\)&lt;/p&gt;

&lt;p&gt;Như vậy \(H \succeq 0\) tại mọi \(x \neq 0\). (Tính lồi trên toàn \(\mathbb{R}^n\) bao gồm cả điểm \(x = 0\) được đảm bảo bởi Phương pháp 1 hoặc Phương pháp 3.)&lt;/p&gt;

&lt;h2 id=&quot;phương-pháp-3-dùng-bất-đẳng-thức-tam-giác&quot;&gt;Phương pháp 3: Dùng bất đẳng thức tam giác&lt;/h2&gt;

&lt;p&gt;Chuẩn Euclidean thỏa mãn &lt;strong&gt;bất đẳng thức tam giác&lt;/strong&gt; (bất đẳng thức Minkowski):
\(\|u + v\|_2 \leq \|u\|_2 + \|v\|_2\)&lt;/p&gt;

&lt;p&gt;Đặt \(u = \theta x\) và \(v = (1-\theta) y\) với \(\theta \in [0,1]\). Áp dụng bất đẳng thức tam giác và tính thuần nhất bậc một của chuẩn, ta có ngay:
\(\|\theta x + (1-\theta) y\|_2 = \|u + v\|_2 \leq \|u\|_2 + \|v\|_2 = \theta \|x\|_2 + (1-\theta) \|y\|_2\)&lt;/p&gt;

&lt;p&gt;Cách chứng minh này cho thấy tính lồi thực chất là hệ quả trực tiếp của hai tiên đề cơ bản của mọi chuẩn.&lt;/p&gt;

&lt;h2 id=&quot;các-tính-chất-và-ứng-dụng-chính&quot;&gt;Các tính chất và ứng dụng chính&lt;/h2&gt;

&lt;h3 id=&quot;các-tính-chất-liên-quan&quot;&gt;Các tính chất liên quan&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lồi chặt dọc theo đường thẳng không qua gốc:&lt;/strong&gt; Chuẩn Euclidean là hàm &lt;strong&gt;lồi chặt&lt;/strong&gt; dọc theo mọi đường thẳng không đi qua gốc tọa độ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính thuần nhất:&lt;/strong&gt; \(\|\alpha x\|_2 = \lvert\alpha\rvert \|x\|_2\) với mọi số thực \(\alpha\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính dưới cộng:&lt;/strong&gt; \(\|x + y\|_2 \leq \|x\|_2 + \|y\|_2\) (bất đẳng thức tam giác).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong tối ưu hóa&lt;/h3&gt;
&lt;p&gt;Tính lồi của chuẩn Euclidean mang lại nhiều hệ quả quan trọng:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán bình phương tối thiểu:&lt;/strong&gt; Hàm mục tiêu \(\|Ax - b\|_2^2\) là hàm lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chính quy hóa (regularization):&lt;/strong&gt; Các số hạng phạt dạng \(\lambda \|x\|_2\) (với \(\lambda \ge 0\)) bảo toàn tính lồi của bài toán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu có ràng buộc:&lt;/strong&gt; Các ràng buộc dạng \(\|x\|_2 \leq r\) xác định miền khả thi lồi.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kết-luận&quot;&gt;Kết luận&lt;/h2&gt;

&lt;p&gt;Chúng ta đã chứng minh chuẩn Euclidean là hàm lồi theo ba hướng tiếp cận:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa trực tiếp:&lt;/strong&gt; Kết hợp khai triển bình phương và bất đẳng thức Cauchy–Schwarz.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra đạo hàm bậc hai:&lt;/strong&gt; Chứng minh ma trận Hessian nửa xác định dương với mọi \(x \neq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức tam giác:&lt;/strong&gt; Dùng trực tiếp bất đẳng thức tam giác và tính thuần nhất của chuẩn.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tính chất lồi này là nền tảng cho nhiều bài toán và thuật toán trong tối ưu hóa, học máy, xử lý tín hiệu và giải tích số.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-06 Tính lồi đối với bất đẳng thức tổng quát</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_06_convexity_with_respect_to_generalized_inequalities/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_06_convexity_with_respect_to_generalized_inequalities</id>
   <content type="html">&lt;p&gt;Khi tối ưu hóa một hệ thống truyền thông, danh mục đầu tư đa mục tiêu hay thiết kế ma trận hiệp phương sai trong Quy hoạch bán xác định (SDP), hàm mục tiêu không còn trả về một số thực đơn lẻ mà trả về một &lt;strong&gt;vector&lt;/strong&gt; hoặc một &lt;strong&gt;ma trận đối xứng&lt;/strong&gt;! Làm sao định nghĩa “hàm giá trị ma trận \(f(X) = X^2\) là hàm lồi”? Ta chỉ cần ghép Chương 02 (bất đẳng thức tổng quát \(\preceq_K\)) với Chương 03 (bất đẳng thức Jensen) để thu được khái niệm &lt;strong&gt;tính lồi theo hình nón \(K\)&lt;/strong&gt; (\(K\)-convexity)!&lt;/p&gt;

&lt;p&gt;Bài học này tổng quát hóa tính đơn điệu, tính lồi, đặc trưng đối ngẫu và quy tắc hợp thành cho các hàm giá trị vector và ma trận.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-của-tính-lồi-theo-k&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép của Tính lồi theo \(K\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính đơn điệu theo \(K\) (\(K\)-monotonicity):&lt;/strong&gt; Với hai hình nón thích hợp \(K_1, K_2\), hàm \(f\) gọi là không giảm nếu \(x \preceq_{K_1} y \implies f(x) \preceq_{K_2} f(y)\). Ví dụ kinh điển: trên \(\mathbb{S}_+^n\), \(f(X) = X^{-1}\) là hàm &lt;strong&gt;giảm&lt;/strong&gt; theo thứ tự Loewner (\(0 \prec X \preceq Y \implies Y^{-1} \preceq X^{-1}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi theo \(K\) (\(K\)-convexity):&lt;/strong&gt; \(f(\theta x + (1-\theta)y) \preceq_K \theta f(x) + (1-\theta)f(y)\) với mọi \(\theta \in [0, 1]\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đặc trưng đối ngẫu cực kỳ thanh lịch:&lt;/strong&gt; \(f\) là \(K\)-lồi khi và chỉ khi với &lt;strong&gt;mọi&lt;/strong&gt; \(w \succeq_{K^*} 0\), hàm vô hướng \(w^T f(x)\) là hàm lồi thông thường! Quy tắc này biến việc kiểm tra tính lồi trên ma trận thành kiểm tra hàm số thực quen thuộc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bậc nhất và hợp thành:&lt;/strong&gt; Mở rộng trực tiếp tiếp tuyến \(f(y) \succeq_K f(x) + Df(x)(y - x)\) và quy tắc hợp thành \(h(g(x))\) cho hàm nhiều chiều.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tính-lồi-ma-trận-mathbbs_2-lồi-của-fx--x2&quot;&gt;Giải thích: Kiểm chứng tính lồi ma trận (\(\mathbb{S}_+^2\)-lồi) của \(f(X) = X^2\)&lt;/h3&gt;

&lt;p&gt;Xét hàm giá trị ma trận \(f(X) = X^2\) trên không gian ma trận đối xứng \(\mathbb{S}^2\) với hình nón \(K = \mathbb{S}_+^2\). Lấy hai ma trận:
\(A = \begin{pmatrix}2 &amp;amp; 0\\ 0 &amp;amp; 0\end{pmatrix}, \qquad B = \begin{pmatrix}0 &amp;amp; 0\\ 0 &amp;amp; 2\end{pmatrix}, \qquad \theta = 0.5.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giá trị tại trung điểm \(M = \frac{A + B}{2}\):&lt;/strong&gt;
\(M = \begin{pmatrix}1 &amp;amp; 0\\ 0 &amp;amp; 1\end{pmatrix} \implies f(M) = M^2 = \begin{pmatrix}1 &amp;amp; 0\\ 0 &amp;amp; 1\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính trung bình hai đầu mút:&lt;/strong&gt;
\(\frac{f(A) + f(B)}{2} = \frac{1}{2}\begin{pmatrix}4 &amp;amp; 0\\ 0 &amp;amp; 0\end{pmatrix} + \frac{1}{2}\begin{pmatrix}0 &amp;amp; 0\\ 0 &amp;amp; 4\end{pmatrix} = \begin{pmatrix}2 &amp;amp; 0\\ 0 &amp;amp; 2\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra hiệu theo hình nón \(\mathbb{S}_+^2\):&lt;/strong&gt;
\(\frac{f(A) + f(B)}{2} - f(M) = \begin{pmatrix}2 &amp;amp; 0\\ 0 &amp;amp; 2\end{pmatrix} - \begin{pmatrix}1 &amp;amp; 0\\ 0 &amp;amp; 1\end{pmatrix} = \begin{pmatrix}1 &amp;amp; 0\\ 0 &amp;amp; 1\end{pmatrix} \succeq 0.\)
Vậy \(f\left(\frac{A+B}{2}\right) \preceq_{\mathbb{S}_+^2} \frac{f(A)+f(B)}{2}\)! (Thậm chí chứng minh tổng quát rất đẹp: với mọi \(z \in \mathbb{R}^n\), \(z^T X^2 z = \|Xz\|_2^2\) là hàm lồi theo \(X\), suy ra ngay theo đặc trưng đối ngẫu rằng \(X^2\) là \(\mathbb{S}_+^n\)-lồi — nhưng chú ý \(X^3\) lại &lt;em&gt;không&lt;/em&gt; lồi trên ma trận!)&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này mở rộng khái niệm tính đơn điệu và tính lồi từ các hàm giá trị thực thông thường sang các hàm giá trị vector thông qua bất đẳng thức tổng quát.&lt;/p&gt;

&lt;p&gt;Trong các không gian nhiều chiều, ta dùng hình nón thích hợp để định nghĩa bất đẳng thức tổng quát, mở rộng quan hệ thứ tự quen thuộc trên \(\mathbb{R}\) (xem bài &lt;a href=&quot;/contents/vi/chapter02/02_01_04_Convex_cone/&quot;&gt;02-01-04&lt;/a&gt;).&lt;/p&gt;

&lt;h2 id=&quot;tính-đơn-điệu-đối-với-bất-đẳng-thức-tổng-quát&quot;&gt;Tính đơn điệu đối với bất đẳng thức tổng quát&lt;/h2&gt;

&lt;p&gt;Giả sử \(K \subseteq \mathbb{R}^n\) là một &lt;strong&gt;hình nón thích hợp&lt;/strong&gt; sinh ra bất đẳng thức tổng quát \(\preceq_K\), tức là một hình nón lồi thỏa mãn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(K\) là tập đóng (chứa biên của nó).&lt;/li&gt;
  &lt;li&gt;\(K\) là hình nón đặc (có phần trong khác rỗng).&lt;/li&gt;
  &lt;li&gt;\(K\) là hình nón nhọn (không chứa đường thẳng nào).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hàm \(f : \mathbb{R}^n \mapsto \mathbb{R}\) được gọi là &lt;strong&gt;không giảm theo \(K\)&lt;/strong&gt; nếu:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \mapsto \mathbb{R}\) không giảm theo \(K\) nếu \(x \preceq_K y \Rightarrow f(x) \leq f(y)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tương tự, \(f\) được gọi là &lt;strong&gt;tăng theo \(K\)&lt;/strong&gt; nếu:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \mapsto \mathbb{R}\) tăng theo \(K\) nếu \(x \preceq_K y, x \neq y \Rightarrow f(x) &amp;lt; f(y)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;điều-kiện-gradient-cho-tính-đơn-điệu&quot;&gt;Điều kiện gradient cho tính đơn điệu&lt;/h3&gt;

&lt;p&gt;Với hàm khả vi một biến \(f : \mathbb{R} \mapsto \mathbb{R}\) trên một khoảng, \(f\) không giảm khi và chỉ khi \(f&apos;(x) \geq 0\) với mọi \(x \in \text{dom}f\), và nếu \(f&apos;(x) &amp;gt; 0\) với mọi \(x \in \text{dom}f\) thì \(f\) tăng. Khái niệm này mở rộng sang bất đẳng thức tổng quát như sau:&lt;/p&gt;

&lt;p&gt;Khi \(\text{dom}f\) lồi, một hàm khả vi \(f\) không giảm theo \(K\) khi và chỉ khi gradient \(\nabla f(x)\) không âm theo bất đẳng thức tổng quát đối ngẫu:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Hàm khả vi \(f\) không giảm theo \(K\) \(\Longleftrightarrow\) \(\nabla f(x) \succeq_{K^*} 0\) với mọi \(x \in \text{dom}f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tương tự, ta có điều kiện đủ cho tính tăng theo \(K\) (như trường hợp một biến, chiều ngược lại không nhất thiết đúng):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\nabla f(x) \succ_{K^*} 0\) với mọi \(x \in \text{dom}f\) \(\Longrightarrow\) \(f\) tăng theo \(K\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;tính-lồi-đối-với-bất-đẳng-thức-tổng-quát&quot;&gt;Tính lồi đối với bất đẳng thức tổng quát&lt;/h2&gt;

&lt;p&gt;Cho \(K \subseteq \mathbb{R}^m\) là hình nón thích hợp gắn với bất đẳng thức tổng quát \(\preceq_K\). Hàm \(f : \mathbb{R}^n \mapsto \mathbb{R}^m\) được gọi là &lt;strong&gt;lồi theo \(K\)&lt;/strong&gt; nếu miền xác định \(\text{dom}f\) lồi và với mọi \(x, y \in \text{dom}f\) cùng mọi \(0 \leq \theta \leq 1\):&lt;/p&gt;
&lt;blockquote&gt;
\[f(\theta x + (1 - \theta) y) \preceq_K \theta f(x) + (1 - \theta) f(y)\]
&lt;/blockquote&gt;

&lt;p&gt;Hàm \(f\) được gọi là &lt;strong&gt;lồi chặt theo \(K\)&lt;/strong&gt; nếu với mọi \(x, y \in \text{dom}f\) (\(x \neq y\)) và \(0 &amp;lt; \theta &amp;lt; 1\):&lt;/p&gt;
&lt;blockquote&gt;
\[f(\theta x + (1 - \theta) y) \prec_K \theta f(x) + (1 - \theta) f(y)\]
&lt;/blockquote&gt;

&lt;p&gt;Khi \(m = 1\) và \(K = \mathbb{R}_+\), định nghĩa này trở về đúng định nghĩa hàm lồi thông thường.&lt;/p&gt;

&lt;h3 id=&quot;đặc-trưng-đối-ngẫu-của-tính-lồi-theo-k&quot;&gt;Đặc trưng đối ngẫu của tính lồi theo \(K\)&lt;/h3&gt;

&lt;p&gt;Theo tính chất của bất đẳng thức tổng quát đối ngẫu:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f\) lồi theo \(K\) khi và chỉ khi hàm giá trị thực \(w^T f\) lồi với mọi \(w \succeq_{K^*} 0\).&lt;/li&gt;
  &lt;li&gt;\(f\) lồi chặt theo \(K\) khi và chỉ khi hàm giá trị thực \(w^T f\) lồi chặt với mọi \(w \succeq_{K^*} 0, w \neq 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;hàm-lồi-theo-k-khả-vi&quot;&gt;Hàm lồi theo \(K\) khả vi&lt;/h3&gt;

&lt;p&gt;Một hàm khả vi \(f\) có miền xác định lồi là lồi theo \(K\) khi và chỉ khi:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(y) \succeq_K f(x) + Df(x)(y - x)\) với mọi \(x, y \in \text{dom}f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(Df(x) \in \mathbb{R}^{m \times n}\) là ma trận đạo hàm (Jacobian) của \(f\) tại \(x\).&lt;/p&gt;

&lt;p&gt;Tương tự, \(f\) lồi chặt theo \(K\) khi và chỉ khi:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(y) \succ_K f(x) + Df(x)(y - x)\) với mọi \(x, y \in \text{dom}f\), \(x \neq y\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;định-lý-hợp-thành&quot;&gt;Định lý hợp thành&lt;/h3&gt;

&lt;p&gt;Nhiều quy tắc hợp thành cũng mở rộng cho tính lồi theo \(K\). Chẳng hạn, nếu \(g : \mathbb{R}^n \mapsto \mathbb{R}^p\) lồi theo \(K\), \(h : \mathbb{R}^p \rightarrow \mathbb{R}\) lồi và phần mở rộng giá trị thực mở rộng \(\widetilde{h}\) không giảm theo \(K\), thì hàm hợp \(h \circ g\) là hàm lồi. Kết quả này tổng quát hóa quy tắc hợp thành của hàm lồi với hàm lồi không giảm. (Điều kiện \(\widetilde{h}\) không giảm theo \(K\) đòi hỏi \(h\) không giảm theo \(K\) trên \(\text{dom}h\) và \(\text{dom}h - K = \text{dom}h\).)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-05 Hàm log-lõm và log-lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_05_log_concave_and_log_convex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_05_log_concave_and_log_convex_functions</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Hãy nhìn vào đường cong hình chuông của phân phối chuẩn Gauss \(p(x) = \frac{1}{\sqrt{2\pi}} e^{-x^2/2}\): nó cong xuống quanh đỉnh \(x = 0\) nhưng lại cong lên ở hai phần đuôi $$&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;&amp;gt; 1\(, tức nó **không lồi cũng không lõm**! Thế nhưng chỉ cần đeo &quot;chiếc kính logarit&quot; vào,\)\log p(x) = -\frac{1}{2}x^2 - \frac{1}{2}\log(2\pi)$$ lập tức biến thành một parabol &lt;strong&gt;lõm chặt&lt;/strong&gt; hoàn hảo! Đó chính là sức mạnh của &lt;strong&gt;hàm log-lõm&lt;/strong&gt; và &lt;strong&gt;hàm log-lồi&lt;/strong&gt; — chiếc cầu nối trực tiếp giữa xác suất thống kê với tối ưu hóa lồi.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Bài học này trình bày định nghĩa, điều kiện đạo hàm cấp hai và hàng loạt tính chất bảo toàn tuyệt đẹp (như phép nhân, tích phân và tích chập!) của họ hàm log-lõm / log-lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-tính-chất-của-log-lõm-và-log-lồi&quot;&gt;Kiến thức cần nhớ: Bốn tính chất của Log-lõm và Log-lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; Với hàm dương \(f(x) &amp;gt; 0\) trên miền lồi, \(f\) là &lt;strong&gt;log-lõm&lt;/strong&gt; nếu \(\log f\) lõm (tương đương \(f(\theta x + (1-\theta)y) \ge f(x)^\theta f(y)^{1-\theta}\)); \(f\) là &lt;strong&gt;log-lồi&lt;/strong&gt; nếu \(\log f\) lồi (và mọi hàm log-lồi đều tự động là hàm lồi!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bậc hai (một biến):&lt;/strong&gt; \(f\) log-lõm \(\iff f(x) f&apos;&apos;(x) \le [f&apos;(x)]^2\); \(f\) log-lồi \(\iff f(x) f&apos;&apos;(x) \ge [f&apos;(x)]^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép toán bảo toàn khác hẳn hàm lồi thường:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Tích&lt;/strong&gt; của hai hàm log-lõm là log-lõm (vì \(\log(fg) = \log f + \log g\)); &lt;strong&gt;tổng&lt;/strong&gt; của hai hàm log-lồi là log-lồi (nhưng tổng hai hàm log-lõm thì &lt;em&gt;chưa chắc&lt;/em&gt; log-lõm!).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Định lý Prékopa (phép tích phân và tích chập):&lt;/strong&gt; Tích phân biên theo một biến của hàm mật độ log-lõm vẫn là log-lõm — nhờ đó &lt;strong&gt;hàm phân phối tích lũy (CDF)&lt;/strong&gt; \(\Phi(x) = \int_{-\infty}^x p(t)\,dt\) của phân phối chuẩn cũng là hàm log-lõm!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng trong MLE và bài toán ràng buộc xác suất:&lt;/strong&gt; Giúp chuyển các ràng buộc dạng \(\mathbb{P}(a^T x \le b) \ge \eta\) thành ràng buộc lồi giải được bằng phần mềm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phân-loại-3-hàm-quen-thuộc-theo-bậc-thang-lồi--log-lõm--log-lồi&quot;&gt;Giải thích: Phân loại 3 hàm quen thuộc theo bậc thang Lồi / Log-lõm / Log-lồi&lt;/h3&gt;

&lt;p&gt;Hãy kiểm tra bằng đạo hàm bậc hai của \(f\) và \(\ln f\) trên từng hàm:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hàm Gauss \(f(x) = e^{-x^2/2}\) trên \(\mathbb{R}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f&apos;&apos;(x) = (x^2 - 1)e^{-x^2/2}\) đổi dấu tại \(x = \pm 1 \implies\) không lồi, không lõm.&lt;/li&gt;
      &lt;li&gt;Nhưng \(\ln f(x) = -\frac{1}{2}x^2 \implies (\ln f)&apos;&apos;(x) = -1 &amp;lt; 0 \implies\) &lt;strong&gt;log-lõm chặt&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm \(g(x) = x^2\) trên \(x &amp;gt; 0\) (cẩn thận nhầm lẫn!):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g&apos;&apos;(x) = 2 &amp;gt; 0 \implies g\) là &lt;strong&gt;hàm lồi chặt&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Nhưng \(\ln g(x) = 2\ln x \implies (\ln g)&apos;&apos;(x) = -\frac{2}{x^2} &amp;lt; 0 \implies g\) lại là &lt;strong&gt;hàm log-lõm&lt;/strong&gt;! (Một hàm hoàn toàn có thể &lt;em&gt;vừa lồi vừa log-lõm&lt;/em&gt;!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm \(h(x) = e^{x^2}\) trên \(\mathbb{R}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\ln h(x) = x^2 \implies (\ln h)&apos;&apos;(x) = 2 &amp;gt; 0 \implies\) &lt;strong&gt;log-lồi&lt;/strong&gt; (và tự động là hàm lồi!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này giới thiệu các hàm log-lõm và log-lồi — hai lớp hàm quan trọng trong xác suất, thống kê và tối ưu hóa.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h2&gt;

&lt;h3 id=&quot;hàm-lõm-logarithm-log-lõm&quot;&gt;Hàm lõm logarithm (log-lõm)&lt;/h3&gt;
&lt;p&gt;Một hàm \(f : \mathbb{R}^n \rightarrow \mathbb{R}\) thỏa mãn \(f(x) &amp;gt; 0\) với mọi \(x \in \text{dom}f\) được gọi là &lt;strong&gt;lõm logarithm&lt;/strong&gt; (hay &lt;strong&gt;log-lõm&lt;/strong&gt;) nếu \(\log f\) là hàm lõm:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) là log-lõm với \(f(x) &amp;gt; 0\) cho mọi \(x \in \text{dom}f\) khi và chỉ khi:&lt;br /&gt;
\(f(\theta x + (1 - \theta) y) \geq f(x)^\theta f(y)^{1-\theta}\) với mọi \(x, y \in \text{dom}f\) và \(0 \leq \theta \leq 1\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;hàm-lồi-logarithm-log-lồi&quot;&gt;Hàm lồi logarithm (log-lồi)&lt;/h3&gt;
&lt;p&gt;Một hàm \(f : \mathbb{R}^n \mapsto \mathbb{R}\) thỏa mãn \(f(x) &amp;gt; 0\) với mọi \(x \in \text{dom}f\) được gọi là &lt;strong&gt;lồi logarithm&lt;/strong&gt; (hay &lt;strong&gt;log-lồi&lt;/strong&gt;) nếu \(\log f\) là hàm lồi. Do đó, \(f\) là log-lồi khi và chỉ khi \(1/f\) là log-lõm:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) là log-lồi với \(f(x) &amp;gt; 0\) cho mọi \(x \in \text{dom}f\) \(\Longleftrightarrow \frac{1}{f}\) là log-lõm.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Trong một số bối cảnh, ta cho phép \(f\) nhận giá trị bằng 0 với quy ước \(\log 0 = -\infty\); khi đó \(f\) vẫn được gọi là log-lõm nếu hàm giá trị thực mở rộng \(\log f\) là hàm lõm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vì hàm logarithm đơn điệu tăng, mọi hàm log-lồi đều là hàm giả lồi và mọi hàm log-lõm đều là hàm giả lõm.&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;h3 id=&quot;hàm-affine&quot;&gt;Hàm affine&lt;/h3&gt;
&lt;p&gt;Hàm affine dương sau đây là hàm log-lõm:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x) = a^Tx + b\) trên \(\{x \mid a^Tx + b &amp;gt; 0\}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;hàm-lũy-thừa&quot;&gt;Hàm lũy thừa&lt;/h3&gt;
&lt;p&gt;\(f(x) = x^a\) trên \(\mathbb{R}_{++}\) là hàm log-lồi khi \(a \leq 0\) và là hàm log-lõm khi \(a \geq 0\).&lt;/p&gt;

&lt;h3 id=&quot;hàm-mũ&quot;&gt;Hàm mũ&lt;/h3&gt;
&lt;p&gt;\(f(x) = e^{ax}\) vừa là hàm log-lồi vừa là hàm log-lõm.&lt;/p&gt;

&lt;h3 id=&quot;hàm-phân-phối-tích-lũy-của-phân-phối-chuẩn-gauss&quot;&gt;Hàm phân phối tích lũy của phân phối chuẩn (Gauss)&lt;/h3&gt;
&lt;p&gt;\(\Phi(x) = \frac{1}{ \sqrt{2 \pi } } \int_{-\infty}^x e^{-u^2/2} du\) là hàm log-lõm.&lt;/p&gt;

&lt;h3 id=&quot;hàm-gamma&quot;&gt;Hàm Gamma&lt;/h3&gt;
&lt;p&gt;\(\Gamma(x) = \int_0^\infty u^{x-1}e^{-u} du\) là hàm log-lồi với \(x \geq 1\) (thực tế đúng trên toàn bộ \(\mathbb{R}_{++}\)).&lt;/p&gt;

&lt;h3 id=&quot;định-thức&quot;&gt;Định thức&lt;/h3&gt;
&lt;p&gt;\(\det X\) là hàm log-lõm trên \(\mathbb{S}^n_{++}\).&lt;/p&gt;

&lt;h3 id=&quot;tỉ-số-giữa-định-thức-và-vết&quot;&gt;Tỉ số giữa định thức và vết&lt;/h3&gt;
&lt;p&gt;\(\det X / \text{tr} X\) là hàm log-lõm trên \(\mathbb{S}^n_{++}\).&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;tính-chất&quot;&gt;Tính chất&lt;/h2&gt;

&lt;h3 id=&quot;hàm-log-lồi-và-log-lõm-khả-vi-hai-lần&quot;&gt;Hàm log-lồi và log-lõm khả vi hai lần&lt;/h3&gt;
&lt;p&gt;Nếu \(f\) khả vi hai lần trên miền lồi \(\text{dom} f\) và \(f(x) &amp;gt; 0\), ta có:&lt;/p&gt;
&lt;blockquote&gt;
\[\nabla^2 \log f(x) = \frac{1}{f(x)} \nabla^2 f(x) - \frac{1}{f(x)^2}\nabla f(x) \nabla f(x)^T\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó:&lt;br /&gt;
\(f\) là log-lồi \(\Longleftrightarrow\) \(f(x) \nabla^2 f(x) \succeq \nabla f(x)\nabla f(x)^T\) với mọi \(x \in \text{dom} f\), và&lt;br /&gt;
\(f\) là log-lõm \(\Longleftrightarrow\) \(f(x) \nabla^2 f(x) \preceq \nabla f(x)\nabla f(x)^T\) với mọi \(x \in \text{dom} f\).&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;phép-nhân&quot;&gt;Phép nhân&lt;/h3&gt;
&lt;p&gt;Tính log-lồi và tính log-lõm được bảo toàn qua phép nhân và phép nhân với hằng số dương. Chẳng hạn, nếu \(f\) và \(g\) là log-lõm thì tích theo điểm \(h(x) = f(x)g(x)\) cũng là log-lõm, vì \(\log h(x) = \log f(x) + \log g(x)\) là tổng của hai hàm lõm.&lt;/p&gt;

&lt;h3 id=&quot;phép-cộng-và-tích-phân-của-hàm-log-lồi&quot;&gt;Phép cộng và tích phân của hàm log-lồi&lt;/h3&gt;
&lt;p&gt;Nhìn chung, tổng của hai hàm log-lõm không nhất thiết log-lõm; tuy nhiên tính log-lồi được bảo toàn qua phép cộng. Thật vậy, nếu \(f\) và \(g\) là các hàm log-lồi thì \(F = \log f\) và \(G = \log g\) đều lồi. Áp dụng quy tắc hợp thành vector cho hàm log-sum-exp (là hàm lồi và không giảm theo từng biến), ta thấy:&lt;/p&gt;

&lt;blockquote&gt;
\[\log(\exp F + \exp G) = \log(f + g)\]
&lt;/blockquote&gt;

&lt;p&gt;là một hàm lồi, do đó \(f + g\) là hàm log-lồi.&lt;/p&gt;

&lt;p&gt;Tổng quát hóa sang dạng tích phân: nếu \(f(x, y)\) là log-lồi theo \(x\) với mọi \(y \in C\), thì hàm \(g(x)\) sau đây cũng là log-lồi:&lt;/p&gt;
&lt;blockquote&gt;
\[g(x) = \int_C f(x,y)\, dy\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;tích-phân-và-tích-chập-của-hàm-log-lõm&quot;&gt;Tích phân và tích chập của hàm log-lõm&lt;/h3&gt;
&lt;p&gt;Tính log-lõm cũng được bảo toàn khi lấy tích phân theo một nhóm biến: nếu \(f : \mathbb{R}^n \times \mathbb{R}^m \mapsto \mathbb{R}\) là hàm log-lõm đồng thời theo \((x, y)\), thì hàm biên \(g(x)\) là log-lõm theo \(x \in \mathbb{R}^n\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \times \mathbb{R}^m \mapsto \mathbb{R}\) là log-lõm \(\Longrightarrow\) \(g(x) = \int f(x,y)\, dy\) là log-lõm theo \(x \in \mathbb{R}^n\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Từ kết quả này suy ra mọi phân phối biên của một mật độ xác suất log-lõm đều là hàm log-lõm.&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Tính log-lõm cũng được bảo toàn qua phép tích chập: nếu \(f\) và \(g\) là các hàm log-lõm trên \(\mathbb{R}^n\) thì tích chập của chúng cũng là hàm log-lõm:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f, g\) là log-lõm trên \(\mathbb{R}^n \Longrightarrow (f \ast g)(x) = \int f(x-y)g(y)\, dy\) là log-lõm.&lt;br /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04-04 Các phép toán bảo toàn tính giả lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_04_04_operations_that_preserve_quasiconvexity/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_04_04_operations_that_preserve_quasiconvexity</id>
   <content type="html">&lt;p&gt;Một cái bẫy cực kỳ nguy hiểm khi làm việc với hàm giả lồi: khác với hàm lồi, &lt;strong&gt;tổng của hai hàm giả lồi nói chung KHÔNG phải hàm giả lồi&lt;/strong&gt;! (Hãy tưởng tượng cộng hai hàm bậc thang ngược chiều nhau tạo thành một đỉnh nhô lên ở giữa.) Thay vào đó, hàm giả lồi lại đóng dưới những phép toán riêng của nó — đặc biệt là &lt;strong&gt;cực đại trọng số không âm&lt;/strong&gt;, &lt;strong&gt;hợp thành với hàm không giảm&lt;/strong&gt;, và quan trọng nhất: &lt;strong&gt;biểu diễn qua họ hàm lồi \(\phi_t(x) \le 0\)&lt;/strong&gt; dùng trực tiếp trong thuật toán chia đôi!&lt;/p&gt;

&lt;p&gt;Bài học này hệ thống hóa các quy tắc lắp ghép hàm giả lồi và cách giải bài toán tối ưu giả lồi bằng chuỗi bài toán lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-quy-tắc-bảo-toàn-và-biểu-diễn-hàm-giả-lồi&quot;&gt;Kiến thức cần nhớ: Bốn quy tắc bảo toàn và biểu diễn Hàm giả lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cực đại từng điểm (không phải phép cộng!):&lt;/strong&gt; Nếu \(f_i\) giả lồi và \(w_i \ge 0\) thì \(f(x) = \max_i w_i f_i(x)\) (hoặc \(\sup_{y} w(y) f(x, y)\)) luôn giả lồi. &lt;em&gt;Cảnh báo:&lt;/em&gt; \(f_1 + f_2\) không nhất thiết giả lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hợp thành với hàm không giảm và ánh xạ affine:&lt;/strong&gt; Nếu \(g\) giả lồi và \(h: \mathbb{R} \to \mathbb{R}\) không giảm thì \(h(g(x))\) giả lồi (nhờ đó mọi phép biến đổi đơn điệu như \(e^{g}, g^3, \ln g\) bảo toàn tính giả lồi!); hợp thành \(f(Ax + b)\) hay phân thức tuyến tính cũng bảo toàn tính giả lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa từng phần:&lt;/strong&gt; Nếu \(f(x, y)\) giả lồi đồng thời theo \((x, y)\) và \(C\) là tập lồi, thì \(g(x) = \inf_{y \in C} f(x, y)\) vẫn giả lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biểu diễn qua họ hàm lồi \(\phi_t(x)\):&lt;/strong&gt; Mọi hàm giả lồi đều biểu diễn được tập mức dưới dạng \(f(x) \le t \iff \phi_t(x) \le 0\) với \(\phi_t\) là &lt;strong&gt;hàm lồi&lt;/strong&gt; theo \(x\) — đây chính là động cơ của phương pháp chia đôi tối ưu giả lồi!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-3-bước-chia-đôi-cho-bài-toán-giả-lồi-min_x-ge-0-fracx2--1x--2&quot;&gt;Giải thích: Giải tay 3 bước chia đôi cho bài toán giả lồi \(\min_{x \ge 0} \frac{x^2 + 1}{x + 2}\)&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu giả lồi \(\min_{x \ge 0} f(x) = \frac{x^2 + 1}{x + 2}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Biểu diễn tập mức dưới bằng họ hàm lồi \(\phi_t(x)\):&lt;/strong&gt;
Với \(x \ge 0\) (nên \(x + 2 &amp;gt; 0\)), điều kiện \(f(x) \le t\) tương đương:
\(\phi_t(x) = x^2 - tx + (1 - 2t) \le 0.\)
Với mọi \(t\) cố định, \(\phi_t(x)\) là &lt;strong&gt;hàm bậc hai lồi&lt;/strong&gt; (vì \(\phi_t&apos;&apos;(x) = 2 &amp;gt; 0\))!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử mức \(t = 1\):&lt;/strong&gt; \(\phi_1(x) = x^2 - x - 1 \le 0\). Tại \(x = 1 \ge 0\): \(\phi_1(1) = -1 \le 0\) (khả thi!) \(\implies p^* \le 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử mức \(t = 0.5\):&lt;/strong&gt; \(\phi_{0.5}(x) = x^2 - 0.5x \le 0\). Tại \(x = 0 \ge 0\): \(\phi_{0.5}(0) = 0 \le 0\) (khả thi!) \(\implies p^* \le 0.5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử mức \(t = 0.4\):&lt;/strong&gt; \(\phi_{0.4}(x) = x^2 - 0.4x + 0.2 \le 0\). Tính biệt thức \(\Delta = (-0.4)^2 - 4(1)(0.2) = 0.16 - 0.80 = -0.64 &amp;lt; 0 \implies \phi_{0.4}(x) &amp;gt; 0\ \forall x\) (&lt;strong&gt;vô nghiệm&lt;/strong&gt;!) \(\implies p^* &amp;gt; 0.4\).
Chỉ sau 3 bước kiểm tra khả thi lồi, ta đã kẹp chặt nghiệm tối ưu vào khoảng \((0.4, 0.5]\) (nghiệm đúng là \(p^* = 2\sqrt{5} - 4 \approx 0.4721\) tại \(x^* = \sqrt{5} - 2 \approx 0.236\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này trình bày các phép toán bảo toàn tính giả lồi của hàm số.&lt;/p&gt;

&lt;h2 id=&quot;maximum-trọng-số-không-âm&quot;&gt;Maximum trọng số không âm&lt;/h2&gt;

&lt;p&gt;Nếu \(f_1, \dots, f_m\) là các hàm giả lồi và \(w_i \geq 0\), thì maximum có trọng số không âm của chúng cũng là hàm giả lồi:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f = \max\{w_1f_1, ... ,w_mf_m\}\) với \(w_i \geq 0\) là giả lồi&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tổng quát hơn cho họ vô hạn các hàm:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x) = \sup_{y \in C}(w(y)g(x,y))\) với \(w(y) \geq 0\),
trong đó \(g(x,y)\) là hàm giả lồi theo \(x\) với mọi \(y \in C\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;hợp-thành&quot;&gt;Hợp thành&lt;/h2&gt;

&lt;p&gt;Nếu \(g : \mathbb{R}^n \mapsto \mathbb{R}\) là hàm giả lồi và \(h : \mathbb{R} \mapsto \mathbb{R}\) không giảm, thì hàm hợp thành \(f = h \circ g\) cũng là hàm giả lồi:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f = h \circ g\) là giả lồi nếu \(h\) không giảm và \(g\) là giả lồi.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hợp thành một hàm giả lồi với biến đổi affine hoặc biến đổi tuyến tính-phân thức cũng bảo toàn tính giả lồi: nếu \(f\) là hàm giả lồi thì \(g(x) = f(Ax + b)\) giả lồi, và \(\tilde{g}(x) = f((Ax + b)/(c^Tx + d))\) giả lồi trên miền \(\{x \mid c^Tx + d &amp;gt; 0,\; (Ax + b)/(c^Tx + d) \in \text{dom}f\}\).&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;cực-tiểu-hóa-từng-phần&quot;&gt;Cực tiểu hóa từng phần&lt;/h2&gt;

&lt;p&gt;Nếu \(f(x, y)\) là hàm giả lồi đồng thời theo \((x, y)\) và \(C\) là một tập lồi, thì phép lấy infimum theo \(y \in C\) bảo toàn tính giả lồi:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(g(x) = \inf_{y \in C} f(x,y)\) là giả lồi nếu \(f\) giả lồi theo \((x,y)\) và \(C\) là một tập lồi.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;biểu-diễn-thông-qua-họ-các-hàm-lồi&quot;&gt;Biểu diễn thông qua họ các hàm lồi&lt;/h2&gt;

&lt;p&gt;Các tập mức dưới của một hàm giả lồi \(f\) có thể được biểu diễn bằng các bất đẳng thức liên quan đến một họ hàm lồi \(\phi_t : \mathbb{R}^n \mapsto \mathbb{R}\) (tham số hóa bởi \(t \in \mathbb{R}\)) sao cho:&lt;/p&gt;
&lt;blockquote&gt;
\[f(x) \leq t \Longleftrightarrow \phi_t(x) \leq 0\]
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, tập mức dưới mức \(t\) của hàm giả lồi \(f\) trùng với tập mức dưới mức 0 của hàm lồi \(\phi_t\). Hơn nữa, với mọi \(x \in \mathbb{R}^n\) và mọi \(s \geq t\), họ hàm này thỏa mãn tính lồng nhau:&lt;/p&gt;
&lt;blockquote&gt;
\[\phi_t(x) \leq 0 \Rightarrow \phi_s(x) \leq 0 \text{ với } s \geq t\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04-03 Hàm giả lồi khả vi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_04_03_differentiable_quasiconvex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_04_03_differentiable_quasiconvex_functions</id>
   <content type="html">&lt;p&gt;Với hàm lồi khả vi, ma trận Hessian phải bán xác định dương theo &lt;strong&gt;mọi hướng&lt;/strong&gt; \(v \in \mathbb{R}^n\). Còn với hàm giả lồi khả vi, điều kiện đó được nới lỏng một cách đầy tinh tế: ta chỉ cần đường cong không uốn xuống theo những hướng &lt;strong&gt;vuông góc với gradient&lt;/strong&gt; (tức các hướng nằm dọc theo siêu mặt mức \(f(x) = c\))! Nhờ trực giác hình học này, điều kiện bậc nhất và bậc hai của hàm giả lồi trở nên vô cùng dễ hiểu và dễ kiểm tra.&lt;/p&gt;

&lt;p&gt;Bài học này thiết lập hai tiêu chuẩn vi phân cốt lõi để nhận diện hàm giả lồi khả vi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-vi-phân-của-hàm-giả-lồi&quot;&gt;Kiến thức cần nhớ: Hình học vi phân của Hàm giả lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bậc nhất:&lt;/strong&gt; Hàm khả vi \(f\) trên miền lồi là giả lồi khi và chỉ khi:
\(f(y) \le f(x) \implies \nabla f(x)^T (y - x) \le 0.\)
&lt;em&gt;Ý nghĩa hình học:&lt;/em&gt; Tại mọi điểm \(x\) có \(\nabla f(x) \ne 0\), vector \(\nabla f(x)\) định nghĩa một &lt;strong&gt;siêu phẳng hỗ trợ&lt;/strong&gt; cho tập mức dưới \(\{y : f(y) \le f(x)\}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sự khác biệt tinh tế với hàm lồi:&lt;/strong&gt; Với hàm giả lồi, \(\nabla f(x^*) = 0\) &lt;strong&gt;không đủ&lt;/strong&gt; để suy ra \(x^*\) là cực tiểu toàn cục (ví dụ \(f(x) = x^3\) có \(f&apos;(0) = 0\) nhưng \(0\) là điểm uốn, không phải cực tiểu!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bậc hai (trên siêu phẳng tiếp xúc mức):&lt;/strong&gt; Nếu \(f\) giả lồi khả vi cấp 2 thì với mọi \(x\) và mọi vector \(y\) trực giao với gradient (\(\nabla f(x)^T y = 0\)), ta phải có \(y^T \nabla^2 f(x) y \ge 0\) — Hessian chỉ có thể có tối đa &lt;strong&gt;một&lt;/strong&gt; giá trị riêng âm (dọc theo phương gradient)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-tra-điều-kiện-bậc-nhất-trên-fx--x3-và-bác-bỏ-gx---x2&quot;&gt;Giải thích: Kiểm tra điều kiện bậc nhất trên \(f(x) = x^3\) và bác bỏ \(g(x) = -x^2\)&lt;/h3&gt;

&lt;p&gt;Áp dụng trực tiếp tiêu chuẩn \(f(y) \le f(x) \implies f&apos;(x)(y - x) \le 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hàm giả lồi \(f(x) = x^3\) (\(f&apos;(x) = 3x^2 \ge 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Chọn \(x = 1,\ y = -1\): ta có \(f(-1) = -1 \le f(1) = 1\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra vế phải: \(f&apos;(1)(y - x) = 3(1)^2 (-1 - 1) = -6 \le 0\) (thỏa mãn!).&lt;/li&gt;
      &lt;li&gt;Tổng quát, \(y^3 \le x^3 \iff y - x \le 0\), nhân thêm \(3x^2 \ge 0\) luôn cho \(3x^2(y - x) \le 0\) \(\implies x^3\) chắc chắn giả lồi!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm KHÔNG giả lồi \(g(x) = -x^2\) (\(g&apos;(x) = -2x\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Chọn \(x = 1,\ y = -2\): ta có \(g(-2) = -4 \le g(1) = -1\) (vế trái đúng).&lt;/li&gt;
      &lt;li&gt;Kiểm tra vế phải: \(g&apos;(1)(y - x) = (-2)(-2 - 1) = (-2)(-3) = +6 &amp;gt; 0\)!
Vế phải dương mâu thuẫn với điều kiện bậc nhất \(\implies g(x) = -x^2\) &lt;strong&gt;không phải&lt;/strong&gt; hàm giả lồi (quả thật tập mức dưới \(\{-x^2 \le -1\} = (-\infty, -1] \cup [1, \infty)\) bị tách làm hai mảnh rời nhau!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này trình bày các điều kiện đặc trưng bậc nhất và bậc hai cho hàm giả lồi khả vi.&lt;/p&gt;

&lt;h2 id=&quot;điều-kiện-bậc-nhất&quot;&gt;Điều kiện bậc nhất&lt;/h2&gt;

&lt;p&gt;Cho hàm khả vi \(f : \mathbb{R}^n \rightarrow \mathbb{R}\) có miền xác định \(\text{dom}f\) lồi. Khi đó \(f\) là hàm giả lồi khi và chỉ khi:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) là giả lồi \(\iff\) \(f(y) \leq f(x) \Rightarrow \nabla f(x)^T(y-x) \leq 0\) với mọi \(x, y \in \text{dom}f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/3.12_Three_level_curves_OV6vtPq.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Ba đường mức của một hàm giả lồi \(f\): gradient \(\nabla f(x)\) là vector pháp tuyến của một siêu phẳng hỗ trợ tập mức dưới \(\{z \mid f(z) \leq f(x)\}\) tại \(x\).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Điều kiện bậc nhất của hàm giả lồi có dạng khá giống đặc trưng bậc nhất của hàm lồi (xem bài &lt;a href=&quot;/contents/vi/chapter03/03_01_03_key_properties_of_convex_functions/&quot;&gt;03-01-03&lt;/a&gt;), nhưng vẫn có khác biệt quan trọng: với hàm lồi, \(\nabla f(x) = 0\) suy ra \(x\) là điểm cực tiểu toàn cục, còn với hàm giả lồi thì điều này không nhất thiết đúng.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;điều-kiện-bậc-hai&quot;&gt;Điều kiện bậc hai&lt;/h2&gt;

&lt;p&gt;Khi \(f\) khả vi hai lần và là hàm giả lồi, với mọi \(x \in \text{dom}f\) và mọi \(y \in \mathbb{R}^n\) ta có:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) là giả lồi, \(y^T \nabla f(x) = 0 \Longrightarrow y^T \nabla^2 f(x)y \geq 0\) với mọi \(x \in \text{dom} f\), mọi \(y \in \mathbb{R}^n\) &lt;br /&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Trong trường hợp một biến trên \(\mathbb{R}\), điều kiện này rút gọn thành:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f\) là giả lồi, \(f&apos;(x) = 0 \Rightarrow f&apos;&apos;(x) \geq 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nghĩa là tại mọi điểm dừng (đạo hàm bậc nhất bằng 0), đạo hàm bậc hai phải không âm. Trong không gian \(\mathbb{R}^n\), điều kiện bậc hai kéo theo hai hệ quả sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Nếu \(\nabla f(x) = 0\) thì ma trận Hessian phải nửa xác định dương: \(\nabla^2f(x) \succeq 0\).&lt;/li&gt;
  &lt;li&gt;Nếu \(\nabla f(x) \neq 0\) thì \(y^T \nabla f(x) = 0 \Rightarrow y^T \nabla^2 f(x)y \geq 0\), tức là ma trận Hessian \(\nabla^2 f(x)\) nửa xác định dương trên không gian con \((n-1)\) chiều \(\nabla f(x)^\perp\) (tập các vector vuông góc với \(\nabla f(x)\)).&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04-02 Các tính chất cơ bản của hàm giả lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_04_02_basic_properties_of_quasiconvex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_04_02_basic_properties_of_quasiconvex_functions</id>
   <content type="html">&lt;p&gt;Bất đẳng thức Jensen cho hàm lồi yêu cầu giá trị tại trung điểm không vượt quá &lt;em&gt;trung bình có trọng số&lt;/em&gt; của hai đầu mút: \(f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y)\). Với hàm giả lồi, yêu cầu đó được nới lỏng vừa đủ: giá trị tại điểm nằm giữa chỉ cần không vượt quá &lt;strong&gt;giá trị lớn hơn&lt;/strong&gt; trong hai đầu mút, tức \(f(\theta x + (1-\theta)y) \le \max\{f(x), f(y)\}\)!&lt;/p&gt;

&lt;p&gt;Chỉ một thay đổi nhỏ từ “trung bình” sang “\(\max\)” nhưng vẫn đủ sức loại bỏ mọi đỉnh nhô lên chắn giữa hai điểm thấp — giải thích vì sao hàm giả lồi trên \(\mathbb{R}\) không bao giờ có hai thung lũng tách rời.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-tính-chất-cơ-bản-của-hàm-giả-lồi&quot;&gt;Kiến thức cần nhớ: Ba tính chất cơ bản của Hàm giả lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Jensen biến đổi:&lt;/strong&gt; \(f\) giả lồi \(\iff \operatorname{dom} f\) lồi và \(f(\theta x + (1-\theta)y) \le \max\{f(x), f(y)\}\) với mọi \(x, y \in \operatorname{dom} f,\ \theta \in [0, 1]\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đặc trưng hàm giả lồi liên tục trên \(\mathbb{R}\):&lt;/strong&gt; Một hàm liên tục một biến là giả lồi khi và chỉ khi nó thuộc đúng 1 trong 3 dạng: (1) không giảm, (2) không tăng, hoặc (3) tồn tại điểm mốc \(c\) sao cho không tăng với \(x \le c\) và không giảm với \(x \ge c\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cảnh báo về điểm dừng “bằng phẳng”:&lt;/strong&gt; Khác với hàm lồi, một hàm giả lồi có thể có &lt;strong&gt;cực tiểu địa phương không phải cực tiểu toàn cục&lt;/strong&gt; nếu có một đoạn bằng phẳng ngang (plateau) — ví dụ hàm bậc thang hoặc \(f(x) = 0\) trên \([1, 2]\) nhưng giảm xuống \(-1\) ở \(x = 0\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-jensen-biến-đổi-trên-fx--ln-x-x--0&quot;&gt;Giải thích: Kiểm chứng Jensen biến đổi trên \(f(x) = \ln x\) (\(x &amp;gt; 0\))&lt;/h3&gt;

&lt;p&gt;Xét \(f(x) = \ln x\) trên miền \(x &amp;gt; 0\) với hai điểm \(x = 1\) và \(y = e^2 \approx 7.389\), chọn \(\theta = 0.5\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giá trị tại hai đầu mút và trung điểm:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(1) = \ln 1 = 0\); \(f(e^2) = \ln(e^2) = 2\).&lt;/li&gt;
      &lt;li&gt;Trung điểm: \(z = \frac{1 + 7.389}{2} = 4.1945 \implies f(z) = \ln(4.1945) \approx 1.434\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh với Jensen thường (cho hàm lồi):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Trung bình hai đầu mút: \(0.5 f(1) + 0.5 f(e^2) = 0.5(0) + 0.5(2) = 1.0\).&lt;/li&gt;
      &lt;li&gt;Ta thấy \(f(z) \approx 1.434 &amp;gt; 1.0 \implies\) &lt;strong&gt;vi phạm&lt;/strong&gt; Jensen thường (vì \(\ln x\) lõm, không lồi).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh với Jensen biến đổi (cho hàm giả lồi):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giá trị lớn hơn của hai đầu mút: \(\max\{f(1), f(e^2)\} = \max\{0, 2\} = 2.0\).&lt;/li&gt;
      &lt;li&gt;Ta thấy \(f(z) \approx 1.434 \le 2.0 \implies\) &lt;strong&gt;thỏa mãn&lt;/strong&gt; Jensen biến đổi!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này trình bày các tính chất cơ bản của hàm giả lồi, bao gồm bất đẳng thức Jensen biến đổi và đặc trưng của hàm giả lồi liên tục một biến.&lt;/p&gt;

&lt;h2 id=&quot;bất-đẳng-thức-jensen-biến-đổi&quot;&gt;Bất đẳng thức Jensen biến đổi&lt;/h2&gt;

&lt;p&gt;Hàm \(f\) là giả lồi khi và chỉ khi miền xác định \(\text{dom}f\) lồi và thỏa mãn bất đẳng thức Jensen biến đổi sau:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(\theta x + (1 - \theta)y) \leq \max\{f(x), f(y)\}\) với mọi \(x, y \in \text{dom}f\), \(0 \leq \theta \leq 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, dọc theo đoạn thẳng nối hai điểm \(x\) và \(y\), giá trị của hàm giả lồi \(f\) không bao giờ vượt quá giá trị lớn hơn trong hai giá trị \(f(x)\) và \(f(y)\).
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/Fig.3.10_quasiconvex_function_on_R_4uChnEm.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Hàm giả lồi trên \(\mathbb{R}\): giá trị của \(f\) giữa \(x\) và \(y\) luôn nhỏ hơn hoặc bằng \(\max\{f(x), f(y)\}\).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;hàm-giả-lồi-trên-mathbbr&quot;&gt;Hàm giả lồi trên \(\mathbb{R}\)&lt;/h2&gt;

&lt;p&gt;Một hàm liên tục \(f : \mathbb{R} \mapsto \mathbb{R}\) là giả lồi khi và chỉ khi nó thỏa mãn ít nhất một trong ba điều kiện sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(f\) không giảm trên \(\text{dom}f\).&lt;/li&gt;
  &lt;li&gt;\(f\) không tăng trên \(\text{dom}f\).&lt;/li&gt;
  &lt;li&gt;Tồn tại một điểm \(c \in \text{dom} f\) sao cho \(f\) không tăng trên \(\{t \in \text{dom}f \mid t \leq c\}\) và không giảm trên \(\{t \in \text{dom}f \mid t \geq c\}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/Fig.3.11_quasiconvex_function_on_R_2_PPQpNiU.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Hàm giả lồi trên \(\mathbb{R}\): không tăng với \(t \leq c\) và không giảm với \(t \geq c\) (\(t \in \text{dom} f\)).&lt;/strong&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04-01 Hàm giả lồi: định nghĩa và ví dụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_04_01_quasiconvex_functions_definition_and_examples/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_04_01_quasiconvex_functions_definition_and_examples</id>
   <content type="html">&lt;p&gt;Khi nhắc đến “lồi”, ta thường hình dung một chiếc bát uốn cong lên trên. Thế nhưng một hàm cong xuống như \(\log x\), một hàm bậc thang rời rạc như \(\lceil x \rceil\), hay một phân thức tuyến tính \(\frac{a^T x + b}{c^T x + d}\) đều có chung một cấu trúc hình học quý giá: nếu bạn cắt ngang đồ thị ở bất kỳ độ cao \(\alpha\) nào, phần nằm dưới nhát cắt luôn tạo thành một &lt;strong&gt;tập lồi&lt;/strong&gt; không bị tách thành nhiều mảnh!&lt;/p&gt;

&lt;p&gt;Bài học này đi sâu vào định nghĩa chính thức của hàm giả lồi, hàm giả lõm, hàm giả tuyến tính và phân tích từng ví dụ kinh điển.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-họ-ví-dụ-mẫu-của-hàm-giả-lồi&quot;&gt;Kiến thức cần nhớ: Bốn họ ví dụ mẫu của Hàm giả lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mọi hàm đơn điệu trên \(\mathbb{R}\):&lt;/strong&gt; Như \(\log x\) (vừa giả lồi vừa giả lõm \(\implies\) &lt;strong&gt;giả tuyến tính / quasilinear&lt;/strong&gt;), \(x^3\) hay hàm làm tròn lên \(\lceil x \rceil\) (thậm chí không liên tục nhưng tập mức dưới vẫn là nửa khoảng \((-\infty, \lfloor \alpha \rfloor]\) lồi!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm phân thức tuyến tính:&lt;/strong&gt; \(f(x) = \frac{a^T x + b}{c^T x + d}\) trên miền \(c^T x + d &amp;gt; 0\) là hàm &lt;strong&gt;giả tuyến tính&lt;/strong&gt; — nền tảng của Quy hoạch phân thức tuyến tính (Linear-Fractional Programming, ví dụ tối ưu hóa tỷ số lợi nhuận trên chi phí).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tỷ số khoảng cách và bậc của đa thức:&lt;/strong&gt; Khoảng cách tỉ đối \(\|x - a\|_2 / \|x - b\|_2\) trên nửa không gian gần \(a\) hơn, hay độ dài (bậc) của tín hiệu rời rạc trong xử lý tín hiệu số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân biệt giả lồi và giả lõm:&lt;/strong&gt; \(f\) giả lõm \(\iff -f\) giả lồi \(\iff\) mọi tập mức &lt;strong&gt;trên&lt;/strong&gt; \(\{x : f(x) \ge \alpha\}\) đều là tập lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tập-mức-dưới-của-hàm-phân-thức-tuyến-tính-fx--frac2x--1x--1&quot;&gt;Giải thích: Kiểm chứng tập mức dưới của hàm phân thức tuyến tính \(f(x) = \frac{2x + 1}{x + 1}\)&lt;/h3&gt;

&lt;p&gt;Xét \(f(x) = \frac{2x + 1}{x + 1}\) trên miền lồi \(x &amp;gt; -1\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải bất đẳng thức tập mức dưới \(f(x) \le \alpha\):&lt;/strong&gt;
Vì mẫu số \(x + 1 &amp;gt; 0\), ta được phép nhân chéo không đổi chiều dấu:
\(\frac{2x + 1}{x + 1} \le \alpha \iff 2x + 1 \le \alpha(x + 1) \iff (2 - \alpha)x \le \alpha - 1.\)
Đây là một &lt;strong&gt;bất đẳng thức tuyến tính&lt;/strong&gt; theo \(x\), nên tập nghiệm luôn là một nửa không gian (giao với \(x &amp;gt; -1\) là một khoảng lồi!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử giá trị cụ thể \(\alpha = 1.5\):&lt;/strong&gt;
\((2 - 1.5)x \le 1.5 - 1 \iff 0.5 x \le 0.5 \iff x \le 1 \implies S_{1.5} = (-1, 1] \text{ (tập lồi!)}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại sao \(f\) không phải hàm lồi?&lt;/strong&gt; Tính đạo hàm:
\(f&apos;(x) = \frac{1}{(x + 1)^2} &amp;gt; 0, \qquad f&apos;&apos;(x) = -\frac{2}{(x + 1)^3} &amp;lt; 0 \quad (\forall x &amp;gt; -1).\)
Hàm thực chất &lt;strong&gt;lõm chặt&lt;/strong&gt;, nhưng vì đơn điệu tăng nên vẫn là hàm &lt;strong&gt;giả lồi&lt;/strong&gt; (thậm chí giả tuyến tính)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Một hàm \(f:\mathbb{R}^n \rightarrow \mathbb{R}\) được gọi là giả lồi nếu miền xác định và mọi tập mức dưới \(\{x \mid f(x) \leq \alpha\}\) của nó đều là tập lồi với mọi \(\alpha \in \mathbb{R}\). &lt;strong&gt;Hàm giả lồi là sự tổng quát hóa của hàm lồi&lt;/strong&gt; và xuất hiện thường xuyên trong các bài toán tối ưu.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h2&gt;

&lt;p&gt;Một hàm \(f: \mathbb{R}^n \rightarrow \mathbb{R}\) được gọi là &lt;strong&gt;giả lồi&lt;/strong&gt; (hoặc &lt;strong&gt;đơn đỉnh — unimodal&lt;/strong&gt;) nếu miền xác định \(\text{dom}f\) và tất cả các tập mức dưới \(S_{\alpha}\) (xem bài &lt;a href=&quot;/contents/vi/chapter03/03_01_03_key_properties_of_convex_functions/&quot;&gt;03-01-03&lt;/a&gt;) đều là tập lồi:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \rightarrow \mathbb{R}\) là giả lồi nếu \(\text{dom}f\) và
\(S_{\alpha} =\{x \in \text{dom}f \mid f(x) \leq \alpha\}\) với mọi \(\alpha \in \mathbb{R}\) đều lồi.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nếu \(-f\) là hàm giả lồi thì \(f\) được gọi là &lt;strong&gt;giả lõm&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \rightarrow \mathbb{R}\) là giả lõm nếu \(\text{dom}f\) và
\(S_{\alpha} = \{ x \in \text{dom}f \mid f(x) \geq \alpha \}\) với mọi \(\alpha \in \mathbb{R}\) đều lồi.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hàm \(f\) vừa giả lồi vừa giả lõm được gọi là &lt;strong&gt;giả tuyến tính&lt;/strong&gt;; khi đó miền xác định và mọi tập mức \(\{x \in \text{dom}f \mid f(x)=\alpha\}\) đều là tập lồi. Hình dưới đây minh họa một hàm giả lồi trên \(\mathbb{R}\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/Fig3.9_quasiconvex_ftn_cAsoUpr.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] hàm giả lồi trên R [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Trong hình trên, tập mức dưới \(S_{\alpha}\) là đoạn \([a,b]\) và tập mức dưới \(S_{\beta}\) là khoảng \((-\infty,c]\) — cả hai đều là tập lồi. &lt;strong&gt;Mọi hàm lồi đều có các tập mức dưới lồi nên đều là hàm giả lồi, nhưng chiều ngược lại không đúng:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) lồi \(\Longrightarrow\) \(f\) giả lồi&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;p&gt;Dưới đây là một số ví dụ quen thuộc về hàm giả lồi.&lt;/p&gt;

&lt;h3 id=&quot;logarithm&quot;&gt;Logarithm&lt;/h3&gt;
&lt;p&gt;Hàm \(\log x\) trên \(\mathbb{R}_{++}\) là hàm giả lồi (đồng thời là hàm giả lõm, nên là hàm giả tuyến tính):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\log x\) trên \(\mathbb{R}_{++}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;hàm-làm-tròn-lên-ceil&quot;&gt;Hàm làm tròn lên (ceil)&lt;/h3&gt;
&lt;p&gt;Hàm lấy phần nguyên trên vừa giả lồi vừa giả lõm:&lt;/p&gt;
&lt;blockquote&gt;
\[\text{ceil}(x) = \inf \{z \in \mathbb{Z} \mid z \geq x\}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;độ-dài-của-vector&quot;&gt;Độ dài của vector&lt;/h3&gt;
&lt;p&gt;Định nghĩa độ dài của vector \(x \in \mathbb{R}^n\) là chỉ số lớn nhất của các thành phần khác không:&lt;/p&gt;
&lt;blockquote&gt;
\[f(x) = \max\{i \mid x_i \neq 0\}\]
&lt;/blockquote&gt;

&lt;p&gt;Với mọi \(\alpha \ge 0\), tập mức dưới thỏa mãn:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x) \leq \alpha \iff x_i = 0\) với mọi \(i = \lfloor\alpha\rfloor + 1,\dots,n\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Đây là một không gian con tuyến tính của \(\mathbb{R}^n\) (nên là tập lồi), do đó \(f\) là hàm giả lồi.&lt;/p&gt;

&lt;h3 id=&quot;hàm-tuyến-tính-phân-thức&quot;&gt;Hàm tuyến tính-phân thức&lt;/h3&gt;
&lt;p&gt;Hàm tuyến tính-phân thức sau đây vừa giả lồi vừa giả lõm, tức là hàm giả tuyến tính:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x) = \frac{a^Tx+b}{c^Tx+d}\) với \(\text{dom}f =\{x \mid c^Tx + d &amp;gt; 0\}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;hàm-tỉ-số-khoảng-cách&quot;&gt;Hàm tỉ số khoảng cách&lt;/h3&gt;
&lt;p&gt;Với hai điểm cố định \(a, b \in \mathbb{R}^n\), xét hàm tỉ số giữa khoảng cách Euclidean từ \(x\) đến \(a\) và từ \(x\) đến \(b\):&lt;/p&gt;

&lt;blockquote&gt;
\[f(x) = \frac{\|x - a\|_2}{\|x - b\|_2}\]
&lt;/blockquote&gt;

&lt;p&gt;Hàm \(f\) là giả lồi trên nửa không gian \(\{x \mid \|x - a\|_2 \leq \|x - b\|_2 \}\). Thật vậy, với mọi \(\alpha \leq 1\), tập mức dưới \(\{x \mid \|x - a\|_2 \le \alpha \|x - b\|_2\}\) là một hình cầu Euclidean (hoặc một nửa không gian khi \(\alpha = 1\)), nên là tập lồi.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04 Hàm giả lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_04_00_Quasiconvex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_04_00_Quasiconvex_functions</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Trong kinh tế học, kỹ thuật và học máy, rất nhiều hàm mục tiêu hoàn toàn tự nhiên — như tỷ lệ chi phí trên lợi ích \(\frac{c^T x + d}{e^T x + f}\), độ dài đoạn tín hiệu, hay hàm $$\sqrt{&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;}$$ — lại &lt;strong&gt;không phải hàm lồi&lt;/strong&gt;. Liệu ta phải bó tay xếp chúng vào nhóm không lồi khó giải? Không hề! Nếu tất cả các &lt;strong&gt;tập mức dưới&lt;/strong&gt; của hàm vẫn là tập lồi, ta gọi đó là &lt;strong&gt;hàm giả lồi (quasiconvex)&lt;/strong&gt; — và bài toán cực tiểu hóa chúng vẫn giải được chính xác bằng một chuỗi ngắn các bài toán khả thi lồi (phương pháp chia đôi)!&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Phần 03-04 mở rộng tầm nhìn của bạn vượt ra ngoài ranh giới hàm lồi cổ điển sang thế giới hàm giả lồi đầy thực dụng.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-đặc-trưng-quan-trọng-của-hàm-giả-lồi&quot;&gt;Kiến thức cần nhớ: Ba đặc trưng quan trọng của Hàm giả lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa qua tập mức dưới:&lt;/strong&gt; \(f\) là giả lồi khi \(\operatorname{dom} f\) lồi và mọi tập mức dưới \(S_\alpha = \{x : f(x) \le \alpha\}\) đều là tập lồi. Mọi hàm lồi đều là giả lồi, nhưng chiều ngược lại rộng hơn rất nhiều.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trực giác một biến (Đơn điệu hoặc một đáy):&lt;/strong&gt; Trên \(\mathbb{R}\), hàm liên tục là giả lồi khi và chỉ khi nó đơn điệu tăng, đơn điệu giảm, hoặc giảm đến một điểm rồi tăng (unimodal) — không có nhiều thung lũng lồi lõm!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán chia đôi (Bisection):&lt;/strong&gt; Vì kiểm tra \(\exists x : f(x) \le t\) chính là kiểm tra một tập lồi \(S_t\) có khác rỗng hay không, ta có thể chặt đôi khoảng chứa \(p^*\) sau mỗi bước để tìm cực tiểu toàn cục với độ chính xác \(\epsilon\) chỉ sau \(\lceil \log_2((u-l)/\epsilon)\rceil\) bước!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-hàm-fx--sqrtx--không-lồi-nhưng-giả-lồi-tuyệt-đối&quot;&gt;Giải thích: Hàm \(f(x) = \sqrt{|x|}\) — Không lồi nhưng Giả lồi tuyệt đối&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét hàm $$f(x) = \sqrt{&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;}\(trên\)\mathbb{R}$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh \(f\) là hàm giả lồi:&lt;/strong&gt; Với mọi mức \(\alpha \in \mathbb{R}\):
    &lt;ul&gt;
      &lt;li&gt;Nếu \(\alpha &amp;lt; 0\): \(S_\alpha = \emptyset\) (tập lồi).&lt;/li&gt;
      &lt;li&gt;Nếu \(\alpha \ge 0\): \(S_\alpha = \{x \in \mathbb{R} : \sqrt{|x|} \le \alpha\} = \{x : |x| \le \alpha^2\} = [-\alpha^2,\ \alpha^2]\).
Vì mọi đoạn đóng \([-\alpha^2, \alpha^2]\) đều là tập lồi, \(f\) chắc chắn là &lt;strong&gt;hàm giả lồi&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh \(f\) KHÔNG phải hàm lồi:&lt;/strong&gt; Chọn \(x = 0,\ y = 4,\ \theta = 0.5\) (trung điểm \(2\)):
    &lt;ul&gt;
      &lt;li&gt;\(f(2) = \sqrt{2} \approx 1.414\).&lt;/li&gt;
      &lt;li&gt;\(0.5 f(0) + 0.5 f(4) = 0.5(0) + 0.5(2) = 1\).
Vì \(1.414 &amp;gt; 1\), đồ thị nhô lên &lt;strong&gt;phía trên&lt;/strong&gt; dây cung (vi phạm tính lồi), nhưng vẫn chỉ có đúng một đáy duy nhất tại \(x^* = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này giới thiệu khái niệm hàm giả lồi (quasiconvex function), cùng các ví dụ tiêu biểu và tính chất cơ bản của chúng.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-03 Hàm liên hợp</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_03_the_conjugate_function/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_03_the_conjugate_function</id>
   <content type="html">&lt;p&gt;Trong vật lý cơ học, phép biến đổi Legendre đổi góc nhìn từ vị trí–vận tốc sang vị trí–động lượng để chuyển phương trình Lagrange thành phương trình Hamilton đầy đối xứng. Trong tối ưu hóa lồi, Werner Fenchel mở rộng ý tưởng đó cho &lt;em&gt;mọi&lt;/em&gt; hàm số (kể cả không trơn, không lồi!) thành &lt;strong&gt;hàm liên hợp Fenchel&lt;/strong&gt; \(f^*(y) = \sup_{x \in \operatorname{dom} f}(y^T x - f(x))\): thay vì mô tả một đường cong bằng tập các điểm \((x, f(x))\), ta mô tả nó bằng tập hợp tất cả các &lt;strong&gt;siêu phẳng tiếp tuyến có độ dốc \(y\)&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Hàm liên hợp là chiếc chìa khóa mở thẳng cánh cửa sang lý thuyết đối ngẫu Fenchel–Rockafellar và đối ngẫu Lagrange trong các chương tiếp theo.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-tính-chất-kỳ-diệu-của-hàm-liên-hợp-f&quot;&gt;Kiến thức cần nhớ: Bốn tính chất kỳ diệu của Hàm liên hợp \(f^*\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa hình học (Độ chênh lớn nhất theo độ dốc \(y\)):&lt;/strong&gt; \(f^*(y)\) đo khoảng cách thẳng đứng lớn nhất giữa đường thẳng đi qua gốc có độ dốc \(y\) (là \(y^T x\)) và đồ thị \(f(x)\); nói cách khác, \(-f^*(y)\) chính là tung độ gốc của tiếp tuyến có độ dốc \(y\) nằm sát ngay dưới đồ thị \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(f^*\) LUÔN là hàm lồi:&lt;/strong&gt; Vì \(f^*(y) = \sup_x (y^T x - f(x))\) là cận trên đúng theo \(x\) của một họ các hàm &lt;strong&gt;affine&lt;/strong&gt; theo \(y\), nên dù \(f\) ban đầu có không lồi đến đâu, \(f^*\) vẫn luôn là hàm lồi đóng!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Fenchel–Young:&lt;/strong&gt; Từ định nghĩa suy ra ngay \(f(x) + f^*(y) \ge y^T x\) với mọi \(x, y\); dấu bằng xảy ra đúng khi \(y \in \partial f(x)\) (với hàm trơn là \(y = \nabla f(x)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hợp kép (Biconjugate \(f^{**}\)):&lt;/strong&gt; Nếu \(f\) là hàm lồi đóng, thì \(f^{**} = f\) — biến đổi hai lần đưa ta trở về chính xác hàm ban đầu không mất một chút thông tin nào!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-hàm-liên-hợp-fy-của-fx--2x2-và-kiểm-chứng-fenchelyoung&quot;&gt;Giải thích: Tính tay hàm liên hợp \(f^*(y)\) của \(f(x) = 2x^2\) và kiểm chứng Fenchel–Young&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai lồi chặt \(f(x) = 2x^2\) trên \(\mathbb{R}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập bài toán cực đại hóa theo \(x\) (giữ \(y\) cố định):&lt;/strong&gt;
\(f^*(y) = \sup_{x \in \mathbb{R}} \left(yx - 2x^2\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm đạt cực đại:&lt;/strong&gt; Hàm \(\phi(x) = yx - 2x^2\) là parabol úp xuống (lõm chặt). Cho đạo hàm theo \(x\) bằng \(0\):
\(\phi&apos;(x) = y - 4x = 0 \implies x^*(y) = \frac{y}{4}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thay ngược \(x^*\) để thu được công thức đóng của \(f^*(y)\):&lt;/strong&gt;
\(f^*(y) = y\left(\frac{y}{4}\right) - 2\left(\frac{y}{4}\right)^2 = \frac{y^2}{4} - \frac{y^2}{8} = \frac{y^2}{8}.\)
(Tổng quát: liên hợp của \(\frac{1}{2}a x^2\) là \(\frac{1}{2a} y^2\) — độ cong \(a\) bị nghịch đảo thành \(1/a\)!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng bất đẳng thức Fenchel–Young \(f(x) + f^*(y) \ge xy\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(x = 3,\ y = 4\): \(f(3) + f^*(4) = 18 + 2 = 20 &amp;gt; 3 \cdot 4 = 12\) (dấu chặt).&lt;/li&gt;
      &lt;li&gt;Tại \(x = 1,\ y = f&apos;(1) = 4\): \(f(1) + f^*(4) = 2 + 2 = 4 = 1 \cdot 4\) (&lt;strong&gt;đạt dấu bằng&lt;/strong&gt;!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này giới thiệu hàm liên hợp (còn gọi là liên hợp lồi hoặc liên hợp Fenchel) — một khái niệm cốt lõi trong giải tích lồi và lý thuyết đối ngẫu, dùng để biến đổi và phân tích các bài toán tối ưu.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa-và-nền-tảng-toán-học&quot;&gt;Định nghĩa và nền tảng toán học&lt;/h2&gt;

&lt;p&gt;Với một hàm \(f: \mathbb{R}^n \to \mathbb{R}\), &lt;strong&gt;hàm liên hợp&lt;/strong&gt; \(f^*: \mathbb{R}^n \to \mathbb{R}\) được định nghĩa là:&lt;/p&gt;

\[f^*(y) = \sup_{x \in \text{dom}(f)} \{y^T x - f(x)\}\]

&lt;p&gt;trong đó \(\sup\) ký hiệu supremum (cận trên đúng) lấy trên toàn bộ miền xác định của \(f\).&lt;/p&gt;

&lt;h3 id=&quot;ý-nghĩa-hình-học&quot;&gt;Ý nghĩa hình học&lt;/h3&gt;

&lt;p&gt;Hàm liên hợp có cách hiểu hình học trực quan:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f^*(y)\) là &lt;strong&gt;hiệu lớn nhất&lt;/strong&gt; giữa hàm tuyến tính \(y^T x\) và hàm gốc \(f(x)\).&lt;/li&gt;
  &lt;li&gt;Về mặt hình học, với siêu phẳng có hệ số góc \(y\), giá trị \(-f^*(y)\) là tung độ gốc lớn nhất sao cho siêu phẳng \(y^T x - f^*(y)\) vẫn nằm phía dưới đồ thị của \(f\).&lt;/li&gt;
  &lt;li&gt;Phép lấy liên hợp chuyển biểu diễn hàm từ không gian biến gốc (không gian nguyên thủy) sang không gian đối ngẫu của các vector độ dốc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;vai-trò-của-hàm-liên-hợp&quot;&gt;Vai trò của hàm liên hợp&lt;/h3&gt;

&lt;p&gt;Hàm liên hợp được sử dụng để:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chuyển bài toán tối ưu gốc thành &lt;strong&gt;bài toán đối ngẫu&lt;/strong&gt; tương ứng.&lt;/li&gt;
  &lt;li&gt;Xây dựng công cụ phân tích cho &lt;strong&gt;lý thuyết đối ngẫu&lt;/strong&gt; (trình bày ở Chương 11).&lt;/li&gt;
  &lt;li&gt;Cho phép thay thế trực tiếp trong &lt;strong&gt;đối ngẫu Lagrange&lt;/strong&gt; mà không cần tính đạo hàm tường minh.&lt;/li&gt;
  &lt;li&gt;Thiết lập liên hệ giữa nghiệm tối ưu nguyên thủy và nghiệm tối ưu đối ngẫu.&lt;/li&gt;
&lt;/ol&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/conjugate_function.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Hàm liên hợp [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;giải-thích-trực-quan&quot;&gt;Giải thích trực quan&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hàm tuyến tính và tính lồi:&lt;/strong&gt; Với mỗi \(x\) cố định, hàm \(y \mapsto \langle y, x \rangle - f(x)\) là hàm affine theo \(y\), nên vừa lồi vừa lõm. Khi lấy supremum theo \(x\) của một họ hàm affine như vậy, ta thu được bao trên của chúng.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bao trên của các đường thẳng luôn tạo thành mặt lồi:&lt;/strong&gt; Trong không gian 2D, mỗi hàm affine ứng với một đường thẳng; bao trên của tập các đường thẳng đó không thể có phần lõm xuống nên luôn là một đường cong lồi.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/conjugate_function_2.svg&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Giải thích trực quan hàm liên hợp [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;các-tính-chất-cơ-bản&quot;&gt;Các tính chất cơ bản&lt;/h2&gt;

&lt;h3 id=&quot;1-tính-lồi&quot;&gt;1. Tính lồi&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(f^*\) luôn là hàm lồi&lt;/strong&gt;, bất kể \(f\) ban đầu có lồi hay không.&lt;/li&gt;
  &lt;li&gt;Lý do là \(f^*(y)\) là supremum theo điểm của họ các hàm affine \(y \mapsto y^T x - f(x)\), mà supremum của một họ hàm lồi luôn là hàm lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-bất-đẳng-thức-fenchel&quot;&gt;2. Bất đẳng thức Fenchel&lt;/h3&gt;
&lt;p&gt;Với mọi \(x \in \text{dom}(f)\) và \(y \in \text{dom}(f^*)\):
\(f(x) + f^*(y) \geq x^T y\)&lt;/p&gt;

&lt;p&gt;Bất đẳng thức này thiết lập quan hệ cận dưới cơ bản giữa một hàm và hàm liên hợp của nó.&lt;/p&gt;

&lt;h3 id=&quot;3-liên-hợp-kép&quot;&gt;3. Liên hợp kép&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Trong trường hợp tổng quát: \(f^{**} \leq f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nếu \(f\) đóng và lồi:&lt;/strong&gt; \(f^{**} = f\) (khôi phục lại chính xác hàm ban đầu).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-quan-hệ-dưới-vi-phân&quot;&gt;4. Quan hệ dưới vi phân&lt;/h3&gt;
&lt;p&gt;Nếu \(f\) đóng và lồi, thì với mọi \(x, y\):
\(y \in \partial f(x) \iff x \in \partial f^*(y) \iff f(x) + f^*(y) = x^T y\)&lt;/p&gt;

&lt;p&gt;Quan hệ này thể hiện tính đối xứng giữa không gian nguyên thủy và không gian đối ngẫu.&lt;/p&gt;

&lt;h2 id=&quot;các-ví-dụ-chi-tiết&quot;&gt;Các ví dụ chi tiết&lt;/h2&gt;

&lt;h3 id=&quot;ví-dụ-1-logarithm-âm&quot;&gt;Ví dụ 1: Logarithm âm&lt;/h3&gt;
&lt;p&gt;Xét \(f(x) = -\log x\) với \(x &amp;gt; 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính toán:&lt;/strong&gt;
\(f^*(y) = \sup_{x&amp;gt;0} \{xy + \log x\}\)&lt;/p&gt;

&lt;p&gt;Lấy đạo hàm theo \(x\) và cho bằng 0:
\(\frac{d}{dx}(xy + \log x) = y + \frac{1}{x} = 0\)&lt;/p&gt;

&lt;p&gt;Ta thu được \(x^* = -\frac{1}{y}\) (chỉ hợp lệ khi \(y &amp;lt; 0\); khi \(y \ge 0\), biểu thức tiến ra \(+\infty\) khi \(x \to +\infty\)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt;
\(f^*(y) = \begin{cases}
-1 - \log(-y), &amp;amp; \text{nếu } y &amp;lt; 0 \\
+\infty, &amp;amp; \text{nếu } y \geq 0
\end{cases}\)&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-2-hàm-bậc-hai&quot;&gt;Ví dụ 2: Hàm bậc hai&lt;/h3&gt;
&lt;p&gt;Xét \(f(x) = \frac{1}{2}x^T Q x\) với \(Q \succ 0\) (đối xứng xác định dương).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính toán:&lt;/strong&gt;
\(f^*(y) = \sup_{x} \{y^T x - \frac{1}{2}x^T Q x\}\)&lt;/p&gt;

&lt;p&gt;Đặt gradient theo \(x\) bằng 0:
\(\nabla_x (y^T x - \frac{1}{2}x^T Q x) = y - Qx = 0 \implies x^* = Q^{-1}y\)&lt;/p&gt;

&lt;p&gt;Thay \(x^*\) trở lại biểu thức:
\(f^*(y) = y^T Q^{-1} y - \frac{1}{2}(Q^{-1}y)^T Q (Q^{-1}y) = \frac{1}{2}y^T Q^{-1} y\)&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-3-giá-trị-tuyệt-đối-một-chiều&quot;&gt;Ví dụ 3: Giá trị tuyệt đối (một chiều)&lt;/h3&gt;
&lt;p&gt;Xét \(f(x) = \lvert x \rvert\) với \(x \in \mathbb{R}\).&lt;/p&gt;

\[f^*(y) = \sup_{x} \{yx - \lvert x \rvert\}\]

&lt;p&gt;&lt;strong&gt;Xét hai trường hợp:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(\lvert y \rvert \leq 1\): \(yx - \lvert x \rvert \le 0\) với mọi \(x\), nên supremum bằng 0 (đạt tại \(x = 0\)).&lt;/li&gt;
  &lt;li&gt;Nếu \(\lvert y \rvert &amp;gt; 1\): biểu thức không bị chặn trên nên supremum bằng \(+\infty\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt;
\(f^*(y) = \begin{cases}
0, &amp;amp; \text{nếu } \lvert y \rvert \leq 1 \\
+\infty, &amp;amp; \text{nếu } \lvert y \rvert &amp;gt; 1
\end{cases}\)&lt;/p&gt;

&lt;p&gt;Đây chính là &lt;strong&gt;hàm chỉ thị&lt;/strong&gt; của đoạn \([-1, 1]\).&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-4-hàm-mũ&quot;&gt;Ví dụ 4: Hàm mũ&lt;/h3&gt;
&lt;p&gt;Xét \(f(x) = e^x\) với \(x \in \mathbb{R}\).&lt;/p&gt;

\[f^*(y) = \sup_{x} \{yx - e^x\}\]

&lt;p&gt;Đặt đạo hàm theo \(x\) bằng 0: \(y - e^x = 0 \implies x^* = \log y\) (với \(y &amp;gt; 0\)). Khi \(y = 0\), \(\sup_x (-e^x) = 0\); khi \(y &amp;lt; 0\), cho \(x \to -\infty\) thì \(yx - e^x \to +\infty\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt;
\(f^*(y) = \begin{cases}
y \log y - y, &amp;amp; \text{nếu } y &amp;gt; 0 \\
0, &amp;amp; \text{nếu } y = 0 \\
+\infty, &amp;amp; \text{nếu } y &amp;lt; 0
\end{cases}\)&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong tối ưu hóa&lt;/h2&gt;

&lt;p&gt;Hàm liên hợp xuất hiện trong nhiều nội dung quan trọng (sẽ được trình bày kỹ hơn ở Chương 11 và Chương 13):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu Lagrange:&lt;/strong&gt; Chuyển bài toán gốc sang bài toán đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu Fenchel:&lt;/strong&gt; Khung lý thuyết tổng quát cho đối ngẫu trong tối ưu lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Toán tử gần kề (proximal operator):&lt;/strong&gt; Nền tảng của nhiều thuật toán tối ưu hiện đại.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải tích biến phân:&lt;/strong&gt; Phân tích bài toán tối ưu thông qua các cặp hàm liên hợp.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;trực-quan-hóa-tương-tác&quot;&gt;Trực quan hóa tương tác&lt;/h2&gt;

&lt;p&gt;Bạn có thể khám phá cách hoạt động của hàm liên hợp qua công cụ tương tác sau:&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;a href=&quot;../conjugate_function_interactive.html&quot; target=&quot;_blank&quot; style=&quot;display: inline-block; padding: 12px 24px; background-color: #3498db; color: white; text-decoration: none; border-radius: 6px; font-weight: bold; box-shadow: 0 2px 4px rgba(0,0,0,0.2);&quot;&gt;
        🎯 Khởi động Công cụ Khám phá Hàm Liên hợp Tương tác
    &lt;/a&gt;
&lt;/div&gt;

&lt;p&gt;Công cụ này cho phép:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Quan sát song song đồ thị của các hàm quen thuộc và hàm liên hợp của chúng&lt;/li&gt;
  &lt;li&gt;Điều chỉnh tham số để theo dõi sự thay đổi của hàm liên hợp&lt;/li&gt;
  &lt;li&gt;Khảo sát các đường tiếp tuyến ứng với ý nghĩa hình học của phép lấy liên hợp&lt;/li&gt;
  &lt;li&gt;So sánh nhiều ví dụ kèm lời giải thích toán học&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;p&gt;Những điểm chính cần ghi nhớ về hàm liên hợp:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; \(f^*(y) = \sup_x \{y^T x - f(x)\}\), chuyển hàm từ không gian nguyên thủy sang không gian đối ngẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi:&lt;/strong&gt; \(f^*\) luôn lồi, không phụ thuộc vào tính lồi của \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Fenchel:&lt;/strong&gt; \(f(x) + f^*(y) \geq x^T y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hệ đối ngẫu:&lt;/strong&gt; Khi \(f\) đóng và lồi, \(f^{**} = f\), làm cầu nối giữa bài toán nguyên thủy và đối ngẫu trong tối ưu lồi, đối ngẫu Lagrange, các phương pháp gần kề và giải tích biến phân.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>03-02 Các phép toán bảo toàn tính lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_02_operations_that_preserve_convexity/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_02_operations_that_preserve_convexity</id>
   <content type="html">&lt;p&gt;Khi bạn viết một bài toán tối ưu trong thư viện như CVX hay CVXPY, phần mềm không hề ngồi tính ma trận Hessian khổng lồ cho hàm mục tiêu của bạn! Thay vào đó, nó chạy một hệ thống quy tắc đại số gọi là &lt;strong&gt;Quy hoạch lồi kỷ luật (Disciplined Convex Programming — DCP)&lt;/strong&gt; dựa hoàn toàn vào nội dung bài học này: bắt đầu từ các hàm lồi nguyên tử và áp dụng tuần tự các &lt;strong&gt;phép toán bảo toàn tính lồi&lt;/strong&gt; (tổng trọng số dương, hợp thành affine, cực đại từng điểm, cực tiểu hóa từng phần, phối cảnh).&lt;/p&gt;

&lt;p&gt;Làm chủ bộ quy tắc này giúp bạn chứng minh tính lồi của những hàm cực kỳ cồng kềnh chỉ trong vài giây mà không cần đụng đến đạo hàm cấp hai.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhóm-phép-toán-bảo-toàn-tính-lồi&quot;&gt;Kiến thức cần nhớ: Bốn nhóm phép toán bảo toàn tính lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tổng trọng số không âm và hợp thành affine:&lt;/strong&gt; Nếu \(f_i\) lồi và \(w_i \ge 0\) thì \(\sum w_i f_i\) lồi; nếu \(f\) lồi thì \(g(x) = f(Ax + b)\) luôn lồi (nhờ đó \(\|Ax - b\|_1\) hay \(\log\sum e^{a_i^T x + b_i}\) lập tức lồi!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực đại từng điểm (Pointwise Maximum / Supremum):&lt;/strong&gt; Nếu \(f_\alpha(x)\) lồi theo \(x\) với mọi chỉ số \(\alpha \in \mathcal{A}\) (kể cả vô hạn!), thì \(f(x) = \sup_{\alpha \in \mathcal{A}} f_\alpha(x)\) luôn lồi — vì epigraph của nó chính là giao của các epigraph lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc hợp thành vô hướng \(h(g(x))\):&lt;/strong&gt; \(h(g(x))\) lồi khi &lt;strong&gt;(\(h\) lồi, không giảm và \(g\) lồi)&lt;/strong&gt; hoặc &lt;strong&gt;(\(h\) lồi, không tăng và \(g\) lõm)&lt;/strong&gt;. Ví dụ: \(e^{g(x)}\) lồi nếu \(g\) lồi; \(1/g(x)\) lồi nếu \(g &amp;gt; 0\) lõm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa từng phần và Phối cảnh:&lt;/strong&gt; Nếu \(f(x, y)\) lồi đồng thời theo \((x, y)\) thì \(g(x) = \inf_{y \in C} f(x, y)\) lồi; hàm phối cảnh \(g(x, t) = t f(x/t)\) (\(t &amp;gt; 0\)) cũng luôn bảo toàn tính lồi!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tính-lồi-của-hàm-cực-đại-từng-điểm-3-nhánh&quot;&gt;Giải thích: Kiểm chứng tính lồi của hàm cực đại từng điểm 3 nhánh&lt;/h3&gt;

&lt;p&gt;Xét hàm không trơn (có góc nhọn nên không thể dùng Hessian):
\(f(x) = \max\left(2x - 1,\ x^2 - 2x + 2,\ e^{-x}\right), \qquad x \in \mathbb{R}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh lồi trong 1 dòng bằng quy tắc bảo toàn:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nhánh 1: \(f_1(x) = 2x - 1\) (affine \(\Rightarrow\) lồi).&lt;/li&gt;
      &lt;li&gt;Nhánh 2: \(f_2(x) = x^2 - 2x + 2 = (x - 1)^2 + 1\) (\(f_2&apos;&apos; = 2 &amp;gt; 0 \Rightarrow\) lồi).&lt;/li&gt;
      &lt;li&gt;Nhánh 3: \(f_3(x) = e^{-x}\) (\(f_3&apos;&apos; = e^{-x} &amp;gt; 0 \Rightarrow\) lồi).
Vì \(f\) là &lt;strong&gt;cực đại từng điểm&lt;/strong&gt; của 3 hàm lồi, \(f\) chắc chắn là &lt;strong&gt;hàm lồi&lt;/strong&gt; trên toàn \(\mathbb{R}\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra số trực tiếp tại \(x = 0,\ 1,\ 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(0) = \max(-1,\ 2,\ 1) = 2\) (nhánh 2 thắng).&lt;/li&gt;
      &lt;li&gt;\(f(1) = \max(1,\ 1,\ e^{-1} \approx 0.368) = 1\) (nhánh 1 và 2 gặp nhau tạo góc nhọn, chính là đáy cực tiểu toàn cục!).&lt;/li&gt;
      &lt;li&gt;\(f(2) = \max(3,\ 2,\ e^{-2} \approx 0.135) = 3\) (nhánh 1 thắng).
Kiểm chứng bất đẳng thức Jensen tại trung điểm \(x = 1\) của \(0\) và \(2\): \(f(1) = 1 \le \frac{f(0) + f(2)}{2} = \frac{2 + 3}{2} = 2.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này trình bày các phép toán bảo toàn tính lồi của hàm số:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tổng trọng số không âm&lt;/li&gt;
  &lt;li&gt;Hợp thành với hàm affine và hợp thành tổng quát&lt;/li&gt;
  &lt;li&gt;Maximum và supremum theo điểm&lt;/li&gt;
  &lt;li&gt;Hàm phối cảnh&lt;/li&gt;
  &lt;li&gt;Hàm tuyến tính-phân thức&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;tổng-trọng-số-không-âm&quot;&gt;Tổng trọng số không âm&lt;/h2&gt;

&lt;p&gt;Các hàm lồi đóng đối với phép nhân với số không âm và phép cộng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nhân một hàm lồi \(f\) với số thực không âm \(\alpha \ge 0\) vẫn thu được một hàm lồi:
    &lt;blockquote&gt;
      &lt;p&gt;\(f\) lồi \(\Rightarrow \alpha f\) lồi với \(\alpha \ge 0\)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Tổng của hai hàm lồi \(f_1, f_2\) là một hàm lồi:
    &lt;blockquote&gt;
      &lt;p&gt;\(f_1, f_2\) lồi \(\Rightarrow f_1 + f_2\) lồi&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Tổng trọng số không âm của các hàm lồi \(f_1, \dots, f_n\) là hàm lồi:
    &lt;blockquote&gt;
      &lt;p&gt;\(f_1, ..., f_n\) lồi \(\Rightarrow \alpha_1f_1 + \cdots + \alpha_nf_n\) lồi, \(\alpha_1, ..., \alpha_n \ge 0\)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;hợp-thành&quot;&gt;Hợp thành&lt;/h2&gt;

&lt;h3 id=&quot;1-hợp-thành-với-ánh-xạ-affine&quot;&gt;1. Hợp thành với ánh xạ affine&lt;/h3&gt;
&lt;p&gt;Nếu \(f\) là hàm lồi thì hàm \(g(x) = f(Ax + b)\) cũng là hàm lồi:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) lồi \(\Rightarrow f(Ax + b)\) lồi&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;2-hợp-thành-vô-hướng&quot;&gt;2. Hợp thành vô hướng&lt;/h3&gt;
&lt;p&gt;Xét hàm \(g:\mathbb{R}^n \mapsto \mathbb{R}\) và hàm \(h:\mathbb{R}\mapsto \mathbb{R}\). Hàm hợp thành \(f(x)=h(g(x))\) có tính lồi hoặc lõm theo các quy tắc sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;hợp thành của \(g:\mathbb{R}^n \mapsto \mathbb{R}\) và \(h:\mathbb{R}\mapsto \mathbb{R}\):
\(f(x)=h(g(x))\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Nếu \(g\) lồi, \(h\) lồi và \(\tilde{h}\) không giảm, thì \(f\) lồi.&lt;/li&gt;
  &lt;li&gt;Nếu \(g\) lõm, \(h\) lồi và \(\tilde{h}\) không tăng, thì \(f\) lồi.&lt;/li&gt;
  &lt;li&gt;Nếu \(g\) lõm, \(h\) lõm và \(\tilde{h}\) không giảm, thì \(f\) lõm.&lt;/li&gt;
  &lt;li&gt;Nếu \(g\) lồi, \(h\) lõm và \(\tilde{h}\) không tăng, thì \(f\) lõm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;lưu-ý&quot;&gt;[Lưu ý]&lt;/h3&gt;
&lt;p&gt;Tính đơn điệu phải đúng cho phần mở rộng giá trị thực mở rộng \(\tilde{h}\) của \(h\) (gán \(+\infty\) ngoài \(\text{dom } h\) khi \(h\) lồi, hoặc \(-\infty\) khi \(h\) lõm).&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(g\) lồi thì \(\exp g(x)\) lồi.&lt;/li&gt;
  &lt;li&gt;Nếu \(g\) lõm và dương thì \(1/g(x)\) lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-hợp-thành-vector&quot;&gt;3. Hợp thành vector&lt;/h3&gt;
&lt;p&gt;Xét \(g:\mathbb{R}^n \mapsto \mathbb{R}^k\) và \(h:\mathbb{R}^k \mapsto \mathbb{R}\), với hàm hợp thành \(f(x)=h(g(x))=h(g_1(x),g_2(x),\dots,g_k(x))\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;hợp thành của \(g:\mathbb{R}^n\mapsto\mathbb{R}^k\) và \(h:\mathbb{R}^k\mapsto\mathbb{R}\):
\(f(x)=h(g(x))=h(g_1(x),g_2(x),...,g_k(x))\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Nếu mỗi \(g_i\) lồi, \(h\) lồi và \(\tilde{h}\) không giảm theo từng đối số, thì \(f\) lồi.&lt;/li&gt;
  &lt;li&gt;Nếu mỗi \(g_i\) lồi, \(h\) lõm và \(\tilde{h}\) không tăng theo từng đối số, thì \(f\) lõm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-1&quot;&gt;Ví dụ&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu các hàm \(g_i\) lõm và dương thì \(\sum_{i=1}^{m} \log g_i(x)\) lõm.&lt;/li&gt;
  &lt;li&gt;Nếu các hàm \(g_i\) lồi thì \(\log \sum_{i=1}^{m} \exp g_i(x)\) lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;maximum-và-supremum-theo-điểm&quot;&gt;Maximum và supremum theo điểm&lt;/h2&gt;

&lt;h3 id=&quot;1-maximum-theo-điểm&quot;&gt;1. Maximum theo điểm&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f_1, f_2\) là các hàm lồi \(\Rightarrow f(x) = \max \{ f_1(x), f_2(x) \}\) (với \(\text{dom } f = \text{dom } f_1 \cap \text{dom } f_2\)) là hàm lồi.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;2-supremum-theo-điểm&quot;&gt;2. Supremum theo điểm&lt;/h3&gt;
&lt;p&gt;Nếu \(f(x, y)\) lồi theo \(x\) với mọi \(y \in A\) thì \(g(x) = \sup_{y\in A} f(x, y)\) cũng là hàm lồi theo \(x\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f(x, y)\) lồi theo \(x\) với mọi \(y \in A\)
\(\Rightarrow g(x) = \sup_{y\in A} f(x, y)\) với \(\text{dom } g = \{x \mid (x, y) \in \text{dom} f \text{ với mọi } y \in A, \sup_{y \in A} f(x, y) &amp;lt; \infty \}\) lồi theo \(x\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;hàm-phối-cảnh&quot;&gt;Hàm phối cảnh&lt;/h2&gt;

&lt;p&gt;Hàm phối cảnh \(g: \mathbb{R}^n \times \mathbb{R} \mapsto \mathbb{R}\) của một hàm \(f: \mathbb{R}^n \mapsto \mathbb{R}\) được định nghĩa là:&lt;/p&gt;

\[g(x,t) = tf\left(\frac{x}{t}\right), \quad \text{dom } g = \left\{(x,t) \left| \frac{x}{t} \in \text{dom } f, t&amp;gt;0 \right.\right\}\]

&lt;p&gt;Phép biến đổi phối cảnh bảo toàn tính lồi: nếu \(f\) lồi thì \(g\) cũng lồi.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-2&quot;&gt;Ví dụ&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Hàm bậc hai chia tuyến tính:&lt;/strong&gt; Vì \(f(x) = x^Tx\) là hàm lồi, nên hàm phối cảnh của nó \(g(x,t) = x^Tx/t\) là hàm lồi với \(t &amp;gt; 0\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Entropy tương đối (từ logarithm âm):&lt;/strong&gt; Vì \(f(x) = -\log x\) là hàm lồi trên \(\mathbb{R}_{++}\), nên hàm phối cảnh của nó — entropy tương đối \(g(x,t) = t\log t - t\log x\) — là hàm lồi trên \(\mathbb{R}_{++}^2\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Kết hợp với biến đổi affine:&lt;/strong&gt; Nếu \(f\) lồi thì hàm \(g(x)=(c^Tx+d)f\left(\frac{Ax+b}{c^Tx+d}\right)\) là hàm lồi trên miền:&lt;/p&gt;
    &lt;blockquote&gt;
\[\left\{x \left| c^Tx+d&amp;gt;0, \frac{Ax+b}{c^Tx+d} \in \text{dom } f\right.\right\}\]
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-01-03 Các tính chất chính của hàm lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_01_03_key_properties_of_convex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_01_03_key_properties_of_convex_functions</id>
   <content type="html">&lt;p&gt;Mỗi tính chất đặc trưng của hàm lồi mở ra một “cửa ngõ” khác nhau để giải quyết bài toán tối ưu: &lt;strong&gt;epigraph&lt;/strong&gt; cho phép biến hàm mục tiêu phi tuyến thành biến phụ tuyến tính \(t\); &lt;strong&gt;tập mức dưới&lt;/strong&gt; giải thích vì sao miền ràng buộc \(g_i(x) \le 0\) luôn là tập lồi; &lt;strong&gt;đặc trưng bậc nhất&lt;/strong&gt; chứng minh ngay rằng \(\nabla f(x^*) = 0\) là đủ để kết luận cực tiểu toàn cục; còn &lt;strong&gt;đặc trưng bậc hai&lt;/strong&gt; quy việc kiểm tra tính lồi về bài toán giá trị riêng của Hessian!&lt;/p&gt;

&lt;p&gt;Một cái bẫy kinh điển mà người học rất hay mắc phải là nhầm chiều mũi tên của tập mức dưới — hãy chú ý kỹ ví dụ phản chứng trong khung giải thích bên dưới.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-đặc-trưng-của-hàm-lồi&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột đặc trưng của hàm lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đặc trưng Epigraph:&lt;/strong&gt; \(f\) lồi \(\iff \operatorname{epi} f = \{(x, t) : f(x) \le t\}\) là tập lồi. Đây là cây cầu biến bài toán \(\min f(x)\) thành \(\min_{x, t} t\) với ràng buộc \((x, t) \in \operatorname{epi} f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập mức dưới (Sublevel Set \(S_\alpha = \{x : f(x) \le \alpha\}\)):&lt;/strong&gt; Nếu \(f\) lồi thì &lt;strong&gt;mọi&lt;/strong&gt; \(S_\alpha\) đều là tập lồi. &lt;strong&gt;Cảnh báo:&lt;/strong&gt; Chiều ngược lại &lt;strong&gt;SAI&lt;/strong&gt;! (Hàm có mọi tập mức dưới lồi chỉ mới là &lt;em&gt;hàm giả lồi&lt;/em&gt;, chưa chắc lồi.)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đặc trưng bậc nhất (\(f\) khả vi):&lt;/strong&gt; \(f\) lồi \(\iff f(y) \ge f(x) + \nabla f(x)^T(y - x)\ \forall x, y \in \operatorname{dom} f\). Hệ quả tức thì: nếu \(\nabla f(x^*) = 0\) thì \(f(y) \ge f(x^*)\ \forall y\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đặc trưng bậc hai (\(f\) khả vi cấp 2):&lt;/strong&gt; \(f\) lồi \(\iff \operatorname{dom} f\) lồi và \(\nabla^2 f(x) \succeq 0\ \forall x \in \operatorname{dom} f\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bẫy-chiều-ngược-của-tập-mức-dưới-qua-ví-dụ-gx--x3&quot;&gt;Giải thích: Bẫy chiều ngược của tập mức dưới qua ví dụ \(g(x) = x^3\)&lt;/h3&gt;

&lt;p&gt;So sánh hai hàm số: \(f(x) = -\ln x\) (trên \(x &amp;gt; 0\)) và \(g(x) = x^3\) (trên \(\mathbb{R}\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hàm lồi \(f(x) = -\ln x\) (\(x &amp;gt; 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Kiểm tra bậc hai: \(f&apos;(x) = -1/x,\ f&apos;&apos;(x) = 1/x^2 &amp;gt; 0 \implies f\) &lt;strong&gt;lồi chặt&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Tập mức dưới ứng với mức \(\alpha\) bất kỳ: \(S_\alpha = \{x &amp;gt; 0 : -\ln x \le \alpha\} = \{x : x \ge e^{-\alpha}\} = [e^{-\alpha}, +\infty)\) — là một khoảng (tập lồi!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm KHÔNG lồi nhưng mọi tập mức dưới ĐỀU lồi — \(g(x) = x^3\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Xét tập mức dưới với mọi \(\alpha \in \mathbb{R}\):
\(S_\alpha = \{x \in \mathbb{R} : x^3 \le \alpha\} = (-\infty,\ \sqrt[3]{\alpha}].\)
Với &lt;em&gt;mọi&lt;/em&gt; \(\alpha\), \(S_\alpha\) luôn là một nửa đường thẳng — hoàn toàn là &lt;strong&gt;tập lồi&lt;/strong&gt;!&lt;/li&gt;
      &lt;li&gt;Nhưng kiểm tra bậc hai: \(g&apos;&apos;(x) = 6x\). Tại \(x = -1\), \(g&apos;&apos;(-1) = -6 &amp;lt; 0\) (lõm chặt trên miền âm!).
Vậy chỉ thấy các tập mức dưới lồi là &lt;strong&gt;chưa đủ&lt;/strong&gt; để kết luận hàm lồi!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;đặc-trưng-epigraph&quot;&gt;Đặc trưng epigraph&lt;/h2&gt;

&lt;p&gt;Như đã nêu ở &lt;a href=&quot;/contents/vi/chapter01/01_02_convex_optimization_problem/&quot;&gt;bài 01-02&lt;/a&gt;, hàm \(f\) lồi khi và chỉ khi epigraph (tập trên đồ thị) của nó là một tập lồi:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f\) lồi \(\iff \text{epi}(f) = \{(x,t) \in \mathbb{R}^{n+1} \mid x \in \text{dom} f, f(x) \le t \}\) là một tập lồi&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;tập-mức-dưới-lồi&quot;&gt;Tập mức dưới lồi&lt;/h2&gt;

&lt;p&gt;Nếu \(f\) là hàm lồi thì mọi tập mức dưới của nó đều là tập lồi:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\{x \in \text{dom } f: f(x) \leq t\}\), với mọi \(t \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;lưu-ý-tập-mức-dưới&quot;&gt;[Lưu ý] Tập mức dưới&lt;/h3&gt;
&lt;p&gt;Với một hàm \(f:\mathbb{R}^n \mapsto \mathbb{R}\), tập \(C_\alpha = \{x \in \text{dom} f \mid f(x) \leq \alpha\}\) được gọi là &lt;em&gt;tập mức dưới mức \(\alpha\)&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;đặc-trưng-bậc-nhất&quot;&gt;Đặc trưng bậc nhất&lt;/h2&gt;

&lt;p&gt;Giả sử \(f\) là hàm &lt;strong&gt;khả vi&lt;/strong&gt;. Khi đó \(f\) lồi khi và chỉ khi miền xác định \(\text{dom} f\) lồi và với mọi \(x, y \in \text{dom} f\), ta có \(f(y) \geq f(x) +\nabla f(x)^T(y-x)\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f\) lồi \(\iff \text{dom}f\) lồi, và \(f(y) \geq f(x) +\nabla f(x)^T(y-x)\) với mọi \(x,y \in \text{dom} f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hình dưới đây minh họa điều kiện bậc nhất cho một hàm lồi khả vi \(f\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/1st_order_condition.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Hàm Lồi [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Điều kiện này còn gọi là &lt;strong&gt;điều kiện tiếp tuyến&lt;/strong&gt; (hoặc siêu phẳng tiếp tuyến trong không gian nhiều chiều): xấp xỉ tuyến tính bậc nhất của \(f\) tại bất kỳ điểm \(x\) nào luôn là một chặn dưới toàn cục của \(f\). Nói cách khác, đồ thị của hàm lồi luôn nằm phía trên (hoặc trùng với) mọi tiếp tuyến của nó.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h3&gt;

&lt;p&gt;Xét hàm \(f(x) = x^2\) với đạo hàm \(f&apos;(x) = 2x\). Tại một điểm bất kỳ \(x_0\), phương trình tiếp tuyến với đồ thị \(f\) là:
\(L(x) = f(x_0) + f&apos;(x_0)(x - x_0) = x_0^2 + 2x_0(x - x_0)\)&lt;/p&gt;

&lt;p&gt;Điều kiện bậc nhất đòi hỏi với mọi \(x \in \mathbb{R}\):
\(f(x) \geq L(x) \iff x^2 \geq x_0^2 + 2x_0(x - x_0)\)&lt;/p&gt;

&lt;p&gt;Rút gọn vế phải và chuyển vế, ta được:
\(x^2 - 2x_0x + x_0^2 \geq 0 \iff (x - x_0)^2 \geq 0\)&lt;/p&gt;

&lt;p&gt;Bất đẳng thức này luôn đúng với mọi số thực \(x\) và \(x_0\), khẳng định \(f(x) = x^2\) thỏa mãn điều kiện bậc nhất và là hàm lồi.&lt;/p&gt;

&lt;h2 id=&quot;đặc-trưng-bậc-hai&quot;&gt;Đặc trưng bậc hai&lt;/h2&gt;

&lt;p&gt;Nếu \(f\) khả vi hai lần với miền xác định \(\text{dom} f\) lồi, ta có các tiêu chuẩn sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(f\) lồi khi và chỉ khi ma trận Hessian \(\nabla^2 f(x)\) nửa xác định dương với mọi \(x \in \text{dom} f\):
    &lt;blockquote&gt;
      &lt;p&gt;\(f\) lồi \(\iff \nabla^2f(x) \succeq 0\) với mọi \(x \in \text{dom} f\), \(\text{dom} f\) lồi&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Nếu \(\nabla^2 f(x)\) xác định dương với mọi \(x \in \text{dom} f\) thì \(f\) lồi chặt:
    &lt;blockquote&gt;
      &lt;p&gt;nếu \(\nabla^2f(x) \succ 0\) với mọi \(x \in \text{dom} f\), thì \(f\) lồi chặt&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nói cách khác, độ cong của hàm theo mọi phương đều không âm.&lt;/p&gt;

&lt;h2 id=&quot;bất-đẳng-thức-jensen&quot;&gt;Bất đẳng thức Jensen&lt;/h2&gt;

&lt;p&gt;Cho \(f\) là hàm lồi và \(w_1, \dots, w_n \ge 0\) là các trọng số không âm thỏa mãn \(\sum_{i=1}^{n} w_i = 1\). Khi đó, với mọi \(x_1, \dots, x_n \in \text{dom} f\):&lt;/p&gt;

\[\sum_{i=1}^{n} w_i f(x_i) \geq f \left ( \sum_{i=1}^{n} w_i x_i \right )\]

&lt;p&gt;Trong trường hợp hai điểm, bất đẳng thức này trở về dạng quen thuộc:&lt;/p&gt;
&lt;blockquote&gt;
\[f(tx_1 + (1 - t)x_2) \le tf(x_1) + (1 - t)f(x_2) \text{ với } 0 \le t \le 1\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Mở rộng xác suất:&lt;/em&gt;&lt;br /&gt;
Nếu \(X\) là biến ngẫu nhiên nhận giá trị trong \(\text{dom } f\) thì \(f(E[X]) \le E[f(X)]\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/jensen_inequality.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Bất đẳng thức Jensen [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;bất-đẳng-thức-jensen-có-trùng-với-định-nghĩa-hàm-lồi-không&quot;&gt;&lt;strong&gt;Bất đẳng thức Jensen có trùng với định nghĩa hàm lồi không?&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Không hoàn toàn — bất đẳng thức Jensen là hệ quả và là dạng tổng quát hóa của định nghĩa hàm lồi:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Định nghĩa hàm lồi chỉ xét tổ hợp lồi của hai điểm (\(n=2\)), còn bất đẳng thức Jensen mở rộng cho số điểm hữu hạn bất kỳ và sang dạng tích phân / kỳ vọng đối với độ đo xác suất.&lt;/li&gt;
  &lt;li&gt;Với \(n=2\), bất đẳng thức Jensen trùng khớp với định nghĩa hàm lồi; với \(n \ge 3\), ta suy ra nó bằng quy nạp từ trường hợp hai điểm.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;ví-dụ-minh-họa&quot;&gt;Ví dụ minh họa&lt;/h3&gt;

&lt;p&gt;Xét hàm lồi \(f(x) = x^2\) với hai điểm \(x_1 = 1\) và \(x_2 = 3\). Ta so sánh \(f\left(\frac{x_1+x_2}{2}\right)\) và \(\frac{f(x_1)+f(x_2)}{2}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Giá trị hàm tại trung bình cộng:&lt;/strong&gt;
Trung bình cộng là \(\frac{1+3}{2} = 2\), nên \(f(2) = 2^2 = 4\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Trung bình cộng của các giá trị hàm:&lt;/strong&gt;
Ta có \(f(1) = 1\) và \(f(3) = 9\), nên trung bình cộng là \(\frac{1+9}{2} = 5\).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So sánh hai giá trị cho thấy \(4 \le 5\), đúng với bất đẳng thức Jensen: \(f\left(\frac{1+3}{2}\right) \le \frac{f(1)+f(3)}{2}\).&lt;/p&gt;

&lt;h3 id=&quot;bốn-cách-kiểm-tra-hàm-lồi-trong-khoảng-3-phút&quot;&gt;Bốn cách kiểm tra hàm lồi trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/convexity-tests_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Dây cung và Jensen trên x² (ví dụ 1 và 3), tiếp tuyến nằm dưới đồ thị, đạo hàm bậc hai và Hessian, epigraph và tập mức dưới, đối chiếu với hàm hình chữ W x⁴ − 3x².&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-01-02 Ví dụ về hàm lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_01_02_examples_of_convex_function/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_01_02_examples_of_convex_function</id>
   <content type="html">&lt;p&gt;Khi xây dựng mô hình tối ưu trong thực tế — từ hồi quy bình phương tối thiểu, phạt điều chuẩn chuẩn \(\ell_1/\ell_2\), hàm mất mát logistic, đến bài toán gán nhãn bằng hàm log-sum-exp — bạn sẽ bắt gặp đi bắt gặp lại cùng một nhóm khoảng một chục “hàm lồi nguyên tử”. Thuộc lòng bảng tuần hoàn các hàm lồi nguyên tử này (cùng miền xác định của chúng!) là bí quyết để bạn nhận diện ngay một bài toán tối ưu lồi chỉ bằng mắt thường.&lt;/p&gt;

&lt;p&gt;Bài học này tổng hợp đầy đủ các ví dụ hàm lồi một biến, đa biến, chuẩn, hàm bậc hai và hàm chỉ thị của tập lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bảng-tuần-hoàn-các-hàm-lồi-nguyên-tử&quot;&gt;Kiến thức cần nhớ: Bảng tuần hoàn các hàm lồi nguyên tử&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm một biến cốt lõi:&lt;/strong&gt; \(e^{ax}\) (mọi \(a\)), \(x^p\) trên \(\mathbb{R}_{++}\) (lồi khi \(p \ge 1\) hoặc \(p \le 0\); lõm khi \(0 \le p \le 1\)), \(-\log x\) và \(x\log x\) trên \(\mathbb{R}_{++}\) (âm entropy).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm affine và hàm bậc hai:&lt;/strong&gt; Mọi hàm affine \(a^T x + b\) vừa lồi vừa lõm; hàm bậc hai \(\frac{1}{2}x^T P x + q^T x + r\) lồi khi và chỉ khi \(P \succeq 0\) (bao gồm hàm mất mát bình phương tối thiểu \(\|Ax - b\|_2^2\) vì \(A^T A \succeq 0\) luôn đúng!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mọi chuẩn và hàm log-sum-exp:&lt;/strong&gt; Bất kỳ chuẩn nào \(\|x\|\) đều lồi nhờ bất đẳng thức tam giác; hàm \(\operatorname{lse}(x) = \log(\sum e^{x_i})\) là xấp xỉ trơn, lồi của hàm \(\max_i x_i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm chỉ thị (Indicator Function \(I_C(x)\)):&lt;/strong&gt; Bằng \(0\) nếu \(x \in C\) và \(+\infty\) nếu \(x \notin C\). Hàm \(I_C\) lồi khi và chỉ khi \(C\) là tập lồi — cho phép nhúng mọi ràng buộc \(x \in C\) vào thẳng hàm mục tiêu \(\min_x f(x) + I_C(x)\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tính-lồi-và-độ-sát-của-hàm-log-sum-exp-với-max&quot;&gt;Giải thích: Kiểm chứng tính lồi và độ sát của hàm Log-Sum-Exp với \(\max\)&lt;/h3&gt;

&lt;p&gt;Xét hàm log-sum-exp 2 biến \(f(x_1, x_2) = \ln(e^{x_1} + e^{x_2})\) — nền tảng của hàm mất mát Softmax / Cross-Entropy trong học sâu:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giá trị tại hai điểm đối xứng \(x = (0, 2)\) và \(y = (2, 0)\):&lt;/strong&gt;
\(f(0, 2) = f(2, 0) = \ln(e^0 + e^2) = \ln(1 + 7.389) = \ln(8.389) \approx 2.127.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra bất đẳng thức Jensen tại trung điểm \(z = (1, 1)\):&lt;/strong&gt;
\(f(1, 1) = \ln(e^1 + e^1) = \ln(2e) = 1 + \ln 2 \approx 1.693.\)
Rõ ràng \(1.693 \le 0.5(2.127) + 0.5(2.127) = 2.127\) — bất đẳng thức lồi thỏa mãn chặt!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra kẹp chặt với hàm \(\max(x_1, x_2)\):&lt;/strong&gt;
Với mọi \(x \in \mathbb{R}^n\), luôn có \(\max_i x_i \le \ln\sum_{i=1}^n e^{x_i} \le \max_i x_i + \ln n\).
Tại \(x = (0, 2)\) (\(n = 2,\ \ln 2 \approx 0.693\)): \(\max(0, 2) = 2 \le 2.127 \le 2 + 0.693 = 2.693\) — log-sum-exp chính là phiên bản “mài tròn góc nhọn” lồi tuyệt đẹp của hàm \(\max\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này điểm qua các ví dụ điển hình về hàm lồi, gồm:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hàm mũ&lt;/li&gt;
  &lt;li&gt;Hàm lũy thừa&lt;/li&gt;
  &lt;li&gt;Hàm affine&lt;/li&gt;
  &lt;li&gt;Hàm bậc hai&lt;/li&gt;
  &lt;li&gt;Hàm mất mát bình phương tối thiểu&lt;/li&gt;
  &lt;li&gt;Chuẩn&lt;/li&gt;
  &lt;li&gt;Hàm chỉ thị&lt;/li&gt;
  &lt;li&gt;Hàm hỗ trợ&lt;/li&gt;
  &lt;li&gt;Hàm max&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;hàm-một-biến&quot;&gt;Hàm một biến&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mũ:&lt;/strong&gt; Với mọi số thực \(a\), hàm \(e^{ax}\) là hàm lồi trên \(\mathbb{R}\).
    &lt;blockquote&gt;
      &lt;p&gt;\(e^{ax}\) là hàm lồi với mọi \(a \in \mathbb{R}\)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm lũy thừa:&lt;/strong&gt; Với \(x \in \mathbb{R}_{++}\) (tức \(x &amp;gt; 0\)) và \(a \in \mathbb{R}\), tính lồi hay lõm của \(x^a\) phụ thuộc vào giá trị của số mũ \(a\):
    &lt;blockquote&gt;
      &lt;p&gt;\(x^{a}\) là hàm lồi trên \(\mathbb{R}_{++}\) với mọi \(a \geq 1\) hoặc \(a \leq 0\)
\(x^{a}\) là hàm lõm trên \(\mathbb{R}_{++}\) với mọi \(0 \leq a \leq 1\)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;hàm-affine&quot;&gt;Hàm affine&lt;/h2&gt;

&lt;p&gt;Như đã nêu trong bài &lt;a href=&quot;/contents/vi/chapter03/03_01_01_convex_functions_definition/&quot;&gt;03-01-01&lt;/a&gt;, mọi hàm affine đều vừa lồi vừa lõm.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Trên \(\mathbb{R}\) và \(\mathbb{R}^n\):
    &lt;blockquote&gt;
      &lt;p&gt;\(a^Tx + b\) vừa lồi vừa lõm&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Trên \(\mathbb{R}^{m \times n}\):
    &lt;blockquote&gt;
      &lt;p&gt;\(\text{tr}(A^TX) + b = \sum_{i=1}^m\sum_{j=1}^n A_{ij}X_{ij} + b\) vừa lồi vừa lõm&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;hàm-bậc-hai&quot;&gt;Hàm bậc hai&lt;/h2&gt;

&lt;p&gt;Xét hàm bậc hai \(f(x)=\frac{1}{2}x^TPx+q^Tx+r\), có gradient \(\nabla f(x)= Px+q\) và ma trận Hessian \(\nabla^2f(x) = P\). Nếu \(P\) là ma trận nửa xác định dương (\(P \succeq 0\)) thì \(f(x)\) là hàm lồi:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x)=\frac{1}{2}x^TPx+q^Tx+r\) là hàm lồi với \(P \in \mathbb{S}^n_+\), \(q \in \mathbb{R}^n\), \(r \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Hỏi: Tại sao \(f(x)\) lồi khi \(P\) là ma trận nửa xác định dương?&lt;/strong&gt;
&lt;strong&gt;Đáp:&lt;/strong&gt; Đối với hàm bậc hai, ma trận Hessian \(\nabla^2 f(x) = P\) phản ánh độ cong của hàm theo mọi phương. Khi \(P \succeq 0\), độ cong theo mọi hướng đều không âm (đồ thị luôn hướng bề lõm lên trên), nên hàm là hàm lồi.&lt;/p&gt;

&lt;h2 id=&quot;hàm-mất-mát-bình-phương-tối-thiểu&quot;&gt;Hàm mất mát bình phương tối thiểu&lt;/h2&gt;

&lt;p&gt;Với mọi ma trận \(A\), ma trận \(A^TA\) luôn nửa xác định dương, do đó hàm \(\left \| Ax - b \right \|_{2}^{2}\) luôn là hàm lồi:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f(x) = \| Ax - b \|_{2}^{2}\) là hàm lồi với mọi \(A\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;chuẩn&quot;&gt;Chuẩn&lt;/h2&gt;

&lt;p&gt;Mọi chuẩn trên \(\mathbb{R}^n\) đều là hàm lồi. Nếu \(f:\mathbb{R}^n \mapsto \mathbb{R}\) là một chuẩn thì theo bất đẳng thức tam giác và tính thuần nhất bậc một, ta có:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{aligned}
f(\theta x+(1-\theta)y) \le \theta f(x)+(1-\theta)f(y), \text{ với } 0 \le \theta \le 1, \text{ cho mọi } x,y \in \text{dom} f,
\end{aligned}\)
\(\begin{aligned}
\|x\|_{p} = \left(\sum_{i=1}^{n} |x_i|^p\right)^{1/p} \text{ với } p \geq 1, \quad \|x\|_\infty = \max_{i=1,.., n} |x_i|\\
\end{aligned}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;hàm-chỉ-thị&quot;&gt;Hàm chỉ thị&lt;/h2&gt;

&lt;p&gt;Với một &lt;strong&gt;tập lồi&lt;/strong&gt; \(C\) cho trước, hàm chỉ thị \(I_C\) nhận giá trị \(0\) với các điểm thuộc \(C\) và \(+\infty\) với các điểm ngoài \(C\) là một hàm lồi:&lt;/p&gt;

&lt;blockquote&gt;
\[I_{C} (x) =
\begin{cases}
0, &amp;amp; x \in C\\
\infty, &amp;amp; x \notin C\\
\end{cases}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;hàm-hỗ-trợ&quot;&gt;Hàm hỗ trợ&lt;/h2&gt;

&lt;p&gt;Xét một tập \(C\) bất kỳ. Dù \(C\) có lồi hay không, hàm hỗ trợ của \(C\) luôn là hàm lồi:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(I_{C}^{*} (x) = \sup_{y\in C} x^Ty\) là hàm lồi&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Xem thêm &lt;a href=&quot;https://en.wikipedia.org/wiki/Support_function&quot;&gt;định nghĩa hàm hỗ trợ trên Wikipedia&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;hàm-max&quot;&gt;Hàm max&lt;/h2&gt;

&lt;p&gt;Giá trị lớn nhất theo từng điểm của một họ hữu hạn các hàm lồi là một hàm lồi; về mặt hình học, bao trên của các đồ thị hàm lồi vẫn là một hàm lồi. Đặc biệt:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x) = \max \{x_1,..., x_n\}\) là hàm lồi&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>03-01-01 Định nghĩa</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_01_01_convex_functions_definition/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_01_01_convex_functions_definition</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Không phải mọi hàm lồi đều “đẹp” như nhau dưới góc độ thuật toán. Hàm giá trị tuyệt đối $$&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(lồi nhưng có đáy nhọn và có thể tạo ra cả một đoạn nghiệm tối ưu không duy nhất; hàm mũ\)e^x\(lồi chặt nhưng càng đi về\)-\infty$$ càng dẹt phẳng dần khiến Gradient Descent bò chậm; chỉ đến &lt;strong&gt;hàm lồi mạnh&lt;/strong&gt; (strongly convex) ta mới có bảo đảm đáy cong chặt toàn cục, nghiệm duy nhất và tốc độ hội tụ tuyến tính thần tốc!&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Bài học này phân biệt rạch ròi chuỗi bao hàm quan trọng bậc nhất của tối ưu hóa: &lt;strong&gt;lồi mạnh \(\implies\) lồi chặt \(\implies\) lồi&lt;/strong&gt;, cùng khái niệm hàm lõm đối xứng.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-cấp-độ-của-độ-cong-lồi&quot;&gt;Kiến thức cần nhớ: Bốn cấp độ của độ cong lồi&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/chapter03/convex_function01.png&quot; alt=&quot;Định nghĩa hình học hàm lồi qua dây cung&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm lồi (Convex):&lt;/strong&gt; Miền xác định \(\operatorname{dom} f\) lồi và \(f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y)\). Bảo đảm cực tiểu địa phương = cực tiểu toàn cục, nhưng cực tiểu có thể không duy nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm lồi chặt (Strictly Convex):&lt;/strong&gt; Bất đẳng thức chặt \(&amp;lt;\) với mọi \(x \ne y,\ \theta \in (0, 1)\). Bảo đảm nếu cực tiểu tồn tại thì nó là &lt;strong&gt;duy nhất&lt;/strong&gt;, nhưng độ cong vẫn có thể tiến về \(0\) ở vô cực.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm \(m\)-lồi mạnh (\(m\)-Strongly Convex):&lt;/strong&gt; \(f(x) - \frac{m}{2}\|x\|_2^2\) vẫn còn lồi (với \(m &amp;gt; 0\)), tương đương \(\nabla^2 f(x) \succeq m I\). Đồ thị bị chặn dưới toàn cục bởi một chiếc bát parabol có độ cong tối thiểu \(m\), bảo đảm tốc độ hội tụ hình học (tuyến tính) cho Gradient Descent!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm lõm (Concave):&lt;/strong&gt; \(-f\) là hàm lồi; cực đại hóa hàm lõm tương đương cực tiểu hóa hàm lồi \(-f\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-3-hàm-đại-diện-cho-3-nấc-lồi-trên-mathbbr&quot;&gt;Giải thích: So sánh 3 hàm đại diện cho 3 nấc lồi trên \(\mathbb{R}\)&lt;/h3&gt;

&lt;p&gt;Hãy kiểm tra trực tiếp từng nấc trên ba hàm cụ thể:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lồi nhưng KHÔNG lồi chặt — \(f_1(x) = |x|\):&lt;/strong&gt;
Chọn \(x = 1,\ y = 3,\ \theta = 0.5\) (trung điểm \(2\)):
\(f_1(2) = 2 = 0.5\cdot f_1(1) + 0.5\cdot f_1(3) = 0.5(1) + 0.5(3) = 2.\)
Dấu bằng xảy ra dù \(x \ne y\), nên \(|x|\) không lồi chặt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lồi chặt nhưng KHÔNG lồi mạnh — \(f_2(x) = e^x\) trên \(\mathbb{R}\):&lt;/strong&gt;
Đạo hàm bậc hai \(f_2&apos;&apos;(x) = e^x &amp;gt; 0\ \forall x \in \mathbb{R} \implies\) &lt;strong&gt;lồi chặt&lt;/strong&gt;.
Tuy nhiên, với mọi hằng số \(m &amp;gt; 0\) bất kỳ, khi chọn \(x &amp;lt; \ln m\) ta có \(f_2&apos;&apos;(x) = e^x &amp;lt; m\), nên không tồn tại \(m &amp;gt; 0\) chặn dưới \(e^x\) trên toàn \(\mathbb{R}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lồi mạnh — \(f_3(x) = x^2 + e^x\) trên \(\mathbb{R}\):&lt;/strong&gt;
Đạo hàm bậc hai \(f_3&apos;&apos;(x) = 2 + e^x &amp;gt; 2\ \forall x \in \mathbb{R}\). Do đó \(f_3(x) - \frac{2}{2}x^2 = e^x\) vẫn lồi, chứng tỏ \(f_3\) là &lt;strong&gt;2-lồi mạnh&lt;/strong&gt; trên toàn \(\mathbb{R}\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;hàm-lồi&quot;&gt;Hàm lồi&lt;/h2&gt;

&lt;p&gt;Một hàm \(f:\mathbb{R}^n \rightarrow \mathbb{R}\) được gọi là &lt;strong&gt;hàm lồi&lt;/strong&gt; nếu miền xác định \(\text{dom}f\) của nó là một tập lồi và với mọi \(x, y \in \text{dom}f\) cùng mọi \(0 \le \theta \le 1\), ta có:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f(\theta x+(1-\theta)y) \le \theta f(x)+(1-\theta)f(y)\),&lt;/p&gt;

  &lt;p&gt;với \(0 \le \theta \le 1\), cho mọi \(x,y \in \text{dom} f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, giá trị của \(f\) tại tổ hợp lồi của hai điểm \(x, y\) luôn nhỏ hơn hoặc bằng tổ hợp lồi tương ứng của \(f(x)\) và \(f(y)\). Về mặt hình học, đoạn thẳng nối hai điểm \((x, f(x))\) và \((y, f(y))\) trên đồ thị của \(f\) luôn nằm phía trên (hoặc trùng với) đồ thị của hàm.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/convex_function2.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Hàm Lồi [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;hàm-lồi-chặt&quot;&gt;Hàm lồi chặt&lt;/h2&gt;

&lt;p&gt;Một hàm \(f:\mathbb{R}^n \rightarrow \mathbb{R}\) được gọi là &lt;strong&gt;lồi chặt&lt;/strong&gt; nếu miền xác định \(\text{dom}f\) lồi và bất đẳng thức nghiêm ngặt sau đúng với mọi hai điểm phân biệt \(x, y \in \text{dom}f\) và \(0 &amp;lt; \theta &amp;lt; 1\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f(\theta x+(1-\theta)y)&amp;lt;\theta f(x)+(1-\theta)f(y)\),&lt;/p&gt;

  &lt;p&gt;với \(0&amp;lt;\theta&amp;lt;1\), \(x \neq y\), cho mọi \(x, y \in \text{dom}f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;hàm-lồi-mạnh&quot;&gt;Hàm lồi mạnh&lt;/h2&gt;

&lt;p&gt;Một hàm \(f\) được gọi là &lt;strong&gt;lồi mạnh&lt;/strong&gt; với tham số \(m &amp;gt; 0\) nếu hàm \(f(x) - \frac{m}{2}\| x \|_{2}^{2}\) là hàm lồi.&lt;/p&gt;

&lt;h3 id=&quot;lưu-ý-lồi-mạnh--lồi-chặt--lồi&quot;&gt;[Lưu ý] lồi mạnh ⇒ lồi chặt ⇒ lồi&lt;/h3&gt;

&lt;h2 id=&quot;hàm-lõm&quot;&gt;Hàm lõm&lt;/h2&gt;

&lt;p&gt;Một hàm \(f\) được gọi là &lt;strong&gt;hàm lõm&lt;/strong&gt; nếu \(-f\) là hàm lồi.&lt;/p&gt;

&lt;p&gt;Mọi hàm affine \(f(x) = a^T x+b\) đều thỏa mãn đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{aligned}
f(\theta x+(1-\theta)y) &amp;amp;= a^T (\theta x+(1-\theta)y) +b \\
&amp;amp;= \theta a^T x + (1-\theta) a^T y + \theta b + (1-\theta) b \\
&amp;amp;= \theta f(x)+(1-\theta)f(y) \\
\end{aligned}\)
\(\text{với mọi } x,y \in \text{dom} f, \text{ và } 0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Do đó, mọi hàm affine đều vừa lồi vừa lõm.&lt;/p&gt;

&lt;h3 id=&quot;bốn-cách-kiểm-tra-hàm-lồi-trong-khoảng-3-phút&quot;&gt;Bốn cách kiểm tra hàm lồi trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/convexity-tests_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Dây cung và Jensen trên x² (ví dụ 1 và 3), tiếp tuyến nằm dưới đồ thị, đạo hàm bậc hai và Hessian, epigraph và tập mức dưới, đối chiếu với hàm hình chữ W x⁴ − 3x².&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-01 Tính chất cơ bản và ví dụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_01_00_Basic_properties_and_examples/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_01_00_Basic_properties_and_examples</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Khi cầm một hàm mục tiêu nhiều biến trên tay — ví dụ hàm mất mát của hồi quy ridge, chuẩn vector hay hàm entropy — câu hỏi đầu tiên của nhà tối ưu là: &lt;em&gt;đây có phải hàm lồi không, và cách chứng minh nhanh nhất là gì?&lt;/em&gt; Không có một công thức duy nhất cho mọi hàm: có hàm kiểm tra bằng Hessian mất 10 giây, có hàm không khả vi (như $$&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;$$) phải dùng định nghĩa hoặc epigraph, lại có hàm chỉ cần nhìn thấy cấu trúc tổng bình phương là kết luận được ngay.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Phần 03-01 trang bị trọn bộ định nghĩa cơ bản, danh mục ví dụ mẫu mực và các đặc trưng bậc nhất – bậc hai cho hàm lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-bộ-công-cụ-nhận-diện-hàm-lồi&quot;&gt;Kiến thức cần nhớ: Ba bộ công cụ nhận diện hàm lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Công cụ hình học (Định nghĩa Jensen &amp;amp; Epigraph):&lt;/strong&gt; Dùng được cho mọi hàm (kể cả hàm không trơn như chuẩn \(\ell_1\), hàm chỉ thị \(I_C\)); nối trực tiếp với tính lồi của tập \(\operatorname{epi} f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Công cụ giải tích (Đặc trưng bậc 1 &amp;amp; bậc 2):&lt;/strong&gt; Với hàm khả vi, kiểm tra chặn dưới tiếp tuyến hoặc Hessian \(\nabla^2 f(x) \succeq 0\) trên miền lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Công cụ cắt lát 1D (Restriction to a line):&lt;/strong&gt; Một hàm \(n\) biến \(f(x)\) là lồi khi và chỉ khi mọi lát cắt một biến \(g(t) = f(x_0 + t v)\) đều lồi theo \(t \in \mathbb{R}\) — cực kỳ lợi hại để chứng minh tính lồi của hàm trên ma trận như \(-\log\det(X)\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chứng-minh-fx_1-x_2--x_12--x_1-x_2--x_22-lồi-theo-3-cách-khác-nhau&quot;&gt;Giải thích: Chứng minh \(f(x_1, x_2) = x_1^2 + x_1 x_2 + x_2^2\) lồi theo 3 cách khác nhau&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai hai biến \(f(x_1, x_2) = x_1^2 + x_1 x_2 + x_2^2\) trên \(\mathbb{R}^2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cách 1 — Kiểm tra nhanh bất đẳng thức Jensen trên một cặp điểm:&lt;/strong&gt; Chọn \(x = (2, 0),\ y = (0, 2)\) (đều có \(f = 4\)) và trung điểm \(z = (1, 1)\):
\(f(1, 1) = 1 + 1 + 1 = 3 \le \frac{f(2, 0) + f(0, 2)}{2} = \frac{4 + 4}{2} = 4.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách 2 — Chứng minh chặt bằng ma trận Hessian:&lt;/strong&gt;
\(\nabla^2 f(x) = \begin{pmatrix}2 &amp;amp; 1\\ 1 &amp;amp; 2\end{pmatrix}.\)
Vết bằng \(4\), định thức bằng \(4 - 1 = 3 &amp;gt; 0 \implies\) giá trị riêng \(\lambda_1 = 3 &amp;gt; 0,\ \lambda_2 = 1 &amp;gt; 0\). Do \(\nabla^2 f \succ 0\) mọi nơi, \(f\) không chỉ lồi mà còn &lt;strong&gt;1-lồi mạnh&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách 3 — Phân tích thành tổng các hàm lồi sơ cấp:&lt;/strong&gt;
\(f(x_1, x_2) = \frac{1}{2}x_1^2 + \frac{1}{2}x_2^2 + \frac{1}{2}(x_1 + x_2)^2.\)
Mỗi số hạng đều có dạng bình phương hàm tuyến tính (lồi), nên tổng của chúng chắc chắn lồi mà không cần tính định thức!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này trình bày định nghĩa hàm lồi, các họ hàm lồi thường gặp và những tính chất đặc trưng cơ bản của chúng.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03 Hàm lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_00_Convex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter03/03_00_Convex_functions</id>
   <content type="html">&lt;p&gt;Nếu Chương 02 vẽ nên “sân chơi” nơi thuật toán được phép di chuyển (tập lồi), thì Chương 03 xây dựng “địa hình” độ cao trên sân chơi đó: &lt;strong&gt;hàm lồi&lt;/strong&gt;. Vẻ đẹp của một hàm lồi nằm ở hai phép màu hình học: mọi dây cung nối hai điểm trên đồ thị luôn nằm phía trên đường cong, và mọi mặt phẳng tiếp tuyến tại bất kỳ điểm nào cũng nằm hoàn toàn bên dưới đồ thị — trở thành một “chặn dưới toàn cục” giúp ta biết chắc mình còn cách đáy tối đa bao xa.&lt;/p&gt;

&lt;p&gt;Chương 03 sẽ dẫn bạn qua định nghĩa hàm lồi, kho ví dụ kinh điển, các phép toán bảo toàn tính lồi, hàm liên hợp Fenchel, hàm giả lồi, hàm log-lõm và tính lồi theo bất đẳng thức tổng quát.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-trụ-cột-của-chương-03&quot;&gt;Kiến thức cần nhớ: Bốn nhánh trụ cột của Chương 03&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa và ba đặc trưng (Bậc 0, Bậc 1, Bậc 2):&lt;/strong&gt; Bất đẳng thức Jensen (không cần khả vi), chặn dưới tiếp tuyến \(f(y) \ge f(x) + \nabla f(x)^T(y-x)\) (khả vi cấp 1) và Hessian bán xác định dương \(\nabla^2 f(x) \succeq 0\) (khả vi cấp 2).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc lắp ghép bảo toàn tính lồi (Disciplined Convex Programming):&lt;/strong&gt; Tổng trọng số dương, cực đại từng điểm (pointwise max), hợp thành affine, hàm phối cảnh và cực tiểu hóa từng phần — công cụ nhận diện hàm lồi không cần tính Hessian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm liên hợp Fenchel (\(f^*\)):&lt;/strong&gt; Phép biến đổi sang không gian độ dốc \(y\), tạo ra cặp bất đẳng thức Fenchel–Young và là viên gạch cốt lõi xây dựng bài toán đối ngẫu ở Chương 05.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mở rộng tính lồi (Giả lồi, Log-lõm và Lồi theo nón \(K\)):&lt;/strong&gt; Bao phủ những hàm cực kỳ quan trọng trong xác suất và kinh tế học (như mật độ chuẩn Gauss hay hàm phân thức tuyến tính) vốn không lồi theo nghĩa cổ điển nhưng vẫn giải tối ưu hiệu quả.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chặn-dưới-tiếp-tuyến-toàn-cục-của-hàm-lồi-x2-so-với-hàm-không-lồi-x3&quot;&gt;Giải thích: Chặn dưới tiếp tuyến toàn cục của hàm lồi \(x^2\) so với hàm không lồi \(x^3\)&lt;/h3&gt;

&lt;p&gt;Đặc trưng bậc nhất phát biểu: hàm khả vi \(f\) lồi khi và chỉ khi tiếp tuyến tại &lt;em&gt;mọi&lt;/em&gt; điểm \(x\) luôn nằm dưới đồ thị: \(f(y) \ge f(x) + f&apos;(x)(y - x)\ \forall y\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thử với hàm lồi \(f(x) = x^2\) tại \(x = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tiếp tuyến: \(T(y) = f(1) + f&apos;(1)(y - 1) = 1 + 2(y - 1) = 2y - 1\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra tại \(y = 3\): \(f(3) = 9 \ge T(3) = 2(3) - 1 = 5\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra tổng quát: \(f(y) - T(y) = y^2 - (2y - 1) = (y - 1)^2 \ge 0\) với mọi \(y \in \mathbb{R}\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử với hàm không lồi \(g(x) = x^3\) tại \(x = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tiếp tuyến: \(T_g(y) = 1 + 3(y - 1) = 3y - 2\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra tại \(y = -3\): \(g(-3) = -27\), trong khi tiếp tuyến cho \(T_g(-3) = 3(-3) - 2 = -11\)!
Vì \(-27 &amp;lt; -11\), đồ thị đã “đâm xuyên” xuống dưới tiếp tuyến — xác nhận ngay \(x^3\) &lt;strong&gt;không lồi&lt;/strong&gt; trên \(\mathbb{R}\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Chương này trình bày định nghĩa, các ví dụ tiêu biểu, các tính chất cơ bản của hàm lồi và những phép toán bảo toàn tính lồi.&lt;/p&gt;

&lt;p&gt;Xem thêm bài tùy chọn &lt;a href=&quot;/contents/vi/chapter03/03_08_Applications_Recent/&quot;&gt;03-08 Ứng dụng và phát triển gần đây&lt;/a&gt; về vai trò của hàm log-sum-exp trong hiệu chỉnh xác suất, hiện tượng neural collapse và hàm mất mát đối sánh.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-10 Practical Exercises - Convex Functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_10_Practical_Exercises_Convex_Functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_10_Practical_Exercises_Convex_Functions</id>
   <content type="html">&lt;p&gt;Real fluency with convex functions happens when you move seamlessly between symbolic proofs (verifying Hessians, deriving Fenchel conjugates, computing subdifferentials) and numerical verification. These practical exercises bring all of Chapter 03 together—from verifying convexity and preservation rules to solving nonsmooth optimality conditions, quasiconvex ratio problems, and log-concave estimation tasks.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-problem-solving-toolkit-for-these-exercises&quot;&gt;Key ideas: Problem-Solving Toolkit for These Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Multi-Method Convexity Proofs:&lt;/strong&gt; Choosing the fastest proof per problem—Hessian test for smooth low-dimensional functions, composition/perspective rules for structured functions, and definition/epigraph for nonsmooth functions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conjugate Derivation Recipe:&lt;/strong&gt; Set \(\nabla_x(y^T x - f(x)) = 0\) when smooth, check boundary/infinity cases carefully to find \(\text{dom}\,f^*\), and verify with Fenchel’s inequality.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Subdifferentials &amp;amp; Nonsmooth Optimality:&lt;/strong&gt; At a kink (like $$&lt;/td&gt;
          &lt;td&gt;x - c&lt;/td&gt;
          &lt;td&gt;\(), replace\)\nabla f(x^&lt;em&gt;) = 0\(with\)0 \in \partial f(x^&lt;/em&gt;)$$—the exact foundation of Lasso soft-thresholding.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quasiconvex &amp;amp; Log-Concave Checks:&lt;/strong&gt; Clear positive denominators to expose convex sublevel sets, and take logarithms before differentiating to test log-concavity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-a-nonsmooth-convex-problem-via-subdifferentials&quot;&gt;Worked example: Solving a Nonsmooth Convex Problem via Subdifferentials&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 1&lt;/td&gt;
      &lt;td&gt;+ \frac{1}{2}(x - 4)^2\(over\)x \in \mathbb{R}$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the subdifferential \(\partial f(x)\) in three regions:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(x &amp;gt; 1\): \(f&apos;(x) = +1 + (x - 4) = x - 3\).&lt;/li&gt;
      &lt;li&gt;For \(x &amp;lt; 1\): \(f&apos;(x) = -1 + (x - 4) = x - 5\).&lt;/li&gt;
      &lt;li&gt;At the kink \(x = 1\): \(\partial f(1) = [-1, 1] + (1 - 4) = [-4, -2]\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the optimality condition \(0 \in \partial f(x^*)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;At \(x = 1\): \(0 \notin [-4, -2]\), so the kink is not optimal.&lt;/li&gt;
      &lt;li&gt;For \(x &amp;lt; 1\): \(x - 5 = 0 \implies x = 5 \not&amp;lt; 1\) (invalid).&lt;/li&gt;
      &lt;li&gt;For \(x &amp;gt; 1\): \(x - 3 = 0 \implies x^* = 3 &amp;gt; 1\) (valid!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Verify strictly lower cost:&lt;/strong&gt; $$f(3) =&lt;/td&gt;
          &lt;td&gt;3 - 1&lt;/td&gt;
          &lt;td&gt;+ \frac{1}{2}(3 - 4)^2 = 2 + 0.5 = 2.5\(, compared to\)f(1) = 0 + 4.5 = 4.5\(and\)f(4) = 3 + 0 = 3.0\(. Notice how the\)\ell_1\(term pulls the unconstrained quadratic minimum from\)4\(toward\)1\(by exactly\)1$$ unit (soft-thresholding!).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---convex-functions&quot;&gt;Practical Exercises - Convex Functions&lt;/h1&gt;

&lt;h2 id=&quot;-exercise-1-verifying-convex-functions&quot;&gt;📝 &lt;strong&gt;Exercise 1: Verifying convex functions&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 3.1 from Boyd &amp;amp; Vandenberghe)
Determine whether the following functions are convex on their domains:&lt;/p&gt;

&lt;p&gt;a) \(f(x) = x^2\) on \(\mathbb{R}\)&lt;/p&gt;

&lt;p&gt;b) \(f(x) = e^{ax}\) on \(\mathbb{R}\)&lt;/p&gt;

&lt;p&gt;c) \(f(x) = x \log x\) on \(\mathbb{R}_{++}\)&lt;/p&gt;

&lt;p&gt;d) \(f(x) = -\log x\) on \(\mathbb{R}_{++}\)&lt;/p&gt;

&lt;p&gt;e) \(f(x) = x^p\) with \(p \geq 1\) on \(\mathbb{R}_+\)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;f) $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;^p\(with\)p \geq 1\(on\)\mathbb{R}$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Verify using the definition of convexity&lt;/li&gt;
  &lt;li&gt;Use second-order conditions where applicable&lt;/li&gt;
  &lt;li&gt;Analyze domain restrictions&lt;/li&gt;
  &lt;li&gt;Visualize the functions and their convexity&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: $$f(x) = x^2$$**

**Second-order condition:** $$f&apos;&apos;(x) = 2 &amp;gt; 0$$ $$\forall x \in \mathbb{R}$$

$$\Rightarrow$$ Strictly convex on $$\mathbb{R}$$

**Verification from the definition:**
$$f(\theta x + (1-\theta) y) = (\theta x + (1-\theta) y)^2 = \theta^2 x^2 + 2\theta(1-\theta)xy + (1-\theta)^2 y^2$$

$$\theta f(x) + (1-\theta) f(y) = \theta x^2 + (1-\theta) y^2$$

$$f(\theta x + (1-\theta) y) - [\theta f(x) + (1-\theta) f(y)] = -\theta(1-\theta)(x-y)^2 \leq 0$$

**Step 2: $$f(x) = e^{ax}$$**

**Second-order condition:** $$f&apos;&apos;(x) = a^2 e^{ax} \geq 0$$ $$\forall x$$

$$\Rightarrow$$ Convex on $$\mathbb{R}$$ (strictly convex if $$a \neq 0$$)

**Step 3: $$f(x) = x \log x$$**

**Domain:** $$\mathbb{R}_{++}$$ ($$x &amp;gt; 0$$)

**First derivative:** $$f&apos;(x) = \log x + 1$$

**Second derivative:** $$f&apos;&apos;(x) = \frac{1}{x} &amp;gt; 0$$ for $$x &amp;gt; 0$$

$$\Rightarrow$$ Strictly convex on $$\mathbb{R}_{++}$$

**Step 4: $$f(x) = -\log x$$**

**Second derivative:** $$f&apos;&apos;(x) = \frac{1}{x^2} &amp;gt; 0$$ for $$x &amp;gt; 0$$

$$\Rightarrow$$ Strictly convex on $$\mathbb{R}_{++}$$

**Step 5: $$f(x) = x^p$$ with $$p \geq 1$$**

**Case $$p = 1$$:** $$f(x) = x$$ is linear $$\Rightarrow$$ convex

**Case $$p &amp;gt; 1$$:** $$f&apos;&apos;(x) = p(p-1)x^{p-2} \geq 0$$ for $$x \geq 0$$

$$\Rightarrow$$ Convex on $$\mathbb{R}_+$$

**Step 6: $$f(x) = |x|^p$$ with $$p \geq 1$$**

**Symmetry:** $$f(-x) = f(x)$$, so it suffices to look at $$x \geq 0$$

**For $$x \geq 0$$:** $$f(x) = x^p$$ is convex (from step 5)

**Note:** being convex on each half-line is not enough to conclude convexity on $$\mathbb{R}$$. The correct argument: $$f(x) = g(|x|)$$ where $$g(t) = t^p$$ is convex and **non-decreasing** on $$\mathbb{R}_+$$, and $$|x|$$ is convex.

**Composition rule:** a non-decreasing convex function of a convex function is convex, so $$|x|^p$$ is convex.

$$\Rightarrow$$ Convex on $$\mathbb{R}$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-operations-preserving-convexity&quot;&gt;📝 &lt;strong&gt;Exercise 2: Operations preserving convexity&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 3.2 from Boyd &amp;amp; Vandenberghe)
Let \(f, g: \mathbb{R}^n \to \mathbb{R}\) be convex. Determine whether the following are convex:&lt;/p&gt;

&lt;p&gt;a) \(h(x) = \alpha f(x) + \beta g(x)\) with \(\alpha, \beta \geq 0\)&lt;/p&gt;

&lt;p&gt;b) \(h(x) = \max\{f(x), g(x)\}\)&lt;/p&gt;

&lt;p&gt;c) \(h(x) = f(Ax + b)\) with \(A \in \mathbb{R}^{n \times m}\), \(b \in \mathbb{R}^n\)&lt;/p&gt;

&lt;p&gt;d) \(h(x) = \inf_{y \in C} f(x, y)\) with \(C\) convex&lt;/p&gt;

&lt;p&gt;e) \(h(x) = \int_0^\infty f(x, t) dt\) (if the integral exists)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Prove convexity for the operations&lt;/li&gt;
  &lt;li&gt;Give counterexamples when not convex&lt;/li&gt;
  &lt;li&gt;Provide concrete examples&lt;/li&gt;
  &lt;li&gt;Discuss conditions for strict convexity&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Non-negative weighted sum - CONVEX**

**Theorem:** If $$f, g$$ are convex and $$\alpha, \beta \geq 0$$, then $$h(x) = \alpha f(x) + \beta g(x)$$ is convex.

**Proof:**
$$h(\theta x + (1-\theta) y) = \alpha f(\theta x + (1-\theta) y) + \beta g(\theta x + (1-\theta) y)$$
$$\leq \alpha[\theta f(x) + (1-\theta) f(y)] + \beta[\theta g(x) + (1-\theta) g(y)]$$
$$= \theta[\alpha f(x) + \beta g(x)] + (1-\theta)[\alpha f(y) + \beta g(y)]$$
$$= \theta h(x) + (1-\theta) h(y)$$

**Step 2: Pointwise maximum - CONVEX**

**Theorem:** $$h(x) = \max\{f(x), g(x)\}$$ is convex if $$f, g$$ are convex.

**Proof:**
$$h(\theta x + (1-\theta) y) = \max\{f(\theta x + (1-\theta) y), g(\theta x + (1-\theta) y)\}$$
$$\leq \max\{\theta f(x) + (1-\theta) f(y), \theta g(x) + (1-\theta) g(y)\}$$
$$\leq \theta \max\{f(x), g(x)\} + (1-\theta) \max\{f(y), g(y)\}$$
$$= \theta h(x) + (1-\theta) h(y)$$

**Generalization:** $$\sup_{t \in T} f_t(x)$$ is convex if every $$f_t$$ is convex.

**Step 3: Affine composition - CONVEX**

**Theorem:** $$h(x) = f(Ax + b)$$ is convex if $$f$$ is convex.

**Proof:**
$$h(\theta x + (1-\theta) y) = f(A(\theta x + (1-\theta) y) + b)$$
$$= f(\theta(Ax + b) + (1-\theta)(Ay + b))$$
$$\leq \theta f(Ax + b) + (1-\theta) f(Ay + b)$$
$$= \theta h(x) + (1-\theta) h(y)$$

**Step 4: Partial minimization - CONVEX**

**Theorem:** $$h(x) = \inf_{y \in C} f(x, y)$$ is convex in $$x$$ if $$f(x, y)$$ is jointly convex in $$(x, y)$$ and $$C$$ is convex.

**Proof:** Given $$\epsilon &amp;gt; 0$$, choose $$y_1, y_2 \in C$$ with $$f(x_k, y_k) \leq h(x_k) + \epsilon$$ ($$k = 1, 2$$). Since $$C$$ is convex, $$\bar{y} = \theta y_1 + (1-\theta) y_2 \in C$$, so:
$$h(\theta x_1 + (1-\theta) x_2) \leq f(\theta x_1 + (1-\theta) x_2, \bar{y})$$
$$\leq \theta f(x_1, y_1) + (1-\theta) f(x_2, y_2) \leq \theta h(x_1) + (1-\theta) h(x_2) + \epsilon$$
Letting $$\epsilon \to 0$$:
$$h(\theta x_1 + (1-\theta) x_2) \leq \theta h(x_1) + (1-\theta) h(x_2)$$
(Note: one must use two different points $$y_1, y_2$$ and **joint** convexity in $$(x, y)$$; using the same $$y$$ for both does not prove it.)

**Step 5: Integration - CONVEX**

**Theorem:** $$h(x) = \int_0^\infty f(x, t) dt$$ is convex if $$f(x, t)$$ is convex in $$x$$ for each $$t$$.

**Proof:** For each $$t$$: $$f(\theta x + (1-\theta) y, t) \leq \theta f(x, t) + (1-\theta) f(y, t)$$. Integrating both sides in $$t$$ (integration preserves inequalities and is linear) gives $$h(\theta x + (1-\theta) y) \leq \theta h(x) + (1-\theta) h(y)$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-conjugate-functions&quot;&gt;📝 &lt;strong&gt;Exercise 3: Conjugate functions&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 3.3 from Boyd &amp;amp; Vandenberghe)
Compute the conjugate function \(f^*(y) = \sup_x (y^T x - f(x))\) for:&lt;/p&gt;

&lt;p&gt;a) \(f(x) = \frac{1}{2}x^T Q x\) with \(Q \succ 0\)&lt;/p&gt;

&lt;p&gt;b) \(f(x) = \lVert x \rVert_2\)&lt;/p&gt;

&lt;p&gt;c) \(f(x) = \lVert x \rVert_1\)&lt;/p&gt;

&lt;p&gt;d) \(f(x) = \log \sum_{i=1}^n e^{x_i}\) (log-sum-exp)&lt;/p&gt;

&lt;p&gt;e) \(f(x) = \max_{i=1,\ldots,n} x_i\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Derive conjugates using optimization&lt;/li&gt;
  &lt;li&gt;Verify conjugacy relationships&lt;/li&gt;
  &lt;li&gt;Analyze the domains of the conjugates&lt;/li&gt;
  &lt;li&gt;Geometric interpretation&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Quadratic function**
$$f(x) = \frac{1}{2}x^T Q x$$ with $$Q \succ 0$$

**Optimization:** $$\max_x (y^T x - \frac{1}{2}x^T Q x)$$

**First-order condition:** $$y - Qx = 0 \Rightarrow x^* = Q^{-1} y$$

**Conjugate:**
$$f^*(y) = y^T Q^{-1} y - \frac{1}{2}y^T Q^{-1} Q Q^{-1} y = \frac{1}{2}y^T Q^{-1} y$$

**Domain:** $$\mathbb{R}^n$$ (since $$Q \succ 0$$)

**Step 2: Euclidean norm**
$$f(x) = \lVert x \rVert_2$$

**Optimization:** $$\max_x (y^T x - \lVert x \rVert_2)$$

**Case analysis:**
- If $$\lVert y \rVert_2 \leq 1$$: by Cauchy-Schwarz, $$y^T x - \lVert x \rVert_2 \leq (\lVert y \rVert_2 - 1)\lVert x \rVert_2 \leq 0$$, so the supremum is $$0$$, attained at $$x = 0$$
- If $$\lVert y \rVert_2 &amp;gt; 1$$: the supremum is $$+\infty$$

**Conjugate:**
$$f^*(y) = \begin{cases} 0 &amp;amp; \text{if } \lVert y \rVert_2 \leq 1 \\ +\infty &amp;amp; \text{if } \lVert y \rVert_2 &amp;gt; 1 \end{cases}$$

**Domain:** Unit ball $$\{y : \lVert y \rVert_2 \leq 1\}$$

**Step 3: $$\ell_1$$ norm**
$$f(x) = \lVert x \rVert_1 = \sum_{i=1}^n |x_i|$$

**Separable optimization:** $$\max_{x_i} (y_i x_i - |x_i|)$$ for each $$i$$

**Component analysis:**
- If $$|y_i| \leq 1$$: the maximum is 0, at $$x_i = 0$$
- If $$|y_i| &amp;gt; 1$$: the maximum is $$+\infty$$

**Conjugate:**
$$f^*(y) = \begin{cases} 0 &amp;amp; \text{if } \lVert y \rVert_\infty \leq 1 \\ +\infty &amp;amp; \text{if } \lVert y \rVert_\infty &amp;gt; 1 \end{cases}$$

**Step 4: Log-sum-exp**
$$f(x) = \log \sum_{i=1}^n e^{x_i}$$

**Optimization:** $$\max_x \left(\sum_{i=1}^n y_i x_i - \log \sum_{i=1}^n e^{x_i}\right)$$

**First-order condition:** $$y_i = \frac{e^{x_i}}{\sum_j e^{x_j}}$$

**Interpretation:** $$y$$ must be probability vector: $$y \geq 0$$, $$\sum y_i = 1$$

**Conjugate:** $$f^*(y) = \sum_{i=1}^n y_i \log y_i$$ (negative entropy)

**Domain:** Probability simplex $$\{y : y \geq 0, \sum y_i = 1\}$$

**Step 5: Max function**
$$f(x) = \max_{i=1,\ldots,n} x_i$$

**Related to the dual of the $$\ell_\infty$$ norm:**

**Conjugate:**
$$f^*(y) = \begin{cases} 0 &amp;amp; \text{if } y \geq 0, \sum y_i = 1 \\ +\infty &amp;amp; \text{otherwise} \end{cases}$$

**Domain:** Probability simplex

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-subdifferentials-and-optimality&quot;&gt;📝 &lt;strong&gt;Exercise 4: Subdifferentials and optimality&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 3.4 from Boyd &amp;amp; Vandenberghe)
Compute the subdifferential \(\partial f(x) = \{g : f(y) \geq f(x) + g^T(y - x), \forall y\}\) for:&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;a) $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;$$ at different points&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;b) \(f(x) = \max\{0, x\}\) (ReLU function)&lt;/p&gt;

&lt;p&gt;c) \(f(x) = \lVert x \rVert_1\)&lt;/p&gt;

&lt;p&gt;d) \(f(x) = \lVert x \rVert_2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Compute subdifferentials explicitly&lt;/li&gt;
  &lt;li&gt;Verify optimality conditions&lt;/li&gt;
  &lt;li&gt;Analyze non-differentiable points&lt;/li&gt;
  &lt;li&gt;Apply to optimization problems&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Absolute value $$f(x) = |x|$$**

**Case $$x &amp;gt; 0$$:** $$f$$ differentiable, $$\partial f(x) = \{1\}$$

**Case $$x &amp;lt; 0$$:** $$f$$ differentiable, $$\partial f(x) = \{-1\}$$

**Case $$x = 0$$:** Non-differentiable point

**Subdifferential at $$x = 0$$:**
$$\partial f(0) = \{g : |y| \geq g \cdot y, \forall y\}$$

**Analysis:** We need $$|g| \leq 1$$

$$\Rightarrow \partial f(0) = [-1, 1]$$

**Step 2: ReLU function $$f(x) = \max\{0, x\}$$**

**Case $$x &amp;gt; 0$$:** $$f(x) = x$$, $$\partial f(x) = \{1\}$$

**Case $$x &amp;lt; 0$$:** $$f(x) = 0$$, $$\partial f(x) = \{0\}$$

**Case $$x = 0$$:** 
$$\partial f(0) = \{g : \max\{0, y\} \geq g \cdot y, \forall y\}$$

**Analysis:**
- For $$y &amp;gt; 0$$: $$y \geq g \cdot y \Rightarrow g \leq 1$$
- For $$y &amp;lt; 0$$: $$0 \geq g \cdot y \Rightarrow g \geq 0$$

$$\Rightarrow \partial f(0) = [0, 1]$$

**Step 3: $$\ell_1$$ norm $$f(x) = \lVert x \rVert_1$$**

**Component-wise analysis:** $$f(x) = \sum_{i=1}^n |x_i|$$

**Subdifferential:** $$\partial f(x) = \partial f_1(x_1) \times \cdots \times \partial f_n(x_n)$$

where $$\partial f_i(x_i) = \begin{cases} \{1\} &amp;amp; \text{if } x_i &amp;gt; 0 \\ \{-1\} &amp;amp; \text{if } x_i &amp;lt; 0 \\ [-1, 1] &amp;amp; \text{if } x_i = 0 \end{cases}$$

**Result:** $$\partial f(x) = \{g : g_i = \text{sign}(x_i) \text{ if } x_i \neq 0, |g_i| \leq 1 \text{ if } x_i = 0\}$$

**Step 4: Euclidean norm $$f(x) = \lVert x \rVert_2$$**

**Case $$x \neq 0$$:** $$\partial f(x) = \left\{\frac{x}{\lVert x \rVert_2}\right\}$$

**Case $$x = 0$$:** 
$$\partial f(0) = \{g : \lVert y \rVert_2 \geq g^T y, \forall y\}$$

**By Cauchy-Schwarz:** $$g^T y \leq \lVert g \rVert_2 \lVert y \rVert_2$$

**Condition:** $$\lVert g \rVert_2 \leq 1$$

$$\Rightarrow \partial f(0) = \{g : \lVert g \rVert_2 \leq 1\}$$ (unit ball)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-jensens-inequality-and-applications&quot;&gt;📝 &lt;strong&gt;Exercise 5: Jensen’s inequality and applications&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 3.5 from Boyd &amp;amp; Vandenberghe)
a) Prove Jensen’s inequality: if \(f\) is convex, \(\lambda_i \geq 0\), \(\sum \lambda_i = 1\), then:
\(f\left(\sum_{i=1}^n \lambda_i x_i\right) \leq \sum_{i=1}^n \lambda_i f(x_i)\)&lt;/p&gt;

&lt;p&gt;b) Use Jensen’s inequality to prove:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Arithmetic-geometric mean: \(\frac{x_1 + \cdots + x_n}{n} \geq \sqrt[n]{x_1 \cdots x_n}\)&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Hölder’s inequality: $$\sum_{i=1}^n&lt;/td&gt;
          &lt;td&gt;x_i y_i&lt;/td&gt;
          &lt;td&gt;\leq \left(\sum_{i=1}^n&lt;/td&gt;
          &lt;td&gt;x_i&lt;/td&gt;
          &lt;td&gt;^p\right)^{1/p} \left(\sum_{i=1}^n&lt;/td&gt;
          &lt;td&gt;y_i&lt;/td&gt;
          &lt;td&gt;^q\right)^{1/q}$$&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c) Derive log-sum inequality&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;A rigorous proof by induction&lt;/li&gt;
  &lt;li&gt;Geometric interpretation&lt;/li&gt;
  &lt;li&gt;Applications in probability&lt;/li&gt;
  &lt;li&gt;Extensions to continuous case&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Proof of Jensen&apos;s inequality**

**Base case ($$n = 2$$):** The definition of convexity

**Inductive step:** Assume it holds for $$n-1$$; prove it for $$n$$.

With $$\sum_{i=1}^n \lambda_i = 1$$, let $$\mu = \sum_{i=1}^{n-1} \lambda_i &amp;lt; 1$$.

$$f\left(\sum_{i=1}^n \lambda_i x_i\right) = f\left(\mu \cdot \frac{\sum_{i=1}^{n-1} \lambda_i x_i}{\mu} + (1-\mu) x_n\right)$$

**By convexity:**
$$\leq \mu f\left(\frac{\sum_{i=1}^{n-1} \lambda_i x_i}{\mu}\right) + (1-\mu) f(x_n)$$

**By induction hypothesis:**
$$\leq \mu \sum_{i=1}^{n-1} \frac{\lambda_i}{\mu} f(x_i) + \lambda_n f(x_n) = \sum_{i=1}^n \lambda_i f(x_i)$$

**Step 2: Arithmetic-geometric mean**

**Setup:** $$f(x) = -\log x$$ is convex on $$\mathbb{R}_{++}$$

**Jensen:** $$-\log\left(\frac{x_1 + \cdots + x_n}{n}\right) \leq \frac{1}{n}\sum_{i=1}^n (-\log x_i) = -\frac{1}{n}\log(x_1 \cdots x_n)$$

**Rearranging:** $$\log\left(\frac{x_1 + \cdots + x_n}{n}\right) \geq \log\sqrt[n]{x_1 \cdots x_n}$$

$$\Rightarrow \frac{x_1 + \cdots + x_n}{n} \geq \sqrt[n]{x_1 \cdots x_n}$$

**Step 3: Hölder&apos;s inequality**

**Setup:** Use conjugate exponents $$\frac{1}{p} + \frac{1}{q} = 1$$

**Key function:** $$f(t) = e^t$$ convex

**Young&apos;s inequality:** for $$a, b &amp;gt; 0$$, Jensen for the convex function $$e^t$$ with weights $$\frac{1}{p}, \frac{1}{q}$$:
$$ab = e^{\frac{1}{p}\log a^p + \frac{1}{q}\log b^q} \leq \frac{1}{p}a^p + \frac{1}{q}b^q$$
**Normalize and sum:** let $$a_i = \frac{|x_i|}{\lVert x \rVert_p}$$, $$b_i = \frac{|y_i|}{\lVert y \rVert_q}$$; then $$\sum_i a_i b_i \leq \frac{1}{p}\sum_i a_i^p + \frac{1}{q}\sum_i b_i^q = \frac{1}{p} + \frac{1}{q} = 1$$, that is:
$$\sum |x_i y_i| \leq \left(\sum |x_i|^p\right)^{1/p} \left(\sum |y_i|^q\right)^{1/q}$$

**Step 4: Log-sum inequality**

**Statement:** $$\sum_{i=1}^n a_i \log \frac{a_i}{b_i} \geq \left(\sum_{i=1}^n a_i\right) \log \frac{\sum_{i=1}^n a_i}{\sum_{i=1}^n b_i}$$

**Proof:** Use Jensen with the convex function $$f(x) = x \log x$$ and appropriate weights.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-6-quasiconvex-functions&quot;&gt;📝 &lt;strong&gt;Exercise 6: Quasiconvex functions&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 3.6 from Boyd &amp;amp; Vandenberghe)
a) Verify quasiconvexity of:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(x) = \frac{x_1}{x_2}\) on \(\{x : x_2 &amp;gt; 0\}\)&lt;/li&gt;
  &lt;li&gt;\(f(x) = x_1^2 / x_2\) on \(\{x : x_2 &amp;gt; 0\}\)&lt;/li&gt;
  &lt;li&gt;\(f(x) = \log(x_1) - \log(x_2)\) on \(\mathbb{R}_{++}^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;b) Prove: \(f\) is quasiconvex \(\Leftrightarrow\) its sublevel sets \(\{x : f(x) \leq \alpha\}\) are convex&lt;/p&gt;

&lt;p&gt;c) Operations preserving quasiconvexity&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Verify using sublevel-set analysis&lt;/li&gt;
  &lt;li&gt;Check first-order conditions&lt;/li&gt;
  &lt;li&gt;Analyze monotonic transformations&lt;/li&gt;
  &lt;li&gt;Compare with convexity&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Ratio function $$f(x) = \frac{x_1}{x_2}$$**

**Sublevel sets:** $$S_\alpha = \{x : x_1 \leq \alpha x_2, x_2 &amp;gt; 0\}$$

**Analysis:** $$S_\alpha = \{x : x_1 - \alpha x_2 \leq 0, x_2 &amp;gt; 0\}$$

Intersection of a halfspace and an (open) halfspace $$\Rightarrow$$ convex

$$\Rightarrow f$$ quasiconvex

**Step 2: $$f(x) = \frac{x_1^2}{x_2}$$**

**Sublevel sets:** $$S_\alpha = \{x : x_1^2 \leq \alpha x_2, x_2 &amp;gt; 0\}$$

**For $$\alpha \leq 0$$:** $$S_\alpha = \{x : x_1 = 0, x_2 &amp;gt; 0\}$$ (convex)

**For $$\alpha &amp;gt; 0$$:** $$S_\alpha = \{x : x_1^2 \leq \alpha x_2, x_2 &amp;gt; 0\}$$

**Second-order cone:** $$\{x : \lVert x_1 \rVert_2 \leq \sqrt{\alpha x_2}, x_2 &amp;gt; 0\}$$ (convex)

$$\Rightarrow f$$ quasiconvex

**Step 3: Log ratio $$f(x) = \log x_1 - \log x_2$$**

**Equivalent:** $$f(x) = \log\frac{x_1}{x_2}$$

**Monotonic transformation:** $$\log$$ increasing, $$\frac{x_1}{x_2}$$ quasiconvex

$$\Rightarrow f$$ quasiconvex

**Step 4: Characterization theorem**

**Theorem:** $$f$$ quasiconvex $$\Leftrightarrow$$ all sublevel sets convex

**Proof ($$\Rightarrow$$):** 
For $$x, y \in S_\alpha$$, $$f(x), f(y) \leq \alpha$$

By quasiconvexity: $$f(\theta x + (1-\theta) y) \leq \max\{f(x), f(y)\} \leq \alpha$$

$$\Rightarrow \theta x + (1-\theta) y \in S_\alpha$$

**Proof ($$\Leftarrow$$):**
If $$f(x), f(y) \leq \alpha$$, then $$x, y \in S_\alpha$$

Since $$S_\alpha$$ is convex: $$\theta x + (1-\theta) y \in S_\alpha$$

$$\Rightarrow f(\theta x + (1-\theta) y) \leq \alpha = \max\{f(x), f(y)\}$$

**Step 5: Operations preserving quasiconvexity**

- **Nonnegative weighted maximum:** $$\max\{f_1, f_2\}$$ quasiconvex
- **Composition with an increasing function:** $$g \circ f$$ is quasiconvex if $$g$$ is increasing
- **Minimization:** Generally not preserved

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-7-log-concave-and-log-convex-functions&quot;&gt;📝 &lt;strong&gt;Exercise 7: Log-concave and log-convex functions&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 3.7 from Boyd &amp;amp; Vandenberghe)
a) Verify log-concavity of:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Gaussian density: \(f(x) = e^{-\frac{1}{2}(x-\mu)^T \Sigma^{-1} (x-\mu)}\)&lt;/li&gt;
  &lt;li&gt;Gamma function: \(\Gamma(x) = \int_0^\infty t^{x-1} e^{-t} dt\) (note: \(\Gamma\) is actually &lt;strong&gt;log-convex&lt;/strong&gt;, not log-concave, on \(x &amp;gt; 0\): each function \(x \mapsto t^{x-1}e^{-t} = e^{(x-1)\log t - t}\) is log-affine, and an integral of log-convex functions is log-convex)&lt;/li&gt;
  &lt;li&gt;Determinant: \(\det(X)\) on \(\mathbb{S}_{++}^n\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;b) Applications in probability and statistics&lt;/p&gt;

&lt;p&gt;c) Relationship with convexity&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Verify using second-order conditions&lt;/li&gt;
  &lt;li&gt;Analyze preservation properties&lt;/li&gt;
  &lt;li&gt;Statistical applications&lt;/li&gt;
  &lt;li&gt;Optimization implications&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Gaussian density**

**Function:** $$f(x) = e^{-\frac{1}{2}(x-\mu)^T \Sigma^{-1} (x-\mu)}$$

**Log function:** $$\log f(x) = -\frac{1}{2}(x-\mu)^T \Sigma^{-1} (x-\mu)$$

**Hessian:** $$\nabla^2 \log f(x) = -\Sigma^{-1} \preceq 0$$

$$\Rightarrow \log f$$ concave $$\Rightarrow f$$ log-concave

**Step 2: Determinant function**

**Function:** $$f(X) = \det(X)$$ on $$\mathbb{S}_{++}^n$$

**Log function:** $$\log f(X) = \log \det(X)$$

**Known result:** $$\log \det(X)$$ is concave on $$\mathbb{S}_{++}^n$$

**Proof sketch:** Hessian analysis or operator concavity

$$\Rightarrow \det(X)$$ log-concave

**Step 3: Preservation properties**

**Products:** If $$f, g$$ are log-concave, then $$fg$$ is log-concave

**Proof:** $$\log(fg) = \log f + \log g$$ (a sum of concave functions)

**Powers:** If $$f$$ is log-concave and $$\alpha \geq 0$$, then $$f^\alpha$$ is log-concave

**Integration:** Log-concavity preserved under integration

**Step 4: Statistical applications**

**Maximum likelihood:** Log-concave likelihoods $$\Rightarrow$$ concave log-likelihood

**Unimodality:** Log-concave densities are unimodal

**Concentration:** Log-concave measures satisfy concentration inequalities

**Step 5: Optimization implications**

**Geometric programming:** Log-convex functions in GP

**Barrier methods:** $$-\log \det(X)$$ as a barrier for the PSD cone

**Exponential families:** Natural parameters and log-partition functions

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-8-perspective-and-epigraph&quot;&gt;📝 &lt;strong&gt;Exercise 8: Perspective and epigraph&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 3.8 from Boyd &amp;amp; Vandenberghe)
a) Let \(f: \mathbb{R}^n \to \mathbb{R}\) be convex. Prove that the perspective function:
\(g(x, t) = t f(x/t)\) with \(t &amp;gt; 0\)
is convex on \(\mathbb{R}^n \times \mathbb{R}_{++}\)&lt;/p&gt;

&lt;p&gt;b) Applications:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[f(x) = \lVert x \rVert_2 \Rightarrow g(x,t) = \lVert x \rVert_2\]
  &lt;/li&gt;
  &lt;li&gt;
\[f(x) = x^2 \Rightarrow g(x,t) = x^2/t\]
  &lt;/li&gt;
  &lt;li&gt;
\[f(x) = e^x \Rightarrow g(x,t) = t e^{x/t}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c) The epigraph characterization of convexity&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;A rigorous proof of convexity of the perspective&lt;/li&gt;
  &lt;li&gt;Geometric interpretation&lt;/li&gt;
  &lt;li&gt;Second-order cone connections&lt;/li&gt;
  &lt;li&gt;Epigraph analysis&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Convexity of the perspective function**

**Theorem:** If $$f$$ is convex, then $$g(x,t) = tf(x/t)$$ is convex on $$\text{dom}(g) = \{(x,t) : x/t \in \text{dom}(f), t &amp;gt; 0\}$$

**Proof:** For $$(x_1, t_1), (x_2, t_2) \in \text{dom}(g)$$ and $$\theta \in [0,1]$$:

$$g(\theta(x_1, t_1) + (1-\theta)(x_2, t_2)) = g(\theta x_1 + (1-\theta) x_2, \theta t_1 + (1-\theta) t_2)$$

$$= (\theta t_1 + (1-\theta) t_2) f\left(\frac{\theta x_1 + (1-\theta) x_2}{\theta t_1 + (1-\theta) t_2}\right)$$

**Key observation:** 
$$\frac{\theta x_1 + (1-\theta) x_2}{\theta t_1 + (1-\theta) t_2} = \frac{\theta t_1}{\theta t_1 + (1-\theta) t_2} \cdot \frac{x_1}{t_1} + \frac{(1-\theta) t_2}{\theta t_1 + (1-\theta) t_2} \cdot \frac{x_2}{t_2}$$

**Convex combination with weights:** $$\frac{\theta t_1}{\theta t_1 + (1-\theta) t_2} + \frac{(1-\theta) t_2}{\theta t_1 + (1-\theta) t_2} = 1$$

**By convexity of $$f$$:**
$$f\left(\frac{\theta x_1 + (1-\theta) x_2}{\theta t_1 + (1-\theta) t_2}\right) \leq \frac{\theta t_1}{\theta t_1 + (1-\theta) t_2} f(x_1/t_1) + \frac{(1-\theta) t_2}{\theta t_1 + (1-\theta) t_2} f(x_2/t_2)$$

**Multiplying by $$\theta t_1 + (1-\theta) t_2$$:**
$$g(\theta(x_1, t_1) + (1-\theta)(x_2, t_2)) \leq \theta t_1 f(x_1/t_1) + (1-\theta) t_2 f(x_2/t_2) = \theta g(x_1, t_1) + (1-\theta) g(x_2, t_2)$$

**Step 2: Applications**

**Example 1:** $$f(x) = \lVert x \rVert_2$$
$$g(x,t) = t \lVert x/t \rVert_2 = \lVert x \rVert_2$$

**Geometric interpretation:** Norm function invariant under perspective

**Example 2:** $$f(x) = x^2$$
$$g(x,t) = t(x/t)^2 = x^2/t$$

**Second-order cone:** $$\{(x,t,s) : x^2/t \leq s, t &amp;gt; 0\} = \{(x,t,s) : \lVert (2x,\ s-t) \rVert_2 \leq s+t,\ t &amp;gt; 0\}$$ (since $$(2x)^2 + (s-t)^2 \leq (s+t)^2 \Leftrightarrow x^2 \leq st$$)

**Example 3:** $$f(x) = e^x$$
$$g(x,t) = te^{x/t}$$

**Exponential cone:** Important in conic optimization

**Step 3: Epigraph characterization**

**Theorem:** $$f$$ convex $$\Leftrightarrow$$ $$\text{epi}(f) = \{(x,t) : f(x) \leq t\}$$ convex

**Proof ($$\Rightarrow$$):** 
For $$(x_1, t_1), (x_2, t_2) \in \text{epi}(f)$$:
$$f(\theta x_1 + (1-\theta) x_2) \leq \theta f(x_1) + (1-\theta) f(x_2) \leq \theta t_1 + (1-\theta) t_2$$

$$\Rightarrow (\theta x_1 + (1-\theta) x_2, \theta t_1 + (1-\theta) t_2) \in \text{epi}(f)$$

**Proof ($$\Leftarrow$$):**
For $$f(x_1) \leq t_1, f(x_2) \leq t_2$$, choose $$t_1 = f(x_1), t_2 = f(x_2)$$

Convexity of the epigraph $$\Rightarrow$$ convexity of $$f$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-9-matrix-functions-and-convexity&quot;&gt;📝 &lt;strong&gt;Exercise 9: Matrix functions and convexity&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 3.9 from Boyd &amp;amp; Vandenberghe)
Analyze the convexity of the following matrix functions:&lt;/p&gt;

&lt;p&gt;a) \(f(X) = \text{tr}(X)\) on \(\mathbb{S}^n\)&lt;/p&gt;

&lt;p&gt;b) \(f(X) = \text{tr}(X^2)\) on \(\mathbb{S}^n\)&lt;/p&gt;

&lt;p&gt;c) \(f(X) = \lambda_{\max}(X)\) on \(\mathbb{S}^n\)&lt;/p&gt;

&lt;p&gt;d) \(f(X) = \det(X)\) on \(\mathbb{S}_{++}^n\)&lt;/p&gt;

&lt;p&gt;e) \(f(X) = -\log \det(X)\) on \(\mathbb{S}_{++}^n\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Verify convexity/concavity&lt;/li&gt;
  &lt;li&gt;Compute subdifferentials&lt;/li&gt;
  &lt;li&gt;Applications in SDP&lt;/li&gt;
  &lt;li&gt;Optimization algorithms&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Trace function $$f(X) = \text{tr}(X)$$**

**Linearity:** $$\text{tr}(\theta X + (1-\theta) Y) = \theta \text{tr}(X) + (1-\theta) \text{tr}(Y)$$

$$\Rightarrow$$ Both convex and concave (affine)

**Subdifferential:** $$\partial f(X) = \{I\}$$

**Step 2: Trace of the square $$f(X) = \text{tr}(X^2)$$**

**Expansion:** $$\text{tr}(X^2) = \sum_{i,j} X_{ij}^2$$

**Convexity:** A sum of convex functions ($$x^2$$)

**Subdifferential:** $$\partial f(X) = \{2X\}$$

**Step 3: Maximum eigenvalue $$f(X) = \lambda_{\max}(X)$$**

**Variational characterization:** $$\lambda_{\max}(X) = \max_{\lVert v \rVert_2 = 1} v^T X v$$

**Convexity:** A maximum of linear functions $$v^T X v$$

**Subdifferential:** $$\partial f(X) = \text{conv}\{vv^T : v \text{ eigenvector of } \lambda_{\max}(X), \lVert v \rVert_2 = 1\}$$

**Step 4: Determinant $$f(X) = \det(X)$$**

**Log-concavity:** $$\log \det(X)$$ concave $$\Rightarrow \det(X)$$ log-concave

**Not convex:** $$\det$$ is neither convex nor concave on $$\mathbb{S}_{++}^n$$ (for $$n \geq 2$$)

**Geometric mean:** $$\det(X)^{1/n} = (\prod \lambda_i)^{1/n}$$ concave

**Step 5: Negative log-determinant $$f(X) = -\log \det(X)$$**

**Convexity:** $$-\log \det(X)$$ is strictly convex on $$\mathbb{S}_{++}^n$$

**Subdifferential:** $$\partial f(X) = \{-X^{-1}\}$$

**Barrier function:** Used in interior-point methods for SDP

**Hessian:** $$\nabla^2 f(X)[H, H] = \text{tr}(X^{-1} H X^{-1} H) &amp;gt; 0$$ for $$H \neq 0$$

**Applications:**
- **SDP barrier:** $$-\log \det(X)$$ as a barrier for $$X \succ 0$$
- **Maximum likelihood:** Covariance estimation
- **Optimal design:** D-optimal experimental design

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-10-convex-optimization-applications&quot;&gt;📝 &lt;strong&gt;Exercise 10: Convex optimization applications&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 3.10 from Boyd &amp;amp; Vandenberghe)
Formulate the following problems using convex functions:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Robust regression:&lt;/strong&gt; Minimize sum of Huber losses
b) &lt;strong&gt;Entropy maximization:&lt;/strong&gt; Subject to moment constraints
c) &lt;strong&gt;Geometric mean maximization:&lt;/strong&gt; \(\max \prod_{i=1}^n x_i^{1/n}\) subject to constraints
d) &lt;strong&gt;Relative entropy minimization:&lt;/strong&gt; \(\min \sum_{i=1}^n x_i \log(x_i/y_i)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Identify convex formulations&lt;/li&gt;
  &lt;li&gt;Analyze optimality conditions&lt;/li&gt;
  &lt;li&gt;Suggest solution algorithms&lt;/li&gt;
  &lt;li&gt;Discuss practical applications&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Robust regression**

**Problem:** $$\min_\beta \sum_{i=1}^n \phi(y_i - x_i^T \beta)$$

where the Huber loss is $$\phi(u) = \begin{cases} \frac{1}{2}u^2 &amp;amp; |u| \leq M \\ M|u| - \frac{1}{2}M^2 &amp;amp; |u| &amp;gt; M \end{cases}$$

**Convexity:** $$\phi$$ is convex (piecewise quadratic with a non-decreasing derivative)

**Reformulation:** 
$$\min_{\beta,r,s} \frac{1}{2}\sum_{i=1}^n r_i^2 + M\sum_{i=1}^n s_i$$
$$\text{s.t.} \quad |y_i - x_i^T \beta| \leq r_i + s_i, \quad 0 \leq r_i \leq M, \quad s_i \geq 0$$

**Step 2: Entropy maximization**

**Problem:** $$\max_x -\sum_{i=1}^n x_i \log x_i \quad \text{s.t.} \quad \sum_{i=1}^n a_{ij} x_i = b_j, \quad x_i \geq 0$$

**Convex formulation:** $$\min_x \sum_{i=1}^n x_i \log x_i$$

**Optimality conditions:** 
$$\log x_i + 1 + \sum_{j=1}^m \lambda_j a_{ij} = 0$$
$$\Rightarrow x_i^* = e^{-1 - \sum_j \lambda_j a_{ij}}$$

**Maximum entropy distribution:** Exponential family form

**Step 3: Geometric mean maximization**

**Problem:** $$\max_{x \geq 0} \prod_{i=1}^n x_i^{1/n} \quad \text{s.t.} \quad Ax \leq b$$

**Log transformation:** $$\max_x \frac{1}{n}\sum_{i=1}^n \log x_i$$

**Convex formulation:** $$\min_x -\sum_{i=1}^n \log x_i \quad \text{s.t.} \quad Ax \leq b, \quad x &amp;gt; 0$$

**Barrier method:** A natural fit for log barriers

**Applications:** Optimal design, Nash bargaining

**Step 4: Relative entropy minimization**

**Problem:** $$\min_x \sum_{i=1}^n x_i \log \frac{x_i}{y_i} \quad \text{s.t.} \quad Ax = b, \quad x \geq 0$$

**Convexity:** The KL divergence is convex in its first argument

**Optimality conditions:**
$$\log \frac{x_i}{y_i} + 1 + (A^T \lambda)_i - \mu_i = 0$$ (with $$\mu \geq 0$$ the multiplier for $$x \geq 0$$; since the solution has $$x_i &amp;gt; 0$$, $$\mu_i = 0$$)

**Solution form:** $$x_i^* = y_i e^{-(A^T \lambda^*)_i - 1}$$

**Applications:**
- **Information theory:** Channel capacity
- **Statistics:** Maximum likelihood with a prior
- **Machine learning:** Regularized optimization

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-practical-tips&quot;&gt;💡 Practical Tips&lt;/h2&gt;

&lt;h4 id=&quot;when-verifying-convexity&quot;&gt;&lt;strong&gt;When verifying convexity:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Second-order condition:&lt;/strong&gt; \(f&apos;&apos;(x) \geq 0\) or \(\nabla^2 f \succeq 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Definition:&lt;/strong&gt; Check \(f(\theta x + (1-\theta) y) \leq \theta f(x) + (1-\theta) f(y)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Composition rules:&lt;/strong&gt; Use operations that preserve convexity&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;when-computing-conjugate-functions&quot;&gt;&lt;strong&gt;When computing conjugate functions:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Optimization approach:&lt;/strong&gt; \(f^*(y) = \sup_x (y^T x - f(x))\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;First-order condition:&lt;/strong&gt; \(y \in \partial f(x^*)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric interpretation:&lt;/strong&gt; Supporting hyperplanes&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;when-working-with-subdifferentials&quot;&gt;&lt;strong&gt;When working with subdifferentials:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Differentiable case:&lt;/strong&gt; \(\partial f(x) = \{\nabla f(x)\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-differentiable:&lt;/strong&gt; Use the definition or calculus rules&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimality:&lt;/strong&gt; \(0 \in \partial f(x^*)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;definition-and-tests-of-convexity&quot;&gt;&lt;strong&gt;Definition and Tests of Convexity:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Condition&lt;/th&gt;
      &lt;th&gt;When to use&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)\)&lt;/td&gt;
      &lt;td&gt;Direct proofs&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;First-order&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(y) \geq f(x) + \nabla f(x)^T(y-x)\)&lt;/td&gt;
      &lt;td&gt;Differentiable functions&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Second-order&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\nabla^2 f(x) \succeq 0\)&lt;/td&gt;
      &lt;td&gt;Twice differentiable&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Epigraph&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\text{epi}(f)\) convex&lt;/td&gt;
      &lt;td&gt;Geometric view&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;convexity-preserving-operations&quot;&gt;&lt;strong&gt;Convexity-preserving Operations:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Operation&lt;/th&gt;
      &lt;th&gt;Result&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Nonnegative weighted sum&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\sum \alpha_i f_i\) with \(\alpha_i \geq 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Composition with affine&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(Ax + b)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Pointwise maximum&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(x) = \max\{f_1(x), \ldots, f_m(x)\}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Pointwise supremum&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(g(x) = \sup_{y \in \mathcal{A}} f(x, y)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Composition rules&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(h \circ g\) (requires \(h\) increasing convex, \(g\) convex)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Minimization&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(g(x) = \inf_y f(x, y)\) if \(f\) is convex in \((x,y)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Perspective&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(g(x, t) = tf(x/t)\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;examples-of-convex-functions&quot;&gt;&lt;strong&gt;Examples of Convex Functions:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Function&lt;/th&gt;
      &lt;th&gt;Domain&lt;/th&gt;
      &lt;th&gt;Convex?&lt;/th&gt;
      &lt;th&gt; &lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Exponential&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(e^{ax}\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}\)&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Powers&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(x^a\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}_{++}\)&lt;/td&gt;
      &lt;td&gt;✓ (\(a \geq 1\) or \(a \leq 0\))&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Logarithm&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(-\log x\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}_{++}\)&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Norms&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(||x||_p\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^n\)&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Max&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\max\{x_1, \ldots, x_n\}\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^n\)&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Quadratic&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(x^TQx\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^n\)&lt;/td&gt;
      &lt;td&gt;✓ (if \(Q \succeq 0\))&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Log-sum-exp&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\log(\sum e^{x_i})\)&lt;/td&gt;
      &lt;td&gt;\(\mathbb{R}^n\)&lt;/td&gt;
      &lt;td&gt;✓&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;conjugate-functions&quot;&gt;&lt;strong&gt;Conjugate Functions:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Definition:&lt;/strong&gt; \(f^*(y) = \sup_x (y^Tx - f(x))\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel inequality:&lt;/strong&gt; \(f(x) + f^*(y) \geq x^Ty\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conjugate of the conjugate:&lt;/strong&gt; \(f^{**} = f\) (if \(f\) is closed and convex)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Examples:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[(x^2/2)^* = y^2/2\]
      &lt;/li&gt;
      &lt;li&gt;\((\|\|x\|\|)^* = I_{\|\|y\|\|^* \leq 1}\) (indicator dual norm ball)&lt;/li&gt;
      &lt;li&gt;
\[(-\log x)^* = -\log(-y) - 1\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;subdifferential&quot;&gt;&lt;strong&gt;Subdifferential:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Definition:&lt;/strong&gt; \(g \in \partial f(x)\) if \(f(y) \geq f(x) + g^T(y-x)\) \(\forall y\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimality:&lt;/strong&gt; \(x^*\) optimal \(\Leftrightarrow\) \(0 \in \partial f(x^*)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Calculus rules:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[\partial(\alpha f) = \alpha \partial f\]
      &lt;/li&gt;
      &lt;li&gt;
\[\partial(f_1 + f_2) = \partial f_1 + \partial f_2\]
      &lt;/li&gt;
      &lt;li&gt;
\[\partial \max\{f_1, f_2\} = \text{conv}\{\partial f_i : f_i(x) = f(x)\}\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 References&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 3: Convex Functions&lt;/li&gt;
      &lt;li&gt;Exercises 3.1-3.54&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Rockafellar, R. T.&lt;/strong&gt; (1970). &lt;em&gt;Convex Analysis&lt;/em&gt;. Princeton University Press.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiriart-Urruty, J.-B., &amp;amp; Lemaréchal, C.&lt;/strong&gt; (1993). &lt;em&gt;Convex Analysis and Minimization Algorithms&lt;/em&gt;. Springer.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>03-09 Multiple-Choice Quiz - Convex Functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_09_Quiz_Convex_Functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_09_Quiz_Convex_Functions</id>
   <content type="html">&lt;p&gt;Can you spot in five seconds whether \(x_1^2 / x_2\) (on \(x_2 &amp;gt; 0\)) is convex, whether the composition \(e^{-x^2}\) preserves convexity, or what the Fenchel conjugate of an \(\ell_2\) norm is? This Chapter 03 quiz puts your convex-function instincts to the test—mixing definitions, Hessian checks, composition rules, conjugates, and Jensen’s inequality so you can verify mastery before moving to Chapter 04’s optimization problems.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-core-competency-checkpoints-for-this-quiz&quot;&gt;Key ideas: Core Competency Checkpoints for This Quiz&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Definition &amp;amp; Curvature Tiers:&lt;/strong&gt; Distinguishing convex, strictly convex, strongly convex, and concave functions via chords, gradients, and Hessians.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Composition Traps:&lt;/strong&gt; Watching monotonicity carefully—composing a convex increasing function with a convex inner function stays convex, while flipping a sign (like \(e^{-x^2}\)) breaks convexity!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conjugate Identities:&lt;/strong&gt; Remembering key conjugate pairs (quadratics \(\leftrightarrow\) inverse quadratics, norms \(\leftrightarrow\) dual-norm indicators, negative entropy \(\leftrightarrow\) log-sum-exp).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Jensen &amp;amp; Perspective Tricks:&lt;/strong&gt; Recognizing quadratic-over-linear \(x^2/y\) as the perspective of \(x^2\) and applying Jensen’s inequality to derive classical inequalities.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-proving-quadratic-over-linear-fx_1-x_2--x_12--x_2-is-convex&quot;&gt;Worked example: Proving Quadratic-over-Linear \(f(x_1, x_2) = x_1^2 / x_2\) Is Convex&lt;/h3&gt;

&lt;p&gt;Test \(f(x_1, x_2) = \frac{x_1^2}{x_2}\) on the open halfplane \(x_2 &amp;gt; 0\) using the Hessian.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute first partial derivatives:&lt;/strong&gt;
\(\frac{\partial f}{\partial x_1} = \frac{2x_1}{x_2}, \qquad \frac{\partial f}{\partial x_2} = -\frac{x_1^2}{x_2^2}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assemble the \(2 \times 2\) Hessian:&lt;/strong&gt;
\(\nabla^2 f(x_1, x_2) = \begin{pmatrix} \frac{2}{x_2} &amp;amp; -\frac{2x_1}{x_2^2} \\ -\frac{2x_1}{x_2^2} &amp;amp; \frac{2x_1^2}{x_2^3} \end{pmatrix} = \frac{2}{x_2^3}\begin{pmatrix} x_2^2 &amp;amp; -x_1 x_2 \\ -x_1 x_2 &amp;amp; x_1^2 \end{pmatrix} = \frac{2}{x_2^3}\begin{pmatrix} x_2 \\ -x_1 \end{pmatrix}\begin{pmatrix} x_2 &amp;amp; -x_1 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Certify positive semidefiniteness:&lt;/strong&gt; For any \(v \in \mathbb{R}^2\) and \(x_2 &amp;gt; 0\),
\(v^T \nabla^2 f(x_1, x_2) v = \frac{2}{x_2^3}(x_2 v_1 - x_1 v_2)^2 \ge 0.\)
Thus \(\nabla^2 f \succeq 0\) everywhere on \(x_2 &amp;gt; 0\) (also immediately visible as the perspective of \(g(u) = u^2\)!).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of convex functions, their basic properties, convexity-preserving operations and conjugate functions.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-definition-of-convex-functions&quot;&gt;📈 &lt;strong&gt;Definition of Convex Functions&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Convex function:&lt;/strong&gt;
A function \(f: \mathbb{R}^n \to \mathbb{R}\) is convex if:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;\(\text{dom}(f)\) is a convex set&lt;/li&gt;
  &lt;li&gt;\(f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y)\)
for all \(x, y \in \text{dom}(f), 0 \le \theta \le 1\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Types of convex functions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Strictly convex:&lt;/strong&gt; \(f(\theta x + (1-\theta)y) &amp;lt; \theta f(x) + (1-\theta)f(y)\) for \(x \neq y, 0 &amp;lt; \theta &amp;lt; 1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strongly convex:&lt;/strong&gt; \(f - \frac{m}{2}\lVert x \rVert_2^2\) is convex for some \(m &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Concave function:&lt;/strong&gt; \(f\) is concave ⟺ \(-f\) is convex&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Relation:&lt;/strong&gt; Strongly convex ⟹ Strictly convex ⟹ Convex&lt;/p&gt;

&lt;h3 id=&quot;-important-examples&quot;&gt;🔢 &lt;strong&gt;Important Examples&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Functions of one variable:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Exponential: \(e^{ax}\) is convex for every \(a \in \mathbb{R}\)&lt;/li&gt;
  &lt;li&gt;Power: \(x^a\) is convex on \(\mathbb{R}_+\) when \(a \ge 1\) or \(a \le 0\)&lt;/li&gt;
  &lt;li&gt;Power: \(x^a\) is concave on \(\mathbb{R}_+\) when \(0 \le a \le 1\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Functions of several variables:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Affine function: \(a^T x + b\) is both convex and concave&lt;/li&gt;
  &lt;li&gt;Quadratic function: \(\frac{1}{2}x^T P x + q^T x + r\) is convex when \(P \succeq 0\)&lt;/li&gt;
  &lt;li&gt;Norms: \(\lVert x \rVert_p\) is convex for every \(p \ge 1\)&lt;/li&gt;
  &lt;li&gt;Squared loss: \(\lVert Ax - b \rVert_2^2\) is always convex&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Special functions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Indicator function: \(I_C(x) = \begin{cases} 0 &amp;amp; x \in C \\ +\infty &amp;amp; x \notin C \end{cases}\) is convex if \(C\) is convex&lt;/li&gt;
  &lt;li&gt;Support function: \(I_C^*(x) = \max_{y \in C} x^T y\) is always convex&lt;/li&gt;
  &lt;li&gt;Max function: \(\max\{f_1(x), \ldots, f_m(x)\}\) is convex if the \(f_i\) are convex&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-characterizing-properties&quot;&gt;🔍 &lt;strong&gt;Characterizing Properties&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Epigraph characterization:&lt;/strong&gt;
\(f\) convex ⟺ \(\text{epi}(f) = \{(x,t) \mid x \in \text{dom}(f), f(x) \le t\}\) is a convex set&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sublevel sets:&lt;/strong&gt;
If \(f\) is convex then \(\{x \mid f(x) \le \alpha\}\) is convex for every \(\alpha\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First-order characterization (differentiable functions):&lt;/strong&gt;
\(f\) is convex ⟺ \(f(y) \ge f(x) + \nabla f(x)^T (y-x)\) for all \(x,y\)
(The function lies above its tangent lines)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second-order characterization (twice-differentiable functions):&lt;/strong&gt;
\(f\) convex ⟺ \(\nabla^2 f(x) \succeq 0\) for all \(x\) (positive semidefinite Hessian, with \(\text{dom}(f)\) convex)&lt;/p&gt;

&lt;h3 id=&quot;-operations-that-preserve-convexity&quot;&gt;🔄 &lt;strong&gt;Operations that Preserve Convexity&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Linear combination:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\alpha f\) is convex if \(f\) is convex and \(\alpha \ge 0\)&lt;/li&gt;
  &lt;li&gt;\(f_1 + f_2\) is convex if \(f_1, f_2\) are convex&lt;/li&gt;
  &lt;li&gt;\(\sum_{i=1}^m \alpha_i f_i\) is convex if the \(f_i\) are convex and \(\alpha_i \ge 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Affine composition:&lt;/strong&gt;
\(f(Ax + b)\) is convex if \(f\) is convex&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;General composition:&lt;/strong&gt; \(h(g(x))\) is convex if:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g\) is convex, \(h\) is convex and nondecreasing&lt;/li&gt;
  &lt;li&gt;\(g\) is concave, \(h\) is convex and nonincreasing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pointwise maximum:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\max\{f_1(x), f_2(x)\}\) is convex if \(f_1, f_2\) are convex&lt;/li&gt;
  &lt;li&gt;\(\sup_{y \in A} f(x,y)\) is convex in \(x\) if \(f(x,y)\) is convex in \(x\) for every \(y\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Perspective transformation:&lt;/strong&gt;
\(g(x,t) = tf(\frac{x}{t})\) is convex if \(f\) is convex, for \(t &amp;gt; 0\)&lt;/p&gt;

&lt;h3 id=&quot;-conjugate-functions&quot;&gt;⭐ &lt;strong&gt;Conjugate Functions&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt;
\(f^*(y) = \sup_{x \in \text{dom}(f)} \{y^T x - f(x)\}\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Key properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f^*\) is always convex (whether or not \(f\) is convex)&lt;/li&gt;
  &lt;li&gt;Fenchel’s inequality: \(f(x) + f^*(y) \ge x^T y\)&lt;/li&gt;
  &lt;li&gt;If \(f\) is closed and convex: \(f^{**} = f\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(x) = \frac{1}{2}x^T Q x \Rightarrow f^*(y) = \frac{1}{2}y^T Q^{-1} y\) (\(Q \succ 0\))&lt;/li&gt;
  &lt;li&gt;
\[f(x) = \lvert x \rvert \Rightarrow f^*(y) = \begin{cases} 0 &amp;amp; \lvert y \rvert \le 1 \\ +\infty &amp;amp; \lvert y \rvert &amp;gt; 1 \end{cases}\]
  &lt;/li&gt;
  &lt;li&gt;
\[f(x) = e^x \Rightarrow f^*(y) = \begin{cases} y \log y - y &amp;amp; y &amp;gt; 0 \\ 0 &amp;amp; y = 0 \\ +\infty &amp;amp; y &amp;lt; 0 \end{cases}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-jensens-inequality&quot;&gt;📊 &lt;strong&gt;Jensen’s Inequality&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;General form:&lt;/strong&gt;
If \(f\) is convex and \(\sum_{i=1}^n w_i = 1, w_i \ge 0\):
\(f\left(\sum_{i=1}^n w_i x_i\right) \le \sum_{i=1}^n w_i f(x_i)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Probabilistic form:&lt;/strong&gt;
If \(X\) is a random variable: \(f(E[X]) \le E[f(X)]\)&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; Convex functions “curve upward” - the chord joining any 2 points on the graph always lies above the graph. This makes optimization much easier!&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Multiple-Choice Quiz: Convex Functions&lt;/h2&gt;
        &lt;p&gt;Choose the best answer for each question. The quiz focuses on the basic concepts of convex functions and related operations.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Question 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Question 1: A function $$f: \mathbb{R}^n \to \mathbb{R}$$ is convex if:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) The domain is a convex set and $$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Only $$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$ is needed&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) The domain is a convex set and the function is differentiable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) The function is continuous on its domain&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The domain is a convex set and $$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$&lt;/strong&gt;&lt;br /&gt;
                The definition of a convex function requires both conditions: the domain must be a convex set and Jensen&apos;s inequality must hold for $$0 \leq \theta \leq 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: How does a strictly convex function differ from a convex function?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) It uses the strict inequality $$&amp;lt;$$ instead of $$\leq$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) It only applies for $$0 &amp;lt; \theta &amp;lt; 1$$ and $$x \neq y$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Both A and B are correct&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) There is no difference&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) Both A and B are correct&lt;/strong&gt;&lt;br /&gt;
                A strictly convex function requires $$f(\theta x + (1-\theta)y) &amp;lt; \theta f(x) + (1-\theta)f(y)$$ for $$0 &amp;lt; \theta &amp;lt; 1$$ and $$x \neq y$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: The relation between the types of convex functions is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) Strongly convex ⇒ Strictly convex ⇒ Convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Convex ⇒ Strictly convex ⇒ Strongly convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Strictly convex ⇒ Strongly convex ⇒ Convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) They are all equivalent&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Strongly convex ⇒ Strictly convex ⇒ Convex&lt;/strong&gt;&lt;br /&gt;
                This is the order from strongest to weakest: strong convexity is the strongest condition, then strict convexity, and finally convexity.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: The affine function $$f(x) = a^T x + b$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Convex only&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Concave only&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Both convex and concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Neither convex nor concave&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) Both convex and concave&lt;/strong&gt;&lt;br /&gt;
                An affine function satisfies $$f(\theta x + (1-\theta)y) = \theta f(x) + (1-\theta)f(y)$$ (with equality), so it is both convex and concave.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: The function $$f(x) = e^{ax}$$ with $$a \in \mathbb{R}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Convex for every $$a$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Convex only when $$a &amp;gt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Concave for every $$a$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Depends on the sign of $$a$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Convex for every $$a$$&lt;/strong&gt;&lt;br /&gt;
                The exponential $$e^{ax}$$ is convex for every real value of $$a$$, including negative, zero and positive $$a$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: On $$\mathbb{R}_+$$, the function $$f(x) = x^a$$ is convex when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) $$a \geq 1$$ or $$a \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) $$0 \leq a \leq 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) $$a &amp;gt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) For every $$a$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$a \geq 1$$ or $$a \leq 0$$&lt;/strong&gt;&lt;br /&gt;
                The function $$x^a$$ is convex on $$\mathbb{R}_+$$ when $$a \geq 1$$ or $$a \leq 0$$, and concave when $$0 \leq a \leq 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: The quadratic function $$f(x) = \frac{1}{2}x^T P x + q^T x + r$$ is convex when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) $$P$$ is positive definite&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) $$P$$ is positive semidefinite&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) $$P$$ is symmetric&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) $$P$$ is invertible&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$P$$ is positive semidefinite&lt;/strong&gt;&lt;br /&gt;
                A quadratic function is convex when its Hessian $$P$$ is positive semidefinite ($$P \succeq 0$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: All norms on $$\mathbb{R}^n$$ are:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) Convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) Concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Both convex and concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) Depends on the type of norm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Convex&lt;/strong&gt;&lt;br /&gt;
                By definition, every norm satisfies the triangle inequality (and homogeneity), which implies convexity.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: If $$f_1, f_2, ..., f_n$$ are convex functions, then $$\sum_{i=1}^n \alpha_i f_i$$ is convex when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) $$\alpha_i \geq 0$$ for all $$i$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) $$\sum_{i=1}^n \alpha_i = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) $$\alpha_i &amp;gt; 0$$ for all $$i$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) For all $$\alpha_i \in \mathbb{R}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\alpha_i \geq 0$$ for all $$i$$&lt;/strong&gt;&lt;br /&gt;
                A nonnegative weighted sum of convex functions is still convex. The condition $$\sum \alpha_i = 1$$ is not needed.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: If $$f$$ is a convex function, then $$g(x) = f(Ax + b)$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) Always convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) Convex only if $$A$$ is invertible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Convex only if $$A$$ is square&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) Not necessarily convex&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Always convex&lt;/strong&gt;&lt;br /&gt;
                Composition of a convex function with an affine map always preserves convexity, whatever the properties of $$A$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: Let $$g$$ be convex and $$h$$ convex and nondecreasing. The function $$f(x) = h(g(x))$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Cannot be determined&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Both convex and concave&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Convex&lt;/strong&gt;&lt;br /&gt;
                When $$g$$ is convex and $$h$$ is convex and nondecreasing, the composition $$h(g(x))$$ is convex.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: If $$f_1, f_2$$ are convex functions, then $$f(x) = \max\{f_1(x), f_2(x)\}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Neither convex nor concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Depends on $$f_1, f_2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Convex&lt;/strong&gt;&lt;br /&gt;
                The pointwise maximum of convex functions is always convex. This is an important convexity-preserving property.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The conjugate function $$f^*(y) = \sup_x \{y^T x - f(x)\}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Always convex, whether or not $$f$$ is convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Convex only if $$f$$ is convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Has the same convexity as $$f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Always concave&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Always convex, whether or not $$f$$ is convex&lt;/strong&gt;&lt;br /&gt;
                The conjugate is always convex because it is a supremum of functions $$y^T x - f(x)$$ that are affine in $$y$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: Fenchel&apos;s inequality states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) $$f(x) + f^*(y) \geq x^T y$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) $$f(x) + f^*(y) \leq x^T y$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) $$f(x) \cdot f^*(y) \geq x^T y$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) $$f(x) = f^*(y) + x^T y$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f(x) + f^*(y) \geq x^T y$$&lt;/strong&gt;&lt;br /&gt;
                Fenchel&apos;s inequality is a basic inequality in the theory of conjugate functions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: For a closed convex function $$f$$, the biconjugate $$f^{**}$$ satisfies:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) $$f^{**} = f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) $$f^{**} \leq f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) $$f^{**} \geq f$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) There is no fixed relationship&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$f^{**} = f$$&lt;/strong&gt;&lt;br /&gt;
                For a closed convex function, the biconjugate equals the original function. This is the Fenchel-Moreau theorem.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: The conjugate of $$f(x) = |x|$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) The indicator function of $$[-1,1]$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) $$|y|$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) $$y^2/2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) $$\log|y|$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The indicator function of $$[-1,1]$$&lt;/strong&gt;&lt;br /&gt;
                The conjugate of $$|x|$$ is $$f^*(y) = 0$$ if $$|y| \leq 1$$ and $$+\infty$$ if $$|y| &amp;gt; 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: The indicator function $$I_C(x)$$ of a convex set $$C$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Neither convex nor concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Depends on the set $$C$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Convex&lt;/strong&gt;&lt;br /&gt;
                The indicator function of a convex set is always convex: $$I_C(x) = 0$$ if $$x \in C$$, $$+\infty$$ if $$x \notin C$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: The support function $$S_C(x) = \max_{y \in C} x^T y$$ of a set $$C$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Convex whether or not $$C$$ is convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Convex only if $$C$$ is convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Concave whether or not $$C$$ is convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Has the same convexity as $$C$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Convex whether or not $$C$$ is convex&lt;/strong&gt;&lt;br /&gt;
                The support function is always convex because it is a supremum of the linear functions $$x^T y$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: The function $$f(x) = \|Ax - b\|_2^2$$ for an arbitrary matrix $$A$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Always convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Convex only if $$A$$ is square&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Convex only if $$A$$ is invertible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Not necessarily convex&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Always convex&lt;/strong&gt;&lt;br /&gt;
                Since $$A^T A$$ is positive semidefinite for every matrix $$A$$, $$\|Ax - b\|_2^2$$ is always convex.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: Why is recognizing convex functions important in optimization?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Every local minimum is a global minimum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) There are many efficient algorithms&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Duality theory applies&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above reasons&lt;/strong&gt;&lt;br /&gt;
                Convex functions have many good properties: local minimum = global minimum, efficient algorithms exist, and duality theory is strong.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: Consider $$f(x) = e^x$$. Is this function convex?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Yes, because $$f&apos;&apos;(x) = e^x &amp;gt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) No, because it grows too fast&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Convex only on $$(0, \infty)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Cannot be determined&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Yes, because $$f&apos;&apos;(x) = e^x &amp;gt; 0$$&lt;/strong&gt;&lt;br /&gt;
                $$f&apos;(x) = e^x$$, $$f&apos;&apos;(x) = e^x &amp;gt; 0$$ for all $$x$$, so the function is convex on all of $$\mathbb{R}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: Is the function $$g(x) = \max\{x, 0\}$$ (ReLU) convex?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Yes, by the definition of a convex function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) No, because it is not differentiable at $$x = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Convex only on $$[0, \infty)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) No, because it has a sharp corner&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Yes, by the definition of a convex function&lt;/strong&gt;&lt;br /&gt;
                The ReLU function satisfies the definition of a convex function. Non-differentiability at one point does not affect convexity.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: Let $$f(x,y) = x^2 + y^2$$. The Hessian matrix of $$f$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 2x &amp;amp; 0 \\ 0 &amp;amp; 2y \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} x &amp;amp; y \\ y &amp;amp; x \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                $$\frac{\partial^2 f}{\partial x^2} = 2$$, $$\frac{\partial^2 f}{\partial y^2} = 2$$, $$\frac{\partial^2 f}{\partial x \partial y} = 0$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The sum of two convex functions $$f$$ and $$g$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Always convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) May or may not be convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Always concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Depends on the domain&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Always convex&lt;/strong&gt;&lt;br /&gt;
                The sum of two convex functions is always convex. This is one of the convexity-preserving operations.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: What property does $$h(x) = |x|^p$$ with $$p \geq 1$$ have?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Convex on $$\mathbb{R}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Concave on $$\mathbb{R}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Convex only when $$p = 2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Neither convex nor concave&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Convex on $$\mathbb{R}$$&lt;/strong&gt;&lt;br /&gt;
                For $$p \geq 1$$, the function $$|x|^p$$ is convex on all of $$\mathbb{R}$$. This is an important example of a convex function.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Previous&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Next&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Exercise Results&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #00BCD4, #009688);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #00BCD4;
    background-color: #e0f2f1;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #00BCD4;
    background-color: #b2dfdb;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #e0f2f1;
    border-left: 4px solid #00BCD4;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #00695C;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #00BCD4;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #00ACC1;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #e0f2f1;
    border-radius: 8px;
    border: 2px solid #00BCD4;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #00695C;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answer for each question
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;c&apos;, q3: &apos;a&apos;, q4: &apos;c&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;a&apos;, q13: &apos;a&apos;, q14: &apos;a&apos;, q15: &apos;a&apos;,
    q16: &apos;a&apos;, q17: &apos;a&apos;, q18: &apos;a&apos;, q19: &apos;a&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

/**
 * Update the progress bar and show the current question
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Question ${currentQuestion}/${totalQuestions}`;
}

/**
 * Show a question by its number
 */
function showQuestion(questionNum) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Update the state of the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Go to the next question
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Go back to the previous question
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Store the user&apos;s answer
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Update the UI to show the selected answer
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Submit and show the results
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Compute the score and build the detailed report
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Show explanations for all questions
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Build the detailed report
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Question ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Correct&apos; : &apos;Incorrect&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Your answer: ${userAnswer || &apos;Not answered&apos;} | Correct answer: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Show the results
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Score: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Excellent! You have mastered the theory of convex functions!&apos; :
              scorePercentage &gt;= 60 ? &apos;👍 Pretty good! Review a few concepts about convex functions.&apos; :
              scorePercentage &gt;= 40 ? &apos;📚 You need more review of the definitions and properties of convex functions.&apos; : &apos;💪 Reread the theory of convex functions and their operations!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Restart the exercise
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide the results and show the navigation again
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Clear all selections
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>03-07 Euclidean Norm - L2 - is Convex</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_07_euclidean_norm_convexity_proof/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_07_euclidean_norm_convexity_proof</id>
   <content type="html">&lt;p&gt;The Euclidean norm \(f(x) = \|x\|_2\) is the workhorse of geometry, group-Lasso regularization, and second-order cone programming—yet it carries a subtle twist: it is &lt;em&gt;not&lt;/em&gt; differentiable at the origin \(x = 0\), so a naive Hessian test alone cannot cover all of \(\mathbb{R}^n\). Proving its convexity three distinct ways—directly via the triangle inequality, algebraically via Cauchy–Schwarz, and differentially via its rank-\((n-1)\) Hessian away from zero—builds deep intuition for nonsmooth convex functions.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-three-complementary-proofs-of-x_2-convexity&quot;&gt;Key ideas: Three Complementary Proofs of \(\|x\|_2\) Convexity&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Triangle Inequality + Homogeneity (Cleanest):&lt;/strong&gt; In two lines, \(\|\theta x + (1-\theta)y\|_2 \le \|\theta x\|_2 + \|(1-\theta)y\|_2 = \theta\|x\|_2 + (1-\theta)\|y\|_2\)—working for &lt;em&gt;every&lt;/em&gt; norm on \(\mathbb{R}^n\) with zero calculus.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cauchy–Schwarz Expansion:&lt;/strong&gt; Squaring both sides of the triangle inequality reduces convexity of \(\|x\|_2\) directly to \(x^T y \le \|x\|_2 \|y\|_2\), revealing that equality holds only along nonnegative rays \(y = \alpha x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hessian on \(\mathbb{R}^n \setminus \{0\}\):&lt;/strong&gt; \(\nabla^2 \|x\|_2 = \frac{1}{\|x\|_2}\left(I - \frac{xx^T}{\|x\|_2^2}\right)\) is a scaled orthogonal projection matrix onto \(x^\perp\)—positive semidefinite with eigenvalue \(0\) along the radial ray \(x\) and \(1/\|x\|_2\) orthogonal to \(x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nonsmooth Kink at \(0\):&lt;/strong&gt; Because the cone tip at \(x = 0\) is nondifferentiable, optimizing \(\|x\|_2\) requires subgradients (the unit ball \(\|g\|_2 \le 1\)), foreshadowing nonsmooth optimization.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-inspecting-the-hessian-of-x_2-at-x--3-4t&quot;&gt;Worked example: Inspecting the Hessian of \(\|x\|_2\) at \(x = (3, 4)^T\)&lt;/h3&gt;

&lt;p&gt;Evaluate the gradient and Hessian of \(f(x) = \|x\|_2\) at \(x = (3, 4)^T\) (where \(\|x\|_2 = 5\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the gradient:&lt;/strong&gt;
\(\nabla f(x) = \frac{x}{\|x\|_2} = \begin{pmatrix} 3/5 \\ 4/5 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Hessian \(\nabla^2 f(x) = \frac{1}{\|x\|_2}\left(I - \frac{xx^T}{\|x\|_2^2}\right)\):&lt;/strong&gt;
\(\frac{xx^T}{25} = \frac{1}{25}\begin{pmatrix} 9 &amp;amp; 12 \\ 12 &amp;amp; 16 \end{pmatrix} \implies \nabla^2 f(3, 4) = \frac{1}{5}\begin{pmatrix} 16/25 &amp;amp; -12/25 \\ -12/25 &amp;amp; 9/25 \end{pmatrix} = \frac{1}{125}\begin{pmatrix} 16 &amp;amp; -12 \\ -12 &amp;amp; 9 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute eigenvalues to read the geometry:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Trace \(= \frac{16 + 9}{125} = \frac{1}{5}\), Determinant \(= \frac{16(9) - (-12)^2}{125^2} = 0\).&lt;/li&gt;
      &lt;li&gt;Therefore the eigenvalues are \(\lambda_1 = 1/5 &amp;gt; 0\) (curving upward tangentially around the circle of radius 5) and \(\lambda_2 = 0\) (completely linear along the radial direction \(x = (3, 4)^T\)). Thus \(\nabla^2 f(3, 4) \succeq 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;strong&gt;Euclidean norm&lt;/strong&gt; (also called the \(\ell_2\)-norm) of a vector \(x \in \mathbb{R}^n\) is defined as:&lt;/p&gt;

\[\|x\|_2 = \sqrt{x_1^2 + x_2^2 + \cdots + x_n^2} = \sqrt{x^T x}\]

&lt;p&gt;We will prove that this function is convex using three different methods:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Definition-based proof&lt;/strong&gt; using Jensen’s inequality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second derivative test&lt;/strong&gt; (Hessian analysis)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Triangle inequality approach&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;method-1-definition-based-proof&quot;&gt;Method 1: Definition-Based Proof&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem&lt;/strong&gt;: The Euclidean norm \(f(x) = \|x\|_2\) is convex on \(\mathbb{R}^n\).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Proof&lt;/strong&gt;: 
To prove convexity, we need to show that for any \(x, y \in \mathbb{R}^n\) and \(\theta \in [0,1]\):&lt;/p&gt;

\[\|\theta x + (1-\theta) y\|_2 \leq \theta \|x\|_2 + (1-\theta) \|y\|_2\]

&lt;p&gt;Let \(z = \theta x + (1-\theta) y\). Then:&lt;/p&gt;

\[\begin{align}
\|z\|_2^2 &amp;amp;= \|\theta x + (1-\theta) y\|_2^2 \\
&amp;amp;= (\theta x + (1-\theta) y)^T (\theta x + (1-\theta) y) \\
&amp;amp;= \theta^2 x^T x + 2\theta(1-\theta) x^T y + (1-\theta)^2 y^T y \\
&amp;amp;= \theta^2 \|x\|_2^2 + 2\theta(1-\theta) x^T y + (1-\theta)^2 \|y\|_2^2
\end{align}\]

&lt;p&gt;By the &lt;strong&gt;Cauchy-Schwarz inequality&lt;/strong&gt;: \(x^T y \leq \|x\|_2 \|y\|_2\)&lt;/p&gt;

&lt;p&gt;Therefore:
\(\|z\|_2^2 \leq \theta^2 \|x\|_2^2 + 2\theta(1-\theta) \|x\|_2 \|y\|_2 + (1-\theta)^2 \|y\|_2^2\)&lt;/p&gt;

&lt;p&gt;The right-hand side can be factored as:
\(\theta^2 \|x\|_2^2 + 2\theta(1-\theta) \|x\|_2 \|y\|_2 + (1-\theta)^2 \|y\|_2^2 = (\theta \|x\|_2 + (1-\theta) \|y\|_2)^2\)&lt;/p&gt;

&lt;p&gt;Taking square roots of both sides:
\(\|\theta x + (1-\theta) y\|_2 \leq \theta \|x\|_2 + (1-\theta) \|y\|_2\)&lt;/p&gt;

&lt;p&gt;This proves that the Euclidean norm is convex. \(\square\)&lt;/p&gt;

&lt;h2 id=&quot;method-2-second-derivative-test-hessian-analysis&quot;&gt;Method 2: Second Derivative Test (Hessian Analysis)&lt;/h2&gt;

&lt;p&gt;For twice-differentiable functions, we can use the &lt;strong&gt;second derivative test&lt;/strong&gt;: a function is convex if its Hessian matrix is positive semidefinite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analysis&lt;/strong&gt;: 
The Euclidean norm \(f(x) = \|x\|_2 = \sqrt{x^T x}\) is not differentiable at \(x = 0\). However, for \(x \neq 0\), we can compute:&lt;/p&gt;

\[\frac{\partial f}{\partial x_i} = \frac{x_i}{\|x\|_2}\]

\[\frac{\partial^2 f}{\partial x_i \partial x_j} = \frac{1}{\|x\|_2} \delta_{ij} - \frac{x_i x_j}{\|x\|_2^3}\]

&lt;p&gt;The Hessian matrix is:
\(H = \frac{1}{\|x\|_2} I - \frac{1}{\|x\|_2^3} x x^T = \frac{1}{\|x\|_2} \left( I - \frac{x x^T}{\|x\|_2^2} \right)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verification of positive semidefiniteness&lt;/strong&gt;:
For any vector \(v \in \mathbb{R}^n\):
\(v^T H v = \frac{1}{\|x\|_2} \left( \|v\|_2^2 - \frac{(x^T v)^2}{\|x\|_2^2} \right)\)&lt;/p&gt;

&lt;p&gt;By Cauchy-Schwarz inequality: \((x^T v)^2 \leq \|x\|_2^2 \|v\|_2^2\)&lt;/p&gt;

&lt;p&gt;Therefore: \(\|v\|_2^2 - \frac{(x^T v)^2}{\|x\|_2^2} \geq 0\)&lt;/p&gt;

&lt;p&gt;This shows \(H \succeq 0\), confirming convexity for \(x \neq 0\).&lt;/p&gt;

&lt;h2 id=&quot;method-3-triangle-inequality-approach&quot;&gt;Method 3: Triangle Inequality Approach&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Alternative Proof using Minkowski Inequality&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;The Euclidean norm satisfies the &lt;strong&gt;triangle inequality&lt;/strong&gt;:
\(\|x + y\|_2 \leq \|x\|_2 + \|y\|_2\)&lt;/p&gt;

&lt;p&gt;For convexity, let \(u = \theta x\) and \(v = (1-\theta) y\) where \(\theta \in [0,1]\):
\(\|\theta x + (1-\theta) y\|_2 = \|u + v\|_2 \leq \|u\|_2 + \|v\|_2 = \theta \|x\|_2 + (1-\theta) \|y\|_2\)&lt;/p&gt;

&lt;p&gt;This directly establishes the convexity condition.&lt;/p&gt;

&lt;h2 id=&quot;key-properties-and-applications&quot;&gt;Key Properties and Applications&lt;/h2&gt;

&lt;h3 id=&quot;properties-of-euclidean-norm-convexity&quot;&gt;Properties of Euclidean Norm Convexity&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Strict Convexity&lt;/strong&gt;: The Euclidean norm is actually &lt;strong&gt;strictly convex&lt;/strong&gt; on any line not passing through the origin.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Homogeneity&lt;/strong&gt;: \(\|\alpha x\|_2 = \lvert\alpha\rvert \|x\|_2\) for any scalar \(\alpha\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Subadditivity&lt;/strong&gt;: \(\|x + y\|_2 \leq \|x\|_2 + \|y\|_2\) (Triangle inequality).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h3&gt;

&lt;p&gt;The convexity of the Euclidean norm has important implications:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Least Squares Problems&lt;/strong&gt;: The objective function \(\|Ax - b\|_2^2\) is convex.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Regularization&lt;/strong&gt;: \(\ell_2\)-regularization terms like \(\lambda \|x\|_2\) preserve convexity.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Constrained Optimization&lt;/strong&gt;: Norm constraints \(\|x\|_2 \leq r\) define convex feasible sets.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;We have proven that the Euclidean norm is convex using three different approaches:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Direct definition&lt;/strong&gt;: Using Jensen’s inequality and Cauchy-Schwarz&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second derivative test&lt;/strong&gt;: Showing the Hessian is positive semidefinite&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Triangle inequality&lt;/strong&gt;: Leveraging the fundamental norm property&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This convexity property is fundamental in optimization theory and has wide-ranging applications in machine learning, signal processing, and numerical analysis.&lt;/p&gt;

&lt;p&gt;The interactive visualization above demonstrates how the convexity condition \(\|\theta x + (1-\theta) y\|_2 \leq \theta \|x\|_2 + (1-\theta) \|y\|_2\) holds for any choice of points and convex combination parameter \(\theta\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-06 Convexity with respect to generalized inequalities</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_06_convexity_with_respect_to_generalized_inequalities/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_06_convexity_with_respect_to_generalized_inequalities</id>
   <content type="html">&lt;p&gt;When optimizing over symmetric matrices (as in covariance estimation, control theory, or quantum information), the objective or constraint map \(F(X)\) itself outputs a &lt;em&gt;matrix&lt;/em&gt; rather than a scalar. How do we define whether \(F(X) = X^2\) is “convex” when comparing matrices? By replacing \(\le\) in Jensen’s inequality with the cone inequality \(\preceq_K\)—and the dual characterization shows that \(K\)-convexity holds if and only if every nonnegative scalar projection \(\lambda^T F(x)\) (\(\lambda \succeq_{K^*} 0\)) is an ordinary scalar convex function.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-extending-convexity-to-vector--matrix-maps&quot;&gt;Key ideas: Extending Convexity to Vector &amp;amp; Matrix Maps&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(K\)-Monotonicity:&lt;/strong&gt; \(f: \mathbb{R}^n \to \mathbb{R}\) is \(K\)-nondecreasing if \(x \preceq_K y \implies f(x) \le f(y)\); for differentiable \(f\), this holds iff \(\nabla f(x) \succeq_{K^*} 0\) everywhere.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(K\)-Convexity:&lt;/strong&gt; A map \(f: \mathbb{R}^n \to \mathbb{R}^m\) is \(K\)-convex (for proper cone \(K \subseteq \mathbb{R}^m\)) iff \(f(\theta x + (1-\theta)y) \preceq_K \theta f(x) + (1-\theta)f(y)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Scalarization Test:&lt;/strong&gt; \(f\) is \(K\)-convex iff for &lt;em&gt;every&lt;/em&gt; \(\lambda \succeq_{K^*} 0\), the scalar function \(\lambda^T f(x)\) is convex—turning matrix-convexity proofs into routine scalar convexity checks!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrix Convexity (\(\mathbb{S}_+^n\)-Convexity):&lt;/strong&gt; Lets us prove \(F(X) = X^2\) and \(F(X) = X^{-1}\) (on \(\mathbb{S}_{++}^n\)) are matrix-convex, unlocking Schur-complement LMI reformulations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-proving-fx--x2-is-matrix-convex-on-mathbbs2&quot;&gt;Worked example: Proving \(F(X) = X^2\) Is Matrix-Convex on \(\mathbb{S}^2\)&lt;/h3&gt;

&lt;p&gt;Verify that \(F(X) = X^2\) is \(\mathbb{S}_+^2\)-convex on symmetric \(2 \times 2\) matrices.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Apply the dual characterization:&lt;/strong&gt; For any vector \(v \in \mathbb{R}^2\), the rank-1 matrix \(W = vv^T \in \mathbb{S}_+^2\) defines a nonnegative dual functional:
\(\text{tr}(W F(X)) = v^T X^2 v = (Xv)^T (Xv) = \|Xv\|_2^2.\)
Because \(X \mapsto Xv\) is linear in \(X\) and \(\|\cdot\|_2^2\) is convex, \(X \mapsto \|Xv\|_2^2\) is convex for every \(v \in \mathbb{R}^2\) (and hence for every \(W \succeq 0\), a nonnegative sum of rank-1 terms). Thus \(F(X) = X^2\) is &lt;strong&gt;matrix-convex&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Concrete numerical check:&lt;/strong&gt; Take \(X = \text{diag}(1, 0)\), \(Y = \text{diag}(0, 1)\), and \(\theta = 0.5\):
    &lt;ul&gt;
      &lt;li&gt;\(F(0.5X + 0.5Y) = \text{diag}(0.5, 0.5)^2 = \text{diag}(0.25, 0.25)\).&lt;/li&gt;
      &lt;li&gt;\(0.5 F(X) + 0.5 F(Y) = 0.5\,\text{diag}(1, 0) + 0.5\,\text{diag}(0, 1) = \text{diag}(0.5, 0.5)\).&lt;/li&gt;
      &lt;li&gt;Difference: \(\text{diag}(0.5, 0.5) - \text{diag}(0.25, 0.25) = \text{diag}(0.25, 0.25) \succeq 0 \quad \checkmark\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section discusses convexity with respect to generalized inequalities, extending the concept of convexity beyond standard real-valued functions.&lt;/p&gt;

&lt;p&gt;In spaces other than \(\mathbb{R}\), we use the definition of cones for generalized inequality expressions that extend the ordering concept commonly used in \(\mathbb{R}\) space (see &lt;a href=&quot;/contents/en/chapter02/02_01_04_Convex_cone/&quot;&gt;02-01-04&lt;/a&gt;). In this section, we examine the concepts of monotonicity and convexity that extend beyond \(\mathbb{R}\) space using the concept of cones.&lt;/p&gt;

&lt;h2 id=&quot;monotonicity-with-respect-to-a-generalized-inequality&quot;&gt;Monotonicity with respect to a generalized inequality&lt;/h2&gt;

&lt;p&gt;Suppose \(K \subseteq \mathbb{R}^n\) is a proper cone represented by \(\preceq_K\). A convex cone \(K \subseteq \mathbb{R}^n\) is a &lt;strong&gt;proper cone&lt;/strong&gt; if it satisfies the following conditions:&lt;/p&gt;

&lt;p&gt;• \(K\) is closed (contains its boundary)
• \(K\) is solid (has nonempty interior)
• \(K\) is pointed (contains no line)&lt;/p&gt;

&lt;p&gt;We define &lt;strong&gt;\(K\)-nondecreasing&lt;/strong&gt; as follows:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \mapsto \mathbb{R}\) is \(K\)-nondecreasing if \(x \preceq_K y \Rightarrow f(x) \leq f(y)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Also, when the following condition is satisfied, we say it is &lt;strong&gt;\(K\)-increasing&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \mapsto \mathbb{R}\) is \(K\)-increasing if \(x \preceq_K y, x \neq y \Rightarrow f(x) &amp;lt; f(y)\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;gradient-conditions-for-monotonicity&quot;&gt;Gradient conditions for monotonicity&lt;/h3&gt;

&lt;p&gt;For a differentiable function \(f : \mathbb{R} \mapsto \mathbb{R}\) to be nondecreasing on a convex (i.e., interval) domain means that \(f&apos;(x) \geq 0\) for all \(x \in \text{dom}f\), and if \(f&apos;(x) &amp;gt; 0\) for all \(x \in \text{dom}f\), then it is increasing. Similarly, monotonicity can be expressed as an extended concept in generalized inequalities.&lt;/p&gt;

&lt;p&gt;When the domain is convex, a differentiable function \(f\) being \(K\)-nondecreasing means satisfying the following equation. Note that unlike simple scalars, the gradient \(\nabla f(x)\) must be nonnegative in the dual inequality.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;A differentiable function \(f\) is \(K\)-nondecreasing \(\Longleftrightarrow\) \(\nabla f(x) \succeq_{K^*} 0\) for all \(x \in \text{dom}f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the following condition is satisfied, \(f\) is called &lt;strong&gt;\(K\)-increasing&lt;/strong&gt;. As with scalars, the converse does not hold.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\nabla f(x) \succ_{K^*} 0\) for all \(x \in \text{dom}f\) \(\Rightarrow\) \(f\) is \(K\)-increasing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;convexity-with-respect-to-generalized-inequality&quot;&gt;Convexity with respect to generalized inequality&lt;/h3&gt;

&lt;p&gt;Let \(K \subseteq \mathbb{R}^m\) be a proper cone associated with the generalized inequality \(\preceq_K\).
Then, if \(f : \mathbb{R}^n \mapsto \mathbb{R}^m\) is called &lt;strong&gt;\(K\)-convex&lt;/strong&gt; for all \(x, y\) and \(0 \leq \theta \leq 1\), the following inequality holds:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \mapsto \mathbb{R}^m\) is \(K\)-convex \(\Rightarrow\) \(f(\theta x + (1 - \theta) y) \preceq_K \theta f(x) + (1 - \theta) f(y)\) with \(0 &amp;lt; \theta &amp;lt; 1\) for all \(x, y\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Also, the condition for &lt;strong&gt;strictly \(K\)-convex&lt;/strong&gt; is as follows:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(\theta x + (1 - \theta) y) \prec_K \theta f(x) + (1 - \theta) f(y)\) for all \(x \neq y\) and \(0 &amp;lt; \theta &amp;lt; 1\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When \(m = 1\) and \(K = \mathbb{R}_+\), this becomes the inequality that satisfies the general convexity we have discussed earlier.&lt;/p&gt;

&lt;h3 id=&quot;dual-characterization-of-k-convexity&quot;&gt;Dual characterization of \(K\)-convexity&lt;/h3&gt;

&lt;p&gt;\(f\) being \(K\)-convex means that the (real-valued) function \(w^T f\) is convex for all \(w \succeq_{K^*} 0\). \(f\) being strictly \(K\)-convex means that the (real-valued) function \(w^T f\) is strictly convex for all \(w \succeq_{K^*} 0\). This follows from the definition and properties of dual inequalities.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3 id=&quot;differentiable-k-convex-functions&quot;&gt;Differentiable \(K\)-convex functions&lt;/h3&gt;

&lt;p&gt;If a differentiable function \(f\) is \(K\)-convex and the function domain is convex, then the following equation holds:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(y) \succeq_K f(x) + Df(x)(y - x)\) for all \(x, y \in \text{dom}f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, \(Df(x) \in \mathbb{R}^{m \times n}\) is the derivative or Jacobian matrix of \(f\) at point \(x\).&lt;/p&gt;

&lt;p&gt;If \(f\) is strictly \(K\)-convex and the function domain is convex, then the following equation holds:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(y) \succ_K f(x) + Df(x)(y - x)\) for all \(x, y \in \text{dom}f\), \(x \neq y\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;composition-theorem&quot;&gt;Composition theorem&lt;/h3&gt;

&lt;p&gt;Many results from composition can be generalized to \(K\)-convexity.
For example, if \(g : \mathbb{R}^n \mapsto \mathbb{R}^p\) is \(K\)-convex, \(h : \mathbb{R}^p \rightarrow \mathbb{R}\) is convex, and the extended-value extension \(\widetilde{h}\) of \(h\) is \(K\)-nondecreasing, then \(h \circ g\) is convex. This generalizes the fact that the composition of a convex function with a nondecreasing convex function is convex.
(The condition that \(\widetilde{h}\) is \(K\)-nondecreasing means that \(\text{dom}h - K = \text{dom}h\).)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-05 Log-concave and log-convex functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_05_log_concave_and_log_convex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_05_log_concave_and_log_convex_functions</id>
   <content type="html">&lt;p&gt;Look at the familiar bell curve of a Gaussian probability density: it bends downward near the peak and upward in the tails, so it is &lt;em&gt;neither&lt;/em&gt; convex nor concave. Yet take its natural logarithm and the bell curve turns into a clean downward-opening parabola \(-\frac{1}{2}x^2 + c\)! That property—&lt;strong&gt;log-concavity&lt;/strong&gt;—is the hidden reason maximum likelihood estimation, Bayesian MAP inference, and Gaussian chance constraints yield tractable convex optimization problems.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-log-concave-and-log-convex-structure&quot;&gt;Key ideas: Log-Concave and Log-Convex Structure&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Definitions (\(f &amp;gt; 0\)):&lt;/strong&gt; \(f\) is &lt;em&gt;log-concave&lt;/em&gt; if \(\log f\) is concave (equivalently \(f(\theta x + (1-\theta)y) \ge f(x)^\theta f(y)^{1-\theta}\)); \(f\) is &lt;em&gt;log-convex&lt;/em&gt; if \(\log f\) is convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-Order Check:&lt;/strong&gt; Twice-differentiable \(f &amp;gt; 0\) is log-concave iff \(f(x)\nabla^2 f(x) \preceq \nabla f(x)\nabla f(x)^T\) (in 1D, \(f&apos;&apos; f \le (f&apos;)^2\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closure Under Products &amp;amp; Marginals:&lt;/strong&gt; Products of log-concave functions stay log-concave (independent likelihoods!), and by Prékopa’s theorem, &lt;em&gt;integrating out&lt;/em&gt; variables (marginal densities and Gaussian CDFs \(\Phi(x)\)) preserves log-concavity!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Log-Convexity Strength:&lt;/strong&gt; Every log-convex function is automatically convex (since \(e^u\) is convex and increasing), and sums of log-convex functions remain log-convex (powering geometric programming).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-the-gaussian-density-is-log-concave-yet-nonconcave&quot;&gt;Worked example: Why the Gaussian Density Is Log-Concave Yet Nonconcave&lt;/h3&gt;

&lt;p&gt;Examine the standard normal density \(f(x) = \frac{1}{\sqrt{2\pi}} e^{-x^2/2}\) on \(\mathbb{R}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check ordinary concavity via \(f&apos;&apos;(x)\):&lt;/strong&gt;
\(f&apos;(x) = -x f(x), \qquad f&apos;&apos;(x) = (x^2 - 1)f(x).\)
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;For $$&lt;/td&gt;
              &lt;td&gt;x&lt;/td&gt;
              &lt;td&gt;&amp;lt; 1\(,\)f’‘(x) &amp;lt; 0$$ (concave near the peak).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;For \(|x| &amp;gt; 1\), \(f&apos;&apos;(x) &amp;gt; 0\) (convex in the tails!).
Thus \(f(x)\) is &lt;strong&gt;neither convex nor concave&lt;/strong&gt; globally.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take the logarithm and differentiate twice:&lt;/strong&gt;
\(\log f(x) = -\frac{1}{2}\ln(2\pi) - \frac{1}{2}x^2 \implies (\log f(x))&apos; = -x \implies (\log f(x))&apos;&apos; = -1 &amp;lt; 0 \text{ everywhere}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimization takeaway:&lt;/strong&gt; Maximizing a product of independent Gaussian densities is nonconcave in raw probability space, but taking \(\log\) immediately yields a strictly concave quadratic!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section introduces log-concave and log-convex functions, which are important in probability, statistics, and optimization.&lt;/p&gt;

&lt;h2 id=&quot;definition&quot;&gt;Definition&lt;/h2&gt;

&lt;p&gt;The definitions of log-concave and log-convex functions are as follows.&lt;/p&gt;

&lt;h3 id=&quot;f--mathbbrn-rightarrow-mathbbr-is-logarithmically-concave-or-log-concave&quot;&gt;\(f : \mathbb{R}^n \rightarrow \mathbb{R}\) is Logarithmically concave or log-concave&lt;/h3&gt;
&lt;p&gt;If \(f(x) &amp;gt; 0\) for all \(x \in \text{dom}f\) and \(\log f\) is concave, then \(f : \mathbb{R}^n \rightarrow \mathbb{R}\) is called logarithmically concave or log-concave.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) is log-concave for \(f(x) &amp;gt; 0\) for all \(x \in \text{dom}f\) : &lt;br /&gt;
\(f(\theta x + (1 - \theta) y) \geq f(x)^\theta f(y)^{1-\theta}\) for \(0 \leq \theta \leq 1\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;f--mathbbrn-mapsto-mathbbr-is-logarithmically-convex-or-log-convex&quot;&gt;\(f : \mathbb{R}^n \mapsto \mathbb{R}\) is Logarithmically convex or log-convex&lt;/h3&gt;
&lt;p&gt;If \(f(x) &amp;gt; 0\) for all \(x \in \text{dom}f\) and \(\log f\) is convex, then \(f : \mathbb{R}^n \mapsto \mathbb{R}\) is called logarithmically convex or log-convex. Therefore, if \(f\) is log-convex, then \(1/f\) is log-concave.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) is log-convex for \(f(x) &amp;gt; 0\) for all \(x \in \text{dom}f\) \(\Longleftrightarrow \frac{1}{f}\) is log-concave.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is sometimes convenient to allow \(f\) values to be 0, in which case \(\log f(x) = -\infty\). In such cases, if the extended-value function \(\log f\) is concave, then \(f\) can be called log-concave.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log-convex functions and log-concave functions are quasiconvex and quasiconcave, respectively, because the logarithm is monotonically increasing.&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&quot;affine-function&quot;&gt;Affine function&lt;/h3&gt;
&lt;p&gt;If \(f\) is defined as follows, then it is log-concave.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x) = a^Tx + b\) on \(\{x \mid a^Tx + b &amp;gt; 0\}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;powers&quot;&gt;Powers&lt;/h3&gt;
&lt;p&gt;\(f(x) = x^a\) on \(\mathbb{R}_{++}\) is log-convex when \(a \leq 0\) and log-concave when \(a \geq 0\).&lt;/p&gt;

&lt;h3 id=&quot;exponentials&quot;&gt;Exponentials&lt;/h3&gt;
&lt;p&gt;\(f(x) = e^{ax}\) is both log-convex and log-concave.&lt;/p&gt;

&lt;h3 id=&quot;the-cumulative-distribution-function-of-a-gaussian-density&quot;&gt;The cumulative distribution function of a Gaussian density&lt;/h3&gt;
&lt;p&gt;\(\Phi(x) = \frac{1}{ \sqrt{2 \pi } }  \int_ {-\infty} ^x e^{-u^2/2} du\) is log-concave.&lt;/p&gt;

&lt;h3 id=&quot;gamma-function&quot;&gt;Gamma function&lt;/h3&gt;
&lt;p&gt;\(\Gamma (x) = \int_0^\infty u^{x-1}e^{-u} du\)
is log-convex for \(x \geq 1\).&lt;/p&gt;

&lt;h3 id=&quot;determinant&quot;&gt;Determinant&lt;/h3&gt;
&lt;p&gt;\(\det X\) is log-concave on \(S^n_{++}\).&lt;/p&gt;

&lt;h3 id=&quot;determinant-over-trace&quot;&gt;Determinant over trace&lt;/h3&gt;
&lt;p&gt;\(\det X / \text{tr} X\) is log-concave on \(S^n_{++}\).&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 id=&quot;properties&quot;&gt;Properties&lt;/h2&gt;

&lt;h3 id=&quot;twice-differentiable-log-convex--concave-functions&quot;&gt;Twice differentiable log-convex / concave functions&lt;/h3&gt;
&lt;p&gt;If \(f\) is twice differentiable and \(\text{dom} f\) is convex, then the following equation holds:&lt;br /&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\nabla ^2 \log f(x) = \frac{1}{f(x)} \nabla ^2f(x) - \frac{1}{f(x)^2}\nabla f(x) \nabla f(x)^T\]
&lt;/blockquote&gt;

&lt;p&gt;\(f\) is log-convex \(\Longleftrightarrow\) \(f(x) \nabla ^2 f(x) \succeq \nabla f(x)\nabla f(x)^T\) for all \(x \in \text{dom} f\), and &lt;br /&gt;
\(f\) is log-concave \(\Longleftrightarrow\) \(f(x) \nabla ^2 f(x) \preceq \nabla f(x)\nabla f(x)^T\) for all \(x \in \text{dom} f\).&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3 id=&quot;multiplication&quot;&gt;Multiplication&lt;/h3&gt;
&lt;p&gt;Log-convexity and log-concavity are closed under multiplication and positive scaling. 
If \(f\) and \(g\) are log-concave, then the pointwise product \(h(x) = f(x)g(x)\) is also log-concave. 
This is because \(\log h(x) = \log f(x) + \log g(x)\), and both \(\log f(x)\) and \(\log g(x)\) are concave functions.&lt;/p&gt;

&lt;h3 id=&quot;addition-and-integration&quot;&gt;Addition and Integration&lt;/h3&gt;
&lt;p&gt;In general, the sum of log-concave functions is not log-concave. However, log-convexity is preserved under addition.
For example, let \(f\) and \(g\) be log-convex functions, i.e., \(F = \log f\) and \(G = \log g\) are convex.
By the composition rules for convex functions, the following holds:&lt;br /&gt;&lt;/p&gt;

&lt;blockquote&gt;
\[\log(exp F + exp G) = \log(f + g)\]
&lt;/blockquote&gt;

&lt;p&gt;This is convex. (The left side is convex because: 1. log-convex functions are convex, 2. applying the exponential function to convex functions preserves convexity, 3. the sum of convex functions is convex, and 4. the logarithm of convex functions is convex.
Therefore, the entire result is convex.) In conclusion, the sum of two log-convex functions is log-convex.&lt;/p&gt;

&lt;p&gt;Generalizing this, if \(f(x, y)\) is log-convex for each \(y \in C\), then \(g(x)\) is log-convex.&lt;/p&gt;
&lt;blockquote&gt;
\[g(x) = \int_C^{} f(x,y) dy\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;integration-of-log-concave-functions&quot;&gt;Integration of log-concave functions&lt;/h3&gt;
&lt;p&gt;In certain cases, log-concavity is also preserved under integration. If \(f : \mathbb{R}^n \times \mathbb{R}^m \mapsto \mathbb{R}\) is log-concave, then \(g(x)\) is a log-concave function for \(x \in \mathbb{R}^n\).&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \mapsto \mathbb{R}\) is log-concave \(\Longrightarrow\) \(g(x) = \int_{}^{} f(x,y) dy\) is log-concave , \(x \in \mathbb{R}^n\) for each \(y \in C\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Based on this, we can confirm that the marginal distribution of a log-concave probability density is log-concave.&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Log-concavity is also closed under convolution operations. If \(f\) and \(g\) are log-concave on \(\mathbb{R}^n\), then their convolution is also log-concave.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\), \(g\) are log-concave on \(\mathbb{R}^n \Longrightarrow (f \ast g)(x) = \int_{}^{} f(x-y)g(y) dy\) is log-concave.&lt;br /&gt;&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04-04 Operations that preserve quasiconvexity</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_04_04_operations_that_preserve_quasiconvexity/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_04_04_operations_that_preserve_quasiconvexity</id>
   <content type="html">&lt;p&gt;Because adding two quasiconvex functions can easily create a double-humped non-quasiconvex landscape, you need a different set of construction rules than for ordinary convexity. Most importantly, representing a quasiconvex function through a 1-parameter family of &lt;em&gt;convex&lt;/em&gt; functions \(\phi_t(x) \le 0\) turns quasiconvex optimization directly into a sequence of standard convex feasibility checks via bisection.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-preserving-and-solving-quasiconvexity&quot;&gt;Key ideas: Preserving and Solving Quasiconvexity&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nonnegative Weighted Maximum:&lt;/strong&gt; \(\max_i w_i f_i(x)\) (\(w_i \ge 0\)) and arbitrary pointwise suprema preserve quasiconvexity—sublevel sets simply intersect!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Composition Rules:&lt;/strong&gt; Composing a quasiconvex function with an affine map or a &lt;em&gt;nondecreasing&lt;/em&gt; scalar function \(h\) preserves quasiconvexity (no convexity required of \(h\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Partial Minimization:&lt;/strong&gt; \(g(x) = \inf_{y \in C} f(x, y)\) is quasiconvex whenever \(f(x, y)\) is jointly quasiconvex and \(C\) is a convex set.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Representation (\(f(x) \le t \iff \phi_t(x) \le 0\)):&lt;/strong&gt; Replacing a quasiconvex objective with a family of convex inequalities \(\phi_t(x) \le 0\) (nonincreasing in \(t\)) is the exact bridge that lets convex solvers minimize quasiconvex objectives via bisection.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-bisection-via-a-convex-family-phi_tx&quot;&gt;Worked example: Bisection via a Convex Family \(\phi_t(x)\)&lt;/h3&gt;

&lt;p&gt;Minimize the quasiconvex linear-fractional objective \(f(x) = \frac{x + 3}{x + 1}\) over the convex interval \(x \in [0, 4]\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Construct the convex representing family \(\phi_t(x)\):&lt;/strong&gt; For \(x \ge 0\) (so \(x + 1 &amp;gt; 0\)),
\(f(x) \le t \iff x + 3 \le t(x + 1) \iff \phi_t(x) = (1 - t)x + (3 - t) \le 0.\)
For each fixed \(t\), \(\phi_t(x)\) is affine (hence convex) in \(x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bracket the optimum with convex feasibility checks:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Test \(t = 2\): \(\phi_2(x) = -x + 1 \le 0 \iff x \ge 1\). Since \([1, 4] \neq \emptyset\), \(t = 2\) is &lt;strong&gt;feasible&lt;/strong&gt; (\(p^* \le 2\)).&lt;/li&gt;
      &lt;li&gt;Test \(t = 1.2\): \(\phi_{1.2}(x) = -0.2x + 1.8 \le 0 \iff x \ge 9\). Since \([9, \infty) \cap [0, 4] = \emptyset\), \(t = 1.2\) is &lt;strong&gt;infeasible&lt;/strong&gt; (\(p^* &amp;gt; 1.2\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Identify the exact threshold:&lt;/strong&gt; Feasibility holds on \([0, 4]\) iff \(\frac{3 - t}{t - 1} \le 4 \iff 3 - t \le 4t - 4 \iff 5t \ge 7 \iff t \ge 1.4\), giving \(p^* = 1.4\) attained at \(x^* = 4\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section discusses operations that preserve the quasiconvexity of functions.&lt;/p&gt;

&lt;h2 id=&quot;nonnegative-weighted-maximum&quot;&gt;Nonnegative weighted maximum&lt;/h2&gt;

&lt;p&gt;When \(f\) is a quasiconvex function, the nonnegative weighted maximum \(f\) is quasiconvex.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f = \max\{w_1f_1, ... ,w_mf_m\}\) with \(w_i \geq 0\) is quasiconvex&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This concept can be extended as follows:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x) = \sup_{y \in C}(w(y)g(x,y))\) with \(w(y) \geq 0\), 
where \(g(x,y)\) is quasiconvex in \(x\) for each \(y\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;composition&quot;&gt;Composition&lt;/h2&gt;

&lt;p&gt;If \(g : \mathbb{R}^n \mapsto \mathbb{R}\) is quasiconvex and \(h : \mathbb{R} \mapsto \mathbb{R}\) is nondecreasing, then the composition \(f\) satisfies quasiconvexity.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f = h \circ g\) is quasiconvex if \(h\) is nondecreasing and \(g\) is quasiconvex.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Composing a quasiconvex function with affine or linear-fractional transformations results in a quasiconvex function.
If \(f\) is quasiconvex, then \(g(x) = f(Ax + b)\) is also quasiconvex, and \(\tilde{g}(x) = f((Ax + b)/(c^Tx + d))\) is also quasiconvex on the set \(\{x \mid c^Tx + d &amp;gt; 0, (Ax + b)/(c^Tx + d) \in \text{dom}f\}\).&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;minimization&quot;&gt;Minimization&lt;/h2&gt;

&lt;p&gt;If \(f(x, y)\) satisfies quasiconvexity and \(C\) is a convex set, then the following condition holds:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(g(x) = \inf_{y \in C} f(x,y)\) is quasiconvex if \(f\) is quasiconvex in \((x,y)\) and \(C\) is a convex set.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;representation-via-family-of-convex-functions&quot;&gt;Representation via family of convex functions&lt;/h2&gt;

&lt;p&gt;The sublevel sets of a quasiconvex function \(f\) can be represented by inequalities of convex functions. A family of convex functions is \(\phi_t : \mathbb{R}^n \mapsto \mathbb{R}\) for \(t \in \mathbb{R}\), defined as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[f(x) \leq t \Longleftrightarrow \phi_t(x) \leq 0\]
&lt;/blockquote&gt;

&lt;p&gt;That is, the \(t\)-sublevel set of quasiconvex function \(f(x)\) becomes the 0-sublevel set of convex function \(\phi_t\). Here, \(t\) represents the index of convex function \(\phi\). For all \(x \in \mathbb{R}^n\), the following is satisfied:&lt;/p&gt;
&lt;blockquote&gt;
\[\phi_t(x) \leq 0 \Rightarrow \phi_s(x) \leq 0 \text{ for } s \geq t\]
&lt;/blockquote&gt;

</content>
 </entry>
 
 <entry>
   <title>03-04-03 Differentiable quasiconvex functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_04_03_differentiable_quasiconvex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_04_03_differentiable_quasiconvex_functions</id>
   <content type="html">&lt;p&gt;For a smooth convex function, \(\nabla f(x^*) = 0\) is a ironclad certificate of global optimality. For a smooth &lt;em&gt;quasiconvex&lt;/em&gt; function, that shortcut breaks: \(f(x) = x^3\) has \(f&apos;(0) = 0\) yet \(x = 0\) is an inflection point, not a minimum! Understanding the exact first- and second-order conditions for differentiable quasiconvex functions reveals what the gradient and Hessian &lt;em&gt;do&lt;/em&gt; guarantee—namely, that \(\nabla f(x)\) defines a supporting hyperplane to the sublevel set at \(x\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-calculus-of-smooth-quasiconvex-functions&quot;&gt;Key ideas: Calculus of Smooth Quasiconvex Functions&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Condition:&lt;/strong&gt; Differentiable \(f\) is quasiconvex iff \(f(y) \le f(x) \implies \nabla f(x)^T(y - x) \le 0\)—geometrically, \(\nabla f(x)\) points outward from the sublevel set \(\{y : f(y) \le f(x)\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why \(\nabla f(x^*) = 0\) Is Insufficient:&lt;/strong&gt; When \(\nabla f(x^*) = 0\), the implication \(f(y) \le f(x^*) \implies 0 \le 0\) becomes vacuous, allowing horizontal inflection points like \(x = 0\) for \(x^3\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-Order Condition (Tangent-Space Curvature):&lt;/strong&gt; Twice-differentiable \(f\) is quasiconvex only if \(y^T \nabla f(x) = 0 \implies y^T \nabla^2 f(x) y \ge 0\)—curvature only needs to be nonnegative along directions &lt;em&gt;tangent&lt;/em&gt; to the level surface!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;1D Curvature Simplification:&lt;/strong&gt; On \(\mathbb{R}\), \(f&apos;(x) = 0 \implies f&apos;&apos;(x) \ge 0\), ruling out local maxima while still permitting concave slopes wherever \(f&apos;(x) \neq 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-checking-first-order-quasiconvexity-and-the-stationary-point-trap&quot;&gt;Worked example: Checking First-Order Quasiconvexity and the Stationary-Point Trap&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Verify the first-order condition on \(f(x) = \ln x\) (\(x &amp;gt; 0\)):&lt;/strong&gt; Pick \(x = 2\) and \(y = 1\).
    &lt;ul&gt;
      &lt;li&gt;Check hypothesis: \(f(1) = 0 \le \ln 2 \approx 0.693 = f(2)\).&lt;/li&gt;
      &lt;li&gt;Check inner product: \(f&apos;(2)(1 - 2) = \frac{1}{2}(-1) = -0.5 \le 0 \quad \checkmark\).
Notice \(f&apos;&apos;(2) = -1/4 &amp;lt; 0\) (concave!), yet \(f\) still satisfies the quasiconvex second-order condition vacuously because \(f&apos;(x) = 1/x \neq 0\) everywhere!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Illustrate the stationary-point trap on \(g(x) = x^3\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g&apos;(x) = 3x^2 \ge 0\) everywhere, so \(g(y) \le g(x) \iff y \le x \implies g&apos;(x)(y - x) \le 0\) (quasiconvex).&lt;/li&gt;
      &lt;li&gt;At \(x = 0\), \(g&apos;(0) = 0\) and \(g&apos;&apos;(0) = 0 \ge 0\), yet \(g(-1) = -1 &amp;lt; 0 = g(0)\), proving \(\nabla g(x) = 0\) does &lt;strong&gt;not&lt;/strong&gt; guarantee optimality for quasiconvex functions.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section discusses the properties and characterizations of differentiable quasiconvex functions.&lt;/p&gt;

&lt;h2 id=&quot;first-order-conditions&quot;&gt;First-order conditions&lt;/h2&gt;
&lt;p&gt;Let \(f : \mathbb{R}^n \rightarrow \mathbb{R}\) be a differentiable function. If \(\text{dom}f\) is convex and the following condition is satisfied, then \(f\) is quasiconvex.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) is quasiconvex \(\iff\) \(f(y) \leq f(x) \Rightarrow \nabla f(x)^T(y-x) \leq 0\) for all \(x, y \in \text{dom}f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/3.12_Three_level_curves_OV6vtPq.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Three level curves of a quasiconvex function \(f\). \(\nabla f(x)\) is the normal vector that defines the supporting hyperplane of the sublevel set \(\{z \mid f(z) \leq f(x)\}\) at \(x\).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first-order condition for quasiconvexity appears similar to the first-order characterization of convexity (see &lt;a href=&quot;/contents/en/chapter03/03_01_03_key_properties_of_convex_functions/&quot;&gt;03-01-03&lt;/a&gt;), but there are important differences. For example, if \(f\) is convex and \(\nabla f(x) = 0\), then \(x\) is a global minimizer of \(f\), but this does not always hold for quasiconvex functions.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 id=&quot;second-order-conditions&quot;&gt;Second-order conditions&lt;/h2&gt;

&lt;p&gt;When \(f\) is twice differentiable, second-order conditions apply. If \(f\) is quasiconvex, then for all \(x \in \text{dom}f\) and all \(y \in \mathbb{R}^n\), the following holds:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) is quasiconvex, \(y^T \nabla f(x) = 0 \Longrightarrow y^T \nabla^2 f(x)y \geq 0\) for all \(x \in \text{dom} f\), all \(y \in \mathbb{R}^n\) &lt;br /&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For quasiconvex functions on \(\mathbb{R}\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f\) is quasiconvex, \(f&apos;(x) = 0 \Rightarrow f&apos;&apos;(x) \geq 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is, if there exists any point with zero slope, the second derivative value is non-negative. Returning to \(\mathbb{R}^n\), the second-order condition also satisfies the following properties:&lt;/p&gt;

&lt;p&gt;1) When \(\nabla f(x) = 0\), we must always have \(\nabla^2f(x) \succeq 0\).
2) If \(\nabla f(x) \neq 0\), then \(y^T \nabla f(x) = 0 \Rightarrow y^T \nabla^2 f(x)y \geq 0\), where \(\nabla^2 f(x)\) acts as the Hessian matrix and is positive semidefinite on the \((n-1)\)-dimensional subspace \(\nabla f(x)^\perp\).&lt;/p&gt;

&lt;p&gt;(The \((n-1)\)-dimensional subspace \(\nabla f(x)^\perp\) means the \((n-1)\)-dimensional subspace orthogonal to \(\nabla f(x)\). It is \((n-1)\)-dimensional because \(\nabla f(x)\) is the gradient of an \(n\)-dimensional function \(f\), reducing the dimension by one.)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04-02 Basic properties of quasiconvex functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_04_02_basic_properties_of_quasiconvex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_04_02_basic_properties_of_quasiconvex_functions</id>
   <content type="html">&lt;p&gt;With ordinary convex functions, blending two points always stays below the &lt;em&gt;average&lt;/em&gt; of their heights; with quasiconvex functions, blending two points only stays below the &lt;em&gt;higher&lt;/em&gt; of their two heights. That subtle relaxation—Modified Jensen’s inequality—explains why quasiconvex functions can have S-shaped inflections and flat shelves while still forbidding multiple separated valleys.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-structural-properties-of-quasiconvex-functions&quot;&gt;Key ideas: Structural Properties of Quasiconvex Functions&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Modified Jensen’s Inequality:&lt;/strong&gt; \(f\) is quasiconvex iff \(f(\theta x + (1-\theta)y) \le \max\{f(x), f(y)\}\) for all \(x, y \in \text{dom}\,f\) and \(\theta \in [0, 1]\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;1D Characterization:&lt;/strong&gt; A function on \(\mathbb{R}\) is quasiconvex iff it is nondecreasing, nonincreasing, or nonincreasing up to some threshold \(c\) and nondecreasing after \(c\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quasiconvexity vs. Local Minima:&lt;/strong&gt; Warning! Unlike convex functions, a &lt;em&gt;local&lt;/em&gt; minimum of a quasiconvex function on a flat plateau is NOT guaranteed to be a global minimum unless the function is &lt;em&gt;strictly&lt;/em&gt; quasiconvex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sum Failure:&lt;/strong&gt; Unlike convex functions, the sum of two quasiconvex functions is generally &lt;strong&gt;not&lt;/strong&gt; quasiconvex—you must use maxima or monotone compositions instead.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-modified-jensen-succeeds-where-ordinary-jensen-fails&quot;&gt;Worked example: Modified Jensen Succeeds Where Ordinary Jensen Fails&lt;/h3&gt;

&lt;p&gt;Test \(f(x) = x^3\) (monotone increasing on \(\mathbb{R}\), hence quasiconvex) at \(x = -2\), \(y = 1\), and \(\theta = 0.5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate endpoints and midpoint:&lt;/strong&gt;
\(f(-2) = -8, \qquad f(1) = 1, \qquad m = 0.5(-2) + 0.5(1) = -0.5 \implies f(-0.5) = -0.125.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test Modified Jensen’s inequality:&lt;/strong&gt;
\(f(-0.5) = -0.125 \le \max\{f(-2), f(1)\} = \max\{-8, 1\} = 1 \quad \checkmark\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Contrast with ordinary Jensen’s inequality:&lt;/strong&gt;
\(0.5 f(-2) + 0.5 f(1) = 0.5(-8) + 0.5(1) = -3.5.\)
Since \(f(-0.5) = -0.125 &amp;gt; -3.5\), ordinary Jensen fails (\(x^3\) is concave on \(x &amp;lt; 0\)), cleanly illustrating why quasiconvexity is strictly broader than convexity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section covers the basic properties of quasiconvex functions, including their relationship to convex functions and their behavior under various operations.&lt;/p&gt;

&lt;h2 id=&quot;modified-jensens-inequality&quot;&gt;Modified Jensen’s inequality&lt;/h2&gt;
&lt;p&gt;Quasiconvex functions can be defined through Jensen’s inequality as follows:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(\theta x + (1 - \theta)y) \leq \max\{f(x), f(y)\}\) for all \(x, y \in \text{dom}f, 0 \leq \theta \leq 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The figure below shows that if function \(f\) is quasiconvex, then the value of \(f\) along the line segment between two points does not exceed the maximum of \(f\) at the endpoints.
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/Fig.3.10_quasiconvex_function_on_R_4uChnEm.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;quasiconvex function on \(\mathbb{R}\). The values of \(f\) between \(x\) and \(y\) are less than \(\max\{f(x), f(y)\}\).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;quasiconvex-function-on-mathbbr&quot;&gt;Quasiconvex function on \(\mathbb{R}\)&lt;/h2&gt;
&lt;p&gt;A continuous function \(f : \mathbb{R} \mapsto \mathbb{R}\) is quasiconvex if and only if it satisfies at least one of the following conditions:&lt;/p&gt;

&lt;p&gt;• \(f\) is nondecreasing
• \(f\) is nonincreasing&lt;br /&gt;
• There exists a point \(c \in \text{dom} f\) such that \(f\) is nonincreasing on \(\{t \in \text{dom}f \mid t \leq c\}\) and nondecreasing on \(\{t \in \text{dom}f \mid t \geq c\}\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/Fig.3.11_quasiconvex_function_on_R_2_PPQpNiU.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;quasiconvex function on \(\mathbb{R}\). It is nonincreasing for \(t \leq c\) where \(t \in \text{dom} f\), and nondecreasing for \(t \geq c\) where \(t \in \text{dom} f\).&lt;/strong&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04-01 Quasiconvex functions: definition and examples</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_04_01_quasiconvex_functions_definition_and_examples/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_04_01_quasiconvex_functions_definition_and_examples</id>
   <content type="html">&lt;p&gt;Maximizing return-to-risk ratios, minimizing unit production cost \(\frac{\text{fixed} + \text{variable}}{\text{output}}\), or minimizing the ratio of distances to two targets all produce &lt;strong&gt;linear-fractional&lt;/strong&gt; objectives that fail the ordinary Hessian test for convexity. Yet every one of them is &lt;em&gt;quasiconvex&lt;/em&gt;: multiplying both sides of \(\frac{a^T x + b}{c^T x + d} \le \alpha\) by the positive denominator instantly turns the nonlinear ratio into a single linear halfspace!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-recognizing-canonical-quasiconvex-functions&quot;&gt;Key ideas: Recognizing Canonical Quasiconvex Functions&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sublevel Set Criterion:&lt;/strong&gt; Check directly whether \(\{x \in \text{dom}\,f : f(x) \le \alpha\}\) is a convex set for every \(\alpha \in \mathbb{R}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quasilinear Functions (Monotone 1D &amp;amp; Logs):&lt;/strong&gt; Functions like \(\log x\) (\(x &amp;gt; 0\)) and \(\lceil x \rceil\) are both quasiconvex and quasiconcave because every sublevel and superlevel set is a half-line.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear-Fractional Functions:&lt;/strong&gt; \(f(x) = \frac{a^T x + b}{c^T x + d}\) on \(c^T x + d &amp;gt; 0\) is quasilinear—its sublevel sets are halfspaces, making fractional linear programming solvable by bisection or Charnes–Cooper transformation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Distance Ratios &amp;amp; Vector Length:&lt;/strong&gt; Ratios \(\frac{\|x - a\|_2}{\|x - b\|_2}\) on the halfspace where \(\|x - a\|_2 \le \|x - b\|_2\) and the non-smooth “last nonzero index” length function are classic quasiconvex benchmarks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-sublevel-halfspace-of-a-linear-fractional-function&quot;&gt;Worked example: Sublevel Halfspace of a Linear-Fractional Function&lt;/h3&gt;

&lt;p&gt;Verify that \(f(x_1, x_2) = \frac{2x_1 + x_2 + 1}{x_1 + x_2 + 2}\) is quasiconvex on \(D = \{(x_1, x_2) : x_1 + x_2 + 2 &amp;gt; 0\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Clear the strictly positive denominator in \(f(x) \le \alpha\):&lt;/strong&gt;
\(\frac{2x_1 + x_2 + 1}{x_1 + x_2 + 2} \le \alpha \iff 2x_1 + x_2 + 1 \le \alpha(x_1 + x_2 + 2).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Collect terms into standard halfspace form:&lt;/strong&gt;
\((2 - \alpha)x_1 + (1 - \alpha)x_2 + (1 - 2\alpha) \le 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inspect the sublevel set \(S_\alpha\):&lt;/strong&gt; For every fixed \(\alpha \in \mathbb{R}\), this is a single linear inequality intersected with the open halfspace \(D\)—an intersection of two convex halfspaces, hence &lt;strong&gt;convex&lt;/strong&gt;!
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Concrete check at \(\alpha = 1\):&lt;/em&gt; \((2 - 1)x_1 + (1 - 1)x_2 + (1 - 2) \le 0 \iff x_1 \le 1\), a clean vertical halfspace.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A function \(f:\mathbb{R}^n \rightarrow \mathbb{R}\) is quasiconvex if all its sublevel sets \(\{x \mid f(x) \leq \alpha\}\) are convex for every \(\alpha \in \mathbb{R}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quasiconvex functions generalize convex functions&lt;/strong&gt; and appear frequently in optimization problems.&lt;/p&gt;

&lt;h2 id=&quot;definition&quot;&gt;Definition&lt;/h2&gt;

&lt;p&gt;A function \(f: \mathbb{R}^n \rightarrow \mathbb{R}\) is called &lt;strong&gt;quasiconvex&lt;/strong&gt; (or &lt;strong&gt;unimodal&lt;/strong&gt;) if its domain \(\text{dom}f\) and all sublevel sets \(S_{\alpha}\) (see &lt;a href=&quot;/contents/en/chapter03/03_01_03_key_properties_of_convex_functions/&quot;&gt;03-01-03&lt;/a&gt;) are convex.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \rightarrow \mathbb{R}\) is quasiconvex if \(\text{dom}f\) and
\(S_{\alpha} =\{x \in \text{dom}f \mid f(x) \leq \alpha\}\) for \(\alpha \in \mathbb{R}\) are convex.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If function \(-f\) is quasiconvex, then \(f\) is called &lt;strong&gt;quasiconcave&lt;/strong&gt;.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f : \mathbb{R}^n \rightarrow \mathbb{R}\) is quasiconcave if \(\text{dom}f\) and
\(S_{\alpha} = \{ x \in \text{dom}f \mid f(x) \geq \alpha \}\) for \(\alpha \in \mathbb{R}\) are convex.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When \(f\) is both quasiconvex and quasiconcave, it is called &lt;strong&gt;quasilinear&lt;/strong&gt;, and the function’s domain and all level sets \(\{x \mid f(x)=\alpha\}\) are convex. The following figure shows an example of a quasiconvex function.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/Fig3.9_quasiconvex_ftn_cAsoUpr.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] quasiconvex function on R [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;For \(\alpha\), the \(\alpha\)-sublevel set \(S_{\alpha}\) is convex, namely the interval \([a,b]\). The \(\beta\)-sublevel set \(S_{\beta}\) is the interval \((-\infty,c]\). &lt;strong&gt;Convex functions have convex sublevel sets and are quasiconvex, but the converse is not true.&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) : convex \(\Longrightarrow\) \(f\) : quasiconvex&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;p&gt;Let’s examine various examples of quasiconvex functions.&lt;/p&gt;

&lt;h3 id=&quot;logarithm&quot;&gt;Logarithm&lt;/h3&gt;
&lt;p&gt;\(\log x\) on \(\mathbb{R}_{++}\) is quasiconvex. (It is also quasiconcave, so it has the property of being quasilinear.)&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\log x\) on \(\mathbb{R}_{++}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;ceiling-function&quot;&gt;Ceiling function&lt;/h3&gt;
&lt;p&gt;The ceiling function is quasiconvex (and also quasiconcave).&lt;/p&gt;
&lt;blockquote&gt;
\[\text{ceil}(x) = \inf \{z \in \mathbb{Z} \mid z \geq x\}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;length-of-vector&quot;&gt;Length of vector&lt;/h3&gt;
&lt;p&gt;If we define the length of \(x \in \mathbb{R}^n\) as the largest index of nonzero components,&lt;/p&gt;
&lt;blockquote&gt;
\[f(x) = \max\{i \mid x_i \neq 0\}\]
&lt;/blockquote&gt;

&lt;p&gt;This satisfies&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x) \leq \alpha \iff x_i = 0\) for \(i = \lfloor\alpha\rfloor + 1,...,n\) on \(\mathbb{R}^n\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;which defines a subspace, so it is quasiconvex.
(Note: A subspace is closed under addition and scalar multiplication. Any subspace of \(\mathbb{R}^n\) is also a convex set.)&lt;/p&gt;

&lt;h3 id=&quot;linear-fractional-function&quot;&gt;Linear-fractional function&lt;/h3&gt;
&lt;p&gt;Under the following conditions, function \(f\) is both quasiconvex and quasiconcave, i.e., quasilinear.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x) = \frac{a^Tx+b}{c^Tx+d}\) with \(\text{dom}f =\{x \mid c^Tx + d &amp;gt; 0\}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;distance-ratio-function&quot;&gt;Distance ratio function&lt;/h3&gt;
&lt;p&gt;For \(a, b \in \mathbb{R}^n\), when function \(f\) is defined as follows, representing the ratio of Euclidean distances from \(x\) to \(a\) and from \(x\) to \(b\),
\(f\) is quasiconvex on the halfspace \(\{x \mid \|x - a\|_2 \leq \|x - b\|_2 \}\).&lt;/p&gt;

&lt;blockquote&gt;
\[f(x) = \frac{\|x - a\|_2}{\|x - b\|_2}\]
&lt;/blockquote&gt;

&lt;p&gt;Under the condition \(\alpha \leq 1\), this becomes a convex set in the form of a Euclidean ball, so \(f\) is quasiconvex.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04 Quasiconvex functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_04_00_Quasiconvex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_04_00_Quasiconvex_functions</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Many important economic utility ratios, signal-to-noise objectives, and linear-fractional costs are &lt;em&gt;not&lt;/em&gt; convex—their graphs can curve downward like $$\sqrt{&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;}\(or flatten out like\)\log x$$—yet they still have a single valley with convex sublevel sets. &lt;strong&gt;Quasiconvex functions&lt;/strong&gt; capture this exact generalization, allowing us to solve nonconvex ratio problems to global optimality via simple bisection over convex feasibility problems.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;key-ideas-why-quasiconvexity-matters&quot;&gt;Key ideas: Why Quasiconvexity Matters&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sublevel-Set Definition:&lt;/strong&gt; \(f\) is quasiconvex iff every sublevel set \(S_\alpha = \{x : f(x) \le \alpha\}\) is convex—a strictly weaker condition than convexity of the epigraph.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unimodality Without Bowl Shape:&lt;/strong&gt; In 1D, quasiconvexity means \(f\) is monotone or decreases then increases—no multiple valleys, though flat plateaus (spurious stationary points) can occur.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Modified Jensen &amp;amp; Calculus Tests:&lt;/strong&gt; The chord bound weakens from a weighted average to a maximum (\(f(\theta x + (1-\theta)y) \le \max\{f(x), f(y)\}\)), and the first-order condition constrains gradient direction only along sublevel boundaries.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic Payoff (Bisection):&lt;/strong&gt; Even when \(f\) is nonconvex, solving \(f(x) \le t\) is a convex feasibility problem, letting bisection pinpoint the global minimum \(p^*\) to \(\varepsilon\) accuracy in \(\lceil \log_2((u-l)/\varepsilon)\rceil\) steps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-fx--sqrtx-is-quasiconvex-but-not-convex&quot;&gt;Worked example: Why \(f(x) = \sqrt{|x|}\) Is Quasiconvex but Not Convex&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Examine $$f(x) = \sqrt{&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;}\(on\)\mathbb{R}$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Check convexity of all sublevel sets $$S_\alpha = {x \in \mathbb{R} : \sqrt{&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;} \le \alpha}$$:**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(\alpha &amp;lt; 0\): \(S_\alpha = \emptyset\) (convex).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;For \(\alpha \ge 0\): $$\sqrt{&lt;/td&gt;
              &lt;td&gt;x&lt;/td&gt;
              &lt;td&gt;} \le \alpha \iff&lt;/td&gt;
              &lt;td&gt;x&lt;/td&gt;
              &lt;td&gt;\le \alpha^2 \iff x \in [-\alpha^2, \alpha^2]$$, a closed interval (hence &lt;strong&gt;convex&lt;/strong&gt;!).&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Therefore $$f(x) = \sqrt{&lt;/td&gt;
              &lt;td&gt;x&lt;/td&gt;
              &lt;td&gt;}$$ is &lt;strong&gt;quasiconvex&lt;/strong&gt;.&lt;/td&gt;
              &lt;td&gt; &lt;/td&gt;
              &lt;td&gt; &lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Disprove ordinary convexity with two points:&lt;/strong&gt; Take \(x = 0\), \(y = 4\), and \(\theta = 0.5\):
\(f(0.5(0) + 0.5(4)) = f(2) = \sqrt{2} \approx 1.414 &amp;gt; 0.5\sqrt{0} + 0.5\sqrt{4} = 1.\)
Because the midpoint lies &lt;em&gt;above&lt;/em&gt; the chord, \(f\) is &lt;strong&gt;not convex&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section introduces quasiconvex functions, their definitions, examples, and basic properties.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-03 The conjugate function</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_03_the_conjugate_function/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_03_the_conjugate_function</id>
   <content type="html">&lt;p&gt;Instead of describing a smooth curve by its height \(f(x)\) at each position \(x\), you can describe the exact same curve by the vertical intercept of every tangent line of slope \(y\). That slope-indexed re-encoding is the &lt;strong&gt;Fenchel conjugate&lt;/strong&gt; \(f^*(y) = \sup_x (y^T x - f(x))\). It is one of the deepest ideas in all of optimization: it automatically converts primal constraints into dual objectives, links smoothness of \(f\) to strong convexity of \(f^*\), and powers Moreau’s decomposition for proximal algorithms.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-intuition-and-power-of-the-fenchel-conjugate&quot;&gt;Key ideas: Intuition and Power of the Fenchel Conjugate&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Geometric Meaning (Maximum Vertical Gap):&lt;/strong&gt; For a fixed slope \(y\), \(f^*(y) = \sup_x (y^T x - f(x))\) finds the maximum amount by which the linear function \(y^T x\) rises above \(f(x)\)—i.e., the negative \(y\)-intercept of the supporting hyperplane with slope \(y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always Convex:&lt;/strong&gt; Because \(f^*(y)\) is a pointwise supremum of affine functions of \(y\), \(f^*\) is &lt;em&gt;always&lt;/em&gt; convex and closed—even when the original function \(f\) is nonconvex!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel–Young Inequality:&lt;/strong&gt; Directly from the supremum definition, \(f(x) + f^*(y) \ge y^T x\) for all \(x, y\), with equality if and only if \(y \in \partial f(x)\) (tangent slope matches \(y\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biconjugate (\(f^{**} = f\)):&lt;/strong&gt; For any closed proper convex function, taking the conjugate twice recovers \(f\) identically; for a nonconvex \(f\), \(f^{**}\) produces its tightest convex envelope!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-conjugate-of-a-quadratic-and-fenchelyoung-check&quot;&gt;Worked example: Conjugate of a Quadratic and Fenchel–Young Check&lt;/h3&gt;

&lt;p&gt;Compute the Fenchel conjugate of \(f(x) = \frac{1}{2}a x^2\) (where \(a &amp;gt; 0\)) and verify Fenchel’s inequality numerically.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Maximize \(g(x) = yx - \frac{1}{2}a x^2\) over \(x \in \mathbb{R}\):&lt;/strong&gt;
\(g&apos;(x) = y - ax = 0 \implies x^* = \frac{y}{a}.\)
Since \(g&apos;&apos;(x) = -a &amp;lt; 0\), \(x^* = y/a\) is the unique global maximizer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Substitute \(x^*\) back into \(g(x)\):&lt;/strong&gt;
\(f^*(y) = y\left(\frac{y}{a}\right) - \frac{1}{2}a\left(\frac{y}{a}\right)^2 = \frac{y^2}{a} - \frac{y^2}{2a} = \frac{y^2}{2a}.\)
Notice the duality of curvature: large curvature \(a\) in \(f\) becomes small curvature \(1/a\) in \(f^*\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical check of Fenchel’s inequality (\(a = 4, x = 2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;With \(y = 6 \neq f&apos;(2) = 8\): \(f(2) + f^*(6) = 8 + \frac{36}{8} = 12.5 &amp;gt; 12 = xy\) (strict inequality).&lt;/li&gt;
      &lt;li&gt;With \(y = f&apos;(2) = 8\): \(f(2) + f^*(8) = 8 + \frac{64}{8} = 16 = 2 \cdot 8 = xy\) (exact equality!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section introduces the conjugate function (also known as the convex conjugate or Fenchel conjugate), a fundamental concept in convex analysis and duality theory that provides a powerful tool for transforming optimization problems.&lt;/p&gt;

&lt;h2 id=&quot;definition-and-mathematical-foundation&quot;&gt;Definition and Mathematical Foundation&lt;/h2&gt;

&lt;p&gt;For a function \(f: \mathbb{R}^n \to \mathbb{R}\), the &lt;strong&gt;conjugate function&lt;/strong&gt; \(f^*: \mathbb{R}^n \to \mathbb{R}\) is defined as:&lt;/p&gt;

\[f^*(y) = \sup_{x \in \text{dom}(f)} \{y^T x - f(x)\}\]

&lt;p&gt;where \(\sup\) denotes the supremum (least upper bound) over all \(x\) in the domain of \(f\).&lt;/p&gt;

&lt;h3 id=&quot;geometric-interpretation&quot;&gt;Geometric Interpretation&lt;/h3&gt;

&lt;p&gt;The conjugate function has a beautiful geometric interpretation:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f^*(y)\) represents the &lt;strong&gt;maximum gap&lt;/strong&gt; between the linear function \(y^T x\) and the original function \(f(x)\)&lt;/li&gt;
  &lt;li&gt;Geometrically, it measures how much the hyperplane with slope \(y\) can be “lifted above” the graph of \(f\)&lt;/li&gt;
  &lt;li&gt;The conjugate transforms the function from the “primal space” to the “dual space” of slopes&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;why-is-it-important&quot;&gt;Why is it Important?&lt;/h3&gt;

&lt;p&gt;The conjugate function is used to:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Transform optimization problems into their corresponding &lt;strong&gt;dual problems&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Provide analytical tools for &lt;strong&gt;duality theory&lt;/strong&gt; (covered in Chapter 11)&lt;/li&gt;
  &lt;li&gt;Enable direct substitution in &lt;strong&gt;Lagrange Duality&lt;/strong&gt; without explicit differentiation&lt;/li&gt;
  &lt;li&gt;Establish connections between primal and dual optimal solutions&lt;/li&gt;
&lt;/ol&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/conjugate_function.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Conjugate function [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;giải-thích-trực-giác-nhé&quot;&gt;giải thích trực giác nhé:&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Ý tưởng về hàm tuyến tính và tính lồi&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Một hàm tuyến tính (dạng 
𝑦
↦
⟨
𝑦
,
𝑥
⟩
−
𝑓
(
𝑥
)
y↦⟨y,x⟩−f(x)) luôn vừa lồi vừa lõm.&lt;/p&gt;

&lt;p&gt;Nếu ta lấy supremum (giá trị lớn nhất) của nhiều hàm tuyến tính, kết quả sẽ là một bao trên của các hàm này.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Sup của hàm tuyến tính tạo ra mặt cong lồi&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hãy tưởng tượng trong 2D:&lt;/p&gt;

&lt;p&gt;Mỗi hàm tuyến tính là một đường thẳng.&lt;/p&gt;

&lt;p&gt;Nếu ta lấy supremum của tất cả các đường thẳng này, ta sẽ “nâng” một lớp màng cao su bao phủ phía trên các đường.&lt;/p&gt;

&lt;p&gt;Kết quả bề mặt này không thể bị lõm xuống, mà luôn lồi ra ngoài.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/conjugate_function_2&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Conjugate function [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;fundamental-properties&quot;&gt;Fundamental Properties&lt;/h2&gt;

&lt;p&gt;The conjugate function has several remarkable properties that make it a powerful analytical tool:&lt;/p&gt;

&lt;h3 id=&quot;1-convexity-property&quot;&gt;1. Convexity Property&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(f^*\) is always convex&lt;/strong&gt;, regardless of whether \(f\) is convex or not&lt;/li&gt;
  &lt;li&gt;This is because \(f^*(y)\) is the pointwise supremum of affine functions \(y^T x - f(x)\)&lt;/li&gt;
  &lt;li&gt;The supremum of any collection of convex (affine) functions is convex&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-fenchels-inequality&quot;&gt;2. Fenchel’s Inequality&lt;/h3&gt;
&lt;p&gt;For any \(x\) and \(y\):
\(f(x) + f^*(y) \geq x^T y\)&lt;/p&gt;

&lt;p&gt;This fundamental inequality establishes a lower bound relationship between a function and its conjugate.&lt;/p&gt;

&lt;h3 id=&quot;3-conjugate-of-conjugate-biconjugate&quot;&gt;3. Conjugate of Conjugate (Biconjugate)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;In general: \(f^{**} \leq f\) (the biconjugate is a lower bound)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;If \(f\) is closed and convex&lt;/strong&gt;: \(f^{**} = f\) (perfect recovery)&lt;/li&gt;
  &lt;li&gt;This property is crucial for duality theory&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-subdifferential-relationship&quot;&gt;4. Subdifferential Relationship&lt;/h3&gt;
&lt;p&gt;If \(f\) is closed and convex, then for any \(x, y\):
\(y \in \partial f(x) \iff x \in \partial f^*(y) \iff f(x) + f^*(y) = x^T y\)&lt;/p&gt;

&lt;p&gt;This establishes a beautiful symmetry between primal and dual spaces.&lt;/p&gt;

&lt;h2 id=&quot;detailed-examples&quot;&gt;Detailed Examples&lt;/h2&gt;

&lt;h3 id=&quot;example-1-negative-logarithm&quot;&gt;Example 1: Negative Logarithm&lt;/h3&gt;
&lt;p&gt;Consider \(f(x) = -\log x\) for \(x &amp;gt; 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-by-step calculation:&lt;/strong&gt;
\(f^*(y) = \sup_{x&amp;gt;0} \{xy + \log x\}\)&lt;/p&gt;

&lt;p&gt;To find the supremum, we differentiate with respect to \(x\):
\(\frac{d}{dx}(xy + \log x) = y + \frac{1}{x} = 0\)&lt;/p&gt;

&lt;p&gt;This gives us \(x^* = -\frac{1}{y}\) (valid only when \(y &amp;lt; 0\)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;
\(f^*(y) = \begin{cases}
-1 - \log(-y), &amp;amp; \text{if } y &amp;lt; 0 \\
+\infty, &amp;amp; \text{if } y \geq 0
\end{cases}\)&lt;/p&gt;

&lt;h3 id=&quot;example-2-quadratic-function&quot;&gt;Example 2: Quadratic Function&lt;/h3&gt;
&lt;p&gt;Consider \(f(x) = \frac{1}{2}x^T Q x\) where \(Q \succ 0\) (positive definite).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-by-step calculation:&lt;/strong&gt;
\(f^*(y) = \sup_{x} \{y^T x - \frac{1}{2}x^T Q x\}\)&lt;/p&gt;

&lt;p&gt;Taking the gradient and setting it to zero:
\(\nabla_x (y^T x - \frac{1}{2}x^T Q x) = y - Qx = 0\)&lt;/p&gt;

&lt;p&gt;This gives us \(x^* = Q^{-1}y\).&lt;/p&gt;

&lt;p&gt;Substituting back:
\(f^*(y) = y^T Q^{-1} y - \frac{1}{2}(Q^{-1}y)^T Q (Q^{-1}y) = \frac{1}{2}y^T Q^{-1} y\)&lt;/p&gt;

&lt;h3 id=&quot;example-3-absolute-value-1d-case&quot;&gt;Example 3: Absolute Value (1D case)&lt;/h3&gt;
&lt;p&gt;Consider \(f(x) = \lvert x \rvert\) for \(x \in \mathbb{R}\).&lt;/p&gt;

\[f^*(y) = \sup_{x} \{yx - \lvert x \rvert\}\]

&lt;p&gt;&lt;strong&gt;Analysis by cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;If \(\lvert y \rvert \leq 1\): The supremum is finite and equals 0&lt;/li&gt;
  &lt;li&gt;If \(\lvert y \rvert &amp;gt; 1\): The supremum is \(+\infty\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;
\(f^*(y) = \begin{cases}
0, &amp;amp; \text{if } \lvert y \rvert \leq 1 \\
+\infty, &amp;amp; \text{if } \lvert y \rvert &amp;gt; 1
\end{cases}\)&lt;/p&gt;

&lt;p&gt;This is the &lt;strong&gt;indicator function&lt;/strong&gt; of the interval \([-1, 1]\).&lt;/p&gt;

&lt;h3 id=&quot;example-4-exponential-function&quot;&gt;Example 4: Exponential Function&lt;/h3&gt;
&lt;p&gt;Consider \(f(x) = e^x\) for \(x \in \mathbb{R}\).&lt;/p&gt;

\[f^*(y) = \sup_{x} \{yx - e^x\}\]

&lt;p&gt;Setting the derivative to zero: \(y - e^x = 0\), so \(x^* = \log y\) (valid for \(y &amp;gt; 0\)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;
\(f^*(y) = \begin{cases}
y \log y - y, &amp;amp; \text{if } y &amp;gt; 0 \\
0, &amp;amp; \text{if } y = 0 \\
+\infty, &amp;amp; \text{if } y &amp;lt; 0
\end{cases}\)&lt;/p&gt;

&lt;h2 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h2&gt;

&lt;p&gt;The conjugate function plays a crucial role in:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lagrange Duality&lt;/strong&gt;: Converting primal problems to dual problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel Duality&lt;/strong&gt;: A general framework for convex optimization duality&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Proximal Operators&lt;/strong&gt;: Used in modern optimization algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Variational Analysis&lt;/strong&gt;: Studying optimization problems through conjugate pairs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These applications will be explored in detail in Chapters 11 and 13.&lt;/p&gt;

&lt;h2 id=&quot;interactive-visualization&quot;&gt;Interactive Visualization&lt;/h2&gt;

&lt;p&gt;To better understand how conjugate functions work, explore our interactive visualization:&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;a href=&quot;../conjugate_function_interactive.html&quot; target=&quot;_blank&quot; style=&quot;display: inline-block; padding: 12px 24px; background-color: #3498db; color: white; text-decoration: none; border-radius: 6px; font-weight: bold; box-shadow: 0 2px 4px rgba(0,0,0,0.2);&quot;&gt;
        🎯 Launch Interactive Conjugate Function Explorer
    &lt;/a&gt;
&lt;/div&gt;

&lt;p&gt;The interactive tool allows you to:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Visualize different function types&lt;/strong&gt; and their conjugates side-by-side&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adjust parameters&lt;/strong&gt; to see how they affect the conjugate&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Explore tangent lines&lt;/strong&gt; to understand the geometric interpretation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare multiple examples&lt;/strong&gt; with detailed mathematical explanations&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;summary-and-key-takeaways&quot;&gt;Summary and Key Takeaways&lt;/h2&gt;

&lt;p&gt;The conjugate function is a powerful mathematical tool that:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Transforms functions&lt;/strong&gt; from primal to dual space through the operation \(f^*(y) = \sup_x \{y^T x - f(x)\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always produces convex functions&lt;/strong&gt;, regardless of the original function’s convexity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Establishes fundamental inequalities&lt;/strong&gt; like Fenchel’s inequality: \(f(x) + f^*(y) \geq x^T y\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enables duality theory&lt;/strong&gt; by connecting primal and dual optimization problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Provides analytical tools&lt;/strong&gt; for solving complex optimization problems&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Understanding conjugate functions is essential for:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Convex optimization theory&lt;/strong&gt; and algorithm development&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lagrange duality&lt;/strong&gt; and dual problem formulation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Modern optimization methods&lt;/strong&gt; like proximal algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Variational analysis&lt;/strong&gt; and mathematical economics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The geometric intuition of “maximum gap between linear and nonlinear functions” provides a visual understanding that complements the analytical definition, making this abstract concept more accessible to learners.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>03-02 Operations that preserve convexity</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_02_operations_that_preserve_convexity/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_02_operations_that_preserve_convexity</id>
   <content type="html">&lt;p&gt;Nobody wants to compute a \(500 \times 500\) Hessian by hand just to prove a regularized empirical loss is convex. Just as Disciplined Convex Programming (DCP) parsers verify convexity symbolically in milliseconds, this lesson teaches you the exact algebraic operations—nonnegative sums, affine pre-compositions, monotone compositions, pointwise suprema, partial minimization, and perspective—that let you prove convexity of intricate objectives by inspection.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-disciplined-convexity-preserving-rules&quot;&gt;Key ideas: Disciplined Convexity-Preserving Rules&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nonnegative Weighted Sums:&lt;/strong&gt; \(\sum_i w_i f_i(x)\) with \(w_i \ge 0\) preserves convexity—immediately certifying empirical risk plus regularization (\(\frac{1}{n}\sum \ell_i(w) + \lambda R(w)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Composition with an Affine Map:&lt;/strong&gt; \(g(x) = f(Ax + b)\) is convex whenever \(f\) is convex—turning 1D atoms like \(\log(1 + e^z)\) into multivariable logistic losses \(\log(1 + e^{-y_i w^T x_i})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scalar &amp;amp; Vector Composition Rules:&lt;/strong&gt; \(h(g(x))\) is convex if \(h\) is convex &amp;amp; nondecreasing and \(g\) is convex (or \(h\) convex &amp;amp; nonincreasing and \(g\) concave)—remember the curvature-monotonicity sign check!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pointwise Supremum, Minimization &amp;amp; Perspective:&lt;/strong&gt; \(\sup_\alpha f_\alpha(x)\), \(\inf_{y \in C} f(x, y)\) (when \(f\) is jointly convex), and \(t f(x/t)\) (\(t &amp;gt; 0\)) all preserve convexity—explaining why dual functions and quadratic-over-linear terms are convex.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-certifying-convexity-without-computing-a-single-hessian&quot;&gt;Worked example: Certifying Convexity Without Computing a Single Hessian&lt;/h3&gt;

&lt;p&gt;Prove that both functions below are convex using preservation rules alone:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Multivariable log-sum-exp:&lt;/strong&gt; \(f(x_1, x_2) = \log\left(e^{2x_1 - x_2} + e^{-x_1 + 3x_2 + 1}\right)\).
    &lt;ul&gt;
      &lt;li&gt;Start with the known convex atom \(\text{lse}(z_1, z_2) = \log(e^{z_1} + e^{z_2})\).&lt;/li&gt;
      &lt;li&gt;Notice \(f(x) = \text{lse}(Ax + b)\) where \(A = \begin{pmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 3 \end{pmatrix}\) and \(b = \begin{pmatrix} 0 \\ 1 \end{pmatrix}\).&lt;/li&gt;
      &lt;li&gt;By &lt;strong&gt;composition with an affine mapping&lt;/strong&gt;, \(f\) is convex on all of \(\mathbb{R}^2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exponential of a quadratic:&lt;/strong&gt; \(q(x) = e^{x^2}\) on \(\mathbb{R}\).
    &lt;ul&gt;
      &lt;li&gt;Write \(q(x) = h(g(x))\) with \(g(x) = x^2\) (convex) and \(h(u) = e^u\) (convex and &lt;strong&gt;nondecreasing&lt;/strong&gt;, since \(h&apos;(u) = e^u &amp;gt; 0\)).&lt;/li&gt;
      &lt;li&gt;By the &lt;strong&gt;scalar composition rule&lt;/strong&gt;, \(q(x) = e^{x^2}\) is convex everywhere (check: \(q&apos;&apos;(x) = (2 + 4x^2)e^{x^2} &amp;gt; 0\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section discusses operations that preserve the convexity of convex functions.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nonnegative weighted sum&lt;/li&gt;
  &lt;li&gt;Composition with affine functions&lt;/li&gt;
  &lt;li&gt;Pointwise maximum&lt;/li&gt;
  &lt;li&gt;Perspective function&lt;/li&gt;
  &lt;li&gt;Linear-fractional function&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;nonnegative-weighted-sum&quot;&gt;Nonnegative weighted sum&lt;/h2&gt;
&lt;p&gt;Convex functions have the following properties with respect to scalar multiplication and addition:&lt;/p&gt;

&lt;p&gt;• When a convex function \(f\) exists, multiplying it by any nonnegative number still results in a convex function \(f\).&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) is convex \(\Rightarrow \alpha f\) is convex for \(\alpha \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;• When two convex functions (\(f_1, f_2\)) exist, their sum is also convex.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f_1, f_2\) are convex \(\Rightarrow f_1 + f_2\) is convex&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;• A nonnegative weighted sum of convex functions \(f_1, ..., f_m\) is convex.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f_1, ..., f_n\) are convex \(\Rightarrow \alpha_1f_1 + \cdots + \alpha_nf_n\) is convex, \(\alpha_1, ..., \alpha_n \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;composition&quot;&gt;Composition&lt;/h2&gt;
&lt;h3 id=&quot;1-affine-composition&quot;&gt;1. Affine composition&lt;/h3&gt;
&lt;p&gt;If function \(f\) is convex, then \(f(Ax + b)\) is also convex.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f\) is convex \(\Rightarrow f(Ax + b)\) is convex&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;2-general-composition&quot;&gt;2. General composition&lt;/h3&gt;
&lt;p&gt;Suppose we have function \(g\) that maps from \(n\)-dimensional to 1-dimensional space and function \(h\) that maps from 1-dimensional to 1-dimensional space.
The composition function \(f(x)=h(g(x))\) is convex or concave in the following cases:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;composition of \(g:\mathbb{R}^n \mapsto \mathbb{R}\) and \(h:\mathbb{R}\mapsto \mathbb{R}\):
\(f(x)=h(g(x))\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;• If \(g\) is convex, \(h\) is convex, and \(h\) is nondecreasing, then \(f\) is convex.
• If \(g\) is concave, \(h\) is convex, and \(h\) is nonincreasing, then \(f\) is convex.
• If \(g\) is concave, \(h\) is concave, and \(h\) is nondecreasing, then \(f\) is concave.
• If \(g\) is convex, \(h\) is concave, and \(h\) is nonincreasing, then \(f\) is concave.&lt;/p&gt;

&lt;h3 id=&quot;note&quot;&gt;[Note]&lt;/h3&gt;
&lt;p&gt;The monotonicity of the extended-value extension \(\tilde{h}\) must be preserved.&lt;/p&gt;

&lt;h3 id=&quot;example&quot;&gt;Example&lt;/h3&gt;
&lt;p&gt;• If \(g\) is convex, then \(\exp g(x)\) is convex.
• If \(g\) is concave and positive, then \(1/g(x)\) is convex.&lt;/p&gt;

&lt;h3 id=&quot;3-vector-composition&quot;&gt;3. Vector composition&lt;/h3&gt;
&lt;p&gt;Suppose we have function \(g\) that maps from \(n\)-dimensional to \(k\)-dimensional space and function \(h\) that maps from \(k\)-dimensional to 1-dimensional space.
Then the composition function \(f(x)=h(g(x))=h(g_1(x),g_2(x),...,g_k(x))\) is convex or concave in the following cases:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;composition of \(g:\mathbb{R}^n\mapsto\mathbb{R}^k\) and \(h:\mathbb{R}^k\mapsto\mathbb{R}\):
\(f(x)=h(g(x))=h(g_1(x),g_2(x),...,g_k(x))\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;• If \(g\) is convex and \(h\) is convex, and \(h\) is nondecreasing in each argument, then \(f\) is convex.
• If \(g\) is convex and \(h\) is concave, and \(h\) is nonincreasing in each argument, then \(f\) is concave.&lt;/p&gt;

&lt;h3 id=&quot;example-1&quot;&gt;Example&lt;/h3&gt;
&lt;p&gt;• If \(g_i\) are concave and positive, then \(\sum_{i=1}^{m} \log g_i(x)\) is concave.
• If \(g_i\) are convex, then \(\log \sum_{i=1}^{m} \exp g_i(x)\) is convex.&lt;/p&gt;

&lt;h2 id=&quot;pointwise-maximum&quot;&gt;Pointwise maximum&lt;/h2&gt;
&lt;p&gt;The pointwise maximum of functions is defined as follows and is convex:&lt;/p&gt;
&lt;h3 id=&quot;1-pointwise-maximum&quot;&gt;1. Pointwise maximum&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f_1, f_2\) are convex functions \(\Rightarrow f(x) = \max \{ f_1(x), f_2(x) \}\), \(\text{dom } f = \text{dom } f_1 \cap \text{dom } f_2\) is convex&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;2-pointwise-supremum&quot;&gt;2. Pointwise supremum&lt;/h3&gt;
&lt;p&gt;If \(f(x, y)\) is convex in \(x\) for each \(y \in A\), then \(g(x) = \sup_{y\in A} f(x, y)\) is convex.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f(x, y)\) is convex in \(x\) for each \(y \in A\)
\(\Rightarrow g(x) = \sup_{y\in A} f(x, y)\) with \(\text{dom } g = \{x | (x, y) \in \text{dom} f \text{ for all } y \in A, \sup &amp;lt; \infty \}\) is convex in \(x\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;perspective&quot;&gt;Perspective&lt;/h2&gt;
&lt;p&gt;If function \(f: \mathbb{R}^n \rightarrow \mathbb{R}\) is convex, then the perspective operation \(g: \mathbb{R}^{n+1} \mapsto \mathbb{R}\) preserves convexity.&lt;/p&gt;

&lt;p&gt;The perspective function \(g: \mathbb{R}^n×\mathbb{R} \mapsto \mathbb{R}\) of function \(f: \mathbb{R}^n \mapsto \mathbb{R}\) is:&lt;/p&gt;

\[g(x,t) = tf\left(\frac{x}{t}\right), \quad \text{dom } g = \left\{(x,t) \left| \frac{x}{t} \in \text{dom } f, t&amp;gt;0 \right.\right\}\]

&lt;p&gt;If function \(f\) is convex, then \(g\) is also convex.&lt;/p&gt;

&lt;h3 id=&quot;example-2&quot;&gt;Example&lt;/h3&gt;
&lt;p&gt;• When \(t\) is positive, if \(g(x,t)=x^Tx/t\) is convex, then \(f(x)=x^Tx\) is convex.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Negative logarithm&lt;/strong&gt;
When relative entropy \(g(x,t) =t\log t − t\log x\) is convex on \(\mathbb{R}_{++}^2\), then \(f(x)=−\log x\) is convex.&lt;/p&gt;

&lt;p&gt;• If \(f\) is convex, then \(g(x)=(c^Tx+d)f\left(\frac{Ax+b}{c^Tx+d}\right)\) is convex under the following condition:&lt;/p&gt;
&lt;blockquote&gt;
\[\left\{x \left| c^Tx+d&amp;gt;0, \frac{Ax+b}{c^Tx+d} \in \text{dom } f\right.\right\}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>03-01-03 Key properties of convex functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_01_03_key_properties_of_convex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_01_03_key_properties_of_convex_functions</id>
   <content type="html">&lt;p&gt;How do you prove a multivariable function is convex without testing every pair of points on every line segment? This lesson gives you four interchangeable lenses: the &lt;strong&gt;epigraph&lt;/strong&gt; (a geometric lens), &lt;strong&gt;sublevel sets&lt;/strong&gt; (a contour lens), the &lt;strong&gt;first-order tangent inequality&lt;/strong&gt; (a slope lens proving \(\nabla f(x^*) = 0 \implies\) global minimum), and the &lt;strong&gt;second-order Hessian test&lt;/strong&gt; (a curvature lens). Switching smoothly between these four characterizations is the signature skill of a graduate-level optimizer.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-equivalent-lenses-on-convexity&quot;&gt;Key ideas: Four Equivalent Lenses on Convexity&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Epigraph Characterization:&lt;/strong&gt; \(f\) is convex iff \(\text{epi}\,f = \{(x, t) : f(x) \le t\}\) is a convex set—bridging Chapter 02 directly into Chapter 03.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Sublevel Sets:&lt;/strong&gt; Every convex function has convex sublevel sets \(\{x : f(x) \le \alpha\}\) (note: the converse fails—functions with convex sublevel sets are &lt;em&gt;quasiconvex&lt;/em&gt;, not necessarily convex!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Condition:&lt;/strong&gt; Differentiable \(f\) is convex iff \(f(y) \ge f(x) + \nabla f(x)^T(y - x)\) everywhere—the tangent plane is a &lt;em&gt;global underestimator&lt;/em&gt;, which immediately proves \(\nabla f(x^*) = 0 \implies f(y) \ge f(x^*)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-Order Condition &amp;amp; Jensen’s Inequality:&lt;/strong&gt; Twice-differentiable \(f\) is convex iff \(\nabla^2 f(x) \succeq 0\) everywhere; Jensen’s inequality \(f(\mathbb{E}[X]) \le \mathbb{E}[f(X)]\) generalizes convexity to expectations and underlies KL divergence nonnegativity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-first--and-second-order-tests-on-a-coupled-quadratic&quot;&gt;Worked example: First- and Second-Order Tests on a Coupled Quadratic&lt;/h3&gt;

&lt;p&gt;Analyze \(f(x_1, x_2) = x_1^2 + x_1 x_2 + x_2^2\) at \(x = (1, 0)^T\) and \(y = (0, 2)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Second-order test (Hessian):&lt;/strong&gt;
\(\nabla f(x_1, x_2) = \begin{pmatrix} 2x_1 + x_2 \\ x_1 + 2x_2 \end{pmatrix}, \qquad \nabla^2 f(x_1, x_2) = \begin{pmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{pmatrix}.\)
Since \(\Delta_1 = 2 &amp;gt; 0\) and \(\Delta_2 = 2(2) - 1^2 = 3 &amp;gt; 0\) (eigenvalues \(3\) and \(1\)), \(\nabla^2 f \succ 0\) everywhere, certifying strict convexity.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the first-order global underestimator between \(x = (1, 0)^T\) and \(y = (0, 2)^T\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(x) = 1\), \(\nabla f(x) = (2, 1)^T\), \(y - x = (-1, 2)^T\).&lt;/li&gt;
      &lt;li&gt;Tangent plane prediction at \(y\):
\(f(x) + \nabla f(x)^T(y - x) = 1 + 2(-1) + 1(2) = 1.\)&lt;/li&gt;
      &lt;li&gt;True value at \(y\): \(f(0, 2) = 0 + 0 + 4 = 4\).
Indeed \(f(y) = 4 \ge 1\), with exact gap \(4 - 1 = 3 = \frac{1}{2}(y - x)^T \nabla^2 f (y - x)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;epigraph-characterization&quot;&gt;Epigraph characterization&lt;/h2&gt;
&lt;p&gt;As discussed in &lt;a href=&quot;/contents/en/chapter01/01_02_convex_optimization_problem/&quot;&gt;lesson 01-02&lt;/a&gt;, \(f\) is convex if and only if its epigraph is a convex set, and vice versa.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f\) is convex \(\iff epi(f) = \{(x,t) \in \mathbb{R}^{n+1} \mid x \in \text{dom} f, f(x) \le t \}\) is a convex set&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;convex-sublevel-sets&quot;&gt;Convex sublevel sets&lt;/h2&gt;
&lt;p&gt;If a function \(f\) is convex, its sublevel sets are also convex.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\{x \in \text{dom } f: f(x) \leq t\}\), for all \(t \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;note-sublevel-set&quot;&gt;[Note] Sublevel set&lt;/h3&gt;
&lt;p&gt;For a function \(f:\mathbb{R}^n \mapsto \mathbb{R}\), \(C_\alpha = \{x \in \text{dom} f | f(x) \leq \alpha\}\) is called the &lt;em&gt;\(\alpha\)-sublevel set&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;first-order-characterization&quot;&gt;First-order characterization&lt;/h2&gt;
&lt;p&gt;If a function \(f\) is &lt;strong&gt;differentiable&lt;/strong&gt;, the following holds:
If the domain \(\text{dom} f\) is convex and for all \(x, y \in \text{dom} f\), \(f(y) \geq f(x) +\nabla f(x)^T(y-x)\), then \(f\) is convex, and vice versa.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f\) is convex \(\iff \text{dom}f\) is convex, and \(f(y) \geq f(x) +\nabla f(x)^T(y-x)\) for all \(x,y \in \text{dom} f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The figure below illustrates the first-order condition for a differentiable convex function \(f\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/1st_order_condition.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Convex Function [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;This condition is known as the &lt;strong&gt;tangent line condition&lt;/strong&gt; (or tangent hyperplane condition in higher dimensions). It essentially states that a convex function always lies above or on all of its tangent lines (or hyperplanes). No matter where you draw a tangent to a convex function, the function’s actual values will never dip below that tangent.&lt;/p&gt;

&lt;h3 id=&quot;example&quot;&gt;Example&lt;/h3&gt;

&lt;p&gt;Consider the simple convex function \(f(x) = x^2\). Its derivative (which is its gradient in 1D) is \(f&apos;(x) = 2x\).&lt;/p&gt;

&lt;p&gt;Let’s pick an arbitrary point \(x_0\). The equation of the tangent line to \(f(x)\) at \(x_0\) is given by:
\(L(x) = f(x_0) + f&apos;(x_0)(x - x_0)\)&lt;/p&gt;

&lt;p&gt;Substituting \(f(x_0) = x_0^2\) and \(f&apos;(x_0) = 2x_0\):
\(L(x) = x_0^2 + 2x_0(x - x_0)\)&lt;/p&gt;

&lt;p&gt;The convexity condition requires that for any \(x\):
\(f(x) \geq L(x)\)
\(x^2 \geq x_0^2 + 2x_0(x - x_0)\)&lt;/p&gt;

&lt;p&gt;Let’s simplify the right side:
\(x^2 \geq x_0^2 + 2x_0x - 2x_0^2\)
\(x^2 \geq 2x_0x - x_0^2\)&lt;/p&gt;

&lt;p&gt;Now, move all terms to one side:
\(x^2 - 2x_0x + x_0^2 \geq 0\)&lt;/p&gt;

&lt;p&gt;This expression is a perfect square:
\((x - x_0)^2 \geq 0\)&lt;/p&gt;

&lt;p&gt;This inequality is always true for any real numbers \(x\) and \(x_0\), because the square of any real number is always non-negative. This confirms that \(f(x) = x^2\) satisfies the tangent line condition and is indeed a convex function.&lt;/p&gt;

&lt;h2 id=&quot;second-order-characterization&quot;&gt;Second-order characterization&lt;/h2&gt;
&lt;p&gt;If a function \(f\) is twice differentiable, it has the following property:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If the second derivative \(\nabla^2f(x)\) is positive semidefinite for all \(x \in \text{dom} f\) and \(\text{dom} f\) is convex, then \(f\) is convex, and vice versa.
    &lt;blockquote&gt;
      &lt;p&gt;\(f\) is convex \(\iff \nabla^2f(x) \succeq 0\) for all \(x \in \text{dom} f, \text{dom} f\): convex&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;If the second derivative \(\nabla^2f(x)\) is positive definite for all \(x \in \text{dom} f\), then \(f\) is strictly convex.
    &lt;blockquote&gt;
      &lt;p&gt;if \(\nabla^2f(x) \succ 0\) for all \(x \in \text{dom} f\), then \(f\) is strictly convex&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;In other words, the curvature is always nonnegative.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;jensens-inequality&quot;&gt;Jensen’s inequality&lt;/h2&gt;

&lt;p&gt;Let \(f\) be a convex function and \(w_1, ..., w_n\) be positive weights such that \(\sum_{i=1}^{n} w_i = 1\). Then, the following inequality holds:&lt;/p&gt;

\[\sum_{i=1}^{n} w_i f(x_i) \geq f \left ( \sum_{i=1}^{n} w_i x_i \right )\]

&lt;p&gt;If a function \(f\) is convex, it satisfies the following inequality:&lt;/p&gt;
&lt;blockquote&gt;
\[f(tx_1 + (1 - t)x_2) \le tf(x_1) + (1 - t)f(x_2) \text{ for } 0 \le t \le 1\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Extension&lt;/em&gt;:&lt;br /&gt;
\(X\) is a random variable supported on \(\text{dom } f\), then \(f(E[X]) \le E[f(X)]\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/jensen_inequality.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Jensen&apos;s Inequality [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;isnt-jensens-inequality-exactly-the-definition-of-a-convex-function&quot;&gt;&lt;strong&gt;Isn’t Jensen’s inequality exactly the definition of a convex function?&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;The answer is no—Jensen’s inequality is a consequence and generalization of the convexity definition, not the definition itself.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;This extends the two-point case (\(n=2\)) in the definition to any finite number of points (and can be further generalized to integrals for probability measures).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why It’s a Generalization:&lt;/strong&gt; The basic definition is for two points (binary convex combination). Jensen applies it iteratively to more points. For instance:
    &lt;ul&gt;
      &lt;li&gt;For \(n=2\), Jensen reduces exactly to the definition.&lt;/li&gt;
      &lt;li&gt;For \(n=3\), you can apply the definition recursively: First combine two points, then with the third.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;
&lt;h3 id=&quot;short-example&quot;&gt;Short Example&lt;/h3&gt;

&lt;p&gt;Let’s use the convex function \(f(x) = x^2\).
Consider two numbers: \(x_1 = 1\) and \(x_2 = 3\).
We want to compare \(f\left(\frac{x_1+x_2}{2}\right)\) with \(\frac{f(x_1)+f(x_2)}{2}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Calculate the function of the average:&lt;/strong&gt;
The average of \(x_1\) and \(x_2\) is \(\frac{1+3}{2} = \frac{4}{2} = 2\).
Applying the function: \(f(2) = 2^2 = 4\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Calculate the average of the function values:&lt;/strong&gt;
\(f(x_1) = f(1) = 1^2 = 1\).
\(f(x_2) = f(3) = 3^2 = 9\).
The average of these function values is \(\frac{1+9}{2} = \frac{10}{2} = 5\).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Comparing the two results: \(4 \le 5\).
This demonstrates Jensen’s inequality: \(f\left(\frac{1+3}{2}\right) \le \frac{f(1)+f(3)}{2}\).&lt;/p&gt;

&lt;h3 id=&quot;four-ways-to-check-convexity-in-about-3-minutes&quot;&gt;Four ways to check convexity in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/convexity-tests_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The chord and Jensen on x² (the 1 and 3 example), the tangent below the graph, second derivatives and the Hessian, epigraph and sublevel sets, contrasted with the W-shaped x⁴ − 3x².&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-01-02 Examples of convex functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_01_02_examples_of_convex_function/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_01_02_examples_of_convex_function</id>
   <content type="html">&lt;p&gt;Just as Chapter 02 built a periodic table of convex sets, this lesson builds the periodic table of &lt;strong&gt;convex functions&lt;/strong&gt;. From affine maps, quadratics, and norms to indicator functions \(I_C(x)\) (which encode hard constraints directly inside an objective) and support functions \(S_C(y)\) (which measure the farthest reach of a set in direction \(y\)), these atoms are the exact building blocks recognized by disciplined convex programming tools like CVXPY.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-essential-convex-function-atoms&quot;&gt;Key ideas: Essential Convex Function Atoms&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Smooth Atoms (Affine, Quadratic, Exponential, Negative Log):&lt;/strong&gt; Affine functions are simultaneously convex and concave; quadratics \(\frac{1}{2}x^T P x + q^T x + r\) are convex iff \(P \succeq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Norms &amp;amp; Pointwise Maxima:&lt;/strong&gt; Every norm is convex by homogeneity and the triangle inequality; \(\max_i x_i\) is convex and piecewise-linear, modeling worst-case costs.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Indicator Function (\(I_C(x)\)):&lt;/strong&gt; Equals \(0\) on \(C\) and \(+\infty\) outside \(C\); it is convex iff \(C\) is a convex set, letting us rewrite constrained minimization \(\min_{x \in C} f(x)\) as unconstrained \(\min_x (f(x) + I_C(x))\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Support Function (\(S_C(y) = \sup_{x \in C} y^T x\)):&lt;/strong&gt; Always convex in \(y\) (even if \(C\) is nonconvex!) because it is a pointwise supremum of affine functions of \(y\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-a-support-function-explicitly&quot;&gt;Worked example: Computing a Support Function Explicitly&lt;/h3&gt;

&lt;p&gt;Compute the support function \(S_C(y) = \sup_{x \in C} y^T x\) of the unit \(\ell_\infty\) box \(C = [-1, 1]^2\), and evaluate it at \(y = (3, -2)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Maximize each coordinate independently over \(x_i \in [-1, 1]\):&lt;/strong&gt;
\(S_C(y) = \sup_{-1 \le x_1 \le 1} (y_1 x_1) + \sup_{-1 \le x_2 \le 1} (y_2 x_2).\)
To make \(y_i x_i\) as large as possible, choose \(x_i = +1\) if \(y_i &amp;gt; 0\) and \(x_i = -1\) if \(y_i &amp;lt; 0\), yielding \(y_i x_i = |y_i|\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Identify the resulting convex function:&lt;/strong&gt;
\(S_C(y) = |y_1| + |y_2| = \|y\|_1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate at \(y = (3, -2)^T\):&lt;/strong&gt; The maximizing vertex is \(x^* = (1, -1)^T \in C\), giving
\(S_C(3, -2) = 3(1) + (-2)(-1) = 3 + 2 = 5 = \|(3, -2)^T\|_1.\)
Thus the support function of the \(\ell_\infty\) unit ball is precisely the convex \(\ell_1\) norm!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section reviews representative examples of convex functions, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Exponential function&lt;/li&gt;
  &lt;li&gt;Power function&lt;/li&gt;
  &lt;li&gt;Affine&lt;/li&gt;
  &lt;li&gt;Quadratic&lt;/li&gt;
  &lt;li&gt;Least squares loss&lt;/li&gt;
  &lt;li&gt;Norm&lt;/li&gt;
  &lt;li&gt;Indicator function&lt;/li&gt;
  &lt;li&gt;Support function&lt;/li&gt;
  &lt;li&gt;Max function&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;univariate-function&quot;&gt;Univariate function&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Exponential function:
For any real number \(a\), \(e^{ax}\) is convex.
    &lt;blockquote&gt;
      &lt;p&gt;\(e^{ax}\) is convex for any \(a \in \mathbb{R}\)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Power function:
For \(x, a \in \mathbb{R}_{+}\), depending on the range of \(a\), \(x^a\) can be convex or concave.
    &lt;blockquote&gt;
      &lt;p&gt;\(x^{a}\) is convex on \(\mathbb{R}_{+}\) for any \(a \geq 1\) or \(a \leq 0\)
\(x^{a}\) is concave on \(\mathbb{R}_{+}\) for any \(0 \leq a \leq 1\)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;affine-function&quot;&gt;Affine function&lt;/h2&gt;
&lt;p&gt;As covered in &lt;a href=&quot;/contents/en/chapter03/03_01_01_convex_functions_definition/&quot;&gt;03-01-01&lt;/a&gt;, all affine functions are both convex and concave.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;On \(\mathbb{R}\) and \(\mathbb{R}^n\):
    &lt;blockquote&gt;
      &lt;p&gt;\(a^Tx + b\) is convex and concave&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;On \(\mathbb{R}^{m \times n}\):
    &lt;blockquote&gt;
      &lt;p&gt;\(\text{tr}(A^TX) + b = \sum_{i=1}^m\sum_{j=1}^n A_{ij}X_{ij} + b\) is convex and concave&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;quadratic-function&quot;&gt;Quadratic function&lt;/h2&gt;
&lt;p&gt;Consider the quadratic function \(f(x)=\frac{1}{2}x^TPx+q^Tx+r\), where \(\nabla f(x)= Px+q\) and \(\nabla^2f(x) = P\). If \(P\) is positive semidefinite, then \(f(x)\) is convex.
For \(P \succeq 0\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x)=\frac{1}{2}x^TPx+q^Tx+r\) is convex with \(P \in \mathbb{S}^n, q \in \mathbb{R}^n, r \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Q: Why is \(f(x)\) convex if \(P\) is positive semidefinite?&lt;/strong&gt;
A: In a quadratic function, the second derivative is the Hessian matrix. The Hessian determines the curvature of the function, and if it is positive semidefinite, the function curves upwards. (That is, the curvature in the direction of the Hessian’s eigenvectors is nonnegative.) Thus, if the second derivative is positive semidefinite, the function is convex.&lt;/p&gt;

&lt;h2 id=&quot;least-squares-loss&quot;&gt;Least squares loss&lt;/h2&gt;
&lt;p&gt;For any matrix \(A\), \(A^TA\) is always positive semidefinite, which means that \(\left \| Ax - b \right \|_{2}^{2}\) is always convex.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f(x) = \| Ax - b \|_{2}^{2}\) is convex for any \(A\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;norm&quot;&gt;Norm&lt;/h2&gt;
&lt;p&gt;All norms on \(\mathbb{R}^n\) are convex.
Let \(f:\mathbb{R}^n \mapsto \mathbb{R}\) be a norm. By definition,&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{aligned}
f(\theta x+(1−\theta)y) \le \theta f(x)+(1−\theta)f(y), \text{  with } \theta \le \theta \le 1, \text{ for all } x,y \in \text{dom} f,
\end{aligned}\)
\(\begin{aligned}
\|x\|_{p} = \left(\sum_{i=1}^{n} x_i^p\right)^{1/p} \text{ for } p \geq 1, \|x\| = \max_{i=1,.., n} |x_i|\\
\end{aligned}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;indicator-function&quot;&gt;Indicator function&lt;/h2&gt;
&lt;p&gt;For a given set \(C\), if the indicator function is defined as infinity (\(\infty\)) for elements not in \(C\) and as zero for elements in \(C\), then the indicator function is convex.&lt;/p&gt;

&lt;p&gt;In other words, by defining the function to be infinitely large outside the set \(C\) and zero within it, the convexity property is preserved.&lt;/p&gt;

&lt;blockquote&gt;
\[I_{C} (x) =
\begin{cases}
0, &amp;amp; x \in C\\
\infty, &amp;amp; x \notin C\\
\end{cases}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;support-function&quot;&gt;Support function&lt;/h2&gt;
&lt;p&gt;Consider a set \(C\). Regardless of whether \(C\) is convex, the support function of \(C\) is convex.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(I_{C}^{*} (x)\) = \(\max_{y\in C} x^Ty\) is convex&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For more on the definition of the support function, refer to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Support_function&quot;&gt;Wikipedia definition&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;max-function&quot;&gt;Max function&lt;/h2&gt;
&lt;p&gt;The max function of a finite collection of convex functions is convex.
In other words, the upper envelope formed by connecting the maxima of a set of convex functions is convex.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(f(x) = \max \{x_1,..., x_n\}\) is convex&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>03-01-01 Definition</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_01_01_convex_functions_definition/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_01_01_convex_functions_definition</id>
   <content type="html">&lt;p&gt;Why do machine learning practitioners add a tiny \(\ell_2\) weight-decay term \(\frac{\lambda}{2}\|w\|_2^2\) to an already convex loss function? Because upgrading a function from &lt;em&gt;convex&lt;/em&gt; to &lt;em&gt;strongly convex&lt;/em&gt; transforms both its geometry and its algorithmics: the minimizer becomes unique, the solution becomes stable under data perturbations, and gradient descent accelerates from slow \(O(1/k)\) convergence to exponential \(O(\rho^k)\) convergence.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-exact-hierarchy-of-convexity&quot;&gt;Key ideas: The Exact Hierarchy of Convexity&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Domain Convexity Requirement:&lt;/strong&gt; A function \(f\) cannot be convex unless its domain \(\text{dom}\,f\) is first a convex set—never skip checking \(\text{dom}\,f\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex vs. Strictly Convex:&lt;/strong&gt; Replacing \(\le\) with \(&amp;lt;\) for all \(x \neq y\) and \(\theta \in (0, 1)\) rules out linear segments on the graph and guarantees at most one global minimizer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(m\)-Strong Convexity:&lt;/strong&gt; \(f(x) - \frac{m}{2}\|x\|_2^2\) is convex (for smooth \(f\), \(\nabla^2 f(x) \succeq m I\)), placing a uniform quadratic lower envelope under every point of the graph.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strict Inclusion Chain:&lt;/strong&gt; \(\text{Strongly Convex} \implies \text{Strictly Convex} \implies \text{Convex}\), and neither arrow reverses in general.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-x4-is-strictly-convex-but-not-strongly-convex&quot;&gt;Worked example: Why \(x^4\) Is Strictly Convex but Not Strongly Convex&lt;/h3&gt;

&lt;p&gt;Compare \(f(x) = x^4\) and \(g(x) = x^4 + x^2\) on \(\mathbb{R}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test \(f(x) = x^4\):&lt;/strong&gt;
\(f&apos;&apos;(x) = 12x^2.\)
    &lt;ul&gt;
      &lt;li&gt;For all \(x \neq 0\), \(f&apos;&apos;(x) &amp;gt; 0\), and \(f&apos;&apos;\) vanishes only at the isolated point \(x = 0\) (no flat interval exists), so \(f\) is &lt;strong&gt;strictly convex&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;However, \(\inf_{x \in \mathbb{R}} f&apos;&apos;(x) = f&apos;&apos;(0) = 0\), so there is &lt;strong&gt;no&lt;/strong&gt; \(m &amp;gt; 0\) with \(12x^2 \ge m\) for all \(x\). Thus \(f(x) = x^4\) is &lt;strong&gt;not strongly convex&lt;/strong&gt; (it is too flat at the origin!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the regularized function \(g(x) = x^4 + x^2\):&lt;/strong&gt;
\(g&apos;&apos;(x) = 12x^2 + 2 \ge 2 \quad \text{for all } x \in \mathbb{R}.\)
Adding \(x^2\) lifts the curvature floor from \(0\) to \(m = 2\), making \(g\) &lt;strong&gt;\(2\)-strongly convex&lt;/strong&gt; everywhere.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;convex-function&quot;&gt;Convex function&lt;/h2&gt;

&lt;p&gt;A function \(f:\mathbb{R}^n \rightarrow \mathbb{R}\) is convex if its domain is a convex set and for any two points \(x, y \in \text{dom}f\), the function satisfies:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f(\theta x+(1-\theta)y) \le \theta f(x)+(1-\theta)f(y)\),&lt;/p&gt;

  &lt;p&gt;with \(0 \le \theta \le 1\), for all \(x,y \in \text{dom} f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This means that for any two points \(x, y\), the value of \(f\) at their convex combination is less than or equal to the convex combination of their function values. Geometrically, the graph of \(f\) lies below the line segment connecting the points \((x, f(x))\) and \((y, f(y))\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter03/convex_function2.png&quot; alt=&quot;&quot; width=&quot;70%&quot; height=&quot;70%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Convex Function [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;strictly-convex&quot;&gt;Strictly convex&lt;/h2&gt;
&lt;p&gt;A function \(f:\mathbb{R}^n \rightarrow \mathbb{R}\) is strictly convex if for any two distinct points \(x, y \in \text{dom}f\) and \(0 &amp;lt; \theta &amp;lt; 1\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f(\theta x+(1-\theta)y)&amp;lt;\theta f(x)+(1-\theta)f(y)\),&lt;/p&gt;

  &lt;p&gt;with \(0&amp;lt;\theta&amp;lt;1\), \(x \neq y\), for all \(x, y \in \text{dom}f\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;strongly-convex&quot;&gt;Strongly convex&lt;/h2&gt;
&lt;p&gt;A function \(f\) is strongly convex if \(f - \frac{m}{2}\| x \|_{2}^{2}\), with \(m &amp;gt; 0\), is convex.&lt;/p&gt;

&lt;h3 id=&quot;note-strongly-convex--strictly-convex--convex&quot;&gt;[Note] strongly convex ⇒ strictly convex ⇒ convex&lt;/h3&gt;

&lt;h2 id=&quot;concave-function&quot;&gt;Concave function&lt;/h2&gt;
&lt;p&gt;A function \(f\) is concave if \(-f\) is convex.&lt;/p&gt;

&lt;p&gt;All affine functions \(f(x) = a^T x+b\) satisfy:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\begin{aligned}
f(\theta x+(1-\theta)y) &amp;amp;= a^T (\theta x+(1-\theta)y) +b \\
&amp;amp;= \theta a^T x + (1-\theta) a^T y + \theta b + (1-\theta) b \\
&amp;amp;= \theta f(x)+(1-\theta)f(y) \\
\end{aligned}\)
\(\text{for all } x,y \in \text{dom} f, \text{with } 0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is, affine functions are always convex, and simultaneously concave.&lt;/p&gt;

&lt;h3 id=&quot;four-ways-to-check-convexity-in-about-3-minutes&quot;&gt;Four ways to check convexity in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/convexity-tests_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;The chord and Jensen on x² (the 1 and 3 example), the tangent below the graph, second derivatives and the Hessian, epigraph and sublevel sets, contrasted with the W-shaped x⁴ − 3x².&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03-01 Basic properties and examples</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_01_00_Basic_properties_and_examples/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_01_00_Basic_properties_and_examples</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Not all convex bowls have the same shape: an absolute-value V-shape $$&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(has flat sides and a sharp kink, an exponential\)e^x\(curves strictly upward everywhere yet flattens out toward\)-\infty\(, and a quadratic\)2x^2 + 3x$$ curves upward with a uniform quadratic cushion everywhere. Section 03-01 distinguishes these exact tiers—convex, strictly convex, and strongly convex—because each tier buys you a stronger uniqueness and convergence guarantee.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;key-ideas-properties--tiers-of-convex-functions&quot;&gt;Key ideas: Properties &amp;amp; Tiers of Convex Functions&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Convexity:&lt;/strong&gt; Guarantees every local minimum is global, though the set of global minimizers may contain multiple points (e.g., a flat bottom).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strict Convexity:&lt;/strong&gt; Eliminates flat segments so that a global minimizer, if it exists, is strictly &lt;strong&gt;unique&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strong Convexity (\(m &amp;gt; 0\)):&lt;/strong&gt; Bounds curvature uniformly away from zero (\(f(x) - \frac{m}{2}\|x\|_2^2\) is convex), unlocking linear (geometric) convergence rates for gradient descent.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Concavity (\(-f\) convex):&lt;/strong&gt; Flips the bowl upside down—maximizing a concave function (such as log-likelihood or utility) is identical to minimizing the convex function \(-f\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-separating-convex-strictly-convex-and-strongly-convex&quot;&gt;Worked example: Separating Convex, Strictly Convex, and Strongly Convex&lt;/h3&gt;

&lt;p&gt;Compare three 1D functions on \(\mathbb{R}\):&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**$$f_1(x) =&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;\((convex, not strictly convex):** For\)x = 1, y = 3\(,\)f_1(2) = 2 = \frac{1}{2}f_1(1) + \frac{1}{2}f_1(3)\(, so the chord coincides with the graph on\)[0, \infty)$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(f_2(x) = e^x\) (strictly convex, not strongly convex):&lt;/strong&gt; \(f_2&apos;&apos;(x) = e^x &amp;gt; 0\) everywhere (strictly convex), but \(\inf_{x \in \mathbb{R}} e^x = 0\), so no constant \(m &amp;gt; 0\) satisfies \(f_2&apos;&apos;(x) \ge m\) globally.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(f_3(x) = 2x^2 + 3x\) (\(4\)-strongly convex):&lt;/strong&gt; \(f_3&apos;&apos;(x) = 4 \ge 4\) for all \(x \in \mathbb{R}\), meaning \(f_3(x) - \frac{4}{2}x^2 = 3x\) is affine (hence convex) and gradient descent converges linearly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section covers the definition of convex functions, representative types of convex functions, and their key properties.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>03 Convex functions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_00_Convex_functions/"/>
   <updated>2021-02-12T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter03/03_00_Convex_functions</id>
   <content type="html">&lt;p&gt;Chapter 02 taught us how to build well-behaved feasible &lt;em&gt;regions&lt;/em&gt;; Chapter 03 teaches us how to recognize and construct well-behaved &lt;em&gt;objectives&lt;/em&gt;—convex functions, their Fenchel conjugates, quasiconvex extensions, and log-concave densities. Once you see that a function’s convexity is simply the convexity of the bowl-shaped set sitting above its graph (its epigraph), every theorem in this chapter locks together into one unified picture.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-architecture-of-chapter-03&quot;&gt;Key ideas: The Architecture of Chapter 03&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Core Characterizations:&lt;/strong&gt; Connect the chord inequality (definition), tangent lower bounds (first-order), nonnegative curvature (second-order), and epigraph geometry.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convexity-Preserving Calculus:&lt;/strong&gt; Build complex convex objectives (like regularized logistic or Huber losses) from simple atoms via weighted sums, compositions, pointwise maxima, and perspective.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fenchel Conjugacy (\(f^*\)):&lt;/strong&gt; Dualizes a convex function by re-indexing it by slope instead of position—the algebraic heart of Lagrange duality and proximal operators.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Generalized Convexity:&lt;/strong&gt; Extend convexity to unimodal &lt;em&gt;quasiconvex&lt;/em&gt; functions (solved via convex feasibility bisection), &lt;em&gt;log-concave&lt;/em&gt; probability densities, and vector-valued &lt;em&gt;\(K\)-convex&lt;/em&gt; functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-checking-the-chord-inequality-on-fx--x2&quot;&gt;Worked example: Checking the Chord Inequality on \(f(x) = x^2\)&lt;/h3&gt;

&lt;p&gt;Test \(f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y)\) on \(f(x) = x^2\) with \(x = 0\), \(y = 4\), and \(\theta = 0.25\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the convex combination of inputs and its function value:&lt;/strong&gt;
\(z = 0.25(0) + 0.75(4) = 3 \implies f(z) = 3^2 = 9.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the matching point on the secant chord connecting \((0, 0)\) and \((4, 16)\):&lt;/strong&gt;
\(0.25 f(0) + 0.75 f(4) = 0.25(0) + 0.75(16) = 12.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare:&lt;/strong&gt; \(9 &amp;lt; 12\), showing that the graph of \(x^2\) bows strictly beneath its chord—a visual signature of strict convexity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we will study the definition, examples, key properties of convex functions, and operations that preserve convexity.&lt;/p&gt;

&lt;p&gt;An optional follow-up, &lt;a href=&quot;/contents/en/chapter03/03_08_Applications_Recent/&quot;&gt;03-08 Applications and recent developments&lt;/a&gt;, revisits log-sum-exp in calibration, neural collapse, and contrastive losses.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02 Tập Lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_Convex_sets/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_Convex_sets</id>
   <content type="html">&lt;p&gt;Hãy hình dung bạn đang đứng trong một căn phòng và muốn nhìn thẳng tới một người bạn ở góc phòng kia mà không bị bức tường nào che khuất. Nếu &lt;em&gt;bất kỳ&lt;/em&gt; hai người nào đứng trong phòng đều luôn nhìn thấy nhau qua một đường thẳng không đụng tường, thì căn phòng đó chính là một &lt;strong&gt;tập lồi&lt;/strong&gt;! Hình ảnh giản dị ấy lại ẩn chứa sức mạnh phi thường của Chương 02: trong tối ưu hóa, miền khả thi lồi đảm bảo ta luôn có thể trượt thẳng từ một phương án tốt sang một phương án tốt hơn mà không bao giờ bị vướng “góc lõm” hay rơi ra ngoài vùng hợp lệ.&lt;/p&gt;

&lt;p&gt;Chương 02 xây dựng toàn bộ hình học của không gian tìm kiếm lồi — từ đoạn thẳng, siêu phẳng, đa diện, hình nón bán xác định dương cho tới các định lý phân tách và hình nón đối ngẫu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-hình-học-của-chương-02&quot;&gt;Kiến thức cần nhớ: Bốn nhánh hình học của Chương 02&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân cấp tổ hợp tuyến tính:&lt;/strong&gt; Từ đường thẳng (tập affine) \(\to\) đoạn thẳng (tập lồi) \(\to\) tia không âm (hình nón lồi), chỉ bằng cách thêm dần các ràng buộc đơn giản lên trọng số \(\theta_i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kho tàng các tập lồi kinh điển:&lt;/strong&gt; Siêu phẳng, nửa không gian, đa diện (LP), hình cầu chuẩn và ellipsoid (SOCP/QP), và hình nón ma trận bán xác định dương \(\mathbb{S}_+^n\) (SDP).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép toán bảo toàn tính lồi:&lt;/strong&gt; Cách kiểm chứng một miền khả thi phức tạp là lồi mà không cần chứng minh trực tiếp từ định nghĩa, thông qua giao, ánh xạ affine và ánh xạ phối cảnh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tách, hỗ trợ và đối ngẫu hình học:&lt;/strong&gt; Định lý siêu phẳng phân tách và hình nón đối ngẫu — chiếc cầu hình học trực tiếp dẫn tới lý thuyết đối ngẫu Lagrange và điều kiện KKT ở các chương sau.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phân-biệt-tập-lồi-và-tập-không-lồi-trên-mặt-phẳng-mathbbr2&quot;&gt;Giải thích: Phân biệt tập lồi và tập không lồi trên mặt phẳng \(\mathbb{R}^2\)&lt;/h3&gt;

&lt;p&gt;So sánh hai miền trong \(\mathbb{R}^2\): hình vuông đơn vị \(C = [0, 1]^2\) và hình chữ L \(S = [0, 2]^2 \setminus (1, 2]^2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra hình vuông \(C = [0, 1]^2\):&lt;/strong&gt; Lấy hai điểm bất kỳ \(x = (x_1, x_2),\ y = (y_1, y_2) \in C\) và \(\theta \in [0, 1]\). Tọa độ thứ nhất của tổ hợp lồi là \(z_1 = \theta x_1 + (1-\theta)y_1\). Vì \(0 \le x_1, y_1 \le 1\), ta có \(0 \le z_1 \le \theta\cdot 1 + (1-\theta)\cdot 1 = 1\) (tương tự cho \(z_2\)). Vậy \(z \in C\), chứng tỏ \(C\) là &lt;strong&gt;tập lồi&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bác bỏ tính lồi của hình chữ L \(S\) bằng một phản ví dụ:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Chọn \(x = (0.5,\ 1.8) \in S\) (vì \(0.5 \le 1\)) và \(y = (1.8,\ 0.5) \in S\) (vì \(0.5 \le 1\)).&lt;/li&gt;
      &lt;li&gt;Lấy trung điểm (\(\theta = 0.5\)):
\(z = \frac{1}{2}(0.5, 1.8) + \frac{1}{2}(1.8, 0.5) = (1.15,\ 1.15).\)&lt;/li&gt;
      &lt;li&gt;Vì cả hai tọa độ đều lớn hơn \(1\), điểm \(z = (1.15, 1.15)\) rơi vào góc khuyết \((1, 2]^2\) nên \(z \notin S\)! Chỉ cần một đoạn thẳng cắt ra ngoài, \(S\) lập tức &lt;strong&gt;không lồi&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong chương này, chúng ta sẽ tìm hiểu khái niệm tập lồi — nền tảng của tối ưu hóa lồi.&lt;/p&gt;

&lt;h3 id=&quot;bối-cảnh&quot;&gt;Bối cảnh&lt;/h3&gt;
&lt;p&gt;Tối ưu hóa lồi nghiên cứu các phương pháp tìm cực đại hoặc cực tiểu cho những bài toán được xây dựng bằng hàm lồi. Tập lồi gắn bó chặt chẽ với hàm lồi theo hai phương diện chính:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hàm lồi được xác định trên tập lồi. Miền xác định và miền giá trị của hàm có vai trò trực tiếp trong việc định nghĩa và suy ra các tính chất cơ bản của hàm lồi.&lt;/li&gt;
  &lt;li&gt;Khi chuyển được một bài toán tối ưu hóa về dạng có hàm lồi, bài toán thường dễ giải hơn đáng kể. Trong nhiều trường hợp không dễ nhận biết trực tiếp một hàm có lồi hay không, ta có thể kiểm tra xem epigraph (trên đồ thị) của hàm đó có phải là tập lồi hay không.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;nội-dung&quot;&gt;Nội dung&lt;/h3&gt;
&lt;p&gt;Chương này trình bày định nghĩa và các ví dụ tiêu biểu về tập lồi, những tính chất cơ bản của chúng, cùng các phép toán bảo toàn tính lồi.&lt;/p&gt;

&lt;p&gt;Xem thêm bài tùy chọn &lt;a href=&quot;/contents/vi/chapter02/02_07_Applications_Recent/&quot;&gt;02-07 Ứng dụng và phát triển gần đây&lt;/a&gt; về đơn hình, quả cầu Wasserstein và polytope công bằng.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-09 Bài Tập Thực Hành - Tập Convex</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_09_Practical_Exercises_Convex_Sets/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_09_Practical_Exercises_Convex_Sets</id>
   <content type="html">&lt;p&gt;Biết phát biểu định lý siêu phẳng phân tách hay định nghĩa hình nón đối ngẫu trên lớp là bước đầu; thực sự viết ra được phương trình siêu phẳng, tính chính xác bao lồi, và vẽ/kiểm chứng được hình nón đối ngẫu bằng cả tay lẫn code mới biến kiến thức Chương 02 thành phản xạ nghề nghiệp.&lt;/p&gt;

&lt;p&gt;Trong bài tập thực hành này, bạn sẽ trực tiếp kiểm tra tính lồi, dựng siêu phẳng phân tách và tính hình nón đối ngẫu. Dưới đây là khung tư duy nhanh và một bài tính tay mẫu về hình nón đối ngẫu đa diện.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-kỹ-năng-thực-hành-cốt-lõi-của-chương-02&quot;&gt;Kiến thức cần nhớ: Bốn kỹ năng thực hành cốt lõi của Chương 02&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra và chứng minh tính lồi:&lt;/strong&gt; Phân biệt khi nào nên dùng định nghĩa trực tiếp, khi nào nên phân rã qua phép giao/ánh xạ affine, và khi nào nên tìm một phản ví dụ 2 điểm để bác bỏ ngay.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính toán siêu phẳng phân tách (SVM &amp;amp; Khoảng cách nhỏ nhất):&lt;/strong&gt; Tìm cặp điểm gần nhau nhất giữa hai tập lồi rồi lấy đường trung trực làm siêu phẳng phân tách biên cực đại.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác định bao lồi (Convex Hull):&lt;/strong&gt; Nhận diện các đỉnh cực biên (extreme points) và loại bỏ các điểm nằm bên trong là tổ hợp lồi của các đỉnh còn lại.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hình nón đối ngẫu đa diện:&lt;/strong&gt; Với hình nón sinh bởi hữu hạn tia \(K = \operatorname{cone}\{v_1, \dots, v_m\}\), điều kiện \(y \in K^*\) rút gọn ngay thành đúng \(m\) bất đẳng thức tuyến tính \(v_i^T y \ge 0\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-hình-nón-đối-ngẫu-của-một-hình-nón-đa-diện-trong-mathbbr2&quot;&gt;Giải thích: Tính tay hình nón đối ngẫu của một hình nón đa diện trong \(\mathbb{R}^2\)&lt;/h3&gt;

&lt;p&gt;Cho hình nón sinh bởi hai tia \(v_1 = (1, 0)^T\) và \(v_2 = (1, 2)^T\):
\(K = \{\theta_1 (1, 0)^T + \theta_2 (1, 2)^T : \theta_1, \theta_2 \ge 0\}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập điều kiện đối ngẫu \(y = (y_1, y_2)^T \in K^*\):&lt;/strong&gt;
Vì mọi phần tử của \(K\) là tổ hợp không âm của \(v_1, v_2\), ta chỉ cần kiểm tra tích vô hướng không âm với đúng hai tia sinh:
    &lt;ul&gt;
      &lt;li&gt;\(v_1^T y \ge 0 \iff 1\cdot y_1 + 0\cdot y_2 \ge 0 \iff y_1 \ge 0\).&lt;/li&gt;
      &lt;li&gt;\(v_2^T y \ge 0 \iff 1\cdot y_1 + 2\cdot y_2 \ge 0 \iff y_2 \ge -\frac{1}{2}y_1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm hai tia biên sinh ra hình nón đối ngẫu \(K^*\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Khi ràng buộc thứ nhất chặt (\(y_1 = 0\)) và ràng buộc thứ hai thỏa (\(2y_2 \ge 0\)): ta được tia \(w_1 = (0, 1)^T\).&lt;/li&gt;
      &lt;li&gt;Khi ràng buộc thứ hai chặt (\(y_1 + 2y_2 = 0\)) và ràng buộc thứ nhất thỏa (\(y_1 \ge 0\)): ta được tia \(w_2 = (2, -1)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra chéo góc vuông giữa biên \(K\) và biên \(K^*\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(w_1^T v_1 = 0(1) + 1(0) = 0\) (vuông góc!) và \(w_1^T v_2 = 2 &amp;gt; 0\).&lt;/li&gt;
      &lt;li&gt;\(w_2^T v_2 = 2(1) + (-1)(2) = 0\) (vuông góc!) và \(w_2^T v_1 = 2 &amp;gt; 0\).
Kết luận: \(K^* = \operatorname{cone}\{(0, 1)^T,\ (2, -1)^T\}\) — đúng với trực giác \(K\) góc nhọn (khoảng \(63.4^\circ\)) thì \(K^*\) mở rộng thành góc tù (\(180^\circ - 63.4^\circ = 116.6^\circ\))!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---tập-lồi&quot;&gt;Bài tập thực hành - Tập lồi&lt;/h1&gt;

&lt;h2 id=&quot;bài-tập-1-kiểm-tra-tính-lồi-của-tập-hợp&quot;&gt;&lt;strong&gt;Bài tập 1: Kiểm tra tính lồi của tập hợp&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 2.1 từ Boyd &amp;amp; Vandenberghe)
Xác định tính lồi của các tập hợp sau:&lt;/p&gt;

&lt;p&gt;a) \(S_1 = \{x \in \mathbb{R}^n : \lVert x \rVert_2 \leq 1\}\)&lt;/p&gt;

&lt;p&gt;b) \(S_2 = \{x \in \mathbb{R}^n : \lVert x \rVert_\infty \leq 1\}\)&lt;/p&gt;

&lt;p&gt;c) \(S_3 = \{x \in \mathbb{R}^n : x^T P x \leq 1\}\) với \(P \succeq 0\)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;d) $$S_4 = {x \in \mathbb{R}^n :&lt;/td&gt;
      &lt;td&gt;x_i&lt;/td&gt;
      &lt;td&gt;\leq a_i, i = 1,\ldots,n}\((với\)a_i \ge 0$$)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh tính lồi bằng định nghĩa&lt;/li&gt;
  &lt;li&gt;Kiểm tra lại bằng các phép toán bảo toàn tính lồi&lt;/li&gt;
  &lt;li&gt;Minh họa trong \(\mathbb{R}^2\)&lt;/li&gt;
  &lt;li&gt;Tìm các điểm cực biên (extreme points) của mỗi tập&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Chứng minh bằng định nghĩa&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;a) Hình cầu \(\ell_2\):&lt;/strong&gt; \(S_1 = \{x : \lVert x \rVert_2 \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;Với mọi \(x, y \in S_1\) và \(\theta \in [0,1]\):
\(\lVert \theta x + (1-\theta) y \rVert_2 \leq \theta \lVert x \rVert_2 + (1-\theta) \lVert y \rVert_2 \leq \theta \cdot 1 + (1-\theta) \cdot 1 = 1\)&lt;/p&gt;

  &lt;p&gt;\(\Rightarrow\) \(S_1\) là tập lồi.&lt;/p&gt;

  &lt;table&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;strong&gt;b) Hình cầu \(\ell_\infty\):&lt;/strong&gt; $$S_2 = {x : \max_i&lt;/td&gt;
        &lt;td&gt;x_i&lt;/td&gt;
        &lt;td&gt;\leq 1}$$&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

\[\max_i |\theta x_i + (1-\theta) y_i| \leq \max_i (\theta |x_i| + (1-\theta) |y_i|) \leq \theta \max_i |x_i| + (1-\theta) \max_i |y_i| \leq 1\]

  &lt;p&gt;\(\Rightarrow\) \(S_2\) là tập lồi.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Ellipsoid:&lt;/strong&gt; \(S_3 = \{x : x^T P x \leq 1\}\) với \(P \succeq 0\)&lt;/p&gt;

\[(\theta x + (1-\theta) y)^T P (\theta x + (1-\theta) y) = \theta^2 x^T P x + 2\theta(1-\theta) x^T P y + (1-\theta)^2 y^T P y\]

  &lt;p&gt;Vì \(P \succeq 0\), dạng toàn phương \(x^T P x\) là hàm lồi, do đó tập mức dưới \(S_3\) là tập lồi.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Hình hộp chữ nhật (hyperrectangle):&lt;/strong&gt; \(S_4 = \prod_{i=1}^n [-a_i, a_i]\)&lt;/p&gt;

  &lt;p&gt;Tích Descartes của các tập lồi (các đoạn đóng) là một tập lồi.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Các phép toán bảo toàn tính lồi&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;a, b:&lt;/strong&gt; Tập mức dưới của hàm lồi (các hàm chuẩn)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;c:&lt;/strong&gt; Tập mức dưới của dạng toàn phương lồi&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;d:&lt;/strong&gt; Tích Descartes của các đoạn đóng lồi&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Điểm cực biên&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;a:&lt;/strong&gt; Biên \(\{x : \lVert x \rVert_2 = 1\}\) (vô số điểm cực biên)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;b:&lt;/strong&gt; Các đỉnh \(\{(\pm 1, \ldots, \pm 1)\}\) (\(2^n\) điểm cực biên; các điểm \(\pm e_i\) là đỉnh của quả cầu \(\ell_1\), không phải của quả cầu \(\ell_\infty\))&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;c:&lt;/strong&gt; Phụ thuộc vào \(P\): nếu \(P \succ 0\), mọi điểm trên biên \(x^T P x = 1\) đều là điểm cực biên; nếu \(P\) suy biến, tập chứa trọn một đường thẳng nên không có điểm cực biên&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;d:&lt;/strong&gt; Các đỉnh \(\{(\pm a_1, \ldots, \pm a_n)\}\) (\(2^n\) điểm cực biên khi \(a_i &amp;gt; 0\) với mọi \(i\))&lt;/li&gt;
  &lt;/ul&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-2-các-phép-toán-bảo-toàn-tính-lồi&quot;&gt;&lt;strong&gt;Bài tập 2: Các phép toán bảo toàn tính lồi&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 2.2 từ Boyd &amp;amp; Vandenberghe)
Cho hai tập lồi \(C_1, C_2 \subseteq \mathbb{R}^n\). Chứng minh hoặc đưa ra phản ví dụ về tính lồi của:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Giao:&lt;/strong&gt; \(C_1 \cap C_2\)&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Hợp:&lt;/strong&gt; \(C_1 \cup C_2\)&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Tổng Minkowski:&lt;/strong&gt; \(C_1 + C_2 = \{x + y : x \in C_1, y \in C_2\}\)&lt;/p&gt;

&lt;p&gt;d) &lt;strong&gt;Tích Descartes:&lt;/strong&gt; \(C_1 \times C_2\)&lt;/p&gt;

&lt;p&gt;e) &lt;strong&gt;Biến đổi affine:&lt;/strong&gt; \(f(C_1) = \{Ax + b : x \in C_1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh chặt chẽ cho các trường hợp đúng&lt;/li&gt;
  &lt;li&gt;Đưa ra phản ví dụ cho các trường hợp sai&lt;/li&gt;
  &lt;li&gt;Minh họa bằng các ví dụ cụ thể&lt;/li&gt;
  &lt;li&gt;Tổng quát hóa cho họ tập hợp bất kỳ&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Giao — LỒI&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt; Với mọi \(x, y \in C_1 \cap C_2\) và \(\theta \in [0,1]\):&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x, y \in C_1 \Rightarrow \theta x + (1-\theta) y \in C_1\) (vì \(C_1\) lồi)&lt;/li&gt;
      &lt;li&gt;\(x, y \in C_2 \Rightarrow \theta x + (1-\theta) y \in C_2\) (vì \(C_2\) lồi)&lt;/li&gt;
      &lt;li&gt;
\[\Rightarrow \theta x + (1-\theta) y \in C_1 \cap C_2\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Tổng quát hóa:&lt;/strong&gt; \(\bigcap_{i \in I} C_i\) là tập lồi nếu mỗi \(C_i\) là tập lồi.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Hợp — KHÔNG LỒI&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Phản ví dụ:&lt;/strong&gt; \(C_1 = \{(x,0) : x \geq 0\}\), \(C_2 = \{(0,y) : y \geq 0\}\)&lt;/p&gt;

  &lt;p&gt;Cả hai tập đều lồi, nhưng \(C_1 \cup C_2\) không lồi:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\((1,0) \in C_1 \cup C_2\) và \((0,1) \in C_1 \cup C_2\)&lt;/li&gt;
    &lt;li&gt;
\[\frac{1}{2}(1,0) + \frac{1}{2}(0,1) = (\frac{1}{2}, \frac{1}{2}) \notin C_1 \cup C_2\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Tổng Minkowski — LỒI&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt; Với mọi \(z_1, z_2 \in C_1 + C_2\):&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;Viết \(z_1 = x_1 + y_1\), \(z_2 = x_2 + y_2\) với \(x_i \in C_1, y_i \in C_2\)&lt;/li&gt;
      &lt;li&gt;
\[\theta z_1 + (1-\theta) z_2 = \theta(x_1 + y_1) + (1-\theta)(x_2 + y_2)\]
      &lt;/li&gt;
      &lt;li&gt;
\[= (\theta x_1 + (1-\theta) x_2) + (\theta y_1 + (1-\theta) y_2)\]
      &lt;/li&gt;
      &lt;li&gt;\(\in C_1 + C_2\) (vì \(C_1, C_2\) lồi)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Bước 4: Tích Descartes — LỒI&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt; Với mọi \((x_1, y_1), (x_2, y_2) \in C_1 \times C_2\):
\(\theta(x_1, y_1) + (1-\theta)(x_2, y_2) = (\theta x_1 + (1-\theta) x_2, \theta y_1 + (1-\theta) y_2) \in C_1 \times C_2\)&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Bước 5: Biến đổi affine — LỒI&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt; Với mọi \(z_1, z_2 \in f(C_1)\):&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;Viết \(z_i = Ax_i + b\) với \(x_i \in C_1\)&lt;/li&gt;
      &lt;li&gt;
\[\theta z_1 + (1-\theta) z_2 = A(\theta x_1 + (1-\theta) x_2) + b \in f(C_1)\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-3-siêu-phẳng-phân-tách&quot;&gt;&lt;strong&gt;Bài tập 3: Siêu phẳng phân tách&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 2.3 từ Boyd &amp;amp; Vandenberghe)
Cho hai tập lồi rời nhau \(C, D \subset \mathbb{R}^n\) (\(C \cap D = \emptyset\)).&lt;/p&gt;

&lt;p&gt;a) Chứng minh tồn tại siêu phẳng phân tách&lt;/p&gt;

&lt;p&gt;b) Tìm một siêu phẳng phân tách cho mỗi cặp tập sau:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(C = \{x : \lVert x \rVert_2 \leq 1\}\), \(D = \{x : \lVert x - (3,0) \rVert_2 \leq 1\}\)&lt;/li&gt;
  &lt;li&gt;\(C = \{x : x_1 + x_2 \leq 1, x_1, x_2 \geq 0\}\), \(D = \{(2,2)\}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh kiến thiết cho định lý siêu phẳng phân tách&lt;/li&gt;
  &lt;li&gt;Tính toán tường minh cho hai ví dụ trên&lt;/li&gt;
  &lt;li&gt;Minh họa hình học sự phân tách&lt;/li&gt;
  &lt;li&gt;Phân tích trường hợp hai tập tiếp xúc tại biên&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Định lý siêu phẳng phân tách&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-theorem&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; Nếu \(C, D\) là hai tập lồi không rỗng và rời nhau, thì tồn tại \(a \neq 0\) và \(b \in \mathbb{R}\) sao cho:
\(a^T x \leq b \leq a^T y, \quad \forall x \in C, y \in D\)&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Chứng minh kiến thiết (trường hợp \(C, D\) đóng và ít nhất một tập bị chặn):&lt;/strong&gt;&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;Xét tập hiệu \(S = C - D = \{x - y : x \in C, y \in D\}\) (là tập lồi)&lt;/li&gt;
    &lt;li&gt;Ta có \(0 \notin S\) (vì \(C \cap D = \emptyset\))&lt;/li&gt;
    &lt;li&gt;Tìm điểm \(s^* \in S\) gần gốc tọa độ nhất: \(s^* = \arg\min_{s \in S} \lVert s \rVert_2\)&lt;/li&gt;
    &lt;li&gt;Viết \(s^* = x^* - y^*\) (\(x^* \in C\), \(y^* \in D\)). Đặt \(a = y^* - x^* = -s^*\) và \(b = \frac{1}{2}(\lVert y^* \rVert_2^2 - \lVert x^* \rVert_2^2)\) (siêu phẳng trung trực của đoạn \(x^* y^*\)). Điều kiện tối ưu của \(s^*\) cho \(s^{*T}(s - s^*) \geq 0\) với mọi \(s \in S\), từ đó suy ra \(a^T x \leq b \leq a^T y\).&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Ví dụ 1 — Hai hình cầu&lt;/strong&gt;
\(C = \{x : \lVert x \rVert_2 \leq 1\}\), \(D = \{x : \lVert x - (3,0) \rVert_2 \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Cách tiếp cận hình học:&lt;/strong&gt; Hai tâm đặt tại \((0,0)\) và \((3,0)\), cùng bán kính bằng 1. Đường thẳng phân tách vuông góc với đoạn nối hai tâm.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt; \(a = (1,0)\), \(b = 1.5\). Siêu phẳng phân tách là \(x_1 = 1.5\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Kiểm tra:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[\max_{x \in C} x_1 = 1 &amp;lt; 1.5\]
    &lt;/li&gt;
    &lt;li&gt;
\[\min_{x \in D} x_1 = 2 &amp;gt; 1.5\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Ví dụ 2 — Đơn hình và một điểm&lt;/strong&gt;
\(C = \{x : x_1 + x_2 \leq 1, x_1, x_2 \geq 0\}\), \(D = \{(2,2)\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Cách tiếp cận:&lt;/strong&gt; Tìm điểm trong \(C\) gần \((2,2)\) nhất bằng bài toán tối ưu:
\(\min_{x \in C} \lVert x - (2,2) \rVert_2^2\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Điều kiện KKT:&lt;/strong&gt; Điểm gần nhất là \((1/2, 1/2)\) (hình chiếu của \((2,2)\) lên cạnh \(x_1 + x_2 = 1\)), với khoảng cách \(\frac{3}{\sqrt{2}}\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt; Chọn \(a = (1,1)\) (cùng hướng với \((2,2) - (1/2,1/2)\)) và \(b = 1.5\), thu được siêu phẳng \(x_1 + x_2 = 1.5\). Tổng quát, mọi \(b \in (1, 4)\) đều tách được hai tập; siêu phẳng trung trực là \(x_1 + x_2 = 2.5\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-4-tính-bao-lồi&quot;&gt;&lt;strong&gt;Bài tập 4: Tính bao lồi&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 2.4 từ Boyd &amp;amp; Vandenberghe)
Tính bao lồi của các tập hợp sau:&lt;/p&gt;

&lt;p&gt;a) \(S_1 = \{(0,0), (1,0), (0,1), (1,1)\}\) trong \(\mathbb{R}^2\)&lt;/p&gt;

&lt;p&gt;b) \(S_2 = \{x \in \mathbb{R}^3 : \lVert x \rVert_2 = 1, x_3 = 0\} \cup \{(0,0,1), (0,0,-1)\}\)&lt;/p&gt;

&lt;p&gt;c) \(S_3 = \{(t, t^2) : t \in [-1,1]\}\) trong \(\mathbb{R}^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Tính tường minh bao lồi&lt;/li&gt;
  &lt;li&gt;Xác định các điểm cực biên&lt;/li&gt;
  &lt;li&gt;Mô tả bằng hệ bất đẳng thức nếu có thể&lt;/li&gt;
  &lt;li&gt;Minh họa kết quả&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Tập hữu hạn điểm&lt;/strong&gt;
\(S_1 = \{(0,0), (1,0), (0,1), (1,1)\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bao lồi:&lt;/strong&gt; Hình vuông đơn vị \([0,1] \times [0,1]\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Điểm cực biên:&lt;/strong&gt; Cả 4 điểm trong \(S_1\) đều là điểm cực biên.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Biểu diễn bằng bất đẳng thức:&lt;/strong&gt;
\(\text{conv}(S_1) = \{x : 0 \leq x_1 \leq 1, 0 \leq x_2 \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Đường tròn và hai đỉnh&lt;/strong&gt;
\(S_2 = \{x \in \mathbb{R}^3 : x_1^2 + x_2^2 = 1, x_3 = 0\} \cup \{(0,0,1), (0,0,-1)\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bao lồi:&lt;/strong&gt; Hình nón đôi (double cone):
\(\text{conv}(S_2) = \{x \in \mathbb{R}^3 : x_1^2 + x_2^2 \leq (1 - |x_3|)^2, |x_3| \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Điểm cực biên:&lt;/strong&gt; Đường tròn \(\{x : x_1^2 + x_2^2 = 1, x_3 = 0\}\) và hai đỉnh \((0,0,\pm 1)\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Cung parabol&lt;/strong&gt;
\(S_3 = \{(t, t^2) : t \in [-1,1]\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bao lồi:&lt;/strong&gt; Miền nằm phía trên cung parabol và phía dưới dây cung \(x_2 = 1\):
\(\text{conv}(S_3) = \{(x_1, x_2) : x_1^2 \leq x_2 \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Điểm cực biên:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Mọi điểm \((t, t^2)\) với \(t \in [-1,1]\) trên cung parabol (kể cả hai đầu mút \((\pm 1, 1)\))&lt;/li&gt;
    &lt;li&gt;Các điểm trong của đoạn thẳng \(x_2 = 1\) không phải là điểm cực biên&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Cách viết khác:&lt;/strong&gt;
\(\text{conv}(S_3) = \{(x_1, x_2) : x_2 \geq x_1^2,\ x_2 \leq 1\}\) (điều kiện \(|x_1| \leq 1\) tự suy ra).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-5-hình-nón-đối-ngẫu&quot;&gt;&lt;strong&gt;Bài tập 5: Hình nón đối ngẫu&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 2.5 từ Boyd &amp;amp; Vandenberghe)
Tìm hình nón đối ngẫu của các hình nón sau:&lt;/p&gt;

&lt;p&gt;a) \(K_1 = \mathbb{R}_+^n = \{x \in \mathbb{R}^n : x_i \geq 0, \forall i\}\)&lt;/p&gt;

&lt;p&gt;b) \(K_2 = \{x \in \mathbb{R}^n : \lVert (x_1, \ldots, x_{n-1}) \rVert_2 \leq x_n\}\) (hình nón bậc hai)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;c) $$K_3 = {x \in \mathbb{R}^n : \sum_{i=1}^{n-1}&lt;/td&gt;
      &lt;td&gt;x_i&lt;/td&gt;
      &lt;td&gt;\leq x_n}\((hình nón\)\ell_1$$)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;d) \(K_4 = \{X \in \mathbb{S}^n : X \succeq 0\}\) (hình nón nửa xác định dương)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Tính hình nón đối ngẫu \(K^* = \{y : y^T x \geq 0, \forall x \in K\}\)&lt;/li&gt;
  &lt;li&gt;Kiểm tra tính tự đối ngẫu (nếu có)&lt;/li&gt;
  &lt;li&gt;Thiết lập các quan hệ đối ngẫu&lt;/li&gt;
  &lt;li&gt;Giải thích ý nghĩa hình học&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Góc phần tư không âm&lt;/strong&gt;
\(K_1^* = \{y : y^T x \geq 0, \forall x \in \mathbb{R}_+^n\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Phân tích:&lt;/strong&gt; \(y^T x = \sum_{i=1}^n y_i x_i \geq 0\) với mọi \(x_i \geq 0\) \(\Rightarrow y_i \geq 0, \forall i\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt; \(K_1^* = \mathbb{R}_+^n = K_1\) (tự đối ngẫu).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Hình nón bậc hai&lt;/strong&gt;
\(K_2 = \{x : \lVert (x_1, \ldots, x_{n-1}) \rVert_2 \leq x_n\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Đối ngẫu:&lt;/strong&gt; \(K_2^* = \{y : y^T x \geq 0, \forall x \in K_2\} = K_2\) (tự đối ngẫu).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Ý tưởng chứng minh:&lt;/strong&gt; Áp dụng bất đẳng thức Cauchy–Schwarz và tính thuần nhất của chuẩn \(\ell_2\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Hình nón \(\ell_1\)&lt;/strong&gt;
\(K_3 = \{x : \sum_{i=1}^{n-1} |x_i| \leq x_n\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Đối ngẫu:&lt;/strong&gt; \(K_3^* = \{y : \lVert (y_1, \ldots, y_{n-1}) \rVert_\infty \leq y_n\}\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Kiểm chứng:&lt;/strong&gt; Dựa trên tính đối ngẫu giữa chuẩn \(\ell_1\) và chuẩn \(\ell_\infty\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 4: Hình nón nửa xác định dương (PSD)&lt;/strong&gt;
\(K_4 = \{X \in \mathbb{S}^n : X \succeq 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Đối ngẫu:&lt;/strong&gt; \(K_4^* = \{Y \in \mathbb{S}^n : \text{tr}(YX) \geq 0, \forall X \succeq 0\} = K_4\) (tự đối ngẫu).&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt; \(Y \succeq 0 \Leftrightarrow \text{tr}(YX) \geq 0, \forall X \succeq 0\).&lt;/p&gt;
  &lt;/div&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-6-phép-chiếu-lên-tập-lồi&quot;&gt;&lt;strong&gt;Bài tập 6: Phép chiếu lên tập lồi&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 2.6 từ Boyd &amp;amp; Vandenberghe)
Tính hình chiếu Euclidean của điểm \(x_0\) lên tập lồi \(C\):&lt;/p&gt;

\[\text{proj}_C(x_0) = \arg\min_{x \in C} \lVert x - x_0 \rVert_2\]

&lt;p&gt;a) \(C = \{x : a^T x = b\}\) (siêu phẳng)&lt;/p&gt;

&lt;p&gt;b) \(C = \{x : a^T x \leq b\}\) (nửa không gian)&lt;/p&gt;

&lt;p&gt;c) \(C = \{x : \lVert x \rVert_2 \leq r\}\) (hình cầu \(\ell_2\))&lt;/p&gt;

&lt;p&gt;d) \(C = \{x : \lVert x \rVert_\infty \leq r\}\) (hình cầu \(\ell_\infty\))&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Tìm công thức nghiệm đóng&lt;/li&gt;
  &lt;li&gt;Kiểm tra điều kiện tối ưu&lt;/li&gt;
  &lt;li&gt;Phân tích tính duy nhất của hình chiếu&lt;/li&gt;
  &lt;li&gt;Xây dựng thuật toán tính toán&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Phép chiếu lên siêu phẳng&lt;/strong&gt;
\(C = \{x : a^T x = b\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Hàm Lagrange:&lt;/strong&gt; \(L(x,\lambda) = \frac{1}{2}\lVert x - x_0 \rVert_2^2 + \lambda(a^T x - b)\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Điều kiện tối ưu:&lt;/strong&gt; \(x - x_0 + \lambda a = 0 \Rightarrow x = x_0 - \lambda a\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Ràng buộc:&lt;/strong&gt; \(a^T(x_0 - \lambda a) = b \Rightarrow \lambda = \frac{a^T x_0 - b}{\lVert a \rVert_2^2}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt; \(\text{proj}_C(x_0) = x_0 - \frac{a^T x_0 - b}{\lVert a \rVert_2^2} a\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Phép chiếu lên nửa không gian&lt;/strong&gt;
\(C = \{x : a^T x \leq b\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Xét hai trường hợp:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Nếu \(a^T x_0 \leq b\): \(\text{proj}_C(x_0) = x_0\)&lt;/li&gt;
    &lt;li&gt;Nếu \(a^T x_0 &amp;gt; b\): chiếu lên siêu phẳng biên \(a^T x = b\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt;
\(\text{proj}_C(x_0) = \begin{cases} 
x_0 &amp;amp; \text{nếu } a^T x_0 \leq b \\
x_0 - \frac{a^T x_0 - b}{\lVert a \rVert_2^2} a &amp;amp; \text{nếu } a^T x_0 &amp;gt; b
\end{cases}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Phép chiếu lên hình cầu \(\ell_2\)&lt;/strong&gt;
\(C = \{x : \lVert x \rVert_2 \leq r\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Xét hai trường hợp:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Nếu \(\lVert x_0 \rVert_2 \leq r\): \(\text{proj}_C(x_0) = x_0\)&lt;/li&gt;
    &lt;li&gt;Nếu \(\lVert x_0 \rVert_2 &amp;gt; r\): chiếu theo phương bán kính lên mặt cầu biên&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt;
\(\text{proj}_C(x_0) = \begin{cases}
x_0 &amp;amp; \text{nếu } \lVert x_0 \rVert_2 \leq r \\
r \frac{x_0}{\lVert x_0 \rVert_2} &amp;amp; \text{nếu } \lVert x_0 \rVert_2 &amp;gt; r
\end{cases}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 4: Phép chiếu lên hình cầu \(\ell_\infty\)&lt;/strong&gt;
\(C = \{x : \lVert x \rVert_\infty \leq r\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Phép chiếu theo từng thành phần:&lt;/strong&gt;
\([\text{proj}_C(x_0)]_i = \begin{cases}
x_{0i} &amp;amp; \text{nếu } |x_{0i}| \leq r \\
r \cdot \text{sign}(x_{0i}) &amp;amp; \text{nếu } |x_{0i}| &amp;gt; r
\end{cases}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Viết gọn:&lt;/strong&gt; \(\text{proj}_C(x_0) = \text{clip}(x_0, -r, r)\)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-7-điểm-cực-biên-và-đỉnh-của-polytope&quot;&gt;&lt;strong&gt;Bài tập 7: Điểm cực biên và đỉnh của polytope&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 2.7 từ Boyd &amp;amp; Vandenberghe)
Cho polytope \(P = \{x : Ax \leq b\}\) trong \(\mathbb{R}^n\).&lt;/p&gt;

&lt;p&gt;a) Chứng minh \(x \in P\) là điểm cực biên khi và chỉ khi có \(n\) ràng buộc độc lập tuyến tính hoạt động (đạt dấu bằng) tại \(x\)&lt;/p&gt;

&lt;p&gt;b) Tìm tất cả các điểm cực biên của:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[P_1 = \{x \in \mathbb{R}^2 : x_1 + x_2 \leq 1, x_1 \geq 0, x_2 \geq 0\}\]
  &lt;/li&gt;
  &lt;li&gt;
\[P_2 = \{x \in \mathbb{R}^3 : x_1 + x_2 + x_3 \leq 1, x_i \geq 0\}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c) Kiểm chứng định lý Krein–Milman: \(P = \text{conv}(\text{các điểm cực biên})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh chặt chẽ đặc trưng đại số của điểm cực biên&lt;/li&gt;
  &lt;li&gt;Liệt kê có hệ thống các đỉnh&lt;/li&gt;
  &lt;li&gt;Minh họa hình học&lt;/li&gt;
  &lt;li&gt;Đề xuất thuật toán tìm đỉnh&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Định lý đặc trưng&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-theorem&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; \(x \in P\) là điểm cực biên \(\Leftrightarrow\) có \(n\) ràng buộc độc lập tuyến tính hoạt động tại \(x\).&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Chứng minh (\(\Leftarrow\)):&lt;/strong&gt; Giả sử có \(n\) ràng buộc hoạt động độc lập tuyến tính: \(A_I x = b_I\) với \(A_I\) có hạng đầy đủ \(n\).&lt;/p&gt;

  &lt;p&gt;Nếu \(x = \theta y + (1-\theta) z\) với \(y, z \in P\) và \(\theta \in (0,1)\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(A_I y \leq b_I\) và \(A_I z \leq b_I\)&lt;/li&gt;
    &lt;li&gt;
\[b_I = A_I x = \theta A_I y + (1-\theta) A_I z \leq b_I\]
    &lt;/li&gt;
    &lt;li&gt;
\[\Rightarrow A_I y = A_I z = b_I\]
    &lt;/li&gt;
    &lt;li&gt;Vì \(A_I\) có hạng đầy đủ nên \(y = z = x\).&lt;/li&gt;
  &lt;/ul&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Chứng minh (\(\Rightarrow\)):&lt;/strong&gt; Dùng phản chứng — nếu số ràng buộc độc lập tuyến tính hoạt động tại \(x\) nhỏ hơn \(n\), tồn tại hướng \(d \neq 0\) thỏa mãn \(A_I d = 0\) sao cho \(x \pm \varepsilon d \in P\) với \(\varepsilon &amp;gt; 0\) đủ nhỏ, nên \(x\) không phải điểm cực biên.&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Ví dụ 1 — Đơn hình 2D&lt;/strong&gt;
\(P_1 = \{x : x_1 + x_2 \leq 1, x_1 \geq 0, x_2 \geq 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Các tổ hợp ràng buộc hoạt động:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\{x_1 = 0, x_2 = 0\}\): đỉnh \((0,0)\)&lt;/li&gt;
    &lt;li&gt;\(\{x_1 = 0, x_1 + x_2 = 1\}\): đỉnh \((0,1)\)&lt;/li&gt;
    &lt;li&gt;\(\{x_2 = 0, x_1 + x_2 = 1\}\): đỉnh \((1,0)\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Tập điểm cực biên:&lt;/strong&gt; \(\{(0,0), (0,1), (1,0)\}\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Ví dụ 2 — Đơn hình 3D&lt;/strong&gt;
\(P_2 = \{x : x_1 + x_2 + x_3 \leq 1, x_1, x_2, x_3 \geq 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Liệt kê có hệ thống:&lt;/strong&gt; Chọn 3 trong 4 ràng buộc để đặt dấu bằng.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Các điểm cực biên:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\((0,0,0)\): \(\{x_1 = 0, x_2 = 0, x_3 = 0\}\)&lt;/li&gt;
    &lt;li&gt;\((1,0,0)\): \(\{x_2 = 0, x_3 = 0, x_1 + x_2 + x_3 = 1\}\)&lt;/li&gt;
    &lt;li&gt;\((0,1,0)\): \(\{x_1 = 0, x_3 = 0, x_1 + x_2 + x_3 = 1\}\)&lt;/li&gt;
    &lt;li&gt;\((0,0,1)\): \(\{x_1 = 0, x_2 = 0, x_1 + x_2 + x_3 = 1\}\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Bước 4: Kiểm chứng định lý Krein–Milman&lt;/strong&gt;
\(P_1 = \text{conv}\{(0,0), (0,1), (1,0)\}\)
\(P_2 = \text{conv}\{(0,0,0), (1,0,0), (0,1,0), (0,0,1)\}\)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-8-bất-đẳng-thức-tổng-quát&quot;&gt;&lt;strong&gt;Bài tập 8: Bất đẳng thức tổng quát&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 2.8 từ Boyd &amp;amp; Vandenberghe)
Cho hình nón thích hợp \(K \subseteq \mathbb{R}^n\) và bất đẳng thức tổng quát \(\preceq_K\).&lt;/p&gt;

&lt;p&gt;a) Kiểm chứng các tính chất của \(\preceq_K\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Phản xạ: \(x \preceq_K x\)&lt;/li&gt;
  &lt;li&gt;Phản đối xứng: \(x \preceq_K y, y \preceq_K x \Rightarrow x = y\)&lt;/li&gt;
  &lt;li&gt;Bắc cầu: \(x \preceq_K y, y \preceq_K z \Rightarrow x \preceq_K z\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;b) Với \(K = \mathbb{S}_+^n\), kiểm chứng:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[A \preceq B \Rightarrow A + C \preceq B + C\]
  &lt;/li&gt;
  &lt;li&gt;
\[A \preceq B, C \succeq 0 \Rightarrow CAC \preceq CBC\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh chặt chẽ các tính chất&lt;/li&gt;
  &lt;li&gt;Đưa ra phản ví dụ cho hình nón không thích hợp&lt;/li&gt;
  &lt;li&gt;Nêu ứng dụng trong tối ưu hóa&lt;/li&gt;
  &lt;li&gt;Liên hệ với hình nón đối ngẫu&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Các tính chất của bất đẳng thức tổng quát&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-definition&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; \(x \preceq_K y \Leftrightarrow y - x \in K\)&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Phản xạ:&lt;/strong&gt; \(x \preceq_K x \Leftrightarrow x - x = 0 \in K\) (đúng vì \(K\) là hình nón nên chứa \(0\)).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Phản đối xứng:&lt;/strong&gt; \(x \preceq_K y, y \preceq_K x\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\Rightarrow y - x \in K\) và \(x - y \in K\)&lt;/li&gt;
    &lt;li&gt;
\[\Rightarrow y - x \in K \cap (-K)\]
    &lt;/li&gt;
    &lt;li&gt;Vì \(K\) nhọn nên \(K \cap (-K) = \{0\}\)&lt;/li&gt;
    &lt;li&gt;
\[\Rightarrow y - x = 0 \Rightarrow x = y\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Bắc cầu:&lt;/strong&gt; \(x \preceq_K y, y \preceq_K z\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[\Rightarrow y - x \in K, z - y \in K\]
    &lt;/li&gt;
    &lt;li&gt;
\[\Rightarrow z - x = (z - y) + (y - x) \in K + K = K\]
    &lt;/li&gt;
    &lt;li&gt;
\[\Rightarrow x \preceq_K z\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Bất đẳng thức ma trận&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Tính chất 1:&lt;/strong&gt; \(A \preceq B \Rightarrow A + C \preceq B + C\)&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt;&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[A \preceq B \Rightarrow B - A \succeq 0\]
      &lt;/li&gt;
      &lt;li&gt;
\[(B + C) - (A + C) = B - A \succeq 0\]
      &lt;/li&gt;
      &lt;li&gt;
\[\Rightarrow A + C \preceq B + C\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Tính chất 2:&lt;/strong&gt; \(A \preceq B, C \succeq 0 \Rightarrow CAC \preceq CBC\)&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt;&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;Ta có \(B - A \succeq 0\) và \(C\) đối xứng (\(C \succeq 0\))&lt;/li&gt;
      &lt;li&gt;Với mọi vector \(x\): \(x^T(CBC - CAC)x = (Cx)^T(B - A)(Cx) \geq 0\)&lt;/li&gt;
      &lt;li&gt;\(\Rightarrow CBC - CAC \succeq 0\) (không cần giả thiết \(C\) khả nghịch; thực tế chỉ cần \(C\) đối xứng)&lt;/li&gt;
      &lt;li&gt;
\[\Rightarrow CAC \preceq CBC\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Phản ví dụ cho hình nón không thích hợp&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Hình nón không nhọn:&lt;/strong&gt; \(K = \{x \in \mathbb{R}^2 : x_1 = 0\}\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[K \cap (-K) = K \neq \{0\}\]
    &lt;/li&gt;
    &lt;li&gt;Tính phản đối xứng không còn đúng&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Hình nón không đặc:&lt;/strong&gt; \(K = \mathbb{R}_+ \times \{0\} \subset \mathbb{R}^2\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Phần trong rỗng&lt;/li&gt;
    &lt;li&gt;Bất đẳng thức nghiêm ngặt \(\prec_K\) không xác định được&lt;/li&gt;
  &lt;/ul&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-9-tổ-hợp-lồi-và-định-lý-carathéodory&quot;&gt;&lt;strong&gt;Bài tập 9: Tổ hợp lồi và định lý Carathéodory&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 2.9 từ Boyd &amp;amp; Vandenberghe)
a) Chứng minh định lý Carathéodory: Mọi điểm trong \(\text{conv}(S)\) (với \(S \subseteq \mathbb{R}^n\)) đều biểu diễn được dưới dạng tổ hợp lồi của tối đa \(n+1\) điểm thuộc \(S\).&lt;/p&gt;

&lt;p&gt;b) Áp dụng cho:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(S = \{(1,0), (0,1), (-1,0), (0,-1)\}\) trong \(\mathbb{R}^2\)&lt;/li&gt;
  &lt;li&gt;\(S = \{e_i : i = 1,\ldots,n\} \cup \{0\}\) trong \(\mathbb{R}^n\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c) Xây dựng thuật toán tìm biểu diễn tối giản&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh đầy đủ định lý Carathéodory&lt;/li&gt;
  &lt;li&gt;Tính toán tường minh cho hai ví dụ&lt;/li&gt;
  &lt;li&gt;Trình bày thuật toán&lt;/li&gt;
  &lt;li&gt;Giải thích ý nghĩa hình học&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Chứng minh định lý Carathéodory&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-theorem&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; Nếu \(x \in \text{conv}(S)\) với \(S \subseteq \mathbb{R}^n\), thì \(x\) viết được dưới dạng:
\(x = \sum_{i=1}^{n+1} \lambda_i x_i\)
với \(x_i \in S\), \(\lambda_i \geq 0\) và \(\sum \lambda_i = 1\).&lt;/p&gt;
  &lt;/div&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt;&lt;/p&gt;
    &lt;ol&gt;
      &lt;li&gt;Giả sử \(x = \sum_{i=1}^k \lambda_i x_i\) với \(k &amp;gt; n+1\)&lt;/li&gt;
      &lt;li&gt;Các vector \(\{x_1 - x_k, \ldots, x_{k-1} - x_k\}\) phụ thuộc tuyến tính trong \(\mathbb{R}^n\)&lt;/li&gt;
      &lt;li&gt;Tồn tại các số \(\mu_1, \dots, \mu_{k-1}\) không đồng thời bằng 0 sao cho \(\sum_{i=1}^{k-1} \mu_i (x_i - x_k) = 0\)&lt;/li&gt;
      &lt;li&gt;Đặt \(\mu_k = -\sum_{i=1}^{k-1} \mu_i\), ta thu được \(\sum_{i=1}^k \mu_i x_i = 0\) và \(\sum_{i=1}^k \mu_i = 0\)&lt;/li&gt;
      &lt;li&gt;Khi đó \(x = \sum_{i=1}^k (\lambda_i - t\mu_i) x_i\) với mọi \(t \in \mathbb{R}\)&lt;/li&gt;
      &lt;li&gt;Chọn \(t = \min\{\lambda_i/\mu_i : \mu_i &amp;gt; 0\}\): mọi hệ số mới vẫn \(\geq 0\), tổng vẫn bằng 1 (do \(\sum \mu_i = 0\)), và có ít nhất một hệ số triệt tiêu, nhờ đó giảm được \(k\) đi ít nhất 1. Lặp lại cho tới khi \(k \le n+1\).&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Ví dụ 1 — Bốn đỉnh hình vuông xoay&lt;/strong&gt;
\(S = \{(1,0), (0,1), (-1,0), (0,-1)\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bao lồi:&lt;/strong&gt; Hình vuông xoay \(45^\circ\) (hình thoi).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Chặn Carathéodory:&lt;/strong&gt; Tối đa \(n+1 = 3\) điểm.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; \((0,0) = \frac{1}{4}(1,0) + \frac{1}{4}(0,1) + \frac{1}{4}(-1,0) + \frac{1}{4}(0,-1)\) có thể rút gọn thành biểu diễn tối giản \((0,0) = \frac{1}{2}(1,0) + \frac{1}{2}(-1,0)\) (chỉ gồm 2 điểm).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Ví dụ 2 — Cơ sở chính tắc và gốc tọa độ&lt;/strong&gt;
\(S = \{e_1, \ldots, e_n, 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bao lồi:&lt;/strong&gt; Đơn hình chuẩn \(\{x : \sum x_i \leq 1, x_i \geq 0\}\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Biểu diễn:&lt;/strong&gt; Mọi điểm \(x\) viết được duy nhất thành \(x = \sum_{i=1}^n x_i e_i + (1 - \sum x_i) \cdot 0\), sử dụng tối đa \(n+1\) điểm (đạt đúng chặn Carathéodory).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 4: Thuật toán rút gọn biểu diễn&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Algorithm: Minimal Convex Combination
Input: Point x, set S
Output: Minimal convex combination

1. Find any representation x = Σ λᵢ xᵢ
2. While |active set| &amp;gt; n+1:
   a. Solve Σ μᵢ xᵢ = 0, Σ μᵢ = 0 with some μᵢ ≠ 0
   b. Find t = min{λᵢ/μᵢ : μᵢ &amp;gt; 0}
   c. Update λᵢ ← λᵢ - t μᵢ
   d. Remove zero coefficients
3. Return minimal representation
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-10-cấu-trúc-mặt-của-tập-lồi&quot;&gt;&lt;strong&gt;Bài tập 10: Cấu trúc mặt của tập lồi&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 2.10 từ Boyd &amp;amp; Vandenberghe)
Cho tập lồi \(C\) và siêu phẳng hỗ trợ \(H = \{x : a^T x = \alpha\}\) với \(\sup_{x \in C} a^T x = \alpha\).&lt;/p&gt;

&lt;p&gt;a) Chứng minh \(F = C \cap H\) là một mặt (face) của \(C\)&lt;/p&gt;

&lt;p&gt;b) Phân loại các mặt của:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hình lập phương đơn vị \([0,1]^n\)&lt;/li&gt;
  &lt;li&gt;Đơn hình đơn vị \(\{x : \sum x_i \leq 1, x_i \geq 0\}\)&lt;/li&gt;
  &lt;li&gt;Hình cầu \(\ell_2\) \(\{x : \lVert x \rVert_2 \leq 1\}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c) Mô tả cấu trúc dàn mặt (face lattice)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh chặt chẽ tính chất mặt&lt;/li&gt;
  &lt;li&gt;Liệt kê đầy đủ cho ba ví dụ&lt;/li&gt;
  &lt;li&gt;Phân tích số chiều của các mặt&lt;/li&gt;
  &lt;li&gt;Mô tả cấu trúc dàn mặt&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Bước 1: Đặc trưng của mặt&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-definition&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; \(F\) là một mặt (face) của \(C\) nếu:&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[F \subseteq C\]
      &lt;/li&gt;
      &lt;li&gt;\(F\) là tập lồi&lt;/li&gt;
      &lt;li&gt;Nếu \(x \in F\) và \(x = \theta y + (1-\theta) z\) với \(y, z \in C\), \(\theta \in (0,1)\), thì \(y, z \in F\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

  &lt;div class=&quot;textbook-theorem&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; Nếu \(H\) là siêu phẳng hỗ trợ của \(C\), thì \(F = C \cap H\) là một mặt của \(C\).&lt;/p&gt;
  &lt;/div&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt;&lt;/p&gt;
    &lt;ol&gt;
      &lt;li&gt;\(F \subseteq C\) (theo định nghĩa)&lt;/li&gt;
      &lt;li&gt;\(F\) là tập lồi (giao của hai tập lồi \(C\) và \(H\))&lt;/li&gt;
      &lt;li&gt;Nếu \(x \in F\) và \(x = \theta y + (1-\theta) z\) với \(y, z \in C\), \(\theta \in (0,1)\):
        &lt;ul&gt;
          &lt;li&gt;
\[\alpha = a^T x = \theta a^T y + (1-\theta) a^T z\]
          &lt;/li&gt;
          &lt;li&gt;Vì \(a^T y \leq \alpha\) và \(a^T z \leq \alpha\) (do \(y, z \in C\)), nên bắt buộc \(a^T y = a^T z = \alpha\)&lt;/li&gt;
          &lt;li&gt;
\[\Rightarrow y, z \in F\]
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Bước 2: Các mặt của hình lập phương đơn vị&lt;/strong&gt;
\(C = [0,1]^n\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Phân loại theo số chiều:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Chiều 0:&lt;/strong&gt; \(2^n\) đỉnh thuộc \(\{0,1\}^n\)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Chiều 1:&lt;/strong&gt; \(n \cdot 2^{n-1}\) cạnh&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Chiều \(k\):&lt;/strong&gt; Các mặt thu được bằng cách cố định \(n-k\) tọa độ nhận giá trị trong \(\{0,1\}\)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Chiều \(n-1\):&lt;/strong&gt; \(2n\) mặt bên (facets) \(\{x_i = 0\}\) và \(\{x_i = 1\}\)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Chiều \(n\):&lt;/strong&gt; Chính tập \(C\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Tổng số mặt khác rỗng:&lt;/strong&gt; \(3^n\) (mỗi tọa độ có 3 lựa chọn: tự do trong \([0,1]\), bằng 0 hoặc bằng 1; tính cả mặt rỗng \(\emptyset\) là \(3^n + 1\)).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bước 3: Các mặt của đơn hình đơn vị&lt;/strong&gt;
\(C = \{x : \sum x_i \leq 1, x_i \geq 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Cấu trúc mặt:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Đỉnh:&lt;/strong&gt; \(\{0, e_1, \ldots, e_n\}\) (\(n+1\) đỉnh)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Cạnh:&lt;/strong&gt; Các đoạn thẳng nối từng cặp đỉnh&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Mặt bên (facets):&lt;/strong&gt; \(\{x_i = 0\}\) và \(\{\sum x_i = 1\}\)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Mặt tổng quát:&lt;/strong&gt; Thu được bằng cách đặt một tập con các ràng buộc bất đẳng thức về dấu bằng&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Bước 4: Các mặt của hình cầu \(\ell_2\)&lt;/strong&gt;
\(C = \{x : \lVert x \rVert_2 \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Cấu trúc mặt:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Chiều 0:&lt;/strong&gt; Mọi điểm biên đơn lẻ \(\{x\}\) với \(\lVert x \rVert_2 = 1\) (vô số điểm cực biên); gốc tọa độ &lt;strong&gt;không&lt;/strong&gt; phải là một mặt&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Chiều \(n\):&lt;/strong&gt; Chính tập \(C\) (cùng mặt rỗng \(\emptyset\))&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Không có mặt nào khác:&lt;/strong&gt; Vì hình cầu lồi chặt nên mọi siêu phẳng hỗ trợ chỉ tiếp xúc tại đúng một điểm; bản thân mặt cầu biên không lồi nên không phải là mặt&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Cấu trúc dàn:&lt;/strong&gt; \(\emptyset \subset \{x\} \subset C\) với mỗi \(x\) trên mặt cầu (không có dây chuyền nào dài hơn 3 phần tử).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mẹo-thực-hành&quot;&gt;Mẹo thực hành&lt;/h2&gt;

&lt;h4 id=&quot;khi-kiểm-tra-tính-lồi&quot;&gt;&lt;strong&gt;Khi kiểm tra tính lồi:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Dùng trực tiếp định nghĩa: kiểm tra \(\theta x + (1-\theta) y \in C\)&lt;/li&gt;
  &lt;li&gt;Áp dụng các phép toán bảo toàn tính lồi&lt;/li&gt;
  &lt;li&gt;Kiểm tra xem tập có phải là tập mức dưới của một hàm lồi hay không&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;khi-tính-bao-lồi&quot;&gt;&lt;strong&gt;Khi tính bao lồi:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Xác định trước các điểm cực biên&lt;/li&gt;
  &lt;li&gt;Dùng định lý Carathéodory để giới hạn số điểm trong tổ hợp lồi&lt;/li&gt;
  &lt;li&gt;Kiểm chứng lại bằng các siêu phẳng hỗ trợ&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;khi-làm-việc-với-hình-nón-đối-ngẫu&quot;&gt;&lt;strong&gt;Khi làm việc với hình nón đối ngẫu:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Nhớ định nghĩa: \(K^* = \{y : y^T x \geq 0, \forall x \in K\}\)&lt;/li&gt;
  &lt;li&gt;Tận dụng tính tự đối ngẫu của các hình nón quen thuộc (\(\mathbb{R}_+^n\), hình nón bậc hai, \(\mathbb{S}_+^n\))&lt;/li&gt;
  &lt;li&gt;Liên hệ với bất đẳng thức tổng quát đối ngẫu&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tổng-kết&quot;&gt;&lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;các-tập-lồi-quan-trọng&quot;&gt;&lt;strong&gt;Các tập lồi quan trọng:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tập&lt;/th&gt;
      &lt;th&gt;Định nghĩa&lt;/th&gt;
      &lt;th&gt;Ghi chú / Ví dụ&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tập affine&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\{x : Ax = b\}\)&lt;/td&gt;
      &lt;td&gt;Không gian con, siêu phẳng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Bao lồi&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\text{conv}(S) = \{\sum \theta_i x_i : \sum \theta_i = 1, \theta_i \geq 0\}\)&lt;/td&gt;
      &lt;td&gt;Tập lồi nhỏ nhất chứa \(S\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hình nón&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\theta x \in C\) \(\forall x \in C, \theta \geq 0\)&lt;/td&gt;
      &lt;td&gt;Góc phần tư không âm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Đa diện&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\{x : Ax \leq b, Cx = d\}\)&lt;/td&gt;
      &lt;td&gt;Giao của các nửa không gian và siêu phẳng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ellipsoid&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\{x : (x-x_c)^TP^{-1}(x-x_c) \leq 1\}\)&lt;/td&gt;
      &lt;td&gt;\(P \succ 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hình cầu chuẩn&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\{x : |x - x_c| \leq r\}\)&lt;/td&gt;
      &lt;td&gt;Hình cầu \(\ell_1, \ell_2, \ell_\infty\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;các-phép-toán-bảo-toàn-tính-lồi&quot;&gt;&lt;strong&gt;Các phép toán bảo toàn tính lồi:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phép toán&lt;/th&gt;
      &lt;th&gt;Biểu thức / Ví dụ&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Giao&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(C_1 \cap C_2\) lồi nếu \(C_1, C_2\) lồi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ánh xạ affine&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(C) = \{Ax + b : x \in C\}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm phối cảnh&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(P(x, t) = x/t\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm tuyến tính-phân thức&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(x) = \frac{Ax + b}{c^Tx + d}\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;phân-tách-và-hỗ-trợ&quot;&gt;&lt;strong&gt;Phân tách và hỗ trợ:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Siêu phẳng phân tách:&lt;/strong&gt; Tồn tại \(a \ne 0\) sao cho \(a^Tx \leq b\) \(\forall x \in C_1\) và \(a^Tx \geq b\) \(\forall x \in C_2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Siêu phẳng hỗ trợ:&lt;/strong&gt; \(\{x : a^Tx = a^Tx_0\}\) tại điểm biên \(x_0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình nón đối ngẫu:&lt;/strong&gt; \(K^* = \{y : y^Tx \geq 0, \forall x \in K\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình nón tự đối ngẫu:&lt;/strong&gt; \(K^* = K\) (ví dụ: góc phần tư không âm, hình nón nửa xác định dương)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;các-định-lý-quan-trọng&quot;&gt;&lt;strong&gt;Các định lý quan trọng:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Carathéodory:&lt;/strong&gt; Mọi điểm trong \(\text{conv}(S) \subset \mathbb{R}^n\) là tổ hợp lồi của tối đa \(n+1\) điểm thuộc \(S\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Radon:&lt;/strong&gt; Mọi tập gồm \(n+2\) điểm trong \(\mathbb{R}^n\) đều chia được thành 2 tập con rời nhau có bao lồi giao nhau&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Helly:&lt;/strong&gt; Nếu \(C_1, \ldots, C_m\) là các tập lồi trong \(\mathbb{R}^n\) (\(m \geq n+1\)) và mọi họ con gồm \(n+1\) tập đều có giao khác rỗng, thì \(\bigcap_{i=1}^m C_i \neq \emptyset\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 2: Convex Sets&lt;/li&gt;
      &lt;li&gt;Exercises 2.1-2.27&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Rockafellar, R. T.&lt;/strong&gt; (1970). &lt;em&gt;Convex Analysis&lt;/em&gt;. Princeton University Press.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ziegler, G. M.&lt;/strong&gt; (1995). &lt;em&gt;Lectures on Polytopes&lt;/em&gt;. Springer-Verlag.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>02-08 Bài tập trắc nghiệm - Tập lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_08_Quiz_Convex_Sets/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_08_Quiz_Convex_Sets</id>
   <content type="html">&lt;p&gt;Chương 02 chứa rất nhiều định nghĩa có tên gọi na ná nhau — tập affine, bao affine, tập lồi, bao lồi, hình nón, hình nón lồi, siêu phẳng phân tách, siêu phẳng hỗ trợ, hình nón thích hợp và hình nón đối ngẫu. Khi làm trắc nghiệm, chỉ cần nhầm một chữ (như nhầm “hợp của hai tập lồi” với “giao của hai tập lồi”, hay quên điều kiện \(0 \le \theta \le 1\)) là dễ mất điểm oan.&lt;/p&gt;

&lt;p&gt;Trước khi bắt tay vào bộ câu hỏi trắc nghiệm bên dưới, hãy rà nhanh 3 trục phân biệt quan trọng nhất và kiểm tra tay 3 tình huống phân loại mẫu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trục-phân-biệt-dễ-nhầm-nhất-của-chương-02&quot;&gt;Kiến thức cần nhớ: Ba trục phân biệt dễ nhầm nhất của Chương 02&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân biệt theo điều kiện trọng số \(\theta\):&lt;/strong&gt; Affine (\(\sum \theta_i = 1\)); Lồi (\(\sum \theta_i = 1,\ \theta_i \ge 0\)); Nón lồi (\(\theta_i \ge 0\)); Không gian con (\(\theta_i \in \mathbb{R}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân biệt phép toán bảo toàn:&lt;/strong&gt; &lt;strong&gt;Giao&lt;/strong&gt; bảo toàn tính lồi, &lt;strong&gt;ánh xạ affine&lt;/strong&gt; bảo toàn tính lồi, &lt;strong&gt;hàm phối cảnh&lt;/strong&gt; bảo toàn tính lồi; còn &lt;strong&gt;phép hợp (union)&lt;/strong&gt; và &lt;strong&gt;phần bù&lt;/strong&gt; nói chung &lt;strong&gt;KHÔNG&lt;/strong&gt; bảo toàn tính lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân biệt hai định lý siêu phẳng:&lt;/strong&gt; &lt;em&gt;Phân tách&lt;/em&gt; dùng cho &lt;strong&gt;hai&lt;/strong&gt; tập lồi rời nhau; &lt;em&gt;hỗ trợ&lt;/em&gt; dùng tại một điểm &lt;strong&gt;biên&lt;/strong&gt; của &lt;strong&gt;một&lt;/strong&gt; tập lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chẩn-đoán-nhanh-3-tập-hợp-trong-mathbbr2-trước-khi-làm-quiz&quot;&gt;Giải thích: Chẩn đoán nhanh 3 tập hợp trong \(\mathbb{R}^2\) trước khi làm quiz&lt;/h3&gt;

&lt;p&gt;Kiểm tra nhanh 3 tập hợp sau có lồi hay không:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tập \(A = \{x \in \mathbb{R}^2 : x_1^2 + x_2^2 \le 4 \text{ và } x_1 + x_2 \ge 1\}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Là &lt;strong&gt;giao&lt;/strong&gt; của một hình tròn đặc (lồi) và một nửa không gian \(-x_1 - x_2 \le -1\) (lồi).&lt;/li&gt;
      &lt;li&gt;Kết luận: &lt;strong&gt;Tập lồi&lt;/strong&gt; (nhờ phép giao bảo toàn tính lồi).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập \(B = \{x : \|x\|_2 \le 1\} \cup \{x : \|x - (3, 0)\|_2 \le 1\}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Là &lt;strong&gt;hợp&lt;/strong&gt; của hai hình tròn rời nhau. Lấy \((0, 0) \in B\) và \((3, 0) \in B\), trung điểm \((1.5, 0)\) có khoảng cách tới cả hai tâm đều bằng \(1.5 &amp;gt; 1 \implies (1.5, 0) \notin B\).&lt;/li&gt;
      &lt;li&gt;Kết luận: &lt;strong&gt;Không lồi&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Tập $$C = {(x_1, x_2) : x_2 \ge&lt;/td&gt;
          &lt;td&gt;x_1&lt;/td&gt;
          &lt;td&gt;}$$:**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Đây chính là &lt;strong&gt;hình nón chuẩn \(\ell_1/\ell_2\) trong \(\mathbb{R}^2\)&lt;/strong&gt; (hình chữ V hướng lên trên): với mọi \(\theta_1, \theta_2 \ge 0\) và \((x_1, x_2), (y_1, y_2) \in C\), ta có $$\theta_1 x_2 + \theta_2 y_2 \ge \theta_1&lt;/td&gt;
              &lt;td&gt;x_1&lt;/td&gt;
              &lt;td&gt;+ \theta_2&lt;/td&gt;
              &lt;td&gt;y_1&lt;/td&gt;
              &lt;td&gt;\ge&lt;/td&gt;
              &lt;td&gt;\theta_1 x_1 + \theta_2 y_1&lt;/td&gt;
              &lt;td&gt;$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Kết luận: &lt;strong&gt;Hình nón lồi&lt;/strong&gt; (vừa là tập lồi vừa là hình nón).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra hiểu biết của bạn về tập affine, tập lồi và các ví dụ quan trọng trong hình học lồi.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-tập-affine&quot;&gt;📏 &lt;strong&gt;Tập Affine&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt;
Tập \(C\) là affine nếu với mọi \(x_1, x_2 \in C\) và \(\theta \in \mathbb{R}\):
\(\theta x_1 + (1-\theta)x_2 \in C\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Tổ hợp affine:&lt;/strong&gt;
\(\sum_{i=1}^k \theta_i x_i\) với \(\sum_{i=1}^k \theta_i = 1\) (không yêu cầu \(\theta_i \ge 0\))&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bao affine:&lt;/strong&gt;
\(\text{aff}(C) = \{\sum_{i=1}^k \theta_i x_i \mid x_i \in C, \sum_{i=1}^k \theta_i = 1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất:&lt;/strong&gt; Tập affine = phép tịnh tiến của không gian con tuyến tính&lt;/p&gt;

&lt;h3 id=&quot;-tập-lồi&quot;&gt;🔵 &lt;strong&gt;Tập Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt;
Tập \(C\) là lồi nếu với mọi \(x_1, x_2 \in C\) và \(0 \le \theta \le 1\):
\(\theta x_1 + (1-\theta)x_2 \in C\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Tổ hợp lồi:&lt;/strong&gt;
\(\sum_{i=1}^k \theta_i x_i\) với \(\sum_{i=1}^k \theta_i = 1, \theta_i \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bao lồi:&lt;/strong&gt;
\(\text{conv}(C) = \{\sum_{i=1}^k \theta_i x_i \mid x_i \in C, \theta_i \ge 0, \sum_{i=1}^k \theta_i = 1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trực quan:&lt;/strong&gt; Không có “vết lõm” - đoạn thẳng nối 2 điểm bất kỳ đều nằm trong tập&lt;/p&gt;

&lt;h3 id=&quot;-hình-nón-và-hình-nón-lồi&quot;&gt;🔺 &lt;strong&gt;Hình Nón và Hình Nón Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hình nón:&lt;/strong&gt;
Tập \(C\) là nón nếu với mọi \(x \in C\) và \(\theta \ge 0\):
\(\theta x \in C\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hình nón lồi:&lt;/strong&gt;
Vừa là nón vừa là lồi. Với \(x_1, x_2 \in C\) và \(\theta_1, \theta_2 \ge 0\):
\(\theta_1 x_1 + \theta_2 x_2 \in C\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tổ hợp nón:&lt;/strong&gt;
\(\sum_{i=1}^k \theta_i x_i\) với \(\theta_i \ge 0\) (không yêu cầu tổng = 1)&lt;/p&gt;

&lt;h3 id=&quot;-các-ví-dụ-quan-trọng&quot;&gt;📐 &lt;strong&gt;Các Ví Dụ Quan Trọng&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Các tập hợp cơ bản:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tập rỗng \(\emptyset\): lồi&lt;/li&gt;
  &lt;li&gt;Điểm đơn \(\{x_0\}\): lồi&lt;/li&gt;
  &lt;li&gt;Đường thẳng, đoạn thẳng, tia: lồi&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Siêu phẳng:&lt;/strong&gt;
\(\{x \mid a^T x = b\}\) với \(a \neq 0\) - là tập affine và lồi&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nửa không gian:&lt;/strong&gt;
\(\{x \mid a^T x \le b\}\) với \(a \neq 0\) - là tập lồi&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tập affine:&lt;/strong&gt;
\(\{x \mid Ax = b\}\) - là tập affine và lồi&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hình cầu Euclidean:&lt;/strong&gt;
\(\{x \mid \lVert x - x_c \rVert_2 \le r\}\) - là tập lồi&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hình cầu chuẩn:&lt;/strong&gt;
\(\{x \mid \lVert x \rVert \le r\}\) với chuẩn bất kỳ - là tập lồi&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ellipsoid:&lt;/strong&gt;
\(\{x \mid (x-x_c)^T P^{-1} (x-x_c) \le 1\}\) với \(P \succ 0\) - là tập lồi&lt;/p&gt;

&lt;h3 id=&quot;️-siêu-phẳng-phân-tách-và-hỗ-trợ&quot;&gt;✂️ &lt;strong&gt;Siêu Phẳng Phân Tách và Hỗ Trợ&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Định lý siêu phẳng phân tách:&lt;/strong&gt;
Nếu \(C\) và \(D\) là hai tập lồi rời nhau, tồn tại siêu phẳng \(\{x \mid a^T x = b\}\) với \(a \neq 0\) sao cho:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(a^T x \le b\) với mọi \(x \in C\)&lt;/li&gt;
  &lt;li&gt;\(a^T x \ge b\) với mọi \(x \in D\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Định lý siêu phẳng hỗ trợ:&lt;/strong&gt;
Với tập lồi \(C\) và điểm biên \(x_0 \in \text{bd}(C)\), tồn tại siêu phẳng hỗ trợ:
\(\{x \mid a^T x = a^T x_0\}\) sao cho \(a^T x \le a^T x_0\) với mọi \(x \in C\)&lt;/p&gt;

&lt;h3 id=&quot;-mối-quan-hệ-giữa-các-tập&quot;&gt;🔗 &lt;strong&gt;Mối Quan Hệ Giữa Các Tập&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Tập Affine ⊂ Tập Lồi
     ↓
Hình Nón Lồi = Hình Nón ∩ Tập Lồi (nên Hình Nón Lồi ⊂ Hình Nón và Hình Nón Lồi ⊂ Tập Lồi)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Ghi nhớ:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Affine:&lt;/strong&gt; Đường thẳng qua 2 điểm (\(\theta \in \mathbb{R}\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lồi:&lt;/strong&gt; Đoạn thẳng nối 2 điểm (\(0 \le \theta \le 1\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nón:&lt;/strong&gt; Tia từ gốc qua điểm (\(\theta \ge 0\))&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-các-phép-toán-bảo-toàn-tính-lồi&quot;&gt;🎯 &lt;strong&gt;Các Phép Toán Bảo Toàn Tính Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Giao:&lt;/strong&gt; Giao của các tập lồi là lồi&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp affine:&lt;/strong&gt; \(\alpha C + \beta D\) lồi nếu \(C, D\) lồi&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ảnh affine:&lt;/strong&gt; \(f(C) = \{Ax + b \mid x \in C\}\) lồi nếu \(C\) lồi&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghịch ảnh affine:&lt;/strong&gt; \(f^{-1}(D) = \{x \mid Ax + b \in D\}\) lồi nếu \(D\) lồi&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Mẹo:&lt;/strong&gt; Tập lồi là nền tảng của tối ưu hóa lồi. Hầu hết các tập ràng buộc trong thực tế đều có thể biểu diễn bằng giao của các tập lồi cơ bản!&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Bài tập trắc nghiệm: Tập lồi&lt;/h2&gt;
        &lt;p&gt;Chọn đáp án đúng nhất cho mỗi câu hỏi. Bài tập tập trung vào các khái niệm cơ bản về tập affine, tập lồi và siêu phẳng.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Câu hỏi 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Câu hỏi 1: Định nghĩa tập affine --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Câu 1: Tập $$C$$ là tập affine nếu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Với mọi $$x_1, x_2 \in C$$ và $$0 \leq \theta \leq 1$$, ta có $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Với mọi $$x_1, x_2 \in C$$ và $$\theta \in \mathbb{R}$$, ta có $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Tập $$C$$ là tập đóng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Tập $$C$$ có biên giới hạn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Với mọi $$x_1, x_2 \in C$$ và $$\theta \in \mathbb{R}$$, ta có $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/strong&gt;&lt;br /&gt;
                Tập affine chứa toàn bộ đường thẳng đi qua hai điểm bất kỳ trong tập, không giới hạn $$\theta$$ trong khoảng $$[0,1]$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Tổ hợp affine --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Tổ hợp affine của các điểm $$x_1, x_2, ..., x_k$$ có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) $$\sum_{i=1}^k \theta_i x_i$$ với $$\theta_i \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) $$\sum_{i=1}^k \theta_i x_i$$ với $$\sum_{i=1}^k \theta_i = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) $$\sum_{i=1}^k \theta_i x_i$$ với $$\theta_i \geq 0$$ và $$\sum_{i=1}^k \theta_i = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) $$\sum_{i=1}^k x_i$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\sum_{i=1}^k \theta_i x_i$$ với $$\sum_{i=1}^k \theta_i = 1$$&lt;/strong&gt;&lt;br /&gt;
                Tổ hợp affine chỉ yêu cầu tổng các hệ số bằng 1, không yêu cầu các hệ số không âm (khác với tổ hợp lồi).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Mối quan hệ tập affine và không gian con --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Nếu $$C$$ là tập affine và $$x_0 \in C$$, thì $$V = C - x_0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) Tập affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Không gian con tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Siêu phẳng&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Không gian con tuyến tính&lt;/strong&gt;&lt;br /&gt;
                Tập affine $$C$$ là phép tịnh tiến của không gian con tuyến tính $$V$$ bởi $$x_0$$. Do đó $$V = C - x_0$$ là không gian con.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Định nghĩa tập lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Tập $$C$$ là tập lồi nếu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Với mọi $$x_1, x_2 \in C$$ và $$\theta \in \mathbb{R}$$, ta có $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Với mọi $$x_1, x_2 \in C$$ và $$0 \leq \theta \leq 1$$, ta có $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Tập $$C$$ không có lỗ hổng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Tập $$C$$ là hình tròn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Với mọi $$x_1, x_2 \in C$$ và $$0 \leq \theta \leq 1$$, ta có $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/strong&gt;&lt;br /&gt;
                Tập lồi chứa đoạn thẳng nối hai điểm bất kỳ trong tập, với $$\theta$$ giới hạn trong $$[0,1]$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Tổ hợp lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Tổ hợp lồi khác với tổ hợp affine ở điểm nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Tổng các hệ số phải bằng 1&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Các hệ số phải không âm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Số lượng điểm tham gia&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Không có sự khác biệt&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Các hệ số phải không âm&lt;/strong&gt;&lt;br /&gt;
                Tổ hợp lồi yêu cầu $$\theta_i \geq 0$$ và $$\sum \theta_i = 1$$, trong khi tổ hợp affine chỉ cần $$\sum \theta_i = 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Siêu phẳng --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Siêu phẳng $$\{x : a^T x = b\}$$ với $$a \neq 0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) Chỉ là tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) Chỉ là tập affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) Vừa là tập lồi vừa là tập affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Không phải tập lồi cũng không phải tập affine&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Vừa là tập lồi vừa là tập affine&lt;/strong&gt;&lt;br /&gt;
                Siêu phẳng thỏa mãn cả định nghĩa tập lồi và tập affine vì nó chứa toàn bộ đường thẳng đi qua bất kỳ hai điểm nào.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Nửa không gian --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Nửa không gian $$\{x : a^T x \leq b\}$$ với $$a \neq 0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Tập lồi nhưng không phải tập affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Tập affine nhưng không phải tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Vừa là tập lồi vừa là tập affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Không phải tập lồi cũng không phải tập affine&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Tập lồi nhưng không phải tập affine&lt;/strong&gt;&lt;br /&gt;
                Nửa không gian là tập lồi vì chứa đoạn thẳng nối hai điểm bất kỳ, nhưng không phải tập affine vì không chứa toàn bộ đường thẳng.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Hình cầu Euclidean --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Hình cầu Euclidean $$B(x_c, r) = \{x : \|x - x_c\|_2 \leq r\}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) Tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) Tập affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Siêu phẳng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) Nửa không gian&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Tập lồi&lt;/strong&gt;&lt;br /&gt;
                Hình cầu Euclidean là tập lồi vì đoạn thẳng nối hai điểm bất kỳ trong hình cầu cũng nằm trong hình cầu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Ellipsoid --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Ellipsoid $$\{x : (x-x_c)^T P^{-1} (x-x_c) \leq 1\}$$ với $$P \succ 0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) Trường hợp đặc biệt của hình cầu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) Tập lồi tổng quát hóa hình cầu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) Không phải tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) Chỉ tồn tại trong 2D&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tập lồi tổng quát hóa hình cầu&lt;/strong&gt;&lt;br /&gt;
                Ellipsoid là tổng quát hóa của hình cầu Euclidean. Khi $$P = r^2 I$$, ellipsoid trở thành hình cầu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Đa diện --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Đa diện được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) Giao của các hình cầu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) Giao của các bất đẳng thức và đẳng thức tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Hợp của các nửa không gian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) Tích của các tập lồi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Giao của các bất đẳng thức và đẳng thức tuyến tính&lt;/strong&gt;&lt;br /&gt;
                Đa diện có dạng $$\{x : a_i^T x \leq b_i, c_j^T x = d_j\}$$, là giao của các nửa không gian và siêu phẳng.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Đơn hình --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Đơn hình trong không gian $$n$$ chiều được tạo từ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) $$n$$ điểm độc lập affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) $$n+1$$ điểm độc lập affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) $$2n$$ điểm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Vô hạn điểm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$n+1$$ điểm độc lập affine&lt;/strong&gt;&lt;br /&gt;
                Đơn hình trong không gian $$n$$ chiều cần $$n+1$$ điểm độc lập affine: điểm (0D), đoạn thẳng (1D), tam giác (2D), tứ diện (3D).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Hình cầu chuẩn --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Hình cầu chuẩn $$\{x : \|x - x_c\| \leq r\}$$ là tập lồi khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Với mọi chuẩn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Chỉ với chuẩn Euclidean&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Chỉ với p-chuẩn khi $$p \geq 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Chỉ khi $$p = 2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Với mọi chuẩn&lt;/strong&gt;&lt;br /&gt;
                Hình cầu của mọi chuẩn đều là tập lồi: nếu $$\|x - x_c\| \leq r$$ và $$\|y - x_c\| \leq r$$ thì theo bất đẳng thức tam giác và tính thuần nhất, $$\|\theta x + (1-\theta)y - x_c\| \leq \theta r + (1-\theta) r = r$$. (Với $$p &amp;lt; 1$$, $$\|\cdot\|_p$$ không phải là chuẩn và &quot;hình cầu&quot; không lồi.)
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Định lý siêu phẳng phân tách --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Định lý siêu phẳng phân tách phát biểu rằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Hai tập lồi bất kỳ đều có thể phân tách bằng siêu phẳng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Hai tập lồi rời nhau có thể phân tách bằng siêu phẳng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Mọi tập lồi đều có siêu phẳng hỗ trợ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Siêu phẳng luôn chia không gian thành hai phần bằng nhau&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Hai tập lồi rời nhau có thể phân tách bằng siêu phẳng&lt;/strong&gt;&lt;br /&gt;
                Định lý siêu phẳng phân tách áp dụng cho hai tập lồi rời nhau (không giao nhau), không phải cho mọi cặp tập lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Siêu phẳng hỗ trợ --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Siêu phẳng hỗ trợ tại điểm $$x_0$$ trên biên của tập lồi $$C$$ thỏa mãn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) $$a^T x \geq a^T x_0$$ với mọi $$x \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) $$a^T x \leq a^T x_0$$ với mọi $$x \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) $$a^T x = a^T x_0$$ với mọi $$x \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) $$a^T x &amp;gt; a^T x_0$$ với mọi $$x \in C$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$a^T x \leq a^T x_0$$ với mọi $$x \in C$$&lt;/strong&gt;&lt;br /&gt;
                Siêu phẳng hỗ trợ $$\{x : a^T x = a^T x_0\}$$ &quot;hỗ trợ&quot; tập $$C$$ tại $$x_0$$, với $$C$$ nằm trong nửa không gian $$a^T x \leq a^T x_0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Phân tách nghiêm ngặt --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Phân tách nghiêm ngặt giữa hai tập $$C$$ và $$D$$ có nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) $$a^T x \leq b$$ với $$x \in C$$ và $$a^T x \geq b$$ với $$x \in D$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) $$a^T x &amp;lt; b$$ với $$x \in C$$ và $$a^T x &amp;gt; b$$ với $$x \in D$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) $$a^T x = b$$ với $$x \in C \cup D$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Khoảng cách giữa $$C$$ và $$D$$ lớn hơn 0&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$a^T x &amp;lt; b$$ với $$x \in C$$ và $$a^T x &amp;gt; b$$ với $$x \in D$$&lt;/strong&gt;&lt;br /&gt;
                Phân tách nghiêm ngặt yêu cầu bất đẳng thức nghiêm ngặt (&amp;lt; và &amp;gt;), không chỉ ≤ và ≥.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Bao lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Bao lồi của tập $$S$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Tập lồi nhỏ nhất chứa $$S$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Tập lồi lớn nhất trong $$S$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Giao của tất cả tập lồi chứa $$S$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Cả A và C đều đúng&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Cả A và C đều đúng&lt;/strong&gt;&lt;br /&gt;
                Bao lồi vừa là tập lồi nhỏ nhất chứa $$S$$, vừa là giao của tất cả các tập lồi chứa $$S$$. Hai định nghĩa này tương đương.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Polytope --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Polytope là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Đa diện bất kỳ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Đa diện bị chặn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Đa diện không bị chặn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Đa diện có vô hạn đỉnh&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Đa diện bị chặn&lt;/strong&gt;&lt;br /&gt;
                Polytope là thuật ngữ đặc biệt dành cho đa diện bị chặn (bounded polyhedron).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Đơn hình xác suất --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Đơn hình xác suất trong $$\mathbb{R}^n$$ được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) $$\{x : x \geq 0, \sum x_i = 1\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) $$\{x : x \geq 0, \sum x_i \leq 1\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) $$\{x : \|x\| = 1\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) $$\{x : \|x\| \leq 1\}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\{x : x \geq 0, \sum x_i = 1\}$$&lt;/strong&gt;&lt;br /&gt;
                Đơn hình xác suất là tập hợp các vector xác suất: các thành phần không âm và tổng bằng 1.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Tính chất hình học --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Tập affine có thể được hiểu như tập hợp của:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Nhiều đường thẳng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Nhiều đoạn thẳng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Nhiều tia&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Nhiều điểm rời rạc&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Nhiều đường thẳng&lt;/strong&gt;&lt;br /&gt;
                Tập affine được hình thành bằng cách tập hợp nhiều đường thẳng, tập lồi bằng nhiều đoạn thẳng, và hình nón bằng nhiều tia.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Ứng dụng thực tế --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Trong tối ưu hóa, siêu phẳng phân tách được sử dụng chủ yếu trong:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Tính toán gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Phân loại và học máy&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Tính tích phân&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Giải phương trình vi phân&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Phân loại và học máy&lt;/strong&gt;&lt;br /&gt;
                Siêu phẳng phân tách là cơ sở cho nhiều thuật toán phân loại như SVM, được sử dụng rộng rãi trong học máy.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 21: Kiểm tra tập lồi thực tế --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Tập $$S = \{(x,y) : x^2 + y^2 \leq 1\}$$ (hình tròn đơn vị) có phải là tập lồi không?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Có, vì thỏa mãn định nghĩa tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Không, vì có biên cong&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Không, vì không phải đa giác&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Chỉ lồi khi bán kính = 1&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Có, vì thỏa mãn định nghĩa tập lồi&lt;/strong&gt;&lt;br /&gt;
                Hình tròn (và hình cầu) luôn là tập lồi. Đoạn thẳng nối hai điểm bất kỳ trong hình tròn đều nằm hoàn toàn trong hình tròn.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Tổ hợp lồi thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Cho ba điểm $$A(0,0), B(2,0), C(1,2)$$. Điểm nào sau đây thuộc tổ hợp lồi của chúng?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$(1,1)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$(3,1)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$(-1,0)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$(2,3)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$(1,1)$$&lt;/strong&gt;&lt;br /&gt;
                Tổ hợp lồi của ba điểm tạo thành tam giác. Điểm $$(1,1)$$ nằm trong tam giác với đỉnh $$A, B, C$$.&lt;br /&gt;
                Có thể viết $$(1,1) = 0.25A + 0.25B + 0.5C$$ với các hệ số không âm và tổng bằng 1.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Siêu phẳng thực tế --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Siêu phẳng $$\{x : 2x_1 + 3x_2 = 6\}$$ trong $$\mathbb{R}^2$$ đi qua điểm nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$(0,2)$$ và $$(3,0)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$(1,1)$$ và $$(2,2)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$(0,0)$$ và $$(1,1)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$(2,3)$$ và $$(6,0)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$(0,2)$$ và $$(3,0)$$&lt;/strong&gt;&lt;br /&gt;
                Kiểm tra: $$2(0) + 3(2) = 6$$ ✓ và $$2(3) + 3(0) = 6$$ ✓&lt;br /&gt;
                Đây là đường thẳng cắt trục $$y$$ tại $$(0,2)$$ và trục $$x$$ tại $$(3,0)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Nón lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Tập $$K = \{(x,y) : x \geq 0, y \geq 0, y \leq x\}$$ có phải là nón lồi không?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Có, vì đóng dưới phép nhân với số không âm và phép cộng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Không, vì không chứa gốc tọa độ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Không, vì không đối xứng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Chỉ là nón, không lồi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Có, vì đóng dưới phép nhân với số không âm và phép cộng&lt;/strong&gt;&lt;br /&gt;
                Tập này là góc phần tư thứ nhất dưới đường $$y = x$$, chứa gốc tọa độ và thỏa mãn định nghĩa nón lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Phép toán bảo toàn tính lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Cho hai tập lồi $$C_1$$ và $$C_2$$. Tập nào sau đây chắc chắn là lồi?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$C_1 \cap C_2$$ (giao)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$C_1 \cup C_2$$ (hợp)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$C_1 \setminus C_2$$ (hiệu)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$C_1 \triangle C_2$$ (hiệu đối xứng)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$C_1 \cap C_2$$ (giao)&lt;/strong&gt;&lt;br /&gt;
                Giao của hai tập lồi luôn là tập lồi. Hợp của hai tập lồi không nhất thiết lồi (ví dụ: hai hình tròn rời nhau).
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Câu trước&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Câu tiếp&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Kết quả bài tập&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #9C27B0, #673AB7);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #9C27B0;
    background-color: #f3e5f5;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #9C27B0;
    background-color: #e8d5e8;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #f3e5f5;
    border-left: 4px solid #9C27B0;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #7B1FA2;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #9C27B0;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #7B1FA2;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #f3e5f5;
    border-radius: 8px;
    border: 2px solid #9C27B0;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #7B1FA2;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng cho từng câu hỏi
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;b&apos;,
    q6: &apos;c&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;b&apos;, q10: &apos;b&apos;,
    q11: &apos;b&apos;, q12: &apos;a&apos;, q13: &apos;b&apos;, q14: &apos;b&apos;, q15: &apos;b&apos;,
    q16: &apos;d&apos;, q17: &apos;b&apos;, q18: &apos;a&apos;, q19: &apos;a&apos;, q20: &apos;b&apos;,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;
};

/**
 * Cập nhật thanh tiến trình và hiển thị câu hỏi hiện tại
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Câu hỏi ${currentQuestion}/${totalQuestions}`;
}

/**
 * Hiển thị câu hỏi theo số thứ tự
 */
function showQuestion(questionNum) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Cập nhật trạng thái nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Chuyển đến câu hỏi tiếp theo
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Quay lại câu hỏi trước
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Lưu đáp án của người dùng
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Cập nhật giao diện để hiển thị đáp án đã chọn
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Nộp bài và hiển thị kết quả
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Tính điểm và tạo báo cáo chi tiết
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Hiển thị giải thích cho tất cả câu hỏi
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Tạo báo cáo chi tiết
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Câu ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Đúng&apos; : &apos;Sai&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Đáp án của bạn: ${userAnswer || &apos;Chưa trả lời&apos;} | Đáp án đúng: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Hiển thị kết quả
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Điểm số: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Xuất sắc! Bạn đã nắm vững hình học lồi!&apos; : 
              scorePercentage &gt;= 60 ? &apos;👍 Khá tốt! Hãy ôn lại một số khái niệm hình học.&apos; : 
              scorePercentage &gt;= 40 ? &apos;📚 Cần ôn tập thêm về tập lồi và siêu phẳng.&apos; : &apos;💪 Hãy đọc lại lý thuyết về hình học lồi!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Khởi động lại bài tập
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn kết quả và hiển thị lại điều hướng
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Xóa tất cả lựa chọn
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>02-06 Hình nón đối ngẫu và bất đẳng thức tổng quát</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_06_Dual_cones_and_generalized_inequalities/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_06_Dual_cones_and_generalized_inequalities</id>
   <content type="html">&lt;p&gt;Làm thế nào để kiểm tra một điểm \(x\) có nằm trong một hình nón phức tạp \(K\) hay không, hoặc tìm ra tất cả các phương án tối ưu Pareto của một bài toán đa mục tiêu mà không phải dò mù trong không gian nhiều chiều? Câu trả lời của giải tích lồi là bước sang “thế giới gương”: gắn cho mỗi hình nón \(K\) một &lt;strong&gt;hình nón đối ngẫu&lt;/strong&gt; \(K^*\) gồm tất cả các vector tạo góc nhọn (hoặc vuông) với mọi phần tử của \(K\).&lt;/p&gt;

&lt;p&gt;Phần 02-06 mở màn cho tư duy đối ngẫu — một trong những công cụ biến đổi góc nhìn mạnh mẽ nhất của toàn bộ lý thuyết tối ưu hóa.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-vai-trò-của-hình-nón-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Ba vai trò của Hình nón đối ngẫu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa hình học qua góc nhọn:&lt;/strong&gt; \(K^* = \{y : y^T x \ge 0,\ \forall x \in K\}\). Dù \(K\) có lồi hay không, \(K^*\) &lt;strong&gt;luôn là hình nón lồi đóng&lt;/strong&gt; (vì là giao của vô số nửa không gian đi qua gốc tọa độ)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính tự đối ngẫu (Self-duality):&lt;/strong&gt; Ba hình nón quan trọng nhất trong tối ưu hóa — \(\mathbb{R}_+^n\), nón bậc hai \(\ell_2\) và nón ma trận \(\mathbb{S}_+^n\) — đều có tính chất kỳ diệu \(K^* = K\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đặc trưng hóa bất đẳng thức và cực tiểu Pareto:&lt;/strong&gt; Nhờ \(K^*\), bài toán tìm nghiệm cực tiểu theo thứ tự nón phức tạp chuyển thành bài toán vô hướng hóa (scalarization) \(\min_{x \in S} \lambda^T x\) với trọng số \(\lambda \in K^*\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-dùng-nhân-chứng-đối-ngẫu-để-kiểm-tra-x-succeq_k-0&quot;&gt;Giải thích: Dùng nhân chứng đối ngẫu để kiểm tra \(x \succeq_K 0\)&lt;/h3&gt;

&lt;p&gt;Xét hình nón thích hợp \(K = \mathbb{R}_+^2\) (tự đối ngẫu: \(K^* = \mathbb{R}_+^2\)). Tính chất nền tảng khẳng định:
\(x \in K \iff \lambda^T x \ge 0 \quad \text{với mọi } \lambda \in K^*.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp đúng (\(x = (2, 3)^T\)):&lt;/strong&gt; Với mọi \(\lambda = (\lambda_1, \lambda_2)^T \in \mathbb{R}_+^2\) (tức \(\lambda_1, \lambda_2 \ge 0\)), ta luôn có \(\lambda^T x = 2\lambda_1 + 3\lambda_2 \ge 0\). Vậy \(x \in K\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp sai (\(x = (2, -1)^T\)):&lt;/strong&gt; Ta chỉ cần chỉ ra &lt;strong&gt;một nhân chứng đối ngẫu&lt;/strong&gt; duy nhất \(\lambda = (0, 1)^T \in K^*\):
\(\lambda^T x = 0(2) + 1(-1) = -1 &amp;lt; 0.\)
Nhân chứng \(\lambda = (0, 1)^T\) lập tức bác bỏ \(x \in K\) — đây chính là cơ chế hình học đằng sau “chứng chỉ vô nghiệm” (certificate of infeasibility) trong các bộ giải tối ưu!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này giới thiệu khái niệm hình nón đối ngẫu gắn với mỗi hình nón và bất đẳng thức tổng quát đối ngẫu tương ứng. Nhờ bất đẳng thức tổng quát đối ngẫu, ta có thể chuyển việc so sánh theo thứ tự hình nón về so sánh các tích vô hướng, giúp việc phân tích trở nên thuận tiện hơn nhiều.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-06-02 Bất đẳng thức tổng quát đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_06_02_Dual_generalized_inequalities/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_06_02_Dual_generalized_inequalities</id>
   <content type="html">&lt;p&gt;Khi thiết kế một hệ thống kỹ thuật phải tối ưu đồng thời hai tiêu chí mâu thuẫn — ví dụ &lt;strong&gt;chi phí thấp&lt;/strong&gt; và &lt;strong&gt;độ trễ nhỏ&lt;/strong&gt; — bạn không thể tìm được một điểm duy nhất tốt nhất theo mọi tiêu chí, mà sẽ thu được cả một đường cong đánh đổi gọi là &lt;strong&gt;biên tối ưu Pareto&lt;/strong&gt; (Pareto frontier). Làm sao dùng các bộ giải tối ưu một mục tiêu thông thường để vẽ ra biên Pareto đó? &lt;strong&gt;Bất đẳng thức tổng quát đối ngẫu&lt;/strong&gt; mang đến câu trả lời trọn vẹn: gán trọng số dương \(\lambda \succ_{K^*} 0\) và cực tiểu hóa hàm vô hướng \(\lambda^T x\)!&lt;/p&gt;

&lt;p&gt;Bài học này nối kết hình nón đối ngẫu \(K^*\) với kỹ thuật vô hướng hóa để tìm phần tử tối tiểu và cực tiểu Pareto.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-vô-hướng-hóa-scalarization-qua-hình-nón-đối-ngẫu&quot;&gt;Kiến thức cần nhớ: Vô hướng hóa (Scalarization) qua hình nón đối ngẫu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức tổng quát đối ngẫu:&lt;/strong&gt; Khi \(K\) là hình nón thích hợp, \(K^*\) cũng là hình nón thích hợp và định nghĩa thứ tự \(\preceq_{K^*}\) cùng bất đẳng thức chặt \(\prec_{K^*}\) (thuộc phần trong \(\operatorname{int} K^*\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đặc trưng phần tử tối tiểu (Minimum):&lt;/strong&gt; \(x\) là phần tử tối tiểu của \(S\) theo \(K\) khi và chỉ khi với &lt;strong&gt;mọi&lt;/strong&gt; \(\lambda \succ_{K^*} 0\), \(x\) là nghiệm tối ưu duy nhất của \(\min_{z \in S} \lambda^T z\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện đủ cho phần tử cực tiểu (Minimal / Pareto):&lt;/strong&gt; Nếu \(x\) cực tiểu hóa \(\lambda^T z\) trên \(S\) với &lt;strong&gt;một&lt;/strong&gt; trọng số \(\lambda \succ_{K^*} 0\) nào đó, thì \(x\) chắc chắn là phần tử cực tiểu Pareto!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện cần (khi \(S\) lồi):&lt;/strong&gt; Nếu \(S\) là tập lồi, hầu như &lt;em&gt;mọi&lt;/em&gt; điểm trên biên Pareto đều tìm được bằng cách quét các trọng số \(\lambda \succeq_{K^*} 0,\ \lambda \ne 0\) (ngược lại, nếu \(S\) không lồi, vùng lõm của biên Pareto có thể bị bỏ sót!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tìm-biên-pareto-của-4-phương-án-bằng-vô-hướng-hóa-lambdat-x&quot;&gt;Giải thích: Tìm biên Pareto của 4 phương án bằng vô hướng hóa \(\lambda^T x\)&lt;/h3&gt;

&lt;p&gt;Giả sử ta có 4 phương án thiết kế \(S = \{p_1, p_2, p_3, p_4\}\) với hai chi phí cần giảm \((f_1, f_2)\) theo nón \(K = \mathbb{R}_+^2\):
\(p_1 = (1, 4), \qquad p_2 = (2, 2), \qquad p_3 = (4, 1), \qquad p_4 = (3, 3).\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thử trọng số cân bằng \(\lambda = (1, 1)^T \succ 0\):&lt;/strong&gt;
\(\lambda^T p_1 = 5,\quad \lambda^T p_2 = 4,\quad \lambda^T p_3 = 5,\quad \lambda^T p_4 = 6 \implies \text{nhận } p_2 = (2, 2).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử trọng số ưu tiên giảm \(f_1\): \(\lambda = (3, 1)^T \succ 0\):&lt;/strong&gt;
\(\lambda^T p_1 = 7,\quad \lambda^T p_2 = 8,\quad \lambda^T p_3 = 13,\quad \lambda^T p_4 = 12 \implies \text{nhận } p_1 = (1, 4).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử trọng số ưu tiên giảm \(f_2\): \(\lambda = (1, 3)^T \succ 0\):&lt;/strong&gt;
\(\lambda^T p_1 = 13,\quad \lambda^T p_2 = 8,\quad \lambda^T p_3 = 7,\quad \lambda^T p_4 = 12 \implies \text{nhận } p_3 = (4, 1).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số phận của \(p_4 = (3, 3)\):&lt;/strong&gt; Vì \(p_2 = (2, 2) \prec p_4 = (3, 3)\), với &lt;em&gt;mọi&lt;/em&gt; \(\lambda_1, \lambda_2 &amp;gt; 0\) ta luôn có \(\lambda^T p_2 = 2\lambda_1 + 2\lambda_2 &amp;lt; 3\lambda_1 + 3\lambda_2 = \lambda^T p_4\). Điểm \(p_4\) bị thống trị nên không bao giờ nằm trên biên Pareto \(\{p_1, p_2, p_3\}\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Khi một hình nón thích hợp \(K\) sinh ra bất đẳng thức tổng quát \(\preceq_K\), hình nón đối ngẫu \(K^*\) của nó cũng là một hình nón thích hợp, và do đó cũng xác định một bất đẳng thức tổng quát tương ứng.&lt;/p&gt;

&lt;p&gt;Phần này định nghĩa bất đẳng thức tổng quát đối ngẫu dựa trên \(K^*\) và sử dụng nó để đặc trưng cho các phần tử tối tiểu và cực tiểu của một tập hợp.&lt;/p&gt;

&lt;h2 id=&quot;bất-đẳng-thức-tổng-quát-đối-ngẫu&quot;&gt;Bất đẳng thức tổng quát đối ngẫu&lt;/h2&gt;

&lt;p&gt;Với hình nón đối ngẫu thích hợp \(K^*\), một điểm \(y\) được xem là không âm theo thứ tự đối ngẫu nếu tích vô hướng của nó với mọi \(x \in K\) đều không âm. Quan hệ \(\succeq_{K^*}\) được gọi là &lt;strong&gt;đối ngẫu&lt;/strong&gt; của \(\succeq_K\), hay &lt;strong&gt;bất đẳng thức tổng quát đối ngẫu&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(y \succeq_{K^*} 0 \iff y^T x \ge 0\) với mọi \(x \succeq_K 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;tính-chất-chính-của-bất-đẳng-thức-tổng-quát-và-đối-ngẫu&quot;&gt;Tính chất chính của bất đẳng thức tổng quát và đối ngẫu&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;\(x \preceq_K y\) khi và chỉ khi \(\lambda^T x \le \lambda^T y\) với mọi \(\lambda \succeq_{K^*} 0\).&lt;/li&gt;
  &lt;li&gt;\(x \prec_K y\) khi và chỉ khi \(\lambda^T x &amp;lt; \lambda^T y\) với mọi \(\lambda \succeq_{K^*} 0, \lambda \ne 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vì \(K\) là hình nón thích hợp nên \(K = K^{**}\), tức là bất đẳng thức tổng quát đối ngẫu của \(\preceq_{K^*}\) chính là \(\preceq_K\). Do vậy, các tính chất trên vẫn đúng khi hoán đổi vai trò giữa \(K\) và \(K^*\).&lt;/p&gt;

&lt;p&gt;Ví dụ, \(\lambda \preceq_{K^*} \mu\) khi và chỉ khi \(\lambda^T x \le \mu^T x\) với mọi \(x \succeq_K 0\).&lt;/p&gt;

&lt;h2 id=&quot;phần-tử-tối-tiểu-và-cực-tiểu-thông-qua-bất-đẳng-thức-đối-ngẫu&quot;&gt;Phần tử tối tiểu và cực tiểu thông qua bất đẳng thức đối ngẫu&lt;/h2&gt;

&lt;p&gt;Với bất đẳng thức tổng quát sinh bởi hình nón thích hợp \(K\), ta có thể dùng bất đẳng thức tổng quát đối ngẫu để đặc trưng cho phần tử tối tiểu và cực tiểu của một tập \(S \subseteq \mathbb{R}^m\) (không nhất thiết lồi).&lt;/p&gt;

&lt;h3 id=&quot;phần-tử-tối-tiểu&quot;&gt;Phần tử tối tiểu&lt;/h3&gt;

&lt;p&gt;Điểm \(x \in S\) là phần tử tối tiểu của \(S\) theo bất đẳng thức tổng quát \(\preceq_K\) khi và chỉ khi với mọi \(\lambda \succ_{K^*} 0\), \(x\) là điểm cực tiểu hóa duy nhất của hàm tuyến tính \(\lambda^T z\) trên \(z \in S\).&lt;/p&gt;

&lt;p&gt;Về mặt hình học, với mỗi \(\lambda \succ_{K^*} 0\), siêu phẳng \(\{ z \mid \lambda^T (z - x) = 0 \}\) là siêu phẳng hỗ trợ nghiêm ngặt cho \(S\) tại \(x\) (chỉ giao với \(S\) tại duy nhất điểm \(x\)). Tính chất này không đòi hỏi \(S\) phải lồi. Hình dưới đây minh họa một phần tử tối tiểu \(x\) cùng siêu phẳng hỗ trợ nghiêm ngặt.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_02_Minimum_element.png&quot; alt=&quot;[Hình1] Phần tử tối tiểu [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình1] Phần tử tối tiểu [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;phần-tử-cực-tiểu&quot;&gt;Phần tử cực tiểu&lt;/h3&gt;

&lt;p&gt;Điều kiện đối với phần tử cực tiểu yếu hơn so với phần tử tối tiểu.&lt;/p&gt;

&lt;p&gt;Nếu tồn tại một vector \(\lambda \succ_{K^*} 0\) sao cho \(x\) cực tiểu hóa \(\lambda^T z\) trên \(z \in S\), thì \(x \in S\) chắc chắn là một phần tử cực tiểu của \(S\). Khác với phần tử tối tiểu, điều kiện này chỉ cần đúng với &lt;em&gt;một&lt;/em&gt; \(\lambda \succ_{K^*} 0\) (không cần mọi \(\lambda\)) và điểm cực tiểu hóa cũng không cần duy nhất. Do đó, ứng với cùng một \(\lambda\) hoặc các \(\lambda\) khác nhau, tập \(S\) có thể có nhiều phần tử cực tiểu.&lt;/p&gt;

&lt;p&gt;Hình dưới đây minh họa trường hợp có nhiều phần tử cực tiểu (nằm trên đường viền đậm ở góc dưới bên trái). Tại đây, \(x_1\) cực tiểu hóa \(\lambda_1^T z\) với \(\lambda_1 \succ_{K^*} 0\) nên \(x_1\) là phần tử cực tiểu; tương tự, \(x_2\) là một phần tử cực tiểu khác ứng với \(\lambda_2\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_05_Minimal_element.png&quot; alt=&quot;[Hình2] Phần tử cực tiểu [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình2] Phần tử cực tiểu [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Tuy nhiên, chiều ngược lại nhìn chung không đúng: một điểm \(x\) có thể là phần tử cực tiểu của \(S\) nhưng không cực tiểu hóa \(\lambda^T z\) trên \(S\) với bất kỳ \(\lambda \succ_{K^*} 0\) nào. Hình dưới đây minh họa một ví dụ khi \(S\) không lồi.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_06_Minimal_element2.png&quot; alt=&quot;[Hình3] Một ví dụ về phần tử cực tiểu không phải là bộ tối ưu hóa [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình3] Một ví dụ về phần tử cực tiểu không phải là bộ tối ưu hóa [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Ngay cả khi \(S\) là tập lồi, chiều ngược lại chỉ đảm bảo tồn tại \(\lambda \succeq_{K^*} 0\) (\(\lambda \ne 0\)), chứ không nhất thiết \(\lambda \succ_{K^*} 0\). Trong hình bên trái dưới đây, \(x_1 \in S_1\) là phần tử cực tiểu nhưng không cực tiểu hóa \(\lambda_1^T z\) với bất kỳ \(\lambda_1 \succ_{K^*} 0\) nào. Hình bên phải cho thấy khi chỉ có \(\lambda_2 \succeq_{K^*} 0, \lambda_2 \ne 0\), điểm \(x_2 \in S_2\) tuy cực tiểu hóa \(\lambda_2^T z\) trên \(S_2\) nhưng lại không phải là phần tử cực tiểu.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_07_Minimal_element3.png&quot; alt=&quot;[Hình4] Các ví dụ mà điều ngược lại không được tăng cường với $$\lambda_1 \succ_{K^*} 0$$ [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Hình4] Các ví dụ mà điều ngược lại không được tăng cường với } \lambda_1 \succ_{K^*} 0 \text{ [1]}$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;biên-sản-xuất-tối-ưu&quot;&gt;Biên sản xuất tối ưu&lt;/h3&gt;

&lt;p&gt;Xét bài toán sản xuất một sản phẩm sử dụng \(n\) loại tài nguyên (như lao động, điện, khí tự nhiên, nước, v.v.). Mỗi phương án sản xuất tương ứng với một vector tài nguyên \(x \in \mathbb{R}^n\), trong đó \(x_i\) là lượng tài nguyên thứ \(i\) tiêu thụ (giả sử \(x_i \ge 0\) và mỗi tài nguyên đều có chi phí dương).&lt;/p&gt;

&lt;p&gt;Tập sản xuất \(P \subseteq \mathbb{R}^n\) là tập hợp tất cả các vector tài nguyên khả thi \(x\). Một phương án sản xuất có vector tài nguyên là phần tử cực tiểu của \(P\) (theo \(\mathbb{R}^n_+\)) được gọi là &lt;strong&gt;tối ưu Pareto&lt;/strong&gt; hay &lt;strong&gt;hiệu quả&lt;/strong&gt;. Tập hợp tất cả các phần tử cực tiểu của \(P\) được gọi là &lt;strong&gt;biên sản xuất hiệu quả&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Xét hai phương án sản xuất với vector tài nguyên \(x\) (ký hiệu \(P_x\)) và \(y\) (ký hiệu \(P_y\)). Nếu \(x_i \le y_i\) với mọi \(i\) và tồn tại ít nhất một chỉ số \(i\) sao cho \(x_i &amp;lt; y_i\) (tức là \(x \preceq y\) và \(x \ne y\)), thì \(P_x\) tốt hơn \(P_y\) vì không dùng nhiều hơn bất kỳ tài nguyên nào và tiết kiệm được ít nhất một tài nguyên. Nếu không có phương án nào tốt hơn \(P_x\) thì \(P_x\) là phương án tối ưu Pareto.&lt;/p&gt;

&lt;p&gt;Ta có thể tìm phương án tối ưu Pareto bằng cách cực tiểu hóa tổng chi phí tài nguyên sau đây trên tập \(P\), trong đó \(\lambda_i &amp;gt; 0\) đóng vai trò đơn giá của tài nguyên thứ \(i\). Vì mọi đơn giá đều dương (\(\lambda \succ 0\)), mọi nghiệm cực tiểu hóa đều là phương án tối ưu Pareto:&lt;/p&gt;

&lt;blockquote&gt;
\[\lambda^T x = \lambda_1 x_1 + \lambda_2 x_2 + \cdots + \lambda_n x_n, \quad \lambda \succ 0\]
&lt;/blockquote&gt;

&lt;p&gt;Hình dưới đây minh họa trực quan: các điểm \(x_1, x_2, x_3\) là tối ưu Pareto, còn \(x_4, x_5\) thì không.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_08_Pareto_optimal.png&quot; alt=&quot;[Hình5] Biên sản xuất tối ưu [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình5] Biên sản xuất tối ưu [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>02-06-01 Hình nón đối ngẫu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_06_01_Dual_cones/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_06_01_Dual_cones</id>
   <content type="html">&lt;p&gt;Khi bạn bóp hẹp một hình nón \(K\) lại (như khép hai cạnh góc nhọn gần nhau hơn), tập các vector tạo góc \(\le 90^\circ\) với mọi tia trong \(K\) sẽ &lt;strong&gt;mở rộng ra&lt;/strong&gt;; ngược lại, nếu bạn mở rộng \(K\) ra, hình nón đối ngẫu \(K^*\) lại &lt;strong&gt;co hẹp vào&lt;/strong&gt;. Sự đảo ngược đầy tính nghệ thuật đó (\(K_1 \subseteq K_2 \implies K_2^* \subseteq K_1^*\)) chính là nhịp thở của lý thuyết đối ngẫu nón.&lt;/p&gt;

&lt;p&gt;Bài học này trình bày định nghĩa chính thức của hình nón đối ngẫu, các tính chất cơ bản và chứng minh kinh điển cho cặp nón chuẩn (\(\ell_2\) tự đối ngẫu; \(\ell_1\) và \(\ell_\infty\) đối ngẫu lẫn nhau).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-tính-chất-cốt-lõi-của-k&quot;&gt;Kiến thức cần nhớ: Bốn tính chất cốt lõi của \(K^*\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Luôn là hình nón lồi đóng:&lt;/strong&gt; \(K^* = \bigcap_{x \in K} \{y : x^T y \ge 0\}\) — giao của họ các nửa không gian đóng chứa gốc tọa độ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đảo chiều bao hàm và song đối ngẫu:&lt;/strong&gt; \(K_1 \subseteq K_2 \implies K_2^* \subseteq K_1^*\); nếu \(K\) là hình nón lồi đóng thì \((K^*)^* = K\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu của hình nón chuẩn:&lt;/strong&gt; Hình nón gắn với chuẩn \(\|\cdot\|\) là \(K = \{(x, t) : \|x\| \le t\}\) có hình nón đối ngẫu đúng bằng hình nón gắn với &lt;strong&gt;chuẩn đối ngẫu&lt;/strong&gt; \(\|\cdot\|_*\): \(K^* = \{(y, s) : \|y\|_* \le s\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các cặp tự đối ngẫu và đối ngẫu tiêu biểu:&lt;/strong&gt; \((\mathbb{R}_+^n)^* = \mathbb{R}_+^n\), \((K_{\ell_2})^* = K_{\ell_2}\), \((\mathbb{S}_+^n)^* = \mathbb{S}_+^n\), còn \((K_{\ell_\infty})^* = K_{\ell_1}\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tay-k_ell_infty--k_ell_1-trên-vector-3-chiều&quot;&gt;Giải thích: Kiểm chứng tay \(K_{\ell_\infty}^* = K_{\ell_1}\) trên vector 3 chiều&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét nón chuẩn \(\ell_\infty\) trong \(\mathbb{R}^3\): $$K_\infty = {(x_1, x_2, t) : \max(&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;,&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;) \le t}\(. Ta kiểm tra điều kiện\)(y_1, y_2, s) \in K_\infty^*\(, tức\)y_1 x_1 + y_2 x_2 + s t \ge 0\(với mọi\)(x, t) \in K_\infty$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Thử vector \(v = (y_1, y_2, s) = (2, -3, 5)\)&lt;/strong&gt; (có $$|y|_1 =&lt;/td&gt;
          &lt;td&gt;2&lt;/td&gt;
          &lt;td&gt;+&lt;/td&gt;
          &lt;td&gt;-3&lt;/td&gt;
          &lt;td&gt;= 5 \le s = 5$$):&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Với mọi \((x_1, x_2, t) \in K_\infty\), ta có $$&lt;/td&gt;
              &lt;td&gt;x_1&lt;/td&gt;
              &lt;td&gt;\le t\(và\)&lt;/td&gt;
              &lt;td&gt;x_2&lt;/td&gt;
              &lt;td&gt;\le t$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Trường hợp bất lợi nhất (làm tích vô hướng nhỏ nhất) xảy ra khi chọn dấu ngược với \(y\): \(x_1 = -t,\ x_2 = +t\) (với \(t = 1 \implies x = (-1, 1)\)).&lt;/li&gt;
      &lt;li&gt;Khi đó: \(y^T x + s t = 2(-1) + (-3)(1) + 5(1) = -2 - 3 + 5 = 0 \ge 0\)! Vậy \((2, -3, 5) \in K_\infty^*\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử giảm \(s\) xuống \(4 &amp;lt; \|y\|_1 = 5\)&lt;/strong&gt;, tức \(w = (2, -3, 4)\):
    &lt;ul&gt;
      &lt;li&gt;Với cùng điểm biên \((x, t) = (-1, 1, 1) \in K_\infty\):
\(y^T x + s t = 2(-1) + (-3)(1) + 4(1) = -5 + 4 = -1 &amp;lt; 0.\)&lt;/li&gt;
      &lt;li&gt;Vậy \((2, -3, 4) \notin K_\infty^*\)! Điều kiện cần và đủ chính xác là \(\|y\|_1 \le s\), tức \(K_\infty^* = K_{\ell_1}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;hình-nón-đối-ngẫu&quot;&gt;Hình nón đối ngẫu&lt;/h2&gt;

&lt;p&gt;Với mỗi hình nón \(K\), ta định nghĩa một &lt;strong&gt;hình nón đối ngẫu&lt;/strong&gt; tương ứng, ký hiệu là \(K^*\). Hình nón đối ngẫu luôn là một hình nón lồi đóng, bất kể \(K\) ban đầu có lồi hay không. Cụ thể, \(K^*\) là tập hợp tất cả các điểm \(y\) có tích vô hướng không âm với mọi điểm \(x \in K\):&lt;/p&gt;

&lt;blockquote&gt;
\[K^* = \{y \mid x^T y \ge 0 \text{ với mọi } x \in K\}\]
&lt;/blockquote&gt;

&lt;p&gt;Điều kiện tích vô hướng \(x^T y \ge 0\) tương đương với góc \(\theta\) giữa hai vector \(x\) và \(y\) thỏa mãn \(\cos\theta \ge 0\) (tức \(0^\circ \le \theta \le 90^\circ\) hoặc \(270^\circ \le \theta \le 360^\circ\)). Về mặt hình học, \(K^*\) chính là tập hợp các hướng ngược chiều với vector pháp tuyến ngoài của mọi siêu phẳng hỗ trợ cho \(K\) tại gốc tọa độ. Hình dưới đây minh họa miền xác định của hình nón đối ngẫu.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_01_2_dual_cone.png&quot; alt=&quot;[Hình1] Vùng định nghĩa hình nón đối ngẫu&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình1] Vùng định nghĩa hình nón đối ngẫu&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Nói cách khác, \(y \in K^*\) khi và chỉ khi \(-y\) là vector pháp tuyến ngoài của một siêu phẳng hỗ trợ cho \(K\) tại gốc tọa độ. Trong hình tiếp theo, ở bên trái, nửa không gian có vector pháp tuyến hướng vào trong \(y\) chứa trọn hình nón \(K\) nên \(y \in K^*\). Ở bên phải, nửa không gian có vector pháp tuyến hướng vào trong \(z\) không chứa trọn \(K\) nên \(z \notin K^*\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_01_dual_cone.png&quot; alt=&quot;[Hình2] Hình nón đối ngẫu và pháp tuyến siêu phẳng hỗ trợ [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình2] Hình nón đối ngẫu và pháp tuyến siêu phẳng hỗ trợ [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;ví-dụ-về-hình-nón-đối-ngẫu&quot;&gt;Ví dụ về hình nón đối ngẫu&lt;/h2&gt;

&lt;p&gt;Dưới đây là một số hình nón quen thuộc cùng hình nón đối ngẫu của chúng. Ba hình nón đầu tiên có tính &lt;strong&gt;tự đối ngẫu&lt;/strong&gt; (\(K^* = K\)). Ví dụ thứ tư cho thấy hình nón đối ngẫu của hình nón chuẩn \(\ell_1\) là hình nón chuẩn \(\ell_\infty\), và ngược lại.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$K = \mathbb{R}^n_+, K^* = \mathbb{R}^n_+$&lt;/li&gt;
  &lt;li&gt;$K = S^n_+, K^* = S^n_+$&lt;/li&gt;
  &lt;li&gt;$K = {(x, t) \mid  |x|_2 \le t }, K^* = {(x, t)\mid  |x|_2 \le t }$&lt;/li&gt;
  &lt;li&gt;$K = {(x, t) \mid  | x |&lt;em&gt;1 \le t }, K^* = {(x, t) \mid  | x |&lt;/em&gt;{\infty} \le t }$&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;hình-nón-l_2-là-tự-đối-ngẫu&quot;&gt;Hình nón \(l_2\) là tự đối ngẫu&lt;/h3&gt;

&lt;p&gt;Hình dưới đây minh họa tính tự đối ngẫu của hình nón chuẩn \(l_2\): với mỗi điểm \(x \in K\) nằm trên biên, vector pháp tuyến ngoài \(-y\) của siêu phẳng hỗ trợ tại \(x\) đối xứng với vector \(y\) nằm ngay trên biên của \(K\), do đó \(K^*\) trùng hoàn toàn với \(K\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_03_L2_self-dual.png&quot; alt=&quot;[Hình3] Hình nón $$l_2$$ và hình nón đối ngẫu&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Hình3] Hình nón } l_2 \text{ và hình nón đối ngẫu}$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;hình-nón-đối-ngẫu-của-hình-nón-l_infty-là-hình-nón-l_1&quot;&gt;Hình nón đối ngẫu của hình nón \(l_\infty\) là hình nón \(l_1\)&lt;/h3&gt;

&lt;p&gt;Hình dưới đây minh họa rằng hình nón đối ngẫu của hình nón \(l_\infty\) chính là hình nón \(l_1\): khi \(x \in K\) nằm trên biên của hình nón \(l_\infty\), các hướng \(y\) tương ứng với siêu phẳng hỗ trợ tạo nên đúng biên của hình nón \(l_1\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_04_L_inf_dual_norm.png&quot; alt=&quot;[Hình4] Hình nón $$l_\infty$$ và hình nón đối ngẫu&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Hình4] Hình nón } l_\infty \text{ và hình nón đối ngẫu}$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>02-05 Siêu phẳng phân tách và hỗ trợ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_05_Separating_and_supporting_hyperplanes/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_05_Separating_and_supporting_hyperplanes</id>
   <content type="html">&lt;p&gt;Nếu bạn đặt hai quả bóng không chạm nhau trên mặt bàn, bạn luôn có thể luồn một tờ giấy phẳng vào giữa để tách hẳn chúng về hai phía. Điều tưởng chừng hiển nhiên trong thế giới 3D ấy lại là một trong những định lý sâu sắc và hữu ích nhất của giải tích lồi: &lt;strong&gt;Định lý siêu phẳng phân tách&lt;/strong&gt; (Separating Hyperplane Theorem) và người anh em sinh đôi &lt;strong&gt;Định lý siêu phẳng hỗ trợ&lt;/strong&gt; (Supporting Hyperplane Theorem).&lt;/p&gt;

&lt;p&gt;Chính định lý phân tách này là công cụ đứng sau bổ đề Farkas, định lý đối ngẫu mạnh Slater, và thuật toán biên cực đại của Máy vector hỗ trợ (SVM)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-phân-tách-và-tiếp-xúc-biên&quot;&gt;Kiến thức cần nhớ: Hình học phân tách và tiếp xúc biên&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định lý siêu phẳng phân tách:&lt;/strong&gt; Nếu \(C\) và \(D\) là hai tập lồi khác rỗng rời nhau (\(C \cap D = \emptyset\)), luôn tồn tại \(a \ne 0\) và \(b\) sao cho \(a^T x \le b\ \forall x \in C\) và \(a^T y \ge b\ \forall y \in D\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tách nghiêm ngặt (Strict Separation):&lt;/strong&gt; Nếu thêm điều kiện \(C, D\) đóng và ít nhất một tập bị chặn (compact), ta có khoảng cách dương thực sự giữa hai tập và tách được bằng dấu chặt \(a^T x &amp;lt; b &amp;lt; a^T y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý siêu phẳng hỗ trợ:&lt;/strong&gt; Tại &lt;strong&gt;mọi điểm biên&lt;/strong&gt; \(x_0 \in \partial C\) của một tập lồi \(C\), luôn tồn tại một siêu phẳng đi qua \(x_0\) “đỡ” toàn bộ tập \(C\) về một phía: \(a^T x \le a^T x_0\ \forall x \in C\). Đây là bản mở rộng hình học của tiếp tuyến khi biên có góc nhọn!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy với tập không lồi:&lt;/strong&gt; Với hai tập không lồi rời nhau (ví dụ một hình trăng khuyết ôm lấy một hình tròn), không thể tồn tại siêu phẳng phẳng nào tách được chúng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-dựng-tay-siêu-phẳng-phân-tách-và-hỗ-trợ-cho-hai-hình-tròn-rời-nhau&quot;&gt;Giải thích: Dựng tay siêu phẳng phân tách và hỗ trợ cho hai hình tròn rời nhau&lt;/h3&gt;

&lt;p&gt;Xét hai hình tròn đóng (compact, lồi) trong \(\mathbb{R}^2\):
\(C = \{x : \|x\|_2 \le 1\} \quad (\text{tâm } (0,0)), \qquad D = \{x : \|x - (4, 0)\|_2 \le 1\} \quad (\text{tâm } (4,0)).\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tìm cặp điểm gần nhau nhất giữa \(C\) và \(D\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Trên \(C\) là \(c^* = (1, 0)^T\); trên \(D\) là \(d^* = (3, 0)^T\). Khoảng cách tối thiểu là \(\|d^* - c^*\|_2 = 2 &amp;gt; 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dựng siêu phẳng phân tách nghiêm ngặt (đường trung trực đoạn \(c^* d^*\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vector pháp tuyến: \(a = d^* - c^* = (2, 0)^T\).&lt;/li&gt;
      &lt;li&gt;Trung điểm: \(m = \frac{c^* + d^*}{2} = (2, 0)^T \implies b = a^T m = 2(2) + 0(0) = 4\).&lt;/li&gt;
      &lt;li&gt;Siêu phẳng phân tách là \(2x_1 = 4 \iff x_1 = 2\).&lt;/li&gt;
      &lt;li&gt;Kiểm chứng: Với mọi \(x \in C\), \(x_1 \le 1 &amp;lt; 2\); với mọi \(y \in D\), \(y_1 \ge 3 &amp;gt; 2\) (tách chặt với lề rộng \(1\) đơn vị mỗi bên!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dựng siêu phẳng hỗ trợ của \(C\) tại điểm biên \(c^* = (1, 0)\):&lt;/strong&gt;
Lấy cùng pháp tuyến \(a = (1, 0)^T\) đi qua \(c^*\): siêu phẳng \(x_1 = 1\) thỏa \(x_1 \le 1 = a^T c^*\) với mọi \(x \in C\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này giới thiệu hai định lý cơ bản đặc trưng cho tập lồi: &lt;strong&gt;định lý siêu phẳng phân tách&lt;/strong&gt; và &lt;strong&gt;định lý siêu phẳng hỗ trợ&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;định-lý-siêu-phẳng-phân-tách&quot;&gt;Định lý siêu phẳng phân tách&lt;/h2&gt;

&lt;p&gt;Giả sử ta có hai tập lồi rời nhau (không giao nhau). Một cách tự nhiên để tách biệt chúng là đặt một đường thẳng hoặc mặt phẳng nằm giữa hai tập hợp. Ý tưởng này được ứng dụng rộng rãi trong các bài toán phân loại và được khẳng định chặt chẽ bởi &lt;strong&gt;định lý siêu phẳng phân tách&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Nếu \(C\) và \(D\) là hai tập lồi không rỗng và rời nhau, thì tồn tại \(a \ne 0\) và \(b \in \mathbb{R}\) sao cho \(a^T x \le b\) với mọi \(x \in C\) và \(a^T x \ge b\) với mọi \(x \in D\). Nói cách khác, hàm affine \(a^T x - b\) không dương trên \(C\) và không âm trên \(D\). Siêu phẳng \(\{ x \mid a^T x = b\}\) được gọi là &lt;strong&gt;siêu phẳng phân tách&lt;/strong&gt; của \(C\) và \(D\).&lt;/p&gt;

&lt;p&gt;Hình dưới đây minh họa một siêu phẳng phân tách hai tập lồi rời nhau \(C\) và \(D\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.05_01_Seperating_hyperplan_theorem.png&quot; alt=&quot;[Hình1] Định lý siêu phẳng phân tách [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình1] Định lý siêu phẳng phân tách [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Chiều ngược lại của định lý không đúng: việc tồn tại siêu phẳng phân tách không đảm bảo hai tập hợp rời nhau. Chẳng hạn, với \(C = D = \{0\} \subseteq \mathbb{R}\), siêu phẳng \(x = 0\) vẫn thỏa mãn định nghĩa phân tách \(C\) và \(D\) dù hai tập này trùng nhau.&lt;/p&gt;

&lt;h3 id=&quot;phân-tách-nghiêm-ngặt&quot;&gt;Phân tách nghiêm ngặt&lt;/h3&gt;

&lt;p&gt;Nếu siêu phẳng phân tách thỏa mãn điều kiện mạnh hơn là \(a^T x &amp;lt; b\) với mọi \(x \in C\) và \(a^T x &amp;gt; b\) với mọi \(x \in D\), ta gọi đó là &lt;strong&gt;phân tách nghiêm ngặt&lt;/strong&gt;. Hai tập lồi đóng rời nhau không phải lúc nào cũng có siêu phẳng phân tách nghiêm ngặt, nhưng điều kiện này vẫn được thỏa mãn trong nhiều trường hợp (ví dụ khi ít nhất một trong hai tập bị chặn).&lt;/p&gt;

&lt;h2 id=&quot;định-lý-siêu-phẳng-hỗ-trợ&quot;&gt;Định lý siêu phẳng hỗ trợ&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Định lý siêu phẳng hỗ trợ&lt;/strong&gt; khẳng định rằng với mọi tập lồi không rỗng \(C\) và mọi điểm \(x_0\) nằm trên biên &lt;strong&gt;bd&lt;/strong&gt; \(C\), luôn tồn tại ít nhất một siêu phẳng hỗ trợ cho \(C\) tại \(x_0\).&lt;/p&gt;

&lt;p&gt;Cụ thể, cho \(x_0\) là một điểm biên của \(C\). Nếu tồn tại \(a \ne 0\) sao cho \(a^T x \le a^T x_0\) với mọi \(x \in C\), thì siêu phẳng \(\{x \mid a^T x = a^T x_0 \}\) được gọi là &lt;strong&gt;siêu phẳng hỗ trợ&lt;/strong&gt; cho \(C\) tại \(x_0\).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lưu ý:&lt;/em&gt; Biên của tập \(C\) được định nghĩa là &lt;strong&gt;bd&lt;/strong&gt; \(C =\) &lt;strong&gt;cl&lt;/strong&gt; \(C \setminus\) &lt;strong&gt;int&lt;/strong&gt; \(C\), tức là bao đóng của \(C\) trừ đi phần trong của nó.&lt;/p&gt;

&lt;p&gt;Về mặt hình học, siêu phẳng hỗ trợ \(\{x \mid a^T x = a^T x_0\}\) đi qua điểm biên \(x_0\) và toàn bộ tập \(C\) nằm trọn trong nửa không gian \(a^T x \le a^T x_0\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.05_02_Supporting_hyperplane_theorem.png&quot; alt=&quot;[Hình 2] Siêu phẳng hỗ trợ [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Siêu phẳng hỗ trợ [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>02-04 Bất đẳng thức tổng quát</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_04_Generalized_inequalities/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_04_Generalized_inequalities</id>
   <content type="html">&lt;p&gt;Trên trục số thực \(\mathbb{R}\), ta luôn so sánh được hai số bất kỳ: \(3 &amp;lt; 5\) hay \(7 \ge 2\). Nhưng khi bạn tối ưu hóa một thiết kế xe hơi với hai mục tiêu xung đột — &lt;strong&gt;giá rẻ&lt;/strong&gt; và &lt;strong&gt;an toàn cao&lt;/strong&gt; — hoặc khi bạn muốn so sánh hai ma trận hiệp phương sai \(A\) và \(B\), dấu “\(\le\)” thông thường không còn đủ nữa. &lt;strong&gt;Bất đẳng thức tổng quát&lt;/strong&gt; (\(x \preceq_K y \iff y - x \in K\)) giải quyết bài toán này một cách tinh tế bằng cách dùng một &lt;strong&gt;hình nón thích hợp&lt;/strong&gt; \(K\) làm thước đo thứ tự!&lt;/p&gt;

&lt;p&gt;Bài học này mở rộng khái niệm so sánh từ số thực sang vector và ma trận, đồng thời phân biệt hai khái niệm cực kỳ quan trọng trong tối ưu hóa đa mục tiêu: &lt;strong&gt;phần tử tối tiểu (minimum)&lt;/strong&gt; và &lt;strong&gt;phần tử cực tiểu (minimal / Pareto optimal)&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-của-thứ-tự-theo-hình-nón&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép của thứ tự theo hình nón&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hình nón thích hợp (Proper Cone \(K\)):&lt;/strong&gt; Phải hội tụ đủ 4 điều kiện: lồi, đóng, đặc (có phần trong khác rỗng) và nhọn (không chứa cả đường thẳng nào, tức \(K \cap (-K) = \{0\}\)). Nhờ 4 tính chất này, quan hệ \(\preceq_K\) thỏa mãn phản xạ, phản đối xứng, bắc cầu và bảo toàn phép cộng/nhân dương.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai ví dụ mẫu mực:&lt;/strong&gt; \(K = \mathbb{R}_+^n\) sinh ra so sánh từng thành phần trên vector (\(x_i \le y_i\ \forall i\)); \(K = \mathbb{S}_+^n\) sinh ra thứ tự Loewner trên ma trận đối xứng (\(A \preceq B \iff B - A \succeq 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thứ tự bộ phận (Partial Order):&lt;/strong&gt; Khác với \(\mathbb{R}\), hai đối tượng có thể &lt;strong&gt;không so sánh được&lt;/strong&gt; với nhau (không \(x \preceq_K y\) cũng không \(y \preceq_K x\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối tiểu (Minimum) so với Cực tiểu (Minimal):&lt;/strong&gt; Phần tử tối tiểu nhỏ hơn &lt;em&gt;mọi&lt;/em&gt; phần tử khác (thường không tồn tại trong bài toán đa mục tiêu); phần tử cực tiểu (Pareto) là phần tử không bị bất kỳ phần tử nào khác vượt trội hơn hẳn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-hai-cặp-ma-trận-theo-thứ-tự-loewner-k--mathbbs_2&quot;&gt;Giải thích: So sánh hai cặp ma trận theo thứ tự Loewner (\(K = \mathbb{S}_+^2\))&lt;/h3&gt;

&lt;p&gt;Xét ba ma trận đối xứng \(2\times 2\):
\(A = \begin{pmatrix}3 &amp;amp; 1\\ 1 &amp;amp; 2\end{pmatrix}, \qquad B = \begin{pmatrix}2 &amp;amp; 0\\ 0 &amp;amp; 1\end{pmatrix}, \qquad C = \begin{pmatrix}3 &amp;amp; 0\\ 0 &amp;amp; 0\end{pmatrix}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;So sánh \(B\) và \(A\):&lt;/strong&gt; Tính hiệu:
\(A - B = \begin{pmatrix}1 &amp;amp; 1\\ 1 &amp;amp; 1\end{pmatrix}.\)
Ma trận \(A - B\) có vết \(2\), định thức \(0 \implies\) giá trị riêng \(\lambda_1 = 2 \ge 0,\ \lambda_2 = 0 \ge 0\). Vậy \(A - B \in \mathbb{S}_+^2\), tức \(B \preceq_{\mathbb{S}_+^2} A\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh \(B\) và \(C\):&lt;/strong&gt; Tính hiệu:
\(C - B = \begin{pmatrix}1 &amp;amp; 0\\ 0 &amp;amp; -1\end{pmatrix}.\)
Giá trị riêng là \(\lambda_1 = +1 &amp;gt; 0\) và \(\lambda_2 = -1 &amp;lt; 0\). Do có cả trị riêng dương và âm, \(C - B \notin \mathbb{S}_+^2\) và \(B - C \notin \mathbb{S}_+^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; \(B\) và \(C\) &lt;strong&gt;không so sánh được&lt;/strong&gt; theo thứ tự Loewner — minh họa trực quan cho tính chất thứ tự bộ phận của bất đẳng thức tổng quát!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trên trục số thực một chiều \(\mathbb{R}\), với hai số bất kỳ như 1 và 2, ta luôn so sánh được 2 lớn hơn 1. Tuy nhiên, trong không gian thực \(n\) chiều \(\mathbb{R}^n\), việc so sánh hai điểm \(x_1\) và \(x_2\) không còn hiển nhiên như vậy.&lt;/p&gt;

&lt;p&gt;Phần này giới thiệu &lt;strong&gt;bất đẳng thức tổng quát&lt;/strong&gt; để xác định quan hệ thứ tự giữa các điểm trong \(\mathbb{R}^n\), cùng hai khái niệm phần tử tối tiểu (minimum) và phần tử cực tiểu (minimal) của một tập hợp.&lt;/p&gt;

&lt;h2 id=&quot;hình-nón-thích-hợp&quot;&gt;Hình nón thích hợp&lt;/h2&gt;

&lt;p&gt;Một hình nón lồi \(K \subseteq \mathbb{R}^n\) được gọi là &lt;strong&gt;hình nón thích hợp&lt;/strong&gt; (proper cone) nếu thỏa mãn ba điều kiện sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(K\) là tập đóng (chứa biên của chính nó).&lt;/li&gt;
  &lt;li&gt;\(K\) là hình nón đặc (solid), tức là phần trong của nó khác rỗng.&lt;/li&gt;
  &lt;li&gt;\(K\) là hình nón nhọn (pointed), tức là không chứa đường thẳng nào đi qua gốc tọa độ (\(x \in K, -x \in K \implies x = 0\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nếu một hình nón lồi đóng và nhọn chỉ nằm trong một không gian con có số chiều từ \(n-1\) trở xuống, phần trong của nó trong \(\mathbb{R}^n\) sẽ rỗng vì nó không thể chứa bất kỳ hình cầu mở \(n\) chiều nào. Khi đó, hình nón không đặc và không phải là hình nón thích hợp. Ví dụ, một hình quạt 2D đóng và nhọn đặt trong không gian \(\mathbb{R}^3\) không phải là hình nón thích hợp.&lt;/p&gt;

&lt;p&gt;Xem thêm &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Interior_(topology)&quot;&gt;Wikipedia: Interior (topology)&lt;/a&gt;&lt;/em&gt; để biết định nghĩa về phần trong của một tập hợp.&lt;/p&gt;

&lt;h2 id=&quot;bất-đẳng-thức-tổng-quát&quot;&gt;Bất đẳng thức tổng quát&lt;/h2&gt;

&lt;p&gt;Dựa trên một hình nón thích hợp \(K\), ta định nghĩa một quan hệ thứ tự bộ phận trong \(\mathbb{R}^n\) gọi là &lt;strong&gt;bất đẳng thức tổng quát&lt;/strong&gt;, mang nhiều tính chất tương tự thứ tự thông thường trên \(\mathbb{R}\):&lt;/p&gt;

&lt;blockquote&gt;
\[x \preceq_{K} y \iff y - x \in K\]
&lt;/blockquote&gt;

&lt;p&gt;Tương tự, bất đẳng thức tổng quát nghiêm ngặt được định nghĩa bởi:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x \prec_{K} y \iff y - x \in\) &lt;strong&gt;int&lt;/strong&gt; \(K\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Khi \(K = \mathbb{R}_{+}\), quan hệ \(\preceq_{K}\) chính là dấu \(\le\) quen thuộc trên \(\mathbb{R}\).&lt;/p&gt;

&lt;h3 id=&quot;tính-chất-của-bất-đẳng-thức-tổng-quát&quot;&gt;Tính chất của bất đẳng thức tổng quát&lt;/h3&gt;

&lt;p&gt;Bất đẳng thức tổng quát \(\preceq_{K}\) có các tính chất sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bảo toàn dưới phép cộng&lt;/strong&gt;: nếu \(x \preceq_{K} y\) và \(u \preceq_{K} v\) thì \(x+u \preceq_{K} y +v\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bắc cầu&lt;/strong&gt;: nếu \(x \preceq_{K} y\) và \(y \preceq_{K} z\) thì \(x \preceq_{K}  z\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bảo toàn dưới phép nhân vô hướng không âm&lt;/strong&gt;: nếu \(x \preceq_{K} y\) và \(\alpha \ge 0\) thì \(\alpha x \preceq_{K} \alpha y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính phản xạ&lt;/strong&gt;: \(x \preceq_{K} x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính phản đối xứng&lt;/strong&gt;: nếu \(x \preceq_{K} y\) và \(y \preceq_{K} x\) thì \(x = y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bảo toàn qua giới hạn&lt;/strong&gt;: nếu \(x_i \preceq_{K}  y_i\) với mọi \(i = 1, 2, \dots\), \(x_i \to x\) và \(y_i \to y\) khi \(i \to \infty\), thì \(x \preceq_{K} y\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bất đẳng thức tổng quát nghiêm ngặt \(\prec_{K}\) cũng có các tính chất tương ứng (trừ tính phản xạ và tính bảo toàn qua giới hạn).&lt;/p&gt;

&lt;h2 id=&quot;phần-tử-tối-tiểu-và-cực-tiểu&quot;&gt;Phần tử tối tiểu và cực tiểu&lt;/h2&gt;

&lt;p&gt;Điểm khác biệt quan trọng nhất giữa thứ tự thông thường trên \(\mathbb{R}\) và bất đẳng thức tổng quát trong \(\mathbb{R}^n\) nằm ở &lt;strong&gt;tính toàn phần (thứ tự tuyến tính)&lt;/strong&gt;. Trên \(\mathbb{R}\), hai số bất kỳ luôn so sánh được với nhau (\(x \le y\) hoặc \(y \le x\)), nhưng với bất đẳng thức tổng quát thì không nhất thiết như vậy. Vì thế, khái niệm nhỏ nhất được tách thành hai khái niệm phân biệt: tối tiểu và cực tiểu.&lt;/p&gt;

&lt;h3 id=&quot;phần-tử-tối-tiểu&quot;&gt;Phần tử tối tiểu&lt;/h3&gt;

&lt;p&gt;Điểm \(x \in S\) được gọi là phần tử &lt;strong&gt;tối tiểu&lt;/strong&gt; (minimum) của tập \(S\) nếu \(x \preceq_{K} y\) với mọi \(y \in S\). Phần tử &lt;strong&gt;tối đại&lt;/strong&gt; (maximum) được định nghĩa tương tự. Nếu tập \(S\) có phần tử tối tiểu thì phần tử đó là duy nhất.&lt;/p&gt;

&lt;p&gt;Về mặt tập hợp, \(x \in S\) là phần tử tối tiểu của \(S\) khi và chỉ khi \(S \subseteq x + K\), trong đó \(x + K\) là tập tất cả các điểm so sánh được với \(x\) và lớn hơn hoặc bằng \(x\) theo \(\preceq_{K}\).&lt;/p&gt;

&lt;h3 id=&quot;phần-tử-cực-tiểu&quot;&gt;Phần tử cực tiểu&lt;/h3&gt;

&lt;p&gt;Điểm \(x \in S\) được gọi là phần tử &lt;strong&gt;cực tiểu&lt;/strong&gt; (minimal) của tập \(S\) nếu không tồn tại điểm \(y \in S\) nào khác \(x\) sao cho \(y \preceq_{K} x\) (tức là với mọi \(y \in S\), \(y \preceq_{K} x \implies y = x\)). Phần tử &lt;strong&gt;cực đại&lt;/strong&gt; (maximal) được định nghĩa tương tự. Khác với phần tử tối tiểu, một tập hợp có thể có nhiều phần tử cực tiểu.&lt;/p&gt;

&lt;p&gt;Về mặt tập hợp, \(x \in S\) là phần tử cực tiểu của \(S\) khi và chỉ khi \((x - K) \cap S = \{x\}\), trong đó \(x - K\) là tập tất cả các điểm so sánh được với \(x\) và nhỏ hơn hoặc bằng \(x\) theo \(\preceq_{K}\).&lt;/p&gt;

&lt;p&gt;Khi \(K = \mathbb{R}_{+}\), hai khái niệm phần tử tối tiểu và phần tử cực tiểu trùng nhau.&lt;/p&gt;

&lt;h3 id=&quot;tối-tiểu-và-cực-tiểu-trong-hình-nón-mathbbr2_&quot;&gt;Tối tiểu và cực tiểu trong hình nón \(\mathbb{R}^2_{+}\)&lt;/h3&gt;

&lt;p&gt;Xét hình nón \(K = \mathbb{R}^2_{+}\). Bất đẳng thức \(x \preceq_{K} y\) có nghĩa là \(y\) nằm ở phía trên bên phải của \(x\). Do đó, với \(x \in S\), nói \(x\) là phần tử tối tiểu nghĩa là mọi điểm của \(S\) đều nằm ở phía trên bên phải của \(x\); còn nói \(x\) là phần tử cực tiểu nghĩa là không có điểm nào khác của \(S\) nằm ở phía dưới bên trái của \(x\).&lt;/p&gt;

&lt;p&gt;Trong hình dưới đây, tập \(S_1\) có phần tử tối tiểu \(x_1\) vì vùng \(x_1 + K\) (tô màu xám nhạt) bao trọn \(S_1\) (\(S_1 \subseteq x_1 + K\)). Tập \(S_2\) có phần tử cực tiểu \(x_2\) vì vùng \(x_2 - K\) (tô màu xám nhạt) chỉ giao với \(S_2\) tại đúng điểm \(x_2\) (\((x_2 - K) \cap S_2 = \{x_2\}\)).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_01_Minimum_and_minimal.png&quot; alt=&quot;[Hình1] Phần tử tối tiểu và cực tiểu [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình1] Phần tử tối tiểu và cực tiểu [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>02-03 Các phép toán bảo toàn tính lồi của tập lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_03_Operations_that_preserve_convexity/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_03_Operations_that_preserve_convexity</id>
   <content type="html">&lt;p&gt;Khi đối mặt với một miền khả thi phức tạp như tập các ma trận có trị riêng lớn nhất không quá 1, hay tập nghiệm của một bài toán quy hoạch phân thức tuyến tính, việc trực tiếp lấy hai điểm \(x_1, x_2\) rồi kiểm tra \(\theta x_1 + (1-\theta)x_2\) thường vừa dài vừa dễ rối. Bí quyết của giới tối ưu hóa là &lt;strong&gt;tư duy lắp ghép&lt;/strong&gt;: xuất phát từ vài tập lồi đơn giản đã biết, rồi áp dụng các &lt;strong&gt;phép toán bảo toàn tính lồi&lt;/strong&gt; (giao, ảnh/ảnh ngược affine, hàm phối cảnh) để kết luận ngay tập kết quả chắc chắn lồi!&lt;/p&gt;

&lt;p&gt;Bài học này trang bị bộ quy tắc lắp ghép tập lồi sẽ giúp bạn chứng minh tính lồi chỉ trong 2–3 dòng suy luận.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-phép-toán-vàng-bảo-toàn-tính-lồi&quot;&gt;Kiến thức cần nhớ: Bốn phép toán vàng bảo toàn tính lồi&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/chapter02/02.03_03_pine_hole.png&quot; alt=&quot;Mô hình hộp tối (Pinhole Camera)&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/chapter02/02.03_04_pine_hole_camera_model.png&quot; alt=&quot;Phép chiếu phối cảnh qua lỗ kim&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/chapter02/02.03_05_linear_fractional_function.png&quot; alt=&quot;Hàm phân thức tuyến tính bảo toàn tính lồi&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phép giao (Intersection):&lt;/strong&gt; Giao của một họ &lt;strong&gt;bất kỳ&lt;/strong&gt; (hữu hạn hoặc vô hạn!) các tập lồi luôn là tập lồi. Đây là cách chứng minh nhanh nhất rằng đa diện (giao hữu hạn nửa không gian) và hình nón \(\mathbb{S}_+^n\) (giao vô hạn nửa không gian \(z^T X z \ge 0\)) đều lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ánh xạ affine (\(f(x) = Ax + b\)) và ảnh ngược affine:&lt;/strong&gt; Tịnh tiến, co giãn, xoay, phép chiếu trực giao và tổng Minkowski \(S_1 + S_2\) của các tập lồi đều bảo toàn tính lồi. Đặc biệt, ảnh ngược của một tập lồi qua \(Ax + b\) cũng luôn lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm phối cảnh (Perspective Function):&lt;/strong&gt; \(P(z, t) = z / t\) trên \(t &amp;gt; 0\) — tương ứng hình học với máy ảnh lỗ kim chiếu không gian 3D lên màn ảnh 2D. Cả ảnh xuôi lẫn ảnh ngược của tập lồi qua \(P\) đều lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm phân thức tuyến tính (Linear-Fractional):&lt;/strong&gt; Kết hợp ánh xạ affine và hàm phối cảnh \(f(x) = \frac{Ax + b}{c^T x + d}\) (với \(c^T x + d &amp;gt; 0\)) — chìa khóa giải quyết bài toán tối ưu phân thức (như tỷ lệ lợi nhuận trên rủi ro).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-quan-sát-hàm-phối-cảnh-biến-trung-điểm-thành-tổ-hợp-lồi-có-trọng-số-mới&quot;&gt;Giải thích: Quan sát hàm phối cảnh biến trung điểm thành tổ hợp lồi có trọng số mới&lt;/h3&gt;

&lt;p&gt;Xét hàm phối cảnh \(P(z, t) = \frac{z}{t}\) (với \(z \in \mathbb{R},\ t &amp;gt; 0\)). Giả sử một tập lồi \(C \subset \mathbb{R} \times \mathbb{R}_{++}\) chứa hai điểm \(u_1 = (z_1, t_1) = (2, 1)\) và \(u_2 = (z_2, t_2) = (12, 3)\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Ảnh phối cảnh của hai đầu mút:&lt;/strong&gt;
\(P(u_1) = \frac{2}{1} = 2, \qquad P(u_2) = \frac{12}{3} = 4.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lấy trung điểm (\(\theta = 0.5\)) trong miền nguồn \(C\):&lt;/strong&gt;
\(u_{\text{mid}} = 0.5(2, 1) + 0.5(12, 3) = (7, 2) \in C.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính ảnh phối cảnh của trung điểm:&lt;/strong&gt;
\(P(u_{\text{mid}}) = \frac{7}{2} = 3.5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng tính lồi (với trọng số \(\mu\) đã đổi do chia cho \(t\)):&lt;/strong&gt;
Chú ý rằng \(3.5\) không phải trung điểm \(3\) của \(2\) và \(4\), mà là tổ hợp lồi với trọng số mới:
\(\mu = \frac{\theta t_1}{\theta t_1 + (1-\theta)t_2} = \frac{0.5 \cdot 1}{0.5 \cdot 1 + 0.5 \cdot 3} = \frac{0.5}{2} = \frac{1}{4} \in [0, 1].\)
Thay vào: \(\mu P(u_1) + (1-\mu) P(u_2) = \frac{1}{4}(2) + \frac{3}{4}(4) = 0.5 + 3 = 3.5 = P(u_{\text{mid}})\)! Ảnh của cả đoạn thẳng \([u_1, u_2]\) vẫn là đúng đoạn thẳng \([2, 4]\), chỉ bị kéo giãn dọc theo trục \(t\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này trình bày các phép toán bảo toàn tính lồi của tập hợp. Những phép toán này giúp ta kiểm tra tính lồi của một tập phức tạp hoặc xây dựng tập lồi mới từ các tập cơ bản như siêu phẳng, nửa không gian và hình cầu chuẩn.&lt;/p&gt;

&lt;p&gt;Các phép toán chính bảo toàn tính lồi gồm:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Phép giao&lt;/li&gt;
  &lt;li&gt;Hàm affine&lt;/li&gt;
  &lt;li&gt;Hàm phối cảnh&lt;/li&gt;
  &lt;li&gt;Hàm tuyến tính-phân thức&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giao&quot;&gt;Giao&lt;/h2&gt;

&lt;p&gt;Giao của các tập lồi là một tập lồi: nếu \(S_1\) và \(S_2\) là tập lồi thì \(S_1 \cap S_2\) cũng là tập lồi. Tính chất này đúng cho giao của họ bất kỳ (kể cả vô hạn) các tập lồi. (Không gian con, tập affine và hình nón lồi cũng đóng đối với phép giao.)&lt;/p&gt;

&lt;p&gt;Mọi tập lồi đóng đều có thể biểu diễn dưới dạng giao của các nửa không gian chứa nó, và ngược lại, giao của bất kỳ họ nửa không gian nào cũng là một tập lồi đóng:&lt;/p&gt;

&lt;blockquote&gt;
\[S = \bigcap \{\mathcal{H} \mid \mathcal{H} \text{ là nửa không gian }, S \subseteq \mathcal{H}\}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;hàm-affine&quot;&gt;Hàm affine&lt;/h2&gt;

&lt;p&gt;Cho \(A \in \mathbb{R}^{m \times n}\) và \(b \in \mathbb{R}^{m}\). Ánh xạ \(f : \mathbb{R}^n \to \mathbb{R}^m\) xác định bởi \(f(x) = Ax + b\) được gọi là hàm affine.&lt;/p&gt;

&lt;p&gt;Nếu \(C \subseteq \mathbb{R}^n\) và \(D \subseteq \mathbb{R}^m\) là các tập lồi, thì:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ảnh affine \(f(C) = \{f(x) \mid x \in C\}\) là tập lồi.&lt;/li&gt;
  &lt;li&gt;Nghịch ảnh affine \(f^{-1}(D) = \{x \mid f(x) \in D\}\) là tập lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nhờ tính chất này, các phép biến đổi affine như co giãn, tịnh tiến, phép chiếu, tổng hai tập hợp và tổng từng phần đều bảo toàn tính lồi.&lt;/p&gt;

&lt;p&gt;Hai ví dụ quan trọng suy ra từ tính chất này là:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tập nghiệm của một bất đẳng thức ma trận tuyến tính \(\{x \mid x_1 A_1 + \cdots + x_m A_m \preceq B\}\) (với \(A_i, B \in S^n\)) là tập lồi.&lt;/li&gt;
  &lt;li&gt;Hình nón hyperbolic \(\{x \mid x^T P x &amp;lt; (c^T x)^2, c^T x &amp;gt; 0\}\) (với \(P \in S^n_+\), \(c \in \mathbb{R}^n\)) cũng là tập lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;hàm-phối-cảnh&quot;&gt;Hàm phối cảnh&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Hàm phối cảnh&lt;/strong&gt; mô hình hóa hiện tượng các vật thể trông nhỏ hơn khi ở xa và lớn hơn khi ở gần, tương tự cách máy ảnh chiếu vật thể từ không gian \(\mathbb{R}^{n+1}\) xuống mặt phẳng ảnh trong \(\mathbb{R}^n\).&lt;/p&gt;

&lt;p&gt;Hàm phối cảnh \(P : \mathbb{R}^{n+1} \to \mathbb{R}^{n}\) có miền xác định &lt;strong&gt;dom&lt;/strong&gt; \(P = \mathbb{R}^{n} \times \mathbb{R}_{++}\) (với \(\mathbb{R}_{++} = \{x \in \mathbb{R} \mid x &amp;gt; 0\}\)) và được cho bởi \(P(z,t) = z/t\). Phép biến đổi này chuẩn hóa tọa độ cuối cùng về 1 rồi bỏ tọa độ đó đi, đưa điểm từ \(\mathbb{R}^{n+1}\) về \(\mathbb{R}^n\). Nếu \(C \subseteq\) &lt;strong&gt;dom&lt;/strong&gt; \(P\) là tập lồi, thì ảnh \(P(C) = \{P(x) \mid x \in C\}\) cũng là tập lồi.&lt;/p&gt;

&lt;p&gt;Hàm phối cảnh hoạt động như một máy ảnh lỗ kim: vật ở xa lỗ kim cho ảnh chiếu nhỏ hơn, còn các điểm nằm trên cùng một tia xuất phát từ lỗ kim sẽ có cùng ảnh chiếu.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-02 Một số ví dụ quan trọng</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_02_Some_important_examples/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_02_Some_important_examples</id>
   <content type="html">&lt;p&gt;Trong thực hành tối ưu hóa, bạn hiếm khi phải ngồi chứng minh một tập hợp phức tạp là lồi từ con số 0. Thay vào đó, các chuyên gia luôn giữ trong đầu một “bộ sưu tập mẫu chuẩn” gồm các khối gạch lồi cơ bản — nửa không gian, đa diện, hình cầu, ellipsoid, đơn hình xác suất và hình nón ma trận — rồi lắp ghép chúng lại để nhận diện bài toán chỉ trong vài giây.&lt;/p&gt;

&lt;p&gt;Phần 02-02 giới thiệu danh mục các tập lồi và hình nón lồi quan trọng nhất xuất hiện dày đặc trong lý thuyết cũng như phần mềm tối ưu hóa.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-họ-gạch-xây-của-miền-khả-thi-lồi&quot;&gt;Kiến thức cần nhớ: Bốn họ “gạch xây” của miền khả thi lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nhóm tuyến tính (Siêu phẳng, Nửa không gian, Đa diện, Đơn hình):&lt;/strong&gt; Được định nghĩa bởi các bất đẳng thức và đẳng thức tuyến tính \(Ax \le b,\ Cx = d\) — lãnh địa của Quy hoạch tuyến tính (LP).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhóm bậc hai &amp;amp; chuẩn (Hình cầu Euclid, Ellipsoid, Hình cầu \(\ell_1/\ell_\infty\)):&lt;/strong&gt; Định nghĩa qua chuẩn hoặc ma trận xác định dương — lãnh địa của tối ưu hóa có điều chuẩn (Ridge/Lasso) và Quy hoạch nón bậc hai (SOCP).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhóm hình nón (Nón chuẩn, Nón không âm \(\mathbb{R}_+^n\), Nón PSD \(\mathbb{S}_+^n\)):&lt;/strong&gt; Là nền tảng cho tối ưu hóa nón hiện đại (LP \(\subset\) SOCP \(\subset\) SDP).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-đặt-cùng-một-điểm-x--05-05t-vào-4-tập-lồi-kinh-điển&quot;&gt;Giải thích: Đặt cùng một điểm \(x = (0.5, 0.5)^T\) vào 4 tập lồi kinh điển&lt;/h3&gt;

&lt;p&gt;Hãy kiểm tra xem điểm \(x = (0.5, 0.5)^T \in \mathbb{R}^2\) nằm trong, trên biên, hay ngoài 4 tập lồi mẫu sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hình cầu đơn vị Euclid \(B_2 = \{x : \|x\|_2 \le 1\}\):&lt;/strong&gt;
\(\|x\|_2 = \sqrt{0.5^2 + 0.5^2} = \sqrt{0.5} \approx 0.707 &amp;lt; 1 \implies\) nằm &lt;strong&gt;chặt bên trong&lt;/strong&gt; \(B_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình cầu đơn vị chuẩn \(\ell_1\) \(B_1 = \{x : \|x\|_1 \le 1\}\):&lt;/strong&gt;
\(\|x\|_1 = |0.5| + |0.5| = 1 \implies\) nằm &lt;strong&gt;ngay trên biên&lt;/strong&gt; của hình thoi \(B_1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đơn hình xác suất \(\Delta_2 = \{x \ge 0 : x_1 + x_2 = 1\}\):&lt;/strong&gt;
\(x_1, x_2 \ge 0\) và \(0.5 + 0.5 = 1 \implies\) thuộc \(\Delta_2\) (biểu diễn phân phối đều 50%–50%).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nửa không gian \(H^- = \{x : 2x_1 + x_2 \le 1\}\):&lt;/strong&gt;
\(2(0.5) + 0.5 = 1.5 &amp;gt; 1 \implies\) nằm &lt;strong&gt;ngoài&lt;/strong&gt; \(H^-\)!
Cùng một tọa độ, nhưng đổi hình dạng ràng buộc là thay đổi hoàn toàn trạng thái khả thi và trạng thái ràng buộc chặt.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này liệt kê các ví dụ quan trọng thường gặp về tập lồi:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Các tập hợp tầm thường: tập rỗng, một điểm, đường thẳng, đoạn thẳng, tia.&lt;/li&gt;
  &lt;li&gt;Siêu phẳng: \(\{x : a^T x = b\}\), với \(a, b\) cho trước và \(a \ne 0\).&lt;/li&gt;
  &lt;li&gt;Nửa không gian: \(\{x : a^T x \le b \}\) với \(a \ne 0\).&lt;/li&gt;
  &lt;li&gt;Tập affine: \(\{x : Ax = b\}\), với \(A, b\) cho trước.&lt;/li&gt;
  &lt;li&gt;Hình cầu Euclidean và ellipsoid.&lt;/li&gt;
  &lt;li&gt;Hình cầu chuẩn: \(\{x : \| x \| \le r\}\), với chuẩn \(\|·\|\) và bán kính \(r\) cho trước.&lt;/li&gt;
  &lt;li&gt;Hình nón lồi: hình nón chuẩn, hình nón pháp tuyến và hình nón nửa xác định dương.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-02-02 Ví dụ về hình nón lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_02_02_Convex_cone_examples/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_02_02_Convex_cone_examples</id>
   <content type="html">&lt;p&gt;Nếu Quy hoạch tuyến tính (LP) làm việc trên hình nón các vector không âm \(\mathbb{R}_+^n\), thì bước nhảy vọt vĩ đại nhất của tối ưu hóa lồi nửa cuối thế kỷ 20 là mở rộng ý tưởng đó lên &lt;strong&gt;hình nón bậc hai (nón kem — ice-cream cone)&lt;/strong&gt; và &lt;strong&gt;hình nón ma trận bán xác định dương \(\mathbb{S}_+^n\)&lt;/strong&gt;. Điều kỳ diệu là nhiều bài toán tưởng chừng bất khả thi — từ thiết kế mạch điện, kiểm soát robot đến xấp xỉ bài toán đồ thị Max-Cut — bỗng giải được trong thời gian đa thức khi đặt vào đúng hình nón lồi!&lt;/p&gt;

&lt;p&gt;Bài học này giới thiệu ba hình nón lồi nổi tiếng nhất: hình nón chuẩn, hình nón pháp tuyến và hình nón nửa xác định dương.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bộ-ba-hình-nón-quyền-lực-của-tối-ưu-hóa-hiện-đại&quot;&gt;Kiến thức cần nhớ: Bộ ba hình nón quyền lực của tối ưu hóa hiện đại&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hình nón chuẩn (Norm Cone):&lt;/strong&gt; \(C = \{(x, t) \in \mathbb{R}^{n+1} : \|x\| \le t\}\). Khi dùng chuẩn Euclid \(\ell_2\), ta có &lt;strong&gt;hình nón bậc hai (Second-Order Cone — SOC)&lt;/strong&gt; — nền tảng của SOCP, dùng để mô tả ràng buộc phương sai rủi ro và độ bền vững (robustness).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình nón pháp tuyến (Normal Cone):&lt;/strong&gt; Gắn với một điểm biên \(x_0\) của tập lồi \(C\), gồm tất cả các vector \(g\) hướng ra ngoài sao cho \(g^T(x - x_0) \le 0\ \forall x \in C\). Điều kiện tối ưu cho bài toán có ràng buộc được viết siêu gọn: \(-\nabla f(x^*) \in N_C(x^*)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình nón nửa xác định dương (\(\mathbb{S}_+^n\)):&lt;/strong&gt; Tập các ma trận đối xứng \(n \times n\) có mọi giá trị riêng \(\ge 0\) (tức \(z^T X z \ge 0\ \forall z\)). Đây là tập lồi (thậm chí là hình nón lồi) vì là giao của vô số nửa không gian tuyến tính theo \(X\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tính-đóng-của-hình-nón-bán-xác-định-dương-mathbbs_2&quot;&gt;Giải thích: Kiểm chứng tính đóng của hình nón bán xác định dương \(\mathbb{S}_+^2\)&lt;/h3&gt;

&lt;p&gt;Xét hai ma trận đối xứng \(2\times 2\):
\(A = \begin{pmatrix}4 &amp;amp; 2\\ 2 &amp;amp; 1\end{pmatrix}, \qquad B = \begin{pmatrix}1 &amp;amp; 0\\ 0 &amp;amp; 4\end{pmatrix}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra \(A \in \mathbb{S}_+^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đường chéo chính: \(4 \ge 0,\ 1 \ge 0\); định thức \(\det(A) = 4\cdot 1 - 2\cdot 2 = 0\); vết \(\operatorname{tr}(A) = 5\).&lt;/li&gt;
      &lt;li&gt;Hai giá trị riêng là \(\lambda_1 = 5,\ \lambda_2 = 0 \ge 0 \implies A \in \mathbb{S}_+^2\) (nằm đúng trên &lt;strong&gt;biên&lt;/strong&gt; của hình nón vì có một giá trị riêng bằng \(0\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra \(B \in \mathbb{S}_+^2\):&lt;/strong&gt; Hai giá trị riêng là \(1 &amp;gt; 0\) và \(4 &amp;gt; 0 \implies B \in \mathbb{S}_{++}^2\) (nằm chặt bên trong hình nón).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lấy tổ hợp nón \(C = A + B = \begin{pmatrix}5 &amp;amp; 2\\ 2 &amp;amp; 5\end{pmatrix}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vết \(\operatorname{tr}(C) = 10\), định thức \(\det(C) = 25 - 4 = 21 &amp;gt; 0\).&lt;/li&gt;
      &lt;li&gt;Phương trình đặc trưng: \(\lambda^2 - 10\lambda + 21 = (\lambda - 7)(\lambda - 3) = 0 \implies \lambda_1 = 7,\ \lambda_2 = 3 &amp;gt; 0\).
Tổng của hai ma trận thuộc \(\mathbb{S}_+^2\) vẫn thuộc chặt bên trong \(\mathbb{S}_+^2\) — minh họa trực tiếp tính chất hình nón lồi!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Các ví dụ tiêu biểu về hình nón lồi gồm hình nón chuẩn, hình nón pháp tuyến và hình nón nửa xác định dương.&lt;/p&gt;

&lt;h2 id=&quot;hình-nón-chuẩn&quot;&gt;Hình nón chuẩn&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Hình nón chuẩn&lt;/strong&gt; là tập hợp các điểm \((x, t) \in \mathbb{R}^{n+1}\) thỏa mãn \(\| x \| \le t\), với \(\|\cdot\|\) là một chuẩn bất kỳ trên \(\mathbb{R}^n\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(C = \{(x, t) : \| x \| \le t\} \subseteq \mathbb{R}^{n+1}\), với chuẩn \(\|·\|\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hình dưới đây minh họa hình nón chuẩn ứng với chuẩn \(\ell_2\) (\(\|·\|_2\)), còn gọi là hình nón bậc hai (second-order cone) hay hình nón kem.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.08_Norm_Cone.png&quot; alt=&quot;[Hình1] Hình Nón Chuẩn [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình1] Hình Nón Chuẩn [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;hình-nón-pháp-tuyến&quot;&gt;Hình nón pháp tuyến&lt;/h2&gt;

&lt;p&gt;Cho một tập \(C\) và điểm \(x \in C\), &lt;strong&gt;hình nón pháp tuyến&lt;/strong&gt; tại \(x\) được định nghĩa là:&lt;/p&gt;

&lt;blockquote&gt;
\[N_C(x) = \{ g: g^T (y - x) \le 0, \text{ với mọi } y \in C \}\]
&lt;/blockquote&gt;

&lt;p&gt;Hình nón pháp tuyến chứa tất cả các vector \(g\) có tích vô hướng không dương với \(y - x\) với mọi \(y \in C\), nghĩa là góc \(\theta\) giữa \(g\) và \(y - x\) thỏa mãn \(\cos\theta \le 0\) (từ \(90^\circ\) đến \(270^\circ\)).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nếu \(x\) nằm trên phần biên trơn của \(C\), các vector \(g \ne 0\) cùng phương với vector pháp tuyến ngoài duy nhất của siêu phẳng hỗ trợ tại \(x\).&lt;/li&gt;
  &lt;li&gt;Nếu \(x\) là một đỉnh, tồn tại nhiều siêu phẳng hỗ trợ nên tập các vector \(g\) tạo thành hình quạt.&lt;/li&gt;
  &lt;li&gt;Nếu \(x\) nằm ở phần trong của \(C\), vector duy nhất thuộc \(N_C(x)\) là vector không.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hình dưới đây minh họa các vector pháp tuyến tương ứng với từng vị trí của \(x\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.04_2_Normal_Cone.png&quot; alt=&quot;[Hình2] Hình Nón Pháp Tuyến [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình2] Hình Nón Pháp Tuyến [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;hình-nón-nửa-xác-định-dương&quot;&gt;Hình nón nửa xác định dương&lt;/h2&gt;

&lt;p&gt;Ký hiệu \(\mathbb{S}^n\) là tập các ma trận đối xứng cỡ \(n \times n\). &lt;strong&gt;Hình nón nửa xác định dương&lt;/strong&gt; \(\mathbb{S}^n_+\) được định nghĩa là:&lt;/p&gt;

&lt;blockquote&gt;
\[\mathbb{S}^n_+ = \{ X \in \mathbb{S}^n : X \succeq 0 \}\]
&lt;/blockquote&gt;

&lt;p&gt;Tập \(\mathbb{S}^n_+\) là một hình nón lồi vì với mọi \(\theta_1, \theta_2 \ge 0\) và \(A, B \in \mathbb{S}^n_+\), ta luôn có \(\theta_1 A + \theta_2 B \in \mathbb{S}^n_+\).&lt;/p&gt;

&lt;p&gt;Hình dưới đây minh họa biên của hình nón nửa xác định dương \(\mathbb{S}^2_+\) trong không gian tọa độ \((x, y, z) \in \mathbb{R}^3\). Một ma trận đối xứng \(2 \times 2\) là nửa xác định dương khi và chỉ khi các phần tử trên đường chéo và định thức của nó đều không âm:&lt;/p&gt;

\[X = 
\begin{bmatrix}
x, y \\
y, z
\end{bmatrix}
\in \mathbb{S}^2_+ \iff x \ge 0, z \ge 0, xz \ge y^2\]

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.10_Positive_Semidefinite_Cone.png&quot; alt=&quot;[Hình3] Hình nón nửa xác định dương [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình3] Hình nón nửa xác định dương [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>02-02-01 Ví dụ về tập lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_02_01_Convex_sets_examples/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_02_01_Convex_sets_examples</id>
   <content type="html">&lt;p&gt;Từ phương trình đường tròn đơn giản đến tập nghiệm của một hệ hàng nghìn ràng buộc tài chính hay tập ma trận hiệp phương sai hợp lệ, thế giới các tập lồi phong phú hơn tưởng tượng rất nhiều. Biết đọc ngay cấu trúc hình học của &lt;strong&gt;nửa không gian&lt;/strong&gt;, &lt;strong&gt;hình cầu chuẩn&lt;/strong&gt;, &lt;strong&gt;ellipsoid&lt;/strong&gt; và &lt;strong&gt;đa diện (polyhedra)&lt;/strong&gt; sẽ giúp bạn nhận ra ngay một bài toán thuộc lớp LP, QP hay SOCP ngay từ lần đọc đầu tiên.&lt;/p&gt;

&lt;p&gt;Bài học này phân tích chi tiết công thức, trực giác hình học và chứng minh tính lồi của những tập lồi kinh điển nhất.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-họ-tập-lồi-chủ-lực&quot;&gt;Kiến thức cần nhớ: Bốn họ tập lồi chủ lực&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Siêu phẳng và Nửa không gian:&lt;/strong&gt; \(a^T x = b\) và \(a^T x \le b\) — là những khối cơ bản nhất; mọi tập lồi đóng đều có thể biểu diễn thành giao của (có thể vô hạn) các nửa không gian!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đa diện (Polyhedron) và Đơn hình (Simplex):&lt;/strong&gt; Giao hữu hạn của các nửa không gian và siêu phẳng \(\{x : Ax \preceq b,\ Cx = d\}\). Tập nghiệm khả thi của mọi bài toán LP là một đa diện.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình cầu Euclid và Hình cầu chuẩn (Norm Balls):&lt;/strong&gt; \(B(x_c, r) = \{x : \|x - x_c\| \le r\}\) luôn lồi nhờ tính đồng nhất dương và bất đẳng thức tam giác của chuẩn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ellipsoid:&lt;/strong&gt; \(\mathcal{E} = \{x : (x - x_c)^T P^{-1}(x - x_c) \le 1\}\) với \(P \succ 0\) — chính là ảnh biến dạng tuyến tính của hình cầu đơn vị, trong đó độ dài các bán trục bằng căn bậc hai các giá trị riêng \(\sqrt{\lambda_i(P)}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-đọc-bán-trục-và-kiểm-tra-điểm-thuộc-một-ellipsoid&quot;&gt;Giải thích: Đọc bán trục và kiểm tra điểm thuộc một Ellipsoid&lt;/h3&gt;

&lt;p&gt;Xét ellipsoid trong \(\mathbb{R}^2\) có tâm \(x_c = (1, 0)^T\) và ma trận hình dạng \(P = \begin{pmatrix}9 &amp;amp; 0\\ 0 &amp;amp; 4\end{pmatrix} \succ 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Viết phương trình tường minh:&lt;/strong&gt; Ma trận nghịch đảo là \(P^{-1} = \begin{pmatrix}1/9 &amp;amp; 0\\ 0 &amp;amp; 1/4\end{pmatrix}\), nên:
\(\mathcal{E} = \left\{(x_1, x_2) : \frac{(x_1 - 1)^2}{9} + \frac{x_2^2}{4} \le 1\right\}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đọc kích thước hình học từ giá trị riêng của \(P\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bán trục theo phương \(x_1\) dài \(\sqrt{9} = 3\) (trải từ \(x_1 = -2\) đến \(x_1 = 4\)).&lt;/li&gt;
      &lt;li&gt;Bán trục theo phương \(x_2\) dài \(\sqrt{4} = 2\) (trải từ \(x_2 = -2\) đến \(x_2 = 2\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra hai điểm cụ thể:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Điểm \(p = (3, 1)^T\): \(\frac{(3 - 1)^2}{9} + \frac{1^2}{4} = \frac{4}{9} + \frac{1}{4} = \frac{25}{36} \approx 0.694 &amp;lt; 1 \implies\) nằm &lt;strong&gt;chặt bên trong&lt;/strong&gt; \(\mathcal{E}\).&lt;/li&gt;
      &lt;li&gt;Điểm \(q = (4, 1)^T\): \(\frac{(4 - 1)^2}{9} + \frac{1^2}{4} = 1 + 0.25 = 1.25 &amp;gt; 1 \implies\) nằm &lt;strong&gt;ngoài&lt;/strong&gt; \(\mathcal{E}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Tập lồi xuất hiện dưới nhiều dạng khác nhau, từ các tập đơn giản như điểm và đường thẳng cho đến siêu phẳng, nửa không gian, hình cầu, ellipsoid, đa diện và hình nón.&lt;/p&gt;

&lt;h2 id=&quot;siêu-phẳng&quot;&gt;Siêu phẳng&lt;/h2&gt;

&lt;p&gt;Siêu phẳng là tập con affine \((n-1)\) chiều chia không gian \(n\) chiều thành hai phần, trong đó \(a\) là vector pháp tuyến và \(b\) xác định vị trí của siêu phẳng so với gốc tọa độ. Siêu phẳng vừa là tập lồi vừa là tập affine.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;{\(x : a^T x = b\)} với \(a \in \mathbb{R}^n, a \ne 0, b \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Trong hình dưới đây, với điểm \(x_0\) nằm trên siêu phẳng, mọi điểm \(x\) thuộc siêu phẳng đều thỏa mãn \((x - x_0)\) vuông góc với \(a\). Do đó \(a^T (x - x_0) = 0\), tức là \(a^T x = b\) với \(b = a^T x_0\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.05_Hyperplane.png&quot; alt=&quot;[Hình1] Siêu phẳng [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình1] Siêu phẳng [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;nửa-không-gian&quot;&gt;Nửa không gian&lt;/h2&gt;

&lt;p&gt;Nửa không gian là mỗi phần không gian nằm về một phía của siêu phẳng. Một siêu phẳng \(a^T x = b\) chia không gian thành hai nửa không gian. Nửa không gian là tập lồi nhưng không phải tập affine.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;{\(x : a^T x \le b\)} hoặc {\(x : a^T x \ge b\)}  với \(a \in \mathbb{R}^n, a \ne 0, b \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Với siêu phẳng \(a^T x = b\), nửa không gian \(a^T x \ge b\) nằm về phía vector pháp tuyến \(a\), còn nửa không gian \(a^T x \le b\) nằm về phía \(-a\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_Halfspace.png&quot; alt=&quot;[Hình2] Nửa không gian [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình2] Nửa không gian [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;em&gt;Lưu ý:&lt;/em&gt; Phần trong của \(\{x : a^T x \le b\}\), tức tập \(\{x : a^T x \lt b\}\), được gọi là nửa không gian mở.&lt;/p&gt;

&lt;h3 id=&quot;tính-chất-quan-trọng-nửa-không-gian-là-tập-lồi&quot;&gt;Tính chất quan trọng: Nửa không gian là tập lồi&lt;/h3&gt;

&lt;p&gt;Xét hai điểm bất kỳ $x_1$ và $x_2$ thuộc nửa không gian:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Cả hai điểm đều thỏa mãn $a^T x_1 \leq b$ và $a^T x_2 \leq b$.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Xét tổ hợp lồi bất kỳ $x_\theta = \theta x_1 + (1 - \theta)x_2$ với $\theta \in [0, 1]$. Ta kiểm tra điều kiện thuộc nửa không gian:
\(a^T x_\theta = a^T(\theta x_1 + (1 - \theta)x_2) = \theta(a^T x_1) + (1 - \theta)(a^T x_2) \leq \theta b + (1 - \theta)b = b\)&lt;/p&gt;

&lt;p&gt;Vì $x_\theta$ thỏa mãn bất đẳng thức nên mọi điểm trên đoạn thẳng nối $x_1$ và $x_2$ đều nằm trong nửa không gian; suy ra nửa không gian là tập lồi.&lt;/p&gt;

&lt;h2 id=&quot;hình-cầu-euclidean&quot;&gt;Hình cầu Euclidean&lt;/h2&gt;

&lt;p&gt;Hình cầu Euclidean tâm \(x_c\), bán kính \(r \ge 0\) là tập hợp tất cả các điểm cách \(x_c\) một khoảng không vượt quá \(r\) theo chuẩn Euclidean \(\|u\|_2 = (u^T u)^{1/2}\):&lt;/p&gt;

&lt;blockquote&gt;
\[B(x_c, r) = \{ x \mid \|x - x_c \|_2 \le r \} = \{ x \mid (x - x_c)^T (x - x_c) \le r^2 \} \text{ với } r \ge 0\]
&lt;/blockquote&gt;

&lt;p&gt;Hình cầu Euclidean cũng có thể được biểu diễn tương đương dưới dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[B(x_c, r) = \{ x_c + ru \mid \| u \|_2 \le 1 \}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;ellipsoid&quot;&gt;Ellipsoid&lt;/h2&gt;

&lt;p&gt;Ellipsoid là tập lồi tổng quát hóa hình cầu Euclidean, được định nghĩa như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\mathcal{E} = \{x \mid (x - x_c)^T P^{-1} (x - x_c) \le 1 \}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong đó \(P = P^T \succ 0\) là ma trận đối xứng xác định dương. Vector \(x_c\) là tâm của ellipsoid, còn ma trận \(P\) quyết định độ dài các bán trục theo từng phương xuất phát từ tâm: độ dài các bán trục bằng \(\sqrt{\lambda_i}\), với \(\lambda_i\) là các giá trị riêng của \(P\). Khi \(P = r^2 I\), ellipsoid trở thành hình cầu Euclidean bán kính \(r\).&lt;/p&gt;

&lt;p&gt;Hình dưới đây minh họa một ellipsoid với tâm \(x_c\) và các trục chính, trục phụ.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.07_Ellipsoid.png&quot; alt=&quot;[Hình3] Ellipsoid [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình3] Ellipsoid [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Ellipsoid cũng có thể được viết dưới dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\mathcal{E} = \{ x_c + Au \mid \|u\|_2 \le 1 \}\]
&lt;/blockquote&gt;

&lt;p&gt;với \(A\) là ma trận vuông không suy biến. Khi chọn \(A = P^{1/2}\) (đối xứng xác định dương), hai cách biểu diễn trùng nhau. Nếu \(A\) đối xứng nửa xác định dương nhưng suy biến, tập thu được gọi là ellipsoid suy biến, có chiều affine bằng hạng của \(A\) và vẫn là tập lồi.&lt;/p&gt;

&lt;h2 id=&quot;hình-cầu-chuẩn&quot;&gt;Hình cầu chuẩn&lt;/h2&gt;

&lt;p&gt;Hình cầu chuẩn là tập hợp các điểm cách tâm \(x_c\) không quá \(r\) theo một chuẩn bất kỳ \(\|\cdot\|\) trên \(\mathbb{R}^n\) (thay vì chỉ dùng chuẩn Euclidean):&lt;/p&gt;

&lt;blockquote&gt;
\[\{ x \mid \|x - x_c \| \le r  \}\]
&lt;/blockquote&gt;

&lt;p&gt;Với chuẩn \(\ell_p\) được định nghĩa là:&lt;/p&gt;

&lt;blockquote&gt;
\[\| x  \|_{p} = \left( \sum_{i=1}^n |x_i|^{p} \right)^{1/p} \text{ với  } p \ge 1\]
&lt;/blockquote&gt;

&lt;p&gt;hình dạng của hình cầu chuẩn thay đổi tùy theo giá trị của \(p\). Hình cầu chuẩn luôn lồi khi \(p \ge 1\). Hai hình dưới đây lần lượt minh họa hình dạng hình cầu chuẩn trong không gian 3D và 2D ứng với các giá trị \(p\) khác nhau.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.07_2_norm_ball.png&quot; alt=&quot;[Hình4] Hình cầu chuẩn [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình4] Hình cầu chuẩn [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.07_3_norm_ball2.png&quot; alt=&quot;[Hình4] Hình cầu chuẩn [2]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình4] Hình cầu chuẩn [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;đa-diện&quot;&gt;Đa diện&lt;/h2&gt;

&lt;p&gt;Đa diện là tập nghiệm của một hệ hữu hạn các bất đẳng thức và đẳng thức tuyến tính. Các tập affine (không gian con, siêu phẳng, đường thẳng), tia, đoạn thẳng và nửa không gian đều là những trường hợp riêng của đa diện. Đa diện là tập lồi; một đa diện bị chặn được gọi là polytope.&lt;/p&gt;

&lt;blockquote&gt;
\[\mathcal{P} = \{ x \mid a^T_i x \le b_i, i = 1, ..., m, c_j^Tx  = d_j, j = 1, ..., p\}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì mỗi đẳng thức \(c_j^T x = d_j\) tương đương với hai bất đẳng thức \(c_j^T x \le d_j\) và \(c_j^T x \ge d_j\), nên mọi đa diện đều có thể biểu diễn chỉ bằng các bất đẳng thức tuyến tính.&lt;/p&gt;

&lt;p&gt;Hình dưới đây minh họa một đa diện ngũ giác tạo bởi giao của năm nửa không gian, với các vector pháp tuyến hướng ra ngoài \(a_1, ..., a_5\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.09_Polyhedra.png&quot; alt=&quot;[Hình5] Đa diện [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình5] Đa diện [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Dưới dạng ma trận, đa diện được viết gọn như sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\mathcal{P} =  \{ x \mid Ax \preceq b, Cx  = d \}\)
trong đó
\(A = 
\begin{bmatrix}
a^T_1 \\
\vdots \\
a^T_m
\end{bmatrix},\)
\(C = 
\begin{bmatrix}
c^T_1 \\
\vdots \\
c^T_p
\end{bmatrix}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;đơn-hình&quot;&gt;Đơn hình&lt;/h3&gt;

&lt;p&gt;Đơn hình là đa diện đơn giản nhất có phần trong khác rỗng trong không gian \(n\) chiều, được tạo thành từ \(n+1\) điểm.&lt;/p&gt;

&lt;p&gt;Tổng quát, cho \(k + 1\) điểm \(v_0, ..., v_k \in \mathbb{R}^n\) độc lập affine (nghĩa là các vector \(v_1 - v_0, ..., v_k - v_0\) độc lập tuyến tính). Đơn hình tương ứng được định nghĩa là bao lồi của \(k+1\) điểm này:&lt;/p&gt;

&lt;blockquote&gt;
\[C = \mathbb{conv} \{v_0, ... , v_k\} = \{ \theta_0 v_0 + \cdots + \theta_k v_k  \mid \theta \succeq 0, 1^T \theta = 1 \}\]
&lt;/blockquote&gt;

&lt;p&gt;Hình dưới đây minh họa các đơn hình từ 0 đến 3 chiều: điểm (0D), đoạn thẳng (1D), tam giác (2D) và tứ diện (3D).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.02_10_Simplex.png&quot; alt=&quot;[Hình6] Đơn hình [nguồn - wikipedia]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình6] Đơn hình [nguồn - wikipedia]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Một ví dụ phổ biến là đơn hình xác suất:&lt;/p&gt;

&lt;blockquote&gt;
\[C = \mathbb{conv} \{e_1, ..., e_n \} = \{ \theta \mid \theta \succeq 0, 1^T \theta = 1\}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>02 Convex Sets</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_Convex_sets/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_Convex_sets</id>
   <content type="html">&lt;p&gt;Imagine a warehouse robot navigating between two valid storage configurations \(x\) and \(y\): if the feasible region of collision-free states is &lt;em&gt;convex&lt;/em&gt;, then the straight-line blend \(\theta x + (1-\theta)y\) is automatically collision-free at every intermediate step. Chapter 02 develops the complete geometric language of convex sets—from lines and hyperplanes to cones, generalized inequalities, and separating hyperplanes—that underpins every feasibility proof and duality theorem in optimization.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-geometric-roadmap-of-chapter-02&quot;&gt;Key ideas: The Geometric Roadmap of Chapter 02&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Primitive Building Blocks (Affine, Convex, Conic):&lt;/strong&gt; Distinguish unconstrained linear combinations (affine sets), weighted averages (convex sets), and nonnegative scalings (convex cones).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Canonical Feasible Regions:&lt;/strong&gt; Master the core library of convex sets—hyperplanes, halfspaces, Euclidean balls, ellipsoids, polyhedra, simplexes, and the positive semidefinite cone \(\mathbb{S}_+^n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convexity-Preserving Calculus:&lt;/strong&gt; Prove complex feasible sets are convex effortlessly via intersections, affine images/preimages, and perspective maps rather than brute-force algebraic checks.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Separation &amp;amp; Duality Geometry:&lt;/strong&gt; Separating and supporting hyperplanes and dual cones \(K^*\) turn geometric disjointness into linear optimality certificates (the root of Lagrange duality).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solid-disk-vs-hollow-circle&quot;&gt;Worked example: Solid Disk vs. Hollow Circle&lt;/h3&gt;

&lt;p&gt;Compare the unit disk \(D = \{x \in \mathbb{R}^2 : \|x\|_2 \le 1\}\) and the unit circle \(S = \{x \in \mathbb{R}^2 : \|x\|_2 = 1\}\) using endpoints \(x = (1, 0)^T\) and \(y = (0, 1)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the midpoint (\(\theta = 0.5\)):&lt;/strong&gt;
\(m = 0.5 x + 0.5 y = (0.5, 0.5)^T.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute its Euclidean norm:&lt;/strong&gt;
\(\|m\|_2 = \sqrt{0.5^2 + 0.5^2} = \sqrt{0.5} \approx 0.7071.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclude convexity:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(D\), \(\|m\|_2 \approx 0.7071 \le 1\) (in fact, by the triangle inequality, \(\|\theta x + (1-\theta)y\|_2 \le \theta\|x\|_2 + (1-\theta)\|y\|_2 \le 1\) for all \(x, y \in D\)), proving \(D\) is &lt;strong&gt;convex&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;For \(S\), \(\|m\|_2 \neq 1 \implies m \notin S\), proving the hollow circle \(S\) is &lt;strong&gt;nonconvex&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we will study the concept of convex sets, which form the foundation of convex optimization.&lt;/p&gt;

&lt;h3 id=&quot;background&quot;&gt;Background&lt;/h3&gt;
&lt;p&gt;Convex optimization refers to techniques for finding maxima or minima by defining problems using convex functions.
Convex sets are closely related to convex functions in two main ways:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Convex functions are defined over convex sets. The domain and range of a function are defined as convex sets, and the main properties of convex functions are determined by these sets.&lt;/li&gt;
  &lt;li&gt;If you can transform an optimization problem into one involving a convex function, it becomes easier to solve. Sometimes, it is difficult to determine whether a problem is defined by a convex function. In such cases, you can check whether the epigraph of the function is a convex set to determine if the function is convex.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;content&quot;&gt;Content&lt;/h3&gt;
&lt;p&gt;In this chapter, we will cover the definition and examples of convex sets, their main properties, and operations that preserve convexity.&lt;/p&gt;

&lt;p&gt;See also the optional &lt;a href=&quot;/contents/en/chapter02/02_07_Applications_Recent/&quot;&gt;02-07 Applications and recent developments&lt;/a&gt; on simplices, Wasserstein balls, and fairness polytopes.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-09 Practical Exercises - Convex Sets</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_09_Practical_Exercises_Convex_Sets/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_09_Practical_Exercises_Convex_Sets</id>
   <content type="html">&lt;p&gt;Knowing that a set is convex is the first step; &lt;em&gt;projecting&lt;/em&gt; an infeasible iterate back onto that convex set is the computational core of projected gradient descent and ADMM. These practical exercises move you from proofs to computation—testing convexity, finding separating hyperplanes, computing convex hulls and dual cones, and projecting points onto polyhedra, balls, and simplexes.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-computational-skills-in-these-exercises&quot;&gt;Key ideas: Computational Skills in These Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algebraic &amp;amp; Computational Verification:&lt;/strong&gt; Checking convexity by rewriting sets as intersections, affine preimages, or epigraphs, and validating numerically.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Cones &amp;amp; Separation Oracles:&lt;/strong&gt; Computing explicit separating hyperplanes and dual cones for polyhedral and norm-cone constraints.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Euclidean Projections (\(\Pi_C(y) = \arg\min_{x \in C} \frac{1}{2}\|x - y\|_2^2\)):&lt;/strong&gt; Deriving closed-form projections onto hyperplanes, boxes, \(\ell_2\) balls, \(\mathbb{R}_+^n\), and the probability simplex \(\Delta_n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Extreme Points &amp;amp; Vertices:&lt;/strong&gt; Identifying extreme points of polytopes—where linear objectives always attain their optima.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-projecting-onto-mathbbr_3-and-the-probability-simplex-delta_3&quot;&gt;Worked example: Projecting onto \(\mathbb{R}_+^3\) and the Probability Simplex \(\Delta_3\)&lt;/h3&gt;

&lt;p&gt;Project the vector \(y = (3, -2, 1)^T\) onto two fundamental convex sets:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Projection onto the nonnegative orthant \(\mathbb{R}_+^3\):&lt;/strong&gt; Componentwise clipping \(x_i^* = \max(y_i, 0)\) immediately gives
\(\Pi_{\mathbb{R}_+^3}(y) = (3, 0, 1)^T.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Projection onto the probability simplex \(\Delta_3 = \{x \ge 0 : x_1 + x_2 + x_3 = 1\}\):&lt;/strong&gt; By KKT conditions, \(\Pi_{\Delta_3}(y)_i = \max(y_i - \nu, 0)\) where the threshold \(\nu \in \mathbb{R}\) is chosen so the entries sum to \(1\).
    &lt;ul&gt;
      &lt;li&gt;Try \(\nu = 2\):
\(\max(3 - 2, 0) = 1, \qquad \max(-2 - 2, 0) = 0, \qquad \max(1 - 2, 0) = 0.\)&lt;/li&gt;
      &lt;li&gt;Sum \(= 1 + 0 + 0 = 1\)! Thus \(x^* = \Pi_{\Delta_3}(y) = (1, 0, 0)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the variational optimality condition \((y - x^*)^T(x - x^*) \le 0 \;\forall x \in \Delta_3\):&lt;/strong&gt;
With \(y - x^* = (2, -2, 1)^T\) and \(x_1 - 1 = -(x_2 + x_3)\) for any \(x \in \Delta_3\),
\((y - x^*)^T(x - x^*) = 2(-x_2 - x_3) - 2x_2 + x_3 = -4x_2 - x_3 \le 0,\)
certifying \(x^* = (1, 0, 0)^T\) as the exact Euclidean projection.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---convex-sets&quot;&gt;Practical Exercises - Convex Sets&lt;/h1&gt;

&lt;h2 id=&quot;exercise-1-verification-of-convex-sets&quot;&gt;&lt;strong&gt;Exercise 1: Verification of convex sets&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 2.1 from Boyd &amp;amp; Vandenberghe)
Determine whether the following sets are convex:&lt;/p&gt;

&lt;p&gt;a) \(S_1 = \{x \in \mathbb{R}^n : \lVert x \rVert_2 \leq 1\}\)&lt;/p&gt;

&lt;p&gt;b) \(S_2 = \{x \in \mathbb{R}^n : \lVert x \rVert_\infty \leq 1\}\)&lt;/p&gt;

&lt;p&gt;c) \(S_3 = \{x \in \mathbb{R}^n : x^T P x \leq 1\}\) with \(P \succeq 0\)&lt;/p&gt;

&lt;p&gt;d) \(S_4 = \{x \in \mathbb{R}^n : \lVert x_i \rVert  \leq a_i, i = 1,\ldots,n\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Prove convexity from the definition&lt;/li&gt;
  &lt;li&gt;Verify using operations that preserve convexity&lt;/li&gt;
  &lt;li&gt;Visualize in \(\mathbb{R}^2\)&lt;/li&gt;
  &lt;li&gt;Find the extreme points of each set&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Proof from the definition&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;a) \(\ell_2\) ball:&lt;/strong&gt; \(S_1 = \{x : \lVert x \rVert_2 \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;For \(x, y \in S_1\) and \(\theta \in [0,1]\):
\(\lVert \theta x + (1-\theta) y \rVert_2 \leq \theta \lVert x \rVert_2 + (1-\theta) \lVert y \rVert_2 \leq \theta \cdot 1 + (1-\theta) \cdot 1 = 1\)&lt;/p&gt;

  &lt;p&gt;\(\Rightarrow\) Convex&lt;/p&gt;

  &lt;table&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;strong&gt;b) \(\ell_\infty\) ball:&lt;/strong&gt; $$S_2 = {x : \max_i&lt;/td&gt;
        &lt;td&gt;x_i&lt;/td&gt;
        &lt;td&gt;\leq 1}$$&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

\[\max_i |\theta x_i + (1-\theta) y_i| \leq \max_i (\theta |x_i| + (1-\theta) |y_i|) \leq \theta \max_i |x_i| + (1-\theta) \max_i |y_i| \leq 1\]

  &lt;p&gt;\(\Rightarrow\) Convex&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;c) Ellipsoid:&lt;/strong&gt; \(S_3 = \{x : x^T P x \leq 1\}\) with \(P \succeq 0\)&lt;/p&gt;

\[(\theta x + (1-\theta) y)^T P (\theta x + (1-\theta) y) = \theta^2 x^T P x + 2\theta(1-\theta) x^T P y + (1-\theta)^2 y^T P y\]

  &lt;p&gt;Since \(P \succeq 0\), the quadratic form is a convex function, so its sublevel set is convex.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;d) Hyperrectangle:&lt;/strong&gt; \(S_4 = \prod_{i=1}^n [-a_i, a_i]\)&lt;/p&gt;

  &lt;p&gt;A Cartesian product of convex sets (intervals) is convex.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: Operations that preserve convexity&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;a, b:&lt;/strong&gt; Sublevel sets of convex functions (norms)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;c:&lt;/strong&gt; Sublevel set of a convex quadratic form&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;d:&lt;/strong&gt; Cartesian product of convex intervals&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: Extreme points&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;a:&lt;/strong&gt; The boundary \(\{x : \lVert x \rVert_2 = 1\}\) (infinitely many extreme points)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;b:&lt;/strong&gt; The vertices \(\{(\pm 1, \ldots, \pm 1)\}\) (\(2^n\) extreme points; the points \(\pm e_i\) are the vertices of the \(\ell_1\) ball, not of the \(\ell_\infty\) ball)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;c:&lt;/strong&gt; Depends on \(P\): if \(P \succ 0\), every point on the boundary \(x^T P x = 1\) is an extreme point; if \(P\) is singular, the set contains an entire line and has no extreme points&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;d:&lt;/strong&gt; The vertices \(\{(\pm a_1, \ldots, \pm a_n)\}\) (\(2^n\) extreme points)&lt;/li&gt;
  &lt;/ul&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-2-operations-preserving-convexity&quot;&gt;&lt;strong&gt;Exercise 2: Operations preserving convexity&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 2.2 from Boyd &amp;amp; Vandenberghe)
Let \(C_1, C_2 \subseteq \mathbb{R}^n\) be convex sets. Prove or disprove convexity of:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Intersection:&lt;/strong&gt; \(C_1 \cap C_2\)&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Union:&lt;/strong&gt; \(C_1 \cup C_2\)&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Minkowski sum:&lt;/strong&gt; \(C_1 + C_2 = \{x + y : x \in C_1, y \in C_2\}\)&lt;/p&gt;

&lt;p&gt;d) &lt;strong&gt;Cartesian product:&lt;/strong&gt; \(C_1 \times C_2\)&lt;/p&gt;

&lt;p&gt;e) &lt;strong&gt;Affine transformation:&lt;/strong&gt; \(f(C_1) = \{Ax + b : x \in C_1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Give mathematical proofs for the true cases&lt;/li&gt;
  &lt;li&gt;Give counterexamples for the false cases&lt;/li&gt;
  &lt;li&gt;Visualize with concrete examples&lt;/li&gt;
  &lt;li&gt;Generalize to arbitrary collections&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Intersection - CONVEX&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt; For \(x, y \in C_1 \cap C_2\) and \(\theta \in [0,1]\):&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x, y \in C_1 \Rightarrow \theta x + (1-\theta) y \in C_1\) (since \(C_1\) is convex)&lt;/li&gt;
      &lt;li&gt;\(x, y \in C_2 \Rightarrow \theta x + (1-\theta) y \in C_2\) (since \(C_2\) is convex)&lt;/li&gt;
      &lt;li&gt;
\[\Rightarrow \theta x + (1-\theta) y \in C_1 \cap C_2\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Generalization:&lt;/strong&gt; \(\bigcap_{i \in I} C_i\) is convex if every \(C_i\) is convex.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: Union - NOT CONVEX&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Counterexample:&lt;/strong&gt; \(C_1 = \{(x,0) : x \geq 0\}\), \(C_2 = \{(0,y) : y \geq 0\}\)&lt;/p&gt;

  &lt;p&gt;Both are convex, but \(C_1 \cup C_2\) is not:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\((1,0) \in C_1 \cup C_2\), \((0,1) \in C_1 \cup C_2\)&lt;/li&gt;
    &lt;li&gt;
\[\frac{1}{2}(1,0) + \frac{1}{2}(0,1) = (\frac{1}{2}, \frac{1}{2}) \notin C_1 \cup C_2\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: Minkowski sum - CONVEX&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt; For \(z_1, z_2 \in C_1 + C_2\):&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;\(z_1 = x_1 + y_1\), \(z_2 = x_2 + y_2\) with \(x_i \in C_1, y_i \in C_2\)&lt;/li&gt;
      &lt;li&gt;
\[\theta z_1 + (1-\theta) z_2 = \theta(x_1 + y_1) + (1-\theta)(x_2 + y_2)\]
      &lt;/li&gt;
      &lt;li&gt;
\[= (\theta x_1 + (1-\theta) x_2) + (\theta y_1 + (1-\theta) y_2)\]
      &lt;/li&gt;
      &lt;li&gt;\(\in C_1 + C_2\) (since \(C_1, C_2\) are convex)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Step 4: Cartesian product - CONVEX&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt; \((x_1, y_1), (x_2, y_2) \in C_1 \times C_2\):
\(\theta(x_1, y_1) + (1-\theta)(x_2, y_2) = (\theta x_1 + (1-\theta) x_2, \theta y_1 + (1-\theta) y_2) \in C_1 \times C_2\)&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Step 5: Affine transformation - CONVEX&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt; For \(z_1, z_2 \in f(C_1)\):&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;\(z_i = Ax_i + b\) with \(x_i \in C_1\)&lt;/li&gt;
      &lt;li&gt;
\[\theta z_1 + (1-\theta) z_2 = A(\theta x_1 + (1-\theta) x_2) + b \in f(C_1)\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-3-separating-hyperplanes&quot;&gt;&lt;strong&gt;Exercise 3: Separating hyperplanes&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 2.3 from Boyd &amp;amp; Vandenberghe)
Let \(C, D \subset \mathbb{R}^n\) be disjoint convex sets (\(C \cap D = \emptyset\)).&lt;/p&gt;

&lt;p&gt;a) Prove that a separating hyperplane exists
b) Find a separating hyperplane for:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(C = \{x : \lVert x \rVert_2 \leq 1\}\), \(D = \{x : \lVert x - (3,0) \rVert_2 \leq 1\}\)&lt;/li&gt;
  &lt;li&gt;\(C = \{x : x_1 + x_2 \leq 1, x_1, x_2 \geq 0\}\), \(D = \{(2,2)\}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;A constructive proof of the separating hyperplane theorem&lt;/li&gt;
  &lt;li&gt;Explicit computations for the examples&lt;/li&gt;
  &lt;li&gt;Visualize separation&lt;/li&gt;
  &lt;li&gt;Analyze the case where the sets touch at the boundary&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Separating hyperplane theorem&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-theorem&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Theorem:&lt;/strong&gt; If \(C, D\) are disjoint convex sets, there exist \(a \neq 0\) and \(b\) such that:
\(a^T x \leq b \leq a^T y, \quad \forall x \in C, y \in D\)&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Constructive proof:&lt;/strong&gt;&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;Consider \(S = C - D = \{x - y : x \in C, y \in D\}\) (convex)&lt;/li&gt;
    &lt;li&gt;\(0 \notin S\) (since \(C \cap D = \emptyset\))&lt;/li&gt;
    &lt;li&gt;Find the point \(s^* \in S\) closest to the origin: \(s^* = \arg\min_{s \in S} \lVert s \rVert_2\)&lt;/li&gt;
    &lt;li&gt;Write \(s^* = x^* - y^*\) (\(x^* \in C\), \(y^* \in D\); assume \(C, D\) are closed and one of them is bounded so that \(s^*\) exists). Set \(a = y^* - x^* = -s^*\), \(b = \frac{1}{2}(\lVert y^* \rVert_2^2 - \lVert x^* \rVert_2^2)\) (the perpendicular bisector of the segment \(x^* y^*\)). The optimality condition for \(s^*\) gives \(s^{*T}(s - s^*) \geq 0\) for all \(s \in S\), from which \(a^T x \leq b \leq a^T y\).&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: Example 1 - Two balls&lt;/strong&gt;
\(C = \{x : \lVert x \rVert_2 \leq 1\}\), \(D = \{x : \lVert x - (3,0) \rVert_2 \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Geometric approach:&lt;/strong&gt; Centers at \((0,0)\) and \((3,0)\), radii = 1.
The separating line is perpendicular to the line connecting the centers.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; \(a = (1,0)\), \(b = 1.5\)
Hyperplane: \(x_1 = 1.5\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Verification:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[\max_{x \in C} x_1 = 1 &amp;lt; 1.5\]
    &lt;/li&gt;
    &lt;li&gt;
\[\min_{x \in D} x_1 = 2 &amp;gt; 1.5\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: Example 2 - Simplex and a point&lt;/strong&gt;
\(C = \{x : x_1 + x_2 \leq 1, x_1, x_2 \geq 0\}\), \(D = \{(2,2)\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Approach:&lt;/strong&gt; Find the point in \(C\) closest to \((2,2)\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Optimization problem:&lt;/strong&gt;
\(\min_{x \in C} \lVert x - (2,2) \rVert_2^2\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;KKT conditions:&lt;/strong&gt; The closest point is \((1/2, 1/2)\) (the projection of \((2,2)\) onto the edge \(x_1 + x_2 = 1\)), at distance \(\frac{3}{\sqrt{2}}\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; \(a = (1,1)\) (in the direction of \((2,2) - (1/2,1/2)\)), \(b = 1.5\). Any \(b \in (1, 4)\) separates; the perpendicular bisector is \(x_1 + x_2 = 2.5\).
Hyperplane: \(x_1 + x_2 = 1.5\)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-4-convex-hull-computations&quot;&gt;&lt;strong&gt;Exercise 4: Convex hull computations&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 2.4 from Boyd &amp;amp; Vandenberghe)
Compute the convex hulls of the following sets:&lt;/p&gt;

&lt;p&gt;a) \(S_1 = \{(0,0), (1,0), (0,1), (1,1)\}\) in \(\mathbb{R}^2\)&lt;/p&gt;

&lt;p&gt;b) \(S_2 = \{x \in \mathbb{R}^3 : \lVert x \rVert_2 = 1, x_3 = 0\} \cup \{(0,0,1), (0,0,-1)\}\)&lt;/p&gt;

&lt;p&gt;c) \(S_3 = \{(t, t^2) : t \in [-1,1]\}\) in \(\mathbb{R}^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Compute the convex hull explicitly&lt;/li&gt;
  &lt;li&gt;Identify extreme points&lt;/li&gt;
  &lt;li&gt;Describe it by inequalities when possible&lt;/li&gt;
  &lt;li&gt;Visualize results&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Finite point set&lt;/strong&gt;
\(S_1 = \{(0,0), (1,0), (0,1), (1,1)\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Convex hull:&lt;/strong&gt; Unit square \([0,1] \times [0,1]\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Extreme points:&lt;/strong&gt; All 4 points are extreme points.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Inequality description:&lt;/strong&gt;
\(\text{conv}(S_1) = \{x : 0 \leq x_1 \leq 1, 0 \leq x_2 \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: Circle plus two points&lt;/strong&gt;
\(S_2 = \{x \in \mathbb{R}^3 : x_1^2 + x_2^2 = 1, x_3 = 0\} \cup \{(0,0,1), (0,0,-1)\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Convex hull:&lt;/strong&gt; Double cone
\(\text{conv}(S_2) = \{x \in \mathbb{R}^3 : x_1^2 + x_2^2 \leq (1 - |x_3|)^2, |x_3| \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Extreme points:&lt;/strong&gt; Circle \(\{x : x_1^2 + x_2^2 = 1, x_3 = 0\}\) and the two apexes \((0,0,\pm 1)\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: Parabola segment&lt;/strong&gt;
\(S_3 = \{(t, t^2) : t \in [-1,1]\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Convex hull:&lt;/strong&gt; Region above the parabola and below the chord \(x_2 = 1\)
\(\text{conv}(S_3) = \{(x_1, x_2) : x_1^2 \leq x_2 \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Extreme points:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Every point \((t, t^2)\), \(t \in [-1,1]\), of the parabolic arc (including the two endpoints \((\pm 1, 1)\))&lt;/li&gt;
    &lt;li&gt;Interior points of the segment \(x_2 = 1\) are not extreme points&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Alternative description:&lt;/strong&gt;
\(\text{conv}(S_3) = \{(x_1, x_2) : x_2 \geq x_1^2,\ x_2 \leq 1\}\) (the condition \(|x_1| \leq 1\) follows automatically)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-5-dual-cones&quot;&gt;&lt;strong&gt;Exercise 5: Dual cones&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 2.5 from Boyd &amp;amp; Vandenberghe)
Find the dual cones of the following cones:&lt;/p&gt;

&lt;p&gt;a) \(K_1 = \mathbb{R}_+^n = \{x \in \mathbb{R}^n : x_i \geq 0, \forall i\}\)&lt;/p&gt;

&lt;p&gt;b) \(K_2 = \{x \in \mathbb{R}^n : \lVert (x_1, \ldots, x_{n-1}) \rVert_2 \leq x_n\}\) (second-order cone)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;c) $$K_3 = {x \in \mathbb{R}^n : \sum_{i=1}^{n-1}&lt;/td&gt;
      &lt;td&gt;x_i&lt;/td&gt;
      &lt;td&gt;\leq x_n}\((\)\ell_1$$ cone)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;d) \(K_4 = \{X \in \mathbb{S}^n : X \succeq 0\}\) (positive semidefinite cone)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Compute the dual cone \(K^* = \{y : y^T x \geq 0, \forall x \in K\}\)&lt;/li&gt;
  &lt;li&gt;Verify self-duality where applicable&lt;/li&gt;
  &lt;li&gt;Establish duality relationships&lt;/li&gt;
  &lt;li&gt;Geometric interpretation&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Non-negative orthant&lt;/strong&gt;
\(K_1^* = \{y : y^T x \geq 0, \forall x \in \mathbb{R}_+^n\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Analysis:&lt;/strong&gt; \(y^T x = \sum_{i=1}^n y_i x_i \geq 0\) for all \(x_i \geq 0\)&lt;/p&gt;

\[\Rightarrow y_i \geq 0, \forall i\]

  &lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; \(K_1^* = \mathbb{R}_+^n = K_1\) (self-dual)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: Second-order cone&lt;/strong&gt;
\(K_2 = \{x : \lVert (x_1, \ldots, x_{n-1}) \rVert_2 \leq x_n\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt; \(K_2^* = \{y : y^T x \geq 0, \forall x \in K_2\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; \(K_2^* = K_2\) (self-dual)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Proof sketch:&lt;/strong&gt; Use the Cauchy-Schwarz inequality and homogeneity.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: \(\ell_1\) cone&lt;/strong&gt;
\(K_3 = \{x : \sum_{i=1}^{n-1} |x_i| \leq x_n\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt; \(K_3^* = \{y : \lVert (y_1, \ldots, y_{n-1}) \rVert_\infty \leq y_n\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Verification:&lt;/strong&gt; Use the duality between the \(\ell_1\) and \(\ell_\infty\) norms.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 4: PSD cone&lt;/strong&gt;
\(K_4 = \{X \in \mathbb{S}^n : X \succeq 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt; \(K_4^* = \{Y \in \mathbb{S}^n : \text{tr}(YX) \geq 0, \forall X \succeq 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; \(K_4^* = K_4\) (self-dual)&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt; \(Y \succeq 0 \Leftrightarrow \text{tr}(YX) \geq 0, \forall X \succeq 0\)&lt;/p&gt;
  &lt;/div&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-6-projection-onto-convex-sets&quot;&gt;&lt;strong&gt;Exercise 6: Projection onto convex sets&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 2.6 from Boyd &amp;amp; Vandenberghe)
Compute the projection of a point \(x_0\) onto a convex set \(C\):&lt;/p&gt;

\[\text{proj}_C(x_0) = \arg\min_{x \in C} \lVert x - x_0 \rVert_2\]

&lt;p&gt;a) \(C = \{x : a^T x = b\}\) (hyperplane)&lt;/p&gt;

&lt;p&gt;b) \(C = \{x : a^T x \leq b\}\) (halfspace)&lt;/p&gt;

&lt;p&gt;c) \(C = \{x : \lVert x \rVert_2 \leq r\}\) (\(\ell_2\) ball)&lt;/p&gt;

&lt;p&gt;d) \(C = \{x : \lVert x \rVert_\infty \leq r\}\) (\(\ell_\infty\) ball)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Derive closed-form solutions&lt;/li&gt;
  &lt;li&gt;Verify optimality conditions&lt;/li&gt;
  &lt;li&gt;Analyze uniqueness&lt;/li&gt;
  &lt;li&gt;Implement algorithms&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Projection onto a hyperplane&lt;/strong&gt;
\(C = \{x : a^T x = b\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt; \(L(x,\lambda) = \frac{1}{2}\lVert x - x_0 \rVert_2^2 + \lambda(a^T x - b)\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Optimality:&lt;/strong&gt; \(x - x_0 + \lambda a = 0 \Rightarrow x = x_0 - \lambda a\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Constraint:&lt;/strong&gt; \(a^T(x_0 - \lambda a) = b \Rightarrow \lambda = \frac{a^T x_0 - b}{\lVert a \rVert_2^2}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; \(\text{proj}_C(x_0) = x_0 - \frac{a^T x_0 - b}{\lVert a \rVert_2^2} a\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: Projection onto a halfspace&lt;/strong&gt;
\(C = \{x : a^T x \leq b\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Case analysis:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;If \(a^T x_0 \leq b\): \(\text{proj}_C(x_0) = x_0\)&lt;/li&gt;
    &lt;li&gt;If \(a^T x_0 &amp;gt; b\): project onto boundary hyperplane&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; 
\(\text{proj}_C(x_0) = \begin{cases} 
x_0 &amp;amp; \text{if } a^T x_0 \leq b \\
x_0 - \frac{a^T x_0 - b}{\lVert a \rVert_2^2} a &amp;amp; \text{if } a^T x_0 &amp;gt; b
\end{cases}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: Projection onto the \(\ell_2\) ball&lt;/strong&gt;
\(C = \{x : \lVert x \rVert_2 \leq r\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Case analysis:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;If \(\lVert x_0 \rVert_2 \leq r\): \(\text{proj}_C(x_0) = x_0\)&lt;/li&gt;
    &lt;li&gt;If \(\lVert x_0 \rVert_2 &amp;gt; r\): project radially&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;
\(\text{proj}_C(x_0) = \begin{cases}
x_0 &amp;amp; \text{if } \lVert x_0 \rVert_2 \leq r \\
r \frac{x_0}{\lVert x_0 \rVert_2} &amp;amp; \text{if } \lVert x_0 \rVert_2 &amp;gt; r
\end{cases}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 4: Projection onto the \(\ell_\infty\) ball&lt;/strong&gt;
\(C = \{x : \lVert x \rVert_\infty \leq r\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Component-wise projection:&lt;/strong&gt;
\([\text{proj}_C(x_0)]_i = \begin{cases}
x_{0i} &amp;amp; \text{if } |x_{0i}| \leq r \\
r \cdot \text{sign}(x_{0i}) &amp;amp; \text{if } |x_{0i}| &amp;gt; r
\end{cases}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Equivalently:&lt;/strong&gt; \(\text{proj}_C(x_0) = \text{clip}(x_0, -r, r)\)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-7-extreme-points-and-vertices&quot;&gt;&lt;strong&gt;Exercise 7: Extreme points and vertices&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 2.7 from Boyd &amp;amp; Vandenberghe)
Let \(P = \{x : Ax \leq b\}\) be a polytope in \(\mathbb{R}^n\).&lt;/p&gt;

&lt;p&gt;a) Prove that \(x\) is an extreme point if and only if \(n\) linearly independent constraints are active at \(x\)&lt;/p&gt;

&lt;p&gt;b) Find all extreme points of:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[P_1 = \{x \in \mathbb{R}^2 : x_1 + x_2 \leq 1, x_1 \geq 0, x_2 \geq 0\}\]
  &lt;/li&gt;
  &lt;li&gt;
\[P_2 = \{x \in \mathbb{R}^3 : x_1 + x_2 + x_3 \leq 1, x_i \geq 0\}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c) Verify Krein-Milman theorem: \(P = \text{conv}(\text{extreme points})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;A rigorous proof of the characterization&lt;/li&gt;
  &lt;li&gt;Systematic enumeration of the vertices&lt;/li&gt;
  &lt;li&gt;Geometric visualization&lt;/li&gt;
  &lt;li&gt;Computational algorithms&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Characterization theorem&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-theorem&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Theorem:&lt;/strong&gt; \(x \in P\) is an extreme point \(\Leftrightarrow\) \(n\) linearly independent constraints are active at \(x\).&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Proof (\(\Leftarrow\)):&lt;/strong&gt; Suppose \(n\) constraints are active: \(A_I x = b_I\) with \(A_I\) of full rank.&lt;/p&gt;

  &lt;p&gt;If \(x = \theta y + (1-\theta) z\) with \(y, z \in P\), \(\theta \in (0,1)\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(A_I y \leq b_I\) and \(A_I z \leq b_I\)&lt;/li&gt;
    &lt;li&gt;
\[b_I = A_I x = \theta A_I y + (1-\theta) A_I z \leq b_I\]
    &lt;/li&gt;
    &lt;li&gt;
\[\Rightarrow A_I y = A_I z = b_I\]
    &lt;/li&gt;
    &lt;li&gt;Since \(A_I\) has full rank: \(y = z = x\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Proof (\(\Rightarrow\)):&lt;/strong&gt; Contrapositive - if fewer than \(n\) independent constraints are active, the point is not extreme.&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: Example 1 - 2D simplex&lt;/strong&gt;
\(P_1 = \{x : x_1 + x_2 \leq 1, x_1 \geq 0, x_2 \geq 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Active constraint combinations:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\{x_1 = 0, x_2 = 0\}\): vertex \((0,0)\)&lt;/li&gt;
    &lt;li&gt;\(\{x_1 = 0, x_1 + x_2 = 1\}\): vertex \((0,1)\)&lt;/li&gt;
    &lt;li&gt;\(\{x_2 = 0, x_1 + x_2 = 1\}\): vertex \((1,0)\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Extreme points:&lt;/strong&gt; \(\{(0,0), (0,1), (1,0)\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: Example 2 - 3D simplex&lt;/strong&gt;
\(P_2 = \{x : x_1 + x_2 + x_3 \leq 1, x_1, x_2, x_3 \geq 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Systematic enumeration:&lt;/strong&gt; Choose 3 from 4 constraints.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Extreme points:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\((0,0,0)\): \(\{x_1 = 0, x_2 = 0, x_3 = 0\}\)&lt;/li&gt;
    &lt;li&gt;\((1,0,0)\): \(\{x_2 = 0, x_3 = 0, x_1 + x_2 + x_3 = 1\}\)&lt;/li&gt;
    &lt;li&gt;\((0,1,0)\): \(\{x_1 = 0, x_3 = 0, x_1 + x_2 + x_3 = 1\}\)&lt;/li&gt;
    &lt;li&gt;\((0,0,1)\): \(\{x_1 = 0, x_2 = 0, x_1 + x_2 + x_3 = 1\}\)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Step 4: Krein-Milman verification&lt;/strong&gt;
\(P_1 = \text{conv}\{(0,0), (0,1), (1,0)\}\)
\(P_2 = \text{conv}\{(0,0,0), (1,0,0), (0,1,0), (0,0,1)\}\)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-8-generalized-inequalities&quot;&gt;&lt;strong&gt;Exercise 8: Generalized inequalities&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 2.8 from Boyd &amp;amp; Vandenberghe)
Let \(K \subseteq \mathbb{R}^n\) be a proper cone with generalized inequality \(\preceq_K\).&lt;/p&gt;

&lt;p&gt;a) Verify the properties of \(\preceq_K\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Reflexive: \(x \preceq_K x\)&lt;/li&gt;
  &lt;li&gt;Antisymmetric: \(x \preceq_K y, y \preceq_K x \Rightarrow x = y\)&lt;/li&gt;
  &lt;li&gt;Transitive: \(x \preceq_K y, y \preceq_K z \Rightarrow x \preceq_K z\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;b) For \(K = \mathbb{S}_+^n\), verify:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[A \preceq B \Rightarrow A + C \preceq B + C\]
  &lt;/li&gt;
  &lt;li&gt;
\[A \preceq B, C \succeq 0 \Rightarrow CAC \preceq CBC\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Rigorous proofs of the properties&lt;/li&gt;
  &lt;li&gt;Counterexamples for improper cones&lt;/li&gt;
  &lt;li&gt;Applications in optimization&lt;/li&gt;
  &lt;li&gt;Dual cone relationships&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Properties of the generalized inequality&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-definition&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt; \(x \preceq_K y \Leftrightarrow y - x \in K\)&lt;/p&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Reflexive:&lt;/strong&gt; \(x \preceq_K x \Leftrightarrow x - x = 0 \in K\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;True because \(K\) is a cone (contains 0)&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Antisymmetric:&lt;/strong&gt; \(x \preceq_K y, y \preceq_K x\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\Rightarrow y - x \in K\) and \(x - y \in K\)&lt;/li&gt;
    &lt;li&gt;
\[\Rightarrow y - x \in K \cap (-K)\]
    &lt;/li&gt;
    &lt;li&gt;Since \(K\) is pointed: \(K \cap (-K) = \{0\}\)&lt;/li&gt;
    &lt;li&gt;
\[\Rightarrow y - x = 0 \Rightarrow x = y\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Transitive:&lt;/strong&gt; \(x \preceq_K y, y \preceq_K z\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[\Rightarrow y - x \in K, z - y \in K\]
    &lt;/li&gt;
    &lt;li&gt;
\[\Rightarrow z - x = (z - y) + (y - x) \in K + K = K\]
    &lt;/li&gt;
    &lt;li&gt;
\[\Rightarrow x \preceq_K z\]
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: Matrix inequalities&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Property 1:&lt;/strong&gt; \(A \preceq B \Rightarrow A + C \preceq B + C\)&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt;&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[A \preceq B \Rightarrow B - A \succeq 0\]
      &lt;/li&gt;
      &lt;li&gt;
\[(B + C) - (A + C) = B - A \succeq 0\]
      &lt;/li&gt;
      &lt;li&gt;
\[\Rightarrow A + C \preceq B + C\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Property 2:&lt;/strong&gt; \(A \preceq B, C \succeq 0 \Rightarrow CAC \preceq CBC\)&lt;/p&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt;&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;\(B - A \succeq 0\) and \(C \succeq 0\)&lt;/li&gt;
      &lt;li&gt;For any \(x\) (with \(C\) symmetric): \(x^T(CBC - CAC)x = (Cx)^T(B - A)(Cx) \geq 0\)&lt;/li&gt;
      &lt;li&gt;\(\Rightarrow CBC - CAC \succeq 0\) (no invertibility of \(C\) needed; in fact \(C\) only needs to be symmetric)&lt;/li&gt;
      &lt;li&gt;
\[\Rightarrow CAC \preceq CBC\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: Counterexample for an improper cone&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Non-pointed cone:&lt;/strong&gt; \(K = \{x \in \mathbb{R}^2 : x_1 = 0\}\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
\[K \cap (-K) = K \neq \{0\}\]
    &lt;/li&gt;
    &lt;li&gt;Antisymmetric property fails&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Non-solid cone:&lt;/strong&gt; \(K = \mathbb{R}_+ \times \{0\} \subset \mathbb{R}^2\)&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Interior empty&lt;/li&gt;
    &lt;li&gt;Strict inequality is not well defined&lt;/li&gt;
  &lt;/ul&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-9-convex-combinations-and-carathéodorys-theorem&quot;&gt;&lt;strong&gt;Exercise 9: Convex combinations and Carathéodory’s theorem&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 2.9 from Boyd &amp;amp; Vandenberghe)
a) Prove Carathéodory’s theorem: every point in \(\text{conv}(S)\) can be written as a convex combination of at most \(n+1\) points of \(S\).&lt;/p&gt;

&lt;p&gt;b) Apply it to:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(S = \{(1,0), (0,1), (-1,0), (0,-1)\}\) in \(\mathbb{R}^2\)&lt;/li&gt;
  &lt;li&gt;\(S = \{e_i : i = 1,\ldots,n\} \cup \{0\}\) in \(\mathbb{R}^n\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c) Construct an algorithm to find a minimal representation&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;A complete proof of Carathéodory’s theorem&lt;/li&gt;
  &lt;li&gt;Explicit computations for the examples&lt;/li&gt;
  &lt;li&gt;Algorithmic implementation&lt;/li&gt;
  &lt;li&gt;Geometric interpretation&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Proof of Carathéodory’s theorem&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-theorem&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Theorem:&lt;/strong&gt; If \(x \in \text{conv}(S)\), then \(x\) can be written as:
\(x = \sum_{i=1}^{n+1} \lambda_i x_i\)
with \(x_i \in S\), \(\lambda_i \geq 0\), \(\sum \lambda_i = 1\).&lt;/p&gt;
  &lt;/div&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt;&lt;/p&gt;
    &lt;ol&gt;
      &lt;li&gt;Suppose \(x = \sum_{i=1}^k \lambda_i x_i\) with \(k &amp;gt; n+1\)&lt;/li&gt;
      &lt;li&gt;The vectors \(\{x_1 - x_k, \ldots, x_{k-1} - x_k\}\) are linearly dependent in \(\mathbb{R}^n\)&lt;/li&gt;
      &lt;li&gt;There exist \(\mu_i\), not all zero, with \(\sum_{i=1}^{k-1} \mu_i (x_i - x_k) = 0\)&lt;/li&gt;
      &lt;li&gt;Setting \(\mu_k = -\sum_{i=1}^{k-1} \mu_i\), we get \(\sum_{i=1}^k \mu_i x_i = 0\)&lt;/li&gt;
      &lt;li&gt;\(x = \sum_{i=1}^k (\lambda_i - t\mu_i) x_i\) for any \(t\)&lt;/li&gt;
      &lt;li&gt;Choose \(t = \min\{\lambda_i/\mu_i : \mu_i &amp;gt; 0\}\): all coefficients stay \(\geq 0\), they still sum to 1 (since \(\sum \mu_i = 0\)), and at least one coefficient becomes 0, so \(k\) decreases&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: Example 1 - Square vertices&lt;/strong&gt;
\(S = \{(1,0), (0,1), (-1,0), (0,-1)\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Convex hull:&lt;/strong&gt; Diamond/square rotated 45°&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Carathéodory bound:&lt;/strong&gt; \(n+1 = 3\) points suffice&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Example point:&lt;/strong&gt; \((0,0) = \frac{1}{4}(1,0) + \frac{1}{4}(0,1) + \frac{1}{4}(-1,0) + \frac{1}{4}(0,-1)\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Minimal representation:&lt;/strong&gt; \((0,0) = \frac{1}{2}(1,0) + \frac{1}{2}(-1,0)\) (2 points)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: Example 2 - Standard basis&lt;/strong&gt;
\(S = \{e_1, \ldots, e_n, 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Convex hull:&lt;/strong&gt; Standard simplex \(\{x : \sum x_i \leq 1, x_i \geq 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Any point:&lt;/strong&gt; \(x = \sum_{i=1}^n x_i e_i + (1 - \sum x_i) \cdot 0\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Carathéodory:&lt;/strong&gt; At most \(n+1\) points are needed (already achieved)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 4: Minimal representation algorithm&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Algorithm: Minimal Convex Combination
Input: Point x, set S
Output: Minimal convex combination

1. Find any representation x = Σ λᵢ xᵢ
2. While |active set| &amp;gt; n+1:
   a. Solve Σ μᵢ xᵢ = 0, Σ μᵢ = 0 with some μᵢ ≠ 0
b. Find t = min{λᵢ/μᵢ : μᵢ &amp;gt; 0}
   c. Update λᵢ ← λᵢ - t μᵢ
   d. Remove zero coefficients
3. Return minimal representation
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-10-facial-structure-of-convex-sets&quot;&gt;&lt;strong&gt;Exercise 10: Facial structure of convex sets&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 2.10 from Boyd &amp;amp; Vandenberghe)
Let \(C\) be a convex set and \(H = \{x : a^T x = \alpha\}\) a supporting hyperplane with \(\sup_{x \in C} a^T x = \alpha\).&lt;/p&gt;

&lt;p&gt;a) Prove that \(F = C \cap H\) is a face of \(C\)&lt;/p&gt;

&lt;p&gt;b) Classify the faces of:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Unit cube \([0,1]^n\)&lt;/li&gt;
  &lt;li&gt;Unit simplex \(\{x : \sum x_i \leq 1, x_i \geq 0\}\)&lt;/li&gt;
  &lt;li&gt;\(\ell_2\) ball \(\{x : \lVert x \rVert_2 \leq 1\}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c) Establish face lattice structure&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;A rigorous proof of the face property&lt;/li&gt;
  &lt;li&gt;Complete enumeration for the examples&lt;/li&gt;
  &lt;li&gt;Dimension analysis&lt;/li&gt;
  &lt;li&gt;Lattice structure visualization&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Detailed solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Step 1: Face characterization&lt;/strong&gt;&lt;/p&gt;

  &lt;div class=&quot;textbook-definition&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt; \(F\) is a face of \(C\) if:&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[F \subseteq C\]
      &lt;/li&gt;
      &lt;li&gt;\(F\) convex&lt;/li&gt;
      &lt;li&gt;If \(x \in F\) and \(x = \theta y + (1-\theta) z\) with \(y, z \in C\), \(\theta \in (0,1)\), then \(y, z \in F\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;

  &lt;div class=&quot;textbook-theorem&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Theorem:&lt;/strong&gt; \(F = C \cap H\) with \(H\) a supporting hyperplane is a face.&lt;/p&gt;
  &lt;/div&gt;

  &lt;div class=&quot;textbook-proof&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt;&lt;/p&gt;
    &lt;ol&gt;
      &lt;li&gt;\(F \subseteq C\) (by definition)&lt;/li&gt;
      &lt;li&gt;\(F\) is convex (intersection of convex sets)&lt;/li&gt;
      &lt;li&gt;If \(x \in F\), \(x = \theta y + (1-\theta) z\), \(y, z \in C\):
        &lt;ul&gt;
          &lt;li&gt;
\[\alpha = a^T x = \theta a^T y + (1-\theta) a^T z\]
          &lt;/li&gt;
          &lt;li&gt;\(a^T y, a^T z \leq \alpha\) (since \(y, z \in C\))&lt;/li&gt;
          &lt;li&gt;
\[\Rightarrow a^T y = a^T z = \alpha\]
          &lt;/li&gt;
          &lt;li&gt;
\[\Rightarrow y, z \in F\]
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/div&gt;

  &lt;p&gt;&lt;strong&gt;Step 2: Faces of the unit cube&lt;/strong&gt;
\(C = [0,1]^n\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Face enumeration:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Dimension 0:&lt;/strong&gt; \(2^n\) vertices \(\{0,1\}^n\)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Dimension 1:&lt;/strong&gt; \(n \cdot 2^{n-1}\) edges&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Dimension \(k\):&lt;/strong&gt; Faces obtained by fixing \(n-k\) coordinates to \(\{0,1\}\)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Dimension \(n-1\):&lt;/strong&gt; \(2n\) facets \(\{x_i = 0\}\), \(\{x_i = 1\}\)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Dimension \(n\):&lt;/strong&gt; \(C\) itself&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Total faces:&lt;/strong&gt; \(3^n\) (each coordinate can be free, 0, or 1)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Step 3: Faces of the unit simplex&lt;/strong&gt;
\(C = \{x : \sum x_i \leq 1, x_i \geq 0\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Face structure:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Vertices:&lt;/strong&gt; \(\{0, e_1, \ldots, e_n\}\) (\(n+1\) vertices)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Edges:&lt;/strong&gt; Connect vertices&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Facets:&lt;/strong&gt; \(\{x_i = 0\}\) and \(\{\sum x_i = 1\}\)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;General faces:&lt;/strong&gt; Obtained by setting subset of coordinates to 0&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Step 4: Faces of the \(\ell_2\) ball&lt;/strong&gt;
\(C = \{x : \lVert x \rVert_2 \leq 1\}\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Face structure:&lt;/strong&gt;&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Dimension 0:&lt;/strong&gt; Every boundary point \(\{x\}\) with \(\lVert x \rVert_2 = 1\) (infinitely many extreme points); the origin is &lt;strong&gt;not&lt;/strong&gt; a face&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Dimension \(n\):&lt;/strong&gt; \(C\) itself (plus the empty face)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;No other faces:&lt;/strong&gt; The ball is strictly convex, so every supporting hyperplane touches it at exactly one point; the sphere itself is not convex, hence not a face&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Lattice structure:&lt;/strong&gt; \(\emptyset \subset \{x\} \subset C\) for each \(x\) on the sphere (no chain of length greater than 3)&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;practical-tips&quot;&gt;Practical Tips&lt;/h2&gt;

&lt;h4 id=&quot;when-verifying-convexity&quot;&gt;&lt;strong&gt;When verifying convexity:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Use the definition directly: \(\theta x + (1-\theta) y \in C\)&lt;/li&gt;
  &lt;li&gt;Apply operations that preserve convexity&lt;/li&gt;
  &lt;li&gt;Check sublevel sets of convex functions&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;when-computing-convex-hulls&quot;&gt;&lt;strong&gt;When computing convex hulls:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Identify the extreme points first&lt;/li&gt;
  &lt;li&gt;Use Carathéodory’s theorem to reduce complexity&lt;/li&gt;
  &lt;li&gt;Verify with supporting hyperplanes&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;when-working-with-dual-cones&quot;&gt;&lt;strong&gt;When working with dual cones:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Remember the definition: \(K^* = \{y : y^T x \geq 0, \forall x \in K\}\)&lt;/li&gt;
  &lt;li&gt;Exploit the self-duality of important cones&lt;/li&gt;
  &lt;li&gt;Use them in generalized inequalities&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;summary&quot;&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;important-convex-sets&quot;&gt;&lt;strong&gt;Important Convex Sets:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Set&lt;/th&gt;
      &lt;th&gt;Definition&lt;/th&gt;
      &lt;th&gt;Example&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Affine set&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\{x : Ax = b\}\)&lt;/td&gt;
      &lt;td&gt;Subspace, hyperplane&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Convex hull&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\text{conv}(S) = \{\sum \theta_i x_i : \sum \theta_i = 1, \theta_i \geq 0\}\)&lt;/td&gt;
      &lt;td&gt;Smallest convex set containing \(S\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Cone&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\theta x \in C\) \(\forall x \in C, \theta \geq 0\)&lt;/td&gt;
      &lt;td&gt;Nonnegative orthant&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Polyhedron&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\{x : Ax \leq b, Cx = d\}\)&lt;/td&gt;
      &lt;td&gt;Intersection of halfspaces&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ellipsoid&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\{x : (x-x_c)^TP^{-1}(x-x_c) \leq 1\}\)&lt;/td&gt;
      &lt;td&gt;\(P \succ 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Norm ball&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\{x : ||x - x_c|| \leq r\}\)&lt;/td&gt;
      &lt;td&gt;\(\ell_1, \ell_2, \ell_\infty\) balls&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;operations-preserving-convexity&quot;&gt;&lt;strong&gt;Operations Preserving Convexity:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Operation&lt;/th&gt;
      &lt;th&gt;Example&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Intersection&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(C_1 \cap C_2\) is convex if \(C_1, C_2\) are convex&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Affine map&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(C) = \{Ax + b : x \in C\}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Perspective&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(P(x, t) = x/t\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Linear fractional&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f(x) = \frac{Ax + b}{c^Tx + d}\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;separation--support&quot;&gt;&lt;strong&gt;Separation &amp;amp; Support:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Separating hyperplane:&lt;/strong&gt; There exists \(a\) such that \(a^Tx \leq b\) \(\forall x \in C_1\) and \(a^Tx \geq b\) \(\forall x \in C_2\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Supporting hyperplane:&lt;/strong&gt; \(\{x : a^Tx = a^Tx_0\}\) at a boundary point \(x_0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual cone:&lt;/strong&gt; \(K^* = \{y : y^Tx \geq 0, \forall x \in K\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-dual cones:&lt;/strong&gt; \(K^* = K\) (e.g., nonnegative orthant, PSD cone)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;key-theorems&quot;&gt;&lt;strong&gt;Key Theorems:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Carathéodory:&lt;/strong&gt; Every point of \(\text{conv}(S) \subset \mathbb{R}^n\) is a combination of \(\leq n+1\) points&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Radon:&lt;/strong&gt; Any \(n+2\) points in \(\mathbb{R}^n\) can be partitioned into 2 disjoint sets whose convex hulls intersect&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Helly:&lt;/strong&gt; If \(C_1, \ldots, C_m\) are convex in \(\mathbb{R}^n\) (\(m \geq n+1\)) and every \(n+1\) of them intersect, then \(\bigcap_{i=1}^m C_i \neq \emptyset\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 2: Convex Sets&lt;/li&gt;
      &lt;li&gt;Exercises 2.1-2.27&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Rockafellar, R. T.&lt;/strong&gt; (1970). &lt;em&gt;Convex Analysis&lt;/em&gt;. Princeton University Press.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ziegler, G. M.&lt;/strong&gt; (1995). &lt;em&gt;Lectures on Polytopes&lt;/em&gt;. Springer-Verlag.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>02-08 Multiple-Choice Quiz - Convex Sets</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_08_Quiz_Convex_Sets/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_08_Quiz_Convex_Sets</id>
   <content type="html">&lt;p&gt;Geometric intuition can trick you in higher dimensions: a set defined by a product inequality like \(x_1 x_2 \ge 1\) looks nonlinear and suspicious, yet its positive branch is completely convex, while the union of two convex cones is almost never convex. This Chapter 02 quiz checks whether you can classify sets, apply convexity-preserving rules, and wield separating hyperplanes and dual cones cleanly under exam conditions.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-skills-verified-by-this-quiz&quot;&gt;Key ideas: Four Skills Verified by This Quiz&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Classification Hierarchy:&lt;/strong&gt; Instantly separating affine sets, convex sets, convex cones, and nonconvex traps (such as nonlinear equalities or set unions).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Canonical Set Recognition:&lt;/strong&gt; Identifying halfspaces, ellipsoids, polyhedra, simplexes, norm cones, and \(\mathbb{S}_+^n\) from algebraic descriptions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preservation Rules:&lt;/strong&gt; Proving convexity rapidly via intersection, affine maps, and perspective rather than getting stuck in messy algebra.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Separation &amp;amp; Dual Cones:&lt;/strong&gt; Applying the separating/supporting hyperplane theorems and recognizing self-dual vs. non-self-dual cones.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-diagnosing-a-nonlinear-inequality-set&quot;&gt;Worked example: Diagnosing a Nonlinear Inequality Set&lt;/h3&gt;

&lt;p&gt;Is \(S = \{(x_1, x_2) \in \mathbb{R}^2 : x_1 &amp;gt; 0,\; x_2 &amp;gt; 0,\; x_1 x_2 \ge 1\}\) convex?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test a concrete pair of boundary points:&lt;/strong&gt; Pick \(x = (1, 1)^T \in S\) and \(y = (4, 1/4)^T \in S\). Their midpoint is
\(m = \frac{1}{2}(1, 1)^T + \frac{1}{2}(4, 0.25)^T = (2.5,\; 0.625)^T.\)
Check the product: \(2.5 \times 0.625 = 1.5625 \ge 1 \implies m \in S\) (encouraging!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Prove convexity rigorously in one line:&lt;/strong&gt; Because \(x_1 &amp;gt; 0\), rewrite \(x_1 x_2 \ge 1\) as \(x_2 \ge \frac{1}{x_1}\). The function \(g(x_1) = 1/x_1\) has \(g&apos;&apos;(x_1) = 2/x_1^3 &amp;gt; 0\) on \(x_1 &amp;gt; 0\), so \(S\) is the epigraph of a convex function—hence &lt;strong&gt;convex&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Watch the sign trap:&lt;/strong&gt; If we dropped \(x_1 &amp;gt; 0, x_2 &amp;gt; 0\), then \((1, 1)\) and \((-1, -1)\) would both satisfy \(x_1 x_2 \ge 1\), yet their midpoint \((0, 0)\) fails \(0 \ge 1\)—making the two-branch set &lt;strong&gt;nonconvex&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of affine sets, convex sets and important examples in convex geometry.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-affine-sets&quot;&gt;📏 &lt;strong&gt;Affine Sets&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt;
A set \(C\) is affine if for all \(x_1, x_2 \in C\) and \(\theta \in \mathbb{R}\):
\(\theta x_1 + (1-\theta)x_2 \in C\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Affine combination:&lt;/strong&gt;
\(\sum_{i=1}^k \theta_i x_i\) with \(\sum_{i=1}^k \theta_i = 1\) (no requirement \(\theta_i \ge 0\))&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bao affine:&lt;/strong&gt;
\(\text{aff}(C) = \{\sum_{i=1}^k \theta_i x_i \mid x_i \in C, \sum_{i=1}^k \theta_i = 1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; An affine set = a translate of a linear subspace&lt;/p&gt;

&lt;h3 id=&quot;-convex-sets&quot;&gt;🔵 &lt;strong&gt;Convex Sets&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt;
A set \(C\) is convex if for all \(x_1, x_2 \in C\) and \(0 \le \theta \le 1\):
\(\theta x_1 + (1-\theta)x_2 \in C\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Convex combination:&lt;/strong&gt;
\(\sum_{i=1}^k \theta_i x_i\) with \(\sum_{i=1}^k \theta_i = 1, \theta_i \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convex hull:&lt;/strong&gt;
\(\text{conv}(C) = \{\sum_{i=1}^k \theta_i x_i \mid x_i \in C, \theta_i \ge 0, \sum_{i=1}^k \theta_i = 1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intuition:&lt;/strong&gt; No “dents” - the segment joining any 2 points lies in the set&lt;/p&gt;

&lt;h3 id=&quot;-cones-and-convex-cones&quot;&gt;🔺 &lt;strong&gt;Cones and Convex Cones&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Cone:&lt;/strong&gt;
A set \(C\) is a cone if for all \(x \in C\) and \(\theta \ge 0\):
\(\theta x \in C\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convex cone:&lt;/strong&gt;
Both a cone and convex. For \(x_1, x_2 \in C\) and \(\theta_1, \theta_2 \ge 0\):
\(\theta_1 x_1 + \theta_2 x_2 \in C\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conic combination:&lt;/strong&gt;
\(\sum_{i=1}^k \theta_i x_i\) with \(\theta_i \ge 0\) (no requirement that the sum = 1)&lt;/p&gt;

&lt;h3 id=&quot;-important-examples&quot;&gt;📐 &lt;strong&gt;Important Examples&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Basic sets:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The empty set \(\emptyset\): convex&lt;/li&gt;
  &lt;li&gt;A single point \(\{x_0\}\): convex&lt;/li&gt;
  &lt;li&gt;Lines, line segments, rays: convex&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hyperplane:&lt;/strong&gt;
\(\{x \mid a^T x = b\}\) with \(a \neq 0\) - affine and convex&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Halfspace:&lt;/strong&gt;
\(\{x \mid a^T x \le b\}\) with \(a \neq 0\) - convex&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Affine space:&lt;/strong&gt;
\(\{x \mid Ax = b\}\) - affine and convex&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Euclidean ball:&lt;/strong&gt;
\(\{x \mid \lVert x - x_c \rVert_2 \le r\}\) - convex&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Norm ball:&lt;/strong&gt;
\(\{x \mid \lVert x \rVert \le r\}\) for any norm - convex&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ellipsoid:&lt;/strong&gt;
\(\{x \mid (x-x_c)^T P^{-1} (x-x_c) \le 1\}\) with \(P \succ 0\) - convex&lt;/p&gt;

&lt;h3 id=&quot;️-separating-and-supporting-hyperplanes&quot;&gt;✂️ &lt;strong&gt;Separating and Supporting Hyperplanes&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Separating hyperplane theorem:&lt;/strong&gt;
If \(C\) and \(D\) are two disjoint convex sets, there exists a hyperplane \(\{x \mid a^T x = b\}\) with \(a \neq 0\) such that:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(a^T x \le b\) for all \(x \in C\)&lt;/li&gt;
  &lt;li&gt;\(a^T x \ge b\) for all \(x \in D\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Supporting hyperplane theorem:&lt;/strong&gt;
For a convex set \(C\) and a boundary point \(x_0 \in \text{bd}(C)\), there exists a supporting hyperplane:
\(\{x \mid a^T x = a^T x_0\}\) such that \(a^T x \le a^T x_0\) for all \(x \in C\)&lt;/p&gt;

&lt;h3 id=&quot;-relations-between-the-sets&quot;&gt;🔗 &lt;strong&gt;Relations Between the Sets&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Affine sets ⊂ Convex sets
     ↓
Convex cones = Cones ∩ Convex sets (so Convex cones ⊂ Cones and Convex cones ⊂ Convex sets)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Remember:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Affine:&lt;/strong&gt; The line through 2 points (\(\theta \in \mathbb{R}\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex:&lt;/strong&gt; The segment joining 2 points (\(0 \le \theta \le 1\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cone:&lt;/strong&gt; The ray from the origin through a point (\(\theta \ge 0\))&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-operations-that-preserve-convexity&quot;&gt;🎯 &lt;strong&gt;Operations that Preserve Convexity&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Intersection:&lt;/strong&gt; The intersection of convex sets is convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine combination:&lt;/strong&gt; \(\alpha C + \beta D\) is convex if \(C, D\) are convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine image:&lt;/strong&gt; \(f(C) = \{Ax + b \mid x \in C\}\) is convex if \(C\) is convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine preimage:&lt;/strong&gt; \(f^{-1}(D) = \{x \mid Ax + b \in D\}\) is convex if \(D\) is convex&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; Convex sets are the foundation of convex optimization. Most constraint sets in practice can be written as intersections of basic convex sets!&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Multiple-Choice Quiz: Convex Sets&lt;/h2&gt;
        &lt;p&gt;Choose the best answer for each question. The quiz focuses on the basic concepts of affine sets, convex sets and hyperplanes.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Question 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Question 1: A set $$C$$ is affine if:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) For all $$x_1, x_2 \in C$$ and $$0 \leq \theta \leq 1$$, we have $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) For all $$x_1, x_2 \in C$$ and $$\theta \in \mathbb{R}$$, we have $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) The set $$C$$ is closed&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) The set $$C$$ has a boundary&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) For all $$x_1, x_2 \in C$$ and $$\theta \in \mathbb{R}$$, we have $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/strong&gt;&lt;br /&gt;
                An affine set contains the entire line through any two of its points, with no restriction of $$\theta$$ to $$[0,1]$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: An affine combination of the points $$x_1, x_2, ..., x_k$$ has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) $$\sum_{i=1}^k \theta_i x_i$$ with $$\theta_i \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) $$\sum_{i=1}^k \theta_i x_i$$ with $$\sum_{i=1}^k \theta_i = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) $$\sum_{i=1}^k \theta_i x_i$$ with $$\theta_i \geq 0$$ and $$\sum_{i=1}^k \theta_i = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) $$\sum_{i=1}^k x_i$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\sum_{i=1}^k \theta_i x_i$$ with $$\sum_{i=1}^k \theta_i = 1$$&lt;/strong&gt;&lt;br /&gt;
                An affine combination only requires the coefficients to sum to 1; it does not require them to be nonnegative (unlike a convex combination).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: If $$C$$ is an affine set and $$x_0 \in C$$, then $$V = C - x_0$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) An affine set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) A linear subspace&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) A convex set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) A hyperplane&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) A linear subspace&lt;/strong&gt;&lt;br /&gt;
                An affine set $$C$$ is the translate of a linear subspace $$V$$ by $$x_0$$. Hence $$V = C - x_0$$ is a subspace.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: A set $$C$$ is convex if:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) For all $$x_1, x_2 \in C$$ and $$\theta \in \mathbb{R}$$, we have $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) For all $$x_1, x_2 \in C$$ and $$0 \leq \theta \leq 1$$, we have $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) The set $$C$$ has no holes&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) The set $$C$$ is a disk&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) For all $$x_1, x_2 \in C$$ and $$0 \leq \theta \leq 1$$, we have $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/strong&gt;&lt;br /&gt;
                A convex set contains the segment joining any two of its points, with $$\theta$$ restricted to $$[0,1]$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: How does a convex combination differ from an affine combination?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) The coefficients must sum to 1&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) The coefficients must be nonnegative&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) The number of points involved&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) There is no difference&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The coefficients must be nonnegative&lt;/strong&gt;&lt;br /&gt;
                A convex combination requires $$\theta_i \geq 0$$ and $$\sum \theta_i = 1$$, whereas an affine combination only needs $$\sum \theta_i = 1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: The hyperplane $$\{x : a^T x = b\}$$ with $$a \neq 0$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) Only a convex set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) Only an affine set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) Both a convex set and an affine set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Neither a convex set nor an affine set&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) Both a convex set and an affine set&lt;/strong&gt;&lt;br /&gt;
                A hyperplane satisfies both the convex-set and the affine-set definitions because it contains the entire line through any two of its points.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: The halfspace $$\{x : a^T x \leq b\}$$ with $$a \neq 0$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Convex but not affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Affine but not convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Both a convex set and an affine set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Neither a convex set nor an affine set&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Convex but not affine&lt;/strong&gt;&lt;br /&gt;
                A halfspace is convex because it contains the segment joining any two of its points, but it is not affine because it does not contain entire lines.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The Euclidean ball $$B(x_c, r) = \{x : \|x - x_c\|_2 \leq r\}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) A convex set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) An affine set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) A hyperplane&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) A halfspace&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) A convex set&lt;/strong&gt;&lt;br /&gt;
                The Euclidean ball is convex because the segment joining any two points of the ball also lies in the ball.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The ellipsoid $$\{x : (x-x_c)^T P^{-1} (x-x_c) \leq 1\}$$ with $$P \succ 0$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) A special case of the ball&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) A convex set generalizing the ball&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) Not a convex set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) Only defined in 2D&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) A convex set generalizing the ball&lt;/strong&gt;&lt;br /&gt;
                The ellipsoid generalizes the Euclidean ball. When $$P = r^2 I$$, the ellipsoid becomes a ball.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: A polyhedron is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) An intersection of balls&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) The solution set of finitely many linear inequalities and equalities&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) A union of halfspaces&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) A product of convex sets&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The solution set of finitely many linear inequalities and equalities&lt;/strong&gt;&lt;br /&gt;
                A polyhedron has the form $$\{x : a_i^T x \leq b_i, c_j^T x = d_j\}$$, the intersection of halfspaces and hyperplanes.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: A simplex in $$n$$-dimensional space is formed from:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) $$n$$ affinely independent points&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) $$n+1$$ affinely independent points&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) $$2n$$ points&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Infinitely many points&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$n+1$$ affinely independent points&lt;/strong&gt;&lt;br /&gt;
                An $$n$$-dimensional simplex needs $$n+1$$ affinely independent points: a point (0D), a segment (1D), a triangle (2D), a tetrahedron (3D).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The norm ball $$\{x : \|x - x_c\| \leq r\}$$ is convex:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) For every norm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Only for the Euclidean norm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Only for p-norms with $$p \geq 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Only when $$p = 2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) For every norm&lt;/strong&gt;&lt;br /&gt;
                The ball of every norm is convex: if $$\|x - x_c\| \leq r$$ and $$\|y - x_c\| \leq r$$, then by the triangle inequality and homogeneity, $$\|\theta x + (1-\theta)y - x_c\| \leq \theta r + (1-\theta) r = r$$. (For $$p &amp;lt; 1$$, $$\|\cdot\|_p$$ is not a norm and its &quot;ball&quot; is not convex.)
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The separating hyperplane theorem states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Any two convex sets can be separated by a hyperplane&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Two disjoint convex sets can be separated by a hyperplane&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Every convex set has a supporting hyperplane&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) A hyperplane always divides space into two equal parts&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Two disjoint convex sets can be separated by a hyperplane&lt;/strong&gt;&lt;br /&gt;
                The separating hyperplane theorem applies to two disjoint (non-intersecting) convex sets, not to every pair of convex sets.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: A supporting hyperplane at a point $$x_0$$ on the boundary of a convex set $$C$$ satisfies:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) $$a^T x \geq a^T x_0$$ for all $$x \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) $$a^T x \leq a^T x_0$$ for all $$x \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) $$a^T x = a^T x_0$$ for all $$x \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) $$a^T x &amp;gt; a^T x_0$$ for all $$x \in C$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$a^T x \leq a^T x_0$$ for all $$x \in C$$&lt;/strong&gt;&lt;br /&gt;
                The supporting hyperplane $$\{x : a^T x = a^T x_0\}$$ &quot;supports&quot; $$C$$ at $$x_0$$, with $$C$$ lying in the halfspace $$a^T x \leq a^T x_0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: Strict separation of two sets $$C$$ and $$D$$ means:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) $$a^T x \leq b$$ for $$x \in C$$ and $$a^T x \geq b$$ for $$x \in D$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) $$a^T x &amp;lt; b$$ for $$x \in C$$ and $$a^T x &amp;gt; b$$ for $$x \in D$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) $$a^T x = b$$ for $$x \in C \cup D$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) The distance between $$C$$ and $$D$$ is greater than 0&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$a^T x &amp;lt; b$$ for $$x \in C$$ and $$a^T x &amp;gt; b$$ for $$x \in D$$&lt;/strong&gt;&lt;br /&gt;
                Strict separation requires strict inequalities (&amp;lt; and &amp;gt;), not just ≤ and ≥.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: The convex hull of a set $$S$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) The smallest convex set containing $$S$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) The largest convex set contained in $$S$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) The intersection of all convex sets containing $$S$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Both A and C are correct&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) Both A and C are correct&lt;/strong&gt;&lt;br /&gt;
                The convex hull is both the smallest convex set containing $$S$$ and the intersection of all convex sets containing $$S$$. The two definitions are equivalent.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: A polytope is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Any polyhedron&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) A bounded polyhedron&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) An unbounded polyhedron&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) A polyhedron with infinitely many vertices&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) A bounded polyhedron&lt;/strong&gt;&lt;br /&gt;
                Polytope is the special term for a bounded polyhedron.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: The probability simplex in $$\mathbb{R}^n$$ is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) $$\{x : x \geq 0, \sum x_i = 1\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) $$\{x : x \geq 0, \sum x_i \leq 1\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) $$\{x : \|x\| = 1\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) $$\{x : \|x\| \leq 1\}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\{x : x \geq 0, \sum x_i = 1\}$$&lt;/strong&gt;&lt;br /&gt;
                The probability simplex is the set of probability vectors: nonnegative components summing to 1.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: An affine set can be thought of as a union of:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Many lines&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Many line segments&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Many rays&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Many isolated points&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Many lines&lt;/strong&gt;&lt;br /&gt;
                An affine set is built from many lines, a convex set from many segments, and a cone from many rays.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20: Real-world applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: In optimization, separating hyperplanes are mainly used in:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Computing gradients&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Classification and machine learning&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Computing integrals&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Solving differential equations&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Classification and machine learning&lt;/strong&gt;&lt;br /&gt;
                Separating hyperplanes underlie many classification algorithms such as SVM, which are widely used in machine learning.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 21 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: Is the set $$S = \{(x,y) : x^2 + y^2 \leq 1\}$$ (the unit disk) convex?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Yes, because it satisfies the definition of a convex set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) No, because it has a curved boundary&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) No, because it is not a polygon&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Convex only when the radius = 1&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Yes, because it satisfies the definition of a convex set&lt;/strong&gt;&lt;br /&gt;
                A disk (and a ball) is always convex. The segment joining any two points of the disk lies entirely in the disk.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: Given three points $$A(0,0), B(2,0), C(1,2)$$, which of the following points is a convex combination of them?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$(1,1)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$(3,1)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$(-1,0)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$(2,3)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$(1,1)$$&lt;/strong&gt;&lt;br /&gt;
                The convex combinations of three points form a triangle. The point $$(1,1)$$ lies in the triangle with vertices $$A, B, C$$.&lt;br /&gt;
                We can write $$(1,1) = 0.25A + 0.25B + 0.5C$$ with nonnegative coefficients summing to 1.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: Which points does the hyperplane $$\{x : 2x_1 + 3x_2 = 6\}$$ in $$\mathbb{R}^2$$ pass through?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$(0,2)$$ and $$(3,0)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$(1,1)$$ and $$(2,2)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$(0,0)$$ and $$(1,1)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$(2,3)$$ and $$(6,0)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$(0,2)$$ and $$(3,0)$$&lt;/strong&gt;&lt;br /&gt;
                Check: $$2(0) + 3(2) = 6$$ ✓ and $$2(3) + 3(0) = 6$$ ✓&lt;br /&gt;
                This is the line crossing the $$y$$-axis at $$(0,2)$$ and the $$x$$-axis at $$(3,0)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: Is the set $$K = \{(x,y) : x \geq 0, y \geq 0, y \leq x\}$$ a convex cone?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Yes, because it is closed under multiplication by positive scalars and under addition&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) No, because it does not contain the origin&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) No, because it is not symmetric&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) It is only a cone, not convex&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Yes, because it is closed under multiplication by positive scalars and under addition&lt;/strong&gt;&lt;br /&gt;
                This set is the part of the first quadrant below the line $$y = x$$; it contains the origin and satisfies the definition of a convex cone.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: Given two convex sets $$C_1$$ and $$C_2$$, which of the following sets is always convex?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$C_1 \cap C_2$$ (giao)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$C_1 \cup C_2$$ (union)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$C_1 \setminus C_2$$ (difference)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$C_1 \triangle C_2$$ (symmetric difference)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$C_1 \cap C_2$$ (giao)&lt;/strong&gt;&lt;br /&gt;
                The intersection of two convex sets is always convex. The union of two convex sets is not necessarily convex (e.g. two disjoint disks).
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Previous&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Next&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Exercise Results&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #9C27B0, #673AB7);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #9C27B0;
    background-color: #f3e5f5;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #9C27B0;
    background-color: #e8d5e8;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #f3e5f5;
    border-left: 4px solid #9C27B0;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #7B1FA2;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #9C27B0;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #7B1FA2;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #f3e5f5;
    border-radius: 8px;
    border: 2px solid #9C27B0;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #7B1FA2;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answer for each question
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;b&apos;,
    q6: &apos;c&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;b&apos;, q10: &apos;b&apos;,
    q11: &apos;b&apos;, q12: &apos;a&apos;, q13: &apos;b&apos;, q14: &apos;b&apos;, q15: &apos;b&apos;,
    q16: &apos;d&apos;, q17: &apos;b&apos;, q18: &apos;a&apos;, q19: &apos;a&apos;, q20: &apos;b&apos;,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;
};

/**
 * Update the progress bar and show the current question
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Question ${currentQuestion}/${totalQuestions}`;
}

/**
 * Show a question by its number
 */
function showQuestion(questionNum) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Update the state of the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Go to the next question
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Go back to the previous question
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Store the user&apos;s answer
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Update the UI to show the selected answer
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Submit and show the results
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Compute the score and build the detailed report
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Show explanations for all questions
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Build the detailed report
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Question ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Correct&apos; : &apos;Incorrect&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Your answer: ${userAnswer || &apos;Not answered&apos;} | Correct answer: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Show the results
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Score: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Excellent! You have mastered convex geometry!&apos; :
              scorePercentage &gt;= 60 ? &apos;👍 Pretty good! Review a few geometric concepts.&apos; :
              scorePercentage &gt;= 40 ? &apos;📚 You need more review of convex sets and hyperplanes.&apos; : &apos;💪 Reread the theory of convex geometry!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Restart the exercise
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide the results and show the navigation again
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Clear all selections
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>02-06 Dual cones and generalized inequalities</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_06_Dual_cones_and_generalized_inequalities/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_06_Dual_cones_and_generalized_inequalities</id>
   <content type="html">&lt;p&gt;Every cone \(K\) casts a shadow—its &lt;strong&gt;dual cone&lt;/strong&gt; \(K^*\), consisting of all directions that make an acute (or right) angle with every vector in \(K\). Why does this geometric shadow matter? Because in vector optimization and conic duality, Lagrange multipliers for a conic constraint \(x \in K\) must live in \(K^*\), and strictly positive dual weights \(\lambda \succ_{K^*} 0\) sweep out Pareto-optimal frontiers by turning multi-objective problems into scalar objectives.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-dual-cones--cone-ordered-duality&quot;&gt;Key ideas: Dual Cones &amp;amp; Cone-Ordered Duality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dual Cone Definition (\(K^* = \{y : y^T x \ge 0 \;\forall x \in K\}\)):&lt;/strong&gt; Always a closed convex cone—even if the original set \(K\) was not convex!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inclusion Reversal (Narrow Cone \(\leftrightarrow\) Wide Dual):&lt;/strong&gt; Shrinking \(K\) relaxes the inner-product constraints on \(y\), making \(K^*\) strictly larger (\(K_1 \subseteq K_2 \implies K_2^* \subseteq K_1^*\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-Dual Cones (\(K^* = K\)):&lt;/strong&gt; The nonnegative orthant \(\mathbb{R}_+^n\), the \(\ell_2\) second-order cone, and the PSD cone \(\mathbb{S}_+^n\) are all self-dual—the symmetry that powers primal-dual interior-point methods.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scalarizing Vector Objectives:&lt;/strong&gt; Multiplying a vector constraint or objective by \(\lambda \in K^*\) converts cone inequalities into ordinary scalar inequalities without reversing their direction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-the-dual-of-a-narrow-2d-wedge&quot;&gt;Worked example: Computing the Dual of a Narrow 2D Wedge&lt;/h3&gt;

&lt;p&gt;Find the dual cone \(K^*\) of the narrow first-quadrant wedge \(K = \text{cone}\{(1, 0)^T,\; (1, 1)^T\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test against the extreme rays of \(K\):&lt;/strong&gt; Any \(x \in K\) is \(x = \alpha(1, 0)^T + \beta(1, 1)^T\) with \(\alpha, \beta \ge 0\). Thus \(y^T x \ge 0\) for all \(x \in K\) if and only if \(y\) has nonnegative inner product with both generators:
    &lt;ul&gt;
      &lt;li&gt;\(y^T (1, 0)^T = y_1 \ge 0\).&lt;/li&gt;
      &lt;li&gt;\(y^T (1, 1)^T = y_1 + y_2 \ge 0\) (i.e., \(y_2 \ge -y_1\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write \(K^*\) explicitly:&lt;/strong&gt;
\(K^* = \{(y_1, y_2) \in \mathbb{R}^2 : y_1 \ge 0,\; y_1 + y_2 \ge 0\}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Observe the width reversal:&lt;/strong&gt; While \(K\) has an opening angle of only \(45^\circ\) (between \(0^\circ\) and \(45^\circ\)), \(K^*\) opens across \(135^\circ\) (from \(-45^\circ\) to \(90^\circ\))—for instance, \(y = (1, -1)^T \in K^*\) even though \(y \notin K\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section discusses dual cones paired with cones, and dual generalized inequalities. Using dual generalized inequalities allows comparison using scalar inner products, making comparisons much easier.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-06-02 Dual generalized inequalities</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_06_02_Dual_generalized_inequalities/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_06_02_Dual_generalized_inequalities</id>
   <content type="html">&lt;p&gt;Suppose an aerospace team must minimize both &lt;em&gt;weight&lt;/em&gt; and &lt;em&gt;drag&lt;/em&gt; simultaneously across a set of wing designs. Because there is no single wing with both minimum weight and minimum drag, how do you actually compute points on the Pareto-optimal trade-off curve using a standard scalar optimizer? Dual generalized inequalities give the exact answer: minimize \(\lambda^T x\) for strictly positive dual weights \(\lambda \succ_{K^*} 0\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-scalarizing-multi-objective-trade-offs&quot;&gt;Key ideas: Scalarizing Multi-Objective Trade-Offs&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Preservation Under Nonnegative Dual Weights:&lt;/strong&gt; \(x \preceq_K y \iff \lambda^T x \le \lambda^T y\) for all \(\lambda \succeq_{K^*} 0\)—turning a vector inequality into an equivalent family of scalar inequalities.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Test for a Minimum Element:&lt;/strong&gt; \(x\) is the minimum element of \(S\) w.r.t. \(K\) if and only if for &lt;em&gt;every&lt;/em&gt; \(\lambda \succ_{K^*} 0\), \(x\) is the unique minimizer of \(\lambda^T z\) over \(S\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Test for Minimal (Pareto) Elements:&lt;/strong&gt; If \(x\) minimizes \(\lambda^T z\) over \(S\) for &lt;em&gt;some&lt;/em&gt; \(\lambda \succ_{K^*} 0\), then \(x\) is guaranteed to be minimal (Pareto-optimal)—and when \(S\) is convex, the converse nearly holds (every minimal point minimizes \(\lambda^T z\) for some nonzero \(\lambda \succeq_{K^*} 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Economic Meaning of \(\lambda\):&lt;/strong&gt; The weight vector \(\lambda\) acts as a vector of shadow prices trading off one objective against another along the optimal production frontier.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-sweeping-a-pareto-frontier-via-dual-weights&quot;&gt;Worked example: Sweeping a Pareto Frontier via Dual Weights&lt;/h3&gt;

&lt;p&gt;Recover all three minimal elements of \(S = \{(1, 4),\; (2, 2),\; (3, 1)\}\) (under \(K = K^* = \mathbb{R}_+^2\)) by minimizing \(\lambda^T z = \lambda_1 z_1 + \lambda_2 z_2\) for strictly positive weights \(\lambda \succ 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Weight \(\lambda^{(1)} = (3, 1)^T\) (prioritizes first cost):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Scores: \(3(1) + 4 = 7\), \(3(2) + 2 = 8\), \(3(3) + 1 = 10\).&lt;/li&gt;
      &lt;li&gt;Unique minimizer: \((1, 4)\), certifying \((1, 4)\) as minimal.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Weight \(\lambda^{(2)} = (2, 1.5)^T\) (balanced trade-off):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Scores: \(2(1) + 1.5(4) = 8\), \(2(2) + 1.5(2) = 7\), \(2(3) + 1.5(1) = 7.5\).&lt;/li&gt;
      &lt;li&gt;Unique minimizer: \((2, 2)\), certifying \((2, 2)\) as minimal.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Weight \(\lambda^{(3)} = (1, 3)^T\) (prioritizes second cost):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Scores: \(1 + 3(4) = 13\), \(2 + 3(2) = 8\), \(3 + 3(1) = 6\).&lt;/li&gt;
      &lt;li&gt;Unique minimizer: \((3, 1)\), certifying \((3, 1)\) as minimal.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If we can define a generalized inequality using a proper cone, we can also define a dual generalized inequality using the dual cone, provided the dual cone is proper.&lt;/p&gt;

&lt;p&gt;This section defines dual generalized inequalities using a proper dual cone and redefines minimum and minimal elements using dual inequalities.&lt;/p&gt;

&lt;h2 id=&quot;dual-generalized-inequalities&quot;&gt;Dual generalized inequalities&lt;/h2&gt;

&lt;p&gt;Given a proper dual cone, the generalized inequality is defined as follows. For a point \(y\), if the inner product with every \(x\) in \(K\) is nonnegative, then \(y\) is nonnegative in the dual cone \(K^*\).&lt;/p&gt;

&lt;p&gt;Here, \(\succeq_{K^*}\) is called the &lt;strong&gt;dual&lt;/strong&gt; of \(\succeq_K\), i.e., the &lt;strong&gt;dual generalized inequality&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(y \succeq_{K^*} 0 \iff y^T x \ge 0\) for all \(x \succeq_K 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;key-properties-of-generalized-and-dual-inequalities&quot;&gt;Key properties of generalized and dual inequalities&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;\(x \preceq_K y\) if and only if \(\lambda^T x \le \lambda^T y\) for all \(\lambda \succeq_{K^*} 0\).&lt;/li&gt;
  &lt;li&gt;\(x \prec_K y\) if and only if \(\lambda^T x &amp;lt; \lambda^T y\) for all \(\lambda \succeq_{K^*} 0, \lambda \ne 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If \(K = K^{**}\), the dual generalized inequality associated with \(\preceq_K^*\) is \(\preceq_K\), so these properties are preserved even if the roles of generalized and dual inequalities are switched.&lt;/p&gt;

&lt;p&gt;For example, \(\lambda \preceq_K^* \mu\) if and only if \(\lambda^T x \le \mu^T x\) for all \(x \succeq_K 0\).&lt;/p&gt;

&lt;h2 id=&quot;minimum-and-minimal-elements-via-dual-inequalities&quot;&gt;Minimum and minimal elements via dual inequalities&lt;/h2&gt;

&lt;p&gt;For a generalized inequality induced by a proper cone \(K\), we can use dual generalized inequalities to characterize the minimum and minimal elements of a (possibly nonconvex) set \(S \subseteq \mathbb{R}^m\).&lt;/p&gt;

&lt;h3 id=&quot;minimum-element&quot;&gt;Minimum element&lt;/h3&gt;

&lt;p&gt;For all \(\lambda \succ_K^* 0\) and \(z \in S\),&lt;/p&gt;

&lt;p&gt;If \(x\) is the unique minimizer of \(\lambda^T z\), then with respect to the generalized inequality \(\succ_K^*\), \(x\) is the minimum of \(S\). (A minimizer is a value of the dependent variable that minimizes a function; here, the function is \(\lambda^T z\), the variable is \(z\), and the minimizer is \(x\).)&lt;/p&gt;

&lt;p&gt;Geometrically, this means that for some \(\lambda \succ_K^* 0\), the hyperplane \(\{ z \mid  \lambda^T (z-x) = 0 \}\) is a strict supporting hyperplane for \(S\) at \(x\). (A strict supporting hyperplane means the hyperplane intersects \(S\) only at \(x\).) \(S\) need not be convex. The figure below shows a minimum \(x\) and a strict supporting hyperplane.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_02_Minimum_element.png&quot; alt=&quot;[Fig1] Minimum element [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Minimum element [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;minimal-element&quot;&gt;Minimal element&lt;/h3&gt;

&lt;p&gt;The necessary and sufficient conditions for minimal elements differ slightly.&lt;/p&gt;

&lt;p&gt;For \(\lambda \succ_K^* 0\) and \(z \in S\), if \(x\) is a minimizer of \(\lambda^T z\), then \(x \in S\) is minimal. In other words, if \(x\) is minimal, then \(\lambda^T z\) does not have a unique minimizer. Therefore, for the same \(\lambda\), there can be multiple minimal elements, and there can be multiple minimal elements for different \(\lambda\).&lt;/p&gt;

&lt;p&gt;The figure below illustrates the existence of multiple minimal elements. The region with the thick black line at the bottom left indicates the area where minimal elements exist.
Here, \(x_1\) is the minimizer of \(\lambda^T_1 z\) and since \(\lambda_1 \succ_K^* 0\), it is minimal. Another minimizer, \(x_2\), also exists.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_05_Minimal_element.png&quot; alt=&quot;[Fig2] Minimal element [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Minimal element [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;However, the converse is not true. Even if a point \(x\) is minimal in a set \(S\), it may not be the minimizer of \(\lambda^T z\) for some \(\lambda\) and \(z \in S\). The figure below shows an example of a minimal element that is not a minimizer. Here, the convexity of the set seems to play a crucial role in this converse not being true.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_06_Minimal_element2.png&quot; alt=&quot;[Fig3] An example of a minimal element that is not a minimizer [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig3] An example of a minimal element that is not a minimizer [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;This converse theorem does not strengthen with \(\lambda_1 \succ_K^* 0\). In the left figure below, \(x_1 \in S_1\) is minimal, but not the minimizer of \(\lambda_1^T x_1\). The right figure shows that \(x_2 \in S_2\) is not minimal, but is the minimizer of \(\lambda_2^T x_2\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_07_Minimal_element3.png&quot; alt=&quot;[Fig4] Examples where the converse does not strengthen with $$\lambda_1 \succ_K^* 0$$ [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig4] Examples where the converse does not strengthen with } \lambda_1 \succ_K^* 0 \text{ [1]}$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;optimal-production-frontier&quot;&gt;Optimal production frontier&lt;/h3&gt;
&lt;p&gt;Consider a product that needs to be produced using n resources (labor, electricity, natural gas, water, etc.).
This product can be produced in several ways. For each production method, there is a resource vector \(x \in \mathbb{R}\), where \(x_i\) denotes the amount of resource \(i\) consumed. It is assumed that the resource consumption \(x_i\) is nonnegative, and the resources have high value.&lt;/p&gt;

&lt;p&gt;The production set \(P \subseteq \mathbb{R}^n\) is defined as the set of all resource vectors \(x\). A production method with a minimal resource vector is called &lt;strong&gt;Pareto optimal&lt;/strong&gt; or &lt;strong&gt;efficient&lt;/strong&gt;. The set of minimal elements of \(P\) is called the &lt;strong&gt;efficient production frontier&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let’s briefly look at Pareto optimality.&lt;/p&gt;

&lt;p&gt;Suppose there are two production methods, one with resource vector \(x\) (\(P_x\)) and the other with resource vector \(y\) (\(P_y\)). If for all \(i\), \(x_i \le y_i\), and for some \(i\), \(x_i \lt y_i\), then we can say that \(P_x\) is better than \(P_y\). In other words, a method that does not use more resources than another, or uses at least one resource less, is considered better. That is, this corresponds to the case where \(x \preceq y\) and \(x \ne y\).
If there is no method better than \(P_x\), then \(P_x\) is said to be Pareto optimal.&lt;/p&gt;

&lt;p&gt;By minimizing the following expression, we can find the Pareto optimal production method. Here, \(\lambda_i\) can be considered as the price of resource \(i\). Minimizing \(\lambda^T x\) with respect to \(P\) yields the cheapest production method. Since the prices are positive, the result of the minimization is always Pareto optimal.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\lambda^T x =\) \(\lambda^T_1 x_1 + \lambda^T_2 x_2 + ... + \lambda^T_n x_n, \lambda \succ 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The figure below illustrates this situation well. In the figure, \(x_1, x_2, x_3\) are Pareto optimal, while \(x_4, x_5\) are not.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_08_Pareto_optimal.png&quot; alt=&quot;[Fig5] Optimal production frontier [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig5] Optimal production frontier [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

</content>
 </entry>
 
 <entry>
   <title>02-06-01 Dual cones</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_06_01_Dual_cones/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_06_01_Dual_cones</id>
   <content type="html">&lt;p&gt;When you write the dual of a second-order cone program or a norm-regularized regression, the dual norm and dual cone appear automatically: the dual of the \(\ell_2\) cone is the \(\ell_2\) cone itself, whereas the dual of the \(\ell_\infty\) cone is the \(\ell_1\) cone (and vice versa). Seeing &lt;em&gt;why&lt;/em&gt; Cauchy–Schwarz and Hölder’s inequality create these dual pairs makes conic duality feel like a natural consequence of inner products rather than a table of memorized formulas.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-computing-and-using-dual-cones&quot;&gt;Key ideas: Computing and Using Dual Cones&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dual Cone via Support / Norm Duality:&lt;/strong&gt; For any norm cone \(K_{\|\cdot\|} = \{(x, t) : \|x\| \le t\}\), its dual cone is the norm cone of the &lt;strong&gt;dual norm&lt;/strong&gt;: \(K_{\|\cdot\|}^* = \{(u, s) : \|u\|_* \le s\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-Dual Pillars:&lt;/strong&gt; \(\mathbb{R}_+^n\), the Lorentz (\(\ell_2\)) cone, and \(\mathbb{S}_+^n\) (under the Frobenius inner product \(\text{tr}(XY)\)) all satisfy \(K^* = K\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Asymmetric Dual Pairs:&lt;/strong&gt; Because \(\ell_1\) and \(\ell_\infty\) are dual norms (\(\frac{1}{1} + \frac{1}{\infty} = 1\)), the dual of the \(\ell_\infty\) cone is the \(\ell_1\) cone—explaining why \(\ell_\infty\) constraints induce \(\ell_1\) dual variables.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biduality (\(K^{**} = \text{cl}(\text{conv}(K))\)):&lt;/strong&gt; For any closed convex cone \(K\), taking the dual twice recovers \(K\) exactly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-self-duality-of-the-ell_2-cone&quot;&gt;Worked example: Verifying Self-Duality of the \(\ell_2\) Cone&lt;/h3&gt;

&lt;p&gt;Let \(K = \{(x, s) \in \mathbb{R}^2 \times \mathbb{R} : \|x\|_2 \le s\}\) and test two candidate dual vectors with \(u = (3, -4)^T\) (so \(\|u\|_2 = 5\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Case 1: \((u, t) = (3, -4, 5)\) (satisfies \(\|u\|_2 \le t\)):&lt;/strong&gt; For &lt;em&gt;any&lt;/em&gt; \((x, s) \in K\), Cauchy–Schwarz yields
\(u^T x + ts \ge -\|u\|_2 \|x\|_2 + ts = -5\|x\|_2 + 5s = 5(s - \|x\|_2) \ge 0.\)
Hence \((3, -4, 5) \in K^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 2: \((u, t) = (3, -4, 4)\) (violates \(\|u\|_2 \le t\) since \(5 &amp;gt; 4\)):&lt;/strong&gt; Construct an explicit primal witness in \(K\) pointing opposite to \(u\):
\(x = -\frac{u}{\|u\|_2} = \begin{pmatrix} -3/5 \\ 4/5 \end{pmatrix}, \qquad s = 1 \quad (\text{so } \|x\|_2 = 1 \le s).\)
Evaluating the inner product gives:
\(u^T x + ts = 3\left(-\frac{3}{5}\right) + (-4)\left(\frac{4}{5}\right) + 4(1) = -5 + 4 = -1 &amp;lt; 0.\)
Thus \((3, -4, 4) \notin K^*\), confirming \(K^* = K\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;dual-cones&quot;&gt;Dual cones&lt;/h2&gt;

&lt;p&gt;A dual cone is defined as a pair with a cone, denoted as \(K\) for the cone and \(K^*\) for the dual cone. The dual cone is always convex, regardless of whether \(K\) is convex. The dual cone is defined as the set of points \(y\) such that the inner product with any \(x\) in \(K\) is nonnegative:&lt;/p&gt;

&lt;blockquote&gt;
\[K^* = \{y \mid x^T y \ge 0 \text{ for all } x \in K\}\]
&lt;/blockquote&gt;

&lt;p&gt;For \(x\) and \(y\), the inner product being nonnegative means the angle between the vectors is in the range where \(\cos\theta \ge 0\), i.e., \(0 \le \theta \le 90\) and \(270 \le \theta \le 360\). Thus, the boundary of the dual cone is formed in the direction of the negative normal vector of the supporting hyperplane of the cone. The figure below shows the region where the dual cone is defined. In summary, the region of the dual cone is the set of all directions of the negative normal vectors of supporting hyperplanes of the cone at the origin.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_01_2_dual_cone.png&quot; alt=&quot;[Fig1] Dual cone definition region&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Dual cone definition region&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Geometrically, if \(y \in K^*\), then \(-y\) is the normal of the supporting hyperplane of \(K\) at the origin. The next figure shows that on the left, the halfspace with inward normal \(y\) contains the cone \(K\), so \(y \in K^*\). On the right, the halfspace with inward normal \(z\) does not contain \(K\), so \(y \notin K^*\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_01_dual_cone.png&quot; alt=&quot;[Fig2] Dual cone and supporting hyperplane normal [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Dual cone and supporting hyperplane normal [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;dual-cones-examples&quot;&gt;Dual cones examples&lt;/h2&gt;

&lt;p&gt;Here are some examples of cones and their duals. The first three are &lt;strong&gt;self-dual&lt;/strong&gt;, meaning the cone and its dual are the same. The last example shows that the dual of the \(l_\infty\) cone is the \(l_1\) cone, and vice versa.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$K = \mathbb{R}^n_+, K^* = \mathbb{R}^n_+$&lt;/li&gt;
  &lt;li&gt;$K = S^n_+, K^* = S^n_+$&lt;/li&gt;
  &lt;li&gt;$K = {(x, t) \mid  |x|_2 \le t }, K^* = {(x, t)\mid  |x|_2 \le t }$&lt;/li&gt;
  &lt;li&gt;$K = {(x, t) \mid  | x |&lt;em&gt;1 \le t }, K^* = {(x, t) \mid  | x |&lt;/em&gt;{\infty} \le t }$&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;l_2-cone-is-self-dual&quot;&gt;\(l_2\) cone is self-dual&lt;/h3&gt;

&lt;p&gt;The figure below shows that the \(l_2\) cone is self-dual. That is, for \(x \in K\) on the boundary, the normal \(-y\) of the supporting hyperplane at \(x\) matches the boundary of \(K\), and \(y\) is the boundary of the dual cone \(K^*\), so \(K\) and \(K^*\) coincide.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_03_L2_self-dual.png&quot; alt=&quot;[Fig3] $$l_2$$ cone and dual cone&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig3] } l_2 \text{ cone and dual cone}$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;the-dual-cone-of-l_infty-cone-is-l_1-cone&quot;&gt;The dual cone of \(l_\infty\) cone is \(l_1\) cone&lt;/h3&gt;

&lt;p&gt;The figure below shows that the dual cone of the \(l_\infty\) cone is the \(l_1\) cone. That is, when \(x \in K\) is a boundary point, the normal \(-y\) of the supporting hyperplane at \(x\) enters the interior of \(K\) and coincides with the boundary of the \(l_1\) cone.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_04_L_inf_dual_norm.png&quot; alt=&quot;[Fig4] $$l_\infty$$ cone and dual cone&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig4] } l_\infty \text{ cone and dual cone}$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>02-05 Separating and supporting hyperplanes</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_05_Separating_and_supporting_hyperplanes/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_05_Separating_and_supporting_hyperplanes</id>
   <content type="html">&lt;p&gt;Here is one of the most powerful geometric miracles in mathematics: if two convex sets do not overlap, you can &lt;em&gt;always&lt;/em&gt; slide a flat sheet of paper (a hyperplane) cleanly between them. That single fact—the Separating Hyperplane Theorem—is the geometric engine behind Support Vector Machines, Farkas’ Lemma, and Strong Lagrange Duality. Its sibling, the Supporting Hyperplane Theorem, guarantees that every boundary point of a convex set admits a tangent flat that keeps the entire set on one side.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-separation-and-support-geometry&quot;&gt;Key ideas: Separation and Support Geometry&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Separating Hyperplane Theorem:&lt;/strong&gt; For any two disjoint nonempty convex sets \(C, D\), there exist \(a \neq 0\) and \(b\) such that \(a^T x \le b \;\forall x \in C\) and \(a^T x \ge b \;\forall x \in D\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strict Separation:&lt;/strong&gt; When \(C\) and \(D\) are closed and disjoint and at least one is compact (bounded), we get a strict margin: \(a^T x &amp;lt; b &amp;lt; a^T y\)—constructed directly from the minimum-distance segment between \(C\) and \(D\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Supporting Hyperplane Theorem:&lt;/strong&gt; At every boundary point \(x_0 \in \partial C\) of a convex set \(C\), there exists \(a \neq 0\) such that \(a^T x \le a^T x_0\) for all \(x \in C\) (the geometric origin of subgradients!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duality Link:&lt;/strong&gt; Proving a convex optimization problem has no feasible solution below value \(p^*\) amounts to separating the epigraph from a target point—yielding the dual multipliers directly as the separating normal \(a\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-constructing-a-strict-separating--supporting-hyperplane&quot;&gt;Worked example: Constructing a Strict Separating &amp;amp; Supporting Hyperplane&lt;/h3&gt;

&lt;p&gt;Let \(C = \{x \in \mathbb{R}^2 : \|x\|_2 \le 1\}\) (closed, compact unit disk) and \(x_0 = (3, 4)^T \notin C\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find the closest point \(p \in C\) to \(x_0\):&lt;/strong&gt; Since \(\|x_0\|_2 = \sqrt{3^2 + 4^2} = 5\), the projection onto the unit disk is
\(p = \frac{x_0}{\|x_0\|_2} = \begin{pmatrix} 3/5 \\ 4/5 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choose the unit separating normal \(u = \frac{x_0 - p}{\|x_0 - p\|_2} = (3/5, 4/5)^T\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;For every \(x \in C\), Cauchy–Schwarz gives \(u^T x \le \|u\|_2 \|x\|_2 \le 1 \cdot 1 = 1\) (with equality at \(x = p\)).&lt;/li&gt;
      &lt;li&gt;At \(x_0 = (3, 4)^T\), \(u^T x_0 = \frac{3}{5}(3) + \frac{4}{5}(4) = \frac{25}{5} = 5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Read off both hyperplanes immediately:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Strict separating hyperplane&lt;/strong&gt; (midpoint \(b = \frac{1 + 5}{2} = 3\)): \(\frac{3}{5}x_1 + \frac{4}{5}x_2 = 3\) strictly separates \(C\) (\(u^T x \le 1 &amp;lt; 3\)) from \(x_0\) (\(u^T x_0 = 5 &amp;gt; 3\)).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Supporting hyperplane to \(C\) at \(p\):&lt;/strong&gt; \(\frac{3}{5}x_1 + \frac{4}{5}x_2 = 1\) touches \(C\) at \(p = (3/5, 4/5)^T\) while keeping all of \(C\) in the halfspace \(u^T x \le 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section introduces two theorems that characterize convex sets: the &lt;strong&gt;separating hyperplane theorem&lt;/strong&gt; and the &lt;strong&gt;supporting hyperplane theorem&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;separating-hyperplane-theorem&quot;&gt;Separating hyperplane theorem&lt;/h2&gt;

&lt;p&gt;Suppose there are several disjoint convex sets with no intersection. How can we separate them? The simplest way is to draw a line between the sets. This method is widely used in classification and is supported by the &lt;strong&gt;separating hyperplane theorem&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If there are two disjoint convex sets \(C\) and \(D\), then for \(x \in C\), \(a^T x \le b\) and for \(x \in D\), \(a^T x \ge b\) for some \(a \ne 0\) and \(b\). In other words, the affine function \(a^T x - b\) is nonpositive on \(C\) and nonnegative on \(D\). The hyperplane \(\{ x \mid a^T x = b\}\) is called a &lt;strong&gt;separating hyperplane&lt;/strong&gt; for \(C\) and \(D\).&lt;/p&gt;

&lt;p&gt;The figure below shows a separating hyperplane dividing two disjoint convex sets \(C\) and \(D\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.05_01_Seperating_hyperplan_theorem.png&quot; alt=&quot;[Fig1] Separating hyperplane theorem [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Separating hyperplane theorem [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The converse of the separating hyperplane theorem does not hold. That is, the existence of a separating hyperplane does not guarantee that the sets are disjoint. For example, if \(C = D = \{0\} \subseteq \mathbb{R}\), then \(x = 0\) separates \(C\) and \(D\).&lt;/p&gt;

&lt;h3 id=&quot;strict-separation&quot;&gt;Strict separation&lt;/h3&gt;

&lt;p&gt;If the separating hyperplane satisfies the stronger condition \(x \in C\) implies \(a^T x &amp;lt; b\) and \(x \in D\) implies \(a^T x &amp;gt; b\), this is called &lt;strong&gt;strict separation&lt;/strong&gt;. Disjoint closed convex sets do not always require strict separation, but in many cases, this condition holds.&lt;/p&gt;

&lt;h2 id=&quot;supporting-hyperplanes-theorem&quot;&gt;Supporting hyperplanes theorem&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;supporting hyperplane theorem&lt;/strong&gt; states that for any nonempty convex set \(C\) and any point \(x_0\) on the boundary &lt;strong&gt;bd&lt;/strong&gt; \(C\), there exists a supporting hyperplane at \(x_0\).&lt;/p&gt;

&lt;p&gt;What is a supporting hyperplane? Suppose \(x_0\) is a boundary point of \(C\). If for all \(x \in C\), \(a^T x \le a^T x_0\) (\(a \ne 0\)), then the hyperplane \(\{x \mid a^T x = a^T x_0 \}\) is a &lt;strong&gt;supporting hyperplane&lt;/strong&gt; for \(C\) at \(x_0\).&lt;/p&gt;

&lt;p&gt;[Note] The boundary is defined as \(x_0 \in\) &lt;strong&gt;bd&lt;/strong&gt; \(C =\) &lt;strong&gt;cl&lt;/strong&gt; \(C\) \(\setminus\) &lt;strong&gt;int&lt;/strong&gt; \(C\), i.e., the closure minus the interior.&lt;/p&gt;

&lt;p&gt;Geometrically, the supporting hyperplane \(\{x \mid a^T x = a^T x_0\}\) is tangent to \(C\) at \(x_0\) and the halfspace \(a^T x \le a^T x_0\) contains \(C\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.05_02_Supporting_hyperplane_theorem.png&quot; alt=&quot;[Fig 2] Supporting hyperplane [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 2] Supporting hyperplane [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

</content>
 </entry>
 
 <entry>
   <title>02-04 Generalized inequalities</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_04_Generalized_inequalities/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_04_Generalized_inequalities</id>
   <content type="html">&lt;p&gt;When buying a laptop, you want both &lt;em&gt;lower price&lt;/em&gt; and &lt;em&gt;longer battery life&lt;/em&gt;. Between Laptop A ($$1000$, 12h) and Laptop B ($$1200$, 16h), neither is strictly better in both dimensions—vector comparisons are only &lt;em&gt;partial&lt;/em&gt; orders! Proper cones formalize vector inequalities \(x \preceq_K y\) cleanly, explaining the crucial difference between a single utopian &lt;strong&gt;minimum&lt;/strong&gt; element and the trade-off frontier of &lt;strong&gt;minimal (Pareto-optimal)&lt;/strong&gt; elements.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-ordering-vectors-and-matrices-with-cones&quot;&gt;Key ideas: Ordering Vectors and Matrices with Cones&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Proper Cone (\(K\)):&lt;/strong&gt; A cone that is convex, closed, solid (nonempty interior), and pointed (contains no full line: \(K \cap (-K) = \{0\}\))—needed so \(\preceq_K\) behaves like a genuine partial order.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Generalized Inequality (\(x \preceq_K y \iff y - x \in K\)):&lt;/strong&gt; Unifies componentwise vector inequalities (\(K = \mathbb{R}_+^n\)) and Loewner matrix inequalities (\(K = \mathbb{S}_+^n\), where \(X \preceq Y \iff Y - X \succeq 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strict Inequality (\(x \prec_K y \iff y - x \in \text{int}(K)\)):&lt;/strong&gt; Requires \(K\) to be solid; for matrices, \(X \prec Y\) means \(Y - X\) is strictly positive definite.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimum vs. Minimal Elements:&lt;/strong&gt; A &lt;em&gt;minimum&lt;/em&gt; beats every other point in \(S\) (\(S \subseteq x + K\)); a &lt;em&gt;minimal&lt;/em&gt; (Pareto-optimal) point is merely undefeated by any other point in \(S\) (\((x - K) \cap S = \{x\}\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-minimum-vs-minimal-elements-under-mathbbr_2&quot;&gt;Worked example: Minimum vs. Minimal Elements Under \(\mathbb{R}_+^2\)&lt;/h3&gt;

&lt;p&gt;Consider four cost vectors (e.g., latency and energy) in \(\mathbb{R}^2\) ordered by \(K = \mathbb{R}_+^2\):
\(S = \{(1, 4),\; (2, 2),\; (3, 1),\; (3, 3)\}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test for dominated points:&lt;/strong&gt; Compare \((2, 2)\) and \((3, 3)\):
\((3, 3) - (2, 2) = (1, 1) \in \mathbb{R}_+^2 \implies (2, 2) \preceq_{\mathbb{R}_+^2} (3, 3).\)
Therefore \((3, 3)\) is strictly dominated and is &lt;strong&gt;not minimal&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the remaining three points pairwise:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\((1, 4) - (2, 2) = (-1, 2) \notin \mathbb{R}_+^2 \cup (-\mathbb{R}_+^2)\) (incomparable).&lt;/li&gt;
      &lt;li&gt;\((2, 2) - (3, 1) = (-1, 1) \notin \mathbb{R}_+^2 \cup (-\mathbb{R}_+^2)\) (incomparable).&lt;/li&gt;
      &lt;li&gt;\((1, 4) - (3, 1) = (-2, 3) \notin \mathbb{R}_+^2 \cup (-\mathbb{R}_+^2)\) (incomparable).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclude:&lt;/strong&gt; The set \(S\) has &lt;strong&gt;three minimal (Pareto-optimal) elements&lt;/strong&gt;—\((1, 4)\), \((2, 2)\), and \((3, 1)\)—and &lt;strong&gt;no minimum element&lt;/strong&gt;, because no single point dominates all others simultaneously.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In one-dimensional real space \(\mathbb{R}\), given two numbers 1 and 2, we can say 2 is greater than 1. But in \(n\)-dimensional real space \(\mathbb{R}^n\), given two points \(x_1\) and \(x_2\), can we say which is greater? This is not straightforward.&lt;/p&gt;

&lt;p&gt;This section introduces &lt;strong&gt;generalized inequalities&lt;/strong&gt; for comparing order between two points in \(\mathbb{R}^n\), and also discusses the concepts of minimum and minimal elements of a set.&lt;/p&gt;

&lt;h2 id=&quot;proper-cone&quot;&gt;Proper cone&lt;/h2&gt;

&lt;p&gt;A convex cone \(K \subseteq \mathbb{R}^n\) is called a &lt;strong&gt;proper cone&lt;/strong&gt; if it satisfies:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;K is closed (includes its boundary).&lt;/li&gt;
  &lt;li&gt;K is solid (its interior is nonempty).&lt;/li&gt;
  &lt;li&gt;K is pointed (does not contain any line) (i.e., \(x \in K, -x \in K \implies x = 0\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If a pointed &amp;amp; closed convex cone is defined in a subspace of dimension \(n-1\) or less, its interior is empty, since it cannot contain an open ball in \(n\) dimensions. Thus, it is not solid and cannot be a proper cone. For example, a 2D pie-shaped pointed &amp;amp; closed convex cone in \(\mathbb{R}^3\) is not a proper cone.&lt;/p&gt;

&lt;p&gt;See &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Interior_(topology)&quot;&gt;Wikipedia: Interior (topology)&lt;/a&gt;&lt;/em&gt; for the definition of interior.&lt;/p&gt;

&lt;h2 id=&quot;generalized-inequality&quot;&gt;Generalized inequality&lt;/h2&gt;

&lt;p&gt;Using a proper cone, we can define a partial ordering in \(\mathbb{R}^n\) called a &lt;strong&gt;generalized inequality&lt;/strong&gt;. It has properties similar to the standard ordering in \(\mathbb{R}\):&lt;/p&gt;

&lt;blockquote&gt;
\[x \preceq_{K} y \iff y − x \in K\]
&lt;/blockquote&gt;

&lt;p&gt;Similarly, strict partial ordering is defined as:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x \prec_{K} y \iff y − x \in\) &lt;strong&gt;int&lt;/strong&gt; \(K\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If \(K = \mathbb{R}_{+}\), then \(\preceq_{K}\) is the usual \(\le\) in \(\mathbb{R}\).&lt;/p&gt;

&lt;h3 id=&quot;properties-of-generalized-inequalities&quot;&gt;Properties of generalized inequalities&lt;/h3&gt;

&lt;p&gt;Generalized inequality \(\preceq_{K}\) satisfies:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Preserved under addition&lt;/strong&gt;: if \(x \preceq_{K} y\) and \(u \preceq_{K} v\), then \(x+u \preceq_{K} y +v\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Transitive&lt;/strong&gt;: if \(x \preceq_{K} y\) and \(y \preceq_{K} z\) then \(x \preceq_{K}  z\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preserved under nonnegative scaling&lt;/strong&gt;: if \(x \preceq_{K} y\) and \(α \ge 0\) then \(αx \preceq_{K} αy\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reflexive&lt;/strong&gt;: \(x \preceq_{K} x\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Antisymmetric&lt;/strong&gt;: if \(x \preceq_{K} y\) and \(y \preceq_{K} x\), then \(x = y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preserved under limits&lt;/strong&gt;: if \(x_i \preceq_{K}  y_i\) for \(i = 1, 2, ..., x_i \to x\) and \(y_i \to y\) as \(i \to ∞\), then \(x \preceq_{K} y\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Strict generalized inequalities have corresponding properties.&lt;/p&gt;

&lt;h2 id=&quot;minimum-and-minimal-elements&quot;&gt;Minimum and minimal elements&lt;/h2&gt;

&lt;p&gt;The most significant difference between ordering in \(\mathbb{R}\) and generalized ordering in \(\mathbb{R}^n\) is &lt;strong&gt;linear ordering&lt;/strong&gt;. In \(\mathbb{R}\), we can compare any two points with \(x \lt y\) or \(x \gt y\), but generalized inequality cannot always do this. Therefore, defining the concepts of maximum and minimum in the context of generalized inequality is expected to be much more complex.&lt;/p&gt;

&lt;h3 id=&quot;minimum-elements&quot;&gt;Minimum elements&lt;/h3&gt;

&lt;p&gt;If \(x \in S\) satisfies \(x \preceq_{K} y\) for all \(y \in S\), then \(x\) is a &lt;strong&gt;minimum&lt;/strong&gt; element of set \(S\). Similarly, &lt;strong&gt;maximum&lt;/strong&gt; can be defined in the same manner. If a minimum exists in a set, it is unique. That is, there exists only one minimum.&lt;/p&gt;

&lt;p&gt;If a point \(x \in S\) is the minimum of \(S\), then \(S \subseteq x + K\). Here, \(x + K\) means that (according to \(\preceq_{K}\)) all points are comparable with \(x\) and are greater than or equal to \(x\).&lt;/p&gt;

&lt;h3 id=&quot;minimal-elements&quot;&gt;Minimal elements&lt;/h3&gt;

&lt;p&gt;A similar concept is &lt;strong&gt;minimal&lt;/strong&gt;. If \(x \in S\) and for all \(y \in S\), the condition \(y \preceq_{K} x\) holds only when \(y=x\), then \(x\) is a &lt;strong&gt;minimal&lt;/strong&gt; element of set \(S\). Similarly, &lt;strong&gt;maximal&lt;/strong&gt; can be defined in the same manner. A set can have multiple minimal elements.&lt;/p&gt;

&lt;p&gt;If a point \(x \in S\) is minimal in \(S\), then \((x - K) \cap S = \{x\}\). Here, \(x - K\) means that (according to \(\preceq_{K}\)) all points are comparable with \(x\) and are less than or equal to \(x\).&lt;/p&gt;

&lt;p&gt;In the case of \(K = \mathbb{R}_{+}\), minimal and minimum are the same and correspond to the general definition of minimum.&lt;/p&gt;

&lt;h3 id=&quot;minimum-and-minimal-in-mathbbr2_-cone&quot;&gt;Minimum and minimal in \(\mathbb{R}^2_{+}\) cone&lt;/h3&gt;

&lt;p&gt;Consider the \(\mathbb{R}^2_{+}\) cone \(K\). The inequality \(x \preceq_{K} y\) means that \(y\) is to the upper right of \(x\). When \(x \in S\), saying that \(x\) is the minimum means that all points in \(S\) are to the upper right of \(x\). Saying that \(x\) is minimal means that there are no points in \(S\) to the lower left of \(x\).&lt;/p&gt;

&lt;p&gt;In the figure below, \(S_1\) has a minimum \(x_1\). The set \(x + K\) is shown in light gray, and since \(S_1 \subseteq x + K\), \(x_1\) is the minimum. \(S_2\) has a minimal element \(x_2\). The set \(x - K\) is shown in light gray, and since \((x - K) \cap S = \{x\}\), \(x_2\) is minimal.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_01_Minimum_and_minimal.png&quot; alt=&quot;[Fig1] Minimum and minimal elements [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Minimum and minimal elements [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

</content>
 </entry>
 
 <entry>
   <title>02-03 Operations that preserve convexity of convex set</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_03_Operations_that_preserve_convexity/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_03_Operations_that_preserve_convexity</id>
   <content type="html">&lt;p&gt;Checking the line-segment definition \(\theta x + (1-\theta)y \in C\) directly on a messy feasible region with 50 constraints is tedious and error-prone. Instead, convex analysts use a compositional calculus: start from simple convex building blocks (halfspaces, balls, cones) and apply operations guaranteed to preserve convexity—intersection, affine maps, perspective maps, and linear-fractional maps—to certify convexity in two lines.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-calculus-of-convex-sets&quot;&gt;Key ideas: The Calculus of Convex Sets&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Arbitrary Intersections:&lt;/strong&gt; If every \(S_\alpha\) is convex (even uncountably many!), \(\bigcap_\alpha S_\alpha\) is convex—this single rule proves polyhedra, \(\mathbb{S}_+^n\), and robust uncertainty constraints are convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine Images &amp;amp; Preimages:&lt;/strong&gt; If \(S\) is convex and \(f(x) = Ax + b\) is affine, both the image \(f(S)\) (scaling, rotation, translation, projection) and inverse image \(f^{-1}(S)\) are convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minkowski Sums &amp;amp; Direct Products:&lt;/strong&gt; Sums \(S_1 + S_2\) and Cartesian products \(S_1 \times S_2\) of convex sets stay convex, letting us combine independent constraint blocks cleanly.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Perspective &amp;amp; Linear-Fractional Functions:&lt;/strong&gt; \(P(z, t) = z/t\) (for \(t &amp;gt; 0\)) and compositions \(x \mapsto \frac{Ax + b}{c^T x + d}\) (for \(c^T x + d &amp;gt; 0\)) preserve convexity of both images and preimages—key to geometric and fractional programming.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-affine-image-and-perspective-map-on-simple-convex-sets&quot;&gt;Worked example: Affine Image and Perspective Map on Simple Convex Sets&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Affine image of the unit square \(S = [0, 1]^2\):&lt;/strong&gt; Apply \(f(x) = Ax + b\) with
\(A = \begin{pmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 3 \end{pmatrix}, \qquad b = \begin{pmatrix} 1 \\ -1 \end{pmatrix}.\)
Evaluate \(f\) on the four vertices of \(S\):
    &lt;ul&gt;
      &lt;li&gt;\(f(0, 0) = (1, -1)^T\), \(f(1, 0) = (3, -1)^T\), \(f(0, 1) = (2, 2)^T\), \(f(1, 1) = (4, 2)^T\).
Because affine maps preserve convex combinations, \(f(S)\) is the convex parallelogram spanned by these four vertices. Check the midpoint \((0.5, 0.5)^T \in S\): \(f(0.5, 0.5) = (2.5, 0.5)^T\), which equals the average of all four image vertices.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Perspective normalization:&lt;/strong&gt; Apply \(P(z, t) = z/t\) (\(t &amp;gt; 0\)) to the ray point \((z_1, z_2, t) = (2, 4, 2)\) in \(\mathbb{R}^2 \times \mathbb{R}_{++}\):
\(P(2, 4, 2) = \left(\frac{2}{2}, \frac{4}{2}\right) = (1, 2).\)
Scaling the input to \((6, 12, 6)\) maps to the exact same normalized point \((1, 2)\), illustrating how perspective projects cones cleanly onto convex slices.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section discusses operations that preserve the convexity of convex sets. These operations are useful for determining convexity or constructing desired convex sets from simple ones like hyperplanes, halfspaces, and norm balls.&lt;/p&gt;

&lt;p&gt;Operations that preserve convexity include:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Intersection&lt;/li&gt;
  &lt;li&gt;Affine functions&lt;/li&gt;
  &lt;li&gt;Perspective function&lt;/li&gt;
  &lt;li&gt;Linear-fractional functions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;intersection&quot;&gt;Intersection&lt;/h2&gt;

&lt;p&gt;The intersection of convex sets is convex. That is, if \(S_1\) and \(S_2\) are convex, then \(S_1 \cap S_2\) is convex. This property holds even for infinitely many sets. (Subspaces, affine sets, and convex cones are also closed under intersection.)&lt;/p&gt;

&lt;p&gt;Convexity can be expressed as the intersection of infinitely many halfspaces, and the converse also holds. That is, a closed convex set \(S\) can be defined as the intersection of all halfspaces containing \(S\):&lt;/p&gt;

&lt;blockquote&gt;
\[S = \bigcap \{\mathcal{H} \mid \mathcal{H} \text{ halfspace }, S \subseteq \mathcal{H}\}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;affine-functions&quot;&gt;Affine functions&lt;/h2&gt;

&lt;p&gt;Let \(A \in \mathbb{R}^{m \times n}\) and \(b \in \mathbb{R}^{m}\). The function \(f : \mathbb{R}^n \to \mathbb{R}^m\) defined by \(f(x) = Ax + b\) is called an affine function.&lt;/p&gt;

&lt;p&gt;If \(C \subseteq \mathbb{R}^n\) is convex and \(D \subseteq \mathbb{R}^m\) is convex, then:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The affine image \(f(C) = \{f(x) \mid x \in C\}\) is convex.&lt;/li&gt;
  &lt;li&gt;The affine preimage \(f^{-1}(D) = \{x \mid f(x) \in D\}\) is convex.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Applying affine functions such as scaling and translation, projection, sum of two sets, and partial sum to convex sets results in convex sets.&lt;/p&gt;

&lt;p&gt;The solution set of a linear matrix inequality \(\{x \mid x_1 A_1 + \cdots + x_m A_m \preceq B\}\) (with \(A_i, B \in S^n\)) is also convex.&lt;/p&gt;

&lt;p&gt;A hyperbolic cone \(\{x \mid x^T P x &amp;lt; (c^T x)^2, c^T x &amp;gt; 0\}\) (with \(P \subseteq S^n_+\), \(c \in \mathbb{R}^n\)) is also convex.&lt;/p&gt;

&lt;h2 id=&quot;perspective-function&quot;&gt;Perspective function&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;perspective function&lt;/strong&gt; models how objects appear smaller when farther away and larger when closer, similar to how a camera projects images. The object is in \(\mathbb{R}^{n+1}\) and its image is in \(\mathbb{R}^n\).&lt;/p&gt;

&lt;p&gt;The perspective function is defined as \(P : \mathbb{R}^{n+1} \to \mathbb{R}^{n}\) with &lt;strong&gt;dom&lt;/strong&gt; \(P = \mathbb{R}^{n} \times \mathbb{R}_{++}\) and \(P(z,t) = z/t\), where \(\mathbb{R}_{++} = \{x \in \mathbb{R} \mid x &amp;gt; 0\}\). This function normalizes the last coordinate to 1 and drops it, reducing the dimension from \(\mathbb{R}^{n+1}\) to \(\mathbb{R}^n\). If \(C \subseteq\) &lt;strong&gt;dom&lt;/strong&gt; \(P\) is convex, then the image \(P(C) = \{P(x) \mid x \in C\}\) is also convex.&lt;/p&gt;

&lt;p&gt;The perspective function works like a pinhole camera: objects farther from the pinhole are projected smaller. The figure below illustrates this principle, showing that objects within the same captured ray are projected identically.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-02 Some important examples</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_02_Some_important_examples/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_02_Some_important_examples</id>
   <content type="html">&lt;p&gt;Just as a chemist learns the periodic table before synthesizing new molecules, an optimization practitioner memorizes a compact catalog of canonical convex sets. Almost every real-world feasible region—whether it is a probability distribution over classes, an uncertainty ellipsoid around a noisy forecast, or a covariance matrix constraint—is built directly from these standard shapes.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-essential-catalog-of-convex-sets&quot;&gt;Key ideas: The Essential Catalog of Convex Sets&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Linear &amp;amp; Polyhedral Shapes:&lt;/strong&gt; Hyperplanes, halfspaces, polyhedra (\(Ax \preceq b, Cx = d\)), and probability simplexes—the geometry of linear programming and categorical probabilities.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Norm-Induced &amp;amp; Ellipsoidal Shapes:&lt;/strong&gt; Euclidean balls, \(\ell_1/\ell_\infty\) norm balls, and ellipsoids—central to regularization (Lasso vs. Ridge) and robust uncertainty sets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic Shapes:&lt;/strong&gt; Norm cones (second-order / Lorentz cones), normal cones, and positive semidefinite cones \(\mathbb{S}_+^n\)—the backbone of SOCP and SDP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recognizing Structure Fast:&lt;/strong&gt; Identifying which canonical set a constraint matches immediately tells you which solver class (LP, QP, SOCP, SDP) can handle it natively.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-testing-one-vector-across-three-canonical-convex-sets&quot;&gt;Worked example: Testing One Vector Across Three Canonical Convex Sets&lt;/h3&gt;

&lt;p&gt;Test the point \(x = (0.6, 0.4)^T \in \mathbb{R}^2\) against three fundamental convex sets:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Probability simplex \(\Delta_2 = \{x \in \mathbb{R}^2 : x_1 + x_2 = 1,\; x_1, x_2 \ge 0\}\):&lt;/strong&gt;
Both coordinates are nonnegative and \(0.6 + 0.4 = 1\), so \(x \in \Delta_2\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Unit \(\ell_1\) norm ball $$B_1 = {x :&lt;/td&gt;
          &lt;td&gt;x_1&lt;/td&gt;
          &lt;td&gt;+&lt;/td&gt;
          &lt;td&gt;x_2&lt;/td&gt;
          &lt;td&gt;\le 1}$$:**&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;$$|x|_1 =&lt;/td&gt;
          &lt;td&gt;0.6&lt;/td&gt;
          &lt;td&gt;+&lt;/td&gt;
          &lt;td&gt;0.4&lt;/td&gt;
          &lt;td&gt;= 1.0 \le 1\(, so\)x\(lies exactly on the boundary of\)B_1$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unit \(\ell_2\) Euclidean ball \(B_2 = \{x : \|x\|_2 \le 1\}\):&lt;/strong&gt;
\(\|x\|_2 = \sqrt{0.6^2 + 0.4^2} = \sqrt{0.36 + 0.16} = \sqrt{0.52} \approx 0.7211 &amp;lt; 1\), so \(x\) lies strictly in the interior of \(B_2\) (reflecting the geometric inclusion \(B_1 \subset B_2\)).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section reviews major examples of convex sets.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Trivial ones: empty set, point, line, line segment, ray&lt;/li&gt;
  &lt;li&gt;Hyperplane: \(\{x : a^T x = b\}\), for given \(a, b\), \(a \ne 0\)&lt;/li&gt;
  &lt;li&gt;Halfspace: \(\{x : a^T x \le b \}\) for \(a \ne 0\)&lt;/li&gt;
  &lt;li&gt;Affine space: \(\{x : Ax = b\}\), for given \(A, b\)&lt;/li&gt;
  &lt;li&gt;Euclidean ball &amp;amp; ellipsoid&lt;/li&gt;
  &lt;li&gt;Norm ball: \(\{x : \| x \| \le r\}\), for given norm \(\|·\|\), radius \(r\)&lt;/li&gt;
  &lt;li&gt;Convex cone: norm cone, normal cone, positive semidefinite cone&lt;/li&gt;
&lt;/ul&gt;

</content>
 </entry>
 
 <entry>
   <title>02-02-02 Convex Cone examples</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_02_02_Convex_cone_examples/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_02_02_Convex_cone_examples</id>
   <content type="html">&lt;p&gt;When an engineer constrains a robust antenna beamformer or a statistician estimates a valid covariance matrix, scalar inequalities like \(x \ge 0\) are no longer enough. Convex cones generalize nonnegativity to vectors and matrices: the second-order (norm) cone constrains Euclidean magnitudes, the normal cone captures all outward-pointing optimality directions at a boundary point, and the positive semidefinite cone \(\mathbb{S}_+^n\) constrains symmetric matrices to have nonnegative eigenvalues.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-big-three-convex-cones&quot;&gt;Key ideas: The Big Three Convex Cones&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Norm Cone (Second-Order / Lorentz Cone):&lt;/strong&gt; \(C = \{(x, t) \in \mathbb{R}^{n+1} : \|x\| \le t\}\) turns norm constraints into conic form, powering SOCP formulations for robust regression and portfolio risk.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Normal Cone (\(N_C(x)\)):&lt;/strong&gt; Collects all vectors \(g\) making an obtuse angle with feasible directions at \(x \in C\) (\(g^T(y - x) \le 0\) for all \(y \in C\)); optimality of a smooth convex problem is simply \(-\nabla f(x^*) \in N_C(x^*)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Positive Semidefinite Cone (\(\mathbb{S}_+^n\)):&lt;/strong&gt; \(\{X \in \mathbb{S}^n : z^T X z \ge 0 \;\forall z \in \mathbb{R}^n\}\) is an intersection of infinitely many linear halfspaces in \(X\), proving immediately that \(\mathbb{S}_+^n\) is a closed convex cone.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic Hierarchy:&lt;/strong&gt; \(\text{LP } (\mathbb{R}_+^n) \subset \text{SOCP } (\text{Lorentz cone}) \subset \text{SDP } (\mathbb{S}_+^n)\)—each cone unlocks richer modeling power while staying polynomial-time solvable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-membership-and-convexity-in-the-psd-cone-mathbbs_2&quot;&gt;Worked example: Membership and Convexity in the PSD Cone \(\mathbb{S}_+^2\)&lt;/h3&gt;

&lt;p&gt;Test two symmetric \(2 \times 2\) matrices:
\(A = \begin{pmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{pmatrix}, \qquad B = \begin{pmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{pmatrix}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check \(A \in \mathbb{S}_+^2\):&lt;/strong&gt; Trace \(= 2 + 2 = 4 &amp;gt; 0\) and determinant \(= 2(2) - 1^2 = 3 &amp;gt; 0\) (eigenvalues \(\lambda_1 = 3, \lambda_2 = 1\)). Since both eigenvalues are \(\ge 0\), \(A \in \mathbb{S}_+^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check \(B \in \mathbb{S}_+^2\):&lt;/strong&gt; Determinant \(= 1(1) - 2^2 = -3 &amp;lt; 0\) (eigenvalues \(3\) and \(-1\)). Picking \(z = (1, -1)^T\) gives \(z^T B z = 1 - 4 + 1 = -2 &amp;lt; 0\), so \(B \notin \mathbb{S}_+^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify convex combination closure inside \(\mathbb{S}_+^2\):&lt;/strong&gt; Combine \(A \in \mathbb{S}_+^2\) with \(C = \begin{pmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{pmatrix} \in \mathbb{S}_+^2\) at \(\theta = 0.5\):
\(M = 0.5 A + 0.5 C = \begin{pmatrix} 3 &amp;amp; 0.5 \\ 0.5 &amp;amp; 1 \end{pmatrix}.\)
Its trace is \(4 &amp;gt; 0\) and determinant is \(3(1) - 0.25 = 2.75 &amp;gt; 0\), confirming \(M \in \mathbb{S}_+^2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Examples of convex cones include the norm cone, normal cone, and positive semidefinite cone.&lt;/p&gt;

&lt;h2 id=&quot;norm-cone&quot;&gt;Norm cone&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;norm cone&lt;/strong&gt; is a cone defined by all points \((x, t)\) such that \(\| x \| \le t\) in \(\mathbb{R}^{n+1}\), where the norm can be arbitrary.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(C = \{(x, t) : \| x \| \le t\} \subseteq \mathbb{R}^{n+1}\), for a norm \(\|·\|\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The figure below shows the norm cone for the \(l_2\) norm \(\|·\|_2\), also called the second-order cone or ice cream cone.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.08_Norm_Cone.png&quot; alt=&quot;[Fig1] Norm Cone [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Norm Cone [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;normal-cone&quot;&gt;Normal Cone&lt;/h2&gt;

&lt;p&gt;For a set \(C\) and a point \(x \in C\), the &lt;strong&gt;normal cone&lt;/strong&gt; is defined as:&lt;/p&gt;

&lt;blockquote&gt;
\[N_C(x) = \{ g: g^T (y - x) \le 0, \text{ for all } y \in C \}\]
&lt;/blockquote&gt;

&lt;p&gt;The normal cone consists of all vectors \(g\) such that the inner product with \(y-x\) is always less than or equal to zero for all \(y \in C\). This means the angle between \(g\) and \(y-x\) is between 90 and 270 degrees (i.e., \(\cos\theta &amp;lt; 0\)).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If \(x\) is on the boundary, the only \(g\) is the normal of the supporting hyperplane.&lt;/li&gt;
  &lt;li&gt;If \(x\) is a vertex, there are multiple supporting hyperplanes, so \(g\) forms a pie shape.&lt;/li&gt;
  &lt;li&gt;If \(x\) is in the interior, the only \(g\) is the zero vector.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The figure below shows the normal vector.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.04_2_Normal_Cone.png&quot; alt=&quot;[Fig2] Normal Cone [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Normal Cone [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;positive-semidefinite-cone&quot;&gt;Positive semidefinite cone&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;positive semidefinite cone&lt;/strong&gt; \(\mathbb{S}^n_+\) is defined as follows, where \(\mathbb{S}^n\) represents \(n \times n\) symmetric matrices:&lt;/p&gt;

&lt;blockquote&gt;
\[\mathbb{S}^n_+ = \{ X \in \mathbb{S}^n : X \succeq 0 \}\]
&lt;/blockquote&gt;

&lt;p&gt;\(\mathbb{S}^n_+\) is a convex cone because for \(\theta_1, \theta_2 \ge 0\) and \(A, B \in \mathbb{S}^n_+\), we have \(\theta_1 A + \theta_2 B \in \mathbb{S}^n_+\). This is called the &lt;strong&gt;positive semidefinite cone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The following figure shows the boundary of the positive semidefinite cone in \(\mathbb{S}^2_+\) plotted in \((x, y, z) \in \mathbb{R}^3\). Since matrix \(X\) is positive semidefinite, its determinant must be non-negative.&lt;/p&gt;

\[X = 
\begin{bmatrix}
x, y \\\
y, z
\end{bmatrix}
\in \mathbb{S}^2_+ \iff x \ge 0, z \ge 0, xz \ge y^2\]

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.10_Positive_Semidefinite_Cone.png&quot; alt=&quot;[Fig3] Positive semidefinite cone [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig3] Positive semidefinite cone [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

</content>
 </entry>
 
 <entry>
   <title>02-02-01 Convex set examples</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_02_01_Convex_sets_examples/"/>
   <updated>2021-02-11T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_02_01_Convex_sets_examples</id>
   <content type="html">&lt;p&gt;Why does \(\ell_1\) regularization produce sparse models with exact zeros while \(\ell_2\) regularization shrinks weights smoothly without zeroing them out? The answer is purely geometric: the \(\ell_1\) norm ball is a sharp-cornered diamond (a polyhedron), whereas the \(\ell_2\) ball is a smooth sphere and an ellipsoid is a stretched sphere. Mastering the equations and geometry of halfspaces, balls, ellipsoids, polyhedra, and simplexes makes regularization and constraint geometry transparent.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-canonical-convex-sets-in-practice&quot;&gt;Key ideas: Canonical Convex Sets in Practice&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Halfspaces &amp;amp; Polyhedra:&lt;/strong&gt; A halfspace \(\{x : a^T x \le b\}\) is convex; intersecting finitely many halfspaces and hyperplanes yields a polyhedron \(\{x : Ax \preceq b, Cx = d\}\) (the feasible set of every LP).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Euclidean &amp;amp; General Norm Balls:&lt;/strong&gt; \(\{x : \|x - x_c\| \le r\}\) is convex for &lt;em&gt;any&lt;/em&gt; norm via homogeneity and the triangle inequality; changing the norm reshapes the boundary from diamond (\(\ell_1\)) to sphere (\(\ell_2\)) to box (\(\ell_\infty\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ellipsoids:&lt;/strong&gt; \(\mathcal{E} = \{x : (x - x_c)^T P^{-1}(x - x_c) \le 1\}\) with \(P \succ 0\) captures correlated confidence regions; the square roots of \(P\)’s eigenvalues give the exact semi-axis lengths.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simplexes:&lt;/strong&gt; The convex hull of \(k + 1\) affinely independent points; the unit probability simplex \(\Delta_n\) is the natural domain of discrete probability distributions and portfolio allocations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-semi-axes-and-membership-of-a-2d-ellipsoid&quot;&gt;Worked example: Semi-Axes and Membership of a 2D Ellipsoid&lt;/h3&gt;

&lt;p&gt;Consider the ellipsoid \(\mathcal{E} = \{x \in \mathbb{R}^2 : (x - x_c)^T P^{-1}(x - x_c) \le 1\}\) centered at \(x_c = (1, -1)^T\) with shape matrix \(P = \begin{pmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 9 \end{pmatrix}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Read off the semi-axis lengths from \(P\):&lt;/strong&gt; Since \(P\) is diagonal with eigenvalues \(\lambda_1 = 4\) and \(\lambda_2 = 9\), the semi-axes align with the coordinate axes and have lengths \(\sqrt{4} = 2\) (horizontal) and \(\sqrt{9} = 3\) (vertical).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write the explicit quadratic inequality:&lt;/strong&gt; With \(P^{-1} = \text{diag}(1/4, 1/9)\),
\(\frac{(x_1 - 1)^2}{4} + \frac{(x_2 + 1)^2}{9} \le 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the candidate point \(x = (2, 1)^T\):&lt;/strong&gt;
\(\frac{(2 - 1)^2}{4} + \frac{(1 + 1)^2}{9} = \frac{1}{4} + \frac{4}{9} = \frac{9 + 16}{36} = \frac{25}{36} \approx 0.6944 &amp;lt; 1.\)
Therefore \((2, 1)^T\) lies strictly in the interior of \(\mathcal{E}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Convex sets include a variety of forms, from trivial ones like points and lines to hyperplanes, halfspaces, balls, ellipsoids, polyhedra, and cones.&lt;/p&gt;

&lt;h2 id=&quot;hyperplanes&quot;&gt;Hyperplanes&lt;/h2&gt;

&lt;p&gt;A hyperplane is an \((n-1)\)-dimensional subset that divides an \(n\)-dimensional space in half, defined as follows. Here, \(a\) is the normal vector and \(b\) is the offset from the origin. A hyperplane is both a convex set and an affine set.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;{\(x : a^T x = b\)} with \(a \in \mathbb{R}^n, a \ne 0, b \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the figure below, any \(x\) on the hyperplane satisfies that \((x - x_0)\) is orthogonal to \(a\). Thus, \(a^T (x - x_0) = 0\), so if \(a^T x = b\), then \(b = a^T x_0\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.05_Hyperplane.png&quot; alt=&quot;[Fig1] Hyperplane [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Hyperplane [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;halfspaces&quot;&gt;Halfspaces&lt;/h2&gt;

&lt;p&gt;A halfspace is one side of a space divided by a hyperplane. Thus, a single hyperplane \(a^T x = b\) defines two halfspaces. A halfspace is a convex set but not an affine set.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;{\(x : a^T x \le b\)} or {\(x : a^T x \ge b\)}  with \(a \in \mathbb{R}^n, a \ne 0, b \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For the hyperplane \(a^T x = b\), the halfspace \(a^T x \ge b\) is in the direction of the normal vector \(a\), while \(a^T x \le b\) is in the direction of \(-a\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.06_Halfspace.png&quot; alt=&quot;[Fig2] Halfspace [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Halfspace [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Note: The interior of \(\{x : a^T x \le b\}\), that is \(\{x : a^T x \lt b\}\), is called an open halfspace.&lt;/p&gt;

&lt;h3 id=&quot;key-property-halfspaces-are-convex&quot;&gt;Key Property: Halfspaces are Convex&lt;/h3&gt;

&lt;p&gt;Take any two points $x_1$ and $x_2$ in the halfspace:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Both satisfy: $a^T x_1 \leq b$ and $a^T x_2 \leq b$&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For any convex combination: $x_\theta = \theta x_1 + (1 - \theta)x_2$ where $\theta \in [0, 1]$&lt;/p&gt;

&lt;p&gt;Check if this point is in the halfspace:
\(a^T x_\theta = a^T(\theta x_1 + (1 - \theta)x_2) = \theta(a^T x_1) + (1 - \theta)(a^T x_2) \leq \theta b + (1 - \theta)b = b\)&lt;/p&gt;

&lt;p&gt;Since $x_\theta$ satisfies the inequality, all points between $x_1$ and $x_2$ are in the halfspace → halfspace is convex.&lt;/p&gt;

&lt;h2 id=&quot;euclidean-balls&quot;&gt;Euclidean balls&lt;/h2&gt;

&lt;p&gt;A Euclidean ball is another convex set, defined as follows. (\(\| . \|_2\) is the Euclidean norm, \(\|u\|_2 = (u^T u)^{1/2}\).) \(x_c\) is the center and \(r\) is the radius. Thus, \(B(x_c, r)\) contains all points within radius \(r\) from center \(x_c\).&lt;/p&gt;

&lt;blockquote&gt;
\[B(x_c, r) = \{ x \mid \|x - x_c \|_2 \le r \} = \{ x \mid (x - x_c)^T (x - x_c) \le r^2 \} \text{ with } r \ge 0\]
&lt;/blockquote&gt;

&lt;p&gt;Alternatively, the Euclidean ball can be expressed as:&lt;/p&gt;

&lt;blockquote&gt;
\[B(x_c, r) = \{ x_c + ru \mid \| u \|_2 \le 1 \}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;ellipsoids&quot;&gt;Ellipsoids&lt;/h2&gt;

&lt;p&gt;An ellipsoid is a convex set related to the Euclidean ball, defined as:&lt;/p&gt;

&lt;blockquote&gt;
\[\mathcal{E} = \{x \mid (x - x_c)^T P^{-1} (x - x_c) \le 1 \}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(P = P^T \succ 0\) means \(P\) is symmetric and positive definite. The vector \(x_c\) is the center of the ellipsoid, and the matrix \(P\) determines how far the ellipsoid extends in each direction from the center. The axes of the ellipsoid are \(\sqrt{\lambda_i}\), where \(\lambda_i\) are the eigenvalues of \(P\). Thus, a ball is a special case of an ellipsoid with \(P = r^2 I\).&lt;/p&gt;

&lt;p&gt;The figure below shows an ellipsoid. The center \(x_c\) is a point, and the major and minor axes are drawn as line segments.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.07_Ellipsoid.png&quot; alt=&quot;[Fig3] Ellipsoid [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig3] Ellipsoid [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The ellipsoid can also be expressed as:&lt;/p&gt;

&lt;blockquote&gt;
\[\mathcal{E} = \{ x_c + Au \mid \|u\|_2 \le 1 \}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(A\) is a square nonsingular matrix. If \(A = P^{1/2}\), the expression matches the previous one, and \(A\) is symmetric and positive definite. If \(A\) is symmetric positive semidefinite and singular, it is called a degenerate ellipsoid, and its affine dimension equals the rank of \(A\). A degenerate ellipsoid is still convex.&lt;/p&gt;

&lt;h2 id=&quot;norm-balls&quot;&gt;Norm balls&lt;/h2&gt;

&lt;p&gt;A norm ball is the set of points within radius \(r\) from center \(x_c\), defined using an arbitrary norm. While a Euclidean ball uses the Euclidean norm, a norm ball can use any norm. If \(\|.\|\) is any norm on \(\mathbb{R}^n\), the norm ball is defined as:&lt;/p&gt;

&lt;blockquote&gt;
\[\{ x \mid \|x - x_c \| \le r  \}\]
&lt;/blockquote&gt;

&lt;p&gt;When the p-norm is defined as:&lt;/p&gt;

&lt;blockquote&gt;
\[\| x  \|_{p} = \left( \sum_{i=0}^n |x_i|^{p} \right)^{1/p} \text{ for  } p \ge 1\]
&lt;/blockquote&gt;

&lt;p&gt;The shape of the norm ball depends on the value of \(p\). The figure below shows the shape of the norm ball in 3D for different values of \(p\). The norm ball is convex if \(p \ge 1\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.07_2_norm_ball.png&quot; alt=&quot;[Fig4] Norm ball [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig4] Norm ball [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The next figure shows the shape of the norm ball in 2D for different values of \(p\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.07_3_norm_ball2.png&quot; alt=&quot;[Fig4] Norm ball [2]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig4] Norm ball [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;polyhedra&quot;&gt;Polyhedra&lt;/h2&gt;

&lt;p&gt;A polyhedron is defined as the intersection of linear inequalities and equalities. Affine sets (subspaces, hyperplanes, lines), rays, line segments, and halfspaces are all polyhedra. Polyhedra are convex sets, and a bounded polyhedron is called a polytope.&lt;/p&gt;

&lt;blockquote&gt;
\[\mathcal{P} = \{ x \mid a^T_i x \le b_i, i = 1, ..., m, c_j^Tx  = d_j, j = 1, ..., p\}\]
&lt;/blockquote&gt;

&lt;p&gt;A single equality \(c_j^Tx  = d_j\) can be represented by two inequalities \(c^T_jx \le d_j\) and \(c^T_jx \ge d_j\). Thus, polyhedra can be defined using only inequalities.&lt;/p&gt;

&lt;p&gt;The figure below shows a pentagonal polyhedron formed by the intersection of five halfspaces, with outward normal vectors \(a_1, ..., a_5\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.09_Polyhedra.png&quot; alt=&quot;[Fig5] Polyhedra [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig5] Polyhedra [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;In matrix form, a polyhedron can be defined as:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\mathcal{P} =  \{ x \mid A^Tx \preceq b, C^Tx  = d \}\)
where
\(A = 
\begin{bmatrix}
a^T_1 \\
\vdots \\
a^T_m
\end{bmatrix},\)
\(C = 
\begin{bmatrix}
c^T_1 \\
\vdots \\
c^T_p
\end{bmatrix}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;simplexes&quot;&gt;Simplexes&lt;/h3&gt;

&lt;p&gt;A simplex is the simplest polygon that can be formed in \(n\)-dimensional space, constructed from \(n+1\) points.&lt;/p&gt;

&lt;p&gt;If there are \(k + 1\) points \(v_0, ..., v_k \in \mathbb{R}^n\) that are affinely independent, the simplex is defined as the convex hull of these \(k+1\) points. Affinely independent means \(v_1 − v_0, ..., v_k − v_0\) are linearly independent.&lt;/p&gt;

&lt;blockquote&gt;
\[C = \mathbb{conv} \{v_0, ... , v_k\} = \{ \theta_0 v_0 + \cdots + \theta_k v_k  \mid \theta \succeq 0, 1^T \theta = 1 \}\]
&lt;/blockquote&gt;

&lt;p&gt;The figure below shows simplexes from 0 to 3 dimensions: a point in 0D, a line segment in 1D, a triangle in 2D, and a tetrahedron in 3D.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.02_10_Simplex.png&quot; alt=&quot;[Fig6] Simplex [source - wikipedia]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig6] Simplex [source - wikipedia]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;A common example of a simplex is the probability simplex:&lt;/p&gt;

&lt;blockquote&gt;
\[C = \mathbb{conv} \{e_1, ..., e_n \} = \{ \theta \mid \theta \succeq 0, 1^T \theta = 1\}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>05-10 Bài Tập Thực Hành - Các Bài Toán Chuẩn</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_10_Practical_Exercises_Canonical_Problems/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_10_Practical_Exercises_Canonical_Problems</id>
   <content type="html">&lt;p&gt;Trên giấy, các bài toán chuẩn LP, QP, QCQP, SOCP, SDP trông giống những khuôn mẫu toán học trừu tượng. Nhưng ngay khi bạn bước vào bộ bài tập thực hành này — từ bài toán lập thực đơn dinh dưỡng tối ưu chi phí (Diet Problem), bài toán phân bổ danh mục đầu tư Markowitz, cho đến thiết kế tối ưu bền vững bằng SOCP — bạn sẽ thấy mỗi lớp bài toán chuẩn chính là một “vũ khí chuyên dụng” giải quyết trực tiếp bài toán thật của thế giới công nghiệp.&lt;/p&gt;

&lt;p&gt;Mục tiêu của buổi thực hành này không chỉ là bấm chạy ra con số cuối cùng, mà là rèn kỹ năng &lt;strong&gt;chuyển dịch hai chiều&lt;/strong&gt;: từ mô tả bằng lời sang công thức toán học chuẩn, và từ nghiệm số quay ngược lại diễn giải ý nghĩa kinh tế/kỹ thuật của từng biến và ràng buộc tích cực.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-kỹ-năng-thực-chiến-khi-mô-hình-hóa-bài-toán-chuẩn&quot;&gt;Kiến thức cần nhớ: Bốn kỹ năng thực chiến khi mô hình hóa bài toán chuẩn&lt;/h2&gt;

&lt;p&gt;Khi tự tay giải các bài tập trong bộ này (bằng tay hoặc bằng CVXPY/Python), hãy kiểm tra bốn tiêu chí sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa biến quyết định &amp;amp; Đơn vị rõ ràng:&lt;/strong&gt; Mọi sai sót mô hình hóa thường bắt nguồn từ việc trộn lẫn đơn vị (ví dụ lợi nhuận theo % năm nhưng rủi ro theo phương sai ngày, hoặc quên điều kiện không âm \(x \ge 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn đúng lớp chuẩn &amp;amp; Kiểm tra ma trận \(Q \succeq 0\):&lt;/strong&gt; Trước khi nạp ma trận hiệp phương sai \(\Sigma\) vào QP, luôn kiểm tra tính đối xứng và trị riêng không âm (tránh lỗi số học nhỏ như \(\lambda_{\min} = -10^{-16}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kỹ thuật Epigraph &amp;amp; Biến phụ để tuyến tính hóa:&lt;/strong&gt; Biết cách chuyển \(\min \|x\|_1\) thành \(\min \mathbf{1}^T t \text{ s.t. } -t \le x \le t\) (LP) và chuyển ràng buộc bất định ellipsoid thành chuẩn \(\ell_2\) (SOCP).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hậu kiểm nghiệm (Sanity Check):&lt;/strong&gt; Luôn kiểm tra lại ba thứ sau khi giải: (1) nghiệm có thỏa mọi ràng buộc với dung sai \(10^{-6}\) không? (2) ràng buộc nào tích cực? (3) kết quả có hợp lý về mặt vật lý/kinh tế không?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-một-bài-toán-khẩu-phần-ăn-diet-problem-2-thực-phẩm&quot;&gt;Giải thích: Giải tay một bài toán Khẩu phần ăn (Diet Problem) 2 thực phẩm&lt;/h3&gt;

&lt;p&gt;Một người cần ít nhất \(10\) đơn vị protein và \(12\) đơn vị vitamin mỗi ngày từ 2 loại thực phẩm:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Thực phẩm A: giá \(2\) USD/phần, chứa \(2\) protein và \(1\) vitamin.&lt;/li&gt;
  &lt;li&gt;Thực phẩm B: giá \(3\) USD/phần, chứa \(1\) protein và \(3\) vitamin.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Lập mô hình LP:&lt;/strong&gt; Gọi \(x_1, x_2 \ge 0\) là số phần A và B.
\(\min_{x_1, x_2 \ge 0} \; 2x_1 + 3x_2 \quad \text{s.t.} \quad \begin{cases} 2x_1 + x_2 \ge 10 \\ x_1 + 3x_2 \ge 12 \end{cases}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Xác định các đỉnh của vùng khả thi (không bị chặn phía trên):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giao \(2x_1 + x_2 = 10\) và \(x_1 = 0\): \((0, 10)\) — kiểm tra \(0 + 30 = 30 \ge 12\) (khả thi), chi phí \(= 30\) USD.&lt;/li&gt;
      &lt;li&gt;Giao \(x_1 + 3x_2 = 12\) và \(x_2 = 0\): \((12, 0)\) — kiểm tra \(24 + 0 = 24 \ge 10\) (khả thi), chi phí \(= 24\) USD.&lt;/li&gt;
      &lt;li&gt;Giao hai đường thẳng \(2x_1 + x_2 = 10\) và \(x_1 + 3x_2 = 12\):
Nhân phương trình 2 với 2: \(2x_1 + 6x_2 = 24\). Trừ phương trình 1: \(5x_2 = 14 \implies x_2^\star = 2.8\), suy ra \(x_1^\star = 12 - 3(2.8) = 3.6\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Tính chi phí tối ưu và hậu kiểm:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Chi phí tại \((3.6, 2.8)\): \(2(3.6) + 3(2.8) = 7.2 + 8.4 = 15.6\) USD (thấp hơn hẳn 24 USD và 30 USD!).&lt;/li&gt;
      &lt;li&gt;Hậu kiểm dinh dưỡng: Protein \(= 2(3.6) + 2.8 = 10\) (đạt đúng ngưỡng), Vitamin \(= 3.6 + 3(2.8) = 12\) (đạt đúng ngưỡng). Cả hai ràng buộc đều tích cực!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---các-bài-toán-chuẩn&quot;&gt;Bài Tập Thực Hành - Các Bài Toán Chuẩn&lt;/h1&gt;

&lt;p&gt;Các bài tập dưới đây được tham khảo từ Boyd &amp;amp; Vandenberghe (2004) và Ben-Tal &amp;amp; Nemirovski (2001).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-i-quy-hoạch-tuyến-tính-lp&quot;&gt;📝 &lt;strong&gt;Phần I: Quy hoạch Tuyến tính (LP)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-1-bài-toán-khẩu-phần-ăn-diet-problem&quot;&gt;&lt;strong&gt;Bài tập 1: Bài toán Khẩu phần ăn (Diet Problem)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Một người cần lập kế hoạch dinh dưỡng với 3 loại thực phẩm:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Thực phẩm 1: 2 đơn vị protein, 1 đơn vị tinh bột (carbs), giá 3 USD.&lt;/li&gt;
  &lt;li&gt;Thực phẩm 2: 1 đơn vị protein, 2 đơn vị carbs, giá 2 USD.&lt;/li&gt;
  &lt;li&gt;Thực phẩm 3: 1 đơn vị protein, 1 đơn vị carbs, giá 1.5 USD.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yêu cầu tối thiểu mỗi ngày: 5 đơn vị protein và 6 đơn vị carbs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Phát biểu bài toán LP cực tiểu hóa chi phí.&lt;br /&gt;
b) Tìm nghiệm tối ưu.&lt;br /&gt;
c) Giải thích ý nghĩa của các biến đối ngẫu (giá bóng – shadow prices).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Mô hình hóa bài toán:**

Đặt $$x_i$$ là lượng thực phẩm thứ $$i$$ ($$i = 1, 2, 3$$):

$$
\begin{align}
\min_{x} \quad &amp;amp; 3x_1 + 2x_2 + 1.5x_3 \\
\text{s.t.} \quad &amp;amp; 2x_1 + x_2 + x_3 \geq 5 \quad \text{(protein)} \\
&amp;amp; x_1 + 2x_2 + x_3 \geq 6 \quad \text{(carbs)} \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}
$$

**Viết dưới dạng bất đẳng thức $$\leq$$:**

$$
\begin{align}
\min_{x} \quad &amp;amp; 3x_1 + 2x_2 + 1.5x_3 \\
\text{s.t.} \quad &amp;amp; -2x_1 - x_2 - x_3 \leq -5 \\
&amp;amp; -x_1 - 2x_2 - x_3 \leq -6 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}
$$

---

**b) Tìm nghiệm tối ưu:**

Thực phẩm 3 có đơn giá thấp nhất trên mỗi đơn vị dinh dưỡng, nên nghiệm tối ưu ưu tiên sử dụng nhiều thực phẩm 3. Xét đỉnh $$x = (0, 1, 4)$$ (cả hai ràng buộc đều chặt và $$x_1 = 0$$):

$$\text{Protein: } 0 + 1 + 4 = 5 \text{ ✓}, \qquad \text{Carbs: } 0 + 2 + 4 = 6 \text{ ✓}$$

Chi phí: $$3 \cdot 0 + 2 \cdot 1 + 1.5 \cdot 4 = 8$$ USD.

Tính tối ưu được xác nhận bằng bài toán đối ngẫu ở phần c): tồn tại nghiệm đối ngẫu khả thi $$\lambda$$ có giá trị mục tiêu bằng 8.

**Nghiệm tối ưu:** $$x^* = (0, 1, 4)$$, chi phí tối thiểu = 8 USD.

(Lưu ý: đỉnh $$x_3 = 0$$ cho $$x = \left(\frac{4}{3}, \frac{7}{3}, 0\right)$$ cũng khả thi nhưng có chi phí $$\frac{26}{3} \approx 8.67 &amp;gt; 8$$ nên không tối ưu.)

---

**c) Biến đối ngẫu (Giá bóng – Shadow prices):**

Bài toán đối ngẫu:

$$
\max_{\lambda} \quad 5\lambda_1 + 6\lambda_2 \quad \text{s.t.} \quad A^T\lambda \leq c, \; \lambda \geq 0
$$

cụ thể là $$2\lambda_1 + \lambda_2 \leq 3$$, $$\lambda_1 + 2\lambda_2 \leq 2$$, và $$\lambda_1 + \lambda_2 \leq 1.5$$.

Xét $$\lambda^* = \left(1, \frac{1}{2}\right)$$ (suy ra từ điều kiện bù lỏng vì $$x_2^*, x_3^* &amp;gt; 0$$ nên ràng buộc đối ngẫu thứ 2 và thứ 3 phải chặt): ràng buộc thứ nhất cho $$2 + 0.5 = 2.5 &amp;lt; 3$$ (không chặt, khớp với $$x_1^* = 0$$), và giá trị đối ngẫu $$5(1) + 6(0.5) = 8$$ bằng đúng giá trị gốc, xác nhận nghiệm tối ưu theo đối ngẫu mạnh.

**Ý nghĩa kinh tế:**
- $$\lambda_1^* = 1$$: tăng yêu cầu protein thêm 1 đơn vị làm chi phí tối thiểu tăng thêm 1 USD.
- $$\lambda_2^* = \frac{1}{2}$$: tăng yêu cầu carbs thêm 1 đơn vị làm chi phí tối thiểu tăng thêm 0.5 USD.

Trong cấu trúc giá này, chi phí cận biên của protein cao gấp đôi carbs.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-ii-quy-hoạch-bậc-hai-qp&quot;&gt;📝 &lt;strong&gt;Phần II: Quy hoạch Bậc hai (QP)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-2-tối-ưu-hóa-danh-mục-đầu-tư&quot;&gt;&lt;strong&gt;Bài tập 2: Tối ưu hóa Danh mục Đầu tư&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Xét đầu tư vào 2 tài sản với:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Lợi suất kỳ vọng: \(\mu = (0.12, 0.10)^T\)&lt;/li&gt;
  &lt;li&gt;Ma trận hiệp phương sai: \(\Sigma = \begin{bmatrix} 0.04 &amp;amp; 0.01 \\ 0.01 &amp;amp; 0.09 \end{bmatrix}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán cực tiểu hóa rủi ro với lợi suất mục tiêu \(r = 0.11\).&lt;br /&gt;
b) Tìm danh mục tối ưu.&lt;br /&gt;
c) Xác định biên hiệu quả (efficient frontier).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Mô hình hóa bài toán:**

$$
\begin{align}
\min_{x} \quad &amp;amp; \frac{1}{2} x^T \Sigma x \\
\text{s.t.} \quad &amp;amp; \mu^T x = r \\
&amp;amp; \mathbf{1}^T x = 1 \\
&amp;amp; x \geq 0
\end{align}
$$

Với $$r = 0.11$$:

$$
\begin{align}
\min_{x} \quad &amp;amp; \frac{1}{2}(0.04x_1^2 + 0.02x_1x_2 + 0.09x_2^2) \\
\text{s.t.} \quad &amp;amp; 0.12x_1 + 0.10x_2 = 0.11 \\
&amp;amp; x_1 + x_2 = 1 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}
$$

---

**b) Tìm nghiệm:**

Từ hệ hai phương trình ràng buộc $$x_1 + x_2 = 1$$ và $$0.12x_1 + 0.10x_2 = 0.11$$:

$$0.12x_1 + 0.10(1-x_1) = 0.11 \Rightarrow 0.02x_1 = 0.01 \Rightarrow x_1 = 0.5, \quad x_2 = 0.5$$

**Nghiệm:** $$x^* = (0.5, 0.5)^T$$.

**Kiểm tra tính khả thi:** $$0.5 + 0.5 = 1$$ ✓, $$0.12(0.5) + 0.10(0.5) = 0.11$$ ✓.

**Phương sai (rủi ro):**

$$\sigma^2 = x^{*T} \Sigma x^* = \begin{bmatrix} 0.5 &amp;amp; 0.5 \end{bmatrix} \begin{bmatrix} 0.04 &amp;amp; 0.01 \\ 0.01 &amp;amp; 0.09 \end{bmatrix} \begin{bmatrix} 0.5 \\ 0.5 \end{bmatrix} = \begin{bmatrix} 0.5 &amp;amp; 0.5 \end{bmatrix} \begin{bmatrix} 0.025 \\ 0.05 \end{bmatrix} = 0.0375$$

**Độ lệch chuẩn:** $$\sigma = \sqrt{0.0375} \approx 0.194 = 19.4\%$$.

---

**c) Biên hiệu quả (Efficient frontier):**

Cho $$r$$ chạy từ $$\min(\mu_i) = 0.10$$ đến $$\max(\mu_i) = 0.12$$:

| Lợi suất $$r$$ | $$x_1$$ | $$x_2$$ | Độ lệch chuẩn $$\sigma$$ |
|----------------|---------|---------|--------------------------|
| 0.10 | 0 | 1 | 0.300 |
| 0.105 | 0.25 | 0.75 | 0.238 |
| 0.11 | 0.5 | 0.5 | 0.194 |
| 0.1145 | 0.727 | 0.273 | 0.178 (rủi ro nhỏ nhất) |
| 0.115 | 0.75 | 0.25 | 0.179 |
| 0.12 | 1 | 0 | 0.200 |

**Kết luận:** Danh mục có rủi ro nhỏ nhất đạt tại $$x_1 = 0.08/0.11 \approx 0.727$$ (tương ứng $$r \approx 0.1145$$). Chỉ nhánh $$r \geq 0.1145$$ là **biên hiệu quả** (với cùng mức rủi ro, lợi suất cao hơn); các điểm ứng với $$r &amp;lt; 0.1145$$ đều bị trội (dominated).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iii-qcqp-và-socp&quot;&gt;📝 &lt;strong&gt;Phần III: QCQP và SOCP&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-3-bình-phương-tối-thiểu-bền-vững-socp&quot;&gt;&lt;strong&gt;Bài tập 3: Bình phương tối thiểu bền vững (SOCP)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho dữ liệu \(A \in \mathbb{R}^{m \times n}\), \(b \in \mathbb{R}^m\). Thay cho bình phương tối thiểu thông thường, xét phiên bản bền vững:&lt;/p&gt;

\[\min_{x} \quad \|Ax - b\|_2 + \gamma \|x\|_2\]

&lt;p&gt;với \(\gamma &amp;gt; 0\) là tham số chính quy hóa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán dưới dạng SOCP.&lt;br /&gt;
b) Với \(A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \\ 2 &amp;amp; 0 \end{bmatrix}\), \(b = \begin{bmatrix} 2 \\ 0 \\ 3 \end{bmatrix}\), \(\gamma = 0.1\), tìm nghiệm.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Biểu diễn dạng SOCP:**

Đưa thêm hai biến phụ $$t_1, t_2$$ thỏa mãn:
- $$\|Ax - b\|_2 \leq t_1$$
- $$\|x\|_2 \leq t_2$$

Bài toán trở thành:

$$
\begin{align}
\min_{x, t_1, t_2} \quad &amp;amp; t_1 + \gamma t_2 \\
\text{s.t.} \quad &amp;amp; \|Ax - b\|_2 \leq t_1 \\
&amp;amp; \|x\|_2 \leq t_2
\end{align}
$$

Đây là một bài toán **SOCP** với 2 ràng buộc nón bậc hai, khớp với dạng chuẩn tổng quát:

$$
\begin{align}
\min \quad &amp;amp; c^T y \\
\text{s.t.} \quad &amp;amp; \|A_i y + b_i\|_2 \leq c_i^T y + d_i, \quad i = 1, \ldots, k
\end{align}
$$

---

**b) Giải số:**

Dữ liệu:

$$A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \\ 2 &amp;amp; 0 \end{bmatrix}, \quad b = \begin{bmatrix} 2 \\ 0 \\ 3 \end{bmatrix}, \quad \gamma = 0.1$$

**Gradient (khi $$Ax \neq b$$ và $$x \neq 0$$):**

$$\nabla f(x) = \frac{A^T(Ax-b)}{\|Ax-b\|_2} + \gamma \frac{x}{\|x\|_2}$$

(Hàm mục tiêu không trơn tại $$x = 0$$ và $$Ax = b$$, đồng thời phương trình $$\nabla f(x) = 0$$ là phi tuyến.)

**Cách 1: Xấp xỉ bằng hồi quy Ridge có nghiệm dạng đóng:**

Xét bài toán lân cận $$\min \|Ax-b\|_2^2 + \gamma^2\|x\|_2^2$$:

$$x_{\text{ridge}} = (A^TA + \gamma^2 I)^{-1} A^T b$$

Tính toán:

$$A^TA = \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 2 \\ 1 &amp;amp; -1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \\ 2 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 6 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}$$

$$A^TA + 0.01I = \begin{bmatrix} 6.01 &amp;amp; 0 \\ 0 &amp;amp; 2.01 \end{bmatrix}, \qquad A^Tb = \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 2 \\ 1 &amp;amp; -1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} 2 \\ 0 \\ 3 \end{bmatrix} = \begin{bmatrix} 8 \\ 2 \end{bmatrix}$$

Suy ra $$x_{\text{ridge}} = \left(\frac{8}{6.01}, \frac{2}{2.01}\right)^T \approx (1.331, 0.995)^T$$, với giá trị hàm mục tiêu gốc $$f(x_{\text{ridge}}) \approx 0.744$$.

**Cách 2: Nghiệm số của bài toán SOCP gốc** (giải trực tiếp $$\min \|Ax-b\|_2 + 0.1\|x\|_2$$):

$$x^* \approx (1.326, 0.983)^T, \qquad f(x^*) \approx 0.743$$

(Hai nghiệm rất gần nhau nhưng không trùng khớp hoàn toàn vì bài toán gốc dùng chuẩn $$\ell_2$$ thay vì bình phương chuẩn.)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-iv-quy-hoạch-nửa-xác-định-sdp&quot;&gt;📝 &lt;strong&gt;Phần IV: Quy hoạch Nửa xác định (SDP)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-4-hoàn-thiện-ma-trận-matrix-completion&quot;&gt;&lt;strong&gt;Bài tập 4: Hoàn thiện Ma trận (Matrix Completion)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Cho ma trận đối xứng \(M \in \mathbb{R}^{3 \times 3}\) bị khuyết một số phần tử, biết:&lt;/p&gt;

\[M_{11} = 4, \quad M_{12} = 2, \quad M_{22} = 5, \quad M_{23} = 1\]

&lt;p&gt;Tìm ma trận nửa xác định dương \(X\) hoàn chỉnh có vết (trace) nhỏ nhất.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;br /&gt;
a) Viết bài toán SDP.&lt;br /&gt;
b) Tìm nghiệm tối ưu.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Biểu diễn dạng SDP:**

$$
\begin{align}
\min_{X} \quad &amp;amp; \text{tr}(X) \\
\text{s.t.} \quad &amp;amp; X_{11} = 4 \\
&amp;amp; X_{12} = X_{21} = 2 \\
&amp;amp; X_{22} = 5 \\
&amp;amp; X_{23} = X_{32} = 1 \\
&amp;amp; X \succeq 0 \\
&amp;amp; X = X^T
\end{align}
$$

Cấu trúc ma trận $$X$$:

$$X = \begin{bmatrix} 4 &amp;amp; 2 &amp;amp; x_{13} \\ 2 &amp;amp; 5 &amp;amp; 1 \\ x_{13} &amp;amp; 1 &amp;amp; x_{33} \end{bmatrix}$$

---

**b) Giải bài toán:**

**Điều kiện nửa xác định dương (PSD):** tất cả các định thức con chính đều không âm.

- **Định thức con chính cấp 1:** $$4 &amp;gt; 0$$ ✓.
- **Định thức con chính cấp 2:**
$$\begin{vmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 5 \end{vmatrix} = 20 - 4 = 16 &amp;gt; 0 \text{ ✓}$$
- **Định thức cấp 3:**
$$\det(X) = 4(5x_{33} - 1) - 2(2x_{33} - x_{13}) + x_{13}(2 - 5x_{13})$$
$$= 20x_{33} - 4 - 4x_{33} + 2x_{13} + 2x_{13} - 5x_{13}^2 = 16x_{33} - 5x_{13}^2 + 4x_{13} - 4$$

Điều kiện $$\det(X) \geq 0$$ tương đương với:
$$x_{33} \geq \frac{5x_{13}^2 - 4x_{13} + 4}{16}$$

(Do hai định thức con chính dẫn đầu cấp 1 và cấp 2 đều dương chặt, điều kiện $$\det(X) \geq 0$$ cũng đủ đảm bảo $$X \succeq 0$$.)

**Cực tiểu hóa $$\text{tr}(X) = 4 + 5 + x_{33} = 9 + x_{33}$$:**

Bài toán quy về tìm giá trị nhỏ nhất của vế phải theo $$x_{13}$$:

$$\frac{d}{dx_{13}}\left(\frac{5x_{13}^2 - 4x_{13} + 4}{16}\right) = \frac{10x_{13} - 4}{16} = 0 \Rightarrow x_{13}^* = 0.4$$

Thay ngược lại để tính $$x_{33}^*$$:

$$x_{33}^{\min} = \frac{5(0.4)^2 - 4(0.4) + 4}{16} = \frac{0.8 - 1.6 + 4}{16} = \frac{3.2}{16} = 0.2$$

**Nghiệm tối ưu:**

$$X^* = \begin{bmatrix} 4 &amp;amp; 2 &amp;amp; 0.4 \\ 2 &amp;amp; 5 &amp;amp; 1 \\ 0.4 &amp;amp; 1 &amp;amp; 0.2 \end{bmatrix}, \quad \text{tr}(X^*) = 9.2$$

**Kiểm tra:** $$\det(X^*) = 16(0.2) - 5(0.16) + 1.6 - 4 = 0$$ (ma trận suy biến hạng 2 và nửa xác định dương ✓).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-phần-v-tổng-hợp&quot;&gt;📝 &lt;strong&gt;Phần V: Tổng hợp&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;bài-tập-5-nhận-diện-dạng-bài-toán-chuẩn-phù-hợp&quot;&gt;&lt;strong&gt;Bài tập 5: Nhận diện dạng bài toán chuẩn phù hợp&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Với mỗi bài toán sau, xác định lớp bài toán chuẩn phù hợp nhất (LP, QP, QCQP, SOCP hay SDP):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; \(\min c^T x\) s.t. \(Ax = b\), \(\|x\|_\infty \leq 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;b)&lt;/strong&gt; \(\min \|Ax - b\|_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;c)&lt;/strong&gt; \(\min x^TQx\) s.t. \(\|Ax - b\|_2 \leq \delta\) (với \(Q \succeq 0\))&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;d)&lt;/strong&gt; \(\min \text{tr}(X)\) s.t. \(X \succeq yy^T\), \(X \succeq 0\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) $$\min c^Tx$$ s.t. $$Ax = b$$, $$\|x\|_\infty \leq 1$$:**

Ràng buộc $$\|x\|_\infty \leq 1 \Leftrightarrow -1 \leq x_i \leq 1$$ là hệ các bất đẳng thức tuyến tính.

→ **Quy hoạch tuyến tính (LP)**.

---

**b) $$\min \|Ax - b\|_1$$:**

Đặt $$r = Ax - b$$, ta có $$\|Ax - b\|_1 = \sum_i |r_i|$$. Đưa thêm biến phụ $$t_i \geq |r_i|$$:

$$
\begin{align}
\min_{x, t} \quad &amp;amp; \sum_i t_i \\
\text{s.t.} \quad &amp;amp; -t_i \leq (Ax - b)_i \leq t_i
\end{align}
$$

→ **Quy hoạch tuyến tính (LP)**.

---

**c) $$\min x^TQx$$ s.t. $$\|Ax - b\|_2 \leq \delta$$ (với $$Q \succeq 0$$):**

- Hàm mục tiêu bậc hai lồi (có thể đưa về ràng buộc nón bậc hai bằng biến phụ epigraph).
- Ràng buộc chuẩn $$\ell_2$$ là ràng buộc nón bậc hai.

→ **Quy hoạch nón bậc hai (SOCP)** (hoặc **QCQP** nếu bình phương hai vế ràng buộc thành $$\|Ax-b\|_2^2 \leq \delta^2$$).

---

**d) $$\min \text{tr}(X)$$ s.t. $$X \succeq yy^T$$, $$X \succeq 0$$:**

- Hàm mục tiêu tuyến tính theo ma trận $$X$$.
- Ràng buộc $$X - yy^T \succeq 0$$ là ràng buộc nửa xác định dương (và kéo theo $$X \succeq 0$$).

→ **Quy hoạch nửa xác định (SDP)**.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;hệ-phân-cấp-các-bài-toán-tối-ưu-hóa-lồi&quot;&gt;&lt;strong&gt;Hệ phân cấp các bài toán tối ưu hóa lồi:&lt;/strong&gt;&lt;/h3&gt;

\[\text{LP} \subset \text{QP} \subset \text{QCQP} \subset \text{SOCP} \subset \text{SDP}\]

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Lớp bài toán&lt;/th&gt;
      &lt;th&gt;Hàm mục tiêu&lt;/th&gt;
      &lt;th&gt;Ràng buộc&lt;/th&gt;
      &lt;th&gt;Ví dụ tiêu biểu&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;LP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
      &lt;td&gt;Bài toán khẩu phần ăn, vận tải&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Bậc hai lồi&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
      &lt;td&gt;Danh mục đầu tư, bình phương tối thiểu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QCQP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Bậc hai lồi&lt;/td&gt;
      &lt;td&gt;Bậc hai lồi&lt;/td&gt;
      &lt;td&gt;Tối ưu hóa bền vững bậc hai&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SOCP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
      &lt;td&gt;Nón bậc hai (\(\ell_2\))&lt;/td&gt;
      &lt;td&gt;Bình phương tối thiểu bền vững, thiết kế ăng-ten&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SDP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
      &lt;td&gt;Nón ma trận PSD&lt;/td&gt;
      &lt;td&gt;Hoàn thiện ma trận, nới lỏng tổ hợp&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;nguyên-tắc-lựa-chọn-mô-hình&quot;&gt;&lt;strong&gt;Nguyên tắc lựa chọn mô hình:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP:&lt;/strong&gt; khi hàm mục tiêu và mọi ràng buộc đều tuyến tính.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QP:&lt;/strong&gt; tối ưu hóa rủi ro bậc hai, bình phương tối thiểu có chính quy hóa \(\ell_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SOCP:&lt;/strong&gt; tối ưu hóa bền vững dạng ellipsoid và các ràng buộc chuẩn \(\ell_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SDP:&lt;/strong&gt; bài toán có biến ma trận nửa xác định dương hoặc nới lỏng bài toán tổ hợp.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 4.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ben-Tal, A., &amp;amp; Nemirovski, A.&lt;/strong&gt; (2001). &lt;em&gt;Lectures on Modern Convex Optimization&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Lobo, M. S., et al.&lt;/strong&gt; (1998). “Applications of Second-Order Cone Programming”. &lt;em&gt;Linear Algebra and Applications&lt;/em&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>05-09 Bài tập trắc nghiệm - Các bài toán tối ưu kinh điển</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_09_Quiz_Canonical_Problems/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_09_Quiz_Canonical_Problems</id>
   <content type="html">&lt;p&gt;Giữa vô vàn ký hiệu \(P \succeq 0\), \(\|Ax + b\|_2 \le c^T x + d\), \(F_0 + \sum x_i F_i \succeq 0\) hay đơn thức dương \(c x_1^{a_1} x_2^{a_2}\), ranh giới giữa LP, QP, QCQP, SOCP, SDP và GP rất dễ bị nhòa đi nếu bạn chỉ đọc lướt. Bài tập trắc nghiệm này giúp bạn rèn phản xạ “chẩn đoán nhanh” trong vài giây: nhìn thấy một bài toán mới là nhận ra ngay nó thuộc tầng nào, có lồi hay không, và liệu có chuyển đổi được về tầng chuẩn thấp hơn hay không.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bảng-phân-biệt-nhanh-6-lớp-bài-toán-chuẩn&quot;&gt;Kiến thức cần nhớ: Bảng phân biệt nhanh 6 lớp bài toán chuẩn&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài trắc nghiệm, hãy dùng bốn quy tắc vàng sau làm la bàn kiểm chứng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc phân cấp nghiêm ngặt:&lt;/strong&gt; \(\text{LP} \subset \text{QP} \subset \text{QCQP} \subset \text{SOCP} \subset \text{SDP} \subset \text{CP}\). Mọi bài LP đều là QP (với \(Q = 0\)), mọi QP đều là SOCP, nhưng chiều ngược lại thì &lt;strong&gt;không&lt;/strong&gt; đúng!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc kiểm tra tính lồi ở từng lớp:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;LP:&lt;/strong&gt; Luôn lồi.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;QP / QCQP:&lt;/strong&gt; Lồi khi và chỉ khi mọi ma trận bậc hai \(P_i \succeq 0\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;GP:&lt;/strong&gt; Dạng gốc phi lồi, nhưng luôn chuyển được về lồi nhờ đổi biến logarit (điều kiện: bất đẳng thức là &lt;em&gt;posynomial&lt;/em&gt;, đẳng thức là &lt;em&gt;monomial&lt;/em&gt;, biến dương).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc nghiệm đóng vs. Thuật toán lặp:&lt;/strong&gt; Bình phương tối thiểu tuyến tính không ràng buộc có nghiệm đóng \(x^\star = (A^T A)^{-1} A^T b\); còn LP, QP có ràng buộc bất đẳng thức, SOCP, SDP và Hồi quy Logistic nói chung &lt;strong&gt;không có nghiệm đóng&lt;/strong&gt; và phải giải lặp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc nhận diện nón ẩn:&lt;/strong&gt; Ràng buộc chuẩn \(\ell_1\) hoặc \(\ell_\infty\) (\(\|Ax - b\|_1 \le t\)) quy về &lt;strong&gt;LP&lt;/strong&gt;; ràng buộc chuẩn \(\ell_2\) (\(\|Ax - b\|_2 \le t\)) quy về &lt;strong&gt;SOCP&lt;/strong&gt;; ràng buộc trị riêng lớn nhất (\(\lambda_{\max}(A(x)) \le t\)) quy về &lt;strong&gt;SDP&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chẩn-đoán-nhanh-tầng-thấp-nhất-cho-3-bài-toán-đánh-lừa-thị-giác&quot;&gt;Giải thích: Chẩn đoán nhanh tầng thấp nhất cho 3 bài toán “đánh lừa thị giác”&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bài A:&lt;/strong&gt; \(\min_{x \in \mathbb{R}^n} \; \|Ax - b\|_\infty\).
    &lt;ul&gt;
      &lt;li&gt;Nhìn thấy chuẩn, nhiều người vội chọn SOCP. &lt;strong&gt;Cẩn thận!&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Chuẩn vô cùng là $$\max_i&lt;/td&gt;
              &lt;td&gt;a_i^T x - b_i&lt;/td&gt;
              &lt;td&gt;\le t \iff -t \le a_i^T x - b_i \le t \; \forall i$$ — toàn bộ là bất đẳng thức tuyến tính!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tầng thấp nhất đúng:&lt;/strong&gt; &lt;strong&gt;LP&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài B:&lt;/strong&gt; \(\min_{x \in \mathbb{R}^n} \; x_1^2 + x_2^2 \text{ s.t. } x_1 + x_2 = 1\).
    &lt;ul&gt;
      &lt;li&gt;Hàm mục tiêu bậc hai với \(P = 2I \succ 0\), ràng buộc tuyến tính.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tầng thấp nhất đúng:&lt;/strong&gt; &lt;strong&gt;QP&lt;/strong&gt; (cũng là bài toán bình phương tối thiểu có ràng buộc đẳng thức!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài C:&lt;/strong&gt; \(\min_{x \in \mathbb{R}^2} \; x_1 + x_2 \text{ s.t. } x_1^2 + x_2^2 \le 1,\; x_1 \ge 0\).
    &lt;ul&gt;
      &lt;li&gt;Hàm mục tiêu tuyến tính, nhưng ràng buộc có hình tròn \(x_1^2 + x_2^2 \le 1\) (tương đương \(\|x\|_2 \le 1\)).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tầng thấp nhất đúng:&lt;/strong&gt; &lt;strong&gt;QCQP&lt;/strong&gt; (hoặc &lt;strong&gt;SOCP&lt;/strong&gt; — không thể đưa về LP hay QP vì tập khả thi cong tròn!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra hiểu biết của bạn về các bài toán tối ưu kinh điển, bao gồm quy hoạch tuyến tính, quy hoạch bậc hai, bình phương tối thiểu và hồi quy tuyến tính.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-quy-hoạch-tuyến-tính-lp&quot;&gt;📊 &lt;strong&gt;Quy Hoạch Tuyến Tính (LP)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Dạng tổng quát:&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;c^T x + d \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;Gx \preceq h \\
&amp;amp;&amp;amp;&amp;amp;Ax = b
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dạng chuẩn:&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;c^T x \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;Ax = b \\
&amp;amp;&amp;amp;&amp;amp;x \succeq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đặc điểm chính:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu và ràng buộc đều &lt;strong&gt;affine&lt;/strong&gt; (tuyến tính)&lt;/li&gt;
  &lt;li&gt;Tập khả thi là &lt;strong&gt;đa diện&lt;/strong&gt; (polyhedron)&lt;/li&gt;
  &lt;li&gt;Nếu có nghiệm tối ưu (và đa diện có đỉnh), luôn tồn tại một nghiệm tối ưu tại &lt;strong&gt;đỉnh&lt;/strong&gt; của đa diện&lt;/li&gt;
  &lt;li&gt;Có thể giải hiệu quả bằng &lt;strong&gt;thuật toán Simplex&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Chuyển đổi về dạng chuẩn:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Thêm biến phụ (slack): \(g_i(x) \le 0 \Rightarrow g_i(x) + s_i = 0, s_i \ge 0\)&lt;/li&gt;
  &lt;li&gt;Tách biến: \(x = x^+ - x^-\) với \(x^+, x^- \ge 0\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-quy-hoạch-bậc-hai-qp&quot;&gt;📈 &lt;strong&gt;Quy Hoạch Bậc Hai (QP)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Dạng tổng quát:&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;\frac{1}{2}x^T P x + q^T x + r \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;Gx \preceq h \\
&amp;amp;&amp;amp;&amp;amp;Ax = b
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện lồi:&lt;/strong&gt; \(P \in \mathbb{S}_+^n\) (ma trận bán xác định dương)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kiểm tra \(P \succeq 0\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tất cả giá trị riêng \(\lambda_i \ge 0\)&lt;/li&gt;
  &lt;li&gt;\(v^T P v \ge 0\) với mọi \(v\)&lt;/li&gt;
  &lt;li&gt;Với ma trận \(2 \times 2\): \(a \ge 0, c \ge 0, ac \ge b^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ ứng dụng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa danh mục:&lt;/strong&gt; \(\max \mu^T x - \frac{\gamma}{2}x^T P x\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVM:&lt;/strong&gt; \(\min \frac{1}{2}\lVert \beta \rVert_2^2 + C\sum \xi_i\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hồi quy Ridge:&lt;/strong&gt; \(\min \lVert Ax - b \rVert_2^2 + \lambda \lVert x \rVert_2^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-bình-phương-tối-thiểu&quot;&gt;🎯 &lt;strong&gt;Bình Phương Tối Thiểu&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán cơ bản:&lt;/strong&gt;
\(\min_{x} \lVert Ax - b \rVert_2^2 = \min_{x} \sum_{i=1}^m (a_i^T x - b_i)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nghiệm dạng đóng (Normal Equation):&lt;/strong&gt;
\(x^* = (A^T A)^{-1} A^T b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện tồn tại nghiệm duy nhất:&lt;/strong&gt; \(A^T A\) khả nghịch (\(A\) có hạng cột đầy đủ)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hồi quy tuyến tính một biến:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Mô hình: \(y = mx + c\)&lt;/li&gt;
  &lt;li&gt;Nghiệm: \(m = \frac{\sum(x_i - \bar{x})(y_i - \bar{y})}{\sum(x_i - \bar{x})^2}\), \(c = \bar{y} - m\bar{x}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hồi quy tuyến tính nhiều biến:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Mô hình: \(y = X\beta\)&lt;/li&gt;
  &lt;li&gt;Nghiệm: \(\beta^* = (X^T X)^{-1} X^T y\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-các-bài-toán-kinh-điển-khác&quot;&gt;🔢 &lt;strong&gt;Các Bài Toán Kinh Điển Khác&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;QCQP (Quadratically Constrained QP):&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min &amp;amp;&amp;amp;\frac{1}{2}x^T P_0 x + q_0^T x \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;\frac{1}{2}x^T P_i x + q_i^T x + r_i \le 0, \quad i = 1,\ldots,m
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SOCP (Second-Order Cone Programming):&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min &amp;amp;&amp;amp;f^T x \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;\lVert A_i x + b_i \rVert_2 \le c_i^T x + d_i, \quad i = 1,\ldots,m
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SDP (Semidefinite Programming):&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min &amp;amp;&amp;amp;\text{tr}(CX) \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;\text{tr}(A_i X) = b_i, \quad i = 1,\ldots,m \\
&amp;amp;&amp;amp;&amp;amp;X \succeq 0
\end{align}\)&lt;/p&gt;

&lt;h3 id=&quot;️-mối-quan-hệ-giữa-các-bài-toán&quot;&gt;🏗️ &lt;strong&gt;Mối Quan Hệ Giữa Các Bài Toán&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;LP ⊆ QP ⊆ QCQP ⊆ SDP
    ⊆ SOCP ⊆
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Giải thích:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP → QP:&lt;/strong&gt; Đặt \(P = 0\) trong QP&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QP → QCQP:&lt;/strong&gt; Ràng buộc tuyến tính là trường hợp đặc biệt của ràng buộc bậc hai&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SOCP → SDP:&lt;/strong&gt; Nón bậc hai biểu diễn được bằng ràng buộc nửa xác định dương (LMI)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QCQP → SDP:&lt;/strong&gt; QCQP (lồi) có thể biểu diễn qua SDP với kỹ thuật Schur complement&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-thuật-toán-giải&quot;&gt;🛠️ &lt;strong&gt;Thuật Toán Giải&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Linear Programming:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Simplex Method:&lt;/strong&gt; Di chuyển từ đỉnh này sang đỉnh khác&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior Point Methods:&lt;/strong&gt; Đi qua phần trong của tập khả thi&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Simplex:&lt;/strong&gt; Bắt đầu từ nghiệm khả thi đối ngẫu&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Quadratic Programming:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp tập tích cực (Active Set):&lt;/strong&gt; Xác định các ràng buộc tích cực&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior Point Methods:&lt;/strong&gt; Mở rộng từ LP&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Projection:&lt;/strong&gt; Chiếu gradient lên tập khả thi&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Least Squares:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Normal Equation:&lt;/strong&gt; Nghiệm trực tiếp \(x^* = (A^T A)^{-1} A^T b\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QR Decomposition:&lt;/strong&gt; Ổn định số hơn&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVD:&lt;/strong&gt; Xử lý ma trận suy biến&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent:&lt;/strong&gt; Cho bài toán lớn&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ứng-dụng-thực-tế&quot;&gt;📋 &lt;strong&gt;Ứng Dụng Thực Tế&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Linear Programming:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tối ưu hóa sản xuất và phân phối&lt;/li&gt;
  &lt;li&gt;Bài toán khẩu phần ăn&lt;/li&gt;
  &lt;li&gt;Quản lý danh mục đầu tư&lt;/li&gt;
  &lt;li&gt;Lịch trình nhân viên&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Quadratic Programming:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tối ưu hóa danh mục Markowitz&lt;/li&gt;
  &lt;li&gt;Support Vector Machines&lt;/li&gt;
  &lt;li&gt;Model Predictive Control&lt;/li&gt;
  &lt;li&gt;Image denoising&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Least Squares:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hồi quy tuyến tính và phi tuyến&lt;/li&gt;
  &lt;li&gt;Curve fitting và interpolation&lt;/li&gt;
  &lt;li&gt;Signal processing&lt;/li&gt;
  &lt;li&gt;Computer vision&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-nhận-biết-loại-bài-toán&quot;&gt;🔍 &lt;strong&gt;Nhận Biết Loại Bài Toán&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Checklist:&lt;/strong&gt;&lt;/p&gt;
&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Hàm mục tiêu tuyến tính? → &lt;strong&gt;LP&lt;/strong&gt;&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Hàm mục tiêu bậc hai, ràng buộc tuyến tính? → &lt;strong&gt;QP&lt;/strong&gt;&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Ràng buộc bậc hai? → &lt;strong&gt;QCQP&lt;/strong&gt;&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Ràng buộc norm? → &lt;strong&gt;SOCP&lt;/strong&gt;&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Ràng buộc ma trận? → &lt;strong&gt;SDP&lt;/strong&gt;&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Không có ràng buộc, mục tiêu bình phương? → &lt;strong&gt;Least Squares&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-độ-phức-tạp-tính-toán&quot;&gt;⚡ &lt;strong&gt;Độ Phức Tạp Tính Toán&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Bài toán&lt;/th&gt;
      &lt;th&gt;Độ phức tạp&lt;/th&gt;
      &lt;th&gt;Ghi chú&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;LP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đa thức (interior point); Simplex nhanh trong thực tế&lt;/td&gt;
      &lt;td&gt;Simplex: tốt trung bình&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đa thức&lt;/td&gt;
      &lt;td&gt;Interior point methods&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Least Squares&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(O(n^3)\)&lt;/td&gt;
      &lt;td&gt;Normal equation&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SOCP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đa thức&lt;/td&gt;
      &lt;td&gt;Tương tự SDP&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SDP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Đa thức&lt;/td&gt;
      &lt;td&gt;Chậm hơn LP, QP&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Lưu ý:&lt;/strong&gt; Nên ưu tiên mô hình hóa bài toán ở lớp đơn giản nhất phù hợp với cấu trúc thực tế; thông thường LP giải nhanh hơn QP, và QP nhanh hơn SDP.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Bài tập trắc nghiệm: Các bài toán tối ưu kinh điển&lt;/h2&gt;
        &lt;p&gt;Chọn đáp án đúng nhất cho mỗi câu hỏi. Bài tập tập trung vào các khái niệm cơ bản và ứng dụng thực tế của LP, QP và bình phương tối thiểu.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Câu hỏi 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Câu hỏi 1: Định nghĩa LP --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Câu 1: Quy hoạch tuyến tính (LP) có đặc điểm nào sau đây?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Hàm mục tiêu và ràng buộc đều là hàm tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Hàm mục tiêu là bậc hai, ràng buộc tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Hàm mục tiêu tuyến tính, ràng buộc phi tuyến&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Cả hàm mục tiêu và ràng buộc đều phi tuyến&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Hàm mục tiêu và ràng buộc đều là hàm tuyến tính&lt;/strong&gt;&lt;br /&gt;
                Quy hoạch tuyến tính được định nghĩa bởi hàm mục tiêu tuyến tính và tất cả ràng buộc đều là tuyến tính (affine).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Dạng chuẩn LP --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Dạng chuẩn của LP có đặc điểm:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) Tối đa hóa, ràng buộc bất đẳng thức, biến tự do&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) Tối thiểu hóa, ràng buộc đẳng thức, biến không âm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Tối đa hóa, ràng buộc đẳng thức, biến không âm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Tối thiểu hóa, ràng buộc bất đẳng thức, biến tự do&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tối thiểu hóa, ràng buộc đẳng thức, biến không âm&lt;/strong&gt;&lt;br /&gt;
                Dạng chuẩn LP: minimize $$c^T x$$ subject to $$Ax = b$$, $$x \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Biến slack --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Biến slack được sử dụng để:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) Chuyển ràng buộc đẳng thức thành bất đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Chuyển ràng buộc bất đẳng thức thành đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Tăng số biến trong bài toán&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Giảm độ phức tạp tính toán&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Chuyển ràng buộc bất đẳng thức thành đẳng thức&lt;/strong&gt;&lt;br /&gt;
                Biến slack chuyển $$Gx \leq h$$ thành $$Gx + s = h$$ với $$s \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Định lý cơ bản LP --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Định lý cơ bản của quy hoạch tuyến tính nói rằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Nghiệm tối ưu luôn duy nhất&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Nếu LP có nghiệm tối ưu và vùng khả thi có đỉnh, thì luôn có một nghiệm tối ưu tại một đỉnh&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Vùng khả thi luôn bị chặn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Hàm mục tiêu luôn có cực tiểu toàn cục&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Nếu LP có nghiệm tối ưu và vùng khả thi có đỉnh, thì luôn có một nghiệm tối ưu tại một đỉnh&lt;/strong&gt;&lt;br /&gt;
                Đây là cơ sở cho thuật toán Simplex: nghiệm tối ưu của LP luôn có thể tìm thấy tại một đỉnh.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Thuật toán Simplex --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Thuật toán Simplex hoạt động bằng cách:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Tìm kiếm ngẫu nhiên trong vùng khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Di chuyển từ đỉnh này sang đỉnh khác để cải thiện hàm mục tiêu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Sử dụng gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Chia đôi vùng khả thi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Di chuyển từ đỉnh này sang đỉnh khác để cải thiện hàm mục tiêu&lt;/strong&gt;&lt;br /&gt;
                Simplex bắt đầu từ một đỉnh và di chuyển đến đỉnh kề cải thiện giá trị hàm mục tiêu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: QP định nghĩa --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Quy hoạch bậc hai (QP) có hàm mục tiêu dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) $$c^T x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) $$\frac{1}{2}x^T P x + q^T x + r$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) $$\|Ax - b\|_2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) $$x^T A x^T$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\frac{1}{2}x^T P x + q^T x + r$$&lt;/strong&gt;&lt;br /&gt;
                QP có hàm mục tiêu là hàm bậc hai lồi với ma trận $$P \in \mathbb{S}_+^n$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Ma trận P trong QP --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Trong QP, ma trận $$P$$ phải thỏa mãn điều kiện:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) $$P$$ là ma trận đối xứng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) $$P$$ là ma trận bán xác định dương&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) $$P$$ là ma trận khả nghịch&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) $$P$$ là ma trận đường chéo&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$P$$ là ma trận bán xác định dương&lt;/strong&gt;&lt;br /&gt;
                Điều kiện $$P \in \mathbb{S}_+^n$$ đảm bảo hàm mục tiêu là lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: LP là trường hợp đặc biệt của QP --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: LP là trường hợp đặc biệt của QP khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) $$P = I$$ (ma trận đơn vị)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) $$P = 0$$ (ma trận không)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) $$q = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) $$r = 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$P = 0$$ (ma trận không)&lt;/strong&gt;&lt;br /&gt;
                Khi $$P = 0$$, hàm mục tiêu QP trở thành $$q^T x + r$$, đây chính là LP.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Bài toán bình phương tối thiểu --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Bài toán bình phương tối thiểu tuyến tính có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) minimize $$\|Ax - b\|_1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) minimize $$\|Ax - b\|_2^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) minimize $$\|Ax - b\|_\infty$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) minimize $$x^T A x$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) minimize $$\|Ax - b\|_2^2$$&lt;/strong&gt;&lt;br /&gt;
                Bài toán bình phương tối thiểu tối thiểu hóa tổng các sai số bình phương.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Nghiệm phương trình chuẩn --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Nghiệm của bài toán bình phương tối thiểu được cho bởi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) $$x^* = A^{-1}b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) $$x^* = (A^T A)^{-1} A^T b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) $$x^* = A^T (AA^T)^{-1} b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) $$x^* = A^T b$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$x^* = (A^T A)^{-1} A^T b$$&lt;/strong&gt;&lt;br /&gt;
                Đây là nghiệm dạng đóng của phương trình chuẩn $$A^T A x = A^T b$$ (khi $$A$$ có hạng cột đầy đủ).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Hồi quy tuyến tính đơn biến --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Trong hồi quy tuyến tính $$y = mx + c$$, hệ số góc $$m$$ được tính bằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) $$\frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) $$\frac{\sum (y_i - \bar{y})^2}{\sum (x_i - \bar{x})^2}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) $$\bar{y} - m\bar{x}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) $$\frac{\sum x_i y_i}{\sum x_i^2}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}$$&lt;/strong&gt;&lt;br /&gt;
                Đây là công thức chuẩn cho hệ số góc trong hồi quy tuyến tính đơn biến.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Giả thuyết Gauss-Markov --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Giả thuyết Gauss-Markov không bao gồm:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Sai số có kỳ vọng bằng 0&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Các sai số không tương quan&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Phương sai đồng nhất&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Sai số phân phối đều&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Sai số phân phối đều&lt;/strong&gt;&lt;br /&gt;
                Giả thuyết Gauss-Markov chỉ yêu cầu sai số có kỳ vọng 0, không tương quan và có phương sai đồng nhất; nó không giả định phân phối cụ thể nào (không cần chuẩn, càng không cần đều). Giả định phân phối chuẩn chỉ cần thêm cho suy luận (kiểm định, khoảng tin cậy) hoặc để OLS trùng với MLE.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Ước lượng hợp lý tối đa --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Ước lượng hợp lý tối đa (MLE) trong hồi quy tuyến tính tương đương với:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Tối đa hóa log-likelihood&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Tối thiểu hóa tổng sai số bình phương&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Cả A và B&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Tối đa hóa R²&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Cả A và B&lt;/strong&gt;&lt;br /&gt;
                Dưới giả thuyết Gaussian, tối đa hóa log-likelihood tương đương với tối thiểu hóa MSE.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Ứng dụng LP --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Bài toán khẩu phần ăn (diet problem) là ví dụ của:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Quy hoạch tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Quy hoạch bậc hai&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Bình phương tối thiểu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Quy hoạch phi tuyến&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Quy hoạch tuyến tính&lt;/strong&gt;&lt;br /&gt;
                Bài toán khẩu phần ăn có hàm mục tiêu và các ràng buộc đều tuyến tính.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Ứng dụng QP --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Tối ưu hóa danh mục đầu tư là ví dụ của:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Quy hoạch tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Quy hoạch bậc hai&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Bình phương tối thiểu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Quy hoạch nguyên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Quy hoạch bậc hai&lt;/strong&gt;&lt;br /&gt;
                Tối ưu hóa danh mục cân bằng lợi nhuận (tuyến tính) và rủi ro (bậc hai).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Polytope --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Vùng khả thi của LP được gọi là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Ellipsoid&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) Polytope (nếu bị chặn)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Simplex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Hyperplane&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Polytope (nếu bị chặn)&lt;/strong&gt;&lt;br /&gt;
                Vùng khả thi của LP là giao của các nửa không gian, tạo thành polytope nếu bị chặn.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Điều kiện tối ưu cho least squares --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Điều kiện tối ưu cho bài toán bình phương tối thiểu là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) $$Ax = b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) $$A^T A x = A^T b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) $$A^T x = b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) $$x = 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$A^T A x = A^T b$$&lt;/strong&gt;&lt;br /&gt;
                Đây là phương trình chuẩn, điều kiện cần và đủ cho bài toán bình phương tối thiểu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: R² trong hồi quy --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Hệ số xác định R² đo lường:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Sai số trung bình&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Tỷ lệ phương sai được giải thích bởi mô hình&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Độ lệch chuẩn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Hệ số tương quan&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tỷ lệ phương sai được giải thích bởi mô hình&lt;/strong&gt;&lt;br /&gt;
                R² = 1 - (SSres/SStot) cho biết mô hình giải thích được bao nhiêu phần trăm biến thiên của dữ liệu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Độ phức tạp Simplex --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Độ phức tạp của thuật toán Simplex là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Đa thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Mũ trong trường hợp xấu nhất nhưng hiệu quả trong thực tế&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Lôgarit&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Hằng số&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Mũ trong trường hợp xấu nhất nhưng hiệu quả trong thực tế&lt;/strong&gt;&lt;br /&gt;
                Simplex có độ phức tạp mũ trong trường hợp xấu nhất (ví dụ Klee-Minty) nhưng trong thực tế số vòng lặp thường chỉ khoảng 2-3 lần số ràng buộc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: BLUE --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: BLUE trong hồi quy tuyến tính có nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Best Linear Unbiased Estimator&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Basic Linear Uniform Estimation&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Bayesian Linear Update Equation&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Bounded Linear Uncertainty Estimate&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Best Linear Unbiased Estimator&lt;/strong&gt;&lt;br /&gt;
                Dưới giả thuyết Gauss-Markov, OLS cho ước lượng tuyến tính không chệch tốt nhất.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Bài toán LP có dạng chuẩn là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$\min c^T x$$ với $$Ax = b, x \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$\min c^T x$$ với $$Ax \leq b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$\max c^T x$$ với $$Ax \leq b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$\min c^T x$$ với $$Ax \geq b$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\min c^T x$$ với $$Ax = b, x \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                Dạng chuẩn của LP là tối thiểu hóa với ràng buộc đẳng thức và ràng buộc không âm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Trong SOCP, ràng buộc nón có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$\|Ax + b\|_2 \leq c^T x + d$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$\|Ax + b\|_1 \leq c^T x + d$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$\|Ax + b\|_\infty \leq c^T x + d$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$(Ax + b)^2 \leq c^T x + d$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\|Ax + b\|_2 \leq c^T x + d$$&lt;/strong&gt;&lt;br /&gt;
                SOCP sử dụng ràng buộc nón bậc hai với chuẩn Euclid (L2).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Bài toán SDP có ràng buộc:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Ma trận nửa xác định dương&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Ma trận đối xứng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Ma trận tam giác&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Ma trận đường chéo&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Ma trận nửa xác định dương&lt;/strong&gt;&lt;br /&gt;
                SDP có ràng buộc ma trận phải nửa xác định dương: $$X \succeq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Bài toán phân bổ tài nguyên với 3 dự án và ngân sách 100 có thể mô hình hóa bằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) LP&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) QP&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) SOCP&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) SDP&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) LP&lt;/strong&gt;&lt;br /&gt;
                Bài toán phân bổ tài nguyên tuyến tính thường được mô hình hóa bằng Linear Programming.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Trong bài toán tối ưu hóa danh mục đầu tư (portfolio optimization), hàm mục tiêu thường là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Tối thiểu hóa rủi ro (phương sai)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Tối đa hóa lợi nhuận&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Cân bằng rủi ro-lợi nhuận&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Tất cả các trường hợp trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các trường hợp trên&lt;/strong&gt;&lt;br /&gt;
                Bài toán tối ưu hóa danh mục đầu tư có thể cực tiểu hóa rủi ro, cực đại hóa lợi suất hoặc cân bằng giữa rủi ro và lợi suất (mô hình Markowitz).
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Câu trước&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Câu tiếp&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Kết quả bài tập&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #FF6B35, #F7931E);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #FF6B35;
    background-color: #fff5f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #FF6B35;
    background-color: #ffe5d6;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #fff5f0;
    border-left: 4px solid #FF6B35;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #D2691E;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #FF6B35;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #E55A2B;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #fff5f0;
    border-radius: 8px;
    border: 2px solid #FF6B35;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #D2691E;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng cho từng câu hỏi
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;b&apos;, q9: &apos;b&apos;, q10: &apos;b&apos;,
    q11: &apos;a&apos;, q12: &apos;d&apos;, q13: &apos;c&apos;, q14: &apos;a&apos;, q15: &apos;b&apos;,
    q16: &apos;b&apos;, q17: &apos;b&apos;, q18: &apos;b&apos;, q19: &apos;b&apos;, q20: &apos;a&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;d&apos;};

/**
 * Cập nhật thanh tiến trình và hiển thị câu hỏi hiện tại
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Câu hỏi ${currentQuestion}/${totalQuestions}`;
}

/**
 * Hiển thị câu hỏi theo số thứ tự
 */
function showQuestion(questionNum) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Cập nhật trạng thái nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Chuyển đến câu hỏi tiếp theo
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Quay lại câu hỏi trước
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Lưu đáp án của người dùng
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Cập nhật giao diện để hiển thị đáp án đã chọn
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Nộp bài và hiển thị kết quả
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Tính điểm và tạo báo cáo chi tiết
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Hiển thị giải thích cho tất cả câu hỏi
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Tạo báo cáo chi tiết
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Câu ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Đúng&apos; : &apos;Sai&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Đáp án của bạn: ${userAnswer || &apos;Chưa trả lời&apos;} | Đáp án đúng: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Hiển thị kết quả
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Điểm số: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Xuất sắc! Bạn đã nắm vững các bài toán tối ưu kinh điển!&apos; : 
              scorePercentage &gt;= 60 ? &apos;👍 Khá tốt! Hãy ôn lại một số khái niệm về LP và QP.&apos; : 
              scorePercentage &gt;= 40 ? &apos;📚 Cần ôn tập thêm về thuật toán Simplex và bình phương tối thiểu.&apos; : &apos;💪 Hãy đọc lại lý thuyết về các bài toán tối ưu cơ bản!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Khởi động lại bài tập
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn kết quả và hiển thị lại điều hướng
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Xóa tất cả lựa chọn
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>05-06 Quy Hoạch Nón (CP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_06_Conic_Programming_(CP)/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_06_Conic_Programming_(CP)</id>
   <content type="html">&lt;p&gt;Nhìn lại chặng đường từ LP (\(x \ge 0\)), sang SOCP (\(\|u\|_2 \le t\)), rồi đến SDP (\(X \succeq 0\)), bạn có nhận ra cả ba lớp bài toán đồ sộ ấy thực chất chỉ khác nhau ở đúng &lt;strong&gt;một ký hiệu duy nhất&lt;/strong&gt; không? Tất cả đều có hàm mục tiêu tuyến tính \(c^T x\), ràng buộc đẳng thức affine \(Ax = b\), và một ràng buộc thành viên duy nhất: \(x \in K\) (hoặc \(Gx + s = h,\; s \in K\)), trong đó \(K\) là một &lt;strong&gt;nón lồi&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Đó chính là tầm nhìn thống nhất tuyệt đẹp của &lt;strong&gt;Quy hoạch Nón (Conic Programming - CP)&lt;/strong&gt;. Thay vì phải viết hàng chục bộ giải riêng biệt cho từng loại bài toán, các nhà tối ưu hóa hiện đại chỉ cần xây dựng lý thuyết đối ngẫu và thuật toán điểm trong cho &lt;em&gt;bài toán nón tổng quát&lt;/em&gt; — và lập tức giải được cả LP, QP, SOCP, SDP, thậm chí cả quy hoạch mũ (exponential cone) và quy hoạch lũy thừa (power cone) trong cùng một kiến trúc phần mềm!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bức-tranh-thống-nhất-của-quy-hoạch-nón&quot;&gt;Kiến thức cần nhớ: Bức tranh thống nhất của Quy hoạch Nón&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau cho thấy vì sao Quy hoạch Nón là “ngôn ngữ máy” (assembly language) của tối ưu hóa lồi hiện đại:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Từ điển các Nón chuẩn (Standard Cones):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Nón không âm&lt;/strong&gt; \(\mathbb{R}_+^n\) sinh ra &lt;strong&gt;LP&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Nón bậc hai&lt;/strong&gt; \(\mathcal{Q}^n\) sinh ra &lt;strong&gt;SOCP&lt;/strong&gt; (bao hàm QP và QCQP).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Nón nửa xác định dương&lt;/strong&gt; \(\mathbb{S}_+^n\) sinh ra &lt;strong&gt;SDP&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Nón mũ&lt;/strong&gt; \(K_{\text{exp}} = \operatorname{cl}\{(x,y,z) : y &amp;gt; 0,\; y e^{x/y} \le z\}\) sinh ra &lt;strong&gt;GP, Hồi quy Logistic và Entropy&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tích Đề-các của nhiều nón (Mixed Cone Programs):&lt;/strong&gt; Trong thực tế, một bài toán duy nhất có thể đồng thời chứa cả biến không âm, ràng buộc chuẩn \(\ell_2\) và ràng buộc ma trận \(X \succeq 0\). Khi đó ta chỉ cần đặt \(K = \mathbb{R}_+^{n_1} \times \mathcal{Q}^{n_2} \times \mathbb{S}_+^{n_3}\) — vẫn là một bài toán Quy hoạch Nón chuẩn!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu Nón &amp;amp; Tự đối ngẫu (Conic Duality):&lt;/strong&gt; Bài toán đối ngẫu của CP có cấu trúc đối xứng gần như y hệt bài toán gốc, chỉ thay nón \(K\) bằng &lt;strong&gt;nón đối ngẫu&lt;/strong&gt; \(K^*\). Nhờ tính đối xứng này, các bộ giải như Clarabel, SCS hay MOSEK giải đồng thời cả bài toán gốc lẫn đối ngẫu và chứng nhận nghiệm tối ưu khi khoảng cách đối ngẫu về \(0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-viết-một-bài-toán-hỗn-hợp-về-đúng-dạng-chuẩn-quy-hoạch-nón&quot;&gt;Giải thích: Viết một bài toán hỗn hợp về đúng dạng chuẩn Quy hoạch Nón&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu 2 biến kết hợp cả ràng buộc tuyến tính lẫn chuẩn Euclidean:
\(\min_{x_1, x_2} \; -x_1 - x_2 \quad \text{thỏa mãn} \quad x_1 \ge 0,\quad x_2 \ge 0,\quad \sqrt{x_1^2 + x_2^2} \le 2.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Đưa vào vector biến phụ \(s\) thuộc tích nón \(K = \mathbb{R}_+^2 \times \mathcal{Q}^3\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với ràng buộc tuyến tính \(x_1 \ge 0,\; x_2 \ge 0\): đặt \(s_1 = x_1 \ge 0,\; s_2 = x_2 \ge 0 \implies (s_1, s_2) \in \mathbb{R}_+^2\).&lt;/li&gt;
      &lt;li&gt;Với ràng buộc chuẩn \(\|(x_1, x_2)\|_2 \le 2\): đặt \(s_3 = 2,\; s_4 = x_1,\; s_5 = x_2 \implies (s_3, s_4, s_5) \in \mathcal{Q}^3\) (vì \(\sqrt{s_4^2 + s_5^2} \le s_3\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Gom thành dạng chuẩn CP \(\min c^T x \text{ s.t. } Gx + s = h,\; s \in K\):&lt;/strong&gt;
\(G = \begin{pmatrix} -1 &amp;amp; 0 \\ 0 &amp;amp; -1 \\ 0 &amp;amp; 0 \\ -1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{pmatrix}, \qquad h = \begin{pmatrix} 0 \\ 0 \\ 2 \\ 0 \\ 0 \end{pmatrix}, \qquad c = \begin{pmatrix} -1 \\ -1 \end{pmatrix}, \qquad K = \mathbb{R}_+^2 \times \mathcal{Q}^3.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kiểm chứng nghiệm:&lt;/strong&gt; Nghiệm tối ưu là \(x^\star = (\sqrt{2}, \sqrt{2})\), cho \(f^\star = -2\sqrt{2} \approx -2.828\). Khi đó \(s^\star = (\sqrt{2}, \sqrt{2}, 2, \sqrt{2}, \sqrt{2})^T\) nằm gọn trong \(\mathbb{R}_+^2 \times \mathcal{Q}^3\) (vì \(\sqrt{2+2} = 2\))! Toàn bộ phần phi tuyến đã được đóng gói sạch sẽ vào hình học của nón \(K\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Nếu ràng buộc bất đẳng thức thông thường trong một bài toán LP tổng quát được thay bằng một &lt;strong&gt;bất đẳng thức tổng quát theo nón lồi&lt;/strong&gt; \(K\), ta thu được &lt;strong&gt;bài toán quy hoạch nón&lt;/strong&gt; (Conic Programming - CP).&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-quy-hoạch-nón&quot;&gt;Bài toán Quy hoạch Nón&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Fx + g \preceq_K 0} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;c, x \in \mathbb{R}^{n}, \; A \in \mathbb{R}^{p \times n}, \text{ và } b \in \mathbb{R}^{p}.
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;\(F: \mathbb{R}^n \rightarrow Y\) là một ánh xạ tuyến tính và \(g \in Y\), với \(Y\) là một không gian Euclid hữu hạn chiều và \(K \subseteq Y\) là một nón lồi chính quy.&lt;/li&gt;
  &lt;li&gt;LP là trường hợp đặc biệt khi \(K = \mathbb{R}_{+}^m\), do đó \(\text{LP} \subseteq \text{CP}\).&lt;/li&gt;
  &lt;li&gt;SDP là trường hợp đặc biệt khi \(K = \mathbb{S}_{+}^k\), do đó \(\text{SDP} \subseteq \text{CP}\).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>05-05 Quy Hoạch Bán Xác Định (SDP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_05_Semidefinite_Programming_(SDP)/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_05_Semidefinite_Programming_(SDP)</id>
   <content type="html">&lt;p&gt;Trong Quy hoạch Tuyến tính, ta yêu cầu một vector \(x \in \mathbb{R}^n\) không âm theo từng thành phần: \(x_i \ge 0\). Bây giờ hãy nâng cấp trí tưởng tượng lên một chiều sâu hoàn toàn mới: thay vector \(x\) bằng một &lt;strong&gt;ma trận đối xứng&lt;/strong&gt; \(X \in \mathbb{S}^n\), và thay điều kiện “không âm từng phần tử” bằng điều kiện “mọi trị riêng đều không âm” — tức ma trận &lt;strong&gt;nửa xác định dương&lt;/strong&gt; \(X \succeq 0\)!&lt;/p&gt;

&lt;p&gt;Bước nhảy vọt tưởng chừng trừu tượng ấy sinh ra &lt;strong&gt;Quy hoạch Nửa xác định (Semidefinite Programming - SDP)&lt;/strong&gt; — một trong những phát kiến rực rỡ nhất của tối ưu hóa lồi cuối thế kỷ 20. Nhờ SDP, Goemans và Williamson (1995) đã phá vỡ kỷ lục xấp xỉ bài toán NP-khó Max-Cut với tỷ lệ đảm bảo \(0.878\), các kỹ sư điều khiển chứng minh được tính ổn định của hệ phi tuyến qua hàm Lyapunov, và các nhà nghiên cứu AI kiểm chứng được độ vững chắc của mạng nơ-ron sâu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-tư-duy-tối-ưu-trên-không-gian-ma-trận&quot;&gt;Kiến thức cần nhớ: Tư duy tối ưu trên không gian ma trận&lt;/h2&gt;

&lt;p&gt;Bốn trụ cột sau mở khóa trực giác về SDP và Bất đẳng thức Ma trận Tuyến tính (LMI):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nón Ma trận Nửa xác định dương \(\mathbb{S}_+^n\):&lt;/strong&gt; Tập tất cả ma trận đối xứng \(X\) thỏa \(v^T X v \ge 0 \; \forall v\) là một nón lồi đóng, tự đối ngẫu (với tích trong Frobenius \(\langle A, B \rangle = \operatorname{tr}(AB)\)). Khác với góc phần tư không âm có các mặt phẳng, biên của \(\mathbb{S}_+^n\) vừa cong trơn vừa có những đường gờ sắc (tại nơi trị riêng giảm hạng).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Ma trận Tuyến tính (LMI):&lt;/strong&gt; Ràng buộc \(F(x) = F_0 + x_1 F_1 + \dots + x_m F_m \succeq 0\) yêu cầu một tổ hợp affine của các ma trận đối xứng phải nửa xác định dương. Nếu mọi \(F_i\) đều là ma trận đường chéo, LMI thu gọn về đúng một hệ bất đẳng thức tuyến tính LP!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bổ đề Phần bù Schur (Schur Complement):&lt;/strong&gt; Đây là “cây đũa thần” chuyển mọi ràng buộc bậc hai và SOCP thành LMI:
\(\|u\|_2 \le t \iff \begin{pmatrix} t I &amp;amp; u \\ u^T &amp;amp; t \end{pmatrix} \succeq 0.\)
Nhờ đó ta chứng minh được ngay \(\text{LP} \subset \text{QP} \subset \text{QCQP} \subset \text{SOCP} \subset \text{SDP}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng SDP cho bài toán tổ hợp &amp;amp; Ma trận hạng thấp:&lt;/strong&gt; Khi gặp biến \(x_i \in \{-1, +1\}\), ta đặt ma trận \(X = x x^T\) thỏa \(X_{ii} = 1,\; X \succeq 0,\; \operatorname{rank}(X) = 1\). Chỉ cần bỏ ràng buộc phi lồi \(\operatorname{rank}(X) = 1\), ta thu được ngay một bài SDP lồi cực chặt!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chuyển-bài-toán-tìm-trị-riêng-lớn-nhất-và-ràng-buộc-socp-thành-lmi-22&quot;&gt;Giải thích: Chuyển bài toán tìm trị riêng lớn nhất và ràng buộc SOCP thành LMI 2×2&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 1 — Tối thiểu hóa trị riêng lớn nhất \(\lambda_{\max}(A(x))\):&lt;/strong&gt;
Cho \(A(x) = \begin{pmatrix} 1 + x &amp;amp; 2 \\ 2 &amp;amp; 3 - x \end{pmatrix}\). Tìm \(x \in \mathbb{R}\) để \(\lambda_{\max}(A(x))\) nhỏ nhất.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển thành SDP:&lt;/strong&gt; Bất đẳng thức \(\lambda_{\max}(A(x)) \le t\) tương đương với mọi trị riêng của \(tI - A(x)\) đều \(\ge 0\), tức là LMI:
\(\min_{x, t} \; t \quad \text{s.t.} \quad \begin{pmatrix} t - 1 - x &amp;amp; -2 \\ -2 &amp;amp; t - 3 + x \end{pmatrix} \succeq 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải bằng tiêu chuẩn Sylvester cho ma trận 2×2 nửa xác định dương:&lt;/strong&gt;
Cần hai phần tử đường chéo \(\ge 0\) và định thức \(\ge 0\):
\((t - 1 - x)(t - 3 + x) - 4 \ge 0 \iff (t - 2)^2 - (x - 1)^2 \ge 4.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm giá trị nhỏ nhất của \(t\):&lt;/strong&gt;
Ta có \((t - 2)^2 \ge 4 + (x - 1)^2 \ge 4\). Muốn \(t\) nhỏ nhất, chọn \(x^\star = 1\) để triệt tiêu \((x-1)^2\), cho \((t - 2)^2 = 4 \implies t^\star = 4\) (vì cần \(t - 1 - x = t - 2 \ge 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra trực tiếp:&lt;/strong&gt; Tại \(x^\star = 1\), \(A(1) = \begin{pmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{pmatrix}\) có hai trị riêng là \(4\) và \(0\), vậy \(\lambda_{\max}(A(1)) = 4\) đúng bằng \(t^\star\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Nếu ràng buộc bất đẳng thức tuyến tính trong một bài toán LP tổng quát được thay bằng một &lt;strong&gt;bất đẳng thức ma trận tuyến tính&lt;/strong&gt; (Linear Matrix Inequality - LMI), ta thu được &lt;strong&gt;bài toán quy hoạch nửa xác định&lt;/strong&gt; (hay &lt;em&gt;quy hoạch bán xác định&lt;/em&gt;, Semidefinite Programming - SDP).&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-quy-hoạch-nửa-xác-định-dạng-bất-đẳng-thức&quot;&gt;Bài toán Quy hoạch Nửa xác định (dạng bất đẳng thức)&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{x_1 F_1 + \dotsb + x_n F_n + G \preceq 0} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;G, F_1, \dotsb, F_n \in \mathbb{S}^{k} \text{ và } A \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Nếu \(G, F_1, \dotsb, F_n\) đều là các ma trận đường chéo kích thước \(k \times k\), ràng buộc LMI trên tương đương với \(k\) bất đẳng thức tuyến tính, và bài toán SDP rút gọn thành một bài toán LP.&lt;/li&gt;
  &lt;li&gt;Nhiều ràng buộc LMI có thể gộp thành một LMI duy nhất bằng cách ghép thành các ma trận đường chéo khối:
    &lt;blockquote&gt;
      &lt;p&gt;\(x_1\hat{F_1} + \dotsb + x_n\hat{F_n} + \hat{G} \preceq 0, \quad x_1\tilde{F_1} + \dotsb + x_n\tilde{F_n} + \tilde{G} \preceq 0\)
tương đương với một LMI duy nhất:
\(x_1
\begin{bmatrix}
    \hat{F_1} &amp;amp; 0 \\\\
    0 &amp;amp; \tilde{F_1} \\\\
\end{bmatrix} + 
x_2
\begin{bmatrix}
    \hat{F_2} &amp;amp; 0 \\\\
    0 &amp;amp; \tilde{F_2} \\\\
\end{bmatrix} + 
\dotsb
+
x_n
\begin{bmatrix}
    \hat{F_n} &amp;amp; 0 \\\\
    0 &amp;amp; \tilde{F_n} \\\\
\end{bmatrix} + 
\begin{bmatrix}
    \hat{G} &amp;amp; 0 \\\\
    0 &amp;amp; \tilde{G} \\\\
\end{bmatrix}
\preceq 0\)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;sdp-ở-dạng-chuẩn&quot;&gt;SDP ở dạng chuẩn&lt;/h2&gt;
&lt;p&gt;Bài toán quy hoạch nửa xác định ở dạng chuẩn được biểu diễn theo biến ma trận \(X \in \mathbb{S}^n\) như sau:&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-sdp-dạng-chuẩn&quot;&gt;Bài toán SDP dạng chuẩn&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{X} &amp;amp;&amp;amp;{\mathrm{tr}(CX)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\mathrm{tr}(A_i X) = b_i, \quad i = 1, \dotsc, m} \\\\
   &amp;amp; &amp;amp;&amp;amp;{X \succeq 0},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;C, A_i \in \mathbb{S}^n, \; X \in \mathbb{S}^n.
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Nhắc lại: tích vô hướng Frobenius giữa hai ma trận đối xứng là \(\mathrm{tr}(CX) = \sum_{i,j=1}^n C_{ij}X_{ij}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mọi bài toán SDP ở dạng bất đẳng thức đều có thể chuyển về SDP dạng chuẩn theo các bước sau:&lt;/p&gt;

&lt;h3 id=&quot;chuyển-đổi-sdp-về-dạng-chuẩn&quot;&gt;Chuyển đổi SDP về dạng chuẩn&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bước 1.&lt;/strong&gt; Đưa thêm ma trận biến phụ \(S \succeq 0\) để chuyển ràng buộc bất đẳng thức LMI thành ràng buộc đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x, S} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\sum_{l=1}^n F_l x_l+ S = -G} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b}\\\\
   &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 2.&lt;/strong&gt; Viết lại ràng buộc đẳng thức ma trận ở Bước 1 theo từng phần tử \((i, j)\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x, S} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\sum_{l=1}^n (F_l x_l)_{ij} + S_{ij} = -G_{ij}, \quad i,j = 1, \dotsc, k} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b}\\\\
   &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 3.&lt;/strong&gt; Tách biến tự do \(x\) thành hiệu của hai biến không âm:
\(x = x^{+} - x^{-}\), với \(x^{+} \succeq 0\) và \(x^{-} \succeq 0\).&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x^{+}, x^{-}, S} &amp;amp;&amp;amp;{c^T (x^{+} - x^{-}) + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\sum_{l=1}^n (F_l x^{+}_l)_{ij} - \sum_{l=1}^n (F_l x^{-}_l)_{ij} + S_{ij} = -G_{ij}, \quad i,j = 1, \dotsc, k} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax^{+} - Ax^{-} = b}\\\\
   &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}\\\\
   &amp;amp; &amp;amp;&amp;amp;{x^{+}, \; x^{-} \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 4.&lt;/strong&gt; Định nghĩa các ma trận đường chéo khối \(X, C, \tilde{A}, \tilde{b}\) (các ô để trống đều bằng 0):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(X = 
\begin{bmatrix}
\operatorname{diag}(x^{+})\\\\
 &amp;amp; \operatorname{diag}(x^{-})\\\\
&amp;amp;&amp;amp; S \\\\
\end{bmatrix}
, \quad
C = 
\begin{bmatrix}
\operatorname{diag}(c)\\\\
&amp;amp; -\operatorname{diag}(c) &amp;amp;\\\\
&amp;amp; &amp;amp; O_{k \times k}\\\\
\end{bmatrix}
,\)
với các ma trận ràng buộc đối xứng \(P_{ij}\) (có khối ứng với \(S\) đặt \(1\) ở vị trí \((i,i)\) nếu \(i=j\) hoặc \(1/2\) ở hai vị trí \((i,j), (j,i)\) nếu \(i \neq j\)) và
\(Q_{i}= 
\begin{bmatrix}
\operatorname{diag}(A_i)\\\\
&amp;amp;-\operatorname{diag}(A_i)\\\\
&amp;amp;&amp;amp;O_{k \times k}\\\\
\end{bmatrix}\)
(trong đó \(A_i\) là hàng thứ \(i\) của ma trận \(A\)), sao cho
\(\mathrm{tr}(P_{ij}X) = -G_{ij}, \qquad \mathrm{tr}(Q_i X) = b_i.\)
Gom tất cả các ma trận \(P_{ij}\) và \(Q_i\) thành danh sách \(\tilde{A}_1, \dotsc, \tilde{A}_m\) cùng vectơ vế phải \(\tilde{b}\) tương ứng.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 5.&lt;/strong&gt; Thay các biểu thức trên vào bài toán ở Bước 3 (bỏ qua hằng số \(d\)), ta thu được dạng chuẩn của SDP:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{X} &amp;amp;&amp;amp;{\mathrm{tr}(CX)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\mathrm{tr}(\tilde{A}_i X) = \tilde{b}_i, \quad i = 1, \dotsc, m} \\\\
   &amp;amp; &amp;amp;&amp;amp;{X \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;mối-quan-hệ-giữa-socp-và-sdp&quot;&gt;Mối quan hệ giữa SOCP và SDP&lt;/h2&gt;
&lt;p&gt;Nhờ sử dụng &lt;strong&gt;bù Schur&lt;/strong&gt; ([&lt;a href=&quot;https://en.wikipedia.org/wiki/Schur_complement&quot;&gt;8&lt;/a&gt;]), mọi ràng buộc nón bậc hai của SOCP đều có thể viết tương đương dưới dạng một LMI. Do đó, SOCP là một trường hợp đặc biệt của SDP, tức là \(SOCP \subseteq SDP\).&lt;/p&gt;

&lt;h3 id=&quot;nhắc-lại-bài-toán-quy-hoạch-nón-bậc-hai&quot;&gt;Nhắc lại: Bài toán Quy hoạch Nón Bậc hai&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{f^T x} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\| A_i x + b_i \|_2 \leq c_i^T x + d_i, \quad i = 1, \dotsc, m}\\\\
   &amp;amp; &amp;amp;&amp;amp;{Fx = g}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;chuyển-đổi-socp-sang-sdp-bằng-bù-schur&quot;&gt;Chuyển đổi SOCP sang SDP bằng bù Schur&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{f^T x} \\\\
   &amp;amp;\text{subject to } 
   &amp;amp;&amp;amp;
   \begin{bmatrix}
   (c_i^T x + d_i)I    &amp;amp; A_i x + b_i \\\\
   (A_i x + b_i)^T &amp;amp; c_i^T x + d_i \\\\
   \end{bmatrix} \succeq 0, \quad i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Fx = g}.
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>05-04 Quy Hoạch Nón Bậc Hai (SOCP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_04_Second_Order_Cone_Programming_(SOCP)/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_04_Second_Order_Cone_Programming_(SOCP)</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng một chiếc ốc quế kem dựng thẳng đứng trong không gian 3 chiều: đáy nhọn tại gốc tọa độ \((0,0,0)\) và miệng mở dần lên trên theo quy luật \(\sqrt{x_1^2 + x_2^2} \le t\). Trong tối ưu hóa lồi, hình khối quen thuộc ấy có một cái tên rất trang trọng: &lt;strong&gt;Nón bậc hai (Second-Order Cone / Lorentz Cone)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Khi bạn cực tiểu hóa một hàm tuyến tính \(f^T x\) dưới các ràng buộc nằm trong nón bậc hai \(\|A_i x + b_i\|_2 \le c_i^T x + d_i\), bạn có &lt;strong&gt;Quy hoạch Nón Bậc hai (SOCP)&lt;/strong&gt;. Đừng để vẻ ngoài đơn giản đánh lừa: SOCP đủ sức nuốt trọn LP, QP, QCQP, tối ưu bền vững (robust LP với nhiễu ellipsoid), bài toán vị trí kho bãi Weber (tổng khoảng cách Euclidean), và thiết kế chùm sóng ăng-ten — trong khi các bộ giải điểm trong hiện đại giải SOCP gần như nhanh ngang ngửa LP!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-sức-mạnh-biểu-diễn-của-nón-bậc-hai&quot;&gt;Kiến thức cần nhớ: Sức mạnh biểu diễn của Nón Bậc Hai&lt;/h2&gt;

&lt;p&gt;Bốn trụ cột dưới đây giúp bạn làm chủ nghệ thuật nhận diện và chuyển đổi về SOCP:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hình học Nón bậc hai \(\mathcal{Q}_{k+1}\):&lt;/strong&gt; Tập \(\{(u, t) \in \mathbb{R}^k \times \mathbb{R} : \|u\|_2 \le t\}\) là một nón lồi, đóng, nhọn và &lt;strong&gt;tự đối ngẫu&lt;/strong&gt; (\(\mathcal{Q}^* = \mathcal{Q}\)). Tính tự đối ngẫu này là lý do các thuật toán điểm trong nguyên–đối ngẫu giải SOCP cực kỳ hiệu quả.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mẹo chuyển ràng buộc Hyperbolic &amp;amp; Bậc hai sang SOCP:&lt;/strong&gt; Đẳng thức đại số vàng \(u^2 \le v \cdot w \iff \left\|\begin{pmatrix} 2u \\ v - w \end{pmatrix}\right\|_2 \le v + w\) (với \(v, w \ge 0\)) cho phép biến mọi ràng buộc phân thức, căn bậc hai, và mọi ràng buộc bậc hai lồi (QP, QCQP) thành ràng buộc nón bậc hai chuẩn!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bao hàm LP, QP, QCQP:&lt;/strong&gt; Đặt \(A_i = 0, b_i = 0\) thì SOCP thu về LP. Dùng biến phụ \(t\) đưa hàm mục tiêu bậc hai \(\|Px + q\|_2^2 \le t\) vào ràng buộc hyperbolic thì mọi QP và QCQP đều trở thành SOCP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng Tối ưu Bền vững (Robust Linear Programming):&lt;/strong&gt; Khi hệ số ràng buộc tuyến tính \(a_i\) có sai số nằm trong ellipsoid \(\{a_i = \bar{a}_i + P_i u : \|u\|_2 \le 1\}\), điều kiện \(\sup_{\|u\|_2 \le 1} (\bar{a}_i + P_i u)^T x \le b_i\) tự động biến thành đúng một ràng buộc SOCP: \(\bar{a}_i^T x + \|P_i^T x\|_2 \le b_i\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chuyển-đổi-ràng-buộc-bậc-hai-sang-dạng-nón-socp-bằng-phép-biến-đổi-đại-số&quot;&gt;Giải thích: Chuyển đổi ràng buộc bậc hai sang dạng nón SOCP bằng phép biến đổi đại số&lt;/h3&gt;

&lt;p&gt;Xét ràng buộc bậc hai 1 biến \(x^2 \le t\) với \(t \ge 0\). Làm sao viết nó thành dạng chuẩn \(\|A z + b\|_2 \le c^T z + d\) (chỉ có chuẩn Euclidean bậc 1 ở vế trái và biểu thức tuyến tính ở vế phải)?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Dùng hằng đẳng thức \(4t = (t + 1)^2 - (t - 1)^2\):&lt;/strong&gt;
\(x^2 \le t \iff 4x^2 \le 4t = (t + 1)^2 - (t - 1)^2 \iff (2x)^2 + (t - 1)^2 \le (t + 1)^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Lấy căn bậc hai hai vế (vì \(t \ge 0 \implies t + 1 &amp;gt; 0\)):&lt;/strong&gt;
\(\left\| \begin{pmatrix} 2x \\ t - 1 \end{pmatrix} \right\|_2 \le t + 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kiểm tra bằng số cụ thể:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Thử \(x = 2,\; t = 4\) (thỏa \(2^2 = 4 \le 4\)):
Vế trái \(= \sqrt{(2\cdot 2)^2 + (4 - 1)^2} = \sqrt{16 + 9} = 5\); vế phải \(= 4 + 1 = 5\). Khớp chính xác!&lt;/li&gt;
      &lt;li&gt;Thử \(x = 3,\; t = 4\) (vi phạm \(9 &amp;gt; 4\)):
Vế trái \(= \sqrt{6^2 + 3^2} = \sqrt{45} \approx 6.708 &amp;gt; 5\). Vi phạm đúng như bài toán gốc!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt; Nhờ đúng một dòng hằng đẳng thức này, mọi bài toán QP và QCQP đều được “dịch” tự động sang SOCP để đưa vào các bộ giải nón hiện đại như ECOS, Clarabel hay MOSEK.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Nếu các ràng buộc bất đẳng thức tuyến tính trong một bài toán LP tổng quát được thay bằng các ràng buộc nón bậc hai (tức là các bất đẳng thức dạng chuẩn \(\ell_2\) của hàm affine không vượt quá một hàm affine), ta thu được &lt;strong&gt;bài toán quy hoạch nón bậc hai&lt;/strong&gt; (Second-Order Cone Programming - SOCP).&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-quy-hoạch-nón-bậc-hai&quot;&gt;Bài toán Quy hoạch Nón Bậc hai&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{f^T x} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\| A_i x + b_i \|_2 \leq c_i^T x + d_i, \quad i = 1, \dotsc, m}\\\\
   &amp;amp; &amp;amp;&amp;amp;{Fx = g},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;x \in \mathbb{R}^n \text{ là biến tối ưu, } A_i \in \mathbb{R}^{n_i \times n}, \text{ và } F \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;nhắc-lại-nón-chuẩn&quot;&gt;Nhắc lại: Nón chuẩn&lt;/h3&gt;
&lt;p&gt;Một &lt;strong&gt;nón chuẩn&lt;/strong&gt; (norm cone) là một nón lồi trong \(\mathbb{R}^{n+1}\) gồm tất cả các điểm \((x, t)\) thỏa mãn \(\| x \| \le t\) đối với một chuẩn \(\| \cdot \|\) cho trước:&lt;/p&gt;

&lt;blockquote&gt;
\[\left\{(x, t) : \| x \| \le t \right\} \text{, với chuẩn } \| \cdot \|\]
&lt;/blockquote&gt;

&lt;p&gt;Hình dưới đây minh họa nón chuẩn ứng với chuẩn \(\ell_2\) (\(\| \cdot \|_2\)), thường gọi là &lt;strong&gt;nón bậc hai&lt;/strong&gt; (second-order cone) hay &lt;em&gt;nón kem&lt;/em&gt; (ice-cream cone).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter05/05_04_norm_cone.png&quot; alt=&quot;[Fig1] Nón Chuẩn [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Nón chuẩn [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;chuyển-đổi-qcqp-sang-socp&quot;&gt;Chuyển đổi QCQP sang SOCP&lt;/h2&gt;
&lt;p&gt;Mọi bài toán QCQP lồi đều có thể viết lại dưới dạng một bài toán SOCP, tức là \(QCQP \subseteq SOCP\). Dưới đây là cách chuyển đổi trực tiếp trong trường hợp các ma trận \(P_i\) xác định dương (\(P_i \succ 0\); trường hợp nửa xác định dương tổng quát xử lý tương tự bằng dạng ép đồ thị/nón bậc hai xoay).&lt;/p&gt;

&lt;h3 id=&quot;nhắc-lại-bài-toán-quy-hoạch-bậc-hai-có-ràng-buộc-bậc-hai&quot;&gt;Nhắc lại: Bài toán Quy hoạch Bậc hai có Ràng buộc Bậc hai&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{(1/2)x^T P_0 x + q_0^T x + r_0} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{(1/2)x^T P_i x + q_i^T x + r_i \leq 0}, \quad i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;P_i \in \mathbb{S}_{+}^n \text{ với } i = 0, \dotsc, m, \text{ và } A \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 1.&lt;/strong&gt; Để tiện biến đổi (nhân đôi hàm mục tiêu và các hàm ràng buộc bất đẳng thức rồi đổi ký hiệu lại hệ số \(r_i\)), ta viết QCQP dưới dạng:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{x^T P_0 x + 2q_0^T x + r_0} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{x^T P_i x + 2q_i^T x + r_i \leq 0}, \quad i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp; P_i \in \mathbb{S}_{++}^n \text{ với } i = 0, \dotsc, m, \text{ và } A \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 2.&lt;/strong&gt; Vì \(P_0\) đối xứng xác định dương, qua phân tích trị riêng \(P_0 = Q_0 \Lambda_0^2 Q_0^T\) (với \(Q_0\) trực giao, \(Q_0^{-1} = Q_0^T\) và \(\Lambda_0\) là ma trận đường chéo chứa căn bậc hai các giá trị riêng dương), ta có thể hoàn thiện bình phương hàm mục tiêu như sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[P_0 = Q_0 \Lambda_0 \Lambda_0 Q_0^T\]
  &lt;/li&gt;
  &lt;li&gt;
\[I = Q_0 \Lambda_0 \Lambda_0^{-1} Q_0^{-1} = Q_0 \Lambda_0^{-1} \Lambda_0 Q_0^{-1}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\begin{align}
{x^T P_0 x + 2q_0^T x + r_0} &amp;amp;= {x^T P_0 x + q_0^T x + x^T q_0 + q_0^T P_0^{-1} q_0 - q_0^T P_0^{-1} q_0 + r_0}\\\\
&amp;amp;= {x^T Q_0 \Lambda_0 \Lambda_0 Q_0^T x} +
     {q_0^T Q_0 \Lambda_0^{-1} \Lambda_0 Q_0^T x} + {x^T Q_0 \Lambda_0 \Lambda_0^{-1} Q_0^T q_0} +
     {q_0^T Q_0 \Lambda_0^{-1} \Lambda_0^{-1} Q_0^T q_0} - q_0^T P_0^{-1} q_0 + r_0\\\\
&amp;amp;=(\Lambda_0 Q_0^T x + \Lambda_0^{-1} Q_0^T q_0)^T(\Lambda_0 Q_0^T x + \Lambda_0^{-1} Q_0^T q_0) - q_0^T P_0^{-1} q_0 + r_0\\\\
&amp;amp;=\| \Lambda_0 Q_0^T x + \Lambda_0^{-1} Q_0^T q_0 \|_2^2 - q_0^T P_0^{-1} q_0 + r_0.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 3.&lt;/strong&gt; Áp dụng cùng phép hoàn thiện bình phương cho từng ràng buộc bất đẳng thức rồi thay vào bài toán ở Bước 1:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{\| \Lambda_0 Q_0^T x + \Lambda_0^{-1} Q_0^T q_0 \|_2^2 - q_0^T P_0^{-1} q_0 + r_0} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\| \Lambda_i Q_i^T x + \Lambda_i^{-1} Q_i^T q_i \|_2^2 \leq q_i^T P_i^{-1} q_i - r_i}, \quad i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 4.&lt;/strong&gt; Số hạng \(-q_0^T P_0^{-1} q_0 + r_0\) trong hàm mục tiêu là hằng số nên có thể bỏ qua:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{\| \Lambda_0 Q_0^T x + \Lambda_0^{-1} Q_0^T q_0 \|_2^2} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\| \Lambda_i Q_i^T x + \Lambda_i^{-1} Q_i^T q_i \|_2^2 \leq q_i^T P_i^{-1} q_i - r_i}, \quad i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 5.&lt;/strong&gt; Đưa thêm biến vô hướng \(t \ge 0\) và lấy căn bậc hai hai vế (khi các vế phải không âm, nếu có ràng buộc có vế phải âm thì bài toán vô nghiệm):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x, t} &amp;amp;&amp;amp;{t} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;\lVert{\Lambda_{0} Q_0^T x + \Lambda_0^{-1} Q_0^T q_0} \rVert_2 \leq t\\\\
   &amp;amp; &amp;amp;&amp;amp;{\| \Lambda_i Q_i^T x + \Lambda_i^{-1} Q_i^T q_i \|_2 \leq \sqrt{q_i^T P_i^{-1} q_i - r_i}}, \quad i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán thu được là một trường hợp đặc biệt của SOCP. Như vậy, ta có quan hệ bao hàm \(QCQP \subseteq SOCP\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-03 Quy Hoạch Bậc Hai với Ràng buộc Bậc Hai (QCQP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_03_Quadratically_Constrained_Quadratic_Programming_(QCQP)/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_03_Quadratically_Constrained_Quadratic_Programming_(QCQP)</id>
   <content type="html">&lt;p&gt;Trong Quy hoạch Bậc hai (QP), hàm mục tiêu đã có độ cong bậc hai nhưng tập khả thi vẫn bị đóng khung bởi các bức tường phẳng tuyến tính. Thế nhưng ngoài đời thực, nhiều giới hạn vật lý mang hình dạng &lt;strong&gt;cong tròn hoặc ellipsoid&lt;/strong&gt;: năng lượng phát sóng của một dàn ăng-ten không vượt quá \(P_{\max}\) (\(\|x\|_2^2 \le P_{\max}\)), hay phương sai rủi ro của danh mục đầu tư không vượt quá ngưỡng \(\sigma_{\max}^2\) (\(x^T \Sigma x \le \sigma_{\max}^2\)).&lt;/p&gt;

&lt;p&gt;Khi ta cho phép cả hàm mục tiêu lẫn các ràng buộc bất đẳng thức đều là các hàm bậc hai lồi, ta bước lên nấc thang mới mang tên &lt;strong&gt;QCQP (Quadratically Constrained Quadratic Programming)&lt;/strong&gt; — lớp bài toán lồi tổng quát hóa trực tiếp QP và là tiền đề ngay trước Quy hoạch Nón Bậc hai (SOCP).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-khi-tập-khả-thi-là-giao-của-các-khối-ellipsoid&quot;&gt;Kiến thức cần nhớ: Khi tập khả thi là giao của các khối Ellipsoid&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau định hình toàn bộ bản chất của QCQP lồi:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện lồi cho mọi ma trận bậc hai:&lt;/strong&gt; Một bài QCQP có dạng \(\min \frac{1}{2}x^T P_0 x + q_0^T x + r_0\) với ràng buộc \(\frac{1}{2}x^T P_i x + q_i^T x + r_i \le 0\) (\(i = 1, \dots, m\)) và \(Ax = b\). Bài toán là &lt;strong&gt;lồi&lt;/strong&gt; khi và chỉ khi mọi ma trận \(P_0, P_1, \dots, P_m\) đều nửa xác định dương (\(\in \mathbb{S}_+^n\)). (Nếu chỉ một \(P_i\) có trị riêng âm, bài toán lập tức trở nên phi lồi và có thể NP-khó!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình học giao các Ellipsoid:&lt;/strong&gt; Mỗi ràng buộc \(\frac{1}{2}x^T P_i x + q_i^T x + r_i \le 0\) với \(P_i \succ 0\) xác định một khối ellipsoid đặc; giao của chúng là một tập lồi có biên cong trơn (trừ các đường giao giữa hai mặt ellipsoid).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ phân cấp bao hàm:&lt;/strong&gt; Nếu đặt \(P_1 = \dots = P_m = 0\), QCQP thu về đúng &lt;strong&gt;QP&lt;/strong&gt;. Ngược lại, mọi bài QCQP lồi đều chuyển được về &lt;strong&gt;SOCP&lt;/strong&gt; nhờ phân rã căn bậc hai ma trận \(P_i = L_i^T L_i\) (Cholesky), giúp giải hiệu quả bằng bộ giải nón điểm trong!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-một-bài-qcqp-tối-thiểu-hóa-khoảng-cách-trên-hình-tròn&quot;&gt;Giải thích: Giải tay một bài QCQP tối thiểu hóa khoảng cách trên hình tròn&lt;/h3&gt;

&lt;p&gt;Xét bài toán QCQP 2 biến:
\(\min_{x \in \mathbb{R}^2} \; f_0(x) = (x_1 - 3)^2 + (x_2 - 4)^2 \quad \text{thỏa mãn} \quad x_1^2 + x_2^2 \le 4.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Viết dưới dạng chuẩn QCQP và kiểm tra tính lồi:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hàm mục tiêu: \(\frac{1}{2} x^T (2I) x + (-6, -8) x + 25\), có \(P_0 = 2I \succ 0\).&lt;/li&gt;
      &lt;li&gt;Ràng buộc: \(\frac{1}{2} x^T (2I) x - 4 \le 0\), có \(P_1 = 2I \succ 0\).&lt;/li&gt;
      &lt;li&gt;Vậy đây là QCQP lồi chặt!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Kiểm tra điểm cực tiểu tự do:&lt;/strong&gt;
Cực tiểu tự do của \(f_0\) là \(x_{\text{free}} = (3, 4)\). Kiểm tra ràng buộc: \(3^2 + 4^2 = 25 &amp;gt; 4\) (không khả thi!). Do đó nghiệm tối ưu buộc phải nằm trên biên đường tròn \(x_1^2 + x_2^2 = 4\) (bán kính \(R = 2\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Dùng trực giác hình học (hoặc KKT):&lt;/strong&gt;
Bài toán tương đương tìm điểm trên hình tròn tâm \((0, 0)\) bán kính \(2\) gần điểm \(a = (3, 4)\) nhất!
Khoảng cách từ gốc tọa độ đến \(a\) là \(\|a\|_2 = \sqrt{3^2 + 4^2} = 5\).
Điểm gần nhất nằm đúng trên tia nối gốc tọa độ tới \(a\) với độ dài \(2\):
\(x^\star = 2 \cdot \frac{(3, 4)}{5} = (1.2,\; 1.6).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — Kiểm chứng KKT:&lt;/strong&gt;
Tại \(x^\star = (1.2, 1.6)\), \(\nabla f_0(x^\star) = 2(x^\star - a) = (-3.6, -4.8)\), còn \(\nabla g_1(x^\star) = 2x^\star = (2.4, 3.2)\).
Ta thấy \(\nabla f_0(x^\star) + \lambda \nabla g_1(x^\star) = 0\) với nhân tử Lagrange \(\lambda = 1.5 &amp;gt; 0\)! Giá trị tối ưu là \(f_0^\star = (5 - 2)^2 = 9\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Nếu các ràng buộc bất đẳng thức tuyến tính trong một bài toán quy hoạch bậc hai được thay bằng các ràng buộc bậc hai lồi, ta thu được &lt;strong&gt;bài toán quy hoạch bậc hai có ràng buộc bậc hai&lt;/strong&gt; (Quadratically Constrained Quadratic Programming - QCQP).&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-quy-hoạch-bậc-hai-có-ràng-buộc-bậc-hai&quot;&gt;Bài toán Quy hoạch Bậc hai có Ràng buộc Bậc hai&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{(1/2)x^T P_0 x + q_0^T x + r_0} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{(1/2)x^T P_i x + q_i^T x + r_i \leq 0}, \quad i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;P_i \in \mathbb{S}_{+}^n \text{ với } i = 0, \dotsc, m, \text{ và } A \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;mối-quan-hệ-giữa-qp-và-qcqp&quot;&gt;Mối quan hệ giữa QP và QCQP&lt;/h2&gt;
&lt;p&gt;Khi \(P_i = 0\) với mọi \(i = 1, \dotsc, m\) trong các ràng buộc của QCQP, bài toán rút gọn về một bài toán QP. Do đó, QP là một trường hợp đặc biệt của QCQP, ký hiệu \(QP \subseteq QCQP\).&lt;/p&gt;

&lt;h3 id=&quot;nhắc-lại-bài-toán-quy-hoạch-bậc-hai&quot;&gt;Nhắc lại: Bài toán Quy hoạch Bậc hai&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{(1/2)x^T P x + q^T x + r} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Gx \preceq h} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;P \in \mathbb{S}_{+}^n, \; G \in \mathbb{R}^{m \times n}, \text{ và } A \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>05-02 Quy Hoạch Bậc Hai (QP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_02_Quadratic_Programming_(QP)-copy/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_02_Quadratic_Programming_(QP) copy</id>
   <content type="html">&lt;p&gt;Năm 1952, Harry Markowitz đặt một câu hỏi làm thay đổi hoàn toàn Phố Wall: nếu chỉ tối đa hóa lợi nhuận kỳ vọng bằng Quy hoạch Tuyến tính (LP), mô hình sẽ dồn 100% tiền vào đúng một cổ phiếu rủi ro nhất! Làm sao vừa tối đa hóa lợi nhuận tuyến tính \(\mu^T x\), vừa giữ rủi ro phương sai \(x^T \Sigma x\) ở mức thấp nhất? Câu trả lời chính là &lt;strong&gt;Quy hoạch Bậc hai (Quadratic Programming - QP)&lt;/strong&gt; — bài toán giữ nguyên tập khả thi đa diện tuyến tính của LP nhưng nâng hàm mục tiêu lên dạng bậc hai lồi \(\frac{1}{2} x^T Q x + c^T x\).&lt;/p&gt;

&lt;p&gt;Từ tối ưu danh mục đầu tư, điều khiển dự báo mô hình (MPC) trên xe tự lái và tên lửa SpaceX, cho đến huấn luyện máy vector hỗ trợ (SVM) — QP là một trong những bài toán được giải hàng tỷ lần mỗi ngày trong công nghiệp.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cấu-trúc-đại-số-và-hình-học-của-qp&quot;&gt;Kiến thức cần nhớ: Cấu trúc đại số và hình học của QP&lt;/h2&gt;

&lt;p&gt;Để nắm vững QP cả về lý thuyết lẫn thực hành, hãy tập trung vào bốn trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện lồi \(Q \succeq 0\) (Positive Semidefiniteness):&lt;/strong&gt; Hàm mục tiêu \(f(x) = \frac{1}{2} x^T Q x + c^T x\) có Hessian là \(Q\) (với \(Q = Q^T\)). Bài toán QP là lồi khi và chỉ khi \(Q \in \mathbb{S}_+^n\) (mọi trị riêng của \(Q\) đều không âm). Nếu \(Q \succ 0\) (xác định dương chặt), hàm lồi chặt và nghiệm tối ưu là duy nhất!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình học Ellipsoid trên Đa diện:&lt;/strong&gt; Khác với LP (đường đồng mức là mặt phẳng song song nên nghiệm luôn ở đỉnh), đường đồng mức của QP là các &lt;strong&gt;ellipsoid đồng tâm&lt;/strong&gt; quanh điểm cực tiểu tự do \(x_{\text{unc}} = -Q^{-1}c\). Do đó, nghiệm tối ưu của QP có thể nằm ở đỉnh, giữa một cạnh/mặt, hoặc nằm gọn bên trong đa diện!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển đổi về dạng chuẩn &amp;amp; Hệ KKT tuyến tính:&lt;/strong&gt; Khi không có ràng buộc bất đẳng thức (chỉ có \(Ax = b\)), bài toán QP giải được chính xác bằng &lt;strong&gt;một hệ phương trình tuyến tính KKT duy nhất&lt;/strong&gt;. Khi có ràng buộc bất đẳng thức \(Gx \le h\), các thuật toán tập tích cực (active-set), điểm trong (interior-point) hoặc ADMM (như bộ giải OSQP) giải cực nhanh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mối liên hệ mật thiết với LP &amp;amp; Least Squares:&lt;/strong&gt; Đặt \(Q = 0\) thì QP thu gọn về LP; bỏ hết ràng buộc và đặt \(Q = 2A^T A,\; c = -2A^T b\) thì QP chính là Bình phương tối thiểu tuyến tính!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-bài-toán-phân-bổ-danh-mục-đầu-tư-markowitz-qp-2-tài-sản&quot;&gt;Giải thích: Giải tay bài toán phân bổ danh mục đầu tư Markowitz (QP 2 tài sản)&lt;/h3&gt;

&lt;p&gt;Giả sử bạn có 1 đơn vị vốn (\(x_1 + x_2 = 1,\; x_1, x_2 \ge 0\)) phân bổ vào 2 tài sản có ma trận hiệp phương sai rủi ro \(Q = \begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 4 \end{pmatrix}\) và lợi nhuận kỳ vọng \(\mu = (1,\; 2)^T\). Ta giải QP:
\(\min_{x_1, x_2} \; \frac{1}{2} x^T Q x - \mu^T x = x_1^2 + 2x_2^2 - x_1 - 2x_2 \quad \text{s.t.} \quad x_1 + x_2 = 1,\; x_1, x_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Kiểm tra tính lồi:&lt;/strong&gt; \(Q = \operatorname{diag}(2, 4)\) có trị riêng \(\lambda_1 = 2 &amp;gt; 0,\; \lambda_2 = 4 &amp;gt; 0 \implies Q \succ 0\). Vậy QP lồi chặt và có nghiệm duy nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Khử ràng buộc đẳng thức \(x_2 = 1 - x_1\) (với \(x_1 \in [0, 1]\)):&lt;/strong&gt;
\(\phi(x_1) = x_1^2 + 2(1 - x_1)^2 - x_1 - 2(1 - x_1) = x_1^2 + 2 - 4x_1 + 2x_1^2 - x_1 - 2 + 2x_1 = 3x_1^2 - 3x_1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Tìm cực tiểu:&lt;/strong&gt;
\(\phi&apos;(x_1) = 6x_1 - 3 = 0 \implies x_1^\star = 0.5.\)
Vì \(0.5 \in [0, 1]\), ta suy ra \(x_2^\star = 0.5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — So sánh với nghiệm LP (nếu bỏ số hạng bậc hai rủi ro):&lt;/strong&gt;
Nếu giải LP \(\min (-x_1 - 2x_2)\), ta sẽ đặt toàn bộ vốn vào tài sản 2: \((0, 1)\). Nhờ số hạng bậc hai rủi ro trong QP, nghiệm tối ưu tự động &lt;strong&gt;đa dạng hóa&lt;/strong&gt; về \((0.5, 0.5)\) (nằm giữa đoạn thẳng khả thi, không nằm ở hai đỉnh!) với giá trị tối ưu \(f^\star = 3(0.25) - 3(0.5) = -0.75\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Một &lt;strong&gt;bài toán quy hoạch bậc hai&lt;/strong&gt; (Quadratic Programming - QP) là bài toán tối ưu hóa lồi trong đó hàm mục tiêu là hàm bậc hai lồi và tất cả các ràng buộc đều là hàm affine. Dạng tổng quát của bài toán quy hoạch bậc hai được phát biểu như sau:&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-quy-hoạch-bậc-hai-tổng-quát&quot;&gt;Bài toán Quy hoạch Bậc hai tổng quát&lt;/h3&gt;
&lt;p&gt;\(\begin{align}
    \text{minimize}_{x} \quad &amp;amp;\frac{1}{2}x^T P x + q^T x + r \\
    \text{subject to} \quad &amp;amp;Gx \preceq h \\
    &amp;amp;Ax = b
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;trong đó:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(P \in \mathbb{S}_{+}^n\) (ma trận đối xứng nửa xác định dương)&lt;/li&gt;
  &lt;li&gt;\(G \in \mathbb{R}^{m \times n}\) (ma trận ràng buộc bất đẳng thức)&lt;/li&gt;
  &lt;li&gt;\(A \in \mathbb{R}^{p \times n}\) (ma trận ràng buộc đẳng thức)&lt;/li&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) (vectơ biến quyết định)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các tính chất chính của QP:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hằng số \(r\) trong hàm mục tiêu không làm thay đổi nghiệm tối ưu \(x^*\) nên thường có thể bỏ qua khi giải.&lt;/li&gt;
  &lt;li&gt;Nếu điều kiện \(P \in \mathbb{S}_{+}^n\) không được thỏa mãn, bài toán không phải là bài toán lồi.&lt;/li&gt;
  &lt;li&gt;Trong tối ưu hóa lồi, khi nhắc đến QP, điều kiện \(P \in \mathbb{S}_{+}^n\) luôn được ngầm giả định.&lt;/li&gt;
  &lt;li&gt;Về mặt hình học, bài toán QP tìm cực tiểu của một hàm bậc hai lồi trên một tập khả thi dạng đa diện.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;nón-nửa-xác-định-dương-mathbbs_n&quot;&gt;Nón nửa xác định dương \(\mathbb{S}_{+}^n\)&lt;/h3&gt;

&lt;p&gt;Ký hiệu \(\mathbb{S}_{+}^n\) biểu diễn &lt;strong&gt;nón các ma trận nửa xác định dương&lt;/strong&gt;, một khái niệm nền tảng trong tối ưu hóa lồi:&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt;&lt;/p&gt;
  &lt;blockquote&gt;
\[\mathbb{S}_{+}^n = \{ X \in \mathbb{S}^n : X \succeq 0 \}\]
  &lt;/blockquote&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;trong đó:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbb{S}^n\) là tập tất cả các &lt;strong&gt;ma trận đối xứng&lt;/strong&gt; kích thước \(n \times n\).&lt;/li&gt;
  &lt;li&gt;\(X \succeq 0\) có nghĩa là ma trận \(X\) &lt;strong&gt;nửa xác định dương&lt;/strong&gt; (bán xác định dương).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tính chất chính:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện nửa xác định dương:&lt;/strong&gt; Một ma trận đối xứng \(P\) là nửa xác định dương khi và chỉ khi:
    &lt;ul&gt;
      &lt;li&gt;Tất cả các giá trị riêng của \(P\) đều không âm (\(\lambda_i \geq 0\)), hoặc tương đương&lt;/li&gt;
      &lt;li&gt;\(v^T P v \geq 0\) với mọi vectơ \(v \in \mathbb{R}^n\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất nón lồi:&lt;/strong&gt; \(\mathbb{S}_{+}^n\) là một nón lồi, vì với mọi \(\theta_1, \theta_2 \geq 0\) và \(A, B \in \mathbb{S}_{+}^n\), ta có \(\theta_1 A + \theta_2 B \in \mathbb{S}_{+}^n\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ với \(n = 2\):&lt;/strong&gt;
Đối với ma trận đối xứng \(2 \times 2\) dạng \(P = \begin{bmatrix} a &amp;amp; b \\ b &amp;amp; c \end{bmatrix}\), điều kiện \(P \in \mathbb{S}_{+}^2\) tương đương với:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(a \geq 0\) và \(c \geq 0\) (các phần tử trên đường chéo chính không âm),&lt;/li&gt;
  &lt;li&gt;\(ac - b^2 \geq 0\) (định thức không âm).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Vai trò của điều kiện này trong QP:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Điều kiện \(P \in \mathbb{S}_{+}^n\) đảm bảo hàm mục tiêu \(\frac{1}{2}x^T P x + q^T x + r\) là hàm lồi.&lt;/li&gt;
  &lt;li&gt;Nếu thiếu điều kiện này, hàm mục tiêu có thể có nhiều cực tiểu địa phương và bài toán không còn là bài toán lồi.&lt;/li&gt;
  &lt;li&gt;Nhờ tính lồi, mọi cực tiểu địa phương của QP đều là cực tiểu toàn cục.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bất-đẳng-thức-theo-thành-phần-gx-preceq-h&quot;&gt;Bất đẳng thức theo thành phần \(Gx \preceq h\)&lt;/h3&gt;

&lt;p&gt;Ký hiệu \(Gx \preceq h\) biểu diễn hệ &lt;strong&gt;ràng buộc bất đẳng thức tuyến tính theo từng thành phần&lt;/strong&gt;:&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt;
\(Gx \preceq h \quad \Leftrightarrow \quad (Gx)_i \leq h_i \text{ với mọi } i = 1, 2, \ldots, m\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;trong đó:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(G \in \mathbb{R}^{m \times n}\) là ma trận hệ số ràng buộc,&lt;/li&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) là vectơ biến quyết định,&lt;/li&gt;
  &lt;li&gt;\(h \in \mathbb{R}^m\) là vectơ vế phải,&lt;/li&gt;
  &lt;li&gt;\(m\) là số lượng ràng buộc bất đẳng thức.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dạng khai triển:&lt;/strong&gt;
Bất đẳng thức vectơ \(Gx \preceq h\) tương đương với hệ:
\(\begin{align}
g_1^T x &amp;amp;\leq h_1 \\
g_2^T x &amp;amp;\leq h_2 \\
&amp;amp;\vdots \\
g_m^T x &amp;amp;\leq h_m
\end{align}\)&lt;/p&gt;

&lt;p&gt;trong đó \(g_i^T\) là hàng thứ \(i\) của ma trận \(G\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;
Xét \(G = \begin{bmatrix} 1 &amp;amp; 2 \\ -1 &amp;amp; 3 \\ 0 &amp;amp; -1 \end{bmatrix}\), \(x = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\), và \(h = \begin{bmatrix} 5 \\ 2 \\ -1 \end{bmatrix}\).&lt;/p&gt;

&lt;p&gt;Khi đó \(Gx \preceq h\) tương đương với hệ:
\(\begin{align}
x_1 + 2x_2 &amp;amp;\leq 5 \\
-x_1 + 3x_2 &amp;amp;\leq 2 \\
-x_2 &amp;amp;\leq -1 \quad \text{(tức là } x_2 \geq 1\text{)}
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa hình học:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Mỗi bất đẳng thức \(g_i^T x \leq h_i\) xác định một &lt;strong&gt;nửa không gian&lt;/strong&gt; trong \(\mathbb{R}^n\).&lt;/li&gt;
  &lt;li&gt;Miền khả thi là &lt;strong&gt;giao&lt;/strong&gt; của tất cả các nửa không gian này.&lt;/li&gt;
  &lt;li&gt;Giao đó tạo thành một &lt;strong&gt;tập đa diện&lt;/strong&gt; (polyhedron), hoặc một đa diện lồi bị chặn (polytope) nếu nó bị chặn.&lt;/li&gt;
  &lt;li&gt;Do đó, ràng buộc \(Gx \preceq h\) xác định &lt;strong&gt;tập khả thi đa diện&lt;/strong&gt; của bài toán QP.&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter05/05_02_geometric_interpretation_of_QP.png&quot; alt=&quot;[Fig 1] Geometric interpretation of QP [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Minh họa hình học của bài toán QP [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;qp-ở-dạng-chuẩn&quot;&gt;QP ở dạng chuẩn&lt;/h2&gt;

&lt;p&gt;Dạng chuẩn của bài toán quy hoạch bậc hai được viết như sau:&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-qp-dạng-chuẩn&quot;&gt;Bài toán QP dạng chuẩn&lt;/h3&gt;
&lt;p&gt;\(\begin{align}
    \text{minimize}_{x} \quad &amp;amp;\frac{1}{2}x^T P x + q^T x + r \\
    \text{subject to} \quad &amp;amp;A x = b \\
    &amp;amp;x \succeq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;Mọi bài toán quy hoạch bậc hai tổng quát đều có thể đưa về dạng chuẩn theo các bước sau:&lt;/p&gt;

&lt;h3 id=&quot;chuyển-đổi-qp-tổng-quát-về-dạng-chuẩn&quot;&gt;Chuyển đổi QP tổng quát về dạng chuẩn&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bước 1.&lt;/strong&gt; Đưa thêm vectơ biến phụ \(s \succeq 0\) để chuyển ràng buộc bất đẳng thức thành ràng buộc đẳng thức:
\(\begin{align}
    \text{minimize}_{x, s} \quad &amp;amp;\frac{1}{2}x^T P x + q^T x + r \\
    \text{subject to} \quad &amp;amp;Gx + s = h \\
    &amp;amp;Ax = b \\
    &amp;amp;s \succeq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 2.&lt;/strong&gt; Tách biến tự do \(x\) thành hiệu của hai biến không âm:
\(x = x^{+} - x^{-}, \quad \text{với } x^{+}, x^{-} \succeq 0\)&lt;/p&gt;

\[\begin{align}
    \text{minimize}_{x^{+}, x^{-}, s} \quad &amp;amp;\frac{1}{2}(x^{+} - x^{-})^T P (x^{+} - x^{-}) + q^T x^{+} - q^T x^{-} + r\\
    \text{subject to} \quad &amp;amp;Gx^{+} - Gx^{-} + s = h \\
    &amp;amp;Ax^{+} - Ax^{-} = b \\
    &amp;amp;s \succeq 0 \\
    &amp;amp;x^{+} \succeq 0, \quad x^{-} \succeq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Bước 3.&lt;/strong&gt; Định nghĩa các biến và ma trận khối \(\tilde{x}\), \(\tilde{q}\), \(\tilde{b}\), \(\tilde{A}\), \(\tilde{P}\):&lt;/p&gt;

\[\tilde{x} =
\begin{bmatrix}
x^{+} \\
x^{-} \\
s
\end{bmatrix}, \quad
\tilde{q} =
\begin{bmatrix}
q \\
-q \\
0
\end{bmatrix}, \quad
\tilde{b} =
\begin{bmatrix}
h \\
b
\end{bmatrix}\]

\[\tilde{A} =
\begin{bmatrix}
G &amp;amp; -G &amp;amp; I \\
A &amp;amp; -A &amp;amp; O
\end{bmatrix}, \quad
\tilde{P} =
\begin{bmatrix}
 P &amp;amp; -P &amp;amp; O \\
-P &amp;amp;  P &amp;amp; O \\
 O &amp;amp;  O &amp;amp; O
\end{bmatrix}\]

&lt;p&gt;&lt;strong&gt;Bước 4.&lt;/strong&gt; Thay các biểu thức ở Bước 3 vào bài toán ở Bước 2 để thu được dạng chuẩn:&lt;/p&gt;

\[\begin{align}
    \text{minimize}_{\tilde{x}} \quad &amp;amp;\frac{1}{2}\tilde{x}^T \tilde{P} \tilde{x} + \tilde{q}^T \tilde{x} + r \\
    \text{subject to} \quad &amp;amp;\tilde{A} \tilde{x} = \tilde{b} \\
    &amp;amp;\tilde{x} \succeq 0
\end{align}\]

&lt;h2 id=&quot;quy-hoạch-tuyến-tính-là-trường-hợp-đặc-biệt-của-qp&quot;&gt;Quy hoạch tuyến tính là trường hợp đặc biệt của QP&lt;/h2&gt;

&lt;p&gt;Khi ma trận \(P = 0\) (tức loại bỏ số hạng bậc hai khỏi hàm mục tiêu), bài toán QP trở thành bài toán quy hoạch tuyến tính (LP). Vì vậy LP là một trường hợp đặc biệt của QP, ký hiệu \(\text{LP} \subseteq \text{QP}\).&lt;/p&gt;

&lt;h3 id=&quot;nhắc-lại-lp-tổng-quát&quot;&gt;Nhắc lại: LP tổng quát&lt;/h3&gt;
&lt;p&gt;\(\begin{align}
    \text{minimize}_{x} \quad &amp;amp;c^T x + d \\
    \text{subject to} \quad &amp;amp;Gx \preceq h \\
    &amp;amp;Ax = b
\end{align}\)
trong đó \(G \in \mathbb{R}^{m \times n}\) và \(A \in \mathbb{R}^{p \times n}\).&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-1-tối-ưu-hóa-danh-mục-đầu-tư&quot;&gt;Ví dụ 1: Tối ưu hóa danh mục đầu tư&lt;/h3&gt;

&lt;p&gt;Bài toán này cân bằng giữa lợi suất kỳ vọng và rủi ro khi phân bổ tỷ trọng cho một danh mục tài sản tài chính:&lt;/p&gt;

\[\begin{align}
    \text{maximize}_{x} \quad &amp;amp;\mu^T x - \frac{\gamma}{2}x^T P x \\
    \text{subject to} \quad &amp;amp;\mathbf{1}^Tx = 1 \\
    &amp;amp;x \succeq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;trong đó:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mu\): vectơ lợi suất kỳ vọng của các tài sản,&lt;/li&gt;
  &lt;li&gt;\(P\): ma trận hiệp phương sai của lợi suất tài sản,&lt;/li&gt;
  &lt;li&gt;\(\gamma &amp;gt; 0\): tham số mức độ ngại rủi ro (siêu tham số),&lt;/li&gt;
  &lt;li&gt;\(x\): vectơ tỷ trọng phân bổ vốn vào từng tài sản.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-2-máy-vectơ-hỗ-trợ-svm&quot;&gt;Ví dụ 2: Máy vectơ hỗ trợ (SVM)&lt;/h3&gt;

&lt;p&gt;Máy vectơ hỗ trợ (SVM) là một ví dụ điển hình của bài toán quy hoạch bậc hai. Dưới đây là mô hình C-SVM (chi tiết lý thuyết SVM nằm ngoài phạm vi chương này):&lt;/p&gt;

\[\begin{align}
    \text{minimize}_{\beta, \beta_0, \xi} \quad &amp;amp;\frac{1}{2} \| \beta \|_2^2 + C \sum_{i=1}^{n} \xi_i \\
    \text{subject to} \quad &amp;amp;\xi_i \geq 0, \quad i = 1, \ldots, n \\
    &amp;amp;y_i (x_i^T \beta + \beta_0) \geq 1 - \xi_i, \quad i = 1, \ldots, n
\end{align}\]

&lt;p&gt;&lt;strong&gt;cho trước:&lt;/strong&gt; \(y \in \{-1, 1\}^n\) và ma trận dữ liệu \(X \in \mathbb{R}^{n \times p}\) có các hàng là \(x_1^T, \ldots, x_n^T\).&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-3-bình-phương-tối-thiểu-trong-hồi-quy&quot;&gt;Ví dụ 3: Bình phương tối thiểu trong hồi quy&lt;/h3&gt;

&lt;p&gt;Bài toán cực tiểu hóa tổng bình phương sai số sau đây là một bài toán QP không ràng buộc:
\(\| Ax - b \|_2^2 = x^T A^TA x - 2b^TAx + b^Tb\)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-02-04 Hồi quy Logistic</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_02_04_Logistic_Regression/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_02_04_Logistic_Regression</id>
   <content type="html">&lt;p&gt;Khi bài toán chuyển từ dự đoán giá nhà (số thực liên tục) sang dự đoán một giao dịch có gian lận hay không (\(y \in \{0, 1\}\)), hồi quy tuyến tính lập tức lộ yếu điểm: nó có thể dự đoán xác suất bằng \(1.7\) hoặc \(-0.4\), và cực kỳ nhạy cảm với các điểm dữ liệu nằm xa biên phân loại. Giải pháp kinh điển của thống kê và học máy là đẩy điểm số tuyến tính \(z = w^T x + b\) đi qua &lt;strong&gt;hàm Sigmoid&lt;/strong&gt; \(\sigma(z) = \frac{1}{1 + e^{-z}}\) để ép gọn vào khoảng xác suất \((0, 1)\).&lt;/p&gt;

&lt;p&gt;Điều kỳ diệu khiến &lt;strong&gt;Hồi quy Logistic&lt;/strong&gt; trở thành “con cưng” của Chương 05 nằm ở phép toán tối ưu đằng sau nó: nếu bạn cố dùng sai số bình phương trên hàm Sigmoid, bài toán sẽ trở thành &lt;strong&gt;phi lồi&lt;/strong&gt; đầy cực tiểu địa phương; nhưng ngay khi bạn dùng &lt;strong&gt;Cross-Entropy (Negative Log-Likelihood của phân phối Bernoulli)&lt;/strong&gt;, hàm mục tiêu bỗng trở thành một &lt;strong&gt;hàm lồi trơn tuyệt đẹp&lt;/strong&gt; với Hessian nửa xác định dương trên toàn không gian!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-toán-học-của-hồi-quy-logistic&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột toán học của Hồi quy Logistic&lt;/h2&gt;

&lt;p&gt;Để hiểu trọn vẹn vì sao Hồi quy Logistic vừa đơn giản vừa bền vững trong thực chiến, hãy nắm bốn mảnh ghép sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình Log-Odds &amp;amp; Hàm Sigmoid:&lt;/strong&gt; Giả sử tỷ lệ chênh logarit (log-odds) là hàm tuyến tính: \(\log \frac{p}{1-p} = w^T x + b\). Giải ngược theo \(p\) thu ngay \(p = \sigma(w^T x + b) = \frac{1}{1 + e^{-(w^T x + b)}}\), với đạo hàm cực gọn \(\sigma&apos;(z) = \sigma(z)(1 - \sigma(z))\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi của hàm mất mát Cross-Entropy:&lt;/strong&gt; Với nhãn \(y_i \in \{0, 1\}\), hàm mất mát từng điểm là \(\ell_i(w) = -y_i \log \hat{p}_i - (1 - y_i)\log(1 - \hat{p}_i) = \log(1 + e^{w^T x_i}) - y_i w^T x_i\). Số hạng đầu là hàm log-sum-exp (luôn lồi), số hạng sau tuyến tính — do đó tổng hàm mất mát &lt;strong&gt;luôn lồi&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không có nghiệm đóng — Cửa ngõ sang Thuật toán lặp:&lt;/strong&gt; Khác với Bình phương tối thiểu có công thức \(x^\star = (A^T A)^{-1} A^T b\), phương trình \(\nabla L(w) = X^T(\hat{p} - y) = 0\) là phương trình siêu việt không có nghiệm đóng. Ta buộc phải giải bằng Gradient Descent, Newton–Raphson (IRLS) hoặc L-BFGS!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiện tượng Tách biệt hoàn toàn (Perfect Separation) &amp;amp; Điều chuẩn \(\ell_2\):&lt;/strong&gt; Nếu dữ liệu tách biệt tuyến tính hoàn toàn, hàm mất mát có thể giảm về \(0\) khi \(\|w\|_2 \to \infty\) (không tồn tại nghiệm hữu hạn!). Cộng thêm \(\frac{\lambda}{2}\|w\|_2^2\) làm hàm trở nên lồi mạnh và đảm bảo nghiệm hữu hạn duy nhất.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-xác-suất-cross-entropy-gradient-và-hessian-của-hồi-quy-logistic&quot;&gt;Giải thích: Tính tay xác suất, Cross-Entropy, Gradient và Hessian của Hồi quy Logistic&lt;/h3&gt;

&lt;p&gt;Xét 2 điểm dữ liệu 1 chiều không hệ số chặn: \((x_1, y_1) = (1, 1)\) và \((x_2, y_2) = (-1, 0)\), tại trọng số hiện tại \(w = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Dự đoán xác suất tại \(w = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(z_1 = 0 \cdot 1 = 0 \implies \hat{p}_1 = \sigma(0) = 0.5\).&lt;/li&gt;
      &lt;li&gt;\(z_2 = 0 \cdot (-1) = 0 \implies \hat{p}_2 = \sigma(0) = 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tính hàm mất mát trung bình (Cross-Entropy):&lt;/strong&gt;
\(L(0) = -\frac{1}{2}\big[1 \cdot \log(0.5) + (1 - 0)\cdot \log(1 - 0.5)\big] = -\log(0.5) = \log 2 \approx 0.6931.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Tính Gradient \(\nabla L(w) = \frac{1}{n}\sum_{i=1}^n (\hat{p}_i - y_i) x_i\):&lt;/strong&gt;
\(\nabla L(0) = \frac{1}{2}\big[(0.5 - 1)(1) + (0.5 - 0)(-1)\big] = \frac{1}{2}(-0.5 - 0.5) = -0.5.\)
Hướng giảm \(-\nabla L(0) = +0.5 &amp;gt; 0\) bảo ta &lt;strong&gt;tăng \(w\) lên&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — Tính đạo hàm bậc hai (Hessian) \(H(w) = \frac{1}{n}\sum_{i=1}^n \hat{p}_i (1 - \hat{p}_i) x_i^2\):&lt;/strong&gt;
\(H(0) = \frac{1}{2}\big[0.25(1)^2 + 0.25(-1)^2\big] = 0.25 &amp;gt; 0.\)
Vì \(\hat{p}_i(1-\hat{p}_i) &amp;gt; 0\) với mọi \(w\), ta có \(H(w) \ge 0\) trên toàn bộ \(\mathbb{R}\) — chứng minh trực tiếp hàm mất mát luôn lồi! Sau 1 bước Newton \(w^{(1)} = w^{(0)} - \frac{\nabla L(0)}{H(0)} = 0 - \frac{-0.5}{0.25} = 2\), xác suất lập tức nhảy lên \(\hat{p}_1 = \sigma(2) \approx 0.881\) và \(\hat{p}_2 = \sigma(-2) \approx 0.119\), kéo loss giảm mạnh từ \(0.693\) xuống \(0.127\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;hồi-quy-logistic-logistic-regression&quot;&gt;Hồi quy Logistic (Logistic Regression)&lt;/h1&gt;

&lt;p&gt;Hồi quy logistic là một trong những ứng dụng tiêu biểu của tối ưu hóa lồi trong học máy, được sử dụng rộng rãi cho bài toán phân loại nhị phân.&lt;/p&gt;

&lt;h2 id=&quot;-bài-toán-phân-loại-nhị-phân&quot;&gt;🎯 Bài toán Phân loại Nhị phân&lt;/h2&gt;

&lt;p&gt;Khác với hồi quy tuyến tính dự đoán giá trị liên tục, &lt;strong&gt;phân loại nhị phân&lt;/strong&gt; dự đoán xác suất một mẫu thuộc về một trong hai lớp.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ thực tế:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Y tế&lt;/strong&gt;: Dự đoán bệnh nhân có mắc bệnh hay không (0: khỏe mạnh, 1: bệnh)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Marketing&lt;/strong&gt;: Khách hàng có mua sản phẩm hay không (0: không mua, 1: mua)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tài chính&lt;/strong&gt;: Giao dịch có gian lận hay không (0: hợp lệ, 1: gian lận)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Công nghệ&lt;/strong&gt;: Email có phải thư rác (spam) hay không (0: không spam, 1: spam)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dữ liệu huấn luyện:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\{(\mathbf{x}_i, y_i)\}_{i=1}^n\) với \(\mathbf{x}_i \in \mathbb{R}^p\), \(y_i \in \{0, 1\}\)&lt;/li&gt;
  &lt;li&gt;\(\mathbf{x}_i\): vector đặc trưng (features)&lt;/li&gt;
  &lt;li&gt;\(y_i\): nhãn lớp (class label)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-từ-hồi-quy-tuyến-tính-đến-hồi-quy-logistic&quot;&gt;📊 Từ Hồi quy Tuyến tính đến Hồi quy Logistic&lt;/h2&gt;

&lt;h3 id=&quot;hạn-chế-khi-dùng-hồi-quy-tuyến-tính-cho-phân-loại&quot;&gt;Hạn chế khi dùng Hồi quy Tuyến tính cho phân loại&lt;/h3&gt;

&lt;p&gt;Nếu áp dụng hồi quy tuyến tính trực tiếp: \(\hat{y} = \mathbf{w}^T \mathbf{x} + b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vấn đề:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\hat{y}\) có thể nhận giá trị bất kỳ: \((-\infty, +\infty)\)&lt;/li&gt;
  &lt;li&gt;Nhưng xác suất phải trong khoảng \([0, 1]\)&lt;/li&gt;
  &lt;li&gt;Không phù hợp với bản chất xác suất của phân loại&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;hàm-sigmoid&quot;&gt;Hàm Sigmoid&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hàm Sigmoid:&lt;/strong&gt;
\(\sigma(z) = \frac{1}{1 + e^{-z}}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất quan trọng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Miền giá trị&lt;/strong&gt;: \(\sigma(z) \in (0, 1)\) \(\forall z \in \mathbb{R}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đơn điệu tăng&lt;/strong&gt;: \(\sigma&apos;(z) &amp;gt; 0\) \(\forall z\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối xứng&lt;/strong&gt;: \(\sigma(-z) = 1 - \sigma(z)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giới hạn&lt;/strong&gt;: \(\lim_{z \to -\infty} \sigma(z) = 0\), \(\lim_{z \to +\infty} \sigma(z) = 1\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Đạo hàm đặc biệt:&lt;/strong&gt;
\(\sigma&apos;(z) = \sigma(z)(1 - \sigma(z))\)&lt;/p&gt;

&lt;h3 id=&quot;mô-hình-hồi-quy-logistic&quot;&gt;Mô hình Hồi quy Logistic&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Xác suất dự đoán:&lt;/strong&gt;
\(P(y = 1 | \mathbf{x}) = \sigma(\mathbf{w}^T \mathbf{x}) = \frac{1}{1 + e^{-\mathbf{w}^T \mathbf{x}}}\)&lt;/p&gt;

\[P(y = 0 | \mathbf{x}) = 1 - P(y = 1 | \mathbf{x}) = \frac{e^{-\mathbf{w}^T \mathbf{x}}}{1 + e^{-\mathbf{w}^T \mathbf{x}}}\]

&lt;p&gt;&lt;strong&gt;Quy tắc quyết định:&lt;/strong&gt;
\(\hat{y} = \begin{cases}
1 &amp;amp; \text{nếu } P(y = 1 | \mathbf{x}) \geq 0.5 \\
0 &amp;amp; \text{nếu } P(y = 1 | \mathbf{x}) &amp;lt; 0.5
\end{cases}\)&lt;/p&gt;

&lt;h2 id=&quot;-hàm-mất-mát-cross-entropy&quot;&gt;🧮 Hàm Mất mát Cross-Entropy&lt;/h2&gt;

&lt;p&gt;Trong hồi quy logistic, ta sử dụng &lt;strong&gt;hàm mất mát Cross-Entropy&lt;/strong&gt; để đo độ sai lệch giữa xác suất dự đoán và nhãn thực tế:&lt;/p&gt;

\[J(\mathbf{w}) = -\sum_{i=1}^n \left[ y_i \log p_i + (1-y_i) \log (1-p_i) \right]\]

&lt;p&gt;với \(p_i = \sigma(\mathbf{w}^T \mathbf{x}_i)\) là xác suất dự đoán.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đặc điểm quan trọng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phạt nặng dự đoán sai:&lt;/strong&gt; Khi dự đoán càng lệch khỏi nhãn thực tế, giá trị mất mát càng lớn và không bị chặn trên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trơn và lồi:&lt;/strong&gt; Thuận lợi cho các thuật toán tối ưu hóa dựa trên gradient.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Có cơ sở xác suất:&lt;/strong&gt; Xuất phát trực tiếp từ ước lượng hợp lý cực đại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-chứng-minh-tính-lồi&quot;&gt;🔍 Chứng minh Tính Lồi&lt;/h2&gt;

&lt;h3 id=&quot;định-lý-hàm-mất-mát-logistic-là-lồi&quot;&gt;Định lý: Hàm mất mát Logistic là lồi&lt;/h3&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; Chứng minh \(-\log \sigma(z)\) là lồi&lt;/p&gt;

\[-\log \sigma(z) = -\log \frac{1}{1 + e^{-z}} = \log(1 + e^{-z})\]

&lt;p&gt;Đạo hàm bậc hai:
\(\frac{d^2}{dz^2} \log(1 + e^{-z}) = \frac{e^{-z}}{(1 + e^{-z})^2} = \sigma(z)(1 - \sigma(z)) &amp;gt; 0\)&lt;/p&gt;

&lt;p&gt;⟹ \(-\log \sigma(z)\) là lồi theo \(z\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt; Chứng minh \(-\log(1 - \sigma(z))\) là lồi&lt;/p&gt;

\[-\log(1 - \sigma(z)) = -\log \frac{e^{-z}}{1 + e^{-z}} = z + \log(1 + e^{-z})\]

&lt;p&gt;Đạo hàm bậc hai:
\(\frac{d^2}{dz^2} [z + \log(1 + e^{-z})] = \frac{e^{-z}}{(1 + e^{-z})^2} &amp;gt; 0\)&lt;/p&gt;

&lt;p&gt;⟹ \(-\log(1 - \sigma(z))\) là lồi theo \(z\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 3:&lt;/strong&gt; Kết luận&lt;/p&gt;

&lt;p&gt;Vì \(z = \mathbf{w}^T \mathbf{x}_i\) là affine theo \(\mathbf{w}\), và tổng của các hàm lồi là lồi:&lt;/p&gt;

\[J(\mathbf{w}) = \sum_{i=1}^n \left[ -y_i \log \sigma(\mathbf{w}^T \mathbf{x}_i) - (1-y_i) \log (1 - \sigma(\mathbf{w}^T \mathbf{x}_i)) \right]\]

&lt;p&gt;là &lt;strong&gt;hàm lồi&lt;/strong&gt; theo \(\mathbf{w}\).&lt;/p&gt;

&lt;h2 id=&quot;-gradient-của-hàm-mất-mát&quot;&gt;📈 Gradient của Hàm Mất mát&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Gradient:&lt;/strong&gt;
\(\nabla_{\mathbf{w}} J(\mathbf{w}) = \sum_{i=1}^n (\sigma(\mathbf{w}^T \mathbf{x}_i) - y_i) \mathbf{x}_i = \mathbf{X}^T (\boldsymbol{\sigma} - \mathbf{y})\)&lt;/p&gt;

&lt;p&gt;với:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{X} \in \mathbb{R}^{n \times p}\): ma trận đặc trưng&lt;/li&gt;
  &lt;li&gt;
\[\boldsymbol{\sigma} = [\sigma(\mathbf{w}^T \mathbf{x}_1), ..., \sigma(\mathbf{w}^T \mathbf{x}_n)]^T\]
  &lt;/li&gt;
  &lt;li&gt;
\[\mathbf{y} = [y_1, ..., y_n]^T\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hessian:&lt;/strong&gt;
\(\nabla^2_{\mathbf{w}} J(\mathbf{w}) = \mathbf{X}^T \mathbf{S} \mathbf{X}\)&lt;/p&gt;

&lt;p&gt;với \(\mathbf{S} = \text{diag}(\sigma(\mathbf{w}^T \mathbf{x}_i)(1 - \sigma(\mathbf{w}^T \mathbf{x}_i)))\)&lt;/p&gt;

&lt;p&gt;Vì \(\mathbf{S} \succ 0\), ta có \(\nabla^2_{\mathbf{w}} J(\mathbf{w}) \succeq 0\) ⟹ &lt;strong&gt;hàm lồi&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;-ý-nghĩa-của-tính-lồi&quot;&gt;🎯 Ý nghĩa của Tính Lồi&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Tại sao tính lồi quan trọng?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Đảm bảo cực tiểu toàn cục:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Mọi &lt;strong&gt;điểm cực tiểu địa phương đều là cực tiểu toàn cục&lt;/strong&gt; (và tập nghiệm tối ưu là một tập lồi).&lt;/li&gt;
      &lt;li&gt;Không gặp tình trạng cực tiểu địa phương như trong mạng nơ-ron sâu.&lt;/li&gt;
      &lt;li&gt;Các thuật toán tối ưu đều hướng về nghiệm tối ưu toàn cục.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hạ gradient (Gradient Descent) hoạt động ổn định:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Hội tụ&lt;/strong&gt; về nghiệm tối ưu với tốc độ học (learning rate) phù hợp khi nghiệm hữu hạn tồn tại (lưu ý: nếu dữ liệu tách tuyến tính hoàn toàn và không có chính quy hóa, chuẩn \(\|\mathbf{w}\|\) tăng ra vô cực).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Không bị mắc kẹt&lt;/strong&gt; tại cực tiểu địa phương.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Đơn giản và dễ cài đặt&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cơ sở lý thuyết chặt chẽ:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Có thể chứng minh &lt;strong&gt;tốc độ hội tụ&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;Có thể &lt;strong&gt;ước lượng sai số&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;Có &lt;strong&gt;điều kiện dừng&lt;/strong&gt; rõ ràng&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-từ-tính-lồi-đến-gradient-descent&quot;&gt;🚀 Từ Tính Lồi đến Gradient Descent&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vì hàm mất mát logistic là lồi và khả vi&lt;/strong&gt;, chúng ta có thể sử dụng &lt;strong&gt;Gradient Descent&lt;/strong&gt; một cách tin cậy:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thuật toán cơ bản:&lt;/strong&gt;
\(\mathbf{w}^{(k+1)} = \mathbf{w}^{(k)} - \alpha \nabla J(\mathbf{w}^{(k)})\)&lt;/p&gt;

&lt;p&gt;với gradient:
\(\nabla J(\mathbf{w}) = \mathbf{X}^T (\boldsymbol{\sigma} - \mathbf{y})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đảm bảo hội tụ:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Chọn tốc độ học \(\alpha\) phù hợp giúp thuật toán hội tụ ổn định.&lt;/li&gt;
  &lt;li&gt;Không gặp vấn đề cực tiểu địa phương.&lt;/li&gt;
  &lt;li&gt;Dễ phân tích tốc độ hội tụ và sai số.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kết nối với Chương 6:&lt;/strong&gt;
Trong &lt;strong&gt;Chương 6 - Gradient Descent&lt;/strong&gt;, chúng ta sẽ học chi tiết:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Cách chọn learning rate tối ưu&lt;/li&gt;
  &lt;li&gt;Phân tích tốc độ hội tụ&lt;/li&gt;
  &lt;li&gt;Các biến thể như Stochastic Gradient Descent&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Logistic Regression sẽ là ví dụ chính&lt;/strong&gt; để minh họa các khái niệm này!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-so-sánh-với-hồi-quy-tuyến-tính&quot;&gt;🔄 So sánh với Hồi quy Tuyến tính&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khía cạnh&lt;/th&gt;
      &lt;th&gt;Linear Regression&lt;/th&gt;
      &lt;th&gt;Logistic Regression&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Bài toán&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hồi quy (regression)&lt;/td&gt;
      &lt;td&gt;Phân loại (classification)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Đầu ra&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Giá trị liên tục&lt;/td&gt;
      &lt;td&gt;Xác suất \(\in [0,1]\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm kích hoạt&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Identity: \(f(z) = z\)&lt;/td&gt;
      &lt;td&gt;Sigmoid: \(\sigma(z) = \frac{1}{1+e^{-z}}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm mất mát&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;MSE: \(\frac{1}{2n}\sum(y_i - \hat{y}_i)^2\)&lt;/td&gt;
      &lt;td&gt;Cross-entropy: \(-\sum[y_i \log p_i + (1-y_i)\log(1-p_i)]\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Nghiệm đóng&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Có (nếu \(\mathbf{X}^T\mathbf{X}\) khả nghịch): \(\mathbf{w}^* = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y}\)&lt;/td&gt;
      &lt;td&gt;Không có&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Thuật toán&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Normal equation hoặc GD&lt;/td&gt;
      &lt;td&gt;Gradient Descent&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tính lồi&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Lồi (quadratic)&lt;/td&gt;
      &lt;td&gt;Lồi (convex)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;-ví-dụ-minh-họa-dự-đoán-spam-email&quot;&gt;💡 Ví dụ Minh họa: Dự đoán Spam Email&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; Phân loại email spam dựa trên số lượng từ khóa đáng ngờ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dữ liệu:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(x\): số từ khóa spam trong email&lt;/li&gt;
  &lt;li&gt;\(y\): 1 nếu spam, 0 nếu không spam&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Mô hình:&lt;/strong&gt;
\(P(\text{spam} | x) = \sigma(w_0 + w_1 x) = \frac{1}{1 + e^{-(w_0 + w_1 x)}}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giải thích:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(w_1 &amp;gt; 0\): càng nhiều từ khóa spam, xác suất spam càng cao&lt;/li&gt;
  &lt;li&gt;Điểm quyết định: \(x^* = -\frac{w_0}{w_1}\) (khi \(P = 0.5\))&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;️-interactive-visualization&quot;&gt;🎛️ Interactive Visualization&lt;/h2&gt;

&lt;div id=&quot;logistic-regression-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;display: flex; gap: 20px; margin-bottom: 20px;&quot;&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;🎚️ Điều khiển Tham số&lt;/h4&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;w0-slider&quot;&gt;Bias (w₀): &lt;span id=&quot;w0-value&quot;&gt;0&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;w0-slider&quot; min=&quot;-5&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;w1-slider&quot;&gt;Weight (w₁): &lt;span id=&quot;w1-value&quot;&gt;1&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;w1-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;button id=&quot;add-data-btn&quot; style=&quot;padding: 8px 16px; margin: 5px;&quot;&gt;Thêm Dữ liệu&lt;/button&gt;
                &lt;button id=&quot;clear-data-btn&quot; style=&quot;padding: 8px 16px; margin: 5px;&quot;&gt;Xóa Dữ liệu&lt;/button&gt;
                &lt;button id=&quot;fit-model-btn&quot; style=&quot;padding: 8px 16px; margin: 5px;&quot;&gt;Fit Model&lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📊 Thông tin Mô hình&lt;/h4&gt;
            &lt;div id=&quot;model-info&quot;&gt;
                &lt;p&gt;&lt;strong&gt;Phương trình:&lt;/strong&gt; P(y=1|x) = σ(&lt;span id=&quot;equation&quot;&gt;0 + 1·x&lt;/span&gt;)&lt;/p&gt;
                &lt;p&gt;&lt;strong&gt;Điểm quyết định:&lt;/strong&gt; x = &lt;span id=&quot;decision-boundary&quot;&gt;0&lt;/span&gt;&lt;/p&gt;
                &lt;p&gt;&lt;strong&gt;Loss:&lt;/strong&gt; &lt;span id=&quot;current-loss&quot;&gt;-&lt;/span&gt;&lt;/p&gt;
                &lt;p&gt;&lt;strong&gt;Accuracy:&lt;/strong&gt; &lt;span id=&quot;accuracy&quot;&gt;-&lt;/span&gt;&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px;&quot;&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📈 Sigmoid Function&lt;/h4&gt;
            &lt;canvas id=&quot;sigmoid-canvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;🎯 Classification Results&lt;/h4&gt;
            &lt;canvas id=&quot;classification-canvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin-top: 20px;&quot;&gt;
        &lt;h4&gt;📉 Loss Function Visualization&lt;/h4&gt;
        &lt;canvas id=&quot;loss-canvas&quot; width=&quot;800&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
class LogisticRegressionDemo {
    constructor() {
        this.w0 = 0;
        this.w1 = 1;
        this.dataPoints = [];
        this.isAddingData = false;
        
        this.initializeCanvases();
        this.setupEventListeners();
        this.generateSampleData();
        this.updateVisualization();
    }
    
    initializeCanvases() {
        this.sigmoidCanvas = document.getElementById(&apos;sigmoid-canvas&apos;);
        this.sigmoidCtx = this.sigmoidCanvas.getContext(&apos;2d&apos;);
        
        this.classificationCanvas = document.getElementById(&apos;classification-canvas&apos;);
        this.classificationCtx = this.classificationCanvas.getContext(&apos;2d&apos;);
        
        this.lossCanvas = document.getElementById(&apos;loss-canvas&apos;);
        this.lossCtx = this.lossCanvas.getContext(&apos;2d&apos;);
    }
    
    setupEventListeners() {
        const w0Slider = document.getElementById(&apos;w0-slider&apos;);
        const w1Slider = document.getElementById(&apos;w1-slider&apos;);
        const addDataBtn = document.getElementById(&apos;add-data-btn&apos;);
        const clearDataBtn = document.getElementById(&apos;clear-data-btn&apos;);
        const fitModelBtn = document.getElementById(&apos;fit-model-btn&apos;);
        
        w0Slider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.w0 = parseFloat(e.target.value);
            document.getElementById(&apos;w0-value&apos;).textContent = this.w0.toFixed(1);
            this.updateVisualization();
        });
        
        w1Slider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.w1 = parseFloat(e.target.value);
            document.getElementById(&apos;w1-value&apos;).textContent = this.w1.toFixed(1);
            this.updateVisualization();
        });
        
        addDataBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.isAddingData = !this.isAddingData;
            addDataBtn.textContent = this.isAddingData ? &apos;Dừng Thêm&apos; : &apos;Thêm Dữ liệu&apos;;
            addDataBtn.style.backgroundColor = this.isAddingData ? &apos;#ff6b6b&apos; : &apos;&apos;;
        });
        
        clearDataBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.dataPoints = [];
            this.updateVisualization();
        });
        
        fitModelBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.fitModel();
        });
        
        // Click to add data points
        this.classificationCanvas.addEventListener(&apos;click&apos;, (e) =&gt; {
            if (this.isAddingData) {
                const rect = this.classificationCanvas.getBoundingClientRect();
                const x = (e.clientX - rect.left - 50) / 300 * 10 - 5; // Scale to [-5, 5]
                const y = e.clientY - rect.top &gt; 150 ? 0 : 1; // Top half = class 1, bottom = class 0
                this.dataPoints.push({x, y});
                this.updateVisualization();
            }
        });
    }
    
    generateSampleData() {
        // Generate some sample data
        const sampleData = [
            {x: -3, y: 0}, {x: -2.5, y: 0}, {x: -2, y: 0}, {x: -1.5, y: 0},
            {x: -1, y: 0}, {x: -0.5, y: 0}, {x: 0, y: 0}, {x: 0.5, y: 1},
            {x: 1, y: 1}, {x: 1.5, y: 1}, {x: 2, y: 1}, {x: 2.5, y: 1}, {x: 3, y: 1}
        ];
        
        // Add some noise
        this.dataPoints = sampleData.map(point =&gt; ({
            x: point.x + (Math.random() - 0.5) * 0.5,
            y: Math.random() &lt; 0.1 ? 1 - point.y : point.y // 10% label noise
        }));
    }
    
    sigmoid(z) {
        return 1 / (1 + Math.exp(-z));
    }
    
    predict(x) {
        return this.sigmoid(this.w0 + this.w1 * x);
    }
    
    calculateLoss() {
        if (this.dataPoints.length === 0) return 0;
        
        let loss = 0;
        for (const point of this.dataPoints) {
            const p = this.predict(point.x);
            const epsilon = 1e-15; // Prevent log(0)
            const clampedP = Math.max(epsilon, Math.min(1 - epsilon, p));
            loss += -point.y * Math.log(clampedP) - (1 - point.y) * Math.log(1 - clampedP);
        }
        return loss / this.dataPoints.length;
    }
    
    calculateAccuracy() {
        if (this.dataPoints.length === 0) return 0;
        
        let correct = 0;
        for (const point of this.dataPoints) {
            const prediction = this.predict(point.x) &gt;= 0.5 ? 1 : 0;
            if (prediction === point.y) correct++;
        }
        return correct / this.dataPoints.length;
    }
    
    fitModel() {
        if (this.dataPoints.length === 0) return;
        
        // Simple gradient descent
        const learningRate = 0.1;
        const iterations = 1000;
        
        for (let iter = 0; iter &lt; iterations; iter++) {
            let gradW0 = 0, gradW1 = 0;
            
            for (const point of this.dataPoints) {
                const p = this.predict(point.x);
                const error = p - point.y;
                gradW0 += error;
                gradW1 += error * point.x;
            }
            
            gradW0 /= this.dataPoints.length;
            gradW1 /= this.dataPoints.length;
            
            this.w0 -= learningRate * gradW0;
            this.w1 -= learningRate * gradW1;
        }
        
        // Update sliders
        document.getElementById(&apos;w0-slider&apos;).value = this.w0;
        document.getElementById(&apos;w1-slider&apos;).value = this.w1;
        document.getElementById(&apos;w0-value&apos;).textContent = this.w0.toFixed(1);
        document.getElementById(&apos;w1-value&apos;).textContent = this.w1.toFixed(1);
        
        this.updateVisualization();
    }
    
    drawSigmoid() {
        const ctx = this.sigmoidCtx;
        const canvas = this.sigmoidCanvas;
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Draw axes
        ctx.strokeStyle = &apos;#ccc&apos;;
        ctx.lineWidth = 1;
        
        // X-axis
        ctx.beginPath();
        ctx.moveTo(50, canvas.height - 50);
        ctx.lineTo(canvas.width - 20, canvas.height - 50);
        ctx.stroke();
        
        // Y-axis
        ctx.beginPath();
        ctx.moveTo(50, 20);
        ctx.lineTo(50, canvas.height - 50);
        ctx.stroke();
        
        // Draw sigmoid curve
        ctx.strokeStyle = &apos;#2196F3&apos;;
        ctx.lineWidth = 2;
        ctx.beginPath();
        
        for (let i = 0; i &lt;= 300; i++) {
            const x = (i / 300) * 10 - 5; // x from -5 to 5
            const z = this.w0 + this.w1 * x;
            const y = this.sigmoid(z);
            
            const canvasX = 50 + (x + 5) / 10 * 300;
            const canvasY = canvas.height - 50 - y * 200;
            
            if (i === 0) {
                ctx.moveTo(canvasX, canvasY);
            } else {
                ctx.lineTo(canvasX, canvasY);
            }
        }
        ctx.stroke();
        
        // Draw decision boundary
        if (this.w1 !== 0) {
            const decisionX = -this.w0 / this.w1;
            if (decisionX &gt;= -5 &amp;&amp; decisionX &lt;= 5) {
                const canvasX = 50 + (decisionX + 5) / 10 * 300;
                ctx.strokeStyle = &apos;#ff6b6b&apos;;
                ctx.lineWidth = 2;
                ctx.setLineDash([5, 5]);
                ctx.beginPath();
                ctx.moveTo(canvasX, 20);
                ctx.lineTo(canvasX, canvas.height - 50);
                ctx.stroke();
                ctx.setLineDash([]);
            }
        }
        
        // Labels
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;P(y=1|x)&apos;, 10, 30);
        ctx.fillText(&apos;x&apos;, canvas.width - 15, canvas.height - 30);
        ctx.fillText(&apos;0&apos;, 45, canvas.height - 30);
        ctx.fillText(&apos;1&apos;, 45, 25);
        ctx.fillText(&apos;0.5&apos;, 35, canvas.height - 150);
    }
    
    drawClassification() {
        const ctx = this.classificationCtx;
        const canvas = this.classificationCanvas;
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Draw background regions
        ctx.fillStyle = &apos;rgba(255, 107, 107, 0.1)&apos;; // Red for class 0
        ctx.fillRect(50, canvas.height/2, 300, canvas.height/2 - 50);
        
        ctx.fillStyle = &apos;rgba(76, 175, 80, 0.1)&apos;; // Green for class 1
        ctx.fillRect(50, 20, 300, canvas.height/2 - 20);
        
        // Draw axes
        ctx.strokeStyle = &apos;#ccc&apos;;
        ctx.lineWidth = 1;
        
        // X-axis
        ctx.beginPath();
        ctx.moveTo(50, canvas.height - 50);
        ctx.lineTo(350, canvas.height - 50);
        ctx.stroke();
        
        // Y-axis (class separator)
        ctx.beginPath();
        ctx.moveTo(50, canvas.height/2);
        ctx.lineTo(350, canvas.height/2);
        ctx.stroke();
        
        // Draw data points
        for (const point of this.dataPoints) {
            const canvasX = 50 + (point.x + 5) / 10 * 300;
            const canvasY = point.y === 1 ? canvas.height/4 : 3*canvas.height/4;
            
            ctx.fillStyle = point.y === 1 ? &apos;#4CAF50&apos; : &apos;#f44336&apos;;
            ctx.beginPath();
            ctx.arc(canvasX, canvasY, 5, 0, 2 * Math.PI);
            ctx.fill();
        }
        
        // Draw decision boundary
        if (this.w1 !== 0) {
            const decisionX = -this.w0 / this.w1;
            if (decisionX &gt;= -5 &amp;&amp; decisionX &lt;= 5) {
                const canvasX = 50 + (decisionX + 5) / 10 * 300;
                ctx.strokeStyle = &apos;#2196F3&apos;;
                ctx.lineWidth = 3;
                ctx.beginPath();
                ctx.moveTo(canvasX, 20);
                ctx.lineTo(canvasX, canvas.height - 50);
                ctx.stroke();
            }
        }
        
        // Labels
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;Class 1&apos;, 10, 40);
        ctx.fillText(&apos;Class 0&apos;, 10, canvas.height - 60);
        ctx.fillText(&apos;x&apos;, 360, canvas.height - 30);
    }
    
    drawLoss() {
        const ctx = this.lossCtx;
        const canvas = this.lossCanvas;
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        if (this.dataPoints.length === 0) return;
        
        // Draw axes
        ctx.strokeStyle = &apos;#ccc&apos;;
        ctx.lineWidth = 1;
        
        // X-axis
        ctx.beginPath();
        ctx.moveTo(50, canvas.height - 50);
        ctx.lineTo(canvas.width - 20, canvas.height - 50);
        ctx.stroke();
        
        // Y-axis
        ctx.beginPath();
        ctx.moveTo(50, 20);
        ctx.lineTo(50, canvas.height - 50);
        ctx.stroke();
        
        // Calculate loss surface
        const originalW0 = this.w0;
        const originalW1 = this.w1;
        
        const w0Range = [-3, 3];
        const w1Range = [-2, 2];
        const resolution = 50;
        
        let minLoss = Infinity;
        let maxLoss = -Infinity;
        const lossData = [];
        
        for (let i = 0; i &lt;= resolution; i++) {
            lossData[i] = [];
            for (let j = 0; j &lt;= resolution; j++) {
                this.w0 = w0Range[0] + (w0Range[1] - w0Range[0]) * i / resolution;
                this.w1 = w1Range[0] + (w1Range[1] - w1Range[0]) * j / resolution;
                const loss = this.calculateLoss();
                lossData[i][j] = loss;
                minLoss = Math.min(minLoss, loss);
                maxLoss = Math.max(maxLoss, loss);
            }
        }
        
        // Draw contour lines
        const numContours = 10;
        for (let c = 0; c &lt; numContours; c++) {
            const level = minLoss + (maxLoss - minLoss) * c / numContours;
            ctx.strokeStyle = `hsl(${240 - c * 20}, 70%, 60%)`;
            ctx.lineWidth = 1;
            
            // Simple contour drawing (could be improved)
            for (let i = 0; i &lt; resolution; i++) {
                for (let j = 0; j &lt; resolution; j++) {
                    if (Math.abs(lossData[i][j] - level) &lt; (maxLoss - minLoss) / numContours / 2) {
                        const x = 50 + i / resolution * (canvas.width - 70);
                        const y = canvas.height - 50 - j / resolution * (canvas.height - 70);
                        ctx.fillRect(x, y, 2, 2);
                    }
                }
            }
        }
        
        // Mark current position
        this.w0 = originalW0;
        this.w1 = originalW1;
        
        const currentX = 50 + (this.w0 - w0Range[0]) / (w0Range[1] - w0Range[0]) * (canvas.width - 70);
        const currentY = canvas.height - 50 - (this.w1 - w1Range[0]) / (w1Range[1] - w1Range[0]) * (canvas.height - 70);
        
        ctx.fillStyle = &apos;#ff6b6b&apos;;
        ctx.beginPath();
        ctx.arc(currentX, currentY, 6, 0, 2 * Math.PI);
        ctx.fill();
        
        // Labels
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;w₁&apos;, 10, canvas.height - 30);
        ctx.fillText(&apos;w₀&apos;, canvas.width - 20, canvas.height - 30);
    }
    
    updateVisualization() {
        this.drawSigmoid();
        this.drawClassification();
        this.drawLoss();
        
        // Update info panel
        const equation = `${this.w0.toFixed(1)} + ${this.w1.toFixed(1)}·x`;
        document.getElementById(&apos;equation&apos;).textContent = equation;
        
        const decisionBoundary = this.w1 !== 0 ? (-this.w0 / this.w1).toFixed(2) : &apos;∞&apos;;
        document.getElementById(&apos;decision-boundary&apos;).textContent = decisionBoundary;
        
        const loss = this.calculateLoss();
        document.getElementById(&apos;current-loss&apos;).textContent = loss.toFixed(3);
        
        const accuracy = this.calculateAccuracy();
        document.getElementById(&apos;accuracy&apos;).textContent = (accuracy * 100).toFixed(1) + &apos;%&apos;;
    }
}

// Initialize demo when page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, () =&gt; {
    new LogisticRegressionDemo();
});
&lt;/script&gt;

&lt;style&gt;
#logistic-regression-demo {
    font-family: Arial, sans-serif;
    max-width: 1000px;
    margin: 0 auto;
}

#logistic-regression-demo canvas {
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#logistic-regression-demo input[type=&quot;range&quot;] {
    width: 100%;
    margin: 5px 0;
}

#logistic-regression-demo button {
    background-color: #2196F3;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

#logistic-regression-demo button:hover {
    background-color: #1976D2;
}

#model-info {
    background-color: #f5f5f5;
    padding: 15px;
    border-radius: 4px;
    font-size: 14px;
}

#model-info p {
    margin: 5px 0;
}
&lt;/style&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Bài tập thực hành:&lt;/strong&gt; Hãy thử thay đổi các tham số trong công cụ minh họa ở trên để quan sát trực tiếp hành vi của mô hình hồi quy logistic.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-đọc-thêm-các-hàm-liên-kết-link-functions-thay-thế-cho-sigmoid&quot;&gt;📖 Đọc thêm: Các hàm liên kết (Link Functions) thay thế cho Sigmoid&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Phần này giải thích sâu hơn cơ sở của hàm sigmoid, nguồn gốc hàm mất mát cross-entropy và các hàm liên kết thay thế trong mô hình tuyến tính tổng quát (GLM).&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;-tại-sao-cross-entropy-là-hàm-mất-mát&quot;&gt;🧮 Tại sao Cross-Entropy là Hàm Mất mát?&lt;/h2&gt;

&lt;h3 id=&quot;-mục-tiêu-tìm-trọng-số-tốt-nhất&quot;&gt;🎯 Mục tiêu: Tìm trọng số tốt nhất&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi cốt lõi:&lt;/strong&gt; Làm thế nào để tìm trọng số \(\mathbf{w}\) sao cho mô hình dự đoán chính xác nhất?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý tưởng:&lt;/strong&gt; Chọn \(\mathbf{w}\) sao cho &lt;strong&gt;xác suất quan sát được dữ liệu thực tế là cao nhất&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;-từ-xác-suất-đến-cross-entropy&quot;&gt;🔍 Từ Xác suất đến Cross-Entropy&lt;/h3&gt;

&lt;h4 id=&quot;bước-1-mô-hình-hóa-xác-suất&quot;&gt;&lt;strong&gt;Bước 1: Mô hình hóa xác suất&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Với mỗi mẫu dữ liệu \((\mathbf{x}_i, y_i)\), mô hình dự đoán:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(y_i = 1\): xác suất là \(p_i = \sigma(\mathbf{w}^T \mathbf{x}_i)\)&lt;/li&gt;
  &lt;li&gt;Nếu \(y_i = 0\): xác suất là \(1 - p_i = 1 - \sigma(\mathbf{w}^T \mathbf{x}_i)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;bước-2-likelihood---khả-năng-xảy-ra&quot;&gt;&lt;strong&gt;Bước 2: Likelihood - “Khả năng xảy ra”&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi:&lt;/strong&gt; Với trọng số \(\mathbf{w}\) hiện tại, xác suất quan sát được toàn bộ tập dữ liệu là bao nhiêu?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trả lời:&lt;/strong&gt; Nhân xác suất của tất cả các mẫu:
\(\text{Likelihood} = p_1^{y_1} \cdot (1-p_1)^{1-y_1} \times p_2^{y_2} \cdot (1-p_2)^{1-y_2} \times \ldots\)&lt;/p&gt;

&lt;h4 id=&quot;bước-3-nguyên-lý-hợp-lý-cực-đại-maximum-likelihood&quot;&gt;&lt;strong&gt;Bước 3: Nguyên lý Hợp lý Cực đại (Maximum Likelihood)&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Nguyên lý:&lt;/strong&gt; Chọn \(\mathbf{w}\) để &lt;strong&gt;tối đa hóa likelihood&lt;/strong&gt; = chọn \(\mathbf{w}\) làm cho dữ liệu quan sát được có khả năng xảy ra cao nhất.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vấn đề thực tế:&lt;/strong&gt; Likelihood là tích của nhiều số nhỏ → khó tính toán và không ổn định.&lt;/p&gt;

&lt;h4 id=&quot;bước-4-log-likelihood&quot;&gt;&lt;strong&gt;Bước 4: Log-Likelihood&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Giải pháp:&lt;/strong&gt; Lấy logarithm để chuyển tích thành tổng:
\(\log(\text{Likelihood}) = \sum_{i=1}^n \left[ y_i \log p_i + (1-y_i) \log (1-p_i) \right]\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lợi ích:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tính toán ổn định hơn&lt;/li&gt;
  &lt;li&gt;Tối đa hóa log-likelihood = tối đa hóa likelihood&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;bước-5-hàm-mất-mát-cross-entropy&quot;&gt;&lt;strong&gt;Bước 5: Hàm mất mát Cross-Entropy&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Chuyển sang bài toán cực tiểu hóa:&lt;/strong&gt; Cực đại hóa log-likelihood tương đương với cực tiểu hóa đối của nó:&lt;/p&gt;

\[J(\mathbf{w}) = -\log(\text{Likelihood}) = -\sum_{i=1}^n \left[ y_i \log p_i + (1-y_i) \log (1-p_i) \right]\]

&lt;p&gt;&lt;strong&gt;Đây chính là Cross-Entropy Loss!&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;-tại-sao-cross-entropy-hợp-lý&quot;&gt;💡 Tại sao Cross-Entropy “Hợp lý”?&lt;/h3&gt;

&lt;h4 id=&quot;1-phạt-nặng-dự-đoán-sai&quot;&gt;&lt;strong&gt;1. Phạt nặng dự đoán sai&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ minh họa:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 1:&lt;/strong&gt; \(y = 1\) (thực tế), \(p = 0.9\) (dự đoán)
    &lt;ul&gt;
      &lt;li&gt;Loss = \(-1 \times \log(0.9) = 0.105\) (thấp - tốt!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp 2:&lt;/strong&gt; \(y = 1\) (thực tế), \(p = 0.1\) (dự đoán)
    &lt;ul&gt;
      &lt;li&gt;Loss = \(-1 \times \log(0.1) = 2.303\) (cao - tệ!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Dự đoán càng sai, loss càng lớn, và &lt;strong&gt;không bị chặn trên&lt;/strong&gt; (tăng xấp xỉ tuyến tính theo mức sai khi \(p \to 0\)).&lt;/p&gt;

&lt;h4 id=&quot;2-khuyến-khích-dự-đoán-tự-tin&quot;&gt;&lt;strong&gt;2. Khuyến khích dự đoán tự tin&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Cross-entropy “thưởng” cho những dự đoán tự tin và đúng:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(p = 0.99\) khi \(y = 1\) → loss rất thấp&lt;/li&gt;
  &lt;li&gt;\(p = 0.51\) khi \(y = 1\) → loss vẫn cao (mặc dù đúng)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-smooth-và-khả-vi&quot;&gt;&lt;strong&gt;3. Smooth và khả vi&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Khác với accuracy (0-1 loss), cross-entropy:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Smooth&lt;/strong&gt;: Có đạo hàm mọi nơi&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex&lt;/strong&gt;: Đảm bảo tối ưu toàn cục&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Informative gradient&lt;/strong&gt;: Gradient lớn khi dự đoán sai&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-so-sánh-với-các-loss-khác&quot;&gt;🔄 So sánh với các Loss khác&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Loss Function&lt;/th&gt;
      &lt;th&gt;Công thức&lt;/th&gt;
      &lt;th&gt;Ưu điểm&lt;/th&gt;
      &lt;th&gt;Nhược điểm&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Cross-Entropy&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(-[y\log p + (1-y)\log(1-p)]\)&lt;/td&gt;
      &lt;td&gt;Smooth, convex, principled&lt;/td&gt;
      &lt;td&gt;Sensitive to outliers&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Mean Squared Error&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\((y - p)^2\)&lt;/td&gt;
      &lt;td&gt;Simple, familiar&lt;/td&gt;
      &lt;td&gt;Not probabilistic&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;0-1 Loss&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\mathbf{1}[y \neq \text{round}(p)]\)&lt;/td&gt;
      &lt;td&gt;Direct accuracy&lt;/td&gt;
      &lt;td&gt;Non-differentiable&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;-kết-luận-về-cross-entropy&quot;&gt;🎯 Kết luận về Cross-Entropy&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Cross-Entropy không phải là lựa chọn tùy ý&lt;/strong&gt; - nó xuất phát tự nhiên từ:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nguyên lý Maximum Likelihood&lt;/strong&gt; - cách tốt nhất để fit mô hình xác suất&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất toán học tốt&lt;/strong&gt; - convex, smooth, differentiable&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa thực tế&lt;/strong&gt; - phạt nặng dự đoán sai, khuyến khích tự tin&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Đây là lý do cross-entropy trở thành hàm mất mát tiêu chuẩn cho bài toán phân loại.&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;-vì-sao-chọn-hàm-sigmoid&quot;&gt;🤔 Vì sao chọn hàm Sigmoid?&lt;/h2&gt;

&lt;h3 id=&quot;1-yêu-cầu-toán-học-đối-với-hàm-ánh-xạ-xác-suất&quot;&gt;1. &lt;strong&gt;Yêu cầu toán học đối với hàm ánh xạ xác suất&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Để chuyển đổi từ \(\mathbb{R}\) sang xác suất \([0,1]\), ta cần một hàm \(g: \mathbb{R} \to [0,1]\) thỏa mãn:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu bắt buộc:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Đơn điệu tăng:&lt;/strong&gt; \(g&apos;(z) &amp;gt; 0\) (bảo toàn thứ tự).&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Bị chặn trong \([0,1]\):&lt;/strong&gt; đảm bảo đầu ra là xác suất hợp lệ.&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Trơn:&lt;/strong&gt; khả vi để tính gradient.&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Tiệm cận:&lt;/strong&gt; \(\lim_{z \to -\infty} g(z) = 0\), \(\lim_{z \to +\infty} g(z) = 1\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các tính chất thuận lợi khác:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;🎯 &lt;strong&gt;Đạo hàm đơn giản:&lt;/strong&gt; thuận tiện cho tính toán số.&lt;/li&gt;
  &lt;li&gt;🎯 &lt;strong&gt;Ý nghĩa xác suất rõ ràng.&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;🎯 &lt;strong&gt;Đối xứng:&lt;/strong&gt; \(g(-z) = 1 - g(z)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-nguồn-gốc-từ-odds-và-logit&quot;&gt;2. &lt;strong&gt;Nguồn gốc từ Odds và Logit&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Odds (Tỷ số cược):&lt;/strong&gt;
\(\text{Odds} = \frac{P(y=1|x)}{P(y=0|x)} = \frac{P(y=1|x)}{1-P(y=1|x)}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log-odds (Logit):&lt;/strong&gt;
\(\text{logit}(p) = \log\left(\frac{p}{1-p}\right)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mô hình tuyến tính cho log-odds:&lt;/strong&gt;
\(\log\left(\frac{P(y=1|x)}{1-P(y=1|x)}\right) = \mathbf{w}^T \mathbf{x}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giải ngược để tìm P:&lt;/strong&gt;
\(\frac{P(y=1|x)}{1-P(y=1|x)} = e^{\mathbf{w}^T \mathbf{x}}\)&lt;/p&gt;

\[P(y=1|x) = (1-P(y=1|x)) \cdot e^{\mathbf{w}^T \mathbf{x}}\]

\[P(y=1|x) = e^{\mathbf{w}^T \mathbf{x}} - P(y=1|x) \cdot e^{\mathbf{w}^T \mathbf{x}}\]

\[P(y=1|x)(1 + e^{\mathbf{w}^T \mathbf{x}}) = e^{\mathbf{w}^T \mathbf{x}}\]

\[P(y=1|x) = \frac{e^{\mathbf{w}^T \mathbf{x}}}{1 + e^{\mathbf{w}^T \mathbf{x}}} = \frac{1}{1 + e^{-\mathbf{w}^T \mathbf{x}}} = \sigma(\mathbf{w}^T \mathbf{x})\]

&lt;p&gt;⟹ &lt;strong&gt;Sigmoid xuất hiện tự nhiên từ mô hình log-odds tuyến tính!&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;3-ưu-điểm-đặc-biệt-của-sigmoid&quot;&gt;3. &lt;strong&gt;Ưu điểm Đặc biệt của Sigmoid&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;a-đạo-hàm-gọn-đẹp&quot;&gt;&lt;strong&gt;a) Đạo hàm gọn đẹp&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\sigma&apos;(z) = \sigma(z)(1 - \sigma(z))\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lợi ích:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Không cần tính lại \(e^{-z}\)&lt;/li&gt;
  &lt;li&gt;Gradient descent hiệu quả&lt;/li&gt;
  &lt;li&gt;Backpropagation đơn giản&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;b-tính-đối-xứng&quot;&gt;&lt;strong&gt;b) Tính Đối xứng&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\sigma(-z) = 1 - \sigma(z)\)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt; Nếu $$P(y=1&lt;/td&gt;
      &lt;td&gt;x) = 0.7\(thì\)P(y=1&lt;/td&gt;
      &lt;td&gt;-x) = 0.3$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h4 id=&quot;c-giải-thích-xác-suất-tự-nhiên&quot;&gt;&lt;strong&gt;c) Giải thích Xác suất Tự nhiên&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(z = 0 \Rightarrow P = 0.5\) (không thiên vị)&lt;/li&gt;
  &lt;li&gt;\(z &amp;gt; 0 \Rightarrow P &amp;gt; 0.5\) (thiên về class 1)&lt;/li&gt;
  &lt;li&gt;\(z &amp;lt; 0 \Rightarrow P &amp;lt; 0.5\) (thiên về class 0)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-tại-sao-cần-các-hàm-thay-thế&quot;&gt;🔄 Tại sao cần các hàm thay thế?&lt;/h3&gt;

&lt;p&gt;Mặc dù sigmoid là lựa chọn phổ biến nhất, trong một số bài toán cụ thể, các hàm liên kết khác có thể phù hợp hơn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dữ liệu có hành vi đuôi phân phối khác biệt.&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sự kiện hiếm hoặc dữ liệu mất cân bằng.&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các giả định thống kê hoặc yêu cầu mô hình hóa đặc thù.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;1-tanh-function&quot;&gt;1. &lt;strong&gt;Tanh Function&lt;/strong&gt;&lt;/h3&gt;

\[\tanh(z) = \frac{e^z - e^{-z}}{e^z + e^{-z}} = \frac{e^{2z} - 1}{e^{2z} + 1}\]

&lt;p&gt;&lt;strong&gt;Mối quan hệ với Sigmoid:&lt;/strong&gt;
\(\tanh(z) = 2\sigma(2z) - 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Miền giá trị&lt;/strong&gt;: \((-1, 1)\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Đối xứng qua gốc&lt;/strong&gt;: \(\tanh(-z) = -\tanh(z)\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Đạo hàm&lt;/strong&gt;: \(\tanh&apos;(z) = 1 - \tanh^2(z)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Chuyển đổi về xác suất:&lt;/strong&gt; \(p = \frac{\tanh(z) + 1}{2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt; Neural networks (hidden layers), khi cần output centered around 0&lt;/p&gt;

&lt;h3 id=&quot;2-probit-function-inverse-normal-cdf&quot;&gt;2. &lt;strong&gt;Probit Function (Inverse Normal CDF)&lt;/strong&gt;&lt;/h3&gt;

\[\Phi^{-1}(p) = z \Leftrightarrow p = \Phi(z) = \int_{-\infty}^z \frac{1}{\sqrt{2\pi}} e^{-t^2/2} dt\]

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Miền giá trị&lt;/strong&gt;: \((0, 1)\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Đối xứng&lt;/strong&gt;: \(\Phi(-z) = 1 - \Phi(z)\)&lt;/li&gt;
  &lt;li&gt;❌ &lt;strong&gt;Không có dạng đóng&lt;/strong&gt;: Cần tính tích phân số&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;So sánh với Sigmoid:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Sigmoid&lt;/strong&gt;: đuôi exponential decay $$\sim e^{-&lt;/td&gt;
          &lt;td&gt;z&lt;/td&gt;
          &lt;td&gt;}$$&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Probit&lt;/strong&gt;: đuôi Gaussian decay \(\sim e^{-z^2/2}\) (nhanh hơn)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Econometrics (probit regression)&lt;/li&gt;
  &lt;li&gt;Khi dữ liệu có phân phối gần Gaussian&lt;/li&gt;
  &lt;li&gt;Threshold models&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-gumbel-log-log-function&quot;&gt;3. &lt;strong&gt;Gumbel (Log-log) Function&lt;/strong&gt;&lt;/h3&gt;

\[F(z) = e^{-e^{-z}}\]

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Miền giá trị&lt;/strong&gt;: \((0, 1)\)&lt;/li&gt;
  &lt;li&gt;❌ &lt;strong&gt;Không đối xứng&lt;/strong&gt;: Right-skewed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;CDF của Gumbel distribution&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Extreme value theory&lt;/li&gt;
  &lt;li&gt;Survival analysis&lt;/li&gt;
  &lt;li&gt;Modeling maximum values&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-complementary-log-log&quot;&gt;4. &lt;strong&gt;Complementary Log-log&lt;/strong&gt;&lt;/h3&gt;

\[F(z) = 1 - e^{-e^z}\]

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Miền giá trị&lt;/strong&gt;: \((0, 1)\)&lt;/li&gt;
  &lt;li&gt;❌ &lt;strong&gt;Không đối xứng&lt;/strong&gt;: Left-skewed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complement của Gumbel&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Rare events modeling&lt;/strong&gt; (y=1 hiếm)&lt;/li&gt;
  &lt;li&gt;Survival analysis (hazard modeling)&lt;/li&gt;
  &lt;li&gt;Time-to-event data&lt;/li&gt;
  &lt;li&gt;Poisson regression với binary outcomes&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5-cauchit-function&quot;&gt;5. &lt;strong&gt;Cauchit Function&lt;/strong&gt;&lt;/h3&gt;

\[F(z) = \frac{1}{2} + \frac{1}{\pi} \arctan(z)\]

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Miền giá trị&lt;/strong&gt;: \((0, 1)\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Đối xứng&lt;/strong&gt;: \(F(-z) = 1 - F(z)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Heavy tails&lt;/strong&gt;: Slower decay than sigmoid/probit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Robust regression (outlier-resistant)&lt;/li&gt;
  &lt;li&gt;Heavy-tailed error distributions&lt;/li&gt;
  &lt;li&gt;Financial modeling&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-interactive-comparison-tool&quot;&gt;📊 Interactive Comparison Tool&lt;/h2&gt;

&lt;div id=&quot;link-functions-comparison&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 20px;&quot;&gt;
        &lt;h4&gt;🎛️ Điều khiển Hiển thị&lt;/h4&gt;
        &lt;div style=&quot;display: flex; gap: 15px; flex-wrap: wrap;&quot;&gt;
            &lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;show-sigmoid&quot; checked=&quot;&quot; /&gt; Sigmoid&lt;/label&gt;
            &lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;show-tanh&quot; checked=&quot;&quot; /&gt; Tanh (scaled)&lt;/label&gt;
            &lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;show-probit&quot; checked=&quot;&quot; /&gt; Probit&lt;/label&gt;
            &lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;show-gumbel&quot; /&gt; Gumbel&lt;/label&gt;
            &lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;show-cauchit&quot; /&gt; Cauchit&lt;/label&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px;&quot;&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📈 Link Functions Comparison&lt;/h4&gt;
            &lt;canvas id=&quot;link-functions-canvas&quot; width=&quot;500&quot; height=&quot;400&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📊 Properties Comparison&lt;/h4&gt;
            &lt;div id=&quot;properties-table&quot; style=&quot;font-size: 14px;&quot;&gt;
                &lt;table style=&quot;width: 100%; border-collapse: collapse;&quot;&gt;
                    &lt;thead&gt;
                        &lt;tr style=&quot;background-color: #f0f0f0;&quot;&gt;
                            &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Function&lt;/th&gt;
                            &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Symmetric&lt;/th&gt;
                            &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Tail Behavior&lt;/th&gt;
                            &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Computation&lt;/th&gt;
                        &lt;/tr&gt;
                    &lt;/thead&gt;
                    &lt;tbody&gt;
                        &lt;tr&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;Sigmoid&lt;/strong&gt;&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;✅ Yes&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Exponential&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;⚡ Fast&lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;Tanh&lt;/strong&gt;&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;✅ Yes&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Exponential&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;⚡ Fast&lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;Probit&lt;/strong&gt;&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;✅ Yes&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Gaussian&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;🐌 Slow&lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;Gumbel&lt;/strong&gt;&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;❌ No&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Right-skewed&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;⚡ Fast&lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;Cauchit&lt;/strong&gt;&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;✅ Yes&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Heavy tails&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;⚡ Fast&lt;/td&gt;
                        &lt;/tr&gt;
                    &lt;/tbody&gt;
                &lt;/table&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
class LinkFunctionsComparison {
    constructor() {
        this.canvas = document.getElementById(&apos;link-functions-canvas&apos;);
        if (!this.canvas) return;
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.setupEventListeners();
        this.draw();
    }
    
    setupEventListeners() {
        const checkboxes = [&apos;sigmoid&apos;, &apos;tanh&apos;, &apos;probit&apos;, &apos;gumbel&apos;, &apos;cauchit&apos;];
        checkboxes.forEach(name =&gt; {
            const checkbox = document.getElementById(`show-${name}`);
            if (checkbox) {
                checkbox.addEventListener(&apos;change&apos;, () =&gt; {
                    this.draw();
                });
            }
        });
    }
    
    sigmoid(z) {
        return 1 / (1 + Math.exp(-z));
    }
    
    tanh_scaled(z) {
        return (Math.tanh(z) + 1) / 2; // Scale tanh from [-1,1] to [0,1]
    }
    
    // Approximation of probit function (inverse normal CDF)
    probit(z) {
        // Using rational approximation for normal CDF
        const a1 = 0.254829592;
        const a2 = -0.284496736;
        const a3 = 1.421413741;
        const a4 = -1.453152027;
        const a5 = 1.061405429;
        const p = 0.3275911;
        
        const sign = z &lt; 0 ? -1 : 1;
        z = Math.abs(z) / Math.sqrt(2);
        
        const t = 1.0 / (1.0 + p * z);
        const y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * Math.exp(-z * z);
        
        return 0.5 * (1.0 + sign * y);
    }
    
    gumbel(z) {
        return Math.exp(-Math.exp(-z));
    }
    
    cauchit(z) {
        return 0.5 + Math.atan(z) / Math.PI;
    }
    
    draw() {
        const ctx = this.ctx;
        const canvas = this.canvas;
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Draw axes
        ctx.strokeStyle = &apos;#ccc&apos;;
        ctx.lineWidth = 1;
        
        // X-axis
        ctx.beginPath();
        ctx.moveTo(50, canvas.height - 50);
        ctx.lineTo(canvas.width - 20, canvas.height - 50);
        ctx.stroke();
        
        // Y-axis
        ctx.beginPath();
        ctx.moveTo(50, 20);
        ctx.lineTo(50, canvas.height - 50);
        ctx.stroke();
        
        // Grid lines
        ctx.strokeStyle = &apos;#f0f0f0&apos;;
        ctx.lineWidth = 0.5;
        
        // Horizontal grid lines
        for (let i = 1; i &lt;= 4; i++) {
            const y = 20 + (canvas.height - 70) * i / 5;
            ctx.beginPath();
            ctx.moveTo(50, y);
            ctx.lineTo(canvas.width - 20, y);
            ctx.stroke();
        }
        
        // Vertical grid lines
        for (let i = 1; i &lt;= 9; i++) {
            const x = 50 + (canvas.width - 70) * i / 10;
            ctx.beginPath();
            ctx.moveTo(x, 20);
            ctx.lineTo(x, canvas.height - 50);
            ctx.stroke();
        }
        
        // Draw functions
        const functions = [
            { name: &apos;sigmoid&apos;, func: this.sigmoid, color: &apos;#2196F3&apos;, label: &apos;Sigmoid&apos; },
            { name: &apos;tanh&apos;, func: this.tanh_scaled, color: &apos;#4CAF50&apos;, label: &apos;Tanh (scaled)&apos; },
            { name: &apos;probit&apos;, func: this.probit, color: &apos;#FF9800&apos;, label: &apos;Probit&apos; },
            { name: &apos;gumbel&apos;, func: this.gumbel, color: &apos;#9C27B0&apos;, label: &apos;Gumbel&apos; },
            { name: &apos;cauchit&apos;, func: this.cauchit, color: &apos;#F44336&apos;, label: &apos;Cauchit&apos; }
        ];
        
        functions.forEach(({name, func, color, label}) =&gt; {
            const checkbox = document.getElementById(`show-${name}`);
            if (checkbox &amp;&amp; checkbox.checked) {
                ctx.strokeStyle = color;
                ctx.lineWidth = 2;
                ctx.beginPath();
                
                for (let i = 0; i &lt;= 400; i++) {
                    const z = (i / 400) * 10 - 5; // z from -5 to 5
                    let y;
                    
                    try {
                        y = func.call(this, z);
                        if (isNaN(y) || !isFinite(y)) continue;
                    } catch (e) {
                        continue;
                    }
                    
                    const canvasX = 50 + (z + 5) / 10 * (canvas.width - 70);
                    const canvasY = canvas.height - 50 - y * (canvas.height - 70);
                    
                    if (i === 0) {
                        ctx.moveTo(canvasX, canvasY);
                    } else {
                        ctx.lineTo(canvasX, canvasY);
                    }
                }
                ctx.stroke();
            }
        });
        
        // Draw legend
        let legendY = 30;
        functions.forEach(({name, color, label}) =&gt; {
            const checkbox = document.getElementById(`show-${name}`);
            if (checkbox &amp;&amp; checkbox.checked) {
                ctx.strokeStyle = color;
                ctx.lineWidth = 3;
                ctx.beginPath();
                ctx.moveTo(canvas.width - 150, legendY);
                ctx.lineTo(canvas.width - 120, legendY);
                ctx.stroke();
                
                ctx.fillStyle = &apos;#333&apos;;
                ctx.font = &apos;12px Arial&apos;;
                ctx.fillText(label, canvas.width - 115, legendY + 4);
                
                legendY += 20;
            }
        });
        
        // Labels
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;z&apos;, canvas.width - 15, canvas.height - 30);
        ctx.fillText(&apos;P(y=1|z)&apos;, 10, 15);
        
        // Axis labels
        ctx.fillText(&apos;-5&apos;, 45, canvas.height - 30);
        ctx.fillText(&apos;0&apos;, 245, canvas.height - 30);
        ctx.fillText(&apos;5&apos;, 445, canvas.height - 30);
        ctx.fillText(&apos;0&apos;, 35, canvas.height - 45);
        ctx.fillText(&apos;0.5&apos;, 30, canvas.height/2 + 5);
        ctx.fillText(&apos;1&apos;, 35, 25);
    }
}

// Initialize comparison when page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, () =&gt; {
    new LinkFunctionsComparison();
});
&lt;/script&gt;

&lt;h2 id=&quot;-hướng-dẫn-lựa-chọn-link-function&quot;&gt;🎯 Hướng dẫn Lựa chọn Link Function&lt;/h2&gt;

&lt;h3 id=&quot;sigmoid-logistic---lựa-chọn-mặc-định-&quot;&gt;&lt;strong&gt;Sigmoid (Logistic)&lt;/strong&gt; - Lựa chọn Mặc định ⭐&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Sử dụng khi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bài toán phân loại nhị phân chuẩn&lt;/li&gt;
  &lt;li&gt;Cần tốc độ tính toán cao&lt;/li&gt;
  &lt;li&gt;Muốn giải thích odds ratio&lt;/li&gt;
  &lt;li&gt;Dữ liệu cân bằng, không có outliers cực đoan&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;probit---cho-dữ-liệu-gaussian&quot;&gt;&lt;strong&gt;Probit&lt;/strong&gt; - Cho Dữ liệu Gaussian&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Sử dụng khi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Dữ liệu có phân phối gần Gaussian&lt;/li&gt;
  &lt;li&gt;Cần mô hình hóa threshold effects&lt;/li&gt;
  &lt;li&gt;Quan tâm đến tail behavior chính xác&lt;/li&gt;
  &lt;li&gt;Có thời gian tính toán (chậm hơn sigmoid)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;complementary-log-log---cho-rare-events&quot;&gt;&lt;strong&gt;Complementary Log-log&lt;/strong&gt; - Cho Rare Events&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Sử dụng khi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Modeling rare events (y=1 hiếm)&lt;/li&gt;
  &lt;li&gt;Survival analysis&lt;/li&gt;
  &lt;li&gt;Time-to-event data&lt;/li&gt;
  &lt;li&gt;Asymmetric data distribution&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;cauchit---cho-heavy-tailed-data&quot;&gt;&lt;strong&gt;Cauchit&lt;/strong&gt; - Cho Heavy-tailed Data&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Sử dụng khi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Dữ liệu có nhiều outliers&lt;/li&gt;
  &lt;li&gt;Heavy-tailed distributions&lt;/li&gt;
  &lt;li&gt;Robust modeling cần thiết&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-tổng-kết-về-các-hàm-liên-kết&quot;&gt;💡 Tổng kết về các hàm liên kết&lt;/h2&gt;

&lt;h3 id=&quot;tại-sao-sigmoid-vẫn-là-lựa-chọn-tốt-nhất&quot;&gt;&lt;strong&gt;Tại sao Sigmoid vẫn là lựa chọn tốt nhất?&lt;/strong&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;🧮 Biểu thức toán học gọn gàng:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đạo hàm đơn giản: \(\sigma&apos;(z) = \sigma(z)(1-\sigma(z))\)&lt;/li&gt;
      &lt;li&gt;Tính toán nhanh, ổn định số học&lt;/li&gt;
      &lt;li&gt;Không cần tra bảng hay tính tích phân&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;📊 Ý nghĩa Xác suất Tự nhiên:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Xuất phát từ log-odds model&lt;/li&gt;
      &lt;li&gt;Giải thích trực quan (odds ratio)&lt;/li&gt;
      &lt;li&gt;Đối xứng quanh mức 0.5&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;⚡ Hiệu suất Tính toán:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Chỉ cần một phép chia và exponential&lt;/li&gt;
      &lt;li&gt;Gradient descent hiệu quả&lt;/li&gt;
      &lt;li&gt;Phù hợp cho big data&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;🔄 Tính Lồi Đảm bảo:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Cross-entropy với sigmoid luôn lồi&lt;/li&gt;
      &lt;li&gt;Đảm bảo nghiệm tối ưu toàn cục&lt;/li&gt;
      &lt;li&gt;Thuật toán hội tụ ổn định&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Khuyến nghị:&lt;/strong&gt; Nên bắt đầu với hàm sigmoid và chỉ chuyển sang hàm liên kết khác khi có lý do mô hình hóa cụ thể cùng kết quả thực nghiệm rõ ràng.&lt;/p&gt;

&lt;h2 id=&quot;-mở-rộng-softmax-regression-multi-class-classification&quot;&gt;🔢 Mở rộng: Softmax Regression (Multi-class Classification)&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Logistic Regression chỉ xử lý được 2 lớp. Vậy làm thế nào để phân loại nhiều lớp?&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;-từ-binary-đến-multi-class&quot;&gt;🎯 Từ Binary đến Multi-class&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bài toán Multi-class Classification:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Input&lt;/strong&gt;: \(\mathbf{x} \in \mathbb{R}^p\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Output&lt;/strong&gt;: \(y \in \{1, 2, 3, ..., K\}\) (K lớp)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mục tiêu&lt;/strong&gt;: Dự đoán xác suất cho mỗi lớp&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ thực tế:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nhận dạng chữ số&lt;/strong&gt;: 0, 1, 2, …, 9 (10 lớp)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân loại email&lt;/strong&gt;: spam, promotion, social, primary (4 lớp)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chẩn đoán bệnh&lt;/strong&gt;: khỏe mạnh, cảm lạnh, viêm họng, COVID (4 lớp)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-softmax-function&quot;&gt;🧮 Softmax Function&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Mở rộng từ Sigmoid:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sigmoid&lt;/strong&gt;: \(\sigma(z) = \frac{e^z}{1 + e^z}\) (2 lớp)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Softmax&lt;/strong&gt;: \(\text{softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_{j=1}^K e^{z_j}}\) (K lớp)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tính chất Softmax:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Tổng bằng 1&lt;/strong&gt;: \(\sum_{i=1}^K \text{softmax}(\mathbf{z})_i = 1\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Luôn dương&lt;/strong&gt;: \(\text{softmax}(\mathbf{z})_i &amp;gt; 0\) \(\forall i\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Monotonic&lt;/strong&gt;: Lớp có \(z_i\) lớn hơn → xác suất cao hơn&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Smooth&lt;/strong&gt;: Khả vi mọi nơi&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-mô-hình-softmax-regression&quot;&gt;🏗️ Mô hình Softmax Regression&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Tham số mô hình:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{W} \in \mathbb{R}^{p \times K}\): ma trận trọng số&lt;/li&gt;
  &lt;li&gt;\(\mathbf{b} \in \mathbb{R}^K\): bias vector&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Forward pass:&lt;/strong&gt;
\(\mathbf{z} = \mathbf{W}^T \mathbf{x} + \mathbf{b}\)&lt;/p&gt;

\[P(y = k | \mathbf{x}) = \frac{e^{z_k}}{\sum_{j=1}^K e^{z_j}}\]

&lt;p&gt;&lt;strong&gt;Dự đoán:&lt;/strong&gt;
\(\hat{y} = \arg\max_k P(y = k | \mathbf{x})\)&lt;/p&gt;

&lt;h3 id=&quot;-cross-entropy-loss-cho-multi-class&quot;&gt;📊 Cross-Entropy Loss cho Multi-class&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;One-hot encoding:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(y = 2\) (lớp 2) → \(\mathbf{y} = [0, 1, 0, 0]\) (nếu K=4)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Multi-class Cross-Entropy:&lt;/strong&gt;
\(J(\mathbf{W}) = -\sum_{i=1}^n \sum_{k=1}^K y_{i,k} \log p_{i,k}\)&lt;/p&gt;

&lt;p&gt;với:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(y_{i,k}\): one-hot encoding của sample \(i\)&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;$$p_{i,k} = P(y = k&lt;/td&gt;
          &lt;td&gt;\mathbf{x}_i)$$: xác suất dự đoán&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mở rộng tự nhiên&lt;/strong&gt; từ binary cross-entropy&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vẫn convex&lt;/strong&gt; → gradient descent hoạt động tốt&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phạt nặng dự đoán sai&lt;/strong&gt; như binary case&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-so-sánh-binary-vs-multi-class&quot;&gt;🔄 So sánh Binary vs Multi-class&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khía cạnh&lt;/th&gt;
      &lt;th&gt;Binary Logistic&lt;/th&gt;
      &lt;th&gt;Softmax Regression&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Số lớp&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;K ≥ 2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Activation&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Sigmoid&lt;/td&gt;
      &lt;td&gt;Softmax&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tham số&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\mathbf{w} \in \mathbb{R}^p\)&lt;/td&gt;
      &lt;td&gt;\(\mathbf{W} \in \mathbb{R}^{p \times K}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;1 xác suất&lt;/td&gt;
      &lt;td&gt;K xác suất&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Loss&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Binary cross-entropy&lt;/td&gt;
      &lt;td&gt;Multi-class cross-entropy&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Gradient&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\mathbf{X}^T(\boldsymbol{\sigma} - \mathbf{y})\)&lt;/td&gt;
      &lt;td&gt;\(\mathbf{X}^T(\mathbf{P} - \mathbf{Y})\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-interactive-softmax-demo&quot;&gt;🎛️ Interactive Softmax Demo&lt;/h3&gt;

&lt;div id=&quot;softmax-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;display: flex; gap: 20px; margin-bottom: 20px;&quot;&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;🎚️ Điều khiển Logits&lt;/h4&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;z1-slider&quot;&gt;z₁ (Class 1): &lt;span id=&quot;z1-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;z1-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;z2-slider&quot;&gt;z₂ (Class 2): &lt;span id=&quot;z2-value&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;z2-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;0.5&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;z3-slider&quot;&gt;z₃ (Class 3): &lt;span id=&quot;z3-value&quot;&gt;-0.5&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;z3-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;-0.5&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;z4-slider&quot;&gt;z₄ (Class 4): &lt;span id=&quot;z4-value&quot;&gt;-1.0&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;z4-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;-1.0&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📊 Softmax Probabilities&lt;/h4&gt;
            &lt;div id=&quot;probabilities-display&quot; style=&quot;font-family: monospace; font-size: 14px;&quot;&gt;
                &lt;div&gt;Class 1: &lt;span id=&quot;p1&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;div&gt;Class 2: &lt;span id=&quot;p2&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;div&gt;Class 3: &lt;span id=&quot;p3&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;div&gt;Class 4: &lt;span id=&quot;p4&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;hr /&gt;
                &lt;div&gt;&lt;strong&gt;Sum: &lt;span id=&quot;sum&quot;&gt;1.000&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
                &lt;div&gt;&lt;strong&gt;Predicted: Class &lt;span id=&quot;predicted&quot;&gt;1&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px;&quot;&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📈 Probability Bars&lt;/h4&gt;
            &lt;canvas id=&quot;prob-bars-canvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;🥧 Probability Pie Chart&lt;/h4&gt;
            &lt;canvas id=&quot;prob-pie-canvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
class SoftmaxDemo {
    constructor() {
        this.z = [1.0, 0.5, -0.5, -1.0];
        this.colors = [&apos;#FF6B6B&apos;, &apos;#4ECDC4&apos;, &apos;#45B7D1&apos;, &apos;#96CEB4&apos;];
        this.setupEventListeners();
        this.updateDisplay();
    }
    
    setupEventListeners() {
        for (let i = 1; i &lt;= 4; i++) {
            const slider = document.getElementById(`z${i}-slider`);
            if (slider) {
                slider.addEventListener(&apos;input&apos;, (e) =&gt; {
                    this.z[i-1] = parseFloat(e.target.value);
                    document.getElementById(`z${i}-value`).textContent = this.z[i-1].toFixed(1);
                    this.updateDisplay();
                });
            }
        }
    }
    
    softmax(z) {
        const maxZ = Math.max(...z);
        const expZ = z.map(zi =&gt; Math.exp(zi - maxZ)); // Numerical stability
        const sumExpZ = expZ.reduce((sum, exp) =&gt; sum + exp, 0);
        return expZ.map(exp =&gt; exp / sumExpZ);
    }
    
    updateDisplay() {
        const probs = this.softmax(this.z);
        const sum = probs.reduce((s, p) =&gt; s + p, 0);
        const predicted = probs.indexOf(Math.max(...probs)) + 1;
        
        // Update probability display
        for (let i = 1; i &lt;= 4; i++) {
            const elem = document.getElementById(`p${i}`);
            if (elem) {
                elem.textContent = probs[i-1].toFixed(3);
                elem.style.color = this.colors[i-1];
                elem.style.fontWeight = predicted === i ? &apos;bold&apos; : &apos;normal&apos;;
            }
        }
        
        const sumElem = document.getElementById(&apos;sum&apos;);
        if (sumElem) sumElem.textContent = sum.toFixed(3);
        
        const predElem = document.getElementById(&apos;predicted&apos;);
        if (predElem) {
            predElem.textContent = predicted;
            predElem.style.color = this.colors[predicted-1];
        }
        
        this.drawBars(probs);
        this.drawPie(probs);
    }
    
    drawBars(probs) {
        const canvas = document.getElementById(&apos;prob-bars-canvas&apos;);
        if (!canvas) return;
        
        const ctx = canvas.getContext(&apos;2d&apos;);
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        const barWidth = 60;
        const maxHeight = 200;
        const startX = 50;
        const startY = canvas.height - 50;
        
        // Draw axes
        ctx.strokeStyle = &apos;#ccc&apos;;
        ctx.lineWidth = 1;
        ctx.beginPath();
        ctx.moveTo(30, 30);
        ctx.lineTo(30, startY);
        ctx.lineTo(canvas.width - 20, startY);
        ctx.stroke();
        
        // Draw bars
        for (let i = 0; i &lt; 4; i++) {
            const x = startX + i * (barWidth + 20);
            const height = probs[i] * maxHeight;
            
            ctx.fillStyle = this.colors[i];
            ctx.fillRect(x, startY - height, barWidth, height);
            
            // Labels
            ctx.fillStyle = &apos;#333&apos;;
            ctx.font = &apos;12px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(`Class ${i+1}`, x + barWidth/2, startY + 20);
            ctx.fillText(probs[i].toFixed(3), x + barWidth/2, startY - height - 5);
        }
        
        // Y-axis labels
        ctx.textAlign = &apos;right&apos;;
        ctx.fillText(&apos;0.0&apos;, 25, startY + 5);
        ctx.fillText(&apos;0.5&apos;, 25, startY - maxHeight/2 + 5);
        ctx.fillText(&apos;1.0&apos;, 25, startY - maxHeight + 5);
    }
    
    drawPie(probs) {
        const canvas = document.getElementById(&apos;prob-pie-canvas&apos;);
        if (!canvas) return;
        
        const ctx = canvas.getContext(&apos;2d&apos;);
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        const centerX = canvas.width / 2;
        const centerY = canvas.height / 2;
        const radius = 100;
        
        let currentAngle = -Math.PI / 2; // Start from top
        
        for (let i = 0; i &lt; 4; i++) {
            const sliceAngle = probs[i] * 2 * Math.PI;
            
            // Draw slice
            ctx.beginPath();
            ctx.moveTo(centerX, centerY);
            ctx.arc(centerX, centerY, radius, currentAngle, currentAngle + sliceAngle);
            ctx.closePath();
            ctx.fillStyle = this.colors[i];
            ctx.fill();
            ctx.strokeStyle = &apos;#fff&apos;;
            ctx.lineWidth = 2;
            ctx.stroke();
            
            // Draw label
            if (probs[i] &gt; 0.05) { // Only show label if slice is big enough
                const labelAngle = currentAngle + sliceAngle / 2;
                const labelX = centerX + Math.cos(labelAngle) * radius * 0.7;
                const labelY = centerY + Math.sin(labelAngle) * radius * 0.7;
                
                ctx.fillStyle = &apos;#fff&apos;;
                ctx.font = &apos;bold 12px Arial&apos;;
                ctx.textAlign = &apos;center&apos;;
                ctx.fillText(`${i+1}`, labelX, labelY + 4);
            }
            
            currentAngle += sliceAngle;
        }
        
        // Legend
        for (let i = 0; i &lt; 4; i++) {
            const legendY = 20 + i * 20;
            ctx.fillStyle = this.colors[i];
            ctx.fillRect(20, legendY, 15, 15);
            ctx.fillStyle = &apos;#333&apos;;
            ctx.font = &apos;12px Arial&apos;;
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(`Class ${i+1}: ${(probs[i] * 100).toFixed(1)}%`, 40, legendY + 12);
        }
    }
}

// Initialize demo when page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, () =&gt; {
    if (document.getElementById(&apos;softmax-demo&apos;)) {
        new SoftmaxDemo();
    }
});
&lt;/script&gt;

&lt;style&gt;
#softmax-demo {
    font-family: Arial, sans-serif;
    max-width: 1000px;
    margin: 0 auto;
}

#softmax-demo canvas {
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#softmax-demo input[type=&quot;range&quot;] {
    width: 100%;
    margin: 5px 0;
}

#probabilities-display {
    background-color: #f5f5f5;
    padding: 15px;
    border-radius: 4px;
    line-height: 1.6;
}

#probabilities-display div {
    margin: 5px 0;
}
&lt;/style&gt;

&lt;h3 id=&quot;-ứng-dụng-thực-tế-của-softmax&quot;&gt;🎯 Ứng dụng Thực tế của Softmax&lt;/h3&gt;

&lt;h4 id=&quot;1-computer-vision&quot;&gt;&lt;strong&gt;1. Computer Vision&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Image Classification&lt;/strong&gt;: ImageNet (1000 lớp)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Object Detection&lt;/strong&gt;: COCO dataset (80 lớp)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Medical Imaging&lt;/strong&gt;: Phân loại X-ray, MRI&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-natural-language-processing&quot;&gt;&lt;strong&gt;2. Natural Language Processing&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sentiment Analysis&lt;/strong&gt;: positive, negative, neutral&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Language Detection&lt;/strong&gt;: English, Vietnamese, Chinese, …&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Text Classification&lt;/strong&gt;: news categories, spam detection&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-recommendation-systems&quot;&gt;&lt;strong&gt;3. Recommendation Systems&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Content Categories&lt;/strong&gt;: movies, music, books&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;User Preferences&lt;/strong&gt;: age groups, interests&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Product Classification&lt;/strong&gt;: electronics, fashion, food&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-kết-nối-với-deep-learning&quot;&gt;🔄 Kết nối với Deep Learning&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Softmax là building block quan trọng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Output layer&lt;/strong&gt; của neural networks&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Attention mechanisms&lt;/strong&gt; trong Transformers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Policy networks&lt;/strong&gt; trong Reinforcement Learning&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Từ Logistic → Softmax → Neural Networks:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Logistic Regression&lt;/strong&gt;: Linear + Sigmoid&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Softmax Regression&lt;/strong&gt;: Linear + Softmax&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Neural Networks&lt;/strong&gt;: Multiple layers + Softmax&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-tóm-tắt-softmax-regression&quot;&gt;💡 Tóm tắt Softmax Regression&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Mở rộng tự nhiên&lt;/strong&gt; từ phân loại nhị phân sang đa lớp.&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Đầu ra dạng xác suất&lt;/strong&gt; dễ diễn giải.&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Bài toán tối ưu hóa lồi&lt;/strong&gt;, đảm bảo hội tụ ổn định.&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Huấn luyện hiệu quả&lt;/strong&gt; bằng hạ gradient.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Nhược điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;❌ &lt;strong&gt;Biên quyết định tuyến tính&lt;/strong&gt; (tương tự hồi quy logistic).&lt;/li&gt;
  &lt;li&gt;❌ &lt;strong&gt;Khó mô hình hóa&lt;/strong&gt; các ranh giới phi tuyến phức tạp nếu không biến đổi đặc trưng.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Khi nào nên sử dụng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bài toán phân loại đa lớp cần đầu ra xác suất.&lt;/li&gt;
  &lt;li&gt;Làm mô hình cơ sở (baseline) trước khi thử các mô hình phức tạp hơn.&lt;/li&gt;
  &lt;li&gt;Các bài toán yêu cầu khả năng giải thích hệ số.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hồi quy Softmax là bước chuyển tự nhiên&lt;/strong&gt; từ hồi quy logistic nhị phân sang các kiến trúc mạng nơ-ron đa lớp.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-02-03 Hồi Quy Tuyến Tính từ Góc Nhìn Thống Kê</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_02_03_Linear_Regression_Statistical_View/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_02_03_Linear_Regression_Statistical_View</id>
   <content type="html">&lt;p&gt;Khi học Bình phương tối thiểu ở bài trước, một câu hỏi đầy hoài nghi thường nảy ra: &lt;em&gt;tại sao lại tối thiểu hóa tổng &lt;strong&gt;bình phương&lt;/strong&gt; sai số \(\sum (y_i - x_i^T \beta)^2\) chứ không phải tổng trị tuyệt đối hay tổng lập phương?&lt;/em&gt; Câu trả lời bất ngờ đến từ thống kê học: việc chọn chuẩn bình phương không hề là một sự tùy hứng hình học!&lt;/p&gt;

&lt;p&gt;Nếu bạn giả định dữ liệu sinh ra bởi một quy luật tuyến tính cộng thêm nhiễu Gaussian độc lập \(\epsilon_i \sim \mathcal{N}(0, \sigma^2)\), thì việc đi tìm bộ tham số \(\beta\) làm cho dữ liệu quan sát được có xác suất xuất hiện cao nhất (&lt;strong&gt;Ước lượng Hợp lý Tối đa — MLE&lt;/strong&gt;) sẽ dẫn ra &lt;strong&gt;chính xác từng dấu phẩy&lt;/strong&gt; bài toán tối ưu lồi Bình phương tối thiểu! Bài học này bắc cây cầu giữa Tối ưu hóa Lồi và Thống kê Suy luận.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-khi-tối-ưu-hóa-lồi-gặp-thống-kê-xác-suất&quot;&gt;Kiến thức cần nhớ: Khi Tối ưu hóa Lồi gặp Thống kê Xác suất&lt;/h2&gt;

&lt;p&gt;Bốn trụ cột dưới đây kết nối hàm mất mát tối ưu với mô hình xác suất sinh dữ liệu:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình sinh dữ liệu Gaussian (Probabilistic Generative Model):&lt;/strong&gt; Giả định \(y_i = x_i^T \beta + \epsilon_i\) với \(\epsilon_i \stackrel{\text{i.i.d.}}{\sim} \mathcal{N}(0, \sigma^2)\) tương đương với phân phối có điều kiện \(y_i \mid x_i \sim \mathcal{N}(x_i^T \beta, \sigma^2)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm Hợp lý &amp;amp; Phép biến đổi Log-Likelihood:&lt;/strong&gt; Hàm hợp lý \(L(\beta) = \prod_{i=1}^n p(y_i \mid x_i; \beta)\) là tích của nhiều hàm mũ — rất khó tối ưu trực tiếp và dễ tràn số dưới (underflow). Nhờ \(\log\) là hàm đơn điệu tăng (Chương 04!), cực đại hóa \(L(\beta)\) tương đương cực đại hóa \(\ell(\beta) = \sum_{i=1}^n \log p(y_i \mid x_i; \beta)\), và cực tiểu hóa &lt;strong&gt;Negative Log-Likelihood (NLL)&lt;/strong&gt; cho ngay bài toán lồi \(\frac{1}{2\sigma^2}\sum_{i=1}^n (y_i - x_i^T \beta)^2\)!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Phân phối nhiễu quyết định Hàm mất mát:&lt;/strong&gt; Đổi giả định nhiễu từ Gaussian sang &lt;strong&gt;Laplace&lt;/strong&gt; ($$\exp(-&lt;/td&gt;
          &lt;td&gt;\epsilon&lt;/td&gt;
          &lt;td&gt;/b)\() sẽ biến NLL thành hồi quy chuẩn\)\ell_1\((bền vững trước ngoại lai)! Còn thêm phân phối tiên nghiệm Gaussian lên\)\beta\((ước lượng MAP) sẽ sinh ra đúng hồi quy **Ridge (\)\ell_2\()**, và tiên nghiệm Laplace sinh ra **Lasso (\)\ell_1$$)**!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý Gauss–Markov &amp;amp; Độ bất định của ước lượng:&lt;/strong&gt; Không chỉ cho điểm tối ưu \(\hat{\beta}_{\text{MLE}}\), góc nhìn thống kê còn cho ta ma trận hiệp phương sai \(\operatorname{Cov}(\hat{\beta}) = \sigma^2 (X^T X)^{-1}\) để tính khoảng tin cậy và kiểm định giả thuyết.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-hàm-log-likelihood-và-kiểm-chứng-mle-trùng-khớp-với-ols&quot;&gt;Giải thích: Tính tay hàm Log-Likelihood và kiểm chứng MLE trùng khớp với OLS&lt;/h3&gt;

&lt;p&gt;Xét mô hình 1 tham số không hệ số chặn \(y_i = \beta x_i + \epsilon_i\) với \(\epsilon_i \sim \mathcal{N}(0, \sigma^2 = 4)\) trên 2 quan sát: \((x_1, y_1) = (1, 2)\) và \((x_2, y_2) = (2, 5)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Viết hàm mật độ hợp lý:&lt;/strong&gt;
\(L(\beta) = \frac{1}{\sqrt{2\pi \cdot 4}} \exp\left(-\frac{(2 - \beta)^2}{8}\right) \cdot \frac{1}{\sqrt{2\pi \cdot 4}} \exp\left(-\frac{(5 - 2\beta)^2}{8}\right).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Lấy âm logarit (Negative Log-Likelihood):&lt;/strong&gt;
\(-\ell(\beta) = \log(8\pi) + \frac{1}{8}\Big[(2 - \beta)^2 + (5 - 2\beta)^2\Big].\)
Hằng số \(\log(8\pi)\) và hệ số dương \(\frac{1}{8}\) không ảnh hưởng đến vị trí cực tiểu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Cực tiểu hóa phần bình phương sai số:&lt;/strong&gt;
\(S(\beta) = (2 - \beta)^2 + (5 - 2\beta)^2 = (4 - 4\beta + \beta^2) + (25 - 20\beta + 4\beta^2) = 5\beta^2 - 24\beta + 29.\)
Đạo hàm: \(S&apos;(\beta) = 10\beta - 24 = 0 \implies \hat{\beta}_{\text{MLE}} = 2.4\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — Tính phương sai ước lượng:&lt;/strong&gt;
Vì \(X^T X = 1^2 + 2^2 = 5\) và \(\sigma^2 = 4\), ta có \(\operatorname{Var}(\hat{\beta}_{\text{MLE}}) = \frac{\sigma^2}{X^T X} = \frac{4}{5} = 0.8\) (độ lệch chuẩn \(\approx 0.894\)). Góc nhìn thống kê cho ta không chỉ con số \(2.4\), mà cả thước đo mức độ tin cậy của nó!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;hồi-quy-tuyến-tính-từ-góc-nhìn-thống-kê&quot;&gt;Hồi Quy Tuyến Tính từ Góc Nhìn Thống Kê&lt;/h2&gt;

&lt;p&gt;Trong bài học này, chúng ta khám phá hồi quy tuyến tính từ góc nhìn xác suất và thống kê, cho thấy việc cực tiểu hóa sai số bình phương trung bình (MSE) không chỉ có ý nghĩa trực quan mà còn có cơ sở lý thuyết chặt chẽ thông qua ước lượng hợp lý cực đại (Maximum Likelihood Estimation - MLE).&lt;/p&gt;

&lt;h3 id=&quot;1-diễn-giải-xác-suất-của-hồi-quy-tuyến-tính&quot;&gt;1. Diễn Giải Xác Suất của Hồi Quy Tuyến Tính&lt;/h3&gt;

&lt;p&gt;Dưới góc nhìn xác suất, nghiệm của bài toán hồi quy tuyến tính thu được từ việc cực tiểu hóa MSE có thể được lý giải trực tiếp bằng mô hình nhiễu thống kê.&lt;/p&gt;

&lt;p&gt;Thật vậy, chúng ta giả định biến mục tiêu và biến đầu vào liên hệ với nhau qua phương trình:&lt;/p&gt;

\[y_i = \mathbf{w}^\top \mathbf{x}_i + \epsilon_i\]

&lt;p&gt;trong đó \(\epsilon_i\) biểu diễn sai số ngẫu nhiên (những yếu tố không được mô hình giải thích). Theo các giả thiết Gauss–Markov cổ điển, sai số ngẫu nhiên thỏa mãn:&lt;/p&gt;

&lt;h4 id=&quot;giả-thiết-1-sai-số-có-kỳ-vọng-bằng-0&quot;&gt;Giả thiết 1: Sai số có kỳ vọng bằng 0&lt;/h4&gt;
&lt;p&gt;Các sai số \(\epsilon_i\) là đại lượng ngẫu nhiên có kỳ vọng bằng 0:&lt;/p&gt;

\[\mathbb{E}(\epsilon_i) = 0\]

&lt;h4 id=&quot;giả-thiết-2-các-sai-số-không-tương-quan&quot;&gt;Giả thiết 2: Các sai số không tương quan&lt;/h4&gt;
&lt;p&gt;Các sai số ngẫu nhiên không có sự tương quan:&lt;/p&gt;

\[\mathbb{E}(\epsilon_i \epsilon_j) = 0, \quad \forall i \neq j\]

&lt;h4 id=&quot;giả-thiết-3-phương-sai-đồng-nhất-homoscedasticity&quot;&gt;Giả thiết 3: Phương sai đồng nhất (Homoscedasticity)&lt;/h4&gt;
&lt;p&gt;Phương sai của sai số ngẫu nhiên là bất biến:&lt;/p&gt;

\[\text{Var}(\epsilon_i) = \sigma^2\]

&lt;h4 id=&quot;giả-thiết-4-sai-số-không-tương-quan-với-biến-đầu-vào&quot;&gt;Giả thiết 4: Sai số không tương quan với biến đầu vào&lt;/h4&gt;
&lt;p&gt;Sai số ngẫu nhiên \(\epsilon_i\) và biến đầu vào \(\mathbf{x}_i\) không tương quan với nhau:&lt;/p&gt;

\[\text{Cov}(\mathbf{x}_i, \epsilon_i) = 0, \quad \forall i = 1, \dots, n\]

&lt;h3 id=&quot;2-phân-phối-gaussian-của-sai-số&quot;&gt;2. Phân Phối Gaussian của Sai Số&lt;/h3&gt;

&lt;p&gt;Nếu giả định thêm rằng các sai số ngẫu nhiên \(\epsilon_i\) độc lập và tuân theo phân phối Gaussian (phân phối chuẩn) với kỳ vọng bằng 0 và phương sai \(\sigma^2\), ký hiệu \(\epsilon_i \sim \mathcal{N}(0, \sigma^2)\), thì hàm mật độ xác suất tại mỗi điểm \(\epsilon_i\) là:&lt;/p&gt;

\[p(\epsilon_i) = \frac{1}{\sqrt{2\pi \sigma^2}} \exp \left( -\frac{\epsilon_i^2}{2\sigma^2} \right)\]

&lt;p&gt;Thay \(\epsilon_i = y_i - \mathbf{w}^\top \mathbf{x}_i\) vào hàm mật độ xác suất, ta thu được:&lt;/p&gt;

\[p(y_i \mid \mathbf{x}_i; \mathbf{w}) = \frac{1}{\sqrt{2\pi \sigma^2}} \exp \left( -\frac{(y_i - \mathbf{w}^\top \mathbf{x}_i)^2}{2\sigma^2} \right)\]

&lt;p&gt;Ký hiệu \(p(y_i \mid \mathbf{x}_i; \mathbf{w})\) biểu diễn mật độ xác suất có điều kiện của \(y_i\) khi biết \(\mathbf{x}_i\), được tham số hóa bởi \(\mathbf{w}\). Vì \(\mathbf{w}\) là tham số cố định chứ không phải biến ngẫu nhiên điều kiện, ta dùng dấu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;;&lt;/code&gt; thay vì dấu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;,&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;3-ước-lượng-hợp-lý-tối-đa&quot;&gt;3. Ước Lượng Hợp Lý Tối Đa&lt;/h3&gt;

&lt;p&gt;Khi cố định dữ liệu quan sát và xét biểu thức trên như một hàm theo tham số \(\mathbf{w}\), ta thu được hàm hợp lý (likelihood):&lt;/p&gt;

\[L(\mathbf{w}) = L(\mathbf{w}; \mathbf{X}, \mathbf{y}) = p(\mathbf{y} \mid \mathbf{X}; \mathbf{w})\]

&lt;p&gt;Vì các sai số Gaussian không tương quan nên chúng độc lập với nhau; do đó mật độ đồng thời của tập dữ liệu bằng tích mật độ của từng mẫu:&lt;/p&gt;

\[\begin{align}
L(\mathbf{w}) &amp;amp;= \prod_{i=1}^{n} p(y_i \mid \mathbf{x}_i; \mathbf{w}) \\
&amp;amp;= \prod_{i=1}^{n} \frac{1}{\sqrt{2\pi \sigma^2}} \exp \left( -\frac{\epsilon_i^2}{2\sigma^2} \right)
\end{align}\]

&lt;p&gt;Hàm hợp lý đo mức độ phù hợp của tham số \(\mathbf{w}\) với dữ liệu quan sát \((\mathbf{X}, \mathbf{y})\). Theo nguyên lý ước lượng hợp lý cực đại (MLE), ta chọn \(\mathbf{w}\) làm cực đại hóa \(L(\mathbf{w})\).&lt;/p&gt;

&lt;h3 id=&quot;4-tối-ưu-hóa-log-likelihood&quot;&gt;4. Tối Ưu Hóa Log-Likelihood&lt;/h3&gt;

&lt;p&gt;Lấy logarit hai vế để đơn giản hóa bài toán tối ưu:&lt;/p&gt;

\[\begin{align}
\hat{\mathbf{w}} &amp;amp;= \arg \max \log L(\mathbf{w}) \\
&amp;amp;= \arg \max \log \left[ \prod_{i=1}^{n} \frac{1}{\sqrt{2\pi \sigma^2}} \exp \left( -\frac{\epsilon_i^2}{2\sigma^2} \right) \right] \\
&amp;amp;= \arg \max \sum_{i=1}^{n} \log \left[ \frac{1}{\sqrt{2\pi \sigma^2}} \exp \left( -\frac{\epsilon_i^2}{2\sigma^2} \right) \right] \\
&amp;amp;= \arg \max \sum_{i=1}^{n} \left[ -\frac{\epsilon_i^2}{2\sigma^2} - \log \sqrt{2\pi \sigma^2} \right] \\
&amp;amp;= \arg \max \left[ -\frac{1}{2\sigma^2} \sum_{i=1}^{n} \epsilon_i^2 - n \log \sqrt{2\pi \sigma^2} \right]
\end{align}\]

&lt;p&gt;Vì \(\sigma^2\) và \(2\pi\) là các hằng số dương, việc cực đại hóa hàm log-likelihood tương đương với cực tiểu hóa tổng bình phương phần dư:&lt;/p&gt;

\[\sum_{i=1}^{n} \epsilon_i^2 = \sum_{i=1}^{n} (y_i - \mathbf{w}^\top \mathbf{x}_i)^2\]

&lt;p&gt;Điều này tương đương với việc tối thiểu hóa hàm MSE:&lt;/p&gt;

\[\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2\]

&lt;h3 id=&quot;5-chứng-minh-lý-thuyết&quot;&gt;5. Chứng Minh Lý Thuyết&lt;/h3&gt;

&lt;p&gt;Như vậy, dưới giả định sai số phân phối chuẩn độc lập đồng nhất, bài toán bình phương tối thiểu tương đương với ước lượng hợp lý cực đại. Ngoài ra, theo định lý Gauss–Markov, chỉ cần các giả thiết Gauss–Markov được thỏa mãn (kể cả không cần giả định chuẩn), ước lượng OLS đã là ước lượng tuyến tính không chệch tốt nhất (BLUE). Giả định phân phối chuẩn cho phép xây dựng thêm các khoảng tin cậy và kiểm định ý nghĩa thống kê (p-value) cho các hệ số.&lt;/p&gt;

&lt;div id=&quot;mle-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Trực Quan Hóa Ước Lượng Hợp Lý Tối Đa&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;!-- Canvas for visualization --&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;mleCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Trực quan hóa:&lt;/strong&gt; Các chấm xanh là điểm dữ liệu, đường đỏ là đường khớp, và các đường cong thể hiện phân phối Gaussian của sai số.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;!-- Controls --&gt;
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Tham Số&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;noise-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;Mức Nhiễu (σ): &lt;span id=&quot;noise-value&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;noise-slider&quot; min=&quot;0.1&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;0.5&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;slope-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;Hệ Số Góc Thực: &lt;span id=&quot;true-slope-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;slope-slider&quot; min=&quot;-2&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;intercept-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;Hệ Số Chặn Thực: &lt;span id=&quot;true-intercept-value&quot;&gt;0.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;intercept-slider&quot; min=&quot;-2&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;0.0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;button id=&quot;generate-data&quot; style=&quot;width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 10px;&quot;&gt;Tạo Dữ Liệu Mới&lt;/button&gt;
                
                &lt;div id=&quot;mle-results&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Ước Lượng MLE:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Hệ số góc: &lt;span id=&quot;mle-slope&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Hệ số chặn: &lt;span id=&quot;mle-intercept&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Log-Likelihood: &lt;span id=&quot;log-likelihood&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;6-huấn-luyện-mô-hình-hồi-quy-tuyến-tính-trên-sklearn&quot;&gt;6. Huấn Luyện Mô Hình Hồi Quy Tuyến Tính trên Sklearn&lt;/h3&gt;

&lt;p&gt;Scikit-learn (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sklearn&lt;/code&gt;) là thư viện Python phổ biến cho học máy và khoa học dữ liệu, hỗ trợ huấn luyện hầu hết các mô hình học máy, xây dựng pipeline, chuẩn hóa dữ liệu, và thực hiện kiểm định chéo (cross-validation).&lt;/p&gt;

&lt;p&gt;Trong phần này, chúng ta sẽ tìm hiểu cách huấn luyện mô hình hồi quy tuyến tính trên sklearn. Quay lại bài toán trước, nếu thêm thông tin về khoảng cách tới trung tâm:&lt;/p&gt;

\[\mathbf{x}_2 = [20, 18, 17, 16, 15, 14, 12, 10, 8, 7, 5, 2, 1]\]

&lt;p&gt;khi đó bài toán trở thành hồi quy đa biến. Quy trình xây dựng và huấn luyện mô hình gồm các bước:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Thu thập dữ liệu&lt;/li&gt;
  &lt;li&gt;Làm sạch dữ liệu&lt;/li&gt;
  &lt;li&gt;Lựa chọn dữ liệu đầu vào&lt;/li&gt;
  &lt;li&gt;Chuẩn hóa dữ liệu&lt;/li&gt;
  &lt;li&gt;Phân chia tập huấn luyện/kiểm tra (train/test)&lt;/li&gt;
  &lt;li&gt;Huấn luyện và đánh giá mô hình&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ở bài toán này, chúng ta tập trung vào bước 6 để hiểu cách huấn luyện mô hình.&lt;/p&gt;

&lt;div id=&quot;sklearn-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Ví Dụ Sklearn Hồi Quy Tuyến Tính&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;!-- Code example --&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;pre style=&quot;background: #f8f9fa; padding: 15px; border-radius: 5px; overflow-x: auto; font-size: 12px;&quot;&gt;&lt;code id=&quot;sklearn-code&quot;&gt;import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score
import matplotlib.pyplot as plt

# Dữ liệu mẫu: giá nhà
# Đặc trưng: [diện_tích, khoảng_cách_tới_trung_tâm]
X = np.array([
    [50, 20], [60, 18], [70, 17], [80, 16], [90, 15],
    [100, 14], [110, 12], [120, 10], [130, 8], [140, 7],
    [150, 5], [160, 2], [170, 1]
])

# Mục tiêu: giá (nghìn đô la)
y = np.array([150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510])

# Chia dữ liệu
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.3, random_state=42
)

# Tạo và huấn luyện mô hình
model = LinearRegression()
model.fit(X_train, y_train)

# Dự đoán
y_pred = model.predict(X_test)

# Đánh giá mô hình
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)

print(f&quot;Hệ số: {model.coef_}&quot;)
print(f&quot;Hệ số chặn: {model.intercept_}&quot;)
print(f&quot;MSE: {mse:.2f}&quot;)
print(f&quot;R²: {r2:.3f}&quot;)
&lt;/code&gt;&lt;/pre&gt;
        &lt;/div&gt;
        
        &lt;!-- Interactive results --&gt;
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Kết Quả Mô Hình&lt;/h5&gt;
                
                &lt;button id=&quot;run-sklearn&quot; style=&quot;width: 100%; padding: 10px; background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 15px;&quot;&gt;Chạy Ví Dụ Sklearn&lt;/button&gt;
                
                &lt;div id=&quot;sklearn-results&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Tham Số Mô Hình:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Hệ số diện tích: &lt;span id=&quot;area-coeff&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Hệ số khoảng cách: &lt;span id=&quot;distance-coeff&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Hệ số chặn: &lt;span id=&quot;sklearn-intercept&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;&lt;strong&gt;Hiệu Suất:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;MSE: &lt;span id=&quot;sklearn-mse&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;R²: &lt;span id=&quot;sklearn-r2&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-top: 15px;&quot;&gt;
                    &lt;h6 style=&quot;margin-bottom: 10px; color: #444;&quot;&gt;Máy Tính Dự Đoán&lt;/h6&gt;
                    &lt;div style=&quot;margin-bottom: 10px;&quot;&gt;
                        &lt;label style=&quot;display: block; margin-bottom: 5px;&quot;&gt;Diện tích (m²):&lt;/label&gt;
                        &lt;input type=&quot;number&quot; id=&quot;pred-area&quot; value=&quot;100&quot; min=&quot;50&quot; max=&quot;200&quot; style=&quot;width: 100%; padding: 5px; border: 1px solid #ddd; border-radius: 3px;&quot; /&gt;
                    &lt;/div&gt;
                    &lt;div style=&quot;margin-bottom: 10px;&quot;&gt;
                        &lt;label style=&quot;display: block; margin-bottom: 5px;&quot;&gt;Khoảng cách tới trung tâm (km):&lt;/label&gt;
                        &lt;input type=&quot;number&quot; id=&quot;pred-distance&quot; value=&quot;10&quot; min=&quot;1&quot; max=&quot;20&quot; style=&quot;width: 100%; padding: 5px; border: 1px solid #ddd; border-radius: 3px;&quot; /&gt;
                    &lt;/div&gt;
                    &lt;button id=&quot;make-prediction&quot; style=&quot;width: 100%; padding: 8px; background: #17a2b8; color: white; border: none; border-radius: 3px; cursor: pointer;&quot;&gt;Dự Đoán Giá&lt;/button&gt;
                    &lt;div id=&quot;prediction-result&quot; style=&quot;margin-top: 10px; padding: 10px; background: #e9ecef; border-radius: 3px; text-align: center; font-weight: bold;&quot;&gt;
                        Giá Dự Đoán: --
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;các-điểm-chính-cần-ghi-nhớ&quot;&gt;Các điểm chính cần ghi nhớ&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nền Tảng Lý Thuyết&lt;/strong&gt;: Ước lượng hợp lý tối đa cung cấp nền tảng lý thuyết vững chắc cho việc tại sao chúng ta tối thiểu hóa sai số bình phương trong hồi quy tuyến tính.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Giả Thuyết Gaussian&lt;/strong&gt;: Hiệu quả của hồi quy tuyến tính dựa trên các giả thuyết Gauss-Markov, đặc biệt là sai số được phân phối chuẩn.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ước Lượng Không Chệch Tốt Nhất&lt;/strong&gt;: Dưới điều kiện phù hợp, OLS cung cấp BLUE - ước lượng tuyến tính không chệch hiệu quả nhất.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Triển Khai Thực Tế&lt;/strong&gt;: Các công cụ hiện đại như sklearn giúp dễ dàng triển khai các khái niệm lý thuyết này trong thực tế.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Đánh Giá Mô Hình&lt;/strong&gt;: Hiểu nền tảng thống kê giúp đánh giá mô hình đúng cách sử dụng các chỉ số như R², khoảng tin cậy và p-values.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script&gt;
// MLE Visualization
class MLEVisualization {
    constructor() {
        this.canvas = document.getElementById(&apos;mleCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        // Parameters
        this.trueSlope = 1.0;
        this.trueIntercept = 0.0;
        this.noiseLevel = 0.5;
        this.dataPoints = [];
        
        this.setupControls();
        this.generateData();
        this.draw();
    }
    
    setupControls() {
        const noiseSlider = document.getElementById(&apos;noise-slider&apos;);
        const slopeSlider = document.getElementById(&apos;slope-slider&apos;);
        const interceptSlider = document.getElementById(&apos;intercept-slider&apos;);
        const generateBtn = document.getElementById(&apos;generate-data&apos;);
        
        noiseSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.noiseLevel = parseFloat(e.target.value);
            document.getElementById(&apos;noise-value&apos;).textContent = this.noiseLevel.toFixed(1);
            this.generateData();
            this.draw();
        });
        
        slopeSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.trueSlope = parseFloat(e.target.value);
            document.getElementById(&apos;true-slope-value&apos;).textContent = this.trueSlope.toFixed(1);
            this.generateData();
            this.draw();
        });
        
        interceptSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.trueIntercept = parseFloat(e.target.value);
            document.getElementById(&apos;true-intercept-value&apos;).textContent = this.trueIntercept.toFixed(1);
            this.generateData();
            this.draw();
        });
        
        generateBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.generateData();
            this.draw();
        });
    }
    
    generateData() {
        this.dataPoints = [];
        const n = 20;
        
        for (let i = 0; i &lt; n; i++) {
            const x = (i / (n - 1)) * 4 - 2; // x from -2 to 2
            const trueY = this.trueSlope * x + this.trueIntercept;
            const noise = (Math.random() - 0.5) * 2 * this.noiseLevel;
            const y = trueY + noise;
            
            this.dataPoints.push({ x, y, trueY });
        }
    }
    
    calculateMLE() {
        const n = this.dataPoints.length;
        let sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0;
        
        for (const point of this.dataPoints) {
            sumX += point.x;
            sumY += point.y;
            sumXY += point.x * point.y;
            sumX2 += point.x * point.x;
        }
        
        const slope = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);
        const intercept = (sumY - slope * sumX) / n;
        
        // Calculate log-likelihood
        let logLikelihood = 0;
        for (const point of this.dataPoints) {
            const predicted = slope * point.x + intercept;
            const error = point.y - predicted;
            logLikelihood -= 0.5 * Math.log(2 * Math.PI * this.noiseLevel * this.noiseLevel);
            logLikelihood -= (error * error) / (2 * this.noiseLevel * this.noiseLevel);
        }
        
        return { slope, intercept, logLikelihood };
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        const mle = this.calculateMLE();
        
        // Update display
        document.getElementById(&apos;mle-slope&apos;).textContent = mle.slope.toFixed(3);
        document.getElementById(&apos;mle-intercept&apos;).textContent = mle.intercept.toFixed(3);
        document.getElementById(&apos;log-likelihood&apos;).textContent = mle.logLikelihood.toFixed(2);
        
        // Transform coordinates
        const transform = (x, y) =&gt; ({
            x: (x + 2.5) * this.width / 5,
            y: this.height - (y + 2.5) * this.height / 5
        });
        
        // Draw axes
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        this.ctx.beginPath();
        this.ctx.moveTo(0, this.height / 2);
        this.ctx.lineTo(this.width, this.height / 2);
        this.ctx.moveTo(this.width / 2, 0);
        this.ctx.lineTo(this.width / 2, this.height);
        this.ctx.stroke();
        
        // Draw fitted line
        this.ctx.strokeStyle = &apos;#ff4444&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        const start = transform(-2, mle.slope * (-2) + mle.intercept);
        const end = transform(2, mle.slope * 2 + mle.intercept);
        this.ctx.moveTo(start.x, start.y);
        this.ctx.lineTo(end.x, end.y);
        this.ctx.stroke();
        
        // Draw data points and error distributions
        for (const point of this.dataPoints) {
            const pos = transform(point.x, point.y);
            
            // Draw Gaussian error distribution
            const predicted = mle.slope * point.x + mle.intercept;
            const errorCenter = transform(point.x, predicted);
            
            this.ctx.strokeStyle = &apos;#cccccc&apos;;
            this.ctx.lineWidth = 1;
            this.ctx.beginPath();
            for (let i = 0; i &lt;= 20; i++) {
                const t = i / 20;
                const gaussY = predicted + (t - 0.5) * 4 * this.noiseLevel;
                const gaussVal = Math.exp(-0.5 * Math.pow((gaussY - predicted) / this.noiseLevel, 2));
                const gaussPos = transform(point.x + gaussVal * 0.3, gaussY);
                
                if (i === 0) {
                    this.ctx.moveTo(gaussPos.x, gaussPos.y);
                } else {
                    this.ctx.lineTo(gaussPos.x, gaussPos.y);
                }
            }
            this.ctx.stroke();
            
            // Draw data point
            this.ctx.fillStyle = &apos;#4444ff&apos;;
            this.ctx.beginPath();
            this.ctx.arc(pos.x, pos.y, 4, 0, 2 * Math.PI);
            this.ctx.fill();
            
            // Draw error line
            this.ctx.strokeStyle = &apos;#888&apos;;
            this.ctx.lineWidth = 1;
            this.ctx.beginPath();
            this.ctx.moveTo(pos.x, pos.y);
            this.ctx.lineTo(errorCenter.x, errorCenter.y);
            this.ctx.stroke();
        }
    }
}

// Sklearn Demo
class SklearnDemo {
    constructor() {
        this.setupControls();
        this.model = null;
        this.data = this.generateSampleData();
    }
    
    generateSampleData() {
        return {
            X: [
                [50, 20], [60, 18], [70, 17], [80, 16], [90, 15],
                [100, 14], [110, 12], [120, 10], [130, 8], [140, 7],
                [150, 5], [160, 2], [170, 1]
            ],
            y: [150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510]
        };
    }
    
    setupControls() {
        const runBtn = document.getElementById(&apos;run-sklearn&apos;);
        const predBtn = document.getElementById(&apos;make-prediction&apos;);
        
        runBtn.addEventListener(&apos;click&apos;, () =&gt; this.runSklearnExample());
        predBtn.addEventListener(&apos;click&apos;, () =&gt; this.makePrediction());
    }
    
    runSklearnExample() {
        // Simulate sklearn linear regression
        const { X, y } = this.data;
        
        // Calculate means
        const meanX1 = X.reduce((sum, row) =&gt; sum + row[0], 0) / X.length;
        const meanX2 = X.reduce((sum, row) =&gt; sum + row[1], 0) / X.length;
        const meanY = y.reduce((sum, val) =&gt; sum + val, 0) / y.length;
        
        // Calculate coefficients using normal equation
        let sumX1X1 = 0, sumX2X2 = 0, sumX1X2 = 0;
        let sumX1Y = 0, sumX2Y = 0;
        
        for (let i = 0; i &lt; X.length; i++) {
            const x1 = X[i][0] - meanX1;
            const x2 = X[i][1] - meanX2;
            const yVal = y[i] - meanY;
            
            sumX1X1 += x1 * x1;
            sumX2X2 += x2 * x2;
            sumX1X2 += x1 * x2;
            sumX1Y += x1 * yVal;
            sumX2Y += x2 * yVal;
        }
        
        // Solve 2x2 system
        const det = sumX1X1 * sumX2X2 - sumX1X2 * sumX1X2;
        const coeff1 = (sumX2X2 * sumX1Y - sumX1X2 * sumX2Y) / det;
        const coeff2 = (sumX1X1 * sumX2Y - sumX1X2 * sumX1Y) / det;
        const intercept = meanY - coeff1 * meanX1 - coeff2 * meanX2;
        
        // Calculate MSE and R²
        let mse = 0, tss = 0;
        for (let i = 0; i &lt; X.length; i++) {
            const predicted = coeff1 * X[i][0] + coeff2 * X[i][1] + intercept;
            const error = y[i] - predicted;
            mse += error * error;
            tss += (y[i] - meanY) * (y[i] - meanY);
        }
        mse /= X.length;
        const r2 = 1 - (mse * X.length) / tss;
        
        this.model = { coeff1, coeff2, intercept };
        
        // Update display
        document.getElementById(&apos;area-coeff&apos;).textContent = coeff1.toFixed(3);
        document.getElementById(&apos;distance-coeff&apos;).textContent = coeff2.toFixed(3);
        document.getElementById(&apos;sklearn-intercept&apos;).textContent = intercept.toFixed(3);
        document.getElementById(&apos;sklearn-mse&apos;).textContent = mse.toFixed(2);
        document.getElementById(&apos;sklearn-r2&apos;).textContent = r2.toFixed(3);
    }
    
    makePrediction() {
        if (!this.model) {
            alert(&apos;Vui lòng chạy ví dụ sklearn trước!&apos;);
            return;
        }
        
        const area = parseFloat(document.getElementById(&apos;pred-area&apos;).value);
        const distance = parseFloat(document.getElementById(&apos;pred-distance&apos;).value);
        
        const prediction = this.model.coeff1 * area + this.model.coeff2 * distance + this.model.intercept;
        
        document.getElementById(&apos;prediction-result&apos;).innerHTML = 
            `Giá Dự Đoán: &lt;strong&gt;$${prediction.toFixed(0)}k&lt;/strong&gt;`;
    }
}

// Initialize when DOM is loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    new MLEVisualization();
    new SklearnDemo();
});
&lt;/script&gt;

&lt;style&gt;
#mle-demo canvas {
    border-radius: 5px;
}

#sklearn-demo pre {
    max-height: 400px;
    overflow-y: auto;
}

.demo-container {
    margin: 20px 0;
}

input[type=&quot;range&quot;] {
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    background: #ddd;
    outline: none;
    border-radius: 5px;
}

input[type=&quot;range&quot;]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
}

input[type=&quot;range&quot;]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
    border: none;
}
&lt;/style&gt;

</content>
 </entry>
 
 <entry>
   <title>05-02-02 Quy Hoạch Hình Học</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_02_02_Geometric_Programming/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_02_02_Geometric_Programming</id>
   <content type="html">&lt;p&gt;Khi thiết kế một vi mạch điện tử hay một cánh máy bay, kỹ sư thường xuyên gặp các công thức vật lý dạng định luật lũy thừa: diện tích tỷ lệ với \(w \cdot h\), điện trở tỷ lệ với \(L \cdot w^{-1}\), công suất tiêu thụ tỷ lệ với \(C \cdot V^2 \cdot f\). Nhìn vào những biểu thức nhân chia lũy thừa ấy, bài toán trông hoàn toàn &lt;strong&gt;phi lồi&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Thế nhưng vào những năm 1960, Duffin, Peterson và Zener phát hiện ra một lớp bài toán kỳ diệu mang tên &lt;strong&gt;Quy hoạch Hình học (Geometric Programming - GP)&lt;/strong&gt;: miễn là mọi biến đều dương (\(x_i &amp;gt; 0\)), các ràng buộc bất đẳng thức là &lt;strong&gt;đa thức dương (posynomial)&lt;/strong&gt; và các ràng buộc đẳng thức là &lt;strong&gt;đơn thức dương (monomial)&lt;/strong&gt;, thì chỉ qua phép đổi biến logarit \(y_i = \log x_i\), toàn bộ bài toán lập tức biến hình thành một bài toán tối ưu hóa lồi trơn tru giải được đến độ chính xác tuyệt đối!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-đơn-thức-dương-đến-bài-toán-lồi-log-sum-exp&quot;&gt;Kiến thức cần nhớ: Từ đơn thức dương đến bài toán lồi Log-Sum-Exp&lt;/h2&gt;

&lt;p&gt;Ba trụ cột dưới đây giải mã trọn vẹn cấu trúc của Quy hoạch Hình học:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đơn thức dương (Monomial) &amp;amp; Đa thức dương (Posynomial):&lt;/strong&gt; Đơn thức dương có dạng \(c x_1^{a_1} \cdots x_n^{a_n}\) với \(c &amp;gt; 0\) và số mũ \(a_i \in \mathbb{R}\) bất kỳ (có thể âm hoặc phân số!). Đa thức dương là tổng của nhiều đơn thức dương (hệ số dương, tuyệt đối không có dấu trừ giữa các số hạng!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép đổi biến Logarit \(x_i = e^{y_i}\):&lt;/strong&gt; Dưới phép đổi biến này, mỗi đơn thức dương trở thành hàm mũ \(e^{a^T y + b}\) (với \(b = \log c\)). Lấy \(\log\) hai vế biến:
    &lt;ul&gt;
      &lt;li&gt;Ràng buộc đẳng thức đơn thức \(h(x) = 1\) thành &lt;strong&gt;đẳng thức affine&lt;/strong&gt; \(a^T y + b = 0\).&lt;/li&gt;
      &lt;li&gt;Ràng buộc bất đẳng thức đa thức dương \(\sum_k c_k x^{a_k} \le 1\) thành &lt;strong&gt;bất đẳng thức log-sum-exp&lt;/strong&gt; \(\log\left(\sum_k e^{a_k^T y + b_k}\right) \le 0\) — luôn lồi!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại sao đẳng thức phải là Monomial chứ không được là Posynomial?&lt;/strong&gt; Vì \(\log\) của một tổng hàm mũ (log-sum-exp) là hàm lồi phi affine, nên nếu đặt dấu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt; thì ràng buộc đẳng thức sẽ mất tính lồi!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-thiết-kế-hộp-chữ-nhật-thể-tích-lớn-nhất-bằng-quy-hoạch-hình-học&quot;&gt;Giải thích: Thiết kế hộp chữ nhật thể tích lớn nhất bằng Quy hoạch Hình học&lt;/h3&gt;

&lt;p&gt;Tìm kích thước dương \((w, h, d) &amp;gt; 0\) của một chiếc hộp không nắp có diện tích mặt đáy và mặt bên giới hạn:
\(\max_{w, h, d &amp;gt; 0} \; w \cdot h \cdot d \quad \text{thỏa mãn} \quad w d + 2 w h + 2 h d \le 12.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Đưa về dạng chuẩn GP:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Cực đại hóa \(w h d\) tương đương cực tiểu hóa đơn thức dương \(f_0(w, h, d) = w^{-1} h^{-1} d^{-1}\).&lt;/li&gt;
      &lt;li&gt;Chia hai vế ràng buộc cho \(12\): \(\frac{1}{12} w d + \frac{1}{6} w h + \frac{1}{6} h d \le 1\) (một đa thức dương!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Đổi biến logarit:&lt;/strong&gt; Đặt \(w = e^{y_1},\; h = e^{y_2},\; d = e^{y_3}\) và lấy \(\log\):
\(\min_{y \in \mathbb{R}^3} \; (-y_1 - y_2 - y_3) \quad \text{s.t.} \quad \log\left(\frac{1}{12} e^{y_1 + y_3} + \frac{1}{6} e^{y_1 + y_2} + \frac{1}{6} e^{y_2 + y_3}\right) \le 0.\)
Đây là bài toán tối ưu hóa lồi 100%!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Giải nhanh bằng đối xứng &amp;amp; bất đẳng thức AM-GM:&lt;/strong&gt;
Với \(w d + 2wh + 2hd \le 12\), theo AM-GM cho 3 số dương:
\(12 \ge wd + 2wh + 2hd \ge 3\sqrt[3]{(wd)(2wh)(2hd)} = 3\sqrt[3]{4(whd)^2}.\)
Dấu bằng xảy ra khi ba số hạng bằng nhau và cùng bằng \(12/3 = 4\):
\(wd = 4,\quad 2wh = 4 \implies wh = 2,\quad 2hd = 4 \implies hd = 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — Khôi phục nghiệm gốc:&lt;/strong&gt;
Nhân cả ba: \((whd)^2 = 4 \cdot 2 \cdot 2 = 16 \implies whd = 4\). Suy ra \(h^\star = \frac{4}{wd} = 1\), \(w^\star = \frac{2}{h^\star} = 2\), \(d^\star = \frac{2}{h^\star} = 2\).
Kiểm tra: diện tích \(2(2) + 2(2)(1) + 2(1)(2) = 12\), thể tích cực đại \(V^\star = 4\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này giới thiệu một lớp bài toán tối ưu ban đầu trông không lồi khi nhìn vào hàm mục tiêu và các ràng buộc gốc, nhưng có thể chuyển đổi tương đương về dạng bài toán tối ưu hóa lồi nhờ phép đổi biến thích hợp.&lt;/p&gt;

&lt;p&gt;Trước tiên, ta cần hai định nghĩa cơ bản:&lt;/p&gt;

&lt;h2 id=&quot;1-đơn-thức-dương-và-đa-thức-dương&quot;&gt;1. Đơn thức dương và Đa thức dương&lt;/h2&gt;

&lt;p&gt;Một hàm \(f: \mathbb{R}^n \to \mathbb{R}\) xác định trên miền \(\text{dom } f = \mathbb{R}^n_{++}\) (mọi thành phần đều dương chặt) có dạng:&lt;/p&gt;

\[f(x) = c x_1^{a_1} x_2^{a_2} \ldots x_n^{a_n} \quad \quad (24)\]

&lt;p&gt;trong đó \(c &amp;gt; 0\) và \(a_i \in \mathbb{R}\), được gọi là &lt;strong&gt;hàm đơn thức dương&lt;/strong&gt; (monomial).&lt;/p&gt;

&lt;p&gt;Tổng của các đơn thức dương:&lt;/p&gt;

\[f(x) = \sum_{k=1}^K c_k x_1^{a_{1k}} x_2^{a_{2k}} \ldots x_n^{a_{nk}} \quad \quad (25)\]

&lt;p&gt;với \(c_k &amp;gt; 0\), được gọi là &lt;strong&gt;hàm đa thức dương&lt;/strong&gt; (posynomial).&lt;/p&gt;

&lt;h2 id=&quot;2-bài-toán-quy-hoạch-hình-học&quot;&gt;2. Bài toán Quy hoạch Hình học&lt;/h2&gt;

&lt;p&gt;Một bài toán tối ưu có dạng:&lt;/p&gt;

\[\begin{align}
x &amp;amp;= \arg\min_x f_0(x) \\
\text{subject to: } &amp;amp;f_i(x) \leq 1, \quad i = 1, 2, \ldots, m \quad \quad (26) \\
&amp;amp;h_j(x) = 1, \quad j = 1, 2, \ldots, p
\end{align}\]

&lt;p&gt;trong đó \(f_0, f_1, \ldots, f_m\) là các đa thức dương và \(h_1, \ldots, h_p\) là các đơn thức dương, được gọi là &lt;strong&gt;bài toán Quy hoạch Hình học (Geometric Programming - GP)&lt;/strong&gt;. Điều kiện \(x \succ 0\) luôn được ngầm hiểu.&lt;/p&gt;

&lt;p&gt;Lưu ý rằng nếu \(f\) là một đa thức dương và \(h\) là một đơn thức dương, thì thương \(f/h\) cũng là một đa thức dương.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
(x, y, z) &amp;amp;= \arg\min_{x,y,z} x/y \\
\text{subject to: } &amp;amp;1 \leq x \leq 2 \\
&amp;amp;x^3 + 2y/z \leq \sqrt{y} \\
&amp;amp;x/y = z
\end{align}\]

&lt;p&gt;Bài toán này có thể viết lại về dạng chuẩn của GP:&lt;/p&gt;

\[\begin{align}
(x, y, z) &amp;amp;= \arg\min_{x,y,z} xy^{-1} \\
\text{subject to: } &amp;amp;x^{-1} \leq 1 \\
&amp;amp;(1/2)x \leq 1 \\
&amp;amp;x^3 y^{-1/2} + 2y^{1/2}z^{-1} \leq 1 \\
&amp;amp;xy^{-1}z^{-1} = 1
\end{align}\]

&lt;p&gt;Ở dạng gốc này, bài toán không phải là bài toán lồi vì hàm mục tiêu và các ràng buộc đều không lồi.&lt;/p&gt;

&lt;h2 id=&quot;3-chuyển-đổi-gp-về-dạng-lồi&quot;&gt;3. Chuyển đổi GP về dạng lồi&lt;/h2&gt;

&lt;p&gt;Ta có thể chuyển đổi bài toán GP về dạng lồi bằng phép đổi biến logarit như sau:&lt;/p&gt;

&lt;p&gt;Đặt \(y_i = \log(x_i)\), tức là \(x_i = \exp(y_i)\). Nếu \(f\) là một đơn thức dương theo \(x\), thì:&lt;/p&gt;

\[f(x) = c(\exp(y_1))^{a_1} \ldots (\exp(y_n))^{a_n} = \exp(a^T y + b)\]

&lt;p&gt;trong đó \(b = \log(c)\). Hàm \(g(y) = \exp(a^T y + b)\) là một hàm lồi theo \(y\) (vì hợp thành của một hàm lồi với một hàm affine luôn bảo toàn tính lồi; ở đây hàm \(\exp\) là hàm lồi và \(a^T y + b\) là hàm affine).&lt;/p&gt;

&lt;p&gt;Tương tự, đa thức dương trong phương trình (25) được viết lại thành:&lt;/p&gt;

\[f(x) = \sum_{k=1}^K \exp(a_k^T y + b_k)\]

&lt;p&gt;trong đó \(a_k = [a_{1k}, \ldots, a_{nk}]^T\) và \(b_k = \log(c_k)\). Biểu thức này là tổng các hàm mũ của hàm affine nên là hàm lồi theo \(y\).&lt;/p&gt;

&lt;p&gt;Bài toán GP (26) do đó được viết lại thành:&lt;/p&gt;

\[\begin{align}
y &amp;amp;= \arg\min_y \sum_{k=1}^{K_0} \exp(a_{0k}^T y + b_{0k}) \\
\text{subject to: } &amp;amp;\sum_{k=1}^{K_i} \exp(a_{ik}^T y + b_{ik}) \leq 1, \quad i = 1, \ldots, m \quad \quad (27) \\
&amp;amp;\exp(g_j^T y + h_j) = 1, \quad j = 1, \ldots, p
\end{align}\]

&lt;p&gt;trong đó \(a_{ik} \in \mathbb{R}^n\) (\(i = 0, 1, \ldots, m\)) và \(g_j \in \mathbb{R}^n\) (\(j = 1, \ldots, p\)).&lt;/p&gt;

&lt;p&gt;Áp dụng phép biến đổi đơn điệu tăng \(\log(\cdot)\) cho hàm mục tiêu và hai vế của các ràng buộc, đồng thời sử dụng tính chất hàm \(\log \sum_{k} \exp(a_k^T y + b_k)\) (log-sum-exp) là hàm lồi, ta viết lại bài toán (27) về dạng lồi:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán GP ở dạng lồi:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\text{minimize}_y \quad &amp;amp;\tilde{f}_0(y) = \log\left(\sum_{k=1}^{K_0} \exp(a_{0k}^T y + b_{0k})\right) \\
\text{subject to: } &amp;amp;\tilde{f}_i(y) = \log\left(\sum_{k=1}^{K_i} \exp(a_{ik}^T y + b_{ik})\right) \leq 0, \quad i = 1, \ldots, m \quad \quad (28) \\
&amp;amp;\tilde{h}_j(y) = g_j^T y + h_j = 0, \quad j = 1, \ldots, p
\end{align}\]

&lt;p&gt;Như vậy, bài toán GP tương đương với một bài toán tối ưu hóa lồi, vì hàm mục tiêu và các hàm ràng buộc bất đẳng thức trong (28) đều là hàm lồi, còn các ràng buộc đẳng thức là hàm affine. Dạng (28) thường được gọi là &lt;strong&gt;bài toán quy hoạch hình học ở dạng lồi&lt;/strong&gt; để phân biệt với dạng gốc (26).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-02-01 Bài Toán Bình Phương Tối Thiểu Tuyến Tính</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_02_01_Least_Square/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_02_01_Least_Square</id>
   <content type="html">&lt;p&gt;Đêm giao thừa năm 1801, nhà thiên văn học Giuseppe Piazzi phát hiện tiểu hành tinh Ceres rồi mất dấu nó sau 41 ngày khi Ceres lẩn ra sau Mặt Trời. Cả giới thiên văn châu Âu bó tay vì các phép đo vị trí đều có sai số. Thế nhưng chàng trai 24 tuổi Carl Friedrich Gauss đã dự đoán chính xác vị trí Ceres tái xuất sau gần một năm nhờ một phương pháp toán học mới tinh: chọn quỹ đạo sao cho &lt;strong&gt;tổng bình phương sai số&lt;/strong&gt; nhỏ nhất — &lt;strong&gt;Bình phương tối thiểu tuyến tính (Linear Least Squares)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Hơn hai thế kỷ sau, bài toán \(\min_x \|Ax - b\|_2^2\) vẫn là nền móng không thể thay thế của khoa học dữ liệu, xử lý tín hiệu, đồ họa máy tính và kinh tế lượng. Không những là một bài toán QP không ràng buộc đặc biệt dễ chịu, nó còn sở hữu một &lt;strong&gt;công thức nghiệm đóng tuyệt đẹp&lt;/strong&gt; nối trực tiếp với hình học phép chiếu trực giao.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-góc-nhìn-về-bình-phương-tối-thiểu&quot;&gt;Kiến thức cần nhớ: Ba góc nhìn về Bình phương tối thiểu&lt;/h2&gt;

&lt;p&gt;Hiểu sâu bài toán bình phương tối thiểu nghĩa là nhìn thấy nó đồng thời qua ba lăng kính:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Góc nhìn Giải tích (Phương trình chuẩn — Normal Equations):&lt;/strong&gt; Khai triển \(f(x) = \|Ax - b\|_2^2 = x^T A^T A x - 2 b^T A x + b^T b\) và cho gradient bằng không \(\nabla f(x) = 2A^T(Ax - b) = 0\) dẫn ngay đến hệ phương trình tuyến tính \(A^T A x = A^T b\). Khi \(A\) đủ hạng cột, nghiệm duy nhất là \(x^\star = (A^T A)^{-1} A^T b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Góc nhìn Hình học (Phép chiếu trực giao):&lt;/strong&gt; Ta đang tìm vector \(\hat{b} = Ax^\star\) nằm trong không gian cột \(\mathcal{R}(A)\) gần \(b\) nhất. Vector phần dư \(r = b - Ax^\star\) phải &lt;strong&gt;vuông góc&lt;/strong&gt; với mọi cột của \(A\), tức là \(A^T(b - Ax^\star) = 0\) — chính xác là phương trình chuẩn!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Góc nhìn Đại số số (QR &amp;amp; SVD thay vì nghịch đảo trực tiếp):&lt;/strong&gt; Trong tính toán số, lập ma trận \(A^T A\) làm &lt;strong&gt;bình phương số điều kiện&lt;/strong&gt; (\(\kappa(A^T A) = \kappa(A)^2\)), dễ gây mất chính xác dấu phẩy động khi các cột gần phụ thuộc tuyến tính. Vì vậy thư viện chuyên nghiệp dùng phân rã QR (\(A = QR \implies Rx = Q^T b\)) hoặc SVD (giả nghịch đảo Moore–Penrose \(A^+ b\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-khớp-đường-thẳng-hồi-quy-bằng-tay-qua-phương-trình-chuẩn&quot;&gt;Giải thích: Khớp đường thẳng hồi quy bằng tay qua phương trình chuẩn&lt;/h3&gt;

&lt;p&gt;Cho 3 điểm dữ liệu \((t_i, y_i)\): \((0, 1),\; (1, 2),\; (2, 4)\). Ta muốn khớp đường thẳng \(y = \beta_0 + \beta_1 t\) theo nghĩa bình phương tối thiểu.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Lập ma trận thiết kế \(A\) và vector mục tiêu \(b\):&lt;/strong&gt;
\(A = \begin{pmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{pmatrix}, \qquad b = \begin{pmatrix} 1 \\ 2 \\ 4 \end{pmatrix}, \qquad x = \begin{pmatrix} \beta_0 \\ \beta_1 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tính \(A^T A\) và \(A^T b\):&lt;/strong&gt;
\(A^T A = \begin{pmatrix} 1 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 2 \end{pmatrix} \begin{pmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{pmatrix} = \begin{pmatrix} 3 &amp;amp; 3 \\ 3 &amp;amp; 5 \end{pmatrix}, \qquad A^T b = \begin{pmatrix} 1+2+4 \\ 0+2+8 \end{pmatrix} = \begin{pmatrix} 7 \\ 10 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Giải hệ \(A^T A x = A^T b\):&lt;/strong&gt;
Định thức \(\det(A^T A) = 3(5) - 3(3) = 6 \neq 0\). Nghịch đảo:
\(x^\star = \frac{1}{6} \begin{pmatrix} 5 &amp;amp; -3 \\ -3 &amp;amp; 3 \end{pmatrix} \begin{pmatrix} 7 \\ 10 \end{pmatrix} = \frac{1}{6} \begin{pmatrix} 5 \\ 9 \end{pmatrix} = \begin{pmatrix} 5/6 \\ 3/2 \end{pmatrix} \approx \begin{pmatrix} 0.833 \\ 1.500 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — Kiểm chứng tính trực giao của phần dư \(r = b - Ax^\star\):&lt;/strong&gt;
\(\hat{b} = Ax^\star = \left(\frac{5}{6},\; \frac{14}{6},\; \frac{23}{6}\right)^T \implies r = b - \hat{b} = \left(\frac{1}{6},\; -\frac{2}{6},\; \frac{1}{6}\right)^T.\)
Kiểm tra: cột 1 của \(A\) nhân \(r\): \(\frac{1}{6} - \frac{2}{6} + \frac{1}{6} = 0\); cột 2 của \(A\) nhân \(r\): \(0 - \frac{2}{6} + \frac{2}{6} = 0\)! Phần dư trực giao hoàn hảo với không gian cột, và tổng bình phương sai số tối thiểu là \(\|r\|_2^2 = \frac{1 + 4 + 1}{36} = \frac{1}{6}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-toán-bình-phương-tối-thiểu-tuyến-tính&quot;&gt;Bài Toán Bình Phương Tối Thiểu Tuyến Tính&lt;/h2&gt;

&lt;p&gt;Bài toán bình phương tối thiểu tuyến tính là một bài toán tối ưu không có ràng buộc, trong đó chúng ta tối thiểu hóa tổng các sai số bình phương:&lt;/p&gt;

\[\text{minimize}_{x} \quad f_0(x) = \|Ax - b\|_2^2 = \sum_{i=1}^{k} (a_i^T x - b_i)^2\]

&lt;p&gt;&lt;strong&gt;trong đó:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(A \in \mathbb{R}^{k \times n}\) là một ma trận với \(k \geq n\)&lt;/li&gt;
  &lt;li&gt;\(a_i^T\) là các hàng của \(A\)&lt;/li&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) là biến chúng ta muốn tìm&lt;/li&gt;
  &lt;li&gt;\(b \in \mathbb{R}^k\) là vector mục tiêu&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu:&lt;/strong&gt; Tìm \(x\) để tối thiểu hóa tổng các phần dư bình phương.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-hồi-quy-tuyến-tính-với-hàm-một-biến&quot;&gt;Ví dụ: Hồi quy Tuyến tính với hàm một biến&lt;/h3&gt;

&lt;p&gt;Tìm đường thẳng phù hợp nhất \(y = mx + c\) xấp xỉ tập điểm dữ liệu. Chúng ta cực tiểu hóa tổng bình phương khoảng cách theo phương thẳng đứng từ các điểm dữ liệu đến đường thẳng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu:&lt;/strong&gt; Tìm \(m, c\).&lt;/p&gt;

&lt;div id=&quot;linear-regression-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Minh họa Hồi quy Tuyến tính Tương tác&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;!-- Canvas for visualization --&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;regressionCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white; cursor: crosshair;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Hướng dẫn:&lt;/strong&gt; Nhấp vào canvas để thêm các điểm dữ liệu. Đường thẳng đỏ hiển thị đường khớp nhất.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;!-- Controls and information --&gt;
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Tham số Hồi quy&lt;/h5&gt;
                &lt;div id=&quot;regression-params&quot; style=&quot;font-family: monospace; font-size: 14px; line-height: 1.6;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Hệ số góc (m):&lt;/strong&gt; &lt;span id=&quot;slope-value&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;&lt;strong&gt;Tung độ gốc (c):&lt;/strong&gt; &lt;span id=&quot;intercept-value&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;&lt;strong&gt;Điểm R²:&lt;/strong&gt; &lt;span id=&quot;r2-value&quot;&gt;N/A&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;&lt;strong&gt;MSE:&lt;/strong&gt; &lt;span id=&quot;mse-value&quot;&gt;N/A&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-top: 15px;&quot;&gt;
                    &lt;h5 style=&quot;color: #444;&quot;&gt;Phương trình&lt;/h5&gt;
                    &lt;div id=&quot;equation&quot; style=&quot;font-family: monospace; font-size: 16px; background: #f0f0f0; padding: 8px; border-radius: 4px;&quot;&gt;
                        y = 0.000x + 0.000
                    &lt;/div&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-top: 15px;&quot;&gt;
                    &lt;button onclick=&quot;clearPoints()&quot; style=&quot;background: #ff6b6b; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; margin-right: 10px;&quot;&gt;Xóa Điểm&lt;/button&gt;
                    &lt;button onclick=&quot;addRandomPoints()&quot; style=&quot;background: #4ecdc4; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Thêm Điểm Ngẫu nhiên&lt;/button&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-top: 15px;&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Công thức Toán học&lt;/h5&gt;
                &lt;div style=&quot;font-size: 13px; line-height: 1.5;&quot;&gt;
                    &lt;p&gt;&lt;strong&gt;Mục tiêu:&lt;/strong&gt; Tối thiểu hóa tổng các phần dư bình phương&lt;/p&gt;
                    &lt;div style=&quot;background: #f8f8f8; padding: 8px; border-radius: 4px; font-family: monospace;&quot;&gt;
                        S(m,c) = Σ(yᵢ - mxᵢ - c)²
                    &lt;/div&gt;
                    &lt;p style=&quot;margin-top: 10px;&quot;&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt;&lt;/p&gt;
                    &lt;div style=&quot;background: #f8f8f8; padding: 8px; border-radius: 4px; font-family: monospace; font-size: 11px;&quot;&gt;
                        m = Σ(xᵢ-x̄)(yᵢ-ȳ) / Σ(xᵢ-x̄)²&lt;br /&gt;
                        c = ȳ - mx̄
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
// Linear Regression Interactive Demo
class LinearRegressionDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;regressionCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.points = [];
        this.slope = 0;
        this.intercept = 0;
        
        // Set up canvas
        this.canvas.addEventListener(&apos;click&apos;, (e) =&gt; this.addPoint(e));
        
        // Initialize with some sample points
        this.addRandomPoints();
        this.draw();
    }
    
    addPoint(event) {
        const rect = this.canvas.getBoundingClientRect();
        const x = event.clientX - rect.left;
        const y = event.clientY - rect.top;
        
        // Convert canvas coordinates to data coordinates
        const dataX = (x / this.canvas.width) * 10;
        const dataY = ((this.canvas.height - y) / this.canvas.height) * 10;
        
        this.points.push({x: dataX, y: dataY});
        this.calculateRegression();
        this.draw();
        this.updateDisplay();
    }
    
    addRandomPoints() {
        // Add some sample points with a trend
        const baseSlope = 0.8;
        const baseIntercept = 2;
        
        for (let i = 0; i &lt; 8; i++) {
            const x = Math.random() * 8 + 1;
            const y = baseSlope * x + baseIntercept + (Math.random() - 0.5) * 2;
            this.points.push({x: x, y: Math.max(0, Math.min(10, y))});
        }
        
        this.calculateRegression();
        this.draw();
        this.updateDisplay();
    }
    
    clearPoints() {
        this.points = [];
        this.slope = 0;
        this.intercept = 0;
        this.draw();
        this.updateDisplay();
    }
    
    calculateRegression() {
        if (this.points.length &lt; 2) {
            this.slope = 0;
            this.intercept = 0;
            return;
        }
        
        const n = this.points.length;
        const sumX = this.points.reduce((sum, p) =&gt; sum + p.x, 0);
        const sumY = this.points.reduce((sum, p) =&gt; sum + p.y, 0);
        const sumXY = this.points.reduce((sum, p) =&gt; sum + p.x * p.y, 0);
        const sumXX = this.points.reduce((sum, p) =&gt; sum + p.x * p.x, 0);
        
        const meanX = sumX / n;
        const meanY = sumY / n;
        
        const numerator = sumXY - n * meanX * meanY;
        const denominator = sumXX - n * meanX * meanX;
        
        if (Math.abs(denominator) &lt; 1e-10) {
            this.slope = 0;
            this.intercept = meanY;
        } else {
            this.slope = numerator / denominator;
            this.intercept = meanY - this.slope * meanX;
        }
    }
    
    calculateR2() {
        if (this.points.length &lt; 2) return 0;
        
        const meanY = this.points.reduce((sum, p) =&gt; sum + p.y, 0) / this.points.length;
        let ssRes = 0;
        let ssTot = 0;
        
        for (const point of this.points) {
            const predicted = this.slope * point.x + this.intercept;
            ssRes += Math.pow(point.y - predicted, 2);
            ssTot += Math.pow(point.y - meanY, 2);
        }
        
        return ssTot === 0 ? 1 : 1 - (ssRes / ssTot);
    }
    
    calculateMSE() {
        if (this.points.length === 0) return 0;
        
        let mse = 0;
        for (const point of this.points) {
            const predicted = this.slope * point.x + this.intercept;
            mse += Math.pow(point.y - predicted, 2);
        }
        
        return mse / this.points.length;
    }
    
    draw() {
        // Clear canvas
        this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
        
        // Draw grid
        this.drawGrid();
        
        // Draw regression line
        if (this.points.length &gt;= 2) {
            this.drawRegressionLine();
        }
        
        // Draw points and residuals
        this.drawPoints();
        
        // Draw axes labels
        this.drawLabels();
    }
    
    drawGrid() {
        this.ctx.strokeStyle = &apos;#f0f0f0&apos;;
        this.ctx.lineWidth = 1;
        
        // Vertical lines
        for (let i = 0; i &lt;= 10; i++) {
            const x = (i / 10) * this.canvas.width;
            this.ctx.beginPath();
            this.ctx.moveTo(x, 0);
            this.ctx.lineTo(x, this.canvas.height);
            this.ctx.stroke();
        }
        
        // Horizontal lines
        for (let i = 0; i &lt;= 10; i++) {
            const y = (i / 10) * this.canvas.height;
            this.ctx.beginPath();
            this.ctx.moveTo(0, y);
            this.ctx.lineTo(this.canvas.width, y);
            this.ctx.stroke();
        }
    }
    
    drawRegressionLine() {
        this.ctx.strokeStyle = &apos;#ff4757&apos;;
        this.ctx.lineWidth = 2;
        
        const x1 = 0;
        const y1 = this.intercept;
        const x2 = 10;
        const y2 = this.slope * x2 + this.intercept;
        
        const canvasX1 = (x1 / 10) * this.canvas.width;
        const canvasY1 = this.canvas.height - (y1 / 10) * this.canvas.height;
        const canvasX2 = (x2 / 10) * this.canvas.width;
        const canvasY2 = this.canvas.height - (y2 / 10) * this.canvas.height;
        
        this.ctx.beginPath();
        this.ctx.moveTo(canvasX1, canvasY1);
        this.ctx.lineTo(canvasX2, canvasY2);
        this.ctx.stroke();
    }
    
    drawPoints() {
        for (const point of this.points) {
            const canvasX = (point.x / 10) * this.canvas.width;
            const canvasY = this.canvas.height - (point.y / 10) * this.canvas.height;
            
            // Draw residual line (vertical distance to regression line)
            if (this.points.length &gt;= 2) {
                const predictedY = this.slope * point.x + this.intercept;
                const predictedCanvasY = this.canvas.height - (predictedY / 10) * this.canvas.height;
                
                this.ctx.strokeStyle = &apos;#ff6b6b&apos;;
                this.ctx.lineWidth = 1;
                this.ctx.setLineDash([2, 2]);
                this.ctx.beginPath();
                this.ctx.moveTo(canvasX, canvasY);
                this.ctx.lineTo(canvasX, predictedCanvasY);
                this.ctx.stroke();
                this.ctx.setLineDash([]);
            }
            
            // Draw point
            this.ctx.fillStyle = &apos;#2f3542&apos;;
            this.ctx.beginPath();
            this.ctx.arc(canvasX, canvasY, 4, 0, 2 * Math.PI);
            this.ctx.fill();
        }
    }
    
    drawLabels() {
        this.ctx.fillStyle = &apos;#666&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        
        // X-axis labels
        for (let i = 0; i &lt;= 10; i += 2) {
            const x = (i / 10) * this.canvas.width;
            this.ctx.fillText(i.toString(), x - 5, this.canvas.height - 5);
        }
        
        // Y-axis labels
        for (let i = 0; i &lt;= 10; i += 2) {
            const y = this.canvas.height - (i / 10) * this.canvas.height;
            this.ctx.fillText(i.toString(), 5, y + 3);
        }
    }
    
    updateDisplay() {
        document.getElementById(&apos;slope-value&apos;).textContent = this.slope.toFixed(3);
        document.getElementById(&apos;intercept-value&apos;).textContent = this.intercept.toFixed(3);
        document.getElementById(&apos;equation&apos;).textContent = `y = ${this.slope.toFixed(3)}x + ${this.intercept.toFixed(3)}`;
        
        if (this.points.length &gt;= 2) {
            document.getElementById(&apos;r2-value&apos;).textContent = this.calculateR2().toFixed(3);
            document.getElementById(&apos;mse-value&apos;).textContent = this.calculateMSE().toFixed(3);
        } else {
            document.getElementById(&apos;r2-value&apos;).textContent = &apos;N/A&apos;;
            document.getElementById(&apos;mse-value&apos;).textContent = &apos;N/A&apos;;
        }
    }
}

// Global functions for buttons
function clearPoints() {
    if (window.regressionDemo) {
        window.regressionDemo.clearPoints();
    }
}

function addRandomPoints() {
    if (window.regressionDemo) {
        window.regressionDemo.clearPoints();
        window.regressionDemo.addRandomPoints();
    }
}

// Initialize when DOM is loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    if (document.getElementById(&apos;regressionCanvas&apos;)) {
        window.regressionDemo = new LinearRegressionDemo();
    }
});

// Initialize immediately if DOM is already loaded
if (document.readyState === &apos;loading&apos;) {
    document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
        if (document.getElementById(&apos;regressionCanvas&apos;)) {
            window.regressionDemo = new LinearRegressionDemo();
        }
    });
} else {
    if (document.getElementById(&apos;regressionCanvas&apos;)) {
        window.regressionDemo = new LinearRegressionDemo();
    }
}
&lt;/script&gt;

&lt;p&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; Cho \(n\) điểm dữ liệu \((x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n)\), tìm đường thẳng \(y = mx + c\) cực tiểu hóa tổng bình phương khoảng cách theo phương thẳng đứng từ các điểm dữ liệu đến đường thẳng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm Mục tiêu:&lt;/strong&gt; Chúng ta muốn tối thiểu hóa
\(S(m,c) = \sum_{i=1}^{n} (y_i - mx_i - c)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nghiệm:&lt;/strong&gt; Để tìm cực tiểu, ta tính các đạo hàm riêng và cho bằng 0.&lt;/p&gt;

&lt;p&gt;Lấy đạo hàm riêng theo \(c\):&lt;/p&gt;
&lt;blockquote&gt;
\[\frac{\partial S}{\partial c} = \sum_{i=1}^{n} 2(y_i - mx_i - c)(-1) = -2\sum_{i=1}^{n} (y_i - mx_i - c) = 0\]
&lt;/blockquote&gt;

&lt;p&gt;Điều này cho ta:
\(\sum_{i=1}^{n} y_i = m\sum_{i=1}^{n} x_i + nc\)&lt;/p&gt;

&lt;p&gt;Do đó:&lt;/p&gt;

&lt;blockquote&gt;
\[c = \frac{1}{n}\sum_{i=1}^{n} y_i - m\frac{1}{n}\sum_{i=1}^{n} x_i = \bar{y} - m\bar{x}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\bar{x}\) và \(\bar{y}\) là giá trị trung bình của các giá trị \(x\) và \(y\).&lt;/p&gt;

&lt;p&gt;Lấy đạo hàm riêng theo \(m\):&lt;/p&gt;

&lt;blockquote&gt;
\[\frac{\partial S}{\partial m} = \sum_{i=1}^{n} 2(y_i - mx_i - c)(-x_i) = -2\sum_{i=1}^{n} x_i(y_i - mx_i - c) = 0\]
&lt;/blockquote&gt;

&lt;p&gt;Thay thế \(c = \bar{y} - m\bar{x}\):
\(\sum_{i=1}^{n} x_i(y_i - mx_i - \bar{y} + m\bar{x}) = 0\)&lt;/p&gt;

&lt;p&gt;Sắp xếp lại:
\(\sum_{i=1}^{n} x_iy_i - m\sum_{i=1}^{n} x_i^2 - \bar{y}\sum_{i=1}^{n} x_i + m\bar{x}\sum_{i=1}^{n} x_i = 0\)&lt;/p&gt;

&lt;p&gt;Vì \(\sum_{i=1}^{n} x_i = n\bar{x}\) và \(\sum_{i=1}^{n} x_iy_i - \bar{y}\sum_{i=1}^{n} x_i = \sum_{i=1}^{n} x_i(y_i - \bar{y})\):&lt;/p&gt;

&lt;blockquote&gt;
\[\sum_{i=1}^{n} x_i(y_i - \bar{y}) = m\left(\sum_{i=1}^{n} x_i^2 - n\bar{x}^2\right)\]
&lt;/blockquote&gt;

&lt;p&gt;Lưu ý rằng \(\sum_{i=1}^{n} x_i^2 - n\bar{x}^2 = \sum_{i=1}^{n} (x_i - \bar{x})^2\)&lt;/p&gt;

&lt;p&gt;Do đó:&lt;/p&gt;

&lt;blockquote&gt;
\[m = \frac{\sum_{i=1}^{n} x_i(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2} = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Kết quả Cuối cùng:&lt;/strong&gt; Đường thẳng hồi quy tối ưu có các tham số:&lt;/p&gt;

&lt;blockquote&gt;
\[\boxed{m = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2} \quad \text{và} \quad c = \bar{y} - m\bar{x}}\]
&lt;/blockquote&gt;

&lt;p&gt;Đây là nghiệm bình phương tối thiểu kinh điển cho hồi quy tuyến tính, cũng được biết đến với tên gọi &lt;strong&gt;Phương trình Chuẩn&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;nghiệm-tối-ưu-của-hồi-quy-tuyến-tính-với-hàm-nhiều-biến&quot;&gt;Nghiệm Tối ưu của Hồi quy Tuyến tính với hàm nhiều biến&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Phát biểu Bài toán:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Trong Hồi quy Tuyến tính, chúng ta muốn tìm một vector các hệ số \(\mathbf{w}\) khớp nhất cho mô hình tuyến tính trên tập dữ liệu đã cho. Chúng ta có \(n\) điểm dữ liệu, mỗi điểm có \(p\) đặc trưng.&lt;/p&gt;

&lt;p&gt;Gọi \(X\) là ma trận thiết kế kích thước \(n \times p\), trong đó mỗi hàng đại diện cho một điểm dữ liệu và mỗi cột đại diện cho một đặc trưng.&lt;/p&gt;

&lt;p&gt;Gọi \(\mathbf{y}\) là vector các giá trị mục tiêu kích thước \(n \times 1\).&lt;/p&gt;

&lt;p&gt;Mô hình tuyến tính của chúng ta dự đoán các giá trị mục tiêu \(\hat{\mathbf{y}}\) như:
\(\hat{\mathbf{y}} = X\mathbf{w}\)
trong đó \(\mathbf{w}\) là vector các hệ số chưa biết kích thước \(p \times 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm Mục tiêu (Hàm Chi phí):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mục tiêu là tối thiểu hóa tổng các sai số bình phương (phần dư) giữa các giá trị mục tiêu thực tế \(\mathbf{y}\) và các giá trị dự đoán \(\hat{\mathbf{y}}\). Điều này được biết đến với tên gọi hàm mục tiêu Bình phương Tối thiểu Thông thường (OLS):
\(J(\mathbf{w}) = \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 = \| \mathbf{y} - X\mathbf{w} \|^2\)&lt;/p&gt;

&lt;p&gt;Chúng ta có thể biểu diễn điều này dưới dạng ma trận bằng cách khai triển bình phương chuẩn Euclid:
\(J(\mathbf{w}) = (\mathbf{y} - X\mathbf{w})^{\text{T}}(\mathbf{y} - X\mathbf{w})\)&lt;/p&gt;

&lt;p&gt;Khai triển biểu thức này:
\(J(\mathbf{w}) = \mathbf{y}^{\text{T}}\mathbf{y} - \mathbf{y}^{\text{T}}X\mathbf{w} - (X\mathbf{w})^{\text{T}}\mathbf{y} + (X\mathbf{w})^{\text{T}}X\mathbf{w}\)&lt;/p&gt;

&lt;p&gt;Sử dụng tính chất \((AB)^{\text{T}} = B^{\text{T}}A^{\text{T}}\), chúng ta có \((X\mathbf{w})^{\text{T}} = \mathbf{w}^{\text{T}}X^{\text{T}}\).&lt;/p&gt;

&lt;p&gt;Ngoài ra, vì \(\mathbf{y}^{\text{T}}X\mathbf{w}\) là một số vô hướng, chuyển vị của nó bằng chính nó: \((\mathbf{y}^{\text{T}}X\mathbf{w})^{\text{T}} = \mathbf{w}^{\text{T}}X^{\text{T}}\mathbf{y}\).&lt;/p&gt;

&lt;p&gt;Do đó, hai số hạng ở giữa là giống nhau:
\(J(\mathbf{w}) = \mathbf{y}^{\text{T}}\mathbf{y} - 2\mathbf{w}^{\text{T}}X^{\text{T}}\mathbf{y} + \mathbf{w}^{\text{T}}X^{\text{T}}X\mathbf{w}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tối thiểu hóa sử dụng Giải tích:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Để tìm \(\mathbf{w}\) tối ưu tối thiểu hóa \(J(\mathbf{w})\), ta lấy đạo hàm của \(J(\mathbf{w})\) theo \(\mathbf{w}\) và cho bằng 0. Chúng ta sử dụng các quy tắc giải tích ma trận sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
\[\frac{\partial (\mathbf{a}^{\text{T}}\mathbf{x})}{\partial \mathbf{x}} = \mathbf{a}\]
  &lt;/li&gt;
  &lt;li&gt;\(\frac{\partial (\mathbf{x}^{\text{T}}A\mathbf{x})}{\partial \mathbf{x}} = (A + A^{\text{T}})\mathbf{x}\) (Nếu \(A\) đối xứng, điều này được rút gọn thành \(2A\mathbf{x}\))&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Áp dụng các quy tắc này cho \(J(\mathbf{w})\):
\(\frac{\partial J(\mathbf{w})}{\partial \mathbf{w}} = \frac{\partial (\mathbf{y}^{\text{T}}\mathbf{y})}{\partial \mathbf{w}} - \frac{\partial (2\mathbf{w}^{\text{T}}X^{\text{T}}\mathbf{y})}{\partial \mathbf{w}} + \frac{\partial (\mathbf{w}^{\text{T}}X^{\text{T}}X\mathbf{w})}{\partial \mathbf{w}}\)&lt;/p&gt;

&lt;p&gt;Hãy tính từng số hạng:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\frac{\partial (\mathbf{y}^{\text{T}}\mathbf{y})}{\partial \mathbf{w}} = 0\) (vì \(\mathbf{y}^{\text{T}}\mathbf{y}\) là một hằng số vô hướng đối với \(\mathbf{w}\))&lt;/li&gt;
  &lt;li&gt;\(\frac{\partial (2\mathbf{w}^{\text{T}}X^{\text{T}}\mathbf{y})}{\partial \mathbf{w}} = 2X^{\text{T}}\mathbf{y}\) (sử dụng quy tắc 1, với \(\mathbf{a} = X^{\text{T}}\mathbf{y}\))&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Đối với số hạng thứ ba, đặt \(A = X^{\text{T}}X\). Lưu ý rằng \(A\) là ma trận đối xứng vì \((X^{\text{T}}X)^{\text{T}} = X^{\text{T}}(X^{\text{T}})^{\text{T}} = X^{\text{T}}X\).&lt;/p&gt;

    &lt;p&gt;Vậy, \(\frac{\partial (\mathbf{w}^{\text{T}}X^{\text{T}}X\mathbf{w})}{\partial \mathbf{w}} = 2X^{\text{T}}X\mathbf{w}\) (sử dụng quy tắc 2 cho ma trận đối xứng \(A\))&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Kết hợp các thành phần này, đạo hàm là:&lt;/p&gt;

&lt;blockquote&gt;
\[\frac{\partial J(\mathbf{w})}{\partial \mathbf{w}} = 0 - 2X^{\text{T}}\mathbf{y} + 2X^{\text{T}}X\mathbf{w} = 2X^{\text{T}}X\mathbf{w} - 2X^{\text{T}}\mathbf{y}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Tìm Nghiệm Tối ưu:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Để tìm cực tiểu của \(J(\mathbf{w})\), ta giải phương trình đạo hàm bằng 0:&lt;/p&gt;

\[\frac{\partial J(\mathbf{w})}{\partial \mathbf{w}} = 2X^{\text{T}}X\mathbf{w} - 2X^{\text{T}}\mathbf{y} = 0\]

&lt;p&gt;Chia cho 2 và sắp xếp lại:
\(X^{\text{T}}X\mathbf{w} = X^{\text{T}}\mathbf{y}\)&lt;/p&gt;

&lt;p&gt;Đây được gọi là &lt;strong&gt;Phương trình Chuẩn&lt;/strong&gt;. Nếu \(X^{\text{T}}X\) khả nghịch (điều này xảy ra khi \(X\) có hạng cột đầy đủ), chúng ta có thể giải để tìm \(\mathbf{w}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\boxed{\mathbf{w}^* = (X^{\text{T}}X)^{-1}X^{\text{T}}\mathbf{y}}\]
&lt;/blockquote&gt;

&lt;p&gt;Đây là &lt;strong&gt;nghiệm dạng đóng&lt;/strong&gt; cho hồi quy bình phương tối thiểu tuyến tính, còn được gọi là &lt;strong&gt;nghiệm Phương trình Chuẩn&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất Quan trọng:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính duy nhất:&lt;/strong&gt; Nếu \(X^{\text{T}}X\) khả nghịch, nghiệm là duy nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa Hình học:&lt;/strong&gt; Nghiệm \(\mathbf{w}^*\) làm cho vector phần dư \(\mathbf{y} - X\mathbf{w}^*\) vuông góc với không gian cột của \(X\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ phức tạp Tính toán:&lt;/strong&gt; \(O(p^3 + np^2)\) trong đó \(n\) là số mẫu và \(p\) là số đặc trưng.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Khi \(X^{\text{T}}X\) không khả nghịch:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Điều này xảy ra khi \(X\) không có hạng cột đầy đủ (tức là một số đặc trưng phụ thuộc tuyến tính)&lt;/li&gt;
  &lt;li&gt;Trong trường hợp này, chúng ta có thể sử dụng &lt;strong&gt;nghịch đảo giả Moore-Penrose&lt;/strong&gt;: \(\mathbf{w}^* = X^{\dagger}\mathbf{y}\)&lt;/li&gt;
  &lt;li&gt;Hoặc thêm thành phần chính quy hóa (hồi quy Ridge): \(\mathbf{w}^* = (X^{\text{T}}X + \lambda I)^{-1}X^{\text{T}}\mathbf{y}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hiệu năng tính toán:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Độ phức tạp thời gian: khoảng \(n^2k\) phép toán&lt;/li&gt;
  &lt;li&gt;Một máy tính tiêu chuẩn giải quyết các bài toán với hàng trăm biến và hàng nghìn số hạng trong vài giây&lt;/li&gt;
  &lt;li&gt;Ma trận thưa (nhiều phần tử bằng không) có thể được giải nhanh hơn nhiều&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; Một ma trận thưa để xử lý ảnh có thể chỉ có 5 phần tử khác không trên mỗi hàng trong ma trận 10,000 × 10,000.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-01 Quy Hoạch Tuyến Tính (LP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_01_Linear_Programming_(LP)/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_01_Linear_Programming_(LP)</id>
   <content type="html">&lt;p&gt;Năm 1947, Không quân Hoa Kỳ đối mặt với một bài toán hậu cần khổng lồ: làm sao phân bổ hàng chục nghìn chuyến bay, kho nhiên liệu, phi hành đoàn và linh kiện sao cho chi phí thấp nhất mà vẫn đáp ứng mọi mục tiêu tác chiến? Nhà toán học trẻ George Dantzig nhận ra mọi ràng buộc tồn kho, ngân sách và vận tải đều là &lt;strong&gt;bất đẳng thức tuyến tính&lt;/strong&gt;, còn mục tiêu là một hàm tuyến tính. Ông đặt tên cho khuôn khổ này là &lt;strong&gt;Quy hoạch Tuyến tính (Linear Programming - LP)&lt;/strong&gt; — mở ra một trong những công cụ tạo ra giá trị kinh tế lớn nhất lịch sử nhân loại.&lt;/p&gt;

&lt;p&gt;Điều kỳ diệu nhất của LP nằm ở hình học của nó: tập khả thi là một khối đa diện nhiều mặt phẳng, và đường đồng mức của hàm mục tiêu là các siêu phẳng song song trượt dần theo hướng \(-c\). Chắc chắn điểm chạm cuối cùng trước khi siêu phẳng rời khỏi khối đa diện sẽ luôn có thể tìm thấy tại một &lt;strong&gt;đỉnh (vertex)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-quy-hoạch-tuyến-tính-lp&quot;&gt;Kiến thức cần nhớ: Giải phẫu Quy hoạch Tuyến tính (LP)&lt;/h2&gt;

&lt;p&gt;Bốn trụ cột sau bao quát toàn bộ lý thuyết và cách viết chuẩn của một bài toán LP:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hình học Đa diện (Polyhedral Geometry):&lt;/strong&gt; Giao của hữu hạn nửa không gian \(a_i^T x \le b_i\) là một đa diện (polyhedron); nếu bị chặn, nó gọi là đa giác/đa diện lồi đóng (polytope). Đường đồng mức \(c^T x = \text{const}\) luôn song song, nên tối ưu hóa tuyến tính thực chất là “đẩy một mặt phẳng đi xa nhất có thể theo hướng \(-c\) cho đến khi chỉ còn chạm vào biên đa diện”.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các dạng chuẩn (Standard Form vs. Inequality Form):&lt;/strong&gt; Để máy tính giải đồng nhất, mọi bài toán LP tổng quát (có biến tự do, dấu \(\ge\), dấu \(=\)) đều chuyển được về dạng chuẩn \(\min c^T x \text{ s.t. } Ax = b,\; x \ge 0\) bằng cách tách biến tự do \(x = x^+ - x^-\) (\(x^+, x^- \ge 0\)) và thêm biến phụ \(s \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ba kịch bản nghiệm duy nhất có thể xảy ra:&lt;/strong&gt; Một bài LP bất kỳ chỉ có thể rơi vào đúng 1 trong 3 trạng thái: (1) &lt;strong&gt;vô nghiệm&lt;/strong&gt; (tập khả thi rỗng), (2) &lt;strong&gt;không bị chặn&lt;/strong&gt; (\(f^\star = -\infty\)), hoặc (3) &lt;strong&gt;có nghiệm tối ưu hữu hạn&lt;/strong&gt; (tại một đỉnh hoặc cả một mặt phẳng nối nhiều đỉnh tối ưu).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng rộng khắp:&lt;/strong&gt; Từ bài toán khẩu phần ăn (Diet Problem), vận tải (Transportation), luồng cực đại trên mạng (Max-Flow), cho đến hồi quy chuẩn \(\ell_1\) (LAD) và hồi quy Chebyshev (\(\ell_\infty\)) đều quy về LP chính xác!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-bài-toán-lp-2-biến-bằng-phương-pháp-duyệt-đỉnh--chuyển-dạng-chuẩn&quot;&gt;Giải thích: Giải tay bài toán LP 2 biến bằng phương pháp duyệt đỉnh &amp;amp; chuyển dạng chuẩn&lt;/h3&gt;

&lt;p&gt;Xét bài toán lập lịch sản xuất:
\(\min_{x_1, x_2} \; -3x_1 - 2x_2 \quad \text{thỏa mãn} \quad \begin{cases} x_1 + x_2 \le 4 \\ 2x_1 + x_2 \le 6 \\ x_1 \ge 0,\; x_2 \ge 0 \end{cases}\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tìm tất cả các đỉnh (giao điểm khả thi của các đường biên):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đỉnh \(A = (0, 0)\): thỏa mọi ràng buộc, \(f(A) = 0\).&lt;/li&gt;
      &lt;li&gt;Đỉnh \(B = (3, 0)\) (giao \(2x_1 + x_2 = 6\) và \(x_2 = 0\)): kiểm tra \(3+0 = 3 \le 4\) (khả thi), \(f(B) = -9\).&lt;/li&gt;
      &lt;li&gt;Đỉnh \(C = (0, 4)\) (giao \(x_1 + x_2 = 4\) và \(x_1 = 0\)): kiểm tra \(0+4 = 4 \le 6\) (khả thi), \(f(C) = -8\).&lt;/li&gt;
      &lt;li&gt;Đỉnh \(D\) (giao \(x_1 + x_2 = 4\) và \(2x_1 + x_2 = 6\)): trừ hai phương trình cho \(x_1 = 2 \implies x_2 = 2\). Khả thi! \(f(D) = -3(2) - 2(2) = -10\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — So sánh giá trị hàm mục tiêu tại các đỉnh:&lt;/strong&gt;
\(\min\{0,\; -9,\; -8,\; -10\} = -10 \quad \text{tại } x^\star = (2, 2).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Viết sang dạng chuẩn \(\min c^T \tilde{x} \text{ s.t. } A\tilde{x} = b,\; \tilde{x} \ge 0\):&lt;/strong&gt;
Thêm hai biến phụ \(s_1, s_2 \ge 0\):
\(\begin{pmatrix} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 0 \\ 2 &amp;amp; 1 &amp;amp; 0 &amp;amp; 1 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ s_1 \\ s_2 \end{pmatrix} = \begin{pmatrix} 4 \\ 6 \end{pmatrix}, \qquad c = (-3, -2, 0, 0)^T.\)
Tại nghiệm tối ưu \(x_1=2, x_2=2\), ta có \(s_1 = 0, s_2 = 0\) — cả hai ràng buộc đều tích cực!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?features=es6&quot;&gt;&lt;/script&gt;

&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;Quy hoạch tuyến tính (Linear Programming - LP) là một trong những kỹ thuật tối ưu hóa nền tảng và được ứng dụng rộng rãi nhất trong toán học, kinh tế học và kỹ thuật. Ví dụ điển hình là bài toán của một nhà quản lý sản xuất cần tối đa hóa lợi nhuận trong phạm vi nguồn lực hữu hạn — đây chính là dạng bài toán mà LP được xây dựng để giải quyết.&lt;/p&gt;

&lt;h3 id=&quot;khi-nào-một-bài-toán-là-tuyến-tính&quot;&gt;Khi nào một bài toán là “tuyến tính”?&lt;/h3&gt;

&lt;p&gt;Một bài toán tối ưu được gọi là tuyến tính khi:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mục tiêu&lt;/strong&gt; là một hàm tuyến tính (hoặc affine) theo các biến quyết định.&lt;/li&gt;
  &lt;li&gt;Tất cả các &lt;strong&gt;ràng buộc&lt;/strong&gt; đều là đẳng thức hoặc bất đẳng thức tuyến tính (affine).&lt;/li&gt;
  &lt;li&gt;Không có tích giữa các biến với nhau (chẳng hạn \(x_1 \cdot x_2\)).&lt;/li&gt;
  &lt;li&gt;Không có biến nào xuất hiện dưới dạng lũy thừa bậc khác 1, hàm mũ hay căn bậc hai.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-mở-đầu-bài-toán-của-nông-dân&quot;&gt;Ví dụ mở đầu: Bài toán của nông dân&lt;/h3&gt;

&lt;p&gt;Xét một ví dụ trực quan: một nông dân có 100 mẫu đất và muốn trồng ngô và lúa mì để tối đa hóa lợi nhuận:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ngô:&lt;/strong&gt; Lợi nhuận $300 mỗi mẫu, cần 2 giờ lao động mỗi mẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lúa mì:&lt;/strong&gt; Lợi nhuận $200 mỗi mẫu, cần 1 giờ lao động mỗi mẫu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quỹ lao động sẵn có:&lt;/strong&gt; Tổng cộng 150 giờ.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi:&lt;/strong&gt; Nông dân nên trồng bao nhiêu mẫu ngô và bao nhiêu mẫu lúa mì để đạt lợi nhuận lớn nhất?&lt;/p&gt;

&lt;div id=&quot;farmer-problem-viz&quot; style=&quot;margin: 20px 0;&quot;&gt;&lt;/div&gt;

&lt;div class=&quot;content-box exercise-box&quot;&gt;
&lt;strong&gt;Bài tập tương tác:&lt;/strong&gt; Sử dụng các thanh trượt bên dưới để thử các phương án phân bổ diện tích trồng ngô và lúa mì khác nhau. Quan sát cách lợi nhuận thay đổi và kiểm tra xem các ràng buộc có được thỏa mãn hay không.

&lt;div style=&quot;margin: 10px 0;&quot;&gt;
  &lt;label for=&quot;corn-acres&quot;&gt;Số mẫu ngô: &lt;span id=&quot;corn-value&quot;&gt;50&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
  &lt;input type=&quot;range&quot; id=&quot;corn-acres&quot; min=&quot;0&quot; max=&quot;100&quot; value=&quot;50&quot; style=&quot;width: 300px;&quot; /&gt;
&lt;/div&gt;

&lt;div style=&quot;margin: 10px 0;&quot;&gt;
  &lt;label for=&quot;wheat-acres&quot;&gt;Số mẫu lúa mì: &lt;span id=&quot;wheat-value&quot;&gt;50&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
  &lt;input type=&quot;range&quot; id=&quot;wheat-acres&quot; min=&quot;0&quot; max=&quot;100&quot; value=&quot;50&quot; style=&quot;width: 300px;&quot; /&gt;
&lt;/div&gt;

&lt;div id=&quot;farmer-results&quot; style=&quot;margin-top: 15px; font-family: monospace;&quot;&gt;
  &lt;div&gt;Tổng diện tích sử dụng: &lt;span id=&quot;land-used&quot;&gt;100&lt;/span&gt; / 100 mẫu&lt;/div&gt;
  &lt;div&gt;Tổng lao động sử dụng: &lt;span id=&quot;labor-used&quot;&gt;150&lt;/span&gt; / 150 giờ&lt;/div&gt;
  &lt;div&gt;Tổng lợi nhuận: $&lt;span id=&quot;total-profit&quot;&gt;25000&lt;/span&gt;&lt;/div&gt;
  &lt;div id=&quot;feasibility-status&quot; style=&quot;font-weight: bold; color: green;&quot;&gt;✓ Nghiệm khả thi&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Bây giờ hãy phát biểu chặt chẽ hơn. Nếu cả hàm mục tiêu lẫn các hàm ràng buộc đều là hàm affine, bài toán tối ưu được gọi là &lt;strong&gt;bài toán quy hoạch tuyến tính&lt;/strong&gt; (LP). Dạng tổng quát của bài toán quy hoạch tuyến tính như sau:&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-lp-tổng-quát&quot;&gt;Bài toán LP tổng quát&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Gx \preceq h}\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp;\text{where } &amp;amp;&amp;amp;G \in \mathbb{R}^{m \times n} \text{ và } A \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Hằng số \(+d\) trong hàm mục tiêu không làm thay đổi nghiệm tối ưu và có thể bỏ qua khi giải.&lt;/li&gt;
  &lt;li&gt;Bài toán cực đại hóa \(c^T x + d\) trên cùng tập ràng buộc tương đương với bài toán cực tiểu hóa \(-c^T x - d\).&lt;/li&gt;
  &lt;li&gt;Về mặt hình học, bài toán tìm điểm tối ưu \(x^*\) của hàm affine \(c^T x + d\) trên một tập khả thi đa diện.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-hình-học&quot;&gt;Giải thích hình học&lt;/h3&gt;

&lt;p&gt;Ý nghĩa của quy hoạch tuyến tính thể hiện rõ qua biểu diễn hình học: mỗi ràng buộc bất đẳng thức tuyến tính xác định một nửa không gian, và tập khả thi là giao của tất cả các nửa không gian đó, tạo thành một &lt;strong&gt;tập đa diện&lt;/strong&gt; (polyhedron).&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Tính chất quan trọng:&lt;/strong&gt; Nếu một bài toán quy hoạch tuyến tính có nghiệm tối ưu (và tập khả thi không chứa đường thẳng), thì luôn tồn tại ít nhất một nghiệm tối ưu nằm tại một &lt;strong&gt;đỉnh&lt;/strong&gt; của miền khả thi. Đây chính là cơ sở để phương pháp Simplex tìm nghiệm bằng cách di chuyển từ đỉnh này sang đỉnh kề.
&lt;/div&gt;

&lt;div id=&quot;geometric-lp-viz&quot; style=&quot;margin: 20px 0; text-align: center;&quot;&gt;&lt;/div&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter05/05_01_geometric_interpretation_of_LP.png&quot; alt=&quot;[Fig1] Giải thích hình học của LP [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Minh họa hình học của bài toán LP [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;lp-ở-dạng-chuẩn&quot;&gt;LP ở dạng chuẩn&lt;/h2&gt;

&lt;p&gt;Nhiều thuật toán giải LP (chẳng hạn phương pháp Simplex) được thiết kế để làm việc trên một cấu trúc đầu vào thống nhất gọi là &lt;strong&gt;dạng chuẩn&lt;/strong&gt;. Việc đưa bài toán về dạng chuẩn cho phép áp dụng các thuật toán này một cách nhất quán.&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-lp-dạng-chuẩn&quot;&gt;Bài toán LP dạng chuẩn&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{A x = b} \\\\
   &amp;amp; &amp;amp;&amp;amp;{x \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Đặc trưng của dạng chuẩn:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mục tiêu:&lt;/strong&gt; luôn ở dạng cực tiểu hóa (bài toán cực đại hóa được đổi dấu hàm mục tiêu).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc:&lt;/strong&gt; chỉ gồm các ràng buộc đẳng thức (bất đẳng thức được chuyển đổi bằng biến phụ).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến quyết định:&lt;/strong&gt; mọi biến đều không âm (\(x \succeq 0\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Vì sao cần dạng chuẩn?&lt;/strong&gt; 
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Thuận tiện cho thuật toán:&lt;/strong&gt; Phương pháp Simplex vận hành trực tiếp trên dạng chuẩn.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Phân tích lý thuyết:&lt;/strong&gt; Dễ thiết lập và chứng minh các điều kiện tối ưu cũng như đối ngẫu.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cài đặt phần mềm:&lt;/strong&gt; Đa số bộ giải LP yêu cầu dữ liệu đầu vào theo định dạng chuẩn hóa.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Mọi bài toán LP tổng quát đều có thể đưa về dạng chuẩn qua bốn bước sau:&lt;/p&gt;

&lt;h3 id=&quot;chuyển-đổi-lp-tổng-quát-về-dạng-chuẩn&quot;&gt;Chuyển đổi LP tổng quát về dạng chuẩn&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Bước 1.&lt;/strong&gt; Thêm vectơ biến phụ (slack variable) \(s \succeq 0\) để chuyển ràng buộc bất đẳng thức thành ràng buộc đẳng thức:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
    &amp;amp;\text{minimize}_{x, s} &amp;amp;&amp;amp;{c^T x + d} \\\\
    &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Gx + s = h} \\\\
    &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
    &amp;amp; &amp;amp;&amp;amp;{s \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 2.&lt;/strong&gt; Tách mỗi biến tự do \(x\) thành hiệu của hai biến không âm:
\(x = x^{+} - x^{-}\), trong đó \(x^{+}, \; x^{-} \succeq 0\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
    &amp;amp;\text{minimize}_{x^{+}, x^{-}, s} &amp;amp;&amp;amp;{c^Tx^{+} - c^Tx^{-} + d} \\\\
    &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Gx^{+} - Gx^{-} + s = h} \\\\
    &amp;amp; &amp;amp;&amp;amp;{Ax^{+} - Ax^{-} = b},\\\\
    &amp;amp; &amp;amp;&amp;amp;{s \succeq 0}\\\\
    &amp;amp; &amp;amp;&amp;amp;{x^{+} \succeq 0}, \; {x^{-} \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 3.&lt;/strong&gt; Định nghĩa các vectơ và ma trận khối \(ilde{x}\), \(ilde{c}\), \(ilde{b}\) và \(ilde{A}\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\tilde{x} =
\begin{bmatrix}
x^{+} \\\\
x^{-} \\\\
s
\end{bmatrix}, 
\tilde{c} =
\begin{bmatrix}
c \\\\
-c \\\\
0
\end{bmatrix},
\tilde{b} =
\begin{bmatrix}
h \\\\
b
\end{bmatrix}\), 
\(\tilde{A} =
\begin{bmatrix}
G &amp;amp; -G &amp;amp; I\\\\
A &amp;amp; -A &amp;amp; O
\end{bmatrix}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 4.&lt;/strong&gt; Thay \(ilde{x}\), \(ilde{c}\), \(ilde{b}\) và \(ilde{A}\) vào bài toán ở Bước 2 để thu được dạng chuẩn:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
    &amp;amp;\text{minimize}_{\tilde{x}} &amp;amp;&amp;amp;{\tilde{c}^T \tilde{x} + d} \\\\
    &amp;amp;\text{subject to} &amp;amp;&amp;amp;{\tilde{A} \tilde{x} = \tilde{b}} \\\\
    &amp;amp; &amp;amp;&amp;amp;{\tilde{x} \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;ví-dụ-bài-toán-khẩu-phần-ăn-diet-problem&quot;&gt;Ví dụ: Bài toán khẩu phần ăn (Diet Problem)&lt;/h3&gt;

&lt;p&gt;Bài toán khẩu phần ăn là một ứng dụng kinh điển của quy hoạch tuyến tính, lần đầu được nghiên cứu trong Thế chiến thứ hai nhằm tìm thực đơn có chi phí thấp nhất mà vẫn đáp ứng đầy đủ nhu cầu dinh dưỡng tối thiểu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phát biểu bài toán:&lt;/strong&gt; Tìm tổ hợp thực phẩm rẻ nhất thỏa mãn tất cả các định mức dinh dưỡng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
    &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x} \\\\
    &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Dx \succeq d} \\\\
    &amp;amp; &amp;amp;&amp;amp;{x \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Biến và tham số:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(c_j\): giá tiền trên mỗi đơn vị thực phẩm \(j\) ($/đơn vị).&lt;/li&gt;
  &lt;li&gt;\(d_i\): mức tiêu thụ tối thiểu khuyến nghị cho chất dinh dưỡng \(i\) (đơn vị/ngày).&lt;/li&gt;
  &lt;li&gt;\(D_{ij}\): hàm lượng chất dinh dưỡng \(i\) trong một đơn vị thực phẩm \(j\).&lt;/li&gt;
  &lt;li&gt;\(x_j\): lượng thực phẩm \(j\) trong khẩu phần ăn (đơn vị/ngày).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;content-box exercise-box&quot;&gt;
&lt;strong&gt;Bộ tối ưu hóa khẩu phần ăn tương tác:&lt;/strong&gt; Giải bài toán khẩu phần ăn đơn giản với 3 loại thực phẩm và 2 nhóm dinh dưỡng:

&lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; margin: 15px 0;&quot;&gt;
  &lt;div style=&quot;text-align: center;&quot;&gt;
    &lt;strong&gt;Bánh mì&lt;/strong&gt;&lt;br /&gt;
    Chi phí: $2/ổ&lt;br /&gt;
    Protein: 4g/ổ&lt;br /&gt;
    Calories: 200/ổ
  &lt;/div&gt;
  &lt;div style=&quot;text-align: center;&quot;&gt;
    &lt;strong&gt;Sữa&lt;/strong&gt;&lt;br /&gt;
    Chi phí: $3/lít&lt;br /&gt;
    Protein: 8g/lít&lt;br /&gt;
    Calories: 150/lít
  &lt;/div&gt;
  &lt;div style=&quot;text-align: center;&quot;&gt;
    &lt;strong&gt;Thịt&lt;/strong&gt;&lt;br /&gt;
    Chi phí: $8/kg&lt;br /&gt;
    Protein: 20g/kg&lt;br /&gt;
    Calories: 300/kg
  &lt;/div&gt;
&lt;/div&gt;

&lt;div style=&quot;margin: 15px 0;&quot;&gt;
  &lt;strong&gt;Yêu cầu dinh dưỡng:&lt;/strong&gt;
  &lt;div&gt;Protein tối thiểu: &lt;input type=&quot;number&quot; id=&quot;min-protein&quot; value=&quot;20&quot; min=&quot;10&quot; max=&quot;50&quot; style=&quot;width: 60px;&quot; /&gt; gram/ngày&lt;/div&gt;
  &lt;div&gt;Calories tối thiểu: &lt;input type=&quot;number&quot; id=&quot;min-calories&quot; value=&quot;800&quot; min=&quot;500&quot; max=&quot;1500&quot; style=&quot;width: 80px;&quot; /&gt; calories/ngày&lt;/div&gt;
&lt;/div&gt;

&lt;button id=&quot;solve-diet&quot; style=&quot;background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer;&quot;&gt;Giải bài toán khẩu phần ăn&lt;/button&gt;

&lt;div id=&quot;diet-results&quot; style=&quot;margin-top: 15px; font-family: monospace; background-color: #f9f9f9; padding: 10px; border-radius: 4px;&quot;&gt;
  &lt;div&gt;Nhấp &quot;Giải bài toán khẩu phần ăn&quot; để xem nghiệm tối ưu.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Ứng dụng thực tế:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hậu cần quân sự:&lt;/strong&gt; Xây dựng khẩu phần bảo đảm dinh dưỡng với chi phí hợp lý.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dinh dưỡng bệnh viện:&lt;/strong&gt; Lập thực đơn đáp ứng yêu cầu điều trị của từng nhóm bệnh nhân.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Phối trộn thức ăn chăn nuôi:&lt;/strong&gt; Đáp ứng định mức dinh dưỡng vật nuôi với chi phí tối thiểu.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bữa ăn học đường:&lt;/strong&gt; Thiết kế thực đơn cân bằng trong giới hạn ngân sách.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;thuật-toán-simplex&quot;&gt;Thuật toán Simplex&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Thuật toán Simplex&lt;/strong&gt; (phương pháp đơn hình), do George Dantzig phát triển năm 1947, là một trong những thuật toán nền tảng của ngành tối ưu hóa, cung cấp phương pháp có hệ thống để giải các bài toán LP.&lt;/p&gt;

&lt;h3 id=&quot;vì-sao-simplex-hoạt-động-định-lý-cơ-bản&quot;&gt;Vì sao Simplex hoạt động: Định lý cơ bản&lt;/h3&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Định lý cơ bản của Quy hoạch tuyến tính:&lt;/strong&gt; Nếu một bài toán quy hoạch tuyến tính có nghiệm tối ưu (và miền khả thi không chứa đường thẳng), thì luôn tồn tại một nghiệm tối ưu nằm tại một đỉnh (điểm cực biên) của miền khả thi.
&lt;/div&gt;

&lt;p&gt;Nhờ định lý này, thay vì phải tìm kiếm trên toàn bộ miền khả thi chứa vô số điểm, thuật toán chỉ cần khảo sát một tập hữu hạn các đỉnh.&lt;/p&gt;

&lt;h3 id=&quot;chiến-lược-hoạt-động-của-simplex&quot;&gt;Chiến lược hoạt động của Simplex&lt;/h3&gt;

&lt;p&gt;Thuật toán Simplex vận hành theo quy trình bốn bước:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khởi tạo&lt;/strong&gt; tại một đỉnh (nghiệm khả thi cơ sở) bất kỳ của miền khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra&lt;/strong&gt; xem đỉnh hiện tại đã tối ưu hay chưa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Di chuyển&lt;/strong&gt; dọc theo một cạnh sang đỉnh kề giúp cải thiện giá trị hàm mục tiêu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lặp lại&lt;/strong&gt; cho đến khi không còn hướng cải thiện nào (đạt nghiệm tối ưu).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;các-bước-của-thuật-toán-simplex&quot;&gt;Các bước của thuật toán Simplex&lt;/h3&gt;

&lt;p&gt;Xét bài toán LP ở dạng chuẩn:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
    &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x} \\\\
    &amp;amp;\text{subject to } &amp;amp;&amp;amp;{A x = b} \\\\
    &amp;amp; &amp;amp;&amp;amp;{x \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bước 1: Thiết lập ban đầu&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Đưa bài toán LP về dạng chuẩn (nếu chưa ở dạng chuẩn).&lt;/li&gt;
  &lt;li&gt;Tìm một nghiệm khả thi cơ sở ban đầu (một đỉnh xuất phát).&lt;/li&gt;
  &lt;li&gt;Lập bảng đơn hình (simplex tableau).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bước 2: Kiểm tra điều kiện tối ưu&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Kiểm tra xem nghiệm cơ sở hiện tại đã tối ưu chưa.&lt;/li&gt;
  &lt;li&gt;Nếu mọi chi phí rút gọn đều không âm, dừng thuật toán và trả về nghiệm tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bước 3: Chọn biến vào cơ sở&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Chọn biến ngoài cơ sở có chi phí rút gọn âm nhất.&lt;/li&gt;
  &lt;li&gt;Biến này xác định cạnh (hướng) di chuyển tiếp theo.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bước 4: Chọn biến ra khỏi cơ sở&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Áp dụng phép kiểm định tỉ số nhỏ nhất (minimum ratio test) để duy trì tính khả thi (\(x \succeq 0\)).&lt;/li&gt;
  &lt;li&gt;Phép kiểm định này xác định độ dài bước di chuyển tới đỉnh kề.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bước 5: Phép xoay (Pivot)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Cập nhật bảng đơn hình bằng phép khử Gauss.&lt;/li&gt;
  &lt;li&gt;Chuyển sang đỉnh mới tương ứng với cơ sở mới.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bước 6: Lặp lại&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Quay về Bước 2 cho đến khi đạt điều kiện dừng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;minh-họa-tương-tác-thuật-toán-simplex&quot;&gt;Minh họa tương tác thuật toán Simplex&lt;/h3&gt;

&lt;p&gt;Theo dõi từng bước di chuyển qua các đỉnh trên một bài toán hai chiều đơn giản:&lt;/p&gt;

&lt;div class=&quot;content-box exercise-box&quot;&gt;
&lt;strong&gt;Bộ giải Simplex tương tác:&lt;/strong&gt; Quan sát thuật toán di chuyển qua từng đỉnh của miền khả thi.

**Bài toán:**
$$\begin{align}
\text{maximize } &amp;amp; 3x_1 + 2x_2 \\
\text{subject to } &amp;amp; x_1 + x_2 \leq 4 \\
&amp;amp; 2x_1 + x_2 \leq 6 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}$$

&lt;div id=&quot;simplex-interactive&quot; style=&quot;margin: 20px 0;&quot;&gt;&lt;/div&gt;

&lt;div style=&quot;margin: 15px 0;&quot;&gt;
  &lt;button id=&quot;simplex-step&quot; style=&quot;background-color: #2196F3; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; margin-right: 10px;&quot;&gt;Bước tiếp theo&lt;/button&gt;
  &lt;button id=&quot;simplex-reset&quot; style=&quot;background-color: #f44336; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer;&quot;&gt;Đặt lại&lt;/button&gt;
&lt;/div&gt;

&lt;div id=&quot;simplex-status&quot; style=&quot;margin-top: 15px; font-family: monospace; background-color: #f9f9f9; padding: 15px; border-radius: 4px;&quot;&gt;
  &lt;div&gt;&lt;strong&gt;Bước 0:&lt;/strong&gt; Bắt đầu tại gốc tọa độ (0, 0)&lt;/div&gt;
  &lt;div&gt;Giá trị hàm mục tiêu hiện tại: 0&lt;/div&gt;
  &lt;div&gt;Nhấp &quot;Bước tiếp theo&quot; để bắt đầu thuật toán Simplex.&lt;/div&gt;
&lt;/div&gt;

&lt;div id=&quot;simplex-tableau&quot; style=&quot;margin-top: 15px; font-family: monospace; background-color: #f0f8ff; padding: 15px; border-radius: 4px;&quot;&gt;
  &lt;strong&gt;Bảng Simplex hiện tại:&lt;/strong&gt;
  &lt;div id=&quot;tableau-content&quot; style=&quot;margin-top: 10px;&quot;&gt;
    Nhấp &quot;Bước tiếp theo&quot; để xem bảng đơn hình.
  &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;hiệu-năng-thực-tế-của-simplex&quot;&gt;Hiệu năng thực tế của Simplex&lt;/h3&gt;

&lt;p&gt;Mặc dù có độ phức tạp trường hợp xấu nhất là hàm mũ, thuật toán Simplex vẫn đạt hiệu quả cao trên các bài toán thực tế:&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Đặc điểm hiệu năng của Simplex:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Trường hợp trung bình:&lt;/strong&gt; Thường chỉ cần duyệt số đỉnh gấp khoảng 2–3 lần số ràng buộc.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bài toán thực tiễn:&lt;/strong&gt; Hành vi tính toán thực tế thường tương đương thời gian đa thức.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Khởi tạo nóng (warm start):&lt;/strong&gt; Dễ tận dụng lại cơ sở tối ưu cũ khi tham số bài toán thay đổi nhẹ.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Xử lý suy biến:&lt;/strong&gt; Các cài đặt hiện đại có cơ chế chống lặp vòng hiệu quả cho các đỉnh suy biến.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;h3 id=&quot;các-biến-thể-của-simplex-và-hướng-phát-triển-hiện-đại&quot;&gt;Các biến thể của Simplex và hướng phát triển hiện đại&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp Simplex cải tiến (Revised Simplex):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Ổn định số tốt hơn so với cập nhật toàn bộ bảng.&lt;/li&gt;
  &lt;li&gt;Khai thác tốt tính thưa của ma trận ràng buộc.&lt;/li&gt;
  &lt;li&gt;Là nền tảng của hầu hết các bộ giải LP thương mại.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp Simplex đối ngẫu (Dual Simplex):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bắt đầu từ nghiệm khả thi đối ngẫu và duy trì tính khả thi đối ngẫu trong suốt quá trình xoay.&lt;/li&gt;
  &lt;li&gt;Rất thuận tiện cho phân tích độ nhạy và khi bổ sung ràng buộc mới (như trong nhánh cận của quy hoạch nguyên).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp điểm trong (Interior-Point Methods):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Có đảm bảo lý thuyết về độ phức tạp thời gian đa thức.&lt;/li&gt;
  &lt;li&gt;Thường tỏ ra lợi thế trên các bài toán kích thước rất lớn.&lt;/li&gt;
  &lt;li&gt;Bổ trợ cho Simplex thay vì thay thế hoàn toàn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ứng-dụng-thực-tế&quot;&gt;Ứng dụng thực tế&lt;/h3&gt;

&lt;p&gt;Thuật toán Simplex và quy hoạch tuyến tính được ứng dụng rộng rãi trong nhiều lĩnh vực:&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Các lĩnh vực ứng dụng tiêu biểu:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hàng không:&lt;/strong&gt; Lập lịch phi hành đoàn, tối ưu hóa đường bay và phân bổ đội tàu bay.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sản xuất:&lt;/strong&gt; Lập kế hoạch sản xuất và tối ưu hóa chuỗi cung ứng.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tài chính:&lt;/strong&gt; Phân bổ tài sản và quản trị rủi ro.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Viễn thông:&lt;/strong&gt; Tối ưu hóa luồng mạng và phân bổ băng thông.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Năng lượng:&lt;/strong&gt; Điều độ lưới điện và phân bổ nguồn phát.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;script&gt;
/**
 * Interactive Linear Programming Visualizations
 * Implements farmer problem, geometric interpretation, diet optimizer, and norm comparisons
 */

// Wait for DOM to be fully loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    
    // ==================== FARMER PROBLEM INTERACTIVE ====================
    
    function initializeFarmerProblem() {
        const cornSlider = document.getElementById(&apos;corn-acres&apos;);
        const wheatSlider = document.getElementById(&apos;wheat-acres&apos;);
        
        if (!cornSlider || !wheatSlider) return;
        
        function updateFarmerResults() {
            const corn = parseFloat(cornSlider.value);
            const wheat = parseFloat(wheatSlider.value);
            
            // Update display values
            document.getElementById(&apos;corn-value&apos;).textContent = corn;
            document.getElementById(&apos;wheat-value&apos;).textContent = wheat;
            
            // Calculate metrics
            const landUsed = corn + wheat;
            const laborUsed = corn * 2 + wheat * 1; // 2 hours per corn acre, 1 hour per wheat acre
            const profit = corn * 300 + wheat * 200; // $300 per corn acre, $200 per wheat acre
            
            // Update results
            document.getElementById(&apos;land-used&apos;).textContent = landUsed;
            document.getElementById(&apos;labor-used&apos;).textContent = laborUsed;
            document.getElementById(&apos;total-profit&apos;).textContent = profit;
            
            // Check feasibility
            const feasibilityStatus = document.getElementById(&apos;feasibility-status&apos;);
            if (landUsed &lt;= 100 &amp;&amp; laborUsed &lt;= 150) {
                feasibilityStatus.textContent = &apos;✓ Feasible solution&apos;;
                feasibilityStatus.style.color = &apos;green&apos;;
            } else {
                feasibilityStatus.textContent = &apos;✗ Infeasible solution&apos;;
                feasibilityStatus.style.color = &apos;red&apos;;
            }
        }
        
        cornSlider.addEventListener(&apos;input&apos;, updateFarmerResults);
        wheatSlider.addEventListener(&apos;input&apos;, updateFarmerResults);
        
        // Initialize
        updateFarmerResults();
    }
    
    // ==================== DIET PROBLEM SOLVER ====================
    
    function initializeDietSolver() {
        const solveButton = document.getElementById(&apos;solve-diet&apos;);
        if (!solveButton) return;
        
        solveButton.addEventListener(&apos;click&apos;, function() {
            const minProtein = parseFloat(document.getElementById(&apos;min-protein&apos;).value);
            const minCalories = parseFloat(document.getElementById(&apos;min-calories&apos;).value);
            
            // Simple heuristic solver (in practice, would use simplex method)
            // Food data: [cost, protein, calories]
            const bread = [2, 4, 200];
            const milk = [3, 8, 150];
            const meat = [8, 20, 300];
            
            // Try different combinations and find minimum cost feasible solution
            let bestCost = Infinity;
            let bestSolution = null;
            
            for (let b = 0; b &lt;= 20; b += 0.5) {
                for (let m = 0; m &lt;= 10; m += 0.5) {
                    for (let mt = 0; mt &lt;= 5; mt += 0.5) {
                        const protein = b * bread[1] + m * milk[1] + mt * meat[1];
                        const calories = b * bread[2] + m * milk[2] + mt * meat[2];
                        const cost = b * bread[0] + m * milk[0] + mt * meat[0];
                        
                        if (protein &gt;= minProtein &amp;&amp; calories &gt;= minCalories &amp;&amp; cost &lt; bestCost) {
                            bestCost = cost;
                            bestSolution = [b, m, mt];
                        }
                    }
                }
            }
            
            const resultsDiv = document.getElementById(&apos;diet-results&apos;);
            if (bestSolution) {
                const [bread_amt, milk_amt, meat_amt] = bestSolution;
                const totalProtein = bread_amt * bread[1] + milk_amt * milk[1] + meat_amt * meat[1];
                const totalCalories = bread_amt * bread[2] + milk_amt * milk[2] + meat_amt * meat[2];
                
                resultsDiv.innerHTML = `
                    &lt;div&gt;&lt;strong&gt;Optimal Diet Solution:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Bread: ${bread_amt.toFixed(1)} loaves&lt;/div&gt;
                    &lt;div&gt;Milk: ${milk_amt.toFixed(1)} liters&lt;/div&gt;
                    &lt;div&gt;Meat: ${meat_amt.toFixed(1)} kg&lt;/div&gt;
                    &lt;div&gt;---&lt;/div&gt;
                    &lt;div&gt;Total cost: $${bestCost.toFixed(2)}&lt;/div&gt;
                    &lt;div&gt;Total protein: ${totalProtein.toFixed(1)}g (required: ${minProtein}g)&lt;/div&gt;
                    &lt;div&gt;Total calories: ${totalCalories.toFixed(0)} (required: ${minCalories})&lt;/div&gt;
                `;
            } else {
                resultsDiv.innerHTML = &apos;&lt;div style=&quot;color: red;&quot;&gt;No feasible solution found!&lt;/div&gt;&apos;;
            }
        });
    }
    
    // ==================== SIMPLEX ALGORITHM VISUALIZATION ====================
    
    function initializeSimplexVisualization() {
        const stepButton = document.getElementById(&apos;simplex-step&apos;);
        const resetButton = document.getElementById(&apos;simplex-reset&apos;);
        const statusDiv = document.getElementById(&apos;simplex-status&apos;);
        const tableauDiv = document.getElementById(&apos;tableau-content&apos;);
        const interactiveDiv = document.getElementById(&apos;simplex-interactive&apos;);
        
        if (!stepButton || !resetButton || !statusDiv || !tableauDiv || !interactiveDiv) return;
        
        // Simplex algorithm state
        let currentStep = 0;
        let currentVertex = [0, 0]; // Starting at origin
        let isOptimal = false;
        
        // Problem: maximize 3x1 + 2x2 subject to x1 + x2 &lt;= 4, 2x1 + x2 &lt;= 6, x1,x2 &gt;= 0
        // In standard form: minimize -3x1 - 2x2 subject to x1 + x2 + s1 = 4, 2x1 + x2 + s2 = 6
        
        const vertices = [
            [0, 0, 4, 6], // (x1, x2, s1, s2) - origin
            [0, 4, 0, 2], // (0, 4, 0, 2) - intersection with x1 + x2 = 4
            [2, 2, 0, 0], // (2, 2, 0, 0) - intersection of both constraints
            [3, 0, 1, 0]  // (3, 0, 1, 0) - intersection with 2x1 + x2 = 6
        ];
        
        const objectiveValues = [0, 8, 10, 9]; // 3x1 + 2x2 at each vertex
        const simplexPath = [0, 3, 2]; // Path: origin -&gt; (3,0) -&gt; (2,2) optimal
        
        function createVisualization() {
            const width = 400;
            const height = 300;
            const margin = {top: 20, right: 20, bottom: 40, left: 40};
            
            // Clear previous content
            interactiveDiv.innerHTML = &apos;&apos;;
            
            const svg = d3.select(&apos;#simplex-interactive&apos;)
                .append(&apos;svg&apos;)
                .attr(&apos;width&apos;, width)
                .attr(&apos;height&apos;, height);
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain([0, 4])
                .range([margin.left, width - margin.right]);
            
            const yScale = d3.scaleLinear()
                .domain([0, 6])
                .range([height - margin.bottom, margin.top]);
            
            // Draw feasible region
            const feasibleRegion = [
                [0, 0], [0, 4], [2, 2], [3, 0], [0, 0]
            ];
            
            svg.append(&apos;path&apos;)
                .datum(feasibleRegion)
                .attr(&apos;fill&apos;, &apos;lightblue&apos;)
                .attr(&apos;fill-opacity&apos;, 0.3)
                .attr(&apos;stroke&apos;, &apos;blue&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;d&apos;, d3.line()
                    .x(d =&gt; xScale(d[0]))
                    .y(d =&gt; yScale(d[1]))
                );
            
            // Draw constraint lines
            // x1 + x2 = 4
            svg.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, xScale(0))
                .attr(&apos;y1&apos;, yScale(4))
                .attr(&apos;x2&apos;, xScale(4))
                .attr(&apos;y2&apos;, yScale(0))
                .attr(&apos;stroke&apos;, &apos;red&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;stroke-dasharray&apos;, &apos;5,5&apos;);
            
            // 2x1 + x2 = 6
            svg.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, xScale(0))
                .attr(&apos;y1&apos;, yScale(6))
                .attr(&apos;x2&apos;, xScale(3))
                .attr(&apos;y2&apos;, yScale(0))
                .attr(&apos;stroke&apos;, &apos;green&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;stroke-dasharray&apos;, &apos;5,5&apos;);
            
            // Draw vertices
            const vertexPoints = [[0,0], [0,4], [2,2], [3,0]];
            svg.selectAll(&apos;.vertex&apos;)
                .data(vertexPoints)
                .enter()
                .append(&apos;circle&apos;)
                .attr(&apos;class&apos;, &apos;vertex&apos;)
                .attr(&apos;cx&apos;, d =&gt; xScale(d[0]))
                .attr(&apos;cy&apos;, d =&gt; yScale(d[1]))
                .attr(&apos;r&apos;, 6)
                .attr(&apos;fill&apos;, &apos;orange&apos;)
                .attr(&apos;stroke&apos;, &apos;black&apos;)
                .attr(&apos;stroke-width&apos;, 2);
            
            // Current position indicator
            svg.append(&apos;circle&apos;)
                .attr(&apos;id&apos;, &apos;current-position&apos;)
                .attr(&apos;cx&apos;, xScale(currentVertex[0]))
                .attr(&apos;cy&apos;, yScale(currentVertex[1]))
                .attr(&apos;r&apos;, 8)
                .attr(&apos;fill&apos;, &apos;red&apos;)
                .attr(&apos;stroke&apos;, &apos;darkred&apos;)
                .attr(&apos;stroke-width&apos;, 3);
            
            // Axes
            svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height - margin.bottom})`)
                .call(d3.axisBottom(xScale));
            
            svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},0)`)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            svg.append(&apos;text&apos;)
                .attr(&apos;x&apos;, width / 2)
                .attr(&apos;y&apos;, height - 5)
                .attr(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;x₁&apos;);
            
            svg.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;x&apos;, -height / 2)
                .attr(&apos;y&apos;, 15)
                .attr(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;x₂&apos;);
            
            // Legend
            const legend = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${width - 150}, 30)`);
            
            legend.append(&apos;text&apos;)
                .attr(&apos;x&apos;, 0)
                .attr(&apos;y&apos;, 0)
                .text(&apos;Constraints:&apos;)
                .attr(&apos;font-weight&apos;, &apos;bold&apos;);
            
            legend.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, 0)
                .attr(&apos;y1&apos;, 15)
                .attr(&apos;x2&apos;, 20)
                .attr(&apos;y2&apos;, 15)
                .attr(&apos;stroke&apos;, &apos;red&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;stroke-dasharray&apos;, &apos;5,5&apos;);
            
            legend.append(&apos;text&apos;)
                .attr(&apos;x&apos;, 25)
                .attr(&apos;y&apos;, 19)
                .text(&apos;x₁ + x₂ ≤ 4&apos;)
                .attr(&apos;font-size&apos;, &apos;12px&apos;);
            
            legend.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, 0)
                .attr(&apos;y1&apos;, 30)
                .attr(&apos;x2&apos;, 20)
                .attr(&apos;y2&apos;, 30)
                .attr(&apos;stroke&apos;, &apos;green&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;stroke-dasharray&apos;, &apos;5,5&apos;);
            
            legend.append(&apos;text&apos;)
                .attr(&apos;x&apos;, 25)
                .attr(&apos;y&apos;, 34)
                .text(&apos;2x₁ + x₂ ≤ 6&apos;)
                .attr(&apos;font-size&apos;, &apos;12px&apos;);
        }
        
        function updateTableau(step) {
            let tableauHTML = &apos;&apos;;
            
            switch(step) {
                case 0:
                    tableauHTML = `
                        &lt;table style=&quot;border-collapse: collapse; margin: 10px 0;&quot;&gt;
                            &lt;tr style=&quot;background-color: #e0e0e0;&quot;&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Basic&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;RHS&lt;/th&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;4&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;2&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;6&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #fff2cc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;z&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; color: red;&quot;&gt;&lt;strong&gt;-3&lt;/strong&gt;&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; color: red;&quot;&gt;-2&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
                            &lt;strong&gt;Analysis:&lt;/strong&gt; Most negative coefficient is -3 (x₁ column). x₁ enters the basis.
                        &lt;/div&gt;
                    `;
                    break;
                case 1:
                    tableauHTML = `
                        &lt;table style=&quot;border-collapse: collapse; margin: 10px 0;&quot;&gt;
                            &lt;tr style=&quot;background-color: #e0e0e0;&quot;&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Basic&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;RHS&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Ratio&lt;/th&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; background-color: #ffcccc;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;4&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;4/1 = 4&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #ccffcc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; background-color: #ffcccc;&quot;&gt;&lt;strong&gt;2&lt;/strong&gt;&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;6&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;6/2 = 3&lt;/strong&gt;&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #fff2cc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;z&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; background-color: #ffcccc;&quot;&gt;-3&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;-2&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;-&lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
                            &lt;strong&gt;Minimum ratio test:&lt;/strong&gt; min{4/1, 6/2} = min{4, 3} = 3. s₂ leaves the basis.
                        &lt;/div&gt;
                    `;
                    break;
                case 2:
                    tableauHTML = `
                        &lt;table style=&quot;border-collapse: collapse; margin: 10px 0;&quot;&gt;
                            &lt;tr style=&quot;background-color: #e0e0e0;&quot;&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Basic&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;RHS&lt;/th&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; color: red;&quot;&gt;&lt;strong&gt;0.5&lt;/strong&gt;&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;-0.5&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0.5&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0.5&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;3&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #fff2cc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;z&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; color: red;&quot;&gt;&lt;strong&gt;-0.5&lt;/strong&gt;&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1.5&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;9&lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
                            &lt;strong&gt;Current solution:&lt;/strong&gt; x₁ = 3, x₂ = 0, objective = 9&lt;br&gt;
                            &lt;strong&gt;Analysis:&lt;/strong&gt; x₂ has negative coefficient (-0.5), so x₂ enters the basis.
                        &lt;/div&gt;
                    `;
                    break;
                case 3:
                    tableauHTML = `
                        &lt;table style=&quot;border-collapse: collapse; margin: 10px 0;&quot;&gt;
                            &lt;tr style=&quot;background-color: #e0e0e0;&quot;&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Basic&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;RHS&lt;/th&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #ccffcc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₂&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;2&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;-1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;2&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;-1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;2&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #ccffcc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;z&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;10&lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
                            &lt;strong&gt;OPTIMAL SOLUTION FOUND!&lt;/strong&gt;&lt;br&gt;
                            x₁ = 2, x₂ = 2, Maximum objective value = 10&lt;br&gt;
                            All coefficients in the objective row are non-negative.
                        &lt;/div&gt;
                    `;
                    break;
            }
            
            tableauDiv.innerHTML = tableauHTML;
        }
        
        function updateStatus(step) {
            let statusHTML = &apos;&apos;;
            
            switch(step) {
                case 0:
                    statusHTML = `
                        &lt;div&gt;&lt;strong&gt;Step 0:&lt;/strong&gt; Initial basic feasible solution&lt;/div&gt;
                        &lt;div&gt;Current vertex: (0, 0)&lt;/div&gt;
                        &lt;div&gt;Current objective value: 0&lt;/div&gt;
                        &lt;div&gt;Basic variables: s₁ = 4, s₂ = 6&lt;/div&gt;
                    `;
                    currentVertex = [0, 0];
                    break;
                case 1:
                    statusHTML = `
                        &lt;div&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Choose entering variable&lt;/div&gt;
                        &lt;div&gt;Most negative coefficient: -3 (x₁ column)&lt;/div&gt;
                        &lt;div&gt;x₁ enters the basis&lt;/div&gt;
                        &lt;div&gt;Performing minimum ratio test...&lt;/div&gt;
                    `;
                    break;
                case 2:
                    statusHTML = `
                        &lt;div&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; First iteration complete&lt;/div&gt;
                        &lt;div&gt;Current vertex: (3, 0)&lt;/div&gt;
                        &lt;div&gt;Current objective value: 9&lt;/div&gt;
                        &lt;div&gt;Basic variables: x₁ = 3, s₁ = 1&lt;/div&gt;
                    `;
                    currentVertex = [3, 0];
                    break;
                case 3:
                    statusHTML = `
                        &lt;div&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; OPTIMAL SOLUTION FOUND!&lt;/div&gt;
                        &lt;div&gt;Current vertex: (2, 2)&lt;/div&gt;
                        &lt;div&gt;Maximum objective value: 10&lt;/div&gt;
                        &lt;div&gt;Basic variables: x₁ = 2, x₂ = 2&lt;/div&gt;
                    `;
                    currentVertex = [2, 2];
                    isOptimal = true;
                    break;
            }
            
            statusDiv.innerHTML = statusHTML;
            
            // Update visualization
            const currentPos = d3.select(&apos;#current-position&apos;);
            if (currentPos.node()) {
                const xScale = d3.scaleLinear().domain([0, 4]).range([40, 360]);
                const yScale = d3.scaleLinear().domain([0, 6]).range([260, 40]);
                
                currentPos
                    .transition()
                    .duration(500)
                    .attr(&apos;cx&apos;, xScale(currentVertex[0]))
                    .attr(&apos;cy&apos;, yScale(currentVertex[1]));
            }
        }
        
        function nextStep() {
            if (currentStep &lt; 3) {
                currentStep++;
                updateStatus(currentStep);
                updateTableau(currentStep);
                
                if (currentStep === 3) {
                    stepButton.textContent = &apos;Algorithm Complete!&apos;;
                    stepButton.disabled = true;
                    stepButton.style.backgroundColor = &apos;#4CAF50&apos;;
                }
            }
        }
        
        function reset() {
            currentStep = 0;
            currentVertex = [0, 0];
            isOptimal = false;
            
            stepButton.textContent = &apos;Next Step&apos;;
            stepButton.disabled = false;
            stepButton.style.backgroundColor = &apos;#2196F3&apos;;
            
            updateStatus(0);
            updateTableau(0);
            createVisualization();
        }
        
        // Event listeners
        stepButton.addEventListener(&apos;click&apos;, nextStep);
        resetButton.addEventListener(&apos;click&apos;, reset);
        
        // Initialize
        createVisualization();
        updateStatus(0);
        updateTableau(0);
    }
    
    // Initialize all interactive elements
    initializeFarmerProblem();
    initializeDietSolver();
    initializeSimplexVisualization();
    
    // Trigger MathJax re-rendering if needed
    if (window.MathJax) {
        MathJax.typesetPromise();
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>05-01-01 Quy Hoạch Tuyến Tính - Thuật Toán Simplex</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_01_01_LP_Simple_Algorithm/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_01_01_LP_Simple_Algorithm</id>
   <content type="html">&lt;p&gt;Một khối đa diện LP với 50 biến và 100 ràng buộc có thể sở hữu số đỉnh lớn hơn \(\binom{100}{50} \approx 10^{29}\) — liệt kê hết các đỉnh là bất khả thi ngay cả với siêu máy tính nhanh nhất thế giới. Vậy mà &lt;strong&gt;thuật toán Simplex&lt;/strong&gt; do George Dantzig phát minh năm 1947 lại thường tìm ra đỉnh tối ưu chỉ sau vài trăm bước nhảy!&lt;/p&gt;

&lt;p&gt;Bí quyết nằm ở đâu? Thay vì thử mù quáng mọi đỉnh, Simplex hành xử như một người leo núi thông minh trên khung cạnh của đa diện: đứng tại một đỉnh (nghiệm cơ sở khả thi), thuật toán nhìn dọc theo các cạnh xuất phát từ đỉnh đó, chọn một cạnh làm giảm hàm mục tiêu (chi phí rút gọn âm), rồi trượt thẳng sang đỉnh kề tốt hơn. Khi mọi cạnh xuất phát đều làm tăng hàm mục tiêu, ta biết chắc mình đã đứng ở đỉnh tối ưu toàn cục!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-động-cơ-đại-số-bên-trong-thuật-toán-simplex&quot;&gt;Kiến thức cần nhớ: Động cơ đại số bên trong thuật toán Simplex&lt;/h2&gt;

&lt;p&gt;Để không bao giờ bị lạc trong các bảng tính (tableau) của Simplex, hãy nắm vững bốn trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nghiệm cơ sở khả thi (Basic Feasible Solution - BFS):&lt;/strong&gt; Với hệ \(Ax = b\) (\(m\) phương trình, \(n\) biến, \(m &amp;lt; n\)), mỗi đỉnh của đa diện tương ứng với việc chọn \(m\) biến &lt;strong&gt;cơ sở&lt;/strong&gt; \(x_B\) (tương ứng ma trận con khả nghịch \(B\)) và đặt \(n - m\) biến &lt;strong&gt;phi cơ sở&lt;/strong&gt; \(x_N = 0\), sao cho \(x_B = B^{-1} b \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí rút gọn (Reduced Cost):&lt;/strong&gt; Khi tăng một biến phi cơ sở \(x_j\) từ \(0\) lên \(\theta &amp;gt; 0\), tốc độ thay đổi ròng của hàm mục tiêu là \(\bar{c}_j = c_j - c_B^T B^{-1} A_j\). Nếu mọi \(\bar{c}_j \ge 0\), không hướng nào cải thiện được nữa — ta dừng và kết luận tối ưu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép xoay trục &amp;amp; Quy tắc tỉ số nhỏ nhất (Pivot &amp;amp; Minimum Ratio Test):&lt;/strong&gt; Khi chọn biến vào \(x_j\) có \(\bar{c}_j &amp;lt; 0\), ta tăng \(x_j\) tối đa đến mức nào để các biến cơ sở \(x_B = B^{-1}b - \theta (B^{-1}A_j)\) không bị âm? Đúng bằng \(\theta^\star = \min_{i : d_i &amp;gt; 0} \frac{(B^{-1}b)_i}{d_i}\) với \(d = B^{-1}A_j\). Biến cơ sở chạm \(0\) đầu tiên sẽ rời cơ sở!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ phức tạp thực tế vs. Trường hợp xấu nhất:&lt;/strong&gt; Dù về lý thuyết Klee–Minty chứng minh Simplex có thể tốn số bước hàm mũ trong trường hợp bệnh lý, trong thực tế Simplex chạy gần như tuyến tính \(O(m)\) bước xoay và vẫn là bộ giải chuẩn cho các bài LP lớn cần khởi động ấm (warm-start).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-trọn-vẹn-2-bước-xoay-simplex-trên-một-bài-lp&quot;&gt;Giải thích: Chạy tay trọn vẹn 2 bước xoay Simplex trên một bài LP&lt;/h3&gt;

&lt;p&gt;Xét bài toán dạng chuẩn:
\(\min \; -3x_1 - 2x_2 \quad \text{s.t.} \quad \begin{cases} x_1 + x_2 + s_1 = 4 \\ 2x_1 + x_2 + s_2 = 6 \end{cases}, \qquad x_1, x_2, s_1, s_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khởi tạo tại đỉnh gốc:&lt;/strong&gt; Cơ sở \(B = \{s_1, s_2\}\), phi cơ sở \(N = \{x_1, x_2\}\). Nghiệm: \(x_1=0, x_2=0, s_1=4, s_2=6\), giá trị \(f = 0\).
    &lt;ul&gt;
      &lt;li&gt;Chi phí rút gọn: \(\bar{c}_{x_1} = -3 &amp;lt; 0\), \(\bar{c}_{x_2} = -2 &amp;lt; 0\). Chọn biến vào là \(x_1\) (âm nhất).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước xoay 1 (đưa \(x_1\) vào cơ sở):&lt;/strong&gt;
Giữ \(x_2 = 0\), ta có \(s_1 = 4 - x_1 \ge 0 \implies x_1 \le 4\) và \(s_2 = 6 - 2x_1 \ge 0 \implies x_1 \le 3\).
Tỉ số nhỏ nhất là \(\min(4/1,\; 6/2) = 3\), nên \(s_2\) rời cơ sở!
Từ phương trình 2: \(x_1 = 3 - 0.5x_2 - 0.5s_2\). Thế vào phương trình 1 và hàm mục tiêu:
\(s_1 = 1 - 0.5x_2 + 0.5s_2, \qquad f = -9 - 0.5x_2 + 1.5s_2.\)
Đỉnh hiện tại: \((x_1, x_2, s_1, s_2) = (3, 0, 1, 0)\), \(f = -9\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước xoay 2 (đưa \(x_2\) vào cơ sở):&lt;/strong&gt;
Nhìn vào \(f = -9 - 0.5x_2 + 1.5s_2\): chi phí rút gọn \(\bar{c}_{x_2} = -0.5 &amp;lt; 0\), nên chọn \(x_2\) vào cơ sở!
Giữ \(s_2 = 0\): \(s_1 = 1 - 0.5x_2 \ge 0 \implies x_2 \le 2\); \(x_1 = 3 - 0.5x_2 \ge 0 \implies x_2 \le 6\).
Tỉ số nhỏ nhất là \(2\), nên \(s_1\) rời cơ sở! Từ \(s_1 = 1 - 0.5x_2 + 0.5s_2 \implies x_2 = 2 - 2s_1 + s_2\).
Thế vào \(x_1\) và \(f\):
\(x_1 = 2 + s_1 - s_2, \qquad f = -10 + s_1 + s_2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện dừng:&lt;/strong&gt; Mọi chi phí rút gọn của biến phi cơ sở (\(+1\) cho \(s_1\), \(+1\) cho \(s_2\)) đều \(\ge 0\)! Dừng ngay: nghiệm tối ưu là \(x_1^\star = 2, x_2^\star = 2\) và \(f^\star = -10\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài toán &lt;a href=&quot;/contents/vi/chapter05/05_01_Linear_Programming_(LP)/&quot;&gt;quy hoạch tuyến tính&lt;/a&gt; ở tiết trước có tập khả thi là một tập đa diện. Một tính chất hình học đặc trưng của LP là: &lt;strong&gt;nếu tồn tại nghiệm tối ưu hữu hạn (và tập khả thi không chứa đường thẳng), thì có ít nhất một điểm tối ưu nằm tại một đỉnh&lt;/strong&gt;. Thuật toán đơn hình (Simplex) di chuyển từ đỉnh này sang đỉnh kề sao cho giá trị hàm mục tiêu được cải thiện, cho đến khi không còn đỉnh lân cận nào tốt hơn.&lt;/p&gt;

&lt;p&gt;Minh họa bảng đơn hình tương tác: &lt;a href=&quot;https://github.com/nglelinh/interactive_math/blob/main/linear-programming/simplex_optimization_demo.html&quot;&gt;demo simplex&lt;/a&gt; trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nglelinh/interactive_math&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Ý tưởng then chốt:&lt;/strong&gt; Trong khi các phương pháp gradient di chuyển bên trong miền khả thi, thuật toán Simplex bám dọc theo các cạnh của tập đa diện và chỉ đánh giá tại các đỉnh. Nhờ đó, dù ra đời từ thập niên 1950, Simplex vẫn được sử dụng rộng rãi để giải nhiều bài toán LP trong phối trộn, định tuyến và bài toán đối ngẫu của SVM.
&lt;/div&gt;

&lt;h2 id=&quot;dạng-chuẩn&quot;&gt;Dạng chuẩn&lt;/h2&gt;

&lt;p&gt;Phần lớn các giáo trình trình bày thuật toán Simplex trên dạng chuẩn với ràng buộc đẳng thức và biến không âm:&lt;/p&gt;

\[\begin{align}
\underset{x}{\text{minimize}} \quad &amp;amp; c^\top x \\
\text{subject to} \quad &amp;amp; Ax = b, \\
&amp;amp; x \succeq 0,
\end{align}\]

&lt;p&gt;trong đó \(A \in \mathbb{R}^{m \times n}\) có hạng hàng đầy đủ bằng \(m\), \(b \succeq 0\), và \(n &amp;gt; m\). Các ràng buộc bất đẳng thức dạng \(Gx \preceq h\) được chuyển sang đẳng thức bằng cách thêm &lt;strong&gt;biến phụ&lt;/strong&gt; (slack variable) không âm, còn các biến tự do được tách thành hiệu của hai biến không âm.&lt;/p&gt;

&lt;p&gt;Một &lt;strong&gt;cơ sở&lt;/strong&gt; (basis) là một tập gồm \(m\) cột độc lập tuyến tính của \(A\). Sau khi hoán vị cột để viết \(A = [A_B \; A_N]\) và tách tương ứng \(x = (x_B, x_N)\), &lt;strong&gt;nghiệm cơ sở&lt;/strong&gt; được xác định bởi:&lt;/p&gt;

\[x_B = A_B^{-1} b, \qquad x_N = 0.\]

&lt;p&gt;Nếu \(x_B \succeq 0\), điểm này được gọi là &lt;strong&gt;nghiệm khả thi cơ sở (Basic Feasible Solution - BFS)&lt;/strong&gt; — về mặt hình học, đây chính là một đỉnh của đa diện khả thi.&lt;/p&gt;

&lt;h2 id=&quot;chi-phí-rút-gọn-và-bước-xoay-pivot&quot;&gt;Chi phí rút gọn và bước xoay (pivot)&lt;/h2&gt;

&lt;p&gt;Từ phương trình \(Ax = b\), ta biểu diễn các biến cơ sở theo các biến ngoài cơ sở:&lt;/p&gt;

\[x_B = A_B^{-1}b - A_B^{-1}A_N x_N.\]

&lt;p&gt;Thay vào hàm mục tiêu, ta thu được:&lt;/p&gt;

\[c^\top x = c_B^\top A_B^{-1}b + \bar{c}_N^\top x_N, \qquad \bar{c}_N^\top := c_N^\top - c_B^\top A_B^{-1}A_N.\]

&lt;p&gt;Vectơ \(\bar{c}_N\) chứa các &lt;strong&gt;chi phí rút gọn&lt;/strong&gt; (reduced costs). Do \(x_N \succeq 0\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nếu \(\bar{c}_N \succeq 0\), mọi cách tăng biến ngoài cơ sở đều không thể làm giảm hàm mục tiêu — nghiệm khả thi cơ sở hiện tại là &lt;strong&gt;tối ưu&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Nếu tồn tại \(\bar{c}_j &amp;lt; 0\), ta có thể tăng biến ngoài cơ sở tương ứng (biến &lt;strong&gt;vào&lt;/strong&gt; cơ sở) cho đến khi một biến cơ sở giảm về 0 (biến &lt;strong&gt;ra&lt;/strong&gt; khỏi cơ sở). Quy tắc kiểm định tỉ số (ratio test) chọn biến ra sao cho điều kiện \(x_B \succeq 0\) vẫn được duy trì.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mỗi phép thay đổi cơ sở như vậy gọi là một bước &lt;strong&gt;xoay&lt;/strong&gt; (pivot). Sau hữu hạn bước (khi áp dụng quy tắc chống lặp vòng, chẳng hạn quy tắc Bland), thuật toán Simplex hoặc dừng tại nghiệm tối ưu, hoặc phát hiện tia không bị chặn (\(Ax = 0\), \(x \succeq 0\), \(c^\top x &amp;lt; 0\)).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-hai-biến&quot;&gt;Ví dụ hai biến&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối đa hóa \(3x_1 + 2x_2\) (tương đương tối thiểu hóa \(-3x_1 - 2x_2\)) với các ràng buộc:&lt;/p&gt;

\[\begin{align}
x_1 + x_2 &amp;amp;\le 4, \\
2x_1 + x_2 &amp;amp;\le 6, \\
x_1, x_2 &amp;amp;\ge 0.
\end{align}\]

&lt;p&gt;Các đỉnh của đa giác khả thi là \((0,0)\), \((3,0)\), \((2,2)\) và \((0,4)\), với giá trị hàm mục tiêu lần lượt là \(0\), \(9\), \(10\) và \(8\). Xuất phát từ gốc tọa độ \((0,0)\), thuật toán Simplex có thể xoay sang \((3,0)\) rồi tới \((2,2)\), tại đó mọi chi phí rút gọn đều không âm. Quan sát hình học cũng cho cùng kết quả: các đường đồng mức của \(3x_1 + 2x_2\) tiếp xúc lần cuối với miền khả thi tại \((2,2)\).&lt;/p&gt;

&lt;h2 id=&quot;vai-trò-của-simplex-trong-khoa-học-dữ-liệu&quot;&gt;Vai trò của Simplex trong khoa học dữ liệu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra cấu trúc mô hình:&lt;/strong&gt; Khi viết được bài toán về dạng chuẩn LP, ta biết ngay bài toán có tính lồi và có nghiệm tối ưu tại đỉnh (nếu bị chặn).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên kết trực tiếp với lý thuyết đối ngẫu:&lt;/strong&gt; Các chi phí rút gọn chính là các biến phụ đối ngẫu. Điều kiện bù lỏng (complementary slackness) ở &lt;a href=&quot;/contents/vi/chapter12/12_00_KKT_conditions/&quot;&gt;Chương 12&lt;/a&gt; chính là chứng chỉ tối ưu mà thuật toán Simplex hướng tới.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sử dụng bộ giải thực tế:&lt;/strong&gt; Các thư viện giải LP hiện đại (HiGHS, Gurobi, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.optimize.linprog&lt;/code&gt;) kết hợp phương pháp Simplex cải tiến và/hoặc phương pháp điểm trong. Người dùng hiếm khi tự lập bảng bằng tay, nhưng cần hiểu bản chất để phân biệt kết quả &lt;em&gt;không khả thi&lt;/em&gt; (infeasible) với &lt;em&gt;không bị chặn&lt;/em&gt; (unbounded).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ghi chú về độ phức tạp:&lt;/strong&gt; Ví dụ khối Klee–Minty cho thấy một số quy tắc xoay có thể cần số bước hàm mũ trong trường hợp xấu nhất. Dù vậy, trong thực tế Simplex thường chạy rất nhanh; trong khi đó phương pháp điểm trong (Chương 15–17) có đảm bảo độ phức tạp thời gian đa thức và thường chiếm ưu thế trên nhiều bài toán LP thưa quy mô lớn. Khi bài toán đã có dạng LP hoặc QP chuẩn — như bài toán khẩu phần, đối ngẫu SVM biên cứng hay basis pursuit — cách tiếp cận thực tế là mô hình hóa bằng công cụ như CVXPY (xem bài thực hành DCP trong chương này) thay vì xoay bảng thủ công.&lt;/p&gt;

&lt;h3 id=&quot;phương-pháp-đơn-hình-trong-khoảng-3-phút&quot;&gt;Phương pháp đơn hình trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/simplex-pivots_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Đi theo các đỉnh của bài LP trong bài: chọn biến vào, kiểm tra tỉ số, xoay bảng, đọc nghiệm đối ngẫu, và một bài không bị chặn.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chuyển hệ ràng buộc \(x_1 - x_2 \le 3\), \(x_1 \ge 0\), \(x_2\) tự do về dạng chuẩn.&lt;/li&gt;
  &lt;li&gt;Xuất phát từ \((0,0)\) trong ví dụ trên, xác định biến vào đầu tiên nếu luôn chọn biến có chi phí rút gọn âm nhất.&lt;/li&gt;
  &lt;li&gt;Xây dựng một bài toán LP hai chiều khả thi nhưng không bị chặn và giải thích vì sao phép kiểm định tỉ số không tìm được biến ra.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Đọc thêm: Boyd &amp;amp; Vandenberghe, Phụ lục B; Nocedal &amp;amp; Wright, Chương 13; tài liệu bài toán chuẩn của CMU được liên kết tại &lt;a href=&quot;/&quot;&gt;README&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05 Các Bài Toán Chuẩn</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_00_Canonical_Problems/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter05/05_00_Canonical_Problems</id>
   <content type="html">&lt;p&gt;Nếu Chương 04 dạy bạn ngữ pháp chung của tối ưu hóa lồi, thì Chương 05 giống như việc bước vào bảo tàng những “kiến trúc kinh điển” đã định hình cả khoa học dữ liệu, tài chính và kỹ thuật hiện đại. Từ bài toán chia khẩu phần ăn thời Thế chiến II (LP), tối ưu danh mục đầu tư Markowitz đạt giải Nobel Kinh tế (QP), đến định vị vệ tinh và thiết kế ăng-ten (SOCP), hay nới lỏng đồ thị lượng tử và kiểm chứng mạng nơ-ron (SDP) — tất cả đều xếp thành một &lt;strong&gt;hệ phân cấp lồng nhau tuyệt đẹp&lt;/strong&gt;:
\(\text{LP} \subset \text{QP} \subset \text{QCQP} \subset \text{SOCP} \subset \text{SDP} \subset \text{CP}.\)&lt;/p&gt;

&lt;p&gt;Tại sao việc nhận diện đúng “họ” của bài toán lại quan trọng đến vậy? Bởi vì mỗi tầng cao hơn có sức biểu diễn mạnh hơn, nhưng chi phí giải cũng tăng theo: một bài LP hàng triệu biến có thể giải trong vài giây, trong khi một bài SDP vài nghìn biến đã đòi hỏi bộ nhớ khổng lồ. Biết xếp bài toán vào tầng &lt;strong&gt;thấp nhất có thể&lt;/strong&gt; chính là dấu ấn của người làm tối ưu chuyên nghiệp.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hệ-phân-cấp-các-bài-toán-tối-ưu-hóa-chuẩn&quot;&gt;Kiến thức cần nhớ: Hệ phân cấp các bài toán tối ưu hóa chuẩn&lt;/h2&gt;

&lt;p&gt;Toàn bộ Chương 05 xoay quanh bốn trụ cột phân loại bài toán theo cấu trúc hàm mục tiêu và hình học nón ràng buộc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tầng Đa diện — LP &amp;amp; QP:&lt;/strong&gt; Tập khả thi là đa diện tạo bởi các bất đẳng thức tuyến tính \(Gx \le h\). LP có hàm mục tiêu tuyến tính (nghiệm nằm ở đỉnh đa diện), còn QP có hàm mục tiêu bậc hai lồi (nghiệm có thể nằm trên mặt hoặc phần trong đa diện).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tầng Nón Bậc Hai — QCQP &amp;amp; SOCP:&lt;/strong&gt; Khi ràng buộc có thêm chuẩn Euclidean \(\|Ax + b\|_2 \le c^T x + d\) (nón hình nón kem / Lorentz cone), ta mô hình hóa được bài toán bền vững trước nhiễu ellipsoid, bài toán khoảng cách, và hồi quy có ràng buộc năng lượng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tầng Nón Ma trận — SDP &amp;amp; CP:&lt;/strong&gt; Khi biến quyết định là ma trận đối xứng nửa xác định dương \(X \succeq 0\), ta mở khóa sức mạnh của bất đẳng thức ma trận tuyến tính (LMI) — nền tảng của lý thuyết điều khiển hiện đại, hoàn thiện ma trận và nới lỏng bài toán tổ hợp NP-khó.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cầu nối Thực hành — Mô hình hóa DCP &amp;amp; Thống kê:&lt;/strong&gt; Các mô hình cốt lõi của học máy như Bình phương tối thiểu (Least Squares), Hồi quy tuyến tính, Hồi quy Logistic, Lasso và SVM đều là các trường hợp đặc biệt trong hệ phân cấp này, và ngôn ngữ DCP (CVXPY) tự động biên dịch chúng về đúng bộ giải nón tương ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phân-tầng-cùng-một-bài-toán-khi-thay-đổi-hàm-mục-tiêu-và-ràng-buộc&quot;&gt;Giải thích: Phân tầng cùng một bài toán khi thay đổi hàm mục tiêu và ràng buộc&lt;/h3&gt;

&lt;p&gt;Xét biến quyết định \(x = (x_1, x_2) \in \mathbb{R}^2\) với ngân sách cơ bản \(x_1 + x_2 \le 4,\; x_1, x_2 \ge 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tầng LP:&lt;/strong&gt; \(\min \; (-2x_1 - 3x_2)\) trên tam giác trên. Hàm mục tiêu tuyến tính, ràng buộc tuyến tính. Nghiệm nằm tại đỉnh \((0, 4)\) với \(f^\star = -12\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tầng QP:&lt;/strong&gt; Thêm phạt rủi ro bậc hai: \(\min \; (-2x_1 - 3x_2 + \frac{1}{2}(x_1^2 + x_2^2))\). Gradient bằng 0 tại \((2, 3)\), vi phạm \(2 + 3 = 5 &amp;gt; 4\). Chiếu lên cạnh \(x_1 + x_2 = 4\): thay \(x_2 = 4 - x_1\) cho \(\phi(x_1) = x_1^2 - 3x_1 - 4\), cực tiểu tại \(x_1^\star = 1.5,\; x_2^\star = 2.5\) (nằm giữa cạnh chứ không ở đỉnh!), \(f^\star = -6.25\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tầng SOCP / QCQP:&lt;/strong&gt; Thêm ràng buộc năng lượng tròn \(\sqrt{x_1^2 + x_2^2} \le 2\) (tương đương \(x_1^2 + x_2^2 \le 4\)) với mục tiêu tuyến tính \(\min (-2x_1 - 3x_2)\). Theo Cauchy-Schwarz, \(-2x_1 - 3x_2 \ge -\sqrt{2^2 + 3^2}\sqrt{x_1^2 + x_2^2} = -2\sqrt{13} \approx -7.211\), đạt tại \(x^\star = \frac{2}{\sqrt{13}}(2, 3) \approx (1.109, 1.664)\) (thỏa \(x_1 + x_2 \approx 2.773 \le 4\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài học rút ra:&lt;/strong&gt; Chỉ cần nhìn bậc của hàm mục tiêu và loại nón của ràng buộc, bạn biết ngay tầng nhỏ nhất cần gọi bộ giải!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;các-bài-toán-chuẩn&quot;&gt;Các Bài Toán Chuẩn&lt;/h1&gt;

&lt;p&gt;Trong &lt;a href=&quot;/chapter01/2021/01/07/optimization_problems/&quot;&gt;Chương 1&lt;/a&gt;, ta đã biết một bài toán tối ưu hóa lồi dạng chuẩn được định nghĩa như sau:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter05/05_00_optimization_problem.png&quot; alt=&quot;[Fig1] Bài toán tối ưu lồi ở dạng chuẩn [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Bài toán tối ưu lồi ở dạng chuẩn [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Miền xác định là tập lồi.&lt;/li&gt;
  &lt;li&gt;Hàm mục tiêu \(f\) và các hàm ràng buộc bất đẳng thức \(g_i\) là các hàm lồi.&lt;/li&gt;
  &lt;li&gt;Các hàm ràng buộc đẳng thức \(h_j\) là các hàm affine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tùy vào cấu trúc của hàm mục tiêu và các hàm ràng buộc, các bài toán tối ưu hóa lồi được phân loại thành nhiều lớp chuẩn khác nhau. Chương này trình bày sáu lớp bài toán tiêu biểu:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Quy hoạch tuyến tính (Linear Programming - LP)&lt;/li&gt;
  &lt;li&gt;Quy hoạch bậc hai (Quadratic Programming - QP)&lt;/li&gt;
  &lt;li&gt;Quy hoạch bậc hai có ràng buộc bậc hai (Quadratically Constrained Quadratic Programming - QCQP)&lt;/li&gt;
  &lt;li&gt;Quy hoạch nón bậc hai (Second-Order Cone Programming - SOCP)&lt;/li&gt;
  &lt;li&gt;Quy hoạch nửa xác định (Semidefinite Programming - SDP)&lt;/li&gt;
  &lt;li&gt;Quy hoạch nón (Conic Programming - CP)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sáu lớp bài toán này tạo thành một hệ thống phân cấp bao hàm, với mức độ tổng quát tăng dần từ trái sang phải:&lt;/p&gt;

&lt;p&gt;\(LP \subseteq QP \subseteq QCQP \subseteq SOCP \subseteq SDP \subseteq CP\)&lt;/p&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter05/05_00_canonical_problems.jpeg&quot; alt=&quot;[Fig2] Các Bài Toán Chuẩn&quot; width=&quot;90%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Các Bài Toán Chuẩn&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Sau phần phân loại và bài thực hành DCP/CVXPY, bài tùy chọn &lt;a href=&quot;/contents/vi/chapter05/05_08_Applications_Recent/&quot;&gt;05-08 Ứng dụng và phát triển gần đây&lt;/a&gt; giới thiệu các ứng dụng hiện đại gắn với những dạng chuẩn này, bao gồm bộ giải Clarabel, bài toán QP tối ưu hóa danh mục đầu tư, nới lỏng SDP trong kiểm chứng mạng nơ-ron và khôi phục thưa bằng khai triển thuật toán.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01-05 Siêu phẳng</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_05_Hyperplane/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_05_Hyperplane</id>
   <content type="html">&lt;p&gt;Trong mặt phẳng 2D, một đường thẳng cắt đôi toàn bộ không gian thành hai phía; trong không gian 3D, một mặt phẳng làm nhiệm vụ tương tự. Khi bước sang không gian \(n\) chiều của học máy và tối ưu hóa, “lưỡi dao phẳng” cắt đôi \(\mathbb{R}^n\) chính là &lt;strong&gt;siêu phẳng&lt;/strong&gt; (hyperplane): \(\{x \in \mathbb{R}^n : a^T x = b\}\) với \(a \ne 0\).&lt;/p&gt;

&lt;p&gt;Đó không chỉ là viên gạch tạo nên đa diện trong quy hoạch tuyến tính, mà còn chính là ranh giới quyết định của Máy vector hỗ trợ (SVM), hồi quy logistic và mỗi nơ-ron tuyến tính trong mạng học sâu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-góc-nhìn-về-siêu-phẳng-at-x--b&quot;&gt;Kiến thức cần nhớ: Bốn góc nhìn về Siêu phẳng \(a^T x = b\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa hình học trực giao:&lt;/strong&gt; Viết lại phương trình thành \(a^T (x - x_0) = 0\) (với \(a^T x_0 = b\)): siêu phẳng là tập mọi điểm \(x\) sao cho vector \(x - x_0\) &lt;strong&gt;vuông góc&lt;/strong&gt; với vector pháp tuyến \(a\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất vừa affine, vừa lồi, vừa đóng:&lt;/strong&gt; Vì là tập nghiệm của một phương trình tuyến tính duy nhất, siêu phẳng có chiều \(n - 1\) và luôn là tập affine đóng (kéo theo lồi).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Khoảng cách có dấu và phép chiếu trực giao:&lt;/strong&gt; Khoảng cách từ điểm \(x_0\) bất kỳ đến siêu phẳng \(a^T x = b\) là $$d(x_0, H) = \frac{&lt;/td&gt;
          &lt;td&gt;a^T x_0 - b&lt;/td&gt;
          &lt;td&gt;}{|a|&lt;em&gt;2}\(, và hình chiếu gần nhất là\)x&lt;/em&gt;{\text{proj}} = x_0 - \frac{a^T x_0 - b}{|a|_2^2} a$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chia không gian thành hai nửa không gian:&lt;/strong&gt; Bất đẳng thức \(a^T x \le b\) và \(a^T x \ge b\) tạo ra hai nửa không gian đóng (đều là tập lồi) nằm hai phía đối diện của siêu phẳng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-khoảng-cách-và-hình-chiếu-vuông-góc-lên-siêu-phẳng-3x_1--4x_2--10&quot;&gt;Giải thích: Tính khoảng cách và hình chiếu vuông góc lên siêu phẳng \(3x_1 + 4x_2 = 10\)&lt;/h3&gt;

&lt;p&gt;Xét siêu phẳng (đường thẳng trong \(\mathbb{R}^2\)) \(H = \{x : a^T x = b\}\) với \(a = (3, 4)^T,\ b = 10\), và điểm gốc \(x_0 = (0, 0)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính chuẩn vector pháp tuyến:&lt;/strong&gt;
\(\|a\|_2 = \sqrt{3^2 + 4^2} = \sqrt{25} = 5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính khoảng cách ngắn nhất từ \(x_0 = (0, 0)\) tới \(H\):&lt;/strong&gt;
\(d(x_0, H) = \frac{|a^T x_0 - b|}{\|a\|_2} = \frac{|0 - 10|}{5} = 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm hình chiếu \(x^* \in H\) gần gốc tọa độ nhất:&lt;/strong&gt;
\(x^* = x_0 - \frac{a^T x_0 - b}{\|a\|_2^2} a = (0, 0)^T - \frac{-10}{25}\begin{pmatrix}3\\ 4\end{pmatrix} = \frac{2}{5}\begin{pmatrix}3\\ 4\end{pmatrix} = \begin{pmatrix}1.2\\ 1.6\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra hai điều kiện vàng:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Thuộc siêu phẳng: \(3(1.2) + 4(1.6) = 3.6 + 6.4 = 10 = b\) (đúng!).&lt;/li&gt;
      &lt;li&gt;Khoảng cách đúng bằng \(2\): \(\|x^* - x_0\|_2 = \sqrt{1.2^2 + 1.6^2} = \sqrt{1.44 + 2.56} = \sqrt{4} = 2\) (khớp tuyệt đối!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Siêu phẳng là một trong những đối tượng hình học cơ bản nhất trong tối ưu hóa lồi và đại số tuyến tính. Nó đóng vai trò nền tảng để xây dựng các tập lồi phức tạp hơn, đồng thời xuất hiện thường xuyên trong các thuật toán tối ưu hóa, học máy và phân tích hình học.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa-siêu-phẳng&quot;&gt;Định nghĩa siêu phẳng&lt;/h2&gt;

&lt;p&gt;Một &lt;strong&gt;siêu phẳng&lt;/strong&gt; trong \(\mathbb{R}^n\) là tập hợp có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\mathcal{H} = \{x \in \mathbb{R}^n : a^T x = b\}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(a \in \mathbb{R}^n\) là vector khác không (\(a \neq 0\)) và \(b \in \mathbb{R}\) là một số thực.&lt;/p&gt;

&lt;p&gt;Vector \(a\) được gọi là &lt;strong&gt;vector pháp tuyến&lt;/strong&gt; của siêu phẳng, xác định phương của siêu phẳng; còn số thực \(b\) xác định vị trí của siêu phẳng so với gốc tọa độ.&lt;/p&gt;

&lt;h3 id=&quot;ý-nghĩa-hình-học&quot;&gt;Ý nghĩa hình học&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Trong \(\mathbb{R}^2\): siêu phẳng là một &lt;strong&gt;đường thẳng&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Trong \(\mathbb{R}^3\): siêu phẳng là một &lt;strong&gt;mặt phẳng&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Trong \(\mathbb{R}^n\) (\(n &amp;gt; 3\)): siêu phẳng là một tập affine có chiều \((n-1)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Siêu phẳng chia không gian \(\mathbb{R}^n\) thành hai &lt;strong&gt;nửa không gian&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nửa không gian dương&lt;/strong&gt;: \(\{x : a^T x \geq b\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nửa không gian âm&lt;/strong&gt;: \(\{x : a^T x \leq b\}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;tính-chất-của-siêu-phẳng&quot;&gt;Tính chất của siêu phẳng&lt;/h2&gt;

&lt;h3 id=&quot;1-tính-chất-tập-affine&quot;&gt;1. Tính chất tập affine&lt;/h3&gt;
&lt;p&gt;Mọi siêu phẳng đều là &lt;strong&gt;tập affine&lt;/strong&gt;: nếu \(x_1, x_2 \in \mathcal{H}\) thì toàn bộ đường thẳng đi qua hai điểm này cũng nằm trong \(\mathcal{H}\):&lt;/p&gt;

\[\theta x_1 + (1-\theta) x_2 \in \mathcal{H} \quad \forall \theta \in \mathbb{R}\]

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh&lt;/strong&gt;: Nếu \(a^T x_1 = b\) và \(a^T x_2 = b\), thì:
\(a^T(\theta x_1 + (1-\theta) x_2) = \theta a^T x_1 + (1-\theta) a^T x_2 = \theta b + (1-\theta) b = b\)&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;2-tính-chất-tập-lồi&quot;&gt;2. Tính chất tập lồi&lt;/h3&gt;
&lt;p&gt;Vì mọi tập affine đều lồi, nên siêu phẳng cũng là &lt;strong&gt;tập lồi&lt;/strong&gt;: với mọi \(x_1, x_2 \in \mathcal{H}\) và \(\lambda \in [0,1]\), ta có:&lt;/p&gt;

\[\lambda x_1 + (1-\lambda) x_2 \in \mathcal{H}\]

&lt;h3 id=&quot;3-tính-chất-tập-đóng&quot;&gt;3. Tính chất tập đóng&lt;/h3&gt;
&lt;p&gt;Siêu phẳng là &lt;strong&gt;tập đóng&lt;/strong&gt; vì nó là tập mức của một hàm tuyến tính liên tục.&lt;/p&gt;

&lt;h3 id=&quot;4-số-chiều&quot;&gt;4. Số chiều&lt;/h3&gt;
&lt;p&gt;Một siêu phẳng trong \(\mathbb{R}^n\) có số chiều bằng \(n-1\).&lt;/p&gt;

&lt;h2 id=&quot;các-cách-biểu-diễn-khác&quot;&gt;Các cách biểu diễn khác&lt;/h2&gt;

&lt;h3 id=&quot;1-dạng-điểm--pháp-tuyến&quot;&gt;1. Dạng điểm – pháp tuyến&lt;/h3&gt;
&lt;p&gt;Khi biết một điểm \(x_0\) nằm trên siêu phẳng và vector pháp tuyến \(a\), siêu phẳng có thể viết dưới dạng:&lt;/p&gt;

\[\mathcal{H} = \{x : a^T (x - x_0) = 0\}\]

&lt;p&gt;Biểu thức này tương đương với \(a^T x = a^T x_0\), tức là \(b = a^T x_0\).&lt;/p&gt;

&lt;h3 id=&quot;2-dạng-ma-trận&quot;&gt;2. Dạng ma trận&lt;/h3&gt;
&lt;p&gt;Nếu coi \(A\) là ma trận cỡ \(1 \times n\) (vector hàng \(a^T\)), siêu phẳng được viết là:&lt;/p&gt;

\[\mathcal{H} = \{x : Ax = b\}\]

&lt;h3 id=&quot;3-dạng-tham-số&quot;&gt;3. Dạng tham số&lt;/h3&gt;
&lt;p&gt;Nếu \(\{v_1, v_2, \ldots, v_{n-1}\}\) là một cơ sở trực chuẩn cho không gian hạt nhân (null space) của \(a^T\) và \(x_0\) là một điểm bất kỳ thuộc siêu phẳng, thì:&lt;/p&gt;

\[\mathcal{H} = \{x_0 + t_1 v_1 + t_2 v_2 + \cdots + t_{n-1} v_{n-1} : t_i \in \mathbb{R}\}\]

&lt;h2 id=&quot;khoảng-cách-từ-điểm-đến-siêu-phẳng&quot;&gt;Khoảng cách từ điểm đến siêu phẳng&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Khoảng cách&lt;/strong&gt; từ một điểm \(x_0\) đến siêu phẳng \(\{x : a^T x = b\}\) được tính bởi:&lt;/p&gt;

\[d(x_0, \mathcal{H}) = \frac{\lvert a^T x_0 - b \rvert}{\lVert a \rVert_2}\]

&lt;p&gt;Công thức này thu được bằng cách chiếu vector nối từ một điểm bất kỳ trên siêu phẳng tới \(x_0\) lên phương pháp tuyến.&lt;/p&gt;

&lt;h3 id=&quot;chứng-minh-công-thức&quot;&gt;Chứng minh công thức&lt;/h3&gt;
&lt;p&gt;Gọi \(x^*\) là điểm trên siêu phẳng gần \(x_0\) nhất. Khi đó vector \(x^* - x_0\) song song với vector pháp tuyến \(a\):&lt;/p&gt;

\[x^* - x_0 = t \frac{a}{\lVert a \rVert_2}\]

&lt;p&gt;Vì \(x^* \in \mathcal{H}\) nên \(a^T x^* = b\). Thay \(x^*\) vào ta có:&lt;/p&gt;

\[a^T \left(x_0 + t \frac{a}{\lVert a \rVert_2}\right) = b\]

&lt;p&gt;Giải phương trình theo \(t\) thu được \(t = \frac{b - a^T x_0}{\lVert a \rVert_2}\), do đó khoảng cách là \(\lvert t \rvert = \frac{\lvert a^T x_0 - b \rvert}{\lVert a \rVert_2}\).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;h3 id=&quot;ví-dụ-1-đường-thẳng-trong-mathbbr2&quot;&gt;Ví dụ 1: Đường thẳng trong \(\mathbb{R}^2\)&lt;/h3&gt;
&lt;p&gt;Siêu phẳng \(2x_1 + 3x_2 = 6\) biểu diễn một đường thẳng trong mặt phẳng:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Vector pháp tuyến: \(a = (2, 3)\)&lt;/li&gt;
  &lt;li&gt;Đường thẳng đi qua hai điểm \((3, 0)\) và \((0, 2)\)&lt;/li&gt;
  &lt;li&gt;Khoảng cách từ gốc tọa độ đến đường thẳng: \(\frac{\lvert 2 \cdot 0 + 3 \cdot 0 - 6 \rvert}{\sqrt{2^2 + 3^2}} = \frac{6}{\sqrt{13}}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-2-mặt-phẳng-trong-mathbbr3&quot;&gt;Ví dụ 2: Mặt phẳng trong \(\mathbb{R}^3\)&lt;/h3&gt;
&lt;p&gt;Siêu phẳng \(x_1 - 2x_2 + x_3 = 4\) biểu diễn một mặt phẳng trong không gian ba chiều:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Vector pháp tuyến: \(a = (1, -2, 1)\)&lt;/li&gt;
  &lt;li&gt;Mặt phẳng đi qua các điểm \((4, 0, 0)\), \((0, -2, 0)\) và \((0, 0, 4)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-3-siêu-phẳng-đi-qua-gốc-tọa-độ&quot;&gt;Ví dụ 3: Siêu phẳng đi qua gốc tọa độ&lt;/h3&gt;
&lt;p&gt;Siêu phẳng \(a^T x = 0\) luôn đi qua gốc tọa độ và là một &lt;strong&gt;không gian con tuyến tính&lt;/strong&gt; có chiều \(n-1\).&lt;/p&gt;

&lt;h2 id=&quot;mối-quan-hệ-với-các-khái-niệm-khác&quot;&gt;Mối quan hệ với các khái niệm khác&lt;/h2&gt;

&lt;h3 id=&quot;liên-hệ-với-tập-affine&quot;&gt;Liên hệ với tập affine&lt;/h3&gt;
&lt;p&gt;Mọi siêu phẳng đều là tập affine, nhưng không phải mọi tập affine đều là siêu phẳng. Cụ thể, siêu phẳng là các tập affine có chiều \((n-1)\) trong \(\mathbb{R}^n\).&lt;/p&gt;

&lt;h3 id=&quot;liên-hệ-với-đại-số-tuyến-tính&quot;&gt;Liên hệ với đại số tuyến tính&lt;/h3&gt;
&lt;p&gt;Siêu phẳng \(\{x : a^T x = b\}\) là &lt;strong&gt;tập mức&lt;/strong&gt; của hàm tuyến tính \(f(x) = a^T x\) tại mức \(b\). Gradient của hàm này không đổi và bằng \(a\), giải thích vì sao \(a\) luôn vuông góc với siêu phẳng.&lt;/p&gt;

&lt;h3 id=&quot;liên-hệ-với-tối-ưu-hóa&quot;&gt;Liên hệ với tối ưu hóa&lt;/h3&gt;
&lt;p&gt;Trong tối ưu hóa có ràng buộc, các ràng buộc đẳng thức tuyến tính thường xác định các siêu phẳng giới hạn miền khả thi. Phương pháp nhân tử Lagrange khai thác tính chất tại điểm tối ưu, gradient của hàm mục tiêu song song với vector pháp tuyến của siêu phẳng ràng buộc.&lt;/p&gt;

&lt;h2 id=&quot;trực-quan-hóa-tương-tác&quot;&gt;Trực quan hóa tương tác&lt;/h2&gt;

&lt;div id=&quot;hyperplane-container&quot; style=&quot;width: 100%; max-width: 800px; margin: 20px auto;&quot;&gt;
    &lt;div id=&quot;controls&quot; style=&quot;margin-bottom: 20px; text-align: center;&quot;&gt;
        &lt;label&gt;Normal vector a₁: &lt;input type=&quot;range&quot; id=&quot;a1-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;&lt;/label&gt;
        &lt;span id=&quot;a1-value&quot;&gt;1.0&lt;/span&gt;&lt;br /&gt;
        &lt;label&gt;Normal vector a₂: &lt;input type=&quot;range&quot; id=&quot;a2-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;&lt;/label&gt;
        &lt;span id=&quot;a2-value&quot;&gt;1.0&lt;/span&gt;&lt;br /&gt;
        &lt;label&gt;Offset b: &lt;input type=&quot;range&quot; id=&quot;b-slider&quot; min=&quot;-5&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;0&quot; /&gt;&lt;/label&gt;
        &lt;span id=&quot;b-value&quot;&gt;0.0&lt;/span&gt;&lt;br /&gt;
        &lt;button id=&quot;reset-btn&quot;&gt;Reset&lt;/button&gt;
    &lt;/div&gt;
    &lt;canvas id=&quot;hyperplane-canvas&quot; width=&quot;600&quot; height=&quot;400&quot; style=&quot;border: 1px solid #ccc; display: block; margin: 0 auto;&quot;&gt;&lt;/canvas&gt;
    &lt;div id=&quot;info&quot; style=&quot;text-align: center; margin-top: 10px; font-family: monospace;&quot;&gt;
        &lt;p&gt;Hyperplane equation: &lt;span id=&quot;equation&quot;&gt;x₁ + x₂ = 0&lt;/span&gt;&lt;/p&gt;
        &lt;p&gt;Distance from origin: &lt;span id=&quot;distance&quot;&gt;0.0&lt;/span&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
class HyperplaneVisualizer {
    constructor() {
        this.canvas = document.getElementById(&apos;hyperplane-canvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        // Parameters
        this.a1 = 1;
        this.a2 = 1;
        this.b = 0;
        
        // Scale and offset for coordinate system
        this.scale = 40;
        this.centerX = this.width / 2;
        this.centerY = this.height / 2;
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const a1Slider = document.getElementById(&apos;a1-slider&apos;);
        const a2Slider = document.getElementById(&apos;a2-slider&apos;);
        const bSlider = document.getElementById(&apos;b-slider&apos;);
        const resetBtn = document.getElementById(&apos;reset-btn&apos;);
        
        a1Slider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.a1 = parseFloat(e.target.value);
            document.getElementById(&apos;a1-value&apos;).textContent = this.a1.toFixed(1);
            this.updateDisplay();
        });
        
        a2Slider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.a2 = parseFloat(e.target.value);
            document.getElementById(&apos;a2-value&apos;).textContent = this.a2.toFixed(1);
            this.updateDisplay();
        });
        
        bSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.b = parseFloat(e.target.value);
            document.getElementById(&apos;b-value&apos;).textContent = this.b.toFixed(1);
            this.updateDisplay();
        });
        
        resetBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.a1 = 1;
            this.a2 = 1;
            this.b = 0;
            a1Slider.value = 1;
            a2Slider.value = 1;
            bSlider.value = 0;
            document.getElementById(&apos;a1-value&apos;).textContent = &apos;1.0&apos;;
            document.getElementById(&apos;a2-value&apos;).textContent = &apos;1.0&apos;;
            document.getElementById(&apos;b-value&apos;).textContent = &apos;0.0&apos;;
            this.updateDisplay();
        });
    }
    
    updateDisplay() {
        this.draw();
        this.updateInfo();
    }
    
    updateInfo() {
        // Update equation
        const eq = `${this.a1.toFixed(1)}x₁ + ${this.a2.toFixed(1)}x₂ = ${this.b.toFixed(1)}`;
        document.getElementById(&apos;equation&apos;).textContent = eq;
        
        // Update distance from origin
        const distance = Math.abs(this.b) / Math.sqrt(this.a1 * this.a1 + this.a2 * this.a2);
        document.getElementById(&apos;distance&apos;).textContent = distance.toFixed(3);
    }
    
    worldToScreen(x, y) {
        return {
            x: this.centerX + x * this.scale,
            y: this.centerY - y * this.scale
        };
    }
    
    draw() {
        // Clear canvas
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        // Draw coordinate system
        this.drawCoordinateSystem();
        
        // Draw hyperplane (line in 2D)
        this.drawHyperplane();
        
        // Draw normal vector
        this.drawNormalVector();
        
        // Draw distance from origin
        this.drawDistanceFromOrigin();
    }
    
    drawCoordinateSystem() {
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        
        // Grid lines
        for (let i = -10; i &lt;= 10; i++) {
            if (i === 0) continue;
            
            // Vertical lines
            const x = this.centerX + i * this.scale;
            this.ctx.beginPath();
            this.ctx.moveTo(x, 0);
            this.ctx.lineTo(x, this.height);
            this.ctx.stroke();
            
            // Horizontal lines
            const y = this.centerY + i * this.scale;
            this.ctx.beginPath();
            this.ctx.moveTo(0, y);
            this.ctx.lineTo(this.width, y);
            this.ctx.stroke();
        }
        
        // Axes
        this.ctx.strokeStyle = &apos;#666&apos;;
        this.ctx.lineWidth = 2;
        
        // X-axis
        this.ctx.beginPath();
        this.ctx.moveTo(0, this.centerY);
        this.ctx.lineTo(this.width, this.centerY);
        this.ctx.stroke();
        
        // Y-axis
        this.ctx.beginPath();
        this.ctx.moveTo(this.centerX, 0);
        this.ctx.lineTo(this.centerX, this.height);
        this.ctx.stroke();
        
        // Labels
        this.ctx.fillStyle = &apos;#666&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.fillText(&apos;x₁&apos;, this.width - 20, this.centerY - 10);
        this.ctx.fillText(&apos;x₂&apos;, this.centerX + 10, 15);
    }
    
    drawHyperplane() {
        if (Math.abs(this.a1) &lt; 1e-10 &amp;&amp; Math.abs(this.a2) &lt; 1e-10) return;
        
        this.ctx.strokeStyle = &apos;#2196F3&apos;;
        this.ctx.lineWidth = 3;
        
        // Find two points on the line a1*x1 + a2*x2 = b
        let x1_start, y1_start, x1_end, y1_end;
        
        if (Math.abs(this.a2) &gt; 1e-10) {
            // Line is not vertical
            x1_start = -10;
            y1_start = (this.b - this.a1 * x1_start) / this.a2;
            x1_end = 10;
            y1_end = (this.b - this.a1 * x1_end) / this.a2;
        } else {
            // Line is vertical
            x1_start = x1_end = this.b / this.a1;
            y1_start = -10;
            y1_end = 10;
        }
        
        const start = this.worldToScreen(x1_start, y1_start);
        const end = this.worldToScreen(x1_end, y1_end);
        
        this.ctx.beginPath();
        this.ctx.moveTo(start.x, start.y);
        this.ctx.lineTo(end.x, end.y);
        this.ctx.stroke();
        
        // Label
        const midX = (start.x + end.x) / 2;
        const midY = (start.y + end.y) / 2;
        this.ctx.fillStyle = &apos;#2196F3&apos;;
        this.ctx.font = &apos;bold 14px Arial&apos;;
        this.ctx.fillText(&apos;Hyperplane&apos;, midX + 10, midY - 10);
    }
    
    drawNormalVector() {
        if (Math.abs(this.a1) &lt; 1e-10 &amp;&amp; Math.abs(this.a2) &lt; 1e-10) return;
        
        // Normalize the normal vector for display
        const norm = Math.sqrt(this.a1 * this.a1 + this.a2 * this.a2);
        const na1 = this.a1 / norm;
        const na2 = this.a2 / norm;
        
        // Find a point on the hyperplane closest to origin
        const t = this.b / (this.a1 * this.a1 + this.a2 * this.a2);
        const px = t * this.a1;
        const py = t * this.a2;
        
        const startPoint = this.worldToScreen(px, py);
        const endPoint = this.worldToScreen(px + na1 * 2, py + na2 * 2);
        
        // Draw normal vector
        this.ctx.strokeStyle = &apos;#FF5722&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        this.ctx.moveTo(startPoint.x, startPoint.y);
        this.ctx.lineTo(endPoint.x, endPoint.y);
        this.ctx.stroke();
        
        // Draw arrowhead
        const angle = Math.atan2(endPoint.y - startPoint.y, endPoint.x - startPoint.x);
        const arrowLength = 10;
        this.ctx.beginPath();
        this.ctx.moveTo(endPoint.x, endPoint.y);
        this.ctx.lineTo(
            endPoint.x - arrowLength * Math.cos(angle - Math.PI / 6),
            endPoint.y - arrowLength * Math.sin(angle - Math.PI / 6)
        );
        this.ctx.moveTo(endPoint.x, endPoint.y);
        this.ctx.lineTo(
            endPoint.x - arrowLength * Math.cos(angle + Math.PI / 6),
            endPoint.y - arrowLength * Math.sin(angle + Math.PI / 6)
        );
        this.ctx.stroke();
        
        // Label
        this.ctx.fillStyle = &apos;#FF5722&apos;;
        this.ctx.font = &apos;bold 12px Arial&apos;;
        this.ctx.fillText(&apos;Normal vector a&apos;, endPoint.x + 5, endPoint.y - 5);
    }
    
    drawDistanceFromOrigin() {
        if (Math.abs(this.a1) &lt; 1e-10 &amp;&amp; Math.abs(this.a2) &lt; 1e-10) return;
        
        // Find closest point on hyperplane to origin
        const t = this.b / (this.a1 * this.a1 + this.a2 * this.a2);
        const px = t * this.a1;
        const py = t * this.a2;
        
        const origin = this.worldToScreen(0, 0);
        const closestPoint = this.worldToScreen(px, py);
        
        // Draw distance line
        this.ctx.strokeStyle = &apos;#4CAF50&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.setLineDash([5, 5]);
        this.ctx.beginPath();
        this.ctx.moveTo(origin.x, origin.y);
        this.ctx.lineTo(closestPoint.x, closestPoint.y);
        this.ctx.stroke();
        this.ctx.setLineDash([]);
        
        // Draw origin point
        this.ctx.fillStyle = &apos;#4CAF50&apos;;
        this.ctx.beginPath();
        this.ctx.arc(origin.x, origin.y, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Draw closest point
        this.ctx.beginPath();
        this.ctx.arc(closestPoint.x, closestPoint.y, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Label
        const midX = (origin.x + closestPoint.x) / 2;
        const midY = (origin.y + closestPoint.y) / 2;
        this.ctx.fillStyle = &apos;#4CAF50&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.fillText(&apos;Distance&apos;, midX + 5, midY + 5);
    }
}

// Initialize visualization when page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    new HyperplaneVisualizer();
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>02-01-04 Hình Nón</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_04_Convex_cone/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_04_Convex_cone</id>
   <content type="html">&lt;p&gt;Khi bạn chiếu một chiếc đèn pin trong bóng tối, chùm sáng tạo thành một hình chóp mở rộng vô tận ra xa: bất kỳ điểm nào nằm trong chùm sáng nếu kéo dài gấp đôi hay thu ngắn còn một nửa dọc theo tia từ bóng đèn thì vẫn nằm trong chùm sáng. Đó chính là trực giác của &lt;strong&gt;hình nón&lt;/strong&gt; (cone) — và nếu chùm sáng đó không bị khuyết lõm, ta có &lt;strong&gt;hình nón lồi&lt;/strong&gt; (convex cone).&lt;/p&gt;

&lt;p&gt;Hình nón lồi là xương sống của tối ưu hóa nón hiện đại (Conic Optimization), thống nhất cả Quy hoạch tuyến tính (nón \(\mathbb{R}_+^n\)), Quy hoạch nón bậc hai (SOCP) và Quy hoạch bán xác định (SDP) dưới một mái nhà duy nhất.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-phân-biệt-hình-nón-và-hình-nón-lồi&quot;&gt;Kiến thức cần nhớ: Phân biệt Hình Nón và Hình Nón Lồi&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/chapter02/02.04_1_Conic_hull.png&quot; alt=&quot;Bao nón (Conic Hull) của tập hợp&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hình nón (Cone):&lt;/strong&gt; Tập \(C\) đóng dưới phép nhân vô hướng không âm: \(x \in C,\ \theta \ge 0 \implies \theta x \in C\). Một hình nón chưa chắc đã lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình nón lồi (Convex Cone):&lt;/strong&gt; Vừa là hình nón vừa là tập lồi, tương đương với tính đóng dưới mọi &lt;strong&gt;tổ hợp nón&lt;/strong&gt;: \(x_1, x_2 \in C,\ \theta_1, \theta_2 \ge 0 \implies \theta_1 x_1 + \theta_2 x_2 \in C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bao nón (Conic Hull):&lt;/strong&gt; Tập tất cả các tổ hợp nón của các phần tử trong \(S\) — chính là hình nón lồi nhỏ nhất chứa \(S\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vai trò trong tối ưu hóa:&lt;/strong&gt; Hình nón lồi dùng để định nghĩa &lt;strong&gt;bất đẳng thức tổng quát&lt;/strong&gt; (như \(A \succeq 0\) trên ma trận) và xây dựng bài toán đối ngẫu nón tổng quát.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-một-hình-nón-không-lồi-so-với-hình-nón-lồi-trong-mathbbr2&quot;&gt;Giải thích: Một hình nón KHÔNG lồi so với hình nón lồi trong \(\mathbb{R}^2\)&lt;/h3&gt;

&lt;p&gt;So sánh hai tập hợp trong \(\mathbb{R}^2\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tập \(U = \{(x_1, 0) : x_1 \ge 0\} \cup \{(0, x_2) : x_2 \ge 0\}\) (hợp của hai nửa trục tọa độ dương).&lt;/li&gt;
  &lt;li&gt;Tập \(K = \{(x_1, x_2) : x_1 \ge 0,\ x_2 \ge 0\} = \mathbb{R}_+^2\) (góc phần tư thứ nhất).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra \(U\) là hình nón nhưng KHÔNG lồi:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Lấy bất kỳ \(x \in U\) (ví dụ \((3, 0)\)) và \(\theta \ge 0\): \(\theta(3, 0) = (3\theta, 0) \in U\). Vậy \(U\) là &lt;strong&gt;hình nón&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Nhưng lấy \(x_1 = (1, 0) \in U\) và \(x_2 = (0, 1) \in U\) với \(\theta_1 = \theta_2 = 1 &amp;gt; 0\):
\(\theta_1 x_1 + \theta_2 x_2 = (1, 0) + (0, 1) = (1, 1) \notin U.\)
Vậy \(U\) &lt;strong&gt;không phải&lt;/strong&gt; hình nón lồi!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lấy bao nón của \(U\):&lt;/strong&gt; Mọi tổ hợp nón \(\theta_1(1, 0) + \theta_2(0, 1) = (\theta_1, \theta_2)\) với \(\theta_1, \theta_2 \ge 0\) lấp đầy trọn vẹn góc phần tư thứ nhất: \(\operatorname{cone}(U) = \mathbb{R}_+^2 = K\) — đây mới là &lt;strong&gt;hình nón lồi&lt;/strong&gt; nhỏ nhất chứa \(U\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Hình nón là tập hợp kéo dài vô hạn theo những hướng nhất định, tương tự chùm tia sáng phát ra từ một nguồn, nhưng không nhất thiết mở rộng theo hướng ngược lại. Để kiểm tra một tập hợp có phải là hình nón hay không, ta xem tia xuất phát từ gốc tọa độ đi qua một điểm bất kỳ trong tập hợp có nằm trọn trong tập hợp đó hay không. (Do đó, mọi hình nón khác rỗng đều chứa gốc tọa độ.) Thông thường hình nón có biên chặn nên không phải là tập affine. Sau đây là định nghĩa toán học cụ thể.&lt;/p&gt;

&lt;h2 id=&quot;hình-nón&quot;&gt;Hình Nón&lt;/h2&gt;

&lt;p&gt;Một tập \(C\) được gọi là &lt;strong&gt;hình nón&lt;/strong&gt; (hay &lt;strong&gt;tập thuần nhất không âm&lt;/strong&gt;) nếu với mọi \(x \in C\) và \(\theta \ge 0\), điểm \(\theta x\) cũng thuộc \(C\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\theta x \in C\) với \(x \in C\), \(\theta \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Lưu ý:&lt;/em&gt; Khác với tập affine hay tập lồi, định nghĩa hình nón lấy gốc tọa độ làm điểm xuất phát của tia nên chỉ cần xét một điểm \(x \in C\).&lt;/p&gt;

&lt;h2 id=&quot;hình-nón-lồi&quot;&gt;Hình Nón Lồi&lt;/h2&gt;

&lt;p&gt;Một tập \(C\) được gọi là &lt;strong&gt;hình nón lồi&lt;/strong&gt; nếu nó vừa là hình nón vừa là tập lồi, tương đương với điều kiện:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\theta_1 x_1 + \theta_2 x_2 \in C\) với \(x_1, x_2 \in C\), \(\theta_1, \theta_2 \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hình dưới đây minh họa một hình nón lồi dạng hình quạt, với \(x_1, x_2\) là các điểm trong hình nón và \(\theta_1, \theta_2\) là các số thực không âm.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.04_Convex_Cone.png&quot; alt=&quot;[Hình1] Hình Nón Lồi [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình1] Hình Nón Lồi [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;tổ-hợp-nón&quot;&gt;Tổ hợp Nón&lt;/h2&gt;

&lt;p&gt;Một tổ hợp tuyến tính của nhiều điểm với mọi hệ số đều không âm được gọi là &lt;strong&gt;tổ hợp nón&lt;/strong&gt; (hay &lt;strong&gt;tổ hợp tuyến tính không âm&lt;/strong&gt;):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Điểm có dạng \(\theta_1 x_1 + \theta_2 x_2 + \cdots + \theta_k x_k\) với \(\theta_i \ge 0, i = 1,  ..., k\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Một tập \(C\) là hình nón lồi khi và chỉ khi mọi tổ hợp nón của các điểm trong \(C\) đều thuộc \(C\).&lt;/p&gt;

&lt;h2 id=&quot;bao-nón&quot;&gt;Bao Nón&lt;/h2&gt;

&lt;p&gt;Tập hợp tất cả các tổ hợp nón của các điểm trong \(C \subseteq \mathbb{R}^n\) được gọi là &lt;strong&gt;bao nón&lt;/strong&gt; của \(C\). Bao nón luôn là hình nón lồi nhỏ nhất chứa \(C\):&lt;/p&gt;
&lt;blockquote&gt;
\[\{ \theta_1 x_1 + \cdots + \theta_k x_k \mid x_i \in C, \theta_i \ge 0, i = 1, ..., k \}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01-03 Tập Lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_03_Convex-set/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_03_Convex-set</id>
   <content type="html">&lt;p&gt;Nếu chỉ được chọn một định nghĩa duy nhất làm linh hồn cho cả khóa học này, đó chính là định nghĩa &lt;strong&gt;tập lồi&lt;/strong&gt;. Từ một điều kiện tưởng chừng bé nhỏ — đoạn thẳng nối hai điểm bất kỳ không được thò ra ngoài tập — nảy sinh hai khái niệm mạnh mẽ đi cùng: &lt;strong&gt;tổ hợp lồi&lt;/strong&gt; (trọng tâm có trọng số không âm) và &lt;strong&gt;bao lồi&lt;/strong&gt; (chiếc dây thun căng bọc quanh một đám mây điểm).&lt;/p&gt;

&lt;p&gt;Hiểu thấu tập lồi và bao lồi giúp bạn giải thích ngay vì sao trong quy hoạch tuyến tính, cực trị luôn đạt tại các điểm cực biên (đỉnh) của bao lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-tầng-khái-niệm-quanh-tập-lồi&quot;&gt;Kiến thức cần nhớ: Ba tầng khái niệm quanh Tập Lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tập lồi (Convex Set):&lt;/strong&gt; Đóng dưới mọi tổ hợp lồi 2 điểm \(\theta x_1 + (1-\theta)x_2\) với \(\theta \in [0, 1]\). Mọi tập affine đều là tập lồi, nhưng đa số tập lồi (như hình tròn, hình vuông) không phải tập affine.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp lồi (Convex Combination):&lt;/strong&gt; Mở rộng cho \(k\) điểm: \(x = \sum_{i=1}^k \theta_i x_i\) với \(\theta_i \ge 0,\ \sum \theta_i = 1\). Về vật lý, đó là &lt;strong&gt;tâm khối&lt;/strong&gt; khi đặt các khối lượng không âm \(\theta_i\) tại các vị trí \(x_i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bao lồi (Convex Hull — \(\operatorname{conv} S\)):&lt;/strong&gt; Tập lồi nhỏ nhất chứa \(S\), đúng bằng tập tất cả các tổ hợp lồi của các điểm thuộc \(S\). Trong tối ưu hóa tổ hợp, ta thường nới lỏng (relax) tập nghiệm rời rạc \(S\) sang \(\operatorname{conv} S\) để giải bằng bài toán lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-tra-điểm-có-nằm-trong-bao-lồi-của-3-đỉnh-tam-giác-không&quot;&gt;Giải thích: Kiểm tra điểm có nằm trong bao lồi của 3 đỉnh tam giác không&lt;/h3&gt;

&lt;p&gt;Xét tập rời rạc gồm 3 điểm trong \(\mathbb{R}^2\): \(v_1 = (0, 0),\ v_2 = (3, 0),\ v_3 = (0, 3)\). Bao lồi \(\operatorname{conv}\{v_1, v_2, v_3\}\) là tam giác đặc có 3 đỉnh đó. Để kiểm tra một điểm \(p = (p_1, p_2)\) có thuộc bao lồi hay không, ta giải hệ tổ hợp lồi:
\(\theta_1 (0, 0) + \theta_2 (3, 0) + \theta_3 (0, 3) = (p_1, p_2), \qquad \theta_1 + \theta_2 + \theta_3 = 1.\)
Từ hệ này suy ra ngay \(\theta_2 = \frac{p_1}{3},\ \theta_3 = \frac{p_2}{3},\ \theta_1 = 1 - \frac{p_1 + p_2}{3}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thử điểm \(p = (1, 1)\):&lt;/strong&gt;
\(\theta_2 = \frac{1}{3},\quad \theta_3 = \frac{1}{3},\quad \theta_1 = 1 - \frac{2}{3} = \frac{1}{3}.\)
Cả ba trọng số đều \(\ge 0\) và có tổng bằng \(1\) \(\implies\) \(p = (1, 1) \in \operatorname{conv}\{v_1, v_2, v_3\}\) (chính là trọng tâm tam giác!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử điểm \(q = (2, 2)\):&lt;/strong&gt;
\(\theta_2 = \frac{2}{3},\quad \theta_3 = \frac{2}{3},\quad \theta_1 = 1 - \frac{4}{3} = -\frac{1}{3} &amp;lt; 0.\)
Vì có trọng số âm (\(\theta_1 &amp;lt; 0\)), điểm \(q = (2, 2)\) vẫn thuộc &lt;em&gt;bao affine&lt;/em&gt; (cả mặt phẳng \(\mathbb{R}^2\)) nhưng nằm &lt;strong&gt;ngoài bao lồi&lt;/strong&gt;!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bây giờ ta xét khái niệm trọng tâm của chương này: tập lồi. Một cách trực quan, tập lồi là tập hợp không bị “lõm” vào trong và không có “lỗ hổng” bên trong. Để kiểm tra một tập hợp có lồi hay không, ta xem đoạn thẳng nối hai điểm bất kỳ thuộc tập hợp có nằm hoàn toàn trong tập hợp đó hay không.&lt;/p&gt;

&lt;h3 id=&quot;video-ngắn-tập-lồi-tổ-hợp-lồi-và-bao-lồi&quot;&gt;Video ngắn: Tập lồi, Tổ hợp lồi và Bao lồi&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:8px;background:#10121a;&quot; src=&quot;/public/videos/reels/convex-sets-hulls_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Video dài khoảng 29 giây (có thuyết minh tiếng Việt): định nghĩa hình học đoạn thẳng nằm trọn trong tập hợp và trực giác sợi dây thun của bao lồi.&lt;/p&gt;

&lt;h2 id=&quot;tập-lồi&quot;&gt;Tập Lồi&lt;/h2&gt;

&lt;p&gt;Một tập \(C \subseteq \mathbb{R}^n\) được gọi là &lt;strong&gt;tập lồi&lt;/strong&gt; nếu với mọi \(x_1, x_2 \in C\), đoạn thẳng nối chúng cũng nằm trong \(C\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\theta x_1 + (1-\theta)x_2 \in C\) với \(x_1, x_2 \in C\), \(0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Điều này có nghĩa là với hai điểm bất kỳ trong \(C\), mọi điểm nằm trên đoạn thẳng nối giữa chúng đều thuộc \(C\).&lt;/p&gt;

&lt;p&gt;Hình dưới đây minh họa các ví dụ về tập lồi và không lồi. Hình lục giác bên trái là tập lồi, trong khi hình bị khuyết bên phải không lồi vì tồn tại hai điểm mà đoạn thẳng nối chúng đi ra ngoài tập hợp.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.02_Convex_Set.png&quot; alt=&quot;[Hình1] Tập Lồi [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình1] Tập Lồi [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;tổ-hợp-lồi&quot;&gt;Tổ hợp Lồi&lt;/h2&gt;

&lt;p&gt;Một tổ hợp tuyến tính của nhiều điểm với các hệ số không âm và có tổng bằng 1 được gọi là &lt;strong&gt;tổ hợp lồi&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Điểm có dạng \(\theta_1 x_1 + \theta_2 x_2 + \cdots + \theta_k x_k\) với \(\theta_1 + \theta_2 + \cdots + \theta_k = 1, \theta_i \ge  0, i = 1,  ..., k\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Một tập \(C\) là tập lồi khi và chỉ khi mọi tổ hợp lồi của các điểm trong \(C\) đều thuộc \(C\).&lt;/p&gt;

&lt;h2 id=&quot;bao-lồi&quot;&gt;Bao Lồi&lt;/h2&gt;

&lt;p&gt;Tập hợp tất cả các tổ hợp lồi của các điểm trong \(C \subseteq \mathbb{R}^n\) được gọi là &lt;strong&gt;bao lồi&lt;/strong&gt; của \(C\), ký hiệu là &lt;strong&gt;conv&lt;/strong&gt; \(C\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;conv&lt;/strong&gt; \(C = \{ \theta_1 x_1 + \cdots + \theta_k x_k \mid x_i \in C, \theta_i \ge 0, i = 1, ..., k, \theta_1 + \cdots + \theta_k = 1 \}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hai hình dưới đây lần lượt minh họa bao lồi của một tập gồm 15 điểm rời rạc và của một hình có phần lõm.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.03_Convex_Hull.png&quot; alt=&quot; Bao Lồi&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Bao Lồi&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.03_Convex_Hull_2.png&quot; alt=&quot; Bao Lồi&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Bao Lồi&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01-02 Tập Affine</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_02_Affine_set/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_02_Affine_set</id>
   <content type="html">&lt;p&gt;Trong đại số tuyến tính, không gian con (subspace) luôn bị “đóng đinh” tại gốc tọa độ \(0\). Thế nhưng trong tối ưu hóa thực tế, các ràng buộc đẳng thức như “tổng ngân sách phân bổ bằng 100%” (\(\sum x_i = 1\)) hay “lưu lượng vào bằng lưu lượng ra” (\(Ax = b\) với \(b \ne 0\)) hầu như không đi qua gốc tọa độ! &lt;strong&gt;Tập affine&lt;/strong&gt; chính là câu trả lời: đó là một không gian con được tịnh tiến sang một vị trí mới \(x_0 + V\).&lt;/p&gt;

&lt;p&gt;Nắm rõ tập affine, tổ hợp affine và bao affine giúp bạn hiểu hoàn toàn hình học của hệ ràng buộc tuyến tính \(Ax = b\) và chiều thực sự của miền khả thi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-tính-chất-cốt-lõi-của-tập-affine&quot;&gt;Kiến thức cần nhớ: Bốn tính chất cốt lõi của tập Affine&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa đóng dưới đường thẳng:&lt;/strong&gt; Tập \(C\) là affine nếu với mọi \(x_1, x_2 \in C\) và mọi \(\theta \in \mathbb{R}\), điểm \(\theta x_1 + (1-\theta)x_2\) vẫn thuộc \(C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan hệ dịch chuyển với không gian con (\(C = x_0 + V\)):&lt;/strong&gt; Lấy bất kỳ điểm cố định \(x_0 \in C\), tập hiệu \(V = C - x_0\) luôn là một &lt;strong&gt;không gian con vector&lt;/strong&gt; duy nhất không phụ thuộc cách chọn \(x_0\). Nhờ vậy ta định nghĩa được &lt;strong&gt;chiều affine&lt;/strong&gt; \(\dim(C) = \dim(V)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập nghiệm của hệ phương trình tuyến tính:&lt;/strong&gt; Mọi tập nghiệm \(C = \{x : Ax = b\}\) đều là tập affine (với không gian con đi kèm là không gian hạch \(V = \mathcal{N}(A)\)), và ngược lại mọi tập affine đều viết được dưới dạng \(Ax = b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bao affine (\(\operatorname{aff} S\)):&lt;/strong&gt; Tập affine nhỏ nhất chứa \(S\) — giúp định nghĩa khái niệm &lt;strong&gt;phần trong tương đối&lt;/strong&gt; (relative interior) cực kỳ quan trọng trong điều kiện Slater.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tách-tập-affine-x_1--2x_2--4-thành-điểm-gốc-và-không-gian-con&quot;&gt;Giải thích: Tách tập affine \(x_1 + 2x_2 = 4\) thành điểm gốc và không gian con&lt;/h3&gt;

&lt;p&gt;Xét đường thẳng \(C = \{(x_1, x_2) \in \mathbb{R}^2 : x_1 + 2x_2 = 4\}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra tính affine trên hai điểm cụ thể:&lt;/strong&gt; Chọn \(p = (4, 0) \in C\) và \(q = (0, 2) \in C\). Lấy tổ hợp affine với \(\theta = 3\) (nên \(1 - \theta = -2\)):
\(z = 3(4, 0) - 2(0, 2) = (12, -4).\)
Thay vào phương trình: \(12 + 2(-4) = 12 - 8 = 4 \implies z \in C\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tách thành \(x_0 + V\):&lt;/strong&gt; Chọn điểm gốc \(x_0 = (4, 0) \in C\). Khi đó mọi điểm \(x \in C\) thỏa \((x_1 - 4) + 2(x_2 - 0) = 0\). Đặt \(v = x - x_0 = (v_1, v_2)\), ta thu được không gian con đi kèm:
\(V = \{(v_1, v_2) : v_1 + 2v_2 = 0\} = \{t(-2, 1)^T : t \in \mathbb{R}\}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa tối ưu hóa:&lt;/strong&gt; Thay vì tối ưu trên hai biến bị ràng buộc \(x_1 + 2x_2 = 4\), ta có thể tham số hóa không ràng buộc \(x(t) = (4, 0)^T + t(-2, 1)^T = (4 - 2t,\ t)^T\) với \(t \in \mathbb{R}\) — giảm bài toán từ 2 chiều có ràng buộc về 1 chiều tự do!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Tập affine là tập hợp không có biên giới hạn, chẳng hạn một điểm, một đường thẳng, một mặt phẳng hay một siêu phẳng. Để kiểm tra một tập hợp có phải là tập affine hay không, ta xem đường thẳng đi qua hai điểm bất kỳ trong tập hợp đó có nằm hoàn toàn trong tập hợp hay không. Vì đường thẳng kéo dài vô hạn về cả hai phía, bất kỳ tập hợp nào có biên chắn theo một hướng (ngoại trừ trường hợp một điểm đơn lẻ) đều không thể là tập affine. Sau đây là định nghĩa toán học chính xác.&lt;/p&gt;

&lt;h2 id=&quot;tập-affine&quot;&gt;Tập Affine&lt;/h2&gt;

&lt;p&gt;Một tập \(C \subseteq \mathbb{R}^n\) được gọi là &lt;strong&gt;tập affine&lt;/strong&gt; nếu với mọi \(x_1, x_2 \in C\), đường thẳng đi qua hai điểm này cũng nằm trong \(C\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\theta x_1 + (1-\theta)x_2 \in C\) với \(\theta \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, đây là tổ hợp tuyến tính của hai điểm trong \(C\) với tổng các hệ số bằng 1. Nếu mọi tổ hợp như vậy đều thuộc \(C\) thì \(C\) là một tập affine.&lt;/p&gt;

&lt;h2 id=&quot;tổ-hợp-affine&quot;&gt;Tổ hợp Affine&lt;/h2&gt;

&lt;p&gt;Một tổ hợp tuyến tính của nhiều điểm có tổng các hệ số bằng 1 được gọi là &lt;strong&gt;tổ hợp affine&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\theta_1 x_1 + \theta_2 x_2 + \cdots + \theta_k x_k \in C\) với \(\theta_1 + \theta_2 + \cdots + \theta_k = 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Một tập \(C\) là tập affine khi và chỉ khi mọi tổ hợp affine của các điểm trong \(C\) đều thuộc \(C\).&lt;/p&gt;

&lt;h2 id=&quot;bao-affine&quot;&gt;Bao Affine&lt;/h2&gt;

&lt;p&gt;Tập hợp tất cả các tổ hợp affine của các điểm trong \(C \subseteq \mathbb{R}^n\) được gọi là &lt;strong&gt;bao affine&lt;/strong&gt; của \(C\), ký hiệu là &lt;strong&gt;aff&lt;/strong&gt; \(C\):&lt;/p&gt;
&lt;blockquote&gt;
\[\text{aff} (C) = \{ \theta_1 x_1 + \cdots + \theta_k x_k \mid x_1, ..., x_k \in C, \theta_1 + \cdots + \theta_k = 1 \}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;mối-quan-hệ-giữa-tập-affine-và-không-gian-con&quot;&gt;Mối quan hệ giữa tập affine và không gian con&lt;/h2&gt;

&lt;p&gt;Nếu \(C\) là một tập affine và \(x_0 \in C\), thì tập \(V = C - x_0\) là một không gian con tuyến tính:&lt;/p&gt;
&lt;blockquote&gt;
\[V = C - x_0 =  \{ x - x_0 \mid x \in C \}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó, tập affine \(C\) chính là phép tịnh tiến của không gian con tuyến tính \(V\) theo vector \(x_0\), với \(x_0\) là một điểm bất kỳ thuộc \(C\). Số chiều của tập affine \(C\) được định nghĩa bằng số chiều của không gian con \(V\).&lt;/p&gt;

&lt;h3 id=&quot;tham-khảo-chứng-minh-v-là-một-không-gian-con&quot;&gt;[Tham khảo] Chứng minh \(V\) là một không gian con&lt;/h3&gt;

&lt;p&gt;Để chứng minh \(V\) là không gian con tuyến tính, ta cần chỉ ra \(V\) đóng với phép cộng và phép nhân vô hướng: với mọi \(v_1, v_2 \in V\) và \(\alpha, \beta \in \mathbb{R}\), ta có \(\alpha v_1 + \beta v_2 \in V\). Thật vậy, viết \(v_1 = x_1 - x_0\) và \(v_2 = x_2 - x_0\) với \(x_1, x_2 \in C\), khi đó \(\alpha v_1 + \beta v_2 + x_0 = \alpha x_1 + \beta x_2 + (1 - \alpha - \beta)x_0\) là một tổ hợp affine của các điểm trong \(C\) nên thuộc \(C\), suy ra \(\alpha v_1 + \beta v_2 \in V\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01-01 Đường thẳng, đoạn thẳng, tia</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_01_Line_line_segment_ray/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_01_Line_line_segment_ray</id>
   <content type="html">&lt;p&gt;Trong không gian 2D hay 3D, ai cũng vẽ được đường thẳng, đoạn thẳng và tia bằng thước kẻ. Nhưng khi bài toán tối ưu sống trong không gian 10.000 chiều — nơi không còn thước kẻ hay hình vẽ — ta cần một biểu diễn đại số thống nhất để “đi bộ” giữa hai phương án \(x_1\) và \(x_2\). Biểu diễn tham số \(x(\theta) = \theta x_1 + (1 - \theta)x_2\) làm đúng điều đó: chỉ cần thay đổi miền của tham số thực \(\theta\), ta lập tức thu được cả đường thẳng, đoạn thẳng lẫn tia.&lt;/p&gt;

&lt;p&gt;Bài học ngắn nhưng nền tảng này đặt viên gạch ký hiệu đầu tiên cho toàn bộ hình học lồi của khóa học.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-đối-tượng-sơ-cấp-qua-một-tham-số-theta&quot;&gt;Kiến thức cần nhớ: Ba đối tượng sơ cấp qua một tham số \(\theta\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đường thẳng (Line):&lt;/strong&gt; \(x(\theta) = \theta x_1 + (1-\theta)x_2\) với \(\theta \in \mathbb{R}\) tự do — không bị chặn cả hai đầu, là khuôn mẫu của &lt;strong&gt;tập affine&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đoạn thẳng (Line Segment):&lt;/strong&gt; Giới hạn \(0 \le \theta \le 1\) — nối kín hai đầu mút \(x_1\) (khi \(\theta = 1\)) và \(x_2\) (khi \(\theta = 0\)), là khuôn mẫu của &lt;strong&gt;tập lồi&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tia (Ray):&lt;/strong&gt; \(x(t) = x_0 + t v\) với \(t \ge 0\) (\(v \ne 0\)) — xuất phát từ điểm gốc \(x_0\) và kéo dài vô hạn theo đúng một hướng \(v\), là khuôn mẫu của &lt;strong&gt;hình nón&lt;/strong&gt; và phân tích hướng vô hạn (recession directions) trong tối ưu hóa.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-định-vị-các-điểm-theo-tham-số-theta-giữa-x_1--1-2-và-x_2--5-4&quot;&gt;Giải thích: Định vị các điểm theo tham số \(\theta\) giữa \(x_1 = (1, 2)\) và \(x_2 = (5, 4)\)&lt;/h3&gt;

&lt;p&gt;Cho \(x_1 = (1, 2)^T\) và \(x_2 = (5, 4)^T\). Biểu diễn tham số là \(x(\theta) = \theta x_1 + (1 - \theta)x_2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điểm trên đoạn thẳng (\(\theta = 0.25 \in [0, 1]\)):&lt;/strong&gt;
\(x(0.25) = 0.25(1, 2) + 0.75(5, 4) = (0.25 + 3.75,\ 0.5 + 3.0) = (4, 3.5).\)
Vì \(1 - \theta = 0.75\) lớn hơn, điểm này nằm gần \(x_2\) hơn gấp 3 lần so với \(x_1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm trên đường thẳng nhưng ngoài đoạn thẳng (\(\theta = 1.5 \notin [0, 1]\)):&lt;/strong&gt;
\(x(1.5) = 1.5(1, 2) - 0.5(5, 4) = (1.5 - 2.5,\ 3 - 2) = (-1, 1).\)
Điểm này vượt quá đầu mút \(x_1\) về phía trái.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm trên tia xuất phát từ \(x_1\) đi qua \(x_2\):&lt;/strong&gt; Đặt hướng \(v = x_2 - x_1 = (4, 2)^T\) và \(x(t) = x_1 + t v\) (\(t \ge 0\)). Với \(t = 2\):
\(x(2) = (1, 2) + 2(4, 2) = (9, 6).\)
Nhờ cách viết này, ta dễ dàng kiểm tra một thuật toán tìm kiếm đường thẳng \(x^{(k+1)} = x^{(k)} + t d\) đang đi dọc theo một tia hợp lệ.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Để định nghĩa tập affine, tập lồi và hình nón, trước hết ta xét ba đối tượng hình học cơ bản: đường thẳng, đoạn thẳng và tia.&lt;/p&gt;

&lt;p&gt;Đường thẳng đi qua hai điểm kéo dài vô hạn về cả hai phía. Ngược lại, đoạn thẳng chỉ gồm các điểm nằm giữa hai điểm đó, còn tia xuất phát từ một điểm và kéo dài vô hạn theo một hướng đi qua điểm còn lại. Hình dưới đây minh họa đường thẳng và đoạn thẳng đi qua hai điểm \(x_1\) và \(x_2\). Tùy theo miền giá trị của tham số \(\theta\), ta thu được biểu diễn tương ứng cho đường thẳng, đoạn thẳng hoặc tia.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.01_Line_Segment.png&quot; alt=&quot;Line Segment&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Hình1] } x_1\text{ và } x_2 \text{ định nghĩa Đường thẳng và Đoạn thẳng [1]}$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;em&gt;Lưu ý:&lt;/em&gt; Khi lấy hai điểm thuộc một tập hợp để tạo thành đường thẳng, đoạn thẳng hoặc tia, việc các điểm tạo ra có luôn thuộc lại tập hợp đó hay không chính là tiêu chí để định nghĩa các loại tập hợp. (Ta cũng có thể định nghĩa tương tự bằng nhiều điểm thông qua tổ hợp affine, tổ hợp lồi hoặc tổ hợp nón; chi tiết sẽ được trình bày ở các mục tiếp theo.)&lt;/p&gt;

&lt;h2 id=&quot;đường-thẳng&quot;&gt;Đường thẳng&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đường thẳng&lt;/strong&gt; đi qua hai điểm \(x_1\) và \(x_2\) được định nghĩa là:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(y = \theta x_1 + (1 - \theta) x_2\) với \(\theta \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;đoạn-thẳng&quot;&gt;Đoạn thẳng&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đoạn thẳng&lt;/strong&gt; nối hai điểm \(x_1\) và \(x_2\) thu được khi giới hạn \(\theta\) trong đoạn \([0, 1]\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(y = \theta x_1 + (1 - \theta) x_2\) với \(0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ta cũng có thể viết lại dưới dạng:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(y = x_2 + \theta (x_1 - x_2)\) với \(0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;tia&quot;&gt;Tia&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tia&lt;/strong&gt; xuất phát từ \(x_2\) và kéo dài vô hạn theo hướng đi qua \(x_1\) được định nghĩa là:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(y = x_2 + \theta (x_1 - x_2)\) với \(\theta \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hoặc viết tương đương:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(y = \theta x_1 + (1 - \theta) x_2\) với \(\theta \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Như vậy, miền giá trị của tham số \(\theta\) lần lượt là \(\theta \in \mathbb{R}\) đối với đường thẳng, \(0 \le \theta \le 1\) đối với đoạn thẳng và \(\theta \ge 0\) đối với tia. Các miền giá trị này sẽ xuất hiện lại tương ứng trong định nghĩa tập affine, tập lồi và hình nón ở các bài sau.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-10 Practical Exercises - Canonical Problems</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_10_Practical_Exercises_Canonical_Problems/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_10_Practical_Exercises_Canonical_Problems</id>
   <content type="html">&lt;p&gt;Mastering canonical forms means being able to take a plain-English engineering or economics story—a diet plan, a portfolio risk cap, a robust sensor design, or an eigenvalue bound—and translate it cleanly into standard matrix notation ready for a solver. These practical exercises walk you across the entire LP \(\to\) QP \(\to\) SOCP \(\to\) SDP ladder so you can build and verify canonical models with confidence.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-word-problem-to-canonical-matrices&quot;&gt;Key ideas: From Word Problem to Canonical Matrices&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identifying Decision Variables &amp;amp; Units&lt;/strong&gt;: Always declare your decision vector \(x \in \mathbb{R}^n\) with explicit physical units (servings, dollars, portfolio weights, watts) before writing a single inequality—unit mismatches are the #1 source of modeling bugs.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mapping Problem Structure to the Right Cone&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Linear cost + linear resource bounds \(\to\) &lt;strong&gt;LP&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Squared error or variance objective + linear bounds \(\to\) &lt;strong&gt;QP&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Euclidean distance, worst-case ellipsoidal uncertainty, or norm cap \(\to\) &lt;strong&gt;SOCP&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;Eigenvalue bounds or matrix covariance constraints \(\to\) &lt;strong&gt;SDP&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Checking Positive Semidefiniteness Before Calling a QP/QCQP Solver&lt;/strong&gt;: Always symmetrize \(P \leftarrow \frac{1}{2}(P + P^T)\) and verify all eigenvalues of \(P\) are \(\ge 0\) (e.g., via Sylvester’s criterion on small problems) so your model is genuinely convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sanity-Checking Solutions Against Physical Bounds&lt;/strong&gt;: After solving, check primal feasibility (every constraint satisfied), identify which constraints are binding (zero slack), and confirm the objective value beats an obvious naive baseline.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-warm-up-mini-diet-lp-solved-by-hand&quot;&gt;Worked example: Warm-Up Mini-Diet LP Solved by Hand&lt;/h3&gt;

&lt;p&gt;Suppose two foods provide protein and vitamin C: Food A costs \$2/unit (3g protein, 1mg vitamin C) and Food B costs \$3/unit (1g protein, 3mg vitamin C). Meet at least 6g protein and 6mg vitamin C at minimum cost.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Formulate the LP&lt;/strong&gt;: Let \(x_1, x_2 \ge 0\) be units of Food A and Food B.
\(\min_{x_1, x_2 \ge 0} \quad 2x_1 + 3x_2 \quad \text{subject to} \quad 3x_1 + x_2 \ge 6, \quad x_1 + 3x_2 \ge 6.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Locate the corner points of the unbounded upper-right feasible region&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;On \(x_2 = 0\): \(3x_1 \ge 6\) and \(x_1 \ge 6 \implies v_1 = (6, 0)\).&lt;/li&gt;
      &lt;li&gt;On \(x_1 = 0\): \(x_2 \ge 6\) and \(3x_2 \ge 6 \implies v_2 = (0, 6)\).&lt;/li&gt;
      &lt;li&gt;Intersection of \(3x_1 + x_2 = 6\) and \(x_1 + 3x_2 = 6\): adding gives \(4(x_1 + x_2) = 12 \implies x_1 + x_2 = 3\); subtracting gives \(2(x_1 - x_2) = 0 \implies x_1 = x_2 = 1.5\), giving \(v_3 = (1.5, 1.5)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate total cost \(C(x_1, x_2) = 2x_1 + 3x_2\) at each corner&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(C(6, 0) = 12\),&lt;/li&gt;
      &lt;li&gt;\(C(0, 6) = 18\),&lt;/li&gt;
      &lt;li&gt;\(C(1.5, 1.5) = 2(1.5) + 3(1.5) = 3 + 4.5 = 7.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify optimality&lt;/strong&gt;: Because the cost vector \((2, 3) &amp;gt; 0\) points strictly into the positive orthant, the objective is bounded below and achieves its unique minimum of &lt;strong&gt;\$7.50&lt;/strong&gt; at \((1.5, 1.5)\), where both nutrient requirements bind exactly (\(3(1.5) + 1.5 = 6\) and \(1.5 + 3(1.5) = 6\)).&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---canonical-problems&quot;&gt;Practical Exercises - Canonical Problems&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd &amp;amp; Vandenberghe (2004) and Ben-Tal &amp;amp; Nemirovski (2001).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-i-linear-programming-lp&quot;&gt;📝 &lt;strong&gt;Part I: Linear Programming (LP)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-1-the-diet-problem&quot;&gt;&lt;strong&gt;Exercise 1: The Diet Problem&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;A person needs to plan a diet with 3 foods:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Food 1: 2 units of protein, 1 unit of carbs, price 3 USD&lt;/li&gt;
  &lt;li&gt;Food 2: 1 unit of protein, 2 units of carbs, price 2 USD&lt;/li&gt;
  &lt;li&gt;Food 3: 1 unit of protein, 1 unit of carbs, price 1.5 USD&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Minimum requirement: 5 units of protein and 6 units of carbs per day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the LP that minimizes the cost&lt;br /&gt;
b) Find the optimal solution&lt;br /&gt;
c) Explain the meaning of the dual variables (shadow prices)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Formulation:**

Variables: $$x_i$$ = amount of food $$i$$ ($$i = 1,2,3$$)

$$
\begin{align}
\min_{x} \quad &amp;amp; 3x_1 + 2x_2 + 1.5x_3 \\
\text{s.t.} \quad &amp;amp; 2x_1 + x_2 + x_3 \geq 5 \quad \text{(protein)} \\
&amp;amp; x_1 + 2x_2 + x_3 \geq 6 \quad \text{(carbs)} \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}
$$

**Standard form (min with $$\leq$$):**

$$
\begin{align}
\min_{x} \quad &amp;amp; 3x_1 + 2x_2 + 1.5x_3 \\
\text{s.t.} \quad &amp;amp; -2x_1 - x_2 - x_3 \leq -5 \\
&amp;amp; -x_1 - 2x_2 - x_3 \leq -6 \\
&amp;amp; x_1, x_2, x_3 \geq 0
\end{align}
$$

---

**b) Find the optimal solution:**

Food 3 is the cheapest per unit of nutrition, so the optimal solution uses a lot of food 3. Consider the vertex $$x = (0, 1, 4)$$ (both constraints active, $$x_1 = 0$$):

$$\text{Protein: } 0 + 1 + 4 = 5 \text{ ✓}, \qquad \text{Carbs: } 0 + 2 + 4 = 6 \text{ ✓}$$

Cost: $$3 \cdot 0 + 2 \cdot 1 + 1.5 \cdot 4 = 8$$ USD.

Optimality is confirmed by the dual in part c): there is a feasible $$\lambda$$ whose dual value equals 8.

**Optimal solution:** $$x^* = (0, 1, 4)$$, cost = 8 USD

(Note: the vertex with $$x_3 = 0$$, $$x = (\frac{4}{3}, \frac{7}{3}, 0)$$, is feasible but its cost $$\frac{26}{3} \approx 8.67 &amp;gt; 8$$, so it is **not** optimal.)

---

---

**c) Dual variables (Shadow prices):**

Dual problem:

$$
\max_{\lambda} \quad 5\lambda_1 + 6\lambda_2 \quad \text{s.t.} \quad A^T\lambda \leq c, \, \lambda \geq 0
$$

that is, $$2\lambda_1 + \lambda_2 \leq 3$$, $$\lambda_1 + 2\lambda_2 \leq 2$$, $$\lambda_1 + \lambda_2 \leq 1.5$$.

With $$\lambda^* = (1, \frac{1}{2})$$ (from complementary slackness: since $$x_2, x_3 &amp;gt; 0$$, dual constraints 2 and 3 must be tight): constraint 1 reads $$2 + 0.5 = 2.5 &amp;lt; 3$$ (slack, consistent with $$x_1^* = 0$$), and the dual value $$5(1) + 6(0.5) = 8$$ equals the primal value → optimal (strong duality).

**Meaning:**
- $$\lambda_1^* = 1$$: raising the protein requirement by 1 unit → cost increases by 1 USD
- $$\lambda_2^* = \frac{1}{2}$$: raising the carbs requirement by 1 unit → cost increases by 0.5 USD

Protein is &quot;more expensive&quot; than carbs in this setting!

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-ii-quadratic-programming-qp&quot;&gt;📝 &lt;strong&gt;Part II: Quadratic Programming (QP)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-2-portfolio-optimization&quot;&gt;&lt;strong&gt;Exercise 2: Portfolio Optimization&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Invest in 2 assets with:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Expected returns: \(\mu = (0.12, 0.10)^T\)&lt;/li&gt;
  &lt;li&gt;Covariance matrix: \(\Sigma = \begin{bmatrix} 0.04 &amp;amp; 0.01 \\ 0.01 &amp;amp; 0.09 \end{bmatrix}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the problem of minimizing risk with target return \(r = 0.11\)&lt;br /&gt;
b) Find the optimal portfolio&lt;br /&gt;
c) Plot the efficient frontier&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) Formulation:**

$$
\begin{align}
\min_{x} \quad &amp;amp; \frac{1}{2} x^T \Sigma x \\
\text{s.t.} \quad &amp;amp; \mu^T x = r \\
&amp;amp; \mathbf{1}^T x = 1 \\
&amp;amp; x \geq 0
\end{align}
$$

With $$r = 0.11$$:

$$
\begin{align}
\min_{x} \quad &amp;amp; \frac{1}{2}(0.04x_1^2 + 0.02x_1x_2 + 0.09x_2^2) \\
\text{s.t.} \quad &amp;amp; 0.12x_1 + 0.10x_2 = 0.11 \\
&amp;amp; x_1 + x_2 = 1 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}
$$

---

**b) Solve using the constraints:**

From $$x_1 + x_2 = 1$$ and $$0.12x_1 + 0.10x_2 = 0.11$$:

$$0.12x_1 + 0.10(1-x_1) = 0.11 \Rightarrow 0.02x_1 = 0.01 \Rightarrow x_1 = 0.5$$

$$x_2 = 0.5$$

**Solution:** $$x^* = (0.5, 0.5)^T$$

**Feasibility check:** $$0.5 + 0.5 = 1$$ ✓, $$0.12(0.5) + 0.10(0.5) = 0.11$$ ✓

**Risk (variance):**

$$\sigma^2 = x^{*T} \Sigma x^* = \begin{bmatrix} 0.5 &amp;amp; 0.5 \end{bmatrix} \begin{bmatrix} 0.04 &amp;amp; 0.01 \\ 0.01 &amp;amp; 0.09 \end{bmatrix} \begin{bmatrix} 0.5 \\ 0.5 \end{bmatrix}$$

$$= \begin{bmatrix} 0.5 &amp;amp; 0.5 \end{bmatrix} \begin{bmatrix} 0.025 \\ 0.05 \end{bmatrix} = 0.0375$$

**Standard deviation:** $$\sigma = \sqrt{0.0375} \approx 0.194 = 19.4\%$$

---

**c) Efficient frontier:**

Vary $$r$$ from $$\min(\mu_i) = 0.10$$ to $$\max(\mu_i) = 0.12$$:

| Return $$r$$ | $$x_1$$ | $$x_2$$ | Risk $$\sigma$$ |
|-------------|---------|---------|-----------------|
| 0.10 | 0 | 1 | 0.300 |
| 0.105 | 0.25 | 0.75 | 0.238 |
| 0.11 | 0.5 | 0.5 | 0.194 |
| 0.1145 | 0.727 | 0.273 | 0.178 (minimum risk) |
| 0.115 | 0.75 | 0.25 | 0.179 |
| 0.12 | 1 | 0 | 0.200 |

**Conclusion:** The (risk, return) curve has minimum risk at $$x_1 = 0.08/0.11 \approx 0.727$$ ($$r \approx 0.1145$$). Only the branch $$r \geq 0.1145$$ is the **efficient frontier** (higher return for the same risk); points with $$r &amp;lt; 0.1145$$ are dominated.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iii-qcqp-and-socp&quot;&gt;📝 &lt;strong&gt;Part III: QCQP and SOCP&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-3-robust-least-squares-socp&quot;&gt;&lt;strong&gt;Exercise 3: Robust Least Squares (SOCP)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Given data \(A \in \mathbb{R}^{m \times n}\), \(b \in \mathbb{R}^m\). Instead of ordinary least squares, consider the robust version:&lt;/p&gt;

\[\min_{x} \quad \|Ax - b\|_2 + \gamma \|x\|_2\]

&lt;p&gt;where \(\gamma &amp;gt; 0\) is a regularization parameter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write it as an SOCP&lt;br /&gt;
b) With \(A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \\ 2 &amp;amp; 0 \end{bmatrix}\), \(b = \begin{bmatrix} 2 \\ 0 \\ 3 \end{bmatrix}\), \(\gamma = 0.1\), find the solution&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) SOCP formulation:**

Let:
- $$t_1$$ sao cho $$\|Ax - b\|_2 \leq t_1$$
- $$t_2$$ sao cho $$\|x\|_2 \leq t_2$$

The problem becomes:

$$
\begin{align}
\min_{x, t_1, t_2} \quad &amp;amp; t_1 + \gamma t_2 \\
\text{s.t.} \quad &amp;amp; \|Ax - b\|_2 \leq t_1 \\
&amp;amp; \|x\|_2 \leq t_2
\end{align}
$$

This is an **SOCP** with 2 second-order cone constraints.

**Standard SOCP form:**

$$
\begin{align}
\min \quad &amp;amp; c^T y \\
\text{s.t.} \quad &amp;amp; \|A_i y + b_i\|_2 \leq c_i^T y + d_i, \quad i = 1, \ldots, k
\end{align}
$$

---

**b) Numerical solution:**

Data:

$$A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \\ 2 &amp;amp; 0 \end{bmatrix}, \quad b = \begin{bmatrix} 2 \\ 0 \\ 3 \end{bmatrix}, \quad \gamma = 0.1$$

**Analytical approach (approximate):**

Gradient of $$f(x) = \|Ax-b\|_2 + \gamma\|x\|_2$$:

$$\nabla f(x) = \frac{A^T(Ax-b)}{\|Ax-b\|_2} + \gamma \frac{x}{\|x\|_2}$$

(Complicated because $$f$$ is non-smooth at $$x = 0$$ and at $$Ax = b$$)

**Method 1: approximate by regularized LS with a closed form:**

Approximate by $$\min \|Ax-b\|_2^2 + \gamma^2\|x\|_2^2$$:

$$x_{\text{ridge}} = (A^TA + \gamma^2 I)^{-1} A^T b$$

Compute:

$$A^TA = \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 2 \\ 1 &amp;amp; -1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \\ 2 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 6 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}$$

$$A^TA + 0.01I = \begin{bmatrix} 6.01 &amp;amp; 0 \\ 0 &amp;amp; 2.01 \end{bmatrix}$$

$$A^Tb = \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 2 \\ 1 &amp;amp; -1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} 2 \\ 0 \\ 3 \end{bmatrix} = \begin{bmatrix} 8 \\ 2 \end{bmatrix}$$

Solving: $$x_{\text{ridge}} = \left(\frac{8}{6.01}, \frac{2}{2.01}\right) \approx (1.331, 0.995)^T$$, with $$f(x_{\text{ridge}}) \approx 0.744$$.

**Method 2: numerical solution of the original SOCP** (directly solving $$\min \|Ax-b\|_2 + 0.1\|x\|_2$$):

$$x^* \approx (1.326, 0.983)^T, \qquad f(x^*) \approx 0.743$$

(The two solutions are close but not identical, because the original problem uses the $$\ell_2$$ norm rather than its square.)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-iv-semidefinite-programming-sdp&quot;&gt;📝 &lt;strong&gt;Part IV: Semidefinite Programming (SDP)&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-4-matrix-completion&quot;&gt;&lt;strong&gt;Exercise 4: Matrix Completion&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Given a matrix \(M \in \mathbb{R}^{3 \times 3}\) with some missing entries. Known:&lt;/p&gt;

\[M_{11} = 4, \quad M_{12} = 2, \quad M_{22} = 5, \quad M_{23} = 1\]

&lt;p&gt;Find the completed positive semidefinite matrix \(X\) with the smallest trace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br /&gt;
a) Write the SDP&lt;br /&gt;
b) Find the solution&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) SDP formulation:**

$$
\begin{align}
\min_{X} \quad &amp;amp; \text{tr}(X) \\
\text{s.t.} \quad &amp;amp; X_{11} = 4 \\
&amp;amp; X_{12} = X_{21} = 2 \\
&amp;amp; X_{22} = 5 \\
&amp;amp; X_{23} = X_{32} = 1 \\
&amp;amp; X \succeq 0 \\
&amp;amp; X = X^T
\end{align}
$$

The matrix:

$$X = \begin{bmatrix} 4 &amp;amp; 2 &amp;amp; x_{13} \\ 2 &amp;amp; 5 &amp;amp; 1 \\ x_{13} &amp;amp; 1 &amp;amp; x_{33} \end{bmatrix}$$

---

**b) Solution:**

**PSD condition:** all principal minors are $$\geq 0$$.

**Minor 1×1:** $$4 &amp;gt; 0$$ ✓

**Minor 2×2:** 

$$\begin{vmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 5 \end{vmatrix} = 20 - 4 = 16 &amp;gt; 0$$ ✓

**Minor 3×3 (determinant):**

$$\det(X) = 4(5x_{33} - 1) - 2(2x_{33} - x_{13}) + x_{13}(2 - 5x_{13})$$

$$= 20x_{33} - 4 - 4x_{33} + 2x_{13} + 2x_{13} - 5x_{13}^2$$

$$= 16x_{33} - 5x_{13}^2 + 4x_{13} - 4$$

For $$\det(X) \geq 0$$: $$16x_{33} \geq 5x_{13}^2 - 4x_{13} + 4$$

**Minimize $$\text{tr}(X) = 4 + 5 + x_{33} = 9 + x_{33}$$:**

We need to minimize $$x_{33}$$ subject to PSD.

From PSD, we need:

$$x_{33} \geq \frac{5x_{13}^2 - 4x_{13} + 4}{16}$$

Minimize RHS over $$x_{13}$$:

$$\frac{d}{dx_{13}}\left(\frac{5x_{13}^2 - 4x_{13} + 4}{16}\right) = \frac{10x_{13} - 4}{16} = 0$$

$$x_{13}^* = 0.4$$

$$x_{33}^{\min} = \frac{5(0.4)^2 - 4(0.4) + 4}{16} = \frac{0.8 - 1.6 + 4}{16} = \frac{3.2}{16} = 0.2$$

**Solution:**

$$X^* = \begin{bmatrix} 4 &amp;amp; 2 &amp;amp; 0.4 \\ 2 &amp;amp; 5 &amp;amp; 1 \\ 0.4 &amp;amp; 1 &amp;amp; 0.2 \end{bmatrix}, \quad \text{tr}(X^*) = 9.2$$

**Check:** $$\det(X^*) = 16(0.2) - 5(0.16) + 1.6 - 4 = 0$$ (rank-deficient, but $$\succeq 0$$ ✓)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-part-v-putting-it-together&quot;&gt;📝 &lt;strong&gt;Part V: Putting It Together&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;exercise-5-choosing-the-right-formulation&quot;&gt;&lt;strong&gt;Exercise 5: Choosing the Right Formulation&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;For each problem, identify the standard class (LP, QP, QCQP, SOCP, SDP):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; \(\min c^T x\) s.t. \(Ax = b\), \(\|x\|_\infty \leq 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;b)&lt;/strong&gt; \(\min \|Ax - b\|_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;c)&lt;/strong&gt; \(\min x^TQx\) s.t. \(\|Ax - b\|_2 \leq \delta\) (with \(Q \succeq 0\))&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;d)&lt;/strong&gt; \(\min \text{tr}(X)\) s.t. \(X \succeq yy^T\), \(X \succeq 0\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) $$\min c^Tx$$ s.t. $$Ax = b$$, $$\|x\|_\infty \leq 1$$:**

$$\|x\|_\infty \leq 1 \Leftrightarrow -1 \leq x_i \leq 1$$ (linear constraints)

→ **Linear Programming (LP)**

---

**b) $$\min \|Ax - b\|_1$$:**

$$\|Ax - b\|_1 = \sum_i |r_i|$$ with $$r = Ax - b$$

Let $$t_i \geq |r_i|$$:

$$
\begin{align}
\min \quad &amp;amp; \sum_i t_i \\
\text{s.t.} \quad &amp;amp; -t_i \leq (Ax - b)_i \leq t_i
\end{align}
$$

→ **Linear Programming (LP)**

---

**c) $$\min x^TQx$$ s.t. $$\|Ax - b\|_2 \leq \delta$$ (with $$Q \succeq 0$$):**

- Objective: quadratic
- Constraint: second-order cone ($$\ell_2$$ norm)

→ **Second-Order Cone Programming (SOCP)**

(Or QCQP if written as $$\|Ax-b\|_2^2 \leq \delta^2$$)

---

**d) $$\min \text{tr}(X)$$ s.t. $$X \succeq yy^T$$, $$X \succeq 0$$:**

- Objective: linear trong $$X$$
- Constraint: $$X \succeq yy^T$$ → $$X - yy^T \succeq 0$$ (PSD constraint)

→ **Semidefinite Programming (SDP)**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;hierarchy-of-convex-problems&quot;&gt;&lt;strong&gt;Hierarchy of Convex Problems:&lt;/strong&gt;&lt;/h3&gt;

\[\text{LP} \subset \text{QP} \subset \text{SOCP} \subset \text{SDP}\]

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Problem&lt;/th&gt;
      &lt;th&gt;Objective&lt;/th&gt;
      &lt;th&gt;Constraints&lt;/th&gt;
      &lt;th&gt;Example&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;LP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;Diet problem, transportation&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Quadratic&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;Portfolio, least squares&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QCQP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Quadratic&lt;/td&gt;
      &lt;td&gt;Quadratic&lt;/td&gt;
      &lt;td&gt;Robust optimization&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SOCP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;\(\ell_2\) cones&lt;/td&gt;
      &lt;td&gt;Robust LS, antenna design&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SDP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;PSD cones&lt;/td&gt;
      &lt;td&gt;Matrix completion, relaxation&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;when-to-use-what&quot;&gt;&lt;strong&gt;When to use what:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP:&lt;/strong&gt; when everything is linear&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QP:&lt;/strong&gt; risk minimization, LS with regularization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SOCP:&lt;/strong&gt; Robust optimization, \(\ell_2\) constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SDP:&lt;/strong&gt; Matrix variables, combinatorial relaxation&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press. Chapter 4.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ben-Tal, A., &amp;amp; Nemirovski, A.&lt;/strong&gt; (2001). &lt;em&gt;Lectures on Modern Convex Optimization&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Lobo, M. S., et al.&lt;/strong&gt; (1998). “Applications of Second-Order Cone Programming”. &lt;em&gt;Linear Algebra and Applications&lt;/em&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

</content>
 </entry>
 
 <entry>
   <title>05-09 Multiple-Choice Quiz - Canonical Optimization Problems</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_09_Quiz_Canonical_Problems/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_09_Quiz_Canonical_Problems</id>
   <content type="html">&lt;p&gt;Recognizing a canonical class on sight is a superpower: the moment you spot whether a problem is an LP, QP, QCQP, SOCP, SDP, or hidden GP, you know its geometry, its optimality properties, and which solver will crack it in milliseconds. This Chapter 05 quiz tests your ability to classify formulations, spot convexity conditions on quadratic matrices, connect statistical MLE to least squares, and rewrite tricky norms into standard cones.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-chapter-05-classification-checklist&quot;&gt;Key ideas: Chapter 05 Classification Checklist&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;LP &amp;amp; Simplex Recognition&lt;/strong&gt;: Linear objective plus affine equalities/inequalities; optima lie at vertices of a polyhedron; \(\ell_1\) and \(\ell_\infty\) objectives convert to LPs via auxiliary variables.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QP, Least Squares &amp;amp; Statistical Regression&lt;/strong&gt;: Convex quadratic objective (\(P \succeq 0\)) with affine constraints; unconstrained least squares solves \(A^T A x = A^T b\) and equals Gaussian MLE; logistic regression yields a strictly convex cross-entropy objective when \(X\) has full rank (or regularized).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QCQP, SOCP &amp;amp; SDP Embeddings&lt;/strong&gt;: Convex quadratic inequalities require \(P_i \succeq 0\) and lift into SOCPs via Cholesky factors; Euclidean norms \(\|Ax + b\|_2 \le c^T x + d\) define SOCPs; Linear Matrix Inequalities \(F_0 + \sum x_i F_i \preceq 0\) define SDPs.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hidden Convexity via GP &amp;amp; Conic Abstraction&lt;/strong&gt;: Posynomials over \(\mathbb{R}^n_{++}\) become convex log-sum-exp programs under \(x_i = e^{y_i}\); all canonical classes unify as \(\min c^T x \text{ s.t. } Fx + g \preceq_K 0,\; Ax = b\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-rapid-fire-class-identification-warm-up&quot;&gt;Worked example: Rapid-Fire Class Identification Warm-Up&lt;/h3&gt;

&lt;p&gt;Before answering the quiz, identify the &lt;em&gt;tightest&lt;/em&gt; canonical convex class for each of these three formulations:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Problem 1&lt;/strong&gt;: \(\min_{x \in \mathbb{R}^2} \|x\|_1 + 2x_1 \quad \text{s.t.} \quad x_1 + x_2 \ge 1\).
    &lt;ul&gt;
      &lt;li&gt;Introduce \(t_1, t_2\) with \(-t_i \le x_i \le t_i\) and minimize \(t_1 + t_2 + 2x_1\). Every expression is linear \(\implies\) &lt;strong&gt;LP&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Problem 2&lt;/strong&gt;: \(\min_{x \in \mathbb{R}^2} x_1^2 + 4x_1 x_2 + x_2^2 \quad \text{s.t.} \quad x_1 + x_2 = 1\).
    &lt;ul&gt;
      &lt;li&gt;Write the Hessian: \(P = \begin{bmatrix} 2 &amp;amp; 4 \\ 4 &amp;amp; 2 \end{bmatrix}\). Its determinant is \(4 - 16 = -12 &amp;lt; 0\), so \(P\) has a negative eigenvalue (\(-2\))! Therefore this is &lt;strong&gt;nonconvex&lt;/strong&gt; (not a convex QP), even though it looks quadratic!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Problem 3&lt;/strong&gt;: \(\min_{x \in \mathbb{R}^2} 3x_1 - x_2 \quad \text{s.t.} \quad \sqrt{(x_1 - 1)^2 + 4x_2^2} \le x_1 + 5\).
    &lt;ul&gt;
      &lt;li&gt;Rewrite the left-hand side as \(\left\|\begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix} x + \begin{bmatrix} -1 \\ 0 \end{bmatrix}\right\|_2 \le \begin{bmatrix} 1 \\ 0 \end{bmatrix}^T x + 5\). Linear objective + one Lorentz cone constraint \(\implies\) &lt;strong&gt;SOCP&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the canonical optimization problems, including linear programming, quadratic programming, least squares and linear regression.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-linear-programming-lp&quot;&gt;📊 &lt;strong&gt;Linear Programming (LP)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;General form:&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;c^T x + d \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;Gx \preceq h \\
&amp;amp;&amp;amp;&amp;amp;Ax = b
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Standard form:&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;c^T x \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;Ax = b \\
&amp;amp;&amp;amp;&amp;amp;x \succeq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Main features:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The objective and constraints are all &lt;strong&gt;affine&lt;/strong&gt; (linear)&lt;/li&gt;
  &lt;li&gt;The feasible set is a &lt;strong&gt;polyhedron&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;If an optimal solution exists (and the polyhedron has a vertex), there is always an optimal solution at a &lt;strong&gt;vertex&lt;/strong&gt; of the polyhedron&lt;/li&gt;
  &lt;li&gt;Can be solved efficiently by the &lt;strong&gt;Simplex algorithm&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Converting to standard form:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Add slack variables: \(g_i(x) \le 0 \Rightarrow g_i(x) + s_i = 0, s_i \ge 0\)&lt;/li&gt;
  &lt;li&gt;Split variables: \(x = x^+ - x^-\) with \(x^+, x^- \ge 0\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-quadratic-programming-qp&quot;&gt;📈 &lt;strong&gt;Quadratic Programming (QP)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;General form:&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;\frac{1}{2}x^T P x + q^T x + r \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;Gx \preceq h \\
&amp;amp;&amp;amp;&amp;amp;Ax = b
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convexity condition:&lt;/strong&gt; \(P \in \mathbb{S}_+^n\) (positive semidefinite matrix)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Checking \(P \succeq 0\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;All eigenvalues \(\lambda_i \ge 0\)&lt;/li&gt;
  &lt;li&gt;\(v^T P v \ge 0\) for all \(v\)&lt;/li&gt;
  &lt;li&gt;For a \(2 \times 2\) matrix: \(a \ge 0, c \ge 0, ac \ge b^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example applications:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Portfolio optimization:&lt;/strong&gt; \(\max \mu^T x - \frac{\gamma}{2}x^T P x\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVM:&lt;/strong&gt; \(\min \frac{1}{2}\lVert \beta \rVert_2^2 + C\sum \xi_i\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ridge regression:&lt;/strong&gt; \(\min \lVert Ax - b \rVert_2^2 + \lambda \lVert x \rVert_2^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-least-squares&quot;&gt;🎯 &lt;strong&gt;Least Squares&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Basic problem:&lt;/strong&gt;
\(\min_{x} \lVert Ax - b \rVert_2^2 = \min_{x} \sum_{i=1}^m (a_i^T x - b_i)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closed-form solution (Normal Equation):&lt;/strong&gt;
\(x^* = (A^T A)^{-1} A^T b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Condition for a unique solution:&lt;/strong&gt; \(A^T A\) invertible (\(A\) has full column rank)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple linear regression:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Model: \(y = mx + c\)&lt;/li&gt;
  &lt;li&gt;Solution: \(m = \frac{\sum(x_i - \bar{x})(y_i - \bar{y})}{\sum(x_i - \bar{x})^2}\), \(c = \bar{y} - m\bar{x}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Multiple linear regression:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Model: \(y = X\beta\)&lt;/li&gt;
  &lt;li&gt;Solution: \(\beta^* = (X^T X)^{-1} X^T y\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-other-canonical-problems&quot;&gt;🔢 &lt;strong&gt;Other Canonical Problems&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;QCQP (Quadratically Constrained QP):&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min &amp;amp;&amp;amp;\frac{1}{2}x^T P_0 x + q_0^T x \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;\frac{1}{2}x^T P_i x + q_i^T x + r_i \le 0, \quad i = 1,\ldots,m
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SOCP (Second-Order Cone Programming):&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min &amp;amp;&amp;amp;f^T x \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;\lVert A_i x + b_i \rVert_2 \le c_i^T x + d_i, \quad i = 1,\ldots,m
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SDP (Semidefinite Programming):&lt;/strong&gt;
\(\begin{align}
&amp;amp;\min &amp;amp;&amp;amp;\text{tr}(CX) \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;\text{tr}(A_i X) = b_i, \quad i = 1,\ldots,m \\
&amp;amp;&amp;amp;&amp;amp;X \succeq 0
\end{align}\)&lt;/p&gt;

&lt;h3 id=&quot;️-relations-between-the-problems&quot;&gt;🏗️ &lt;strong&gt;Relations Between the Problems&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;LP ⊆ QP ⊆ QCQP ⊆ SDP
    ⊆ SOCP ⊆
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP → QP:&lt;/strong&gt; Set \(P = 0\) in the QP&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QP → QCQP:&lt;/strong&gt; Linear constraints are a special case of quadratic constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SOCP → SDP:&lt;/strong&gt; Second-order cones can be represented by positive semidefinite (LMI) constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QCQP → SDP:&lt;/strong&gt; (Convex) QCQPs can be written as SDPs using the Schur complement&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-solution-algorithms&quot;&gt;🛠️ &lt;strong&gt;Solution Algorithms&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Linear Programming:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Simplex Method:&lt;/strong&gt; Move from vertex to vertex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior Point Methods:&lt;/strong&gt; Travel through the interior of the feasible set&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dual Simplex:&lt;/strong&gt; Start from a dual feasible solution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Quadratic Programming:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Active Set Methods:&lt;/strong&gt; Identify the active constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior Point Methods:&lt;/strong&gt; Extended from LP&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Projection:&lt;/strong&gt; Project the gradient step onto the feasible set&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Least Squares:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Normal Equation:&lt;/strong&gt; Direct solution \(x^* = (A^T A)^{-1} A^T b\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QR Decomposition:&lt;/strong&gt; More numerically stable&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVD:&lt;/strong&gt; Handles singular matrices&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent:&lt;/strong&gt; For large problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-real-world-applications&quot;&gt;📋 &lt;strong&gt;Real-World Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Linear Programming:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Production and distribution optimization&lt;/li&gt;
  &lt;li&gt;Diet planning&lt;/li&gt;
  &lt;li&gt;Portfolio management&lt;/li&gt;
  &lt;li&gt;Staff scheduling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Quadratic Programming:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Markowitz portfolio optimization&lt;/li&gt;
  &lt;li&gt;Support Vector Machines&lt;/li&gt;
  &lt;li&gt;Model Predictive Control&lt;/li&gt;
  &lt;li&gt;Image denoising&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Least Squares:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Linear and nonlinear regression&lt;/li&gt;
  &lt;li&gt;Curve fitting and interpolation&lt;/li&gt;
  &lt;li&gt;Signal processing&lt;/li&gt;
  &lt;li&gt;Computer vision&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-recognizing-the-problem-type&quot;&gt;🔍 &lt;strong&gt;Recognizing the Problem Type&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Checklist:&lt;/strong&gt;&lt;/p&gt;
&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Linear objective? → &lt;strong&gt;LP&lt;/strong&gt;&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Quadratic objective, linear constraints? → &lt;strong&gt;QP&lt;/strong&gt;&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Quadratic constraints? → &lt;strong&gt;QCQP&lt;/strong&gt;&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Norm constraints? → &lt;strong&gt;SOCP&lt;/strong&gt;&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Matrix constraints? → &lt;strong&gt;SDP&lt;/strong&gt;&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;No constraints, squared objective? → &lt;strong&gt;Least Squares&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-computational-complexity&quot;&gt;⚡ &lt;strong&gt;Computational Complexity&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Problem&lt;/th&gt;
      &lt;th&gt;Complexity&lt;/th&gt;
      &lt;th&gt;Notes&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;LP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Polynomial (interior point); Simplex fast in practice&lt;/td&gt;
      &lt;td&gt;Simplex: good on average&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Polynomial&lt;/td&gt;
      &lt;td&gt;Interior point methods&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Least Squares&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(O(n^3)\)&lt;/td&gt;
      &lt;td&gt;Normal equation&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SOCP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Polynomial&lt;/td&gt;
      &lt;td&gt;Similar to SDP&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SDP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Polynomial&lt;/td&gt;
      &lt;td&gt;Slower than LP, QP&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; Always start with the simplest problem class that solves your problem. LP is faster than QP, and QP is faster than SDP!&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Multiple-Choice Quiz: Canonical Optimization Problems&lt;/h2&gt;
        &lt;p&gt;Choose the best answer for each question. The quiz focuses on the basic concepts and practical applications of LP, QP and least squares.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Question 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Question 1: Which of the following characterizes linear programming (LP)?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) The objective and constraints are all linear functions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) The objective is quadratic, the constraints are linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) The objective is linear, the constraints are nonlinear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Both the objective and constraints are nonlinear&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The objective and constraints are all linear functions&lt;/strong&gt;&lt;br /&gt;
                Linear programming is defined by a linear objective with all constraints linear (affine).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The standard form of an LP has:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) Maximization, inequality constraints, free variables&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) Minimization, equality constraints, nonnegative variables&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Maximization, equality constraints, nonnegative variables&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Minimization, inequality constraints, free variables&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Minimization, equality constraints, nonnegative variables&lt;/strong&gt;&lt;br /&gt;
                Standard-form LP: minimize $$c^T x$$ subject to $$Ax = b$$, $$x \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: Slack variables are used to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) Turn equality constraints into inequalities&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Turn inequality constraints into equalities&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Increase the number of variables&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Reduce the computational complexity&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Turn inequality constraints into equalities&lt;/strong&gt;&lt;br /&gt;
                A slack variable turns $$Gx \leq h$$ into $$Gx + s = h$$ with $$s \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: The fundamental theorem of linear programming states that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) The optimal solution is always unique&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) If the LP has an optimal solution and the feasible region has a vertex, then there is always an optimal solution at a vertex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) The feasible region is always bounded&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) The objective always has a global minimum&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) If the LP has an optimal solution and the feasible region has a vertex, then there is always an optimal solution at a vertex&lt;/strong&gt;&lt;br /&gt;
                This is the basis of the Simplex algorithm: an optimal solution of an LP can always be found at a vertex.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: The Simplex algorithm works by:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Searching randomly in the feasible region&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Moving from vertex to vertex to improve the objective&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Using gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Bisecting the feasible region&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Moving from vertex to vertex to improve the objective&lt;/strong&gt;&lt;br /&gt;
                Simplex starts at a vertex and moves to an adjacent vertex that improves the objective value.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: A quadratic program (QP) has an objective of the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) $$c^T x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) $$\frac{1}{2}x^T P x + q^T x + r$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) $$\|Ax - b\|_2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) $$x^T A x^T$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\frac{1}{2}x^T P x + q^T x + r$$&lt;/strong&gt;&lt;br /&gt;
                A QP has a convex quadratic objective with matrix $$P \in \mathbb{S}_+^n$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: In a QP, the matrix $$P$$ must satisfy:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) $$P$$ is symmetric&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) $$P$$ is positive semidefinite&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) $$P$$ is invertible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) $$P$$ is diagonal&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$P$$ is positive semidefinite&lt;/strong&gt;&lt;br /&gt;
                The condition $$P \in \mathbb{S}_+^n$$ guarantees that the objective is convex.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: LP is a special case of QP when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) $$P = I$$ (identity matrix)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) $$P = 0$$ (zero matrix)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) $$q = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) $$r = 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$P = 0$$ (zero matrix)&lt;/strong&gt;&lt;br /&gt;
                When $$P = 0$$, the QP objective becomes $$q^T x + r$$, which is exactly an LP.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The linear least-squares problem has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) minimize $$\|Ax - b\|_1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) minimize $$\|Ax - b\|_2^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) minimize $$\|Ax - b\|_\infty$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) minimize $$x^T A x$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) minimize $$\|Ax - b\|_2^2$$&lt;/strong&gt;&lt;br /&gt;
                The least-squares problem minimizes the sum of squared errors.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: The solution of the least-squares problem is given by:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) $$x^* = A^{-1}b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) $$x^* = (A^T A)^{-1} A^T b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) $$x^* = A^T (AA^T)^{-1} b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) $$x^* = A^T b$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$x^* = (A^T A)^{-1} A^T b$$&lt;/strong&gt;&lt;br /&gt;
                This is the closed-form solution of the normal equation $$A^T A x = A^T b$$ (when $$A$$ has full column rank).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: In linear regression $$y = mx + c$$, the slope $$m$$ is computed as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) $$\frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) $$\frac{\sum (y_i - \bar{y})^2}{\sum (x_i - \bar{x})^2}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) $$\bar{y} - m\bar{x}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) $$\frac{\sum x_i y_i}{\sum x_i^2}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}$$&lt;/strong&gt;&lt;br /&gt;
                This is the standard formula for the slope in simple linear regression.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The Gauss-Markov assumptions do NOT include:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) The errors have zero mean&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) The errors are uncorrelated&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Constant variance (homoscedasticity)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Uniformly distributed errors&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) Uniformly distributed errors&lt;/strong&gt;&lt;br /&gt;
                The Gauss-Markov assumptions only require errors with zero mean, no correlation and constant variance; they assume no particular distribution (normality is not needed, let alone uniformity). The normality assumption is only added for inference (tests, confidence intervals) or to make OLS coincide with MLE.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: Maximum likelihood estimation (MLE) in linear regression is equivalent to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Maximizing the log-likelihood&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Minimizing the sum of squared errors&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Both A and B&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Maximizing R²&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) Both A and B&lt;/strong&gt;&lt;br /&gt;
                Under the Gaussian assumption, maximizing the log-likelihood is equivalent to minimizing the MSE.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: The diet problem is an example of:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Linear programming&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Quadratic programming&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Least squares&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Nonlinear programming&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Linear programming&lt;/strong&gt;&lt;br /&gt;
                The diet problem has a linear objective and linear constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: Portfolio optimization is an example of:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Linear programming&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Quadratic programming&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Least squares&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Integer programming&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Quadratic programming&lt;/strong&gt;&lt;br /&gt;
                Portfolio optimization balances return (linear) and risk (quadratic).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: The feasible region of an LP is called:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) Ellipsoid&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) A polytope (if bounded)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Simplex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Hyperplane&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) A polytope (if bounded)&lt;/strong&gt;&lt;br /&gt;
                The feasible region of an LP is an intersection of halfspaces, forming a polytope if it is bounded.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: The optimality condition for the least-squares problem is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) $$Ax = b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) $$A^T A x = A^T b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) $$A^T x = b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) $$x = 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$A^T A x = A^T b$$&lt;/strong&gt;&lt;br /&gt;
                This is the normal equation, the necessary and sufficient condition for the least-squares problem.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: The coefficient of determination R² measures:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) The mean error&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) The proportion of variance explained by the model&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) The standard deviation&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) The correlation coefficient&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The proportion of variance explained by the model&lt;/strong&gt;&lt;br /&gt;
                R² = 1 - (SSres/SStot) tells what percentage of the variation in the data the model explains.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: The complexity of the Simplex algorithm is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Polynomial&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Exponential in the worst case but efficient in practice&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Logarithmic&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Constant&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Exponential in the worst case but efficient in practice&lt;/strong&gt;&lt;br /&gt;
                Simplex has exponential worst-case complexity (e.g. Klee-Minty), but in practice the number of iterations is usually only about 2-3 times the number of constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: BLUE in linear regression stands for:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Best Linear Unbiased Estimator&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Basic Linear Uniform Estimation&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Bayesian Linear Update Equation&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Bounded Linear Uncertainty Estimate&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Best Linear Unbiased Estimator&lt;/strong&gt;&lt;br /&gt;
                Under the Gauss-Markov assumptions, OLS gives the best linear unbiased estimator.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: The standard form of an LP is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$\min c^T x$$ subject to $$Ax = b, x \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$\min c^T x$$ subject to $$Ax \leq b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$\max c^T x$$ subject to $$Ax \leq b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$\min c^T x$$ subject to $$Ax \geq b$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\min c^T x$$ subject to $$Ax = b, x \geq 0$$&lt;/strong&gt;&lt;br /&gt;
                The standard form of an LP is minimization with equality constraints and nonnegativity constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: In an SOCP, the cone constraint has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$\|Ax + b\|_2 \leq c^T x + d$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$\|Ax + b\|_1 \leq c^T x + d$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$\|Ax + b\|_\infty \leq c^T x + d$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$(Ax + b)^2 \leq c^T x + d$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\|Ax + b\|_2 \leq c^T x + d$$&lt;/strong&gt;&lt;br /&gt;
                SOCP uses second-order cone constraints with the Euclidean (L2) norm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: An SDP has the constraint:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Positive semidefinite matrix&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Symmetric matrix&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Triangular matrix&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Diagonal matrix&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Positive semidefinite matrix&lt;/strong&gt;&lt;br /&gt;
                An SDP constrains a matrix to be positive semidefinite: $$X \succeq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: A resource allocation problem with 3 projects and a budget of 100 can be modeled as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) LP&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) QP&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) SOCP&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) SDP&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) LP&lt;/strong&gt;&lt;br /&gt;
                A linear resource allocation problem is usually modeled by Linear Programming.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: In portfolio optimization, the objective is usually to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Minimize risk (variance)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Maximize return&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Balance risk and return&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above cases&lt;/strong&gt;&lt;br /&gt;
                Portfolio optimization can minimize risk, maximize return, or balance both (the Markowitz model).
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Previous&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Next&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Exercise Results&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #FF6B35, #F7931E);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #FF6B35;
    background-color: #fff5f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #FF6B35;
    background-color: #ffe5d6;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #fff5f0;
    border-left: 4px solid #FF6B35;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #D2691E;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #FF6B35;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #E55A2B;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #fff5f0;
    border-radius: 8px;
    border: 2px solid #FF6B35;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #D2691E;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answer for each question
const correctAnswers = {
    q1: &apos;a&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;b&apos;, q9: &apos;b&apos;, q10: &apos;b&apos;,
    q11: &apos;a&apos;, q12: &apos;d&apos;, q13: &apos;c&apos;, q14: &apos;a&apos;, q15: &apos;b&apos;,
    q16: &apos;b&apos;, q17: &apos;b&apos;, q18: &apos;b&apos;, q19: &apos;b&apos;, q20: &apos;a&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;d&apos;};

/**
 * Update the progress bar and show the current question
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Question ${currentQuestion}/${totalQuestions}`;
}

/**
 * Show a question by its number
 */
function showQuestion(questionNum) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Update the state of the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Go to the next question
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Go back to the previous question
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Store the user&apos;s answer
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Update the UI to show the selected answer
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Submit and show the results
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Compute the score and build the detailed report
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Show explanations for all questions
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Build the detailed report
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Question ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Correct&apos; : &apos;Incorrect&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Your answer: ${userAnswer || &apos;Not answered&apos;} | Correct answer: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Show the results
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Score: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Excellent! You have mastered the canonical optimization problems!&apos; :
              scorePercentage &gt;= 60 ? &apos;👍 Pretty good! Review a few concepts about LP and QP.&apos; :
              scorePercentage &gt;= 40 ? &apos;📚 You need more review of the Simplex algorithm and least squares.&apos; : &apos;💪 Reread the theory of the basic optimization problems!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Restart the exercise
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide the results and show the navigation again
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Clear all selections
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>05-06 Conic Programming (CP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_06_Conic_Programming_(CP)/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_06_Conic_Programming_(CP)</id>
   <content type="html">&lt;p&gt;After seeing LPs, SOCPs, and SDPs, you might notice a striking pattern: every single one minimizes a &lt;em&gt;linear&lt;/em&gt; objective \(c^T x\) subject to affine equalities \(Ax = b\) and a membership constraint saying that an affine expression must stay inside a convex cone \(K\). Conic Programming (CP) is the grand unified abstraction that captures all of them—plus exponential and power cones—under one mathematical roof and one solver API.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-unified-conic-framework&quot;&gt;Key ideas: The Unified Conic Framework&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Proper Cones and Generalized Inequalities&lt;/strong&gt;: A cone \(K \subseteq \mathbb{R}^m\) is &lt;em&gt;proper&lt;/em&gt; if it is convex, closed, solid (non-empty interior), and pointed (\(K \cap (-K) = \{0\}\)). Any proper cone induces a partial order \(u \preceq_K v \iff v - u \in K\), generalizing scalar \(\le\) to vectors and matrices.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;All Canonical Classes as Choices of \(K\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;LP&lt;/strong&gt;: \(K = \mathbb{R}^m_+\) (nonnegative orthant).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;SOCP&lt;/strong&gt;: \(K = \mathcal{Q}_{n_1} \times \cdots \times \mathcal{Q}_{n_r}\) (Cartesian product of second-order cones).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;SDP&lt;/strong&gt;: \(K = \mathbb{S}^k_+\) (positive semidefinite cone).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Exponential / Power Cones&lt;/strong&gt;: Handle logarithms, entropy, relative entropy, and \(p\)-norms cleanly inside modern conic solvers (like Clarabel and MOSEK).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Solvers Love Conic Form&lt;/strong&gt;: Moving all nonlinearity out of the objective and constraints and into a small library of standard cones \(K\) means a solver only needs to know the barrier function and dual cone \(K^\star = \{y : y^T x \ge 0 \;\forall x \in K\}\) for those few cones.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self-Dual Cones&lt;/strong&gt;: The three classical cones—\(\mathbb{R}^m_+\), \(\mathcal{Q}_n\), and \(\mathbb{S}^k_+\)—are &lt;em&gt;self-dual&lt;/em&gt; (\(K^\star = K\)), which gives primal–dual interior-point methods extraordinary symmetry and numerical precision.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-unifying-an-lp-and-an-socp-inside-one-product-cone&quot;&gt;Worked example: Unifying an LP and an SOCP Inside One Product Cone&lt;/h3&gt;

&lt;p&gt;Consider minimizing \(x_1 + x_2\) subject to \(x_1 \ge 1\) and \(\sqrt{x_1^2 + x_2^2} \le 2\). Let us express this single problem as a standard Conic Program \(\min c^T x \text{ s.t. } Fx + g \preceq_K 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify the required product cone \(K\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Constraint 1 (\(x_1 \ge 1 \iff 1 - x_1 \le 0\)) lives in the 1D nonnegative orthant \(K_1 = \mathbb{R}_+\).&lt;/li&gt;
      &lt;li&gt;Constraint 2 (\(\|x\|_2 \le 2 \iff (x_1, x_2, 2) \in \mathcal{Q}_3\)) lives in the 3D second-order cone \(K_2 = \mathcal{Q}_3\).&lt;/li&gt;
      &lt;li&gt;Combine them into the product cone \(K = \mathbb{R}_+ \times \mathcal{Q}_3 \subseteq \mathbb{R}^4\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write \(s = -(Fx + g) \in K\) explicitly&lt;/strong&gt;:
\(s = \begin{bmatrix} x_1 - 1 \\ x_1 \\ x_2 \\ 2 \end{bmatrix} = \underbrace{\begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}}_{-F} \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + \underbrace{\begin{bmatrix} -1 \\ 0 \\ 0 \\ 2 \end{bmatrix}}_{-g} \in \mathbb{R}_+ \times \mathcal{Q}_3.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the conic program geometrically&lt;/strong&gt;: We want the smallest \(x_1 + x_2\) inside the disk \(x_1^2 + x_2^2 \le 4\) with \(x_1 \ge 1\).
    &lt;ul&gt;
      &lt;li&gt;To minimize \(x_1 + x_2\), push \(x_1\) as small as allowed (\(x_1^\star = 1\)) and \(x_2\) as negative as the disk permits: \(x_2^\star = -\sqrt{4 - 1^2} = -\sqrt{3}\).&lt;/li&gt;
      &lt;li&gt;Check gradient/feasibility on the boundary: at \(x = (1, -\sqrt{3})\), \(s = (0, 1, -\sqrt{3}, 2)^T\) has \(s_1 = 0 \in \mathbb{R}_+\) and \(\sqrt{1^2 + (-\sqrt{3})^2} = 2 \le 2\), so \(s \in K\) and \(f^\star = 1 - \sqrt{3} \approx -0.732\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the inequality constraint in a general LP is replaced by a generalized inequality constraint, the problem is called a &lt;em&gt;Conic Program&lt;/em&gt; (CP).&lt;/p&gt;

&lt;h3 id=&quot;conic-program&quot;&gt;Conic Program&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Fx + g \preceq_K 0} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;c, x \in \mathbb{R}^{n}, A \in \mathbb{R}^{p \times n}, \text{and } b \in \mathbb{R}^{p}.
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;\(F: \mathbb{R}^n \rightarrow Y\) is a linear map, \(g \in Y\), for Euclidean space \(Y\).&lt;/li&gt;
  &lt;li&gt;LP is the special case when \(K = \mathbb{R}_{+}^n\), i.e., LP \(\subseteq\) CP.&lt;/li&gt;
  &lt;li&gt;SDP is the special case when \(K = \mathbb{S}_{+}^n\), i.e., SDP \(\subseteq\) CP.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>05-05 Semidefinite Programming (SDP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_05_Semidefinite_Programming_(SDP)/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_05_Semidefinite_Programming_(SDP)</id>
   <content type="html">&lt;p&gt;In Linear Programming, variables satisfy scalar inequalities \(x_i \ge 0\). Now lift that single idea from numbers to symmetric matrices: instead of requiring scalars to be nonnegative, require an entire symmetric matrix \(X\) to have all nonnegative eigenvalues (\(X \succeq 0\)). That leap produces Semidefinite Programming (SDP)—a convex powerhouse capable of certifying robot stability, bounding NP-hard graph cuts (Goemans–Williamson Max-Cut), and verifying neural-network robustness.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-optimizing-over-the-positive-semidefinite-cone&quot;&gt;Key ideas: Optimizing Over the Positive Semidefinite Cone&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Linear Matrix Inequalities (LMIs)&lt;/strong&gt;: An SDP minimizes a linear objective \(c^T x\) subject to \(F(x) = F_0 + \sum_{i=1}^n x_i F_i \preceq 0\) (where each \(F_i \in \mathbb{S}^k\) is symmetric) and \(Ax = b\). Equivalently, in standard conic form: \(\min \langle C, X \rangle\) subject to \(\langle A_i, X \rangle = b_i\) and \(X \succeq 0\), where \(\langle C, X \rangle = \operatorname{tr}(C^T X)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Schur Complement Bridge&lt;/strong&gt;: A convex quadratic constraint or second-order cone constraint \(\|u\|_2 \le t\) embeds seamlessly into an SDP via the Schur complement:
\(\|u\|_2 \le t \iff \begin{bmatrix} t I &amp;amp; u \\ u^T &amp;amp; t \end{bmatrix} \succeq 0.\)
Thus every LP, QP, QCQP, and SOCP is a special case of an SDP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Eigenvalue Optimization&lt;/strong&gt;: Minimizing the largest eigenvalue \(\lambda_{\max}(A(x))\) of an affine symmetric matrix family is an exact SDP: minimize \(t\) subject to \(A(x) \preceq tI\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SDP Relaxations of Combinatorial Problems&lt;/strong&gt;: By lifting \(x \in \{-1, +1\}^n\) to the rank-1 matrix \(X = xx^T\) (which satisfies \(X \succeq 0\) and \(X_{ii} = 1\)) and dropping the nonconvex constraint \(\operatorname{rank}(X) = 1\), we obtain tight polynomial-time convex relaxations for Max-Cut, sensor localization, and phase retrieval.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-minimizing-the-largest-eigenvalue-via-an-lmi&quot;&gt;Worked example: Minimizing the Largest Eigenvalue via an LMI&lt;/h3&gt;

&lt;p&gt;Find \(x \in \mathbb{R}\) that minimizes the largest eigenvalue \(\lambda_{\max}(A(x))\) of the \(2 \times 2\) matrix
\(A(x) = \begin{bmatrix} 1 + x &amp;amp; 2 \\ 2 &amp;amp; 5 - x \end{bmatrix}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Formulate as an SDP&lt;/strong&gt;: Introduce scalar \(t \in \mathbb{R}\) and enforce \(A(x) \preceq tI\), i.e., \(tI - A(x) \succeq 0\):
\(\min_{x, t} \; t \quad \text{subject to} \quad M(x, t) = \begin{bmatrix} t - 1 - x &amp;amp; -2 \\ -2 &amp;amp; t - 5 + x \end{bmatrix} \succeq 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply Sylvester’s criterion for \(2 \times 2\) positive semidefiniteness&lt;/strong&gt;: \(M(x, t) \succeq 0\) holds iff the diagonal entries and determinant are nonnegative:
    &lt;ul&gt;
      &lt;li&gt;\(t - 1 - x \ge 0\) and \(t - 5 + x \ge 0\),&lt;/li&gt;
      &lt;li&gt;\(\det M(x, t) = (t - 1 - x)(t - 5 + x) - 4 \ge 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rewrite the determinant cleanly&lt;/strong&gt;: Notice that the sum of the two diagonal entries is \((t - 1 - x) + (t - 5 + x) = 2(t - 3)\), independent of \(x\)! Let \(u = x - 2\) so the two diagonal entries are \((t - 3) - u\) and \((t - 3) + u\). Then
\(\det M(x, t) = (t - 3)^2 - u^2 - 4 \ge 0 \iff (t - 3)^2 \ge 4 + u^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find the exact minimum&lt;/strong&gt;: To make \(t \ge 3\) as small as possible, set \(u = 0 \implies x^\star = 2\), which gives \((t - 3)^2 \ge 4 \implies t^\star = 5\).
Verify directly: at \(x^\star = 2\), \(A(2) = \begin{bmatrix} 3 &amp;amp; 2 \\ 2 &amp;amp; 3 \end{bmatrix}\), whose eigenvalues are \(3 + 2 = 5\) and \(3 - 2 = 1\). For any \(x \neq 2\), the eigenvalues spread wider and \(\lambda_{\max}(A(x)) = 3 + \sqrt{(x - 2)^2 + 4} &amp;gt; 5\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the inequality constraint in a general LP is replaced by a linear matrix inequality (LMI), the problem is called a &lt;em&gt;Semidefinite Program&lt;/em&gt; (SDP).&lt;/p&gt;

&lt;h3 id=&quot;semidefinite-program&quot;&gt;Semidefinite Program&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{x_1 F_1 + \dotsb + x_n F_n + G \preceq 0} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;G, F_1, \dotsb, F_n \in \mathbb{S}^{k} \text{ and } A \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;If \(G, F_1, \dotsb, F_n\) are all diagonal matrices, the above inequality constraint is equivalent to \(n\) linear inequalities, and the SDP reduces to an LP.&lt;/li&gt;
  &lt;li&gt;Multiple LMIs can be represented as a single LMI using block diagonal matrices:
    &lt;blockquote&gt;
      &lt;p&gt;\(x_1\hat{F_1} + \dotsb + x_n\hat{F_n} + \hat{G} \preceq 0, \quad x_1\tilde{F_1} + \dotsb + x_n\tilde{F_n} + \tilde{G} \preceq 0\)
is equivalent to a single LMI:
\(x_1
\begin{bmatrix}
    \hat{F_1} &amp;amp; 0 \\\\
    0 &amp;amp; \tilde{F_1} \\\\
\end{bmatrix} + 
x_2
\begin{bmatrix}
    \hat{F_2} &amp;amp; 0 \\\\
    0 &amp;amp; \tilde{F_2} \\\\
\end{bmatrix} + 
\dotsb
+
x_n
\begin{bmatrix}
    \hat{F_n} &amp;amp; 0 \\\\
    0 &amp;amp; \tilde{F_n} \\\\
\end{bmatrix} + 
\begin{bmatrix}
    \hat{G} &amp;amp; 0 \\\\
    0 &amp;amp; \tilde{G} \\\\
\end{bmatrix}
\preceq 0\)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;sdp-in-standard-form&quot;&gt;SDP in Standard form&lt;/h2&gt;
&lt;p&gt;When expressed as follows, it is called the standard form of a semidefinite program.&lt;/p&gt;

&lt;h3 id=&quot;standard-form-sdp&quot;&gt;Standard form SDP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{X} &amp;amp;&amp;amp;{\mathrm{tr}(CX)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\mathrm{tr}(A_i X) = b_i, \quad i = 1, \dotsc, m} \\\\
   &amp;amp; &amp;amp;&amp;amp;{X \succeq 0},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;C, A_i \in \mathbb{S}^n, X \in \mathbb{S}^n.
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Recall: \(\mathrm{tr}(CX) = \sum_{i,j=1}^n C_{ij}X_{ij}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All SDPs can be transformed into the standard form SDP through the following process.&lt;/p&gt;

&lt;h3 id=&quot;converting-sdps-to-standard-form&quot;&gt;Converting SDPs to standard form&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Step1.&lt;/strong&gt;  Use a slack variable S to convert the inequality constraint into an equality constraint.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\sum_{l=1}^n F_l x_l+ S = -G} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b}\\\\
   &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step2.&lt;/strong&gt; Transform the equality constraints derived in Step 1 into component-wise equations.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\sum_{l=1}^n (F_l x_l)_{ij} + S_{ij} = -G_{ij}, i,j = 1, \dotsc, k} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b}\\\\
   &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step3.&lt;/strong&gt; Replace x with two nonnegative variables.
\(x = x^{+}  - x^{-}\), where \(x^{+} \text{ and } x^{-} \succeq 0.\)&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T (x^{+}  - x^{-}) + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\sum_{l=1}^n (F_l x^{+} _l)_{ij} - \sum_{l=1}^n (F_l x^{-} _l)_{ij} + S_{ij} = -G_{ij}, i,j = 1, \dotsc, k} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax^{+}  - Ax^{-} = b}\\\\
   &amp;amp; &amp;amp;&amp;amp;{S \succeq 0}\\\\
   &amp;amp; &amp;amp;&amp;amp;{x^{+} \text{, } x^{-} \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step4.&lt;/strong&gt; Define \(X, C, \tilde{A}, \tilde{b}\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;All the blanks are zero.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(X = 
\begin{bmatrix}
diag(x^{+})\\\\
 &amp;amp; diag(x^{-})\\\\
&amp;amp;&amp;amp; s_{11}\\\\
&amp;amp;&amp;amp;&amp;amp; s_{12}\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;\dotsc\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;s_{ij}\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;\dotsc \\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;s_{kk}\\\\
\end{bmatrix}
,\)
\(C = 
\begin{bmatrix}
diag(c)\\\\
&amp;amp; -diag(c) &amp;amp;\\\\
&amp;amp; &amp;amp; O_{k^2 \text{ x } k^2}\\\\
\end{bmatrix}
,\)
\(P_{ij} = 
\begin{bmatrix}
(F_1)_{ij}\\\\
&amp;amp;(F_2)_{ij}\\\\
&amp;amp;&amp;amp;\dotsc\\\\
&amp;amp;&amp;amp;&amp;amp;(F_n)_{ij}\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;-(F_1)_{ij}\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;-(F_2)_{ij}\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;\dotsc\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;-(F_n)_{ij}\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;0&amp;amp;\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;\dotsc\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;1 \phantom{1} (\text{ij th position})\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;\dotsc\\\\
&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;0\\\\
\end{bmatrix}
,\)&lt;/p&gt;

  &lt;p&gt;\(Q_{i}= 
\begin{bmatrix}
diag(A_i)\\\\
&amp;amp;-diag(A_i)\\\\
&amp;amp;&amp;amp;O_{k^2 \text{ x } k^2}\\\\
\end{bmatrix}\)
(\(A_i\) is ith row of A),
\(\tilde{A} = 
\begin{bmatrix}
P_{11}\\\\
\dotsc\\\\
P_{kk}\\\\
Q_{1}\\\\
\dotsc\\\\
Q_{p}\\\\
\end{bmatrix}
-G_{ij} = \mathrm{tr}(P_{ij}X)
,\)&lt;/p&gt;

  &lt;p&gt;\(b_i = \mathrm{tr}(Q_iX)\),&lt;/p&gt;

  &lt;p&gt;\(\tilde{b} = 
\begin{bmatrix}
-G_{11}\\\\
\dotsc\\\\
-G_{kk}\\\\
b_{1}\\\\
\dotsc\\\\
b_{p}\\\\
\end{bmatrix}\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step5.&lt;/strong&gt; Substitute the problem from &lt;em&gt;Step3&lt;/em&gt; with \(X, C, \tilde{A}, \tilde{b}\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{X} &amp;amp;&amp;amp;{\mathrm{tr}(CX)} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\mathrm{tr}(\tilde{A}_iX) = \tilde{b}_i, \quad i=1,\dotsc,k^2+p} \\\\
   &amp;amp; &amp;amp;&amp;amp;{X \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;socp-and-equivalent-sdp&quot;&gt;SOCP and equivalent SDP&lt;/h2&gt;
&lt;p&gt;By using the Schur complement[&lt;a href=&quot;https://en.wikipedia.org/wiki/Schur_complement&quot;&gt;8&lt;/a&gt;], the inequality constraint of SOCP can be expressed in such a way that SOCP is transformed into a special case of SDP. That is, there is a relationship of inclusion: SOCP \(\subseteq\) SDP.&lt;/p&gt;

&lt;h3 id=&quot;recall-second-order-cone-program&quot;&gt;Recall: Second-Order Cone Program&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{f^T x} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\| A_i x + b_i \|_2 \leq c_i^T x + d_i, i = 1, \dotsc, m}\\\\
   &amp;amp; &amp;amp;&amp;amp;{Fx = g}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;socp-to-sdp-by-schur-complement&quot;&gt;SOCP to SDP by Schur complement&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{f^T x} \\\\
   &amp;amp;\text{subject to } 
   &amp;amp;&amp;amp;
   \begin{bmatrix}
   (c_i^T x + d)I    &amp;amp; A_i x + b_i \\\\
   (A_i x + b_i)^T &amp;amp; c_i^T x + d \\\\
   \end{bmatrix} \succeq 0, i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Fx = g}.
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>05-04 Second-Order Cone Programming (SOCP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_04_Second_Order_Cone_Programming_(SOCP)/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_04_Second_Order_Cone_Programming_(SOCP)</id>
   <content type="html">&lt;p&gt;Picture an upside-down ice-cream cone standing in 3D space: \(\{(u, t) : \|u\|_2 \le t\}\). That clean geometric shape—the &lt;em&gt;second-order (Lorentz) cone&lt;/em&gt;—unlocks a surprisingly vast slice of modern engineering. From robust linear programming under ellipsoidal uncertainty to rocket landing trajectories (used in SpaceX’s powered-descent guidance!), Second-Order Cone Programming (SOCP) handles Euclidean norm constraints natively and fast.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-inside-the-second-order-cone&quot;&gt;Key ideas: Inside the Second-Order Cone&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Standard SOCP Structure&lt;/strong&gt;: An SOCP minimizes a linear objective \(f^T x\) subject to affine equalities \(Fx = g\) and second-order cone constraints \(\|A_i x + b_i\|_2 \le c_i^T x + d_i\). Equivalently, the affine map \((A_i x + b_i,\; c_i^T x + d_i)\) must belong to the norm cone \(\mathcal{Q}_{n_i + 1} = \{(u, t) : \|u\|_2 \le t\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Subsuming LP, QP, and QCQP&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Setting \(A_i = 0, b_i = 0\) yields scalar linear inequalities \(0 \le c_i^T x + d_i\) (LP).&lt;/li&gt;
      &lt;li&gt;Using the hyperbolic identity \(u^T u \le s t \iff \left\|\begin{bmatrix} 2u \\ s - t \end{bmatrix}\right\|_2 \le s + t\) (for \(s, t \ge 0\)) converts every convex quadratic objective or inequality into a rotated second-order cone constraint (QP and QCQP).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust Linear Programming as an SOCP&lt;/strong&gt;: Suppose a linear constraint \(a^T x \le b\) must hold for &lt;em&gt;every&lt;/em&gt; uncertain vector \(a\) inside an ellipsoid \(\mathcal{E} = \{\bar{a} + Pu : \|u\|_2 \le 1\}\). Taking the worst case gives \(\sup_{\|u\|_2 \le 1} (\bar{a} + Pu)^T x = \bar{a}^T x + \|P^T x\|_2 \le b\)—an exact SOCP constraint!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why SOCPs Are Fast&lt;/strong&gt;: Even though SOCPs are far more expressive than LPs, primal–dual interior-point solvers handle Lorentz cones with a simple 2-parameter self-concordant barrier \(-\ln(t^2 - \|u\|_2^2)\), scaling to hundreds of thousands of variables.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-rewriting-a-robust-linear-constraint-as-an-socp&quot;&gt;Worked example: Rewriting a Robust Linear Constraint as an SOCP&lt;/h3&gt;

&lt;p&gt;Suppose a chemical blend \(x = (x_1, x_2)^T \ge 0\) must satisfy \(a_1 x_1 + a_2 x_2 \le 10\) for &lt;em&gt;all&lt;/em&gt; uncertain coefficients \(a = (a_1, a_2)^T\) within a Euclidean ball of radius \(r = 0.5\) around the nominal vector \(\bar{a} = (2, 3)^T\), i.e., \(\|a - \bar{a}\|_2 \le 0.5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Express the worst-case left-hand side&lt;/strong&gt;: Write \(a = \bar{a} + 0.5 u\) with \(\|u\|_2 \le 1\). Then
\(\max_{\|u\|_2 \le 1} (\bar{a} + 0.5 u)^T x = \bar{a}^T x + 0.5 \max_{\|u\|_2 \le 1} (u^T x) = 2x_1 + 3x_2 + 0.5\|x\|_2.\)
(By Cauchy–Schwarz, the maximum occurs at \(u = x / \|x\|_2\).)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write the exact SOCP constraint&lt;/strong&gt;:
\(\|0.5 I_2 x\|_2 \le -2x_1 - 3x_2 + 10,\)
matching \(\|A_1 x + b_1\|_2 \le c_1^T x + d_1\) with \(A_1 = 0.5 I_2\), \(b_1 = 0\), \(c_1 = (-2, -3)^T\), \(d_1 = 10\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test a candidate point \(x = (2, 1.5)\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Nominal usage: \(2(2) + 3(1.5) = 4 + 4.5 = 8.5 \le 10\) (nominally feasible with 1.5 margin).&lt;/li&gt;
      &lt;li&gt;Worst-case uncertainty buffer: \(0.5\sqrt{2^2 + 1.5^2} = 0.5\sqrt{6.25} = 0.5(2.5) = 1.25\).&lt;/li&gt;
      &lt;li&gt;Total worst-case usage: \(8.5 + 1.25 = 9.75 \le 10\), so \(x = (2, 1.5)\) is &lt;strong&gt;robustly feasible&lt;/strong&gt; against every perturbation in the ball!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the inequality constraints in a general LP are replaced with second-order cone constraints (which are affine functions), the problem is called a &lt;em&gt;Second-Order Cone Program&lt;/em&gt; (SOCP).&lt;/p&gt;

&lt;h3 id=&quot;second-order-cone-program&quot;&gt;Second-Order Cone Program&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{f^T x} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\| A_i x + b_i \|_2 \leq c_i^T x + d_i, i = 1, \dotsc, m}\\\\
   &amp;amp; &amp;amp;&amp;amp;{Fx = g},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;x \in \mathbb{R}^n \text{ is the optimization variable, } A_i  \in \mathbb{R}^{n_i \times n}, \text{ and } F \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;recall-norm-cone&quot;&gt;Recall: Norm cone&lt;/h3&gt;
&lt;p&gt;A &lt;em&gt;norm cone&lt;/em&gt; is a convex cone in \(\mathbb{R}^{n+1}\) defined by all points \((x, t)\) such that \(\| x \| \le t\) for some norm \(\| \cdot \|\).&lt;/p&gt;

&lt;blockquote&gt;
\[\left\{(x, t) : \| x \| \le t \right\} \text{, for a norm } \| \cdot \|\]
&lt;/blockquote&gt;

&lt;p&gt;The figure below shows the norm cone for the \(l_2\) norm \(\| \cdot \|_2\), also called the second-order cone or ice cream cone.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter05/05_04_norm_cone.png&quot; alt=&quot;[Fig1] Norm Cone [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Norm Cone [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;qcqp-and-equivalent-socp&quot;&gt;QCQP and equivalent SOCP&lt;/h2&gt;
&lt;p&gt;A QCQP can be reformulated as an SOCP in certain cases, i.e., \(QCQP \subseteq SOCP\).&lt;/p&gt;

&lt;h3 id=&quot;recall-quadratically-constrained-quadratic-program&quot;&gt;Recall: Quadratically Constrained Quadratic Program&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{(1/2)x^T P_0 x + q_0^T x + r_0} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{(1/2)x^T P_i x + q_i^T x + r_i \leq 0}, i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;P_i \in \mathbb{S}_{+}^n \text{ for } i = 0, \dotsc, m, \text{ and } A \in \mathbb{R}^{p \times n}
\end{align}\]

  &lt;p&gt;&lt;strong&gt;Step 1.&lt;/strong&gt; For convenience, QCQP can be reformulated in different ways to fit SOCP structure.
\(\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{x^T P_0 x + 2q_0^T x + r_0} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{x^T P_i x + 2q_i^T x + r_i \leq 0}, i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp; P_i \in \mathbb{S}_{+}^n \text{ for } i = 0, \dotsc, m \text{, and } A \in \mathbb{R}^{\text{p x n}}.
\end{align}\\\)&lt;/p&gt;

&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 2.&lt;/strong&gt; Since \(P_0\) is a positive semidefinite matrix, any \(\tilde{P_0}\) satisfying \(P_0 = \tilde{P_0}\tilde{P_0}\) is also a positive semidefinite matrix. This \(\tilde{P_0}\) can be obtained through eigendecomposition. Using this, the objective function of the QCQP can be transformed as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[P_0 = Q_0 \Lambda_0 \Lambda_0 Q_0^T\]
  &lt;/li&gt;
  &lt;li&gt;
\[I = Q_0 \Lambda_0 \Lambda_0^{-1} Q_0^{-1} = Q_0 \Lambda_0^{-1} \Lambda_0 Q_0^{-1}\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\begin{align}
{x^T P_0 x + 2q_0^T x + r_0} &amp;amp;= {x^T P_0 x + q_0^T x + x^T q_0 + q_0^T P_0^{-1} q_0 - q_0^T P_0^{-1} q_0 + r_0}\\\\
&amp;amp;= {x^T Q_0 \Lambda_0 \Lambda_0 Q_0^T x} +
     {q_0^T Q_0 \Lambda_0^{-1} \Lambda_0 Q_0^{-1} x} + {x^T Q_0 \Lambda_0 \Lambda_0^{-1} Q_0^{-1} q_0} +
     {q_0^T Q_0 \Lambda_0^{-1} \Lambda_0^{-1} Q_0^T q_0} - {q_0^T P_0^{-1} q_0 + r_0}\\\\
&amp;amp;=(\Lambda_0 Q_0^T x + \Lambda_0^{-1} Q_0^T q_0)^T(\Lambda_0 Q_0^T x + \Lambda_0^{-1} Q_0^T q_0) - {q_0^T P_0^{-1} q_0 + r_0}\\\\
&amp;amp;=\| \Lambda_0 Q_0^T x + \Lambda_0^{-1} Q_0^T q_0 \|_2^2 - {q_0^T P_0^{-1} q_0 + r_0}\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 3.&lt;/strong&gt; The same procedure as in Step 2 is applied to the inequality constraint functions, and then substituted into the QCQP from Step 1.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{\| \Lambda_0 Q_0^T x + \Lambda_0^{-1} Q_0^T q_0 \|_2^2 - {q_0^T P_0^{-1} q_0 + r_0}} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\| \Lambda_i Q_i^T x + \Lambda_i^{-1} Q_i^T q_i \|_2^2 \leq {q_i^T P_i^{-1} q_i + r_i}}, i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b}.\\\\
\end{align}\]

&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 4.&lt;/strong&gt; The term \({q_0^T P_0^{-1} q_0 + r_0}\) in the objective function is a constant and can be omitted.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{\| \Lambda_0 Q_0^T x + \Lambda_0^{-1} Q_0^T q_0 \|_2^2} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{\| \Lambda_i Q_i^T x + \Lambda_i^{-1} Q_i^T q_i \|_2^2 \leq {q_i^T P_i^{-1} q_i + r_i} }, i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 5.&lt;/strong&gt; Introducing a scalar variable \(t\), the same problem as in Step 4 can be defined.&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x, t} &amp;amp;&amp;amp;{t} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;\lVert{\Lambda_{0} Q_0^T x + \Lambda_0^{-1} Q_0^T q_0} \rVert_2^2 \leq t\\\\
   &amp;amp; &amp;amp;&amp;amp;{\| \Lambda_i Q_i^T x + \Lambda_i^{-1} Q_i^T q_i \|_2^2 \leq {q_i^T P_i^{-1} q_i + r_i} }, i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b}.\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The above represents a special case of SOCP. Thus, the relationship \(QCQP \subseteq SOCP\) holds.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-03 Quadratically Constrained Quadratic Programming (QCQP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_03_Quadratically_Constrained_Quadratic_Programming_(QCQP)/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_03_Quadratically_Constrained_Quadratic_Programming_(QCQP)</id>
   <content type="html">&lt;p&gt;Sometimes a quadratic objective is not enough—the &lt;em&gt;constraints&lt;/em&gt; themselves are curved. When a robot must stay inside a circular safety zone, an antenna array must obey a total power budget \(\|w\|_2^2 \le P_{\max}\), or a portfolio must cap its variance \(x^T \Sigma x \le \sigma_{\max}^2\), the feasible region becomes an intersection of ellipsoids rather than flat walls. That is the domain of Quadratically Constrained Quadratic Programming (QCQP).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-and-reformulations-of-qcqps&quot;&gt;Key ideas: Geometry and Reformulations of QCQPs&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Convexity Condition on Every Matrix \(P_i\)&lt;/strong&gt;: A QCQP minimizes \(\frac{1}{2}x^T P_0 x + q_0^T x + r_0\) subject to \(\frac{1}{2}x^T P_i x + q_i^T x + r_i \le 0\) (\(i = 1, \dots, m\)) and \(Ax = b\). The problem is convex if and only if &lt;strong&gt;every&lt;/strong&gt; symmetric matrix \(P_0, P_1, \dots, P_m \in \mathbb{S}_+^n\) is positive semidefinite.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric Picture — Intersection of Ellipsoids&lt;/strong&gt;: Each inequality \(\frac{1}{2}x^T P_i x + q_i^T x + r_i \le 0\) defines an ellipsoid (when \(P_i \succ 0\)) or an elliptic cylinder (when \(P_i \succeq 0\) is singular). Notice that setting \(P_1 = \dots = P_m = 0\) recovers a QP, and further setting \(P_0 = 0\) recovers an LP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Every Convex QCQP Rewrites as an SOCP&lt;/strong&gt;: Factoring \(P_i = L_i L_i^T\) lets you complete the square and turn any convex quadratic inequality into a Euclidean norm constraint \(\|A_i x + b_i\|_2 \le c_i^T x + d_i\), allowing modern conic solvers (like Clarabel or ECOS) to solve QCQPs natively.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warning on Nonconvex QCQPs&lt;/strong&gt;: If even a single \(P_i\) has a negative eigenvalue (or if a quadratic constraint is written as an &lt;em&gt;equality&lt;/em&gt; \(x^T P_i x = 1\)), the problem becomes nonconvex and generally NP-hard—requiring SDP relaxation (Shor relaxation) to obtain tight lower bounds.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-solving-a-disk-constrained-quadratic-program&quot;&gt;Worked example: Solving a Disk-Constrained Quadratic Program&lt;/h3&gt;

&lt;p&gt;Minimize \(f_0(x_1, x_2) = (x_1 - 3)^2 + (x_2 - 4)^2\) subject to the quadratic ball constraint \(x_1^2 + x_2^2 \le 4\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Verify standard convex QCQP form&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Objective: \(f_0(x) = \frac{1}{2}x^T (2I) x + (-6, -8)x + 25\), so \(P_0 = 2I \succ 0\).&lt;/li&gt;
      &lt;li&gt;Constraint: \(\frac{1}{2}x^T (2I) x - 4 \le 0\), so \(P_1 = 2I \succ 0\). Both matrices are positive definite, guaranteeing a unique global minimizer.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the unconstrained minimizer&lt;/strong&gt;: \(x_{\mathrm{unc}} = (3, 4)\) has \(\|x_{\mathrm{unc}}\|_2^2 = 3^2 + 4^2 = 25 &amp;gt; 4\), so it lies outside the disk of radius \(2\). Thus the quadratic constraint must be active: \(\|x^\star\|_2 = 2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the KKT stationarity condition&lt;/strong&gt;: With multiplier \(\lambda \ge 0\) for \(g_1(x) = x_1^2 + x_2^2 - 4 \le 0\),
\(\nabla f_0(x) + \lambda \nabla g_1(x) = 0 \implies 2(x - x_{\mathrm{unc}}) + 2\lambda x = 0 \implies (1 + \lambda) x = (3, 4).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve for \(\lambda^\star\) and \(x^\star\)&lt;/strong&gt;: Taking norms of \((1 + \lambda)x^\star = (3, 4)\) gives
\((1 + \lambda)\|x^\star\|_2 = \|(3, 4)\|_2 = 5 \implies (1 + \lambda)(2) = 5 \implies 1 + \lambda^\star = 2.5 \implies \lambda^\star = 1.5 &amp;gt; 0.\)
Hence \(x^\star = \frac{1}{2.5}(3, 4) = (1.2, 1.6)\). Check feasibility: \(1.2^2 + 1.6^2 = 1.44 + 2.56 = 4\). Optimal value: \((1.2 - 3)^2 + (1.6 - 4)^2 = (-1.8)^2 + (-2.4)^2 = 3.24 + 5.76 = 9 = (5 - 2)^2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the inequality constraint functions in a quadratic program are replaced with convex quadratic functions, the problem is called a &lt;em&gt;Quadratically Constrained Quadratic Program&lt;/em&gt; (QCQP).&lt;/p&gt;

&lt;h3 id=&quot;quadratically-constrained-quadratic-program&quot;&gt;Quadratically Constrained Quadratic Program&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{(1/2)x^T P_0 x + q_0^T x + r_0} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{(1/2)x^T P_i x + q_i^T x + r_i \leq 0}, i = 1, \dotsc, m\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;P_i \in \mathbb{S}_{+}^n \text{ for } i = 0, \dotsc, m, \text{ and } A \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;qp-and-equivalent-qcqp&quot;&gt;QP and equivalent QCQP&lt;/h2&gt;
&lt;p&gt;If \(P_i = 0\) for all \(i = 1, \dotsc, m\) in the QCQP constraints, the problem reduces to a QP. Thus, QP is a special case of QCQP, and \(QP \subseteq QCQP\).&lt;/p&gt;

&lt;h3 id=&quot;recall-quadratic-program&quot;&gt;Recall: Quadratic Program&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{(1/2)x^T P x + q^T x + r} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Gx \preceq h} \\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp; \text{where } &amp;amp;&amp;amp;P \in \mathbb{S}_{+}^n, G \in \mathbb{R}^{m \times n}, \text{ and } A \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>05-02 Quadratic Programming (QP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_02_Quadratic_Programming_(QP)-copy/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_02_Quadratic_Programming_(QP) copy</id>
   <content type="html">&lt;p&gt;Linear Programming always pushes solutions to sharp corners—great for shipping containers, terrible for financial portfolios where putting 100% of your wealth into a single stock is reckless. By adding a smooth convex quadratic bowl \(\frac{1}{2}x^T P x\) to the objective, Quadratic Programming (QP) balances linear rewards against quadratic risk or energy, producing interior diversification and powering everything from Markowitz portfolios to Support Vector Machines and Model Predictive Control.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-structure-and-geometry-of-quadratic-programs&quot;&gt;Key ideas: Structure and Geometry of Quadratic Programs&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Positive Semidefiniteness (\(P \in \mathbb{S}_+^n\)) Guarantees Convexity&lt;/strong&gt;: The Hessian of \(f(x) = \frac{1}{2}x^T P x + q^T x + r\) is the constant matrix \(P\) (assuming \(P = P^T\)). Requiring \(P \succeq 0\) ensures the objective is globally convex; if \(P \succ 0\) (positive definite), the objective is strictly convex and any feasible QP has a unique global minimizer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ellipsoidal Level Sets Meeting a Polyhedron&lt;/strong&gt;: Unlike LPs whose optima sit at vertices, a QP’s ellipsoidal contours can kiss the &lt;em&gt;interior&lt;/em&gt; of a polyhedral face or even sit strictly inside the feasible set. Active-set QP solvers identify which linear inequalities bind and solve equality-constrained KKT linear systems on that face.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Canonical Applications&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Markowitz Portfolio Optimization&lt;/em&gt;: minimize variance \(\frac{1}{2}w^T \Sigma w\) subject to expected return \(\mu^T w \ge R\) and \(\mathbf{1}^T w = 1, w \ge 0\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Hard/Soft-Margin SVM&lt;/em&gt;: minimize \(\frac{1}{2}\|w\|_2^2 + C\sum_i \xi_i\) subject to linear margin inequalities.&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Constrained Least Squares&lt;/em&gt;: minimize \(\frac{1}{2}\|Ax - b\|_2^2 = \frac{1}{2}x^T(A^T A)x - (A^T b)^T x + \frac{1}{2}b^T b\) with box/linear constraints.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equality-Constrained QP = One Linear System&lt;/strong&gt;: When a QP has only affine equalities \(Ax = b\) (no inequalities), its KKT optimality conditions reduce to a single symmetric indefinite linear system \(\begin{bmatrix} P &amp;amp; A^T \\ A &amp;amp; 0 \end{bmatrix}\begin{bmatrix} x^\star \\ \nu^\star \end{bmatrix} = \begin{bmatrix} -q \\ b \end{bmatrix}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-solving-an-equality-constrained-qp-via-the-kkt-system&quot;&gt;Worked example: Solving an Equality-Constrained QP via the KKT System&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = x_1^2 + 2x_2^2 - 2x_1 - 8x_2\) subject to \(x_1 + x_2 = 3\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Put into standard QP form \(\frac{1}{2}x^T P x + q^T x\)&lt;/strong&gt;:
\(P = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 4 \end{bmatrix} \succ 0, \qquad q = \begin{bmatrix} -2 \\ -8 \end{bmatrix}, \qquad A = \begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix}, \qquad b = 3.\)
Because \(P \succ 0\), the solution is guaranteed to be unique.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assemble the KKT system \(Px + A^T \nu = -q,\; Ax = b\)&lt;/strong&gt;:
\(\begin{cases} 2x_1 + \nu = 2 \\ 4x_2 + \nu = 8 \\ x_1 + x_2 = 3. \end{cases}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve for \((x_1^\star, x_2^\star, \nu^\star)\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;From the first two equations: \(x_1 = 1 - \frac{\nu}{2}\) and \(x_2 = 2 - \frac{\nu}{4}\).&lt;/li&gt;
      &lt;li&gt;Substitute into \(x_1 + x_2 = 3\):
\(\left(1 - \frac{\nu}{2}\right) + \left(2 - \frac{\nu}{4}\right) = 3 \implies 3 - \frac{3\nu}{4} = 3 \implies \nu^\star = 0.\)&lt;/li&gt;
      &lt;li&gt;Therefore \(x_1^\star = 1\) and \(x_2^\star = 2\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interpret the zero multiplier&lt;/strong&gt;: Why did \(\nu^\star = 0\)? Because the unconstrained minimizer of \(f\) is \(x_{\mathrm{unc}} = -P^{-1}q = (1, 2)^T\), which &lt;em&gt;already&lt;/em&gt; satisfies \(1 + 2 = 3\)! The equality constraint happens to pass straight through the bottom of the quadratic bowl, giving optimal value \(f^\star = 1^2 + 2(2)^2 - 2(1) - 8(2) = 1 + 8 - 2 - 16 = -9\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A &lt;strong&gt;Quadratic Program&lt;/strong&gt; (QP) is a convex optimization problem where the objective function is a convex quadratic function and all constraint functions are affine. The general quadratic program is formulated as:&lt;/p&gt;

&lt;h3 id=&quot;general-quadratic-program&quot;&gt;General Quadratic Program&lt;/h3&gt;
&lt;p&gt;\(\begin{align}
    \text{minimize}_{x} \quad &amp;amp;\frac{1}{2}x^T P x + q^T x + r \\
    \text{subject to} \quad &amp;amp;Gx \preceq h \\
    &amp;amp;Ax = b
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;where:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(P \in \mathbb{S}_{+}^n\) (positive semidefinite matrix)&lt;/li&gt;
  &lt;li&gt;\(G \in \mathbb{R}^{m \times n}\) (inequality constraint matrix)&lt;/li&gt;
  &lt;li&gt;\(A \in \mathbb{R}^{p \times n}\) (equality constraint matrix)&lt;/li&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) (decision variable)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key Properties of QP:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The constant \(r\) in the objective function does not affect the optimization process or result and can be omitted.&lt;/li&gt;
  &lt;li&gt;If \(P \in \mathbb{S}_{+}^n\) is not satisfied, the problem is not convex.&lt;/li&gt;
  &lt;li&gt;Even if not explicitly stated, QP assumes \(P \in \mathbb{S}_{+}^n\).&lt;/li&gt;
  &lt;li&gt;The above problem seeks the minimizer \(x^*\) of the convex quadratic function \(\frac{1}{2}x^T P x + q^T x + r\) over a polyhedral feasible set.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;understanding-mathbbs_n-positive-semidefinite-cone&quot;&gt;Understanding \(\mathbb{S}_{+}^n\) (Positive Semidefinite Cone)&lt;/h3&gt;

&lt;p&gt;The notation \(\mathbb{S}_{+}^n\) represents the &lt;strong&gt;positive semidefinite cone&lt;/strong&gt;, which is a fundamental concept in convex optimization:&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt;&lt;/p&gt;
  &lt;blockquote&gt;
\[\mathbb{S}_{+}^n = \{ X \in \mathbb{S}^n : X \succeq 0 \}\]
  &lt;/blockquote&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;where:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbb{S}^n\) is the set of all \(n \times n\) &lt;strong&gt;symmetric matrices&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;\(X \succeq 0\) means matrix \(X\) is &lt;strong&gt;positive semidefinite&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key Properties:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Positive semidefinite condition&lt;/strong&gt;: A matrix \(P\) is positive semidefinite if:
    &lt;ul&gt;
      &lt;li&gt;All eigenvalues of \(P\) are non-negative (\(\lambda_i \geq 0\))&lt;/li&gt;
      &lt;li&gt;For any vector \(v\), we have \(v^T P v \geq 0\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex cone property&lt;/strong&gt;: \(\mathbb{S}_{+}^n\) is a convex cone because if \(\theta_1, \theta_2 \geq 0\) and \(A, B \in \mathbb{S}_{+}^n\), then \(\theta_1 A + \theta_2 B \in \mathbb{S}_{+}^n\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example for \(n=2\):&lt;/strong&gt;
For a \(2 \times 2\) matrix \(P = \begin{bmatrix} a &amp;amp; b \\ b &amp;amp; c \end{bmatrix}\), the condition \(P \in \mathbb{S}_{+}^2\) requires:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(a \geq 0\) (diagonal elements non-negative)&lt;/li&gt;
  &lt;li&gt;\(c \geq 0\) (diagonal elements non-negative)&lt;/li&gt;
  &lt;li&gt;\(ac \geq b^2\) (determinant non-negative)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why is this important for QP?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The condition \(P \in \mathbb{S}_{+}^n\) ensures that the quadratic function \((1/2)x^T P x + q^T x + r\) is &lt;strong&gt;convex&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Without this condition, the problem may have multiple local minima and would not be a convex optimization problem&lt;/li&gt;
  &lt;li&gt;This guarantees that any local minimum is also a global minimum&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;understanding-gx-preceq-h-component-wise-inequality&quot;&gt;Understanding \(Gx \preceq h\) (Component-wise Inequality)&lt;/h3&gt;

&lt;p&gt;The notation \(Gx \preceq h\) represents &lt;strong&gt;component-wise inequality constraints&lt;/strong&gt;, which is a compact way to write multiple linear inequality constraints:&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt;
\(Gx \preceq h \quad \Leftrightarrow \quad (Gx)_i \leq h_i \text{ for all } i = 1, 2, \ldots, m\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;where:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(G \in \mathbb{R}^{m \times n}\) is the constraint matrix&lt;/li&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) is the decision variable vector&lt;/li&gt;
  &lt;li&gt;\(h \in \mathbb{R}^m\) is the right-hand side vector&lt;/li&gt;
  &lt;li&gt;\(m\) is the number of inequality constraints&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Expanded Form:&lt;/strong&gt;
The single matrix inequality \(Gx \preceq h\) is equivalent to the system:
\(\begin{align}
g_1^T x &amp;amp;\leq h_1 \\
g_2^T x &amp;amp;\leq h_2 \\
&amp;amp;\vdots \\
g_m^T x &amp;amp;\leq h_m
\end{align}\)&lt;/p&gt;

&lt;p&gt;where \(g_i^T\) is the \(i\)-th row of matrix \(G\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;
Consider \(G = \begin{bmatrix} 1 &amp;amp; 2 \\ -1 &amp;amp; 3 \\ 0 &amp;amp; -1 \end{bmatrix}\), \(x = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\), and \(h = \begin{bmatrix} 5 \\ 2 \\ -1 \end{bmatrix}\)&lt;/p&gt;

&lt;p&gt;Then \(Gx \preceq h\) means:
\(\begin{align}
x_1 + 2x_2 &amp;amp;\leq 5 \\
-x_1 + 3x_2 &amp;amp;\leq 2 \\
-x_2 &amp;amp;\leq -1 \quad \text{(i.e., } x_2 \geq 1\text{)}
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Geometric Interpretation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Each inequality \(g_i^T x \leq h_i\) defines a &lt;strong&gt;half-space&lt;/strong&gt; in \(\mathbb{R}^n\)&lt;/li&gt;
  &lt;li&gt;The feasible region is the &lt;strong&gt;intersection&lt;/strong&gt; of all these half-spaces&lt;/li&gt;
  &lt;li&gt;This intersection forms a &lt;strong&gt;polyhedron&lt;/strong&gt; (or polytope if bounded)&lt;/li&gt;
  &lt;li&gt;The constraint \(Gx \preceq h\) defines the &lt;strong&gt;polyhedral feasible set&lt;/strong&gt; for the QP&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter05/05_02_geometric_interpretation_of_QP.png&quot; alt=&quot;[Fig 1] Geometric interpretation of QP [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Geometric interpretation of QP [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;qp-in-standard-form&quot;&gt;QP in Standard Form&lt;/h2&gt;

&lt;p&gt;The standard form of a quadratic program is:&lt;/p&gt;

&lt;h3 id=&quot;standard-form-qp&quot;&gt;Standard Form QP&lt;/h3&gt;
&lt;p&gt;\(\begin{align}
    \text{minimize}_{x} \quad &amp;amp;\frac{1}{2}x^T P x + q^T x + r \\
    \text{subject to} \quad &amp;amp;A x = b \\
    &amp;amp;x \succeq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;Any general quadratic program can be converted to standard form using the following steps:&lt;/p&gt;

&lt;h3 id=&quot;converting-qps-to-standard-form&quot;&gt;Converting QPs to Standard Form&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1.&lt;/strong&gt; Use slack variables \(s\) to convert inequality constraints into equality constraints:
\(\begin{align}
    \text{minimize}_{x, s} \quad &amp;amp;\frac{1}{2}x^T P x + q^T x + r \\
    \text{subject to} \quad &amp;amp;Gx + s = h \\
    &amp;amp;Ax = b \\
    &amp;amp;s \succeq 0
\end{align}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2.&lt;/strong&gt; Replace \(x\) with two nonnegative variables:
\(x = x^{+} - x^{-}, \quad \text{where } x^{+}, x^{-} \succeq 0\)&lt;/p&gt;

\[\begin{align}
    \text{minimize}_{x^{+}, x^{-}, s} \quad &amp;amp;\frac{1}{2}(x^{+} - x^{-})^T P (x^{+} - x^{-}) + q^T x^{+} - q^T x^{-} + r\\
    \text{subject to} \quad &amp;amp;Gx^{+} - Gx^{-} + s = h \\
    &amp;amp;Ax^{+} - Ax^{-} = b \\
    &amp;amp;s \succeq 0 \\
    &amp;amp;x^{+} \succeq 0, \quad x^{-} \succeq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;Step 3.&lt;/strong&gt; Define \(\tilde{x}\), \(\tilde{q}\), \(\tilde{b}\), \(\tilde{A}\), \(\tilde{P}\):&lt;/p&gt;

\[\tilde{x} =
\begin{bmatrix}
x^{+} \\
x^{-} \\
s
\end{bmatrix}, \quad
\tilde{q} =
\begin{bmatrix}
q \\
-q \\
0
\end{bmatrix}, \quad
\tilde{b} =
\begin{bmatrix}
h \\
b
\end{bmatrix}\]

\[\tilde{A} =
\begin{bmatrix}
G &amp;amp; -G &amp;amp; I \\
A &amp;amp; -A &amp;amp; O
\end{bmatrix}, \quad
\tilde{P} =
\begin{bmatrix}
 P &amp;amp; -P &amp;amp; O \\
-P &amp;amp;  P &amp;amp; O \\
 O &amp;amp;  O &amp;amp; O
\end{bmatrix}\]

&lt;p&gt;&lt;strong&gt;Step 4.&lt;/strong&gt; Substitute the expressions from Step 3 into the formulation:&lt;/p&gt;

\[\begin{align}
    \text{minimize}_{\tilde{x}} \quad &amp;amp;\frac{1}{2}\tilde{x}^T \tilde{P} \tilde{x} + \tilde{q}^T \tilde{x} + r \\
    \text{subject to} \quad &amp;amp;\tilde{A} \tilde{x} = \tilde{b} \\
    &amp;amp;\tilde{x} \succeq 0
\end{align}\]

&lt;h2 id=&quot;linear-programming-as-a-special-case-of-qp&quot;&gt;Linear Programming as a Special Case of QP&lt;/h2&gt;

&lt;p&gt;If the quadratic term is removed from the objective function of a quadratic program, it takes the form of a linear program. Thus, LP is a special case of QP, denoted as LP \(\subseteq\) QP.&lt;/p&gt;

&lt;h3 id=&quot;recall-general-lp&quot;&gt;Recall: General LP&lt;/h3&gt;
&lt;p&gt;\(\begin{align}
    \text{minimize}_{x} \quad &amp;amp;c^T x + d \\
    \text{subject to} \quad &amp;amp;Gx \preceq h \\
    &amp;amp;Ax = b
\end{align}\)
where \(G \in \mathbb{R}^{m \times n}\) and \(A \in \mathbb{R}^{p \times n}\).&lt;/p&gt;

&lt;h3 id=&quot;example-1-portfolio-optimization&quot;&gt;Example 1: Portfolio Optimization&lt;/h3&gt;

&lt;p&gt;This problem involves appropriately trading off performance and risk in creating a financial portfolio.&lt;/p&gt;

\[\begin{align}
    \text{maximize}_{x} \quad &amp;amp;\mu^T x - \frac{\gamma}{2}x^T P x \\
    \text{subject to} \quad &amp;amp;\mathbf{1}^Tx = 1 \\
    &amp;amp;x \succeq 0
\end{align}\]

&lt;p&gt;&lt;strong&gt;where:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mu\): expected assets’ returns&lt;/li&gt;
  &lt;li&gt;\(P\): covariance matrix of assets’ returns&lt;/li&gt;
  &lt;li&gt;\(\gamma\): risk aversion parameter (hyperparameter)&lt;/li&gt;
  &lt;li&gt;\(x\): portfolio holdings (percentages)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example-2-support-vector-machines&quot;&gt;Example 2: Support Vector Machines&lt;/h3&gt;

&lt;p&gt;Support Vector Machines (SVM) are an example of a quadratic program. Below is C-SVM, a variant of SVM. A detailed explanation of SVM is beyond the scope of this chapter and will therefore be omitted.&lt;/p&gt;

\[\begin{align}
    \text{minimize}_{\beta, \beta_0, \xi} \quad &amp;amp;\frac{1}{2} \| \beta \|_2^2 + C \sum_{i=1}^{n} \xi_i \\
    \text{subject to} \quad &amp;amp;\xi_i \geq 0, \quad i = 1, \ldots, n \\
    &amp;amp;y_i (x_i^T \beta + \beta_0) \geq 1 - \xi_i, \quad i = 1, \ldots, n
\end{align}\]

&lt;p&gt;&lt;strong&gt;given:&lt;/strong&gt; \(y \in \{-1, 1\}^n\) and \(X \in \mathbb{R}^{n \times p}\) having rows \(x_1, \ldots, x_n\).&lt;/p&gt;

&lt;h3 id=&quot;example-3-least-squares-in-regression&quot;&gt;Example 3: Least-Squares in Regression&lt;/h3&gt;

&lt;p&gt;The problem of minimizing the following convex quadratic function corresponds to an (unconstrained) QP:
\(\| Ax - b \|_2^2 = x^T A^TA x - 2b^TAx + b^Tb\)&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>05-02-04 Logistic Regression</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_02_04_Logistic_Regression/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_02_04_Logistic_Regression</id>
   <content type="html">&lt;p&gt;Try predicting whether a tumor is malignant (\(y = 1\)) or benign (\(y = 0\)) using linear regression and two disasters strike immediately: predictions shoot past \(0\) and \(1\) into meaningless probabilities like \(-0.4\) or \(1.7\), and a single confident outlier drags the entire decision boundary off course. Logistic regression fixes both by passing the linear score \(w^T x\) through the sigmoid function—and miraculously, the resulting cross-entropy loss is still a smooth, globally convex optimization problem!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-convexity-behind-logistic-regression&quot;&gt;Key ideas: Convexity Behind Logistic Regression&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Log-Odds and the Sigmoid Link&lt;/strong&gt;: Modeling the log-odds as linear, \(\ln\frac{p}{1 - p} = w^T x\), maps any real score \(z = w^T x \in \mathbb{R}\) smoothly into a calibrated probability \(p = \sigma(z) = \frac{1}{1 + e^{-z}} \in (0, 1)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convexity of Binary Cross-Entropy&lt;/strong&gt;: For labels \(y_i \in \{0, 1\}\), the negative log-likelihood is
\(J(w) = \sum_{i=1}^m \Bigl[\ln\bigl(1 + e^{w^T x_i}\bigr) - y_i (w^T x_i)\Bigr].\)
Its Hessian is \(\nabla^2 J(w) = X^T D X\) where \(D = \operatorname{diag}\bigl(p_i(1 - p_i)\bigr) \succ 0\), proving \(J(w)\) is &lt;strong&gt;globally convex&lt;/strong&gt; (and strictly convex whenever \(X\) has full column rank).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;No Closed-Form Solution, Fast Iterative Solvers&lt;/strong&gt;: Unlike linear least squares, \(\nabla J(w) = X^T(p - y) = 0\) is nonlinear in \(w\) and cannot be inverted in one shot. Because \(J(w)\) is smooth and convex, Gradient Descent, L-BFGS, and Newton’s Method (Iteratively Reweighted Least Squares, IRLS) converge rapidly to the unique global minimum.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear Separability Requires Regularization&lt;/strong&gt;: If two classes are perfectly separable by a hyperplane, pushing \(\|w\|_2 \to \infty\) drives \(J(w) \to 0\) with no finite minimizer. Adding \(\frac{\lambda}{2}\|w\|_2^2\) makes the objective strongly convex and guarantees a finite, well-behaved maximum-margin-like separator.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-computing-gradient-hessian-and-one-newton-step&quot;&gt;Worked example: Computing Gradient, Hessian, and One Newton Step&lt;/h3&gt;

&lt;p&gt;Consider 1D logistic regression without intercept (\(z_i = w x_i\)) on two points: \((x_1, y_1) = (1, 1)\) and \((x_2, y_2) = (-1, 0)\), with L2 regularization \(\frac{1}{2}w^2\) (\(\lambda = 1\)):
\(J(w) = \ln(1 + e^{w}) - w + \ln(1 + e^{-w}) + \frac{1}{2}w^2.\)
Start at \(w_0 = 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute predicted probabilities at \(w_0 = 0\)&lt;/strong&gt;:
\(p_1 = \sigma(0) = 0.5, \qquad p_2 = \sigma(0) = 0.5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the first derivative (gradient) at \(w_0 = 0\)&lt;/strong&gt;:
\(J&apos;(w) = x_1(p_1 - y_1) + x_2(p_2 - y_2) + w = 1(0.5 - 1) + (-1)(0.5 - 0) + 0 = -0.5 - 0.5 = -1.\)
Since \(J&apos;(0) = -1 &amp;lt; 0\), increasing \(w\) reduces the loss.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the second derivative (Hessian) at \(w_0 = 0\)&lt;/strong&gt;:
\(J&apos;&apos;(w) = x_1^2 p_1(1 - p_1) + x_2^2 p_2(1 - p_2) + 1 = 1(0.25) + 1(0.25) + 1 = 1.5 &amp;gt; 0.\)
(Strictly positive, confirming strict convexity!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take one Newton step&lt;/strong&gt;:
\(w_1 = w_0 - \frac{J&apos;(w_0)}{J&apos;&apos;(w_0)} = 0 - \frac{-1}{1.5} = \frac{2}{3} \approx 0.6667.\)
Check the drop in loss: \(J(0) = 2\ln 2 \approx 1.3863\), while at \(w_1 = 2/3\), \(\ln(1 + e^{2/3}) - \frac{2}{3} + \ln(1 + e^{-2/3}) + \frac{2}{9} = 2\ln(1 + e^{-2/3}) + \frac{2}{9} \approx 2(0.4144) + 0.2222 = 1.0510\)—nearly at the global minimum in a single step!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;logistic-regression&quot;&gt;Logistic Regression&lt;/h1&gt;

&lt;p&gt;Logistic regression is one of the most important applications of convex optimization in machine learning, and is widely used for binary classification problems.&lt;/p&gt;

&lt;h2 id=&quot;-the-binary-classification-problem&quot;&gt;🎯 The Binary Classification Problem&lt;/h2&gt;

&lt;p&gt;Unlike linear regression, which predicts a continuous value, &lt;strong&gt;binary classification&lt;/strong&gt; predicts the probability that a sample belongs to one of two classes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Medicine&lt;/strong&gt;: Predicting whether a patient has a disease (0: healthy, 1: sick)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Marketing&lt;/strong&gt;: Whether a customer buys a product (0: does not buy, 1: buys)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Finance&lt;/strong&gt;: Whether an email is spam (0: not spam, 1: spam)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Technology&lt;/strong&gt;: Whether a transaction is fraudulent (0: legitimate, 1: fraudulent)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Training data:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\{(\mathbf{x}_i, y_i)\}_{i=1}^n\) with \(\mathbf{x}_i \in \mathbb{R}^p\), \(y_i \in \{0, 1\}\)&lt;/li&gt;
  &lt;li&gt;\(\mathbf{x}_i\): feature vector&lt;/li&gt;
  &lt;li&gt;\(y_i\): class label&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-from-linear-regression-to-logistic-regression&quot;&gt;📊 From Linear Regression to Logistic Regression&lt;/h2&gt;

&lt;h3 id=&quot;the-problem-with-linear-regression-for-classification&quot;&gt;The Problem with Linear Regression for Classification&lt;/h3&gt;

&lt;p&gt;If we apply linear regression directly: \(\hat{y} = \mathbf{w}^T \mathbf{x} + b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The problem:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\hat{y}\) can take any value: \((-\infty, +\infty)\)&lt;/li&gt;
  &lt;li&gt;But a probability must lie in \([0, 1]\)&lt;/li&gt;
  &lt;li&gt;This does not match the probabilistic nature of classification&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;the-sigmoid-function---an-important-bridge&quot;&gt;The Sigmoid Function - An Important Bridge&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The sigmoid function:&lt;/strong&gt;
\(\sigma(z) = \frac{1}{1 + e^{-z}}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Range&lt;/strong&gt;: \(\sigma(z) \in (0, 1)\) \(\forall z \in \mathbb{R}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Monotonically increasing&lt;/strong&gt;: \(\sigma&apos;(z) &amp;gt; 0\) \(\forall z\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Symmetry&lt;/strong&gt;: \(\sigma(-z) = 1 - \sigma(z)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Limits&lt;/strong&gt;: \(\lim_{z \to -\infty} \sigma(z) = 0\), \(\lim_{z \to +\infty} \sigma(z) = 1\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A special derivative:&lt;/strong&gt;
\(\sigma&apos;(z) = \sigma(z)(1 - \sigma(z))\)&lt;/p&gt;

&lt;h3 id=&quot;the-logistic-regression-model&quot;&gt;The Logistic Regression Model&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Predicted probability:&lt;/strong&gt;
\(P(y = 1 | \mathbf{x}) = \sigma(\mathbf{w}^T \mathbf{x}) = \frac{1}{1 + e^{-\mathbf{w}^T \mathbf{x}}}\)&lt;/p&gt;

\[P(y = 0 | \mathbf{x}) = 1 - P(y = 1 | \mathbf{x}) = \frac{e^{-\mathbf{w}^T \mathbf{x}}}{1 + e^{-\mathbf{w}^T \mathbf{x}}}\]

&lt;p&gt;&lt;strong&gt;Decision rule:&lt;/strong&gt;
\(\hat{y} = \begin{cases}
1 &amp;amp; \text{if } P(y = 1 | \mathbf{x}) \geq 0.5 \\
0 &amp;amp; \text{if } P(y = 1 | \mathbf{x}) &amp;lt; 0.5
\end{cases}\)&lt;/p&gt;

&lt;h2 id=&quot;-the-cross-entropy-loss&quot;&gt;🧮 The Cross-Entropy Loss&lt;/h2&gt;

&lt;p&gt;In logistic regression, we use the &lt;strong&gt;Cross-Entropy Loss&lt;/strong&gt; to measure the difference between predictions and reality:&lt;/p&gt;

\[J(\mathbf{w}) = -\sum_{i=1}^n \left[ y_i \log p_i + (1-y_i) \log (1-p_i) \right]\]

&lt;p&gt;where \(p_i = \sigma(\mathbf{w}^T \mathbf{x}_i)\) is the predicted probability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Heavy penalty for wrong predictions:&lt;/strong&gt; The more wrong the prediction, the larger and unbounded the loss&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smooth and convex:&lt;/strong&gt; Guarantees efficient optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Probabilistic:&lt;/strong&gt; Matches the probabilistic nature of the problem&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-proof-of-convexity&quot;&gt;🔍 Proof of Convexity&lt;/h2&gt;

&lt;h3 id=&quot;theorem-the-logistic-loss-function-is-convex&quot;&gt;Theorem: The logistic loss function is convex&lt;/h3&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Show that \(-\log \sigma(z)\) is convex&lt;/p&gt;

\[-\log \sigma(z) = -\log \frac{1}{1 + e^{-z}} = \log(1 + e^{-z})\]

&lt;p&gt;Second derivative:
\(\frac{d^2}{dz^2} \log(1 + e^{-z}) = \frac{e^{-z}}{(1 + e^{-z})^2} = \sigma(z)(1 - \sigma(z)) &amp;gt; 0\)&lt;/p&gt;

&lt;p&gt;⟹ \(-\log \sigma(z)\) is convex in \(z\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Show that \(-\log(1 - \sigma(z))\) is convex&lt;/p&gt;

\[-\log(1 - \sigma(z)) = -\log \frac{e^{-z}}{1 + e^{-z}} = z + \log(1 + e^{-z})\]

&lt;p&gt;Second derivative:
\(\frac{d^2}{dz^2} [z + \log(1 + e^{-z})] = \frac{e^{-z}}{(1 + e^{-z})^2} &amp;gt; 0\)&lt;/p&gt;

&lt;p&gt;⟹ \(-\log(1 - \sigma(z))\) is convex in \(z\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Conclusion&lt;/p&gt;

&lt;p&gt;Since \(z = \mathbf{w}^T \mathbf{x}_i\) is affine in \(\mathbf{w}\), and a sum of convex functions is convex:&lt;/p&gt;

\[J(\mathbf{w}) = \sum_{i=1}^n \left[ -y_i \log \sigma(\mathbf{w}^T \mathbf{x}_i) - (1-y_i) \log (1 - \sigma(\mathbf{w}^T \mathbf{x}_i)) \right]\]

&lt;p&gt;is a &lt;strong&gt;convex function&lt;/strong&gt; of \(\mathbf{w}\).&lt;/p&gt;

&lt;h2 id=&quot;-the-gradient-of-the-loss-function&quot;&gt;📈 The Gradient of the Loss Function&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Gradient:&lt;/strong&gt;
\(\nabla_{\mathbf{w}} J(\mathbf{w}) = \sum_{i=1}^n (\sigma(\mathbf{w}^T \mathbf{x}_i) - y_i) \mathbf{x}_i = \mathbf{X}^T (\boldsymbol{\sigma} - \mathbf{y})\)&lt;/p&gt;

&lt;p&gt;with:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{X} \in \mathbb{R}^{n \times p}\): the feature matrix&lt;/li&gt;
  &lt;li&gt;
\[\boldsymbol{\sigma} = [\sigma(\mathbf{w}^T \mathbf{x}_1), ..., \sigma(\mathbf{w}^T \mathbf{x}_n)]^T\]
  &lt;/li&gt;
  &lt;li&gt;
\[\mathbf{y} = [y_1, ..., y_n]^T\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hessian:&lt;/strong&gt;
\(\nabla^2_{\mathbf{w}} J(\mathbf{w}) = \mathbf{X}^T \mathbf{S} \mathbf{X}\)&lt;/p&gt;

&lt;p&gt;with \(\mathbf{S} = \text{diag}(\sigma(\mathbf{w}^T \mathbf{x}_i)(1 - \sigma(\mathbf{w}^T \mathbf{x}_i)))\)&lt;/p&gt;

&lt;p&gt;Since the diagonal entries of \(\mathbf{S}\) are positive, we have \(\nabla^2_{\mathbf{w}} J(\mathbf{w}) = \mathbf{X}^T \mathbf{S} \mathbf{X} \succeq 0\) ⟹ &lt;strong&gt;convex function&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;-the-significance-of-convexity&quot;&gt;🎯 The Significance of Convexity&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why does convexity matter?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Guarantees a global optimum:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Every &lt;strong&gt;local minimum is a global minimum&lt;/strong&gt; (the set of optimal solutions is convex)&lt;/li&gt;
      &lt;li&gt;There are no “false” local minima as in neural networks&lt;/li&gt;
      &lt;li&gt;Optimization algorithms head toward a global optimum&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient descent works efficiently:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Converges&lt;/strong&gt; to the optimal solution (with a suitable learning rate, when an optimal solution exists; for perfectly linearly separable data the optimum lies at infinity and \(\|\mathbf{w}\|\) keeps growing)&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Does not get stuck&lt;/strong&gt; at local minima&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Simple and stable&lt;/strong&gt; - no complicated techniques are needed&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Powerful optimization theory:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;We can prove &lt;strong&gt;convergence rates&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;We can &lt;strong&gt;estimate the error&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;There are clear &lt;strong&gt;stopping criteria&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-from-convexity-to-gradient-descent&quot;&gt;🚀 From Convexity to Gradient Descent&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Since the logistic loss is convex and differentiable&lt;/strong&gt;, we can use &lt;strong&gt;Gradient Descent&lt;/strong&gt; with confidence:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The basic algorithm:&lt;/strong&gt;
\(\mathbf{w}^{(k+1)} = \mathbf{w}^{(k)} - \alpha \nabla J(\mathbf{w}^{(k)})\)&lt;/p&gt;

&lt;p&gt;with the gradient:
\(\nabla J(\mathbf{w}) = \mathbf{X}^T (\boldsymbol{\sigma} - \mathbf{y})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convergence guarantee:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Choose a suitable learning rate \(\alpha\) → &lt;strong&gt;converges&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;No need to worry about local minima&lt;/li&gt;
  &lt;li&gt;The behavior of the algorithm is predictable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Connection with Chapter 6:&lt;/strong&gt;
In &lt;strong&gt;Chapter 6 - Gradient Descent&lt;/strong&gt;, we will study in detail:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;How to choose the optimal learning rate&lt;/li&gt;
  &lt;li&gt;Convergence rate analysis&lt;/li&gt;
  &lt;li&gt;Variants such as Stochastic Gradient Descent&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Logistic Regression will be the main example&lt;/strong&gt; illustrating these concepts!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-comparison-with-linear-regression&quot;&gt;🔄 Comparison with Linear Regression&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aspect&lt;/th&gt;
      &lt;th&gt;Linear Regression&lt;/th&gt;
      &lt;th&gt;Logistic Regression&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Regression&lt;/td&gt;
      &lt;td&gt;Classification&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Continuous value&lt;/td&gt;
      &lt;td&gt;Probability \(\in [0,1]\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Activation function&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Identity: \(f(z) = z\)&lt;/td&gt;
      &lt;td&gt;Sigmoid: \(\sigma(z) = \frac{1}{1+e^{-z}}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Loss function&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;MSE: \(\frac{1}{2n}\sum(y_i - \hat{y}_i)^2\)&lt;/td&gt;
      &lt;td&gt;Cross-entropy: \(-\sum[y_i \log p_i + (1-y_i)\log(1-p_i)]\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Closed-form solution&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Yes (if \(\mathbf{X}^T\mathbf{X}\) is invertible): \(\mathbf{w}^* = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y}\)&lt;/td&gt;
      &lt;td&gt;None&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Algorithm&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Normal equation or GD&lt;/td&gt;
      &lt;td&gt;Gradient Descent&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Convexity&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Convex (quadratic)&lt;/td&gt;
      &lt;td&gt;Convex&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;-illustrative-example-spam-email-prediction&quot;&gt;💡 Illustrative Example: Spam Email Prediction&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Classify spam emails based on the number of suspicious keywords.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(x\): the number of spam keywords in the email&lt;/li&gt;
  &lt;li&gt;\(y\): 1 if spam, 0 if not spam&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Model:&lt;/strong&gt;
\(P(\text{spam} | x) = \sigma(w_0 + w_1 x) = \frac{1}{1 + e^{-(w_0 + w_1 x)}}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;If \(w_1 &amp;gt; 0\): the more spam keywords, the higher the probability of spam&lt;/li&gt;
  &lt;li&gt;Decision point: \(x^* = -\frac{w_0}{w_1}\) (when \(P = 0.5\))&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;️-interactive-visualization&quot;&gt;🎛️ Interactive Visualization&lt;/h2&gt;

&lt;div id=&quot;logistic-regression-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;display: flex; gap: 20px; margin-bottom: 20px;&quot;&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;🎚️ Parameter Controls&lt;/h4&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;w0-slider&quot;&gt;Bias (w₀): &lt;span id=&quot;w0-value&quot;&gt;0&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;w0-slider&quot; min=&quot;-5&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;w1-slider&quot;&gt;Weight (w₁): &lt;span id=&quot;w1-value&quot;&gt;1&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;w1-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;button id=&quot;add-data-btn&quot; style=&quot;padding: 8px 16px; margin: 5px;&quot;&gt;Add Data&lt;/button&gt;
                &lt;button id=&quot;clear-data-btn&quot; style=&quot;padding: 8px 16px; margin: 5px;&quot;&gt;Clear Data&lt;/button&gt;
                &lt;button id=&quot;fit-model-btn&quot; style=&quot;padding: 8px 16px; margin: 5px;&quot;&gt;Fit Model&lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📊 Model Information&lt;/h4&gt;
            &lt;div id=&quot;model-info&quot;&gt;
                &lt;p&gt;&lt;strong&gt;Equation:&lt;/strong&gt; P(y=1|x) = σ(&lt;span id=&quot;equation&quot;&gt;0 + 1·x&lt;/span&gt;)&lt;/p&gt;
                &lt;p&gt;&lt;strong&gt;Decision point:&lt;/strong&gt; x = &lt;span id=&quot;decision-boundary&quot;&gt;0&lt;/span&gt;&lt;/p&gt;
                &lt;p&gt;&lt;strong&gt;Loss:&lt;/strong&gt; &lt;span id=&quot;current-loss&quot;&gt;-&lt;/span&gt;&lt;/p&gt;
                &lt;p&gt;&lt;strong&gt;Accuracy:&lt;/strong&gt; &lt;span id=&quot;accuracy&quot;&gt;-&lt;/span&gt;&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px;&quot;&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📈 Sigmoid Function&lt;/h4&gt;
            &lt;canvas id=&quot;sigmoid-canvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;🎯 Classification Results&lt;/h4&gt;
            &lt;canvas id=&quot;classification-canvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin-top: 20px;&quot;&gt;
        &lt;h4&gt;📉 Loss Function Visualization&lt;/h4&gt;
        &lt;canvas id=&quot;loss-canvas&quot; width=&quot;800&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
class LogisticRegressionDemo {
    constructor() {
        this.w0 = 0;
        this.w1 = 1;
        this.dataPoints = [];
        this.isAddingData = false;
        
        this.initializeCanvases();
        this.setupEventListeners();
        this.generateSampleData();
        this.updateVisualization();
    }
    
    initializeCanvases() {
        this.sigmoidCanvas = document.getElementById(&apos;sigmoid-canvas&apos;);
        this.sigmoidCtx = this.sigmoidCanvas.getContext(&apos;2d&apos;);
        
        this.classificationCanvas = document.getElementById(&apos;classification-canvas&apos;);
        this.classificationCtx = this.classificationCanvas.getContext(&apos;2d&apos;);
        
        this.lossCanvas = document.getElementById(&apos;loss-canvas&apos;);
        this.lossCtx = this.lossCanvas.getContext(&apos;2d&apos;);
    }
    
    setupEventListeners() {
        const w0Slider = document.getElementById(&apos;w0-slider&apos;);
        const w1Slider = document.getElementById(&apos;w1-slider&apos;);
        const addDataBtn = document.getElementById(&apos;add-data-btn&apos;);
        const clearDataBtn = document.getElementById(&apos;clear-data-btn&apos;);
        const fitModelBtn = document.getElementById(&apos;fit-model-btn&apos;);
        
        w0Slider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.w0 = parseFloat(e.target.value);
            document.getElementById(&apos;w0-value&apos;).textContent = this.w0.toFixed(1);
            this.updateVisualization();
        });
        
        w1Slider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.w1 = parseFloat(e.target.value);
            document.getElementById(&apos;w1-value&apos;).textContent = this.w1.toFixed(1);
            this.updateVisualization();
        });
        
        addDataBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.isAddingData = !this.isAddingData;
            addDataBtn.textContent = this.isAddingData ? &apos;Stop Adding&apos; : &apos;Add Data&apos;;
            addDataBtn.style.backgroundColor = this.isAddingData ? &apos;#ff6b6b&apos; : &apos;&apos;;
        });
        
        clearDataBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.dataPoints = [];
            this.updateVisualization();
        });
        
        fitModelBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.fitModel();
        });
        
        // Click to add data points
        this.classificationCanvas.addEventListener(&apos;click&apos;, (e) =&gt; {
            if (this.isAddingData) {
                const rect = this.classificationCanvas.getBoundingClientRect();
                const x = (e.clientX - rect.left - 50) / 300 * 10 - 5; // Scale to [-5, 5]
                const y = e.clientY - rect.top &gt; 150 ? 0 : 1; // Top half = class 1, bottom = class 0
                this.dataPoints.push({x, y});
                this.updateVisualization();
            }
        });
    }
    
    generateSampleData() {
        // Generate some sample data
        const sampleData = [
            {x: -3, y: 0}, {x: -2.5, y: 0}, {x: -2, y: 0}, {x: -1.5, y: 0},
            {x: -1, y: 0}, {x: -0.5, y: 0}, {x: 0, y: 0}, {x: 0.5, y: 1},
            {x: 1, y: 1}, {x: 1.5, y: 1}, {x: 2, y: 1}, {x: 2.5, y: 1}, {x: 3, y: 1}
        ];
        
        // Add some noise
        this.dataPoints = sampleData.map(point =&gt; ({
            x: point.x + (Math.random() - 0.5) * 0.5,
            y: Math.random() &lt; 0.1 ? 1 - point.y : point.y // 10% label noise
        }));
    }
    
    sigmoid(z) {
        return 1 / (1 + Math.exp(-z));
    }
    
    predict(x) {
        return this.sigmoid(this.w0 + this.w1 * x);
    }
    
    calculateLoss() {
        if (this.dataPoints.length === 0) return 0;
        
        let loss = 0;
        for (const point of this.dataPoints) {
            const p = this.predict(point.x);
            const epsilon = 1e-15; // Prevent log(0)
            const clampedP = Math.max(epsilon, Math.min(1 - epsilon, p));
            loss += -point.y * Math.log(clampedP) - (1 - point.y) * Math.log(1 - clampedP);
        }
        return loss / this.dataPoints.length;
    }
    
    calculateAccuracy() {
        if (this.dataPoints.length === 0) return 0;
        
        let correct = 0;
        for (const point of this.dataPoints) {
            const prediction = this.predict(point.x) &gt;= 0.5 ? 1 : 0;
            if (prediction === point.y) correct++;
        }
        return correct / this.dataPoints.length;
    }
    
    fitModel() {
        if (this.dataPoints.length === 0) return;
        
        // Simple gradient descent
        const learningRate = 0.1;
        const iterations = 1000;
        
        for (let iter = 0; iter &lt; iterations; iter++) {
            let gradW0 = 0, gradW1 = 0;
            
            for (const point of this.dataPoints) {
                const p = this.predict(point.x);
                const error = p - point.y;
                gradW0 += error;
                gradW1 += error * point.x;
            }
            
            gradW0 /= this.dataPoints.length;
            gradW1 /= this.dataPoints.length;
            
            this.w0 -= learningRate * gradW0;
            this.w1 -= learningRate * gradW1;
        }
        
        // Update sliders
        document.getElementById(&apos;w0-slider&apos;).value = this.w0;
        document.getElementById(&apos;w1-slider&apos;).value = this.w1;
        document.getElementById(&apos;w0-value&apos;).textContent = this.w0.toFixed(1);
        document.getElementById(&apos;w1-value&apos;).textContent = this.w1.toFixed(1);
        
        this.updateVisualization();
    }
    
    drawSigmoid() {
        const ctx = this.sigmoidCtx;
        const canvas = this.sigmoidCanvas;
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Draw axes
        ctx.strokeStyle = &apos;#ccc&apos;;
        ctx.lineWidth = 1;
        
        // X-axis
        ctx.beginPath();
        ctx.moveTo(50, canvas.height - 50);
        ctx.lineTo(canvas.width - 20, canvas.height - 50);
        ctx.stroke();
        
        // Y-axis
        ctx.beginPath();
        ctx.moveTo(50, 20);
        ctx.lineTo(50, canvas.height - 50);
        ctx.stroke();
        
        // Draw sigmoid curve
        ctx.strokeStyle = &apos;#2196F3&apos;;
        ctx.lineWidth = 2;
        ctx.beginPath();
        
        for (let i = 0; i &lt;= 300; i++) {
            const x = (i / 300) * 10 - 5; // x from -5 to 5
            const z = this.w0 + this.w1 * x;
            const y = this.sigmoid(z);
            
            const canvasX = 50 + (x + 5) / 10 * 300;
            const canvasY = canvas.height - 50 - y * 200;
            
            if (i === 0) {
                ctx.moveTo(canvasX, canvasY);
            } else {
                ctx.lineTo(canvasX, canvasY);
            }
        }
        ctx.stroke();
        
        // Draw decision boundary
        if (this.w1 !== 0) {
            const decisionX = -this.w0 / this.w1;
            if (decisionX &gt;= -5 &amp;&amp; decisionX &lt;= 5) {
                const canvasX = 50 + (decisionX + 5) / 10 * 300;
                ctx.strokeStyle = &apos;#ff6b6b&apos;;
                ctx.lineWidth = 2;
                ctx.setLineDash([5, 5]);
                ctx.beginPath();
                ctx.moveTo(canvasX, 20);
                ctx.lineTo(canvasX, canvas.height - 50);
                ctx.stroke();
                ctx.setLineDash([]);
            }
        }
        
        // Labels
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;P(y=1|x)&apos;, 10, 30);
        ctx.fillText(&apos;x&apos;, canvas.width - 15, canvas.height - 30);
        ctx.fillText(&apos;0&apos;, 45, canvas.height - 30);
        ctx.fillText(&apos;1&apos;, 45, 25);
        ctx.fillText(&apos;0.5&apos;, 35, canvas.height - 150);
    }
    
    drawClassification() {
        const ctx = this.classificationCtx;
        const canvas = this.classificationCanvas;
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Draw background regions
        ctx.fillStyle = &apos;rgba(255, 107, 107, 0.1)&apos;; // Red for class 0
        ctx.fillRect(50, canvas.height/2, 300, canvas.height/2 - 50);
        
        ctx.fillStyle = &apos;rgba(76, 175, 80, 0.1)&apos;; // Green for class 1
        ctx.fillRect(50, 20, 300, canvas.height/2 - 20);
        
        // Draw axes
        ctx.strokeStyle = &apos;#ccc&apos;;
        ctx.lineWidth = 1;
        
        // X-axis
        ctx.beginPath();
        ctx.moveTo(50, canvas.height - 50);
        ctx.lineTo(350, canvas.height - 50);
        ctx.stroke();
        
        // Y-axis (class separator)
        ctx.beginPath();
        ctx.moveTo(50, canvas.height/2);
        ctx.lineTo(350, canvas.height/2);
        ctx.stroke();
        
        // Draw data points
        for (const point of this.dataPoints) {
            const canvasX = 50 + (point.x + 5) / 10 * 300;
            const canvasY = point.y === 1 ? canvas.height/4 : 3*canvas.height/4;
            
            ctx.fillStyle = point.y === 1 ? &apos;#4CAF50&apos; : &apos;#f44336&apos;;
            ctx.beginPath();
            ctx.arc(canvasX, canvasY, 5, 0, 2 * Math.PI);
            ctx.fill();
        }
        
        // Draw decision boundary
        if (this.w1 !== 0) {
            const decisionX = -this.w0 / this.w1;
            if (decisionX &gt;= -5 &amp;&amp; decisionX &lt;= 5) {
                const canvasX = 50 + (decisionX + 5) / 10 * 300;
                ctx.strokeStyle = &apos;#2196F3&apos;;
                ctx.lineWidth = 3;
                ctx.beginPath();
                ctx.moveTo(canvasX, 20);
                ctx.lineTo(canvasX, canvas.height - 50);
                ctx.stroke();
            }
        }
        
        // Labels
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;Class 1&apos;, 10, 40);
        ctx.fillText(&apos;Class 0&apos;, 10, canvas.height - 60);
        ctx.fillText(&apos;x&apos;, 360, canvas.height - 30);
    }
    
    drawLoss() {
        const ctx = this.lossCtx;
        const canvas = this.lossCanvas;
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        if (this.dataPoints.length === 0) return;
        
        // Draw axes
        ctx.strokeStyle = &apos;#ccc&apos;;
        ctx.lineWidth = 1;
        
        // X-axis
        ctx.beginPath();
        ctx.moveTo(50, canvas.height - 50);
        ctx.lineTo(canvas.width - 20, canvas.height - 50);
        ctx.stroke();
        
        // Y-axis
        ctx.beginPath();
        ctx.moveTo(50, 20);
        ctx.lineTo(50, canvas.height - 50);
        ctx.stroke();
        
        // Calculate loss surface
        const originalW0 = this.w0;
        const originalW1 = this.w1;
        
        const w0Range = [-3, 3];
        const w1Range = [-2, 2];
        const resolution = 50;
        
        let minLoss = Infinity;
        let maxLoss = -Infinity;
        const lossData = [];
        
        for (let i = 0; i &lt;= resolution; i++) {
            lossData[i] = [];
            for (let j = 0; j &lt;= resolution; j++) {
                this.w0 = w0Range[0] + (w0Range[1] - w0Range[0]) * i / resolution;
                this.w1 = w1Range[0] + (w1Range[1] - w1Range[0]) * j / resolution;
                const loss = this.calculateLoss();
                lossData[i][j] = loss;
                minLoss = Math.min(minLoss, loss);
                maxLoss = Math.max(maxLoss, loss);
            }
        }
        
        // Draw contour lines
        const numContours = 10;
        for (let c = 0; c &lt; numContours; c++) {
            const level = minLoss + (maxLoss - minLoss) * c / numContours;
            ctx.strokeStyle = `hsl(${240 - c * 20}, 70%, 60%)`;
            ctx.lineWidth = 1;
            
            // Simple contour drawing (could be improved)
            for (let i = 0; i &lt; resolution; i++) {
                for (let j = 0; j &lt; resolution; j++) {
                    if (Math.abs(lossData[i][j] - level) &lt; (maxLoss - minLoss) / numContours / 2) {
                        const x = 50 + i / resolution * (canvas.width - 70);
                        const y = canvas.height - 50 - j / resolution * (canvas.height - 70);
                        ctx.fillRect(x, y, 2, 2);
                    }
                }
            }
        }
        
        // Mark current position
        this.w0 = originalW0;
        this.w1 = originalW1;
        
        const currentX = 50 + (this.w0 - w0Range[0]) / (w0Range[1] - w0Range[0]) * (canvas.width - 70);
        const currentY = canvas.height - 50 - (this.w1 - w1Range[0]) / (w1Range[1] - w1Range[0]) * (canvas.height - 70);
        
        ctx.fillStyle = &apos;#ff6b6b&apos;;
        ctx.beginPath();
        ctx.arc(currentX, currentY, 6, 0, 2 * Math.PI);
        ctx.fill();
        
        // Labels
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;w₁&apos;, 10, canvas.height - 30);
        ctx.fillText(&apos;w₀&apos;, canvas.width - 20, canvas.height - 30);
    }
    
    updateVisualization() {
        this.drawSigmoid();
        this.drawClassification();
        this.drawLoss();
        
        // Update info panel
        const equation = `${this.w0.toFixed(1)} + ${this.w1.toFixed(1)}·x`;
        document.getElementById(&apos;equation&apos;).textContent = equation;
        
        const decisionBoundary = this.w1 !== 0 ? (-this.w0 / this.w1).toFixed(2) : &apos;∞&apos;;
        document.getElementById(&apos;decision-boundary&apos;).textContent = decisionBoundary;
        
        const loss = this.calculateLoss();
        document.getElementById(&apos;current-loss&apos;).textContent = loss.toFixed(3);
        
        const accuracy = this.calculateAccuracy();
        document.getElementById(&apos;accuracy&apos;).textContent = (accuracy * 100).toFixed(1) + &apos;%&apos;;
    }
}

// Initialize demo when page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, () =&gt; {
    new LogisticRegressionDemo();
});
&lt;/script&gt;

&lt;style&gt;
#logistic-regression-demo {
    font-family: Arial, sans-serif;
    max-width: 1000px;
    margin: 0 auto;
}

#logistic-regression-demo canvas {
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#logistic-regression-demo input[type=&quot;range&quot;] {
    width: 100%;
    margin: 5px 0;
}

#logistic-regression-demo button {
    background-color: #2196F3;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

#logistic-regression-demo button:hover {
    background-color: #1976D2;
}

#model-info {
    background-color: #f5f5f5;
    padding: 15px;
    border-radius: 4px;
    font-size: 14px;
}

#model-info p {
    margin: 5px 0;
}
&lt;/style&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Practice exercise:&lt;/strong&gt; Try changing the parameters in the visualization above to understand better how logistic regression works!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-further-reading-alternative-link-functions-to-the-sigmoid&quot;&gt;📖 Further Reading: Alternative Link Functions to the Sigmoid&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;This section is for those who want to learn more about why the sigmoid function is chosen, why the cross-entropy loss is used, and the alternatives in generalized linear models.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;-why-is-cross-entropy-the-loss-function&quot;&gt;🧮 Why Is Cross-Entropy the Loss Function?&lt;/h2&gt;

&lt;h3 id=&quot;-goal-find-the-best-weights&quot;&gt;🎯 Goal: Find the Best Weights&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Core question:&lt;/strong&gt; How do we find the weights \(\mathbf{w}\) so that the model predicts as accurately as possible?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Idea:&lt;/strong&gt; Choose \(\mathbf{w}\) so that &lt;strong&gt;the probability of observing the actual data is highest&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;-from-probability-to-cross-entropy&quot;&gt;🔍 From Probability to Cross-Entropy&lt;/h3&gt;

&lt;h4 id=&quot;step-1-modeling-the-probability&quot;&gt;&lt;strong&gt;Step 1: Modeling the probability&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;For each data sample \((\mathbf{x}_i, y_i)\), the model predicts:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;If \(y_i = 1\): the probability is \(p_i = \sigma(\mathbf{w}^T \mathbf{x}_i)\)&lt;/li&gt;
  &lt;li&gt;If \(y_i = 0\): the probability is \(1 - p_i = 1 - \sigma(\mathbf{w}^T \mathbf{x}_i)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;step-2-likelihood&quot;&gt;&lt;strong&gt;Step 2: Likelihood&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; With the current weights \(\mathbf{w}\), how likely is it to observe all of the data?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt; Multiply the probabilities of all the samples:
\(\text{Likelihood} = p_1^{y_1} \cdot (1-p_1)^{1-y_1} \times p_2^{y_2} \cdot (1-p_2)^{1-y_2} \times \ldots\)&lt;/p&gt;

&lt;h4 id=&quot;step-3-the-maximum-likelihood-principle&quot;&gt;&lt;strong&gt;Step 3: The Maximum Likelihood Principle&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Principle:&lt;/strong&gt; Choose \(\mathbf{w}\) to &lt;strong&gt;maximize the likelihood&lt;/strong&gt; = choose \(\mathbf{w}\) so that the observed data is as likely as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A practical problem:&lt;/strong&gt; The likelihood is a product of many small numbers → hard to compute and numerically unstable.&lt;/p&gt;

&lt;h4 id=&quot;step-4-log-likelihood&quot;&gt;&lt;strong&gt;Step 4: Log-Likelihood&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Take the logarithm to turn the product into a sum:
\(\log(\text{Likelihood}) = \sum_{i=1}^n \left[ y_i \log p_i + (1-y_i) \log (1-p_i) \right]\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;More numerically stable&lt;/li&gt;
  &lt;li&gt;Maximizing the log-likelihood = maximizing the likelihood&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;step-5-cross-entropy-loss&quot;&gt;&lt;strong&gt;Step 5: Cross-Entropy Loss&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Final conversion:&lt;/strong&gt; Maximizing = minimizing the negative&lt;/p&gt;

\[J(\mathbf{w}) = -\log(\text{Likelihood}) = -\sum_{i=1}^n \left[ y_i \log p_i + (1-y_i) \log (1-p_i) \right]\]

&lt;p&gt;&lt;strong&gt;This is exactly the Cross-Entropy Loss!&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;-why-is-cross-entropy-reasonable&quot;&gt;💡 Why Is Cross-Entropy “Reasonable”?&lt;/h3&gt;

&lt;h4 id=&quot;1-heavy-penalty-for-wrong-predictions&quot;&gt;&lt;strong&gt;1. Heavy penalty for wrong predictions&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Illustrative example:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Case 1:&lt;/strong&gt; \(y = 1\) (actual), \(p = 0.9\) (predicted)
    &lt;ul&gt;
      &lt;li&gt;Loss = \(-1 \times \log(0.9) = 0.105\) (low - good!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 2:&lt;/strong&gt; \(y = 1\) (actual), \(p = 0.1\) (predicted)
    &lt;ul&gt;
      &lt;li&gt;Loss = \(-1 \times \log(0.1) = 2.303\) (high - bad!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; The more wrong the prediction, the larger the loss, and it is &lt;strong&gt;unbounded&lt;/strong&gt; (it grows roughly linearly in the size of the error as \(p \to 0\)).&lt;/p&gt;

&lt;h4 id=&quot;2-it-encourages-confident-predictions&quot;&gt;&lt;strong&gt;2. It encourages confident predictions&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Cross-entropy “rewards” confident and correct predictions:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(p = 0.99\) when \(y = 1\) → very low loss&lt;/li&gt;
  &lt;li&gt;\(p = 0.51\) when \(y = 1\) → the loss is still high (even though it is correct)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-smooth-and-differentiable&quot;&gt;&lt;strong&gt;3. Smooth and differentiable&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Unlike accuracy (0-1 loss), cross-entropy is:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Smooth&lt;/strong&gt;: has derivatives everywhere&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex&lt;/strong&gt;: guarantees a global optimum&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Informative gradient&lt;/strong&gt;: the gradient is large when the prediction is wrong&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-comparison-with-other-losses&quot;&gt;🔄 Comparison with Other Losses&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Loss Function&lt;/th&gt;
      &lt;th&gt;Formula&lt;/th&gt;
      &lt;th&gt;Advantages&lt;/th&gt;
      &lt;th&gt;Disadvantages&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Cross-Entropy&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(-[y\log p + (1-y)\log(1-p)]\)&lt;/td&gt;
      &lt;td&gt;Smooth, convex, principled&lt;/td&gt;
      &lt;td&gt;Sensitive to outliers&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Mean Squared Error&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\((y - p)^2\)&lt;/td&gt;
      &lt;td&gt;Simple, familiar&lt;/td&gt;
      &lt;td&gt;Not probabilistic&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;0-1 Loss&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\mathbf{1}[y \neq \text{round}(p)]\)&lt;/td&gt;
      &lt;td&gt;Direct accuracy&lt;/td&gt;
      &lt;td&gt;Non-differentiable&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;-conclusion-on-cross-entropy&quot;&gt;🎯 Conclusion on Cross-Entropy&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Cross-Entropy is not an arbitrary choice&lt;/strong&gt; - it arises naturally from:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;The Maximum Likelihood principle&lt;/strong&gt; - the best way to fit a probabilistic model&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Good mathematical properties&lt;/strong&gt; - convex, smooth, differentiable&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical meaning&lt;/strong&gt; - heavily penalizes wrong predictions, encourages confidence&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;This is why cross-entropy is the “gold standard” for classification problems!&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;-why-choose-the-sigmoid-function&quot;&gt;🤔 Why Choose the Sigmoid Function?&lt;/h2&gt;

&lt;h3 id=&quot;1-mathematical-requirements-for-an-activation-function&quot;&gt;1. &lt;strong&gt;Mathematical Requirements for an Activation Function&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;To convert from \(\mathbb{R}\) to a probability in \([0,1]\), we need a function \(g: \mathbb{R} \to [0,1]\) satisfying:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mandatory requirements:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Monotonic&lt;/strong&gt;: \(g&apos;(z) &amp;gt; 0\) (preserves ordering)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Bounded&lt;/strong&gt;: \(g(z) \in [0,1]\) (a valid probability)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Smooth&lt;/strong&gt;: differentiable, so we can compute gradients&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Asymptotic&lt;/strong&gt;: \(\lim_{z \to -\infty} g(z) = 0\), \(\lim_{z \to +\infty} g(z) = 1\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Desirable requirements:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;🎯 &lt;strong&gt;Simple derivative&lt;/strong&gt;: the derivative is easy to compute&lt;/li&gt;
  &lt;li&gt;🎯 &lt;strong&gt;Probabilistic interpretation&lt;/strong&gt;: it has a probabilistic meaning&lt;/li&gt;
  &lt;li&gt;🎯 &lt;strong&gt;Symmetric&lt;/strong&gt;: \(g(-z) = 1 - g(z)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-the-origin-in-odds-and-logit&quot;&gt;2. &lt;strong&gt;The Origin in Odds and Logit&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Odds:&lt;/strong&gt;
\(\text{Odds} = \frac{P(y=1|x)}{P(y=0|x)} = \frac{P(y=1|x)}{1-P(y=1|x)}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log-odds (Logit):&lt;/strong&gt;
\(\text{logit}(p) = \log\left(\frac{p}{1-p}\right)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A linear model for the log-odds:&lt;/strong&gt;
\(\log\left(\frac{P(y=1|x)}{1-P(y=1|x)}\right) = \mathbf{w}^T \mathbf{x}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solving back for P:&lt;/strong&gt;
\(\frac{P(y=1|x)}{1-P(y=1|x)} = e^{\mathbf{w}^T \mathbf{x}}\)&lt;/p&gt;

\[P(y=1|x) = (1-P(y=1|x)) \cdot e^{\mathbf{w}^T \mathbf{x}}\]

\[P(y=1|x) = e^{\mathbf{w}^T \mathbf{x}} - P(y=1|x) \cdot e^{\mathbf{w}^T \mathbf{x}}\]

\[P(y=1|x)(1 + e^{\mathbf{w}^T \mathbf{x}}) = e^{\mathbf{w}^T \mathbf{x}}\]

\[P(y=1|x) = \frac{e^{\mathbf{w}^T \mathbf{x}}}{1 + e^{\mathbf{w}^T \mathbf{x}}} = \frac{1}{1 + e^{-\mathbf{w}^T \mathbf{x}}} = \sigma(\mathbf{w}^T \mathbf{x})\]

&lt;p&gt;⟹ &lt;strong&gt;The sigmoid arises naturally from the linear log-odds model!&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;3-special-advantages-of-the-sigmoid&quot;&gt;3. &lt;strong&gt;Special Advantages of the Sigmoid&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;a-an-elegant-derivative&quot;&gt;&lt;strong&gt;a) An Elegant Derivative&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\sigma&apos;(z) = \sigma(z)(1 - \sigma(z))\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;No need to recompute \(e^{-z}\)&lt;/li&gt;
  &lt;li&gt;Efficient gradient descent&lt;/li&gt;
  &lt;li&gt;Simple backpropagation&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;b-symmetry&quot;&gt;&lt;strong&gt;b) Symmetry&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\sigma(-z) = 1 - \sigma(z)\)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Meaning:&lt;/strong&gt; If $$P(y=1&lt;/td&gt;
      &lt;td&gt;x) = 0.7\(then\)P(y=1&lt;/td&gt;
      &lt;td&gt;-x) = 0.3$$ (for the model without a bias term)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h4 id=&quot;c-a-natural-probabilistic-interpretation&quot;&gt;&lt;strong&gt;c) A Natural Probabilistic Interpretation&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(z = 0 \Rightarrow P = 0.5\) (no bias)&lt;/li&gt;
  &lt;li&gt;\(z &amp;gt; 0 \Rightarrow P &amp;gt; 0.5\) (leans toward class 1)&lt;/li&gt;
  &lt;li&gt;\(z &amp;lt; 0 \Rightarrow P &amp;lt; 0.5\) (leans toward class 0)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-why-do-we-need-alternative-functions&quot;&gt;🔄 Why Do We Need Alternative Functions?&lt;/h3&gt;

&lt;p&gt;Although the sigmoid is the most popular choice, in some special cases other link functions can be more suitable:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Data with different tail behavior&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rare events or imbalanced data&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Special modeling requirements&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Different theoretical assumptions&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;1-tanh-function&quot;&gt;1. &lt;strong&gt;Tanh Function&lt;/strong&gt;&lt;/h3&gt;

\[\tanh(z) = \frac{e^z - e^{-z}}{e^z + e^{-z}} = \frac{e^{2z} - 1}{e^{2z} + 1}\]

&lt;p&gt;&lt;strong&gt;Relationship with the Sigmoid:&lt;/strong&gt;
\(\tanh(z) = 2\sigma(2z) - 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Range&lt;/strong&gt;: \((-1, 1)\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Symmetric about the origin&lt;/strong&gt;: \(\tanh(-z) = -\tanh(z)\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Derivative&lt;/strong&gt;: \(\tanh&apos;(z) = 1 - \tanh^2(z)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conversion to a probability:&lt;/strong&gt; \(p = \frac{\tanh(z) + 1}{2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applications:&lt;/strong&gt; Neural networks (hidden layers), when outputs centered around 0 are needed&lt;/p&gt;

&lt;h3 id=&quot;2-probit-function-inverse-normal-cdf&quot;&gt;2. &lt;strong&gt;Probit Function (Inverse Normal CDF)&lt;/strong&gt;&lt;/h3&gt;

\[\Phi^{-1}(p) = z \Leftrightarrow p = \Phi(z) = \int_{-\infty}^z \frac{1}{\sqrt{2\pi}} e^{-t^2/2} dt\]

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Range&lt;/strong&gt;: \((0, 1)\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Symmetric&lt;/strong&gt;: \(\Phi(-z) = 1 - \Phi(z)\)&lt;/li&gt;
  &lt;li&gt;❌ &lt;strong&gt;No closed form&lt;/strong&gt;: requires numerical integration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Comparison with the Sigmoid:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Sigmoid&lt;/strong&gt;: exponentially decaying tails $$\sim e^{-&lt;/td&gt;
          &lt;td&gt;z&lt;/td&gt;
          &lt;td&gt;}$$&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Probit&lt;/strong&gt;: Gaussian decaying tails \(\sim e^{-z^2/2}\) (faster)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Applications:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Econometrics (probit regression)&lt;/li&gt;
  &lt;li&gt;When the data has a nearly Gaussian distribution&lt;/li&gt;
  &lt;li&gt;Threshold models&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-gumbel-log-log-function&quot;&gt;3. &lt;strong&gt;Gumbel (Log-log) Function&lt;/strong&gt;&lt;/h3&gt;

\[F(z) = e^{-e^{-z}}\]

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Range&lt;/strong&gt;: \((0, 1)\)&lt;/li&gt;
  &lt;li&gt;❌ &lt;strong&gt;Not symmetric&lt;/strong&gt;: Right-skewed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The CDF of the Gumbel distribution&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Applications:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Extreme value theory&lt;/li&gt;
  &lt;li&gt;Survival analysis&lt;/li&gt;
  &lt;li&gt;Modeling maximum values&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-complementary-log-log&quot;&gt;4. &lt;strong&gt;Complementary Log-log&lt;/strong&gt;&lt;/h3&gt;

\[F(z) = 1 - e^{-e^z}\]

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Range&lt;/strong&gt;: \((0, 1)\)&lt;/li&gt;
  &lt;li&gt;❌ &lt;strong&gt;Not symmetric&lt;/strong&gt;: Left-skewed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The complement of the Gumbel&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Applications:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Rare events modeling&lt;/strong&gt; (y=1 is rare)&lt;/li&gt;
  &lt;li&gt;Survival analysis (hazard modeling)&lt;/li&gt;
  &lt;li&gt;Time-to-event data&lt;/li&gt;
  &lt;li&gt;Poisson regression with binary outcomes&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5-cauchit-function&quot;&gt;5. &lt;strong&gt;Cauchit Function&lt;/strong&gt;&lt;/h3&gt;

\[F(z) = \frac{1}{2} + \frac{1}{\pi} \arctan(z)\]

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Range&lt;/strong&gt;: \((0, 1)\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Symmetric&lt;/strong&gt;: \(F(-z) = 1 - F(z)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Heavy tails&lt;/strong&gt;: slower decay than sigmoid/probit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Applications:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Robust regression (outlier-resistant)&lt;/li&gt;
  &lt;li&gt;Heavy-tailed error distributions&lt;/li&gt;
  &lt;li&gt;Financial modeling&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-interactive-comparison-tool&quot;&gt;📊 Interactive Comparison Tool&lt;/h2&gt;

&lt;div id=&quot;link-functions-comparison&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;margin-bottom: 20px;&quot;&gt;
        &lt;h4&gt;🎛️ Display Controls&lt;/h4&gt;
        &lt;div style=&quot;display: flex; gap: 15px; flex-wrap: wrap;&quot;&gt;
            &lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;show-sigmoid&quot; checked=&quot;&quot; /&gt; Sigmoid&lt;/label&gt;
            &lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;show-tanh&quot; checked=&quot;&quot; /&gt; Tanh (scaled)&lt;/label&gt;
            &lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;show-probit&quot; checked=&quot;&quot; /&gt; Probit&lt;/label&gt;
            &lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;show-gumbel&quot; /&gt; Gumbel&lt;/label&gt;
            &lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;show-cauchit&quot; /&gt; Cauchit&lt;/label&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px;&quot;&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📈 Link Functions Comparison&lt;/h4&gt;
            &lt;canvas id=&quot;link-functions-canvas&quot; width=&quot;500&quot; height=&quot;400&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📊 Properties Comparison&lt;/h4&gt;
            &lt;div id=&quot;properties-table&quot; style=&quot;font-size: 14px;&quot;&gt;
                &lt;table style=&quot;width: 100%; border-collapse: collapse;&quot;&gt;
                    &lt;thead&gt;
                        &lt;tr style=&quot;background-color: #f0f0f0;&quot;&gt;
                            &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Function&lt;/th&gt;
                            &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Symmetric&lt;/th&gt;
                            &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Tail Behavior&lt;/th&gt;
                            &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Computation&lt;/th&gt;
                        &lt;/tr&gt;
                    &lt;/thead&gt;
                    &lt;tbody&gt;
                        &lt;tr&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;Sigmoid&lt;/strong&gt;&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;✅ Yes&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Exponential&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;⚡ Fast&lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;Tanh&lt;/strong&gt;&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;✅ Yes&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Exponential&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;⚡ Fast&lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;Probit&lt;/strong&gt;&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;✅ Yes&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Gaussian&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;🐌 Slow&lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;Gumbel&lt;/strong&gt;&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;❌ No&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Right-skewed&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;⚡ Fast&lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;Cauchit&lt;/strong&gt;&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;✅ Yes&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Heavy tails&lt;/td&gt;
                            &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;⚡ Fast&lt;/td&gt;
                        &lt;/tr&gt;
                    &lt;/tbody&gt;
                &lt;/table&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
class LinkFunctionsComparison {
    constructor() {
        this.canvas = document.getElementById(&apos;link-functions-canvas&apos;);
        if (!this.canvas) return;
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.setupEventListeners();
        this.draw();
    }
    
    setupEventListeners() {
        const checkboxes = [&apos;sigmoid&apos;, &apos;tanh&apos;, &apos;probit&apos;, &apos;gumbel&apos;, &apos;cauchit&apos;];
        checkboxes.forEach(name =&gt; {
            const checkbox = document.getElementById(`show-${name}`);
            if (checkbox) {
                checkbox.addEventListener(&apos;change&apos;, () =&gt; {
                    this.draw();
                });
            }
        });
    }
    
    sigmoid(z) {
        return 1 / (1 + Math.exp(-z));
    }
    
    tanh_scaled(z) {
        return (Math.tanh(z) + 1) / 2; // Scale tanh from [-1,1] to [0,1]
    }
    
    // Approximation of probit function (inverse normal CDF)
    probit(z) {
        // Using rational approximation for normal CDF
        const a1 = 0.254829592;
        const a2 = -0.284496736;
        const a3 = 1.421413741;
        const a4 = -1.453152027;
        const a5 = 1.061405429;
        const p = 0.3275911;
        
        const sign = z &lt; 0 ? -1 : 1;
        z = Math.abs(z) / Math.sqrt(2);
        
        const t = 1.0 / (1.0 + p * z);
        const y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * Math.exp(-z * z);
        
        return 0.5 * (1.0 + sign * y);
    }
    
    gumbel(z) {
        return Math.exp(-Math.exp(-z));
    }
    
    cauchit(z) {
        return 0.5 + Math.atan(z) / Math.PI;
    }
    
    draw() {
        const ctx = this.ctx;
        const canvas = this.canvas;
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Draw axes
        ctx.strokeStyle = &apos;#ccc&apos;;
        ctx.lineWidth = 1;
        
        // X-axis
        ctx.beginPath();
        ctx.moveTo(50, canvas.height - 50);
        ctx.lineTo(canvas.width - 20, canvas.height - 50);
        ctx.stroke();
        
        // Y-axis
        ctx.beginPath();
        ctx.moveTo(50, 20);
        ctx.lineTo(50, canvas.height - 50);
        ctx.stroke();
        
        // Grid lines
        ctx.strokeStyle = &apos;#f0f0f0&apos;;
        ctx.lineWidth = 0.5;
        
        // Horizontal grid lines
        for (let i = 1; i &lt;= 4; i++) {
            const y = 20 + (canvas.height - 70) * i / 5;
            ctx.beginPath();
            ctx.moveTo(50, y);
            ctx.lineTo(canvas.width - 20, y);
            ctx.stroke();
        }
        
        // Vertical grid lines
        for (let i = 1; i &lt;= 9; i++) {
            const x = 50 + (canvas.width - 70) * i / 10;
            ctx.beginPath();
            ctx.moveTo(x, 20);
            ctx.lineTo(x, canvas.height - 50);
            ctx.stroke();
        }
        
        // Draw functions
        const functions = [
            { name: &apos;sigmoid&apos;, func: this.sigmoid, color: &apos;#2196F3&apos;, label: &apos;Sigmoid&apos; },
            { name: &apos;tanh&apos;, func: this.tanh_scaled, color: &apos;#4CAF50&apos;, label: &apos;Tanh (scaled)&apos; },
            { name: &apos;probit&apos;, func: this.probit, color: &apos;#FF9800&apos;, label: &apos;Probit&apos; },
            { name: &apos;gumbel&apos;, func: this.gumbel, color: &apos;#9C27B0&apos;, label: &apos;Gumbel&apos; },
            { name: &apos;cauchit&apos;, func: this.cauchit, color: &apos;#F44336&apos;, label: &apos;Cauchit&apos; }
        ];
        
        functions.forEach(({name, func, color, label}) =&gt; {
            const checkbox = document.getElementById(`show-${name}`);
            if (checkbox &amp;&amp; checkbox.checked) {
                ctx.strokeStyle = color;
                ctx.lineWidth = 2;
                ctx.beginPath();
                
                for (let i = 0; i &lt;= 400; i++) {
                    const z = (i / 400) * 10 - 5; // z from -5 to 5
                    let y;
                    
                    try {
                        y = func.call(this, z);
                        if (isNaN(y) || !isFinite(y)) continue;
                    } catch (e) {
                        continue;
                    }
                    
                    const canvasX = 50 + (z + 5) / 10 * (canvas.width - 70);
                    const canvasY = canvas.height - 50 - y * (canvas.height - 70);
                    
                    if (i === 0) {
                        ctx.moveTo(canvasX, canvasY);
                    } else {
                        ctx.lineTo(canvasX, canvasY);
                    }
                }
                ctx.stroke();
            }
        });
        
        // Draw legend
        let legendY = 30;
        functions.forEach(({name, color, label}) =&gt; {
            const checkbox = document.getElementById(`show-${name}`);
            if (checkbox &amp;&amp; checkbox.checked) {
                ctx.strokeStyle = color;
                ctx.lineWidth = 3;
                ctx.beginPath();
                ctx.moveTo(canvas.width - 150, legendY);
                ctx.lineTo(canvas.width - 120, legendY);
                ctx.stroke();
                
                ctx.fillStyle = &apos;#333&apos;;
                ctx.font = &apos;12px Arial&apos;;
                ctx.fillText(label, canvas.width - 115, legendY + 4);
                
                legendY += 20;
            }
        });
        
        // Labels
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;z&apos;, canvas.width - 15, canvas.height - 30);
        ctx.fillText(&apos;P(y=1|z)&apos;, 10, 15);
        
        // Axis labels
        ctx.fillText(&apos;-5&apos;, 45, canvas.height - 30);
        ctx.fillText(&apos;0&apos;, 245, canvas.height - 30);
        ctx.fillText(&apos;5&apos;, 445, canvas.height - 30);
        ctx.fillText(&apos;0&apos;, 35, canvas.height - 45);
        ctx.fillText(&apos;0.5&apos;, 30, canvas.height/2 + 5);
        ctx.fillText(&apos;1&apos;, 35, 25);
    }
}

// Initialize comparison when page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, () =&gt; {
    new LinkFunctionsComparison();
});
&lt;/script&gt;

&lt;h2 id=&quot;-guide-to-choosing-a-link-function&quot;&gt;🎯 Guide to Choosing a Link Function&lt;/h2&gt;

&lt;h3 id=&quot;sigmoid-logistic---the-default-choice-&quot;&gt;&lt;strong&gt;Sigmoid (Logistic)&lt;/strong&gt; - The Default Choice ⭐&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use when:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;A standard binary classification problem&lt;/li&gt;
  &lt;li&gt;High computational speed is needed&lt;/li&gt;
  &lt;li&gt;You want to interpret odds ratios&lt;/li&gt;
  &lt;li&gt;The data is balanced, with no extreme outliers&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;probit---for-gaussian-data&quot;&gt;&lt;strong&gt;Probit&lt;/strong&gt; - For Gaussian Data&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use when:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The data has a nearly Gaussian distribution&lt;/li&gt;
  &lt;li&gt;You need to model threshold effects&lt;/li&gt;
  &lt;li&gt;You care about exact tail behavior&lt;/li&gt;
  &lt;li&gt;You have computation time to spare (slower than the sigmoid)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;complementary-log-log---for-rare-events&quot;&gt;&lt;strong&gt;Complementary Log-log&lt;/strong&gt; - For Rare Events&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use when:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Modeling rare events (y=1 is rare)&lt;/li&gt;
  &lt;li&gt;Survival analysis&lt;/li&gt;
  &lt;li&gt;Time-to-event data&lt;/li&gt;
  &lt;li&gt;Asymmetric data distribution&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;cauchit---for-heavy-tailed-data&quot;&gt;&lt;strong&gt;Cauchit&lt;/strong&gt; - For Heavy-tailed Data&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use when:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The data has many outliers&lt;/li&gt;
  &lt;li&gt;Heavy-tailed distributions&lt;/li&gt;
  &lt;li&gt;Robust modeling is needed&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-conclusion-on-link-functions&quot;&gt;💡 Conclusion on Link Functions&lt;/h2&gt;

&lt;h3 id=&quot;why-is-the-sigmoid-still-the-best-choice&quot;&gt;&lt;strong&gt;Why Is the Sigmoid Still the Best Choice?&lt;/strong&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;🧮 Elegant Mathematics:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Simple derivative: \(\sigma&apos;(z) = \sigma(z)(1-\sigma(z))\)&lt;/li&gt;
      &lt;li&gt;Fast computation, numerically stable&lt;/li&gt;
      &lt;li&gt;No lookup tables or integrals needed&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;📊 A Natural Probabilistic Meaning:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Arises from the log-odds model&lt;/li&gt;
      &lt;li&gt;Intuitive interpretation (odds ratio)&lt;/li&gt;
      &lt;li&gt;Symmetric around 0.5&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;⚡ Computational Efficiency:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Only one division and one exponential&lt;/li&gt;
      &lt;li&gt;Efficient gradient descent&lt;/li&gt;
      &lt;li&gt;Suitable for big data&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;🔄 Guaranteed Convexity:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Cross-entropy with the sigmoid is always convex&lt;/li&gt;
      &lt;li&gt;Global optimum guaranteed&lt;/li&gt;
      &lt;li&gt;Algorithms converge stably&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Recommendation:&lt;/strong&gt; Start with the sigmoid, and switch to another link function only when there is a specific reason and after comparing performance experimentally.&lt;/p&gt;

&lt;h2 id=&quot;-extension-softmax-regression-multi-class-classification&quot;&gt;🔢 Extension: Softmax Regression (Multi-class Classification)&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Logistic Regression can only handle 2 classes. So how do we classify more than two classes?&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;-from-binary-to-multi-class&quot;&gt;🎯 From Binary to Multi-class&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The multi-class classification problem:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Input&lt;/strong&gt;: \(\mathbf{x} \in \mathbb{R}^p\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Output&lt;/strong&gt;: \(y \in \{1, 2, 3, ..., K\}\) (K classes)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Goal&lt;/strong&gt;: Predict the probability of each class&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Real-world examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Digit recognition&lt;/strong&gt;: 0, 1, 2, …, 9 (10 classes)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Email classification&lt;/strong&gt;: spam, promotion, social, primary (4 classes)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Disease diagnosis&lt;/strong&gt;: healthy, cold, sore throat, COVID (4 classes)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-the-softmax-function&quot;&gt;🧮 The Softmax Function&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Extension of the Sigmoid:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sigmoid&lt;/strong&gt;: \(\sigma(z) = \frac{e^z}{1 + e^z}\) (2 classes)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Softmax&lt;/strong&gt;: \(\text{softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_{j=1}^K e^{z_j}}\) (K classes)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Properties of Softmax:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;Sums to 1&lt;/strong&gt;: \(\sum_{i=1}^K \text{softmax}(\mathbf{z})_i = 1\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Always positive&lt;/strong&gt;: \(\text{softmax}(\mathbf{z})_i &amp;gt; 0\) \(\forall i\)&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Monotonic&lt;/strong&gt;: The class with larger \(z_i\) → higher probability&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Smooth&lt;/strong&gt;: differentiable everywhere&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-the-softmax-regression-model&quot;&gt;🏗️ The Softmax Regression Model&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Model parameters:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{W} \in \mathbb{R}^{p \times K}\): the weight matrix&lt;/li&gt;
  &lt;li&gt;\(\mathbf{b} \in \mathbb{R}^K\): the bias vector&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Forward pass:&lt;/strong&gt;
\(\mathbf{z} = \mathbf{W}^T \mathbf{x} + \mathbf{b}\)&lt;/p&gt;

\[P(y = k | \mathbf{x}) = \frac{e^{z_k}}{\sum_{j=1}^K e^{z_j}}\]

&lt;p&gt;&lt;strong&gt;Prediction:&lt;/strong&gt;
\(\hat{y} = \arg\max_k P(y = k | \mathbf{x})\)&lt;/p&gt;

&lt;h3 id=&quot;-cross-entropy-loss-for-multi-class&quot;&gt;📊 Cross-Entropy Loss for Multi-class&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;One-hot encoding:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(y = 2\) (class 2) → \(\mathbf{y} = [0, 1, 0, 0]\) (if K=4)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Multi-class Cross-Entropy:&lt;/strong&gt;
\(J(\mathbf{W}) = -\sum_{i=1}^n \sum_{k=1}^K y_{i,k} \log p_{i,k}\)&lt;/p&gt;

&lt;p&gt;with:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(y_{i,k}\): the one-hot encoding of sample \(i\)&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;$$p_{i,k} = P(y = k&lt;/td&gt;
          &lt;td&gt;\mathbf{x}_i)$$: the predicted probability&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;A natural extension&lt;/strong&gt; of binary cross-entropy&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Still convex&lt;/strong&gt; → gradient descent works well&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Heavily penalizes wrong predictions&lt;/strong&gt; as in the binary case&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-comparison-binary-vs-multi-class&quot;&gt;🔄 Comparison: Binary vs Multi-class&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aspect&lt;/th&gt;
      &lt;th&gt;Binary Logistic&lt;/th&gt;
      &lt;th&gt;Softmax Regression&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Number of classes&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;K ≥ 2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Activation&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Sigmoid&lt;/td&gt;
      &lt;td&gt;Softmax&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Parameters&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\mathbf{w} \in \mathbb{R}^p\)&lt;/td&gt;
      &lt;td&gt;\(\mathbf{W} \in \mathbb{R}^{p \times K}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;1 probability&lt;/td&gt;
      &lt;td&gt;K probabilities&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Loss&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Binary cross-entropy&lt;/td&gt;
      &lt;td&gt;Multi-class cross-entropy&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Gradient&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\mathbf{X}^T(\boldsymbol{\sigma} - \mathbf{y})\)&lt;/td&gt;
      &lt;td&gt;\(\mathbf{X}^T(\mathbf{P} - \mathbf{Y})\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-interactive-softmax-demo&quot;&gt;🎛️ Interactive Softmax Demo&lt;/h3&gt;

&lt;div id=&quot;softmax-demo&quot; style=&quot;margin: 20px 0;&quot;&gt;
    &lt;div style=&quot;display: flex; gap: 20px; margin-bottom: 20px;&quot;&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;🎚️ Logit Controls&lt;/h4&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;z1-slider&quot;&gt;z₁ (Class 1): &lt;span id=&quot;z1-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;z1-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;z2-slider&quot;&gt;z₂ (Class 2): &lt;span id=&quot;z2-value&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;z2-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;0.5&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;z3-slider&quot;&gt;z₃ (Class 3): &lt;span id=&quot;z3-value&quot;&gt;-0.5&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;z3-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;-0.5&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin: 10px 0;&quot;&gt;
                &lt;label for=&quot;z4-slider&quot;&gt;z₄ (Class 4): &lt;span id=&quot;z4-value&quot;&gt;-1.0&lt;/span&gt;&lt;/label&gt;
                &lt;input type=&quot;range&quot; id=&quot;z4-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;-1.0&quot; style=&quot;width: 100%;&quot; /&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📊 Softmax Probabilities&lt;/h4&gt;
            &lt;div id=&quot;probabilities-display&quot; style=&quot;font-family: monospace; font-size: 14px;&quot;&gt;
                &lt;div&gt;Class 1: &lt;span id=&quot;p1&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;div&gt;Class 2: &lt;span id=&quot;p2&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;div&gt;Class 3: &lt;span id=&quot;p3&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;div&gt;Class 4: &lt;span id=&quot;p4&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;hr /&gt;
                &lt;div&gt;&lt;strong&gt;Sum: &lt;span id=&quot;sum&quot;&gt;1.000&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
                &lt;div&gt;&lt;strong&gt;Predicted: Class &lt;span id=&quot;predicted&quot;&gt;1&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;display: flex; gap: 20px;&quot;&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;📈 Probability Bars&lt;/h4&gt;
            &lt;canvas id=&quot;prob-bars-canvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
        &lt;div style=&quot;flex: 1;&quot;&gt;
            &lt;h4&gt;🥧 Probability Pie Chart&lt;/h4&gt;
            &lt;canvas id=&quot;prob-pie-canvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
class SoftmaxDemo {
    constructor() {
        this.z = [1.0, 0.5, -0.5, -1.0];
        this.colors = [&apos;#FF6B6B&apos;, &apos;#4ECDC4&apos;, &apos;#45B7D1&apos;, &apos;#96CEB4&apos;];
        this.setupEventListeners();
        this.updateDisplay();
    }
    
    setupEventListeners() {
        for (let i = 1; i &lt;= 4; i++) {
            const slider = document.getElementById(`z${i}-slider`);
            if (slider) {
                slider.addEventListener(&apos;input&apos;, (e) =&gt; {
                    this.z[i-1] = parseFloat(e.target.value);
                    document.getElementById(`z${i}-value`).textContent = this.z[i-1].toFixed(1);
                    this.updateDisplay();
                });
            }
        }
    }
    
    softmax(z) {
        const maxZ = Math.max(...z);
        const expZ = z.map(zi =&gt; Math.exp(zi - maxZ)); // Numerical stability
        const sumExpZ = expZ.reduce((sum, exp) =&gt; sum + exp, 0);
        return expZ.map(exp =&gt; exp / sumExpZ);
    }
    
    updateDisplay() {
        const probs = this.softmax(this.z);
        const sum = probs.reduce((s, p) =&gt; s + p, 0);
        const predicted = probs.indexOf(Math.max(...probs)) + 1;
        
        // Update probability display
        for (let i = 1; i &lt;= 4; i++) {
            const elem = document.getElementById(`p${i}`);
            if (elem) {
                elem.textContent = probs[i-1].toFixed(3);
                elem.style.color = this.colors[i-1];
                elem.style.fontWeight = predicted === i ? &apos;bold&apos; : &apos;normal&apos;;
            }
        }
        
        const sumElem = document.getElementById(&apos;sum&apos;);
        if (sumElem) sumElem.textContent = sum.toFixed(3);
        
        const predElem = document.getElementById(&apos;predicted&apos;);
        if (predElem) {
            predElem.textContent = predicted;
            predElem.style.color = this.colors[predicted-1];
        }
        
        this.drawBars(probs);
        this.drawPie(probs);
    }
    
    drawBars(probs) {
        const canvas = document.getElementById(&apos;prob-bars-canvas&apos;);
        if (!canvas) return;
        
        const ctx = canvas.getContext(&apos;2d&apos;);
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        const barWidth = 60;
        const maxHeight = 200;
        const startX = 50;
        const startY = canvas.height - 50;
        
        // Draw axes
        ctx.strokeStyle = &apos;#ccc&apos;;
        ctx.lineWidth = 1;
        ctx.beginPath();
        ctx.moveTo(30, 30);
        ctx.lineTo(30, startY);
        ctx.lineTo(canvas.width - 20, startY);
        ctx.stroke();
        
        // Draw bars
        for (let i = 0; i &lt; 4; i++) {
            const x = startX + i * (barWidth + 20);
            const height = probs[i] * maxHeight;
            
            ctx.fillStyle = this.colors[i];
            ctx.fillRect(x, startY - height, barWidth, height);
            
            // Labels
            ctx.fillStyle = &apos;#333&apos;;
            ctx.font = &apos;12px Arial&apos;;
            ctx.textAlign = &apos;center&apos;;
            ctx.fillText(`Class ${i+1}`, x + barWidth/2, startY + 20);
            ctx.fillText(probs[i].toFixed(3), x + barWidth/2, startY - height - 5);
        }
        
        // Y-axis labels
        ctx.textAlign = &apos;right&apos;;
        ctx.fillText(&apos;0.0&apos;, 25, startY + 5);
        ctx.fillText(&apos;0.5&apos;, 25, startY - maxHeight/2 + 5);
        ctx.fillText(&apos;1.0&apos;, 25, startY - maxHeight + 5);
    }
    
    drawPie(probs) {
        const canvas = document.getElementById(&apos;prob-pie-canvas&apos;);
        if (!canvas) return;
        
        const ctx = canvas.getContext(&apos;2d&apos;);
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        const centerX = canvas.width / 2;
        const centerY = canvas.height / 2;
        const radius = 100;
        
        let currentAngle = -Math.PI / 2; // Start from top
        
        for (let i = 0; i &lt; 4; i++) {
            const sliceAngle = probs[i] * 2 * Math.PI;
            
            // Draw slice
            ctx.beginPath();
            ctx.moveTo(centerX, centerY);
            ctx.arc(centerX, centerY, radius, currentAngle, currentAngle + sliceAngle);
            ctx.closePath();
            ctx.fillStyle = this.colors[i];
            ctx.fill();
            ctx.strokeStyle = &apos;#fff&apos;;
            ctx.lineWidth = 2;
            ctx.stroke();
            
            // Draw label
            if (probs[i] &gt; 0.05) { // Only show label if slice is big enough
                const labelAngle = currentAngle + sliceAngle / 2;
                const labelX = centerX + Math.cos(labelAngle) * radius * 0.7;
                const labelY = centerY + Math.sin(labelAngle) * radius * 0.7;
                
                ctx.fillStyle = &apos;#fff&apos;;
                ctx.font = &apos;bold 12px Arial&apos;;
                ctx.textAlign = &apos;center&apos;;
                ctx.fillText(`${i+1}`, labelX, labelY + 4);
            }
            
            currentAngle += sliceAngle;
        }
        
        // Legend
        for (let i = 0; i &lt; 4; i++) {
            const legendY = 20 + i * 20;
            ctx.fillStyle = this.colors[i];
            ctx.fillRect(20, legendY, 15, 15);
            ctx.fillStyle = &apos;#333&apos;;
            ctx.font = &apos;12px Arial&apos;;
            ctx.textAlign = &apos;left&apos;;
            ctx.fillText(`Class ${i+1}: ${(probs[i] * 100).toFixed(1)}%`, 40, legendY + 12);
        }
    }
}

// Initialize demo when page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, () =&gt; {
    if (document.getElementById(&apos;softmax-demo&apos;)) {
        new SoftmaxDemo();
    }
});
&lt;/script&gt;

&lt;style&gt;
#softmax-demo {
    font-family: Arial, sans-serif;
    max-width: 1000px;
    margin: 0 auto;
}

#softmax-demo canvas {
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#softmax-demo input[type=&quot;range&quot;] {
    width: 100%;
    margin: 5px 0;
}

#probabilities-display {
    background-color: #f5f5f5;
    padding: 15px;
    border-radius: 4px;
    line-height: 1.6;
}

#probabilities-display div {
    margin: 5px 0;
}
&lt;/style&gt;

&lt;h3 id=&quot;-real-world-applications-of-softmax&quot;&gt;🎯 Real-World Applications of Softmax&lt;/h3&gt;

&lt;h4 id=&quot;1-computer-vision&quot;&gt;&lt;strong&gt;1. Computer Vision&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Image Classification&lt;/strong&gt;: ImageNet (1000 classes)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Object Detection&lt;/strong&gt;: COCO dataset (80 classes)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Medical Imaging&lt;/strong&gt;: X-ray and MRI classification&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-natural-language-processing&quot;&gt;&lt;strong&gt;2. Natural Language Processing&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sentiment Analysis&lt;/strong&gt;: positive, negative, neutral&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Language Detection&lt;/strong&gt;: English, Vietnamese, Chinese, …&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Text Classification&lt;/strong&gt;: news categories, spam detection&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-recommendation-systems&quot;&gt;&lt;strong&gt;3. Recommendation Systems&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Content Categories&lt;/strong&gt;: movies, music, books&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;User Preferences&lt;/strong&gt;: age groups, interests&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Product Classification&lt;/strong&gt;: electronics, fashion, food&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-connection-with-deep-learning&quot;&gt;🔄 Connection with Deep Learning&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Softmax is an important building block:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The &lt;strong&gt;output layer&lt;/strong&gt; of neural networks&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Attention mechanisms&lt;/strong&gt; in Transformers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Policy networks&lt;/strong&gt; in Reinforcement Learning&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;From Logistic → Softmax → Neural Networks:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Logistic Regression&lt;/strong&gt;: Linear + Sigmoid&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Softmax Regression&lt;/strong&gt;: Linear + Softmax&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Neural Networks&lt;/strong&gt;: Multiple layers + Softmax&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-summary-of-softmax-regression&quot;&gt;💡 Summary of Softmax Regression&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;✅ &lt;strong&gt;A natural extension&lt;/strong&gt; of binary classification&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Meaningful probabilistic output&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Convex optimization&lt;/strong&gt; → reliable&lt;/li&gt;
  &lt;li&gt;✅ &lt;strong&gt;Efficient training&lt;/strong&gt; with gradient descent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;❌ &lt;strong&gt;Linear decision boundaries&lt;/strong&gt; (like logistic)&lt;/li&gt;
  &lt;li&gt;❌ &lt;strong&gt;Assumes linear separability&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;❌ &lt;strong&gt;May struggle&lt;/strong&gt; with complex patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Multi-class classification problems&lt;/li&gt;
  &lt;li&gt;When probabilistic outputs are needed&lt;/li&gt;
  &lt;li&gt;A baseline model before trying complex methods&lt;/li&gt;
  &lt;li&gt;When interpretability matters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Softmax Regression is the perfect stepping stone&lt;/strong&gt; between simple logistic regression and complex neural networks!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-02-03 Linear Regression from Statistical Perspective</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_02_03_Linear_Regression_Statistical_View/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_02_03_Linear_Regression_Statistical_View</id>
   <content type="html">&lt;p&gt;Why do we square errors in linear regression instead of taking their absolute values or fourth powers? Geometrically, squaring gives a clean orthogonal projection; statistically, it has an even deeper justification. When measurement noise follows a Gaussian bell curve, minimizing the sum of squared errors is mathematically &lt;em&gt;identical&lt;/em&gt; to Maximum Likelihood Estimation (MLE)—connecting Chapter 05’s quadratic optimization directly to statistical inference.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-where-convex-optimization-meets-statistical-inference&quot;&gt;Key ideas: Where Convex Optimization Meets Statistical Inference&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gaussian Noise Model \(\Longleftrightarrow\) Least Squares&lt;/strong&gt;: Assuming \(y_i = x_i^T w + \varepsilon_i\) with independent noise \(\varepsilon_i \sim \mathcal{N}(0, \sigma^2)\), the negative log-likelihood is \(\frac{n}{2}\ln(2\pi\sigma^2) + \frac{1}{2\sigma^2}\|Xw - y\|_2^2\). Dropping constants that do not depend on \(w\) recovers ordinary least squares \(\min_w \|Xw - y\|_2^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unbiasedness and the Gauss–Markov Theorem&lt;/strong&gt;: Under zero-mean homoscedastic errors, the OLS estimator \(\hat{w} = (X^T X)^{-1} X^T y\) is unbiased (\(\mathbb{E}[\hat{w}] = w_{\mathrm{true}}\)) and achieves the smallest covariance matrix \(\sigma^2 (X^T X)^{-1}\) among all &lt;em&gt;linear unbiased&lt;/em&gt; estimators (BLUE).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;MAP Estimation \(\Longleftrightarrow\) Regularized Optimization&lt;/strong&gt;: Placing a zero-mean Gaussian prior \(w \sim \mathcal{N}(0, \tau^2 I)\) adds a quadratic penalty \(\frac{\sigma^2}{\tau^2}\|w\|_2^2\) to the negative log-posterior, yielding &lt;strong&gt;Ridge Regression&lt;/strong&gt;. Replacing the prior with a Laplace distribution yields &lt;strong&gt;Lasso&lt;/strong&gt; (\(\ell_1\) penalty).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Noise Distribution Dictates the Loss Function&lt;/strong&gt;: If outliers cause heavy-tailed Laplace noise \(\varepsilon_i \sim \mathrm{Laplace}(0, b)\), MLE instead minimizes the \(\ell_1\) loss \(\|Xw - y\|_1\) (an LP!), explaining why robust regression switches norms when Gaussian assumptions fail.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-deriving-mle-and-estimator-variance-for-a-1-parameter-model&quot;&gt;Worked example: Deriving MLE and Estimator Variance for a 1-Parameter Model&lt;/h3&gt;

&lt;p&gt;Suppose we observe three noisy measurements of a scalar parameter \(w\) through \(y_i = x_i w + \varepsilon_i\) with \(\varepsilon_i \stackrel{\text{i.i.d.}}{\sim} \mathcal{N}(0, \sigma^2 = 4)\), where \(x = (1, 2, 2)^T\) and \(y = (3, 5, 7)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the Gaussian log-likelihood \(\ell(w)\)&lt;/strong&gt;:
\(\ell(w) = -\frac{3}{2}\ln(8\pi) - \frac{1}{2(4)}\Bigl((3 - w)^2 + (5 - 2w)^2 + (7 - 2w)^2\Bigr).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Maximize \(\ell(w)\) by minimizing the quadratic negative log-likelihood&lt;/strong&gt;:
\(S(w) = (3 - w)^2 + (5 - 2w)^2 + (7 - 2w)^2 = (9 - 6w + w^2) + (25 - 20w + 4w^2) + (49 - 28w + 4w^2) = 9w^2 - 54w + 83.\)
Setting \(S&apos;(w) = 18w - 54 = 0\) yields the MLE \(\hat{w}_{\mathrm{MLE}} = 3\).
(Cross-check via formula: \(x^T y / x^T x = (3 + 10 + 14)/(1 + 4 + 4) = 27/9 = 3\).)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the estimator’s sampling variance&lt;/strong&gt;:
\(\operatorname{Var}(\hat{w}_{\mathrm{MLE}}) = \sigma^2 (x^T x)^{-1} = \frac{4}{9} \approx 0.444, \qquad \mathrm{SE}(\hat{w}_{\mathrm{MLE}}) = \frac{2}{3} \approx 0.667.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with a Gaussian prior (MAP / Ridge) \(w \sim \mathcal{N}(0, \tau^2 = 4)\)&lt;/strong&gt;: Here \(\lambda = \sigma^2 / \tau^2 = 4/4 = 1\), so
\(\hat{w}_{\mathrm{MAP}} = \frac{x^T y}{x^T x + \lambda} = \frac{27}{9 + 1} = 2.7,\)
shrinking the estimate slightly toward zero in exchange for lower variance.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;linear-regression-from-statistical-perspective&quot;&gt;Linear Regression from Statistical Perspective&lt;/h2&gt;

&lt;p&gt;In this lesson, we explore linear regression from a probabilistic and statistical viewpoint, demonstrating why minimizing the sum of squared errors (MSE) is not only intuitive but also theoretically justified through maximum likelihood estimation.&lt;/p&gt;

&lt;h3 id=&quot;1-probabilistic-interpretation-of-linear-regression&quot;&gt;1. Probabilistic Interpretation of Linear Regression&lt;/h3&gt;

&lt;p&gt;From a probabilistic perspective, we can prove that the estimates obtained from linear regression based on minimizing the sum of squared errors from the MSE function are completely natural and reasonable.&lt;/p&gt;

&lt;p&gt;Indeed, we assume that the target variable and input variables are related through the equation:&lt;/p&gt;

\[y_i = \mathbf{w}^\top \mathbf{x}_i + \epsilon_i\]

&lt;p&gt;where $\epsilon_i$ represents the random error that any equation has. These are factors that cannot be explained by the model. Since our estimate is unbiased, this random error is assumed to satisfy the properties according to the Gauss-Markov hypothesis:&lt;/p&gt;

&lt;h4 id=&quot;assumption-1-zero-mean-error&quot;&gt;Assumption 1: Zero Mean Error&lt;/h4&gt;
&lt;p&gt;The errors $\epsilon_i$ are random variables with zero expectation:&lt;/p&gt;

\[\mathbb{E}(\epsilon_i) = 0\]

&lt;h4 id=&quot;assumption-2-uncorrelated-errors&quot;&gt;Assumption 2: Uncorrelated Errors&lt;/h4&gt;
&lt;p&gt;The random errors have no correlation:&lt;/p&gt;

\[\mathbb{E}(\epsilon_i \epsilon_j) = 0, \quad \forall i \neq j\]

&lt;h4 id=&quot;assumption-3-constant-variance-homoscedasticity&quot;&gt;Assumption 3: Constant Variance (Homoscedasticity)&lt;/h4&gt;
&lt;p&gt;The variance of the random error is invariant:&lt;/p&gt;

\[\text{Var}(\epsilon_i) = \sigma^2\]

&lt;h4 id=&quot;assumption-4-independence-of-errors-and-features&quot;&gt;Assumption 4: Independence of Errors and Features&lt;/h4&gt;
&lt;p&gt;The random error $\epsilon_i$ and the input variables $\mathbf{x}_i$ have no correlation:&lt;/p&gt;

\[\text{Cov}(\mathbf{x}_i, \epsilon_i) = 0, \quad \forall i = 1, \dots, p\]

&lt;h3 id=&quot;2-gaussian-distribution-of-errors&quot;&gt;2. Gaussian Distribution of Errors&lt;/h3&gt;

&lt;p&gt;Under these assumptions, the random errors $\epsilon_i$ form a Gaussian (normal) distribution with mean 0 and variance $\sigma^2$, denoted as $\epsilon_i \sim \mathcal{N}(0, \sigma^2)$. The probability density function at each point $\epsilon_i$ is:&lt;/p&gt;

\[p(\epsilon_i) = \frac{1}{\sqrt{2\pi \sigma^2}} \exp \left( -\frac{\epsilon_i^2}{2\sigma^2} \right)\]

&lt;p&gt;Substituting $\epsilon_i = y_i - \mathbf{w}^\top \mathbf{x}_i$ into the probability density function, we get:&lt;/p&gt;

\[p(y_i \mid \mathbf{x}_i; \mathbf{w}) = \frac{1}{\sqrt{2\pi \sigma^2}} \exp \left( -\frac{(y_i - \mathbf{w}^\top \mathbf{x}_i)^2}{2\sigma^2} \right)\]

&lt;p&gt;The notation $p(y_i \mid \mathbf{x}_i; \mathbf{w})$ indicates the probability of $y_i$ corresponding to $\mathbf{x}_i$, parameterized by $\mathbf{w}$. Here, $\mathbf{w}$ is known and is not considered as a condition of $y_i$, hence we use ; instead of ,.&lt;/p&gt;

&lt;h3 id=&quot;3-maximum-likelihood-estimation&quot;&gt;3. Maximum Likelihood Estimation&lt;/h3&gt;

&lt;p&gt;From a probabilistic perspective, $p(y_i \mid \mathbf{x}_i; \mathbf{w})$ is a function dependent on the input data $\mathbf{x}_i$ when the weight $\mathbf{w}$ is known. When viewing probability from the perspective of a function with respect to $\mathbf{w}$, we call it the likelihood function:&lt;/p&gt;

\[L(\mathbf{w}) = L(\mathbf{w}; \mathbf{X}, \mathbf{y}) = p(\mathbf{y} \mid \mathbf{X}; \mathbf{w})\]

&lt;p&gt;According to condition 2 of the Gauss-Markov hypothesis, the errors are independent, so the joint probability of the data equals the product of the probability densities of each data point:&lt;/p&gt;

\[\begin{align}
L(\mathbf{w}) &amp;amp;= \prod_{i=1}^{n} p(y_i \mid \mathbf{x}_i; \mathbf{w}) \\
&amp;amp;= \prod_{i=1}^{n} \frac{1}{\sqrt{2\pi \sigma^2}} \exp \left( -\frac{\epsilon_i^2}{2\sigma^2} \right)
\end{align}\]

&lt;p&gt;The likelihood function reflects the probabilistic relationship between $\mathbf{y}$ and $\mathbf{X}$. To find $\mathbf{w}$ such that this relationship is most appropriate, according to Maximum Likelihood Estimation, we choose $\mathbf{w}$ such that $L(\mathbf{w})$ is maximized.&lt;/p&gt;

&lt;h3 id=&quot;4-log-likelihood-optimization&quot;&gt;4. Log-Likelihood Optimization&lt;/h3&gt;

&lt;p&gt;Taking the logarithm of both sides to simplify the optimization problem:&lt;/p&gt;

\[\begin{align}
\hat{\mathbf{w}} &amp;amp;= \arg \max \log L(\mathbf{w}) \\
&amp;amp;= \arg \max \log \left[ \prod_{i=1}^{n} \frac{1}{\sqrt{2\pi \sigma^2}} \exp \left( -\frac{\epsilon_i^2}{2\sigma^2} \right) \right] \\
&amp;amp;= \arg \max \sum_{i=1}^{n} \log \left[ \frac{1}{\sqrt{2\pi \sigma^2}} \exp \left( -\frac{\epsilon_i^2}{2\sigma^2} \right) \right] \\
&amp;amp;= \arg \max \sum_{i=1}^{n} \left[ -\frac{\epsilon_i^2}{2\sigma^2} - \log \sqrt{2\pi \sigma^2} \right] \\
&amp;amp;= \arg \max \left[ -\frac{1}{2\sigma^2} \sum_{i=1}^{n} \epsilon_i^2 - n \log \sqrt{2\pi \sigma^2} \right]
\end{align}\]

&lt;p&gt;Since $\sigma^2$ and $2\pi$ are constants, optimizing the above function is equivalent to minimizing:&lt;/p&gt;

\[\sum_{i=1}^{n} \epsilon_i^2 = \sum_{i=1}^{n} (y_i - \mathbf{w}^\top \mathbf{x}_i)^2\]

&lt;p&gt;This is equivalent to minimizing the MSE function:&lt;/p&gt;

\[\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2\]

&lt;h3 id=&quot;5-theoretical-justification&quot;&gt;5. Theoretical Justification&lt;/h3&gt;

&lt;p&gt;Thus, from a probabilistic perspective, we have proven that linear regression based on minimizing the sum of squared errors is equivalent to optimizing the likelihood function. When the conditions of the Gauss-Markov hypothesis are satisfied, our estimate is the best linear unbiased estimator (BLUE). Assumptions about confidence intervals for predicted values and evaluation of the significance of weights through P-values can be made based on the normal distribution.&lt;/p&gt;

&lt;div id=&quot;mle-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Maximum Likelihood Estimation Visualization&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;!-- Canvas for visualization --&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;mleCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Visualization:&lt;/strong&gt; Blue dots are data points, red line is the fitted line, and the curves show the Gaussian distributions of errors.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;!-- Controls --&gt;
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Parameters&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;noise-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;Noise Level (σ): &lt;span id=&quot;noise-value&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;noise-slider&quot; min=&quot;0.1&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;0.5&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;slope-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;True Slope: &lt;span id=&quot;true-slope-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;slope-slider&quot; min=&quot;-2&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;intercept-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;True Intercept: &lt;span id=&quot;true-intercept-value&quot;&gt;0.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;intercept-slider&quot; min=&quot;-2&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;0.0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;button id=&quot;generate-data&quot; style=&quot;width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 10px;&quot;&gt;Generate New Data&lt;/button&gt;
                
                &lt;div id=&quot;mle-results&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;MLE Estimates:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Slope: &lt;span id=&quot;mle-slope&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Intercept: &lt;span id=&quot;mle-intercept&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Log-Likelihood: &lt;span id=&quot;log-likelihood&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;6-training-linear-regression-models-with-sklearn&quot;&gt;6. Training Linear Regression Models with sklearn&lt;/h3&gt;

&lt;p&gt;Sklearn is a comprehensive Python library for data science, supporting training of most machine learning models, building pipelines, data normalization, and performing cross-validation.&lt;/p&gt;

&lt;p&gt;In this section, we will learn how to train linear regression models on sklearn. Returning to the previous problem, if we add information about distance to city center:&lt;/p&gt;

\[\mathbf{x}_2 = [20, 18, 17, 16, 15, 14, 12, 10, 8, 7, 5, 2, 1]\]

&lt;p&gt;then the problem becomes multivariate regression. The process of building and training the model includes the steps:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Data collection&lt;/li&gt;
  &lt;li&gt;Data cleaning&lt;/li&gt;
  &lt;li&gt;Feature selection&lt;/li&gt;
  &lt;li&gt;Data normalization&lt;/li&gt;
  &lt;li&gt;Train/test split&lt;/li&gt;
  &lt;li&gt;Model training and evaluation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this problem, we focus on step 6 to understand how to train the model.&lt;/p&gt;

&lt;div id=&quot;sklearn-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Sklearn Linear Regression Example&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;!-- Code example --&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;pre style=&quot;background: #f8f9fa; padding: 15px; border-radius: 5px; overflow-x: auto; font-size: 12px;&quot;&gt;&lt;code id=&quot;sklearn-code&quot;&gt;import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score
import matplotlib.pyplot as plt

# Sample data: house prices
# Features: [area, distance_to_center]
X = np.array([
    [50, 20], [60, 18], [70, 17], [80, 16], [90, 15],
    [100, 14], [110, 12], [120, 10], [130, 8], [140, 7],
    [150, 5], [160, 2], [170, 1]
])

# Target: prices (in thousands)
y = np.array([150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510])

# Split data
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.3, random_state=42
)

# Create and train model
model = LinearRegression()
model.fit(X_train, y_train)

# Make predictions
y_pred = model.predict(X_test)

# Evaluate model
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)

print(f&quot;Coefficients: {model.coef_}&quot;)
print(f&quot;Intercept: {model.intercept_}&quot;)
print(f&quot;MSE: {mse:.2f}&quot;)
print(f&quot;R²: {r2:.3f}&quot;)
&lt;/code&gt;&lt;/pre&gt;
        &lt;/div&gt;
        
        &lt;!-- Interactive results --&gt;
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Model Results&lt;/h5&gt;
                
                &lt;button id=&quot;run-sklearn&quot; style=&quot;width: 100%; padding: 10px; background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 15px;&quot;&gt;Run Sklearn Example&lt;/button&gt;
                
                &lt;div id=&quot;sklearn-results&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Model Parameters:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Area coeff: &lt;span id=&quot;area-coeff&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Distance coeff: &lt;span id=&quot;distance-coeff&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Intercept: &lt;span id=&quot;sklearn-intercept&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;&lt;strong&gt;Performance:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;MSE: &lt;span id=&quot;sklearn-mse&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;R²: &lt;span id=&quot;sklearn-r2&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-top: 15px;&quot;&gt;
                    &lt;h6 style=&quot;margin-bottom: 10px; color: #444;&quot;&gt;Prediction Calculator&lt;/h6&gt;
                    &lt;div style=&quot;margin-bottom: 10px;&quot;&gt;
                        &lt;label style=&quot;display: block; margin-bottom: 5px;&quot;&gt;Area (m²):&lt;/label&gt;
                        &lt;input type=&quot;number&quot; id=&quot;pred-area&quot; value=&quot;100&quot; min=&quot;50&quot; max=&quot;200&quot; style=&quot;width: 100%; padding: 5px; border: 1px solid #ddd; border-radius: 3px;&quot; /&gt;
                    &lt;/div&gt;
                    &lt;div style=&quot;margin-bottom: 10px;&quot;&gt;
                        &lt;label style=&quot;display: block; margin-bottom: 5px;&quot;&gt;Distance to center (km):&lt;/label&gt;
                        &lt;input type=&quot;number&quot; id=&quot;pred-distance&quot; value=&quot;10&quot; min=&quot;1&quot; max=&quot;20&quot; style=&quot;width: 100%; padding: 5px; border: 1px solid #ddd; border-radius: 3px;&quot; /&gt;
                    &lt;/div&gt;
                    &lt;button id=&quot;make-prediction&quot; style=&quot;width: 100%; padding: 8px; background: #17a2b8; color: white; border: none; border-radius: 3px; cursor: pointer;&quot;&gt;Predict Price&lt;/button&gt;
                    &lt;div id=&quot;prediction-result&quot; style=&quot;margin-top: 10px; padding: 10px; background: #e9ecef; border-radius: 3px; text-align: center; font-weight: bold;&quot;&gt;
                        Predicted Price: --
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;key-insights&quot;&gt;Key Insights&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Theoretical Foundation&lt;/strong&gt;: Maximum likelihood estimation provides a solid theoretical foundation for why we minimize squared errors in linear regression.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Gaussian Assumptions&lt;/strong&gt;: The effectiveness of linear regression relies on the Gauss-Markov assumptions, particularly that errors are normally distributed.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Best Linear Unbiased Estimator&lt;/strong&gt;: Under the right conditions, OLS provides the BLUE - the most efficient unbiased linear estimator.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Practical Implementation&lt;/strong&gt;: Modern tools like sklearn make it easy to implement these theoretical concepts in practice.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Model Evaluation&lt;/strong&gt;: Understanding the statistical foundation helps in proper model evaluation using metrics like R², confidence intervals, and p-values.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;script&gt;
// MLE Visualization
class MLEVisualization {
    constructor() {
        this.canvas = document.getElementById(&apos;mleCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        // Parameters
        this.trueSlope = 1.0;
        this.trueIntercept = 0.0;
        this.noiseLevel = 0.5;
        this.dataPoints = [];
        
        this.setupControls();
        this.generateData();
        this.draw();
    }
    
    setupControls() {
        const noiseSlider = document.getElementById(&apos;noise-slider&apos;);
        const slopeSlider = document.getElementById(&apos;slope-slider&apos;);
        const interceptSlider = document.getElementById(&apos;intercept-slider&apos;);
        const generateBtn = document.getElementById(&apos;generate-data&apos;);
        
        noiseSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.noiseLevel = parseFloat(e.target.value);
            document.getElementById(&apos;noise-value&apos;).textContent = this.noiseLevel.toFixed(1);
            this.generateData();
            this.draw();
        });
        
        slopeSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.trueSlope = parseFloat(e.target.value);
            document.getElementById(&apos;true-slope-value&apos;).textContent = this.trueSlope.toFixed(1);
            this.generateData();
            this.draw();
        });
        
        interceptSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.trueIntercept = parseFloat(e.target.value);
            document.getElementById(&apos;true-intercept-value&apos;).textContent = this.trueIntercept.toFixed(1);
            this.generateData();
            this.draw();
        });
        
        generateBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.generateData();
            this.draw();
        });
    }
    
    generateData() {
        this.dataPoints = [];
        const n = 20;
        
        for (let i = 0; i &lt; n; i++) {
            const x = (i / (n - 1)) * 4 - 2; // x from -2 to 2
            const trueY = this.trueSlope * x + this.trueIntercept;
            const noise = (Math.random() - 0.5) * 2 * this.noiseLevel;
            const y = trueY + noise;
            
            this.dataPoints.push({ x, y, trueY });
        }
    }
    
    calculateMLE() {
        const n = this.dataPoints.length;
        let sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0;
        
        for (const point of this.dataPoints) {
            sumX += point.x;
            sumY += point.y;
            sumXY += point.x * point.y;
            sumX2 += point.x * point.x;
        }
        
        const slope = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);
        const intercept = (sumY - slope * sumX) / n;
        
        // Calculate log-likelihood
        let logLikelihood = 0;
        for (const point of this.dataPoints) {
            const predicted = slope * point.x + intercept;
            const error = point.y - predicted;
            logLikelihood -= 0.5 * Math.log(2 * Math.PI * this.noiseLevel * this.noiseLevel);
            logLikelihood -= (error * error) / (2 * this.noiseLevel * this.noiseLevel);
        }
        
        return { slope, intercept, logLikelihood };
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        const mle = this.calculateMLE();
        
        // Update display
        document.getElementById(&apos;mle-slope&apos;).textContent = mle.slope.toFixed(3);
        document.getElementById(&apos;mle-intercept&apos;).textContent = mle.intercept.toFixed(3);
        document.getElementById(&apos;log-likelihood&apos;).textContent = mle.logLikelihood.toFixed(2);
        
        // Transform coordinates
        const transform = (x, y) =&gt; ({
            x: (x + 2.5) * this.width / 5,
            y: this.height - (y + 2.5) * this.height / 5
        });
        
        // Draw axes
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        this.ctx.beginPath();
        this.ctx.moveTo(0, this.height / 2);
        this.ctx.lineTo(this.width, this.height / 2);
        this.ctx.moveTo(this.width / 2, 0);
        this.ctx.lineTo(this.width / 2, this.height);
        this.ctx.stroke();
        
        // Draw fitted line
        this.ctx.strokeStyle = &apos;#ff4444&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        const start = transform(-2, mle.slope * (-2) + mle.intercept);
        const end = transform(2, mle.slope * 2 + mle.intercept);
        this.ctx.moveTo(start.x, start.y);
        this.ctx.lineTo(end.x, end.y);
        this.ctx.stroke();
        
        // Draw data points and error distributions
        for (const point of this.dataPoints) {
            const pos = transform(point.x, point.y);
            
            // Draw Gaussian error distribution
            const predicted = mle.slope * point.x + mle.intercept;
            const errorCenter = transform(point.x, predicted);
            
            this.ctx.strokeStyle = &apos;#cccccc&apos;;
            this.ctx.lineWidth = 1;
            this.ctx.beginPath();
            for (let i = 0; i &lt;= 20; i++) {
                const t = i / 20;
                const gaussY = predicted + (t - 0.5) * 4 * this.noiseLevel;
                const gaussVal = Math.exp(-0.5 * Math.pow((gaussY - predicted) / this.noiseLevel, 2));
                const gaussPos = transform(point.x + gaussVal * 0.3, gaussY);
                
                if (i === 0) {
                    this.ctx.moveTo(gaussPos.x, gaussPos.y);
                } else {
                    this.ctx.lineTo(gaussPos.x, gaussPos.y);
                }
            }
            this.ctx.stroke();
            
            // Draw data point
            this.ctx.fillStyle = &apos;#4444ff&apos;;
            this.ctx.beginPath();
            this.ctx.arc(pos.x, pos.y, 4, 0, 2 * Math.PI);
            this.ctx.fill();
            
            // Draw error line
            this.ctx.strokeStyle = &apos;#888&apos;;
            this.ctx.lineWidth = 1;
            this.ctx.beginPath();
            this.ctx.moveTo(pos.x, pos.y);
            this.ctx.lineTo(errorCenter.x, errorCenter.y);
            this.ctx.stroke();
        }
    }
}

// Sklearn Demo
class SklearnDemo {
    constructor() {
        this.setupControls();
        this.model = null;
        this.data = this.generateSampleData();
    }
    
    generateSampleData() {
        return {
            X: [
                [50, 20], [60, 18], [70, 17], [80, 16], [90, 15],
                [100, 14], [110, 12], [120, 10], [130, 8], [140, 7],
                [150, 5], [160, 2], [170, 1]
            ],
            y: [150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510]
        };
    }
    
    setupControls() {
        const runBtn = document.getElementById(&apos;run-sklearn&apos;);
        const predBtn = document.getElementById(&apos;make-prediction&apos;);
        
        runBtn.addEventListener(&apos;click&apos;, () =&gt; this.runSklearnExample());
        predBtn.addEventListener(&apos;click&apos;, () =&gt; this.makePrediction());
    }
    
    runSklearnExample() {
        // Simulate sklearn linear regression
        const { X, y } = this.data;
        
        // Calculate means
        const meanX1 = X.reduce((sum, row) =&gt; sum + row[0], 0) / X.length;
        const meanX2 = X.reduce((sum, row) =&gt; sum + row[1], 0) / X.length;
        const meanY = y.reduce((sum, val) =&gt; sum + val, 0) / y.length;
        
        // Calculate coefficients using normal equation
        let sumX1X1 = 0, sumX2X2 = 0, sumX1X2 = 0;
        let sumX1Y = 0, sumX2Y = 0;
        
        for (let i = 0; i &lt; X.length; i++) {
            const x1 = X[i][0] - meanX1;
            const x2 = X[i][1] - meanX2;
            const yVal = y[i] - meanY;
            
            sumX1X1 += x1 * x1;
            sumX2X2 += x2 * x2;
            sumX1X2 += x1 * x2;
            sumX1Y += x1 * yVal;
            sumX2Y += x2 * yVal;
        }
        
        // Solve 2x2 system
        const det = sumX1X1 * sumX2X2 - sumX1X2 * sumX1X2;
        const coeff1 = (sumX2X2 * sumX1Y - sumX1X2 * sumX2Y) / det;
        const coeff2 = (sumX1X1 * sumX2Y - sumX1X2 * sumX1Y) / det;
        const intercept = meanY - coeff1 * meanX1 - coeff2 * meanX2;
        
        // Calculate MSE and R²
        let mse = 0, tss = 0;
        for (let i = 0; i &lt; X.length; i++) {
            const predicted = coeff1 * X[i][0] + coeff2 * X[i][1] + intercept;
            const error = y[i] - predicted;
            mse += error * error;
            tss += (y[i] - meanY) * (y[i] - meanY);
        }
        mse /= X.length;
        const r2 = 1 - (mse * X.length) / tss;
        
        this.model = { coeff1, coeff2, intercept };
        
        // Update display
        document.getElementById(&apos;area-coeff&apos;).textContent = coeff1.toFixed(3);
        document.getElementById(&apos;distance-coeff&apos;).textContent = coeff2.toFixed(3);
        document.getElementById(&apos;sklearn-intercept&apos;).textContent = intercept.toFixed(3);
        document.getElementById(&apos;sklearn-mse&apos;).textContent = mse.toFixed(2);
        document.getElementById(&apos;sklearn-r2&apos;).textContent = r2.toFixed(3);
    }
    
    makePrediction() {
        if (!this.model) {
            alert(&apos;Please run the sklearn example first!&apos;);
            return;
        }
        
        const area = parseFloat(document.getElementById(&apos;pred-area&apos;).value);
        const distance = parseFloat(document.getElementById(&apos;pred-distance&apos;).value);
        
        const prediction = this.model.coeff1 * area + this.model.coeff2 * distance + this.model.intercept;
        
        document.getElementById(&apos;prediction-result&apos;).innerHTML = 
            `Predicted Price: &lt;strong&gt;$${prediction.toFixed(0)}k&lt;/strong&gt;`;
    }
}

// Initialize when DOM is loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    new MLEVisualization();
    new SklearnDemo();
});
&lt;/script&gt;

&lt;style&gt;
#mle-demo canvas {
    border-radius: 5px;
}

#sklearn-demo pre {
    max-height: 400px;
    overflow-y: auto;
}

.demo-container {
    margin: 20px 0;
}

input[type=&quot;range&quot;] {
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    background: #ddd;
    outline: none;
    border-radius: 5px;
}

input[type=&quot;range&quot;]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
}

input[type=&quot;range&quot;]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
    border: none;
}
&lt;/style&gt;

</content>
 </entry>
 
 <entry>
   <title>05-02-02 Geometric Programming</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_02_02_Geometric_Programming/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_02_02_Geometric_Programming</id>
   <content type="html">&lt;p&gt;When chip designers size transistors on a microprocessor—trading off area, power dissipation, and signal delay—every physical law is a product of powers like \(c\, w_1^{a_1} w_2^{a_2}\). Written directly in transistor widths \(w_i &amp;gt; 0\), the problem looks wildly nonconvex. Yet one logarithmic change of variables flips the entire circuit-sizing problem into a smooth convex program solvable to global optimality in milliseconds: that is the magic of Geometric Programming (GP).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-monomials-posynomials-and-log-space-convexity&quot;&gt;Key ideas: Monomials, Posynomials, and Log-Space Convexity&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Monomials vs. Posynomials&lt;/strong&gt;: On the strictly positive orthant \(\mathbb{R}^n_{++}\), a &lt;em&gt;monomial&lt;/em&gt; is a single term \(f(x) = c x_1^{a_1}\cdots x_n^{a_n}\) with \(c &amp;gt; 0\) and arbitrary real exponents \(a_i \in \mathbb{R}\). A &lt;em&gt;posynomial&lt;/em&gt; is any finite sum of monomials \(f(x) = \sum_{k=1}^K c_k x_1^{a_{1k}}\cdots x_n^{a_{nk}}\) (with all \(c_k &amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;GP Standard-Form Rules&lt;/strong&gt;: A Geometric Program minimizes a posynomial \(f_0(x)\) subject to posynomial upper bounds \(f_i(x) \le 1\) and &lt;em&gt;monomial&lt;/em&gt; equalities \(h_j(x) = 1\). (Equality constraints must be monomials—not sums—so that taking logs turns them into affine equalities!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Exponential Change of Variables&lt;/strong&gt;: Setting \(x_i = e^{y_i}\) (so \(y_i = \ln x_i \in \mathbb{R}\)) and applying \(\ln(\cdot)\) to the objective and constraints turns every monomial \(c \prod x_i^{a_i}\) into an affine function \(a^T y + \ln c\), and every posynomial into a convex &lt;em&gt;log-sum-exp&lt;/em&gt; function \(\ln\bigl(\sum_k \exp(a_k^T y + b_k)\bigr)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why GP Matters Beyond Circuits&lt;/strong&gt;: Beyond VLSI gate sizing, GPs model wireless power control, aircraft wing design, structural truss optimization, and maximum-likelihood estimation for logistic/multinomial models.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-designing-a-minimum-surface-area-box-via-gp&quot;&gt;Worked example: Designing a Minimum-Surface-Area Box via GP&lt;/h3&gt;

&lt;p&gt;Design a closed rectangular box of dimensions \(w, h, d &amp;gt; 0\) with volume \(whd = 8\) that minimizes total surface area \(2wh + 2wd + 2hd\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Recognize the Geometric Program structure&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Objective \(f_0(w, h, d) = 2wh + 2wd + 2hd\) is a &lt;strong&gt;posynomial&lt;/strong&gt; (sum of three monomials with positive coefficients).&lt;/li&gt;
      &lt;li&gt;Equality constraint \(\frac{1}{8}whd = 1\) is a &lt;strong&gt;monomial equality&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Transform to convex form via \(w = e^{y_1},\; h = e^{y_2},\; d = e^{y_3}\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Monomial equality becomes \(y_1 + y_2 + y_3 - \ln 8 = 0\) (an affine equality!).&lt;/li&gt;
      &lt;li&gt;Taking \(\ln\) of the objective gives the convex log-sum-exp problem:
\(\min_{y \in \mathbb{R}^3} \quad \ln\!\left(2e^{y_1 + y_2} + 2e^{y_1 + y_3} + 2e^{y_2 + y_3}\right) \quad \text{s.t.} \quad y_1 + y_2 + y_3 = \ln 8.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the convex problem using symmetry / KKT&lt;/strong&gt;: Differentiating the Lagrangian \(\ln(S) + \nu(y_1 + y_2 + y_3 - \ln 8)\) with respect to each \(y_i\) gives equal partial derivatives when all three exponentials match: \(y_1 = y_2 = y_3\).
    &lt;ul&gt;
      &lt;li&gt;From \(3y_1 = \ln 8 = 3\ln 2\), we get \(y_1^\star = y_2^\star = y_3^\star = \ln 2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Transform back to physical dimensions&lt;/strong&gt;:
\(w^\star = h^\star = d^\star = e^{\ln 2} = 2.\)
Check volume: \(2 \cdot 2 \cdot 2 = 8\). Minimum surface area: \(2(4) + 2(4) + 2(4) = 24\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we will see a class of problems that appear non-convex when looking at the objective function and constraint functions, but can be transformed into convex form through several techniques.&lt;/p&gt;

&lt;p&gt;First, we need some definitions:&lt;/p&gt;

&lt;h2 id=&quot;1-monomials-and-posynomials&quot;&gt;1. Monomials and Posynomials&lt;/h2&gt;

&lt;p&gt;A function \(f: \mathbb{R}^n \to \mathbb{R}\) with domain \(\text{dom } f = \mathbb{R}^n_{++}\) (all elements are positive) has the form:&lt;/p&gt;

\[f(x) = c x_1^{a_1} x_2^{a_2} \ldots x_n^{a_n} \quad \quad (24)\]

&lt;p&gt;where \(c &amp;gt; 0\) and \(a_i \in \mathbb{R}\), is called a &lt;strong&gt;monomial function&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A sum of monomials:&lt;/p&gt;

\[f(x) = \sum_{k=1}^K c_k x_1^{a_{1k}} x_2^{a_{2k}} \ldots x_n^{a_{nk}} \quad \quad (25)\]

&lt;p&gt;where \(c_k &amp;gt; 0\), is called a &lt;strong&gt;posynomial function&lt;/strong&gt;, or simply a &lt;strong&gt;posynomial&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;2-geometric-programming&quot;&gt;2. Geometric Programming&lt;/h2&gt;

&lt;p&gt;An optimization problem of the form:&lt;/p&gt;

\[\begin{align}
x &amp;amp;= \arg\min_x f_0(x) \\
\text{subject to: } &amp;amp;f_i(x) \leq 1, \quad i = 1, 2, \ldots, m \quad \quad (26) \\
&amp;amp;h_j(x) = 1, \quad j = 1, 2, \ldots, p
\end{align}\]

&lt;p&gt;where \(f_0, f_1, \ldots, f_m\) are posynomials and \(h_1, \ldots, h_p\) are monomials, is called &lt;strong&gt;Geometric Programming (GP)&lt;/strong&gt;. The condition \(x \succ 0\) is implicit.&lt;/p&gt;

&lt;p&gt;Note that if \(f\) is a posynomial and \(h\) is a monomial, then \(f/h\) is a posynomial.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
(x, y, z) &amp;amp;= \arg\min_{x,y,z} x/y \\
\text{subject to: } &amp;amp;1 \leq x \leq 2 \\
&amp;amp;x^3 + 2y/z \leq \sqrt{y} \\
&amp;amp;x/y = z
\end{align}\]

&lt;p&gt;This can be rewritten in GP form:&lt;/p&gt;

\[\begin{align}
(x, y, z) &amp;amp;= \arg\min_{x,y,z} xy^{-1} \\
\text{subject to: } &amp;amp;x^{-1} \leq 1 \\
&amp;amp;(1/2)x \leq 1 \\
&amp;amp;x^3 y^{-1/2} + 2y^{1/2}z^{-1} \leq 1 \\
&amp;amp;xy^{-1}z^{-1} = 1
\end{align}\]

&lt;p&gt;This problem is clearly nonconvex since both the objective function and constraint functions are not convex.&lt;/p&gt;

&lt;h2 id=&quot;3-transforming-gp-to-convex-form&quot;&gt;3. Transforming GP to Convex Form&lt;/h2&gt;

&lt;p&gt;GP can be transformed to convex form as follows:&lt;/p&gt;

&lt;p&gt;Let \(y_i = \log(x_i)\), i.e., \(x_i = \exp(y_i)\). If \(f\) is a monomial function of \(x\), then:&lt;/p&gt;

\[f(x) = c(\exp(y_1))^{a_1} \ldots (\exp(y_n))^{a_n} = \exp(a^T y + b)\]

&lt;p&gt;where \(b = \log(c)\). Now, the function \(g(y) = \exp(a^T y + b)\) is a convex function in \(y\). (The reader can prove by definition that the composition of two convex functions is a convex function. In this case, both the \(\exp\) function and the affine function are convex functions.)&lt;/p&gt;

&lt;p&gt;Similarly, the posynomial in equation (25) can be written as:&lt;/p&gt;

\[f(x) = \sum_{k=1}^K \exp(a_k^T y + b_k)\]

&lt;p&gt;where \(a_k = [a_{1k}, \ldots, a_{nk}]^T\) and \(b_k = \log(c_k)\). Now, the posynomial has been written as a sum of \(\exp\) functions of affine functions (and is therefore a convex function, recall that the sum of convex functions is convex).&lt;/p&gt;

&lt;p&gt;The GP problem (26) is rewritten as:&lt;/p&gt;

\[\begin{align}
y &amp;amp;= \arg\min_y \sum_{k=1}^{K_0} \exp(a_{0k}^T y + b_{0k}) \\
\text{subject to: } &amp;amp;\sum_{k=1}^{K_i} \exp(a_{ik}^T y + b_{ik}) \leq 1, \quad i = 1, \ldots, m \quad \quad (27) \\
&amp;amp;\exp(g_j^T y + h_j) = 1, \quad j = 1, \ldots, p
\end{align}\]

&lt;p&gt;where \(a_{ik} \in \mathbb{R}^n\), \(i = 1, \ldots, p\) and \(g_i \in \mathbb{R}^n\).&lt;/p&gt;

&lt;p&gt;With the observation that the function \(\log \sum_{i=1}^m \exp(g_i(x))\) is a convex function if \(g_i\) are convex functions (we omit the proof), we can rewrite problem (27) in convex form by taking the \(\log\) of the functions as follows:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GP in convex form:&lt;/strong&gt;&lt;/p&gt;

\[\begin{align}
\text{minimize}_y \quad &amp;amp;\tilde{f}_0(y) = \log\left(\sum_{k=1}^{K_0} \exp(a_{0k}^T y + b_{0k})\right) \\
\text{subject to: } &amp;amp;\tilde{f}_i(y) = \log\left(\sum_{k=1}^{K_i} \exp(a_{ik}^T y + b_{ik})\right) \leq 0, \quad i = 1, \ldots, m \quad \quad (28) \\
&amp;amp;\tilde{h}_j(y) = g_j^T y + h_j = 0, \quad j = 1, \ldots, p
\end{align}\]

&lt;p&gt;Now we can say that GP is equivalent to a convex optimization problem because the objective function and inequality constraint functions in (28) are all convex functions, while the equality constraints are in affine form. This form is often called a &lt;strong&gt;geometric program in convex form&lt;/strong&gt; (to distinguish it from the original definition of GP).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-02-01 Linear Least-Squares Problems</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_02_01_Least_Square/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_02_01_Least_Square</id>
   <content type="html">&lt;p&gt;In 1801, the dwarf planet Ceres vanished behind the Sun after just 41 days of noisy telescopic sightings. A 24-year-old Carl Friedrich Gauss predicted exactly where it would reappear—using a brand-new idea he called the &lt;em&gt;method of least squares&lt;/em&gt;. Over two centuries later, minimizing \(\|Ax - b\|_2^2\) remains the single most widely solved convex optimization problem in science, statistics, and signal processing.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-and-algebra-of-linear-least-squares&quot;&gt;Key ideas: Geometry and Algebra of Linear Least Squares&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Convexity Without Constraints&lt;/strong&gt;: Expanding \(f(x) = \|Ax - b\|_2^2 = x^T(A^T A)x - 2b^T A x + b^T b\) shows its Hessian is \(2A^T A \succeq 0\). Every least-squares problem is an unconstrained convex QP, and it is strictly convex whenever \(A\) has full column rank (\(\operatorname{null}(A) = \{0\}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Normal Equations and Orthogonal Projection&lt;/strong&gt;: Setting \(\nabla f(x) = 2A^T(Ax - b) = 0\) yields the &lt;em&gt;normal equations&lt;/em&gt; \(A^T A x^\star = A^T b\). Geometrically, the residual \(r^\star = b - Ax^\star\) is orthogonal to every column of \(A\), meaning \(\hat{b} = Ax^\star\) is the orthogonal projection of \(b\) onto the column space \(\operatorname{col}(A)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical Stability — QR and SVD Over Explicit Inversion&lt;/strong&gt;: Forming \(A^T A\) squares the condition number (\(\kappa(A^T A) = \kappa(A)^2\)), which can wipe out precision when columns are nearly collinear. Production solvers instead factor \(A = QR\) (solving \(Rx^\star = Q^T b\)) or use the SVD \(A = U\Sigma V^T\) to compute the minimum-norm pseudoinverse solution \(x^\star = A^+ b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Weighted and Regularized Extensions&lt;/strong&gt;: Replacing \(\|Ax - b\|_2^2\) with \(\|W^{1/2}(Ax - b)\|_2^2\) handles heteroscedastic noise, while adding \(\lambda\|x\|_2^2\) (Ridge / Tikhonov regularization) replaces \(A^T A\) with \(A^T A + \lambda I \succ 0\), guaranteeing invertibility even when \(A\) is rank-deficient.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-fitting-a-line-by-normal-equations-and-verifying-orthogonality&quot;&gt;Worked example: Fitting a Line by Normal Equations and Verifying Orthogonality&lt;/h3&gt;

&lt;p&gt;Fit a line \(y = x_1 + x_2 t\) to three data points: \((t_1, y_1) = (0, 1)\), \((t_2, y_2) = (1, 2)\), and \((t_3, y_3) = (2, 2)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the design matrix \(A\) and target vector \(b\)&lt;/strong&gt;:
\(A = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}, \qquad b = \begin{bmatrix} 1 \\ 2 \\ 2 \end{bmatrix}, \qquad x = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(A^T A\) and \(A^T b\)&lt;/strong&gt;:
\(A^T A = \begin{bmatrix} 3 &amp;amp; 3 \\ 3 &amp;amp; 5 \end{bmatrix}, \qquad A^T b = \begin{bmatrix} 1 + 2 + 2 \\ 0(1) + 1(2) + 2(2) \end{bmatrix} = \begin{bmatrix} 5 \\ 6 \end{bmatrix}.\)
Notice \(\det(A^T A) = 3(5) - 3^2 = 6 &amp;gt; 0\), so \(A^T A\) is strictly positive definite.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the \(2 \times 2\) normal equations&lt;/strong&gt;:
\(x^\star = (A^T A)^{-1} A^T b = \frac{1}{6}\begin{bmatrix} 5 &amp;amp; -3 \\ -3 &amp;amp; 3 \end{bmatrix}\begin{bmatrix} 5 \\ 6 \end{bmatrix} = \frac{1}{6}\begin{bmatrix} 25 - 18 \\ -15 + 18 \end{bmatrix} = \begin{bmatrix} 7/6 \\ 1/2 \end{bmatrix}.\)
Thus the best-fit line is \(y = \frac{7}{6} + \frac{1}{2}t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify residual orthogonality&lt;/strong&gt;: Predictions are \(\hat{b} = Ax^\star = (\tfrac{7}{6}, \tfrac{10}{6}, \tfrac{13}{6})^T\), so the residual is
\(r^\star = b - \hat{b} = \left(-\frac{1}{6},\; +\frac{2}{6},\; -\frac{1}{6}\right)^T.\)
Check \(A^T r^\star\): sum of entries is \((-1 + 2 - 1)/6 = 0\), and dot product with \((0, 1, 2)^T\) is \((0 + 2 - 2)/6 = 0\)! The minimum squared error is \(\|r^\star\|_2^2 = \frac{1 + 4 + 1}{36} = \frac{1}{6}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;linear-least-squares-problems&quot;&gt;Linear Least-Squares Problems&lt;/h2&gt;

&lt;p&gt;A linear least-squares problem is an optimization problem without constraints where we minimize the sum of squared errors:&lt;/p&gt;

\[\text{minimize}_{x} \quad f_0(x) = \|Ax - b\|_2^2 = \sum_{i=1}^{k} (a_i^T x - b_i)^2\]

&lt;p&gt;&lt;strong&gt;where:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(A \in \mathbb{R}^{k \times n}\) is a matrix with \(k \geq n\)&lt;/li&gt;
  &lt;li&gt;\(a_i^T\) are the rows of \(A\)&lt;/li&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) is the variable we want to find&lt;/li&gt;
  &lt;li&gt;\(b \in \mathbb{R}^k\) is the target vector&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Find \(x\) to minimize the sum of squared residuals.&lt;/p&gt;

&lt;h3 id=&quot;example-linear-regression-for-single-variable&quot;&gt;Example: Linear Regression for single variable&lt;/h3&gt;

&lt;p&gt;Finding the best-fit line \(y = mx + c\) through data points. We minimize the sum of squared vertical distances from points to the line.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Find \(m, c\).&lt;/p&gt;

&lt;div id=&quot;linear-regression-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Interactive Linear Regression Demonstration&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;!-- Canvas for visualization --&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;regressionCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white; cursor: crosshair;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Instructions:&lt;/strong&gt; Click on the canvas to add data points. The red line shows the best-fit line.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;!-- Controls and information --&gt;
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Regression Parameters&lt;/h5&gt;
                &lt;div id=&quot;regression-params&quot; style=&quot;font-family: monospace; font-size: 14px; line-height: 1.6;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Slope (m):&lt;/strong&gt; &lt;span id=&quot;slope-value&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;&lt;strong&gt;Intercept (c):&lt;/strong&gt; &lt;span id=&quot;intercept-value&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;&lt;strong&gt;R² Score:&lt;/strong&gt; &lt;span id=&quot;r2-value&quot;&gt;N/A&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;&lt;strong&gt;MSE:&lt;/strong&gt; &lt;span id=&quot;mse-value&quot;&gt;N/A&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-top: 15px;&quot;&gt;
                    &lt;h5 style=&quot;color: #444;&quot;&gt;Equation&lt;/h5&gt;
                    &lt;div id=&quot;equation&quot; style=&quot;font-family: monospace; font-size: 16px; background: #f0f0f0; padding: 8px; border-radius: 4px;&quot;&gt;
                        y = 0.000x + 0.000
                    &lt;/div&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-top: 15px;&quot;&gt;
                    &lt;button onclick=&quot;clearPoints()&quot; style=&quot;background: #ff6b6b; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; margin-right: 10px;&quot;&gt;Clear Points&lt;/button&gt;
                    &lt;button onclick=&quot;addRandomPoints()&quot; style=&quot;background: #4ecdc4; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;&quot;&gt;Add Random Points&lt;/button&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-top: 15px;&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Mathematical Formulation&lt;/h5&gt;
                &lt;div style=&quot;font-size: 13px; line-height: 1.5;&quot;&gt;
                    &lt;p&gt;&lt;strong&gt;Objective:&lt;/strong&gt; Minimize sum of squared residuals&lt;/p&gt;
                    &lt;div style=&quot;background: #f8f8f8; padding: 8px; border-radius: 4px; font-family: monospace;&quot;&gt;
                        S(m,c) = Σ(yᵢ - mxᵢ - c)²
                    &lt;/div&gt;
                    &lt;p style=&quot;margin-top: 10px;&quot;&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
                    &lt;div style=&quot;background: #f8f8f8; padding: 8px; border-radius: 4px; font-family: monospace; font-size: 11px;&quot;&gt;
                        m = Σ(xᵢ-x̄)(yᵢ-ȳ) / Σ(xᵢ-x̄)²&lt;br /&gt;
                        c = ȳ - mx̄
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
// Linear Regression Interactive Demo
class LinearRegressionDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;regressionCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.points = [];
        this.slope = 0;
        this.intercept = 0;
        
        // Set up canvas
        this.canvas.addEventListener(&apos;click&apos;, (e) =&gt; this.addPoint(e));
        
        // Initialize with some sample points
        this.addRandomPoints();
        this.draw();
    }
    
    addPoint(event) {
        const rect = this.canvas.getBoundingClientRect();
        const x = event.clientX - rect.left;
        const y = event.clientY - rect.top;
        
        // Convert canvas coordinates to data coordinates
        const dataX = (x / this.canvas.width) * 10;
        const dataY = ((this.canvas.height - y) / this.canvas.height) * 10;
        
        this.points.push({x: dataX, y: dataY});
        this.calculateRegression();
        this.draw();
        this.updateDisplay();
    }
    
    addRandomPoints() {
        // Add some sample points with a trend
        const baseSlope = 0.8;
        const baseIntercept = 2;
        
        for (let i = 0; i &lt; 8; i++) {
            const x = Math.random() * 8 + 1;
            const y = baseSlope * x + baseIntercept + (Math.random() - 0.5) * 2;
            this.points.push({x: x, y: Math.max(0, Math.min(10, y))});
        }
        
        this.calculateRegression();
        this.draw();
        this.updateDisplay();
    }
    
    clearPoints() {
        this.points = [];
        this.slope = 0;
        this.intercept = 0;
        this.draw();
        this.updateDisplay();
    }
    
    calculateRegression() {
        if (this.points.length &lt; 2) {
            this.slope = 0;
            this.intercept = 0;
            return;
        }
        
        const n = this.points.length;
        const sumX = this.points.reduce((sum, p) =&gt; sum + p.x, 0);
        const sumY = this.points.reduce((sum, p) =&gt; sum + p.y, 0);
        const sumXY = this.points.reduce((sum, p) =&gt; sum + p.x * p.y, 0);
        const sumXX = this.points.reduce((sum, p) =&gt; sum + p.x * p.x, 0);
        
        const meanX = sumX / n;
        const meanY = sumY / n;
        
        const numerator = sumXY - n * meanX * meanY;
        const denominator = sumXX - n * meanX * meanX;
        
        if (Math.abs(denominator) &lt; 1e-10) {
            this.slope = 0;
            this.intercept = meanY;
        } else {
            this.slope = numerator / denominator;
            this.intercept = meanY - this.slope * meanX;
        }
    }
    
    calculateR2() {
        if (this.points.length &lt; 2) return 0;
        
        const meanY = this.points.reduce((sum, p) =&gt; sum + p.y, 0) / this.points.length;
        let ssRes = 0;
        let ssTot = 0;
        
        for (const point of this.points) {
            const predicted = this.slope * point.x + this.intercept;
            ssRes += Math.pow(point.y - predicted, 2);
            ssTot += Math.pow(point.y - meanY, 2);
        }
        
        return ssTot === 0 ? 1 : 1 - (ssRes / ssTot);
    }
    
    calculateMSE() {
        if (this.points.length === 0) return 0;
        
        let mse = 0;
        for (const point of this.points) {
            const predicted = this.slope * point.x + this.intercept;
            mse += Math.pow(point.y - predicted, 2);
        }
        
        return mse / this.points.length;
    }
    
    draw() {
        // Clear canvas
        this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
        
        // Draw grid
        this.drawGrid();
        
        // Draw regression line
        if (this.points.length &gt;= 2) {
            this.drawRegressionLine();
        }
        
        // Draw points and residuals
        this.drawPoints();
        
        // Draw axes labels
        this.drawLabels();
    }
    
    drawGrid() {
        this.ctx.strokeStyle = &apos;#f0f0f0&apos;;
        this.ctx.lineWidth = 1;
        
        // Vertical lines
        for (let i = 0; i &lt;= 10; i++) {
            const x = (i / 10) * this.canvas.width;
            this.ctx.beginPath();
            this.ctx.moveTo(x, 0);
            this.ctx.lineTo(x, this.canvas.height);
            this.ctx.stroke();
        }
        
        // Horizontal lines
        for (let i = 0; i &lt;= 10; i++) {
            const y = (i / 10) * this.canvas.height;
            this.ctx.beginPath();
            this.ctx.moveTo(0, y);
            this.ctx.lineTo(this.canvas.width, y);
            this.ctx.stroke();
        }
    }
    
    drawRegressionLine() {
        this.ctx.strokeStyle = &apos;#ff4757&apos;;
        this.ctx.lineWidth = 2;
        
        const x1 = 0;
        const y1 = this.intercept;
        const x2 = 10;
        const y2 = this.slope * x2 + this.intercept;
        
        const canvasX1 = (x1 / 10) * this.canvas.width;
        const canvasY1 = this.canvas.height - (y1 / 10) * this.canvas.height;
        const canvasX2 = (x2 / 10) * this.canvas.width;
        const canvasY2 = this.canvas.height - (y2 / 10) * this.canvas.height;
        
        this.ctx.beginPath();
        this.ctx.moveTo(canvasX1, canvasY1);
        this.ctx.lineTo(canvasX2, canvasY2);
        this.ctx.stroke();
    }
    
    drawPoints() {
        for (const point of this.points) {
            const canvasX = (point.x / 10) * this.canvas.width;
            const canvasY = this.canvas.height - (point.y / 10) * this.canvas.height;
            
            // Draw residual line (vertical distance to regression line)
            if (this.points.length &gt;= 2) {
                const predictedY = this.slope * point.x + this.intercept;
                const predictedCanvasY = this.canvas.height - (predictedY / 10) * this.canvas.height;
                
                this.ctx.strokeStyle = &apos;#ff6b6b&apos;;
                this.ctx.lineWidth = 1;
                this.ctx.setLineDash([2, 2]);
                this.ctx.beginPath();
                this.ctx.moveTo(canvasX, canvasY);
                this.ctx.lineTo(canvasX, predictedCanvasY);
                this.ctx.stroke();
                this.ctx.setLineDash([]);
            }
            
            // Draw point
            this.ctx.fillStyle = &apos;#2f3542&apos;;
            this.ctx.beginPath();
            this.ctx.arc(canvasX, canvasY, 4, 0, 2 * Math.PI);
            this.ctx.fill();
        }
    }
    
    drawLabels() {
        this.ctx.fillStyle = &apos;#666&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        
        // X-axis labels
        for (let i = 0; i &lt;= 10; i += 2) {
            const x = (i / 10) * this.canvas.width;
            this.ctx.fillText(i.toString(), x - 5, this.canvas.height - 5);
        }
        
        // Y-axis labels
        for (let i = 0; i &lt;= 10; i += 2) {
            const y = this.canvas.height - (i / 10) * this.canvas.height;
            this.ctx.fillText(i.toString(), 5, y + 3);
        }
    }
    
    updateDisplay() {
        document.getElementById(&apos;slope-value&apos;).textContent = this.slope.toFixed(3);
        document.getElementById(&apos;intercept-value&apos;).textContent = this.intercept.toFixed(3);
        document.getElementById(&apos;equation&apos;).textContent = `y = ${this.slope.toFixed(3)}x + ${this.intercept.toFixed(3)}`;
        
        if (this.points.length &gt;= 2) {
            document.getElementById(&apos;r2-value&apos;).textContent = this.calculateR2().toFixed(3);
            document.getElementById(&apos;mse-value&apos;).textContent = this.calculateMSE().toFixed(3);
        } else {
            document.getElementById(&apos;r2-value&apos;).textContent = &apos;N/A&apos;;
            document.getElementById(&apos;mse-value&apos;).textContent = &apos;N/A&apos;;
        }
    }
}

// Global functions for buttons
function clearPoints() {
    if (window.regressionDemo) {
        window.regressionDemo.clearPoints();
    }
}

function addRandomPoints() {
    if (window.regressionDemo) {
        window.regressionDemo.clearPoints();
        window.regressionDemo.addRandomPoints();
    }
}

// Initialize when DOM is loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    if (document.getElementById(&apos;regressionCanvas&apos;)) {
        window.regressionDemo = new LinearRegressionDemo();
    }
});

// Initialize immediately if DOM is already loaded
if (document.readyState === &apos;loading&apos;) {
    document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
        if (document.getElementById(&apos;regressionCanvas&apos;)) {
            window.regressionDemo = new LinearRegressionDemo();
        }
    });
} else {
    if (document.getElementById(&apos;regressionCanvas&apos;)) {
        window.regressionDemo = new LinearRegressionDemo();
    }
}
&lt;/script&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Given \(n\) data points \((x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n)\), find the line \(y = mx + c\) that minimizes the sum of squared vertical distances from the points to the line.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Objective Function:&lt;/strong&gt; We want to minimize
\(S(m,c) = \sum_{i=1}^{n} (y_i - mx_i - c)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; To find the minimum, we take partial derivatives and set them equal to zero.&lt;/p&gt;

&lt;p&gt;Taking the partial derivative with respect to \(c\):&lt;/p&gt;
&lt;blockquote&gt;
\[\frac{\partial S}{\partial c} = \sum_{i=1}^{n} 2(y_i - mx_i - c)(-1) = -2\sum_{i=1}^{n} (y_i - mx_i - c) = 0\]
&lt;/blockquote&gt;

&lt;p&gt;This gives us:
\(\sum_{i=1}^{n} y_i = m\sum_{i=1}^{n} x_i + nc\)&lt;/p&gt;

&lt;p&gt;Therefore:&lt;/p&gt;

&lt;blockquote&gt;
\[c = \frac{1}{n}\sum_{i=1}^{n} y_i - m\frac{1}{n}\sum_{i=1}^{n} x_i = \bar{y} - m\bar{x}\]
&lt;/blockquote&gt;

&lt;p&gt;where \(\bar{x}\) and \(\bar{y}\) are the means of \(x\) and \(y\) values.&lt;/p&gt;

&lt;p&gt;Taking the partial derivative with respect to \(m\):&lt;/p&gt;

&lt;blockquote&gt;
\[\frac{\partial S}{\partial m} = \sum_{i=1}^{n} 2(y_i - mx_i - c)(-x_i) = -2\sum_{i=1}^{n} x_i(y_i - mx_i - c) = 0\]
&lt;/blockquote&gt;

&lt;p&gt;Substituting \(c = \bar{y} - m\bar{x}\):
\(\sum_{i=1}^{n} x_i(y_i - mx_i - \bar{y} + m\bar{x}) = 0\)&lt;/p&gt;

&lt;p&gt;Rearranging:
\(\sum_{i=1}^{n} x_iy_i - m\sum_{i=1}^{n} x_i^2 - \bar{y}\sum_{i=1}^{n} x_i + m\bar{x}\sum_{i=1}^{n} x_i = 0\)&lt;/p&gt;

&lt;p&gt;Since \(\sum_{i=1}^{n} x_i = n\bar{x}\) and \(\sum_{i=1}^{n} x_iy_i - \bar{y}\sum_{i=1}^{n} x_i = \sum_{i=1}^{n} x_i(y_i - \bar{y})\):&lt;/p&gt;

&lt;blockquote&gt;
\[\sum_{i=1}^{n} x_i(y_i - \bar{y}) = m\left(\sum_{i=1}^{n} x_i^2 - n\bar{x}^2\right)\]
&lt;/blockquote&gt;

&lt;p&gt;Note that \(\sum_{i=1}^{n} x_i^2 - n\bar{x}^2 = \sum_{i=1}^{n} (x_i - \bar{x})^2\)&lt;/p&gt;

&lt;p&gt;Therefore:&lt;/p&gt;

&lt;blockquote&gt;
\[m = \frac{\sum_{i=1}^{n} x_i(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2} = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Final Result:&lt;/strong&gt; The best-fit line has parameters:&lt;/p&gt;

&lt;blockquote&gt;
\[\boxed{m = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2} \quad \text{and} \quad c = \bar{y} - m\bar{x}}\]
&lt;/blockquote&gt;

&lt;p&gt;This is the classical least-squares solution for linear regression, also known as the &lt;strong&gt;Normal Equations&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;the-optimal-solution-of-linear-regression-with-multiple-variables&quot;&gt;The Optimal Solution of Linear Regression with multiple variables&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem Statement:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Linear Regression, we aim to find a vector of coefficients \(\mathbf{w}\) that best fits a linear model to a given dataset. We have \(n\) data points, each with \(p\) features.&lt;/p&gt;

&lt;p&gt;Let \(X\) be the design matrix of size \(n \times p\), where each row represents a data point and each column represents a feature.&lt;/p&gt;

&lt;p&gt;Let \(\mathbf{y}\) be the vector of target values of size \(n \times 1\).&lt;/p&gt;

&lt;p&gt;Our linear model predicts the target values \(\hat{\mathbf{y}}\) as:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\hat{\mathbf{y}} = X\mathbf{w}\)
where \(\mathbf{w}\) is the vector of unknown coefficients of size \(p \times 1\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Objective Function (Cost Function):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The goal is to minimize the sum of squared errors (residuals) between the actual target values \(\mathbf{y}\) and the predicted values \(\hat{\mathbf{y}}\). This is known as the Ordinary Least Squares (OLS) objective function:
\(J(\mathbf{w}) = \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 = \| \mathbf{y} - X\mathbf{w} \|^2\)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; \(J(\mathbf{w})\) is the &lt;strong&gt;cost function&lt;/strong&gt; (also called loss function or objective function) that measures how well our linear model fits the data. It represents the total squared error between our predictions and the actual values. The smaller \(J(\mathbf{w})\), the better our model fits the data. Our goal is to find the optimal weights \(\mathbf{w}\) that minimize this function.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can express this in matrix form by expanding the squared Euclidean norm:
\(J(\mathbf{w}) = (\mathbf{y} - X\mathbf{w})^{\text{T}}(\mathbf{y} - X\mathbf{w})\)&lt;/p&gt;

&lt;p&gt;Expanding this expression:
\(J(\mathbf{w}) = \mathbf{y}^{\text{T}}\mathbf{y} - \mathbf{y}^{\text{T}}X\mathbf{w} - (X\mathbf{w})^{\text{T}}\mathbf{y} + (X\mathbf{w})^{\text{T}}X\mathbf{w}\)&lt;/p&gt;

&lt;p&gt;Using the property that \((AB)^{\text{T}} = B^{\text{T}}A^{\text{T}}\), we have \((X\mathbf{w})^{\text{T}} = \mathbf{w}^{\text{T}}X^{\text{T}}\).&lt;/p&gt;

&lt;p&gt;Also, since \(\mathbf{y}^{\text{T}}X\mathbf{w}\) is a scalar, its transpose is itself: \((\mathbf{y}^{\text{T}}X\mathbf{w})^{\text{T}} = \mathbf{w}^{\text{T}}X^{\text{T}}\mathbf{y}\).&lt;/p&gt;

&lt;p&gt;Thus, the two middle terms are identical:
\(J(\mathbf{w}) = \mathbf{y}^{\text{T}}\mathbf{y} - 2\mathbf{w}^{\text{T}}X^{\text{T}}\mathbf{y} + \mathbf{w}^{\text{T}}X^{\text{T}}X\mathbf{w}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Minimization \(J(\mathbf{w})\) using Calculus:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To find the optimal \(\mathbf{w}\) that minimizes \(J(\mathbf{w})\), we take the derivative of \(J(\mathbf{w})\) with respect to \(\mathbf{w}\) and set it to zero. We use the following matrix calculus rules:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
\[\frac{\partial (\mathbf{a}^{\text{T}}\mathbf{x})}{\partial \mathbf{x}} = \mathbf{a}\]
  &lt;/li&gt;
  &lt;li&gt;\(\frac{\partial (\mathbf{x}^{\text{T}}A\mathbf{x})}{\partial \mathbf{x}} = (A + A^{\text{T}})\mathbf{x}\) (If \(A\) is symmetric, this simplifies to \(2A\mathbf{x}\))&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Applying these rules to \(J(\mathbf{w})\):
\(\frac{\partial J(\mathbf{w})}{\partial \mathbf{w}} = \frac{\partial (\mathbf{y}^{\text{T}}\mathbf{y})}{\partial \mathbf{w}} - \frac{\partial (2\mathbf{w}^{\text{T}}X^{\text{T}}\mathbf{y})}{\partial \mathbf{w}} + \frac{\partial (\mathbf{w}^{\text{T}}X^{\text{T}}X\mathbf{w})}{\partial \mathbf{w}}\)&lt;/p&gt;

&lt;p&gt;Let’s evaluate each term:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\frac{\partial (\mathbf{y}^{\text{T}}\mathbf{y})}{\partial \mathbf{w}} = 0\) (since \(\mathbf{y}^{\text{T}}\mathbf{y}\) is a scalar constant with respect to \(\mathbf{w}\))&lt;/li&gt;
  &lt;li&gt;\(\frac{\partial (2\mathbf{w}^{\text{T}}X^{\text{T}}\mathbf{y})}{\partial \mathbf{w}} = 2X^{\text{T}}\mathbf{y}\) (using rule 1, with \(\mathbf{a} = X^{\text{T}}\mathbf{y}\))&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;For the third term, let \(A = X^{\text{T}}X\). Note that \(A\) is a symmetric matrix because \((X^{\text{T}}X)^{\text{T}} = X^{\text{T}}(X^{\text{T}})^{\text{T}} = X^{\text{T}}X\).&lt;/p&gt;

    &lt;p&gt;So, \(\frac{\partial (\mathbf{w}^{\text{T}}X^{\text{T}}X\mathbf{w})}{\partial \mathbf{w}} = 2X^{\text{T}}X\mathbf{w}\) (using rule 2 for a symmetric matrix \(A\))&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Combining these, the derivative is:&lt;/p&gt;

&lt;blockquote&gt;
\[\frac{\partial J(\mathbf{w})}{\partial \mathbf{w}} = 0 - 2X^{\text{T}}\mathbf{y} + 2X^{\text{T}}X\mathbf{w} = 2X^{\text{T}}X\mathbf{w} - 2X^{\text{T}}\mathbf{y}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Finding the Optimal Solution:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To find the minimum of \(J(\mathbf{w})\), we set the derivative equal to zero:&lt;/p&gt;

\[\frac{\partial J(\mathbf{w})}{\partial \mathbf{w}} = 2X^{\text{T}}X\mathbf{w} - 2X^{\text{T}}\mathbf{y} = 0\]

&lt;p&gt;Dividing by 2 and rearranging:
\(X^{\text{T}}X\mathbf{w} = X^{\text{T}}\mathbf{y}\)&lt;/p&gt;

&lt;p&gt;This is known as the &lt;strong&gt;Normal Equation&lt;/strong&gt;. If \(X^{\text{T}}X\) is invertible (which happens when \(X\) has full column rank), we can solve for \(\mathbf{w}\):&lt;/p&gt;

&lt;blockquote&gt;
\[\boxed{\mathbf{w}^* = (X^{\text{T}}X)^{-1}X^{\text{T}}\mathbf{y}}\]
&lt;/blockquote&gt;

&lt;p&gt;This is the &lt;strong&gt;closed-form solution&lt;/strong&gt; for linear least-squares regression, also known as the &lt;strong&gt;Normal Equation solution&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Time complexity: roughly \(n^2k\) operations&lt;/li&gt;
  &lt;li&gt;A standard computer solves problems with hundreds of variables and thousands of terms in seconds&lt;/li&gt;
  &lt;li&gt;Sparse matrices (many zero entries) can be solved much faster&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; A sparse matrix for image processing might have only 5 non-zero entries per row in a 10,000 × 10,000 matrix.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05-01 Linear Programming (LP)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_01_Linear_Programming_(LP)/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_01_Linear_Programming_(LP)</id>
   <content type="html">&lt;p&gt;During the Berlin Airlift of 1948, planners faced a logistical nightmare: how to allocate aircraft, crews, fuel, and runways to feed two million people at minimum cost. George Dantzig’s Linear Programming framework turned that crisis into a system of linear inequalities—and launched an optimization revolution that today schedules airlines, balances power grids, and routes global supply chains every second.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-foundations-of-linear-programming&quot;&gt;Key ideas: Foundations of Linear Programming&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Polyhedral Geometry and Vertex Optimality&lt;/strong&gt;: The feasible set \(\{x : Gx \preceq h,\; Ax = b\}\) is a &lt;em&gt;polyhedron&lt;/em&gt;—an intersection of finitely many halfspaces and hyperplanes. Because the objective \(c^T x\) has constant gradient \(c\), level sets are parallel hyperplanes that always make last contact with the polyhedron at a boundary face (and at a vertex whenever the polyhedron has vertices and the LP is bounded).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Standard Form vs. Inequality Form&lt;/strong&gt;: Every LP can be converted into standard form \(\min c^T x \text{ s.t. } Ax = b, x \ge 0\) using slack variables for inequalities and splitting free variables as \(x = x^+ - x^-\) with \(x^+, x^- \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Three Possible Outcomes&lt;/strong&gt;: Every LP falls into exactly one of three regimes: (i) &lt;em&gt;infeasible&lt;/em&gt; (empty polyhedron), (ii) &lt;em&gt;unbounded below&lt;/em&gt; (a feasible ray along which \(c^T d &amp;lt; 0\)), or (iii) &lt;em&gt;optimal&lt;/em&gt; (attained at a finite vertex).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear Modeling Tricks&lt;/strong&gt;: Piecewise-linear convex functions such as \(\|Ax - b\|_1\), \(\|Ax - b\|_\infty\), and \(\max_i (a_i^T x + b_i)\) can all be recast as pure LPs via epigraph and absolute-value auxiliary variables.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-solving-a-two-product-lp-by-vertex-enumeration&quot;&gt;Worked example: Solving a Two-Product LP by Vertex Enumeration&lt;/h3&gt;

&lt;p&gt;Maximize profit \(P(x_1, x_2) = 4x_1 + 3x_2\) (equivalently minimize \(-4x_1 - 3x_2\)) subject to:
\(x_1 + x_2 \le 6, \qquad 2x_1 + x_2 \le 8, \qquad x_1 \ge 0, \quad x_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify all boundary lines&lt;/strong&gt;: The four lines are \(x_1 = 0\), \(x_2 = 0\), \(x_1 + x_2 = 6\), and \(2x_1 + x_2 = 8\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find the feasible vertices (extreme points)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Origin: \(v_1 = (0, 0)\) — satisfies \(0 \le 6, 0 \le 8\).&lt;/li&gt;
      &lt;li&gt;\(x_1\)-intercept of \(2x_1 + x_2 = 8\): \(v_2 = (4, 0)\) — satisfies \(4 \le 6, 8 \le 8\). (Note \((6, 0)\) violates \(2x_1 + x_2 \le 8\).)&lt;/li&gt;
      &lt;li&gt;\(x_2\)-intercept of \(x_1 + x_2 = 6\): \(v_3 = (0, 6)\) — satisfies \(6 \le 6, 6 \le 8\). (Note \((0, 8)\) violates \(x_1 + x_2 \le 6\).)&lt;/li&gt;
      &lt;li&gt;Intersection of \(x_1 + x_2 = 6\) and \(2x_1 + x_2 = 8\): subtracting gives \(x_1 = 2\), so \(x_2 = 4\), giving \(v_4 = (2, 4)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the objective \(P(x_1, x_2) = 4x_1 + 3x_2\) at every vertex&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;
\[P(0, 0) = 0\]
      &lt;/li&gt;
      &lt;li&gt;
\[P(4, 0) = 16\]
      &lt;/li&gt;
      &lt;li&gt;
\[P(0, 6) = 18\]
      &lt;/li&gt;
      &lt;li&gt;\(P(2, 4) = 4(2) + 3(4) = 8 + 12 = 20\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclude global optimality&lt;/strong&gt;: By the Fundamental Theorem of Linear Programming, the maximum occurs at \(x^\star = (2, 4)\) with optimal profit \(P^\star = 20\).&lt;/li&gt;
&lt;/ol&gt;

&lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?features=es6&quot;&gt;&lt;/script&gt;

&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;Linear Programming (LP) is one of the most fundamental and widely-used optimization techniques in mathematics, economics, and engineering. Imagine you’re a factory manager trying to maximize profit while dealing with limited resources - this is exactly the type of problem LP was designed to solve!&lt;/p&gt;

&lt;h3 id=&quot;what-makes-a-problem-linear&quot;&gt;What makes a problem “Linear”?&lt;/h3&gt;

&lt;p&gt;A problem is linear when:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The &lt;strong&gt;objective function&lt;/strong&gt; (what you want to optimize) is a straight line relationship&lt;/li&gt;
  &lt;li&gt;All &lt;strong&gt;constraints&lt;/strong&gt; (limitations) are also straight line relationships&lt;/li&gt;
  &lt;li&gt;No variables are multiplied together (no \(x_1 \cdot x_2\) terms)&lt;/li&gt;
  &lt;li&gt;No variables appear in exponents or under square roots&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;simple-example-the-farmers-problem&quot;&gt;Simple Example: The Farmer’s Problem&lt;/h3&gt;

&lt;p&gt;Let’s start with an intuitive example. A farmer has 100 acres of land and wants to plant corn and wheat to maximize profit:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Corn&lt;/strong&gt;: $300 profit per acre, requires 2 hours of labor per acre&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Wheat&lt;/strong&gt;: $200 profit per acre, requires 1 hour of labor per acre&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Available labor&lt;/strong&gt;: 150 hours total&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Question&lt;/strong&gt;: How many acres of each crop should the farmer plant?&lt;/p&gt;

&lt;div id=&quot;farmer-problem-viz&quot; style=&quot;margin: 20px 0;&quot;&gt;&lt;/div&gt;

&lt;div class=&quot;content-box exercise-box&quot;&gt;
&lt;strong&gt;Interactive Exercise:&lt;/strong&gt; Use the sliders below to explore different combinations of corn and wheat. Watch how the profit changes and whether constraints are satisfied!

&lt;div style=&quot;margin: 10px 0;&quot;&gt;
  &lt;label for=&quot;corn-acres&quot;&gt;Corn acres: &lt;span id=&quot;corn-value&quot;&gt;50&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
  &lt;input type=&quot;range&quot; id=&quot;corn-acres&quot; min=&quot;0&quot; max=&quot;100&quot; value=&quot;50&quot; style=&quot;width: 300px;&quot; /&gt;
&lt;/div&gt;

&lt;div style=&quot;margin: 10px 0;&quot;&gt;
  &lt;label for=&quot;wheat-acres&quot;&gt;Wheat acres: &lt;span id=&quot;wheat-value&quot;&gt;50&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
  &lt;input type=&quot;range&quot; id=&quot;wheat-acres&quot; min=&quot;0&quot; max=&quot;100&quot; value=&quot;50&quot; style=&quot;width: 300px;&quot; /&gt;
&lt;/div&gt;

&lt;div id=&quot;farmer-results&quot; style=&quot;margin-top: 15px; font-family: monospace;&quot;&gt;
  &lt;div&gt;Total land used: &lt;span id=&quot;land-used&quot;&gt;100&lt;/span&gt; / 100 acres&lt;/div&gt;
  &lt;div&gt;Total labor used: &lt;span id=&quot;labor-used&quot;&gt;150&lt;/span&gt; / 150 hours&lt;/div&gt;
  &lt;div&gt;Total profit: $&lt;span id=&quot;total-profit&quot;&gt;25000&lt;/span&gt;&lt;/div&gt;
  &lt;div id=&quot;feasibility-status&quot; style=&quot;font-weight: bold; color: green;&quot;&gt;✓ Feasible solution&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now let’s formalize this intuition. If both the objective function and constraint functions are affine, the optimization problem is called a &lt;em&gt;linear program&lt;/em&gt; (LP). The general linear program is formulated as:&lt;/p&gt;

&lt;h3 id=&quot;general-lp&quot;&gt;General LP&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Gx \preceq h}\\\\
   &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
   &amp;amp;\text{where } &amp;amp;&amp;amp;G \in \mathbb{R}^{m \times n} \text{ and } A \in \mathbb{R}^{p \times n}.
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;The constant \(+d\) in the objective function does not affect the optimization process or result and can be omitted.&lt;/li&gt;
  &lt;li&gt;If you want to maximize \(c^T x + d\) under the same constraints, you can equivalently minimize \(-c^T x - d\).&lt;/li&gt;
  &lt;li&gt;The above problem seeks the minimizer \(x^*\) of the affine function \(c^T x + d\) over a polyhedral feasible set.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;geometric-interpretation&quot;&gt;Geometric Interpretation&lt;/h3&gt;

&lt;p&gt;The power of linear programming becomes clear when we visualize it geometrically. Each constraint defines a half-space, and the feasible region is the intersection of all these half-spaces - forming a &lt;strong&gt;polyhedron&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Key Insight:&lt;/strong&gt; The optimal solution of a linear program always occurs at a &lt;strong&gt;vertex&lt;/strong&gt; (corner point) of the feasible region! This is why the simplex method works by moving from vertex to vertex.
&lt;/div&gt;

&lt;div id=&quot;geometric-lp-viz&quot; style=&quot;margin: 20px 0; text-align: center;&quot;&gt;&lt;/div&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter05/05_01_geometric_interpretation_of_LP.png&quot; alt=&quot;[Fig1] Geometric interpretation of LP [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Traditional geometric interpretation of LP [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;lp-in-standard-form&quot;&gt;LP in Standard form&lt;/h2&gt;

&lt;p&gt;Why do we need a standard form? Many LP algorithms (like the simplex method) are designed to work with a specific format. Converting to standard form allows us to use these powerful algorithms consistently.&lt;/p&gt;

&lt;h3 id=&quot;standard-form-lp&quot;&gt;Standard form LP&lt;/h3&gt;
&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x + d} \\\\
   &amp;amp;\text{subject to } &amp;amp;&amp;amp;{A x = b} \\\\
   &amp;amp; &amp;amp;&amp;amp;{x \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Key characteristics of standard form:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Objective&lt;/strong&gt;: Always minimization (maximization problems are converted by negating)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constraints&lt;/strong&gt;: Only equality constraints (inequalities converted using slack variables)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Variables&lt;/strong&gt;: All variables must be non-negative&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Why Standard Form?&lt;/strong&gt; 
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Algorithmic efficiency:&lt;/strong&gt; Simplex method works directly on standard form&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Theoretical analysis:&lt;/strong&gt; Easier to prove optimality conditions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Software implementation:&lt;/strong&gt; Most LP solvers expect standard form input&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;All general LPs can be converted to standard form using the following steps:&lt;/p&gt;

&lt;h3 id=&quot;converting-lps-to-standard-form&quot;&gt;Converting LPs to standard form&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Step 1.&lt;/strong&gt; Use slack variables \(s\) to convert inequality constraints into equality constraints:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
    &amp;amp;\text{minimize}_{x, s} &amp;amp;&amp;amp;{c^T x + d} \\\\
    &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Gx + s = h} \\\\
    &amp;amp; &amp;amp;&amp;amp;{Ax = b},\\\\
    &amp;amp; &amp;amp;&amp;amp;{s \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 2.&lt;/strong&gt; Replace each variable \(x\) with two nonnegative variables:
\(x = x^{+}  - x^{-}\), where \(x^{+} \text{, } x^{-} \succeq 0\).&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
    &amp;amp;\text{minimize}_{x^{+}, x^{-}, s} &amp;amp;&amp;amp;{c^Tx^{+} - c^Tx^{-} + d} \\\\
    &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Gx^{+} - Gx^{-} + s = h} \\\\
    &amp;amp; &amp;amp;&amp;amp;{Ax^{+} - Ax^{-} = b},\\\\
    &amp;amp; &amp;amp;&amp;amp;{s \succeq 0}\\\\
    &amp;amp; &amp;amp;&amp;amp;{x^{+} \succeq 0}, {x^{-} \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 3.&lt;/strong&gt; Define \(\tilde{x}\), \(\tilde{c}\), \(\tilde{b}\), and \(\tilde{A}\) as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\tilde{x} =
\begin{bmatrix}
x^{+} \\\\
x^{-} \\\\
s
\end{bmatrix}, 
\tilde{c} =
\begin{bmatrix}
c \\\\
-c \\\\
0
\end{bmatrix},
\tilde{b} =
\begin{bmatrix}
h \\\\
b
\end{bmatrix}\), 
\(\tilde{A} =
\begin{bmatrix}
G &amp;amp; -G &amp;amp; I\\\\
A &amp;amp; -A &amp;amp; O
\end{bmatrix}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 4.&lt;/strong&gt; Substitute \(\tilde{x}\), \(\tilde{c}\), \(\tilde{b}\), and \(\tilde{A}\) into the problem from Step 2:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
    &amp;amp;\text{minimize}_{\tilde{x}} &amp;amp;&amp;amp;{\tilde{c}^T \tilde{x} + d} \\\\
    &amp;amp;\text{subject to} &amp;amp;&amp;amp;{\tilde{A} \tilde{x} = \tilde{b}} \\\\
    &amp;amp; &amp;amp;&amp;amp;{\tilde{x} \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;example---diet-program&quot;&gt;Example - Diet program&lt;/h3&gt;

&lt;p&gt;The diet problem is a classic application of linear programming, first studied during World War II to find the most economical way to feed soldiers while meeting nutritional requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Setup:&lt;/strong&gt; Find the cheapest combination of foods that meets all nutritional requirements.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
    &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x} \\\\
    &amp;amp;\text{subject to } &amp;amp;&amp;amp;{Dx \succeq d} \\\\
    &amp;amp; &amp;amp;&amp;amp;{x \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Variables and Parameters:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(c_j\): Cost per unit of food item j ($/unit)&lt;/li&gt;
  &lt;li&gt;\(d_i\): Minimum recommended intake for nutrient i (units/day)&lt;/li&gt;
  &lt;li&gt;\(D_{ij}\): Amount of nutrient i in food item j (units of nutrient per unit of food)&lt;/li&gt;
  &lt;li&gt;\(x_j\): Amount of food item j in the diet (units/day)&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;content-box exercise-box&quot;&gt;
&lt;strong&gt;Interactive Diet Optimizer:&lt;/strong&gt; Let&apos;s solve a simplified diet problem with 3 foods and 2 nutrients!

&lt;div style=&quot;display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; margin: 15px 0;&quot;&gt;
  &lt;div style=&quot;text-align: center;&quot;&gt;
    &lt;strong&gt;Bread&lt;/strong&gt;&lt;br /&gt;
    Cost: $2/loaf&lt;br /&gt;
    Protein: 4g/loaf&lt;br /&gt;
    Calories: 200/loaf
  &lt;/div&gt;
  &lt;div style=&quot;text-align: center;&quot;&gt;
    &lt;strong&gt;Milk&lt;/strong&gt;&lt;br /&gt;
    Cost: $3/liter&lt;br /&gt;
    Protein: 8g/liter&lt;br /&gt;
    Calories: 150/liter
  &lt;/div&gt;
  &lt;div style=&quot;text-align: center;&quot;&gt;
    &lt;strong&gt;Meat&lt;/strong&gt;&lt;br /&gt;
    Cost: $8/kg&lt;br /&gt;
    Protein: 20g/kg&lt;br /&gt;
    Calories: 300/kg
  &lt;/div&gt;
&lt;/div&gt;

&lt;div style=&quot;margin: 15px 0;&quot;&gt;
  &lt;strong&gt;Requirements:&lt;/strong&gt;
  &lt;div&gt;Minimum protein: &lt;input type=&quot;number&quot; id=&quot;min-protein&quot; value=&quot;20&quot; min=&quot;10&quot; max=&quot;50&quot; style=&quot;width: 60px;&quot; /&gt; grams/day&lt;/div&gt;
  &lt;div&gt;Minimum calories: &lt;input type=&quot;number&quot; id=&quot;min-calories&quot; value=&quot;800&quot; min=&quot;500&quot; max=&quot;1500&quot; style=&quot;width: 80px;&quot; /&gt; calories/day&lt;/div&gt;
&lt;/div&gt;

&lt;button id=&quot;solve-diet&quot; style=&quot;background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer;&quot;&gt;Solve Diet Problem&lt;/button&gt;

&lt;div id=&quot;diet-results&quot; style=&quot;margin-top: 15px; font-family: monospace; background-color: #f9f9f9; padding: 10px; border-radius: 4px;&quot;&gt;
  &lt;div&gt;Click &quot;Solve Diet Problem&quot; to see the optimal solution!&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Real-world Applications:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Military logistics:&lt;/strong&gt; Feeding troops cost-effectively&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hospital meal planning:&lt;/strong&gt; Meeting patient dietary requirements&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Animal feed optimization:&lt;/strong&gt; Livestock nutrition at minimum cost&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;School lunch programs:&lt;/strong&gt; Nutritious meals within budget constraints&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-simplex-algorithm&quot;&gt;The Simplex Algorithm&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Simplex Algorithm&lt;/strong&gt;, developed by George Dantzig in 1947, is one of the most important algorithms in optimization history. It revolutionized linear programming by providing an efficient method to solve LP problems systematically.&lt;/p&gt;

&lt;h3 id=&quot;why-simplex-works-the-fundamental-theorem&quot;&gt;Why Simplex Works: The Fundamental Theorem&lt;/h3&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Fundamental Theorem of Linear Programming:&lt;/strong&gt; If a linear program has an optimal solution, then there exists an optimal solution that occurs at a vertex (extreme point) of the feasible region.
&lt;/div&gt;

&lt;p&gt;This theorem is the key insight behind the Simplex algorithm. Instead of searching the entire feasible region (which could be infinite), we only need to check the finite number of vertices!&lt;/p&gt;

&lt;h3 id=&quot;how-simplex-works-the-strategy&quot;&gt;How Simplex Works: The Strategy&lt;/h3&gt;

&lt;p&gt;The Simplex algorithm follows this elegant strategy:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Start&lt;/strong&gt; at any vertex of the feasible region&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check&lt;/strong&gt; if the current vertex is optimal&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Move&lt;/strong&gt; to an adjacent vertex that improves the objective function&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Repeat&lt;/strong&gt; until no improvement is possible (optimal solution found)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;simplex-algorithm-steps&quot;&gt;Simplex Algorithm Steps&lt;/h3&gt;

&lt;p&gt;Let’s walk through the algorithm step by step using our standard form LP:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
    &amp;amp;\text{minimize}_{x} &amp;amp;&amp;amp;{c^T x} \\\\
    &amp;amp;\text{subject to } &amp;amp;&amp;amp;{A x = b} \\\\
    &amp;amp; &amp;amp;&amp;amp;{x \succeq 0}.
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Initial Setup&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Convert the LP to standard form (if not already)&lt;/li&gt;
  &lt;li&gt;Find an initial basic feasible solution (vertex)&lt;/li&gt;
  &lt;li&gt;Set up the simplex tableau&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Optimality Test&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Check if the current solution is optimal&lt;/li&gt;
  &lt;li&gt;If all reduced costs are non-negative, we’re done!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Choose Entering Variable&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Select the variable with the most negative reduced cost&lt;/li&gt;
  &lt;li&gt;This determines the direction to move&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Choose Leaving Variable&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Use the minimum ratio test to avoid infeasibility&lt;/li&gt;
  &lt;li&gt;This determines how far to move&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Pivot Operation&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Update the tableau using Gaussian elimination&lt;/li&gt;
  &lt;li&gt;Move to the new vertex&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Repeat&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Go back to Step 2 until optimal&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;interactive-simplex-example&quot;&gt;Interactive Simplex Example&lt;/h3&gt;

&lt;p&gt;Let’s solve a simple 2D problem step by step to see how Simplex works in practice:&lt;/p&gt;

&lt;div class=&quot;content-box exercise-box&quot;&gt;
&lt;strong&gt;Interactive Simplex Solver:&lt;/strong&gt; Watch the algorithm move from vertex to vertex!

**Problem:**
$$\begin{align}
\text{maximize } &amp;amp; 3x_1 + 2x_2 \\
\text{subject to } &amp;amp; x_1 + x_2 \leq 4 \\
&amp;amp; 2x_1 + x_2 \leq 6 \\
&amp;amp; x_1, x_2 \geq 0
\end{align}$$

&lt;div id=&quot;simplex-interactive&quot; style=&quot;margin: 20px 0;&quot;&gt;&lt;/div&gt;

&lt;div style=&quot;margin: 15px 0;&quot;&gt;
  &lt;button id=&quot;simplex-step&quot; style=&quot;background-color: #2196F3; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; margin-right: 10px;&quot;&gt;Next Step&lt;/button&gt;
  &lt;button id=&quot;simplex-reset&quot; style=&quot;background-color: #f44336; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer;&quot;&gt;Reset&lt;/button&gt;
&lt;/div&gt;

&lt;div id=&quot;simplex-status&quot; style=&quot;margin-top: 15px; font-family: monospace; background-color: #f9f9f9; padding: 15px; border-radius: 4px;&quot;&gt;
  &lt;div&gt;&lt;strong&gt;Step 0:&lt;/strong&gt; Starting at origin (0, 0)&lt;/div&gt;
  &lt;div&gt;Current objective value: 0&lt;/div&gt;
  &lt;div&gt;Click &quot;Next Step&quot; to begin the Simplex algorithm!&lt;/div&gt;
&lt;/div&gt;

&lt;div id=&quot;simplex-tableau&quot; style=&quot;margin-top: 15px; font-family: monospace; background-color: #f0f8ff; padding: 15px; border-radius: 4px;&quot;&gt;
  &lt;strong&gt;Current Simplex Tableau:&lt;/strong&gt;
  &lt;div id=&quot;tableau-content&quot; style=&quot;margin-top: 10px;&quot;&gt;
    Click &quot;Next Step&quot; to see the tableau!
  &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;why-simplex-is-efficient&quot;&gt;Why Simplex is Efficient&lt;/h3&gt;

&lt;p&gt;Despite having potentially exponential worst-case complexity, Simplex is remarkably efficient in practice:&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Simplex Efficiency:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Average case:&lt;/strong&gt; Typically visits only 2-3 times the number of constraints&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Practical problems:&lt;/strong&gt; Often solves in polynomial time&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Warm starts:&lt;/strong&gt; Can reuse previous solutions when problem changes slightly&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Degeneracy handling:&lt;/strong&gt; Modern implementations handle degenerate cases well&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;h3 id=&quot;simplex-variants-and-modern-developments&quot;&gt;Simplex Variants and Modern Developments&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Revised Simplex Method:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;More numerically stable&lt;/li&gt;
  &lt;li&gt;Better for sparse matrices&lt;/li&gt;
  &lt;li&gt;Used in most commercial solvers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dual Simplex Method:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Starts with dual feasible solution&lt;/li&gt;
  &lt;li&gt;Useful for sensitivity analysis&lt;/li&gt;
  &lt;li&gt;Better for certain problem types&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Interior Point Methods:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Polynomial-time complexity guarantee&lt;/li&gt;
  &lt;li&gt;Better for very large problems&lt;/li&gt;
  &lt;li&gt;Complement rather than replace Simplex&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;impact-and-applications&quot;&gt;Impact and Applications&lt;/h3&gt;

&lt;p&gt;The Simplex algorithm has transformed numerous industries:&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Simplex Success Stories:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Airlines:&lt;/strong&gt; Crew scheduling, route optimization, fleet assignment&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Manufacturing:&lt;/strong&gt; Production planning, supply chain optimization&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Finance:&lt;/strong&gt; Portfolio optimization, risk management&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Telecommunications:&lt;/strong&gt; Network flow optimization, bandwidth allocation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Energy:&lt;/strong&gt; Power grid optimization, resource allocation&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;script&gt;
/**
 * Interactive Linear Programming Visualizations
 * Implements farmer problem, geometric interpretation, diet optimizer, and norm comparisons
 */

// Wait for DOM to be fully loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    
    // ==================== FARMER PROBLEM INTERACTIVE ====================
    
    function initializeFarmerProblem() {
        const cornSlider = document.getElementById(&apos;corn-acres&apos;);
        const wheatSlider = document.getElementById(&apos;wheat-acres&apos;);
        
        if (!cornSlider || !wheatSlider) return;
        
        function updateFarmerResults() {
            const corn = parseFloat(cornSlider.value);
            const wheat = parseFloat(wheatSlider.value);
            
            // Update display values
            document.getElementById(&apos;corn-value&apos;).textContent = corn;
            document.getElementById(&apos;wheat-value&apos;).textContent = wheat;
            
            // Calculate metrics
            const landUsed = corn + wheat;
            const laborUsed = corn * 2 + wheat * 1; // 2 hours per corn acre, 1 hour per wheat acre
            const profit = corn * 300 + wheat * 200; // $300 per corn acre, $200 per wheat acre
            
            // Update results
            document.getElementById(&apos;land-used&apos;).textContent = landUsed;
            document.getElementById(&apos;labor-used&apos;).textContent = laborUsed;
            document.getElementById(&apos;total-profit&apos;).textContent = profit;
            
            // Check feasibility
            const feasibilityStatus = document.getElementById(&apos;feasibility-status&apos;);
            if (landUsed &lt;= 100 &amp;&amp; laborUsed &lt;= 150) {
                feasibilityStatus.textContent = &apos;✓ Feasible solution&apos;;
                feasibilityStatus.style.color = &apos;green&apos;;
            } else {
                feasibilityStatus.textContent = &apos;✗ Infeasible solution&apos;;
                feasibilityStatus.style.color = &apos;red&apos;;
            }
        }
        
        cornSlider.addEventListener(&apos;input&apos;, updateFarmerResults);
        wheatSlider.addEventListener(&apos;input&apos;, updateFarmerResults);
        
        // Initialize
        updateFarmerResults();
    }
    
    // ==================== DIET PROBLEM SOLVER ====================
    
    function initializeDietSolver() {
        const solveButton = document.getElementById(&apos;solve-diet&apos;);
        if (!solveButton) return;
        
        solveButton.addEventListener(&apos;click&apos;, function() {
            const minProtein = parseFloat(document.getElementById(&apos;min-protein&apos;).value);
            const minCalories = parseFloat(document.getElementById(&apos;min-calories&apos;).value);
            
            // Simple heuristic solver (in practice, would use simplex method)
            // Food data: [cost, protein, calories]
            const bread = [2, 4, 200];
            const milk = [3, 8, 150];
            const meat = [8, 20, 300];
            
            // Try different combinations and find minimum cost feasible solution
            let bestCost = Infinity;
            let bestSolution = null;
            
            for (let b = 0; b &lt;= 20; b += 0.5) {
                for (let m = 0; m &lt;= 10; m += 0.5) {
                    for (let mt = 0; mt &lt;= 5; mt += 0.5) {
                        const protein = b * bread[1] + m * milk[1] + mt * meat[1];
                        const calories = b * bread[2] + m * milk[2] + mt * meat[2];
                        const cost = b * bread[0] + m * milk[0] + mt * meat[0];
                        
                        if (protein &gt;= minProtein &amp;&amp; calories &gt;= minCalories &amp;&amp; cost &lt; bestCost) {
                            bestCost = cost;
                            bestSolution = [b, m, mt];
                        }
                    }
                }
            }
            
            const resultsDiv = document.getElementById(&apos;diet-results&apos;);
            if (bestSolution) {
                const [bread_amt, milk_amt, meat_amt] = bestSolution;
                const totalProtein = bread_amt * bread[1] + milk_amt * milk[1] + meat_amt * meat[1];
                const totalCalories = bread_amt * bread[2] + milk_amt * milk[2] + meat_amt * meat[2];
                
                resultsDiv.innerHTML = `
                    &lt;div&gt;&lt;strong&gt;Optimal Diet Solution:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Bread: ${bread_amt.toFixed(1)} loaves&lt;/div&gt;
                    &lt;div&gt;Milk: ${milk_amt.toFixed(1)} liters&lt;/div&gt;
                    &lt;div&gt;Meat: ${meat_amt.toFixed(1)} kg&lt;/div&gt;
                    &lt;div&gt;---&lt;/div&gt;
                    &lt;div&gt;Total cost: $${bestCost.toFixed(2)}&lt;/div&gt;
                    &lt;div&gt;Total protein: ${totalProtein.toFixed(1)}g (required: ${minProtein}g)&lt;/div&gt;
                    &lt;div&gt;Total calories: ${totalCalories.toFixed(0)} (required: ${minCalories})&lt;/div&gt;
                `;
            } else {
                resultsDiv.innerHTML = &apos;&lt;div style=&quot;color: red;&quot;&gt;No feasible solution found!&lt;/div&gt;&apos;;
            }
        });
    }
    
    // ==================== SIMPLEX ALGORITHM VISUALIZATION ====================
    
    function initializeSimplexVisualization() {
        const stepButton = document.getElementById(&apos;simplex-step&apos;);
        const resetButton = document.getElementById(&apos;simplex-reset&apos;);
        const statusDiv = document.getElementById(&apos;simplex-status&apos;);
        const tableauDiv = document.getElementById(&apos;tableau-content&apos;);
        const interactiveDiv = document.getElementById(&apos;simplex-interactive&apos;);
        
        if (!stepButton || !resetButton || !statusDiv || !tableauDiv || !interactiveDiv) return;
        
        // Simplex algorithm state
        let currentStep = 0;
        let currentVertex = [0, 0]; // Starting at origin
        let isOptimal = false;
        
        // Problem: maximize 3x1 + 2x2 subject to x1 + x2 &lt;= 4, 2x1 + x2 &lt;= 6, x1,x2 &gt;= 0
        // In standard form: minimize -3x1 - 2x2 subject to x1 + x2 + s1 = 4, 2x1 + x2 + s2 = 6
        
        const vertices = [
            [0, 0, 4, 6], // (x1, x2, s1, s2) - origin
            [0, 4, 0, 2], // (0, 4, 0, 2) - intersection with x1 + x2 = 4
            [2, 2, 0, 0], // (2, 2, 0, 0) - intersection of both constraints
            [3, 0, 1, 0]  // (3, 0, 1, 0) - intersection with 2x1 + x2 = 6
        ];
        
        const objectiveValues = [0, 8, 10, 9]; // 3x1 + 2x2 at each vertex
        const simplexPath = [0, 3, 2]; // Path: origin -&gt; (3,0) -&gt; (2,2) optimal
        
        function createVisualization() {
            const width = 400;
            const height = 300;
            const margin = {top: 20, right: 20, bottom: 40, left: 40};
            
            // Clear previous content
            interactiveDiv.innerHTML = &apos;&apos;;
            
            const svg = d3.select(&apos;#simplex-interactive&apos;)
                .append(&apos;svg&apos;)
                .attr(&apos;width&apos;, width)
                .attr(&apos;height&apos;, height);
            
            // Scales
            const xScale = d3.scaleLinear()
                .domain([0, 4])
                .range([margin.left, width - margin.right]);
            
            const yScale = d3.scaleLinear()
                .domain([0, 6])
                .range([height - margin.bottom, margin.top]);
            
            // Draw feasible region
            const feasibleRegion = [
                [0, 0], [0, 4], [2, 2], [3, 0], [0, 0]
            ];
            
            svg.append(&apos;path&apos;)
                .datum(feasibleRegion)
                .attr(&apos;fill&apos;, &apos;lightblue&apos;)
                .attr(&apos;fill-opacity&apos;, 0.3)
                .attr(&apos;stroke&apos;, &apos;blue&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;d&apos;, d3.line()
                    .x(d =&gt; xScale(d[0]))
                    .y(d =&gt; yScale(d[1]))
                );
            
            // Draw constraint lines
            // x1 + x2 = 4
            svg.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, xScale(0))
                .attr(&apos;y1&apos;, yScale(4))
                .attr(&apos;x2&apos;, xScale(4))
                .attr(&apos;y2&apos;, yScale(0))
                .attr(&apos;stroke&apos;, &apos;red&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;stroke-dasharray&apos;, &apos;5,5&apos;);
            
            // 2x1 + x2 = 6
            svg.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, xScale(0))
                .attr(&apos;y1&apos;, yScale(6))
                .attr(&apos;x2&apos;, xScale(3))
                .attr(&apos;y2&apos;, yScale(0))
                .attr(&apos;stroke&apos;, &apos;green&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;stroke-dasharray&apos;, &apos;5,5&apos;);
            
            // Draw vertices
            const vertexPoints = [[0,0], [0,4], [2,2], [3,0]];
            svg.selectAll(&apos;.vertex&apos;)
                .data(vertexPoints)
                .enter()
                .append(&apos;circle&apos;)
                .attr(&apos;class&apos;, &apos;vertex&apos;)
                .attr(&apos;cx&apos;, d =&gt; xScale(d[0]))
                .attr(&apos;cy&apos;, d =&gt; yScale(d[1]))
                .attr(&apos;r&apos;, 6)
                .attr(&apos;fill&apos;, &apos;orange&apos;)
                .attr(&apos;stroke&apos;, &apos;black&apos;)
                .attr(&apos;stroke-width&apos;, 2);
            
            // Current position indicator
            svg.append(&apos;circle&apos;)
                .attr(&apos;id&apos;, &apos;current-position&apos;)
                .attr(&apos;cx&apos;, xScale(currentVertex[0]))
                .attr(&apos;cy&apos;, yScale(currentVertex[1]))
                .attr(&apos;r&apos;, 8)
                .attr(&apos;fill&apos;, &apos;red&apos;)
                .attr(&apos;stroke&apos;, &apos;darkred&apos;)
                .attr(&apos;stroke-width&apos;, 3);
            
            // Axes
            svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(0,${height - margin.bottom})`)
                .call(d3.axisBottom(xScale));
            
            svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${margin.left},0)`)
                .call(d3.axisLeft(yScale));
            
            // Axis labels
            svg.append(&apos;text&apos;)
                .attr(&apos;x&apos;, width / 2)
                .attr(&apos;y&apos;, height - 5)
                .attr(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;x₁&apos;);
            
            svg.append(&apos;text&apos;)
                .attr(&apos;transform&apos;, &apos;rotate(-90)&apos;)
                .attr(&apos;x&apos;, -height / 2)
                .attr(&apos;y&apos;, 15)
                .attr(&apos;text-anchor&apos;, &apos;middle&apos;)
                .text(&apos;x₂&apos;);
            
            // Legend
            const legend = svg.append(&apos;g&apos;)
                .attr(&apos;transform&apos;, `translate(${width - 150}, 30)`);
            
            legend.append(&apos;text&apos;)
                .attr(&apos;x&apos;, 0)
                .attr(&apos;y&apos;, 0)
                .text(&apos;Constraints:&apos;)
                .attr(&apos;font-weight&apos;, &apos;bold&apos;);
            
            legend.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, 0)
                .attr(&apos;y1&apos;, 15)
                .attr(&apos;x2&apos;, 20)
                .attr(&apos;y2&apos;, 15)
                .attr(&apos;stroke&apos;, &apos;red&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;stroke-dasharray&apos;, &apos;5,5&apos;);
            
            legend.append(&apos;text&apos;)
                .attr(&apos;x&apos;, 25)
                .attr(&apos;y&apos;, 19)
                .text(&apos;x₁ + x₂ ≤ 4&apos;)
                .attr(&apos;font-size&apos;, &apos;12px&apos;);
            
            legend.append(&apos;line&apos;)
                .attr(&apos;x1&apos;, 0)
                .attr(&apos;y1&apos;, 30)
                .attr(&apos;x2&apos;, 20)
                .attr(&apos;y2&apos;, 30)
                .attr(&apos;stroke&apos;, &apos;green&apos;)
                .attr(&apos;stroke-width&apos;, 2)
                .attr(&apos;stroke-dasharray&apos;, &apos;5,5&apos;);
            
            legend.append(&apos;text&apos;)
                .attr(&apos;x&apos;, 25)
                .attr(&apos;y&apos;, 34)
                .text(&apos;2x₁ + x₂ ≤ 6&apos;)
                .attr(&apos;font-size&apos;, &apos;12px&apos;);
        }
        
        function updateTableau(step) {
            let tableauHTML = &apos;&apos;;
            
            switch(step) {
                case 0:
                    tableauHTML = `
                        &lt;table style=&quot;border-collapse: collapse; margin: 10px 0;&quot;&gt;
                            &lt;tr style=&quot;background-color: #e0e0e0;&quot;&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Basic&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;RHS&lt;/th&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;4&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;2&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;6&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #fff2cc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;z&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; color: red;&quot;&gt;&lt;strong&gt;-3&lt;/strong&gt;&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; color: red;&quot;&gt;-2&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
                            &lt;strong&gt;Analysis:&lt;/strong&gt; Most negative coefficient is -3 (x₁ column). x₁ enters the basis.
                        &lt;/div&gt;
                    `;
                    break;
                case 1:
                    tableauHTML = `
                        &lt;table style=&quot;border-collapse: collapse; margin: 10px 0;&quot;&gt;
                            &lt;tr style=&quot;background-color: #e0e0e0;&quot;&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Basic&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;RHS&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Ratio&lt;/th&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; background-color: #ffcccc;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;4&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;4/1 = 4&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #ccffcc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; background-color: #ffcccc;&quot;&gt;&lt;strong&gt;2&lt;/strong&gt;&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;6&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;&lt;strong&gt;6/2 = 3&lt;/strong&gt;&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #fff2cc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;z&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; background-color: #ffcccc;&quot;&gt;-3&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;-2&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;-&lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
                            &lt;strong&gt;Minimum ratio test:&lt;/strong&gt; min{4/1, 6/2} = min{4, 3} = 3. s₂ leaves the basis.
                        &lt;/div&gt;
                    `;
                    break;
                case 2:
                    tableauHTML = `
                        &lt;table style=&quot;border-collapse: collapse; margin: 10px 0;&quot;&gt;
                            &lt;tr style=&quot;background-color: #e0e0e0;&quot;&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Basic&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;RHS&lt;/th&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; color: red;&quot;&gt;&lt;strong&gt;0.5&lt;/strong&gt;&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;-0.5&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0.5&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0.5&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;3&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #fff2cc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;z&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px; color: red;&quot;&gt;&lt;strong&gt;-0.5&lt;/strong&gt;&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1.5&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;9&lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
                            &lt;strong&gt;Current solution:&lt;/strong&gt; x₁ = 3, x₂ = 0, objective = 9&lt;br&gt;
                            &lt;strong&gt;Analysis:&lt;/strong&gt; x₂ has negative coefficient (-0.5), so x₂ enters the basis.
                        &lt;/div&gt;
                    `;
                    break;
                case 3:
                    tableauHTML = `
                        &lt;table style=&quot;border-collapse: collapse; margin: 10px 0;&quot;&gt;
                            &lt;tr style=&quot;background-color: #e0e0e0;&quot;&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;Basic&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₁&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;s₂&lt;/th&gt;
                                &lt;th style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;RHS&lt;/th&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #ccffcc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₂&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;2&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;-1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;2&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;x₁&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;-1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;2&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr style=&quot;background-color: #ccffcc;&quot;&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;z&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;0&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;1&lt;/td&gt;
                                &lt;td style=&quot;border: 1px solid #ccc; padding: 8px;&quot;&gt;10&lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                        &lt;div style=&quot;margin-top: 10px;&quot;&gt;
                            &lt;strong&gt;OPTIMAL SOLUTION FOUND!&lt;/strong&gt;&lt;br&gt;
                            x₁ = 2, x₂ = 2, Maximum objective value = 10&lt;br&gt;
                            All coefficients in the objective row are non-negative.
                        &lt;/div&gt;
                    `;
                    break;
            }
            
            tableauDiv.innerHTML = tableauHTML;
        }
        
        function updateStatus(step) {
            let statusHTML = &apos;&apos;;
            
            switch(step) {
                case 0:
                    statusHTML = `
                        &lt;div&gt;&lt;strong&gt;Step 0:&lt;/strong&gt; Initial basic feasible solution&lt;/div&gt;
                        &lt;div&gt;Current vertex: (0, 0)&lt;/div&gt;
                        &lt;div&gt;Current objective value: 0&lt;/div&gt;
                        &lt;div&gt;Basic variables: s₁ = 4, s₂ = 6&lt;/div&gt;
                    `;
                    currentVertex = [0, 0];
                    break;
                case 1:
                    statusHTML = `
                        &lt;div&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Choose entering variable&lt;/div&gt;
                        &lt;div&gt;Most negative coefficient: -3 (x₁ column)&lt;/div&gt;
                        &lt;div&gt;x₁ enters the basis&lt;/div&gt;
                        &lt;div&gt;Performing minimum ratio test...&lt;/div&gt;
                    `;
                    break;
                case 2:
                    statusHTML = `
                        &lt;div&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; First iteration complete&lt;/div&gt;
                        &lt;div&gt;Current vertex: (3, 0)&lt;/div&gt;
                        &lt;div&gt;Current objective value: 9&lt;/div&gt;
                        &lt;div&gt;Basic variables: x₁ = 3, s₁ = 1&lt;/div&gt;
                    `;
                    currentVertex = [3, 0];
                    break;
                case 3:
                    statusHTML = `
                        &lt;div&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; OPTIMAL SOLUTION FOUND!&lt;/div&gt;
                        &lt;div&gt;Current vertex: (2, 2)&lt;/div&gt;
                        &lt;div&gt;Maximum objective value: 10&lt;/div&gt;
                        &lt;div&gt;Basic variables: x₁ = 2, x₂ = 2&lt;/div&gt;
                    `;
                    currentVertex = [2, 2];
                    isOptimal = true;
                    break;
            }
            
            statusDiv.innerHTML = statusHTML;
            
            // Update visualization
            const currentPos = d3.select(&apos;#current-position&apos;);
            if (currentPos.node()) {
                const xScale = d3.scaleLinear().domain([0, 4]).range([40, 360]);
                const yScale = d3.scaleLinear().domain([0, 6]).range([260, 40]);
                
                currentPos
                    .transition()
                    .duration(500)
                    .attr(&apos;cx&apos;, xScale(currentVertex[0]))
                    .attr(&apos;cy&apos;, yScale(currentVertex[1]));
            }
        }
        
        function nextStep() {
            if (currentStep &lt; 3) {
                currentStep++;
                updateStatus(currentStep);
                updateTableau(currentStep);
                
                if (currentStep === 3) {
                    stepButton.textContent = &apos;Algorithm Complete!&apos;;
                    stepButton.disabled = true;
                    stepButton.style.backgroundColor = &apos;#4CAF50&apos;;
                }
            }
        }
        
        function reset() {
            currentStep = 0;
            currentVertex = [0, 0];
            isOptimal = false;
            
            stepButton.textContent = &apos;Next Step&apos;;
            stepButton.disabled = false;
            stepButton.style.backgroundColor = &apos;#2196F3&apos;;
            
            updateStatus(0);
            updateTableau(0);
            createVisualization();
        }
        
        // Event listeners
        stepButton.addEventListener(&apos;click&apos;, nextStep);
        resetButton.addEventListener(&apos;click&apos;, reset);
        
        // Initialize
        createVisualization();
        updateStatus(0);
        updateTableau(0);
    }
    
    // Initialize all interactive elements
    initializeFarmerProblem();
    initializeDietSolver();
    initializeSimplexVisualization();
    
    // Trigger MathJax re-rendering if needed
    if (window.MathJax) {
        MathJax.typesetPromise();
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>05-01-01 Linear Programming - Simplex Algorithm</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_01_01_LP_Simple_Algorithm/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_01_01_LP_Simple_Algorithm</id>
   <content type="html">&lt;p&gt;A high-dimensional polytope with 1,000 constraints can easily have more vertices than atoms in the observable universe—enumerating them all is impossible. Dantzig’s Simplex Algorithm solves this in breathtaking geometric style: instead of visiting every corner, it stands at one vertex, checks which adjacent edges slope strictly downhill, and walks along the polytope’s skeleton until every neighboring edge goes uphill.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-mechanics-of-the-simplex-method&quot;&gt;Key ideas: Mechanics of the Simplex Method&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Basic Feasible Solutions (BFS) = Vertices&lt;/strong&gt;: In standard form \(Ax = b, x \ge 0\) with \(A \in \mathbb{R}^{m \times n}\) of full row rank \(m\), partitioning columns into an invertible basis \(B\) (\(m\) columns) and nonbasic set \(N\) (\(n - m\) columns) sets \(x_N = 0\) and \(x_B = B^{-1}b\). Whenever \(x_B \ge 0\), this algebraic partition corresponds directly to a geometric vertex of the polyhedron.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reduced Costs as Edge Slopes&lt;/strong&gt;: Moving a single nonbasic variable \(x_j\) up from \(0\) forces \(x_B = B^{-1}b - B^{-1}A_j x_j\) and changes the objective at rate \(\bar{c}_j = c_j - c_B^T B^{-1} A_j\). If all \(\bar{c}_j \ge 0\), no feasible edge improves the objective and the current BFS is globally optimal.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimum-Ratio Test (Choosing the Leaving Variable)&lt;/strong&gt;: Once an entering variable \(x_j\) with \(\bar{c}_j &amp;lt; 0\) is chosen, we increase \(x_j\) as far as possible until the first basic variable hits zero: \(t^\star = \min_{i : d_i &amp;gt; 0} \frac{(x_B)_i}{d_i}\) where \(d = B^{-1}A_j\). If \(d \le 0\), the LP is unbounded below.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Degeneracy and Cycling&lt;/strong&gt;: If some basic variable already equals \(0\), a pivot can take step size \(t^\star = 0\) (changing the basis without moving in space). Bland’s rule—always picking the smallest-index entering and leaving variables—guarantees finite termination without cycling.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-executing-one-exact-simplex-pivot-by-hand&quot;&gt;Worked example: Executing One Exact Simplex Pivot by Hand&lt;/h3&gt;

&lt;p&gt;Minimize \(-3x_1 - 2x_2\) subject to \(x_1 + x_2 + s_1 = 4\), \(2x_1 + x_2 + s_2 = 6\), with \(x_1, x_2, s_1, s_2 \ge 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Start at the slack basis \(B = \{s_1, s_2\}\), \(N = \{x_1, x_2\}\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Here \(B = I_2\), \(c_B = (0, 0)^T\), so \(x_B = (s_1, s_2)^T = (4, 6)^T\) and objective \(z = 0\).&lt;/li&gt;
      &lt;li&gt;Reduced costs for \(N\): \(\bar{c}_1 = -3 - 0 = -3 &amp;lt; 0\), \(\bar{c}_2 = -2 - 0 = -2 &amp;lt; 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choose entering variable \(x_1\)&lt;/strong&gt; (most negative reduced cost, \(\bar{c}_1 = -3\)):
    &lt;ul&gt;
      &lt;li&gt;Direction vector: \(d = B^{-1} A_1 = (1, 2)^T\).&lt;/li&gt;
      &lt;li&gt;Minimum-ratio test: \(\min\left(\frac{4}{1}, \frac{6}{2}\right) = \min(4, 3) = 3\), attained by the second row (\(s_2\)).&lt;/li&gt;
      &lt;li&gt;Thus \(s_2\) leaves the basis and \(x_1\) enters at value \(x_1 = 3\), while \(s_1 = 4 - 1(3) = 1\) and \(z = -3(3) = -9\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute reduced costs at the new basis \(B = \{s_1, x_1\}\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Express basic variables in terms of nonbasic \(\{x_2, s_2\}\): from \(2x_1 + x_2 + s_2 = 6\), we get \(x_1 = 3 - \tfrac{1}{2}x_2 - \tfrac{1}{2}s_2\).&lt;/li&gt;
      &lt;li&gt;Substituting into the objective: \(z = -3\bigl(3 - \tfrac{1}{2}x_2 - \tfrac{1}{2}s_2\bigr) - 2x_2 = -9 - \tfrac{1}{2}x_2 + \tfrac{3}{2}s_2\).&lt;/li&gt;
      &lt;li&gt;The new reduced costs are \(\bar{c}_{x_2} = -\tfrac{1}{2} &amp;lt; 0\) and \(\bar{c}_{s_2} = +\tfrac{3}{2} &amp;gt; 0\), so one more pivot (bringing \(x_2\) in and \(s_1\) out) will reach the optimal vertex \((x_1, x_2) = (2, 2)\) with \(z^\star = -10\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;a href=&quot;/contents/en/chapter05/05_01_Linear_Programming_(LP)/&quot;&gt;linear program&lt;/a&gt; from the previous lesson has a polyhedral feasible set. A remarkable geometric fact makes LP special: &lt;strong&gt;if a finite optimum exists, at least one optimal point is a vertex&lt;/strong&gt;. The simplex algorithm walks from vertex to vertex, improving the objective, until no neighboring vertex is better.&lt;/p&gt;

&lt;p&gt;Interactive tableau: &lt;a href=&quot;https://github.com/nglelinh/interactive_math/blob/main/linear-programming/simplex_optimization_demo.html&quot;&gt;simplex demo&lt;/a&gt; in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nglelinh/interactive_math&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Key insight:&lt;/strong&gt; gradient methods wander through the interior. Simplex stays on the skeleton of the polyhedron and only evaluates corners. That is why a 1950s algorithm still solves many of the LPs behind blending, routing, and SVM duals.
&lt;/div&gt;

&lt;h2 id=&quot;standard-form&quot;&gt;Standard form&lt;/h2&gt;

&lt;p&gt;Most textbooks implement simplex on an equality form with nonnegative variables:&lt;/p&gt;

\[\begin{align}
\underset{x}{\text{minimize}} \quad &amp;amp; c^\top x \\
\text{subject to} \quad &amp;amp; Ax = b, \\
&amp;amp; x \succeq 0,
\end{align}\]

&lt;p&gt;where \(A \in \mathbb{R}^{m \times n}\) has full row rank \(m\), \(b \succeq 0\), and \(n &amp;gt; m\). Inequality constraints \(Gx \preceq h\) are converted by adding nonnegative &lt;strong&gt;slack&lt;/strong&gt; variables. Free variables are split as a difference of two nonnegative variables.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;basis&lt;/strong&gt; is a set of \(m\) linearly independent columns of \(A\). Write \(A = [A_B \; A_N]\) after permuting columns, and split \(x = (x_B, x_N)\). The corresponding &lt;strong&gt;basic solution&lt;/strong&gt; is&lt;/p&gt;

\[x_B = A_B^{-1} b, \qquad x_N = 0.\]

&lt;p&gt;If \(x_B \succeq 0\), the point is a &lt;strong&gt;basic feasible solution (BFS)&lt;/strong&gt; — geometrically, a vertex of the feasible polyhedron.&lt;/p&gt;

&lt;h2 id=&quot;reduced-costs-and-a-pivot&quot;&gt;Reduced costs and a pivot&lt;/h2&gt;

&lt;p&gt;From \(Ax = b\) we can eliminate the basic variables:&lt;/p&gt;

\[x_B = A_B^{-1}b - A_B^{-1}A_N x_N.\]

&lt;p&gt;Substitute into the objective:&lt;/p&gt;

\[c^\top x = c_B^\top A_B^{-1}b + \bar{c}_N^\top x_N, \qquad \bar{c}_N^\top := c_N^\top - c_B^\top A_B^{-1}A_N.\]

&lt;p&gt;The vector \(\bar{c}_N\) contains the &lt;strong&gt;reduced costs&lt;/strong&gt;. Because \(x_N \succeq 0\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;if \(\bar{c}_N \succeq 0\), no feasible increase of a nonbasic variable can decrease the objective — the BFS is &lt;strong&gt;optimal&lt;/strong&gt;;&lt;/li&gt;
  &lt;li&gt;if some \(\bar{c}_j &amp;lt; 0\), we may increase that nonbasic coordinate (it &lt;strong&gt;enters&lt;/strong&gt; the basis) and drive one basic variable to zero (it &lt;strong&gt;leaves&lt;/strong&gt;). The ratio test picks the leaving index so that \(x_B\) stays nonnegative.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One such exchange is a &lt;strong&gt;pivot&lt;/strong&gt;. After a finite number of pivots (assuming a rule that prevents cycling, e.g. Bland’s rule), simplex either reports optimality or detects an unbounded ray (\(Ax = 0\), \(x \succeq 0\), \(c^\top x &amp;lt; 0\)).&lt;/p&gt;

&lt;h2 id=&quot;a-two-variable-walk-through&quot;&gt;A two-variable walk-through&lt;/h2&gt;

&lt;p&gt;Maximize \(3x_1 + 2x_2\) (equivalently minimize \(-3x_1-2x_2\)) subject to&lt;/p&gt;

\[\begin{align}
x_1 + x_2 &amp;amp;\le 4, \\
2x_1 + x_2 &amp;amp;\le 6, \\
x_1, x_2 &amp;amp;\ge 0.
\end{align}\]

&lt;p&gt;Vertices of the feasible polygon are \((0,0)\), \((3,0)\), \((2,2)\), and \((0,4)\). Objective values: \(0\), \(9\), \(10\), \(8\). Simplex can start at the origin and pivot to \((3,0)\) then \((2,2)\), where both reduced costs are nonnegative. The same conclusion is immediate from the figure: the level lines of \(3x_1+2x_2\) last touch the polygon at \((2,2)\).&lt;/p&gt;

&lt;h2 id=&quot;why-we-still-teach-it-in-a-data-science-course&quot;&gt;Why we still teach it in a data-science course&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Modeling check.&lt;/strong&gt; If you can put a problem in LP standard form, you already know it is convex and that a vertex solution exists.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duality preview.&lt;/strong&gt; Reduced costs are dual slacks. Complementary slackness in &lt;a href=&quot;/contents/en/chapter12/12_00_KKT_conditions/&quot;&gt;Chapter 12&lt;/a&gt; is the optimality certificate simplex is hunting.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solvers.&lt;/strong&gt; Production codes (HiGHS, Gurobi, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.optimize.linprog&lt;/code&gt;) use revised simplex and/or interior-point methods. You will rarely code a tableau, but you should recognize an infeasible vs unbounded return.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Complexity note.&lt;/strong&gt; Klee–Minty cubes show that some pivot rules take exponentially many steps in the worst case. In practice, simplex is often fast; interior-point methods (Chapters 15–17) have polynomial worst-case guarantees and dominate some large sparse LPs. For data-science models that are &lt;em&gt;already&lt;/em&gt; LPs or QPs — diet problems, maximum-margin SVM duals, basis pursuit — you typically call a modeling layer such as CVXPY (see the DCP lab in this chapter) rather than pivoting by hand.&lt;/p&gt;

&lt;h3 id=&quot;the-simplex-method-in-about-3-minutes&quot;&gt;The simplex method in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/simplex-pivots_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Walking the vertices of the lesson’s LP: entering variable, ratio test, pivots, the dual solution, and an unbounded problem.&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Convert \(x_1 - x_2 \le 3\), \(x_1 \ge 0\), \(x_2\) free into standard form.&lt;/li&gt;
  &lt;li&gt;Starting from \((0,0)\) in the example above, compute the first entering variable if you always pick the most negative reduced cost.&lt;/li&gt;
  &lt;li&gt;Give a 2-D LP that is feasible and unbounded, and explain how the ratio test fails.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Further reading: Boyd &amp;amp; Vandenberghe, Appendix B; Nocedal &amp;amp; Wright, Ch. 13; the CMU canonical-problems notes linked from the &lt;a href=&quot;/&quot;&gt;README&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>05 Canonical Problems</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_00_Canonical_Problems/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter05/05_00_Canonical_Problems</id>
   <content type="html">&lt;p&gt;Walk into an ER with a broken wrist and the triage doctor immediately classifies the fracture before ordering a cast—different injuries need different instruments. Convex optimization works the same way: instead of writing a bespoke algorithm for every new problem, practitioners classify models into a nested hierarchy of &lt;em&gt;canonical forms&lt;/em&gt;—LP, QP, QCQP, SOCP, SDP, and general Conic Programs—each matched to battle-tested, polynomial-time solvers.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-nested-hierarchy-of-convex-programs&quot;&gt;Key ideas: The Nested Hierarchy of Convex Programs&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;The Russian-Doll Inclusion Chain&lt;/strong&gt;: Every Linear Program (LP) is a special case of a Quadratic Program (QP), which is a special case of a Quadratically Constrained Quadratic Program (QCQP), which embeds into a Second-Order Cone Program (SOCP), which embeds into a Semidefinite Program (SDP), all unified under Conic Programming (CP): \(\mathrm{LP} \subset \mathrm{QP} \subset \mathrm{QCQP} \subset \mathrm{SOCP} \subset \mathrm{SDP} \subset \mathrm{CP}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Expressiveness vs. Computational Cost&lt;/strong&gt;: Moving rightward in the hierarchy lets you model richer geometry (polyhedra \(\to\) ellipsoids \(\to\) Lorentz ice-cream cones \(\to\) positive semidefinite matrices), at the price of heavier per-iteration linear algebra. Choosing the &lt;em&gt;simplest&lt;/em&gt; canonical class that captures your problem can mean a 100× speedup.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solver Specialization&lt;/strong&gt;: LP and QP solvers exploit sparse linear factorizations and active-set/simplex warm starts; SOCP and SDP solvers use primal–dual interior-point methods over self-concordant cone barriers (such as Clarabel, ECOS, or MOSEK).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Canonicalization Bridges Modeling and Solving&lt;/strong&gt;: Modeling frameworks like CVXPY automatically rewrite high-level mathematical expressions (like \(\|Ax - b\|_2 + \lambda\|x\|_1\)) into one of these standard cone classes so the user never has to hand-code barrier derivatives.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-classifying-one-engineering-model-across-the-hierarchy&quot;&gt;Worked example: Classifying One Engineering Model Across the Hierarchy&lt;/h3&gt;

&lt;p&gt;Suppose a portfolio manager chooses asset weights \(x \in \mathbb{R}^2\) satisfying \(x_1 + x_2 = 1\) and \(x_1, x_2 \ge 0\), with expected return vector \(\mu = (0.08, 0.05)^T\) and covariance matrix \(\Sigma = \begin{bmatrix} 0.04 &amp;amp; 0.01 \\ 0.01 &amp;amp; 0.02 \end{bmatrix}\). Watch how changing a single risk term shifts the canonical class:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Linear objective only (LP)&lt;/strong&gt;: Maximizing expected return \(\min_x -\mu^T x\) subject to \(x_1 + x_2 = 1, x \ge 0\) has a linear objective and linear constraints. Optimal vertex: \(x^\star = (1, 0)\) with return \(8\%\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adding variance penalty (QP)&lt;/strong&gt;: Minimizing \(\frac{1}{2}x^T \Sigma x - \mu^T x\) keeps linear constraints and adds a convex quadratic objective (\(\Sigma \succ 0\) since \(0.04 &amp;gt; 0\) and \(\det \Sigma = 0.0008 - 0.0001 = 0.0007 &amp;gt; 0\)). This is a &lt;strong&gt;QP&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Capping portfolio variance (QCQP / SOCP)&lt;/strong&gt;: Requiring \(x^T \Sigma x \le 0.0225\) while maximizing \(\mu^T x\) adds a convex quadratic inequality (&lt;strong&gt;QCQP&lt;/strong&gt;). Factoring \(\Sigma = L L^T\) rewrites it as \(\|L^T x\|_2 \le 0.15\), a &lt;strong&gt;Second-Order Cone (SOCP)&lt;/strong&gt; constraint.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Testing a specific point&lt;/strong&gt;: At \(x = (0.5, 0.5)\), expected return is \(0.5(0.08) + 0.5(0.05) = 0.065\) and variance is \(0.25(0.04) + 2(0.25)(0.01) + 0.25(0.02) = 0.01 + 0.005 + 0.005 = 0.020 \le 0.0225\), confirming feasibility for the QCQP/SOCP risk cap.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;canonical-problems&quot;&gt;Canonical Problems&lt;/h1&gt;

&lt;p&gt;In &lt;a href=&quot;/chapter01/2021/01/07/optimization_problems/&quot;&gt;Chapter 1&lt;/a&gt;, we learned that a convex optimization problem is defined as follows:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter05/05_00_optimization_problem.png&quot; alt=&quot;[Fig1] Convex Optimization Problem in standard form [3]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Convex Optimization Problem in standard form [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;The domain set is convex&lt;/li&gt;
  &lt;li&gt;The objective function \(f\) and the inequality constraint function \(g_i\) are convex&lt;/li&gt;
  &lt;li&gt;The equality constraint function \(h_j\) is affine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Depending on the type of objective and constraint functions, optimization problems are classified into several categories. In this chapter, we will learn about six major subclasses:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Linear Programming (LP)&lt;/li&gt;
  &lt;li&gt;Quadratic Programming (QP)&lt;/li&gt;
  &lt;li&gt;Quadratically Constrained Quadratic Programming (QCQP)&lt;/li&gt;
  &lt;li&gt;Second-Order Cone Programming (SOCP)&lt;/li&gt;
  &lt;li&gt;Semidefinite Programming (SDP)&lt;/li&gt;
  &lt;li&gt;Conic Programming (CP)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These problems have the following inclusion relationships and become more general as you move down the list:&lt;/p&gt;

&lt;p&gt;\(LP \subseteq QP \subseteq QCQP \subseteq SOCP \subseteq SDP \subseteq CP\)&lt;/p&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter05/05_00_canonical_problems.jpeg&quot; alt=&quot;[Fig2] Canonical Problems&quot; width=&quot;90%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Canonical Problems&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;After the taxonomy and the DCP lab, the optional &lt;a href=&quot;/contents/en/chapter05/05_08_Applications_Recent/&quot;&gt;05-08 Applications and recent developments&lt;/a&gt; points at Clarabel, portfolio QPs, SDP verification, and unrolled sparse recovery.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01-05 Hyperplane</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_05_Hyperplane/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_05_Hyperplane</id>
   <content type="html">&lt;p&gt;Every linear classifier—from perceptrons and logistic regression to support vector machines—draws a single flat boundary across \(\mathbb{R}^n\) to slice positive examples from negative ones. That boundary is a &lt;strong&gt;hyperplane&lt;/strong&gt; \(\{x : a^T x = b\}\). Because its normal vector \(a\) points perpendicularly off the flat, computing signed margins, Euclidean projections, and linear constraint violations reduces to a single inner product.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-a-hyperplane&quot;&gt;Key ideas: Anatomy of a Hyperplane&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Normal-Offset Representation (\(a^T x = b, \; a \neq 0\)):&lt;/strong&gt; The vector \(a\) sets the orientation (orthogonal to every vector lying inside the hyperplane), and \(b / \|a\|_2\) sets the signed shift from the origin.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Point-Normal Form (\(a^T(x - x_0) = 0\)):&lt;/strong&gt; Rewrites the hyperplane explicitly as \(x_0 + a^\perp\), showing immediately that every hyperplane is an affine set of dimension \(n - 1\) (codimension 1).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Signed Distance &amp;amp; Orthogonal Projection:&lt;/strong&gt; The Euclidean distance from any point \(x_0\) to \(H\) is $$\frac{&lt;/td&gt;
          &lt;td&gt;a^T x_0 - b&lt;/td&gt;
          &lt;td&gt;}{|a|_2}\(, and the closest point on\)H\(is\)x_p = x_0 - \frac{a^T x_0 - b}{|a|_2^2}a$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Boundary Between Halfspaces:&lt;/strong&gt; Every hyperplane partitions \(\mathbb{R}^n\) into two closed convex halfspaces, \(a^T x \le b\) and \(a^T x \ge b\)—the atomic ingredients of linear programming and SVM margins.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-exact-distance-and-projection-onto-a-hyperplane&quot;&gt;Worked example: Exact Distance and Projection onto a Hyperplane&lt;/h3&gt;

&lt;p&gt;Find the Euclidean distance from \(x_0 = (3, 4)^T\) to the hyperplane \(H = \{x \in \mathbb{R}^2 : 3x_1 + 4x_2 = 10\}\), and compute its orthogonal projection \(x_p \in H\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Extract normal \(a\) and norm \(\|a\|_2\):&lt;/strong&gt;
\(a = \begin{pmatrix} 3 \\ 4 \end{pmatrix}, \qquad b = 10, \qquad \|a\|_2 = \sqrt{3^2 + 4^2} = 5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the residual and Euclidean distance:&lt;/strong&gt;
\(a^T x_0 - b = 3(3) + 4(4) - 10 = 9 + 16 - 10 = 15 \implies \text{dist}(x_0, H) = \frac{|15|}{5} = 3.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the orthogonal projection \(x_p\):&lt;/strong&gt;
\(x_p = x_0 - \frac{a^T x_0 - b}{\|a\|_2^2} a = \begin{pmatrix} 3 \\ 4 \end{pmatrix} - \frac{15}{25}\begin{pmatrix} 3 \\ 4 \end{pmatrix} = \frac{2}{5}\begin{pmatrix} 3 \\ 4 \end{pmatrix} = \begin{pmatrix} 1.2 \\ 1.6 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify both membership and distance:&lt;/strong&gt; \(3(1.2) + 4(1.6) = 3.6 + 6.4 = 10\) (so \(x_p \in H\)), and \(\|x_0 - x_p\|_2 = \|(1.8, 2.4)^T\|_2 = \sqrt{3.24 + 5.76} = \sqrt{9} = 3\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A hyperplane is one of the most fundamental geometric objects in convex optimization and linear algebra. It serves as a building block for understanding more complex convex sets and plays a crucial role in optimization algorithms, machine learning, and geometric analysis.&lt;/p&gt;

&lt;h2 id=&quot;definition-of-hyperplane&quot;&gt;Definition of Hyperplane&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;hyperplane&lt;/strong&gt; in \(\mathbb{R}^n\) is a set of the form:&lt;/p&gt;

&lt;blockquote&gt;
\[\mathcal{H} = \{x \in \mathbb{R}^n : a^T x = b\}\]
&lt;/blockquote&gt;

&lt;p&gt;where \(a \in \mathbb{R}^n\) is a nonzero vector (\(a \neq 0\)) and \(b \in \mathbb{R}\) is a scalar.&lt;/p&gt;

&lt;p&gt;The vector \(a\) is called the &lt;strong&gt;normal vector&lt;/strong&gt; to the hyperplane, and it determines the orientation of the hyperplane. The scalar \(b\) determines the position of the hyperplane relative to the origin.&lt;/p&gt;

&lt;h3 id=&quot;geometric-interpretation&quot;&gt;Geometric Interpretation&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;In \(\mathbb{R}^2\): A hyperplane is a &lt;strong&gt;line&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;In \(\mathbb{R}^3\): A hyperplane is a &lt;strong&gt;plane&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;In \(\mathbb{R}^n\) (\(n &amp;gt; 3\)): A hyperplane is an \((n-1)\)-dimensional subspace&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The hyperplane divides the entire space \(\mathbb{R}^n\) into two &lt;strong&gt;halfspaces&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Positive halfspace&lt;/strong&gt;: \(\{x : a^T x \geq b\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Negative halfspace&lt;/strong&gt;: \(\{x : a^T x \leq b\}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;properties-of-hyperplanes&quot;&gt;Properties of Hyperplanes&lt;/h2&gt;

&lt;h3 id=&quot;1-affine-set-property&quot;&gt;1. Affine Set Property&lt;/h3&gt;
&lt;p&gt;Every hyperplane is an &lt;strong&gt;affine set&lt;/strong&gt;. This means that if \(x_1, x_2 \in \mathcal{H}\), then the entire line passing through them is also contained in \(\mathcal{H}\):&lt;/p&gt;

\[\theta x_1 + (1-\theta) x_2 \in \mathcal{H} \quad \forall \theta \in \mathbb{R}\]

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof&lt;/strong&gt;: If \(a^T x_1 = b\) and \(a^T x_2 = b\), then:
\(a^T(\theta x_1 + (1-\theta) x_2) = \theta a^T x_1 + (1-\theta) a^T x_2 = \theta b + (1-\theta) b = b\)&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;2-convex-set-property&quot;&gt;2. Convex Set Property&lt;/h3&gt;
&lt;p&gt;Since every affine set is convex, hyperplanes are &lt;strong&gt;convex sets&lt;/strong&gt;. For any \(x_1, x_2 \in \mathcal{H}\) and \(\lambda \in [0,1]\):&lt;/p&gt;

\[\lambda x_1 + (1-\lambda) x_2 \in \mathcal{H}\]

&lt;h3 id=&quot;3-closed-set-property&quot;&gt;3. Closed Set Property&lt;/h3&gt;
&lt;p&gt;Hyperplanes are &lt;strong&gt;closed sets&lt;/strong&gt; because they are the level sets of continuous linear functions.&lt;/p&gt;

&lt;h3 id=&quot;4-dimension&quot;&gt;4. Dimension&lt;/h3&gt;
&lt;p&gt;A hyperplane in \(\mathbb{R}^n\) has dimension \(n-1\).&lt;/p&gt;

&lt;h2 id=&quot;alternative-representations&quot;&gt;Alternative Representations&lt;/h2&gt;

&lt;h3 id=&quot;1-point-normal-form&quot;&gt;1. Point-Normal Form&lt;/h3&gt;
&lt;p&gt;If we know a point \(x_0\) on the hyperplane and the normal vector \(a\), the hyperplane can be written as:&lt;/p&gt;

\[\mathcal{H} = \{x : a^T (x - x_0) = 0\}\]

&lt;p&gt;This is equivalent to \(a^T x = a^T x_0\), so \(b = a^T x_0\).&lt;/p&gt;

&lt;h3 id=&quot;2-matrix-form&quot;&gt;2. Matrix Form&lt;/h3&gt;
&lt;p&gt;A hyperplane can also be represented using matrix notation. If \(A\) is a \(1 \times n\) matrix (row vector), then:&lt;/p&gt;

\[\mathcal{H} = \{x : Ax = b\}\]

&lt;h3 id=&quot;3-parametric-form&quot;&gt;3. Parametric Form&lt;/h3&gt;
&lt;p&gt;A hyperplane can be parameterized using a basis for its null space. If \(\{v_1, v_2, \ldots, v_{n-1}\}\) is an orthonormal basis for the null space of \(a^T\), and \(x_0\) is any point on the hyperplane, then:&lt;/p&gt;

\[\mathcal{H} = \{x_0 + t_1 v_1 + t_2 v_2 + \cdots + t_{n-1} v_{n-1} : t_i \in \mathbb{R}\}\]

&lt;h2 id=&quot;distance-from-point-to-hyperplane&quot;&gt;Distance from Point to Hyperplane&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;distance&lt;/strong&gt; from a point \(x_0\) to the hyperplane \(\{x : a^T x = b\}\) is given by:&lt;/p&gt;

\[d(x_0, \mathcal{H}) = \frac{\lvert a^T x_0 - b \rvert}{\lVert a \rVert_2}\]

&lt;p&gt;This formula comes from projecting the vector from any point on the hyperplane to \(x_0\) onto the normal direction.&lt;/p&gt;

&lt;h3 id=&quot;derivation&quot;&gt;Derivation&lt;/h3&gt;
&lt;p&gt;Let \(x^*\) be the closest point on the hyperplane to \(x_0\). Then \(x^* - x_0\) is parallel to the normal vector \(a\):&lt;/p&gt;

\[x^* - x_0 = t \frac{a}{\lVert a \rVert_2}\]

&lt;p&gt;Since \(x^* \in \mathcal{H}\), we have \(a^T x^* = b\). Substituting:&lt;/p&gt;

\[a^T \left(x_0 + t \frac{a}{\lVert a \rVert_2}\right) = b\]

&lt;p&gt;Solving for \(t\): \(t = \frac{b - a^T x_0}{\lVert a \rVert_2}\)&lt;/p&gt;

&lt;p&gt;The distance is \(\lvert t \rvert = \frac{\lvert a^T x_0 - b \rvert}{\lVert a \rVert_2}\).&lt;/p&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;h3 id=&quot;example-1-line-in-mathbbr2&quot;&gt;Example 1: Line in \(\mathbb{R}^2\)&lt;/h3&gt;
&lt;p&gt;The hyperplane \(2x_1 + 3x_2 = 6\) represents a line in the plane.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Normal vector: \(a = (2, 3)\)&lt;/li&gt;
  &lt;li&gt;The line passes through points \((3, 0)\) and \((0, 2)\)&lt;/li&gt;
  &lt;li&gt;Distance from origin: \(\frac{\lvert 2 \cdot 0 + 3 \cdot 0 - 6 \rvert}{\sqrt{2^2 + 3^2}} = \frac{6}{\sqrt{13}}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example-2-plane-in-mathbbr3&quot;&gt;Example 2: Plane in \(\mathbb{R}^3\)&lt;/h3&gt;
&lt;p&gt;The hyperplane \(x_1 - 2x_2 + x_3 = 4\) represents a plane in 3D space.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Normal vector: \(a = (1, -2, 1)\)&lt;/li&gt;
  &lt;li&gt;The plane passes through points \((4, 0, 0)\), \((0, -2, 0)\), and \((0, 0, 4)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example-3-hyperplane-through-origin&quot;&gt;Example 3: Hyperplane through Origin&lt;/h3&gt;
&lt;p&gt;The hyperplane \(a^T x = 0\) always passes through the origin and is actually a &lt;strong&gt;subspace&lt;/strong&gt; of dimension \(n-1\).&lt;/p&gt;

&lt;h2 id=&quot;interactive-visualization&quot;&gt;Interactive Visualization&lt;/h2&gt;

&lt;div id=&quot;hyperplane-container&quot; style=&quot;width: 100%; max-width: 800px; margin: 20px auto;&quot;&gt;
    &lt;div id=&quot;controls&quot; style=&quot;margin-bottom: 20px; text-align: center;&quot;&gt;
        &lt;label&gt;Normal vector a₁: &lt;input type=&quot;range&quot; id=&quot;a1-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;&lt;/label&gt;
        &lt;span id=&quot;a1-value&quot;&gt;1.0&lt;/span&gt;&lt;br /&gt;
        &lt;label&gt;Normal vector a₂: &lt;input type=&quot;range&quot; id=&quot;a2-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1&quot; /&gt;&lt;/label&gt;
        &lt;span id=&quot;a2-value&quot;&gt;1.0&lt;/span&gt;&lt;br /&gt;
        &lt;label&gt;Offset b: &lt;input type=&quot;range&quot; id=&quot;b-slider&quot; min=&quot;-5&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;0&quot; /&gt;&lt;/label&gt;
        &lt;span id=&quot;b-value&quot;&gt;0.0&lt;/span&gt;&lt;br /&gt;
        &lt;button id=&quot;reset-btn&quot;&gt;Reset&lt;/button&gt;
    &lt;/div&gt;
    &lt;canvas id=&quot;hyperplane-canvas&quot; width=&quot;600&quot; height=&quot;400&quot; style=&quot;border: 1px solid #ccc; display: block; margin: 0 auto;&quot;&gt;&lt;/canvas&gt;
    &lt;div id=&quot;info&quot; style=&quot;text-align: center; margin-top: 10px; font-family: monospace;&quot;&gt;
        &lt;p&gt;Hyperplane equation: &lt;span id=&quot;equation&quot;&gt;x₁ + x₂ = 0&lt;/span&gt;&lt;/p&gt;
        &lt;p&gt;Distance from origin: &lt;span id=&quot;distance&quot;&gt;0.0&lt;/span&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
class HyperplaneVisualizer {
    constructor() {
        this.canvas = document.getElementById(&apos;hyperplane-canvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        // Parameters
        this.a1 = 1;
        this.a2 = 1;
        this.b = 0;
        
        // Scale and offset for coordinate system
        this.scale = 40;
        this.centerX = this.width / 2;
        this.centerY = this.height / 2;
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const a1Slider = document.getElementById(&apos;a1-slider&apos;);
        const a2Slider = document.getElementById(&apos;a2-slider&apos;);
        const bSlider = document.getElementById(&apos;b-slider&apos;);
        const resetBtn = document.getElementById(&apos;reset-btn&apos;);
        
        a1Slider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.a1 = parseFloat(e.target.value);
            document.getElementById(&apos;a1-value&apos;).textContent = this.a1.toFixed(1);
            this.updateDisplay();
        });
        
        a2Slider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.a2 = parseFloat(e.target.value);
            document.getElementById(&apos;a2-value&apos;).textContent = this.a2.toFixed(1);
            this.updateDisplay();
        });
        
        bSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.b = parseFloat(e.target.value);
            document.getElementById(&apos;b-value&apos;).textContent = this.b.toFixed(1);
            this.updateDisplay();
        });
        
        resetBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.a1 = 1;
            this.a2 = 1;
            this.b = 0;
            a1Slider.value = 1;
            a2Slider.value = 1;
            bSlider.value = 0;
            document.getElementById(&apos;a1-value&apos;).textContent = &apos;1.0&apos;;
            document.getElementById(&apos;a2-value&apos;).textContent = &apos;1.0&apos;;
            document.getElementById(&apos;b-value&apos;).textContent = &apos;0.0&apos;;
            this.updateDisplay();
        });
    }
    
    updateDisplay() {
        this.draw();
        this.updateInfo();
    }
    
    updateInfo() {
        // Update equation
        const eq = `${this.a1.toFixed(1)}x₁ + ${this.a2.toFixed(1)}x₂ = ${this.b.toFixed(1)}`;
        document.getElementById(&apos;equation&apos;).textContent = eq;
        
        // Update distance from origin
        const distance = Math.abs(this.b) / Math.sqrt(this.a1 * this.a1 + this.a2 * this.a2);
        document.getElementById(&apos;distance&apos;).textContent = distance.toFixed(3);
    }
    
    worldToScreen(x, y) {
        return {
            x: this.centerX + x * this.scale,
            y: this.centerY - y * this.scale
        };
    }
    
    draw() {
        // Clear canvas
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        // Draw coordinate system
        this.drawCoordinateSystem();
        
        // Draw hyperplane (line in 2D)
        this.drawHyperplane();
        
        // Draw normal vector
        this.drawNormalVector();
        
        // Draw distance from origin
        this.drawDistanceFromOrigin();
    }
    
    drawCoordinateSystem() {
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        
        // Grid lines
        for (let i = -10; i &lt;= 10; i++) {
            if (i === 0) continue;
            
            // Vertical lines
            const x = this.centerX + i * this.scale;
            this.ctx.beginPath();
            this.ctx.moveTo(x, 0);
            this.ctx.lineTo(x, this.height);
            this.ctx.stroke();
            
            // Horizontal lines
            const y = this.centerY + i * this.scale;
            this.ctx.beginPath();
            this.ctx.moveTo(0, y);
            this.ctx.lineTo(this.width, y);
            this.ctx.stroke();
        }
        
        // Axes
        this.ctx.strokeStyle = &apos;#666&apos;;
        this.ctx.lineWidth = 2;
        
        // X-axis
        this.ctx.beginPath();
        this.ctx.moveTo(0, this.centerY);
        this.ctx.lineTo(this.width, this.centerY);
        this.ctx.stroke();
        
        // Y-axis
        this.ctx.beginPath();
        this.ctx.moveTo(this.centerX, 0);
        this.ctx.lineTo(this.centerX, this.height);
        this.ctx.stroke();
        
        // Labels
        this.ctx.fillStyle = &apos;#666&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.fillText(&apos;x₁&apos;, this.width - 20, this.centerY - 10);
        this.ctx.fillText(&apos;x₂&apos;, this.centerX + 10, 15);
    }
    
    drawHyperplane() {
        if (Math.abs(this.a1) &lt; 1e-10 &amp;&amp; Math.abs(this.a2) &lt; 1e-10) return;
        
        this.ctx.strokeStyle = &apos;#2196F3&apos;;
        this.ctx.lineWidth = 3;
        
        // Find two points on the line a1*x1 + a2*x2 = b
        let x1_start, y1_start, x1_end, y1_end;
        
        if (Math.abs(this.a2) &gt; 1e-10) {
            // Line is not vertical
            x1_start = -10;
            y1_start = (this.b - this.a1 * x1_start) / this.a2;
            x1_end = 10;
            y1_end = (this.b - this.a1 * x1_end) / this.a2;
        } else {
            // Line is vertical
            x1_start = x1_end = this.b / this.a1;
            y1_start = -10;
            y1_end = 10;
        }
        
        const start = this.worldToScreen(x1_start, y1_start);
        const end = this.worldToScreen(x1_end, y1_end);
        
        this.ctx.beginPath();
        this.ctx.moveTo(start.x, start.y);
        this.ctx.lineTo(end.x, end.y);
        this.ctx.stroke();
        
        // Label
        const midX = (start.x + end.x) / 2;
        const midY = (start.y + end.y) / 2;
        this.ctx.fillStyle = &apos;#2196F3&apos;;
        this.ctx.font = &apos;bold 14px Arial&apos;;
        this.ctx.fillText(&apos;Hyperplane&apos;, midX + 10, midY - 10);
    }
    
    drawNormalVector() {
        if (Math.abs(this.a1) &lt; 1e-10 &amp;&amp; Math.abs(this.a2) &lt; 1e-10) return;
        
        // Normalize the normal vector for display
        const norm = Math.sqrt(this.a1 * this.a1 + this.a2 * this.a2);
        const na1 = this.a1 / norm;
        const na2 = this.a2 / norm;
        
        // Find a point on the hyperplane closest to origin
        const t = this.b / (this.a1 * this.a1 + this.a2 * this.a2);
        const px = t * this.a1;
        const py = t * this.a2;
        
        const startPoint = this.worldToScreen(px, py);
        const endPoint = this.worldToScreen(px + na1 * 2, py + na2 * 2);
        
        // Draw normal vector
        this.ctx.strokeStyle = &apos;#FF5722&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        this.ctx.moveTo(startPoint.x, startPoint.y);
        this.ctx.lineTo(endPoint.x, endPoint.y);
        this.ctx.stroke();
        
        // Draw arrowhead
        const angle = Math.atan2(endPoint.y - startPoint.y, endPoint.x - startPoint.x);
        const arrowLength = 10;
        this.ctx.beginPath();
        this.ctx.moveTo(endPoint.x, endPoint.y);
        this.ctx.lineTo(
            endPoint.x - arrowLength * Math.cos(angle - Math.PI / 6),
            endPoint.y - arrowLength * Math.sin(angle - Math.PI / 6)
        );
        this.ctx.moveTo(endPoint.x, endPoint.y);
        this.ctx.lineTo(
            endPoint.x - arrowLength * Math.cos(angle + Math.PI / 6),
            endPoint.y - arrowLength * Math.sin(angle + Math.PI / 6)
        );
        this.ctx.stroke();
        
        // Label
        this.ctx.fillStyle = &apos;#FF5722&apos;;
        this.ctx.font = &apos;bold 12px Arial&apos;;
        this.ctx.fillText(&apos;Normal vector a&apos;, endPoint.x + 5, endPoint.y - 5);
    }
    
    drawDistanceFromOrigin() {
        if (Math.abs(this.a1) &lt; 1e-10 &amp;&amp; Math.abs(this.a2) &lt; 1e-10) return;
        
        // Find closest point on hyperplane to origin
        const t = this.b / (this.a1 * this.a1 + this.a2 * this.a2);
        const px = t * this.a1;
        const py = t * this.a2;
        
        const origin = this.worldToScreen(0, 0);
        const closestPoint = this.worldToScreen(px, py);
        
        // Draw distance line
        this.ctx.strokeStyle = &apos;#4CAF50&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.setLineDash([5, 5]);
        this.ctx.beginPath();
        this.ctx.moveTo(origin.x, origin.y);
        this.ctx.lineTo(closestPoint.x, closestPoint.y);
        this.ctx.stroke();
        this.ctx.setLineDash([]);
        
        // Draw origin point
        this.ctx.fillStyle = &apos;#4CAF50&apos;;
        this.ctx.beginPath();
        this.ctx.arc(origin.x, origin.y, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Draw closest point
        this.ctx.beginPath();
        this.ctx.arc(closestPoint.x, closestPoint.y, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Label
        const midX = (origin.x + closestPoint.x) / 2;
        const midY = (origin.y + closestPoint.y) / 2;
        this.ctx.fillStyle = &apos;#4CAF50&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.fillText(&apos;Distance&apos;, midX + 5, midY + 5);
    }
}

// Initialize visualization when page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    new HyperplaneVisualizer();
});
&lt;/script&gt;

&lt;h2 id=&quot;relationship-to-other-concepts&quot;&gt;Relationship to Other Concepts&lt;/h2&gt;

&lt;h3 id=&quot;connection-to-affine-sets&quot;&gt;Connection to Affine Sets&lt;/h3&gt;
&lt;p&gt;Every hyperplane is an affine set, but not every affine set is a hyperplane. Hyperplanes are specifically \((n-1)\)-dimensional affine sets in \(\mathbb{R}^n\).&lt;/p&gt;

&lt;h3 id=&quot;connection-to-linear-algebra&quot;&gt;Connection to Linear Algebra&lt;/h3&gt;
&lt;p&gt;The hyperplane \(\{x : a^T x = b\}\) is the &lt;strong&gt;level set&lt;/strong&gt; of the linear function \(f(x) = a^T x\) at level \(b\). The gradient of this function is constant and equal to \(a\), which explains why \(a\) is perpendicular to the hyperplane.&lt;/p&gt;

&lt;h3 id=&quot;connection-to-optimization&quot;&gt;Connection to Optimization&lt;/h3&gt;
&lt;p&gt;In constrained optimization, equality constraints often define hyperplanes that restrict the feasible region. The method of Lagrange multipliers exploits the fact that at an optimal point, the gradient of the objective function is parallel to the normal vector of the constraint hyperplane.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01-04 Cone</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_04_Convex_cone/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_04_Convex_cone</id>
   <content type="html">&lt;p&gt;Modern conic solvers (such as MOSEK, ECOS, and SCS) solve linear programs, second-order cone programs, and semidefinite programs using a &lt;em&gt;single&lt;/em&gt; unified framework: minimizing a linear objective over the intersection of an affine subspace and a &lt;strong&gt;convex cone&lt;/strong&gt;. Understanding why a set can be a cone without being convex—and why adding closure under addition turns any cone into a convex cone—unlocks the architecture of modern conic optimization.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-cones-convex-cones-and-conic-hulls&quot;&gt;Key ideas: Cones, Convex Cones, and Conic Hulls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cone (Scale Invariance):&lt;/strong&gt; \(C\) is a cone if \(x \in C \implies \theta x \in C\) for all \(\theta \ge 0\)—every point brings its entire positive ray from the origin along with it.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Cone (Ray + Sum Closure):&lt;/strong&gt; A cone is convex if and only if \(x_1, x_2 \in C \implies \theta_1 x_1 + \theta_2 x_2 \in C\) for all \(\theta_1, \theta_2 \ge 0\) (equivalently, closed under nonnegative scaling and vector addition).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic Hull (\(\text{cone}(S)\)):&lt;/strong&gt; The smallest convex cone containing \(S\), formed by all nonnegative linear combinations \(\sum \theta_i x_i\) (\(\theta_i \ge 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Cones Matter:&lt;/strong&gt; Conic constraints \(\mathbb{R}_+^n\) (LP), second-order cones (SOCP), and positive semidefinite cones (SDP) cover virtually all tractable convex optimization models in engineering and machine learning.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-a-cone-that-fails-to-be-convex&quot;&gt;Worked example: A Cone That Fails to Be Convex&lt;/h3&gt;

&lt;p&gt;Compare two cones in \(\mathbb{R}^2\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(K_1 = \{(x_1, x_2) : x_1 \ge 0,\; x_2 \ge 0\}\) (first quadrant).&lt;/li&gt;
  &lt;li&gt;\(K_2 = \{(x_1, x_2) : x_1 x_2 \ge 0\}\) (union of first and third quadrants).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Verify both are cones:&lt;/strong&gt; For any \(\theta \ge 0\) and \((x_1, x_2) \in K_2\), \((\theta x_1)(\theta x_2) = \theta^2 (x_1 x_2) \ge 0\), so \(\theta x \in K_2\) (and similarly for \(K_1\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test closure under addition for \(K_2\):&lt;/strong&gt; Choose \(x = (1, 0)^T \in K_2\) (since \(1 \cdot 0 = 0 \ge 0\)) and \(y = (0, -1)^T \in K_2\) (since \(0 \cdot (-1) = 0 \ge 0\)).
Their sum is:
\(x + y = (1, -1)^T \implies (1)(-1) = -1 &amp;lt; 0 \implies x + y \notin K_2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; \(K_2\) is a &lt;strong&gt;nonconvex cone&lt;/strong&gt;, whereas for \(K_1\), \(\theta_1 x + \theta_2 y\) always has nonnegative coordinates whenever \(\theta_1, \theta_2 \ge 0\), certifying \(K_1\) as a &lt;strong&gt;convex cone&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A cone is a set that extends infinitely in certain directions, like a beam of light from a source, but is not defined in the opposite direction. To determine if a set is a cone, check if the ray starting from the origin and passing through any point in the set is also contained within the set. (Thus, a cone must include the origin.) Because a cone has boundaries, it cannot be an affine set. Let’s define this mathematically.&lt;/p&gt;

&lt;h2 id=&quot;cone&quot;&gt;Cone&lt;/h2&gt;

&lt;p&gt;A set \(C\) is a &lt;strong&gt;cone&lt;/strong&gt; (or &lt;strong&gt;nonnegative homogeneous set&lt;/strong&gt;) if for any point \(x \in C\), the ray \(\theta x\) is also in \(C\) for \(\theta \ge 0\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\theta x \in C\) with \(x \in C\), \(\theta \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;[Reference] Unlike affine or convex sets, when defining a cone, the starting point of the ray is assumed to be the origin, so only one point is used.&lt;/p&gt;

&lt;h2 id=&quot;convex-cone&quot;&gt;Convex Cone&lt;/h2&gt;

&lt;p&gt;A set \(C\) is a &lt;strong&gt;convex cone&lt;/strong&gt; if it is both a cone and convex:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\theta_1 x_1 + \theta_2 x_2 \in C\) with \(x_1, x_2 \in C\), \(\theta_1, \theta_2 \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The figure below shows a pie-shaped convex cone. In the figure, \(x_1\) and \(x_2\) are points in the cone, and \(\theta_1\) and \(\theta_2\) are non-negative scalars.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.04_Convex_Cone.png&quot; alt=&quot;[Fig1] Convex Cone [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Convex Cone [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;conic-combination&quot;&gt;Conic combination&lt;/h2&gt;

&lt;p&gt;A linear combination of several points where all coefficients are non-negative is called a &lt;strong&gt;conic combination&lt;/strong&gt; (or &lt;strong&gt;nonnegative linear combination&lt;/strong&gt;):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;A point of the form \(\theta_1 x_1 + \theta_2 x_2 + \cdots + \theta_k x_k\) with \(\theta_i \ge 0, i = 1,  ..., k\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If every conic combination of points in a set \(C\) is also in \(C\), then \(C\) is a conic set.&lt;/p&gt;

&lt;h2 id=&quot;conic-hull&quot;&gt;Conic hull&lt;/h2&gt;

&lt;p&gt;The set of all conic combinations of points in \(C \subseteq \mathbb{R}^n\) is called the &lt;strong&gt;conic hull&lt;/strong&gt; of \(C\). The conic hull is always the smallest convex cone containing \(C\):&lt;/p&gt;
&lt;blockquote&gt;
\[\{ \theta_1 x_1 + \cdots + \theta_k x_k \mid x_i \in C, \theta_i \ge 0, i = 1, ..., k \}\]
&lt;/blockquote&gt;

</content>
 </entry>
 
 <entry>
   <title>02-01-03 Convex set</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_03_Convex-set/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_03_Convex-set</id>
   <content type="html">&lt;p&gt;If an investor holds two compliant portfolios \(x\) and \(y\), any blended portfolio \(\theta x + (1-\theta)y\) (\(0 \le \theta \le 1\)) represents a diversification mix between them. When the set of compliant portfolios is &lt;em&gt;convex&lt;/em&gt;, diversification never violates the rules. Beyond feasibility, the &lt;em&gt;convex hull&lt;/em&gt; lets us wrap any scattered or nonconvex set of points inside the tightest possible convex envelope—the foundational trick behind convex relaxations.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-core-geometry-of-convex-sets&quot;&gt;Key ideas: Core Geometry of Convex Sets&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Line-Segment Closure:&lt;/strong&gt; \(C\) is convex if and only if for all \(x, y \in C\) and \(\theta \in [0, 1]\), \(\theta x + (1-\theta)y \in C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Combinations as Weighted Averages:&lt;/strong&gt; Generalizing to \(k\) points gives \(\sum_{i=1}^k \theta_i x_i\) with \(\theta_i \ge 0, \sum \theta_i = 1\)—interpretable as the center of mass (or expectation) of a discrete probability distribution over \(\{x_1, \dots, x_k\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Hull (\(\text{conv}(S)\)):&lt;/strong&gt; The set of all finite convex combinations of points in \(S\)—equivalently, the intersection of all convex sets containing \(S\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimization Connection:&lt;/strong&gt; Minimizing a linear function over a nonconvex set \(S\) has the exact same optimal value as minimizing it over the convex set \(\text{conv}(S)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-testing-membership-in-a-2d-convex-hull&quot;&gt;Worked example: Testing Membership in a 2D Convex Hull&lt;/h3&gt;

&lt;p&gt;Determine whether the point \(p = (2, 2)^T\) lies in the convex hull of the triangle vertices \(v_1 = (0, 0)^T\), \(v_2 = (4, 0)^T\), and \(v_3 = (1, 4)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Set up the convex combination system \(p = \theta_1 v_1 + \theta_2 v_2 + \theta_3 v_3\) with \(\theta_1 + \theta_2 + \theta_3 = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;First coordinate: \(0\theta_1 + 4\theta_2 + 1\theta_3 = 2\).&lt;/li&gt;
      &lt;li&gt;Second coordinate: \(0\theta_1 + 0\theta_2 + 4\theta_3 = 2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve sequentially for \(\theta_3, \theta_2, \theta_1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;From the second coordinate: \(\theta_3 = \frac{2}{4} = 0.5\).&lt;/li&gt;
      &lt;li&gt;Substitute into the first coordinate: \(4\theta_2 + 0.5 = 2 \implies \theta_2 = \frac{1.5}{4} = 0.375\).&lt;/li&gt;
      &lt;li&gt;Use sum-to-one: \(\theta_1 = 1 - 0.5 - 0.375 = 0.125\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check nonnegativity:&lt;/strong&gt; Since \(\theta_1 = 0.125 \ge 0\), \(\theta_2 = 0.375 \ge 0\), and \(\theta_3 = 0.5 \ge 0\), \(p\) is a valid convex combination and lies strictly inside \(\text{conv}\{v_1, v_2, v_3\}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now let’s look at the core concept of this chapter: the convex set. Intuitively, a convex set is a set with no “dents” or “holes” inside. To determine if a set is convex, check if the line segment connecting any two points in the set is also contained within the set.&lt;/p&gt;

&lt;h2 id=&quot;convex-set&quot;&gt;Convex set&lt;/h2&gt;

&lt;p&gt;A set \(C \subseteq \mathbb{R}^n\) is a &lt;strong&gt;convex set&lt;/strong&gt; if for any two points \(x_1, x_2 \in C\), the line segment connecting them is also in \(C\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\theta x_1 + (1-\theta)x_2 \in C\) with \(x_1, x_2 \in C\), \(0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This means that for any two points in \(C\), all points on the line segment between them are also in \(C\).&lt;/p&gt;

&lt;p&gt;The figure below shows examples of convex sets. The triangle on the left is convex, but the shape with a cavity on the right is not convex because the line segment between some points leaves the set.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.02_Convex_Set.png&quot; alt=&quot;[Fig1] Convex Set [1]&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Convex Set [1]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;convex-combination&quot;&gt;Convex combination&lt;/h2&gt;

&lt;p&gt;A linear combination of several points where the coefficients are non-negative and sum to 1 is called a &lt;strong&gt;convex combination&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;A point of the form \(\theta_1 x_1 + \theta_2 x_2 + \cdots + \theta_k x_k\) with \(\theta_1 + \theta_2 + \cdots + \theta_k = 1, \theta_i \ge  0, i = 1,  ..., k\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If every convex combination of points in a set \(C\) is also in \(C\), then \(C\) is a convex set.&lt;/p&gt;

&lt;h2 id=&quot;convex-hull&quot;&gt;Convex hull&lt;/h2&gt;

&lt;p&gt;The set of all convex combinations of points in \(C \subseteq \mathbb{R}^n\) is called the &lt;strong&gt;convex hull&lt;/strong&gt; of \(C\), denoted as &lt;strong&gt;conv&lt;/strong&gt; \(C\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;conv&lt;/strong&gt; \(C = \{ \theta_1 x_1 + \cdots + \theta_k x_k \mid x_i \in C, \theta_i \ge 0, i = 1, ..., k, \theta_1 + \cdots + \theta_k = 1 \}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The figure below shows the convex hull for a set of 15 points and a shape with a cavity.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.03_Convex_Hull.png&quot; alt=&quot; Convex Hull&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Convex Hull&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.03_Convex_Hull_2.png&quot; alt=&quot; Convex Hull&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Convex Hull&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01-02 Affine set</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_02_Affine_set/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_02_Affine_set</id>
   <content type="html">&lt;p&gt;When you impose linear equality constraints \(Ax = b\)—such as flow conservation in a power grid or portfolio weights summing to 1—the feasible region is a flat slice of \(\mathbb{R}^n\) that does not necessarily pass through the origin. That shifted flat is an &lt;em&gt;affine set&lt;/em&gt;. Recognizing that every affine set is just a linear subspace translated by a single feasible point \(x_0\) lets us eliminate equality constraints cleanly in optimization algorithms.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-affine-sets-and-linear-equalities&quot;&gt;Key ideas: Affine Sets and Linear Equalities&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Closure Under Infinite Lines:&lt;/strong&gt; A set \(C\) is affine if for any \(x_1, x_2 \in C\) and &lt;em&gt;all&lt;/em&gt; \(\theta \in \mathbb{R}\), \(\theta x_1 + (1-\theta)x_2 \in C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine Combinations &amp;amp; Affine Hull:&lt;/strong&gt; The affine hull \(\text{aff}(S)\) is the smallest flat containing \(S\)—crucial for defining the &lt;em&gt;relative interior&lt;/em&gt; of lower-dimensional convex sets like the probability simplex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Shifted Subspace Structure (\(C = x_0 + V\)):&lt;/strong&gt; Subtracting any single point \(x_0 \in C\) produces a unique linear subspace \(V = C - x_0\) independent of the choice of \(x_0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equivalence to \(Ax = b\):&lt;/strong&gt; Every solution set \(\{x : Ax = b\}\) is affine (with associated subspace \(V = \mathcal{N}(A)\)), and conversely every affine set can be written as the solution set of a linear system.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-decomposing-a-line-into-x_0--v&quot;&gt;Worked example: Decomposing a Line into \(x_0 + V\)&lt;/h3&gt;

&lt;p&gt;Consider the affine set \(C = \{(x_1, x_2) \in \mathbb{R}^2 : 2x_1 + x_2 = 4\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Pick any particular point \(x_0 \in C\):&lt;/strong&gt; Setting \(x_2 = 0\) gives \(x_0 = (2, 0)^T \in C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Identify the associated subspace \(V = C - x_0\):&lt;/strong&gt; For any \(x \in C\), let \(v = x - x_0\). Then
\(2(v_1 + 2) + (v_2 + 0) = 4 \iff 2v_1 + v_2 = 0 \implies V = \text{span}\left\{\begin{pmatrix} 1 \\ -2 \end{pmatrix}\right\}.\)
Hence \(C = \begin{pmatrix} 2 \\ 0 \end{pmatrix} + \text{span}\left\{\begin{pmatrix} 1 \\ -2 \end{pmatrix}\right\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify closure under an affine combination with negative weight:&lt;/strong&gt; Take \(p = (2, 0)^T \in C\), \(q = (0, 4)^T \in C\), and \(\theta = 3\):
\(3p + (1 - 3)q = 3(2, 0)^T - 2(0, 4)^T = (6, -8)^T.\)
Checking the defining equation: \(2(6) + (-8) = 12 - 8 = 4\), confirming \((6, -8)^T \in C\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An affine set is a collection with no boundaries, such as a point, line, plane, or hyperplane. To determine if a set is affine, check if the line passing through any two points in the set is also contained within the set. The absence of boundaries means that if any space has a boundary, it cannot be an affine set. Let’s define this mathematically.&lt;/p&gt;

&lt;h2 id=&quot;affine-set&quot;&gt;Affine set&lt;/h2&gt;

&lt;p&gt;A set \(C \subseteq \mathbb{R}^n\) is an &lt;strong&gt;affine set&lt;/strong&gt; if for any two points \(x_1, x_2 \in C\), the line passing through them is also in \(C\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\theta x_1 + (1-\theta)x_2 \in C\) with \(\theta \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This can be interpreted as a linear combination of two points in \(C\), where the sum of the coefficients is 1. If the result is always in \(C\), then \(C\) is an affine set.&lt;/p&gt;

&lt;h2 id=&quot;affine-combination&quot;&gt;Affine combination&lt;/h2&gt;

&lt;p&gt;A linear combination of several points where the sum of the coefficients is 1 is called an &lt;strong&gt;affine combination&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\theta_1 x_1 + \theta_2 x_2 + \cdots + \theta_k x_k \in C\) with \(\theta_1 + \theta_2 + \cdots + \theta_k = 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If every affine combination of points in a set \(C\) is also in \(C\), then \(C\) is an affine set.&lt;/p&gt;

&lt;h2 id=&quot;affine-hull&quot;&gt;Affine hull&lt;/h2&gt;

&lt;p&gt;The set of all affine combinations of points in \(C \subseteq \mathbb{R}^n\) is called the &lt;strong&gt;affine hull&lt;/strong&gt; of \(C\), denoted as &lt;strong&gt;aff&lt;/strong&gt; \(C\):&lt;/p&gt;
&lt;blockquote&gt;
\[\text{aff} (C) = \{ \theta_1 x_1 + \cdots + \theta_k x_k \mid x_1, ..., x_k \in C, \theta_1 + \cdots + \theta_k = 1 \}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;relationship-between-affine-set-and-subspace&quot;&gt;Relationship between affine set and subspace&lt;/h2&gt;

&lt;p&gt;If \(C\) is an affine set and \(x_0 \in C\), then \(V = C - x_0\) is a subspace:&lt;/p&gt;
&lt;blockquote&gt;
\[V = C - x_0 =  \{ x - x_0 \mid x \in C \}\]
&lt;/blockquote&gt;

&lt;p&gt;Thus, “An affine set \(C\) is a translation of a linear subspace \(V\) by \(x_0\),” where \(x_0\) can be any point in \(C\). The dimension of \(C\) is the same as that of \(V\).&lt;/p&gt;

&lt;h3 id=&quot;reference-proof-that-v-is-a-subspace&quot;&gt;[Reference] Proof that \(V\) is a subspace&lt;/h3&gt;

&lt;p&gt;To prove \(V\) is a subspace, show that it is closed under addition and scalar multiplication. That is, for \(v_1, v_2 \in V\) and \(\alpha, \beta \in \mathbb{R}\), \(\alpha v_1 + \beta v_2 \in V\). This follows from the definition above.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01-01 Line, line segment, ray</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_01_Line_line_segment_ray/"/>
   <updated>2021-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_01_Line_line_segment_ray</id>
   <content type="html">&lt;p&gt;Every line-search algorithm in optimization reduces an \(n\)-dimensional problem to a 1-dimensional walk along a ray \(x_k + t d\) (\(t \ge 0\)), while every proof of convexity checks values along a line segment \(\theta x_1 + (1-\theta)x_2\) (\(0 \le \theta \le 1\)). Mastering the exact parameter domains of lines, segments, and rays turns high-dimensional geometry into effortless 1D algebra.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-one-dimensional-geometric-primitives&quot;&gt;Key ideas: One-Dimensional Geometric Primitives&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Line (\(\theta \in \mathbb{R}\)):&lt;/strong&gt; \(y(\theta) = \theta x_1 + (1-\theta)x_2\) extends infinitely in both directions through \(x_1\) and \(x_2\)—the simplest nontrivial affine set.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Line Segment (\(\theta \in [0, 1]\)):&lt;/strong&gt; Restricting \(\theta\) to \([0, 1]\) traps \(y(\theta)\) between endpoints \(x_1\) and \(x_2\)—the exact test object for convexity.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ray (\(t \ge 0\)):&lt;/strong&gt; \(y(t) = x_0 + t v\) starts at basepoint \(x_0\) and shoots infinitely along direction \(v \neq 0\)—used for line search and unbounded recession directions of feasible sets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parameterization Equivalence:&lt;/strong&gt; Writing \(y(\theta) = x_2 + \theta(x_1 - x_2)\) reveals the direction vector \(v = x_1 - x_2\) explicitly so you can read velocity and endpoints at a glance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-parameterizing-a-line-segment-and-ray-in-mathbbr2&quot;&gt;Worked example: Parameterizing a Line, Segment, and Ray in \(\mathbb{R}^2\)&lt;/h3&gt;

&lt;p&gt;Given \(x_1 = (1, 2)^T\) and \(x_2 = (5, 0)^T\), form \(y(\theta) = \theta x_1 + (1-\theta)x_2 = (5 - 4\theta,\; 2\theta)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Point on the line segment (\(\theta = 0.25 \in [0, 1]\)):&lt;/strong&gt;
\(y(0.25) = (5 - 1,\; 0.5)^T = (4, 0.5)^T.\)
This sits one-quarter of the way from \(x_2\) toward \(x_1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Point on the infinite line but outside the segment (\(\theta = 1.5 \notin [0, 1]\)):&lt;/strong&gt;
\(y(1.5) = (5 - 6,\; 3)^T = (-1, 3)^T.\)
Notice it overshoots \(x_1\) along the same collinear slope \(-1/2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ray starting at \(x_1\) through \(x_2\):&lt;/strong&gt; Direction is \(v = x_2 - x_1 = (4, -2)^T\), so \(r(t) = (1, 2)^T + t(4, -2)^T\) for \(t \ge 0\). At \(t = 2\), \(r(2) = (9, -2)^T\), continuing past \(x_2\) (which corresponds to \(t = 1\)).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To define affine sets, convex sets, and cones, let’s first look at lines, line segments, and rays.&lt;/p&gt;

&lt;p&gt;A line is an infinitely extending straight path passing through two points in both directions. In contrast, a line segment is a straight path defined only between two points, and a ray starts at one point and extends infinitely in one direction through another point. The figure below shows a line and a line segment. Depending on the range of the parameter \(\theta\), you can imagine how a line, line segment, or ray is defined.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter02/02.01_Line_Segment.png&quot; alt=&quot;Line Segment&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;$$\text{[Fig1] } x_1\text{ and } x_2 \text{ defining a Line and Line Segment [1]}$$&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;[Reference] When you use two points included in a set to create a line, line segment, or ray, whether these are included in the set determines the definition of the set. (You can also define sets using multiple points and their affine, convex, or conic combinations. Details will be explained in the following sections.)&lt;/p&gt;

&lt;h2 id=&quot;line&quot;&gt;Line&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;Line&lt;/strong&gt; passing through two points \(x_1\) and \(x_2\) is defined as:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(y = \theta x_1 + (1 - \theta) x_2\) with \(\theta \in \mathbb{R}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;line-segment&quot;&gt;Line segment&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;Line segment&lt;/strong&gt; is defined by restricting \(\theta\) to the interval [0, 1]:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(y = \theta x_1 + (1 - \theta) x_2\) with \(0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Alternatively, you can express it as:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(y = x_2 + \theta (x_1 - x_2)\) with \(0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;ray&quot;&gt;Ray&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;Ray&lt;/strong&gt; starts at one point and extends infinitely in one direction:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(y = x_2 + \theta (x_1 - x_2)\) with \(\theta \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or equivalently:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(y = \theta x_1 + (1 - \theta) x_2\) with \(\theta \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now you can see that the range of \(\theta\) is \(\theta \in \mathbb{R}\) for lines, \(0 \le \theta \le 1\) for line segments, and \(\theta \ge 0\) for rays. Furthermore, you will find that the ranges of \(\theta\) are the same in the affine sets, convex sets, and conic sets that we will define later.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>makers</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/home/makers/"/>
   <updated>2021-02-03T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/home/makers</id>
   <content type="html">
</content>
 </entry>
 
 <entry>
   <title>Conventions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contribution/conventions/"/>
   <updated>2021-02-03T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contribution/conventions</id>
   <content type="html">&lt;h2 id=&quot;1-directory-convention&quot;&gt;1. Directory Convention&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;주요 컨텐츠는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;contents/chapter&lt;/code&gt;로 시작하는 디렉토리에 포함되어 있습니다. 또한 컨텐츠에 필요한 이미지는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;image&lt;/code&gt; 디렉토리에 들어 있습니다.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;contents/chapter&lt;/code&gt;의 내부 디렉토리는 다음과 같습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;contents
├── chapter01
│   ├── _posts
│   │   ├── 21-01-07-01_00_Introduction.md
│   │   ├── 21-01-07-01_01_optimization_problems.md
│   │   ├── 21-01-28-01_02_convex_optimization_problem.md
│   │   ├── 21-01-28-01_03_goals_and_topics.md
│   │   └── 21-01-28-01_04_brief_history_of_convex_optimization.md
│   ├── index.html
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Jekyll에서는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_posts&lt;/code&gt; 디렉토리 내에 있는 Markdown 또는 html 파일을 블로그의 Posting으로 인식합니다. 따라서 새로운 포스팅을 작성하고자 한다면 각 디렉토리의 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_posts&lt;/code&gt;에 새로 파일을 추가하시면 됩니다.&lt;/li&gt;
  &lt;li&gt;Jekyll의 Posting 파일들은 모두 아래와 같은 Naming Convention을 따라야 합니다.
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;yy-mm-dd-new_posting_name.md&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chapter&lt;/code&gt;와 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;image&lt;/code&gt; 디렉토리 외의 내용들은 모두 Blog의 설정과 관련된 것들입니다. 안정적인 운영을 위해 설정과 관련된 부분들에 대해서는 직접 편집보다는 이슈로 작성해주시면 처리하겠습니다(관련 내용 수정 시 PR Merge가 어려울 수 있습니다).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-posting-convention&quot;&gt;2. Posting Convention&lt;/h2&gt;

&lt;h3 id=&quot;21-header-field&quot;&gt;2.1. Header Field&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;모든 Posting 파일들은 다음 예시와 같은 Header를 가지고 있어야 합니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;---
layout: post
title: Quasi-Newton Methods
chapter: &quot;18&quot;
order: 1
owner: &quot;Kyeongmin Woo&quot;
---
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;layout&lt;/strong&gt;은 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;post&lt;/code&gt;여야 합니다.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;title&lt;/strong&gt;은 내용에 맞게 임의의 String으로 설정할 수 있습니다.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;chapter&lt;/strong&gt;는 상위 카테고리의 마지막 두 숫자를 String으로 표기합니다. 다만 한 자리수인 경우 “01”과 같이 0을 붙여줘야 합니다.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;order&lt;/strong&gt;는 해당 chapter 내에서의 정렬 순서를 의미합니다.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;owner&lt;/strong&gt;는 해당 post의 관리자를 의미합니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;22-latex&quot;&gt;2.2. Latex&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;수식은 Latex 문법에 따라 표기합니다.&lt;/li&gt;
  &lt;li&gt;$$ 와 같이 double dollar sign을 사용하여 수식임을 나타냅니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$$\theta x_1 + (1-\theta)x_2 \in C$$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;위 수식은 다음과 같이 표기됩니다.&lt;/p&gt;

\[\theta x_1 + (1-\theta)x_2 \in C\]

&lt;h3 id=&quot;23-image-convention&quot;&gt;2.3. Image Convention&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Posting 파일에서 이미지를 삽일할 때 아래의 Convention을 따라야합니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&amp;gt;
&amp;lt;p align=&quot;center&quot;&amp;gt;
  &amp;lt;img src=&quot;{image_path}&quot; alt=&quot;{description of image}&quot; width=&quot;{scale_ratio}%&quot; height=&quot;{scale_ratio}%&quot;&amp;gt;
  &amp;lt;figcaption style=&quot;text-align: center;&quot;&amp;gt;{figcaption}&amp;lt;/figcaption&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;/figure&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;figure class는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;image&lt;/code&gt;여야합니다.&lt;/li&gt;
  &lt;li&gt;{}에 들어갈 내용을 적절히 넣어야합니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;24-hyperlink-convention&quot;&gt;2.4 Hyperlink Convention&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Blog 내의 Post에 대한 hyperlink는 jekyll multilang_post_url 사용합니다. 첫 번째 Post인 &lt;a href=&quot;/contents/en/chapter01/01_01_optimization_problems/&quot;&gt;Optimization problems?&lt;/a&gt;의 hyperlink는 아래와 같이 작성합니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[Optimization problems?](/contents/en/chapter01/01_01_optimization_problems/)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;기타 외부 Url로의 hyperlink는 다음과 같이 작성할 수 있습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[Convex Optimization 위키](&amp;lt;https://bit.ly/2PXv736&amp;gt;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;3-github-convnention&quot;&gt;3. GitHub Convnention&lt;/h2&gt;

&lt;p&gt;작성 내용에 질문이 있거나 수정 사항을 발견하신 경우 다음 두 방법 중 하나로 남겨주시면 됩니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;댓글 작성하기&lt;/li&gt;
  &lt;li&gt;Repogitory에 이슈 생성하기&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;새로운 내용을 추가하거나 직접 편집하시고 싶으신 경우에는 새로운 Branch를 생성하여 먼저 수정하신 후 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pull Request&lt;/code&gt;를 생성해주시면 됩니다. 신규 작성 및 기존 내용 수정은 누구나 가능합니다.&lt;/p&gt;

&lt;h3 id=&quot;31-repository-policy&quot;&gt;3.1. Repository Policy&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt; 브랜치로 Merge 되기 위해서는 1명 이상의 Reviewer가 Approve 해야 합니다. CODEOWNERS 시스템이 도입되어 있어 각 Chapter 별 Reviewer가 자동으로 할당됩니다.&lt;/p&gt;

&lt;h3 id=&quot;32-branch-naming-convention&quot;&gt;3.2. Branch Naming Convention&lt;/h3&gt;

&lt;p&gt;브랜치 이름은 다음 컨벤션에 맞춰 생성해주시면 됩니다.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[feature|bugfix]/[chapter**|settings]-변경-사항
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Prefix는 feature와 bugfix 두 가지를 사용합니다. 각각의 사용 예시는 다음과 같습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;feature
    &lt;ul&gt;
      &lt;li&gt;Migration 작업&lt;/li&gt;
      &lt;li&gt;문장/수식/이미지 등이 달라지는 경우&lt;/li&gt;
      &lt;li&gt;새로운 내용이 추가되는 경우&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;bugfix
    &lt;ul&gt;
      &lt;li&gt;오타를 수정하는 경우&lt;/li&gt;
      &lt;li&gt;latex view가 깨져 수정하는 경우&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;구체적인 예시는 아래와 같습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feature/chapter01-migration&lt;/code&gt;: chapter01 Migration&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feature/chapter01-fix-formula&lt;/code&gt;: chapter01에서 수식 업데이트&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feature/settings-update-branch-convention&lt;/code&gt;: Convention 업데이트&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bugfix/chapter01-fix-typo&lt;/code&gt;: chapter01에서 오타 수정&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-07 Bài Tập Thực Hành - Giới Thiệu Tối Ưu Hóa</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_07_Practical_Exercises_Introduction/"/>
   <updated>2021-01-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_07_Practical_Exercises_Introduction</id>
   <content type="html">&lt;p&gt;Một bài toán thực tế hiếm khi xuất hiện sẵn trong lớp vỏ lồi gọn gàng; phép màu của kỹ sư tối ưu nằm ở kỹ năng &lt;strong&gt;chuyển dạng (reformulation)&lt;/strong&gt;: đổi biến logarit để biến Quy hoạch hình học (Geometric Programming) thành bài toán lồi, thêm biến phụ để khử giá trị tuyệt đối trong chuẩn \(\ell_1\), hay viết lại hồi quy bình phương tối thiểu thành hệ phương trình chuẩn.&lt;/p&gt;

&lt;p&gt;Bài tập thực hành cuối Chương 01 đưa bạn trực tiếp từ việc phân loại LP/QP/GP trên giấy sang triển khai và kiểm chứng nghiệm. Dưới đây là bản đồ các kỹ thuật chuyển dạng quan trọng nhất cùng một ví dụ GP giải tay từng bước.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-họ-bài-toán-thực-hành-cốt-lõi-của-chương-01&quot;&gt;Kiến thức cần nhớ: Bốn họ bài toán thực hành cốt lõi của Chương 01&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bình phương tối thiểu (Least Squares):&lt;/strong&gt; \(\min_x \|Ax - b\|_2^2\) — có công thức đóng \(x^* = (A^T A)^{-1}A^T b\) khi \(A\) đủ hạng cột, là điểm khởi đầu của hồi quy và ước lượng tín hiệu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy hoạch tuyến tính (LP):&lt;/strong&gt; Hàm mục tiêu và mọi ràng buộc đều affine; nghiệm tối ưu (nếu tồn tại và bị chặn) luôn đạt được tại ít nhất một đỉnh của đa diện khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy hoạch bậc hai (QP):&lt;/strong&gt; Hàm mục tiêu bậc hai lồi \(\frac{1}{2}x^T P x + q^T x\) với \(P \succeq 0\) và ràng buộc tuyến tính — khung chuẩn của tối ưu hóa danh mục đầu tư Markowitz và máy vector hỗ trợ (SVM).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy hoạch hình học (Geometric Programming — GP):&lt;/strong&gt; Thoạt nhìn phi tuyến, không lồi (chứa đơn thức và posynomial trên \(x &amp;gt; 0\)), nhưng phép đổi biến \(u_i = \ln x_i\) biến nó thành bài toán &lt;strong&gt;lồi hoàn toàn&lt;/strong&gt; nhờ tính lồi của hàm log-sum-exp!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phù-phép-đổi-biến-một-bài-toán-quy-hoạch-hình-học-thành-bài-toán-lồi&quot;&gt;Giải thích: “Phù phép” đổi biến một bài toán Quy hoạch hình học thành bài toán lồi&lt;/h3&gt;

&lt;p&gt;Xét bài toán trên miền dương \(x &amp;gt; 0,\ y &amp;gt; 0\):
\(\min_{x, y &amp;gt; 0} \frac{1}{xy} \quad \text{với điều kiện} \quad x + 2y \le 4.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhận diện:&lt;/strong&gt; Hàm mục tiêu \(x^{-1}y^{-1}\) là đơn thức (monomial), vế trái ràng buộc \(x + 2y\) là tổng các đơn thức hệ số dương (posynomial). Đây là một bài toán GP ở dạng gốc (chưa lồi chuẩn).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đổi biến logarit \(u = \ln x,\ v = \ln y\) (tức \(x = e^u,\ y = e^v\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Lấy log hàm mục tiêu: \(\ln(x^{-1}y^{-1}) = -u - v\) (hàm &lt;strong&gt;tuyến tính&lt;/strong&gt;!).&lt;/li&gt;
      &lt;li&gt;Lấy log hai vế ràng buộc: \(\ln(e^u + 2e^v) = \ln(e^u + e^{v + \ln 2}) \le \ln 4\) (vế trái là hàm &lt;strong&gt;log-sum-exp&lt;/strong&gt;, hoàn toàn &lt;strong&gt;lồi&lt;/strong&gt; theo \((u, v)\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải chính xác bằng bất đẳng thức AM–GM:&lt;/strong&gt;
Với \(x, y &amp;gt; 0\) và \(x + 2y \le 4\), ta có:
\(4 \ge x + 2y \ge 2\sqrt{2xy} \implies 2\sqrt{2xy} \le 4 \implies 2xy \le 4 \implies xy \le 2 \implies \frac{1}{xy} \ge \frac{1}{2}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm đạt dấu bằng:&lt;/strong&gt; Xảy ra khi \(x = 2y\) và \(x + 2y = 4 \implies x^* = 2,\ y^* = 1\) (tương ứng \(u^* = \ln 2,\ v^* = 0\)), cho giá trị tối ưu \(p^* = \frac{1}{2} = 0.5\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---giới-thiệu-tối-ưu-hóa&quot;&gt;Bài tập thực hành - Giới thiệu tối ưu hóa&lt;/h1&gt;

&lt;h2 id=&quot;-bài-tập-1-phân-loại-bài-toán-tối-ưu-hóa-cơ-bản&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Phân loại bài toán tối ưu hóa cơ bản&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 1.1 từ Boyd &amp;amp; Vandenberghe)
Phân loại các bài toán sau đây vào các lớp: LP (quy hoạch tuyến tính), QP (quy hoạch bậc hai), QCQP (quy hoạch bậc hai có ràng buộc bậc hai), SOCP (quy hoạch nón bậc hai), SDP (quy hoạch nửa xác định) hoặc GP (quy hoạch hình học):&lt;/p&gt;

&lt;p&gt;a) \(\min_{x \in \mathbb{R}^n} c^T x \quad \text{s.t.} \quad Ax \leq b\)&lt;/p&gt;

&lt;p&gt;b) \(\min_{x \in \mathbb{R}^n} x^T P x + q^T x \quad \text{s.t.} \quad Ax = b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;c) \(\min_{x \in \mathbb{R}^n} \lVert Ax - b \rVert_2 \quad \text{s.t.} \quad \lVert x \rVert_2 \leq 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Xác định lớp bài toán cho mỗi trường hợp.&lt;/li&gt;
  &lt;li&gt;Giải thích lý do phân loại.&lt;/li&gt;
  &lt;li&gt;Nêu điều kiện để bài toán là bài toán lồi.&lt;/li&gt;
  &lt;li&gt;Đề xuất phương pháp giải phù hợp.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Phân loại**

**a) Quy hoạch tuyến tính (LP)**
- Hàm mục tiêu: tuyến tính ($$c^T x$$).
- Ràng buộc: bất đẳng thức tuyến tính ($$Ax \leq b$$).
- Đây là dạng chuẩn của bài toán LP.

**b) Quy hoạch bậc hai (QP)**
- Hàm mục tiêu: hàm bậc hai ($$x^T P x + q^T x$$).
- Ràng buộc: tuyến tính ($$Ax = b, x \geq 0$$).
- Là bài toán QP lồi khi $$P \succeq 0$$.

**c) Quy hoạch nón bậc hai (SOCP)**
- Hàm mục tiêu: chuẩn Euclid ($$\lVert Ax - b \rVert_2$$).
- Ràng buộc: ràng buộc chuẩn Euclid ($$\lVert x \rVert_2 \leq 1$$).
- Có thể đưa trực tiếp về dạng chuẩn SOCP (bằng cách thêm biến phụ $$t$$ với ràng buộc $$\lVert Ax - b \rVert_2 \leq t$$).

**Bước 2: Điều kiện tính lồi**
- **a)** Luôn lồi (hàm mục tiêu và các ràng buộc đều tuyến tính/affine).
- **b)** Lồi khi $$P \succeq 0$$ (ma trận nửa xác định dương).
- **c)** Luôn lồi (chuẩn Euclid là hàm lồi và hình cầu chuẩn là tập lồi).

**Bước 3: Phương pháp giải**
- **a)** Thuật toán đơn hình (Simplex), phương pháp điểm trong.
- **b)** Phương pháp tập hoạt động (Active-set), phương pháp điểm trong.
- **c)** Phương pháp điểm trong cho SOCP.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-bình-phương-tối-thiểu-và-các-biến-thể&quot;&gt;📝 &lt;strong&gt;Bài tập 2: Bình phương tối thiểu và các biến thể&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 1.2 từ Boyd &amp;amp; Vandenberghe)
Xét các bài toán bình phương tối thiểu sau:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Bình phương tối thiểu thông thường (OLS):&lt;/strong&gt; \(\min_x \lVert Ax - b \rVert_2^2\)&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Bình phương tối thiểu có trọng số (WLS):&lt;/strong&gt; \(\min_x (Ax - b)^T W (Ax - b)\) với \(W \succ 0\)&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Bình phương tối thiểu có điều chuẩn (Ridge):&lt;/strong&gt; \(\min_x \lVert Ax - b \rVert_2^2 + \lambda \lVert x \rVert_2^2\)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;d) &lt;strong&gt;Bình phương tối thiểu bền vững (Robust LS):&lt;/strong&gt; \(\min_x \sum_{i=1}^m \phi((Ax - b)_i)\) với $$\phi(u) = \begin{cases} u^2 &amp;amp;&lt;/td&gt;
      &lt;td&gt;u&lt;/td&gt;
      &lt;td&gt;\leq M \ 2M&lt;/td&gt;
      &lt;td&gt;u&lt;/td&gt;
      &lt;td&gt;- M^2 &amp;amp;&lt;/td&gt;
      &lt;td&gt;u&lt;/td&gt;
      &lt;td&gt;&amp;gt; M \end{cases}$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Tìm nghiệm giải tích (dạng đóng) cho các trường hợp a, b, c.&lt;/li&gt;
  &lt;li&gt;Chứng minh tính lồi của cả bốn bài toán.&lt;/li&gt;
  &lt;li&gt;Phân tích ý nghĩa hình học của thành phần điều chuẩn.&lt;/li&gt;
  &lt;li&gt;So sánh độ bền vững (robustness) trước điểm ngoại lai của các phương pháp.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Nghiệm giải tích**

**a) Bình phương tối thiểu thông thường:**
$$x^* = (A^T A)^{-1} A^T b$$ (khi $$A^T A$$ khả nghịch).

**b) Bình phương tối thiểu có trọng số:**
$$x^* = (A^T W A)^{-1} A^T W b$$ (khi $$A^T W A$$ khả nghịch).

**c) Bình phương tối thiểu có điều chuẩn (Hồi quy Ridge):**
$$x^* = (A^T A + \lambda I)^{-1} A^T b$$ (luôn khả nghịch với mọi $$\lambda &amp;gt; 0$$).

**d) Bình phương tối thiểu bền vững:**
Không có công thức nghiệm dạng đóng, cần giải bằng các phương pháp số lặp.

**Bước 2: Chứng minh tính lồi**

- **a–c)** Đều là hàm bậc hai có ma trận Hessian nửa xác định dương: $$2A^TA \succeq 0$$, $$2A^TWA \succeq 0$$ và $$2(A^TA + \lambda I) \succ 0$$ (với $$\lambda &amp;gt; 0$$).
- **d)** Hàm phạt Huber $$\phi(u)$$ là hàm lồi (hàm bậc hai từng khúc có đạo hàm liên tục và không giảm), nên tổng hợp tuyến tính của chúng cũng là hàm lồi.

**Bước 3: Ý nghĩa hình học của điều chuẩn**
- **Điều chuẩn $$L_2$$:** kéo nghiệm về gần gốc tọa độ, hạn chế quá khớp (overfitting).
- **Tham số $$\lambda$$:** kiểm soát sự đánh đổi giữa độ chệch (bias) và phương sai (variance).
- Về mặt thống kê Bayes, bài toán tương đương ước lượng hậu nghiệm cực đại (MAP) với phân phối tiên nghiệm chuẩn $$x \sim \mathcal{N}(0, \sigma^2/\lambda I)$$.

**Bước 4: So sánh độ bền vững**
- **OLS:** nhạy cảm mạnh với điểm ngoại lai do sai số bị bình phương.
- **WLS:** có thể giảm ảnh hưởng của điểm ngoại lai nếu chọn ma trận trọng số $$W$$ phù hợp.
- **Ridge:** giảm quá khớp và cải thiện khả năng tổng quát hóa, nhưng vẫn dùng mất mát bình phương.
- **Robust LS:** hàm mất mát Huber tăng tuyến tính khi $$|u| &amp;gt; M$$ nên giảm đáng kể độ nhạy với ngoại lai.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-quy-hoạch-tuyến-tính-ở-dạng-chuẩn&quot;&gt;📝 &lt;strong&gt;Bài tập 3: Quy hoạch tuyến tính ở dạng chuẩn&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 1.3 từ Boyd &amp;amp; Vandenberghe)
Đưa các bài toán sau về dạng chuẩn của quy hoạch tuyến tính (LP):&lt;/p&gt;

&lt;p&gt;a) \(\min_{x,y} 2x + 3y \quad \text{s.t.} \quad x + 2y \geq 5, \quad x - y = 2, \quad x \geq 0, \quad y \text{ free}\)&lt;/p&gt;

&lt;p&gt;b) \(\max_x c^T x \quad \text{s.t.} \quad Ax \leq b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;c) \(\min_x \lVert c^T x - d \rVert_\infty \quad \text{s.t.} \quad Ax \leq b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Biến đổi về dạng \(\min c^T z \text{ s.t. } Az = b, z \geq 0\).&lt;/li&gt;
  &lt;li&gt;Xác định rõ ma trận \(A\) và các vector \(b, c\) mới.&lt;/li&gt;
  &lt;li&gt;Giải thích các phép biến đổi đã sử dụng.&lt;/li&gt;
  &lt;li&gt;Kiểm tra tính tương đương giữa bài toán gốc và bài toán sau biến đổi.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Biến đổi bài toán a)**

- **Xử lý biến tự do:** đặt $$y = y^+ - y^-$$ với $$y^+, y^- \geq 0$$.
- **Xử lý bất đẳng thức:** thêm biến bù (surplus) $$s \geq 0$$ để chuyển $$x + 2y \geq 5 \Rightarrow x + 2y - s = 5$$.

**Dạng chuẩn:**
$$\min_{x,y^+,y^-,s} 2x + 3y^+ - 3y^- \quad \text{s.t.} \quad \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; -2 &amp;amp; -1 \\ 1 &amp;amp; -1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x \\ y^+ \\ y^- \\ s \end{bmatrix} = \begin{bmatrix} 5 \\ 2 \end{bmatrix}$$

với $$x, y^+, y^-, s \geq 0$$.

**Bước 2: Biến đổi bài toán b)**

- **Chuyển cực đại thành cực tiểu:** $$\max c^T x = -\min (-c^T x)$$.
- **Chuyển bất đẳng thức thành đẳng thức:** thêm vector biến bù (slack) $$s \geq 0$$ sao cho $$Ax \leq b \Rightarrow Ax + s = b$$.

**Dạng chuẩn:**
$$\min_{x,s} (-c^T x + 0^T s) \quad \text{s.t.} \quad [A \quad I] \begin{bmatrix} x \\ s \end{bmatrix} = b, \quad x,s \geq 0$$

**Bước 3: Biến đổi bài toán c)**

- **Loại bỏ chuẩn $$\ell_\infty$$:** đưa vào biến phụ $$t$$ sao cho $$\min t \text{ s.t. } -t \leq c^T x - d \leq t$$.

**Dạng chuẩn:**
$$\min_{x,t,s_1,s_2,s_3} t \quad \text{s.t.} \quad \begin{bmatrix} A &amp;amp; 0 &amp;amp; I &amp;amp; 0 &amp;amp; 0 \\ c^T &amp;amp; -1 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ -c^T &amp;amp; -1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} x \\ t \\ s_1 \\ s_2 \\ s_3 \end{bmatrix} = \begin{bmatrix} b \\ d \\ -d \end{bmatrix}, \quad t, s_1, s_2, s_3 \geq 0$$

Hai hàng cuối biểu diễn lần lượt $$c^T x - d \leq t$$ và $$-(c^T x - d) \leq t$$, mỗi hàng dùng một biến bù riêng. Do $$x$$ là biến tự do, ta thay tiếp $$x = x^+ - x^-$$ với $$x^+, x^- \geq 0$$ để đảm bảo mọi biến đều không âm.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-ứng-dụng-quy-hoạch-bậc-hai&quot;&gt;📝 &lt;strong&gt;Bài tập 4: Ứng dụng quy hoạch bậc hai&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 1.4 từ Boyd &amp;amp; Vandenberghe)
Xét bài toán tối ưu hóa danh mục đầu tư:&lt;/p&gt;

\[\min_x \frac{1}{2} x^T \Sigma x \quad \text{s.t.} \quad \mu^T x \geq r, \quad \mathbf{1}^T x = 1, \quad x \geq 0\]

&lt;p&gt;trong đó \(\Sigma \succ 0\) là ma trận hiệp phương sai, \(\mu\) là vector lợi suất kỳ vọng và \(r\) là mức lợi suất mục tiêu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh đây là bài toán QP lồi.&lt;/li&gt;
  &lt;li&gt;Viết hệ điều kiện KKT.&lt;/li&gt;
  &lt;li&gt;Phân tích trường hợp bỏ ràng buộc \(x \geq 0\).&lt;/li&gt;
  &lt;li&gt;Tìm đường biên hiệu quả (efficient frontier).&lt;/li&gt;
  &lt;li&gt;Cài đặt lời giải số.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Chứng minh tính lồi**
- Hàm mục tiêu: $$f(x) = \frac{1}{2} x^T \Sigma x$$ có Hessian $$\nabla^2 f = \Sigma \succ 0$$ nên là hàm lồi chặt.
- Các ràng buộc đều là bất đẳng thức và đẳng thức tuyến tính.
- $$\Rightarrow$$ Đây là bài toán QP lồi.

**Bước 2: Điều kiện KKT**
Hàm Lagrange (dùng $$\eta$$ làm nhân tử cho $$x \geq 0$$ để tránh trùng ký hiệu với $$\mu$$):
$$L(x,\lambda,\nu,\eta) = \frac{1}{2} x^T \Sigma x - \lambda(\mu^T x - r) + \nu(\mathbf{1}^T x - 1) - \eta^T x$$

Hệ điều kiện KKT:
- Điều kiện dừng (Stationarity): $$\Sigma x - \lambda \mu + \nu \mathbf{1} - \eta = 0$$.
- Tính khả thi gốc (Primal feasibility): $$\mu^T x \geq r, \mathbf{1}^T x = 1, x \geq 0$$.
- Tính khả thi đối ngẫu (Dual feasibility): $$\lambda \geq 0, \eta \geq 0$$.
- Điều kiện bù lỏng (Complementary slackness): $$\lambda(\mu^T x - r) = 0, \eta_i x_i = 0$$.

**Bước 3: Trường hợp bỏ ràng buộc $$x \geq 0$$ (giả sử ràng buộc lợi suất chặt, $$\mu^T x = r$$)**
Từ điều kiện dừng ta có:
$$x^* = \Sigma^{-1}(\lambda^* \mu - \nu^* \mathbf{1})$$

Thay vào hai ràng buộc đẳng thức:
- $$\mathbf{1}^T x^* = 1 \Rightarrow \mathbf{1}^T \Sigma^{-1}(\lambda^* \mu - \nu^* \mathbf{1}) = 1$$
- $$\mu^T x^* = r \Rightarrow \mu^T \Sigma^{-1}(\lambda^* \mu - \nu^* \mathbf{1}) = r$$

Thu được hệ phương trình tuyến tính 2 ẩn:
$$\begin{bmatrix} A &amp;amp; B \\ B &amp;amp; C \end{bmatrix} \begin{bmatrix} \lambda^* \\ -\nu^* \end{bmatrix} = \begin{bmatrix} r \\ 1 \end{bmatrix}$$

với $$A = \mu^T \Sigma^{-1} \mu, B = \mu^T \Sigma^{-1} \mathbf{1}, C = \mathbf{1}^T \Sigma^{-1} \mathbf{1}$$.

**Bước 4: Đường biên hiệu quả**
Phương sai rủi ro nhỏ nhất theo mức lợi suất mục tiêu $$r$$ là:
$$\sigma^2(r) = x^{*T} \Sigma x^* = \frac{Cr^2 - 2Br + A}{AC - B^2}$$

Đây là một nhánh hyperbol trong mặt phẳng $$(r, \sigma)$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-quy-hoạch-hình-học-geometric-programming&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Quy hoạch hình học (Geometric Programming)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 1.5 từ Boyd &amp;amp; Vandenberghe)
Xét bài toán thiết kế mạch điện:&lt;/p&gt;

\[\min_{x,y,z} \frac{1}{xyz} \quad \text{s.t.} \quad \frac{x}{y} + \frac{y}{z} \leq 1, \quad z \leq 1, \quad x,y,z &amp;gt; 0\]

&lt;p&gt;&lt;em&gt;(Ràng buộc \(z \leq 1\) là cần thiết: nếu bỏ ràng buộc này, khi nhân \((x, y, z)\) với hệ số \(s &amp;gt; 0\) thì ràng buộc thứ nhất không đổi nhưng \(\frac{1}{xyz} \to 0\) khi \(s \to \infty\), khiến bài toán không có nghiệm tối ưu.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh đây là một bài toán quy hoạch hình học (GP).&lt;/li&gt;
  &lt;li&gt;Chuyển bài toán về dạng lồi bằng phép đổi biến logarit.&lt;/li&gt;
  &lt;li&gt;Giải bài toán lồi thu được.&lt;/li&gt;
  &lt;li&gt;Diễn giải nghiệm trong bối cảnh thiết kế mạch.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Kiểm tra dạng quy hoạch hình học**
- Hàm mục tiêu: $$f_0(x,y,z) = x^{-1} y^{-1} z^{-1}$$ (đơn thức — monomial).
- Các ràng buộc: $$g_1(x,y,z) = x^1 y^{-1} z^0 + x^0 y^1 z^{-1}$$ (đa thức dương — posynomial) và $$g_2(x,y,z) = z$$ (đơn thức).
- Miền biến: $$x,y,z &amp;gt; 0$$.

$$\Rightarrow$$ Đây là bài toán GP ở dạng chuẩn.

**Bước 2: Phép đổi biến logarit**
Đặt $$u = \log x, v = \log y, w = \log z$$:

$$\min_{u,v,w} -u - v - w \quad \text{s.t.} \quad \log(e^{u-v} + e^{v-w}) \leq 0, \quad w \leq 0$$

Tương đương:
$$\min_{u,v,w} -u - v - w \quad \text{s.t.} \quad e^{u-v} + e^{v-w} \leq 1, \quad w \leq 0$$

**Bước 3: Xác nhận tính lồi**
Hàm mục tiêu là tuyến tính, $$\log(e^{u-v} + e^{v-w})$$ là hàm log-sum-exp của các hàm affine (nên lồi), còn $$w \leq 0$$ là ràng buộc tuyến tính.

Vậy bài toán sau đổi biến là bài toán tối ưu hóa lồi.

**Bước 4: Nghiệm tối ưu**
Có thể giải tổng quát bằng phương pháp điểm trong hoặc các bộ giải GP chuyên dụng. Ở bài toán nhỏ này ta giải trực tiếp được:
- Nghiệm trong biến gốc liên hệ qua $$x^* = e^{u^*}, y^* = e^{v^*}, z^* = e^{w^*}$$.
- Cả hai ràng buộc đều chặt tại nghiệm tối ưu. Với $$z = 1$$, bài toán trở thành $$\max xy$$ s.t. $$x \leq y(1 - y)$$, tức $$\max_y y^2(1-y)$$, đạt cực đại tại $$y = 2/3$$.
- Nghiệm tối ưu: $$x^* = 2/9$$, $$y^* = 2/3$$, $$z^* = 1$$; kiểm tra $$\frac{x^*}{y^*} + \frac{y^*}{z^*} = \frac{1}{3} + \frac{2}{3} = 1$$ ✓; giá trị tối ưu $$\frac{1}{x^*y^*z^*} = \frac{27}{4}$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-6-cơ-bản-về-quy-hoạch-nửa-xác-định-sdp&quot;&gt;📝 &lt;strong&gt;Bài tập 6: Cơ bản về quy hoạch nửa xác định (SDP)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 1.6 từ Boyd &amp;amp; Vandenberghe)
Xét bài toán:&lt;/p&gt;

\[\min_X \text{tr}(CX) \quad \text{s.t.} \quad \text{tr}(A_i X) = b_i, \quad i = 1,\ldots,m, \quad X \succeq 0\]

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh đây là bài toán tối ưu hóa lồi.&lt;/li&gt;
  &lt;li&gt;Xây dựng bài toán đối ngẫu.&lt;/li&gt;
  &lt;li&gt;Phân tích điều kiện đối ngẫu mạnh (strong duality).&lt;/li&gt;
  &lt;li&gt;Nêu ví dụ cụ thể: nới lỏng SDP cho bài toán cắt cực đại (Maximum Cut).&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Chứng minh tính lồi**
- Hàm mục tiêu: $$\text{tr}(CX)$$ là hàm tuyến tính theo ma trận $$X$$.
- Các ràng buộc đẳng thức: $$\text{tr}(A_i X) = b_i$$ là các ràng buộc tuyến tính.
- Ràng buộc nón: $$X \succeq 0$$ xác định nón các ma trận đối xứng nửa xác định dương, vốn là một tập lồi.

$$\Rightarrow$$ Đây là bài toán quy hoạch nửa xác định (SDP) lồi.

**Bước 2: Bài toán đối ngẫu**
Hàm Lagrange: $$L(X,y,Z) = \text{tr}(CX) + \sum_{i=1}^m y_i (b_i - \text{tr}(A_i X)) - \text{tr}(ZX)$$

Hàm đối ngẫu: $$g(y,Z) = \inf_X L(X,y,Z)$$

Để hàm đối ngẫu hữu hạn, hệ số của $$X$$ phải bằng không: $$C - \sum_{i=1}^m y_i A_i - Z = 0$$.

**Bài toán đối ngẫu:**
$$\max_{y,Z} \sum_{i=1}^m b_i y_i \quad \text{s.t.} \quad \sum_{i=1}^m y_i A_i + Z = C, \quad Z \succeq 0$$

**Bước 3: Đối ngẫu mạnh**
Đối ngẫu mạnh xảy ra khi điều kiện Slater được thỏa mãn (bài toán gốc khả thi chặt):
$$\exists X \succ 0 \text{ s.t. } \text{tr}(A_i X) = b_i, \forall i$$

**Bước 4: Ví dụ nới lỏng cho bài toán cắt cực đại (Max-Cut)**
Cho đồ thị $$G = (V,E)$$ với trọng số cạnh $$w_{ij}$$:

$$\max_x \sum_{(i,j) \in E} w_{ij} \frac{1 - x_i x_j}{2} \quad \text{s.t.} \quad x_i \in \{-1,1\}$$

**Nới lỏng SDP:**
$$\max_X \sum_{(i,j) \in E} w_{ij} \frac{1 - X_{ij}}{2} \quad \text{s.t.} \quad X_{ii} = 1, \quad X \succeq 0$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-7-giới-thiệu-tối-ưu-hóa-bền-vững-robust-optimization&quot;&gt;📝 &lt;strong&gt;Bài tập 7: Giới thiệu tối ưu hóa bền vững (Robust Optimization)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 1.7 từ Boyd &amp;amp; Vandenberghe)
Xét bài toán quy hoạch tuyến tính bền vững:&lt;/p&gt;

\[\min_x c^T x \quad \text{s.t.} \quad a_i^T x \leq b_i \quad \forall a_i \in \mathcal{U}_i, \quad i = 1,\ldots,m\]

&lt;p&gt;với hai dạng tập bất định (uncertainty sets):
a) Dạng hình hộp (Box): \(\mathcal{U}_i = \{a_i^{nom} + u : \lVert u \rVert_\infty \leq \rho_i\}\)
b) Dạng ellipsoid: \(\mathcal{U}_i = \{a_i^{nom} + P_i u : \lVert u \rVert_2 \leq 1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Biến đổi thành các bài toán tối ưu hóa lồi tất định tương đương.&lt;/li&gt;
  &lt;li&gt;So sánh độ phức tạp tính toán.&lt;/li&gt;
  &lt;li&gt;Phân tích mức độ bảo thủ của từng dạng tập bất định.&lt;/li&gt;
  &lt;li&gt;Cài đặt và so sánh nghiệm thu được.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Tập bất định dạng hình hộp**
$$\max_{a_i \in \mathcal{U}_i} a_i^T x = (a_i^{nom})^T x + \rho_i \lVert x \rVert_1$$

**Bài toán tất định tương đương:**
$$\min_x c^T x \quad \text{s.t.} \quad (a_i^{nom})^T x + \rho_i \lVert x \rVert_1 \leq b_i$$

**Đưa về dạng LP:**
$$\min_{x,t_i} c^T x \quad \text{s.t.} \quad (a_i^{nom})^T x + \rho_i \sum_j t_{ij} \leq b_i, \quad -t_{ij} \leq x_j \leq t_{ij}$$

**Bước 2: Tập bất định dạng ellipsoid**
$$\max_{a_i \in \mathcal{U}_i} a_i^T x = (a_i^{nom})^T x + \lVert P_i^T x \rVert_2$$

**Bài toán tất định tương đương:**
$$\min_x c^T x \quad \text{s.t.} \quad (a_i^{nom})^T x + \lVert P_i^T x \rVert_2 \leq b_i$$

Đây là một bài toán quy hoạch nón bậc hai (SOCP).

**Bước 3: So sánh độ phức tạp**
- **Hình hộp:** bài toán LP với $$O(mn)$$ biến và ràng buộc (khi đặt riêng $$t_{ij}$$).
- **Ellipsoid:** bài toán SOCP với $$n + m$$ biến (hoặc $$n$$ biến trực tiếp) và $$m$$ ràng buộc nón bậc hai.
- **Danh nghĩa (Nominal):** bài toán LP với $$n$$ biến và $$m$$ ràng buộc.

**Bước 4: Phân tích mức độ bảo thủ**
- **Hình hộp:** bảo thủ nhất (xét trường hợp xấu nhất đồng thời trên mọi tọa độ).
- **Ellipsoid:** bảo thủ ở mức trung bình (giới hạn tổng độ lệch theo chuẩn Euclid).
- **Danh nghĩa:** ít bảo thủ nhất (bỏ qua tính bất định).

&quot;Chi phí của tính bền vững&quot; (price of robustness) thường được đo bằng: $$\frac{\text{Giá trị tối ưu bền vững}}{\text{Giá trị tối ưu danh nghĩa}} - 1$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-8-kiểm-tra-tính-lồi&quot;&gt;📝 &lt;strong&gt;Bài tập 8: Kiểm tra tính lồi&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 1.8 từ Boyd &amp;amp; Vandenberghe)
Xác định tính lồi của các hàm số sau:&lt;/p&gt;

&lt;p&gt;a) \(f(x) = x \log x\) trên \(\mathbb{R}_{++}\)
b) \(f(x) = -\log(\det X)\) trên \(\mathbb{S}_{++}^n\)
c) \(f(x) = \lVert x \rVert_p\) với \(p \geq 1\)
d) \(f(X) = \lambda_{\max}(X)\) trên \(\mathbb{S}^n\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chứng minh hoặc phản chứng tính lồi của từng hàm.&lt;/li&gt;
  &lt;li&gt;Áp dụng điều kiện bậc hai khi phù hợp.&lt;/li&gt;
  &lt;li&gt;Kiểm chứng bằng định nghĩa hoặc các quy tắc bảo toàn tính lồi.&lt;/li&gt;
  &lt;li&gt;Xác định miền xác định lồi của mỗi hàm.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: $$f(x) = x \log x$$**
- **Miền xác định:** $$\mathbb{R}_{++}$$ (tập lồi).
- **Đạo hàm bậc hai:** $$f&apos;&apos;(x) = \frac{1}{x} &amp;gt; 0$$ với mọi $$x &amp;gt; 0$$.
- $$\Rightarrow$$ Hàm lồi chặt trên $$\mathbb{R}_{++}$$.

**Bước 2: $$f(X) = -\log(\det X)$$**
- **Miền xác định:** $$\mathbb{S}_{++}^n$$ (nón ma trận đối xứng xác định dương, là tập lồi).
- **Hessian:** có thể chứng minh $$\nabla^2 f \succ 0$$.
- Biểu diễn theo giá trị riêng: $$-\log(\det X) = -\log(\prod_i \lambda_i) = -\sum_i \log \lambda_i$$.
- Lưu ý: lập luận tách riêng từng giá trị riêng là chưa đủ (các giá trị riêng nói chung không phải hàm lõm của $$X$$; chỉ $$\lambda_{\min}$$ là hàm lõm). Cách chứng minh chuẩn là hạn chế hàm lên một đường thẳng bất kỳ $$X = Z + tV$$ với $$Z \succ 0$$: ta có $$f(Z + tV) = -\log\det Z - \sum_i \log(1 + t\lambda_i)$$, trong đó $$\lambda_i$$ là các giá trị riêng của $$Z^{-1/2} V Z^{-1/2}$$. Mỗi số hạng $$-\log(1 + t\lambda_i)$$ lồi theo $$t$$, nên $$f$$ lồi.
- **Kết luận:** Hàm lồi trên $$\mathbb{S}_{++}^n$$.

**Bước 3: $$f(x) = \lVert x \rVert_p$$**
- **Miền xác định:** $$\mathbb{R}^n$$ (tập lồi).
- **Với $$p \geq 1$$:** bất đẳng thức tam giác (bất đẳng thức Minkowski) kết hợp với tính thuần nhất dương kéo theo tính lồi.
- **Với $$0 &amp;lt; p &amp;lt; 1$$:** không lồi (bất đẳng thức tam giác bị vi phạm; ví dụ với $$p = 1/2$$, $$\lVert (1,1) \rVert_{1/2} = 4 &amp;gt; \lVert (1,0) \rVert_{1/2} + \lVert (0,1) \rVert_{1/2} = 2$$).

**Bước 4: $$f(X) = \lambda_{\max}(X)$$**
- **Miền xác định:** $$\mathbb{S}^n$$ (tập lồi).
- **Chứng minh tính lồi:** theo biểu diễn thương Rayleigh, $$\lambda_{\max}(X) = \max_{\lVert v \rVert = 1} v^T X v$$.
- Vì mỗi hàm $$X \mapsto v^T X v$$ là hàm tuyến tính theo $$X$$, giá trị lớn nhất theo điểm của một họ hàm tuyến tính là hàm lồi.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-9-mô-hình-hóa-bài-toán-tối-ưu&quot;&gt;📝 &lt;strong&gt;Bài tập 9: Mô hình hóa bài toán tối ưu&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 1.9 từ Boyd &amp;amp; Vandenberghe)
Mô hình hóa các bài toán kỹ thuật sau dưới dạng bài toán tối ưu hóa lồi:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Thiết kế mảng ăng-ten:&lt;/strong&gt; cực tiểu hóa mức búp phụ (sidelobe level).
b) &lt;strong&gt;Thiết kế bộ lọc:&lt;/strong&gt; cực tiểu hóa gợn dải thông (passband ripple) và năng lượng dải chắn (stopband energy).
c) &lt;strong&gt;Thiết kế dàn kết cấu (truss design):&lt;/strong&gt; cực tiểu hóa khối lượng với ràng buộc độ cứng.
d) &lt;strong&gt;Khớp dữ liệu:&lt;/strong&gt; hồi quy bền vững khi dữ liệu có điểm ngoại lai.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Xây dựng mô hình toán học cho từng bài toán.&lt;/li&gt;
  &lt;li&gt;Xác định rõ biến quyết định, hàm mục tiêu và các ràng buộc.&lt;/li&gt;
  &lt;li&gt;Kiểm chứng tính lồi của mô hình.&lt;/li&gt;
  &lt;li&gt;Đề xuất hướng giải phù hợp.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Thiết kế mảng ăng-ten**
- **Biến quyết định:** $$w \in \mathbb{C}^n$$ (vector trọng số của các phần tử mảng).
- **Hàm mục tiêu:** cực tiểu hóa biên độ búp phụ lớn nhất:
$$\min_{w,t} t \quad \text{s.t.} \quad |a(\theta)^H w| \leq t, \quad \forall \theta \in \Theta_{sidelobe}$$
trong đó $$a(\theta)$$ là vector lái (steering vector) và $$\Theta_{sidelobe}$$ là miền góc búp phụ.
- **Ràng buộc búp chính:** $$a(\theta_0)^H w = 1$$ (chuẩn hóa độ lợi theo hướng mục tiêu).
- **Tính lồi:** là bài toán SOCP (các ràng buộc mô-đun phức là ràng buộc nón bậc hai).

**Bước 2: Thiết kế bộ lọc**
- **Biến quyết định:** $$h \in \mathbb{R}^n$$ (các hệ số của bộ lọc).
- **Gợn dải thông:** $$|H(\omega) - 1| \leq \delta_p, \quad \omega \in \Omega_p$$
- **Suy hao dải chắn:** $$|H(\omega)| \leq \delta_s, \quad \omega \in \Omega_s$$
trong đó $$H(\omega) = \sum_{k=0}^{n-1} h_k e^{-j\omega k}$$ là đáp ứng tần số.
- **Mô hình lồi:**
$$\min_{h,\delta_p,\delta_s} \alpha \delta_p + \beta \delta_s$$
với các ràng buộc đáp ứng tần số nêu trên.

**Bước 3: Thiết kế dàn kết cấu**
- **Biến quyết định:** $$A \in \mathbb{R}^m$$ (diện tích mặt cắt ngang các thanh dàn).
- **Hàm mục tiêu:** $$\min \sum_{i=1}^m \rho_i l_i A_i$$ (tổng khối lượng).
- **Ràng buộc độ cứng:** $$u^T K(A) u \geq u_{min}^T K_0 u_{min}$$
với $$K(A) = \sum_{i=1}^m A_i K_i$$ là ma trận độ cứng tổng thể.
- **Tính lồi:** hàm mục tiêu tuyến tính và ràng buộc tuyến tính theo $$A$$ (với chuyển vị $$u$$ cố định).

**Bước 4: Hồi quy bền vững**
- **Biến quyết định:** $$\beta \in \mathbb{R}^p$$ (vector hệ số hồi quy).
- **Hàm mất mát Huber:** $$\min_\beta \sum_{i=1}^n \phi(y_i - x_i^T \beta)$$
với $$\phi(u) = \begin{cases} \frac{1}{2}u^2 &amp;amp; |u| \leq M \\ M|u| - \frac{1}{2}M^2 &amp;amp; |u| &amp;gt; M \end{cases}$$
- **Tính lồi:** hàm Huber là hàm lồi, nên bài toán tối ưu là lồi.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-10-nhập-môn-lý-thuyết-đối-ngẫu&quot;&gt;📝 &lt;strong&gt;Bài tập 10: Nhập môn lý thuyết đối ngẫu&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; (Bài 1.10 từ Boyd &amp;amp; Vandenberghe)
Cho bài toán quy hoạch tuyến tính (LP):
\(\min_x c^T x \quad \text{s.t.} \quad Ax = b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Xây dựng bài toán đối ngẫu thông qua hàm Lagrange.&lt;/li&gt;
  &lt;li&gt;Chứng minh định lý đối ngẫu yếu (weak duality).&lt;/li&gt;
  &lt;li&gt;Nêu điều kiện để đối ngẫu mạnh (strong duality) xảy ra.&lt;/li&gt;
  &lt;li&gt;Diễn giải ý nghĩa kinh tế của các biến đối ngẫu.&lt;/li&gt;
  &lt;li&gt;Phát biểu điều kiện bù lỏng (complementary slackness).&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Hàm Lagrange và bài toán đối ngẫu**
$$L(x,\nu,\lambda) = c^T x + \nu^T(Ax - b) - \lambda^T x$$

**Hàm đối ngẫu:**
$$g(\nu,\lambda) = \inf_x L(x,\nu,\lambda) = \inf_x (c + A^T \nu - \lambda)^T x - \nu^T b$$

**Điều kiện để hàm đối ngẫu hữu hạn:** $$c + A^T \nu - \lambda = 0$$, tức $$\lambda = A^T \nu + c$$.

**Bài toán đối ngẫu:**
$$\max_{\nu,\lambda} g(\nu,\lambda) = \max_\nu -\nu^T b \quad \text{s.t.} \quad A^T \nu + c \geq 0$$

Đổi dấu biến $$\nu \leftarrow -\nu$$, ta viết lại ở dạng quen thuộc:
$$\max_\nu b^T \nu \quad \text{s.t.} \quad A^T \nu \leq c$$

**Bước 2: Đối ngẫu yếu**
Với mọi nghiệm khả thi gốc $$x$$ và nghiệm khả thi đối ngẫu $$\nu$$:
$$c^T x \geq b^T \nu$$

**Chứng minh:**
$$c^T x \geq (A^T \nu)^T x = \nu^T Ax = \nu^T b = b^T \nu$$

**Bước 3: Đối ngẫu mạnh**
Với bài toán LP, đối ngẫu mạnh luôn đúng khi cả bài toán gốc và bài toán đối ngẫu đều khả thi (định lý cơ bản của quy hoạch tuyến tính).

**Bước 4: Ý nghĩa kinh tế**
- $$\nu_i$$ là giá ẩn (shadow price) của nguồn lực thứ $$i$$.
- $$\nu_i$$ biểu thị giá trị biên của ràng buộc thứ $$i$$: nếu $$b_i$$ tăng thêm 1 đơn vị (trong phạm vi cơ sở tối ưu không đổi), giá trị tối ưu thay đổi xấp xỉ một lượng $$\nu_i$$.

**Bước 5: Điều kiện bù lỏng (Complementary slackness)**
- Nếu $$x_j^* &amp;gt; 0$$ thì $$(A^T \nu^*)_j = c_j$$ (chi phí giảm bằng 0).
- Nếu $$(A^T \nu^*)_j &amp;lt; c_j$$ thì $$x_j^* = 0$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-kinh-nghiệm-thực-hành&quot;&gt;💡 Kinh nghiệm thực hành&lt;/h2&gt;

&lt;h4 id=&quot;khi-phân-loại-bài-toán-tối-ưu-hóa&quot;&gt;&lt;strong&gt;Khi phân loại bài toán tối ưu hóa:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Kiểm tra dạng của hàm mục tiêu (tuyến tính, bậc hai hay tổng quát).&lt;/li&gt;
  &lt;li&gt;Xác định loại ràng buộc (tuyến tính, bậc hai hay nón).&lt;/li&gt;
  &lt;li&gt;Kiểm tra tính lồi của từng thành phần.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;khi-chuyển-đổi-về-dạng-chuẩn&quot;&gt;&lt;strong&gt;Khi chuyển đổi về dạng chuẩn:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Biến tự do: tách thành hiệu hai biến không âm \(x = x^+ - x^-\).&lt;/li&gt;
  &lt;li&gt;Bất đẳng thức: bổ sung biến bù (slack/surplus).&lt;/li&gt;
  &lt;li&gt;Bài toán cực đại: đổi dấu hàm mục tiêu để chuyển thành cực tiểu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;khi-xác-minh-tính-lồi&quot;&gt;&lt;strong&gt;Khi xác minh tính lồi:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Ưu tiên điều kiện bậc hai khi hàm khả vi hai lần.&lt;/li&gt;
  &lt;li&gt;Áp dụng các phép toán bảo toàn tính lồi.&lt;/li&gt;
  &lt;li&gt;Quay về định nghĩa trực tiếp khi cần thiết.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;phân-loại-các-lớp-bài-toán-tối-ưu&quot;&gt;&lt;strong&gt;Phân loại các lớp bài toán tối ưu&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Loại&lt;/th&gt;
      &lt;th&gt;Hàm mục tiêu&lt;/th&gt;
      &lt;th&gt;Ràng buộc&lt;/th&gt;
      &lt;th&gt;Ví dụ&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;LP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
      &lt;td&gt;\(\min c^Tx\), \(Ax \leq b\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Bậc hai&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
      &lt;td&gt;\(\min \frac{1}{2}x^TQx + c^Tx\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QCQP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Bậc hai&lt;/td&gt;
      &lt;td&gt;Bậc hai&lt;/td&gt;
      &lt;td&gt;Danh mục đầu tư có ràng buộc rủi ro&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SOCP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
      &lt;td&gt;Chuẩn \(\ell_2\)&lt;/td&gt;
      &lt;td&gt;\(||Ax-b||_2 \leq c^Tx\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SDP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tuyến tính&lt;/td&gt;
      &lt;td&gt;Ma trận nửa xác định dương&lt;/td&gt;
      &lt;td&gt;\(\min \text{tr}(CX)\), \(X \succeq 0\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;các-biến-thể-bình-phương-tối-thiểu&quot;&gt;&lt;strong&gt;Các biến thể bình phương tối thiểu&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Hàm mục tiêu&lt;/th&gt;
      &lt;th&gt;Đặc điểm&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Bình phương tối thiểu (OLS)&lt;/td&gt;
      &lt;td&gt;\(||Ax-b||_2^2\)&lt;/td&gt;
      &lt;td&gt;Có nghiệm dạng đóng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Có trọng số (WLS)&lt;/td&gt;
      &lt;td&gt;\((Ax-b)^TW(Ax-b)\)&lt;/td&gt;
      &lt;td&gt;Gán trọng số khác nhau cho từng quan sát&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Có điều chuẩn (Ridge)&lt;/td&gt;
      &lt;td&gt;\(||Ax-b||_2^2 + \lambda||x||_2^2\)&lt;/td&gt;
      &lt;td&gt;Giảm quá khớp, ổn định ma trận&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bền vững (Robust LS)&lt;/td&gt;
      &lt;td&gt;\(\sum \phi((Ax-b)_i)\)&lt;/td&gt;
      &lt;td&gt;Ít nhạy cảm với điểm ngoại lai&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;LASSO&lt;/td&gt;
      &lt;td&gt;\(||Ax-b||_2^2 + \lambda||x||_1\)&lt;/td&gt;
      &lt;td&gt;Tạo nghiệm thưa (sparse)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;các-khái-niệm-đối-ngẫu-cốt-lõi&quot;&gt;&lt;strong&gt;Các khái niệm đối ngẫu cốt lõi&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu yếu:&lt;/strong&gt; \(d^* \leq p^*\) (luôn đúng).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối ngẫu mạnh:&lt;/strong&gt; \(d^* = p^*\) (đúng khi thỏa điều kiện chính quy, ví dụ điều kiện Slater).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giá ẩn (Shadow price):&lt;/strong&gt; \(\nu_i^*\) là giá trị biên của ràng buộc thứ \(i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù lỏng:&lt;/strong&gt; \(\lambda_i^* (g_i(x^*)) = 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 Tài liệu tham khảo&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 1: Introduction&lt;/li&gt;
      &lt;li&gt;Exercises 1.1–1.15&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nocedal, J., &amp;amp; Wright, S. J.&lt;/strong&gt; (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt;. Springer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bertsekas, D. P.&lt;/strong&gt; (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt;. Athena Scientific.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>01-06 Bài tập trắc nghiệm - Bài toán tối ưu hóa</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_06_Quiz_Optimization_Problems/"/>
   <updated>2021-01-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_06_Quiz_Optimization_Problems</id>
   <content type="html">&lt;p&gt;Sai lầm phổ biến nhất của người mới học tối ưu hóa lồi không phải là tính đạo hàm sai, mà là &lt;strong&gt;nhận diện nhầm bài toán lồi với bài toán không lồi&lt;/strong&gt; ngay từ dòng đề bài đầu tiên. Chỉ cần một dấu bất đẳng thức bị đảo ngược (\(\ge\) thay vì \(\le\) trên một hàm lồi), hay một ràng buộc đẳng thức bậc hai như \(x_1^2 + x_2^2 = 1\), toàn bộ tính lồi của miền khả thi lập tức biến mất.&lt;/p&gt;

&lt;p&gt;Bộ trắc nghiệm này kiểm tra phản xạ phân loại bài toán tối ưu của bạn. Trước khi bắt đầu, hãy ôn nhanh 3 tiêu chí vàng và tự tay kiểm tra 3 ví dụ “bẫy” kinh điển ngay sau đây.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-chốt-kiểm-tra-nhanh-bài-toán-tối-ưu-hóa-lồi&quot;&gt;Kiến thức cần nhớ: Ba chốt kiểm tra nhanh bài toán tối ưu hóa lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chốt 1 — Hàm mục tiêu \(f_0(x)\):&lt;/strong&gt; Nếu bài toán là \(\min f_0\) thì \(f_0\) phải lồi; nếu là \(\max f_0\) thì \(f_0\) phải lõm (tức \(-f_0\) lồi).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chốt 2 — Ràng buộc bất đẳng thức \(g_i(x) \le 0\):&lt;/strong&gt; Mỗi \(g_i\) phải là hàm lồi (nếu đề viết \(u(x) \ge 0\) thì \(u\) phải là hàm lõm để \(-u(x) \le 0\) lồi).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chốt 3 — Ràng buộc đẳng thức \(h_j(x) = 0\):&lt;/strong&gt; Bắt buộc phải là hàm affine \(a_j^T x + b_j = 0\); mọi đẳng thức phi tuyến (trừ trường hợp đặc biệt rút gọn được) đều phá vỡ tính lồi của miền khả thi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phân-loại-3-bài-toán-thoạt-nhìn-rất-giống-nhau&quot;&gt;Giải thích: Phân loại 3 bài toán thoạt nhìn rất giống nhau&lt;/h3&gt;

&lt;p&gt;Hãy kiểm tra tính lồi của ba bài toán trên \(\mathbb{R}^2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán A:&lt;/strong&gt; \(\min 2x_1 - x_2\) thỏa mãn \(x_1 + 2x_2 \le 4\).
    &lt;ul&gt;
      &lt;li&gt;Hàm mục tiêu tuyến tính (lồi), ràng buộc \(x_1 + 2x_2 - 4 \le 0\) là hàm affine (lồi).&lt;/li&gt;
      &lt;li&gt;Kết luận: &lt;strong&gt;Quy hoạch tuyến tính (LP)&lt;/strong&gt; \(\subset\) bài toán tối ưu hóa lồi.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán B:&lt;/strong&gt; \(\min x_1^2 + x_2^2\) thỏa mãn \(x_1^2 + x_2^2 \ge 1\).
    &lt;ul&gt;
      &lt;li&gt;Hàm mục tiêu lồi, nhưng ràng buộc là \(g(x) = 1 - (x_1^2 + x_2^2) \le 0\) — hàm \(g\) là hàm &lt;strong&gt;lõm&lt;/strong&gt;, không phải hàm lồi!&lt;/li&gt;
      &lt;li&gt;Phản ví dụ trực tiếp: \(x = (1, 0)\) và \(y = (-1, 0)\) đều khả thi (\(1 \ge 1\)), nhưng trung điểm \(\frac{1}{2}(x + y) = (0, 0)\) có \(0^2 + 0^2 = 0 &amp;lt; 1\) (nằm ngoài miền khả thi!).&lt;/li&gt;
      &lt;li&gt;Kết luận: &lt;strong&gt;Không lồi&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán C:&lt;/strong&gt; \(\min x_1^2 + x_2^2\) thỏa mãn \(x_1^2 + x_2^2 \le 1\).
    &lt;ul&gt;
      &lt;li&gt;Đảo dấu bất đẳng thức thành \(x_1^2 + x_2^2 - 1 \le 0\) biến miền khả thi thành hình tròn đặc (tập lồi).&lt;/li&gt;
      &lt;li&gt;Kết luận: &lt;strong&gt;Bài toán tối ưu hóa lồi&lt;/strong&gt; (cụ thể là QCQP lồi), đạt cực tiểu duy nhất tại \(x^* = (0, 0)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài tập trắc nghiệm này giúp bạn kiểm tra mức độ nắm vững các khái niệm cơ bản về bài toán tối ưu hóa và tối ưu hóa lồi.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy điểm lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-bài-toán-tối-ưu-hóa-tổng-quát&quot;&gt;🎯 &lt;strong&gt;Bài toán tối ưu hóa tổng quát&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Dạng chuẩn:&lt;/strong&gt;
\(egin{align*} 
&amp;amp;\min_{x\in D}\ &amp;amp;&amp;amp;f(x) \
&amp;amp;	ext{với điều kiện} &amp;amp;&amp;amp; g_i(x) \le 0,\ i = 1, ..., m \
&amp;amp;&amp;amp;&amp;amp; h_j(x) = 0,\ j = 1,\ ..., r
\end{align*}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Các thành phần:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\): biến tối ưu hóa (biến quyết định).&lt;/li&gt;
  &lt;li&gt;\(f(x)\): hàm mục tiêu (objective function) hoặc hàm chi phí.&lt;/li&gt;
  &lt;li&gt;\(g_i(x) \le 0\): ràng buộc bất đẳng thức (inequality constraints).&lt;/li&gt;
  &lt;li&gt;\(h_j(x) = 0\): ràng buộc đẳng thức (equality constraints).&lt;/li&gt;
  &lt;li&gt;\(x^*\): nghiệm tối ưu (optimal solution).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Miền xác định chung:&lt;/strong&gt;
\(D = 	ext{dom}(f) \cap igcap_{i=1}^m 	ext{dom}(g_i) \cap igcap_{j=1}^r 	ext{dom}(h_j)\)&lt;/p&gt;

&lt;h3 id=&quot;-tập-lồi-convex-sets&quot;&gt;🔵 &lt;strong&gt;Tập lồi (Convex Sets)&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt;
Tập \(C\) là tập lồi nếu với mọi \(x_1, x_2 \in C\) và \(0 \le 	heta \le 1\):
\(heta x_1 + (1-	heta)x_2 \in C\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Đoạn thẳng:&lt;/strong&gt; \(x = 	heta x_1 + (1 - 	heta) x_2\) với \(0 \le 	heta \le 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tổ hợp lồi:&lt;/strong&gt; 
\(x = \sum_{i=1}^k 	heta_i x_i\) với \(\sum_{i=1}^k 	heta_i = 1, 	heta_i \ge 0\)&lt;/p&gt;

&lt;h3 id=&quot;-hàm-lồi-convex-functions&quot;&gt;📈 &lt;strong&gt;Hàm lồi (Convex Functions)&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt;
Hàm \(f: \mathbb{R}^n 
ightarrow \mathbb{R}\) là hàm lồi nếu:&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;\(ext{dom}(f)\) là tập lồi.&lt;/li&gt;
    &lt;li&gt;\(f(	heta x + (1 - 	heta)y) \le 	heta f(x) + (1-	heta)f(y)\)
với mọi \(x, y \in 	ext{dom}(f), 0 \le 	heta \le 1\).&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Biểu đồ trên (Epigraph):&lt;/strong&gt;
\(ext{epi } f = \{(x, t) \in \mathbb{R}^{n+1} \mid x \in 	ext{dom } f, f(x) \le t\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất quan trọng:&lt;/strong&gt; \(f\) lồi ⟺ \(ext{epi } f\) là tập lồi.&lt;/p&gt;

&lt;h3 id=&quot;-bài-toán-tối-ưu-hóa-lồi&quot;&gt;🏆 &lt;strong&gt;Bài toán tối ưu hóa lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt;
Bài toán tối ưu hóa là bài toán lồi khi:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Hàm mục tiêu \(f\) là hàm lồi.&lt;/li&gt;
    &lt;li&gt;Các hàm ràng buộc bất đẳng thức \(g_i\) là hàm lồi.&lt;/li&gt;
    &lt;li&gt;Các hàm ràng buộc đẳng thức \(h_j\) là hàm affine: \(h_j(x) = a_j^T x + b_j\).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Tính chất cốt lõi:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Mọi cực tiểu địa phương của bài toán tối ưu hóa lồi đều là cực tiểu toàn cục.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Hàm affine:&lt;/strong&gt; \(f(x) = Ax + b\) (hàm tuyến tính cộng với một hằng số).&lt;/p&gt;

&lt;h3 id=&quot;-hàm-lõm-và-hàm-lồi&quot;&gt;🔄 &lt;strong&gt;Hàm lõm và hàm lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hàm lõm:&lt;/strong&gt; \(f\) lõm ⟺ \(-f\) lồi
\(f(	heta x + (1 - 	heta)y) \ge 	heta f(x) + (1-	heta)f(y)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chuyển đổi:&lt;/strong&gt; Cực đại hóa hàm lõm \(f\) tương đương cực tiểu hóa hàm lồi \(-f\).&lt;/p&gt;

&lt;h3 id=&quot;-mục-tiêu-khóa-học&quot;&gt;🎯 &lt;strong&gt;Mục tiêu khóa học&lt;/strong&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhận biết:&lt;/strong&gt; xác định khi nào một bài toán là tối ưu hóa lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình hóa:&lt;/strong&gt; chuyển bài toán thực tế thành bài toán tối ưu hóa lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn:&lt;/strong&gt; chọn thuật toán phù hợp nhất cho từng lớp bài toán.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;️-các-thuật-toán-chính&quot;&gt;🛠️ &lt;strong&gt;Các thuật toán chính&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent:&lt;/strong&gt; phương pháp bậc nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp Newton:&lt;/strong&gt; phương pháp bậc hai.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Proximal Gradient:&lt;/strong&gt; dành cho hàm mục tiêu có phần không khả vi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ADMM:&lt;/strong&gt; phù hợp với bài toán có cấu trúc tách được.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate Descent:&lt;/strong&gt; tối ưu hóa luân phiên theo từng tọa độ/khối biến.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Gợi ý:&lt;/strong&gt; Tối ưu hóa lồi có một tính chất rất thuận lợi: không có cực tiểu địa phương tách biệt với cực tiểu toàn cục — mọi cực tiểu địa phương đều là cực tiểu toàn cục.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Bài tập trắc nghiệm: Bài toán tối ưu hóa&lt;/h2&gt;
        &lt;p&gt;Chọn đáp án đúng nhất cho mỗi câu hỏi. Bạn sẽ nhận được kết quả ngay sau khi hoàn thành.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Câu hỏi 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Câu hỏi 1: Định nghĩa bài toán tối ưu hóa --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Câu 1: Trong dạng chuẩn của bài toán tối ưu hóa, $$f(x)$$ được gọi là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Hàm ràng buộc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Hàm mục tiêu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Biến tối ưu hóa&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Miền khả thi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Hàm mục tiêu&lt;/strong&gt;&lt;br /&gt;
                Trong bài toán tối ưu hóa $$\min_{x\in D} f(x)$$, hàm $$f(x)$$ là hàm mục tiêu (objective function) hoặc hàm chi phí (cost function) mà chúng ta muốn tối thiểu hóa.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Ràng buộc tường minh vs ngầm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Cho bài toán $$\min \log(x)$$. Ràng buộc $$x &amp;gt; 0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) Ràng buộc tường minh&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) Ràng buộc ngầm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Ràng buộc đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Không phải ràng buộc&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Ràng buộc ngầm&lt;/strong&gt;&lt;br /&gt;
                Ràng buộc $$x &amp;gt; 0$$ phát sinh từ miền xác định của hàm $$\log(x)$$, không được chỉ định trực tiếp trong bài toán, nên được gọi là ràng buộc ngầm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Định nghĩa tập lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Một tập $$C$$ được gọi là lồi nếu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) Với mọi $$x_1, x_2 \in C$$ và $$0 \leq \theta \leq 1$$, ta có $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) Tập $$C$$ là hình tròn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) Tập $$C$$ không có lỗ hổng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) Tập $$C$$ là tập đóng&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Với mọi $$x_1, x_2 \in C$$ và $$0 \leq \theta \leq 1$$, ta có $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/strong&gt;&lt;br /&gt;
                Định nghĩa tập lồi: đoạn thẳng nối bất kỳ hai điểm nào trong tập đều nằm hoàn toàn trong tập đó.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Hàm lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Hàm $$f$$ là lồi nếu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$f(\theta x + (1-\theta)y) \geq \theta f(x) + (1-\theta)f(y)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) $$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) $$f(\theta x + (1-\theta)y) = \theta f(x) + (1-\theta)f(y)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) $$f$$ là hàm tuyến tính&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$&lt;/strong&gt;&lt;br /&gt;
                Định nghĩa hàm lồi: đoạn thẳng nối hai điểm bất kỳ trên đồ thị nằm phía trên đồ thị của hàm số.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Hàm lõm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Nếu $$f$$ là hàm lõm, thì $$-f$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Hàm lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Hàm lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Hàm tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Không xác định được&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Hàm lồi&lt;/strong&gt;&lt;br /&gt;
                Theo định nghĩa, hàm $$f$$ là lõm khi và chỉ khi $$-f$$ là lồi. Đây là cách chuyển đổi bài toán tối đa hóa hàm lõm thành tối thiểu hóa hàm lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Epigraph --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Epigraph của hàm $$f$$ được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) $$\{(x,t) : x \in \text{dom } f, f(x) \geq t\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) $$\{(x,t) : x \in \text{dom } f, f(x) \leq t\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) $$\{(x,t) : x \in \text{dom } f, f(x) = t\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) $$\{x : x \in \text{dom } f\}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\{(x,t) : x \in \text{dom } f, f(x) \leq t\}$$&lt;/strong&gt;&lt;br /&gt;
                Epigraph là tập hợp các điểm nằm phía trên đồ thị của hàm số. &quot;Epi&quot; có nghĩa là &quot;phía trên&quot;.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Mối quan hệ hàm lồi và tập lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Hàm $$f$$ là lồi khi và chỉ khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Miền xác định của $$f$$ là tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) Epigraph của $$f$$ là tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Đồ thị của $$f$$ là tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Hypograph của $$f$$ là tập lồi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Epigraph của $$f$$ là tập lồi&lt;/strong&gt;&lt;br /&gt;
                Đây là mối quan hệ quan trọng kết nối định nghĩa hàm lồi và tập lồi: hàm lồi ⟺ epigraph là tập lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Tính chất tối ưu địa phương --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Đối với hàm lồi, điểm tối ưu địa phương:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) Luôn là điểm tối ưu toàn cục&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) Có thể không phải là điểm tối ưu toàn cục&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Không tồn tại&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) Chỉ tồn tại duy nhất một điểm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Luôn là điểm tối ưu toàn cục&lt;/strong&gt;&lt;br /&gt;
                Đây là tính chất quan trọng của hàm lồi: mọi điểm tối ưu địa phương đều là tối ưu toàn cục, làm cho việc tìm nghiệm dễ dàng hơn.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Tổ hợp lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Tổ hợp lồi của các điểm $$x_1, x_2, ..., x_k$$ có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) $$\sum_{i=1}^k \theta_i x_i$$ với $$\theta_i \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) $$\sum_{i=1}^k \theta_i x_i$$ với $$\sum_{i=1}^k \theta_i = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) $$\sum_{i=1}^k \theta_i x_i$$ với $$\theta_i \geq 0$$ và $$\sum_{i=1}^k \theta_i = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) $$\sum_{i=1}^k x_i$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) $$\sum_{i=1}^k \theta_i x_i$$ với $$\theta_i \geq 0$$ và $$\sum_{i=1}^k \theta_i = 1$$&lt;/strong&gt;&lt;br /&gt;
                Tổ hợp lồi yêu cầu các hệ số không âm và tổng bằng 1, tạo ra &quot;trung bình có trọng số&quot; của các điểm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Bài toán tối ưu hóa lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Trong bài toán tối ưu hóa lồi, các hàm ràng buộc đẳng thức $$h_j(x) = 0$$ phải là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) Hàm lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) Hàm lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Hàm affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) Hàm bất kỳ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Hàm affine&lt;/strong&gt;&lt;br /&gt;
                Trong bài toán tối ưu hóa lồi, các ràng buộc đẳng thức phải là hàm affine: $$h_j(x) = a_j^T x + b_j$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Hàm affine --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Hàm affine có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) $$e^{a^T x} + b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) $$ax^2 + bx + c$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) $$a^T x + b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) $$\|x\|^2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) $$a^T x + b$$&lt;/strong&gt;&lt;br /&gt;
                Hàm affine là hàm tuyến tính cộng với một hằng số, có dạng tổng quát $$a^T x + b$$ trong không gian nhiều chiều.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Ví dụ tập lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Tập nào sau đây là tập lồi?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Hình tròn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Hình vuông&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Nửa không gian&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Tất cả các đáp án trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các đáp án trên&lt;/strong&gt;&lt;br /&gt;
                Hình tròn, hình vuông và nửa không gian đều là các ví dụ của tập lồi vì đoạn thẳng nối hai điểm bất kỳ trong tập đều nằm hoàn toàn trong tập.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Ví dụ hàm lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Hàm nào sau đây là hàm lồi?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) $$f(x) = x^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) $$f(x) = |x|$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) $$f(x) = e^x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Tất cả các đáp án trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các đáp án trên&lt;/strong&gt;&lt;br /&gt;
                $$x^2$$ (parabol), $$|x|$$ (hàm trị tuyệt đối), và $$e^x$$ (hàm mũ) đều là các ví dụ cơ bản của hàm lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Ứng dụng trong machine learning --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Trong machine learning, bài toán nào sau đây thường được giải bằng tối ưu hóa lồi?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Huấn luyện mạng nơ-ron&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Hồi quy tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Lựa chọn đặc trưng bằng Lasso (phạt chuẩn $$\ell_1$$)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Cả B và C&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Cả B và C&lt;/strong&gt;&lt;br /&gt;
                Hồi quy tuyến tính và lựa chọn đặc trưng bằng Lasso (nới lỏng lồi của bài toán chọn tập con) dẫn đến bài toán tối ưu hóa lồi. Huấn luyện mạng nơ-ron thường là bài toán không lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Miền khả thi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Miền khả thi của bài toán tối ưu hóa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Tập hợp tất cả các biến&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Tập hợp các điểm thỏa mãn tất cả ràng buộc&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Miền xác định của hàm mục tiêu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Tập hợp các nghiệm tối ưu&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Tập hợp các điểm thỏa mãn tất cả ràng buộc&lt;/strong&gt;&lt;br /&gt;
                Miền khả thi (feasible region) là tập hợp tất cả các điểm $$x$$ thỏa mãn các ràng buộc $$g_i(x) \leq 0$$ và $$h_j(x) = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Thuật toán Simplex --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Thuật toán Simplex được phát triển bởi ai và vào năm nào?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) George Dantzig, 1947&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) John von Neumann, 1944&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Leonid Kantorovich, 1939&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Narendra Karmarkar, 1984&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) George Dantzig, 1947&lt;/strong&gt;&lt;br /&gt;
                George Dantzig phát triển thuật toán Simplex vào năm 1947, tạo ra cuộc cách mạng trong lĩnh vực tối ưu hóa thực tế.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Total variation denoising --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Trong bài toán khử nhiễu total variation, số hạng $$\sum_{(i,j) \in E} |\theta_i - \theta_j|$$ có tác dụng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Tăng nhiễu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Làm mịn ảnh&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Tăng độ tương phản&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Giảm kích thước ảnh&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Làm mịn ảnh&lt;/strong&gt;&lt;br /&gt;
                Số hạng total variation penalty khuyến khích sự thay đổi nhỏ giữa các pixel lân cận, tạo hiệu ứng làm mịn ảnh.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Ràng buộc bất đẳng thức --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Trong bài toán tối ưu hóa lồi, các hàm ràng buộc bất đẳng thức $$g_i(x) \leq 0$$ phải là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Hàm lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Hàm lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Hàm tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Hàm bất kỳ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Hàm lồi&lt;/strong&gt;&lt;br /&gt;
                Trong bài toán tối ưu hóa lồi, các hàm ràng buộc bất đẳng thức $$g_i(x) \leq 0$$ phải là hàm lồi để đảm bảo miền khả thi là tập lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Ưu điểm của tối ưu hóa lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Ưu điểm chính của bài toán tối ưu hóa lồi so với bài toán không lồi là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Có nhiều nghiệm hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Không có cực tiểu địa phương (ngoài cực tiểu toàn cục)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Tính toán nhanh hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Ứng dụng rộng hơn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Không có cực tiểu địa phương (ngoài cực tiểu toàn cục)&lt;/strong&gt;&lt;br /&gt;
                Ưu điểm chính của tối ưu hóa lồi là mọi cực tiểu địa phương đều là cực tiểu toàn cục, tránh được vấn đề &quot;mắc kẹt&quot; tại cực tiểu địa phương.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Ứng dụng thực tế --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Lĩnh vực nào sau đây KHÔNG phải là ứng dụng chính của tối ưu hóa lồi?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Xử lý tín hiệu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Thiết kế mạch&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Trò chơi điện tử&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tài chính&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Trò chơi điện tử&lt;/strong&gt;&lt;br /&gt;
                Mặc dù tối ưu hóa có thể được sử dụng trong trò chơi điện tử, nhưng xử lý tín hiệu, thiết kế mạch và tài chính là những ứng dụng chính và truyền thống hơn của tối ưu hóa lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 21: Bài toán tối ưu hóa thực tế --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Cho bài toán tối thiểu hóa $$f(x) = x^2 + 4x + 3$$. Giá trị tối ưu là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$-1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$3$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$-2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$-1$$&lt;/strong&gt;&lt;br /&gt;
                $$f&apos;(x) = 2x + 4 = 0 \Rightarrow x = -2$$&lt;br /&gt;
                $$f(-2) = (-2)^2 + 4(-2) + 3 = 4 - 8 + 3 = -1$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Kiểm tra tính lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Hàm $$f(x) = |x|$$ có phải là hàm lồi không?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Có, vì $$f&apos;&apos;(x) \geq 0$$ mọi nơi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Có, theo định nghĩa hàm lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Không, vì không khả vi tại $$x = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Không, vì đồ thị có góc nhọn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Có, theo định nghĩa hàm lồi&lt;/strong&gt;&lt;br /&gt;
                Hàm $$|x|$$ thỏa mãn $$|tx + (1-t)y| \leq t|x| + (1-t)|y|$$ với mọi $$t \in [0,1]$$. Tính không khả vi tại một điểm không ảnh hưởng đến tính lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Ràng buộc trong thực tế --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Trong bài toán phân bổ ngân sách với $$x_1 + x_2 + x_3 = 100$$ và $$x_i \geq 0$$, có bao nhiêu ràng buộc?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) 1 ràng buộc đẳng thức, 3 ràng buộc bất đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) 4 ràng buộc đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) 3 ràng buộc bất đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) 1 ràng buộc đẳng thức&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) 1 ràng buộc đẳng thức, 3 ràng buộc bất đẳng thức&lt;/strong&gt;&lt;br /&gt;
                Có 1 ràng buộc đẳng thức $$x_1 + x_2 + x_3 = 100$$ và 3 ràng buộc bất đẳng thức $$x_1 \geq 0, x_2 \geq 0, x_3 \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Miền khả thi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Miền khả thi của bài toán $$\min x^2 + y^2$$ với $$x + y = 1, x \geq 0, y \geq 0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Đoạn thẳng từ $$(0,1)$$ đến $$(1,0)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Tam giác với đỉnh $$(0,0), (0,1), (1,0)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Đường tròn đơn vị&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Toàn bộ mặt phẳng&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Đoạn thẳng từ $$(0,1)$$ đến $$(1,0)$$&lt;/strong&gt;&lt;br /&gt;
                Ràng buộc $$x + y = 1$$ tạo ra đường thẳng, kết hợp với $$x \geq 0, y \geq 0$$ cho ta đoạn thẳng trong góc phần tư thứ nhất.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Tối ưu hóa có ràng buộc --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Nghiệm của bài toán $$\min x^2 + y^2$$ với ràng buộc $$x + y = 1$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$x = 0.5, y = 0.5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$x = 1, y = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$x = 0, y = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$x = 1, y = 1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$x = 0.5, y = 0.5$$&lt;/strong&gt;&lt;br /&gt;
                Sử dụng phương pháp Lagrange hoặc thế $$y = 1-x$$ vào hàm mục tiêu:&lt;br /&gt;
                $$\min x^2 + (1-x)^2 = 2x^2 - 2x + 1$$&lt;br /&gt;
                $$\frac{d}{dx}(2x^2 - 2x + 1) = 4x - 2 = 0 \Rightarrow x = 0.5, y = 0.5$$
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Câu trước&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Câu tiếp&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Kết quả bài tập&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #FF6B35, #F7931E);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #FF6B35;
    background-color: #fff5f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #FF6B35;
    background-color: #ffe8e0;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #e8f4fd;
    border-left: 4px solid #2196F3;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #1976D2;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #FF6B35;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #e55a2b;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #f0f8f0;
    border-radius: 8px;
    border: 2px solid #FF6B35;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #d84315;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng cho từng câu hỏi
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;a&apos;, q4: &apos;b&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;c&apos;, q10: &apos;c&apos;,
    q11: &apos;c&apos;, q12: &apos;d&apos;, q13: &apos;d&apos;, q14: &apos;d&apos;, q15: &apos;b&apos;,
    q16: &apos;a&apos;, q17: &apos;b&apos;, q18: &apos;a&apos;, q19: &apos;b&apos;, q20: &apos;c&apos;,
    q21: &apos;a&apos;, q22: &apos;b&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;
};

/**
 * Cập nhật thanh tiến trình và hiển thị câu hỏi hiện tại
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Câu hỏi ${currentQuestion}/${totalQuestions}`;
}

/**
 * Hiển thị câu hỏi theo số thứ tự
 */
function showQuestion(questionNum) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Cập nhật trạng thái nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Chuyển đến câu hỏi tiếp theo
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Quay lại câu hỏi trước
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Lưu đáp án của người dùng
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Cập nhật giao diện để hiển thị đáp án đã chọn
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Nộp bài và hiển thị kết quả
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Tính điểm và tạo báo cáo chi tiết
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Hiển thị giải thích cho tất cả câu hỏi
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Tạo báo cáo chi tiết
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Câu ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Đúng&apos; : &apos;Sai&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Đáp án của bạn: ${userAnswer || &apos;Chưa trả lời&apos;} | Đáp án đúng: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Hiển thị kết quả
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Điểm số: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Xuất sắc! Bạn đã nắm vững các khái niệm cơ bản!&apos; : 
              scorePercentage &gt;= 60 ? &apos;👍 Khá tốt! Hãy ôn lại một số khái niệm.&apos; : 
              scorePercentage &gt;= 40 ? &apos;📚 Cần ôn tập thêm về tối ưu hóa lồi.&apos; : &apos;💪 Hãy đọc lại lý thuyết và thử lại!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Khởi động lại bài tập
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn kết quả và hiển thị lại điều hướng
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Xóa tất cả lựa chọn
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>01-04 Lịch sử ngắn gọn về tối ưu hóa lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_04_brief_history_of_convex_optimization/"/>
   <updated>2021-01-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_04_brief_history_of_convex_optimization</id>
   <content type="html">&lt;p&gt;Ít ai biết rằng thuật toán Đơn hình (Simplex) — viên gạch khai sinh thời đại tối ưu hóa tính toán — ra đời năm 1947 từ một bài toán hậu cần quân sự tưởng chừng đời thường của George Dantzig: làm sao lập kế hoạch cung ứng tối ưu với ngân sách thấp nhất? Kể từ đó, tối ưu hóa lồi trải qua ba làn sóng lịch sử ngoạn mục: từ nền tảng hình học thuần túy của Minkowski–Fenchel–Rockafellar, đến cuộc cách mạng đa thức của phương pháp điểm trong (Karmarkar, Nesterov–Nemirovski), và bùng nổ thành động cơ cốt lõi của học máy quy mô lớn thế kỷ 21.&lt;/p&gt;

&lt;p&gt;Đọc lịch sử tối ưu hóa giúp bạn hiểu &lt;em&gt;tại sao&lt;/em&gt; các công cụ trong khóa học lại xuất hiện theo đúng thứ tự như vậy, thay vì nhìn chúng như những định lý rời rạc.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-làn-sóng-định-hình-tối-ưu-hóa-lồi-hiện-đại&quot;&gt;Kiến thức cần nhớ: Ba làn sóng định hình tối ưu hóa lồi hiện đại&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Làn sóng 1 — Nền tảng lý thuyết (1900–1970):&lt;/strong&gt; Minkowski đặt nền hình học tập lồi, Fenchel–Rockafellar xây dựng giải tích lồi và đối ngẫu, Karush–Kuhn–Tucker thiết lập điều kiện tối ưu KKT cho bài toán có ràng buộc bất đẳng thức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Làn sóng 2 — Cuộc cách mạng thuật toán đa thức (1947–1995):&lt;/strong&gt; Simplex của Dantzig (1947) giải LP thần tốc trong thực tế nhưng có trường hợp xấu nhất hàm mũ; phương pháp Ellipsoid (Khachiyan, 1979) chứng minh LP thuộc lớp \(P\); và phương pháp Điểm trong (Karmarkar, 1984; Nesterov–Nemirovski, 1994) mở rộng thời gian đa thức sang cả QP, SOCP và SDP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Làn sóng 3 — Tối ưu hóa quy mô lớn và kỷ nguyên AI (2000–nay):&lt;/strong&gt; Các thư viện mô hình hóa kỷ luật (CVX, CVXPY) dân chủ hóa tối ưu hóa lồi, trong khi các thuật toán bậc nhất (FISTA, ADMM, SGD, Adam) xử lý mượt mà hàng triệu đến hàng tỷ biến trong khoa học dữ liệu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-trải-nghiệm-ý-tưởng-đường-trung-tâm-của-phương-pháp-điểm-trong-19841994&quot;&gt;Giải thích: Trải nghiệm ý tưởng “đường trung tâm” của phương pháp điểm trong (1984–1994)&lt;/h3&gt;

&lt;p&gt;Khác với Simplex nhảy dọc theo các đỉnh biên của đa diện, phương pháp điểm trong đi xuyên qua &lt;strong&gt;lòng trong&lt;/strong&gt; miền khả thi bằng hàm rào chắn logarit (log-barrier). Xét bài toán LP một biến tối giản:&lt;/p&gt;

\[\min_{x} x \quad \text{với điều kiện} \quad x \ge 0 \quad (\text{nghiệm đúng } x^* = 0,\ p^* = 0).\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thay ràng buộc cứng \(x \ge 0\) bằng rào chắn mượt \(-\frac{1}{t}\ln x\) (với \(t &amp;gt; 0\) tăng dần):&lt;/strong&gt;
\(\min_{x &amp;gt; 0} \phi_t(x) = t x - \ln x.\)
Khi \(x \to 0^+\), \(-\ln x \to +\infty\) tạo một bức tường vô hình đẩy nghiệm giữ chặt trong phần trong \(x &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải chính xác điểm trên đường trung tâm (central path):&lt;/strong&gt;
\(\phi_t&apos;(x) = t - \frac{1}{x} = 0 \implies x^*(t) = \frac{1}{t}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan sát dãy điểm khi tăng tham số \(t\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(t = 1 \implies x^*(1) = 1.0\) (sai số so với \(p^*\) đúng bằng \(1\)).&lt;/li&gt;
      &lt;li&gt;\(t = 10 \implies x^*(10) = 0.1\) (sai số \(0.1\)).&lt;/li&gt;
      &lt;li&gt;\(t = 1000 \implies x^*(1000) = 0.001\) (sai số \(0.001\)).
Ở mọi bước, sai số đối ngẫu luôn được kiểm soát chính xác bằng \(\frac{1}{t}\) — chính cấu trúc rào chắn tự điều hòa (self-concordant) này đã giúp Nesterov và Nemirovski chứng minh tốc độ hội tụ đa thức tổng quát!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;lịch-sử-phát-triển-của-tối-ưu-hóa-lồi&quot;&gt;Lịch sử phát triển của tối ưu hóa lồi&lt;/h1&gt;

&lt;p&gt;Tối ưu hóa lồi có quá trình phát triển lâu dài, đi từ những nền tảng hình học và giải tích thuần túy đến các ứng dụng rộng rãi trong kỹ thuật và khoa học dữ liệu hiện đại. Bài học này điểm lại các cột mốc chính theo từng giai đoạn.&lt;/p&gt;

&lt;h2 id=&quot;-tổng-quan-dòng-thời-gian&quot;&gt;🎯 Tổng quan dòng thời gian&lt;/h2&gt;

&lt;div class=&quot;timeline-container&quot;&gt;
  &lt;div class=&quot;timeline-item&quot;&gt;
    &lt;div class=&quot;timeline-year&quot;&gt;1900-1970&lt;/div&gt;
    &lt;div class=&quot;timeline-content&quot;&gt;Hình thành nền tảng lý thuyết&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;timeline-item&quot;&gt;
    &lt;div class=&quot;timeline-year&quot;&gt;1947-1990&lt;/div&gt;
    &lt;div class=&quot;timeline-content&quot;&gt;Phát triển các thuật toán nền tảng&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;timeline-item&quot;&gt;
    &lt;div class=&quot;timeline-year&quot;&gt;1990-nay&lt;/div&gt;
    &lt;div class=&quot;timeline-content&quot;&gt;Mở rộng mạnh mẽ sang các lĩnh vực ứng dụng&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;-giai-đoạn-1-nền-tảng-lý-thuyết-19001970&quot;&gt;📚 Giai đoạn 1: Nền tảng lý thuyết (1900–1970)&lt;/h2&gt;

&lt;h3 id=&quot;những-người-đặt-nền-móng&quot;&gt;Những người đặt nền móng&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hermann Minkowski (1864–1909)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Đặt nền móng cho hình học lồi với khái niệm tập lồi.&lt;/li&gt;
  &lt;li&gt;Phát triển lý thuyết về đa diện lồi.&lt;/li&gt;
  &lt;li&gt;Đóng góp chính: xây dựng ngôn ngữ hình học cơ bản cho tối ưu hóa lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Leonid Kantorovich (1912–1986)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Phát triển lý thuyết quy hoạch tuyến tính vào thập niên 1930.&lt;/li&gt;
  &lt;li&gt;Giải quyết bài toán phân bổ tài nguyên tối ưu trong sản xuất.&lt;/li&gt;
  &lt;li&gt;Đóng góp chính: chứng minh khả năng ứng dụng thực tế của tối ưu hóa trong kinh tế học.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;John von Neumann (1903–1957)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Xây dựng lý thuyết trò chơi và làm rõ mối liên hệ với tối ưu hóa.&lt;/li&gt;
  &lt;li&gt;Chứng minh định lý minimax cơ bản.&lt;/li&gt;
  &lt;li&gt;Đóng góp chính: kết nối tối ưu hóa với lý thuyết ra quyết định và tính đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;các-khái-niệm-nền-tảng-được-hình-thành&quot;&gt;Các khái niệm nền tảng được hình thành&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tập lồi và hàm lồi&lt;/strong&gt;: định nghĩa chặt chẽ và các tính chất cơ bản.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện tối ưu&lt;/strong&gt;: hệ thống các điều kiện cần và đủ cho nghiệm tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết đối ngẫu (Duality theory)&lt;/strong&gt;: xây dựng bài toán đối ngẫu và quan hệ giữa bài toán gốc và bài toán đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;️-giai-đoạn-2-bước-tiến-về-thuật-toán-19471990&quot;&gt;⚙️ Giai đoạn 2: Bước tiến về thuật toán (1947–1990)&lt;/h2&gt;

&lt;h3 id=&quot;1947-thuật-toán-đơn-hình-simplex&quot;&gt;1947: Thuật toán đơn hình (Simplex)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;George Dantzig&lt;/strong&gt; đề xuất thuật toán đơn hình (Simplex):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Ý tưởng cốt lõi: Di chuyển dọc theo các cạnh của đa diện khả thi
để tìm điểm tối ưu tại một đỉnh.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Vì sao cột mốc này quan trọng?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Là thuật toán thực tế đầu tiên giải hiệu quả các bài toán quy hoạch tuyến tính (LP).&lt;/li&gt;
  &lt;li&gt;Mở ra hàng loạt ứng dụng trong hậu cần, sản xuất và quân sự.&lt;/li&gt;
  &lt;li&gt;Đạt hiệu năng rất cao trong thực tế dù độ phức tạp trường hợp xấu nhất là hàm mũ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;thập-niên-1960-các-phương-pháp-điểm-trong-ban-đầu&quot;&gt;Thập niên 1960: Các phương pháp điểm trong ban đầu&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Fiacco &amp;amp; McCormick&lt;/strong&gt; phát triển:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Phương pháp rào chắn (barrier methods) cho bài toán có ràng buộc bất đẳng thức.&lt;/li&gt;
  &lt;li&gt;Ý tưởng: thêm hàm rào chắn để giữ nghiệm lặp nằm bên trong miền khả thi.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dikin&lt;/strong&gt; đóng góp:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Phương pháp co giãn affine (affine scaling method), cải tiến hướng tiếp cận của các phương pháp điểm trong.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;thập-niên-1970-phương-pháp-ellipsoid-và-dưới-gradient&quot;&gt;Thập niên 1970: Phương pháp ellipsoid và dưới gradient&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Shor, Nemirovski và Yudin&lt;/strong&gt; phát triển:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp ellipsoid&lt;/strong&gt;: đặt nền tảng cho thuật toán thời gian đa thức đầu tiên cho LP (được Khachiyan áp dụng năm 1979).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp dưới gradient (subgradient)&lt;/strong&gt;: xử lý các hàm mục tiêu lồi không khả vi.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa lý thuyết:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Chứng minh bài toán LP thuộc lớp P (giải được trong thời gian đa thức).&lt;/li&gt;
  &lt;li&gt;Mở rộng phạm vi giải sang lớp các bài toán tối ưu không trơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;1984-phương-pháp-điểm-trong-của-karmarkar&quot;&gt;1984: Phương pháp điểm trong của Karmarkar&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Narendra Karmarkar&lt;/strong&gt; tạo ra bước ngoặt mới:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Đề xuất thuật toán điểm trong có độ phức tạp thời gian đa thức (O(n^{3.5}L)).&lt;/li&gt;
  &lt;li&gt;Cho hiệu năng thực tế tốt hơn thuật toán đơn hình trên nhiều bài toán quy mô lớn.&lt;/li&gt;
  &lt;li&gt;Mở đầu cho giai đoạn phát triển mạnh của các phương pháp điểm trong hiện đại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;cuối-thập-niên-19801990-tổng-quát-hóa&quot;&gt;Cuối thập niên 1980–1990: Tổng quát hóa&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Nesterov &amp;amp; Nemirovski (1994)&lt;/strong&gt; mở rộng lý thuyết điểm trong:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Mở rộng phương pháp điểm trong sang tối ưu hóa lồi phi tuyến.&lt;/li&gt;
  &lt;li&gt;Xây dựng lý thuyết hàm tự tương thích (self-concordant functions).&lt;/li&gt;
  &lt;li&gt;Cung cấp thuật toán thời gian đa thức cho một lớp bài toán lồi tổng quát hơn nhiều.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-giai-đoạn-3-mở-rộng-ứng-dụng-1990nay&quot;&gt;🚀 Giai đoạn 3: Mở rộng ứng dụng (1990–nay)&lt;/h2&gt;

&lt;h3 id=&quot;trước-năm-1990-chủ-yếu-trong-vận-trù-học-operations-research&quot;&gt;Trước năm 1990: Chủ yếu trong vận trù học (Operations Research)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Các ứng dụng chính:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán vận tải&lt;/strong&gt;: tối ưu hóa chi phí vận chuyển hàng hóa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lập kế hoạch sản xuất&lt;/strong&gt;: tối ưu hóa lịch trình và công suất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân bổ tài nguyên&lt;/strong&gt;: phân bổ nguồn lực trong doanh nghiệp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hậu cần quân sự&lt;/strong&gt;: lập kế hoạch cung ứng trong Thế chiến II và thời kỳ Chiến tranh Lạnh.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Nguyên nhân phạm vi còn hạn chế:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Năng lực tính toán của máy tính còn thấp.&lt;/li&gt;
  &lt;li&gt;Thiếu các công cụ và thư viện phần mềm thuận tiện.&lt;/li&gt;
  &lt;li&gt;Chưa được phổ biến rộng rãi trong các ngành kỹ thuật khác.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;từ-năm-1990-trở-đi-ứng-dụng-rộng-rãi-trong-kỹ-thuật&quot;&gt;Từ năm 1990 trở đi: Ứng dụng rộng rãi trong kỹ thuật&lt;/h3&gt;

&lt;h4 id=&quot;️-hệ-thống-điều-khiển-control-systems&quot;&gt;🎛️ Hệ thống điều khiển (Control Systems)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều khiển dự báo theo mô hình (MPC)&lt;/strong&gt;: tính toán tín hiệu điều khiển tối ưu theo từng bước thời gian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều khiển bền vững (Robust control)&lt;/strong&gt;: đảm bảo ổn định hệ thống trước nhiễu và bất định.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ&lt;/strong&gt;: điều khiển nhiệt độ trong nhà máy, hệ thống lái tự động trên máy bay.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;-xử-lý-tín-hiệu-signal-processing&quot;&gt;📡 Xử lý tín hiệu (Signal Processing)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cảm biến nén (Compressed sensing)&lt;/strong&gt;: khôi phục tín hiệu thưa từ số lượng mẫu đo ít.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khử nhiễu ảnh (Image denoising)&lt;/strong&gt;: tách nhiễu mà vẫn giữ biên ảnh sắc nét.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ&lt;/strong&gt;: tái tạo ảnh chụp cộng hưởng từ (MRI), xử lý tín hiệu radar.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;-truyền-thông-communications&quot;&gt;📱 Truyền thông (Communications)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định dạng chùm sóng (Beamforming)&lt;/strong&gt;: điều hướng sóng trong mảng ăng-ten.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân bổ công suất (Power allocation)&lt;/strong&gt;: tối ưu công suất phát trong mạng không dây.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ&lt;/strong&gt;: mạng di động 5G, truyền thông vệ tinh.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;-thiết-kế-mạch-circuit-design&quot;&gt;💻 Thiết kế mạch (Circuit Design)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định cỡ cổng (Gate sizing)&lt;/strong&gt;: tối ưu kích thước transistor để cân bằng tốc độ và diện tích.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu công suất (Power optimization)&lt;/strong&gt;: giảm tiêu thụ năng lượng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ&lt;/strong&gt;: thiết kế bộ vi xử lý (CPU), tối ưu chip di động.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-các-lớp-bài-toán-mới&quot;&gt;🆕 Các lớp bài toán mới&lt;/h3&gt;

&lt;h4 id=&quot;quy-hoạch-nửa-xác-định-semidefinite-programming--sdp&quot;&gt;Quy hoạch nửa xác định (Semidefinite Programming — SDP)&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Tối ưu hóa trên nón các ma trận nửa xác định dương.
Ứng dụng: Nới lỏng lồi cho các bài toán tổ hợp, lý thuyết điều khiển.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;quy-hoạch-nón-bậc-hai-second-order-cone-programming--socp&quot;&gt;Quy hoạch nón bậc hai (Second-Order Cone Programming — SOCP)&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Tối ưu hóa với ràng buộc thuộc nón bậc hai.
Ứng dụng: Tối ưu hóa bền vững, tối ưu hóa danh mục đầu tư.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;tối-ưu-hóa-bền-vững-robust-optimization&quot;&gt;Tối ưu hóa bền vững (Robust Optimization)&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Tối ưu hóa khi dữ liệu hoặc tham số chứa tính bất định.
Ứng dụng: Tài chính định lượng, quản trị chuỗi cung ứng.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;-xu-hướng-hiện-tại-và-tương-lai&quot;&gt;🔮 Xu hướng hiện tại và tương lai&lt;/h2&gt;

&lt;h3 id=&quot;tích-hợp-với-học-máy-machine-learning&quot;&gt;Tích hợp với học máy (Machine Learning)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng lồi (Convex relaxations)&lt;/strong&gt; cho các bài toán phân tích mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán tối ưu trong huấn luyện&lt;/strong&gt;: SGD, Adam, RMSprop.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều chuẩn (Regularization)&lt;/strong&gt;: các thành phần phạt \(L_1, L_2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ứng-dụng-dữ-liệu-lớn-big-data&quot;&gt;Ứng dụng dữ liệu lớn (Big Data)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa phân tán (Distributed optimization)&lt;/strong&gt;: xử lý dữ liệu quy mô lớn trên nhiều nút tính toán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán trực tuyến (Online algorithms)&lt;/strong&gt;: cập nhật nghiệm liên tục theo luồng dữ liệu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa theo luồng (Streaming optimization)&lt;/strong&gt;: tối ưu theo thời gian thực.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tính-toán-lượng-tử-quantum-computing&quot;&gt;Tính toán lượng tử (Quantum Computing)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa lồi lượng tử&lt;/strong&gt;: nghiên cứu các thuật toán lượng tử cho bài toán tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thuật toán lượng tử biến phân&lt;/strong&gt;: QAOA, VQE.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-bài-học-từ-lịch-sử&quot;&gt;💡 Bài học từ lịch sử&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết dẫn đường cho thực hành&lt;/strong&gt;: nền tảng toán học chặt chẽ là cơ sở để thiết kế thuật toán đáng tin cậy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần cứng và phần mềm thúc đẩy ứng dụng&lt;/strong&gt;: năng lực tính toán tăng lên mở rộng mạnh mẽ phạm vi áp dụng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hợp tác liên ngành&lt;/strong&gt;: sự giao thoa giữa toán học, khoa học máy tính và kỹ thuật tạo ra các hướng đi mới.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhu cầu thực tiễn thúc đẩy đổi mới&lt;/strong&gt;: các bài toán thực tế luôn là động lực trực tiếp cho sự ra đời của thuật toán mới.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;div class=&quot;info-box&quot;&gt;
&lt;h4&gt;🎯 Điểm cốt lõi cần ghi nhớ&lt;/h4&gt;
&lt;p&gt;Tối ưu hóa lồi đã phát triển từ một nhánh toán học lý thuyết thành công cụ nền tảng trong nhiều ngành kỹ thuật và khoa học dữ liệu hiện đại. Sự kết hợp giữa lý thuyết chặt chẽ và thuật toán hiệu quả giúp giải quyết ổn định nhiều bài toán thực tiễn quy mô lớn.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;-minh-họa-tương-tác&quot;&gt;🎮 Minh họa tương tác&lt;/h2&gt;

&lt;h3 id=&quot;minh-họa-thuật-toán-đơn-hình-simplex&quot;&gt;Minh họa thuật toán đơn hình (Simplex)&lt;/h3&gt;

&lt;div id=&quot;simplex-demo&quot;&gt;
  &lt;h4&gt;Minh họa thuật toán Simplex&lt;/h4&gt;
  &lt;p&gt;Thử nghiệm với một bài toán quy hoạch tuyến tính hai biến:&lt;/p&gt;
  
  &lt;div class=&quot;problem-setup&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; Cực đại hóa \(c_1x_1 + c_2x_2\)&lt;/p&gt;
    &lt;p&gt;&lt;strong&gt;Với điều kiện:&lt;/strong&gt; \(x_1, x_2 \geq 0\) và các ràng buộc tuyến tính&lt;/p&gt;
    
    &lt;div class=&quot;controls&quot;&gt;
      &lt;label&gt;c₁: &lt;input type=&quot;range&quot; id=&quot;c1&quot; min=&quot;-5&quot; max=&quot;5&quot; value=&quot;3&quot; step=&quot;0.1&quot; /&gt;&lt;/label&gt;
      &lt;span id=&quot;c1-value&quot;&gt;3&lt;/span&gt;&lt;br /&gt;
      &lt;label&gt;c₂: &lt;input type=&quot;range&quot; id=&quot;c2&quot; min=&quot;-5&quot; max=&quot;5&quot; value=&quot;2&quot; step=&quot;0.1&quot; /&gt;&lt;/label&gt;
      &lt;span id=&quot;c2-value&quot;&gt;2&lt;/span&gt;&lt;br /&gt;
      &lt;button onclick=&quot;runSimplex()&quot;&gt;Chạy Simplex&lt;/button&gt;
      &lt;button onclick=&quot;resetDemo()&quot;&gt;Đặt lại&lt;/button&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;canvas id=&quot;simplex-canvas&quot; width=&quot;400&quot; height=&quot;300&quot;&gt;&lt;/canvas&gt;
  &lt;div id=&quot;simplex-steps&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;khám-phá-dòng-thời-gian&quot;&gt;Khám phá dòng thời gian&lt;/h3&gt;

&lt;div id=&quot;timeline-explorer&quot;&gt;
  &lt;h4&gt;Khám phá dòng thời gian tương tác&lt;/h4&gt;
  &lt;div class=&quot;year-slider&quot;&gt;
    &lt;label&gt;Năm: &lt;input type=&quot;range&quot; id=&quot;year-slider&quot; min=&quot;1900&quot; max=&quot;2024&quot; value=&quot;1947&quot; step=&quot;1&quot; /&gt;&lt;/label&gt;
    &lt;span id=&quot;current-year&quot;&gt;1947&lt;/span&gt;
  &lt;/div&gt;
  
  &lt;div id=&quot;year-info&quot;&gt;
    &lt;h5 id=&quot;event-title&quot;&gt;1947: Thuật toán Simplex&lt;/h5&gt;
    &lt;p id=&quot;event-description&quot;&gt;George Dantzig phát triển thuật toán Simplex, mở đầu kỷ nguyên giải bài toán quy hoạch tuyến tính trong thực tế.&lt;/p&gt;
    &lt;div id=&quot;event-impact&quot;&gt;
      &lt;strong&gt;Tác động:&lt;/strong&gt; &lt;span id=&quot;impact-text&quot;&gt;Thay đổi căn bản lĩnh vực vận trù học&lt;/span&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;ứng-dụng-hiện-đại&quot;&gt;Ứng dụng hiện đại&lt;/h3&gt;

&lt;div id=&quot;applications-demo&quot;&gt;
  &lt;h4&gt;Một số ứng dụng thực tế&lt;/h4&gt;
  &lt;div class=&quot;app-selector&quot;&gt;
    &lt;button onclick=&quot;showApplication(&apos;portfolio&apos;)&quot; class=&quot;app-btn&quot;&gt;Tối ưu danh mục&lt;/button&gt;
    &lt;button onclick=&quot;showApplication(&apos;supply-chain&apos;)&quot; class=&quot;app-btn&quot;&gt;Chuỗi cung ứng&lt;/button&gt;
    &lt;button onclick=&quot;showApplication(&apos;machine-learning&apos;)&quot; class=&quot;app-btn&quot;&gt;Học máy&lt;/button&gt;
    &lt;button onclick=&quot;showApplication(&apos;signal-processing&apos;)&quot; class=&quot;app-btn&quot;&gt;Xử lý tín hiệu&lt;/button&gt;
  &lt;/div&gt;
  
  &lt;div id=&quot;app-content&quot;&gt;
    &lt;div class=&quot;app-example&quot; id=&quot;portfolio&quot;&gt;
      &lt;h5&gt;📈 Tối ưu hóa danh mục đầu tư&lt;/h5&gt;
      &lt;p&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; Phân bổ vốn đầu tư nhằm cực đại hóa lợi suất kỳ vọng và cực tiểu hóa rủi ro&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Công thức:&lt;/strong&gt; \(\min rac{1}{2}w^T\Sigma w - \mu^T w\)&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt; Quỹ đầu tư, ngân hàng, bảo hiểm&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
// Simplex Algorithm Demo
function runSimplex() {
  const canvas = document.getElementById(&apos;simplex-canvas&apos;);
  const ctx = canvas.getContext(&apos;2d&apos;);
  const c1 = parseFloat(document.getElementById(&apos;c1&apos;).value);
  const c2 = parseFloat(document.getElementById(&apos;c2&apos;).value);
  
  // Clear canvas
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  
  // Draw feasible region (simple example)
  ctx.fillStyle = &apos;rgba(0, 122, 204, 0.2)&apos;;
  ctx.beginPath();
  ctx.moveTo(50, 250);
  ctx.lineTo(200, 250);
  ctx.lineTo(200, 100);
  ctx.lineTo(100, 50);
  ctx.lineTo(50, 100);
  ctx.closePath();
  ctx.fill();
  
  // Draw objective function direction
  ctx.strokeStyle = &apos;#ff6b35&apos;;
  ctx.lineWidth = 3;
  ctx.beginPath();
  ctx.moveTo(125, 175);
  ctx.lineTo(125 + c1*20, 175 - c2*20);
  ctx.stroke();
  
  // Add labels
  ctx.fillStyle = &apos;#333&apos;;
  ctx.font = &apos;14px Arial&apos;;
  ctx.fillText(&apos;Feasible Region&apos;, 60, 200);
  ctx.fillText(`Objective: ${c1.toFixed(1)}x₁ + ${c2.toFixed(1)}x₂`, 220, 50);
  
  // Show steps
  document.getElementById(&apos;simplex-steps&apos;).innerHTML = `
    &lt;h5&gt;Các bước Simplex:&lt;/h5&gt;
    &lt;ol&gt;
      &lt;li&gt;Bắt đầu tại đỉnh (0,0)&lt;/li&gt;
      &lt;li&gt;Kiểm tra hướng cải thiện: (${c1.toFixed(1)}, ${c2.toFixed(1)})&lt;/li&gt;
      &lt;li&gt;Di chuyển dọc theo cạnh có gradient tốt nhất&lt;/li&gt;
      &lt;li&gt;Dừng khi không thể cải thiện thêm&lt;/li&gt;
    &lt;/ol&gt;
  `;
}

function resetDemo() {
  document.getElementById(&apos;c1&apos;).value = 3;
  document.getElementById(&apos;c2&apos;).value = 2;
  document.getElementById(&apos;c1-value&apos;).textContent = &apos;3&apos;;
  document.getElementById(&apos;c2-value&apos;).textContent = &apos;2&apos;;
  document.getElementById(&apos;simplex-steps&apos;).innerHTML = &apos;&apos;;
  const canvas = document.getElementById(&apos;simplex-canvas&apos;);
  const ctx = canvas.getContext(&apos;2d&apos;);
  ctx.clearRect(0, 0, canvas.width, canvas.height);
}

// Timeline Explorer
const timelineEvents = {
  1900: {title: &quot;1900: Nền tảng Hình học&quot;, desc: &quot;Minkowski phát triển lý thuyết tập lồi&quot;, impact: &quot;Tạo nền tảng toán học&quot;},
  1930: {title: &quot;1930: Kantorovich&quot;, desc: &quot;Lý thuyết lập trình tuyến tính đầu tiên&quot;, impact: &quot;Ứng dụng trong kinh tế&quot;},
  1947: {title: &quot;1947: Thuật toán Simplex&quot;, desc: &quot;Dantzig tạo ra thuật toán thực tế đầu tiên&quot;, impact: &quot;Cách mạng operations research&quot;},
  1960: {title: &quot;1960s: Interior Point&quot;, desc: &quot;Fiacco &amp; McCormick phát triển barrier methods&quot;, impact: &quot;Mở rộng khả năng giải bài toán&quot;},
  1984: {title: &quot;1984: Karmarkar&quot;, desc: &quot;Interior-point polynomial-time algorithm&quot;, impact: &quot;Đột phá về độ phức tạp&quot;},
  1994: {title: &quot;1994: Nesterov &amp; Nemirovski&quot;, desc: &quot;Tổng quát hóa cho convex optimization&quot;, impact: &quot;Nền tảng cho ứng dụng hiện đại&quot;},
  2010: {title: &quot;2010s: Machine Learning&quot;, desc: &quot;Tích hợp với AI và Big Data&quot;, impact: &quot;Ứng dụng rộng rãi trong công nghệ&quot;},
  2024: {title: &quot;2024: Quantum Computing&quot;, desc: &quot;Thuật toán tối ưu lượng tử&quot;, impact: &quot;Tương lai của tính toán&quot;}
};

function updateTimeline() {
  const year = parseInt(document.getElementById(&apos;year-slider&apos;).value);
  document.getElementById(&apos;current-year&apos;).textContent = year;
  
  // Find closest event
  let closestYear = 1900;
  for (let eventYear in timelineEvents) {
    if (parseInt(eventYear) &lt;= year) {
      closestYear = parseInt(eventYear);
    }
  }
  
  const event = timelineEvents[closestYear];
  document.getElementById(&apos;event-title&apos;).textContent = event.title;
  document.getElementById(&apos;event-description&apos;).textContent = event.desc;
  document.getElementById(&apos;impact-text&apos;).textContent = event.impact;
}

// Applications Demo
const applications = {
  portfolio: {
    title: &quot;📈 Portfolio Optimization&quot;,
    problem: &quot;Phân bổ vốn đầu tư để tối đa hóa lợi nhuận và giảm thiểu rủi ro&quot;,
    formula: &quot;\\min \\frac{1}{2}w^T\\Sigma w - \\mu^T w&quot;,
    usage: &quot;Quỹ đầu tư, ngân hàng, bảo hiểm&quot;
  },
  &quot;supply-chain&quot;: {
    title: &quot;🚚 Supply Chain Optimization&quot;,
    problem: &quot;Tối ưu hóa logistics và phân phối hàng hóa&quot;,
    formula: &quot;\\min \\sum_{i,j} c_{ij}x_{ij}&quot;,
    usage: &quot;Amazon, Walmart, FedEx&quot;
  },
  &quot;machine-learning&quot;: {
    title: &quot;🤖 Machine Learning&quot;,
    problem: &quot;Training neural networks và feature selection&quot;,
    formula: &quot;\\min \\frac{1}{2}||Xw - y||^2 + \\lambda||w||_1&quot;,
    usage: &quot;Google, Facebook, Tesla autopilot&quot;
  },
  &quot;signal-processing&quot;: {
    title: &quot;📡 Signal Processing&quot;,
    problem: &quot;Khôi phục tín hiệu từ dữ liệu nhiễu hoặc không đầy đủ&quot;,
    formula: &quot;\\min ||x||_1 \\text{ s.t. } ||Ax - b||_2 \\leq \\epsilon&quot;,
    usage: &quot;MRI imaging, radar, 5G communications&quot;
  }
};

function showApplication(appKey) {
  const app = applications[appKey];
  document.getElementById(&apos;app-content&apos;).innerHTML = `
    &lt;div class=&quot;app-example&quot;&gt;
      &lt;h5&gt;${app.title}&lt;/h5&gt;
      &lt;p&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; ${app.problem}&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Công thức:&lt;/strong&gt; \\(${app.formula}\\)&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt; ${app.usage}&lt;/p&gt;
    &lt;/div&gt;
  `;
  
  // Re-render MathJax
  if (window.MathJax) {
    MathJax.typesetPromise([document.getElementById(&apos;app-content&apos;)]);
  }
}

// Event listeners
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
  // Slider updates
  document.getElementById(&apos;c1&apos;).addEventListener(&apos;input&apos;, function() {
    document.getElementById(&apos;c1-value&apos;).textContent = this.value;
  });
  
  document.getElementById(&apos;c2&apos;).addEventListener(&apos;input&apos;, function() {
    document.getElementById(&apos;c2-value&apos;).textContent = this.value;
  });
  
  document.getElementById(&apos;year-slider&apos;).addEventListener(&apos;input&apos;, updateTimeline);
  
  // Initialize
  updateTimeline();
  showApplication(&apos;portfolio&apos;);
});
&lt;/script&gt;

&lt;style&gt;
.timeline-container {
  position: relative;
  margin: 20px 0;
}

.timeline-item {
  display: flex;
  margin: 10px 0;
  padding: 10px;
  border-left: 3px solid #007acc;
  background: #f8f9fa;
}

.timeline-year {
  font-weight: bold;
  color: #007acc;
  min-width: 100px;
}

.timeline-content {
  margin-left: 20px;
}

.info-box {
  background: #e3f2fd;
  border: 1px solid #2196f3;
  border-radius: 5px;
  padding: 15px;
  margin: 20px 0;
}

.info-box h4 {
  margin-top: 0;
  color: #1976d2;
}

/* Interactive Demo Styles */
#simplex-demo, #timeline-explorer, #applications-demo {
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  padding: 20px;
  margin: 20px 0;
}

.controls {
  margin: 15px 0;
}

.controls label {
  display: inline-block;
  margin: 5px 10px 5px 0;
  min-width: 40px;
}

.controls input[type=&quot;range&quot;] {
  width: 150px;
  margin: 0 10px;
}

.controls button {
  background: #007acc;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  margin: 5px;
}

.controls button:hover {
  background: #005a9e;
}

#simplex-canvas {
  border: 1px solid #ccc;
  margin: 10px 0;
  background: white;
}

.year-slider {
  margin: 15px 0;
}

.year-slider input[type=&quot;range&quot;] {
  width: 300px;
}

#year-info {
  background: white;
  padding: 15px;
  border-radius: 5px;
  border-left: 4px solid #007acc;
}

.app-selector {
  margin: 15px 0;
}

.app-btn {
  background: #28a745;
  color: white;
  border: none;
  padding: 10px 15px;
  border-radius: 5px;
  cursor: pointer;
  margin: 5px;
  font-size: 14px;
}

.app-btn:hover {
  background: #218838;
}

.app-example {
  background: white;
  padding: 15px;
  border-radius: 5px;
  border-left: 4px solid #28a745;
  margin-top: 15px;
}

.problem-setup {
  background: white;
  padding: 15px;
  border-radius: 5px;
  margin: 10px 0;
}

#simplex-steps {
  background: white;
  padding: 15px;
  border-radius: 5px;
  margin-top: 10px;
}

#simplex-steps ol {
  margin: 10px 0;
  padding-left: 20px;
}

#simplex-steps li {
  margin: 5px 0;
}
&lt;/style&gt;

</content>
 </entry>
 
 <entry>
   <title>01-03 Mục tiêu và Chủ đề</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_03_goals_and_topics/"/>
   <updated>2021-01-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_03_goals_and_topics</id>
   <content type="html">&lt;p&gt;Học tối ưu hóa lồi không phải chỉ để bấm nút gọi một bộ giải hộp đen rồi chờ kết quả. Một câu chuyện kinh điển ngay trong bài học này cho thấy: cùng một bài toán khử nhiễu ảnh Total Variation, thuật toán tổng quát (Proximal Gradient) mất tới &lt;strong&gt;1.000 vòng lặp&lt;/strong&gt; mà vẫn chưa sắc nét bằng thuật toán khai thác đúng cấu trúc bài toán (Specialized ADMM) chỉ sau &lt;strong&gt;20 vòng lặp&lt;/strong&gt;! Biết cách “nhìn xuyên” cấu trúc toán học của bài toán giúp bạn tăng tốc thực thi hàng trăm lần.&lt;/p&gt;

&lt;p&gt;Bài học này phác họa bản đồ toàn khóa học: từ nền tảng hình học tập lồi, lý thuyết đối ngẫu KKT cho đến hệ sinh thái thuật toán bậc nhất, bậc hai và tách biến.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-tầng-năng-lực-của-người-học-tối-ưu-hóa-lồi&quot;&gt;Kiến thức cần nhớ: Ba tầng năng lực của người học tối ưu hóa lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tầng 1 — Nhận diện và tái phát biểu (Modeling &amp;amp; Reformulation):&lt;/strong&gt; Biến một bài toán thực tế thoạt nhìn không lồi hoặc không trơn (như chuẩn \(\ell_1\), hàm \(\max\), khử nhiễu TV) về dạng lồi chuẩn tương đương.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tầng 2 — Lý thuyết tối ưu và Đối ngẫu (Theory &amp;amp; Duality):&lt;/strong&gt; Dùng điều kiện KKT, hàm liên hợp và bài toán đối ngẫu để chứng nhận nghiệm tối ưu, tính cận dưới chất lượng nghiệm và phân tích độ nhạy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tầng 3 — Thiết kế và chọn thuật toán (Algorithms):&lt;/strong&gt; Chọn đúng vũ khí theo quy mô và cấu trúc: phương pháp điểm trong cho độ chính xác cao cỡ vừa; Proximal Gradient, FISTA, ADMM hay Coordinate Descent cho dữ liệu lớn không trơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-giải-bài-toán-khử-nhiễu-1d-total-variation-tv-3-điểm&quot;&gt;Giải thích: Tự tay giải bài toán khử nhiễu 1D Total Variation (TV) 3 điểm&lt;/h3&gt;

&lt;p&gt;Giả sử ta đo được tín hiệu 3 điểm bị gai nhiễu ở giữa \(y = (0, 3, 0)^T\) và muốn tìm tín hiệu sạch \(x = (x_1, x_2, x_3)^T\) bằng bài toán khử nhiễu TV với trọng số phạt \(\lambda = 0.5\):&lt;/p&gt;

\[\min_{x \in \mathbb{R}^3} F(x) = \frac{1}{2}\left[(x_1 - 0)^2 + (x_2 - 3)^2 + (x_3 - 0)^2\right] + 0.5\left(|x_2 - x_1| + |x_3 - x_2|\right).\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khai thác tính đối xứng:&lt;/strong&gt; Vì \(y_1 = y_3 = 0 &amp;lt; y_2 = 3\), nghiệm tối ưu sẽ đối xứng \(x_1 = x_3 = a\) và đỉnh giữa \(x_2 = b \ge a\). Khi đó \(|x_2 - x_1| = |x_3 - x_2| = b - a\), nên:
\(F(a, b) = a^2 + \frac{1}{2}(b - 3)^2 + 0.5 \cdot 2(b - a) = a^2 + \frac{1}{2}(b - 3)^2 + b - a.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm dừng trên miền \(b \ge a\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\frac{\partial F}{\partial a} = 2a - 1 = 0 \implies a^* = 0.5\).&lt;/li&gt;
      &lt;li&gt;\(\frac{\partial F}{\partial b} = (b - 3) + 1 = 0 \implies b^* = 2\).
Kiểm tra điều kiện \(b^* = 2 \ge a^* = 0.5\): thỏa mãn chặt!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đọc kết quả trực quan:&lt;/strong&gt; Tín hiệu tối ưu \(x^* = (0.5,\ 2,\ 0.5)^T\) đã kéo gai nhiễu từ \(3\) xuống \(2\) và nâng hai biên từ \(0\) lên \(0.5\), giảm hàm mục tiêu từ \(F(0, 3, 0) = 3.0\) xuống còn:
\(F(0.5, 2, 0.5) = 0.25 + 0.5(1)^2 + (2 - 0.5) = 2.25.\)
Nếu tăng \(\lambda\) lên \(1\), nghiệm ép phẳng hẳn về \(x^* = (1, 1, 1)^T\) — đó chính là cơ chế “làm phẳng từng mảnh” nổi tiếng của TV denoising!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu&quot;&gt;Mục tiêu&lt;/h2&gt;

&lt;p&gt;Khóa học này hướng tới việc rèn luyện ba năng lực chính:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nhận biết khi nào một bài toán cho trước là bài toán tối ưu hóa lồi.&lt;/li&gt;
  &lt;li&gt;Mô hình hóa một bài toán thực tế thành bài toán tối ưu hóa lồi.&lt;/li&gt;
  &lt;li&gt;Lựa chọn thuật toán phù hợp nhất để giải một bài toán tối ưu hóa lồi cụ thể.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;chủ-đề&quot;&gt;Chủ đề&lt;/h2&gt;

&lt;p&gt;Để đạt được các mục tiêu trên, khóa học sẽ đi qua các nội dung:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tập lồi, hàm lồi và bài toán tối ưu hóa lồi.&lt;/li&gt;
  &lt;li&gt;Các ví dụ và ứng dụng điển hình.&lt;/li&gt;
  &lt;li&gt;Các lớp thuật toán tối ưu (gradient, proximal, Newton, điểm trong, ADMM, …).&lt;/li&gt;
  &lt;li&gt;Lộ trình hiện đại 2026 trên trang này: SGD / Adam / AdamW (Chương 26), vi phân tự động (Chương 27), bề mặt hàm mục tiêu không lồi (Chương 28), SGD song song dữ liệu và FedAvg (Chương 29).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Trong đó, trọng tâm xuyên suốt của khóa học là thuật toán.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán&quot;&gt;Thuật toán&lt;/h2&gt;

&lt;p&gt;Có nhiều phương pháp khác nhau để giải cùng một bài toán tối ưu hóa, và hiệu quả của từng phương pháp phụ thuộc chặt chẽ vào cấu trúc của bài toán. Để chọn được thuật toán phù hợp nhất, cần hiểu rõ cả đặc điểm của bài toán lẫn cơ chế hoạt động của thuật toán. Ta minh họa điều này qua ví dụ khử nhiễu toàn biến phân (total variation denoising).&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-khử-nhiễu-total-variation&quot;&gt;Ví dụ: Khử nhiễu Total Variation&lt;/h3&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/2d_fused_lasso.png&quot; alt=&quot;2D Fused Lasso&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình1] Khử nhiễu Total Variation [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Giả sử bạn có một bức ảnh bị nhiễu (hình giữa) và muốn khử nhiễu để khôi phục ảnh (hình phải) gần với ảnh gốc (hình trái). Nếu ký hiệu giá trị từng điểm ảnh là \(y_i, i = 1, ..., n\), ta có thể mô hình hóa yêu cầu này thành bài toán tối ưu hóa sau — thường gọi là bài toán &lt;strong&gt;2D fused lasso&lt;/strong&gt; hay &lt;strong&gt;khử nhiễu 2D total variation&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{\theta} \frac{1}{2} \sum_{i=1}^n (y_i - \theta_{i})^2 + \lambda \sum_{(i,j) \in E} \vert \theta_i - \theta_j \vert\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;\(E\): tập hợp các cạnh nối giữa các điểm ảnh lân cận.&lt;/li&gt;
  &lt;li&gt;\(\frac{1}{2} \sum_{i=1}^n (y_i - \theta_{i})^2\): hàm mất mát bình phương tối thiểu, giữ cho ảnh khôi phục \(\theta\) bám sát ảnh quan sát \(y\).&lt;/li&gt;
  &lt;li&gt;\(\sum_{(i,j) \in E} \vert \theta_i - \theta_j \vert\): thành phần làm mịn toàn biến phân (total variation), phù hợp khi giá trị các điểm ảnh lân cận ít thay đổi (dạng hằng số từng khúc). Việc chọn thành phần điều chuẩn thích hợp đòi hỏi cân nhắc kỹ đặc thù của bài toán (xem thêm Chương 6.1.2 và 6.3 trong Tài liệu tham khảo 1).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bài toán tối ưu hóa lồi trên có thể được giải bằng thuật toán &lt;a href=&quot;http://stanford.edu/~boyd/admm.html&quot;&gt;Specialized ADMM&lt;/a&gt;, cho kết quả như hình bên phải chỉ sau 20 lần lặp.&lt;/p&gt;

&lt;h3 id=&quot;specialized-admm-20-lần-lặp&quot;&gt;Specialized ADMM, 20 lần lặp&lt;/h3&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/result1.png&quot; alt=&quot;Result1&quot; width=&quot;50%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình2] Kết quả Specialized ADMM [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;proximal-gradient-descent-1000-lần-lặp&quot;&gt;Proximal gradient descent, 1000 lần lặp&lt;/h3&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/result2.png&quot; alt=&quot;Result2&quot; width=&quot;50%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình3] Kết quả Proximal Gradient Descent [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;coordinate-descent-10000-chu-kỳ&quot;&gt;Coordinate descent, 10.000 chu kỳ&lt;/h3&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/result3.png&quot; alt=&quot;Result3&quot; width=&quot;50%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình4] Kết quả Coordinate Descent [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Như kết quả minh họa ở trên, với bài toán 2D fused lasso, Specialized ADMM vượt trội hơn hai phương pháp còn lại. Tuy nhiên, trên những bài toán khác, proximal gradient descent hoặc coordinate descent có thể lại hiệu quả hơn. Trong các chương tiếp theo, chúng ta sẽ phân tích sâu từng lớp thuật toán và lớp bài toán để biết cách lựa chọn phương pháp thích hợp nhất.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>01-02 Bài toán tối ưu hóa lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_02_convex_optimization_problem/"/>
   <updated>2021-01-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_02_convex_optimization_problem</id>
   <content type="html">&lt;p&gt;Tại sao một kỹ sư khi gặp một bài toán mới thường cố gắng biến đổi nó về &lt;strong&gt;dạng lồi&lt;/strong&gt; bằng mọi giá? Bởi vì ngay khoảnh khắc bài toán khoác lên chiếc áo lồi — hàm mục tiêu lồi, ràng buộc bất đẳng thức lồi và ràng buộc đẳng thức affine — ta lập tức nhận được “tấm thẻ bảo hiểm toàn cục”: bất kỳ cực tiểu địa phương nào mà thuật toán tìm thấy chắc chắn là &lt;strong&gt;cực tiểu toàn cục tốt nhất có thể&lt;/strong&gt;. Không cần đoán mò hàng trăm điểm khởi tạo ngẫu nhiên, cũng không sợ bỏ lỡ nghiệm tốt hơn ở một góc khuất nào đó của không gian.&lt;/p&gt;

&lt;p&gt;Bài học này giới thiệu trọn vẹn định nghĩa chuẩn của bài toán tối ưu hóa lồi, cầu nối hình học qua epigraph và chứng minh kinh điển cho tính chất “địa phương = toàn cục”.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-kiến-trúc-của-một-bài-toán-tối-ưu-hóa-lồi&quot;&gt;Kiến thức cần nhớ: Kiến trúc của một bài toán tối ưu hóa lồi&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tập lồi (Convex Set):&lt;/strong&gt; Chứa trọn đoạn thẳng nối hai điểm bất kỳ trong tập. Trong bài toán lồi, miền khả thi luôn là tập lồi (giao của các tập mức dưới của \(g_i\) và các siêu phẳng \(h_j(x) = 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm lồi và Epigraph:&lt;/strong&gt; Hàm \(f\) lồi khi và chỉ khi vùng nằm trên đồ thị của nó (\(\operatorname{epi} f\)) là một tập lồi. Đây là cây cầu nối giải tích (hàm số) với hình học (tập hợp).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vì sao ràng buộc đẳng thức \(h_j(x) = 0\) bắt buộc phải là affine?&lt;/strong&gt; Nếu viết \(h(x) = 0\) thành cặp \(h(x) \le 0\) và \(-h(x) \le 0\), thì cả \(h\) và \(-h\) cùng phải lồi — điều này chỉ xảy ra khi \(h\) là hàm affine \(a^T x + b\)! (Ví dụ \(x_1^2 + x_2^2 = 1\) là đường tròn rỗng ruột, không phải tập lồi.)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất toàn cục (Local = Global):&lt;/strong&gt; Chứng minh bằng phản chứng chỉ dùng đúng định nghĩa tập lồi và bất đẳng thức hàm lồi cho tổ hợp \(\theta y + (1-\theta)x\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-tra-tính-lồi-và-giải-tay-một-bài-toán-lồi-có-cả-2-loại-ràng-buộc&quot;&gt;Giải thích: Kiểm tra tính lồi và giải tay một bài toán lồi có cả 2 loại ràng buộc&lt;/h3&gt;

&lt;p&gt;Xét bài toán:
\(\min_{x_1, x_2} f(x_1, x_2) = x_1^2 + 2x_2^2 \quad \text{với điều kiện} \quad g_1(x) = 3 - x_1 - x_2 \le 0,\quad h_1(x) = x_1 - x_2 - 1 = 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra cấu trúc lồi:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hàm mục tiêu \(f(x) = x_1^2 + 2x_2^2\) có Hessian \(\operatorname{diag}(2, 4) \succ 0\) nên lồi chặt.&lt;/li&gt;
      &lt;li&gt;Ràng buộc bất đẳng thức \(g_1(x) = 3 - x_1 - x_2\) là hàm affine (vừa lồi vừa lõm).&lt;/li&gt;
      &lt;li&gt;Ràng buộc đẳng thức \(h_1(x) = x_1 - x_2 - 1\) là hàm affine.
Vậy đây là &lt;strong&gt;bài toán tối ưu hóa lồi chuẩn&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khử ràng buộc đẳng thức:&lt;/strong&gt; Từ \(x_1 - x_2 - 1 = 0 \implies x_1 = x_2 + 1\). Thay vào bất đẳng thức:
\(3 - (x_2 + 1) - x_2 \le 0 \iff 2 - 2x_2 \le 0 \iff x_2 \ge 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa hàm một biến thu gọn:&lt;/strong&gt;
\(\phi(x_2) = (x_2 + 1)^2 + 2x_2^2 = 3x_2^2 + 2x_2 + 1, \qquad x_2 \ge 1.\)
Đạo hàm \(\phi&apos;(x_2) = 6x_2 + 2 &amp;gt; 0\) với mọi \(x_2 \ge 1\), nên \(\phi\) tăng nghiêm ngặt trên \([1, \infty)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiệm tối ưu toàn cục:&lt;/strong&gt; Đạt tại \(x_2^* = 1 \implies x_1^* = 2\), giá trị tối ưu \(p^* = 2^2 + 2(1)^2 = 6\). Kiểm chứng bất đẳng thức lồi giữa \(x^* = (2, 1)\) và một điểm khả thi khác \(y = (3, 2)\) (\(f(y) = 17\)): trung điểm \(z = (2.5, 1.5)\) thỏa ràng buộc và có \(f(z) = 6.25 + 4.5 = 10.75 \le \frac{6 + 17}{2} = 11.5\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài toán tối ưu hóa lồi là một lớp đặc biệt quan trọng của bài toán tối ưu hóa.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align*} 
&amp;amp;\min_{x\in D}\ &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{với điều kiện} &amp;amp;&amp;amp; g_i(x) \le 0,\ i = 1, ..., m \\
&amp;amp;&amp;amp;&amp;amp; h_j(x) = 0,\ j = 1,\ ..., r
\end{align*}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bài toán tối ưu hóa lồi ở dạng chuẩn [3]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Trong dạng chuẩn này, hàm mục tiêu \(f\) và các hàm ràng buộc bất đẳng thức \(g_i\) là các hàm lồi, còn các hàm ràng buộc đẳng thức \(h_j\) là các hàm affine (hàm tuyến tính cộng với một hằng số):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(h_j,\ j = 1, ..., r\) là hàm affine: \(h_j(x) = a_{j}^T x + b_{j},\ j=1, ..., r\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vậy thế nào là một hàm lồi? Để trả lời câu hỏi này, trước hết ta cần định nghĩa tập lồi.&lt;/p&gt;

&lt;h2 id=&quot;tập-lồi&quot;&gt;Tập lồi&lt;/h2&gt;

&lt;p&gt;Đoạn thẳng nối hai điểm \(x_1\) và \(x_2\) được định nghĩa là tập các điểm có dạng:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x = \theta x_1 + (1 - \theta) x_2\) với \(0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Một tập hợp được gọi là &lt;strong&gt;tập lồi&lt;/strong&gt; nếu đoạn thẳng nối hai điểm \(x_1, x_2\) bất kỳ thuộc tập đều nằm hoàn toàn trong tập đó. Nói cách khác, tập \(C\) là tập lồi nếu:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x_1, x_2 \in C\), \(0 \le \theta \le 1\)  \(\Rightarrow\) \(\theta x_1 + (1-\theta)x_2 \in C\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Chẳng hạn, trong hình minh họa dưới đây, chỉ có hình ngoài cùng bên trái là tập lồi.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/Convex_set.png&quot; alt=&quot;Convex Set&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình1] Trái: tập lồi; giữa &amp;amp; phải: tập không lồi [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;hàm-lồi&quot;&gt;Hàm lồi&lt;/h2&gt;

&lt;p&gt;Một hàm số \(f\) được gọi là &lt;strong&gt;hàm lồi&lt;/strong&gt; nếu thỏa mãn điều kiện sau:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f: \mathbb{R}^n \rightarrow \mathbb{R}\) là lồi nếu \(dom(f)\) là tập lồi và&lt;/p&gt;

  &lt;p&gt;\(f(\theta x + (1 - \theta)y) \le \theta f(x) + (1-\theta)f(y)\) với mọi \(x, y \in dom(f),\ 0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Về mặt hình học, với hai điểm bất kỳ \((x, f(x))\) và \((y, f(y))\) trên đồ thị của \(f\), đoạn thẳng nối hai điểm đó luôn nằm phía trên (hoặc trùng với) đồ thị trên đoạn giữa \(x\) và \(y\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/Convex_function.png&quot; alt=&quot;Convex Function&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình2] Hàm lồi [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;mối-quan-hệ-giữa-tập-lồi-và-hàm-lồi&quot;&gt;Mối quan hệ giữa tập lồi và hàm lồi&lt;/h2&gt;

&lt;p&gt;Tập lồi và hàm lồi liên hệ chặt chẽ với nhau qua khái niệm biểu đồ trên (epigraph):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Một hàm \(f\) là hàm lồi khi và chỉ khi biểu đồ trên (epigraph) của nó là một tập lồi.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tiền tố &lt;em&gt;epi&lt;/em&gt; nghĩa là “phía trên”, do đó &lt;strong&gt;epigraph&lt;/strong&gt; của \(f\) là tập hợp tất cả các điểm nằm trên hoặc phía trên đồ thị của \(f\). Về mặt toán học:&lt;/p&gt;

&lt;blockquote&gt;
\[\eqalign{
&amp;amp; \text{epigraph của } f: \mathbb{R}^n \rightarrow \mathbb{R}\\
&amp;amp; \text{epi } f = \{(x, t) \in \mathbb{R}^{n+1} \mid x \in \text{ dom } f, f(x) \le t\}
}\]
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/epigraph.png&quot; alt=&quot;Epigraph&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình3] Epigraph [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Nếu \(f\) là hàm lồi thì \(\text{epi } f\) là tập lồi, và ngược lại. Đây là tính chất cốt lõi kết nối hình học của tập lồi với giải tích của hàm lồi.&lt;/p&gt;

&lt;h2 id=&quot;hàm-lồi-và-hàm-lõm&quot;&gt;Hàm lồi và hàm lõm&lt;/h2&gt;

&lt;p&gt;Một hàm \(f\) được gọi là &lt;strong&gt;hàm lõm&lt;/strong&gt; nếu \(-f\) là hàm lồi. Tương đương, \(f\) lõm nếu \(dom(f)\) là tập lồi và:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f(\theta x + (1 - \theta)y) \ge \theta f(x) + (1-\theta)f(y)\) với mọi \(x, y \in dom(f),\ 0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Về mặt hình học, đoạn thẳng nối hai điểm bất kỳ trên đồ thị hàm lõm luôn nằm phía dưới đồ thị: hàm lõm “cong xuống”, còn hàm lồi “cong lên”.&lt;/p&gt;

&lt;p&gt;Vì sao trong lý thuyết tối ưu ta tập trung vào hàm lồi mà ít trình bày riêng về hàm lõm?&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm lõm chỉ là phiên bản đổi dấu của hàm lồi. Mọi bài toán cực đại hóa hàm lõm \(f\) đều có thể chuyển ngay thành bài toán cực tiểu hóa hàm lồi \(-f\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;video-ngắn-lồi-vs-không-lồi--kiến-trúc-bài-toán-lồi&quot;&gt;Video ngắn: Lồi vs. Không lồi &amp;amp; Kiến trúc Bài toán Lồi&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:8px;background:#10121a;&quot; src=&quot;/public/videos/reels/convex-vs-nonconvex_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Video dài khoảng 29 giây (có thuyết minh tiếng Việt): ranh giới thực sự trong tối ưu hóa theo Boyd–Vandenberghe và cấu trúc chuẩn tắc của bài toán lồi.&lt;/p&gt;

&lt;h2 id=&quot;tính-chất-cốt-lõi-của-bài-toán-tối-ưu-hóa-lồi&quot;&gt;Tính chất cốt lõi của bài toán tối ưu hóa lồi&lt;/h2&gt;

&lt;p&gt;Một tính chất nổi bật khiến bài toán tối ưu hóa lồi dễ giải hơn nhiều so với bài toán không lồi là:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Nếu bài toán tối ưu hóa là lồi và \(x\) là điểm cực tiểu địa phương, thì \(x\) cũng là điểm cực tiểu toàn cục.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ta chứng minh mệnh đề này bằng phản chứng:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh bằng phản chứng:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Giả sử \(x\) là điểm cực tiểu địa phương của bài toán tối ưu hóa lồi nhưng không phải cực tiểu toàn cục. Khi đó, tồn tại bán kính \(\rho &amp;gt; 0\) sao cho \(f(x) \le f(z)\) với mọi điểm khả thi \(z\) thỏa mãn \(\|z - x\|_2 \le \rho\). Mặt khác, vì \(x\) không phải cực tiểu toàn cục nên tồn tại một điểm khả thi \(y\) sao cho \(f(y) &amp;lt; f(x)\). Do \(f(y) &amp;lt; f(x)\), nhất thiết phải có \(\|y - x\|_2 &amp;gt; \rho\).&lt;/p&gt;

  &lt;p&gt;Đặt \(\theta=\frac{\rho}{2\|y-x\|_2}\) (khi đó \(0 &amp;lt; \theta &amp;lt; \frac{1}{2} &amp;lt; 1\)) và xét điểm \(z = \theta y + (1 - \theta) x = x + \theta( y - x)\). Ta có:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;
      &lt;p&gt;Vì miền khả thi của bài toán tối ưu hóa lồi là tập lồi, \(z\) là tổ hợp lồi của hai điểm khả thi \(x, y\) nên \(z\) cũng khả thi.&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;\(\|z - x\|_2 = \theta \|y - x\|_2 = \frac{\rho}{2} &amp;lt; \rho\).&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;\(f(z) \le \theta f(y) + (1 - \theta) f(x) &amp;lt; \theta f(x) + (1 - \theta) f(x) = f(x)\).&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Hai điều (2) và (3) mâu thuẫn với giả thiết \(x\) là cực tiểu địa phương trong hình cầu bán kính \(\rho\). Vậy mọi điểm cực tiểu địa phương \(x\) đều là điểm cực tiểu toàn cục.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;tổ-hợp-lồi&quot;&gt;Tổ hợp lồi&lt;/h2&gt;

&lt;p&gt;Tổ hợp lồi của các điểm \(x_1, ..., x_k\) được định nghĩa là:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x = \theta_1 x_1 + \theta_2 x_2 + \cdots + \theta_k x_k\) với \(\theta_1 + \cdots + \theta_k = 1, \theta_i \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nếu \(D\) là tập lồi và \(x_1, x_2, ..., x_k \in D\), thì mọi tổ hợp lồi \(x\) của chúng cũng thuộc \(D\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>01-07 Practical Exercises - Introduction to Optimization</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_07_Practical_Exercises_Introduction/"/>
   <updated>2021-01-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_07_Practical_Exercises_Introduction</id>
   <content type="html">&lt;p&gt;Theory clicks when you pick up a pencil (or open Python) and actually reformulate messy word problems into canonical LP, QP, GP, and SDP forms. These practical exercises train the single most valuable skill of an optimization practitioner: taking an unstructured engineering or financial problem, introducing slack or auxiliary variables cleanly, verifying convexity, and checking that your reformulation preserves the exact same optimal solution.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-practical-reformulation-toolkit&quot;&gt;Key ideas: Practical Reformulation Toolkit&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP Standard Form Conversions:&lt;/strong&gt; Turning maximization into minimization, rewriting \(\le\)/\(\ge\) inequalities with nonnegative slack/surplus variables, and splitting free variables via \(x = x^+ - x^-\) with \(x^+, x^- \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Least Squares &amp;amp; QP Modeling:&lt;/strong&gt; Expanding squared norms \(\|Ax - b\|_2^2\) into standard quadratic form \(\frac{1}{2}x^T P x + q^T x + r\) with \(P = 2A^T A \succeq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nonlinear Convex Classes (GP &amp;amp; SDP):&lt;/strong&gt; Transforming posynomial geometric programs via logarithmic change of variables \(y_i = \ln x_i\) and recognizing linear matrix inequalities (LMIs) \(F(x) \succeq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust Optimization Thinking:&lt;/strong&gt; Replacing uncertain parameters with worst-case bounds over an uncertainty set so decisions stay feasible under real-world perturbations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-converting-a-free-variable-lp-to-standard-equality-form&quot;&gt;Worked example: Converting a Free-Variable LP to Standard Equality Form&lt;/h3&gt;

&lt;p&gt;Convert the following linear program into standard form (\(\min c^T z\) s.t. \(Az = b,\; z \ge 0\)):
\(\max_{x_1, x_2} \; 3x_1 - x_2 \quad \text{s.t.} \quad x_1 + 2x_2 \le 6,\; x_1 \ge 0,\; x_2 \in \mathbb{R} \text{ (free)}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Flip max to min:&lt;/strong&gt; Maximizing \(3x_1 - x_2\) is equivalent to minimizing \(-3x_1 + x_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Split the free variable \(x_2\):&lt;/strong&gt; Introduce \(x_2^+, x_2^- \ge 0\) with \(x_2 = x_2^+ - x_2^-\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convert the inequality to an equality with a slack variable \(s \ge 0\):&lt;/strong&gt;
\(x_1 + 2(x_2^+ - x_2^-) + s = 6.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write the standard-form problem in \(z = (x_1, x_2^+, x_2^-, s)^T \ge 0\):&lt;/strong&gt;
\(\min_{z \ge 0} \; -3x_1 + x_2^+ - x_2^- + 0\cdot s \quad \text{s.t.} \quad x_1 + 2x_2^+ - 2x_2^- + s = 6.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sanity-check feasibility:&lt;/strong&gt; The original point \((x_1, x_2) = (4, 1)\) maps to \(z = (4, 1, 0, 0)^T \ge 0\), satisfying \(4 + 2(1) - 0 + 0 = 6\) with negated objective \(-11\) (matching original objective \(3(4) - 1 = 11\)).&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---introduction-to-optimization&quot;&gt;Practical Exercises - Introduction to Optimization&lt;/h1&gt;

&lt;h2 id=&quot;-exercise-1-classifying-basic-optimization-problems&quot;&gt;📝 &lt;strong&gt;Exercise 1: Classifying basic optimization problems&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 1.1 from Boyd &amp;amp; Vandenberghe)
Classify the following problems as LP (Linear Programming), QP (Quadratic Programming), QCQP (Quadratically Constrained QP), SOCP (Second-Order Cone Programming), SDP (Semidefinite Programming), or GP (Geometric Programming):&lt;/p&gt;

&lt;p&gt;a) \(\min_{x \in \mathbb{R}^n} c^T x \quad \text{s.t.} \quad Ax \leq b\)&lt;/p&gt;

&lt;p&gt;b) \(\min_{x \in \mathbb{R}^n} x^T P x + q^T x \quad \text{s.t.} \quad Ax = b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;c) \(\min_{x \in \mathbb{R}^n} \lVert Ax - b \rVert_2 \quad \text{s.t.} \quad \lVert x \rVert_2 \leq 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Identify the problem class for each case&lt;/li&gt;
  &lt;li&gt;Explain the reason for the classification&lt;/li&gt;
  &lt;li&gt;State the conditions under which the problem is convex&lt;/li&gt;
  &lt;li&gt;Suggest a suitable solution method&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Classification**

**a) Linear programming (LP)**
- Objective: linear ($$c^T x$$)
- Constraints: linear inequalities ($$Ax \leq b$$)
- This is the standard form of an LP

**b) Quadratic programming (QP)**
- Objective: quadratic ($$x^T P x + q^T x$$)
- Constraints: linear ($$Ax = b, x \geq 0$$)
- Convex when $$P \succeq 0$$

**c) Second-order cone programming (SOCP)**
- Objective: a norm ($$\lVert Ax - b \rVert_2$$)
- Constraint: a norm constraint ($$\lVert x \rVert_2 \leq 1$$)
- Can be rewritten in standard SOCP form

**Step 2: Convexity conditions**
- **a)** Always convex (linear functions)
- **b)** Convex when $$P \succeq 0$$ (positive semidefinite)
- **c)** Always convex (norm objective and norm constraint)

**Step 3: Solution methods**
- **a)** The Simplex method, interior-point methods
- **b)** Active-set methods, interior-point methods
- **c)** Interior-point methods for SOCP

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-least-squares-and-variants&quot;&gt;📝 &lt;strong&gt;Exercise 2: Least squares and variants&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 1.2 from Boyd &amp;amp; Vandenberghe)
Consider the following least squares problems:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Ordinary least squares:&lt;/strong&gt; \(\min_x \lVert Ax - b \rVert_2^2\)&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Weighted least squares:&lt;/strong&gt; \(\min_x (Ax - b)^T W (Ax - b)\) with \(W \succ 0\)&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Regularized least squares:&lt;/strong&gt; \(\min_x \lVert Ax - b \rVert_2^2 + \lambda \lVert x \rVert_2^2\)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;d) &lt;strong&gt;Robust least squares:&lt;/strong&gt; \(\min_x \sum_{i=1}^m \phi((Ax - b)_i)\) with $$\phi(u) = \begin{cases} u^2 &amp;amp;&lt;/td&gt;
      &lt;td&gt;u&lt;/td&gt;
      &lt;td&gt;\leq M \ 2M&lt;/td&gt;
      &lt;td&gt;u&lt;/td&gt;
      &lt;td&gt;- M^2 &amp;amp;&lt;/td&gt;
      &lt;td&gt;u&lt;/td&gt;
      &lt;td&gt;&amp;gt; M \end{cases}$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Find the analytical solution for cases a, b, c&lt;/li&gt;
  &lt;li&gt;Prove that all of the problems are convex&lt;/li&gt;
  &lt;li&gt;Analyze the geometric meaning of regularization&lt;/li&gt;
  &lt;li&gt;Compare the robustness of the methods&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Analytical solutions**

**a) Ordinary least squares:**
$$x^* = (A^T A)^{-1} A^T b$$ (if $$A^T A$$ is invertible)

**b) Weighted least squares:**
$$x^* = (A^T W A)^{-1} A^T W b$$

**c) Regularized least squares (Ridge regression):**
$$x^* = (A^T A + \lambda I)^{-1} A^T b$$

**d) Robust least squares:**
No closed form; numerical methods are needed.

**Step 2: Proving convexity**

**a-c)** Quadratic functions with positive semidefinite Hessians: $$2A^TA \succeq 0$$, $$2A^TWA \succeq 0$$, $$2(A^TA + \lambda I) \succ 0$$ (for $$\lambda &amp;gt; 0$$)
**d)** $$\phi(u)$$ is a convex function (piecewise quadratic with a non-decreasing derivative)

**Step 3: Geometric meaning**
- **Regularization:** Shrinks toward the origin, preventing overfitting
- **$$\lambda$$** controls the bias-variance trade-off
- Equivalent to a Bayesian prior $$x \sim \mathcal{N}(0, \sigma^2/\lambda I)$$

**Step 4: Comparing robustness**
- **OLS:** Sensitive to outliers (quadratic penalty)
- **Weighted:** Can down-weight outliers if $$W$$ is chosen well
- **Regularized:** Reduces overfitting, improves generalization
- **Robust:** The Huber loss reduces sensitivity to outliers

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-linear-programming-in-standard-form&quot;&gt;📝 &lt;strong&gt;Exercise 3: Linear programming in standard form&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 1.3 from Boyd &amp;amp; Vandenberghe)
Convert the following problems to LP standard form:&lt;/p&gt;

&lt;p&gt;a) \(\min_{x,y} 2x + 3y \quad \text{s.t.} \quad x + 2y \geq 5, \quad x - y = 2, \quad x \geq 0, \quad y \text{ free}\)&lt;/p&gt;

&lt;p&gt;b) \(\max_x c^T x \quad \text{s.t.} \quad Ax \leq b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;c) \(\min_x \lVert c^T x - d \rVert_\infty \quad \text{s.t.} \quad Ax \leq b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Convert to the form \(\min c^T z \text{ s.t. } Az = b, z \geq 0\)&lt;/li&gt;
  &lt;li&gt;Identify the new matrix \(A\) and vectors \(b, c\)&lt;/li&gt;
  &lt;li&gt;Explain the transformations used&lt;/li&gt;
  &lt;li&gt;Verify that the original and transformed problems are equivalent&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Converting problem a)**

**Free variable:** $$y = y^+ - y^-$$ with $$y^+, y^- \geq 0$$

**Inequality:** $$x + 2y \geq 5 \Rightarrow x + 2y - s = 5$$ with $$s \geq 0$$

**Standard form:**
$$\min_{x,y^+,y^-,s} 2x + 3y^+ - 3y^- \quad \text{s.t.} \quad \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; -2 &amp;amp; -1 \\ 1 &amp;amp; -1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} x \\ y^+ \\ y^- \\ s \end{bmatrix} = \begin{bmatrix} 5 \\ 2 \end{bmatrix}$$

with $$x, y^+, y^-, s \geq 0$$.

**Step 2: Converting problem b)**

**Max to min:** $$\max c^T x = -\min (-c^T x)$$

**Inequality to equality:** $$Ax \leq b \Rightarrow Ax + s = b$$ with $$s \geq 0$$

**Standard form:**
$$\min_{x,s} (-c^T x + 0^T s) \quad \text{s.t.} \quad [A \quad I] \begin{bmatrix} x \\ s \end{bmatrix} = b, \quad x,s \geq 0$$

**Step 3: Converting problem c)**

**Rewriting the $$\ell_\infty$$ norm:** $$\min t \text{ s.t. } -t \leq c^T x - d \leq t$$

**Standard form:**
$$\min_{x,t,s_1,s_2,s_3} t \quad \text{s.t.} \quad \begin{bmatrix} A &amp;amp; 0 &amp;amp; I &amp;amp; 0 &amp;amp; 0 \\ c^T &amp;amp; -1 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ -c^T &amp;amp; -1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} x \\ t \\ s_1 \\ s_2 \\ s_3 \end{bmatrix} = \begin{bmatrix} b \\ d \\ -d \end{bmatrix}, \quad t, s_1, s_2, s_3 \geq 0$$

The last two rows are $$c^T x - d \leq t$$ and $$-(c^T x - d) \leq t$$; each needs its own slack variable. Since $$x$$ is free, also substitute $$x = x^+ - x^-$$ with $$x^+, x^- \geq 0$$ to reach the exact form $$z \geq 0$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-quadratic-programming-applications&quot;&gt;📝 &lt;strong&gt;Exercise 4: Quadratic programming applications&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 1.4 from Boyd &amp;amp; Vandenberghe)
Consider the portfolio optimization problem:&lt;/p&gt;

\[\min_x \frac{1}{2} x^T \Sigma x \quad \text{s.t.} \quad \mu^T x \geq r, \quad \mathbf{1}^T x = 1, \quad x \geq 0\]

&lt;p&gt;with \(\Sigma \succ 0\) (covariance matrix), \(\mu\) (expected returns), \(r\) (target return).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Prove that this is a convex QP&lt;/li&gt;
  &lt;li&gt;Write the KKT conditions&lt;/li&gt;
  &lt;li&gt;Analyze the case without the constraint \(x \geq 0\)&lt;/li&gt;
  &lt;li&gt;Find the efficient frontier&lt;/li&gt;
  &lt;li&gt;Implement numerical solution&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Proving convexity**
- Objective: $$f(x) = \frac{1}{2} x^T \Sigma x$$ with $$\nabla^2 f = \Sigma \succ 0$$
- Constraints: all linear
- $$\Rightarrow$$ Convex QP

**Step 2: KKT conditions**
Lagrangian (using $$\eta$$ for the multiplier of $$x \geq 0$$ to avoid a clash with $$\mu$$): $$L(x,\lambda,\nu,\eta) = \frac{1}{2} x^T \Sigma x - \lambda(\mu^T x - r) + \nu(\mathbf{1}^T x - 1) - \eta^T x$$

KKT conditions:
- Stationarity: $$\Sigma x - \lambda \mu + \nu \mathbf{1} - \eta = 0$$
- Primal feasibility: $$\mu^T x \geq r, \mathbf{1}^T x = 1, x \geq 0$$
- Dual feasibility: $$\lambda \geq 0, \eta \geq 0$$
- Complementary slackness: $$\lambda(\mu^T x - r) = 0, \eta_i x_i = 0$$

**Step 3: Dropping the constraint $$x \geq 0$$ (assuming the return constraint is active, $$\mu^T x = r$$)**
$$x^* = \Sigma^{-1}(\lambda^* \mu - \nu^* \mathbf{1})$$

From the constraints:
- $$\mathbf{1}^T x^* = 1 \Rightarrow \mathbf{1}^T \Sigma^{-1}(\lambda^* \mu - \nu^* \mathbf{1}) = 1$$
- $$\mu^T x^* = r \Rightarrow \mu^T \Sigma^{-1}(\lambda^* \mu - \nu^* \mathbf{1}) = r$$

Solve the system:
$$\begin{bmatrix} A &amp;amp; B \\ B &amp;amp; C \end{bmatrix} \begin{bmatrix} \lambda^* \\ -\nu^* \end{bmatrix} = \begin{bmatrix} r \\ 1 \end{bmatrix}$$

with $$A = \mu^T \Sigma^{-1} \mu, B = \mu^T \Sigma^{-1} \mathbf{1}, C = \mathbf{1}^T \Sigma^{-1} \mathbf{1}$$

**Step 4: The efficient frontier**
$$\sigma^2(r) = x^{*T} \Sigma x^* = \frac{Cr^2 - 2Br + A}{AC - B^2}$$

This is a hyperbola in the $$(r, \sigma)$$ plane.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-geometric-programming&quot;&gt;📝 &lt;strong&gt;Exercise 5: Geometric programming&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 1.5 from Boyd &amp;amp; Vandenberghe)
Consider the circuit design problem:&lt;/p&gt;

\[\min_{x,y,z} \frac{1}{xyz} \quad \text{s.t.} \quad \frac{x}{y} + \frac{y}{z} \leq 1, \quad z \leq 1, \quad x,y,z &amp;gt; 0\]

&lt;p&gt;&lt;em&gt;(The constraint \(z \leq 1\) is needed: without it, scaling \((x, y, z)\) by \(s &amp;gt; 0\) leaves the first constraint unchanged but drives \(\frac{1}{xyz} \to 0\) as \(s \to \infty\), so the problem has no optimal solution.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Show that this is a geometric program&lt;/li&gt;
  &lt;li&gt;Convert it to convex form with a log transformation&lt;/li&gt;
  &lt;li&gt;Solve the convex problem&lt;/li&gt;
  &lt;li&gt;Interpret the solution in the circuit-design context&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Verify that it is a geometric program**
- Objective: $$f_0(x,y,z) = x^{-1} y^{-1} z^{-1}$$ (monomial)
- Constraint: $$g_1(x,y,z) = x^1 y^{-1} z^0 + x^0 y^1 z^{-1}$$ (posynomial), $$g_2(x,y,z) = z$$ (monomial)
- Domain: $$x,y,z &amp;gt; 0$$

$$\Rightarrow$$ This is a GP in standard form.

**Step 2: Log transformation**
Let $$u = \log x, v = \log y, w = \log z$$:

$$\min_{u,v,w} -u - v - w \quad \text{s.t.} \quad \log(e^{u-v} + e^{v-w}) \leq 0, \quad w \leq 0$$

Equivalently:
$$\min_{u,v,w} -u - v - w \quad \text{s.t.} \quad e^{u-v} + e^{v-w} \leq 1, \quad w \leq 0$$

**Step 3: Convex formulation**
The objective is linear, $$\log(e^{u-v} + e^{v-w})$$ is log-sum-exp of affine functions (convex), and $$w \leq 0$$ is linear.

This is a convex problem (log-sum-exp constraint).

**Step 4: Solution method**
Use an interior-point method or a dedicated GP solver.

The optimal solution:
- $$x^* = e^{u^*}, y^* = e^{v^*}, z^* = e^{w^*}$$
- Both constraints are active. With $$z = 1$$, the problem becomes $$\max xy$$ s.t. $$x \leq y(1 - y)$$, i.e. $$\max_y y^2(1-y)$$, attained at $$y = 2/3$$.
- Solution: $$x^* = 2/9$$, $$y^* = 2/3$$, $$z^* = 1$$; check $$\frac{x^*}{y^*} + \frac{y^*}{z^*} = \frac{1}{3} + \frac{2}{3} = 1$$ ✓; optimal value $$\frac{1}{x^*y^*z^*} = \frac{27}{4}$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-6-semidefinite-programming-basics&quot;&gt;📝 &lt;strong&gt;Exercise 6: Semidefinite programming basics&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 1.6 from Boyd &amp;amp; Vandenberghe)
Consider the problem:&lt;/p&gt;

\[\min_X \text{tr}(CX) \quad \text{s.t.} \quad \text{tr}(A_i X) = b_i, \quad i = 1,\ldots,m, \quad X \succeq 0\]

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Prove that this is a convex optimization problem&lt;/li&gt;
  &lt;li&gt;Write the dual problem&lt;/li&gt;
  &lt;li&gt;Analyze the conditions for strong duality&lt;/li&gt;
  &lt;li&gt;Concrete example: the Maximum Cut relaxation&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Proving convexity**
- Objective: $$\text{tr}(CX)$$ is linear in $$X$$
- Constraints: $$\text{tr}(A_i X) = b_i$$ linear
- Constraint: $$X \succeq 0$$ convex (positive semidefinite cone)

$$\Rightarrow$$ Convex SDP

**Step 2: Dual problem**
Lagrangian: $$L(X,y,Z) = \text{tr}(CX) + \sum_{i=1}^m y_i (b_i - \text{tr}(A_i X)) - \text{tr}(ZX)$$

Dual function: $$g(y,Z) = \inf_X L(X,y,Z)$$

Condition: $$C - \sum_{i=1}^m y_i A_i - Z = 0$$

**Dual problem:**
$$\max_{y,Z} \sum_{i=1}^m b_i y_i \quad \text{s.t.} \quad \sum_{i=1}^m y_i A_i + Z = C, \quad Z \succeq 0$$

**Step 3: Strong duality**
Strong duality holds if Slater&apos;s condition is satisfied:
$$\exists X \succ 0 \text{ s.t. } \text{tr}(A_i X) = b_i, \forall i$$

**Step 4: Maximum cut example**
Given a graph $$G = (V,E)$$ with weights $$w_{ij}$$:

$$\max_x \sum_{(i,j) \in E} w_{ij} \frac{1 - x_i x_j}{2} \quad \text{s.t.} \quad x_i \in \{-1,1\}$$

**SDP relaxation:**
$$\max_X \sum_{(i,j) \in E} w_{ij} \frac{1 - X_{ij}}{2} \quad \text{s.t.} \quad X_{ii} = 1, \quad X \succeq 0$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-7-introduction-to-robust-optimization&quot;&gt;📝 &lt;strong&gt;Exercise 7: Introduction to robust optimization&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 1.7 from Boyd &amp;amp; Vandenberghe)
Consider the robust linear program:&lt;/p&gt;

\[\min_x c^T x \quad \text{s.t.} \quad a_i^T x \leq b_i \quad \forall a_i \in \mathcal{U}_i, \quad i = 1,\ldots,m\]

&lt;p&gt;with uncertainty sets:
a) Box: \(\mathcal{U}_i = \{a_i^{nom} + u : \lVert u \rVert_\infty \leq \rho_i\}\)
b) Ellipsoidal: \(\mathcal{U}_i = \{a_i^{nom} + P_i u : \lVert u \rVert_2 \leq 1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Reformulate as deterministic convex programs&lt;/li&gt;
  &lt;li&gt;Compare the computational complexity&lt;/li&gt;
  &lt;li&gt;Analyze the level of conservatism&lt;/li&gt;
  &lt;li&gt;Implement and compare the solutions&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Box uncertainty**
$$\max_{a_i \in \mathcal{U}_i} a_i^T x = (a_i^{nom})^T x + \rho_i \lVert x \rVert_1$$

**Deterministic equivalent:**
$$\min_x c^T x \quad \text{s.t.} \quad (a_i^{nom})^T x + \rho_i \lVert x \rVert_1 \leq b_i$$

**LP reformulation:**
$$\min_{x,t_i} c^T x \quad \text{s.t.} \quad (a_i^{nom})^T x + \rho_i \sum_j t_{ij} \leq b_i, \quad -t_{ij} \leq x_j \leq t_{ij}$$

**Step 2: Ellipsoidal uncertainty**
$$\max_{a_i \in \mathcal{U}_i} a_i^T x = (a_i^{nom})^T x + \lVert P_i^T x \rVert_2$$

**Deterministic equivalent:**
$$\min_x c^T x \quad \text{s.t.} \quad (a_i^{nom})^T x + \lVert P_i^T x \rVert_2 \leq b_i$$

This is a Second-Order Cone Program (SOCP).

**Step 3: Comparing complexity**
- **Box:** LP with $$O(mn)$$ variables and constraints
- **Ellipsoidal:** SOCP with $$n + m$$ variables and $$m$$ SOC constraints
- **Nominal:** LP with $$n$$ variables and $$m$$ constraints

**Step 4: Analyzing conservatism**
- **Box:** Most conservative (worst case in every direction)
- **Ellipsoidal:** Moderately conservative (direction-dependent uncertainty)
- **Nominal:** Least conservative (no uncertainty)

Price of robustness = $$\frac{\text{Robust optimal value}}{\text{Nominal optimal value}} - 1$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-8-convexity-verification&quot;&gt;📝 &lt;strong&gt;Exercise 8: Convexity verification&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 1.8 from Boyd &amp;amp; Vandenberghe)
Determine whether the following functions are convex:&lt;/p&gt;

&lt;p&gt;a) \(f(x) = x \log x\) on \(\mathbb{R}_{++}\)
b) \(f(x) = -\log(\det X)\) on \(\mathbb{S}_{++}^n\)
c) \(f(x) = \lVert x \rVert_p\) with \(p \geq 1\)
d) \(f(X) = \lambda_{\max}(X)\) on \(\mathbb{S}^n\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Prove or disprove convexity&lt;/li&gt;
  &lt;li&gt;Compute second-order conditions where applicable&lt;/li&gt;
  &lt;li&gt;Verify using the definition or composition rules&lt;/li&gt;
  &lt;li&gt;Find the convex domain of each function&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: $$f(x) = x \log x$$**
**Domain:** $$\mathbb{R}_{++}$$ (convex)

**Second derivative:** $$f&apos;&apos;(x) = \frac{1}{x} &amp;gt; 0$$ for $$x &amp;gt; 0$$

$$\Rightarrow$$ Convex on $$\mathbb{R}_{++}$$

**Step 2: $$f(X) = -\log(\det X)$$**
**Domain:** $$\mathbb{S}_{++}^n$$ (convex)

**Hessian:** One can show that $$\nabla^2 f \succ 0$$

Alternative: $$-\log(\det X) = -\log(\prod_i \lambda_i) = -\sum_i \log \lambda_i$$

Arguing eigenvalue by eigenvalue is not enough (eigenvalues are not concave functions of $$X$$; only $$\lambda_{\min}$$ is). The standard argument: take $$X = Z + tV$$ with $$Z \succ 0$$; then $$f(Z + tV) = -\log\det Z - \sum_i \log(1 + t\lambda_i)$$, where $$\lambda_i$$ are the eigenvalues of $$Z^{-1/2} V Z^{-1/2}$$. Each term $$-\log(1 + t\lambda_i)$$ is convex in $$t$$, so $$f$$ is convex.

**Result:** Convex on $$\mathbb{S}_{++}^n$$

**Step 3: $$f(x) = \lVert x \rVert_p$$**
**Domain:** $$\mathbb{R}^n$$ (convex)

**For $$p \geq 1$$:** Triangle inequality $$\Rightarrow$$ convex
**For $$0 &amp;lt; p &amp;lt; 1$$:** Not convex (the triangle inequality fails: for $$p = 1/2$$, $$\lVert (1,1) \rVert_{1/2} = 4 &amp;gt; \lVert (1,0) \rVert_{1/2} + \lVert (0,1) \rVert_{1/2} = 2$$)

**Verification:** Minkowski inequality for $$p \geq 1$$

**Step 4: $$f(X) = \lambda_{\max}(X)$$**
**Domain:** $$\mathbb{S}^n$$ (convex)

**Convexity:** $$\lambda_{\max}(X) = \max_{\lVert v \rVert = 1} v^T X v$$

A maximum of linear functions $$\Rightarrow$$ convex

**Alternative:** Spectral norm property

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-9-optimization-modeling&quot;&gt;📝 &lt;strong&gt;Exercise 9: Optimization modeling&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 1.9 from Boyd &amp;amp; Vandenberghe)
Formulate the following real-world problems as convex optimization problems:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Antenna array design:&lt;/strong&gt; Minimize sidelobe level
b) &lt;strong&gt;Filter design:&lt;/strong&gt; Minimize passband ripple and stopband energy
c) &lt;strong&gt;Truss design:&lt;/strong&gt; Minimize weight subject to stiffness constraints
d) &lt;strong&gt;Data fitting:&lt;/strong&gt; Robust regression with outliers&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Mathematical formulation of each problem&lt;/li&gt;
  &lt;li&gt;Identify variables, objective, constraints&lt;/li&gt;
  &lt;li&gt;Verify convexity&lt;/li&gt;
  &lt;li&gt;Suggest solution approaches&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Antenna array design**
**Variables:** $$w \in \mathbb{C}^n$$ (array weights)

**Objective:** Minimize maximum sidelobe level
$$\min_{w,t} t \quad \text{s.t.} \quad |a(\theta)^H w| \leq t, \quad \forall \theta \in \Theta_{sidelobe}$$

where $$a(\theta)$$ is the steering vector and $$\Theta_{sidelobe}$$ is the sidelobe region.

**Main beam constraint:** $$a(\theta_0)^H w = 1$$ (normalization)

**Convex:** SOCP (second-order cone constraints)

**Step 2: Filter design**
**Variables:** $$h \in \mathbb{R}^n$$ (filter coefficients)

**Passband ripple:** $$|H(\omega) - 1| \leq \delta_p, \quad \omega \in \Omega_p$$
**Stopband attenuation:** $$|H(\omega)| \leq \delta_s, \quad \omega \in \Omega_s$$

where $$H(\omega) = \sum_{k=0}^{n-1} h_k e^{-j\omega k}$$

**Convex formulation:**
$$\min_{h,\delta_p,\delta_s} \alpha \delta_p + \beta \delta_s$$
subject to frequency response constraints.

**Step 3: Truss design**
**Variables:** $$A \in \mathbb{R}^m$$ (cross-sectional areas)

**Objective:** $$\min \sum_{i=1}^m \rho_i l_i A_i$$ (total weight)

**Stiffness constraint:** $$u^T K(A) u \geq u_{min}^T K_0 u_{min}$$

where $$K(A) = \sum_{i=1}^m A_i K_i$$ (stiffness matrix)

**Convex:** Linear objective, constraint linear in $$A$$

**Step 4: Robust regression**
**Variables:** $$\beta \in \mathbb{R}^p$$ (regression coefficients)

**Huber loss:** $$\min_\beta \sum_{i=1}^n \phi(y_i - x_i^T \beta)$$

where $$\phi(u) = \begin{cases} \frac{1}{2}u^2 &amp;amp; |u| \leq M \\ M|u| - \frac{1}{2}M^2 &amp;amp; |u| &amp;gt; M \end{cases}$$

**Convex:** The Huber function is convex

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-10-introduction-to-duality&quot;&gt;📝 &lt;strong&gt;Exercise 10: Introduction to duality&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; (Exercise 1.10 from Boyd &amp;amp; Vandenberghe)
Consider the LP:
\(\min_x c^T x \quad \text{s.t.} \quad Ax = b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Derive the dual problem using the Lagrangian approach&lt;/li&gt;
  &lt;li&gt;Prove weak duality&lt;/li&gt;
  &lt;li&gt;Find conditions for strong duality&lt;/li&gt;
  &lt;li&gt;Interpret dual variables economically&lt;/li&gt;
  &lt;li&gt;Verify complementary slackness&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Lagrangian and dual**
$$L(x,\nu,\lambda) = c^T x + \nu^T(Ax - b) - \lambda^T x$$

**Dual function:**
$$g(\nu,\lambda) = \inf_x L(x,\nu,\lambda) = \inf_x (c + A^T \nu - \lambda)^T x - \nu^T b$$

**Finiteness condition:** $$c + A^T \nu - \lambda = 0$$, i.e., $$\lambda = A^T \nu + c$$

**Dual problem:**
$$\max_{\nu,\lambda} g(\nu,\lambda) = \max_\nu -\nu^T b \quad \text{s.t.} \quad A^T \nu + c \geq 0$$

Equivalently:
$$\max_\nu b^T \nu \quad \text{s.t.} \quad A^T \nu \leq c$$

**Step 2: Weak duality**
For every primal feasible $$x$$ and dual feasible $$\nu$$:
$$c^T x \geq b^T \nu$$

**Proof:** 
$$c^T x \geq (A^T \nu)^T x = \nu^T Ax = \nu^T b = b^T \nu$$

**Step 3: Strong duality**
Strong duality holds for LP whenever both the primal and the dual are feasible (fundamental theorem of LP).

**Step 4: Economic interpretation**
- $$\nu_i$$: shadow price of resource $$i$$
- $$\nu_i$$ = marginal value of constraint $$i$$
- If $$b_i$$ increases by 1 unit, the optimal value increases by $$\nu_i$$

**Step 5: Complementary slackness**
- If $$x_j^* &amp;gt; 0$$, then $$(A^T \nu^*)_j = c_j$$ (reduced cost = 0)
- If $$(A^T \nu^*)_j &amp;lt; c_j$$, then $$x_j^* = 0$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-practical-tips&quot;&gt;💡 Practical Tips&lt;/h2&gt;

&lt;h4 id=&quot;when-classifying-optimization-problems&quot;&gt;&lt;strong&gt;When classifying optimization problems:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Check the form of the objective (linear, quadratic, general)&lt;/li&gt;
  &lt;li&gt;Identify the constraint types (linear, quadratic, conic)&lt;/li&gt;
  &lt;li&gt;Verify the convexity of each component&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;when-converting-to-standard-form&quot;&gt;&lt;strong&gt;When converting to standard form:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Free variables: \(x = x^+ - x^-\)&lt;/li&gt;
  &lt;li&gt;Inequalities: add slack variables&lt;/li&gt;
  &lt;li&gt;Max to min: flip the sign of the objective&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;when-verifying-convexity&quot;&gt;&lt;strong&gt;When verifying convexity:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Use the second-order condition when possible&lt;/li&gt;
  &lt;li&gt;Apply composition rules and convexity-preserving operations&lt;/li&gt;
  &lt;li&gt;Check the definition directly if needed&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;classes-of-optimization-problems&quot;&gt;&lt;strong&gt;Classes of Optimization Problems:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Class&lt;/th&gt;
      &lt;th&gt;Objective&lt;/th&gt;
      &lt;th&gt;Constraints&lt;/th&gt;
      &lt;th&gt;Example&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;LP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;\(\min c^Tx\), \(Ax \leq b\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Quadratic&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;\(\min \frac{1}{2}x^TQx + c^Tx\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;QCQP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Quadratic&lt;/td&gt;
      &lt;td&gt;Quadratic&lt;/td&gt;
      &lt;td&gt;Portfolio with risk constraints&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SOCP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;\(\ell_2\) norm&lt;/td&gt;
      &lt;td&gt;\(||Ax-b||_2 \leq c^Tx\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SDP&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Linear&lt;/td&gt;
      &lt;td&gt;PSD matrix&lt;/td&gt;
      &lt;td&gt;\(\min \text{tr}(CX)\), \(X \succeq 0\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;least-squares-variants&quot;&gt;&lt;strong&gt;Least Squares Variants:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Objective&lt;/th&gt;
      &lt;th&gt;Characteristics&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Ordinary LS&lt;/td&gt;
      &lt;td&gt;\(||Ax-b||_2^2\)&lt;/td&gt;
      &lt;td&gt;Closed-form solution&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Weighted LS&lt;/td&gt;
      &lt;td&gt;\((Ax-b)^TW(Ax-b)\)&lt;/td&gt;
      &lt;td&gt;Weights for observations&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Regularized LS&lt;/td&gt;
      &lt;td&gt;\(||Ax-b||_2^2 + \lambda||x||_2^2\)&lt;/td&gt;
      &lt;td&gt;Ridge regression&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Robust LS&lt;/td&gt;
      &lt;td&gt;\(\sum \phi((Ax-b)_i)\)&lt;/td&gt;
      &lt;td&gt;Resistant to outliers&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;LASSO&lt;/td&gt;
      &lt;td&gt;\(||Ax-b||_2^2 + \lambda||x||_1\)&lt;/td&gt;
      &lt;td&gt;Sparse solutions&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;duality-concepts&quot;&gt;&lt;strong&gt;Duality Concepts:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Weak duality:&lt;/strong&gt; \(d^* \leq p^*\) (always holds)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strong duality:&lt;/strong&gt; \(d^* = p^*\) (requires conditions, e.g., Slater)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Shadow price:&lt;/strong&gt; \(\nu_i^*\) = marginal value of constraint \(i\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; \(\lambda_i^* (g_i(x^*)) = 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 References&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 1: Introduction&lt;/li&gt;
      &lt;li&gt;Exercises 1.1-1.15&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nocedal, J., &amp;amp; Wright, S. J.&lt;/strong&gt; (2006). &lt;em&gt;Numerical Optimization&lt;/em&gt;. Springer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bertsekas, D. P.&lt;/strong&gt; (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt;. Athena Scientific.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>01-06 Multiple-Choice Quiz - Optimization Problems</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_06_Quiz_Optimization_Problems/"/>
   <updated>2021-01-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_06_Quiz_Optimization_Problems</id>
   <content type="html">&lt;p&gt;Spotting convexity in the wild is a pattern-recognition skill that sharpens only when you test it against tricky counterexamples—like an optimization problem with a convex objective whose single quadratic &lt;em&gt;equality&lt;/em&gt; constraint quietly breaks convexity. This Chapter 01 quiz tests your command of standard formulations, convex vs. nonconvex classification, and algorithm selection before we dive into the geometry of convex sets in Chapter 02.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-key-concepts-tested-in-this-quiz&quot;&gt;Key ideas: Key Concepts Tested in This Quiz&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Standard Form Translation:&lt;/strong&gt; Mapping maximization, lower-bound inequalities (\(g(x) \ge c\)), and implicit domain constraints cleanly into standard minimization form.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convexity Verification Rules:&lt;/strong&gt; Checking all three pieces—objective \(f_0\) convex, inequalities \(f_i \le 0\) convex, and equalities \(h_j = 0\) affine—never just the objective alone.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Local vs. Global Optimality:&lt;/strong&gt; Distinguishing guarantees for convex problems (every local min is global) vs. strictly convex problems (unique global min) vs. nonconvex problems.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solver &amp;amp; Algorithm Awareness:&lt;/strong&gt; Matching problem families (LP, QP, nonsmooth composite) to the right algorithmic class (Simplex, interior-point, proximal gradient, ADMM).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-one-symbol-le-vs--flips-convexity&quot;&gt;Worked example: Why One Symbol (\(\le\) vs. \(=\)) Flips Convexity&lt;/h3&gt;

&lt;p&gt;Compare two nearly identical 1D problems:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Problem A:&lt;/strong&gt; \(\min_x \; x^2 - 4x \quad \text{s.t.} \quad x^2 - 1 \le 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Problem B:&lt;/strong&gt; \(\min_x \; x^2 - 4x \quad \text{s.t.} \quad x^2 - 1 = 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check Problem A:&lt;/strong&gt; The objective \(x^2 - 4x\) has second derivative \(2 &amp;gt; 0\) (convex), and the inequality \(x^2 - 1 \le 0\) defines the interval \([-1, 1]\) (a convex set). Thus Problem A is &lt;strong&gt;convex&lt;/strong&gt;, minimized at \(x^* = 1\) with \(p^* = -3\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check Problem B:&lt;/strong&gt; The equality constraint \(x^2 - 1 = 0\) is &lt;strong&gt;nonlinear (not affine)&lt;/strong&gt;. Its feasible set is \(\{-1, 1\}\), which is &lt;strong&gt;nonconvex&lt;/strong&gt;: the midpoint \(\frac{1}{2}(-1) + \frac{1}{2}(1) = 0\) is not in \(\{-1, 1\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lesson for the quiz:&lt;/strong&gt; Always check whether equality constraints are affine—a convex function set &lt;em&gt;equal&lt;/em&gt; to zero almost never defines a convex constraint!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the basic concepts of optimization problems and convex optimization.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-the-general-optimization-problem&quot;&gt;🎯 &lt;strong&gt;The General Optimization Problem&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Standard form:&lt;/strong&gt;
\(\begin{align*} 
&amp;amp;\min_{x\in D}\ &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp; g_i(x) \le 0,\ i = 1, ..., m \\
&amp;amp;&amp;amp;&amp;amp; h_j(x) = 0,\ j = 1,\ ..., r
\end{align*}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Components:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\): optimization variable (decision variable)&lt;/li&gt;
  &lt;li&gt;\(f(x)\): objective function or cost function&lt;/li&gt;
  &lt;li&gt;\(g_i(x) \le 0\): inequality constraints&lt;/li&gt;
  &lt;li&gt;\(h_j(x) = 0\): equality constraints&lt;/li&gt;
  &lt;li&gt;\(x^*\): optimal solution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Feasible region:&lt;/strong&gt;
\(D = \text{dom}(f) \cap \bigcap_{i=1}^m \text{dom}(g_i) \cap \bigcap_{j=1}^r \text{dom}(h_j)\)&lt;/p&gt;

&lt;h3 id=&quot;-convex-sets&quot;&gt;🔵 &lt;strong&gt;Convex Sets&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt;
A set \(C\) is convex if for all \(x_1, x_2 \in C\) and \(0 \le \theta \le 1\):
\(\theta x_1 + (1-\theta)x_2 \in C\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Line segment:&lt;/strong&gt; \(x = \theta x_1 + (1 - \theta) x_2\) with \(0 \le \theta \le 1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convex combination:&lt;/strong&gt;
\(x = \sum_{i=1}^k \theta_i x_i\) with \(\sum_{i=1}^k \theta_i = 1, \theta_i \ge 0\)&lt;/p&gt;

&lt;h3 id=&quot;-convex-functions&quot;&gt;📈 &lt;strong&gt;Convex Functions&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt;
A function \(f: \mathbb{R}^n \rightarrow \mathbb{R}\) is convex if:&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;\(\text{dom}(f)\) is a convex set&lt;/li&gt;
    &lt;li&gt;\(f(\theta x + (1 - \theta)y) \le \theta f(x) + (1-\theta)f(y)\)
for all \(x, y \in \text{dom}(f), 0 \le \theta \le 1\)&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Epigraph:&lt;/strong&gt;
\(\text{epi } f = \{(x, t) \in \mathbb{R}^{n+1} \mid x \in \text{dom } f, f(x) \le t\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key property:&lt;/strong&gt; \(f\) convex ⟺ \(\text{epi } f\) is a convex set&lt;/p&gt;

&lt;h3 id=&quot;-convex-optimization-problems&quot;&gt;🏆 &lt;strong&gt;Convex Optimization Problems&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt;
An optimization problem is convex when:&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;The objective function \(f\) is convex&lt;/li&gt;
    &lt;li&gt;The inequality constraint functions \(g_i\) are convex&lt;/li&gt;
    &lt;li&gt;The equality constraint functions \(h_j\) are affine: \(h_j(x) = a_j^T x + b_j\)&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The golden property:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Every local minimum of a convex optimization problem is a global minimum&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Affine function:&lt;/strong&gt; \(f(x) = Ax + b\) (linear + constant)&lt;/p&gt;

&lt;h3 id=&quot;-concave-vs-convex-functions&quot;&gt;🔄 &lt;strong&gt;Concave vs Convex Functions&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Concave function:&lt;/strong&gt; \(f\) concave ⟺ \(-f\) convex
\(f(\theta x + (1 - \theta)y) \ge \theta f(x) + (1-\theta)f(y)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conversion:&lt;/strong&gt; Maximizing a concave function \(f\) = Minimizing the convex function \(-f\)&lt;/p&gt;

&lt;h3 id=&quot;-course-goals&quot;&gt;🎯 &lt;strong&gt;Course Goals&lt;/strong&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Recognize:&lt;/strong&gt; When is a problem a convex optimization problem?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Formulate:&lt;/strong&gt; Turn real-world situations into convex optimization problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choose:&lt;/strong&gt; The most suitable algorithm for each specific problem&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;️-main-algorithms&quot;&gt;🛠️ &lt;strong&gt;Main Algorithms&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent:&lt;/strong&gt; First-order method&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Newton Method:&lt;/strong&gt; Second-order method&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Proximal Gradient:&lt;/strong&gt; For non-differentiable functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ADMM:&lt;/strong&gt; For problems with special structure&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coordinate Descent:&lt;/strong&gt; Optimize one variable at a time&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; Convex optimization has a wonderful property - there are no “spurious” local minima; every local solution is global!&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Multiple-Choice Quiz: Optimization Problems&lt;/h2&gt;
        &lt;p&gt;Choose the best answer for each question. You will see your results as soon as you finish.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Question 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Question 1: In the standard form of an optimization problem, $$f(x)$$ is called:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Constraint function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Objective function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Optimization variable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Feasible region&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Objective function&lt;/strong&gt;&lt;br /&gt;
                In the optimization problem $$\min_{x\in D} f(x)$$, the function $$f(x)$$ is the objective function (or cost function) that we want to minimize.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: Consider the problem $$\min \log(x)$$. The constraint $$x &amp;gt; 0$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) An explicit constraint&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) An implicit constraint&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) An equality constraint&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Not a constraint&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) An implicit constraint&lt;/strong&gt;&lt;br /&gt;
                The constraint $$x &amp;gt; 0$$ comes from the domain of $$\log(x)$$ and is not stated directly in the problem, so it is called an implicit constraint.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: A set $$C$$ is called convex if:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) For all $$x_1, x_2 \in C$$ and $$0 \leq \theta \leq 1$$, we have $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) The set $$C$$ is a disk&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) The set $$C$$ has no holes&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) The set $$C$$ is closed&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) For all $$x_1, x_2 \in C$$ and $$0 \leq \theta \leq 1$$, we have $$\theta x_1 + (1-\theta)x_2 \in C$$&lt;/strong&gt;&lt;br /&gt;
                Definition of a convex set: the line segment joining any two points of the set lies entirely in the set.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: A function $$f$$ is convex if:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$f(\theta x + (1-\theta)y) \geq \theta f(x) + (1-\theta)f(y)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) $$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) $$f(\theta x + (1-\theta)y) = \theta f(x) + (1-\theta)f(y)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) $$f$$ is a linear function&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$&lt;/strong&gt;&lt;br /&gt;
                Definition of a convex function: the line segment joining any two points on the graph lies above the graph of the function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: If $$f$$ is a concave function, then $$-f$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Cannot be determined&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Convex&lt;/strong&gt;&lt;br /&gt;
                By definition, $$f$$ is concave if and only if $$-f$$ is convex. This is how maximizing a concave function is turned into minimizing a convex function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: The epigraph of a function $$f$$ is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) $$\{(x,t) : x \in \text{dom } f, f(x) \geq t\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) $$\{(x,t) : x \in \text{dom } f, f(x) \leq t\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) $$\{(x,t) : x \in \text{dom } f, f(x) = t\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) $$\{x : x \in \text{dom } f\}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\{(x,t) : x \in \text{dom } f, f(x) \leq t\}$$&lt;/strong&gt;&lt;br /&gt;
                The epigraph is the set of points lying above the graph of the function. &quot;Epi&quot; means &quot;above&quot;.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: A function $$f$$ is convex if and only if:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) The domain of $$f$$ is a convex set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) The epigraph of $$f$$ is a convex set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) The graph of $$f$$ is a convex set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) The hypograph of $$f$$ is a convex set&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The epigraph of $$f$$ is a convex set&lt;/strong&gt;&lt;br /&gt;
                This is the key link between convex functions and convex sets: convex function ⟺ convex epigraph.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: For a convex function, a local optimum:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) Is always a global optimum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) May not be a global optimum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Does not exist&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) Is always the unique point&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Is always a global optimum&lt;/strong&gt;&lt;br /&gt;
                This is an important property of convex functions: every local optimum is a global optimum, which makes finding solutions easier.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: A convex combination of the points $$x_1, x_2, ..., x_k$$ has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) $$\sum_{i=1}^k \theta_i x_i$$ with $$\theta_i \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) $$\sum_{i=1}^k \theta_i x_i$$ with $$\sum_{i=1}^k \theta_i = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) $$\sum_{i=1}^k \theta_i x_i$$ with $$\theta_i \geq 0$$ and $$\sum_{i=1}^k \theta_i = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) $$\sum_{i=1}^k x_i$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) $$\sum_{i=1}^k \theta_i x_i$$ with $$\theta_i \geq 0$$ and $$\sum_{i=1}^k \theta_i = 1$$&lt;/strong&gt;&lt;br /&gt;
                A convex combination requires nonnegative coefficients summing to 1, producing a &quot;weighted average&quot; of the points.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: In a convex optimization problem, the equality constraint functions $$h_j(x) = 0$$ must be:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) Convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) Concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Affine functions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) Arbitrary functions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) Affine function&lt;/strong&gt;&lt;br /&gt;
                In a convex optimization problem, the equality constraints must be affine: $$h_j(x) = a_j^T x + b_j$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: An affine function has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) $$e^{a^T x} + b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) $$ax^2 + bx + c$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) $$a^T x + b$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) $$\|x\|^2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) $$a^T x + b$$&lt;/strong&gt;&lt;br /&gt;
                An affine function is a linear function plus a constant, with general form $$a^T x + b$$ in several dimensions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: Which of the following sets is convex?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) A disk&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) A square&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) A halfspace&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                A disk, a square and a halfspace are all examples of convex sets, because the segment joining any two points of the set lies entirely in the set.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: Which of the following functions is convex?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) $$f(x) = x^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) $$f(x) = |x|$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) $$f(x) = e^x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                $$x^2$$ (parabola), $$|x|$$ (absolute value), and $$e^x$$ (exponential) are all basic examples of convex functions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: In machine learning, which of the following problems is usually solved by convex optimization?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Training a neural network&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Linear regression&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Feature selection via the Lasso ($$\ell_1$$ penalty)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Both B and C&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) Both B and C&lt;/strong&gt;&lt;br /&gt;
                Linear regression and feature selection via the Lasso (a convex relaxation of subset selection) lead to convex optimization problems. Training a neural network is usually a non-convex problem.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: The feasible region of an optimization problem is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) The set of all variables&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) The set of points satisfying all the constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) The domain of the objective function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) The set of optimal solutions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The set of points satisfying all the constraints&lt;/strong&gt;&lt;br /&gt;
                The feasible region is the set of all points $$x$$ satisfying the constraints $$g_i(x) \leq 0$$ and $$h_j(x) = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: Who developed the Simplex algorithm, and in what year?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) George Dantzig, 1947&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) John von Neumann, 1944&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) Leonid Kantorovich, 1939&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Narendra Karmarkar, 1984&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) George Dantzig, 1947&lt;/strong&gt;&lt;br /&gt;
                George Dantzig developed the Simplex algorithm in 1947, revolutionizing practical optimization.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: In total variation denoising, the term $$\sum_{(i,j) \in E} |\theta_i - \theta_j|$$ serves to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Increase the noise&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Smooth the image&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Increase the contrast&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Reduce the image size&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Smooth the image&lt;/strong&gt;&lt;br /&gt;
                The total variation penalty encourages small changes between neighboring pixels, which smooths the image.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: In a convex optimization problem, the inequality constraint functions $$g_i(x) \leq 0$$ must be:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Concave&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Linear&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Arbitrary functions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Convex&lt;/strong&gt;&lt;br /&gt;
                In a convex optimization problem, the inequality constraint functions $$g_i(x) \leq 0$$ must be convex to guarantee that the feasible region is a convex set.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: The main advantage of convex optimization problems over non-convex ones is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) They have more solutions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) There are no local minima (other than global minima)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) They are faster to compute&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) They have wider applications&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) There are no local minima (other than global minima)&lt;/strong&gt;&lt;br /&gt;
                The main advantage of convex optimization is that every local minimum is a global minimum, which avoids getting &quot;stuck&quot; at a local minimum.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20: Real-world applications --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: Which of the following is NOT a main application of convex optimization?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Signal processing&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Circuit design&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Video games&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Finance&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) Video games&lt;/strong&gt;&lt;br /&gt;
                Although optimization can be used in video games, signal processing, circuit design and finance are the main and more traditional applications of convex optimization.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 21 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: Consider minimizing $$f(x) = x^2 + 4x + 3$$. The optimal value is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$-1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$3$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$-2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$-1$$&lt;/strong&gt;&lt;br /&gt;
                $$f&apos;(x) = 2x + 4 = 0 \Rightarrow x = -2$$&lt;br /&gt;
                $$f(-2) = (-2)^2 + 4(-2) + 3 = 4 - 8 + 3 = -1$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: Is the function $$f(x) = |x|$$ convex?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Yes, because $$f&apos;&apos;(x) \geq 0$$ everywhere&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Yes, by the definition of a convex function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) No, because it is not differentiable at $$x = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) No, because the graph has a sharp corner&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Yes, by the definition of a convex function&lt;/strong&gt;&lt;br /&gt;
                The function $$|x|$$ satisfies $$|tx + (1-t)y| \leq t|x| + (1-t)|y|$$ for all $$t \in [0,1]$$. Non-differentiability at one point does not affect convexity.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: In a budget allocation problem with $$x_1 + x_2 + x_3 = 100$$ and $$x_i \geq 0$$, how many constraints are there?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) 1 equality constraint, 3 inequality constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) 4 equality constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) 3 inequality constraints&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) 1 equality constraint&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) 1 equality constraint, 3 inequality constraints&lt;/strong&gt;&lt;br /&gt;
                There is 1 equality constraint $$x_1 + x_2 + x_3 = 100$$ and 3 inequality constraints $$x_1 \geq 0, x_2 \geq 0, x_3 \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The feasible region of the problem $$\min x^2 + y^2$$ subject to $$x + y = 1, x \geq 0, y \geq 0$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) The line segment from $$(0,1)$$ to $$(1,0)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) The triangle with vertices $$(0,0), (0,1), (1,0)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) The unit circle&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) The whole plane&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The line segment from $$(0,1)$$ to $$(1,0)$$&lt;/strong&gt;&lt;br /&gt;
                The constraint $$x + y = 1$$ gives a line; combined with $$x \geq 0, y \geq 0$$ we get a line segment in the first quadrant.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: The solution of the problem $$\min x^2 + y^2$$ subject to $$x + y = 1$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$x = 0.5, y = 0.5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$x = 1, y = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$x = 0, y = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$x = 1, y = 1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$x = 0.5, y = 0.5$$&lt;/strong&gt;&lt;br /&gt;
                Use the Lagrange method or substitute $$y = 1-x$$ into the objective:&lt;br /&gt;
                $$\min x^2 + (1-x)^2 = 2x^2 - 2x + 1$$&lt;br /&gt;
                $$\frac{d}{dx}(2x^2 - 2x + 1) = 4x - 2 = 0 \Rightarrow x = 0.5, y = 0.5$$
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Previous&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Next&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Exercise Results&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #FF6B35, #F7931E);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #FF6B35;
    background-color: #fff5f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #FF6B35;
    background-color: #ffe8e0;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #e8f4fd;
    border-left: 4px solid #2196F3;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #1976D2;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #FF6B35;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #e55a2b;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #f0f8f0;
    border-radius: 8px;
    border: 2px solid #FF6B35;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #d84315;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answer for each question
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;a&apos;, q4: &apos;b&apos;, q5: &apos;b&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;c&apos;, q10: &apos;c&apos;,
    q11: &apos;c&apos;, q12: &apos;d&apos;, q13: &apos;d&apos;, q14: &apos;d&apos;, q15: &apos;b&apos;,
    q16: &apos;a&apos;, q17: &apos;b&apos;, q18: &apos;a&apos;, q19: &apos;b&apos;, q20: &apos;c&apos;,
    q21: &apos;a&apos;, q22: &apos;b&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;
};

/**
 * Update the progress bar and show the current question
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Question ${currentQuestion}/${totalQuestions}`;
}

/**
 * Show a question by its number
 */
function showQuestion(questionNum) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Update the state of the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Go to the next question
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Go back to the previous question
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Store the user&apos;s answer
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Update the UI to show the selected answer
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Submit and show the results
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Compute the score and build the detailed report
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Show explanations for all questions
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Build the detailed report
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Question ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Correct&apos; : &apos;Incorrect&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Your answer: ${userAnswer || &apos;Not answered&apos;} | Correct answer: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Show the results
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Score: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Excellent! You have mastered the basic concepts!&apos; :
              scorePercentage &gt;= 60 ? &apos;👍 Pretty good! Review a few concepts.&apos; :
              scorePercentage &gt;= 40 ? &apos;📚 You need more review of convex optimization.&apos; : &apos;💪 Reread the theory and try again!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Restart the exercise
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide the results and show the navigation again
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Clear all selections
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>01-04 Brief history of convex optimization</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_04_brief_history_of_convex_optimization/"/>
   <updated>2021-01-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_04_brief_history_of_convex_optimization</id>
   <content type="html">&lt;p&gt;In 1947, George Dantzig faced an Air Force logistics planning problem so large that hand calculation was hopeless; his Simplex algorithm turned linear programming into an industrial revolution. Nearly forty years later, Narendra Karmarkar shocked the field by cutting straight through the &lt;em&gt;interior&lt;/em&gt; of the feasible polytope instead of walking along its boundary edges, launching the interior-point era—and today, billion-variable machine learning models have sparked a third renaissance in first-order and stochastic methods.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-historical-eras-of-convex-optimization&quot;&gt;Key ideas: Four Historical Eras of Convex Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Theoretical Foundations (1900–1970):&lt;/strong&gt; Minkowski, Fenchel, von Neumann, Kuhn, Tucker, and Rockafellar established separating hyperplanes, conjugate duality, and KKT optimality conditions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Simplex Breakthrough (1947–1970s):&lt;/strong&gt; Dantzig’s Simplex method solved industrial LPs by pivoting between extreme vertices—blazingly fast in practice despite worst-case exponential vertex counts.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polynomial-Time &amp;amp; Interior-Point Revolution (1979–1994):&lt;/strong&gt; Khachiyan’s ellipsoid method proved LP is in P, Karmarkar’s projective method made interior-point solvers practical, and Nesterov &amp;amp; Nemirovski unified LP, QP, SOCP, and SDP via self-concordant barriers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Large-Scale First-Order Era (2000s–Present):&lt;/strong&gt; Accelerated gradients, proximal splitting, ADMM, and SGD traded interior-point’s \(O(n^3)\) linear algebra for cheap \(O(n)\) iterations capable of training modern AI systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-simplex-boundary-walk-vs-interior-point-philosophy&quot;&gt;Worked example: Simplex Boundary Walk vs. Interior-Point Philosophy&lt;/h3&gt;

&lt;p&gt;Consider the 2D linear program:
\(\min_{x_1, x_2} \; -x_1 - 2x_2 \quad \text{s.t.} \quad x_1 \ge 0,\; x_2 \ge 0,\; x_1 + x_2 \le 4,\; x_2 \le 3.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Simplex path (walking along boundary vertices):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Start at vertex \(v_0 = (0, 0)\): objective \(= 0\).&lt;/li&gt;
      &lt;li&gt;Pivot along \(x_2\) (steepest negative cost \(-2\)) until hitting \(x_2 = 3\) at vertex \(v_1 = (0, 3)\): objective \(= -6\).&lt;/li&gt;
      &lt;li&gt;Pivot along \(x_1\) until hitting \(x_1 + x_2 = 4\) at vertex \(v_2 = (1, 3)\): objective \(= -1 - 6 = -7\).&lt;/li&gt;
      &lt;li&gt;Check remaining vertex \((4, 0)\) (objective \(-4 &amp;gt; -7\)). Thus \(v_2 = (1, 3)\) is optimal with \(p^* = -7\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior-point contrast (central path):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Instead of hugging boundary edges, an interior-point method starts strictly inside the polygon—say at \((1, 1)\) where all four slacks are strictly positive (\(1, 1, 2, 2 &amp;gt; 0\))—and minimizes \(-x_1 - 2x_2 - \mu[\ln x_1 + \ln x_2 + \ln(4 - x_1 - x_2) + \ln(3 - x_2)]\) as \(\mu \to 0^+\), curving smoothly through the interior directly into \((1, 3)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;lịch-sử-phát-triển-của-tối-ưu-hóa-lồi&quot;&gt;Lịch sử phát triển của Tối ưu hóa Lồi&lt;/h1&gt;

&lt;p&gt;Tối ưu hóa lồi có một lịch sử phát triển phong phú, từ những nền tảng lý thuyết đầu tiên đến các ứng dụng hiện đại trong công nghệ và khoa học. Hãy cùng khám phá hành trình này qua các giai đoạn quan trọng.&lt;/p&gt;

&lt;h2 id=&quot;-tổng-quan-timeline&quot;&gt;🎯 Tổng quan Timeline&lt;/h2&gt;

&lt;div class=&quot;timeline-container&quot;&gt;
  &lt;div class=&quot;timeline-item&quot;&gt;
    &lt;div class=&quot;timeline-year&quot;&gt;1900-1970&lt;/div&gt;
    &lt;div class=&quot;timeline-content&quot;&gt;Phát triển nền tảng lý thuyết&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;timeline-item&quot;&gt;
    &lt;div class=&quot;timeline-year&quot;&gt;1947-1990&lt;/div&gt;
    &lt;div class=&quot;timeline-content&quot;&gt;Các thuật toán đột phá&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;timeline-item&quot;&gt;
    &lt;div class=&quot;timeline-year&quot;&gt;1990-nay&lt;/div&gt;
    &lt;div class=&quot;timeline-content&quot;&gt;Bùng nổ ứng dụng&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;-giai-đoạn-1-nền-tảng-lý-thuyết-1900-1970&quot;&gt;📚 Giai đoạn 1: Nền tảng Lý thuyết (1900-1970)&lt;/h2&gt;

&lt;h3 id=&quot;những-người-tiên-phong&quot;&gt;Những người tiên phong&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hermann Minkowski (1864-1909)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Đặt nền móng cho hình học lồi với khái niệm “tập lồi”&lt;/li&gt;
  &lt;li&gt;Phát triển lý thuyết về các đa diện lồi&lt;/li&gt;
  &lt;li&gt;Ảnh hưởng: Tạo ra ngôn ngữ toán học cơ bản cho tối ưu hóa lồi&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Leonid Kantorovich (1912-1986)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Phát triển lý thuyết lập trình tuyến tính vào những năm 1930&lt;/li&gt;
  &lt;li&gt;Giải quyết bài toán phân bổ tài nguyên tối ưu&lt;/li&gt;
  &lt;li&gt;Đóng góp: Chứng minh tính khả thi của việc tối ưu hóa trong kinh tế&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;John von Neumann (1903-1957)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Phát triển lý thuyết trò chơi và mối liên hệ với tối ưu hóa&lt;/li&gt;
  &lt;li&gt;Đưa ra định lý minimax cơ bản&lt;/li&gt;
  &lt;li&gt;Ảnh hưởng: Kết nối tối ưu hóa với lý thuyết quyết định&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;các-khái-niệm-nền-tảng-được-hình-thành&quot;&gt;Các khái niệm nền tảng được hình thành:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tập lồi và hàm lồi&lt;/strong&gt;: Định nghĩa chính xác và tính chất cơ bản&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện tối ưu&lt;/strong&gt;: Phát triển các điều kiện cần và đủ&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duality theory&lt;/strong&gt;: Khái niệm về bài toán đối ngẫu&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;️-giai-đoạn-2-cách-mạng-thuật-toán-1947-1990&quot;&gt;⚙️ Giai đoạn 2: Cách mạng Thuật toán (1947-1990)&lt;/h2&gt;

&lt;h3 id=&quot;1947-thuật-toán-simplex---bước-ngoặt-lịch-sử&quot;&gt;1947: Thuật toán Simplex - Bước ngoặt lịch sử&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;George Dantzig&lt;/strong&gt; đã tạo ra cuộc cách mạng với thuật toán Simplex:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Ý tưởng cốt lõi: Di chuyển dọc theo các cạnh của đa diện khả thi
để tìm điểm tối ưu tại một đỉnh.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Tại sao quan trọng?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Lần đầu tiên có thuật toán thực tế để giải bài toán lập trình tuyến tính&lt;/li&gt;
  &lt;li&gt;Mở ra khả năng ứng dụng trong logistics, sản xuất, quân sự&lt;/li&gt;
  &lt;li&gt;Hiệu quả cao trong thực tế dù có độ phức tạp tệ nhất là exponential&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;1960s-phương-pháp-điểm-trong-đầu-tiên&quot;&gt;1960s: Phương pháp Điểm trong đầu tiên&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Fiacco &amp;amp; McCormick&lt;/strong&gt; phát triển:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Barrier methods cho bài toán có ràng buộc bất đẳng thức&lt;/li&gt;
  &lt;li&gt;Ý tưởng: Thêm hàm penalty để “đẩy” nghiệm vào bên trong miền khả thi&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dikin&lt;/strong&gt; đóng góp:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Affine scaling method&lt;/li&gt;
  &lt;li&gt;Cải thiện hướng tiếp cận của barrier methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;1970s-phương-pháp-ellipsoid-và-subgradient&quot;&gt;1970s: Phương pháp Ellipsoid và Subgradient&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Shor, Nemirovski, Yudin&lt;/strong&gt; phát triển:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ellipsoid method&lt;/strong&gt;: Thuật toán đa thức đầu tiên cho LP&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Subgradient methods&lt;/strong&gt;: Xử lý hàm không khả vi&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa lý thuyết:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Chứng minh LP thuộc lớp P (polynomial time)&lt;/li&gt;
  &lt;li&gt;Mở rộng khả năng giải các bài toán không trơn&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;1984-đột-phá-của-karmarkar&quot;&gt;1984: Đột phá của Karmarkar&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Narendra Karmarkar&lt;/strong&gt; tạo ra cuộc cách mạng thứ hai:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Thuật toán interior-point với độ phức tạp \(O(n^{3.5}L)\)&lt;/li&gt;
  &lt;li&gt;Hiệu quả thực tế cao hơn simplex cho bài toán lớn&lt;/li&gt;
  &lt;li&gt;Khởi đầu cho kỷ nguyên interior-point methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;late-1980s-1990s-tổng-quát-hóa&quot;&gt;Late 1980s-1990s: Tổng quát hóa&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Nesterov &amp;amp; Nemirovski (1994)&lt;/strong&gt; mở rộng:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Interior-point methods cho tối ưu lồi phi tuyến&lt;/li&gt;
  &lt;li&gt;Self-concordant functions&lt;/li&gt;
  &lt;li&gt;Polynomial-time algorithms cho broader class&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-giai-đoạn-3-bùng-nổ-ứng-dụng-1990-nay&quot;&gt;🚀 Giai đoạn 3: Bùng nổ Ứng dụng (1990-nay)&lt;/h2&gt;

&lt;h3 id=&quot;trước-1990-giới-hạn-trong-operations-research&quot;&gt;Trước 1990: Giới hạn trong Operations Research&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Các ứng dụng chính:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Transportation problems&lt;/strong&gt;: Tối ưu hóa vận chuyển hàng hóa&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Production planning&lt;/strong&gt;: Lập kế hoạch sản xuất&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Resource allocation&lt;/strong&gt;: Phân bổ tài nguyên trong doanh nghiệp&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Military logistics&lt;/strong&gt;: Ứng dụng trong quân sự (WWII và Cold War)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tại sao giới hạn?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Máy tính chưa đủ mạnh&lt;/li&gt;
  &lt;li&gt;Thiếu software tools&lt;/li&gt;
  &lt;li&gt;Chưa nhận thức được tiềm năng trong engineering&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;từ-1990-cách-mạng-ứng-dụng&quot;&gt;Từ 1990: Cách mạng Ứng dụng&lt;/h3&gt;

&lt;h4 id=&quot;️-control-systems-hệ-thống-điều-khiển&quot;&gt;🎛️ Control Systems (Hệ thống Điều khiển)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Model Predictive Control (MPC)&lt;/strong&gt;: Điều khiển dự báo&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust control&lt;/strong&gt;: Điều khiển bền vững&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ&lt;/strong&gt;: Điều khiển nhiệt độ trong nhà máy, autopilot máy bay&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;-signal-processing-xử-lý-tín-hiệu&quot;&gt;📡 Signal Processing (Xử lý Tín hiệu)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Compressed sensing&lt;/strong&gt;: Khôi phục tín hiệu từ ít mẫu&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Image denoising&lt;/strong&gt;: Khử nhiễu ảnh&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ&lt;/strong&gt;: MRI imaging, radar processing&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;-communications-truyền-thông&quot;&gt;📱 Communications (Truyền thông)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Beamforming&lt;/strong&gt;: Định hướng sóng trong antenna arrays&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Power allocation&lt;/strong&gt;: Phân bổ công suất trong mạng wireless&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ&lt;/strong&gt;: 5G networks, satellite communications&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;-circuit-design-thiết-kế-mạch&quot;&gt;💻 Circuit Design (Thiết kế Mạch)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gate sizing&lt;/strong&gt;: Tối ưu kích thước transistor&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Power optimization&lt;/strong&gt;: Tối ưu tiêu thụ năng lượng&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ&lt;/strong&gt;: CPU design, mobile chip optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-các-lớp-bài-toán-mới&quot;&gt;🆕 Các lớp bài toán mới&lt;/h3&gt;

&lt;h4 id=&quot;semidefinite-programming-sdp&quot;&gt;Semidefinite Programming (SDP)&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Tối ưu hóa trên ma trận bán xác định dương
Ứng dụng: Relaxation của bài toán combinatorial
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;second-order-cone-programming-socp&quot;&gt;Second-Order Cone Programming (SOCP)&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Tối ưu hóa với ràng buộc hình nón bậc hai
Ứng dụng: Robust optimization, portfolio optimization
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;robust-optimization&quot;&gt;Robust Optimization&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Tối ưu hóa với uncertainty trong dữ liệu
Ứng dụng: Finance, supply chain management
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;-xu-hướng-hiện-tại-và-tương-lai&quot;&gt;🔮 Xu hướng Hiện tại và Tương lai&lt;/h2&gt;

&lt;h3 id=&quot;machine-learning-integration&quot;&gt;Machine Learning Integration&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Convex relaxations&lt;/strong&gt; của neural networks&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimization trong training&lt;/strong&gt;: Adam, RMSprop&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization&lt;/strong&gt;: L1, L2 penalties&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;big-data-applications&quot;&gt;Big Data Applications&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Distributed optimization&lt;/strong&gt;: Xử lý dữ liệu lớn&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Online algorithms&lt;/strong&gt;: Học trực tuyến&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Streaming optimization&lt;/strong&gt;: Tối ưu real-time&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;quantum-computing&quot;&gt;Quantum Computing&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quantum convex optimization&lt;/strong&gt;: Thuật toán lượng tử&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Variational quantum algorithms&lt;/strong&gt;: QAOA, VQE&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;-bài-học-từ-lịch-sử&quot;&gt;💡 Bài học từ Lịch sử&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết dẫn đường cho thực hành&lt;/strong&gt;: Nền tảng toán học vững chắc là cần thiết&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Công nghệ thúc đẩy ứng dụng&lt;/strong&gt;: Máy tính mạnh mở ra khả năng mới&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interdisciplinary collaboration&lt;/strong&gt;: Sự kết hợp giữa các lĩnh vực tạo ra đột phá&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical needs drive innovation&lt;/strong&gt;: Nhu cầu thực tế thúc đẩy phát triển thuật toán&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;div class=&quot;info-box&quot;&gt;
&lt;h4&gt;🎯 Takeaway chính&lt;/h4&gt;
&lt;p&gt;Tối ưu hóa lồi đã phát triển từ một lĩnh vực toán học thuần túy thành công cụ không thể thiếu trong công nghệ hiện đại. Sự kết hợp giữa lý thuyết vững chắc và thuật toán hiệu quả đã tạo ra những ứng dụng đột phá trong mọi lĩnh vực của cuộc sống.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;-khám-phá-tương-tác&quot;&gt;🎮 Khám phá Tương tác&lt;/h2&gt;

&lt;h3 id=&quot;simplex-algorithm-visualization&quot;&gt;Simplex Algorithm Visualization&lt;/h3&gt;

&lt;div id=&quot;simplex-demo&quot;&gt;
  &lt;h4&gt;Minh họa Thuật toán Simplex&lt;/h4&gt;
  &lt;p&gt;Thử nghiệm với bài toán lập trình tuyến tính đơn giản:&lt;/p&gt;
  
  &lt;div class=&quot;problem-setup&quot;&gt;
    &lt;p&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; Maximize \\(c_1x_1 + c_2x_2\\)&lt;/p&gt;
    &lt;p&gt;&lt;strong&gt;Subject to:&lt;/strong&gt; \\(x_1, x_2 \geq 0\\) và các ràng buộc tuyến tính&lt;/p&gt;
    
    &lt;div class=&quot;controls&quot;&gt;
      &lt;label&gt;c₁: &lt;input type=&quot;range&quot; id=&quot;c1&quot; min=&quot;-5&quot; max=&quot;5&quot; value=&quot;3&quot; step=&quot;0.1&quot; /&gt;&lt;/label&gt;
      &lt;span id=&quot;c1-value&quot;&gt;3&lt;/span&gt;&lt;br /&gt;
      &lt;label&gt;c₂: &lt;input type=&quot;range&quot; id=&quot;c2&quot; min=&quot;-5&quot; max=&quot;5&quot; value=&quot;2&quot; step=&quot;0.1&quot; /&gt;&lt;/label&gt;
      &lt;span id=&quot;c2-value&quot;&gt;2&lt;/span&gt;&lt;br /&gt;
      &lt;button onclick=&quot;runSimplex()&quot;&gt;Chạy Simplex&lt;/button&gt;
      &lt;button onclick=&quot;resetDemo()&quot;&gt;Reset&lt;/button&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;canvas id=&quot;simplex-canvas&quot; width=&quot;400&quot; height=&quot;300&quot;&gt;&lt;/canvas&gt;
  &lt;div id=&quot;simplex-steps&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;timeline-explorer&quot;&gt;Timeline Explorer&lt;/h3&gt;

&lt;div id=&quot;timeline-explorer&quot;&gt;
  &lt;h4&gt;Khám phá Timeline Tương tác&lt;/h4&gt;
  &lt;div class=&quot;year-slider&quot;&gt;
    &lt;label&gt;Năm: &lt;input type=&quot;range&quot; id=&quot;year-slider&quot; min=&quot;1900&quot; max=&quot;2024&quot; value=&quot;1947&quot; step=&quot;1&quot; /&gt;&lt;/label&gt;
    &lt;span id=&quot;current-year&quot;&gt;1947&lt;/span&gt;
  &lt;/div&gt;
  
  &lt;div id=&quot;year-info&quot;&gt;
    &lt;h5 id=&quot;event-title&quot;&gt;1947: Thuật toán Simplex&lt;/h5&gt;
    &lt;p id=&quot;event-description&quot;&gt;George Dantzig phát triển thuật toán Simplex, mở đầu kỷ nguyên tối ưu hóa thực tế.&lt;/p&gt;
    &lt;div id=&quot;event-impact&quot;&gt;
      &lt;strong&gt;Tác động:&lt;/strong&gt; &lt;span id=&quot;impact-text&quot;&gt;Cách mạng trong operations research&lt;/span&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;ứng-dụng-hiện-đại&quot;&gt;Ứng dụng Hiện đại&lt;/h3&gt;

&lt;div id=&quot;applications-demo&quot;&gt;
  &lt;h4&gt;Ứng dụng trong Cuộc sống&lt;/h4&gt;
  &lt;div class=&quot;app-selector&quot;&gt;
    &lt;button onclick=&quot;showApplication(&apos;portfolio&apos;)&quot; class=&quot;app-btn&quot;&gt;Portfolio Optimization&lt;/button&gt;
    &lt;button onclick=&quot;showApplication(&apos;supply-chain&apos;)&quot; class=&quot;app-btn&quot;&gt;Supply Chain&lt;/button&gt;
    &lt;button onclick=&quot;showApplication(&apos;machine-learning&apos;)&quot; class=&quot;app-btn&quot;&gt;Machine Learning&lt;/button&gt;
    &lt;button onclick=&quot;showApplication(&apos;signal-processing&apos;)&quot; class=&quot;app-btn&quot;&gt;Signal Processing&lt;/button&gt;
  &lt;/div&gt;
  
  &lt;div id=&quot;app-content&quot;&gt;
    &lt;div class=&quot;app-example&quot; id=&quot;portfolio&quot;&gt;
      &lt;h5&gt;📈 Portfolio Optimization&lt;/h5&gt;
      &lt;p&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; Phân bổ vốn đầu tư để tối đa hóa lợi nhuận và giảm thiểu rủi ro&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Công thức:&lt;/strong&gt; \\(\min \frac{1}{2}w^T\Sigma w - \mu^T w\\)&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt; Quỹ đầu tư, ngân hàng, bảo hiểm&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
// Simplex Algorithm Demo
function runSimplex() {
  const canvas = document.getElementById(&apos;simplex-canvas&apos;);
  const ctx = canvas.getContext(&apos;2d&apos;);
  const c1 = parseFloat(document.getElementById(&apos;c1&apos;).value);
  const c2 = parseFloat(document.getElementById(&apos;c2&apos;).value);
  
  // Clear canvas
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  
  // Draw feasible region (simple example)
  ctx.fillStyle = &apos;rgba(0, 122, 204, 0.2)&apos;;
  ctx.beginPath();
  ctx.moveTo(50, 250);
  ctx.lineTo(200, 250);
  ctx.lineTo(200, 100);
  ctx.lineTo(100, 50);
  ctx.lineTo(50, 100);
  ctx.closePath();
  ctx.fill();
  
  // Draw objective function direction
  ctx.strokeStyle = &apos;#ff6b35&apos;;
  ctx.lineWidth = 3;
  ctx.beginPath();
  ctx.moveTo(125, 175);
  ctx.lineTo(125 + c1*20, 175 - c2*20);
  ctx.stroke();
  
  // Add labels
  ctx.fillStyle = &apos;#333&apos;;
  ctx.font = &apos;14px Arial&apos;;
  ctx.fillText(&apos;Feasible Region&apos;, 60, 200);
  ctx.fillText(`Objective: ${c1.toFixed(1)}x₁ + ${c2.toFixed(1)}x₂`, 220, 50);
  
  // Show steps
  document.getElementById(&apos;simplex-steps&apos;).innerHTML = `
    &lt;h5&gt;Các bước Simplex:&lt;/h5&gt;
    &lt;ol&gt;
      &lt;li&gt;Bắt đầu tại đỉnh (0,0)&lt;/li&gt;
      &lt;li&gt;Kiểm tra hướng cải thiện: (${c1.toFixed(1)}, ${c2.toFixed(1)})&lt;/li&gt;
      &lt;li&gt;Di chuyển dọc theo cạnh có gradient tốt nhất&lt;/li&gt;
      &lt;li&gt;Dừng khi không thể cải thiện thêm&lt;/li&gt;
    &lt;/ol&gt;
  `;
}

function resetDemo() {
  document.getElementById(&apos;c1&apos;).value = 3;
  document.getElementById(&apos;c2&apos;).value = 2;
  document.getElementById(&apos;c1-value&apos;).textContent = &apos;3&apos;;
  document.getElementById(&apos;c2-value&apos;).textContent = &apos;2&apos;;
  document.getElementById(&apos;simplex-steps&apos;).innerHTML = &apos;&apos;;
  const canvas = document.getElementById(&apos;simplex-canvas&apos;);
  const ctx = canvas.getContext(&apos;2d&apos;);
  ctx.clearRect(0, 0, canvas.width, canvas.height);
}

// Timeline Explorer
const timelineEvents = {
  1900: {title: &quot;1900: Nền tảng Hình học&quot;, desc: &quot;Minkowski phát triển lý thuyết tập lồi&quot;, impact: &quot;Tạo nền tảng toán học&quot;},
  1930: {title: &quot;1930: Kantorovich&quot;, desc: &quot;Lý thuyết lập trình tuyến tính đầu tiên&quot;, impact: &quot;Ứng dụng trong kinh tế&quot;},
  1947: {title: &quot;1947: Thuật toán Simplex&quot;, desc: &quot;Dantzig tạo ra thuật toán thực tế đầu tiên&quot;, impact: &quot;Cách mạng operations research&quot;},
  1960: {title: &quot;1960s: Interior Point&quot;, desc: &quot;Fiacco &amp; McCormick phát triển barrier methods&quot;, impact: &quot;Mở rộng khả năng giải bài toán&quot;},
  1984: {title: &quot;1984: Karmarkar&quot;, desc: &quot;Interior-point polynomial-time algorithm&quot;, impact: &quot;Đột phá về độ phức tạp&quot;},
  1994: {title: &quot;1994: Nesterov &amp; Nemirovski&quot;, desc: &quot;Tổng quát hóa cho convex optimization&quot;, impact: &quot;Nền tảng cho ứng dụng hiện đại&quot;},
  2010: {title: &quot;2010s: Machine Learning&quot;, desc: &quot;Tích hợp với AI và Big Data&quot;, impact: &quot;Ứng dụng rộng rãi trong công nghệ&quot;},
  2024: {title: &quot;2024: Quantum Computing&quot;, desc: &quot;Thuật toán tối ưu lượng tử&quot;, impact: &quot;Tương lai của tính toán&quot;}
};

function updateTimeline() {
  const year = parseInt(document.getElementById(&apos;year-slider&apos;).value);
  document.getElementById(&apos;current-year&apos;).textContent = year;
  
  // Find closest event
  let closestYear = 1900;
  for (let eventYear in timelineEvents) {
    if (parseInt(eventYear) &lt;= year) {
      closestYear = parseInt(eventYear);
    }
  }
  
  const event = timelineEvents[closestYear];
  document.getElementById(&apos;event-title&apos;).textContent = event.title;
  document.getElementById(&apos;event-description&apos;).textContent = event.desc;
  document.getElementById(&apos;impact-text&apos;).textContent = event.impact;
}

// Applications Demo
const applications = {
  portfolio: {
    title: &quot;📈 Portfolio Optimization&quot;,
    problem: &quot;Phân bổ vốn đầu tư để tối đa hóa lợi nhuận và giảm thiểu rủi ro&quot;,
    formula: &quot;\\min \\frac{1}{2}w^T\\Sigma w - \\mu^T w&quot;,
    usage: &quot;Quỹ đầu tư, ngân hàng, bảo hiểm&quot;
  },
  &quot;supply-chain&quot;: {
    title: &quot;🚚 Supply Chain Optimization&quot;,
    problem: &quot;Tối ưu hóa logistics và phân phối hàng hóa&quot;,
    formula: &quot;\\min \\sum_{i,j} c_{ij}x_{ij}&quot;,
    usage: &quot;Amazon, Walmart, FedEx&quot;
  },
  &quot;machine-learning&quot;: {
    title: &quot;🤖 Machine Learning&quot;,
    problem: &quot;Training neural networks và feature selection&quot;,
    formula: &quot;\\min \\frac{1}{2}||Xw - y||^2 + \\lambda||w||_1&quot;,
    usage: &quot;Google, Facebook, Tesla autopilot&quot;
  },
  &quot;signal-processing&quot;: {
    title: &quot;📡 Signal Processing&quot;,
    problem: &quot;Khôi phục tín hiệu từ dữ liệu nhiễu hoặc không đầy đủ&quot;,
    formula: &quot;\\min ||x||_1 \\text{ s.t. } ||Ax - b||_2 \\leq \\epsilon&quot;,
    usage: &quot;MRI imaging, radar, 5G communications&quot;
  }
};

function showApplication(appKey) {
  const app = applications[appKey];
  document.getElementById(&apos;app-content&apos;).innerHTML = `
    &lt;div class=&quot;app-example&quot;&gt;
      &lt;h5&gt;${app.title}&lt;/h5&gt;
      &lt;p&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; ${app.problem}&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Công thức:&lt;/strong&gt; \\(${app.formula}\\)&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt; ${app.usage}&lt;/p&gt;
    &lt;/div&gt;
  `;
  
  // Re-render MathJax
  if (window.MathJax) {
    MathJax.typesetPromise([document.getElementById(&apos;app-content&apos;)]);
  }
}

// Event listeners
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
  // Slider updates
  document.getElementById(&apos;c1&apos;).addEventListener(&apos;input&apos;, function() {
    document.getElementById(&apos;c1-value&apos;).textContent = this.value;
  });
  
  document.getElementById(&apos;c2&apos;).addEventListener(&apos;input&apos;, function() {
    document.getElementById(&apos;c2-value&apos;).textContent = this.value;
  });
  
  document.getElementById(&apos;year-slider&apos;).addEventListener(&apos;input&apos;, updateTimeline);
  
  // Initialize
  updateTimeline();
  showApplication(&apos;portfolio&apos;);
});
&lt;/script&gt;

&lt;style&gt;
.timeline-container {
  position: relative;
  margin: 20px 0;
}

.timeline-item {
  display: flex;
  margin: 10px 0;
  padding: 10px;
  border-left: 3px solid #007acc;
  background: #f8f9fa;
}

.timeline-year {
  font-weight: bold;
  color: #007acc;
  min-width: 100px;
}

.timeline-content {
  margin-left: 20px;
}

.info-box {
  background: #e3f2fd;
  border: 1px solid #2196f3;
  border-radius: 5px;
  padding: 15px;
  margin: 20px 0;
}

.info-box h4 {
  margin-top: 0;
  color: #1976d2;
}

/* Interactive Demo Styles */
#simplex-demo, #timeline-explorer, #applications-demo {
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  padding: 20px;
  margin: 20px 0;
}

.controls {
  margin: 15px 0;
}

.controls label {
  display: inline-block;
  margin: 5px 10px 5px 0;
  min-width: 40px;
}

.controls input[type=&quot;range&quot;] {
  width: 150px;
  margin: 0 10px;
}

.controls button {
  background: #007acc;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  margin: 5px;
}

.controls button:hover {
  background: #005a9e;
}

#simplex-canvas {
  border: 1px solid #ccc;
  margin: 10px 0;
  background: white;
}

.year-slider {
  margin: 15px 0;
}

.year-slider input[type=&quot;range&quot;] {
  width: 300px;
}

#year-info {
  background: white;
  padding: 15px;
  border-radius: 5px;
  border-left: 4px solid #007acc;
}

.app-selector {
  margin: 15px 0;
}

.app-btn {
  background: #28a745;
  color: white;
  border: none;
  padding: 10px 15px;
  border-radius: 5px;
  cursor: pointer;
  margin: 5px;
  font-size: 14px;
}

.app-btn:hover {
  background: #218838;
}

.app-example {
  background: white;
  padding: 15px;
  border-radius: 5px;
  border-left: 4px solid #28a745;
  margin-top: 15px;
}

.problem-setup {
  background: white;
  padding: 15px;
  border-radius: 5px;
  margin: 10px 0;
}

#simplex-steps {
  background: white;
  padding: 15px;
  border-radius: 5px;
  margin-top: 10px;
}

#simplex-steps ol {
  margin: 10px 0;
  padding-left: 20px;
}

#simplex-steps li {
  margin: 5px 0;
}
&lt;/style&gt;

</content>
 </entry>
 
 <entry>
   <title>01-03 Goals and Topics</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_03_goals_and_topics/"/>
   <updated>2021-01-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_03_goals_and_topics</id>
   <content type="html">&lt;p&gt;Knowing the definition of convexity is only the first mile; the real superpower of this course is &lt;em&gt;recognizing&lt;/em&gt; hidden convexity in applied problems and matching each problem structure to the right algorithm. A naive general-purpose solver might take 10,000 iterations on an image-denoising problem that a tailored ADMM or proximal splitting method solves to high accuracy in 20 iterations.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-three-pillars-of-mastering-convex-optimization&quot;&gt;Key ideas: The Three Pillars of Mastering Convex Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Recognition &amp;amp; Reformulation (Modeling):&lt;/strong&gt; Spotting when a seemingly nonconvex problem (such as fractional programming or \(\ell_1\)-regularized regression) can be transformed into an equivalent LP, QP, SOCP, or SDP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Duality &amp;amp; Optimality Theory:&lt;/strong&gt; Using Lagrange duality and KKT conditions to derive analytical optimality certificates, sensitivity analyses, and stopping criteria (duality gaps).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm–Structure Matching:&lt;/strong&gt; Selecting among first-order methods (gradient, proximal, coordinate descent), operator splitting (ADMM), and second-order interior-point methods based on dimension \(n\), smoothness, and desired accuracy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical Trade-Offs:&lt;/strong&gt; Balancing per-iteration cost (cheap matrix-vector products vs. expensive linear solves) against iteration count and wall-clock time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-1d-total-variation-tv-denoising-by-hand&quot;&gt;Worked example: 1D Total Variation (TV) Denoising by Hand&lt;/h3&gt;

&lt;p&gt;Consider a 3-pixel noisy signal \(y = (0, 0, 3)^T\) with regularization weight \(\lambda = 1\):
\(\min_{x \in \mathbb{R}^3} \; F(x) = \frac{1}{2}\left[(x_1 - 0)^2 + (x_2 - 0)^2 + (x_3 - 3)^2\right] + |x_2 - x_1| + |x_3 - x_2|.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test two extremes to build intuition:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;No smoothing (\(x = y = (0, 0, 3)^T\)): \(F(y) = 0 + 0 + 3 = 3.0\).&lt;/li&gt;
      &lt;li&gt;Total flattening (\(x = (1, 1, 1)^T\)): \(F(1,1,1) = \frac{1}{2}(1 + 1 + 4) + 0 = 3.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve for a piecewise-constant jump \(x_1 = x_2 = a &amp;lt; b = x_3\):&lt;/strong&gt;
With \(x_1 = x_2 = a\) and \(x_3 = b &amp;gt; a\), the TV penalty simplifies to \(b - a\), so
\(F(a, a, b) = a^2 + \frac{1}{2}(b - 3)^2 + (b - a).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Set partial derivatives to zero:&lt;/strong&gt;
\(\frac{\partial F}{\partial a} = 2a - 1 = 0 \implies a^* = 0.5, \qquad \frac{\partial F}{\partial b} = (b - 3) + 1 = 0 \implies b^* = 2.0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify strict improvement:&lt;/strong&gt; At \(x^* = (0.5, 0.5, 2.0)^T\), \(a^* &amp;lt; b^*\) holds and
\(F(x^*) = \frac{1}{2}(0.25 + 0.25 + 1.0) + (0 + 1.5) = 0.75 + 1.5 = 2.25 &amp;lt; 3.0.\)
Notice how TV denoising pulls the outlier down from \(3\) to \(2\) while preserving a crisp jump edge instead of blurring the signal linearly.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;goals&quot;&gt;Goals&lt;/h2&gt;
&lt;p&gt;The goal of this course is to develop the following abilities:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Recognize when a given problem is a convex optimization problem&lt;/li&gt;
  &lt;li&gt;Formulate a given situation as a convex optimization problem&lt;/li&gt;
  &lt;li&gt;Select the most appropriate algorithm to solve a defined convex optimization problem&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;topics&quot;&gt;Topics&lt;/h2&gt;
&lt;p&gt;To achieve these goals, the following topics will be covered:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Convex sets, functions, optimization problems&lt;/li&gt;
  &lt;li&gt;Examples and applications&lt;/li&gt;
  &lt;li&gt;Algorithms (gradient, proximal, Newton, interior-point, ADMM, …)&lt;/li&gt;
  &lt;li&gt;2026 modern track on this site: SGD / Adam / AdamW (Ch.26), autodiff (Ch.27), nonconvex landscapes (Ch.28), data-parallel SGD and FedAvg (Ch.29)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In particular, the main focus will be on algorithms.&lt;/p&gt;

&lt;h2 id=&quot;algorithms&quot;&gt;Algorithms&lt;/h2&gt;
&lt;p&gt;There are many different methods for solving optimization problems. The performance of each method depends on the properties of the problem being solved. To choose the most efficient algorithm, a deep understanding of both the problem and the algorithms is required. Let’s look at an example: total variation denoising.&lt;/p&gt;

&lt;h3 id=&quot;example-total-variation-denoising&quot;&gt;Example: Total variation denoising&lt;/h3&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/2d_fused_lasso.png&quot; alt=&quot;2D Fused Lasso&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Total Variation Denoising [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;Suppose you receive a noisy image (middle), and you want to remove the noise to obtain a solution (right) close to the true image (left). If each pixel value is \(y_i, i = 1, ..., n\), this problem can be formulated as the following optimization problem, commonly called the 2D fused lasso or 2D total variation denoising problem:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{\theta} \frac{1}{2} \sum_{i=1}^n (y_i - \theta_{i})^2 + \lambda \sum_{(i,j) \in E} \vert \theta_i - \theta_j \vert\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;E: the set of edges between all neighboring \(\theta\)&lt;/li&gt;
  &lt;li&gt;\(\frac{1}{2} \sum_{i=1}^n (y_i - \theta_{i})^2\): Least squares loss. Forces \(\theta\) to be close to \(y\)&lt;/li&gt;
  &lt;li&gt;\(\sum_{(i,j) \in E} \vert \theta_i - \theta_j \vert\): Total variation smoothing. Used when the change between neighboring pixels is not large (piecewise constant). Choosing the right smoothing method requires careful consideration of the problem’s characteristics. (For more details on total variation smoothing, see Chapter 6.1.2 and 6.3 in Reference 1.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The convex optimization problem above can be solved using the &lt;a href=&quot;http://stanford.edu/~boyd/admm.html&quot;&gt;Specialized ADMM&lt;/a&gt; algorithm, which yields the solution on the right after 20 iterations.&lt;/p&gt;

&lt;h3 id=&quot;specialized-admm-20-iterations&quot;&gt;Specialized ADMM, 20 iterations&lt;/h3&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/result1.png&quot; alt=&quot;Result1&quot; width=&quot;50%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Specialized ADMM Result [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;proximal-gradient-descent-1000-iterations&quot;&gt;Proximal gradient descent, 1000 iterations&lt;/h3&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/result2.png&quot; alt=&quot;Result2&quot; width=&quot;50%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig3] Proximal Gradient Descent Result [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;coordinate-descent-10k-cycles&quot;&gt;Coordinate descent, 10K cycles&lt;/h3&gt;
&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/result3.png&quot; alt=&quot;Result3&quot; width=&quot;50%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig4] Coordinate Descent Result [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;As shown above, for the 2D fused lasso problem, Specialized ADMM performs best among the three methods. However, for other problems, the other two methods may outperform Specialized ADMM. In later chapters, we will analyze various algorithms and problems to learn how to select the most appropriate algorithm — including, after the classical spine, the 2026 modern-track chapters on this site.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>01-02 Convex optimization problem</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_02_convex_optimization_problem/"/>
   <updated>2021-01-28T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_02_convex_optimization_problem</id>
   <content type="html">&lt;p&gt;Most nonlinear optimization problems are treacherous: a solver can stop at a point that looks flat and locally optimal, yet a far better solution hides over the next ridge. Convex optimization eliminates that anxiety completely. When the objective and inequality constraints are convex and all equality constraints are affine, the geometry of the problem guarantees that &lt;em&gt;local optimality implies global optimality&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-what-makes-an-optimization-problem-convex&quot;&gt;Key ideas: What Makes an Optimization Problem Convex&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Convex Feasible Set:&lt;/strong&gt; Requires that for any two feasible solutions \(x, y\), the entire line segment \(\theta x + (1 - \theta)y\) (\(0 \le \theta \le 1\)) remains feasible—no holes, disconnected islands, or inward dents.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Objective &amp;amp; Inequality Constraints:&lt;/strong&gt; Both \(f_0(x)\) and every \(f_i(x) \le 0\) must satisfy Jensen’s inequality \(f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Affine Equality Constraints Only:&lt;/strong&gt; Equality constraints must be linear/affine (\(a_j^T x = b_j\)), because a nonlinear equality like \(x_1^2 + x_2^2 = 1\) (a hollow circle) is nonconvex even though \(x_1^2 + x_2^2\) is convex!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Global Optimality Theorem:&lt;/strong&gt; If \(x^*\) is locally optimal for a convex problem, any strictly better point \(y\) would pull the line segment toward \(x^*\) strictly downhill inside the neighborhood of \(x^*\)—a contradiction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-convexity-and-solving-analytically&quot;&gt;Worked example: Verifying Convexity and Solving Analytically&lt;/h3&gt;

&lt;p&gt;Consider:
\(\min_{x_1, x_2} \; f_0(x_1, x_2) = x_1^2 + 2x_2^2 \quad \text{s.t.} \quad x_1^2 + x_2^2 \le 10, \quad x_1 + x_2 = 3.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check the three convexity requirements:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Objective \(f_0\): Hessian \(\nabla^2 f_0 = \text{diag}(2, 4) \succ 0 \implies\) strictly convex.&lt;/li&gt;
      &lt;li&gt;Inequality \(f_1(x) = x_1^2 + x_2^2 - 10 \le 0\): Hessian \(\text{diag}(2, 2) \succ 0 \implies\) convex.&lt;/li&gt;
      &lt;li&gt;Equality \(h_1(x) = x_1 + x_2 - 3 = 0\): affine!
Hence this is a &lt;strong&gt;strictly convex optimization problem&lt;/strong&gt; with a unique global minimizer.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Eliminate the affine equality constraint:&lt;/strong&gt; Substitute \(x_2 = 3 - x_1\) into \(f_0\):
\(\phi(x_1) = x_1^2 + 2(3 - x_1)^2 = 3x_1^2 - 12x_1 + 18.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize \(\phi(x_1)\) and check the inequality:&lt;/strong&gt;
\(\phi&apos;(x_1) = 6x_1 - 12 = 0 \implies x_1^* = 2, \quad x_2^* = 3 - 2 = 1.\)
Verify the inequality: \((2)^2 + (1)^2 = 5 \le 10\) (strictly satisfied!). Thus \(x^* = (2, 1)^T\) is the unique global optimum with \(p^* = 2^2 + 2(1)^2 = 6\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A convex optimization problem is a type of optimization problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align*} 
&amp;amp;\min_{x\in D}\ &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp; g_i(x) \le 0,\ i = 1, ..., m \\
&amp;amp;&amp;amp;&amp;amp; h_j(x) = 0,\ j = 1,\ ..., r
\end{align*}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Convex Optimization Problem in standard form [3]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here, the objective function \(f\) and the inequality constraint functions \(g_i\) are convex, and the equality constraint functions \(h_j\) are affine. An affine function is a linear function plus a constant:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(h_j,\ j = 1, ..., r\) are affine: \(h_j(x) = a_{j}^T x + b_{j},\ j=1, ..., r\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What does it mean for a function to be convex? To understand this, we first need to understand convex sets.&lt;/p&gt;

&lt;h2 id=&quot;convex-sets&quot;&gt;Convex sets&lt;/h2&gt;
&lt;p&gt;A line segment connecting two points \(x_1\) and \(x_2\) is defined as:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x = \theta x_1 + (1 - \theta) x_2\) with \(0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Given a set, if the line segment between any two points \(x_1\) and \(x_2\) in the set is also contained in the set, we call it a convex set. In other words, a set \(C\) is convex if:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x_1, x_2 \in C\), \(0 \le \theta \le 1\)  \(\Rightarrow\) \(\theta x_1 + (1-\theta)x_2 \in C\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example, in the figure below, only the leftmost shape is a convex set.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/Convex_set.png&quot; alt=&quot;Convex Set&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] left: a convex set, mid &amp;amp; right: non-convex sets [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;convex-functions&quot;&gt;Convex functions&lt;/h2&gt;
&lt;p&gt;A convex function is defined as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f: \mathbb{R}^n \rightarrow \mathbb{R}\) is convex if \(dom(f)\) is a convex set and,&lt;/p&gt;

  &lt;p&gt;\(f(\theta x + (1 - \theta)y) \le \theta f(x) + (1-\theta)f(y)\) for all \(x, y \in dom(f),\ 0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Geometrically, this means that for any two points \((x, f(x))\) and \((y, f(y))\) on the graph of \(f\), the line segment connecting them lies above the graph between \(x\) and \(y\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/Convex_function.png&quot; alt=&quot;Convex Function&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Convex Function [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;relation-between-a-convex-set-and-a-convex-function&quot;&gt;Relation between a convex set and a convex function&lt;/h2&gt;
&lt;p&gt;There is a close relationship between convex functions and convex sets:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;A function \(f\) is convex if and only if its epigraph is a convex set.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What is an epigraph? ‘Epi’ means ‘above’, so the epigraph of \(f\) is the set of points above the graph of \(f\). Formally, the epigraph is defined as:&lt;/p&gt;

&lt;blockquote&gt;
\[\eqalign{
&amp;amp; \text{epigraph of } f: \mathbb{R}^n \rightarrow \mathbb{R}\\
&amp;amp; \text{epi } f = \{(x, t) \in \mathbb{R}^{n+1} \mid x \in \text{ dom } f, f(x) \le t\}
}\]
&lt;/blockquote&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter01/epigraph.png&quot; alt=&quot;Epigraph&quot; width=&quot;70%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig3] Epigraph [2]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;If \(f\) is a convex function, then \(\text{epi } f\) is always a convex set, and vice versa. This is a key property connecting the definitions of convex functions and convex sets.&lt;/p&gt;

&lt;h2 id=&quot;convex-and-concave-functions&quot;&gt;Convex and concave functions&lt;/h2&gt;

&lt;p&gt;A function \(f\) is concave if \(-f\) is convex. Equivalently, \(f\) is concave if:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(f(\theta x + (1 - \theta)y) \ge \theta f(x) + (1-\theta)f(y)\) for all \(x, y \in dom(f),\ 0 \le \theta \le 1\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Geometrically, this means that the line segment connecting any two points on the graph lies below the graph of the function. A concave function “curves downward” while a convex function “curves upward”.&lt;/p&gt;

&lt;p&gt;What about concave functions? Why do we emphasize convex functions so much, and seemingly “ignore” concave ones?&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;We “don’t care” about concave functions separately because they’re just the mirror image of convex ones. Always reformulate maximization of concave \(f\) as minimization of convex \(-f\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;nice-property-of-convex-optimization-problems&quot;&gt;Nice property of convex optimization problems&lt;/h2&gt;
&lt;p&gt;A local minimum of a convex function is always a global minimum. For convex optimization problems, solutions are generally easier to find than for non-convex problems, because convex functions have the following property:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;If \(f\) is convex and \(x\) is a locally optimal point (i.e., a local minimum), then \(x\) is also a globally optimal point.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s prove this by contradiction:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Proof by contradiction:&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Suppose for a convex function \(f\), \(x\) is a locally optimal point but not a globally optimal point. Let \(y\) be a feasible global optimal point, so for any positive \(\rho\), \(\|y - x\|_2 &amp;gt; \rho\) and \(f(y) &amp;lt; f(x)\). (Because \(x\) is locally optimal, if \(\|x - y\|_2 \le \rho\) then \(f(x) \le f(y)\), which contradicts \(y\) being globally optimal.)
Now, for \(\theta=\frac{\rho}{2\|y-x\|_2}\), let \(z = \theta y + (1 - \theta) x = x + \theta( y - x)\). Then:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;
      &lt;p&gt;\(z\) is a convex combination of two feasible points \(x, y\), so it is also feasible.&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;\(\|z - x\|_2 = \theta \|y - x\|_2 = \frac{\rho}{2} &amp;lt; \rho\).&lt;/p&gt;
    &lt;/li&gt;
    &lt;li&gt;
\[f(z) \le \theta f(y) + (1 - \theta) f(x) &amp;lt; \theta f(x) + (1 - \theta) f(x) = f(x)\]
    &lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Points 2 and 3 contradict the assumption that \(x\) is a locally optimal point, so by contradiction, any locally optimal point \(x\) is also globally optimal.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;convex-combination&quot;&gt;Convex combination&lt;/h2&gt;

&lt;p&gt;A convex combination of \(x_1, ..., x_k\) is defined as:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x = \theta_1 x_1 + \theta_2 x_2 + \cdots + \theta_k x_k\) with \(\theta_1 + \cdots + \theta_k = 1, \theta_i \ge 0\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If \(D\) is a convex set and \(x_1, x_2, ..., x_k \in D\), then \(x \in D\) as well.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>contents</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/home/link_to_how_to_contribute/"/>
   <updated>2021-01-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/home/link_to_how_to_contribute</id>
   <content type="html">
</content>
 </entry>
 
 <entry>
   <title>Initial Settings</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contribution/initial_settings/"/>
   <updated>2021-01-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contribution/initial_settings</id>
   <content type="html">&lt;p&gt;The contents of this repository are hosted as a &lt;a href=&quot;https://convex-optimization-for-all.github.io/&quot;&gt;Github Blog&lt;/a&gt; using Jekyll.
Therefore, to edit existing content or create new content, you must follow Jekyll’s directory structure and content writing conventions.
Additionally, you need to verify that changes are properly reflected in your local environment (your current computer) through a web browser.&lt;/p&gt;

&lt;p&gt;We have compiled environment setup instructions for those who are not familiar with GitHub or Jekyll.
If you have difficulties following the guide, please leave an &lt;a href=&quot;https://github.com/convex-optimization-for-all/convex-optimization-for-all.github.io/issues&quot;&gt;issue&lt;/a&gt; in the repository or contact us via the email below for assistance.&lt;/p&gt;

&lt;p&gt;(Kyeongmin Woo, wgm0601@gmail.com)&lt;/p&gt;

&lt;h2 id=&quot;1-git-installation&quot;&gt;1. Git Installation&lt;/h2&gt;

&lt;p&gt;All work management for this blog is performed through Git and GitHub. Please visit the website below to install Git.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://git-scm.com/downloads&quot;&gt;https://git-scm.com/downloads&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;2-downloading-the-repository&quot;&gt;2. Downloading the Repository&lt;/h2&gt;

&lt;p&gt;To modify the blog, enter the following command in the terminal to download the blog’s source code.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/convex-optimization-for-all/convex-optimization-for-all.github.io.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;3-local-hosting&quot;&gt;3. Local Hosting&lt;/h2&gt;

&lt;p&gt;Before applying changed or modified content to the blog, you must verify that the work has been performed as intended through local hosting.
If you merge work content that does not follow Jekyll’s required conventions into the repository, the blog hosted on the actual web may not function properly.
For local hosting setup, you can choose between two methods: using a virtual environment (Docker) (Option 1) or directly installing the Jekyll environment locally (Option 2).
After completing the local hosting setup and running the local server, you can check your blog content through the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.0.0.1:4000&lt;/code&gt; address in your web browser.&lt;/p&gt;

&lt;h3 id=&quot;3-1-option-1-docker-installation&quot;&gt;3-1. (Option 1) Docker Installation&lt;/h3&gt;

&lt;h3 id=&quot;a-docker-installation&quot;&gt;A. Docker Installation&lt;/h3&gt;

&lt;p&gt;Using Docker enables local hosting without direct environment installation on your local machine.
Please visit the website below to install Docker.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.docker.com/get-docker/&quot;&gt;https://docs.docker.com/get-docker/&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;b-local-hosting&quot;&gt;B. Local Hosting&lt;/h3&gt;

&lt;p&gt;Enter the following command in the terminal.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker-compose up
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-2-option-2-jekyll-environment-installation&quot;&gt;3-2. (Option 2) Jekyll Environment Installation&lt;/h3&gt;

&lt;h3 id=&quot;a-jekyll-and-ruby-package-installation&quot;&gt;A. Jekyll and Ruby Package Installation&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://jekyllrb.com/docs/installation/&quot;&gt;Installing Ruby&lt;/a&gt;: Jekyll is built with Ruby. Therefore, you need to install Ruby to use Jekyll.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://jekyllrb.com/docs/&quot;&gt;Installing Jekyll&lt;/a&gt;: Once Ruby is installed, enter the cloned repository and install Jekyll.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://jekyllrb.com/docs/&quot;&gt;Installing Bundle Gem&lt;/a&gt;: You need to additionally install Ruby packages required for hosting. Run the following command in the repository’s project directory.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;bundle &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;b-local-hosting-1&quot;&gt;B. Local Hosting&lt;/h3&gt;

&lt;p&gt;Enter the following command in the terminal.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If hosting doesn’t work, you can also try the following command.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ bundle exec jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If both commands don’t work, the Jekyll environment has not been properly installed.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>How to Contribute</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contribution/how_to_contribute/"/>
   <updated>2021-01-27T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contribution/how_to_contribute</id>
   <content type="html">&lt;hr /&gt;

&lt;h2 id=&quot;1-컨텐츠를-직접-수정하는-방법&quot;&gt;1. 컨텐츠를 직접 수정하는 방법&lt;/h2&gt;

&lt;h3 id=&quot;1-우선-local의-repository-directory로-들어갑니다-local-repository가-없다면-initial-settings를-참고하시기-바랍니다&quot;&gt;(1) 우선 Local의 Repository Directory로 들어갑니다. Local Repository가 없다면 &lt;a href=&quot;https://convex-optimization-for-all.github.io/contribution/2021/01/27/initial_settings/&quot;&gt;Initial Settings&lt;/a&gt;를 참고하시기 바랍니다.&lt;/h3&gt;

&lt;h3 id=&quot;2--remote-저장소와의-정보를-동기화합니다&quot;&gt;(2)  Remote 저장소와의 정보를 동기화합니다.&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout main
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git pull &lt;span class=&quot;nt&quot;&gt;--all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-수정-내용을-담는-새로운-브랜치를-생성합니다-브랜치-명은-prefix챕터명수정하는_이유로-하시면-됩니다branch-naming-convetion-예시는-아래와-같습니다&quot;&gt;(3) 수정 내용을 담는 새로운 브랜치를 생성합니다. 브랜치 명은 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[Prefix]/[챕터명]/[수정하는_이유]&lt;/code&gt;로 하시면 됩니다(&lt;a href=&quot;https://convex-optimization-for-all.github.io/contribution/2021/02/03/conventions/&quot;&gt;Branch Naming Convetion&lt;/a&gt;). 예시는 아래와 같습니다.&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout &lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; bugfix/chapter01-fix-typo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;4-파일을-편집합니다-생성-또는-수정하고자-하는-컨텐츠는-convention을-지켜-작성해야-합니다&quot;&gt;(4) 파일을 편집합니다. 생성 또는 수정하고자 하는 컨텐츠는 &lt;a href=&quot;https://convex-optimization-for-all.github.io/contribution/2021/02/03/conventions/&quot;&gt;Convention&lt;/a&gt;을 지켜 작성해야 합니다.&lt;/h3&gt;

&lt;h3 id=&quot;5-remote로-push합니다-예시는-아래와-같습니다&quot;&gt;(5) Remote로 Push합니다. 예시는 아래와 같습니다.&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git push origin bugfix/chapter01-fix-typo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;6-github에서-main-branch로의-pull-request를-생성합니다-pull-request-생성-방법은-아래-github-docs를-참고하시기-바랍니다&quot;&gt;(6) &lt;a href=&quot;https://github.com/convex-optimization-for-all/convex-optimization-for-all.github.io/pulls&quot;&gt;Github&lt;/a&gt;에서 main branch로의 Pull Request를 생성합니다. Pull Request 생성 방법은 아래 GitHub Docs를 참고하시기 바랍니다.&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request&quot;&gt;Creating a pull request&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;2-컨텐츠-수정을-요청하는-방법&quot;&gt;2. 컨텐츠 수정을 요청하는 방법&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Github Repository에 &lt;a href=&quot;https://github.com/convex-optimization-for-all/convex-optimization-for-all.github.io/issues&quot;&gt;Issue&lt;/a&gt;를 생성하실 수 있습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;
</content>
 </entry>
 
 <entry>
   <title>introduction</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/home/introduction/"/>
   <updated>2021-01-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/home/introduction</id>
   <content type="html">
</content>
 </entry>
 
 <entry>
   <title>contents</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/home/contents/"/>
   <updated>2021-01-20T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/home/contents</id>
   <content type="html">&lt;p&gt;An introduction to convex optimization problems, concepts in convex analysis, convex optimization algorithms, duality theory, optimality conditions, and applications of convex optimization in statistics and machine learning. The &lt;strong&gt;2026 modern track&lt;/strong&gt; (Chapters 26–29 on this site) adds SGD and adaptive methods, automatic differentiation, nonconvex deep-learning landscapes, and a first look at data-parallel / federated optimization.&lt;/p&gt;

&lt;h1 id=&quot;course-objectives&quot;&gt;Course Objectives&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Provide students with fundamental knowledge of convex optimization to support their study and research in data science.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Enable students to understand optimization algorithms and use existing software to solve optimization problems.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Begin to develop skills in analyzing and solving convex optimization problems in real-world applications, and in applying optimization algorithms to these problems.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;main-textbooks&quot;&gt;Main Textbooks&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Y. Nesterov, Lectures on Convex Optimization, 2018. [FIT_2101685_001]&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;S. Boyd &amp;amp; L. Vandenberghe, Convex Optimization, 2004.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;C. C. Aggarwal, Linear Algebra and Optimization for Machine Learning: A Textbook, 2020. [FIT_2101685_101]&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;C. Byrne, A First Course in Optimization, CRC Press, 2015.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;S. Sra, S. Nowozin, &amp;amp; S. J. Wright (eds.), Optimization for Machine Learning, MIT Press, 2012.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01 Tập Affine và Tập Lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_Affine_and_Convex_Sets/"/>
   <updated>2021-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter02/02_01_Affine_and_Convex_Sets</id>
   <content type="html">&lt;p&gt;Một điều rất đẹp trong hình học lồi là ba họ tập hợp quan trọng nhất — &lt;strong&gt;tập affine&lt;/strong&gt;, &lt;strong&gt;tập lồi&lt;/strong&gt; và &lt;strong&gt;hình nón lồi&lt;/strong&gt; — thực chất đều sinh ra từ cùng một công thức tổ hợp tuyến tính \(\theta_1 x_1 + \theta_2 x_2\), chỉ khác nhau ở hai chữ số nhỏ trên hệ số \(\theta_1, \theta_2\)! Thay vì học thuộc lòng ba định nghĩa rời rạc, hãy nhìn chúng như một chiếc bảng điều khiển có hai công tắc: “tổng bằng 1” và “không âm”.&lt;/p&gt;

&lt;p&gt;Phần 02-01 sẽ đưa bạn đi qua từng viên gạch hình học sơ cấp từ đường thẳng, đoạn thẳng, tia cho đến siêu phẳng.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bảng-hai-công-tắc-sinh-ra-bốn-họ-tập-hợp&quot;&gt;Kiến thức cần nhớ: Bảng hai công tắc sinh ra bốn họ tập hợp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không gian con (Subspace):&lt;/strong&gt; \(\theta_1, \theta_2 \in \mathbb{R}\) hoàn toàn tự do (luôn chứa gốc tọa độ \(0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập Affine:&lt;/strong&gt; Bật công tắc \(\theta_1 + \theta_2 = 1\) (trượt tự do trên toàn đường thẳng đi qua \(x_1, x_2\); mô tả ràng buộc đẳng thức \(Ax = b\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập Lồi:&lt;/strong&gt; Bật cả hai công tắc \(\theta_1 + \theta_2 = 1\) và \(\theta_1, \theta_2 \ge 0\) (chỉ giữ lại đoạn thẳng nằm giữa \(x_1\) và \(x_2\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình nón lồi:&lt;/strong&gt; Chỉ bật công tắc \(\theta_1, \theta_2 \ge 0\) (cho phép co giãn tùy ý theo hướng dương, tạo thành chùm tia xuất phát từ gốc tọa độ).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-cùng-hai-điểm-x_1--1-0-x_2--0-2-tạo-ra-ba-loại-tổ-hợp-khác-nhau&quot;&gt;Giải thích: Cùng hai điểm \(x_1 = (1, 0),\ x_2 = (0, 2)\) tạo ra ba loại tổ hợp khác nhau&lt;/h3&gt;

&lt;p&gt;Xét hai điểm \(x_1 = (1, 0)^T\) và \(x_2 = (0, 2)^T\) trong \(\mathbb{R}^2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp affine (\(\theta_1 + \theta_2 = 1\), cho phép âm):&lt;/strong&gt; Chọn \(\theta_1 = 2,\ \theta_2 = -1\):
\(z_{\text{aff}} = 2(1, 0) + (-1)(0, 2) = (2, -2).\)
Điểm này nằm trên đường thẳng \(2x_1 + x_2 = 2\) (kiểm tra: \(2(2) + (-2) = 2\)), nhưng nằm ngoài đoạn nối \(x_1, x_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp lồi (\(\theta_1 + \theta_2 = 1,\ \theta_i \ge 0\)):&lt;/strong&gt; Chọn \(\theta_1 = 0.5,\ \theta_2 = 0.5\):
\(z_{\text{conv}} = 0.5(1, 0) + 0.5(0, 2) = (0.5, 1).\)
Điểm này nằm đúng trên đoạn thẳng nối \(x_1\) và \(x_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp nón (\(\theta_1, \theta_2 \ge 0\), không cần tổng bằng 1):&lt;/strong&gt; Chọn \(\theta_1 = 2,\ \theta_2 = 1\):
\(z_{\text{cone}} = 2(1, 0) + 1(0, 2) = (2, 2).\)
Điểm này không còn nằm trên đường thẳng \(2x_1 + x_2 = 2\) (vì \(2(2)+2 = 6 \ne 2\)), mà nằm sâu trong góc phần tư thứ nhất \(\mathbb{R}_+^2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này giới thiệu các khái niệm và định nghĩa cơ bản xoay quanh tập lồi. Chúng ta sẽ lần lượt xét ba loại tập hợp: cơ bản nhất là tập affine, sau đó bằng cách đặt thêm điều kiện lên tập affine, ta định nghĩa tập lồi và hình nón.&lt;/p&gt;

&lt;p&gt;Một cách trực quan, ba loại tập hợp này có thể được hình dung như tập hợp tạo thành từ các đường thẳng, đoạn thẳng hoặc tia: tập affine được xây dựng từ các đường thẳng, tập lồi từ các đoạn thẳng và hình nón từ các tia. Cách nhìn này giúp việc nắm bắt sự khác nhau giữa chúng trở nên rõ ràng hơn. Ngoài ra, hình nón còn được gọi là tập thuần nhất không âm (nonnegative homogeneous set), phản ánh tính chất kéo dài vô hạn chỉ theo một hướng tính từ gốc tọa độ.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01 Affine and Convex Sets</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_Affine_and_Convex_Sets/"/>
   <updated>2021-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter02/02_01_Affine_and_Convex_Sets</id>
   <content type="html">&lt;p&gt;Not all combinations of two vectors are created equal. Depending on which restrictions we place on the scalar weights \(\theta_1, \theta_2\), combining the exact same pair of points traces out an infinite line (affine), a bounded bridge (convex), or an unbounded wedge (conic). Section 02-01 lays out this three-tier geometric hierarchy that classifies every linear and conic constraint in optimization.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-three-weight-rules-three-geometric-worlds&quot;&gt;Key ideas: Three Weight Rules, Three Geometric Worlds&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Affine Combinations (\(\sum \theta_i = 1\)):&lt;/strong&gt; Weights can be negative, extending infinitely in both directions; models linear equality constraints \(Ax = b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Combinations (\(\sum \theta_i = 1,\; \theta_i \ge 0\)):&lt;/strong&gt; Nonnegative probability weights that stay strictly between the generating points; models bounded mixtures and feasible polytopes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic Combinations (\(\theta_i \ge 0\)):&lt;/strong&gt; Drop the sum-to-one rule while keeping nonnegativity; models scale-invariant cones such as \(\mathbb{R}_+^n\), second-order cones, and \(\mathbb{S}_+^n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nested Inclusion:&lt;/strong&gt; Every affine set is convex, and every convex cone is convex—knowing which tier a constraint belongs to immediately unlocks stronger structural theorems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-pair-of-points-under-three-combination-rules&quot;&gt;Worked example: One Pair of Points Under Three Combination Rules&lt;/h3&gt;

&lt;p&gt;Let \(x_1 = (1, 0)^T\) and \(x_2 = (0, 2)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Affine combination (\(\theta_1 = 2, \theta_2 = -1\), sum \(= 1\)):&lt;/strong&gt;
\(2x_1 - x_2 = 2(1, 0)^T - (0, 2)^T = (2, -2)^T.\)
Because \(\theta_2 &amp;lt; 0\), this point lies outside the segment connecting \(x_1\) and \(x_2\), yet remains on the infinite line through them.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex combination (\(\theta_1 = 0.5, \theta_2 = 0.5\), nonnegative and sum \(= 1\)):&lt;/strong&gt;
\(0.5x_1 + 0.5x_2 = (0.5, 1)^T,\)
the exact midpoint of the line segment from \(x_1\) to \(x_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conic combination (\(\theta_1 = 2, \theta_2 = 3\), nonnegative, sum \(= 5 \neq 1\)):&lt;/strong&gt;
\(2x_1 + 3x_2 = (2, 6)^T,\)
which stays inside the nonnegative first quadrant (the conic hull of \(x_1, x_2\)) while scaling beyond the line segment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this chapter, we will explore the concepts and definitions centered around convex sets. We introduce three types of sets: the most basic is the affine set, and by imposing additional constraints on the affine set, we define the convex set and the cone.&lt;/p&gt;

&lt;p&gt;Interestingly, these sets can be thought of as collections of many lines (line), line segments, or rays. An affine set is formed by gathering many lines, a convex set by gathering many line segments, and a cone by gathering many rays. This perspective makes it easier to understand these concepts. Also, a cone is sometimes called a nonnegative homogeneous set, which refers to the property that it extends only in one direction from the origin, helping to clarify the naming.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>01-01 Bài toán tối ưu hóa?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_01_optimization_problems/"/>
   <updated>2021-01-07T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_01_optimization_problems</id>
   <content type="html">&lt;p&gt;Trước khi máy tính có thể giải bất kỳ bài toán thực tế nào — từ phân bổ vốn đầu tư, thiết kế ăng-ten, đến lập lịch giao hàng — người kỹ sư phải làm công việc quan trọng nhất: &lt;strong&gt;dịch một câu chuyện đời thực thành ngôn ngữ chuẩn của bài toán tối ưu toán học&lt;/strong&gt;. Chọn sai biến quyết định hoặc viết thiếu một ràng buộc biên có thể biến một bài toán dễ giải thành bài toán vô nghiệm hoặc cho ra kết quả phi thực tế.&lt;/p&gt;

&lt;p&gt;Bài học này đặt ra bộ khung chuẩn mực gồm biến tối ưu, hàm mục tiêu, ràng buộc bất đẳng thức, ràng buộc đẳng thức và phân biệt rõ giá trị tối ưu \(p^*\) với nghiệm tối ưu \(x^*\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-một-bài-toán-tối-ưu-chuẩn&quot;&gt;Kiến thức cần nhớ: Giải phẫu một bài toán tối ưu chuẩn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Biến quyết định (\(x \in \mathbb{R}^n\)):&lt;/strong&gt; Các đại lượng ta thực sự có quyền điều chỉnh (khác với các tham số cố định cho trước của bài toán).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mục tiêu (\(f_0(x)\)):&lt;/strong&gt; Thước đo chi phí cần tối thiểu hóa. Nếu bài toán gốc yêu cầu &lt;em&gt;tối đa hóa&lt;/em&gt; lợi nhuận \(u(x)\), ta chỉ cần đổi dấu thành &lt;em&gt;tối thiểu hóa&lt;/em&gt; \(-u(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Miền khả thi (Feasible Set):&lt;/strong&gt; Tập tất cả các điểm \(x\) thỏa mãn đồng thời mọi ràng buộc \(g_i(x) \le 0\) và \(h_j(x) = 0\). Nếu miền này rỗng, bài toán &lt;em&gt;vô nghiệm&lt;/em&gt; (infeasible, \(p^* = +\infty\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giá trị tối ưu (\(p^*\)) và tập nghiệm tối ưu (\(X_{\text{opt}}\)):&lt;/strong&gt; Một bài toán có thể có nghiệm duy nhất, vô số nghiệm cùng đạt \(p^*\), hoặc không bị chặn dưới (\(p^* = -\infty\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chuẩn-hóa-và-giải-tay-một-bài-toán-phân-bổ-chi-phí-2-biến&quot;&gt;Giải thích: Chuẩn hóa và giải tay một bài toán phân bổ chi phí 2 biến&lt;/h3&gt;

&lt;p&gt;Một xưởng cần sản xuất ít nhất \(5\) tấn hỗn hợp từ hai nguyên liệu \(x_1, x_2\) (tấn) với chi phí lần lượt \(3\) triệu/tấn và \(2\) triệu/tấn, sao cho dùng tối thiểu \(1\) tấn loại 1 và \(2\) tấn loại 2.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Viết lại về dạng chuẩn (\(\min\) và ràng buộc \(\le 0\)):&lt;/strong&gt;
\(\min_{x_1, x_2} f_0(x) = 3x_1 + 2x_2\)
với ba ràng buộc bất đẳng thức:
\(g_1(x) = 5 - x_1 - x_2 \le 0, \qquad g_2(x) = 1 - x_1 \le 0, \qquad g_3(x) = 2 - x_2 \le 0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác định các đỉnh của miền khả thi:&lt;/strong&gt; Miền khả thi là vùng không bị chặn phía trên bên phải nhưng bị chặn dưới bởi hai góc nhọn:
    &lt;ul&gt;
      &lt;li&gt;Đỉnh \(A\) (giao \(x_1 = 1\) và \(x_1 + x_2 = 5\)): \(A = (1, 4)\).&lt;/li&gt;
      &lt;li&gt;Đỉnh \(B\) (giao \(x_2 = 2\) và \(x_1 + x_2 = 5\)): \(B = (3, 2)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hàm mục tiêu tại các ứng viên:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(A = (1, 4)\): \(f_0(1, 4) = 3(1) + 2(4) = 11\).&lt;/li&gt;
      &lt;li&gt;Tại \(B = (3, 2)\): \(f_0(3, 2) = 3(3) + 2(2) = 13\).
Vì hệ số chi phí đều dương, tăng \(x_1\) hoặc \(x_2\) chỉ làm chi phí tăng thêm.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Nghiệm tối ưu duy nhất là \(x^* = (1, 4)^T\) với giá trị tối ưu \(p^* = 11\) triệu đồng; tại \(x^*\), hai ràng buộc \(g_1(x^*) = 0\) và \(g_2(x^*) = 0\) là &lt;strong&gt;ràng buộc chặt&lt;/strong&gt; (active), còn \(g_3(x^*) = 2 - 4 = -2 &amp;lt; 0\) là ràng buộc lỏng.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài toán tối ưu hóa là bài toán tìm nghiệm tốt nhất (nghiệm tối ưu) — hoặc một nghiệm đủ gần tối ưu — trong tập hợp các phương án khả dĩ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trong khoa học dữ liệu và học máy&lt;/strong&gt;, tối ưu hóa hiện diện ở hầu hết mọi tác vụ:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Huấn luyện mạng nơ-ron&lt;/strong&gt;: tìm bộ trọng số làm cực tiểu sai số dự đoán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hồi quy tuyến tính&lt;/strong&gt;: tìm siêu phẳng khớp nhất làm cực tiểu tổng bình phương sai số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân cụm&lt;/strong&gt;: tối ưu vị trí tâm cụm nhằm cực tiểu hóa phương sai trong từng cụm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn đặc trưng&lt;/strong&gt;: chọn tập con đặc trưng phù hợp nhất để tối đa hóa hiệu năng mô hình.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tinh chỉnh siêu tham số&lt;/strong&gt;: tìm tốc độ học, hệ số điều chuẩn và các siêu tham số tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mỗi khi bạn huấn luyện một mô hình học máy, thực chất bạn đang giải một bài toán tối ưu hóa.&lt;/p&gt;

&lt;h2 id=&quot;bài-toán-tối-ưu-hóa-toán-học&quot;&gt;Bài toán tối ưu hóa toán học&lt;/h2&gt;

&lt;p&gt;Một bài toán tối ưu hóa toán học có thể viết ở dạng tổng quát như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align*} 
&amp;amp;\min_{x\in D}\ &amp;amp;&amp;amp; f(x) \\
&amp;amp;\text{với điều kiện} &amp;amp;&amp;amp; g_i(x) \le 0,\ i = 1, ..., m \\
&amp;amp;&amp;amp;&amp;amp; h_j(x) = 0,\ j = 1,\ ..., r
\end{align*}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bài toán tối ưu hóa toán học ở dạng chuẩn&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) là biến tối ưu hóa (biến quyết định).&lt;/li&gt;
  &lt;li&gt;\(f: \mathbb{R}^n \rightarrow \mathbb{R}\) là hàm mục tiêu (hoặc hàm chi phí).&lt;/li&gt;
  &lt;li&gt;\(g_i: \mathbb{R}^n \rightarrow \mathbb{R},\ i = 1, ..., m\) là các hàm ràng buộc bất đẳng thức.&lt;/li&gt;
  &lt;li&gt;\(h_j: \mathbb{R}^n \rightarrow \mathbb{R},\ j = 1, ..., r\) là các hàm ràng buộc đẳng thức.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vector \(x\) làm cực tiểu hàm mục tiêu \(f\) trên miền khả thi (tập hợp tất cả các điểm thỏa mãn mọi ràng buộc) được ký hiệu là \(x^*\) và gọi là &lt;strong&gt;nghiệm tối ưu&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Các ràng buộc được chia thành hai loại:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc tường minh:&lt;/strong&gt; Các ràng buộc được nêu trực tiếp trong bài toán. Trong dạng chuẩn ở trên, các điều kiện liên quan đến \(g_i\) và \(h_j\) là ràng buộc tường minh. Nếu không có ràng buộc tường minh nào, bài toán được gọi là bài toán không ràng buộc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc ngầm:&lt;/strong&gt; Các ràng buộc không viết tường minh, nhưng phát sinh từ giao miền xác định của hàm mục tiêu và tất cả các hàm ràng buộc:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;\(D = dom(f) \cap \bigcap_{i=1}^m {\rm dom}(g_i) \cap \bigcap_{j=1}^r dom(h_j)\)&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ghi chú:&lt;/strong&gt; \(dom(f)\) ký hiệu miền xác định của hàm \(f\).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ: Ràng buộc ngầm ↔ Ràng buộc tường minh&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Xét bài toán tối ưu hóa sau:&lt;/p&gt;

\[\begin{align*} \text{tối thiểu } &amp;amp; &amp;amp; \log(x) \end{align*}\]

  &lt;p&gt;Ở đây, miền xác định của hàm mục tiêu \(\log(x)\) là \(x &amp;gt; 0\), nên \(x &amp;gt; 0\) là một ràng buộc ngầm. Khi viết lại với ràng buộc tường minh, bài toán trở thành:&lt;/p&gt;

\[\begin{align*} &amp;amp;\text{tối thiểu } &amp;amp;&amp;amp; \log(x) \\ &amp;amp;\text{với điều kiện } &amp;amp;&amp;amp;x &amp;gt; 0 \end{align*}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;💡 Lưu ý thực hành&lt;/strong&gt;: Khi có thể, hãy bắt đầu với mô hình tối ưu hóa lồi vì chúng dễ phân tích và giải chính xác hơn. Chỉ nên chuyển sang các mô hình không lồi phức tạp hơn khi mô hình lồi không đáp ứng được yêu cầu bài toán.&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>01 Giới thiệu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_00_Introduction/"/>
   <updated>2021-01-07T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter01/01_00_Introduction</id>
   <content type="html">&lt;p&gt;Một câu nói nổi tiếng của nhà toán học R. Tyrrell Rockafellar năm 1993 đã định hình lại cách cả thế giới nhìn về tối ưu hóa: &lt;em&gt;“Ranh giới thực sự phân chia các bài toán tối ưu không phải là giữa tuyến tính và phi tuyến, mà là giữa &lt;strong&gt;lồi&lt;/strong&gt; và &lt;strong&gt;không lồi&lt;/strong&gt;.”&lt;/em&gt; Một bài toán không lồi chỉ có vài chục biến đôi khi khiến siêu máy tính bó tay vì hàng triệu cái bẫy cực tiểu địa phương; ngược lại, một bài toán tối ưu hóa lồi có tới hàng triệu biến lại có thể giải tới độ chính xác gần như tuyệt đối chỉ trong vài giây.&lt;/p&gt;

&lt;p&gt;Chương 01 mở cánh cửa bước vào thế giới tối ưu hóa lồi: định nghĩa bài toán tối ưu tổng quát, nhận diện cấu trúc lồi, lộ trình khóa học và câu chuyện lịch sử gần một thế kỷ tạo nên các bộ giải hiện đại.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-khái-niệm-mở-màn-của-chương-01&quot;&gt;Kiến thức cần nhớ: Bốn khái niệm mở màn của Chương 01&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình hóa bài toán tối ưu hóa:&lt;/strong&gt; Quy mọi bài toán ra quyết định về ba thành phần chuẩn hóa: biến quyết định \(x\), hàm mục tiêu \(f_0(x)\) và tập ràng buộc khả thi \(g_i(x) \le 0,\ h_j(x) = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lồi so với Không lồi (Convex vs. Non-convex):&lt;/strong&gt; Hiểu vì sao tính lồi loại bỏ hoàn toàn các “bẫy” cực tiểu địa phương: trong bài toán lồi, mọi điểm thấp nhất trong lân cận đều là điểm thấp nhất toàn cục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các họ bài toán kinh điển:&lt;/strong&gt; Định vị Bình phương tối thiểu (LS), Quy hoạch tuyến tính (LP), Quy hoạch bậc hai (QP) và Quy hoạch bán xác định (SDP) trên cùng một bản đồ phân cấp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tư duy thuật toán hiện đại:&lt;/strong&gt; Biết rằng giải một bài toán lớn trong thực tế không chỉ dựa vào công thức đạo hàm, mà còn dựa vào việc khai thác cấu trúc bài toán (như ADMM, điểm trong, gradient gần kề).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-thấy-tận-mắt-bẫy-cực-tiểu-địa-phương-của-hàm-không-lồi&quot;&gt;Giải thích: Thấy tận mắt “bẫy cực tiểu địa phương” của hàm không lồi&lt;/h3&gt;

&lt;p&gt;So sánh hai hàm số một biến trên \(\mathbb{R}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hàm lồi \(f_1(x) = (x - 2)^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đạo hàm \(f_1&apos;(x) = 2(x - 2) = 0 \iff x = 2\), và \(f_1&apos;&apos;(x) = 2 &amp;gt; 0\) mọi nơi.&lt;/li&gt;
      &lt;li&gt;Dù xuất phát từ \(x_0 = -100\) hay \(x_0 = +100\), thuật toán hạ dốc đều trượt về đúng một đáy duy nhất \(x^* = 2\) với \(f_1(2) = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm không lồi \(f_2(x) = \frac{1}{4}x^4 - \frac{1}{3}x^3 - x^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đạo hàm: \(f_2&apos;(x) = x^3 - x^2 - 2x = x(x - 2)(x + 1) = 0 \implies x \in \{-1,\ 0,\ 2\}\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra đạo hàm cấp hai \(f_2&apos;&apos;(x) = 3x^2 - 2x - 2\):
        &lt;ul&gt;
          &lt;li&gt;Tại \(x = -1\): \(f_2&apos;&apos;(-1) = 3 &amp;gt; 0\) (cực tiểu địa phương), \(f_2(-1) = \frac{1}{4} + \frac{1}{3} - 1 = -\frac{5}{12} \approx -0.417\).&lt;/li&gt;
          &lt;li&gt;Tại \(x = 0\): \(f_2&apos;&apos;(0) = -2 &amp;lt; 0\) (cực đại địa phương), \(f_2(0) = 0\).&lt;/li&gt;
          &lt;li&gt;Tại \(x = 2\): \(f_2&apos;&apos;(2) = 6 &amp;gt; 0\) (cực tiểu toàn cục), \(f_2(2) = 4 - \frac{8}{3} - 4 = -\frac{8}{3} \approx -2.667\).
Nếu thuật toán bắt đầu ở \(x_0 = -2\), nó sẽ rơi vào thung lũng nông \(x = -1\) (\(-0.417\)) và mắc kẹt vĩnh viễn, bỏ lỡ thung lũng sâu hơn gấp 6 lần ở \(x = 2\) (\(-2.667\))!&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Chương này mở đầu khóa học bằng ba câu hỏi cốt lõi: một bài toán tối ưu hóa &lt;em&gt;là gì&lt;/em&gt;, vì sao các bài toán &lt;strong&gt;lồi&lt;/strong&gt; cho phép ta đảm bảo chất lượng nghiệm, và phần còn lại của khóa học trang bị những gì cho sinh viên khoa học dữ liệu.&lt;/p&gt;

&lt;p&gt;Một bài toán quy hoạch toán học tìm điểm \(x\) thuộc tập khả thi sao cho hàm mục tiêu đạt giá trị nhỏ nhất (hoặc lớn nhất):&lt;/p&gt;

\[\begin{align}
\underset{x}{\text{minimize}} \quad &amp;amp; f(x) \\
\text{subject to} \quad &amp;amp; x \in \mathcal{C}.
\end{align}\]

&lt;p&gt;Trong học máy, cấu trúc này xuất hiện ở hầu hết mọi mô hình. Huấn luyện một bộ dự đoán thường có dạng bài toán &lt;strong&gt;cực tiểu hóa rủi ro thực nghiệm&lt;/strong&gt;:&lt;/p&gt;

\[\min_w \frac{1}{n}\sum_{i=1}^n \ell\bigl(h_w(x_i), y_i\bigr) + \lambda R(w),\]

&lt;p&gt;trong đó \(\ell\) là hàm mất mát và \(R\) là hàm điều chuẩn (regularizer). Lựa chọn đặc trưng, phân bổ trọng số danh mục đầu tư, ước lượng hợp lý tối đa và bài toán đối ngẫu của máy vector hỗ trợ (SVM) đều chung khuôn mẫu này, chỉ khác nhau ở hàm mục tiêu \(f\) và tập khả thi \(\mathcal{C}\).&lt;/p&gt;

&lt;p&gt;Các bài toán quy hoạch &lt;strong&gt;lồi&lt;/strong&gt; — khi \(f\) là hàm lồi trên tập lồi \(\mathcal{C}\) — có tính chất đặc biệt: mọi cực tiểu địa phương đều là cực tiểu toàn cục, điều kiện bậc nhất thường là điều kiện đủ, và ta có các thuật toán đáng tin cậy (gradient, proximal, điểm trong). Các mạng nơ-ron sâu dù không lồi vẫn sử dụng những thuật toán này; &lt;a href=&quot;/contents/vi/chapter28/&quot;&gt;Chương 28&lt;/a&gt; sẽ phân tích vì sao bề mặt hàm mất mát trong thực tế thường thuận lợi hơn so với dự đoán từ lý thuyết trường hợp xấu nhất.&lt;/p&gt;

&lt;h2 id=&quot;nội-dung-của-chương-này&quot;&gt;Nội dung của chương này&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán tối ưu hóa&lt;/strong&gt; — biến quyết định, hàm mục tiêu, ràng buộc và tính khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán tối ưu hóa lồi&lt;/strong&gt; — định nghĩa nền tảng dùng xuyên suốt khóa học.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mục tiêu và chủ đề&lt;/strong&gt; — cách kết nối giữa Chương 02–25 (nền tảng cổ điển) và Chương 26–29 (lộ trình hiện đại 2026).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lược sử&lt;/strong&gt; — từ quy hoạch tuyến tính đến học sâu gắn với vi phân tự động (autodiff).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hãy đọc bài tiếp theo về dạng chuẩn với ràng buộc bất đẳng thức và đẳng thức; sau đó thử tự phân loại với những bài toán quen thuộc (bình phương tối thiểu, hồi quy logistic, &lt;em&gt;k&lt;/em&gt;-means) xem bài nào là bài toán lồi.&lt;/p&gt;

&lt;p&gt;Bài đọc tùy chọn ở cuối chương, &lt;a href=&quot;/contents/vi/chapter01/01_05_Applications_Recent/&quot;&gt;01-05 Ứng dụng và phát triển gần đây&lt;/a&gt;, áp dụng cùng khuôn mẫu này cho bài toán huấn luyện LLM tối ưu theo tính toán, khuôn khổ predict-then-optimize và tối ưu hóa với ràng buộc công bằng.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>01-01 Optimization problems?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_01_optimization_problems/"/>
   <updated>2021-01-07T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_01_optimization_problems</id>
   <content type="html">&lt;p&gt;Whether you are routing delivery trucks across Ho Chi Minh City, allocating capital across stocks, or fitting a neural network, you are solving the exact same mathematical template: choose a vector \(x\) from a set of allowed choices to make a single scalar score as small as possible. Writing a problem down cleanly in standard mathematical form is half the battle—it exposes hidden symmetries, infeasibilities, and exact bounds before you ever touch a solver.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-a-mathematical-optimization-problem&quot;&gt;Key ideas: Anatomy of a Mathematical Optimization Problem&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Decision Vector (\(x \in \mathbb{R}^n\)):&lt;/strong&gt; The levers you actually control—never confuse controllable decisions with fixed problem parameters (data).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Objective Function (\(f_0(x)\)):&lt;/strong&gt; A scalar metric to minimize (maximization of \(g(x)\) is always rewritten as minimizing \(-g(x)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constraints &amp;amp; Feasible Set (\(\mathcal{C}\)):&lt;/strong&gt; The intersection of all inequality constraints \(f_i(x) \le b_i\) and equality constraints \(h_j(x) = 0\); if \(\mathcal{C} = \emptyset\), the problem is &lt;em&gt;infeasible&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal Value (\(p^*\)) vs. Optimal Solution (\(x^*\)):&lt;/strong&gt; \(p^* = \inf_{x \in \mathcal{C}} f_0(x)\) is the best achievable score, whereas \(x^* \in \mathcal{C}\) is a feasible point achieving \(f_0(x^*) = p^*\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-bounding-and-solving-a-constrained-problem-by-hand&quot;&gt;Worked example: Bounding and Solving a Constrained Problem by Hand&lt;/h3&gt;

&lt;p&gt;Consider the problem:
\(\min_{x_1, x_2 \in \mathbb{R}} \; x_1^2 + x_2^2 \quad \text{subject to} \quad x_1 + x_2 \ge 4,\; x_1 \ge 0,\; x_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test a feasible candidate:&lt;/strong&gt; Try \(x = (3, 2)^T\). It satisfies \(3 + 2 = 5 \ge 4\) and \(3, 2 \ge 0\), giving an upper bound \(p^* \le 3^2 + 2^2 = 13\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Derive an exact lower bound via Cauchy–Schwarz:&lt;/strong&gt; For any feasible \((x_1, x_2)\),
\((1 \cdot x_1 + 1 \cdot x_2)^2 \le (1^2 + 1^2)(x_1^2 + x_2^2) = 2(x_1^2 + x_2^2).\)
Since \(x_1 + x_2 \ge 4\), we get \(16 \le (x_1 + x_2)^2 \le 2(x_1^2 + x_2^2) \implies x_1^2 + x_2^2 \ge 8\). Thus \(p^* \ge 8\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check attainment:&lt;/strong&gt; At \(x^* = (2, 2)^T\), all constraints hold (\(2 + 2 = 4 \ge 4\), \(2 \ge 0\)) and \(f_0(2, 2) = 2^2 + 2^2 = 8\). Because the upper bound equals the lower bound, \(x^* = (2, 2)^T\) is certified globally optimal with \(p^* = 8\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An optimization problem is a problem in which, among many possible candidates, we seek the optimal solution (optimal value) or a value close to the optimal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In data science and machine learning&lt;/strong&gt;, optimization is everywhere:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Training neural networks&lt;/strong&gt;: Finding weights that minimize prediction error&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear regression&lt;/strong&gt;: Finding the best-fit line that minimizes squared errors&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Clustering&lt;/strong&gt;: Optimizing cluster centers to minimize within-cluster variance&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feature selection&lt;/strong&gt;: Choosing the best subset of features to maximize model performance&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hyperparameter tuning&lt;/strong&gt;: Finding optimal learning rates, regularization parameters, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every time you train a machine learning model, you’re solving an optimization problem!&lt;/p&gt;

&lt;h2 id=&quot;mathematical-optimization-problems&quot;&gt;Mathematical optimization problems&lt;/h2&gt;
&lt;p&gt;A mathematical optimization problem can be expressed as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align*} 
&amp;amp;\min_{x\in D}\ &amp;amp;&amp;amp; f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp; g_i(x) \le 0,\ i = 1, ..., m \\
&amp;amp;&amp;amp;&amp;amp; h_j(x) = 0,\ j = 1,\ ..., r
\end{align*}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Mathematical Optimization Problem in standard form&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(x \in \mathbb{R}^n\) is the optimization variable&lt;/li&gt;
  &lt;li&gt;\(f: \mathbb{R}^n \rightarrow \mathbb{R}\) is the objective or cost function&lt;/li&gt;
  &lt;li&gt;\(g_i: \mathbb{R}^n \rightarrow \mathbb{R}, i = 1, ..., m\) are the inequality constraint functions&lt;/li&gt;
  &lt;li&gt;\(h_j: \mathbb{R}^n \rightarrow \mathbb{R}, j = 1, ..., r\) are the equality constraint functions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The vector \(x\) that minimizes the objective function \(f\) over the feasible domain (the set of all points satisfying the constraints) is denoted as \(x^*\) and called the optimal solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints can be classified into two types:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Explicit constraints: Constraints that are directly specified in the optimization problem. In the standard form above, the constraints expressed by the functions \(g_i\) and \(h_j\) are explicit. If there are no explicit constraints, the problem is called an unconstrained problem.&lt;/li&gt;
  &lt;li&gt;Implicit constraints: Constraints that are not directly specified, but arise from the intersection of the domains of the objective and constraint functions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;\(D = dom(f) \cap \bigcap_{i=1}^m {\rm dom}(g_i) \cap \bigcap_{j=1}^r dom(h_j)\)&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; \(dom(f)\) means the domain of the function \(f\).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Example: implicit constraint ↔ explicit constraint&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;Suppose the optimization problem is given as follows:&lt;/p&gt;

\[\begin{align*} \text{minimize } &amp;amp; &amp;amp; \log(x) \end{align*}\]

  &lt;p&gt;Here, the domain of the objective function \(\log(x)\) is \(x &amp;gt; 0\), so \(x &amp;gt; 0\) is an implicit constraint. If we write this as an optimization problem with explicit constraints:&lt;/p&gt;

\[\begin{align*} &amp;amp;\text{minimize } &amp;amp;&amp;amp; \log(x) \\ &amp;amp;\text{subject to } &amp;amp;&amp;amp;x &amp;gt; 0 \end{align*}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;💡 Pro Tip&lt;/strong&gt;: Start with convex formulations when possible - they’re easier to solve and understand. Only move to complex non-convex models when simpler approaches fail to meet your requirements.&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>01 Introduction</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_00_Introduction/"/>
   <updated>2021-01-07T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter01/01_00_Introduction</id>
   <content type="html">&lt;p&gt;In 1993, R. Tyrrell Rockafellar wrote a sentence that reshaped modern applied mathematics: &lt;em&gt;“The great watershed in optimization isn’t between linearity and nonlinearity, but convexity and nonconvexity.”&lt;/em&gt; Chapter 01 opens the door to why that watershed matters—showing how casting an engineering, finance, or machine learning problem in convex form transforms an intractable search through exponential local traps into a reliable, polynomial-time computation.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-architecture-of-chapter-01&quot;&gt;Key ideas: The Architecture of Chapter 01&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Standard Problem Formulation:&lt;/strong&gt; Translating real-world decisions into decision variables \(x\), an objective \(f_0(x)\), inequality constraints \(f_i(x) \le 0\), and equality constraints \(h_j(x) = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Convexity Watershed:&lt;/strong&gt; Recognizing when the objective and feasible region are convex so that &lt;em&gt;every local minimum is automatically a global minimum&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Modeling vs. Algorithm Selection:&lt;/strong&gt; Understanding the two-step workflow of recognizing/reformulating convexity first, then matching problem structure (LP, QP, SOCP, SDP, nonsmooth composite) to specialized solvers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Historical &amp;amp; Modern Perspective:&lt;/strong&gt; Tracing how simplex, ellipsoid, interior-point, and modern first-order splitting methods made convex optimization a universal computational primitive.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-nonconvex-traps-vs-convex-global-certifiability&quot;&gt;Worked example: Nonconvex Traps vs. Convex Global Certifiability&lt;/h3&gt;

&lt;p&gt;Compare two 1D unconstrained objectives: \(f_1(x) = x^4 - 4x^2 + x\) (nonconvex) and \(f_2(x) = x^2 - 4x + 5\) (convex).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Analyze the nonconvex function \(f_1(x)\):&lt;/strong&gt;
\(f_1&apos;(x) = 4x^3 - 8x + 1, \qquad f_1&apos;&apos;(x) = 12x^2 - 8.\)
    &lt;ul&gt;
      &lt;li&gt;At \(x \approx 1.35\), \(f_1&apos;(1.35) \approx 0\) and \(f_1&apos;&apos;(1.35) \approx 13.87 &amp;gt; 0\), giving a &lt;strong&gt;local minimum&lt;/strong&gt; \(f_1(1.35) \approx -2.62\).&lt;/li&gt;
      &lt;li&gt;At \(x \approx -1.47\), \(f_1&apos;(-1.47) \approx 0\) and \(f_1&apos;&apos;(-1.47) \approx 17.93 &amp;gt; 0\), giving a strictly lower &lt;strong&gt;global minimum&lt;/strong&gt; \(f_1(-1.47) \approx -5.45\).
A local solver started at \(x_0 = 2\) gets permanently trapped at \(x \approx 1.35\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Analyze the convex function \(f_2(x)\):&lt;/strong&gt;
\(f_2&apos;(x) = 2x - 4 = 0 \implies x^* = 2, \qquad f_2&apos;&apos;(x) = 2 &amp;gt; 0 \text{ everywhere}.\)
From &lt;em&gt;any&lt;/em&gt; starting point \(x_0 \in \mathbb{R}\), descent converges to the unique global minimum \(f_2(2) = 1\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This chapter is the front door to the course: what an optimization problem &lt;em&gt;is&lt;/em&gt;, why &lt;strong&gt;convex&lt;/strong&gt; problems are the ones we can certify, and what the rest of the semester will buy you as a data-science student.&lt;/p&gt;

&lt;p&gt;A mathematical program asks for a point \(x\) in a feasible set that makes an objective as small (or as large) as possible:&lt;/p&gt;

\[\begin{align}
\underset{x}{\text{minimize}} \quad &amp;amp; f(x) \\
\text{subject to} \quad &amp;amp; x \in \mathcal{C}.
\end{align}\]

&lt;p&gt;In machine learning the same template is everywhere. Training a predictor is usually &lt;strong&gt;empirical risk minimization&lt;/strong&gt;&lt;/p&gt;

\[\min_w \frac{1}{n}\sum_{i=1}^n \ell\bigl(h_w(x_i), y_i\bigr) + \lambda R(w),\]

&lt;p&gt;with \(\ell\) a loss and \(R\) a regularizer. Feature selection, portfolio weights, maximum-likelihood parameters, and the dual of a support-vector machine are the same idea with different \(f\) and \(\mathcal{C}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convex&lt;/strong&gt; programs — convex \(f\) over a convex \(\mathcal{C}\) — are special: every local minimizer is global, first-order conditions are often sufficient, and we have reliable algorithms (gradient, proximal, interior-point). Nonconvex deep networks still use those algorithms; &lt;a href=&quot;/contents/en/chapter28/&quot;&gt;Chapter 28&lt;/a&gt; asks why the landscape is often kinder than the worst-case theory.&lt;/p&gt;

&lt;h2 id=&quot;what-this-chapter-contains&quot;&gt;What this chapter contains&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Optimization problems&lt;/strong&gt; — variables, objectives, constraints, feasibility.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex optimization problems&lt;/strong&gt; — the definition you will reuse every week.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Goals and topics&lt;/strong&gt; — how Chapters 02–25 (classical spine) and 26–29 (2026 modern track) fit together.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;A brief history&lt;/strong&gt; — from linear programming to autodiff-driven deep learning.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Read the next lesson for the standard form with inequality and equality constraints; then decide, for a problem you already know (least squares, logistic regression, &lt;em&gt;k&lt;/em&gt;-means), which pieces are convex.&lt;/p&gt;

&lt;p&gt;An optional close-out, &lt;a href=&quot;/contents/en/chapter01/01_05_Applications_Recent/&quot;&gt;01-05 Applications and recent developments&lt;/a&gt;, applies the same template to compute-optimal LLMs, predict-then-optimize, and fairness constraints.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00 Giới thiệu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_Introduction/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_Introduction</id>
   <content type="html">&lt;p&gt;Mỗi khi một chiếc xe tự lái chọn quỹ đạo tránh vật cản trong vài mili-giây, một hãng hàng không xếp lịch bay cho hàng nghìn chuyến trong bão, hay một mô hình ngôn ngữ lớn cập nhật hàng tỷ trọng số trên cụm GPU, bên dưới tất cả đều đang vận hành cùng một nhịp tim toán học: &lt;strong&gt;tối ưu hóa&lt;/strong&gt;. Nhưng để đọc được “bản nhạc” của tối ưu hóa lồi — nơi một bất đẳng thức hình học đơn giản có thể tiết kiệm hàng triệu phép tính — trước hết ta cần làm chủ bộ ngôn ngữ nền tảng gồm giải tích, đại số tuyến tính, tôpô tập hợp và xác suất.&lt;/p&gt;

&lt;p&gt;Chương 00 không phải là phần ôn tập khô khan để lướt qua cho xong, mà là xưởng rèn công cụ giúp bạn biến trực giác hình học thành lập luận chặt chẽ trước khi bước vào các thuật toán tối ưu hóa hiện đại.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-toán-học-của-tối-ưu-hóa&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột toán học của Tối ưu hóa&lt;/h2&gt;

&lt;p&gt;Để hiểu sâu vì sao một thuật toán hội tụ, khi nào nghiệm tối ưu tồn tại, và làm sao xử lý dữ liệu nhiễu, tối ưu hóa đứng vững trên bốn trụ cột liên kết chặt chẽ:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Giải tích đa biến (Multivariable Calculus):&lt;/strong&gt; Cung cấp ngôn ngữ mô tả tốc độ biến thiên cục bộ của hàm mục tiêu thông qua đạo hàm riêng, vector gradient \(\nabla f(x)\), ma trận Hessian \(\nabla^2 f(x)\) và khai triển Taylor. Đây là la bàn chỉ hướng giảm nhanh nhất tại mỗi bước lặp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đại số tuyến tính (Linear Algebra):&lt;/strong&gt; Biến hệ phương trình ràng buộc, phép chiếu và độ cong bậc hai thành ngôn ngữ gọn gàng của vector, ma trận, giá trị riêng và dạng toàn phương \(x^T Q x\). Mọi bước tính trong lập trình tối ưu thực tế đều quy về đại số tuyến tính số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết tập hợp và Tôpô thực (Set Theory &amp;amp; Real Topology):&lt;/strong&gt; Định nghĩa chính xác “miền khả thi” (tập đóng, tập mở, tập compact, tập biên) và trả lời câu hỏi quan trọng trước khi chạy bất kỳ thuật toán nào: &lt;em&gt;liệu nghiệm tối ưu toàn cục có thực sự tồn tại hay không?&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác suất và Thống kê (Probability &amp;amp; Statistics):&lt;/strong&gt; Khi dữ liệu có nhiễu hoặc bài toán mang yếu tố ngẫu nhiên (như tối ưu hóa ngẫu nhiên SGD hay ước lượng hợp lý tối đa MLE), xác suất biến việc khớp mô hình thành bài toán cực tiểu hóa hàm mất mát kỳ vọng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bốn-trụ-cột-cùng-giải-một-bài-toán-tối-ưu-nhỏ&quot;&gt;Giải thích: Bốn trụ cột cùng giải một bài toán tối ưu nhỏ&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa hàm bậc hai một biến trên một đoạn đóng:&lt;/p&gt;

\[\min_{x \in [4, 6]} f(x) = (x - 3)^2 + 2.\]

&lt;p&gt;Hãy quan sát cả bốn trụ cột phối hợp từng bước:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải tích (tìm điểm dừng không ràng buộc):&lt;/strong&gt; Đạo hàm \(f&apos;(x) = 2(x - 3) = 0 \Rightarrow x_{\text{uncon}} = 3\), với \(f&apos;&apos;(x) = 2 &amp;gt; 0\) (độ cong dương). Nếu không có ràng buộc, đáy của parabol nằm tại \(x = 3\) với \(f(3) = 2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập hợp và Tôpô (kiểm tra miền khả thi):&lt;/strong&gt; Miền khả thi \(D = [4, 6]\) là tập đóng và bị chặn (compact) trên \(\mathbb{R}\), và \(f\) liên tục, nên theo định lý Weierstrass chắc chắn tồn tại nghiệm tối ưu toàn cục trên \(D\). Tuy nhiên \(x_{\text{uncon}} = 3 \notin [4, 6]\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình học và hướng giảm tại biên:&lt;/strong&gt; Trên toàn đoạn \([4, 6]\), ta có \(f&apos;(x) = 2(x-3) \ge 2 &amp;gt; 0\), nghĩa là hàm luôn tăng khi đi sang phải. Do đó điểm thấp nhất bắt buộc rơi vào biên trái \(x^* = 4\), cho giá trị tối ưu \(f(4) = (4 - 3)^2 + 2 = 3\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài học cốt lõi:&lt;/strong&gt; Đặt đạo hàm bằng \(0\) chỉ đúng khi nghiệm nằm trong phần trong (interior) của miền khả thi; khi có ràng buộc, nghiệm tối ưu rất thường nằm ngay trên &lt;strong&gt;biên&lt;/strong&gt;, nơi hướng giảm \(-f&apos;(x^*)\) bị chặn bởi tường ràng buộc.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Tối ưu hóa giữ vai trò trung tâm trong khoa học dữ liệu. Dù bạn đang huấn luyện mạng nơ-ron, cực tiểu hóa sai số trong các mô hình hồi quy hay phân bổ tài nguyên trong hệ thống gợi ý, về bản chất bạn đều đang giải bài toán tìm nghiệm “tốt nhất” trong một tập hợp lớn các phương án khả dĩ. Để giải quyết hiệu quả các bài toán này, bạn cần nắm vững ngôn ngữ toán học nền tảng. Trong chương này, chúng ta sẽ ôn lại những kiến thức cốt lõi từ đại số tuyến tính, lý thuyết tập hợp, giải tích và xác suất, giúp bạn sẵn sàng làm việc với gradient, ma trận, ràng buộc và tính bất định trong các bài toán tối ưu hóa.&lt;/p&gt;

&lt;p&gt;Bài đọc tùy chọn ở cuối chương, &lt;a href=&quot;/contents/vi/chapter00/00_05_Applications_Recent/&quot;&gt;00-05 Ứng dụng và phát triển gần đây&lt;/a&gt;, kết nối các công cụ nền tảng này với vi phân tự động (autodiff), LoRA và mô hình khuếch tán (2022–2025).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-06 Bài tập trắc nghiệm - Khái niệm cơ bản</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_06_Quiz_Basic_Concepts/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_06_Quiz_Basic_Concepts</id>
   <content type="html">&lt;p&gt;Đọc hiểu lý thuyết trên giấy và tự tin giải đúng dưới áp lực chọn đáp án là hai nấc thang hoàn toàn khác nhau. Rất nhiều lỗi sai kinh điển khi bước sang Chương 01–03 — như nhầm lẫn giữa tập đóng với tập compact, quên kiểm tra định thức Hessian, hay nhầm giữa xác suất có điều kiện với hàm hợp lý — đều bắt nguồn từ những “điểm mù” nhỏ trong phần nền tảng.&lt;/p&gt;

&lt;p&gt;Trước khi làm bộ câu hỏi trắc nghiệm bên dưới, hãy dành vài phút quét lại bốn trụ cột cốt lõi và thử tự tay kiểm tra bài toán chẩn đoán nhanh dưới đây.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-vùng-kiểm-tra-trọng-tâm-của-chương-00&quot;&gt;Kiến thức cần nhớ: Bốn vùng kiểm tra trọng tâm của Chương 00&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra Giải tích:&lt;/strong&gt; Phân biệt được liên tục – liên tục đều – Lipschitz; tính nhanh gradient, đạo hàm theo hướng \(D_u f = \nabla f^T u\) và khai triển Taylor bậc 1–2.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra Đại số tuyến tính:&lt;/strong&gt; Nắm chắc độc lập tuyến tính, chuẩn vector, hạng ma trận, cách tính giá trị riêng qua vết/định thức và tiêu chuẩn ma trận xác định dương.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra Tập hợp &amp;amp; Tôpô:&lt;/strong&gt; Nhận diện đúng tập mở, tập đóng, biên, tập compact và điều kiện áp dụng định lý Weierstrass cho sự tồn tại nghiệm tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra Xác suất &amp;amp; Thống kê:&lt;/strong&gt; Sử dụng thành thạo quy tắc Bayes, phân biệt mật độ các phân phối chuẩn/Laplace/Bernoulli và thiết lập bài toán MLE qua log-likelihood.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bài-toán-chẩn-đoán-tổng-hợp-cả-4-trụ-cột-trong-4-bước&quot;&gt;Giải thích: Bài toán chẩn đoán tổng hợp cả 4 trụ cột trong 4 bước&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu có ràng buộc:
\(\min_{x_1, x_2} f(x_1, x_2) = \frac{1}{2}(x_1^2 + 4x_2^2) - 2x_1 - 8x_2 \quad \text{thỏa mãn} \quad x_1 + x_2 \le 4,\ x_1 \ge 0,\ x_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải tích (tìm điểm dừng):&lt;/strong&gt;
\(\nabla f(x) = \begin{pmatrix}x_1 - 2\\ 4x_2 - 8\end{pmatrix} = \begin{pmatrix}0\\ 0\end{pmatrix} \implies x^* = (2, 2)^T.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đại số tuyến tính (kiểm tra độ cong qua giá trị riêng):&lt;/strong&gt;
\(\nabla^2 f(x) = \begin{pmatrix}1 &amp;amp; 0\\ 0 &amp;amp; 4\end{pmatrix}.\)
Hai giá trị riêng là \(\lambda_1 = 1 &amp;gt; 0\) và \(\lambda_2 = 4 &amp;gt; 0\), nên Hessian xác định dương (\(H \succ 0\)), hàm lồi mạnh và \(x^* = (2, 2)^T\) là cực tiểu toàn cục không ràng buộc duy nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập hợp &amp;amp; Tôpô (kiểm tra tính khả thi):&lt;/strong&gt;
Miền ràng buộc là tam giác đóng và bị chặn (compact) có các đỉnh \((0,0), (4,0), (0,4)\). Kiểm tra \(x^* = (2, 2)^T\): \(2 \ge 0,\ 2 \ge 0\) và \(2 + 2 = 4 \le 4\) — điểm \(x^*\) nằm ngay trên &lt;strong&gt;biên&lt;/strong&gt; khả thi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Vì điểm cực tiểu toàn cục không ràng buộc đã nằm trong miền khả thi, nó lập tức là nghiệm tối ưu của bài toán có ràng buộc với giá trị \(f(2, 2) = \frac{1}{2}(4 + 16) - 4 - 16 = -10\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài tập trắc nghiệm này giúp bạn kiểm tra mức độ nắm vững các khái niệm nền tảng về giải tích, đại số tuyến tính, tập hợp và xác suất phục vụ cho tối ưu hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy điểm lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-giải-tích-cơ-bản&quot;&gt;🔢 &lt;strong&gt;Giải tích cơ bản&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Đạo hàm và đạo hàm riêng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Đạo hàm: \(f&apos;(x) = \lim_{h 	o 0} rac{f(x+h) - f(x)}{h}\)&lt;/li&gt;
  &lt;li&gt;Đạo hàm riêng: \(rac{\partial f}{\partial x_i}\) — đạo hàm theo \(x_i\) khi các biến còn lại được giữ cố định.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Gradient và đạo hàm theo hướng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Gradient: \(abla f = egin{pmatrix} rac{\partial f}{\partial x_1} \ dots \ rac{\partial f}{\partial x_n} \end{pmatrix}\) — vector chỉ theo hướng tăng nhanh nhất của hàm số.&lt;/li&gt;
  &lt;li&gt;Đạo hàm theo hướng: \(D_{\mathbf{u}}f = 
abla f \cdot \mathbf{u} = \|
abla f\| \cos 	heta\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Chuỗi Taylor:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bậc 1: \(f(\mathbf{x}) pprox f(\mathbf{x}_0) + 
abla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0)\)&lt;/li&gt;
  &lt;li&gt;Bậc 2: \(f(\mathbf{x}) pprox f(\mathbf{x}_0) + 
abla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0) + rac{1}{2} (\mathbf{x} - \mathbf{x}_0)^T 
abla^2 f(\mathbf{x}_0) (\mathbf{x} - \mathbf{x}_0)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-đại-số-tuyến-tính&quot;&gt;📐 &lt;strong&gt;Đại số tuyến tính&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vector và không gian vector:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Vector: bộ có thứ tự gồm các số thực \(\mathbf{v} = egin{pmatrix} v_1 \ dots \ v_n \end{pmatrix}\)&lt;/li&gt;
  &lt;li&gt;Không gian \(\mathbb{R}^n\): tập hợp mọi vector có \(n\) thành phần thực.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các phép toán vector:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Cộng vector: \(\mathbf{u} + \mathbf{v} = egin{pmatrix} u_1 + v_1 \ dots \ u_n + v_n \end{pmatrix}\)&lt;/li&gt;
  &lt;li&gt;Nhân vô hướng: \(c\mathbf{v} = egin{pmatrix} cv_1 \ dots \ cv_n \end{pmatrix}\)&lt;/li&gt;
  &lt;li&gt;Tích vô hướng: \(\mathbf{u} \cdot \mathbf{v} = \sum_{i=1}^n u_i v_i = \|\mathbf{u}\| \|\mathbf{v}\| \cos 	heta\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Chuẩn vector:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Chuẩn \(L_2\) (Euclid): \(\|\mathbf{x}\|_2 = \sqrt{\sum_{i=1}^n x_i^2}\)&lt;/li&gt;
  &lt;li&gt;Chuẩn \(L_1\) (Manhattan): \(\|\mathbf{x}\|_1 = \sum_{i=1}^n \lvert x_i 
vert\)&lt;/li&gt;
  &lt;li&gt;Chuẩn \(L_\infty\) (cực đại): \(\|\mathbf{x}\|_\infty = \max_i \lvert x_i 
vert\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ma trận:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Phép nhân ma trận: \((AB)_{ij} = \sum_{k} A_{ik} B_{kj}\)&lt;/li&gt;
  &lt;li&gt;Ma trận nghịch đảo: \(AA^{-1} = I\) (khi ma trận khả nghịch)&lt;/li&gt;
  &lt;li&gt;Định thức: \(\det(A)\) — đo hệ số thay đổi thể tích dưới phép biến đổi tuyến tính.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Giá trị riêng và vector riêng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(A\mathbf{v} = \lambda \mathbf{v}\) với \(\mathbf{v} 
eq \mathbf{0}\)&lt;/li&gt;
  &lt;li&gt;\(\lambda\): giá trị riêng (eigenvalue), \(\mathbf{v}\): vector riêng (eigenvector) tương ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-lý-thuyết-tập-hợp-và-giải-tích-thực&quot;&gt;📊 &lt;strong&gt;Lý thuyết tập hợp và giải tích thực&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Các khái niệm tôpô cơ bản:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tập mở: mọi điểm thuộc tập đều có một lân cận nằm hoàn toàn trong tập.&lt;/li&gt;
  &lt;li&gt;Tập đóng: chứa mọi điểm biên của nó.&lt;/li&gt;
  &lt;li&gt;Tập compact: vừa đóng vừa bị chặn trong \(\mathbb{R}^n\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tính liên tục:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm liên tục tại \(x_0\): \(\lim_{x 	o x_0} f(x) = f(x_0)\)&lt;/li&gt;
  &lt;li&gt;Liên tục đều: \(orall \epsilon &amp;gt; 0, \exists \delta &amp;gt; 0\) sao cho \(\lvert x-y 
vert &amp;lt; \delta \Rightarrow \lvert f(x)-f(y) 
vert &amp;lt; \epsilon\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-xác-suất-cơ-bản&quot;&gt;🎲 &lt;strong&gt;Xác suất cơ bản&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Khái niệm cơ bản:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Xác suất: \(P(A) \in [0,1]\), \(P(\Omega) = 1\)&lt;/li&gt;
  &lt;li&gt;Biến ngẫu nhiên: hàm ánh xạ từ không gian mẫu vào tập số thực.&lt;/li&gt;
  &lt;li&gt;Kỳ vọng: \(E[X] = \int x f(x) dx\) (liên tục) hoặc \(E[X] = \sum x P(X=x)\) (rời rạc).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Một số phân phối thông dụng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Phân phối chuẩn: \(X \sim N(\mu, \sigma^2)\)&lt;/li&gt;
  &lt;li&gt;Phân phối đều: \(X \sim U(a,b)\)&lt;/li&gt;
  &lt;li&gt;Phân phối Bernoulli: \(X \sim 	ext{Ber}(p)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Gợi ý:&lt;/strong&gt; Những khái niệm này tạo thành nền tảng trực tiếp cho các chương sau: gradient chỉ hướng tăng nhanh nhất, ma trận Hessian phản ánh độ cong, và chuỗi Taylor giúp xấp xỉ hàm mục tiêu cục bộ.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Bài tập trắc nghiệm: Khái niệm cơ bản&lt;/h2&gt;
        &lt;p&gt;Chọn đáp án đúng nhất cho mỗi câu hỏi. Bạn sẽ nhận được kết quả ngay sau khi hoàn thành.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Câu hỏi 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Câu hỏi 1: Đạo hàm cơ bản --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Câu 1: Đạo hàm của hàm số $$f(x) = x^3 + 2x^2 - 5x + 1$$ tại $$x = 1$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) $$4$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) $$2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) $$-1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) $$6$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$2$$&lt;/strong&gt;&lt;br /&gt;
                $$f&apos;(x) = 3x^2 + 4x - 5$$&lt;br /&gt;
                $$f&apos;(1) = 3(1)^2 + 4(1) - 5 = 3 + 4 - 5 = 2$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Đạo hàm riêng --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Cho $$f(x,y) = x^2y + 3xy^2$$. Đạo hàm riêng $$\frac{\partial f}{\partial x}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) $$2xy + 3y^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) $$x^2 + 6xy$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) $$2xy + 6xy$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) $$x^2 + 3y^2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$2xy + 3y^2$$&lt;/strong&gt;&lt;br /&gt;
                Khi tính đạo hàm riêng theo $$x$$, ta coi $$y$$ là hằng số:&lt;br /&gt;
                $$\frac{\partial f}{\partial x} = \frac{\partial}{\partial x}(x^2y + 3xy^2) = 2xy + 3y^2$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Gradient --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Gradient của hàm $$f(x,y) = x^2 + 2xy + y^2$$ tại điểm $$(1,1)$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 4 \\ 4 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 2 \\ 2 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 3 \\ 3 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 1 \\ 1 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\begin{pmatrix} 4 \\ 4 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                $$\frac{\partial f}{\partial x} = 2x + 2y$$, $$\frac{\partial f}{\partial y} = 2x + 2y$$&lt;br /&gt;
                Tại $$(1,1)$$: $$\nabla f(1,1) = \begin{pmatrix} 2(1) + 2(1) \\ 2(1) + 2(1) \end{pmatrix} = \begin{pmatrix} 4 \\ 4 \end{pmatrix}$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Đạo hàm theo hướng --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Cho gradient $$\nabla f = \begin{pmatrix} 3 \\ 4 \end{pmatrix}$$ và vector đơn vị $$\mathbf{u} = \begin{pmatrix} 0.6 \\ 0.8 \end{pmatrix}$$. Đạo hàm theo hướng $$D_{\mathbf{u}}f$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) $$4.8$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) $$3.2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) $$7$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$5$$&lt;/strong&gt;&lt;br /&gt;
                $$D_{\mathbf{u}}f = \nabla f \cdot \mathbf{u} = 3(0.6) + 4(0.8) = 1.8 + 3.2 = 5$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Hướng tăng nhanh nhất --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Hướng tăng nhanh nhất của hàm số luôn là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Hướng của vector gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Hướng ngược với vector gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Hướng vuông góc với vector gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Hướng của trục x&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Hướng của vector gradient&lt;/strong&gt;&lt;br /&gt;
                Gradient luôn chỉ theo hướng tăng nhanh nhất của hàm số. Đây là một tính chất cơ bản của gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Phép cộng vector --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Cho $$\mathbf{u} = \begin{pmatrix} 2 \\ -1 \\ 3 \end{pmatrix}$$ và $$\mathbf{v} = \begin{pmatrix} 1 \\ 4 \\ -2 \end{pmatrix}$$. Vector $$\mathbf{u} + \mathbf{v}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 3 \\ 3 \\ 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 1 \\ -5 \\ 5 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 2 \\ 4 \\ -6 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 3 \\ -3 \\ 1 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\begin{pmatrix} 3 \\ 3 \\ 1 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                $$\mathbf{u} + \mathbf{v} = \begin{pmatrix} 2+1 \\ -1+4 \\ 3+(-2) \end{pmatrix} = \begin{pmatrix} 3 \\ 3 \\ 1 \end{pmatrix}$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Tích vô hướng --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Tích vô hướng của $$\mathbf{a} = \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix}$$ và $$\mathbf{b} = \begin{pmatrix} 4 \\ 5 \\ 6 \end{pmatrix}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) $$32$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) $$14$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) $$18$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) $$24$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$32$$&lt;/strong&gt;&lt;br /&gt;
                $$\mathbf{a} \cdot \mathbf{b} = 1 \cdot 4 + 2 \cdot 5 + 3 \cdot 6 = 4 + 10 + 18 = 32$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Chuẩn Euclid --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Chuẩn Euclid của vector $$\mathbf{v} = \begin{pmatrix} 3 \\ 4 \end{pmatrix}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) $$5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) $$7$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) $$25$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) $$\sqrt{7}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$5$$&lt;/strong&gt;&lt;br /&gt;
                $$\|\mathbf{v}\|_2 = \sqrt{3^2 + 4^2} = \sqrt{9 + 16} = \sqrt{25} = 5$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Vector trực giao --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Hai vector $$\mathbf{u}$$ và $$\mathbf{v}$$ được gọi là trực giao khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) $$\mathbf{u} \cdot \mathbf{v} = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) $$\mathbf{u} \cdot \mathbf{v} = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) $$\|\mathbf{u}\| = \|\mathbf{v}\|$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) $$\mathbf{u} + \mathbf{v} = \mathbf{0}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\mathbf{u} \cdot \mathbf{v} = 0$$&lt;/strong&gt;&lt;br /&gt;
                Hai vector trực giao (vuông góc) khi và chỉ khi tích vô hướng của chúng bằng 0.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Phép nhân ma trận --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Tích của hai ma trận $$\begin{pmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{pmatrix} \begin{pmatrix} 2 &amp;amp; 0 \\ 1 &amp;amp; 3 \end{pmatrix}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 4 &amp;amp; 6 \\ 10 &amp;amp; 12 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 2 &amp;amp; 4 \\ 10 &amp;amp; 14 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 2 &amp;amp; 0 \\ 3 &amp;amp; 12 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 3 &amp;amp; 2 \\ 4 &amp;amp; 7 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\begin{pmatrix} 4 &amp;amp; 6 \\ 10 &amp;amp; 12 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                Phần tử $$(1,1)$$: $$1 \cdot 2 + 2 \cdot 1 = 4$$&lt;br /&gt;
                Phần tử $$(1,2)$$: $$1 \cdot 0 + 2 \cdot 3 = 6$$&lt;br /&gt;
                Phần tử $$(2,1)$$: $$3 \cdot 2 + 4 \cdot 1 = 10$$&lt;br /&gt;
                Phần tử $$(2,2)$$: $$3 \cdot 0 + 4 \cdot 3 = 12$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Ma trận đơn vị --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Ma trận đơn vị $$2 \times 2$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                Ma trận đơn vị có các phần tử trên đường chéo chính bằng 1 và các phần tử khác bằng 0.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Ma trận chuyển vị --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Chuyển vị của ma trận $$\begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 5 &amp;amp; 6 \end{pmatrix}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 1 &amp;amp; 4 \\ 2 &amp;amp; 5 \\ 3 &amp;amp; 6 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 6 &amp;amp; 5 &amp;amp; 4 \\ 3 &amp;amp; 2 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 4 &amp;amp; 1 \\ 5 &amp;amp; 2 \\ 6 &amp;amp; 3 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 5 &amp;amp; 6 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\begin{pmatrix} 1 &amp;amp; 4 \\ 2 &amp;amp; 5 \\ 3 &amp;amp; 6 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                Chuyển vị của ma trận được tạo bằng cách hoán đổi hàng và cột.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Định thức 2x2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Định thức của ma trận $$\begin{pmatrix} 3 &amp;amp; 1 \\ 2 &amp;amp; 4 \end{pmatrix}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) $$10$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) $$14$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) $$2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) $$12$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$10$$&lt;/strong&gt;&lt;br /&gt;
                $$\det\begin{pmatrix} 3 &amp;amp; 1 \\ 2 &amp;amp; 4 \end{pmatrix} = 3 \cdot 4 - 1 \cdot 2 = 12 - 2 = 10$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Độc lập tuyến tính --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Hai vector $$\mathbf{v}_1 = \begin{pmatrix} 1 \\ 2 \end{pmatrix}$$ và $$\mathbf{v}_2 = \begin{pmatrix} 2 \\ 4 \end{pmatrix}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Độc lập tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Phụ thuộc tuyến tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Trực giao&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Không thể xác định&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Phụ thuộc tuyến tính&lt;/strong&gt;&lt;br /&gt;
                $$\mathbf{v}_2 = 2\mathbf{v}_1$$, do đó hai vector này phụ thuộc tuyến tính.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Chuẩn Manhattan --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Chuẩn Manhattan (L1) của vector $$\mathbf{v} = \begin{pmatrix} -2 \\ 3 \\ -1 \end{pmatrix}$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) $$6$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) $$0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) $$4$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) $$\sqrt{14}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$6$$&lt;/strong&gt;&lt;br /&gt;
                $$\|\mathbf{v}\|_1 = |-2| + |3| + |-1| = 2 + 3 + 1 = 6$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Quy tắc dây chuyền --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Cho $$z = x^2 + y^2$$ với $$x = 2t$$ và $$y = 3t$$. Đạo hàm $$\frac{dz}{dt}$$ tại $$t = 1$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) $$26$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) $$13$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) $$10$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) $$5$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$26$$&lt;/strong&gt;&lt;br /&gt;
                $$\frac{dz}{dt} = \frac{\partial z}{\partial x}\frac{dx}{dt} + \frac{\partial z}{\partial y}\frac{dy}{dt} = 2x \cdot 2 + 2y \cdot 3$$&lt;br /&gt;
                Tại $$t = 1$$: $$x = 2, y = 3$$, nên $$\frac{dz}{dt} = 2(2)(2) + 2(3)(3) = 8 + 18 = 26$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Điểm tới hạn --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Điểm tới hạn của hàm số là điểm mà:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Gradient bằng vector không&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Hàm số đạt giá trị lớn nhất&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Hàm số đạt giá trị nhỏ nhất&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Hàm số không xác định&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Gradient bằng vector không&lt;/strong&gt;&lt;br /&gt;
                Điểm tới hạn là điểm mà gradient của hàm số bằng vector không, tức là $$\nabla f = \mathbf{0}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Ma trận nghịch đảo --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Ma trận $$\begin{pmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{pmatrix}$$ có nghịch đảo là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 0.5 &amp;amp; 0.5 \\ 0.5 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\begin{pmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                $$\det(A) = 2 \cdot 1 - 1 \cdot 1 = 1$$&lt;br /&gt;
                $$A^{-1} = \frac{1}{1}\begin{pmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{pmatrix} = \begin{pmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{pmatrix}$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Đường mức --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Gradient (khác 0) của hàm số tại một điểm luôn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Vuông góc với đường mức tại điểm đó&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Song song với đường mức tại điểm đó&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Tạo góc 45° với đường mức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Không có mối quan hệ với đường mức&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Vuông góc với đường mức tại điểm đó&lt;/strong&gt;&lt;br /&gt;
                Gradient luôn vuông góc với đường mức vì đường mức là tập hợp các điểm có cùng giá trị hàm số.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Ứng dụng trong tối ưu hóa --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Trong thuật toán gradient descent, chúng ta di chuyển theo hướng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Ngược với hướng gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Cùng hướng với gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Vuông góc với gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Hướng ngẫu nhiên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Ngược với hướng gradient&lt;/strong&gt;&lt;br /&gt;
                Gradient descent di chuyển theo hướng $$-\nabla f$$ để tìm điểm cực tiểu của hàm số.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 21: Tính toán đạo hàm bậc hai --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Đạo hàm bậc hai của hàm $$f(x) = 3x^4 - 2x^3 + x^2 - 5x + 1$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$36x^2 - 12x + 2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$12x^3 - 6x^2 + 2x - 5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$36x^2 - 12x + 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$12x^2 - 6x + 2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$36x^2 - 12x + 2$$&lt;/strong&gt;&lt;br /&gt;
                $$f&apos;(x) = 12x^3 - 6x^2 + 2x - 5$$&lt;br /&gt;
                $$f&apos;&apos;(x) = 36x^2 - 12x + 2$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Ứng dụng ma trận Hessian --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Cho $$f(x,y) = x^2 + 2xy + 3y^2$$. Ma trận Hessian tại điểm $$(1,1)$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 3 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 6 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 4 &amp;amp; 4 \\ 4 &amp;amp; 8 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\begin{pmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                $$\frac{\partial^2 f}{\partial x^2} = 2$$, $$\frac{\partial^2 f}{\partial y^2} = 6$$, $$\frac{\partial^2 f}{\partial x \partial y} = 2$$&lt;br /&gt;
                Ma trận Hessian không phụ thuộc vào điểm cụ thể trong trường hợp này.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Tính toán thực tế với vector --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Khoảng cách từ điểm $$A(1,2)$$ đến điểm $$B(4,6)$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$7$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$25$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$3$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$5$$&lt;/strong&gt;&lt;br /&gt;
                Khoảng cách = $$\sqrt{(4-1)^2 + (6-2)^2} = \sqrt{9 + 16} = \sqrt{25} = 5$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Ứng dụng eigenvalue --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Ma trận $$A = \begin{pmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{pmatrix}$$ có các giá trị riêng là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$\lambda_1 = 3, \lambda_2 = 2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$\lambda_1 = 3, \lambda_2 = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$\lambda_1 = 1, \lambda_2 = 5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) $$\lambda_1 = 0, \lambda_2 = 5$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\lambda_1 = 3, \lambda_2 = 2$$&lt;/strong&gt;&lt;br /&gt;
                Đối với ma trận tam giác trên, các giá trị riêng chính là các phần tử trên đường chéo chính.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Tối ưu hóa đơn giản --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Điểm cực tiểu của hàm $$f(x) = x^2 - 4x + 5$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$x = 2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$x = -2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$x = 4$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$x = 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$x = 2$$&lt;/strong&gt;&lt;br /&gt;
                $$f&apos;(x) = 2x - 4 = 0 \Rightarrow x = 2$$&lt;br /&gt;
                $$f&apos;&apos;(x) = 2 &amp;gt; 0$$, nên $$x = 2$$ là điểm cực tiểu.
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Câu trước&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Câu tiếp&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Kết quả bài tập&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #45a049);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: center;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
}

.options label:hover {
    border-color: #4CAF50;
    background-color: #f0f8f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    transform: scale(1.2);
}

.options label.selected {
    border-color: #4CAF50;
    background-color: #e8f5e8;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #e3f2fd;
    border-left: 4px solid #2196F3;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #1976D2;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #45a049;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #f0f8f0;
    border-radius: 8px;
    border: 2px solid #4CAF50;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #2E7D32;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng cho từng câu hỏi
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;a&apos;, q3: &apos;a&apos;, q4: &apos;a&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;a&apos;, q13: &apos;a&apos;, q14: &apos;b&apos;, q15: &apos;a&apos;,
    q16: &apos;a&apos;, q17: &apos;a&apos;, q18: &apos;a&apos;, q19: &apos;a&apos;, q20: &apos;a&apos;,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;
};

/**
 * Cập nhật thanh tiến trình và hiển thị câu hỏi hiện tại
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Câu hỏi ${currentQuestion}/${totalQuestions}`;
}

/**
 * Hiển thị câu hỏi theo số thứ tự
 */
function showQuestion(questionNum) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Cập nhật trạng thái nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Chuyển đến câu hỏi tiếp theo
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Quay lại câu hỏi trước
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Lưu đáp án của người dùng
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Cập nhật giao diện để hiển thị đáp án đã chọn
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Nộp bài và hiển thị kết quả
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Tính điểm và tạo báo cáo chi tiết
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Hiển thị giải thích cho tất cả câu hỏi
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Tạo báo cáo chi tiết
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Câu ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Đúng&apos; : &apos;Sai&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Đáp án của bạn: ${userAnswer || &apos;Chưa trả lời&apos;} | Đáp án đúng: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Hiển thị kết quả
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Điểm số: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Xuất sắc!&apos; : 
              scorePercentage &gt;= 60 ? &apos;👍 Khá tốt!&apos; : 
              scorePercentage &gt;= 40 ? &apos;📚 Cần ôn tập thêm&apos; : &apos;💪 Hãy cố gắng hơn!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Khởi động lại bài tập
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn kết quả và hiển thị lại điều hướng
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Xóa tất cả lựa chọn
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>00-04 Xác Suất và Thống Kê</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_04_Probability_and_Statistics/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_04_Probability_and_Statistics</id>
   <content type="html">&lt;p&gt;Trong thế giới lý tưởng của sách giáo khoa cổ điển, mọi hệ số trong hàm mục tiêu và ràng buộc đều biết chính xác tuyệt đối. Nhưng trong khoa học dữ liệu và kỹ thuật hiện đại, dữ liệu luôn kèm nhiễu đo đạc, nhu cầu thị trường biến động ngẫu nhiên và ta chỉ quan sát được một mẫu hữu hạn. Lúc ấy, &lt;strong&gt;xác suất và thống kê&lt;/strong&gt; bước vào, biến bài toán học từ dữ liệu thành một bài toán tối ưu hóa trên hàm kỳ vọng hoặc hàm hợp lý.&lt;/p&gt;

&lt;p&gt;Phần 00-04 mở ra chiếc cầu nối giữa mô hình xác suất (như phân phối Gauss, Laplace, Bernoulli) với các hàm mất mát quen thuộc trong tối ưu hóa lồi (MSE, MAE, Cross-Entropy, Ridge, Lasso).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-xác-suất-gặp-tối-ưu-hóa-ở-đâu&quot;&gt;Kiến thức cần nhớ: Xác suất gặp Tối ưu hóa ở đâu?&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa rủi ro kỳ vọng và rủi ro thực nghiệm (ERM):&lt;/strong&gt; Ta muốn cực tiểu hóa tổn thất kỳ vọng \(\mathbb{E}[\ell(x, \xi)]\) nhưng chỉ có \(N\) mẫu dữ liệu, nên thay bằng trung bình mẫu \(\frac{1}{N}\sum_{i=1}^N \ell(x, \xi_i)\) — bài toán tối ưu hóa tổng hữu hạn kinh điển.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng hợp lý tối đa (MLE) và hậu nghiệm tối đa (MAP):&lt;/strong&gt; Cực đại hóa xác suất quan sát được dữ liệu tương đương cực tiểu hóa &lt;strong&gt;âm log-hợp lý&lt;/strong&gt; (negative log-likelihood). Thêm phân phối tiên nghiệm (prior) sinh ra đúng số hạng điều chuẩn (regularization) trong tối ưu hóa!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Jensen và tính lồi:&lt;/strong&gt; Cho hàm lồi \(f\), \(f(\mathbb{E}[X]) \le \mathbb{E}[f(X)]\). Đây là cầu nối vàng giữa xác suất và tối ưu hóa lồi, xuất hiện trong phân kỳ KL, thuật toán EM và suy luận biến phân.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa ngẫu nhiên (Stochastic Optimization):&lt;/strong&gt; Khi \(N\) lên tới hàng triệu, tính gradient đầy đủ quá tốn kém; ta ước lượng gradient không chệch từ một mini-batch ngẫu nhiên (SGD).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tại-sao-chọn-hàm-mất-mát-ell_2-ra-trung-bình-còn-ell_1-ra-trung-vị&quot;&gt;Giải thích: Tại sao chọn hàm mất mát \(\ell_2\) ra Trung bình, còn \(\ell_1\) ra Trung vị?&lt;/h3&gt;

&lt;p&gt;Giả sử bạn thu thập \(4\) phép đo nhiệt độ có một giá trị nhiễu mạnh: \(y = (2, 4, 5, 9)\), và muốn chọn một con số đại diện \(\theta\) tốt nhất:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa sai số bình phương (\(\ell_2\)):&lt;/strong&gt;
\(L_2(\theta) = \frac{1}{4}\left[(2-\theta)^2 + (4-\theta)^2 + (5-\theta)^2 + (9-\theta)^2\right].\)
Lấy đạo hàm theo \(\theta\) và cho bằng \(0\):
\(L_2&apos;(\theta) = -\frac{1}{2}\left[(2-\theta) + (4-\theta) + (5-\theta) + (9-\theta)\right] = 0 \implies 4\theta = 20 \implies \theta_2^* = 5.\)
Nghiệm tối ưu chính là &lt;strong&gt;trung bình cộng&lt;/strong&gt; (bị điểm ngoại lai \(9\) kéo mạnh lên \(5\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa sai số tuyệt đối (\(\ell_1\)):&lt;/strong&gt;
\(L_1(\theta) = \frac{1}{4}\left(|2-\theta| + |4-\theta| + |5-\theta| + |9-\theta|\right).\)
Thử tính trực tiếp:
    &lt;ul&gt;
      &lt;li&gt;Tại \(\theta = 4\): \(L_1(4) = \frac{1}{4}(2 + 0 + 1 + 5) = 2\).&lt;/li&gt;
      &lt;li&gt;Tại \(\theta = 4.5\): \(L_1(4.5) = \frac{1}{4}(2.5 + 0.5 + 0.5 + 4.5) = 2\).&lt;/li&gt;
      &lt;li&gt;Tại \(\theta = 5\): \(L_1(5) = \frac{1}{4}(3 + 1 + 0 + 4) = 2\).&lt;/li&gt;
      &lt;li&gt;Tại \(\theta = 6\): \(L_1(6) = \frac{1}{4}(4 + 2 + 1 + 3) = 2.5 &amp;gt; 2\).
Mọi điểm &lt;strong&gt;trung vị&lt;/strong&gt; \(\theta_1^* \in [4, 5]\) đều đạt cực tiểu \(2\), và dù điểm ngoại lai \(9\) tăng lên \(900\), tập nghiệm tối ưu \([4, 5]\) vẫn hoàn toàn bất biến!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;xác-suất-và-thống-kê-cho-tối-ưu-hóa-lồi&quot;&gt;Xác suất và thống kê cho tối ưu hóa lồi&lt;/h2&gt;

&lt;p&gt;Xác suất và thống kê là nền tảng thiết yếu để hiểu nhiều bài toán tối ưu hóa, đặc biệt trong học máy và khoa học dữ liệu. Phần này giới thiệu các khái niệm xác suất cốt lõi thường xuất hiện trong tối ưu hóa lồi, từ ước lượng hợp lý tối đa đến tối ưu hóa Bayes.&lt;/p&gt;

&lt;h3 id=&quot;vì-sao-xác-suất-quan-trọng-trong-tối-ưu-hóa&quot;&gt;Vì sao xác suất quan trọng trong tối ưu hóa&lt;/h3&gt;

&lt;p&gt;Nhiều bài toán tối ưu hóa bắt nguồn trực tiếp từ mô hình hóa thống kê:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng hợp lý tối đa (MLE)&lt;/strong&gt;: tìm bộ tham số làm cực đại hàm hợp lý (likelihood) của dữ liệu quan sát.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa Bayes&lt;/strong&gt;: sử dụng mô hình xác suất để định hướng quá trình tìm kiếm nghiệm tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa ngẫu nhiên&lt;/strong&gt;: xử lý tính bất định và nhiễu ngẫu nhiên trong hàm mục tiêu hoặc ràng buộc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều chuẩn (Regularization)&lt;/strong&gt;: bổ sung phân phối tiên nghiệm (prior) nhằm hạn chế quá khớp (overfitting).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa rủi ro&lt;/strong&gt;: cực tiểu hóa giá trị kỳ vọng của hàm mất mát trên một phân phối xác suất.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;các-chủ-đề-chính&quot;&gt;Các chủ đề chính&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết xác suất cơ bản&lt;/strong&gt;: không gian mẫu, biến cố và các tiên đề xác suất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các phân phối xác suất thông dụng&lt;/strong&gt;: phân phối chuẩn, phân phối mũ và các phân phối quan trọng khác.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kỳ vọng và phương sai&lt;/strong&gt;: tính toán và tối ưu hóa giá trị kỳ vọng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý Bayes&lt;/strong&gt;: cơ sở của suy luận và tối ưu hóa Bayes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng thống kê&lt;/strong&gt;: kết nối lý thuyết xác suất với bài toán tối ưu hóa.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;kết-nối-với-tối-ưu-hóa-lồi&quot;&gt;Kết nối với tối ưu hóa lồi&lt;/h3&gt;

&lt;p&gt;Nắm vững xác suất giúp bạn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xây dựng mô hình bài toán&lt;/strong&gt;: chuyển đổi tính bất định trong thực tế thành bài toán tối ưu hóa toán học.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn hàm mục tiêu&lt;/strong&gt;: chọn hàm mất mát phù hợp dựa trên các giả định xác suất về dữ liệu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải kết quả&lt;/strong&gt;: hiểu rõ khoảng tin cậy và ý nghĩa thống kê của nghiệm tìm được.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xử lý nhiễu&lt;/strong&gt;: ứng phó hiệu quả với sai số đo lường và các quá trình ngẫu nhiên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thiết kế thuật toán&lt;/strong&gt;: xây dựng các phương pháp tối ưu hóa ổn định trước tính bất định.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nền tảng này sẽ được sử dụng trực tiếp ở các chương sau khi ta phân tích cách các mô hình xác suất dẫn đến bài toán tối ưu hóa lồi trong học máy, thống kê và kỹ thuật.&lt;/p&gt;

&lt;div style=&quot;background: #e8f4fd; padding: 15px; border-left: 4px solid #2196F3; margin: 20px 0;&quot;&gt;
&lt;strong&gt;💡 Lộ trình học:&lt;/strong&gt; Bắt đầu từ các khái niệm xác suất cơ bản, sau đó tìm hiểu cách chúng gắn với tối ưu hóa qua ước lượng hợp lý tối đa và phương pháp Bayes. Mỗi bài học kế tiếp giúp làm rõ cách tính bất định và yếu tố ngẫu nhiên hình thành nên các bài toán tối ưu hóa.
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>00-04-03 Likelihood và Ước Lượng Hợp Lý Tối Đa (MLE)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_04_03_Likelihood_and_Maximum_Likelihood_Estimation/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_04_03_Likelihood_and_Maximum_Likelihood_Estimation</id>
   <content type="html">&lt;p&gt;Xác suất trả lời câu hỏi xuôi: &lt;em&gt;“Biết đồng xu có tỷ lệ ngửa \(p = 0.7\), khả năng tung 10 lần ra 7 mặt ngửa là bao nhiêu?”&lt;/em&gt; Thống kê và học máy lại phải đi ngược lại: &lt;em&gt;“Ta vừa tung 10 lần thấy 7 mặt ngửa — vậy giá trị \(p\) nào giải thích dữ liệu này hợp lý nhất?”&lt;/em&gt; &lt;strong&gt;Ước lượng hợp lý tối đa (MLE)&lt;/strong&gt; do Ronald Fisher hệ thống hóa từ thập niên 1920 biến đúng câu hỏi suy luận ngược ấy thành một bài toán tối ưu hóa cụ thể.&lt;/p&gt;

&lt;p&gt;Điều tuyệt vời là khi lấy logarit hàm hợp lý, hàng loạt bài toán MLE kinh điển trở thành bài toán cực đại hóa hàm lõm (hay cực tiểu hóa hàm lồi), cho phép giải chính xác bằng giải tích hoặc thuật toán lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cấu-trúc-tối-ưu-hóa-của-mle&quot;&gt;Kiến thức cần nhớ: Cấu trúc tối ưu hóa của MLE&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm hợp lý (\(L(\theta \mid x)\)):&lt;/strong&gt; Giữ cố định dữ liệu đã quan sát \(x\) và coi xác suất (hoặc mật độ) là một hàm số theo tham số \(\theta\) cần tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến đổi Log-Likelihood (\(\ell(\theta) = \log L(\theta)\)):&lt;/strong&gt; Vì hàm \(\log\) tăng nghiêm ngặt, \(\arg\max_\theta L(\theta) = \arg\max_\theta \ell(\theta)\). Phép biến đổi này vừa tránh tràn số dưới (underflow) khi nhân hàng nghìn xác suất nhỏ, vừa biến tích thành tổng dễ lấy đạo hàm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bậc nhất (Score = 0) và bậc hai (Thông tin Fisher):&lt;/strong&gt; Giải \(\nabla_\theta \ell(\theta) = 0\) tìm ứng viên tối ưu; kiểm tra ma trận Hessian \(\nabla^2_\theta \ell(\theta) \prec 0\) xác nhận điểm cực đại (thậm chí cực đại toàn cục nếu \(\ell(\theta)\) lõm).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mở rộng sang MAP và điều chuẩn:&lt;/strong&gt; Nhân thêm phân phối tiên nghiệm \(p(\theta)\) trước khi lấy log sẽ cộng thêm số hạng \(-\log p(\theta)\) vào hàm mất mát — biến MLE thành tối ưu hóa có điều chuẩn (như Ridge khi tiên nghiệm là Gauss).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-mle-cho-bài-toán-tung-đồng-xu-10-lần-ra-7-mặt-ngửa&quot;&gt;Giải thích: Tính tay MLE cho bài toán tung đồng xu 10 lần ra 7 mặt ngửa&lt;/h3&gt;

&lt;p&gt;Giả sử tung một đồng xu độc lập \(n = 10\) lần và quan sát được \(k = 7\) mặt ngửa, \(3\) mặt sấp. Ta tìm tham số \(p \in (0, 1)\) hợp lý nhất:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Viết hàm hợp lý và log-hợp lý:&lt;/strong&gt;
\(L(p) = p^7 (1 - p)^3 \implies \ell(p) = \ln L(p) = 7\ln p + 3\ln(1 - p).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm dừng (đạo hàm bậc nhất bằng 0):&lt;/strong&gt;
\(\ell&apos;(p) = \frac{7}{p} - \frac{3}{1 - p} = 0 \implies 7(1 - p) = 3p \implies 7 = 10p \implies \hat p = 0.7.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra tính lõm bằng đạo hàm bậc hai:&lt;/strong&gt;
\(\ell&apos;&apos;(p) = -\frac{7}{p^2} - \frac{3}{(1 - p)^2} &amp;lt; 0 \quad \forall p \in (0, 1).\)
Tại \(\hat p = 0.7\), ta có \(\ell&apos;&apos;(0.7) = -\frac{7}{0.49} - \frac{3}{0.09} \approx -14.29 - 33.33 = -47.62 &amp;lt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận tối ưu hóa:&lt;/strong&gt; Vì \(\ell&apos;&apos;(p) &amp;lt; 0\) trên toàn khoảng \((0, 1)\), hàm \(\ell(p)\) &lt;strong&gt;lõm chặt&lt;/strong&gt;, nên \(\hat p = 0.7\) không chỉ là cực đại địa phương mà chắc chắn là &lt;strong&gt;cực đại toàn cục duy nhất&lt;/strong&gt; của bài toán MLE!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;likelihood-và-ước-lượng-hợp-lý-tối-đa&quot;&gt;Likelihood và ước lượng hợp lý tối đa&lt;/h2&gt;

&lt;p&gt;Trong xác suất thống kê, &lt;strong&gt;hàm hợp lý (likelihood)&lt;/strong&gt; đo mức độ phù hợp của một mô hình hay một bộ tham số với dữ liệu đã quan sát. Khi giữ cố định dữ liệu và xem biểu thức xác suất như một hàm theo tham số, ta thu được hàm hợp lý; lưu ý rằng đây không phải là một phân phối xác suất theo tham số.&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa-hàm-hợp-lý-likelihood&quot;&gt;Định nghĩa hàm hợp lý (Likelihood)&lt;/h3&gt;

&lt;p&gt;Hàm hợp lý của tham số \(heta\) ứng với dữ liệu quan sát \(x\) được định nghĩa bằng xác suất (hoặc mật độ xác suất) quan sát được dữ liệu \(x\) khi tham số nhận giá trị \(heta\). Hàm này thường ký hiệu là \(L(	heta \mid x)\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Công thức:&lt;/strong&gt;
\(L(	heta \mid x) = P(x \mid 	heta)\)&lt;/p&gt;

&lt;p&gt;Trong đó, \(P(x \mid 	heta)\) là xác suất (hoặc mật độ) của dữ liệu \(x\) khi tham số \(heta\) đã cho trước.&lt;/p&gt;

&lt;h3 id=&quot;điểm-khác-biệt-với-xác-suất&quot;&gt;Điểm khác biệt với xác suất&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xác suất&lt;/strong&gt; mô tả khả năng xảy ra của các kết quả ngẫu nhiên trong tương lai khi tham số của phân phối đã biết.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm hợp lý (likelihood)&lt;/strong&gt; ngược lại: dữ liệu đã được quan sát và giữ cố định, còn ta thay đổi tham số để đánh giá mức độ phù hợp của từng giá trị tham số với dữ liệu đó.&lt;/li&gt;
&lt;/ul&gt;

&lt;div style=&quot;background: #fff3cd; padding: 15px; border-left: 4px solid #ffc107; margin: 20px 0;&quot;&gt;
&lt;strong&gt;⚠️ Lưu ý quan trọng:&lt;/strong&gt; Hàm hợp lý không phải là phân phối xác suất của tham số θ, vì tổng hoặc tích phân của nó theo θ không nhất thiết bằng 1.
&lt;/div&gt;

&lt;h3 id=&quot;ví-dụ-minh-họa-tung-đồng-xu&quot;&gt;Ví dụ minh họa: Tung đồng xu&lt;/h3&gt;

&lt;p&gt;Giả sử bạn tung một đồng xu 5 lần và quan sát được 3 lần “mặt sấp” (S) cùng 2 lần “mặt ngửa” (N). Gọi \(p\) là xác suất xuất hiện mặt sấp.&lt;/p&gt;

&lt;p&gt;Hàm hợp lý của \(p\) ứng với dữ liệu (3 sấp, 2 ngửa) là:&lt;/p&gt;

\[L(p \mid 	ext{dữ liệu}) = P(	ext{3 sấp, 2 ngửa} \mid p) = inom{5}{3} p^3 (1-p)^2\]

&lt;p&gt;Trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(inom{5}{3}\) là hệ số nhị thức (số cách chọn 3 lần ra mặt sấp trong 5 lần tung).&lt;/li&gt;
  &lt;li&gt;\(p^3\) là xác suất cho 3 lần mặt sấp.&lt;/li&gt;
  &lt;li&gt;\((1-p)^2\) là xác suất cho 2 lần mặt ngửa.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Thử tính với các giá trị \(p\) khác nhau:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Với \(p = 0.6\):
\(L(0.6 \mid 	ext{dữ liệu}) = inom{5}{3} (0.6)^3 (0.4)^2 = 10 	imes 0.216 	imes 0.16 pprox 0.3456\)&lt;/p&gt;

&lt;p&gt;Với \(p = 0.5\):
\(L(0.5 \mid 	ext{dữ liệu}) = inom{5}{3} (0.5)^3 (0.5)^2 = 10 	imes 0.125 	imes 0.25 pprox 0.3125\)&lt;/p&gt;

&lt;p&gt;Giá trị hàm hợp lý tại \(p = 0.6\) cao hơn tại \(p = 0.5\), cho thấy \(p = 0.6\) phù hợp với dữ liệu quan sát hơn so với \(p = 0.5\).&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-tương-tác-tung-đồng-xu&quot;&gt;Ví dụ tương tác: Tung đồng xu&lt;/h3&gt;

&lt;div id=&quot;coin-flip-example&quot; style=&quot;border: 1px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 8px;&quot;&gt;
    &lt;h4&gt;Thí nghiệm tung đồng xu&lt;/h4&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;label for=&quot;p-slider&quot;&gt;Xác suất mặt sấp (p): &lt;span id=&quot;p-value&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;p-slider&quot; min=&quot;0.01&quot; max=&quot;0.99&quot; step=&quot;0.01&quot; value=&quot;0.5&quot; style=&quot;width: 300px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;label for=&quot;heads-input&quot;&gt;Số lần sấp: &lt;/label&gt;
        &lt;input type=&quot;number&quot; id=&quot;heads-input&quot; value=&quot;3&quot; min=&quot;0&quot; max=&quot;20&quot; style=&quot;width: 60px;&quot; /&gt;
        
        &lt;label for=&quot;tails-input&quot; style=&quot;margin-left: 20px;&quot;&gt;Số lần ngửa: &lt;/label&gt;
        &lt;input type=&quot;number&quot; id=&quot;tails-input&quot; value=&quot;2&quot; min=&quot;0&quot; max=&quot;20&quot; style=&quot;width: 60px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;canvas id=&quot;likelihood-plot&quot; width=&quot;600&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
    &lt;/div&gt;
    
    &lt;div id=&quot;likelihood-result&quot; style=&quot;background: #f8f9fa; padding: 10px; border-radius: 4px; margin: 10px 0;&quot;&gt;
        &lt;strong&gt;Likelihood hiện tại:&lt;/strong&gt; &lt;span id=&quot;current-likelihood&quot;&gt;0.3125&lt;/span&gt;&lt;br /&gt;
        &lt;strong&gt;Log-likelihood:&lt;/strong&gt; &lt;span id=&quot;current-log-likelihood&quot;&gt;-1.16&lt;/span&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    const pSlider = document.getElementById(&apos;p-slider&apos;);
    const pValue = document.getElementById(&apos;p-value&apos;);
    const headsInput = document.getElementById(&apos;heads-input&apos;);
    const tailsInput = document.getElementById(&apos;tails-input&apos;);
    const canvas = document.getElementById(&apos;likelihood-plot&apos;);
    const ctx = canvas.getContext(&apos;2d&apos;);
    const likelihoodResult = document.getElementById(&apos;current-likelihood&apos;);
    const logLikelihoodResult = document.getElementById(&apos;current-log-likelihood&apos;);
    
    function binomialCoeff(n, k) {
        if (k &gt; n) return 0;
        if (k === 0 || k === n) return 1;
        
        let result = 1;
        for (let i = 0; i &lt; k; i++) {
            result = result * (n - i) / (i + 1);
        }
        return result;
    }
    
    function likelihood(p, heads, tails) {
        const n = heads + tails;
        const coeff = binomialCoeff(n, heads);
        return coeff * Math.pow(p, heads) * Math.pow(1 - p, tails);
    }
    
    function logLikelihood(p, heads, tails) {
        const n = heads + tails;
        const logCoeff = Math.log(binomialCoeff(n, heads));
        return logCoeff + heads * Math.log(p) + tails * Math.log(1 - p);
    }
    
    function plotLikelihood() {
        const heads = parseInt(headsInput.value);
        const tails = parseInt(tailsInput.value);
        const currentP = parseFloat(pSlider.value);
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Vẽ trục
        ctx.strokeStyle = &apos;#333&apos;;
        ctx.lineWidth = 1;
        ctx.beginPath();
        ctx.moveTo(50, 250);
        ctx.lineTo(550, 250);
        ctx.moveTo(50, 250);
        ctx.lineTo(50, 50);
        ctx.stroke();
        
        // Nhãn trục
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;p (xác suất mặt sấp)&apos;, 250, 280);
        ctx.save();
        ctx.translate(20, 150);
        ctx.rotate(-Math.PI/2);
        ctx.fillText(&apos;Likelihood&apos;, 0, 0);
        ctx.restore();
        
        // Vẽ đường likelihood
        ctx.strokeStyle = &apos;#2196F3&apos;;
        ctx.lineWidth = 2;
        ctx.beginPath();
        
        let maxLikelihood = 0;
        const points = [];
        
        for (let i = 0; i &lt;= 500; i++) {
            const p = 0.01 + (i / 500) * 0.98;
            const l = likelihood(p, heads, tails);
            points.push({p: p, l: l});
            maxLikelihood = Math.max(maxLikelihood, l);
        }
        
        for (let i = 0; i &lt; points.length; i++) {
            const x = 50 + (points[i].p - 0.01) / 0.98 * 500;
            const y = 250 - (points[i].l / maxLikelihood) * 200;
            
            if (i === 0) {
                ctx.moveTo(x, y);
            } else {
                ctx.lineTo(x, y);
            }
        }
        ctx.stroke();
        
        // Vẽ điểm hiện tại
        const currentLikelihood = likelihood(currentP, heads, tails);
        const currentX = 50 + (currentP - 0.01) / 0.98 * 500;
        const currentY = 250 - (currentLikelihood / maxLikelihood) * 200;
        
        ctx.fillStyle = &apos;#f44336&apos;;
        ctx.beginPath();
        ctx.arc(currentX, currentY, 5, 0, 2 * Math.PI);
        ctx.fill();
        
        // Cập nhật kết quả
        likelihoodResult.textContent = currentLikelihood.toFixed(6);
        logLikelihoodResult.textContent = logLikelihood(currentP, heads, tails).toFixed(4);
        
        // Vẽ các tick marks
        ctx.fillStyle = &apos;#666&apos;;
        ctx.font = &apos;10px Arial&apos;;
        for (let i = 0; i &lt;= 10; i++) {
            const p = i / 10;
            const x = 50 + (p - 0.01) / 0.98 * 500;
            ctx.fillText(p.toFixed(1), x - 10, 265);
        }
    }
    
    function updateDisplay() {
        pValue.textContent = pSlider.value;
        plotLikelihood();
    }
    
    pSlider.addEventListener(&apos;input&apos;, updateDisplay);
    headsInput.addEventListener(&apos;input&apos;, plotLikelihood);
    tailsInput.addEventListener(&apos;input&apos;, plotLikelihood);
    
    // Khởi tạo
    updateDisplay();
});
&lt;/script&gt;

&lt;h3 id=&quot;ước-lượng-hợp-lý-tối-đa-mle&quot;&gt;Ước lượng hợp lý tối đa (MLE)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ước lượng hợp lý tối đa (Maximum Likelihood Estimation — MLE)&lt;/strong&gt; là phương pháp tìm giá trị tham số \(heta\) làm cực đại hàm hợp lý \(L(	heta \mid x)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Công thức MLE:&lt;/strong&gt;
\(\hat{	heta}_{MLE} = rg\max_{	heta} L(	heta \mid x)\)&lt;/p&gt;

&lt;p&gt;Trong thực hành, vì hàm logarit đơn điệu tăng, ta thường cực đại hóa hàm log-likelihood để chuyển tích thành tổng và tránh tràn số:
\(\hat{	heta}_{MLE} = rg\max_{	heta} \log L(	heta \mid x)\)&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-mle-phân-phối-chuẩn&quot;&gt;Ví dụ MLE: Phân phối chuẩn&lt;/h3&gt;

&lt;p&gt;Giả sử ta có \(n\) quan sát độc lập và cùng phân phối \(x_1, x_2, \ldots, x_n\) từ phân phối chuẩn \(N(\mu, \sigma^2)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm hợp lý:&lt;/strong&gt;
\(L(\mu, \sigma^2 \mid x_1, \ldots, x_n) = \prod_{i=1}^{n} rac{1}{\sqrt{2\pi\sigma^2}} \exp\left(-rac{(x_i - \mu)^2}{2\sigma^2}
ight)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log-likelihood:&lt;/strong&gt;
\(\ell(\mu, \sigma^2) = -rac{n}{2}\log(2\pi) - rac{n}{2}\log(\sigma^2) - rac{1}{2\sigma^2}\sum_{i=1}^{n}(x_i - \mu)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tìm ước lượng MLE:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lấy đạo hàm riêng theo \(\mu\) và cho bằng 0:
\(rac{\partial \ell}{\partial \mu} = rac{1}{\sigma^2}\sum_{i=1}^{n}(x_i - \mu) = 0\)&lt;/p&gt;

&lt;p&gt;Giải phương trình này, ta thu được trung bình mẫu: \(\hat{\mu}_{MLE} = rac{1}{n}\sum_{i=1}^{n} x_i = ar{x}\)&lt;/p&gt;

&lt;p&gt;Tương tự, lấy đạo hàm theo \(\sigma^2\) và cho bằng 0 ta thu được:
\(\hat{\sigma^2}_{MLE} = rac{1}{n}\sum_{i=1}^{n}(x_i - ar{x})^2\)&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-tương-tác-mle-cho-phân-phối-chuẩn&quot;&gt;Ví dụ tương tác: MLE cho phân phối chuẩn&lt;/h3&gt;

&lt;div id=&quot;normal-mle-example&quot; style=&quot;border: 1px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 8px;&quot;&gt;
    &lt;h4&gt;MLE cho phân phối chuẩn&lt;/h4&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;button id=&quot;generate-data&quot; style=&quot;background: #4CAF50; color: white; padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer;&quot;&gt;Tạo dữ liệu mới&lt;/button&gt;
        &lt;span style=&quot;margin-left: 20px;&quot;&gt;Số mẫu: &lt;/span&gt;
        &lt;input type=&quot;number&quot; id=&quot;sample-size&quot; value=&quot;50&quot; min=&quot;10&quot; max=&quot;200&quot; style=&quot;width: 60px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;label for=&quot;mu-guess&quot;&gt;Ước lượng μ: &lt;span id=&quot;mu-guess-value&quot;&gt;0&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;mu-guess&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 300px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;label for=&quot;sigma-guess&quot;&gt;Ước lượng σ: &lt;span id=&quot;sigma-guess-value&quot;&gt;1&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;sigma-guess&quot; min=&quot;0.1&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1&quot; style=&quot;width: 300px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;canvas id=&quot;normal-plot&quot; width=&quot;600&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
    &lt;/div&gt;
    
    &lt;div id=&quot;mle-results&quot; style=&quot;background: #f8f9fa; padding: 10px; border-radius: 4px; margin: 10px 0;&quot;&gt;
        &lt;div&gt;&lt;strong&gt;Dữ liệu thực:&lt;/strong&gt; μ = &lt;span id=&quot;true-mu&quot;&gt;1.0&lt;/span&gt;, σ = &lt;span id=&quot;true-sigma&quot;&gt;1.5&lt;/span&gt;&lt;/div&gt;
        &lt;div&gt;&lt;strong&gt;Ước lượng MLE:&lt;/strong&gt; μ̂ = &lt;span id=&quot;mle-mu&quot;&gt;0.95&lt;/span&gt;, σ̂ = &lt;span id=&quot;mle-sigma&quot;&gt;1.48&lt;/span&gt;&lt;/div&gt;
        &lt;div&gt;&lt;strong&gt;Ước lượng hiện tại:&lt;/strong&gt; μ = &lt;span id=&quot;current-mu&quot;&gt;0&lt;/span&gt;, σ = &lt;span id=&quot;current-sigma&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
        &lt;div&gt;&lt;strong&gt;Log-likelihood hiện tại:&lt;/strong&gt; &lt;span id=&quot;current-ll&quot;&gt;-75.2&lt;/span&gt;&lt;/div&gt;
        &lt;div&gt;&lt;strong&gt;Log-likelihood tối đa:&lt;/strong&gt; &lt;span id=&quot;max-ll&quot;&gt;-72.1&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    const generateBtn = document.getElementById(&apos;generate-data&apos;);
    const sampleSizeInput = document.getElementById(&apos;sample-size&apos;);
    const muGuess = document.getElementById(&apos;mu-guess&apos;);
    const sigmaGuess = document.getElementById(&apos;sigma-guess&apos;);
    const muGuessValue = document.getElementById(&apos;mu-guess-value&apos;);
    const sigmaGuessValue = document.getElementById(&apos;sigma-guess-value&apos;);
    const canvas = document.getElementById(&apos;normal-plot&apos;);
    const ctx = canvas.getContext(&apos;2d&apos;);
    
    let data = [];
    let trueMu = 1.0;
    let trueSigma = 1.5;
    
    function normalRandom(mu, sigma) {
        let u = 0, v = 0;
        while(u === 0) u = Math.random();
        while(v === 0) v = Math.random();
        return Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v) * sigma + mu;
    }
    
    function generateData() {
        const n = parseInt(sampleSizeInput.value);
        trueMu = (Math.random() - 0.5) * 4; // -2 to 2
        trueSigma = 0.5 + Math.random() * 2; // 0.5 to 2.5
        
        data = [];
        for (let i = 0; i &lt; n; i++) {
            data.push(normalRandom(trueMu, trueSigma));
        }
        
        // Tính MLE
        const mleMu = data.reduce((sum, x) =&gt; sum + x, 0) / data.length;
        const mleSigma = Math.sqrt(data.reduce((sum, x) =&gt; sum + (x - mleMu) ** 2, 0) / data.length);
        
        document.getElementById(&apos;true-mu&apos;).textContent = trueMu.toFixed(2);
        document.getElementById(&apos;true-sigma&apos;).textContent = trueSigma.toFixed(2);
        document.getElementById(&apos;mle-mu&apos;).textContent = mleMu.toFixed(2);
        document.getElementById(&apos;mle-sigma&apos;).textContent = mleSigma.toFixed(2);
        
        plotData();
    }
    
    function logLikelihood(mu, sigma, data) {
        const n = data.length;
        const sumSquares = data.reduce((sum, x) =&gt; sum + (x - mu) ** 2, 0);
        return -n/2 * Math.log(2 * Math.PI) - n * Math.log(sigma) - sumSquares / (2 * sigma ** 2);
    }
    
    function normalPDF(x, mu, sigma) {
        return (1 / (sigma * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * ((x - mu) / sigma) ** 2);
    }
    
    function plotData() {
        if (data.length === 0) return;
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        const currentMu = parseFloat(muGuess.value);
        const currentSigma = parseFloat(sigmaGuess.value);
        
        // Tìm phạm vi dữ liệu
        const minX = Math.min(...data) - 1;
        const maxX = Math.max(...data) + 1;
        const range = maxX - minX;
        
        // Vẽ histogram
        const bins = 20;
        const binWidth = range / bins;
        const binCounts = new Array(bins).fill(0);
        
        data.forEach(x =&gt; {
            const binIndex = Math.floor((x - minX) / binWidth);
            if (binIndex &gt;= 0 &amp;&amp; binIndex &lt; bins) {
                binCounts[binIndex]++;
            }
        });
        
        const maxCount = Math.max(...binCounts);
        
        ctx.fillStyle = &apos;rgba(33, 150, 243, 0.3)&apos;;
        for (let i = 0; i &lt; bins; i++) {
            const x = 50 + (i * binWidth / range) * 500;
            const height = (binCounts[i] / maxCount) * 200;
            const width = (binWidth / range) * 500;
            ctx.fillRect(x, 250 - height, width, height);
        }
        
        // Vẽ đường phân phối thực
        ctx.strokeStyle = &apos;#4CAF50&apos;;
        ctx.lineWidth = 2;
        ctx.beginPath();
        for (let i = 0; i &lt;= 500; i++) {
            const x = minX + (i / 500) * range;
            const y = normalPDF(x, trueMu, trueSigma);
            const plotX = 50 + (i / 500) * 500;
            const plotY = 250 - (y / (1 / (trueSigma * Math.sqrt(2 * Math.PI)))) * 200;
            
            if (i === 0) ctx.moveTo(plotX, plotY);
            else ctx.lineTo(plotX, plotY);
        }
        ctx.stroke();
        
        // Vẽ đường ước lượng hiện tại
        ctx.strokeStyle = &apos;#f44336&apos;;
        ctx.lineWidth = 2;
        ctx.setLineDash([5, 5]);
        ctx.beginPath();
        for (let i = 0; i &lt;= 500; i++) {
            const x = minX + (i / 500) * range;
            const y = normalPDF(x, currentMu, currentSigma);
            const plotX = 50 + (i / 500) * 500;
            const plotY = 250 - (y / (1 / (currentSigma * Math.sqrt(2 * Math.PI)))) * 200;
            
            if (i === 0) ctx.moveTo(plotX, plotY);
            else ctx.lineTo(plotX, plotY);
        }
        ctx.stroke();
        ctx.setLineDash([]);
        
        // Vẽ trục
        ctx.strokeStyle = &apos;#333&apos;;
        ctx.lineWidth = 1;
        ctx.beginPath();
        ctx.moveTo(50, 250);
        ctx.lineTo(550, 250);
        ctx.stroke();
        
        // Cập nhật kết quả
        const currentLL = logLikelihood(currentMu, currentSigma, data);
        const mleMu = data.reduce((sum, x) =&gt; sum + x, 0) / data.length;
        const mleSigma = Math.sqrt(data.reduce((sum, x) =&gt; sum + (x - mleMu) ** 2, 0) / data.length);
        const maxLL = logLikelihood(mleMu, mleSigma, data);
        
        document.getElementById(&apos;current-mu&apos;).textContent = currentMu.toFixed(2);
        document.getElementById(&apos;current-sigma&apos;).textContent = currentSigma.toFixed(2);
        document.getElementById(&apos;current-ll&apos;).textContent = currentLL.toFixed(2);
        document.getElementById(&apos;max-ll&apos;).textContent = maxLL.toFixed(2);
        
        // Thêm chú thích
        ctx.fillStyle = &apos;#4CAF50&apos;;
        ctx.fillRect(450, 60, 15, 3);
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;Phân phối thực&apos;, 470, 65);
        
        ctx.strokeStyle = &apos;#f44336&apos;;
        ctx.setLineDash([5, 5]);
        ctx.beginPath();
        ctx.moveTo(450, 80);
        ctx.lineTo(465, 80);
        ctx.stroke();
        ctx.setLineDash([]);
        ctx.fillText(&apos;Ước lượng hiện tại&apos;, 470, 85);
    }
    
    function updateDisplay() {
        muGuessValue.textContent = muGuess.value;
        sigmaGuessValue.textContent = sigmaGuess.value;
        plotData();
    }
    
    generateBtn.addEventListener(&apos;click&apos;, generateData);
    muGuess.addEventListener(&apos;input&apos;, updateDisplay);
    sigmaGuess.addEventListener(&apos;input&apos;, updateDisplay);
    sampleSizeInput.addEventListener(&apos;change&apos;, generateData);
    
    // Khởi tạo
    generateData();
});
&lt;/script&gt;

&lt;h3 id=&quot;tính-chất-của-mle&quot;&gt;Tính chất của MLE&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính vững (Consistency)&lt;/strong&gt;: khi kích thước mẫu tăng lên vô hạn, ước lượng MLE hội tụ theo xác suất về giá trị thực của tham số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính chuẩn tiệm cận (Asymptotic Normality)&lt;/strong&gt;: với kích thước mẫu đủ lớn, phân phối của ước lượng MLE xấp xỉ phân phối chuẩn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hiệu quả tiệm cận (Asymptotic Efficiency)&lt;/strong&gt;: MLE đạt cận dưới Cramér–Rao về mặt tiệm cận, tức có phương sai nhỏ nhất trong lớp các ước lượng không chệch.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bất biến (Invariance)&lt;/strong&gt;: nếu \(\hat{	heta}\) là MLE của \(heta\) thì \(g(\hat{	heta})\) là MLE của \(g(	heta)\) với mọi hàm khả nghịch \(g\) (và mở rộng cho hàm \(g\) tổng quát thông qua hàm hợp lý cảm sinh).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;ứng-dụng-của-mle&quot;&gt;Ứng dụng của MLE&lt;/h3&gt;

&lt;h4 id=&quot;1-ước-lượng-tham-số&quot;&gt;1. Ước lượng tham số&lt;/h4&gt;

&lt;p&gt;MLE được sử dụng rộng rãi để ước lượng tham số trong nhiều mô hình thống kê:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Phân phối chuẩn: ước lượng kỳ vọng và phương sai.&lt;/li&gt;
  &lt;li&gt;Phân phối Poisson: ước lượng tham số tốc độ \(\lambda\).&lt;/li&gt;
  &lt;li&gt;Hồi quy tuyến tính: ước lượng vector hệ số hồi quy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-so-sánh-mô-hình&quot;&gt;2. So sánh mô hình&lt;/h4&gt;

&lt;p&gt;Hàm hợp lý là cơ sở của nhiều tiêu chí đánh giá và chọn mô hình:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm định tỷ số hợp lý (Likelihood Ratio Test)&lt;/strong&gt;: so sánh hai mô hình lồng nhau.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;AIC / BIC&lt;/strong&gt;: các tiêu chí lựa chọn mô hình cân bằng giữa log-likelihood và độ phức tạp mô hình.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-thống-kê-bayes&quot;&gt;3. Thống kê Bayes&lt;/h4&gt;

&lt;p&gt;Trong suy luận Bayes, hàm hợp lý kết hợp với phân phối tiên nghiệm (prior) để xác định phân phối hậu nghiệm (posterior):&lt;/p&gt;

\[P(	heta \mid x) \propto L(	heta \mid x) \cdot P(	heta)\]

&lt;h3 id=&quot;kết-nối-với-tối-ưu-hóa&quot;&gt;Kết nối với tối ưu hóa&lt;/h3&gt;

&lt;p&gt;Bài toán MLE trực tiếp dẫn đến một bài toán tối ưu hóa:&lt;/p&gt;

\[\max_{	heta} L(	heta \mid x) \quad 	ext{hoặc} \quad \max_{	heta} \log L(	heta \mid x)\]

&lt;p&gt;Tùy cấu trúc mô hình, bài toán này có thể thuộc các dạng:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa không ràng buộc&lt;/strong&gt;: khi tham số nhận giá trị tự do trên \(\mathbb{R}^d\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa có ràng buộc&lt;/strong&gt;: khi tham số phải thỏa mãn miền điều kiện (ví dụ \(p \in [0, 1]\) hoặc \(\sigma &amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán tối ưu hóa lồi&lt;/strong&gt;: với nhiều mô hình, hàm log-likelihood là hàm lõm (tương đương, âm log-likelihood là hàm lồi), nên bài toán có nghiệm tối ưu toàn cục.&lt;/li&gt;
&lt;/ul&gt;

&lt;div style=&quot;background: #e8f4fd; padding: 15px; border-left: 4px solid #2196F3; margin: 20px 0;&quot;&gt;
&lt;strong&gt;💡 Kết nối với tối ưu hóa lồi:&lt;/strong&gt; Nhiều bài toán MLE — đặc biệt trong họ phân phối mũ — dẫn đến bài toán tối ưu hóa lồi. Nhờ đó, mọi cực tiểu địa phương đều là cực tiểu toàn cục và các thuật toán tối ưu hội tụ ổn định về nghiệm đúng.
&lt;/div&gt;

&lt;h3 id=&quot;ví-dụ-thực-tế-hồi-quy-logistic&quot;&gt;Ví dụ thực tế: Hồi quy logistic&lt;/h3&gt;

&lt;p&gt;Trong hồi quy logistic, xác suất của biến nhị phân \(y \in \{0, 1\}\) được mô hình hóa theo đặc trưng \(x\):&lt;/p&gt;

\[P(y = 1 \mid x) = rac{1}{1 + e^{-(eta_0 + eta_1 x)}}\]

&lt;p&gt;&lt;strong&gt;Log-likelihood&lt;/strong&gt; (với \(p_i = P(y_i = 1 \mid x_i)\)):
\(\ell(eta_0, eta_1) = \sum_{i=1}^{n} \left[ y_i \log(p_i) + (1-y_i) \log(1-p_i) 
ight]\)&lt;/p&gt;

&lt;p&gt;Đây là bài toán cực đại hóa hàm lõm (tương đương cực tiểu hóa hàm lồi là âm log-likelihood), có thể giải hiệu quả bằng gradient descent hoặc phương pháp Newton.&lt;/p&gt;

&lt;h3 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm hợp lý (Likelihood)&lt;/strong&gt; đo mức độ phù hợp của tham số với dữ liệu đã quan sát.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;MLE&lt;/strong&gt; tìm bộ tham số làm cực đại hàm hợp lý (hoặc log-likelihood).&lt;/li&gt;
  &lt;li&gt;MLE sở hữu nhiều tính chất tiệm cận tốt: tính vững, tính chuẩn tiệm cận và tính hiệu quả tiệm cận.&lt;/li&gt;
  &lt;li&gt;MLE chuyển trực tiếp bài toán ước lượng thống kê thành bài toán tối ưu hóa, trong đó nhiều trường hợp quan trọng là tối ưu hóa lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;div style=&quot;background: #d4edda; padding: 15px; border-left: 4px solid #28a745; margin: 20px 0;&quot;&gt;
&lt;strong&gt;🎯 Điểm cốt lõi:&lt;/strong&gt; MLE là cầu nối trực tiếp giữa thống kê và tối ưu hóa, giúp ta hiểu cách tham số của các mô hình thống kê được ước lượng bằng các phương pháp tối ưu hóa, đặc biệt là tối ưu hóa lồi.
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>00-04-02 Các Phân Phối Xác Suất Thông Dụng</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_04_02_Common_Probability_Distributions/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_04_02_Common_Probability_Distributions</id>
   <content type="html">&lt;p&gt;Một trong những bất ngờ thú vị nhất khi học tối ưu hóa cho khoa học dữ liệu là phát hiện ra: các hàm mất mát nổi tiếng nhất không phải do ai đó “bịa” ra ngẫu nhiên, mà mỗi hàm đều là hình bóng logarit của một &lt;strong&gt;phân phối xác suất&lt;/strong&gt; cổ điển! Phân phối Gauss sinh ra hồi quy bình phương tối thiểu, phân phối Bernoulli sinh ra hồi quy logistic, phân phối Laplace sinh ra hồi quy chuẩn \(\ell_1\), còn phân phối chuẩn đa biến gắn liền trực tiếp với ma trận xác định dương.&lt;/p&gt;

&lt;p&gt;Bài học này giúp bạn không chỉ nhớ công thức các phân phối rời rạc và liên tục thông dụng, mà còn thấy ngay cấu trúc lồi ẩn sau log-mật độ của chúng.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-họ-phân-phối-và-hàm-mất-mát-tương-ứng&quot;&gt;Kiến thức cần nhớ: Họ phân phối và hàm mất mát tương ứng&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân phối rời rạc (Bernoulli, Nhị thức, Poisson, Categorical):&lt;/strong&gt; Mô hình hóa dữ liệu đếm và phân loại nhãn. Âm log-hợp lý của Bernoulli/Categorical chính là hàm mất mát &lt;strong&gt;Binary/Multi-class Cross-Entropy&lt;/strong&gt; — một hàm lồi đẹp theo tham số tuyến tính.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Phân phối liên tục một biến (Đều, Mũ, Chuẩn Gauss, Laplace):&lt;/strong&gt; Phân phối Gauss có đuôi giảm theo \(e^{-x^2}\) (tạo phạt bình phương nhạy với ngoại lai), còn Laplace có đuôi giảm theo $$e^{-&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;}\((tạo phạt\)\ell_1$$ bền vững và khuyến khích độ thưa).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân phối chuẩn đa biến (\(\mathcal{N}(\mu, \Sigma)\)):&lt;/strong&gt; Mở rộng Gauss lên \(\mathbb{R}^n\) với mật độ tỉ lệ với \(\exp\left(-\frac{1}{2}(x-\mu)^T \Sigma^{-1}(x-\mu)\right)\). Đường đồng mức của mật độ chính là các &lt;strong&gt;ellipsoid&lt;/strong&gt; — đối tượng lồi quen thuộc của Chương 02.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính log-lõm (Log-concavity):&lt;/strong&gt; Hầu hết các phân phối kinh điển (Gauss, Mũ, Laplace, Gamma với \(\alpha \ge 1\)) đều có log-mật độ là hàm lõm, nhờ đó bài toán ước lượng tham số tự động trở thành &lt;strong&gt;bài toán tối ưu hóa lồi&lt;/strong&gt;!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-âm-log-hợp-lý-gauss-và-laplace-trên-cùng-bộ-dữ-liệu&quot;&gt;Giải thích: So sánh âm log-hợp lý Gauss và Laplace trên cùng bộ dữ liệu&lt;/h3&gt;

&lt;p&gt;Cho \(3\) quan sát độc lập \(x_1 = 1,\ x_2 = 2,\ x_3 = 6\). Ta muốn ước lượng tâm vị trí \(\mu\) dưới hai giả thiết nhiễu khác nhau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giả thiết nhiễu chuẩn \(\mathcal{N}(\mu, 1)\):&lt;/strong&gt;
Hàm mật độ \(p(x_i \mid \mu) = \frac{1}{\sqrt{2\pi}}\exp\left(-\frac{(x_i - \mu)^2}{2}\right)\). Lấy tổng âm log-hợp lý (bỏ hằng số):
\(\text{NLL}_{\text{Gauss}}(\mu) = \frac{1}{2}\left[(1-\mu)^2 + (2-\mu)^2 + (6-\mu)^2\right].\)
Đạo hàm bằng \(0\): \(-(1-\mu) - (2-\mu) - (6-\mu) = 0 \implies 3\mu = 9 \implies \hat\mu_{\text{Gauss}} = 3\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giả thiết nhiễu Laplace \(\operatorname{Laplace}(\mu, 1)\):&lt;/strong&gt;
Hàm mật độ \(p(x_i \mid \mu) = \frac{1}{2}\exp(-|x_i - \mu|)\). Lấy tổng âm log-hợp lý (bỏ hằng số):
\(\text{NLL}_{\text{Laplace}}(\mu) = |1-\mu| + |2-\mu| + |6-\mu|.\)
Kiểm tra giá trị:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Tại \(\mu = 2\): $$&lt;/td&gt;
              &lt;td&gt;1-2&lt;/td&gt;
              &lt;td&gt;+&lt;/td&gt;
              &lt;td&gt;2-2&lt;/td&gt;
              &lt;td&gt;+&lt;/td&gt;
              &lt;td&gt;6-2&lt;/td&gt;
              &lt;td&gt;= 1 + 0 + 4 = 5$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Tại \(\mu = 3\): \(|1-3| + |2-3| + |6-3| = 2 + 1 + 3 = 6 &amp;gt; 5\).
Vậy \(\hat\mu_{\text{Laplace}} = 2\) (trung vị). Chỉ cần đổi giả thiết phân phối nhiễu, bài toán tối ưu lập tức đổi từ chuẩn \(\ell_2\) sang chuẩn \(\ell_1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;các-phân-phối-xác-suất-thông-dụng&quot;&gt;Các phân phối xác suất thông dụng&lt;/h2&gt;

&lt;p&gt;Hiểu rõ các phân phối xác suất cốt lõi là yêu cầu thiết yếu đối với nhiều bài toán tối ưu hóa trong học máy và thống kê. Các phân phối này thường đóng vai trò là giả định phân phối dữ liệu, phân phối tiên nghiệm (prior) trong suy luận Bayes hoặc mô hình nhiễu trong hồi quy.&lt;/p&gt;

&lt;h3 id=&quot;1-phân-phối-rời-rạc&quot;&gt;1. Phân phối rời rạc&lt;/h3&gt;

&lt;h4 id=&quot;phân-phối-bernoulli&quot;&gt;Phân phối Bernoulli&lt;/h4&gt;

&lt;p&gt;Mô hình hóa một phép thử đơn với hai kết quả có thể xảy ra (thành công hoặc thất bại).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tham số&lt;/strong&gt;: \(p \in [0,1]\) (xác suất thành công)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PMF&lt;/strong&gt;: \(P(X = k) = p^k (1-p)^{1-k}\) với \(k \in \{0,1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kỳ vọng&lt;/strong&gt;: \(\mathbb{E}[X] = p\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương sai&lt;/strong&gt;: \(ext{Var}(X) = p(1-p)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ứng dụng&lt;/strong&gt;: phân loại nhị phân, tung đồng xu, kiểm định A/B.&lt;/p&gt;

&lt;h4 id=&quot;phân-phối-nhị-thức&quot;&gt;Phân phối nhị thức&lt;/h4&gt;

&lt;p&gt;Mô hình hóa số lần thành công trong \(n\) phép thử Bernoulli độc lập có cùng xác suất thành công.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tham số&lt;/strong&gt;: \(n \in \mathbb{N}\) (số phép thử), \(p \in [0,1]\) (xác suất thành công)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PMF&lt;/strong&gt;: \(P(X = k) = inom{n}{k} p^k (1-p)^{n-k}\) với \(k = 0,1,\ldots,n\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kỳ vọng&lt;/strong&gt;: \(\mathbb{E}[X] = np\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương sai&lt;/strong&gt;: \(ext{Var}(X) = np(1-p)\)&lt;/p&gt;

&lt;h4 id=&quot;phân-phối-poisson&quot;&gt;Phân phối Poisson&lt;/h4&gt;

&lt;p&gt;Mô hình hóa số sự kiện xảy ra trong một khoảng thời gian (hoặc không gian) cố định khi các sự kiện diễn ra độc lập với tốc độ trung bình không đổi.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tham số&lt;/strong&gt;: \(\lambda &amp;gt; 0\) (tốc độ trung bình)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PMF&lt;/strong&gt;: \(P(X = k) = rac{\lambda^k e^{-\lambda}}{k!}\) với \(k = 0,1,2,\ldots\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kỳ vọng&lt;/strong&gt;: \(\mathbb{E}[X] = \lambda\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương sai&lt;/strong&gt;: \(ext{Var}(X) = \lambda\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ứng dụng&lt;/strong&gt;: dữ liệu đếm, sự kiện hiếm, lý thuyết hàng đợi.&lt;/p&gt;

&lt;div id=&quot;discrete-distributions-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Phân phối rời rạc tương tác&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;discreteCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Trực quan hóa:&lt;/strong&gt; Hàm khối xác suất của các phân phối rời rạc.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Loại phân phối&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;discrete-dist&quot; value=&quot;bernoulli&quot; checked=&quot;&quot; /&gt; Bernoulli
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;discrete-dist&quot; value=&quot;binomial&quot; /&gt; Nhị thức
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;discrete-dist&quot; value=&quot;poisson&quot; /&gt; Poisson
                    &lt;/label&gt;
                &lt;/div&gt;
                
                &lt;div id=&quot;discrete-params&quot;&gt;
                    &lt;div id=&quot;p-param&quot; style=&quot;margin-bottom: 15px;&quot;&gt;
                        &lt;label for=&quot;p-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;p: &lt;span id=&quot;p-value&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;
                        &lt;input type=&quot;range&quot; id=&quot;p-slider&quot; min=&quot;0.1&quot; max=&quot;0.9&quot; step=&quot;0.05&quot; value=&quot;0.5&quot; style=&quot;width: 100%;&quot; /&gt;
                    &lt;/div&gt;
                    
                    &lt;div id=&quot;n-param&quot; style=&quot;margin-bottom: 15px; display: none;&quot;&gt;
                        &lt;label for=&quot;n-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;n: &lt;span id=&quot;n-value&quot;&gt;10&lt;/span&gt;&lt;/label&gt;
                        &lt;input type=&quot;range&quot; id=&quot;n-slider&quot; min=&quot;5&quot; max=&quot;50&quot; step=&quot;1&quot; value=&quot;10&quot; style=&quot;width: 100%;&quot; /&gt;
                    &lt;/div&gt;
                    
                    &lt;div id=&quot;lambda-param&quot; style=&quot;margin-bottom: 15px; display: none;&quot;&gt;
                        &lt;label for=&quot;lambda-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;λ: &lt;span id=&quot;lambda-value&quot;&gt;3.0&lt;/span&gt;&lt;/label&gt;
                        &lt;input type=&quot;range&quot; id=&quot;lambda-slider&quot; min=&quot;0.5&quot; max=&quot;10&quot; step=&quot;0.5&quot; value=&quot;3.0&quot; style=&quot;width: 100%;&quot; /&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                
                &lt;div id=&quot;discrete-stats&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Thống kê:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Kỳ vọng: &lt;span id=&quot;discrete-mean&quot;&gt;0.500&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Phương sai: &lt;span id=&quot;discrete-variance&quot;&gt;0.250&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Mode: &lt;span id=&quot;discrete-mode&quot;&gt;0 hoặc 1&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;2-phân-phối-liên-tục&quot;&gt;2. Phân phối liên tục&lt;/h3&gt;

&lt;h4 id=&quot;phân-phối-đều&quot;&gt;Phân phối đều&lt;/h4&gt;

&lt;p&gt;Mọi giá trị trong một đoạn cho trước đều có mật độ xác suất như nhau.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tham số&lt;/strong&gt;: \(a, b \in \mathbb{R}\) với \(a &amp;lt; b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt;: \(f(x) = rac{1}{b-a}\) với \(x \in [a,b]\), và bằng \(0\) ở ngoài đoạn này&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kỳ vọng&lt;/strong&gt;: \(\mathbb{E}[X] = rac{a+b}{2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương sai&lt;/strong&gt;: \(ext{Var}(X) = rac{(b-a)^2}{12}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ứng dụng&lt;/strong&gt;: lấy mẫu ngẫu nhiên, khởi tạo tham số trong thuật toán.&lt;/p&gt;

&lt;h4 id=&quot;phân-phối-chuẩn-gaussian&quot;&gt;Phân phối chuẩn (Gaussian)&lt;/h4&gt;

&lt;p&gt;Phân phối có vai trò trung tâm trong thống kê và tối ưu hóa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tham số&lt;/strong&gt;: \(\mu \in \mathbb{R}\) (kỳ vọng), \(\sigma^2 &amp;gt; 0\) (phương sai)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt;: \(f(x) = rac{1}{\sqrt{2\pi\sigma^2}} \exp\left(-rac{(x-\mu)^2}{2\sigma^2}
ight)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kỳ vọng&lt;/strong&gt;: \(\mathbb{E}[X] = \mu\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương sai&lt;/strong&gt;: \(ext{Var}(X) = \sigma^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Đối xứng quanh \(\mu\).&lt;/li&gt;
  &lt;li&gt;Quy tắc 68–95–99.7.&lt;/li&gt;
  &lt;li&gt;Gắn với định lý giới hạn trung tâm.&lt;/li&gt;
  &lt;li&gt;Đạt entropy cực đại trong số các phân phối trên \(\mathbb{R}\) có cùng kỳ vọng và phương sai cho trước.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;phân-phối-mũ&quot;&gt;Phân phối mũ&lt;/h4&gt;

&lt;p&gt;Mô hình hóa thời gian chờ giữa hai sự kiện liên tiếp trong một quá trình Poisson.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tham số&lt;/strong&gt;: \(\lambda &amp;gt; 0\) (tham số tốc độ)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt;: \(f(x) = \lambda e^{-\lambda x}\) với \(x \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kỳ vọng&lt;/strong&gt;: \(\mathbb{E}[X] = rac{1}{\lambda}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương sai&lt;/strong&gt;: \(ext{Var}(X) = rac{1}{\lambda^2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất&lt;/strong&gt;: tính không nhớ (memoryless).&lt;/p&gt;

&lt;h4 id=&quot;phân-phối-beta&quot;&gt;Phân phối Beta&lt;/h4&gt;

&lt;p&gt;Phân phối liên tục linh hoạt trên đoạn \([0,1]\), thường dùng để mô hình hóa xác suất hoặc tỷ lệ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tham số&lt;/strong&gt;: \(lpha, eta &amp;gt; 0\) (các tham số hình dạng)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt;: \(f(x) = rac{\Gamma(lpha+eta)}{\Gamma(lpha)\Gamma(eta)} x^{lpha-1}(1-x)^{eta-1}\) với \(x \in [0,1]\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kỳ vọng&lt;/strong&gt;: \(\mathbb{E}[X] = rac{lpha}{lpha+eta}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương sai&lt;/strong&gt;: \(ext{Var}(X) = rac{lphaeta}{(lpha+eta)^2(lpha+eta+1)}\)&lt;/p&gt;

&lt;div id=&quot;continuous-distributions-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Phân phối liên tục tương tác&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;continuousCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Trực quan hóa:&lt;/strong&gt; Hàm mật độ xác suất của các phân phối liên tục.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Loại phân phối&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;continuous-dist&quot; value=&quot;uniform&quot; checked=&quot;&quot; /&gt; Đều
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;continuous-dist&quot; value=&quot;normal&quot; /&gt; Chuẩn
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;continuous-dist&quot; value=&quot;exponential&quot; /&gt; Mũ
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;continuous-dist&quot; value=&quot;beta&quot; /&gt; Beta
                    &lt;/label&gt;
                &lt;/div&gt;
                
                &lt;div id=&quot;continuous-params&quot;&gt;
                    &lt;div id=&quot;uniform-params&quot;&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;a-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;a: &lt;span id=&quot;a-value&quot;&gt;0&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;a-slider&quot; min=&quot;-2&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;b-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;b: &lt;span id=&quot;b-value&quot;&gt;1&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;b-slider&quot; min=&quot;0.5&quot; max=&quot;4&quot; step=&quot;0.1&quot; value=&quot;1&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    
                    &lt;div id=&quot;normal-params&quot; style=&quot;display: none;&quot;&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;mu-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;μ: &lt;span id=&quot;mu-value&quot;&gt;0&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;mu-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;sigma-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;σ: &lt;span id=&quot;sigma-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;sigma-slider&quot; min=&quot;0.5&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    
                    &lt;div id=&quot;exponential-params&quot; style=&quot;display: none;&quot;&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;exp-lambda-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;λ: &lt;span id=&quot;exp-lambda-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;exp-lambda-slider&quot; min=&quot;0.2&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    
                    &lt;div id=&quot;beta-params&quot; style=&quot;display: none;&quot;&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;alpha-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;α: &lt;span id=&quot;alpha-value&quot;&gt;2&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;alpha-slider&quot; min=&quot;0.5&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;2&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;beta-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;β: &lt;span id=&quot;beta-value&quot;&gt;2&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;beta-slider&quot; min=&quot;0.5&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;2&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                
                &lt;div id=&quot;continuous-stats&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Thống kê:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Kỳ vọng: &lt;span id=&quot;continuous-mean&quot;&gt;0.500&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Phương sai: &lt;span id=&quot;continuous-variance&quot;&gt;0.083&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Miền xác định: &lt;span id=&quot;continuous-support&quot;&gt;[0, 1]&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;3-phân-phối-đa-biến&quot;&gt;3. Phân phối đa biến&lt;/h3&gt;

&lt;h4 id=&quot;phân-phối-chuẩn-đa-biến&quot;&gt;Phân phối chuẩn đa biến&lt;/h4&gt;

&lt;p&gt;Tổng quát hóa phân phối chuẩn sang không gian nhiều chiều.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tham số&lt;/strong&gt;: \(oldsymbol{\mu} \in \mathbb{R}^d\) (vector kỳ vọng), \(oldsymbol{\Sigma} \in \mathbb{R}^{d 	imes d}\) (ma trận hiệp phương sai đối xứng xác định dương)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt;: \(f(\mathbf{x}) = rac{1}{(2\pi)^{d/2}|oldsymbol{\Sigma}|^{1/2}} \exp\left(-rac{1}{2}(\mathbf{x}-oldsymbol{\mu})^Toldsymbol{\Sigma}^{-1}(\mathbf{x}-oldsymbol{\mu})
ight)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Các phân phối biên đều là phân phối chuẩn.&lt;/li&gt;
  &lt;li&gt;Tổ hợp tuyến tính của các thành phần tuân theo phân phối chuẩn.&lt;/li&gt;
  &lt;li&gt;Các phân phối có điều kiện đều là phân phối chuẩn.&lt;/li&gt;
&lt;/ul&gt;

&lt;div id=&quot;multivariate-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f0f8ff;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Phân phối chuẩn đa biến&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;multivariateCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Trực quan 2D:&lt;/strong&gt; Đồ thị đường mức của phân phối chuẩn hai biến. Các điểm mẫu được hiển thị dưới dạng chấm.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Tham số&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;mu1-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;μ₁: &lt;span id=&quot;mu1-value&quot;&gt;0.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;mu1-slider&quot; min=&quot;-2&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;mu2-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;μ₂: &lt;span id=&quot;mu2-value&quot;&gt;0.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;mu2-slider&quot; min=&quot;-2&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;sigma1-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;σ₁: &lt;span id=&quot;sigma1-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;sigma1-slider&quot; min=&quot;0.5&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;sigma2-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;σ₂: &lt;span id=&quot;sigma2-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;sigma2-slider&quot; min=&quot;0.5&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;rho-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;ρ (tương quan): &lt;span id=&quot;rho-value&quot;&gt;0.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;rho-slider&quot; min=&quot;-0.9&quot; max=&quot;0.9&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;button id=&quot;generate-samples&quot; style=&quot;width: 100%; padding: 10px; background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 15px;&quot;&gt;Tạo mẫu&lt;/button&gt;
                
                &lt;div id=&quot;multivariate-stats&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Ma trận hiệp phương sai:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Σ₁₁: &lt;span id=&quot;cov11&quot;&gt;1.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Σ₁₂: &lt;span id=&quot;cov12&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Σ₂₂: &lt;span id=&quot;cov22&quot;&gt;1.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Det(Σ): &lt;span id=&quot;det-cov&quot;&gt;1.000&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;4-ứng-dụng-trong-tối-ưu-hóa&quot;&gt;4. Ứng dụng trong tối ưu hóa&lt;/h3&gt;

&lt;h4 id=&quot;ước-lượng-hợp-lý-tối-đa&quot;&gt;Ước lượng hợp lý tối đa&lt;/h4&gt;
&lt;p&gt;Nhiều bài toán tối ưu hóa tìm bộ tham số làm cực đại hàm hợp lý của dữ liệu quan sát dưới một phân phối giả định:&lt;/p&gt;

\[\hat{	heta} = rg\max_	heta \prod_{i=1}^n f(x_i; 	heta)\]

&lt;h4 id=&quot;tối-ưu-hóa-bayes&quot;&gt;Tối ưu hóa Bayes&lt;/h4&gt;
&lt;p&gt;Phân phối tiên nghiệm (prior) mã hóa tri thức ban đầu về tham số trước khi quan sát dữ liệu:&lt;/p&gt;

\[p(	heta|dữ\ liệu) \propto p(dữ\ liệu|	heta) \cdot p(	heta)\]

&lt;h4 id=&quot;điều-chuẩn-regularization&quot;&gt;Điều chuẩn (Regularization)&lt;/h4&gt;
&lt;p&gt;Các phân phối tiên nghiệm tương ứng trực tiếp với các thành phần điều chuẩn trong tối ưu hóa:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Điều chuẩn \(L_2\) ↔ phân phối tiên nghiệm Gaussian.&lt;/li&gt;
  &lt;li&gt;Điều chuẩn \(L_1\) ↔ phân phối tiên nghiệm Laplace.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tối-ưu-hóa-ngẫu-nhiên&quot;&gt;Tối ưu hóa ngẫu nhiên&lt;/h4&gt;
&lt;p&gt;Các phân phối xác suất được dùng để mô hình hóa nhiễu và tính bất định trong hàm mục tiêu cũng như ràng buộc.&lt;/p&gt;

&lt;h3 id=&quot;những-điểm-quan-trọng-cho-tối-ưu-hóa&quot;&gt;Những điểm quan trọng cho tối ưu hóa&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn mô hình&lt;/strong&gt;: chọn phân phối phù hợp với bản chất dữ liệu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng tham số&lt;/strong&gt;: dùng MLE hoặc phương pháp Bayes để ước lượng tham số phân phối.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lượng tính bất định&lt;/strong&gt;: phân phối xác suất cho cách biểu diễn tự nhiên đối với sai số và độ không chắc chắn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều chuẩn&lt;/strong&gt;: phân phối tiên nghiệm giúp hạn chế quá khớp (overfitting).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu quả tính toán&lt;/strong&gt;: nhiều phân phối kinh điển có công thức nghiệm dạng đóng cho các phép toán thống kê thông dụng.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hiểu rõ các phân phối này cùng tính chất của chúng là nền tảng để xây dựng và giải các bài toán tối ưu hóa trong học máy, thống kê và kỹ thuật.&lt;/p&gt;

&lt;script&gt;
// Discrete Distributions Demo
class DiscreteDistributionsDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;discreteCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.distType = &apos;bernoulli&apos;;
        this.params = { p: 0.5, n: 10, lambda: 3.0 };
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const radios = document.querySelectorAll(&apos;input[name=&quot;discrete-dist&quot;]&apos;);
        const pSlider = document.getElementById(&apos;p-slider&apos;);
        const nSlider = document.getElementById(&apos;n-slider&apos;);
        const lambdaSlider = document.getElementById(&apos;lambda-slider&apos;);
        
        radios.forEach(radio =&gt; {
            radio.addEventListener(&apos;change&apos;, (e) =&gt; {
                this.distType = e.target.value;
                this.updateParameterVisibility();
                this.updateStats();
                this.draw();
            });
        });
        
        pSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.params.p = parseFloat(e.target.value);
            document.getElementById(&apos;p-value&apos;).textContent = this.params.p.toFixed(1);
            this.updateStats();
            this.draw();
        });
        
        nSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.params.n = parseInt(e.target.value);
            document.getElementById(&apos;n-value&apos;).textContent = this.params.n;
            this.updateStats();
            this.draw();
        });
        
        lambdaSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.params.lambda = parseFloat(e.target.value);
            document.getElementById(&apos;lambda-value&apos;).textContent = this.params.lambda.toFixed(1);
            this.updateStats();
            this.draw();
        });
        
        this.updateParameterVisibility();
        this.updateStats();
    }
    
    updateParameterVisibility() {
        document.getElementById(&apos;p-param&apos;).style.display = 
            (this.distType === &apos;bernoulli&apos; || this.distType === &apos;binomial&apos;) ? &apos;block&apos; : &apos;none&apos;;
        document.getElementById(&apos;n-param&apos;).style.display = 
            this.distType === &apos;binomial&apos; ? &apos;block&apos; : &apos;none&apos;;
        document.getElementById(&apos;lambda-param&apos;).style.display = 
            this.distType === &apos;poisson&apos; ? &apos;block&apos; : &apos;none&apos;;
    }
    
    updateStats() {
        let mean, variance, mode;
        
        switch(this.distType) {
            case &apos;bernoulli&apos;:
                mean = this.params.p;
                variance = this.params.p * (1 - this.params.p);
                mode = this.params.p &gt; 0.5 ? &apos;1&apos; : (this.params.p &lt; 0.5 ? &apos;0&apos; : &apos;0 hoặc 1&apos;);
                break;
            case &apos;binomial&apos;:
                mean = this.params.n * this.params.p;
                variance = this.params.n * this.params.p * (1 - this.params.p);
                mode = Math.floor((this.params.n + 1) * this.params.p).toString();
                break;
            case &apos;poisson&apos;:
                mean = this.params.lambda;
                variance = this.params.lambda;
                mode = Math.floor(this.params.lambda).toString();
                break;
        }
        
        document.getElementById(&apos;discrete-mean&apos;).textContent = mean.toFixed(3);
        document.getElementById(&apos;discrete-variance&apos;).textContent = variance.toFixed(3);
        document.getElementById(&apos;discrete-mode&apos;).textContent = mode;
    }
    
    factorial(n) {
        if (n &lt;= 1) return 1;
        return n * this.factorial(n - 1);
    }
    
    binomialCoeff(n, k) {
        if (k &gt; n) return 0;
        return this.factorial(n) / (this.factorial(k) * this.factorial(n - k));
    }
    
    getProbability(k) {
        switch(this.distType) {
            case &apos;bernoulli&apos;:
                return k === 0 ? (1 - this.params.p) : (k === 1 ? this.params.p : 0);
            case &apos;binomial&apos;:
                if (k &lt; 0 || k &gt; this.params.n) return 0;
                return this.binomialCoeff(this.params.n, k) * 
                       Math.pow(this.params.p, k) * 
                       Math.pow(1 - this.params.p, this.params.n - k);
            case &apos;poisson&apos;:
                if (k &lt; 0) return 0;
                return Math.pow(this.params.lambda, k) * Math.exp(-this.params.lambda) / this.factorial(k);
        }
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        const marginX = 50;
        const marginY = 50;
        const plotWidth = this.width - 2 * marginX;
        const plotHeight = this.height - 2 * marginY;
        
        // Draw axes
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        this.ctx.beginPath();
        this.ctx.moveTo(marginX, this.height - marginY);
        this.ctx.lineTo(this.width - marginX, this.height - marginY);
        this.ctx.moveTo(marginX, marginY);
        this.ctx.lineTo(marginX, this.height - marginY);
        this.ctx.stroke();
        
        // Determine range
        let maxK;
        switch(this.distType) {
            case &apos;bernoulli&apos;: maxK = 1; break;
            case &apos;binomial&apos;: maxK = this.params.n; break;
            case &apos;poisson&apos;: maxK = Math.min(20, this.params.lambda + 3 * Math.sqrt(this.params.lambda)); break;
        }
        
        // Find max probability for scaling
        let maxProb = 0;
        for (let k = 0; k &lt;= maxK; k++) {
            maxProb = Math.max(maxProb, this.getProbability(k));
        }
        
        // Draw bars
        this.ctx.fillStyle = &apos;#2196f3&apos;;
        const barWidth = plotWidth / (maxK + 2);
        
        for (let k = 0; k &lt;= maxK; k++) {
            const prob = this.getProbability(k);
            const x = marginX + (k + 0.5) * barWidth;
            const height = (prob / maxProb) * plotHeight * 0.8;
            const y = this.height - marginY - height;
            
            this.ctx.fillRect(x - barWidth * 0.3, y, barWidth * 0.6, height);
            
            // Label
            this.ctx.fillStyle = &apos;#000&apos;;
            this.ctx.font = &apos;10px Arial&apos;;
            this.ctx.textAlign = &apos;center&apos;;
            this.ctx.fillText(k.toString(), x, this.height - marginY + 15);
            this.ctx.fillText(prob.toFixed(3), x, y - 5);
            this.ctx.fillStyle = &apos;#2196f3&apos;;
        }
        
        // Labels
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;center&apos;;
        this.ctx.fillText(&apos;k&apos;, this.width / 2, this.height - 10);
        
        this.ctx.save();
        this.ctx.translate(15, this.height / 2);
        this.ctx.rotate(-Math.PI / 2);
        this.ctx.fillText(&apos;P(X = k)&apos;, 0, 0);
        this.ctx.restore();
    }
}

// Continuous Distributions Demo
class ContinuousDistributionsDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;continuousCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.distType = &apos;uniform&apos;;
        this.params = { a: 0, b: 1, mu: 0, sigma: 1, lambda: 1, alpha: 2, beta: 2 };
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const radios = document.querySelectorAll(&apos;input[name=&quot;continuous-dist&quot;]&apos;);
        
        radios.forEach(radio =&gt; {
            radio.addEventListener(&apos;change&apos;, (e) =&gt; {
                this.distType = e.target.value;
                this.updateParameterVisibility();
                this.updateStats();
                this.draw();
            });
        });
        
        // Setup all sliders
        const sliders = [&apos;a&apos;, &apos;b&apos;, &apos;mu&apos;, &apos;sigma&apos;, &apos;exp-lambda&apos;, &apos;alpha&apos;, &apos;beta&apos;];
        sliders.forEach(slider =&gt; {
            const element = document.getElementById(slider + &apos;-slider&apos;);
            if (element) {
                element.addEventListener(&apos;input&apos;, (e) =&gt; {
                    const value = parseFloat(e.target.value);
                    const param = slider === &apos;exp-lambda&apos; ? &apos;lambda&apos; : slider;
                    this.params[param] = value;
                    
                    const valueSpan = document.getElementById(slider + &apos;-value&apos;);
                    if (valueSpan) {
                        valueSpan.textContent = value.toFixed(1);
                    }
                    
                    this.updateStats();
                    this.draw();
                });
            }
        });
        
        this.updateParameterVisibility();
        this.updateStats();
    }
    
    updateParameterVisibility() {
        document.getElementById(&apos;uniform-params&apos;).style.display = 
            this.distType === &apos;uniform&apos; ? &apos;block&apos; : &apos;none&apos;;
        document.getElementById(&apos;normal-params&apos;).style.display = 
            this.distType === &apos;normal&apos; ? &apos;block&apos; : &apos;none&apos;;
        document.getElementById(&apos;exponential-params&apos;).style.display = 
            this.distType === &apos;exponential&apos; ? &apos;block&apos; : &apos;none&apos;;
        document.getElementById(&apos;beta-params&apos;).style.display = 
            this.distType === &apos;beta&apos; ? &apos;block&apos; : &apos;none&apos;;
    }
    
    updateStats() {
        let mean, variance, support;
        
        switch(this.distType) {
            case &apos;uniform&apos;:
                mean = (this.params.a + this.params.b) / 2;
                variance = Math.pow(this.params.b - this.params.a, 2) / 12;
                support = `[${this.params.a}, ${this.params.b}]`;
                break;
            case &apos;normal&apos;:
                mean = this.params.mu;
                variance = this.params.sigma * this.params.sigma;
                support = &apos;(-∞, ∞)&apos;;
                break;
            case &apos;exponential&apos;:
                mean = 1 / this.params.lambda;
                variance = 1 / (this.params.lambda * this.params.lambda);
                support = &apos;[0, ∞)&apos;;
                break;
            case &apos;beta&apos;:
                mean = this.params.alpha / (this.params.alpha + this.params.beta);
                variance = (this.params.alpha * this.params.beta) / 
                          (Math.pow(this.params.alpha + this.params.beta, 2) * 
                           (this.params.alpha + this.params.beta + 1));
                support = &apos;[0, 1]&apos;;
                break;
        }
        
        document.getElementById(&apos;continuous-mean&apos;).textContent = mean.toFixed(3);
        document.getElementById(&apos;continuous-variance&apos;).textContent = variance.toFixed(3);
        document.getElementById(&apos;continuous-support&apos;).textContent = support;
    }
    
    gamma(z) {
        // Stirling&apos;s approximation for gamma function
        if (z &lt; 0.5) return Math.PI / (Math.sin(Math.PI * z) * this.gamma(1 - z));
        z -= 1;
        let x = 0.99999999999980993;
        const p = [676.5203681218851, -1259.1392167224028, 771.32342877765313,
                  -176.61502916214059, 12.507343278686905, -0.13857109526572012,
                  9.9843695780195716e-6, 1.5056327351493116e-7];
        for (let i = 0; i &lt; p.length; i++) {
            x += p[i] / (z + i + 1);
        }
        const t = z + p.length - 0.5;
        return Math.sqrt(2 * Math.PI) * Math.pow(t, z + 0.5) * Math.exp(-t) * x;
    }
    
    getPDF(x) {
        switch(this.distType) {
            case &apos;uniform&apos;:
                return (x &gt;= this.params.a &amp;&amp; x &lt;= this.params.b) ? 
                       1 / (this.params.b - this.params.a) : 0;
            case &apos;normal&apos;:
                return Math.exp(-0.5 * Math.pow((x - this.params.mu) / this.params.sigma, 2)) / 
                       (this.params.sigma * Math.sqrt(2 * Math.PI));
            case &apos;exponential&apos;:
                return x &gt;= 0 ? this.params.lambda * Math.exp(-this.params.lambda * x) : 0;
            case &apos;beta&apos;:
                if (x &lt; 0 || x &gt; 1) return 0;
                const B = this.gamma(this.params.alpha) * this.gamma(this.params.beta) / 
                         this.gamma(this.params.alpha + this.params.beta);
                return Math.pow(x, this.params.alpha - 1) * Math.pow(1 - x, this.params.beta - 1) / B;
        }
    }
    
    getRange() {
        switch(this.distType) {
            case &apos;uniform&apos;: return [this.params.a - 0.5, this.params.b + 0.5];
            case &apos;normal&apos;: return [this.params.mu - 4 * this.params.sigma, this.params.mu + 4 * this.params.sigma];
            case &apos;exponential&apos;: return [0, 5 / this.params.lambda];
            case &apos;beta&apos;: return [0, 1];
        }
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        const marginX = 50;
        const marginY = 50;
        const plotWidth = this.width - 2 * marginX;
        const plotHeight = this.height - 2 * marginY;
        
        // Draw axes
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        this.ctx.beginPath();
        this.ctx.moveTo(marginX, this.height - marginY);
        this.ctx.lineTo(this.width - marginX, this.height - marginY);
        this.ctx.moveTo(marginX, marginY);
        this.ctx.lineTo(marginX, this.height - marginY);
        this.ctx.stroke();
        
        const [minX, maxX] = this.getRange();
        
        // Find max PDF for scaling
        let maxPDF = 0;
        for (let i = 0; i &lt;= 200; i++) {
            const x = minX + (maxX - minX) * i / 200;
            maxPDF = Math.max(maxPDF, this.getPDF(x));
        }
        
        // Draw PDF curve
        this.ctx.strokeStyle = &apos;#2196f3&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        
        for (let i = 0; i &lt;= 200; i++) {
            const x = minX + (maxX - minX) * i / 200;
            const pdf = this.getPDF(x);
            const plotX = marginX + (x - minX) / (maxX - minX) * plotWidth;
            const plotY = this.height - marginY - (pdf / maxPDF) * plotHeight * 0.8;
            
            if (i === 0) {
                this.ctx.moveTo(plotX, plotY);
            } else {
                this.ctx.lineTo(plotX, plotY);
            }
        }
        this.ctx.stroke();
        
        // Labels
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;center&apos;;
        this.ctx.fillText(&apos;x&apos;, this.width / 2, this.height - 10);
        
        this.ctx.save();
        this.ctx.translate(15, this.height / 2);
        this.ctx.rotate(-Math.PI / 2);
        this.ctx.fillText(&apos;f(x)&apos;, 0, 0);
        this.ctx.restore();
    }
}

// Multivariate Normal Demo
class MultivariateDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;multivariateCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.params = { mu1: 0, mu2: 0, sigma1: 1, sigma2: 1, rho: 0 };
        this.samples = [];
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const sliders = [&apos;mu1&apos;, &apos;mu2&apos;, &apos;sigma1&apos;, &apos;sigma2&apos;, &apos;rho&apos;];
        
        sliders.forEach(slider =&gt; {
            const element = document.getElementById(slider + &apos;-slider&apos;);
            element.addEventListener(&apos;input&apos;, (e) =&gt; {
                this.params[slider] = parseFloat(e.target.value);
                document.getElementById(slider + &apos;-value&apos;).textContent = this.params[slider].toFixed(1);
                this.updateStats();
                this.draw();
            });
        });
        
        document.getElementById(&apos;generate-samples&apos;).addEventListener(&apos;click&apos;, () =&gt; {
            this.generateSamples();
            this.draw();
        });
        
        this.updateStats();
    }
    
    updateStats() {
        const cov11 = this.params.sigma1 * this.params.sigma1;
        const cov12 = this.params.rho * this.params.sigma1 * this.params.sigma2;
        const cov22 = this.params.sigma2 * this.params.sigma2;
        const det = cov11 * cov22 - cov12 * cov12;
        
        document.getElementById(&apos;cov11&apos;).textContent = cov11.toFixed(3);
        document.getElementById(&apos;cov12&apos;).textContent = cov12.toFixed(3);
        document.getElementById(&apos;cov22&apos;).textContent = cov22.toFixed(3);
        document.getElementById(&apos;det-cov&apos;).textContent = det.toFixed(3);
    }
    
    generateSamples() {
        this.samples = [];
        const n = 100;
        
        for (let i = 0; i &lt; n; i++) {
            // Box-Muller transform
            const u1 = Math.random();
            const u2 = Math.random();
            const z1 = Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
            const z2 = Math.sqrt(-2 * Math.log(u1)) * Math.sin(2 * Math.PI * u2);
            
            // Transform to correlated normal
            const x1 = this.params.mu1 + this.params.sigma1 * z1;
            const x2 = this.params.mu2 + this.params.sigma2 * (this.params.rho * z1 + Math.sqrt(1 - this.params.rho * this.params.rho) * z2);
            
            this.samples.push([x1, x2]);
        }
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        const marginX = 50;
        const marginY = 50;
        const plotWidth = this.width - 2 * marginX;
        const plotHeight = this.height - 2 * marginY;
        
        // Draw axes
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        this.ctx.beginPath();
        this.ctx.moveTo(marginX, this.height - marginY);
        this.ctx.lineTo(this.width - marginX, this.height - marginY);
        this.ctx.moveTo(marginX, marginY);
        this.ctx.lineTo(marginX, this.height - marginY);
        this.ctx.stroke();
        
        // Draw contour ellipses
        const levels = [0.5, 1, 1.5, 2];
        const colors = [&apos;#ff9999&apos;, &apos;#ff6666&apos;, &apos;#ff3333&apos;, &apos;#ff0000&apos;];
        
        levels.forEach((level, idx) =&gt; {
            this.ctx.strokeStyle = colors[idx];
            this.ctx.lineWidth = 1;
            this.ctx.beginPath();
            
            const a = level * this.params.sigma1;
            const b = level * this.params.sigma2;
            const angle = 0.5 * Math.atan2(2 * this.params.rho * this.params.sigma1 * this.params.sigma2,
                                          this.params.sigma1 * this.params.sigma1 - this.params.sigma2 * this.params.sigma2);
            
            for (let i = 0; i &lt;= 100; i++) {
                const t = 2 * Math.PI * i / 100;
                const x = a * Math.cos(t) * Math.cos(angle) - b * Math.sin(t) * Math.sin(angle) + this.params.mu1;
                const y = a * Math.cos(t) * Math.sin(angle) + b * Math.sin(t) * Math.cos(angle) + this.params.mu2;
                
                const plotX = marginX + (x + 4) / 8 * plotWidth;
                const plotY = this.height - marginY - (y + 4) / 8 * plotHeight;
                
                if (i === 0) {
                    this.ctx.moveTo(plotX, plotY);
                } else {
                    this.ctx.lineTo(plotX, plotY);
                }
            }
            this.ctx.stroke();
        });
        
        // Draw samples
        if (this.samples.length &gt; 0) {
            this.ctx.fillStyle = &apos;#2196f3&apos;;
            this.samples.forEach(([x1, x2]) =&gt; {
                const plotX = marginX + (x1 + 4) / 8 * plotWidth;
                const plotY = this.height - marginY - (x2 + 4) / 8 * plotHeight;
                
                if (plotX &gt;= marginX &amp;&amp; plotX &lt;= this.width - marginX &amp;&amp;
                    plotY &gt;= marginY &amp;&amp; plotY &lt;= this.height - marginY) {
                    this.ctx.beginPath();
                    this.ctx.arc(plotX, plotY, 2, 0, 2 * Math.PI);
                    this.ctx.fill();
                }
            });
        }
        
        // Draw mean point
        const meanX = marginX + (this.params.mu1 + 4) / 8 * plotWidth;
        const meanY = this.height - marginY - (this.params.mu2 + 4) / 8 * plotHeight;
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.beginPath();
        this.ctx.arc(meanX, meanY, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Labels
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;center&apos;;
        this.ctx.fillText(&apos;X₁&apos;, this.width / 2, this.height - 10);
        
        this.ctx.save();
        this.ctx.translate(15, this.height / 2);
        this.ctx.rotate(-Math.PI / 2);
        this.ctx.fillText(&apos;X₂&apos;, 0, 0);
        this.ctx.restore();
    }
}

// Initialize when DOM is loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    new DiscreteDistributionsDemo();
    new ContinuousDistributionsDemo();
    new MultivariateDemo();
});
&lt;/script&gt;

&lt;style&gt;
input[type=&quot;range&quot;] {
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    background: #ddd;
    outline: none;
    border-radius: 5px;
}

input[type=&quot;range&quot;]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
}

input[type=&quot;range&quot;]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

canvas {
    border-radius: 5px;
}

.demo-container {
    margin: 20px 0;
}
&lt;/style&gt;

</content>
 </entry>
 
 <entry>
   <title>00-04-01 Lý Thuyết Xác Suất Cơ Bản</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_04_01_Basic_Probability_Theory/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_04_01_Basic_Probability_Theory</id>
   <content type="html">&lt;p&gt;Mọi quyết định dưới sự bất định — từ lọc thư rác, chẩn đoán y khoa bằng AI cho đến kiểm soát rủi ro tài chính — đều bắt đầu bằng việc định lượng niềm tin một cách nhất quán. Năm 1933, Andrey Kolmogorov đặt toàn bộ lý thuyết xác suất lên chỉ ba tiên đề giản dị về độ đo, biến trực giác “cơ hội” thành một hệ thống toán học sắc bén không thể tranh cãi.&lt;/p&gt;

&lt;p&gt;Bài học này hệ thống hóa không gian mẫu, tiên đề Kolmogorov, xác suất có điều kiện, định lý Bayes và kỳ vọng–phương sai, tạo nền tảng để bạn xây dựng các hàm mục tiêu xác suất.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-kiến-trúc-cơ-bản-của-xác-suất&quot;&gt;Kiến thức cần nhớ: Kiến trúc cơ bản của xác suất&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không gian mẫu và Tiên đề Kolmogorov:&lt;/strong&gt; Gắn mỗi biến cố \(A \subset \Omega\) với một số \(P(A) \in [0, 1]\) thỏa \(P(\Omega) = 1\) và tính cộng tính trên các biến cố xung khắc. Đây là điều kiện ràng buộc cho mọi vector phân phối xác suất thuộc đơn hình xác suất (probability simplex).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác suất có điều kiện và Định lý Bayes:&lt;/strong&gt; Cập nhật niềm tin khi có thêm bằng chứng mới: \(P(A\mid B) = \frac{P(B\mid A)P(A)}{P(B)}\). Đây là nền tảng của suy luận Bayes và tối ưu hóa hậu nghiệm cực đại (MAP).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính độc lập và tích xác suất:&lt;/strong&gt; Khi các mẫu dữ liệu \(x_1, \dots, x_n\) độc lập, xác suất đồng thời tách thành tích \(\prod P(x_i)\); lấy logarit lập tức biến tích thành &lt;strong&gt;tổng&lt;/strong&gt; \(\sum \log P(x_i)\) — dạng hàm cực kỳ thuận lợi cho tính đạo hàm và tối ưu hóa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kỳ vọng, phương sai và hiệp phương sai:&lt;/strong&gt; Tóm tắt trung tâm và độ phân tán của biến ngẫu nhiên; đặc biệt ma trận hiệp phương sai \(\Sigma\) luôn đối xứng bán xác định dương (\(\Sigma \succeq 0\)), là đầu vào trực tiếp của bài toán tối ưu danh mục Markowitz.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-định-lý-bayes-trong-hệ-thống-cảnh-báo-lỗi-hiếm&quot;&gt;Giải thích: Định lý Bayes trong hệ thống cảnh báo lỗi hiếm&lt;/h3&gt;

&lt;p&gt;Giả sử một dây chuyền sản xuất có tỷ lệ sản phẩm lỗi là \(2\%\) (\(P(D) = 0.02\)). Một cảm biến kiểm tra tự động có độ nhạy \(95\%\) (\(P(+\mid D) = 0.95\)) và tỷ lệ báo động giả \(5\%\) (\(P(+\mid \neg D) = 0.05\)). Khi cảm biến bật đèn đỏ (\(+\)), xác suất sản phẩm thực sự bị lỗi là bao nhiêu?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính xác suất rơi vào từng nhánh báo động đỏ:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Lỗi thật và báo đúng: \(P(D \cap +) = P(D)P(+\mid D) = 0.02 \times 0.95 = 0.019\).&lt;/li&gt;
      &lt;li&gt;Không lỗi nhưng báo giả: \(P(\neg D \cap +) = P(\neg D)P(+\mid \neg D) = 0.98 \times 0.05 = 0.049\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính xác suất toàn phần có báo động đỏ:&lt;/strong&gt;
\(P(+) = 0.019 + 0.049 = 0.068.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng định lý Bayes:&lt;/strong&gt;
\(P(D \mid +) = \frac{0.019}{0.068} = \frac{19}{68} \approx 0.2794 \text{ (khoảng } 27.94\%\text{)}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài học tối ưu hóa quyết định:&lt;/strong&gt; Dù cảm biến chính xác tới \(95\%\), hơn \(72\%\) cảnh báo đỏ vẫn là báo giả do tỷ lệ nền \(P(D)\) nhỏ! Khi thiết kế ngưỡng phân loại tối ưu, ta buộc phải cân đối cả xác suất tiên nghiệm lẫn chi phí sai lầm loại I và loại II.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;lý-thuyết-xác-suất-cơ-bản&quot;&gt;Lý thuyết xác suất cơ bản&lt;/h2&gt;

&lt;p&gt;Lý thuyết xác suất cung cấp khung toán học chặt chẽ để phân tích tính bất định — nền tảng của nhiều bài toán tối ưu hóa trong học máy và khoa học dữ liệu.&lt;/p&gt;

&lt;h3 id=&quot;1-không-gian-mẫu-và-biến-cố&quot;&gt;1. Không gian mẫu và biến cố&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Không gian mẫu (Ω)&lt;/strong&gt;: tập hợp tất cả các kết quả có thể xảy ra của một phép thử ngẫu nhiên.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Biến cố (A)&lt;/strong&gt;: một tập con của không gian mẫu, biểu diễn một nhóm kết quả cụ thể.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tung đồng xu: Ω = {S, N}&lt;/li&gt;
  &lt;li&gt;Tung xúc xắc: Ω = {1, 2, 3, 4, 5, 6}&lt;/li&gt;
  &lt;li&gt;Trường hợp liên tục: Ω = [0, 1] đối với biến ngẫu nhiên có phân phối đều trên [0, 1]&lt;/li&gt;
&lt;/ul&gt;

&lt;div id=&quot;sample-space-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Trực quan hóa không gian mẫu tương tác&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;sampleSpaceCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Trực quan hóa:&lt;/strong&gt; Nhấp để tạo mẫu ngẫu nhiên. Các màu khác nhau biểu diễn các biến cố khác nhau.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Loại phép thử&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;experiment&quot; value=&quot;coin&quot; checked=&quot;&quot; /&gt; Tung đồng xu
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;experiment&quot; value=&quot;dice&quot; /&gt; Tung xúc xắc
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;experiment&quot; value=&quot;uniform&quot; /&gt; Phân phối đều [0,1]
                    &lt;/label&gt;
                &lt;/div&gt;
                
                &lt;button id=&quot;generate-sample&quot; style=&quot;width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 10px;&quot;&gt;Tạo mẫu&lt;/button&gt;
                &lt;button id=&quot;clear-samples&quot; style=&quot;width: 100%; padding: 8px; background: #6c757d; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 15px;&quot;&gt;Xóa&lt;/button&gt;
                
                &lt;div id=&quot;sample-stats&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Thống kê:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Tổng mẫu: &lt;span id=&quot;total-samples&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Biến cố A: &lt;span id=&quot;event-a-count&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Biến cố B: &lt;span id=&quot;event-b-count&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(A) ≈ &lt;span id=&quot;prob-a&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(B) ≈ &lt;span id=&quot;prob-b&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;2-tiên-đề-xác-suất-tiên-đề-kolmogorov&quot;&gt;2. Tiên đề xác suất (Tiên đề Kolmogorov)&lt;/h3&gt;

&lt;p&gt;Mọi độ đo xác suất P đều phải thỏa mãn ba tiên đề sau:&lt;/p&gt;

&lt;h4 id=&quot;tiên-đề-1-tính-không-âm&quot;&gt;Tiên đề 1: Tính không âm&lt;/h4&gt;
&lt;p&gt;\(P(A) \geq 0 	ext{ với mọi biến cố } A\)&lt;/p&gt;

&lt;h4 id=&quot;tiên-đề-2-chuẩn-hóa&quot;&gt;Tiên đề 2: Chuẩn hóa&lt;/h4&gt;
&lt;p&gt;\(P(\Omega) = 1\)&lt;/p&gt;

&lt;h4 id=&quot;tiên-đề-3-tính-cộng-đếm-được&quot;&gt;Tiên đề 3: Tính cộng đếm được&lt;/h4&gt;
&lt;p&gt;Với mọi dãy biến cố đôi một xung khắc \(A_1, A_2, \ldots\):
\(P\left(igcup_{i=1}^{\infty} A_i
ight) = \sum_{i=1}^{\infty} P(A_i)\)&lt;/p&gt;

&lt;h3 id=&quot;3-tính-chất-và-quy-tắc-cơ-bản&quot;&gt;3. Tính chất và quy tắc cơ bản&lt;/h3&gt;

&lt;h4 id=&quot;quy-tắc-phần-bù&quot;&gt;Quy tắc phần bù&lt;/h4&gt;
&lt;p&gt;\(P(A^c) = 1 - P(A)\)&lt;/p&gt;

&lt;h4 id=&quot;quy-tắc-cộng&quot;&gt;Quy tắc cộng&lt;/h4&gt;
&lt;p&gt;Với hai biến cố A và B bất kỳ:
\(P(A \cup B) = P(A) + P(B) - P(A \cap B)\)&lt;/p&gt;

&lt;h4 id=&quot;quy-tắc-nhân&quot;&gt;Quy tắc nhân&lt;/h4&gt;
&lt;p&gt;\(P(A \cap B) = P(A|B) \cdot P(B) = P(B|A) \cdot P(A)\)&lt;/p&gt;

&lt;h3 id=&quot;4-xác-suất-có-điều-kiện&quot;&gt;4. Xác suất có điều kiện&lt;/h3&gt;

&lt;p&gt;Xác suất của biến cố A khi biết biến cố B đã xảy ra:&lt;/p&gt;

\[P(A|B) = rac{P(A \cap B)}{P(B)}, \quad P(B) &amp;gt; 0\]

&lt;p&gt;&lt;strong&gt;Diễn giải&lt;/strong&gt;: Xác suất có điều kiện cập nhật mức độ tin cậy về A khi ta có thêm thông tin rằng B đã xảy ra.&lt;/p&gt;

&lt;div id=&quot;conditional-prob-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Trực quan hóa xác suất có điều kiện&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;conditionalCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Biểu đồ Venn:&lt;/strong&gt; Hình tròn xanh là biến cố A, hình tròn đỏ là biến cố B. Phần giao màu tím biểu diễn A ∩ B.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Điều chỉnh xác suất&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;prob-a-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;P(A): &lt;span id=&quot;prob-a-value&quot;&gt;0.4&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;prob-a-slider&quot; min=&quot;0.1&quot; max=&quot;0.9&quot; step=&quot;0.05&quot; value=&quot;0.4&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;prob-b-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;P(B): &lt;span id=&quot;prob-b-value&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;prob-b-slider&quot; min=&quot;0.1&quot; max=&quot;0.9&quot; step=&quot;0.05&quot; value=&quot;0.5&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;overlap-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;Giao: &lt;span id=&quot;overlap-value&quot;&gt;0.2&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;overlap-slider&quot; min=&quot;0&quot; max=&quot;0.4&quot; step=&quot;0.05&quot; value=&quot;0.2&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div id=&quot;conditional-results&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Xác suất:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;P(A) = &lt;span id=&quot;display-prob-a&quot;&gt;0.400&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(B) = &lt;span id=&quot;display-prob-b&quot;&gt;0.500&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(A ∩ B) = &lt;span id=&quot;display-prob-ab&quot;&gt;0.200&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(A ∪ B) = &lt;span id=&quot;display-prob-union&quot;&gt;0.700&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;&lt;strong&gt;Xác suất có điều kiện:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;P(A|B) = &lt;span id=&quot;display-prob-a-given-b&quot;&gt;0.400&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(B|A) = &lt;span id=&quot;display-prob-b-given-a&quot;&gt;0.500&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;5-tính-độc-lập&quot;&gt;5. Tính độc lập&lt;/h3&gt;

&lt;p&gt;Hai biến cố A và B được gọi là &lt;strong&gt;độc lập&lt;/strong&gt; nếu:
\(P(A \cap B) = P(A) \cdot P(B)\)&lt;/p&gt;

&lt;p&gt;Tương đương (khi các xác suất khác 0):
\(P(A|B) = P(A) \quad 	ext{và} \quad P(B|A) = P(B)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Diễn giải&lt;/strong&gt;: Thông tin về việc một biến cố đã xảy ra không làm thay đổi xác suất của biến cố còn lại.&lt;/p&gt;

&lt;h3 id=&quot;6-biến-ngẫu-nhiên&quot;&gt;6. Biến ngẫu nhiên&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Biến ngẫu nhiên&lt;/strong&gt; X là một hàm ánh xạ mỗi kết quả trong không gian mẫu thành một số thực:
\(X: \Omega 
ightarrow \mathbb{R}\)&lt;/p&gt;

&lt;h4 id=&quot;các-loại-biến-ngẫu-nhiên&quot;&gt;Các loại biến ngẫu nhiên&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Rời rạc&lt;/strong&gt;: nhận các giá trị đếm được (ví dụ: số lần xuất hiện mặt sấp).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm khối xác suất (PMF): \(P(X = x)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Liên tục&lt;/strong&gt;: nhận các giá trị trên một khoảng số thực (ví dụ: chiều cao, cân nặng).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mật độ xác suất (PDF): \(f_X(x)\)&lt;/li&gt;
  &lt;li&gt;
\[P(a \leq X \leq b) = \int_a^b f_X(x) dx\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;7-kết-nối-với-tối-ưu-hóa&quot;&gt;7. Kết nối với tối ưu hóa&lt;/h3&gt;

&lt;p&gt;Lý thuyết xác suất gắn liền với tối ưu hóa qua nhiều bài toán điển hình:&lt;/p&gt;

&lt;h4 id=&quot;ước-lượng-hợp-lý-tối-đa&quot;&gt;Ước lượng hợp lý tối đa&lt;/h4&gt;
&lt;p&gt;Tìm tham số θ để cực đại hóa hàm hợp lý (likelihood):
\(\hat{	heta} = rg\max_	heta P(	ext{dữ liệu}|	heta)\)&lt;/p&gt;

&lt;h4 id=&quot;tối-ưu-hóa-giá-trị-kỳ-vọng&quot;&gt;Tối ưu hóa giá trị kỳ vọng&lt;/h4&gt;
&lt;p&gt;Cực tiểu hóa giá trị kỳ vọng của hàm mất mát:
\(\min_	heta \mathbb{E}[L(Y, f(X; 	heta))]\)&lt;/p&gt;

&lt;h4 id=&quot;tối-ưu-hóa-bayes&quot;&gt;Tối ưu hóa Bayes&lt;/h4&gt;
&lt;p&gt;Sử dụng phân phối xác suất để mô hình hóa tính bất định của hàm mục tiêu và định hướng tìm kiếm nghiệm tối ưu.&lt;/p&gt;

&lt;div id=&quot;optimization-connection&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f0f8ff;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Ví dụ xác suất trong tối ưu hóa&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;optimizationCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Ví dụ MLE:&lt;/strong&gt; Tìm tham số μ để cực đại hóa hàm hợp lý của dữ liệu quan sát từ phân phối Normal(μ, 1).
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Minh họa MLE&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;true-mu-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;μ thực: &lt;span id=&quot;true-mu-value&quot;&gt;2.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;true-mu-slider&quot; min=&quot;-2&quot; max=&quot;4&quot; step=&quot;0.1&quot; value=&quot;2.0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;sample-size-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;Kích thước mẫu: &lt;span id=&quot;sample-size-value&quot;&gt;20&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;sample-size-slider&quot; min=&quot;5&quot; max=&quot;100&quot; step=&quot;5&quot; value=&quot;20&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;button id=&quot;generate-mle-data&quot; style=&quot;width: 100%; padding: 10px; background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 15px;&quot;&gt;Tạo dữ liệu &amp;amp; tìm MLE&lt;/button&gt;
                
                &lt;div id=&quot;mle-results&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;μ thực: &lt;span id=&quot;display-true-mu&quot;&gt;2.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Trung bình mẫu: &lt;span id=&quot;sample-mean&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Ước lượng MLE: &lt;span id=&quot;mle-estimate&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Sai số: &lt;span id=&quot;mle-error&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;những-điểm-chính&quot;&gt;Những điểm chính&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nền tảng&lt;/strong&gt;: các tiên đề xác suất cung cấp cơ sở toán học để lập luận về tính bất định.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác suất có điều kiện&lt;/strong&gt;: công cụ cốt lõi để cập nhật niềm tin khi có thông tin mới.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính độc lập&lt;/strong&gt;: giúp đơn giản hóa tính toán và xây dựng các giả định mô hình.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến ngẫu nhiên&lt;/strong&gt;: cầu nối giữa không gian xác suất trừu tượng và các đại lượng đo lường cụ thể.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết nối với tối ưu hóa&lt;/strong&gt;: nhiều bài toán tối ưu hóa bắt nguồn trực tiếp từ mô hình hóa xác suất.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nắm vững những khái niệm cơ bản này giúp bạn sẵn sàng tiếp cận các chủ đề chuyên sâu hơn như suy luận Bayes, ước lượng hợp lý tối đa và tối ưu hóa ngẫu nhiên — những trụ cột của học máy và khoa học dữ liệu hiện đại.&lt;/p&gt;

&lt;script&gt;
// Sample Space Visualization
class SampleSpaceDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;sampleSpaceCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.samples = [];
        this.experimentType = &apos;coin&apos;;
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const radios = document.querySelectorAll(&apos;input[name=&quot;experiment&quot;]&apos;);
        const generateBtn = document.getElementById(&apos;generate-sample&apos;);
        const clearBtn = document.getElementById(&apos;clear-samples&apos;);
        
        radios.forEach(radio =&gt; {
            radio.addEventListener(&apos;change&apos;, (e) =&gt; {
                this.experimentType = e.target.value;
                this.samples = [];
                this.updateStats();
                this.draw();
            });
        });
        
        generateBtn.addEventListener(&apos;click&apos;, () =&gt; this.generateSample());
        clearBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.samples = [];
            this.updateStats();
            this.draw();
        });
        
        this.canvas.addEventListener(&apos;click&apos;, () =&gt; this.generateSample());
    }
    
    generateSample() {
        let sample;
        
        switch(this.experimentType) {
            case &apos;coin&apos;:
                sample = {
                    value: Math.random() &lt; 0.5 ? &apos;S&apos; : &apos;N&apos;,
                    x: Math.random() * (this.width - 40) + 20,
                    y: Math.random() * (this.height - 40) + 20,
                    eventA: Math.random() &lt; 0.5, // Biến cố A: Sấp
                    eventB: Math.random() &lt; 0.3  // Biến cố B: May mắn
                };
                break;
            case &apos;dice&apos;:
                const diceValue = Math.floor(Math.random() * 6) + 1;
                sample = {
                    value: diceValue,
                    x: Math.random() * (this.width - 40) + 20,
                    y: Math.random() * (this.height - 40) + 20,
                    eventA: diceValue &gt;= 4, // Biến cố A: 4, 5, hoặc 6
                    eventB: diceValue % 2 === 0 // Biến cố B: Chẵn
                };
                break;
            case &apos;uniform&apos;:
                const uniformValue = Math.random();
                sample = {
                    value: uniformValue.toFixed(3),
                    x: uniformValue * (this.width - 40) + 20,
                    y: Math.random() * (this.height - 40) + 20,
                    eventA: uniformValue &gt; 0.5, // Biến cố A: &gt; 0.5
                    eventB: uniformValue &lt; 0.7  // Biến cố B: &lt; 0.7
                };
                break;
        }
        
        this.samples.push(sample);
        this.updateStats();
        this.draw();
    }
    
    updateStats() {
        const total = this.samples.length;
        const eventACount = this.samples.filter(s =&gt; s.eventA).length;
        const eventBCount = this.samples.filter(s =&gt; s.eventB).length;
        
        document.getElementById(&apos;total-samples&apos;).textContent = total;
        document.getElementById(&apos;event-a-count&apos;).textContent = eventACount;
        document.getElementById(&apos;event-b-count&apos;).textContent = eventBCount;
        document.getElementById(&apos;prob-a&apos;).textContent = total &gt; 0 ? (eventACount / total).toFixed(3) : &apos;0.000&apos;;
        document.getElementById(&apos;prob-b&apos;).textContent = total &gt; 0 ? (eventBCount / total).toFixed(3) : &apos;0.000&apos;;
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        // Draw background
        this.ctx.fillStyle = &apos;#f8f9fa&apos;;
        this.ctx.fillRect(0, 0, this.width, this.height);
        
        // Draw samples
        this.samples.forEach(sample =&gt; {
            // Determine color based on events
            let color = &apos;#666&apos;;
            if (sample.eventA &amp;&amp; sample.eventB) color = &apos;#9c27b0&apos;; // Cả hai biến cố
            else if (sample.eventA) color = &apos;#2196f3&apos;; // Chỉ biến cố A
            else if (sample.eventB) color = &apos;#f44336&apos;; // Chỉ biến cố B
            
            this.ctx.fillStyle = color;
            this.ctx.beginPath();
            this.ctx.arc(sample.x, sample.y, 5, 0, 2 * Math.PI);
            this.ctx.fill();
            
            // Draw value
            this.ctx.fillStyle = &apos;#000&apos;;
            this.ctx.font = &apos;10px Arial&apos;;
            this.ctx.textAlign = &apos;center&apos;;
            this.ctx.fillText(sample.value, sample.x, sample.y - 8);
        });
        
        // Draw legend
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;left&apos;;
        this.ctx.fillText(&apos;Chú thích:&apos;, 10, 20);
        
        this.ctx.fillStyle = &apos;#2196f3&apos;;
        this.ctx.beginPath();
        this.ctx.arc(20, 35, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.fillText(&apos;Chỉ biến cố A&apos;, 30, 38);
        
        this.ctx.fillStyle = &apos;#f44336&apos;;
        this.ctx.beginPath();
        this.ctx.arc(20, 50, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.fillText(&apos;Chỉ biến cố B&apos;, 30, 53);
        
        this.ctx.fillStyle = &apos;#9c27b0&apos;;
        this.ctx.beginPath();
        this.ctx.arc(20, 65, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.fillText(&apos;Cả A và B&apos;, 30, 68);
    }
}

// Conditional Probability Visualization
class ConditionalProbDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;conditionalCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.probA = 0.4;
        this.probB = 0.5;
        this.overlap = 0.2;
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const probASlider = document.getElementById(&apos;prob-a-slider&apos;);
        const probBSlider = document.getElementById(&apos;prob-b-slider&apos;);
        const overlapSlider = document.getElementById(&apos;overlap-slider&apos;);
        
        probASlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.probA = parseFloat(e.target.value);
            document.getElementById(&apos;prob-a-value&apos;).textContent = this.probA.toFixed(1);
            this.updateCalculations();
            this.draw();
        });
        
        probBSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.probB = parseFloat(e.target.value);
            document.getElementById(&apos;prob-b-value&apos;).textContent = this.probB.toFixed(1);
            this.updateCalculations();
            this.draw();
        });
        
        overlapSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.overlap = parseFloat(e.target.value);
            document.getElementById(&apos;overlap-value&apos;).textContent = this.overlap.toFixed(1);
            // Ensure overlap doesn&apos;t exceed min(probA, probB)
            const maxOverlap = Math.min(this.probA, this.probB);
            if (this.overlap &gt; maxOverlap) {
                this.overlap = maxOverlap;
                overlapSlider.value = this.overlap;
                document.getElementById(&apos;overlap-value&apos;).textContent = this.overlap.toFixed(1);
            }
            this.updateCalculations();
            this.draw();
        });
        
        this.updateCalculations();
    }
    
    updateCalculations() {
        const probUnion = this.probA + this.probB - this.overlap;
        const probAGivenB = this.probB &gt; 0 ? this.overlap / this.probB : 0;
        const probBGivenA = this.probA &gt; 0 ? this.overlap / this.probA : 0;
        
        document.getElementById(&apos;display-prob-a&apos;).textContent = this.probA.toFixed(3);
        document.getElementById(&apos;display-prob-b&apos;).textContent = this.probB.toFixed(3);
        document.getElementById(&apos;display-prob-ab&apos;).textContent = this.overlap.toFixed(3);
        document.getElementById(&apos;display-prob-union&apos;).textContent = probUnion.toFixed(3);
        document.getElementById(&apos;display-prob-a-given-b&apos;).textContent = probAGivenB.toFixed(3);
        document.getElementById(&apos;display-prob-b-given-a&apos;).textContent = probBGivenA.toFixed(3);
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        // Draw universe rectangle
        this.ctx.strokeStyle = &apos;#000&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.strokeRect(50, 50, 300, 200);
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;14px Arial&apos;;
        this.ctx.fillText(&apos;Ω (Không gian mẫu)&apos;, 55, 45);
        
        // Calculate circle parameters
        const centerAX = 150;
        const centerAY = 150;
        const centerBX = 250;
        const centerBY = 150;
        
        // Calculate radii based on probabilities (area proportional to probability)
        const radiusA = Math.sqrt(this.probA * 10000 / Math.PI);
        const radiusB = Math.sqrt(this.probB * 10000 / Math.PI);
        
        // Draw circle A
        this.ctx.globalAlpha = 0.3;
        this.ctx.fillStyle = &apos;#2196f3&apos;;
        this.ctx.beginPath();
        this.ctx.arc(centerAX, centerAY, radiusA, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Draw circle B
        this.ctx.fillStyle = &apos;#f44336&apos;;
        this.ctx.beginPath();
        this.ctx.arc(centerBX, centerBY, radiusB, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Draw intersection (approximate)
        if (this.overlap &gt; 0) {
            this.ctx.fillStyle = &apos;#9c27b0&apos;;
            const overlapRadius = Math.sqrt(this.overlap * 5000 / Math.PI);
            this.ctx.beginPath();
            this.ctx.arc((centerAX + centerBX) / 2, (centerAY + centerBY) / 2, overlapRadius, 0, 2 * Math.PI);
            this.ctx.fill();
        }
        
        this.ctx.globalAlpha = 1.0;
        
        // Draw circle outlines
        this.ctx.strokeStyle = &apos;#2196f3&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        this.ctx.arc(centerAX, centerAY, radiusA, 0, 2 * Math.PI);
        this.ctx.stroke();
        
        this.ctx.strokeStyle = &apos;#f44336&apos;;
        this.ctx.beginPath();
        this.ctx.arc(centerBX, centerBY, radiusB, 0, 2 * Math.PI);
        this.ctx.stroke();
        
        // Labels
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;16px Arial&apos;;
        this.ctx.fillText(&apos;A&apos;, centerAX - 40, centerAY);
        this.ctx.fillText(&apos;B&apos;, centerBX + 30, centerBY);
        
        if (this.overlap &gt; 0) {
            this.ctx.fillText(&apos;A∩B&apos;, (centerAX + centerBX) / 2 - 15, (centerAY + centerBY) / 2 + 5);
        }
    }
}

// MLE Optimization Demo
class MLEDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;optimizationCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.trueMu = 2.0;
        this.sampleSize = 20;
        this.data = [];
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const trueMuSlider = document.getElementById(&apos;true-mu-slider&apos;);
        const sampleSizeSlider = document.getElementById(&apos;sample-size-slider&apos;);
        const generateBtn = document.getElementById(&apos;generate-mle-data&apos;);
        
        trueMuSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.trueMu = parseFloat(e.target.value);
            document.getElementById(&apos;true-mu-value&apos;).textContent = this.trueMu.toFixed(1);
            document.getElementById(&apos;display-true-mu&apos;).textContent = this.trueMu.toFixed(3);
        });
        
        sampleSizeSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.sampleSize = parseInt(e.target.value);
            document.getElementById(&apos;sample-size-value&apos;).textContent = this.sampleSize;
        });
        
        generateBtn.addEventListener(&apos;click&apos;, () =&gt; this.generateDataAndFindMLE());
    }
    
    generateDataAndFindMLE() {
        // Generate data from Normal(trueMu, 1)
        this.data = [];
        for (let i = 0; i &lt; this.sampleSize; i++) {
            // Box-Muller transform for normal distribution
            const u1 = Math.random();
            const u2 = Math.random();
            const z = Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
            this.data.push(this.trueMu + z); // Normal(trueMu, 1)
        }
        
        // Calculate MLE (sample mean for normal distribution)
        const sampleMean = this.data.reduce((sum, x) =&gt; sum + x, 0) / this.data.length;
        const error = Math.abs(sampleMean - this.trueMu);
        
        // Update display
        document.getElementById(&apos;sample-mean&apos;).textContent = sampleMean.toFixed(3);
        document.getElementById(&apos;mle-estimate&apos;).textContent = sampleMean.toFixed(3);
        document.getElementById(&apos;mle-error&apos;).textContent = error.toFixed(3);
        
        this.draw();
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        if (this.data.length === 0) {
            this.ctx.fillStyle = &apos;#666&apos;;
            this.ctx.font = &apos;16px Arial&apos;;
            this.ctx.textAlign = &apos;center&apos;;
            this.ctx.fillText(&apos;Nhấp &quot;Tạo Dữ Liệu &amp; Tìm MLE&quot; để bắt đầu&apos;, this.width / 2, this.height / 2);
            return;
        }
        
        // Draw axes
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        const marginX = 50;
        const marginY = 50;
        const plotWidth = this.width - 2 * marginX;
        const plotHeight = this.height - 2 * marginY;
        
        // X-axis
        this.ctx.beginPath();
        this.ctx.moveTo(marginX, this.height - marginY);
        this.ctx.lineTo(this.width - marginX, this.height - marginY);
        this.ctx.stroke();
        
        // Y-axis
        this.ctx.beginPath();
        this.ctx.moveTo(marginX, marginY);
        this.ctx.lineTo(marginX, this.height - marginY);
        this.ctx.stroke();
        
        // Find data range
        const minX = Math.min(...this.data) - 1;
        const maxX = Math.max(...this.data) + 1;
        
        // Draw likelihood function
        this.ctx.strokeStyle = &apos;#2196f3&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        
        for (let i = 0; i &lt;= 100; i++) {
            const mu = minX + (maxX - minX) * i / 100;
            let logLikelihood = 0;
            
            // Calculate log-likelihood
            for (const x of this.data) {
                logLikelihood -= 0.5 * Math.log(2 * Math.PI);
                logLikelihood -= 0.5 * (x - mu) * (x - mu);
            }
            
            const x = marginX + (mu - minX) / (maxX - minX) * plotWidth;
            const y = this.height - marginY - (logLikelihood - (-this.data.length * 2)) / (this.data.length) * plotHeight * 0.8;
            
            if (i === 0) {
                this.ctx.moveTo(x, y);
            } else {
                this.ctx.lineTo(x, y);
            }
        }
        this.ctx.stroke();
        
        // Mark MLE
        const sampleMean = this.data.reduce((sum, x) =&gt; sum + x, 0) / this.data.length;
        const mleX = marginX + (sampleMean - minX) / (maxX - minX) * plotWidth;
        
        this.ctx.strokeStyle = &apos;#f44336&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        this.ctx.moveTo(mleX, marginY);
        this.ctx.lineTo(mleX, this.height - marginY);
        this.ctx.stroke();
        
        // Mark true value
        const trueX = marginX + (this.trueMu - minX) / (maxX - minX) * plotWidth;
        this.ctx.strokeStyle = &apos;#4caf50&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.setLineDash([5, 5]);
        this.ctx.beginPath();
        this.ctx.moveTo(trueX, marginY);
        this.ctx.lineTo(trueX, this.height - marginY);
        this.ctx.stroke();
        this.ctx.setLineDash([]);
        
        // Draw data points
        this.ctx.fillStyle = &apos;#666&apos;;
        for (const x of this.data) {
            const pointX = marginX + (x - minX) / (maxX - minX) * plotWidth;
            this.ctx.beginPath();
            this.ctx.arc(pointX, this.height - marginY + 10, 2, 0, 2 * Math.PI);
            this.ctx.fill();
        }
        
        // Labels
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;center&apos;;
        this.ctx.fillText(&apos;μ&apos;, this.width / 2, this.height - 10);
        
        this.ctx.save();
        this.ctx.translate(15, this.height / 2);
        this.ctx.rotate(-Math.PI / 2);
        this.ctx.fillText(&apos;Log-Likelihood&apos;, 0, 0);
        this.ctx.restore();
        
        // Legend
        this.ctx.textAlign = &apos;left&apos;;
        this.ctx.fillText(&apos;— Likelihood&apos;, 10, 20);
        this.ctx.fillStyle = &apos;#f44336&apos;;
        this.ctx.fillText(&apos;— MLE&apos;, 10, 35);
        this.ctx.fillStyle = &apos;#4caf50&apos;;
        this.ctx.fillText(&apos;--- μ Thực&apos;, 10, 50);
    }
}

// Initialize when DOM is loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    new SampleSpaceDemo();
    new ConditionalProbDemo();
    new MLEDemo();
});
&lt;/script&gt;

&lt;style&gt;
input[type=&quot;range&quot;] {
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    background: #ddd;
    outline: none;
    border-radius: 5px;
}

input[type=&quot;range&quot;]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
}

input[type=&quot;range&quot;]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

canvas {
    border-radius: 5px;
}

.demo-container {
    margin: 20px 0;
}
&lt;/style&gt;

</content>
 </entry>
 
 <entry>
   <title>00-03 Giải tích thực và Lý thuyết tập hợp</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_03_Real_Analysis_and_Set_Theory/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_03_Real_Analysis_and_Set_Theory</id>
   <content type="html">&lt;p&gt;Trước khi viết một dòng code để tìm giá trị nhỏ nhất của hàm \(f(x)\) trên tập \(S\), nhà toán học tối ưu luôn hỏi một câu tưởng chừng đơn giản nhưng vô cùng hiểm hóc: &lt;em&gt;liệu giá trị nhỏ nhất ấy có thực sự tồn tại không?&lt;/em&gt; Một bài toán thiết kế thiếu cẩn thận có thể có cận dưới \(\inf\) bằng \(0\) nhưng không bao giờ chạm tới \(0\) — khiến mọi thuật toán chạy vô tận mà không hội tụ về một điểm hợp lệ nào.&lt;/p&gt;

&lt;p&gt;Phần 00-03 trang bị ngôn ngữ tập hợp và tôpô thực để bạn phân biệt rạch ròi giữa \(\inf\) và \(\min\), giữa biên và phần trong, làm bệ phóng trực tiếp cho Chương 02 về tập lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-vì-sao-tối-ưu-hóa-cần-tập-hợp-và-tôpô&quot;&gt;Kiến thức cần nhớ: Vì sao tối ưu hóa cần tập hợp và tôpô?&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ngôn ngữ tập hợp và miền khả thi:&lt;/strong&gt; Mọi hệ ràng buộc \(g_i(x) \le 0, h_j(x) = 0\) thực chất định nghĩa miền khả thi \(D\) dưới dạng &lt;strong&gt;giao&lt;/strong&gt; của nhiều tập con trong \(\mathbb{R}^n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập mở, tập đóng và biên (Open, Closed, Boundary):&lt;/strong&gt; Xác định khi nào ta có thể nhích biến theo mọi hướng mà vẫn ở trong miền khả thi (điểm trong), và khi nào ràng buộc bị “chạm ngưỡng” (điểm biên).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính compact và Định lý Weierstrass:&lt;/strong&gt; Trong \(\mathbb{R}^n\), tập compact đồng nghĩa với &lt;strong&gt;đóng và bị chặn&lt;/strong&gt; (định lý Heine–Borel). Mọi hàm liên tục trên tập compact khác rỗng luôn đạt giá trị nhỏ nhất và lớn nhất toàn cục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cận dưới đúng (\(\inf\)) so với Cực tiểu (\(\min\)):&lt;/strong&gt; Giúp phân biệt trường hợp giá trị tối ưu hữu hạn nhưng không đạt được tại bất kỳ điểm khả thi nào.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-một-ranh-giới-đóng-hay-mở-quyết-định-sự-tồn-tại-của-nghiệm&quot;&gt;Giải thích: Một ranh giới đóng hay mở quyết định sự tồn tại của nghiệm&lt;/h3&gt;

&lt;p&gt;So sánh hai bài toán tối ưu cực kỳ đơn giản trên trục số thực:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán A (miền không đóng):&lt;/strong&gt; \(\min_{x \in (0, 1]} f(x) = x\).
    &lt;ul&gt;
      &lt;li&gt;Với mọi \(x \in (0, 1]\), ta có \(f(x) &amp;gt; 0\). Nếu bạn thử \(x = 0.01\), luôn có \(x = 0.001\) nhỏ hơn; thử \(10^{-9}\), luôn có \(10^{-10}\) nhỏ hơn.&lt;/li&gt;
      &lt;li&gt;Vậy \(\inf_{x \in (0, 1]} f(x) = 0\), nhưng &lt;strong&gt;không tồn tại&lt;/strong&gt; \(x^* \in (0, 1]\) đạt \(f(x^*) = 0\) vì \(0 \notin (0, 1]\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán B (đóng lại thành tập compact):&lt;/strong&gt; \(\min_{x \in [0, 1]} f(x) = x\).
    &lt;ul&gt;
      &lt;li&gt;Miền \([0, 1]\) vừa đóng vừa bị chặn (compact), hàm \(f(x) = x\) liên tục.&lt;/li&gt;
      &lt;li&gt;Theo định lý Weierstrass, cực tiểu toàn cục chắc chắn tồn tại và đạt tại đúng điểm biên \(x^* = 0\) với \(\min f = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thông điệp thực hành:&lt;/strong&gt; Đó là lý do trong dạng chuẩn của bài toán tối ưu hóa, ta luôn viết ràng buộc bất đẳng thức lỏng \(g_i(x) \le 0\) (tạo tập đóng) thay vì bất đẳng thức chặt \(g_i(x) &amp;lt; 0\) (tạo tập mở dễ mất nghiệm).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Tối ưu hóa lồi là giải tích trên &lt;em&gt;tập hợp&lt;/em&gt;: miền khả thi, biểu đồ trên (epigraph) và nón nhân tử đối ngẫu. Trước khi Chương 02 định nghĩa tập lồi, ta cần nắm vững ngôn ngữ về tập mở, tập đóng, phần trong và dãy hội tụ.&lt;/p&gt;

&lt;h2 id=&quot;vai-trò-của-phần-này&quot;&gt;Vai trò của phần này&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tập khả thi&lt;/strong&gt; là một tập con của \(\mathbb{R}^n\). Tính đóng quyết định liệu giới hạn của một dãy điểm giảm dần có nằm &lt;em&gt;trong&lt;/em&gt; tập khả thi hay không; tính đóng kết hợp với tính bị chặn (định lý Heine–Borel trong không gian hữu hạn chiều) đảm bảo hàm liên tục đạt giá trị nhỏ nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập mở và phần trong&lt;/strong&gt; xuất hiện trong điều kiện chính quy ràng buộc (điều kiện Slater: tồn tại điểm nằm trong phần trong tương đối của tập ràng buộc bất đẳng thức), giúp điều kiện KKT trở thành điều kiện cần ở Chương 12.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dãy và giới hạn&lt;/strong&gt; là công cụ để phát biểu chặt chẽ sự hội tụ “\(x^{(k)}\to x^\star\)” của các thuật toán như gradient descent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Một tập \(C\subseteq\mathbb{R}^n\) được gọi là &lt;strong&gt;đóng&lt;/strong&gt; nếu nó chứa mọi điểm giới hạn của mình, &lt;strong&gt;mở&lt;/strong&gt; nếu là lân cận của mỗi điểm thuộc nó, và &lt;strong&gt;compact&lt;/strong&gt; (trong \(\mathbb{R}^n\)) khi và chỉ khi nó vừa đóng vừa bị chặn. &lt;strong&gt;Biểu đồ trên&lt;/strong&gt; (epigraph)&lt;/p&gt;

\[\operatorname{epi} f = \bigl\{(x,t): f(x)\le t\bigr\}\]

&lt;p&gt;là một tập con trong \(\mathbb{R}^{n+1}\); hàm \(f\) nửa liên tục dưới khi và chỉ khi \(\operatorname{epi} f\) là tập đóng. Nhận định ngắn gọn này chính là nền tảng giải tích để trả lời câu hỏi: liệu một hàm mất mát có đạt được cận dưới đúng (infimum) hay không.&lt;/p&gt;

&lt;h2 id=&quot;các-bài-trong-phần-này&quot;&gt;Các bài trong phần này&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Cơ sở lý thuyết tập hợp (hợp, giao, phần bù, tích — phép toán trên các tập ràng buộc)&lt;/li&gt;
  &lt;li&gt;Tôpô trong giải tích thực (tập mở/đóng, phần trong, tính compact, dãy hội tụ)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sau hai bài này, bạn cần trả lời được ngay: tập \(\{x: \|x\|_2 \le 1\}\) có compact không, và tập \(\{x: \|x\|_2 &amp;lt; 1\}\) có thể chứa cực tiểu của một hàm đang giảm dần về phía biên hay không.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-03-02 Tôpô trong Giải tích thực</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_03_02_Topology_in_Real_Analysis/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_03_02_Topology_in_Real_Analysis</id>
   <content type="html">&lt;p&gt;Vì sao một bài toán tối ưu có thể “suýt” có nghiệm nhưng lại không bao giờ đạt được? Vì sao điều kiện Slater trong đối ngẫu Lagrange đòi hỏi tồn tại một điểm nằm &lt;strong&gt;chặt bên trong&lt;/strong&gt; (strictly interior) miền khả thi chứ không chỉ nằm trên biên? Câu trả lời nằm ở &lt;strong&gt;tôpô trong giải tích thực&lt;/strong&gt; — ngành học nghiên cứu về sự “gần nhau”, lân cận, tập mở, tập đóng, điểm biên và tính compact.&lt;/p&gt;

&lt;p&gt;Nắm vững trực giác tôpô sẽ giúp bạn đọc các định lý về siêu phẳng phân tách, điều kiện KKT và hội tụ dãy điểm một cách nhẹ nhàng và chính xác.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-khái-niệm-tôpô-cốt-lõi-cho-tối-ưu-hóa&quot;&gt;Kiến thức cần nhớ: Bốn khái niệm tôpô cốt lõi cho tối ưu hóa&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không gian metric và hình cầu mở:&lt;/strong&gt; Quả cầu mở \(B(x, r) = \{y : \|y - x\| &amp;lt; r\}\) định nghĩa “vùng đệm an toàn” quanh điểm \(x\). Một điểm nằm trong phần trong (\(\operatorname{int} S\)) nếu có thể vẽ một quả cầu nhỏ quanh nó nằm trọn trong \(S\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập đóng và bao đóng (\(\operatorname{cl} S\)):&lt;/strong&gt; Tập đóng chứa trọn mọi điểm giới hạn của các dãy hội tụ trong nó. Nhờ tính đóng, nếu thuật toán tạo ra dãy điểm khả thi \(x^{(k)} \to x^*\), thì giới hạn \(x^*\) chắc chắn vẫn là nghiệm khả thi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biên của tập hợp (\(\partial S = \operatorname{cl} S \setminus \operatorname{int} S\)):&lt;/strong&gt; Nơi các ràng buộc bất đẳng thức trở thành đẳng thức chặt (active constraints). Trong quy hoạch tuyến tính, nghiệm tối ưu luôn nằm trên biên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính compact (Đóng + Bị chặn trong \(\mathbb{R}^n\)):&lt;/strong&gt; Theo định lý Bolzano–Weierstrass, mọi dãy trong tập compact đều có dãy con hội tụ về một điểm thuộc tập đó — chìa khóa bảo đảm tồn tại nghiệm tối ưu toàn cục.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chiếu-điểm-3-0-lên-hình-tròn-mở-so-với-hình-tròn-đóng&quot;&gt;Giải thích: Chiếu điểm \((3, 0)\) lên hình tròn mở so với hình tròn đóng&lt;/h3&gt;

&lt;p&gt;Xét tập mở \(S = \{(x_1, x_2) \in \mathbb{R}^2 : x_1^2 + x_2^2 &amp;lt; 4\}\) (hình tròn mở tâm gốc tọa độ, bán kính \(2\)) và bài toán tìm điểm gần \(p = (3, 0)\) nhất, tức cực tiểu hóa \(f(x) = \|x - p\|_2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Xác định các thành phần tôpô của \(S\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Phần trong: \(\operatorname{int}(S) = S\) (vì \(S\) là tập mở).&lt;/li&gt;
      &lt;li&gt;Bao đóng: \(\operatorname{cl}(S) = \{x \in \mathbb{R}^2 : \|x\|_2 \le 2\}\) (tập compact: đóng và bị chặn).&lt;/li&gt;
      &lt;li&gt;Biên: \(\partial S = \{x \in \mathbb{R}^2 : \|x\|_2 = 2\}\) (đường tròn bán kính \(2\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu trên tập mở \(S\):&lt;/strong&gt; Xét dãy khả thi \(x^{(k)} = \left(2 - \frac{1}{k}, 0\right) \in S\). Khoảng cách đến \(p = (3, 0)\) là:
\(f(x^{(k)}) = 3 - \left(2 - \frac{1}{k}\right) = 1 + \frac{1}{k} \xrightarrow{k \to \infty} 1.\)
Cận dưới đúng là \(\inf_{x \in S} f(x) = 1\), nhưng không có điểm nào &lt;em&gt;trong \(S\)&lt;/em&gt; đạt khoảng cách \(1\) vì điểm giới hạn \((2, 0)\) rơi ra ngoài \(S\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu trên bao đóng compact \(\operatorname{cl}(S)\):&lt;/strong&gt; Vì \((2, 0) \in \partial S \subset \operatorname{cl}(S)\), bài toán đạt cực tiểu duy nhất tại \(x^* = (2, 0)\) với \(f(x^*) = 1\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài học này trình bày các khái niệm tôpô thiết yếu trong giải tích thực — nền tảng để hiểu cấu trúc vùng khả thi, tính liên tục và sự tồn tại nghiệm tối ưu trong các bài toán tối ưu hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;giới-thiệu-về-tôpô&quot;&gt;Giới thiệu về tôpô&lt;/h2&gt;

&lt;p&gt;Tôpô nghiên cứu những tính chất của không gian được bảo toàn dưới các phép biến đổi liên tục. Trong tối ưu hóa, các khái niệm tôpô giúp ta phân tích cấu trúc của vùng khả thi và hành vi của hàm số, đặc biệt là điều kiện để nghiệm tối ưu tồn tại.&lt;/p&gt;

&lt;h3 id=&quot;không-gian-metric-và-khoảng-cách&quot;&gt;Không gian metric và khoảng cách&lt;/h3&gt;

&lt;p&gt;Trước khi xét các khái niệm tôpô, ta cần định nghĩa khoảng cách. Trong \(\mathbb{R}^n\), &lt;strong&gt;khoảng cách Euclid&lt;/strong&gt; chuẩn giữa hai điểm \(\mathbf{x}\) và \(\mathbf{y}\) là:&lt;/p&gt;

\[d(\mathbf{x}, \mathbf{y}) = \|\mathbf{x} - \mathbf{y}\|_2 = \sqrt{\sum_{i=1}^n (x_i - y_i)^2}\]

&lt;h3 id=&quot;hình-cầu-mở-và-lân-cận&quot;&gt;Hình cầu mở và lân cận&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hình cầu mở&lt;/strong&gt; tâm \(\mathbf{x}_0\) với bán kính \(\epsilon &amp;gt; 0\) được định nghĩa là:&lt;/p&gt;

\[B(\mathbf{x}_0, \epsilon) = \{\mathbf{y} \in \mathbb{R}^n : d(\mathbf{x}_0, \mathbf{y}) &amp;lt; \epsilon\}\]

&lt;p&gt;Đây là tập hợp tất cả các điểm cách \(\mathbf{x}_0\) một khoảng nhỏ hơn hẳn \(\epsilon\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Trong \(\mathbb{R}\): \(B(0, 1) = (-1, 1)\) (khoảng mở).&lt;/li&gt;
  &lt;li&gt;Trong \(\mathbb{R}^2\): \(B(\mathbf{0}, 1) = \{(x, y) : x^2 + y^2 &amp;lt; 1\}\) (đĩa đơn vị mở).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tập-mở&quot;&gt;Tập mở&lt;/h2&gt;

&lt;p&gt;Một &lt;strong&gt;tập mở&lt;/strong&gt; là tập hợp &lt;strong&gt;không chứa bất kỳ điểm biên nào của nó&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa-chính-thức&quot;&gt;Định nghĩa chính thức&lt;/h3&gt;

&lt;p&gt;Một tập \(S \subseteq \mathbb{R}^n\) được gọi là &lt;strong&gt;mở&lt;/strong&gt; nếu với mọi điểm \(\mathbf{x} \in S\), tồn tại một số thực dương \(\epsilon &amp;gt; 0\) sao cho hình cầu mở \(B(\mathbf{x}, \epsilon)\) nằm hoàn toàn trong \(S\):&lt;/p&gt;

\[\forall \mathbf{x} \in S, \exists \epsilon &amp;gt; 0 : B(\mathbf{x}, \epsilon) \subseteq S\]

&lt;h3 id=&quot;ý-nghĩa-trực-quan&quot;&gt;Ý nghĩa trực quan&lt;/h3&gt;

&lt;p&gt;Với một tập mở, tại bất kỳ điểm nào thuộc tập, ta luôn có thể dịch chuyển một đoạn đủ nhỏ theo mọi hướng mà vẫn nằm bên trong tập hợp đó.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-về-tập-mở&quot;&gt;Ví dụ về tập mở&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Trong \(\mathbb{R}\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[(0, 1) = \{x : 0 &amp;lt; x &amp;lt; 1\}\]
  &lt;/li&gt;
  &lt;li&gt;
\[(-\infty, 5) = \{x : x &amp;lt; 5\}\]
  &lt;/li&gt;
  &lt;li&gt;Toàn bộ \(\mathbb{R}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trong \(\mathbb{R}^2\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\{(x, y) : x^2 + y^2 &amp;lt; 1\}\) (đĩa đơn vị mở)&lt;/li&gt;
  &lt;li&gt;\(\{(x, y) : x &amp;gt; 0, y &amp;gt; 0\}\) (góc phần tư thứ nhất, không bao gồm các trục tọa độ)&lt;/li&gt;
  &lt;li&gt;Toàn bộ \(\mathbb{R}^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trong \(\mathbb{R}^n\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Mọi hình cầu mở \(B(\mathbf{x}_0, r)\)&lt;/li&gt;
  &lt;li&gt;Toàn bộ \(\mathbb{R}^n\)&lt;/li&gt;
  &lt;li&gt;\(\emptyset\) (tập rỗng, là tập mở theo quy ước hiển nhiên)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tính-chất-của-tập-mở&quot;&gt;Tính chất của tập mở&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Hợp của một họ bất kỳ các tập mở là tập mở.&lt;/li&gt;
  &lt;li&gt;Giao của hữu hạn các tập mở là tập mở.&lt;/li&gt;
  &lt;li&gt;\(\mathbb{R}^n\) và \(\emptyset\) đều là tập mở.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tập-đóng&quot;&gt;Tập đóng&lt;/h2&gt;

&lt;p&gt;Một &lt;strong&gt;tập đóng&lt;/strong&gt; là tập hợp chứa mọi điểm biên của nó. Tương đương, tập \(S\) đóng khi và chỉ khi phần bù \(\mathbb{R}^n \setminus S\) của nó là một &lt;strong&gt;tập mở&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa-theo-dãy&quot;&gt;Định nghĩa theo dãy&lt;/h3&gt;

&lt;p&gt;Một tập \(S\) là &lt;strong&gt;đóng&lt;/strong&gt; nếu nó chứa mọi điểm giới hạn của mình. Nghĩa là, nếu một dãy điểm \((\mathbf{x}_n)\) trong \(S\) hội tụ về \(\mathbf{x}\) thì \(\mathbf{x}\) cũng thuộc \(S\):&lt;/p&gt;

\[\text{Nếu } \mathbf{x}_n \in S \text{ với mọi } n \text{ và } \lim_{n \to \infty} \mathbf{x}_n = \mathbf{x}, \text{ thì } \mathbf{x} \in S\]

&lt;h3 id=&quot;ví-dụ-về-tập-đóng&quot;&gt;Ví dụ về tập đóng&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Trong \(\mathbb{R}\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[[0, 1] = \{x : 0 \leq x \leq 1\}\]
  &lt;/li&gt;
  &lt;li&gt;
\[[a, \infty) = \{x : x \geq a\}\]
  &lt;/li&gt;
  &lt;li&gt;\(\{0\}\) (tập gồm một điểm)&lt;/li&gt;
  &lt;li&gt;\(\mathbb{Z}\) (tập các số nguyên)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trong \(\mathbb{R}^2\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\{(x, y) : x^2 + y^2 \leq 1\}\) (đĩa đơn vị đóng)&lt;/li&gt;
  &lt;li&gt;\(\{(x, y) : x \geq 0, y \geq 0\}\) (góc phần tư thứ nhất, bao gồm cả các trục tọa độ)&lt;/li&gt;
  &lt;li&gt;\(\{(0, 0)\}\) (tập gồm một điểm)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trong \(\mathbb{R}^n\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Mọi hình cầu đóng \(\overline{B}(\mathbf{x}_0, r) = \{\mathbf{x} : d(\mathbf{x}, \mathbf{x}_0) \leq r\}\)&lt;/li&gt;
  &lt;li&gt;Toàn bộ \(\mathbb{R}^n\)&lt;/li&gt;
  &lt;li&gt;\(\emptyset\) (tập rỗng)&lt;/li&gt;
  &lt;li&gt;Mọi tập hữu hạn&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tính-chất-của-tập-đóng&quot;&gt;Tính chất của tập đóng&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Giao của một họ bất kỳ các tập đóng là tập đóng.&lt;/li&gt;
  &lt;li&gt;Hợp của hữu hạn các tập đóng là tập đóng.&lt;/li&gt;
  &lt;li&gt;\(\mathbb{R}^n\) và \(\emptyset\) đều là tập đóng.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;lưu-ý-quan-trọng&quot;&gt;Lưu ý quan trọng&lt;/h3&gt;

&lt;p&gt;Một tập hợp có thể rơi vào một trong bốn trường hợp:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mở nhưng không đóng:&lt;/strong&gt; \((0, 1)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đóng nhưng không mở:&lt;/strong&gt; \([0, 1]\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vừa mở vừa đóng:&lt;/strong&gt; \(\mathbb{R}^n\), \(\emptyset\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không mở cũng không đóng:&lt;/strong&gt; \([0, 1)\), \((0, 1]\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;biên-phần-trong-và-bao-đóng&quot;&gt;Biên, phần trong và bao đóng&lt;/h2&gt;

&lt;h3 id=&quot;biên&quot;&gt;Biên&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Biên&lt;/strong&gt; của tập \(S\), ký hiệu \(\partial S\), là tập các điểm nằm ở “rìa” của \(S\). Một điểm \(\mathbf{x}\) là &lt;strong&gt;điểm biên&lt;/strong&gt; của \(S\) nếu mọi hình cầu mở tâm \(\mathbf{x}\) đều giao với cả \(S\) lẫn phần bù \(S^c\):&lt;/p&gt;

\[\partial S = \{\mathbf{x} : \forall \epsilon &amp;gt; 0, B(\mathbf{x}, \epsilon) \cap S \neq \emptyset \text{ and } B(\mathbf{x}, \epsilon) \cap S^c \neq \emptyset\}\]

&lt;h3 id=&quot;phần-trong&quot;&gt;Phần trong&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phần trong&lt;/strong&gt; của tập \(S\), ký hiệu \(S^\circ\) hay \(\text{int}(S)\), là tập tất cả các điểm nằm hoàn toàn bên trong \(S\) (không chứa điểm biên):&lt;/p&gt;

\[S^\circ = \{\mathbf{x} \in S : \exists \epsilon &amp;gt; 0, B(\mathbf{x}, \epsilon) \subseteq S\}\]

&lt;h3 id=&quot;bao-đóng&quot;&gt;Bao đóng&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bao đóng&lt;/strong&gt; của tập \(S\), ký hiệu \(\overline{S}\) hay \(\text{cl}(S)\), là tập đóng nhỏ nhất chứa \(S\):&lt;/p&gt;

\[\overline{S} = S \cup \partial S\]

&lt;h3 id=&quot;ví-dụ-minh-họa&quot;&gt;Ví dụ minh họa&lt;/h3&gt;

&lt;p&gt;Với khoảng \(S = [0, 1)\) trong \(\mathbb{R}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phần trong:&lt;/strong&gt; \(S^\circ = (0, 1)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biên:&lt;/strong&gt; \(\partial S = \{0, 1\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bao đóng:&lt;/strong&gt; \(\overline{S} = [0, 1]\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Với đĩa mở \(S = \{(x, y) : x^2 + y^2 &amp;lt; 1\}\) trong \(\mathbb{R}^2\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phần trong:&lt;/strong&gt; \(S^\circ = S\) (vì \(S\) đã là tập mở)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biên:&lt;/strong&gt; \(\partial S = \{(x, y) : x^2 + y^2 = 1\}\) (đường tròn đơn vị)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bao đóng:&lt;/strong&gt; \(\overline{S} = \{(x, y) : x^2 + y^2 \leq 1\}\) (đĩa đơn vị đóng)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tập-compact&quot;&gt;Tập compact&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tập compact&lt;/strong&gt; là một trong những khái niệm quan trọng nhất của lý thuyết tối ưu hóa.&lt;/p&gt;

&lt;h3 id=&quot;đặc-trưng-trong-không-gian-euclid&quot;&gt;Đặc trưng trong không gian Euclid&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Định lý Heine–Borel:&lt;/strong&gt; Trong không gian Euclid \(\mathbb{R}^n\), một tập hợp là compact khi và chỉ khi nó vừa &lt;strong&gt;đóng&lt;/strong&gt; vừa &lt;strong&gt;bị chặn&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bị chặn:&lt;/strong&gt; tập \(S\) bị chặn nếu nó nằm trong một hình cầu mở đủ lớn, tức tồn tại \(M &amp;gt; 0\) và \(\mathbf{x}_0\) sao cho \(S \subseteq B(\mathbf{x}_0, M)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đóng:&lt;/strong&gt; như định nghĩa ở phần trên.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-về-tập-compact&quot;&gt;Ví dụ về tập compact&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Trong \(\mathbb{R}\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\([a, b]\) (mọi đoạn đóng và bị chặn)&lt;/li&gt;
  &lt;li&gt;\(\{0\}\) (tập gồm một điểm)&lt;/li&gt;
  &lt;li&gt;Mọi tập hữu hạn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trong \(\mathbb{R}^2\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\{(x, y) : x^2 + y^2 \leq 1\}\) (đĩa đơn vị đóng)&lt;/li&gt;
  &lt;li&gt;\([0, 1] \times [0, 1]\) (hình vuông đơn vị đóng)&lt;/li&gt;
  &lt;li&gt;Mọi tập hữu hạn điểm&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trong \(\mathbb{R}^n\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Mọi hình cầu đóng \(\overline{B}(\mathbf{x}_0, r)\)&lt;/li&gt;
  &lt;li&gt;Mọi hình hộp đóng và bị chặn \([a_1, b_1] \times [a_2, b_2] \times \cdots \times [a_n, b_n]\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;các-tập-không-compact&quot;&gt;Các tập không compact&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;\((0, 1)\) (bị chặn nhưng không đóng)&lt;/li&gt;
  &lt;li&gt;\([0, \infty)\) (đóng nhưng không bị chặn)&lt;/li&gt;
  &lt;li&gt;\(\mathbb{R}^n\) (không bị chặn)&lt;/li&gt;
  &lt;li&gt;\(\{1, 1/2, 1/3, 1/4, \ldots\}\) (bị chặn nhưng không đóng, vì điểm giới hạn \(0\) không thuộc tập)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tính-liên-tục-của-hàm-số&quot;&gt;Tính liên tục của hàm số&lt;/h2&gt;

&lt;h3 id=&quot;liên-tục-tại-một-điểm&quot;&gt;Liên tục tại một điểm&lt;/h3&gt;

&lt;p&gt;Hàm số \(f: A \to \mathbb{R}\) được gọi là &lt;strong&gt;liên tục tại điểm&lt;/strong&gt; \(\mathbf{c} \in A\) nếu với mọi \(\varepsilon &amp;gt; 0\), tồn tại \(\delta &amp;gt; 0\) sao cho với mọi \(\mathbf{x} \in A\):&lt;/p&gt;

\[\|\mathbf{x} - \mathbf{c}\| &amp;lt; \delta \implies |f(\mathbf{x}) - f(\mathbf{c})| &amp;lt; \varepsilon\]

&lt;p&gt;&lt;strong&gt;Ý nghĩa trực quan:&lt;/strong&gt; biến thiên đủ nhỏ ở đầu vào dẫn đến biến thiên nhỏ ở đầu ra.&lt;/p&gt;

&lt;h3 id=&quot;liên-tục-trên-một-tập-hợp&quot;&gt;Liên tục trên một tập hợp&lt;/h3&gt;

&lt;p&gt;Hàm \(f\) &lt;strong&gt;liên tục trên \(A\)&lt;/strong&gt; nếu nó liên tục tại mọi điểm thuộc \(A\).&lt;/p&gt;

&lt;h3 id=&quot;đặc-trưng-qua-dãy&quot;&gt;Đặc trưng qua dãy&lt;/h3&gt;

&lt;p&gt;Hàm \(f\) liên tục tại \(\mathbf{c}\) khi và chỉ khi với mọi dãy \((\mathbf{x}_n)\) trong \(A\) hội tụ về \(\mathbf{c}\):&lt;/p&gt;

\[\lim_{n \to \infty} f(\mathbf{x}_n) = f(\mathbf{c})\]

&lt;hr /&gt;

&lt;h2 id=&quot;các-định-lý-quan-trọng-cho-tối-ưu-hóa&quot;&gt;Các định lý quan trọng cho tối ưu hóa&lt;/h2&gt;

&lt;h3 id=&quot;định-lý-giá-trị-cực-trị-extreme-value-theorem&quot;&gt;Định lý giá trị cực trị (Extreme Value Theorem)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Nếu \(f\) liên tục trên một tập compact khác rỗng \(K\) thì \(f\) đạt giá trị lớn nhất và giá trị nhỏ nhất trên \(K\).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Đây là kết quả nền tảng trong tối ưu hóa: nó đảm bảo mọi hàm mục tiêu liên tục đều có nghiệm tối ưu trên vùng khả thi compact.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý tưởng chứng minh:&lt;/strong&gt; Tính compact đảm bảo cận trên đúng (supremum) và cận dưới đúng (infimum) của \(f\) trên \(K\) thực sự đạt được tại các điểm thuộc \(K\).&lt;/p&gt;

&lt;h3 id=&quot;định-lý-giá-trị-trung-gian-intermediate-value-theorem&quot;&gt;Định lý giá trị trung gian (Intermediate Value Theorem)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Nếu \(f\) liên tục trên đoạn \([a, b]\) và \(y\) nằm giữa \(f(a)\) và \(f(b)\) thì tồn tại \(c \in [a, b]\) sao cho \(f(c) = y\).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Định lý này giúp chứng minh sự tồn tại nghiệm của các phương trình dạng \(f(x) = 0\).&lt;/p&gt;

&lt;h3 id=&quot;định-lý-bolzanoweierstrass&quot;&gt;Định lý Bolzano–Weierstrass&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Mọi dãy bị chặn trong \(\mathbb{R}^n\) đều có ít nhất một dãy con hội tụ.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kết quả này là công cụ quan trọng khi chứng minh tính hội tụ của các thuật toán tối ưu hóa lặp.&lt;/p&gt;

&lt;h3 id=&quot;định-lý-xấp-xỉ-weierstrass&quot;&gt;Định lý xấp xỉ Weierstrass&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Mọi hàm liên tục trên một đoạn đóng và bị chặn đều có thể được xấp xỉ đều bằng đa thức.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Định lý này là cơ sở lý thuyết cho việc sử dụng các xấp xỉ đa thức trong thiết kế thuật toán tối ưu hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong tối ưu hóa&lt;/h2&gt;

&lt;h3 id=&quot;1-sự-tồn-tại-nghiệm&quot;&gt;1. Sự tồn tại nghiệm&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vùng khả thi compact đảm bảo nghiệm tối ưu tồn tại:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu vùng khả thi \(S\) compact (khác rỗng) và hàm mục tiêu \(f\) liên tục thì bài toán \(\min_{\mathbf{x} \in S} f(\mathbf{x})\) luôn có nghiệm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-điều-kiện-chính-quy-của-ràng-buộc&quot;&gt;2. Điều kiện chính quy của ràng buộc&lt;/h3&gt;

&lt;p&gt;Các tính chất tôpô của tập ràng buộc quyết định hiệu lực của điều kiện tối ưu và thuật toán:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điểm chính quy:&lt;/strong&gt; điểm mà gradient của các ràng buộc hoạt động độc lập tuyến tính.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp điểm trong:&lt;/strong&gt; đòi hỏi vùng khả thi có phần trong khác rỗng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-phân-tích-hội-tụ&quot;&gt;3. Phân tích hội tụ&lt;/h3&gt;

&lt;p&gt;Các tính chất tôpô giúp phân tích hành vi dãy nghiệm sinh ra bởi thuật toán:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính đóng:&lt;/strong&gt; đảm bảo điểm giới hạn của dãy điểm khả thi vẫn thuộc vùng khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính compact:&lt;/strong&gt; đảm bảo dãy lặp bị chặn luôn trích ra được dãy con hội tụ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-cực-trị-địa-phương-và-toàn-cục&quot;&gt;4. Cực trị địa phương và toàn cục&lt;/h3&gt;

&lt;p&gt;Khái niệm lân cận được dùng để phân biệt cực trị địa phương và toàn cục:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu địa phương:&lt;/strong&gt; \(f(\mathbf{x}^*) \leq f(\mathbf{x})\) với mọi \(\mathbf{x}\) khả thi thuộc một lân cận nào đó của \(\mathbf{x}^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu toàn cục:&lt;/strong&gt; \(f(\mathbf{x}^*) \leq f(\mathbf{x})\) với mọi \(\mathbf{x}\) thuộc toàn bộ vùng khả thi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5-phân-tích-vùng-khả-thi&quot;&gt;5. Phân tích vùng khả thi&lt;/h3&gt;

&lt;p&gt;Phân loại cấu trúc tập ràng buộc:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc bất đẳng thức/đẳng thức tuyến tính:&lt;/strong&gt; xác định các tập đóng (nửa không gian đóng, siêu phẳng).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc phi tuyến:&lt;/strong&gt; có thể tạo ra tập không mở cũng không đóng (nếu có bất đẳng thức nghiêm ngặt).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vùng khả thi compact:&lt;/strong&gt; đảm bảo tồn tại nghiệm tối ưu cho hàm mục tiêu liên tục.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ-tối-ưu-danh-mục-đầu-tư&quot;&gt;Ví dụ: Tối ưu danh mục đầu tư&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa rủi ro danh mục đầu tư với các ràng buộc:&lt;/p&gt;

\[\begin{align}
\min_{\mathbf{w}} \quad &amp;amp; \mathbf{w}^T \mathbf{\Sigma} \mathbf{w} \\
\text{s.t.} \quad &amp;amp; \mathbf{1}^T \mathbf{w} = 1 \\
&amp;amp; \mathbf{w} \geq \mathbf{0}
\end{align}\]

&lt;p&gt;Vùng khả thi \(S = \{\mathbf{w} : \mathbf{1}^T \mathbf{w} = 1, \mathbf{w} \geq \mathbf{0}\}\) có các tính chất:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đóng:&lt;/strong&gt; là giao của các tập đóng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bị chặn:&lt;/strong&gt; ràng buộc \(\mathbf{1}^T \mathbf{w} = 1\) kết hợp với \(\mathbf{w} \geq \mathbf{0}\) kéo theo \(0 \leq w_i \leq 1\) với mọi \(i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compact:&lt;/strong&gt; vì vừa đóng vừa bị chặn trong \(\mathbb{R}^n\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do hàm mục tiêu \(\mathbf{w}^T \mathbf{\Sigma} \mathbf{w}\) liên tục và \(S\) là tập compact khác rỗng, định lý giá trị cực trị đảm bảo bài toán luôn có danh mục tối ưu.&lt;/p&gt;

&lt;p&gt;Tôpô và giải tích thực cung cấp cơ sở chặt chẽ để chứng minh sự tồn tại nghiệm và tính hội tụ của các thuật toán tối ưu hóa, phục vụ cả phân tích lý thuyết lẫn triển khai thực tế.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-03-01 Cơ sở Lý thuyết tập hợp</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_03_01_Set_Theory_Fundamentals/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_03_01_Set_Theory_Fundamentals</id>
   <content type="html">&lt;p&gt;Mỗi ràng buộc trong bài toán thực tế — “ngân sách không vượt quá 10 tỷ”, “sản lượng không âm”, “tổng tỷ trọng danh mục bằng 100%” — thực chất đang cắt ra một tập hợp điểm trong không gian \(\mathbb{R}^n\). Miền khả thi cuối cùng nơi thuật toán được phép tìm kiếm chính là phần &lt;strong&gt;giao&lt;/strong&gt; của tất cả các tập hợp đó. Vì vậy, lý thuyết tập hợp không phải lý thuyết trừu tượng xa vời, mà là ngữ pháp cơ bản để phát biểu đúng mọi bài toán tối ưu có ràng buộc.&lt;/p&gt;

&lt;p&gt;Bài học này củng cố ký hiệu tập hợp, các phép toán hợp–giao–bù, ánh xạ và tích Descartes gắn liền với không gian biến quyết định.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ngữ-pháp-tập-hợp-trong-tối-ưu-hóa&quot;&gt;Kiến thức cần nhớ: Ngữ pháp tập hợp trong tối ưu hóa&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ký hiệu và đặc tả tập hợp:&lt;/strong&gt; Cách viết miền khả thi theo thuộc tính \(D = \{x \in \mathbb{R}^n : g_i(x) \le 0, h_j(x) = 0\}\) giúp phân biệt rõ biến quyết định, tham số và miền xác định.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép giao (\(\cap\)) và tính bảo toàn:&lt;/strong&gt; Giao của nhiều tập ràng buộc mô tả việc thỏa mãn &lt;em&gt;đồng thời&lt;/em&gt; mọi điều kiện. Một phép màu lớn của Chương 02 là giao của họ bất kỳ các tập lồi luôn là tập lồi (còn phép hợp thì thường không!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tích Descartes (\(A \times B\)):&lt;/strong&gt; Là cách xây dựng không gian nhiều biến (như \(\mathbb{R}^n = \mathbb{R} \times \cdots \times \mathbb{R}\)) và đặc biệt là không gian \(\mathbb{R}^n \times \mathbb{R}\) chứa &lt;strong&gt;epigraph&lt;/strong&gt; (biểu đồ trên) của hàm số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ánh xạ, miền xác định và ảnh ngược:&lt;/strong&gt; Liên kết tập nghiệm của bài toán với ảnh ngược \(f^{-1}((-\infty, \alpha])\) — chính là &lt;strong&gt;tập mức dưới&lt;/strong&gt; (sublevel set) đóng vai trò trung tâm khi định nghĩa hàm lồi và hàm giả lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-dựng-miền-khả-thi-từ-phép-giao-ba-tập-ràng-buộc&quot;&gt;Giải thích: Dựng miền khả thi từ phép giao ba tập ràng buộc&lt;/h3&gt;

&lt;p&gt;Xét bài toán tìm cực tiểu của \(f(x_1, x_2) = -2x_1 - 3x_2\) trên miền \(D = S_1 \cap S_2 \cap S_3 \subset \mathbb{R}^2\) với:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(S_1 = \{(x_1, x_2) : x_1 + x_2 \le 4\}\) (tổng tài nguyên không quá 4),&lt;/li&gt;
  &lt;li&gt;\(S_2 = \{(x_1, x_2) : x_1 \ge 0,\ x_2 \ge 0\}\) (không âm),&lt;/li&gt;
  &lt;li&gt;\(S_3 = \{(x_1, x_2) : x_1 \le 3\}\) (giới hạn sản phẩm 1).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Xác định các đỉnh của tập giao \(D\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giao \(x_1 = 0\) và \(x_2 = 0\) cho đỉnh \(A = (0, 0)\).&lt;/li&gt;
      &lt;li&gt;Giao \(x_1 = 3\) và \(x_2 = 0\) cho đỉnh \(B = (3, 0)\).&lt;/li&gt;
      &lt;li&gt;Giao \(x_1 = 3\) và \(x_1 + x_2 = 4\) cho đỉnh \(C = (3, 1)\).&lt;/li&gt;
      &lt;li&gt;Giao \(x_1 = 0\) và \(x_1 + x_2 = 4\) cho đỉnh \(E = (0, 4)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh giá hàm mục tiêu tuyến tính tại bốn đỉnh:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(f(0, 0) = 0\);&lt;/li&gt;
      &lt;li&gt;\(f(3, 0) = -6\);&lt;/li&gt;
      &lt;li&gt;\(f(3, 1) = -2(3) - 3(1) = -9\);&lt;/li&gt;
      &lt;li&gt;\(f(0, 4) = -2(0) - 3(4) = -12\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Điểm tối ưu toàn cục trên tập giao \(D\) là \(x^* = (0, 4)\) với \(f(x^*) = -12\). Nếu bỏ bớt ràng buộc \(S_1\), miền giao trở nên không bị chặn và hàm có thể giảm xuống \(-\infty\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài học này trình bày các khái niệm cơ bản của lý thuyết tập hợp — nền tảng toán học để mô tả bài toán tối ưu hóa, các ràng buộc và vùng khả thi.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;giới-thiệu-về-lý-thuyết-tập-hợp&quot;&gt;Giới thiệu về lý thuyết tập hợp&lt;/h2&gt;

&lt;p&gt;Lý thuyết tập hợp là nền tảng của toán học hiện đại và rất cần thiết để phát biểu chính xác các khái niệm tối ưu hóa. Một &lt;strong&gt;tập hợp&lt;/strong&gt; là một sưu tập các đối tượng phân biệt, gọi là các phần tử của tập hợp đó.&lt;/p&gt;

&lt;h3 id=&quot;ký-hiệu-cơ-bản&quot;&gt;Ký hiệu cơ bản&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ký hiệu liệt kê tập hợp:&lt;/strong&gt; \(A = \{1, 2, 3, 4\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan hệ thuộc:&lt;/strong&gt; \(x \in A\) (\(x\) thuộc \(A\)) hoặc \(x \notin A\) (\(x\) không thuộc \(A\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập rỗng:&lt;/strong&gt; \(\emptyset = \{\}\) (tập hợp không chứa phần tử nào)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ký hiệu theo tính chất đặc trưng:&lt;/strong&gt; \(A = \{x : P(x)\}\) (tập hợp tất cả các phần tử \(x\) thỏa mãn tính chất \(P(x)\))&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;\(A = \{1, 2, 3, 4\}\) (liệt kê tường minh)&lt;/li&gt;
  &lt;li&gt;\(B = \{x \in \mathbb{R} : x^2 &amp;lt; 4\} = (-2, 2)\) (mô tả theo tính chất đặc trưng)&lt;/li&gt;
  &lt;li&gt;\(C = \{x \in \mathbb{Z} : x \text{ là số chẵn}\}\) (tập tất cả các số nguyên chẵn)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;các-phép-toán-tập-hợp-cơ-bản&quot;&gt;Các phép toán tập hợp cơ bản&lt;/h2&gt;

&lt;h3 id=&quot;tập-hợp-và-tập-con&quot;&gt;Tập hợp và tập con&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tập con:&lt;/strong&gt; \(A \subseteq B\) nghĩa là mọi phần tử của \(A\) đều thuộc \(B\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập con thực sự:&lt;/strong&gt; \(A \subset B\) nghĩa là \(A \subseteq B\) và \(A \neq B\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai tập hợp bằng nhau:&lt;/strong&gt; \(A = B\) khi và chỉ khi \(A \subseteq B\) và \(B \subseteq A\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\{1, 2\} \subseteq \{1, 2, 3, 4\}\]
  &lt;/li&gt;
  &lt;li&gt;
\[\{1, 2\} \subset \{1, 2, 3, 4\}\]
  &lt;/li&gt;
  &lt;li&gt;\(\emptyset \subseteq A\) với mọi tập hợp \(A\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;hợp-và-giao&quot;&gt;Hợp và giao&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hợp (\(A \cup B\)):&lt;/strong&gt; tập hợp tất cả các phần tử thuộc \(A\) hoặc thuộc \(B\) (hoặc cả hai):
\(A \cup B = \{x : x \in A \text{ hoặc } x \in B\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giao (\(A \cap B\)):&lt;/strong&gt; tập hợp tất cả các phần tử thuộc đồng thời cả \(A\) và \(B\):
\(A \cap B = \{x : x \in A \text{ và } x \in B\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(A = \{1, 2, 3\}\) và \(B = \{3, 4, 5\}\), thì:
    &lt;ul&gt;
      &lt;li&gt;
\[A \cup B = \{1, 2, 3, 4, 5\}\]
      &lt;/li&gt;
      &lt;li&gt;
\[A \cap B = \{3\}\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hai tập hợp rời nhau:&lt;/strong&gt; \(A\) và \(B\) rời nhau nếu \(A \cap B = \emptyset\).&lt;/p&gt;

&lt;h3 id=&quot;phần-bù-và-hiệu&quot;&gt;Phần bù và hiệu&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phần bù (\(A^c\)):&lt;/strong&gt; tập hợp tất cả các phần tử không thuộc \(A\) (trong một tập vũ trụ \(U\) cho trước):
\(A^c = \{x \in U : x \notin A\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hiệu tập hợp (\(A \setminus B\)):&lt;/strong&gt; tập hợp các phần tử thuộc \(A\) nhưng không thuộc \(B\):
\(A \setminus B = \{x : x \in A \text{ và } x \notin B\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hiệu đối xứng:&lt;/strong&gt; \((A \setminus B) \cup (B \setminus A) = (A \cup B) \setminus (A \cap B)\)&lt;/p&gt;

&lt;h3 id=&quot;các-luật-của-phép-toán-tập-hợp&quot;&gt;Các luật của phép toán tập hợp&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Luật giao hoán:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[A \cup B = B \cup A\]
  &lt;/li&gt;
  &lt;li&gt;
\[A \cap B = B \cap A\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Luật kết hợp:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[(A \cup B) \cup C = A \cup (B \cup C)\]
  &lt;/li&gt;
  &lt;li&gt;
\[(A \cap B) \cap C = A \cap (B \cap C)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Luật phân phối:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[A \cap (B \cup C) = (A \cap B) \cup (A \cap C)\]
  &lt;/li&gt;
  &lt;li&gt;
\[A \cup (B \cap C) = (A \cup B) \cap (A \cup C)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Luật De Morgan:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[(A \cup B)^c = A^c \cap B^c\]
  &lt;/li&gt;
  &lt;li&gt;
\[(A \cap B)^c = A^c \cup B^c\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;các-tập-số-quan-trọng&quot;&gt;Các tập số quan trọng&lt;/h2&gt;

&lt;p&gt;Nắm rõ hệ thống phân cấp các tập số giúp xác định chính xác miền biến của bài toán tối ưu hóa:&lt;/p&gt;

&lt;h3 id=&quot;số-tự-nhiên&quot;&gt;Số tự nhiên&lt;/h3&gt;
&lt;p&gt;\(\mathbb{N} = \{1, 2, 3, 4, \ldots\}\)
(Đôi khi bao gồm cả số 0: \(\mathbb{N}_0 = \{0, 1, 2, 3, \ldots\}\))&lt;/p&gt;

&lt;h3 id=&quot;số-nguyên&quot;&gt;Số nguyên&lt;/h3&gt;
&lt;p&gt;\(\mathbb{Z} = \{\ldots, -2, -1, 0, 1, 2, \ldots\}\)&lt;/p&gt;

&lt;h3 id=&quot;số-hữu-tỉ&quot;&gt;Số hữu tỉ&lt;/h3&gt;
&lt;p&gt;\(\mathbb{Q} = \left\{\frac{p}{q} : p, q \in \mathbb{Z}, q \neq 0\right\}\)&lt;/p&gt;

&lt;p&gt;Gồm mọi số có thể biểu diễn dưới dạng phân số của hai số nguyên.&lt;/p&gt;

&lt;h3 id=&quot;số-thực&quot;&gt;Số thực&lt;/h3&gt;
&lt;p&gt;\(\mathbb{R}\) gồm tất cả các số hữu tỉ và số vô tỉ (như \(\pi\), \(e\), \(\sqrt{2}\)).&lt;/p&gt;

&lt;h3 id=&quot;số-phức&quot;&gt;Số phức&lt;/h3&gt;
&lt;p&gt;\(\mathbb{C} = \{a + bi : a, b \in \mathbb{R}, i^2 = -1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quan hệ bao hàm:&lt;/strong&gt; \(\mathbb{N} \subset \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R} \subset \mathbb{C}\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;hàm-số-miền-xác-định-và-miền-giá-trị&quot;&gt;Hàm số: Miền xác định và miền giá trị&lt;/h2&gt;

&lt;p&gt;Một &lt;strong&gt;hàm số&lt;/strong&gt; \(f: A \to B\) là quy tắc gán cho mỗi phần tử thuộc tập \(A\) đúng một phần tử thuộc tập \(B\).&lt;/p&gt;

&lt;h3 id=&quot;các-khái-niệm-chính&quot;&gt;Các khái niệm chính&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Miền xác định (domain):&lt;/strong&gt; tập \(A\) gồm tất cả các giá trị đầu vào hợp lệ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập đích (codomain):&lt;/strong&gt; tập \(B\) chứa các giá trị đầu ra có thể nhận.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Miền giá trị / ảnh (range):&lt;/strong&gt; tập hợp tất cả các giá trị đầu ra thực tế: \(\text{Range}(f) = \{f(x) : x \in A\} \subseteq B\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; Với \(f: \mathbb{R} \to \mathbb{R}\) định nghĩa bởi \(f(x) = x^2\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Miền xác định: \(\mathbb{R}\)&lt;/li&gt;
  &lt;li&gt;Tập đích: \(\mathbb{R}\)&lt;/li&gt;
  &lt;li&gt;Miền giá trị: \([0, \infty)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phân-loại-ánh-xạ-hàm-số&quot;&gt;Phân loại ánh xạ (hàm số)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Đơn ánh (injective):&lt;/strong&gt; hai phần tử khác nhau trong miền xác định có ảnh khác nhau:
\(f(x_1) = f(x_2) \implies x_1 = x_2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Toàn ánh (surjective):&lt;/strong&gt; mọi phần tử trong tập đích đều là ảnh của ít nhất một phần tử trong miền xác định:
Với mọi \(y \in B\), tồn tại \(x \in A\) sao cho \(f(x) = y\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Song ánh (bijective):&lt;/strong&gt; vừa là đơn ánh vừa là toàn ánh, tạo ra sự tương ứng một-một giữa miền xác định và tập đích.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(x) = 2x\) từ \(\mathbb{R}\) vào \(\mathbb{R}\) là song ánh.&lt;/li&gt;
  &lt;li&gt;\(f(x) = x^2\) từ \(\mathbb{R}\) vào \(\mathbb{R}\) không là đơn ánh và cũng không là toàn ánh.&lt;/li&gt;
  &lt;li&gt;\(f(x) = x^2\) từ \([0, \infty)\) vào \([0, \infty)\) là song ánh.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bất-đẳng-thức&quot;&gt;Bất đẳng thức&lt;/h2&gt;

&lt;p&gt;Bất đẳng thức là công cụ quen thuộc trong tối ưu hóa vì phần lớn ràng buộc được biểu diễn dưới dạng bất đẳng thức.&lt;/p&gt;

&lt;h3 id=&quot;các-ký-hiệu-bất-đẳng-thức-cơ-bản&quot;&gt;Các ký hiệu bất đẳng thức cơ bản&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;\(a &amp;lt; b\): \(a\) nhỏ hơn hẳn \(b\)&lt;/li&gt;
  &lt;li&gt;\(a \leq b\): \(a\) nhỏ hơn hoặc bằng \(b\)&lt;/li&gt;
  &lt;li&gt;\(a &amp;gt; b\): \(a\) lớn hơn hẳn \(b\)&lt;/li&gt;
  &lt;li&gt;\(a \geq b\): \(a\) lớn hơn hoặc bằng \(b\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tính-chất-của-bất-đẳng-thức&quot;&gt;Tính chất của bất đẳng thức&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính bắc cầu:&lt;/strong&gt; Nếu \(a \leq b\) và \(b \leq c\), thì \(a \leq c\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cộng hai vế:&lt;/strong&gt; Nếu \(a \leq b\), thì \(a + c \leq b + c\) với mọi \(c \in \mathbb{R}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhân với số dương:&lt;/strong&gt; Nếu \(a \leq b\) và \(c &amp;gt; 0\), thì \(ac \leq bc\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhân với số âm:&lt;/strong&gt; Nếu \(a \leq b\) và \(c &amp;lt; 0\), thì \(ac \geq bc\) (chiều bất đẳng thức đảo ngược).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;ký-hiệu-khoảng&quot;&gt;Ký hiệu khoảng&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng mở:&lt;/strong&gt; \((a, b) = \{x \in \mathbb{R} : a &amp;lt; x &amp;lt; b\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đoạn đóng:&lt;/strong&gt; \([a, b] = \{x \in \mathbb{R} : a \leq x \leq b\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng nửa mở:&lt;/strong&gt; \([a, b)\), \((a, b]\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng không bị chặn:&lt;/strong&gt; \((-\infty, a)\), \([a, \infty)\), \((-\infty, \infty) = \mathbb{R}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong tối ưu hóa&lt;/h2&gt;

&lt;p&gt;Các khái niệm của lý thuyết tập hợp xuất hiện trực tiếp trong mô hình hóa và phân tích bài toán tối ưu hóa:&lt;/p&gt;

&lt;h3 id=&quot;1-vùng-khả-thi&quot;&gt;1. Vùng khả thi&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vùng khả thi&lt;/strong&gt; là tập hợp tất cả các điểm thỏa mãn đồng thời mọi ràng buộc:
\(S = \{x \in \mathbb{R}^n : g_i(x) \leq 0, i = 1, \ldots, m; h_j(x) = 0, j = 1, \ldots, p\}\)&lt;/p&gt;

&lt;h3 id=&quot;2-tập-mức&quot;&gt;2. Tập mức&lt;/h3&gt;

&lt;p&gt;Với hàm số \(f: \mathbb{R}^n \to \mathbb{R}\), &lt;strong&gt;tập mức&lt;/strong&gt; tại mức \(c\) là:
\(L_c = \{x \in \mathbb{R}^n : f(x) = c\}\)&lt;/p&gt;

&lt;h3 id=&quot;3-điều-kiện-ràng-buộc&quot;&gt;3. Điều kiện ràng buộc&lt;/h3&gt;

&lt;p&gt;Các tính chất hình học và tôpô của tập ràng buộc (chẳng hạn tính đóng hoặc có phần trong khác rỗng) ảnh hưởng trực tiếp đến sự tồn tại và đặc trưng của nghiệm tối ưu.&lt;/p&gt;

&lt;h3 id=&quot;4-phân-tích-hội-tụ&quot;&gt;4. Phân tích hội tụ&lt;/h3&gt;

&lt;p&gt;Ngôn ngữ tập hợp, dãy số và giới hạn giúp phân tích xem thuật toán tối ưu hóa có hội tụ về nghiệm tối ưu hay không.&lt;/p&gt;

&lt;h3 id=&quot;5-các-phép-toán-tập-hợp-trong-bài-toán-tối-ưu&quot;&gt;5. Các phép toán tập hợp trong bài toán tối ưu&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Giao:&lt;/strong&gt; xác định tập điểm thỏa mãn đồng thời nhiều ràng buộc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hợp:&lt;/strong&gt; gộp các vùng khả thi từ nhiều kịch bản khác nhau.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần bù:&lt;/strong&gt; xác định miền không khả thi.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; Trong quy hoạch tuyến tính, vùng khả thi có dạng:
\(S = \{x \in \mathbb{R}^n : Ax \leq b, x \geq 0\} = \bigcap_{i=1}^{m} \{x : a_i^T x \leq b_i\} \cap \{x : x \geq 0\}\)&lt;/p&gt;

&lt;p&gt;Đây là giao của các nửa không gian đóng, minh họa cách phép toán tập hợp xuất hiện tự nhiên khi xây dựng bài toán tối ưu hóa.&lt;/p&gt;

&lt;p&gt;Nắm vững lý thuyết tập hợp cung cấp nền tảng chặt chẽ để phát biểu chính xác các bài toán tối ưu hóa và phân tích tính chất của chúng một cách có hệ thống.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-02 Đại số tuyến tính cơ bản</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_02_Basic_Linear_Algebra/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_02_Basic_Linear_Algebra</id>
   <content type="html">&lt;p&gt;Nếu giải tích là đôi mắt giúp thuật toán nhìn độ dốc, thì &lt;strong&gt;đại số tuyến tính&lt;/strong&gt; là khung xương nâng đỡ toàn bộ tính toán trong tối ưu hóa. Một hệ thống 10.000 ràng buộc sản xuất thu gọn thành đúng một dòng \(Ax \le b\); độ cong của hàm mất mát trong không gian triệu chiều thu gọn thành dạng toàn phương \(x^T Q x\); và bài toán hồi quy cổ điển nhất lịch sử — bình phương tối thiểu — giải xong chỉ bằng một phép chiếu trực giao.&lt;/p&gt;

&lt;p&gt;Phần 00-02 giúp bạn chuyển từ cách nhớ công thức nhân ma trận máy móc sang tư duy hình học về không gian con, phép biến đổi và phổ giá trị riêng.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-đại-số-tuyến-tính-trong-tối-ưu-hóa&quot;&gt;Kiến thức cần nhớ: Ba trụ cột đại số tuyến tính trong tối ưu hóa&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không gian vector, tích vô hướng và chuẩn:&lt;/strong&gt; Cung cấp thước đo khoảng cách (\(\ell_1, \ell_2, \ell_\infty\)) và góc giữa các hướng đi. Việc đổi chuẩn từ \(\ell_2\) sang \(\ell_1\) chính là bí quyết biến hồi quy Ridge trơn thành hồi quy Lasso tạo nghiệm thưa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ma trận và ánh xạ tuyến tính:&lt;/strong&gt; Mô tả mọi ràng buộc tuyến tính \(Ax = b\), toán tử chiếu lên không gian con và cấu trúc hạng (rank) quyết định bài toán có nghiệm duy nhất, vô số nghiệm hay vô nghiệm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giá trị riêng, vector riêng và ma trận xác định dương:&lt;/strong&gt; Phổ của ma trận Hessian \(\nabla^2 f\) quyết định hình dáng các đường mức (hình tròn đẹp hay elip kéo dẹt khó hội tụ) thông qua &lt;strong&gt;chỉ số điều kiện&lt;/strong&gt; \(\kappa = \lambda_{\max}/\lambda_{\min}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-tay-bài-toán-bình-phương-tối-thiểu-bằng-phương-trình-chuẩn&quot;&gt;Giải thích: Giải tay bài toán bình phương tối thiểu bằng phương trình chuẩn&lt;/h3&gt;

&lt;p&gt;Giả sử ta muốn tìm số thực \(x \in \mathbb{R}\) khớp tốt nhất hai phương trình mâu thuẫn \(1\cdot x \approx 2\) và \(2\cdot x \approx 5\), tức giải \(\min_x \|Ax - b\|_2^2\) với \(A = \begin{pmatrix}1\\ 2\end{pmatrix}, b = \begin{pmatrix}2\\ 5\end{pmatrix}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Lập phương trình chuẩn \(A^T A x = A^T b\):&lt;/strong&gt;
\(A^T A = 1^2 + 2^2 = 5, \qquad A^T b = 1\cdot 2 + 2\cdot 5 = 12.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải nghiệm tối ưu:&lt;/strong&gt;
\(x^* = \frac{12}{5} = 2.4.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra trực giao hình học:&lt;/strong&gt; Vector sai số (phần dư) là:
\(r = b - Ax^* = \begin{pmatrix}2\\ 5\end{pmatrix} - \begin{pmatrix}2.4\\ 4.8\end{pmatrix} = \begin{pmatrix}-0.4\\ 0.2\end{pmatrix}.\)
Tính tích vô hướng với cột của \(A\): \(A^T r = 1(-0.4) + 2(0.2) = 0\)! Phần dư \(r\) vuông góc tuyệt đối với không gian cột của \(A\), chứng tỏ \(Ax^*\) chính là hình chiếu gần \(b\) nhất với sai số bình phương nhỏ nhất \(\|r\|_2^2 = (-0.4)^2 + 0.2^2 = 0.2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Trong hầu hết các thuật toán tối ưu hóa, mỗi bước lặp đều thao tác trên vector, mỗi ràng buộc tuyến tính là một tích ma trận–vector, và độ cong cục bộ được mô tả qua các giá trị riêng của ma trận Hessian hoặc ma trận Gram. Trang này giới thiệu tổng quan cho ba bài đại số tuyến tính tiếp theo.&lt;/p&gt;

&lt;h2 id=&quot;các-đối-tượng-sử-dụng-xuyên-suốt-khóa-học&quot;&gt;Các đối tượng sử dụng xuyên suốt khóa học&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vector và tích trong.&lt;/strong&gt; Hình học Euclid \(\langle g, d\rangle = g^\top d\) quyết định \(d\) có phải hướng giảm hay không (\(g^\top d &amp;lt; 0\)). Các hình học khác (Mahalanobis, ánh xạ gương) sẽ xuất hiện ở phần sau dưới dạng tiền điều kiện và chuẩn đối ngẫu (Chương 13).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ma trận như ánh xạ tuyến tính.&lt;/strong&gt; Ràng buộc đẳng thức \(Ax = b\) xác định một không gian affine; hạt nhân (kernel) của \(A\) là không gian các hướng bước khả thi. Bài toán bình phương tối thiểu (Chương 05) giải hệ \(A^\top A \hat{x} = A^\top y\) khi \(A\) đủ hạng cột.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giá trị riêng và dạng toàn phương.&lt;/strong&gt; Nếu \(Q\succeq 0\) thì hàm \(x\mapsto x^\top Q x\) là hàm lồi; số điều kiện \(\kappa = \lambda_{\max}(Q)/\lambda_{\min}(Q)\) của một hàm toàn phương lồi mạnh chính là yếu tố làm chậm gradient descent thuần và là động lực cho các phương pháp tăng tốc (Chương 06, 09, 26).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mọi ma trận đối xứng \(Q\) đều chéo hóa trực giao được dưới dạng \(Q = U\Lambda U^\top\). Thương Rayleigh&lt;/p&gt;

\[\lambda_{\min}(Q) = \min_{\|x\|_2=1} x^\top Q x, \qquad \lambda_{\max}(Q) = \max_{\|x\|_2=1} x^\top Q x\]

&lt;p&gt;là cách trực quan nhất để xác định các hằng số lồi mạnh và độ trơn.&lt;/p&gt;

&lt;h2 id=&quot;các-bài-trong-phần-này&quot;&gt;Các bài trong phần này&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Vector và không gian vector&lt;/li&gt;
  &lt;li&gt;Ma trận và phép biến đổi tuyến tính&lt;/li&gt;
  &lt;li&gt;Giá trị riêng và vector riêng&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tự kiểm tra: hãy giải thích trong một câu vì sao điều kiện \(\nabla^2 f(x)\succeq 0\) tại mọi điểm kéo theo hàm \(f\) khả vi hai lần là hàm lồi. (Chương 03 sẽ chứng minh đầy đủ; đại số tuyến tính giúp ta hiểu rõ ý nghĩa của mệnh đề này.)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-02-03 Giá trị riêng và Vector riêng</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_02_03_Eigenvalues_and_Eigenvectors/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_02_03_Eigenvalues_and_Eigenvectors</id>
   <content type="html">&lt;p&gt;Khi một ma trận \(A\) tác động lên các vector trong không gian, hầu hết vector đều bị xoay lệch sang hướng khác. Thế nhưng luôn có những “trục đặc biệt” mà trên đó ma trận chỉ kéo giãn hoặc co ngắn vector mà không hề xoay chúng: đó là các &lt;strong&gt;vector riêng&lt;/strong&gt;, còn hệ số kéo giãn chính là &lt;strong&gt;giá trị riêng&lt;/strong&gt;. Trong tối ưu hóa lồi, đây không phải khái niệm trang trí — phổ giá trị riêng của ma trận Hessian quyết định trực tiếp hàm có lồi hay không, và Gradient Descent sẽ chạy nhanh như tên bắn hay bò chậm rì theo đường zíc-zắc.&lt;/p&gt;

&lt;p&gt;Bài học này giải mã cách tính, ý nghĩa hình học và vai trò cốt tử của giá trị riêng trong phân tích độ cong và tính xác định dương.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-phổ-ma-trận-và-hình-học-tối-ưu&quot;&gt;Kiến thức cần nhớ: Phổ ma trận và hình học tối ưu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương trình đặc trưng (\(Av = \lambda v\)):&lt;/strong&gt; Biến ma trận nhiều chiều thành các hệ số vô hướng \(\lambda_i\) độc lập trên từng trục riêng. Tích các giá trị riêng bằng \(\det(A)\), tổng các giá trị riêng bằng vết \(\operatorname{tr}(A)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý phổ cho ma trận đối xứng (Spectral Theorem):&lt;/strong&gt; Mọi ma trận đối xứng thực \(H = H^T\) (như ma trận Hessian) đều có giá trị riêng thực và một hệ cơ sở trực chuẩn các vector riêng: \(H = Q \Lambda Q^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính xác định dương (\(H \succ 0\)) và bán xác định dương (\(H \succeq 0\)):&lt;/strong&gt; \(H \succeq 0 \iff\) mọi \(\lambda_i \ge 0\) (điều kiện lồi bậc hai); \(H \succ 0 \iff\) mọi \(\lambda_i &amp;gt; 0\) (lồi chặt / lồi mạnh).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chỉ số điều kiện (\(\kappa = \lambda_{\max}/\lambda_{\min}\)):&lt;/strong&gt; Đo độ “dẹt” của thung lũng hàm bậc hai. Khi \(\kappa = 1\), đường mức là hình tròn và Gradient Descent hội tụ tức thì; khi \(\kappa \gg 1\), thung lũng hẹp dài làm Gradient Descent dao động mạnh qua lại hai vách.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-phân-tích-phổ-và-chỉ-số-điều-kiện-của-hessian-h--beginpmatrix5--2-2--2endpmatrix&quot;&gt;Giải thích: Phân tích phổ và chỉ số điều kiện của Hessian \(H = \begin{pmatrix}5 &amp;amp; 2\\ 2 &amp;amp; 2\end{pmatrix}\)&lt;/h3&gt;

&lt;p&gt;Xét dạng toàn phương \(f(x) = \frac{1}{2}x^T H x\) với \(H = \begin{pmatrix}5 &amp;amp; 2\\ 2 &amp;amp; 2\end{pmatrix}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tìm giá trị riêng bằng vết và định thức:&lt;/strong&gt;
\(\operatorname{tr}(H) = 5 + 2 = 7, \qquad \det(H) = 5\cdot 2 - 2\cdot 2 = 6.\)
Đa thức đặc trưng: \(\lambda^2 - 7\lambda + 6 = (\lambda - 6)(\lambda - 1) = 0 \implies \lambda_1 = 6,\ \lambda_2 = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm hai vector riêng trực giao:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(\lambda_1 = 6\): \((H - 6I)v_1 = \begin{pmatrix}-1 &amp;amp; 2\\ 2 &amp;amp; -4\end{pmatrix}v_1 = 0 \implies v_1 = \begin{pmatrix}2\\ 1\end{pmatrix}\) (kiểm tra: \(Hv_1 = (12, 6)^T = 6v_1\)).&lt;/li&gt;
      &lt;li&gt;Với \(\lambda_2 = 1\): \((H - I)v_2 = \begin{pmatrix}4 &amp;amp; 2\\ 2 &amp;amp; 1\end{pmatrix}v_2 = 0 \implies v_2 = \begin{pmatrix}-1\\ 2\end{pmatrix}\) (kiểm tra: \(Hv_2 = (-1, 2)^T = 1v_2\)).
Dễ thấy \(v_1^T v_2 = 2(-1) + 1(2) = 0\) (vuông góc tuyệt đối!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đọc thông điệp tối ưu hóa:&lt;/strong&gt; Vì \(\lambda_1 = 6 &amp;gt; 0\) và \(\lambda_2 = 1 &amp;gt; 0\), ma trận \(H \succ 0\) nên \(f\) là hàm lồi mạnh với hằng số lồi mạnh \(m = 1\) và hằng số trơn \(L = 6\). Chỉ số điều kiện là \(\kappa = L/m = 6\): trục dọc theo \(v_1\) dốc gấp \(6\) lần trục dọc theo \(v_2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài học này trình bày khái niệm giá trị riêng và vector riêng — công cụ quan trọng để phân tích hành vi của các phép biến đổi tuyến tính và hàm toàn phương trong tối ưu hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;định-nghĩa-và-ý-nghĩa-trực-quan&quot;&gt;Định nghĩa và ý nghĩa trực quan&lt;/h2&gt;

&lt;p&gt;Khi một ma trận tác động lên một vector, nó thường làm thay đổi cả hướng lẫn độ dài của vector đó. Tuy nhiên, &lt;strong&gt;vector riêng&lt;/strong&gt; là những vector khác không đặc biệt mà sau phép biến đổi ma trận, phương của chúng được giữ nguyên và chỉ có độ dài (hoặc chiều) thay đổi theo một hệ số vô hướng.&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa-toán-học&quot;&gt;Định nghĩa toán học&lt;/h3&gt;

&lt;p&gt;Với một ma trận vuông \(\mathbf{A}\) và một vector khác không \(\mathbf{v}\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(\mathbf{v}\) là một &lt;strong&gt;vector riêng&lt;/strong&gt; của \(\mathbf{A}\)&lt;/li&gt;
  &lt;li&gt;\(\lambda\) là &lt;strong&gt;giá trị riêng&lt;/strong&gt; tương ứng&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;nếu chúng thỏa mãn &lt;strong&gt;phương trình giá trị riêng&lt;/strong&gt;:&lt;/p&gt;

\[\mathbf{A}\mathbf{v} = \lambda\mathbf{v}\]

&lt;h3 id=&quot;diễn-giải-hình-học&quot;&gt;Diễn giải hình học&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vector riêng:&lt;/strong&gt; các vector khác không giữ nguyên phương dưới phép biến đổi \(\mathbf{A}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giá trị riêng:&lt;/strong&gt; hệ số vô hướng co giãn tương ứng với từng vector riêng.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa trực quan theo giá trị \(\lambda\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(\lambda &amp;gt; 1\): vector riêng bị kéo dài.&lt;/li&gt;
  &lt;li&gt;Nếu \(0 &amp;lt; \lambda &amp;lt; 1\): vector riêng bị co ngắn lại.&lt;/li&gt;
  &lt;li&gt;Nếu \(\lambda &amp;lt; 0\): vector riêng bị co giãn và đảo ngược chiều.&lt;/li&gt;
  &lt;li&gt;Nếu \(\lambda = 0\): vector riêng bị ánh xạ về vector không.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;cách-tìm-giá-trị-riêng-và-vector-riêng&quot;&gt;Cách tìm giá trị riêng và vector riêng&lt;/h2&gt;

&lt;h3 id=&quot;bước-1-tìm-giá-trị-riêng&quot;&gt;Bước 1: Tìm giá trị riêng&lt;/h3&gt;

&lt;p&gt;Biến đổi phương trình giá trị riêng:
\(\mathbf{A}\mathbf{v} = \lambda\mathbf{v}\)
\(\mathbf{A}\mathbf{v} - \lambda\mathbf{v} = \mathbf{0}\)
\((\mathbf{A} - \lambda\mathbf{I})\mathbf{v} = \mathbf{0}\)&lt;/p&gt;

&lt;p&gt;Để hệ có nghiệm không tầm thường (\(\mathbf{v} \neq \mathbf{0}\)), ma trận \((\mathbf{A} - \lambda\mathbf{I})\) phải suy biến, nghĩa là:&lt;/p&gt;

\[\det(\mathbf{A} - \lambda\mathbf{I}) = 0\]

&lt;p&gt;Phương trình này được gọi là &lt;strong&gt;phương trình đặc trưng&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;bước-2-tìm-vector-riêng&quot;&gt;Bước 2: Tìm vector riêng&lt;/h3&gt;

&lt;p&gt;Với mỗi giá trị riêng \(\lambda_i\) tìm được, ta giải hệ phương trình tuyến tính thuần nhất:
\((\mathbf{A} - \lambda_i\mathbf{I})\mathbf{v} = \mathbf{0}\)&lt;/p&gt;

&lt;p&gt;Tập nghiệm của hệ này (kèm theo vector không) tạo thành &lt;strong&gt;không gian riêng&lt;/strong&gt; ứng với \(\lambda_i\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ví-dụ-chi-tiết&quot;&gt;Ví dụ chi tiết&lt;/h2&gt;

&lt;p&gt;Tìm các giá trị riêng và vector riêng của ma trận \(\mathbf{A} = \begin{pmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{pmatrix}\).&lt;/p&gt;

&lt;h3 id=&quot;bước-1-tìm-giá-trị-riêng-1&quot;&gt;Bước 1: Tìm giá trị riêng&lt;/h3&gt;

\[\mathbf{A} - \lambda\mathbf{I} = \begin{pmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{pmatrix} - \lambda\begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix} = \begin{pmatrix} 3-\lambda &amp;amp; 1 \\ 0 &amp;amp; 2-\lambda \end{pmatrix}\]

\[\det(\mathbf{A} - \lambda\mathbf{I}) = (3-\lambda)(2-\lambda) - (1)(0) = (3-\lambda)(2-\lambda) = 0\]

&lt;p&gt;Ta thu được hai giá trị riêng \(\lambda_1 = 3\) và \(\lambda_2 = 2\).&lt;/p&gt;

&lt;h3 id=&quot;bước-2-tìm-vector-riêng-1&quot;&gt;Bước 2: Tìm vector riêng&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Với \(\lambda_1 = 3\):&lt;/strong&gt;
\((\mathbf{A} - 3\mathbf{I})\mathbf{v} = \begin{pmatrix} 0 &amp;amp; 1 \\ 0 &amp;amp; -1 \end{pmatrix}\begin{pmatrix} v_1 \\ v_2 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;Suy ra \(v_2 = 0\) và \(v_1\) có thể nhận mọi giá trị khác không. Ta chọn \(\mathbf{v}_1 = \begin{pmatrix} 1 \\ 0 \end{pmatrix}\) (hoặc mọi bội khác không của nó).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Với \(\lambda_2 = 2\):&lt;/strong&gt;
\((\mathbf{A} - 2\mathbf{I})\mathbf{v} = \begin{pmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{pmatrix}\begin{pmatrix} v_1 \\ v_2 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;Suy ra \(v_1 + v_2 = 0\), tức \(v_2 = -v_1\). Ta chọn \(\mathbf{v}_2 = \begin{pmatrix} 1 \\ -1 \end{pmatrix}\) (hoặc mọi bội khác không của nó).&lt;/p&gt;

&lt;h3 id=&quot;kiểm-chứng&quot;&gt;Kiểm chứng&lt;/h3&gt;

&lt;p&gt;Kiểm tra trực tiếp lại kết quả:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{A}\mathbf{v}_1 = \begin{pmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{pmatrix}\begin{pmatrix} 1 \\ 0 \end{pmatrix} = \begin{pmatrix} 3 \\ 0 \end{pmatrix} = 3\begin{pmatrix} 1 \\ 0 \end{pmatrix} = 3\mathbf{v}_1\) ✓&lt;/li&gt;
  &lt;li&gt;\(\mathbf{A}\mathbf{v}_2 = \begin{pmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{pmatrix}\begin{pmatrix} 1 \\ -1 \end{pmatrix} = \begin{pmatrix} 2 \\ -2 \end{pmatrix} = 2\begin{pmatrix} 1 \\ -1 \end{pmatrix} = 2\mathbf{v}_2\) ✓&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;các-tính-chất-và-định-lý-quan-trọng&quot;&gt;Các tính chất và định lý quan trọng&lt;/h2&gt;

&lt;h3 id=&quot;tính-chất-cơ-bản&quot;&gt;Tính chất cơ bản&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Tổng các giá trị riêng bằng vết của ma trận:&lt;/strong&gt;
\(\sum_{i=1}^n \lambda_i = \text{tr}(\mathbf{A}) = \sum_{i=1}^n a_{ii}\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Tích các giá trị riêng bằng định thức của ma trận:&lt;/strong&gt;
\(\prod_{i=1}^n \lambda_i = \det(\mathbf{A})\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Các vector riêng ứng với các giá trị riêng đôi một khác nhau thì độc lập tuyến tính.&lt;/strong&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Nếu \(\mathbf{A}\) là ma trận đối xứng thực&lt;/strong&gt;, mọi giá trị riêng của nó đều là số thực và các vector riêng ứng với giá trị riêng khác nhau trực giao với nhau.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;bội-của-giá-trị-riêng&quot;&gt;Bội của giá trị riêng&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bội đại số (algebraic multiplicity):&lt;/strong&gt; số lần \(\lambda\) xuất hiện như một nghiệm của đa thức đặc trưng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bội hình học (geometric multiplicity):&lt;/strong&gt; số chiều của không gian riêng tương ứng (số vector riêng độc lập tuyến tính tối đa ứng với \(\lambda\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Với mọi giá trị riêng, luôn có: bội hình học ≤ bội đại số.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phân-tích-trị-riêng-eigendecomposition&quot;&gt;Phân tích trị riêng (Eigendecomposition)&lt;/h2&gt;

&lt;h3 id=&quot;ma-trận-đối-xứng&quot;&gt;Ma trận đối xứng&lt;/h3&gt;

&lt;p&gt;Ma trận đối xứng thực \(\mathbf{A} = \mathbf{A}^T\) có những tính chất đặc biệt quan trọng:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Mọi giá trị riêng đều là số thực.&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các vector riêng ứng với các giá trị riêng khác nhau trực giao với nhau.&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Luôn chéo hóa được bằng ma trận trực giao.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cụ thể, mọi ma trận đối xứng thực đều có phân tích phổ:&lt;/p&gt;

\[\mathbf{A} = \mathbf{Q}\mathbf{\Lambda}\mathbf{Q}^T\]

&lt;p&gt;trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{Q}\) là ma trận trực giao (\(\mathbf{Q}^T\mathbf{Q} = \mathbf{I}\)) có các cột là các vector riêng đơn vị trực chuẩn.&lt;/li&gt;
  &lt;li&gt;\(\mathbf{\Lambda}\) là ma trận đường chéo chứa các giá trị riêng tương ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;các-phép-toán-dựa-trên-phân-tích-trị-riêng&quot;&gt;Các phép toán dựa trên phân tích trị riêng&lt;/h3&gt;

&lt;p&gt;Khi ma trận chéo hóa được (\(\mathbf{A} = \mathbf{P}\mathbf{D}\mathbf{P}^{-1}\)), nhiều phép toán ma trận phức tạp trở nên đơn giản:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Lũy thừa ma trận:&lt;/strong&gt;&lt;/p&gt;

\[\mathbf{A}^k = \mathbf{P}\mathbf{D}^k\mathbf{P}^{-1}\]

&lt;p&gt;Điều này đặc biệt hữu ích khi \(k\) lớn, vì lũy thừa của ma trận đường chéo chỉ cần lũy thừa từng phần tử trên đường chéo:&lt;/p&gt;

\[\mathbf{D}^k = \begin{pmatrix} \lambda_1^k &amp;amp; 0 &amp;amp; \cdots &amp;amp; 0 \\ 0 &amp;amp; \lambda_2^k &amp;amp; \cdots &amp;amp; 0 \\ \vdots &amp;amp; \vdots &amp;amp; \ddots &amp;amp; \vdots \\ 0 &amp;amp; 0 &amp;amp; \cdots &amp;amp; \lambda_n^k \end{pmatrix}\]

&lt;p&gt;&lt;strong&gt;2. Ma trận nghịch đảo:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Nếu tất cả các giá trị riêng đều khác 0:&lt;/p&gt;

\[\mathbf{A}^{-1} = \mathbf{P}\mathbf{D}^{-1}\mathbf{P}^{-1}\]

&lt;p&gt;với \(\mathbf{D}^{-1}\) là ma trận đường chéo có các phần tử \(1/\lambda_i\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Hàm mũ ma trận:&lt;/strong&gt;&lt;/p&gt;

\[e^{\mathbf{A}} = \mathbf{P}e^{\mathbf{D}}\mathbf{P}^{-1}\]

&lt;p&gt;với \(e^{\mathbf{D}} = \text{diag}(e^{\lambda_1}, e^{\lambda_2}, \ldots, e^{\lambda_n})\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Định thức và vết (trace):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(\det(\mathbf{A}) = \prod_i \lambda_i\) (tích các giá trị riêng).&lt;/li&gt;
  &lt;li&gt;\(\text{tr}(\mathbf{A}) = \sum_i \lambda_i\) (tổng các giá trị riêng).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;định-lý-đĩa-gershgorin&quot;&gt;Định lý đĩa Gershgorin&lt;/h2&gt;

&lt;p&gt;Định lý đĩa Gershgorin (Gershgorin Circle Theorem) cung cấp cách ước lượng nhanh miền chứa các giá trị riêng của ma trận mà không cần giải phương trình đặc trưng.&lt;/p&gt;

&lt;h3 id=&quot;phát-biểu-định-lý&quot;&gt;Phát biểu định lý&lt;/h3&gt;

&lt;p&gt;Cho ma trận \(\mathbf{A} = [a_{ij}]_{n \times n}\). Với mỗi hàng \(i\), xác định:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tâm:&lt;/strong&gt; \(a_{ii}\) (phần tử trên đường chéo thứ \(i\))&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Bán kính:&lt;/strong&gt; $$r_i = \sum_{j \neq i}&lt;/td&gt;
          &lt;td&gt;a_{ij}&lt;/td&gt;
          &lt;td&gt;\((tổng giá trị tuyệt đối các phần tử ngoài đường chéo ở hàng\)i$$)&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý:&lt;/strong&gt; Mọi giá trị riêng của \(\mathbf{A}\) đều nằm trong hợp của các đĩa Gershgorin:&lt;/p&gt;

  &lt;p&gt;\(D_i = \{z \in \mathbb{C} : |z - a_{ii}| \leq r_i\}\)&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h3&gt;

&lt;p&gt;Xét ma trận đối xứng: \(\mathbf{A} = \begin{pmatrix} 4 &amp;amp; 0.3 &amp;amp; 0.2 \\ 0.3 &amp;amp; 5 &amp;amp; 0.1 \\ 0.2 &amp;amp; 0.1 &amp;amp; 3 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;Do \(\mathbf{A}\) đối xứng nên mọi giá trị riêng đều là số thực. Các khoảng ứng với đĩa Gershgorin trên trục thực là:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(D_1\): tâm \(4\), bán kính \(0.5\), cho khoảng \(3.5 \leq \lambda \leq 4.5\)&lt;/li&gt;
  &lt;li&gt;\(D_2\): tâm \(5\), bán kính \(0.4\), cho khoảng \(4.6 \leq \lambda \leq 5.4\)&lt;/li&gt;
  &lt;li&gt;\(D_3\): tâm \(3\), bán kính \(0.3\), cho khoảng \(2.7 \leq \lambda \leq 3.3\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; Mọi giá trị riêng của \(\mathbf{A}\) đều nằm trong đoạn \([2.7, 5.4]\).&lt;/p&gt;

&lt;h3 id=&quot;ứng-dụng-thực-tế&quot;&gt;Ứng dụng thực tế&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra nhanh tính xác định dương:&lt;/strong&gt; Với ma trận đối xứng, nếu mọi đĩa Gershgorin đều nằm hoàn toàn bên phải trục ảo (tức \(a_{ii} - r_i &amp;gt; 0\) với mọi \(i\)), ma trận chắc chắn xác định dương.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng số điều kiện (condition number):&lt;/strong&gt; Giúp đánh giá nhanh độ ổn định số học của ma trận.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thiết kế ma trận:&lt;/strong&gt; Đảm bảo các tính chất phổ mong muốn bằng cách kiểm soát độ lớn phần tử đường chéo so với phần tử ngoài đường chéo.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phép-chéo-hóa-ma-trận&quot;&gt;Phép chéo hóa ma trận&lt;/h2&gt;

&lt;p&gt;Một ma trận vuông \(\mathbf{A}\) được gọi là &lt;strong&gt;chéo hóa được&lt;/strong&gt; nếu tồn tại ma trận khả nghịch \(\mathbf{P}\) và ma trận đường chéo \(\mathbf{D}\) sao cho:&lt;/p&gt;

\[\mathbf{A} = \mathbf{P}\mathbf{D}\mathbf{P}^{-1}\]

&lt;p&gt;trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{D}\) là ma trận đường chéo chứa các giá trị riêng của \(\mathbf{A}\).&lt;/li&gt;
  &lt;li&gt;\(\mathbf{P}\) là ma trận có các cột là các vector riêng tương ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;lợi-ích-của-phép-chéo-hóa&quot;&gt;Lợi ích của phép chéo hóa&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính lũy thừa ma trận nhanh chóng:&lt;/strong&gt; \(\mathbf{A}^k = \mathbf{P}\mathbf{D}^k\mathbf{P}^{-1}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiểu rõ cấu trúc phép biến đổi:&lt;/strong&gt; Các giá trị riêng mô tả trực tiếp mức độ co giãn của phép biến đổi dọc theo từng phương vector riêng.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ứng-dụng-hành-vi-của-phép-nhân-ma-trận-lặp&quot;&gt;Ứng dụng: Hành vi của phép nhân ma trận lặp&lt;/h2&gt;

&lt;p&gt;Một ứng dụng quan trọng của giá trị riêng là phân tích hành vi dài hạn khi nhân lặp lại một ma trận với vector: \(\mathbf{A}\mathbf{x}, \mathbf{A}^2\mathbf{x}, \mathbf{A}^3\mathbf{x}, \ldots\)&lt;/p&gt;

&lt;h3 id=&quot;vector-riêng-và-hành-vi-dài-hạn&quot;&gt;Vector riêng và hành vi dài hạn&lt;/h3&gt;

&lt;p&gt;Giả sử ma trận \(\mathbf{A}\) chéo hóa được dưới dạng:&lt;/p&gt;

\[\mathbf{A} = \mathbf{P}\mathbf{D}\mathbf{P}^{-1}\]

&lt;p&gt;Khi đó:&lt;/p&gt;

\[\mathbf{A}^k = \mathbf{P}\mathbf{D}^k\mathbf{P}^{-1} = \mathbf{P}\begin{pmatrix} \lambda_1^k &amp;amp; 0 &amp;amp; \cdots \\ 0 &amp;amp; \lambda_2^k &amp;amp; \cdots \\ \vdots &amp;amp; \vdots &amp;amp; \ddots \end{pmatrix}\mathbf{P}^{-1}\]

&lt;p&gt;&lt;strong&gt;Nhận xét quan trọng:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Nếu $$&lt;/td&gt;
          &lt;td&gt;\lambda_{\max}&lt;/td&gt;
          &lt;td&gt;&amp;gt; 1$$:** độ lớn của vector tăng theo hàm mũ (bùng nổ — explode).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Nếu $$&lt;/td&gt;
          &lt;td&gt;\lambda_{\max}&lt;/td&gt;
          &lt;td&gt;&amp;lt; 1\(:** vector tiến dần về\)\mathbf{0}$$ (triệt tiêu — vanish).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Nếu $$&lt;/td&gt;
          &lt;td&gt;\lambda_{\max}&lt;/td&gt;
          &lt;td&gt;= 1$$:** vector giữ độ lớn ổn định hoặc dao động (tùy bội và phần ảo của giá trị riêng).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;ví-dụ-ma-trận-ngẫu-nhiên&quot;&gt;Ví dụ: Ma trận ngẫu nhiên&lt;/h3&gt;

&lt;p&gt;Xét ma trận ngẫu nhiên cỡ \(5 \times 5\) có các phần tử độc lập tuân theo phân phối chuẩn tắc (trung bình bằng 0, phương sai bằng 1).&lt;/p&gt;

&lt;p&gt;Khi nhân lặp lại ma trận này với một vector ngẫu nhiên, ta thấy:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Độ dài vector tăng theo cấp số nhân.&lt;/li&gt;
  &lt;li&gt;Tốc độ tăng được chi phối bởi giá trị riêng có mô-đun lớn nhất \(\lambda_{\max}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Định luật đường tròn (Circular Law):&lt;/strong&gt; Với ma trận ngẫu nhiên lớn cỡ \(n \times n\) có các phần tử độc lập, trung bình bằng 0, phương sai bằng 1, giá trị riêng có mô-đun lớn nhất xấp xỉ \(\sqrt{n}\).&lt;/p&gt;

&lt;h3 id=&quot;chuẩn-hóa-ma-trận&quot;&gt;Chuẩn hóa ma trận&lt;/h3&gt;

&lt;p&gt;Để kiểm soát sự bùng nổ hoặc triệt tiêu này, ta có thể chuẩn hóa ma trận theo giá trị riêng lớn nhất:&lt;/p&gt;

\[\mathbf{A}_{\text{normalized}} = \frac{\mathbf{A}}{\lambda_{\max}}\]

&lt;p&gt;Sau khi chuẩn hóa (khi \(\lambda_{\max} &amp;gt; 0\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Giá trị riêng lớn nhất bằng 1.&lt;/li&gt;
  &lt;li&gt;Độ lớn vector không bị bùng nổ hay triệt tiêu theo hàm mũ.&lt;/li&gt;
  &lt;li&gt;Dãy lặp duy trì hành vi ổn định.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ý-nghĩa-trong-học-sâu-deep-learning&quot;&gt;Ý nghĩa trong học sâu (Deep Learning)&lt;/h3&gt;

&lt;p&gt;Hiện tượng nhân lặp ma trận có hệ quả trực tiếp trong mạng nơ-ron sâu:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gradient triệt tiêu / bùng nổ (Vanishing/Exploding Gradients):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu ma trận trọng số có các giá trị riêng quá lớn → gradient bùng nổ.&lt;/li&gt;
      &lt;li&gt;Nếu các giá trị riêng quá nhỏ → gradient triệt tiêu.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khởi tạo trọng số (Weight Initialization):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Cần khởi tạo sao cho quy mô phổ (giá trị riêng / giá trị kỳ dị) gần 1.&lt;/li&gt;
      &lt;li&gt;Các phương pháp như khởi tạo Xavier và He được xây dựng dựa trên nguyên lý này.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn hóa theo lô (Batch Normalization):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Kiểm soát phân phối của các giá trị kích hoạt giữa các tầng.&lt;/li&gt;
      &lt;li&gt;Hạn chế hiện tượng bùng nổ và triệt tiêu trong quá trình huấn luyện.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết nối tắt (Residual Connections — ResNet):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bổ sung nhánh tắt giúp luồng gradient truyền ngược ổn định hơn.&lt;/li&gt;
      &lt;li&gt;Về mặt toán học, nhánh tắt tương đương việc cộng thêm ma trận đơn vị, giúp giữ các giá trị riêng gần 1 khi trọng số nhánh dư còn nhỏ.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;phân-tích-hội-tụ-của-thuật-toán-lặp&quot;&gt;Phân tích hội tụ của thuật toán lặp&lt;/h3&gt;

&lt;p&gt;Trong nhiều thuật toán lặp (như gradient descent, phương pháp lũy thừa — power iteration), &lt;strong&gt;tốc độ hội tụ&lt;/strong&gt; phụ thuộc vào tỷ số giữa hai giá trị riêng lớn nhất theo mô-đun:&lt;/p&gt;

\[\text{Convergence rate} \propto \left|\frac{\lambda_2}{\lambda_1}\right|\]

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Nếu $$&lt;/td&gt;
          &lt;td&gt;\lambda_2&lt;/td&gt;
          &lt;td&gt;\ll&lt;/td&gt;
          &lt;td&gt;\lambda_1&lt;/td&gt;
          &lt;td&gt;$$: thuật toán hội tụ nhanh.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Nếu $$&lt;/td&gt;
          &lt;td&gt;\lambda_2&lt;/td&gt;
          &lt;td&gt;\approx&lt;/td&gt;
          &lt;td&gt;\lambda_1&lt;/td&gt;
          &lt;td&gt;$$: thuật toán hội tụ chậm.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Thuật toán lặp lũy thừa (Power Iteration):&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Khởi tạo với một vector ngẫu nhiên \(\mathbf{v}_0\).&lt;/li&gt;
  &lt;li&gt;Lặp bước chuẩn hóa: \(\mathbf{v}_{k+1} = \frac{\mathbf{A}\mathbf{v}_k}{\|\mathbf{A}\mathbf{v}_k\|}\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Dãy vector hội tụ về vector riêng ứng với giá trị riêng có mô-đun lớn nhất $$&lt;/td&gt;
          &lt;td&gt;\lambda_{\max}&lt;/td&gt;
          &lt;td&gt;$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Đây là nguyên lý nền tảng cho nhiều thuật toán tính giá trị riêng và vector riêng trên ma trận cỡ lớn.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong tối ưu hóa&lt;/h2&gt;

&lt;p&gt;Giá trị riêng và vector riêng giữ vai trò then chốt trong tối ưu hóa ở nhiều khía cạnh:&lt;/p&gt;

&lt;h3 id=&quot;1-dạng-toàn-phương-và-tính-xác-định-dấu&quot;&gt;1. Dạng toàn phương và tính xác định dấu&lt;/h3&gt;

&lt;p&gt;Với hàm toàn phương \(f(\mathbf{x}) = \mathbf{x}^T\mathbf{Q}\mathbf{x}\) (\(\mathbf{Q}\) đối xứng):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xác định dương&lt;/strong&gt; (\(f(\mathbf{x}) &amp;gt; 0\) với mọi \(\mathbf{x} \neq \mathbf{0}\)): mọi giá trị riêng của \(\mathbf{Q}\) đều dương.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nửa xác định dương&lt;/strong&gt; (\(f(\mathbf{x}) \geq 0\)): mọi giá trị riêng đều không âm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác định âm&lt;/strong&gt; (\(f(\mathbf{x}) &amp;lt; 0\) với mọi \(\mathbf{x} \neq \mathbf{0}\)): mọi giá trị riêng đều âm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không xác định dấu&lt;/strong&gt; (\(f(\mathbf{x})\) nhận cả giá trị dương và âm): có cả giá trị riêng dương lẫn giá trị riêng âm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-điều-kiện-tối-ưu-bậc-hai&quot;&gt;2. Điều kiện tối ưu bậc hai&lt;/h3&gt;

&lt;p&gt;Với hàm \(f(\mathbf{x})\) khả vi hai lần tại một điểm tới hạn \(\mathbf{x}^*\) (nơi \(\nabla f(\mathbf{x}^*) = \mathbf{0}\)):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu địa phương:&lt;/strong&gt; ma trận Hessian \(\nabla^2 f(\mathbf{x}^*)\) xác định dương (mọi giá trị riêng đều dương).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực đại địa phương:&lt;/strong&gt; ma trận Hessian xác định âm (mọi giá trị riêng đều âm).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm yên ngựa:&lt;/strong&gt; ma trận Hessian không xác định dấu (có cả giá trị riêng dương và âm).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-phân-tích-thành-phần-chính-pca&quot;&gt;3. Phân tích thành phần chính (PCA)&lt;/h3&gt;

&lt;p&gt;PCA tìm các phương mà dữ liệu có phương sai lớn nhất:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Các vector riêng của ma trận hiệp phương sai xác định các trục thành phần chính.&lt;/li&gt;
  &lt;li&gt;Các giá trị riêng tương ứng cho biết phương sai của dữ liệu theo từng trục đó.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-phân-tích-hội-tụ&quot;&gt;4. Phân tích hội tụ&lt;/h3&gt;

&lt;p&gt;Trong các thuật toán tối ưu hóa lặp:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Số điều kiện&lt;/strong&gt; \(\kappa = \frac{\lambda_{\max}}{\lambda_{\min}}\) ảnh hưởng trực tiếp đến tốc độ hội tụ.&lt;/li&gt;
  &lt;li&gt;Số điều kiện lớn dẫn đến hội tụ chậm (đặc biệt với các phương pháp bậc nhất).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5-phương-pháp-newton&quot;&gt;5. Phương pháp Newton&lt;/h3&gt;

&lt;p&gt;Phương pháp Newton sử dụng nghịch đảo của ma trận Hessian:
\(\mathbf{x}_{k+1} = \mathbf{x}_k - [\nabla^2 f(\mathbf{x}_k)]^{-1} \nabla f(\mathbf{x}_k)\)&lt;/p&gt;

&lt;p&gt;Phổ giá trị riêng của ma trận Hessian quyết định hành vi cục bộ và tốc độ hội tụ của phương pháp.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ví-dụ-ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ví dụ: Ứng dụng trong tối ưu hóa&lt;/h2&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa hàm \(f(x, y) = 2x^2 + 3y^2 + 2xy\).&lt;/p&gt;

&lt;p&gt;Ma trận Hessian của hàm là: \(\mathbf{H} = \begin{pmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tìm các giá trị riêng:&lt;/strong&gt;
\(\det(\mathbf{H} - \lambda\mathbf{I}) = (4-\lambda)(6-\lambda) - 4 = \lambda^2 - 10\lambda + 20 = 0\)&lt;/p&gt;

\[\lambda = \frac{10 \pm \sqrt{100-80}}{2} = \frac{10 \pm 2\sqrt{5}}{2} = 5 \pm \sqrt{5}\]

&lt;p&gt;Vì cả hai giá trị riêng đều dương (\(\lambda_1 = 5 + \sqrt{5} &amp;gt; 0\) và \(\lambda_2 = 5 - \sqrt{5} &amp;gt; 0\)), ma trận Hessian xác định dương, khẳng định gốc tọa độ \((0, 0)\) là điểm cực tiểu toàn cục.&lt;/p&gt;

&lt;p&gt;Số điều kiện của ma trận Hessian là \(\kappa = \frac{5 + \sqrt{5}}{5 - \sqrt{5}} \approx 4.24\), cho thấy bài toán có điều kiện số khá tốt đối với các thuật toán tối ưu hóa.&lt;/p&gt;

&lt;p&gt;Nắm vững giá trị riêng và vector riêng giúp ta hiểu rõ cấu trúc hình học và giải tích của các bài toán tối ưu hóa, từ đó thiết kế thuật toán và phân tích hội tụ hiệu quả hơn.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-02-02 Ma trận và Phép biến đổi Tuyến tính</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_02_02_Matrices_and_Linear_Transformations/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_02_02_Matrices_and_Linear_Transformations</id>
   <content type="html">&lt;p&gt;Đừng chỉ nhìn một ma trận như một bảng số hình chữ nhật; trong tối ưu hóa, mỗi ma trận \(A \in \mathbb{R}^{m \times n}\) là một &lt;strong&gt;cỗ máy biến hình không gian&lt;/strong&gt;: nó kéo giãn, xoay, chiếu hoặc ép phẳng các tập lồi trong \(\mathbb{R}^n\) thành những hình dạng mới trong \(\mathbb{R}^m\). Hiểu ma trận như một phép biến đổi tuyến tính giúp bạn hiểu ngay vì sao ảnh affine của một hình cầu là một ellipsoid, hay vì sao hệ ràng buộc \(Ax = b\) mô tả một không gian con dịch chuyển.&lt;/p&gt;

&lt;p&gt;Bài học này kết nối các phép toán đại số trên ma trận với ý nghĩa hình học và cấu trúc nghiệm của hệ phương trình tuyến tính.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-góc-nhìn-về-một-ma-trận-a&quot;&gt;Kiến thức cần nhớ: Bốn góc nhìn về một ma trận \(A\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phép biến đổi tuyến tính:&lt;/strong&gt; Ánh xạ \(T(x) = Ax\) bảo toàn tổ hợp tuyến tính: \(A(\alpha x + \beta y) = \alpha Ax + \beta Ay\). Cột thứ \(j\) của \(A\) chính là ảnh của vector cơ sở chuẩn \(e_j\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bốn không gian con cơ bản:&lt;/strong&gt; Không gian cột \(\mathcal{R}(A)\) (các đầu ra đạt được), không gian hạch \(\mathcal{N}(A)\) (các hướng bị triệt tiêu về \(0\)), cùng \(\mathcal{R}(A^T)\) và \(\mathcal{N}(A^T)\). Khi giải hệ \(Ax = b\), tập nghiệm có dạng \(x_p + \mathcal{N}(A)\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Hạng (Rank), Định thức và Ma trận nghịch đảo:&lt;/strong&gt; Với ma trận vuông \(n\times n\), \(\det(A) \ne 0 \iff \operatorname{rank}(A) = n \iff A\) khả nghịch. Định thức $$&lt;/td&gt;
          &lt;td&gt;\det(A)&lt;/td&gt;
          &lt;td&gt;$$ đo đúng hệ số phóng đại thể tích của phép biến đổi.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ma trận đối xứng và chuyển vị (\(A^T\)):&lt;/strong&gt; Xuất hiện dày đặc trong dạng toàn phương \(x^T Q x\), phương trình chuẩn \(A^T A x = A^T b\) và biểu diễn đối ngẫu của các phép biến đổi tuyến tính.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-mã-phép-biến-đổi-a--beginpmatrix2--1-1--2endpmatrix-và-hệ-ax--b&quot;&gt;Giải thích: Giải mã phép biến đổi \(A = \begin{pmatrix}2 &amp;amp; 1\\ 1 &amp;amp; 2\end{pmatrix}\) và hệ \(Ax = b\)&lt;/h3&gt;

&lt;p&gt;Xét ma trận đối xứng \(A = \begin{pmatrix}2 &amp;amp; 1\\ 1 &amp;amp; 2\end{pmatrix}\) và vector vế phải \(b = \begin{pmatrix}4\\ 5\end{pmatrix}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra khả nghịch và hệ số thể tích:&lt;/strong&gt;
\(\det(A) = 2\cdot 2 - 1\cdot 1 = 3 \ne 0.\)
Phép biến đổi \(x \mapsto Ax\) làm diện tích mọi hình trong \(\mathbb{R}^2\) tăng đúng \(3\) lần và không làm sụp chiều nào (\(\operatorname{rank}(A) = 2\), \(\mathcal{N}(A) = \{0\}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm ma trận nghịch đảo:&lt;/strong&gt;
\(A^{-1} = \frac{1}{3}\begin{pmatrix}2 &amp;amp; -1\\ -1 &amp;amp; 2\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải duy nhất hệ \(Ax = b\):&lt;/strong&gt;
\(x = A^{-1}b = \frac{1}{3}\begin{pmatrix}2\cdot 4 - 1\cdot 5\\ -1\cdot 4 + 2\cdot 5\end{pmatrix} = \frac{1}{3}\begin{pmatrix}3\\ 6\end{pmatrix} = \begin{pmatrix}1\\ 2\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra ngược:&lt;/strong&gt; \(A\begin{pmatrix}1\\ 2\end{pmatrix} = 1\begin{pmatrix}2\\ 1\end{pmatrix} + 2\begin{pmatrix}1\\ 2\end{pmatrix} = \begin{pmatrix}4\\ 5\end{pmatrix} = b\). Vector \(b\) chính là tổ hợp tuyến tính duy nhất của hai cột của \(A\) với trọng số \(1\) và \(2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài học này trình bày về ma trận, các phép toán trên ma trận và phép biến đổi tuyến tính — những công cụ cơ bản để biểu diễn và giải các bài toán tối ưu hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ma-trận-và-các-phép-toán-ma-trận&quot;&gt;Ma trận và các phép toán ma trận&lt;/h2&gt;

&lt;h3 id=&quot;ma-trận-là-gì&quot;&gt;Ma trận là gì?&lt;/h3&gt;

&lt;p&gt;Một &lt;strong&gt;ma trận&lt;/strong&gt; (matrix) là một bảng số hình chữ nhật gồm các phần tử sắp xếp theo hàng và cột. Ma trận được dùng để biểu diễn dữ liệu, phép biến đổi, hệ phương trình và mối quan hệ giữa các biến.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dạng tổng quát:&lt;/strong&gt;
\(\mathbf{A} = \begin{pmatrix} 
a_{11} &amp;amp; a_{12} &amp;amp; \cdots &amp;amp; a_{1n} \\
a_{21} &amp;amp; a_{22} &amp;amp; \cdots &amp;amp; a_{2n} \\
\vdots &amp;amp; \vdots &amp;amp; \ddots &amp;amp; \vdots \\
a_{m1} &amp;amp; a_{m2} &amp;amp; \cdots &amp;amp; a_{mn}
\end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;Đây là ma trận cỡ \(m \times n\) (\(m\) hàng, \(n\) cột).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;
\(\mathbf{A} = \begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 5 &amp;amp; 6 \end{pmatrix}\) là ma trận cỡ \(2 \times 3\).&lt;/p&gt;

&lt;h3 id=&quot;phép-cộng-ma-trận&quot;&gt;Phép cộng ma trận&lt;/h3&gt;

&lt;p&gt;Hai ma trận cùng kích thước được cộng bằng cách cộng từng cặp phần tử ở vị trí tương ứng:&lt;/p&gt;

\[\mathbf{A} + \mathbf{B} = \begin{pmatrix} a_{11} + b_{11} &amp;amp; a_{12} + b_{12} \\ a_{21} + b_{21} &amp;amp; a_{22} + b_{22} \end{pmatrix}\]

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;
\(\begin{pmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{pmatrix} + \begin{pmatrix} 5 &amp;amp; 6 \\ 7 &amp;amp; 8 \end{pmatrix} = \begin{pmatrix} 6 &amp;amp; 8 \\ 10 &amp;amp; 12 \end{pmatrix}\)&lt;/p&gt;

&lt;h3 id=&quot;phép-nhân-vô-hướng&quot;&gt;Phép nhân vô hướng&lt;/h3&gt;

&lt;p&gt;Nhân mọi phần tử của ma trận với một số vô hướng \(c\):&lt;/p&gt;

\[c\mathbf{A} = \begin{pmatrix} ca_{11} &amp;amp; ca_{12} \\ ca_{21} &amp;amp; ca_{22} \end{pmatrix}\]

&lt;h3 id=&quot;phép-nhân-ma-trận&quot;&gt;Phép nhân ma trận&lt;/h3&gt;

&lt;p&gt;Với hai ma trận \(\mathbf{A}_{m \times n}\) và \(\mathbf{B}_{n \times p}\), ma trận tích \(\mathbf{C}_{m \times p} = \mathbf{AB}\) có phần tử ở hàng \(i\), cột \(j\) bằng tích vô hướng của hàng \(i\) của \(\mathbf{A}\) với cột \(j\) của \(\mathbf{B}\):&lt;/p&gt;

\[c_{ij} = \sum_{k=1}^{n} a_{ik} b_{kj}\]

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;
\(\begin{pmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{pmatrix} \begin{pmatrix} 5 &amp;amp; 6 \\ 7 &amp;amp; 8 \end{pmatrix} = \begin{pmatrix} 1 \cdot 5 + 2 \cdot 7 &amp;amp; 1 \cdot 6 + 2 \cdot 8 \\ 3 \cdot 5 + 4 \cdot 7 &amp;amp; 3 \cdot 6 + 4 \cdot 8 \end{pmatrix} = \begin{pmatrix} 19 &amp;amp; 22 \\ 43 &amp;amp; 50 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Phép nhân ma trận &lt;strong&gt;không có tính giao hoán&lt;/strong&gt; — nói chung \(\mathbf{AB} \neq \mathbf{BA}\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;phép-biến-đổi-tuyến-tính&quot;&gt;Phép biến đổi tuyến tính&lt;/h2&gt;

&lt;p&gt;Một &lt;strong&gt;phép biến đổi tuyến tính&lt;/strong&gt; là ánh xạ \(T: \mathbb{R}^n \to \mathbb{R}^m\) bảo toàn phép cộng vector và phép nhân vô hướng. Mọi phép biến đổi tuyến tính giữa các không gian hữu hạn chiều đều có thể biểu diễn bằng một ma trận.&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h3&gt;

&lt;p&gt;Ánh xạ \(T(\mathbf{v}) = \mathbf{Av}\) là tuyến tính khi và chỉ khi:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính cộng:&lt;/strong&gt; \(T(\mathbf{u} + \mathbf{v}) = T(\mathbf{u}) + T(\mathbf{v})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính thuần nhất:&lt;/strong&gt; \(T(c\mathbf{v}) = cT(\mathbf{v})\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hai điều kiện trên có thể gộp thành một điều kiện tương đương: \(T(c_1\mathbf{u} + c_2\mathbf{v}) = c_1T(\mathbf{u}) + c_2T(\mathbf{v})\).&lt;/p&gt;

&lt;h3 id=&quot;phép-nhân-ma-trận-với-vector&quot;&gt;Phép nhân ma trận với vector&lt;/h3&gt;

&lt;p&gt;Nếu \(\mathbf{A}\) là ma trận \(m \times n\) và \(\mathbf{v}\) là vector cột \(n \times 1\), thì tích \(\mathbf{Av}\) là vector cột \(m \times 1\):&lt;/p&gt;

\[\mathbf{w} = \mathbf{Av} = \begin{pmatrix} 
a_{11}v_1 + a_{12}v_2 + \cdots + a_{1n}v_n \\
a_{21}v_1 + a_{22}v_2 + \cdots + a_{2n}v_n \\
\vdots \\
a_{m1}v_1 + a_{m2}v_2 + \cdots + a_{mn}v_n
\end{pmatrix}\]

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;
\(\begin{pmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 3 \end{pmatrix} \begin{pmatrix} 4 \\ 5 \end{pmatrix} = \begin{pmatrix} 2 \cdot 4 + 1 \cdot 5 \\ 0 \cdot 4 + 3 \cdot 5 \end{pmatrix} = \begin{pmatrix} 13 \\ 15 \end{pmatrix}\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;các-phép-biến-đổi-2d-thường-gặp&quot;&gt;Các phép biến đổi 2D thường gặp&lt;/h2&gt;

&lt;p&gt;Quan sát các phép biến đổi hình học trong mặt phẳng giúp hình dung rõ cách ma trận tác động lên vector.&lt;/p&gt;

&lt;h3 id=&quot;phép-co-giãn-scaling&quot;&gt;Phép co giãn (Scaling)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ma trận co giãn:&lt;/strong&gt;
\(\mathbf{S} = \begin{pmatrix} s_x &amp;amp; 0 \\ 0 &amp;amp; s_y \end{pmatrix}\)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Co giãn tọa độ \(x\) theo hệ số \(s_x\) và tọa độ \(y\) theo hệ số \(s_y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; \(\begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 3 \end{pmatrix}\) nhân đôi tọa độ \(x\) và nhân ba tọa độ \(y\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phép-quay-rotation&quot;&gt;Phép quay (Rotation)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ma trận quay ngược chiều kim đồng hồ một góc \(\theta\):&lt;/strong&gt;
\(\mathbf{R} = \begin{pmatrix} \cos\theta &amp;amp; -\sin\theta \\ \sin\theta &amp;amp; \cos\theta \end{pmatrix}\)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; phép quay \(90°\) có ma trận \(\begin{pmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{pmatrix}\), biến điểm \((x, y)\) thành \((-y, x)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phép-phản-xạ-reflection&quot;&gt;Phép phản xạ (Reflection)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phản xạ qua trục \(x\):&lt;/strong&gt;
\(\mathbf{F}_x = \begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phản xạ qua trục \(y\):&lt;/strong&gt;
\(\mathbf{F}_y = \begin{pmatrix} -1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phản xạ qua đường thẳng \(y = x\):&lt;/strong&gt;
\(\mathbf{F}_{y=x} = \begin{pmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{pmatrix}\)&lt;/p&gt;

&lt;h3 id=&quot;phép-trượt-shearing&quot;&gt;Phép trượt (Shearing)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Trượt ngang:&lt;/strong&gt;
\(\mathbf{H} = \begin{pmatrix} 1 &amp;amp; k \\ 0 &amp;amp; 1 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;Biến điểm \((x, y)\) thành \((x + ky, y)\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;các-loại-ma-trận-đặc-biệt&quot;&gt;Các loại ma trận đặc biệt&lt;/h2&gt;

&lt;h3 id=&quot;ma-trận-đơn-vị&quot;&gt;Ma trận đơn vị&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ma trận đơn vị&lt;/strong&gt; \(\mathbf{I}\) đóng vai trò phần tử đơn vị (tương tự số 1) đối với phép nhân ma trận:&lt;/p&gt;

\[\mathbf{I}_n = \begin{pmatrix} 
1 &amp;amp; 0 &amp;amp; \cdots &amp;amp; 0 \\
0 &amp;amp; 1 &amp;amp; \cdots &amp;amp; 0 \\
\vdots &amp;amp; \vdots &amp;amp; \ddots &amp;amp; \vdots \\
0 &amp;amp; 0 &amp;amp; \cdots &amp;amp; 1
\end{pmatrix}\]

&lt;p&gt;&lt;strong&gt;Tính chất:&lt;/strong&gt; \(\mathbf{AI} = \mathbf{IA} = \mathbf{A}\) với mọi ma trận \(\mathbf{A}\) có kích thước tương thích.&lt;/p&gt;

&lt;h3 id=&quot;ma-trận-chuyển-vị&quot;&gt;Ma trận chuyển vị&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Chuyển vị&lt;/strong&gt; \(\mathbf{A}^T\) thu được bằng cách đổi hàng thành cột (lật ma trận qua đường chéo chính):&lt;/p&gt;

\[\text{Nếu } \mathbf{A} = \begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 5 &amp;amp; 6 \end{pmatrix}, \text{ thì } \mathbf{A}^T = \begin{pmatrix} 1 &amp;amp; 4 \\ 2 &amp;amp; 5 \\ 3 &amp;amp; 6 \end{pmatrix}\]

&lt;p&gt;&lt;strong&gt;Các tính chất:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[(\mathbf{A}^T)^T = \mathbf{A}\]
  &lt;/li&gt;
  &lt;li&gt;
\[(\mathbf{A} + \mathbf{B})^T = \mathbf{A}^T + \mathbf{B}^T\]
  &lt;/li&gt;
  &lt;li&gt;
\[(\mathbf{AB})^T = \mathbf{B}^T\mathbf{A}^T\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ma-trận-đối-xứng&quot;&gt;Ma trận đối xứng&lt;/h3&gt;

&lt;p&gt;Một ma trận vuông là &lt;strong&gt;đối xứng&lt;/strong&gt; nếu \(\mathbf{A} = \mathbf{A}^T\):&lt;/p&gt;

\[\mathbf{A} = \begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 2 &amp;amp; 4 &amp;amp; 5 \\ 3 &amp;amp; 5 &amp;amp; 6 \end{pmatrix}\]

&lt;p&gt;Ma trận đối xứng có nhiều tính chất đặc biệt (như giá trị riêng thực và khả năng chéo hóa trực giao) rất quan trọng trong tối ưu hóa.&lt;/p&gt;

&lt;h3 id=&quot;ma-trận-nghịch-đảo&quot;&gt;Ma trận nghịch đảo&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ma trận nghịch đảo&lt;/strong&gt; \(\mathbf{A}^{-1}\) của ma trận vuông \(\mathbf{A}\) thỏa mãn:&lt;/p&gt;

\[\mathbf{A}\mathbf{A}^{-1} = \mathbf{A}^{-1}\mathbf{A} = \mathbf{I}\]

&lt;p&gt;&lt;strong&gt;Với ma trận \(2 \times 2\):&lt;/strong&gt;
\(\mathbf{A}^{-1} = \frac{1}{\det(\mathbf{A})} \begin{pmatrix} d &amp;amp; -b \\ -c &amp;amp; a \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;trong đó \(\mathbf{A} = \begin{pmatrix} a &amp;amp; b \\ c &amp;amp; d \end{pmatrix}\) và \(\det(\mathbf{A}) = ad - bc\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Không phải ma trận vuông nào cũng có nghịch đảo. Một ma trận &lt;strong&gt;khả nghịch&lt;/strong&gt; (không suy biến) khi và chỉ khi định thức của nó khác không.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong tối ưu hóa&lt;/h2&gt;

&lt;p&gt;Ma trận và phép biến đổi tuyến tính xuất hiện xuyên suốt các bài toán tối ưu hóa:&lt;/p&gt;

&lt;h3 id=&quot;1-hệ-phương-trình-tuyến-tính&quot;&gt;1. Hệ phương trình tuyến tính&lt;/h3&gt;

&lt;p&gt;Nhiều bài toán tối ưu hóa quy về việc giải hệ \(\mathbf{Ax} = \mathbf{b}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nghiệm duy nhất:&lt;/strong&gt; \(\mathbf{x} = \mathbf{A}^{-1}\mathbf{b}\) (khi \(\mathbf{A}\) vuông và khả nghịch).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bình phương tối thiểu:&lt;/strong&gt; cực tiểu hóa \(\|\mathbf{Ax} - \mathbf{b}\|^2\) khi hệ không có nghiệm chính xác.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-dạng-toàn-phương&quot;&gt;2. Dạng toàn phương&lt;/h3&gt;

&lt;p&gt;Các hàm toàn phương rất phổ biến trong tối ưu hóa:
\(f(\mathbf{x}) = \mathbf{x}^T\mathbf{Q}\mathbf{x} + \mathbf{c}^T\mathbf{x} + d\)&lt;/p&gt;

&lt;p&gt;Ma trận \(\mathbf{Q}\) quyết định độ cong và tính lồi của hàm số.&lt;/p&gt;

&lt;h3 id=&quot;3-quy-hoạch-tuyến-tính&quot;&gt;3. Quy hoạch tuyến tính&lt;/h3&gt;

&lt;p&gt;Dạng chuẩn: cực tiểu hóa \(\mathbf{c}^T\mathbf{x}\) với điều kiện \(\mathbf{Ax} = \mathbf{b}\), \(\mathbf{x} \geq \mathbf{0}\).&lt;/p&gt;

&lt;h3 id=&quot;4-biểu-diễn-ràng-buộc&quot;&gt;4. Biểu diễn ràng buộc&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc đẳng thức:&lt;/strong&gt; \(\mathbf{Ax} = \mathbf{b}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc bất đẳng thức:&lt;/strong&gt; \(\mathbf{Ax} \leq \mathbf{b}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5-phép-đổi-biến&quot;&gt;5. Phép đổi biến&lt;/h3&gt;

&lt;p&gt;Áp dụng phép đổi biến tuyến tính \(\mathbf{y} = \mathbf{T}\mathbf{x}\) có thể đơn giản hóa cấu trúc của bài toán tối ưu hóa.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-tối-ưu-danh-mục-đầu-tư&quot;&gt;Ví dụ: Tối ưu danh mục đầu tư&lt;/h3&gt;

&lt;p&gt;Trong tài chính định lượng, bài toán cực tiểu hóa rủi ro danh mục có dạng:
\(\text{cực tiểu hóa } \mathbf{w}^T\mathbf{\Sigma}\mathbf{w}\)&lt;/p&gt;

&lt;p&gt;trong đó \(\mathbf{w}\) là vector trọng số phân bổ vốn và \(\mathbf{\Sigma}\) là ma trận hiệp phương sai lợi suất của các tài sản.&lt;/p&gt;

&lt;p&gt;Nắm vững ma trận và phép biến đổi tuyến tính cung cấp nền tảng để mô hình hóa, phân tích và giải hiệu quả nhiều bài toán tối ưu hóa.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-02-01 Vector và Không gian Vector</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_02_01_Vectors_and_Vector_Spaces/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_02_01_Vectors_and_Vector_Spaces</id>
   <content type="html">&lt;p&gt;Trong tối ưu hóa, một “phương án” — dù là danh mục đầu tư 50 cổ phiếu, lịch vận hành 24 giờ của nhà máy điện, hay bộ trọng số của một mô hình dự báo — đều được mã hóa thành một điểm duy nhất: một &lt;strong&gt;vector&lt;/strong&gt; \(x \in \mathbb{R}^n\). Khi hiểu không gian vector, cơ sở, tích vô hướng và các chuẩn khác nhau, bạn sẽ nhìn thấy ngay vì sao hình cầu đơn vị của chuẩn \(\ell_1\) có các góc nhọn tạo nghiệm thưa còn chuẩn \(\ell_2\) lại trơn tròn.&lt;/p&gt;

&lt;p&gt;Bài học này đặt lại nền tảng cho mọi thao tác vector sẽ xuất hiện xuyên suốt các chương về tập lồi và đối ngẫu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-của-không-gian-mathbbrn&quot;&gt;Kiến thức cần nhớ: Hình học của không gian \(\mathbb{R}^n\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp tuyến tính, độc lập tuyến tính và cơ sở:&lt;/strong&gt; Cho biết tập các hướng cơ bản nhỏ nhất có thể sinh ra toàn bộ không gian tìm kiếm; tránh dư thừa biến hoặc ràng buộc phụ thuộc tuyến tính.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Tích vô hướng và bất đẳng thức Cauchy–Schwarz:&lt;/strong&gt; Định nghĩa góc, tính trực giao và phép chiếu: $$&lt;/td&gt;
          &lt;td&gt;u^T v&lt;/td&gt;
          &lt;td&gt;\le |u|_2 |v|_2\(. Đây cũng là nguồn gốc trực tiếp của biểu diễn siêu phẳng\)a^T x = b$$ trong Chương 02.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các chuẩn vector (\(\ell_1, \ell_2, \ell_\infty\)):&lt;/strong&gt; Là những “thước đo độ dài” khác nhau trên cùng một không gian. Mỗi chuẩn sinh ra một dạng phạt điều chuẩn (regularization) riêng biệt trong học máy và tối ưu hóa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không gian con (Subspace):&lt;/strong&gt; Tập các vector đóng dưới phép cộng và nhân vô hướng (luôn đi qua gốc tọa độ), là nguyên mẫu để định nghĩa tập affine \(x_0 + V\) ở chương sau.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-ba-chuẩn-và-kiểm-chứng-cauchyschwarz-trên-v--3--4t&quot;&gt;Giải thích: So sánh ba chuẩn và kiểm chứng Cauchy–Schwarz trên \(v = (3, -4)^T\)&lt;/h3&gt;

&lt;p&gt;Cho hai vector trong \(\mathbb{R}^2\): \(v = (3, -4)^T\) và \(w = (1, 2)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính ba chuẩn phổ biến của \(v\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Chuẩn \(\ell_1\) (khoảng cách Manhattan): $$|v|_1 =&lt;/td&gt;
              &lt;td&gt;3&lt;/td&gt;
              &lt;td&gt;+&lt;/td&gt;
              &lt;td&gt;-4&lt;/td&gt;
              &lt;td&gt;= 7$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Chuẩn \(\ell_2\) (khoảng cách Euclid): \(\|v\|_2 = \sqrt{3^2 + (-4)^2} = \sqrt{25} = 5\).&lt;/li&gt;
      &lt;li&gt;Chuẩn \(\ell_\infty\) (thành phần cực đại): \(\|v\|_\infty = \max(|3|, |-4|) = 4\).
Quan sát trật tự luôn đúng trên \(\mathbb{R}^n\): \(\|v\|_\infty \le \|v\|_2 \le \|v\|_1\) (\(4 \le 5 \le 7\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng bất đẳng thức Cauchy–Schwarz:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Tích vô hướng: $$v^T w = 3(1) + (-4)(2) = -5 \implies&lt;/td&gt;
              &lt;td&gt;v^T w&lt;/td&gt;
              &lt;td&gt;= 5$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Tích hai chuẩn Euclid: \(\|v\|_2 \|w\|_2 = 5 \cdot \sqrt{1^2 + 2^2} = 5\sqrt{5} \approx 11.18\).
Ta thấy \(5 \le 11.18\), và góc \(\theta\) giữa hai vector thỏa \(\cos\theta = \frac{-5}{5\sqrt{5}} = -\frac{1}{\sqrt{5}} \approx -0.447\) (góc tù \(\approx 116.6^\circ\) — nếu \(v\) là gradient thì \(w\) là một hướng giảm!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài học này giới thiệu về vector, không gian vector và các khái niệm cơ bản tạo nền tảng cho đại số tuyến tính trong tối ưu hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;vector-và-không-gian-vector-mathbbrn&quot;&gt;Vector và không gian vector (\(\mathbb{R}^n\))&lt;/h2&gt;

&lt;h3 id=&quot;vector-là-gì&quot;&gt;Vector là gì?&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Vector:&lt;/strong&gt; Có thể hình dung vector như một mũi tên trong không gian, biểu diễn cả hướng và độ lớn (độ dài). Về mặt đại số, vector là một bộ có thứ tự gồm các số thực, tương tự như tọa độ của một điểm. Chẳng hạn, một vector trong không gian hai chiều có thể là \(\mathbf{v} = \begin{pmatrix} 3 \\ 4 \end{pmatrix}\), tương ứng với 3 đơn vị theo trục \(x\) và 4 đơn vị theo trục \(y\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Góc nhìn hình học và đại số:&lt;/strong&gt;&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Hình học:&lt;/strong&gt; vector là đoạn thẳng có hướng với độ lớn xác định.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Đại số:&lt;/strong&gt; vector là bộ có thứ tự gồm các số thực.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;không-gian-vector&quot;&gt;Không gian vector&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Không gian vector (\(\mathbb{R}^n\)):&lt;/strong&gt; Là tập hợp tất cả các vector gồm \(n\) thành phần thực. Ví dụ, \(\mathbb{R}^2\) là tập hợp mọi vector có 2 thành phần, biểu diễn các điểm hoặc mũi tên trong mặt phẳng hai chiều.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\mathbb{R}^2 = \left\{\begin{pmatrix} x \\ y \end{pmatrix} : x, y \in \mathbb{R}\right\}\) (mặt phẳng 2D)&lt;/li&gt;
      &lt;li&gt;\(\mathbb{R}^3 = \left\{\begin{pmatrix} x \\ y \\ z \end{pmatrix} : x, y, z \in \mathbb{R}\right\}\) (không gian 3D)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;các-phép-toán-trên-vector&quot;&gt;Các phép toán trên vector&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phép cộng vector:&lt;/strong&gt;
\(\mathbf{u} + \mathbf{v} = \begin{pmatrix} u_1 \\ u_2 \\ \vdots \\ u_n \end{pmatrix} + \begin{pmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{pmatrix} = \begin{pmatrix} u_1 + v_1 \\ u_2 + v_2 \\ \vdots \\ u_n + v_n \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phép nhân vô hướng:&lt;/strong&gt;
\(c\mathbf{v} = c \begin{pmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{pmatrix} = \begin{pmatrix} cv_1 \\ cv_2 \\ \vdots \\ cv_n \end{pmatrix}\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;độc-lập-tuyến-tính-cơ-sở-và-số-chiều&quot;&gt;Độc lập tuyến tính, cơ sở và số chiều&lt;/h2&gt;

&lt;h3 id=&quot;độc-lập-tuyến-tính&quot;&gt;Độc lập tuyến tính&lt;/h3&gt;

&lt;p&gt;Một hệ vector \(\{\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_k\}\) được gọi là &lt;strong&gt;độc lập tuyến tính&lt;/strong&gt; nếu phương trình&lt;/p&gt;

\[c_1\mathbf{v}_1 + c_2\mathbf{v}_2 + \cdots + c_k\mathbf{v}_k = \mathbf{0}\]

&lt;p&gt;chỉ có nghiệm tầm thường \(c_1 = c_2 = \cdots = c_k = 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa trực quan:&lt;/strong&gt; Một hệ vector độc lập tuyến tính khi không có vector nào trong hệ có thể biểu diễn được bằng cách nhân vô hướng và cộng các vector còn lại. Các vector này độc lập về phương hướng, không bị dư thừa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ trong \(\mathbb{R}^2\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{v}_1 = \begin{pmatrix} 1 \\ 0 \end{pmatrix}\) và \(\mathbf{v}_2 = \begin{pmatrix} 0 \\ 1 \end{pmatrix}\) độc lập tuyến tính.&lt;/li&gt;
  &lt;li&gt;\(\mathbf{v}_1 = \begin{pmatrix} 1 \\ 2 \end{pmatrix}\) và \(\mathbf{v}_2 = \begin{pmatrix} 2 \\ 4 \end{pmatrix}\) phụ thuộc tuyến tính (vì \(\mathbf{v}_2 = 2\mathbf{v}_1\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;cơ-sở&quot;&gt;Cơ sở&lt;/h3&gt;

&lt;p&gt;Một &lt;strong&gt;cơ sở&lt;/strong&gt; của không gian vector là một hệ vector độc lập tuyến tính tối tiểu có thể tổ hợp (nhân vô hướng và cộng) để tạo thành &lt;em&gt;mọi&lt;/em&gt; vector trong không gian đó.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất của một cơ sở:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Các vector trong cơ sở độc lập tuyến tính.&lt;/li&gt;
  &lt;li&gt;Hệ vector đó sinh ra toàn bộ không gian vector.&lt;/li&gt;
  &lt;li&gt;Mọi vector trong không gian đều biểu diễn được một cách duy nhất dưới dạng tổ hợp tuyến tính của các vector cơ sở.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Cơ sở chính tắc của \(\mathbb{R}^n\):&lt;/strong&gt;
\(\mathbf{e}_1 = \begin{pmatrix} 1 \\ 0 \\ \vdots \\ 0 \end{pmatrix}, \mathbf{e}_2 = \begin{pmatrix} 0 \\ 1 \\ \vdots \\ 0 \end{pmatrix}, \ldots, \mathbf{e}_n = \begin{pmatrix} 0 \\ 0 \\ \vdots \\ 1 \end{pmatrix}\)&lt;/p&gt;

&lt;h3 id=&quot;số-chiều&quot;&gt;Số chiều&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Số chiều&lt;/strong&gt; của một không gian vector là số lượng vector có trong bất kỳ cơ sở nào của không gian đó, phản ánh số hướng độc lập cần thiết để mô tả toàn bộ không gian.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[\dim(\mathbb{R}^2) = 2\]
  &lt;/li&gt;
  &lt;li&gt;
\[\dim(\mathbb{R}^3) = 3\]
  &lt;/li&gt;
  &lt;li&gt;
\[\dim(\mathbb{R}^n) = n\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;chuẩn-của-vector&quot;&gt;Chuẩn của vector&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Chuẩn&lt;/strong&gt; là một hàm gán “độ dài” hoặc “kích thước” cho mỗi vector, tổng quát hóa khái niệm khoảng cách từ gốc tọa độ.&lt;/p&gt;

&lt;h3 id=&quot;tính-chất-của-chuẩn&quot;&gt;Tính chất của chuẩn&lt;/h3&gt;

&lt;p&gt;Mọi chuẩn \(\|\cdot\|\) đều phải thỏa mãn ba tiên đề:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính xác định không âm:&lt;/strong&gt; \(\|\mathbf{x}\| \geq 0\), và \(\|\mathbf{x}\| = 0\) khi và chỉ khi \(\mathbf{x} = \mathbf{0}\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Tính thuần nhất:&lt;/strong&gt; $$|t\mathbf{x}| =&lt;/td&gt;
          &lt;td&gt;t&lt;/td&gt;
          &lt;td&gt;|\mathbf{x}|\(với mọi số thực\)t$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức tam giác:&lt;/strong&gt; \(\|\mathbf{x} + \mathbf{y}\| \leq \|\mathbf{x}\| + \|\mathbf{y}\|\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;các-chuẩn-thông-dụng&quot;&gt;Các chuẩn thông dụng&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Chuẩn Euclid (chuẩn \(L_2\)):&lt;/strong&gt;
\(\|\mathbf{x}\|_2 = \sqrt{\sum_{i=1}^n x_i^2} = \sqrt{x_1^2 + x_2^2 + \cdots + x_n^2}\)&lt;/p&gt;

&lt;p&gt;Đây là khoảng cách hình học quen thuộc trong không gian Euclid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chuẩn Manhattan (chuẩn \(L_1\)):&lt;/strong&gt;
\(\|\mathbf{x}\|_1 = \sum_{i=1}^n |x_i| = |x_1| + |x_2| + \cdots + |x_n|\)&lt;/p&gt;

&lt;p&gt;Còn được gọi là “chuẩn taxi”, tương ứng với quãng đường di chuyển dọc theo lưới ô vuông của các tuyến phố.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chuẩn cực đại (chuẩn \(L_\infty\)):&lt;/strong&gt;
\(\|\mathbf{x}\|_\infty = \max_{i} |x_i|\)&lt;/p&gt;

&lt;p&gt;Bằng giá trị tuyệt đối lớn nhất trong các thành phần của vector.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; Với \(\mathbf{x} = \begin{pmatrix} 3 \\ -4 \\ 1 \end{pmatrix}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\|\mathbf{x}\|_2 = \sqrt{3^2 + (-4)^2 + 1^2} = \sqrt{26} \approx 5.1\]
  &lt;/li&gt;
  &lt;li&gt;
\[\|\mathbf{x}\|_1 = |3| + |-4| + |1| = 8\]
  &lt;/li&gt;
  &lt;li&gt;
\[\|\mathbf{x}\|_\infty = \max\{|3|, |-4|, |1|\} = 4\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tích-vô-hướng-tích-chấm&quot;&gt;Tích vô hướng (tích chấm)&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tích vô hướng&lt;/strong&gt; (hay tích chấm) là phép toán phổ biến giữa hai vector cùng chiều, cho kết quả là một số vô hướng.&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h3&gt;

&lt;p&gt;Với hai vector \(\mathbf{x}\) và \(\mathbf{y}\) trong \(\mathbb{R}^n\):&lt;/p&gt;

\[\mathbf{x}^T \mathbf{y} = \mathbf{x} \cdot \mathbf{y} = \sum_{i=1}^n x_i y_i = x_1 y_1 + x_2 y_2 + \cdots + x_n y_n\]

&lt;h3 id=&quot;diễn-giải-hình-học&quot;&gt;Diễn giải hình học&lt;/h3&gt;

\[\mathbf{x} \cdot \mathbf{y} = \|\mathbf{x}\| \|\mathbf{y}\| \cos \theta\]

&lt;p&gt;trong đó \(\theta\) là góc giữa hai vector \(\mathbf{x}\) và \(\mathbf{y}\).&lt;/p&gt;

&lt;h3 id=&quot;tính-chất&quot;&gt;Tính chất&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giao hoán:&lt;/strong&gt; \(\mathbf{x} \cdot \mathbf{y} = \mathbf{y} \cdot \mathbf{x}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính phân phối:&lt;/strong&gt; \(\mathbf{x} \cdot (\mathbf{y} + \mathbf{z}) = \mathbf{x} \cdot \mathbf{y} + \mathbf{x} \cdot \mathbf{z}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính thuần nhất:&lt;/strong&gt; \((c\mathbf{x}) \cdot \mathbf{y} = c(\mathbf{x} \cdot \mathbf{y})\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;các-trường-hợp-đặc-biệt&quot;&gt;Các trường hợp đặc biệt&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hai vector trực giao:&lt;/strong&gt; \(\mathbf{x} \cdot \mathbf{y} = 0\) (vuông góc với nhau).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai vector cùng phương:&lt;/strong&gt; \(\mathbf{x} \cdot \mathbf{y} = \pm \|\mathbf{x}\| \|\mathbf{y}\|\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tích vô hướng với chính nó:&lt;/strong&gt; \(\mathbf{x} \cdot \mathbf{x} = \|\mathbf{x}\|_2^2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h3&gt;

&lt;p&gt;Với \(\mathbf{x} = \begin{pmatrix} 1 \\ 2 \end{pmatrix}\) và \(\mathbf{y} = \begin{pmatrix} 3 \\ 4 \end{pmatrix}\):&lt;/p&gt;

\[\mathbf{x}^T \mathbf{y} = (1)(3) + (2)(4) = 3 + 8 = 11\]

&lt;hr /&gt;

&lt;h2 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong tối ưu hóa&lt;/h2&gt;

&lt;p&gt;Vector và không gian vector giữ vai trò cốt lõi trong tối ưu hóa ở các khía cạnh sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Biến quyết định:&lt;/strong&gt; Bài toán tối ưu hóa nhiều biến được biểu diễn gọn gàng dưới dạng tìm một vector biến tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient:&lt;/strong&gt; Gradient của hàm số là một vector chỉ theo hướng tăng nhanh nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc:&lt;/strong&gt; Ràng buộc tuyến tính được biểu diễn trực tiếp bằng tích vô hướng: \(\mathbf{a}^T \mathbf{x} \leq b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng cách và độ lớn bước lặp:&lt;/strong&gt; Các chuẩn khác nhau cho phép đo khoảng cách giữa các nghiệm hoặc kích thước bước dịch chuyển theo những tiêu chí khác nhau.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính trực giao:&lt;/strong&gt; Nhiều tính chất trong tối ưu hóa gắn với quan hệ vuông góc, chẳng hạn giữa vector gradient và tiếp tuyến của đường mức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp tuyến tính:&lt;/strong&gt; Nhiều vùng khả thi được xây dựng từ tổ hợp tuyến tính của các vector (bao lồi, nón lồi, v.v.).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Khung lý thuyết về không gian vector cung cấp ngôn ngữ toán học chuẩn xác để mô hình hóa và giải các bài toán tối ưu hóa một cách có hệ thống.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01 Giải tích</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_01_Calculus/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_01_Calculus</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng bạn đang đứng trên một sườn núi dày đặc sương mù, tầm nhìn chỉ vài bước chân, và nhiệm vụ là đi xuống thung lũng sâu nhất. Bạn không nhìn thấy bản đồ toàn vùng, nhưng đôi chân bạn cảm nhận được độ dốc ngay dưới đế giày. &lt;strong&gt;Giải tích&lt;/strong&gt; chính là nghệ thuật đọc độ dốc và độ cong cục bộ ấy — biến những thông tin rất nhỏ xung quanh một điểm thành quyết định bước đi tiếp theo cho thuật toán tối ưu.&lt;/p&gt;

&lt;p&gt;Trong phần 00-01 này, chúng ta kết nối bốn mảnh ghép giải tích thiết yếu: tính liên tục, đạo hàm đa biến, gradient–đạo hàm theo hướng và chuỗi Taylor.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-giải-tích-phục-vụ-tối-ưu-hóa&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép giải tích phục vụ tối ưu hóa&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch00_calculus_foundation.svg&quot; alt=&quot;Nền tảng Giải tích Đa biến cho Tối ưu hóa&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính liên tục và tính Lipschitz:&lt;/strong&gt; Đảm bảo hàm mục tiêu không bị “nhảy vọt” bất ngờ khi ta nhích biến \(x\) một lượng nhỏ. Đặc biệt, hằng số Lipschitz \(L\) của gradient đặt ra giới hạn an toàn cho kích thước bước nhảy \(\eta \le 1/L\) trong Gradient Descent.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đạo hàm và vi phân đa biến:&lt;/strong&gt; Mở rộng khái niệm độ dốc từ đường cong một biến sang siêu mặt trong \(\mathbb{R}^n\) thông qua đạo hàm riêng, ma trận Jacobian và ma trận Hessian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient và đạo hàm theo hướng:&lt;/strong&gt; Xác định chính xác hướng làm hàm tăng nhanh nhất (\(\nabla f\)), hướng giảm nhanh nhất (\(-\nabla f\)) và mối liên hệ trực giao với các đường mức (contour lines).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuỗi Taylor (bậc nhất và bậc hai):&lt;/strong&gt; Xấp xỉ một hàm phi tuyến phức tạp bằng mặt phẳng tiếp tuyến (bậc 1 — nền tảng của Gradient Descent) hoặc mặt paraboloid (bậc 2 — nền tảng của phương pháp Newton).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-một-bước-hạ-dốc-trên-parabol-fx--x2---4x--5&quot;&gt;Giải thích: Một bước hạ dốc trên parabol \(f(x) = x^2 - 4x + 5\)&lt;/h3&gt;

&lt;p&gt;Xét hàm mục tiêu \(f(x) = x^2 - 4x + 5\) (nghiệm tối ưu thật là \(x^* = 2\) với \(f(2) = 1\)). Giả sử thuật toán xuất phát tại \(x_0 = 0\) với tốc độ học \(\eta = 0.25\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Đánh giá hiện trạng:&lt;/strong&gt; Tại \(x_0 = 0\), giá trị hàm là \(f(0) = 0^2 - 4(0) + 5 = 5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đọc độ dốc bằng đạo hàm:&lt;/strong&gt; \(f&apos;(x) = 2x - 4 \Rightarrow f&apos;(0) = -4\). Dấu âm báo hiệu đi sang phải (tăng \(x\)) sẽ làm \(f\) giảm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật bước đầu tiên:&lt;/strong&gt;
\(x_1 = x_0 - \eta f&apos;(x_0) = 0 - 0.25 \cdot (-4) = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng mức giảm:&lt;/strong&gt; \(f(1) = 1^2 - 4(1) + 5 = 2 &amp;lt; 5\). Chỉ sau một bước, sai số so với đáy đã giảm từ \(4\) xuống còn \(1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước tiếp theo:&lt;/strong&gt; \(f&apos;(1) = 2(1) - 4 = -2 \Rightarrow x_2 = 1 - 0.25(-2) = 1.5\), \(f(1.5) = 1.25\). Vì \(f&apos;&apos;(x) = 2\) (hằng số Lipschitz \(L = 2\)), mọi bước học \(0 &amp;lt; \eta &amp;lt; 2/L = 1\) đều đảm bảo hội tụ về \(x^* = 2\); riêng nếu chọn \(\eta = 1/L = 0.5\), ta nhảy thẳng tới \(x_1 = 0 - 0.5(-4) = 2\) chỉ trong đúng 1 bước!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Tối ưu hóa gắn liền với &lt;em&gt;sự thay đổi&lt;/em&gt;: một bước lặp làm giảm hàm mất mát, một ràng buộc trở thành ràng buộc chặt, hay một xấp xỉ Taylor chính xác trong lân cận điểm đang xét. Ngôn ngữ để mô tả những điều đó là giải tích. Trang này đóng vai trò bản đồ tổng quan cho bốn bài giải tích tiếp theo, không thay thế nội dung chi tiết của chúng.&lt;/p&gt;

&lt;h2 id=&quot;những-nội-dung-cần-thành-thạo&quot;&gt;Những nội dung cần thành thạo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính liên tục&lt;/strong&gt;: đảm bảo một dãy điểm giảm dần không “nhảy qua” điểm cực tiểu, đồng thời hàm liên tục trên tập compact luôn đạt giá trị nhỏ nhất (định lý Weierstrass).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đạo hàm và quy tắc dây chuyền nhiều biến&lt;/strong&gt;: mọi phép tính gradient trong mạng nơ-ron đều là một chuỗi dài của quy tắc dây chuyền — nội dung này sẽ quay trở lại ở &lt;a href=&quot;/contents/vi/chapter27/&quot;&gt;Chương 27&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient và đạo hàm theo hướng&lt;/strong&gt;: mô hình bậc nhất \(f(x+d) \approx f(x) + \nabla f(x)^\top d\) là cơ sở để thuật toán gradient descent (Chương 06) hoạt động, trong đó \(-\nabla f(x)\) là hướng giảm nhanh nhất theo hình học Euclid.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khai triển Taylor&lt;/strong&gt;: phương pháp Newton (Chương 14) thực hiện bước cực tiểu hóa xấp xỉ bậc hai cục bộ \(f(x) + \nabla f(x)^\top d + \tfrac12 d^\top \nabla^2 f(x)\, d\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hàm \(f:\mathbb{R}^n\to\mathbb{R}\) khả vi tại \(x\) nếu&lt;/p&gt;

\[\lim_{\|h\|\to 0}\frac{f(x+h)-f(x)-\nabla f(x)^\top h}{\|h\|}=0.\]

&lt;p&gt;Nếu \(\nabla f\) liên tục Lipschitz với hằng số \(L\), bổ đề giảm (descent lemma)&lt;/p&gt;

\[f(y) \le f(x) + \nabla f(x)^\top(y-x) + \tfrac{L}{2}\|y-x\|_2^2\]

&lt;p&gt;cho ta cận trên của kích thước bước \(t \le 1/L\), được sử dụng xuyên suốt lý thuyết tối ưu hóa bậc nhất.&lt;/p&gt;

&lt;h2 id=&quot;các-bài-trong-phần-này&quot;&gt;Các bài trong phần này&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Liên tục và liên tục đều&lt;/li&gt;
  &lt;li&gt;Đạo hàm và giải tích đa biến&lt;/li&gt;
  &lt;li&gt;Gradient và đạo hàm theo hướng&lt;/li&gt;
  &lt;li&gt;Chuỗi Taylor&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hãy đọc các bài theo đúng thứ tự, sau đó tự kiểm tra bằng cách viết \(\nabla f\) và \(\nabla^2 f\) cho hàm \(f(x)=\tfrac12 x^\top Q x + q^\top x\) với \(Q\) là ma trận đối xứng. Nếu bạn thực hiện thành thạo bước này, bạn đã sẵn sàng cho phần hàm lồi ở Chương 03.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01-04 Chuỗi Taylor</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_01_04_Taylor_Series/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_01_04_Taylor_Series</id>
   <content type="html">&lt;p&gt;Một hàm mục tiêu thực tế — như hàm mất mát cross-entropy hay hàm năng lượng vật lý — thường quá phức tạp để giải phương trình \(\nabla f(x) = 0\) bằng công thức đóng. Thế nhưng nếu phóng to đủ gần quanh điểm hiện tại \(x_0\), mọi hàm trơn đều trông giống một mặt phẳng (xấp xỉ bậc nhất) hoặc một chiếc bát parabol (xấp xỉ bậc hai). &lt;strong&gt;Chuỗi Taylor&lt;/strong&gt; chính là chiếc kính hiển vi toán học biến bài toán tối ưu phi tuyến khó nhằn thành một chuỗi bài toán tuyến tính hoặc bậc hai dễ giải.&lt;/p&gt;

&lt;p&gt;Gần như mọi thuật toán tối ưu trơn nổi tiếng — từ Gradient Descent, phương pháp Newton đến BFGS và Trust-Region — đều có thể đọc trực tiếp như một chiến lược cực tiểu hóa mô hình Taylor cục bộ.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-xấp-xỉ-cục-bộ-và-sai-số-phần-dư&quot;&gt;Kiến thức cần nhớ: Xấp xỉ cục bộ và sai số phần dư&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình bậc nhất (Tiếp tuyến / Siêu phẳng tiếp xúc):&lt;/strong&gt; \(f(x_0 + d) \approx f(x_0) + \nabla f(x_0)^T d\). Nếu thêm phạt bình phương bước đi \(\frac{1}{2\eta}\|d\|_2^2\) rồi cực tiểu hóa theo \(d\), ta thu được đúng công thức Gradient Descent \(d = -\eta \nabla f(x_0)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình bậc hai (Paraboloid cục bộ):&lt;/strong&gt; \(f(x_0 + d) \approx f(x_0) + \nabla f(x_0)^T d + \frac{1}{2} d^T \nabla^2 f(x_0) d\). Khi \(\nabla^2 f(x_0) \succ 0\), cực tiểu hóa mô hình này cho ra ngay &lt;strong&gt;bước Newton&lt;/strong&gt; \(d = -[\nabla^2 f(x_0)]^{-1} \nabla f(x_0)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần dư Taylor và bất đẳng thức \(L\)-smooth:&lt;/strong&gt; Phần dư bậc hai \(\frac{1}{2} d^T \nabla^2 f(\xi) d\) khi bị chặn bởi \(\frac{L}{2}\|d\|_2^2\) tạo ra “bát parabol bao trên” (&lt;em&gt;quadratic upper bound&lt;/em&gt;), là công cụ chứng minh hội tụ quan trọng nhất của tối ưu hóa lồi trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hệ điều kiện cực trị:&lt;/strong&gt; Tại điểm dừng \(\nabla f(x^*) = 0\), số hạng bậc nhất biến mất; hành vi lân cận hoàn toàn do số hạng bậc hai \(\frac{1}{2} d^T \nabla^2 f(x^*) d\) quyết định.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-từ-khai-triển-taylor-bậc-hai-đến-bước-newton-trên-fx--ex---2x&quot;&gt;Giải thích: Từ khai triển Taylor bậc hai đến bước Newton trên \(f(x) = e^x - 2x\)&lt;/h3&gt;

&lt;p&gt;Xét bài toán tìm cực tiểu của hàm lồi \(f(x) = e^x - 2x\) (nghiệm đúng là \(x^* = \ln 2 \approx 0.6931\) với \(f(x^*) = 2 - 2\ln 2 \approx 0.6137\)). Xuất phát từ \(x_0 = 0\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giá trị và đạo hàm tại \(x_0 = 0\):&lt;/strong&gt;
\(f(0) = e^0 - 0 = 1, \qquad f&apos;(x) = e^x - 2 \Rightarrow f&apos;(0) = -1, \qquad f&apos;&apos;(x) = e^x \Rightarrow f&apos;&apos;(0) = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xây dựng mô hình Taylor bậc hai quanh \(x_0 = 0\):&lt;/strong&gt;
\(q_0(x) = f(0) + f&apos;(0)x + \frac{1}{2}f&apos;&apos;(0)x^2 = 1 - x + \frac{1}{2}x^2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa mô hình xấp xỉ \(q_0(x)\):&lt;/strong&gt;
\(q_0&apos;(x) = -1 + x = 0 \implies x_1 = 1.\)
Đây chính là một bước Newton từ \(x_0 = 0\)! Giá trị hàm giảm từ \(f(0) = 1\) xuống \(f(1) = e - 2 \approx 0.7183\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lặp thêm 1 bước tại \(x_1 = 1\):&lt;/strong&gt;
\(f&apos;(1) = e - 2 \approx 0.7183, \qquad f&apos;&apos;(1) = e \approx 2.7183 \implies x_2 = 1 - \frac{e - 2}{e} = \frac{2}{e} \approx 0.7358,\)
với \(f(x_2) \approx 0.6155\) — chỉ sau 2 bước xấp xỉ Taylor bậc hai, sai số hàm mục tiêu đã nhỏ hơn \(0.002\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài học này trình bày khai triển chuỗi Taylor — công cụ nền tảng để xấp xỉ hàm số và phân tích hành vi cục bộ của hàm mục tiêu trong các thuật toán tối ưu hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;định-nghĩa-chuỗi-taylor&quot;&gt;Định nghĩa chuỗi Taylor&lt;/h2&gt;

&lt;p&gt;Chuỗi Taylor biểu diễn một hàm số dưới dạng tổng vô hạn các số hạng được xác định từ giá trị các đạo hàm của hàm tại một điểm cho trước. Nhờ đó, ta có thể xấp xỉ các hàm phức tạp bằng đa thức.&lt;/p&gt;

&lt;h3 id=&quot;chuỗi-taylor-một-biến&quot;&gt;Chuỗi Taylor một biến&lt;/h3&gt;

&lt;p&gt;Chuỗi Taylor của hàm \(f(x)\) khai triển tại điểm \(a\) có dạng:&lt;/p&gt;

\[f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n\]

&lt;p&gt;Viết tường minh theo từng số hạng:&lt;/p&gt;

\[f(x) = f(a) + \frac{f&apos;(a)}{1!}(x-a) + \frac{f&apos;&apos;(a)}{2!}(x-a)^2 + \frac{f&apos;&apos;&apos;(a)}{3!}(x-a)^3 + \dots\]

&lt;h3 id=&quot;chuỗi-maclaurin&quot;&gt;Chuỗi Maclaurin&lt;/h3&gt;

&lt;p&gt;Trường hợp riêng khi khai triển tại \(a = 0\) được gọi là &lt;strong&gt;chuỗi Maclaurin&lt;/strong&gt;:&lt;/p&gt;

\[f(x) = f(0) + f&apos;(0)x + \frac{f&apos;&apos;(0)}{2!}x^2 + \frac{f&apos;&apos;&apos;(0)}{3!}x^3 + \dots\]

&lt;h3 id=&quot;một-số-chuỗi-maclaurin-thông-dụng&quot;&gt;Một số chuỗi Maclaurin thông dụng&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hàm mũ:&lt;/strong&gt;
\(e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \dots = \sum_{n=0}^{\infty} \frac{x^n}{n!}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm sin:&lt;/strong&gt;
\(\sin x = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \dots = \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n+1}}{(2n+1)!}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm cosin:&lt;/strong&gt;
\(\cos x = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \frac{x^6}{6!} + \dots = \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n}}{(2n)!}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logarit tự nhiên (với \(|x| &amp;lt; 1\)):&lt;/strong&gt;
\(\ln(1 + x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + \dots = \sum_{n=1}^{\infty} \frac{(-1)^{n+1} x^n}{n}\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;chuỗi-taylor-đa-biến&quot;&gt;Chuỗi Taylor đa biến&lt;/h2&gt;

&lt;p&gt;Với hàm nhiều biến, khai triển Taylor phức tạp hơn nhưng vẫn dựa trên cùng nguyên lý: sử dụng các đạo hàm riêng tại điểm khai triển \(\mathbf{x}_0\).&lt;/p&gt;

&lt;h3 id=&quot;khai-triển-taylor-bậc-nhất&quot;&gt;Khai triển Taylor bậc nhất&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Xấp xỉ tuyến tính&lt;/strong&gt; của \(f(\mathbf{x})\) quanh \(\mathbf{x}_0\):&lt;/p&gt;

\[f(\mathbf{x}) \approx f(\mathbf{x}_0) + \nabla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0)\]

&lt;p&gt;Biểu thức này chính là phương trình siêu phẳng tiếp xúc với đồ thị của hàm số tại \(\mathbf{x}_0\).&lt;/p&gt;

&lt;h3 id=&quot;khai-triển-taylor-bậc-hai&quot;&gt;Khai triển Taylor bậc hai&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Xấp xỉ bậc hai&lt;/strong&gt; bổ sung thêm thông tin về độ cong của hàm số:&lt;/p&gt;

\[f(\mathbf{x}) \approx f(\mathbf{x}_0) + \nabla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0) + \frac{1}{2} (\mathbf{x} - \mathbf{x}_0)^T \nabla^2 f(\mathbf{x}_0) (\mathbf{x} - \mathbf{x}_0)\]

&lt;p&gt;trong đó \(\nabla^2 f(\mathbf{x}_0)\) là ma trận Hessian của \(f\) tại \(\mathbf{x}_0\).&lt;/p&gt;

&lt;h3 id=&quot;dạng-tổng-quát&quot;&gt;Dạng tổng quát&lt;/h3&gt;

&lt;p&gt;Chuỗi Taylor đa biến đầy đủ sử dụng ký hiệu đa chỉ số (và các đạo hàm bậc cao):&lt;/p&gt;

\[f(\mathbf{x}) = \sum_{|\alpha|=0}^{\infty} \frac{D^{\alpha} f(\mathbf{x}_0)}{\alpha!} (\mathbf{x} - \mathbf{x}_0)^{\alpha}\]

&lt;p&gt;trong đó \(\alpha = (\alpha_1, \alpha_2, \ldots, \alpha_n)\) là một đa chỉ số.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong tối ưu hóa&lt;/h2&gt;

&lt;p&gt;Chuỗi Taylor giữ vai trò nền tảng trong lý thuyết và thuật toán tối ưu hóa ở ba khía cạnh chính:&lt;/p&gt;

&lt;h3 id=&quot;1-xấp-xỉ-hàm-cục-bộ&quot;&gt;1. Xấp xỉ hàm cục bộ&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Xấp xỉ tuyến tính (phương pháp bậc nhất):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Được sử dụng trong các thuật toán gradient descent.&lt;/li&gt;
  &lt;li&gt;Xem hàm số xấp xỉ tuyến tính trong một lân cận đủ nhỏ.&lt;/li&gt;
  &lt;li&gt;Kích thước bước phải đủ nhỏ để xấp xỉ tuyến tính còn chính xác.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Xấp xỉ bậc hai (phương pháp bậc hai):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Được sử dụng trong phương pháp Newton và tựa Newton (quasi-Newton).&lt;/li&gt;
  &lt;li&gt;Khai thác thông tin độ cong thông qua ma trận Hessian.&lt;/li&gt;
  &lt;li&gt;Thường cho tốc độ hội tụ nhanh hơn so với phương pháp bậc nhất.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-điều-kiện-tối-ưu&quot;&gt;2. Điều kiện tối ưu&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện cần bậc nhất:&lt;/strong&gt;
Tại cực tiểu địa phương \(\mathbf{x}^*\) của hàm khả vi không ràng buộc, ta phải có \(\nabla f(\mathbf{x}^*) = \mathbf{0}\).&lt;/p&gt;

&lt;p&gt;Điều này suy trực tiếp từ khai triển Taylor bậc nhất: nếu \(\nabla f(\mathbf{x}^*) \neq \mathbf{0}\), ta luôn có thể dịch chuyển một bước nhỏ theo hướng \(-\nabla f(\mathbf{x}^*)\) để làm giảm giá trị hàm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện đủ bậc hai:&lt;/strong&gt;
Nếu \(\nabla f(\mathbf{x}^*) = \mathbf{0}\) và \(\nabla^2 f(\mathbf{x}^*)\) xác định dương, thì \(\mathbf{x}^*\) là một điểm cực tiểu địa phương chặt.&lt;/p&gt;

&lt;p&gt;Điều này xuất phát từ khai triển Taylor bậc hai: khi số hạng bậc nhất triệt tiêu, số hạng bậc hai quyết định dấu của hiệu \(f(\mathbf{x}) - f(\mathbf{x}^*)\) trong lân cận \(\mathbf{x}^*\).&lt;/p&gt;

&lt;h3 id=&quot;3-thiết-kế-thuật-toán&quot;&gt;3. Thiết kế thuật toán&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp Newton:&lt;/strong&gt;
Cực tiểu hóa trực tiếp mô hình Taylor bậc hai để cập nhật nghiệm:&lt;/p&gt;

\[\mathbf{x}_{k+1} = \mathbf{x}_k - [\nabla^2 f(\mathbf{x}_k)]^{-1} \nabla f(\mathbf{x}_k)\]

&lt;p&gt;&lt;strong&gt;Phương pháp vùng tin cậy (Trust Region):&lt;/strong&gt;
Cực tiểu hóa mô hình xấp xỉ Taylor trong một vùng tin cậy mà tại đó mô hình được xem là đủ chính xác.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp tìm kiếm theo đường thẳng (Line Search):&lt;/strong&gt;
Dựa vào khai triển Taylor để lựa chọn kích thước bước phù hợp dọc theo hướng tìm kiếm.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ví-dụ-phân-tích-hàm-bậc-hai&quot;&gt;Ví dụ: Phân tích hàm bậc hai&lt;/h2&gt;

&lt;p&gt;Xét hàm \(f(x, y) = x^2 + 2xy + 3y^2\) tại điểm \((0, 0)\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gradient:&lt;/strong&gt;
\(\nabla f = \begin{pmatrix} 2x + 2y \\ 2x + 6y \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;Tại \((0, 0)\): \(\nabla f(0, 0) = \begin{pmatrix} 0 \\ 0 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hessian:&lt;/strong&gt;
\(\nabla^2 f = \begin{pmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Khai triển Taylor bậc hai tại \((0, 0)\):&lt;/strong&gt;
\(f(x, y) = f(0, 0) + 0 + \frac{1}{2} \begin{pmatrix} x &amp;amp; y \end{pmatrix} \begin{pmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix}\)&lt;/p&gt;

\[= 0 + \frac{1}{2}(2x^2 + 4xy + 6y^2) = x^2 + 2xy + 3y^2\]

&lt;p&gt;Do \(f\) vốn là hàm bậc hai, khai triển Taylor bậc hai cho kết quả hoàn toàn chính xác.&lt;/p&gt;

&lt;p&gt;Phương trình đặc trưng của ma trận Hessian là \(\lambda^2 - 8\lambda + 8 = 0\), cho hai giá trị riêng \(\lambda_1 = 4 + 2\sqrt{2} &amp;gt; 0\) và \(\lambda_2 = 4 - 2\sqrt{2} &amp;gt; 0\). Vì cả hai giá trị riêng đều dương nên ma trận Hessian xác định dương, do đó điểm \((0, 0)\) là điểm cực tiểu (vừa là cực tiểu địa phương, vừa là cực tiểu toàn cục).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;các-lưu-ý-thực-tế&quot;&gt;Các lưu ý thực tế&lt;/h2&gt;

&lt;h3 id=&quot;hội-tụ-và-độ-chính-xác&quot;&gt;Hội tụ và độ chính xác&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bán kính hội tụ&lt;/strong&gt;: chuỗi Taylor chỉ hội tụ trong một bán kính nhất định quanh điểm khai triển.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sai số cắt cụt&lt;/strong&gt;: việc giữ lại hữu hạn số hạng luôn kèm theo sai số xấp xỉ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí tính toán&lt;/strong&gt;: các số hạng bậc càng cao đòi hỏi tính toán càng nhiều đạo hàm.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;lựa-chọn-thuật-toán-tối-ưu-hóa&quot;&gt;Lựa chọn thuật toán tối ưu hóa&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp bậc nhất&lt;/strong&gt; (gradient descent): chỉ cần thông tin gradient; hội tụ chậm hơn nhưng chi phí tính toán thấp hơn ở mỗi bước lặp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp bậc hai&lt;/strong&gt; (Newton): sử dụng thêm ma trận Hessian; hội tụ nhanh hơn nhưng chi phí tính toán lớn hơn ở mỗi bước lặp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp tựa Newton (quasi-Newton)&lt;/strong&gt;: xấp xỉ ma trận Hessian, cân bằng giữa tốc độ hội tụ và chi phí tính toán.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tóm lại, khai triển chuỗi Taylor cho phép xấp xỉ các hàm phức tạp bằng đa thức đơn giản quanh một điểm, tạo cơ sở để phân tích hành vi cục bộ của hàm số và thiết kế các thuật toán tối ưu hóa.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01-03 Gradient và Đạo Hàm Theo Hướng</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_01_03_Gradient_and_Directional_Derivatives/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_01_03_Gradient_and_Directional_Derivatives</id>
   <content type="html">&lt;p&gt;Đứng giữa sườn đồi, bạn có vô số hướng để bước đi: hướng nào giúp hạ độ cao nhanh nhất, hướng nào giữ nguyên độ cao, và nếu bị một hàng rào ràng buộc chặn hướng dốc nhất thì ta vẫn có thể đi xuống theo một hướng xiên khác không? Câu trả lời trọn vẹn nằm ở mối quan hệ cực kỳ thanh lịch giữa &lt;strong&gt;vector gradient&lt;/strong&gt; và &lt;strong&gt;đạo hàm theo hướng&lt;/strong&gt;: một phép tích vô hướng duy nhất \(D_u f(x) = \nabla f(x)^T u\).&lt;/p&gt;

&lt;p&gt;Đây là công thức nền tảng đứng sau mọi phương pháp hạ bậc nhất (first-order methods), từ Gradient Descent cổ điển cho đến Conditional Gradient (Frank–Wolfe).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-của-hướng-đi-và-độ-dốc&quot;&gt;Kiến thức cần nhớ: Hình học của hướng đi và độ dốc&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đạo hàm theo hướng (\(D_u f(x)\)):&lt;/strong&gt; Đo tốc độ thay đổi tức thời của \(f\) khi ta di chuyển từ \(x\) dọc theo vector đơn vị \(u\) (\(\|u\|_2 = 1\)). Với hàm khả vi, \(D_u f(x) = \nabla f(x)^T u = \|\nabla f(x)\|_2 \cos\theta\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức Cauchy–Schwarz và hướng dốc nhất:&lt;/strong&gt; Vì \(-1 \le \cos\theta \le 1\), giá trị lớn nhất của \(D_u f(x)\) là \(+\|\nabla f(x)\|_2\) khi \(u\) cùng hướng \(\nabla f(x)\), và giá trị nhỏ nhất là \(-\|\nabla f(x)\|_2\) khi \(u\) ngược hướng \(\nabla f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hướng giảm (Descent Direction):&lt;/strong&gt; Bất kỳ vector \(d\) nào thỏa mãn \(\nabla f(x)^T d &amp;lt; 0\) (tạo góc tù với gradient) đều bảo đảm \(f(x + \alpha d) &amp;lt; f(x)\) với bước \(\alpha &amp;gt; 0\) đủ nhỏ — nền tảng của mọi thuật toán tìm kiếm đường thẳng (line search).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính trực giao với đường mức:&lt;/strong&gt; Khi \(u\) tiếp tuyến với đường mức \(f(x) = c\), hàm không đổi dọc theo \(u\) nên \(\nabla f(x)^T u = 0\), tức gradient luôn vuông góc với đường mức.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-tốc-độ-giảm-dọc-theo-hai-hướng-khác-nhau&quot;&gt;Giải thích: So sánh tốc độ giảm dọc theo hai hướng khác nhau&lt;/h3&gt;

&lt;p&gt;Xét hàm \(f(x, y) = x^2 + 2y^2\) tại điểm \(p = (1, 1)^T\) (giá trị \(f(1, 1) = 3\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính gradient tại \(p\):&lt;/strong&gt;
\(\nabla f(x, y) = \begin{pmatrix}2x \\ 4y\end{pmatrix} \implies \nabla f(1, 1) = \begin{pmatrix}2 \\ 4\end{pmatrix}, \qquad \|\nabla f(1, 1)\|_2 = \sqrt{2^2 + 4^2} = \sqrt{20} = 2\sqrt{5} \approx 4.472.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử đi theo hướng đơn vị \(u = (3/5, 4/5)^T\):&lt;/strong&gt;
\(D_u f(1, 1) = \nabla f(1, 1)^T u = 2\left(\frac{3}{5}\right) + 4\left(\frac{4}{5}\right) = \frac{6 + 16}{5} = \frac{22}{5} = 4.4 &amp;gt; 0.\)
Hàm tăng rất nhanh gần sát mức tối đa \(4.472\) vì \(u\) gần trùng hướng gradient.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử hướng giảm nhanh nhất \(u^* = -\frac{\nabla f(1,1)}{\|\nabla f(1,1)\|_2} = \left(-\frac{1}{\sqrt{5}}, -\frac{2}{\sqrt{5}}\right)^T\):&lt;/strong&gt;
\(D_{u^*} f(1, 1) = 2\left(-\frac{1}{\sqrt{5}}\right) + 4\left(-\frac{2}{\sqrt{5}}\right) = -\frac{10}{\sqrt{5}} = -2\sqrt{5} \approx -4.472.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử hướng tiếp tuyến đường mức \(v = (-2/\sqrt{5}, 1/\sqrt{5})^T\):&lt;/strong&gt;
\(D_v f(1, 1) = 2\left(-\frac{2}{\sqrt{5}}\right) + 4\left(\frac{1}{\sqrt{5}}\right) = 0.\)
Đi dọc theo \(v\) giữ nguyên độ cao tức thời (tiếp tuyến với elip \(x^2 + 2y^2 = 3\) tại \((1,1)\)).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài học này trình bày vector gradient và đạo hàm theo hướng — hai khái niệm trung tâm trong tối ưu hóa giúp phân tích cách hàm số biến thiên theo từng hướng di chuyển.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;vector-gradient&quot;&gt;Vector gradient&lt;/h2&gt;

&lt;p&gt;Gradient \(\nabla f\) là vector gồm tất cả các đạo hàm riêng bậc nhất của hàm \(f\) theo từng biến. Tại một điểm cho trước, gradient chỉ theo hướng hàm số tăng nhanh nhất.&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa-và-cách-tính&quot;&gt;Định nghĩa và cách tính&lt;/h3&gt;

&lt;p&gt;Với hàm hai biến \(f(x, y)\), gradient của hàm là:&lt;/p&gt;

\[\nabla f = \begin{pmatrix} \frac{\partial f}{\partial x} \\ \frac{\partial f}{\partial y} \end{pmatrix}\]

&lt;p&gt;Với hàm \(n\) biến \(f(x_1, x_2, \ldots, x_n)\):&lt;/p&gt;

\[\nabla f = \begin{pmatrix} \frac{\partial f}{\partial x_1} \\ \frac{\partial f}{\partial x_2} \\ \vdots \\ \frac{\partial f}{\partial x_n} \end{pmatrix}\]

&lt;h3 id=&quot;ví-dụ-tính-gradient&quot;&gt;Ví dụ: Tính gradient&lt;/h3&gt;

&lt;p&gt;Xét hàm \(f(x, y) = x^2 + 3xy + y^2\):&lt;/p&gt;

&lt;p&gt;\(\frac{\partial f}{\partial x} = 2x + 3y\)
\(\frac{\partial f}{\partial y} = 3x + 2y\)&lt;/p&gt;

&lt;p&gt;Do đó: \(\nabla f = \begin{pmatrix} 2x + 3y \\ 3x + 2y \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;Tại điểm \((1, 2)\): \(\nabla f(1, 2) = \begin{pmatrix} 2(1) + 3(2) \\ 3(1) + 2(2) \end{pmatrix} = \begin{pmatrix} 8 \\ 7 \end{pmatrix}\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;đạo-hàm-theo-hướng&quot;&gt;Đạo hàm theo hướng&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đạo hàm theo hướng&lt;/strong&gt; đo tốc độ thay đổi của hàm \(f\) khi di chuyển theo một hướng \(\mathbf{u}\) bất kỳ, trong đó \(\mathbf{u}\) là vector đơn vị (có độ dài bằng 1).&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h3&gt;

&lt;p&gt;Với hàm \(f(\mathbf{x})\) và vector đơn vị \(\mathbf{u} = \langle u_1, u_2, \ldots, u_n \rangle\):&lt;/p&gt;

\[D_{\mathbf{u}}f(\mathbf{x}) = \nabla f(\mathbf{x}) \cdot \mathbf{u} = \sum_{i=1}^{n} \frac{\partial f}{\partial x_i} u_i\]

&lt;h3 id=&quot;diễn-giải-hình-học&quot;&gt;Diễn giải hình học&lt;/h3&gt;

&lt;p&gt;Đạo hàm theo hướng có thể biểu diễn dưới dạng:&lt;/p&gt;

\[D_{\mathbf{u}}f = \lvert \nabla f \rvert \cos \theta\]

&lt;p&gt;trong đó \(\theta\) là góc giữa \(\nabla f\) và \(\mathbf{u}\), còn \(\lvert \nabla f \rvert\) là độ lớn (chuẩn Euclid) của gradient.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-tính-đạo-hàm-theo-hướng&quot;&gt;Ví dụ: Tính đạo hàm theo hướng&lt;/h3&gt;

&lt;p&gt;Xét lại hàm \(f(x, y) = x^2 + 3xy + y^2\) tại điểm \((1, 2)\) với \(\nabla f(1, 2) = \begin{pmatrix} 8 \\ 7 \end{pmatrix}\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hướng 1:&lt;/strong&gt; \(\mathbf{u}_1 = \begin{pmatrix} 1 \\ 0 \end{pmatrix}\) (hướng dương của trục \(x\))
\(D_{\mathbf{u}_1}f(1, 2) = 8 \cdot 1 + 7 \cdot 0 = 8\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hướng 2:&lt;/strong&gt; \(\mathbf{u}_2 = \begin{pmatrix} 0 \\ 1 \end{pmatrix}\) (hướng dương của trục \(y\))
\(D_{\mathbf{u}_2}f(1, 2) = 8 \cdot 0 + 7 \cdot 1 = 7\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hướng 3:&lt;/strong&gt; \(\mathbf{u}_3 = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 1 \end{pmatrix}\) (hướng đường chéo 45°)
\(D_{\mathbf{u}_3}f(1, 2) = 8 \cdot \frac{1}{\sqrt{2}} + 7 \cdot \frac{1}{\sqrt{2}} = \frac{15}{\sqrt{2}} \approx 10.61\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tốc-độ-thay-đổi-lớn-nhất-và-nhỏ-nhất&quot;&gt;Tốc độ thay đổi lớn nhất và nhỏ nhất&lt;/h2&gt;

&lt;h3 id=&quot;các-tính-chất-chính&quot;&gt;Các tính chất chính&lt;/h3&gt;

&lt;p&gt;Từ công thức \(D_{\mathbf{u}}f = \lvert \nabla f \rvert \cos \theta\), ta suy ra:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ thay đổi lớn nhất&lt;/strong&gt;: đạt được khi \(\cos \theta = 1\) (tức \(\theta = 0°\))
    &lt;ul&gt;
      &lt;li&gt;Hướng: \(\mathbf{u} = \frac{\nabla f}{\lvert \nabla f \rvert}\) (cùng hướng với gradient)&lt;/li&gt;
      &lt;li&gt;Giá trị lớn nhất: \(D_{\max}f = \lvert \nabla f \rvert\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ thay đổi nhỏ nhất&lt;/strong&gt;: đạt được khi \(\cos \theta = -1\) (tức \(\theta = 180°\))
    &lt;ul&gt;
      &lt;li&gt;Hướng: \(\mathbf{u} = -\frac{\nabla f}{\lvert \nabla f \rvert}\) (ngược hướng với gradient)&lt;/li&gt;
      &lt;li&gt;Giá trị nhỏ nhất: \(D_{\min}f = -\lvert \nabla f \rvert\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ thay đổi bằng không&lt;/strong&gt;: xảy ra khi \(\cos \theta = 0\) (tức \(\theta = 90°\))
    &lt;ul&gt;
      &lt;li&gt;Hướng: mọi vector đơn vị vuông góc với \(\nabla f\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;tóm-tắt-các-tính-chất-của-gradient&quot;&gt;Tóm tắt các tính chất của gradient&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Gradient \(\nabla f\) chỉ theo hướng &lt;strong&gt;tăng nhanh nhất&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Vector \(-\nabla f\) chỉ theo hướng &lt;strong&gt;giảm nhanh nhất&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Độ lớn \(\lvert \nabla f \rvert\) bằng &lt;strong&gt;tốc độ thay đổi lớn nhất&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Tại điểm thỏa mãn \(\nabla f = \mathbf{0}\), ta có &lt;strong&gt;điểm tới hạn&lt;/strong&gt; (critical point) — ứng viên cho cực trị của hàm số.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;quan-hệ-với-đường-mức&quot;&gt;Quan hệ với đường mức&lt;/h2&gt;

&lt;p&gt;Tại mọi điểm trên một đường mức \(f(x, y) = c\), vector gradient \(\nabla f\) luôn &lt;strong&gt;trực giao (vuông góc)&lt;/strong&gt; với tiếp tuyến của đường mức tại điểm đó.&lt;/p&gt;

&lt;h3 id=&quot;ý-nghĩa-của-tính-trực-giao&quot;&gt;Ý nghĩa của tính trực giao&lt;/h3&gt;

&lt;p&gt;Tính trực giao giữa gradient và đường mức có ý nghĩa quan trọng vì:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Đường mức ứng với giá trị hàm không đổi&lt;/strong&gt;: di chuyển dọc theo tiếp tuyến của đường mức không làm thay đổi giá trị hàm ở bậc nhất, nên đạo hàm theo hướng đó bằng không.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient chỉ theo hướng tăng nhanh nhất&lt;/strong&gt;: hướng làm hàm số tăng nhanh nhất phải vuông góc với hướng không làm thay đổi giá trị hàm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng trong tối ưu hóa&lt;/strong&gt;: để tìm cực trị, ta tìm các điểm mà gradient bằng không (điểm tới hạn) hoặc — trong bài toán có ràng buộc — điểm mà gradient vuông góc với biên của tập ràng buộc.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong tối ưu hóa&lt;/h3&gt;

&lt;p&gt;Hiểu rõ về gradient và đạo hàm theo hướng là cơ sở cho nhiều nội dung trong tối ưu hóa:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent&lt;/strong&gt;: di chuyển theo hướng \(-\nabla f\) để cực tiểu hóa \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Ascent&lt;/strong&gt;: di chuyển theo hướng \(+\nabla f\) để cực đại hóa \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa có ràng buộc&lt;/strong&gt;: khai thác mối quan hệ hình học giữa gradient và đường mức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích hội tụ&lt;/strong&gt;: đánh giá điều kiện để thuật toán hội tụ về nghiệm tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn kích thước bước&lt;/strong&gt;: xác định độ dài bước đi hợp lý dọc theo hướng tìm kiếm.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nhờ cung cấp đồng thời hướng di chuyển và tốc độ thay đổi cục bộ của hàm số, gradient đóng vai trò nền tảng trong phần lớn các thuật toán tối ưu hóa.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01-02 Đạo hàm và Giải tích đa biến</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_01_02_Derivatives_and_Multivariable_Calculus/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_01_02_Derivatives_and_Multivariable_Calculus</id>
   <content type="html">&lt;p&gt;Khi tối ưu hóa một biến số duy nhất, ta chỉ cần quan tâm đường cong đang đi lên hay đi xuống. Nhưng một mô hình hồi quy hay mạng nơ-ron không sống trên đường thẳng — nó sống trong không gian hàng nghìn đến hàng tỷ chiều, nơi mỗi tọa độ là một “núm vặn” có thể xoay đồng thời. Giải tích đa biến mở ra cách quan sát toàn bộ bề mặt nhiều chiều đó chỉ qua hai đối tượng: &lt;strong&gt;vector gradient&lt;/strong&gt; (bậc nhất) và &lt;strong&gt;ma trận Hessian&lt;/strong&gt; (bậc hai).&lt;/p&gt;

&lt;p&gt;Nắm vững cách đọc đạo hàm riêng, đường mức và độ cong đa biến sẽ giúp bạn hình dung ngay bề mặt hàm mất mát ngay cả khi không thể vẽ nó trong không gian 3D.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cấu-trúc-vi-phân-của-hàm-nhiều-biến&quot;&gt;Kiến thức cần nhớ: Cấu trúc vi phân của hàm nhiều biến&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Đạo hàm riêng và Gradient (\(\nabla f\)):&lt;/strong&gt; Giữ cố định các biến khác và khảo sát tốc độ thay đổi dọc theo từng trục tọa độ \(x_i\). Ghép tất cả đạo hàm riêng thành một vector, ta thu được \(\nabla f(x) \in \mathbb{R}^n\) — tổng hợp đầy đủ độ dốc bậc nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đường mức và siêu mặt mức (Level Sets):&lt;/strong&gt; Tập \(\{x : f(x) = c\}\) giúp “cắt lát” địa hình nhiều chiều giống như bản đồ địa hình. Gradient tại mỗi điểm luôn vuông góc với đường mức đi qua điểm đó.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ma trận Jacobian (\(J_f\)):&lt;/strong&gt; Tổng quát hóa đạo hàm cho ánh xạ vector \(f: \mathbb{R}^n \to \mathbb{R}^m\), đặc biệt quan trọng khi viết quy tắc dây chuyền (chain rule) trong lan truyền ngược (backpropagation) và hệ ràng buộc đa biến.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ma trận Hessian (\(\nabla^2 f\)):&lt;/strong&gt; Chứa mọi đạo hàm riêng cấp hai \(\frac{\partial^2 f}{\partial x_i \partial x_j}\). Tính xác định dương hay bán xác định dương của Hessian chính là tiêu chuẩn kiểm tra tính lồi và phân biệt cực tiểu, cực đại hay điểm yên ngựa.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-gradient-và-hessian-của-fx_1-x_2--x_12--3x_1-x_2--4x_22&quot;&gt;Giải thích: Tính tay Gradient và Hessian của \(f(x_1, x_2) = x_1^2 + 3x_1 x_2 + 4x_2^2\)&lt;/h3&gt;

&lt;p&gt;Xét hàm hai biến \(f(x_1, x_2) = x_1^2 + 3x_1 x_2 + 4x_2^2\) tại điểm \(x = (1, -1)^T\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính đạo hàm riêng cấp một (Gradient):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\frac{\partial f}{\partial x_1} = 2x_1 + 3x_2\). Tại \((1, -1)\): \(2(1) + 3(-1) = -1\).&lt;/li&gt;
      &lt;li&gt;\(\frac{\partial f}{\partial x_2} = 3x_1 + 8x_2\). Tại \((1, -1)\): \(3(1) + 8(-1) = -5\).
Vậy \(\nabla f(1, -1) = \begin{pmatrix}-1 \\ -5\end{pmatrix}\). Hướng giảm nhanh nhất tại đây là \(-\nabla f(1, -1) = \begin{pmatrix}1 \\ 5\end{pmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính ma trận Hessian cấp hai:&lt;/strong&gt;
\(\nabla^2 f(x) = \begin{pmatrix} \frac{\partial^2 f}{\partial x_1^2} &amp;amp; \frac{\partial^2 f}{\partial x_1 \partial x_2} \\ \frac{\partial^2 f}{\partial x_2 \partial x_1} &amp;amp; \frac{\partial^2 f}{\partial x_2^2} \end{pmatrix} = \begin{pmatrix} 2 &amp;amp; 3 \\ 3 &amp;amp; 8 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra độ cong (tiêu chuẩn Sylvester):&lt;/strong&gt; Định thức con chính thứ nhất là \(H_{11} = 2 &amp;gt; 0\); định thức toàn phần là \(\det(H) = 2 \cdot 8 - 3 \cdot 3 = 16 - 9 = 7 &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận cho tối ưu hóa:&lt;/strong&gt; Vì \(H\) đối xứng xác định dương (\(H \succ 0\)) tại mọi điểm, \(f\) là hàm lồi mạnh toàn cục; điểm dừng duy nhất giải \(\nabla f(x) = 0\) là \(x^* = (0, 0)^T\) chắc chắn là cực tiểu toàn cục duy nhất.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài học này trình bày đạo hàm và các khái niệm cốt lõi của giải tích đa biến — nền tảng của lý thuyết và thuật toán tối ưu hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;đạo-hàm-và-tốc-độ-thay-đổi&quot;&gt;Đạo hàm và tốc độ thay đổi&lt;/h2&gt;

&lt;p&gt;Đạo hàm của một hàm một biến biểu thị tốc độ thay đổi tức thời của hàm đó, giúp ta nắm bắt hành vi cục bộ của hàm số.&lt;/p&gt;

&lt;h3 id=&quot;các-khái-niệm-đạo-hàm-cơ-bản&quot;&gt;Các khái niệm đạo hàm cơ bản&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Độ dốc giữa hai điểm:&lt;/strong&gt;&lt;/p&gt;

\[\text{Độ dốc} = \frac{y_2 - y_1}{x_2 - x_1}\]

&lt;p&gt;&lt;strong&gt;Đạo hàm (tốc độ thay đổi tức thời):&lt;/strong&gt;&lt;/p&gt;

\[f&apos;(x_0) = \lim_{x_1 \to x_0} \frac{f(x_1) - f(x_0)}{x_1 - x_0} = \lim_{\Delta x \to 0} \frac{f(x_0 + \Delta x) - f(x_0)}{\Delta x}\]

&lt;p&gt;Đạo hàm cho biết hàm số thay đổi nhanh đến mức nào tại một điểm cho trước. Trong tối ưu hóa, khái niệm này đặc biệt quan trọng để xác định các điểm dừng — nơi tốc độ thay đổi bằng không.&lt;/p&gt;

&lt;h3 id=&quot;đường-mức-của-hàm-số&quot;&gt;Đường mức của hàm số&lt;/h3&gt;

&lt;p&gt;Đường mức là công cụ cơ bản trong giải tích đa biến để trực quan hóa các hàm hai biến \(f(x, y)\), cho phép biểu diễn một mặt cong trong không gian 3 chiều trên mặt phẳng 2 chiều.&lt;/p&gt;

&lt;p&gt;Một &lt;strong&gt;đường mức&lt;/strong&gt; của hàm số \(f(x, y)\) là tập hợp tất cả các điểm \((x, y)\) thuộc miền xác định của \(f\) mà tại đó hàm số nhận cùng một giá trị hằng số:&lt;/p&gt;

\[f(x, y) = c\]

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Với \(f(x, y) = x^2 + y^2\), các đường mức là các đường tròn đồng tâm: \(x^2 + y^2 = c\) (với \(c &amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;Với \(f(x, y) = x + y\), các đường mức là các đường thẳng song song: \(x + y = c\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Đường mức giúp ta quan sát:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Hình dạng bề mặt (địa hình) của hàm số.&lt;/li&gt;
  &lt;li&gt;Hướng tăng nhanh nhất và hướng giảm nhanh nhất.&lt;/li&gt;
  &lt;li&gt;Vị trí của các điểm cực trị tiềm năng.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;các-khái-niệm-chính-của-giải-tích-đa-biến&quot;&gt;Các khái niệm chính của giải tích đa biến&lt;/h2&gt;

&lt;h3 id=&quot;đạo-hàm-riêng&quot;&gt;Đạo hàm riêng&lt;/h3&gt;

&lt;p&gt;Với hàm nhiều biến \(f(x_1, x_2, \ldots, x_n)\), &lt;strong&gt;đạo hàm riêng&lt;/strong&gt; theo biến \(x_i\) được định nghĩa là:&lt;/p&gt;

\[\frac{\partial f}{\partial x_i} = \lim_{h \to 0} \frac{f(x_1, \ldots, x_i + h, \ldots, x_n) - f(x_1, \ldots, x_i, \ldots, x_n)}{h}\]

&lt;p&gt;Đạo hàm riêng đo tốc độ thay đổi của \(f\) khi chỉ có \(x_i\) biến thiên trong khi tất cả các biến còn lại được giữ cố định.&lt;/p&gt;

&lt;h3 id=&quot;vector-gradient&quot;&gt;Vector gradient&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Gradient&lt;/strong&gt; là vector tập hợp toàn bộ các đạo hàm riêng bậc nhất của hàm số:&lt;/p&gt;

\[\nabla f(\mathbf{x}) = \begin{pmatrix} \frac{\partial f}{\partial x_1} \\ \frac{\partial f}{\partial x_2} \\ \vdots \\ \frac{\partial f}{\partial x_n} \end{pmatrix}\]

&lt;p&gt;Gradient chỉ theo hướng tăng nhanh nhất của hàm số và luôn vuông góc với các đường mức.&lt;/p&gt;

&lt;h3 id=&quot;ma-trận-hessian&quot;&gt;Ma trận Hessian&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ma trận Hessian&lt;/strong&gt; chứa toàn bộ các đạo hàm riêng bậc hai của hàm số:&lt;/p&gt;

\[\nabla^2 f(\mathbf{x}) = \mathbf{H} = \begin{pmatrix} 
\frac{\partial^2 f}{\partial x_1^2} &amp;amp; \frac{\partial^2 f}{\partial x_1 \partial x_2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_1 \partial x_n} \\
\frac{\partial^2 f}{\partial x_2 \partial x_1} &amp;amp; \frac{\partial^2 f}{\partial x_2^2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_2 \partial x_n} \\
\vdots &amp;amp; \vdots &amp;amp; \ddots &amp;amp; \vdots \\
\frac{\partial^2 f}{\partial x_n \partial x_1} &amp;amp; \frac{\partial^2 f}{\partial x_n \partial x_2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_n^2}
\end{pmatrix}\]

&lt;p&gt;Ma trận Hessian phản ánh độ cong của hàm số và được dùng để:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Phân loại các điểm tới hạn (cực tiểu, cực đại hoặc điểm yên ngựa).&lt;/li&gt;
  &lt;li&gt;Xây dựng các thuật toán tối ưu hóa bậc hai như phương pháp Newton.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;quy-tắc-dây-chuyền-cho-hàm-đa-biến&quot;&gt;Quy tắc dây chuyền cho hàm đa biến&lt;/h2&gt;

&lt;p&gt;Quy tắc dây chuyền là công cụ thiết yếu để tính đạo hàm của hàm hợp — dạng hàm xuất hiện rất phổ biến trong các bài toán tối ưu hóa.&lt;/p&gt;

&lt;h3 id=&quot;quy-tắc-dây-chuyền-cơ-bản&quot;&gt;Quy tắc dây chuyền cơ bản&lt;/h3&gt;

&lt;p&gt;Với hàm \(z = f(x, y)\), trong đó \(x = g(t)\) và \(y = h(t)\):&lt;/p&gt;

\[\frac{dz}{dt} = \frac{\partial f}{\partial x} \frac{dx}{dt} + \frac{\partial f}{\partial y} \frac{dy}{dt}\]

&lt;h3 id=&quot;quy-tắc-dây-chuyền-tổng-quát&quot;&gt;Quy tắc dây chuyền tổng quát&lt;/h3&gt;

&lt;p&gt;Với hàm \(z = f(x_1, x_2, \ldots, x_n)\), trong đó mỗi \(x_i = x_i(t_1, t_2, \ldots, t_m)\):&lt;/p&gt;

\[\frac{\partial z}{\partial t_j} = \sum_{i=1}^{n} \frac{\partial f}{\partial x_i} \frac{\partial x_i}{\partial t_j}\]

&lt;h3 id=&quot;ứng-dụng-trong-tối-ưu-hóa&quot;&gt;Ứng dụng trong tối ưu hóa&lt;/h3&gt;

&lt;p&gt;Quy tắc dây chuyền giữ vai trò nền tảng trong:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính gradient&lt;/strong&gt;: tính đạo hàm của các hàm mục tiêu có cấu trúc hàm hợp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xử lý ràng buộc&lt;/strong&gt;: xử lý các ràng buộc phụ thuộc vào các biến trung gian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cài đặt thuật toán&lt;/strong&gt;: thuật toán lan truyền ngược (backpropagation) trong mạng nơ-ron và vi phân tự động.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích độ nhạy&lt;/strong&gt;: đánh giá mức độ ảnh hưởng của sự thay đổi tham số tới nghiệm tối ưu.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;ví-dụ-tối-ưu-hóa-có-ràng-buộc&quot;&gt;Ví dụ: Tối ưu hóa có ràng buộc&lt;/h3&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa \(f(x, y) = x^2 + y^2\) với ràng buộc \(g(x, y) = x + y - 1 = 0\).&lt;/p&gt;

&lt;p&gt;Từ ràng buộc, ta rút \(y = 1 - x\) để đưa về bài toán một biến:&lt;/p&gt;

\[h(x) = f(x, 1-x) = x^2 + (1-x)^2\]

&lt;p&gt;Áp dụng quy tắc dây chuyền:&lt;/p&gt;

\[h&apos;(x) = \frac{\partial f}{\partial x} \cdot 1 + \frac{\partial f}{\partial y} \cdot \frac{d(1-x)}{dx} = 2x + 2(1-x)(-1) = 4x - 2\]

&lt;p&gt;Giải phương trình \(h&apos;(x) = 0\) ta được \(x = 1/2\), suy ra điểm tối ưu là \((1/2, 1/2)\).&lt;/p&gt;

&lt;p&gt;Ví dụ này minh họa cách các công cụ giải tích đa biến phối hợp với nhau để giải bài toán tối ưu hóa một cách có hệ thống.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01-01 Tính liên tục và Tính liên tục đều</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_01_01_Continuity_and_Uniform_Continuity/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter00/00_01_01_Continuity_and_Uniform_Continuity</id>
   <content type="html">&lt;p&gt;Thoạt nghe, phân biệt giữa &lt;em&gt;liên tục&lt;/em&gt;, &lt;em&gt;liên tục đều&lt;/em&gt; và &lt;em&gt;liên tục Lipschitz&lt;/em&gt; có vẻ là trò chơi tỉ mỉ của giới giải tích thuần túy với các ký hiệu \(\epsilon\)–\(\delta\). Thế nhưng trong tối ưu hóa, sự khác biệt đó lại quyết định trực tiếp việc một thuật toán có hội tụ ổn định hay bị “nổ” giá trị khi bước nhảy không phù hợp: một hàm chỉ liên tục thôi vẫn có thể có độ dốc dựng đứng vô hạn ở đâu đó, khiến bước nhảy cố định làm thuật toán văng khỏi quỹ đạo.&lt;/p&gt;

&lt;p&gt;Bài học này giúp bạn nhìn thấu bậc thang chặt chẽ dần từ liên tục điểm đến liên tục đều và liên tục Lipschitz — khái niệm xuất hiện trong hầu hết mọi định lý hội tụ của tối ưu hóa hiện đại.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-liên-tục-cục-bộ-đến-kiểm-soát-tốc-độ-biến-thiên-toàn-cục&quot;&gt;Kiến thức cần nhớ: Từ liên tục cục bộ đến kiểm soát tốc độ biến thiên toàn cục&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính liên tục tại điểm (Pointwise Continuity):&lt;/strong&gt; Đảm bảo không có bước nhảy đứt gãy tại \(x_0\); tuy nhiên bán kính an toàn \(\delta\) có thể phải thu nhỏ tùy ý khi \(x_0\) thay đổi vị trí.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính liên tục đều (Uniform Continuity):&lt;/strong&gt; Nâng chuẩn lên mức toàn cục: tồn tại &lt;strong&gt;một&lt;/strong&gt; \(\delta(\epsilon)\) duy nhất dùng chung cho mọi điểm trên miền xét. Trên tập compact (đóng và bị chặn), định lý Heine–Cantor bảo đảm mọi hàm liên tục tự động liên tục đều.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Tính liên tục Lipschitz (Lipschitz Continuity):&lt;/strong&gt; Đặt một “trần tốc độ” tuyến tính rõ ràng: $$&lt;/td&gt;
          &lt;td&gt;f(x) - f(y)&lt;/td&gt;
          &lt;td&gt;\le L|x - y|\(. Hằng số\)L\(chính là cận trên toàn cục của độ dốc, cho phép tính trước số vòng lặp cần thiết để đạt sai số\)\epsilon$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuỗi bao hàm trong tối ưu hóa:&lt;/strong&gt; \(\text{Lipschitz} \subset \text{Liên tục đều} \subset \text{Liên tục}\). Trong nhiều bài toán học máy, ta cần \(L\)-Lipschitz cho bản thân hàm \(f\) (với hàm không trơn như ReLU, Hinge loss) hoặc cho gradient \(\nabla f\) (gọi là tính trơn \(L\)-smooth).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-vì-sao-fx--x2-lipschitz-trên-0-3-nhưng-không-liên-tục-đều-trên-mathbbr&quot;&gt;Giải thích: Vì sao \(f(x) = x^2\) Lipschitz trên \([0, 3]\) nhưng không liên tục đều trên \(\mathbb{R}\)?&lt;/h3&gt;

&lt;p&gt;Hãy tự kiểm chứng bằng tay trên hàm quen thuộc \(f(x) = x^2\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trên đoạn đóng \([0, 3]\) (Lipschitz với \(L = 6\)):&lt;/strong&gt; Với mọi \(x, y \in [0, 3]\), ta phân tích:
\(|f(x) - f(y)| = |x^2 - y^2| = |x + y|\cdot |x - y| \le (3 + 3)|x - y| = 6|x - y|.\)
Vậy \(f\) liên tục Lipschitz với hằng số \(L = 6\), kéo theo liên tục đều trên \([0, 3]\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trên toàn trục thực \(\mathbb{R}\) (mất tính liên tục đều):&lt;/strong&gt; Chọn hai dãy điểm càng lúc càng sát nhau: \(x_n = n\) và \(y_n = n + \frac{1}{n}\).
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Khoảng cách đầu vào: $$&lt;/td&gt;
              &lt;td&gt;y_n - x_n&lt;/td&gt;
              &lt;td&gt;= \frac{1}{n} \to 0\(khi\)n \to \infty\((chẳng hạn tại\)n = 100\(, hai điểm chỉ cách nhau\)0.01$$).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Độ lệch đầu ra:
\(|f(y_n) - f(x_n)| = \left(n + \frac{1}{n}\right)^2 - n^2 = 2 + \frac{1}{n^2} &amp;gt; 2.\)
Dù \(x_n\) và \(y_n\) gần nhau tới mức nào, đầu ra vẫn cách nhau hơn \(2\) đơn vị! Không tồn tại một \(\delta\) chung cho \(\epsilon = 1\) trên toàn \(\mathbb{R}\), nên \(x^2\) &lt;strong&gt;không&lt;/strong&gt; liên tục đều trên \(\mathbb{R}\) — đó cũng là lý do các định lý hội tụ thường đòi hỏi chặn miền làm việc hoặc giả thiết gradient Lipschitz.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài học này giới thiệu các khái niệm cơ bản về tính liên tục, tính liên tục đều và tính liên tục Lipschitz — những công cụ nền tảng giúp phân tích hành vi của hàm số trong tối ưu hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tính-liên-tục-và-tính-liên-tục-đều&quot;&gt;Tính liên tục và tính liên tục đều&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tính liên tục&lt;/strong&gt; và &lt;strong&gt;tính liên tục đều&lt;/strong&gt; là các khái niệm cơ bản mô tả mức độ ổn định của hàm số khi biến đầu vào thay đổi nhỏ. Dù có liên hệ chặt chẽ, hai khái niệm này mang bản chất khác nhau, trong đó tính liên tục đều là điều kiện mạnh hơn so với tính liên tục thông thường.&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa-tính-liên-tục&quot;&gt;Định nghĩa tính liên tục&lt;/h3&gt;

&lt;p&gt;Một hàm số \(f: A \to \mathbb{R}\) được gọi là &lt;strong&gt;liên tục tại điểm&lt;/strong&gt; \(c \in A\) nếu với mọi số thực dương \(\varepsilon &amp;gt; 0\), tồn tại một số thực dương \(\delta &amp;gt; 0\) sao cho với mọi \(x \in A\), nếu&lt;/p&gt;

\[\lvert x - c \rvert &amp;lt; \delta\]

&lt;p&gt;thì&lt;/p&gt;

\[\lvert f(x) - f(c) \rvert &amp;lt; \varepsilon.\]

&lt;p&gt;Về mặt trực quan, với mọi ngưỡng sai số \(\varepsilon\) cho trước ở đầu ra \(f(x)\), ta luôn tìm được một lân cận đủ nhỏ quanh \(c\) (có độ rộng \(2\delta\)) sao cho mọi giá trị \(x\) trong lân cận đó đều có ảnh \(f(x)\) nằm trong khoảng \(\varepsilon\) quanh \(f(c)\). Điểm quan trọng cần lưu ý là giá trị \(\delta\) nói chung không chỉ phụ thuộc vào \(\varepsilon\) mà còn phụ thuộc vào vị trí của điểm \(c\).&lt;/p&gt;

&lt;p&gt;Một hàm số được gọi là &lt;strong&gt;liên tục trên tập hợp&lt;/strong&gt; \(A\) nếu nó liên tục tại mọi điểm \(c \in A\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ về các hàm liên tục&lt;/strong&gt; gồm mọi đa thức (chẳng hạn \(f(x) = x^2 + 3x - 1\)), các hàm lượng giác như \(\sin(x)\), \(\cos(x)\) và hàm mũ \(e^x\) trên miền xác định tương ứng của chúng.&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa-tính-liên-tục-đều&quot;&gt;Định nghĩa tính liên tục đều&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Tính liên tục đều&lt;/strong&gt; đặt ra một điều kiện chặt chẽ hơn. Một hàm số \(f: A \to \mathbb{R}\) được gọi là &lt;strong&gt;liên tục đều trên tập hợp&lt;/strong&gt; \(A\) nếu với mọi số thực dương \(\varepsilon &amp;gt; 0\), tồn tại một số thực dương \(\delta &amp;gt; 0\) sao cho với mọi \(x, y \in A\), nếu&lt;/p&gt;

\[\lvert x - y \rvert &amp;lt; \delta\]

&lt;p&gt;thì&lt;/p&gt;

\[\lvert f(x) - f(y) \rvert &amp;lt; \varepsilon.\]

&lt;p&gt;&lt;strong&gt;Điểm khác biệt cốt lõi&lt;/strong&gt; so với tính liên tục tại điểm nằm ở thứ tự của các lượng từ: đối với tính liên tục &lt;strong&gt;đều&lt;/strong&gt;, \(\delta\) chỉ phụ thuộc vào \(\varepsilon\) và dùng chung cho mọi cặp điểm \(x, y\) trên toàn miền xác định \(A\).&lt;/p&gt;

&lt;h3 id=&quot;định-nghĩa-tính-liên-tục-lipschitz&quot;&gt;Định nghĩa tính liên tục Lipschitz&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Tính liên tục Lipschitz&lt;/strong&gt; đưa ra một điều kiện định lượng cụ thể hơn cho tính liên tục. Một hàm số \(f: A \to \mathbb{R}\) được gọi là &lt;strong&gt;liên tục Lipschitz&lt;/strong&gt; (hoặc &lt;strong&gt;\(L\)-Lipschitz&lt;/strong&gt;) trên tập hợp \(A\) nếu tồn tại hằng số \(L \geq 0\) sao cho với mọi \(x, y \in A\):&lt;/p&gt;

\[\lvert f(x) - f(y) \rvert \leq L \lvert x - y \rvert.\]

&lt;p&gt;Hằng số \(L\) nhỏ nhất thỏa mãn bất đẳng thức trên được gọi là &lt;strong&gt;hằng số Lipschitz&lt;/strong&gt; của \(f\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Các tính chất chính của tính liên tục Lipschitz:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ thay đổi bị chặn&lt;/strong&gt;: điều kiện Lipschitz đảm bảo hàm số không thay đổi nhanh hơn tốc độ tuyến tính xác định bởi \(L\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suy ra tính liên tục đều&lt;/strong&gt;: mọi hàm liên tục Lipschitz đều liên tục đều (với \(L &amp;gt; 0\), chỉ cần chọn \(\delta = \varepsilon / L\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả vi hầu khắp nơi&lt;/strong&gt;: hàm liên tục Lipschitz khả vi hầu khắp nơi, và tại mọi điểm khả vi ta có \(\lvert f&apos;(x) \rvert \leq L\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(x) = \lvert x \rvert\) là \(1\)-Lipschitz trên \(\mathbb{R}\).&lt;/li&gt;
  &lt;li&gt;\(f(x) = \sin(x)\) là \(1\)-Lipschitz trên \(\mathbb{R}\) (vì \(\lvert \cos(x) \rvert \leq 1\)).&lt;/li&gt;
  &lt;li&gt;\(f(x) = x^2\) không liên tục Lipschitz trên \(\mathbb{R}\), nhưng liên tục Lipschitz trên mọi khoảng bị chặn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;sự-khác-biệt-chính-và-quan-hệ-bao-hàm&quot;&gt;Sự khác biệt chính và quan hệ bao hàm&lt;/h3&gt;

&lt;p&gt;Ba lớp hàm liên tục tạo thành một thứ bậc theo mức độ chặt chẽ của điều kiện:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liên tục Lipschitz ⊆ Liên tục đều ⊆ Liên tục&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính chất cục bộ và tính chất toàn cục&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Tính liên tục&lt;/strong&gt;: tính chất cục bộ (kiểm tra riêng tại từng điểm).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tính liên tục đều&lt;/strong&gt;: tính chất toàn cục trên cả miền xác định.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tính liên tục Lipschitz&lt;/strong&gt;: tính chất toàn cục kèm theo cận định lượng tường minh.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách chọn \(\delta\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Tính liên tục&lt;/strong&gt;: \(\delta\) có thể phụ thuộc vào cả \(\varepsilon\) lẫn điểm \(c\).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tính liên tục đều&lt;/strong&gt;: \(\delta\) chỉ phụ thuộc vào \(\varepsilon\), áp dụng đồng thời cho mọi điểm trên miền xác định.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tính liên tục Lipschitz&lt;/strong&gt;: \(\delta = \varepsilon / L\) cho công thức tường minh theo \(\varepsilon\) và \(L\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm soát tốc độ thay đổi&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Tính liên tục&lt;/strong&gt;: không kiểm soát tốc độ thay đổi.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tính liên tục đều&lt;/strong&gt;: đảm bảo độ biến thiên của hàm nhỏ trên các khoảng đủ nhỏ một cách đồng đều.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tính liên tục Lipschitz&lt;/strong&gt;: chặn tốc độ thay đổi bằng một cận tuyến tính cụ thể.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quan hệ kéo theo&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Mọi hàm liên tục Lipschitz đều liên tục đều.&lt;/li&gt;
      &lt;li&gt;Mọi hàm liên tục đều đều liên tục.&lt;/li&gt;
      &lt;li&gt;Các chiều ngược lại nhìn chung không đúng.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;ví-dụ-chi-tiết-và-so-sánh&quot;&gt;Ví dụ chi tiết và so sánh&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 1: \(f(x) = x^2\)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trên \(\mathbb{R}\)&lt;/strong&gt;: liên tục nhưng không liên tục đều (tốc độ thay đổi \(\lvert f&apos;(x) \rvert = 2\lvert x \rvert\) không bị chặn).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trên \([0,1]\)&lt;/strong&gt;: liên tục, liên tục đều và liên tục Lipschitz với \(L = 2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 2: \(f(x) = \sin(x)\)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trên \(\mathbb{R}\)&lt;/strong&gt;: liên tục, liên tục đều và \(1\)-Lipschitz (vì \(\lvert \cos(x) \rvert \leq 1\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 3: \(f(x) = \lvert x \rvert\)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trên \(\mathbb{R}\)&lt;/strong&gt;: liên tục, liên tục đều và \(1\)-Lipschitz.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý&lt;/strong&gt;: hàm không khả vi tại \(x = 0\) nhưng vẫn liên tục Lipschitz.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 4: \(f(x) = \sqrt{x}\)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trên \([0,1]\)&lt;/strong&gt;: liên tục và liên tục đều, nhưng không liên tục Lipschitz (đạo hàm không bị chặn gần \(x = 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trên \([a,1]\) với \(a &amp;gt; 0\)&lt;/strong&gt;: liên tục Lipschitz với \(L = 1/(2\sqrt{a})\).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>00 Introduction</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_Introduction/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_Introduction</id>
   <content type="html">&lt;p&gt;Imagine piloting an autonomous spacecraft through a gravitational valley with a fixed fuel tank: every thruster firing is a decision vector, fuel consumption is the objective, and orbital safety corridors are the constraints. Before you can design the autopilot—or prove that it will never get trapped in a false valley—you need a sharp mathematical language for &lt;em&gt;rates of change&lt;/em&gt;, &lt;em&gt;multidimensional geometry&lt;/em&gt;, &lt;em&gt;sets and limits&lt;/em&gt;, and &lt;em&gt;uncertainty&lt;/em&gt;. Chapter 00 builds that exact toolkit so that every theorem in convex optimization feels inevitable rather than mysterious.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-four-mathematical-pillars-of-optimization&quot;&gt;Key ideas: The Four Mathematical Pillars of Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Multivariable Calculus (Local Geometry &amp;amp; Descent):&lt;/strong&gt; Gradients point uphill, Hessians measure curvature, and Taylor expansions turn nonlinear objectives into tractable local quadratics. Without calculus, first- and second-order optimality conditions cannot even be stated.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear Algebra (Structure &amp;amp; Conditioning):&lt;/strong&gt; Decision variables live in \(\mathbb{R}^n\), linear constraints are matrix equations \(Ax = b\), and eigenvalues of the Hessian govern how fast gradient methods converge. Poor conditioning stretches level sets into narrow canyons.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Set Theory &amp;amp; Real Analysis (Existence of Solutions):&lt;/strong&gt; Continuity and compactness (Weierstrass’s theorem) tell us when a minimum actually exists instead of escaping to infinity or approaching an unattainable boundary.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Probability &amp;amp; Statistics (Data-Driven Objectives):&lt;/strong&gt; Empirical risk minimization, maximum likelihood estimation, and stochastic gradient methods all cast statistical inference directly as optimization problems over noisy data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-unifying-calculus-and-linear-algebra-on-a-2d-quadratic&quot;&gt;Worked example: Unifying Calculus and Linear Algebra on a 2D Quadratic&lt;/h3&gt;

&lt;p&gt;Consider minimizing the coupled quadratic objective:&lt;/p&gt;

\[f(x_1, x_2) = (x_1 - 2)^2 + 4(x_2 + 1)^2 + x_1 x_2\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the gradient (first-order condition):&lt;/strong&gt; Differentiate with respect to each coordinate and set \(\nabla f(x_1, x_2) = \mathbf{0}\):
\(\frac{\partial f}{\partial x_1} = 2(x_1 - 2) + x_2 = 2x_1 + x_2 - 4 = 0\)
\(\frac{\partial f}{\partial x_2} = 8(x_2 + 1) + x_1 = x_1 + 8x_2 + 8 = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the linear system:&lt;/strong&gt; From the second equation, \(x_1 = -8x_2 - 8\). Substituting into the first gives:
\(2(-8x_2 - 8) + x_2 - 4 = -15x_2 - 20 = 0 \implies x_2^* = -\frac{4}{3}, \quad x_1^* = -8\left(-\frac{4}{3}\right) - 8 = \frac{8}{3}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify optimality via the Hessian (linear algebra):&lt;/strong&gt;
\(\nabla^2 f(x_1, x_2) = \begin{pmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 8 \end{pmatrix}.\)
Its trace is \(2 + 8 = 10 &amp;gt; 0\) and its determinant is \(2(8) - 1^2 = 15 &amp;gt; 0\), so both eigenvalues are strictly positive. Therefore \(\nabla^2 f \succ 0\) everywhere, certifying that \(x^* = (8/3, -4/3)^T\) is the unique global minimizer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Optimization is at the heart of data science. Whether you’re training a neural network, minimizing errors in regression models, or efficiently allocating resources in recommendation systems, you’re essentially solving problems that involve finding the “best” solution from a vast set of possibilities. But to do this effectively, you need to speak the language of mathematics. We’ll revisit key ideas from linear algebra, set theory, and calculus, ensuring you’re equipped to handle gradients, matrices, constraints, and uncertainties that arise in optimization tasks.&lt;/p&gt;

&lt;p&gt;A later optional lesson, &lt;a href=&quot;/contents/en/chapter00/00_05_Applications_Recent/&quot;&gt;00-05 Applications and recent developments&lt;/a&gt;, maps those same tools onto autodiff, LoRA, and diffusion models (2022–2025).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-06 Multiple-Choice Quiz - Basic Concepts</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_06_Quiz_Basic_Concepts/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_06_Quiz_Basic_Concepts</id>
   <content type="html">&lt;p&gt;Reading derivations feels effortless until you have to diagnose a Hessian, spot a non-compact domain, or compute a directional derivative on a blank sheet of paper. This diagnostic quiz stress-tests your Chapter 00 fluency across calculus, linear algebra, real analysis, and probability—catching any subtle blind spots now before we build convex sets, duality, and interior-point methods on top of them.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-four-diagnostic-checkpoints-for-this-quiz&quot;&gt;Key ideas: Four Diagnostic Checkpoints for This Quiz&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Calculus Fluency:&lt;/strong&gt; Verify that you can rapidly compute gradients, directional derivatives, Hessians, and second-order Taylor expansions without sign or transpose slips.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear Algebra Fluency:&lt;/strong&gt; Check your command of rank, nullspace, orthogonality, eigenvalues, and positive definiteness tests (principal minors and eigenvalues).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Analysis &amp;amp; Topology Fluency:&lt;/strong&gt; Distinguish open vs. closed sets, bounded vs. compact domains, and continuity vs. uniform/Lipschitz continuity.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Probability Fluency:&lt;/strong&gt; Confirm comfort with Bayes’ rule, expectation/variance algebra, and turning log-likelihoods into concave maximization problems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-integrated-pre-quiz-warm-up&quot;&gt;Worked example: Integrated Pre-Quiz Warm-Up&lt;/h3&gt;

&lt;p&gt;Before starting the quiz, test all core tools at once on \(f(x, y) = 2x^2 + 2xy + 3y^2 - 6x - 8y\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Find the stationary point (\(\nabla f = 0\)):&lt;/strong&gt;
\(\frac{\partial f}{\partial x} = 4x + 2y - 6 = 0, \qquad \frac{\partial f}{\partial y} = 2x + 6y - 8 = 0.\)
Multiply the second equation by \(2\) (\(4x + 12y - 16 = 0\)) and subtract the first:
\(10y - 10 = 0 \implies y^* = 1 \implies 4x + 2(1) = 6 \implies x^* = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Classify using the Hessian (linear algebra):&lt;/strong&gt;
\(\nabla^2 f(x, y) = \begin{pmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix}.\)
Leading principal minors are \(\Delta_1 = 4 &amp;gt; 0\) and \(\Delta_2 = 4(6) - 2^2 = 20 &amp;gt; 0\) (also \(\text{tr} = 10 &amp;gt; 0\)), so \(\nabla^2 f \succ 0\) everywhere.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the global minimum:&lt;/strong&gt;
\(f(1, 1) = 2(1) + 2(1) + 3(1) - 6(1) - 8(1) = 7 - 14 = -7.\)
If every step above felt immediate, you are ready to breeze through the quiz below.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the basic concepts of calculus and linear algebra that form the foundation of optimization.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-basic-calculus&quot;&gt;🔢 &lt;strong&gt;Basic Calculus&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Derivatives and partial derivatives:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Derivative: \(f&apos;(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}\)&lt;/li&gt;
  &lt;li&gt;Partial derivative: \(\frac{\partial f}{\partial x_i}\) - the derivative with respect to \(x_i\) when the other variables are held fixed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Gradient and directional derivative:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Gradient: \(\nabla f = \begin{pmatrix} \frac{\partial f}{\partial x_1} \\ \vdots \\ \frac{\partial f}{\partial x_n} \end{pmatrix}\) - the vector pointing in the direction of steepest ascent&lt;/li&gt;
  &lt;li&gt;Directional derivative: \(D_{\mathbf{u}}f = \nabla f \cdot \mathbf{u} = \|\nabla f\| \cos \theta\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Taylor series:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;First order: \(f(\mathbf{x}) \approx f(\mathbf{x}_0) + \nabla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0)\)&lt;/li&gt;
  &lt;li&gt;Second order: \(f(\mathbf{x}) \approx f(\mathbf{x}_0) + \nabla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0) + \frac{1}{2} (\mathbf{x} - \mathbf{x}_0)^T \nabla^2 f(\mathbf{x}_0) (\mathbf{x} - \mathbf{x}_0)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-linear-algebra&quot;&gt;📐 &lt;strong&gt;Linear Algebra&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vectors and vector spaces:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Vector: an ordered list of numbers \(\mathbf{v} = \begin{pmatrix} v_1 \\ \vdots \\ v_n \end{pmatrix}\)&lt;/li&gt;
  &lt;li&gt;The space \(\mathbb{R}^n\): the set of all vectors with \(n\) components&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Vector operations:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Vector addition: \(\mathbf{u} + \mathbf{v} = \begin{pmatrix} u_1 + v_1 \\ \vdots \\ u_n + v_n \end{pmatrix}\)&lt;/li&gt;
  &lt;li&gt;Scalar multiplication: \(c\mathbf{v} = \begin{pmatrix} cv_1 \\ \vdots \\ cv_n \end{pmatrix}\)&lt;/li&gt;
  &lt;li&gt;Dot product: \(\mathbf{u} \cdot \mathbf{v} = \sum_{i=1}^n u_i v_i = \|\mathbf{u}\| \|\mathbf{v}\| \cos \theta\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Vector norms:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;L2 (Euclidean) norm: \(\|\mathbf{x}\|_2 = \sqrt{\sum_{i=1}^n x_i^2}\)&lt;/li&gt;
  &lt;li&gt;L1 (Manhattan) norm: \(\|\mathbf{x}\|_1 = \sum_{i=1}^n \lvert x_i \rvert\)&lt;/li&gt;
  &lt;li&gt;L∞ (Max) norm: \(\|\mathbf{x}\|_\infty = \max_i \lvert x_i \rvert\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Matrices:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Matrix multiplication: \((AB)_{ij} = \sum_{k} A_{ik} B_{kj}\)&lt;/li&gt;
  &lt;li&gt;Inverse matrix: \(AA^{-1} = I\) (if it exists)&lt;/li&gt;
  &lt;li&gt;Determinant: \(\det(A)\) - measures the “volume” scaling of the linear map&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Eigenvalues and eigenvectors:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(A\mathbf{v} = \lambda \mathbf{v}\) with \(\mathbf{v} \neq \mathbf{0}\)&lt;/li&gt;
  &lt;li&gt;\(\lambda\): eigenvalue, \(\mathbf{v}\): the corresponding eigenvector&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-set-theory-and-real-analysis&quot;&gt;📊 &lt;strong&gt;Set Theory and Real Analysis&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Basic sets:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Open set: every point has a neighborhood contained in the set&lt;/li&gt;
  &lt;li&gt;Closed set: contains all of its boundary points&lt;/li&gt;
  &lt;li&gt;Compact set: closed and bounded in \(\mathbb{R}^n\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Continuity:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Function continuous at \(x_0\): \(\lim_{x \to x_0} f(x) = f(x_0)\)&lt;/li&gt;
  &lt;li&gt;Uniformly continuous: \(\forall \epsilon &amp;gt; 0, \exists \delta &amp;gt; 0\) such that \(\lvert x-y \rvert &amp;lt; \delta \Rightarrow \lvert f(x)-f(y) \rvert &amp;lt; \epsilon\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-basic-probability&quot;&gt;🎲 &lt;strong&gt;Basic Probability&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Basic concepts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Probability: \(P(A) \in [0,1]\), \(P(\Omega) = 1\)&lt;/li&gt;
  &lt;li&gt;Random variable: a function from the sample space to the real numbers&lt;/li&gt;
  &lt;li&gt;Expectation: \(E[X] = \int x f(x) dx\) (continuous) or \(E[X] = \sum x P(X=x)\) (discrete)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common distributions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Normal: \(X \sim N(\mu, \sigma^2)\)&lt;/li&gt;
  &lt;li&gt;Uniform: \(X \sim U(a,b)\)&lt;/li&gt;
  &lt;li&gt;Bernoulli: \(X \sim \text{Ber}(p)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; These concepts are the foundation of optimization. The gradient points in the direction of fastest increase, the Hessian matrix describes curvature, and the Taylor series gives local approximations of a function.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Multiple-Choice Quiz: Basic Concepts&lt;/h2&gt;
        &lt;p&gt;Choose the best answer for each question. You will see your results as soon as you finish.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Question 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Question 1: The derivative of $$f(x) = x^3 + 2x^2 - 5x + 1$$ at $$x = 1$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) $$4$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) $$2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) $$-1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) $$6$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$2$$&lt;/strong&gt;&lt;br /&gt;
                $$f&apos;(x) = 3x^2 + 4x - 5$$&lt;br /&gt;
                $$f&apos;(1) = 3(1)^2 + 4(1) - 5 = 3 + 4 - 5 = 2$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: Let $$f(x,y) = x^2y + 3xy^2$$. The partial derivative $$\frac{\partial f}{\partial x}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) $$2xy + 3y^2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) $$x^2 + 6xy$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) $$2xy + 6xy$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) $$x^2 + 3y^2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$2xy + 3y^2$$&lt;/strong&gt;&lt;br /&gt;
                When taking the partial derivative with respect to $$x$$, we treat $$y$$ as a constant:&lt;br /&gt;
                $$\frac{\partial f}{\partial x} = \frac{\partial}{\partial x}(x^2y + 3xy^2) = 2xy + 3y^2$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: The gradient of $$f(x,y) = x^2 + 2xy + y^2$$ at the point $$(1,1)$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 4 \\ 4 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 2 \\ 2 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 3 \\ 3 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 1 \\ 1 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\begin{pmatrix} 4 \\ 4 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                $$\frac{\partial f}{\partial x} = 2x + 2y$$, $$\frac{\partial f}{\partial y} = 2x + 2y$$&lt;br /&gt;
                At $$(1,1)$$: $$\nabla f(1,1) = \begin{pmatrix} 2(1) + 2(1) \\ 2(1) + 2(1) \end{pmatrix} = \begin{pmatrix} 4 \\ 4 \end{pmatrix}$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: Given the gradient $$\nabla f = \begin{pmatrix} 3 \\ 4 \end{pmatrix}$$ and the unit vector $$\mathbf{u} = \begin{pmatrix} 0.6 \\ 0.8 \end{pmatrix}$$, the directional derivative $$D_{\mathbf{u}}f$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) $$4.8$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) $$3.2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) $$7$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$5$$&lt;/strong&gt;&lt;br /&gt;
                $$D_{\mathbf{u}}f = \nabla f \cdot \mathbf{u} = 3(0.6) + 4(0.8) = 1.8 + 3.2 = 5$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: The direction of steepest ascent of a function is always:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) The direction of the gradient vector&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) The direction opposite to the gradient vector&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) A direction perpendicular to the gradient vector&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) The direction of the x-axis&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The direction of the gradient vector&lt;/strong&gt;&lt;br /&gt;
                The gradient always points in the direction of steepest ascent of the function. This is a fundamental property of the gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: Let $$\mathbf{u} = \begin{pmatrix} 2 \\ -1 \\ 3 \end{pmatrix}$$ and $$\mathbf{v} = \begin{pmatrix} 1 \\ 4 \\ -2 \end{pmatrix}$$. The vector $$\mathbf{u} + \mathbf{v}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 3 \\ 3 \\ 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 1 \\ -5 \\ 5 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 2 \\ 4 \\ -6 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 3 \\ -3 \\ 1 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\begin{pmatrix} 3 \\ 3 \\ 1 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                $$\mathbf{u} + \mathbf{v} = \begin{pmatrix} 2+1 \\ -1+4 \\ 3+(-2) \end{pmatrix} = \begin{pmatrix} 3 \\ 3 \\ 1 \end{pmatrix}$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: The dot product of $$\mathbf{a} = \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix}$$ and $$\mathbf{b} = \begin{pmatrix} 4 \\ 5 \\ 6 \end{pmatrix}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) $$32$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) $$14$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) $$18$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) $$24$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$32$$&lt;/strong&gt;&lt;br /&gt;
                $$\mathbf{a} \cdot \mathbf{b} = 1 \cdot 4 + 2 \cdot 5 + 3 \cdot 6 = 4 + 10 + 18 = 32$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The Euclidean norm of the vector $$\mathbf{v} = \begin{pmatrix} 3 \\ 4 \end{pmatrix}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) $$5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) $$7$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) $$25$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) $$\sqrt{7}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$5$$&lt;/strong&gt;&lt;br /&gt;
                $$\|\mathbf{v}\|_2 = \sqrt{3^2 + 4^2} = \sqrt{9 + 16} = \sqrt{25} = 5$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: Two vectors $$\mathbf{u}$$ and $$\mathbf{v}$$ are called orthogonal when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) $$\mathbf{u} \cdot \mathbf{v} = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) $$\mathbf{u} \cdot \mathbf{v} = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) $$\|\mathbf{u}\| = \|\mathbf{v}\|$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) $$\mathbf{u} + \mathbf{v} = \mathbf{0}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\mathbf{u} \cdot \mathbf{v} = 0$$&lt;/strong&gt;&lt;br /&gt;
                Two vectors are orthogonal (perpendicular) if and only if their dot product is 0.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: The product of the two matrices $$\begin{pmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{pmatrix} \begin{pmatrix} 2 &amp;amp; 0 \\ 1 &amp;amp; 3 \end{pmatrix}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 4 &amp;amp; 6 \\ 10 &amp;amp; 12 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 2 &amp;amp; 4 \\ 10 &amp;amp; 14 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 2 &amp;amp; 0 \\ 3 &amp;amp; 12 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 3 &amp;amp; 2 \\ 4 &amp;amp; 7 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\begin{pmatrix} 4 &amp;amp; 6 \\ 10 &amp;amp; 12 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                Entry $$(1,1)$$: $$1 \cdot 2 + 2 \cdot 1 = 4$$&lt;br /&gt;
                Entry $$(1,2)$$: $$1 \cdot 0 + 2 \cdot 3 = 6$$&lt;br /&gt;
                Entry $$(2,1)$$: $$3 \cdot 2 + 4 \cdot 1 = 10$$&lt;br /&gt;
                Entry $$(2,2)$$: $$3 \cdot 0 + 4 \cdot 3 = 12$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: The $$2 \times 2$$ identity matrix is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                The identity matrix has ones on the main diagonal and zeros everywhere else.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The transpose of the matrix $$\begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 5 &amp;amp; 6 \end{pmatrix}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 1 &amp;amp; 4 \\ 2 &amp;amp; 5 \\ 3 &amp;amp; 6 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 6 &amp;amp; 5 &amp;amp; 4 \\ 3 &amp;amp; 2 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 4 &amp;amp; 1 \\ 5 &amp;amp; 2 \\ 6 &amp;amp; 3 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 5 &amp;amp; 6 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\begin{pmatrix} 1 &amp;amp; 4 \\ 2 &amp;amp; 5 \\ 3 &amp;amp; 6 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                The transpose of a matrix is formed by swapping its rows and columns.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The determinant of the matrix $$\begin{pmatrix} 3 &amp;amp; 1 \\ 2 &amp;amp; 4 \end{pmatrix}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) $$10$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) $$14$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) $$2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) $$12$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$10$$&lt;/strong&gt;&lt;br /&gt;
                $$\det\begin{pmatrix} 3 &amp;amp; 1 \\ 2 &amp;amp; 4 \end{pmatrix} = 3 \cdot 4 - 1 \cdot 2 = 12 - 2 = 10$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: The two vectors $$\mathbf{v}_1 = \begin{pmatrix} 1 \\ 2 \end{pmatrix}$$ and $$\mathbf{v}_2 = \begin{pmatrix} 2 \\ 4 \end{pmatrix}$$ are:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Linearly independent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Linearly dependent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Orthogonal&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Cannot be determined&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Linearly dependent&lt;/strong&gt;&lt;br /&gt;
                $$\mathbf{v}_2 = 2\mathbf{v}_1$$, so the two vectors are linearly dependent.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: The Manhattan (L1) norm of the vector $$\mathbf{v} = \begin{pmatrix} -2 \\ 3 \\ -1 \end{pmatrix}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) $$6$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) $$0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) $$4$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) $$\sqrt{14}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$6$$&lt;/strong&gt;&lt;br /&gt;
                $$\|\mathbf{v}\|_1 = |-2| + |3| + |-1| = 2 + 3 + 1 = 6$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: Let $$z = x^2 + y^2$$ with $$x = 2t$$ and $$y = 3t$$. The derivative $$\frac{dz}{dt}$$ at $$t = 1$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) $$26$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) $$13$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) $$10$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) $$5$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$26$$&lt;/strong&gt;&lt;br /&gt;
                $$\frac{dz}{dt} = \frac{\partial z}{\partial x}\frac{dx}{dt} + \frac{\partial z}{\partial y}\frac{dy}{dt} = 2x \cdot 2 + 2y \cdot 3$$&lt;br /&gt;
                At $$t = 1$$: $$x = 2, y = 3$$, so $$\frac{dz}{dt} = 2(2)(2) + 2(3)(3) = 8 + 18 = 26$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: A critical point of a function is a point where:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) The gradient equals the zero vector&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) The function attains its maximum value&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) The function attains its minimum value&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) The function is undefined&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) The gradient equals the zero vector&lt;/strong&gt;&lt;br /&gt;
                A critical point is a point where the gradient of the function is the zero vector, i.e. $$\nabla f = \mathbf{0}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: The inverse of the matrix $$\begin{pmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{pmatrix}$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 0.5 &amp;amp; 0.5 \\ 0.5 &amp;amp; 1 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\begin{pmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                $$\det(A) = 2 \cdot 1 - 1 \cdot 1 = 1$$&lt;br /&gt;
                $$A^{-1} = \frac{1}{1}\begin{pmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{pmatrix} = \begin{pmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{pmatrix}$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: The (nonzero) gradient of a function at a point is always:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Perpendicular to the level curve at that point&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Parallel to the level curve at that point&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) At a 45° angle to the level curve&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Unrelated to the level curve&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Perpendicular to the level curve at that point&lt;/strong&gt;&lt;br /&gt;
                The gradient is always perpendicular to the level curve, because the level curve is the set of points with the same function value.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: In the gradient descent algorithm, we move in the direction:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Opposite to the gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Along the gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Perpendicular to the gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) A random direction&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Opposite to the gradient&lt;/strong&gt;&lt;br /&gt;
                Gradient descent moves in the direction $$-\nabla f$$ to find a minimum of the function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 21 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: The second derivative of $$f(x) = 3x^4 - 2x^3 + x^2 - 5x + 1$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$36x^2 - 12x + 2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$12x^3 - 6x^2 + 2x - 5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$36x^2 - 12x + 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$12x^2 - 6x + 2$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$36x^2 - 12x + 2$$&lt;/strong&gt;&lt;br /&gt;
                $$f&apos;(x) = 12x^3 - 6x^2 + 2x - 5$$&lt;br /&gt;
                $$f&apos;&apos;(x) = 36x^2 - 12x + 2$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: Let $$f(x,y) = x^2 + 2xy + 3y^2$$. The Hessian matrix at the point $$(1,1)$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$\begin{pmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$\begin{pmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 3 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$\begin{pmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 6 \end{pmatrix}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) $$\begin{pmatrix} 4 &amp;amp; 4 \\ 4 &amp;amp; 8 \end{pmatrix}$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\begin{pmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix}$$&lt;/strong&gt;&lt;br /&gt;
                $$\frac{\partial^2 f}{\partial x^2} = 2$$, $$\frac{\partial^2 f}{\partial y^2} = 6$$, $$\frac{\partial^2 f}{\partial x \partial y} = 2$$&lt;br /&gt;
                In this case the Hessian matrix does not depend on the particular point.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: The distance from the point $$A(1,2)$$ to the point $$B(4,6)$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$7$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$25$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$3$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$5$$&lt;/strong&gt;&lt;br /&gt;
                Distance = $$\sqrt{(4-1)^2 + (6-2)^2} = \sqrt{9 + 16} = \sqrt{25} = 5$$
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The eigenvalues of the matrix $$A = \begin{pmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{pmatrix}$$ are:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$\lambda_1 = 3, \lambda_2 = 2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$\lambda_1 = 3, \lambda_2 = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$\lambda_1 = 1, \lambda_2 = 5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) $$\lambda_1 = 0, \lambda_2 = 5$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\lambda_1 = 3, \lambda_2 = 2$$&lt;/strong&gt;&lt;br /&gt;
                For an upper triangular matrix, the eigenvalues are exactly the entries on the main diagonal.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: The minimizer of $$f(x) = x^2 - 4x + 5$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$x = 2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$x = -2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$x = 4$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$x = 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$x = 2$$&lt;/strong&gt;&lt;br /&gt;
                $$f&apos;(x) = 2x - 4 = 0 \Rightarrow x = 2$$&lt;br /&gt;
                $$f&apos;&apos;(x) = 2 &amp;gt; 0$$, so $$x = 2$$ is a minimizer.
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Previous&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Next&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Exercise Results&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #45a049);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: center;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
}

.options label:hover {
    border-color: #4CAF50;
    background-color: #f0f8f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    transform: scale(1.2);
}

.options label.selected {
    border-color: #4CAF50;
    background-color: #e8f5e8;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #e3f2fd;
    border-left: 4px solid #2196F3;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #1976D2;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #45a049;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #f0f8f0;
    border-radius: 8px;
    border: 2px solid #4CAF50;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #2E7D32;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answer for each question
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;a&apos;, q3: &apos;a&apos;, q4: &apos;a&apos;, q5: &apos;a&apos;,
    q6: &apos;a&apos;, q7: &apos;a&apos;, q8: &apos;a&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;a&apos;, q13: &apos;a&apos;, q14: &apos;b&apos;, q15: &apos;a&apos;,
    q16: &apos;a&apos;, q17: &apos;a&apos;, q18: &apos;a&apos;, q19: &apos;a&apos;, q20: &apos;a&apos;,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;
};

/**
 * Update the progress bar and show the current question
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Question ${currentQuestion}/${totalQuestions}`;
}

/**
 * Show a question by its number
 */
function showQuestion(questionNum) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Update the state of the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Go to the next question
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Go back to the previous question
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Store the user&apos;s answer
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Update the UI to show the selected answer
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Submit and show the results
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Compute the score and build the detailed report
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Show explanations for all questions
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Build the detailed report
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Question ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Correct&apos; : &apos;Incorrect&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Your answer: ${userAnswer || &apos;Not answered&apos;} | Correct answer: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Show the results
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Score: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Excellent!&apos; :
              scorePercentage &gt;= 60 ? &apos;👍 Pretty good!&apos; :
              scorePercentage &gt;= 40 ? &apos;📚 Needs more review&apos; : &apos;💪 Keep trying!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Restart the exercise
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide the results and show the navigation again
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Clear all selections
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>00-04 Probability and Statistics</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_04_Probability_and_Statistics/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_04_Probability_and_Statistics</id>
   <content type="html">&lt;p&gt;Real-world optimization rarely operates on noiseless, deterministic formulas: demand forecasts fluctuate, sensor readings carry Gaussian noise, and machine learning datasets are random samples from an unknown population. Probability and statistics supply the mathematical bridge from noisy observations to clean optimization objectives—turning parameter estimation, risk management, and stochastic approximation into convex problems we can solve with provable guarantees.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-why-probability-sits-inside-modern-optimization&quot;&gt;Key ideas: Why Probability Sits Inside Modern Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Random Variables &amp;amp; Expectation:&lt;/strong&gt; Expected loss \(\mathbb{E}[\ell(w; Z)]\) is the true target of stochastic optimization; linearity of expectation lets us differentiate and average unbiased gradient estimates.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Loss Functions as Distributional Assumptions:&lt;/strong&gt; Minimizing squared error corresponds to Gaussian noise, minimizing \(\ell_1\) error corresponds to Laplace noise, and cross-entropy corresponds to categorical log-likelihood.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Empirical Risk Minimization (ERM):&lt;/strong&gt; Replaces an unknown expectation with a finite sample average \(\frac{1}{n}\sum_{i=1}^n \ell(w; z_i)\), yielding a concrete finite-sum optimization problem.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Concentration &amp;amp; Variance Control:&lt;/strong&gt; Variance bounds explain why mini-batching, variance reduction, and regularization stabilize noisy optimization trajectories.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-sample-mean-vs-sample-median-as-optimization-solutions&quot;&gt;Worked example: Sample Mean vs. Sample Median as Optimization Solutions&lt;/h3&gt;

&lt;p&gt;Given a small noisy dataset \(\{2, 4, 9\}\), compare two 1D empirical risk minimization objectives for a location estimate \(\theta \in \mathbb{R}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Squared loss (\(\ell_2\) ERM):&lt;/strong&gt;
\(L_2(\theta) = \frac{1}{3}\left[(2 - \theta)^2 + (4 - \theta)^2 + (9 - \theta)^2\right].\)
Differentiate and set to zero:
\(L_2&apos;(\theta) = \frac{2}{3}\left[(\theta - 2) + (\theta - 4) + (\theta - 9)\right] = \frac{2}{3}(3\theta - 15) = 0 \implies \hat{\theta}_2 = 5 \text{ (the sample mean)}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Absolute loss (\(\ell_1\) ERM):&lt;/strong&gt;
\(L_1(\theta) = |2 - \theta| + |4 - \theta| + |9 - \theta|.\)
For \(\theta &amp;lt; 4\) the slope is \(-1\) (or \(-3\) below \(2\)); for \(\theta &amp;gt; 4\) the slope is \(+1\) (or \(+3\) above \(9\)). The slope flips sign at \(\hat{\theta}_1 = 4\) (the sample median), where \(L_1(4) = 2 + 0 + 5 = 7\) (compared to \(L_1(5) = 3 + 1 + 4 = 8\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Changing the noise model from Gaussian (\(\ell_2\)) to heavy-tailed Laplace (\(\ell_1\)) shifts the optimizer from \(5\) to \(4\), making the estimate resistant to the outlier \(9\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;probability-and-statistics-for-convex-optimization&quot;&gt;Probability and Statistics for Convex Optimization&lt;/h2&gt;

&lt;p&gt;Probability and statistics form a crucial foundation for understanding many optimization problems, especially in machine learning and data science. This section introduces the essential probabilistic concepts that frequently appear in convex optimization, from maximum likelihood estimation to Bayesian optimization.&lt;/p&gt;

&lt;h3 id=&quot;why-probability-matters-in-optimization&quot;&gt;Why Probability Matters in Optimization&lt;/h3&gt;

&lt;p&gt;Many optimization problems arise from statistical modeling:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Maximum Likelihood Estimation (MLE)&lt;/strong&gt;: Finding parameters that maximize the likelihood of observed data&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bayesian Optimization&lt;/strong&gt;: Using probabilistic models to guide the search for optimal solutions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic Optimization&lt;/strong&gt;: Dealing with uncertainty and randomness in objective functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization&lt;/strong&gt;: Adding probabilistic priors to prevent overfitting&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Risk Minimization&lt;/strong&gt;: Optimizing expected loss over probability distributions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;key-topics-covered&quot;&gt;Key Topics Covered&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Basic Probability Theory&lt;/strong&gt;: Sample spaces, events, and probability axioms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Common Probability Distributions&lt;/strong&gt;: Normal, exponential, and other distributions crucial for optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Expectation and Variance&lt;/strong&gt;: Computing and optimizing expected values&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bayes’ Theorem&lt;/strong&gt;: Foundation for Bayesian optimization and inference&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Statistical Estimation&lt;/strong&gt;: Connecting probability theory to optimization problems&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;connection-to-convex-optimization&quot;&gt;Connection to Convex Optimization&lt;/h3&gt;

&lt;p&gt;Understanding probability helps you:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Formulate Problems&lt;/strong&gt;: Convert real-world uncertainty into mathematical optimization problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choose Objective Functions&lt;/strong&gt;: Select appropriate loss functions based on probabilistic assumptions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interpret Results&lt;/strong&gt;: Understand confidence intervals and statistical significance of solutions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Handle Noise&lt;/strong&gt;: Deal with measurement errors and stochastic processes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Design Algorithms&lt;/strong&gt;: Develop robust optimization methods that work under uncertainty&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This foundation will be essential as we explore how probabilistic models lead to convex optimization problems in machine learning, statistics, and engineering applications.&lt;/p&gt;

&lt;div style=&quot;background: #e8f4fd; padding: 15px; border-left: 4px solid #2196F3; margin: 20px 0;&quot;&gt;
&lt;strong&gt;💡 Learning Path:&lt;/strong&gt; Start with basic probability concepts, then explore how they connect to optimization through maximum likelihood estimation and Bayesian methods. Each lesson builds toward understanding how uncertainty and randomness create optimization problems.
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>00-04-03 Likelihood and Maximum Likelihood Estimation (MLE)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_04_03_Likelihood_and_Maximum_Likelihood_Estimation/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_04_03_Likelihood_and_Maximum_Likelihood_Estimation</id>
   <content type="html">&lt;p&gt;Probability asks, &lt;em&gt;given a known model parameter \(\theta\), how likely is this dataset?&lt;/em&gt; Statistics flips the telescope around: &lt;em&gt;given the fixed dataset we actually observed, which parameter \(\theta\) makes our observations most plausible?&lt;/em&gt; That simple perspective flip defines the likelihood function, and taking its logarithm converts messy products of tiny probabilities into clean sums that optimization algorithms can maximize directly.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-casting-estimation-as-optimization&quot;&gt;Key ideas: Casting Estimation as Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Likelihood vs. Probability:&lt;/strong&gt; While \(p(x \mid \theta)\) is a normalized density over data \(x\), the likelihood \(L(\theta) = p(x \mid \theta)\) treats \(x\) as fixed and varies \(\theta\)—it is an objective function, not a distribution over \(\theta\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Log-Likelihood Transformation:&lt;/strong&gt; Since \(\ln(\cdot)\) is strictly increasing, maximizing \(\ell(\theta) = \sum_{i=1}^n \ln p(x_i \mid \theta)\) yields the exact same optimizer \(\hat{\theta}_{\text{MLE}}\) while avoiding numerical underflow.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Score Equation &amp;amp; Concavity:&lt;/strong&gt; Setting the score \(\nabla \ell(\theta) = \mathbf{0}\) locates stationary candidates; checking \(\nabla^2 \ell(\theta) \preceq 0\) verifies a global maximum (equivalently, minimizing the convex negative log-likelihood \(-\ell(\theta)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bridge to Regularization (MAP):&lt;/strong&gt; Adding a log-prior \(\ln p(\theta)\) to \(\ell(\theta)\) produces Maximum A Posteriori estimation, which algebraically matches adding an \(\ell_2\) or \(\ell_1\) penalty in regularized optimization.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-bernoulli-mle-from-10-coin-flips&quot;&gt;Worked example: Bernoulli MLE from 10 Coin Flips&lt;/h3&gt;

&lt;p&gt;An experiment observes \(7\) heads and \(3\) tails in \(n = 10\) independent \(\text{Bernoulli}(p)\) trials, where \(p \in (0, 1)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the likelihood and log-likelihood:&lt;/strong&gt;
\(L(p) = p^7 (1 - p)^3 \implies \ell(p) = 7\ln p + 3\ln(1 - p).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Differentiate with respect to \(p\) and set to zero:&lt;/strong&gt;
\(\ell&apos;(p) = \frac{7}{p} - \frac{3}{1 - p} = 0 \implies 7(1 - p) = 3p \implies 7 = 10p \implies \hat{p}_{\text{MLE}} = 0.7.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check strict concavity at \(\hat{p} = 0.7\) (and everywhere on \((0, 1)\)):&lt;/strong&gt;
\(\ell&apos;&apos;(p) = -\frac{7}{p^2} - \frac{3}{(1 - p)^2} &amp;lt; 0.\)
At \(p = 0.7\), \(\ell&apos;&apos;(0.7) = -\frac{7}{0.49} - \frac{3}{0.09} = -\frac{100}{7} - \frac{100}{3} = -\frac{1000}{21} \approx -47.62 &amp;lt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; Minimizing the negative log-likelihood \(-\ell(p)\) is a strictly convex problem with unique global minimizer \(\hat{p}_{\text{MLE}} = 0.7\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;likelihood-and-maximum-likelihood-estimation&quot;&gt;Likelihood and Maximum Likelihood Estimation&lt;/h2&gt;

&lt;p&gt;In probability and statistics, the &lt;strong&gt;likelihood&lt;/strong&gt; is an important concept that expresses how plausible the observed data is under an assumed model or a given set of parameters. However, the likelihood is not an ordinary probability: it is a function that measures how well a model fits the data.&lt;/p&gt;

&lt;h3 id=&quot;definition-of-likelihood&quot;&gt;Definition of Likelihood&lt;/h3&gt;

&lt;p&gt;The likelihood of a parameter \(\theta\) (or of a model) is defined as the probability of the observed data, assuming the parameter \(\theta\) is true. It is usually written \(L(\theta \mid x)\), where \(x\) is the observed data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Formula:&lt;/strong&gt;
\(L(\theta \mid x) = P(x \mid \theta)\)&lt;/p&gt;

&lt;p&gt;Here, \(P(x \mid \theta)\) is the probability of the data \(x\) when the parameter \(\theta\) is given.&lt;/p&gt;

&lt;h3 id=&quot;the-difference-from-probability&quot;&gt;The Difference from Probability&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Probability&lt;/strong&gt; describes how likely a future event is, with known parameters.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Likelihood&lt;/strong&gt;, conversely, measures how well different parameters fit data that has already been observed.&lt;/li&gt;
&lt;/ul&gt;

&lt;div style=&quot;background: #fff3cd; padding: 15px; border-left: 4px solid #ffc107; margin: 20px 0;&quot;&gt;
&lt;strong&gt;⚠️ Important note:&lt;/strong&gt; The likelihood is not the probability of the parameter θ, because it is not normalized like a probability distribution (the integral of the likelihood does not have to equal 1).
&lt;/div&gt;

&lt;h3 id=&quot;illustrative-example-flipping-a-coin&quot;&gt;Illustrative Example: Flipping a Coin&lt;/h3&gt;

&lt;p&gt;Suppose you flip a coin and observe 3 “heads” (H) and 2 “tails” (T) in 5 flips. You want to know the probability \(p\) of getting heads.&lt;/p&gt;

&lt;p&gt;The likelihood of \(p\) is the probability of observing the data (3 heads, 2 tails) when \(p\) is given:&lt;/p&gt;

\[L(p \mid \text{data}) = P(\text{3 heads, 2 tails} \mid p) = \binom{5}{3} p^3 (1-p)^2\]

&lt;p&gt;Where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\binom{5}{3}\) is the binomial coefficient&lt;/li&gt;
  &lt;li&gt;\(p^3\) is the probability of 3 heads&lt;/li&gt;
  &lt;li&gt;\((1-p)^2\) is the probability of 2 tails&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trying different values:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For \(p = 0.6\):
\(L(0.6 \mid \text{data}) = \binom{5}{3} (0.6)^3 (0.4)^2 = 10 \times 0.216 \times 0.16 \approx 0.3456\)&lt;/p&gt;

&lt;p&gt;For \(p = 0.5\):
\(L(0.5 \mid \text{data}) = \binom{5}{3} (0.5)^3 (0.5)^2 = 10 \times 0.125 \times 0.25 \approx 0.3125\)&lt;/p&gt;

&lt;p&gt;The higher likelihood at \(p = 0.6\) shows that this value fits the observed data better than \(p = 0.5\).&lt;/p&gt;

&lt;h3 id=&quot;interactive-example-flipping-a-coin&quot;&gt;Interactive Example: Flipping a Coin&lt;/h3&gt;

&lt;div id=&quot;coin-flip-example&quot; style=&quot;border: 1px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 8px;&quot;&gt;
    &lt;h4&gt;Coin Flip Experiment&lt;/h4&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;label for=&quot;p-slider&quot;&gt;Probability of heads (p): &lt;span id=&quot;p-value&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;p-slider&quot; min=&quot;0.01&quot; max=&quot;0.99&quot; step=&quot;0.01&quot; value=&quot;0.5&quot; style=&quot;width: 300px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;label for=&quot;heads-input&quot;&gt;Number of heads: &lt;/label&gt;
        &lt;input type=&quot;number&quot; id=&quot;heads-input&quot; value=&quot;3&quot; min=&quot;0&quot; max=&quot;20&quot; style=&quot;width: 60px;&quot; /&gt;
        
        &lt;label for=&quot;tails-input&quot; style=&quot;margin-left: 20px;&quot;&gt;Number of tails: &lt;/label&gt;
        &lt;input type=&quot;number&quot; id=&quot;tails-input&quot; value=&quot;2&quot; min=&quot;0&quot; max=&quot;20&quot; style=&quot;width: 60px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;canvas id=&quot;likelihood-plot&quot; width=&quot;600&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
    &lt;/div&gt;
    
    &lt;div id=&quot;likelihood-result&quot; style=&quot;background: #f8f9fa; padding: 10px; border-radius: 4px; margin: 10px 0;&quot;&gt;
        &lt;strong&gt;Current likelihood:&lt;/strong&gt; &lt;span id=&quot;current-likelihood&quot;&gt;0.3125&lt;/span&gt;&lt;br /&gt;
        &lt;strong&gt;Log-likelihood:&lt;/strong&gt; &lt;span id=&quot;current-log-likelihood&quot;&gt;-1.16&lt;/span&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    const pSlider = document.getElementById(&apos;p-slider&apos;);
    const pValue = document.getElementById(&apos;p-value&apos;);
    const headsInput = document.getElementById(&apos;heads-input&apos;);
    const tailsInput = document.getElementById(&apos;tails-input&apos;);
    const canvas = document.getElementById(&apos;likelihood-plot&apos;);
    const ctx = canvas.getContext(&apos;2d&apos;);
    const likelihoodResult = document.getElementById(&apos;current-likelihood&apos;);
    const logLikelihoodResult = document.getElementById(&apos;current-log-likelihood&apos;);
    
    function binomialCoeff(n, k) {
        if (k &gt; n) return 0;
        if (k === 0 || k === n) return 1;
        
        let result = 1;
        for (let i = 0; i &lt; k; i++) {
            result = result * (n - i) / (i + 1);
        }
        return result;
    }
    
    function likelihood(p, heads, tails) {
        const n = heads + tails;
        const coeff = binomialCoeff(n, heads);
        return coeff * Math.pow(p, heads) * Math.pow(1 - p, tails);
    }
    
    function logLikelihood(p, heads, tails) {
        const n = heads + tails;
        const logCoeff = Math.log(binomialCoeff(n, heads));
        return logCoeff + heads * Math.log(p) + tails * Math.log(1 - p);
    }
    
    function plotLikelihood() {
        const heads = parseInt(headsInput.value);
        const tails = parseInt(tailsInput.value);
        const currentP = parseFloat(pSlider.value);
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Draw axes
        ctx.strokeStyle = &apos;#333&apos;;
        ctx.lineWidth = 1;
        ctx.beginPath();
        ctx.moveTo(50, 250);
        ctx.lineTo(550, 250);
        ctx.moveTo(50, 250);
        ctx.lineTo(50, 50);
        ctx.stroke();
        
        // Axis labels
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;p (probability of heads)&apos;, 250, 280);
        ctx.save();
        ctx.translate(20, 150);
        ctx.rotate(-Math.PI/2);
        ctx.fillText(&apos;Likelihood&apos;, 0, 0);
        ctx.restore();
        
        // Draw the likelihood curve
        ctx.strokeStyle = &apos;#2196F3&apos;;
        ctx.lineWidth = 2;
        ctx.beginPath();
        
        let maxLikelihood = 0;
        const points = [];
        
        for (let i = 0; i &lt;= 500; i++) {
            const p = 0.01 + (i / 500) * 0.98;
            const l = likelihood(p, heads, tails);
            points.push({p: p, l: l});
            maxLikelihood = Math.max(maxLikelihood, l);
        }
        
        for (let i = 0; i &lt; points.length; i++) {
            const x = 50 + (points[i].p - 0.01) / 0.98 * 500;
            const y = 250 - (points[i].l / maxLikelihood) * 200;
            
            if (i === 0) {
                ctx.moveTo(x, y);
            } else {
                ctx.lineTo(x, y);
            }
        }
        ctx.stroke();
        
        // Draw the current point
        const currentLikelihood = likelihood(currentP, heads, tails);
        const currentX = 50 + (currentP - 0.01) / 0.98 * 500;
        const currentY = 250 - (currentLikelihood / maxLikelihood) * 200;
        
        ctx.fillStyle = &apos;#f44336&apos;;
        ctx.beginPath();
        ctx.arc(currentX, currentY, 5, 0, 2 * Math.PI);
        ctx.fill();
        
        // Update results
        likelihoodResult.textContent = currentLikelihood.toFixed(6);
        logLikelihoodResult.textContent = logLikelihood(currentP, heads, tails).toFixed(4);
        
        // Draw tick marks
        ctx.fillStyle = &apos;#666&apos;;
        ctx.font = &apos;10px Arial&apos;;
        for (let i = 0; i &lt;= 10; i++) {
            const p = i / 10;
            const x = 50 + (p - 0.01) / 0.98 * 500;
            ctx.fillText(p.toFixed(1), x - 10, 265);
        }
    }
    
    function updateDisplay() {
        pValue.textContent = pSlider.value;
        plotLikelihood();
    }
    
    pSlider.addEventListener(&apos;input&apos;, updateDisplay);
    headsInput.addEventListener(&apos;input&apos;, plotLikelihood);
    tailsInput.addEventListener(&apos;input&apos;, plotLikelihood);
    
    // Initialize
    updateDisplay();
});
&lt;/script&gt;

&lt;h3 id=&quot;maximum-likelihood-estimation-mle&quot;&gt;Maximum Likelihood Estimation (MLE)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Maximum likelihood estimation&lt;/strong&gt; is the method of finding the value of the parameter \(\theta\) for which the likelihood function \(L(\theta \mid x)\) attains its largest value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MLE formula:&lt;/strong&gt;
\(\hat{\theta}_{MLE} = \arg\max_{\theta} L(\theta \mid x)\)&lt;/p&gt;

&lt;p&gt;It is often easier to maximize the log-likelihood:
\(\hat{\theta}_{MLE} = \arg\max_{\theta} \log L(\theta \mid x)\)&lt;/p&gt;

&lt;h3 id=&quot;mle-example-the-normal-distribution&quot;&gt;MLE Example: The Normal Distribution&lt;/h3&gt;

&lt;p&gt;Suppose we have \(n\) independent observations \(x_1, x_2, \ldots, x_n\) from a normal distribution \(N(\mu, \sigma^2)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Likelihood function:&lt;/strong&gt;
\(L(\mu, \sigma^2 \mid x_1, \ldots, x_n) = \prod_{i=1}^{n} \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left(-\frac{(x_i - \mu)^2}{2\sigma^2}\right)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log-likelihood:&lt;/strong&gt;
\(\ell(\mu, \sigma^2) = -\frac{n}{2}\log(2\pi) - \frac{n}{2}\log(\sigma^2) - \frac{1}{2\sigma^2}\sum_{i=1}^{n}(x_i - \mu)^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MLE estimates:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To find \(\hat{\mu}\), differentiate with respect to \(\mu\) and set the derivative to 0:
\(\frac{\partial \ell}{\partial \mu} = \frac{1}{\sigma^2}\sum_{i=1}^{n}(x_i - \mu) = 0\)&lt;/p&gt;

&lt;p&gt;Solving gives: \(\hat{\mu}_{MLE} = \frac{1}{n}\sum_{i=1}^{n} x_i = \bar{x}\)&lt;/p&gt;

&lt;p&gt;Similarly for \(\sigma^2\):
\(\hat{\sigma^2}_{MLE} = \frac{1}{n}\sum_{i=1}^{n}(x_i - \bar{x})^2\)&lt;/p&gt;

&lt;h3 id=&quot;interactive-example-mle-for-the-normal-distribution&quot;&gt;Interactive Example: MLE for the Normal Distribution&lt;/h3&gt;

&lt;div id=&quot;normal-mle-example&quot; style=&quot;border: 1px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 8px;&quot;&gt;
    &lt;h4&gt;MLE for the Normal Distribution&lt;/h4&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;button id=&quot;generate-data&quot; style=&quot;background: #4CAF50; color: white; padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer;&quot;&gt;Generate New Data&lt;/button&gt;
        &lt;span style=&quot;margin-left: 20px;&quot;&gt;Sample size: &lt;/span&gt;
        &lt;input type=&quot;number&quot; id=&quot;sample-size&quot; value=&quot;50&quot; min=&quot;10&quot; max=&quot;200&quot; style=&quot;width: 60px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;label for=&quot;mu-guess&quot;&gt;Estimate of μ: &lt;span id=&quot;mu-guess-value&quot;&gt;0&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;mu-guess&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 300px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;label for=&quot;sigma-guess&quot;&gt;Estimate of σ: &lt;span id=&quot;sigma-guess-value&quot;&gt;1&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
        &lt;input type=&quot;range&quot; id=&quot;sigma-guess&quot; min=&quot;0.1&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1&quot; style=&quot;width: 300px;&quot; /&gt;
    &lt;/div&gt;
    
    &lt;div style=&quot;margin: 15px 0;&quot;&gt;
        &lt;canvas id=&quot;normal-plot&quot; width=&quot;600&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc;&quot;&gt;&lt;/canvas&gt;
    &lt;/div&gt;
    
    &lt;div id=&quot;mle-results&quot; style=&quot;background: #f8f9fa; padding: 10px; border-radius: 4px; margin: 10px 0;&quot;&gt;
        &lt;div&gt;&lt;strong&gt;True data:&lt;/strong&gt; μ = &lt;span id=&quot;true-mu&quot;&gt;1.0&lt;/span&gt;, σ = &lt;span id=&quot;true-sigma&quot;&gt;1.5&lt;/span&gt;&lt;/div&gt;
        &lt;div&gt;&lt;strong&gt;MLE estimate:&lt;/strong&gt; μ̂ = &lt;span id=&quot;mle-mu&quot;&gt;0.95&lt;/span&gt;, σ̂ = &lt;span id=&quot;mle-sigma&quot;&gt;1.48&lt;/span&gt;&lt;/div&gt;
        &lt;div&gt;&lt;strong&gt;Current estimate:&lt;/strong&gt; μ = &lt;span id=&quot;current-mu&quot;&gt;0&lt;/span&gt;, σ = &lt;span id=&quot;current-sigma&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
        &lt;div&gt;&lt;strong&gt;Current log-likelihood:&lt;/strong&gt; &lt;span id=&quot;current-ll&quot;&gt;-75.2&lt;/span&gt;&lt;/div&gt;
        &lt;div&gt;&lt;strong&gt;Maximum log-likelihood:&lt;/strong&gt; &lt;span id=&quot;max-ll&quot;&gt;-72.1&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    const generateBtn = document.getElementById(&apos;generate-data&apos;);
    const sampleSizeInput = document.getElementById(&apos;sample-size&apos;);
    const muGuess = document.getElementById(&apos;mu-guess&apos;);
    const sigmaGuess = document.getElementById(&apos;sigma-guess&apos;);
    const muGuessValue = document.getElementById(&apos;mu-guess-value&apos;);
    const sigmaGuessValue = document.getElementById(&apos;sigma-guess-value&apos;);
    const canvas = document.getElementById(&apos;normal-plot&apos;);
    const ctx = canvas.getContext(&apos;2d&apos;);
    
    let data = [];
    let trueMu = 1.0;
    let trueSigma = 1.5;
    
    function normalRandom(mu, sigma) {
        let u = 0, v = 0;
        while(u === 0) u = Math.random();
        while(v === 0) v = Math.random();
        return Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v) * sigma + mu;
    }
    
    function generateData() {
        const n = parseInt(sampleSizeInput.value);
        trueMu = (Math.random() - 0.5) * 4; // -2 to 2
        trueSigma = 0.5 + Math.random() * 2; // 0.5 to 2.5
        
        data = [];
        for (let i = 0; i &lt; n; i++) {
            data.push(normalRandom(trueMu, trueSigma));
        }
        
        // Compute the MLE
        const mleMu = data.reduce((sum, x) =&gt; sum + x, 0) / data.length;
        const mleSigma = Math.sqrt(data.reduce((sum, x) =&gt; sum + (x - mleMu) ** 2, 0) / data.length);
        
        document.getElementById(&apos;true-mu&apos;).textContent = trueMu.toFixed(2);
        document.getElementById(&apos;true-sigma&apos;).textContent = trueSigma.toFixed(2);
        document.getElementById(&apos;mle-mu&apos;).textContent = mleMu.toFixed(2);
        document.getElementById(&apos;mle-sigma&apos;).textContent = mleSigma.toFixed(2);
        
        plotData();
    }
    
    function logLikelihood(mu, sigma, data) {
        const n = data.length;
        const sumSquares = data.reduce((sum, x) =&gt; sum + (x - mu) ** 2, 0);
        return -n/2 * Math.log(2 * Math.PI) - n * Math.log(sigma) - sumSquares / (2 * sigma ** 2);
    }
    
    function normalPDF(x, mu, sigma) {
        return (1 / (sigma * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * ((x - mu) / sigma) ** 2);
    }
    
    function plotData() {
        if (data.length === 0) return;
        
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        const currentMu = parseFloat(muGuess.value);
        const currentSigma = parseFloat(sigmaGuess.value);
        
        // Find the data range
        const minX = Math.min(...data) - 1;
        const maxX = Math.max(...data) + 1;
        const range = maxX - minX;
        
        // Draw the histogram
        const bins = 20;
        const binWidth = range / bins;
        const binCounts = new Array(bins).fill(0);
        
        data.forEach(x =&gt; {
            const binIndex = Math.floor((x - minX) / binWidth);
            if (binIndex &gt;= 0 &amp;&amp; binIndex &lt; bins) {
                binCounts[binIndex]++;
            }
        });
        
        const maxCount = Math.max(...binCounts);
        
        ctx.fillStyle = &apos;rgba(33, 150, 243, 0.3)&apos;;
        for (let i = 0; i &lt; bins; i++) {
            const x = 50 + (i * binWidth / range) * 500;
            const height = (binCounts[i] / maxCount) * 200;
            const width = (binWidth / range) * 500;
            ctx.fillRect(x, 250 - height, width, height);
        }
        
        // Draw the true distribution curve
        ctx.strokeStyle = &apos;#4CAF50&apos;;
        ctx.lineWidth = 2;
        ctx.beginPath();
        for (let i = 0; i &lt;= 500; i++) {
            const x = minX + (i / 500) * range;
            const y = normalPDF(x, trueMu, trueSigma);
            const plotX = 50 + (i / 500) * 500;
            const plotY = 250 - (y / (1 / (trueSigma * Math.sqrt(2 * Math.PI)))) * 200;
            
            if (i === 0) ctx.moveTo(plotX, plotY);
            else ctx.lineTo(plotX, plotY);
        }
        ctx.stroke();
        
        // Draw the current estimate curve
        ctx.strokeStyle = &apos;#f44336&apos;;
        ctx.lineWidth = 2;
        ctx.setLineDash([5, 5]);
        ctx.beginPath();
        for (let i = 0; i &lt;= 500; i++) {
            const x = minX + (i / 500) * range;
            const y = normalPDF(x, currentMu, currentSigma);
            const plotX = 50 + (i / 500) * 500;
            const plotY = 250 - (y / (1 / (currentSigma * Math.sqrt(2 * Math.PI)))) * 200;
            
            if (i === 0) ctx.moveTo(plotX, plotY);
            else ctx.lineTo(plotX, plotY);
        }
        ctx.stroke();
        ctx.setLineDash([]);
        
        // Draw axes
        ctx.strokeStyle = &apos;#333&apos;;
        ctx.lineWidth = 1;
        ctx.beginPath();
        ctx.moveTo(50, 250);
        ctx.lineTo(550, 250);
        ctx.stroke();
        
        // Update results
        const currentLL = logLikelihood(currentMu, currentSigma, data);
        const mleMu = data.reduce((sum, x) =&gt; sum + x, 0) / data.length;
        const mleSigma = Math.sqrt(data.reduce((sum, x) =&gt; sum + (x - mleMu) ** 2, 0) / data.length);
        const maxLL = logLikelihood(mleMu, mleSigma, data);
        
        document.getElementById(&apos;current-mu&apos;).textContent = currentMu.toFixed(2);
        document.getElementById(&apos;current-sigma&apos;).textContent = currentSigma.toFixed(2);
        document.getElementById(&apos;current-ll&apos;).textContent = currentLL.toFixed(2);
        document.getElementById(&apos;max-ll&apos;).textContent = maxLL.toFixed(2);
        
        // Add the legend
        ctx.fillStyle = &apos;#4CAF50&apos;;
        ctx.fillRect(450, 60, 15, 3);
        ctx.fillStyle = &apos;#333&apos;;
        ctx.font = &apos;12px Arial&apos;;
        ctx.fillText(&apos;True distribution&apos;, 470, 65);
        
        ctx.strokeStyle = &apos;#f44336&apos;;
        ctx.setLineDash([5, 5]);
        ctx.beginPath();
        ctx.moveTo(450, 80);
        ctx.lineTo(465, 80);
        ctx.stroke();
        ctx.setLineDash([]);
        ctx.fillText(&apos;Current estimate&apos;, 470, 85);
    }
    
    function updateDisplay() {
        muGuessValue.textContent = muGuess.value;
        sigmaGuessValue.textContent = sigmaGuess.value;
        plotData();
    }
    
    generateBtn.addEventListener(&apos;click&apos;, generateData);
    muGuess.addEventListener(&apos;input&apos;, updateDisplay);
    sigmaGuess.addEventListener(&apos;input&apos;, updateDisplay);
    sampleSizeInput.addEventListener(&apos;change&apos;, generateData);
    
    // Initialize
    generateData();
});
&lt;/script&gt;

&lt;h3 id=&quot;properties-of-the-mle&quot;&gt;Properties of the MLE&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: As the sample size grows, the MLE converges to the true value of the parameter.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Asymptotic Normality&lt;/strong&gt;: For large samples, the distribution of the MLE is approximately normal.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Asymptotic Efficiency&lt;/strong&gt;: The MLE attains the Cramér-Rao bound, meaning it has the smallest variance among unbiased estimators.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Invariance&lt;/strong&gt;: If \(\hat{\theta}\) is the MLE of \(\theta\), then \(g(\hat{\theta})\) is the MLE of \(g(\theta)\) for an invertible function \(g\) (the property extends to any function \(g\) through the induced likelihood).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;applications-of-the-mle&quot;&gt;Applications of the MLE&lt;/h3&gt;

&lt;h4 id=&quot;1-parameter-estimation&quot;&gt;1. Parameter Estimation&lt;/h4&gt;

&lt;p&gt;The MLE is widely used to estimate parameters in statistical models:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Normal distribution: estimating the mean and variance&lt;/li&gt;
  &lt;li&gt;Poisson distribution: estimating the parameter λ&lt;/li&gt;
  &lt;li&gt;Linear regression: estimating the regression coefficients&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-model-comparison&quot;&gt;2. Model Comparison&lt;/h4&gt;

&lt;p&gt;The likelihood is used to compare different statistical models:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Likelihood Ratio Test&lt;/strong&gt;: compares two nested models&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;AIC/BIC&lt;/strong&gt;: model selection criteria based on the likelihood&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-bayesian-statistics&quot;&gt;3. Bayesian Statistics&lt;/h4&gt;

&lt;p&gt;In Bayesian statistics, the likelihood is combined with a prior distribution to compute the posterior distribution:&lt;/p&gt;

\[P(\theta \mid x) \propto L(\theta \mid x) \cdot P(\theta)\]

&lt;h3 id=&quot;connection-with-optimization&quot;&gt;Connection with Optimization&lt;/h3&gt;

&lt;p&gt;The MLE gives rise to an optimization problem:&lt;/p&gt;

\[\max_{\theta} L(\theta \mid x) \quad \text{or} \quad \max_{\theta} \log L(\theta \mid x)\]

&lt;p&gt;This often leads to:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Unconstrained optimization&lt;/strong&gt;: when there are no constraints on the parameters&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constrained optimization&lt;/strong&gt;: when the parameters must satisfy certain conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex problems&lt;/strong&gt;: for many models the log-likelihood is concave (equivalently, the negative log-likelihood is convex), so maximizing it is a convex problem and guarantees a global optimum&lt;/li&gt;
&lt;/ul&gt;

&lt;div style=&quot;background: #e8f4fd; padding: 15px; border-left: 4px solid #2196F3; margin: 20px 0;&quot;&gt;
&lt;strong&gt;💡 Connection with Convex Optimization:&lt;/strong&gt; Many MLE problems lead to convex optimization, especially for exponential families of distributions. This guarantees that the solution found is globally optimal and that optimization algorithms will converge to the true solution.
&lt;/div&gt;

&lt;h3 id=&quot;a-real-world-example-logistic-regression&quot;&gt;A Real-World Example: Logistic Regression&lt;/h3&gt;

&lt;p&gt;In logistic regression, we model the probability of a binary variable:&lt;/p&gt;

\[P(y = 1 \mid x) = \frac{1}{1 + e^{-(\beta_0 + \beta_1 x)}}\]

&lt;p&gt;&lt;strong&gt;Log-likelihood&lt;/strong&gt; (with \(p_i = P(y_i = 1 \mid x_i)\)):
\(\ell(\beta_0, \beta_1) = \sum_{i=1}^{n} \left[ y_i \log(p_i) + (1-y_i) \log(1-p_i) \right]\)&lt;/p&gt;

&lt;p&gt;This is a concave maximization problem (equivalently, a convex minimization of the negative log-likelihood), which can be solved by gradient descent or Newton’s method.&lt;/p&gt;

&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;strong&gt;likelihood&lt;/strong&gt; measures how well a parameter fits the observed data&lt;/li&gt;
  &lt;li&gt;The &lt;strong&gt;MLE&lt;/strong&gt; finds the parameter that maximizes the likelihood&lt;/li&gt;
  &lt;li&gt;The MLE has many good statistical properties: consistency, efficiency, asymptotic normality&lt;/li&gt;
  &lt;li&gt;The MLE gives rise to optimization problems, many of which are convex&lt;/li&gt;
  &lt;li&gt;Widely used in statistics, machine learning and data science&lt;/li&gt;
&lt;/ul&gt;

&lt;div style=&quot;background: #d4edda; padding: 15px; border-left: 4px solid #28a745; margin: 20px 0;&quot;&gt;
&lt;strong&gt;🎯 Key Point:&lt;/strong&gt; The MLE is an important bridge between statistics and optimization. Understanding the MLE helps you grasp how statistical models are estimated through optimization methods, especially convex optimization.
&lt;/div&gt;

</content>
 </entry>
 
 <entry>
   <title>00-04-02 Common Probability Distributions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_04_02_Common_Probability_Distributions/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_04_02_Common_Probability_Distributions</id>
   <content type="html">&lt;p&gt;Why do logistic regression, ridge regression, and Poisson count models all yield convex optimization problems? The secret lies in the functional form of common probability distributions: Bernoulli, Gaussian, Exponential, and Poisson densities belong to the exponential family, whose negative log-likelihoods are naturally convex functions of their canonical parameters. Recognizing a distribution’s algebraic signature immediately tells you what optimization geometry you are about to face.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-distributions-through-an-optimization-lens&quot;&gt;Key ideas: Distributions Through an Optimization Lens&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Discrete Families (Bernoulli, Binomial, Poisson):&lt;/strong&gt; Model binary classification, trial counts, and rare event arrivals; their log-likelihoods generate cross-entropy and generalized linear model (GLM) losses.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Continuous Families (Gaussian, Exponential, Uniform):&lt;/strong&gt; Gaussian densities yield quadratic (\(\ell_2\)) objectives; Exponential densities model waiting times and yield strictly concave log-likelihoods in rate \(\lambda\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multivariate Normal (\(\mathcal{N}(\mu, \Sigma)\)):&lt;/strong&gt; Links statistics directly to positive definite matrices (\(\Sigma \succ 0\)), Mahalanobis ellipsoids, and precision-matrix estimation in graphical models.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Log-Concavity Connection:&lt;/strong&gt; Most standard densities have concave log-densities, ensuring that maximum likelihood estimation over convex parameter constraints has no spurious local optima.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-concave-log-likelihood-of-an-exponential-distribution&quot;&gt;Worked example: Concave Log-Likelihood of an Exponential Distribution&lt;/h3&gt;

&lt;p&gt;Suppose four independent server failure inter-arrival times are observed: \(x = (1, 3, 2, 6)\) hours, modeled by \(\text{Exponential}(\lambda)\) with density \(p(x \mid \lambda) = \lambda e^{-\lambda x}\) for \(\lambda &amp;gt; 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the joint likelihood and log-likelihood:&lt;/strong&gt;
\(L(\lambda) = \prod_{i=1}^4 \lambda e^{-\lambda x_i} = \lambda^4 e^{-\lambda(1 + 3 + 2 + 6)} = \lambda^4 e^{-12\lambda},\)
\(\ell(\lambda) = \ln L(\lambda) = 4\ln\lambda - 12\lambda.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the first-order optimality condition:&lt;/strong&gt;
\(\ell&apos;(\lambda) = \frac{4}{\lambda} - 12 = 0 \implies \hat{\lambda} = \frac{4}{12} = \frac{1}{3} \text{ failures/hour}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Certify global optimality via the second derivative:&lt;/strong&gt;
\(\ell&apos;&apos;(\lambda) = -\frac{4}{\lambda^2} &amp;lt; 0 \quad \text{for all } \lambda &amp;gt; 0.\)
Because \(\ell(\lambda)\) is strictly concave on \((0, \infty)\), \(\hat{\lambda} = 1/3\) (the reciprocal of the sample mean \(\bar{x} = 3\)) is the unique global maximizer.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;common-probability-distributions&quot;&gt;Common Probability Distributions&lt;/h2&gt;

&lt;p&gt;Understanding key probability distributions is essential for optimization problems in machine learning and statistics. These distributions frequently appear as assumptions in models, priors in Bayesian methods, and error models in regression.&lt;/p&gt;

&lt;h3 id=&quot;1-discrete-distributions&quot;&gt;1. Discrete Distributions&lt;/h3&gt;

&lt;h4 id=&quot;bernoulli-distribution&quot;&gt;Bernoulli Distribution&lt;/h4&gt;

&lt;p&gt;Models a single trial with two outcomes (success/failure).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters&lt;/strong&gt;: \(p \in [0,1]\) (probability of success)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PMF&lt;/strong&gt;: \(P(X = k) = p^k (1-p)^{1-k}\) for \(k \in \{0,1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mean&lt;/strong&gt;: \(\mathbb{E}[X] = p\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variance&lt;/strong&gt;: \(\text{Var}(X) = p(1-p)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applications&lt;/strong&gt;: Binary classification, coin flips, A/B testing&lt;/p&gt;

&lt;h4 id=&quot;binomial-distribution&quot;&gt;Binomial Distribution&lt;/h4&gt;

&lt;p&gt;Models the number of successes in \(n\) independent Bernoulli trials.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters&lt;/strong&gt;: \(n \in \mathbb{N}\) (trials), \(p \in [0,1]\) (success probability)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PMF&lt;/strong&gt;: \(P(X = k) = \binom{n}{k} p^k (1-p)^{n-k}\) for \(k = 0,1,\ldots,n\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mean&lt;/strong&gt;: \(\mathbb{E}[X] = np\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variance&lt;/strong&gt;: \(\text{Var}(X) = np(1-p)\)&lt;/p&gt;

&lt;h4 id=&quot;poisson-distribution&quot;&gt;Poisson Distribution&lt;/h4&gt;

&lt;p&gt;Models the number of events in a fixed interval when events occur independently at a constant rate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters&lt;/strong&gt;: \(\lambda &amp;gt; 0\) (rate parameter)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PMF&lt;/strong&gt;: \(P(X = k) = \frac{\lambda^k e^{-\lambda}}{k!}\) for \(k = 0,1,2,\ldots\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mean&lt;/strong&gt;: \(\mathbb{E}[X] = \lambda\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variance&lt;/strong&gt;: \(\text{Var}(X) = \lambda\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applications&lt;/strong&gt;: Count data, rare events, queueing theory&lt;/p&gt;

&lt;div id=&quot;discrete-distributions-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Interactive Discrete Distributions&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;discreteCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Visualization:&lt;/strong&gt; Probability mass functions of discrete distributions.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Distribution Type&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;discrete-dist&quot; value=&quot;bernoulli&quot; checked=&quot;&quot; /&gt; Bernoulli
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;discrete-dist&quot; value=&quot;binomial&quot; /&gt; Binomial
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;discrete-dist&quot; value=&quot;poisson&quot; /&gt; Poisson
                    &lt;/label&gt;
                &lt;/div&gt;
                
                &lt;div id=&quot;discrete-params&quot;&gt;
                    &lt;div id=&quot;p-param&quot; style=&quot;margin-bottom: 15px;&quot;&gt;
                        &lt;label for=&quot;p-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;p: &lt;span id=&quot;p-value&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;
                        &lt;input type=&quot;range&quot; id=&quot;p-slider&quot; min=&quot;0.1&quot; max=&quot;0.9&quot; step=&quot;0.05&quot; value=&quot;0.5&quot; style=&quot;width: 100%;&quot; /&gt;
                    &lt;/div&gt;
                    
                    &lt;div id=&quot;n-param&quot; style=&quot;margin-bottom: 15px; display: none;&quot;&gt;
                        &lt;label for=&quot;n-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;n: &lt;span id=&quot;n-value&quot;&gt;10&lt;/span&gt;&lt;/label&gt;
                        &lt;input type=&quot;range&quot; id=&quot;n-slider&quot; min=&quot;5&quot; max=&quot;50&quot; step=&quot;1&quot; value=&quot;10&quot; style=&quot;width: 100%;&quot; /&gt;
                    &lt;/div&gt;
                    
                    &lt;div id=&quot;lambda-param&quot; style=&quot;margin-bottom: 15px; display: none;&quot;&gt;
                        &lt;label for=&quot;lambda-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;λ: &lt;span id=&quot;lambda-value&quot;&gt;3.0&lt;/span&gt;&lt;/label&gt;
                        &lt;input type=&quot;range&quot; id=&quot;lambda-slider&quot; min=&quot;0.5&quot; max=&quot;10&quot; step=&quot;0.5&quot; value=&quot;3.0&quot; style=&quot;width: 100%;&quot; /&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                
                &lt;div id=&quot;discrete-stats&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Statistics:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Mean: &lt;span id=&quot;discrete-mean&quot;&gt;0.500&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Variance: &lt;span id=&quot;discrete-variance&quot;&gt;0.250&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Mode: &lt;span id=&quot;discrete-mode&quot;&gt;0 or 1&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;2-continuous-distributions&quot;&gt;2. Continuous Distributions&lt;/h3&gt;

&lt;h4 id=&quot;uniform-distribution&quot;&gt;Uniform Distribution&lt;/h4&gt;

&lt;p&gt;All values in an interval are equally likely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters&lt;/strong&gt;: \(a, b \in \mathbb{R}\) with \(a &amp;lt; b\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt;: \(f(x) = \frac{1}{b-a}\) for \(x \in [a,b]\), 0 otherwise&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mean&lt;/strong&gt;: \(\mathbb{E}[X] = \frac{a+b}{2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variance&lt;/strong&gt;: \(\text{Var}(X) = \frac{(b-a)^2}{12}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applications&lt;/strong&gt;: Random sampling, initialization in algorithms&lt;/p&gt;

&lt;h4 id=&quot;normal-gaussian-distribution&quot;&gt;Normal (Gaussian) Distribution&lt;/h4&gt;

&lt;p&gt;The most important distribution in statistics and optimization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters&lt;/strong&gt;: \(\mu \in \mathbb{R}\) (mean), \(\sigma^2 &amp;gt; 0\) (variance)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt;: \(f(x) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mean&lt;/strong&gt;: \(\mathbb{E}[X] = \mu\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variance&lt;/strong&gt;: \(\text{Var}(X) = \sigma^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Symmetric around \(\mu\)&lt;/li&gt;
  &lt;li&gt;68-95-99.7 rule&lt;/li&gt;
  &lt;li&gt;Central Limit Theorem&lt;/li&gt;
  &lt;li&gt;Maximum entropy for given mean and variance&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;exponential-distribution&quot;&gt;Exponential Distribution&lt;/h4&gt;

&lt;p&gt;Models waiting times between events in a Poisson process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters&lt;/strong&gt;: \(\lambda &amp;gt; 0\) (rate parameter)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt;: \(f(x) = \lambda e^{-\lambda x}\) for \(x \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mean&lt;/strong&gt;: \(\mathbb{E}[X] = \frac{1}{\lambda}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variance&lt;/strong&gt;: \(\text{Var}(X) = \frac{1}{\lambda^2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties&lt;/strong&gt;: Memoryless property&lt;/p&gt;

&lt;h4 id=&quot;beta-distribution&quot;&gt;Beta Distribution&lt;/h4&gt;

&lt;p&gt;Flexible distribution on \([0,1]\), often used for modeling probabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters&lt;/strong&gt;: \(\alpha, \beta &amp;gt; 0\) (shape parameters)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt;: \(f(x) = \frac{\Gamma(\alpha+\beta)}{\Gamma(\alpha)\Gamma(\beta)} x^{\alpha-1}(1-x)^{\beta-1}\) for \(x \in [0,1]\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mean&lt;/strong&gt;: \(\mathbb{E}[X] = \frac{\alpha}{\alpha+\beta}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variance&lt;/strong&gt;: \(\text{Var}(X) = \frac{\alpha\beta}{(\alpha+\beta)^2(\alpha+\beta+1)}\)&lt;/p&gt;

&lt;div id=&quot;continuous-distributions-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Interactive Continuous Distributions&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;continuousCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Visualization:&lt;/strong&gt; Probability density functions of continuous distributions.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Distribution Type&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;continuous-dist&quot; value=&quot;uniform&quot; checked=&quot;&quot; /&gt; Uniform
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;continuous-dist&quot; value=&quot;normal&quot; /&gt; Normal
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;continuous-dist&quot; value=&quot;exponential&quot; /&gt; Exponential
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;continuous-dist&quot; value=&quot;beta&quot; /&gt; Beta
                    &lt;/label&gt;
                &lt;/div&gt;
                
                &lt;div id=&quot;continuous-params&quot;&gt;
                    &lt;div id=&quot;uniform-params&quot;&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;a-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;a: &lt;span id=&quot;a-value&quot;&gt;0&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;a-slider&quot; min=&quot;-2&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;b-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;b: &lt;span id=&quot;b-value&quot;&gt;1&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;b-slider&quot; min=&quot;0.5&quot; max=&quot;4&quot; step=&quot;0.1&quot; value=&quot;1&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    
                    &lt;div id=&quot;normal-params&quot; style=&quot;display: none;&quot;&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;mu-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;μ: &lt;span id=&quot;mu-value&quot;&gt;0&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;mu-slider&quot; min=&quot;-3&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;sigma-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;σ: &lt;span id=&quot;sigma-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;sigma-slider&quot; min=&quot;0.5&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    
                    &lt;div id=&quot;exponential-params&quot; style=&quot;display: none;&quot;&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;exp-lambda-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;λ: &lt;span id=&quot;exp-lambda-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;exp-lambda-slider&quot; min=&quot;0.2&quot; max=&quot;3&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    
                    &lt;div id=&quot;beta-params&quot; style=&quot;display: none;&quot;&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;alpha-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;α: &lt;span id=&quot;alpha-value&quot;&gt;2&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;alpha-slider&quot; min=&quot;0.5&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;2&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                        &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                            &lt;label for=&quot;beta-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;β: &lt;span id=&quot;beta-value&quot;&gt;2&lt;/span&gt;&lt;/label&gt;
                            &lt;input type=&quot;range&quot; id=&quot;beta-slider&quot; min=&quot;0.5&quot; max=&quot;5&quot; step=&quot;0.1&quot; value=&quot;2&quot; style=&quot;width: 100%;&quot; /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                
                &lt;div id=&quot;continuous-stats&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Statistics:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Mean: &lt;span id=&quot;continuous-mean&quot;&gt;0.500&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Variance: &lt;span id=&quot;continuous-variance&quot;&gt;0.083&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Support: &lt;span id=&quot;continuous-support&quot;&gt;[0, 1]&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;3-multivariate-distributions&quot;&gt;3. Multivariate Distributions&lt;/h3&gt;

&lt;h4 id=&quot;multivariate-normal-distribution&quot;&gt;Multivariate Normal Distribution&lt;/h4&gt;

&lt;p&gt;Extension of the normal distribution to multiple dimensions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters&lt;/strong&gt;: \(\boldsymbol{\mu} \in \mathbb{R}^d\) (mean vector), \(\boldsymbol{\Sigma} \in \mathbb{R}^{d \times d}\) (covariance matrix, positive definite)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;PDF&lt;/strong&gt;: $$f(\mathbf{x}) = \frac{1}{(2\pi)^{d/2}&lt;/td&gt;
      &lt;td&gt;\boldsymbol{\Sigma}&lt;/td&gt;
      &lt;td&gt;^{1/2}} \exp\left(-\frac{1}{2}(\mathbf{x}-\boldsymbol{\mu})^T\boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu})\right)$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Properties&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Marginal distributions are normal&lt;/li&gt;
  &lt;li&gt;Linear combinations are normal&lt;/li&gt;
  &lt;li&gt;Conditional distributions are normal&lt;/li&gt;
&lt;/ul&gt;

&lt;div id=&quot;multivariate-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f0f8ff;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Multivariate Normal Distribution&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;multivariateCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;2D Visualization:&lt;/strong&gt; Contour plot of bivariate normal distribution. Samples shown as dots.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Parameters&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;mu1-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;μ₁: &lt;span id=&quot;mu1-value&quot;&gt;0.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;mu1-slider&quot; min=&quot;-2&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;mu2-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;μ₂: &lt;span id=&quot;mu2-value&quot;&gt;0.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;mu2-slider&quot; min=&quot;-2&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;sigma1-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;σ₁: &lt;span id=&quot;sigma1-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;sigma1-slider&quot; min=&quot;0.5&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;sigma2-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;σ₂: &lt;span id=&quot;sigma2-value&quot;&gt;1.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;sigma2-slider&quot; min=&quot;0.5&quot; max=&quot;2&quot; step=&quot;0.1&quot; value=&quot;1.0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;rho-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;ρ (correlation): &lt;span id=&quot;rho-value&quot;&gt;0.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;rho-slider&quot; min=&quot;-0.9&quot; max=&quot;0.9&quot; step=&quot;0.1&quot; value=&quot;0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;button id=&quot;generate-samples&quot; style=&quot;width: 100%; padding: 10px; background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 15px;&quot;&gt;Generate Samples&lt;/button&gt;
                
                &lt;div id=&quot;multivariate-stats&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Covariance Matrix:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Σ₁₁: &lt;span id=&quot;cov11&quot;&gt;1.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Σ₁₂: &lt;span id=&quot;cov12&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Σ₂₂: &lt;span id=&quot;cov22&quot;&gt;1.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Det(Σ): &lt;span id=&quot;det-cov&quot;&gt;1.000&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;4-applications-in-optimization&quot;&gt;4. Applications in Optimization&lt;/h3&gt;

&lt;h4 id=&quot;maximum-likelihood-estimation&quot;&gt;Maximum Likelihood Estimation&lt;/h4&gt;
&lt;p&gt;Many optimization problems involve finding parameters that maximize the likelihood of observed data under a specific distribution:&lt;/p&gt;

\[\hat{\theta} = \arg\max_\theta \prod_{i=1}^n f(x_i; \theta)\]

&lt;h4 id=&quot;bayesian-optimization&quot;&gt;Bayesian Optimization&lt;/h4&gt;
&lt;p&gt;Prior distributions encode beliefs about parameters before seeing data:&lt;/p&gt;

\[p(\theta|data) \propto p(data|\theta) \cdot p(\theta)\]

&lt;h4 id=&quot;regularization&quot;&gt;Regularization&lt;/h4&gt;
&lt;p&gt;Distributions can be used as priors to regularize optimization problems:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;L2 regularization ↔ Gaussian prior&lt;/li&gt;
  &lt;li&gt;L1 regularization ↔ Laplace prior&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;stochastic-optimization&quot;&gt;Stochastic Optimization&lt;/h4&gt;
&lt;p&gt;Distributions model noise and uncertainty in objective functions and constraints.&lt;/p&gt;

&lt;h3 id=&quot;key-insights-for-optimization&quot;&gt;Key Insights for Optimization&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Model Selection&lt;/strong&gt;: Choose distributions that match your data’s characteristics&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parameter Estimation&lt;/strong&gt;: Use MLE or Bayesian methods to estimate distribution parameters&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Uncertainty Quantification&lt;/strong&gt;: Distributions provide natural ways to quantify uncertainty&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization&lt;/strong&gt;: Prior distributions can prevent overfitting&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational Efficiency&lt;/strong&gt;: Some distributions have closed-form solutions for common operations&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Understanding these distributions and their properties is crucial for formulating and solving optimization problems in machine learning, statistics, and engineering applications.&lt;/p&gt;

&lt;script&gt;
// Discrete Distributions Demo
class DiscreteDistributionsDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;discreteCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.distType = &apos;bernoulli&apos;;
        this.params = { p: 0.5, n: 10, lambda: 3.0 };
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const radios = document.querySelectorAll(&apos;input[name=&quot;discrete-dist&quot;]&apos;);
        const pSlider = document.getElementById(&apos;p-slider&apos;);
        const nSlider = document.getElementById(&apos;n-slider&apos;);
        const lambdaSlider = document.getElementById(&apos;lambda-slider&apos;);
        
        radios.forEach(radio =&gt; {
            radio.addEventListener(&apos;change&apos;, (e) =&gt; {
                this.distType = e.target.value;
                this.updateParameterVisibility();
                this.updateStats();
                this.draw();
            });
        });
        
        pSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.params.p = parseFloat(e.target.value);
            document.getElementById(&apos;p-value&apos;).textContent = this.params.p.toFixed(1);
            this.updateStats();
            this.draw();
        });
        
        nSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.params.n = parseInt(e.target.value);
            document.getElementById(&apos;n-value&apos;).textContent = this.params.n;
            this.updateStats();
            this.draw();
        });
        
        lambdaSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.params.lambda = parseFloat(e.target.value);
            document.getElementById(&apos;lambda-value&apos;).textContent = this.params.lambda.toFixed(1);
            this.updateStats();
            this.draw();
        });
        
        this.updateParameterVisibility();
        this.updateStats();
    }
    
    updateParameterVisibility() {
        document.getElementById(&apos;p-param&apos;).style.display = 
            (this.distType === &apos;bernoulli&apos; || this.distType === &apos;binomial&apos;) ? &apos;block&apos; : &apos;none&apos;;
        document.getElementById(&apos;n-param&apos;).style.display = 
            this.distType === &apos;binomial&apos; ? &apos;block&apos; : &apos;none&apos;;
        document.getElementById(&apos;lambda-param&apos;).style.display = 
            this.distType === &apos;poisson&apos; ? &apos;block&apos; : &apos;none&apos;;
    }
    
    updateStats() {
        let mean, variance, mode;
        
        switch(this.distType) {
            case &apos;bernoulli&apos;:
                mean = this.params.p;
                variance = this.params.p * (1 - this.params.p);
                mode = this.params.p &gt; 0.5 ? &apos;1&apos; : (this.params.p &lt; 0.5 ? &apos;0&apos; : &apos;0 or 1&apos;);
                break;
            case &apos;binomial&apos;:
                mean = this.params.n * this.params.p;
                variance = this.params.n * this.params.p * (1 - this.params.p);
                mode = Math.floor((this.params.n + 1) * this.params.p).toString();
                break;
            case &apos;poisson&apos;:
                mean = this.params.lambda;
                variance = this.params.lambda;
                mode = Math.floor(this.params.lambda).toString();
                break;
        }
        
        document.getElementById(&apos;discrete-mean&apos;).textContent = mean.toFixed(3);
        document.getElementById(&apos;discrete-variance&apos;).textContent = variance.toFixed(3);
        document.getElementById(&apos;discrete-mode&apos;).textContent = mode;
    }
    
    factorial(n) {
        if (n &lt;= 1) return 1;
        return n * this.factorial(n - 1);
    }
    
    binomialCoeff(n, k) {
        if (k &gt; n) return 0;
        return this.factorial(n) / (this.factorial(k) * this.factorial(n - k));
    }
    
    getProbability(k) {
        switch(this.distType) {
            case &apos;bernoulli&apos;:
                return k === 0 ? (1 - this.params.p) : (k === 1 ? this.params.p : 0);
            case &apos;binomial&apos;:
                if (k &lt; 0 || k &gt; this.params.n) return 0;
                return this.binomialCoeff(this.params.n, k) * 
                       Math.pow(this.params.p, k) * 
                       Math.pow(1 - this.params.p, this.params.n - k);
            case &apos;poisson&apos;:
                if (k &lt; 0) return 0;
                return Math.pow(this.params.lambda, k) * Math.exp(-this.params.lambda) / this.factorial(k);
        }
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        const marginX = 50;
        const marginY = 50;
        const plotWidth = this.width - 2 * marginX;
        const plotHeight = this.height - 2 * marginY;
        
        // Draw axes
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        this.ctx.beginPath();
        this.ctx.moveTo(marginX, this.height - marginY);
        this.ctx.lineTo(this.width - marginX, this.height - marginY);
        this.ctx.moveTo(marginX, marginY);
        this.ctx.lineTo(marginX, this.height - marginY);
        this.ctx.stroke();
        
        // Determine range
        let maxK;
        switch(this.distType) {
            case &apos;bernoulli&apos;: maxK = 1; break;
            case &apos;binomial&apos;: maxK = this.params.n; break;
            case &apos;poisson&apos;: maxK = Math.min(20, this.params.lambda + 3 * Math.sqrt(this.params.lambda)); break;
        }
        
        // Find max probability for scaling
        let maxProb = 0;
        for (let k = 0; k &lt;= maxK; k++) {
            maxProb = Math.max(maxProb, this.getProbability(k));
        }
        
        // Draw bars
        this.ctx.fillStyle = &apos;#2196f3&apos;;
        const barWidth = plotWidth / (maxK + 2);
        
        for (let k = 0; k &lt;= maxK; k++) {
            const prob = this.getProbability(k);
            const x = marginX + (k + 0.5) * barWidth;
            const height = (prob / maxProb) * plotHeight * 0.8;
            const y = this.height - marginY - height;
            
            this.ctx.fillRect(x - barWidth * 0.3, y, barWidth * 0.6, height);
            
            // Label
            this.ctx.fillStyle = &apos;#000&apos;;
            this.ctx.font = &apos;10px Arial&apos;;
            this.ctx.textAlign = &apos;center&apos;;
            this.ctx.fillText(k.toString(), x, this.height - marginY + 15);
            this.ctx.fillText(prob.toFixed(3), x, y - 5);
            this.ctx.fillStyle = &apos;#2196f3&apos;;
        }
        
        // Labels
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;center&apos;;
        this.ctx.fillText(&apos;k&apos;, this.width / 2, this.height - 10);
        
        this.ctx.save();
        this.ctx.translate(15, this.height / 2);
        this.ctx.rotate(-Math.PI / 2);
        this.ctx.fillText(&apos;P(X = k)&apos;, 0, 0);
        this.ctx.restore();
    }
}

// Continuous Distributions Demo
class ContinuousDistributionsDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;continuousCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.distType = &apos;uniform&apos;;
        this.params = { a: 0, b: 1, mu: 0, sigma: 1, lambda: 1, alpha: 2, beta: 2 };
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const radios = document.querySelectorAll(&apos;input[name=&quot;continuous-dist&quot;]&apos;);
        
        radios.forEach(radio =&gt; {
            radio.addEventListener(&apos;change&apos;, (e) =&gt; {
                this.distType = e.target.value;
                this.updateParameterVisibility();
                this.updateStats();
                this.draw();
            });
        });
        
        // Setup all sliders
        const sliders = [&apos;a&apos;, &apos;b&apos;, &apos;mu&apos;, &apos;sigma&apos;, &apos;exp-lambda&apos;, &apos;alpha&apos;, &apos;beta&apos;];
        sliders.forEach(slider =&gt; {
            const element = document.getElementById(slider + &apos;-slider&apos;);
            if (element) {
                element.addEventListener(&apos;input&apos;, (e) =&gt; {
                    const value = parseFloat(e.target.value);
                    const param = slider === &apos;exp-lambda&apos; ? &apos;lambda&apos; : slider;
                    this.params[param] = value;
                    
                    const valueSpan = document.getElementById(slider + &apos;-value&apos;);
                    if (valueSpan) {
                        valueSpan.textContent = value.toFixed(1);
                    }
                    
                    this.updateStats();
                    this.draw();
                });
            }
        });
        
        this.updateParameterVisibility();
        this.updateStats();
    }
    
    updateParameterVisibility() {
        document.getElementById(&apos;uniform-params&apos;).style.display = 
            this.distType === &apos;uniform&apos; ? &apos;block&apos; : &apos;none&apos;;
        document.getElementById(&apos;normal-params&apos;).style.display = 
            this.distType === &apos;normal&apos; ? &apos;block&apos; : &apos;none&apos;;
        document.getElementById(&apos;exponential-params&apos;).style.display = 
            this.distType === &apos;exponential&apos; ? &apos;block&apos; : &apos;none&apos;;
        document.getElementById(&apos;beta-params&apos;).style.display = 
            this.distType === &apos;beta&apos; ? &apos;block&apos; : &apos;none&apos;;
    }
    
    updateStats() {
        let mean, variance, support;
        
        switch(this.distType) {
            case &apos;uniform&apos;:
                mean = (this.params.a + this.params.b) / 2;
                variance = Math.pow(this.params.b - this.params.a, 2) / 12;
                support = `[${this.params.a}, ${this.params.b}]`;
                break;
            case &apos;normal&apos;:
                mean = this.params.mu;
                variance = this.params.sigma * this.params.sigma;
                support = &apos;(-∞, ∞)&apos;;
                break;
            case &apos;exponential&apos;:
                mean = 1 / this.params.lambda;
                variance = 1 / (this.params.lambda * this.params.lambda);
                support = &apos;[0, ∞)&apos;;
                break;
            case &apos;beta&apos;:
                mean = this.params.alpha / (this.params.alpha + this.params.beta);
                variance = (this.params.alpha * this.params.beta) / 
                          (Math.pow(this.params.alpha + this.params.beta, 2) * 
                           (this.params.alpha + this.params.beta + 1));
                support = &apos;[0, 1]&apos;;
                break;
        }
        
        document.getElementById(&apos;continuous-mean&apos;).textContent = mean.toFixed(3);
        document.getElementById(&apos;continuous-variance&apos;).textContent = variance.toFixed(3);
        document.getElementById(&apos;continuous-support&apos;).textContent = support;
    }
    
    gamma(z) {
        // Stirling&apos;s approximation for gamma function
        if (z &lt; 0.5) return Math.PI / (Math.sin(Math.PI * z) * this.gamma(1 - z));
        z -= 1;
        let x = 0.99999999999980993;
        const p = [676.5203681218851, -1259.1392167224028, 771.32342877765313,
                  -176.61502916214059, 12.507343278686905, -0.13857109526572012,
                  9.9843695780195716e-6, 1.5056327351493116e-7];
        for (let i = 0; i &lt; p.length; i++) {
            x += p[i] / (z + i + 1);
        }
        const t = z + p.length - 0.5;
        return Math.sqrt(2 * Math.PI) * Math.pow(t, z + 0.5) * Math.exp(-t) * x;
    }
    
    getPDF(x) {
        switch(this.distType) {
            case &apos;uniform&apos;:
                return (x &gt;= this.params.a &amp;&amp; x &lt;= this.params.b) ? 
                       1 / (this.params.b - this.params.a) : 0;
            case &apos;normal&apos;:
                return Math.exp(-0.5 * Math.pow((x - this.params.mu) / this.params.sigma, 2)) / 
                       (this.params.sigma * Math.sqrt(2 * Math.PI));
            case &apos;exponential&apos;:
                return x &gt;= 0 ? this.params.lambda * Math.exp(-this.params.lambda * x) : 0;
            case &apos;beta&apos;:
                if (x &lt; 0 || x &gt; 1) return 0;
                const B = this.gamma(this.params.alpha) * this.gamma(this.params.beta) / 
                         this.gamma(this.params.alpha + this.params.beta);
                return Math.pow(x, this.params.alpha - 1) * Math.pow(1 - x, this.params.beta - 1) / B;
        }
    }
    
    getRange() {
        switch(this.distType) {
            case &apos;uniform&apos;: return [this.params.a - 0.5, this.params.b + 0.5];
            case &apos;normal&apos;: return [this.params.mu - 4 * this.params.sigma, this.params.mu + 4 * this.params.sigma];
            case &apos;exponential&apos;: return [0, 5 / this.params.lambda];
            case &apos;beta&apos;: return [0, 1];
        }
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        const marginX = 50;
        const marginY = 50;
        const plotWidth = this.width - 2 * marginX;
        const plotHeight = this.height - 2 * marginY;
        
        // Draw axes
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        this.ctx.beginPath();
        this.ctx.moveTo(marginX, this.height - marginY);
        this.ctx.lineTo(this.width - marginX, this.height - marginY);
        this.ctx.moveTo(marginX, marginY);
        this.ctx.lineTo(marginX, this.height - marginY);
        this.ctx.stroke();
        
        const [minX, maxX] = this.getRange();
        
        // Find max PDF for scaling
        let maxPDF = 0;
        for (let i = 0; i &lt;= 200; i++) {
            const x = minX + (maxX - minX) * i / 200;
            maxPDF = Math.max(maxPDF, this.getPDF(x));
        }
        
        // Draw PDF curve
        this.ctx.strokeStyle = &apos;#2196f3&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        
        for (let i = 0; i &lt;= 200; i++) {
            const x = minX + (maxX - minX) * i / 200;
            const pdf = this.getPDF(x);
            const plotX = marginX + (x - minX) / (maxX - minX) * plotWidth;
            const plotY = this.height - marginY - (pdf / maxPDF) * plotHeight * 0.8;
            
            if (i === 0) {
                this.ctx.moveTo(plotX, plotY);
            } else {
                this.ctx.lineTo(plotX, plotY);
            }
        }
        this.ctx.stroke();
        
        // Labels
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;center&apos;;
        this.ctx.fillText(&apos;x&apos;, this.width / 2, this.height - 10);
        
        this.ctx.save();
        this.ctx.translate(15, this.height / 2);
        this.ctx.rotate(-Math.PI / 2);
        this.ctx.fillText(&apos;f(x)&apos;, 0, 0);
        this.ctx.restore();
    }
}

// Multivariate Normal Demo
class MultivariateDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;multivariateCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.params = { mu1: 0, mu2: 0, sigma1: 1, sigma2: 1, rho: 0 };
        this.samples = [];
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const sliders = [&apos;mu1&apos;, &apos;mu2&apos;, &apos;sigma1&apos;, &apos;sigma2&apos;, &apos;rho&apos;];
        
        sliders.forEach(slider =&gt; {
            const element = document.getElementById(slider + &apos;-slider&apos;);
            element.addEventListener(&apos;input&apos;, (e) =&gt; {
                this.params[slider] = parseFloat(e.target.value);
                document.getElementById(slider + &apos;-value&apos;).textContent = this.params[slider].toFixed(1);
                this.updateStats();
                this.draw();
            });
        });
        
        document.getElementById(&apos;generate-samples&apos;).addEventListener(&apos;click&apos;, () =&gt; {
            this.generateSamples();
            this.draw();
        });
        
        this.updateStats();
    }
    
    updateStats() {
        const cov11 = this.params.sigma1 * this.params.sigma1;
        const cov12 = this.params.rho * this.params.sigma1 * this.params.sigma2;
        const cov22 = this.params.sigma2 * this.params.sigma2;
        const det = cov11 * cov22 - cov12 * cov12;
        
        document.getElementById(&apos;cov11&apos;).textContent = cov11.toFixed(3);
        document.getElementById(&apos;cov12&apos;).textContent = cov12.toFixed(3);
        document.getElementById(&apos;cov22&apos;).textContent = cov22.toFixed(3);
        document.getElementById(&apos;det-cov&apos;).textContent = det.toFixed(3);
    }
    
    generateSamples() {
        this.samples = [];
        const n = 100;
        
        for (let i = 0; i &lt; n; i++) {
            // Box-Muller transform
            const u1 = Math.random();
            const u2 = Math.random();
            const z1 = Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
            const z2 = Math.sqrt(-2 * Math.log(u1)) * Math.sin(2 * Math.PI * u2);
            
            // Transform to correlated normal
            const x1 = this.params.mu1 + this.params.sigma1 * z1;
            const x2 = this.params.mu2 + this.params.sigma2 * (this.params.rho * z1 + Math.sqrt(1 - this.params.rho * this.params.rho) * z2);
            
            this.samples.push([x1, x2]);
        }
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        const marginX = 50;
        const marginY = 50;
        const plotWidth = this.width - 2 * marginX;
        const plotHeight = this.height - 2 * marginY;
        
        // Draw axes
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        this.ctx.beginPath();
        this.ctx.moveTo(marginX, this.height - marginY);
        this.ctx.lineTo(this.width - marginX, this.height - marginY);
        this.ctx.moveTo(marginX, marginY);
        this.ctx.lineTo(marginX, this.height - marginY);
        this.ctx.stroke();
        
        // Draw contour ellipses
        const levels = [0.5, 1, 1.5, 2];
        const colors = [&apos;#ff9999&apos;, &apos;#ff6666&apos;, &apos;#ff3333&apos;, &apos;#ff0000&apos;];
        
        levels.forEach((level, idx) =&gt; {
            this.ctx.strokeStyle = colors[idx];
            this.ctx.lineWidth = 1;
            this.ctx.beginPath();
            
            const a = level * this.params.sigma1;
            const b = level * this.params.sigma2;
            const angle = 0.5 * Math.atan2(2 * this.params.rho * this.params.sigma1 * this.params.sigma2,
                                          this.params.sigma1 * this.params.sigma1 - this.params.sigma2 * this.params.sigma2);
            
            for (let i = 0; i &lt;= 100; i++) {
                const t = 2 * Math.PI * i / 100;
                const x = a * Math.cos(t) * Math.cos(angle) - b * Math.sin(t) * Math.sin(angle) + this.params.mu1;
                const y = a * Math.cos(t) * Math.sin(angle) + b * Math.sin(t) * Math.cos(angle) + this.params.mu2;
                
                const plotX = marginX + (x + 4) / 8 * plotWidth;
                const plotY = this.height - marginY - (y + 4) / 8 * plotHeight;
                
                if (i === 0) {
                    this.ctx.moveTo(plotX, plotY);
                } else {
                    this.ctx.lineTo(plotX, plotY);
                }
            }
            this.ctx.stroke();
        });
        
        // Draw samples
        if (this.samples.length &gt; 0) {
            this.ctx.fillStyle = &apos;#2196f3&apos;;
            this.samples.forEach(([x1, x2]) =&gt; {
                const plotX = marginX + (x1 + 4) / 8 * plotWidth;
                const plotY = this.height - marginY - (x2 + 4) / 8 * plotHeight;
                
                if (plotX &gt;= marginX &amp;&amp; plotX &lt;= this.width - marginX &amp;&amp;
                    plotY &gt;= marginY &amp;&amp; plotY &lt;= this.height - marginY) {
                    this.ctx.beginPath();
                    this.ctx.arc(plotX, plotY, 2, 0, 2 * Math.PI);
                    this.ctx.fill();
                }
            });
        }
        
        // Draw mean point
        const meanX = marginX + (this.params.mu1 + 4) / 8 * plotWidth;
        const meanY = this.height - marginY - (this.params.mu2 + 4) / 8 * plotHeight;
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.beginPath();
        this.ctx.arc(meanX, meanY, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Labels
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;center&apos;;
        this.ctx.fillText(&apos;X₁&apos;, this.width / 2, this.height - 10);
        
        this.ctx.save();
        this.ctx.translate(15, this.height / 2);
        this.ctx.rotate(-Math.PI / 2);
        this.ctx.fillText(&apos;X₂&apos;, 0, 0);
        this.ctx.restore();
    }
}

// Initialize when DOM is loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    new DiscreteDistributionsDemo();
    new ContinuousDistributionsDemo();
    new MultivariateDemo();
});
&lt;/script&gt;

&lt;style&gt;
input[type=&quot;range&quot;] {
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    background: #ddd;
    outline: none;
    border-radius: 5px;
}

input[type=&quot;range&quot;]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
}

input[type=&quot;range&quot;]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

canvas {
    border-radius: 5px;
}

.demo-container {
    margin: 20px 0;
}
&lt;/style&gt;

</content>
 </entry>
 
 <entry>
   <title>00-04-01 Basic Probability Theory</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_04_01_Basic_Probability_Theory/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_04_01_Basic_Probability_Theory</id>
   <content type="html">&lt;p&gt;Suppose a factory sensor flags a turbine blade as defective with 90% sensitivity and a 10% false-alarm rate, while true defects occur in only 5% of blades. Should you shut down the production line immediately? Intuition often misfires on base rates, whereas Kolmogorov’s probability axioms and Bayes’ theorem give the exact posterior probability needed to weigh shutdown costs against failure risks in an optimization decision.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-axiomatic-probability-for-decision-making&quot;&gt;Key ideas: Axiomatic Probability for Decision-Making&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sample Space, Events &amp;amp; Kolmogorov Axioms:&lt;/strong&gt; Non-negativity, unit total probability, and countable additivity enforce mathematical consistency across all probabilistic models and chance constraints.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conditional Probability &amp;amp; Law of Total Probability:&lt;/strong&gt; Decompose complex uncertainties across mutually exclusive scenarios via \(P(A) = \sum_i P(A \mid B_i)P(B_i)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bayes’ Theorem:&lt;/strong&gt; Updates prior beliefs into posterior probabilities after observing data—the cornerstone of Bayesian inference, MAP estimation, and online decision-making.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Expectation &amp;amp; Variance:&lt;/strong&gt; Summarize random payoffs and risk; in stochastic optimization, \(\mathbb{E}[X]\) often drives the objective while \(\text{Var}(X)\) enters risk-aversion penalties.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-bayes-theorem-on-a-rare-defect-sensor-alarm&quot;&gt;Worked example: Bayes’ Theorem on a Rare-Defect Sensor Alarm&lt;/h3&gt;

&lt;p&gt;Let \(D\) be the event that a blade is defective (\(P(D) = 0.05\), so \(P(D^c) = 0.95\)), and let \(+\) be a positive alarm with \(P(+ \mid D) = 0.90\) and \(P(+ \mid D^c) = 0.10\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the total probability of an alarm (Law of Total Probability):&lt;/strong&gt;
\(P(+) = P(+ \mid D)P(D) + P(+ \mid D^c)P(D^c) = (0.90)(0.05) + (0.10)(0.95) = 0.045 + 0.095 = 0.14.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply Bayes’ theorem for the posterior defect probability:&lt;/strong&gt;
\(P(D \mid +) = \frac{P(+ \mid D)P(D)}{P(+)} = \frac{0.045}{0.14} = \frac{9}{28} \approx 0.3214 \; (32.14\%).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interpret for optimization:&lt;/strong&gt; Even after a positive alarm, there is still a \(67.86\%\) chance the blade is healthy. A cost-minimizing policy therefore compares the expected failure cost (\(0.3214 \times C_{\text{fail}}\)) against the inspection/shutdown cost (\(C_{\text{inspect}}\)) rather than treating the alarm as certainty.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;basic-probability-theory&quot;&gt;Basic Probability Theory&lt;/h2&gt;

&lt;p&gt;Probability theory provides the mathematical framework for reasoning about uncertainty, which is fundamental to many optimization problems in machine learning and data science.&lt;/p&gt;

&lt;h3 id=&quot;1-sample-space-and-events&quot;&gt;1. Sample Space and Events&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Sample Space (Ω)&lt;/strong&gt;: The set of all possible outcomes of an experiment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event (A)&lt;/strong&gt;: A subset of the sample space representing a collection of outcomes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Coin flip: Ω = {H, T}&lt;/li&gt;
  &lt;li&gt;Die roll: Ω = {1, 2, 3, 4, 5, 6}&lt;/li&gt;
  &lt;li&gt;Continuous: Ω = [0, 1] for uniform random variable&lt;/li&gt;
&lt;/ul&gt;

&lt;div id=&quot;sample-space-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Interactive Sample Space Visualization&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;sampleSpaceCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Visualization:&lt;/strong&gt; Click to generate random samples. Different colors represent different events.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Experiment Type&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;experiment&quot; value=&quot;coin&quot; checked=&quot;&quot; /&gt; Coin Flip
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;experiment&quot; value=&quot;dice&quot; /&gt; Dice Roll
                    &lt;/label&gt;
                    &lt;label style=&quot;display: block; margin-bottom: 10px;&quot;&gt;
                        &lt;input type=&quot;radio&quot; name=&quot;experiment&quot; value=&quot;uniform&quot; /&gt; Uniform [0,1]
                    &lt;/label&gt;
                &lt;/div&gt;
                
                &lt;button id=&quot;generate-sample&quot; style=&quot;width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 10px;&quot;&gt;Generate Sample&lt;/button&gt;
                &lt;button id=&quot;clear-samples&quot; style=&quot;width: 100%; padding: 8px; background: #6c757d; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 15px;&quot;&gt;Clear&lt;/button&gt;
                
                &lt;div id=&quot;sample-stats&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Statistics:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;Total samples: &lt;span id=&quot;total-samples&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Event A: &lt;span id=&quot;event-a-count&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Event B: &lt;span id=&quot;event-b-count&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(A) ≈ &lt;span id=&quot;prob-a&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(B) ≈ &lt;span id=&quot;prob-b&quot;&gt;0.000&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;2-probability-axioms-kolmogorov-axioms&quot;&gt;2. Probability Axioms (Kolmogorov Axioms)&lt;/h3&gt;

&lt;p&gt;For any probability measure P, the following axioms must hold:&lt;/p&gt;

&lt;h4 id=&quot;axiom-1-non-negativity&quot;&gt;Axiom 1: Non-negativity&lt;/h4&gt;
&lt;p&gt;\(P(A) \geq 0 \text{ for all events } A\)&lt;/p&gt;

&lt;h4 id=&quot;axiom-2-normalization&quot;&gt;Axiom 2: Normalization&lt;/h4&gt;
&lt;p&gt;\(P(\Omega) = 1\)&lt;/p&gt;

&lt;h4 id=&quot;axiom-3-countable-additivity&quot;&gt;Axiom 3: Countable Additivity&lt;/h4&gt;
&lt;p&gt;For mutually exclusive events \(A_1, A_2, \ldots\):
\(P\left(\bigcup_{i=1}^{\infty} A_i\right) = \sum_{i=1}^{\infty} P(A_i)\)&lt;/p&gt;

&lt;h3 id=&quot;3-basic-properties-and-rules&quot;&gt;3. Basic Properties and Rules&lt;/h3&gt;

&lt;h4 id=&quot;complement-rule&quot;&gt;Complement Rule&lt;/h4&gt;
&lt;p&gt;\(P(A^c) = 1 - P(A)\)&lt;/p&gt;

&lt;h4 id=&quot;addition-rule&quot;&gt;Addition Rule&lt;/h4&gt;
&lt;p&gt;For any two events A and B:
\(P(A \cup B) = P(A) + P(B) - P(A \cap B)\)&lt;/p&gt;

&lt;h4 id=&quot;multiplication-rule&quot;&gt;Multiplication Rule&lt;/h4&gt;
&lt;p&gt;\(P(A \cap B) = P(A|B) \cdot P(B) = P(B|A) \cdot P(A)\)&lt;/p&gt;

&lt;h3 id=&quot;4-conditional-probability&quot;&gt;4. Conditional Probability&lt;/h3&gt;

&lt;p&gt;The probability of event A given that event B has occurred:&lt;/p&gt;

\[P(A|B) = \frac{P(A \cap B)}{P(B)}, \quad P(B) &amp;gt; 0\]

&lt;p&gt;&lt;strong&gt;Interpretation&lt;/strong&gt;: Conditional probability updates our belief about A when we have information about B.&lt;/p&gt;

&lt;div id=&quot;conditional-prob-demo&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f9f9f9;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Conditional Probability Visualization&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;conditionalCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;Venn Diagram:&lt;/strong&gt; Blue circle is event A, red circle is event B. Purple intersection shows A ∩ B.
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;Adjust Probabilities&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;prob-a-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;P(A): &lt;span id=&quot;prob-a-value&quot;&gt;0.4&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;prob-a-slider&quot; min=&quot;0.1&quot; max=&quot;0.9&quot; step=&quot;0.05&quot; value=&quot;0.4&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;prob-b-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;P(B): &lt;span id=&quot;prob-b-value&quot;&gt;0.5&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;prob-b-slider&quot; min=&quot;0.1&quot; max=&quot;0.9&quot; step=&quot;0.05&quot; value=&quot;0.5&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;overlap-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;Overlap: &lt;span id=&quot;overlap-value&quot;&gt;0.2&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;overlap-slider&quot; min=&quot;0&quot; max=&quot;0.4&quot; step=&quot;0.05&quot; value=&quot;0.2&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div id=&quot;conditional-results&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Probabilities:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;P(A) = &lt;span id=&quot;display-prob-a&quot;&gt;0.400&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(B) = &lt;span id=&quot;display-prob-b&quot;&gt;0.500&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(A ∩ B) = &lt;span id=&quot;display-prob-ab&quot;&gt;0.200&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(A ∪ B) = &lt;span id=&quot;display-prob-union&quot;&gt;0.700&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;&lt;strong&gt;Conditional:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;P(A|B) = &lt;span id=&quot;display-prob-a-given-b&quot;&gt;0.400&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;P(B|A) = &lt;span id=&quot;display-prob-b-given-a&quot;&gt;0.500&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;5-independence&quot;&gt;5. Independence&lt;/h3&gt;

&lt;p&gt;Two events A and B are &lt;strong&gt;independent&lt;/strong&gt; if:
\(P(A \cap B) = P(A) \cdot P(B)\)&lt;/p&gt;

&lt;p&gt;Equivalently:
\(P(A|B) = P(A) \quad \text{and} \quad P(B|A) = P(B)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interpretation&lt;/strong&gt;: Knowledge about one event doesn’t change the probability of the other.&lt;/p&gt;

&lt;h3 id=&quot;6-random-variables&quot;&gt;6. Random Variables&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;random variable&lt;/strong&gt; X is a function that assigns a real number to each outcome in the sample space:
\(X: \Omega \rightarrow \mathbb{R}\)&lt;/p&gt;

&lt;h4 id=&quot;types-of-random-variables&quot;&gt;Types of Random Variables:&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Discrete&lt;/strong&gt;: Takes countable values (e.g., number of heads in coin flips)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Probability Mass Function (PMF): \(P(X = x)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Continuous&lt;/strong&gt;: Takes uncountable values (e.g., height, weight)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Probability Density Function (PDF): \(f_X(x)\)&lt;/li&gt;
  &lt;li&gt;
\[P(a \leq X \leq b) = \int_a^b f_X(x) dx\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;7-connection-to-optimization&quot;&gt;7. Connection to Optimization&lt;/h3&gt;

&lt;p&gt;Probability theory connects to optimization in several ways:&lt;/p&gt;

&lt;h4 id=&quot;maximum-likelihood-estimation&quot;&gt;Maximum Likelihood Estimation&lt;/h4&gt;
&lt;p&gt;Find parameters θ that maximize the likelihood:
\(\hat{\theta} = \arg\max_\theta P(\text{data}|\theta)\)&lt;/p&gt;

&lt;h4 id=&quot;expected-value-optimization&quot;&gt;Expected Value Optimization&lt;/h4&gt;
&lt;p&gt;Minimize expected loss:
\(\min_\theta \mathbb{E}[L(Y, f(X; \theta))]\)&lt;/p&gt;

&lt;h4 id=&quot;bayesian-optimization&quot;&gt;Bayesian Optimization&lt;/h4&gt;
&lt;p&gt;Use probability distributions to model uncertainty in objective functions and guide search for optimal solutions.&lt;/p&gt;

&lt;div id=&quot;optimization-connection&quot; style=&quot;border: 2px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 10px; background-color: #f0f8ff;&quot;&gt;
    &lt;h4 style=&quot;text-align: center; color: #333;&quot;&gt;Probability in Optimization Example&lt;/h4&gt;
    
    &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;&quot;&gt;
        &lt;div style=&quot;flex: 1; min-width: 400px;&quot;&gt;
            &lt;canvas id=&quot;optimizationCanvas&quot; width=&quot;400&quot; height=&quot;300&quot; style=&quot;border: 1px solid #ccc; background: white;&quot;&gt;&lt;/canvas&gt;
            &lt;p style=&quot;font-size: 12px; color: #666; margin-top: 5px;&quot;&gt;
                &lt;strong&gt;MLE Example:&lt;/strong&gt; Finding the parameter μ that maximizes likelihood of observed data from Normal(μ, 1).
            &lt;/p&gt;
        &lt;/div&gt;
        
        &lt;div style=&quot;flex: 1; min-width: 250px;&quot;&gt;
            &lt;div style=&quot;background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);&quot;&gt;
                &lt;h5 style=&quot;margin-top: 0; color: #444;&quot;&gt;MLE Demo&lt;/h5&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;true-mu-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;True μ: &lt;span id=&quot;true-mu-value&quot;&gt;2.0&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;true-mu-slider&quot; min=&quot;-2&quot; max=&quot;4&quot; step=&quot;0.1&quot; value=&quot;2.0&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;div style=&quot;margin-bottom: 15px;&quot;&gt;
                    &lt;label for=&quot;sample-size-slider&quot; style=&quot;display: block; margin-bottom: 5px; font-weight: bold;&quot;&gt;Sample Size: &lt;span id=&quot;sample-size-value&quot;&gt;20&lt;/span&gt;&lt;/label&gt;
                    &lt;input type=&quot;range&quot; id=&quot;sample-size-slider&quot; min=&quot;5&quot; max=&quot;100&quot; step=&quot;5&quot; value=&quot;20&quot; style=&quot;width: 100%;&quot; /&gt;
                &lt;/div&gt;
                
                &lt;button id=&quot;generate-mle-data&quot; style=&quot;width: 100%; padding: 10px; background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 15px;&quot;&gt;Generate Data &amp;amp; Find MLE&lt;/button&gt;
                
                &lt;div id=&quot;mle-results&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 1.4; background: #f8f9fa; padding: 10px; border-radius: 4px;&quot;&gt;
                    &lt;div&gt;&lt;strong&gt;Results:&lt;/strong&gt;&lt;/div&gt;
                    &lt;div&gt;True μ: &lt;span id=&quot;display-true-mu&quot;&gt;2.000&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Sample mean: &lt;span id=&quot;sample-mean&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;MLE estimate: &lt;span id=&quot;mle-estimate&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                    &lt;div&gt;Error: &lt;span id=&quot;mle-error&quot;&gt;--&lt;/span&gt;&lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;key-takeaways&quot;&gt;Key Takeaways&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Foundation&lt;/strong&gt;: Probability axioms provide the mathematical foundation for reasoning about uncertainty&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conditional Probability&lt;/strong&gt;: Essential for updating beliefs with new information&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Independence&lt;/strong&gt;: Simplifies calculations and modeling assumptions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Random Variables&lt;/strong&gt;: Bridge between abstract probability and concrete applications&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimization Connection&lt;/strong&gt;: Many optimization problems arise from probabilistic modeling&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Understanding these basics prepares you for more advanced topics like Bayesian inference, maximum likelihood estimation, and stochastic optimization that are central to modern machine learning and data science.&lt;/p&gt;

&lt;script&gt;
// Sample Space Visualization
class SampleSpaceDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;sampleSpaceCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.samples = [];
        this.experimentType = &apos;coin&apos;;
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const radios = document.querySelectorAll(&apos;input[name=&quot;experiment&quot;]&apos;);
        const generateBtn = document.getElementById(&apos;generate-sample&apos;);
        const clearBtn = document.getElementById(&apos;clear-samples&apos;);
        
        radios.forEach(radio =&gt; {
            radio.addEventListener(&apos;change&apos;, (e) =&gt; {
                this.experimentType = e.target.value;
                this.samples = [];
                this.updateStats();
                this.draw();
            });
        });
        
        generateBtn.addEventListener(&apos;click&apos;, () =&gt; this.generateSample());
        clearBtn.addEventListener(&apos;click&apos;, () =&gt; {
            this.samples = [];
            this.updateStats();
            this.draw();
        });
        
        this.canvas.addEventListener(&apos;click&apos;, () =&gt; this.generateSample());
    }
    
    generateSample() {
        let sample;
        
        switch(this.experimentType) {
            case &apos;coin&apos;:
                sample = {
                    value: Math.random() &lt; 0.5 ? &apos;H&apos; : &apos;T&apos;,
                    x: Math.random() * (this.width - 40) + 20,
                    y: Math.random() * (this.height - 40) + 20,
                    eventA: Math.random() &lt; 0.5, // Event A: Heads
                    eventB: Math.random() &lt; 0.3  // Event B: Lucky flip
                };
                break;
            case &apos;dice&apos;:
                const diceValue = Math.floor(Math.random() * 6) + 1;
                sample = {
                    value: diceValue,
                    x: Math.random() * (this.width - 40) + 20,
                    y: Math.random() * (this.height - 40) + 20,
                    eventA: diceValue &gt;= 4, // Event A: 4, 5, or 6
                    eventB: diceValue % 2 === 0 // Event B: Even
                };
                break;
            case &apos;uniform&apos;:
                const uniformValue = Math.random();
                sample = {
                    value: uniformValue.toFixed(3),
                    x: uniformValue * (this.width - 40) + 20,
                    y: Math.random() * (this.height - 40) + 20,
                    eventA: uniformValue &gt; 0.5, // Event A: &gt; 0.5
                    eventB: uniformValue &lt; 0.7  // Event B: &lt; 0.7
                };
                break;
        }
        
        this.samples.push(sample);
        this.updateStats();
        this.draw();
    }
    
    updateStats() {
        const total = this.samples.length;
        const eventACount = this.samples.filter(s =&gt; s.eventA).length;
        const eventBCount = this.samples.filter(s =&gt; s.eventB).length;
        
        document.getElementById(&apos;total-samples&apos;).textContent = total;
        document.getElementById(&apos;event-a-count&apos;).textContent = eventACount;
        document.getElementById(&apos;event-b-count&apos;).textContent = eventBCount;
        document.getElementById(&apos;prob-a&apos;).textContent = total &gt; 0 ? (eventACount / total).toFixed(3) : &apos;0.000&apos;;
        document.getElementById(&apos;prob-b&apos;).textContent = total &gt; 0 ? (eventBCount / total).toFixed(3) : &apos;0.000&apos;;
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        // Draw background
        this.ctx.fillStyle = &apos;#f8f9fa&apos;;
        this.ctx.fillRect(0, 0, this.width, this.height);
        
        // Draw samples
        this.samples.forEach(sample =&gt; {
            // Determine color based on events
            let color = &apos;#666&apos;;
            if (sample.eventA &amp;&amp; sample.eventB) color = &apos;#9c27b0&apos;; // Both events
            else if (sample.eventA) color = &apos;#2196f3&apos;; // Event A only
            else if (sample.eventB) color = &apos;#f44336&apos;; // Event B only
            
            this.ctx.fillStyle = color;
            this.ctx.beginPath();
            this.ctx.arc(sample.x, sample.y, 5, 0, 2 * Math.PI);
            this.ctx.fill();
            
            // Draw value
            this.ctx.fillStyle = &apos;#000&apos;;
            this.ctx.font = &apos;10px Arial&apos;;
            this.ctx.textAlign = &apos;center&apos;;
            this.ctx.fillText(sample.value, sample.x, sample.y - 8);
        });
        
        // Draw legend
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;left&apos;;
        this.ctx.fillText(&apos;Legend:&apos;, 10, 20);
        
        this.ctx.fillStyle = &apos;#2196f3&apos;;
        this.ctx.beginPath();
        this.ctx.arc(20, 35, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.fillText(&apos;Event A only&apos;, 30, 38);
        
        this.ctx.fillStyle = &apos;#f44336&apos;;
        this.ctx.beginPath();
        this.ctx.arc(20, 50, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.fillText(&apos;Event B only&apos;, 30, 53);
        
        this.ctx.fillStyle = &apos;#9c27b0&apos;;
        this.ctx.beginPath();
        this.ctx.arc(20, 65, 4, 0, 2 * Math.PI);
        this.ctx.fill();
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.fillText(&apos;Both A and B&apos;, 30, 68);
    }
}

// Conditional Probability Visualization
class ConditionalProbDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;conditionalCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.probA = 0.4;
        this.probB = 0.5;
        this.overlap = 0.2;
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const probASlider = document.getElementById(&apos;prob-a-slider&apos;);
        const probBSlider = document.getElementById(&apos;prob-b-slider&apos;);
        const overlapSlider = document.getElementById(&apos;overlap-slider&apos;);
        
        probASlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.probA = parseFloat(e.target.value);
            document.getElementById(&apos;prob-a-value&apos;).textContent = this.probA.toFixed(1);
            this.updateCalculations();
            this.draw();
        });
        
        probBSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.probB = parseFloat(e.target.value);
            document.getElementById(&apos;prob-b-value&apos;).textContent = this.probB.toFixed(1);
            this.updateCalculations();
            this.draw();
        });
        
        overlapSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.overlap = parseFloat(e.target.value);
            document.getElementById(&apos;overlap-value&apos;).textContent = this.overlap.toFixed(1);
            // Ensure overlap doesn&apos;t exceed min(probA, probB)
            const maxOverlap = Math.min(this.probA, this.probB);
            if (this.overlap &gt; maxOverlap) {
                this.overlap = maxOverlap;
                overlapSlider.value = this.overlap;
                document.getElementById(&apos;overlap-value&apos;).textContent = this.overlap.toFixed(1);
            }
            this.updateCalculations();
            this.draw();
        });
        
        this.updateCalculations();
    }
    
    updateCalculations() {
        const probUnion = this.probA + this.probB - this.overlap;
        const probAGivenB = this.probB &gt; 0 ? this.overlap / this.probB : 0;
        const probBGivenA = this.probA &gt; 0 ? this.overlap / this.probA : 0;
        
        document.getElementById(&apos;display-prob-a&apos;).textContent = this.probA.toFixed(3);
        document.getElementById(&apos;display-prob-b&apos;).textContent = this.probB.toFixed(3);
        document.getElementById(&apos;display-prob-ab&apos;).textContent = this.overlap.toFixed(3);
        document.getElementById(&apos;display-prob-union&apos;).textContent = probUnion.toFixed(3);
        document.getElementById(&apos;display-prob-a-given-b&apos;).textContent = probAGivenB.toFixed(3);
        document.getElementById(&apos;display-prob-b-given-a&apos;).textContent = probBGivenA.toFixed(3);
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        // Draw universe rectangle
        this.ctx.strokeStyle = &apos;#000&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.strokeRect(50, 50, 300, 200);
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;14px Arial&apos;;
        this.ctx.fillText(&apos;Ω (Sample Space)&apos;, 55, 45);
        
        // Calculate circle parameters
        const centerAX = 150;
        const centerAY = 150;
        const centerBX = 250;
        const centerBY = 150;
        
        // Calculate radii based on probabilities (area proportional to probability)
        const radiusA = Math.sqrt(this.probA * 10000 / Math.PI);
        const radiusB = Math.sqrt(this.probB * 10000 / Math.PI);
        
        // Draw circle A
        this.ctx.globalAlpha = 0.3;
        this.ctx.fillStyle = &apos;#2196f3&apos;;
        this.ctx.beginPath();
        this.ctx.arc(centerAX, centerAY, radiusA, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Draw circle B
        this.ctx.fillStyle = &apos;#f44336&apos;;
        this.ctx.beginPath();
        this.ctx.arc(centerBX, centerBY, radiusB, 0, 2 * Math.PI);
        this.ctx.fill();
        
        // Draw intersection (approximate)
        if (this.overlap &gt; 0) {
            this.ctx.fillStyle = &apos;#9c27b0&apos;;
            const overlapRadius = Math.sqrt(this.overlap * 5000 / Math.PI);
            this.ctx.beginPath();
            this.ctx.arc((centerAX + centerBX) / 2, (centerAY + centerBY) / 2, overlapRadius, 0, 2 * Math.PI);
            this.ctx.fill();
        }
        
        this.ctx.globalAlpha = 1.0;
        
        // Draw circle outlines
        this.ctx.strokeStyle = &apos;#2196f3&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        this.ctx.arc(centerAX, centerAY, radiusA, 0, 2 * Math.PI);
        this.ctx.stroke();
        
        this.ctx.strokeStyle = &apos;#f44336&apos;;
        this.ctx.beginPath();
        this.ctx.arc(centerBX, centerBY, radiusB, 0, 2 * Math.PI);
        this.ctx.stroke();
        
        // Labels
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;16px Arial&apos;;
        this.ctx.fillText(&apos;A&apos;, centerAX - 40, centerAY);
        this.ctx.fillText(&apos;B&apos;, centerBX + 30, centerBY);
        
        if (this.overlap &gt; 0) {
            this.ctx.fillText(&apos;A∩B&apos;, (centerAX + centerBX) / 2 - 15, (centerAY + centerBY) / 2 + 5);
        }
    }
}

// MLE Optimization Demo
class MLEDemo {
    constructor() {
        this.canvas = document.getElementById(&apos;optimizationCanvas&apos;);
        this.ctx = this.canvas.getContext(&apos;2d&apos;);
        this.width = this.canvas.width;
        this.height = this.canvas.height;
        
        this.trueMu = 2.0;
        this.sampleSize = 20;
        this.data = [];
        
        this.setupControls();
        this.draw();
    }
    
    setupControls() {
        const trueMuSlider = document.getElementById(&apos;true-mu-slider&apos;);
        const sampleSizeSlider = document.getElementById(&apos;sample-size-slider&apos;);
        const generateBtn = document.getElementById(&apos;generate-mle-data&apos;);
        
        trueMuSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.trueMu = parseFloat(e.target.value);
            document.getElementById(&apos;true-mu-value&apos;).textContent = this.trueMu.toFixed(1);
            document.getElementById(&apos;display-true-mu&apos;).textContent = this.trueMu.toFixed(3);
        });
        
        sampleSizeSlider.addEventListener(&apos;input&apos;, (e) =&gt; {
            this.sampleSize = parseInt(e.target.value);
            document.getElementById(&apos;sample-size-value&apos;).textContent = this.sampleSize;
        });
        
        generateBtn.addEventListener(&apos;click&apos;, () =&gt; this.generateDataAndFindMLE());
    }
    
    generateDataAndFindMLE() {
        // Generate data from Normal(trueMu, 1)
        this.data = [];
        for (let i = 0; i &lt; this.sampleSize; i++) {
            // Box-Muller transform for normal distribution
            const u1 = Math.random();
            const u2 = Math.random();
            const z = Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
            this.data.push(this.trueMu + z); // Normal(trueMu, 1)
        }
        
        // Calculate MLE (sample mean for normal distribution)
        const sampleMean = this.data.reduce((sum, x) =&gt; sum + x, 0) / this.data.length;
        const error = Math.abs(sampleMean - this.trueMu);
        
        // Update display
        document.getElementById(&apos;sample-mean&apos;).textContent = sampleMean.toFixed(3);
        document.getElementById(&apos;mle-estimate&apos;).textContent = sampleMean.toFixed(3);
        document.getElementById(&apos;mle-error&apos;).textContent = error.toFixed(3);
        
        this.draw();
    }
    
    draw() {
        this.ctx.clearRect(0, 0, this.width, this.height);
        
        if (this.data.length === 0) {
            this.ctx.fillStyle = &apos;#666&apos;;
            this.ctx.font = &apos;16px Arial&apos;;
            this.ctx.textAlign = &apos;center&apos;;
            this.ctx.fillText(&apos;Click &quot;Generate Data &amp; Find MLE&quot; to start&apos;, this.width / 2, this.height / 2);
            return;
        }
        
        // Draw axes
        this.ctx.strokeStyle = &apos;#ddd&apos;;
        this.ctx.lineWidth = 1;
        const marginX = 50;
        const marginY = 50;
        const plotWidth = this.width - 2 * marginX;
        const plotHeight = this.height - 2 * marginY;
        
        // X-axis
        this.ctx.beginPath();
        this.ctx.moveTo(marginX, this.height - marginY);
        this.ctx.lineTo(this.width - marginX, this.height - marginY);
        this.ctx.stroke();
        
        // Y-axis
        this.ctx.beginPath();
        this.ctx.moveTo(marginX, marginY);
        this.ctx.lineTo(marginX, this.height - marginY);
        this.ctx.stroke();
        
        // Find data range
        const minX = Math.min(...this.data) - 1;
        const maxX = Math.max(...this.data) + 1;
        
        // Draw likelihood function
        this.ctx.strokeStyle = &apos;#2196f3&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        
        for (let i = 0; i &lt;= 100; i++) {
            const mu = minX + (maxX - minX) * i / 100;
            let logLikelihood = 0;
            
            // Calculate log-likelihood
            for (const x of this.data) {
                logLikelihood -= 0.5 * Math.log(2 * Math.PI);
                logLikelihood -= 0.5 * (x - mu) * (x - mu);
            }
            
            const x = marginX + (mu - minX) / (maxX - minX) * plotWidth;
            const y = this.height - marginY - (logLikelihood - (-this.data.length * 2)) / (this.data.length) * plotHeight * 0.8;
            
            if (i === 0) {
                this.ctx.moveTo(x, y);
            } else {
                this.ctx.lineTo(x, y);
            }
        }
        this.ctx.stroke();
        
        // Mark MLE
        const sampleMean = this.data.reduce((sum, x) =&gt; sum + x, 0) / this.data.length;
        const mleX = marginX + (sampleMean - minX) / (maxX - minX) * plotWidth;
        
        this.ctx.strokeStyle = &apos;#f44336&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.beginPath();
        this.ctx.moveTo(mleX, marginY);
        this.ctx.lineTo(mleX, this.height - marginY);
        this.ctx.stroke();
        
        // Mark true value
        const trueX = marginX + (this.trueMu - minX) / (maxX - minX) * plotWidth;
        this.ctx.strokeStyle = &apos;#4caf50&apos;;
        this.ctx.lineWidth = 2;
        this.ctx.setLineDash([5, 5]);
        this.ctx.beginPath();
        this.ctx.moveTo(trueX, marginY);
        this.ctx.lineTo(trueX, this.height - marginY);
        this.ctx.stroke();
        this.ctx.setLineDash([]);
        
        // Draw data points
        this.ctx.fillStyle = &apos;#666&apos;;
        for (const x of this.data) {
            const pointX = marginX + (x - minX) / (maxX - minX) * plotWidth;
            this.ctx.beginPath();
            this.ctx.arc(pointX, this.height - marginY + 10, 2, 0, 2 * Math.PI);
            this.ctx.fill();
        }
        
        // Labels
        this.ctx.fillStyle = &apos;#000&apos;;
        this.ctx.font = &apos;12px Arial&apos;;
        this.ctx.textAlign = &apos;center&apos;;
        this.ctx.fillText(&apos;μ&apos;, this.width / 2, this.height - 10);
        
        this.ctx.save();
        this.ctx.translate(15, this.height / 2);
        this.ctx.rotate(-Math.PI / 2);
        this.ctx.fillText(&apos;Log-Likelihood&apos;, 0, 0);
        this.ctx.restore();
        
        // Legend
        this.ctx.textAlign = &apos;left&apos;;
        this.ctx.fillText(&apos;— Likelihood&apos;, 10, 20);
        this.ctx.fillStyle = &apos;#f44336&apos;;
        this.ctx.fillText(&apos;— MLE&apos;, 10, 35);
        this.ctx.fillStyle = &apos;#4caf50&apos;;
        this.ctx.fillText(&apos;--- True μ&apos;, 10, 50);
    }
}

// Initialize when DOM is loaded
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    new SampleSpaceDemo();
    new ConditionalProbDemo();
    new MLEDemo();
});
&lt;/script&gt;

&lt;style&gt;
input[type=&quot;range&quot;] {
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    background: #ddd;
    outline: none;
    border-radius: 5px;
}

input[type=&quot;range&quot;]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
}

input[type=&quot;range&quot;]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    background: #007bff;
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

canvas {
    border-radius: 5px;
}

.demo-container {
    margin: 20px 0;
}
&lt;/style&gt;

</content>
 </entry>
 
 <entry>
   <title>00-03 Real Analysis And Set Theory</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_03_Real_Analysis_and_Set_Theory/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_03_Real_Analysis_and_Set_Theory</id>
   <content type="html">&lt;p&gt;Before running an algorithm to minimize \(f(x)\) over a feasible region \(C\), a mathematician asks a deceptively simple question: &lt;em&gt;does a minimum even exist?&lt;/em&gt; Minimizing \(e^x\) over \(\mathbb{R}\) or \(1/x\) over \((1, \infty)\) chases an infimum that is never attained. Set theory and real analysis give us the exact vocabulary—open, closed, bounded, compact, infimum—needed to guarantee that optimization problems are well-posed before we spend a single CPU cycle solving them.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-foundations-of-well-posed-optimization&quot;&gt;Key ideas: Foundations of Well-Posed Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Set Algebra for Constraints:&lt;/strong&gt; Every feasible region is an intersection of constraint sets \(C = \bigcap_i C_i\); set operations let us manipulate feasible domains cleanly and apply De Morgan’s laws when reasoning about infeasibility.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infimum vs. Minimum:&lt;/strong&gt; The infimum \(\inf_{x \in C} f(x)\) always exists in \(\mathbb{R} \cup \{-\infty\}\), whereas a &lt;em&gt;minimum&lt;/em&gt; requires an actual point \(x^* \in C\) attaining that value.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Open, Closed, and Boundary Points:&lt;/strong&gt; Strict inequalities define open sets (no boundary to land on), while non-strict inequalities define closed sets that contain their own limit points.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compactness &amp;amp; Weierstrass’s Theorem:&lt;/strong&gt; In \(\mathbb{R}^n\), closed and bounded sets are compact; any continuous objective on a nonempty compact set is guaranteed to attain both its global minimum and maximum.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-attained-minimum-vs-unattained-infimum&quot;&gt;Worked example: Attained Minimum vs. Unattained Infimum&lt;/h3&gt;

&lt;p&gt;Compare minimizing \(f(x) = \frac{1}{x}\) over three different domains:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Open unbounded domain \(D_1 = (1, \infty)\):&lt;/strong&gt; As \(x \to \infty\), \(1/x \to 0\), yet \(1/x &amp;gt; 0\) for every \(x \in D_1\). Thus \(\inf_{x \in D_1} f(x) = 0\), but &lt;strong&gt;no minimizer exists&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Half-open bounded domain \(D_2 = (0, 1]\):&lt;/strong&gt; On \(D_2\), \(f(x) \ge 1\) with equality at \(x^* = 1 \in D_2\), so \(\min_{x \in D_2} f(x) = 1\) exists; however, \(f(x) \to +\infty\) as \(x \to 0^+\), so no maximum exists because \(D_2\) is not closed.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compact domain \(D_3 = [1, 4]\):&lt;/strong&gt; \(D_3\) is closed and bounded (compact by Heine–Borel), and \(f(x) = 1/x\) is continuous on \(D_3\). By Weierstrass’s theorem, both extrema are attained:
\(\min_{x \in [1, 4]} \frac{1}{x} = \frac{1}{4} \text{ (at } x = 4\text{)}, \qquad \max_{x \in [1, 4]} \frac{1}{x} = 1 \text{ (at } x = 1\text{)}.\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Convex optimization is analysis on &lt;em&gt;sets&lt;/em&gt;: a feasible region, an epigraph, a cone of dual multipliers. Before Chapter 02 defines convex sets, we need the vocabulary of open and closed sets, interiors, and sequences.&lt;/p&gt;

&lt;h2 id=&quot;why-this-block-exists&quot;&gt;Why this block exists&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Feasible sets&lt;/strong&gt; are subsets of \(\mathbb{R}^n\). Closedness decides whether a minimizing sequence has a limit &lt;em&gt;inside&lt;/em&gt; the set; boundedness plus closedness (Heine–Borel in finite dimension) gives existence of a minimizer for a continuous objective.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Open sets and interiors&lt;/strong&gt; appear in constraint qualifications (Slater: a point in the relative interior of the inequalities) that make KKT conditions necessary in Chapter 12.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sequences and limits&lt;/strong&gt; are how we even state “\(x^{(k)}\to x^\star\)” for gradient descent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A set \(C\subseteq\mathbb{R}^n\) is &lt;strong&gt;closed&lt;/strong&gt; if it contains all its limit points, &lt;strong&gt;open&lt;/strong&gt; if it is a neighborhood of each of its points, and &lt;strong&gt;compact&lt;/strong&gt; (in \(\mathbb{R}^n\)) if and only if it is closed and bounded. The &lt;strong&gt;epigraph&lt;/strong&gt;&lt;/p&gt;

\[\operatorname{epi} f = \bigl\{(x,t): f(x)\le t\bigr\}\]

&lt;p&gt;is a set in \(\mathbb{R}^{n+1}\); \(f\) is lower semicontinuous precisely when \(\operatorname{epi} f\) is closed. That one sentence is the analysis backbone of “does this loss attain its infimum?”&lt;/p&gt;

&lt;h2 id=&quot;lessons-in-this-block&quot;&gt;Lessons in this block&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Set theory fundamentals (unions, intersections, complements, products — the algebra of constraints)&lt;/li&gt;
  &lt;li&gt;Topology in real analysis (open/closed sets, interiors, sequences)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After these two lessons you should be able to say, without hesitation, whether \(\{x: \|x\|_2 \le 1\}\) is compact and whether \(\{x: \|x\|_2 &amp;lt; 1\}\) can contain a minimizer of a function that decreases toward the boundary.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-03-02 Topology in Real Analysis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_03_02_Topology_in_Real_Analysis/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_03_02_Topology_in_Real_Analysis</id>
   <content type="html">&lt;p&gt;When an interior-point method marches toward an optimal solution sitting on the boundary of a feasible polytope, it deliberately stays inside the &lt;em&gt;interior&lt;/em&gt; so that its logarithmic barrier stays finite, converging to a &lt;em&gt;boundary&lt;/em&gt; point only in the limit. Understanding open balls, interiors, closures, boundaries, and compactness explains exactly why Slater’s condition requires a strictly feasible interior point and why Weierstrass’s theorem guarantees an optimizer exists.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-topological-concepts-that-govern-convergence&quot;&gt;Key ideas: Topological Concepts That Govern Convergence&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Metric &amp;amp; Open Balls (\(B(x, r)\)):&lt;/strong&gt; Formalize “closeness” in \(\mathbb{R}^n\); a point is in the interior of \(S\) if you can wiggle it by some radius \(r &amp;gt; 0\) in &lt;em&gt;every&lt;/em&gt; direction without leaving \(S\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Open vs. Closed Sets:&lt;/strong&gt; Closed sets contain all limits of convergent sequences inside them—critical so that the limit of an algorithm’s iterates \(x_k \to x^*\) remains feasible.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closure (\(\text{cl}(S)\)) &amp;amp; Boundary (\(\partial S\)):&lt;/strong&gt; Active constraints at an optimum \(x^*\) almost always place \(x^*\) on the boundary \(\partial S = \text{cl}(S) \setminus \text{int}(S)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compactness (Heine–Borel in \(\mathbb{R}^n\)):&lt;/strong&gt; Closed and bounded sets trap every sequence so it has a convergent subsequence inside the set, guaranteeing global minima for continuous objectives.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-interior-closure-boundary-and-compactness-of-a-half-disk&quot;&gt;Worked example: Interior, Closure, Boundary, and Compactness of a Half-Disk&lt;/h3&gt;

&lt;p&gt;Analyze the planar set \(S = \{(x, y) \in \mathbb{R}^2 : x^2 + y^2 &amp;lt; 4,\; y \ge 0\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test an interior point \(p = (0, 1)\):&lt;/strong&gt; Distance from \(p\) to the line \(y = 0\) is \(1\), and distance to the circle \(x^2 + y^2 = 4\) (radius 2) is \(2 - 1 = 1\). Therefore the open ball \(B(p, 0.5)\) lies completely inside \(S\), proving \(p \in \text{int}(S)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Identify interior, closure, and boundary:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\text{int}(S) = \{(x, y) : x^2 + y^2 &amp;lt; 4,\; y &amp;gt; 0\}\) (open upper half-disk).&lt;/li&gt;
      &lt;li&gt;\(\text{cl}(S) = \{(x, y) : x^2 + y^2 \le 4,\; y \ge 0\}\) (adds the upper semicircular arc).&lt;/li&gt;
      &lt;li&gt;\(\partial S = \{(x, y) : x^2 + y^2 = 4, y \ge 0\} \cup \{(x, 0) : -2 \le x \le 2\}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check openness, closedness, and compactness:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(S\) is &lt;strong&gt;neither open nor closed&lt;/strong&gt;: \((0, 0) \in S\) is not interior (so not open), and the sequence \((0, 2 - 1/n) \in S\) converges to \((0, 2) \notin S\) (so not closed).&lt;/li&gt;
      &lt;li&gt;Although \(S\) is bounded (contained in \(B(0, 2)\)), it is &lt;strong&gt;not compact&lt;/strong&gt; because it is not closed. Its closure \(\text{cl}(S)\) is both closed and bounded, hence &lt;strong&gt;compact&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This lesson covers essential topological concepts from real analysis that are crucial for understanding the structure of feasible regions, continuity, and the existence of optimal solutions in optimization problems.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;introduction-to-topology&quot;&gt;Introduction to Topology&lt;/h2&gt;

&lt;p&gt;Topology studies the properties of space that are preserved under continuous deformations. In optimization, topological concepts help us understand the structure of feasible regions and the behavior of functions, particularly regarding the existence and characterization of optimal solutions.&lt;/p&gt;

&lt;h3 id=&quot;metric-spaces-and-distance&quot;&gt;Metric Spaces and Distance&lt;/h3&gt;

&lt;p&gt;Before discussing topology, we need the concept of distance. In \(\mathbb{R}^n\), the standard &lt;strong&gt;Euclidean distance&lt;/strong&gt; between points \(\mathbf{x}\) and \(\mathbf{y}\) is:&lt;/p&gt;

\[d(\mathbf{x}, \mathbf{y}) = \|\mathbf{x} - \mathbf{y}\|_2 = \sqrt{\sum_{i=1}^n (x_i - y_i)^2}\]

&lt;h3 id=&quot;open-balls-and-neighborhoods&quot;&gt;Open Balls and Neighborhoods&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;open ball&lt;/strong&gt; centered at \(\mathbf{x}_0\) with radius \(\epsilon &amp;gt; 0\) is:&lt;/p&gt;

\[B(\mathbf{x}_0, \epsilon) = \{\mathbf{y} \in \mathbb{R}^n : d(\mathbf{x}_0, \mathbf{y}) &amp;lt; \epsilon\}\]

&lt;p&gt;This represents all points within distance \(\epsilon\) from \(\mathbf{x}_0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;In \(\mathbb{R}\): \(B(0, 1) = (-1, 1)\) (open interval)&lt;/li&gt;
  &lt;li&gt;In \(\mathbb{R}^2\): \(B(\mathbf{0}, 1) = \{(x, y) : x^2 + y^2 &amp;lt; 1\}\) (open unit disk)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;open-sets&quot;&gt;Open Sets&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;open set&lt;/strong&gt; is characterized by the property that it &lt;strong&gt;contains none of its boundary points&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;formal-definition&quot;&gt;Formal Definition&lt;/h3&gt;

&lt;p&gt;A set \(S\) in \(\mathbb{R}^n\) is &lt;strong&gt;open&lt;/strong&gt; if for every point \(\mathbf{x} \in S\), there exists a positive real number \(\epsilon &amp;gt; 0\) such that the open ball \(B(\mathbf{x}, \epsilon)\) is entirely contained within \(S\):&lt;/p&gt;

\[\forall \mathbf{x} \in S, \exists \epsilon &amp;gt; 0 : B(\mathbf{x}, \epsilon) \subseteq S\]

&lt;h3 id=&quot;intuitive-understanding&quot;&gt;Intuitive Understanding&lt;/h3&gt;

&lt;p&gt;An open set has the property that if you’re inside it, you can move a small distance in any direction and still remain inside the set. There’s always some “wiggle room” around every point.&lt;/p&gt;

&lt;h3 id=&quot;examples-of-open-sets&quot;&gt;Examples of Open Sets&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;In \(\mathbb{R}\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[(0, 1) = \{x : 0 &amp;lt; x &amp;lt; 1\}\]
  &lt;/li&gt;
  &lt;li&gt;
\[(-\infty, 5) = \{x : x &amp;lt; 5\}\]
  &lt;/li&gt;
  &lt;li&gt;\(\mathbb{R}\) itself&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In \(\mathbb{R}^2\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\{(x, y) : x^2 + y^2 &amp;lt; 1\}\) (open unit disk)&lt;/li&gt;
  &lt;li&gt;\(\{(x, y) : x &amp;gt; 0, y &amp;gt; 0\}\) (first quadrant, excluding axes)&lt;/li&gt;
  &lt;li&gt;\(\mathbb{R}^2\) itself&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In \(\mathbb{R}^n\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Any open ball \(B(\mathbf{x}_0, r)\)&lt;/li&gt;
  &lt;li&gt;\(\mathbb{R}^n\) itself&lt;/li&gt;
  &lt;li&gt;\(\emptyset\) (empty set - vacuously open)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;properties-of-open-sets&quot;&gt;Properties of Open Sets&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;The union of any collection of open sets is open&lt;/li&gt;
  &lt;li&gt;The intersection of finitely many open sets is open&lt;/li&gt;
  &lt;li&gt;\(\mathbb{R}^n\) and \(\emptyset\) are both open&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;closed-sets&quot;&gt;Closed Sets&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;closed set&lt;/strong&gt; is defined as a set that contains all of its boundary points. Equivalently, a set \(S\) is closed if its complement \(\mathbb{R}^n \setminus S\) is an &lt;strong&gt;open set&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;formal-definition-1&quot;&gt;Formal Definition&lt;/h3&gt;

&lt;p&gt;A set \(S\) is &lt;strong&gt;closed&lt;/strong&gt; if it contains all its limit points. That is, if a sequence of points \((x_n)\) from \(S\) converges to a point \(\mathbf{x}\), then \(\mathbf{x}\) must also be in \(S\):&lt;/p&gt;

\[\text{If } \mathbf{x}_n \in S \text{ for all } n \text{ and } \lim_{n \to \infty} \mathbf{x}_n = \mathbf{x}, \text{ then } \mathbf{x} \in S\]

&lt;h3 id=&quot;examples-of-closed-sets&quot;&gt;Examples of Closed Sets&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;In \(\mathbb{R}\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[[0, 1] = \{x : 0 \leq x \leq 1\}\]
  &lt;/li&gt;
  &lt;li&gt;
\[[a, \infty) = \{x : x \geq a\}\]
  &lt;/li&gt;
  &lt;li&gt;\(\{0\}\) (single point)&lt;/li&gt;
  &lt;li&gt;\(\mathbb{Z}\) (integers)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In \(\mathbb{R}^2\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\{(x, y) : x^2 + y^2 \leq 1\}\) (closed unit disk)&lt;/li&gt;
  &lt;li&gt;\(\{(x, y) : x \geq 0, y \geq 0\}\) (first quadrant, including axes)&lt;/li&gt;
  &lt;li&gt;\(\{(0, 0)\}\) (single point)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In \(\mathbb{R}^n\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Any closed ball \(\overline{B}(\mathbf{x}_0, r) = \{\mathbf{x} : d(\mathbf{x}, \mathbf{x}_0) \leq r\}\)&lt;/li&gt;
  &lt;li&gt;\(\mathbb{R}^n\) itself&lt;/li&gt;
  &lt;li&gt;\(\emptyset\) (empty set)&lt;/li&gt;
  &lt;li&gt;Any finite set&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;properties-of-closed-sets&quot;&gt;Properties of Closed Sets&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;The intersection of any collection of closed sets is closed&lt;/li&gt;
  &lt;li&gt;The union of finitely many closed sets is closed&lt;/li&gt;
  &lt;li&gt;\(\mathbb{R}^n\) and \(\emptyset\) are both closed&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;important-note&quot;&gt;Important Note&lt;/h3&gt;

&lt;p&gt;Sets can be:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Open but not closed:&lt;/strong&gt; \((0, 1)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closed but not open:&lt;/strong&gt; \([0, 1]\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Both open and closed:&lt;/strong&gt; \(\mathbb{R}^n\), \(\emptyset\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Neither open nor closed:&lt;/strong&gt; \([0, 1)\), \((0, 1]\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;boundary-interior-and-closure&quot;&gt;Boundary, Interior, and Closure&lt;/h2&gt;

&lt;h3 id=&quot;boundary&quot;&gt;Boundary&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;boundary&lt;/strong&gt; of a set \(S\), denoted \(\partial S\), consists of points that are “on the edge” of the set. A point \(\mathbf{x}\) is a &lt;strong&gt;boundary point&lt;/strong&gt; of \(S\) if every open ball centered at \(\mathbf{x}\) intersects both \(S\) and its complement \(S^c\):&lt;/p&gt;

\[\partial S = \{\mathbf{x} : \forall \epsilon &amp;gt; 0, B(\mathbf{x}, \epsilon) \cap S \neq \emptyset \text{ and } B(\mathbf{x}, \epsilon) \cap S^c \neq \emptyset\}\]

&lt;h3 id=&quot;interior&quot;&gt;Interior&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;interior&lt;/strong&gt; of a set \(S\), denoted \(S^\circ\) or \(\text{int}(S)\), includes all points strictly “inside” the set, excluding the boundary:&lt;/p&gt;

\[S^\circ = \{\mathbf{x} \in S : \exists \epsilon &amp;gt; 0, B(\mathbf{x}, \epsilon) \subseteq S\}\]

&lt;h3 id=&quot;closure&quot;&gt;Closure&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;closure&lt;/strong&gt; of a set \(S\), denoted \(\overline{S}\) or \(\text{cl}(S)\), is the smallest closed set containing \(S\):&lt;/p&gt;

\[\overline{S} = S \cup \partial S\]

&lt;h3 id=&quot;example-analysis&quot;&gt;Example Analysis&lt;/h3&gt;

&lt;p&gt;For the interval \(S = [0, 1)\) in \(\mathbb{R}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Interior:&lt;/strong&gt; \(S^\circ = (0, 1)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Boundary:&lt;/strong&gt; \(\partial S = \{0, 1\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closure:&lt;/strong&gt; \(\overline{S} = [0, 1]\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the open disk \(S = \{(x, y) : x^2 + y^2 &amp;lt; 1\}\) in \(\mathbb{R}^2\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Interior:&lt;/strong&gt; \(S^\circ = S\) (the set is already open)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Boundary:&lt;/strong&gt; \(\partial S = \{(x, y) : x^2 + y^2 = 1\}\) (unit circle)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closure:&lt;/strong&gt; \(\overline{S} = \{(x, y) : x^2 + y^2 \leq 1\}\) (closed unit disk)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;compact-sets&quot;&gt;Compact Sets&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;compact set&lt;/strong&gt; is one of the most important concepts in optimization theory.&lt;/p&gt;

&lt;h3 id=&quot;definition-in-euclidean-spaces&quot;&gt;Definition in Euclidean Spaces&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Heine-Borel Theorem:&lt;/strong&gt; In Euclidean spaces (\(\mathbb{R}^n\)), a set is compact if and only if it is both &lt;strong&gt;closed and bounded&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bounded:&lt;/strong&gt; A set \(S\) is bounded if it can be contained within some sufficiently large open ball: \(\exists M &amp;gt; 0, \mathbf{x}_0\) such that \(S \subseteq B(\mathbf{x}_0, M)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closed:&lt;/strong&gt; As defined above&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;examples-of-compact-sets&quot;&gt;Examples of Compact Sets&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;In \(\mathbb{R}\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\([a, b]\) (any closed, bounded interval)&lt;/li&gt;
  &lt;li&gt;\(\{0\}\) (single point)&lt;/li&gt;
  &lt;li&gt;Any finite set&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In \(\mathbb{R}^2\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\{(x, y) : x^2 + y^2 \leq 1\}\) (closed unit disk)&lt;/li&gt;
  &lt;li&gt;\([0, 1] \times [0, 1]\) (unit square)&lt;/li&gt;
  &lt;li&gt;Any finite set of points&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In \(\mathbb{R}^n\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Any closed ball \(\overline{B}(\mathbf{x}_0, r)\)&lt;/li&gt;
  &lt;li&gt;Any closed, bounded rectangle \([a_1, b_1] \times [a_2, b_2] \times \cdots \times [a_n, b_n]\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;non-compact-sets&quot;&gt;Non-Compact Sets&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;\((0, 1)\) (bounded but not closed)&lt;/li&gt;
  &lt;li&gt;\([0, \infty)\) (closed but not bounded)&lt;/li&gt;
  &lt;li&gt;\(\mathbb{R}^n\) (not bounded)&lt;/li&gt;
  &lt;li&gt;\(\{1, 1/2, 1/3, 1/4, \ldots\}\) (bounded but not closed, since 0 is a limit point not in the set)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;continuity-of-functions&quot;&gt;Continuity of Functions&lt;/h2&gt;

&lt;h3 id=&quot;point-wise-continuity&quot;&gt;Point-wise Continuity&lt;/h3&gt;

&lt;p&gt;A function \(f: A \to \mathbb{R}\) is &lt;strong&gt;continuous at a point&lt;/strong&gt; \(\mathbf{c} \in A\) if for every \(\varepsilon &amp;gt; 0\), there exists \(\delta &amp;gt; 0\) such that for all \(\mathbf{x} \in A\):&lt;/p&gt;

\[\|\mathbf{x} - \mathbf{c}\| &amp;lt; \delta \implies |f(\mathbf{x}) - f(\mathbf{c})| &amp;lt; \varepsilon\]

&lt;p&gt;&lt;strong&gt;Intuitive meaning:&lt;/strong&gt; Small changes in input lead to small changes in output.&lt;/p&gt;

&lt;h3 id=&quot;global-continuity&quot;&gt;Global Continuity&lt;/h3&gt;

&lt;p&gt;\(f\) is &lt;strong&gt;continuous on \(A\)&lt;/strong&gt; if it’s continuous at every point in \(A\).&lt;/p&gt;

&lt;h3 id=&quot;sequential-characterization&quot;&gt;Sequential Characterization&lt;/h3&gt;

&lt;p&gt;\(f\) is continuous at \(\mathbf{c}\) if and only if for every sequence \((\mathbf{x}_n)\) in \(A\) converging to \(\mathbf{c}\):&lt;/p&gt;

\[\lim_{n \to \infty} f(\mathbf{x}_n) = f(\mathbf{c})\]

&lt;hr /&gt;

&lt;h2 id=&quot;important-theorems-for-optimization&quot;&gt;Important Theorems for Optimization&lt;/h2&gt;

&lt;h3 id=&quot;extreme-value-theorem&quot;&gt;Extreme Value Theorem&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;If \(f\) is continuous on a compact set \(K\), then \(f\) attains its maximum and minimum on \(K\).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is fundamental for optimization: it guarantees that continuous objective functions have optimal solutions on compact feasible regions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proof idea:&lt;/strong&gt; Compactness ensures that the supremum and infimum of \(f\) on \(K\) are actually achieved at points in \(K\).&lt;/p&gt;

&lt;h3 id=&quot;intermediate-value-theorem&quot;&gt;Intermediate Value Theorem&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;If \(f\) is continuous on \([a, b]\) and \(y\) is between \(f(a)\) and \(f(b)\), then there exists \(c \in [a, b]\) such that \(f(c) = y\).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This helps establish the existence of solutions to equations \(f(x) = 0\).&lt;/p&gt;

&lt;h3 id=&quot;bolzano-weierstrass-theorem&quot;&gt;Bolzano-Weierstrass Theorem&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Every bounded sequence in \(\mathbb{R}^n\) has a convergent subsequence.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is crucial for proving convergence of optimization algorithms.&lt;/p&gt;

&lt;h3 id=&quot;weierstrass-approximation-theorem&quot;&gt;Weierstrass Approximation Theorem&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Every continuous function on a closed interval can be uniformly approximated by polynomials.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This justifies using polynomial approximations in optimization algorithms.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h2&gt;

&lt;h3 id=&quot;1-existence-of-solutions&quot;&gt;1. Existence of Solutions&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Compact feasible sets guarantee optimal solutions exist:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;If the feasible region \(S\) is compact and the objective function \(f\) is continuous, then the optimization problem \(\min_{\mathbf{x} \in S} f(\mathbf{x})\) has a solution.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-constraint-qualification&quot;&gt;2. Constraint Qualification&lt;/h3&gt;

&lt;p&gt;Understanding topological properties of constraint sets:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Regular points:&lt;/strong&gt; Points where constraint gradients are linearly independent&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interior point methods:&lt;/strong&gt; Require the feasible region to have non-empty interior&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-convergence-analysis&quot;&gt;3. Convergence Analysis&lt;/h3&gt;

&lt;p&gt;Analyzing whether optimization algorithms converge:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Closed sets:&lt;/strong&gt; Ensure limit points of convergent sequences remain feasible&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compactness:&lt;/strong&gt; Guarantees convergent subsequences exist&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-local-vs-global-optima&quot;&gt;4. Local vs Global Optima&lt;/h3&gt;

&lt;p&gt;Using neighborhoods to define optimality:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Local minimum:&lt;/strong&gt; \(f(\mathbf{x}^*) \leq f(\mathbf{x})\) for all \(\mathbf{x}\) in some neighborhood of \(\mathbf{x}^*\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Global minimum:&lt;/strong&gt; \(f(\mathbf{x}^*) \leq f(\mathbf{x})\) for all \(\mathbf{x}\) in the feasible region&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5-feasible-region-analysis&quot;&gt;5. Feasible Region Analysis&lt;/h3&gt;

&lt;p&gt;Determining properties of constraint sets:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Linear constraints:&lt;/strong&gt; Define closed sets (half-spaces)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nonlinear constraints:&lt;/strong&gt; May create sets that are neither open nor closed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compact feasible regions:&lt;/strong&gt; Guarantee existence of optimal solutions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example-portfolio-optimization&quot;&gt;Example: Portfolio Optimization&lt;/h3&gt;

&lt;p&gt;Consider minimizing portfolio risk subject to constraints:&lt;/p&gt;

\[\begin{align}
\min_{\mathbf{w}} \quad &amp;amp; \mathbf{w}^T \mathbf{\Sigma} \mathbf{w} \\
\text{s.t.} \quad &amp;amp; \mathbf{1}^T \mathbf{w} = 1 \\
&amp;amp; \mathbf{w} \geq \mathbf{0}
\end{align}\]

&lt;p&gt;The feasible region \(S = \{\mathbf{w} : \mathbf{1}^T \mathbf{w} = 1, \mathbf{w} \geq \mathbf{0}\}\) is:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Closed:&lt;/strong&gt; It’s the intersection of closed sets&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bounded:&lt;/strong&gt; The constraint \(\mathbf{1}^T \mathbf{w} = 1\) with \(\mathbf{w} \geq \mathbf{0}\) bounds the feasible region&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compact:&lt;/strong&gt; Being closed and bounded in \(\mathbb{R}^n\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since the objective function \(\mathbf{w}^T \mathbf{\Sigma} \mathbf{w}\) is continuous and \(S\) is compact, the Extreme Value Theorem guarantees that an optimal portfolio exists.&lt;/p&gt;

&lt;p&gt;Understanding topology and real analysis provides the rigorous foundation needed to prove that optimization problems have solutions and that algorithms will find them. These concepts are essential for both theoretical analysis and practical algorithm design.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-03-01 Set Theory Fundamentals</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_03_01_Set_Theory_Fundamentals/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_03_01_Set_Theory_Fundamentals</id>
   <content type="html">&lt;p&gt;Every constrained optimization problem begins by carving a feasible set out of \(\mathbb{R}^n\): budget limits, physical capacity bounds, and non-negativity requirements each define a set, and a valid decision must belong to their intersection. Clear fluency in set notation, subsets, complements, and De Morgan’s laws prevents subtle logical errors when translating business or engineering rules into formal mathematical constraints.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-set-operations-behind-optimization-constraints&quot;&gt;Key ideas: Set Operations Behind Optimization Constraints&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Set-Builder Notation:&lt;/strong&gt; Expresses feasible regions concisely as \(\{x \in \mathbb{R}^n : g_i(x) \le 0\}\), separating the ambient space from the logical predicates defining membership.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Intersection (\(\cap\)) for Simultaneous Constraints:&lt;/strong&gt; Imposing multiple constraints corresponds to intersecting their individual feasible sets; a crucial theorem in Chapter 02 shows that arbitrary intersections of convex sets remain convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Union (\(\cup\)) and Non-Convexity:&lt;/strong&gt; Disjunctive constraints (“either machine A or machine B”) correspond to set unions, which typically destroy convexity and introduce combinatorial branching.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complements &amp;amp; De Morgan’s Laws:&lt;/strong&gt; \((A \cap B)^c = A^c \cup B^c\) formalizes infeasibility certificates—violating the intersection means violating &lt;em&gt;at least one&lt;/em&gt; constituent constraint.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-intersecting-constraint-sets-and-checking-de-morgans-law&quot;&gt;Worked example: Intersecting Constraint Sets and Checking De Morgan’s Law&lt;/h3&gt;

&lt;p&gt;Let the universal space be \(\mathbb{R}\) with two constraint sets:
\(S_1 = \{x \in \mathbb{R} : x^2 \le 4\} = [-2, 2], \qquad S_2 = \{x \in \mathbb{R} : 2x - 1 &amp;gt; 0\} = (0.5, \infty).\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the feasible intersection \(S_1 \cap S_2\):&lt;/strong&gt; A point \(x\) must satisfy both \(-2 \le x \le 2\) and \(x &amp;gt; 0.5\), giving
\(S_1 \cap S_2 = (0.5, 2].\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the infeasible region \((S_1 \cap S_2)^c\):&lt;/strong&gt; Everything outside \((0.5, 2]\) is
\((S_1 \cap S_2)^c = (-\infty, 0.5] \cup (2, \infty).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify De Morgan’s law directly:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(S_1^c = (-\infty, -2) \cup (2, \infty)\).&lt;/li&gt;
      &lt;li&gt;\(S_2^c = (-\infty, 0.5]\).&lt;/li&gt;
      &lt;li&gt;Taking their union: \(S_1^c \cup S_2^c = (-\infty, 0.5] \cup (2, \infty)\), matching \((S_1 \cap S_2)^c\) identically.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This lesson covers fundamental concepts from set theory that provide the mathematical foundation for understanding optimization problems, constraints, and feasible regions.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;introduction-to-set-theory&quot;&gt;Introduction to Set Theory&lt;/h2&gt;

&lt;p&gt;Set theory provides the foundation for modern mathematics and is essential for understanding optimization concepts. A &lt;strong&gt;set&lt;/strong&gt; is simply a collection of distinct objects, called elements or members.&lt;/p&gt;

&lt;h3 id=&quot;basic-notation&quot;&gt;Basic Notation&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Set notation:&lt;/strong&gt; \(A = \{1, 2, 3, 4\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Element membership:&lt;/strong&gt; \(x \in A\) (x is in A) or \(x \notin A\) (x is not in A)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Empty set:&lt;/strong&gt; \(\emptyset = \{\}\) (the set with no elements)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Set builder notation:&lt;/strong&gt; \(A = \{x : P(x)\}\) (the set of all x such that property P(x) holds)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;examples&quot;&gt;Examples&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;\(A = \{1, 2, 3, 4\}\) (explicit listing)&lt;/li&gt;
  &lt;li&gt;\(B = \{x \in \mathbb{R} : x^2 &amp;lt; 4\} = (-2, 2)\) (set builder notation)&lt;/li&gt;
  &lt;li&gt;\(C = \{x \in \mathbb{Z} : x \text{ is even}\}\) (all even integers)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;basic-set-operations&quot;&gt;Basic Set Operations&lt;/h2&gt;

&lt;h3 id=&quot;sets-and-subsets&quot;&gt;Sets and Subsets&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Subset:&lt;/strong&gt; \(A \subseteq B\) means every element of \(A\) is also in \(B\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Proper Subset:&lt;/strong&gt; \(A \subset B\) means \(A \subseteq B\) and \(A \neq B\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Set Equality:&lt;/strong&gt; \(A = B\) if and only if \(A \subseteq B\) and \(B \subseteq A\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\{1, 2\} \subseteq \{1, 2, 3, 4\}\]
  &lt;/li&gt;
  &lt;li&gt;
\[\{1, 2\} \subset \{1, 2, 3, 4\}\]
  &lt;/li&gt;
  &lt;li&gt;\(\emptyset \subseteq A\) for any set \(A\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;union-and-intersection&quot;&gt;Union and Intersection&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Union (\(A \cup B\)):&lt;/strong&gt; All elements that are in \(A\) or \(B\) (or both)
\(A \cup B = \{x : x \in A \text{ or } x \in B\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intersection (\(A \cap B\)):&lt;/strong&gt; All elements that are in both \(A\) and \(B\)
\(A \cap B = \{x : x \in A \text{ and } x \in B\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;If \(A = \{1, 2, 3\}\) and \(B = \{3, 4, 5\}\), then:
    &lt;ul&gt;
      &lt;li&gt;
\[A \cup B = \{1, 2, 3, 4, 5\}\]
      &lt;/li&gt;
      &lt;li&gt;
\[A \cap B = \{3\}\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disjoint Sets:&lt;/strong&gt; \(A\) and \(B\) are disjoint if \(A \cap B = \emptyset\)&lt;/p&gt;

&lt;h3 id=&quot;complement-and-difference&quot;&gt;Complement and Difference&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Complement (\(A^c\)):&lt;/strong&gt; All elements not in \(A\) (within some universal set \(U\))
\(A^c = \{x \in U : x \notin A\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Set Difference (\(A \setminus B\)):&lt;/strong&gt; Elements in \(A\) but not in \(B\)
\(A \setminus B = \{x : x \in A \text{ and } x \notin B\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Symmetric Difference:&lt;/strong&gt; \((A \setminus B) \cup (B \setminus A) = (A \cup B) \setminus (A \cap B)\)&lt;/p&gt;

&lt;h3 id=&quot;set-laws&quot;&gt;Set Laws&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Commutative Laws:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[A \cup B = B \cup A\]
  &lt;/li&gt;
  &lt;li&gt;
\[A \cap B = B \cap A\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Associative Laws:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[(A \cup B) \cup C = A \cup (B \cup C)\]
  &lt;/li&gt;
  &lt;li&gt;
\[(A \cap B) \cap C = A \cap (B \cap C)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Distributive Laws:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[A \cap (B \cup C) = (A \cap B) \cup (A \cap C)\]
  &lt;/li&gt;
  &lt;li&gt;
\[A \cup (B \cap C) = (A \cup B) \cap (A \cup C)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;De Morgan’s Laws:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[(A \cup B)^c = A^c \cap B^c\]
  &lt;/li&gt;
  &lt;li&gt;
\[(A \cap B)^c = A^c \cup B^c\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;important-number-sets&quot;&gt;Important Number Sets&lt;/h2&gt;

&lt;p&gt;Understanding the hierarchy of number systems is crucial for optimization:&lt;/p&gt;

&lt;h3 id=&quot;natural-numbers&quot;&gt;Natural Numbers&lt;/h3&gt;
&lt;p&gt;\(\mathbb{N} = \{1, 2, 3, 4, \ldots\}\)
(Sometimes includes 0: \(\mathbb{N}_0 = \{0, 1, 2, 3, \ldots\}\))&lt;/p&gt;

&lt;h3 id=&quot;integers&quot;&gt;Integers&lt;/h3&gt;
&lt;p&gt;\(\mathbb{Z} = \{\ldots, -2, -1, 0, 1, 2, \ldots\}\)&lt;/p&gt;

&lt;h3 id=&quot;rational-numbers&quot;&gt;Rational Numbers&lt;/h3&gt;
&lt;p&gt;\(\mathbb{Q} = \left\{\frac{p}{q} : p, q \in \mathbb{Z}, q \neq 0\right\}\)&lt;/p&gt;

&lt;p&gt;All numbers that can be expressed as fractions.&lt;/p&gt;

&lt;h3 id=&quot;real-numbers&quot;&gt;Real Numbers&lt;/h3&gt;
&lt;p&gt;\(\mathbb{R}\) includes all rational and irrational numbers (like \(\pi\), \(e\), \(\sqrt{2}\)).&lt;/p&gt;

&lt;h3 id=&quot;complex-numbers&quot;&gt;Complex Numbers&lt;/h3&gt;
&lt;p&gt;\(\mathbb{C} = \{a + bi : a, b \in \mathbb{R}, i^2 = -1\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hierarchy:&lt;/strong&gt; \(\mathbb{N} \subset \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R} \subset \mathbb{C}\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;functions-domain-and-range&quot;&gt;Functions: Domain and Range&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;function&lt;/strong&gt; \(f: A \to B\) is a rule that assigns to each element in set \(A\) exactly one element in set \(B\).&lt;/p&gt;

&lt;h3 id=&quot;key-concepts&quot;&gt;Key Concepts&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Domain:&lt;/strong&gt; The set \(A\) of all possible input values&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Codomain:&lt;/strong&gt; The set \(B\) where outputs are taken from&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Range (Image):&lt;/strong&gt; The set of all actual output values: \(\text{Range}(f) = \{f(x) : x \in A\} \subseteq B\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; For \(f(x) = x^2\) with \(f: \mathbb{R} \to \mathbb{R}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Domain: \(\mathbb{R}\)&lt;/li&gt;
  &lt;li&gt;Codomain: \(\mathbb{R}\)&lt;/li&gt;
  &lt;li&gt;Range: \([0, \infty)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;types-of-functions&quot;&gt;Types of Functions&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Injective (One-to-One):&lt;/strong&gt; Each element in the range corresponds to exactly one element in the domain
\(f(x_1) = f(x_2) \implies x_1 = x_2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Surjective (Onto):&lt;/strong&gt; Every element in the codomain is in the range
For every \(y \in B\), there exists \(x \in A\) such that \(f(x) = y\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bijective:&lt;/strong&gt; Both injective and surjective
There’s a perfect one-to-one correspondence between domain and codomain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(x) = 2x\) on \(\mathbb{R}\) is bijective&lt;/li&gt;
  &lt;li&gt;\(f(x) = x^2\) on \(\mathbb{R}\) is neither injective nor surjective&lt;/li&gt;
  &lt;li&gt;\(f(x) = x^2\) on \([0, \infty) \to [0, \infty)\) is bijective&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;inequalities&quot;&gt;Inequalities&lt;/h2&gt;

&lt;p&gt;Understanding inequalities is crucial for optimization, as constraints are often expressed as inequalities.&lt;/p&gt;

&lt;h3 id=&quot;basic-inequality-symbols&quot;&gt;Basic Inequality Symbols&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;\(a &amp;lt; b\): \(a\) is strictly less than \(b\)&lt;/li&gt;
  &lt;li&gt;\(a \leq b\): \(a\) is less than or equal to \(b\)&lt;/li&gt;
  &lt;li&gt;\(a &amp;gt; b\): \(a\) is strictly greater than \(b\)&lt;/li&gt;
  &lt;li&gt;\(a \geq b\): \(a\) is greater than or equal to \(b\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;properties-of-inequalities&quot;&gt;Properties of Inequalities&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Transitivity:&lt;/strong&gt; If \(a \leq b\) and \(b \leq c\), then \(a \leq c\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Addition:&lt;/strong&gt; If \(a \leq b\), then \(a + c \leq b + c\) for any \(c\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Multiplication by Positive:&lt;/strong&gt; If \(a \leq b\) and \(c &amp;gt; 0\), then \(ac \leq bc\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Multiplication by Negative:&lt;/strong&gt; If \(a \leq b\) and \(c &amp;lt; 0\), then \(ac \geq bc\) (inequality flips!)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;interval-notation&quot;&gt;Interval Notation&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Open interval:&lt;/strong&gt; \((a, b) = \{x \in \mathbb{R} : a &amp;lt; x &amp;lt; b\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Closed interval:&lt;/strong&gt; \([a, b] = \{x \in \mathbb{R} : a \leq x \leq b\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Half-open intervals:&lt;/strong&gt; \([a, b)\), \((a, b]\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unbounded intervals:&lt;/strong&gt; \((-\infty, a)\), \([a, \infty)\), \((-\infty, \infty) = \mathbb{R}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h2&gt;

&lt;p&gt;Set theory concepts are fundamental to optimization:&lt;/p&gt;

&lt;h3 id=&quot;1-feasible-regions&quot;&gt;1. Feasible Regions&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;feasible region&lt;/strong&gt; is the set of all points satisfying the constraints:
\(S = \{x \in \mathbb{R}^n : g_i(x) \leq 0, i = 1, \ldots, m; h_j(x) = 0, j = 1, \ldots, p\}\)&lt;/p&gt;

&lt;h3 id=&quot;2-level-sets&quot;&gt;2. Level Sets&lt;/h3&gt;

&lt;p&gt;For a function \(f: \mathbb{R}^n \to \mathbb{R}\), the &lt;strong&gt;level set&lt;/strong&gt; at level \(c\) is:
\(L_c = \{x \in \mathbb{R}^n : f(x) = c\}\)&lt;/p&gt;

&lt;h3 id=&quot;3-constraint-qualification&quot;&gt;3. Constraint Qualification&lt;/h3&gt;

&lt;p&gt;Understanding when constraint sets have “nice” properties (like being closed or having non-empty interior) affects the existence and characterization of optimal solutions.&lt;/p&gt;

&lt;h3 id=&quot;4-convergence-analysis&quot;&gt;4. Convergence Analysis&lt;/h3&gt;

&lt;p&gt;Sequences and limits are essential for analyzing whether optimization algorithms converge to optimal solutions.&lt;/p&gt;

&lt;h3 id=&quot;5-set-operations-in-algorithms&quot;&gt;5. Set Operations in Algorithms&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Intersection:&lt;/strong&gt; Finding points that satisfy multiple constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Union:&lt;/strong&gt; Combining feasible regions from different scenarios&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complement:&lt;/strong&gt; Understanding infeasible regions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; In linear programming, the feasible region is:
\(S = \{x \in \mathbb{R}^n : Ax \leq b, x \geq 0\} = \bigcap_{i=1}^{m} \{x : a_i^T x \leq b_i\} \cap \{x : x \geq 0\}\)&lt;/p&gt;

&lt;p&gt;This is the intersection of half-spaces, demonstrating how set operations naturally arise in optimization problem formulation.&lt;/p&gt;

&lt;p&gt;Understanding set theory provides the rigorous mathematical foundation needed to formulate optimization problems precisely and analyze their properties systematically.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-02 Basic Linear Algebra</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_02_Basic_Linear_Algebra/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_02_Basic_Linear_Algebra</id>
   <content type="html">&lt;p&gt;Open the hood of almost any convex optimization solver—whether it is fitting a ridge regression, solving a portfolio linear program, or taking a Newton step in an interior-point method—and you will find the same workhorse engine: solving linear systems \(Ax = b\) and analyzing symmetric matrices. Fluency in linear algebra turns multi-page coordinate sums into clean, geometric matrix equations whose behavior you can read at a glance.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-linear-algebra-as-optimization-infrastructure&quot;&gt;Key ideas: Linear Algebra as Optimization Infrastructure&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vector Spaces, Norms &amp;amp; Inner Products:&lt;/strong&gt; Equip \(\mathbb{R}^n\) with length, angles, and projections so we can measure residuals \(\|Ax - b\|_2\) and enforce orthogonality conditions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrices as Linear Maps &amp;amp; Constraints:&lt;/strong&gt; Encode affine feasible sets \(\{x : Ax = b\}\), feature designs, and Jacobians; rank and nullspace reveal whether solutions are unique or have free degrees of freedom.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Eigenvalues &amp;amp; Positive Definiteness:&lt;/strong&gt; Diagonalize symmetric quadratic forms \(x^T Q x\) into independent principal axes, certifying convexity (\(Q \succeq 0\)) and quantifying ill-conditioning (\(\kappa = \lambda_{\max}/\lambda_{\min}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Normal Equations &amp;amp; Projections:&lt;/strong&gt; Bridge geometry and algebra by showing that least-squares optimality means the residual \(b - Ax^*\) is orthogonal to the column space of \(A\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-solving-least-squares-via-normal-equations&quot;&gt;Worked example: Solving Least Squares via Normal Equations&lt;/h3&gt;

&lt;p&gt;Fit a line \(y \approx x_1 + x_2 t\) to three data points \((t, y) \in \{(0, 1), (1, 2), (2, 4)\}\) by minimizing \(\|Ax - b\|_2^2\) where&lt;/p&gt;

\[A = \begin{pmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{pmatrix}, \qquad b = \begin{pmatrix} 1 \\ 2 \\ 4 \end{pmatrix}.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the normal equations \(A^T A x = A^T b\):&lt;/strong&gt;
\(A^T A = \begin{pmatrix} 1 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 2 \end{pmatrix}\begin{pmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{pmatrix} = \begin{pmatrix} 3 &amp;amp; 3 \\ 3 &amp;amp; 5 \end{pmatrix}, \qquad A^T b = \begin{pmatrix} 1 + 2 + 4 \\ 0 + 2 + 8 \end{pmatrix} = \begin{pmatrix} 7 \\ 10 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Invert the \(2 \times 2\) Gram matrix:&lt;/strong&gt; Since \(\det(A^T A) = 3(5) - 3^2 = 6 &amp;gt; 0\), \(A^T A\) is strictly positive definite and invertible:
\(x^* = (A^T A)^{-1} A^T b = \frac{1}{6}\begin{pmatrix} 5 &amp;amp; -3 \\ -3 &amp;amp; 3 \end{pmatrix}\begin{pmatrix} 7 \\ 10 \end{pmatrix} = \frac{1}{6}\begin{pmatrix} 5 \\ 9 \end{pmatrix} = \begin{pmatrix} 5/6 \\ 3/2 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify orthogonality of the residual:&lt;/strong&gt; \(r = b - Ax^* = (1 - 5/6,\; 2 - 14/6,\; 4 - 23/6)^T = (1/6,\; -1/3,\; 1/6)^T\). Checking \(A^T r = (1/6 - 2/6 + 1/6,\; 0 - 1/3 + 2/6)^T = (0, 0)^T\) confirms optimality.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Almost every optimization iterate is a vector, every linear constraint is a matrix–vector product, and every local curvature story is an eigenvalue of a Hessian or Gram matrix. This page orients the three linear-algebra lessons that follow.&lt;/p&gt;

&lt;h2 id=&quot;objects-you-will-reuse-all-semester&quot;&gt;Objects you will reuse all semester&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vectors and inner products.&lt;/strong&gt; The Euclidean geometry \(\langle g, d\rangle = g^\top d\) decides whether \(d\) is a descent direction (\(g^\top d &amp;lt; 0\)). Other geometries (Mahalanobis, mirror maps) appear later as preconditioning and dual norms (Chapter 13).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrices as linear maps.&lt;/strong&gt; An equality \(Ax = b\) cuts an affine subspace; the nullspace of \(A\) is the set of feasible steps. Least squares (Chapter 05) solves \(A^\top A \hat{x} = A^\top y\) when \(A\) has full column rank.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Eigenvalues and quadratic forms.&lt;/strong&gt; If \(Q\succeq 0\) then \(x\mapsto x^\top Q x\) is convex; the condition number \(\kappa = \lambda_{\max}(Q)/\lambda_{\min}(Q)\) of a strongly convex quadratic is exactly the number that slows vanilla gradient descent and motivates acceleration (Chapters 06, 09, 26).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A symmetric matrix \(Q\) admits an orthonormal diagonalization \(Q = U\Lambda U^\top\). The Rayleigh quotient&lt;/p&gt;

\[\lambda_{\min}(Q) = \min_{\|x\|_2=1} x^\top Q x, \qquad \lambda_{\max}(Q) = \max_{\|x\|_2=1} x^\top Q x\]

&lt;p&gt;is the cleanest way to &lt;em&gt;see&lt;/em&gt; strong convexity and smoothness constants.&lt;/p&gt;

&lt;h2 id=&quot;lessons-in-this-block&quot;&gt;Lessons in this block&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Vectors and vector spaces&lt;/li&gt;
  &lt;li&gt;Matrices and linear transformations&lt;/li&gt;
  &lt;li&gt;Eigenvalues and eigenvectors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Checkpoint: explain in one sentence why \(\nabla^2 f(x)\succeq 0\) everywhere implies that a twice-differentiable \(f\) is convex. (Chapter 03 will prove it; linear algebra is what makes the statement meaningful.)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-02-03 Eigenvalues and Eigenvectors</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_02_03_Eigenvalues_and_Eigenvectors/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_02_03_Eigenvalues_and_Eigenvectors</id>
   <content type="html">&lt;p&gt;Why does gradient descent zig-zag painfully slowly down some quadratic valleys while racing straight to the bottom of others? The answer is hidden inside the eigenvalues and eigenvectors of the Hessian matrix. Eigenvectors reveal the natural, uncoupled axes of a symmetric transformation, and the ratio of the largest to smallest eigenvalue—the condition number—quantifies exactly how elongated the valley is.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-spectral-geometry-in-optimization&quot;&gt;Key ideas: Spectral Geometry in Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Invariant Directions (\(Av = \lambda v\)):&lt;/strong&gt; Eigenvectors are directions that \(A\) only scales without rotating; along these axes, coupled multivariable dynamics decouple into independent 1D scalings.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Spectral Theorem for Symmetric Matrices:&lt;/strong&gt; Every real symmetric matrix (including every smooth Hessian) has real eigenvalues and an orthonormal eigenbasis \(Q = U \Lambda U^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Positive Definiteness via Eigenvalues:&lt;/strong&gt; \(Q \succ 0\) if and only if all \(\lambda_i &amp;gt; 0\) (strictly convex bowl), \(Q \succeq 0\) if all \(\lambda_i \ge 0\) (convex), and mixed signs signal a saddle point.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Condition Number (\(\kappa = \lambda_{\max}/\lambda_{\min}\)):&lt;/strong&gt; Measures eccentricity of quadratic level sets; large \(\kappa\) slows first-order methods while Newton’s method rescales the axes to make \(\kappa = 1\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-eigen-decomposition-and-condition-number-of-a-hessian&quot;&gt;Worked example: Eigen-Decomposition and Condition Number of a Hessian&lt;/h3&gt;

&lt;p&gt;Analyze the symmetric quadratic matrix \(Q = \begin{pmatrix} 5 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{pmatrix}\) appearing in \(f(x) = \frac{1}{2}x^T Q x\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Solve the characteristic equation \(\det(Q - \lambda I) = 0\):&lt;/strong&gt;
\((5 - \lambda)(2 - \lambda) - 4 = \lambda^2 - 7\lambda + 6 = (\lambda - 6)(\lambda - 1) = 0 \implies \lambda_1 = 6, \; \lambda_2 = 1.\)
Because both eigenvalues are strictly positive, \(Q \succ 0\) and \(f\) is strictly convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find unit eigenvectors:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(\lambda_1 = 6\): \((Q - 6I)v = \begin{pmatrix} -1 &amp;amp; 2 \\ 2 &amp;amp; -4 \end{pmatrix}v = 0 \implies v_1 = \begin{pmatrix} 2 \\ 1 \end{pmatrix} \implies u_1 = \frac{1}{\sqrt{5}}\begin{pmatrix} 2 \\ 1 \end{pmatrix}\).&lt;/li&gt;
      &lt;li&gt;For \(\lambda_2 = 1\): \((Q - I)v = \begin{pmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{pmatrix}v = 0 \implies v_2 = \begin{pmatrix} -1 \\ 2 \end{pmatrix} \implies u_2 = \frac{1}{\sqrt{5}}\begin{pmatrix} -1 \\ 2 \end{pmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify orthogonality and action:&lt;/strong&gt; \(u_1^T u_2 = \frac{-2 + 2}{5} = 0\), and \(Q u_1 = \frac{1}{\sqrt{5}}\begin{pmatrix} 12 \\ 6 \end{pmatrix} = 6 u_1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the condition number:&lt;/strong&gt; \(\kappa(Q) = \frac{\lambda_{\max}}{\lambda_{\min}} = \frac{6}{1} = 6\), meaning the curvature along \(u_1\) is six times steeper than along \(u_2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This lesson covers eigenvalues and eigenvectors, which are crucial for understanding the behavior of linear transformations and quadratic functions in optimization.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;definition-and-intuition&quot;&gt;Definition and Intuition&lt;/h2&gt;

&lt;p&gt;When a matrix transforms a vector, it usually changes both the vector’s direction and its length. However, &lt;strong&gt;eigenvectors&lt;/strong&gt; are special vectors that, when transformed by a given matrix, only get scaled but do not change their direction.&lt;/p&gt;

&lt;h3 id=&quot;mathematical-definition&quot;&gt;Mathematical Definition&lt;/h3&gt;

&lt;p&gt;For a square matrix \(\mathbf{A}\) and a non-zero vector \(\mathbf{v}\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(\mathbf{v}\) is an &lt;strong&gt;eigenvector&lt;/strong&gt; of \(\mathbf{A}\)&lt;/li&gt;
  &lt;li&gt;\(\lambda\) is the corresponding &lt;strong&gt;eigenvalue&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;if they satisfy the &lt;strong&gt;eigenvalue equation&lt;/strong&gt;:&lt;/p&gt;

\[\mathbf{A}\mathbf{v} = \lambda\mathbf{v}\]

&lt;h3 id=&quot;geometric-interpretation&quot;&gt;Geometric Interpretation&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Eigenvectors:&lt;/strong&gt; Non-zero vectors that maintain their direction under the transformation \(\mathbf{A}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Eigenvalues:&lt;/strong&gt; The scalar factors by which the eigenvectors are scaled&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Visual Understanding:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;If \(\lambda &amp;gt; 1\): The eigenvector is stretched&lt;/li&gt;
  &lt;li&gt;If \(0 &amp;lt; \lambda &amp;lt; 1\): The eigenvector is shrunk&lt;/li&gt;
  &lt;li&gt;If \(\lambda &amp;lt; 0\): The eigenvector is scaled and flipped&lt;/li&gt;
  &lt;li&gt;If \(\lambda = 0\): The eigenvector is mapped to the zero vector&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;finding-eigenvalues-and-eigenvectors&quot;&gt;Finding Eigenvalues and Eigenvectors&lt;/h2&gt;

&lt;h3 id=&quot;step-1-find-eigenvalues&quot;&gt;Step 1: Find Eigenvalues&lt;/h3&gt;

&lt;p&gt;Rearrange the eigenvalue equation:
\(\mathbf{A}\mathbf{v} = \lambda\mathbf{v}\)
\(\mathbf{A}\mathbf{v} - \lambda\mathbf{v} = \mathbf{0}\)
\((\mathbf{A} - \lambda\mathbf{I})\mathbf{v} = \mathbf{0}\)&lt;/p&gt;

&lt;p&gt;For a non-trivial solution (\(\mathbf{v} \neq \mathbf{0}\)), the matrix \((\mathbf{A} - \lambda\mathbf{I})\) must be singular, so:&lt;/p&gt;

\[\det(\mathbf{A} - \lambda\mathbf{I}) = 0\]

&lt;p&gt;This is called the &lt;strong&gt;characteristic equation&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;step-2-find-eigenvectors&quot;&gt;Step 2: Find Eigenvectors&lt;/h3&gt;

&lt;p&gt;For each eigenvalue \(\lambda_i\), solve the system:
\((\mathbf{A} - \lambda_i\mathbf{I})\mathbf{v} = \mathbf{0}\)&lt;/p&gt;

&lt;p&gt;The solutions form the &lt;strong&gt;eigenspace&lt;/strong&gt; corresponding to \(\lambda_i\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;detailed-example&quot;&gt;Detailed Example&lt;/h2&gt;

&lt;p&gt;Let’s find the eigenvalues and eigenvectors of \(\mathbf{A} = \begin{pmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{pmatrix}\).&lt;/p&gt;

&lt;h3 id=&quot;step-1-find-eigenvalues-1&quot;&gt;Step 1: Find Eigenvalues&lt;/h3&gt;

\[\mathbf{A} - \lambda\mathbf{I} = \begin{pmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{pmatrix} - \lambda\begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix} = \begin{pmatrix} 3-\lambda &amp;amp; 1 \\ 0 &amp;amp; 2-\lambda \end{pmatrix}\]

\[\det(\mathbf{A} - \lambda\mathbf{I}) = (3-\lambda)(2-\lambda) - (1)(0) = (3-\lambda)(2-\lambda) = 0\]

&lt;p&gt;This gives us \(\lambda_1 = 3\) and \(\lambda_2 = 2\).&lt;/p&gt;

&lt;h3 id=&quot;step-2-find-eigenvectors-1&quot;&gt;Step 2: Find Eigenvectors&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;For \(\lambda_1 = 3\):&lt;/strong&gt;
\((\mathbf{A} - 3\mathbf{I})\mathbf{v} = \begin{pmatrix} 0 &amp;amp; 1 \\ 0 &amp;amp; -1 \end{pmatrix}\begin{pmatrix} v_1 \\ v_2 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;This gives us \(v_2 = 0\) and \(v_1\) can be any non-zero value. So \(\mathbf{v}_1 = \begin{pmatrix} 1 \\ 0 \end{pmatrix}\) (or any scalar multiple).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For \(\lambda_2 = 2\):&lt;/strong&gt;
\((\mathbf{A} - 2\mathbf{I})\mathbf{v} = \begin{pmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{pmatrix}\begin{pmatrix} v_1 \\ v_2 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;This gives us \(v_1 + v_2 = 0\), so \(v_2 = -v_1\). Thus \(\mathbf{v}_2 = \begin{pmatrix} 1 \\ -1 \end{pmatrix}\) (or any scalar multiple).&lt;/p&gt;

&lt;h3 id=&quot;verification&quot;&gt;Verification&lt;/h3&gt;

&lt;p&gt;Let’s verify our results:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{A}\mathbf{v}_1 = \begin{pmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{pmatrix}\begin{pmatrix} 1 \\ 0 \end{pmatrix} = \begin{pmatrix} 3 \\ 0 \end{pmatrix} = 3\begin{pmatrix} 1 \\ 0 \end{pmatrix} = 3\mathbf{v}_1\) ✓&lt;/li&gt;
  &lt;li&gt;\(\mathbf{A}\mathbf{v}_2 = \begin{pmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{pmatrix}\begin{pmatrix} 1 \\ -1 \end{pmatrix} = \begin{pmatrix} 2 \\ -2 \end{pmatrix} = 2\begin{pmatrix} 1 \\ -1 \end{pmatrix} = 2\mathbf{v}_2\) ✓&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;properties-and-important-theorems&quot;&gt;Properties and Important Theorems&lt;/h2&gt;

&lt;h3 id=&quot;key-properties&quot;&gt;Key Properties&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Sum of eigenvalues = trace of matrix:&lt;/strong&gt;
\(\sum_{i=1}^n \lambda_i = \text{tr}(\mathbf{A}) = \sum_{i=1}^n a_{ii}\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Product of eigenvalues = determinant of matrix:&lt;/strong&gt;
\(\prod_{i=1}^n \lambda_i = \det(\mathbf{A})\)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Eigenvectors corresponding to different eigenvalues are linearly independent&lt;/strong&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;If \(\mathbf{A}\) is symmetric, all eigenvalues are real and eigenvectors are orthogonal&lt;/strong&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;eigenvalue-multiplicity&quot;&gt;Eigenvalue Multiplicity&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algebraic multiplicity:&lt;/strong&gt; How many times \(\lambda\) appears as a root of the characteristic polynomial&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric multiplicity:&lt;/strong&gt; The dimension of the eigenspace (number of linearly independent eigenvectors)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For any eigenvalue: geometric multiplicity ≤ algebraic multiplicity&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;diagonalization&quot;&gt;Diagonalization&lt;/h2&gt;

&lt;p&gt;A matrix \(\mathbf{A}\) is &lt;strong&gt;diagonalizable&lt;/strong&gt; if it can be written as:&lt;/p&gt;

\[\mathbf{A} = \mathbf{P}\mathbf{D}\mathbf{P}^{-1}\]

&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{D}\) is a diagonal matrix of eigenvalues&lt;/li&gt;
  &lt;li&gt;\(\mathbf{P}\) is a matrix whose columns are the corresponding eigenvectors&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;benefits-of-diagonalization&quot;&gt;Benefits of Diagonalization&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Easy computation of powers:&lt;/strong&gt; \(\mathbf{A}^k = \mathbf{P}\mathbf{D}^k\mathbf{P}^{-1}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Understanding behavior:&lt;/strong&gt; The eigenvalues determine the transformation’s behavior along each eigenvector direction&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h2&gt;

&lt;p&gt;Eigenvalues and eigenvectors are crucial in optimization for several reasons:&lt;/p&gt;

&lt;h3 id=&quot;1-quadratic-forms-and-definiteness&quot;&gt;1. Quadratic Forms and Definiteness&lt;/h3&gt;

&lt;p&gt;For a quadratic function \(f(\mathbf{x}) = \mathbf{x}^T\mathbf{Q}\mathbf{x}\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Positive definite&lt;/strong&gt; (\(f(\mathbf{x}) &amp;gt; 0\) for \(\mathbf{x} \neq \mathbf{0}\)): All eigenvalues of \(\mathbf{Q}\) are positive&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Positive semidefinite&lt;/strong&gt; (\(f(\mathbf{x}) \geq 0\)): All eigenvalues are non-negative&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Negative definite&lt;/strong&gt; (\(f(\mathbf{x}) &amp;lt; 0\) for \(\mathbf{x} \neq \mathbf{0}\)): All eigenvalues are negative&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Indefinite&lt;/strong&gt; (\(f(\mathbf{x})\) can be positive or negative): Mixed positive and negative eigenvalues&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-second-order-optimality-conditions&quot;&gt;2. Second-Order Optimality Conditions&lt;/h3&gt;

&lt;p&gt;For a function \(f(\mathbf{x})\) at a critical point \(\mathbf{x}^*\) (where \(\nabla f(\mathbf{x}^*) = \mathbf{0}\)):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Local minimum:&lt;/strong&gt; Hessian \(\nabla^2 f(\mathbf{x}^*)\) is positive definite (all eigenvalues &amp;gt; 0)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Local maximum:&lt;/strong&gt; Hessian is negative definite (all eigenvalues &amp;lt; 0)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Saddle point:&lt;/strong&gt; Hessian is indefinite (mixed eigenvalues)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-principal-component-analysis-pca&quot;&gt;3. Principal Component Analysis (PCA)&lt;/h3&gt;

&lt;p&gt;PCA finds the directions of maximum variance in data:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Eigenvectors of the covariance matrix give the principal directions&lt;/li&gt;
  &lt;li&gt;Eigenvalues give the variance along each principal direction&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-convergence-analysis&quot;&gt;4. Convergence Analysis&lt;/h3&gt;

&lt;p&gt;In iterative optimization algorithms:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The &lt;strong&gt;condition number&lt;/strong&gt; \(\kappa = \frac{\lambda_{\max}}{\lambda_{\min}}\) affects convergence speed&lt;/li&gt;
  &lt;li&gt;Large condition numbers lead to slow convergence&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5-newtons-method&quot;&gt;5. Newton’s Method&lt;/h3&gt;

&lt;p&gt;Newton’s method uses the inverse Hessian:
\(\mathbf{x}_{k+1} = \mathbf{x}_k - [\nabla^2 f(\mathbf{x}_k)]^{-1} \nabla f(\mathbf{x}_k)\)&lt;/p&gt;

&lt;p&gt;The eigenvalues of the Hessian determine the method’s behavior and convergence rate.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;example-optimization-application&quot;&gt;Example: Optimization Application&lt;/h2&gt;

&lt;p&gt;Consider minimizing \(f(x, y) = 2x^2 + 3y^2 + 2xy\).&lt;/p&gt;

&lt;p&gt;The Hessian is: \(\mathbf{H} = \begin{pmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Finding eigenvalues:&lt;/strong&gt;
\(\det(\mathbf{H} - \lambda\mathbf{I}) = (4-\lambda)(6-\lambda) - 4 = \lambda^2 - 10\lambda + 20 = 0\)&lt;/p&gt;

\[\lambda = \frac{10 \pm \sqrt{100-80}}{2} = \frac{10 \pm 2\sqrt{5}}{2} = 5 \pm \sqrt{5}\]

&lt;p&gt;Since both eigenvalues are positive (\(\lambda_1 = 5 + \sqrt{5} &amp;gt; 0\) and \(\lambda_2 = 5 - \sqrt{5} &amp;gt; 0\)), the Hessian is positive definite, confirming that the origin is a global minimum.&lt;/p&gt;

&lt;p&gt;The condition number is \(\kappa = \frac{5 + \sqrt{5}}{5 - \sqrt{5}} \approx 4.24\), indicating reasonably good conditioning for optimization algorithms.&lt;/p&gt;

&lt;p&gt;Understanding eigenvalues and eigenvectors provides deep insights into the geometric and analytical properties of optimization problems, enabling better algorithm design and convergence analysis.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-02-02 Matrices and Linear Transformations</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_02_02_Matrices_and_Linear_Transformations/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_02_02_Matrices_and_Linear_Transformations</id>
   <content type="html">&lt;p&gt;A matrix is far more than a rectangular spreadsheet of numbers—it is a geometric operator that rotates, stretches, shears, and projects entire spaces. In optimization, every linear equality constraint \(Ax = b\) asks which inputs \(x\) land on a target \(b\) under the transformation \(A\), and the geometry of the solution set is governed completely by \(A\)’s column space (what is reachable) and nullspace (what directions remain invisible to \(A\)).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-matrices-as-geometric-operators&quot;&gt;Key ideas: Matrices as Geometric Operators&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Matrix Multiplication as Composition:&lt;/strong&gt; Multiplying \(BAx\) applies linear map \(A\) followed by \(B\)—the algebraic reason matrix products are associative yet generally non-commutative.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Column Space (Range):&lt;/strong&gt; \(\mathcal{R}(A) = \{Ax : x \in \mathbb{R}^n\}\) defines the exact set of right-hand sides \(b\) for which \(Ax = b\) is feasible.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nullspace (Kernel):&lt;/strong&gt; \(\mathcal{N}(A) = \{v : Av = 0\}\) collects all feasible step directions that leave \(Ax = b\) unchanged, turning any single feasible point \(x_p\) into the full affine feasible set \(x_p + \mathcal{N}(A)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rank–Nullity Theorem:&lt;/strong&gt; \(\text{rank}(A) + \dim(\mathcal{N}(A)) = n\) balances the number of independent constraints against the remaining free optimization dimensions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-parameterizing-a-feasible-set-via-nullspace&quot;&gt;Worked example: Parameterizing a Feasible Set via Nullspace&lt;/h3&gt;

&lt;p&gt;Consider the underdetermined linear constraint system \(Ax = b\) with&lt;/p&gt;

\[A = \begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 3 \end{pmatrix}, \qquad b = \begin{pmatrix} 4 \\ 9 \end{pmatrix}.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Row-reduce \([A \mid b]\) to RREF:&lt;/strong&gt; Subtract \(2 \times R_1\) from \(R_2\):
\(\begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; \mid &amp;amp; 4 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; \mid &amp;amp; 1 \end{pmatrix} \xrightarrow{R_1 \leftarrow R_1 - R_2} \begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; \mid &amp;amp; 3 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; \mid &amp;amp; 1 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Read off rank and free variables:&lt;/strong&gt; Pivot columns are columns 1 and 3, so \(\text{rank}(A) = 2\) and \(x_2 = t \in \mathbb{R}\) is free (\(\dim\mathcal{N}(A) = 3 - 2 = 1\), confirming Rank–Nullity \(2 + 1 = 3\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write the complete feasible set:&lt;/strong&gt;
\(x_1 = 3 - 2t, \quad x_2 = t, \quad x_3 = 1 \implies x(t) = \begin{pmatrix} 3 \\ 0 \\ 1 \end{pmatrix} + t\begin{pmatrix} -2 \\ 1 \\ 0 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify both parts:&lt;/strong&gt; \(A x_p = (3 + 0 + 1,\; 6 + 0 + 3)^T = (4, 9)^T = b\) and \(A v = (-2 + 2 + 0,\; -4 + 4 + 0)^T = (0, 0)^T\). Any optimization over \(Ax = b\) now collapses to a 1D problem in \(t\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This lesson covers matrices, matrix operations, and linear transformations, which are fundamental tools for representing and solving optimization problems.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;matrices-and-matrix-operations&quot;&gt;Matrices and Matrix Operations&lt;/h2&gt;

&lt;h3 id=&quot;what-is-a-matrix&quot;&gt;What is a Matrix?&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;matrix&lt;/strong&gt; is a rectangular grid of numbers arranged in rows and columns. Matrices represent data, transformations, systems of equations, and relationships between variables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;General Form:&lt;/strong&gt;
\(\mathbf{A} = \begin{pmatrix} 
a_{11} &amp;amp; a_{12} &amp;amp; \cdots &amp;amp; a_{1n} \\
a_{21} &amp;amp; a_{22} &amp;amp; \cdots &amp;amp; a_{2n} \\
\vdots &amp;amp; \vdots &amp;amp; \ddots &amp;amp; \vdots \\
a_{m1} &amp;amp; a_{m2} &amp;amp; \cdots &amp;amp; a_{mn}
\end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;This is an \(m \times n\) matrix (\(m\) rows, \(n\) columns).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;
\(\mathbf{A} = \begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 5 &amp;amp; 6 \end{pmatrix}\) is a \(2 \times 3\) matrix.&lt;/p&gt;

&lt;h3 id=&quot;matrix-addition&quot;&gt;Matrix Addition&lt;/h3&gt;

&lt;p&gt;Matrices are added by summing corresponding elements. Both matrices must have the same dimensions.&lt;/p&gt;

\[\mathbf{A} + \mathbf{B} = \begin{pmatrix} a_{11} + b_{11} &amp;amp; a_{12} + b_{12} \\ a_{21} + b_{21} &amp;amp; a_{22} + b_{22} \end{pmatrix}\]

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;
\(\begin{pmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{pmatrix} + \begin{pmatrix} 5 &amp;amp; 6 \\ 7 &amp;amp; 8 \end{pmatrix} = \begin{pmatrix} 6 &amp;amp; 8 \\ 10 &amp;amp; 12 \end{pmatrix}\)&lt;/p&gt;

&lt;h3 id=&quot;scalar-multiplication&quot;&gt;Scalar Multiplication&lt;/h3&gt;

&lt;p&gt;Multiply every element of the matrix by the scalar:&lt;/p&gt;

\[c\mathbf{A} = \begin{pmatrix} ca_{11} &amp;amp; ca_{12} \\ ca_{21} &amp;amp; ca_{22} \end{pmatrix}\]

&lt;h3 id=&quot;matrix-multiplication&quot;&gt;Matrix Multiplication&lt;/h3&gt;

&lt;p&gt;For matrices \(\mathbf{A}_{m \times n}\) and \(\mathbf{B}_{n \times p}\), the product \(\mathbf{C}_{m \times p}\) is formed by taking the dot product of rows from \(\mathbf{A}\) and columns from \(\mathbf{B}\):&lt;/p&gt;

\[c_{ij} = \sum_{k=1}^{n} a_{ik} b_{kj}\]

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;
\(\begin{pmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{pmatrix} \begin{pmatrix} 5 &amp;amp; 6 \\ 7 &amp;amp; 8 \end{pmatrix} = \begin{pmatrix} 1 \cdot 5 + 2 \cdot 7 &amp;amp; 1 \cdot 6 + 2 \cdot 8 \\ 3 \cdot 5 + 4 \cdot 7 &amp;amp; 3 \cdot 6 + 4 \cdot 8 \end{pmatrix} = \begin{pmatrix} 19 &amp;amp; 22 \\ 43 &amp;amp; 50 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; Matrix multiplication is &lt;strong&gt;not commutative&lt;/strong&gt;: \(\mathbf{AB} \neq \mathbf{BA}\) in general.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;linear-transformations&quot;&gt;Linear Transformations&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;linear transformation&lt;/strong&gt; is a function \(T: \mathbb{R}^n \to \mathbb{R}^m\) that preserves vector addition and scalar multiplication. Every linear transformation can be represented by a matrix.&lt;/p&gt;

&lt;h3 id=&quot;definition&quot;&gt;Definition&lt;/h3&gt;

&lt;p&gt;A transformation \(T(\mathbf{v}) = \mathbf{Av}\) is linear if and only if:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Additivity:&lt;/strong&gt; \(T(\mathbf{u} + \mathbf{v}) = T(\mathbf{u}) + T(\mathbf{v})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Homogeneity:&lt;/strong&gt; \(T(c\mathbf{v}) = cT(\mathbf{v})\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These can be combined into: \(T(c_1\mathbf{u} + c_2\mathbf{v}) = c_1T(\mathbf{u}) + c_2T(\mathbf{v})\)&lt;/p&gt;

&lt;h3 id=&quot;matrix-vector-multiplication&quot;&gt;Matrix-Vector Multiplication&lt;/h3&gt;

&lt;p&gt;If \(\mathbf{A}\) is an \(m \times n\) matrix and \(\mathbf{v}\) is an \(n \times 1\) column vector, their product \(\mathbf{Av}\) is an \(m \times 1\) column vector:&lt;/p&gt;

\[\mathbf{w} = \mathbf{Av} = \begin{pmatrix} 
a_{11}v_1 + a_{12}v_2 + \cdots + a_{1n}v_n \\
a_{21}v_1 + a_{22}v_2 + \cdots + a_{2n}v_n \\
\vdots \\
a_{m1}v_1 + a_{m2}v_2 + \cdots + a_{mn}v_n
\end{pmatrix}\]

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;
\(\begin{pmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 3 \end{pmatrix} \begin{pmatrix} 4 \\ 5 \end{pmatrix} = \begin{pmatrix} 2 \cdot 4 + 1 \cdot 5 \\ 0 \cdot 4 + 3 \cdot 5 \end{pmatrix} = \begin{pmatrix} 13 \\ 15 \end{pmatrix}\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;common-2d-transformations&quot;&gt;Common 2D Transformations&lt;/h2&gt;

&lt;p&gt;Understanding geometric transformations helps visualize how matrices affect vectors.&lt;/p&gt;

&lt;h3 id=&quot;scaling&quot;&gt;Scaling&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Scaling Matrix:&lt;/strong&gt;
\(\mathbf{S} = \begin{pmatrix} s_x &amp;amp; 0 \\ 0 &amp;amp; s_y \end{pmatrix}\)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Scales x-coordinates by \(s_x\) and y-coordinates by \(s_y\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Example:&lt;/strong&gt; \(\begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 3 \end{pmatrix}\) doubles x-values and triples y-values&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;rotation&quot;&gt;Rotation&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Rotation Matrix (counter-clockwise by angle \(\theta\)):&lt;/strong&gt;
\(\mathbf{R} = \begin{pmatrix} \cos\theta &amp;amp; -\sin\theta \\ \sin\theta &amp;amp; \cos\theta \end{pmatrix}\)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Example:&lt;/strong&gt; 90° rotation: \(\begin{pmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{pmatrix}\)&lt;/li&gt;
  &lt;li&gt;Transforms \((x, y) \mapsto (-y, x)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;reflection&quot;&gt;Reflection&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Reflection across x-axis:&lt;/strong&gt;
\(\mathbf{F}_x = \begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reflection across y-axis:&lt;/strong&gt;
\(\mathbf{F}_y = \begin{pmatrix} -1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reflection across line \(y = x\):&lt;/strong&gt;
\(\mathbf{F}_{y=x} = \begin{pmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{pmatrix}\)&lt;/p&gt;

&lt;h3 id=&quot;shearing&quot;&gt;Shearing&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Horizontal Shear:&lt;/strong&gt;
\(\mathbf{H} = \begin{pmatrix} 1 &amp;amp; k \\ 0 &amp;amp; 1 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;Transforms \((x, y) \mapsto (x + ky, y)\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;special-types-of-matrices&quot;&gt;Special Types of Matrices&lt;/h2&gt;

&lt;h3 id=&quot;identity-matrix&quot;&gt;Identity Matrix&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;identity matrix&lt;/strong&gt; \(\mathbf{I}\) acts like the number 1 for matrix multiplication:&lt;/p&gt;

\[\mathbf{I}_n = \begin{pmatrix} 
1 &amp;amp; 0 &amp;amp; \cdots &amp;amp; 0 \\
0 &amp;amp; 1 &amp;amp; \cdots &amp;amp; 0 \\
\vdots &amp;amp; \vdots &amp;amp; \ddots &amp;amp; \vdots \\
0 &amp;amp; 0 &amp;amp; \cdots &amp;amp; 1
\end{pmatrix}\]

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; \(\mathbf{AI} = \mathbf{IA} = \mathbf{A}\) for any compatible matrix \(\mathbf{A}\).&lt;/p&gt;

&lt;h3 id=&quot;transpose&quot;&gt;Transpose&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;transpose&lt;/strong&gt; \(\mathbf{A}^T\) flips a matrix across its main diagonal:&lt;/p&gt;

\[\text{If } \mathbf{A} = \begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 5 &amp;amp; 6 \end{pmatrix}, \text{ then } \mathbf{A}^T = \begin{pmatrix} 1 &amp;amp; 4 \\ 2 &amp;amp; 5 \\ 3 &amp;amp; 6 \end{pmatrix}\]

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[(\mathbf{A}^T)^T = \mathbf{A}\]
  &lt;/li&gt;
  &lt;li&gt;
\[(\mathbf{A} + \mathbf{B})^T = \mathbf{A}^T + \mathbf{B}^T\]
  &lt;/li&gt;
  &lt;li&gt;
\[(\mathbf{AB})^T = \mathbf{B}^T\mathbf{A}^T\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;symmetric-matrices&quot;&gt;Symmetric Matrices&lt;/h3&gt;

&lt;p&gt;A matrix is &lt;strong&gt;symmetric&lt;/strong&gt; if \(\mathbf{A} = \mathbf{A}^T\):&lt;/p&gt;

\[\mathbf{A} = \begin{pmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 2 &amp;amp; 4 &amp;amp; 5 \\ 3 &amp;amp; 5 &amp;amp; 6 \end{pmatrix}\]

&lt;p&gt;Symmetric matrices have special properties important in optimization.&lt;/p&gt;

&lt;h3 id=&quot;inverse-matrix&quot;&gt;Inverse Matrix&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;inverse&lt;/strong&gt; \(\mathbf{A}^{-1}\) of a square matrix \(\mathbf{A}\) satisfies:&lt;/p&gt;

\[\mathbf{A}\mathbf{A}^{-1} = \mathbf{A}^{-1}\mathbf{A} = \mathbf{I}\]

&lt;p&gt;&lt;strong&gt;For 2×2 matrices:&lt;/strong&gt;
\(\mathbf{A}^{-1} = \frac{1}{\det(\mathbf{A})} \begin{pmatrix} d &amp;amp; -b \\ -c &amp;amp; a \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;where \(\mathbf{A} = \begin{pmatrix} a &amp;amp; b \\ c &amp;amp; d \end{pmatrix}\) and \(\det(\mathbf{A}) = ad - bc\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Not all matrices have inverses. A matrix is &lt;strong&gt;invertible&lt;/strong&gt; (non-singular) if and only if its determinant is non-zero.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h2&gt;

&lt;p&gt;Matrices and linear transformations are fundamental in optimization for several reasons:&lt;/p&gt;

&lt;h3 id=&quot;1-system-of-linear-equations&quot;&gt;1. System of Linear Equations&lt;/h3&gt;

&lt;p&gt;Many optimization problems involve solving \(\mathbf{Ax} = \mathbf{b}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Unique solution:&lt;/strong&gt; \(\mathbf{x} = \mathbf{A}^{-1}\mathbf{b}\) (when \(\mathbf{A}\) is invertible)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Least squares:&lt;/strong&gt; Minimize \(\|\mathbf{Ax} - \mathbf{b}\|^2\) when no exact solution exists&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-quadratic-forms&quot;&gt;2. Quadratic Forms&lt;/h3&gt;

&lt;p&gt;Quadratic functions appear frequently in optimization:
\(f(\mathbf{x}) = \mathbf{x}^T\mathbf{Q}\mathbf{x} + \mathbf{c}^T\mathbf{x} + d\)&lt;/p&gt;

&lt;p&gt;The matrix \(\mathbf{Q}\) determines the curvature properties of the function.&lt;/p&gt;

&lt;h3 id=&quot;3-linear-programming&quot;&gt;3. Linear Programming&lt;/h3&gt;

&lt;p&gt;Standard form: Minimize \(\mathbf{c}^T\mathbf{x}\) subject to \(\mathbf{Ax} = \mathbf{b}\), \(\mathbf{x} \geq \mathbf{0}\)&lt;/p&gt;

&lt;h3 id=&quot;4-constraint-representation&quot;&gt;4. Constraint Representation&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Equality constraints:&lt;/strong&gt; \(\mathbf{Ax} = \mathbf{b}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inequality constraints:&lt;/strong&gt; \(\mathbf{Ax} \leq \mathbf{b}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5-transformations-of-variables&quot;&gt;5. Transformations of Variables&lt;/h3&gt;

&lt;p&gt;Change of variables: \(\mathbf{y} = \mathbf{T}\mathbf{x}\) can simplify optimization problems.&lt;/p&gt;

&lt;h3 id=&quot;example-portfolio-optimization&quot;&gt;Example: Portfolio Optimization&lt;/h3&gt;

&lt;p&gt;In finance, we might minimize portfolio risk:
\(\text{minimize } \mathbf{w}^T\mathbf{\Sigma}\mathbf{w}\)&lt;/p&gt;

&lt;p&gt;where \(\mathbf{w}\) is the vector of portfolio weights and \(\mathbf{\Sigma}\) is the covariance matrix of asset returns.&lt;/p&gt;

&lt;p&gt;Understanding matrices and linear transformations provides the tools to formulate, analyze, and solve a wide variety of optimization problems efficiently.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-02-01 Vectors and Vector Spaces</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_02_01_Vectors_and_Vector_Spaces/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_02_01_Vectors_and_Vector_Spaces</id>
   <content type="html">&lt;p&gt;When an operations researcher schedules 500 flights or a data scientist tunes 500 regression weights, those 500 numbers are not a messy list—they are a single point in \(\mathbb{R}^{500}\). Thinking in vector spaces lets us ask sharp structural questions: are some decision variables redundant (linearly dependent)? What is the true number of independent degrees of freedom (dimension)? And can we re-express our problem in a cleaner basis where constraints decouple?&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-of-mathbbrn-for-optimization&quot;&gt;Key ideas: Geometry of \(\mathbb{R}^n\) for Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vectors &amp;amp; Subspaces:&lt;/strong&gt; Feasible perturbations around an equality-constrained point \(Ax = b\) always form a linear subspace \(\{d : Ad = 0\}\) closed under addition and scaling.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Linear Independence:&lt;/strong&gt; Guarantees that no feature column or constraint direction is a redundant combination of the others—essential for unique least-squares and simplex basic solutions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Basis &amp;amp; Coordinate Representation:&lt;/strong&gt; A basis provides a minimal, non-redundant coordinate system so every vector in the space has a &lt;em&gt;unique&lt;/em&gt; expansion \(x = \sum c_i v_i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dimension:&lt;/strong&gt; Counts the true degrees of freedom of a subspace, letting us track how many variables remain free after imposing linear equality constraints.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-a-basis-and-finding-unique-coordinates-in-mathbbr3&quot;&gt;Worked example: Verifying a Basis and Finding Unique Coordinates in \(\mathbb{R}^3\)&lt;/h3&gt;

&lt;p&gt;Consider the three vectors \(v_1 = (1, 1, 0)^T\), \(v_2 = (0, 1, 1)^T\), and \(v_3 = (1, 0, 1)^T\), and target vector \(b = (3, 4, 3)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test linear independence via the determinant:&lt;/strong&gt; Assemble \(V = [v_1\; v_2\; v_3]\):
\(\det(V) = \det\begin{pmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 \end{pmatrix} = 1(1\cdot 1 - 0\cdot 1) - 0 + 1(1\cdot 1 - 1\cdot 0) = 1 + 1 = 2 \neq 0.\)
Because \(\det(V) \neq 0\), the three vectors are linearly independent and form a basis of \(\mathbb{R}^3\) (dimension 3).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve for the unique coordinates \(c_1 v_1 + c_2 v_2 + c_3 v_3 = b\):&lt;/strong&gt;
\(c_1 + c_3 = 3, \qquad c_1 + c_2 = 4, \qquad c_2 + c_3 = 3.\)
Adding all three equations gives \(2(c_1 + c_2 + c_3) = 10 \implies c_1 + c_2 + c_3 = 5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Subtract each equation from the sum:&lt;/strong&gt;
\(c_2 = 5 - 3 = 2, \qquad c_3 = 5 - 4 = 1, \qquad c_1 = 5 - 3 = 2.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify directly:&lt;/strong&gt; \(2(1, 1, 0)^T + 2(0, 1, 1)^T + 1(1, 0, 1)^T = (3, 4, 3)^T = b\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This lesson introduces vectors, vector spaces, and fundamental concepts that form the foundation for understanding linear algebra in optimization contexts.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;vectors-and-vector-spaces-mathbbrn&quot;&gt;Vectors and Vector Spaces (\(\mathbb{R}^n\))&lt;/h2&gt;

&lt;h3 id=&quot;what-is-a-vector&quot;&gt;What is a Vector?&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Vectors:&lt;/strong&gt; Think of a vector as an arrow in space, representing both a direction and a magnitude (length). Mathematically, it’s an ordered list of numbers, like coordinates. For example, a vector in 2D space could be \(\mathbf{v} = \begin{pmatrix} 3 \\ 4 \end{pmatrix}\), meaning 3 units along the x-axis and 4 units along the y-axis.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Geometric vs Algebraic View:&lt;/strong&gt;&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Geometric:&lt;/strong&gt; Vectors are arrows with direction and magnitude&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Algebraic:&lt;/strong&gt; Vectors are ordered lists of real numbers&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;vector-spaces&quot;&gt;Vector Spaces&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Vector Space (\(\mathbb{R}^n\)):&lt;/strong&gt; This is the collection of all possible vectors that have \(n\) components (numbers). For instance, \(\mathbb{R}^2\) includes all 2-component vectors, representing all points or arrows in a 2D plane.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\mathbb{R}^2 = \left\{\begin{pmatrix} x \\ y \end{pmatrix} : x, y \in \mathbb{R}\right\}\) (the plane)&lt;/li&gt;
      &lt;li&gt;\(\mathbb{R}^3 = \left\{\begin{pmatrix} x \\ y \\ z \end{pmatrix} : x, y, z \in \mathbb{R}\right\}\) (3D space)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;vector-operations&quot;&gt;Vector Operations&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vector Addition:&lt;/strong&gt;
\(\mathbf{u} + \mathbf{v} = \begin{pmatrix} u_1 \\ u_2 \\ \vdots \\ u_n \end{pmatrix} + \begin{pmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{pmatrix} = \begin{pmatrix} u_1 + v_1 \\ u_2 + v_2 \\ \vdots \\ u_n + v_n \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scalar Multiplication:&lt;/strong&gt;
\(c\mathbf{v} = c \begin{pmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{pmatrix} = \begin{pmatrix} cv_1 \\ cv_2 \\ \vdots \\ cv_n \end{pmatrix}\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;linear-independence-basis-and-dimension&quot;&gt;Linear Independence, Basis, and Dimension&lt;/h2&gt;

&lt;h3 id=&quot;linear-independence&quot;&gt;Linear Independence&lt;/h3&gt;

&lt;p&gt;A set of vectors \(\{\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_k\}\) is &lt;strong&gt;linearly independent&lt;/strong&gt; if the only solution to:&lt;/p&gt;

\[c_1\mathbf{v}_1 + c_2\mathbf{v}_2 + \cdots + c_k\mathbf{v}_k = \mathbf{0}\]

&lt;p&gt;is \(c_1 = c_2 = \cdots = c_k = 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intuitive Understanding:&lt;/strong&gt; A set of vectors is “linearly independent” if no vector in the set can be created by scaling and adding the other vectors in the set. They all point in “different enough” directions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example in \(\mathbb{R}^2\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\mathbf{v}_1 = \begin{pmatrix} 1 \\ 0 \end{pmatrix}\) and \(\mathbf{v}_2 = \begin{pmatrix} 0 \\ 1 \end{pmatrix}\) are linearly independent&lt;/li&gt;
  &lt;li&gt;\(\mathbf{v}_1 = \begin{pmatrix} 1 \\ 2 \end{pmatrix}\) and \(\mathbf{v}_2 = \begin{pmatrix} 2 \\ 4 \end{pmatrix}\) are linearly dependent (since \(\mathbf{v}_2 = 2\mathbf{v}_1\))&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;basis&quot;&gt;Basis&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;basis&lt;/strong&gt; for a vector space is a minimal set of linearly independent vectors that can be combined (scaled and added) to create &lt;em&gt;any&lt;/em&gt; other vector in that space. It’s like a fundamental set of building blocks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties of a Basis:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;The vectors are linearly independent&lt;/li&gt;
  &lt;li&gt;They span the entire vector space&lt;/li&gt;
  &lt;li&gt;Every vector in the space can be written uniquely as a linear combination of basis vectors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Standard Basis for \(\mathbb{R}^n\):&lt;/strong&gt;
\(\mathbf{e}_1 = \begin{pmatrix} 1 \\ 0 \\ \vdots \\ 0 \end{pmatrix}, \mathbf{e}_2 = \begin{pmatrix} 0 \\ 1 \\ \vdots \\ 0 \end{pmatrix}, \ldots, \mathbf{e}_n = \begin{pmatrix} 0 \\ 0 \\ \vdots \\ 1 \end{pmatrix}\)&lt;/p&gt;

&lt;h3 id=&quot;dimension&quot;&gt;Dimension&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;dimension&lt;/strong&gt; of a vector space is simply the number of vectors in any of its bases. It tells you how many independent directions are needed to describe the space.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[\dim(\mathbb{R}^2) = 2\]
  &lt;/li&gt;
  &lt;li&gt;
\[\dim(\mathbb{R}^3) = 3\]
  &lt;/li&gt;
  &lt;li&gt;
\[\dim(\mathbb{R}^n) = n\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;norms-of-vectors&quot;&gt;Norms of Vectors&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;norm&lt;/strong&gt; is a function that assigns a “length” or “size” to a vector. It generalizes the concept of distance from the origin.&lt;/p&gt;

&lt;h3 id=&quot;properties-of-norms&quot;&gt;Properties of Norms&lt;/h3&gt;

&lt;p&gt;Any norm \(\|\cdot\|\) must satisfy three properties:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Non-negativity:&lt;/strong&gt; \(\|\mathbf{x}\| \geq 0\), and \(\|\mathbf{x}\| = 0\) if and only if \(\mathbf{x} = \mathbf{0}\)&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Homogeneity:&lt;/strong&gt; $$|t\mathbf{x}| =&lt;/td&gt;
          &lt;td&gt;t&lt;/td&gt;
          &lt;td&gt;|\mathbf{x}|\(for any scalar\)t$$&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Triangle Inequality:&lt;/strong&gt; \(\|\mathbf{x} + \mathbf{y}\| \leq \|\mathbf{x}\| + \|\mathbf{y}\|\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;common-norms&quot;&gt;Common Norms&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Euclidean Norm (L2 Norm):&lt;/strong&gt;
\(\|\mathbf{x}\|_2 = \sqrt{\sum_{i=1}^n x_i^2} = \sqrt{x_1^2 + x_2^2 + \cdots + x_n^2}\)&lt;/p&gt;

&lt;p&gt;This is the “ordinary” distance we’re familiar with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Manhattan Norm (L1 Norm):&lt;/strong&gt;
\(\|\mathbf{x}\|_1 = \sum_{i=1}^n |x_i| = |x_1| + |x_2| + \cdots + |x_n|\)&lt;/p&gt;

&lt;p&gt;Also called “taxicab norm” - the distance a taxi would travel in a city with a grid layout.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Maximum Norm (L∞ Norm):&lt;/strong&gt;
\(\|\mathbf{x}\|_\infty = \max_{i} |x_i|\)&lt;/p&gt;

&lt;p&gt;The largest component in absolute value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; For \(\mathbf{x} = \begin{pmatrix} 3 \\ -4 \\ 1 \end{pmatrix}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[\|\mathbf{x}\|_2 = \sqrt{3^2 + (-4)^2 + 1^2} = \sqrt{26} \approx 5.1\]
  &lt;/li&gt;
  &lt;li&gt;
\[\|\mathbf{x}\|_1 = |3| + |-4| + |1| = 8\]
  &lt;/li&gt;
  &lt;li&gt;
\[\|\mathbf{x}\|_\infty = \max\{|3|, |-4|, |1|\} = 4\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;inner-products-dot-product&quot;&gt;Inner Products (Dot Product)&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;dot product&lt;/strong&gt; (or inner product) is the most common way to multiply two vectors, producing a scalar result.&lt;/p&gt;

&lt;h3 id=&quot;definition&quot;&gt;Definition&lt;/h3&gt;

&lt;p&gt;For two vectors \(\mathbf{x}\) and \(\mathbf{y}\) in \(\mathbb{R}^n\):&lt;/p&gt;

\[\mathbf{x}^T \mathbf{y} = \mathbf{x} \cdot \mathbf{y} = \sum_{i=1}^n x_i y_i = x_1 y_1 + x_2 y_2 + \cdots + x_n y_n\]

&lt;h3 id=&quot;geometric-interpretation&quot;&gt;Geometric Interpretation&lt;/h3&gt;

\[\mathbf{x} \cdot \mathbf{y} = \|\mathbf{x}\| \|\mathbf{y}\| \cos \theta\]

&lt;p&gt;where \(\theta\) is the angle between the vectors.&lt;/p&gt;

&lt;h3 id=&quot;properties&quot;&gt;Properties&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Commutative:&lt;/strong&gt; \(\mathbf{x} \cdot \mathbf{y} = \mathbf{y} \cdot \mathbf{x}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Distributive:&lt;/strong&gt; \(\mathbf{x} \cdot (\mathbf{y} + \mathbf{z}) = \mathbf{x} \cdot \mathbf{y} + \mathbf{x} \cdot \mathbf{z}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Homogeneous:&lt;/strong&gt; \((c\mathbf{x}) \cdot \mathbf{y} = c(\mathbf{x} \cdot \mathbf{y})\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;special-cases&quot;&gt;Special Cases&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Orthogonal vectors:&lt;/strong&gt; \(\mathbf{x} \cdot \mathbf{y} = 0\) (perpendicular)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parallel vectors:&lt;/strong&gt; \(\mathbf{x} \cdot \mathbf{y} = \pm \|\mathbf{x}\| \|\mathbf{y}\|\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Self dot product:&lt;/strong&gt; \(\mathbf{x} \cdot \mathbf{x} = \|\mathbf{x}\|_2^2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;example&quot;&gt;Example&lt;/h3&gt;

&lt;p&gt;For \(\mathbf{x} = \begin{pmatrix} 1 \\ 2 \end{pmatrix}\) and \(\mathbf{y} = \begin{pmatrix} 3 \\ 4 \end{pmatrix}\):&lt;/p&gt;

\[\mathbf{x}^T \mathbf{y} = (1)(3) + (2)(4) = 3 + 8 = 11\]

&lt;hr /&gt;

&lt;h2 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h2&gt;

&lt;p&gt;Understanding vectors and vector spaces is crucial for optimization because:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Decision Variables:&lt;/strong&gt; Optimization problems often involve finding the best values for multiple variables, naturally represented as vectors.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Gradients:&lt;/strong&gt; The gradient of a function is a vector pointing in the direction of steepest increase.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Constraints:&lt;/strong&gt; Linear constraints in optimization can be expressed using dot products: \(\mathbf{a}^T \mathbf{x} \leq b\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Distance and Similarity:&lt;/strong&gt; Different norms provide different ways to measure distances between solutions or the size of changes.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Orthogonality:&lt;/strong&gt; Many optimization concepts rely on perpendicularity, such as the relationship between gradients and level curves.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Linear Combinations:&lt;/strong&gt; Feasible regions are often defined as linear combinations of vectors (convex hulls, cones, etc.).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The vector space framework provides the mathematical foundation for formulating and solving optimization problems systematically.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01 Calculus</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_01_Calculus/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_01_Calculus</id>
   <content type="html">&lt;p&gt;Every iterative optimization algorithm is a disciplined way of taking steps in the dark using only local terrain measurements. Calculus provides the altimeter, the compass, and the curvature gauge: continuity ensures the terrain does not teleport beneath your feet, gradients tell you which way is downhill, and second derivatives tell you how steeply the ground bends so you do not overshoot the valley floor.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-how-calculus-powers-optimization&quot;&gt;Key ideas: How Calculus Powers Optimization&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/zero_fill/ch00_calculus_foundation.svg&quot; alt=&quot;Nền tảng Giải tích Đa biến cho Tối ưu hóa&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Continuity &amp;amp; Lipschitz Smoothness:&lt;/strong&gt; Guarantees that small parameter perturbations yield controlled changes in objective value and gradient, enabling step-size bounds that prevent divergence.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Derivatives &amp;amp; Gradients:&lt;/strong&gt; Characterize stationary points via \(\nabla f(x^*) = 0\) and identify steepest descent directions \(-\nabla f(x)\) in high-dimensional parameter spaces.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Directional Derivatives:&lt;/strong&gt; Project the gradient onto any candidate search direction \(d\) via \(\nabla f(x)^T d\), giving the exact algebraic test for a descent direction (\(\nabla f(x)^T d &amp;lt; 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Taylor Approximations:&lt;/strong&gt; Replace complex nonlinear functions locally with linear (first-order) or quadratic (second-order) surrogates—the direct foundation of gradient descent and Newton’s method.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-calculus-driven-step-of-gradient-descent&quot;&gt;Worked example: One Calculus-Driven Step of Gradient Descent&lt;/h3&gt;

&lt;p&gt;Take the smooth scalar objective \(f(x) = \frac{1}{2}x^2 - 3x + 5\) starting at \(x_0 = 0\) with step size \(\alpha = 0.5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate initial loss and slope:&lt;/strong&gt;
\(f(0) = 5, \qquad f&apos;(x) = x - 3 \implies f&apos;(0) = -3.\)
Because \(f&apos;(0) &amp;lt; 0\), moving in the positive direction decreases \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the gradient descent update:&lt;/strong&gt;
\(x_1 = x_0 - \alpha f&apos;(x_0) = 0 - 0.5(-3) = 1.5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Measure the decrease:&lt;/strong&gt;
\(f(1.5) = \frac{1}{2}(1.5)^2 - 3(1.5) + 5 = 1.125 - 4.5 + 5 = 1.625 &amp;lt; 5.\)&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Compare against the exact stationary point:&lt;/strong&gt; Setting \(f&apos;(x^*) = x^* - 3 = 0\) gives \(x^* = 3\) with \(f&apos;&apos;(3) = 1 &amp;gt; 0\) and global minimum \(f(3) = 0.5\). Notice that one step cut the distance to \(x^*\) exactly in half ($$&lt;/td&gt;
          &lt;td&gt;3 - 1.5&lt;/td&gt;
          &lt;td&gt;= 1.5\(vs.\)&lt;/td&gt;
          &lt;td&gt;3 - 0&lt;/td&gt;
          &lt;td&gt;= 3$$).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Optimization talks about &lt;em&gt;change&lt;/em&gt;: a step that decreases a loss, a constraint that becomes tight, a Taylor model that is locally accurate. That language is calculus. This overview is the map for the four calculus lessons that follow; it does not replace them.&lt;/p&gt;

&lt;h2 id=&quot;what-you-must-be-fluent-in&quot;&gt;What you must be fluent in&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Continuity&lt;/strong&gt; so that a descent sequence cannot jump over a minimizer, and so that a continuous function on a compact set attains its min (Weierstrass).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Derivatives and the multivariable chain rule&lt;/strong&gt;, because every neural-net gradient is a long chain rule — a story we return to in &lt;a href=&quot;/contents/en/chapter27/&quot;&gt;Chapter 27&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradients and directional derivatives.&lt;/strong&gt; The first-order model \(f(x+d) \approx f(x) + \nabla f(x)^\top d\) is the reason gradient descent (Chapter 06) works, and \(-\nabla f(x)\) is the locally steepest-descent direction in Euclidean geometry.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Taylor expansions.&lt;/strong&gt; Newton’s method (Chapter 14) is exactly the step that minimizes the local quadratic \(f(x) + \nabla f(x)^\top d + \tfrac12 d^\top \nabla^2 f(x)\, d\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A function \(f:\mathbb{R}^n\to\mathbb{R}\) is differentiable at \(x\) if&lt;/p&gt;

\[\lim_{\|h\|\to 0}\frac{f(x+h)-f(x)-\nabla f(x)^\top h}{\|h\|}=0.\]

&lt;p&gt;If \(\nabla f\) itself is Lipschitz, the descent lemma&lt;/p&gt;

\[f(y) \le f(x) + \nabla f(x)^\top(y-x) + \tfrac{L}{2}\|y-x\|_2^2\]

&lt;p&gt;gives the step-size restriction \(t \le 1/L\) used throughout first-order theory.&lt;/p&gt;

&lt;h2 id=&quot;lessons-in-this-block&quot;&gt;Lessons in this block&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Continuity and uniform continuity&lt;/li&gt;
  &lt;li&gt;Derivatives and multivariable calculus&lt;/li&gt;
  &lt;li&gt;Gradient and directional derivatives&lt;/li&gt;
  &lt;li&gt;Taylor series&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Read them in order, then try this check: write \(\nabla f\) and \(\nabla^2 f\) for \(f(x)=\tfrac12 x^\top Q x + q^\top x\) with \(Q\) symmetric. If that is automatic, you are ready for convex functions in Chapter 03.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01-04 Taylor Series</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_01_04_Taylor_Series/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_01_04_Taylor_Series</id>
   <content type="html">&lt;p&gt;Most real-world objective functions—log-likelihoods, cross-entropy losses, barrier functions—cannot be minimized in closed form. Optimization solves them by repeatedly replacing the complicated function around the current iterate \(x_k\) with a simpler polynomial model that we &lt;em&gt;can&lt;/em&gt; minimize analytically. First-order Taylor approximations yield tangent hyperplanes (and gradient descent), while second-order Taylor approximations yield quadratic bowls (and Newton’s method).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-local-polynomial-models-in-optimization&quot;&gt;Key ideas: Local Polynomial Models in Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Taylor Approximation:&lt;/strong&gt; \(f(x + h) \approx f(x) + \nabla f(x)^T h\) captures local slope; for convex functions, this affine tangent plane sits globally &lt;em&gt;below&lt;/em&gt; the function graph.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-Order Taylor Approximation:&lt;/strong&gt; Adds curvature via \(\frac{1}{2}h^T \nabla^2 f(x) h\); minimizing this quadratic model directly derives the Newton step \(h_{\text{nt}} = -[\nabla^2 f(x)]^{-1}\nabla f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Remainder Terms &amp;amp; Convergence Guarantees:&lt;/strong&gt; Bounding the Taylor remainder (via Lipschitz gradients or Hessians) converts qualitative intuition into exact descent lemmas like \(f(x + h) \le f(x) + \nabla f(x)^T h + \frac{L}{2}\|h\|^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Maclaurin Benchmarks:&lt;/strong&gt; Canonical expansions for \(e^x\), \(\ln(1+x)\), and \((1+x)^{-1}\) appear constantly in barrier methods, log-sum-exp smoothing, and complexity analyses.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-first--vs-second-order-multivariable-taylor-accuracy&quot;&gt;Worked example: First- vs. Second-Order Multivariable Taylor Accuracy&lt;/h3&gt;

&lt;p&gt;Approximate \(f(x, y) = \ln(1 + x + 2y)\) around \((0, 0)\) and evaluate at \(h = (0.1, 0.05)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Value and gradient at \((0, 0)\):&lt;/strong&gt;
\(f(0, 0) = \ln(1) = 0, \qquad \nabla f(x, y) = \frac{1}{1 + x + 2y}\begin{pmatrix} 1 \\ 2 \end{pmatrix} \implies \nabla f(0, 0) = \begin{pmatrix} 1 \\ 2 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hessian at \((0, 0)\):&lt;/strong&gt;
\(\nabla^2 f(x, y) = -\frac{1}{(1 + x + 2y)^2}\begin{pmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{pmatrix} \implies \nabla^2 f(0, 0) = -\begin{pmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate both Taylor models at \(h = (0.1, 0.05)^T\):&lt;/strong&gt; Note that \(\nabla f(0,0)^T h = 1(0.1) + 2(0.05) = 0.2\) and \(h^T \nabla^2 f(0,0) h = -(0.1 + 2(0.05))^2 = -0.04\).
    &lt;ul&gt;
      &lt;li&gt;First-order model: \(T_1(h) = 0 + 0.2 = 0.2000\).&lt;/li&gt;
      &lt;li&gt;Second-order model: \(T_2(h) = 0 + 0.2 + \frac{1}{2}(-0.04) = 0.1800\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare to the exact value:&lt;/strong&gt; \(f(0.1, 0.05) = \ln(1.2) \approx 0.18232\). Adding the quadratic Hessian term cuts the approximation error nearly eightfold, from \(0.01768\) down to \(0.00232\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This lesson covers Taylor series expansions, which are fundamental for approximating functions and understanding the local behavior of functions in optimization algorithms.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;taylor-series-definition&quot;&gt;Taylor Series Definition&lt;/h2&gt;

&lt;p&gt;The Taylor series is a representation of a function as an infinite sum of terms calculated from the values of the function’s derivatives at a single point. It provides a way to approximate complex functions using polynomials.&lt;/p&gt;

&lt;h3 id=&quot;single-variable-taylor-series&quot;&gt;Single Variable Taylor Series&lt;/h3&gt;

&lt;p&gt;A Taylor series is a series expansion of a function \(f(x)\) about a point \(a\):&lt;/p&gt;

\[f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n\]

&lt;p&gt;In expanded form:&lt;/p&gt;

\[f(x) = f(a) + \frac{f&apos;(a)}{1!}(x-a) + \frac{f&apos;&apos;(a)}{2!}(x-a)^2 + \frac{f&apos;&apos;&apos;(a)}{3!}(x-a)^3 + \dots\]

&lt;h3 id=&quot;maclaurin-series&quot;&gt;Maclaurin Series&lt;/h3&gt;

&lt;p&gt;When the expansion is around \(a = 0\), the Taylor series is called a &lt;strong&gt;Maclaurin series&lt;/strong&gt;:&lt;/p&gt;

\[f(x) = f(0) + f&apos;(0)x + \frac{f&apos;&apos;(0)}{2!}x^2 + \frac{f&apos;&apos;&apos;(0)}{3!}x^3 + \dots\]

&lt;h3 id=&quot;common-maclaurin-series&quot;&gt;Common Maclaurin Series&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Exponential Function:&lt;/strong&gt;
\(e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \dots = \sum_{n=0}^{\infty} \frac{x^n}{n!}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sine Function:&lt;/strong&gt;
\(\sin x = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \dots = \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n+1}}{(2n+1)!}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cosine Function:&lt;/strong&gt;
\(\cos x = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \frac{x^6}{6!} + \dots = \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n}}{(2n)!}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Natural Logarithm (for \(|x| &amp;lt; 1\)):&lt;/strong&gt;
\(\ln(1 + x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + \dots = \sum_{n=1}^{\infty} \frac{(-1)^{n+1} x^n}{n}\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;multivariable-taylor-series&quot;&gt;Multivariable Taylor Series&lt;/h2&gt;

&lt;p&gt;For functions of multiple variables, Taylor series become more complex but follow similar principles. The expansion around a point \(\mathbf{x}_0\) involves partial derivatives.&lt;/p&gt;

&lt;h3 id=&quot;first-order-taylor-expansion&quot;&gt;First-Order Taylor Expansion&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;linear approximation&lt;/strong&gt; of \(f(\mathbf{x})\) around \(\mathbf{x}_0\):&lt;/p&gt;

\[f(\mathbf{x}) \approx f(\mathbf{x}_0) + \nabla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0)\]

&lt;p&gt;This is the equation of the tangent plane to the function at \(\mathbf{x}_0\).&lt;/p&gt;

&lt;h3 id=&quot;second-order-taylor-expansion&quot;&gt;Second-Order Taylor Expansion&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;quadratic approximation&lt;/strong&gt; includes curvature information:&lt;/p&gt;

\[f(\mathbf{x}) \approx f(\mathbf{x}_0) + \nabla f(\mathbf{x}_0)^T (\mathbf{x} - \mathbf{x}_0) + \frac{1}{2} (\mathbf{x} - \mathbf{x}_0)^T \nabla^2 f(\mathbf{x}_0) (\mathbf{x} - \mathbf{x}_0)\]

&lt;p&gt;where \(\nabla^2 f(\mathbf{x}_0)\) is the Hessian matrix at \(\mathbf{x}_0\).&lt;/p&gt;

&lt;h3 id=&quot;general-form&quot;&gt;General Form&lt;/h3&gt;

&lt;p&gt;The complete multivariable Taylor series involves higher-order tensors:&lt;/p&gt;

\[f(\mathbf{x}) = \sum_{|\alpha|=0}^{\infty} \frac{D^{\alpha} f(\mathbf{x}_0)}{\alpha!} (\mathbf{x} - \mathbf{x}_0)^{\alpha}\]

&lt;p&gt;where \(\alpha = (\alpha_1, \alpha_2, \ldots, \alpha_n)\) is a multi-index.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h2&gt;

&lt;p&gt;Taylor series are fundamental to optimization theory and algorithms for several reasons:&lt;/p&gt;

&lt;h3 id=&quot;1-local-function-approximation&quot;&gt;1. Local Function Approximation&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Linear Approximation (First-Order Methods):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Used in gradient descent algorithms&lt;/li&gt;
  &lt;li&gt;Assumes the function is approximately linear in a small neighborhood&lt;/li&gt;
  &lt;li&gt;Step size must be small enough for the approximation to be valid&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Quadratic Approximation (Second-Order Methods):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Used in Newton’s method and quasi-Newton methods&lt;/li&gt;
  &lt;li&gt;Captures curvature information through the Hessian&lt;/li&gt;
  &lt;li&gt;Often provides faster convergence than first-order methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-optimality-conditions&quot;&gt;2. Optimality Conditions&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;First-Order Necessary Condition:&lt;/strong&gt;
At a local minimum \(\mathbf{x}^*\), we must have \(\nabla f(\mathbf{x}^*) = \mathbf{0}\).&lt;/p&gt;

&lt;p&gt;This comes from the first-order Taylor expansion: if \(\nabla f(\mathbf{x}^*) \neq \mathbf{0}\), we could move in the direction \(-\nabla f(\mathbf{x}^*)\) to decrease the function value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second-Order Sufficient Condition:&lt;/strong&gt;
If \(\nabla f(\mathbf{x}^*) = \mathbf{0}\) and \(\nabla^2 f(\mathbf{x}^*)\) is positive definite, then \(\mathbf{x}^*\) is a local minimum.&lt;/p&gt;

&lt;p&gt;This follows from the second-order Taylor expansion: the quadratic term dominates near \(\mathbf{x}^*\).&lt;/p&gt;

&lt;h3 id=&quot;3-algorithm-design&quot;&gt;3. Algorithm Design&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Newton’s Method:&lt;/strong&gt;
Uses the second-order Taylor approximation to find the minimum of the quadratic model:&lt;/p&gt;

\[\mathbf{x}_{k+1} = \mathbf{x}_k - [\nabla^2 f(\mathbf{x}_k)]^{-1} \nabla f(\mathbf{x}_k)\]

&lt;p&gt;&lt;strong&gt;Trust Region Methods:&lt;/strong&gt;
Use Taylor approximations within a trusted region where the approximation is believed to be accurate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Line Search Methods:&lt;/strong&gt;
Use Taylor expansions to determine appropriate step sizes along search directions.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;example-quadratic-function-analysis&quot;&gt;Example: Quadratic Function Analysis&lt;/h2&gt;

&lt;p&gt;Consider \(f(x, y) = x^2 + 2xy + 3y^2\) around the point \((0, 0)\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gradient:&lt;/strong&gt;
\(\nabla f = \begin{pmatrix} 2x + 2y \\ 2x + 6y \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;At \((0, 0)\): \(\nabla f(0, 0) = \begin{pmatrix} 0 \\ 0 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hessian:&lt;/strong&gt;
\(\nabla^2 f = \begin{pmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second-Order Taylor Expansion around \((0, 0)\):&lt;/strong&gt;
\(f(x, y) \approx f(0, 0) + 0 + \frac{1}{2} \begin{pmatrix} x &amp;amp; y \end{pmatrix} \begin{pmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix}\)&lt;/p&gt;

\[= 0 + \frac{1}{2}(2x^2 + 4xy + 6y^2) = x^2 + 2xy + 3y^2\]

&lt;p&gt;In this case, the function is exactly quadratic, so the second-order Taylor expansion is exact.&lt;/p&gt;

&lt;p&gt;Since the Hessian has eigenvalues \(\lambda_1 = 2 + 2\sqrt{2} &amp;gt; 0\) and \(\lambda_2 = 2 - 2\sqrt{2} &amp;lt; 0\), the point \((0, 0)\) is a saddle point, not a minimum.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;practical-considerations&quot;&gt;Practical Considerations&lt;/h2&gt;

&lt;h3 id=&quot;convergence-and-accuracy&quot;&gt;Convergence and Accuracy&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Radius of Convergence&lt;/strong&gt;: Taylor series only converge within a certain radius from the expansion point&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Truncation Error&lt;/strong&gt;: Using finite terms introduces approximation errors&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Computational Cost&lt;/strong&gt;: Higher-order terms require more derivative computations&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;optimization-algorithm-choice&quot;&gt;Optimization Algorithm Choice&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;First-order methods&lt;/strong&gt; (gradient descent): Use only gradient information, slower but cheaper per iteration&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-order methods&lt;/strong&gt; (Newton): Use Hessian information, faster convergence but expensive per iteration&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quasi-Newton methods&lt;/strong&gt;: Approximate the Hessian, balancing speed and computational cost&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Taylor series expansion helps us approximate complex functions with simpler polynomial functions around a specific point, which is vital for optimization algorithms and understanding local behavior of functions.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01-03 Gradient and Directional Derivatives</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_01_03_Gradient_and_Directional_Derivatives/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_01_03_Gradient_and_Directional_Derivatives</id>
   <content type="html">&lt;p&gt;Picture standing on a foggy mountain ridge in 100 dimensions: you cannot see the valley floor, only the tilt of the ground right under your boots. If you choose an arbitrary compass heading \(u\), how fast will your altitude change? The directional derivative answers that question for any heading, and Cauchy–Schwarz reveals a remarkable fact: among all unit-length headings, the negative gradient \(-\nabla f / \|\nabla f\|\) is guaranteed to drop your altitude faster than any other direction.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-steering-descent-in-mathbbrn&quot;&gt;Key ideas: Steering Descent in \(\mathbb{R}^n\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;The Gradient as Steepest Ascent:&lt;/strong&gt; The vector \(\nabla f(x)\) points orthogonally to the contour line passing through \(x\) in the direction of maximum instantaneous increase.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Directional Derivative (\(D_u f(x)\)):&lt;/strong&gt; Measures the rate of change along a unit vector \(u\) via the inner product \(D_u f(x) = \nabla f(x)^T u = \|\nabla f(x)\|\cos\theta\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Descent Direction Criterion:&lt;/strong&gt; Any vector \(d\) satisfying \(\nabla f(x)^T d &amp;lt; 0\) (an obtuse angle with \(\nabla f(x)\)) is guaranteed to decrease \(f(x + td)\) for sufficiently small \(t &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimality via Zero Slope in All Directions:&lt;/strong&gt; If \(D_u f(x^*) = 0\) for every unit vector \(u\), then \(\nabla f(x^*) = \mathbf{0}\), signaling a stationary point.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-testing-a-candidate-descent-direction&quot;&gt;Worked example: Testing a Candidate Descent Direction&lt;/h3&gt;

&lt;p&gt;Let \(f(x, y) = 3x^2 - 2xy + y^2\) at the point \(p = (1, 2)\), and consider moving in the direction of \(v = (3, -4)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the gradient at \(p = (1, 2)\):&lt;/strong&gt;
\(\nabla f(x, y) = \begin{pmatrix} 6x - 2y \\ -2x + 2y \end{pmatrix} \implies \nabla f(1, 2) = \begin{pmatrix} 6(1) - 2(2) \\ -2(1) + 2(2) \end{pmatrix} = \begin{pmatrix} 2 \\ 2 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Normalize the direction vector \(v\):&lt;/strong&gt;
\(\|v\|_2 = \sqrt{3^2 + (-4)^2} = 5 \implies u = \frac{v}{\|v\|_2} = \begin{pmatrix} 3/5 \\ -4/5 \end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the directional derivative \(D_u f(1, 2)\):&lt;/strong&gt;
\(D_u f(1, 2) = \nabla f(1, 2)^T u = 2\left(\frac{3}{5}\right) + 2\left(-\frac{4}{5}\right) = \frac{6 - 8}{5} = -\frac{2}{5} = -0.4.\)
Because \(D_u f(1, 2) &amp;lt; 0\), \(u\) is a valid descent direction.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with steepest descent:&lt;/strong&gt; The steepest descent unit vector is
\(u_{\text{best}} = -\frac{\nabla f(1, 2)}{\|\nabla f(1, 2)\|_2} = \begin{pmatrix} -1/\sqrt{2} \\ -1/\sqrt{2} \end{pmatrix},\)
which achieves a much faster initial rate of decrease: \(D_{u_{\text{best}}} f(1, 2) = -\|\nabla f(1, 2)\|_2 = -2\sqrt{2} \approx -2.828\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This lesson explores the gradient vector and directional derivatives, which are central concepts in optimization for understanding how functions change in different directions.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;gradient-vector&quot;&gt;Gradient Vector&lt;/h2&gt;

&lt;p&gt;The gradient \(\nabla f\) is a vector composed of the partial derivatives of the function \(f\) with respect to each of its variables. It indicates the direction of the steepest ascent of the function at a given point.&lt;/p&gt;

&lt;h3 id=&quot;definition-and-computation&quot;&gt;Definition and Computation&lt;/h3&gt;

&lt;p&gt;For a function of two variables, \(f(x, y)\), its gradient is:&lt;/p&gt;

\[\nabla f = \begin{pmatrix} \frac{\partial f}{\partial x} \\ \frac{\partial f}{\partial y} \end{pmatrix}\]

&lt;p&gt;For a function of \(n\) variables, \(f(x_1, x_2, \ldots, x_n)\):&lt;/p&gt;

\[\nabla f = \begin{pmatrix} \frac{\partial f}{\partial x_1} \\ \frac{\partial f}{\partial x_2} \\ \vdots \\ \frac{\partial f}{\partial x_n} \end{pmatrix}\]

&lt;h3 id=&quot;example-computing-a-gradient&quot;&gt;Example: Computing a Gradient&lt;/h3&gt;

&lt;p&gt;For \(f(x, y) = x^2 + 3xy + y^2\):&lt;/p&gt;

&lt;p&gt;\(\frac{\partial f}{\partial x} = 2x + 3y\)
\(\frac{\partial f}{\partial y} = 3x + 2y\)&lt;/p&gt;

&lt;p&gt;Therefore: \(\nabla f = \begin{pmatrix} 2x + 3y \\ 3x + 2y \end{pmatrix}\)&lt;/p&gt;

&lt;p&gt;At the point \((1, 2)\): \(\nabla f(1, 2) = \begin{pmatrix} 2(1) + 3(2) \\ 3(1) + 2(2) \end{pmatrix} = \begin{pmatrix} 8 \\ 7 \end{pmatrix}\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;directional-derivatives&quot;&gt;Directional Derivatives&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;directional derivative&lt;/strong&gt; measures the rate of change of \(f\) when we move in any chosen direction \(\mathbf{u}\). Here \(\mathbf{u}\) must be a unit vector (length 1).&lt;/p&gt;

&lt;h3 id=&quot;definition&quot;&gt;Definition&lt;/h3&gt;

&lt;p&gt;For a function \(f(\mathbf{x})\) and unit vector \(\mathbf{u} = \langle u_1, u_2, \ldots, u_n \rangle\):&lt;/p&gt;

\[D_{\mathbf{u}}f(\mathbf{x}) = \nabla f(\mathbf{x}) \cdot \mathbf{u} = \sum_{i=1}^{n} \frac{\partial f}{\partial x_i} u_i\]

&lt;h3 id=&quot;geometric-interpretation&quot;&gt;Geometric Interpretation&lt;/h3&gt;

&lt;p&gt;The directional derivative can be written as:&lt;/p&gt;

\[D_{\mathbf{u}}f = \lvert \nabla f \rvert \cos \theta\]

&lt;p&gt;where \(\theta\) is the angle between \(\nabla f\) and \(\mathbf{u}\), and \(\lvert \nabla f \rvert\) is the magnitude of the gradient.&lt;/p&gt;

&lt;h3 id=&quot;example-computing-directional-derivatives&quot;&gt;Example: Computing Directional Derivatives&lt;/h3&gt;

&lt;p&gt;Using our previous example \(f(x, y) = x^2 + 3xy + y^2\) at point \((1, 2)\) where \(\nabla f(1, 2) = \begin{pmatrix} 8 \\ 7 \end{pmatrix}\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Direction 1:&lt;/strong&gt; \(\mathbf{u}_1 = \begin{pmatrix} 1 \\ 0 \end{pmatrix}\) (positive x-direction)
\(D_{\mathbf{u}_1}f(1, 2) = 8 \cdot 1 + 7 \cdot 0 = 8\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Direction 2:&lt;/strong&gt; \(\mathbf{u}_2 = \begin{pmatrix} 0 \\ 1 \end{pmatrix}\) (positive y-direction)
\(D_{\mathbf{u}_2}f(1, 2) = 8 \cdot 0 + 7 \cdot 1 = 7\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Direction 3:&lt;/strong&gt; \(\mathbf{u}_3 = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 1 \end{pmatrix}\) (45° diagonal)
\(D_{\mathbf{u}_3}f(1, 2) = 8 \cdot \frac{1}{\sqrt{2}} + 7 \cdot \frac{1}{\sqrt{2}} = \frac{15}{\sqrt{2}} \approx 10.61\)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;maximum-and-minimum-rates-of-change&quot;&gt;Maximum and Minimum Rates of Change&lt;/h2&gt;

&lt;h3 id=&quot;key-properties&quot;&gt;Key Properties&lt;/h3&gt;

&lt;p&gt;From the formula \(D_{\mathbf{u}}f = \lvert \nabla f \rvert \cos \theta\), we can determine:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Maximum Rate of Change&lt;/strong&gt;: Occurs when \(\cos \theta = 1\) (i.e., \(\theta = 0°\))
    &lt;ul&gt;
      &lt;li&gt;Direction: \(\mathbf{u} = \frac{\nabla f}{\lvert \nabla f \rvert}\) (same direction as gradient)&lt;/li&gt;
      &lt;li&gt;Maximum rate: \(D_{\max}f = \lvert \nabla f \rvert\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimum Rate of Change&lt;/strong&gt;: Occurs when \(\cos \theta = -1\) (i.e., \(\theta = 180°\))
    &lt;ul&gt;
      &lt;li&gt;Direction: \(\mathbf{u} = -\frac{\nabla f}{\lvert \nabla f \rvert}\) (opposite to gradient)&lt;/li&gt;
      &lt;li&gt;Minimum rate: \(D_{\min}f = -\lvert \nabla f \rvert\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Zero Rate of Change&lt;/strong&gt;: Occurs when \(\cos \theta = 0\) (i.e., \(\theta = 90°\))
    &lt;ul&gt;
      &lt;li&gt;Direction: Any vector perpendicular to \(\nabla f\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;summary-of-gradient-properties&quot;&gt;Summary of Gradient Properties&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;The gradient \(\nabla f\) points in the direction of &lt;strong&gt;steepest increase&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;The direction \(-\nabla f\) points in the direction of &lt;strong&gt;steepest decrease&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;The magnitude \(\lvert \nabla f \rvert\) gives the &lt;strong&gt;maximum rate of change&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;When \(\nabla f = \mathbf{0}\), the point is a &lt;strong&gt;critical point&lt;/strong&gt; (potential optimum)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;relation-to-level-curves&quot;&gt;Relation to Level Curves&lt;/h2&gt;

&lt;p&gt;At any point on a level curve \(f(x, y) = c\), the gradient vector \(\nabla f\) is &lt;strong&gt;orthogonal (perpendicular)&lt;/strong&gt; to the tangent line of the level curve at that point.&lt;/p&gt;

&lt;h3 id=&quot;why-this-matters&quot;&gt;Why This Matters&lt;/h3&gt;

&lt;p&gt;This orthogonality property is fundamental because:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Level curves represent constant function values&lt;/strong&gt;: Moving along a level curve doesn’t change the function value, so the directional derivative is zero.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Gradient points to steepest increase&lt;/strong&gt;: The direction that increases the function value most rapidly must be perpendicular to the direction that doesn’t change it at all.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Optimization insight&lt;/strong&gt;: To find extrema, we look for points where the gradient is zero (critical points) or where the gradient is perpendicular to the constraint boundary.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h3&gt;

&lt;p&gt;Understanding gradients and directional derivatives is crucial for:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Descent&lt;/strong&gt;: Moving in the direction \(-\nabla f\) to minimize \(f\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Ascent&lt;/strong&gt;: Moving in the direction \(+\nabla f\) to maximize \(f\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constrained Optimization&lt;/strong&gt;: Using the relationship between gradients and level curves&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence Analysis&lt;/strong&gt;: Understanding when algorithms will converge to optimal solutions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step Size Selection&lt;/strong&gt;: Determining how far to move in the gradient direction&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The gradient provides both the direction to move and information about how quickly the function is changing, making it the foundation for most optimization algorithms.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01-02 Derivatives and Multivariable Calculus</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_01_02_Derivatives_and_Multivariable_Calculus/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_01_02_Derivatives_and_Multivariable_Calculus</id>
   <content type="html">&lt;p&gt;Training a modern machine learning model means tuning millions of coupled parameters simultaneously, where nudging one weight ripples through composite layers of transformations. Single-variable slopes are no longer enough: you need partial derivatives to isolate coordinate sensitivities, the gradient to assemble them into a vector, the Hessian to read local bowl-versus-saddle curvature, and the multivariable chain rule—the exact mathematical engine behind backpropagation.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-multivariable-differential-calculus-in-optimization&quot;&gt;Key ideas: Multivariable Differential Calculus in Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Partial Derivatives &amp;amp; Level Curves:&lt;/strong&gt; Partial derivatives measure change along coordinate axes, while level curves \(f(x,y) = c\) visualize the landscape; the gradient always cuts perpendicularly across level sets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Vector (\(\nabla f\)):&lt;/strong&gt; Packages all first-order partial derivatives into a single vector in \(\mathbb{R}^n\) whose vanishing (\(\nabla f(x^*) = \mathbf{0}\)) is necessary for unconstrained local optimality.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hessian Matrix (\(\nabla^2 f\)):&lt;/strong&gt; Collects all second-order partial derivatives into a symmetric \(n \times n\) matrix; its positive semidefiniteness certifies local convexity and distinguishes minima from saddles.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multivariable Chain Rule:&lt;/strong&gt; Computes derivatives of composed functions \(g(t) = f(x(t))\) via \(g&apos;(t) = \nabla f(x(t))^T x&apos;(t)\), enabling exact differentiation along optimization trajectories and through neural network layers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-gradient-hessian-and-chain-rule-on-fx-y--ex2--y&quot;&gt;Worked example: Gradient, Hessian, and Chain Rule on \(f(x, y) = e^{x^2 + y}\)&lt;/h3&gt;

&lt;p&gt;Evaluate the local calculus of \(f(x, y) = e^{x^2 + y}\) at \((0, 0)\) and along the path \(\gamma(t) = (t, 2t)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;First-order partial derivatives (Gradient):&lt;/strong&gt;
\(\frac{\partial f}{\partial x} = 2x e^{x^2 + y}, \qquad \frac{\partial f}{\partial y} = e^{x^2 + y}.\)
At \((0, 0)\), \(\nabla f(0, 0) = \begin{pmatrix} 0 \\ 1 \end{pmatrix}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-order partial derivatives (Hessian):&lt;/strong&gt;
\(\frac{\partial^2 f}{\partial x^2} = (2 + 4x^2)e^{x^2 + y}, \quad \frac{\partial^2 f}{\partial x \partial y} = 2x e^{x^2 + y}, \quad \frac{\partial^2 f}{\partial y^2} = e^{x^2 + y}.\)
At \((0, 0)\),
\(\nabla^2 f(0, 0) = \begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix},\)
which is strictly positive definite (eigenvalues \(2\) and \(1\)), meaning \(f\) curves upward in every direction around the origin.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chain rule along \(\gamma(t) = (t, 2t)\) at \(t = 0\):&lt;/strong&gt; With \(\gamma&apos;(0) = (1, 2)^T\),
\(\left.\frac{d}{dt} f(\gamma(t))\right|_{t=0} = \nabla f(0, 0)^T \gamma&apos;(0) = \begin{pmatrix} 0 &amp;amp; 1 \end{pmatrix}\begin{pmatrix} 1 \\ 2 \end{pmatrix} = 2.\)
&lt;em&gt;Hand check:&lt;/em&gt; Directly substituting gives \(f(t, 2t) = e^{t^2 + 2t}\), whose derivative \((2t + 2)e^{t^2 + 2t}\) at \(t = 0\) is indeed \(2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This lesson covers derivatives and essential multivariable calculus concepts that form the foundation for optimization theory and algorithms.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;derivatives-and-rate-of-change&quot;&gt;Derivatives and Rate of Change&lt;/h2&gt;

&lt;p&gt;The derivative of a single variable function represents its instantaneous rate of change, which is fundamental to understanding how functions behave locally.&lt;/p&gt;

&lt;h3 id=&quot;basic-derivative-concepts&quot;&gt;Basic Derivative Concepts&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Slope between two points:&lt;/strong&gt;&lt;/p&gt;

\[\text{Slope} = \frac{y_2 - y_1}{x_2 - x_1}\]

&lt;p&gt;&lt;strong&gt;Derivative (instantaneous rate of change):&lt;/strong&gt;&lt;/p&gt;

\[f&apos;(x_0) = \lim_{x_1 \to x_0} \frac{f(x_1) - f(x_0)}{x_1 - x_0} = \lim_{\Delta x \to 0} \frac{f(x_0 + \Delta x) - f(x_0)}{\Delta x}\]

&lt;p&gt;The derivative tells us how quickly the function is changing at any given point, which is essential for finding optimal points where the rate of change is zero.&lt;/p&gt;

&lt;h3 id=&quot;level-curves-of-functions&quot;&gt;Level Curves of Functions&lt;/h3&gt;

&lt;p&gt;Level curves are a fundamental concept in multivariable calculus used to visualize functions of two variables, typically denoted as \(f(x, y)\). They provide a way to represent a 3D surface in a 2D plane.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;level curve&lt;/strong&gt; of a function \(f(x, y)\) is the set of all points \((x, y)\) in the domain of \(f\) where the function takes a constant value:&lt;/p&gt;

\[f(x, y) = c\]

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;For \(f(x, y) = x^2 + y^2\), the level curves are circles: \(x^2 + y^2 = c\)&lt;/li&gt;
  &lt;li&gt;For \(f(x, y) = x + y\), the level curves are parallel lines: \(x + y = c\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Level curves help us understand:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;The topography of the function&lt;/li&gt;
  &lt;li&gt;Directions of steepest ascent and descent&lt;/li&gt;
  &lt;li&gt;Locations of potential optima&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;multivariable-calculus-key-concepts&quot;&gt;Multivariable Calculus Key Concepts&lt;/h2&gt;

&lt;h3 id=&quot;partial-derivatives&quot;&gt;Partial Derivatives&lt;/h3&gt;

&lt;p&gt;For a function \(f(x_1, x_2, \ldots, x_n)\), the &lt;strong&gt;partial derivative&lt;/strong&gt; with respect to \(x_i\) is:&lt;/p&gt;

\[\frac{\partial f}{\partial x_i} = \lim_{h \to 0} \frac{f(x_1, \ldots, x_i + h, \ldots, x_n) - f(x_1, \ldots, x_i, \ldots, x_n)}{h}\]

&lt;p&gt;This measures how \(f\) changes when only \(x_i\) varies while all other variables remain fixed.&lt;/p&gt;

&lt;h3 id=&quot;gradient-vector&quot;&gt;Gradient Vector&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;gradient&lt;/strong&gt; is a vector composed of all partial derivatives:&lt;/p&gt;

\[\nabla f(\mathbf{x}) = \begin{pmatrix} \frac{\partial f}{\partial x_1} \\ \frac{\partial f}{\partial x_2} \\ \vdots \\ \frac{\partial f}{\partial x_n} \end{pmatrix}\]

&lt;p&gt;The gradient points in the direction of steepest increase of the function and is perpendicular to level curves.&lt;/p&gt;

&lt;h3 id=&quot;hessian-matrix&quot;&gt;Hessian Matrix&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Hessian matrix&lt;/strong&gt; contains all second-order partial derivatives:&lt;/p&gt;

\[\nabla^2 f(\mathbf{x}) = \mathbf{H} = \begin{pmatrix} 
\frac{\partial^2 f}{\partial x_1^2} &amp;amp; \frac{\partial^2 f}{\partial x_1 \partial x_2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_1 \partial x_n} \\
\frac{\partial^2 f}{\partial x_2 \partial x_1} &amp;amp; \frac{\partial^2 f}{\partial x_2^2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_2 \partial x_n} \\
\vdots &amp;amp; \vdots &amp;amp; \ddots &amp;amp; \vdots \\
\frac{\partial^2 f}{\partial x_n \partial x_1} &amp;amp; \frac{\partial^2 f}{\partial x_n \partial x_2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_n^2}
\end{pmatrix}\]

&lt;p&gt;The Hessian provides information about the curvature of the function and is crucial for:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Determining the nature of critical points (minimum, maximum, or saddle point)&lt;/li&gt;
  &lt;li&gt;Second-order optimization methods like Newton’s method&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;chain-rule-for-multivariable-functions&quot;&gt;Chain Rule for Multivariable Functions&lt;/h2&gt;

&lt;p&gt;The chain rule is fundamental for computing derivatives of composite functions, which frequently appear in optimization problems.&lt;/p&gt;

&lt;h3 id=&quot;basic-chain-rule&quot;&gt;Basic Chain Rule&lt;/h3&gt;

&lt;p&gt;For a function \(z = f(x, y)\) where \(x = g(t)\) and \(y = h(t)\):&lt;/p&gt;

\[\frac{dz}{dt} = \frac{\partial f}{\partial x} \frac{dx}{dt} + \frac{\partial f}{\partial y} \frac{dy}{dt}\]

&lt;h3 id=&quot;general-chain-rule&quot;&gt;General Chain Rule&lt;/h3&gt;

&lt;p&gt;For \(z = f(x_1, x_2, \ldots, x_n)\) where each \(x_i = x_i(t_1, t_2, \ldots, t_m)\):&lt;/p&gt;

\[\frac{\partial z}{\partial t_j} = \sum_{i=1}^{n} \frac{\partial f}{\partial x_i} \frac{\partial x_i}{\partial t_j}\]

&lt;h3 id=&quot;applications-in-optimization&quot;&gt;Applications in Optimization&lt;/h3&gt;

&lt;p&gt;The chain rule is essential for:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gradient Computation&lt;/strong&gt;: Computing gradients of composite objective functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constraint Handling&lt;/strong&gt;: Dealing with constraints that are functions of other variables&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm Implementation&lt;/strong&gt;: Backpropagation in neural networks and automatic differentiation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity Analysis&lt;/strong&gt;: Understanding how changes in parameters affect optimal solutions&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;example-optimization-with-constraints&quot;&gt;Example: Optimization with Constraints&lt;/h3&gt;

&lt;p&gt;Consider minimizing \(f(x, y) = x^2 + y^2\) subject to \(g(x, y) = x + y - 1 = 0\).&lt;/p&gt;

&lt;p&gt;Using the constraint to eliminate one variable: \(y = 1 - x\), so we minimize:
\(h(x) = f(x, 1-x) = x^2 + (1-x)^2\)&lt;/p&gt;

&lt;p&gt;Using the chain rule:
\(h&apos;(x) = \frac{\partial f}{\partial x} \cdot 1 + \frac{\partial f}{\partial y} \cdot \frac{d(1-x)}{dx} = 2x + 2(1-x)(-1) = 4x - 2\)&lt;/p&gt;

&lt;p&gt;Setting \(h&apos;(x) = 0\) gives \(x = 1/2\), so the optimal point is \((1/2, 1/2)\).&lt;/p&gt;

&lt;p&gt;This demonstrates how multivariable calculus concepts work together to solve optimization problems systematically.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01-01 Continuity and Uniform Continuity</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_01_01_Continuity_and_Uniform_Continuity/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter00/00_01_01_Continuity_and_Uniform_Continuity</id>
   <content type="html">&lt;p&gt;Suppose you are calibrating a robotic arm’s torque controller: if a tiny \(0.001\)-radian sensor jitter causes a sudden jump in predicted energy cost, no line-search algorithm can trust its own step sizes. Worse yet, even if a function is continuous at every individual point, its slope might blow up near the edge of the domain, forcing step sizes to shrink unpredictably. Distinguishing ordinary continuity, uniform continuity, and Lipschitz continuity is how analysts guarantee that a &lt;em&gt;single&lt;/em&gt; global step size works across the entire optimization domain.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-hierarchy-of-function-regularity&quot;&gt;Key ideas: The Hierarchy of Function Regularity&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pointwise Continuity:&lt;/strong&gt; Guarantees no sudden jumps at a fixed point \(c\), but the allowable input tolerance \(\delta(\varepsilon, c)\) may depend heavily on &lt;em&gt;where&lt;/em&gt; \(c\) sits in the domain.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Uniform Continuity:&lt;/strong&gt; Upgrades the guarantee so that one tolerance \(\delta(\varepsilon)\) works simultaneously everywhere on the domain—automatically achieved by any continuous function on a compact set (Heine–Cantor theorem).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Lipschitz Continuity:&lt;/strong&gt; Enforces a uniform global bound $$&lt;/td&gt;
          &lt;td&gt;f(x) - f(y)&lt;/td&gt;
          &lt;td&gt;\le L|x - y|$$ on how fast outputs can change per unit input, directly controlling subgradient norms and convergence rates.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strict Inclusion Hierarchy:&lt;/strong&gt; \(\text{Lipschitz Continuous} \subset \text{Uniformly Continuous} \subset \text{Continuous}\)—knowing which tier an objective occupies determines which convergence theorems apply.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-fx--x2-is-lipschitz-on-0-2-but-not-uniformly-continuous-on-0-infty&quot;&gt;Worked example: Why \(f(x) = x^2\) Is Lipschitz on \([0, 2]\) but Not Uniformly Continuous on \([0, \infty)\)&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bounded domain \([0, 2]\) (Lipschitz proof):&lt;/strong&gt; For any \(x, y \in [0, 2]\), factor the difference:
\(|f(x) - f(y)| = |x^2 - y^2| = |x + y|\,|x - y|.\)
Since \(0 \le x, y \le 2\), we have \(|x + y| \le 4\), so
\(|f(x) - f(y)| \le 4|x - y|.\)
Thus \(f\) is Lipschitz continuous on \([0, 2]\) with Lipschitz constant \(L = 4\) (and hence uniformly continuous with \(\delta = \varepsilon / 4\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unbounded domain \([0, \infty)\) (failure of uniform continuity):&lt;/strong&gt; Choose \(\varepsilon = 1\) and test the sequences \(x_n = n\) and \(y_n = n + \frac{1}{n}\) for any integer \(n \ge 1\).
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Input separation: $$&lt;/td&gt;
              &lt;td&gt;y_n - x_n&lt;/td&gt;
              &lt;td&gt;= \frac{1}{n} \to 0\(as\)n \to \infty\((smaller than any proposed\)\delta &amp;gt; 0\(for large\)n$$).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Output separation:
\(|y_n^2 - x_n^2| = \left(n^2 + 2 + \frac{1}{n^2}\right) - n^2 = 2 + \frac{1}{n^2} &amp;gt; 2 &amp;gt; \varepsilon.\)
Because no single \(\delta &amp;gt; 0\) can keep the output change below \(1\) across all of \([0, \infty)\), \(x^2\) is continuous everywhere yet fails to be uniformly continuous on \([0, \infty)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This lesson introduces the fundamental concepts of continuity and uniform continuity, which are essential for understanding the behavior of functions in optimization.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;continuity-and-uniform-continuity&quot;&gt;Continuity and Uniform Continuity&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Continuity&lt;/strong&gt; and &lt;strong&gt;Uniform Continuity&lt;/strong&gt; are fundamental concepts that describe the behavior of functions, particularly concerning their “smoothness” or “predictability.” While closely related, they capture distinct properties, with uniform continuity being a stronger condition than mere continuity.&lt;/p&gt;

&lt;h3 id=&quot;definition-of-continuity&quot;&gt;Definition of Continuity&lt;/h3&gt;

&lt;p&gt;A function \(f: A \to \mathbb{R}\) is said to be &lt;strong&gt;continuous at a point&lt;/strong&gt; \(c \in A\) if, for every positive real number \(\varepsilon &amp;gt; 0\), there exists a positive real number \(\delta &amp;gt; 0\) such that for all \(x \in A\), if&lt;/p&gt;

\[\lvert x - c \rvert &amp;lt; \delta\]

&lt;p&gt;then&lt;/p&gt;

\[\lvert f(x) - f(c) \rvert &amp;lt; \varepsilon\]

&lt;p&gt;Intuitively, it means that for any desired level of precision \(\varepsilon\) in the output \(f(x)\), we can find a sufficiently small interval around \(c\) (of width \(2\delta\)) such that all \(x\) values within this interval map to \(f(x)\) values within an \(\varepsilon\)-interval around \(f(c)\). The crucial aspect here is that the choice of \(\delta\) generally depends not only on \(\varepsilon\) but also on the specific point \(c\).&lt;/p&gt;

&lt;p&gt;A function is &lt;strong&gt;continuous on a set&lt;/strong&gt; \(A\) if it is continuous at every point \(c \in A\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples of continuous functions&lt;/strong&gt; include all polynomials (e.g., \(f(x) = x^2 + 3x - 1\)), trigonometric functions like \(\sin(x)\) and \(\cos(x)\), and exponential functions \(e^x\) on their respective domains.&lt;/p&gt;

&lt;h3 id=&quot;definition-of-uniform-continuity&quot;&gt;Definition of Uniform Continuity&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Uniform Continuity&lt;/strong&gt;, on the other hand, imposes a more stringent condition. A function \(f: A \to \mathbb{R}\) is said to be &lt;strong&gt;uniformly continuous on a set&lt;/strong&gt; \(A\) if, for every positive real number \(\varepsilon &amp;gt; 0\), there exists a positive real number \(\delta &amp;gt; 0\) such that for all \(x, y \in A\), if&lt;/p&gt;

\[\lvert x - y \rvert &amp;lt; \delta\]

&lt;p&gt;then&lt;/p&gt;

\[\lvert f(x) - f(y) \rvert &amp;lt; \varepsilon\]

&lt;p&gt;The &lt;strong&gt;key distinction&lt;/strong&gt; from point-wise continuity lies in the order of quantifiers: for &lt;strong&gt;uniform&lt;/strong&gt; continuity, the \(\delta\) depends &lt;em&gt;only&lt;/em&gt; on \(\varepsilon\) and is independent of the specific points \(x\) and \(y\) in the domain.&lt;/p&gt;

&lt;h3 id=&quot;definition-of-lipschitz-continuity&quot;&gt;Definition of Lipschitz Continuity&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Lipschitz Continuity&lt;/strong&gt; provides an even more specific and quantitative notion of continuity. A function \(f: A \to \mathbb{R}\) is said to be &lt;strong&gt;Lipschitz continuous&lt;/strong&gt; (or &lt;strong&gt;L-Lipschitz&lt;/strong&gt;) on a set \(A\) if there exists a constant \(L \geq 0\) such that for all \(x, y \in A\):&lt;/p&gt;

\[\lvert f(x) - f(y) \rvert \leq L \lvert x - y \rvert\]

&lt;p&gt;The smallest such constant \(L\) is called the &lt;strong&gt;Lipschitz constant&lt;/strong&gt; or &lt;strong&gt;Lipschitz modulus&lt;/strong&gt; of \(f\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Properties of Lipschitz Continuity:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bounded Rate of Change&lt;/strong&gt;: The Lipschitz condition ensures that the function cannot change faster than a linear rate determined by \(L\).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Uniform Continuity&lt;/strong&gt;: Every Lipschitz continuous function is uniformly continuous (choose \(\delta = \varepsilon/L\) for \(L &amp;gt; 0\)).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Almost Everywhere Differentiability&lt;/strong&gt;: Lipschitz continuous functions are differentiable almost everywhere, and where the derivative exists, \(\lvert f&apos;(x) \rvert \leq L\).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f(x) = \lvert x \rvert\) is 1-Lipschitz on \(\mathbb{R}\)&lt;/li&gt;
  &lt;li&gt;\(f(x) = \sin(x)\) is 1-Lipschitz on \(\mathbb{R}\) (since \(\lvert \cos(x) \rvert \leq 1\))&lt;/li&gt;
  &lt;li&gt;\(f(x) = x^2\) is not Lipschitz on \(\mathbb{R}\) but is Lipschitz on any bounded interval&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;key-differences-and-hierarchy&quot;&gt;Key Differences and Hierarchy&lt;/h3&gt;

&lt;p&gt;The three types of continuity form a hierarchy of increasingly strong conditions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continuity ⊆ Uniform Continuity ⊆ Lipschitz Continuity&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Point-wise vs Global&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Continuity&lt;/strong&gt;: Local property (checked at each point)&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Uniform Continuity&lt;/strong&gt;: Global property of the entire function&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Lipschitz Continuity&lt;/strong&gt;: Global property with quantitative bounds&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choice of \(\delta\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Continuity&lt;/strong&gt;: \(\delta\) can depend on both \(\varepsilon\) and the specific point \(c\)&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Uniform Continuity&lt;/strong&gt;: \(\delta\) depends only on \(\varepsilon\), working for all points simultaneously&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Lipschitz Continuity&lt;/strong&gt;: \(\delta = \varepsilon/L\) provides explicit relationship&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rate of Change Control&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Continuity&lt;/strong&gt;: No control over rate of change&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Uniform Continuity&lt;/strong&gt;: Ensures bounded variation over small intervals&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Lipschitz Continuity&lt;/strong&gt;: Provides explicit linear bound on rate of change&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strength Relationships&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Every Lipschitz continuous function is uniformly continuous&lt;/li&gt;
      &lt;li&gt;Every uniformly continuous function is continuous&lt;/li&gt;
      &lt;li&gt;The converses are not generally true&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;detailed-examples-and-comparisons&quot;&gt;Detailed Examples and Comparisons&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Example 1: \(f(x) = x^2\)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;On \(\mathbb{R}\)&lt;/strong&gt;: Continuous but not uniformly continuous (rate of change \(\lvert f&apos;(x) \rvert = 2\lvert x \rvert\) is unbounded)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;On \([0,1]\)&lt;/strong&gt;: Continuous, uniformly continuous, and Lipschitz with \(L = 2\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example 2: \(f(x) = \sin(x)\)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;On \(\mathbb{R}\)&lt;/strong&gt;: Continuous, uniformly continuous, and 1-Lipschitz (since \(\lvert \cos(x) \rvert \leq 1\))&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example 3: \(f(x) = \lvert x \rvert\)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;On \(\mathbb{R}\)&lt;/strong&gt;: Continuous, uniformly continuous, and 1-Lipschitz&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Note&lt;/strong&gt;: Not differentiable at \(x = 0\), but still Lipschitz&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example 4: \(f(x) = \sqrt{x}\)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;On \([0,1]\)&lt;/strong&gt;: Continuous and uniformly continuous, but not Lipschitz (derivative unbounded near \(x = 0\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;On \([a,1]\) for \(a &amp;gt; 0\)&lt;/strong&gt;: Lipschitz with \(L = 1/(2\sqrt{a})\)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-11 Bài Tập Thực Hành - Phương pháp Subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_11_Practical_Exercises_Subgradient_Methods/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_11_Practical_Exercises_Subgradient_Methods</id>
   <content type="html">&lt;p&gt;Lý thuyết tối ưu chỉ thực sự thấm vào tay nghề khi bạn tự viết vòng lặp, nhìn thấy đường cong loss nhảy lên nhảy xuống trên màn hình, rồi tự tay thuần hóa nó bằng các kỹ thuật thực hành. Trong khi các bài giảng trước tập trung vào công thức cập nhật cơ bản, năm bài tập thực hành dưới đây đưa bạn đi thẳng vào “xưởng cơ khí” của tối ưu không trơn: từ subgradient đối ngẫu cho quy hoạch tuyến tính, trung bình hóa Polyak–Ruppert, Mirror Descent trên đơn hình xác suất cho tới phương pháp mặt phẳng cắt (Cutting Plane).&lt;/p&gt;

&lt;p&gt;Mỗi bài tập đều đại diện cho một hướng nâng cấp quan trọng của phương pháp subgradient cổ điển. Nếu bạn từng thắc mắc làm sao một thuật toán chỉ có tốc độ \(O(1/\epsilon^2)\) lại có thể được cải tiến mạnh mẽ trong thực tế bằng kỹ thuật lấy trung bình hay thay đổi hình học không gian, loạt bài thực hành này chính là câu trả lời sống động nhất.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-kỹ-thuật-mở-rộng-xuất-hiện-trong-bộ-bài-tập-thực-hành&quot;&gt;Kiến thức cần nhớ: Bốn kỹ thuật mở rộng xuất hiện trong bộ bài tập thực hành&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Subgradient đối ngẫu cho bài toán có ràng buộc (Dual Subgradient):&lt;/strong&gt; Khi bài toán gốc có ràng buộc tuyến tính \(Ax = b\), hàm đối ngẫu \(g(\lambda) = \inf_{x \ge 0} (c^T x + \lambda^T(Ax - b))\) là hàm lõm không trơn; subgradient của \(-g(\lambda)\) chính là phần dư vi phạm ràng buộc \(b - Ax(\lambda)\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trung bình hóa Polyak–Ruppert (Iterate Averaging):&lt;/strong&gt; Thay vì lấy điểm lặp cuối \(x^{(k)}\) vốn dễ dao động quanh đáy chữ V, ta lấy trung bình \(\bar{x}^{(k)} = \frac{1}{k}\sum_{i=1}^k x^{(i)}\) (hoặc trung bình có trọng số bước \(\alpha_i\)). Nhờ tính lồi (bất đẳng thức Jensen), \(f(\bar{x}^{(k)}) \le \frac{1}{k}\sum f(x^{(i)})\), triệt tiêu đáng kể dao động răng cưa!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mirror Descent và hình học đơn hình xác suất:&lt;/strong&gt; Trên đơn hình \(\Delta_n = \{x \ge 0 : \sum x_i = 1\}\), dùng hàm tạo entropy \(\psi(x) = \sum x_i \ln x_i\) biến bước cập nhật thành quy tắc nhân trọng số (Exponentiated Gradient) \(x_i^{(k+1)} \propto x_i^{(k)} e^{-t_k g_i^{(k)}}\), tránh hẳn phép chiếu đắt đỏ và tăng tốc mạnh theo số chiều \(n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp mặt phẳng cắt (Cutting Plane / Kelley’s Method):&lt;/strong&gt; Thay vì quên sạch các subgradient cũ sau mỗi bước, ta tích lũy chúng thành một hàm xấp xỉ tuyến tính từng khúc \(\hat{f}_k(x) = \max_{1 \le i \le k} \{f(x^{(i)}) + g^{(i)T}(x - x^{(i)})\}\) — đây là tiền thân trực tiếp của phương pháp bó (bundle methods).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-sức-mạnh-của-trung-bình-hóa-polyakruppert-trên-hàm-fx--x&quot;&gt;Giải thích: Tính tay sức mạnh của trung bình hóa Polyak–Ruppert trên hàm \(f(x) = |x|\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Quay lại kịch bản dao động bất tận của $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(với bước cố định\)t = 1\(từ\)x^{(0)} = 0.5$$:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Quỹ đạo thô \(x^{(k)}\) bị kẹt dao động:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[x^{(0)} = +0.5 \implies f(x^{(0)}) = 0.5\]
      &lt;/li&gt;
      &lt;li&gt;
\[x^{(1)} = 0.5 - 1(1) = -0.5 \implies f(x^{(1)}) = 0.5\]
      &lt;/li&gt;
      &lt;li&gt;
\[x^{(2)} = -0.5 - 1(-1) = +0.5 \implies f(x^{(2)}) = 0.5\]
      &lt;/li&gt;
      &lt;li&gt;\(x^{(3)} = -0.5 \implies f(x^{(3)}) = 0.5\)
Nếu chỉ nhìn điểm cuối \(x^{(k)}\) hay thậm chí \(f_{\text{best}}^{(k)}\), sai số không bao giờ nhỏ hơn \(0.5\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng trung bình hóa Polyak–Ruppert \(\bar{x}^{(k)} = \frac{1}{k}\sum_{i=0}^{k-1} x^{(i)}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Sau \(k = 2\) điểm (\(x^{(0)}, x^{(1)}\)): \(\bar{x}^{(2)} = \frac{0.5 + (-0.5)}{2} = 0.0 = x^* \implies f(\bar{x}^{(2)}) = 0!\)&lt;/li&gt;
      &lt;li&gt;Sau \(k = 3\) điểm: \(\bar{x}^{(3)} = \frac{0.5 - 0.5 + 0.5}{3} = 0.167 \implies f(\bar{x}^{(3)}) = 0.167 &amp;lt; 0.5\).&lt;/li&gt;
      &lt;li&gt;Sau \(k = 4\) điểm: \(\bar{x}^{(4)} = 0.0 \implies f(\bar{x}^{(4)}) = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trực giác cốt lõi:&lt;/strong&gt; Bất đẳng thức Jensen đảm bảo điểm trung bình của một đám mây dao động quanh đáy luôn nằm sâu hơn hẳn từng điểm đơn lẻ — một mẹo lập trình chỉ tốn 2 dòng code nhưng mang lại khác biệt rõ rệt khi làm các bài tập thực hành dưới đây.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---phương-pháp-subgradient&quot;&gt;Bài Tập Thực Hành - Phương pháp Subgradient&lt;/h1&gt;

&lt;p&gt;Các bài tập được tham khảo từ Boyd et al. (2003) và Nesterov (2009).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-1-phương-pháp-subgradient-đối-ngẫu-cho-bài-toán-quy-hoạch-tuyến-tính-lp&quot;&gt;&lt;strong&gt;Bài tập 1: Phương pháp Subgradient đối ngẫu cho bài toán Quy hoạch tuyến tính (LP)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho bài toán LP: \(\min c^Tx\) với ràng buộc \(Ax = b\), \(x \geq 0\), trong đó \(c = (1,2)^T\), \(A = [1,1]\), \(b = 3\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Viết bài toán đối ngẫu.&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Tính subgradient của hàm đối ngẫu.&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Thực hiện các bước lặp subgradient đối ngẫu.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Hàm Lagrangian:&lt;/strong&gt; \(L(x,\nu) = c^Tx + \nu(b - Ax)\), suy ra \(g(\nu) = 3\nu + \inf_{x \geq 0}(c - A^T\nu)^Tx\), hữu hạn khi \(A^T\nu \leq c\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Bài toán đối ngẫu:&lt;/strong&gt; \(\max 3\nu\) với ràng buộc \(\nu \leq 1\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Subgradient:&lt;/strong&gt; \(g&apos;(\nu) = b - Ax^*(\nu) = 3\) (với \(x^*=0\) khi \(\nu \le 1\)).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm tối ưu:&lt;/strong&gt; \(\nu^* = 1\) (giá trị đối ngẫu bằng \(3\), trùng với giá trị gốc tại \(x = (3, 0)\)).&lt;/p&gt;

  &lt;p&gt;Áp dụng bước tăng gradient có chiếu lên miền \(\nu \leq 1\) với \(\alpha = 0.1\) xuất phát từ \(\nu^{(0)} = 0\), ta thu được dãy \(0.3, 0.6, 0.9, 1\), hội tụ đến \(\nu^* = 1\) sau 4 bước.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-2-phương-pháp-subgradient-ngẫu-nhiên&quot;&gt;&lt;strong&gt;Bài tập 2: Phương pháp Subgradient ngẫu nhiên&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho bài toán \(\min \frac{1}{n}\sum_i \max(0, 1 - y_i w^T x_i)\) với 3 điểm dữ liệu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Viết công thức cập nhật ngẫu nhiên.&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; So sánh với phương pháp batch.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;Phương pháp ngẫu nhiên chọn một mẫu dữ liệu \(i\) ở mỗi bước lặp và cập nhật:&lt;/p&gt;

\[w^{(k+1)} = w^{(k)} - \alpha_k g_i\]

  &lt;p&gt;với \(g_i = -y_i x_i\) nếu mẫu \(i\) vi phạm lề (\(1 - y_i w^T x_i &amp;gt; 0\)), và \(g_i = 0\) nếu không vi phạm.&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Chi phí mỗi bước lặp thấp hơn nhiều so với phương pháp batch, đồng thời vẫn tạo được tiến triển nhanh trong giai đoạn đầu khi tập dữ liệu lớn.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-3-trung-bình-polyakruppert&quot;&gt;&lt;strong&gt;Bài tập 3: Trung bình Polyak–Ruppert&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho \(f(x) = \max\{2x, -x+3\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Tìm nghiệm tối ưu \(x^*\).&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; So sánh dãy điểm lặp \(x^{(k)}\) với dãy trung bình \(\bar{x}^{(k)}\).&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Nghiệm tối ưu:&lt;/strong&gt; \(x^* = 1\) (giao điểm của hai đường thẳng \(2x\) và \(-x+3\)).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Trung bình các bước lặp:&lt;/strong&gt; \(\bar{x}^{(k)} = \frac{1}{k}\sum_{i=1}^k x^{(i)}\).&lt;/p&gt;

  &lt;p&gt;Việc lấy trung bình giúp làm mượt dao động quanh điểm gấp khúc và cải thiện sự ổn định khi tiến gần \(x^*\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-4-mirror-descent-trên-tập-đơn-hình-simplex&quot;&gt;&lt;strong&gt;Bài tập 4: Mirror Descent trên tập đơn hình (Simplex)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho \(f(x) = c^Tx\) trên tập đơn hình \(\Delta_3\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Sử dụng ánh xạ gương entropy \(\psi(x) = \sum x_i \log x_i\).&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Suy ra công thức cập nhật.&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Công thức cập nhật:&lt;/strong&gt;&lt;/p&gt;

\[x_i^{(k+1)} \propto x_i^{(k)} e^{-\alpha c_i}\]

  &lt;p&gt;Sau đó chuẩn hóa để đảm bảo \(\sum x_i = 1\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Phù hợp tự nhiên với cấu trúc hình học của tập đơn hình, giúp duy trì nghiệm nằm trong miền ràng buộc một cách trực tiếp.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bài-tập-5-phương-pháp-mặt-phẳng-cắt-cutting-plane-method&quot;&gt;&lt;strong&gt;Bài tập 5: Phương pháp mặt phẳng cắt (Cutting Plane Method)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho \(f(x) = \max\{x^2, (x-2)^2\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Xây dựng các mặt phẳng cắt \(\ell_k(x) = f(x^{(k)}) + g^{(k)}(x - x^{(k)})\).&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Cực tiểu hóa hàm cận dưới \(\hat{f}(x) = \max_k \ell_k(x)\).&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Lời giải&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;Xuất phát từ \(x^{(0)} = 0\):&lt;/p&gt;

\[\ell_0(x) = 4 - 4x\]

  &lt;p&gt;Tại \(x^{(1)} = 1\):&lt;/p&gt;

\[\ell_1(x) = 1 + 2(x-1) = 2x - 1\]

  &lt;p&gt;Cực tiểu hóa \(\max\{4-4x, 2x-1\}\) cho điểm tiếp theo \(x^{(2)} = \frac{5}{6}\).&lt;/p&gt;

  &lt;p&gt;Lặp lại quá trình bổ sung mặt phẳng cắt cho đến khi khoảng cách giữa cận trên và cận dưới đạt ngưỡng cho phép.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tổng-kết&quot;&gt;&lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Tốc độ hội tụ&lt;/th&gt;
      &lt;th&gt;Phù hợp nhất cho&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Subgradient đối ngẫu&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Quy hoạch tuyến tính, bài toán lồi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Subgradient ngẫu nhiên&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Học máy quy mô lớn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Trung bình hóa&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Giảm dao động quanh nghiệm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mirror Descent&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Miền ràng buộc có hình học đặc thù&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bundle / Mặt phẳng cắt&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;Hàm không trơn, số biến nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tài-liệu-tham-khảo&quot;&gt;&lt;strong&gt;Tài liệu Tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Boyd, S., et al. (2003). “Subgradient Methods”. Stanford.&lt;/li&gt;
  &lt;li&gt;Nesterov, Y. (2009). “Primal-dual subgradient methods”.&lt;/li&gt;
  &lt;li&gt;Beck, A., &amp;amp; Teboulle, M. (2003). “Mirror descent”.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>08-10 Bài tập trắc nghiệm - Phương Pháp Subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_10_Quiz_Subgradient_Method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_10_Quiz_Subgradient_Method</id>
   <content type="html">&lt;p&gt;Đọc hiểu công thức của phương pháp subgradient trên bảng thường tạo ra một cảm giác an tâm đánh lừa: trông nó giống gradient descent đến 90%! Thế nhưng chính 10% khác biệt còn lại mới là nơi các câu hỏi trắc nghiệm và bài kiểm tra phỏng vấn kỹ sư tối ưu đặt ra những chiếc bẫy sắc bén nhất — từ việc nhầm tưởng \(-g\) luôn làm giảm hàm, quên điều kiện \(\sum t_k^2 &amp;lt; \infty\), cho đến chọn sai hằng số Lipschitz hay nhầm lẫn giữa tốc độ theo bước \(k\) và theo sai số \(\epsilon\).&lt;/p&gt;

&lt;p&gt;Bộ câu hỏi trắc nghiệm dưới đây được thiết kế như một phòng thí nghiệm chẩn đoán nhanh: mỗi câu hỏi chạm đúng vào một ngộ nhận kinh điển của Chương 08. Trước khi bấm chọn đáp án, hãy đi qua bản đồ kiến thức tổng hợp và khung kiểm tra nhanh bốn cạm bẫy kinh điển ngay dưới đây để chắc chắn bạn nắm vững bản chất thay vì đoán mò.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-cụm-kiến-thức-trọng-tâm-cần-chốt-trước-khi-làm-bài-trắc-nghiệm&quot;&gt;Kiến thức cần nhớ: Bốn cụm kiến thức trọng tâm cần chốt trước khi làm bài trắc nghiệm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa dưới vi phân và tính không đơn điệu:&lt;/strong&gt; Nhớ phân biệt \(\partial f(x)\) (một tập hợp) với \(g \in \partial f(x)\) (một vector đại diện); hiểu vì sao \(f(x^{(k+1)})\) có thể lớn hơn \(f(x^{(k)})\) nên luôn phải theo dõi \(f_{\text{best}}^{(k)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lịch kích thước bước và điều kiện hội tụ:&lt;/strong&gt; Phân biệt rạch ròi ba nhóm: bước cố định (hội tụ đến sàn \(G^2 t/2\)), bước giảm dần \(\sum t_k = \infty, \sum t_k^2 &amp;lt; \infty\) (hội tụ về đúng \(f^*\)), và bước Polyak \(t_k = \frac{f^{(k-1)} - f^*}{\|g^{(k-1)}\|_2^2}\) (dùng khi biết \(f^*\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ hội tụ và phép chiếu:&lt;/strong&gt; Khắc sâu tốc độ \(O(1/\epsilon^2)\) (tức \(O(1/\sqrt{k})\)) dưới giả thiết \(f\) là \(G\)-Lipschitz, và lý do phép chiếu \(P_C\) lên tập lồi đóng không làm hỏng bất đẳng thức cơ bản.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến thể ngẫu nhiên vs. batch:&lt;/strong&gt; Nắm rõ bản ngẫu nhiên giảm chi phí mỗi bước \(m\) lần, cho kỳ vọng không chệch nhưng tạo nhiễu gần nghiệm nên cần giảm bước dần về \(0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bốn-phép-thử-số-nhanh-để-né-bẫy-trắc-nghiệm-chương-08&quot;&gt;Giải thích: Bốn phép thử số nhanh để né bẫy trắc nghiệm Chương 08&lt;/h3&gt;

&lt;p&gt;Hãy tự kiểm chứng 4 phép tính ngắn gọn sau trước khi bước vào bộ câu hỏi:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Bẫy 1 — Dưới vi phân tại điểm gãy:&lt;/strong&gt; Với $$f(x) =&lt;/td&gt;
          &lt;td&gt;2x - 4&lt;/td&gt;
          &lt;td&gt;\(tại\)x = 2$$, dưới vi phân là gì?&lt;/td&gt;
          &lt;td&gt; &lt;/td&gt;
          &lt;td&gt; &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;Vì $$&lt;/td&gt;
          &lt;td&gt;2x - 4&lt;/td&gt;
          &lt;td&gt;= 2&lt;/td&gt;
          &lt;td&gt;x - 2&lt;/td&gt;
          &lt;td&gt;\(, nên\)\partial f(2) = 2[-1, 1] = [-2, 2]\((đừng quên nhân hệ số\)2$$!).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 2 — Kiểm tra lịch bước giảm dần:&lt;/strong&gt; Dãy \(t_k = \frac{1}{\sqrt{k}}\) có thỏa điều kiện hội tụ cổ điển \(\sum t_k = \infty, \sum t_k^2 &amp;lt; \infty\) không?
Kiểm tra: \(\sum \frac{1}{\sqrt{k}} = \infty\) (thỏa), nhưng \(\sum t_k^2 = \sum \frac{1}{k} = \infty\) (&lt;strong&gt;không thỏa&lt;/strong&gt;! Dù vậy, nếu dùng trung bình hoặc bước trên đoạn hữu hạn \(K\), \(t_k = c/\sqrt{k}\) vẫn đạt cận \(O(\ln K / \sqrt{K})\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 3 — Tính nhanh bước Polyak:&lt;/strong&gt; Biết \(f^* = 1\), tại \(x^{(k)}\) có \(f(x^{(k)}) = 5\) và \(g^{(k)} = (3, -4)\).
Ta có \(\|g^{(k)}\|_2^2 = 3^2 + (-4)^2 = 25\), nên \(t_k = \frac{5 - 1}{25} = 0.16\) (chú ý mẫu số là &lt;em&gt;bình phương&lt;/em&gt; chuẩn \(\ell_2\), không phải chuẩn \(\|g\|_2 = 5\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 4 — Quy đổi độ phức tạp \(O(1/\epsilon^2)\):&lt;/strong&gt; Nếu giảm sai số mục tiêu \(\epsilon\) đi 5 lần (từ \(0.1\) xuống \(0.02\)), số bước lặp tối đa của phương pháp subgradient tăng bao nhiêu lần?
Vì \(k \propto 1/\epsilon^2\), số bước tăng \(5^2 = 25\) lần!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-phương-pháp-subgradient&quot;&gt;⚡ &lt;strong&gt;Phương Pháp Subgradient&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa-thuật-toán&quot;&gt;&lt;strong&gt;Định nghĩa thuật toán&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Phương pháp subgradient mở rộng gradient descent cho các hàm lồi không khả vi:&lt;/p&gt;

\[x^{(k)} = x^{(k-1)} - t_k \cdot g^{(k-1)}, \quad k = 1, 2, 3, \ldots\]

&lt;p&gt;với \(g^{(k-1)} \in \partial f(x^{(k-1)})\) là một subgradient của \(f\) tại \(x^{(k-1)}\).&lt;/p&gt;

&lt;h4 id=&quot;khác-biệt-quan-trọng-so-với-gradient-descent&quot;&gt;&lt;strong&gt;Khác biệt quan trọng so với Gradient Descent&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không đảm bảo giảm đơn điệu:&lt;/strong&gt; Giá trị hàm mục tiêu có thể tăng ở một số bước.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theo dõi giá trị tốt nhất:&lt;/strong&gt; \(f(x_{\text{best}}^{(k)}) = \min_{i=0,\ldots,k} f(x^{(i)})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bước định trước:&lt;/strong&gt; Không dùng tìm kiếm đường thẳng lùi như gradient descent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-lựa-chọn-kích-thước-bước&quot;&gt;📏 &lt;strong&gt;Lựa Chọn Kích Thước Bước&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-kích-thước-bước-cố-định&quot;&gt;&lt;strong&gt;1. Kích thước bước cố định&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t_k = t &amp;gt; 0, \quad \forall k\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Dễ cài đặt.&lt;/li&gt;
  &lt;li&gt;Hội tụ đến một lân cận của giá trị tối ưu.&lt;/li&gt;
  &lt;li&gt;Không đạt tới nghiệm chính xác.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-kích-thước-bước-giảm-dần&quot;&gt;&lt;strong&gt;2. Kích thước bước giảm dần&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Thỏa mãn điều kiện tổng phân kỳ nhưng tổng bình phương hội tụ:
\(\sum_{k=1}^{\infty} t_k = \infty, \quad \sum_{k=1}^{\infty} t_k^2 &amp;lt; \infty\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ phổ biến:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(t_k = \frac{1}{k}\) (chuỗi điều hòa)&lt;/li&gt;
  &lt;li&gt;\(t_k = \frac{a}{b + k}\) với \(a, b &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;(Lưu ý: \(t_k = \frac{1}{\sqrt{k}}\) chỉ thỏa \(\sum t_k = \infty, t_k \to 0\) chứ không thỏa \(\sum t_k^2 &amp;lt; \infty\), nhưng vẫn cho hội tụ với cận \(O(\log k / \sqrt{k})\).)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Đặc điểm:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hội tụ chính xác đến giá trị tối ưu (\(f_{\text{best}}^{(k)} \to f^*\)).&lt;/li&gt;
  &lt;li&gt;Tốc độ hội tụ ban đầu chậm hơn so với kích thước bước cố định.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-kích-thước-bước-polyak&quot;&gt;&lt;strong&gt;3. Kích thước bước Polyak&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t_k = \frac{f(x^{(k)}) - f^*}{\lVert g^{(k)} \rVert_2^2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt; Biết trước giá trị tối ưu \(f^*\).
&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Hội tụ nhanh hơn trong thực hành khi biết \(f^*\).&lt;/p&gt;

&lt;h3 id=&quot;-phân-tích-hội-tụ&quot;&gt;📊 &lt;strong&gt;Phân Tích Hội Tụ&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;giả-thiết-cơ-bản&quot;&gt;&lt;strong&gt;Giả thiết cơ bản&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(f\) là hàm lồi với \(\text{dom}(f) = \mathbb{R}^n\).&lt;/li&gt;
  &lt;li&gt;\(f\) thỏa mãn điều kiện Lipschitz:
\(|f(x) - f(y)| \le G \lVert x - y \rVert_2, \quad \forall x, y\)&lt;/li&gt;
  &lt;li&gt;Các subgradient bị chặn chuẩn: \(\lVert g \rVert_2 \le G\) với mọi \(g \in \partial f(x)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;định-lý-hội-tụ-cho-kích-thước-bước-cố-định&quot;&gt;&lt;strong&gt;Định lý hội tụ cho kích thước bước cố định&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lim_{k \to \infty} f(x_{\text{best}}^{(k)}) \le f^* + \frac{G^2 t}{2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hội tụ đến lân cận của giá trị tối ưu.&lt;/li&gt;
  &lt;li&gt;Sai số giới hạn tỷ lệ thuận với kích thước bước \(t\).&lt;/li&gt;
  &lt;li&gt;Đánh đổi: \(t\) nhỏ cho sai số nhỏ nhưng hội tụ chậm hơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;định-lý-hội-tụ-cho-kích-thước-bước-giảm-dần&quot;&gt;&lt;strong&gt;Định lý hội tụ cho kích thước bước giảm dần&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lim_{k \to \infty} f(x_{\text{best}}^{(k)}) = f^*\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hội tụ chính xác đến giá trị tối ưu (\(f_{\text{best}}^{(k)} \to f^*\)).&lt;/li&gt;
  &lt;li&gt;Tốc độ hội tụ bậc dưới tuyến tính: \(O(1/\sqrt{k})\) (khi chọn bước tối ưu theo số bước).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;bất-đẳng-thức-cơ-bản&quot;&gt;&lt;strong&gt;Bất đẳng thức cơ bản&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f_{\text{best}}^{(k)} - f^* \le \frac{R^2 + G^2 \sum_{i=1}^k t_i^2}{2 \sum_{i=1}^k t_i}\)&lt;/p&gt;

&lt;p&gt;với \(R = \lVert x^{(0)} - x^* \rVert_2\).&lt;/p&gt;

&lt;h3 id=&quot;-ứng-dụng-thực-tế&quot;&gt;🎯 &lt;strong&gt;Ứng Dụng Thực Tế&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-hồi-quy-lasso&quot;&gt;&lt;strong&gt;1. Hồi quy LASSO&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_\beta \frac{1}{2} \lVert y - X\beta \rVert_2^2 + \lambda \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vi phân dưới:&lt;/strong&gt;
\(\partial f(\beta) = X^T(X\beta - y) + \lambda \partial \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;h4 id=&quot;2-hồi-quy-logistic-có-chính-quy-hóa&quot;&gt;&lt;strong&gt;2. Hồi quy Logistic có chính quy hóa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_\beta \sum_{i=1}^n \left[-y_i x_i^T \beta + \log(1 + \exp(x_i^T \beta))\right] + \lambda \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So sánh:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ridge (L2):&lt;/strong&gt; Khả vi → dùng gradient descent.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;LASSO (L1):&lt;/strong&gt; Không khả vi → dùng phương pháp subgradient.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-máy-vector-hỗ-trợ-svm&quot;&gt;&lt;strong&gt;3. Máy vector hỗ trợ (SVM)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_w \frac{1}{2} \lVert w \rVert_2^2 + C \sum_{i=1}^n \max(0, 1 - y_i w^T x_i)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hàm mất mát hinge:&lt;/strong&gt; \(\max(0, 1 - z)\) không khả vi tại \(z = 1\).&lt;/p&gt;

&lt;h3 id=&quot;-phương-pháp-subgradient-ngẫu-nhiên&quot;&gt;🔄 &lt;strong&gt;Phương Pháp Subgradient Ngẫu Nhiên&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-dạng-tổng&quot;&gt;&lt;strong&gt;Bài toán dạng tổng&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) = \min_x \sum_{i=1}^m f_i(x)\)&lt;/p&gt;

&lt;h4 id=&quot;bước-cập-nhật-ngẫu-nhiên&quot;&gt;&lt;strong&gt;Bước cập nhật ngẫu nhiên&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k g_i^{(k-1)}\)&lt;/p&gt;

&lt;p&gt;với \(g_i^{(k-1)} \in \partial f_i(x^{(k-1)})\) và chỉ số \(i\) được chọn ngẫu nhiên.&lt;/p&gt;

&lt;h4 id=&quot;ưu-điểm&quot;&gt;&lt;strong&gt;Ưu điểm&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Chi phí mỗi bước là \(O(1)\) hàm thành phần thay vì \(O(m)\).&lt;/li&gt;
  &lt;li&gt;Phù hợp với tập dữ liệu lớn.&lt;/li&gt;
  &lt;li&gt;Tiến nhanh về vùng lân cận nghiệm trong giai đoạn đầu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;nhược-điểm&quot;&gt;&lt;strong&gt;Nhược điểm&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Phương sai cao hơn phương pháp batch.&lt;/li&gt;
  &lt;li&gt;Cần điều chỉnh tốc độ học cẩn thận.&lt;/li&gt;
  &lt;li&gt;Hội tụ chậm hơn khi đã tiến gần nghiệm tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-phương-pháp-subgradient-có-chiếu&quot;&gt;📈 &lt;strong&gt;Phương Pháp Subgradient Có Chiếu&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-có-ràng-buộc&quot;&gt;&lt;strong&gt;Bài toán có ràng buộc&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{x \in C} f(x)\)&lt;/p&gt;

&lt;p&gt;với \(C\) là tập lồi đóng.&lt;/p&gt;

&lt;h4 id=&quot;thuật-toán&quot;&gt;&lt;strong&gt;Thuật toán&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = P_C(x^{(k-1)} - t_k g^{(k-1)})\)&lt;/p&gt;

&lt;p&gt;với \(P_C(\cdot)\) là phép chiếu Euclid lên tập \(C\).&lt;/p&gt;

&lt;h4 id=&quot;ví-dụ-tìm-điểm-giao-của-các-tập-lồi&quot;&gt;&lt;strong&gt;Ví dụ: Tìm điểm giao của các tập lồi&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x \max_{i=1,\ldots,m} \text{dist}(x, C_i)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thuật toán (với bước Polyak khi \(f^* = 0\)):&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chọn tập \(C_i\) xa điểm hiện tại nhất (khoảng cách lớn nhất).&lt;/li&gt;
  &lt;li&gt;Chiếu lên \(C_i\): \(x^{(k)} = P_{C_i}(x^{(k-1)})\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-so-sánh-các-phương-pháp&quot;&gt;🔄 &lt;strong&gt;So Sánh Các Phương Pháp&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Điều kiện&lt;/th&gt;
      &lt;th&gt;Tốc độ hội tụ&lt;/th&gt;
      &lt;th&gt;Ứng dụng&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Gradient Descent&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hàm khả vi&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\) (hoặc tuyến tính khi lồi mạnh)&lt;/td&gt;
      &lt;td&gt;Tối ưu hàm trơn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Subgradient&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hàm lồi&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Tối ưu hàm không trơn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SGD&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hàm khả vi&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Bài toán quy mô lớn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Subgradient ngẫu nhiên&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hàm lồi&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Bài toán không trơn quy mô lớn&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-kỹ-thuật-thực-hành&quot;&gt;🛠️ &lt;strong&gt;Kỹ Thuật Thực Hành&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;chọn-kích-thước-bước&quot;&gt;&lt;strong&gt;Chọn kích thước bước&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước cố định:&lt;/strong&gt; Thử các giá trị như \(t = 0.01, 0.1, 1\) và chọn giá trị phù hợp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước giảm dần:&lt;/strong&gt; Sử dụng \(t_k = \frac{1}{\sqrt{k}}\) hoặc \(t_k = \frac{1}{k}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước Polyak:&lt;/strong&gt; Áp dụng khi biết trước \(f^*\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;theo-dõi-hội-tụ&quot;&gt;&lt;strong&gt;Theo dõi hội tụ&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Theo dõi \(f(x_{\text{best}}^{(k)})\) thay vì chỉ nhìn \(f(x^{(k)})\).&lt;/li&gt;
  &lt;li&gt;Vẽ đồ thị quá trình hội tụ để kiểm tra.&lt;/li&gt;
  &lt;li&gt;Có thể lấy trung bình trượt để làm mượt đường cong.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;kiểm-tra-và-gỡ-lỗi&quot;&gt;&lt;strong&gt;Kiểm tra và gỡ lỗi&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Kiểm tra tính chính xác của công thức subgradient.&lt;/li&gt;
  &lt;li&gt;Ước lượng hằng số Lipschitz \(G\).&lt;/li&gt;
  &lt;li&gt;Thử nhiều lịch trình kích thước bước khác nhau.&lt;/li&gt;
  &lt;li&gt;Đối chiếu với gradient descent trên trường hợp hàm khả vi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-các-hướng-cải-tiến&quot;&gt;⚡ &lt;strong&gt;Các Hướng Cải Tiến&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-lấy-trung-bình-averaging&quot;&gt;&lt;strong&gt;1. Lấy trung bình (Averaging)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\bar{x}^{(k)} = \frac{1}{k} \sum_{i=1}^k x^{(i)}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Giảm dao động và cải thiện độ ổn định hội tụ.&lt;/p&gt;

&lt;h4 id=&quot;2-động-lượng-momentum&quot;&gt;&lt;strong&gt;2. Động lượng (Momentum)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k g^{(k-1)} + \beta(x^{(k-1)} - x^{(k-2)})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Tăng tốc tiến triển dọc theo hướng ổn định, giảm dao động.&lt;/p&gt;

&lt;h4 id=&quot;3-kích-thước-bước-thích-nghi&quot;&gt;&lt;strong&gt;3. Kích thước bước thích nghi&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;AdaGrad cho subgradient&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các biến thể kiểu RMSprop&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các phương pháp kiểu Adam&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ví-dụ-minh-họa&quot;&gt;🎯 &lt;strong&gt;Ví Dụ Minh Họa&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-min_x-x---2--x--1&quot;&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; \(\min_x |x - 2| + |x + 1|\)&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; Tính vi phân dưới
\(\partial f(x) = \partial |x - 2| + \partial |x + 1|\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt; Chạy phương pháp subgradient với \(t_k = 0.1\)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Xuất phát từ \(x^{(0)} = 5\).&lt;/li&gt;
  &lt;li&gt;\(g^{(0)} = 1 + 1 = 2\).&lt;/li&gt;
  &lt;li&gt;\(x^{(1)} = 5 - 0.1 \times 2 = 4.8\).&lt;/li&gt;
  &lt;li&gt;Tiếp tục lặp cho đến khi đi vào vùng nghiệm.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kết quả:&lt;/strong&gt; Hội tụ đến miền nghiệm \(x^* \in [-1, 2]\).&lt;/p&gt;

&lt;h3 id=&quot;-lưu-ý-khi-áp-dụng&quot;&gt;💡 &lt;strong&gt;Lưu Ý Khi Áp Dụng&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;khi-nào-nên-dùng-phương-pháp-subgradient&quot;&gt;&lt;strong&gt;Khi nào nên dùng phương pháp Subgradient:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu không khả vi (chứa \(\lvert \cdot \rvert\), \(\max\{\cdot\}\)).&lt;/li&gt;
  &lt;li&gt;Bài toán có chính quy hóa chuẩn \(\ell_1\).&lt;/li&gt;
  &lt;li&gt;Bài toán tối ưu có ràng buộc qua phép chiếu.&lt;/li&gt;
  &lt;li&gt;Bài toán quy mô lớn với biến thể ngẫu nhiên.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;khi-nào-không-nên-dùng&quot;&gt;&lt;strong&gt;Khi nào KHÔNG nên dùng:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Hàm mục tiêu trơn khả vi (nên dùng gradient descent).&lt;/li&gt;
  &lt;li&gt;Cần hội tụ rất nhanh với độ chính xác cao (nên dùng phương pháp bậc hai hoặc proximal).&lt;/li&gt;
  &lt;li&gt;Hàm không lồi (không đảm bảo tìm được cực tiểu toàn cục).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;nguyên-tắc-thực-hành-tốt&quot;&gt;&lt;strong&gt;Nguyên tắc thực hành tốt:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Luôn lưu giữ \(f_{\text{best}}^{(k)}\).&lt;/li&gt;
  &lt;li&gt;Thử nhiều chiến lược kích thước bước.&lt;/li&gt;
  &lt;li&gt;Dùng trung bình hóa để giảm dao động.&lt;/li&gt;
  &lt;li&gt;Kết hợp phép chiếu cho bài toán có ràng buộc.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Ghi chú:&lt;/strong&gt; Phương pháp subgradient là công cụ cơ bản cho tối ưu hóa không trơn, được sử dụng rộng rãi trong học máy có chính quy hóa và tối ưu bền vững.&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra hiểu biết của bạn về phương pháp subgradient, lựa chọn kích thước bước, phân tích hội tụ, projected subgradient method và stochastic subgradient method.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🔄 Quiz: Phương Pháp Subgradient&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: Định nghĩa subgradient method --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Công thức cập nhật của phương pháp subgradient là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(x^{(k)} = x^{(k-1)} + t_k \cdot g^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(x^{(k)} = x^{(k-1)} - t_k \cdot g^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(x^{(k)} = x^{(k-1)} - t_k \cdot \nabla f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(x^{(k)} = x^{(k-1)} - g^{(k-1)}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$x^{(k)} = x^{(k-1)} - t_k \cdot g^{(k-1)}$$&lt;/strong&gt;&lt;br /&gt;
                Phương pháp subgradient thay thế gradient bằng subgradient $$g^{(k-1)} \in \partial f(x^{(k-1)})$$ với step size $$t_k$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Tính chất descent --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Khác với gradient descent, phương pháp subgradient:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) Luôn giảm giá trị hàm số ở mỗi bước&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) Không luôn đảm bảo giảm giá trị hàm số ở mỗi bước&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Chỉ áp dụng cho hàm khả vi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Hội tụ nhanh hơn gradient descent&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Không luôn đảm bảo giảm giá trị hàm số ở mỗi bước&lt;/strong&gt;&lt;br /&gt;
                Vì vậy phương pháp này không được gọi là &quot;descent&quot; subgradient và cần theo dõi giá trị tốt nhất $$f(x_{best}^{(k)})$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Best value tracking --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Trong subgradient method, \(f(x_{best}^{(k)})\) được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(f(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(\min_{i=0,...,k} f(x^{(i)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \(\max_{i=0,...,k} f(x^{(i)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \(\frac{1}{k+1} \sum_{i=0}^k f(x^{(i)})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\min_{i=0,...,k} f(x^{(i)})$$&lt;/strong&gt;&lt;br /&gt;
                Đây là giá trị nhỏ nhất của hàm $$f$$ thu được trong $$k$$ lần lặp của phương pháp subgradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Fixed step size --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Với kích thước bước cố định \(t_k = t\), phương pháp subgradient:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Hội tụ đến nghiệm tối ưu chính xác&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Hội tụ đến một lân cận của giá trị tối ưu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Không hội tụ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Chỉ hội tụ cho hàm khả vi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Hội tụ đến một lân cận của giá trị tối ưu&lt;/strong&gt;&lt;br /&gt;
                Với step size cố định, thuật toán không hội tụ chính xác: $$\lim_{k\to\infty} f(x_{best}^{(k)}) \leq f^* + \frac{G^2 t}{2}$$, tức là chỉ đến gần giá trị tối ưu trong một lân cận tỉ lệ với $$t$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Diminishing step size conditions --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Điều kiện cho kích thước bước giảm dần để đảm bảo hội tụ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(\sum_{k=1}^{\infty} t_k &amp;lt; \infty\) và \(\sum_{k=1}^{\infty} t_k^2 &amp;lt; \infty\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(\sum_{k=1}^{\infty} t_k = \infty\) và \(\sum_{k=1}^{\infty} t_k^2 &amp;lt; \infty\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(\sum_{k=1}^{\infty} t_k = \infty\) và \(\sum_{k=1}^{\infty} t_k^2 = \infty\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \(t_k = \text{constant}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\sum_{k=1}^{\infty} t_k = \infty$$ và $$\sum_{k=1}^{\infty} t_k^2 &amp;lt; \infty$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện Robbins-Monro: tổng vô hạn để đảm bảo tiến bộ, tổng bình phương hữu hạn để kiểm soát nhiễu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Ví dụ step size --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Kích thước bước \(t_k = \frac{1}{k}\) thỏa mãn điều kiện hội tụ vì:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(\sum_{k=1}^{\infty} \frac{1}{k} = \infty\) (chuỗi điều hòa) và \(\sum_{k=1}^{\infty} \frac{1}{k^2} &amp;lt; \infty\) (bài toán Basel)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) Cả hai tổng đều hữu hạn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) Cả hai tổng đều vô hạn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Không thỏa mãn điều kiện&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\sum_{k=1}^{\infty} \frac{1}{k} = \infty$$ (chuỗi điều hòa) và $$\sum_{k=1}^{\infty} \frac{1}{k^2} &amp;lt; \infty$$ (bài toán Basel)&lt;/strong&gt;&lt;br /&gt;
                Đây là ví dụ cổ điển của step size thỏa mãn điều kiện Robbins-Monro.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Convergence rate --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Tốc độ hội tụ của subgradient method với diminishing step size là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) \(O(1/\sqrt{k})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(O(e^{-k})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) $$O(1/\sqrt{k})$$&lt;/strong&gt;&lt;br /&gt;
                Subgradient method có tốc độ hội tụ $$O(1/\sqrt{k})$$, chậm hơn gradient descent $$O(1/k)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Basic inequality --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Bất đẳng thức cơ bản trong phân tích subgradient method là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(\|x^{(k)} - x^*\|^2 \leq \|x^{(k-1)} - x^*\|^2 - 2t_k(f(x^{(k-1)}) - f^*) + t_k^2\|g^{(k-1)}\|^2\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(\|x^{(k)} - x^*\|^2 \geq \|x^{(k-1)} - x^*\|^2\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(f(x^{(k)}) \leq f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(\|g^{(k)}\| \leq \|g^{(k-1)}\|\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\|x^{(k)} - x^*\|^2 \leq \|x^{(k-1)} - x^*\|^2 - 2t_k(f(x^{(k-1)}) - f^*) + t_k^2\|g^{(k-1)}\|^2$$&lt;/strong&gt;&lt;br /&gt;
                Đây là bất đẳng thức cơ bản dùng để phân tích hội tụ, cân bằng giữa tiến bộ và nhiễu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Polyak step size --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Polyak step size được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(t_k = \frac{1}{k}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(t_k = \frac{f(x^{(k-1)}) - f^*}{\|g^{(k-1)}\|^2}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(t_k = \text{constant}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(t_k = \frac{1}{\|g^{(k-1)}\|}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$t_k = \frac{f(x^{(k-1)}) - f^*}{\|g^{(k-1)}\|^2}$$&lt;/strong&gt;&lt;br /&gt;
                Polyak step size yêu cầu biết giá trị tối ưu $$f^*$$ và thường cho kết quả tốt trong thực tế.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Projected subgradient method --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Projected subgradient method cho bài toán có ràng buộc \(\min_{x \in C} f(x)\) có công thức:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(x^{(k)} = x^{(k-1)} - t_k g^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(x^{(k)} = P_C(x^{(k-1)} - t_k g^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(x^{(k)} = x^{(k-1)} - t_k P_C(g^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(x^{(k)} = P_C(x^{(k-1)})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$x^{(k)} = P_C(x^{(k-1)} - t_k g^{(k-1)})$$&lt;/strong&gt;&lt;br /&gt;
                Projected subgradient method thực hiện bước subgradient rồi chiếu kết quả về tập ràng buộc $$C$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Stochastic subgradient --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Stochastic subgradient method cho bài toán \(\min \sum_{i=1}^m f_i(x)\) có công thức:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(x^{(k)} = x^{(k-1)} - t_k \sum_{i=1}^m g_i^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(x^{(k)} = x^{(k-1)} - t_k g_{i_k}^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(x^{(k)} = x^{(k-1)} - t_k \frac{1}{m} \sum_{i=1}^m g_i^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(x^{(k)} = x^{(k-1)} - g_{i_k}^{(k-1)}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$x^{(k)} = x^{(k-1)} - t_k g_{i_k}^{(k-1)}$$&lt;/strong&gt;&lt;br /&gt;
                Stochastic version chỉ sử dụng subgradient của một hàm $$f_{i_k}$$ được chọn tại mỗi iteration.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Advantage of stochastic --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Ưu điểm chính của stochastic subgradient method là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Hội tụ nhanh hơn batch method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Chi phí tính toán thấp hơn mỗi iteration&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Luôn giảm giá trị hàm số&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Không cần step size&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Chi phí tính toán thấp hơn mỗi iteration&lt;/strong&gt;&lt;br /&gt;
                Stochastic method chỉ cần tính subgradient của một hàm thay vì tổng tất cả, giảm đáng kể chi phí tính toán.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Convergence comparison --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: So với gradient descent, subgradient method:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Hội tụ nhanh hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Hội tụ chậm hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Có cùng tốc độ hội tụ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Không hội tụ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Hội tụ chậm hơn&lt;/strong&gt;&lt;br /&gt;
                Subgradient method có tốc độ $$O(1/\sqrt{k})$$ so với $$O(1/k)$$ của gradient descent, nhưng áp dụng được cho hàm không khả vi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: When to use subgradient --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Subgradient method được sử dụng khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Hàm mục tiêu khả vi mọi nơi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Hàm mục tiêu lồi nhưng có thể không khả vi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Hàm mục tiêu không lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Chỉ cho bài toán không ràng buộc&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Hàm mục tiêu lồi nhưng có thể không khả vi&lt;/strong&gt;&lt;br /&gt;
                Subgradient method được thiết kế đặc biệt cho các hàm lồi không khả vi như norm L1, max function.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Step size adaptation --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Khác với gradient descent, step size trong subgradient method:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Có thể sử dụng backtracking line search&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Phải được thiết lập trước, không thích ứng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Luôn bằng 1&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Tự động tối ưu&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Phải được thiết lập trước, không thích ứng&lt;/strong&gt;&lt;br /&gt;
                Subgradient method không thể sử dụng line search vì không đảm bảo descent direction.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Subgradient bound --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Trong phân tích hội tụ, thường giả sử subgradient bị chặn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(\|g^{(k)}\| \leq G\) với \(G &amp;gt; 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(\|g^{(k)}\| = 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(\|g^{(k)}\| \to 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(\|g^{(k)}\|\) không bị chặn&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\|g^{(k)}\| \leq G$$ với $$G &amp;gt; 0$$&lt;/strong&gt;&lt;br /&gt;
                Giả sử subgradient bị chặn là cần thiết để đảm bảo hội tụ và ước lượng tốc độ hội tụ.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Intersection of sets --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Để tìm giao của các tập lồi \(C_1 \cap C_2 \cap ... \cap C_m\), ta có thể sử dụng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Subgradient method trên hàm $$f(x) = \max_i d_{C_i}(x)$$ (dẫn đến phép chiếu luân phiên)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Newton method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Không thể giải được&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Subgradient method trên hàm $$f(x) = \max_i d_{C_i}(x)$$ (dẫn đến phép chiếu luân phiên)&lt;/strong&gt;&lt;br /&gt;
                Tối thiểu hóa $$f(x) = \max_i d_{C_i}(x)$$ (với $$f^* = 0$$ khi giao khác rỗng). Subgradient của $$d_{C_i}$$ là $$(x - P_{C_i}(x))/d_{C_i}(x)$$; với Polyak step size, mỗi bước chính là chiếu $$x$$ lên tập xa nhất, tức là thuật toán chiếu luân phiên (alternating projections).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Regularized problems --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Subgradient method thích hợp cho bài toán regularized như:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) \(\min f(x) + \lambda \|x\|_2^2\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) \(\min f(x) + \lambda \|x\|_1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) \(\min f(x) + \lambda x^T x\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Tất cả các trường hợp trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\min f(x) + \lambda \|x\|_1$$&lt;/strong&gt;&lt;br /&gt;
                L1 regularization tạo ra hàm không khả vi, phù hợp với subgradient method. L2 regularization vẫn khả vi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Batch vs stochastic --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Trong stochastic subgradient method, việc chọn index \(i_k\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Phải hoàn toàn ngẫu nhiên&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Có thể tuần hoàn hoặc ngẫu nhiên&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Phải theo thứ tự tăng dần&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Không ảnh hưởng đến hội tụ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Có thể tuần hoàn hoặc ngẫu nhiên&lt;/strong&gt;&lt;br /&gt;
                Cả hai cách chọn tuần hoàn và ngẫu nhiên đều có thể đảm bảo hội tụ với điều kiện thích hợp.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Practical considerations --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Trong thực tế, để cải thiện hiệu suất của subgradient method, ta có thể:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Sử dụng averaging của các iterate&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Kết hợp với momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Sử dụng adaptive step size&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các phương pháp trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các phương pháp trên&lt;/strong&gt;&lt;br /&gt;
                Averaging, momentum, và adaptive step size đều là các kỹ thuật được sử dụng để cải thiện subgradient method.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Subgradient method có tốc độ hội tụ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$O(1/k)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$O(1/\sqrt{k})$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$O(1/k^2)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Tuyến tính&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$O(1/\sqrt{k})$$&lt;/strong&gt;&lt;br /&gt;
                Subgradient method có tốc độ hội tụ $$O(1/\sqrt{k})$$ cho hàm lồi không trơn.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Kích thước bước trong subgradient method thường chọn:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Cố định nhỏ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Giảm dần theo $$1/\sqrt{k}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Tăng dần&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Ngẫu nhiên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Giảm dần theo $$1/\sqrt{k}$$&lt;/strong&gt;&lt;br /&gt;
                Kích thước bước thường chọn $$t_k = \frac{c}{\sqrt{k}}$$ để đảm bảo hội tụ.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Với hàm $$f(x) = |x|$$, từ $$x_0 = 2$$, một bước subgradient với $$t = 0.5$$ cho:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$x_1 = 1.5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$x_1 = 2.5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$x_1 = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$x_1 = 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$x_1 = 1.5$$&lt;/strong&gt;&lt;br /&gt;
                Tại $$x_0 = 2$$: subgradient là $$g = 1$$. $$x_1 = 2 - 0.5 \cdot 1 = 1.5$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Subgradient method khác gradient descent ở chỗ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Không cần hàm khả vi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Hội tụ chậm hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Có thể dao động&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) Tất cả các điều trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các điều trên&lt;/strong&gt;&lt;br /&gt;
                Subgradient method áp dụng cho hàm không trơn, hội tụ chậm hơn và có thể dao động quanh nghiệm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Điều kiện dừng trong subgradient method thường dựa vào:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$\|g_k\| &amp;lt; \epsilon$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Số lần lặp tối đa&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Giá trị hàm mục tiêu&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) B và C&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) B và C&lt;/strong&gt;&lt;br /&gt;
                Do subgradient có thể không bằng 0 tại nghiệm, thường dùng số lần lặp hoặc giá trị hàm để dừng.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành Quiz!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;b&apos;,
    q6: &apos;a&apos;, q7: &apos;c&apos;, q8: &apos;a&apos;, q9: &apos;b&apos;, q10: &apos;b&apos;,
    q11: &apos;b&apos;, q12: &apos;b&apos;, q13: &apos;b&apos;, q14: &apos;b&apos;, q15: &apos;b&apos;,
    q16: &apos;a&apos;, q17: &apos;b&apos;, q18: &apos;b&apos;, q19: &apos;b&apos;, q20: &apos;d&apos;
,
    q21: &apos;b&apos;, q22: &apos;b&apos;, q23: &apos;a&apos;, q24: &apos;d&apos;, q25: &apos;d&apos;};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã nắm vững subgradient method!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu khá tốt về thuật toán và phân tích hội tụ.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại step size choices và stochastic methods.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Hãy ôn lại các khái niệm cơ bản về subgradient.&apos;;
    } else {
        message = &apos;📖 Hãy học lại từ đầu về subgradient method nhé!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>08-03 Cải tiến Phương pháp Subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_03_improving_on_the_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_03_improving_on_the_subgradient_method</id>
   <content type="html">&lt;p&gt;Kết thúc hành trình Chương 08, ta mang theo một cảm giác vừa phấn khởi vừa tiếc nuối. Phấn khởi vì phương pháp subgradient giải được mọi bài toán lồi không trơn chỉ với một dòng cập nhật duy nhất; nhưng tiếc nuối vì rào cản tốc độ \(O(1/\epsilon^2)\) quá chậm — muốn thêm một chữ số chính xác phải trả giá bằng 100 lần số vòng lặp!&lt;/p&gt;

&lt;p&gt;Câu hỏi lớn mở ra cánh cửa sang Chương 09 là: &lt;em&gt;có phải ta đang lãng phí thông tin không?&lt;/em&gt; Hãy nhìn lại bài toán Lasso \(\frac{1}{2}\|y - X\beta\|_2^2 + \lambda\|\beta\|_1\) hay hồi quy logistic có điều chuẩn \(\ell_1\). Chúng đâu có “xấu xí không trơn ở khắp mọi nơi”! Thực ra chúng là tổng của một hàm &lt;strong&gt;rất đẹp, trơn mượt&lt;/strong&gt; \(g(x)\) cộng với một hàm &lt;strong&gt;không trơn nhưng cực kỳ đơn giản&lt;/strong&gt; \(h(x)\). Phương pháp subgradient đối xử với cả hai như nhau — vứt bỏ hoàn toàn tính trơn của \(g(x)\)! Nếu biết tách riêng hai phần ấy ra, ta có thể kéo tốc độ hội tụ từ \(O(1/\epsilon^2)\) nhảy vọt lên \(O(1/\epsilon)\), và thậm chí \(O(1/\sqrt{\epsilon})\) khi tăng tốc!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-con-đường-vượt-qua-rào-cản-o1epsilon2&quot;&gt;Kiến thức cần nhớ: Ba con đường vượt qua rào cản \(O(1/\epsilon^2)\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khai thác cấu trúc phân tách (Composite Structure \(f = g + h\)):&lt;/strong&gt; Thay vì dùng hộp đen subgradient cho toàn bộ \(f\), ta dùng gradient \(\nabla g(x)\) trên phần trơn và xử lý chính xác phần không trơn \(h(x)\) bằng toán tử gần kề (proximal operator). Đây chính là nền tảng của &lt;strong&gt;Proximal Gradient Descent (Chương 09)&lt;/strong&gt;, khôi phục tốc độ \(O(1/\epsilon)\) và \(O(1/\sqrt{\epsilon})\) (FISTA).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Làm trơn hóa có kiểm soát (Nesterov Smoothing):&lt;/strong&gt; Với một số hàm không trơn dạng \(\max_u (\langle Ax, u\rangle - \phi(u))\), ta có thể cộng thêm số hạng điều chuẩn mạnh nhỏ \(\mu\) để tạo xấp xỉ trơn \(f_\mu\) có gradient Lipschitz \(O(1/\mu)\), rồi chạy gradient tăng tốc để đạt tốc độ \(O(1/\epsilon)\) thay vì \(O(1/\epsilon^2)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khai thác cấu trúc hình học phi Euclid (Mirror Descent &amp;amp; Bundle Methods):&lt;/strong&gt; Thay chuẩn Euclid bằng phân kỳ Bregman (ví dụ entropy âm trên đơn hình xác suất) giúp giảm mạnh hằng số chiều \(n\) từ \(O(\sqrt{n})\) xuống \(O(\sqrt{\ln n})\); còn phương pháp bó (bundle methods) lưu lại nhiều siêu phẳng đỡ quá khứ để xấp xỉ hàm lồi tốt hơn nhiều so với chỉ giữ 1 subgradient hiện tại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-một-phép-thử-tính-tay-cho-thấy-vì-sao-tách-cấu-trúc-thắng-áp-đảo-subgradient&quot;&gt;Giải thích: Một phép thử tính tay cho thấy vì sao “tách cấu trúc” thắng áp đảo subgradient&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu tổng hợp 1D:
\(\min_{x \in \mathbb{R}} \; f(x) = \underbrace{\frac{1}{2}(x - 3)^2}_{g(x)\text{ trơn, }L=1} + \underbrace{|x|}_{h(x)\text{ không trơn}}.\)
Nghiệm tối ưu chính xác là \(x^* = 2\) (vì \(g&apos;(2) + h&apos;(2) = (2 - 3) + 1 = 0\)), với \(f^* = 0.5 + 2 = 2.5\). Xuất phát từ \(x^{(0)} = 0\) (\(f(0) = 4.5\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nếu chạy phương pháp subgradient (coi cả \(f\) là hộp đen không trơn) với bước \(t = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bước 1: tại \(x^{(0)} = 0\), \(g^{(0)} = -3 + 0 = -3 \implies x^{(1)} = 0 - 0.5(-3) = 1.5\) (\(f(1.5) = 1.125 + 1.5 = 2.625\)).&lt;/li&gt;
      &lt;li&gt;Bước 2: tại \(x^{(1)} = 1.5\), \(g^{(1)} = -1.5 + 1 = -0.5 \implies x^{(2)} = 1.5 - 0.5(-0.5) = 1.75\) (\(f(1.75) = 2.53125\)).&lt;/li&gt;
      &lt;li&gt;Bước 3: \(x^{(3)} = 1.875\)… Càng gần \(x^*=2\), phải chạy nhiều bước (và nếu \(x^* = 0\), subgradient sẽ dao động qua lại mãi quanh \(0\) mà không bao giờ đặt chính xác \(x = 0\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nếu tách cấu trúc (Proximal Gradient, Chương 09) với bước \(t = 1/L = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bước gradient trên phần trơn \(g\): \(z = x^{(0)} - 1 \cdot g&apos;(0) = 0 - (-3) = 3\).&lt;/li&gt;
      &lt;li&gt;Áp dụng toán tử co ngưỡng mềm (prox của \(|x|\) với ngưỡng \(t = 1\)):
\(x^{(1)} = \operatorname{sign}(3)\max(|3| - 1, 0) = 2.0 = x^*!\)
Chạm đúng nghiệm tối ưu trong &lt;strong&gt;đúng 1 bước duy nhất&lt;/strong&gt;! Đó chính là sức mạnh của việc tôn trọng cấu trúc toán học thay vì coi hàm là hộp đen.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Phương pháp subgradient có ưu điểm là áp dụng được cho các hàm lồi không khả vi, nên có phạm vi sử dụng rộng hơn gradient descent. Tuy nhiên, tốc độ hội tụ \(O(1/\epsilon^{2})\) của nó chậm hơn nhiều so với tốc độ \(O(1/\epsilon)\) của gradient descent.&lt;/p&gt;

&lt;p&gt;Liệu có thể kết hợp ưu điểm của cả hai phương pháp không? Trong chương tiếp theo, chúng ta sẽ tìm hiểu &lt;strong&gt;phương pháp gradient gần kề (proximal gradient descent)&lt;/strong&gt;, giúp giữ được tốc độ hội tụ tốt trên lớp bài toán tổng hợp có thành phần không khả vi.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02 Phương pháp Subgradient Ngẫu nhiên</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_02_stochastic_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_02_stochastic_subgradient_method</id>
   <content type="html">&lt;p&gt;Hãy hình dung bạn đang huấn luyện một bộ phân loại SVM tuyến tính trên 10 triệu văn bản. Phương pháp subgradient toàn phần (batch) đòi hỏi bạn phải đọc qua toàn bộ 10 triệu văn bản, cộng dồn 10 triệu vector subgradient, chỉ để thực hiện &lt;em&gt;đúng một bước nhích nhỏ&lt;/em&gt; của vector trọng số! Trong khi đó, chỉ cần bốc ngẫu nhiên một (hoặc một lô nhỏ) văn bản thôi, hướng subgradient của nó tuy ồn ào nhưng trung bình lại chỉ đúng về hướng của cả tập dữ liệu.&lt;/p&gt;

&lt;p&gt;Đó chính là bước nhảy tư duy của &lt;strong&gt;phương pháp subgradient ngẫu nhiên (Stochastic Subgradient Method)&lt;/strong&gt; — cầu nối trực tiếp từ giải tích lồi không trơn sang trái tim của học máy quy mô lớn. Mục này giới thiệu khung tư tưởng chung trước khi ta đi sâu vào hai biến thể (chọn ngẫu nhiên và chọn tuần hoàn), định lý hội tụ, tốc độ hội tụ và sự đánh đổi thực chiến với phương pháp batch.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-tối-ưu-không-trơn-ngẫu-nhiên&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của tối ưu không trơn ngẫu nhiên&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán tổng hữu hạn (Finite-sum Optimization):&lt;/strong&gt; Hàm mục tiêu có dạng \(f(x) = \sum_{i=1}^m f_i(x)\) (hoặc trung bình \(\frac{1}{m}\sum_{i=1}^m f_i(x)\)) với \(m\) rất lớn và từng \(f_i\) lồi nhưng có thể không trơn (như mất mát hinge hay \(\ell_1\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng không chệch của subgradient:&lt;/strong&gt; Nếu chọn chỉ số \(i_k\) đều ngẫu nhiên từ \(\{1, \dots, m\}\) và lấy \(g_{i_k} \in \partial f_{i_k}(x)\), thì \(\mathbb{E}[m \, g_{i_k}] = \sum_{i=1}^m g_i \in \partial f(x)\). Nhờ tính không chệch này, sai lệch ngẫu nhiên ở từng bước có kỳ vọng bằng \(0\) và triệt tiêu dần khi cộng dồn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh đổi chi phí mỗi bước lấy nhiễu phương sai:&lt;/strong&gt; Chi phí mỗi vòng lặp giảm \(m\) lần (từ \(O(mp)\) xuống \(O(p)\)), nhưng bước cập nhật luôn kèm nhiễu phương sai nên yêu cầu bước giảm dần \(t_k \to 0\) để đạt độ chính xác cao.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-ước-lượng-không-chệch-trên-4-mẫu-mất-mát-hinge&quot;&gt;Giải thích: Kiểm chứng ước lượng không chệch trên 4 mẫu mất mát hinge&lt;/h3&gt;

&lt;p&gt;Xét 4 điểm dữ liệu 1D có tổng mất mát trung bình \(f(w) = \frac{1}{4}\sum_{i=1}^4 \max(0, 1 - y_i x_i w)\) với \(y_i x_i\) lần lượt là \(+2, +1, -1, +2\) tại \(w = 0.6\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính subgradient từng mẫu tại \(w = 0.6\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Mẫu 1 (\(1 - 1.2 = -0.2 &amp;lt; 0\)): \(g_1 = 0\).&lt;/li&gt;
      &lt;li&gt;Mẫu 2 (\(1 - 0.6 = +0.4 &amp;gt; 0\)): \(g_2 = -1\).&lt;/li&gt;
      &lt;li&gt;Mẫu 3 (\(1 - (-0.6) = +1.6 &amp;gt; 0\)): \(g_3 = +1\).&lt;/li&gt;
      &lt;li&gt;Mẫu 4 (\(1 - 1.2 = -0.2 &amp;lt; 0\)): \(g_4 = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh subgradient toàn phần (batch) và kỳ vọng subgradient ngẫu nhiên:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Subgradient batch: \(g_{\text{batch}} = \frac{1}{4}(0 - 1 + 1 + 0) = 0\) (tốn 4 lần tính).&lt;/li&gt;
      &lt;li&gt;Chọn ngẫu nhiên đều \(i \in \{1, 2, 3, 4\}\): kỳ vọng \(\mathbb{E}[g_i] = \frac{1}{4}(0) + \frac{1}{4}(-1) + \frac{1}{4}(1) + \frac{1}{4}(0) = 0 = g_{\text{batch}}\) (chỉ tốn 1 lần tính!).&lt;/li&gt;
      &lt;li&gt;Tuy nhiên phương sai \(\operatorname{Var}(g_i) = \frac{1}{4}(0 + 1 + 1 + 0) = 0.5 &amp;gt; 0\): dù đang đứng ngay tại điểm có \(g_{\text{batch}} = 0\), bước ngẫu nhiên vẫn có 50% cơ hội đẩy \(w\) lệch đi \(\pm t_k\) — đó là lý do ta phải phân tích sâu hơn về hội tụ ngẫu nhiên ở các bài tiếp theo.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Phương pháp subgradient ngẫu nhiên là sự mở rộng của stochastic gradient descent, trong đó gradient được thay thế bằng subgradient để xử lý các hàm mục tiêu không khả vi.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02-04 So sánh Phương pháp Batch và Ngẫu nhiên</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_02_04_batch_vs_stochastic_methods/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_02_04_batch_vs_stochastic_methods</id>
   <content type="html">&lt;p&gt;Trong phòng thí nghiệm học máy, có một biểu đồ quen thuộc đến mức gần như thành biểu tượng: trục hoành là thời gian tính toán (tính bằng số lượt quét dữ liệu — epochs), trục tung là sai số \(f(x) - f^*\). Đường cong của phương pháp ngẫu nhiên lao dốc thẳng đứng ngay trong epoch đầu tiên, bỏ xa phương pháp batch một khoảng mênh mông; nhưng rồi đến gần đáy, nó bắt đầu rung lắc đi ngang, để đường cong chậm rãi nhưng vững chãi của phương pháp batch âm thầm vượt qua ở độ chính xác cao.&lt;/p&gt;

&lt;p&gt;Bài học này đặt hai phương pháp lên bàn cân thực chiến. Không có kẻ thắng tuyệt đối trong mọi chế độ: hiểu rõ thời điểm chuyển giao giữa “giai đoạn tiếp cận nhanh độ chính xác vừa” (vùng thống trị của stochastic) và “giai đoạn tinh chỉnh độ chính xác cao” (vùng ưu thế của batch) là kỹ năng cốt lõi giúp bạn chọn thuật toán — hoặc thiết kế chiến lược lai (tăng dần cỡ mini-batch theo thời gian).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-tiêu-chí-đối-chiếu-batch-và-ngẫu-nhiên&quot;&gt;Kiến thức cần nhớ: Bốn tiêu chí đối chiếu Batch và Ngẫu nhiên&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí trên mỗi đơn vị giảm sai số ban đầu:&lt;/strong&gt; Khi còn xa nghiệm tối ưu, phương sai nhiễu nhỏ hơn rất nhiều so với tín hiệu hướng đi chung. Nhờ cập nhật \(m\) lần trong thời gian batch cập nhật 1 lần, phương pháp ngẫu nhiên giảm sai số ban đầu nhanh vượt trội.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ chính xác yêu cầu (\(\epsilon\) vừa vs. \(\epsilon\) cực nhỏ):&lt;/strong&gt; Trong học máy thống kê, sai số tổng quát hóa vốn đã bị giới hạn bởi nhiễu dữ liệu (ví dụ \(\epsilon \sim 10^{-2}\) hay \(10^{-3}\)), nên ta hiếm khi cần tối ưu chính xác tới \(10^{-10}\) — đó là lý do phương pháp ngẫu nhiên thống trị huấn luyện mô hình lớn. Ngược lại, trong tối ưu kỹ thuật hoặc bài toán ràng buộc chặt, độ chính xác cao lại cực kỳ quan trọng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả năng song song hóa phần cứng (Vectorization / GPU):&lt;/strong&gt; Phương pháp batch (và mini-batch lớn) tận dụng rất tốt phép nhân ma trận song song trên GPU/TPU, trong khi cập nhật từng mẫu \(B=1\) mang tính tuần tự cao và lãng phí băng thông tính toán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiến lược lai (Growing Mini-batch &amp;amp; Variance Reduction):&lt;/strong&gt; Bắt đầu bằng mini-batch nhỏ để lao nhanh về vùng nghiệm, sau đó tăng dần cỡ lô (hoặc chuyển sang phương pháp giảm phương sai như SVRG/SAGA khi hàm trơn) giúp gặt hái ưu điểm của cả hai thế giới.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bảng-tính-tay-so-sánh-ngân-sách-giữa-batch-và-stochastic-với-m--10000&quot;&gt;Giải thích: Bảng tính tay so sánh ngân sách giữa Batch và Stochastic với \(m = 10{,}000\)&lt;/h3&gt;

&lt;p&gt;Giả sử ta có tập dữ liệu \(m = 10{,}000\) mẫu với \(R = 1, G = 1\). Quy đổi mọi chi phí về &lt;strong&gt;số lượt tính \(g_i\)&lt;/strong&gt; (1 epoch = \(10{,}000\) lượt tính).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Mục tiêu độ chính xác vừa (\(\epsilon = 0.05\), phổ biến trong học máy):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Stochastic:&lt;/strong&gt; Cần \(k \approx \frac{1}{0.05^2} = 400\) lượt tính \(g_i\) = &lt;strong&gt;0.04 epoch&lt;/strong&gt; (mới duyệt 4% dữ liệu!).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Batch:&lt;/strong&gt; Cần \(k \approx 400\) vòng lặp batch = \(400 \times 10{,}000 = 4{,}000{,}000\) lượt tính \(g_i\) = &lt;strong&gt;400 epochs&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Kết luận:&lt;/em&gt; Stochastic nhanh hơn tới &lt;strong&gt;10,000 lần&lt;/strong&gt; về số phép tính lý thuyết ở ngưỡng sai số vừa!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mục tiêu độ chính xác cao khi có bước cố định (\(t = 0.01\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với &lt;strong&gt;Batch&lt;/strong&gt;, nếu bài toán có thêm cấu trúc trơn cục bộ gần nghiệm, ta có thể dùng bước lớn hơn hoặc chuyển sang phương pháp bậc hai/proximal để đạt \(\epsilon = 10^{-6}\) trong vài trăm bước.&lt;/li&gt;
      &lt;li&gt;Với &lt;strong&gt;Stochastic&lt;/strong&gt; bước cố định \(t = 0.01\), sai số kẹt mãi ở sàn \(O(G^2 t / 2) = 0.005\); muốn hạ xuống \(\epsilon = 10^{-4}\) phải giảm bước xuống \(10^{-4}\) và chạy tới \(10^8\) bước = &lt;strong&gt;10,000 epochs&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài học thực hành:&lt;/strong&gt; Dùng mini-batch nhỏ (ví dụ \(B = 64\) hoặc \(256\)) để vừa tận dụng song song hóa, vừa đạt tiến độ nhanh trong vài epoch đầu, rồi giảm learning rate theo lịch hoặc tăng cỡ lô ở giai đoạn cuối.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Đặc điểm hội tụ của phương pháp batch và phương pháp ngẫu nhiên có thể tóm tắt như sau:&lt;/p&gt;

&lt;p&gt;Nhìn chung, phương pháp ngẫu nhiên tiến nhanh về vùng lân cận nghiệm tối ưu trong giai đoạn đầu, nhưng thường dao động và khó hội tụ chính xác khi đã đến gần nghiệm tối ưu. Ngược lại, phương pháp batch tiến chậm hơn ở giai đoạn đầu nhưng hội tụ ổn định và chính xác hơn về điểm tối ưu.&lt;/p&gt;

&lt;p&gt;Hình dưới đây so sánh quá trình hội tụ của hai phương pháp trên bài toán &lt;a href=&quot;https://en.wikipedia.org/wiki/Logistic_regression&quot;&gt;hồi quy logistic&lt;/a&gt; không có chính quy hóa:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter08/08_02_stochastic_vs_batch.png&quot; alt=&quot;stochastic_vs_batch&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 3] So sánh Batch vs Stochastic Gradient Descent [2]&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Khi mỗi hàm thành phần \(f_i\) đều trơn, phần dao động còn lại của đường ngẫu nhiên quanh điểm tối ưu chính là sàn nhiễu mà các phương pháp giảm phương sai trong &lt;a href=&quot;/contents/vi/chapter26/26_05_variance_reduction/&quot;&gt;26-05 SVRG và SAGA&lt;/a&gt; loại bỏ — mà không cần tính lại toàn bộ gradient batch ở mỗi bước.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02-03 Tốc độ Hội tụ của Phương pháp Ngẫu nhiên</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_02_03_convergence_rate_of_stochastic_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_02_03_convergence_rate_of_stochastic_method</id>
   <content type="html">&lt;p&gt;Nếu cả hai biến thể — tuần hoàn và ngẫu nhiên — đều hội tụ, tại sao giới học máy gần như luôn xáo trộn dữ liệu ngẫu nhiên thay vì giữ nguyên thứ tự cố định? Câu trả lời nằm gọn trong bài học này: &lt;strong&gt;phụ thuộc vào số lượng thành phần \(m\) trong tốc độ hội tụ&lt;/strong&gt;. Một phép so sánh tinh tế về cách hằng số Lipschitz \(G\) nhân lên theo \(m\) sẽ cho thấy sự chênh lệch khổng lồ khi \(m\) lên tới hàng triệu.&lt;/p&gt;

&lt;p&gt;Khi ta chạy phương pháp batch trên \(\sum_{i=1}^m f_i(x)\), hằng số Lipschitz của tổng có thể lớn tới \(G_{\text{batch}} = mG\) và mỗi bước tốn \(m\) phép tính subgradient. Biến thể ngẫu nhiên phá vỡ vòng lặp lồng nhau ấy: nhờ tính không chệch, nó đạt độ chính xác \(\epsilon\) chỉ sau số vòng lặp tỷ lệ với \(m^2 G^2 / \epsilon^2\) (tức trung bình chỉ \(m G^2 / \epsilon^2\) lượt quét toàn bộ dữ liệu — tương đương batch), trong khi với bài toán lấy trung bình \(\frac{1}{m}\sum f_i(x)\), tốc độ \(O(G^2/\epsilon^2)\) thậm chí &lt;strong&gt;độc lập hoàn toàn với kích thước tập dữ liệu \(m\)&lt;/strong&gt;!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-so-sánh-tốc-độ-batch-tuần-hoàn-và-ngẫu-nhiên&quot;&gt;Kiến thức cần nhớ: Ba trụ cột so sánh tốc độ batch, tuần hoàn và ngẫu nhiên&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn hóa hàm tổng vs. hàm trung bình:&lt;/strong&gt; Nếu viết \(\min_x \frac{1}{m}\sum_{i=1}^m f_i(x)\) với mỗi \(f_i\) là \(G\)-Lipschitz, thì hàm trung bình cũng \(G\)-Lipschitz. Khi đó:
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Subgradient batch&lt;/em&gt; cần \(O(R^2 G^2 / \epsilon^2)\) bước, mỗi bước tốn \(m\) đánh giá \(\implies\) tổng chi phí \(O(m R^2 G^2 / \epsilon^2)\) đánh giá subgradient.&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Subgradient ngẫu nhiên&lt;/em&gt; cần \(O(R^2 G^2 / \epsilon^2)\) bước, mỗi bước tốn đúng \(1\) đánh giá \(\implies\) tổng chi phí \(O(R^2 G^2 / \epsilon^2)\) — &lt;strong&gt;giảm đúng \(m\) lần&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lý do bản tuần hoàn chậm hơn bản ngẫu nhiên trong trường hợp xấu nhất:&lt;/strong&gt; Trong một chu kỳ tuần hoàn, sai số trượt (drift) giữa điểm đầu chu kỳ và điểm giữa chu kỳ tích lũy tuyến tính theo \(m\), khiến cận lý thuyết xấu nhất bị nhân thêm hệ số theo \(m\) so với bản rút thăm ngẫu nhiên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích theo đơn vị “epoch” (một lượt quét \(m\) mẫu):&lt;/strong&gt; Để so sánh công bằng, ta luôn quy đổi về tổng số phép tính subgradient thành phần \(g_i\). Một bước batch tiêu tốn tài nguyên bằng \(m\) bước ngẫu nhiên.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tổng-số-phép-tính-subgradient-khi-m--1000-mẫu&quot;&gt;Giải thích: Tính tổng số phép tính subgradient khi \(m = 1{,}000\) mẫu&lt;/h3&gt;

&lt;p&gt;Xét bài toán trung bình \(f(x) = \frac{1}{1000}\sum_{i=1}^{1000} f_i(x)\) với \(R = 1\), \(G = 1\), mục tiêu đạt sai số \(\epsilon = 0.1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp subgradient batch:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Số vòng lặp cần theo cận lý thuyết: \(k_{\text{batch}} = \frac{R^2 G^2}{\epsilon^2} = \frac{1^2 \cdot 1^2}{0.1^2} = 100\) vòng lặp.&lt;/li&gt;
      &lt;li&gt;Mỗi vòng lặp phải tính cả \(m = 1{,}000\) subgradient thành phần.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tổng chi phí:&lt;/strong&gt; \(100 \times 1{,}000 = 100{,}000\) lần tính \(g_i\) (tức 100 epochs).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp subgradient ngẫu nhiên (chọn đều \(i_k\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Số vòng lặp cần theo cận kỳ vọng: \(k_{\text{stoch}} = \frac{R^2 G^2}{\epsilon^2} = 100\) vòng lặp.&lt;/li&gt;
      &lt;li&gt;Mỗi vòng lặp chỉ tính đúng \(1\) subgradient thành phần!&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Tổng chi phí:&lt;/strong&gt; \(100 \times 1 = 100\) lần tính \(g_i\) (chỉ bằng &lt;strong&gt;0.1 epoch&lt;/strong&gt; — tức chưa đọc hết nổi 10% tập dữ liệu đã đạt cận kỳ vọng \(\epsilon = 0.1\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưu ý quan trọng khi \(\epsilon\) rất nhỏ:&lt;/strong&gt; Nếu ta đòi độ chính xác siêu cao \(\epsilon = 10^{-4}\), số bước ngẫu nhiên vọt lên \(10^8\) (tức \(100{,}000\) epochs), và vì bước phải thu cực nhỏ nên bản ngẫu nhiên bắt đầu lộ nhược điểm dao động kéo dài.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tốc độ hội tụ lý thuyết có sự khác biệt giữa cách chọn chỉ số tuần hoàn và cách chọn chỉ số ngẫu nhiên.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/contents/vi/chapter08/08_01_04_convergence_rate/&quot;&gt;Tốc độ hội tụ&lt;/a&gt; của phương pháp subgradient batch là \(O(G_{batch}^{2}/\epsilon^{2})\), trong đó \(G_{batch}\) là hằng số Lipschitz của hàm tổng \(\sum f_i\) (có bậc \(mG\) nếu mỗi \(f_i\) có hằng số Lipschitz là \(G\)).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp tuần hoàn&lt;/strong&gt;: Số bước cập nhật cần thiết là \(O(m^{3}G^{2}/\epsilon^{2})\). Nếu quy đổi một chu kỳ (duyệt qua đủ \(m\) hàm thành phần) là tương đương về chi phí với một bước của phương pháp subgradient batch, thì phương pháp tuần hoàn cần \(O(m^{2}G^{2}/\epsilon^{2})\) chu kỳ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp ngẫu nhiên&lt;/strong&gt;: Số bước cập nhật cần thiết là \(O(m^{2}G^{2}/\epsilon^{2})\), tương đương \(O(mG^{2}/\epsilon^2)\) chu kỳ — nhanh hơn \(m\) lần so với phương pháp batch và phương pháp tuần hoàn (\(O(m^2G^2/\epsilon^2)\) chu kỳ). Theo đánh giá Big-O, khi \(m\) lớn, phương pháp ngẫu nhiên có tốc độ hội tụ tốt hơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mặc dù cận Big-O của hai phương pháp chênh nhau một hệ số \(m\), cần lưu ý rằng cận của phương pháp tuần hoàn là đánh giá cho trường hợp xấu nhất, còn cận của phương pháp ngẫu nhiên là đánh giá theo kỳ vọng (trường hợp trung bình). Trong thực tế, mức chênh lệch có thể không lớn như kết quả tiệm cận gợi ý.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02-02 Hội tụ của các Phương pháp Ngẫu nhiên</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_02_02_convergence_of_stochastic_methods/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_02_02_convergence_of_stochastic_methods</id>
   <content type="html">&lt;p&gt;Một câu hỏi rất tự nhiên sau khi thấy ví dụ chạy thử là: &lt;em&gt;nếu mỗi bước ta chỉ nhìn một phần nhỏ của hàm mục tiêu rồi bước theo hướng ồn ào của riêng nó, liệu thuật toán có bị kéo lạc mãi ra xa không?&lt;/em&gt; Đáp án vừa quen vừa mới: cả biến thể tuần hoàn lẫn biến thể ngẫu nhiên đều hội tụ dưới đúng những quy tắc kích thước bước ta đã quen ở phần batch, nhưng &lt;strong&gt;nghĩa của sự hội tụ&lt;/strong&gt; và &lt;strong&gt;kích thước sàn sai số&lt;/strong&gt; có sự khác biệt tinh tế.&lt;/p&gt;

&lt;p&gt;Với bước cố định \(t\), ngay cả khi bạn đặt thuật toán ngay chính giữa nghiệm tối ưu \(x^*\), nhiễu từ các thành phần \(f_i\) khác nhau vẫn lập tức “đá” điểm lặp văng ra khỏi \(x^*\), tạo nên một quỹ đạo dao động trong lân cận của nghiệm. Còn với bước giảm dần thỏa \(\sum t_k = \infty, \sum t_k^2 &amp;lt; \infty\), biên độ của những cú đá ấy nhỏ dần về \(0\), giúp giá trị hàm tốt nhất hội tụ về đúng \(f^*\) (hội tụ tất định với bản tuần hoàn, và hội tụ theo kỳ vọng / hầu chắc chắn với bản ngẫu nhiên).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-lý-thuyết-hội-tụ-ngẫu-nhiên&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của lý thuyết hội tụ ngẫu nhiên&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hội tụ theo kỳ vọng và hầu chắc chắn (Expectation &amp;amp; Almost Sure Convergence):&lt;/strong&gt; Vì dãy \(x^{(k)}\) là dãy biến ngẫu nhiên phụ thuộc vào chuỗi chỉ số rút thăm \(i_1, i_2, \dots\), ta đánh giá \(\mathbb{E}[f_{\text{best}}^{(k)}] - f^* \to 0\) (hoặc hội tụ hầu chắc chắn bằng bổ đề siêu martingale Robbins–Siegmund).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhiễu tại nghiệm tối ưu (Gradient Noise at Optimum):&lt;/strong&gt; Tại \(x^*\), tổng subgradient bằng \(0\) (\(\sum_{i=1}^m g_i(x^*) = 0\)), nhưng từng \(g_i(x^*)\) nói chung &lt;strong&gt;khác \(0\)&lt;/strong&gt;! Chính phương sai nội tại này tạo ra sàn sai số không thể xóa bỏ khi dùng bước cố định \(t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khác biệt giữa sàn sai số tuần hoàn và ngẫu nhiên:&lt;/strong&gt; Trong biến thể tuần hoàn, sai lệch có thể cộng dồn qua trọn một vòng \(m\) mẫu (tạo hệ số lớn hơn theo \(m\)), trong khi bản ngẫu nhiên triệt tiêu sai số chéo nhờ tính độc lập giữa các bước, cho sàn sai số chặt hơn rõ rệt khi \(m\) lớn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-minh-họa-vì-sao-bước-cố-định-luôn-bị-đá-khỏi-nghiệm-tối-ưu&quot;&gt;Giải thích: Minh họa vì sao bước cố định luôn bị “đá” khỏi nghiệm tối ưu&lt;/h3&gt;

&lt;p&gt;Xét bài toán gồm 2 hàm thành phần lồi trên \(\mathbb{R}\):
\(f_1(x) = 2|x - 1|, \quad f_2(x) = |x + 1|, \quad f(x) = f_1(x) + f_2(x).\)
Kiểm tra tại \(x = 1\): \(\partial f_1(1) = [-2, 2]\) và \(\nabla f_2(1) = 1\), nên \(\partial f(1) = [-1, 3] \ni 0\). Vậy \(x^* = 1\) là &lt;strong&gt;nghiệm tối ưu duy nhất&lt;/strong&gt; với \(f^* = 0 + 2 = 2\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khởi đầu ngay tại nghiệm tối ưu \(x^{(0)} = x^* = 1\) với bước cố định \(t = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu bước 1 rút trúng \(i_1 = 2\): dù \(x^{(0)}\) đã tối ưu cho \(f\), ta vẫn có \(g_2(1) = +1 \ne 0\)!&lt;/li&gt;
      &lt;li&gt;Thuật toán cập nhật: \(x^{(1)} = 1 - 0.5(1) = 0.5\), khiến \(f(0.5) = 2(0.5) + 1.5 = 2.5 &amp;gt; f^* = 2\)!&lt;/li&gt;
      &lt;li&gt;Nếu bước 2 rút trúng \(i_2 = 1\): \(g_1(0.5) = -2\), cập nhật \(x^{(2)} = 0.5 - 0.5(-2) = 1.5\), \(f(1.5) = 2(0.5) + 2.5 = 3.5\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thay bằng bước giảm dần \(t_k = 1/k\):&lt;/strong&gt;
Khi \(k = 100\), cú “đá” từ \(f_2\) chỉ còn dịch chuyển \(x\) một lượng \(t_{100} \cdot 1 = 0.01\), làm tăng \(f\) tối đa \(0.03\); khi \(k \to \infty\), bán kính vùng dao động co về đúng \(0\) và dãy hội tụ về \(f^* = 2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Giả sử mỗi hàm thành phần \(f_i\) (\(i = 1,...,m\)) là hàm lồi và liên tục Lipschitz với hằng số \(G\).&lt;/p&gt;

&lt;p&gt;Đối với phương pháp subgradient ngẫu nhiên, ta có hai kết quả hội tụ tương ứng với kích thước bước cố định và kích thước bước giảm dần:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bước cố định&lt;/strong&gt; \(t_k = t\) (\(k = 1, 2, 3, ...\)):&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\text{Đối với cả hai biến thể tuần hoàn và ngẫu nhiên với kích thước bước cố định, ta có:} \\
\begin{align}
\lim_{k\to\infty} f(x_{best}^{(k)}) \le f^{*} + 5m^{2}G^{2}t/2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong đó, \(mG\) là hằng số Lipschitz của hàm tổng \(\sum_{i=1}^{m} f_i\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bước giảm dần&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\text{Đối với cả hai biến thể tuần hoàn và ngẫu nhiên với kích thước bước giảm dần, ta có:} \\
\begin{align}
\lim_{k\to\infty} f(x_{best}^{(k)}) = f^{*}
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02-01 Phương pháp Subgradient Ngẫu nhiên</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_02_01_stochastic_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_02_01_stochastic_subgradient_method</id>
   <content type="html">&lt;p&gt;Nếu bạn đứng giữa một căn phòng đông người đang tranh cãi và muốn tìm hướng đi chung của cả phòng, bạn có hai lựa chọn: hỏi lần lượt từng người theo vòng tròn quanh bàn (tuần hoàn — &lt;em&gt;cyclic&lt;/em&gt;), hoặc rút thăm ngẫu nhiên một người để hỏi ở mỗi bước (&lt;em&gt;randomized&lt;/em&gt;). Trong tối ưu hóa tổng hữu hạn \(\min_x \sum_{i=1}^m f_i(x)\), hai cách chọn chỉ số \(i_k\) này tạo ra hai biến thể cốt lõi của phương pháp subgradient ngẫu nhiên.&lt;/p&gt;

&lt;p&gt;Tưởng như chỉ là chi tiết cài đặt nhỏ, nhưng sự khác biệt giữa chọn tuần hoàn và chọn ngẫu nhiên lại có tác động mạnh đến cả lý thuyết lẫn thực tế: dữ liệu sắp xếp theo thứ tự xấu (ví dụ toàn bộ mẫu dương đứng trước, mẫu âm đứng sau) có thể làm biến thể tuần hoàn chao đảo theo chu kỳ dài, trong khi rút thăm ngẫu nhiên (hoặc xáo trộn dữ liệu mỗi epoch) phá vỡ hoàn toàn các mẫu tuần hoàn bất lợi đó.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-thuật-toán-subgradient-ngẫu-nhiên&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của thuật toán subgradient ngẫu nhiên&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Công thức cập nhật một mẫu (hoặc mini-batch):&lt;/strong&gt; Thay vì tính \(\sum_{i=1}^m g_i^{(k-1)}\), ta chọn một chỉ số \(i_k \in \{1, \dots, m\}\) và cập nhật \(x^{(k)} = x^{(k-1)} - t_k g_{i_k}^{(k-1)}\) với \(g_{i_k}^{(k-1)} \in \partial f_{i_k}(x^{(k-1)})\). Dùng mini-batch cỡ \(B\) là trung dung giữa \(B = 1\) (nhanh, nhiễu cao) và \(B = m\) (chậm, không nhiễu).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc tuần hoàn (Cyclic) vs. Quy tắc ngẫu nhiên (Randomized):&lt;/strong&gt; Quy tắc tuần hoàn quét \(1, 2, \dots, m, 1, 2, \dots\) đảm bảo mọi mẫu được thăm đúng một lần mỗi epoch, nhưng dễ bị thiên lệch nếu thứ tự dữ liệu có cấu trúc. Quy tắc ngẫu nhiên chọn độc lập đều trên \(\{1, \dots, m\}\) đảm bảo tính không chệch ở mọi bước và tránh mọi thứ tự đối kháng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lịch bước và tính tương thích với bài toán không trơn:&lt;/strong&gt; Giống hệt phương pháp subgradient batch, ta không thể dùng line search trên từng \(f_{i_k}\) đơn lẻ (vì làm giảm \(f_{i_k}\) có thể phá hỏng các \(f_j\) khác), nên phải chọn bước cố định nhỏ hoặc bước giảm dần thỏa \(\sum t_k = \infty, \sum t_k^2 &amp;lt; \infty\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chạy-tay-3-bước-subgradient-ngẫu-nhiên-để-tìm-trung-vị-của-3-điểm&quot;&gt;Giải thích: Chạy tay 3 bước subgradient ngẫu nhiên để tìm trung vị của 3 điểm&lt;/h3&gt;

&lt;p&gt;Xét bài toán tìm trung vị của 3 số \(\{1, 2, 5\}\):
\(\min_{x \in \mathbb{R}} \; f(x) = |x - 1| + |x - 2| + |x - 5| = f_1(x) + f_2(x) + f_3(x).\)
Nghiệm tối ưu chính xác là trung vị \(x^* = 2\) với \(f^* = 1 + 0 + 3 = 4\). Bắt đầu tại \(x^{(0)} = 0\) (\(f(0) = 8\)) với lịch bước \(t_k = 1/k\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 (\(t_1 = 1\)), rút ngẫu nhiên \(i_1 = 3\) (\(f_3(x) = |x - 5|\)):&lt;/strong&gt;
Tại \(x^{(0)} = 0 &amp;lt; 5\), \(g_3(0) = -1\).
\(x^{(1)} = 0 - 1(-1) = 1.0, \quad f(1) = 0 + 1 + 4 = 5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 (\(t_2 = 0.5\)), rút ngẫu nhiên \(i_2 = 1\) (\(f_1(x) = |x - 1|\)):&lt;/strong&gt;
Tại \(x^{(1)} = 1\), chọn \(g_1(1) = 0 \in [-1, 1]\).
\(x^{(2)} = 1.0 - 0.5(0) = 1.0, \quad f(1) = 5.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 (\(t_3 = 1/3 \approx 0.333\)), rút ngẫu nhiên \(i_3 = 2\) (\(f_2(x) = |x - 2|\)):&lt;/strong&gt;
Tại \(x^{(2)} = 1 &amp;lt; 2\), \(g_2(1) = -1\).
\(x^{(3)} = 1.0 - \frac{1}{3}(-1) = 1.333, \quad f(1.333) = 0.333 + 0.667 + 3.667 = 4.667.\)
Chỉ sau &lt;strong&gt;3 phép tính subgradient đơn lẻ&lt;/strong&gt; (tương đương đúng 1 vòng lặp batch!), giá trị hàm đã tụt từ \(8\) xuống \(4.667\) — rất gần đáy \(f^* = 4\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa tổng của \(m\) hàm lồi sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{equation}
\min_x \sum_{i=1}^m f_i(x)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu áp dụng phương pháp subgradient tiêu chuẩn, ở mỗi bước lặp ta phải tính subgradient cho toàn bộ \(m\) hàm \(f_i\) rồi cộng lại (tương tự như động cơ dẫn đến &lt;a href=&quot;/contents/vi/chapter06/06_05_stochastic_gradient_descent/&quot;&gt;stochastic gradient descent&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Thay vì tính trên toàn bộ tổng, phương pháp subgradient ngẫu nhiên chỉ cập nhật theo một hàm thành phần tại mỗi bước:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^{(k)} = x^{(k-1)} - t_k \cdot g_{i_k}^{(k-1)}, \quad k = 1, 2, 3, . . . 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Trong đó, \(i_k \in \{1,...,m\}\) là chỉ số được chọn tại bước lặp thứ \(k\), và \(g_{i}^{(k-1)} \in \partial f_{i}(x^{k-1})\). Cách chọn chỉ số \(i_k\) — theo thứ tự tuần hoàn (cyclic) hay chọn ngẫu nhiên (randomized) — sẽ ảnh hưởng đến tốc độ hội tụ, như sẽ phân tích ở bài tiếp theo. Hướng cập nhật này khác với &lt;a href=&quot;/contents/vi/chapter08/08_01_subgradient_method/&quot;&gt;phương pháp subgradient&lt;/a&gt; thông thường (còn gọi là phương pháp subgradient batch hoặc full batch), vốn dùng tổng \(\sum_{i=1}^{m} g_i^{(k-1)}\).&lt;/p&gt;

&lt;p&gt;Khi mọi hàm \(f_i\) (\(i = 1,...,m\)) đều khả vi, thuật toán này trở về đúng stochastic gradient descent; do đó, phương pháp subgradient ngẫu nhiên là một dạng tổng quát hơn.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01 Phương pháp Subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_subgradient_method</id>
   <content type="html">&lt;p&gt;Nếu bạn đã quen với gradient descent, phản xạ tự nhiên nhất khi gặp bài toán không trơn là: “Thay \(\nabla f\) bằng một subgradient \(g \in \partial f\) là ta có ngay &lt;em&gt;subgradient descent&lt;/em&gt;, đúng không?” Câu trả lời khiến hầu hết người học tối ưu lần đầu đều bất ngờ: &lt;strong&gt;không có từ “descent” ở đây&lt;/strong&gt;. Phương pháp này chỉ được gọi là &lt;em&gt;phương pháp subgradient&lt;/em&gt; (subgradient method), và việc bỏ đi một chữ ấy chứa đựng cả một bài học hình học sâu sắc.&lt;/p&gt;

&lt;p&gt;Tại sao hướng âm của một subgradient lại có thể đưa bạn &lt;em&gt;leo ngược lên dốc&lt;/em&gt; ngay cả khi kích thước bước nhỏ tùy ý? Bởi vì subgradient chỉ là pháp tuyến của một siêu phẳng đỡ nằm dưới mặt cong lồi — nó đảm bảo góc nhọn với vector hướng về nghiệm \(x^*\), chứ không đảm bảo độ dốc theo hướng \(-g\) là âm dọc theo mọi cạnh gãy của đồ thị. Vì vậy, muốn thuật toán vận hành tin cậy, ta phải theo dõi kỷ lục tốt nhất \(f_{\text{best}}^{(k)} = \min_{i \le k} f(x^{(i)})\) thay vì chỉ nhìn vào điểm cuối \(x^{(k)}\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trực-giác-định-nghĩa-phương-pháp-subgradient&quot;&gt;Kiến thức cần nhớ: Ba trực giác định nghĩa phương pháp subgradient&lt;/h2&gt;

&lt;p&gt;Để đọc công thức cập nhật \(x^{(k)} = x^{(k-1)} - t_k g^{(k-1)}\) mà thấy ngay chuyển động hình học phía sau, hãy nắm chắc ba nhánh sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Siêu phẳng đỡ và nón pháp tuyến:&lt;/strong&gt; Bất đẳng thức \(f(y) \ge f(x) + g^T(y-x)\) nói rằng khi đặt \(y = x^*\), ta luôn có \(g^T(x - x^*) \ge f(x) - f(x^*) \ge 0\). Nghĩa là \(-g\) luôn tạo góc tù (hoặc vuông) với \(x - x^*\) — tức là nó &lt;em&gt;luôn&lt;/em&gt; chỉ về nửa không gian chứa nghiệm tối ưu \(x^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sự khác biệt giữa hướng giảm hàm và hướng giảm khoảng cách:&lt;/strong&gt; Với hàm khả vi, \(-\nabla f(x)\) vừa làm giảm \(f(x)\) vừa kéo gần \(x^*\). Với hàm không trơn, \(-g\) chỉ bảo toàn tính chất thứ hai (giảm khoảng cách \(\|x - x^*\|_2\) khi bước đủ nhỏ), còn giá trị hàm \(f(x)\) có thể tăng lên ngay lập tức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kỷ lục tốt nhất (Best Iterate Tracking):&lt;/strong&gt; Vì chuỗi \(f(x^{(0)}), f(x^{(1)}), \dots\) có thể nhấp nhô lên xuống như răng cưa, đầu ra thực tế của thuật toán là \(x_{\text{best}}^{(k)} = \arg\min_{0 \le i \le k} f(x^{(i)})\). Toàn bộ các định lý hội tụ của chương này đều phát biểu cho \(f_{\text{best}}^{(k)} - f^*\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-ví-dụ-tính-tay-chứng-minh--g-làm-hàm-tăng-nhưng-vẫn-kéo-gần-x&quot;&gt;Giải thích: Ví dụ tính tay chứng minh \(-g\) làm hàm tăng nhưng vẫn kéo gần \(x^*\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét hàm lồi không trơn hai biến $$f(x_1, x_2) = 3&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\(, có nghiệm tối ưu duy nhất\)x^* = (0, 0)\(với\)f^* = 0$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chọn điểm xuất phát trên sống gãy:&lt;/strong&gt; Lấy \(x^{(0)} = (0, 1)\), giá trị hàm là \(f(0, 1) = 3(0) + 1 = 1\), khoảng cách bình phương tới nghiệm là \(\|x^{(0)} - x^*\|_2^2 = 0^2 + 1^2 = 1\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Tìm một subgradient hợp lệ:&lt;/strong&gt; Tại \(x_1 = 0\), $$\partial (3&lt;/td&gt;
          &lt;td&gt;x_1&lt;/td&gt;
          &lt;td&gt;)\big&lt;/td&gt;
          &lt;td&gt;_{0} = [-3, 3]\(; tại\)x_2 = 1\(, đạo hàm của\)&lt;/td&gt;
          &lt;td&gt;x_2&lt;/td&gt;
          &lt;td&gt;\(là\)1\(. Vậy\)g^{(0)} = (3, 1)\(là một subgradient hoàn toàn hợp lệ trong\)\partial f(0, 1)$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đi một bước nhỏ tùy ý \(t \in (0, 1)\) theo hướng \(-g^{(0)} = (-3, -1)\):&lt;/strong&gt;
\(x^{(1)} = (0, 1) - t(3, 1) = (-3t, 1 - t).\)
Tính giá trị hàm mới:
\(f(x^{(1)}) = 3|-3t| + |1 - t| = 9t + (1 - t) = 1 + 8t &amp;gt; 1 = f(x^{(0)}).\)
Dù chọn bước nhỏ tới đâu (\(t = 0.01\) hay \(t = 10^{-6}\)), hàm \(f\) &lt;strong&gt;vẫn tăng&lt;/strong&gt;! Đây là bằng chứng rõ nhất vì sao \(-g^{(0)}\) không phải hướng giảm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra khoảng cách bình phương tới nghiệm \(x^* = (0, 0)\):&lt;/strong&gt;
\(\|x^{(1)} - x^*\|_2^2 = (-3t)^2 + (1 - t)^2 = 1 - 2t + 10t^2.\)
Với \(t = 0.1\): \(f(x^{(1)}) = 1.8 &amp;gt; 1\) (hàm tăng!), nhưng \(\|x^{(1)} - x^*\|_2^2 = 1 - 0.2 + 0.1 = 0.9 &amp;lt; 1\) (khoảng cách tới nghiệm &lt;strong&gt;giảm thật sự&lt;/strong&gt;!). Nhờ sự co lại của khoảng cách này mà phương pháp subgradient vẫn hội tụ.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Giả sử \(f\) là một hàm lồi xác định trên \({R}^n\) và có thể không khả vi tại một số điểm.&lt;/p&gt;

&lt;p&gt;Phương pháp subgradient được xây dựng bằng cách thay thế gradient trong phương pháp gradient descent bằng một subgradient (\(\nabla f(x^{(k-1)}) \to g(x^{(k-1)})\)):&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = x^{(k-1)} - t_k \cdot g^{(k-1)}, \quad k = 1, 2, 3, . . .\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(g^{(k-1)} \in \partial f(x^{(k-1)})\) là một subgradient của \(f\) tại \(x^{(k-1)}\).&lt;/p&gt;

&lt;h2 id=&quot;vì-sao-gọi-là-phương-pháp-subgradient-chứ-không-phải-subgradient-descent&quot;&gt;Vì sao gọi là “phương pháp subgradient” (chứ không phải “subgradient descent”)&lt;/h2&gt;

&lt;p&gt;Khác với gradient descent, phương pháp subgradient không đảm bảo giá trị hàm mục tiêu luôn giảm sau mỗi bước lặp (do đó thuật toán không được gọi là “subgradient descent”). Vì vậy, trong quá trình chạy thuật toán, cần lưu lại giá trị tốt nhất đạt được tính đến bước hiện tại:&lt;/p&gt;

&lt;blockquote&gt;
\[f(x_{best}^{(k)}) = \min_{i=0,...k} f(x^{(i)})\]
&lt;/blockquote&gt;

&lt;p&gt;Ở đây, \(f(x^{(k)}_{best})\) ký hiệu giá trị nhỏ nhất của hàm \(f\) thu được sau \(k\) bước lặp.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-08 Phương pháp Subgradient có Chiếu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_08_projected_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_08_projected_subgradient_method</id>
   <content type="html">&lt;p&gt;Trong hầu hết các bài toán thực tế, biến quyết định không được phép tung tăng tự do khắp không gian \(\mathbb{R}^n\): xác suất phải không âm và có tổng bằng 1 (nằm trên đơn hình xác suất), trọng số danh mục đầu tư không vượt trần rủi ro, hay nhiễu đối kháng phải nằm trong quả cầu \(\ell_\infty\) bán kính \(\epsilon\). Nếu chỉ chạy bước subgradient \(y^{(k)} = x^{(k-1)} - t_k g^{(k-1)}\), điểm mới rất dễ văng ra ngoài miền ràng buộc \(C\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp subgradient có chiếu (Projected Subgradient Method)&lt;/strong&gt; giải quyết bài toán ấy theo cách trực quan nhất có thể: cứ bước một bước subgradient tự do, rồi kéo ngay điểm vừa bước về điểm gần nhất trong miền hợp lệ \(C\) bằng phép chiếu Euclid \(P_C(\cdot)\). Điều đáng kinh ngạc là toàn bộ bộ máy chứng minh hội tụ của phương pháp không ràng buộc — kể cả bất đẳng thức cơ bản và tốc độ \(O(1/\epsilon^2)\) — vẫn giữ nguyên không sứt mẻ một ly, nhờ một tính chất hình học vàng của tập lồi: phép chiếu luôn làm co (không làm tăng) khoảng cách tới mọi điểm nằm trong \(C\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-phương-pháp-subgradient-có-chiếu&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của phương pháp subgradient có chiếu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính không giãn (Non-expansiveness) của phép chiếu Euclid lên tập lồi đóng:&lt;/strong&gt; Với mọi \(y \in \mathbb{R}^n\) và mọi điểm \(x^* \in C\), ta luôn có:
\(\|P_C(y) - x^*\|_2 \le \|y - x^*\|_2.\)
Về hình học, góc \(\angle(y - P_C(y), x^* - P_C(y)) \ge 90^\circ\) (định lý góc tù của phép chiếu lồi). Nhờ bất đẳng thức này, khi ta thay \(y^{(k)} = x^{(k-1)} - t_k g^{(k-1)}\) bằng \(x^{(k)} = P_C(y^{(k)})\), khoảng cách bình phương tới \(x^*\) chỉ có thể &lt;em&gt;giảm thêm&lt;/em&gt; hoặc giữ nguyên, không bao giờ tăng!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bảo toàn nguyên vẹn tốc độ hội tụ \(O(1/\epsilon^2)\):&lt;/strong&gt; Vì \(\|x^{(k)} - x^*\|_2^2 \le \|x^{(k-1)} - t_k g^{(k-1)} - x^*\|_2^2\), mọi bước trong chứng minh bất đẳng thức cơ bản đều đi qua trơn tru. Phép chiếu hoàn toàn “miễn phí” về mặt số vòng lặp lý thuyết.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí tính phép chiếu — ranh giới của tính thực tiễn:&lt;/strong&gt; Thuật toán chỉ nhanh khi \(P_C(y)\) có công thức đóng hoặc thuật toán tính nhanh: chiếu lên hộp \([l, u]\) là phép cắt ngưỡng (clipping) \(O(n)\); chiếu lên quả cầu \(\ell_2\) là co tỷ lệ \(O(n)\); chiếu lên đơn hình xác suất mất \(O(n \log n)\) (hoặc \(O(n)\) kỳ vọng). Nếu \(C\) là giao phức tạp của nhiều đa diện, phép chiếu bản thân nó đã là một bài toán quy hoạch bậc hai tốn kém.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-một-bước-subgradient-có-chiếu-lên-đĩa-đơn-vị&quot;&gt;Giải thích: Tính tay một bước subgradient có chiếu lên đĩa đơn vị&lt;/h3&gt;

&lt;p&gt;Xét bài toán có ràng buộc trong \(\mathbb{R}^2\):
\(\min_{x \in C} \; f(x) = |x_1 - 2| + |x_2 - 2|, \quad C = \{x \in \mathbb{R}^2 : \|x\|_2 \le 1\}.\)
Đích tự do \((2, 2)\) nằm ngoài đĩa đơn vị, nên nghiệm có ràng buộc phải nằm trên biên của \(C\). Bắt đầu từ \(x^{(0)} = (0, 0) \in C\) với bước \(t_1 = 1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính subgradient tại \(x^{(0)} = (0, 0)\):&lt;/strong&gt;
Vì \(x_1 = 0 &amp;lt; 2\) và \(x_2 = 0 &amp;lt; 2\), cả hai nhánh trị tuyệt đối đều trơn tại \((0, 0)\) với \(g^{(0)} = (-1, -1)\).
Giá trị ban đầu: \(f(0, 0) = 2 + 2 = 4\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước subgradient tự do (chưa chiếu):&lt;/strong&gt;
\(y^{(1)} = x^{(0)} - t_1 g^{(0)} = (0, 0) - 1(-1, -1) = (1, 1).\)
Kiểm tra tính khả thi: \(\|y^{(1)}\|_2 = \sqrt{1^2 + 1^2} = \sqrt{2} \approx 1.414 &amp;gt; 1\) — điểm \(y^{(1)}\) đã văng ra ngoài đĩa \(C\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiếu trực giao lên đĩa đơn vị \(C\):&lt;/strong&gt;
\(x^{(1)} = P_C(1, 1) = \frac{(1, 1)}{\|(1, 1)\|_2} = \left(\frac{1}{\sqrt{2}}, \frac{1}{\sqrt{2}}\right) \approx (0.707, 0.707).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng tính không giãn và chất lượng nghiệm:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Giá trị hàm giảm mạnh: \(f(x^{(1)}) = 2\left(2 - \frac{1}{\sqrt{2}}\right) = 4 - \sqrt{2} \approx 2.586 &amp;lt; 4\).&lt;/li&gt;
      &lt;li&gt;Thực tế, theo bất đẳng thức Cauchy–Schwarz \(x_1 + x_2 \le \sqrt{2}\|x\|_2 \le \sqrt{2}\), nên \(4 - \sqrt{2}\) chính là giá trị tối ưu toàn cục \(f^*\) và \(x^{(1)}\) chạm đúng nghiệm tối ưu ngay trong bước chiếu đầu tiên!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ý tưởng phép chiếu ở ví dụ trước dẫn đến &lt;strong&gt;phương pháp subgradient có chiếu (projected subgradient method)&lt;/strong&gt;, dùng để giải các bài toán tối ưu lồi có ràng buộc.&lt;/p&gt;

&lt;p&gt;Ký hiệu miền ràng buộc là tập lồi đóng \(C\), bài toán tối ưu có dạng:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
\min_x \text{ }f(x) \quad \text{với điều kiện } x \in C
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Phương pháp subgradient có chiếu thực hiện tương tự phương pháp subgradient tiêu chuẩn, nhưng sau mỗi bước cập nhật, điểm mới được chiếu trở lại tập ràng buộc \(C\):&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
x^{(k)} = P_c(x^{(k-1)} - t_k \cdot g^{(k-1)}), \quad k = 1,2,3,...
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu phép chiếu \(P_C\) thực hiện được chính xác, phương pháp này có cùng các tính chất hội tụ và tốc độ hội tụ như phương pháp subgradient không ràng buộc.&lt;/p&gt;

&lt;p&gt;Tuy nhiên, cần lưu ý rằng ngay cả khi \(C\) là một tập lồi có mô tả đơn giản, nếu phép chiếu \(P_C\) khó tính toán thì thuật toán tổng thể vẫn tốn kém. Một số tập \(C\) có phép chiếu tương đối dễ tính gồm:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tập ảnh affine: {\(Ax + b : x \in \mathbb{R}^{n}\)}&lt;/li&gt;
  &lt;li&gt;Tập nghiệm của hệ phương trình tuyến tính: {\(x: Ax=b\)}&lt;/li&gt;
  &lt;li&gt;Góc phần tư không âm (nonnegative orthant): \(\mathbb{R}_+^{n} =\) {\(x: x\ge 0\)}&lt;/li&gt;
  &lt;li&gt;Một số quả cầu chuẩn: {\(x: \lVert x \rVert _p \le 1\)} với \(p=1,2,\infty\)&lt;/li&gt;
  &lt;li&gt;Một số đa diện đơn giản và hình nón đơn giản&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-07 Ví dụ: Giao của các tập hợp</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_07_example_intersection_of_sets/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_07_example_intersection_of_sets</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng bạn cần thiết kế một bộ lọc tín hiệu thỏa mãn đồng thời hàng chục yêu cầu kỹ thuật: năng lượng không vượt ngưỡng, biên độ trong miền tần số nằm trong dải cho phép, và hệ số thời gian bị giới hạn trong hộp cứng. Mỗi yêu cầu định nghĩa một tập lồi \(C_i\), và câu hỏi của bạn không phải là “tối ưu hàm nào” mà là: &lt;em&gt;làm sao tìm được một điểm \(x\) nằm trong giao \(C_1 \cap C_2 \cap \dots \cap C_m\)?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Đây là bài toán khả thi lồi (convex feasibility problem) — một trong những bài toán xuất hiện dày đặc nhất trong xử lý ảnh, tái tạo chụp cắt lớp CT và điều khiển tự động. Điều kỳ diệu mà bài học này phơi bày là khi ta biến bài toán hình học ấy thành cực tiểu hóa khoảng cách lớn nhất \(f(x) = \max_{1 \le i \le m} \operatorname{dist}(x, C_i)\) rồi áp dụng phương pháp subgradient với bước Polyak (vì biết chắc \(f^* = 0\)!), công thức đại số phức tạp tự rút gọn thành một hành động hình học đẹp như mơ: &lt;strong&gt;ở mỗi bước, chọn tập lồi xa nhất và chiếu thẳng \(x\) lên tập đó!&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-nối-giải-tích-không-trơn-với-phép-chiếu-luân-phiên&quot;&gt;Kiến thức cần nhớ: Ba trụ cột nối giải tích không trơn với phép chiếu luân phiên&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm khoảng cách tới tập lồi và tính khả vi của nó:&lt;/strong&gt; Với tập lồi đóng khác rỗng \(C\), hàm \(\operatorname{dist}(x, C) = \min_{y \in C} \|x - y\|_2\) luôn lồi. Khi \(x \notin C\), điểm chiếu \(P_C(x)\) là duy nhất và hàm khoảng cách thực sự &lt;em&gt;khả vi&lt;/em&gt; tại \(x\) với gradient đơn vị \(\nabla \operatorname{dist}(x, C) = \frac{x - P_C(x)}{\|x - P_C(x)\|_2}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc dưới vi phân của hàm max hữu hạn (Danskin / Dubovitskii–Milyutin):&lt;/strong&gt; Với \(f(x) = \max_{1 \le i \le m} f_i(x)\), dưới vi phân tại \(x\) là bao lồi của các dưới vi phân thuộc những nhánh đang đạt cực đại \(I(x) = \{i : f_i(x) = f(x)\}\). Để chạy thuật toán subgradient, ta chỉ cần nhặt một chỉ số \(j \in I(x)\) và lấy đúng gradient của \(f_j\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép chiếu luân phiên (Alternating Projections / POCS) như trường hợp đặc biệt của bước Polyak:&lt;/strong&gt; Thay \(f^* = 0\) và \(\|g^{(k)}\|_2 = 1\) vào bước Polyak:
\(x^{(k+1)} = x^{(k)} - \frac{\|x^{(k)} - P_{C_j}(x^{(k)})\|_2}{1^2} \cdot \frac{x^{(k)} - P_{C_j}(x^{(k)})}{\|x^{(k)} - P_{C_j}(x^{(k)})\|_2} = P_{C_j}(x^{(k)}).\)
Hai ý tưởng tưởng như thuộc hai thế giới khác nhau — subgradient Polyak và chiếu tập lồi POCS — hóa ra là một!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-tìm-giao-của-đĩa-tròn-và-nửa-mặt-phẳng-bằng-subgradient-polyak&quot;&gt;Giải thích: Tính tay tìm giao của đĩa tròn và nửa mặt phẳng bằng subgradient Polyak&lt;/h3&gt;

&lt;p&gt;Trong \(\mathbb{R}^2\), xét hai tập lồi đóng:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Đĩa đơn vị \(C_1 = \{x \in \mathbb{R}^2 : \|x\|_2 \le 1\}\),&lt;/li&gt;
  &lt;li&gt;Nửa mặt phẳng phải \(C_2 = \{x \in \mathbb{R}^2 : x_1 \ge 0.5\}\).
Giao \(C_1 \cap C_2\) khác rỗng (chứa điểm \((0.5, 0)\)), nên \(f^* = 0\). Bắt đầu từ \(x^{(0)} = (-2, 0)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính khoảng cách và hình chiếu tới từng tập tại \(x^{(0)} = (-2, 0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Với \(C_1\): chiếu lên đĩa đơn vị là \(P_{C_1}(-2, 0) = (-1, 0)\), nên \(f_1(x^{(0)}) = \|(-2,0) - (-1,0)\|_2 = 1.0\).&lt;/li&gt;
      &lt;li&gt;Với \(C_2\): chiếu lên \(x_1 \ge 0.5\) là \(P_{C_2}(-2, 0) = (0.5, 0)\), nên \(f_2(x^{(0)}) = \|(-2,0) - (0.5,0)\|_2 = 2.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn nhánh lớn nhất và tính subgradient đơn vị:&lt;/strong&gt;
\(f(x^{(0)}) = \max(1.0, 2.5) = 2.5\) đạt tại \(j = 2\).
Subgradient tương ứng là:
\(g^{(0)} = \frac{x^{(0)} - P_{C_2}(x^{(0)})}{\|x^{(0)} - P_{C_2}(x^{(0)})\|_2} = \frac{(-2.5, 0)}{2.5} = (-1, 0), \quad \|g^{(0)}\|_2 = 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật theo bước Polyak (\(f^* = 0\)):&lt;/strong&gt;
\(t_1 = \frac{f(x^{(0)}) - 0}{\|g^{(0)}\|_2^2} = \frac{2.5}{1} = 2.5 \implies x^{(1)} = (-2, 0) - 2.5(-1, 0) = (0.5, 0) = P_{C_2}(x^{(0)}).\)
Kiểm tra điểm mới \(x^{(1)} = (0.5, 0)\): \(\|x^{(1)}\|_2 = 0.5 \le 1\) (thuộc \(C_1\)) và \(x_1^{(1)} = 0.5 \ge 0.5\) (thuộc \(C_2\)). Ta chạm đích \(f(x^{(1)}) = 0\) ngay sau đúng 1 bước!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Xét bài toán tìm một điểm thuộc giao của nhiều tập lồi đóng \(C_1, C_2, \dots, C_m\).&lt;/p&gt;

&lt;p&gt;Định nghĩa \(f_i(x)\) là khoảng cách từ điểm \(x\) đến tập \(C_i\), và \(f(x)\) là khoảng cách lớn nhất từ \(x\) đến tất cả các tập \(C_i\) (\(i=1,...,m\)):&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
f_i(x) &amp;amp; = \mathbb{dist}(x, C_i), i=1,...,m \\
f(x) &amp;amp; = \max_{1,...,m}\text{ }f_i(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Bài toán tìm giao của các tập lồi có thể được phát biểu thành bài toán tối ưu sau:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
min_{x}\text{ }f(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Việc tìm một điểm chung của các tập lồi tương đương với việc tìm điểm \(x\) cực tiểu hóa khoảng cách lớn nhất \(f(x)\) đến các tập \(C_i\). Hàm mục tiêu \(f(x)\) là hàm lồi. Nếu giao của tất cả các tập là khác rỗng, thì giá trị tối ưu là \(f^* = 0\) và mọi điểm tối ưu đều thỏa mãn \(x^* \in C_1 \cap C_2 \cap ... \cap C_m\).&lt;/p&gt;

&lt;h2 id=&quot;gradient-của-hàm-khoảng-cách&quot;&gt;Gradient của hàm khoảng cách&lt;/h2&gt;

&lt;p&gt;Trong &lt;a href=&quot;/contents/vi/chapter07/07_03_05_example_distance_to_convex_set/&quot;&gt;bài trước&lt;/a&gt;, khoảng cách đến một tập lồi đóng \(C\) được định nghĩa là \(dist(x, C_i) = \min_{y \in C} \lVert y-x \rVert _2\), và với \(x \notin C\), gradient của hàm này là:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
\partial dist(x,C) = \frac{x-P_C(x)}{ \Vert x-P_C(x) \Vert_2}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(P_C(x)\) là phép chiếu Euclid của \(x\) lên tập \(C\).&lt;/p&gt;

&lt;h2 id=&quot;vi-phân-dưới-của-giá-trị-lớn-nhất-hữu-hạn-theo-điểm&quot;&gt;Vi phân dưới của giá trị lớn nhất hữu hạn theo điểm&lt;/h2&gt;

&lt;p&gt;Vi phân dưới của hàm giá trị lớn nhất hữu hạn theo điểm \(f(x)=max_{i=1,...,m}\text{ }f_i(x)\) là:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
\partial f(x) = \text{conv}\left(\bigcup_{i:f_i(x)=f(x)} \partial f_i(x)\right)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Nói cách khác, \(\partial f(x)\) là bao lồi của hợp các vi phân dưới \(\partial f_i(x)\) ứng với những chỉ số \(i\) đạt cực đại \(f_i(x) = f(x)\). Đặc biệt, nếu \(f_i(x) = f(x)\) và \(g_i \in \partial f_i(x)\) thì \(g_i \in \partial f(x)\).&lt;/p&gt;

&lt;h2 id=&quot;suy-ra-công-thức-cập-nhật-subgradient&quot;&gt;Suy ra công thức cập nhật subgradient&lt;/h2&gt;

&lt;p&gt;Nhắc lại từ &lt;a href=&quot;/contents/vi/chapter07/07_03_05_example_distance_to_convex_set/&quot;&gt;chương trước&lt;/a&gt;, với \(x \notin C_i\), hàm \(dist(x, C_i)\) có gradient là:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(Nhắc lại:\)
\(\begin{align}
g_i = \nabla f_i(x) = \frac{x-P_{C_i}(x)}{ \Vert x-P_{C_i}(x) \Vert_2}
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nếu giao của các tập lồi khác rỗng, ta biết ngay \(f^*=0\) nên có thể áp dụng kích thước bước Polyak. Hơn nữa, vì vector \(x-P_{C_i}(x)\) đã được chuẩn hóa, ta có \(\Vert g \Vert_2^{2}=1\). Thay vào công thức kích thước bước Polyak \(t_k = \{\frac{f^{(k-1)}-f^*}{ \Vert g^{(k-1)} \Vert_2^{2}}\}\), bước cập nhật subgradient trở thành:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
x^{(k)} &amp;amp; = x^{(k-1)} - t_{k}⋅g_{k-1} \\
&amp;amp; = x^{(k-1)} - \frac{f^{(k-1)}-f^*}{ \Vert g^{(k-1)} \Vert_2^{2}} \frac{x^{(k-1)}-P_{C_i}(x)}{ \Vert x^{(k-1)}-P_{C_i}(x) \Vert_2}  \\
&amp;amp; = x^{(k-1)} - f(x^{k-1}) \frac{x^{(k-1)}-P_{C_i}(x)}{ \Vert x^{(k-1)}-P_{C_i}(x) \Vert_2}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do \(f(x^{(k-1)}) = dist(x^{(k-1)}, C_i) = \Vert x^{(k-1)}-P_{C_i}(x^{(k-1)}) \Vert_2\) với \(C_i\) là tập xa \(x^{(k-1)}\) nhất, công thức cập nhật rút gọn thành:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
x^{(k)} = P_{C_i}(x^{(k-1)})
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Về mặt hình học, ở mỗi bước thuật toán chiếu điểm hiện tại lên &lt;strong&gt;tập lồi xa nhất&lt;/strong&gt; (tập có khoảng cách lớn nhất tới điểm hiện tại).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter08/08_01_projection.png&quot; alt=&quot;projection&quot; width=&quot;60%&quot; height=&quot;60%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 2] Alternating Projection Algorithm [10]&lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-06 Kích thước bước Polyak</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_06_polyak_step_sizes/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_06_polyak_step_sizes</id>
   <content type="html">&lt;p&gt;Một trong những nỗi đau lớn nhất khi chạy phương pháp subgradient là phải tự “mò” hằng số bước \(t\) hay lịch giảm dần: chọn hơi lớn thì dao động, chọn hơi nhỏ thì bò như rùa. Năm 1969, nhà toán học Liên Xô Boris Polyak đặt ra một câu hỏi táo bạo: &lt;em&gt;nếu ta biết trước độ cao đáy thung lũng \(f^*\), liệu có công thức tự động cho ra bước đi tối ưu nhất ở ngay mỗi vòng lặp không?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Câu trả lời là công thức ngắn gọn đến mức trông như một phép màu: \(t_k = \frac{f(x^{(k-1)}) - f^*}{\|g^{(k-1)}\|_2^2}\). Trong nhiều bài toán thực tế, ta thực sự biết chính xác \(f^*\) — ví dụ tìm điểm chung của các tập lồi (\(f^* = 0\)), giải hệ bất đẳng thức tuyến tính khả thi (\(f^* = 0\)), hay bài toán khớp dữ liệu nội suy (interpolating models) trong học sâu hiện đại nơi loss tối ưu bằng \(0\). Và ngay cả khi chỉ nhìn vào cách suy ra công thức Polyak, bạn cũng sẽ thấy sự kết hợp hoàn mỹ giữa tối thiểu hóa cận trên khoảng cách và phép chiếu lên siêu phẳng đỡ!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-góc-nhìn-về-kích-thước-bước-polyak&quot;&gt;Kiến thức cần nhớ: Bốn góc nhìn về kích thước bước Polyak&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối thiểu hóa trực tiếp khoảng cách bước sau:&lt;/strong&gt; Xuất phát từ bất đẳng thức \(\|x^{(k)} - x^*\|_2^2 \le \|x^{(k-1)} - x^*\|_2^2 - 2 t_k (f^{(k-1)} - f^*) + t_k^2 \|g^{(k-1)}\|_2^2\), vế phải là một hàm bậc hai lồi theo biến \(t_k\). Lấy đạo hàm theo \(t_k\) bằng \(0\) cho ra ngay nghiệm duy nhất \(t_k = \frac{f^{(k-1)} - f^*}{\|g^{(k-1)}\|_2^2}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diễn giải hình học (Phương pháp Newton 1D / Chiếu lên siêu phẳng):&lt;/strong&gt; Siêu phẳng tiếp tuyến đỡ \(y \mapsto f(x^{(k-1)}) + g^{(k-1)T}(y - x^{(k-1)})\) cắt mặt mức \(f^*\) tại một siêu phẳng \(H_k\). Điểm \(x^{(k)}\) dùng bước Polyak chính xác là &lt;strong&gt;hình chiếu trực giao&lt;/strong&gt; của \(x^{(k-1)}\) lên siêu phẳng \(H_k\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tự động thích nghi theo độ dốc và khoảng cách tới đáy:&lt;/strong&gt; Khi còn xa đáy (\(f^{(k-1)} - f^*\) lớn), bước đi tự động lớn để tăng tốc; khi sát đáy (\(f^{(k-1)} - f^* \to 0\)), bước đi tự động co về \(0\) mà không cần đặt lịch giảm dần bằng tay, đồng thời bất biến với phép nhân hằng số dương vào hàm \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mở rộng khi chưa biết chính xác \(f^*\):&lt;/strong&gt; Nếu chỉ có ước lượng \(\hat{f}_k\) (ví dụ từ nghiệm đối ngẫu hoặc cơ chế cập nhật mục tiêu kiểu Polyak–Nedich), bước Polyak ước lượng vẫn hoạt động hiệu quả và là nền tảng của bộ tối ưu SPS (Stochastic Polyak Step-size) trong học sâu từ năm 2021 trở lại đây.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-bước-polyak-trên-hàm-gấp-khúc-1d-và-2d&quot;&gt;Giải thích: Tính tay bước Polyak trên hàm gấp khúc 1D và 2D&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 1 (1D — chạm đáy trong đúng 1 bước):&lt;/strong&gt; Xét \(f(x) = \max(2x - 2, -x + 1)\), có đáy \(f^* = 0\) tại \(x^* = 1\).&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Bắt đầu tại \(x^{(0)} = 4\): \(f(4) = \max(6, -3) = 6\), nhánh hoạt động là \(2x - 2\) nên \(g^{(0)} = 2\).&lt;/li&gt;
  &lt;li&gt;Áp dụng công thức Polyak:
\(t_1 = \frac{f(4) - f^*}{|g^{(0)}|^2} = \frac{6 - 0}{2^2} = 1.5.\)&lt;/li&gt;
  &lt;li&gt;Cập nhật: \(x^{(1)} = 4 - 1.5 \times 2 = 1.0 = x^*\)! Vì nhánh hoạt động là hàm tuyến tính, siêu phẳng đỡ trùng đúng với đồ thị nhánh và cắt mức \(0\) ngay tại nghiệm.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 2 (2D — thu hẹp khoảng cách chắc chắn):&lt;/strong&gt; Xét \(f(x_1, x_2) = |x_1| + 2|x_2|\) (\(f^* = 0\), \(x^* = (0, 0)\)) từ \(x^{(0)} = (2, 1)\).&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Tính giá trị và subgradient: \(f(2, 1) = 2 + 2(1) = 4\); \(g^{(0)} = (1, 2)\) nên \(\|g^{(0)}\|_2^2 = 1^2 + 2^2 = 5\).&lt;/li&gt;
  &lt;li&gt;Bước Polyak: \(t_1 = \frac{4 - 0}{5} = 0.8\).&lt;/li&gt;
  &lt;li&gt;Điểm mới: \(x^{(1)} = (2, 1) - 0.8(1, 2) = (1.2, -0.6)\).&lt;/li&gt;
  &lt;li&gt;Kiểm chứng cả hai đại lượng:
    &lt;ul&gt;
      &lt;li&gt;Giá trị hàm giảm: \(f(1.2, -0.6) = 1.2 + 2(0.6) = 2.4 &amp;lt; 4\).&lt;/li&gt;
      &lt;li&gt;Bình phương khoảng cách tới \(x^*\) giảm đúng lượng dự báo \(\frac{(f^{(0)} - f^*)^2}{\|g^{(0)}\|_2^2} = \frac{16}{5} = 3.2\):
\(\|x^{(0)}\|_2^2 = 5 \longrightarrow \|x^{(1)}\|_2^2 = 1.44 + 0.36 = 1.80 = 5 - 3.2!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Kích thước bước Polyak&lt;/strong&gt; là quy tắc chọn kích thước bước khi đã biết trước giá trị tối ưu \(f^*\). Công thức kích thước bước Polyak được định nghĩa như sau:&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa-kích-thước-bước-polyak&quot;&gt;Định nghĩa kích thước bước Polyak&lt;/h2&gt;
&lt;blockquote&gt;

\[\begin{align}
t_k = \frac{f^{(k-1)}-f^*}{ \Vert g^{(k-1)} \Vert_2^{2}}, \quad k = 1,2,3...
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;cách-suy-ra-kích-thước-bước-polyak&quot;&gt;Cách suy ra kích thước bước Polyak&lt;/h2&gt;
&lt;p&gt;Ta xuất phát từ bất đẳng thức trung gian trong phần &lt;a href=&quot;/contents/vi/chapter08/08_01_02_basic_inequality/&quot;&gt;bất đẳng thức cơ bản&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
 \Vert x^{(k)}-x^* \Vert_2^{2}  \quad \le \quad  \Vert x^{(k-1)}-x^* \Vert_2^{2}-2t_k (f(x^{(k-1)})-f^*)+t_k^{2} \Vert g^{(k-1)} \Vert_2^{2} \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Lấy đạo hàm vế phải theo \(t_k\) và cho bằng 0 để cực tiểu hóa cận trên của khoảng cách \(\Vert x^{(k)}-x^* \Vert_2^2\), ta thu được kích thước bước Polyak:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp; \frac{\partial}{\partial t_k}  \Vert x^{(k-1)}-x^* \Vert_2^{2}-2t_k (f(x^{(k-1)})-f^*)+t_k^{2} \Vert g^{(k-1)} \Vert_2^{2} = 0 \\
 \Longleftrightarrow &amp;amp; -2(f(x^{(k-1)})-f^*)+2t_k \Vert g^{(k-1)} \Vert_2^{2} = 0 \\
 \Longleftrightarrow &amp;amp; f(x^{(k-1)})-f^* = t_k \Vert g^{(k-1)} \Vert_2^{2} \\
 \Longleftrightarrow &amp;amp; t_k = \frac{f(x^{(k-1)})-f^*}{ \Vert g^{(k-1)} \Vert_2^{2}} \quad \text{(kích thước bước Polyak tại bước k)}
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;tốc-độ-hội-tụ-của-kích-thước-bước-polyak&quot;&gt;Tốc độ hội tụ của kích thước bước Polyak&lt;/h2&gt;

&lt;p&gt;Thay kích thước bước Polyak \(t_i\) vào bất đẳng thức tổng quát từ phần &lt;a href=&quot;/contents/vi/chapter08/08_01_02_basic_inequality/&quot;&gt;bất đẳng thức cơ bản&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp; 2\sum_{i=1}^{k}t_i(f(x^{(i)})-f^*) \le R^2 + \sum_{i=1}^kt_i^2 \Vert g^{(i)} \Vert_2^2 \\
 \Longleftrightarrow \quad &amp;amp; 2\sum_{i=1}^{k}\frac{(f(x^{(i)})-f^*)^2}{ \Vert g^{(i)} \Vert_2^2} \le R^2 + \sum_{i=1}^k\frac{(f(x^{(i)})-f^*)^2}{ \Vert g^{(i)} \Vert_2^2} \\
 \Longleftrightarrow \quad &amp;amp; \sum_{i=1}^{k}\frac{(f(x^{(i)})-f^*)^2}{ \Vert g^{(i)} \Vert_2^2} \le R^2 \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Với giả thiết Lipschitz \(\Vert g^{(i)} \Vert_2 \le G\), bất đẳng thức trên dẫn đến:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp; \sum_{i=1}^{k}(f(x^{(i)})-f^*)^2 \le R^2G^2 \\
 \Longleftrightarrow \quad &amp;amp; k ⋅ (f(x^{(i)})-f^*)^2 \le R^2G^2 \\
 \Longleftrightarrow \quad &amp;amp; \sqrt{k} ⋅ (f(x^{(i)})-f^*) \le RG \\
 \Longleftrightarrow \quad &amp;amp; (f(x^{(i)})-f^*) \le \frac{RG}{\sqrt{k}} \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;(Trong các dòng suy ra cuối, \(f(x^{(i)})\) được hiểu là giá trị tốt nhất qua \(k\) bước lặp, tức \(f^{(k)}_{best}\).)&lt;/p&gt;

&lt;p&gt;Đặt \(\frac{RG}{\sqrt{k}}=\epsilon\), ta thu được \(k=\big(\frac{RG}{\epsilon}\big)^2\). Như vậy, số bước lặp cần thiết để đạt sai số \(\epsilon\) có bậc \(\big(\frac{RG}{\epsilon}\big)^2\), tức tốc độ hội tụ là \(O(1/\epsilon^{2})\) — cùng bậc với các quy tắc chọn bước khác của phương pháp subgradient.&lt;/p&gt;

&lt;h3 id=&quot;bước-polyak-chọn-độ-dài-bước-từ-f-video&quot;&gt;Bước Polyak: chọn độ dài bước từ f* (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/polyak-step_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;Bước cố định dừng lại ở một lân cận quanh nghiệm tối ưu, bước giảm dần tiến rất chậm, còn bước Polyak \(\alpha_k=\dfrac{f(x_k)-f^*}{\|g_k\|_2^2}\) hướng thẳng về điểm cực tiểu nhưng đòi hỏi phải biết trước \(f^*\).&lt;/p&gt;

&lt;h3 id=&quot;tự-tay-thử-ba-quy-tắc-kích-thước-bước&quot;&gt;Tự tay thử: ba quy tắc kích thước bước&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;sgm&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-05 Ví dụ: Hồi quy Logistic có Điều Chuẩn</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_05_example_regularized_logistic_regression/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_05_example_regularized_logistic_regression</id>
   <content type="html">&lt;p&gt;Hồi quy logistic là “ngựa thồ” kinh điển của học máy thống kê — hàm mất mát log-loss của nó trơn vô hạn lần, lồi đẹp đẽ và có gradient tính trong chớp mắt. Thế nhưng chỉ cần thêm vào một số hạng điều chuẩn chuẩn \(\ell_1\) nhỏ bé \(\lambda \|\beta\|_1\) để tự động loại bỏ các đặc trưng nhiễu và tạo mô hình thưa (sparse), toàn bộ các siêu phẳng tọa độ \(\beta_j = 0\) lập tức biến thành những đường gãy sắc cạnh!&lt;/p&gt;

&lt;p&gt;Ngay tại thời điểm mô hình đạt độ thưa mong muốn (nhiều trọng số \(\beta_j = 0\)), đạo hàm cổ điển lại biến mất đúng ở những tọa độ đó. Bài học này cho thấy cách phương pháp subgradient bước vào giải quyết trọn vẹn bài toán hồi quy logistic có điều chuẩn \(\ell_1\) (và so sánh với điều chuẩn \(\ell_2\) trơn), đồng thời làm lộ ra một tinh tế quan trọng: khi một trọng số bằng \(0\), ta được quyền chọn bất kỳ giá trị nào trong đoạn \([-\lambda, \lambda]\) cho thành phần subgradient tương ứng.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-hồi-quy-logistic-có-điều-chuẩn&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của hồi quy logistic có điều chuẩn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mất mát log-loss và tính lồi trơn:&lt;/strong&gt; Với xác suất dự đoán \(p_i(\beta) = \sigma(x_i^T\beta) = \frac{1}{1 + e^{-x_i^T\beta}}\), đạo hàm của \(-\sum (y_i x_i^T\beta - \log(1 + e^{x_i^T\beta}))\) có dạng cực kỳ trực quan: \(\nabla \ell(\beta) = \sum_{i=1}^n (p_i(\beta) - y_i) x_i\) — chính là tổng các vector đặc trưng có trọng số bằng sai số dự đoán!&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Điều chuẩn \(\ell_1\) vs \(\ell_2\) và hình học tạo thưa:&lt;/strong&gt; Số hạng \(\frac{\lambda}{2}|\beta|_2^2\) trơn khắp nơi và chỉ co nhỏ trọng số về gần \(0\); trong khi \(\lambda|\beta|_1\) có góc nhọn dọc các trục tọa độ, tạo ra dưới vi phân $$\partial(\lambda&lt;/td&gt;
          &lt;td&gt;\beta_j&lt;/td&gt;
          &lt;td&gt;)\big&lt;/td&gt;
          &lt;td&gt;_0 = [-\lambda, \lambda]\(đủ rộng để hấp thụ gradient nhỏ của hàm mất mát và giữ chặt\)\beta_j = 0$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc cộng dưới vi phân (Moreau–Rockafellar):&lt;/strong&gt; Vì cả hàm mất mát log-loss lẫn hàm phạt \(\lambda\|\beta\|_1\) đều lồi và xác định trên toàn \(\mathbb{R}^p\), dưới vi phân của tổng bằng tổng các dưới vi phân: \(\partial f(\beta) = \nabla \ell(\beta) + \lambda \partial \|\beta\|_1\). Ta chỉ cần tính từng phần rồi cộng lại theo từng tọa độ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-một-bước-subgradient-cho-hồi-quy-logistic-ell_1&quot;&gt;Giải thích: Tính tay một bước subgradient cho hồi quy logistic \(\ell_1\)&lt;/h3&gt;

&lt;p&gt;Xét tập dữ liệu 1 chiều cực gọn gồm 2 mẫu: \((x_1, y_1) = (1, 1)\) và \((x_2, y_2) = (-1, 0)\), hệ số điều chuẩn \(\lambda = 0.5\):
\(f(\beta) = \sum_{i=1}^2 \big(-y_i x_i \beta + \log(1 + e^{x_i \beta})\big) + 0.5|\beta|.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính gradient phần log-loss tại điểm khởi tạo \(\beta^{(0)} = 0\):&lt;/strong&gt;
Tại \(\beta = 0\), xác suất dự đoán cho cả hai mẫu đều là \(p_1(0) = p_2(0) = \frac{1}{1 + e^0} = 0.5\).
    &lt;ul&gt;
      &lt;li&gt;Đóng góp mẫu 1: \((p_1 - y_1) x_1 = (0.5 - 1)(1) = -0.5\).&lt;/li&gt;
      &lt;li&gt;Đóng góp mẫu 2: \((p_2 - y_2) x_2 = (0.5 - 0)(-1) = -0.5\).&lt;/li&gt;
      &lt;li&gt;Tổng gradient phần trơn: \(\nabla \ell(0) = -0.5 + (-0.5) = -1.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác định tập dưới vi phân \(\partial f(0)\) và kiểm tra xem \(\beta = 0\) có tối ưu không:&lt;/strong&gt;
Vì \(\partial (0.5|\beta|)\big|_0 = [-0.5, 0.5]\), ta có:
\(\partial f(0) = -1.0 + [-0.5, 0.5] = [-1.5, -0.5].\)
Vì \(0 \notin [-1.5, -0.5]\), điểm \(\beta = 0\) &lt;strong&gt;chưa tối ưu&lt;/strong&gt; (tín hiệu dữ liệu mạnh hơn lực phạt \(\lambda = 0.5\)). Ngược lại, nếu ta tăng \(\lambda = 1.2\), thì \(\partial f(0) = [-2.2, 0.2] \ni 0\) và \(\beta^* = 0\) lập tức là nghiệm tối ưu!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thực hiện một bước cập nhật subgradient với \(t_1 = 0.5\):&lt;/strong&gt;
Chọn \(s^{(0)} = 0 \in [-1, 1]\) cho \(\partial |\beta|\big|_0\) (quy ước phổ biến nhất trong code), ta có \(g^{(0)} = -1.0 + 0.5(0) = -1.0\).
\(\beta^{(1)} = 0 - 0.5(-1.0) = 0.5.\)
Khi \(\beta^{(1)} = 0.5 &amp;gt; 0\), ta kiểm tra: \(f(0) = 2\ln 2 \approx 1.386\), còn \(f(0.5) = -0.5 + \ln(1+e^{0.5}) + \ln(1+e^{-0.5}) + 0.25 = -0.5 + 0.974 + 0.474 + 0.25 = 1.198 &amp;lt; 1.386\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cho tập dữ liệu \((x_i, y_i) \in \mathbb{R}^p \times \{0, 1\}\) với \(i=1,...,n\). Hàm mất mát của hồi quy logistic được định nghĩa như sau:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
f(\beta) = \sum_{i=1}^n\big(-y_ix_i^T\beta + \log(1+\exp(x_i^T\beta))\big)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vì đây là tổng hữu hạn của các hàm tuyến tính và hàm log-sum-exp, \(f(\beta)\) là hàm lồi và khả vi.&lt;/p&gt;

&lt;p&gt;Xét bài toán hồi quy logistic có chính quy hóa đối với \(\beta\):&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\min_{\beta} \text{ } f(\beta) + \lambda \cdot P(\beta)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;trong đó thành phần phạt \(P(\beta)\) có thể là \(\Vert \beta \Vert _2^2\) (chính quy hóa Ridge) hoặc \(\Vert \beta \Vert _1\) (chính quy hóa Lasso).&lt;/p&gt;

&lt;p&gt;Hàm mục tiêu với phạt Ridge vẫn là hàm lồi khả vi, còn hàm mục tiêu với phạt Lasso là hàm lồi không khả vi. Khi áp dụng gradient descent cho bài toán Ridge và phương pháp subgradient cho bài toán Lasso, rồi vẽ giá trị hàm mục tiêu theo số bước lặp \(k\), ta có thể trực quan hóa sự khác biệt về tốc độ hội tụ giữa hai phương pháp.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter08/08_01_grad_vs_subgrad.png&quot; alt=&quot;grad_vs_subgrad&quot; width=&quot;90%&quot; height=&quot;90%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Gradient descent so với phương pháp Subgradient [3]&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Kết quả thực nghiệm cho thấy gradient descent hội tụ nhanh hơn đáng kể so với phương pháp subgradient.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-04 Tốc độ hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_04_convergence_rate/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_04_convergence_rate</id>
   <content type="html">&lt;p&gt;Có một thực tế phũ phàng mà bất kỳ kỹ sư tối ưu nào cũng sớm chạm mặt: một thuật toán &lt;em&gt;có hội tụ&lt;/em&gt; chưa chắc đã &lt;em&gt;dùng được&lt;/em&gt;. Nếu để giảm sai số đi 10 lần mà số vòng lặp tăng lên 100 lần, thời gian tính toán sẽ nhanh chóng vượt quá tuổi thọ dự án. Bài học này đặt con số chính xác lên chiếc đồng hồ đó: phương pháp subgradient đạt tốc độ hội tụ \(O(1/\epsilon^2)\) — chậm hơn một bậc toàn diện so với \(O(1/\epsilon)\) của gradient descent trên hàm trơn.&lt;/p&gt;

&lt;p&gt;Điều đặc biệt là tốc độ \(O(1/\epsilon^2)\) không phải do ta chứng minh kém hay chọn bước chưa khéo. Trong lý thuyết độ phức tạp thông tin của Nemirovski và Yudin, tồn tại các hàm lồi không trơn (trong không gian chiều đủ lớn) mà &lt;em&gt;không một thuật toán bậc nhất hộp đen nào&lt;/em&gt; chỉ hỏi giá trị hàm và subgradient có thể vượt qua cận dưới \(\Omega(1/\epsilon^2)\). Nói cách khác, \(O(1/\epsilon^2)\) vừa là giới hạn, vừa là thành tích tối ưu của lớp bài toán hoàn toàn không trơn.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-phân-tích-tốc-độ-hội-tụ&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của phân tích tốc độ hội tụ&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu hóa cận trên theo kích thước bước (Step-size Balancing):&lt;/strong&gt; Xuất phát từ cận \(f_{\text{best}}^{(k)} - f^* \le \frac{R^2}{2kt} + \frac{G^2 t}{2}\), ta xem đây là hàm của \(t &amp;gt; 0\). Dùng bất đẳng thức AM–GM (hoặc lấy đạo hàm theo \(t\) bằng \(0\)), hai số hạng bằng nhau khi \(t^* = \frac{R}{G\sqrt{k}}\), cho ra cận nhỏ nhất \(\frac{RG}{\sqrt{k}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển đổi giữa tốc độ theo số bước \(k\) và độ phức tạp theo sai số \(\epsilon\):&lt;/strong&gt; Đặt \(\frac{RG}{\sqrt{k}} \le \epsilon\) rồi giải tìm \(k\), ta thu được \(k \ge \frac{R^2 G^2}{\epsilon^2} = O(1/\epsilon^2)\). Như vậy tốc độ \(O(1/\sqrt{k})\) theo số bước tương đương chính xác với độ phức tạp \(O(1/\epsilon^2)\) theo độ chính xác mong muốn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý cận dưới thông tin (Oracle Complexity Lower Bound):&lt;/strong&gt; Trên lớp hàm lồi \(G\)-Lipschitz trong \(\mathbb{R}^n\) (với \(n\) lớn), mọi phương pháp bậc nhất chỉ dùng tổ hợp tuyến tính các subgradient quá khứ đều có sai số ít nhất \(\Omega(RG/\sqrt{k})\). Do đó, muốn phá vỡ rào cản \(O(1/\epsilon^2)\), ta bắt buộc phải khai thác thêm cấu trúc (tính trơn, tính tách được, hoặc phép toán gần kề).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-ngân-sách-vòng-lặp-cụ-thể-cho-o1epsilon2-so-với-o1epsilon&quot;&gt;Giải thích: Tính ngân sách vòng lặp cụ thể cho \(O(1/\epsilon^2)\) so với \(O(1/\epsilon)\)&lt;/h3&gt;

&lt;p&gt;Giả sử bài toán có \(R = 10\) và \(G = 2\), nên tích \(RG = 20\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tìm bước cố định tối ưu cho ngân sách \(k\) bước:&lt;/strong&gt;
Đặt \(\phi(t) = \frac{100}{2kt} + \frac{4t}{2} = \frac{50}{kt} + 2t\).
Đạo hàm \(\phi&apos;(t) = -\frac{50}{kt^2} + 2 = 0 \implies t^* = \frac{5}{\sqrt{k}} = \frac{R}{G\sqrt{k}}\).
Thay vào \(\phi(t^*)\): \(\phi(t^*) = \frac{50}{k(5/\sqrt{k})} + 2\frac{5}{\sqrt{k}} = \frac{10}{\sqrt{k}} + \frac{10}{\sqrt{k}} = \frac{20}{\sqrt{k}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đếm số vòng lặp theo từng mức sai số \(\epsilon\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Muốn \(\epsilon = 0.1\): cần \(\frac{20}{\sqrt{k}} \le 0.1 \implies \sqrt{k} \ge 200 \implies k \ge 40{,}000\) bước (với \(t^* = 5/200 = 0.025\)).&lt;/li&gt;
      &lt;li&gt;Muốn chính xác gấp 10 lần, \(\epsilon = 0.01\): cần \(\sqrt{k} \ge 2{,}000 \implies k \ge 4{,}000{,}000\) bước — &lt;strong&gt;tăng gấp 100 lần&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh với gradient descent trên hàm trơn (\(L = 2\)):&lt;/strong&gt;
Với gradient descent, cận sai số là \(\frac{LR^2}{2k} = \frac{100}{k}\).
    &lt;ul&gt;
      &lt;li&gt;Để đạt \(\epsilon = 0.1\): chỉ cần \(k = 1{,}000\) bước (nhanh hơn 40 lần).&lt;/li&gt;
      &lt;li&gt;Để đạt \(\epsilon = 0.01\): chỉ cần \(k = 10{,}000\) bước (nhanh hơn &lt;strong&gt;400 lần&lt;/strong&gt;!).
Con số chênh lệch 400 lần này giải thích trọn vẹn vì sao trong thực tế, mỗi khi tách được phần trơn ra khỏi phần không trơn (như Lasso hay hồi quy logistic có chuẩn \(\ell_1\)), ta sẽ rất hào hứng chuyển sang phương pháp gradient gần kề ở Chương 09.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tốc độ hội tụ mô tả số bước lặp cần thiết để đạt một điểm cận tối ưu với sai số \(\epsilon\) theo độ lớn của \(\epsilon\), biểu diễn qua &lt;a href=&quot;https://en.wikipedia.org/wiki/Big_O_notation&quot;&gt;ký hiệu Big-O&lt;/a&gt;. Chẳng hạn, nếu \(\epsilon = 10^{-2}\) và tốc độ hội tụ là \(O(1/\epsilon)\), thuật toán cần khoảng \(1/10^{-2}=10^2\) bước lặp.&lt;/p&gt;

&lt;p&gt;Ta sử dụng &lt;a href=&quot;/contents/vi/chapter08/08_01_02_basic_inequality/&quot;&gt;08-01-02 Bất đẳng thức cơ bản&lt;/a&gt; để suy ra tốc độ hội tụ của phương pháp subgradient với kích thước bước cố định.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(Nhắc lại:\)
\begin{align}
f^{k}_{best} - f^{*} \quad \le \quad \frac{R^{2}}{2kt} + \frac{G^{2}t}{2}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Giả sử ta chọn \(t\) và \(k\) sao cho \(\frac{R^{2}}{2kt} \le \frac{\epsilon}{2}\) và \(\frac{G^{2}t}{2} \le \frac{\epsilon}{2}\) (trong đó \(\epsilon\) là sai số cận tối ưu, \(G\) là hằng số Lipschitz, và \(R\) là khoảng cách từ điểm khởi tạo đến điểm tối ưu). Khi đó \(\frac{R^{2}}{2kt} + \frac{G^{2}t}{2} \le \epsilon\). Từ \(\frac{G^{2}t}{2} \le \frac{\epsilon}{2}\) suy ra \(t \le \frac{\epsilon}{G^{2}}\); kết hợp với \(\frac{R^{2}}{2kt} \le \frac{\epsilon}{2}\) ta có \(k \ge \frac{R^2G^2}{\epsilon^2}\). Như vậy, để bảo đảm \(f^{k}_{best} - f^{*} \le \epsilon\), số bước lặp cần thiết có bậc \(\frac{R^2G^2}{\epsilon^2}\).&lt;/p&gt;

&lt;p&gt;Do đó, tốc độ hội tụ của phương pháp subgradient là \(O(1/\epsilon^2)\), đòi hỏi nhiều bước lặp hơn đáng kể so với tốc độ \(O(1/\epsilon)\) của gradient descent trên hàm trơn.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-03 Phân tích hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_03_convergence_analysis/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_03_convergence_analysis</id>
   <content type="html">&lt;p&gt;Trong giải tích tối ưu, câu hỏi “thuật toán này có hội tụ không?” luôn đi kèm một câu hỏi sắc bén hơn: &lt;em&gt;“Hội tụ dưới giả thiết tối thiểu nào, và hội tụ tới đâu?”&lt;/em&gt; Với gradient descent ở Chương 06, ta phải đòi hỏi \(\nabla f\) liên tục Lipschitz (tức hàm phải đủ “mượt”, độ cong không vô hạn). Nhưng với bài toán không trơn, \(\nabla f\) thậm chí còn không tồn tại tại những điểm quan trọng nhất! Do đó, phương pháp subgradient hạ thấp đòi hỏi xuống một bậc hoàn toàn khác: chỉ cần chính hàm \(f\) liên tục Lipschitz với hằng số \(G\).&lt;/p&gt;

&lt;p&gt;Cái giá của sự phóng khoáng về giả thiết thể hiện ngay trong kết quả định lý hội tụ: nếu giữ kích thước bước cố định \(t\), sai số không tiến về \(0\) mà dừng ở ngưỡng \(G^2 t / 2\); chỉ khi cho kích thước bước giảm dần đúng chuẩn (\(\sum t_k = \infty, \sum t_k^2 &amp;lt; \infty\)), cả hai phần của phân số trong bất đẳng thức cơ bản mới đồng loạt triệt tiêu về \(0\). Hiểu rõ cơ chế phân tách hai số hạng này sẽ giúp bạn chẩn đoán ngay vì sao một mô hình học máy đứng yên ở mức loss cố định khi dùng learning rate hằng số.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-giả-thiết-và-cơ-chế-hội-tụ&quot;&gt;Kiến thức cần nhớ: Bốn giả thiết và cơ chế hội tụ&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Tính liên tục Lipschitz của hàm \(f\) (thay vì của \(\nabla f\)):&lt;/strong&gt; Điều kiện $$&lt;/td&gt;
          &lt;td&gt;f(x) - f(y)&lt;/td&gt;
          &lt;td&gt;\le G|x - y|_2\(tương đương với mọi subgradient đều bị chặn chuẩn:\)|g|_2 \le G\(với mọi\)g \in \partial f(x)\(. Lưu ý rằng các hàm bậc hai như\)f(x) = x^2\(không Lipschitz toàn cục trên\)\mathbb{R}$$, nhưng vẫn Lipschitz trên mọi miền bị chặn chứa quỹ đạo lặp.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân rã cận sai số thành hai thành phần:&lt;/strong&gt; Từ bất đẳng thức cơ bản với bước cố định \(t\):
\(f_{\text{best}}^{(k)} - f^* \le \underbrace{\frac{R^2}{2kt}}_{\text{sai số khởi điểm (giảm về } 0\text{)}} + \underbrace{\frac{G^2 t}{2}}_{\text{sàn dao động (không giảm)}}.\)
Nhìn vào hai số hạng này, ta thấy ngay vì sao tăng \(k \to \infty\) chỉ xóa được phần thứ nhất mà không xóa được phần thứ hai.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý hội tụ cho bước giảm dần:&lt;/strong&gt; Khi \(\sum_{i=1}^k t_i \to \infty\) (mẫu số ra vô cực) trong khi \(\sum_{i=1}^k t_i^2 \to C &amp;lt; \infty\) (tử số bị chặn), phân số \(\frac{R^2 + G^2\sum_{i=1}^k t_i^2}{2\sum_{i=1}^k t_i}\) bắt buộc tiến về \(0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khác biệt giữa hội tụ giá trị hàm và hội tụ điểm lặp:&lt;/strong&gt; Định lý khẳng định \(f_{\text{best}}^{(k)} \to f^*\); còn bản thân dãy \(x^{(k)}\) chỉ hội tụ về tập nghiệm \(X^*\) khi có thêm giả thiết (chẳng hạn tập nghiệm bị chặn hoặc hàm lồi mạnh).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-trực-tiếp-hai-số-hạng-sai-số-cho-bước-cố-định-và-bước-t_k--1k&quot;&gt;Giải thích: Tính trực tiếp hai số hạng sai số cho bước cố định và bước \(t_k = 1/k\)&lt;/h3&gt;

&lt;p&gt;Giả sử một bài toán lồi không trơn có khoảng cách ban đầu \(R = 4\) và hằng số Lipschitz \(G = 1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp bước cố định \(t = 0.2\):&lt;/strong&gt;
Cận sai số tại bước \(k\) là:
\(f_{\text{best}}^{(k)} - f^* \le \frac{4^2}{2 \cdot k \cdot 0.2} + \frac{1^2 \cdot 0.2}{2} = \frac{40}{k} + 0.1.\)
    &lt;ul&gt;
      &lt;li&gt;Sau \(k = 40\) bước: cận là \(1.0 + 0.1 = 1.1\).&lt;/li&gt;
      &lt;li&gt;Sau \(k = 400\) bước: cận là \(0.1 + 0.1 = 0.2\).&lt;/li&gt;
      &lt;li&gt;Sau \(k = 40{,}000\) bước: cận là \(0.001 + 0.1 = 0.101\) — chạy thêm hàng chục nghìn bước cũng không phá nổi sàn \(0.1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trường hợp bước giảm dần \(t_i = 1/i\):&lt;/strong&gt;
Ta biết tổng điều hòa \(H_k = \sum_{i=1}^k \frac{1}{i} \approx \ln k + 0.577\), còn \(\sum_{i=1}^k \frac{1}{i^2} &amp;lt; \frac{\pi^2}{6} \approx 1.645\).
    &lt;ul&gt;
      &lt;li&gt;Tử số luôn nhỏ hơn \(R^2 + G^2 \cdot 1.645 = 16 + 1.645 = 17.645\) với mọi \(k\).&lt;/li&gt;
      &lt;li&gt;Mẫu số \(2 H_k\) tăng mãi ra vô cực: tại \(k = 100\), \(2 H_{100} \approx 10.37 \implies \text{cận} \approx 1.70\); tại \(k = 10^6\), \(2 H_{10^6} \approx 28.79 \implies \text{cận} \approx 0.61\).&lt;/li&gt;
      &lt;li&gt;Khi \(k \to \infty\), cận tiến về đúng \(0\), không còn sàn sai số — nhưng đổi lại tốc độ co của \(\ln k\) rất chậm, gợi ý vì sao bài tiếp theo ta cần tìm quy tắc bước tối ưu theo số vòng lặp \(k\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Trong gradient descent, ta giả thiết \(\nabla f\) liên tục Lipschitz; còn trong phương pháp subgradient, ta giả thiết chính hàm \(f\) liên tục Lipschitz (xem thêm định lý hội tụ của gradient descent tại &lt;a href=&quot;#post-not-found&quot;&gt;06-03-01&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Giả sử \(f\) là hàm lồi với \(\text{dom } f = \mathbb{R}^n\) và thỏa mãn điều kiện Lipschitz:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
| f(x) - f(y) | \le G \lVert x - y \rVert_2 \text{ với mọi } x, y
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Dưới các giả thiết này, ta có hai kết quả hội tụ tương ứng với kích thước bước cố định và kích thước bước giảm dần.&lt;/p&gt;

&lt;h2 id=&quot;định-lý-hội-tụ-cho-kích-thước-bước-cố-định&quot;&gt;Định lý hội tụ cho kích thước bước cố định&lt;/h2&gt;

&lt;p&gt;Với kích thước bước cố định \(t_k = t\):&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\lim_{k\to\infty} f(x^{(k)}_{best}) \le f^* + \frac{G^{2}t}{2}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;định-lý-hội-tụ-cho-kích-thước-bước-giảm-dần&quot;&gt;Định lý hội tụ cho kích thước bước giảm dần&lt;/h2&gt;

&lt;p&gt;Với kích thước bước giảm dần thỏa mãn điều kiện chuẩn:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\lim_{k\to\infty}f(x^{(k)}_{best}) = f^*
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h2&gt;

&lt;h3 id=&quot;trường-hợp-kích-thước-bước-cố-định&quot;&gt;Trường hợp kích thước bước cố định&lt;/h3&gt;

&lt;p&gt;Với kích thước bước cố định, ta có \(\sum_{i=1}^{k}t_{i} = kt\) và \(\sum_{i=1}^{k}t_{i}^{2} = kt^2\). Thay vào bất đẳng thức cơ bản:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; f_{best}^{(k)} - f^* \le \frac{R^{2}+G^{2}\sum_{i=1}^{k}t_{i}^{2}}{2\sum_{i=1}^{k}t_{i}} = \frac{R^{2}+G^{2}k t^{2}}{2kt}  = \frac{R^{2}}{2tk} + \frac{G^{2}t}{2} \\
&amp;amp; \lim_{k→\infty}(f^{(k)}_{best} - f^*) \le 0 + \frac{G^{2}t}{2} = \frac{G^{2}t}{2} \\
&amp;amp; \lim_{k→\infty}(f^{(k)}_{best}) \le f^* + \frac{G^{2}t}{2}
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;trường-hợp-kích-thước-bước-giảm-dần&quot;&gt;Trường hợp kích thước bước giảm dần&lt;/h3&gt;

&lt;p&gt;Chứng minh sử dụng hai điều kiện (1) và (2) của dãy kích thước bước giảm dần:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{(1)} \sum_{i=1}^{\infty} t_i = \infty, \quad \text{(2)}  \sum_{i=1}^{\infty} t_i^{2} = \beta &amp;lt; \infty
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Thay vào bất đẳng thức cơ bản và cho \(k \to \infty\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; f_{best}^{(k)} - f^* \le \frac{R^{2}+G^{2}\sum_{i=1}^{k}t_{i}^{2}}{2\sum_{i=1}^{k}t_{i}} \\
&amp;amp; \lim_{k→\infty}(f^{(k)}_{best} - f^* ) \le \frac{R^{2}+G^{2}\beta}{2\infty} = 0 \\
&amp;amp; \lim_{k→\infty}(f^{(k)}_{best}) =  f^* \\
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-02 Bất đẳng thức cơ bản</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_02_basic_inequality/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_02_basic_inequality</id>
   <content type="html">&lt;p&gt;Mọi định lý lớn về hội tụ trong chương này — từ bước cố định, bước giảm dần, cho tới tốc độ \(O(1/\epsilon^2)\) và kích thước bước Polyak — đều mọc ra từ cùng một gốc rễ duy nhất: &lt;strong&gt;bất đẳng thức cơ bản của phương pháp subgradient&lt;/strong&gt;. Thú vị hơn nữa, chứng minh của nó không hề cần đến công cụ giải tích cao cấp nào; nó chỉ dài đúng vài dòng đại số sơ cấp dựa trên hằng đẳng thức \(\|a - b\|_2^2 = \|a\|_2^2 - 2a^T b + \|b\|_2^2\) và phép cộng dồn rút gọn (telescoping sum).&lt;/p&gt;

&lt;p&gt;Điều kỳ diệu nằm ở góc nhìn “kế toán năng lượng”: ở mỗi bước lặp \(i\), lượng khoảng cách bình phương \(\|x^{(i)} - x^*\|_2^2\) thay đổi bởi hai lực kéo ngược chiều nhau. Một bên là lực hút về nghiệm \(-2\alpha_i(f(x^{(i)}) - f^*)\) kéo ta tiến lại gần \(x^*\); bên kia là lực nhiễu bước đi \(+\alpha_i^2 \|g^{(i)}\|_2^2\) sinh ra do ta bước thẳng theo subgradient. Khi cộng dồn qua \(k\) bước, tất cả các số hạng trung gian tự triệt tiêu nhau như quân domino, để lại đúng một cân bằng hoàn hảo giữa khoảng cách ban đầu \(R^2\) và tổng bình phương bước đi \(G^2 \sum \alpha_i^2\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-tạo-nên-bất-đẳng-thức-cơ-bản&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép tạo nên bất đẳng thức cơ bản&lt;/h2&gt;

&lt;p&gt;Để không bao giờ phải học thuộc lòng công thức \(\frac{R^2 + G^2\sum \alpha_i^2}{2\sum \alpha_i}\), hãy nhìn rõ bốn viên gạch xây nên nó:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khai triển bình phương chuẩn Euclid:&lt;/strong&gt; Đẳng thức \(\|x^{(k+1)} - x^*\|_2^2 = \|x^{(k)} - x^*\|_2^2 - 2\alpha_k g^{(k)T}(x^{(k)} - x^*) + \alpha_k^2 \|g^{(k)}\|_2^2\) là phương trình cân bằng ở từng bước, biến một bài toán phi tuyến thành tổng các số hạng dễ chặn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức định nghĩa subgradient:&lt;/strong&gt; Từ \(f(x^*) \ge f(x^{(k)}) + g^{(k)T}(x^* - x^{(k)})\), ta đổi vế để thay tích vô hướng \(g^{(k)T}(x^{(k)} - x^*)\) bằng đại lượng ta thực sự quan tâm là khoảng cách hàm mục tiêu \(f(x^{(k)}) - f^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giả thiết bị chặn \(R\) và \(G\):&lt;/strong&gt; Khoảng cách khởi điểm \(\|x^{(0)} - x^*\|_2 \le R\) kiểm soát tử số ban đầu, còn tính Lipschitz \(\|g^{(i)}\|_2 \le G\) chặn số hạng bậc hai \(\alpha_i^2 \|g^{(i)}\|_2^2 \le \alpha_i^2 G^2\) để bước đi không bị nổ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng rút gọn (Telescoping Sum) và chặn dưới bởi \(f_{\text{best}}^k\):&lt;/strong&gt; Khi cộng từ \(i=1\) đến \(k\), chuỗi \(\|x^{(i)} - x^*\|_2^2 - \|x^{(i+1)} - x^*\|_2^2\) rút gọn còn \(\|x^{(1)} - x^*\|_2^2 - \|x^{(k+1)} - x^*\|_2^2 \le R^2\). Sau đó dùng \(\sum \alpha_i (f(x^{(i)}) - f^*) \ge (f_{\text{best}}^k - f^*)\sum \alpha_i\) để tách ra kỷ lục tốt nhất.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-từng-số-hạng-của-bất-đẳng-thức-cơ-bản-bằng-tay&quot;&gt;Giải thích: Kiểm chứng từng số hạng của bất đẳng thức cơ bản bằng tay&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((\)x^* = 0\(,\)f^* = 0\(,\)G = 1\(), bắt đầu tại\)x^{(0)} = 1.5\((nên\)R = 1.5\(,\)R^2 = 2.25\() và dùng bước cố định\)\alpha_0 = \alpha_1 = 1\(trong\)k = 2$$ bước.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính quỹ đạo thực tế:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(x^{(0)} = 1.5\): \(f(x^{(0)}) = 1.5\), \(g^{(0)} = 1\). Cập nhật \(x^{(1)} = 1.5 - 1(1) = 0.5\).&lt;/li&gt;
      &lt;li&gt;Tại \(x^{(1)} = 0.5\): \(f(x^{(1)}) = 0.5\), \(g^{(1)} = 1\). Cập nhật \(x^{(2)} = 0.5 - 1(1) = -0.5\).&lt;/li&gt;
      &lt;li&gt;Kỷ lục tốt nhất sau hai điểm đã duyệt: \(f_{\text{best}} = \min(1.5, 0.5) = 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra phương trình năng lượng ở từng bước:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Bước 0:&lt;/strong&gt; \(\|x^{(1)} - x^*\|^2 = 0.25\), trong khi \(\|x^{(0)} - x^*\|^2 - 2\alpha_0(f(x^{(0)}) - f^*) + \alpha_0^2 \|g^{(0)}\|^2 = 2.25 - 2(1)(1.5) + 1(1) = 0.25\) (khớp chính xác!).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; \(\|x^{(2)} - x^*\|^2 = 0.25\), trong khi \(0.25 - 2(1)(0.5) + 1(1) = 0.25\) (khớp chính xác!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cộng dồn hai bước và đối chiếu bất đẳng thức cơ bản:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Cộng hai vế: \(2(1)(1.5 + 0.5) = 4 = 2.25 - 0.25 + 1^2(1 + 1) \le R^2 + G^2\sum \alpha_i^2 = 2.25 + 2 = 4.25\).&lt;/li&gt;
      &lt;li&gt;Chia cho \(2\sum \alpha_i = 4\):
\(f_{\text{best}} - f^* = 0.5 \;\le\; \frac{1.5 + 0.5}{2} = 1.0 \;\le\; \frac{2.25 + 2}{4} = 1.0625.\)
Mọi mắc xích — từ bình phương khoảng cách, tổng rút gọn đến cận trên cuối cùng — đều khớp từng con số thập phân!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Định lý hội tụ và tốc độ hội tụ của phương pháp subgradient đều được suy ra từ bất đẳng thức cơ bản dưới đây.&lt;/p&gt;

&lt;h2 id=&quot;bất-đẳng-thức-cơ-bản&quot;&gt;Bất đẳng thức cơ bản&lt;/h2&gt;

&lt;blockquote&gt;
\[\begin{align}
f_{best}^{k} - f^* \quad \le \quad \frac{R^{2}+G^{2}\sum_{i=1}^{k}\alpha_{i}^{2}}{2\sum_{i=1}^{k}\alpha_{i}} 
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h2&gt;

&lt;p&gt;Nếu \(x^*\) là một điểm tối ưu của hàm \(f\), ta có khai triển bình phương khoảng cách:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
 \Vert x^{(k+1)}-x^* \Vert _2^{2} &amp;amp; \quad = \quad  \Vert x^{(k)}-\alpha_k g^{(k)}-x^* \Vert _2^{2}  \\
                                   &amp;amp; \quad = \quad  \Vert (x^{(k)}-x^*)-\alpha_k g^{(k)} \Vert _2^{2}  \\
                                   &amp;amp; \quad = \quad  \Vert x^{(k)}-x^* \Vert _2^2 - 2 \alpha_k g^{(k)T}(x^{(k)}-x^*)+\alpha_k^2 \Vert g^{(k)} \Vert _2^2 \\
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Theo định nghĩa của subgradient, ta có:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
f(x^*) \ge f(x^{(k)}) + g^{(k)T}(x^*-x^{(k)}) &amp;amp; \quad \Longleftrightarrow \quad f(x^*)-f(x^{(k)}) \ge  g^{(k)T}(x^*-x^{(k)}) \\
                     &amp;amp; \quad  \Longleftrightarrow \quad f(x^{(k)}) - f(x^*) \le  g^{(k)T}(x^{(k)}-x^*) \\
                     &amp;amp; \quad \Longleftrightarrow \quad -2\alpha_{k}(f(x^{(k)}) - f(x^*)) \ge  -2\alpha_{k}(g^{(k)T}(x^{(k)}-x^*)) \\
                     &amp;amp; \quad \Longleftrightarrow \quad -2\alpha_{k}(g^{(k)T}(x^{(k)}-x^*)) \le -2\alpha_{k}(f(x^{(k)})-f(x^*)) \\
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Thay bất đẳng thức này vào biểu thức khai triển ở trên và cộng dồn theo các bước lặp, ta thu được bất đẳng thức cơ bản đã phát biểu ở đầu bài.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-01 Lựa chọn kích thước bước</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_01_step_size_choices/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_01_01_step_size_choices</id>
   <content type="html">&lt;p&gt;Nếu bạn bịt mắt đi xuống một khe núi hẹp mà không thể đo xem bước tiếp theo có thấp hơn chỗ đang đứng hay không, bạn sẽ quyết định độ dài mỗi bước như thế nào? Bước quá to thì bạn cứ nhảy qua nhảy lại giữa hai vách núi mãi không dừng; bước thu nhỏ quá nhanh thì bạn kiệt sức đứng im giữa chừng khi chưa kịp chạm đáy. Đó chính xác là thế lưỡng nan của &lt;strong&gt;lựa chọn kích thước bước&lt;/strong&gt; trong phương pháp subgradient.&lt;/p&gt;

&lt;p&gt;Khác với gradient descent nơi backtracking line search tự động dò bước an toàn nhờ điều kiện giảm Armijo, phương pháp subgradient không có bảo chứng giảm đơn điệu nên buộc phải đặt lịch kích thước bước ngay từ đầu. Chính hai điều kiện tưởng chừng trừu tượng của giải tích chuỗi — \(\sum_{k=1}^{\infty} t_k = \infty\) và \(\sum_{k=1}^{\infty} t_k^2 &amp;lt; \infty\) — lại gói trọn đúng trực giác vật lý: tổng quãng đường phải vô hạn để đi tới bất kỳ điểm tối ưu nào dù xa đến đâu, nhưng bước phải nhỏ dần đủ nhanh để dập tắt hoàn toàn dao động quanh điểm gãy.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-đằng-sau-lịch-kích-thước-bước&quot;&gt;Kiến thức cần nhớ: Ba trụ cột đằng sau lịch kích thước bước&lt;/h2&gt;

&lt;p&gt;Để chọn đúng quy tắc bước cho bài toán thực tế và hiểu gốc rễ toán học của chúng, hãy kết nối ba mảng kiến thức sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chuỗi số điều hòa và chuỗi \(p\)-series (Giải tích thực):&lt;/strong&gt; Điều kiện không khả tổng \(\sum t_k = \infty\) nhưng khả tổng bình phương \(\sum t_k^2 &amp;lt; \infty\) chọn đúng vùng “vàng” \(t_k \sim c / k^p\) với \(\frac{1}{2} &amp;lt; p \le 1\). Chẳng hạn \(t_k = 1/k\) thỏa cả hai (\(\sum 1/k = \infty\), \(\sum 1/k^2 = \pi^2/6 &amp;lt; \infty\)), còn \(t_k = 1/\sqrt{k}\) vi phạm điều kiện thứ hai vì \(\sum 1/k = \infty\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh đổi giữa thiên lệch (bias) và độ dao động (variance/floor):&lt;/strong&gt; Với bước cố định \(t_k = t\), thuật toán không bao giờ dừng lại hẳn tại điểm gãy mà dao động trong một vùng bán kính tỷ lệ thuận với \(t\) (sai số dư bậc \(G^2 t / 2\)). Giảm \(t\) giúp đáy sai số nhỏ hơn nhưng kéo dài thời gian tiếp cận từ xa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lịch bước theo ngân sách vòng lặp hữu hạn (Horizon-aware Steps):&lt;/strong&gt; Trong thực hành, ta hiếm khi chạy vô hạn bước. Nếu biết trước sẽ chạy đúng \(K\) vòng lặp, chọn bước cố định tối ưu \(t = \frac{R}{G\sqrt{K}}\) (hoặc bước giảm dần \(t_k = \frac{c}{\sqrt{k}}\)) thường cho tốc độ nhanh hơn nhiều so với \(t_k = 1/k\) vốn co bước quá sớm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-3-lịch-bước-bằng-tay-trên-hàm-fx--x&quot;&gt;Giải thích: So sánh 3 lịch bước bằng tay trên hàm \(f(x) = |x|\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét bài toán cực tiểu hóa $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((nghiệm\)x^* = 0\(,\)g(x) = \operatorname{sign}(x)\(với\)&lt;/td&gt;
      &lt;td&gt;g&lt;/td&gt;
      &lt;td&gt;= 1$$).&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước cố định \(t_k = 1\) từ \(x^{(0)} = 1.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = 1.5 - 1(1) = 0.5\) (\(f = 0.5\))&lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = 0.5 - 1(1) = -0.5\) (\(f = 0.5\))&lt;/li&gt;
      &lt;li&gt;\(x^{(3)} = -0.5 - 1(-1) = 0.5\) (\(f = 0.5\))
Thuật toán mắc kẹt mãi trong chu kỳ dao động \(0.5 \leftrightarrow -0.5\), không bao giờ tiến dưới mức sai số \(0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước giảm quá nhanh \(t_k = (0.5)^k\) từ \(x^{(0)} = 3\) (vi phạm \(\sum t_k = \infty\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tổng quãng đường tối đa có thể đi sau vô hạn bước là \(\sum_{k=1}^{\infty} (0.5)^k = 0.5 + 0.25 + 0.125 + \dots = 1.\)&lt;/li&gt;
      &lt;li&gt;Vì vậy \(x^{(k)} &amp;gt; 3 - 1 = 2\) với mọi \(k\)! Thuật toán “chết máy” ngay tại \(x = 2\) dù cách nghiệm \(x^* = 0\) tới 2 đơn vị.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước giảm dần đúng chuẩn \(t_k = 1/k\) từ \(x^{(0)} = 1.5\) (thỏa \(\sum t_k = \infty\) và \(\sum t_k^2 &amp;lt; \infty\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
\[x^{(1)} = 1.5 - 1(1) = 0.5\]
      &lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = 0.5 - 0.5(1) = 0\) — chạm đúng nghiệm tối ưu \(x^* = 0\)!
Ngay cả khi không chạm trúng \(0\) ở bước 2 (ví dụ bắt đầu từ \(x^{(0)} = 1.4\)), biên độ dao động quanh \(0\) sẽ co dần theo \(1/k \to 0\), bảo đảm hội tụ về đúng \(f^* = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Có nhiều cách để lựa chọn &lt;strong&gt;kích thước bước&lt;/strong&gt; trong phương pháp subgradient. Dưới đây là hai cách phổ biến:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bước cố định&lt;/strong&gt;: \(t_k = t\) với mọi \(k = 1, 2, 3, ...\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bước giảm dần&lt;/strong&gt;: dãy \(t_k\) thỏa mãn đồng thời hai điều kiện:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\sum_{k=1}^{\infty} t_k = \infty, \quad \sum_{k=1}^{\infty} t_k^{2} &amp;lt; \infty
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;ví-dụ-về-kích-thước-bước-giảm-dần&quot;&gt;Ví dụ về kích thước bước giảm dần&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; t_k = \frac{1}{k}, k = 1,2,3,... \\
&amp;amp; \sum_{k=1}^{\infty}t_k = \infty \quad \text{(Chuỗi điều hòa)} \\
&amp;amp; \sum_{k=1}^{\infty}t^2_k \approx 1.644934 &amp;lt; \infty \quad \text{(Bài toán Basel)}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Một đặc điểm quan trọng của phương pháp subgradient là kích thước bước thường phải được chọn trước, khác với gradient descent. Nói cách khác, không giống tìm kiếm đường thẳng lùi (backtracking line search) trong gradient descent, kích thước bước ở đây không tự điều chỉnh theo độ cong cục bộ của hàm mục tiêu.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08 Phương pháp Subgradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_00_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter08/08_00_subgradient_method</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng bạn đang trượt tuyết xuống một thung lũng có đáy hình chữ V sắc cạnh thay vì một lòng chảo parabol mượt mà. Ở mọi sườn dốc trơn láng, la bàn đạo hàm \(\nabla f(x)\) chỉ chính xác hướng dốc nhất để bạn trượt xuống; nhưng ngay khoảnh khắc ván trượt chạm vào sống rãnh gấp khúc của chữ V, độ dốc bị gãy đột ngột và đạo hàm cổ điển biến mất. Thế giới tối ưu hóa hiện đại — từ bài toán Lasso với chuẩn \(\ell_1\), máy vector hỗ trợ (SVM) với mất mát bản lề (hinge loss), đến mạng nơ-ron dùng hàm kích hoạt ReLU — tràn ngập những “sống rãnh sắc cạnh” như vậy.&lt;/p&gt;

&lt;p&gt;Chương 08 mở ra cánh cửa bước qua ranh giới khả vi bằng một ý tưởng thanh lịch đáng kinh ngạc: &lt;strong&gt;phương pháp subgradient&lt;/strong&gt;. Thay vì đầu hàng trước những điểm gãy không có tiếp tuyến duy nhất, ta thay gradient bằng &lt;em&gt;một&lt;/em&gt; siêu phẳng đỡ (supporting hyperplane) bất kỳ nằm dưới đồ thị hàm lồi. Chỉ với thay đổi tưởng chừng nhỏ bé ấy, ta giải được gần như mọi bài toán tối ưu lồi không trơn — đổi lại là một hiện tượng thú vị: giá trị hàm mục tiêu không còn giảm đơn điệu sau từng bước, buộc ta phải nhìn vào hình học khoảng cách tới nghiệm tối ưu \(x^*\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tối-ưu-không-trơn-bậc-nhất&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tối ưu không trơn bậc nhất&lt;/h2&gt;

&lt;p&gt;Để hiểu sâu vì sao phương pháp subgradient vừa đơn giản vừa có những giới hạn rất đặc thù, hãy kết nối bốn nhánh kiến thức nền sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Giải tích lồi không trơn (Nonsmooth Convex Analysis):&lt;/strong&gt; Mở rộng khái niệm đạo hàm thành &lt;em&gt;dưới vi phân&lt;/em&gt; (subdifferential) \(\partial f(x)\) — tập tất cả các vector \(g\) sao cho \(f(y) \ge f(x) + g^T(y - x)\) với mọi \(y\). Tại điểm trơn, \(\partial f(x) = \{\nabla f(x)\}\); tại điểm gấp khúc, \(\partial f(x)\) là một tập lồi đóng chứa cả “quạt” các hướng dốc hợp lệ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hình học khoảng cách Euclid và bất đẳng thức năng lượng:&lt;/strong&gt; Khi không còn đảm bảo \(f(x^{(k+1)}) &amp;lt; f(x^{(k)})\), công cụ chứng minh hội tụ chuyển từ việc theo dõi độ giảm của \(f\) sang theo dõi hàm thế năng \(\|x^{(k)} - x^*\|_2^2\). Mỗi bước subgradient có thể tạm làm \(f\) tăng, nhưng vẫn kéo \(x^{(k)}\) lại gần \(x^*\) nếu bước đủ nhỏ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lý thuyết chọn kích thước bước (Step-size Schedules):&lt;/strong&gt; Không thể dùng backtracking line search như gradient descent vì \(-g\) chưa chắc là hướng giảm. Toàn bộ nghệ thuật của chương xoay quanh các quy tắc bước định trước: bước cố định, bước giảm dần thỏa \(\sum t_k = \infty, \sum t_k^2 &amp;lt; \infty\), và bước Polyak khi biết \(f^*\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu ngẫu nhiên và phân tách cấu trúc:&lt;/strong&gt; Khi hàm mục tiêu là tổng của hàng triệu mẫu dữ liệu, subgradient ngẫu nhiên thay tổng lớn bằng một mẫu duy nhất mỗi bước; và khi hàm có phần trơn cộng phần không trơn, tốc độ \(O(1/\epsilon^2)\) của chương này sẽ là động lực trực tiếp dẫn sang phương pháp gradient gần kề ở Chương 09.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-trượt-xuống-đáy-chữ-v-không-trơn-trên-một-ví-dụ-tính-tay&quot;&gt;Giải thích: Trượt xuống đáy chữ V không trơn trên một ví dụ tính tay&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét hàm lồi không khả vi một biến $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 1&lt;/td&gt;
      &lt;td&gt;+ \frac{1}{2}x^2\(. Điểm gấp khúc nằm ngay tại\)x = 1$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện tối ưu bằng dưới vi phân:&lt;/strong&gt;
Với \(x &amp;gt; 1\), \(f&apos;(x) = 1 + x &amp;gt; 2 &amp;gt; 0\). Với \(x &amp;lt; 1\), \(f&apos;(x) = -1 + x &amp;lt; 0\).
Tại điểm gãy \(x = 1\), dưới vi phân của \(|x - 1|\) là đoạn \([-1, 1]\), còn đạo hàm của \(\frac{1}{2}x^2\) là \(1\), nên:
\(\partial f(1) = [-1, 1] + 1 = [0, 2].\)
Vì \(0 \in [0, 2]\), điểm tối ưu duy nhất chính là điểm không khả vi \(x^* = 1\) với giá trị tối ưu \(f^* = |1-1| + \frac{1}{2}(1)^2 = 0.5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chạy hai bước subgradient từ \(x^{(0)} = 2\) với bước cố định \(t = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Bước 1:&lt;/strong&gt; Tại \(x^{(0)} = 2 &amp;gt; 1\), \(g^{(0)} = 1 + 2 = 3\), \(f(2) = 1 + 2 = 3\).
Cập nhật: \(x^{(1)} = 2 - 0.5 \times 3 = 0.5\).
Giá trị mới: \(f(0.5) = |0.5 - 1| + \frac{1}{2}(0.25) = 0.625\) (giảm mạnh từ \(3\) xuống \(0.625\)).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Bước 2:&lt;/strong&gt; Tại \(x^{(1)} = 0.5 &amp;lt; 1\), \(g^{(1)} = -1 + 0.5 = -0.5\).
Cập nhật: \(x^{(2)} = 0.5 - 0.5 \times (-0.5) = 0.75\).
Giá trị mới: \(f(0.75) = 0.25 + 0.28125 = 0.53125\), tiến rất sát \(f^* = 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều rút ra:&lt;/strong&gt; Dù nghiệm \(x^* = 1\) nằm đúng tại đỉnh nhọn không có đạo hàm, vòng lặp \(x^{(k)} = x^{(k-1)} - t_k g^{(k-1)}\) vẫn tiến thẳng về vùng nghiệm mà không cần bất kỳ phép biến đổi trơn hóa nào.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Trong chương này, chúng ta tìm hiểu phương pháp subgradient — thuật toán áp dụng cho các hàm lồi không nhất thiết khả vi, được xây dựng dựa trên khái niệm gradient dưới. Chúng ta cũng sẽ phân tích tính chất hội tụ và tốc độ hội tụ của phương pháp này thông qua các ví dụ cụ thể.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-hiện-đại-20222026&quot;&gt;Ứng dụng hiện đại (2022–2026)&lt;/h2&gt;

&lt;p&gt;Bài đọc tùy chọn đi kèm liên hệ trực tiếp vòng lặp subgradient (bao gồm biến thể có chiếu và ngẫu nhiên) với các ứng dụng như PGD trong huấn luyện đối kháng / RobustBench, bài toán ràng buộc tỷ lệ trong Fairlearn, và huấn luyện mạng ReLU không trơn. Xem &lt;a href=&quot;/contents/vi/chapter08/08_09_modern_applications/&quot;&gt;08-09 Ứng dụng hiện đại của phương pháp subgradient&lt;/a&gt;. Khi hàm mục tiêu dạng tổng hữu hạn &lt;em&gt;thực sự&lt;/em&gt; trơn, giới hạn nhiễu \(O(1/\sqrt{T})\) của phương pháp ngẫu nhiên trong chương này có thể được khắc phục bằng các kỹ thuật giảm phương sai như SVRG / SAGA — xem &lt;a href=&quot;/contents/vi/chapter26/26_05_variance_reduction/&quot;&gt;26-05&lt;/a&gt;, nằm cùng nhóm bài về SGD.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-11 Practical Exercises - Subgradient Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_11_Practical_Exercises_Subgradient_Methods/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_11_Practical_Exercises_Subgradient_Methods</id>
   <content type="html">&lt;p&gt;Reading convergence proofs is only half of learning nonsmooth optimization; the real intuition clicks when you compute a dual subgradient by hand, watch Polyak–Ruppert averaging smooth out stochastic noise, or see mirror descent adapt to the geometry of a probability simplex. These practical exercises bridge textbook theory and real solver design, taking you from basic dual subgradient steps on a linear program all the way to mirror descent and cutting-plane methods.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-advanced-subgradient-variants-in-practice&quot;&gt;Key ideas: Advanced Subgradient Variants in Practice&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Dual Subgradient Ascent:&lt;/strong&gt; Maximizing a concave Lagrange dual \(q(\lambda) = \inf_x (c^\top x + \lambda^\top(Ax - b))\) is equivalent to minimizing \(-q(\lambda)\). By Danskin’s theorem, the constraint residual \(Ax(\lambda) - b\) is a subgradient of \(q(\lambda)\), turning dual ascent into a price-adjustment mechanism.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Polyak–Ruppert Iterate Averaging:&lt;/strong&gt; Instead of returning the noisy final iterate \(x^{(k)}\) or tracking only the single best point, averaging \(\bar{x}^{(k)} = \frac{1}{k}\sum_{i=1}^k x^{(i)}\) exploits Jensen’s inequality (\(f(\bar{x}^{(k)}) \le \frac{1}{k}\sum f(x^{(i)})\)) to stabilize stochastic trajectories and achieve optimal variance constants.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Mirror Descent &amp;amp; Non-Euclidean Geometry:&lt;/strong&gt; Replacing the Euclidean squared distance \(\frac{1}{2}\|x - y\|_2^2\) with a Bregman divergence (such as KL divergence on the simplex) produces multiplicative-weights / exponentiated-gradient updates whose dimension dependence improves from \(O(\sqrt{n})\) to \(O(\sqrt{\log n})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Cutting-Plane &amp;amp; Localization Methods:&lt;/strong&gt; Rather than discarding past subgradients, cutting-plane methods accumulate linear underestimators \(f(y) \ge f(x^{(i)}) + g^{(i)\top}(y - x^{(i)})\) into a polyhedral model that slices the feasible region in half, trading higher per-step cost for faster \(O(n \log(1/\varepsilon))\) convergence in low-to-moderate dimensions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-jensens-inequality-in-action-for-polyakruppert-averaging&quot;&gt;Worked example: Jensen’s Inequality in Action for Polyak–Ruppert Averaging&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider minimizing $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((\)x^\star = 0, f^\star = 0\() where a noisy subgradient loop oscillates around the origin through the four iterates\)x^{(1)} = 0.8,\; x^{(2)} = -0.6,\; x^{(3)} = 0.4,\; x^{(4)} = -0.2$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the individual objective values:&lt;/strong&gt;
\(f(x^{(1)}) = 0.8, \quad f(x^{(2)}) = 0.6, \quad f(x^{(3)}) = 0.4, \quad f(x^{(4)}) = 0.2.\)
The average of the objective values is \(\frac{0.8 + 0.6 + 0.4 + 0.2}{4} = 0.50\), and the best single iterate has \(f_{\text{best}}^{(4)} = 0.20\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the Polyak–Ruppert averaged iterate \(\bar{x}^{(4)}\):&lt;/strong&gt;
\(\bar{x}^{(4)} = \frac{0.8 + (-0.6) + 0.4 + (-0.2)}{4} = \frac{0.4}{4} = 0.10.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate \(f(\bar{x}^{(4)})\) and compare:&lt;/strong&gt;
\(f(\bar{x}^{(4)}) = |0.10| = 0.10 &amp;lt; 0.20 = f_{\text{best}}^{(4)} &amp;lt; 0.50 = \frac{1}{4}\sum_{i=1}^4 f(x^{(i)}).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why it works:&lt;/strong&gt; Opposite-sign oscillations cancel out when you average the &lt;em&gt;iterates&lt;/em&gt; before evaluating \(f\), making \(\bar{x}^{(4)}\) twice as accurate as even the best single point visited! Keep this exact cancellation mechanism in mind as you work through Exercises 1–5 below.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---subgradient-methods&quot;&gt;Practical Exercises - Subgradient Methods&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Boyd et al. (2003) and Nesterov (2009).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-1-dual-subgradient-for-an-lp&quot;&gt;&lt;strong&gt;Exercise 1: Dual Subgradient for an LP&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Given the LP: \(\min c^Tx\) s.t. \(Ax = b\), \(x \geq 0\) with \(c = (1,2)^T\), \(A = [1,1]\), \(b = 3\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Write the dual problem&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Compute a subgradient&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Carry out dual subgradient iterations&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Lagrangian:&lt;/strong&gt; \(L(x,\nu) = c^Tx + \nu(b - Ax)\), so \(g(\nu) = 3\nu + \inf_{x \geq 0}(c - A^T\nu)^Tx\), which is finite when \(A^T\nu \leq c\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Dual:&lt;/strong&gt; \(\max 3\nu\) s.t. \(\nu \leq 1\)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Subgradient:&lt;/strong&gt; \(g&apos;(\nu) = b - Ax^*(\nu) = 3\) (with \(x^*=0\) when \(\nu \le 1\))&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; \(\nu^* = 1\) (the dual value \(3\) equals the primal value at \(x = (3, 0)\))&lt;/p&gt;

  &lt;p&gt;Projected gradient ascent onto \(\nu \leq 1\) with \(\alpha = 0.1\) from \(\nu^{(0)} = 0\) gives \(0.3, 0.6, 0.9, 1\), converging to \(\nu^* = 1\) after 4 steps.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-2-stochastic-subgradient&quot;&gt;&lt;strong&gt;Exercise 2: Stochastic Subgradient&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Given \(\min \frac{1}{n}\sum_i \max(0, 1 - y_i w^T x_i)\) with 3 data points.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Write the stochastic update&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Compare with the batch method&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;The stochastic method picks one random sample per iteration:&lt;/p&gt;

\[w^{(k+1)} = w^{(k)} - \alpha_k g_i\]

  &lt;p&gt;with \(g_i = -y_i x_i\) if the margin is violated (and \(g_i = 0\) otherwise).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Advantage:&lt;/strong&gt; cheaper per iteration, and it keeps making progress when the batch method stalls.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-3-polyak-ruppert-averaging&quot;&gt;&lt;strong&gt;Exercise 3: Polyak-Ruppert Averaging&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Given \(f(x) = \max\{2x, -x+3\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Find \(x^*\)&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Compare \(x^{(k)}\) with the averaged iterate \(\bar{x}^{(k)}\)&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;\(x^* = 1\)&lt;/strong&gt; (the intersection point)&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Averaging:&lt;/strong&gt; \(\bar{x}^{(k)} = \frac{1}{k}\sum_{i=1}^k x^{(i)}\)&lt;/p&gt;

  &lt;p&gt;It smooths out oscillations and converges faster to \(x^*\).&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-4-mirror-descent-on-the-simplex&quot;&gt;&lt;strong&gt;Exercise 4: Mirror Descent on the Simplex&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Given \(f(x) = c^Tx\) on the simplex \(\Delta_3\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Use the entropic mirror map \(\psi(x) = \sum x_i \log x_i\)&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Derive the update rule&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;&lt;/p&gt;

\[x_i^{(k+1)} \propto x_i^{(k)} e^{-\alpha c_i}\]

  &lt;p&gt;Normalize so that \(\sum x_i = 1\).&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;Advantage:&lt;/strong&gt; handles the simplex constraint naturally and is geometry-aware.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercise-5-cutting-plane-method&quot;&gt;&lt;strong&gt;Exercise 5: Cutting Plane Method&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Given \(f(x) = \max\{x^2, (x-2)^2\}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Build cutting planes \(\ell_k(x) = f(x^{(k)}) + g^{(k)}(x - x^{(k)})\)&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Minimize the lower bound \(\hat{f}(x) = \max_k \ell_k(x)\)&lt;/p&gt;

&lt;details&gt;
  &lt;summary&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/summary&gt;

  &lt;p&gt;From \(x^{(0)} = 0\):&lt;/p&gt;

\[\ell_0(x) = 4 - 4x\]

  &lt;p&gt;From \(x^{(1)} = 1\):&lt;/p&gt;

\[\ell_1(x) = 1 + 2(x-1) = 2x - 1\]

  &lt;p&gt;Minimize \(\max\{4-4x, 2x-1\}\) → \(x^{(2)} = \frac{5}{6}\)&lt;/p&gt;

  &lt;p&gt;Iterate until the gap closes.&lt;/p&gt;

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;summary&quot;&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Convergence&lt;/th&gt;
      &lt;th&gt;Best for&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual Subgradient&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;LP, convex programs&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Stochastic&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Large-scale ML&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Averaged&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Reducing oscillations&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mirror Descent&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Constrained domains&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bundle/Cutting&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;Non-smooth, few variables&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Boyd, S., et al. (2003). “Subgradient Methods”. Stanford.&lt;/li&gt;
  &lt;li&gt;Nesterov, Y. (2009). “Primal-dual subgradient methods”.&lt;/li&gt;
  &lt;li&gt;Beck, A., &amp;amp; Teboulle, M. (2003). “Mirror descent”.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>08-10 Multiple-Choice Quiz - Subgradient Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_10_Quiz_Subgradient_Method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_10_Quiz_Subgradient_Method</id>
   <content type="html">&lt;p&gt;Before you test your instincts on the multiple-choice quiz below, pause and think like an optimization theorist debugging a failing training loop. Most misconceptions about subgradient methods stem from unconsciously importing smooth-calculus habits—assuming \(-g\) must go downhill, forgetting that subgradients do not vanish at \(x^\star\), or confusing the \(O(1/\varepsilon^2)\) nonsmooth rate with smooth \(O(1/\varepsilon)\). Use the conceptual map and warm-up calculation below to sharpen your intuition before diving into the questions.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-core-diagnostic-pillars-for-chapter-08-mastery&quot;&gt;Key ideas: Core Diagnostic Pillars for Chapter 08 Mastery&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Non-Descent vs. Distance Contraction:&lt;/strong&gt; Memorize the geometric contrast: \(f(x^{(k)})\) can increase on any single step, so convergence is tracked via \(f_{\text{best}}^{(k)}\), while the Lyapunov proof tracks Euclidean distance \(\|x^{(k)} - x^\star\|_2^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Step-Size Regimes at a Glance:&lt;/strong&gt; Fixed step \(t\) leaves an error floor \(G^2 t / 2\); diminishing steps (\(\sum t_k = \infty, \sum t_k^2 &amp;lt; \infty\)) converge exactly; Polyak’s step \(t_k = \frac{f(x^{(k-1)}) - f^\star}{\|g^{(k-1)}\|_2^2}\) requires knowing \(f^\star\) and needs no tuning.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Projection &amp;amp; Feasibility Unification:&lt;/strong&gt; Projected subgradient preserves the exact \(O(1/\varepsilon^2)\) rate because Euclidean projection \(P_C\) is nonexpansive; minimizing \(\max_i d_{C_i}(x)\) with Polyak’s step size reproduces alternating projections onto the farthest set.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Stochastic vs. Cyclic vs. Batch Trade-offs:&lt;/strong&gt; Batch costs \(O(m)\) per step with zero variance; cyclic suffers \(O(m^3 G^2/\varepsilon^2)\) worst-case updates due to coherent intra-cycle drift; randomized saves a factor of \(m\) to reach \(O(m^2 G^2/\varepsilon^2)\) updates.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-a-quick-4-check-sanity-audit-before-starting-the-quiz&quot;&gt;Worked example: A Quick 4-Check Sanity Audit Before Starting the Quiz&lt;/h3&gt;

&lt;p&gt;Suppose a convex function \(f: \mathbb{R}^n \to \mathbb{R}\) is \(G\)-Lipschitz with \(G = 3\), initial distance \(R = 6\), and known optimal value \(f^\star = 2\). At \(x^{(0)}\), we observe \(f(x^{(0)}) = 11\) and a subgradient \(g^{(0)}\) with \(\|g^{(0)}\|_2 = 3\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check 1 — Optimal fixed step size for \(k = 100\) iterations:&lt;/strong&gt;
\(t^\star = \frac{R}{G\sqrt{k}} = \frac{6}{3\sqrt{100}} = \frac{6}{30} = 0.2.\)
Guaranteed best-iterate gap after 100 steps: \(\frac{RG}{\sqrt{k}} = \frac{6 \cdot 3}{10} = 1.8\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check 2 — Steady-state error floor if we keep \(t = 0.2\) forever:&lt;/strong&gt;
\(\frac{G^2 t}{2} = \frac{9 \cdot 0.2}{2} = 0.9.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check 3 — Polyak step size at \(x^{(0)}\):&lt;/strong&gt;
\(t_1^{\text{Polyak}} = \frac{f(x^{(0)}) - f^\star}{\|g^{(0)}\|_2^2} = \frac{11 - 2}{3^2} = \frac{9}{9} = 1.0.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check 4 — Guaranteed squared-distance reduction from that single Polyak step:&lt;/strong&gt;
\(\|x^{(1)} - x^\star\|_2^2 \le \|x^{(0)} - x^\star\|_2^2 - \frac{(11 - 2)^2}{3^2} = 36 - 9 = 27.\)
If every one of those four numbers feels natural and transparent, you are ready to ace the quiz below!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-the-subgradient-method&quot;&gt;⚡ &lt;strong&gt;The Subgradient Method&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;algorithm-definition&quot;&gt;&lt;strong&gt;Algorithm definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The subgradient method extends gradient descent to non-differentiable convex functions:&lt;/p&gt;

\[x^{(k)} = x^{(k-1)} - t_k \cdot g^{(k-1)}, \quad k = 1, 2, 3, \ldots\]

&lt;p&gt;where \(g^{(k-1)} \in \partial f(x^{(k-1)})\) is a subgradient of \(f\) at \(x^{(k-1)}\)&lt;/p&gt;

&lt;h4 id=&quot;key-differences-from-gradient-descent&quot;&gt;&lt;strong&gt;Key differences from Gradient Descent&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;No guaranteed descent:&lt;/strong&gt; The function value may increase at some steps&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Track the best value:&lt;/strong&gt; \(f(x_{\text{best}}^{(k)}) = \min_{i=0,\ldots,k} f(x^{(i)})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pre-set step sizes:&lt;/strong&gt; Line search cannot be used as in gradient descent&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-choosing-the-step-size&quot;&gt;📏 &lt;strong&gt;Choosing the Step Size&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-fixed-step-size&quot;&gt;&lt;strong&gt;1. Fixed step size&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t_k = t &amp;gt; 0, \quad \forall k\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Simple to implement&lt;/li&gt;
  &lt;li&gt;Converges to a neighborhood of the optimal value&lt;/li&gt;
  &lt;li&gt;Does not reach the exact solution&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-diminishing-step-sizes&quot;&gt;&lt;strong&gt;2. Diminishing step sizes&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Satisfying the conditions:
\(\sum_{k=1}^{\infty} t_k = \infty, \quad \sum_{k=1}^{\infty} t_k^2 &amp;lt; \infty\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(t_k = \frac{1}{k}\) (harmonic series)&lt;/li&gt;
  &lt;li&gt;
\[t_k = \frac{1}{\sqrt{k}}\]
  &lt;/li&gt;
  &lt;li&gt;\(t_k = \frac{a}{b + k}\) with \(a, b &amp;gt; 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Converges exactly to the optimal value (\(f_{\text{best}}^{(k)} \to f^*\))&lt;/li&gt;
  &lt;li&gt;Slower initial convergence than a fixed step size&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-polyak-step-sizes&quot;&gt;&lt;strong&gt;3. Polyak step sizes&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(t_k = \frac{f(x^{(k)}) - f^*}{\lVert g^{(k)} \rVert_2^2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirement:&lt;/strong&gt; The optimal value \(f^*\) must be known
&lt;strong&gt;Advantage:&lt;/strong&gt; Faster convergence when \(f^*\) is known&lt;/p&gt;

&lt;h3 id=&quot;-convergence-analysis&quot;&gt;📊 &lt;strong&gt;Convergence Analysis&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;basic-assumptions&quot;&gt;&lt;strong&gt;Basic assumptions&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(f\) is convex with \(\text{dom}(f) = \mathbb{R}^n\)&lt;/li&gt;
  &lt;li&gt;\(f\) satisfies the Lipschitz condition:
\(|f(x) - f(y)| \le G \lVert x - y \rVert_2, \quad \forall x, y\)&lt;/li&gt;
  &lt;li&gt;Bounded subgradients: \(\lVert g \rVert_2 \le G\) for \(g \in \partial f(x)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;convergence-theorem-for-a-fixed-step-size&quot;&gt;&lt;strong&gt;Convergence theorem for a fixed step size&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lim_{k \to \infty} f(x_{\text{best}}^{(k)}) \le f^* + \frac{G^2 t}{2}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meaning:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Converges to a neighborhood of the optimal value&lt;/li&gt;
  &lt;li&gt;The final error is proportional to the step size \(t\)&lt;/li&gt;
  &lt;li&gt;Trade-off: small \(t\) → small error but slow convergence&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;convergence-theorem-for-diminishing-step-sizes&quot;&gt;&lt;strong&gt;Convergence theorem for diminishing step sizes&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\lim_{k \to \infty} f(x_{\text{best}}^{(k)}) = f^*\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meaning:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Converges exactly to the optimal value (\(f_{\text{best}}^{(k)} \to f^*\))&lt;/li&gt;
  &lt;li&gt;Convergence rate: \(O(1/\sqrt{k})\) (sublinear)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;basic-proof&quot;&gt;&lt;strong&gt;Basic proof&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;From the basic inequality:
\(f_{\text{best}}^{(k)} - f^* \le \frac{R^2 + G^2 \sum_{i=1}^k t_i^2}{2 \sum_{i=1}^k t_i}\)&lt;/p&gt;

&lt;p&gt;with \(R = \lVert x^{(0)} - x^* \rVert_2\)&lt;/p&gt;

&lt;h3 id=&quot;-practical-applications&quot;&gt;🎯 &lt;strong&gt;Practical Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-lasso-regression&quot;&gt;&lt;strong&gt;1. LASSO Regression&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_\beta \frac{1}{2} \lVert y - X\beta \rVert_2^2 + \lambda \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Subgradient:&lt;/strong&gt;
\(\partial f(\beta) = X^T(X\beta - y) + \lambda \partial \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;h4 id=&quot;2-regularized-logistic-regression&quot;&gt;&lt;strong&gt;2. Regularized Logistic Regression&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_\beta \sum_{i=1}^n \left[-y_i x_i^T \beta + \log(1 + \exp(x_i^T \beta))\right] + \lambda \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparison:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ridge (L2):&lt;/strong&gt; Differentiable → Gradient descent&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;LASSO (L1):&lt;/strong&gt; Non-differentiable → Subgradient method&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-support-vector-machine&quot;&gt;&lt;strong&gt;3. Support Vector Machine&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_w \frac{1}{2} \lVert w \rVert_2^2 + C \sum_{i=1}^n \max(0, 1 - y_i w^T x_i)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hinge loss:&lt;/strong&gt; \(\max(0, 1 - z)\) is not differentiable at \(z = 1\)&lt;/p&gt;

&lt;h3 id=&quot;-stochastic-subgradient-method&quot;&gt;🔄 &lt;strong&gt;Stochastic Subgradient Method&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;sum-problem&quot;&gt;&lt;strong&gt;Sum problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x f(x) = \min_x \sum_{i=1}^m f_i(x)\)&lt;/p&gt;

&lt;h4 id=&quot;stochastic-update&quot;&gt;&lt;strong&gt;Stochastic update&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k g_i^{(k-1)}\)&lt;/p&gt;

&lt;p&gt;with \(g_i^{(k-1)} \in \partial f_i(x^{(k-1)})\) and \(i\) chosen at random&lt;/p&gt;

&lt;h4 id=&quot;advantages&quot;&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Computational cost: \(O(1)\) instead of \(O(m)\)&lt;/li&gt;
  &lt;li&gt;Suited to big data&lt;/li&gt;
  &lt;li&gt;Can escape saddle points&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;disadvantages&quot;&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Noisier than the batch method&lt;/li&gt;
  &lt;li&gt;Requires careful learning-rate tuning&lt;/li&gt;
  &lt;li&gt;Slower convergence near the optimum&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-projected-subgradient-method&quot;&gt;📈 &lt;strong&gt;Projected Subgradient Method&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;constrained-problem&quot;&gt;&lt;strong&gt;Constrained problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_{x \in C} f(x)\)&lt;/p&gt;

&lt;p&gt;with \(C\) a closed convex set&lt;/p&gt;

&lt;h4 id=&quot;algorithm&quot;&gt;&lt;strong&gt;Algorithm&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = P_C(x^{(k-1)} - t_k g^{(k-1)})\)&lt;/p&gt;

&lt;p&gt;with \(P_C(\cdot)\) the projection onto \(C\)&lt;/p&gt;

&lt;h4 id=&quot;example-intersection-of-sets&quot;&gt;&lt;strong&gt;Example: Intersection of Sets&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_x \frac{1}{2} \lVert x \rVert_2^2 \quad \text{s.t.} \quad x \in \bigcap_{i=1}^m C_i\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algorithm:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Choose the most violated set \(C_i\)&lt;/li&gt;
  &lt;li&gt;Project onto \(C_i\): \(x^{(k)} = P_{C_i}(x^{(k-1)})\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-comparing-the-methods&quot;&gt;🔄 &lt;strong&gt;Comparing the Methods&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Condition&lt;/th&gt;
      &lt;th&gt;Convergence rate&lt;/th&gt;
      &lt;th&gt;Applications&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Gradient Descent&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Differentiable functions&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\) or linear&lt;/td&gt;
      &lt;td&gt;Smooth optimization&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Subgradient&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Convex functions&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Non-smooth optimization&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;SGD&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Differentiable functions&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Large-scale problems&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Stochastic Subgradient&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Convex functions&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Large-scale non-smooth&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-practical-techniques&quot;&gt;🛠️ &lt;strong&gt;Practical Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;choosing-the-step-size&quot;&gt;&lt;strong&gt;Choosing the step size&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fixed step size:&lt;/strong&gt; Try \(t = 0.01, 0.1, 1\) and pick the best&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diminishing:&lt;/strong&gt; Use \(t_k = \frac{1}{\sqrt{k}}\) or \(t_k = \frac{1}{k}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polyak:&lt;/strong&gt; If \(f^*\) is known, use the Polyak formula&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;monitoring-convergence&quot;&gt;&lt;strong&gt;Monitoring convergence&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Track \(f(x_{\text{best}}^{(k)})\) instead of \(f(x^{(k)})\)&lt;/li&gt;
  &lt;li&gt;Plot the convergence to check it&lt;/li&gt;
  &lt;li&gt;Use a moving average for smoothing&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;debugging&quot;&gt;&lt;strong&gt;Debugging&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Check that the subgradient is correct&lt;/li&gt;
  &lt;li&gt;Verify Lipschitz constant \(G\)&lt;/li&gt;
  &lt;li&gt;Try several step sizes&lt;/li&gt;
  &lt;li&gt;Compare with gradient descent (if the function is differentiable)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-improvements-to-the-subgradient-method&quot;&gt;⚡ &lt;strong&gt;Improvements to the Subgradient Method&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-averaging&quot;&gt;&lt;strong&gt;1. Averaging&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\bar{x}^{(k)} = \frac{1}{k} \sum_{i=1}^k x^{(i)}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Reduces noise, improves the convergence rate&lt;/p&gt;

&lt;h4 id=&quot;2-momentum&quot;&gt;&lt;strong&gt;2. Momentum&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = x^{(k-1)} - t_k g^{(k-1)} + \beta(x^{(k-1)} - x^{(k-2)})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Accelerates convergence, reduces oscillation&lt;/p&gt;

&lt;h4 id=&quot;3-adaptive-step-sizes&quot;&gt;&lt;strong&gt;3. Adaptive step sizes&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;AdaGrad for subgradients&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;RMSprop variants&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adam-like methods&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-illustrative-examples&quot;&gt;🎯 &lt;strong&gt;Illustrative Examples&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;problem-min_x-x---2--x--1&quot;&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(\min_x |x - 2| + |x + 1|\)&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Compute a subgradient
\(\partial f(x) = \partial |x - 2| + \partial |x + 1|\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Subgradient method with \(t_k = 0.1\)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Start from \(x^{(0)} = 5\)&lt;/li&gt;
  &lt;li&gt;
\[g^{(0)} = 1 + 1 = 2\]
  &lt;/li&gt;
  &lt;li&gt;
\[x^{(1)} = 5 - 0.1 \times 2 = 4.8\]
  &lt;/li&gt;
  &lt;li&gt;Continue until convergence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; Converges to \(x^* \in [-1, 2]\)&lt;/p&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;when-to-use-the-subgradient-method&quot;&gt;&lt;strong&gt;When to use the Subgradient Method:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Non-differentiable objectives (containing \(\lvert \cdot \rvert\), \(\max\{\cdot\}\))&lt;/li&gt;
  &lt;li&gt;Regularization with the L1 norm&lt;/li&gt;
  &lt;li&gt;Constrained optimization with indicator functions&lt;/li&gt;
  &lt;li&gt;Large-scale problems with stochastic variants&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;when-not-to-use-it&quot;&gt;&lt;strong&gt;When NOT to use it:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Differentiable functions (use gradient descent)&lt;/li&gt;
  &lt;li&gt;When fast convergence is needed (use Newton methods)&lt;/li&gt;
  &lt;li&gt;Non-convex functions (no global optimum guarantee)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;best-practices&quot;&gt;&lt;strong&gt;Best practices:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Always track \(f_{\text{best}}^{(k)}\)&lt;/li&gt;
  &lt;li&gt;Try several step-size strategies&lt;/li&gt;
  &lt;li&gt;Use averaging to reduce noise&lt;/li&gt;
  &lt;li&gt;Combine with projection for constrained problems&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; The subgradient method is a powerful tool for non-smooth optimization, especially important in machine learning with regularization and in robust optimization!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the subgradient method, step-size choice, convergence analysis, the projected subgradient method and the stochastic subgradient method.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🔄 Quiz: The Subgradient Method&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: The update formula of the subgradient method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(x^{(k)} = x^{(k-1)} + t_k \cdot g^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(x^{(k)} = x^{(k-1)} - t_k \cdot g^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(x^{(k)} = x^{(k-1)} - t_k \cdot \nabla f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(x^{(k)} = x^{(k-1)} - g^{(k-1)}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$x^{(k)} = x^{(k-1)} - t_k \cdot g^{(k-1)}$$&lt;/strong&gt;&lt;br /&gt;
                The subgradient method replaces the gradient with a subgradient $$g^{(k-1)} \in \partial f(x^{(k-1)})$$ with step size $$t_k$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: Unlike gradient descent, the subgradient method:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) Always decreases the function value at every step&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) Does not always guarantee a decrease of the function value at every step&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Only applies to differentiable functions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) Converges faster than gradient descent&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Does not always guarantee a decrease of the function value at every step&lt;/strong&gt;&lt;br /&gt;
                That is why this method is not called subgradient &quot;descent&quot;, and we need to track the best value $$f(x_{best}^{(k)})$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: In the subgradient method, \(f(x_{best}^{(k)})\) is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(f(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(\min_{i=0,...,k} f(x^{(i)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \(\max_{i=0,...,k} f(x^{(i)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \(\frac{1}{k+1} \sum_{i=0}^k f(x^{(i)})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\min_{i=0,...,k} f(x^{(i)})$$&lt;/strong&gt;&lt;br /&gt;
                This is the smallest value of $$f$$ obtained over $$k$$ iterations of the subgradient method.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: With a fixed step size \(t_k = t\), the subgradient method:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) Converges to the exact optimal solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) Converges to a neighborhood of the optimal value&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) Does not converge&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) Converges only for differentiable functions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Converges to a neighborhood of the optimal value&lt;/strong&gt;&lt;br /&gt;
                With a fixed step size the algorithm does not converge exactly: $$\lim_{k\to\infty} f(x_{best}^{(k)}) \leq f^* + \frac{G^2 t}{2}$$, i.e. it only gets within a neighborhood of the optimal value proportional to $$t$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: A condition on diminishing step sizes that guarantees convergence is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(\sum_{k=1}^{\infty} t_k &amp;lt; \infty\) and \(\sum_{k=1}^{\infty} t_k^2 &amp;lt; \infty\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(\sum_{k=1}^{\infty} t_k = \infty\) and \(\sum_{k=1}^{\infty} t_k^2 &amp;lt; \infty\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(\sum_{k=1}^{\infty} t_k = \infty\) and \(\sum_{k=1}^{\infty} t_k^2 = \infty\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \(t_k = \text{constant}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\sum_{k=1}^{\infty} t_k = \infty$$ and $$\sum_{k=1}^{\infty} t_k^2 &amp;lt; \infty$$&lt;/strong&gt;&lt;br /&gt;
                The Robbins-Monro condition: an infinite sum guarantees progress, a finite sum of squares controls the noise.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: The step size \(t_k = \frac{1}{k}\) satisfies the convergence condition because:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(\sum_{k=1}^{\infty} \frac{1}{k} = \infty\) (harmonic series) and \(\sum_{k=1}^{\infty} \frac{1}{k^2} &amp;lt; \infty\) (Basel problem)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) Both sums are finite&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) Both sums are infinite&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) It does not satisfy the condition&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\sum_{k=1}^{\infty} \frac{1}{k} = \infty$$ (harmonic series) and $$\sum_{k=1}^{\infty} \frac{1}{k^2} &amp;lt; \infty$$ (Basel problem)&lt;/strong&gt;&lt;br /&gt;
                This is the classic example of a step size satisfying the Robbins-Monro condition.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: The convergence rate of the subgradient method with diminishing step sizes is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) \(O(1/\sqrt{k})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) \(O(e^{-k})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) $$O(1/\sqrt{k})$$&lt;/strong&gt;&lt;br /&gt;
                The subgradient method converges at the rate $$O(1/\sqrt{k})$$, slower than gradient descent&apos;s $$O(1/k)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: The basic inequality in the analysis of the subgradient method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) \(\|x^{(k)} - x^*\|^2 \leq \|x^{(k-1)} - x^*\|^2 - 2t_k(f(x^{(k-1)}) - f^*) + t_k^2\|g^{(k-1)}\|^2\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) \(\|x^{(k)} - x^*\|^2 \geq \|x^{(k-1)} - x^*\|^2\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) \(f(x^{(k)}) \leq f(x^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) \(\|g^{(k)}\| \leq \|g^{(k-1)}\|\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\|x^{(k)} - x^*\|^2 \leq \|x^{(k-1)} - x^*\|^2 - 2t_k(f(x^{(k-1)}) - f^*) + t_k^2\|g^{(k-1)}\|^2$$&lt;/strong&gt;&lt;br /&gt;
                This is the basic inequality used in the convergence analysis, balancing progress against noise.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The Polyak step size is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(t_k = \frac{1}{k}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(t_k = \frac{f(x^{(k-1)}) - f^*}{\|g^{(k-1)}\|^2}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(t_k = \text{constant}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(t_k = \frac{1}{\|g^{(k-1)}\|}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$t_k = \frac{f(x^{(k-1)}) - f^*}{\|g^{(k-1)}\|^2}$$&lt;/strong&gt;&lt;br /&gt;
                The Polyak step size requires knowing the optimal value $$f^*$$ and usually performs well in practice.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: The projected subgradient method for the constrained problem \(\min_{x \in C} f(x)\) has the formula:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(x^{(k)} = x^{(k-1)} - t_k g^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(x^{(k)} = P_C(x^{(k-1)} - t_k g^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(x^{(k)} = x^{(k-1)} - t_k P_C(g^{(k-1)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(x^{(k)} = P_C(x^{(k-1)})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$x^{(k)} = P_C(x^{(k-1)} - t_k g^{(k-1)})$$&lt;/strong&gt;&lt;br /&gt;
                The projected subgradient method takes a subgradient step and then projects the result onto the constraint set $$C$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: The stochastic subgradient method for the problem \(\min \sum_{i=1}^m f_i(x)\) has the formula:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) \(x^{(k)} = x^{(k-1)} - t_k \sum_{i=1}^m g_i^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) \(x^{(k)} = x^{(k-1)} - t_k g_{i_k}^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) \(x^{(k)} = x^{(k-1)} - t_k \frac{1}{m} \sum_{i=1}^m g_i^{(k-1)}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) \(x^{(k)} = x^{(k-1)} - g_{i_k}^{(k-1)}\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$x^{(k)} = x^{(k-1)} - t_k g_{i_k}^{(k-1)}$$&lt;/strong&gt;&lt;br /&gt;
                The stochastic version only uses the subgradient of one function $$f_{i_k}$$ chosen at each iteration.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The main advantage of the stochastic subgradient method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Faster convergence than the batch method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Lower computational cost per iteration&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) It always decreases the function value&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) No step size is needed&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Lower computational cost per iteration&lt;/strong&gt;&lt;br /&gt;
                The stochastic method only needs the subgradient of one function instead of the whole sum, greatly reducing the computational cost.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: Compared with gradient descent, the subgradient method:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Converges faster&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Converges more slowly&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Has the same convergence rate&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Does not converge&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Converges more slowly&lt;/strong&gt;&lt;br /&gt;
                The subgradient method has rate $$O(1/\sqrt{k})$$ compared with $$O(1/k)$$ for gradient descent, but it applies to non-differentiable functions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: The subgradient method is used when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) The objective is differentiable everywhere&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) The objective is convex but possibly non-differentiable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) The objective is non-convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Only for unconstrained problems&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The objective is convex but possibly non-differentiable&lt;/strong&gt;&lt;br /&gt;
                The subgradient method is designed specifically for non-differentiable convex functions such as the L1 norm and max functions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: Unlike gradient descent, the step size in the subgradient method:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) Can use backtracking line search&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) Must be set in advance, not adaptively&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) Is always equal to 1&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Is automatically optimal&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Must be set in advance, not adaptively&lt;/strong&gt;&lt;br /&gt;
                The subgradient method cannot use line search because the direction is not guaranteed to be a descent direction.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: In the convergence analysis, the subgradients are usually assumed to be bounded:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(\|g^{(k)}\| \leq G\) with \(G &amp;gt; 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(\|g^{(k)}\| = 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(\|g^{(k)}\| \to 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(\|g^{(k)}\|\) is unbounded&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\|g^{(k)}\| \leq G$$ with $$G &amp;gt; 0$$&lt;/strong&gt;&lt;br /&gt;
                The bounded-subgradient assumption is needed to guarantee convergence and to estimate the convergence rate.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: To find a point in the intersection of convex sets \(C_1 \cap C_2 \cap ... \cap C_m\), we can use:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) The subgradient method on $$f(x) = \max_i d_{C_i}(x)$$ (which leads to alternating projections)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Newton method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) It cannot be solved&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The subgradient method on $$f(x) = \max_i d_{C_i}(x)$$ (which leads to alternating projections)&lt;/strong&gt;&lt;br /&gt;
                Minimize $$f(x) = \max_i d_{C_i}(x)$$ (with $$f^* = 0$$ when the intersection is nonempty). The subgradient of $$d_{C_i}$$ is $$(x - P_{C_i}(x))/d_{C_i}(x)$$; with the Polyak step size, each step projects $$x$$ onto the farthest set, i.e. the alternating projections algorithm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: The subgradient method is well suited to regularized problems such as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) \(\min f(x) + \lambda \|x\|_2^2\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) \(\min f(x) + \lambda \|x\|_1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) \(\min f(x) + \lambda x^T x\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) All of the above cases&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\min f(x) + \lambda \|x\|_1$$&lt;/strong&gt;&lt;br /&gt;
                L1 regularization makes the function non-differentiable, which suits the subgradient method. L2 regularization remains differentiable.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: In the stochastic subgradient method, the choice of the index \(i_k\):&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Must be completely random&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Can be cyclic or random&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Must be in increasing order&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Does not affect convergence&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Can be cyclic or random&lt;/strong&gt;&lt;br /&gt;
                Both cyclic and random choices can guarantee convergence under suitable conditions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20: Practical considerations --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: In practice, to improve the performance of the subgradient method, we can:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Average the iterates&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Combine it with momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Use adaptive step sizes&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above methods&lt;/strong&gt;&lt;br /&gt;
                Averaging, momentum and adaptive step sizes are all techniques used to improve the subgradient method.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: The subgradient method has convergence rate:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$O(1/k)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$O(1/\sqrt{k})$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$O(1/k^2)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Linear&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$O(1/\sqrt{k})$$&lt;/strong&gt;&lt;br /&gt;
                The subgradient method has convergence rate $$O(1/\sqrt{k})$$ for non-smooth convex functions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: The step size in the subgradient method is usually chosen:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Fixed and small&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Diminishing like $$1/\sqrt{k}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) Increasing&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Random&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Diminishing like $$1/\sqrt{k}$$&lt;/strong&gt;&lt;br /&gt;
                The step size is usually chosen as $$t_k = \frac{c}{\sqrt{k}}$$ to guarantee convergence.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: For $$f(x) = |x|$$, starting from $$x_0 = 2$$, one subgradient step with $$t = 0.5$$ gives:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$x_1 = 1.5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$x_1 = 2.5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$x_1 = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$x_1 = 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$x_1 = 1.5$$&lt;/strong&gt;&lt;br /&gt;
                At $$x_0 = 2$$: the subgradient is $$g = 1$$. $$x_1 = 2 - 0.5 \cdot 1 = 1.5$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The subgradient method differs from gradient descent in that it:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) Does not require a differentiable function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) Converges more slowly&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) Can oscillate&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) All of the above&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above&lt;/strong&gt;&lt;br /&gt;
                The subgradient method applies to non-smooth functions, converges more slowly and can oscillate around the solution.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: The stopping criterion of the subgradient method is usually based on:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$\|g_k\| &amp;lt; \epsilon$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) The maximum number of iterations&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) The objective value&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) B and C&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) B and C&lt;/strong&gt;&lt;br /&gt;
                Since a subgradient need not be 0 at the solution, the number of iterations or the function value is usually used to stop.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;b&apos;,
    q6: &apos;a&apos;, q7: &apos;c&apos;, q8: &apos;a&apos;, q9: &apos;b&apos;, q10: &apos;b&apos;,
    q11: &apos;b&apos;, q12: &apos;b&apos;, q13: &apos;b&apos;, q14: &apos;b&apos;, q15: &apos;b&apos;,
    q16: &apos;a&apos;, q17: &apos;b&apos;, q18: &apos;b&apos;, q19: &apos;b&apos;, q20: &apos;d&apos;
,
    q21: &apos;b&apos;, q22: &apos;b&apos;, q23: &apos;a&apos;, q24: &apos;d&apos;, q25: &apos;d&apos;};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered the subgradient method!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand the algorithm and its convergence analysis quite well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review the step-size choices and stochastic methods.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review the basic concepts of subgradients.&apos;;
    } else {
        message = &apos;📖 Study the subgradient method again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>08-03 Improving on the Subgradient Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_03_improving_on_the_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_03_improving_on_the_subgradient_method</id>
   <content type="html">&lt;p&gt;At first glance, the \(O(1/\varepsilon^2)\) convergence rate of the subgradient method sounds like bad news: needing one million iterations for three digits of accuracy feels painfully slow compared to the \(O(1/\varepsilon)\) rate of smooth gradient descent (and \(O(1/\sqrt{\varepsilon})\) with Nesterov acceleration). Yet Nemirovski and Yudin proved that &lt;em&gt;no&lt;/em&gt; general black-box subgradient method can beat \(O(1/\varepsilon^2)\)! So how do we break the barrier? Not by inventing a cleverer black-box step size, but by &lt;strong&gt;opening the black box&lt;/strong&gt;—separating the smooth, differentiable physics of the problem from its simple nonsmooth geometry.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-breaking-the-o1varepsilon2-barrier&quot;&gt;Key ideas: Breaking the \(O(1/\varepsilon^2)\) Barrier&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The Black-Box Lower Bound:&lt;/strong&gt; Treating \(f(x)\) as an opaque oracle that only returns \((f(x), g)\) forces a worst-case rate of \(\Omega(1/\varepsilon^2)\). Speedups are mathematically impossible unless the algorithm exploits additional structure in \(f\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Composite Splitting (\(f = g + h\)):&lt;/strong&gt; Almost every nonsmooth problem in statistics and machine learning—Lasso, elastic net, nuclear-norm matrix completion, constrained regression—splits naturally into a smooth \(L\)-Lipschitz-gradient loss \(g(x)\) plus a simple nonsmooth regularizer or indicator \(h(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Proximal Gradient Descent (Chapter 09 Preview):&lt;/strong&gt; Instead of linearizing the nonsmooth part \(h\) with a subgradient, proximal gradient linearizes &lt;em&gt;only&lt;/em&gt; \(g\) and solves the exact regularized subproblem \(\operatorname{prox}_{t h}(x - t \nabla g(x))\), immediately recovering the smooth \(O(1/\varepsilon)\) rate!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Smoothing &amp;amp; Mirror/Bundle Alternatives:&lt;/strong&gt; When \(h\) lacks a cheap proximal operator, alternative escape routes include Nesterov smoothing (approximating a max-function by log-sum-exp to achieve \(O(1/\varepsilon)\)) and cutting-plane / bundle methods (storing past subgradients to build a piecewise-linear lower model of \(f\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-iteration-count-comparison-across-three-speed-limits&quot;&gt;Worked example: Iteration-Count Comparison Across Three Speed Limits&lt;/h3&gt;

&lt;p&gt;Suppose a convex problem has scale constants normalized to \(1\), and we want suboptimality \(\varepsilon = 10^{-4}\) (four digits of accuracy).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Black-box subgradient method (\(O(1/\varepsilon^2)\)):&lt;/strong&gt;
\(K_{\text{subgrad}} \approx \frac{1}{(10^{-4})^2} = 10^8 = 100{,}000{,}000 \text{ iterations}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Proximal gradient descent on \(g + h\) (\(O(1/\varepsilon)\)):&lt;/strong&gt;
\(K_{\text{prox}} \approx \frac{1}{10^{-4}} = 10^4 = 10{,}000 \text{ iterations}\)
—a &lt;strong&gt;\(10{,}000\times\) speedup&lt;/strong&gt; purely from handling \(h\) via its proximal operator instead of a subgradient!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Accelerated proximal gradient / FISTA (\(O(1/\sqrt{\varepsilon})\)):&lt;/strong&gt;
\(K_{\text{FISTA}} \approx \frac{1}{\sqrt{10^{-4}}} = 10^2 = 100 \text{ iterations}\)
—a &lt;strong&gt;\(1{,}000{,}000\times\) speedup&lt;/strong&gt; over plain subgradient!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; This six-order-of-magnitude gap explains the entire arc from Chapter 08 to Chapter 09: use subgradient methods when \(f\) is genuinely unstructured or you only need coarse accuracy (\(\varepsilon \sim 10^{-2}\)), and switch to proximal/accelerated methods the moment \(f\) splits into \(g + h\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The subgradient method is advantageous because it can be used for nondifferentiable convex functions, making it more general. However, its convergence rate is \(O(1/\epsilon^{2})\), which is much slower than the convergence rate of gradient descent, \(O(1/\epsilon)\).&lt;/p&gt;

&lt;p&gt;Is there a way to combine the strengths of gradient descent and the subgradient method? In the next section, we will learn about the proximal gradient descent method, which combines the advantages of both algorithms.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02 Stochastic Subgradient Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_02_stochastic_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_02_stochastic_subgradient_method</id>
   <content type="html">&lt;p&gt;When your objective is a sum over ten million training examples—as in large-scale support vector machines or empirical risk minimization—computing a single full subgradient requires reading the entire dataset before taking even one tiny step. The &lt;strong&gt;stochastic subgradient method&lt;/strong&gt; breaks this bottleneck by replacing the full sum of subgradients with a single randomly (or cyclically) sampled component subgradient. You trade a clean deterministic step for a noisy, cheap step—and in massive-scale machine learning, that trade-off is almost always a decisive win.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-deterministic-to-stochastic-subgradients&quot;&gt;Key ideas: From Deterministic to Stochastic Subgradients&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Finite-Sum Optimization Structure:&lt;/strong&gt; Modern statistical learning minimizes \(f(x) = \sum_{i=1}^m f_i(x)\) (or \(\frac{1}{m}\sum_{i=1}^m f_i(x)\)), where each \(f_i\) is a convex, possibly nonsmooth loss (such as hinge loss or absolute error) on a single datum.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Unbiased Stochastic Oracles:&lt;/strong&gt; Drawing an index \(i_k \in \{1, \dots, m\}\) uniformly at random and returning \(g_{i_k} \in \partial f_{i_k}(x)\) satisfies \(\mathbb{E}[m \, g_{i_k} \mid x] \in \partial f(x)\). Even though \(g_{i_k}\) may point far from the full subgradient, its conditional expectation is an exact subgradient of the full objective.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Cost-Per-Step vs. Variance Trade-off:&lt;/strong&gt; Each stochastic iteration is \(m\times\) cheaper than a batch subgradient step, allowing rapid early progress when iterates are far from \(x^\star$. Near\)x^\star$$, however, gradient noise across components persists even at the exact optimum, requiring diminishing step sizes to converge.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Cyclic vs. Randomized Sampling:&lt;/strong&gt; Practitioners either cycle deterministically through \(i = 1, \dots, m\) (cyclic/incremental subgradient) or sample randomly (stochastic subgradient). Randomization avoids adversarial ordering effects and yields tighter expected convergence rates in \(m\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-comparing-full-vs-stochastic-subgradient-on-a-2-term-sum&quot;&gt;Worked example: Comparing Full vs. Stochastic Subgradient on a 2-Term Sum&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize $$f(x) = f_1(x) + f_2(x) =&lt;/td&gt;
      &lt;td&gt;x - 2&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x + 2&lt;/td&gt;
      &lt;td&gt;\((optimal set is\)x^\star \in [-2, 2]\(with\)f^\star = 4\() starting from\)x^{(0)} = 4\(with step size\)t = 1$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Full (batch) subgradient at \(x^{(0)} = 4\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;\(g_1(4) = +1\) (from $$&lt;/td&gt;
              &lt;td&gt;x - 2&lt;/td&gt;
              &lt;td&gt;\() and\)g_2(4) = +1\((from\)&lt;/td&gt;
              &lt;td&gt;x + 2&lt;/td&gt;
              &lt;td&gt;$$).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Full subgradient: \(g(4) = 1 + 1 = 2\) (requires evaluating &lt;em&gt;both&lt;/em&gt; terms).&lt;/li&gt;
      &lt;li&gt;Batch step: \(x^{(1)}_{\text{batch}} = 4 - 1 \cdot 2 = 2\), reaching the optimal set immediately at cost \(2\) evaluations.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic subgradient at \(x^{(0)} = 4\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Sample \(i_1 \in \{1, 2\}\) uniformly; either way \(g_{i_1}(4) = +1\) (cost: \(1\) evaluation).&lt;/li&gt;
      &lt;li&gt;Update: \(x^{(1)}_{\text{stoch}} = 4 - 1 \cdot 1 = 3\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Observe what happens inside the optimal set at \(x = 0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Full subgradient: \(g_1(0) + g_2(0) = -1 + 1 = 0\) (batch method stops completely!).&lt;/li&gt;
      &lt;li&gt;Stochastic subgradient: \(g_1(0) = -1\) with probability \(1/2\) and \(g_2(0) = +1\) with probability \(1/2\). Notice \(\mathbb{E}[g_{i}(0)] = 0\) (unbiased!), yet \(\mathbb{E}[\|g_i(0)\|^2] = 1 &amp;gt; 0\)—showing visually why stochastic methods bounce around \(x^\star\) unless \(t_k \to 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The stochastic subgradient method is similar to stochastic gradient descent, but replaces the gradient with a subgradient.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02-04 Batch vs Stochastic Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_02_04_batch_vs_stochastic_methods/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_02_04_batch_vs_stochastic_methods</id>
   <content type="html">&lt;p&gt;If you plot the objective value of batch versus stochastic subgradient on a real logistic regression problem, you immediately see a classic crossing-curves story: in the first few passes over the data, the stochastic curve plummets while the batch curve barely budges; later on, the stochastic curve flattens into a noisy jitter floor while the batch curve steadily grinds past it to higher accuracy. Understanding &lt;em&gt;why&lt;/em&gt; those two curves cross is the key to choosing the right method—and to designing hybrid schedules like mini-batching or increasing batch sizes.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-two-regimes-of-batch-vs-stochastic-optimization&quot;&gt;Key ideas: The Two Regimes of Batch vs. Stochastic Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Early Transient Regime (Signal Dominates Noise):&lt;/strong&gt; Far from \(x^\star\), almost all data points agree on the rough direction toward the optimum. Paying \(m\) evaluations to average \(m\) nearly identical subgradients is wasteful; taking \(m\) cheap stochastic steps makes dramatically faster progress per pass over the data.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Asymptotic Accuracy Regime (Noise Dominates Signal):&lt;/strong&gt; Near \(x^\star\), individual component subgradients cancel each other out (\(\sum g_i \approx 0\)) while each individual \(\|g_i\|\) remains large. Batch averaging eliminates this variance cleanly, whereas a stochastic method must shrink \(t_k \to 0\) to suppress it, slowing convergence.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Mini-Batching as a Continuous Dial:&lt;/strong&gt; Averaging \(b\) sampled subgradients (\(1 \le b \le m\)) reduces step variance by a factor of \(b\) while keeping iteration cost \(m/b\) times smaller than full batch—and maps cleanly onto vectorized GPU/SIMD hardware.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Practical Hybrid Strategy:&lt;/strong&gt; Start with small batches (or pure stochastic steps) to burn through the initial distance \(R\) in a handful of epochs, then increase batch size or anneal the step size once the objective enters the noise floor.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-the-exact-crossover-point-between-batch-and-stochastic-progress&quot;&gt;Worked example: Computing the Exact Crossover Point Between Batch and Stochastic Progress&lt;/h3&gt;

&lt;p&gt;Suppose we minimize \(\frac{1}{m}\sum_{i=1}^m f_i(x)\) with \(m = 1{,}000\) samples, \(R = 10\), \(G = 1\), and measure computational cost in &lt;strong&gt;epochs&lt;/strong&gt; (1 epoch = \(1{,}000\) component subgradient evaluations).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Batch subgradient cost for accuracy \(\varepsilon\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Each batch iteration costs \(1\) full epoch.&lt;/li&gt;
      &lt;li&gt;Using the standard bound \(\varepsilon \approx \frac{RG}{\sqrt{K_{\text{batch}}}}\), reaching \(\varepsilon = 0.5\) requires:
\(K_{\text{batch}} = \left(\frac{10 \cdot 1}{0.5}\right)^2 = 400 \text{ epochs}.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic subgradient cost for the same accuracy \(\varepsilon = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Each epoch performs \(m = 1{,}000\) updates, so \(E\) epochs correspond to \(K_{\text{stoch}} = 1{,}000 E\) updates.&lt;/li&gt;
      &lt;li&gt;Using the normalized randomized bound \(\varepsilon \approx \frac{RG}{\sqrt{K_{\text{stoch}}}}\), reaching \(\varepsilon = 0.5\) requires:
\(K_{\text{stoch}} = 400 \text{ updates} = \frac{400}{1{,}000} = 0.4 \text{ epochs}!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Now compare at high precision when the smooth/batch method exploits extra structure (or variance reduction) vs. fixed-step stochastic:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;If the stochastic step size is kept fixed at \(t = 0.05\) (noise floor \(\approx G^2 t / 2 = 0.025\)), then for \(\varepsilon = 0.5\) stochastic wins by \(1{,}000\times\) in epochs, whereas for \(\varepsilon = 0.001\) the fixed-step stochastic method &lt;em&gt;never&lt;/em&gt; reaches the target while batch (or diminishing-step) keeps descending. This exact tension motivates variance-reduced and adaptive batch-size methods in modern ML.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The convergence properties of batch and stochastic methods are as follows:&lt;/p&gt;

&lt;p&gt;Generally, the stochastic method quickly approaches the optimal point in the early stages, but may not converge as well near the optimal point. In contrast, the batch method converges more slowly but approaches the optimal point more accurately.&lt;/p&gt;

&lt;p&gt;The figure below compares the convergence of batch and stochastic methods for &lt;a href=&quot;https://en.wikipedia.org/wiki/Logistic_regression&quot;&gt;logistic regression&lt;/a&gt; (without regularization):&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter08/08_02_stochastic_vs_batch.png&quot; alt=&quot;stochastic_vs_batch&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 3] Batch vs Stochastic Gradient Descent [2]&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;When each \(f_i\) is smooth, the leftover jitter of the stochastic curve near the optimum is exactly the noise floor that &lt;a href=&quot;/contents/en/chapter26/26_05_variance_reduction/&quot;&gt;26-05 SVRG and SAGA&lt;/a&gt; removes — without paying a full-batch gradient at every step.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02-03 Convergence Rate of Stochastic Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_02_03_convergence_rate_of_stochastic_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_02_03_convergence_rate_of_stochastic_method</id>
   <content type="html">&lt;p&gt;A subtle and famous surprise awaits anyone who compares cyclic versus randomized stochastic subgradient methods in terms of \(m\) (the number of data points): while both share the same \(O(1/\varepsilon^2)\) dependence on accuracy \(\varepsilon\), the randomized method saves a full factor of \(m\) in worst-case complexity over the cyclic method! That extra factor of \(m\) is not a mere proof artifact—adversarial data orderings genuinely slow cyclic updates down by a factor of \(m\), whereas random shuffling cancels out correlated errors by the law of large numbers.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-complexity-scaling-in-m-g-and-varepsilon&quot;&gt;Key ideas: Complexity Scaling in \(m\), \(G\), and \(\varepsilon\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Batch Subgradient Benchmark:&lt;/strong&gt; Using \(G_{\text{batch}} \le mG\), the batch method takes \(O(G_{\text{batch}}^2 / \varepsilon^2) \le O(m^2 G^2 / \varepsilon^2)\) batch iterations. Because each batch iteration evaluates all \(m\) components, total component evaluations scale as \(O(m^3 G^2 / \varepsilon^2)\) in the worst case.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Cyclic Method Complexity (\(O(m^3 G^2 / \varepsilon^2)\) updates):&lt;/strong&gt; An adversarial ordering (e.g., putting all \(+1\) subgradients first and all \(-1\) subgradients last) creates \(O(m)\) coherent drift within each cycle. Counting individual steps gives \(O(m^3 G^2 / \varepsilon^2)\), or \(O(m^2 G^2 / \varepsilon^2)\) full cycles—matching the worst-case batch evaluation count.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Randomized Method Complexity (\(O(m^2 G^2 / \varepsilon^2)\) updates):&lt;/strong&gt; Because independent random draws have zero cross-term covariance, the expected squared norm of the step noise does not accumulate coherently across \(m\) steps, saving a full factor of \(m\) in component evaluations (equivalent to \(O(m G^2 / \varepsilon^2)\) passes over the data).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Normalized Average Objective (\(\frac{1}{m}\sum f_i\)):&lt;/strong&gt; Dividing the objective by \(m\) rescales \(\varepsilon \mapsto m\varepsilon\), turning the randomized complexity into \(O(G^2 / \varepsilon^2)\) component evaluations—completely &lt;em&gt;independent of the dataset size \(m\)&lt;/em&gt;!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why-adversarial-ordering-hurts-cyclic-updates&quot;&gt;Worked example: Why Adversarial Ordering Hurts Cyclic Updates&lt;/h3&gt;

&lt;p&gt;Consider \(f(x) = \sum_{i=1}^{2k} f_i(x)\) with \(m = 2k\) terms where the first \(k\) terms are \(f_i(x) = +x\) and the last \(k\) terms are \(f_i(x) = -x\) (so \(f(x) \equiv 0\) and every \(x\) is optimal, with \(G = 1\)). Start at \(x^{(0)} = 0\) with step size \(t\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cyclic ordering (all \(+x\) first, then all \(-x\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;After the first \(k = m/2\) steps, every subgradient is \(+1\), so \(x^{(k)} = 0 - k t = -\frac{m}{2} t\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;The peak displacement from \(x^{(0)}\) is $$\left&lt;/td&gt;
              &lt;td&gt;x^{(k)} - x^{(0)}\right&lt;/td&gt;
              &lt;td&gt;= \frac{m}{2} t\(, and the squared displacement scales as\)\Theta(m^2 t^2)$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Over the remaining \(k\) steps, all subgradients are \(-1\), returning to \(x^{(2k)} = 0\), but the huge intermediate drift \(\Theta(m t)\) injects \(\Theta(m^2 G^2 t)\) bias whenever \(f_i\) is nonlinear.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Randomized ordering (\(i_j\) uniform in \(\{1, \dots, 2k\}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Each step adds \(\pm t\) independently with probability \(1/2\) (a 1D symmetric random walk).&lt;/li&gt;
      &lt;li&gt;After \(k = m/2\) steps, the expected squared displacement is only \(\mathbb{E}[(x^{(k)} - x^{(0)})^2] = k t^2 = \frac{m}{2} t^2\)—smaller by a full factor of \(m/2\)!&lt;/li&gt;
      &lt;li&gt;Typical drift is \(O(\sqrt{m}\, t)\) instead of \(O(m\, t)\), directly illustrating where the \(m\times\) speedup of randomized stochastic subgradient comes from.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are differences in the convergence rates between cyclic and randomized methods.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;/contents/en/chapter08/08_01_04_convergence_rate/&quot;&gt;convergence rate&lt;/a&gt; of the batch subgradient method is \(O(G_{batch}^{2}/\epsilon^{2})\), where \(G_{batch}\) is the Lipschitz constant of \(\sum f_i\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Cyclic method&lt;/strong&gt;: The iteration complexity of the cyclic method is \(O(m^{3}G^{2}/\epsilon^{2})\). If one cycle of the cyclic stochastic subgradient method is considered equivalent to one batch subgradient method, then each cycle requires \(O(m^{2}G^{2}/\epsilon^{2})\) iterations. (\(G\) is the Lipschitz constant of a single function \(f_i\))&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Randomized method&lt;/strong&gt;: The iteration complexity of the randomized method is \(O(m^{2}G^{2}/\epsilon^{2})\). That is, the randomized method requires \(O(mG^{2}/\epsilon^2)\) iterations, which is \(m\) times faster than the batch and cyclic methods with \(O(m^2G^2/\epsilon^2)\). In terms of Big-O notation, if \(m\) is large, the randomized method has a faster convergence rate.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although the Big-O bounds for randomized and cyclic methods differ by a factor of \(m\), note that the cyclic method’s Big-O bound is worst-case, while the randomized method’s is average-case. In practice, the difference may not be as large as the Big-O notation suggests.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02-02 Convergence of Stochastic Methods</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_02_02_convergence_of_stochastic_methods/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_02_02_convergence_of_stochastic_methods</id>
   <content type="html">&lt;p&gt;Does a noisy, one-sample-at-a-time subgradient loop actually converge to the true minimizer of the full sum, or does the constant tug-of-war between conflicting data points trap it forever? Remarkably, the exact same qualitative dichotomy from deterministic subgradient optimization reappears—only with a sharper dependence on the number of terms \(m\) and an extra factor of \(5\) in the fixed-step error neighborhood. This lesson states the core convergence theorems for both cyclic and randomized stochastic subgradient methods.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-convergence-guarantees-under-sampling-noise&quot;&gt;Key ideas: Convergence Guarantees Under Sampling Noise&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Componentwise \(G\)-Lipschitz Continuity:&lt;/strong&gt; Assuming each individual term \(f_i\) is \(G\)-Lipschitz (\(\|g_i\|_2 \le G\)) implies the full sum \(f = \sum_{i=1}^m f_i\) is at most \(mG\)-Lipschitz. The factor \(m^2 G^2\) in the error floor directly reflects the worst-case disagreement among \(m\) components.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Fixed-Step Error Floor (\(5 m^2 G^2 t / 2\)):&lt;/strong&gt; With constant step size \(t\), both cyclic and randomized methods satisfy \(\lim_{k \to \infty} f(x_{\text{best}}^{(k)}) \le f^\star + \frac{5 m^2 G^2 t}{2}\) (in expectation for the randomized variant). The larger constant compared to batch (\(G_{\text{batch}}^2 t / 2\)) accounts for drift &lt;em&gt;within&lt;/em&gt; a cycle of \(m\) updates.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Exact Asymptotic Convergence via Diminishing Steps:&lt;/strong&gt; Under the Robbins–Monro conditions \(\sum t_k = \infty\) and \(\sum t_k^2 &amp;lt; \infty\), the intra-cycle drift and stochastic variance both vanish asymptotically, guaranteeing \(f(x_{\text{best}}^{(k)}) \to f^\star\) (with probability 1 / in expectation for randomized selection).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Expectation vs. Deterministic Guarantees:&lt;/strong&gt; Cyclic methods yield deterministic bounds across full epochs, whereas randomized methods bound \(\mathbb{E}[f(x_{\text{best}}^{(k)})]\) (and converge almost surely by supermartingale convergence).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-quantifying-the-fixed-step-noise-floor-as-m-grows&quot;&gt;Worked example: Quantifying the Fixed-Step Noise Floor as \(m\) Grows&lt;/h3&gt;

&lt;p&gt;Suppose \(f(x) = \sum_{i=1}^m f_i(x)\) where each \(f_i\) has Lipschitz constant \(G = 1\), and we compare \(m = 10\) vs. \(m = 100\) components using a fixed step size \(t\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the guaranteed error floor for \(m = 10\) and \(t = 10^{-3}\):&lt;/strong&gt;
\(\frac{5 m^2 G^2 t}{2} = \frac{5 \cdot 10^2 \cdot 1^2 \cdot 10^{-3}}{2} = \frac{500 \cdot 10^{-3}}{2} = 0.25.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the same step size \(t = 10^{-3}\) when \(m = 100\):&lt;/strong&gt;
\(\frac{5 m^2 G^2 t}{2} = \frac{5 \cdot 100^2 \cdot 1^2 \cdot 10^{-3}}{2} = \frac{50{,}000 \cdot 10^{-3}}{2} = 25.0.\)
Because the unnormalized sum \(f = \sum_{i=1}^m f_i\) grows linearly with \(m\) and its squared Lipschitz constant grows like \(m^2\), keeping \(t\) fixed inflates the error floor by \(100\times\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rescale \(t\) to keep the per-sample average error \(\frac{1}{m}(f - f^\star) \le 0.025\):&lt;/strong&gt;
We need \(\frac{5 m G^2 t}{2} \le 0.025 \implies t \le \frac{0.05}{5 m G^2} = \frac{0.01}{m}\).
    &lt;ul&gt;
      &lt;li&gt;For \(m = 10\): \(t \le 10^{-3}\).&lt;/li&gt;
      &lt;li&gt;For \(m = 100\): \(t \le 10^{-4}\).
This hand calculation explains a universal rule of thumb in practice: when optimizing an unnormalized sum of \(m\) losses, the step size must scale inversely with \(m\) (or equivalently, optimize the average \(\frac{1}{m}\sum f_i\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Assume each function \(f_i, i = 1,...,m\) is convex and Lipschitz continuous with constant G.&lt;/p&gt;

&lt;p&gt;For the stochastic subgradient method, the following properties hold for fixed and diminishing step sizes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Fixed step sizes&lt;/strong&gt; for \(t_k = t\), \(k = 1, 2, 3, ...\)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\text{For cyclic and randomized methods with fixed step sizes, the following holds:} \\
\begin{align}
\lim_{k\to\infty} f(x_{best}^{(k)}) \le f^{*} + 5m^{2}G^{2}t/2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(mG\) is the Lipschitz constant of \(\sum_{i=1}^{m} f_i\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Diminishing step sizes&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\text{For cyclic and randomized methods with diminishing step sizes, the following holds:} \\
\begin{align}
\lim_{k\to\infty} f(x_{best}^{(k)}) = f^{*}
\end{align}\]
&lt;/blockquote&gt;

</content>
 </entry>
 
 <entry>
   <title>08-02-01 Stochastic Subgradient Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_02_01_stochastic_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_02_01_stochastic_subgradient_method</id>
   <content type="html">&lt;p&gt;Replacing a full dataset sweep with a single data point turns every iteration into a quick, noisy tug in one component’s direction. To analyze and implement this cleanly, we distinguish two classic index-selection rules: the &lt;strong&gt;cyclic&lt;/strong&gt; (incremental) method, which marches through \(i = 1, 2, \dots, m\) in fixed order, and the &lt;strong&gt;randomized&lt;/strong&gt; method, which draws \(i_k\) uniformly at random at every step. This lesson formalizes both updates side by side and prepares the ground for comparing their convergence guarantees.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-cyclic-vs-randomized-incremental-updates&quot;&gt;Key ideas: Cyclic vs. Randomized Incremental Updates&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Additive Subdifferential Decomposition:&lt;/strong&gt; For convex functions \(f_1, \dots, f_m\) on \(\mathbb{R}^n\), \(\partial\left(\sum_{i=1}^m f_i\right)(x) = \sum_{i=1}^m \partial f_i(x)\). A batch step evaluates all \(m\) components at the &lt;em&gt;same&lt;/em&gt; point \(x^{(k-1)}\), whereas incremental methods update \(x\) after &lt;em&gt;every&lt;/em&gt; single component.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Cyclic (Incremental) Subgradient Rule:&lt;/strong&gt; Choosing \(i_k = ((k - 1) \bmod m) + 1\) guarantees that every component \(f_i\) is visited exactly once per pass (epoch) of \(m\) steps, making it natural for sequential disk reads, though vulnerable to poorly ordered data.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Randomized Subgradient Rule:&lt;/strong&gt; Drawing \(i_k \sim \operatorname{Uniform}\{1, \dots, m\}\) independently at each step breaks worst-case data orderings and makes \(m g_{i_k}^{(k-1)}\) an unbiased estimator of a full subgradient, simplifying expectation-based convergence proofs.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Epoch-Level Interpretation:&lt;/strong&gt; One full pass of \(m\) stochastic steps performs roughly the same arithmetic work as \(1\) batch subgradient step, so fair comparisons always measure progress per &lt;em&gt;epoch&lt;/em&gt; (effective data passes) rather than per raw update.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-full-cyclic-epoch-on-a-3-term-absolute-deviation-problem&quot;&gt;Worked example: One Full Cyclic Epoch on a 3-Term Absolute-Deviation Problem&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize $$f(x) =&lt;/td&gt;
      &lt;td&gt;x - 1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x - 2&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x - 6&lt;/td&gt;
      &lt;td&gt;\((the median minimizer is\)x^\star = 2\(, with\)f^\star = 1 + 0 + 4 = 5\(). Start at\)x^{(0)} = 0\(with fixed step size\)t = 0.5\(and cyclic order\)i = 1, 2, 3$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Step 1 ($$f_1(x) =&lt;/td&gt;
          &lt;td&gt;x - 1&lt;/td&gt;
          &lt;td&gt;\(at\)x^{(0)} = 0$$):**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Since \(0 &amp;lt; 1\), \(g_1(0) = -1\).&lt;/li&gt;
      &lt;li&gt;\(x^{(1)} = 0 - 0.5(-1) = 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Step 2 ($$f_2(x) =&lt;/td&gt;
          &lt;td&gt;x - 2&lt;/td&gt;
          &lt;td&gt;\(at\)x^{(1)} = 0.5$$):**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Since \(0.5 &amp;lt; 2\), \(g_2(0.5) = -1\).&lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = 0.5 - 0.5(-1) = 1.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Step 3 ($$f_3(x) =&lt;/td&gt;
          &lt;td&gt;x - 6&lt;/td&gt;
          &lt;td&gt;\(at\)x^{(2)} = 1.0$$):**&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Since \(1.0 &amp;lt; 6\), \(g_3(1.0) = -1\).&lt;/li&gt;
      &lt;li&gt;\(x^{(3)} = 1.0 - 0.5(-1) = 1.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare after 1 epoch (3 component evaluations):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Cyclic incremental moved from \(x^{(0)} = 0\) (\(f(0) = 9\)) to \(x^{(3)} = 1.5\) (\(f(1.5) = 0.5 + 0.5 + 4.5 = 5.5\)), cutting the suboptimality gap from \(4.0\) down to \(0.5\)!&lt;/li&gt;
      &lt;li&gt;A batch step from \(x^{(0)} = 0\) with \(t = 0.5\) uses \(g(0) = -1 - 1 - 1 = -3\), landing at \(x^{(1)}_{\text{batch}} = 0 - 0.5(-3) = 1.5\)—identical here because all three components had the same sign, whereas once \(x\) crosses \(1\), the incremental method immediately feels the sign flip on \(f_1\) mid-epoch.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s consider the problem of minimizing the sum of functions as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{equation}
\min_x \sum_{i=1}^m f_i(x)
\end{equation}\]
&lt;/blockquote&gt;

&lt;p&gt;If we apply the subgradient method to this problem, we need to compute the subgradient for each function \(f_i\) and sum them. (This is similar to the method introduced in &lt;a href=&quot;/contents/en/chapter06/06_05_stochastic_gradient_descent/&quot;&gt;stochastic gradient descent&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;In summary, the stochastic subgradient method takes the following form:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
x^{(k)} = x^{(k-1)} - t_k \cdot g_{i_k}^{(k-1)}, \quad k = 1, 2, 3, . . . 
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(i_k \in \{1,...,m\}\) is the index chosen at the \(k\)-th iteration. As will be discussed in the next section on the convergence rate of the stochastic subgradient method, the choice of cyclic or random method affects the result. \(g_{i}^{(k-1)} \in \partial f_{i}(x^{k-1})\), and this update direction is different from the usual &lt;a href=&quot;/contents/en/chapter08/08_01_subgradient_method/&quot;&gt;subgradient method&lt;/a&gt; (also called batch subgradient method or full batch subgradient method), where \(\sum_{i=1}^{m} g_i^{(k-1)}\) is used.&lt;/p&gt;

&lt;p&gt;If each \(f_i, i = 1,...,m\) is differentiable, this algorithm becomes stochastic gradient descent. (The stochastic subgradient method is a more general form)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01 Subgradient Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_subgradient_method</id>
   <content type="html">&lt;p&gt;When you first replace \(\nabla f(x^{(k-1)})\) with a subgradient \(g^{(k-1)} \in \partial f(x^{(k-1)})\), the update equation looks almost identical to ordinary gradient descent. Yet removing differentiability changes the algorithm’s personality completely: you lose the guarantee of monotonic descent, you can no longer rely on Armijo backtracking line search, and you must rethink what “making progress” even means. This lesson introduces the canonical subgradient iteration and explains why optimization theorists deliberately drop the word “descent” from its name.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-the-subgradient-update&quot;&gt;Key ideas: Anatomy of the Subgradient Update&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Generalized First-Order Oracle:&lt;/strong&gt; At each iterate \(x^{(k-1)}\), the algorithm queries a single arbitrary vector \(g^{(k-1)} \in \partial f(x^{(k-1)})\). Computing all of \(\partial f(x)\) is unnecessary; any one supporting slope suffices to define the step.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Failure of Descent Directions:&lt;/strong&gt; For a smooth function, \(-\nabla f(x)\) is always a descent direction whenever \(\nabla f(x) \neq 0\). For a nonsmooth function, \(-g\) can point strictly uphill along a ridge (forming an obtuse angle with the steepest descent direction), so \(f(x - tg) &amp;gt; f(x)\) can happen for &lt;em&gt;every&lt;/em&gt; \(t &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Distance Contraction as a Lyapunov Function:&lt;/strong&gt; Instead of tracking \(f(x^{(k)})\), the analysis monitors \(\|x^{(k)} - x^\star\|_2^2\). Because \(g^{(k-1)\top}(x^{(k-1)} - x^\star) \ge f(x^{(k-1)}) - f^\star &amp;gt; 0\), the negative subgradient always forms an acute angle with \(x^\star - x^{(k-1)}\), guaranteeing distance reduction for sufficiently small \(t_k\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Keeping Track of \(x_{\text{best}}^{(k)}\):&lt;/strong&gt; Since the last iterate \(x^{(k)}\) may sit on an upward oscillation, any practical implementation stores \(x_{\text{best}}^{(k)} = \arg\min_{0 \le i \le k} f(x^{(i)})\) at essentially zero extra memory cost.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-why--g-can-fail-to-be-a-descent-direction-for-every-t--0&quot;&gt;Worked example: Why \(-g\) Can Fail to Be a Descent Direction for Every \(t &amp;gt; 0\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider \(f(x_1, x_2) = \max\{ x_1 + 2x_2,\; x_1 - 2x_2 \}\), which simplifies to $$f(x_1, x_2) = x_1 + 2&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate at \(x^{(0)} = (0, 0)\):&lt;/strong&gt; Here \(f(0, 0) = 0\), and both linear pieces achieve the maximum simultaneously.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Identify the subdifferential:&lt;/strong&gt; By the pointwise-maximum rule, \(\partial f(0, 0) = \operatorname{conv}\{(1, 2), (1, -2)\} = \{ (1, v) : v \in [-2, 2] \}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pick the valid subgradient \(g = (1, 2) \in \partial f(0, 0)\):&lt;/strong&gt; Move along \(-g\) with &lt;em&gt;any&lt;/em&gt; positive step size \(t &amp;gt; 0\):
\(x(t) = (0, 0) - t(1, 2) = (-t, -2t).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate \(f(x(t))\):&lt;/strong&gt;
\(f(-t, -2t) = (-t) + 2|-2t| = -t + 4t = 3t &amp;gt; 0 = f(0, 0).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt; For &lt;em&gt;every&lt;/em&gt; \(t &amp;gt; 0\), no matter how infinitesimally small, moving along \(-g\) strictly increases \(f\)! Yet if the minimizer over a bounded region lies in the half-space \(x_1 &amp;lt; 0, x_2 = 0\), say \(x^\star = (-5, 0)\), notice that \((-g)^\top (x^\star - x^{(0)}) = (-1, -2)^\top (-5, 0) = +5 &amp;gt; 0\), confirming that \(-g\) still points toward \(x^\star\) even while climbing uphill.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Assume the domain of the function is \({R}^n\) and there is a convex function \(f\) that may not be differentiable everywhere.&lt;/p&gt;

&lt;p&gt;The subgradient method is defined by replacing the gradient in gradient descent with a subgradient. (\(\nabla f(x^{(k-1)}) \to g(x^{(k-1)})\))&lt;/p&gt;

&lt;blockquote&gt;
\[x^{(k)} = x^{(k-1)} - t_k \cdot g^{(k-1)}, \quad k = 1, 2, 3, . . .\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(g^{(k-1)} \in \partial f(x^{(k-1)})\), i.e., \(g^{(k-1)}\) is a subgradient of \(f\) at \(x^{(k-1)}\).&lt;/p&gt;

&lt;h2 id=&quot;subgradient-method-not-subgradient-descent&quot;&gt;Subgradient method (not subgradient “descent”)&lt;/h2&gt;

&lt;p&gt;Unlike gradient descent, the subgradient method does not always guarantee descent at each step (hence the name is not subgradient “descent”). Therefore, when using the subgradient method, it is important to track the best result at each iteration.&lt;/p&gt;

&lt;blockquote&gt;
\[f(x_{best}^{(k)}) = \min_{i=0,...k} f(x^{(i)})\]
&lt;/blockquote&gt;

&lt;p&gt;\(f(x^{(k)}_{best})\) denotes the minimum value of the function \(f\) obtained over \(k\) iterations of the subgradient method.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-08 Projected Subgradient Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_08_projected_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_08_projected_subgradient_method</id>
   <content type="html">&lt;p&gt;Real-world optimization problems rarely live in unconstrained \(\mathbb{R}^n\): probabilities must sum to one and stay nonnegative, portfolio weights face leverage caps, and adversarial perturbations must stay inside an \(\ell_p\) ball. The &lt;strong&gt;projected subgradient method&lt;/strong&gt; handles such constraints with disarming elegance: take an ordinary subgradient step as if no constraints existed, and if you step outside the feasible set \(C\), snap right back to the nearest point inside \(C\) via Euclidean projection. Surprisingly, this projection step never hurts the convergence rate—in fact, it strictly helps!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-constrained-nonsmooth-optimization-via-projection&quot;&gt;Key ideas: Constrained Nonsmooth Optimization via Projection&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Euclidean Projection Operator \(P_C(y)\):&lt;/strong&gt; Defined as \(P_C(y) = \arg\min_{x \in C} \frac{1}{2}\|x - y\|_2^2\), the projection onto a nonempty closed convex set \(C\) always exists and is unique. For simple sets (boxes, Euclidean balls, half-spaces, simplices), \(P_C\) has a fast closed-form or \(O(n \log n)\) algorithm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Nonexpansiveness (Why Projection Only Helps):&lt;/strong&gt; Because \(C\) is convex, Euclidean projection is nonexpansive: for any \(y \in \mathbb{R}^n\) and any feasible \(x^\star \in C\), \(\|P_C(y) - x^\star\|_2^2 \le \|y - x^\star\|_2^2\) (in fact, \(\|P_C(y) - x^\star\|_2^2 \le \|y - x^\star\|_2^2 - \|y - P_C(y)\|_2^2\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Unchanged Basic Inequality &amp;amp; \(O(1/\varepsilon^2)\) Rate:&lt;/strong&gt; Applying nonexpansiveness to \(y = x^{(k)} - t_k g^{(k)}\) yields \(\|x^{(k+1)} - x^\star\|_2^2 \le \|x^{(k)} - t_k g^{(k)} - x^\star\|_2^2\), so the exact same basic inequality and convergence rates (fixed, diminishing, and Polyak) carry over verbatim from the unconstrained setting.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Computational Bottleneck:&lt;/strong&gt; Each iteration costs one subgradient evaluation plus one projection \(P_C\). The method is therefore ideal when \(P_C\) is cheap, whereas complex polyhedra or semidefinite cones motivate projection-free methods (Frank–Wolfe) or dual decomposition.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-projected-subgradient-on-a-box-constraint&quot;&gt;Worked example: Projected Subgradient on a Box Constraint&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize $$f(x_1, x_2) =&lt;/td&gt;
      &lt;td&gt;x_1 - 2&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;x_2 + 1&lt;/td&gt;
      &lt;td&gt;\(subject to the unit box\)C = [-1, 1] \times [-1, 1]\(. Notice the unconstrained minimum\)(2, -1)\(lies outside\)C\(, while the constrained minimum is\)x^\star = (1, -1)\(with\)f^\star = 1$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Initialize at \(x^{(0)} = (0, 0) \in C\)&lt;/strong&gt; with step size \(t_1 = 1.5\). Here $$f(0, 0) =&lt;/td&gt;
          &lt;td&gt;-2&lt;/td&gt;
          &lt;td&gt;+&lt;/td&gt;
          &lt;td&gt;1&lt;/td&gt;
          &lt;td&gt;= 3\(, and\)|x^{(0)} - x^\star|_2^2 = 1^2 + 1^2 = 2$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute a subgradient at \(x^{(0)} = (0, 0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Since \(x_1 - 2 = -2 &amp;lt; 0\), $$\partial_{x_1}&lt;/td&gt;
              &lt;td&gt;x_1 - 2&lt;/td&gt;
              &lt;td&gt;= {-1}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Since \(x_2 + 1 = 1 &amp;gt; 0\), $$\partial_{x_2}&lt;/td&gt;
              &lt;td&gt;x_2 + 1&lt;/td&gt;
              &lt;td&gt;= {+1}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Hence \(g^{(0)} = (-1, 1)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take the unconstrained subgradient step:&lt;/strong&gt;
\(y^{(1)} = x^{(0)} - t_1 g^{(0)} = (0, 0) - 1.5(-1, 1) = (1.5, -1.5).\)
Notice \(y^{(1)} \notin C\) (both coordinates exceed the box bounds \([-1, 1]\)), and its squared distance to \(x^\star = (1, -1)\) is \((1.5 - 1)^2 + (-1.5 + 1)^2 = 0.25 + 0.25 = 0.50\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Project onto the box \(C = [-1, 1]^2\) (coordinatewise clipping):&lt;/strong&gt;
\(x^{(1)} = P_C(1.5, -1.5) = (\min(1, \max(-1, 1.5)),\; \min(1, \max(-1, -1.5))) = (1, -1).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify nonexpansiveness:&lt;/strong&gt; After projection, \(\|x^{(1)} - x^\star\|_2^2 = 0 &amp;lt; 0.50 = \|y^{(1)} - x^\star\|_2^2\). The projection not only restored feasibility—it landed directly on the exact constrained optimum \(x^\star = (1, -1)\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The method described in the previous example is called the projected subgradient method. This algorithm can be used for convex problems with constraints.&lt;/p&gt;

&lt;p&gt;If we denote the domain that satisfies the constraints as the set \(C\), then a constrained convex problem is defined as follows:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
\min_x \text{ }f(x) \quad \text{subject to } x \in C
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;By using the projected subgradient method, such problems can be solved relatively easily. The projected subgradient method is similar to the standard subgradient method, but at each iteration, the result is projected onto the set \(C\).&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
x^{(k)} = P_c(x^{(k-1)} - t_k \cdot g^{(k-1)}), \quad k = 1,2,3,...
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;If projection is possible, this method has the same convergence properties and rate as the subgradient method.&lt;/p&gt;

&lt;p&gt;One thing to note about the projected subgradient method is that even if \(C\) is a simple convex set, if the projection operation \(P_c\) is difficult, the overall problem also becomes hard to solve. Typically, the following sets \(C\) are relatively easy to project onto:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Affine images: {\(Ax=b : x \in \mathbb{R}^{n}\)}&lt;/li&gt;
  &lt;li&gt;Solution set of linear system: {\(x: Ax=b\)}&lt;/li&gt;
  &lt;li&gt;Nonnegative orthant: \(\mathbb{R}_+^{n} =\){\(x: x\ge 0\)}&lt;/li&gt;
  &lt;li&gt;Some norm balls: {\(x: \lVert x \rVert _p \le 1\)} for \(p=1,2,\infty\)&lt;/li&gt;
  &lt;li&gt;Some simple polyhedra and simple cones&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-07 Example: Intersection of sets</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_07_example_intersection_of_sets/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_07_example_intersection_of_sets</id>
   <content type="html">&lt;p&gt;From reconstructing CT scans that must simultaneously match X-ray measurements and physical density bounds, to finding a portfolio that satisfies both risk caps and regulatory sector limits, engineers constantly face the &lt;strong&gt;convex feasibility problem&lt;/strong&gt;: find a single point \(x\) lying inside the intersection \(C_1 \cap C_2 \cap \dots \cap C_m\) of several closed convex sets. Remarkably, by rewriting feasibility as minimizing the maximum Euclidean distance to all sets—an objective whose optimal value is known to be \(f^\star = 0\)—Polyak’s subgradient method morphs automatically into the classic &lt;strong&gt;alternating projections&lt;/strong&gt; algorithm!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-convex-feasibility-as-nonsmooth-optimization&quot;&gt;Key ideas: Convex Feasibility as Nonsmooth Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Distance-to-Set Function:&lt;/strong&gt; For a nonempty closed convex set \(C_i\), \(d_{C_i}(x) = \min_{y \in C_i} \|x - y\|_2\) is convex and \(1\)-Lipschitz. Outside \(C_i\), it is differentiable with unit-length gradient \(\nabla d_{C_i}(x) = \frac{x - P_{C_i}(x)}{\|x - P_{C_i}(x)\|_2}\), pointing directly away from the unique Euclidean projection \(P_{C_i}(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Pointwise Maximum Formulation:&lt;/strong&gt; Defining \(f(x) = \max_{1 \le i \le m} d_{C_i}(x)\) converts feasibility into \(\min_x f(x)\). Whenever the intersection is nonempty, \(f^\star = 0\) is known exactly, unlocking Polyak’s step size with zero tuning.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Active-Set Subgradient Selection:&lt;/strong&gt; By Danskin’s / pointwise-maximum subdifferential rule, choosing the farthest set \(j \in \arg\max_i d_{C_i}(x^{(k)})\) yields a valid unit-norm subgradient \(g^{(k)} = \frac{x^{(k)} - P_{C_j}(x^{(k)})}{\|x^{(k)} - P_{C_j}(x^{(k)})\|_2}\) with \(\|g^{(k)}\|_2 = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Equivalence to Farthest-Set Projection:&lt;/strong&gt; Plugging \(f(x^{(k)}) = d_{C_j}(x^{(k)})\), \(f^\star = 0\), and \(\|g^{(k)}\|_2 = 1\) into Polyak’s update gives \(x^{(k+1)} = x^{(k)} - d_{C_j}(x^{(k)}) \frac{x^{(k)} - P_{C_j}(x^{(k)})}{d_{C_j}(x^{(k)})} = P_{C_j}(x^{(k)})\): every Polyak subgradient step is literally an exact Euclidean projection onto the most violated constraint set.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-finding-a-point-in-the-intersection-of-a-half-space-and-a-disk&quot;&gt;Worked example: Finding a Point in the Intersection of a Half-Space and a Disk&lt;/h3&gt;

&lt;p&gt;Let \(C_1 = \{ (x_1, x_2) \in \mathbb{R}^2 : x_1^2 + x_2^2 \le 1 \}\) (the unit disk) and \(C_2 = \{ (x_1, x_2) \in \mathbb{R}^2 : x_1 \ge 0.5 \}\) (a right half-space). Start at \(x^{(0)} = (-3, 0)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 at \(x^{(0)} = (-3, 0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Distance to \(C_1\): \(P_{C_1}(-3, 0) = (-1, 0)\), so \(d_{C_1}(x^{(0)}) = \|(-3, 0) - (-1, 0)\|_2 = 2.0\).&lt;/li&gt;
      &lt;li&gt;Distance to \(C_2\): \(P_{C_2}(-3, 0) = (0.5, 0)\), so \(d_{C_2}(x^{(0)}) = \|(-3, 0) - (0.5, 0)\|_2 = 3.5\).&lt;/li&gt;
      &lt;li&gt;Farthest set is \(C_2\) (\(f(x^{(0)}) = 3.5\)). The unit subgradient is \(g^{(0)} = \frac{(-3, 0) - (0.5, 0)}{3.5} = (-1, 0)\).&lt;/li&gt;
      &lt;li&gt;Polyak step size: \(t_1 = \frac{f(x^{(0)}) - 0}{\|g^{(0)}\|_2^2} = \frac{3.5}{1^2} = 3.5\).&lt;/li&gt;
      &lt;li&gt;Update: \(x^{(1)} = (-3, 0) - 3.5(-1, 0) = (0.5, 0) = P_{C_2}(x^{(0)})\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify feasibility at \(x^{(1)} = (0.5, 0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Check \(C_1\): \(0.5^2 + 0^2 = 0.25 \le 1\) (inside \(C_1\), \(d_{C_1} = 0\)).&lt;/li&gt;
      &lt;li&gt;Check \(C_2\): \(0.5 \ge 0.5\) (inside \(C_2\), \(d_{C_2} = 0\)).&lt;/li&gt;
      &lt;li&gt;Thus \(f(x^{(1)}) = 0 = f^\star\) and \(x^{(1)} \in C_1 \cap C_2\) in one step! When the sets meet at an angle (e.g., two slanted half-spaces), the exact same rule zig-zags cleanly into \(C_1 \cap C_2\) while shrinking \(\|x^{(k)} - x^\star\|_2\) monotonically at every projection.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Suppose we want to find a point in the intersection of several closed convex sets.&lt;/p&gt;

&lt;p&gt;First, let \(f_i(x)\) be the distance from a point \(x\) to the set \(C_i\), and let \(f(x)\) be the maximum of the distances from \(x\) to all the sets \(C_i, i=1,...,m\):&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
f_i(x) &amp;amp; = \mathbb{dist}(x, C_i), \quad i=1,...,m \\
f(x) &amp;amp; = \max_{i=1,...,m}\text{ }f_i(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Using these two functions, the problem of finding a point in the intersection of the convex sets can be formulated as the following minimization problem:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
\min_{x}\text{ }f(x)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Finding a point in the intersection of the convex sets is equivalent to finding the point \(x\) that minimizes the maximum distance \(f(x)\) to the sets \(C_i\). In this case, the objective function \(f(x)\) is convex. If the sets have a common point, then \(f^* = 0\) and the optimal point is \(x^* \in C_1 \cap C_2 \cap ... \cap C_m\).&lt;/p&gt;

&lt;h2 id=&quot;gradient-of-distance-function&quot;&gt;Gradient of distance function&lt;/h2&gt;

&lt;p&gt;In &lt;a href=&quot;/contents/en/chapter07/07_03_05_example_distance_to_convex_set/&quot;&gt;the previous section&lt;/a&gt;, we defined the distance to a convex set as \(dist(x, C_i) = \min_{y \in C} \lVert y-x \rVert _2\), and saw that its gradient is:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
\partial dist(x,C) = \frac{x-P_C(x)}{ \Vert x-P_C(x) \Vert_2}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(P_C(x)\) is the projection of the point \(x\) onto the set \(C\).&lt;/p&gt;

&lt;h2 id=&quot;subdifferential-of-finite-pointwise-maximum&quot;&gt;Subdifferential of finite pointwise maximum&lt;/h2&gt;

&lt;p&gt;The subdifferential of the finite pointwise maximum function \(f(x)=\max_{i=1,...,m}\text{ }f_i(x)\) is given by&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
\partial f(x) = \text{conv}\left(\bigcup_{i:f_i(x)=f(x)} \partial f_i(x)\right)
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;That is, the subdifferential of \(f\) at \(x\) is the convex hull of the union of the subdifferentials \(\partial f_i(x)\) of all the functions \(f_i\) that attain the maximum at \(x\).&lt;/p&gt;

&lt;p&gt;In particular, if \(f_i(x) = f(x)\) and \(g_i \in \partial f_i(x)\), then \(g_i \in \partial f(x)\).&lt;/p&gt;

&lt;h2 id=&quot;deriving-subgradient-updating-steps&quot;&gt;Deriving subgradient updating steps&lt;/h2&gt;

&lt;p&gt;As we saw in &lt;a href=&quot;/contents/en/chapter07/07_03_05_example_distance_to_convex_set/&quot;&gt;the previous section&lt;/a&gt;, \(dist(x, C_i)\) has the following subgradient:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(\text{Recall:}\)
\(\begin{align}
g_i = \nabla f_i(x) = \frac{x-P_{C_i}(x)}{ \Vert x-P_{C_i}(x) \Vert_2}
\end{align}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the convex sets have a common point, we know right away that \(f^*=0\), so we can use Polyak step sizes. Since \(x-P_{C_i}(x)\) is normalized in the subgradient above, \(\Vert g \Vert_2^{2}=1\). Substituting these known values into the Polyak step size \(t_k = \frac{f(x^{(k-1)})-f^*}{ \Vert g^{(k-1)} \Vert_2^{2}}\), we obtain the following subgradient method update (here \(i\) is an index of a set farthest from \(x^{(k-1)}\), i.e. \(f_i(x^{(k-1)}) = f(x^{(k-1)})\)):&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
x^{(k)} &amp;amp; = x^{(k-1)} - t_{k}\cdot g^{(k-1)} \\
&amp;amp; = x^{(k-1)} - \frac{f(x^{(k-1)})-f^*}{ \Vert g^{(k-1)} \Vert_2^{2}} \frac{x^{(k-1)}-P_{C_i}(x^{(k-1)})}{ \Vert x^{(k-1)}-P_{C_i}(x^{(k-1)}) \Vert_2}  \\
&amp;amp; = x^{(k-1)} - f(x^{(k-1)}) \frac{x^{(k-1)}-P_{C_i}(x^{(k-1)})}{ \Vert x^{(k-1)}-P_{C_i}(x^{(k-1)}) \Vert_2}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Here the Polyak step size is \(f(x^{(k-1)}) = dist(x^{(k-1)}, C_i) =  \Vert x^{(k-1)}-P_{C_i}(x^{(k-1)}) \Vert_2\), so the subgradient method simplifies to:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
x^{(k)} = P_{C_i}(x^{(k-1)})
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;In pictures, at each step the iterate is projected onto the set that is farthest from it, and this is repeated.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter08/08_01_projection.png&quot; alt=&quot;projection&quot; width=&quot;60%&quot; height=&quot;60%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 2] Alternating Projection Algorithm [10]&lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-06 Polyak step sizes</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_06_polyak_step_sizes/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_06_polyak_step_sizes</id>
   <content type="html">&lt;p&gt;Choosing a diminishing step-size schedule often feels like flying blind: make \(t_k\) too small and you crawl; make it too large and you bounce wildly. In 1969, Boris Polyak asked a deceptively simple question: &lt;em&gt;what if you already know the optimal value \(f^\star\)?&lt;/em&gt; In feasibility problems, overparameterized machine learning (where interpolation achieves \(f^\star = 0\)), and exact-zero-residual systems, \(f^\star\) is known a priori—and Polyak showed that projecting onto the linear underestimator \(f(x^{(k)}) + g^{(k)\top}(x - x^{(k)}) = f^\star\) yields a self-tuning, parameter-free step size that strictly minimizes the distance bound at every single iteration.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-geometry-of-polyaks-step-size&quot;&gt;Key ideas: The Geometry of Polyak’s Step Size&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Exact Hyperplane Projection Intuition:&lt;/strong&gt; Setting the first-order convex lower bound \(f(x^{(k)}) + g^{(k)\top}(x - x^{(k)})\) equal to \(f^\star\) defines a separating hyperplane that separates \(x^{(k)}\) from the optimal set. Projecting \(x^{(k)}\) orthogonally onto this hyperplane yields the exact Polyak step \(t_k = \frac{f(x^{(k)}) - f^\star}{\|g^{(k)}\|_2^2}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Optimal One-Step Distance Reduction:&lt;/strong&gt; Minimizing the RHS of the one-step distance inequality \(\|x^{(k+1)} - x^\star\|_2^2 \le \|x^{(k)} - x^\star\|_2^2 - 2t_k(f(x^{(k)}) - f^\star) + t_k^2 \|g^{(k)}\|_2^2\) with respect to \(t_k\) recovers Polyak’s formula uniquely, shrinking the squared distance by at least \(\frac{(f(x^{(k)}) - f^\star)^2}{\|g^{(k)}\|_2^2}\) at every step.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Scale Invariance &amp;amp; Zero Hyperparameter Tuning:&lt;/strong&gt; If you rescale the objective by a constant \(c &amp;gt; 0\) (replacing \(f\) with \(cf\)), both the numerator \(f - f^\star\) and denominator \(\|g\|_2^2\) scale cleanly so \(t_k g^{(k)}\) is &lt;em&gt;completely invariant&lt;/em&gt; to objective scaling—no Lipschitz constant \(G\) or initial radius \(R\) is ever needed.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Sensitivity to Misspecified \(f^\star\):&lt;/strong&gt; Polyak’s rule assumes \(f^\star\) is exact. Overestimating \(f^\star\) stalls progress early; underestimating \(f^\star\) causes persistent overshooting near the optimum, motivating modern adaptive variants (such as SPS in stochastic deep learning) that estimate or clip \(f^\star\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-polyaks-step-vs-fixed-step-on-a-steep-piecewise-linear-function&quot;&gt;Worked example: Polyak’s Step vs. Fixed Step on a Steep Piecewise Linear Function&lt;/h3&gt;

&lt;p&gt;Consider \(f(x) = \max\{ 2x - 2,\; -4x - 2,\; 0 \}\) on \(\mathbb{R}\), whose optimal value is known to be \(f^\star = 0\) (achieved on the interval \(x \in [-0.5, 1]\)). Start at \(x^{(0)} = 4\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration 1 at \(x^{(0)} = 4\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Evaluate the pieces: \(2(4) - 2 = 6\), \(-4(4) - 2 = -18\), \(0\). Thus \(f(4) = 6\) and the active piece is \(2x - 2\), so \(g^{(0)} = 2\).&lt;/li&gt;
      &lt;li&gt;Compute Polyak step size:
\(t_1 = \frac{f(x^{(0)}) - f^\star}{\|g^{(0)}\|_2^2} = \frac{6 - 0}{2^2} = \frac{6}{4} = 1.5.\)&lt;/li&gt;
      &lt;li&gt;Update:
\(x^{(1)} = x^{(0)} - t_1 g^{(0)} = 4 - 1.5(2) = 1.0.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the result:&lt;/strong&gt; At \(x^{(1)} = 1.0\), \(f(1.0) = \max\{0, -6, 0\} = 0 = f^\star\)! Polyak’s step hit the exact optimal set in a &lt;em&gt;single&lt;/em&gt; iteration because the active linear piece intersected \(y = f^\star\) at \(x = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the distance contraction bound:&lt;/strong&gt; With \(x^\star = 1\) (the closest minimizer), \(\|x^{(0)} - x^\star\|^2 = (4 - 1)^2 = 9\), and Polyak guarantees:
\(\|x^{(1)} - x^\star\|^2 \le 9 - \frac{(6 - 0)^2}{2^2} = 9 - 9 = 0.\)
Here the bound is tight to the last decimal place, illustrating why Polyak’s rule is the gold standard whenever \(f^\star\) is known.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Polyak step sizes&lt;/strong&gt; are a way to set the step size when the optimal value is known. If \(f^*\) is known, Polyak step sizes can be defined as follows.&lt;/p&gt;

&lt;h2 id=&quot;convergence-theorem-for-polyak-step-sizes&quot;&gt;Convergence theorem for Polyak step-sizes&lt;/h2&gt;
&lt;blockquote&gt;

\[\begin{align}
t_k = \frac{f^{(k-1)}-f^*}{ \Vert g^{(k-1)} \Vert_2^{2}}, \quad k = 1,2,3...
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;proof-of-convergence-theorem-for-polyak-step-sizes&quot;&gt;Proof of convergence theorem for Polyak step-sizes&lt;/h2&gt;
&lt;p&gt;The proof can be derived from the &lt;a href=&quot;/contents/en/chapter08/08_01_02_basic_inequality/&quot;&gt;basic inequality&lt;/a&gt; and the sequence of inequalities used there.&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
 \Vert x^{(k)}-x^* \Vert_2^{2}  \quad \le \quad  \Vert x^{(k-1)}-x^* \Vert_2^{2}-2t_k (f(x^{(k-1)})-f^*)+t_k^{2} \Vert g^{(k-1)} \Vert_2^{2} \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;By differentiating the right-hand side above with respect to \(t_k\) and setting it to zero, we obtain the Polyak step size that minimizes the right-hand side.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp; \frac{\partial}{\partial t_k}  \Vert x^{(k-1)}-x^* \Vert_2^{2}-2t_k (f(x^{(k-1)})-f^*)+t_k^{2} \Vert g^{(k-1)} \Vert_2^{2} = 0 \\
 \Longleftrightarrow &amp;amp; -2(f(x^{(k-1)})-f^*)+2t_k \Vert g^{(k-1)} \Vert_2^{2} = 0 \\
 \Longleftrightarrow &amp;amp; f(x^{(k-1)})-f^* = t_k \Vert g^{(k-1)} \Vert_2^{2} \\
 \Longleftrightarrow &amp;amp; t_k = \frac{f(x^{(k-1)})-f^*}{ \Vert g^{(k-1)} \Vert_2^{2}} \quad \text{(Polyak step size at k)}
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The convergence rate of the Polyak step size can also be derived from the &lt;a href=&quot;/contents/en/chapter08/08_01_02_basic_inequality/&quot;&gt;basic inequality&lt;/a&gt; and the sequence of inequalities used there.&lt;/p&gt;

&lt;h2 id=&quot;convergence-rate-for-polyak-step-sizes&quot;&gt;Convergence rate for Polyak step-sizes&lt;/h2&gt;

&lt;p&gt;Let’s substitute the Polyak step size \(t_i\) into the basic inequality derived in the &lt;a href=&quot;/contents/en/chapter08/08_01_02_basic_inequality/&quot;&gt;basic inequality&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp; 2\sum_{i=1}^{k}t_i(f(x^{(i)})-f^*) \le R^2 + \sum_{i=1}^kt_i^2 \Vert g^{(i)} \Vert_2^2 \\
 \Longleftrightarrow \quad &amp;amp; 2\sum_{i=1}^{k}\frac{(f(x^{(i)})-f^*)^2}{ \Vert g^{(i)} \Vert_2^2} \le R^2 + \sum_{i=1}^k\frac{(f(x^{(i)})-f^*)^2}{ \Vert g^{(i)} \Vert_2^2} \\
 \Longleftrightarrow \quad &amp;amp; \sum_{i=1}^{k}\frac{(f(x^{(i)})-f^*)^2}{ \Vert g^{(i)} \Vert_2^2} \le R^2 \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Assuming that the Lipschitz condition \(\Vert g^{(i)} \Vert_2 \le G\) always holds, the above inequality can be rearranged as follows:&lt;/p&gt;
&lt;blockquote&gt;

\[\begin{align}
&amp;amp; \sum_{i=1}^{k}(f(x^{(i)})-f^*)^2 \le R^2G^2 \\
 \Longleftrightarrow \quad &amp;amp; k ⋅ (f(x^{(i)})-f^*)^2 \le R^2G^2 \\
 \Longleftrightarrow \quad &amp;amp; \sqrt{k} ⋅ (f(x^{(i)})-f^*) \le RG \\
 \Longleftrightarrow \quad &amp;amp; (f(x^{(i)})-f^*) \le \frac{RG}{\sqrt{k}} \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;If we let \(\frac{RG}{\sqrt{k}}=\epsilon\), then \(k=\big(\frac{RG}{\epsilon}\big)^2\), so the number of trials required to reach a suboptimal point with respect to \(\epsilon\) is on the order of \(\big(\frac{RG}{\epsilon}\big)^2\). In other words, the convergence rate is \(O(1/\epsilon^{2})\), which is the same as other subgradient methods.&lt;/p&gt;

&lt;h3 id=&quot;the-polyak-step-choosing-the-step-from-f-video&quot;&gt;The Polyak step: choosing the step from f* (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/polyak-step_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;A constant step stalls at a floor, a diminishing step creeps, and the Polyak step \(\alpha_k=\dfrac{f(x_k)-f^*}{\|g_k\|_2^2}\) lands on the minimiser, but it needs \(f^*\).&lt;/p&gt;

&lt;h3 id=&quot;try-it-yourself-three-step-size-rules&quot;&gt;Try it yourself: three step-size rules&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;sgm&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-05 Example: Regularized Logistic Regression</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_05_example_regularized_logistic_regression/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_05_example_regularized_logistic_regression</id>
   <content type="html">&lt;p&gt;In modern high-dimensional statistics—from predicting disease risk from 50,000 genetic markers to scoring ad clicks across millions of sparse features—plain logistic regression quickly overfits. Adding an \(\ell_1\) penalty \(\lambda \|\beta\|_1\) simultaneously regularizes the model and drives irrelevant coefficients to exact zero, turning classification into automatic feature selection. Because \(\|\beta\|_1\) has sharp creases along every coordinate axis, smooth gradient descent can no longer be applied directly—making \(\ell_1\)-regularized logistic regression a classic proving ground for the subgradient method.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-ell_1-regularized-logistic-regression&quot;&gt;Key ideas: Anatomy of \(\ell_1\)-Regularized Logistic Regression&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Smooth Log-Loss (Negative Log-Likelihood):&lt;/strong&gt; The data-fidelity term \(f(\beta) = \sum_{i=1}^n (-y_i x_i^\top \beta + \log(1 + e^{x_i^\top \beta}))\) is convex and infinitely differentiable, with gradient \(\nabla f(\beta) = \sum_{i=1}^n (p_i(\beta) - y_i) x_i\), where \(p_i(\beta) = \frac{1}{1 + e^{-x_i^\top \beta}}\) is the predicted probability.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Nonsmooth Sparsity Inducer (\(\lambda \|\beta\|_1\)):&lt;/strong&gt; The \(\ell_1\) norm has subdifferential \(\partial \|\beta\|_1 = \{ v \in \mathbb{R}^p : v_j = \operatorname{sign}(\beta_j) \text{ if } \beta_j \neq 0,\; v_j \in [-1, 1] \text{ if } \beta_j = 0 \}\). By additivity of subdifferentials, \(\partial(f + \lambda \|\cdot\|_1)(\beta) = \nabla f(\beta) + \lambda \partial \|\beta\|_1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Why Subgradient Struggles to Produce Exact Zeros:&lt;/strong&gt; Unlike proximal soft-thresholding (Chapter 09), a raw subgradient step \(\beta^{(k)} = \beta^{(k-1)} - t_k(\nabla f(\beta^{(k-1)}) + \lambda v^{(k-1)})\) rarely lands &lt;em&gt;exactly&lt;/em&gt; on \(\beta_j = 0\); instead, inactive coordinates jitter back and forth around zero at amplitude \(O(t_k \lambda)\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 4 — Lipschitz Constant of the Composite Objective:&lt;/strong&gt; Because $$&lt;/td&gt;
          &lt;td&gt;p_i(\beta) - y_i&lt;/td&gt;
          &lt;td&gt;\le 1\(, the smooth gradient is globally bounded by\)\sum_{i=1}^n |x_i|&lt;em&gt;2\(, and every subgradient of\)\lambda |\beta|_1\(has norm at most\)\lambda \sqrt{p}\(. Thus the entire objective is globally\)G\(-Lipschitz with\)G \le \sum&lt;/em&gt;{i=1}^n |x_i|_2 + \lambda\sqrt{p}$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-subgradient-update-on-a-2-sample-logistic-model&quot;&gt;Worked example: One Subgradient Update on a 2-Sample Logistic Model&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider \(n = 2\) data points in \(\mathbb{R}^2\): \((x_1, y_1) = ((1, 0)^\top, 1)\) and \((x_2, y_2) = ((0, 1)^\top, 0)\), with regularization \(\lambda = 0.5\) and objective $$F(\beta) = \sum_{i=1}^2 (-y_i x_i^\top \beta + \log(1 + e^{x_i^\top \beta})) + 0.5(&lt;/td&gt;
      &lt;td&gt;\beta_1&lt;/td&gt;
      &lt;td&gt;+&lt;/td&gt;
      &lt;td&gt;\beta_2&lt;/td&gt;
      &lt;td&gt;)$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Initialize at \(\beta^{(0)} = (0, 0)^\top\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Linear predictors: \(x_1^\top \beta^{(0)} = 0\), \(x_2^\top \beta^{(0)} = 0\).&lt;/li&gt;
      &lt;li&gt;Predicted probabilities: \(p_1 = p_2 = \frac{1}{1 + e^0} = 0.5\).&lt;/li&gt;
      &lt;li&gt;Initial objective: \(F(0, 0) = 2\log(2) + 0 \approx 1.3863\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the smooth gradient \(\nabla f(\beta^{(0)})\):&lt;/strong&gt;
\(\nabla f(0, 0) = (0.5 - 1)\begin{pmatrix}1\\0\end{pmatrix} + (0.5 - 0)\begin{pmatrix}0\\1\end{pmatrix} = \begin{pmatrix}-0.5 \\ 0.5\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choose a subgradient of \(\lambda \|\beta\|_1\) at \(\beta^{(0)} = (0, 0)^\top\):&lt;/strong&gt;
Any \(v \in [-1, 1]^2\) is valid. Notice that choosing \(v = (1, -1)^\top\) gives \(\nabla f(0,0) + 0.5 v = (-0.5, 0.5)^\top + (0.5, -0.5)^\top = (0, 0)^\top\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pause and notice the optimality miracle:&lt;/strong&gt; Because \(0 \in \partial F(0, 0)\), \(\beta^\star = (0, 0)^\top\) is &lt;em&gt;already&lt;/em&gt; the exact global minimizer when \(\lambda = 0.5\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;What if we carelessly picked \(v = (0, 0)^\top \in \partial \|\beta^{(0)}\|_1\)?&lt;/strong&gt; With step size \(t_1 = 0.2\), we would move to \(\beta^{(1)} = (0, 0) - 0.2(-0.5, 0.5) = (0.1, -0.1)\), where \(F(0.1, -0.1) = (-0.1 + \log(1+e^{0.1})) + \log(1+e^{-0.1}) + 0.5(0.2) \approx 0.6444 + 0.6444 + 0.1 = 1.3888 &amp;gt; 1.3863\). This demonstrates both how subgradient choice matters at kinks and why proximal methods are preferred for exact sparsity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Suppose \((x_i, y_i) \in \mathbb{R}^p \times \{0, 1\}\) for \(i=1,...,n\). The logistic regression loss is defined as:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
f(\beta) = \sum_{i=1}^n\big(-y_ix_i^T\beta + \log(1+\exp(x_i^T\beta))\big)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This function is a finite sum of a linear function and a log-sum-exp function, so it is a differentiable convex function.&lt;/p&gt;

&lt;p&gt;Now, the regularization problem for \(\beta\) is formulated as:&lt;/p&gt;

&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\min_{\beta} \text{ } f(\beta) + \lambda \cdot P(\beta)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, \(P(\beta)\) can be defined as \(\Vert \beta \Vert _2^2\) (ridge penalty) or \(\Vert \beta \Vert _1\) (lasso penalty).&lt;/p&gt;

&lt;p&gt;The loss function with ridge penalty remains a differentiable convex function, but the loss function with lasso penalty becomes a nondifferentiable convex function. For these two loss functions, we can apply gradient descent for ridge and the subgradient method for lasso, and by plotting the objective function value at iteration \(k\), we can observe the convergence characteristics of both methods.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter08/08_01_grad_vs_subgrad.png&quot; alt=&quot;grad_vs_subgrad&quot; width=&quot;90%&quot; height=&quot;90%&quot; /&gt;
&lt;/p&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Gradient descent vs Subgradient method [3]&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;This experiment shows that gradient descent converges much faster than the subgradient method.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-04 Convergence rate</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_04_convergence_rate/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_04_convergence_rate</id>
   <content type="html">&lt;p&gt;Knowing that an algorithm eventually converges is reassuring in theory, but in engineering practice the decisive question is: &lt;em&gt;how many iterations will it take to get within \(\varepsilon = 10^{-3}\) of the optimum?&lt;/em&gt; In smooth gradient descent, cutting \(\varepsilon\) by a factor of \(10\) costs \(10\times\) more iterations (\(O(1/\varepsilon)\)); in the subgradient method, cutting \(\varepsilon\) by a factor of \(10\) costs \(100\times\) more iterations (\(O(1/\varepsilon^2)\)). This lesson derives that famous quadratic penalty directly from the basic inequality and shows why it is not a flaw in our proof, but a fundamental speed limit of nonsmooth geometry.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-deriving-the-o1varepsilon2-complexity-barrier&quot;&gt;Key ideas: Deriving the \(O(1/\varepsilon^2)\) Complexity Barrier&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Optimizing the Fixed Step Size for a Known Horizon \(k\):&lt;/strong&gt; Minimizing \(B(t) = \frac{R^2}{2kt} + \frac{G^2 t}{2}\) over \(t &amp;gt; 0\) by setting \(B&apos;(t) = 0\) yields the optimal horizon-dependent step \(t^\star = \frac{R}{G\sqrt{k}}\) and the tightest upper bound \(f_{\text{best}}^{(k)} - f^\star \le \frac{RG}{\sqrt{k}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Translating Error Bound to Iteration Complexity:&lt;/strong&gt; Setting \(\frac{RG}{\sqrt{k}} \le \varepsilon\) and solving for \(k\) gives \(k \ge \frac{R^2 G^2}{\varepsilon^2}\). Every extra decimal digit of accuracy multiplies the iteration budget by \(100\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Horizon-Free \(1/\sqrt{k}\) Schedules:&lt;/strong&gt; When the total number of iterations \(k\) is unknown in advance, choosing \(t_i = \frac{R}{G\sqrt{i}}\) (which is &lt;em&gt;not&lt;/em&gt; square-summable, yet \(\sum_{i=1}^k 1/i \approx \ln k\) while \(\sum_{i=1}^k 1/\sqrt{i} \approx 2\sqrt{k}\)) still achieves \(O\!\left(\frac{\ln k}{\sqrt{k}}\right)\), far faster than \(t_i = 1/i\) which gives only \(O(1/\ln k)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Information-Theoretic Lower Bound (Nesterov / Nemirovski–Yudin):&lt;/strong&gt; For high-dimensional nonsmooth convex functions (\(n \ge k\)), &lt;em&gt;no&lt;/em&gt; first-order black-box method using only subgradients can beat \(\Omega(RG/\sqrt{k})\) in the worst case—so to go faster, one must exploit extra problem structure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-optimizing-t-and-counting-iterations-for-varepsilon--001&quot;&gt;Worked example: Optimizing \(t\) and Counting Iterations for \(\varepsilon = 0.01\)&lt;/h3&gt;

&lt;p&gt;Suppose \(R = 5\) and \(G = 2\), and we want to guarantee \(f_{\text{best}}^{(k)} - f^\star \le \varepsilon\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Derive the optimal constant step size for a fixed budget \(k\):&lt;/strong&gt;
\(\frac{d}{dt}\left(\frac{R^2}{2kt} + \frac{G^2 t}{2}\right) = -\frac{R^2}{2kt^2} + \frac{G^2}{2} = 0 \implies t^\star = \frac{R}{G\sqrt{k}} = \frac{5}{2\sqrt{k}}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Substitute \(t^\star\) back into the bound:&lt;/strong&gt;
\(f_{\text{best}}^{(k)} - f^\star \le \frac{R^2}{2k \cdot \frac{R}{G\sqrt{k}}} + \frac{G^2}{2} \cdot \frac{R}{G\sqrt{k}} = \frac{RG}{2\sqrt{k}} + \frac{RG}{2\sqrt{k}} = \frac{RG}{\sqrt{k}} = \frac{10}{\sqrt{k}}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute iterations needed for \(\varepsilon = 0.1\) vs. \(\varepsilon = 0.01\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;For \(\varepsilon = 0.1\): \(\frac{10}{\sqrt{k}} \le 0.1 \implies \sqrt{k} \ge 100 \implies k = 10{,}000\) iterations, with \(t^\star = \frac{5}{2 \cdot 100} = 0.025\).&lt;/li&gt;
      &lt;li&gt;For \(\varepsilon = 0.01\): \(\frac{10}{\sqrt{k}} \le 0.01 \implies \sqrt{k} \ge 1000 \implies k = 1{,}000{,}000\) iterations, with \(t^\star = \frac{5}{2 \cdot 1000} = 0.0025\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Contrast with smooth gradient descent (\(O(1/\varepsilon)\)):&lt;/strong&gt; Improving accuracy \(10\times\) (from \(0.1\) to \(0.01\)) multiplied the subgradient budget by \(100\times\) (from \(10^4\) to \(10^6\)), explaining why subgradient methods excel at low-to-medium precision and struggle at high precision.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The convergence rate describes how the number of iterations required to reach an \(\epsilon\)-suboptimal point depends on \(\epsilon\), using &lt;a href=&quot;https://en.wikipedia.org/wiki/Big_O_notation&quot;&gt;Big-O notation&lt;/a&gt;. For example, if \(\epsilon = 10^{-2}\) and the convergence rate is \(O(1/\epsilon)\), then about \(1/10^{-2}=10^2\) iterations are needed.&lt;/p&gt;

&lt;p&gt;Let’s use &lt;a href=&quot;/contents/en/chapter08/08_01_02_basic_inequality/&quot;&gt;08-01-02 Basic inequality&lt;/a&gt; to derive the convergence rate for the subgradient method with fixed step sizes.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(Recall:\)
\begin{align}
f^{k}_{best} - f^{*} \quad \le \quad \frac{R^{2}}{2kt} + \frac{G^{2}t}{2}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Suppose \(\epsilon\) satisfies \(\frac{R^{2}}{2kt} \le \frac{\epsilon}{2}\) and \(\frac{G^{2}t}{2} \le \frac{\epsilon}{2}\) (where \(\epsilon\) is the suboptimality gap, \(G\) is the Lipschitz constant, and \(R\) is the distance between the starting point and the optimal point). Then \(\frac{R^{2}}{2kt} + \frac{G^{2}t}{2} \le \epsilon\). If \(\frac{G^{2}t}{2} \le \frac{\epsilon}{2}\), then \(t \le \frac{\epsilon}{G^{2}}\), and \(\frac{R^{2}}{2kt} \le \frac{\epsilon}{2}\) leads to \(\frac{R^2G^2}{\epsilon^2} \le k\). This means the number of iterations required is at least \(\frac{R^2G^2}{\epsilon^2}\) to achieve \(f^{k}_{best} - f^{*} \le \epsilon\).&lt;/p&gt;

&lt;p&gt;The convergence rate of this algorithm is \(O(1/\epsilon^2)\), which means it requires significantly more iterations than the gradient descent method, which has a rate of \(O(1/\epsilon)\).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-03 Convergence analysis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_03_convergence_analysis/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_03_convergence_analysis</id>
   <content type="html">&lt;p&gt;In smooth optimization, Lipschitz continuity of the &lt;em&gt;gradient&lt;/em&gt; \(\nabla f\) caps how sharply the slope can bend, giving gradient descent a smooth quadratic upper bound to descend along. When \(f\) has corners, \(\nabla f\) does not even exist—so we step down one derivative and assume instead that \(f\) itself is \(G\)-Lipschitz continuous. That single change of assumption explains the entire qualitative gap between smooth and nonsmooth convergence guarantees.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-lipschitz-functions-to-convergence-theorems&quot;&gt;Key ideas: From Lipschitz Functions to Convergence Theorems&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 1 — \(G\)-Lipschitz Continuity Equals Bounded Subgradients:&lt;/strong&gt; For a convex function on \(\mathbb{R}^n\), $$&lt;/td&gt;
          &lt;td&gt;f(x) - f(y)&lt;/td&gt;
          &lt;td&gt;\le G|x - y|_2\(holds if and only if every subgradient satisfies\)|g|_2 \le G\(. This guarantees that the squared-norm penalty\)t_k^2 |g^{(k)}|_2^2\(in the basic inequality is uniformly capped by\)G^2 t_k^2$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Constant Step Size Limit (\(G^2 t / 2\) Floor):&lt;/strong&gt; Plugging \(t_i = t\) into the basic inequality gives \(f_{\text{best}}^{(k)} - f^\star \le \frac{R^2}{2kt} + \frac{G^2 t}{2}\). As \(k \to \infty\), the initial-distance term vanishes at rate \(O(1/k)\), leaving an irreducible bias floor of \(G^2 t / 2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Asymptotic Convergence Under Diminishing Step Sizes:&lt;/strong&gt; When \(\sum_{i=1}^\infty t_i = \infty\) and \(\sum_{i=1}^\infty t_i^2 = S &amp;lt; \infty\), the numerator \(R^2 + G^2 S\) stays bounded while the denominator \(2\sum_{i=1}^k t_i\) diverges to \(\infty\), forcing \(\lim_{k\to\infty} f_{\text{best}}^{(k)} = f^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Bias–Variance Trade-off in Step Selection:&lt;/strong&gt; A larger fixed step \(t\) crushes the transient term \(R^2/(2kt)\) quickly but leaves a larger steady-state error \(G^2 t/2\); a smaller \(t\) shrinks the steady-state error at the cost of a longer transient phase.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-the-exact-convergence-floor-and-horizon&quot;&gt;Worked example: Computing the Exact Convergence Floor and Horizon&lt;/h3&gt;

&lt;p&gt;Suppose a \(G\)-Lipschitz convex function has \(G = 4\), initial distance \(R = \|x^{(1)} - x^\star\|_2 = 10\), and we run the subgradient method with a fixed step size \(t = 0.05\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the asymptotic error floor:&lt;/strong&gt;
\(\frac{G^2 t}{2} = \frac{4^2 \cdot 0.05}{2} = \frac{16 \cdot 0.05}{2} = 0.40.\)
No matter how many iterations we run with \(t = 0.05\), the theorem only guarantees \(f_{\text{best}}^{(k)} - f^\star \le 0.40\) in the limit.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the transient term at \(k = 250\) iterations:&lt;/strong&gt;
\(\frac{R^2}{2kt} = \frac{10^2}{2 \cdot 250 \cdot 0.05} = \frac{100}{25} = 4.00.\)
Total guaranteed gap at \(k = 250\): \(4.00 + 0.40 = 4.40\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Balance both terms at \(k = 2500\) iterations:&lt;/strong&gt;
\(\frac{R^2}{2kt} = \frac{100}{2 \cdot 2500 \cdot 0.05} = \frac{100}{250} = 0.40.\)
At \(k = 2500\), the transient error equals the steady-state floor, giving \(f_{\text{best}}^{(2500)} - f^\star \le 0.40 + 0.40 = 0.80\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with diminishing step size \(t_i = 1/i\) at \(k = 100\):&lt;/strong&gt; Using \(\sum_{i=1}^{100} 1/i \approx 5.187\) and \(\sum_{i=1}^{100} 1/i^2 &amp;lt; \pi^2/6 \approx 1.645\), the bound is:
\(f_{\text{best}}^{(100)} - f^\star \le \frac{100 + 16(1.645)}{2(5.187)} \approx \frac{126.32}{10.374} \approx 12.18,\)
which eventually vanishes as \(k \to \infty\), though very slowly because \(\sum 1/i \approx \ln k\) grows only logarithmically!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In gradient descent, it is assumed that \(\nabla f\) is Lipschitz continuous, but in the subgradient method, we assume that \(f\) itself is Lipschitz continuous. (See the convergence theorem for gradient descent &lt;a href=&quot;#post-not-found&quot;&gt;06-03-01&lt;/a&gt; for reference.)&lt;/p&gt;

&lt;p&gt;Assume \(f\) is convex, dom \(f = \mathbb{R}^n\), and \(f\) satisfies the Lipschitz condition:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
| f(x) - f(y) | \le G \lVert x - y \rVert_2 \text{ for all } x, y
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Given these assumptions, the convergence formulas for fixed and diminishing step sizes are as follows:&lt;/p&gt;

&lt;h2 id=&quot;convergence-theorem-for-fixed-step-sizes&quot;&gt;Convergence theorem for fixed step sizes&lt;/h2&gt;

&lt;p&gt;Fixed step sizes have the following convergence property:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\lim_{k\to\infty} f(x^{(k)}_{best}) \le f^* + \frac{G^{2}t}{2}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;convergence-theorem-for-diminishing-step-sizes&quot;&gt;Convergence theorem for diminishing step sizes&lt;/h2&gt;

&lt;p&gt;The diminishing step sizes method has the following convergence property:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\lim_{k\to\infty}f(x^{(k)}_{best}) = f^*
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;proofs&quot;&gt;Proofs&lt;/h2&gt;

&lt;p&gt;The proofs for fixed and diminishing step sizes are as follows.&lt;/p&gt;

&lt;h2 id=&quot;proof-of-convergence-theorem-for-fixed-step-sizes&quot;&gt;Proof of convergence theorem for fixed step sizes&lt;/h2&gt;

&lt;p&gt;The fixed step size method uses \(\sum_{i=1}^{k}t_{i} = kt\) in its proof.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; f_{best}^{(k)} - f^* \le \frac{R^{2}+G^{2}\sum_{i=1}^{k}t_{i}^{2}}{2\sum_{i=1}^{k}t_{i}} = \frac{R^{2}+G^{2}k t^{2}}{2kt}  = \frac{R^{2}}{2tk} + \frac{G^{2}t}{2} \\
&amp;amp; \lim_{k→\infty}(f^{(k)}_{best} - f^*) \le 0 + \frac{G^{2}t}{2} = \frac{G^{2}t}{2} \\
&amp;amp; \lim_{k→\infty}(f^{(k)}_{best}) \le f^* + \frac{G^{2}t}{2}
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;proof-of-convergence-theorem-for-diminishing-step-sizes&quot;&gt;Proof of convergence theorem for diminishing step sizes&lt;/h2&gt;

&lt;p&gt;The proof for the diminishing step sizes uses the following properties (1) and (2):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{(1)} \sum_{i=1}^{\infty} t_i = \infty, \quad \text{(2)}  \sum_{i=1}^{\infty} t_i^{2} = \beta &amp;lt; \infty
\end{align}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; f_{best}^{(k)} - f^* \le \frac{R^{2}+G^{2}\sum_{i=1}^{k}t_{i}^{2}}{2\sum_{i=1}^{k}t_{i}} \\
&amp;amp; \lim_{k→\infty}(f^{(k)}_{best} - f^* ) \le \frac{R^{2}+G^{2}\beta}{2\infty} = 0 \\
&amp;amp; \lim_{k→\infty}(f^{(k)}_{best}) =  f^* \\
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-02 Basic Inequality</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_02_basic_inequality/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_02_basic_inequality</id>
   <content type="html">&lt;p&gt;Every major theorem in Chapter 08—convergence under fixed step sizes, diminishing step sizes, optimal \(O(1/\varepsilon^2)\) rates, and even Polyak’s adaptive rule—flows from a single, five-line algebraic master key called the &lt;strong&gt;basic inequality&lt;/strong&gt;. Rather than proving each step-size rule from scratch, Shor and Polyak discovered that expanding the squared Euclidean distance \(\|x^{(k+1)} - x^\star\|_2^2\) and telescoping across iterations traps the entire trajectory in one clean ratio. Mastering this single inequality lets you derive every convergence bound in nonsmooth optimization on the back of an envelope.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-mechanics-of-the-basic-inequality&quot;&gt;Key ideas: The Mechanics of the Basic Inequality&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Squared-Distance Expansion:&lt;/strong&gt; Expanding \(\|x^{(k+1)} - x^\star\|_2^2 = \|x^{(k)} - \alpha_k g^{(k)} - x^\star\|_2^2\) splits the update into three pieces: previous distance \(\|x^{(k)} - x^\star\|_2^2\), a helpful cross-term \(-2\alpha_k g^{(k)\top}(x^{(k)} - x^\star)\), and a quadratic overshoot penalty \(+\alpha_k^2 \|g^{(k)}\|_2^2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — The Subgradient Bridge:&lt;/strong&gt; Applying convexity \(g^{(k)\top}(x^{(k)} - x^\star) \ge f(x^{(k)}) - f^\star\) converts the geometric inner product directly into an objective suboptimality gap, coupling Euclidean space to function values.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Telescoping Cancellation:&lt;/strong&gt; Summing the one-step recursion from \(i = 1\) to \(k\) causes all intermediate distances \(\|x^{(i)} - x^\star\|_2^2\) to cancel in pairs, leaving only the initial squared radius \(R^2 \ge \|x^{(1)} - x^\star\|_2^2\) minus the nonnegative final distance \(\|x^{(k+1)} - x^\star\|_2^2 \ge 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Weighted Average to Best-Iterate Bound:&lt;/strong&gt; Because \(\sum_{i=1}^k \alpha_i (f(x^{(i)}) - f^\star) \ge \left(\sum_{i=1}^k \alpha_i\right)(f_{\text{best}}^{(k)} - f^\star)\), dividing by \(2\sum \alpha_i\) immediately isolates \(f_{\text{best}}^{(k)} - f^\star\) as a competition between initial distance \(R^2\) and accumulated step variance \(G^2 \sum \alpha_i^2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-the-basic-inequality-numerically&quot;&gt;Worked example: Verifying the Basic Inequality Numerically&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Take $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((\)x^\star = 0, f^\star = 0, G = 1\(), starting at\)x^{(1)} = 1\((so\)R =&lt;/td&gt;
      &lt;td&gt;1 - 0&lt;/td&gt;
      &lt;td&gt;= 1\(), with\)k = 2\(steps using\)\alpha_1 = 0.6\(and\)\alpha_2 = 0.4$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Run the two iterations explicitly:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Step 1: \(g^{(1)} = 1\), so \(x^{(2)} = 1 - 0.6(1) = 0.4\). Objective values so far: \(f(x^{(1)}) = 1\), \(f(x^{(2)}) = 0.4\).&lt;/li&gt;
      &lt;li&gt;Step 2: \(g^{(2)} = 1\), so \(x^{(3)} = 0.4 - 0.4(1) = 0.0\).&lt;/li&gt;
      &lt;li&gt;The best value among \(\{x^{(1)}, x^{(2)}\}\) (the iterates entering the sum \(i=1,2\)) is \(f_{\text{best}}^{(2)} = \min\{1, 0.4\} = 0.4\), so \(f_{\text{best}}^{(2)} - f^\star = 0.4\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the telescoping sum directly:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\|x^{(1)} - x^\star\|^2 - \|x^{(3)} - x^\star\|^2 = 1^2 - 0^2 = 1\).&lt;/li&gt;
      &lt;li&gt;Weighted suboptimality sum: \(2\sum_{i=1}^2 \alpha_i (f(x^{(i)}) - f^\star) = 2[0.6(1) + 0.4(0.4)] = 2(0.76) = 1.52\).&lt;/li&gt;
      &lt;li&gt;Accumulated squared-step term: \(\sum_{i=1}^2 \alpha_i^2 \|g^{(i)}\|^2 = 0.6^2(1) + 0.4^2(1) = 0.36 + 0.16 = 0.52\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Check the exact identity: \(1.52 = 1 + 0.52\) (exact equality here because $$f(x) =&lt;/td&gt;
              &lt;td&gt;x&lt;/td&gt;
              &lt;td&gt;\(is linear on\)x &amp;gt; 0$$!).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the Basic Inequality RHS:&lt;/strong&gt;
\(\frac{R^2 + G^2(\alpha_1^2 + \alpha_2^2)}{2(\alpha_1 + \alpha_2)} = \frac{1 + 1(0.36 + 0.16)}{2(0.6 + 0.4)} = \frac{1.52}{2.0} = 0.76.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify:&lt;/strong&gt; Indeed \(f_{\text{best}}^{(2)} - f^\star = 0.4 \le 0.76\), and the slack \(0.76 - 0.4 = 0.36\) comes purely from replacing the weighted average \((0.6 \cdot 1 + 0.4 \cdot 0.4)/1.0 = 0.76\) with the minimum \(0.4\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The convergence theorem and convergence rate of the subgradient method can be proved using the following basic inequality.&lt;/p&gt;

&lt;h2 id=&quot;basic-inequality&quot;&gt;Basic Inequality&lt;/h2&gt;

&lt;blockquote&gt;
\[\begin{align}
f_{best}^{k} - f^* \quad \le \quad \frac{R^{2}+G^{2}\sum_{i=1}^{k}\alpha_{i}^{2}}{2\sum_{i=1}^{k}\alpha_{i}} 
\end{align}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;proof&quot;&gt;Proof&lt;/h2&gt;
&lt;p&gt;If \(x^*\) is the optimal point of the function \(f\), then the following equation holds:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
 \Vert x^{(k+1)}-x^* \Vert _2^{2} &amp;amp; \quad = \quad  \Vert x^{(k)}-\alpha_k g^{(k)}-x^* \Vert _2^{2}  \\
                                   &amp;amp; \quad = \quad  \Vert (x^{(k)}-x^*)-\alpha_k g^{(k)} \Vert _2^{2}  \\
                                   &amp;amp; \quad = \quad  \Vert x^{(k)}-x^* \Vert _2^2 - 2 \alpha_k g^{(k)T}(x^{(k)}-x^*)+\alpha_k^2 \Vert g^{(k)} \Vert _2^2 \\
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;From the definition of subgradient, the following inequality holds:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{alignat}{1}
f(x^*) \ge f(x^{(k)}) + g^{(k)T}(x^*-x^{(k)}) &amp;amp; \quad \Longleftrightarrow \quad f(x^*)-f(x^{(k)}) \ge  g^{(k)T}(x^*-x^{(k)}) \\
                     &amp;amp; \quad  \Longleftrightarrow \quad f(x^{(k)} - f(x^*)) \le  g^{(k)T}(x^{(k)}-x^*) \\
                     &amp;amp; \quad \Longleftrightarrow \quad -2\alpha_{k}(f(x^{(k)}) - f(x^*)) \ge  -2\alpha_{k}(g^{(k)T}(x^{(k)}-x^*)) \\
                     &amp;amp; \quad \Longleftrightarrow \quad -2\alpha_{k}(g^{(k)T}(x^{(k)}-x^*)) \le -2\alpha_{k}(f(x^{(k)})-f(x^*)) \\
\end{alignat}\]
&lt;/blockquote&gt;

&lt;p&gt;Using the above equations and inequalities, the following inequality can be derived:&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01-01 Step size choices</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_01_step_size_choices/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_01_01_step_size_choices</id>
   <content type="html">&lt;p&gt;Imagine trying to park a car at the exact bottom of a V-shaped ramp where the accelerator only has two settings: full forward or full reverse. If your stride length stays fixed forever, you will hop back and forth across the bottom indefinitely without ever landing on it; if you shrink your stride too fast, you will stall halfway down the ramp and never reach the bottom. Choosing step sizes \(t_k\) in the subgradient method is the exact mathematical balancing act between reaching the optimum from any distance and damping out the oscillations once you arrive.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-step-size-schedules-in-nonsmooth-optimization&quot;&gt;Key ideas: Step-Size Schedules in Nonsmooth Optimization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 1 — Non-Vanishing Subgradients Near \(x^\star\):&lt;/strong&gt; Unlike smooth gradients that shrink continuously to \(0\) as \(x \to x^\star\), subgradients of nonsmooth functions like $$&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;\(maintain norm\)1\(arbitrarily close to the minimizer. Fixed step sizes therefore create a permanent residual error neighborhood around\)f^\star$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — The Infinite-Travel Condition (\(\sum_{k=1}^\infty t_k = \infty\)):&lt;/strong&gt; Because the starting point \(x^{(0)}\) may lie arbitrarily far from \(x^\star\), the total accumulated step length must diverge so the algorithm can traverse any finite initial distance \(R = \|x^{(0)} - x^\star\|_2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — The Square-Summable Noise Condition (\(\sum_{k=1}^\infty t_k^2 &amp;lt; \infty\)):&lt;/strong&gt; The overshoot error accumulated from non-vanishing subgradient norms scales with \(\sum_{k=1}^K t_k^2 G^2\). Requiring this series to converge guarantees that the error ratio \(\frac{\sum t_k^2}{\sum t_k} \to 0\), ensuring exact convergence \(f_{\text{best}}^{(k)} \to f^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Constant Step Length vs. Constant Step Size:&lt;/strong&gt; Scaling the step by the subgradient norm (\(t_k = \gamma / \|g^{(k-1)}\|_2\)) keeps the Euclidean displacement \(\|x^{(k)} - x^{(k-1)}\|_2 = \gamma\) uniform across steep and flat regions, preventing wild jumps when \(\|g\|\) is large.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-fixed-vs-diminishing-step-sizes-on-fx--x&quot;&gt;Worked example: Fixed vs. Diminishing Step Sizes on \(f(x) = |x|\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Let $$f(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((\)x^\star = 0, f^\star = 0\(), starting at\)x^{(0)} = 0.7\(, using subgradient\)g(x) = \operatorname{sign}(x)\((with\)g(0) = 0$$).&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fixed step size \(t_k = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(k=1\): \(x^{(1)} = 0.7 - 0.5(1) = 0.2\) (\(f = 0.2\)).&lt;/li&gt;
      &lt;li&gt;\(k=2\): \(x^{(2)} = 0.2 - 0.5(1) = -0.3\) (\(f = 0.3\)).&lt;/li&gt;
      &lt;li&gt;\(k=3\): \(x^{(3)} = -0.3 - 0.5(-1) = 0.2\) (\(f = 0.2\)).&lt;/li&gt;
      &lt;li&gt;The iterates enter a permanent 2-cycle \(0.2 \leftrightarrow -0.3\); \(f_{\text{best}}^{(k)}\) stalls at \(0.2 \le \frac{G^2 t}{2} = \frac{1^2 \cdot 0.5}{2} = 0.25\) and never reaches \(0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diminishing step size \(t_k = 1/k\) (satisfies \(\sum 1/k = \infty\) and \(\sum 1/k^2 = \pi^2/6 &amp;lt; \infty\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(k=1\) (\(t_1 = 1\)): \(x^{(1)} = 0.7 - 1(1) = -0.3\) (\(f = 0.3\)).&lt;/li&gt;
      &lt;li&gt;\(k=2\) (\(t_2 = 0.5\)): \(x^{(2)} = -0.3 - 0.5(-1) = 0.2\) (\(f = 0.2\)).&lt;/li&gt;
      &lt;li&gt;\(k=3\) (\(t_3 = 1/3\)): \(x^{(3)} = 0.2 - \frac{1}{3}(1) = -\frac{2}{15} \approx -0.133\) (\(f \approx 0.133\)).&lt;/li&gt;
      &lt;li&gt;\(k=4\) (\(t_4 = 0.25\)): \(x^{(4)} = -\frac{2}{15} + \frac{1}{4} = \frac{7}{60} \approx 0.117\) (\(f \approx 0.117\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with a too-fast schedule \(t_k = 2^{-k}\) (\(\sum 2^{-k} = 1 &amp;lt; \infty\)):&lt;/strong&gt; Starting from \(x^{(0)} = 2.0\), the maximum possible total movement is \(\sum_{k=1}^\infty 2^{-k} = 1\), so \(x^{(k)} &amp;gt; 1\) forever and the method stalls at \(f(x) \ge 1\)—illustrating why \(\sum t_k = \infty\) is indispensable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are various ways to choose the &lt;strong&gt;step size&lt;/strong&gt; in the subgradient method.&lt;/p&gt;

&lt;p&gt;Let’s take a closer look at the following two approaches:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Fixed step sizes&lt;/strong&gt;: \(t_k = t\), where \(k = 1, 2, 3, ...\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diminishing step sizes&lt;/strong&gt;: \(t_k\) that satisfy the following conditions:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\sum_{k=1}^{\infty} t_k = \infty, \quad \sum_{k=1}^{\infty} t_k^{2} &amp;lt; \infty
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;example-of-diminishing-step-sizes&quot;&gt;Example of Diminishing step sizes&lt;/h3&gt;

&lt;blockquote&gt;
\[\begin{align}
&amp;amp; t_k = \frac{1}{k}, k = 1,2,3,... \\
&amp;amp; \sum_{k=1}^{\infty}t_k = \infty \quad \text{(Harmonic  series)} \\
&amp;amp; \sum_{k=1 }^{\infty}t^2_k \approx 1.644934 &amp;lt; \infty \quad \text{(Basel problem)} \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;A key feature of the step size in the subgradient method is that it must be set in advance, unlike in gradient descent. In other words, unlike the backtracking line search in gradient descent, the step size in the subgradient method does not adapt to the curvature of the function.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>08 Subgradient Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_00_subgradient_method/"/>
   <updated>2020-03-29T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter08/08_00_subgradient_method</id>
   <content type="html">&lt;p&gt;Picture yourself hiking down a foggy mountain ridge whose terrain is not a smooth granite dome, but a folded landscape of razor-sharp V-shaped valleys and intersecting cliff faces. In smooth calculus, a compass needle pointing opposite the gradient always aims locally downhill; on a sharp crease, however, no single tangent plane exists, and the naive gradient compass breaks down completely. The &lt;strong&gt;subgradient method&lt;/strong&gt;—pioneered in the Soviet optimization school by Naum Shor, Boris Polyak, and Arkadi Nemirovski in the 1960s and 1970s—is the minimalist yet remarkably resilient toolkit that lets us navigate these nonsmooth convex landscapes without ever differentiating across a kink.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-navigating-nonsmooth-convex-landscapes&quot;&gt;Key ideas: Navigating Nonsmooth Convex Landscapes&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Subgradients &amp;amp; Supporting Hyperplanes:&lt;/strong&gt; At a kink where a convex function \(f\) fails to be differentiable, a subgradient \(g \in \partial f(x)\) defines a global linear underestimator \(f(y) \ge f(x) + g^\top (y - x)\). Rather than requiring local smoothness, this single inequality is strong enough to pull iterates closer to the optimal set in Euclidean distance.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Non-Monotonic Progress &amp;amp; Best-Iterate Tracking:&lt;/strong&gt; Unlike gradient descent, a negative subgradient \(-g\) is not guaranteed to be a descent direction; the objective \(f(x^{(k)})\) can temporarily increase even for tiny step sizes. Consequently, the method relies on tracking the running best iterate \(f_{\text{best}}^{(k)} = \min_{0 \le i \le k} f(x^{(i)})\) and measuring progress via distance to \(x^\star\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 3 — Step-Size Geometry (Fixed, Diminishing, and Polyak):&lt;/strong&gt; Because subgradients do not necessarily vanish as \(x^{(k)} \to x^\star\) (think of $$&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;\(whose subgradient has magnitude\)1\(arbitrarily close to\)0\(), step sizes must either shrink slowly (\)\sum t_k = \infty, \sum t_k^2 &amp;lt; \infty$$) or adapt using known optimal values (Polyak’s rule) to prevent perpetual oscillation.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Complexity Frontier (\(O(1/\varepsilon^2)\)):&lt;/strong&gt; Under only convexity and \(G\)-Lipschitz continuity, the subgradient method achieves \(\varepsilon\)-suboptimality in \(O(G^2 R^2 / \varepsilon^2)\) iterations. This rate is information-theoretically optimal for black-box nonsmooth convex optimization, motivating the structured composite methods (proximal gradient) studied in Chapter 09.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-subgradient-step-can-increase-f-yet-shrink-distance-to-xstar&quot;&gt;Worked example: One Subgradient Step Can Increase \(f\) Yet Shrink Distance to \(x^\star\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider the nonsmooth convex function on \(\mathbb{R}^2\) given by $$f(x_1, x_2) =&lt;/td&gt;
      &lt;td&gt;x_1&lt;/td&gt;
      &lt;td&gt;+ 2&lt;/td&gt;
      &lt;td&gt;x_2&lt;/td&gt;
      &lt;td&gt;\(, whose unique minimizer is\)x^\star = (0, 0)\(with\)f^\star = 0$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Choose a starting point on a kink:&lt;/strong&gt; Let \(x^{(0)} = (1, 0)\). Here $$f(x^{(0)}) =&lt;/td&gt;
          &lt;td&gt;1&lt;/td&gt;
          &lt;td&gt;+ 2&lt;/td&gt;
          &lt;td&gt;0&lt;/td&gt;
          &lt;td&gt;= 1\(, and the squared distance to the optimum is\)|x^{(0)} - x^\star|_2^2 = 1^2 + 0^2 = 1$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Compute the subdifferential at \(x^{(0)} = (1, 0)\):&lt;/strong&gt; Since \(x_1 = 1 &amp;gt; 0\), the first coordinate has unique derivative \(1\). Since \(x_2 = 0\), the subdifferential of $$2&lt;/td&gt;
          &lt;td&gt;x_2&lt;/td&gt;
          &lt;td&gt;\(is the interval\)[-2, 2]\(. Hence\)\partial f(1, 0) = { (1, v) : v \in [-2, 2] }$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pick a valid subgradient and take a step:&lt;/strong&gt; Select \(g^{(0)} = (1, 2) \in \partial f(1, 0)\) and step size \(t_1 = 0.25\). The update yields:
\(x^{(1)} = (1, 0) - 0.25(1, 2) = (0.75, -0.5).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare objective value vs. distance to \(x^\star\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;New objective value: $$f(x^{(1)}) =&lt;/td&gt;
              &lt;td&gt;0.75&lt;/td&gt;
              &lt;td&gt;+ 2&lt;/td&gt;
              &lt;td&gt;-0.5&lt;/td&gt;
              &lt;td&gt;= 0.75 + 1.0 = 1.75 &amp;gt; 1 = f(x^{(0)})$$. The function value &lt;em&gt;strictly increased&lt;/em&gt;!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;New squared distance to \(x^\star\): \(\|x^{(1)} - x^\star\|_2^2 = 0.75^2 + (-0.5)^2 = 0.5625 + 0.25 = 0.8125 &amp;lt; 1 = \|x^{(0)} - x^\star\|_2^2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Key takeaway:&lt;/strong&gt; Even though the objective rose from \(1\) to \(1.75\), the iterate moved strictly closer to the true minimizer \(x^\star\) in Euclidean norm—the exact geometric miracle that powers every convergence proof in Chapter 08.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we will look at the subgradient method, which can be applied to convex functions that may not be differentiable, using the concept of subgradients. We will also explore the convergence properties and rate of the subgradient method with examples.&lt;/p&gt;

&lt;h2 id=&quot;modern-applications-20222026&quot;&gt;Modern applications (2022–2026)&lt;/h2&gt;

&lt;p&gt;An optional companion lesson places the same (projected, stochastic) subgradient loop in adversarial PGD / RobustBench, Fairlearn rate constraints, and nonsmooth ReLU training. See &lt;a href=&quot;/contents/en/chapter08/08_09_modern_applications/&quot;&gt;08-09 Modern applications of the subgradient method&lt;/a&gt;. When the finite-sum objective &lt;em&gt;is&lt;/em&gt; smooth, the \(O(1/\sqrt{T})\) noise floor of this chapter’s stochastic method can be removed by SVRG / SAGA — that lesson is &lt;a href=&quot;/contents/en/chapter26/26_05_variance_reduction/&quot;&gt;26-05&lt;/a&gt;, next to the SGD track.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>04-11 Bài Tập Thực Hành - Bài Toán Tối Ưu Convex</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_11_Practical_Exercises_Convex_Optimization_Problems/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_11_Practical_Exercises_Convex_Optimization_Problems</id>
   <content type="html">&lt;p&gt;Hiểu lý thuyết tối ưu hóa lồi giống như đọc sách dạy bơi trên bờ; chỉ khi tự tay cầm một bài toán thực tế lộn xộn — có giá trị tuyệt đối, có chuẩn, có cực đại lồng nhau, có tham số nhiễu — và biến đổi nó về dạng chuẩn rồi chạy kiểm chứng bằng code, các khái niệm của Chương 04 mới thực sự trở thành kỹ năng của riêng bạn.&lt;/p&gt;

&lt;p&gt;Bộ bài tập thực hành này dẫn bạn đi qua năm kỹ năng cốt lõi của một kỹ sư tối ưu hóa: chuyển đổi dạng chuẩn, phân tích điều kiện tối ưu, độ nhạy nghiệm theo tham số ràng buộc, thiết kế nới lỏng cho bài toán khó và mô hình hóa tối ưu bền vững (robust optimization) khi dữ liệu có bất định.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-quy-trình-4-bước-giải-bài-tập-thực-hành-tối-ưu-lồi&quot;&gt;Kiến thức cần nhớ: Quy trình 4 bước giải bài tập thực hành tối ưu lồi&lt;/h2&gt;

&lt;p&gt;Khi đối mặt với bất kỳ bài tập mô hình hóa hay chuyển đổi nào trong bộ bài này, hãy đi theo đúng khung bốn bước:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Bước 1 — Chuẩn hóa ngôn ngữ (Standard Form Canonicalization):&lt;/strong&gt; Đưa mọi cực đại hóa về cực tiểu hóa (\(\max f \iff \min -f\)), chuyển mọi bất đẳng thức \(a \ge b\) về \(b - a \le 0\), và tách các hàm không trơn như $$&lt;/td&gt;
          &lt;td&gt;x_i&lt;/td&gt;
          &lt;td&gt;\(hay\)\max_k (a_k^T x + b_k)$$ bằng cách thêm biến phụ (epigraph reformulation).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Kiểm định tính lồi &amp;amp; Ràng buộc tích cực:&lt;/strong&gt; Xác định rõ hàm nào lồi, hàm nào affine; tìm điểm cực tiểu không ràng buộc trước để biết ràng buộc nào thực sự phải kích hoạt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Phân tích độ nhạy &amp;amp; Đối ngẫu (Sensitivity &amp;amp; Perturbation):&lt;/strong&gt; Khi vế phải ràng buộc thay đổi một lượng nhỏ \(\Delta b\), giá trị tối ưu thay đổi xấp xỉ \(-\lambda^\star \Delta b\) — công cụ cực mạnh để định giá tài nguyên biên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — Xử lý bất định &amp;amp; Phi lồi (Robust &amp;amp; Relaxation):&lt;/strong&gt; Với bài toán có tham số nhiễu trong tập bất định (ví dụ hình cầu \(\|u\|_2 \le \rho\)), dùng bất đẳng thức Cauchy-Schwarz để chuyển ràng buộc “với mọi \(u\)” thành dạng đóng lồi (thường là ràng buộc chuẩn \(\ell_2\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chuyển-đổi-một-bài-toán-có-trị-tuyệt-đối--bất-định-về-dạng-chuẩn-lồi&quot;&gt;Giải thích: Chuyển đổi một bài toán có trị tuyệt đối &amp;amp; bất định về dạng chuẩn lồi&lt;/h3&gt;

&lt;p&gt;Xét bài toán: tìm \(x \in \mathbb{R}^2\) cực tiểu hóa \(f(x) = |x_1 - 2| + 2|x_2 + 1|\) thỏa mãn ràng buộc bền vững
\((a_0 + u)^T x \le 3 \quad \text{với mọi } u \in \mathbb{R}^2 \text{ thỏa } \|u\|_2 \le 0.5, \quad \text{trong đó } a_0 = (1, 1)^T.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khử trị tuyệt đối bằng biến phụ \(t_1, t_2\):&lt;/strong&gt;
Đặt \(|x_1 - 2| \le t_1\) và \(|x_2 + 1| \le t_2\). Tương đương với 4 bất đẳng thức tuyến tính:
\(x_1 - 2 \le t_1,\quad -(x_1 - 2) \le t_1,\quad x_2 + 1 \le t_2,\quad -(x_2 + 1) \le t_2.\)
Hàm mục tiêu trở thành hàm tuyến tính \(t_1 + 2t_2\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển ràng buộc vô hạn “với mọi \(u\)” về dạng đóng lồi:&lt;/strong&gt;
Ràng buộc đúng với mọi \(\|u\|_2 \le 0.5\) khi và chỉ khi giá trị xấu nhất (lớn nhất) cũng \(\le 3\):
\(\max_{\|u\|_2 \le 0.5} (a_0^T x + u^T x) = a_0^T x + 0.5 \|x\|_2 \le 3.\)
(Dấu bằng đạt được theo Cauchy-Schwarz khi \(u = 0.5 \frac{x}{\|x\|_2}\).)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra bài toán dạng chuẩn cuối cùng:&lt;/strong&gt;
\(\min_{x, t} \; t_1 + 2t_2 \quad \text{s.t.} \quad \begin{cases} x_1 - t_1 - 2 \le 0,\; -x_1 - t_1 + 2 \le 0 \\ x_2 - t_2 + 1 \le 0,\; -x_2 - t_2 - 1 \le 0 \\ x_1 + x_2 + 0.5\sqrt{x_1^2 + x_2^2} - 3 \le 0 \end{cases}\)
Mọi hàm đều lồi rõ ràng (thực chất là một bài toán SOCP)! Thử điểm \(x = (2, -1)\): \(x_1 + x_2 + 0.5\sqrt{4+1} = 1 + 0.5\sqrt{5} \approx 2.118 \le 3\), nên \(x^\star = (2, -1)\) khả thi và đạt ngay \(f^\star = 0\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---bài-toán-tối-ưu-hóa-lồi&quot;&gt;Bài Tập Thực Hành - Bài Toán Tối Ưu Hóa Lồi&lt;/h1&gt;

&lt;h2 id=&quot;-bài-tập-1-chuyển-đổi-về-dạng-chuẩn&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Chuyển đổi về dạng chuẩn&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Chuyển đổi các bài toán sau về dạng chuẩn của tối ưu hóa lồi:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Ràng buộc hỗn hợp:&lt;/strong&gt;
\(\min_{x \in \mathbb{R}^3} x_1^2 + x_2^2 + x_3^2\)
\(\text{s.t.} \quad x_1 + 2x_2 - x_3 = 5, \quad x_1 - x_2 \geq 3, \quad x_2 \leq 4, \quad x_3 \text{ tự do}\)&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Bài toán minimax:&lt;/strong&gt;
\(\min_x \max_{i=1,\ldots,m} (a_i^T x + b_i)\)&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Bình phương tối thiểu bền vững (robust least squares):&lt;/strong&gt;
\(\min_x \max_{\lVert u \rVert_2 \leq 1} \lVert (A + \sum_{i=1}^k u_i B_i)x - b \rVert_2^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Chuyển bài toán về dạng chuẩn của tối ưu hóa lồi.&lt;/li&gt;
  &lt;li&gt;Xác định rõ biến quyết định, các ràng buộc và hàm mục tiêu.&lt;/li&gt;
  &lt;li&gt;Kiểm tra tính lồi của bài toán sau khi biến đổi.&lt;/li&gt;
  &lt;li&gt;Thảo luận tác động về mặt tính toán.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Bài toán có ràng buộc hỗn hợp**

**Xử lý biến tự do:** tách $$x_3 = x_3^+ - x_3^-$$ với $$x_3^+, x_3^- \geq 0$$.

**Đổi chiều bất đẳng thức:** $$x_1 - x_2 \geq 3 \Rightarrow -x_1 + x_2 \leq -3$$.

**Dạng chuẩn hóa:**
$$\min_{x_1,x_2,x_3^+,x_3^-} x_1^2 + x_2^2 + (x_3^+)^2 + (x_3^-)^2 - 2x_3^+ x_3^-$$
$$\text{s.t.} \quad x_1 + 2x_2 - x_3^+ + x_3^- = 5$$
$$\quad -x_1 + x_2 \leq -3$$
$$\quad x_2 \leq 4$$
$$\quad x_3^+, x_3^- \geq 0 \quad (x_1, x_2 \text{ vẫn tự do vì bài toán gốc không có ràng buộc } x_1, x_2 \geq 0)$$

**Lưu ý:** Vì $$(x_3^+ - x_3^-)^2 = (x_3^+)^2 + (x_3^-)^2 - 2x_3^+ x_3^-$$, hàm mục tiêu vẫn lồi (ma trận Hessian nửa xác định dương). Việc tách biến tự do thực chất chỉ cần thiết cho dạng chuẩn của quy hoạch tuyến tính (LP); đối với bộ giải quy hoạch bậc hai (QP), ta không cần tách biến này.

**Cách tiếp cận trực tiếp:** giữ nguyên $$x_3$$ tự do và giải trực tiếp bài toán QP lồi:
$$\min_{x_1,x_2,x_3} x_1^2 + x_2^2 + x_3^2$$
$$\text{s.t.} \quad x_1 + 2x_2 - x_3 = 5, \quad x_1 - x_2 \geq 3, \quad x_2 \leq 4$$

**Bước 2: Bài toán minimax**

**Biểu diễn trên đồ thị (epigraph):**
$$\min_{x,t} t$$
$$\text{s.t.} \quad a_i^T x + b_i \leq t, \quad i = 1,\ldots,m$$

**Tính lồi:** Hàm mục tiêu tuyến tính và các ràng buộc tuyến tính $$\Rightarrow$$ đây là một bài toán quy hoạch tuyến tính (LP).

**Bước 3: Bình phương tối thiểu bền vững**

**Hàm mục tiêu trường hợp xấu nhất:**
$$\max_{\lVert u \rVert_2 \leq 1} \lVert (A + \sum_{i=1}^k u_i B_i)x - b \rVert_2^2$$

**Viết lại dưới dạng ma trận:** $$\max_{\lVert u \rVert_2 \leq 1} \lVert Ax - b + (\sum_{i=1}^k u_i B_i)x \rVert_2^2$$.

**Đặt** $$q(x) = Ax - b$$ và $$P(x) = [B_1 x \ \cdots \ B_k x]$$ (đều là hàm affine theo $$x$$). Khi đó $$(\sum_i u_i B_i)x = P(x)u$$ và giá trị trường hợp xấu nhất là $$\max_{\lVert u \rVert_2 \leq 1} \lVert q(x) + P(x)u \rVert_2^2$$. Lưu ý rằng biểu thức này **không** bằng $$\lVert q \rVert_2^2 + \lVert \sum_i B_i x \rVert_2^2$$.

**Biểu diễn quy hoạch nửa xác định (bổ đề S, Boyd &amp;amp; Vandenberghe §6.4.2):**
$$\min_{x,t,\lambda} t + \lambda$$
$$\text{s.t.} \quad \begin{bmatrix} I &amp;amp; P(x) &amp;amp; q(x) \\ P(x)^T &amp;amp; \lambda I &amp;amp; 0 \\ q(x)^T &amp;amp; 0 &amp;amp; t \end{bmatrix} \succeq 0$$

**Chặn trên dạng SOCP (đơn giản hơn nhưng chặt hơn về mức bảo thủ):** do $$\lVert P(x)u \rVert_2 \leq \lVert P(x) \rVert_F$$ khi $$\lVert u \rVert_2 \leq 1$$, ta thu được bài toán xấp xỉ:
$$\min_{x} \ \lVert Ax - b \rVert_2 + \lVert P(x) \rVert_F$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-phân-tích-điều-kiện-tối-ưu&quot;&gt;📝 &lt;strong&gt;Bài tập 2: Phân tích điều kiện tối ưu&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Phân tích các điều kiện tối ưu cho các bài toán sau:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Bài toán bậc hai có ràng buộc:&lt;/strong&gt;
\(\min_x \frac{1}{2}x^T Q x + c^T x \quad \text{s.t.} \quad Ax = b, \quad x \geq 0\)
với \(Q \succeq 0\).&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Cực đại hóa entropy:&lt;/strong&gt;
\(\max_x -\sum_{i=1}^n x_i \log x_i \quad \text{s.t.} \quad \sum_{i=1}^n x_i = 1, \quad \sum_{i=1}^n a_i x_i = \alpha, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Máy vectơ hỗ trợ (Support Vector Machine - SVM):&lt;/strong&gt;
\(\min_{w,b,\xi} \frac{1}{2}\lVert w \rVert_2^2 + C\sum_{i=1}^m \xi_i\)
\(\text{s.t.} \quad y_i(w^T x_i + b) \geq 1 - \xi_i, \quad \xi_i \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Thiết lập các điều kiện KKT.&lt;/li&gt;
  &lt;li&gt;Phân tích điều kiện bù lỏng (complementary slackness).&lt;/li&gt;
  &lt;li&gt;Đặc trưng hóa nghiệm tối ưu.&lt;/li&gt;
  &lt;li&gt;Giải thích ý nghĩa hình học.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Bài toán bậc hai có ràng buộc**

**Hàm Lagrange:**
$$L(x,\lambda,\mu) = \frac{1}{2}x^T Q x + c^T x + \lambda^T(Ax - b) - \mu^T x$$

**Các điều kiện KKT:**
- **Điều kiện dừng:** $$Qx + c + A^T \lambda - \mu = 0$$
- **Tính khả thi gốc:** $$Ax = b, \quad x \geq 0$$
- **Tính khả thi đối ngẫu:** $$\mu \geq 0$$
- **Điều kiện bù lỏng:** $$\mu_i x_i = 0, \quad \forall i$$

**Phân tích:**
- Nếu $$x_i &amp;gt; 0$$ thì $$\mu_i = 0$$.
- Nếu $$x_i = 0$$ thì $$\mu_i \geq 0$$ (chi phí rút gọn).

**Cấu trúc nghiệm:** Các phương pháp tập tích cực (active-set methods) tận dụng cấu trúc thưa này để cập nhật tập các ràng buộc chặt.

**Bước 2: Cực đại hóa entropy**

**Chuyển về bài toán cực tiểu hóa:**
$$\min_x \sum_{i=1}^n x_i \log x_i \quad \text{s.t.} \quad \sum_{i=1}^n x_i = 1, \quad \sum_{i=1}^n a_i x_i = \alpha, \quad x \geq 0$$

**Hàm Lagrange:**
$$L(x,\lambda_1,\lambda_2,\mu) = \sum_{i=1}^n x_i \log x_i + \lambda_1\left(\sum_{i=1}^n x_i - 1\right) + \lambda_2\left(\sum_{i=1}^n a_i x_i - \alpha\right) - \sum_{i=1}^n \mu_i x_i$$

**Các điều kiện KKT:**
- **Điều kiện dừng:** $$\log x_i + 1 + \lambda_1 + \lambda_2 a_i - \mu_i = 0$$
- **Điều kiện bù lỏng:** $$\mu_i x_i = 0$$

**Nghiệm tối ưu:**
$$x_i^* = e^{-1 - \lambda_1 - \lambda_2 a_i}$$ (luôn dương, suy ra $$\mu_i = 0$$); sau khi chuẩn hóa theo điều kiện $$\sum_i x_i = 1$$:
$$x_i^* = \frac{e^{-\lambda_2 a_i}}{\sum_j e^{-\lambda_2 a_j}}$$

**Dạng họ mũ:** Phân phối có entropy cực đại dưới ràng buộc mô-men luôn thuộc họ phân phối mũ (phân phối Boltzmann/Gibbs).

**Bước 3: Máy vectơ hỗ trợ (SVM)**

**Hàm Lagrange:**
$$L(w,b,\xi,\alpha,\beta) = \frac{1}{2}\lVert w \rVert_2^2 + C\sum_{i=1}^m \xi_i - \sum_{i=1}^m \alpha_i[y_i(w^T x_i + b) - 1 + \xi_i] - \sum_{i=1}^m \beta_i \xi_i$$

**Các điều kiện KKT:**
- **Điều kiện dừng:**
  - $$\nabla_w L = w - \sum_{i=1}^m \alpha_i y_i x_i = 0 \Rightarrow w = \sum_{i=1}^m \alpha_i y_i x_i$$
  - $$\nabla_b L = -\sum_{i=1}^m \alpha_i y_i = 0$$
  - $$\nabla_{\xi_i} L = C - \alpha_i - \beta_i = 0$$

- **Điều kiện bù lỏng:**
  - $$\alpha_i[y_i(w^T x_i + b) - 1 + \xi_i] = 0$$
  - $$\beta_i \xi_i = 0$$

**Phân loại các điểm dữ liệu theo $$\alpha_i$$:**
- $$\alpha_i = 0$$: $$x_i$$ không phải là vectơ hỗ trợ (nằm đúng phía và ngoài biên).
- $$0 &amp;lt; \alpha_i &amp;lt; C$$: $$x_i$$ nằm chính xác trên biên ($$\xi_i = 0$$).
- $$\alpha_i = C$$: $$x_i$$ vi phạm biên hoặc nằm trên biên với $$\xi_i \geq 0$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-đối-ngẫu-và-phân-tích-độ-nhạy&quot;&gt;📝 &lt;strong&gt;Bài tập 3: Đối ngẫu và phân tích độ nhạy&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Xét bài toán quy hoạch tuyến tính:
\(\min_x c^T x \quad \text{s.t.} \quad Ax \leq b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;a) Thiết lập bài toán đối ngẫu và phân tích điều kiện đối ngẫu mạnh.
b) Thực hiện phân tích độ nhạy: giá trị tối ưu thay đổi thế nào khi \(b\) thay đổi?
c) Giải thích ý nghĩa kinh tế của giá bóng (shadow prices).
d) Phân tích quy hoạch tham số với \(b(\theta) = b_0 + \theta d\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Phân tích đầy đủ bài toán đối ngẫu.&lt;/li&gt;
  &lt;li&gt;Tính toán độ nhạy theo vế phải \(b\).&lt;/li&gt;
  &lt;li&gt;Giải thích ý nghĩa kinh tế.&lt;/li&gt;
  &lt;li&gt;Mô tả quỹ đạo nghiệm theo tham số \(\theta\).&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Thiết lập bài toán đối ngẫu**

**Bài toán gốc (primal):** $$\min_x c^T x \text{ s.t. } Ax \leq b, \; x \geq 0$$

**Hàm Lagrange (đặt miền $$x \geq 0$$):** $$L(x,\lambda) = c^T x + \lambda^T(Ax - b)$$

**Hàm đối ngẫu:** $$g(\lambda) = \inf_{x \geq 0} L(x,\lambda) = \inf_{x \geq 0} (c + A^T \lambda)^T x - \lambda^T b$$

**Điều kiện để hàm đối ngẫu hữu hạn:** $$c + A^T \lambda \geq 0$$.

**Bài toán đối ngẫu:**
$$\max_\lambda -\lambda^T b \quad \text{s.t.} \quad A^T \lambda + c \geq 0, \quad \lambda \geq 0$$

Hoặc viết tương đương bằng cách đặt $$\nu = -\lambda$$:
$$\max_\nu b^T \nu \quad \text{s.t.} \quad A^T \nu \leq c, \quad \nu \leq 0$$

**Bước 2: Điều kiện đối ngẫu mạnh**

**Điều kiện Slater:** Tồn tại $$x &amp;gt; 0$$ sao cho $$Ax &amp;lt; b$$.

**Định lý cơ bản của quy hoạch tuyến tính:** Đối với LP, đối ngẫu mạnh luôn đúng miễn là cả bài toán gốc và bài toán đối ngẫu đều khả thi (không nhất thiết cần điểm khả thi chặt).

**Điều kiện bù lỏng:**
- $$(c + A^T \lambda^*)_j x_j^* = 0, \quad \forall j$$
- $$\lambda_i^* (Ax^* - b)_i = 0, \quad \forall i$$

**Bước 3: Phân tích độ nhạy**

**Hàm giá trị tối ưu:** $$f^*(b) = \min\{c^T x : Ax \leq b, \; x \geq 0\}$$.

**Định lý bao (Envelope theorem):** Tại các điểm mà $$f^*$$ khả vi,
$$\nabla_b f^*(b) = -\lambda^*(b) \leq 0$$
(khi nới rộng vế phải $$b$$, tập khả thi lớn hơn nên giá trị cực tiểu $$f^*(b)$$ giảm hoặc giữ nguyên).

**Ý nghĩa giá bóng (shadow price):** $$\lambda_i^*$$ đo mức giảm cận biên của chi phí tối ưu khi tăng thêm một đơn vị tài nguyên thứ $$i$$.

**Ứng dụng thực tế:**
- Giải cặp bài toán gốc – đối ngẫu.
- Nghiệm đối ngẫu $$\lambda^*$$ cung cấp trực tiếp các hệ số độ nhạy.
- Kết quả có hiệu lực cục bộ trong một lân cận của giá trị $$b$$ hiện tại (khi cơ sở tối ưu chưa thay đổi).

**Bước 4: Quy hoạch tham số**

**Bài toán tham số hóa:** $$\min_x c^T x \text{ s.t. } Ax \leq b_0 + \theta d, \; x \geq 0$$.

**Giá trị tối ưu theo tham số:** $$f^*(\theta) = f^*(b_0 + \theta d)$$.

**Tính chất:** $$f^*(\theta)$$ là hàm lồi và tuyến tính từng khúc theo $$\theta$$.

**Điểm tới hạn (breakpoints):** Xuất hiện tại các giá trị $$\theta$$ nơi cơ sở tối ưu thay đổi.

**Quỹ đạo nghiệm:**
1. Bắt đầu từ nghiệm tối ưu tại $$\theta = 0$$.
2. Tăng $$\theta$$ cho đến khi một biến cơ sở chạm 0 (hoặc tính khả thi thay đổi).
3. Thực hiện phép xoay (pivot) sang cơ sở tối ưu mới.
4. Lặp lại cho đến khi đạt giá trị $$\theta$$ mong muốn.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-các-kỹ-thuật-nới-lỏng-relaxation&quot;&gt;📝 &lt;strong&gt;Bài tập 4: Các kỹ thuật nới lỏng (Relaxation)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Xét bài toán quy hoạch nguyên nhị phân:
\(\min_x c^T x \quad \text{s.t.} \quad Ax \leq b, \quad x_i \in \{0,1\}, \quad i \in I\)&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Nới lỏng LP:&lt;/strong&gt; nới lỏng điều kiện \(x_i \in [0,1]\).
b) &lt;strong&gt;Nới lỏng Lagrange:&lt;/strong&gt; đưa một tập con các ràng buộc vào hàm mục tiêu.
c) &lt;strong&gt;Nới lỏng SDP:&lt;/strong&gt; nâng biến với \(x_i x_j = X_{ij}\) và \(X \succeq 0\).
d) &lt;strong&gt;Bao lồi (convex hull):&lt;/strong&gt; mô tả \(\text{conv}(\text{tập điểm nguyên khả thi})\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Phát biểu các dạng nới lỏng.&lt;/li&gt;
  &lt;li&gt;Phân tích chất lượng chặn dưới thu được.&lt;/li&gt;
  &lt;li&gt;Trình bày kỹ thuật làm chặt (tightening).&lt;/li&gt;
  &lt;li&gt;So sánh chi phí tính toán.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Nới lỏng LP**

**Bài toán nới lỏng:**
$$\min_x c^T x \quad \text{s.t.} \quad Ax \leq b, \quad 0 \leq x_i \leq 1, \quad i \in I$$

**Tính chất:**
- **Chặn dưới:** $$z_{LP} \leq z_{IP}$$.
- **Độ phức tạp:** giải được trong thời gian đa thức.
- **Độ chặt:** chặn dưới là chặt khi nghiệm tối ưu của bài toán LP có giá trị nguyên.

**Khoảng cách nguyên (integrality gap):** $$\frac{z_{IP}}{z_{LP}}$$ (với giá trị dương).

**Bước 2: Nới lỏng Lagrange**

**Đưa nhóm ràng buộc $$A_2 x \leq b_2$$ vào hàm mục tiêu:**
$$L_D(\lambda) = \min_x \{c^T x + \lambda^T(A_2 x - b_2) : A_1 x \leq b_1, \; x_i \in \{0,1\}\}$$

**Chặn dưới đối ngẫu:** $$\max_{\lambda \geq 0} L_D(\lambda)$$.

**Ưu điểm:**
- **Khả năng phân rã:** bài toán tách thành nhiều bài toán con độc lập nếu $$A_1$$ có cấu trúc đường chéo khối.
- **Chặn chặt hơn:** thường cho chặn dưới chặt hơn hoặc bằng nới lỏng LP.
- **Tối ưu hóa dưới gradient:** bài toán đối ngẫu có thể giải bằng phương pháp dưới gradient (subgradient).

**Bước 3: Nới lỏng SDP**

**Bài toán bậc hai tương ứng:** $$\min \sum_{ij} c_{ij} x_i x_j$$

**Dạng nới lỏng SDP:**
$$\min_{X} \sum_{ij} c_{ij} X_{ij}$$
$$\text{s.t.} \quad \text{các ràng buộc tuyến tính theo } X$$
$$\quad X_{ii} = x_i, \quad X \succeq 0$$

**Ràng buộc hạng 1:** ràng buộc phi lồi $$X = xx^T$$ được nới lỏng thành $$X \succeq 0$$ (hoặc $$\begin{bmatrix} 1 &amp;amp; x^T \\ x &amp;amp; X \end{bmatrix} \succeq 0$$).

**Ứng dụng tiêu biểu:**
- **Bài toán cắt cực đại (Max-Cut):** thuật toán Goemans–Williamson.
- **Bài toán gán bậc hai (QAP):** các phép nới lỏng SDP.

**Bước 4: Đặc trưng hóa bao lồi**

**Đa diện lồi nguyên:** $$P_I = \text{conv}\{x \in \{0,1\}^n : Ax \leq b\}$$.

**Nhận diện các mặt (facets):**
- **Bất đẳng thức hợp lệ (valid inequalities):** $$\alpha^T x \leq \beta$$ đúng với mọi $$x \in P_I$$.
- **Bất đẳng thức tạo mặt (facet-defining):** các bất đẳng thức hợp lệ chặt nhất mô tả biên của $$P_I$$.

**Phương pháp mặt phẳng cắt (cutting plane methods):**
1. Giải bài toán nới lỏng LP.
2. Nếu nghiệm còn chứa thành phần phân số, tìm một bất đẳng thức hợp lệ bị nghiệm này vi phạm.
3. Bổ sung lát cắt (cut) vào bài toán LP và giải lại.
4. Lặp lại cho đến khi thu được nghiệm nguyên.

**Ví dụ:**
- **Bài toán cái túi (Knapsack):** bất đẳng thức phủ (cover inequalities).
- **Bài toán người bán hàng (TSP):** ràng buộc loại bỏ chu trình con (subtour elimination constraints).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-tối-ưu-hóa-bền-vững-robust-optimization&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Tối ưu hóa bền vững (Robust optimization)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Bài toán tối ưu hóa danh mục đầu tư dưới điều kiện bất định:
\(\min_x x^T \Sigma x \quad \text{s.t.} \quad \mu^T x \geq r, \quad \mathbf{1}^T x = 1, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;với tham số bất định \((\mu, \Sigma)\).&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Bất định dạng hộp (box uncertainty):&lt;/strong&gt; \(\mu_i \in [\underline{\mu}_i, \overline{\mu}_i]\).
b) &lt;strong&gt;Bất định dạng ellipsoid:&lt;/strong&gt; \(\mu \in \{\mu_0 + Pu : \lVert u \rVert_2 \leq 1\}\).
c) &lt;strong&gt;Mô hình nhân tố (factor model):&lt;/strong&gt; \(\mu = \beta f + \epsilon\) với \(f\) bất định.
d) &lt;strong&gt;Bền vững theo phân phối (distributionally robust):&lt;/strong&gt; \(\mathbb{E}_P[\mu] = \mu_0\), \(\text{Var}_P[\mu] \preceq \Sigma_0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Viết lại các bài toán dưới dạng bài toán tối ưu hóa lồi tất định.&lt;/li&gt;
  &lt;li&gt;Phân tích mức độ bảo thủ của từng mô hình.&lt;/li&gt;
  &lt;li&gt;So sánh độ phức tạp tính toán.&lt;/li&gt;
  &lt;li&gt;Nhận xét về cài đặt thực tế.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Bất định dạng hộp**

**Ràng buộc trường hợp xấu nhất:** $$\min_{\mu \in \mathcal{U}} \mu^T x \geq r$$

với $$\mathcal{U} = \{\mu : \underline{\mu}_i \leq \mu_i \leq \overline{\mu}_i\}$$.

**Phân tích trường hợp xấu nhất:**
$$\min_{\mu \in \mathcal{U}} \mu^T x = \sum_{i: x_i \geq 0} \underline{\mu}_i x_i + \sum_{i: x_i &amp;lt; 0} \overline{\mu}_i x_i$$

**Bài toán bền vững tương đương:**
$$\min_x x^T \Sigma x$$
$$\text{s.t.} \quad \sum_{i: x_i \geq 0} \underline{\mu}_i x_i + \sum_{i: x_i &amp;lt; 0} \overline{\mu}_i x_i \geq r$$
$$\quad \mathbf{1}^T x = 1, \quad x \geq 0$$
(với ràng buộc $$x \geq 0$$, điều kiện lợi suất rút gọn thành $$\underline{\mu}^T x \geq r$$).

**Bước 2: Bất định dạng ellipsoid**

**Tập bất định:** $$\mathcal{U} = \{\mu_0 + Pu : \lVert u \rVert_2 \leq 1\}$$.

**Ràng buộc trường hợp xấu nhất:**
$$\min_{\lVert u \rVert_2 \leq 1} (\mu_0 + Pu)^T x = \mu_0^T x - \lVert P^T x \rVert_2 \geq r$$

**Bài toán bền vững tương đương:**
$$\min_x x^T \Sigma x$$
$$\text{s.t.} \quad \mu_0^T x - \lVert P^T x \rVert_2 \geq r$$
$$\quad \mathbf{1}^T x = 1, \quad x \geq 0$$

**Phân loại:** Ràng buộc $$\mu_0^T x - \lVert P^T x \rVert_2 \geq r$$ là ràng buộc nón bậc hai, nên bài toán có thể đưa về dạng SOCP.

**Bước 3: Mô hình nhân tố**

**Mô hình:** $$\mu = \beta f + \epsilon$$ với $$f \in \mathcal{F}$$ và nhiễu $$\epsilon$$.

**Tập bất định:** $$\mathcal{U} = \{\beta f + \epsilon : f \in \mathcal{F}, \; \lVert \epsilon \rVert_2 \leq \sigma\}$$.

**Phân tích trường hợp xấu nhất:**
$$\min_{\mu \in \mathcal{U}} \mu^T x = \min_{f \in \mathcal{F}} (\beta f)^T x - \sigma \lVert x \rVert_2$$

**Trường hợp đa nhân tố:** $$\mu = \sum_{k=1}^K \beta_k f_k + \epsilon$$.

**Bước 4: Bền vững theo phân phối**

**Tập phân phối bất định (ambiguity set):** $$\mathcal{P} = \{P : \mathbb{E}_P[\mu] = \mu_0, \; \text{Cov}_P[\mu] \preceq \Sigma_0\}$$.

**Lưu ý:** Kỳ vọng không mang tính bất định vì $$\mathbb{E}_P[\mu^T x] = \mu_0^T x$$ với mọi $$P \in \mathcal{P}$$. Tính bền vững đến từ ràng buộc xác suất (chance constraint) $$\inf_{P \in \mathcal{P}} \mathbb{P}_P[\mu^T x \geq r] \geq 1 - \epsilon$$; theo bất đẳng thức Cantelli/Chebyshev một phía, ràng buộc này tương đương với:
$$\mu_0^T x - \kappa \sqrt{x^T \Sigma_0 x} \geq r, \qquad \kappa = \sqrt{\frac{1-\epsilon}{\epsilon}}$$

**Bài toán bền vững tương đương:**
$$\min_x x^T \Sigma x$$
$$\text{s.t.} \quad \mu_0^T x - \kappa \sqrt{x^T \Sigma_0 x} \geq r$$
$$\quad \mathbf{1}^T x = 1, \quad x \geq 0$$

**Liên hệ với dạng ellipsoid:** Biểu thức trên tương đương với bất định ellipsoid có $$P P^T = \kappa^2 \Sigma_0$$ (vì $$\lVert P^T x \rVert_2^2 = x^T P P^T x$$).

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-6-tối-ưu-hóa-đa-mục-tiêu&quot;&gt;📝 &lt;strong&gt;Bài tập 6: Tối ưu hóa đa mục tiêu&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Xét bài toán hai mục tiêu:
\(\min_x (f_1(x), f_2(x)) \quad \text{s.t.} \quad x \in \mathcal{X}\)&lt;/p&gt;

&lt;p&gt;với \(f_1, f_2\) là các hàm lồi và \(\mathcal{X}\) là tập lồi.&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Tính tối ưu Pareto:&lt;/strong&gt; đặc trưng hóa các nghiệm tối ưu Pareto.
b) &lt;strong&gt;Các phương pháp vô hướng hóa:&lt;/strong&gt; tổng có trọng số, ràng buộc \(\epsilon\), và vô hướng hóa theo mức đạt được (achievement scalarization).
c) &lt;strong&gt;Xây dựng biên Pareto:&lt;/strong&gt; liệt kê có hệ thống các điểm trên biên.
d) &lt;strong&gt;Ứng dụng:&lt;/strong&gt; tối ưu hóa danh mục đầu tư và thiết kế kỹ thuật.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Trình bày đặc trưng lý thuyết.&lt;/li&gt;
  &lt;li&gt;Trình bày các thuật toán tiếp cận.&lt;/li&gt;
  &lt;li&gt;Minh họa bằng ví dụ tính toán.&lt;/li&gt;
  &lt;li&gt;Nêu các lưu ý thực tế.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Đặc trưng hóa tính tối ưu Pareto**

**Định nghĩa:** $$x^* \in \mathcal{X}$$ là nghiệm tối ưu Pareto nếu không tồn tại $$x \in \mathcal{X}$$ sao cho:
- $$f_i(x) \leq f_i(x^*)$$ với mọi $$i$$, và
- $$f_j(x) &amp;lt; f_j(x^*)$$ với ít nhất một chỉ số $$j$$.

**Điều kiện cần (trong trường hợp lồi):** Nếu $$x^*$$ là nghiệm tối ưu Pareto, tồn tại $$\lambda \geq 0$$, $$\lambda \neq 0$$ sao cho $$x^*$$ là nghiệm của bài toán:
$$\min_x \sum_{i=1}^2 \lambda_i f_i(x) \quad \text{s.t.} \quad x \in \mathcal{X}$$

**Điều kiện đủ:** Nếu $$\lambda &amp;gt; 0$$ (các thành phần đều dương chặt) và $$x^*$$ giải bài toán tổng trọng số (hoặc $$\lambda \geq 0, \lambda \neq 0$$ và $$x^*$$ là nghiệm duy nhất), thì $$x^*$$ là nghiệm tối ưu Pareto.

**Bước 2: Các phương pháp vô hướng hóa**

**Phương pháp tổng có trọng số (weighted sum):**
$$\min_x \lambda_1 f_1(x) + \lambda_2 f_2(x) \quad \text{s.t.} \quad x \in \mathcal{X}$$

với $$\lambda_1, \lambda_2 \geq 0$$, $$\lambda_1 + \lambda_2 = 1$$.

**Hạn chế:** Không thể tìm được các điểm nằm trên phần không lồi của biên Pareto (nếu bài toán tổng quát không lồi).

**Phương pháp ràng buộc $$\epsilon$$ ($$\epsilon$$-constraint):**
$$\min_x f_1(x) \quad \text{s.t.} \quad f_2(x) \leq \epsilon, \quad x \in \mathcal{X}$$

**Ưu điểm:** Có thể tìm được toàn bộ biên Pareto kể cả khi biên không lồi.

**Vô hướng hóa theo mức đạt được (achievement scalarization):**
$$\min_{x,t} t \quad \text{s.t.} \quad f_i(x) - z_i^* \leq t, \quad x \in \mathcal{X}$$

với $$z^*$$ là điểm lý tưởng: $$z_i^* = \min_{x \in \mathcal{X}} f_i(x)$$.

**Bước 3: Tính toán biên Pareto**

**Thuật toán 1: Quét tổng có trọng số**
```
For λ₁ = 0 to 1 (step δ):
    λ₂ = 1 - λ₁
    Solve: min λ₁f₁(x) + λ₂f₂(x) s.t. x ∈ X
    Store solution if Pareto optimal
```

**Thuật toán 2: Quét ràng buộc $$\epsilon$$**
```
Compute range [ε_min, ε_max] for f₂
For ε = ε_min to ε_max (step δ):
    Solve: min f₁(x) s.t. f₂(x) ≤ ε, x ∈ X
    Store solution
```

**Thuật toán 3: Giao tuyến biên pháp tuyến (Normal Boundary Intersection)**
- Xây dựng bao lồi của các điểm cực tiểu riêng lẻ.
- Sinh các điểm phân bố đều trên bao lồi đó.
- Giải các bài toán tối ưu hóa có ràng buộc tương ứng để chiếu lên biên Pareto.

**Bước 4: Ví dụ danh mục đầu tư**

**Hai hàm mục tiêu:**
- $$f_1(x) = x^T \Sigma x$$ (rủi ro)
- $$f_2(x) = -\mu^T x$$ (âm lợi suất kỳ vọng)

**Ràng buộc:** $$\mathbf{1}^T x = 1$$, $$x \geq 0$$.

**Biên hiệu quả (efficient frontier):**
$$\min_x x^T \Sigma x \quad \text{s.t.} \quad \mu^T x \geq r, \quad \mathbf{1}^T x = 1, \quad x \geq 0$$

**Họ nghiệm theo tham số:** quét $$r \in [r_{\min}, r_{\max}]$$.

**Biên trung bình – phương sai:** có dạng nhánh hyperbol trong không gian $$(r, \sigma)$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-7-tối-ưu-hóa-ngẫu-nhiên-stochastic-optimization&quot;&gt;📝 &lt;strong&gt;Bài tập 7: Tối ưu hóa ngẫu nhiên (Stochastic optimization)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Xét bài toán quy hoạch ngẫu nhiên hai giai đoạn:
\(\min_{x} c^T x + \mathbb{E}_\xi[Q(x, \xi)]\)
\(\text{s.t.} \quad Ax = b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;trong đó \(Q(x, \xi) = \min_y \{q^T y : Wy = h - Tx, \; y \geq 0\}\).&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Xấp xỉ trung bình mẫu (Sample Average Approximation - SAA).&lt;/strong&gt;
b) &lt;strong&gt;Mô hình hóa theo kịch bản (scenario-based formulation).&lt;/strong&gt;
c) &lt;strong&gt;Phân rã Benders (Benders decomposition).&lt;/strong&gt;
d) &lt;strong&gt;Thước đo rủi ro:&lt;/strong&gt; CVaR và hướng tiếp cận bền vững.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Xây dựng dạng tương đương tất định.&lt;/li&gt;
  &lt;li&gt;Trình bày thuật toán phân rã.&lt;/li&gt;
  &lt;li&gt;Nêu kết quả hội tụ thống kê.&lt;/li&gt;
  &lt;li&gt;Trình bày mở rộng có xét đến rủi ro.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Xấp xỉ trung bình mẫu (SAA)**

**Bài toán gốc:** $$\min_x \{c^T x + \mathbb{E}_\xi[Q(x, \xi)] : Ax = b, \; x \geq 0\}$$.

**Bài toán xấp xỉ SAA:** $$\min_x \left\{c^T x + \frac{1}{N}\sum_{i=1}^N Q(x, \xi^i) : Ax = b, \; x \geq 0\right\}$$

với $$\xi^1, \ldots, \xi^N$$ là các mẫu độc lập, cùng phân phối (i.i.d.).

**Tính hội tụ:** $$\hat{x}_N \to x^*$$ khi $$N \to \infty$$ (hội tụ hầu chắc chắn).

**Kích thước mẫu:** cần $$N = O(\epsilon^{-2})$$ để đạt nghiệm $$\epsilon$$-tối ưu.

**Bước 2: Mô hình hóa theo kịch bản**

**Bài toán tương đương tất định:**
$$\min_{x,y^1,\ldots,y^N} c^T x + \frac{1}{N}\sum_{i=1}^N q^T y^i$$
$$\text{s.t.} \quad Ax = b, \quad x \geq 0$$
$$\quad W y^i = h^i - T^i x, \quad y^i \geq 0, \quad i = 1,\ldots,N$$

**Quy mô bài toán LP:** kích thước tăng nhanh theo số kịch bản $$N$$ (số biến và số ràng buộc tỷ lệ với $$N$$).

**Cấu trúc khối:** Ma trận ràng buộc có cấu trúc khối góc, thuận lợi cho các thuật toán phân rã.

**Bước 3: Phân rã Benders**

**Bài toán chính (master problem):**
$$\min_{x,\theta} c^T x + \theta$$
$$\text{s.t.} \quad Ax = b, \quad x \geq 0$$
$$\quad \theta \geq \frac{1}{N}\sum_{i=1}^N (\pi^{i,k})^T(h^i - T^i x), \quad k = 1, 2, \ldots \quad \text{(lát cắt tối ưu, với } \pi^{i,k} \text{ là nghiệm đối ngẫu của bài toán con)}$$

**Các bài toán con (subproblems):** với mỗi kịch bản $$i$$,
$$\min_{y^i} q^T y^i \quad \text{s.t.} \quad W y^i = h^i - T^i x, \quad y^i \geq 0$$

**Quy trình thuật toán:**
1. Giải bài toán chính để nhận nghiệm $$x^k$$.
2. Giải các bài toán con theo từng kịch bản để thu được nghiệm đối ngẫu $$\pi^{i,k}$$.
3. Bổ sung các lát cắt Benders vào bài toán chính.
4. Lặp lại cho đến khi hội tụ.

**Bước 4: Thước đo rủi ro**

**Giá trị rủi ro có điều kiện (Conditional Value-at-Risk - CVaR):**
$$\text{CVaR}_\alpha[Z] = \mathbb{E}[Z \mid Z \geq \text{VaR}_\alpha[Z]]$$

**Biểu diễn dưới dạng bài toán tối ưu:**
$$\min_{x,\eta,s} c^T x + \eta + \frac{1}{(1-\alpha)N}\sum_{i=1}^N s_i$$
$$\text{s.t.} \quad Ax = b, \quad x \geq 0$$
$$\quad s_i \geq Q(x, \xi^i) - \eta, \quad s_i \geq 0$$

**Bài toán có ràng buộc rủi ro:**
$$\min_x c^T x \quad \text{s.t.} \quad \text{CVaR}_\alpha[Q(x, \xi)] \leq \gamma$$

**Hướng tiếp cận bền vững theo phân phối:** xét trường hợp xấu nhất trên tập phân phối $$\mathcal{P}$$:
$$\min_x c^T x + \max_{P \in \mathcal{P}} \mathbb{E}_P[Q(x, \xi)]$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-8-tối-ưu-hóa-nón-conic-optimization&quot;&gt;📝 &lt;strong&gt;Bài tập 8: Tối ưu hóa nón (Conic optimization)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Phân tích các lớp bài toán tối ưu hóa nón sau:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Quy hoạch nón bậc hai (SOCP):&lt;/strong&gt;
\(\min_x c^T x \quad \text{s.t.} \quad \lVert A_i x + b_i \rVert_2 \leq c_i^T x + d_i\)&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Quy hoạch nửa xác định (SDP):&lt;/strong&gt;
\(\min_X \langle C, X \rangle \quad \text{s.t.} \quad \langle A_i, X \rangle = b_i, \quad X \succeq 0\)&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Quy hoạch nón mũ (exponential cone programming):&lt;/strong&gt;
\(\min_x c^T x \quad \text{s.t.} \quad (x_i, x_j, x_k) \in \mathcal{K}_{\exp}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Trình bày dạng chuẩn của từng lớp bài toán.&lt;/li&gt;
  &lt;li&gt;Thiết lập bài toán đối ngẫu.&lt;/li&gt;
  &lt;li&gt;Nêu vai trò của thuật toán điểm trong.&lt;/li&gt;
  &lt;li&gt;Liệt kê các ứng dụng và ví dụ mô hình hóa.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Quy hoạch nón bậc hai (SOCP)**

**Dạng chuẩn:**
$$\min_x c^T x \quad \text{s.t.} \quad Ax = b, \quad x \in \mathcal{K}$$

với $$\mathcal{K} = \mathcal{K}_1 \times \cdots \times \mathcal{K}_m$$ và $$\mathcal{K}_i = \{(t, u) : \lVert u \rVert_2 \leq t\}$$.

**Bài toán đối ngẫu:**
$$\max_y b^T y \quad \text{s.t.} \quad A^T y + s = c, \quad s \in \mathcal{K}$$

**Tính tự đối ngẫu:** $$\mathcal{K}_i^* = \mathcal{K}_i$$.

**Ứng dụng:**
- **Tối ưu hóa bền vững:** bất định dạng ellipsoid.
- **Tối ưu hóa danh mục đầu tư:** ràng buộc rủi ro và phương sai.
- **Thiết kế bộ lọc:** các ràng buộc đáp ứng tần số.

**Bước 2: Quy hoạch nửa xác định (SDP)**

**Dạng chuẩn:**
$$\min_X \langle C, X \rangle \quad \text{s.t.} \quad \langle A_i, X \rangle = b_i, \quad X \succeq 0$$

**Dạng vectơ hóa:** $$\min_x c^T x \text{ s.t. } Ax = b, \; x \in \mathcal{S}_+^n$$.

**Bài toán đối ngẫu:**
$$\max_y b^T y \quad \text{s.t.} \quad \sum_{i=1}^m y_i A_i + S = C, \quad S \succeq 0$$

**Đối ngẫu mạnh:** Đúng khi điều kiện Slater được thỏa mãn.

**Ứng dụng:**
- **Tối ưu hóa tổ hợp:** bài toán cắt cực đại (Max-Cut), tô màu đồ thị.
- **Lý thuyết điều khiển:** bất đẳng thức ma trận tuyến tính (LMI).
- **Học máy:** các phương pháp nhân (kernel methods).

**Bước 3: Nón mũ (Exponential cone)**

**Định nghĩa nón mũ:** $$\mathcal{K}_{\exp} = \{(x,y,z) : ye^{x/y} \leq z, \; y &amp;gt; 0\} \cup \{(x,0,z) : x \leq 0, \; z \geq 0\}$$.

**Nón đối ngẫu:** $$\mathcal{K}_{\exp}^* = \{(u,v,w) : u &amp;lt; 0, \; -ue^{v/u} \leq ew, \text{ hoặc } u = 0, \; v \geq 0, \; w \geq 0\}$$.

**Ứng dụng:**
- **Tối ưu hóa entropy:** $$\min \sum x_i \log x_i$$.
- **Quy hoạch hình học:** sau phép đổi biến logarit.
- **Entropy tương đối:** cực tiểu hóa phân kỳ KL.

**Ví dụ mô hình hóa:**

**Entropy:** $$x \log x \leq t \Leftrightarrow (-t, x, 1) \in \mathcal{K}_{\exp}$$ (vì $$x e^{-t/x} \leq 1 \Leftrightarrow t \geq x \log x$$).

**Log-sum-exp:** $$\log(\sum e^{x_i}) \leq t$$ tương đương với một hệ các ràng buộc nón mũ.

**Nón lũy thừa (power cone):** $$x_1^{p_1} \cdots x_k^{p_k} \geq |x_{k+1}|$$ là một loại nón riêng (không phải nón mũ); với số mũ hữu tỉ, có thể biểu diễn lại bằng các ràng buộc nón bậc hai.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-9-thuật-toán-xấp-xỉ&quot;&gt;📝 &lt;strong&gt;Bài tập 9: Thuật toán xấp xỉ&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Thiết kế thuật toán xấp xỉ cho các bài toán không lồi sau:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Nới lỏng SDP cho Max-Cut:&lt;/strong&gt; thuật toán Goemans–Williamson.
b) &lt;strong&gt;Định vị cơ sở (Facility location):&lt;/strong&gt; làm tròn dựa trên LP.
c) &lt;strong&gt;Phủ tập hợp (Set cover):&lt;/strong&gt; phân tích thuật toán tham lam.
d) &lt;strong&gt;Bài toán cái túi (Knapsack):&lt;/strong&gt; lược đồ xấp xỉ thời gian đa thức đầy đủ (FPTAS) qua quy hoạch động.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Xây dựng dạng nới lỏng.&lt;/li&gt;
  &lt;li&gt;Thiết kế lược đồ làm tròn (rounding).&lt;/li&gt;
  &lt;li&gt;Phân tích tỉ số xấp xỉ.&lt;/li&gt;
  &lt;li&gt;Nêu các đảm bảo hiệu năng.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Nới lỏng SDP cho bài toán Max-Cut**

**Bài toán gốc:** $$\max_{x \in \{-1,1\}^n} \frac{1}{2}\sum_{(i,j) \in E} w_{ij}(1 - x_i x_j)$$ (mỗi cạnh tính một lần; cạnh bị cắt cho $$1 - x_i x_j = 2$$).

**Dạng tương đương:** $$\min_{x \in \{-1,1\}^n} \sum_{(i,j) \in E} w_{ij} x_i x_j$$.

**Nới lỏng SDP:** đặt $$X = xx^T \Rightarrow X_{ij} = x_i x_j$$ và nới lỏng thành:
$$\max_X \frac{1}{2}\sum_{(i,j) \in E} w_{ij}(1 - X_{ij})$$
$$\text{s.t.} \quad X_{ii} = 1, \quad X \succeq 0$$

**Thuật toán Goemans–Williamson:**
1. Giải bài toán nới lỏng SDP để thu được nghiệm tối ưu $$X^*$$.
2. Phân tích Cholesky: $$X^* = V^T V$$.
3. Chọn siêu phẳng ngẫu nhiên: $$r \sim \mathcal{N}(0, I)$$.
4. Làm tròn: $$x_i = \text{sign}(r^T v_i)$$.

**Tỉ số xấp xỉ:** $$\alpha_{GW} = \min_{0 \leq \theta \leq \pi} \frac{2}{\pi} \cdot \frac{\theta}{1 - \cos \theta} \approx 0.878$$.

**Bước 2: Bài toán định vị cơ sở (Facility location)**

**Bài toán:** $$\min \sum_{i \in F} f_i y_i + \sum_{i \in F, j \in C} c_{ij} x_{ij}$$
$$\text{s.t.} \quad \sum_{i \in F} x_{ij} = 1, \quad x_{ij} \leq y_i, \quad x_{ij}, y_i \in \{0,1\}$$

**Nới lỏng LP:** $$x_{ij}, y_i \in [0,1]$$.

**Thuật toán làm tròn:**
1. Giải bài toán nới lỏng LP.
2. Gom cụm các khách hàng và trong mỗi cụm, mở một cơ sở được chọn với xác suất tỷ lệ với $$x_{ij}^*$$ (nếu chỉ mở từng cơ sở độc lập với xác suất $$y_i^*$$ thì có thể xảy ra trường hợp một số khách hàng không có cơ sở phục vụ).
3. Nối mỗi khách hàng $$j$$ với cơ sở đang mở gần nhất.

**Phân tích:** Làm tròn ngẫu nhiên theo cụm (Chudak–Shmoys) cho chi phí kỳ vọng $$\leq (1 + 2/e) \times$$ giá trị tối ưu LP $$\approx 1.736 \times$$ LP.

**Các đảm bảo tốt hơn:** Thuật toán tham lam khớp đối ngẫu của Jain–Mahdian–Saberi đạt tỉ số $$1.61$$; tỉ số tốt nhất từng biết là khoảng $$1.488$$ (Li, 2011).

**Bước 3: Thuật toán tham lam cho phủ tập hợp (Set cover)**

**Bài toán:** $$\min \sum_{S \in \mathcal{S}} x_S \quad \text{s.t.} \quad \sum_{S: e \in S} x_S \geq 1, \quad x_S \in \{0,1\}$$.

**Thuật toán tham lam:**
```
While uncovered elements exist:
    Pick set S maximizing |S ∩ (uncovered elements)| / cost(S)
    Add S to solution
```

**Phân tích:** Đạt tỉ số xấp xỉ $$H_n$$ với $$H_n = \sum_{i=1}^n \frac{1}{i} \approx \ln n$$.

**Kỹ thuật phân tích dựa trên LP:**
- Phương pháp khớp đối ngẫu (dual fitting).
- Thuật toán gốc – đối ngẫu (primal-dual).

**Bước 4: FPTAS cho bài toán cái túi (Knapsack)**

**Bài toán:** $$\max \sum_{i=1}^n v_i x_i \quad \text{s.t.} \quad \sum_{i=1}^n w_i x_i \leq W, \quad x_i \in \{0,1\}$$.

**Quy hoạch động chuẩn:** thời gian $$O(nW)$$ (giả đa thức).

**Hướng tiếp cận FPTAS:**
1. Co giãn giá trị: $$\tilde{v}_i = \lfloor v_i / K \rfloor$$ với $$K = \epsilon \cdot v_{\max} / n$$.
2. Chạy quy hoạch động trên bài toán đã co giãn với độ phức tạp $$O(n^3 / \epsilon)$$ (tổng giá trị sau co giãn $$\leq n^2/\epsilon$$).
3. Trả về nghiệm thu được.

**Đảm bảo xấp xỉ:** đạt ít nhất $$(1 - \epsilon)$$ lần giá trị tối ưu.

**Ý tưởng chính:** Phép làm tròn giá trị vừa giữ được độ gần tối ưu, vừa thu nhỏ đáng kể không gian trạng thái của quy hoạch động.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-10-ứng-dụng-trong-học-máy&quot;&gt;📝 &lt;strong&gt;Bài tập 10: Ứng dụng trong học máy&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Đề bài:&lt;/strong&gt; Phân tích các bài toán học máy sau dưới góc độ tối ưu hóa lồi:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Hồi quy logistic:&lt;/strong&gt; \(\min_w \sum_{i=1}^n \log(1 + e^{-y_i w^T x_i}) + \lambda \lVert w \rVert_2^2\)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;b) &lt;strong&gt;Hồi quy vectơ hỗ trợ (SVR):&lt;/strong&gt; $$\min_{w,b} \frac{1}{2}\lVert w \rVert_2^2 + C\sum_{i=1}^n \max(0,&lt;/td&gt;
      &lt;td&gt;y_i - w^T x_i - b&lt;/td&gt;
      &lt;td&gt;- \epsilon)$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;c) &lt;strong&gt;Hoàn thiện ma trận (Matrix completion):&lt;/strong&gt; \(\min_X \lVert X \rVert_* \quad \text{s.t.} \quad X_{ij} = M_{ij}, \; (i,j) \in \Omega\)&lt;/p&gt;

&lt;p&gt;d) &lt;strong&gt;Mã hóa thưa (Sparse coding):&lt;/strong&gt; \(\min_{D,\alpha} \frac{1}{2}\lVert Y - D\alpha \rVert_F^2 + \lambda \lVert \alpha \rVert_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yêu cầu:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Phân tích tính lồi.&lt;/li&gt;
  &lt;li&gt;Thiết lập điều kiện tối ưu.&lt;/li&gt;
  &lt;li&gt;Đề xuất các thuật toán giải.&lt;/li&gt;
  &lt;li&gt;Phân tích tác dụng của thành phần chính quy hóa.&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải chi tiết&lt;/strong&gt;&lt;/summary&gt;

**Bước 1: Hồi quy logistic**

**Hàm mục tiêu:** $$f(w) = \sum_{i=1}^n \log(1 + e^{-y_i w^T x_i}) + \lambda \lVert w \rVert_2^2$$.

**Tính lồi:**
- Mỗi số hạng $$\log(1 + e^{-y_i w^T x_i})$$ là hàm lồi (dạng log-sum-exp hợp với hàm affine).
- Thành phần chính quy hóa $$\ell_2$$ là hàm lồi (lồi chặt nếu $$\lambda &amp;gt; 0$$).
- Tổng các hàm lồi là hàm lồi.

**Gradient:** $$\nabla f(w) = -\sum_{i=1}^n \frac{y_i x_i}{1 + e^{y_i w^T x_i}} + 2\lambda w$$.

**Ma trận Hessian:** $$\nabla^2 f(w) = \sum_{i=1}^n \frac{e^{y_i w^T x_i}}{(1 + e^{y_i w^T x_i})^2} x_i x_i^T + 2\lambda I \succ 0$$ (với $$\lambda &amp;gt; 0$$).

**Thuật toán giải:**
- **Phương pháp Newton:** hội tụ nhanh khi số chiều vừa phải.
- **BFGS / L-BFGS:** phương pháp tựa Newton.
- **SGD:** mở rộng tốt cho tập dữ liệu lớn.

**Bước 2: Hồi quy vectơ hỗ trợ (SVR)**

**Viết lại bằng biến phụ:** $$\min_{w,b,\xi,\xi^*} \frac{1}{2}\lVert w \rVert_2^2 + C\sum_{i=1}^n (\xi_i + \xi_i^*)$$
$$\text{s.t.} \quad y_i - w^T x_i - b \leq \epsilon + \xi_i$$
$$\quad w^T x_i + b - y_i \leq \epsilon + \xi_i^*$$
$$\quad \xi_i, \xi_i^* \geq 0$$

**Bài toán đối ngẫu:**
$$\max_{\alpha,\alpha^*} -\frac{1}{2}\sum_{i,j}(\alpha_i - \alpha_i^*)(\alpha_j - \alpha_j^*) x_i^T x_j - \epsilon \sum_i(\alpha_i + \alpha_i^*) + \sum_i y_i(\alpha_i - \alpha_i^*)$$
$$\text{s.t.} \quad \sum_i(\alpha_i - \alpha_i^*) = 0, \quad 0 \leq \alpha_i, \alpha_i^* \leq C$$

**Vectơ hỗ trợ:** các điểm $$x_i$$ có $$\alpha_i &amp;gt; 0$$ hoặc $$\alpha_i^* &amp;gt; 0$$.

**Bước 3: Hoàn thiện ma trận (Matrix completion)**

**Chuẩn hạt nhân (nuclear norm):** $$\lVert X \rVert_* = \sum_{i=1}^{\min(m,n)} \sigma_i(X)$$.

**Tính lồi:** Chuẩn hạt nhân là hàm lồi (tổng các giá trị kỳ dị).

**Biểu diễn dưới dạng SDP:**
$$\min_{X,U,V} \frac{1}{2}(\text{tr}(U) + \text{tr}(V))$$
$$\text{s.t.} \quad \begin{bmatrix} U &amp;amp; X \\ X^T &amp;amp; V \end{bmatrix} \succeq 0, \quad X_{ij} = M_{ij}, \; (i,j) \in \Omega$$

**Thuật toán giải:**
- **Hạ gradient cận kề (proximal gradient):** ngưỡng mềm (soft thresholding) trên các giá trị kỳ dị SVD.
- **ADMM:** phương pháp nhân tử theo hướng luân phiên.
- **Frank–Wolfe:** phương pháp gradient có điều kiện.

**Bước 4: Mã hóa thưa (Sparse coding)**

**Tính song lồi (bi-convex):** Lồi theo $$D$$ khi cố định $$\alpha$$, và lồi theo $$\alpha$$ khi cố định $$D$$ (không lồi đồng thời theo $$(D, \alpha)$$).

**Cập nhật từ điển:** $$\min_D \frac{1}{2}\lVert Y - D\alpha \rVert_F^2$$ (bài toán bình phương tối thiểu).

**Cập nhật mã thưa:** $$\min_\alpha \frac{1}{2}\lVert Y - D\alpha \rVert_F^2 + \lambda \lVert \alpha \rVert_1$$ (bài toán LASSO).

**Cực tiểu hóa luân phiên:**
1. **Bước mã hóa thưa:** giải LASSO cho từng cột của $$\alpha$$.
2. **Bước cập nhật từ điển:** giải bình phương tối thiểu kèm chuẩn hóa các cột của $$D$$.
3. Lặp lại cho đến khi hội tụ.

**Nghiệm LASSO bằng ngưỡng mềm:**
$$\alpha_j^{(k+1)} = \text{soft}(\alpha_j^{(k)} - \eta \nabla_j f, \; \eta \lambda)$$

với $$\text{soft}(x, \tau) = \text{sign}(x) \max(|x| - \tau, 0)$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-mẹo-thực-hành&quot;&gt;💡 Mẹo thực hành&lt;/h2&gt;

&lt;h4 id=&quot;khi-mô-hình-hóa-bài-toán-tối-ưu&quot;&gt;&lt;strong&gt;Khi mô hình hóa bài toán tối ưu:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nhận diện cấu trúc:&lt;/strong&gt; xác định bài toán thuộc lớp LP, QP, SOCP, SDP hay GP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra tính lồi:&lt;/strong&gt; kiểm tra đồng thời hàm mục tiêu và các ràng buộc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đưa về dạng chuẩn:&lt;/strong&gt; biến đổi để tận dụng hiệu quả các bộ giải chuyên dụng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;khi-phân-tích-tính-tối-ưu&quot;&gt;&lt;strong&gt;Khi phân tích tính tối ưu:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện KKT:&lt;/strong&gt; xác định mối liên hệ giữa điều kiện cần và điều kiện đủ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bù lỏng:&lt;/strong&gt; nhận diện các ràng buộc tích cực tại nghiệm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích độ nhạy:&lt;/strong&gt; đánh giá giá bóng và tác động khi tham số nhiễu động.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;khi-thiết-kế-thuật-toán&quot;&gt;&lt;strong&gt;Khi thiết kế thuật toán:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Khai thác cấu trúc:&lt;/strong&gt; tận dụng tính thưa, tính tách được và khả năng phân rã.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ:&lt;/strong&gt; dùng nới lỏng và làm tròn khi bài toán chính xác khó giải.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bền vững:&lt;/strong&gt; xử lý bất định và nhiễu dữ liệu một cách có hệ thống.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;dạng-chuẩn-của-bài-toán-tối-ưu-hóa-lồi&quot;&gt;&lt;strong&gt;Dạng chuẩn của bài toán tối ưu hóa lồi:&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; f_0(x) \\
\text{s.t.} \quad &amp;amp; f_i(x) \leq 0, \quad i = 1, \ldots, m \\
&amp;amp; h_i(x) = 0, \quad i = 1, \ldots, p
\end{align}\]

&lt;p&gt;với \(f_0, \ldots, f_m\) là các hàm lồi và \(h_i\) là các hàm affine.&lt;/p&gt;

&lt;h3 id=&quot;điều-kiện-tối-ưu&quot;&gt;&lt;strong&gt;Điều kiện tối ưu:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Trường hợp&lt;/th&gt;
      &lt;th&gt;Công thức / Điều kiện&lt;/th&gt;
      &lt;th&gt;Khi nào đủ cho tối ưu toàn cục&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Không ràng buộc&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\nabla f(x^*) = 0\)&lt;/td&gt;
      &lt;td&gt;\(f\) lồi và khả vi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ràng buộc đẳng thức&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\nabla f(x^*) + \sum \nu_i^* \nabla h_i(x^*) = 0\), \(h_i(x^*)=0\)&lt;/td&gt;
      &lt;td&gt;\(f\) lồi khả vi, \(h_i\) affine&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;KKT (tổng quát)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Điều kiện dừng, khả thi gốc/đối ngẫu, bù lỏng&lt;/td&gt;
      &lt;td&gt;Bài toán lồi khả vi (điều kiện Slater đảm bảo KKT là cần)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tính chất lồi&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Cực tiểu địa phương = Cực tiểu toàn cục&lt;/td&gt;
      &lt;td&gt;Bài toán lồi&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;đối-ngẫu&quot;&gt;&lt;strong&gt;Đối ngẫu:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khái niệm&lt;/th&gt;
      &lt;th&gt;Định nghĩa&lt;/th&gt;
      &lt;th&gt;Ý nghĩa&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm Lagrange&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(L(x, \lambda, \nu) = f_0(x) + \sum \lambda_i f_i(x) + \sum \nu_i h_i(x)\)&lt;/td&gt;
      &lt;td&gt;Hàm mục tiêu mở rộng theo ràng buộc&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hàm đối ngẫu&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(g(\lambda, \nu) = \inf_x L(x, \lambda, \nu)\)&lt;/td&gt;
      &lt;td&gt;Chặn dưới của giá trị tối ưu gốc&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Bài toán đối ngẫu&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\max g(\lambda, \nu)\) s.t. \(\lambda \geq 0\)&lt;/td&gt;
      &lt;td&gt;Tìm chặn dưới tốt nhất&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Đối ngẫu yếu&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(d^* \leq p^*\)&lt;/td&gt;
      &lt;td&gt;Luôn đúng với mọi bài toán&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Đối ngẫu mạnh&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(d^* = p^*\)&lt;/td&gt;
      &lt;td&gt;Điều kiện Slater \(\Rightarrow\) khe đối ngẫu bằng 0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Bù lỏng&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\lambda_i^* f_i(x^*) = 0\)&lt;/td&gt;
      &lt;td&gt;Liên hệ giữa nhân tử và ràng buộc tích cực&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;tối-ưu-hóa-tựa-lồi-quasiconvex-optimization&quot;&gt;&lt;strong&gt;Tối ưu hóa tựa lồi (Quasiconvex Optimization):&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; \(f\) là hàm tựa lồi nếu mọi tập mức dưới \(\{x : f(x) \leq \alpha\}\) đều là tập lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không bảo toàn qua phép cộng:&lt;/strong&gt; tổng \(f_1 + f_2\) của hai hàm tựa lồi nói chung không nhất thiết tựa lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy hoạch phân thức:&lt;/strong&gt; \(\min \frac{f(x)}{g(x)}\) có thể giải bằng phương pháp chia đôi (bisection) qua một chuỗi bài toán khả thi lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tối-ưu-hóa-vectơ&quot;&gt;&lt;strong&gt;Tối ưu hóa vectơ:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu Pareto:&lt;/strong&gt; không tồn tại \(y\) khả thi sao cho \(f(y) \preceq_{K} f(x)\) và \(f(y) \neq f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vô hướng hóa:&lt;/strong&gt; \(\min \lambda^T f(x)\) với \(\lambda \succ_{K^*} 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp ràng buộc \(\epsilon\):&lt;/strong&gt; cố định ngưỡng cho \(m-1\) mục tiêu và tối ưu mục tiêu còn lại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tối-ưu-hóa-ngẫu-nhiên-và-bền-vững&quot;&gt;&lt;strong&gt;Tối ưu hóa ngẫu nhiên và bền vững:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Công thức&lt;/th&gt;
      &lt;th&gt;Đặc trưng đánh đổi&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Giá trị kỳ vọng&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\min \mathbb{E}[f(x, \xi)]\)&lt;/td&gt;
      &lt;td&gt;Tối ưu hiệu năng trung bình&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Trường hợp xấu nhất&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\min \max_{\xi \in \mathcal{U}} f(x, \xi)\)&lt;/td&gt;
      &lt;td&gt;Bảo thủ, an toàn trước bất định&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ràng buộc xác suất&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\mathbb{P}[f(x, \xi) \leq 0] \geq 1 - \epsilon\)&lt;/td&gt;
      &lt;td&gt;Đảm bảo ở mức tin cậy xác suất&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Trung bình mẫu (SAA)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\min \frac{1}{N}\sum f(x, \xi_i)\)&lt;/td&gt;
      &lt;td&gt;Xấp xỉ khả giải từ dữ liệu mẫu&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;các-kỹ-thuật-nới-lỏng&quot;&gt;&lt;strong&gt;Các kỹ thuật nới lỏng:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng LP:&lt;/strong&gt; \(x \in \{0,1\}^n \to x \in [0,1]^n\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng SDP:&lt;/strong&gt; \(xx^T \to X \succeq 0\), \(X_{ii} = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng Lagrange:&lt;/strong&gt; đưa các ràng buộc phức tạp vào hàm mục tiêu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Làm tròn ngẫu nhiên:&lt;/strong&gt; chuyển nghiệm phân số hoặc nghiệm ma trận về nghiệm nguyên.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 Tài liệu tham khảo&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 4: Convex Optimization Problems&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ben-Tal, A., &amp;amp; Nemirovski, A.&lt;/strong&gt; (2001). &lt;em&gt;Lectures on Modern Convex Optimization&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bertsekas, D. P.&lt;/strong&gt; (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt;. Athena Scientific.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Shapiro, A., Dentcheva, D., &amp;amp; Ruszczyński, A.&lt;/strong&gt; (2009). &lt;em&gt;Lectures on Stochastic Programming&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Williamson, D. P., &amp;amp; Shmoys, D. B.&lt;/strong&gt; (2011). &lt;em&gt;The Design of Approximation Algorithms&lt;/em&gt;. Cambridge University Press.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>04-10 Bài tập trắc nghiệm - Cơ bản tối ưu hóa lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_10_Quiz_Convex_Optimization_Basics/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_10_Quiz_Convex_Optimization_Basics</id>
   <content type="html">&lt;p&gt;Đọc hiểu một định lý khi lời giải đã viết sẵn trên giấy luôn tạo cảm giác “dễ dàng đến lạ” — các nhà tâm lý học nhận thức gọi đó là &lt;em&gt;ảo giác thông thạo&lt;/em&gt;. Phép thử thực sự chỉ bắt đầu khi bạn đứng trước một phát biểu đánh lạc hướng rất tinh vi: một ràng buộc đẳng thức \(x_1^2 + x_2^2 = 1\) trông có vẻ “đều đặn”, hay một hàm mục tiêu lồi có hai điểm cực tiểu riêng biệt… liệu có tồn tại hay không?&lt;/p&gt;

&lt;p&gt;Bộ bài tập trắc nghiệm này được thiết kế như một phòng thí nghiệm chẩn đoán cho toàn bộ Chương 04. Thay vì đoán mò theo trực giác mơ hồ, hãy dùng mỗi câu hỏi để rèn thói quen phản xạ chuẩn của người làm tối ưu: kiểm tra miền xác định, kiểm tra độ cong Hessian, kiểm tra điều kiện bậc nhất và tìm phản ví dụ nhỏ nhất ngay khi nghi ngờ một mệnh đề sai.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-điểm-mù-hay-gặp-nhất-trong-chương-04&quot;&gt;Kiến thức cần nhớ: Bốn “điểm mù” hay gặp nhất trong Chương 04&lt;/h2&gt;

&lt;p&gt;Trước khi bắt đầu làm bài, hãy rà soát bốn bẫy tư duy kinh điển mà các câu hỏi trắc nghiệm thường khai thác:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 1 — Đẳng thức phi affine:&lt;/strong&gt; Nhiều người thấy \(g(x) = x_1^2 + x_2^2 - 1\) là hàm lồi nên vội kết luận bài toán có ràng buộc \(x_1^2 + x_2^2 = 1\) là bài toán lồi. Sai! Ràng buộc đẳng thức trong tối ưu lồi bắt buộc phải là hàm &lt;strong&gt;affine&lt;/strong&gt; (\(a^T x = b\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 2 — Gradient bằng 0 vs. Bất đẳng thức biến phân:&lt;/strong&gt; \(\nabla f(x^\star) = 0\) chỉ là điều kiện cần và đủ cho bài toán &lt;em&gt;không ràng buộc&lt;/em&gt; (hoặc khi \(x^\star\) nằm hoàn toàn trong phần trong của tập khả thi). Trên biên tập khả thi, \(\nabla f(x^\star)\) có thể khác 0 miễn là \(\nabla f(x^\star)^T (y - x^\star) \ge 0\) với mọi \(y\) khả thi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 3 — Lồi vs. Lồi chặt và Số lượng nghiệm:&lt;/strong&gt; Bài toán lồi có thể vô nghiệm, có 1 nghiệm, hoặc có &lt;strong&gt;vô số nghiệm&lt;/strong&gt; tạo thành một tập lồi (không bao giờ có đúng 2 nghiệm rời rạc!). Chỉ khi hàm mục tiêu &lt;strong&gt;lồi chặt&lt;/strong&gt; mới đảm bảo nhiều nhất 1 nghiệm tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 4 — Phép biến đổi tương đương vs. Phép nới lỏng:&lt;/strong&gt; Đổi biến song ánh hay biến đổi đơn điệu tăng giữ nguyên nghiệm tối ưu (\(f_{\text{new}}^\star\) tương ứng 1-1 với \(f^\star\)), còn nới lỏng mở rộng tập khả thi nên chỉ cho cận dưới \(f_{\text{relax}}^\star \le f^\star\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-thực-hành-phản-xạ-30-giây-kiểm-tra-một-mệnh-đề-trắc-nghiệm&quot;&gt;Giải thích: Thực hành phản xạ “30 giây kiểm tra một mệnh đề trắc nghiệm”&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi mẫu:&lt;/strong&gt; &lt;em&gt;Xét bài toán \(\min_{x \in \mathbb{R}^2} \; f(x) = x_1^2 + x_2\) trên tập \(C = \{x : x_1 \ge 0,\; x_2 \ge 0,\; x_1 + x_2 \ge 1\}\). Điểm \(x^\star = (0.5, 0.5)\) có phải là nghiệm tối ưu toàn cục không?&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Kiểm tra bài toán có lồi không:&lt;/strong&gt; \(f(x) = x_1^2 + x_2\) có Hessian \(\begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{pmatrix} \succeq 0\) (lồi); \(C\) là giao của 3 nửa không gian (lồi). Vậy điều kiện bậc nhất vừa cần vừa đủ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tính gradient tại điểm đề xuất \(x^\star = (0.5, 0.5)\):&lt;/strong&gt;
\(\nabla f(x_1, x_2) = (2x_1,\; 1)^T \implies \nabla f(0.5, 0.5) = (1,\; 1)^T.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kiểm tra tích vô hướng \(\nabla f(x^\star)^T (y - x^\star)\) với mọi \(y \in C\):&lt;/strong&gt;
\(\nabla f(x^\star)^T (y - x^\star) = 1 \cdot (y_1 - 0.5) + 1 \cdot (y_2 - 0.5) = (y_1 + y_2) - 1.\)
Vì mọi \(y \in C\) đều thỏa \(y_1 + y_2 \ge 1\), ta có \((y_1 + y_2) - 1 \ge 0\) luôn đúng!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận chắc chắn:&lt;/strong&gt; Dù \(\nabla f(0.5, 0.5) = (1,1)^T \neq 0\), điểm \((0.5, 0.5)\) vẫn là &lt;strong&gt;nghiệm tối ưu toàn cục&lt;/strong&gt; (với \(f^\star = 0.25 + 0.5 = 0.75\)). Nhờ kiểm tra đại số 3 bước này, bạn không bao giờ bị đánh lừa bởi trực giác cảm tính.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra hiểu biết của bạn về các khái niệm cơ bản trong tối ưu hóa lồi, bao gồm thuật ngữ, điều kiện tối ưu và các kỹ thuật biến đổi.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-bài-toán-tối-ưu-hóa-lồi&quot;&gt;🎯 &lt;strong&gt;Bài Toán Tối Ưu Hóa Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Dạng chuẩn:&lt;/strong&gt;
\(\begin{aligned}
&amp;amp;\min_{x \in D} &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;g_i(x) \le 0, \quad i = 1, \ldots, m \\
&amp;amp;&amp;amp;&amp;amp;h_j(x) = 0, \quad j = 1, \ldots, r
\end{aligned}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện lồi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f, g_i\) là hàm lồi&lt;/li&gt;
  &lt;li&gt;\(h_j\) là hàm affine: \(h_j(x) = a_j^T x + b_j\)&lt;/li&gt;
  &lt;li&gt;
\[D = \text{dom}(f) \cap \bigcap_{i=1}^m \text{dom}(g_i) \cap \bigcap_{j=1}^r \text{dom}(h_j)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-thuật-ngữ-cơ-bản&quot;&gt;📝 &lt;strong&gt;Thuật Ngữ Cơ Bản&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Các khái niệm quan trọng:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mục tiêu:&lt;/strong&gt; \(f(x)\) - hàm cần tối thiểu hóa&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc bất đẳng thức:&lt;/strong&gt; \(g_i(x) \le 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc đẳng thức:&lt;/strong&gt; \(h_j(x) = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm khả thi:&lt;/strong&gt; \(x\) thỏa mãn tất cả ràng buộc&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giá trị tối ưu:&lt;/strong&gt; \(f^* = \min\{f(x) \mid x \text{ khả thi}\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiệm tối ưu:&lt;/strong&gt; \(x^*\) khả thi và \(f(x^*) = f^*\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\epsilon\)-cận tối ưu (dưới tối ưu):&lt;/strong&gt; \(x\) khả thi và \(f(x) \le f^* + \epsilon\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc tích cực (hoạt động):&lt;/strong&gt; \(g_i(x^*) = 0\) tại nghiệm tối ưu&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tập khả thi:&lt;/strong&gt;
\(S = \{x \in D \mid g_i(x) \le 0, h_j(x) = 0\}\)&lt;/p&gt;

&lt;h3 id=&quot;-tính-chất-tập-nghiệm&quot;&gt;🔵 &lt;strong&gt;Tính Chất Tập Nghiệm&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Tính chất 1:&lt;/strong&gt; Tập nghiệm \(X_{\text{opt}}\) của bài toán lồi là tập lồi&lt;/p&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh:&lt;/strong&gt; Nếu \(x, y \in X_{\text{opt}}\) và \(0 \le \theta \le 1\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\theta x + (1-\theta)y\) khả thi (do tính lồi của tập khả thi)&lt;/li&gt;
    &lt;li&gt;
\[f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y) = f^*\]
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Tính chất 2:&lt;/strong&gt; Nếu \(f\) lồi chặt thì nghiệm (nếu tồn tại) là duy nhất&lt;/p&gt;

&lt;h3 id=&quot;-điều-kiện-tối-ưu&quot;&gt;✅ &lt;strong&gt;Điều Kiện Tối Ưu&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện bậc nhất (hàm khả vi):&lt;/strong&gt;
Với bài toán \(\min_x f(x)\) s.t. \(x \in C\):
\(\nabla f(x^*)^T (y - x^*) \ge 0 \quad \forall y \in C\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trường hợp không ràng buộc:&lt;/strong&gt; \(C = \mathbb{R}^n\)
\(\nabla f(x^*) = 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện bậc hai (hàm khả vi hai lần):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện cần:&lt;/strong&gt; \(\nabla f(x^*) = 0\) và \(\nabla^2 f(x^*) \succeq 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện đủ:&lt;/strong&gt; \(\nabla f(x^*) = 0\) và \(\nabla^2 f(x^*) \succ 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa Hessian:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\nabla^2 f(x^*) \succ 0\): cực tiểu địa phương chặt&lt;/li&gt;
  &lt;li&gt;\(\nabla^2 f(x^*) \prec 0\): cực đại địa phương chặt&lt;/li&gt;
  &lt;li&gt;\(\nabla^2 f(x^*)\) bất định: điểm yên ngựa&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-biến-phụ-slack-variables&quot;&gt;🔄 &lt;strong&gt;Biến Phụ (Slack Variables)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Mục đích:&lt;/strong&gt; Chuyển ràng buộc bất đẳng thức thành đẳng thức&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Biến đổi:&lt;/strong&gt;
\(g_i(x) \le 0 \quad \Rightarrow \quad g_i(x) + s_i = 0, \quad s_i \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán gốc:&lt;/strong&gt;
\(\begin{aligned}
&amp;amp;\min_x &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;g_i(x) \le 0
\end{aligned}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Với biến phụ:&lt;/strong&gt;
\(\begin{aligned}
&amp;amp;\min_{x,s} &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;g_i(x) + s_i = 0 \\
&amp;amp;&amp;amp;&amp;amp;s_i \ge 0
\end{aligned}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(s_i &amp;gt; 0\): ràng buộc \(i\) không tích cực (không hoạt động)&lt;/li&gt;
  &lt;li&gt;\(s_i = 0\): ràng buộc \(i\) tích cực (chặt)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Chỉ bảo toàn tính lồi khi \(g_i(x)\) là hàm affine&lt;/p&gt;

&lt;h3 id=&quot;-nới-lỏng-relaxation--làm-giản&quot;&gt;🔧 &lt;strong&gt;Nới Lỏng (Relaxation / Làm Giản)&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa:&lt;/strong&gt; Thay thế tập khả thi \(C\) bằng siêu tập \(\tilde{C} \supseteq C\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Bài toán gốc:&lt;/strong&gt; \(\min_x f(x)\) s.t. \(x \in C\)
&lt;strong&gt;Bài toán nới lỏng:&lt;/strong&gt; \(\min_x f(x)\) s.t. \(x \in \tilde{C}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất:&lt;/strong&gt; Giá trị tối ưu của bài toán nới lỏng \(\le\) giá trị tối ưu gốc&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ quan trọng:&lt;/strong&gt; Nới lỏng ràng buộc đẳng thức
\(h_j(x) = 0 \quad \Rightarrow \quad h_j(x) \le 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ứng dụng:&lt;/strong&gt; Chuyển bài toán phi lồi thành lồi (khi \(h_j\) lồi nhưng phi-affine)&lt;/p&gt;

&lt;h3 id=&quot;-các-kỹ-thuật-biến-đổi-khác&quot;&gt;🎲 &lt;strong&gt;Các Kỹ Thuật Biến Đổi Khác&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Loại bỏ ràng buộc đẳng thức:&lt;/strong&gt;
Nếu \(Ax = b\) có nghiệm, có thể tham số hóa:
\(x = x_0 + Fz\) với \(Ax_0 = b\) và \(\text{range}(F) = \text{null}(A)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đổi biến:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Thay đổi biến để đơn giản hóa bài toán&lt;/li&gt;
  &lt;li&gt;Bảo toàn tính lồi qua phép biến đổi affine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tách biến:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tách bài toán lớn thành các bài toán con nhỏ hơn&lt;/li&gt;
  &lt;li&gt;Sử dụng cấu trúc đặc biệt của bài toán&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-so-sánh-các-phương-pháp&quot;&gt;📊 &lt;strong&gt;So Sánh Các Phương Pháp&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Kỹ thuật&lt;/th&gt;
      &lt;th&gt;Mục đích&lt;/th&gt;
      &lt;th&gt;Ưu điểm&lt;/th&gt;
      &lt;th&gt;Nhược điểm&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Biến phụ&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Chuyển bất đẳng thức → đẳng thức&lt;/td&gt;
      &lt;td&gt;Đơn giản hóa thuật toán&lt;/td&gt;
      &lt;td&gt;Tăng số biến&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Nới lỏng (làm giản)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Mở rộng tập khả thi&lt;/td&gt;
      &lt;td&gt;Chuyển phi lồi → lồi&lt;/td&gt;
      &lt;td&gt;Nghiệm có thể không khả thi với bài toán gốc&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Loại bỏ ràng buộc&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Giảm số ràng buộc&lt;/td&gt;
      &lt;td&gt;Giảm chiều bài toán&lt;/td&gt;
      &lt;td&gt;Yêu cầu phân tích đặc biệt&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;-nhận-biết-bài-toán-lồi&quot;&gt;🔍 &lt;strong&gt;Nhận Biết Bài Toán Lồi&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Checklist:&lt;/strong&gt;&lt;/p&gt;
&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Hàm mục tiêu \(f\) lồi?&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Ràng buộc bất đẳng thức \(g_i\) lồi?&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Ràng buộc đẳng thức \(h_j\) affine?&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Miền xác định \(D\) lồi?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Nếu tất cả ✓ → Bài toán tối ưu hóa lồi&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Lưu ý:&lt;/strong&gt; Trong tối ưu hóa lồi, mọi cực tiểu địa phương đều là cực tiểu toàn cục, giúp các thuật toán giải bài toán đạt độ tin cậy cao.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Bài tập trắc nghiệm: Cơ bản tối ưu hóa lồi&lt;/h2&gt;
        &lt;p&gt;Chọn đáp án đúng nhất cho mỗi câu hỏi. Bài tập tập trung vào các khái niệm cơ bản và thực tế trong tối ưu hóa lồi.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Câu hỏi 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Câu hỏi 1: Định nghĩa bài toán tối ưu hóa lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Câu 1: Trong bài toán tối ưu hóa lồi, hàm ràng buộc đẳng thức $$h_j(x) = 0$$ phải là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Hàm lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Hàm lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Hàm affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Hàm bất kỳ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Hàm affine&lt;/strong&gt;&lt;br /&gt;
                Trong bài toán tối ưu hóa lồi, các hàm ràng buộc đẳng thức $$h_j(x) = 0$$ phải là hàm affine để đảm bảo tập khả thi là tập lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Điểm khả thi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Điểm $$x$$ được gọi là khả thi nếu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) $$x \in D$$ và $$g_i(x) \leq 0$$ với mọi $$i$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) $$x \in D$$, $$g_i(x) \leq 0$$ với mọi $$i$$, và $$h_j(x) = 0$$ với mọi $$j$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Chỉ cần $$f(x)$$ xác định&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) $$x$$ là nghiệm tối ưu&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$x \in D$$, $$g_i(x) \leq 0$$ với mọi $$i$$, và $$h_j(x) = 0$$ với mọi $$j$$&lt;/strong&gt;&lt;br /&gt;
                Điểm khả thi phải thỏa mãn tất cả các điều kiện: nằm trong miền xác định và thỏa mãn tất cả ràng buộc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Ràng buộc hoạt động --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Ràng buộc $$g_i(x) \leq 0$$ được gọi là &quot;hoạt động&quot; tại $$x$$ khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) $$g_i(x) &amp;lt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) $$g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) $$g_i(x) &amp;gt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) $$g_i(x) \leq -1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$g_i(x) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Ràng buộc hoạt động có nghĩa là nó được thỏa mãn với đẳng thức, tức là $$g_i(x) = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Điểm ε-dưới tối ưu --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Điểm $$x$$ được gọi là $$\epsilon$$-dưới tối ưu nếu:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$f(x) = f^* + \epsilon$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) $$f(x) \leq f^* + \epsilon$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) $$f(x) \geq f^* - \epsilon$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) $$|f(x) - f^*| \leq \epsilon$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$f(x) \leq f^* + \epsilon$$&lt;/strong&gt;&lt;br /&gt;
                Điểm $$\epsilon$$-dưới tối ưu có giá trị hàm mục tiêu không vượt quá giá trị tối ưu cộng với $$\epsilon$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Tính chất tập nghiệm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Tập nghiệm $$X_{opt}$$ của bài toán tối ưu hóa lồi có tính chất:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Luôn là tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) Có thể không lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Luôn chứa duy nhất một điểm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Luôn là tập rỗng&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Luôn là tập lồi&lt;/strong&gt;&lt;br /&gt;
                Tập nghiệm của bài toán tối ưu hóa lồi luôn là tập lồi, đây là một tính chất quan trọng.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Nghiệm duy nhất --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Bài toán tối ưu hóa lồi có nghiệm duy nhất khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) Hàm mục tiêu $$f$$ là lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) Hàm mục tiêu $$f$$ là lồi chặt&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) Tập khả thi bị chặn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) Có ràng buộc đẳng thức&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Hàm mục tiêu $$f$$ là lồi chặt&lt;/strong&gt;&lt;br /&gt;
                Khi hàm mục tiêu là lồi chặt, nghiệm tối ưu (nếu tồn tại) là duy nhất vì không có đoạn phẳng nào trên đồ thị.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: Điều kiện tối ưu bậc nhất --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Với bài toán $$\min_x f(x)$$ s.t. $$x \in C$$, điều kiện tối ưu bậc nhất là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) $$\nabla f(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) $$\nabla f(x)^T(y-x) \geq 0$$ với mọi $$y \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) $$\nabla f(x)^T(y-x) \leq 0$$ với mọi $$y \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) $$f(x) \leq f(y)$$ với mọi $$y \in C$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\nabla f(x)^T(y-x) \geq 0$$ với mọi $$y \in C$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện bậc nhất cho tính tối ưu yêu cầu không có hướng khả thi nào là hướng giảm: $$-\nabla f(x)$$ không được chỉ vào trong tập khả thi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: Trường hợp không ràng buộc --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: Với bài toán không ràng buộc $$\min_x f(x)$$ ($$C = \mathbb{R}^n$$), điều kiện tối ưu là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) $$\nabla f(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) $$\nabla^2 f(x) \succ 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) $$f(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) $$x = 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\nabla f(x) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Với bài toán không ràng buộc, điều kiện tối ưu bậc nhất trở thành $$\nabla f(x) = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: Ma trận Hessian --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Ma trận Hessian $$\nabla^2 f(x)$$ cung cấp thông tin về:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) Độ dốc của hàm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) Độ cong của hàm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) Giá trị của hàm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) Miền xác định của hàm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Độ cong của hàm&lt;/strong&gt;&lt;br /&gt;
                Ma trận Hessian chứa các đạo hàm bậc hai, cung cấp thông tin về độ cong của hàm tại một điểm.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: Điều kiện bậc hai đủ --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Điều kiện đủ cho cực tiểu địa phương chặt là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) $$\nabla f(x) = 0$$ và $$\nabla^2 f(x) \succeq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) $$\nabla f(x) = 0$$ và $$\nabla^2 f(x) \succ 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Chỉ cần $$\nabla f(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) $$\nabla^2 f(x) \prec 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\nabla f(x) = 0$$ và $$\nabla^2 f(x) \succ 0$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện đủ cho cực tiểu địa phương chặt yêu cầu gradient bằng 0 và Hessian xác định dương.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Biến phụ --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Biến phụ $$s_i$$ được giới thiệu để:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Chuyển ràng buộc bất đẳng thức thành đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Chuyển ràng buộc đẳng thức thành bất đẳng thức&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Tăng số biến trong bài toán&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Giảm độ phức tạp tính toán&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Chuyển ràng buộc bất đẳng thức thành đẳng thức&lt;/strong&gt;&lt;br /&gt;
                Biến phụ được sử dụng để biến đổi $$g_i(x) \leq 0$$ thành $$g_i(x) + s_i = 0$$ với $$s_i \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Ý nghĩa biến phụ --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Khi $$s_i &amp;gt; 0$$ tại nghiệm tối ưu, điều này có nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Ràng buộc $$g_i(x) \leq 0$$ hoạt động&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Ràng buộc $$g_i(x) \leq 0$$ không hoạt động&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Bài toán không khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Nghiệm không tối ưu&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Ràng buộc $$g_i(x) \leq 0$$ không hoạt động&lt;/strong&gt;&lt;br /&gt;
                Khi $$s_i &amp;gt; 0$$, ta có $$g_i(x) = -s_i &amp;lt; 0$$, nghĩa là ràng buộc không hoạt động (có &quot;khoảng trống&quot;).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Bảo toàn tính lồi với biến phụ --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Biến đổi biến phụ bảo toàn tính lồi khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) $$g_i(x)$$ là hàm lồi bất kỳ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) $$g_i(x)$$ là hàm affine&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) $$g_i(x)$$ là hàm lõm&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Luôn bảo toàn tính lồi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$g_i(x)$$ là hàm affine&lt;/strong&gt;&lt;br /&gt;
                Biến đổi biến phụ chỉ bảo toàn tính lồi khi $$g_i(x)$$ là hàm affine. Với hàm phi tuyến, có thể phá hủy tính lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Làm giản (Relaxation) --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Kỹ thuật làm giản thay đổi tập miền $$C$$ thành $$\tilde{C}$$ sao cho:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) $$\tilde{C} \subseteq C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) $$\tilde{C} \supseteq C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) $$\tilde{C} = C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) $$\tilde{C} \cap C = \emptyset$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\tilde{C} \supseteq C$$&lt;/strong&gt;&lt;br /&gt;
                Làm giản mở rộng tập miền khả thi, tức là $$\tilde{C}$$ chứa $$C$$ như một tập con.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Giá trị tối ưu sau làm giản --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Sau khi làm giản, giá trị tối ưu $$\tilde{f}^*$$ so với giá trị gốc $$f^*$$:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) $$\tilde{f}^* \geq f^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) $$\tilde{f}^* \leq f^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) $$\tilde{f}^* = f^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Không có mối quan hệ cố định&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\tilde{f}^* \leq f^*$$&lt;/strong&gt;&lt;br /&gt;
                Vì tối ưu hóa trên tập miền lớn hơn, giá trị tối ưu sau làm giản không thể lớn hơn giá trị gốc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Làm giản ràng buộc đẳng thức --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Làm giản ràng buộc đẳng thức $$h_j(x) = 0$$ thành:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) $$h_j(x) \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) $$h_j(x) \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) $$|h_j(x)| \leq \epsilon$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Loại bỏ ràng buộc&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$h_j(x) \leq 0$$&lt;/strong&gt;&lt;br /&gt;
                Khi $$h_j(x)$$ là hàm lồi phi-affine, có thể làm giản $$h_j(x) = 0$$ thành $$h_j(x) \leq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Tập khả thi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Tập khả thi của bài toán tối ưu hóa lồi có tính chất:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Luôn là tập lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Có thể không lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Luôn bị chặn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Luôn không rỗng&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Luôn là tập lồi&lt;/strong&gt;&lt;br /&gt;
                Trong bài toán tối ưu hóa lồi, tập khả thi luôn là tập lồi do các ràng buộc lồi và affine.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Polytope --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: Trong quy hoạch tuyến tính, tập khả thi bị chặn được gọi là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Polyhedron&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Polytope&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Simplex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Ellipsoid&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Polytope&lt;/strong&gt;&lt;br /&gt;
                Polytope là tập khả thi bị chặn trong quy hoạch tuyến tính, trong khi polyhedron có thể không bị chặn.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Nghiệm tại đỉnh --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Trong quy hoạch tuyến tính, nếu nghiệm tối ưu tồn tại, nó có thể được tìm thấy tại:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Điểm bất kỳ trong tập khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) Tâm của tập khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) Một trong các đỉnh của tập khả thi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) Biên của tập khả thi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: C) Một trong các đỉnh của tập khả thi&lt;/strong&gt;&lt;br /&gt;
                Đây là cơ sở cho thuật toán Simplex: nghiệm tối ưu của LP luôn có thể tìm thấy tại một đỉnh.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Ưu điểm tối ưu hóa lồi --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Ưu điểm chính của bài toán tối ưu hóa lồi là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Luôn có nghiệm duy nhất&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Mọi cực tiểu địa phương đều là cực tiểu toàn cục&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Tính toán nhanh hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Không cần điều kiện tối ưu&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Mọi cực tiểu địa phương đều là cực tiểu toàn cục&lt;/strong&gt;&lt;br /&gt;
                Đây là tính chất quan trọng nhất của tối ưu hóa lồi, đảm bảo không có vấn đề &quot;mắc kẹt&quot; tại cực tiểu địa phương.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Trong bài toán tối ưu lồi, điều kiện KKT là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Đủ cho tối ưu, và cũng cần thiết khi điều kiện Slater thỏa mãn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Chỉ cần thiết&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Chỉ đủ&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Không liên quan&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Đủ cho tối ưu, và cũng cần thiết khi điều kiện Slater thỏa mãn&lt;/strong&gt;&lt;br /&gt;
                Đối với bài toán tối ưu lồi, điều kiện KKT luôn đủ cho tối ưu toàn cục; chúng cũng cần thiết khi có điều kiện chính quy như Slater (khi đó đối ngẫu mạnh đúng). Không có Slater, nghiệm tối ưu có thể không thỏa KKT (ví dụ $$\min x$$ với $$x^2 \leq 0$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Bài toán $$\min x^2 + y^2$$ với $$x + y \geq 1$$ có nghiệm là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$x = 0.5, y = 0.5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$x = 1, y = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$x = 0, y = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Không có nghiệm&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$x = 0.5, y = 0.5$$&lt;/strong&gt;&lt;br /&gt;
                Sử dụng phương pháp Lagrange với ràng buộc tích cực $$x + y = 1$$, ta được $$x = y = 0.5$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: Hàm Lagrange của bài toán $$\min f(x)$$ với $$g(x) \leq 0$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$L(x,\lambda) = f(x) + \lambda g(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$L(x,\lambda) = f(x) - \lambda g(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$L(x,\lambda) = f(x) + \lambda^2 g(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$L(x,\lambda) = f(x) \cdot \lambda g(x)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$L(x,\lambda) = f(x) + \lambda g(x)$$&lt;/strong&gt;&lt;br /&gt;
                Hàm Lagrange chuẩn có dạng $$L(x,\lambda) = f(x) + \lambda g(x)$$ với $$\lambda \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Điều kiện bù lỏng (complementary slackness) trong KKT là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$\lambda_i g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$\lambda_i + g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$\lambda_i - g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) $$\lambda_i \cdot g_i(x) = 1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\lambda_i g_i(x) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Điều kiện bù lỏng $$\lambda_i g_i(x) = 0$$ đảm bảo rằng với mỗi ràng buộc, hoặc ràng buộc đó tích cực ($$g_i(x) = 0$$) hoặc nhân tử Lagrange tương ứng bằng 0 ($$\lambda_i = 0$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Trong bài toán QP: $$\min \frac{1}{2}x^T P x + q^T x$$, ma trận $$P$$ phải:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Nửa xác định dương&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Xác định dương&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Đối xứng&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Cả A và C&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Cả A và C&lt;/strong&gt;&lt;br /&gt;
                Để bài toán QP là lồi, ma trận $$P$$ phải nửa xác định dương và đối xứng.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Câu trước&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Câu tiếp&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Kết quả bài tập&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #E91E63, #9C27B0);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #E91E63;
    background-color: #fce4ec;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #E91E63;
    background-color: #f8bbd9;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #fce4ec;
    border-left: 4px solid #E91E63;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #AD1457;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #E91E63;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #C2185B;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #fce4ec;
    border-radius: 8px;
    border: 2px solid #E91E63;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #AD1457;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng cho từng câu hỏi
const correctAnswers = {
    q1: &apos;c&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;a&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;b&apos;, q10: &apos;b&apos;,
    q11: &apos;a&apos;, q12: &apos;b&apos;, q13: &apos;b&apos;, q14: &apos;b&apos;, q15: &apos;b&apos;,
    q16: &apos;b&apos;, q17: &apos;a&apos;, q18: &apos;b&apos;, q19: &apos;c&apos;, q20: &apos;b&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;d&apos;};

/**
 * Cập nhật thanh tiến trình và hiển thị câu hỏi hiện tại
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Câu hỏi ${currentQuestion}/${totalQuestions}`;
}

/**
 * Hiển thị câu hỏi theo số thứ tự
 */
function showQuestion(questionNum) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Cập nhật trạng thái nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Chuyển đến câu hỏi tiếp theo
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Quay lại câu hỏi trước
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Lưu đáp án của người dùng
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Cập nhật giao diện để hiển thị đáp án đã chọn
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Nộp bài và hiển thị kết quả
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Tính điểm và tạo báo cáo chi tiết
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Hiển thị giải thích cho tất cả câu hỏi
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Tạo báo cáo chi tiết
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Câu ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Đúng&apos; : &apos;Sai&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Đáp án của bạn: ${userAnswer || &apos;Chưa trả lời&apos;} | Đáp án đúng: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Hiển thị kết quả
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Điểm số: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Xuất sắc! Bạn đã nắm vững cơ bản tối ưu hóa lồi!&apos; : 
              scorePercentage &gt;= 60 ? &apos;👍 Khá tốt! Hãy ôn lại một số khái niệm cơ bản.&apos; : 
              scorePercentage &gt;= 40 ? &apos;📚 Cần ôn tập thêm về thuật ngữ và điều kiện tối ưu.&apos; : &apos;💪 Hãy đọc lại lý thuyết cơ bản về tối ưu hóa lồi!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Khởi động lại bài tập
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn kết quả và hiển thị lại điều hướng
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Xóa tất cả lựa chọn
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>04-08 Làm giản</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_08_Relaxation/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_08_Relaxation</id>
   <content type="html">&lt;p&gt;Trong khoa học máy tính và kỹ thuật, rất nhiều bài toán quan trọng nhất lại là bài toán &lt;strong&gt;NP-khó&lt;/strong&gt;: chọn tập hợp máy chủ tốt nhất (\(x_i \in \{0, 1\}\)), tìm ma trận hạng thấp nhất để gợi ý phim (\(\operatorname{rank}(X) \le r\)), hay giải bài toán cắt đồ thị cực đại (Max-Cut). Nếu cố tìm nghiệm chính xác cho 1.000 biến nhị phân, số tổ hợp \(2^{1000}\) lớn hơn cả số nguyên tử trong vũ trụ quan sát được!&lt;/p&gt;

&lt;p&gt;Lối thoát kinh điển của tối ưu hóa lồi là &lt;strong&gt;kỹ thuật nới lỏng (Relaxation)&lt;/strong&gt;: thay vì bám chặt vào tập khả thi \(C\) khó nhằn, ta nới rộng nó thành một tập lồi \(\tilde{C} \supseteq C\) dễ giải hơn nhiều. Cái giá phải trả là nghiệm nới lỏng có thể không còn nằm trong \(C\), nhưng phần thưởng lại vô cùng to lớn: ta lập tức có một &lt;strong&gt;cận dưới chắc chắn&lt;/strong&gt; \(f_{\text{relax}}^\star \le f^\star\) và một bàn đạp vàng để làm tròn về nghiệm khả thi chất lượng cao.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-nguyên-lý-cốt-lõi-của-nới-lỏng-lồi&quot;&gt;Kiến thức cần nhớ: Nguyên lý cốt lõi của Nới lỏng Lồi&lt;/h2&gt;

&lt;p&gt;Để hiểu vì sao nới lỏng vừa là công cụ lý thuyết vừa là vũ khí thực chiến mạnh nhất trong tối ưu hóa tổ hợp và học máy, hãy nhớ ba trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính đơn điệu theo tập khả thi (Feasible Set Enlargement):&lt;/strong&gt; Nếu \(C \subseteq \tilde{C}\), thì tập các giá trị \(f(x)\) trên \(\tilde{C}\) rộng hơn trên \(C\), do đó \(\min_{x \in \tilde{C}} f(x) \le \min_{x \in C} f(x)\). Đặc biệt, nếu nghiệm tối ưu \(\tilde{x}^\star\) của bài toán nới lỏng tình cờ nằm trong \(C\), thì ta đã tìm được &lt;strong&gt;nghiệm tối ưu chính xác&lt;/strong&gt; của bài toán gốc!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng tuyến tính &amp;amp; Bao lồi (LP Relaxation &amp;amp; Convex Hull):&lt;/strong&gt; Ví dụ phổ biến nhất là nới lỏng biến nhị phân \(x_i \in \{0, 1\}\) thành đoạn liên tục \(0 \le x_i \le 1\), hoặc nới lỏng chuẩn đếm \(\ell_0\) (số phần tử khác 0) thành chuẩn \(\ell_1\) (Lasso), hay nới lỏng hạng ma trận thành chuẩn hạt nhân (nuclear norm).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng đẳng thức phi affine thành bất đẳng thức lồi:&lt;/strong&gt; Khi gặp ràng buộc kiểu \(g(x) = 0\) với \(g\) lồi (không phải affine), ta không thể giải trực tiếp bằng tối ưu lồi. Việc nới lỏng thành \(g(x) \le 0\) biến tập khả thi thành tập lồi; trong nhiều bài toán vật lý và tài chính, tính đơn điệu của hàm mục tiêu tự động đẩy nghiệm ép sát về lại biên \(g(x^\star) = 0\) (gọi là &lt;em&gt;nới lỏng chặt — exact relaxation&lt;/em&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-cận-dưới-nới-lỏng-và-kiểm-chứng-trường-hợp-nới-lỏng-chặt&quot;&gt;Giải thích: Tính tay cận dưới nới lỏng và kiểm chứng trường hợp “nới lỏng chặt”&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 1 — Nới lỏng bài toán nguyên (có khoảng cách nới lỏng):&lt;/strong&gt;
\(\min \; f(x) = -5x_1 - 4x_2 \quad \text{thỏa mãn} \quad 2x_1 + x_2 \le 3,\quad x_1, x_2 \in \{0, 1\}.\)&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giải bài toán gốc (thử 4 tổ hợp nhị phân):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\((0,0) \to 0\); \((1,0) \to -5\); \((0,1) \to -4\); \((1,1) \to\) vi phạm \(2(1)+1 = 3 \le 3\)? Khoan! \(2(1) + 1 = 3 \le 3\) thỏa mãn! Đổi ràng buộc thành \(2x_1 + 2x_2 \le 3\) để thấy rõ sự khác biệt: khi đó \((1,1)\) cho \(4 &amp;gt; 3\) (không khả thi), nên nghiệm nguyên tối ưu là \(x^\star = (1, 0)\) với \(f^\star = -5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nới lỏng sang \(x_1, x_2 \in [0, 1]\) với ràng buộc \(2x_1 + 2x_2 \le 3\):&lt;/strong&gt;
Ta có thể đặt \(x_1 = 1\) và đẩy \(x_2\) lên \(0.5\) (vì \(2(1) + 2(0.5) = 3\)). Khi đó \(\tilde{x}^\star = (1, 0.5)\) cho giá trị \(f_{\text{relax}}^\star = -5(1) - 4(0.5) = -7\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng bất đẳng thức cận dưới:&lt;/strong&gt; \(f_{\text{relax}}^\star = -7 \le -5 = f^\star\). Khoảng cách nới lỏng (integrality gap) là \(2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ 2 — Nới lỏng chặt đẳng thức phi affine:&lt;/strong&gt;
Xét \(\min_{x \in \mathbb{R}^2} \; (-x_1 - x_2)\) thỏa mãn đẳng thức đường tròn phi lồi \(x_1^2 + x_2^2 = 2\).&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Nới lỏng thành hình tròn lồi \(x_1^2 + x_2^2 \le 2\).&lt;/li&gt;
  &lt;li&gt;Vì hàm mục tiêu \(-x_1 - x_2\) giảm khi \(x_1, x_2\) tăng, nghiệm tối ưu trên hình tròn buộc phải nằm trên biên tròn tại \(\tilde{x}^\star = (1, 1)\), thỏa đúng \(1^2 + 1^2 = 2\)!&lt;/li&gt;
  &lt;li&gt;Vì \(\tilde{x}^\star\) khả thi với bài toán gốc, phép nới lỏng này là &lt;strong&gt;chặt tuyệt đối&lt;/strong&gt;: \(x^\star = (1, 1)\) và \(f^\star = -2\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này trình bày kỹ thuật &lt;strong&gt;nới lỏng&lt;/strong&gt; (relaxation, còn gọi là &lt;em&gt;làm giản&lt;/em&gt;), thường dùng để đơn giản hóa hoặc xấp xỉ các bài toán tối ưu hóa bằng cách mở rộng tập khả thi.&lt;/p&gt;

&lt;p&gt;Xét bài toán tối ưu hóa có dạng:&lt;/p&gt;
&lt;blockquote&gt;
\[\min_{x} \; f(x) \quad \text{thỏa mãn} \quad x \in C\]
&lt;/blockquote&gt;

&lt;p&gt;Quá trình thay tập khả thi \(C\) bằng một tập lớn hơn \(\tilde{C} \supseteq C\) được gọi là &lt;strong&gt;nới lỏng&lt;/strong&gt; (relaxation):&lt;/p&gt;
&lt;blockquote&gt;
\[\min_{x} \; f(x) \quad \text{thỏa mãn} \quad x \in \tilde{C}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì bài toán mới được cực tiểu hóa trên một tập khả thi rộng hơn \(C\), giá trị tối ưu của bài toán nới lỏng luôn nhỏ hơn hoặc bằng giá trị tối ưu của bài toán gốc (tức là tạo ra một chặn dưới cho bài toán gốc).&lt;/p&gt;

&lt;h3 id=&quot;trường-hợp-đặc-biệt-quan-trọng-nới-lỏng-ràng-buộc-đẳng-thức-phi-affine&quot;&gt;Trường hợp đặc biệt quan trọng: Nới lỏng ràng buộc đẳng thức phi affine&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;Thay ràng buộc đẳng thức \(h_{j}(x) = 0\) (\(j = 1, \dotsc, r\)), trong đó \(h_{j}\) là các hàm lồi nhưng không affine, bằng ràng buộc bất đẳng thức \(h_{j}(x) \le 0\) (\(j = 1, \dotsc, r\)).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Việc chuyển ràng buộc đẳng thức thành bất đẳng thức giúp nới lỏng điều kiện và mở rộng tập khả thi. Khi các hàm \(h_j\) lồi nhưng không affine, phép nới lỏng này cho phép viết lại bài toán ban đầu (không lồi) thành một bài toán tối ưu hóa lồi. Nếu nghiệm tối ưu của bài toán nới lỏng đồng thời thỏa mãn \(h_j(x^\star) = 0\) (tức vẫn khả thi với bài toán gốc), thì đó cũng chính là nghiệm tối ưu của bài toán gốc.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>04-07 Biến phụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_07_Slack_variables/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_07_Slack_variables</id>
   <content type="html">&lt;p&gt;Trong quản trị sản xuất, nếu nhà máy có 100 giờ máy nhưng kế hoạch chỉ dùng hết 82 giờ, thì 18 giờ còn thừa không phải là con số vô nghĩa — nó chính là &lt;strong&gt;năng lực dự phòng&lt;/strong&gt; (slack) cho biết phân xưởng đó chưa bị quá tải. Trong tối ưu hóa toán học, việc đặt tên chính thức cho phần dự phòng ấy bằng một &lt;strong&gt;biến phụ (slack variable)&lt;/strong&gt; \(s_i \ge 0\) tạo ra một phép biến hình ngoạn mục: mọi bất đẳng thức rườm rà \(g_i(x) \le 0\) đồng loạt biến thành đẳng thức gọn gàng \(g_i(x) + s_i = 0\).&lt;/p&gt;

&lt;p&gt;Tuy nhiên, phép biến đổi này ẩn chứa một cái bẫy kinh điển mà người mới rất dễ mắc phải: nếu \(g_i(x)\) là hàm lồi &lt;em&gt;phi tuyến&lt;/em&gt;, thì đẳng thức \(g_i(x) + s_i = 0\) sẽ &lt;strong&gt;phá vỡ tính lồi&lt;/strong&gt; của dạng chuẩn! Vì thế, bài học này không chỉ giới thiệu cơ chế thêm biến phụ (xương sống của thuật toán Simplex và phương pháp điểm trong), mà còn chỉ rõ ranh giới chính xác khi nào nó giữ nguyên tính lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-vai-trò-của-biến-phụ-trong-lý-thuyết-và-thuật-toán&quot;&gt;Kiến thức cần nhớ: Vai trò của biến phụ trong lý thuyết và thuật toán&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau giúp bạn sử dụng biến phụ đúng chỗ và tránh bẫy mất tính lồi:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Từ bất đẳng thức sang đẳng thức + nón không âm:&lt;/strong&gt; Khi \(g_i(x) = a_i^T x - b_i\) là hàm affine (như trong Quy hoạch Tuyến tính LP), việc thêm \(s_i \ge 0\) biến hệ \(Ax \le b\) thành \(Ax + s = b,\; s \ge 0\). Tập khả thi biến thành giao của một không gian con affine với góc phần tư không âm — đúng dạng chuẩn mà thuật toán Simplex cần.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cạm bẫy bảo toàn tính lồi với \(g_i\) phi tuyến:&lt;/strong&gt; Nếu \(g_i(x) = x^2 - 1 \le 0\), việc viết thành \(x^2 - 1 + s = 0, s \ge 0\) tạo ra ràng buộc đẳng thức &lt;em&gt;phi affine&lt;/em&gt;! Tập các cặp \((x, s)\) thỏa \(s = 1 - x^2\) là một đường parabol (tập &lt;strong&gt;không lồi&lt;/strong&gt;), dù hình chiếu của nó lên trục \(x\) vẫn là đoạn \([-1, 1]\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa kinh tế &amp;amp; Độ lệch bù (Complementary Slackness):&lt;/strong&gt; Giá trị của \(s_i^\star\) cho biết ngay lập tức ràng buộc thứ \(i\) có tích cực hay không: \(s_i^\star = 0\) nghĩa là tài nguyên thứ \(i\) đã cạn kiệt (nút thắt cổ chai), còn \(s_i^\star &amp;gt; 0\) nghĩa là tài nguyên vẫn còn dư và giá bóng (nhân tử đối ngẫu \(\lambda_i^\star\)) của nó bằng \(0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-chuyển-bài-toán-phân-bổ-tài-nguyên-sang-dạng-biến-phụ-và-đọc-ý-nghĩa-nghiệm&quot;&gt;Giải thích: Chuyển bài toán phân bổ tài nguyên sang dạng biến phụ và đọc ý nghĩa nghiệm&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối đa hóa lợi nhuận (tương đương cực tiểu hóa \(-3x_1 - 5x_2\)) của một xưởng mộc:
\(\max_{x_1, x_2 \ge 0} \; 3x_1 + 5x_2 \quad \text{thỏa mãn} \quad \begin{cases} x_1 \le 4 &amp;amp; \text{(gỗ)} \\ 2x_2 \le 12 &amp;amp; \text{(nhân công)} \\ 3x_1 + 2x_2 \le 18 &amp;amp; \text{(thời gian máy)} \end{cases}\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Đưa vào 3 biến phụ không âm \(s_1, s_2, s_3 \ge 0\):&lt;/strong&gt;
\(\begin{cases} x_1 + s_1 = 4 \\ 2x_2 + s_2 = 12 \\ 3x_1 + 2x_2 + s_3 = 18 \end{cases}, \qquad x_1, x_2, s_1, s_2, s_3 \ge 0.\)
Vì cả 3 ràng buộc gốc đều tuyến tính, bài toán mở rộng hoàn toàn là một bài toán LP lồi chuẩn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Kiểm tra tại phương án tối ưu \(x^\star = (2, 6)\):&lt;/strong&gt;
Lợi nhuận đạt \(3(2) + 5(6) = 36\). Thay \(x_1 = 2, x_2 = 6\) vào các phương trình biến phụ:
    &lt;ul&gt;
      &lt;li&gt;\(s_1^\star = 4 - 2 = 2 &amp;gt; 0\) (còn dư 2 đơn vị gỗ — ràng buộc &lt;strong&gt;không tích cực&lt;/strong&gt;).&lt;/li&gt;
      &lt;li&gt;\(s_2^\star = 12 - 2(6) = 0\) (dùng hết nhân công — ràng buộc &lt;strong&gt;tích cực&lt;/strong&gt;).&lt;/li&gt;
      &lt;li&gt;\(s_3^\star = 18 - 3(2) - 2(6) = 0\) (dùng hết thời gian máy — ràng buộc &lt;strong&gt;tích cực&lt;/strong&gt;).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Kiểm chứng phản ví dụ phi tuyến:&lt;/strong&gt; Nếu ta có ràng buộc lồi \(x^2 \le 4\) và đổi thành \(x^2 + s = 4, s \ge 0\), lấy hai điểm thỏa mãn là \(P_1 = (2, 0)\) và \(P_2 = (-2, 0)\). Trung điểm \(M = (0, 0)\) lại cho \(0^2 + 0 = 0 \neq 4\)! Do đó, chỉ nên dùng biến phụ thành đẳng thức đối với ràng buộc &lt;strong&gt;tuyến tính/affine&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;biến-phụ-trong-tối-ưu-hóa-lồi&quot;&gt;Biến phụ trong Tối ưu hóa Lồi&lt;/h1&gt;

&lt;h2 id=&quot;giới-thiệu-và-động-lực&quot;&gt;Giới thiệu và động lực&lt;/h2&gt;

&lt;p&gt;Biến phụ (slack variable) là các biến phụ trợ được đưa thêm vào nhằm chuyển đổi ràng buộc bất đẳng thức thành ràng buộc đẳng thức kèm điều kiện không âm. Phép biến đổi này được sử dụng rộng rãi trong lý thuyết tối ưu hóa, đặc biệt là trong quy hoạch tuyến tính, các phương pháp điểm trong và nhiều thuật toán giải chuẩn khác.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tại sao cần dùng biến phụ?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nhiều thuật toán tối ưu hóa được thiết kế để xử lý trực tiếp các ràng buộc đẳng thức kết hợp với điều kiện không âm hiệu quả hơn.&lt;/li&gt;
  &lt;li&gt;Biến phụ cho ý nghĩa hình học rõ ràng về mức độ “chặt” (khoảng dư) của từng ràng buộc.&lt;/li&gt;
  &lt;li&gt;Đây là bước chuẩn hóa không thể thiếu trong phương pháp đơn hình (Simplex) cho quy hoạch tuyến tính.&lt;/li&gt;
  &lt;li&gt;Biến phụ hỗ trợ thuận tiện cho việc phân tích đối ngẫu và phân tích độ nhạy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;công-thức-toán-học&quot;&gt;Công thức toán học&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối ưu hóa lồi dạng chuẩn:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_x &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;g_{i}(x) \leq 0, \quad i = 1, \ldots, m\\
&amp;amp;&amp;amp;&amp;amp;Ax = b
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;Bằng cách đưa vào các &lt;strong&gt;biến phụ&lt;/strong&gt; \(s_i \geq 0\) tương ứng với từng ràng buộc bất đẳng thức, ta có thể viết lại bài toán thành:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_{x, s} &amp;amp;&amp;amp;f(x)\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;s_{i} \geq 0, \quad i = 1, \ldots, m\\
&amp;amp;&amp;amp;&amp;amp;g_{i}(x) + s_{i} = 0, \quad i = 1, \ldots, m\\
&amp;amp;&amp;amp;&amp;amp;Ax = b
\end{aligned}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;giải-thích-hình-học&quot;&gt;Giải thích hình học&lt;/h2&gt;

&lt;p&gt;Biến phụ \(s_i\) đo lường “khoảng dư” (hay độ lệch so với biên) của ràng buộc thứ \(i\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(s_i &amp;gt; 0\):&lt;/strong&gt; Ràng buộc \(g_i(x) \leq 0\) &lt;strong&gt;không tích cực&lt;/strong&gt; (không chặt).
    &lt;ul&gt;
      &lt;li&gt;Điểm \(x\) nằm bên trong miền khả thi do ràng buộc thứ \(i\) xác định.&lt;/li&gt;
      &lt;li&gt;Khi đó \(g_i(x) = -s_i &amp;lt; 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(s_i = 0\):&lt;/strong&gt; Ràng buộc \(g_i(x) \leq 0\) &lt;strong&gt;tích cực&lt;/strong&gt; (chặt).
    &lt;ul&gt;
      &lt;li&gt;Điểm \(x\) nằm đúng trên biên \(g_i(x) = 0\).&lt;/li&gt;
      &lt;li&gt;Ràng buộc này được thỏa mãn với dấu bằng tại điểm đang xét.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ví-dụ-thực-tế-phân-bổ-tài-nguyên&quot;&gt;Ví dụ thực tế: Phân bổ tài nguyên&lt;/h2&gt;

&lt;p&gt;Xét bài toán phân bổ tài nguyên đơn giản sau:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán gốc:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\max &amp;amp;&amp;amp;3x_1 + 2x_2 \\
&amp;amp;\text{thỏa mãn} &amp;amp;&amp;amp;x_1 + x_2 \leq 4 \quad \text{(giờ lao động)}\\
&amp;amp;&amp;amp;&amp;amp;2x_1 + x_2 \leq 6 \quad \text{(đơn vị nguyên liệu)}\\
&amp;amp;&amp;amp;&amp;amp;x_1, x_2 \geq 0
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Sau khi thêm biến phụ:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\max &amp;amp;&amp;amp;3x_1 + 2x_2 \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;x_1 + x_2 + s_1 = 4\\
&amp;amp;&amp;amp;&amp;amp;2x_1 + x_2 + s_2 = 6\\
&amp;amp;&amp;amp;&amp;amp;x_1, x_2, s_1, s_2 \geq 0
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(s_1\): số giờ lao động chưa sử dụng.&lt;/li&gt;
  &lt;li&gt;\(s_2\): số đơn vị nguyên liệu chưa sử dụng.&lt;/li&gt;
  &lt;li&gt;Nếu \(s_1 = 0\) tại nghiệm tối ưu: toàn bộ quỹ giờ lao động đã được sử dụng hết.&lt;/li&gt;
  &lt;li&gt;Nếu \(s_2 &amp;gt; 0\) tại nghiệm tối ưu: vẫn còn một phần nguyên liệu chưa được sử dụng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;các-tính-chất-và-lưu-ý-quan-trọng&quot;&gt;Các tính chất và lưu ý quan trọng&lt;/h2&gt;

&lt;h3 id=&quot;1-tính-tương-đương-của-hai-bài-toán&quot;&gt;1. Tính tương đương của hai bài toán&lt;/h3&gt;
&lt;p&gt;Bài toán gốc và bài toán sau khi thêm biến phụ &lt;strong&gt;tương đương về mặt toán học&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Có cùng giá trị mục tiêu tối ưu.&lt;/li&gt;
  &lt;li&gt;Có cùng thành phần nghiệm tối ưu \(x^*\).&lt;/li&gt;
  &lt;li&gt;Giá trị tối ưu \(s_i^*\) của các biến phụ cho biết trực tiếp ràng buộc nào là tích cực tại nghiệm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-điều-kiện-bảo-toàn-tính-lồi&quot;&gt;2. Điều kiện bảo toàn tính lồi&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Lưu ý quan trọng:&lt;/strong&gt; Phép đưa thêm biến phụ chỉ bảo toàn tính lồi của bài toán &lt;strong&gt;khi \(g_i(x)\) là hàm affine&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nếu \(g_i(x) = a_i^T x - b_i\) (affine):&lt;/strong&gt; Ràng buộc \(g_i(x) + s_i = 0\) là đẳng thức affine, nên bài toán viết lại vẫn là bài toán lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nếu \(g_i(x)\) là hàm lồi phi tuyến:&lt;/strong&gt; Ràng buộc đẳng thức \(g_i(x) + s_i = 0\) không còn là hàm affine, làm phá vỡ tính lồi của bài toán.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-tác-động-đến-kích-thước-bài-toán&quot;&gt;3. Tác động đến kích thước bài toán&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Bài toán gốc có \(n\) biến.&lt;/li&gt;
  &lt;li&gt;Bài toán với biến phụ có \(n + m\) biến.&lt;/li&gt;
  &lt;li&gt;Đánh đổi: số biến tăng lên nhưng cấu trúc ràng buộc trở nên đồng nhất và dễ xử lý hơn đối với nhiều thuật toán.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ví-dụ-chuẩn-hóa-bài-toán-quy-hoạch-tuyến-tính&quot;&gt;Ví dụ: Chuẩn hóa bài toán quy hoạch tuyến tính&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Dạng bất đẳng thức:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min &amp;amp;&amp;amp;c^T x \\
&amp;amp;\text{thỏa mãn} &amp;amp;&amp;amp;Ax \leq b\\
&amp;amp;&amp;amp;&amp;amp;x \geq 0
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Dạng chuẩn với biến phụ:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min &amp;amp;&amp;amp;c^T x \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;Ax + s = b\\
&amp;amp;&amp;amp;&amp;amp;x, s \geq 0
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(s \in \mathbb{R}^m\) là vectơ các biến phụ.&lt;/p&gt;

&lt;h2 id=&quot;các-điểm-chính&quot;&gt;Các điểm chính&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Công cụ chuyển đổi:&lt;/strong&gt; Biến phụ chuyển ràng buộc bất đẳng thức thành ràng buộc đẳng thức kèm điều kiện không âm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa hình học:&lt;/strong&gt; Đo lường khoảng dư so với biên ràng buộc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hỗ trợ thuật toán:&lt;/strong&gt; Là thành phần chuẩn trong phương pháp đơn hình và nhiều bộ giải tối ưu hóa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện bảo toàn tính lồi:&lt;/strong&gt; Chỉ bảo toàn tính lồi đối với các ràng buộc affine.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa ứng dụng:&lt;/strong&gt; Phản ánh trực tiếp lượng tài nguyên dư thừa trong các bài toán phân bổ kinh tế.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>04-06 Loại bỏ ràng buộc đẳng thức</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_06_Eliminating_equality_constraints/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_06_Eliminating_equality_constraints</id>
   <content type="html">&lt;p&gt;Giả sử bạn phải tìm vị trí thấp nhất của một thung lũng trong không gian 3 chiều, nhưng bị buộc phải đi dọc theo một con đường thẳng cắt ngang thung lũng đó. Bạn có cần mang theo cả bản đồ 3D phức tạp không? Hoàn toàn không! Vì mọi vị trí trên con đường thẳng chỉ cần đúng &lt;strong&gt;một tọa độ duy nhất&lt;/strong&gt; (số mét tính từ điểm xuất phát) để xác định.&lt;/p&gt;

&lt;p&gt;Đó chính là tinh thần của kỹ thuật &lt;strong&gt;loại bỏ ràng buộc đẳng thức tuyến tính&lt;/strong&gt; \(Ax = b\). Thay vì mang gánh nặng các phương trình ràng buộc vào thuật toán giải, ta tham số hóa toàn bộ tập nghiệm của \(Ax = b\) dưới dạng \(x = Fz + x_0\), biến bài toán có ràng buộc đẳng thức thành bài toán nhỏ gọn hơn theo biến tự do \(z\) mà vẫn giữ nguyên vẹn tính lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-đại-số-tuyến-tính-đằng-sau-việc-khử-ax--b&quot;&gt;Kiến thức cần nhớ: Đại số tuyến tính đằng sau việc khử \(Ax = b\)&lt;/h2&gt;

&lt;p&gt;Để thực hiện phép khử này chính xác và biết khi nào &lt;em&gt;nên&lt;/em&gt; hay &lt;em&gt;không nên&lt;/em&gt; dùng nó trong thực tế, hãy nắm ba trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cấu trúc không gian nghiệm của hệ tuyến tính (Affine Subspace Parametrization):&lt;/strong&gt; Tập nghiệm của \(Ax = b\) (nếu khác rỗng) luôn có dạng \(x_0 + \operatorname{null}(A)\), trong đó \(x_0\) là một nghiệm riêng bất kỳ (\(Ax_0 = b\)) và các cột của ma trận \(F\) tạo thành cơ sở của không gian hạt nhân \(\operatorname{null}(A)\) (tức \(AF = 0\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bảo toàn tính lồi dưới hợp thành affine (Affine Composition):&lt;/strong&gt; Khi thay \(x = Fz + x_0\) vào hàm mục tiêu \(f(x)\) và ràng buộc bất đẳng thức \(g_i(x)\), ta thu được \(\tilde{f}(z) = f(Fz + x_0)\) và \(\tilde{g}_i(z) = g_i(Fz + x_0)\). Vì hợp thành của hàm lồi với ánh xạ affine luôn lồi, bài toán mới chắc chắn vẫn là bài toán tối ưu hóa lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh đổi tính toán: Kích thước vs. Độ thưa (Sparsity Trade-off):&lt;/strong&gt; Khử ràng buộc đẳng thức giúp giảm số chiều biến từ \(n\) xuống \(n - \operatorname{rank}(A)\), cực kỳ hiệu quả với bài toán cỡ vừa. Tuy nhiên, với bài toán cực lớn có ma trận \(A\) thưa, ma trận \(F\) thường bị &lt;strong&gt;dày đặc (dense)&lt;/strong&gt;, nên các bộ giải lớn thường giữ nguyên \(Ax = b\) và giải hệ KKT thưa thay vì khử trực tiếp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-khử-ràng-buộc-đẳng-thức-và-giải-tay-bài-toán-3-biến-về-1-biến&quot;&gt;Giải thích: Khử ràng buộc đẳng thức và giải tay bài toán 3 biến về 1 biến&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu lồi trong \(\mathbb{R}^3\):
\(\min_{x \in \mathbb{R}^3} \; f(x) = x_1^2 + 2x_2^2 + x_3^2 \quad \text{thỏa mãn} \quad \begin{cases} x_1 + x_2 + x_3 = 3 \\ x_1 - x_3 = 1 \end{cases}\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tìm một nghiệm riêng \(x_0\):&lt;/strong&gt;
Chọn thử \(x_3 = 0 \implies x_1 = 1\), từ phương trình đầu suy ra \(x_2 = 2\). Vậy \(x_0 = (1, 2, 0)^T\) thỏa mãn hệ \(Ax = b\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Tìm cơ sở \(F\) của không gian hạt nhân \(Av = 0\):&lt;/strong&gt;
Hệ thuần nhất: \(v_1 + v_2 + v_3 = 0\) và \(v_1 - v_3 = 0 \implies v_1 = v_3\) và \(v_2 = -2v_3\).
Chọn \(v_3 = 1\) ta được vector cơ sở duy nhất \(F = (1, -2, 1)^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Tham số hóa \(x = Fz + x_0\) (với \(z \in \mathbb{R}\)):&lt;/strong&gt;
\(x_1 = 1 + z, \qquad x_2 = 2 - 2z, \qquad x_3 = z.\)
Kiểm tra nhanh: \(x_1 + x_2 + x_3 = (1+z) + (2-2z) + z = 3\) và \(x_1 - x_3 = 1\) đúng với mọi \(z \in \mathbb{R}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 4 — Giải bài toán không ràng buộc 1 biến theo \(z\):&lt;/strong&gt;
\(\tilde{f}(z) = (1 + z)^2 + 2(2 - 2z)^2 + z^2 = (1 + 2z + z^2) + 2(4 - 8z + 4z^2) + z^2 = 10z^2 - 14z + 9.\)
Đạo hàm \(\tilde{f}&apos;(z) = 20z - 14 = 0 \implies z^\star = 0.7\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 5 — Khôi phục nghiệm gốc:&lt;/strong&gt;
\(x^\star = F(0.7) + x_0 = (1.7,\; 0.6,\; 0.7)^T, \qquad f^\star = 10(0.49) - 14(0.7) + 9 = 4.1.\)
Cả hai ràng buộc đẳng thức đều thỏa mãn chính xác (\(1.7+0.6+0.7=3\), \(1.7-0.7=1\)) mà không cần dùng đến nhân tử Lagrange!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này trình bày kỹ thuật loại bỏ các ràng buộc đẳng thức tuyến tính trong bài toán tối ưu hóa lồi nhằm đơn giản hóa tập khả thi hoặc cấu trúc bài toán.&lt;/p&gt;

&lt;p&gt;Xét bài toán tối ưu hóa lồi có dạng:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x)\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;g_{i}(x) \leq 0, \quad i = 1, \dotsc, m\\
&amp;amp;&amp;amp;&amp;amp;{Ax = b}.\\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;Giả sử \(x_{0}\) là một nghiệm riêng bất kỳ thỏa mãn \(Ax_{0} = b\) và \(M\) là ma trận sao cho không gian cột của nó trùng với không gian hạch của \(A\), tức là \(\text{col}(M) = \text{null}(A)\). Khi đó, mọi điểm \(x\) thỏa mãn ràng buộc đẳng thức \(Ax = b\) đều có thể biểu diễn dưới dạng:&lt;/p&gt;
&lt;blockquote&gt;
\[x = My + x_{0}\]
&lt;/blockquote&gt;

&lt;p&gt;Thật vậy, \(Ax = A(My + x_{0}) = AMy + Ax_{0} = 0 + b = b\). Do đó, bằng cách thay thế \(x = My + x_{0}\) vào bài toán gốc, ta loại bỏ hoàn toàn ràng buộc đẳng thức và thu được bài toán tương đương:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_y &amp;amp;&amp;amp;f(My+x_0)\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;g_{i}(My+x_{0}) \leq 0, \quad i = 1, \dotsc, m.\\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;Tuy nhiên, trong thực tế cần cân nhắc kỹ trước khi áp dụng phương pháp này vì hai hạn chế chính:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Việc tìm ma trận \(M\) (chẳng hạn qua phân tích QR hoặc SVD) thường tốn kém về mặt tính toán khi kích thước bài toán lớn.&lt;/li&gt;
  &lt;li&gt;Nếu ma trận bài toán theo biến gốc \(x\) có cấu trúc thưa, việc chuyển sang biến \(y\) qua ma trận dày đặc \(M\) có thể phá vỡ tính thưa và làm tăng chi phí tính toán.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>04-05 Biến đổi và thay đổi biến</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_05_Transformations_and_change_of_variables/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_05_Transformations_and_change_of_variables</id>
   <content type="html">&lt;p&gt;Trong nhiều bài toán thiết kế mạch điện, quy hoạch mạng truyền thông hay định giá kinh tế, các công thức hiện ra toàn tích lũy thừa như \(x_1^{0.5} x_2^{-1.2} + 3 x_1 x_2 \le 1\). Nhìn bằng mắt thường, tập khả thi cong queo và hàm mục tiêu hoàn toàn &lt;strong&gt;phi lồi&lt;/strong&gt; — ai cũng muốn bỏ cuộc và gọi thuật toán tìm kiếm cục bộ. Thế nhưng chỉ cần đặt \(y_i = \log x_i\) và lấy logarit hai vế, toàn bộ bức tranh cong queo ấy bỗng “duỗi thẳng” thành một bài toán tối ưu hóa lồi hoàn hảo!&lt;/p&gt;

&lt;p&gt;Bài học này trao cho bạn hai chiếc kính biến hình quyền lực nhất trong tối ưu hóa: &lt;strong&gt;biến đổi đơn điệu hàm mục tiêu&lt;/strong&gt; (Định lý 1) và &lt;strong&gt;đổi biến song ánh&lt;/strong&gt; (Định lý 2). Nắm vững chúng giúp bạn nhận ra rất nhiều bài toán “giả phi lồi” thực chất là bài toán lồi đang cải trang.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-nghệ-thuật-phát-hiện-tính-lồi-ẩn&quot;&gt;Kiến thức cần nhớ: Nghệ thuật phát hiện “tính lồi ẩn”&lt;/h2&gt;

&lt;p&gt;Bốn nguyên tắc dưới đây quyết định khi nào một phép biến đổi giữ nguyên hoàn toàn tập nghiệm tối ưu:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Biến đổi đơn điệu tăng của hàm mục tiêu (Monotone Transformation):&lt;/strong&gt; Nếu \(h: \mathbb{R} \to \mathbb{R}\) là hàm tăng ngặt, thì cực tiểu hóa \(f(x)\) hoàn toàn tương đương với cực tiểu hóa \(h(f(x))\). Ví dụ kinh điển: thay vì cực tiểu hóa chuẩn Euclidean \(\|Ax - b\|_2\) (không trơn tại \(0\)), ta cực tiểu hóa \(\|Ax - b\|_2^2\) (hàm bậc hai trơn đẹp) vì \(h(t) = t^2\) tăng ngặt trên \([0, \infty)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đổi biến khả nghịch (Change of Variables):&lt;/strong&gt; Thay \(x = \phi(z)\) với \(\phi\) là song ánh giữa miền mới và miền cũ biến bài toán theo \(x\) thành bài toán theo \(z\). Nghiệm cũ khôi phục ngay lập tức qua \(x^\star = \phi(z^\star)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép biến đổi Logarit trong Quy hoạch Hình học (Log-Transform / GP):&lt;/strong&gt; Đặt \(x_i = e^{y_i}\) biến mọi tích lũy thừa dương \(c x_1^{a_1} \cdots x_n^{a_n}\) thành hàm mũ \(e^{a^T y + \log c}\), rồi lấy \(\log\) đưa về hàm &lt;strong&gt;log-sum-exp&lt;/strong&gt; vốn luôn lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cẩn trọng với tính lồi của ràng buộc:&lt;/strong&gt; Biến đổi đơn điệu \(h\) giữ nguyên &lt;em&gt;tập nghiệm&lt;/em&gt;, nhưng không tự động biến bài toán thành &lt;em&gt;lồi&lt;/em&gt; — bạn phải chọn \(h\) hoặc \(\phi\) sao cho hàm mục tiêu mới và các hàm ràng buộc mới thực sự lồi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-mã-một-bài-toán-phi-lồi-bằng-phép-đổi-biến-logarit&quot;&gt;Giải thích: “Giải mã” một bài toán phi lồi bằng phép đổi biến logarit&lt;/h3&gt;

&lt;p&gt;Xét bài toán tối ưu trên \(x_1 &amp;gt; 0,\; x_2 &amp;gt; 0\):
\(\min_{x_1, x_2 &amp;gt; 0} \; f(x_1, x_2) = \frac{1}{x_1 x_2} \quad \text{thỏa mãn} \quad x_1 + 2x_2 \le 4.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhận diện vẻ ngoài phi lồi:&lt;/strong&gt; Đặt \(x_1 = e^{y_1}\), \(x_2 = e^{y_2}\) với \(y_1, y_2 \in \mathbb{R}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển hàm mục tiêu:&lt;/strong&gt;
\(f(e^{y_1}, e^{y_2}) = e^{-y_1 - y_2}.\)
Lấy \(\log\) (hàm tăng ngặt trên \((0, \infty)\)) cho hàm mục tiêu mới cực kỳ đơn giản:
\(\tilde{f}(y_1, y_2) = \log(e^{-y_1 - y_2}) = -y_1 - y_2 \quad (\text{hàm tuyến tính!}).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuyển ràng buộc:&lt;/strong&gt; \(x_1 + 2x_2 \le 4 \iff e^{y_1} + 2e^{y_2} \le 4\). Lấy \(\log\) hai vế:
\(\log(e^{y_1} + 2e^{y_2}) - \log 4 \le 0.\)
Hàm \(\log(e^{y_1} + e^{y_2 + \log 2})\) là hàm log-sum-exp, nên &lt;strong&gt;luôn lồi&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải trực tiếp trên bài toán lồi mới:&lt;/strong&gt;
Muốn cực tiểu hóa \(-y_1 - y_2\) (tức cực đại hóa \(y_1 + y_2\)) dưới ràng buộc \(e^{y_1} + 2e^{y_2} \le 4\), bất đẳng thức AM-GM cho \(e^{y_1} + 2e^{y_2} \ge 2\sqrt{2 e^{y_1 + y_2}}\), dấu bằng xảy ra khi \(e^{y_1} = 2e^{y_2} = 2\).
Suy ra \(y_1^\star = \log 2\), \(y_2^\star = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khôi phục nghiệm gốc:&lt;/strong&gt; \(x_1^\star = e^{\log 2} = 2\), \(x_2^\star = e^0 = 1\). Kiểm tra ràng buộc gốc: \(2 + 2(1) = 4 \le 4\), giá trị tối ưu gốc là \(f^\star = \frac{1}{2 \cdot 1} = 0.5\).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này trình bày các kỹ thuật biến đổi hàm và đổi biến trong tối ưu hóa, giúp đơn giản hóa hoặc viết lại bài toán về dạng tương đương thuận lợi hơn.&lt;/p&gt;

&lt;p&gt;Bằng cách biến đổi hàm mục tiêu hoặc các hàm ràng buộc mà vẫn giữ nguyên tập nghiệm tương ứng, đôi khi ta có thể phát hiện “tính lồi ẩn” của những bài toán ban đầu trông có vẻ không lồi.&lt;/p&gt;

&lt;h3 id=&quot;định-lý-1&quot;&gt;Định lý 1&lt;/h3&gt;
&lt;p&gt;Nếu \(h : \mathbb{R} \rightarrow \mathbb{R}\) là một hàm đơn điệu tăng chặt, thì hai bài toán sau là tương đương:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
  &amp;amp;\min_{x} f(x) \text{ subject to } x \in C \\
  \Longleftrightarrow \quad &amp;amp;\min_{x} h(f(x)) \text{ subject to } x \in C
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;định-lý-2&quot;&gt;Định lý 2&lt;/h3&gt;
&lt;p&gt;Nếu ánh xạ \(\phi: \mathbb{R}^{n} \rightarrow \mathbb{R}^{m}\) là một song ánh (hoặc đơn ánh có ảnh bao phủ tập khả thi \(C\)), thì có thể đổi biến bài toán tối ưu hóa như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{x} f(x) \text{ subject to } x \in C \\\\ 
   \Longleftrightarrow \quad &amp;amp;\min_{y} f(\phi(y)) \text{ subject to } \phi(y) \in C
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;ví-dụ-quy-hoạch-hình-học&quot;&gt;Ví dụ: Quy hoạch hình học&lt;/h3&gt;

&lt;p&gt;Một hàm \(f: \mathbb{R}_{++}^n \rightarrow \mathbb{R}\) có dạng sau được gọi là &lt;strong&gt;đơn thức dương&lt;/strong&gt; (monomial):&lt;/p&gt;
&lt;blockquote&gt;
\[f(x) = \gamma x_{1}^{a_{1}} x_{2}^{a_{2}} \dotsb x_{n}^{a_{n}} \text{ với } \gamma &amp;gt; 0, \; a_{1}, \dotsc, a_{n} \in \mathbb{R}.\]
&lt;/blockquote&gt;

&lt;p&gt;Tổng của các đơn thức dương được gọi là &lt;strong&gt;đa thức dương&lt;/strong&gt; (posynomial):&lt;/p&gt;
&lt;blockquote&gt;
\[g(x) = \sum_{k=1}^{p} \gamma_{k} x_{1}^{a_{k1}} x_{2}^{a_{k2}} \dotsb x_{n}^{a_{kn}} \text{ với } \gamma_{k} &amp;gt; 0, \; a_{k1}, \dotsc, a_{kn} \in \mathbb{R}.\]
&lt;/blockquote&gt;

&lt;p&gt;Một &lt;strong&gt;bài toán quy hoạch hình học&lt;/strong&gt; (geometric program) được phát biểu như sau (dạng gốc không phải là bài toán lồi):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;g_{i}(x) \leq 1, \quad i = 1, \dotsc, m\\
&amp;amp;&amp;amp;&amp;amp;h_{j}(x) = 1, \quad j = 1, \dotsc, r,\\\\
\end{align}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;trong đó \(f\) và \(g_{i}\) (\(i=1, \dotsc, m\)) là các đa thức dương, còn \(h_{j}\) (\(j=1, \dotsc, r\)) là các đơn thức dương.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hãy chứng minh rằng mọi bài toán quy hoạch hình học đều tương đương với một bài toán tối ưu hóa lồi.&lt;/p&gt;

&lt;h3 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;Với một đơn thức dương \(f(x) = \gamma x_{1}^{a_{1}} x_{2}^{a_{2}} \dotsb x_{n}^{a_{n}}\), đặt phép đổi biến \(y_{i} = \log x_{i}\) (tức \(x_i = e^{y_i}\)) và \(b = \log \gamma\). Theo &lt;strong&gt;Định lý 2&lt;/strong&gt;, phép đổi biến này bảo toàn tính tương đương của bài toán và đưa \(f\) về dạng:
\(\gamma (e^{y_{1}})^{a_{1}} (e^{y_{2}})^{a_{2}} \dotsb (e^{y_{n}})^{a_{n}} = e^{a^Ty + b}.\)&lt;/p&gt;

  &lt;p&gt;Tương tự, mỗi đa thức dương trở thành \(\sum_{k=1}^{p} e^{a_{k}^{T}y + b_{k}}\).&lt;/p&gt;

  &lt;p&gt;Tiếp theo, áp dụng phép biến đổi đơn điệu tăng chặt \(\log(\cdot)\) theo &lt;strong&gt;Định lý 1&lt;/strong&gt;, ta thu được dạng \(\log \big( \sum_{k=1}^{p} e^{a_{k}^{T}y + b_{k}} \big)\) mà vẫn giữ nguyên tính tương đương của bài toán.&lt;/p&gt;

  &lt;p&gt;Như vậy, bài toán quy hoạch hình học ban đầu tương đương với bài toán sau, vốn là một bài toán tối ưu hóa lồi (vì hàm log-sum-exp là hàm lồi và ràng buộc đẳng thức là affine):&lt;/p&gt;

\[\begin{align}
&amp;amp;\min_{y} \quad &amp;amp;&amp;amp;{\log \big( \sum_{k=1}^{p_{0}} e^{a_{0k}^{T}y + b_{0k}} \big)} \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;{
         \log \big( \sum_{k=1}^{p_{i}} e^{a_{ik}^{T}y + b_{ik}} \big)
         \leq 0
         , \quad i = 1, \dotsc, m
}\\
&amp;amp;&amp;amp;&amp;amp;c_{j}^{T}y + d_{j} = 0, \quad j = 1, \dotsc, r.\\\\
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>04-04 Tối ưu hóa từng phần</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_04_Partial_optimization/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_04_Partial_optimization</id>
   <content type="html">&lt;p&gt;Khi giải một câu đố nhiều tầng, chiến lược tự nhiên nhất của con người là “chia để trị”: tạm coi một nhóm biến là cố định, tìm phương án tốt nhất cho nhóm biến còn lại, rồi thay kết quả đó ngược trở lại vào bài toán ban đầu. Trong đại số thông thường, phép thế này luôn hợp lệ; nhưng trong tối ưu hóa lồi, một câu hỏi quan trọng hiện ra: &lt;em&gt;sau khi tối ưu hóa trước một phần biến, bài toán rút gọn có còn giữ được tính lồi hay không?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;May mắn thay, định lý bảo toàn tính lồi qua phép lấy cực tiểu từng phần trả lời là &lt;strong&gt;CÓ&lt;/strong&gt; — miễn là hàm gốc lồi &lt;em&gt;đồng thời&lt;/em&gt; theo cả hai nhóm biến \((x, y)\) và miền của \(y\) là lồi. Phép biến đổi tưởng chừng đơn giản này chính là cây cầu biến đổi bài toán SVM biên mềm kinh điển từ dạng có hàng nghìn biến phụ \(\xi_i\) thành dạng không ràng buộc với &lt;strong&gt;hàm mất mát bản lề (hinge loss)&lt;/strong&gt; quen thuộc trong mọi thư viện học máy hiện đại.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cơ-chế-rút-gọn-biến-mà-vẫn-bảo-toàn-tính-lồi&quot;&gt;Kiến thức cần nhớ: Cơ chế “rút gọn biến” mà vẫn bảo toàn tính lồi&lt;/h2&gt;

&lt;p&gt;Ba trụ cột sau giải thích khi nào tối ưu hóa từng phần hoạt động và tại sao nó lại mạnh mẽ đến vậy:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi đồng thời (Joint Convexity):&lt;/strong&gt; Điều kiện tiên quyết là \(f(x, y)\) phải lồi đồng thời theo cặp \((x, y)\), chứ không chỉ lồi riêng lẻ theo \(x\) và riêng lẻ theo \(y\) (ví dụ \(f(x,y) = xy\) lồi theo từng biến nhưng không lồi đồng thời!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép chiếu trên đồ thị (Epigraph Projection):&lt;/strong&gt; Hình học của \(g(x) = \inf_{y \in C} f(x, y)\) cực kỳ trong sáng: tập trên đồ thị của \(g\) chính là hình chiếu của tập trên đồ thị của \(f\) (một tập lồi) xuống không gian của \((x, t)\). Vì phép chiếu tuyến tính bảo toàn tính lồi, \(g(x)\) lập tức thừa hưởng tính lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đánh đổi giữa “nhiều biến – hàm trơn” và “ít biến – hàm không trơn”:&lt;/strong&gt; Khi bạn khử biến phụ \(\xi_i\) trong SVM bằng tối ưu hóa từng phần, số biến giảm mạnh nhưng hàm mục tiêu chuyển từ hàm tuyến tính trơn thành hàm \(\max(0, \cdot)\) không khả vi. Ngược lại, đọc công thức theo chiều ngược lại chính là cách “làm trơn” một hàm cực đại bằng cách thêm biến phụ!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-hàm-rút-gọn-gx-và-kiểm-chứng-trên-một-ví-dụ-svm-mini&quot;&gt;Giải thích: Tính tay hàm rút gọn \(g(x)\) và kiểm chứng trên một ví dụ SVM mini&lt;/h3&gt;

&lt;p&gt;Xét bài toán lồi đồng thời theo \((w, \xi) \in \mathbb{R} \times \mathbb{R}\):
\(\min_{w, \xi} \; \frac{1}{2} w^2 + 2\xi \quad \text{thỏa mãn} \quad \xi \ge 0,\quad \xi \ge 1 - 2w.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Cố định \(w\), tối ưu hóa theo biến phụ \(\xi\):&lt;/strong&gt;
Hai ràng buộc \(\xi \ge 0\) và \(\xi \ge 1 - 2w\) gộp lại thành \(\xi \ge \max(0, 1 - 2w)\).
Vì hệ số của \(\xi\) trong hàm mục tiêu là \(+2 &amp;gt; 0\), muốn cực tiểu hóa \(2\xi\) ta phải chọn \(\xi\) nhỏ nhất có thể:
\(\xi^\star(w) = \max(0, 1 - 2w).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Thay \(\xi^\star(w)\) vào bài toán gốc:&lt;/strong&gt;
Ta thu được bài toán hoàn toàn không ràng buộc chỉ còn 1 biến \(w\):
\(\min_{w \in \mathbb{R}} \; g(w) = \frac{1}{2} w^2 + 2\max(0, 1 - 2w).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Giải bài toán rút gọn theo từng khoảng:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nếu \(w \ge 0.5\): \(\max(0, 1-2w) = 0 \implies g(w) = \frac{1}{2}w^2\), đạt cực tiểu trên \([0.5, \infty)\) tại \(w = 0.5\) với \(g(0.5) = 0.125\).&lt;/li&gt;
      &lt;li&gt;Nếu \(w &amp;lt; 0.5\): \(g(w) = \frac{1}{2}w^2 + 2 - 4w\). Đạo hàm \(g&apos;(w) = w - 4 &amp;lt; 0\) với mọi \(w &amp;lt; 0.5\), nên hàm giảm nghiêm ngặt đến sát \(w = 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết luận &amp;amp; Kiểm tra ngược:&lt;/strong&gt; Nghiệm tối ưu là \(w^\star = 0.5\), kéo theo \(\xi^\star = \max(0, 1 - 2(0.5)) = 0\), và giá trị tối ưu \(g^\star = 0.125\). Phép tối ưu từng phần đã thu gọn bài toán 2 biến có 2 ràng buộc bất đẳng thức về đúng một hàm 1 biến lồi!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;/contents/vi/chapter03/03_02_operations_that_preserve_convexity/&quot;&gt;Nhắc lại:&lt;/a&gt;
Nếu \(C\) là tập lồi và \(f\) là hàm lồi đồng thời theo \((x, y)\), thì hàm \(g(x) = \min_{y \in C} f(x, y)\) là hàm lồi theo \(x\).&lt;/p&gt;

&lt;p&gt;Do đó, phép tối ưu hóa từng phần trên một tập con các biến trong bài toán tối ưu hóa lồi vẫn bảo toàn tính lồi.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter04/partial-optimization.png&quot; alt=&quot;[Fig1] partial optimization of a convex problem [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Tối ưu hóa từng phần của một bài toán lồi [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-dạng-hàm-mất-mát-hinge-của-svm&quot;&gt;Ví dụ: Dạng hàm mất mát hinge của SVM&lt;/h3&gt;
&lt;p&gt;Đối với tập dữ liệu không tách tuyến tính được, bài toán máy vectơ hỗ trợ (SVM) biên mềm được phát biểu như sau:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_{\beta, \beta_{0}, \xi} &amp;amp;&amp;amp;\frac{1}{2}\|\beta\|_2^2 + C \sum_{i=1}^{n} \xi_{i} \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;{\xi}_{i} \ge 0, \\ 
&amp;amp;&amp;amp;&amp;amp;y_{i}(x_{i}^T \beta + \beta_{0}) \ge 1 - {\xi}_{i}, \\
&amp;amp;&amp;amp;&amp;amp;i = 1, \dotsc, n. \\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;Hai nhóm ràng buộc trên có thể gộp lại thành một ràng buộc duy nhất theo \(\xi_i\):&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
{\xi}_{i} \ge \max\{0, 1 - y_{i} (x_{i}^T \beta + \beta_{0})\} \\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;Với mỗi cặp \((\beta, \beta_0)\) cố định, giá trị nhỏ nhất có thể của \(\xi_{i}\) chính là \(\max\{0, 1 - y_{i} (x_{i}^T \beta + \beta_{0})\}\). Khi tối ưu hóa riêng theo biến \(\xi\), ta định nghĩa hàm mục tiêu rút gọn \(\tilde{f}\) như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
\frac{1}{2} \|\beta\|_{2}^{2} + C \sum_{i=1}^{n} {\xi}_{i} &amp;amp;\ge \frac{1}{2} \|\beta\|_{2}^{2} + C \sum_{i=1}^{n} \max({0, 1 - y_{i} (x_{i}^T \beta + \beta_{0})})\\
&amp;amp;= \min\left\{\frac{1}{2} \|\beta\|_{2}^{2} + C \sum_{i=1}^{n} \xi_{i} \;\middle|\; \xi_{i} \ge 0, \ y_{i}(x_{i}^T \beta + \beta_{0}) \ge 1 - \xi_{i}, \ i = 1, \dotsc, n\right\} \\
&amp;amp;= \tilde{f}(\beta, \beta_{0}). \\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;Sử dụng hàm mục tiêu rút gọn \(\tilde{f}\) giúp loại bỏ hoàn toàn các biến phụ \(\xi\), đồng thời chuyển bài toán ban đầu từ dạng có ràng buộc sang bài toán tối ưu hóa lồi không ràng buộc tương đương:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
\min_{\beta, \beta_0} \frac{1}{2} \|\beta\|_2^2 + C \sum_{i=1}^{n} \max\{0, 1 - y_{i} (x_{i}^{T} \beta + \beta_{0}) \}
\end{aligned}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>04-03 Điều kiện tối ưu</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_03_Optimality_conditions/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_03_Optimality_conditions</id>
   <content type="html">&lt;p&gt;Trong giải tích năm nhất đại học, câu thần chú đầu tiên ai cũng thuộc lòng để tìm cực tiểu là: &lt;em&gt;“lấy đạo hàm và cho bằng không”&lt;/em&gt;. Nhưng ngay khi bước ra thế giới thực — nơi bạn không thể đầu tư số tiền âm, không thể sản xuất vượt công suất nhà máy, hay không thể đặt xác suất lớn hơn 1 — câu thần chú ấy lập tức thất bại: điểm tối ưu thường nằm ép sát vào biên tập khả thi, nơi gradient hoàn toàn khác không!&lt;/p&gt;

&lt;p&gt;Vậy làm sao ta biết chắc một điểm nằm trên biên thực sự là đáy sâu nhất? Câu trả lời của tối ưu hóa lồi mang vẻ đẹp hình học đáng kinh ngạc: &lt;strong&gt;tại điểm tối ưu \(x^\star\), hướng giảm nhanh nhất \(-\nabla f(x^\star)\) phải chỉ thẳng ra ngoài tập khả thi&lt;/strong&gt;, sao cho mọi bước đi hợp lệ \(y - x^\star\) vào bên trong tập khả thi đều tạo góc tù (hoặc vuông) với \(-\nabla f(x^\star)\), tức \(\nabla f(x^\star)^T (y - x^\star) \ge 0\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-đạo-hàm-cổ-điển-đến-điều-kiện-tối-ưu-có-ràng-buộc&quot;&gt;Kiến thức cần nhớ: Từ đạo hàm cổ điển đến điều kiện tối ưu có ràng buộc&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/chapter04/second-order-summary.png&quot; alt=&quot;Tóm tắt điều kiện tối ưu bậc hai&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Bài học này nối liền giải tích nhiều biến với hình học lồi qua bốn trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện tối ưu bậc nhất (First-Order Optimality / Variational Inequality):&lt;/strong&gt; Với hàm lồi khả vi \(f\) trên tập khả thi lồi \(C\), bất đẳng thức \(\nabla f(x^\star)^T (y - x^\star) \ge 0 \; \forall y \in C\) là điều kiện &lt;strong&gt;vừa cần vừa đủ&lt;/strong&gt; cho tối ưu toàn cục. Khi \(x^\star\) nằm ở phần trong của \(C\), nó tự động thu gọn về \(\nabla f(x^\star) = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nón pháp tuyến (Normal Cone):&lt;/strong&gt; Viết lại bất đẳng thức trên dưới dạng \((-\nabla f(x^\star))^T (y - x^\star) \le 0\) cho thấy \(-\nabla f(x^\star)\) thuộc nón pháp tuyến \(N_C(x^\star)\) — tập mọi vector “chống lại” mọi hướng đi vào \(C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không gian tiếp tuyến &amp;amp; Điều kiện bậc hai (Second-Order Conditions):&lt;/strong&gt; Đối với bài toán tổng quát (kể cả chưa chắc lồi), thông tin đạo hàm bậc nhất chỉ cho biết độ dốc, còn ma trận Hessian \(\nabla^2 f(x^\star)\) đo độ cong. Trên không gian các hướng khả thi, Hessian nửa xác định dương là điều kiện cần, và xác định dương chặt là điều kiện đủ cho cực tiểu địa phương chặt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hệ với Nhân tử Lagrange &amp;amp; KKT:&lt;/strong&gt; Khi tập \(C\) được mô tả bằng các bất đẳng thức và đẳng thức cụ thể, điều kiện \(-\nabla f(x^\star) \in N_C(x^\star)\) sẽ bung ra thành hệ phương trình KKT nổi tiếng mà ta sẽ học sâu hơn ở các chương đối ngẫu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-điều-kiện-tối-ưu-bậc-nhất-trên-ba-trường-hợp-điển-hình&quot;&gt;Giải thích: Kiểm chứng điều kiện tối ưu bậc nhất trên ba trường hợp điển hình&lt;/h3&gt;

&lt;p&gt;Xét hàm mục tiêu lồi \(f(x_1, x_2) = \frac{1}{2}(x_1 - 2)^2 + \frac{1}{2}(x_2 + 1)^2\), có gradient \(\nabla f(x) = (x_1 - 2,\; x_2 + 1)^T\), cực tiểu hóa trên góc phần tư không âm \(C = \{x \in \mathbb{R}^2 : x_1 \ge 0,\; x_2 \ge 0\}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Ứng viên 1 (sai): \(x^{(1)} = (1, 0)\).&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient: \(\nabla f(1, 0) = (-1, 1)^T\).&lt;/li&gt;
      &lt;li&gt;Chọn điểm khả thi \(y = (2, 0) \in C\). Khi đó \(y - x^{(1)} = (1, 0)^T\) và
\(\nabla f(x^{(1)})^T (y - x^{(1)}) = (-1)(1) + (1)(0) = -1 &amp;lt; 0.\)&lt;/li&gt;
      &lt;li&gt;Kết luận: Vi phạm điều kiện tối ưu! Đi theo hướng \((1,0)\) làm giảm \(f\) (thực tế \(f(2,0)=0.5 &amp;lt; f(1,0)=1\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng viên 2 (đúng): \(x^\star = (2, 0)\).&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient: \(\nabla f(2, 0) = (0, 1)^T \neq 0\)! Dù gradient khác không, hãy kiểm tra với &lt;strong&gt;mọi&lt;/strong&gt; \(y = (y_1, y_2) \in C\) (tức \(y_1 \ge 0, y_2 \ge 0\)):
\(\nabla f(x^\star)^T (y - x^\star) = 0 \cdot (y_1 - 2) + 1 \cdot (y_2 - 0) = y_2 \ge 0.\)&lt;/li&gt;
      &lt;li&gt;Kết luận: Thỏa mãn với mọi \(y \in C\)! Vì \(f\) lồi và \(C\) lồi, \(x^\star = (2, 0)\) chắc chắn là nghiệm tối ưu toàn cục, với \(f^\star = 0.5\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện bậc hai:&lt;/strong&gt; Ma trận Hessian \(\nabla^2 f(x^\star) = \begin{pmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{pmatrix} \succ 0\) xác định dương chặt trên mọi hướng khác không, khẳng định thêm rằng \(x^\star = (2, 0)\) là cực tiểu chặt duy nhất.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;điều-kiện-tối-ưu-bậc-nhất&quot;&gt;Điều kiện tối ưu bậc nhất&lt;/h2&gt;

&lt;p&gt;Để ôn lại các tính chất của hàm lồi, xem &lt;a href=&quot;/contents/vi/chapter03/03_01_03_key_properties_of_convex_functions/&quot;&gt;Chương 3: Các Tính chất Chính của Hàm Lồi&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Xét bài toán tối ưu hóa lồi:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_x &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;x \in C
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;Đối với một bài toán lồi có hàm mục tiêu \(f\) &lt;strong&gt;khả vi&lt;/strong&gt; và tập khả thi \(C\) lồi, điều kiện cần và đủ để điểm khả thi \(x \in C\) là điểm tối ưu là:&lt;/p&gt;

&lt;blockquote&gt;
\[\nabla f(x)^{T}(y-x) \geq 0 \quad \text{với mọi } y \in C\]
&lt;/blockquote&gt;

&lt;p&gt;Đây được gọi là &lt;em&gt;điều kiện bậc nhất cho tính tối ưu&lt;/em&gt; (first-order optimality condition).&lt;/p&gt;

&lt;p&gt;Phương trình \(\nabla f(x)^{T}(y-x) = 0\) xác định một siêu phẳng tựa đi qua \(x\) đối với tập \(C\), trong đó vectơ \(-\nabla f(x)\) là hướng giảm nhanh nhất của hàm \(f\) tại \(x\). &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Khi điều kiện trên được thỏa mãn, toàn bộ tập \(C\) nằm trong nửa không gian đối diện với hướng \(-\nabla f(x)\), nghĩa là không tồn tại hướng dịch chuyển khả thi nào từ \(x\) làm giảm giá trị hàm mục tiêu; do đó \(x\) là điểm tối ưu.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter04/first-order-condition.png&quot; alt=&quot;[Fig1] geometric interpretation of first-order condition for optimality [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Minh họa hình học cho điều kiện tối ưu bậc nhất [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;trường-hợp-đặc-biệt-quan-trọng&quot;&gt;Trường hợp đặc biệt quan trọng&lt;/h3&gt;
&lt;p&gt;Khi \(C = \mathbb{R}^n\) (bài toán tối ưu hóa không ràng buộc), điều kiện tối ưu bậc nhất rút gọn thành:&lt;/p&gt;
&lt;blockquote&gt;
\[\nabla f(x) = 0\]
&lt;/blockquote&gt;

&lt;p&gt;Trong trường hợp này, mọi hướng trong \(\mathbb{R}^n\) đều là hướng khả thi, nên điều kiện \(\nabla f(x) = 0\) có nghĩa là tại \(x\) không còn hướng nào giúp giảm giá trị của \(f\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;nền-tảng-toán-học-cho-điều-kiện-bậc-hai&quot;&gt;Nền tảng toán học cho điều kiện bậc hai&lt;/h2&gt;

&lt;p&gt;Trong khi các điều kiện bậc nhất sử dụng gradient \(\nabla f(x)\), các điều kiện bậc hai sử dụng &lt;strong&gt;ma trận Hessian&lt;/strong&gt;:&lt;/p&gt;

\[H_f(x) = \nabla^2 f(x) = \begin{bmatrix}
\frac{\partial^2 f}{\partial x_1^2} &amp;amp; \frac{\partial^2 f}{\partial x_1 \partial x_2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_1 \partial x_n} \\
\frac{\partial^2 f}{\partial x_2 \partial x_1} &amp;amp; \frac{\partial^2 f}{\partial x_2^2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_2 \partial x_n} \\
\vdots &amp;amp; \vdots &amp;amp; \ddots &amp;amp; \vdots \\
\frac{\partial^2 f}{\partial x_n \partial x_1} &amp;amp; \frac{\partial^2 f}{\partial x_n \partial x_2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_n^2}
\end{bmatrix}\]

&lt;p&gt;Ma trận Hessian mô tả &lt;strong&gt;độ cong&lt;/strong&gt; của hàm tại điểm \(x\), cung cấp thông tin về hình dạng cục bộ của hàm mục tiêu quanh điểm đang xét.&lt;/p&gt;

&lt;h2 id=&quot;điều-kiện-tối-ưu-bậc-hai&quot;&gt;Điều kiện tối ưu bậc hai&lt;/h2&gt;

&lt;p&gt;Xét bài toán tối ưu hóa không ràng buộc:
\(\min_x f(x)\)&lt;/p&gt;

&lt;p&gt;trong đó \(f: \mathbb{R}^n \to \mathbb{R}\) khả vi liên tục cấp hai.&lt;/p&gt;

&lt;h3 id=&quot;điều-kiện-cần-bậc-hai&quot;&gt;Điều kiện cần bậc hai&lt;/h3&gt;

&lt;p&gt;Nếu \(x^*\) là điểm cực tiểu địa phương của \(f\), thì:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện cần bậc nhất:&lt;/strong&gt; \(\nabla f(x^*) = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện cần bậc hai:&lt;/strong&gt; \(\nabla^2 f(x^*) \succeq 0\) (ma trận nửa xác định dương)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;điều-kiện-đủ-bậc-hai&quot;&gt;Điều kiện đủ bậc hai&lt;/h3&gt;

&lt;p&gt;Nếu tại điểm \(x^*\) thỏa mãn đồng thời:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;\(\nabla f(x^*) = 0\) (điều kiện bậc nhất)&lt;/li&gt;
  &lt;li&gt;\(\nabla^2 f(x^*) \succ 0\) (ma trận xác định dương)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;thì \(x^*\) là &lt;strong&gt;điểm cực tiểu địa phương chặt&lt;/strong&gt; của \(f\).&lt;/p&gt;

&lt;h2 id=&quot;tính-xác-định-dương-của-ma-trận-đối-xứng&quot;&gt;Tính xác định dương của ma trận đối xứng&lt;/h2&gt;

&lt;p&gt;Một ma trận đối xứng \(A\) được gọi là:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xác định dương&lt;/strong&gt; (\(A \succ 0\)) nếu \(v^T A v &amp;gt; 0\) với mọi \(v \neq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nửa xác định dương&lt;/strong&gt; (\(A \succeq 0\)) nếu \(v^T A v \geq 0\) với mọi \(v\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các tiêu chuẩn kiểm tra tính xác định dương trong thực tế:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chuẩn giá trị riêng:&lt;/strong&gt; Tất cả các giá trị riêng của \(A\) đều dương.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chuẩn Sylvester (định thức con chính dẫn đầu):&lt;/strong&gt; Tất cả các định thức con chính dẫn đầu của \(A\) đều dương.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích Cholesky:&lt;/strong&gt; Tồn tại ma trận tam giác dưới \(L\) có các phần tử đường chéo dương sao cho \(A = L L^T\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;giải-thích-hình-học&quot;&gt;Giải thích hình học&lt;/h2&gt;

&lt;p&gt;Các điều kiện bậc hai cho biết &lt;strong&gt;độ cong&lt;/strong&gt; của đồ thị hàm số tại điểm dừng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(\nabla^2 f(x^*) \succ 0\):&lt;/strong&gt; Đồ thị cong lên theo mọi hướng → &lt;strong&gt;cực tiểu địa phương chặt&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\nabla^2 f(x^*) \prec 0\):&lt;/strong&gt; Đồ thị cong xuống theo mọi hướng → &lt;strong&gt;cực đại địa phương chặt&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\nabla^2 f(x^*) \succeq 0\):&lt;/strong&gt; Độ cong không âm theo mọi hướng → &lt;strong&gt;có thể là điểm cực tiểu&lt;/strong&gt; (cần kiểm tra thêm ở bậc cao hơn).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hessian bất định:&lt;/strong&gt; Độ cong dương theo một số hướng và âm theo một số hướng khác → &lt;strong&gt;điểm yên ngựa&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter04/second-order-conditions.png&quot; alt=&quot;Second-order optimality conditions visualization&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Minh họa hình học về các điều kiện tối ưu bậc hai&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;các-ví-dụ-minh-họa&quot;&gt;Các ví dụ minh họa&lt;/h2&gt;

&lt;h3 id=&quot;ví-dụ-1-hàm-bậc-hai&quot;&gt;Ví dụ 1: Hàm bậc hai&lt;/h3&gt;
&lt;p&gt;Xét hàm \(f(x_1, x_2) = x_1^2 + 2x_2^2 + x_1 x_2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 1: Tìm điểm dừng&lt;/strong&gt;
\(\nabla f(x) = \begin{bmatrix} 2x_1 + x_2 \\ 4x_2 + x_1 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}\)&lt;/p&gt;

&lt;p&gt;Giải hệ phương trình trên thu được điểm dừng duy nhất \(x^* = (0, 0)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 2: Tính ma trận Hessian&lt;/strong&gt;
\(\nabla^2 f(x) = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 4 \end{bmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 3: Kiểm tra tính xác định dương&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Giá trị riêng: từ phương trình đặc trưng \(\lambda^2 - 6\lambda + 7 = 0\), ta có \(\lambda_1 = \frac{6 + \sqrt{8}}{2} = 3 + \sqrt{2} &amp;gt; 0\) và \(\lambda_2 = \frac{6 - \sqrt{8}}{2} = 3 - \sqrt{2} &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;Định thức con chính dẫn đầu: \(\Delta_1 = 2 &amp;gt; 0\) và \(\Delta_2 = \det = 8 - 1 = 7 &amp;gt; 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; \(\nabla^2 f(0,0) \succ 0\), do đó \((0,0)\) là điểm cực tiểu địa phương chặt (và cũng là cực tiểu toàn cục vì \(f\) lồi chặt).&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-2-hàm-không-lồi&quot;&gt;Ví dụ 2: Hàm không lồi&lt;/h3&gt;
&lt;p&gt;Xét hàm \(f(x_1, x_2) = x_1^4 + x_2^4 - 2x_1^2 - 2x_2^2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 1: Tìm các điểm dừng&lt;/strong&gt;
\(\nabla f(x) = \begin{bmatrix} 4x_1^3 - 4x_1 \\ 4x_2^3 - 4x_2 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}\)&lt;/p&gt;

&lt;p&gt;Các điểm dừng là: \((0,0)\), \((\pm 1, 0)\), \((0, \pm 1)\), và \((\pm 1, \pm 1)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 2: Phân tích tại \((0,0)\)&lt;/strong&gt;
\(\nabla^2 f(0,0) = \begin{bmatrix} -4 &amp;amp; 0 \\ 0 &amp;amp; -4 \end{bmatrix} \prec 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; \((0,0)\) là điểm cực đại địa phương chặt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bước 3: Phân tích tại \((1,1)\)&lt;/strong&gt;
\(\nabla^2 f(1,1) = \begin{bmatrix} 8 &amp;amp; 0 \\ 0 &amp;amp; 8 \end{bmatrix} \succ 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; \((1,1)\) là điểm cực tiểu địa phương chặt.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-3-điểm-yên-ngựa&quot;&gt;Ví dụ 3: Điểm yên ngựa&lt;/h3&gt;
&lt;p&gt;Xét hàm \(f(x_1, x_2) = x_1^2 - x_2^2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phân tích tại \((0,0)\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\nabla f(0,0) = (0,0)\) ✓&lt;/li&gt;
  &lt;li&gt;\(\nabla^2 f(0,0) = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; -2 \end{bmatrix}\) (ma trận bất định)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kết luận:&lt;/strong&gt; \((0,0)\) là một điểm yên ngựa (không phải cực tiểu cũng không phải cực đại).&lt;/p&gt;

&lt;h2 id=&quot;tối-ưu-hóa-có-ràng-buộc-điều-kiện-bậc-hai&quot;&gt;Tối ưu hóa có ràng buộc: Điều kiện bậc hai&lt;/h2&gt;

&lt;p&gt;Đối với bài toán tối ưu hóa có ràng buộc đẳng thức:
\(\min_x f(x) \text{ subject to } h_i(x) = 0, \, i = 1,\ldots,m\)&lt;/p&gt;

&lt;p&gt;ta sử dụng &lt;strong&gt;ma trận Hessian có viền&lt;/strong&gt; (bordered Hessian) của hàm Lagrange:
\(\mathcal{L}(x,\lambda) = f(x) + \sum_{i=1}^m \lambda_i h_i(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điều kiện đủ bậc hai:&lt;/strong&gt; Tại điểm dừng thỏa mãn điều kiện chính quy, nếu ma trận Hessian có viền có quán tính phù hợp (số giá trị riêng âm bằng đúng số ràng buộc \(m\) và \(n\) giá trị riêng còn lại đều dương), thì điểm đó là điểm cực tiểu địa phương chặt.&lt;/p&gt;

&lt;h2 id=&quot;so-sánh-điều-kiện-bậc-nhất-và-điều-kiện-bậc-hai&quot;&gt;So sánh điều kiện bậc nhất và điều kiện bậc hai&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khía cạnh&lt;/th&gt;
      &lt;th&gt;Điều kiện bậc nhất&lt;/th&gt;
      &lt;th&gt;Điều kiện bậc hai&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Thông tin sử dụng&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Gradient (độ dốc)&lt;/td&gt;
      &lt;td&gt;Ma trận Hessian (độ cong)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Điều kiện cần&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\nabla f(x^*) = 0\)&lt;/td&gt;
      &lt;td&gt;\(\nabla f(x^*) = 0\) và \(\nabla^2 f(x^*) \succeq 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Điều kiện đủ (không ràng buộc)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Không đủ với hàm tổng quát (chỉ đủ nếu \(f\) lồi)&lt;/td&gt;
      &lt;td&gt;\(\nabla f(x^*) = 0\) và \(\nabla^2 f(x^*) \succ 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Mức độ chặt&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Yếu hơn&lt;/td&gt;
      &lt;td&gt;Mạnh hơn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Chi phí tính toán&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Khả năng phân loại&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Chỉ xác định điểm dừng&lt;/td&gt;
      &lt;td&gt;Phân biệt cực tiểu, cực đại và điểm yên ngựa&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;công-cụ-minh-họa-tương-tác&quot;&gt;Công cụ minh họa tương tác&lt;/h2&gt;

&lt;p&gt;Khám phá trực quan cách hoạt động của các điều kiện bậc hai trong thực tế:&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;a href=&quot;../second_order_conditions_interactive.html&quot; target=&quot;_blank&quot; style=&quot;display: inline-block; padding: 12px 24px; background-color: #e74c3c; color: white; text-decoration: none; border-radius: 6px; font-weight: bold; box-shadow: 0 2px 4px rgba(0,0,0,0.2);&quot;&gt;
        🎯 Khởi động Công cụ Khám phá Điều kiện Bậc Hai
    &lt;/a&gt;
&lt;/div&gt;

&lt;p&gt;Công cụ tương tác này minh họa:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích giá trị riêng của ma trận Hessian&lt;/strong&gt; cho nhiều dạng hàm khác nhau.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân loại trực quan&lt;/strong&gt; các điểm dừng (cực tiểu, cực đại, điểm yên ngựa).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đồ thị đường đồng mức&lt;/strong&gt; thể hiện hành vi độ cong cục bộ của hàm số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các bước tính toán chi tiết&lt;/strong&gt; cho kiểm tra điều kiện bậc hai.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;điều-kiện-tối-ưu-bậc-nhất-trong-khoảng-3-phút&quot;&gt;Điều kiện tối ưu bậc nhất trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/first-order-optimality_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;∇f(x&lt;em&gt;)ᵀ(y − x&lt;/em&gt;) ≥ 0 trên một tam giác: kiểm tra bằng các đỉnh, nón pháp tuyến, gradient chiếu, nghiệm ở đỉnh, và 9 điểm dừng của ví dụ không lồi.&lt;/p&gt;

&lt;h2 id=&quot;tóm-tắt-và-điểm-chính&quot;&gt;Tóm tắt và điểm chính&lt;/h2&gt;

&lt;p&gt;Các điều kiện tối ưu bậc hai cho phép &lt;strong&gt;đặc trưng hóa chính xác hơn&lt;/strong&gt; bản chất của các điểm dừng:&lt;/p&gt;

&lt;h3 id=&quot;kết-quả-chính&quot;&gt;&lt;strong&gt;Kết quả chính:&lt;/strong&gt;&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện cần:&lt;/strong&gt; \(\nabla f(x^*) = 0\) và \(\nabla^2 f(x^*) \succeq 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện đủ:&lt;/strong&gt; \(\nabla f(x^*) = 0\) và \(\nabla^2 f(x^*) \succ 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả năng phân loại:&lt;/strong&gt; Phân biệt rõ ràng giữa điểm cực tiểu, điểm cực đại và điểm yên ngựa.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;ý-nghĩa-thực-tế&quot;&gt;&lt;strong&gt;Ý nghĩa thực tế:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thiết kế thuật toán:&lt;/strong&gt; Là cơ sở của các phương pháp kiểu Newton.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra tính lồi:&lt;/strong&gt; Hỗ trợ xác minh tính lồi của hàm khả vi cấp hai.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ tin cậy lý thuyết:&lt;/strong&gt; Cung cấp điều kiện chặt hơn so với chỉ dùng thông tin bậc nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên kết lý thuyết:&lt;/strong&gt; Góp phần kết nối phân tích cực trị địa phương với tối ưu toàn cục.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;cân-nhắc-về-tính-toán&quot;&gt;&lt;strong&gt;Cân nhắc về tính toán:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí:&lt;/strong&gt; Việc tính và lưu trữ ma trận Hessian có độ phức tạp \(O(n^2)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ Hessian:&lt;/strong&gt; Các phương pháp tựa Newton (Quasi-Newton) giúp giảm chi phí này khi số chiều \(n\) lớn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ổn định số:&lt;/strong&gt; Việc tính giá trị riêng hoặc phân tích ma trận đòi hỏi cài đặt số cẩn thận.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-02 Tập nghiệm lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_02_Convex_solution_sets/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_02_Convex_solution_sets</id>
   <content type="html">&lt;p&gt;Hãy tưởng tượng bạn thả một viên bi vào một chiếc bát đáy phẳng rồi thả nó vào một địa hình đồi núi lởm chởm. Ở địa hình đồi núi, hai vị trí thấp nhất có thể nằm ở hai thung lũng tách biệt bởi một đỉnh núi cao — đi từ nghiệm này sang nghiệm kia buộc bạn phải leo lên dốc. Nhưng trong chiếc bát lồi đáy phẳng, nếu có hai vị trí cùng thấp nhất, thì toàn bộ đoạn thẳng nối giữa chúng cũng nằm phẳng lì dưới đáy bát!&lt;/p&gt;

&lt;p&gt;Đó chính là trực giác tuyệt đẹp đứng sau &lt;strong&gt;tập nghiệm tối ưu của bài toán lồi&lt;/strong&gt;: tập \(X_{\text{opt}}\) luôn là một tập lồi, và ngay khi hàm mục tiêu có độ cong dương chặt (lồi chặt), chiếc bát mất hoàn toàn đáy phẳng — chỉ còn lại &lt;strong&gt;duy nhất một điểm tối ưu&lt;/strong&gt; trên toàn không gian.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-hình-học-tập-lồi-đến-tính-duy-nhất-của-nghiệm&quot;&gt;Kiến thức cần nhớ: Từ hình học tập lồi đến tính duy nhất của nghiệm&lt;/h2&gt;

&lt;p&gt;Để hiểu trọn vẹn sức mạnh của hai tính chất tập nghiệm trong bài học này, ta cần đặt chúng trên ba trụ cột:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tổ hợp lồi &amp;amp; Bất đẳng thức Jensen (Convex Combinations):&lt;/strong&gt; Nếu \(x, y \in X_{\text{opt}}\) đều đạt giá trị nhỏ nhất \(f^\star\), thì mọi điểm giữa \(z = \theta x + (1-\theta)y\) (\(\theta \in [0,1]\)) vừa thuộc tập khả thi lồi, vừa thỏa \(f(z) \le \theta f(x) + (1-\theta)f(y) = f^\star\). Bởi \(f^\star\) đã là nhỏ nhất, dấu bằng buộc phải xảy ra!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi chặt &amp;amp; Tính duy nhất (Strict Convexity &amp;amp; Uniqueness):&lt;/strong&gt; Khi \(f\) lồi chặt, bất đẳng thức Jensen trở thành bất đẳng thức ngặt \(f(z) &amp;lt; \theta f(x) + (1-\theta)f(y) = f^\star\) với mọi \(x \neq y\) và \(\theta \in (0,1)\). Điều này tạo ra mâu thuẫn ngay lập tức với định nghĩa \(f^\star\) — chứng minh chỉ có thể tồn tại nhiều nhất một nghiệm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ý nghĩa trong Học máy &amp;amp; Điều chuẩn (Regularization):&lt;/strong&gt; Nhiều bài toán như hồi quy tuyến tính thiếu hạng (\(n &amp;lt; p\)) hay Lasso (\(\ell_1\)) chỉ lồi chứ không lồi chặt, dẫn đến vô số nghiệm tối ưu nằm trên một đa diện lồi. Việc cộng thêm thành phần Ridge \(\frac{\lambda}{2}\|x\|_2^2\) (\(\lambda &amp;gt; 0\)) làm hàm mục tiêu trở nên lồi chặt, ép tập nghiệm co lại thành một điểm duy nhất ổn định.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-bài-toán-có-vô-số-nghiệm-lồi-và-bài-toán-có-nghiệm-duy-nhất&quot;&gt;Giải thích: So sánh bài toán có vô số nghiệm lồi và bài toán có nghiệm duy nhất&lt;/h3&gt;

&lt;p&gt;Xét hai bài toán trên cùng tập khả thi hình vuông \(\mathcal{F} = \{(x_1, x_2) : 0 \le x_1 \le 2,\; 0 \le x_2 \le 2\}\):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài toán A (Lồi nhưng không lồi chặt):&lt;/strong&gt; \(\min_{(x_1, x_2) \in \mathcal{F}} \; f_A(x_1, x_2) = |x_1 + x_2 - 2|.\)&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Vì \(f_A(x) \ge 0\) với mọi \(x\), giá trị nhỏ nhất có thể là \(f_A^\star = 0\) khi \(x_1 + x_2 = 2\).&lt;/li&gt;
  &lt;li&gt;Kiểm tra hai nghiệm phân biệt \(x^{(1)} = (2, 0)\) và \(x^{(2)} = (0, 2)\): cả hai đều thuộc \(\mathcal{F}\) và cho \(f_A = 0\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Lấy trung điểm \(z = 0.5 x^{(1)} + 0.5 x^{(2)} = (1, 1)\): ta có \(z \in \mathcal{F}\) và $$f_A(1, 1) =&lt;/td&gt;
          &lt;td&gt;1 + 1 - 2&lt;/td&gt;
          &lt;td&gt;= 0 = f_A^\star\(. Tập nghiệm\)X_{\text{opt}}\(là cả đoạn thẳng nối\)(2,0)\(đến\)(0,2)$$ — một tập lồi có vô số điểm!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Bài toán B (Thêm điều chuẩn lồi chặt):&lt;/strong&gt; \(\min_{(x_1, x_2) \in \mathcal{F}} \; f_B(x_1, x_2) = |x_1 + x_2 - 2| + 0.1(x_1^2 + x_2^2).\)&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Thành phần \(0.1(x_1^2 + x_2^2)\) có Hessian \(0.2 I \succ 0\) nên \(f_B\) là hàm &lt;strong&gt;lồi chặt&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Thử tính giá trị trên đoạn thẳng \(x_1 + x_2 = 2\): tại \((2, 0)\) và \((0, 2)\), \(f_B = 0 + 0.1(4 + 0) = 0.4\). Nhưng tại trung điểm \((1, 1)\), \(f_B(1, 1) = 0 + 0.1(1 + 1) = 0.2 &amp;lt; 0.4\)!&lt;/li&gt;
  &lt;li&gt;Vì \(f_B\) lồi chặt, nghiệm tối ưu toàn cục là duy nhất (thực tế nằm tại \(x_1 = x_2 = \frac{1}{1.1} \approx 0.9091\) nếu tính đạo hàm dọc đường \(x_1 = x_2\), nhưng trên vùng \(x_1 + x_2 &amp;lt; 2\) ta có \(f_B(t,t) = (2-2t) + 0.2t^2\) giảm cho tới \(t=1\) vì đạo hàm \(-2 + 0.4t &amp;lt; 0\) với \(t \le 1\), nên nghiệm duy nhất đúng là \((1, 1)\) với \(f_B^\star = 0.2\)!).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;Phần này trình bày các tính chất cơ bản của tập nghiệm trong một bài toán tối ưu hóa lồi. &lt;br /&gt;
Gọi \(X_{opt}\) là tập nghiệm tối ưu của một bài toán lồi:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
X_{opt} =
&amp;amp;\text{arg}\min_x &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;g_{i}(x) \leq 0, \quad i = 1, \dotsc, m \\
&amp;amp;&amp;amp;&amp;amp;h_{j}(x) = 0, \quad j = 1, \dotsc, r  \\\\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;tính-chất-chính-1&quot;&gt;Tính chất chính 1&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(X_{opt}\) là một tập lồi.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;chứng-minh&quot;&gt;Chứng minh&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;Giả sử \(x\) và \(y\) đều là nghiệm tối ưu của bài toán:&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;Vì miền xác định \(D\) là tập lồi nên với mọi \(0 \le t \le 1\), ta có \(tx + (1-t)y \in D\).&lt;/li&gt;
    &lt;li&gt;Vì \(g_i\) (\(i=1,\dotsc,m\)) là các hàm lồi và \(h_j\) (\(j=1, \dotsc,r\)) là các hàm affine, nên điểm \(tx + (1-t)y\) cũng thỏa mãn mọi ràng buộc:
 \(\begin{aligned}
    g_{i}(tx + (1-t)y) &amp;amp;\leq tg_i(x) + (1-t)g_i(y) \leq 0, \\
    h_{j}(tx + (1-t)y) &amp;amp;= th_j(x) + (1-t)h_j(y) = 0.
 \end{aligned}\)&lt;/li&gt;
    &lt;li&gt;Vì \(f\) là hàm lồi, ta có:
 \(\begin{aligned}
   f(tx+(1-t)y) &amp;amp;\leq tf(x) + (1-t)f(y) \\
   &amp;amp;= tf^{\star} + (1-t) f^{\star} \\
   &amp;amp;= f^{\star},
 \end{aligned}\)
 trong đó \(f^{\star}\) là giá trị tối ưu của bài toán. Do \(tx + (1-t)y\) là điểm khả thi nên \(f(tx+(1-t)y) \ge f^{\star}\), suy ra \(f(tx+(1-t)y) = f^{\star}\). Vậy \(tx + (1-t)y\) cũng là một nghiệm tối ưu.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;giải-thích-hình-học&quot;&gt;Giải thích hình học&lt;/h3&gt;
&lt;p&gt;Với một bài toán tối ưu hóa lồi, mọi cực tiểu địa phương đều là cực tiểu toàn cục. &lt;br /&gt;
Nếu tập nghiệm chứa nhiều hơn một phần tử, thì mọi tổ hợp lồi của các nghiệm cũng là nghiệm, nên tập nghiệm có dạng phẳng ở đáy như minh họa dưới đây:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter04/multiple-optima.png&quot; alt=&quot;[Fig1] geometric interpretation of convexity of the solution set&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Minh họa hình học về tính lồi của tập nghiệm&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;tính-chất-chính-2&quot;&gt;Tính chất chính 2&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;Nếu \(f\) là hàm lồi chặt, thì nghiệm tối ưu (nếu tồn tại) là duy nhất, tức là \(X_{opt}\) chứa tối đa một phần tử.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hàm \(f\) được gọi là lồi chặt nếu với mọi \(x \neq y \in \text{dom } f\) và mọi \(0 &amp;lt; t &amp;lt; 1\), ta luôn có:&lt;/p&gt;
&lt;blockquote&gt;
\[f(tx + (1-t)y) &amp;lt; tf(x) + (1-t)f(y).\]
&lt;/blockquote&gt;

&lt;p&gt;Về mặt hình học, đồ thị của hàm lồi chặt cong hướng lên và không chứa bất kỳ đoạn thẳng phẳng nào, do đó bài toán không thể có hai điểm cực tiểu phân biệt.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>04-01 Thuật ngữ cơ bản</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_01_Basic_terminology/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_01_Basic_terminology</id>
   <content type="html">&lt;p&gt;Trước khi xây một tòa nhà cao tầng, kiến trúc sư và kỹ sư kết cấu phải nói chung một ngôn ngữ: thế nào là tải trọng giới hạn, thế nào là vùng an toàn, và biên độ dự phòng được đo ra sao. Trong tối ưu hóa lồi cũng vậy: một sự nhầm lẫn nhỏ giữa &lt;em&gt;miền xác định&lt;/em&gt; \(D\) và &lt;em&gt;tập khả thi&lt;/em&gt;, hay giữa &lt;em&gt;giá trị tối ưu&lt;/em&gt; \(f^\star\) và &lt;em&gt;điểm tối ưu&lt;/em&gt; \(x^\star\), có thể khiến toàn bộ chứng minh định lý ở các chương sau sụp đổ.&lt;/p&gt;

&lt;p&gt;Bài học này đặt nền móng thuật ngữ chuẩn quốc tế cho mọi bài toán tối ưu hóa lồi — từ ràng buộc tích cực (active constraint), nghiệm \(\epsilon\)-cận tối ưu (thứ duy nhất máy tính thực sự đạt được trong thực tế), cho đến lý do cốt tử vì sao ràng buộc đẳng thức \(h_j(x) = 0\) bắt buộc phải là hàm affine chứ không thể là hàm lồi tùy ý.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-định-nghĩa-bài-toán-chuẩn&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép định nghĩa bài toán chuẩn&lt;/h2&gt;

&lt;p&gt;Khi đọc một bài toán tối ưu hóa bất kỳ, bộ não của người làm tối ưu tự động tách nó thành bốn lớp khái niệm rõ ràng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mục tiêu &amp;amp; Miền xác định ngầm (Objective &amp;amp; Implicit Domain):&lt;/strong&gt; Ngoài các ràng buộc viết tường minh, mỗi hàm toán học như \(\log(x)\) hay \(\sqrt{x}\) còn mang theo miền xác định riêng \(\operatorname{dom}(f)\). Miền chung \(D\) là giao của mọi miền xác định này — tập khả thi luôn là tập con của \(D\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc bất đẳng thức lồi và Tập mức dưới (Sublevel Sets):&lt;/strong&gt; Bất đẳng thức \(g_i(x) \le 0\) với \(g_i\) lồi chính là tập mức dưới tại mức \(0\) của \(g_i\), do đó luôn là một tập lồi. Ràng buộc nào đạt dấu bằng \(g_i(x^\star) = 0\) được gọi là &lt;em&gt;tích cực&lt;/em&gt; vì nó trực tiếp “chặn” nghiệm tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ràng buộc đẳng thức Affine (Affine Equality Constraints):&lt;/strong&gt; Đẳng thức \(h_j(x) = 0\) tương đương với cả \(h_j(x) \le 0\) lẫn \(-h_j(x) \le 0\). Để cả hai đều tạo thành tập lồi, \(h_j\) phải vừa lồi vừa lõm — tức là phải là hàm affine \(a_j^T x = b_j\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiệm chính xác vs. Nghiệm \(\epsilon\)-cận tối ưu:&lt;/strong&gt; Trong số học dấu phẩy động, thuật toán lặp hiếm khi chạm đúng \(f^\star\) sau hữu hạn bước. Khái niệm điểm khả thi thỏa \(f(x) \le f^\star + \epsilon\) là cầu nối giữa lý thuyết toán học thuần túy và tiêu chí dừng của bộ giải thực tế.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-giải-phẫu-đầy-đủ-thuật-ngữ-trên-một-bài-toán-cụ-thể&quot;&gt;Giải thích: Giải phẫu đầy đủ thuật ngữ trên một bài toán cụ thể&lt;/h3&gt;

&lt;p&gt;Xét bài toán 2 biến:
\(\min_{x_1, x_2} \; f(x_1, x_2) = -\log(x_1) + x_2^2 \quad \text{thỏa mãn} \quad g_1(x) = x_1 + x_2 - 2 \le 0,\quad g_2(x) = -x_2 \le 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Xác định miền \(D\):&lt;/strong&gt; Hàm \(-\log(x_1)\) đòi hỏi \(x_1 &amp;gt; 0\); các hàm còn lại xác định trên toàn \(\mathbb{R}^2\). Vậy \(D = \{(x_1, x_2) \in \mathbb{R}^2 : x_1 &amp;gt; 0\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác định tập khả thi \(\mathcal{F}\):&lt;/strong&gt; Là tập các điểm \((x_1, x_2)\) thỏa \(x_1 &amp;gt; 0\), \(x_2 \ge 0\) và \(x_1 + x_2 \le 2\) (một tam giác bỏ cạnh trục tung \(x_1 = 0\)). Điểm \((1, 0.5)\) là điểm khả thi vì \(1 &amp;gt; 0, 0.5 \ge 0, 1.5 \le 2\). Điểm \((0, 1)\) &lt;strong&gt;không&lt;/strong&gt; khả thi dù thỏa \(g_1, g_2 \le 0\) vì nó nằm ngoài \(D\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm điểm tối ưu \(x^\star\) và giá trị tối ưu \(f^\star\):&lt;/strong&gt; Với mọi \(x_1 \in (0, 2]\), muốn giảm \(f = -\log(x_1) + x_2^2\) ta cần \(x_1\) lớn nhất có thể và \(x_2\) nhỏ nhất có thể. Chọn \(x_2^\star = 0\) và đẩy \(x_1\) sát biên \(x_1 + 0 \le 2\) cho \(x_1^\star = 2\). Khi đó \(x^\star = (2, 0)\) và \(f^\star = -\log(2) \approx -0.6931\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân loại ràng buộc tại \(x^\star = (2, 0)\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(g_1(2, 0) = 2 + 0 - 2 = 0 \implies\) &lt;strong&gt;ràng buộc tích cực&lt;/strong&gt;.&lt;/li&gt;
      &lt;li&gt;\(g_2(2, 0) = -0 = 0 \implies\) &lt;strong&gt;ràng buộc tích cực&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra nghiệm \(\epsilon\)-cận tối ưu:&lt;/strong&gt; Xét điểm khả thi \(\tilde{x} = (1.9, 0.1)\). Ta có \(f(\tilde{x}) = -\log(1.9) + 0.01 \approx -0.6419 + 0.01 = -0.6319\). Độ lệch so với \(f^\star\) là \(-0.6319 - (-0.6931) = 0.0612\). Vậy \(\tilde{x}\) là điểm \(0.1\)-cận tối ưu (vì \(0.0612 \le 0.1\)) nhưng không phải \(0.05\)-cận tối ưu.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;cơ-bản-về-tối-ưu-hóa-lồi&quot;&gt;Cơ bản về Tối ưu hóa Lồi&lt;/h2&gt;

&lt;p&gt;Phần này ôn tập các thuật ngữ cơ bản thường dùng trong các bài toán tối ưu hóa lồi. Một bài toán tối ưu hóa lồi được phát biểu dưới dạng chuẩn như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\text{minimize}_{x \in D} &amp;amp;&amp;amp;{f(x)} \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;{g_{i}(x) \leq 0, \quad i = 1, \dotsc, m} \\
&amp;amp;&amp;amp;&amp;amp;{h_{j}(x) = 0, \quad j = 1, \dotsc, r},\\\\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;trong đó \(f\) và \(g_{i}\) (\(i=1,\dotsc, m\)) đều là các hàm lồi, \(h_j\) (\(j = 1, \dotsc, r\)) đều là các hàm affine, và miền xác định của bài toán là \(D = \operatorname{dom}(f) \cap \bigcap_{i=1}^{m} \operatorname{dom}(g_{i}) \cap \bigcap_{j=1}^r \operatorname{dom}(h_{j})\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;\(f\) được gọi là &lt;strong&gt;hàm tiêu chí&lt;/strong&gt; hoặc &lt;strong&gt;hàm mục tiêu&lt;/strong&gt; (objective function).&lt;/li&gt;
  &lt;li&gt;\(g_{i}(x)\) được gọi là &lt;strong&gt;hàm ràng buộc bất đẳng thức&lt;/strong&gt; (inequality constraint function).&lt;/li&gt;
  &lt;li&gt;\(h_{j}(x)\) được gọi là &lt;strong&gt;hàm ràng buộc đẳng thức&lt;/strong&gt; (equality constraint function).&lt;/li&gt;
  &lt;li&gt;Nếu \(x \in D\) thỏa mãn \(g_{i}(x) \leq 0\) với mọi \(i\) và \(h_{j}(x) = 0\) với mọi \(j\), thì \(x\) được gọi là một &lt;strong&gt;điểm khả thi&lt;/strong&gt; (feasible point).&lt;/li&gt;
  &lt;li&gt;Trên tập tất cả các điểm khả thi \(x\), giá trị nhỏ nhất của \(f(x)\) được gọi là &lt;strong&gt;giá trị tối ưu&lt;/strong&gt; (optimal value), ký hiệu là \(f^{\star}\).&lt;/li&gt;
  &lt;li&gt;Nếu \(x\) khả thi và \(f(x) = f^{\star}\), thì \(x\) được gọi là &lt;strong&gt;điểm tối ưu&lt;/strong&gt;, &lt;strong&gt;nghiệm tối ưu&lt;/strong&gt;, hoặc &lt;strong&gt;điểm cực tiểu&lt;/strong&gt; (minimizer).&lt;/li&gt;
  &lt;li&gt;Nếu \(x\) khả thi và \(f(x) \le f^{\star} + \epsilon\) (với \(\epsilon &amp;gt; 0\)), thì \(x\) được gọi là điểm &lt;strong&gt;\(\epsilon\)-cận tối ưu&lt;/strong&gt; (\(\epsilon\)-suboptimal).&lt;/li&gt;
  &lt;li&gt;Nếu \(x\) khả thi và \(g_i(x) = 0\), ta nói ràng buộc \(g_i\) là &lt;strong&gt;ràng buộc tích cực&lt;/strong&gt; (hay &lt;em&gt;hoạt động&lt;/em&gt;, active constraint) tại \(x\).&lt;/li&gt;
  &lt;li&gt;Mọi bài toán cực tiểu hóa lồi đều có thể chuyển tương đương thành một bài toán cực đại hóa lõm:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\text{maximize}_{x \in D} &amp;amp;&amp;amp;-f(x)\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;g_{i}(x) \leq 0, \quad i = 1, \dotsc, m\\
&amp;amp;&amp;amp;&amp;amp;h_{j}(x) = 0, \quad j = 1, \dotsc, r,\\\\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;trong đó \(f\) và \(g_{i}\) (\(i=1,\dotsc, m\)) đều là các hàm lồi, \(h_j\) (\(j = 1, \dotsc, r\)) đều là các hàm affine, và miền xác định của bài toán là \(D = \operatorname{dom}(f) \cap \bigcap_{i=1}^{m} \operatorname{dom}(g_{i}) \cap \bigcap_{j=1}^r \operatorname{dom}(h_{j})\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;tập-khả-thi&quot;&gt;Tập khả thi&lt;/h3&gt;

&lt;p&gt;Tập khả thi (còn gọi là miền khả thi hoặc không gian nghiệm khả thi) là tập hợp tất cả các điểm khả thi, biểu diễn toàn bộ các phương án thỏa mãn đồng thời mọi ràng buộc của bài toán.&lt;/p&gt;

&lt;p&gt;Tập khả thi, thường ký hiệu là \(S\) hoặc \(\mathcal{F}\), được định nghĩa như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[S = \{ \mathbf{x} \in X \mid g_i(\mathbf{x}) \le 0 \text{ với mọi } i=1, \dots, m, \text{ và } h_j(\mathbf{x}) = 0 \text{ với mọi } j=1, \dots, r \}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;tính-chất-của-tập-khả-thi&quot;&gt;Tính chất của tập khả thi&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính lồi:&lt;/strong&gt; Nếu tất cả các hàm ràng buộc bất đẳng thức \(g_i(\mathbf{x})\) đều lồi và tất cả các hàm ràng buộc đẳng thức \(h_j(\mathbf{x})\) đều affine, thì tập khả thi \(S\) là một &lt;strong&gt;tập lồi&lt;/strong&gt;. Đây là tính chất nền tảng của tối ưu hóa lồi, góp phần đảm bảo mọi cực tiểu địa phương cũng là cực tiểu toàn cục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bị chặn:&lt;/strong&gt; Một tập khả thi có thể &lt;strong&gt;bị chặn&lt;/strong&gt; (nằm gọn trong một vùng hữu hạn) hoặc &lt;strong&gt;không bị chặn&lt;/strong&gt; (trải dài vô hạn theo ít nhất một hướng).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tập rỗng:&lt;/strong&gt; Tập khả thi có thể rỗng (\(S = \emptyset\)), nghĩa là không tồn tại điểm nào thỏa mãn đồng thời mọi ràng buộc. Khi đó, bài toán tối ưu hóa được gọi là &lt;strong&gt;không khả thi&lt;/strong&gt; (infeasible).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đa diện lồi bị chặn và tập đa diện (Polytope / Polyhedron):&lt;/strong&gt; Trong quy hoạch tuyến tính, tập khả thi khác rỗng và bị chặn được gọi là &lt;strong&gt;đa diện lồi bị chặn&lt;/strong&gt; (polytope). Nếu tập khả thi khác rỗng nhưng có thể không bị chặn, nó được gọi là &lt;strong&gt;tập đa diện&lt;/strong&gt; (polyhedron). Cả hai đều là tập lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đỉnh (điểm cực biên):&lt;/strong&gt; Đối với bài toán quy hoạch tuyến tính, nếu tồn tại nghiệm tối ưu (và tập khả thi không chứa đường thẳng), thì luôn tồn tại ít nhất một nghiệm tối ưu nằm tại một đỉnh (còn gọi là điểm cực biên) của tập khả thi. Tính chất này là cơ sở của các thuật toán duyệt đỉnh như phương pháp đơn hình (Simplex).&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>04 Cơ bản về tối ưu hóa lồi</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_00_Convex_optimization_basics/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter04/04_00_Convex_optimization_basics</id>
   <content type="html">&lt;p&gt;Một kỹ sư lưới điện cần điều phối hàng trăm nhà máy phát điện mỗi 15 phút để vừa đủ công suất tiêu thụ, vừa tối thiểu hóa chi phí nhiên liệu mà không làm quá tải đường dây. Một nhà khoa học dữ liệu khác cần huấn luyện mô hình dự báo rủi ro tín dụng trên hàng triệu hồ sơ mà không bị mắc kẹt ở nghiệm xấu. Điểm chung của hai bài toán tưởng chừng cách xa nhau ấy là gì? Cả hai đều có thể được viết lại dưới &lt;strong&gt;khuôn mẫu bài toán tối ưu hóa lồi&lt;/strong&gt; — vùng đất hiếm hoi trong toán học ứng dụng nơi mọi điểm cực tiểu địa phương đều là cực tiểu toàn cục.&lt;/p&gt;

&lt;p&gt;Chương 04 đóng vai trò bản lề của toàn khóa học: ta chuyển từ ngôn ngữ hình học của &lt;em&gt;tập lồi&lt;/em&gt; (Chương 02) và &lt;em&gt;hàm lồi&lt;/em&gt; (Chương 03) sang ngôn ngữ hành động của &lt;strong&gt;bài toán tối ưu hóa lồi&lt;/strong&gt;. Không chỉ dừng ở việc đặt tên cho các thành phần, chương này còn dạy bạn nghệ thuật “nhìn xuyên qua lớp vỏ phi lồi” bằng các phép biến đổi tương đương như đổi biến, loại bỏ ràng buộc đẳng thức, thêm biến phụ hay nới lỏng.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-kiến-trúc-của-một-bài-toán-tối-ưu-hóa-lồi&quot;&gt;Kiến thức cần nhớ: Kiến trúc của một bài toán tối ưu hóa lồi&lt;/h2&gt;

&lt;p&gt;Để làm chủ Chương 04 mà không bị choáng ngợp bởi hàng loạt định lý và kỹ thuật biến đổi, hãy hình dung chương này đứng trên bốn trụ cột liên kết chặt chẽ:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hình học tập khả thi (Feasible Set Geometry):&lt;/strong&gt; Mỗi ràng buộc bất đẳng thức lồi \(g_i(x) \le 0\) cắt ra một tập mức dưới lồi, còn mỗi ràng buộc đẳng thức affine \(h_j(x) = 0\) cắt ra một siêu phẳng. Giao của chúng tạo thành tập khả thi lồi — nền sân phẳng không có “hốc lõm” bẫy thuật toán.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giải tích biến phân &amp;amp; Điều kiện tối ưu (Optimality Conditions):&lt;/strong&gt; Thay vì chỉ giải \(\nabla f(x) = 0\) như giải tích cổ điển (vốn chỉ đúng khi không có ràng buộc), tối ưu hóa lồi tổng quát hóa thành bất đẳng thức biến phân \(\nabla f(x^\star)^T (y - x^\star) \ge 0\) trên tập khả thi, và mở rộng lên bậc hai với ma trận Hessian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đại số các phép biến đổi tương đương (Equivalent Reformulations):&lt;/strong&gt; Một bài toán thực tế hiếm khi xuất hiện sẵn dưới dạng chuẩn. Các phép tối ưu hóa từng phần, đổi biến khả nghịch, loại bỏ ràng buộc đẳng thức tuyến tính và thêm biến phụ giúp ta biến đổi bài toán mà không làm mất nghiệm tối ưu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghệ thuật Nới lỏng (Convex Relaxation):&lt;/strong&gt; Khi bài toán gốc thực sự phi lồi (ví dụ biến nhị phân \(x_i \in \{0,1\}\)), ta thay tập khả thi bằng bao lồi lớn hơn để thu được cận dưới đáng tin cậy và điểm xuất phát tốt cho nghiệm xấp xỉ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-nhận-diện-và-giải-nhanh-một-bài-toán-tối-ưu-lồi-2-biến&quot;&gt;Giải thích: Nhận diện và giải nhanh một bài toán tối ưu lồi 2 biến&lt;/h3&gt;

&lt;p&gt;Xét bài toán: tìm \(x = (x_1, x_2) \in \mathbb{R}^2\) sao cho
\(\min \; f(x_1, x_2) = (x_1 - 3)^2 + (x_2 - 2)^2 \quad \text{thỏa mãn} \quad x_1 + x_2 \le 3,\; x_1 \ge 0,\; x_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra tính lồi:&lt;/strong&gt; Hàm mục tiêu \(f\) có Hessian \(\nabla^2 f = 2I \succ 0\) nên lồi chặt. Các ràng buộc \(x_1 + x_2 - 3 \le 0\), \(-x_1 \le 0\), \(-x_2 \le 0\) đều là hàm affine (nên lồi). Vậy đây là bài toán tối ưu hóa lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử nghiệm tự do (bỏ ràng buộc):&lt;/strong&gt; Giải \(\nabla f(x) = 0\) cho \(x_{\text{free}} = (3, 2)\). Thay vào ràng buộc: \(x_1 + x_2 = 5 &amp;gt; 3\), nên điểm tự do &lt;strong&gt;không khả thi&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiếu hình học lên biên tích cực:&lt;/strong&gt; Vì \((3,2)\) nằm ngoài tam giác khả thi, nghiệm tối ưu \(x^\star\) buộc phải nằm trên cạnh \(x_1 + x_2 = 3\). Thay \(x_2 = 3 - x_1\) vào \(f\):
\(\phi(x_1) = (x_1 - 3)^2 + (1 - x_1)^2 = 2x_1^2 - 8x_1 + 10.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cực tiểu hóa hàm 1 biến:&lt;/strong&gt; \(\phi&apos;(x_1) = 4x_1 - 8 = 0 \implies x_1^\star = 2\), suy ra \(x_2^\star = 1\). Kiểm tra: \(x_1^\star = 2 \ge 0\), \(x_2^\star = 1 \ge 0\), \(x_1^\star + x_2^\star = 3\). Giá trị tối ưu là \(f^\star = (2-3)^2 + (1-2)^2 = 2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện tối ưu bậc nhất:&lt;/strong&gt; \(\nabla f(2,1) = (-2, -2)\). Với mọi điểm khả thi \(y = (y_1, y_2)\) thỏa \(y_1 + y_2 \le 3\), ta có
\(\nabla f(x^\star)^T (y - x^\star) = -2(y_1 - 2) - 2(y_2 - 1) = -2(y_1 + y_2 - 3) \ge 0.\)
Điều kiện đủ được thỏa mãn tuyệt đối: \((2,1)\) là nghiệm tối ưu toàn cục duy nhất!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;cơ-bản-về-tối-ưu-hóa-lồi&quot;&gt;Cơ bản về Tối ưu hóa Lồi&lt;/h2&gt;

&lt;p&gt;Chương này giới thiệu các tính chất cơ bản của bài toán tối ưu hóa lồi cùng một số kỹ thuật biến đổi thường dùng để đưa bài toán về dạng thuận lợi hơn cho việc phân tích và giải quyết.&lt;/p&gt;

&lt;p&gt;Bài tùy chọn &lt;a href=&quot;/contents/vi/chapter04/04_09_Applications_Recent/&quot;&gt;04-09 Ứng dụng và phát triển gần đây&lt;/a&gt; trình bày cách các điều kiện tối ưu trong chương này được ứng dụng để xây dựng lớp tối ưu hóa khả vi trong mạng nơ-ron (cvxpylayers, Theseus) và các hàm mất mát thay thế lồi cho bài toán ra quyết định.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>04-11 Practical Exercises - Convex Optimization Problems</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_11_Practical_Exercises_Convex_Optimization_Problems/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_11_Practical_Exercises_Convex_Optimization_Problems</id>
   <content type="html">&lt;p&gt;Theory tells you &lt;em&gt;why&lt;/em&gt; a convex problem has a global optimum; hands-on reformulation teaches you &lt;em&gt;how&lt;/em&gt; to bend a messy real-world specification into a form a solver can actually ingest. In this practical workshop, you will convert mixed constraints, minimax objectives, robust least-squares models, and nonconvex relaxations step by step—building the exact modeling reflexes used in research and production optimization.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-practical-reformulation-toolkit&quot;&gt;Key ideas: Practical Reformulation Toolkit&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Epigraph Lifting for Nonsmooth Objectives&lt;/strong&gt;: Objectives containing \(\max_i f_i(x)\) or \(\|Ax - b\|_\infty\) are converted to smooth constraints by introducing a scalar variable \(t\), minimizing \(t\), and imposing \(f_i(x) \le t\) for every \(i\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Standardizing Mixed Constraints&lt;/strong&gt;: Greater-than inequalities \(a^T x \ge b\) flip to \(-a^T x + b \le 0\); free variables split into \(x = x^+ - x^-\) with \(x^+, x^- \ge 0\) when nonnegativity is required; and affine inequalities convert to equalities via nonnegative slacks.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Optimality as a Solver Check&lt;/strong&gt;: Before trusting numerical output from any solver, plug the candidate \(x^\star\) into \(\nabla f(x^\star)^T (y - x^\star) \ge 0\) (or check complementary slackness on box/orthant constraints) to certify optimality by hand.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convex Surrogates and Relaxations&lt;/strong&gt;: When an exercise includes cardinality, rank, or non-affine equality constraints, replace them with their tightest convex envelopes (e.g., \(\ell_1\) norm for \(\ell_0\), or \(g(x) \le 0\) for \(g(x) = 0\)) and check whether the relaxed solution is feasible for the original problem.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-epigraph-reformulation-of-a-minimax-linear-problem&quot;&gt;Worked example: Epigraph Reformulation of a Minimax Linear Problem&lt;/h3&gt;

&lt;p&gt;Before tackling the exercises below, practice the epigraph trick on:
\(\min_{x \in \mathbb{R}} \quad \max\{2x - 1,\; -x + 5,\; 3\}.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Introduce the epigraph scalar \(t \in \mathbb{R}\)&lt;/strong&gt;: Replace the piecewise-linear maximum with a linear objective \(\min_{x, t} t\) subject to \(t\) dominating every branch:
\(2x - 1 \le t, \qquad -x + 5 \le t, \qquad 3 \le t.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rewrite in standard form \(g_i(x, t) \le 0\)&lt;/strong&gt;:
\(2x - t - 1 \le 0, \qquad -x - t + 5 \le 0, \qquad 3 - t \le 0.\)
Every constraint is affine, so this is now a clean Linear Program in \((x, t)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve by intersecting the active branches&lt;/strong&gt;: Find where the two slanted lines meet:
\(2x - 1 = -x + 5 \implies 3x = 6 \implies x^\star = 2.\)
At \(x^\star = 2\), the three branches evaluate to \(2(2) - 1 = 3\), \(-2 + 5 = 3\), and \(3\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify optimality&lt;/strong&gt;: The minimum is \(t^\star = 3\) at \(x^\star = 2\). Moving left (\(x &amp;lt; 2\)) increases \(-x + 5 &amp;gt; 3\); moving right (\(x &amp;gt; 2\)) increases \(2x - 1 &amp;gt; 3\). Hence \((x^\star, t^\star) = (2, 3)\) is the unique global optimum, with all three constraints active simultaneously.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---convex-optimization-problems&quot;&gt;Practical Exercises - Convex Optimization Problems&lt;/h1&gt;

&lt;h2 id=&quot;-exercise-1-standard-form-transformations&quot;&gt;📝 &lt;strong&gt;Exercise 1: Standard form transformations&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Convert the following problems to standard forms:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Mixed constraints:&lt;/strong&gt;
\(\min_{x \in \mathbb{R}^3} x_1^2 + x_2^2 + x_3^2\)
\(\text{s.t.} \quad x_1 + 2x_2 - x_3 = 5, \quad x_1 - x_2 \geq 3, \quad x_2 \leq 4, \quad x_3 \text{ free}\)&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Minimax problem:&lt;/strong&gt;
\(\min_x \max_{i=1,\ldots,m} (a_i^T x + b_i)\)&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Robust least squares:&lt;/strong&gt;
\(\min_x \max_{\lVert u \rVert_2 \leq 1} \lVert (A + \sum_{i=1}^k u_i B_i)x - b \rVert_2^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Transform to the convex optimization standard form&lt;/li&gt;
  &lt;li&gt;Identify the variables, constraints, and objective&lt;/li&gt;
  &lt;li&gt;Verify convexity of the transformed problem&lt;/li&gt;
  &lt;li&gt;Discuss computational implications&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Mixed constraints problem**

**Handle free variable:** $$x_3 = x_3^+ - x_3^-$$ with $$x_3^+, x_3^- \geq 0$$

**Handle inequality:** $$x_1 - x_2 \geq 3 \Rightarrow -x_1 + x_2 \leq -3$$

**Standard form:**
$$\min_{x_1,x_2,x_3^+,x_3^-} x_1^2 + x_2^2 + (x_3^+)^2 + (x_3^-)^2 - 2x_3^+ x_3^-$$
$$\text{s.t.} \quad x_1 + 2x_2 - x_3^+ + x_3^- = 5$$
$$\quad -x_1 + x_2 \leq -3$$
$$\quad x_2 \leq 4$$
$$\quad x_3^+, x_3^- \geq 0 \quad (x_1, x_2 \text{ remain free: the original problem has no } x_1, x_2 \geq 0)$$

**Note:** $$(x_3^+ - x_3^-)^2 = (x_3^+)^2 + (x_3^-)^2 - 2x_3^+ x_3^-$$; the objective is still convex (PSD Hessian). Splitting a free variable is only needed for the LP standard form; for a QP solver it is unnecessary.

**Alternative approach:** Keep $$x_3$$ free, handle directly:
$$\min_{x_1,x_2,x_3} x_1^2 + x_2^2 + x_3^2$$
$$\text{s.t.} \quad x_1 + 2x_2 - x_3 = 5, \quad x_1 - x_2 \geq 3, \quad x_2 \leq 4$$

**Step 2: Minimax problem**

**Epigraph formulation:**
$$\min_{x,t} t$$
$$\text{s.t.} \quad a_i^T x + b_i \leq t, \quad i = 1,\ldots,m$$

**Convexity:** Linear objective, linear constraints $$\Rightarrow$$ LP

**Step 3: Robust least squares**

**Worst-case reformulation:**
$$\max_{\lVert u \rVert_2 \leq 1} \lVert (A + \sum_{i=1}^k u_i B_i)x - b \rVert_2^2$$

**Matrix form:** $$\max_{\lVert u \rVert_2 \leq 1} \lVert Ax - b + (\sum_{i=1}^k u_i B_i)x \rVert_2^2$$

**Let** $$q(x) = Ax - b$$ and $$P(x) = [B_1 x \ \cdots \ B_k x]$$ (affine in $$x$$); then $$(\sum_i u_i B_i)x = P(x)u$$ and the worst-case function is $$\max_{\lVert u \rVert_2 \leq 1} \lVert q(x) + P(x)u \rVert_2^2$$. This is **not** equal to $$\lVert q \rVert_2^2 + \lVert \sum_i B_i x \rVert_2^2$$.

**Semidefinite reformulation (S-lemma, Boyd &amp;amp; Vandenberghe §6.4.2):**
$$\min_{x,t,\lambda} t + \lambda$$
$$\text{s.t.} \quad \begin{bmatrix} I &amp;amp; P(x) &amp;amp; q(x) \\ P(x)^T &amp;amp; \lambda I &amp;amp; 0 \\ q(x)^T &amp;amp; 0 &amp;amp; t \end{bmatrix} \succeq 0$$

**SOCP upper bound (simpler but conservative):** since $$\lVert P(x)u \rVert_2 \leq \lVert P(x) \rVert_F$$ when $$\lVert u \rVert_2 \leq 1$$:
$$\min_{x} \ \lVert Ax - b \rVert_2 + \lVert P(x) \rVert_F$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-optimality-conditions-analysis&quot;&gt;📝 &lt;strong&gt;Exercise 2: Optimality conditions analysis&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Analyze the optimality conditions for the following problems:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Constrained quadratic:&lt;/strong&gt;
\(\min_x \frac{1}{2}x^T Q x + c^T x \quad \text{s.t.} \quad Ax = b, \quad x \geq 0\)
with \(Q \succeq 0\)&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Entropy maximization:&lt;/strong&gt;
\(\max_x -\sum_{i=1}^n x_i \log x_i \quad \text{s.t.} \quad \sum_{i=1}^n x_i = 1, \quad \sum_{i=1}^n a_i x_i = \alpha, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Support vector machine:&lt;/strong&gt;
\(\min_{w,b,\xi} \frac{1}{2}\lVert w \rVert_2^2 + C\sum_{i=1}^m \xi_i\)
\(\text{s.t.} \quad y_i(w^T x_i + b) \geq 1 - \xi_i, \quad \xi_i \geq 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Derive KKT conditions&lt;/li&gt;
  &lt;li&gt;Analyze complementary slackness&lt;/li&gt;
  &lt;li&gt;Characterize optimal solutions&lt;/li&gt;
  &lt;li&gt;Discuss geometric interpretation&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Constrained quadratic**

**Lagrangian:**
$$L(x,\lambda,\mu) = \frac{1}{2}x^T Q x + c^T x + \lambda^T(Ax - b) - \mu^T x$$

**KKT conditions:**
- **Stationarity:** $$Qx + c + A^T \lambda - \mu = 0$$
- **Primal feasibility:** $$Ax = b, x \geq 0$$
- **Dual feasibility:** $$\mu \geq 0$$
- **Complementary slackness:** $$\mu_i x_i = 0, \forall i$$

**Analysis:**
- If $$x_i &amp;gt; 0$$: $$\mu_i = 0$$
- If $$x_i = 0$$: $$\mu_i \geq 0$$ (reduced cost)

**Solution structure:** Active set methods exploit sparsity pattern.

**Step 2: Entropy maximization**

**Convert to minimization:**
$$\min_x \sum_{i=1}^n x_i \log x_i \quad \text{s.t.} \quad \sum_{i=1}^n x_i = 1, \sum_{i=1}^n a_i x_i = \alpha, x \geq 0$$

**Lagrangian:**
$$L(x,\lambda_1,\lambda_2,\mu) = \sum_{i=1}^n x_i \log x_i + \lambda_1(\sum x_i - 1) + \lambda_2(\sum a_i x_i - \alpha) - \sum \mu_i x_i$$

**KKT conditions:**
- **Stationarity:** $$\log x_i + 1 + \lambda_1 + \lambda_2 a_i - \mu_i = 0$$
- **Complementary slackness:** $$\mu_i x_i = 0$$

**Optimal solution:**
$$x_i^* = e^{-1 - \lambda_1 - \lambda_2 a_i}$$ (always $$&amp;gt; 0$$, so $$\mu_i = 0$$); normalizing: $$x_i^* = \frac{e^{-\lambda_2 a_i}}{\sum_j e^{-\lambda_2 a_j}}$$

**Exponential family form:** Maximum entropy distribution with moment constraints.

**Step 3: Support vector machine**

**Lagrangian:**
$$L(w,b,\xi,\alpha,\beta) = \frac{1}{2}\lVert w \rVert_2^2 + C\sum \xi_i - \sum \alpha_i[y_i(w^T x_i + b) - 1 + \xi_i] - \sum \beta_i \xi_i$$

**KKT conditions:**
- **Stationarity:**
  - $$\nabla_w L = w - \sum \alpha_i y_i x_i = 0 \Rightarrow w = \sum \alpha_i y_i x_i$$
  - $$\nabla_b L = -\sum \alpha_i y_i = 0$$
  - $$\nabla_{\xi_i} L = C - \alpha_i - \beta_i = 0$$

- **Complementary slackness:**
  - $$\alpha_i[y_i(w^T x_i + b) - 1 + \xi_i] = 0$$
  - $$\beta_i \xi_i = 0$$

**Support vector characterization:**
- $$\alpha_i = 0$$: $$x_i$$ not support vector
- $$0 &amp;lt; \alpha_i &amp;lt; C$$: $$x_i$$ on margin ($$\xi_i = 0$$)
- $$\alpha_i = C$$: $$x_i$$ violates margin ($$\xi_i &amp;gt; 0$$)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-duality-and-sensitivity-analysis&quot;&gt;📝 &lt;strong&gt;Exercise 3: Duality and sensitivity analysis&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Consider the linear program:
\(\min_x c^T x \quad \text{s.t.} \quad Ax \leq b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;a) Derive the dual problem and analyze the strong duality conditions
b) Perform sensitivity analysis: How does the optimal value change with \(b\)?
c) Shadow prices interpretation
d) Parametric programming: \(b(\theta) = b_0 + \theta d\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Complete duality analysis&lt;/li&gt;
  &lt;li&gt;Sensitivity computations&lt;/li&gt;
  &lt;li&gt;Economic interpretation&lt;/li&gt;
  &lt;li&gt;Parametric solution paths&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Dual derivation**

**Primal:** $$\min_x c^T x \text{ s.t. } Ax \leq b, x \geq 0$$

**Lagrangian:** $$L(x,\lambda) = c^T x + \lambda^T(Ax - b)$$

**Dual function:** $$g(\lambda) = \inf_x L(x,\lambda) = \inf_x (c + A^T \lambda)^T x - \lambda^T b$$

**Condition for finiteness:** $$c + A^T \lambda \geq 0$$

**Dual problem:**
$$\max_\lambda -\lambda^T b \quad \text{s.t.} \quad A^T \lambda + c \geq 0, \quad \lambda \geq 0$$

Equivalently:
$$\max_\nu b^T \nu \quad \text{s.t.} \quad A^T \nu \leq c, \quad \nu \leq 0 \qquad (\nu = -\lambda)$$

**Step 2: Strong duality conditions**

**Slater&apos;s condition:** $$\exists x &amp;gt; 0 \text{ s.t. } Ax &amp;lt; b$$

**Fundamental theorem of LP:** Strong duality holds when both the primal and the dual are feasible.

**Complementary slackness:**
- $$(c + A^T \lambda^*)_j x_j^* = 0, \forall j$$
- $$\lambda_i^* (Ax^* - b)_i = 0, \forall i$$

**Step 3: Sensitivity analysis**

**Optimal value function:** $$f^*(b) = \min\{c^T x : Ax \leq b, x \geq 0\}$$

**Envelope theorem:** $$\nabla_b f^*(b) = -\lambda^*(b) \leq 0$$ (relaxing $$b$$ decreases the optimal value; at points where $$f^*$$ is differentiable)

**Shadow price interpretation:** $$\lambda_i^*$$ = marginal value of resource $$i$$

**Practical computation:**
- Solve primal-dual pair
- $$\lambda^*$$ gives sensitivity coefficients
- Valid in a neighborhood of the current $$b$$

**Step 4: Parametric programming**

**Parameterized problem:** $$\min_x c^T x \text{ s.t. } Ax \leq b_0 + \theta d, x \geq 0$$

**Optimal value:** $$f^*(\theta) = f^*(b_0 + \theta d)$$

**Piecewise linear:** $$f^*(\theta)$$ is piecewise linear in $$\theta$$

**Critical points:** Breakpoints where the optimal basis changes

**Solution path:**
1. Start with the optimal solution at $$\theta = 0$$
2. Increase $$\theta$$ until basis change
3. Pivot to new basis
4. Repeat until desired $$\theta$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-relaxation-techniques&quot;&gt;📝 &lt;strong&gt;Exercise 4: Relaxation techniques&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Consider the integer programming problem:
\(\min_x c^T x \quad \text{s.t.} \quad Ax \leq b, \quad x_i \in \{0,1\}, \quad i \in I\)&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;LP relaxation:&lt;/strong&gt; Relax \(x_i \in [0,1]\)
b) &lt;strong&gt;Lagrangian relaxation:&lt;/strong&gt; Dualize a subset of the constraints
c) &lt;strong&gt;SDP relaxation:&lt;/strong&gt; \(x_i x_j = X_{ij}\) with \(X \succeq 0\)
d) &lt;strong&gt;Convex hull:&lt;/strong&gt; Characterize \(\text{conv}(\text{feasible integer points})\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Formulate relaxations&lt;/li&gt;
  &lt;li&gt;Analyze bound quality&lt;/li&gt;
  &lt;li&gt;Tightening techniques&lt;/li&gt;
  &lt;li&gt;Computational comparison&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: LP relaxation**

**Relaxed problem:**
$$\min_x c^T x \quad \text{s.t.} \quad Ax \leq b, \quad 0 \leq x_i \leq 1, \quad i \in I$$

**Properties:**
- **Lower bound:** $$z_{LP} \leq z_{IP}$$
- **Polynomial time** solvable
- **Tight when** the optimal LP solution is integer

**Integrality gap:** $$\frac{z_{IP}}{z_{LP}}$$

**Step 2: Lagrangian relaxation**

**Dualize constraints $$A_2 x \leq b_2$$:**
$$L_D(\lambda) = \min_x \{c^T x + \lambda^T(A_2 x - b_2) : A_1 x \leq b_1, x_i \in \{0,1\}\}$$

**Dual bound:** $$\max_{\lambda \geq 0} L_D(\lambda)$$

**Advantages:**
- **Decomposition:** If $$A_1$$ is block diagonal
- **Better bounds:** Potentially tighter than LP relaxation
- **Subgradient optimization:** For dual problem

**Step 3: SDP relaxation**

**Quadratic reformulation:** $$\min \sum_{ij} c_{ij} x_i x_j$$

**SDP relaxation:**
$$\min_{X} \sum_{ij} c_{ij} X_{ij}$$
$$\text{s.t.} \quad \text{linear constraints in } X$$
$$\quad X_{ii} = x_i, \quad X \succeq 0$$

**Rank-1 constraint:** $$X = xx^T$$ (relaxed)

**Applications:**
- **Max-cut:** Goemans-Williamson algorithm
- **Quadratic assignment:** QAP relaxations

**Step 4: Convex hull characterization**

**Polytope:** $$P_I = \text{conv}\{x \in \{0,1\}^n : Ax \leq b\}$$

**Facet identification:**
- **Valid inequalities:** $$\alpha^T x \leq \beta$$ for all $$x \in P_I$$
- **Facet-defining:** Maximal valid inequalities

**Cutting plane methods:**
1. Solve LP relaxation
2. If fractional, find violated valid inequality
3. Add the cut and re-solve
4. Repeat until integer solution

**Examples:**
- **Knapsack:** Cover inequalities
- **TSP:** Subtour elimination constraints

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-robust-optimization&quot;&gt;📝 &lt;strong&gt;Exercise 5: Robust optimization&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Portfolio optimization under uncertainty:
\(\min_x x^T \Sigma x \quad \text{s.t.} \quad \mu^T x \geq r, \quad \mathbf{1}^T x = 1, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;with uncertain parameters \((\mu, \Sigma)\).&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Box uncertainty:&lt;/strong&gt; \(\mu_i \in [\underline{\mu}_i, \overline{\mu}_i]\)
b) &lt;strong&gt;Ellipsoidal uncertainty:&lt;/strong&gt; \(\mu \in \{\mu_0 + Pu : \lVert u \rVert_2 \leq 1\}\)
c) &lt;strong&gt;Factor model:&lt;/strong&gt; \(\mu = \beta f + \epsilon\) with \(f\) uncertain
d) &lt;strong&gt;Distributionally robust:&lt;/strong&gt; \(\mathbb{E}_P[\mu] = \mu_0\), \(\text{Var}_P[\mu] \preceq \Sigma_0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Reformulate as deterministic convex programs&lt;/li&gt;
  &lt;li&gt;Analyze conservatism levels&lt;/li&gt;
  &lt;li&gt;Compare computational complexity&lt;/li&gt;
  &lt;li&gt;Practical implementation&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Box uncertainty**

**Worst-case constraint:** $$\min_{\mu \in \mathcal{U}} \mu^T x \geq r$$

with $$\mathcal{U} = \{\mu : \underline{\mu}_i \leq \mu_i \leq \overline{\mu}_i\}$$

**Worst-case analysis:**
$$\min_{\mu \in \mathcal{U}} \mu^T x = \sum_{i: x_i \geq 0} \underline{\mu}_i x_i + \sum_{i: x_i &amp;lt; 0} \overline{\mu}_i x_i$$

**Robust formulation:**
$$\min_x x^T \Sigma x$$
$$\text{s.t.} \quad \sum_{i: x_i \geq 0} \underline{\mu}_i x_i + \sum_{i: x_i &amp;lt; 0} \overline{\mu}_i x_i \geq r$$
$$\quad \mathbf{1}^T x = 1, \quad x \geq 0$$

**Step 2: Ellipsoidal uncertainty**

**Uncertainty set:** $$\mathcal{U} = \{\mu_0 + Pu : \lVert u \rVert_2 \leq 1\}$$

**Worst-case constraint:**
$$\min_{\lVert u \rVert_2 \leq 1} (\mu_0 + Pu)^T x = \mu_0^T x - \lVert P^T x \rVert_2 \geq r$$

**Robust formulation:**
$$\min_x x^T \Sigma x$$
$$\text{s.t.} \quad \mu_0^T x - \lVert P^T x \rVert_2 \geq r$$
$$\quad \mathbf{1}^T x = 1, \quad x \geq 0$$

**SOCP formulation:** Second-order cone constraint

**Step 3: Factor model**

**Model:** $$\mu = \beta f + \epsilon$$ with $$f \in \mathcal{F}$$, $$\epsilon$$ noise

**Uncertainty set:** $$\mathcal{U} = \{\beta f + \epsilon : f \in \mathcal{F}, \lVert \epsilon \rVert_2 \leq \sigma\}$$

**Worst-case analysis:**
$$\min_{\mu \in \mathcal{U}} \mu^T x = \min_{f \in \mathcal{F}} (\beta f)^T x - \sigma \lVert x \rVert_2$$

**Multi-factor case:** $$\mu = \sum_{k=1}^K \beta_k f_k + \epsilon$$

**Step 4: Distributionally robust**

**Ambiguity set:** $$\mathcal{P} = \{P : \mathbb{E}_P[\mu] = \mu_0, \text{Cov}_P[\mu] \preceq \Sigma_0\}$$

**Note:** the expectation itself carries no uncertainty: $$\mathbb{E}_P[\mu^T x] = \mu_0^T x$$ for every $$P \in \mathcal{P}$$. Robustness comes from the chance constraint $$\inf_{P \in \mathcal{P}} \mathbb{P}_P[\mu^T x \geq r] \geq 1 - \epsilon$$, which is equivalent (one-sided Cantelli/Chebyshev inequality) to:
$$\mu_0^T x - \kappa \sqrt{x^T \Sigma_0 x} \geq r, \qquad \kappa = \sqrt{\frac{1-\epsilon}{\epsilon}}$$

**Robust formulation:**
$$\min_x x^T \Sigma x$$
$$\text{s.t.} \quad \mu_0^T x - \kappa \sqrt{x^T \Sigma_0 x} \geq r$$
$$\quad \mathbf{1}^T x = 1, \quad x \geq 0$$

**Connection:** Ellipsoidal uncertainty with $$P P^T = \kappa^2 \Sigma_0$$ (since $$\lVert P^T x \rVert_2^2 = x^T P P^T x$$)

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-6-multi-objective-optimization&quot;&gt;📝 &lt;strong&gt;Exercise 6: Multi-objective optimization&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Consider the bi-objective problem:
\(\min_x (f_1(x), f_2(x)) \quad \text{s.t.} \quad x \in \mathcal{X}\)&lt;/p&gt;

&lt;p&gt;with \(f_1, f_2\) convex and \(\mathcal{X}\) convex.&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Pareto efficiency:&lt;/strong&gt; Characterize Pareto optimal solutions
b) &lt;strong&gt;Scalarization methods:&lt;/strong&gt; Weighted sum, \(\epsilon\)-constraint, achievement
c) &lt;strong&gt;Pareto frontier computation:&lt;/strong&gt; Systematic enumeration
d) &lt;strong&gt;Applications:&lt;/strong&gt; Portfolio optimization, engineering design&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Theoretical characterization&lt;/li&gt;
  &lt;li&gt;Algorithmic approaches&lt;/li&gt;
  &lt;li&gt;Computational examples&lt;/li&gt;
  &lt;li&gt;Practical considerations&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Pareto efficiency characterization**

**Definition:** $$x^*$$ is Pareto optimal if there is no $$x \in \mathcal{X}$$ such that:
- $$f_i(x) \leq f_i(x^*)$$ for all $$i$$
- $$f_j(x) &amp;lt; f_j(x^*)$$ for some $$j$$

**Necessary condition:** If $$x^*$$ is Pareto optimal, there exists $$\lambda \geq 0$$, $$\lambda \neq 0$$ such that $$x^*$$ solves:
$$\min_x \sum_{i=1}^2 \lambda_i f_i(x) \quad \text{s.t.} \quad x \in \mathcal{X}$$

**Sufficient condition:** If $$\lambda &amp;gt; 0$$ and $$x^*$$ uniquely solves the weighted problem, then $$x^*$$ is Pareto optimal.

**Step 2: Scalarization methods**

**Weighted sum method:**
$$\min_x \lambda_1 f_1(x) + \lambda_2 f_2(x) \quad \text{s.t.} \quad x \in \mathcal{X}$$

with $$\lambda_1, \lambda_2 \geq 0$$, $$\lambda_1 + \lambda_2 = 1$$

**Limitations:** Cannot find non-convex parts of the Pareto frontier

**$$\epsilon$$-constraint method:**
$$\min_x f_1(x) \quad \text{s.t.} \quad f_2(x) \leq \epsilon, \quad x \in \mathcal{X}$$

**Advantages:** Can find entire Pareto frontier

**Achievement scalarization:**
$$\min_{x,t} t \quad \text{s.t.} \quad f_i(x) - z_i^* \leq t, \quad x \in \mathcal{X}$$

with $$z^*$$ the ideal point: $$z_i^* = \min_x f_i(x)$$

**Step 3: Pareto frontier computation**

**Algorithm 1: Weighted sum sweep**
```
For λ₁ = 0 to 1 (step δ):
    λ₂ = 1 - λ₁
    Solve: min λ₁f₁(x) + λ₂f₂(x) s.t. x ∈ X
    Store solution if Pareto optimal
```

**Algorithm 2: $$\epsilon$$-constraint sweep**
```
Compute range [ε_min, ε_max] for f₂
For ε = ε_min to ε_max (step δ):
    Solve: min f₁(x) s.t. f₂(x) ≤ ε, x ∈ X
    Store solution
```

**Algorithm 3: Normal boundary intersection**
- Construct the convex hull of the individual minima
- Generate evenly distributed points
- Solve constrained problems

**Step 4: Portfolio example**

**Objectives:**
- $$f_1(x) = x^T \Sigma x$$ (risk)
- $$f_2(x) = -\mu^T x$$ (negative return)

**Constraints:** $$\mathbf{1}^T x = 1$$, $$x \geq 0$$

**Efficient frontier:** 
$$\min_x x^T \Sigma x \quad \text{s.t.} \quad \mu^T x \geq r, \quad \mathbf{1}^T x = 1, \quad x \geq 0$$

**Parametric solution:** $$r \in [r_{\min}, r_{\max}]$$

**Mean-variance frontier:** Hyperbola in $$(r, \sigma)$$ space

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-7-stochastic-optimization&quot;&gt;📝 &lt;strong&gt;Exercise 7: Stochastic optimization&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Two-stage stochastic program:
\(\min_{x} c^T x + \mathbb{E}_\xi[Q(x, \xi)]\)
\(\text{s.t.} \quad Ax = b, \quad x \geq 0\)&lt;/p&gt;

&lt;p&gt;with \(Q(x, \xi) = \min_y \{q^T y : Wy = h - Tx, y \geq 0\}\)&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Sample average approximation (SAA)&lt;/strong&gt;
b) &lt;strong&gt;Scenario-based formulation&lt;/strong&gt;
c) &lt;strong&gt;Benders decomposition&lt;/strong&gt;
d) &lt;strong&gt;Risk measures:&lt;/strong&gt; CVaR, robust optimization&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Deterministic equivalent formulations&lt;/li&gt;
  &lt;li&gt;Decomposition algorithms&lt;/li&gt;
  &lt;li&gt;Statistical analysis&lt;/li&gt;
  &lt;li&gt;Risk-aware extensions&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Sample average approximation**

**True problem:** $$\min_x \{c^T x + \mathbb{E}_\xi[Q(x, \xi)] : Ax = b, x \geq 0\}$$

**SAA approximation:** $$\min_x \{c^T x + \frac{1}{N}\sum_{i=1}^N Q(x, \xi^i) : Ax = b, x \geq 0\}$$

with $$\xi^1, \ldots, \xi^N$$ i.i.d. samples

**Convergence:** $$\hat{x}_N \to x^*$$ as $$N \to \infty$$ (w.p.1)

**Sample size:** $$N = O(\epsilon^{-2})$$ for $$\epsilon$$-optimal solution

**Step 2: Scenario-based formulation**

**Deterministic equivalent:**
$$\min_{x,y^1,\ldots,y^N} c^T x + \frac{1}{N}\sum_{i=1}^N q^T y^i$$
$$\text{s.t.} \quad Ax = b, \quad x \geq 0$$
$$\quad W y^i = h^i - T^i x, \quad y^i \geq 0, \quad i = 1,\ldots,N$$

**Large-scale LP:** $$(n + Nm)$$ variables, $$(m + Nm)$$ constraints

**Block structure:** Exploitable by decomposition

**Step 3: Benders decomposition**

**Master problem:**
$$\min_{x,\theta} c^T x + \theta$$
$$\text{s.t.} \quad Ax = b, \quad x \geq 0$$
$$\quad \theta \geq \frac{1}{N}\sum_{i=1}^N (\pi^{i,k})^T(h^i - T^i x), \quad k = 1, 2, \ldots \quad \text{(optimality cuts, } \pi^{i,k} \text{ is the dual solution of the subproblem)}$$

**Subproblems:** For each scenario $$i$$:
$$\min_{y^i} q^T y^i \quad \text{s.t.} \quad W y^i = h^i - T^i x, \quad y^i \geq 0$$

**Algorithm:**
1. Solve master problem → get $$x^k$$
2. Solve subproblems → get $$\pi^{i,k}$$
3. Add Benders cuts
4. Repeat until convergence

**Step 4: Risk measures**

**Conditional Value-at-Risk (CVaR):**
$$\text{CVaR}_\alpha[Z] = \mathbb{E}[Z | Z \geq \text{VaR}_\alpha[Z]]$$

**Optimization formulation:**
$$\min_{x,\eta,s} c^T x + \eta + \frac{1}{(1-\alpha)N}\sum_{i=1}^N s_i$$
$$\text{s.t.} \quad Ax = b, \quad x \geq 0$$
$$\quad s_i \geq Q(x, \xi^i) - \eta, \quad s_i \geq 0$$

**Risk-constrained:**
$$\min_x c^T x \quad \text{s.t.} \quad \text{CVaR}_\alpha[Q(x, \xi)] \leq \gamma$$

**Robust approach:** Worst-case over ambiguity set
$$\min_x c^T x + \max_{P \in \mathcal{P}} \mathbb{E}_P[Q(x, \xi)]$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-8-conic-optimization&quot;&gt;📝 &lt;strong&gt;Exercise 8: Conic optimization&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Analyze conic optimization problems:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Second-order cone programming (SOCP):&lt;/strong&gt;
\(\min_x c^T x \quad \text{s.t.} \quad \lVert A_i x + b_i \rVert_2 \leq c_i^T x + d_i\)&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Semidefinite programming (SDP):&lt;/strong&gt;
\(\min_X \langle C, X \rangle \quad \text{s.t.} \quad \langle A_i, X \rangle = b_i, \quad X \succeq 0\)&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Exponential cone programming:&lt;/strong&gt;
\(\min_x c^T x \quad \text{s.t.} \quad (x_i, x_j, x_k) \in \mathcal{K}_{\exp}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Standard form representations&lt;/li&gt;
  &lt;li&gt;Duality theory&lt;/li&gt;
  &lt;li&gt;Interior-point algorithms&lt;/li&gt;
  &lt;li&gt;Applications and modeling&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Second-order cone programming**

**Standard form:**
$$\min_x c^T x \quad \text{s.t.} \quad Ax = b, \quad x \in \mathcal{K}$$

with $$\mathcal{K} = \mathcal{K}_1 \times \cdots \times \mathcal{K}_m$$ and $$\mathcal{K}_i = \{(t, u) : \lVert u \rVert_2 \leq t\}$$

**Dual problem:**
$$\max_y b^T y \quad \text{s.t.} \quad A^T y + s = c, \quad s \in \mathcal{K}$$

**Self-dual cone:** $$\mathcal{K}_i^* = \mathcal{K}_i$$

**Applications:**
- **Robust optimization:** Ellipsoidal uncertainty
- **Portfolio optimization:** Risk measures
- **Filter design:** Frequency response constraints

**Step 2: Semidefinite programming**

**Standard form:**
$$\min_X \langle C, X \rangle \quad \text{s.t.} \quad \langle A_i, X \rangle = b_i, \quad X \succeq 0$$

**Vectorized form:** $$\min_x c^T x \text{ s.t. } Ax = b, x \in \mathcal{S}_+^n$$

**Dual problem:**
$$\max_y b^T y \quad \text{s.t.} \quad \sum_{i=1}^m y_i A_i + S = C, \quad S \succeq 0$$

**Strong duality:** Holds under Slater condition

**Applications:**
- **Combinatorial optimization:** Max-cut, coloring
- **Control theory:** LMI constraints
- **Machine learning:** Kernel methods

**Step 3: Exponential cone**

**Exponential cone:** $$\mathcal{K}_{\exp} = \{(x,y,z) : ye^{x/y} \leq z, y &amp;gt; 0\} \cup \{(x,0,z) : x \leq 0, z \geq 0\}$$

**Dual cone:** $$\mathcal{K}_{\exp}^* = \{(u,v,w) : u &amp;lt; 0, -ue^{v/u} \leq ew, \text{ or } u = 0, v \geq 0, w \geq 0\}$$

**Applications:**
- **Entropy optimization:** $$\min \sum x_i \log x_i$$
- **Geometric programming:** After log transformation
- **Relative entropy:** KL divergence minimization

**Modeling examples:**

**Entropy:** $$x \log x \leq t \Leftrightarrow (-t, x, 1) \in \mathcal{K}_{\exp}$$ (since $$x e^{-t/x} \leq 1 \Leftrightarrow t \geq x \log x$$)

**Log-sum-exp:** $$\log(\sum e^{x_i}) \leq t \Leftrightarrow$$ a system of exponential cone constraints

**Power cone:** $$x_1^{p_1} \cdots x_k^{p_k} \geq |x_{k+1}|$$ is a separate cone (not an exponential cone); for rational exponents it can be represented by second-order cone constraints

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-9-approximation-algorithms&quot;&gt;📝 &lt;strong&gt;Exercise 9: Approximation algorithms&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Design approximation algorithms for non-convex problems:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Max-cut SDP relaxation:&lt;/strong&gt; Goemans-Williamson algorithm
b) &lt;strong&gt;Facility location:&lt;/strong&gt; LP-based rounding
c) &lt;strong&gt;Set cover:&lt;/strong&gt; Greedy algorithm analysis
d) &lt;strong&gt;Knapsack:&lt;/strong&gt; FPTAS via dynamic programming&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Relaxation formulations&lt;/li&gt;
  &lt;li&gt;Rounding schemes&lt;/li&gt;
  &lt;li&gt;Approximation ratio analysis&lt;/li&gt;
  &lt;li&gt;Performance guarantees&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Max-cut SDP relaxation**

**Original problem:** $$\max_{x \in \{-1,1\}^n} \frac{1}{2}\sum_{(i,j) \in E} w_{ij}(1 - x_i x_j)$$ (each edge counted once; a cut edge gives $$1 - x_i x_j = 2$$)

**Equivalent:** $$\min_{x \in \{-1,1\}^n} \sum_{(i,j) \in E} w_{ij} x_i x_j$$

**SDP relaxation:** $$X = xx^T \Rightarrow X_{ij} = x_i x_j$$
$$\max_X \frac{1}{2}\sum_{(i,j) \in E} w_{ij}(1 - X_{ij})$$
$$\text{s.t.} \quad X_{ii} = 1, \quad X \succeq 0$$

**Goemans-Williamson algorithm:**
1. Solve SDP relaxation → optimal $$X^*$$
2. Cholesky decomposition: $$X^* = V^T V$$
3. Random hyperplane: $$r \sim \mathcal{N}(0, I)$$
4. Rounding: $$x_i = \text{sign}(r^T v_i)$$

**Approximation ratio:** $$\alpha_{GW} = \min_{0 \leq \theta \leq \pi} \frac{2}{\pi} \cdot \frac{\theta}{1 - \cos \theta} \approx 0.878$$

**Step 2: Facility location**

**Problem:** $$\min \sum_{i \in F} f_i y_i + \sum_{i \in F, j \in C} c_{ij} x_{ij}$$
$$\text{s.t.} \quad \sum_{i \in F} x_{ij} = 1, \quad x_{ij} \leq y_i, \quad x_{ij}, y_i \in \{0,1\}$$

**LP relaxation:** $$x_{ij}, y_i \in [0,1]$$

**Rounding algorithm:**
1. Solve LP relaxation
2. Cluster clients and, in each cluster, open one facility chosen with probability proportional to $$x_{ij}^*$$ (opening each facility independently with probability $$y_i^*$$ alone can leave clients unserved)
3. Connect client $$j$$ to the closest open facility
**Analysis:** Clustered randomized rounding (Chudak–Shmoys) gives expected cost $$\leq (1 + 2/e) \times$$ LP optimal $$\approx 1.736 \times$$ LP
**Better guarantees:** The greedy dual-fitting algorithm of Jain–Mahdian–Saberi achieves 1.61; the best known ratio is about 1.488 (Li, 2011)

**Step 3: Set cover greedy**

**Problem:** $$\min \sum_{S \in \mathcal{S}} x_S \quad \text{s.t.} \quad \sum_{S: e \in S} x_S \geq 1, \quad x_S \in \{0,1\}$$

**Greedy algorithm:**
```
While uncovered elements exist:
    Pick set S maximizing |S ∩ (uncovered elements)| / cost(S)
    Add S to solution
```

**Analysis:** $$H_n$$-approximation with $$H_n = \sum_{i=1}^n \frac{1}{i} \approx \ln n$$

**LP-based analysis:**
- Dual fitting method
- Primal-dual algorithm

**Step 4: Knapsack FPTAS**

**Problem:** $$\max \sum_{i=1}^n v_i x_i \quad \text{s.t.} \quad \sum_{i=1}^n w_i x_i \leq W, \quad x_i \in \{0,1\}$$

**Dynamic programming:** $$O(nW)$$ time (pseudo-polynomial)

**FPTAS approach:**
1. Scale profits: $$\tilde{v}_i = \lfloor v_i / K \rfloor$$ with $$K = \epsilon \cdot v_{\max} / n$$
2. DP on scaled instance: $$O(n^3 / \epsilon)$$ time (scaled total profit $$\leq n^2/\epsilon$$)
3. Return solution

**Approximation guarantee:** $$(1 - \epsilon)$$-optimal

**Key insight:** Rounding preserves near-optimality but reduces the state space

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-10-machine-learning-applications&quot;&gt;📝 &lt;strong&gt;Exercise 10: Machine learning applications&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Formulate machine learning problems as convex optimization:&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Logistic regression:&lt;/strong&gt; \(\min_w \sum_{i=1}^n \log(1 + e^{-y_i w^T x_i}) + \lambda \lVert w \rVert_2^2\)&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;b) &lt;strong&gt;Support vector regression:&lt;/strong&gt; $$\min_{w,b} \frac{1}{2}\lVert w \rVert_2^2 + C\sum_{i=1}^n \max(0,&lt;/td&gt;
      &lt;td&gt;y_i - w^T x_i - b&lt;/td&gt;
      &lt;td&gt;- \epsilon)$$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;c) &lt;strong&gt;Matrix completion:&lt;/strong&gt; \(\min_X \lVert X \rVert_* \quad \text{s.t.} \quad X_{ij} = M_{ij}, (i,j) \in \Omega\)&lt;/p&gt;

&lt;p&gt;d) &lt;strong&gt;Sparse coding:&lt;/strong&gt; \(\min_{D,\alpha} \frac{1}{2}\lVert Y - D\alpha \rVert_F^2 + \lambda \lVert \alpha \rVert_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Convexity analysis&lt;/li&gt;
  &lt;li&gt;Optimality conditions&lt;/li&gt;
  &lt;li&gt;Algorithmic approaches&lt;/li&gt;
  &lt;li&gt;Regularization effects&lt;/li&gt;
&lt;/ol&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Detailed solution&lt;/strong&gt;&lt;/summary&gt;

**Step 1: Logistic regression**

**Objective:** $$f(w) = \sum_{i=1}^n \log(1 + e^{-y_i w^T x_i}) + \lambda \lVert w \rVert_2^2$$

**Convexity:** 
- Log-sum-exp convex
- $$\ell_2$$ regularization convex
- Sum preserves convexity

**Gradient:** $$\nabla f(w) = -\sum_{i=1}^n \frac{y_i x_i}{1 + e^{y_i w^T x_i}} + 2\lambda w$$

**Hessian:** $$\nabla^2 f(w) = \sum_{i=1}^n \frac{e^{y_i w^T x_i}}{(1 + e^{y_i w^T x_i})^2} x_i x_i^T + 2\lambda I \succ 0$$

**Algorithms:**
- **Newton method:** Fast convergence
- **BFGS:** Quasi-Newton
- **SGD:** Scalable to large datasets

**Step 2: Support vector regression**

**Reformulation:** $$\min_{w,b,\xi,\xi^*} \frac{1}{2}\lVert w \rVert_2^2 + C\sum_{i=1}^n (\xi_i + \xi_i^*)$$
$$\text{s.t.} \quad y_i - w^T x_i - b \leq \epsilon + \xi_i$$
$$\quad w^T x_i + b - y_i \leq \epsilon + \xi_i^*$$
$$\quad \xi_i, \xi_i^* \geq 0$$

**Dual problem:**
$$\max_{\alpha,\alpha^*} -\frac{1}{2}\sum_{i,j}(\alpha_i - \alpha_i^*)(\alpha_j - \alpha_j^*) x_i^T x_j - \epsilon \sum_i(\alpha_i + \alpha_i^*) + \sum_i y_i(\alpha_i - \alpha_i^*)$$
$$\text{s.t.} \quad \sum_i(\alpha_i - \alpha_i^*) = 0, \quad 0 \leq \alpha_i, \alpha_i^* \leq C$$

**Support vectors:** $$x_i$$ with $$\alpha_i &amp;gt; 0$$ or $$\alpha_i^* &amp;gt; 0$$

**Step 3: Matrix completion**

**Nuclear norm:** $$\lVert X \rVert_* = \sum_{i=1}^{\min(m,n)} \sigma_i(X)$$

**Convexity:** The nuclear norm is convex (spectral function)

**SDP formulation:**
$$\min_{X,U,V} \frac{1}{2}(\text{tr}(U) + \text{tr}(V))$$
$$\text{s.t.} \quad \begin{bmatrix} U &amp;amp; X \\ X^T &amp;amp; V \end{bmatrix} \succeq 0, \quad X_{ij} = M_{ij}$$

**Algorithms:**
- **Proximal gradient:** Soft thresholding of the SVD
- **ADMM:** Alternating direction method
- **Frank-Wolfe:** Conditional gradient

**Step 4: Sparse coding**

**Bi-convex:** Convex in $$D$$ (fixed $$\alpha$$) and convex in $$\alpha$$ (fixed $$D$$)

**Dictionary update:** $$\min_D \frac{1}{2}\lVert Y - D\alpha \rVert_F^2$$ (least squares)

**Sparse coding:** $$\min_\alpha \frac{1}{2}\lVert Y - D\alpha \rVert_F^2 + \lambda \lVert \alpha \rVert_1$$ (LASSO)

**Alternating minimization:**
1. **Sparse coding step:** Solve LASSO for each column
2. **Dictionary update:** Least squares with normalization
3. Repeat until convergence

**LASSO solution:** Soft thresholding
$$\alpha_j^{(k+1)} = \text{soft}(\alpha_j^{(k)} - \eta \nabla_j f, \eta \lambda)$$

with $$\text{soft}(x, \tau) = \text{sign}(x) \max(|x| - \tau, 0)$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-practical-tips&quot;&gt;💡 Practical Tips&lt;/h2&gt;

&lt;h4 id=&quot;when-formulating-optimization-problems&quot;&gt;&lt;strong&gt;When formulating optimization problems:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Identify structure:&lt;/strong&gt; LP, QP, SOCP, SDP, GP&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check convexity:&lt;/strong&gt; Objective and constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Standard forms:&lt;/strong&gt; Transform to use efficient solvers&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;when-analyzing-optimality&quot;&gt;&lt;strong&gt;When analyzing optimality:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;KKT conditions:&lt;/strong&gt; Necessary and sufficient conditions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complementary slackness:&lt;/strong&gt; Active constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity analysis:&lt;/strong&gt; Shadow prices and perturbations&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;when-designing-algorithms&quot;&gt;&lt;strong&gt;When designing algorithms:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Exploit structure:&lt;/strong&gt; Sparsity, separability, decomposition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Approximation:&lt;/strong&gt; When exact solution intractable&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robustness:&lt;/strong&gt; Handle uncertainty and noise&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;h3 id=&quot;convex-optimization-standard-form&quot;&gt;&lt;strong&gt;Convex Optimization Standard Form:&lt;/strong&gt;&lt;/h3&gt;

\[\begin{align}
\min_{x} \quad &amp;amp; f_0(x) \\
\text{s.t.} \quad &amp;amp; f_i(x) \leq 0, \quad i = 1, \ldots, m \\
&amp;amp; h_i(x) = 0, \quad i = 1, \ldots, p
\end{align}\]

&lt;p&gt;with \(f_0, \ldots, f_m\) convex, \(h_i\) affine.&lt;/p&gt;

&lt;h3 id=&quot;optimality-conditions&quot;&gt;&lt;strong&gt;Optimality Conditions:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Condition&lt;/th&gt;
      &lt;th&gt;Formula&lt;/th&gt;
      &lt;th&gt;When sufficient&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Unconstrained&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\nabla f(x^*) = 0\)&lt;/td&gt;
      &lt;td&gt;\(f\) differentiable&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Equality constraints&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\nabla f(x^*) + \sum \nu_i^* \nabla h_i(x^*) = 0\)&lt;/td&gt;
      &lt;td&gt;Affine \(h_i\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;KKT (general)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Stationarity, primal/dual feasibility, complementary slackness&lt;/td&gt;
      &lt;td&gt;Slater’s condition&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Convex&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Local optimum = Global optimum&lt;/td&gt;
      &lt;td&gt;Convexity&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;duality&quot;&gt;&lt;strong&gt;Duality:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Concept&lt;/th&gt;
      &lt;th&gt;Definition&lt;/th&gt;
      &lt;th&gt;Meaning&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Lagrangian&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(L(x, \lambda, \nu) = f_0(x) + \sum \lambda_i f_i(x) + \sum \nu_i h_i(x)\)&lt;/td&gt;
      &lt;td&gt;Augmented objective&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dual function&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(g(\lambda, \nu) = \inf_x L(x, \lambda, \nu)\)&lt;/td&gt;
      &lt;td&gt;Lower bound&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dual problem&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\max g(\lambda, \nu)\) s.t. \(\lambda \geq 0\)&lt;/td&gt;
      &lt;td&gt;Best lower bound&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Weak duality&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(d^* \leq p^*\)&lt;/td&gt;
      &lt;td&gt;Always holds&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Strong duality&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(d^* = p^*\)&lt;/td&gt;
      &lt;td&gt;Slater → zero gap&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Complementary slackness&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\lambda_i^* f_i(x^*) = 0\)&lt;/td&gt;
      &lt;td&gt;Active constraints&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;quasiconvex-optimization&quot;&gt;&lt;strong&gt;Quasiconvex Optimization:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Definition:&lt;/strong&gt; \(f\) is quasiconvex if its sublevel sets \(\{x : f(x) \leq \alpha\}\) are convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Not closed under addition:&lt;/strong&gt; \(f_1 + f_2\) is not necessarily quasiconvex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fractional programming:&lt;/strong&gt; \(\min \frac{f(x)}{g(x)}\) can be solved by bisection&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;vector-optimization&quot;&gt;&lt;strong&gt;Vector Optimization:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pareto optimal:&lt;/strong&gt; There is no other \(y\) such that \(f(y) \preceq_{K} f(x)\) and \(f(y) \neq f(x)\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scalarization:&lt;/strong&gt; \(\min \lambda^T f(x)\) with \(\lambda \succ_{K^*} 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\epsilon\)-constraint method:&lt;/strong&gt; Fix \(m-1\) objectives, optimize 1&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;stochastic--robust-optimization&quot;&gt;&lt;strong&gt;Stochastic &amp;amp; Robust Optimization:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Formulation&lt;/th&gt;
      &lt;th&gt;Trade-off&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Expected value&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\min \mathbb{E}[f(x, \xi)]\)&lt;/td&gt;
      &lt;td&gt;Average performance&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Worst-case&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\min \max_{\xi \in \mathcal{U}} f(x, \xi)\)&lt;/td&gt;
      &lt;td&gt;Conservative&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Chance constraint&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\mathbb{P}[f(x, \xi) \leq 0] \geq 1 - \epsilon\)&lt;/td&gt;
      &lt;td&gt;Probabilistic guarantee&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Sample average&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\min \frac{1}{N}\sum f(x, \xi_i)\)&lt;/td&gt;
      &lt;td&gt;Tractable approximation&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;relaxation-techniques&quot;&gt;&lt;strong&gt;Relaxation Techniques:&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LP relaxation:&lt;/strong&gt; \(x \in \{0,1\}^n \to x \in [0,1]^n\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SDP relaxation:&lt;/strong&gt; \(xx^T \to X \succeq 0\), \(X_{ii} = 1\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lagrangian relaxation:&lt;/strong&gt; Dualize hard constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Randomized rounding:&lt;/strong&gt; Convert fractional solution to integer&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 References&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Boyd, S., &amp;amp; Vandenberghe, L.&lt;/strong&gt; (2004). &lt;em&gt;Convex Optimization&lt;/em&gt;. Cambridge University Press.
    &lt;ul&gt;
      &lt;li&gt;Chapter 4: Convex Optimization Problems&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Ben-Tal, A., &amp;amp; Nemirovski, A.&lt;/strong&gt; (2001). &lt;em&gt;Lectures on Modern Convex Optimization&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bertsekas, D. P.&lt;/strong&gt; (1999). &lt;em&gt;Nonlinear Programming&lt;/em&gt;. Athena Scientific.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Shapiro, A., Dentcheva, D., &amp;amp; Ruszczyński, A.&lt;/strong&gt; (2009). &lt;em&gt;Lectures on Stochastic Programming&lt;/em&gt;. SIAM.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Williamson, D. P., &amp;amp; Shmoys, D. B.&lt;/strong&gt; (2011). &lt;em&gt;The Design of Approximation Algorithms&lt;/em&gt;. Cambridge University Press.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>04-10 Multiple-Choice Quiz - Convex Optimization Basics</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_10_Quiz_Convex_Optimization_Basics/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_10_Quiz_Convex_Optimization_Basics</id>
   <content type="html">&lt;p&gt;Reading a theorem and nodding along feels effortless; spotting a subtle non-affine equality constraint or a hidden violation of convexity under exam pressure is where real mastery shows up. This quiz checkpoints your command of Chapter 04’s entire toolkit—from recognizing standard-form convex programs and testing first-order optimality to executing variable transformations, slack reformulations, and convex relaxations.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-what-this-chapter-04-assessment-tests&quot;&gt;Key ideas: What This Chapter 04 Assessment Tests&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Formulation &amp;amp; Convexity Diagnostics&lt;/strong&gt;: Quickly verifying whether an objective \(f\) and inequality constraints \(g_i\) are convex and whether all equality constraints \(h_j\) are strictly affine, as well as distinguishing implicit domains \(D\) from feasible sets \(C\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solution-Set Geometry &amp;amp; Uniqueness&lt;/strong&gt;: Predicting when \(X_{\mathrm{opt}}\) is empty, a single point (strict convexity), or a convex face with infinitely many solutions, and applying the local-implies-global theorem.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Optimality Verification&lt;/strong&gt;: Checking \(\nabla f(x^\star)^T (y - x^\star) \ge 0\) across unconstrained spaces, affine subspaces, and nonnegative orthants without getting tripped up by boundary constraints.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equivalent Rewrites &amp;amp; Relaxations&lt;/strong&gt;: Identifying which transformations (monotone maps, bijections, partial minimization, affine slacks) preserve exact optimality and which widen the feasible set to provide a lower bound.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-warm-up-diagnostic-before-starting-the-quiz&quot;&gt;Worked example: Warm-Up Diagnostic Before Starting the Quiz&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Warm-Up Question&lt;/strong&gt;: Is the following problem a convex optimization problem in standard form? If not, can it be equivalently rewritten as one?
\(\min_{x \in \mathbb{R}^2} \quad e^{x_1^2 + x_2^2} \quad \text{subject to} \quad x_1^2 + x_2^2 \le 4, \quad x_1 x_2 = 1.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check the objective&lt;/strong&gt;: \(q(x) = x_1^2 + x_2^2\) is convex, and \(h(u) = e^u\) is convex and nondecreasing, so \(f(x) = e^{x_1^2 + x_2^2}\) is convex. (Even simpler, applying \(\ln(\cdot)\) gives the equivalent objective \(x_1^2 + x_2^2\).)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the inequality constraint&lt;/strong&gt;: \(g_1(x) = x_1^2 + x_2^2 - 4\) has Hessian \(2I \succeq 0\), so \(g_1\) is convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the equality constraint&lt;/strong&gt;: \(h_1(x) = x_1 x_2 - 1 = 0\) is &lt;strong&gt;not affine&lt;/strong&gt;! Test two feasible points: \(x = (1, 1)\) and \(y = (-1, -1)\) both satisfy \(x_1 x_2 = 1\) and \(x_1^2 + x_2^2 = 2 \le 4\), yet their midpoint \((0, 0)\) has \(0 \cdot 0 = 0 \neq 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;: The problem is &lt;strong&gt;not&lt;/strong&gt; convex in standard form, and because the feasible set is disconnected (two branches of a hyperbola inside a disk), no smooth bijection on \(\mathbb{R}^2\) can make the full feasible set convex—though restricting to \(x_1, x_2 &amp;gt; 0\) and substituting \(x_i = e^{z_i}\) makes the positive branch convex (\(z_1 + z_2 = 0\), \(e^{2z_1} + e^{2z_2} \le 4\)). Keep an eye out for exactly these structural traps in the questions below!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the basic concepts of convex optimization, including terminology, optimality conditions and transformation techniques.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-the-convex-optimization-problem&quot;&gt;🎯 &lt;strong&gt;The Convex Optimization Problem&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Standard form:&lt;/strong&gt;
\(\begin{aligned}
&amp;amp;\min_{x \in D} &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;g_i(x) \le 0, \quad i = 1, \ldots, m \\
&amp;amp;&amp;amp;&amp;amp;h_j(x) = 0, \quad j = 1, \ldots, r
\end{aligned}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convexity conditions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(f, g_i\) are convex functions&lt;/li&gt;
  &lt;li&gt;\(h_j\) are affine functions: \(h_j(x) = a_j^T x + b_j\)&lt;/li&gt;
  &lt;li&gt;
\[D = \text{dom}(f) \cap \bigcap_{i=1}^m \text{dom}(g_i) \cap \bigcap_{j=1}^r \text{dom}(h_j)\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-basic-terminology&quot;&gt;📝 &lt;strong&gt;Basic Terminology&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Key concepts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Objective function:&lt;/strong&gt; \(f(x)\) - the function to minimize&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inequality constraints:&lt;/strong&gt; \(g_i(x) \le 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equality constraints:&lt;/strong&gt; \(h_j(x) = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Feasible point:&lt;/strong&gt; \(x\) satisfying all the constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal value:&lt;/strong&gt; \(f^* = \min\{f(x) \mid x \text{ feasible}\}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal solution:&lt;/strong&gt; \(x^*\) feasible with \(f(x^*) = f^*\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\epsilon\)-suboptimal:&lt;/strong&gt; \(x\) feasible with \(f(x) \le f^* + \epsilon\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Active constraint:&lt;/strong&gt; \(g_i(x^*) = 0\) at the optimal solution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Feasible set:&lt;/strong&gt;
\(S = \{x \in D \mid g_i(x) \le 0, h_j(x) = 0\}\)&lt;/p&gt;

&lt;h3 id=&quot;-properties-of-the-solution-set&quot;&gt;🔵 &lt;strong&gt;Properties of the Solution Set&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Property 1:&lt;/strong&gt; The solution set \(X_{\text{opt}}\) of a convex problem is convex&lt;/p&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt; If \(x, y \in X_{\text{opt}}\) and \(0 \le \theta \le 1\):&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;\(\theta x + (1-\theta)y\) is feasible (by convexity of the feasible set)&lt;/li&gt;
    &lt;li&gt;
\[f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y) = f^*\]
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Property 2:&lt;/strong&gt; If \(f\) is strictly convex then the solution (if it exists) is unique&lt;/p&gt;

&lt;h3 id=&quot;-optimality-conditions&quot;&gt;✅ &lt;strong&gt;Optimality Conditions&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;First-order condition (differentiable functions):&lt;/strong&gt;
For the problem \(\min_x f(x)\) s.t. \(x \in C\):
\(\nabla f(x^*)^T (y - x^*) \ge 0 \quad \forall y \in C\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unconstrained case:&lt;/strong&gt; \(C = \mathbb{R}^n\)
\(\nabla f(x^*) = 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second-order conditions (twice-differentiable functions):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Necessary condition:&lt;/strong&gt; \(\nabla f(x^*) = 0\) and \(\nabla^2 f(x^*) \succeq 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sufficient condition:&lt;/strong&gt; \(\nabla f(x^*) = 0\) and \(\nabla^2 f(x^*) \succ 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Meaning of the Hessian:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\nabla^2 f(x^*) \succ 0\): strict local minimum&lt;/li&gt;
  &lt;li&gt;\(\nabla^2 f(x^*) \prec 0\): strict local maximum&lt;/li&gt;
  &lt;li&gt;\(\nabla^2 f(x^*)\) indefinite: saddle point&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-slack-variables&quot;&gt;🔄 &lt;strong&gt;Slack Variables&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; Turn inequality constraints into equalities&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transformation:&lt;/strong&gt;
\(g_i(x) \le 0 \quad \Rightarrow \quad g_i(x) + s_i = 0, \quad s_i \ge 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Original problem:&lt;/strong&gt;
\(\begin{aligned}
&amp;amp;\min_x &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;g_i(x) \le 0
\end{aligned}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With slack variables:&lt;/strong&gt;
\(\begin{aligned}
&amp;amp;\min_{x,s} &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{s.t.} &amp;amp;&amp;amp;g_i(x) + s_i = 0 \\
&amp;amp;&amp;amp;&amp;amp;s_i \ge 0
\end{aligned}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meaning:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(s_i &amp;gt; 0\): constraint \(i\) is inactive&lt;/li&gt;
  &lt;li&gt;\(s_i = 0\): constraint \(i\) is active (tight)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Convexity is preserved only when \(g_i(x)\) is affine&lt;/p&gt;

&lt;h3 id=&quot;-relaxation&quot;&gt;🔧 &lt;strong&gt;Relaxation&lt;/strong&gt;&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt; Replace the feasible set \(C\) with a superset \(\tilde{C} \supseteq C\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Original problem:&lt;/strong&gt; \(\min_x f(x)\) s.t. \(x \in C\)
&lt;strong&gt;Relaxed problem:&lt;/strong&gt; \(\min_x f(x)\) s.t. \(x \in \tilde{C}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; Optimal value of the relaxed problem \(\le\) original optimal value&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important example:&lt;/strong&gt; Relaxing equality constraints
\(h_j(x) = 0 \quad \Rightarrow \quad h_j(x) \le 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Application:&lt;/strong&gt; Turn a non-convex problem into a convex one (when \(h_j\) is convex but not affine)&lt;/p&gt;

&lt;h3 id=&quot;-other-transformation-techniques&quot;&gt;🎲 &lt;strong&gt;Other Transformation Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Eliminating equality constraints:&lt;/strong&gt;
If \(Ax = b\) is solvable, we can parametrize:
\(x = x_0 + Fz\) with \(Ax_0 = b\) and \(\text{range}(F) = \text{null}(A)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Change of variables:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Change variables to simplify the problem&lt;/li&gt;
  &lt;li&gt;Convexity is preserved under affine transformations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Decomposition:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Split a large problem into smaller subproblems&lt;/li&gt;
  &lt;li&gt;Exploit the special structure of the problem&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-comparison-of-techniques&quot;&gt;📊 &lt;strong&gt;Comparison of Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Technique&lt;/th&gt;
      &lt;th&gt;Purpose&lt;/th&gt;
      &lt;th&gt;Advantages&lt;/th&gt;
      &lt;th&gt;Disadvantages&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Slack variables&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Inequality → equality&lt;/td&gt;
      &lt;td&gt;Simplifies algorithms&lt;/td&gt;
      &lt;td&gt;More variables&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Relaxation&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Enlarge the feasible set&lt;/td&gt;
      &lt;td&gt;Non-convex → convex&lt;/td&gt;
      &lt;td&gt;The solution may be inexact&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Eliminating constraints&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Fewer constraints&lt;/td&gt;
      &lt;td&gt;Lower problem dimension&lt;/td&gt;
      &lt;td&gt;Requires special analysis&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;-recognizing-convex-problems&quot;&gt;🔍 &lt;strong&gt;Recognizing Convex Problems&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Checklist:&lt;/strong&gt;&lt;/p&gt;
&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Is the objective \(f\) convex?&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Are the inequality constraints \(g_i\) convex?&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Are the equality constraints \(h_j\) affine?&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Is the domain \(D\) convex?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;If all ✓ → Convex optimization problem&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; In convex optimization every local minimum is a global minimum. This makes solving problems reliable and efficient!&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;Multiple-Choice Quiz: Convex Optimization Basics&lt;/h2&gt;
        &lt;p&gt;Choose the best answer for each question. The quiz focuses on basic and practical concepts of convex optimization.&lt;/p&gt;
        &lt;div id=&quot;progress-bar&quot;&gt;
            &lt;div id=&quot;progress-fill&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;p id=&quot;progress-text&quot;&gt;Question 1/25&lt;/p&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-questions&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot;&gt;
            &lt;h3&gt;Question 1: In a convex optimization problem, the equality constraint functions $$h_j(x) = 0$$ must be:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) Convex functions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) Concave functions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) Affine functions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) Arbitrary functions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) Affine function&lt;/strong&gt;&lt;br /&gt;
                In a convex optimization problem, the equality constraint functions $$h_j(x) = 0$$ must be affine to guarantee that the feasible set is convex.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: A point $$x$$ is called feasible if:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) $$x \in D$$ and $$g_i(x) \leq 0$$ for all $$i$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) $$x \in D$$, $$g_i(x) \leq 0$$ for all $$i$$, and $$h_j(x) = 0$$ for all $$j$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) Only $$f(x)$$ needs to be defined&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) $$x$$ is an optimal solution&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$x \in D$$, $$g_i(x) \leq 0$$ for all $$i$$, and $$h_j(x) = 0$$ for all $$j$$&lt;/strong&gt;&lt;br /&gt;
                A feasible point must satisfy all the conditions: it lies in the domain and satisfies all the constraints.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: A constraint $$g_i(x) \leq 0$$ is called &quot;active&quot; at $$x$$ when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) $$g_i(x) &amp;lt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) $$g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) $$g_i(x) &amp;gt; 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) $$g_i(x) \leq -1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$g_i(x) = 0$$&lt;/strong&gt;&lt;br /&gt;
                An active constraint is satisfied with equality, i.e. $$g_i(x) = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: A point $$x$$ is called $$\epsilon$$-suboptimal if:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) $$f(x) = f^* + \epsilon$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) $$f(x) \leq f^* + \epsilon$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) $$f(x) \geq f^* - \epsilon$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) $$|f(x) - f^*| \leq \epsilon$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$f(x) \leq f^* + \epsilon$$&lt;/strong&gt;&lt;br /&gt;
                An $$\epsilon$$-suboptimal point has an objective value no larger than the optimal value plus $$\epsilon$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: The solution set $$X_{opt}$$ of a convex optimization problem:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) Is always convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) May be non-convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) Always contains exactly one point&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) Is always empty&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Is always convex&lt;/strong&gt;&lt;br /&gt;
                The solution set of a convex optimization problem is always convex; this is an important property.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: A convex optimization problem has a unique solution when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) The objective $$f$$ is convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) The objective $$f$$ is strictly convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) The feasible set is bounded&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) There are equality constraints&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The objective $$f$$ is strictly convex&lt;/strong&gt;&lt;br /&gt;
                When the objective is strictly convex, the optimal solution (if it exists) is unique because the graph has no flat segments.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: For the problem $$\min_x f(x)$$ s.t. $$x \in C$$, the first-order optimality condition is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) $$\nabla f(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) $$\nabla f(x)^T(y-x) \geq 0$$ for all $$y \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) $$\nabla f(x)^T(y-x) \leq 0$$ for all $$y \in C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) $$f(x) \leq f(y)$$ for all $$y \in C$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\nabla f(x)^T(y-x) \geq 0$$ for all $$y \in C$$&lt;/strong&gt;&lt;br /&gt;
                The first-order optimality condition requires that no feasible direction is a descent direction: $$-\nabla f(x)$$ must not point into the feasible set.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: For the unconstrained problem $$\min_x f(x)$$ ($$C = \mathbb{R}^n$$), the optimality condition is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) $$\nabla f(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) $$\nabla^2 f(x) \succ 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) $$f(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) $$x = 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\nabla f(x) = 0$$&lt;/strong&gt;&lt;br /&gt;
                For an unconstrained problem, the first-order optimality condition becomes $$\nabla f(x) = 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The Hessian matrix $$\nabla^2 f(x)$$ gives information about:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) The slope of the function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) The curvature of the function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) The value of the function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) The domain of the function&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The curvature of the function&lt;/strong&gt;&lt;br /&gt;
                The Hessian contains the second derivatives and gives information about the curvature of the function at a point.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: A sufficient condition for a strict local minimum is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) $$\nabla f(x) = 0$$ and $$\nabla^2 f(x) \succeq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) $$\nabla f(x) = 0$$ and $$\nabla^2 f(x) \succ 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) Only $$\nabla f(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) $$\nabla^2 f(x) \prec 0$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\nabla f(x) = 0$$ and $$\nabla^2 f(x) \succ 0$$&lt;/strong&gt;&lt;br /&gt;
                The sufficient condition for a strict local minimum requires a zero gradient and a positive definite Hessian.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: Slack variables $$s_i$$ are introduced in order to:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Turn inequality constraints into equalities&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Turn equality constraints into inequalities&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Increase the number of variables&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Reduce the computational complexity&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Turn inequality constraints into equalities&lt;/strong&gt;&lt;br /&gt;
                Slack variables are used to transform $$g_i(x) \leq 0$$ into $$g_i(x) + s_i = 0$$ with $$s_i \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: When $$s_i &amp;gt; 0$$ at the optimal solution, this means:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) The constraint $$g_i(x) \leq 0$$ is active&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) The constraint $$g_i(x) \leq 0$$ is inactive&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) The problem is infeasible&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) The solution is not optimal&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) The constraint $$g_i(x) \leq 0$$ is inactive&lt;/strong&gt;&lt;br /&gt;
                When $$s_i &amp;gt; 0$$, we have $$g_i(x) = -s_i &amp;lt; 0$$, so the constraint is inactive (there is &quot;slack&quot;).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: The slack-variable transformation preserves convexity when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) $$g_i(x)$$ is any convex function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) $$g_i(x)$$ is an affine function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) $$g_i(x)$$ is a concave function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) It always preserves convexity&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$g_i(x)$$ is an affine function&lt;/strong&gt;&lt;br /&gt;
                The slack-variable transformation preserves convexity only when $$g_i(x)$$ is affine. For nonlinear functions it can destroy convexity.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: Relaxation changes the set $$C$$ into $$\tilde{C}$$ such that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) $$\tilde{C} \subseteq C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) $$\tilde{C} \supseteq C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) $$\tilde{C} = C$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) $$\tilde{C} \cap C = \emptyset$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\tilde{C} \supseteq C$$&lt;/strong&gt;&lt;br /&gt;
                Relaxation enlarges the feasible set, i.e. $$\tilde{C}$$ contains $$C$$ as a subset.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: After relaxation, the optimal value $$\tilde{f}^*$$ compared with the original value $$f^*$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) $$\tilde{f}^* \geq f^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) $$\tilde{f}^* \leq f^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) $$\tilde{f}^* = f^*$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) There is no fixed relationship&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\tilde{f}^* \leq f^*$$&lt;/strong&gt;&lt;br /&gt;
                Since we optimize over a larger set, the relaxed optimal value cannot be larger than the original one.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: Relaxing the equality constraint $$h_j(x) = 0$$ gives:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) $$h_j(x) \geq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) $$h_j(x) \leq 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) $$|h_j(x)| \leq \epsilon$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) Remove the constraint&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$h_j(x) \leq 0$$&lt;/strong&gt;&lt;br /&gt;
                When $$h_j(x)$$ is convex but not affine, $$h_j(x) = 0$$ can be relaxed to $$h_j(x) \leq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: The feasible set of a convex optimization problem:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Is always convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) May be non-convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Is always bounded&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Is always nonempty&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Is always convex&lt;/strong&gt;&lt;br /&gt;
                In a convex optimization problem, the feasible set is always convex because the constraints are convex and affine.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: In linear programming, a bounded feasible set is called:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Polyhedron&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Polytope&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Simplex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Ellipsoid&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Polytope&lt;/strong&gt;&lt;br /&gt;
                A polytope is a bounded feasible set in linear programming, whereas a polyhedron may be unbounded.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: In linear programming, if an optimal solution exists, it can be found at:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) Any point of the feasible set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) The center of the feasible set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) One of the vertices of the feasible set&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) The boundary of the feasible set&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: C) One of the vertices of the feasible set&lt;/strong&gt;&lt;br /&gt;
                This is the basis of the Simplex algorithm: an optimal solution of an LP can always be found at a vertex.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: The main advantage of convex optimization problems is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) They always have a unique solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) Every local minimum is a global minimum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) They are faster to compute&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) No optimality conditions are needed&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Every local minimum is a global minimum&lt;/strong&gt;&lt;br /&gt;
                This is the most important property of convex optimization; it guarantees we do not get &quot;stuck&quot; at a local minimum.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: In a convex optimization problem, the KKT conditions are:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) Sufficient for optimality, and also necessary when Slater&apos;s condition holds&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) Only necessary&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) Only sufficient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) Irrelevant&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Sufficient for optimality, and also necessary when Slater&apos;s condition holds&lt;/strong&gt;&lt;br /&gt;
                For a convex optimization problem, the KKT conditions are always sufficient for global optimality; they are also necessary under a constraint qualification such as Slater&apos;s condition (then strong duality holds). Without Slater, an optimal solution may fail to satisfy KKT (e.g. $$\min x$$ subject to $$x^2 \leq 0$$).
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: The solution of the problem $$\min x^2 + y^2$$ subject to $$x + y \geq 1$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) $$x = 0.5, y = 0.5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) $$x = 1, y = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) $$x = 0, y = 1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) No solution&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$x = 0.5, y = 0.5$$&lt;/strong&gt;&lt;br /&gt;
                Using the Lagrange method with the active constraint $$x + y = 1$$, we get $$x = y = 0.5$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: The Lagrangian of the problem $$\min f(x)$$ subject to $$g(x) \leq 0$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) $$L(x,\lambda) = f(x) + \lambda g(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) $$L(x,\lambda) = f(x) - \lambda g(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) $$L(x,\lambda) = f(x) + \lambda^2 g(x)$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) $$L(x,\lambda) = f(x) \cdot \lambda g(x)$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$L(x,\lambda) = f(x) + \lambda g(x)$$&lt;/strong&gt;&lt;br /&gt;
                The standard Lagrangian has the form $$L(x,\lambda) = f(x) + \lambda g(x)$$ with $$\lambda \geq 0$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The complementary slackness condition in KKT is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$\lambda_i g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$\lambda_i + g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$\lambda_i - g_i(x) = 0$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) $$\lambda_i \cdot g_i(x) = 1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\lambda_i g_i(x) = 0$$&lt;/strong&gt;&lt;br /&gt;
                Complementary slackness $$\lambda_i g_i(x) = 0$$ ensures that either the constraint is inactive or the Lagrange multiplier is zero.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: In the QP $$\min \frac{1}{2}x^T P x + q^T x$$, the matrix $$P$$ must be:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) Positive semidefinite&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) Positive definite&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) Symmetric&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) Both A and C&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) Both A and C&lt;/strong&gt;&lt;br /&gt;
                For the QP to be convex, the matrix $$P$$ must be positive semidefinite and symmetric.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div id=&quot;quiz-navigation&quot;&gt;
        &lt;button id=&quot;prev-btn&quot; onclick=&quot;previousQuestion()&quot; disabled=&quot;&quot;&gt;Previous&lt;/button&gt;
        &lt;button id=&quot;next-btn&quot; onclick=&quot;nextQuestion()&quot;&gt;Next&lt;/button&gt;
        &lt;button id=&quot;submit-btn&quot; onclick=&quot;submitQuiz()&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-results&quot; style=&quot;display: none;&quot;&gt;
        &lt;h3&gt;Exercise Results&lt;/h3&gt;
        &lt;div id=&quot;score-display&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;detailed-results&quot;&gt;&lt;/div&gt;
        &lt;button onclick=&quot;restartQuiz()&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

#quiz-header {
    text-align: center;
    margin-bottom: 30px;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #E91E63, #9C27B0);
    width: 5%;
    transition: width 0.3s ease;
}

.question {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.question h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.4;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options label {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    line-height: 1.4;
}

.options label:hover {
    border-color: #E91E63;
    background-color: #fce4ec;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
    flex-shrink: 0;
}

.options label.selected {
    border-color: #E91E63;
    background-color: #f8bbd9;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #fce4ec;
    border-left: 4px solid #E91E63;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
}

.explanation strong {
    color: #AD1457;
}

#quiz-navigation {
    text-align: center;
    margin: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#quiz-navigation button {
    background: #E91E63;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#quiz-navigation button:hover:not(:disabled) {
    background: #C2185B;
}

#quiz-navigation button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#quiz-results {
    text-align: center;
    padding: 30px;
    background: #fce4ec;
    border-radius: 8px;
    border: 2px solid #E91E63;
}

#score-display {
    font-size: 1.5em;
    font-weight: bold;
    margin: 20px 0;
    color: #AD1457;
}

#detailed-results {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.result-item {
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.result-item.correct {
    background-color: #e8f5e8;
    border-left-color: #4CAF50;
}

.result-item.incorrect {
    background-color: #ffebee;
    border-left-color: #f44336;
}

@media (max-width: 600px) {
    #quiz-container {
        padding: 10px;
    }
    
    .question {
        padding: 15px;
    }
    
    #quiz-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    #quiz-navigation button {
        width: 100%;
    }
}
&lt;/style&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answer for each question
const correctAnswers = {
    q1: &apos;c&apos;, q2: &apos;b&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;a&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;a&apos;, q9: &apos;b&apos;, q10: &apos;b&apos;,
    q11: &apos;a&apos;, q12: &apos;b&apos;, q13: &apos;b&apos;, q14: &apos;b&apos;, q15: &apos;b&apos;,
    q16: &apos;b&apos;, q17: &apos;a&apos;, q18: &apos;b&apos;, q19: &apos;c&apos;, q20: &apos;b&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;d&apos;};

/**
 * Update the progress bar and show the current question
 */
function updateProgress() {
    const progressFill = document.getElementById(&apos;progress-fill&apos;);
    const progressText = document.getElementById(&apos;progress-text&apos;);
    
    const percentage = (currentQuestion / totalQuestions) * 100;
    progressFill.style.width = percentage + &apos;%&apos;;
    progressText.textContent = `Question ${currentQuestion}/${totalQuestions}`;
}

/**
 * Show a question by its number
 */
function showQuestion(questionNum) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${questionNum}`).style.display = &apos;block&apos;;
    
    // Update the state of the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (questionNum === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (questionNum === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    updateProgress();
}

/**
 * Go to the next question
 */
function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        currentQuestion++;
        showQuestion(currentQuestion);
    }
}

/**
 * Go back to the previous question
 */
function previousQuestion() {
    if (currentQuestion &gt; 1) {
        currentQuestion--;
        showQuestion(currentQuestion);
    }
}

/**
 * Store the user&apos;s answer
 */
function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Update the UI to show the selected answer
    const labels = document.querySelectorAll(`#${questionId} .options label`);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        if (label.querySelector(&apos;input&apos;).value === answer) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

/**
 * Submit and show the results
 */
function submitQuiz() {
    if (quizSubmitted) return;
    
    quizSubmitted = true;
    let correctCount = 0;
    let detailedResults = &apos;&apos;;
    
    // Compute the score and build the detailed report
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const questionId = `q${i}`;
        const userAnswer = userAnswers[questionId];
        const correctAnswer = correctAnswers[questionId];
        const isCorrect = userAnswer === correctAnswer;
        
        if (isCorrect) correctCount++;
        
        // Show explanations for all questions
        const explanation = document.querySelector(`#${questionId} .explanation`);
        if (explanation) {
            explanation.style.display = &apos;block&apos;;
        }
        
        // Build the detailed report
        detailedResults += `
            &lt;div class=&quot;result-item ${isCorrect ? &apos;correct&apos; : &apos;incorrect&apos;}&quot;&gt;
                &lt;strong&gt;Question ${i}:&lt;/strong&gt; ${isCorrect ? &apos;Correct&apos; : &apos;Incorrect&apos;}
                ${!isCorrect ? `&lt;br&gt;&lt;small&gt;Your answer: ${userAnswer || &apos;Not answered&apos;} | Correct answer: ${correctAnswer}&lt;/small&gt;` : &apos;&apos;}
            &lt;/div&gt;
        `;
    }
    
    // Show the results
    const scorePercentage = Math.round((correctCount / totalQuestions) * 100);
    document.getElementById(&apos;score-display&apos;).innerHTML = `
        &lt;div&gt;Score: ${correctCount}/${totalQuestions} (${scorePercentage}%)&lt;/div&gt;
        &lt;div style=&quot;margin-top: 10px; font-size: 0.9em;&quot;&gt;
            ${scorePercentage &gt;= 80 ? &apos;🎉 Excellent! You have mastered the basics of convex optimization!&apos; :
              scorePercentage &gt;= 60 ? &apos;👍 Pretty good! Review a few basic concepts.&apos; :
              scorePercentage &gt;= 40 ? &apos;📚 You need more review of terminology and optimality conditions.&apos; : &apos;💪 Reread the basic theory of convex optimization!&apos;}
        &lt;/div&gt;
    `;
    
    document.getElementById(&apos;detailed-results&apos;).innerHTML = detailedResults;
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;none&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;quiz-results&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

/**
 * Restart the exercise
 */
function restartQuiz() {
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide the results and show the navigation again
    document.getElementById(&apos;quiz-results&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;quiz-navigation&apos;).style.display = &apos;flex&apos;;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Clear all selections
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>04-08 Relaxation</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_08_Relaxation/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_08_Relaxation</id>
   <content type="html">&lt;p&gt;When a door is locked by a hard nonconvex constraint—like requiring variables to be binary \(\{0, 1\}\) or a matrix to have rank 1—exact optimization can take exponential time. &lt;em&gt;Relaxation&lt;/em&gt; is the art of widening the feasible set \(C\) to a larger, friendlier convex set \(\tilde{C} \supseteq C\) so that a solver can compute a guaranteed lower bound in polynomial time—and sometimes, remarkably, the relaxed solution lands right back inside \(C\) and solves the hard problem exactly!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-how-convex-relaxation-bridges-hard-and-tractable-problems&quot;&gt;Key ideas: How Convex Relaxation Bridges Hard and Tractable Problems&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Guaranteed Lower Bounds (for Minimization)&lt;/strong&gt;: Because \(\tilde{C} \supseteq C\) gives the optimizer strictly more choices, the relaxed optimal value always satisfies \(\tilde{f}^\star \le f^\star\). This bound is priceless: if a heuristic gives a feasible solution \(x_{\mathrm{heur}} \in C\), the gap \(f(x_{\mathrm{heur}}) - \tilde{f}^\star\) certifies how close you are to global optimality.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Exactness Certificate&lt;/strong&gt;: If the minimizer \(\tilde{x}^\star\) of the relaxed problem happens to satisfy the dropped constraints (\(\tilde{x}^\star \in C\)), then \(\tilde{f}^\star = f(\tilde{x}^\star) \ge f^\star \ge \tilde{f}^\star\), proving \(\tilde{x}^\star\) is an &lt;em&gt;exact global minimizer&lt;/em&gt; of the original hard problem.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Relaxing Non-Affine Equalities to Inequalities&lt;/strong&gt;: A non-affine equality \(g(x) = 0\) (where \(g\) is convex) makes a problem nonconvex because \(g(x) \ge 0\) is generally nonconvex. Relaxing \(g(x) = 0\) to \(g(x) \le 0\) restores convexity—for instance, relaxing the unit sphere \(\|x\|_2 = 1\) to the unit ball \(\|x\|_2 \le 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tightness vs. Tractability Trade-Off&lt;/strong&gt;: Replacing a discrete set \(\{0, 1\}^n\) with its convex hull \([0, 1]^n\) (LP relaxation) or replacing \(\operatorname{rank}(X) = 1\) with \(X \succeq 0\) (SDP relaxation) balances how close \(\tilde{f}^\star\) is to \(f^\star\) against how fast we can solve the relaxed problem.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-relaxing-a-nonconvex-sphere-constraint-to-a-convex-ball&quot;&gt;Worked example: Relaxing a Nonconvex Sphere Constraint to a Convex Ball&lt;/h3&gt;

&lt;p&gt;Consider the nonconvex problem of minimizing a linear function on the unit circle:
\(\text{minimize}_{x \in \mathbb{R}^2} \quad f(x) = -3x_1 - 4x_2 \quad \text{subject to} \quad x_1^2 + x_2^2 = 1.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify why it is nonconvex&lt;/strong&gt;: The equality constraint \(x_1^2 + x_2^2 = 1\) is non-affine—the midpoint of \((1, 0)\) and \((-1, 0)\) is \((0, 0)\), which does not lie on the unit circle.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Form the convex relaxation&lt;/strong&gt;: Replace the equality \(x_1^2 + x_2^2 = 1\) with the convex quadratic inequality \(x_1^2 + x_2^2 \le 1\) (widening the circle \(C\) to the filled unit disk \(\tilde{C}\)):
\(\text{minimize}_{x \in \mathbb{R}^2} \quad -3x_1 - 4x_2 \quad \text{subject to} \quad \|x\|_2^2 \le 1.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the relaxed convex problem&lt;/strong&gt;: By the Cauchy–Schwarz inequality,
\(-3x_1 - 4x_2 = -(3, 4) \cdot (x_1, x_2) \ge -\|(3, 4)\|_2 \|x\|_2 = -5 \|x\|_2 \ge -5,\)
with equality achieved at \(\tilde{x}^\star = \frac{1}{5}(3, 4) = (0.6, 0.8)\), giving \(\tilde{f}^\star = -5\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check exactness&lt;/strong&gt;: Test whether \(\tilde{x}^\star\) lies in the original nonconvex set \(C\):
\(0.6^2 + 0.8^2 = 0.36 + 0.64 = 1.\)
It does! Because \(\tilde{x}^\star \in C\), the relaxation is &lt;strong&gt;exact&lt;/strong&gt;, certifying \(x^\star = (0.6, 0.8)\) and \(f^\star = -5\) as the global optimum of the original nonconvex problem.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section discusses relaxation techniques, which are used to simplify or approximate convex optimization problems by relaxing constraints.&lt;/p&gt;

&lt;p&gt;Consider a problem of the form:&lt;/p&gt;
&lt;blockquote&gt;
\[\text{min}_{x} \text{ } f(x) \text{  subject to  } x \in C\]
&lt;/blockquote&gt;

&lt;p&gt;The process of changing the domain set \(C\) to a superset \(\tilde{C} \supseteq C\) is known as &lt;em&gt;Relaxation&lt;/em&gt;.&lt;/p&gt;
&lt;blockquote&gt;
\[\text{min}_{x} \text{ } f(x) \text{  subject to  } x \in \tilde{C}\]
&lt;/blockquote&gt;

&lt;p&gt;Since we are optimizing over a larger domain set than \(C\), the optimal value of the relaxed problem is always less than or equal to that of the original problem.&lt;/p&gt;

&lt;h3 id=&quot;important-special-case-relaxing-non-affine-equality-constraints&quot;&gt;Important special case: relaxing non-affine equality constraints&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(h_{j}(x) = 0, j = 1, \dotsc, r,\) where \(h_{j}, j = 1, \dotsc, r\) are convex but non-affine,
are replaced with \(h_{j}(x) \le 0, j = 1, \dotsc, r.\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By transforming equality constraints into inequality constraints, the relaxation technique loosens the constraints and effectively enlarges the domain. When the given equality constraints are convex and non-affine, this method can be used to reformulate the problem as a convex optimization problem. (However, this is under the condition that the same solution is still valid even after the relaxation.)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>04-07 Slack variables</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_07_Slack_variables/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_07_Slack_variables</id>
   <content type="html">&lt;p&gt;Imagine you have a budget cap of $100 and you spend $73. You can either write the inequality \(x \le 100\), or you can name the unspent $27 as a variable \(s = 27 \ge 0\) and write the clean equation \(x + s = 100\). That simple accounting move—introducing &lt;em&gt;slack variables&lt;/em&gt;—is the backbone of the simplex method and interior-point solvers, turning awkward inequalities into structured equations plus simple nonnegativity boxes.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-turning-inequalities-into-structured-equalities&quot;&gt;Key ideas: Turning Inequalities into Structured Equalities&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Exact Reformulation of Inequalities&lt;/strong&gt;: Any inequality \(g_i(x) \le 0\) is equivalent to introducing a scalar variable \(s_i \ge 0\) and enforcing \(g_i(x) + s_i = 0\). In linear programming, \(Gx \le h\) becomes \(Gx + s = h,\; s \ge 0\)—keeping the equality constraint affine!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The Convexity Trap for Nonlinear Inequalities&lt;/strong&gt;: Warning! If \(g_i(x)\) is a &lt;em&gt;nonlinear&lt;/em&gt; convex function (like \(x^2 - 1 \le 0\)), writing \(g_i(x) + s_i = 0\) creates a &lt;em&gt;non-affine&lt;/em&gt; equality constraint, which violates the standard convex-program rule. Therefore, slack variables preserve standard convexity &lt;strong&gt;only for affine inequalities&lt;/strong&gt; (unless \(s_i\) is kept in an inequality \(g_i(x) + s_i \le 0\) or lifted into a cone constraint).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Physical and Economic Meaning of Slack&lt;/strong&gt;: At an optimal solution \((x^\star, s^\star)\), the value \(s_i^\star = -g_i(x^\star)\) measures unused resource or safety margin. When \(s_i^\star = 0\), the constraint is &lt;em&gt;active&lt;/em&gt; (a bottleneck); when \(s_i^\star &amp;gt; 0\), the constraint is &lt;em&gt;inactive&lt;/em&gt; (surplus capacity exists).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enabling Matrix Solvers and Duality&lt;/strong&gt;: Converting \(Gx \le h\) to \(Gx + s = h, s \ge 0\) lets simplex algorithms solve linear systems \(B x_B = h\) at every pivot and lets interior-point methods place a clean logarithmic barrier \(-\sum_i \ln(s_i)\) directly on the nonnegative slacks.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-converting-a-production-lp-to-standard-slack-form&quot;&gt;Worked example: Converting a Production LP to Standard Slack Form&lt;/h3&gt;

&lt;p&gt;A small workshop produces \(x_1\) chairs and \(x_2\) tables to maximize profit \(3x_1 + 5x_2\) (equivalently, minimize \(-3x_1 - 5x_2\)) subject to wood and labor limits:
\(2x_1 + x_2 \le 10, \qquad x_1 + 3x_2 \le 12, \qquad x_1, x_2 \ge 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Introduce nonnegative slack variables \(s_1, s_2 \ge 0\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;\(s_1\) represents unused wood hours: \(2x_1 + x_2 + s_1 = 10\).&lt;/li&gt;
      &lt;li&gt;\(s_2\) represents unused labor hours: \(x_1 + 3x_2 + s_2 = 12\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Write the matrix standard form&lt;/strong&gt;: Let \(z = (x_1, x_2, s_1, s_2)^T \ge 0\). Then the LP is
\(\min_{z \ge 0} \quad [-3, -5, 0, 0]\,z \quad \text{subject to} \quad \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 3 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} z = \begin{bmatrix} 10 \\ 12 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inspect candidate vertices via slack values&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;At \((x_1, x_2) = (0, 0)\): \(s_1 = 10, s_2 = 12\) (all resources unused, profit \(= 0\)).&lt;/li&gt;
      &lt;li&gt;At \((x_1, x_2) = (0, 4)\): \(s_1 = 10 - 4 = 6\) (6 wood hours left), \(s_2 = 12 - 12 = 0\) (labor is binding), profit \(= 20\).&lt;/li&gt;
      &lt;li&gt;At the intersection of both binding constraints (\(s_1 = 0, s_2 = 0\)): solving \(2x_1 + x_2 = 10\) and \(x_1 + 3x_2 = 12\) gives \(5x_2 = 14 \implies x_2^\star = 2.8\) and \(x_1^\star = 3.6\), with profit \(3(3.6) + 5(2.8) = 10.8 + 14.0 = 24.8\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify slack interpretation&lt;/strong&gt;: Because \(s_1^\star = 0\) and \(s_2^\star = 0\), both wood and labor are completely exhausted at the optimal production plan \((3.6, 2.8)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;slack-variables-in-convex-optimization&quot;&gt;Slack Variables in Convex Optimization&lt;/h1&gt;

&lt;h2 id=&quot;introduction-and-motivation&quot;&gt;Introduction and Motivation&lt;/h2&gt;

&lt;p&gt;Slack variables are auxiliary variables introduced to transform inequality constraints into equality constraints. This transformation is fundamental in optimization theory and has practical applications in linear programming, interior-point methods, and many optimization algorithms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do we need slack variables?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Many optimization algorithms are designed to handle equality constraints more efficiently&lt;/li&gt;
  &lt;li&gt;They provide a geometric interpretation of how “tight” a constraint is&lt;/li&gt;
  &lt;li&gt;They are essential in the simplex method for linear programming&lt;/li&gt;
  &lt;li&gt;They help in duality theory and sensitivity analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mathematical-formulation&quot;&gt;Mathematical Formulation&lt;/h2&gt;

&lt;p&gt;Consider the standard convex optimization problem:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_x &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;g_{i}(x) \leq 0, \quad i = 1, \ldots, m\\
&amp;amp;&amp;amp;&amp;amp;Ax = b
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;By introducing &lt;strong&gt;slack variables&lt;/strong&gt; \(s_i \geq 0\) for each inequality constraint, we can reformulate this as:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_{x, s} &amp;amp;&amp;amp;f(x)\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;s_{i} \geq 0, \quad i = 1, \ldots, m\\
&amp;amp;&amp;amp;&amp;amp;g_{i}(x) + s_{i} = 0, \quad i = 1, \ldots, m\\
&amp;amp;&amp;amp;&amp;amp;Ax = b
\end{aligned}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;geometric-interpretation&quot;&gt;Geometric Interpretation&lt;/h2&gt;

&lt;p&gt;The slack variable \(s_i\) represents the “slack” or “margin” in the \(i\)-th constraint:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(s_i &amp;gt; 0\)&lt;/strong&gt;: The constraint \(g_i(x) \leq 0\) is &lt;strong&gt;inactive&lt;/strong&gt; (not binding)
    &lt;ul&gt;
      &lt;li&gt;The point \(x\) is in the interior of the feasible region defined by constraint \(i\)&lt;/li&gt;
      &lt;li&gt;We have \(g_i(x) = -s_i &amp;lt; 0\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(s_i = 0\)&lt;/strong&gt;: The constraint \(g_i(x) \leq 0\) is &lt;strong&gt;active&lt;/strong&gt; (binding)
    &lt;ul&gt;
      &lt;li&gt;The point \(x\) lies exactly on the boundary defined by \(g_i(x) = 0\)&lt;/li&gt;
      &lt;li&gt;This constraint is “tight” at the optimal solution&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;practical-example-resource-allocation&quot;&gt;Practical Example: Resource Allocation&lt;/h2&gt;

&lt;p&gt;Consider a simple resource allocation problem:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Original Problem:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\max &amp;amp;&amp;amp;3x_1 + 2x_2 \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;x_1 + x_2 \leq 4 \quad \text{(labor hours)}\\
&amp;amp;&amp;amp;&amp;amp;2x_1 + x_2 \leq 6 \quad \text{(material units)}\\
&amp;amp;&amp;amp;&amp;amp;x_1, x_2 \geq 0
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;With Slack Variables:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\max &amp;amp;&amp;amp;3x_1 + 2x_2 \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;x_1 + x_2 + s_1 = 4\\
&amp;amp;&amp;amp;&amp;amp;2x_1 + x_2 + s_2 = 6\\
&amp;amp;&amp;amp;&amp;amp;x_1, x_2, s_1, s_2 \geq 0
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(s_1\): unused labor hours&lt;/li&gt;
  &lt;li&gt;\(s_2\): unused material units&lt;/li&gt;
  &lt;li&gt;If \(s_1 = 0\) at optimum: all labor is utilized&lt;/li&gt;
  &lt;li&gt;If \(s_2 &amp;gt; 0\) at optimum: some material remains unused&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;important-properties-and-considerations&quot;&gt;Important Properties and Considerations&lt;/h2&gt;

&lt;h3 id=&quot;1-equivalence-of-problems&quot;&gt;1. Equivalence of Problems&lt;/h3&gt;
&lt;p&gt;The original and slack variable formulations are &lt;strong&gt;mathematically equivalent&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Same optimal objective value&lt;/li&gt;
  &lt;li&gt;Optimal \(x^*\) is the same in both formulations&lt;/li&gt;
  &lt;li&gt;The slack variables \(s_i^*\) at optimum tell us which constraints are active&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-convexity-preservation&quot;&gt;2. Convexity Preservation&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Critical Note:&lt;/strong&gt; The transformation preserves convexity &lt;strong&gt;only when&lt;/strong&gt; \(g_i(x)\) are &lt;strong&gt;affine functions&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;If \(g_i(x) = a_i^T x - b_i\) (affine)&lt;/strong&gt;: The reformulated problem remains convex&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;If \(g_i(x)\) is nonlinear&lt;/strong&gt;: The equality constraint \(g_i(x) + s_i = 0\) may destroy convexity&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-dimensionality-impact&quot;&gt;3. Dimensionality Impact&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Original problem: \(n\) variables&lt;/li&gt;
  &lt;li&gt;With slack variables: \(n + m\) variables&lt;/li&gt;
  &lt;li&gt;Trade-off: more variables but simpler constraint structure&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;example-converting-a-linear-program&quot;&gt;Example: Converting a Linear Program&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Original Form:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min &amp;amp;&amp;amp;c^T x \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;Ax \leq b\\
&amp;amp;&amp;amp;&amp;amp;x \geq 0
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Standard Form with Slack Variables:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min &amp;amp;&amp;amp;c^T x \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;Ax + s = b\\
&amp;amp;&amp;amp;&amp;amp;x, s \geq 0
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;Where \(s \in \mathbb{R}^m\) is the vector of slack variables.&lt;/p&gt;

&lt;h2 id=&quot;key-takeaways&quot;&gt;Key Takeaways&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Transformation Tool&lt;/strong&gt;: Slack variables convert inequalities to equalities&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Geometric Meaning&lt;/strong&gt;: They measure constraint “tightness”&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm Enabler&lt;/strong&gt;: Essential for many optimization algorithms&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convexity Condition&lt;/strong&gt;: Preserve convexity only for affine constraints&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Practical Insight&lt;/strong&gt;: Provide economic interpretation in resource problems&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Understanding slack variables is crucial for:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Implementing optimization algorithms&lt;/li&gt;
  &lt;li&gt;Interpreting optimization results&lt;/li&gt;
  &lt;li&gt;Analyzing constraint sensitivity&lt;/li&gt;
  &lt;li&gt;Connecting theory with computational practice&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-06 Eliminating equality constraints</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_06_Eliminating_equality_constraints/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_06_Eliminating_equality_constraints</id>
   <content type="html">&lt;p&gt;If a robot arm is bolted to a flat rail, you do not need three spatial coordinates to describe its position—one coordinate along the rail tells the whole story. Eliminating affine equality constraints \(Ax = b\) works on the exact same principle: every feasible vector \(x\) splits into a single particular anchor \(x_0\) plus a free movement \(My\) inside the null space of \(A\), turning a constrained problem into a lower-dimensional problem with no equality constraints at all.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-null-space-parameterization-of-affine-constraints&quot;&gt;Key ideas: Null-Space Parameterization of Affine Constraints&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Affine Subspace Decomposition&lt;/strong&gt;: Whenever \(Ax = b\) is consistent, pick any particular solution \(x_0\) with \(Ax_0 = b\) and a matrix \(M \in \mathbb{R}^{n \times (n-r)}\) whose columns form a basis for \(\operatorname{null}(A)\) (where \(r = \operatorname{rank}(A)\)). Then \(\{x : Ax = b\} = \{My + x_0 : y \in \mathbb{R}^{n-r}\}\), giving an exact, redundancy-free parameterization.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convexity Is Automatically Preserved&lt;/strong&gt;: Substituting \(x = My + x_0\) composes the convex objective \(f\) and convex inequalities \(g_i\) with an affine map. Because pre-composition with an affine function always preserves convexity, the reduced problem in \(y\) is guaranteed to remain convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dimension Reduction vs. Sparsity Loss&lt;/strong&gt;: Eliminating \(r\) independent equalities shrinks the variable count from \(n\) to \(n - r\), which is great for small dense problems or analytical derivations. However, for large sparse systems (e.g., network flows or PDE meshes), computing a null-space basis \(M\) via QR/SVD can be expensive and turn a sparse problem into a dense one—which is why large-scale solvers often keep \(Ax = b\) explicitly via KKT systems.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choice of Basis \(M\) Matters Numerically&lt;/strong&gt;: Using an &lt;em&gt;orthonormal&lt;/em&gt; basis \(M\) (so \(M^T M = I\), obtained from QR factorization of \(A^T\)) preserves Euclidean norms and avoids inflating the condition number of the Hessian \(M^T \nabla^2 f(x) M\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-reducing-a-3d-constrained-quadratic-to-a-1d-unconstrained-problem&quot;&gt;Worked example: Reducing a 3D Constrained Quadratic to a 1D Unconstrained Problem&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2, x_3) = x_1^2 + 2x_2^2 + x_3^2\) subject to the two linear equalities:
\(x_1 + x_2 + x_3 = 6, \qquad x_1 - x_3 = 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Write the system as \(Ax = b\)&lt;/strong&gt;:
\(A = \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; -1 \end{bmatrix}, \qquad b = \begin{bmatrix} 6 \\ 0 \end{bmatrix}.\)
Since \(\operatorname{rank}(A) = 2\) and \(n = 3\), the null space has dimension \(3 - 2 = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find a particular solution \(x_0\) and a null-space basis \(M\)&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Setting \(x_3 = 0\) gives \(x_1 = 0\) and \(x_2 = 6\), so \(x_0 = (0, 6, 0)^T\) satisfies \(Ax_0 = (6, 0)^T = b\).&lt;/li&gt;
      &lt;li&gt;For \(Av = 0\): \(v_1 - v_3 = 0 \implies v_1 = v_3\), and \(v_1 + v_2 + v_3 = 0 \implies v_2 = -2v_3\). Choosing \(v_3 = 1\) gives the basis column \(M = (1, -2, 1)^T\).&lt;/li&gt;
      &lt;li&gt;Check \(AM = (1 - 2 + 1,\; 1 - 1)^T = (0, 0)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Substitute \(x = My + x_0 = (y,\; 6 - 2y,\; y)^T\) into the objective&lt;/strong&gt;:
\(\tilde{f}(y) = y^2 + 2(6 - 2y)^2 + y^2 = 2y^2 + 2(36 - 24y + 4y^2) = 10y^2 - 48y + 72.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the unconstrained 1D problem and lift back to \(x\)&lt;/strong&gt;:
Setting \(\tilde{f}&apos;(y) = 20y - 48 = 0\) gives \(y^\star = \frac{48}{20} = 2.4\).
Substituting back:
\(x^\star = M(2.4) + x_0 = \begin{bmatrix} 2.4 \\ 6 - 4.8 \\ 2.4 \end{bmatrix} = \begin{bmatrix} 2.4 \\ 1.2 \\ 2.4 \end{bmatrix}.\)
Verify constraints: \(2.4 + 1.2 + 2.4 = 6\) and \(2.4 - 2.4 = 0\). Optimal value: \(f(x^\star) = 2.4^2 + 2(1.2)^2 + 2.4^2 = 5.76 + 2.88 + 5.76 = 14.4\).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section explains techniques for eliminating equality constraints in convex optimization problems to simplify the feasible set or problem structure.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x)\\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;g_{i}(x) \leq 0, i = 1, .., m\\
&amp;amp;&amp;amp;&amp;amp;{Ax = b}.\\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;For an arbitrary solution \(x_{0}\) satisfying \(Ax_{0} = b\) and \(\text{col}(M) = \text{null}(A)\), any \(x\) that satisfies the equality constraint can be expressed as follows:&lt;/p&gt;
&lt;blockquote&gt;
\[x = My + x_{0}\]
&lt;/blockquote&gt;

&lt;p&gt;That is, \(Ax = A(My + x_{0}) = AMy + Ax_{0} = 0 + b = b\). Therefore, by substituting \(My+x_{0}\) for \(x\) in the given problem, we can eliminate the equality constraint.&lt;/p&gt;

&lt;p&gt;Thus, the following problem is equivalent to the original problem:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_y &amp;amp;&amp;amp;f(My+x_0)\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;g_{i}(My+x_{0}) \leq 0, i = 1, .., m.\\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;However, caution is advised when using this method for the following reasons:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;The computation of \(M\) is generally very expensive.&lt;/li&gt;
  &lt;li&gt;If \(x\) is sparser than \(y\), the cost of computation using \(y\) may be higher.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>04-05 Transformations and change of variables</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_05_Transformations_and_change_of_variables/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_05_Transformations_and_change_of_variables</id>
   <content type="html">&lt;p&gt;Many optimization problems in physics, finance, and engineering look hopelessly nonconvex at first glance—products of powers, ratios of norms, or awkward exponential constraints. Yet a surprisingly large fraction of them are &lt;em&gt;convex problems in disguise&lt;/em&gt;. Just as switching from Cartesian to polar coordinates turns a messy circle equation into \(r = 1\), monotone transformations and invertible changes of variables unmask hidden convexity without altering the true optimal solution.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-discovering-hidden-convexity&quot;&gt;Key ideas: Discovering Hidden Convexity&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Monotone Increasing Objective Transformations&lt;/strong&gt;: If \(h: \mathbb{R} \to \mathbb{R}\) is strictly increasing on the range of \(f\), then minimizing \(h(f(x))\) has the exact same set of optimal points \(X_{\mathrm{opt}}\) as minimizing \(f(x)\). Taking \(\ln(\cdot)\) of a likelihood function or squaring a nonnegative norm \(\|Ax - b\|_2\) are everyday applications that simplify derivatives or remove square roots.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;One-to-One Change of Variables&lt;/strong&gt;: If \(\phi: \mathbb{R}^n \to \mathbb{R}^n\) is a bijection whose image covers the feasible domain, substituting \(x = \phi(z)\) produces an equivalent problem in \(z\), and optimal points map back via \(x^\star = \phi(z^\star)\). Choosing \(\phi\) cleverly (such as \(x_i = e^{z_i}\) for positive variables) can turn multiplicative constraints into additive convex ones.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Log-Sum-Exp and Geometric Programming&lt;/strong&gt;: A posynomial \(\sum_{k=1}^K c_k x_1^{a_{1k}} \cdots x_n^{a_{nk}}\) (with \(c_k &amp;gt; 0, x_i &amp;gt; 0\)) is generally nonconvex in \(x\). Setting \(x_i = e^{z_i}\) and taking the logarithm of the objective and constraints converts every posynomial into \(\ln\!\left(\sum_k \exp(a_k^T z + b_k)\right)\), which is convex in \(z\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preserving Equivalence vs. Changing Optimal Value&lt;/strong&gt;: A strictly increasing transformation \(h\) preserves the &lt;em&gt;minimizers&lt;/em&gt; \(x^\star\), though the &lt;em&gt;optimal value&lt;/em&gt; changes from \(f^\star\) to \(h(f^\star)\). Always invert \(h\) and \(\phi\) at the end when reporting the original problem’s answer.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-unmasking-a-nonconvex-looking-posynomial-program&quot;&gt;Worked example: Unmasking a Nonconvex-Looking Posynomial Program&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = x_1^{-1} x_2^{-1}\) subject to \(x_1 &amp;gt; 0,\; x_2 &amp;gt; 0\) and \(x_1 + 4x_2 \le 8\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Observe the apparent nonconvexity&lt;/strong&gt;: The objective \(f(x_1, x_2) = (x_1 x_2)^{-1}\) is a monomial; in general geometric programs, products and powers with arbitrary exponents do not have positive semidefinite Hessians everywhere.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the change of variables \(x_1 = e^{z_1},\; x_2 = e^{z_2}\)&lt;/strong&gt; (a bijection from \(\mathbb{R}^2\) onto \(\mathbb{R}^2_{++}\)):
    &lt;ul&gt;
      &lt;li&gt;Objective becomes \(e^{-z_1 - z_2}\).&lt;/li&gt;
      &lt;li&gt;Constraint becomes \(e^{z_1} + 4e^{z_2} \le 8\), or equivalently \(\frac{1}{8}e^{z_1} + \frac{1}{2}e^{z_2} \le 1\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the strictly increasing transformation \(h(u) = \ln(u)\)&lt;/strong&gt; to both the positive objective and both sides of the positive inequality constraint:
\(\begin{aligned} \text{minimize}_{z_1, z_2} \quad &amp;amp; -z_1 - z_2 \\ \text{subject to} \quad &amp;amp; \ln\!\left(e^{z_1 - \ln 8} + e^{z_2 - \ln 2}\right) \le 0. \end{aligned}\)
Now the objective is linear (convex) and the constraint is a log-sum-exp of affine functions (convex)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Solve the convex problem analytically&lt;/strong&gt;: By symmetry of minimizing \(-z_1 - z_2\) subject to \(e^{z_1} + 4e^{z_2} = 8\), the constraint binds and AM–GM (or Lagrange multipliers on the convex form) gives \(e^{z_1} = 4e^{z_2} = 4\).
    &lt;ul&gt;
      &lt;li&gt;Hence \(z_1^\star = \ln 4\) and \(z_2^\star = \ln 1 = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Map back to the original variables&lt;/strong&gt;: \(x_1^\star = e^{\ln 4} = 4\), \(x_2^\star = e^0 = 1\). Check feasibility: \(4 + 4(1) = 8 \le 8\). The original optimal value is \(f^\star = (4 \cdot 1)^{-1} = \frac{1}{4}\) (matching \(e^{-z_1^\star - z_2^\star} = e^{-\ln 4} = \frac{1}{4}\)).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This section discusses transformations and change of variables in convex optimization problems, which are useful for simplifying or reformulating problems.&lt;/p&gt;

&lt;p&gt;The objective function or constraint functions can be modified while preserving the given optimization problem, and sometimes this can be used to discover the “hidden convexity” of the problem.&lt;/p&gt;

&lt;h3 id=&quot;theorem-1&quot;&gt;Theorem 1&lt;/h3&gt;
&lt;p&gt;When function \(h : \mathbb{R} \rightarrow \mathbb{R}\) is a monotone increasing transformation, the following relationship holds:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
  &amp;amp;\text{min}_{x} f(x) \text{ subject to } x \in C \\
  \Longleftrightarrow \quad &amp;amp;\text{min}_{x} h(f(x)) \text{ subject to } x \in C
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;theorem-2&quot;&gt;Theorem 2&lt;/h3&gt;
&lt;p&gt;If function \(\phi: \mathbb{R}^{n} \rightarrow \mathbb{R}^{m}\) is a one-to-one correspondence function and the image of \(\phi\) covers the feasible set \(C\), then the variables of the optimization problem can be changed as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
   &amp;amp;\min_{x} f(x) \text{ subject to } x \in C \\\\ 
   \Longleftrightarrow \quad &amp;amp;\min_{y} f(\phi(y)) \text{ subject to } \phi(y) \in C
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;example-geometric-programming&quot;&gt;Example: geometric programming&lt;/h3&gt;

&lt;p&gt;A function \(f: \mathbb{R}_{++}^n \rightarrow \mathbb{R}\) of the following form is called a &lt;strong&gt;monomial&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
\[f(x) = \gamma x_{1}^{a_{1}} x_{2}^{a_{2}} \dotsb x_{n}^{a_{n}} \text{ for } \gamma &amp;gt; 0, a_{1}, \dotsc, a_{n} \in \mathbb{R}.\]
&lt;/blockquote&gt;

&lt;p&gt;Also, the sum of monomials is called a &lt;strong&gt;posynomial&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
\[g(x) = \sum_{k=1}^{p} \gamma_{k} x_{1}^{a_{k1}} x_{2}^{a_{k2}} \dotsb x_{n}^{a_{kn}} \text{ for } \gamma &amp;gt; 0, a\_1, \dotsc, a_{n} \in \mathbb{R}.\]
&lt;/blockquote&gt;

&lt;p&gt;A &lt;strong&gt;geometric program&lt;/strong&gt; is defined in the following form and is a non-convex problem:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
&amp;amp;\min_{x} &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to } &amp;amp;&amp;amp;g_{i}(x) \leq 1, i = 1, \dotsc, m\\
&amp;amp;&amp;amp;&amp;amp;h_{j}(x) = 1, j = 1, \dotsc, r,\\\\
\end{align}\\\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;where \(f\), \(g_{i}, i=1, \dotsc, m\) are posynomials and \(h_{j}, j=1, \dotsc, r\) are monomials.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s prove that a geometric program is equivalent to some convex problem.&lt;/p&gt;

&lt;h3 id=&quot;proof&quot;&gt;Proof:&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;For \(f(x) = \gamma x_{1}^{a_{1}} x_{2}^{a_{2}} \dotsb x_{n}^{a_{n}}\), if we let \(y_{i} = \log x_{i}\) and \(b = \log \gamma\), then \(f\) can be transformed as follows, and by &lt;strong&gt;Theorem 2&lt;/strong&gt;, this preserves the given optimization problem equivalently:
\(\gamma (e^{y_{1}})^{a_{1}} (e^{y_{2}})^{a_{2}} \dotsb (e^{y_{n}})^{a_{n}} = e^{a^Ty + b}\)&lt;/p&gt;

  &lt;p&gt;Also, a posynomial can be represented as \(\sum_{k=1}^{p} e^{a_{k}^{Ty} + b_{k}}\).&lt;/p&gt;

  &lt;p&gt;At this point, by &lt;strong&gt;Theorem 1&lt;/strong&gt;, the logarithmic form \(\log \big( \sum_{k=1}^{p} e^{a_{k}^{Ty} + b_{k}} \big)\) can also preserve the optimization problem equivalently.&lt;/p&gt;

  &lt;p&gt;That is, the geometric program is equivalent to the following problem, which is a convex problem:&lt;/p&gt;

\[\begin{align}
&amp;amp;\min_{x} \quad &amp;amp;&amp;amp;{log \big( \sum_{k=1}^{p_{0}} e^{a_{0k}^{Ty} + b_{0k}} \big)} \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;{
         log \big( \sum_{k=1}^{p_{i}} e^{a_{ik}^{Ty} + b_{ik}} \big)
         \leq 0
         , \quad i = 1, \dotsc, m
}\\
&amp;amp;&amp;amp;&amp;amp;c_{j}^{Ty} + d_{j} = 0, \quad j = 1, \dotsc, r\\\\
\end{align}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>04-04 Partial optimization</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_04_Partial_optimization/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_04_Partial_optimization</id>
   <content type="html">&lt;p&gt;Suppose you are designing a supply chain with two kinds of decisions: &lt;em&gt;strategic&lt;/em&gt; decisions (where to build warehouses, \(x\)) and &lt;em&gt;operational&lt;/em&gt; decisions (how much to ship from each warehouse once built, \(y\)). If you optimize the shipping plan \(y\) for every candidate warehouse layout \(x\), does the resulting cost-as-a-function-of-\(x\) remain convex? Remarkably, yes—partial minimization over a convex block of variables always preserves convexity, letting you eliminate auxiliary variables cleanly or reveal the hidden hinge-loss structure of models like Support Vector Machines.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-partial-minimization-and-variable-elimination&quot;&gt;Key ideas: Partial Minimization and Variable Elimination&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Convexity Preservation Under Infimal Projection&lt;/strong&gt;: If \(f(x, y)\) is &lt;em&gt;jointly convex&lt;/em&gt; in \((x, y)\) and \(C\) is a convex set, then the marginal function \(g(x) = \inf_{y \in C} f(x, y)\) is convex in \(x\) (provided \(g(x) &amp;gt; -\infty\)). Geometrically, the epigraph of \(g\) is the projection of the convex epigraph of \(f\) onto the \((x, t)\) subspace, and linear projections of convex sets are always convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Equivalence of Joint and Two-Stage Problems&lt;/strong&gt;: Minimizing \(f(x, y)\) jointly over \((x, y)\) with constraints on \(y\) is equivalent to first minimizing over \(y\) (treating \(x\) as fixed) to obtain \(g(x)\), and then minimizing \(g(x)\) over \(x\). You can run this trick in &lt;em&gt;both&lt;/em&gt; directions: eliminate variables to get a compact unconstrained form (like SVM hinge loss), or introduce variables to smooth out a nonsmooth objective (like epigraph variables).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Joint Convexity Is Essential&lt;/strong&gt;: It is &lt;em&gt;not&lt;/em&gt; enough for \(f(x, y)\) to be convex in \(x\) for each fixed \(y\) and convex in \(y\) for each fixed \(x\) (separate convexity). For example, \(f(x, y) = xy\) is linear in each variable separately, yet not jointly convex. Always verify joint convexity before projecting out \(y\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Canonical ML Example — Soft-Margin SVM&lt;/strong&gt;: Introducing slack variables \(\xi_i \ge 0\) converts the nonsmooth hinge loss \(\max(0, 1 - y_i(w^T x_i + b))\) into linear inequalities \(\xi_i \ge 1 - y_i(w^T x_i + b)\) and \(\xi_i \ge 0\). Minimizing out \(\xi_i\) analytically recovers the exact hinge-loss objective.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-eliminating-a-variable-in-a-coupled-quadratic-program&quot;&gt;Worked example: Eliminating a Variable in a Coupled Quadratic Program&lt;/h3&gt;

&lt;p&gt;Consider the jointly convex quadratic function \(f(x, y) = x^2 + 2xy + 2y^2 - 4y\) over \((x, y) \in \mathbb{R}^2\). Let us compute the reduced objective \(g(x) = \min_{y \in \mathbb{R}} f(x, y)\) and verify both problems yield the same solution.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Verify joint convexity&lt;/strong&gt;: The Hessian of \(f(x, y)\) is
\(\nabla^2 f(x, y) = \begin{bmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix}.\)
Its leading principal minors are \(2 &amp;gt; 0\) and \(\det = 2(4) - 2^2 = 4 &amp;gt; 0\), so \(\nabla^2 f \succ 0\) and \(f\) is strictly jointly convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize over \(y\) for fixed \(x\)&lt;/strong&gt;: Differentiate with respect to \(y\) and set to zero:
\(\frac{\partial f}{\partial y} = 2x + 4y - 4 = 0 \implies y^\star(x) = 1 - \frac{x}{2}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Substitute \(y^\star(x)\) back into \(f(x, y)\) to form \(g(x)\)&lt;/strong&gt;:
\(\begin{aligned} g(x) &amp;amp;= x^2 + 2x\left(1 - \frac{x}{2}\right) + 2\left(1 - \frac{x}{2}\right)^2 - 4\left(1 - \frac{x}{2}\right) \\ &amp;amp;= x^2 + 2x - x^2 + 2\left(1 - x + \frac{x^2}{4}\right) - 4 + 2x \\ &amp;amp;= \frac{1}{2}x^2 + 2x - 2. \end{aligned}\)
Notice that \(g&apos;&apos;(x) = 1 &amp;gt; 0\), confirming \(g(x)\) is convex (this is the Schur complement of the \(y\)-block!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize \(g(x)\) and recover \((x^\star, y^\star)\)&lt;/strong&gt;: Setting \(g&apos;(x) = x + 2 = 0\) gives \(x^\star = -2\), and substituting into \(y^\star(x)\) gives \(y^\star = 1 - (-2)/2 = 2\). The optimal value is \(g(-2) = \frac{1}{2}(4) + 2(-2) - 2 = -4\). Checking directly in \(f(-2, 2)\): \((-2)^2 + 2(-2)(2) + 2(2)^2 - 4(2) = 4 - 8 + 8 - 8 = -4\), an exact match.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href=&quot;/contents/en/chapter03/03_02_operations_that_preserve_convexity/&quot;&gt;Reminder: &lt;/a&gt;
If \(C\) is a convex set and \(f\) is convex in \((x,y)\), then \(g(x) = \min_{y \in C} f(x, y)\) is convex in \(x\).&lt;/p&gt;

&lt;p&gt;Thus, partial optimization in a convex problem constructed with multivariate functions preserves convexity.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter04/partial-optimization.png&quot; alt=&quot;[Fig1] partial optimization of a convex problem [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] partial optimization of a convex problem [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;example-hinge-form-of-svms&quot;&gt;Example: hinge form of SVMs&lt;/h3&gt;

&lt;p&gt;For a non-separable set, the SVM problem is defined as:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_{\beta, \beta_{0}, \xi} &amp;amp;&amp;amp;\frac{1}{2}\|\beta\|_2^2 + C \sum_{i=1}^{n} \xi_{i} \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;{\xi}_{i} \ge 0, \\ 
&amp;amp;&amp;amp;&amp;amp;y_{i}(x_{i}^T \beta + \beta_{0}) \ge 1 - {\xi}_{i}, \\
&amp;amp;&amp;amp;&amp;amp;i = 1, .., n \\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;The above constraints can be expressed as a single constraint:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{aligned}
{\xi}_{i} \ge \max\{0, 1 - y_{i} (x_{i}^T \beta + \beta_{0})\} \\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;In this case, \(\max\{0, 1 - y_{i} (x_{i}^T \beta + \beta_{0})\}\) is the minimum value for \(\xi_{i}\), and we can define \(\tilde{f}\) as:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
\frac{1}{2} \|\beta\|_{2}^{2} + C \sum_{i=1}^{n} {\xi}_{i} &amp;amp;\ge \frac{1}{2} \|\beta\|_{2}^{2} + C \sum_{i=1}^{n} \max({0, 1 - y_{i} (x_{i}^T \beta + \beta_{0})})\\
&amp;amp;= \min\{\frac{1}{2} \|\beta\|_{2}^{2} + C \sum_{i=1}^{n} \xi_{i} \quad | \quad \xi_{i} \ge 0, \ y_{i}(x_{i}^T \beta + \beta_{0}) \ge 1 - \xi_{i}, \ i = 1, .., n\} \\
&amp;amp;= \tilde{f}(\beta, \beta_{0}) \\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;By using the simplified \(\tilde{f}\) as the objective function, a more straightforward solution can be obtained. In the given problem, \(\xi\) has been eliminated, and it has also been transformed from a constrained problem to an unconstrained problem.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
\min_{\beta, \beta_0} \frac{1}{2} \|\beta\|_2^2 + C \sum_{i=1}^{n} \max\{0, 1 - y_{i} (x_{i}^{T} \beta + \beta_{0}) \}
\end{aligned}\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>04-03 Optimality conditions</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_03_Optimality_conditions/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_03_Optimality_conditions</id>
   <content type="html">&lt;p&gt;In single-variable calculus, you learn one reflex: set \(f&apos;(x) = 0\). The moment constraints enter the picture, that reflex breaks—a ball resting against the wall of a tilted bowl stops moving even though gravity still pulls downhill! The first-order optimality condition for constrained convex optimization replaces “\(f&apos;(x) = 0\)” with a sharper geometric law: at the optimum, no feasible direction points downhill.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-first-order-variational-optimality&quot;&gt;Key ideas: First-Order Variational Optimality&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Feasible Directions and the Variational Inequality&lt;/strong&gt;: For a differentiable convex function \(f\) over a convex set \(C\), a point \(x^\star \in C\) is globally optimal if and only if \(\nabla f(x^\star)^T (y - x^\star) \ge 0\) for all \(y \in C\). Because \(y - x^\star\) is the direction toward any other feasible point, the directional derivative along every feasible ray must be nonnegative.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Normal Cone Geometry&lt;/strong&gt;: Rewriting the inequality as \((-\nabla f(x^\star))^T (y - x^\star) \le 0\) for all \(y \in C\) means that the negative gradient \(-\nabla f(x^\star)\) makes an obtuse (or right) angle with every feasible displacement—equivalently, \(-\nabla f(x^\star) \in N_C(x^\star)\), the normal cone of \(C\) at \(x^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recovering Classic Special Cases&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Unconstrained&lt;/em&gt; (\(C = \mathbb{R}^n\)): \(y - x^\star\) can point in any direction, forcing \(\nabla f(x^\star) = 0\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Affine equality&lt;/em&gt; (\(C = \{x : Ax = b\}\)): feasible displacements lie in \(\operatorname{null}(A)\), forcing \(\nabla f(x^\star) \perp \operatorname{null}(A)\), i.e., \(\nabla f(x^\star) = A^T \nu\) for some Lagrange multiplier \(\nu\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Nonnegative orthant&lt;/em&gt; (\(C = \mathbb{R}^n_+\)): yields the complementarity triad \(x^\star \ge 0\), \(\nabla f(x^\star) \ge 0\), and \(x_i^\star \nabla_i f(x^\star) = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Necessity AND Sufficiency&lt;/strong&gt;: In nonconvex optimization, \(\nabla f(x^\star)^T (y - x^\star) \ge 0\) is only necessary (saddle points satisfy it too). Convexity supplies the global linear underestimator \(f(y) \ge f(x^\star) + \nabla f(x^\star)^T(y - x^\star)\), immediately upgrading the condition to both necessary and sufficient for global optimality.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-certifying-optimality-on-the-nonnegative-orthant&quot;&gt;Worked example: Certifying Optimality on the Nonnegative Orthant&lt;/h3&gt;

&lt;p&gt;Minimize \(f(x_1, x_2) = (x_1 + 1)^2 + (x_2 - 2)^2\) subject to \(x_1 \ge 0,\; x_2 \ge 0\) (so \(C = \mathbb{R}^2_+\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the gradient&lt;/strong&gt;:
\(\nabla f(x) = \begin{bmatrix} 2(x_1 + 1) \\ 2(x_2 - 2) \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply the nonnegative orthant optimality conditions&lt;/strong&gt; (\(x_i \ge 0\), \(\nabla_i f(x) \ge 0\), \(x_i \nabla_i f(x) = 0\)):
    &lt;ul&gt;
      &lt;li&gt;For \(i = 1\): since \(x_1 \ge 0\), we always have \(2(x_1 + 1) \ge 2 &amp;gt; 0\). Complementary slackness \(x_1 \cdot 2(x_1 + 1) = 0\) forces \(x_1^\star = 0\).&lt;/li&gt;
      &lt;li&gt;For \(i = 2\): setting \(\nabla_2 f(x) = 2(x_2 - 2) = 0\) gives \(x_2^\star = 2 \ge 0\), which satisfies all three conditions (\(2 \ge 0\), \(0 \ge 0\), \(2 \cdot 0 = 0\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the gradient at \(x^\star = (0, 2)\)&lt;/strong&gt;:
\(\nabla f(0, 2) = \begin{bmatrix} 2 \\ 0 \end{bmatrix}, \quad -\nabla f(0, 2) = \begin{bmatrix} -2 \\ 0 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the variational inequality directly for every \(y \in \mathbb{R}^2_+\)&lt;/strong&gt;:
\(\nabla f(x^\star)^T (y - x^\star) = 2(y_1 - 0) + 0(y_2 - 2) = 2y_1 \ge 0 \quad \text{since } y_1 \ge 0.\)
Geometrically, the negative gradient \((-2, 0)\) pushes straight into the left wall \(x_1 = 0\), so the feasible set completely blocks any further descent.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;first-order-optimality-condition&quot;&gt;First order optimality condition&lt;/h2&gt;

&lt;p&gt;For more background on convex functions, see &lt;a href=&quot;/contents/en/chapter03/03_01_03_key_properties_of_convex_functions/&quot;&gt;Chapter 3: Key Properties of Convex Functions&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\min_x &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;x \in C
\end{aligned}\]
&lt;/blockquote&gt;

&lt;p&gt;For a convex problem where the objective function \(f\) is &lt;strong&gt;differentiable&lt;/strong&gt;, the following condition is necessary and sufficient for an optimal point \(x\):&lt;/p&gt;

&lt;blockquote&gt;
\[\nabla f(x)^{T}(y-x) \geq 0 \\
\text{ for all } y \in C\]
&lt;/blockquote&gt;

&lt;p&gt;This is called the &lt;em&gt;first-order condition for optimality&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;\(\nabla f(x)^{T}(y-x) = 0\) defines a hyperplane passing through \(x\) in set \(C\), and \(- \nabla f(x)\) points in the direction of movement toward the optimal point \(x\). &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;If the above condition is satisfied, 
set \(C\) is contained in the half-space opposite to \(- \nabla f(x)\), 
so \(x\) is an optimal point.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter04/first-order-condition.png&quot; alt=&quot;[Fig1] geometric interpretation of first-order condition for optimality [3]&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] geometric interpretation of first-order condition for optimality [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;important-special-case&quot;&gt;Important special case&lt;/h3&gt;
&lt;p&gt;When \(C = \mathbb{R}^n\) (unconstrained optimization),
the optimality condition is:&lt;/p&gt;
&lt;blockquote&gt;
\[\nabla f(x) = 0\]
&lt;/blockquote&gt;

&lt;p&gt;In this case every direction in \(\mathbb{R}^n\) is feasible. Whenever \(\nabla f(x) \ne 0\), the direction \(-\nabla f(x)\) is a descent direction (it decreases \(f\) locally, although it need not point straight at a minimizer), so \(\nabla f(x) = 0\) means there is no direction left that decreases \(f\) at \(x\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mathematical-foundation&quot;&gt;Mathematical Foundation&lt;/h2&gt;

&lt;p&gt;While first-order conditions use the gradient \(\nabla f(x)\), second-order conditions utilize the &lt;strong&gt;Hessian matrix&lt;/strong&gt;:&lt;/p&gt;

\[H_f(x) = \nabla^2 f(x) = \begin{bmatrix}
\frac{\partial^2 f}{\partial x_1^2} &amp;amp; \frac{\partial^2 f}{\partial x_1 \partial x_2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_1 \partial x_n} \\
\frac{\partial^2 f}{\partial x_2 \partial x_1} &amp;amp; \frac{\partial^2 f}{\partial x_2^2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_2 \partial x_n} \\
\vdots &amp;amp; \vdots &amp;amp; \ddots &amp;amp; \vdots \\
\frac{\partial^2 f}{\partial x_n \partial x_1} &amp;amp; \frac{\partial^2 f}{\partial x_n \partial x_2} &amp;amp; \cdots &amp;amp; \frac{\partial^2 f}{\partial x_n^2}
\end{bmatrix}\]

&lt;p&gt;The Hessian captures the &lt;strong&gt;curvature&lt;/strong&gt; of the function at point \(x\), providing information about the local shape of the objective function.&lt;/p&gt;

&lt;h2 id=&quot;second-order-optimality-conditions&quot;&gt;Second-Order Optimality Conditions&lt;/h2&gt;

&lt;p&gt;Consider the unconstrained optimization problem:
\(\min_x f(x)\)&lt;/p&gt;

&lt;p&gt;where \(f: \mathbb{R}^n \to \mathbb{R}\) is twice continuously differentiable.&lt;/p&gt;

&lt;h3 id=&quot;necessary-conditions-second-order&quot;&gt;Necessary Conditions (Second-Order)&lt;/h3&gt;

&lt;p&gt;If \(x^*\) is a local minimum of \(f\), then:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;First-order necessary condition&lt;/strong&gt;: \(\nabla f(x^*) = 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Second-order necessary condition&lt;/strong&gt;: \(\nabla^2 f(x^*) \succeq 0\) (positive semidefinite)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;sufficient-conditions-second-order&quot;&gt;Sufficient Conditions (Second-Order)&lt;/h3&gt;

&lt;p&gt;If at point \(x^*\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;\(\nabla f(x^*) = 0\) (first-order condition)&lt;/li&gt;
  &lt;li&gt;\(\nabla^2 f(x^*) \succ 0\) (positive definite)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then \(x^*\) is a &lt;strong&gt;strict local minimum&lt;/strong&gt; of \(f\).&lt;/p&gt;

&lt;h2 id=&quot;understanding-positive-definiteness&quot;&gt;Understanding Positive Definiteness&lt;/h2&gt;

&lt;p&gt;A symmetric matrix \(A\) is:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Positive definite&lt;/strong&gt; (\(A \succ 0\)) if \(v^T A v &amp;gt; 0\) for all \(v \neq 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Positive semidefinite&lt;/strong&gt; (\(A \succeq 0\)) if \(v^T A v \geq 0\) for all \(v\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Practical tests for positive definiteness:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Eigenvalue test&lt;/strong&gt;: All eigenvalues are positive&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Leading principal minors&lt;/strong&gt;: All leading principal minors are positive&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cholesky decomposition&lt;/strong&gt;: \(A = L L^T\) exists with \(L\) lower triangular&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;geometric-interpretation&quot;&gt;Geometric Interpretation&lt;/h2&gt;

&lt;p&gt;The second-order conditions provide information about the &lt;strong&gt;curvature&lt;/strong&gt; at the critical point:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(\nabla^2 f(x^*) \succ 0\)&lt;/strong&gt;: The function curves upward in all directions → &lt;strong&gt;strict local minimum&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\nabla^2 f(x^*) \prec 0\)&lt;/strong&gt;: The function curves downward in all directions → &lt;strong&gt;strict local maximum&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(\nabla^2 f(x^*) \succeq 0\)&lt;/strong&gt;: Non-negative curvature → &lt;strong&gt;possible minimum&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Indefinite Hessian&lt;/strong&gt;: Mixed curvature → &lt;strong&gt;saddle point&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
 &lt;img src=&quot;/img/chapter_img/chapter04/second-order-conditions.png&quot; alt=&quot;Second-order optimality conditions visualization&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
 &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Geometric interpretation of second-order conditions&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;detailed-examples&quot;&gt;Detailed Examples&lt;/h2&gt;

&lt;h3 id=&quot;example-1-quadratic-function&quot;&gt;Example 1: Quadratic Function&lt;/h3&gt;
&lt;p&gt;Consider \(f(x_1, x_2) = x_1^2 + 2x_2^2 + x_1 x_2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Find critical points&lt;/strong&gt;
\(\nabla f(x) = \begin{bmatrix} 2x_1 + x_2 \\ 4x_2 + x_1 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}\)&lt;/p&gt;

&lt;p&gt;Solving: \(x^* = (0, 0)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Compute Hessian&lt;/strong&gt;
\(\nabla^2 f(x) = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 4 \end{bmatrix}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Check positive definiteness&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Eigenvalues: \(\lambda_1 = \frac{6 + \sqrt{8}}{2} = 3 + \sqrt{2} &amp;gt; 0\), \(\lambda_2 = \frac{6 - \sqrt{8}}{2} = 3 - \sqrt{2} &amp;gt; 0\)&lt;/li&gt;
  &lt;li&gt;Leading principal minors: \(2 &amp;gt; 0\), \(\det = 8 - 1 = 7 &amp;gt; 0\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;: \(\nabla^2 f(0,0) \succ 0\) → \((0,0)\) is a strict local minimum.&lt;/p&gt;

&lt;h3 id=&quot;example-2-non-convex-function&quot;&gt;Example 2: Non-Convex Function&lt;/h3&gt;
&lt;p&gt;Consider \(f(x_1, x_2) = x_1^4 + x_2^4 - 2x_1^2 - 2x_2^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Find critical points&lt;/strong&gt;
\(\nabla f(x) = \begin{bmatrix} 4x_1^3 - 4x_1 \\ 4x_2^3 - 4x_2 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}\)&lt;/p&gt;

&lt;p&gt;Critical points: \((0,0)\), \((\pm 1, 0)\), \((0, \pm 1)\), \((\pm 1, \pm 1)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Analyze \((0,0)\)&lt;/strong&gt;
\(\nabla^2 f(0,0) = \begin{bmatrix} -4 &amp;amp; 0 \\ 0 &amp;amp; -4 \end{bmatrix} \prec 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;: \((0,0)\) is a strict local maximum.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Analyze \((1,1)\)&lt;/strong&gt;
\(\nabla^2 f(1,1) = \begin{bmatrix} 8 &amp;amp; 0 \\ 0 &amp;amp; 8 \end{bmatrix} \succ 0\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;: \((1,1)\) is a strict local minimum.&lt;/p&gt;

&lt;h3 id=&quot;example-3-saddle-point&quot;&gt;Example 3: Saddle Point&lt;/h3&gt;
&lt;p&gt;Consider \(f(x_1, x_2) = x_1^2 - x_2^2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analysis at \((0,0)\):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\nabla f(0,0) = (0,0)\) ✓&lt;/li&gt;
  &lt;li&gt;\(\nabla^2 f(0,0) = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; -2 \end{bmatrix}\) (indefinite)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;: \((0,0)\) is a saddle point (neither minimum nor maximum).&lt;/p&gt;

&lt;h2 id=&quot;constrained-optimization-second-order-conditions&quot;&gt;Constrained Optimization: Second-Order Conditions&lt;/h2&gt;

&lt;p&gt;For constrained problems:
\(\min_x f(x) \text{ subject to } h_i(x) = 0, \, i = 1,\ldots,m\)&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;bordered Hessian&lt;/strong&gt; of the Lagrangian is used:
\(\mathcal{L}(x,\lambda) = f(x) + \sum_{i=1}^m \lambda_i h_i(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second-order sufficient condition&lt;/strong&gt;: The bordered Hessian has the correct inertia (number of negative eigenvalues equals the number of constraints).&lt;/p&gt;

&lt;h2 id=&quot;comparison-first-vs-second-order-conditions&quot;&gt;Comparison: First vs Second-Order Conditions&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aspect&lt;/th&gt;
      &lt;th&gt;First-Order&lt;/th&gt;
      &lt;th&gt;Second-Order&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Information&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Gradient (slope)&lt;/td&gt;
      &lt;td&gt;Hessian (curvature)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Necessary condition&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(\nabla f(x^*) = 0\)&lt;/td&gt;
      &lt;td&gt;\(\nabla f(x^*) = 0\) and \(\nabla^2 f(x^*) \succeq 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Sufficient condition (unconstrained)&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Not sufficient for general \(f\) (sufficient if \(f\) is convex)&lt;/td&gt;
      &lt;td&gt;\(\nabla f(x^*) = 0\) and \(\nabla^2 f(x^*) \succ 0\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Strength&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Weaker&lt;/td&gt;
      &lt;td&gt;Stronger&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Computational cost&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(O(n)\)&lt;/td&gt;
      &lt;td&gt;\(O(n^2)\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Distinguishes&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Critical points&lt;/td&gt;
      &lt;td&gt;Minima, maxima, saddle points&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;interactive-visualization&quot;&gt;Interactive Visualization&lt;/h2&gt;

&lt;p&gt;Explore how second-order conditions work in practice:&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 20px 0;&quot;&gt;
    &lt;a href=&quot;../second_order_conditions_interactive.html&quot; target=&quot;_blank&quot; style=&quot;display: inline-block; padding: 12px 24px; background-color: #e74c3c; color: white; text-decoration: none; border-radius: 6px; font-weight: bold; box-shadow: 0 2px 4px rgba(0,0,0,0.2);&quot;&gt;
        🎯 Launch Second-Order Conditions Explorer
    &lt;/a&gt;
&lt;/div&gt;

&lt;p&gt;The interactive tool demonstrates:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hessian eigenvalue analysis&lt;/strong&gt; for different function types&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Visual classification&lt;/strong&gt; of critical points (minimum, maximum, saddle)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Contour plots&lt;/strong&gt; showing local curvature behavior&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step-by-step calculations&lt;/strong&gt; for second-order tests&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;the-first-order-optimality-condition-in-about-3-minutes&quot;&gt;The first-order optimality condition in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/first-order-optimality_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;∇f(x&lt;em&gt;)ᵀ(y − x&lt;/em&gt;) ≥ 0 on a triangle: checking at the vertices, the normal cone, projected gradient, a vertex solution, and the 9 stationary points of the nonconvex example.&lt;/p&gt;

&lt;h2 id=&quot;summary-and-key-takeaways&quot;&gt;Summary and Key Takeaways&lt;/h2&gt;

&lt;p&gt;Second-order optimality conditions provide &lt;strong&gt;stronger characterization&lt;/strong&gt; of optimal points:&lt;/p&gt;

&lt;h3 id=&quot;key-results&quot;&gt;&lt;strong&gt;Key Results:&lt;/strong&gt;&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Necessary conditions&lt;/strong&gt;: \(\nabla f(x^*) = 0\) and \(\nabla^2 f(x^*) \succeq 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sufficient conditions&lt;/strong&gt;: \(\nabla f(x^*) = 0\) and \(\nabla^2 f(x^*) \succ 0\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Classification power&lt;/strong&gt;: Can distinguish between minima, maxima, and saddle points&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;practical-importance&quot;&gt;&lt;strong&gt;Practical Importance:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algorithm design&lt;/strong&gt;: Foundation for Newton-type methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convexity analysis&lt;/strong&gt;: Essential for verifying convex functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robustness&lt;/strong&gt;: Stronger guarantees than first-order conditions alone&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimization theory&lt;/strong&gt;: Bridge between local and global optimality&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;computational-considerations&quot;&gt;&lt;strong&gt;Computational Considerations:&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cost&lt;/strong&gt;: \(O(n^2)\) storage and computation for Hessian&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Approximation&lt;/strong&gt;: Quasi-Newton methods reduce computational burden&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical stability&lt;/strong&gt;: Eigenvalue computations require careful implementation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding second-order conditions is essential for advanced optimization theory and the development of efficient numerical algorithms. They provide the mathematical foundation for many modern optimization methods and offer deeper insights into the structure of optimization problems.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>04-02 Convex solution sets</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_02_Convex_solution_sets/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_02_Convex_solution_sets</id>
   <content type="html">&lt;p&gt;When an optimization solver returns a solution, a natural engineering question immediately follows: &lt;em&gt;is this the only optimal answer, or is there an entire family of equally good designs?&lt;/em&gt; In nonconvex optimization, optimal solutions can be scattered like isolated islands across space. In convex optimization, however, the geometry of the optimal solution set \(X_{\mathrm{opt}}\) obeys a strict law: it is always a single connected convex region—and under strict convexity, it shrinks to at most one point.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-geometry-of-the-optimal-solution-set&quot;&gt;Key ideas: Geometry of the Optimal Solution Set&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Convexity of Sublevel Sets&lt;/strong&gt;: For any convex function \(f\) and threshold \(\alpha\), the sublevel set \(S_\alpha = \{x : f(x) \le \alpha\}\) is convex. The optimal solution set is simply the intersection of the feasible set \(C\) with the lowest non-empty sublevel set: \(X_{\mathrm{opt}} = C \cap \{x : f(x) \le f^\star\}\). Because the intersection of convex sets is convex, \(X_{\mathrm{opt}}\) is guaranteed to be convex.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Flat Valleys and Non-Unique Solutions&lt;/strong&gt;: Whenever a convex objective has flat directions aligned with the feasible set—such as a linear objective parallel to a face of a polytope, or an \(\ell_1\)-regularized regression with collinear features—any convex combination \(\theta x + (1-\theta)y\) of two minimizers stays feasible and achieves the exact same optimal value \(f^\star\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Strict Convexity and Uniqueness&lt;/strong&gt;: A function is strictly convex if \(f(\theta x + (1-\theta)y) &amp;lt; \theta f(x) + (1-\theta)f(y)\) for all \(x \neq y\) and \(\theta \in (0, 1)\). If two distinct optimal points existed, their midpoint would be feasible and have strictly lower objective value than \(f^\star\), contradicting optimality. Hence strict convexity guarantees $$&lt;/td&gt;
          &lt;td&gt;X_{\mathrm{opt}}&lt;/td&gt;
          &lt;td&gt;\le 1$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Why Uniqueness Matters in Practice&lt;/strong&gt;: In statistics and machine learning (such as Ridge vs. Lasso regression), adding a small strictly convex regularizer \(\frac{\lambda}{2}\|x\|_2^2\) turns a flat solution face into a unique minimizer, stabilizing parameter estimates and making solutions continuous with respect to data perturbations.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-comparing-a-convex-solution-face-vs-a-unique-minimizer&quot;&gt;Worked example: Comparing a Convex Solution Face vs. a Unique Minimizer&lt;/h3&gt;

&lt;p&gt;Compare two convex programs over the unit simplex \(C = \{x \in \mathbb{R}^2 : x_1 \ge 0,\; x_2 \ge 0,\; x_1 + x_2 = 1\}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Problem A (Convex, not strictly convex)&lt;/strong&gt;: \(\min_{x \in C} f_A(x) = (x_1 + x_2 - 1)^2 + 3(x_1 + x_2)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Problem B (Strictly convex)&lt;/strong&gt;: \(\min_{x \in C} f_B(x) = x_1^2 + 3x_2^2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Analyze Problem A&lt;/strong&gt;: On the simplex \(C\), every feasible point satisfies \(x_1 + x_2 = 1\). Substituting this into \(f_A\) gives \(f_A(x) = 0^2 + 3(1) = 3\) for every \(x \in C\). Therefore \(f_A^\star = 3\) and the optimal solution set is the entire line segment
\(X_{\mathrm{opt}}^A = \{(t, 1 - t) : 0 \le t \le 1\},\)
which is a convex set with infinitely many points. Notice that if you take two minimizers \(x = (1, 0)\) and \(y = (0, 1)\), their midpoint \(z = (0.5, 0.5)\) satisfies \(z \in C\) and \(f_A(z) = 3 = f_A^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Analyze Problem B&lt;/strong&gt;: The Hessian of \(f_B\) is \(\nabla^2 f_B(x) = \operatorname{diag}(2, 6) \succ 0\), so \(f_B\) is strictly convex. Substitute \(x_2 = 1 - x_1\) with \(x_1 \in [0, 1]\):
\(f_B(x_1, 1 - x_1) = x_1^2 + 3(1 - x_1)^2 = 4x_1^2 - 6x_1 + 3.\)
Setting the derivative \(8x_1 - 6 = 0\) gives \(x_1^\star = \frac{3}{4} \in [0, 1]\) and \(x_2^\star = \frac{1}{4}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify strict-convexity contradiction on any second point&lt;/strong&gt;: At \(x^\star = (\tfrac{3}{4}, \tfrac{1}{4})\), \(f_B^\star = \frac{9}{16} + 3\cdot\frac{1}{16} = \frac{12}{16} = 0.75\). Try another feasible point \(y = (\tfrac{1}{2}, \tfrac{1}{2})\): \(f_B(y) = 0.25 + 0.75 = 1.00 &amp;gt; 0.75\). Their midpoint \(z = (\tfrac{5}{8}, \tfrac{3}{8})\) gives \(f_B(z) = \frac{25 + 27}{64} = \frac{52}{64} = 0.8125 &amp;lt; \frac{0.75 + 1.00}{2} = 0.875\), illustrating the strict Jensen drop that forbids a second distinct minimizer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s understand the properties of convex solution sets. &lt;br /&gt;
Let \(X_{opt}\) denote the set of solutions to a convex problem:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
X_{opt} =
&amp;amp;\text{arg}\min_x &amp;amp;&amp;amp;f(x) \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;g_{i}(x) \leq 0, i = 1, .., m \\
&amp;amp;&amp;amp;&amp;amp;h_{j}(x) = 0, j = 1, .., r  \\\\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;h2 id=&quot;key-property-1&quot;&gt;Key property 1&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(X_{opt}\) is a convex set.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;proof&quot;&gt;Proof&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;If \(x\) and \(y\) are solutions:&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;The domain set \(D\) is convex, so for \(0 \le t \le 1\), \(tx+ (1-t)y \in D\).&lt;/li&gt;
    &lt;li&gt;\(g_i, i=1,\dotsc,m\) and \(h_j, j=1, \dotsc,r\) are convex and affine functions, so the following conditions hold:
 \(\begin{aligned}
    g_{i}(tx + (1-t)y) \leq tg_i(x) + (1-t)g_i(y) \leq 0, \\
    h_{j}(tx + (1-t)y) = th_j(x) + (1-t)h_j(y) = 0 \\
 \end{aligned}\)&lt;/li&gt;
    &lt;li&gt;\(f\) is a convex function, so:
      &lt;blockquote&gt;

        &lt;p&gt;\begin{aligned}
 f(tx+(1-t)y) &amp;amp;\leq tf(x) + (1-t)f(y) &lt;br /&gt;
 = tf^{\star} + (1-t) f^{\star} &lt;br /&gt;
 = f^{\star}
\end{aligned}
where \(f^{\star} -\) minimum value.
Thus, \(tx + (1-t)y\) is also a solution.&lt;/p&gt;
      &lt;/blockquote&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;geometric-interpretation&quot;&gt;Geometric interpretation&lt;/h3&gt;
&lt;p&gt;In a convex function, any local optimum is also a global optimum. &lt;br /&gt;
If the solution set contains multiple elements, it must look like the following:&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter04/multiple-optima.png&quot; alt=&quot;[Fig1] geometric interpretation of convexity of the solution set&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] geometric interpretation of convexity of the solution set&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;key-property-2&quot;&gt;Key property 2&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;If \(f\) is strictly convex, then the solution is unique. That is, \(X_{opt}\) contains only one element.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;\(f\) being strictly convex means that \(f\) always satisfies the following property:&lt;/p&gt;
&lt;blockquote&gt;
\[f(tx + (1-t)y) &amp;lt; tf(x) + (1-t)f(y),\]

\[\text{where } 0 &amp;lt; t &amp;lt; 1, x \neq y, \text{ and } x, y \in \text{dom } f.\]
&lt;/blockquote&gt;

&lt;p&gt;That is, \(f\) is downward convex with no flat segments, and the solution of \(f\) is unique.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>04-01 Basic terminology</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_01_Basic_terminology/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_01_Basic_terminology</id>
   <content type="html">&lt;p&gt;Before a pilot can fly by instruments, every dial on the cockpit panel needs an unambiguous name. In convex optimization, confusing the &lt;em&gt;domain&lt;/em&gt; with the &lt;em&gt;feasible set&lt;/em&gt;, or an &lt;em&gt;optimal value&lt;/em&gt; with an &lt;em&gt;optimal point&lt;/em&gt;, leads directly to broken proofs and silent modeling bugs. This lesson builds the exact vocabulary—feasible points, optimal values, active constraints, and local versus global minimizers—that every subsequent theorem in convex analysis relies on.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-core-vocabulary-of-convex-programs&quot;&gt;Key ideas: Core Vocabulary of Convex Programs&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Implicit Domain vs. Feasible Set&lt;/strong&gt;: Every problem starts with the implicit intersection of function domains \(D = \operatorname{dom}(f) \cap \bigcap_i \operatorname{dom}(g_i) \cap \bigcap_j \operatorname{dom}(h_j)\). The &lt;em&gt;feasible set&lt;/em&gt; \(C \subseteq D\) further filters \(D\) to points satisfying all inequalities \(g_i(x) \le 0\) and affine equalities \(h_j(x) = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimal Value \(f^\star\) vs. Optimal Points \(x^\star\)&lt;/strong&gt;: The optimal value \(f^\star = \inf_{x \in C} f(x)\) always exists in \(\mathbb{R} \cup \{-\infty, +\infty\}\) (with \(+\infty\) for infeasible problems and \(-\infty\) for unbounded-below problems). However, an &lt;em&gt;attaining&lt;/em&gt; optimal point \(x^\star \in C\) with \(f(x^\star) = f^\star\) need not exist—for example, minimizing \(e^{-x}\) over \(\mathbb{R}\) has \(f^\star = 0\) with no finite minimizer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Active vs. Inactive Inequality Constraints&lt;/strong&gt;: At a feasible point \(x\), an inequality \(g_i(x) \le 0\) is &lt;em&gt;active&lt;/em&gt; (binding) if \(g_i(x) = 0\) and &lt;em&gt;inactive&lt;/em&gt; (strictly satisfied) if \(g_i(x) &amp;lt; 0\). Active constraints are the walls you are actually pressed against at the optimum; inactive constraints can be locally ignored without moving \(x^\star\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Local vs. Global Optimality under Convexity&lt;/strong&gt;: A point \(x\) is locally optimal if it minimizes \(f\) inside some ball \(\|y - x\|_2 \le R\) intersected with \(C\). Because every line segment connecting a local minimizer to a strictly better feasible point stays inside \(C\) and has objective values bounded by convexity, any local minimizer of a convex problem is automatically globally optimal.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-dissecting-domain-feasibility-and-active-constraints&quot;&gt;Worked example: Dissecting Domain, Feasibility, and Active Constraints&lt;/h3&gt;

&lt;p&gt;Consider the one-dimensional convex optimization problem:
\(\text{minimize} \quad f(x) = -\ln(x) + \frac{1}{2}x^2 \quad \text{subject to} \quad g_1(x) = x - 2 \le 0, \quad g_2(x) = \frac{1}{2} - x \le 0.\)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify the implicit domain \(D\)&lt;/strong&gt;: The logarithm requires \(x &amp;gt; 0\), while \(x^2\) and both constraints are defined on all of \(\mathbb{R}\). Therefore \(D = (0, +\infty)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Determine the feasible set \(C\)&lt;/strong&gt;: Constraint \(g_1(x) \le 0\) gives \(x \le 2\), and constraint \(g_2(x) \le 0\) gives \(x \ge \frac{1}{2}\). Intersecting with \(D\) yields the closed interval \(C = [\tfrac{1}{2}, 2]\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify convexity and locate the unconstrained minimizer&lt;/strong&gt;: On \(D\), \(f&apos;(x) = -\frac{1}{x} + x\) and \(f&apos;&apos;(x) = \frac{1}{x^2} + 1 &amp;gt; 0\), so \(f\) is strictly convex. Setting \(f&apos;(x) = 0\) gives \(x = \frac{1}{x} \implies x^2 = 1\). Since \(x \in D = (0, \infty)\), the unique unconstrained minimizer is \(x^\star = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check feasibility, optimal value, and active constraints&lt;/strong&gt;: Since \(1 \in [\tfrac{1}{2}, 2]\), \(x^\star = 1\) is feasible and achieves the global optimal value \(f^\star = -\ln(1) + \frac{1}{2}(1)^2 = 0.5\). Evaluating the constraints at \(x^\star = 1\) gives \(g_1(1) = 1 - 2 = -1 &amp;lt; 0\) and \(g_2(1) = \frac{1}{2} - 1 = -0.5 &amp;lt; 0\), so &lt;strong&gt;both inequality constraints are inactive&lt;/strong&gt; at the optimum.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Contrast with a shifted constraint&lt;/strong&gt;: If we tighten \(g_1\) to \(g_1(x) = x - 0.8 \le 0\), then \(x = 1\) becomes infeasible. Because \(f&apos;(x) = x - 1/x &amp;lt; 0\) on \([0.5, 0.8]\), \(f\) is strictly decreasing on the feasible interval, so the new optimum is \(x^\star = 0.8\) with \(g_1(0.8) = 0\) (&lt;strong&gt;active&lt;/strong&gt;) and \(g_2(0.8) = -0.3 &amp;lt; 0\) (&lt;strong&gt;inactive&lt;/strong&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;convex-optimization-basics&quot;&gt;Convex Optimization Basics&lt;/h2&gt;

&lt;p&gt;Let’s review the basic terminology used in convex optimization problems. A convex optimization problem is defined as:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\text{minimize}_{x \in D} &amp;amp;&amp;amp;{f(x)} \\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;{g_{i}(x) \leq 0, \quad i = 1, \dotsc, m} \\
&amp;amp;&amp;amp;&amp;amp;{h_{j}(x) = 0, \quad j = 1, \dotsc, r},\\\\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;where \(f\) and \(g_{i}\), \(i=1,\dotsc, m\) are all convex,
\(h_j, j = 1, \dotsc, r\) are all affine,
and the optimization domain is \(D = dom(f) \cap \bigcap_{i=1}^{m} dom(g_{i}) \cap  \bigcap_{j=1}^r dom(h_{j})\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;\(f\) is called the &lt;strong&gt;criterion&lt;/strong&gt; or &lt;strong&gt;objective function&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;\(g_{i}(x)\) is called the &lt;strong&gt;inequality constraint function&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;\(h_{j}(x)\) is called the &lt;strong&gt;equality constraint function&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;If \(x \in D\) and \(g_{i}(x) \leq 0\) for all \(i\) and \(h_{j}(x) = 0\) for all \(j\), then \(x\) is a &lt;strong&gt;feasible point&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;For all feasible points \(x\), the minimum value of \(f(x)\) is called the &lt;strong&gt;optimal value&lt;/strong&gt;, denoted as \(f^{\star}\).&lt;/li&gt;
  &lt;li&gt;If \(x\) is feasible and \(f(x) = f^{\star}\), then \(x\) is called &lt;strong&gt;optimal&lt;/strong&gt;, a &lt;strong&gt;solution&lt;/strong&gt;, or a &lt;strong&gt;minimizer&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;If \(x\) is feasible and \(f(x) \le f^{\star} + \epsilon\), then \(x\) is called &lt;strong&gt;\(\epsilon\)-suboptimal&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;If \(x\) is feasible and \(g_i(x) = 0\), then \(g_i\) is &lt;strong&gt;active&lt;/strong&gt; at \(x\).&lt;/li&gt;
  &lt;li&gt;A convex minimization problem can be converted to a concave maximization problem.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\begin{aligned}
&amp;amp;\text{maximize}_{x \in D} &amp;amp;&amp;amp;-f(x)\\
&amp;amp;\text{subject to} &amp;amp;&amp;amp;g_{i}(x) \leq 0, i = 1, .., m\\
&amp;amp;&amp;amp;&amp;amp;h_{j}(x) = 0, j = 1, \dotsc, r,\\\\
\end{aligned}\]
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;where \(f\) and \(g_{i}\), \(i=1,\dotsc, m\) are all convex,
\(h_j, j = 1, \dotsc, r\) are all affine,
and the optimization domain is \(D = dom(f) \cap \bigcap_{i=1}^{m} dom(g_{i}) \cap  \bigcap_{j=1}^r dom(h_{j})\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;feasible-set&quot;&gt;Feasible Set&lt;/h3&gt;

&lt;p&gt;A feasible set (also known as a feasible region or solution space) is the set of all feasible points. It represents all the choices that are allowed by the problem’s conditions.&lt;/p&gt;

&lt;p&gt;The feasible set, often denoted by \(S\) or \(\mathcal{F}\), is defined as:&lt;/p&gt;

&lt;blockquote&gt;
\[S = \{ \mathbf{x} \in X \mid g_i(\mathbf{x}) \le 0 \text{ for all } i=1, \dots, m, \text{ and } h_j(\mathbf{x}) = 0 \text{ for all } j=1, \dots, r \}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;properties-of-feasible-sets&quot;&gt;Properties of Feasible Sets&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Convexity:&lt;/strong&gt; If all inequality constraint functions $g_i(\mathbf{x})$ are convex and all equality constraint functions $h_j(\mathbf{x})$ are affine (linear), then the feasible set $S$ is a &lt;strong&gt;convex set&lt;/strong&gt;. This property is crucial in convex optimization, as it guarantees that any local optimum is also a global optimum.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Boundedness:&lt;/strong&gt; A feasible set can be &lt;strong&gt;bounded&lt;/strong&gt; (enclosed within a finite region) or &lt;strong&gt;unbounded&lt;/strong&gt; (extending infinitely in some direction).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Empty Set:&lt;/strong&gt; It is possible for the feasible set to be empty ($S = \emptyset$). This means there are no points that satisfy all the given constraints, and the optimization problem is said to be &lt;strong&gt;infeasible&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polytope/Polyhedron&lt;/strong&gt; (&lt;strong&gt;Đa hình / Đa diện&lt;/strong&gt;): In linear programming, if the feasible set is non-empty and bounded, it is called a &lt;strong&gt;polytope&lt;/strong&gt;. If it is non-empty but potentially unbounded, it is called a &lt;strong&gt;polyhedron&lt;/strong&gt;. Both are convex sets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vertices (Extreme Points):&lt;/strong&gt; For linear programming problems, if an optimal solution exists, it can always be found at one of the vertices (also known as extreme points or corner points) of the feasible set. This is the basis for algorithms like the Simplex method.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>04 Convex optimization basics</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_00_Convex_optimization_basics/"/>
   <updated>2020-02-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter04/04_00_Convex_optimization_basics</id>
   <content type="html">&lt;p&gt;Imagine standing on a foggy mountain range where every valley might be a false bottom—that is general nonlinear optimization. Now imagine the fog lifts and reveals a single, giant smooth bowl: any step downhill eventually leads to the true lowest point on Earth. Chapter 04 formalizes the exact mathematical contract that turns messy engineering and machine-learning problems into that single-bowl world, and shows the legal algebraic moves that preserve it.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-architecture-of-a-convex-program&quot;&gt;Key ideas: Architecture of a Convex Program&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Standard-Form Modeling (Objective, Inequalities, and Affine Equalities)&lt;/strong&gt;: A convex program minimizes a convex objective \(f\) over a domain \(D\) subject to convex inequalities \(g_i(x) \le 0\) and &lt;em&gt;affine&lt;/em&gt; equalities \(h_j(x) = a_j^T x - b_j = 0\). Requiring equalities to be affine ensures the feasible set stays convex—bending an equality constraint into a curve immediately destroys convexity of the slice.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Global Optimality and Geometry of Solutions&lt;/strong&gt;: In a convex program, every local minimum is automatically a global minimum, and the set of all optimal solutions \(X_{\mathrm{opt}}\) is itself a convex set. When the objective is strictly convex, the solution collapses to a unique point.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;First-Order Variational Optimality&lt;/strong&gt;: At a minimizer \(x^\star\) on a convex feasible set \(C\), moving toward any other feasible point \(y \in C\) cannot decrease the objective to first order: \(\nabla f(x^\star)^T (y - x^\star) \ge 0\). Geometrically, \(-\nabla f(x^\star)\) lies in the normal cone \(N_C(x^\star)\), a unifying condition that also powers modern differentiable optimization layers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convexity-Preserving Reformulations&lt;/strong&gt;: Real-world models rarely arrive in textbook standard form. Partial minimization, monotone objective transformations, invertible changes of variables, equality elimination, slack variables, and convex relaxations let you reshape a problem into an equivalent—or tightly bounding—convex program without breaking its global-optimality guarantee.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;worked-example-certifying-and-solving-a-constrained-convex-program&quot;&gt;Worked example: Certifying and Solving a Constrained Convex Program&lt;/h3&gt;

&lt;p&gt;Consider minimizing the quadratic objective \(f(x_1, x_2) = (x_1 - 3)^2 + (x_2 - 1)^2\) subject to the halfspace constraint \(g_1(x) = x_1 + x_2 - 2 \le 0\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check convexity of the formulation&lt;/strong&gt;: The Hessian of \(f\) is \(\nabla^2 f(x) = 2I \succ 0\), so \(f\) is strictly convex. The inequality constraint \(g_1(x) = x_1 + x_2 - 2\) is affine (hence convex), so the feasible set \(C = \{x \in \mathbb{R}^2 : x_1 + x_2 \le 2\}\) is convex and the solution is guaranteed to be unique.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the unconstrained minimizer&lt;/strong&gt;: Setting \(\nabla f(x) = (2(x_1 - 3), 2(x_2 - 1)) = (0, 0)\) yields \(x_{\mathrm{unc}} = (3, 1)\). Checking feasibility gives \(g_1(3, 1) = 3 + 1 - 2 = 2 &amp;gt; 0\), so \(x_{\mathrm{unc}}\) is infeasible and the optimum must lie on the boundary \(x_1 + x_2 = 2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Project onto the boundary&lt;/strong&gt;: Substitute \(x_2 = 2 - x_1\) into \(f\):
\(f(x_1, 2 - x_1) = (x_1 - 3)^2 + (1 - x_1)^2 = (x_1^2 - 6x_1 + 9) + (x_1^2 - 2x_1 + 1) = 2x_1^2 - 8x_1 + 10.\)
Setting the derivative \(4x_1 - 8 = 0\) gives \(x_1^\star = 2\), and hence \(x_2^\star = 2 - 2 = 0\). The optimal value is \(f^\star = (2 - 3)^2 + (0 - 1)^2 = 1 + 1 = 2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify the first-order optimality condition&lt;/strong&gt;: At \(x^\star = (2, 0)\), the gradient is \(\nabla f(x^\star) = (2(2-3), 2(0-1)) = (-2, -2)\). For any feasible \(y = (y_1, y_2)\) with \(y_1 + y_2 \le 2\),
\(\nabla f(x^\star)^T (y - x^\star) = -2(y_1 - 2) - 2(y_2 - 0) = 2\bigl(2 - (y_1 + y_2)\bigr) \ge 0.\)
Thus \(x^\star = (2, 0)\) is certified as the unique global minimizer.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;convex-optimization-basics&quot;&gt;Convex Optimization Basics&lt;/h2&gt;

&lt;p&gt;This chapter introduces the main properties of convex problems and several techniques commonly used in solving them.&lt;/p&gt;

&lt;p&gt;The optional &lt;a href=&quot;/contents/en/chapter04/04_09_Applications_Recent/&quot;&gt;04-09 Applications and recent developments&lt;/a&gt; shows how those optimality residuals become differentiable layers (cvxpylayers, Theseus) and convex decision surrogates.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Phương pháp gradient gần kề và tăng tốc</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_proximal_gradient_descent_and_acceleration/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_proximal_gradient_descent_and_acceleration</id>
   <content type="html">&lt;p&gt;Ở cuối Chương 08, ta từng chạm phải một bức tường cứng: phương pháp subgradient giải được mọi hàm lồi không trơn, nhưng phải trả giá bằng tốc độ chậm chạp \(O(1/\epsilon^2)\). Câu hỏi đặt ra cho Chương 09 là: nếu bài toán thực tế không “gấp khúc hỗn loạn ở mọi nơi”, mà là sự kết hợp gọn gàng giữa một phần &lt;strong&gt;trơn mượt&lt;/strong&gt; \(g(x)\) (như sai số bình phương hay log-loss) và một phần &lt;strong&gt;không trơn nhưng có cấu trúc đơn giản&lt;/strong&gt; \(h(x)\) (như chuẩn \(\ell_1\), chuẩn hạt nhân hay hàm chỉ thị tập lồi), ta có thể làm nhanh hơn bao nhiêu?&lt;/p&gt;

&lt;p&gt;Câu trả lời làm thay đổi hoàn toàn bộ mặt của tối ưu hóa quy mô lớn và xử lý tín hiệu hiện đại: bằng cách tách riêng hai phần trong &lt;strong&gt;phương pháp gradient gần kề (Proximal Gradient Descent)&lt;/strong&gt;, ta lập tức kéo tốc độ từ \(O(1/\epsilon^2)\) lên \(O(1/\epsilon)\) — ngang hàng với gradient descent trên hàm trơn! Và chưa dừng lại ở đó, khi gắn thêm “động cơ quán tính” &lt;strong&gt;tăng tốc Nesterov / FISTA&lt;/strong&gt;, tốc độ vọt thẳng lên \(O(1/\sqrt{\epsilon})\), đạt chuẩn tối ưu bậc nhất của lý thuyết tối ưu lồi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-tối-ưu-gần-kề-và-tăng-tốc&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của tối ưu gần kề và tăng tốc&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình tối ưu tổng hợp (Composite Optimization):&lt;/strong&gt; Phân tách hàm mục tiêu thành \(f(x) = g(x) + h(x)\), trong đó \(g\) lồi khả vi với \(\nabla g\) liên tục \(L\)-Lipschitz, còn \(h\) lồi (có thể không khả vi, thậm chí nhận giá trị \(+\infty\) để mã hóa ràng buộc) nhưng “dễ giải” qua toán tử gần kề.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Toán tử gần kề (Proximal Operator):&lt;/strong&gt; Định nghĩa \(\operatorname{prox}_{t h}(v) = \arg\min_z \left\{\frac{1}{2t}\|z - v\|_2^2 + h(z)\right\}\) — tìm một điểm dung hòa giữa việc giữ gần điểm \(v\) và làm nhỏ \(h(z)\). Đây là tổng quát hóa tự nhiên của phép chiếu Euclid lên tập lồi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khôi phục tốc độ \(O(1/k)\) và tính chất tạo thưa chính xác:&lt;/strong&gt; Nhờ giữ nguyên \(h(x)\) thay vì xấp xỉ tuyến tính nó, mỗi vòng lặp vừa đạt tốc độ \(O(1/k)\) (tương đương \(O(1/\epsilon)\)), vừa đưa thẳng các tọa độ nhỏ về &lt;strong&gt;đúng bằng \(0\)&lt;/strong&gt; (không dao động quanh \(0\) như subgradient).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tăng tốc Nesterov (FISTA):&lt;/strong&gt; Thay vì tính gradient tại điểm cũ \(x^{(k)}\), ta ngoại suy thêm một bước quán tính tới \(y^{(k)} = x^{(k)} + \beta_k(x^{(k)} - x^{(k-1)})\) rồi mới áp dụng bước gần kề, nâng tốc độ từ \(O(1/k)\) lên \(O(1/k^2)\) (tức \(O(1/\sqrt{\epsilon})\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-so-sánh-tốc-độ-hội-tụ-của-3-thế-hệ-thuật-toán-trên-cùng-một-bài-toán&quot;&gt;Giải thích: So sánh tốc độ hội tụ của 3 thế hệ thuật toán trên cùng một bài toán&lt;/h3&gt;

&lt;p&gt;Giả sử ta cần giải bài toán Lasso \(f(x) = \frac{1}{2}\|Ax - b\|_2^2 + \lambda\|x\|_1\) đến độ chính xác \(\epsilon = 10^{-4}\) (với các hằng số bài toán đều chuẩn hóa bằng \(1\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thế hệ 1 — Phương pháp Subgradient (Chương 08):&lt;/strong&gt; Tốc độ \(O(1/\epsilon^2)\).
Để đạt \(\epsilon = 10^{-4}\), số vòng lặp cỡ \((10^4)^2 = 100{,}000{,}000\) bước — gần như bất khả thi với dữ liệu lớn!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thế hệ 2 — Proximal Gradient / ISTA (Chương 09, phần đầu):&lt;/strong&gt; Tốc độ \(O(1/\epsilon)\).
Số vòng lặp giảm mạnh xuống cỡ \(10^4 = 10{,}000\) bước — nhanh hơn &lt;strong&gt;10,000 lần&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thế hệ 3 — Accelerated Proximal Gradient / FISTA (Chương 09, phần sau):&lt;/strong&gt; Tốc độ \(O(1/\sqrt{\epsilon})\).
Số vòng lặp chỉ còn cỡ \(\sqrt{10^4} = 100\) bước — nhanh hơn ISTA thêm &lt;strong&gt;100 lần&lt;/strong&gt;, và nhanh hơn subgradient đúng &lt;strong&gt;1 triệu lần&lt;/strong&gt;!
Chỉ bằng cách tôn trọng cấu trúc \(g + h\) và thêm một dòng quán tính Nesterov, cùng một bài toán đã biến từ “bất khả thi” thành chạy xong trong tích tắc.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;phương-pháp-gradient-gần-kề-và-tăng-tốc&quot;&gt;Phương pháp gradient gần kề và tăng tốc&lt;/h1&gt;

&lt;p&gt;Chương này giới thiệu phương pháp gradient gần kề (proximal gradient descent) cùng các kỹ thuật tăng tốc cho các bài toán tối ưu có hàm mục tiêu dạng tổng hợp.&lt;/p&gt;

&lt;h2 id=&quot;tổng-quan&quot;&gt;Tổng quan&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Phương pháp gradient gần kề được dùng cho các bài toán mà hàm mục tiêu có thể tách thành một phần khả vi và một phần không khả vi.&lt;/li&gt;
  &lt;li&gt;Các kỹ thuật tăng tốc như tăng tốc Nesterov và FISTA giúp cải thiện đáng kể tốc độ hội tụ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;cấu-trúc-chương&quot;&gt;Cấu trúc chương&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Phần 1: Phương pháp gradient gần kề&lt;/li&gt;
  &lt;li&gt;Phần 2: Phân tích hội tụ&lt;/li&gt;
  &lt;li&gt;Phần 3: Ví dụ về hoàn thiện ma trận&lt;/li&gt;
  &lt;li&gt;Phần 4: Các trường hợp đặc biệt&lt;/li&gt;
  &lt;li&gt;Phần 5: Các phương pháp tăng tốc — bắt đầu từ góc nhìn trực quan kiểu Distill ở &lt;a href=&quot;/contents/vi/chapter09/09_05_acceleration/&quot;&gt;09-05&lt;/a&gt;, tiếp theo là phần trình bày giải tích về FISTA ở 09-05-01; biến thể ngẫu nhiên với hệ số \(\beta\) cố định được trình bày tại &lt;a href=&quot;/contents/vi/chapter26/26_02_momentum_and_nesterov/&quot;&gt;26-02&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tham khảo từng bài học dưới đây để xem chi tiết thuật toán và phân tích toán học.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-hiện-đại-20222026&quot;&gt;Ứng dụng hiện đại (2022–2026)&lt;/h2&gt;

&lt;p&gt;Bài đọc tùy chọn đi kèm nối tiếp khuôn mẫu proximal gradient / FISTA sang các ứng dụng như tái tạo ảnh plug-and-play (PnP), trải phẳng thuật toán (unrolling) trong FISTA-Net / pFISTA-DR, và đường chính quy hóa elastic net trong thực tế. Xem &lt;a href=&quot;/contents/vi/chapter09/09_06_modern_applications/&quot;&gt;09-06 Ứng dụng hiện đại của proximal GD và tăng tốc&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>09-11 Bài Tập Thực Hành - Proximal Gradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_11_Practical_Exercises_Proximal_Gradient/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_11_Practical_Exercises_Proximal_Gradient</id>
   <content type="html">&lt;p&gt;Sức mạnh thực sự của phương pháp gradient gần kề nằm ở “từ điển toán tử gần kề”: chỉ cần biết cách tính \(\operatorname{prox}_{t h}(v)\) cho một hàm không trơn mới — dù là chuẩn \(\ell_1\), chuẩn hạt nhân ma trận, chuẩn \(\ell_2\) không bình phương (Group Lasso), hay hàm chỉ thị của đơn hình xác suất — là bạn lập tức có ngay một bộ giải tốc độ \(O(1/k^2)\) bằng FISTA!&lt;/p&gt;

&lt;p&gt;Năm bài tập thực hành dưới đây đưa bạn đi qua trọn bộ kỹ năng triển khai đó: từ lập trình ISTA và FISTA cho Lasso, giải bài toán hoàn thiện ma trận bằng SVD, tự tay suy ra các công thức prox cơ bản (bao gồm đồng nhất thức Moreau tuyệt đẹp!), cho đến kết hợp gradient gần kề với bài toán đối ngẫu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-công-cụ-giải-tích-cần-thiết-cho-bộ-bài-tập-thực-hành&quot;&gt;Kiến thức cần nhớ: Bốn công cụ giải tích cần thiết cho bộ bài tập thực hành&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện tối ưu của bài toán con prox:&lt;/strong&gt; Điểm \(u = \operatorname{prox}_{t h}(v)\) được đặc trưng duy nhất bởi quan hệ bao hàm dưới vi phân:
\(0 \in \frac{1}{t}(u - v) + \partial h(u) \;\Longleftrightarrow\; \frac{v - u}{t} \in \partial h(u).\)
Đây là công cụ nhanh nhất để tự chứng minh mọi công thức prox đóng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý phân rã Moreau (Moreau Decomposition):&lt;/strong&gt; Với mọi hàm lồi đóng chính quy \(h\) và hàm liên hợp lồi \(h^*\) của nó:
\(v = \operatorname{prox}_h(v) + \operatorname{prox}_{h^*}(v).\)
Định lý này giống như phép phân tích trực giao \(v = P_S(v) + P_{S^\perp}(v)\) tổng quát hóa sang hàm lồi! Nhờ nó, nếu bạn biết phép chiếu lên quả cầu \(\ell_\infty\) (prox của \(h^* = I_{B_\infty}\)), bạn suy ngay ra co ngưỡng mềm (prox của \(h = \|\cdot\|_1\)) bằng một phép trừ duy nhất!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc biến đổi affine và tách biến (Separable Sum Rule):&lt;/strong&gt; Nếu \(h(x) = \sum_{j=1}^n h_j(x_j)\), toán tử prox tách độc lập theo từng tọa độ \(j\). Với chuẩn \(\ell_2\) không bình phương \(\lambda\|x\|_2\) (không tách biến), ta vẫn có công thức đóng gọi là &lt;em&gt;co ngưỡng khối&lt;/em&gt; (block soft-thresholding): \(\left(1 - \frac{t\lambda}{\|v\|_2}\right)_+ v\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tiêu chuẩn dừng thực hành:&lt;/strong&gt; Thay vì chỉ dừng theo số vòng lặp, ta thường kiểm tra chuẩn độ dốc tổng quát \(\|G_t(x^{(k)})\|_2 = \frac{1}{t}\|x^{(k)} - x^{(k+1)}\|_2 \le \text{tol}\) hoặc khoảng cách đối ngẫu (duality gap).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tay-định-lý-phân-rã-moreau-cho-hx--x&quot;&gt;Giải thích: Kiểm chứng tay định lý phân rã Moreau cho \(h(x) = |x|\)&lt;/h3&gt;

&lt;p&gt;Với \(h(x) = |x|\) trên \(\mathbb{R}\), hàm liên hợp lồi là hàm chỉ thị đoạn \([-1, 1]\):
\(h^*(y) = \sup_x (xy - |x|) = I_{[-1, 1]}(y) = \begin{cases} 0 &amp;amp; \text{nếu } |y| \le 1, \\ +\infty &amp;amp; \text{nếu } |y| &amp;gt; 1. \end{cases}\)
Do đó \(\operatorname{prox}_h(v) = S_1(v)\) (co ngưỡng mềm ngưỡng \(1\)) và \(\operatorname{prox}_{h^*}(v) = P_{[-1, 1]}(v) = \operatorname{clip}(v, -1, 1)\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm thử với \(v = 2.7\) (ngoài đoạn \([-1, 1]\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\operatorname{prox}_h(2.7) = S_1(2.7) = 2.7 - 1 = 1.7\).&lt;/li&gt;
      &lt;li&gt;\(\operatorname{prox}_{h^*}(2.7) = \operatorname{clip}(2.7, -1, 1) = 1.0\).&lt;/li&gt;
      &lt;li&gt;Cộng lại: \(1.7 + 1.0 = 2.7 = v\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm thử với \(v = -0.6\) (trong đoạn \([-1, 1]\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\operatorname{prox}_h(-0.6) = S_1(-0.6) = 0\).&lt;/li&gt;
      &lt;li&gt;\(\operatorname{prox}_{h^*}(-0.6) = \operatorname{clip}(-0.6, -1, 1) = -0.6\).&lt;/li&gt;
      &lt;li&gt;Cộng lại: \(0 + (-0.6) = -0.6 = v\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ứng dụng ngay cho Bài tập 4:&lt;/strong&gt; Tương tự, với \(h(x) = \|x\|_2\), hàm liên hợp là \(I_{B_2(1)}\), nên chỉ cần trừ đi hình chiếu lên quả cầu đơn vị \(\ell_2\) là bạn có ngay công thức \(\operatorname{prox}_{\|\cdot\|_2}(v) = v - P_{B_2(1)}(v) = \left(1 - \frac{1}{\|v\|_2}\right)_+ v\) mà không cần giải đạo hàm phức tạp!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;bài-tập-thực-hành---proximal-gradient&quot;&gt;Bài Tập Thực Hành - Proximal Gradient&lt;/h1&gt;

&lt;p&gt;Các bài tập được tham khảo từ Parikh &amp;amp; Boyd (2014) và Beck &amp;amp; Teboulle (2009).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-1-bài-toán-lasso-với-toán-tử-ngưỡng-mềm&quot;&gt;📝 &lt;strong&gt;Bài tập 1: Bài toán LASSO với toán tử ngưỡng mềm&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho bài toán LASSO: \(\min \frac{1}{2}\|Ax - b\|^2 + \lambda\|x\|_1\) với \(A = I\), \(b = (2, -1, 0.5)^T\), \(\lambda = 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Viết toán tử gần kề (proximal operator).&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Áp dụng toán tử ngưỡng mềm (soft-thresholding).&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Thực hiện bước lặp xuất phát từ \(x^{(0)} = 0\).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**Toán tử gần kề:**

$$\text{prox}_{t\lambda\|\cdot\|_1}(y) = S_{t\lambda}(y)$$

**Toán tử ngưỡng mềm:**

$$S_{\tau}(y_i) = \begin{cases}
y_i - \tau &amp;amp; \text{nếu } y_i &amp;gt; \tau \\
0 &amp;amp; \text{nếu } |y_i| \leq \tau \\
y_i + \tau &amp;amp; \text{nếu } y_i &amp;lt; -\tau
\end{cases}$$

**Với $$A = I$$ (hằng số Lipschitz $$L = 1$$, chọn kích thước bước $$t = 1$$):**

$$x^{(1)} = S_1(b) = (1, 0, 0)^T$$

Thuật toán hội tụ chỉ sau 1 bước.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-2-hoàn-thiện-ma-trận-matrix-completion&quot;&gt;📝 &lt;strong&gt;Bài tập 2: Hoàn thiện ma trận (Matrix Completion)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cực tiểu hóa \(\|X\|_*\) với ràng buộc \(X_{ij} = M_{ij}\) tại các vị trí quan sát được.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Viết bước lặp gradient gần kề cho phiên bản chính quy hóa với \(f(X) = \frac{1}{2}\|P_\Omega(X - M)\|_F^2\).&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Tính toán tử gần kề của chuẩn hạt nhân (nuclear norm).&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Áp dụng ngưỡng mềm theo phân tích SVD.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**Toán tử gần kề của chuẩn hạt nhân:**

$$\text{prox}_{t\|\cdot\|_*}(Y) = U S_t(\Sigma) V^T$$

trong đó $$Y = U\Sigma V^T$$ là phân tích SVD của $$Y$$ và $$S_t(\sigma_i) = \max(\sigma_i - t, 0)$$.

**Công thức cập nhật:**

$$X^{(k+1)} = \text{prox}_{t\|\cdot\|_*}(X^{(k)} - t\nabla f(X^{(k)}))$$

với $$\nabla f(X) = P_\Omega(X - M)$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-3-gradient-gần-kề-tăng-tốc-fista&quot;&gt;📝 &lt;strong&gt;Bài tập 3: Gradient gần kề tăng tốc (FISTA)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho bài toán tổng hợp \(f(x) + g(x)\) với \(f\) trơn và \(g\) không trơn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Viết công thức cập nhật của FISTA.&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; So sánh tốc độ hội tụ với phương pháp gradient gần kề tiêu chuẩn.&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Nêu cách áp dụng cho bài toán LASSO.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**Công thức cập nhật FISTA:**

$$
\begin{align}
y^{(k)} &amp;amp;= x^{(k)} + \frac{k-1}{k+2}(x^{(k)} - x^{(k-1)}) \\
x^{(k+1)} &amp;amp;= \text{prox}_{tg}(y^{(k)} - t\nabla f(y^{(k)}))
\end{align}
$$

**So sánh tốc độ hội tụ:**
- Gradient gần kề tiêu chuẩn: $$O(1/k)$$ (cần $$O(1/\epsilon)$$ bước để đạt sai số $$\epsilon$$).
- FISTA: $$O(1/k^2)$$ (chỉ cần $$O(1/\sqrt{\epsilon})$$ bước để đạt sai số $$\epsilon$$).

Với bài toán LASSO, ta thay $$\nabla f(y) = A^T(Ay - b)$$ và $$\text{prox}_{tg}$$ bằng toán tử ngưỡng mềm $$S_{t\lambda}$$.

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-4-tính-các-toán-tử-gần-kề-cơ-bản&quot;&gt;📝 &lt;strong&gt;Bài tập 4: Tính các toán tử gần kề cơ bản&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Tính toán tử gần kề cho các hàm sau:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; \(g(x) = \|x\|_2\)&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; \(g(x) = I_C(x)\) (hàm chỉ thị của tập lồi đóng \(C\))&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; \(g(x) = \frac{1}{2}x^TQx\) (với \(Q\) đối xứng nửa xác định dương)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**a) Chuẩn $$\ell_2$$:**

$$\text{prox}_{t\|\cdot\|_2}(y) = \begin{cases}
\left(1 - \frac{t}{\|y\|}\right)y &amp;amp; \text{nếu } \|y\| &amp;gt; t \\
0 &amp;amp; \text{trường hợp khác}
\end{cases}$$

**b) Hàm chỉ thị:**

$$\text{prox}_{tI_C}(y) = \Pi_C(y)$$ (phép chiếu Euclid lên tập $$C$$).

**c) Hàm bậc hai:**

$$\text{prox}_{tg}(y) = (I + tQ)^{-1}y$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-bài-tập-5-gradient-gần-kề-đối-ngẫu&quot;&gt;📝 &lt;strong&gt;Bài tập 5: Gradient gần kề đối ngẫu&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Cho bài toán \(\min c^Tx\) với ràng buộc \(Ax = b, x \geq 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Viết bài toán đối ngẫu.&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Áp dụng phương pháp gradient gần kề cho bài toán đối ngẫu.&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Khôi phục nghiệm bài toán gốc.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Lời giải&lt;/strong&gt;&lt;/summary&gt;

**Bài toán đối ngẫu:**

$$\max_\nu \quad g(\nu) = b^T\nu$$

với ràng buộc $$A^T\nu \leq c$$.

**Bước cập nhật gradient gần kề (có chiếu) trên bài toán đối ngẫu:**

$$\nu^{(k+1)} = \Pi_{\{A^T\nu \leq c\}}(\nu^{(k)} + t b)$$

**Khôi phục nghiệm gốc:**

$$x^{(k)} = \arg\min_x L(x, \nu^{(k)})$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tổng-kết&quot;&gt;💡 &lt;strong&gt;Tổng kết&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Tốc độ hội tụ&lt;/th&gt;
      &lt;th&gt;Đặc điểm chính&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Gradient gần kề&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;Xử lý trực tiếp thành phần không trơn \(g\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FISTA&lt;/td&gt;
      &lt;td&gt;\(O(1/k^2)\)&lt;/td&gt;
      &lt;td&gt;Tăng tốc bằng động lượng Nesterov&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Gradient gần kề đối ngẫu&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;Xử lý ràng buộc qua bài toán đối ngẫu&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;một-số-toán-tử-gần-kề-thường-gặp&quot;&gt;&lt;strong&gt;Một số toán tử gần kề thường gặp:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Hàm số&lt;/th&gt;
      &lt;th&gt;Toán tử gần kề&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;\(|\cdot|_1\)&lt;/td&gt;
      &lt;td&gt;Ngưỡng mềm (Soft-thresholding)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(|\cdot|_2\)&lt;/td&gt;
      &lt;td&gt;Ngưỡng mềm theo khối (Block soft-thresholding)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(|\cdot|_*\)&lt;/td&gt;
      &lt;td&gt;Ngưỡng mềm trên giá trị kỳ dị (SVD soft-thresholding)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(I_C\)&lt;/td&gt;
      &lt;td&gt;Phép chiếu \(\Pi_C\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hàm bậc hai&lt;/td&gt;
      &lt;td&gt;Nghịch đảo ma trận \((I + tQ)^{-1}\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-tài-liệu-tham-khảo&quot;&gt;📚 &lt;strong&gt;Tài liệu Tham khảo&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Parikh, N., &amp;amp; Boyd, S. (2014). “Proximal Algorithms”. Foundations and Trends.&lt;/li&gt;
  &lt;li&gt;Beck, A., &amp;amp; Teboulle, M. (2009). “A Fast Iterative Shrinkage-Thresholding Algorithm” (FISTA).&lt;/li&gt;
  &lt;li&gt;Combettes, P. L., &amp;amp; Pesquet, J.-C. (2011). “Proximal Splitting Methods”.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>09-10 Bài tập trắc nghiệm - Phương Pháp Proximal Gradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_10_Quiz_Proximal_Gradient/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_10_Quiz_Proximal_Gradient</id>
   <content type="html">&lt;p&gt;Chương 09 chứa mật độ ý tưởng dày đặc bậc nhất nửa đầu khóa học: từ phép tách hàm \(f = g + h\), toán tử gần kề \(\operatorname{prox}_{t h}\), co ngưỡng mềm ISTA, co ngưỡng giá trị kỳ dị cho hoàn thiện ma trận, cho đến các trường hợp đặc biệt và tăng tốc FISTA \(O(1/k^2)\). Chính vì nhiều khái niệm đan xen nhau nên khi làm bài trắc nghiệm, người học rất dễ mắc những lỗi tinh vi như quên nhân kích thước bước \(t\) vào ngưỡng \(\lambda\), nhầm tốc độ ISTA và FISTA, hay tưởng FISTA luôn giảm đơn điệu.&lt;/p&gt;

&lt;p&gt;Trước khi bắt đầu bộ câu hỏi trắc nghiệm chuyên sâu dưới đây, hãy dành hai phút rà soát bốn trụ cột cốt lõi và bốn phép thử số ngắn gọn để khóa chặt mọi công thức quan trọng.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-cụm-kiến-thức-trọng-tâm-cho-bài-trắc-nghiệm-chương-09&quot;&gt;Kiến thức cần nhớ: Bốn cụm kiến thức trọng tâm cho bài trắc nghiệm Chương 09&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Định nghĩa và tính chất toán tử gần kề:&lt;/strong&gt; Nắm chắc \(\operatorname{prox}_{t h}(v) = \arg\min_z \left\{\frac{1}{2t}\|z - v\|_2^2 + h(z)\right\}\); nhận ra ngay các trường hợp đặc biệt: \(h = 0 \Rightarrow v\), \(h = I_C \Rightarrow P_C(v)\), \(h(x) = \lambda\|x\|_1 \Rightarrow S_{t\lambda}(v)\), \(h(X) = \lambda\|X\|_* \Rightarrow \text{SVT}_{t\lambda}(V)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện hội tụ và bước an toàn:&lt;/strong&gt; Yêu cầu \(g\) lồi có \(\nabla g\) liên tục \(L\)-Lipschitz, \(h\) lồi có prox tính được, và bước cố định \(t \le 1/L\) (hoặc dùng backtracking trên phần trơn \(g\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bảng tốc độ hội tụ chuẩn:&lt;/strong&gt; Phân biệt rạch ròi ba bậc: Subgradient \(O(1/\epsilon^2)\) (\(O(1/\sqrt{k})\)), Proximal GD / ISTA \(O(1/\epsilon)\) (\(O(1/k)\)), và Accelerated Proximal GD / FISTA \(O(1/\sqrt{\epsilon})\) (\(O(1/k^2)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hành vi thực tế của tăng tốc:&lt;/strong&gt; Nhớ rằng ISTA giảm đơn điệu \(f(x^{(k+1)}) \le f(x^{(k)})\), còn FISTA có thể không đơn điệu (tạo gợn sóng) và nhạy cảm với nhiễu hoặc prox xấp xỉ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-bốn-phép-thử-số-nhanh-né-bẫy-trắc-nghiệm-chương-09&quot;&gt;Giải thích: Bốn phép thử số nhanh né bẫy trắc nghiệm Chương 09&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 1 — Ngưỡng co mềm là \(t\lambda\), không phải \(\lambda\):&lt;/strong&gt;
Với \(h(x) = 3\|x\|_1\), kích thước bước \(t = 0.5\) và vector \(v = (2.0, -1.0, 0.8)^T\):
Ngưỡng cắt là \(t\lambda = 0.5 \times 3 = 1.5\). Do đó:
\(\operatorname{prox}_{0.5 h}(v) = (2.0 - 1.5,\; 0,\; 0)^T = (0.5, 0, 0)^T.\)
(Nếu quên nhân \(t = 0.5\) mà cắt bằng \(\lambda = 3\), bạn sẽ sai hoàn toàn ra \((0, 0, 0)^T\)!)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 2 — Prox của hàm chỉ thị không phụ thuộc \(t\):&lt;/strong&gt;
Với \(h(x) = I_{[0, 1]}(x)\) và \(t = 10\) hay \(t = 0.01\), \(\operatorname{prox}_{t h}(2.5)\) luôn là hình chiếu \(P_{[0, 1]}(2.5) = 1.0\) (vì \(I_C(z)\) nhân với \(t &amp;gt; 0\) vẫn là \(I_C(z)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 3 — Prox của hàm bình phương \(\frac{\lambda}{2}\|x\|_2^2\):&lt;/strong&gt;
Cho đạo hàm của \(\frac{1}{2t}\|z - v\|_2^2 + \frac{\lambda}{2}\|z\|_2^2\) bằng \(0\):
\(\operatorname{prox}_{t h}(v) = \frac{1}{1 + t\lambda} v.\)
Ví dụ \(t = 0.5, \lambda = 2, v = 4 \implies z = \frac{4}{1 + 1} = 2\) (chỉ co tỷ lệ, không bao giờ cắt về \(0\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy 4 — Quy đổi độ phức tạp FISTA:&lt;/strong&gt;
Giảm sai số \(\epsilon\) đi 100 lần (từ \(10^{-2}\) xuống \(10^{-4}\)): ISTA tăng số bước &lt;strong&gt;100 lần&lt;/strong&gt;, còn FISTA chỉ tăng \(\sqrt{100} = 10\) lần!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-ôn-tập-lý-thuyết&quot;&gt;📚 Ôn tập lý thuyết&lt;/h2&gt;

&lt;p&gt;Trước khi làm bài tập, hãy ôn lại các khái niệm chính trong chương này:&lt;/p&gt;

&lt;h3 id=&quot;-phương-pháp-gradient-gần-kề-proximal-gradient&quot;&gt;⚡ &lt;strong&gt;Phương Pháp Gradient Gần Kề (Proximal Gradient)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-tổng-hợp-composite&quot;&gt;&lt;strong&gt;Bài toán tổng hợp (Composite)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Xét hàm mục tiêu có thể phân tách thành hai phần:
\(f(x) = g(x) + h(x)\)&lt;/p&gt;

&lt;p&gt;trong đó:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g(x)\): hàm lồi, khả vi, \(\text{dom}(g) = \mathbb{R}^n\).&lt;/li&gt;
  &lt;li&gt;\(h(x)\): hàm lồi, có thể không khả vi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;ý-tưởng-chính&quot;&gt;&lt;strong&gt;Ý tưởng chính&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ \(g\):&lt;/strong&gt; Dùng khai triển Taylor bậc hai với ma trận Hessian thay bằng \(\frac{1}{t}I\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giữ nguyên \(h\):&lt;/strong&gt; Không xấp xỉ phần không khả vi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kết hợp tối ưu:&lt;/strong&gt; Tìm điểm cực tiểu của tổng hàm xấp xỉ bậc hai và \(h\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;thuật-toán-cơ-bản&quot;&gt;&lt;strong&gt;Thuật toán cơ bản&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = \text{prox}_{t_k}(x^{(k-1)} - t_k \nabla g(x^{(k-1)}))\)&lt;/p&gt;

&lt;p&gt;với &lt;strong&gt;ánh xạ gần kề (proximal mapping):&lt;/strong&gt;
\(\text{prox}_t(x) = \underset{z}{\arg\min} \left\{ \frac{1}{2t} \lVert x - z \rVert_2^2 + h(z) \right\}\)&lt;/p&gt;

&lt;h4 id=&quot;diễn-giải-trực-quan&quot;&gt;&lt;strong&gt;Diễn giải trực quan&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước gradient:&lt;/strong&gt; \(x - t\nabla g(x)\) (một bước gradient descent trên \(g\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều chỉnh gần kề:&lt;/strong&gt; Tìm điểm vừa gần kết quả bước gradient, vừa làm nhỏ \(h\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cân bằng:&lt;/strong&gt; Tham số \(t\) điều tiết giữa việc bám theo bước gradient và việc làm nhỏ \(h\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-ánh-xạ-gần-kề-proximal-mapping&quot;&gt;📏 &lt;strong&gt;Ánh Xạ Gần Kề (Proximal Mapping)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;định-nghĩa&quot;&gt;&lt;strong&gt;Định nghĩa&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\text{prox}_t(x) = \underset{z}{\arg\min} \left\{ \frac{1}{2t} \lVert x - z \rVert_2^2 + h(z) \right\}\)&lt;/p&gt;

&lt;h4 id=&quot;tính-chất-quan-trọng&quot;&gt;&lt;strong&gt;Tính chất quan trọng&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chỉ phụ thuộc vào \(h\):&lt;/strong&gt; Độc lập với hàm \(g\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Có dạng đóng:&lt;/strong&gt; Tính được trực tiếp cho nhiều hàm \(h\) phổ biến.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đơn trị:&lt;/strong&gt; Nghiệm tồn tại duy nhất do tính lồi chặt của bài toán con.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không giãn (Non-expansive):&lt;/strong&gt; \(\lVert \text{prox}_t(x) - \text{prox}_t(y) \rVert \le \lVert x - y \rVert\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;các-ví-dụ-tiêu-biểu&quot;&gt;&lt;strong&gt;Các ví dụ tiêu biểu&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Chuẩn L1 (LASSO):&lt;/strong&gt;
\(h(x) = \lambda \lVert x \rVert_1 \Rightarrow \text{prox}_t(x) = S_{\lambda t}(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Toán tử ngưỡng mềm (Soft-thresholding):&lt;/strong&gt;
\([S_{\lambda t}(x)]_i = \begin{cases}
x_i - \lambda t &amp;amp; \text{nếu } x_i &amp;gt; \lambda t \\
0 &amp;amp; \text{nếu } |x_i| \le \lambda t \\
x_i + \lambda t &amp;amp; \text{nếu } x_i &amp;lt; -\lambda t
\end{cases}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Hàm chỉ thị (Phép chiếu):&lt;/strong&gt;
\(h(x) = I_C(x) \Rightarrow \text{prox}_t(x) = P_C(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Chuẩn L2:&lt;/strong&gt;
\(h(x) = \lambda \lVert x \rVert_2 \Rightarrow \text{prox}_t(x) = \max\left\{0, 1 - \frac{\lambda t}{\lVert x \rVert_2}\right\} x\)&lt;/p&gt;

&lt;h3 id=&quot;-phân-tích-hội-tụ&quot;&gt;📊 &lt;strong&gt;Phân Tích Hội Tụ&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;giả-thiết&quot;&gt;&lt;strong&gt;Giả thiết&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(g\) lồi, khả vi với \(\nabla g\) liên tục Lipschitz (hằng số \(L\)).&lt;/li&gt;
  &lt;li&gt;\(h\) lồi và \(\text{prox}_t\) tính được.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;định-lý-hội-tụ&quot;&gt;&lt;strong&gt;Định lý hội tụ&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Với kích thước bước cố định \(t \le 1/L\):
\(f(x^{(k)}) - f^* \le \frac{\lVert x^{(0)} - x^* \rVert_2^2}{2tk}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ý nghĩa:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ hội tụ:&lt;/strong&gt; \(O(1/k)\) (cùng bậc với gradient descent).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều kiện kích thước bước:&lt;/strong&gt; \(t \le 1/L\) (tương tự gradient descent).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu quả:&lt;/strong&gt; Tương đương gradient descent xét theo số bước lặp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;tìm-kiếm-đường-thẳng-lùi-backtracking-line-search&quot;&gt;&lt;strong&gt;Tìm kiếm đường thẳng lùi (Backtracking line search)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Điều kiện kiểm tra:&lt;/strong&gt;
\(g(x - tG_t(x)) &amp;gt; g(x) - t\nabla g(x)^T G_t(x) + \frac{t}{2} \lVert G_t(x) \rVert_2^2\)&lt;/p&gt;

&lt;p&gt;với \(G_t(x) = \frac{x - \text{prox}_t(x - t\nabla g(x))}{t}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lưu ý:&lt;/strong&gt; Điều kiện lùi chỉ đánh giá trên phần trơn \(g\), không đánh giá trên toàn bộ \(f\).&lt;/p&gt;

&lt;h3 id=&quot;-ví-dụ-ista-iterative-soft-thresholding-algorithm&quot;&gt;🎯 &lt;strong&gt;Ví Dụ: ISTA (Iterative Soft-Thresholding Algorithm)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-lasso&quot;&gt;&lt;strong&gt;Bài toán LASSO&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_\beta \frac{1}{2} \lVert y - X\beta \rVert_2^2 + \lambda \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phân tách:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g(\beta) = \frac{1}{2} \lVert y - X\beta \rVert_2^2\) (khả vi).&lt;/li&gt;
  &lt;li&gt;\(h(\beta) = \lambda \lVert \beta \rVert_1\) (không khả vi).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;gradient-của-g&quot;&gt;&lt;strong&gt;Gradient của \(g\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\nabla g(\beta) = -X^T(y - X\beta) = X^T(X\beta - y)\)&lt;/p&gt;

&lt;h4 id=&quot;bước-cập-nhật-ista&quot;&gt;&lt;strong&gt;Bước cập nhật ISTA&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\beta^{(k)} = S_{\lambda t}(\beta^{(k-1)} + tX^T(y - X\beta^{(k-1)}))\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm:&lt;/strong&gt; Công thức đơn giản và hội tụ nhanh hơn nhiều so với phương pháp subgradient.&lt;/p&gt;

&lt;h3 id=&quot;-ví-dụ-hoàn-thiện-ma-trận-matrix-completion&quot;&gt;🎯 &lt;strong&gt;Ví Dụ: Hoàn Thiện Ma Trận (Matrix Completion)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán&quot;&gt;&lt;strong&gt;Bài toán&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_B \frac{1}{2} \sum_{(i,j) \in \Omega} (Y_{ij} - B_{ij})^2 + \lambda \lVert B \rVert_{tr}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phân tách:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g(B) = \frac{1}{2} \lVert P_\Omega(Y) - P_\Omega(B) \rVert_F^2\) (khả vi).&lt;/li&gt;
  &lt;li&gt;\(h(B) = \lambda \lVert B \rVert_{tr}\) (chuẩn vết, không khả vi).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;toán-tử-chiếu&quot;&gt;&lt;strong&gt;Toán tử chiếu&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\([P_\Omega(B)]_{ij} = \begin{cases}
B_{ij} &amp;amp; \text{nếu } (i,j) \in \Omega \\
0 &amp;amp; \text{trường hợp khác}
\end{cases}\)&lt;/p&gt;

&lt;h4 id=&quot;gradient-của-g-1&quot;&gt;&lt;strong&gt;Gradient của \(g\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\nabla g(B) = -(P_\Omega(Y) - P_\Omega(B))\)&lt;/p&gt;

&lt;h4 id=&quot;ánh-xạ-gần-kề-cho-chuẩn-vết&quot;&gt;&lt;strong&gt;Ánh xạ gần kề cho chuẩn vết&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\text{prox}_t(B) = S_{\lambda t}(B)\) (ngưỡng mềm ma trận).&lt;/p&gt;

&lt;p&gt;Nếu \(B = U\Sigma V^T\) (phân tích SVD), thì:
\(S_{\lambda t}(B) = U\Sigma_{\lambda t} V^T\)&lt;/p&gt;

&lt;p&gt;với \((\Sigma_{\lambda t})_{ii} = \max\{\Sigma_{ii} - \lambda t, 0\}\).&lt;/p&gt;

&lt;h4 id=&quot;thuật-toán-soft-impute&quot;&gt;&lt;strong&gt;Thuật toán Soft-Impute&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(B^{(k)} = S_{\lambda}(P_\Omega(Y) + P_\Omega^\perp(B^{(k-1)}))\)&lt;/p&gt;

&lt;h3 id=&quot;-các-trường-hợp-đặc-biệt&quot;&gt;🔄 &lt;strong&gt;Các Trường Hợp Đặc Biệt&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Phương pháp gradient gần kề là &lt;strong&gt;khuôn khổ tổng quát&lt;/strong&gt; bao gồm:&lt;/p&gt;

&lt;h4 id=&quot;1-gradient-descent&quot;&gt;&lt;strong&gt;1. Gradient Descent&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(h = 0 \Rightarrow \text{prox}_t(x) = x\)
\(x^{(k)} = x^{(k-1)} - t\nabla g(x^{(k-1)})\)&lt;/p&gt;

&lt;h4 id=&quot;2-gradient-descent-có-chiếu-projected-gradient-descent&quot;&gt;&lt;strong&gt;2. Gradient Descent có chiếu (Projected Gradient Descent)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(h = I_C \Rightarrow \text{prox}_t(x) = P_C(x)\)
\(x^{(k)} = P_C(x^{(k-1)} - t\nabla g(x^{(k-1)}))\)&lt;/p&gt;

&lt;h4 id=&quot;3-thuật-toán-tối-ưu-gần-kề-pma&quot;&gt;&lt;strong&gt;3. Thuật toán tối ưu gần kề (PMA)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(g = 0 \Rightarrow x^{(k)} = \text{prox}_t(x^{(k-1)})\)&lt;/p&gt;

&lt;h3 id=&quot;-gradient-gần-kề-tăng-tốc-fista&quot;&gt;⚡ &lt;strong&gt;Gradient Gần Kề Tăng Tốc (FISTA)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;ý-tưởng&quot;&gt;&lt;strong&gt;Ý tưởng&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Bổ sung &lt;strong&gt;động lượng&lt;/strong&gt; để nâng tốc độ hội tụ từ \(O(1/k)\) lên \(O(1/k^2)\).&lt;/p&gt;

&lt;h4 id=&quot;thuật-toán&quot;&gt;&lt;strong&gt;Thuật toán&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(v = x^{(k-1)} + \frac{k-2}{k+1}(x^{(k-1)} - x^{(k-2)})\)
\(x^{(k)} = \text{prox}_{t_k}(v - t_k \nabla g(v))\)&lt;/p&gt;

&lt;h4 id=&quot;trọng-số-động-lượng&quot;&gt;&lt;strong&gt;Trọng số động lượng&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\frac{k-2}{k+1} \to 1\) khi \(k \to \infty\).&lt;/p&gt;

&lt;h4 id=&quot;đặc-điểm&quot;&gt;&lt;strong&gt;Đặc điểm&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tốc độ hội tụ:&lt;/strong&gt; \(O(1/k^2)\) — tối ưu trong lớp các phương pháp bậc nhất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không đơn điệu:&lt;/strong&gt; Giá trị hàm mục tiêu có thể tăng tạm thời (“gợn sóng Nesterov”).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu quả:&lt;/strong&gt; Cải thiện rõ rệt trên các bài toán có số điều kiện lớn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;fista-cho-lasso&quot;&gt;&lt;strong&gt;FISTA cho LASSO&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Giảm đáng kể số bước lặp so với cả ISTA và phương pháp subgradient.&lt;/p&gt;

&lt;h3 id=&quot;-so-sánh-các-phương-pháp&quot;&gt;🔄 &lt;strong&gt;So Sánh Các Phương Pháp&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phương pháp&lt;/th&gt;
      &lt;th&gt;Điều kiện&lt;/th&gt;
      &lt;th&gt;Tốc độ hội tụ&lt;/th&gt;
      &lt;th&gt;Ứng dụng&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Gradient Descent&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f\) khả vi&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;Tối ưu hàm trơn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Subgradient&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f\) lồi&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Hàm không trơn tổng quát&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Gradient gần kề&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f = g + h\), \(g\) trơn&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;Bài toán tổng hợp&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Gradient gần kề tăng tốc&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f = g + h\), \(g\) trơn&lt;/td&gt;
      &lt;td&gt;\(O(1/k^2)\)&lt;/td&gt;
      &lt;td&gt;Bài toán tổng hợp cần hội tụ nhanh&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-kỹ-thuật-thực-hành&quot;&gt;🛠️ &lt;strong&gt;Kỹ Thuật Thực Hành&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;khi-nào-nên-dùng-gradient-gần-kề&quot;&gt;&lt;strong&gt;Khi nào nên dùng Gradient gần kề:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm tổng hợp:&lt;/strong&gt; \(f = g + h\) với \(g\) trơn, \(h\) không trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán chính quy hóa:&lt;/strong&gt; LASSO, elastic net, group LASSO.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu có ràng buộc:&lt;/strong&gt; Gradient descent có chiếu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán ma trận:&lt;/strong&gt; Hoàn thiện ma trận, phân tích thành phần chính bền vững (robust PCA).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tối ưu thưa:&lt;/strong&gt; Chọn đặc trưng, cảm biến nén.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;điều-kiện-triển-khai-hiệu-quả&quot;&gt;&lt;strong&gt;Điều kiện triển khai hiệu quả:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(\nabla g\):&lt;/strong&gt; Gradient của phần trơn phải tính được nhanh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính \(\text{prox}_t\):&lt;/strong&gt; Có công thức giải tích hoặc bộ giải con hiệu quả.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hằng số Lipschitz \(L\):&lt;/strong&gt; Giúp chọn kích thước bước ổn định.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;gỡ-lỗi-và-tinh-chỉnh&quot;&gt;&lt;strong&gt;Gỡ lỗi và tinh chỉnh:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra ánh xạ gần kề:&lt;/strong&gt; Xác minh công thức trên các ví dụ nhỏ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn kích thước bước:&lt;/strong&gt; Bước cố định (\(t = 1/L\)) hoặc tìm kiếm đường thẳng lùi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theo dõi hội tụ:&lt;/strong&gt; Quan sát \(f(x^{(k)})\) qua các vòng lặp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tăng tốc:&lt;/strong&gt; Thử FISTA nếu phương pháp cơ bản hội tụ chậm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ứng-dụng-thực-tế&quot;&gt;📈 &lt;strong&gt;Ứng Dụng Thực Tế&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-học-máy&quot;&gt;&lt;strong&gt;1. Học máy&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hồi quy LASSO:&lt;/strong&gt; Chọn lọc đặc trưng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Elastic Net:&lt;/strong&gt; Kết hợp chính quy hóa L1 và L2.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Group LASSO:&lt;/strong&gt; Tạo tính thưa theo nhóm biến.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hồi quy Logistic thưa:&lt;/strong&gt; Phân loại kết hợp chọn đặc trưng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-xử-lý-tín-hiệu&quot;&gt;&lt;strong&gt;2. Xử lý tín hiệu&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cảm biến nén (Compressed Sensing):&lt;/strong&gt; Khôi phục tín hiệu thưa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khử nhiễu ảnh:&lt;/strong&gt; Chính quy hóa biến phân toàn phần (Total Variation).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hoàn thiện ma trận:&lt;/strong&gt; Lọc cộng tác, hệ thống gợi ý.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-thị-giác-máy-tính&quot;&gt;&lt;strong&gt;3. Thị giác máy tính&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân đoạn ảnh:&lt;/strong&gt; Các phương pháp biến phân toàn phần.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dòng quang học (Optical Flow):&lt;/strong&gt; Ước lượng chuyển động có chính quy hóa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tái tạo cấu trúc từ chuyển động:&lt;/strong&gt; Tối ưu thưa trong bundle adjustment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;4-thống-kê&quot;&gt;&lt;strong&gt;4. Thống kê&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chọn biến:&lt;/strong&gt; Hồi quy nhiều chiều.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thống kê bền vững:&lt;/strong&gt; Hàm mất mát Huber, hồi quy phân vị.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mô hình đồ thị:&lt;/strong&gt; Ước lượng ma trận độ chính xác thưa.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ví-dụ-minh-họa&quot;&gt;💡 &lt;strong&gt;Ví Dụ Minh Họa&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;bài-toán-min_x-frac12x-22--x&quot;&gt;&lt;strong&gt;Bài toán:&lt;/strong&gt; \(\min_x \frac{1}{2}(x-2)^2 + |x|\)&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Phân tách:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g(x) = \frac{1}{2}(x-2)^2\), \(\nabla g(x) = x-2\)&lt;/li&gt;
  &lt;li&gt;
\[h(x) = |x|\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ánh xạ gần kề:&lt;/strong&gt;
\(\text{prox}_t(x) = S_t(x) = \begin{cases}
x - t &amp;amp; \text{nếu } x &amp;gt; t \\
0 &amp;amp; \text{nếu } |x| \le t \\
x + t &amp;amp; \text{nếu } x &amp;lt; -t
\end{cases}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Một bước gradient gần kề:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Bước gradient: \(x - t(x-2) = (1-t)x + 2t\).&lt;/li&gt;
  &lt;li&gt;Áp dụng ngưỡng mềm: \(\text{prox}_t((1-t)x + 2t)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-kết-nối-với-các-chương-khác&quot;&gt;🎯 &lt;strong&gt;Kết Nối Với Các Chương Khác&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;từ-các-chương-trước&quot;&gt;&lt;strong&gt;Từ các chương trước:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chương 08:&lt;/strong&gt; Phương pháp subgradient cho hàm không trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chương 07:&lt;/strong&gt; Gradient dưới và vi phân dưới.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chương 06:&lt;/strong&gt; Gradient descent cho hàm trơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;ưu-điểm-của-gradient-gần-kề&quot;&gt;&lt;strong&gt;Ưu điểm của Gradient gần kề:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nhanh hơn subgradient:&lt;/strong&gt; \(O(1/k)\) so với \(O(1/\sqrt{k})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng quát hơn gradient descent:&lt;/strong&gt; Xử lý trực tiếp thành phần không trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Có thể tăng tốc:&lt;/strong&gt; FISTA đạt tốc độ \(O(1/k^2)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;hướng-mở-rộng&quot;&gt;&lt;strong&gt;Hướng mở rộng:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;ADMM:&lt;/strong&gt; Phương pháp nhân tử theo hướng luân phiên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương pháp gốc–đối ngẫu:&lt;/strong&gt; Xử lý bài toán có ràng buộc phức tạp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biến thể ngẫu nhiên:&lt;/strong&gt; Phiên bản mini-batch và trực tuyến.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-ý-nghĩa-lý-thuyết&quot;&gt;🌟 &lt;strong&gt;Ý Nghĩa Lý Thuyết&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;toán-tử-gần-kề-như-gradient-tổng-quát&quot;&gt;&lt;strong&gt;Toán tử gần kề như “gradient tổng quát”:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient:&lt;/strong&gt; \(\nabla f(x)\) cho hàm trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Subgradient:&lt;/strong&gt; \(\partial f(x)\) cho hàm không trơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Toán tử gần kề:&lt;/strong&gt; \(\text{prox}_t\) cho bài toán tổng hợp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;bao-moreau-moreau-envelope&quot;&gt;&lt;strong&gt;Bao Moreau (Moreau envelope):&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f_t(x) = \min_z \left\{ f(z) + \frac{1}{2t}\lVert x - z \rVert^2 \right\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tính chất:&lt;/strong&gt; \(f_t\) là hàm trơn với \(\nabla f_t(x) = \frac{x - \text{prox}_t(x)}{t}\).&lt;/p&gt;

&lt;h4 id=&quot;liên-hệ-với-giải-tích-biến-phân&quot;&gt;&lt;strong&gt;Liên hệ với giải tích biến phân:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Gradient gần kề ↔ Tách xuôi–ngược (forward-backward splitting).&lt;/li&gt;
  &lt;li&gt;Tăng tốc ↔ Các phương pháp có quán tính.&lt;/li&gt;
  &lt;li&gt;Tốc độ hội tụ ↔ Lý thuyết độ phức tạp tối ưu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-mẹo-thực-hành&quot;&gt;💡 &lt;strong&gt;Mẹo Thực Hành&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;lựa-chọn-phương-pháp-phù-hợp&quot;&gt;&lt;strong&gt;Lựa chọn phương pháp phù hợp:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hàm trơn:&lt;/strong&gt; Gradient descent.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm không trơn tổng quát:&lt;/strong&gt; Phương pháp subgradient.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm tổng hợp có prox dễ tính:&lt;/strong&gt; Phương pháp gradient gần kề.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cần hội tụ nhanh hơn:&lt;/strong&gt; FISTA.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Có ràng buộc tập lồi:&lt;/strong&gt; Gradient descent có chiếu.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;kinh-nghiệm-cài-đặt&quot;&gt;&lt;strong&gt;Kinh nghiệm cài đặt:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vector hóa phép tính:&lt;/strong&gt; Tận dụng tính toán song song.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khởi tạo ấm (Warm start):&lt;/strong&gt; Dùng nghiệm của tham số trước làm điểm khởi tạo.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước thích nghi:&lt;/strong&gt; Dùng tìm kiếm đường thẳng lùi khi không biết \(L\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dừng sớm:&lt;/strong&gt; Theo dõi tiêu chuẩn hội tụ qua từng bước.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;lỗi-thường-gặp&quot;&gt;&lt;strong&gt;Lỗi thường gặp:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sai công thức toán tử gần kề:&lt;/strong&gt; Cần kiểm tra kỹ ngưỡng và hệ số \(t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kích thước bước quá lớn:&lt;/strong&gt; Có thể gây phân kỳ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bỏ qua hằng số Lipschitz:&lt;/strong&gt; Ảnh hưởng trực tiếp đến điều kiện hội tụ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không chuẩn hóa dữ liệu:&lt;/strong&gt; Làm xấu số điều kiện và giảm ổn định số học.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Ghi chú:&lt;/strong&gt; Phương pháp gradient gần kề là cầu nối tự nhiên giữa tối ưu hàm trơn và tối ưu hàm không trơn, giữ vai trò trọng tâm trong học máy có chính quy hóa.&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Sửa lỗi alignment cho MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Đảm bảo các label trong quiz có alignment tốt */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;Bài tập trắc nghiệm này kiểm tra hiểu biết của bạn về phương pháp gradient gần kề (proximal gradient method), proximal operator, composite optimization và acceleration methods như FISTA.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🎯 Quiz: Phương Pháp Proximal Gradient&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Câu hỏi: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Câu hỏi 1: Composite function form --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Câu 1: Proximal gradient method áp dụng cho bài toán có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(\min f(x)\) với \(f\) khả vi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(\min f(x) = g(x) + h(x)\) với \(g\) khả vi, \(h\) lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(\min f(x)\) với \(f\) không lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(\min f(x)\) với ràng buộc tuyến tính&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\min f(x) = g(x) + h(x)$$ với $$g$$ khả vi, $$h$$ lồi&lt;/strong&gt;&lt;br /&gt;
                Proximal gradient method được thiết kế cho composite optimization với $$g$$ khả vi và $$h$$ có thể không khả vi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 2: Proximal operator definition --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 2: Proximal operator của hàm \(h\) được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(\text{prox}_h(v) = \arg\min_x \{h(x) + \frac{1}{2}\|x - v\|^2\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\text{prox}_h(v) = \arg\min_x \{h(x) - \frac{1}{2}\|x - v\|^2\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(\text{prox}_h(v) = \arg\min_x \{h(x) + \|x - v\|\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(\text{prox}_h(v) = v - \nabla h(v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\text{prox}_h(v) = \arg\min_x \{h(x) + \frac{1}{2}\|x - v\|^2\}$$&lt;/strong&gt;&lt;br /&gt;
                Proximal operator cân bằng giữa việc giảm thiểu $$h(x)$$ và giữ $$x$$ gần với $$v$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 3: Proximal gradient update --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 3: Công thức cập nhật của proximal gradient method là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(x^{(k+1)} = x^{(k)} - t \nabla g(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(x^{(k+1)} = \text{prox}_{th}(x^{(k)} - t \nabla g(x^{(k)}))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \(x^{(k+1)} = \text{prox}_{tg}(x^{(k)} - t \nabla h(x^{(k)}))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \(x^{(k+1)} = x^{(k)} - t(\nabla g(x^{(k)}) + \nabla h(x^{(k)}))\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$x^{(k+1)} = \text{prox}_{th}(x^{(k)} - t \nabla g(x^{(k)}))$$&lt;/strong&gt;&lt;br /&gt;
                Thực hiện gradient step cho $$g$$ rồi áp dụng proximal operator cho $$h$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 4: Proximal operator of L1 norm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 4: Proximal operator của \(h(x) = \lambda\|x\|_1\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) \(\text{prox}_{\lambda\|\cdot\|_1}(v) = v - \lambda\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) \(\text{prox}_{\lambda\|\cdot\|_1}(v) = \text{sign}(v) \max(|v| - \lambda, 0)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) \(\text{prox}_{\lambda\|\cdot\|_1}(v) = \frac{v}{1 + \lambda}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) \(\text{prox}_{\lambda\|\cdot\|_1}(v) = v\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\text{prox}_{\lambda\|\cdot\|_1}(v) = \text{sign}(v) \max(|v| - \lambda, 0)$$&lt;/strong&gt;&lt;br /&gt;
                Đây là soft thresholding operator, co các thành phần về phía 0 một lượng $$\lambda$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 5: Proximal operator of L2 norm squared --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 5: Proximal operator của \(h(x) = \frac{\lambda}{2}\|x\|_2^2\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(\text{prox}_{\frac{\lambda}{2}\|\cdot\|_2^2}(v) = \frac{v}{1 + \lambda}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(\text{prox}_{\frac{\lambda}{2}\|\cdot\|_2^2}(v) = v - \lambda v\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(\text{prox}_{\frac{\lambda}{2}\|\cdot\|_2^2}(v) = v\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \(\text{prox}_{\frac{\lambda}{2}\|\cdot\|_2^2}(v) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\text{prox}_{\frac{\lambda}{2}\|\cdot\|_2^2}(v) = \frac{v}{1 + \lambda}$$&lt;/strong&gt;&lt;br /&gt;
                Proximal operator của quadratic function có dạng shrinkage với hệ số $$\frac{1}{1 + \lambda}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 6: Convergence rate --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 6: Tốc độ hội tụ của proximal gradient method là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(O(1/\sqrt{k})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(O(e^{-k})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$O(1/k)$$&lt;/strong&gt;&lt;br /&gt;
                Proximal gradient method có tốc độ hội tụ $$O(1/k)$$ giống như gradient descent cho hàm lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 7: When to use proximal gradient --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 7: Proximal gradient method thích hợp khi:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Cả \(g\) và \(h\) đều khả vi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(g\) khả vi và proximal operator của \(h\) dễ tính&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Cả \(g\) và \(h\) đều không khả vi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) Hàm mục tiêu không lồi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$g$$ khả vi và proximal operator của $$h$$ dễ tính&lt;/strong&gt;&lt;br /&gt;
                Phương pháp này hiệu quả khi có thể tính gradient của $$g$$ và proximal operator của $$h$$ một cách dễ dàng.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 8: FISTA algorithm --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 8: FISTA (Fast Iterative Shrinkage-Thresholding Algorithm) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) Phiên bản chậm của proximal gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) Phiên bản tăng tốc của proximal gradient với momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) Thuật toán cho bài toán không lồi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) Thuật toán chỉ cho L1 regularization&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Phiên bản tăng tốc của proximal gradient với momentum&lt;/strong&gt;&lt;br /&gt;
                FISTA sử dụng momentum để đạt tốc độ hội tụ $$O(1/k^2)$$ thay vì $$O(1/k)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 9: FISTA convergence rate --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 9: Tốc độ hội tụ của FISTA là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(O(1/\sqrt{k})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(O(e^{-k})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$O(1/k^2)$$&lt;/strong&gt;&lt;br /&gt;
                FISTA đạt tốc độ hội tụ optimal $$O(1/k^2)$$ cho first-order methods trên hàm lồi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 10: FISTA momentum parameter --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 10: Trong FISTA, tham số momentum \(t_k\) được cập nhật theo công thức:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(t_{k+1} = \frac{1 + \sqrt{1 + 4t_k^2}}{2}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(t_{k+1} = t_k + 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(t_{k+1} = 0.9 t_k\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(t_{k+1} = 1\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$t_{k+1} = \frac{1 + \sqrt{1 + 4t_k^2}}{2}$$&lt;/strong&gt;&lt;br /&gt;
                Đây là công thức đặc biệt trong FISTA để đảm bảo tốc độ hội tụ optimal.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 11: Proximal operator properties --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 11: Proximal operator có tính chất:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Không làm tăng khoảng cách (non-expansive, với $$h$$ lồi)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Tăng khoảng cách&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Không liên tục&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Chỉ áp dụng cho hàm khả vi&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Không làm tăng khoảng cách (non-expansive, với $$h$$ lồi)&lt;/strong&gt;&lt;br /&gt;
                $$\|\text{prox}_h(u) - \text{prox}_h(v)\| \leq \|u - v\|$$ với mọi $$u, v$$, đây là tính chất quan trọng cho phân tích hội tụ.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 12: Lasso problem --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 12: Bài toán Lasso \(\min \frac{1}{2}\|Ax - b\|_2^2 + \lambda\|x\|_1\) có thể giải bằng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Proximal gradient với \(g(x) = \frac{1}{2}\|Ax - b\|_2^2\), \(h(x) = \lambda\|x\|_1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Newton method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) Không thể giải được&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Proximal gradient với $$g(x) = \frac{1}{2}\|Ax - b\|_2^2$$, $$h(x) = \lambda\|x\|_1$$&lt;/strong&gt;&lt;br /&gt;
                Lasso là ví dụ điển hình của composite optimization với $$g$$ khả vi và $$h$$ không khả vi.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 13: Matrix completion --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 13: Trong matrix completion, proximal operator của nuclear norm thực hiện:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Hard thresholding trên singular values&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Soft thresholding trên singular values&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) Không thay đổi ma trận&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Đặt tất cả phần tử bằng 0&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Soft thresholding trên singular values&lt;/strong&gt;&lt;br /&gt;
                Proximal operator của nuclear norm $$\|X\|_*$$ thực hiện SVD và soft thresholding trên các singular values.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 14: Backtracking line search --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 14: Trong proximal gradient method, có thể sử dụng backtracking line search không?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) Không, vì hàm không khả vi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Có, dựa trên điều kiện giảm đủ cho composite function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Chỉ khi \(h = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Chỉ cho FISTA&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Có, dựa trên điều kiện giảm đủ cho composite function&lt;/strong&gt;&lt;br /&gt;
                Có thể sử dụng backtracking với điều kiện $$f(x^+) \leq Q_t(x^+, x)$$ trong đó $$Q_t$$ là quadratic upper bound.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 15: Proximal operator of indicator function --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 15: Proximal operator của hàm chỉ thị \(I_C(x)\) của tập lồi \(C\) là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(\text{prox}_{I_C}(v) = v\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(\text{prox}_{I_C}(v) = P_C(v)\) (projection onto \(C\))&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(\text{prox}_{I_C}(v) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) Không tồn tại&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$\text{prox}_{I_C}(v) = P_C(v)$$ (projection onto $$C$$)&lt;/strong&gt;&lt;br /&gt;
                Proximal operator của hàm chỉ thị chính là phép chiếu lên tập ràng buộc.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 16: Composite gradient mapping --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 16: Composite gradient mapping \(G_t(x)\) được định nghĩa là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(G_t(x) = \nabla g(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(G_t(x) = \frac{1}{t}(x - \text{prox}_{th}(x - t\nabla g(x)))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(G_t(x) = \text{prox}_{th}(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(G_t(x) = x - t\nabla g(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$G_t(x) = \frac{1}{t}(x - \text{prox}_{th}(x - t\nabla g(x)))$$&lt;/strong&gt;&lt;br /&gt;
                Composite gradient mapping tổng quát hóa gradient cho composite functions và được dùng trong điều kiện dừng.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 17: Acceleration always beneficial --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 17: Acceleration (như FISTA) có luôn có lợi không?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Luôn có lợi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) Không, có thể làm chậm hội tụ trong một số trường hợp&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Chỉ có lợi cho hàm quadratic&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Chỉ có lợi cho L1 regularization&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Không, có thể làm chậm hội tụ trong một số trường hợp&lt;/strong&gt;&lt;br /&gt;
                Acceleration có thể gây dao động và chậm hội tụ, đặc biệt khi hàm có conditioning kém hoặc trong giai đoạn đầu.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 18: Proximal gradient vs subgradient --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 18: So với subgradient method, proximal gradient method:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Chậm hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Nhanh hơn và ổn định hơn&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Chỉ áp dụng cho hàm khả vi&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Có cùng tốc độ hội tụ&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) Nhanh hơn và ổn định hơn&lt;/strong&gt;&lt;br /&gt;
                Proximal gradient có tốc độ $$O(1/k)$$ so với $$O(1/\sqrt{k})$$ của subgradient, và ít dao động hơn.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 19: Strongly convex case --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 19: Khi \(g\) là strongly convex, proximal gradient method có tốc độ hội tụ:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) \(O(\rho^k)\) với \(\rho &amp;lt; 1\) (linear)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) \(O(1/\sqrt{k})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: B) $$O(\rho^k)$$ với $$\rho &amp;lt; 1$$ (linear)&lt;/strong&gt;&lt;br /&gt;
                Strong convexity của $$g$$ đảm bảo tốc độ hội tụ linear (geometric) cho proximal gradient method.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 20: Practical considerations --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 20: Trong thực tế, để áp dụng proximal gradient method hiệu quả, cần:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) Proximal operator của \(h\) phải có closed-form solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) \(g\) phải có Lipschitz gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) Biết step size thích hợp&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) Tất cả các điều kiện trên&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: D) Tất cả các điều kiện trên&lt;/strong&gt;&lt;br /&gt;
                Để hiệu quả, cần proximal operator dễ tính, Lipschitz gradient cho $$g$$, và step size phù hợp.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Câu hỏi 21: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 21: Proximal operator của hàm $$f(x) = \lambda|x|$$ là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$\text{prox}_f(x) = \text{sign}(x)\max\{|x|-\lambda, 0\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$\text{prox}_f(x) = x - \lambda$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$\text{prox}_f(x) = \lambda x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$\text{prox}_f(x) = |x|$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\text{prox}_f(x) = \text{sign}(x)\max\{|x|-\lambda, 0\}$$&lt;/strong&gt;&lt;br /&gt;
                Đây là soft thresholding operator, một trong những proximal operator quan trọng nhất.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 22: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 22: Proximal gradient method kết hợp:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Gradient descent + proximal operator&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Newton method + gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) SGD + momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Line search + Hessian&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Gradient descent + proximal operator&lt;/strong&gt;&lt;br /&gt;
                Proximal gradient method: $$x^{(k+1)} = \text{prox}_{th}(x^{(k)} - t\nabla g(x^{(k)}))$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 23: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 23: FISTA là thuật toán:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Tăng tốc proximal gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Newton method cải tiến&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Stochastic gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Interior point method&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) Tăng tốc proximal gradient&lt;/strong&gt;&lt;br /&gt;
                FISTA (Fast Iterative Shrinkage-Thresholding Algorithm) là phiên bản tăng tốc của proximal gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 24: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 24: Bài toán LASSO có dạng:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$\min \frac{1}{2}\|Ax-b\|^2 + \lambda\|x\|_1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$\min \frac{1}{2}\|Ax-b\|^2 + \lambda\|x\|_2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$\min \|Ax-b\|_1 + \lambda\|x\|_2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) $$\min \|Ax-b\|_\infty + \lambda\|x\|_1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$\min \frac{1}{2}\|Ax-b\|^2 + \lambda\|x\|_1$$&lt;/strong&gt;&lt;br /&gt;
                LASSO sử dụng regularization L1: $$\min \frac{1}{2}\|Ax-b\|^2 + \lambda\|x\|_1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Câu hỏi 25: Thực hành --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Câu 25: Với $$\text{prox}_{\lambda|\cdot|}(2)$$ và $$\lambda = 0.5$$, kết quả là:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$1.5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$0.5$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Đáp án đúng: A) $$1.5$$&lt;/strong&gt;&lt;br /&gt;
                $$\text{prox}_{0.5|\cdot|}(2) = \text{sign}(2)\max\{|2|-0.5, 0\} = 1 \cdot 1.5 = 1.5$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Câu trước&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Câu tiếp →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Nộp bài&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Làm lại&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Hoàn thành Quiz!&lt;/h2&gt;
        &lt;p&gt;Điểm số của bạn: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Đáp án đúng
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;a&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;a&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;b&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;b&apos;, q13: &apos;b&apos;, q14: &apos;b&apos;, q15: &apos;b&apos;,
    q16: &apos;b&apos;, q17: &apos;b&apos;, q18: &apos;b&apos;, q19: &apos;b&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Ẩn tất cả câu hỏi
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Hiển thị câu hỏi hiện tại
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Cập nhật progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Cập nhật số câu hỏi
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Cập nhật nút điều hướng
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Hiển thị tất cả giải thích
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight đáp án đúng và sai
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Hiển thị kết quả cuối
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Xuất sắc! Bạn đã thành thạo proximal gradient method!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Rất tốt! Bạn hiểu tốt về proximal operators và FISTA.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Khá ổn! Hãy xem lại proximal operators và acceleration.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Cần cải thiện! Ôn lại composite optimization và proximal operators.&apos;;
    } else {
        message = &apos;📖 Hãy học lại từ đầu về proximal gradient method nhé!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Ẩn nút submit, hiện nút reset
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Cuộn đến kết quả
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset trạng thái
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Ẩn tất cả giải thích
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset style của labels
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck tất cả radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Hiển thị câu hỏi đầu tiên
    showQuestion(1);
    
    // Cuộn lên đầu
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Ẩn kết quả cuối và reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Khởi tạo bài tập khi trang được tải
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Thêm event listener cho tất cả radio button
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax sau khi DOM được tải
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Xử lý phím tắt
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>09-05 Tăng tốc</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_05_acceleration/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_05_acceleration</id>
   <content type="html">&lt;p&gt;Nếu bạn thả một viên bi nặng lăn xuống một hẻm núi hình lòng máng hẹp và dài, viên bi sẽ trượt đi như thế nào? Gradient descent (và proximal gradient tiêu chuẩn) hành xử giống như một người đi bộ mất trí nhớ hoàn toàn: sau mỗi bước, họ dừng hẳn lại, quên sạch hướng mình vừa đi, rồi lại đo dốc cục bộ và đi vuông góc với đường đồng mức — kết quả là họ cứ zíc-zắc qua lại giữa hai thành hẻm núi, tiến dọc theo đáy hẻm chậm như rùa!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tăng tốc Nesterov (Nesterov Acceleration)&lt;/strong&gt; trả lại “trí nhớ quán tính” cho viên bi ấy — nhưng theo một cách tinh tế hơn cả vật lý cổ điển. Thay vì chỉ cộng quán tính sau khi tính gradient (như phương pháp Heavy Ball của Polyak), Nesterov để viên bi &lt;strong&gt;nhìn trước một bước theo đà quán tính&lt;/strong&gt; rồi mới đo gradient và áp dụng toán tử gần kề tại điểm nhìn trước đó. Chỉ một thay đổi nhỏ về thứ tự phép tính ấy đã làm chấn động ngành tối ưu năm 1983, nâng tốc độ từ \(O(1/k)\) lên đúng giới hạn lý thuyết \(O(1/k^2)\)!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trực-giác-cốt-lõi-về-tăng-tốc-bậc-nhất&quot;&gt;Kiến thức cần nhớ: Bốn trực giác cốt lõi về tăng tốc bậc nhất&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bệnh zíc-zắc trên hàm có số điều kiện lớn (Ill-conditioned Landscapes):&lt;/strong&gt; Khi độ cong theo một hướng lớn gấp \(\kappa\) lần hướng kia, bước \(t \le 1/L\) bị khống chế bởi hướng dốc nhất, khiến bước tiến dọc theo thung lũng phẳng cực kỳ nhỏ bé. Quán tính triệt tiêu các thành phần dao động ngược dấu qua hai bước liên tiếp và cộng hưởng các thành phần cùng hướng dọc đáy thung lũng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sự khác biệt giữa Polyak Heavy Ball và Nesterov Look-ahead:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Heavy Ball:&lt;/em&gt; tính gradient tại \(x^{(k)}\), rồi cộng đà \(\beta(x^{(k)} - x^{(k-1)})\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Nesterov:&lt;/em&gt; ngoại suy trước \(y^{(k)} = x^{(k)} + \beta_k(x^{(k)} - x^{(k-1)})\), rồi mới tính \(\nabla g(y^{(k)})\) và \(\operatorname{prox}_{t h}\). Nhờ “phanh sớm” nếu bước quán tính vượt quá đáy, Nesterov đảm bảo hội tụ toàn cục \(O(1/k^2)\) cho mọi hàm lồi trơn.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov lý thuyết vs. “Nesterov trong PyTorch”:&lt;/strong&gt; Trong lý thuyết tối ưu lồi, hệ số quán tính tăng dần theo lịch \(\beta_k = \frac{k-1}{k+2} \to 1\) để khớp tốc độ \(O(1/k^2)\); trong khi ở học sâu (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.optim.SGD(..., momentum=0.9, nesterov=True)&lt;/code&gt;), hệ số \(\beta\) thường giữ cố định (như \(0.9\)) để cân bằng giữa tốc độ và nhiễu mini-batch.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tác dụng phụ: gợn sóng Nesterov (Nesterov Ripples):&lt;/strong&gt; Vì có quán tính, quỹ đạo tăng tốc có thể trượt lố qua đáy rồi quay lại, nên giá trị hàm \(f(x^{(k)})\) không còn giảm đơn điệu như ISTA — mở ra nhu cầu kỹ thuật khởi động lại (adaptive restart).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-thấy-tận-mắt-cơ-chế-nhìn-trước-để-phanh-sớm-của-nesterov&quot;&gt;Giải thích: Thấy tận mắt cơ chế “nhìn trước để phanh sớm” của Nesterov&lt;/h3&gt;

&lt;p&gt;Xét hàm bậc hai 1D \(g(x) = \frac{1}{2}x^2\) (\(L = 1\), nghiệm \(x^* = 0\)) với bước \(t = 0.5\) và đà \(\beta = 0.5\). Giả sử ta đang có \(x^{(0)} = 4\) và \(x^{(1)} = 1\) (đà chuyển động \(x^{(1)} - x^{(0)} = -3\) đang lao mạnh về trái qua \(0\)).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cách 1 — Không quán tính (GD thường):&lt;/strong&gt;
\(x^{(2)} = 1 - 0.5(1) = 0.5\) (an toàn nhưng chậm).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách 2 — Polyak Heavy Ball (đo dốc ở chỗ cũ rồi mới cộng đà):&lt;/strong&gt;
\(x^{(2)}_{\text{HB}} = x^{(1)} - 0.5\nabla g(x^{(1)}) + 0.5(x^{(1)} - x^{(0)}) = 1 - 0.5(1) + 0.5(-3) = -1.0.\)
Viên bi lao lố sang tận \(-1.0\) (sai số giữ nguyên \(|x| = 1\))!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách 3 — Nesterov Look-ahead (nhìn trước rồi mới đo dốc):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Điểm nhìn trước: \(y^{(1)} = 1 + 0.5(-3) = -0.5\) (thấy ngay rằng mình sắp vượt qua đáy \(0\) sang phía âm!).&lt;/li&gt;
      &lt;li&gt;Đo gradient tại \(y^{(1)} = -0.5\): \(\nabla g(-0.5) = -0.5\) (lực phanh kéo ngược về phải!).&lt;/li&gt;
      &lt;li&gt;Cập nhật: \(x^{(2)}_{\text{Nest}} = y^{(1)} - 0.5(-0.5) = -0.5 + 0.25 = -0.25\)!
Sai số rơi ngay từ \(1.0\) xuống \(0.25\) (tốt gấp &lt;strong&gt;4 lần&lt;/strong&gt; Heavy Ball và gấp &lt;strong&gt;2 lần&lt;/strong&gt; GD thường)! Đó chính là bí mật của hai chữ &lt;em&gt;look-ahead&lt;/em&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;tăng-tốc&quot;&gt;Tăng tốc&lt;/h1&gt;

&lt;p&gt;Phương pháp gradient gần kề trên bài toán tổng hợp \(\min_x g(x)+h(x)\) đã đạt tốc độ hội tụ \(O(1/k)\) khi \(\nabla g\) liên tục Lipschitz (bài 09-02). &lt;strong&gt;Tăng tốc (acceleration)&lt;/strong&gt; là kỹ thuật bổ sung thành phần động lượng giúp nâng tốc độ hội tụ lên mức tối ưu bậc nhất \(O(1/k^2)\) cho lớp hàm lồi trơn \(g\) mà không cần tính ma trận Hessian. Bài học này trình bày góc nhìn trực quan theo phong cách Distill trước khi đi vào phần biến đổi đại số của FISTA. Thuật toán và chứng minh tốc độ \(O(1/k^2)\) nằm ở &lt;a href=&quot;/contents/vi/chapter09/09_05_01_accelerated_proximal_gradient_method/&quot;&gt;09-05-01&lt;/a&gt; và &lt;a href=&quot;/contents/vi/chapter09/09_05_02_convergence_analysis/&quot;&gt;09-05-02&lt;/a&gt;; biến thể ngẫu nhiên với hệ số \(\beta\) cố định dùng trong huấn luyện mạng nơ-ron nằm ở &lt;a href=&quot;/contents/vi/chapter26/26_02_momentum_and_nesterov/&quot;&gt;26-02&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;vì-sao-bước-gradient-gần-kề-tiêu-chuẩn-dễ-dao-động-zíc-zắc&quot;&gt;Vì sao bước gradient gần kề tiêu chuẩn dễ dao động zíc-zắc&lt;/h2&gt;

&lt;p&gt;Có thể hình dung một bước gradient gần kề là: thực hiện một bước gradient trên phần trơn, sau đó điều chỉnh lại bằng \(\operatorname{prox}_{t h}\). Khi \(h=0\), thuật toán trở về gradient descent thông thường, và ví dụ kinh điển là thung lũng hẹp \(g(x)=\tfrac12 x^\top\operatorname{diag}(1,L)\,x\): kích thước bước đủ nhỏ để không dao động theo chiều dốc lại khiến thuật toán tiến rất chậm dọc theo đáy thung lũng. Kỹ thuật động lượng — do Nesterov đề xuất cho hàm lồi trơn năm 1983, và được Beck–Teboulle (2009) mở rộng kèm ánh xạ gần kề thành &lt;strong&gt;FISTA&lt;/strong&gt; — lưu lại điểm lặp &lt;em&gt;trước đó&lt;/em&gt; để ngoại suy vị trí trước khi áp dụng toán tử gần kề.&lt;/p&gt;

&lt;p&gt;Bước ngoại suy nhìn trước (look-ahead) của FISTA ở bài 09-05-01 có dạng:&lt;/p&gt;

\[\begin{align}
v^{(k)} &amp;amp;= x^{(k-1)}+\frac{k-2}{k+1}\bigl(x^{(k-1)}-x^{(k-2)}\bigr),\\
x^{(k)} &amp;amp;= \operatorname{prox}_{t_k h}\bigl(v^{(k)}-t_k\nabla g(v^{(k)})\bigr).
\end{align}\]

&lt;p&gt;Trọng số \((k-2)/(k+1)\) khởi đầu từ \(0\) (bước đầu tiên trùng với gradient gần kề tiêu chuẩn) và tăng dần tiến tới \(1\). Lịch trình này không phải lựa chọn tùy ý, mà là phiên bản rời rạc của cơ chế tắt dần trong thời gian liên tục giúp hoàn tất chứng minh tốc độ \(O(1/k^2)\) của Nesterov. Bài viết trên Distill của Goh, &lt;em&gt;&lt;a href=&quot;https://distill.pub/2017/momentum/&quot;&gt;Why Momentum Really Works&lt;/a&gt;&lt;/em&gt;, minh họa đúng hình học này trong trường hợp không có prox: một hệ thức truy hồi bậc hai với nghiệm đặc trưng nằm trên đường tròn bán kính \((\sqrt{\kappa}-1)/(\sqrt{\kappa}+1)\), cải thiện hệ số co từ \(1-\Theta(1/\kappa)\) thành \(1-\Theta(1/\sqrt{\kappa})\).&lt;/p&gt;

&lt;h2 id=&quot;tăng-tốc-nesterov-lý-thuyết-và-nesterov-trong-pytorch&quot;&gt;Tăng tốc Nesterov lý thuyết và “Nesterov trong PyTorch”&lt;/h2&gt;

&lt;p&gt;Hai khái niệm mang cùng tên trong giáo trình này có bản chất khác nhau và không thể dùng thay thế cho nhau một cách tùy tiện.&lt;/p&gt;

&lt;p&gt;Trên hàm \(g\) &lt;em&gt;lồi trơn&lt;/em&gt; (hoặc bài toán tổng hợp \(g+h\) với \(h\) lồi), Nesterov / FISTA sử dụng trọng số động lượng &lt;strong&gt;thay đổi theo lịch trình&lt;/strong&gt; và tính gradient của phần trơn tại điểm ngoại suy \(v\). Khi đó ta có bảo đảm \(g(x^{(k)})+h(x^{(k)})-F^\star=O(1/k^2)\), đạt đúng cận dưới lý thuyết của các phương pháp bậc nhất ở &lt;a href=&quot;/contents/vi/chapter06/06_03_06_can_we_do_better/&quot;&gt;06-03-06&lt;/a&gt;. Biểu đồ so sánh ISTA và FISTA trên bài toán Lasso ở &lt;a href=&quot;/contents/vi/chapter09/09_05_03_example_FISTA/&quot;&gt;09-05-03&lt;/a&gt; là kết quả thực nghiệm cần nắm vững.&lt;/p&gt;

&lt;p&gt;Trên &lt;em&gt;mạng nơ-ron sâu&lt;/em&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.optim.SGD(..., nesterov=True)&lt;/code&gt; thường dùng hệ số động lượng &lt;strong&gt;cố định&lt;/strong&gt; \(\beta\approx 0.9\) trên hàm mất mát không lồi. Trực giác về bộ lọc vẫn hữu ích — các hướng nhất quán được tích lũy, các hướng dao động triệt tiêu nhau, và bước nhìn trước giúp giảm hiện tượng vượt đích — nhưng không còn bảo đảm lý thuyết \(O(1/k^2)\). Bài 26-02 phân tích chi tiết sự khác biệt này, bao gồm đa thức đặc trưng của phương pháp heavy-ball và đoạn mã so sánh ngắn bằng NumPy.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;Điểm cốt lõi cần nhớ.&lt;/strong&gt; FISTA là bước nhìn trước Nesterov &lt;em&gt;kết hợp&lt;/em&gt; toán tử gần kề với trọng số thay đổi theo $$k$$. Động lượng trong học sâu dùng cùng ý tưởng nhìn trước nhưng cố định trọng số. Áp dụng định lý theo lịch trình cho các bài toán lồi như Lasso hay hồi quy logistic; dùng trực giác thung lũng của Distill cho các bài toán khác.
&lt;/div&gt;

&lt;h2 id=&quot;khi-tăng-tốc-chưa-chắc-là-lựa-chọn-tối-ưu&quot;&gt;Khi tăng tốc chưa chắc là lựa chọn tối ưu&lt;/h2&gt;

&lt;p&gt;Tăng tốc không mang lại lợi ích miễn phí trong mọi trường hợp. Chính quán tính giúp di chuyển nhanh dọc đáy thung lũng lồi cũng có thể khiến quỹ đạo vượt quá điểm gấp khúc không trơn hoặc vùng cực tiểu hẹp — đó là lý do tồn tại bài &lt;a href=&quot;/contents/vi/chapter09/09_05_04_is_acceleration_always_useful/&quot;&gt;09-05-04&lt;/a&gt; và kỹ thuật khởi động lại (restart) cho FISTA. Nếu phần trơn có chi phí tính thấp và lồi mạnh, phương pháp gradient gần kề được tinh chỉnh tốt (hoặc các phương pháp giảm phương sai ở &lt;a href=&quot;/contents/vi/chapter26/26_05_variance_reduction/&quot;&gt;26-05&lt;/a&gt;) có thể nhanh hơn phương pháp tăng tốc không có restart xét theo thời gian thực thi thực tế. Cần theo dõi giá trị hàm mục tiêu: nếu xuất hiện dao động kiểu “gợn sóng Nesterov”, hãy áp dụng restart hoặc giảm \(\beta\).&lt;/p&gt;

&lt;h3 id=&quot;ista-và-fista-trong-khoảng-3-phút&quot;&gt;ISTA và FISTA trong khoảng 3 phút&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/ista-fista_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;ISTA và FISTA trên lasso: ngưỡng mềm, trọng số (k − 2)/(k + 1), gợn sóng Nesterov, trường hợp tăng tốc làm chậm, và khởi động lại.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài tập.&lt;/strong&gt; Trên thung lũng \(g(x)=\tfrac12 x^\top\operatorname{diag}(1,100)\,x\) với \(h=0\), hãy vẽ đường hội tụ của ISTA (GD tiêu chuẩn), FISTA với trọng số \((k-2)/(k+1)\), và Nesterov với \(\beta\) cố định từ bài 26-02. Phương pháp nào đạt \(\|x\|_2\le 10^{-4}\) sớm nhất, và phương pháp nào dao động quanh gốc tọa độ nếu không dùng restart?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Câu hỏi.&lt;/strong&gt; Trọng số của FISTA tiến tới \(1\), trong khi trọng số heavy-ball tối ưu \(\beta^\star\) theo bài Distill (khi biết số điều kiện \(\kappa\)) luôn nhỏ hơn \(1\) nghiêm ngặt. Vì sao cả hai kết quả này đều đúng — và điều gì thay đổi khi ta &lt;em&gt;không&lt;/em&gt; biết trước \(\kappa\)?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>09-05-04 Tăng tốc có luôn hữu ích không?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_05_04_is_acceleration_always_useful/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_05_04_is_acceleration_always_useful</id>
   <content type="html">&lt;p&gt;Nếu FISTA nhanh hơn ISTA theo lý thuyết từ \(O(1/k)\) lên \(O(1/k^2)\) mà chi phí mỗi vòng gần như bằng nhau, tại sao không mặc định bật tăng tốc cho mọi bài toán tối ưu trên đời? Người làm tối ưu giàu kinh nghiệm hiểu ngay câu ngạn ngữ quen thuộc: &lt;em&gt;“Không có bữa trưa nào hoàn toàn miễn phí.”&lt;/em&gt; Quán tính giúp viên bi lao nhanh dọc thung lũng dài, nhưng chính quán tính ấy cũng làm viên bi &lt;strong&gt;lao lố qua đáy&lt;/strong&gt;, phóng đại nhiễu gradient ngẫu nhiên, và tạo ra những gợn sóng dao động kéo dài trên các bài toán điều kiện xấu!&lt;/p&gt;

&lt;p&gt;Bài học ngắn nhưng cực kỳ thực chiến này giúp bạn phát triển trực giác kỹ sư: biết khi nào FISTA là vũ khí hủy diệt, khi nào nó gây hại (gradient nhiễu, bước prox xấp xỉ không đủ chính xác, bài toán cần giảm đơn điệu tuyệt đối), và cách khắc phục thanh lịch nhất trong thực tế — &lt;strong&gt;khởi động lại thích nghi (adaptive restart)&lt;/strong&gt; của O’Donoghue &amp;amp; Candès (2015).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-tình-huống-giới-hạn-của-kỹ-thuật-tăng-tốc&quot;&gt;Kiến thức cần nhớ: Bốn tình huống giới hạn của kỹ thuật tăng tốc&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Mất tính đơn điệu và gợn sóng Nesterov (Overshooting &amp;amp; Ripples):&lt;/strong&gt; Vì hệ số quán tính \(\beta_k \to 1\) gần như không có ma sát khi \(k\) lớn, điểm lặp thường trượt vượt qua đáy nghiệm rồi vòng ngược lại, tạo ra hình răng cưa trên đồ thị loss.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhạy cảm với nhiễu gradient và sai số prox (Error Accumulation):&lt;/strong&gt; Trong phương pháp không tăng tốc, sai số tính gần đúng ở bước cũ bị tắt dần; còn trong FISTA, hệ số quán tính lớn có thể &lt;em&gt;tích lũy và khuếch đại&lt;/em&gt; sai số của gradient ngẫu nhiên (mini-batch) hoặc sai số giải gần đúng bài toán con prox!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí ẩn khi đánh giá tính đơn điệu (MFISTA):&lt;/strong&gt; Nếu ứng dụng đòi hỏi \(f(x^{(k)})\) không bao giờ tăng (ví dụ tái tạo ảnh y tế cần bảo chứng giảm năng lượng từng bước), biến thể Monotone FISTA phải tính thêm giá trị hàm \(f\) ở mỗi bước và chọn điểm tốt hơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kỹ thuật khởi động lại thích nghi (Adaptive Restart):&lt;/strong&gt; Ngay khi phát hiện đà quán tính đang kéo ngược chiều với hướng giảm (tức \((y^{(k)} - x^{(k+1)})^T(x^{(k+1)} - x^{(k)}) &amp;gt; 0\) hoặc \(f(x^{(k+1)}) &amp;gt; f(x^{(k)})\)), ta đặt lại \(t_k = 1\) (xóa quán tính về \(0\)). Chỉ một câu lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt; ấy xóa sạch gợn sóng và thậm chí đạt hội tụ tuyến tính (hàm mũ) trên các hàm lồi mạnh cục bộ!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-kiểm-tra-điều-kiện-adaptive-restart-khi-fista-trượt-lố&quot;&gt;Giải thích: Tính tay kiểm tra điều kiện Adaptive Restart khi FISTA trượt lố&lt;/h3&gt;

&lt;p&gt;Giả sử trên một bài toán 1D có nghiệm \(x^* = 0\), FISTA đang chạy tới vòng \(k\) với:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Điểm cũ \(x^{(k)} = 0.2\),&lt;/li&gt;
  &lt;li&gt;Điểm ngoại suy trượt lố sang bên kia đáy \(y^{(k)} = -0.3\),&lt;/li&gt;
  &lt;li&gt;Bước prox kéo ngược lại về phía \(0\) nên \(x^{(k+1)} = -0.1\).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra hai vector trong tiêu chuẩn khởi động lại gradient (O’Donoghue–Candès):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hướng dịch chuyển thực tế của bước lặp: \(d_{\text{move}} = x^{(k+1)} - x^{(k)} = -0.1 - 0.2 = -0.3\) (đang lao về bên trái).&lt;/li&gt;
      &lt;li&gt;Hướng ngược bước prox (xấp xỉ gradient tại \(y^{(k)}\)): \(d_{\text{grad}} = y^{(k)} - x^{(k+1)} = -0.3 - (-0.1) = -0.2\) (chỉ sang trái, nghĩa là hướng giảm \(-d_{\text{grad}} = +0.2\) lại đang kéo sang &lt;strong&gt;bên phải&lt;/strong&gt;!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính tích vô hướng kiểm tra:&lt;/strong&gt;
\((y^{(k)} - x^{(k+1)})^T (x^{(k+1)} - x^{(k)}) = (-0.2) \times (-0.3) = +0.06 &amp;gt; 0!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hành động của bộ giải:&lt;/strong&gt; Tích vô hướng &lt;strong&gt;dương&lt;/strong&gt; báo hiệu góc giữa hướng đà quán tính và hướng giảm đang là góc tù — quán tính vừa đẩy ta vượt qua đáy! Thuật toán lập tức &lt;strong&gt;restart&lt;/strong&gt;: đặt lại \(t_{k+1} = 1\) (xóa đà về \(0\)) và đặt \(y^{(k+1)} = x^{(k+1)} = -0.1\) để bước sau tiến thẳng vào \(x^* = 0\) mà không dao động qua lại nữa.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;tăng-tốc-có-luôn-hữu-ích-không&quot;&gt;Tăng tốc có luôn hữu ích không?&lt;/h1&gt;

&lt;p&gt;Mặc dù các phương pháp tăng tốc như FISTA đạt tốc độ hội tụ lý thuyết nhanh hơn, trong thực tế việc dùng tăng tốc không phải lúc nào cũng mang lại hiệu quả tốt hơn.&lt;/p&gt;

&lt;h2 id=&quot;khi-nào-tăng-tốc-có-thể-kém-hiệu-quả&quot;&gt;Khi nào tăng tốc có thể kém hiệu quả&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu bài toán có điều kiện tốt (số điều kiện \(\kappa = L/\mu\) nhỏ), phương pháp gradient gần kề thường đã hội tụ nhanh, với tốc độ tuyến tính. Khi đó tăng tốc lợi rất ít, thậm chí động lượng có thể làm chậm hơn một chút. Ví dụ, với một bài Lasso 2 chiều có \(\kappa = 3\), ISTA cần 14 vòng lặp còn FISTA cần 16 vòng.&lt;/li&gt;
  &lt;li&gt;Tăng tốc có lợi nhất khi bài toán có điều kiện xấu (\(\kappa\) lớn). Lúc đó gradient gần kề thường chạy rất chậm, còn FISTA giảm số vòng lặp đi nhiều lần. Đổi lại, giá trị hàm mục tiêu có thể dao động.&lt;/li&gt;
  &lt;li&gt;Nếu \(g\) không trơn, hoặc \(\nabla g\) không có hằng số Lipschitz phù hợp, thì đảm bảo \(O(1/k^2)\) không còn áp dụng được.&lt;/li&gt;
  &lt;li&gt;Hiện tượng “gợn sóng Nesterov” khiến giá trị hàm mục tiêu không giảm đơn điệu: nó có thể tăng lên vài vòng rồi mới giảm tiếp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kinh-nghiệm-thực-hành&quot;&gt;Kinh nghiệm thực hành&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Nên dùng tăng tốc khi phần trơn của bài toán có điều kiện xấu, vì đó là lúc tăng tốc có lợi nhất.&lt;/li&gt;
  &lt;li&gt;Khi bài toán có điều kiện tốt, phương pháp gradient gần kề thường là đủ.&lt;/li&gt;
  &lt;li&gt;Theo dõi giá trị hàm mục tiêu. Nếu dao động lớn, dùng cơ chế khởi động lại (restart, đặt lại \(t_k = 1\) khi hàm mục tiêu tăng) thay vì bỏ hẳn tăng tốc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kỹ-thuật-làm-trơn-nesterov-smoothing-và-khoảng-cách-dư-excessive-gap&quot;&gt;Kỹ thuật Làm trơn Nesterov (Smoothing) và Khoảng cách Dư (Excessive Gap)&lt;/h2&gt;

&lt;p&gt;Trong giáo trình &lt;em&gt;Lectures on Convex Optimization&lt;/em&gt; (Chương 6), Yurii Nesterov chỉ ra cách phá vỡ cận dưới \(O(1/\varepsilon^2)\) của bài toán lồi &lt;strong&gt;không trơn&lt;/strong&gt; có cấu trúc minimax \(f(x) = \max_{u \in Q_2} \langle Ax, u \rangle - \phi(u)\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bằng cách thêm thành phần điều chuẩn lồi mạnh \(\mu d_2(u)\) vào hàm mục tiêu đối ngẫu, ta thu được hàm xấp xỉ trơn \(f_\mu(x)\) với hằng số Lipschitz \(L_\mu = \|A\|^2 / \mu\).&lt;/li&gt;
  &lt;li&gt;Áp dụng &lt;strong&gt;Phương pháp Gradient Nhanh (FGM)&lt;/strong&gt; lên \(f_\mu(x)\) đạt tốc độ hội tụ &lt;strong&gt;\(O(1/\varepsilon)\)&lt;/strong&gt; thay vì \(O(1/\varepsilon^2)\) của dưới-gradient cổ điển — và kỹ thuật &lt;strong&gt;Khoảng cách Dư (Excessive Gap)&lt;/strong&gt; còn tự động giảm \(\mu_k \to 0\) theo từng vòng lặp mà không cần biết trước độ chính xác \(\varepsilon\).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-05-03 Ví dụ: FISTA</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_05_03_example_FISTA/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_05_03_example_FISTA</id>
   <content type="html">&lt;p&gt;Nếu phải chọn một cái tên duy nhất gắn liền với làn sóng ứng dụng tối ưu lồi vào xử lý ảnh y tế, nén cảm biến (compressed sensing) và học máy thưa suốt 15 năm qua, đó chắc chắn là &lt;strong&gt;FISTA&lt;/strong&gt; (&lt;em&gt;Fast Iterative Shrinkage-Thresholding Algorithm&lt;/em&gt;, Beck &amp;amp; Teboulle 2009). Bài báo gốc của FISTA đã thu hút hàng chục nghìn trích dẫn không phải vì nó phức tạp, mà chính vì sự &lt;strong&gt;giản dị đáng kinh ngạc&lt;/strong&gt; của nó: chỉ vỏn vẹn 4 dòng cập nhật lặp lại, không cần nghịch đảo ma trận, không cần bộ nhớ lớn, nhưng nhanh hơn thuật toán ISTA kinh điển hàng chục đến hàng trăm lần!&lt;/p&gt;

&lt;p&gt;Điểm thú vị phân biệt FISTA với công thức \(\frac{k-2}{k+1}\) ở bài trước là chuỗi hệ số quán tính chuẩn tắc \(t_{k+1} = \frac{1 + \sqrt{1 + 4 t_k^2}}{2}\) (khởi đầu \(t_1 = 1\)) và trọng số ngoại suy \(\frac{t_k - 1}{t_{k+1}}\). Đằng sau công thức căn bậc hai tưởng như huyền bí ấy thực ra chỉ là nghiệm dương của phương trình bậc hai \(t_{k+1}^2 - t_{k+1} = t_k^2\) — điều kiện đại số chính xác để tổng rút gọn trong chứng minh hội tụ khớp từng số hạng!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-tạo-nên-thuật-toán-fista&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép tạo nên thuật toán FISTA&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/chapter09/FISTA.png&quot; alt=&quot;Quỹ đạo hội tụ của thuật toán FISTA&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/chapter_img/chapter09/FISTA2.png&quot; alt=&quot;So sánh tốc độ FISTA O(1/k²) và ISTA O(1/k)&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Từ ISTA đến FISTA:&lt;/strong&gt; ISTA giải \(\min_x \frac{1}{2}\|Ax - b\|_2^2 + \lambda\|x\|_1\) bằng lặp \(x^{(k)} = S_{\eta\lambda}(x^{(k-1)} - \eta A^T(Ax^{(k-1)} - b))\). FISTA giữ nguyên bước co ngưỡng mềm \(S_{\eta\lambda}\), chỉ thay đầu vào từ \(x^{(k-1)}\) sang điểm ngoại suy \(y^{(k)}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuỗi hệ số quán tính \(t_k\):&lt;/strong&gt; Khởi tạo \(t_1 = 1\) và cập nhật \(t_{k+1} = \frac{1 + \sqrt{1 + 4 t_k^2}}{2}\), cho dãy \(1,\; 1.618,\; 2.193,\; 2.752,\dots\) (tăng tuyến tính xấp xỉ \(\frac{k+1}{2}\)). Vì \(t_{k+1}^2 - t_{k+1} = t_k^2\), tỷ lệ \(t_k^2\) tăng theo bậc \(O(k^2)\), trực tiếp tạo ra mẫu số \(O(1/k^2)\) của tốc độ hội tụ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chi phí tính toán gần như miễn phí:&lt;/strong&gt; Phép toán đắt nhất trong Lasso là hai phép nhân ma trận-vector \(A y\) và \(A^T r\) (tốn \(O(mn)\)). Phép ngoại suy \(y^{(k+1)} = x^{(k)} + \frac{t_k - 1}{t_{k+1}}(x^{(k)} - x^{(k-1)})\) chỉ là cộng vector \(O(n)\), chiếm chưa tới 1% thời gian mỗi vòng lặp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn bước \(\eta = 1/L\):&lt;/strong&gt; Với \(g(x) = \frac{1}{2}\|Ax - b\|_2^2\), hằng số Lipschitz chính là bình phương giá trị kỳ dị lớn nhất \(L = \|A\|_2^2 = \lambda_{\max}(A^T A)\) (có thể ước lượng nhanh bằng vài bước lặp lũy thừa power iteration).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-3-bước-đầu-của-fista-kèm-chuỗi-t_k-cho-lasso-1d&quot;&gt;Giải thích: Tính tay 3 bước đầu của FISTA (kèm chuỗi \(t_k\)) cho Lasso 1D&lt;/h3&gt;

&lt;p&gt;Xét bài toán Lasso 1D \(f(x) = \frac{1}{2}(2x - 6)^2 + 2|x|\).
Ở đây \(A = 2\), \(b = 6\), \(\lambda = 2\), nên \(\nabla g(x) = 2(2x - 6) = 4x - 12\) và \(L = A^2 = 4\).
Nghiệm tối ưu: \(4x^* - 12 + 2 = 0 \implies x^* = 2.5\).
Dùng bước an toàn nhỏ hơn cực đại một chút \(\eta = \frac{1}{8} = 0.125\) (ngưỡng co mềm \(\eta\lambda = 0.25\)) để quan sát rõ đà FISTA. Khởi tạo \(x^{(0)} = y^{(1)} = 0\), \(t_1 = 1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(k = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient tại \(y^{(1)} = 0\): \(\nabla g(0) = -12\).&lt;/li&gt;
      &lt;li&gt;\(x^{(1)} = S_{0.25}\big(0 - 0.125(-12)\big) = S_{0.25}(1.5) = 1.25\).&lt;/li&gt;
      &lt;li&gt;Tính \(t_2 = \frac{1 + \sqrt{1 + 4(1)^2}}{2} = \frac{1 + \sqrt{5}}{2} \approx 1.618\) (tỷ lệ vàng!).&lt;/li&gt;
      &lt;li&gt;Trọng số quán tính: \(\beta_1 = \frac{1 - 1}{1.618} = 0 \implies y^{(2)} = 1.25\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(k = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient tại \(y^{(2)} = 1.25\): \(\nabla g(1.25) = 4(1.25) - 12 = -7\).&lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = S_{0.25}\big(1.25 - 0.125(-7)\big) = S_{0.25}(2.125) = 1.875\).&lt;/li&gt;
      &lt;li&gt;Tính \(t_3 = \frac{1 + \sqrt{1 + 4(1.618)^2}}{2} = \frac{1 + \sqrt{11.472}}{2} \approx 2.193\).&lt;/li&gt;
      &lt;li&gt;Trọng số quán tính: \(\beta_2 = \frac{1.618 - 1}{2.193} \approx 0.282\).&lt;/li&gt;
      &lt;li&gt;Điểm ngoại suy: \(y^{(3)} = 1.875 + 0.282(1.875 - 1.25) = 1.875 + 0.176 = 2.051\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước \(k = 3\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient tại \(y^{(3)} = 2.051\): \(\nabla g(2.051) = 4(2.051) - 12 = -3.796\).&lt;/li&gt;
      &lt;li&gt;\(x^{(3)} = S_{0.25}\big(2.051 - 0.125(-3.796)\big) = S_{0.25}(2.5255) = 2.2755\) (còn cách \(x^* = 2.5\) chỉ \(0.2245\), trong khi ISTA ở bước 3 mới tới \(2.1875\), còn cách \(0.3125\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ví-dụ-fista&quot;&gt;Ví dụ: FISTA&lt;/h1&gt;

&lt;p&gt;Trong phần này, chúng ta giới thiệu &lt;strong&gt;Thuật toán Ngưỡng-Co lặp Nhanh (FISTA — Fast Iterative Shrinkage-Thresholding Algorithm)&lt;/strong&gt;, một dạng phổ biến của phương pháp gradient gần kề tăng tốc.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán-fista&quot;&gt;Thuật toán FISTA&lt;/h2&gt;
&lt;p&gt;FISTA giải bài toán tối ưu tổng hợp có dạng:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\min_x g(x) + h(x)\)
trong đó \(g\) là hàm lồi khả vi (với \(\nabla g\) liên tục Lipschitz hằng số \(L\)) và \(h\) là hàm lồi.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Với kích thước bước cố định \(\alpha \le 1/L\), các bước cập nhật của thuật toán là:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Khởi tạo \(x^{(0)} = x^{(-1)}\), \(t_0 = 1\).&lt;/li&gt;
  &lt;li&gt;Với \(k = 1, 2, ...\):
    &lt;ul&gt;
      &lt;li&gt;
\[t_k = \frac{1 + \sqrt{1 + 4 t_{k-1}^2}}{2}\]
      &lt;/li&gt;
      &lt;li&gt;
\[y^{(k)} = x^{(k-1)} + \frac{t_{k-1} - 1}{t_k} (x^{(k-1)} - x^{(k-2)})\]
      &lt;/li&gt;
      &lt;li&gt;
\[x^{(k)} = \text{prox}_{\alpha}\left(y^{(k)} - \alpha \nabla g(y^{(k)})\right)\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(Ở đây dãy \(t_k\) là dãy hệ số động lượng, tách biệt với kích thước bước \(\alpha\).)&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-cho-bài-toán-lasso&quot;&gt;Ứng dụng cho bài toán Lasso&lt;/h2&gt;
&lt;p&gt;FISTA thường được áp dụng cho hồi quy Lasso — bài toán cực tiểu hóa tổng bình phương sai số kèm thành phần chính quy hóa chuẩn \(\ell_1\) — và đạt tốc độ hội tụ nhanh hơn rõ rệt so với phương pháp gradient gần kề tiêu chuẩn (ISTA).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>09-05-02 Phân tích hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_05_02_convergence_analysis/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_05_02_convergence_analysis</id>
   <content type="html">&lt;p&gt;Trong giải tích thuật toán, bước nhảy từ \(O(1/k)\) sang \(O(1/k^2)\) không chỉ là thêm một số mũ nhỏ ở mẫu số — đó là ranh giới giữa việc chờ 10 giây và chờ 3 giờ đồng hồ! Bài học này phát biểu định lý hội tụ chính xác cho phương pháp gradient gần kề tăng tốc: dưới đúng các giả thiết quen thuộc của bài 09-02 (\(g\) lồi với \(\nabla g\) liên tục \(L\)-Lipschitz, \(h\) lồi có prox tính được), sai số giảm theo \(\frac{2\|x^{(0)} - x^*\|_2^2}{t(k+1)^2}\) với bước cố định \(t \le 1/L\) (và giữ nguyên bậc \(O(1/k^2)\) với tìm kiếm đường thẳng lùi).&lt;/p&gt;

&lt;p&gt;Điểm đáng chiêm ngưỡng nhất về mặt lý thuyết là con số \(O(1/k^2)\) này &lt;strong&gt;khớp chặt với cận dưới thông tin của Nemirovski–Yudin&lt;/strong&gt; cho toàn bộ lớp hàm lồi trơn \(L\)-Lipschitz! Nghĩa là không tồn tại bất kỳ thuật toán bậc nhất nào (chỉ dùng giá trị hàm, \(\nabla g\) và \(\operatorname{prox}_h\)) có thể đạt tốc độ tốt hơn \(\Omega(1/k^2)\) trong trường hợp xấu nhất trên không gian chiều cao.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-phân-tích-hội-tụ-tăng-tốc-o1k2&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của phân tích hội tụ tăng tốc \(O(1/k^2)\)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm thế năng Lyapunov (Estimate Sequence):&lt;/strong&gt; Khác với ISTA chỉ cần theo dõi \(f(x^{(k)}) - f^*\) giảm đơn điệu, bản tăng tốc có thể làm \(f\) tạm tăng ở một vài bước. Chứng minh vì thế theo dõi một &lt;em&gt;hàm năng lượng tổng hợp&lt;/em&gt; kết hợp cả sai số hàm \((k+1)^2(f(x^{(k)}) - f^*)\) lẫn bình phương khoảng cách của điểm phụ tới \(x^*\) — và chứng minh tổng năng lượng này không tăng theo \(k\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh hằng số đầu và hệ số tiệm cận:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;ISTA (không tăng tốc): \(f(x^{(k)}) - f^* \le \frac{L\|x^{(0)} - x^*\|_2^2}{2k}\).&lt;/li&gt;
      &lt;li&gt;Tăng tốc (FISTA / APG): \(f(x^{(k)}) - f^* \le \frac{2L\|x^{(0)} - x^*\|_2^2}{(k+1)^2}\).
Ở \(k = 1\) hai cận gần ngang nhau, nhưng ngay từ \(k \ge 4\) tử số lớn gấp 4 lần đã bị mẫu số \((k+1)^2\) đè bẹp hoàn toàn!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường thẳng lùi với bước không tăng:&lt;/strong&gt; Khi dùng backtracking cho phương pháp tăng tốc, ta kiểm tra điều kiện chặn trên parabol của \(g\) tại điểm ngoại suy \(v^{(k)}\) (thay vì \(x^{(k)}\)), và cần chú ý giữ dãy bước \(t_k\) không tăng (hoặc điều chỉnh hệ số \(\theta_k\) theo tỷ lệ \(t_k / t_{k-1}\)) để bảo toàn bất đẳng thức Lyapunov.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-trực-tiếp-cận-sai-số-của-ista-và-tăng-tốc-theo-số-vòng-lặp-k&quot;&gt;Giải thích: Tính trực tiếp cận sai số của ISTA và Tăng tốc theo số vòng lặp \(k\)&lt;/h3&gt;

&lt;p&gt;Giả sử bài toán có \(L = 2\) và khoảng cách khởi điểm \(\|x^{(0)} - x^*\|_2 = 5\) (nên \(L\|x^{(0)} - x^*\|_2^2 = 2 \times 25 = 50\)). Với bước \(t = 1/L = 0.5\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Cận ISTA: \(B_{\text{ISTA}}(k) = \frac{50}{2k} = \frac{25}{k}\).&lt;/li&gt;
  &lt;li&gt;Cận Tăng tốc: \(B_{\text{APG}}(k) = \frac{2 \times 50}{(k+1)^2} = \frac{100}{(k+1)^2}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tại \(k = 10\) vòng lặp:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;ISTA: \(25 / 10 = 2.50\).&lt;/li&gt;
      &lt;li&gt;Tăng tốc: \(100 / 11^2 = 100 / 121 \approx 0.826\) (nhỏ hơn &lt;strong&gt;3 lần&lt;/strong&gt;).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại \(k = 100\) vòng lặp:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;ISTA: \(25 / 100 = 0.25\).&lt;/li&gt;
      &lt;li&gt;Tăng tốc: \(100 / 101^2 = 100 / 10{,}201 \approx 0.0098\) (nhỏ hơn &lt;strong&gt;25.5 lần&lt;/strong&gt;!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số vòng lặp cần để đảm bảo sai số \(\le 0.01\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;ISTA cần \(\frac{25}{k} \le 0.01 \implies k \ge 2{,}500\) vòng lặp.&lt;/li&gt;
      &lt;li&gt;Tăng tốc chỉ cần \(\frac{100}{(k+1)^2} \le 0.01 \implies (k+1)^2 \ge 10{,}000 \implies k \ge 99\) vòng lặp!
Chỉ mất &lt;strong&gt;99 vòng thay vì 2,500 vòng&lt;/strong&gt; — một phép tính tay đủ nói lên toàn bộ giá trị của định lý hội tụ \(O(1/k^2)\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;phân-tích-hội-tụ&quot;&gt;Phân tích hội tụ&lt;/h1&gt;

&lt;p&gt;Trong phần này, chúng ta trình bày kết quả hội tụ của phương pháp gradient gần kề tăng tốc.&lt;/p&gt;

&lt;h2 id=&quot;định-lý-hội-tụ&quot;&gt;Định lý hội tụ&lt;/h2&gt;
&lt;p&gt;Giả sử \(g\) là hàm lồi và khả vi, \(h\) là hàm lồi, và \(\nabla g\) liên tục Lipschitz với hằng số \(L &amp;gt; 0\). Khi đó, phương pháp gradient gần kề tăng tốc với kích thước bước cố định \(t \le 1/L\) thỏa mãn:&lt;/p&gt;

&lt;blockquote&gt;
\[f(x^{(k)}) - f^* \le \frac{2L \lVert x^{(0)} - x^* \rVert^2_2}{(k+1)^2}\]
&lt;/blockquote&gt;

&lt;p&gt;Kết quả này cho thấy tốc độ hội tụ của thuật toán đạt \(O(1/k^2)\), nhanh hơn đáng kể so với tốc độ \(O(1/k)\) của phương pháp gradient gần kề tiêu chuẩn.&lt;/p&gt;

&lt;h2 id=&quot;tìm-kiếm-đường-thẳng-lùi&quot;&gt;Tìm kiếm đường thẳng lùi&lt;/h2&gt;
&lt;p&gt;Tìm kiếm đường thẳng lùi cũng có thể áp dụng cho phương pháp gradient gần kề tăng tốc tương tự như phương pháp gradient gần kề tiêu chuẩn, cho phép điều chỉnh kích thước bước thích ứng khi không biết trước hằng số Lipschitz \(L\).&lt;/p&gt;

&lt;p&gt;Để xem chứng minh chi tiết và phiên bản có tìm kiếm đường thẳng lùi, tham khảo Beck và Teboulle (2009), “A Fast Iterative Shrinkage-Thresholding Algorithm for Linear Inverse Problems” (FISTA).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>09-05-01 Phương pháp gradient gần kề tăng tốc</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_05_01_accelerated_proximal_gradient_method/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_05_01_accelerated_proximal_gradient_method</id>
   <content type="html">&lt;p&gt;Năm 1983, khi Yurii Nesterov công bố phương pháp tăng tốc bậc nhất cho hàm trơn, cộng đồng tối ưu gần như không tin vào mắt mình — làm sao chỉ một phép ngoại suy tuyến tính miễn phí lại phá vỡ được rào cản \(O(1/k)\) vốn thống trị suốt nhiều thập kỷ? Hơn hai mươi năm sau, câu hỏi mở rộng nó sang bài toán tổng hợp không trơn \(f(x) = g(x) + h(x)\) đã được giải quyết trọn vẹn (đặc biệt qua công trình FISTA của Beck &amp;amp; Teboulle 2009 và chuỗi bài của Nesterov 2007), tạo ra &lt;strong&gt;phương pháp gradient gần kề tăng tốc (Accelerated Proximal Gradient Method)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Hãy nhìn vào công thức cập nhật của bài học này: chỉ thêm đúng &lt;em&gt;một dòng&lt;/em&gt; ngoại suy \(v = x^{(k-1)} + \frac{k-2}{k+1}(x^{(k-1)} - x^{(k-2)})\) trước khi gọi bước prox quen thuộc! Chi phí tính toán mỗi vòng lặp gần như &lt;strong&gt;bằng hệt&lt;/strong&gt; phương pháp không tăng tốc (vẫn chỉ 1 lần tính \(\nabla g\) và 1 lần tính \(\operatorname{prox}_{t h}\)), nhưng tốc độ hội tụ nhảy vọt từ \(O(1/\epsilon)\) lên \(O(1/\sqrt{\epsilon})\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-công-thức-gradient-gần-kề-tăng-tốc&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của công thức gradient gần kề tăng tốc&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chuỗi hai điểm (Điểm lặp \(x^{(k)}\) và điểm ngoại suy \(v^{(k)}\)):&lt;/strong&gt; Ta duy trì điểm hợp lệ \(x^{(k)}\) (luôn nằm trong miền của \(h\) và giữ tính thưa) cùng điểm ngoại suy \(v^{(k)} = x^{(k-1)} + \frac{k-2}{k+1}(x^{(k-1)} - x^{(k-2)})\). Bước gradient và prox được thực hiện từ \(v^{(k)}\):
\(x^{(k)} = \operatorname{prox}_{t_k h}\big(v^{(k)} - t_k \nabla g(v^{(k)})\big).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quy luật tăng dần của trọng số quán tính \(\beta_k = \frac{k-2}{k+1}\):&lt;/strong&gt; Ở bước đầu (\(k = 1, 2\)), hệ số bằng \(0\) (khởi động êm như proximal gradient thường); khi \(k\) lớn dần, \(\beta_k \approx 1 - \frac{3}{k}\) tiến sát \(1\). Chính con số \(3\) trong \(1 - 3/k\) gắn chặt với phương trình vi phân bậc hai giảm chấn \(\ddot{X} + \frac{3}{t}\dot{X} + \nabla g(X) = 0\) (Su–Boyd–Candès 2014)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính tương thích với bài toán Lasso và bài toán có ràng buộc:&lt;/strong&gt; Ngay cả khi \(v^{(k)}\) tạm thời nhảy ra ngoài miền ràng buộc \(C\) (hoặc tạm mất tính thưa do cộng hiệu hai vector), bước \(\operatorname{prox}_{t_k h}\) ngay sau đó lập tức kéo \(x^{(k)}\) quay về miền hợp lệ và khôi phục tính thưa!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-3-vòng-lặp-đầu-của-accelerated-proximal-gd-trên-lasso-1d&quot;&gt;Giải thích: Tính tay 3 vòng lặp đầu của Accelerated Proximal GD trên Lasso 1D&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét bài toán Lasso 1D $$f(x) = \frac{1}{2}(x - 5)^2 + 1.0&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((\)g(x) = \frac{1}{2}(x-5)^2, L=1\(), dùng bước cố định nhỏ\)t = 0.5\(để quan sát rõ tác dụng quán tính. Nghiệm tối ưu là\)x^* = 4\(. Khởi tạo\)x^{(0)} = x^{(-1)} = 0$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vòng \(k = 1\) (\(\beta_1 = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v^{(1)} = x^{(0)} = 0\).&lt;/li&gt;
      &lt;li&gt;\(x^{(1)} = S_{0.5}\big(0 - 0.5(0 - 5)\big) = S_{0.5}(2.5) = 2.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng \(k = 2\) (\(\beta_2 = \frac{2-2}{2+1} = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v^{(2)} = x^{(1)} = 2.0\).&lt;/li&gt;
      &lt;li&gt;\(x^{(2)} = S_{0.5}\big(2.0 - 0.5(2.0 - 5)\big) = S_{0.5}(3.5) = 3.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vòng \(k = 3\) (\(\beta_3 = \frac{3-2}{3+1} = 0.25\) — quán tính bắt đầu kích hoạt!):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Ngoại suy: \(v^{(3)} = x^{(2)} + 0.25(x^{(2)} - x^{(1)}) = 3.0 + 0.25(3.0 - 2.0) = 3.25\).&lt;/li&gt;
      &lt;li&gt;Bước gradient + prox tại \(v^{(3)} = 3.25\):
\(x^{(3)} = S_{0.5}\big(3.25 - 0.5(3.25 - 5)\big) = S_{0.5}(3.25 + 0.875) = S_{0.5}(4.125) = 3.625.\)&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;So sánh với không tăng tốc (ISTA cùng \(t=0.5\)):&lt;/em&gt; ISTA ở vòng 3 chỉ đạt \(S_{0.5}(3.0 + 1.0) = 3.500\) (còn cách \(x^*=4\) là \(0.5\)), trong khi bản tăng tốc đã tiến tới \(3.625\) (chỉ còn cách \(0.375\)) ngay từ nhịp quán tính đầu tiên!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;phương-pháp-gradient-gần-kề-tăng-tốc&quot;&gt;Phương pháp gradient gần kề tăng tốc&lt;/h1&gt;

&lt;p&gt;Khi bổ sung kỹ thuật tăng tốc, phương pháp gradient gần kề đạt được tốc độ hội tụ tối ưu \(O(1/\sqrt{\epsilon})\). Trong chuỗi nghiên cứu của mình, Nesterov đã đề xuất bốn phương pháp nổi tiếng, trong đó có ba phương pháp tăng tốc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;1983: Phương pháp tăng tốc đầu tiên cho các hàm trơn&lt;/li&gt;
  &lt;li&gt;1988: Một biến thể tăng tốc khác cho các hàm trơn&lt;/li&gt;
  &lt;li&gt;2005: Kỹ thuật làm trơn hàm không trơn kết hợp với phương pháp tăng tốc năm 1983&lt;/li&gt;
  &lt;li&gt;2007: Phương pháp tăng tốc cho các bài toán tối ưu tổng hợp&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dưới đây, chúng ta trình bày phương pháp của Beck và Teboulle (2008), mở rộng phương pháp Nesterov (1983) cho lớp hàm tổng hợp.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán-gradient-gần-kề-tăng-tốc&quot;&gt;Thuật toán gradient gần kề tăng tốc&lt;/h2&gt;
&lt;p&gt;Tương tự các bài trước, giả sử \(g\) là hàm lồi khả vi và \(h\) là hàm lồi. Xét bài toán:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\min_x g(x) + h(x)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp gradient gần kề tăng tốc&lt;/strong&gt; tận dụng hướng dịch chuyển của bước trước để tránh đổi hướng đột ngột ở bước tiếp theo. Nói cách khác, thuật toán bổ sung một thành phần động lượng tạo quán tính theo hướng tiến triển gần nhất.&lt;/p&gt;

&lt;p&gt;Khởi tạo \(x^{(0)} = x^{(-1)} \in \mathbb{R}^n\). Tại mỗi bước \(k = 1, 2, 3, \dots\), ta tính điểm ngoại suy \(v\) có xét đến động lượng, rồi áp dụng bước gradient gần kề tại \(v\):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
v &amp;amp; = x^{(k-1)} + \frac{k-2}{k + 1}  (x^{(k-1)} −x^{(k-2)}) \\
x^{(k)} &amp;amp; = \text{prox}_{t_k} (v − t_k \nabla g(v)), k = 1,2,3,...  \\
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Ở bước đầu tiên (\(k = 1\)), vì \(x^{(0)} - x^{(-1)} = 0\), điểm \(v\) trùng với \(x^{(0)}\) nên bước cập nhật giống hệt phương pháp gradient gần kề tiêu chuẩn.&lt;/li&gt;
  &lt;li&gt;Từ các bước sau trở đi, \(v\) được dịch thêm một lượng động lượng theo hướng \(x^{(k-1)} - x^{(k-2)}\). Khi \(k\) tăng, trọng số động lượng tăng dần và tiến về \(1\).&lt;/li&gt;
  &lt;li&gt;Khi \(h = 0\), thuật toán trở về &lt;strong&gt;phương pháp gradient tăng tốc (accelerated gradient method)&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hình dưới đây minh họa sự biến thiên của trọng số động lượng theo \(k\). Ở các giá trị \(k\) đầu tiên, trọng số có giá trị âm, nhưng tại \(k = 1\) hiệu \(x^{(0)} - x^{(-1)} = 0\) nên thành phần động lượng triệt tiêu và không gây ảnh hưởng. Khi \(k\) tăng, trọng số tiến gần về \(1\), giúp duy trì quán tính mạnh hơn và tăng tốc độ hội tụ.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter09/momentum_weight.png&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Trọng số động lượng [3]&lt;/figcaption&gt;
&amp;lt;/figure&amp;gt;

## Ví dụ trên bài toán Lasso
Khi áp dụng phương pháp gradient gần kề tăng tốc cho bài toán Lasso đã xét trước đó, đồ thị hội tụ dưới đây cho thấy tốc độ hội tụ vượt trội so với cả phương pháp subgradient và phương pháp gradient gần kề tiêu chuẩn.

Có thể quan sát một đoạn ở giữa đồ thị mà giá trị hàm mục tiêu tạm thời tăng lên — hiện tượng này được gọi là &quot;gợn sóng Nesterov&quot; (Nesterov ripples). Điều này cho thấy phương pháp gradient gần kề tăng tốc không đảm bảo giảm đơn điệu giá trị hàm mục tiêu ở mọi bước lặp.

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter09/accelerated_proximal_gradient.png&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 2] Gradient Gần kề Tăng tốc [3]&lt;/figcaption&gt;
&amp;lt;/figure&amp;gt;
&lt;/p&gt;&lt;/figure&gt;&lt;/p&gt;&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>09-04 Các trường hợp đặc biệt</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_04_special_cases/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_04_special_cases</id>
   <content type="html">&lt;p&gt;Trong toán học, dấu hiệu của một khái niệm thực sự sâu sắc là nó có khả năng “thống nhất nhiều vùng đất tưởng chừng rời rạc dưới cùng một mái nhà”. Phương pháp gradient gần kề chính là một khái niệm như vậy. Khi ta lần lượt bật tắt hai thành phần \(g(x)\) và \(h(x)\) trong bài toán tổng hợp \(\min_x g(x) + h(x)\), hàng loạt thuật toán kinh điển mà bạn đã học trước đây bỗng đồng loạt hiện ra như những lát cắt đặc biệt của cùng một công thức duy nhất!&lt;/p&gt;

&lt;p&gt;Đặt \(h = 0\), ta thu lại ngay &lt;strong&gt;Gradient Descent&lt;/strong&gt;. Đặt \(h = I_C\) (hàm chỉ thị của tập lồi đóng \(C\)), toán tử prox biến thành phép chiếu Euclid \(P_C\) và ta thu lại &lt;strong&gt;Projected Gradient Descent&lt;/strong&gt;. Còn nếu đặt \(g = 0\), ta khám phá ra một thuật toán cực kỳ mạnh mẽ của lý thuyết tối ưu hiện đại: &lt;strong&gt;Thuật toán tối ưu gần kề (Proximal Point / Proximal Minimization Algorithm)&lt;/strong&gt; — thuật toán hội tụ cho &lt;em&gt;mọi&lt;/em&gt; kích thước bước \(t &amp;gt; 0\) lớn tùy ý!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-nhánh-kết-nối-của-phương-pháp-gradient-tổng-quát&quot;&gt;Kiến thức cần nhớ: Bốn nhánh kết nối của phương pháp gradient tổng quát&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(h(x) = 0 \implies\) Gradient Descent cổ điển:&lt;/strong&gt; Khi không có phần không trơn, \(\operatorname{prox}_{t \cdot 0}(v) = \arg\min_z \frac{1}{2t}\|z - v\|_2^2 = v\) (ánh xạ đồng nhất), nên \(x^{(k)} = x^{(k-1)} - t_k \nabla g(x^{(k-1)})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(h(x) = I_C(x) \implies\) Projected Gradient Descent:&lt;/strong&gt; Hàm chỉ thị bằng \(0\) trên \(C\) và \(+\infty\) ngoài \(C\) biến bài toán con prox thành \(\arg\min_{z \in C} \|z - v\|_2^2 = P_C(v)\). Mọi định lý hội tụ \(O(1/k)\) của Chương 09 lập tức áp dụng miễn phí cho bài toán trơn có ràng buộc lồi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(g(x) = 0 \implies\) Thuật toán tối ưu gần kề (Proximal Point Algorithm):&lt;/strong&gt; Công thức \(x^{(k)} = \operatorname{prox}_{t_k h}(x^{(k-1)})\) không cần \(h\) khả vi và không hề bị giới hạn bởi \(t \le 1/L\); bước \(t_k\) càng lớn, mỗi vòng lặp càng tiến gần nghiệm tối ưu toàn cục (nhưng bài toán con càng khó giải).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Toán tử gần kề xấp xỉ (Inexact Proximal Methods):&lt;/strong&gt; Khi \(\operatorname{prox}_{t h}\) không có công thức đóng, ta có thể giải gần đúng bài toán con bằng một vòng lặp trong (inner solver). Để vẫn giữ tốc độ hội tụ \(O(1/k)\), sai số giải bài toán con ở bước \(k\) phải giảm đủ nhanh (cỡ \(\varepsilon_k \sim O(1/k^2)\) hoặc khả tổng).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-so-sánh-gradient-descent-và-proximal-minimization-trên-fx--frac12x2&quot;&gt;Giải thích: Tính tay so sánh Gradient Descent và Proximal Minimization trên \(f(x) = \frac{1}{2}x^2\)&lt;/h3&gt;

&lt;p&gt;Xét hàm đơn giản \(f(x) = \frac{1}{2}x^2\) (nghiệm \(x^* = 0\), độ cong \(L = 1\)), khởi tạo tại \(x^{(0)} = 4\), thử một kích thước bước &lt;strong&gt;rất lớn&lt;/strong&gt; \(t = 3\) (vượt xa ngưỡng \(2/L = 2\) của Gradient Descent!).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Coi \(g(x) = \frac{1}{2}x^2, h(x) = 0\) (Gradient Descent tường minh):&lt;/strong&gt;
\(x^{(1)} = x^{(0)} - t \nabla g(x^{(0)}) = 4 - 3(4) = -8.\)
\(x^{(2)} = -8 - 3(-8) = +16.\)
Dãy bùng nổ ra vô cực vì bước \(t = 3\) vượt ngưỡng ổn định \(2/L = 2\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Coi \(g(x) = 0, h(x) = \frac{1}{2}x^2\) (Proximal Minimization / bước ẩn):&lt;/strong&gt;
Giải bài toán con \(\min_z \left\{\frac{1}{2t}(z - x)^2 + \frac{1}{2}z^2\right\}\) bằng cách cho đạo hàm bằng \(0\):
\(\frac{z - x}{t} + z = 0 \implies z = \frac{x}{1 + t}.\)
Với \(t = 3\) và \(x^{(0)} = 4\):
    &lt;ul&gt;
      &lt;li&gt;
\[x^{(1)} = \frac{4}{1 + 3} = 1.0\]
      &lt;/li&gt;
      &lt;li&gt;
\[x^{(2)} = \frac{1.0}{4} = 0.25\]
      &lt;/li&gt;
      &lt;li&gt;\(x^{(3)} = \frac{0.25}{4} = 0.0625\)!
Càng chọn \(t\) lớn (ví dụ \(t = 99\)), \(x^{(1)} = \frac{4}{100} = 0.04\) tiến thẳng về \(0\) gần như tức thì — đây chính là khác biệt bản chất giữa sơ đồ &lt;em&gt;tường minh&lt;/em&gt; (explicit) và sơ đồ &lt;em&gt;ẩn&lt;/em&gt; (implicit) trong giải tích số!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;các-trường-hợp-đặc-biệt&quot;&gt;Các trường hợp đặc biệt&lt;/h1&gt;

&lt;p&gt;Phương pháp gradient gần kề còn được gọi là phương pháp gradient descent tổng hợp (composite gradient descent) hoặc gradient descent tổng quát (generalized gradient descent).&lt;/p&gt;

&lt;p&gt;Lý do phương pháp này mang tính &lt;strong&gt;“tổng quát”&lt;/strong&gt; là vì nó bao hàm các thuật toán quen thuộc sau như những trường hợp đặc biệt:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(h = 0 \to\) phương pháp gradient descent&lt;/li&gt;
  &lt;li&gt;\(h = I_C \to\) phương pháp gradient descent có chiếu (projected gradient descent)&lt;/li&gt;
  &lt;li&gt;\(g = 0 \to\) thuật toán tối ưu gần kề (proximal minimization algorithm)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nhờ cùng nằm trong khuôn khổ chung này, tất cả các thuật toán trên đều thừa hưởng tốc độ hội tụ \(O(1/\epsilon)\).&lt;/p&gt;

&lt;h2 id=&quot;gradient-descent-có-chiếu-projected-gradient-descent&quot;&gt;Gradient descent có chiếu (Projected gradient descent)&lt;/h2&gt;
&lt;p&gt;Với \(I_C(x)\) là hàm chỉ thị của một tập lồi đóng \(C \subseteq \mathbb{R}^n\), bài toán tối ưu có ràng buộc trên tập \(C\) có thể được viết lại thành bài toán không ràng buộc như sau (lưu ý \(C\) cần là tập đóng để phép chiếu được xác định duy nhất):&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x \in C} g(x) \iff \min_x g(x) + I_C(x)\]

\[I_C(x) = 
\begin{cases}
0, &amp;amp; x \in C \\
\infty, &amp;amp; x \notin C
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;Khi đó, ánh xạ gần kề của \(I_C\) là:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{prox}_t(x)  
&amp;amp;= \underset{z}{\text{argmin}} \frac{1}{2t} \lVert x−z \rVert_2^2 + I_C(z) \\
&amp;amp; = \underset{z \in C}{\text{argmin}} \lVert x−z \rVert_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó \(\text{prox}_t(x) = P_C(x)\) chính là phép chiếu Euclid lên tập \(C\).&lt;/p&gt;

&lt;p&gt;Bước cập nhật gradient gần kề trở thành \(x^+ = P_C (x−t \nabla g(x) )\): sau khi thực hiện một bước gradient descent, ta chiếu điểm vừa thu được trở về tập khả thi \(C\).&lt;/p&gt;

&lt;p&gt;Trong hình minh họa dưới đây, hình chữ nhật màu hồng là tập khả thi \(C\). Khi bước gradient descent đưa điểm lặp ra ngoài \(C\), phép chiếu \(P_C\) đưa điểm đó quay lại điểm gần nhất thuộc \(C\).&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter09/projected_gradient_descent.png&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Projected Gradient Descent [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;thuật-toán-tối-ưu-gần-kề-proximal-minimization-algorithm&quot;&gt;Thuật toán tối ưu gần kề (Proximal Minimization Algorithm)&lt;/h2&gt;

&lt;p&gt;Xét bài toán cực tiểu hóa một hàm lồi \(h\) không nhất thiết khả vi, tương ứng với trường hợp \(g(x) = 0\):&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\min_x h(x)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Công thức lặp gradient gần kề rút gọn thành:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x^{(k)} &amp;amp;= \text{prox}_{t_k} \big(x^{(k-1)} - t_k \nabla g ( x^{(k-1)} ) \big) , \qquad k = 1, 2, 3, ... \\
&amp;amp;= \text{prox}_{t_k} \big(x^{(k-1)} \big) ,  \qquad \qquad \qquad \qquad \; k = 1, 2, 3, ... \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Hay viết tường minh:&lt;/p&gt;
&lt;blockquote&gt;
\[x^+ = \underset{z}{\text{argmin}} \frac{1}{2t} \lVert x−z \rVert_2^2 + h(z)\]
&lt;/blockquote&gt;

&lt;p&gt;Thuật toán này được gọi là &lt;strong&gt;thuật toán tối ưu gần kề (PMA)&lt;/strong&gt;. Về số bước lặp, PMA hội tụ nhanh hơn phương pháp subgradient; tuy nhiên, thuật toán chỉ thực sự hữu ích khi ánh xạ gần kề của \(h\) có thể tính được hiệu quả (ví dụ ở dạng đóng).&lt;/p&gt;

&lt;h2 id=&quot;khi-ánh-xạ-gần-kề-không-thể-tính-chính-xác&quot;&gt;Khi ánh xạ gần kề không thể tính chính xác&lt;/h2&gt;
&lt;p&gt;Về mặt lý thuyết, khi áp dụng phương pháp gradient gần kề cho \(f = g + h\), ta giả định bài toán con xác định \(\text{prox}_t(x)\) được giải chính xác:&lt;/p&gt;
&lt;blockquote&gt;
\[\text{prox}_t(x )= \underset{z}{\text{argmin}} \frac{1}{2t} \lVert x−z \rVert_2^2 + h(z)\]
&lt;/blockquote&gt;

&lt;p&gt;Nếu bài toán con này chỉ được giải xấp xỉ, nhìn chung không tự động đảm bảo kết quả hội tụ ban đầu. Tuy nhiên, nếu sai số xấp xỉ của toán tử gần kề giảm đủ nhanh và được kiểm soát chặt chẽ, tốc độ hội tụ ban đầu vẫn được bảo toàn (Schmidt et al. (2011), Convergence rates of inexact proximal-gradient methods for convex optimization).&lt;/p&gt;

&lt;p&gt;Trong thực hành, khi phải tính gần đúng \(\text{prox}_t\), người ta thường giải bài toán con với độ chính xác cao.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>09-03 Ví dụ: hoàn thiện ma trận</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_03_example_matrix_completion/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_03_example_matrix_completion</id>
   <content type="html">&lt;p&gt;Năm 2006, Netflix treo giải thưởng 1 triệu đô la cho bất kỳ đội ngũ nào cải thiện hệ thống gợi ý phim thêm 10%. Bài toán cốt lõi nghe rất giản dị: bạn có một bảng khổng lồ gồm hàng trăm nghìn người dùng và hàng chục nghìn bộ phim, nhưng hơn 98% số ô trong bảng bị bỏ trống vì mỗi người chỉ chấm điểm vài chục phim. Làm thế nào để điền chính xác những ô trống còn lại?&lt;/p&gt;

&lt;p&gt;Nếu ma trận điểm số hoàn toàn ngẫu nhiên thì bài toán vô nghiệm. Chìa khóa cứu rỗi là giả thiết &lt;strong&gt;hạng thấp (low-rank)&lt;/strong&gt;: thị hiếu của hàng trăm nghìn người thực chất chỉ bị chi phối bởi vài chục “nhân tố ẩn” (thể loại, đạo diễn, độ hài hước…). Nhưng cực tiểu hóa \(\operatorname{rank}(X)\) lại là bài toán NP-khó! Giống như cách chuẩn \(\ell_1\) thay thế cho chuẩn \(\ell_0\) (số phần tử khác 0) ở vector, &lt;strong&gt;chuẩn vết / chuẩn hạt nhân&lt;/strong&gt; \(\|X\|_* = \sum_i \sigma_i(X)\) (tổng các giá trị kỳ dị) là bao lồi chặt nhất của \(\operatorname{rank}(X)\). Và khi đưa vào phương pháp gradient gần kề, toán tử prox của chuẩn hạt nhân hóa ra có một vẻ đẹp đối xứng đến ngỡ ngàng: &lt;strong&gt;co ngưỡng mềm trực tiếp lên các giá trị kỳ dị của SVD!&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-bài-toán-hoàn-thiện-ma-trận&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của bài toán hoàn thiện ma trận&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phân rã giá trị kỳ dị (SVD) và hạng ma trận:&lt;/strong&gt; Mọi ma trận \(X \in \mathbb{R}^{m \times n}\) đều viết được dưới dạng \(X = U \Sigma V^T\) với các giá trị kỳ dị \(\sigma_1 \ge \sigma_2 \ge \dots \ge \sigma_r &amp;gt; 0\). Hạng của \(X\) chính là số lượng giá trị kỳ dị khác \(0\) — tức là chuẩn \(\ell_0\) của vector \(\sigma(X)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn vết / Chuẩn hạt nhân (Trace / Nuclear Norm):&lt;/strong&gt; Thay \(\|\sigma(X)\|_0\) bằng \(\|\sigma(X)\|_1 = \sum_{i=1}^r \sigma_i(X) = \|X\|_*\) biến bài toán tìm ma trận hạng thấp thành một bài toán tối ưu lồi không trơn nhưng toàn cục!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Toán tử chiếu lên tập quan sát \(P_\Omega(X)\):&lt;/strong&gt; Tập chỉ số \(\Omega\) ghi lại các ô đã biết điểm. Phần trơn của hàm mục tiêu là \(g(X) = \frac{1}{2}\|P_\Omega(X) - P_\Omega(Y)\|_F^2\), có gradient cực gọn \(\nabla g(X) = P_\Omega(X - Y)\) với hằng số Lipschitz \(L = 1\) (cho phép dùng bước cố định \(t = 1\)!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý co ngưỡng giá trị kỳ dị (Singular Value Thresholding — SVT):&lt;/strong&gt; Toán tử gần kề của \(\lambda\|X\|_*\) là:
\(\operatorname{prox}_{\lambda \|\cdot\|_*}(Z) = U \cdot \operatorname{diag}\big(\max(\sigma_i - \lambda, 0)\big) \cdot V^T.\)
Các giá trị kỳ dị nhỏ hơn \(\lambda\) bị cắt thẳng về \(0\), hạ thấp trực tiếp hạng của ma trận sau mỗi bước lặp!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-1-bước-thuật-toán-soft-impute-proximal-gd-cho-ma-trận-2-times-2&quot;&gt;Giải thích: Tính tay 1 bước thuật toán Soft-Impute (Proximal GD) cho ma trận \(2 \times 2\)&lt;/h3&gt;

&lt;p&gt;Giả sử ta quan sát 3 ô của một ma trận \(2 \times 2\) và khuyết ô \((2, 2)\) (đánh dấu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?&lt;/code&gt;):
\(Y = \begin{pmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; ? \end{pmatrix}, \quad \Omega = \{(1,1), (1,2), (2,1)\}.\)
Xét bài toán \(\min_X \frac{1}{2}\|P_\Omega(X) - P_\Omega(Y)\|_F^2 + \lambda\|X\|_*\) với \(\lambda = 1.5\), bước cố định \(t = 1\) (vì \(L = 1\)). Khởi tạo \(X^{(0)} = \begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhịp 1 — Bước gradient trên phần quan sát \(\Omega\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Hiệu trên các ô quan sát: \(P_\Omega(X^{(0)} - Y) = \begin{pmatrix} 2 - 4 &amp;amp; 0 - 0 \\ 0 - 0 &amp;amp; 0 \end{pmatrix} = \begin{pmatrix} -2 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{pmatrix}\) (ô khuyết \((2,2)\) luôn có gradient bằng \(0\)!).&lt;/li&gt;
      &lt;li&gt;Ma trận trung gian \(Z^{(1)} = X^{(0)} - 1 \cdot \nabla g(X^{(0)}) = \begin{pmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix} - \begin{pmatrix} -2 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{pmatrix} = \begin{pmatrix} 4 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{pmatrix}\).
(Nhận xét trực giác: \(Z^{(1)}\) giữ nguyên giá trị dự đoán cũ ở ô khuyết, và kéo các ô quan sát về đúng dữ liệu \(Y\)!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhịp 2 — Phân rã SVD và co ngưỡng mềm giá trị kỳ dị với \(\lambda = 1.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Vì \(Z^{(1)}\) đã là ma trận đường chéo không âm, các giá trị kỳ dị là \(\sigma_1 = 4\) và \(\sigma_2 = 2\) (\(U = V = I_2\)).&lt;/li&gt;
      &lt;li&gt;Áp dụng \(\max(\sigma_i - 1.5, 0)\):
\(\sigma_1&apos; = \max(4 - 1.5, 0) = 2.5, \quad \sigma_2&apos; = \max(2 - 1.5, 0) = 0.5.\)&lt;/li&gt;
      &lt;li&gt;Kết quả sau bước 1: \(X^{(1)} = \begin{pmatrix} 2.5 &amp;amp; 0 \\ 0 &amp;amp; 0.5 \end{pmatrix}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều gì xảy ra nếu ta tăng lực phạt lên \(\lambda = 2.5\)?&lt;/strong&gt;
Khi đó \(\sigma_2&apos; = \max(2 - 2.5, 0) = 0\), nên \(X^{(1)} = \begin{pmatrix} 1.5 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{pmatrix}\) có &lt;strong&gt;hạng đúng bằng 1&lt;/strong&gt;! Bằng cách lặp lại hai nhịp “điền dữ liệu quan sát \(\to\) co ngưỡng SVD”, thuật toán vừa khớp các ô đã biết vừa ép cấu trúc hạng thấp lên toàn ma trận.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;ví-dụ-hoàn-thiện-ma-trận-matrix-completion&quot;&gt;Ví dụ: hoàn thiện ma trận (Matrix completion)&lt;/h1&gt;

&lt;p&gt;Trong nhiều bài toán thực tế, dữ liệu đo đạc được biểu diễn dưới dạng ma trận, trong đó phần lớn các phần tử bị thiếu và chỉ một số ít phần tử được quan sát. Bài toán dự đoán các phần tử bị thiếu từ các phần tử đã biết được gọi là &lt;strong&gt;hoàn thiện ma trận (matrix completion)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Một ứng dụng quen thuộc là hệ thống gợi ý, nơi ta cần ước lượng mức độ quan tâm của người dùng đối với những sản phẩm hoặc dịch vụ mà họ chưa từng đánh giá.&lt;/p&gt;

&lt;h2 id=&quot;phát-biểu-bài-toán-hoàn-thiện-ma-trận&quot;&gt;Phát biểu bài toán hoàn thiện ma trận&lt;/h2&gt;
&lt;p&gt;Cho ma trận dữ liệu quan sát \(Y \in \mathbb{R}^{m\times n}\), với \(\Omega\) là tập hợp các chỉ số \((i,j)\) tại đó giá trị \(Y_{ij}\) đã được quan sát. Ta cần tìm ma trận ước lượng \(B\) để điền vào các vị trí bị thiếu thông qua bài toán tối ưu:&lt;/p&gt;

&lt;blockquote&gt;
\[\min_B \frac{1}{2} \sum_{(i,j)\in\Omega} (Y_{ij} −B_{ij})^2 + \lambda\lVert B \rVert_{tr}\]
&lt;/blockquote&gt;

&lt;p&gt;Số hạng thứ nhất đo sai số bình phương giữa \(B\) và dữ liệu quan sát được trên \(\Omega\), còn số hạng thứ hai khuyến khích ma trận \(B\) có hạng thấp (dựa trên giả định rằng ma trận dữ liệu nằm gần một không gian chiều thấp). Nhờ đó, \(B\) khôi phục các phần tử còn thiếu theo cấu trúc hạng thấp phù hợp với các quan sát hiện có.&lt;/p&gt;

&lt;h3 id=&quot;tham-khảo-chuẩn-vết-trace-norm&quot;&gt;[Tham khảo] Chuẩn vết (Trace Norm)&lt;/h3&gt;
&lt;p&gt;Chuẩn vết (hay chuẩn hạt nhân — nuclear norm) của một ma trận được định nghĩa là tổng các giá trị kỳ dị của nó:&lt;/p&gt;

&lt;blockquote&gt;
\[\lVert B \rVert_{tr} = \text{trace}(\sqrt{B^* B}) = \sum_{i=1}^r \sigma_i(B), \quad r = rank(B)\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(B^* B\) là ma trận nửa xác định dương và các giá trị kỳ dị được sắp theo thứ tự giảm dần \(\sigma_1(B) \ge ... \ge \sigma_r(B) \ge 0\).&lt;/p&gt;

&lt;h3 id=&quot;tham-khảo-chính-quy-hóa-chuẩn-ell_1-và-chuẩn-vết&quot;&gt;[Tham khảo] Chính quy hóa chuẩn \(\ell_1\) và chuẩn vết&lt;/h3&gt;
&lt;p&gt;Bài toán trên có thể xem như phiên bản ma trận của bài toán ngưỡng mềm vector: chuẩn \(\ell_1\) cho vector (\(\lVert \cdot \rVert_{1}\)) được thay bằng chuẩn vết cho ma trận (\(\lVert \cdot \rVert_{tr}\)), với vai trò hoàn toàn tương tự.&lt;/p&gt;

&lt;p&gt;Trong khi chuẩn \(\ell_1\) thúc đẩy tính thưa của các phần tử trong vector, chuẩn vết thúc đẩy tính thưa trên vector các giá trị kỳ dị của ma trận. Với ma trận đường chéo, các phần tử đường chéo chính là các giá trị kỳ dị, nên cực tiểu hóa chuẩn vết tương đương với cực tiểu hóa chuẩn \(\ell_1\) của vector đường chéo. Theo nghĩa đó, chuẩn vết \(\lVert B \rVert_{tr}\) đóng vai trò là xấp xỉ lồi cho \(\text{Rank}(B)\).&lt;/p&gt;

&lt;h2 id=&quot;áp-dụng-phương-pháp-gradient-gần-kề&quot;&gt;Áp dụng phương pháp gradient gần kề&lt;/h2&gt;
&lt;p&gt;Để đưa bài toán về dạng tổng hợp chuẩn của phương pháp gradient gần kề, ta định nghĩa toán tử chiếu lên tập chỉ số quan sát.&lt;/p&gt;

&lt;h3 id=&quot;toán-tử-chiếu&quot;&gt;Toán tử chiếu&lt;/h3&gt;
&lt;p&gt;Định nghĩa toán tử chiếu \(P_\Omega\) như sau:&lt;/p&gt;

&lt;blockquote&gt;
\[[ P_\Omega(B) ] _{ij} =
\begin{cases}
B_{ij}, &amp;amp; (i,j) ∈ \Omega \\\
0, &amp;amp; (i,j) \notin \Omega
\end{cases}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;hàm-mục-tiêu&quot;&gt;Hàm mục tiêu&lt;/h3&gt;
&lt;p&gt;Sử dụng toán tử chiếu, hàm mục tiêu được viết gọn thành:&lt;/p&gt;

&lt;blockquote&gt;
\[f(B) = \underbrace{ \frac{1}{2} \lVert P_\Omega(Y) − P_\Omega(B) \rVert_F^2 }_{g(B)} + \underbrace{ \lambda \lVert B \rVert_{tr} }_{h(B)}\]
&lt;/blockquote&gt;

&lt;p&gt;Khi đó, \(f(B)\) được tách thành phần khả vi \(g(B)\) và phần không khả vi \(h(B)\).&lt;/p&gt;

&lt;h3 id=&quot;ánh-xạ-gần-kề&quot;&gt;Ánh xạ gần kề&lt;/h3&gt;
&lt;p&gt;Để áp dụng phương pháp gradient gần kề, ta cần gradient của \(g(B)\) và ánh xạ gần kề của \(h(B)\):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Gradient của \(g(B)\): \(\nabla g(B) = −(P_\Omega(Y )−P_\Omega(B))\).&lt;/li&gt;
  &lt;li&gt;Ánh xạ gần kề:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{prox}_t (B) = \underset{Z}{\text{argmin}} \frac{1}{2t} \Vert B−Z \Vert_F^2 + \lambda \Vert Z \Vert_{tr}
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;phân-tích-svd-và-toán-tử-ngưỡng-mềm-ma-trận&quot;&gt;Phân tích SVD và toán tử ngưỡng mềm ma trận&lt;/h3&gt;
&lt;p&gt;Ánh xạ gần kề trên chính là toán tử ngưỡng mềm ma trận ở mức \(\lambda t\): \(\text{prox}_t(B) = S_{\lambda t}(B)\).&lt;/p&gt;

&lt;p&gt;Nếu phân tích giá trị kỳ dị (SVD) của \(B\) là \(B = U \Sigma V^T\), thì toán tử ngưỡng mềm ma trận \(S_\lambda(B)\) được tính bởi:&lt;/p&gt;

&lt;blockquote&gt;
\[S_\lambda(B) = U \Sigma_\lambda V^T\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\Sigma_\lambda\) là ma trận đường chéo với các phần tử:&lt;/p&gt;

&lt;blockquote&gt;
\[(\Sigma_\lambda)_{ii} = \max \{ \Sigma_{ii} −\lambda,0 \}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;tham-khảo-cách-suy-ra-công-thức-sigma_lambda_ii--max--sigma_ii-lambda0-&quot;&gt;[Tham khảo] Cách suy ra công thức \((\Sigma_\lambda)_{ii} = \max \{ \Sigma_{ii} −\lambda,0 \}\)&lt;/h3&gt;
&lt;p&gt;Đặt \(Z = \text{prox}_t(B)\). Từ điều kiện tối ưu bậc một theo biến \(Z\) của bài toán định nghĩa \(\text{prox}_t(B)\), ta có:&lt;/p&gt;

&lt;blockquote&gt;
\[0 ∈ Z − B + \lambda t \cdot \partial \lVert Z \rVert_{tr}\]
&lt;/blockquote&gt;

&lt;p&gt;Biến đổi biểu thức trên với \(t = 1\) (tương ứng hằng số Lipschitz \(L = 1\)) và chọn thành phần \(W = 0\) cho các giá trị kỳ dị dương:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
Z &amp;amp; = B - \lambda t \cdot \partial \lVert Z \rVert_{tr} \\
 &amp;amp; = U \Sigma V^T - \lambda t \cdot (UV^T + W) \\
 &amp;amp; = U (\Sigma - \lambda t) V^T - \lambda t  W \\
 &amp;amp; = U (\Sigma - \lambda ) V^T  \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Do đó \(\text{prox}_1(B) = S_\lambda(B) = Z\), với các giá trị kỳ dị được co ngưỡng mềm theo công thức:&lt;/p&gt;

&lt;blockquote&gt;
\[(\Sigma_\lambda)_{ii} = \max \{ \Sigma_{ii} −\lambda,0 \}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;tham-khảo-vi-phân-dưới-của-chuẩn-vết&quot;&gt;[Tham khảo] Vi phân dưới của chuẩn vết&lt;/h3&gt;
&lt;p&gt;Với phân tích SVD rút gọn \(Z = U \Sigma V^T\), vi phân dưới của chuẩn vết được cho bởi:&lt;/p&gt;
&lt;blockquote&gt;
\[\partial \lVert Z \rVert_{tr} = \{UV^T + W : \lVert W \rVert_{op} ≤ 1, U^TW = 0, WV = 0 \}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\lVert W \rVert_{op}\) là chuẩn toán tử (giá trị kỳ dị lớn nhất của \(W\)) không vượt quá 1, và không gian cột/hàng của \(W\) trực giao với \(U\) và \(V\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tham khảo chứng minh chi tiết tại: &lt;a href=&quot;https://math.stackexchange.com/questions/701062/derivative-of-the-nuclear-norm-with-respect-to-its-argument&quot;&gt;Derivative of the nuclear norm with respect to its argument&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bước-cập-nhật-gradient-gần-kề&quot;&gt;Bước cập nhật gradient gần kề&lt;/h3&gt;
&lt;p&gt;Công thức cập nhật gradient gần kề cho bài toán hoàn thiện ma trận là:&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = S_{\lambda t} ( B + t( P_\Omega(Y) − P_\Omega(B) ) )\]
&lt;/blockquote&gt;

&lt;p&gt;Vì \(\nabla g(B)\) liên tục Lipschitz với hằng số \(L = 1\), ta có thể chọn kích thước bước cố định \(t = 1\). Khi đó, công thức cập nhật rút gọn thành:&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = S_\lambda (P_\Omega(Y) + P_\Omega^\bot (B) )\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(P_\Omega^\bot\) là phép chiếu lên tập các vị trí không quan sát được, thỏa mãn \(P_\Omega(B) + P_\Omega^\bot (B) = B\).&lt;/p&gt;

&lt;p&gt;Trong biểu thức này, \(P_\Omega(Y)\) giữ nguyên các giá trị đã quan sát, còn \(P_\Omega^\bot (B)\) lấy các giá trị ước lượng hiện tại ở các vị trí bị thiếu. Sau đó, phép tính \(S_\lambda\) chỉ cần thực hiện phân tích SVD và áp dụng co ngưỡng \((\Sigma_\lambda)_{ii} = \max \{ \Sigma_{ii} −\lambda,0 \}\).&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán-soft-impute&quot;&gt;Thuật toán Soft-Impute&lt;/h2&gt;
&lt;p&gt;Thuật toán thu được có tên gọi là &lt;strong&gt;Soft-Impute&lt;/strong&gt;, mang lại cách giải đơn giản và hiệu quả cho bài toán hoàn thiện ma trận. Dù chi phí SVD trên ma trận cỡ lớn có thể cao, nhưng nhờ cấu trúc đặc biệt gồm một ma trận thưa \(P_\Omega(Y)\) cộng với một ma trận hạng thấp \(P_\Omega^\bot (B)\), phép phân tích SVD trong Soft-Impute có thể được thực hiện rất hiệu quả.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tham khảo thêm: Mazumder et al. (2011), “Spectral regularization algorithms for learning large incomplete matrices”.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-02 Phân tích hội tụ</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_02_convergence_analysis/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_02_convergence_analysis</id>
   <content type="html">&lt;p&gt;Vì sao phương pháp gradient gần kề lại vượt xa phương pháp subgradient cả một bậc tốc độ — từ \(O(1/\epsilon^2)\) nhảy vọt lên \(O(1/\epsilon)\) — dù cùng giải bài toán không trơn? Câu trả lời nằm trong &lt;strong&gt;độ dốc tổng quát (generalized gradient map)&lt;/strong&gt; \(G_t(x) = \frac{1}{t}\big(x - \operatorname{prox}_{t h}(x - t\nabla g(x))\big)\). Khi viết lại vòng lặp dưới dạng \(x^+ = x - t G_t(x)\), ta nhận ra một phép màu giải tích: gần như toàn bộ chứng minh hội tụ của gradient descent trên hàm trơn được “tái sinh” gần như nguyên vẹn!&lt;/p&gt;

&lt;p&gt;Tuy nhiên, trong thực hành có một trở ngại quen thuộc: ta hiếm khi biết trước hằng số Lipschitz \(L\) của \(\nabla g\) (chẳng hạn với ma trận \(A\) khổng lồ, tính giá trị kỳ dị lớn nhất \(\|A\|_2^2\) rất tốn kém). Đó là lý do nửa sau bài học giới thiệu &lt;strong&gt;tìm kiếm đường thẳng lùi (backtracking line search)&lt;/strong&gt; cho bài toán tổng hợp — một điều kiện dừng tinh gọn chỉ kiểm tra độ cong trên riêng phần trơn \(g\) mà vẫn bảo toàn nguyên vẹn tốc độ \(O(1/k)\).&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-trụ-cột-của-chứng-minh-hội-tụ-gradient-gần-kề&quot;&gt;Kiến thức cần nhớ: Bốn trụ cột của chứng minh hội tụ gradient gần kề&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bất đẳng thức trơn \(L\)-Lipschitz của \(\nabla g\):&lt;/strong&gt; Mọi hàm \(g\) có \(\nabla g\) liên tục \(L\)-Lipschitz đều bị chặn trên bởi parabol:
\(g(y) \le g(x) + \nabla g(x)^T(y - x) + \frac{L}{2}\|y - x\|_2^2.\)
Điều kiện \(t \le 1/L\) đảm bảo mô hình parabol dùng trong bước prox luôn nằm trên \(g(y)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bản đồ gradient tổng quát \(G_t(x)\) và tính giảm đơn điệu:&lt;/strong&gt; Định nghĩa \(G_t(x) = \frac{x - x^+}{t}\). Theo điều kiện tối ưu của bài toán con prox, \(G_t(x) - \nabla g(x) \in \partial h(x^+)\). Từ đó suy ra bất đẳng thức giảm cốt lõi cho mọi điểm \(z\):
\(f(x^+) \le f(z) + G_t(x)^T(x - z) - \frac{t}{2}\|G_t(x)\|_2^2.\)
Đặt \(z = x\) cho ngay \(f(x^+) \le f(x) - \frac{t}{2}\|G_t(x)\|_2^2\) (giảm chặt đơn điệu!); đặt \(z = x^*\) và cộng dồn cho ra ngay cận \(\frac{\|x^{(0)} - x^*\|_2^2}{2 t k}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm kiếm đường thẳng lùi (Backtracking Line Search):&lt;/strong&gt; Khi không biết \(L\), ta bắt đầu từ \(t\) lớn và nhân \(t \leftarrow \beta t\) (\(\beta \in (0, 1)\)) cho tới khi thỏa điều kiện chặn trên parabol cho riêng phần trơn \(g\):
\(g(x - t G_t(x)) \le g(x) - t\nabla g(x)^T G_t(x) + \frac{t}{2}\|G_t(x)\|_2^2.\)
Lưu ý: mỗi lần thu nhỏ \(t\) phải tính lại \(x^+ = \operatorname{prox}_{t h}(x - t\nabla g(x))\), nên \(h\) cần có prox thật nhẹ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bảo toàn hằng số tốc độ khi dùng backtracking:&lt;/strong&gt; Vì điều kiện backtracking chắc chắn dừng ngay khi \(t \le 1/L\), bước được chọn luôn thỏa \(t_k \ge \min(t_0, \beta/L)\), nên cận hội tụ chỉ tăng thêm tối đa một hệ số hằng \(1/\beta\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-kiểm-chứng-tay-điều-kiện-backtracking-và-cận-o1k&quot;&gt;Giải thích: Kiểm chứng tay điều kiện backtracking và cận \(O(1/k)\)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Xét \(g(x) = 2x^2\) (nên \(\nabla g(x) = 4x\) và \(L = 4\), ngưỡng an toàn là \(1/L = 0.25\)) và $$h(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((nghiệm tối ưu\)x^* = 0, f^* = 0\(). Bắt đầu từ\)x^{(0)} = 1\(, giả sử ta *không biết*\)L = 4\(và thử backtracking với\)t = 1.0\(, hệ số thu hẹp\)\beta = 0.5$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thử \(t = 1.0\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v = x^{(0)} - 1.0 \cdot \nabla g(1) = 1 - 4 = -3\).&lt;/li&gt;
      &lt;li&gt;\(x^+ = S_{1.0}(-3) = -2\), suy ra \(G_1(1) = \frac{1 - (-2)}{1} = 3\).&lt;/li&gt;
      &lt;li&gt;Kiểm tra điều kiện backtracking trên \(g(x) = 2x^2\):
        &lt;ul&gt;
          &lt;li&gt;Vế trái: \(g(x^+) = 2(-2)^2 = 8\).&lt;/li&gt;
          &lt;li&gt;Vế phải: \(g(1) - 1(4)(3) + \frac{1}{2}(3)^2 = 2 - 12 + 4.5 = -5.5\).&lt;/li&gt;
          &lt;li&gt;Vì \(8 &amp;gt; -5.5\), điều kiện &lt;strong&gt;vi phạm&lt;/strong&gt; \(\implies\) thu nhỏ \(t \leftarrow 0.5\)!&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử \(t = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v = 1 - 0.5(4) = -1\), \(x^+ = S_{0.5}(-1) = -0.5\), \(G_{0.5}(1) = \frac{1 - (-0.5)}{0.5} = 3\).&lt;/li&gt;
      &lt;li&gt;Vế trái: \(g(-0.5) = 0.5\); vế phải: \(2 - 0.5(4)(3) + \frac{0.5}{2}(9) = 2 - 6 + 2.25 = -1.75\). Vẫn vi phạm (\(0.5 &amp;gt; -1.75\)) \(\implies\) thu nhỏ \(t \leftarrow 0.25\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thử \(t = 0.25\) (chạm đúng \(1/L\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(v = 1 - 0.25(4) = 0\), \(x^+ = S_{0.25}(0) = 0\), \(G_{0.25}(1) = \frac{1 - 0}{0.25} = 4\).&lt;/li&gt;
      &lt;li&gt;Vế trái: \(g(0) = 0\); vế phải: \(2 - 0.25(4)(4) + \frac{0.25}{2}(16) = 2 - 4 + 2 = 0\).&lt;/li&gt;
      &lt;li&gt;Thỏa mãn \(0 \le 0\)! Thuật toán chấp nhận \(t = 0.25\) và nhảy thẳng tới đúng nghiệm tối ưu \(x^{(1)} = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;phân-tích-hội-tụ&quot;&gt;Phân tích hội tụ&lt;/h1&gt;
&lt;p&gt;Trong phần này, chúng ta phân tích tính chất hội tụ của phương pháp gradient gần kề đối với bước cố định và tìm kiếm đường thẳng lùi.&lt;/p&gt;

&lt;h2 id=&quot;giả-thiết-hội-tụ&quot;&gt;Giả thiết hội tụ&lt;/h2&gt;
&lt;p&gt;Đối với hàm mục tiêu \(f(x) = g(x) + h(x)\), ta giả thiết:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(g\) là hàm lồi, khả vi, &lt;strong&gt;dom&lt;/strong&gt;\((g) = \mathbb{R}^n\), và \(\nabla g\) liên tục Lipschitz với hằng số \(L &amp;gt; 0\).&lt;/li&gt;
  &lt;li&gt;\(h\) là hàm lồi, và ánh xạ gần kề \(\text{prox}_{t}(x) = \underset{z} {\text{argmin}} \{ \parallel x - z \parallel_2^2/ (2t) + h(z) \}\) có thể tính được.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;định-lý-hội-tụ-với-kích-thước-bước-cố-định&quot;&gt;Định lý hội tụ với kích thước bước cố định&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Phương pháp gradient gần kề&lt;/strong&gt; với kích thước bước cố định \(t \le 1/L\) thỏa mãn: 
\begin{align}
f(x^{(k)}) - f^{*} \le  \frac{ \lVert x^{(0)} - x^{*} \rVert^2_2 }{2tk}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Như vậy, phương pháp gradient gần kề đạt tốc độ hội tụ \(O(1/k)\) hay \(O(1/\epsilon)\), tương đương với gradient descent trên hàm trơn. Tuy nhiên, đánh giá này tính theo số bước lặp chứ không phải tổng số phép toán (vì chi phí tính \(\text{prox}_t\) phụ thuộc vào hàm \(h\)).&lt;/p&gt;

&lt;h2 id=&quot;tìm-kiếm-đường-thẳng-lùi-backtracking-line-search&quot;&gt;Tìm kiếm đường thẳng lùi (Backtracking line search)&lt;/h2&gt;
&lt;p&gt;Tìm kiếm đường thẳng lùi cho phương pháp gradient gần kề có nguyên lý tương tự gradient descent, nhưng điều kiện kiểm tra chỉ áp dụng trên phần trơn \(g\) chứ không phải toàn bộ hàm \(f\).&lt;/p&gt;

&lt;p&gt;Chọn tham số \(0 &amp;lt; \beta &amp;lt; 1\) và khởi tạo \(t=1\). Ở mỗi bước lặp, ta lặp lại phép co \(t = \beta t\) chừng nào điều kiện sau còn đúng, và thực hiện bước cập nhật khi điều kiện này không còn thỏa mãn:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
g(x - tG_t(x)) &amp;gt; g(x) - t \nabla g(x)^T G_t(x) + \frac{t}{2} \parallel G_t(x) \parallel_2 ^2
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Điều kiện trên kiểm tra xem giá trị của \(g\) tại điểm đề xuất \(x - tG_t(x)\) có vượt quá cận trên bậc hai của \(g\) hay không.&lt;/p&gt;

&lt;p&gt;Khi \(h = 0\) (nên \(G_t(x) = \nabla g(x)\)), bất đẳng thức này trở thành \(g(x - t \nabla g(x)) &amp;gt; g(x) - \frac{t}{2} \lVert \nabla g(x) \rVert_2^2\), trùng với điều kiện lùi của gradient descent với \(\alpha = 1/2\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ghi chú:&lt;/strong&gt; Xem thêm chi tiết về tìm kiếm đường thẳng lùi cho gradient descent tại &lt;a href=&quot;/contents/vi/chapter06/06_02_02_backtracking_line_search/&quot;&gt;06-02-02 backtracking line search&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;thuật-toán-tìm-kiếm-đường-thẳng-lùi&quot;&gt;Thuật toán tìm kiếm đường thẳng lùi&lt;/h3&gt;
&lt;p&gt;Tóm tắt quy trình thực hiện (với độ dịch chuyển \(\Delta x = - t G_t(x)\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Khởi tạo tham số co bước \(0 \lt \beta \lt 1\).&lt;/li&gt;
  &lt;li&gt;Ở mỗi bước lặp, đặt lại \(t = t_{\text{init}}\) (thường chọn \(t_{\text{init}} = 1\)).&lt;/li&gt;
  &lt;li&gt;Nếu điều kiện \(g(x - tG_t(x)) \gt g(x) - t \nabla g(x)^T G_t(x) + \frac{t}{2} \parallel G_t(x) \parallel_2 ^2\) thỏa mãn, cập nhật \(t = \beta t\) và lặp lại bước kiểm tra này.&lt;/li&gt;
  &lt;li&gt;Thực hiện bước cập nhật gradient gần kề: \(x^+ = x - t G_t(x) = \text{prox}_t(x - t \nabla g(x))\).&lt;/li&gt;
  &lt;li&gt;Nếu chưa thỏa mãn điều kiện dừng, quay lại bước 2.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lưu ý rằng trong mỗi lần thử \(t\) khi lùi, ta phải tính lại \(G_t(x)\), kéo theo việc tính lại ánh xạ gần kề \(\text{prox}_t\). Nếu \(\text{prox}_t\) có chi phí tính toán cao, tổng chi phí của tìm kiếm đường thẳng lùi sẽ tăng lên đáng kể.&lt;/p&gt;

&lt;h3 id=&quot;định-lý-hội-tụ-với-tìm-kiếm-đường-thẳng-lùi&quot;&gt;Định lý hội tụ với tìm kiếm đường thẳng lùi&lt;/h3&gt;
&lt;p&gt;Dưới cùng các giả thiết như trên, phương pháp gradient gần kề kết hợp tìm kiếm đường thẳng lùi vẫn giữ được bậc tốc độ hội tụ \(O(1/k)\).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Phương pháp gradient gần kề&lt;/strong&gt; với tìm kiếm đường thẳng lùi thỏa mãn bất đẳng thức sau, với \(t_{\text{min}} = \text{min} \{1,\beta /L \}\):&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
\[f(x^{(k)})−f^{\star} ≤ \frac{\lVert x^{(0)} − x^{\star} \rVert_{2}^{2}}{2 t_{min}k}, \space t_{\text{min}} = \text{min} \{ 1, \beta / L \} \\\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>09-01 Phương pháp gradient gần kề (Proximal gradient descent)</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_01_proximal_gradient_descent/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/vi/chapter09/09_01_proximal_gradient_descent</id>
   <content type="html">&lt;p&gt;Nếu muốn hiểu sâu &lt;strong&gt;phương pháp gradient gần kề (Proximal Gradient Descent)&lt;/strong&gt; trong đúng một hình ảnh, hãy nhớ lại cách ta suy ra gradient descent cổ điển: ở mỗi điểm \(x\), ta thay hàm \(g(z)\) bằng một chiếc bát parabol mở lên tiếp xúc với \(g\) tại \(x\):
\(g(z) \approx g(x) + \nabla g(x)^T(z - x) + \frac{1}{2t}\|z - x\|_2^2,\)
rồi nhảy thẳng xuống đáy chiếc bát đó. Nhưng khi hàm mục tiêu có dạng \(f(z) = g(z) + h(z)\) với \(h(z)\) bị gãy khúc, ta không thể thay \(h(z)\) bằng đường tiếp tuyến được. Vậy phải làm gì?&lt;/p&gt;

&lt;p&gt;Ý tưởng thiên tài của phương pháp gradient gần kề là: &lt;strong&gt;chỉ xấp xỉ bậc hai phần trơn \(g(z)\), còn phần không trơn \(h(z)\) thì giữ nguyên vẹn!&lt;/strong&gt; Khi tối thiểu hóa tổng của chiếc bát parabol ấy cộng với \(h(z)\), ta thu được đúng một vòng lặp hai nhịp nhịp nhàng: nhịp 1 bước theo \(-\nabla g(x)\) giống hệt gradient descent; nhịp 2 áp dụng toán tử gần kề \(\operatorname{prox}_{t h}\) để “gọt” điểm vừa bước theo hình học của \(h\). Với \(h(x) = \lambda\|x\|_1\), toán tử ấy hóa ra chính là phép co ngưỡng mềm (soft-thresholding) nổi tiếng của thuật toán ISTA!&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-mảnh-ghép-của-thuật-toán-gradient-gần-kề&quot;&gt;Kiến thức cần nhớ: Bốn mảnh ghép của thuật toán gradient gần kề&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xấp xỉ bậc hai cục bộ cho phần trơn (Majorization–Minimization):&lt;/strong&gt; Khi \(t \le 1/L\), hàm bậc hai \(g(x) + \nabla g(x)^T(z-x) + \frac{1}{2t}\|z-x\|_2^2\) nằm &lt;em&gt;hoàn toàn phía trên&lt;/em&gt; \(g(z)\). Do đó, cực tiểu hóa mô hình thay thế cộng \(h(z)\) đảm bảo giá trị hàm thực \(f(x^{(k)})\) &lt;strong&gt;giảm đơn điệu&lt;/strong&gt; sau mọi bước — khắc phục hẳn nhược điểm lên xuống của subgradient!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Toán tử gần kề (Proximal Mapping):&lt;/strong&gt; Viết lại bài toán con ở mỗi bước bằng cách gộp bình phương, ta được:
\(x^{(k)} = \operatorname{prox}_{t h}\big(x^{(k-1)} - t\nabla g(x^{(k-1)})\big), \quad \operatorname{prox}_{t h}(v) = \arg\min_z \left\{\frac{1}{2t}\|z - v\|_2^2 + h(z)\right\}.\)
Vì hàm trong \(\arg\min\) là lồi mạnh, nghiệm luôn tồn tại và &lt;strong&gt;duy nhất&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phép co ngưỡng mềm (Soft-Thresholding) cho chuẩn \(\ell_1\):&lt;/strong&gt; Khi \(h(x) = \lambda\|x\|_1\), bài toán prox tách độc lập theo từng tọa độ \(j\), cho công thức đóng:
\([S_{t\lambda}(v)]_j = \operatorname{sign}(v_j)\max(|v_j| - t\lambda, 0).\)
Mọi tọa độ có độ lớn không vượt quá ngưỡng \(t\lambda\) bị kéo về &lt;strong&gt;chính xác bằng \(0\)&lt;/strong&gt;, tạo ra nghiệm thưa thực sự.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ phức tạp ẩn trong phép prox:&lt;/strong&gt; Toàn bộ hiệu quả của thuật toán phụ thuộc vào việc \(\operatorname{prox}_{t h}\) có tính nhanh hay không. Với \(\ell_1\), \(\ell_2\), hộp ràng buộc, đơn hình, hay chuẩn hạt nhân ma trận, prox đều có công thức đóng hoặc thuật toán rất gọn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;giải-thích-tính-tay-2-bước-ista-trên-bài-toán-lasso-2-biến&quot;&gt;Giải thích: Tính tay 2 bước ISTA trên bài toán Lasso 2 biến&lt;/h3&gt;

&lt;p&gt;Xét bài toán Lasso đơn giản với ma trận thiết kế trực giao \(A = I_2\) (nên \(L = 1\), chọn bước \(t = 1\)), vector quan sát \(b = (2.5, -0.4)^T\) và hệ số phạt \(\lambda = 1.0\):
\(\min_{x \in \mathbb{R}^2} \; \frac{1}{2}\|x - b\|_2^2 + 1.0\|x\|_1.\)
Khởi tạo tại \(x^{(0)} = (0, 0)^T\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhịp 1 — Bước gradient trên phần trơn \(g(x) = \frac{1}{2}\|x - b\|_2^2\):&lt;/strong&gt;
\(\nabla g(x^{(0)}) = x^{(0)} - b = (-2.5, 0.4)^T.\)
Điểm trung gian trước khi áp dụng prox:
\(v^{(1)} = x^{(0)} - 1 \cdot \nabla g(x^{(0)}) = (2.5, -0.4)^T.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhịp 2 — Áp dụng toán tử gần kề (co ngưỡng mềm với ngưỡng \(t\lambda = 1.0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Tọa độ 1: $$&lt;/td&gt;
              &lt;td&gt;2.5&lt;/td&gt;
              &lt;td&gt;&amp;gt; 1.0 \implies x_1^{(1)} = (+1)\cdot(2.5 - 1.0) = 1.5$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Tọa độ 2: \(|-0.4| \le 1.0 \implies x_2^{(1)} = 0\) (bị cắt sạch về đúng \(0\)!).
Vậy \(x^{(1)} = (1.5, 0)^T\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện tối ưu tại \(x^{(1)} = (1.5, 0)^T\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tọa độ 1: \(g_1&apos;(1.5) + \lambda\operatorname{sign}(1.5) = (1.5 - 2.5) + 1 = 0\).&lt;/li&gt;
      &lt;li&gt;Tọa độ 2: \(g_2&apos;(0) = 0 - (-0.4) = 0.4 \in [-1, 1] = -\partial(\lambda|x_2|)\big|_0\).
Điều kiện tối ưu thỏa mãn ở cả hai tọa độ! Nếu chạy thêm bước 2, ta sẽ thấy \(v^{(2)} = (1.5, 0) - (-1, 0.4) = (2.5, -0.4)\) và \(x^{(2)} = (1.5, 0) = x^{(1)}\) — điểm bất động chính xác!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Phương pháp gradient gần kề (proximal gradient descent)&lt;/strong&gt; là phương pháp tối ưu dựa trên việc phân tách hàm mục tiêu thành một phần khả vi và một phần không khả vi. Trong bài này, chúng ta trình bày cách xây dựng thuật toán và áp dụng nó cho bài toán Lasso.&lt;/p&gt;

&lt;h2 id=&quot;hàm-mục-tiêu-có-thể-phân-tách&quot;&gt;Hàm mục tiêu có thể phân tách&lt;/h2&gt;
&lt;p&gt;Giả sử hàm mục tiêu \(f\) có thể viết dưới dạng tổng của hai hàm \(g\) và \(h\):&lt;/p&gt;

&lt;blockquote&gt;
\[f(x) = g(x) + h(x)\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(g\) là hàm lồi và khả vi, với &lt;strong&gt;dom&lt;/strong&gt;\((g) = \mathbb{R}^n\).&lt;/li&gt;
  &lt;li&gt;\(h\) là hàm lồi và có thể không khả vi.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nếu \(f\) khả vi, ta có thể cập nhật điểm lặp bằng phương pháp gradient descent:&lt;/p&gt;

&lt;blockquote&gt;
\[x^+ = x - t \cdot \nabla f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;[Ghi chú]&lt;/strong&gt; Trong gradient descent, hàm \(f\) được xấp xỉ quanh \(x\) bằng khai triển Taylor bậc hai với ma trận Hessian \(\nabla^2 f(x)\) được thay thế bằng \(\frac{1}{t} I\). Điểm cực tiểu của hàm xấp xỉ bậc hai này chính là điểm lặp tiếp theo (xem chi tiết tại Chương 6 về Gradient descent):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^+ = \underset{z}{\text{argmin}}  \underbrace{ f(x) + \nabla f(x)^T (z - x) + \frac{1}{2t} \parallel z - x \parallel_2 ^2}_{\tilde{f}_t(z)}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Khi \(f\) không khả vi, ta không thể áp dụng trực tiếp gradient descent. Tuy nhiên, với cấu trúc \(f = g + h\), ta có thể xấp xỉ bậc hai riêng cho phần khả vi \(g\) và giữ nguyên phần không khả vi \(h\).&lt;/p&gt;

&lt;p&gt;Ý tưởng này dẫn đến &lt;strong&gt;phương pháp gradient gần kề&lt;/strong&gt;: ở mỗi bước, ta tìm điểm mới vừa gần vị trí cập nhật gradient của \(g\), vừa làm nhỏ giá trị của \(h\):&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
x^+ &amp;amp; = \underset{z}{\text{argmin}}   \tilde{g}_t(z) + h(z) \\
&amp;amp; = \underset{z}{\text{argmin}} \ g(x) + \nabla g(x)^T (z - x) + \frac{1}{2t} \parallel z - x \parallel_2 ^2 + h(z) \\
&amp;amp; = \underset{z}{\text{argmin}}  \nabla g(x)^T (z - x) + \frac{1}{2t} \parallel z - x \parallel_2 ^2 + \frac{t}{2} \parallel \nabla g(x) \parallel_2 ^2  + h(z) \\
&amp;amp; = \underset{z}{\text{argmin}}  \frac{1}{2t} \left ( 2t \nabla g(x)^T (z - x) + \parallel z - x \parallel_2 ^2 + t^2 \parallel \nabla g(x) \parallel_2 ^2 \right )  + h(z) \\
&amp;amp; = \underset{z}{\text{argmin}}  \frac{1}{2t} \left ( \parallel z - x \parallel_2 ^2 + 2t \nabla g(x)^T (z - x) + t^2 \parallel \nabla g(x) \parallel_2 ^2 \right ) + h(z) \\
&amp;amp; = \underset{z}{\text{argmin}}   \frac{1}{2t} \parallel z - (x - t \nabla g(x) )\parallel_2 ^2 + h(z) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Từ dòng thứ hai sang dòng thứ ba, ta bỏ hằng số \(g(x)\) (không phụ thuộc vào \(z\)) và cộng thêm hằng số \(\frac{t}{2} \parallel \nabla g(x) \parallel_2 ^2\) để hoàn thiện bình phương. Ở biểu thức cuối cùng, số hạng \(\frac{1}{2t} \parallel z - (x - t \nabla g(x) )\parallel_2 ^2\) kéo \(z\) lại gần điểm cập nhật gradient của \(g\), còn số hạng \(h(z)\) thúc đẩy việc giảm giá trị của \(h\).&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán-gradient-gần-kề&quot;&gt;Thuật toán gradient gần kề&lt;/h2&gt;
&lt;p&gt;Xuất phát từ điểm ban đầu \(x^{(0)}\), phương pháp gradient gần kề lặp lại bước cập nhật:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x^{(k)} = \text{prox}_{t_k}(x^{(k-1)} - t_k \nabla g(x^{(k-1)}) )\), \(k=1,2,3,...\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(\text{prox}_{t}\) là &lt;strong&gt;ánh xạ gần kề (proximal mapping)&lt;/strong&gt; của \(h\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\text{prox}_{t}(x) = \underset{z}{\arg \min}  \frac{1}{2t} \parallel x - z \parallel_2^2 + h(z)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ta cũng có thể viết bước cập nhật dưới dạng tương tự gradient descent bằng cách định nghĩa ánh xạ gradient tổng quát \(G_t(x)\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{(k)} = x^{(k-1)} - t_k \cdot G_{t_k}(x^{(k-1)}), \space \space \text{trong đó} \space G_{t}(x) = \frac{x-\text{prox}_{t} (x - t \nabla g(x))}{t} &lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;ưu-điểm-của-cách-tiếp-cận-này&quot;&gt;Ưu điểm của cách tiếp cận này&lt;/h2&gt;
&lt;p&gt;Thoạt nhìn, bước cập nhật trên dường như chỉ chuyển bài toán ban đầu sang một bài toán tối ưu con khác. Tuy nhiên, giá trị thực tiễn của phương pháp nằm ở hai điểm:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Với nhiều hàm \(h\) phổ biến trong thực tế, ánh xạ \(\text{prox}_{t}(\cdot)\) có thể tính được trực tiếp bằng công thức dạng đóng.&lt;/li&gt;
  &lt;li&gt;Ánh xạ \(\text{prox}_{t}(\cdot)\) chỉ phụ thuộc vào \(h\), không phụ thuộc vào \(g\); ngay cả khi \(g\) phức tạp, ta chỉ cần tính được gradient \(\nabla g\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Các kết quả phân tích hội tụ tiếp theo được tính theo số bước lặp của thuật toán. Cần lưu ý rằng chi phí tính toán trên mỗi bước lặp còn phụ thuộc vào độ phức tạp khi tính \(\text{prox}_{t}(\cdot)\) đối với từng hàm \(h\) cụ thể.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-ista&quot;&gt;Ví dụ: ISTA&lt;/h2&gt;
&lt;p&gt;Xét lại bài toán Lasso với \(y \in \mathbb{R}^n\) và \(X \in \mathbb{R}^{n \times p}\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
f(\beta) = \frac{1}{2} \parallel y - X\beta \parallel_2^2 + \lambda \parallel \beta \parallel_1 &lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tách hàm mục tiêu thành \(g(\beta) = \frac{1}{2} \parallel y - X\beta \parallel_2^2\) và \(h(\beta) = \lambda \parallel \beta \parallel_1\). Khi đó, ánh xạ gần kề của \(h\) là:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
\text{prox}_{t}(\beta) &amp;amp; = \underset{z}{\text{argmin}}  \frac{1}{2t} \parallel \beta - z \parallel_2^2 + \lambda \parallel z \parallel_1 \\
&amp;amp; = S_{\lambda t}(\beta) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;trong đó \(S_{\lambda t}(\beta)\) là toán tử ngưỡng mềm (soft-thresholding operator) với ngưỡng \(\lambda t\) (xem chi tiết tại Chương 7):&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
[S_{\lambda t}(\beta)]_i =
\begin{cases}
\beta_i - \lambda t &amp;amp; \mbox{nếu } \beta_i \gt \lambda t \\
0 &amp;amp; \mbox{nếu } -\lambda t \le \beta_i \le \lambda t, \quad i = 1, ..., p \\
\beta_i + \lambda t &amp;amp; \mbox{nếu } \beta_i \lt -\lambda t \\
\end{cases}
\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Vì \(\nabla g(\beta) = -X^{T} (y - X \beta)\), bước cập nhật gradient gần kề trở thành:&lt;/p&gt;

&lt;blockquote&gt;
\[\beta^+ = S_{\lambda t}(\beta + tX^{T} (y - X \beta) )\]
&lt;/blockquote&gt;

&lt;p&gt;Thuật toán này được gọi là &lt;strong&gt;thuật toán ngưỡng mềm lặp (Iterative Soft-Thresholding Algorithm — ISTA)&lt;/strong&gt; (Beck và Teboulle (2008), “A fast iterative shrinkage-thresholding algorithm for linear inverse problems”).&lt;/p&gt;

&lt;p&gt;Hình dưới đây minh họa sự khác biệt rõ rệt về tốc độ hội tụ giữa phương pháp subgradient và phương pháp gradient gần kề: xét theo số bước lặp, hiệu suất của phương pháp gradient gần kề tương đương với gradient descent.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter09/09.01_01_ISTA.png&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Hình 1] Ví dụ về tốc độ hội tụ của gradient gần kề (ISTA) so với phương pháp subgradient [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;co-ngưỡng-mềm-prox-của-λx-và-vì-sao-có-số-0-thật-video&quot;&gt;Co ngưỡng mềm: prox của λ|x| và vì sao có số 0 thật (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/prox-shrink_vi.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Ánh xạ gần kề của \(\lambda|x|_1\) đưa các thành phần nhỏ về đúng 0 và co các thành phần còn lại một đoạn \(\lambda\): $$\operatorname{sign}(y)\max(&lt;/td&gt;
      &lt;td&gt;y&lt;/td&gt;
      &lt;td&gt;-\lambda,0)$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;tự-tay-thử-ista-trên-một-bài-toán-lasso-nhỏ&quot;&gt;Tự tay thử: ISTA trên một bài toán Lasso nhỏ&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;ista&quot; data-lang=&quot;vi&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Proximal gradient descent and acceleration</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_proximal_gradient_descent_and_acceleration/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_proximal_gradient_descent_and_acceleration</id>
   <content type="html">&lt;p&gt;In Chapter 08, we hit a seemingly immovable speed limit: black-box subgradient methods need \(O(1/\varepsilon^2)\) iterations to reach accuracy \(\varepsilon\). Yet almost every nonsmooth problem in statistics, signal processing, and imaging—Lasso, nuclear-norm matrix completion, constrained least squares—is not an opaque black box at all. It is a &lt;strong&gt;composite&lt;/strong&gt; sum \(f(x) = g(x) + h(x)\) of a smooth loss \(g\) and a simple structured regularizer \(h\). Chapter 09 shows how splitting those two pieces apart restores the smooth \(O(1/\varepsilon)\) rate via &lt;strong&gt;proximal gradient descent&lt;/strong&gt;, and then launches all the way to the optimal \(O(1/\sqrt{\varepsilon})\) first-order rate via &lt;strong&gt;Nesterov / FISTA acceleration&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-composite-optimization-architecture&quot;&gt;Key ideas: The Composite Optimization Architecture&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Composite Splitting (\(f = g + h\)):&lt;/strong&gt; Instead of throwing away the smoothness of \(g\) just because \(h\) has kinks, we approximate &lt;em&gt;only&lt;/em&gt; \(g\) by its local quadratic majorizer while keeping \(h\) completely exact inside every iteration.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — The Proximal Operator (\(\operatorname{prox}_{t h}\)):&lt;/strong&gt; Defined as \(\operatorname{prox}_{t h}(y) = \arg\min_z \left\{\frac{1}{2t}\|z - y\|_2^2 + h(z)\right\}\), the prox map acts as a generalized projection: it balances staying close to the gradient-descent proposal \(y = x - t\nabla g(x)\) against minimizing \(h(z)\), often in closed form (e.g., soft-thresholding for \(\ell_1\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Generalized Gradient &amp;amp; \(O(1/\varepsilon)\) Recovery:&lt;/strong&gt; Defining the generalized gradient \(G_t(x) = \frac{1}{t}(x - \operatorname{prox}_{t h}(x - t\nabla g(x)))\) turns the proximal step into \(x^+ = x - t G_t(x)\), unifying ordinary gradient descent, projected gradient descent, and ISTA under one \(O(1/\varepsilon)\) convergence proof.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Nesterov Momentum &amp;amp; FISTA (\(O(1/\sqrt{\varepsilon})\)):&lt;/strong&gt; Adding an extrapolated look-ahead point \(v^{(k)} = x^{(k-1)} + \frac{k-2}{k+1}(x^{(k-1)} - x^{(k-2)})\) before applying the proximal gradient step accelerates the rate from \(O(1/k)\) to \(O(1/k^2)\) at practically zero extra per-iteration cost.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-seeing-why-splitting-g--h-beats-a-raw-subgradient-step&quot;&gt;Worked example: Seeing Why Splitting \(g + h\) Beats a Raw Subgradient Step&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Consider the 1D composite problem $$f(x) = g(x) + h(x) = \frac{1}{2}(x - 1)^2 + 2&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((\)L = 1\(for\)\nabla g(x) = x - 1\(). Since\)0 \in (0 - 1) + 2[-1, 1] = [-3, 1]\(, the exact minimizer is\)x^\star = 0\(. Start at\)x^{(0)} = 0.5\(with step size\)t = 1/L = 1$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gradient step on the smooth part \(g(x) = \frac{1}{2}(x - 1)^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\nabla g(0.5) = 0.5 - 1 = -0.5\).&lt;/li&gt;
      &lt;li&gt;Intermediate point: \(y = x^{(0)} - t \nabla g(x^{(0)}) = 0.5 - 1(-0.5) = 1.0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;**Proximal step on the nonsmooth part $$h(x) = 2&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;\((soft-thresholding with threshold\)t\lambda = 1 \cdot 2 = 2$$):**&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;$$x^{(1)} = S_{2}(1.0) = \operatorname{sign}(1.0)\max(&lt;/td&gt;
          &lt;td&gt;1.0&lt;/td&gt;
          &lt;td&gt;- 2,\; 0) = 0.$$&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with a raw subgradient step from \(x^{(0)} = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Full subgradient at \(0.5\) is \((0.5 - 1) + 2 = +1.5\).&lt;/li&gt;
      &lt;li&gt;With \(t = 1\), a raw subgradient step lands at \(0.5 - 1.5 = -1.0\) (overshooting \(0\) completely and &lt;em&gt;increasing&lt;/em&gt; \(f\) from \(1.125\) to \(4.0\)!).&lt;/li&gt;
      &lt;li&gt;Proximal gradient snapped directly to the exact sparse solution \(x^\star = 0\) in &lt;strong&gt;one iteration&lt;/strong&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;proximal-gradient-descent-and-acceleration&quot;&gt;Proximal gradient descent and acceleration&lt;/h1&gt;

&lt;p&gt;This chapter introduces proximal gradient descent and acceleration techniques for optimization problems involving composite functions.&lt;/p&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Proximal gradient descent is used for problems where the objective can be split into a differentiable part and a non-differentiable part.&lt;/li&gt;
  &lt;li&gt;Acceleration methods, such as Nesterov’s acceleration and FISTA, can improve convergence rates.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;structure&quot;&gt;Structure&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Section 1: Proximal gradient descent&lt;/li&gt;
  &lt;li&gt;Section 2: Convergence analysis&lt;/li&gt;
  &lt;li&gt;Section 3: Matrix completion example&lt;/li&gt;
  &lt;li&gt;Section 4: Special cases&lt;/li&gt;
  &lt;li&gt;Section 5: Acceleration methods — start at the Distill-style picture in &lt;a href=&quot;/contents/en/chapter09/09_05_acceleration/&quot;&gt;09-05&lt;/a&gt;, then the FISTA algebra in 09-05-01; the stochastic / constant-\(\beta\) cousin is &lt;a href=&quot;/contents/en/chapter26/26_02_momentum_and_nesterov/&quot;&gt;26-02&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Refer to each section for details and mathematical formulations.&lt;/p&gt;

&lt;h2 id=&quot;modern-applications-20222026&quot;&gt;Modern applications (2022–2026)&lt;/h2&gt;

&lt;p&gt;An optional companion lesson follows the same proximal-gradient / FISTA template into PnP imaging, FISTA-Net / pFISTA-DR unrolling, and production elastic-net paths. See &lt;a href=&quot;/contents/en/chapter09/09_06_modern_applications/&quot;&gt;09-06 Modern applications of proximal GD and acceleration&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>09-11 Practical Exercises - Proximal Gradient</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_11_Practical_Exercises_Proximal_Gradient/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_11_Practical_Exercises_Proximal_Gradient</id>
   <content type="html">&lt;p&gt;Derivations on paper make proximal operators look effortless, but true fluency comes from computing them by hand across diverse geometries: \(\ell_1\) shrinkage on vectors, singular-value thresholding on matrices, FISTA momentum updates, and dual proximal mappings via Moreau’s decomposition. The five practical exercises below are modeled on Parikh &amp;amp; Boyd (2014) and Beck &amp;amp; Teboulle (2009) to build genuine muscle memory across every corner of Chapter 09.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-essential-identities-for-solving-proximal-exercises&quot;&gt;Key ideas: Essential Identities for Solving Proximal Exercises&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — First-Order Optimality of the Prox Map:&lt;/strong&gt; \(z = \operatorname{prox}_{t h}(y) \iff \frac{1}{t}(y - z) \in \partial h(z)\). This single subdifferential inclusion lets you derive any closed-form proximal operator in three lines without guessing.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Moreau’s Identity (Primal–Dual Proximal Bridge):&lt;/strong&gt; For any closed proper convex \(h\) and its Fenchel conjugate \(h^\star\), \(y = \operatorname{prox}_{t h}(y) + t \operatorname{prox}_{h^\star / t}(y / t)\). Whenever \(h\) is a norm \(\|\cdot\|\), \(h^\star\) is the indicator of the dual-norm unit ball, turning any norm prox into a simple projection!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Spectral / Orthogonally Invariant Prox:&lt;/strong&gt; If \(h(X) = \phi(\sigma(X))\) depends only on the singular values of matrix \(X = U \operatorname{diag}(\sigma) V^\top\), then \(\operatorname{prox}_{t h}(X) = U \operatorname{diag}(\operatorname{prox}_{t \phi}(\sigma)) V^\top\)—immediately yielding SVT for the nuclear norm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Dual Proximal Gradient:&lt;/strong&gt; When the primal objective is strongly convex with linear constraints, the Lagrange dual becomes smooth with Lipschitz gradient, allowing proximal gradient (or FISTA) to solve the dual directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-deriving-soft-thresholding-via-moreaus-identity&quot;&gt;Worked example: Deriving Soft-Thresholding via Moreau’s Identity&lt;/h3&gt;

&lt;p&gt;Let \(h(x) = \lambda \|x\|_1\) on \(\mathbb{R}^n\) with \(t = 1\), and compute \(\operatorname{prox}_{\lambda \|\cdot\|_1}(y)\) using Moreau’s identity instead of case-by-case differentiation.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identify the Fenchel conjugate \(h^\star(u)\):&lt;/strong&gt;
For \(h(x) = \lambda \|x\|_1\), the dual norm of \(\|\cdot\|_1\) is \(\|\cdot\|_\infty\), so \(h^\star(u) = I_{\{ \|u\|_\infty \le \lambda \}}(u)\) (\(0\) if \(\|u\|_\infty \le \lambda\), and \(+\infty\) otherwise).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(\operatorname{prox}_{h^\star}(y)\):&lt;/strong&gt;
Since \(h^\star\) is an indicator of the box \([-\lambda, \lambda]^n\), its proximal operator is simply coordinatewise clipping onto \([-\lambda, \lambda]\):
\([\operatorname{prox}_{h^\star}(y)]_j = \operatorname{clip}(y_j, -\lambda, \lambda) = \min(\lambda,\; \max(-\lambda, y_j)).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply Moreau’s identity \(\operatorname{prox}_h(y) = y - \operatorname{prox}_{h^\star}(y)\):&lt;/strong&gt;
\([\operatorname{prox}_{\lambda \|\cdot\|_1}(y)]_j = y_j - \operatorname{clip}(y_j, -\lambda, \lambda) = \begin{cases} y_j - \lambda &amp;amp; y_j &amp;gt; \lambda, \\ 0 &amp;amp; |y_j| \le \lambda, \\ y_j + \lambda &amp;amp; y_j &amp;lt; -\lambda. \end{cases}\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical check with \(y = (2, -1, 0.5)^\top\) and \(\lambda = 1\):&lt;/strong&gt;
\(\operatorname{clip}(y, -1, 1) = (1, -1, 0.5)^\top \implies \operatorname{prox}_h(y) = (2, -1, 0.5)^\top - (1, -1, 0.5)^\top = (1, 0, 0)^\top.\)
Notice how Moreau’s identity gives you an instant visual picture of soft-thresholding: it is literally the residual left over after clipping \(y\) to the box \([-\lambda, \lambda]^n\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;practical-exercises---proximal-gradient&quot;&gt;Practical Exercises - Proximal Gradient&lt;/h1&gt;

&lt;p&gt;The exercises are adapted from Parikh &amp;amp; Boyd (2014) and Beck &amp;amp; Teboulle (2009).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-1-lasso-with-soft-thresholding&quot;&gt;📝 &lt;strong&gt;Exercise 1: LASSO with Soft-Thresholding&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Given the LASSO: \(\min \frac{1}{2}\|Ax - b\|^2 + \lambda\|x\|_1\) with \(A = I\), \(b = (2, -1, 0.5)^T\), \(\lambda = 1\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Write the proximal operator&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Compute the soft-thresholding&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Iterate from \(x^{(0)} = 0\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**Proximal operator:**

$$\text{prox}_{t\lambda\|\cdot\|_1}(y) = S_{t\lambda}(y)$$

**Soft-thresholding:**

$$S_\lambda(y_i) = \begin{cases}
y_i - \lambda &amp;amp; \text{if } y_i &amp;gt; \lambda \\
0 &amp;amp; \text{if } |y_i| \leq \lambda \\
y_i + \lambda &amp;amp; \text{if } y_i &amp;lt; -\lambda
\end{cases}$$

**With $$A = I$$ (and $$t = 1$$):**

$$x^{(1)} = S_1(b) = (1, 0, 0)^T$$

Converged in 1 step!

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-2-matrix-completion&quot;&gt;📝 &lt;strong&gt;Exercise 2: Matrix Completion&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Minimize \(\|X\|_*\) s.t. \(X_{ij} = M_{ij}\) for the observed entries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Write proximal gradient with \(f(X) = \frac{1}{2}\|P_\Omega(X - M)\|_F^2\)&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Compute the proximal operator of the nuclear norm&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Apply SVD soft-thresholding&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**Proximal operator of the nuclear norm:**

$$\text{prox}_{t\|\cdot\|_*}(Y) = U S_t(\Sigma) V^T$$

where $$Y = U\Sigma V^T$$ (SVD), $$S_t(\sigma_i) = \max(\sigma_i - t, 0)$$.

**Update:**

$$X^{(k+1)} = \text{prox}_{t\|\cdot\|_*}(X^{(k)} - t\nabla f(X^{(k)}))$$

$$\nabla f(X) = P_\Omega(X - M)$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-3-accelerated-proximal-gradient-fista&quot;&gt;📝 &lt;strong&gt;Exercise 3: Accelerated Proximal Gradient (FISTA)&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Given \(f(x) + g(x)\) with \(f\) smooth and \(g\) non-smooth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Write the FISTA update&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Compare the convergence rate with proximal GD&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Apply it to LASSO&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**FISTA:**

$$
\begin{align}
y^{(k)} &amp;amp;= x^{(k)} + \frac{k-1}{k+2}(x^{(k)} - x^{(k-1)}) \\
x^{(k+1)} &amp;amp;= \text{prox}_{tg}(y^{(k)} - t\nabla f(y^{(k)}))
\end{align}
$$

**Convergence:**
- Proximal GD: $$O(1/k)$$
- FISTA: $$O(1/k^2)$$

**A $$k^2$$ speedup!**

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-4-proximal-operators&quot;&gt;📝 &lt;strong&gt;Exercise 4: Proximal Operators&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Compute the proximal operator of:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; \(g(x) = \|x\|_2\)&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; \(g(x) = I_C(x)\) (indicator of a convex set \(C\))&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; \(g(x) = \frac{1}{2}x^TQx\)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**a) $$\ell_2$$ norm:**

$$\text{prox}_{t\|\cdot\|_2}(y) = \begin{cases}
\left(1 - \frac{t}{\|y\|}\right)y &amp;amp; \text{if } \|y\| &amp;gt; t \\
0 &amp;amp; \text{otherwise}
\end{cases}$$

**b) Indicator function:**

$$\text{prox}_{tI_C}(y) = \Pi_C(y)$$ (projection onto $$C$$)

**c) Quadratic:**

$$\text{prox}_{tg}(y) = (I + tQ)^{-1}y$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-exercise-5-dual-proximal-gradient&quot;&gt;📝 &lt;strong&gt;Exercise 5: Dual Proximal Gradient&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Given \(\min c^Tx\) s.t. \(Ax = b, x \geq 0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; Write the dual problem&lt;br /&gt;
&lt;strong&gt;b)&lt;/strong&gt; Apply proximal gradient to the dual&lt;br /&gt;
&lt;strong&gt;c)&lt;/strong&gt; Recover the primal solution&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;&lt;strong&gt;💡 Solution&lt;/strong&gt;&lt;/summary&gt;

**Dual:**

$$\max_\nu \quad g(\nu) = b^T\nu$$

s.t. $$A^T\nu \leq c$$

**Proximal gradient on the dual (projected gradient ascent):**

$$\nu^{(k+1)} = \Pi_{\{A^T\nu \leq c\}}(\nu^{(k)} + t b)$$

**Recover the primal:**

$$x^{(k)} = \arg\min_x L(x, \nu^{(k)})$$

&lt;/details&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-summary&quot;&gt;💡 &lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Convergence&lt;/th&gt;
      &lt;th&gt;Key Feature&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Proximal GD&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;Handles non-smooth \(g\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FISTA&lt;/td&gt;
      &lt;td&gt;\(O(1/k^2)\)&lt;/td&gt;
      &lt;td&gt;Accelerated&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dual Proximal&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;Constraints via the dual&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;proximal-operators&quot;&gt;&lt;strong&gt;Proximal Operators:&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Function&lt;/th&gt;
      &lt;th&gt;Proximal Operator&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;\(|\cdot|_1\)&lt;/td&gt;
      &lt;td&gt;Soft-thresholding&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(|\cdot|_2\)&lt;/td&gt;
      &lt;td&gt;Block soft-thresholding&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(|\cdot|_*\)&lt;/td&gt;
      &lt;td&gt;SVD soft-thresholding&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(I_C\)&lt;/td&gt;
      &lt;td&gt;Projection \(\Pi_C\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Quadratic&lt;/td&gt;
      &lt;td&gt;Matrix inversion&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;-references&quot;&gt;📚 &lt;strong&gt;References&lt;/strong&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Parikh, N., &amp;amp; Boyd, S. (2014). “Proximal Algorithms”. Foundations and Trends.&lt;/li&gt;
  &lt;li&gt;Beck, A., &amp;amp; Teboulle, M. (2009). “A Fast Iterative Shrinkage-Thresholding Algorithm” (FISTA).&lt;/li&gt;
  &lt;li&gt;Combettes, P. L., &amp;amp; Pesquet, J.-C. (2011). “Proximal Splitting Methods”.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>09-10 Multiple-Choice Quiz - Proximal Gradient Method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_10_Quiz_Proximal_Gradient/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_10_Quiz_Proximal_Gradient</id>
   <content type="html">&lt;p&gt;Before tackling the Chapter 09 multiple-choice quiz, take a moment to check your mental model of composite optimization. Most errors on proximal gradient exams come from mixing up the smooth part \(g\) and the nonsmooth part \(h\)—forgetting that \(L\) belongs &lt;em&gt;only&lt;/em&gt; to \(\nabla g\), misplacing the step size \(t\) inside the soft-thresholding parameter \(\lambda t\), or confusing the \(O(1/\varepsilon)\) proximal rate with the \(O(1/\sqrt{\varepsilon})\) accelerated rate. Review the four core pillars and quick warm-up check below before starting the questions.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-chapter-09-diagnostic-checklist&quot;&gt;Key ideas: Chapter 09 Diagnostic Checklist&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Composite Structure &amp;amp; Prox Definition:&lt;/strong&gt; For \(f = g + h\), \(\operatorname{prox}_{t h}(y) = \arg\min_z \{\frac{1}{2t}\|z - y\|_2^2 + h(z)\}\) uses &lt;em&gt;only&lt;/em&gt; \(h\); the smooth gradient \(\nabla g\) enters only through the proposal \(y = x - t\nabla g(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Iconic Proximal Operators:&lt;/strong&gt; Know the big three cold: \(h = 0 \implies \text{identity}\); \(h = I_C \implies P_C\) (Euclidean projection); \(h = \lambda \|\cdot\|_1 \implies S_{\lambda t}\) (coordinatewise soft-thresholding); and \(h = \lambda \|\cdot\|_* \implies \text{SVT}\) (singular value soft-thresholding).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Complexity Hierarchy:&lt;/strong&gt; Black-box subgradient: \(O(1/\varepsilon^2)\); Proximal gradient (ISTA): \(O(1/\varepsilon)\) with \(t \le 1/L\); Accelerated proximal gradient (FISTA): \(O(1/\sqrt{\varepsilon})\) with momentum extrapolation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Practical Caveats:&lt;/strong&gt; Proximal gradient is monotonic for \(t \le 1/L\), whereas FISTA is non-monotonic (Nesterov ripples) and benefits from adaptive restarting or MFISTA when \(f\) is ill-conditioned or locally strongly convex.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-rapid-3-operator-proximal-warm-up&quot;&gt;Worked example: Rapid 3-Operator Proximal Warm-Up&lt;/h3&gt;

&lt;p&gt;Let \(y = (3, -1, 0.4)^\top\) and step size \(t = 0.5\). Evaluate \(\operatorname{prox}_{t h}(y)\) for three different choices of \(h\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;\(h(x) = 2\|x\|_1\) (Lasso regularizer):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Effective threshold is \(\lambda t = 2 \cdot 0.5 = 1.0\).&lt;/li&gt;
      &lt;li&gt;Coordinate 1: \(3 - 1.0 = 2.0\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Coordinate 2: $$&lt;/td&gt;
              &lt;td&gt;-1&lt;/td&gt;
              &lt;td&gt;\le 1.0 \implies 0$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Coordinate 3: $$&lt;/td&gt;
              &lt;td&gt;0.4&lt;/td&gt;
              &lt;td&gt;\le 1.0 \implies 0$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Result: \(\operatorname{prox}_{t h}(y) = (2, 0, 0)^\top\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(h(x) = I_{\mathbb{R}_+^3}(x)\) (Nonnegativity constraint \(x \ge 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Projection clips negative entries to \(0\): \(\operatorname{prox}_{t h}(y) = (3, 0, 0.4)^\top\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;\(h(x) = \frac{\mu}{2}\|x\|_2^2\) with \(\mu = 2\) (Ridge / \(\ell_2^2\) penalty):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Minimizing \(\frac{1}{2t}\|z - y\|_2^2 + \frac{\mu}{2}\|z\|_2^2\) sets \(\frac{1}{t}(z - y) + \mu z = 0 \implies z = \frac{1}{1 + \mu t} y\).&lt;/li&gt;
      &lt;li&gt;With \(\mu t = 2 \cdot 0.5 = 1\), \(\operatorname{prox}_{t h}(y) = \frac{1}{2} y = (1.5, -0.5, 0.2)^\top\) (pure multiplicative shrinkage—notice ridge shrinks uniformly without creating exact zeros!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;-theory-review&quot;&gt;📚 Theory Review&lt;/h2&gt;

&lt;p&gt;Before starting the exercises, review the key concepts of this chapter:&lt;/p&gt;

&lt;h3 id=&quot;-the-proximal-gradient-method&quot;&gt;⚡ &lt;strong&gt;The Proximal Gradient Method&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;the-composite-problem&quot;&gt;&lt;strong&gt;The composite problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Consider an objective that can be decomposed as:
\(f(x) = g(x) + h(x)\)&lt;/p&gt;

&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g(x)\): convex, differentiable, \(\text{dom}(g) = \mathbb{R}^n\)&lt;/li&gt;
  &lt;li&gt;\(h(x)\): convex, possibly non-differentiable&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;main-idea&quot;&gt;&lt;strong&gt;Main idea&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Approximate \(g\):&lt;/strong&gt; Use a second-order Taylor expansion with Hessian \(\frac{1}{t}I\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Keep \(h\) as is:&lt;/strong&gt; Do not approximate the non-differentiable part&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimize the combination:&lt;/strong&gt; Find the minimizer of the approximation + \(h\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;basic-algorithm&quot;&gt;&lt;strong&gt;Basic algorithm&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(x^{(k)} = \text{prox}_{t_k}(x^{(k-1)} - t_k \nabla g(x^{(k-1)}))\)&lt;/p&gt;

&lt;p&gt;with the &lt;strong&gt;proximal mapping:&lt;/strong&gt;
\(\text{prox}_t(x) = \underset{z}{\arg\min} \left\{ \frac{1}{2t} \lVert x - z \rVert_2^2 + h(z) \right\}\)&lt;/p&gt;

&lt;h4 id=&quot;intuitive-explanation&quot;&gt;&lt;strong&gt;Intuitive explanation&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Gradient step:&lt;/strong&gt; \(x - t\nabla g(x)\) (gradient descent on \(g\))&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Proximal correction:&lt;/strong&gt; Find a point close to the gradient step that also makes \(h\) small&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trade-off:&lt;/strong&gt; Balance between “close to the gradient step” and “small \(h\)”&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-the-proximal-mapping&quot;&gt;📏 &lt;strong&gt;The Proximal Mapping&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;definition&quot;&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\text{prox}_t(x) = \underset{z}{\arg\min} \left\{ \frac{1}{2t} \lVert x - z \rVert_2^2 + h(z) \right\}\)&lt;/p&gt;

&lt;h4 id=&quot;important-properties&quot;&gt;&lt;strong&gt;Important properties&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Depends only on \(h\):&lt;/strong&gt; Not on \(g\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Often computable in closed form:&lt;/strong&gt; For many important functions \(h\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Single-valued:&lt;/strong&gt; Unique solution (by strict convexity)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-expansive:&lt;/strong&gt; \(\lVert \text{prox}_t(x) - \text{prox}_t(y) \rVert \le \lVert x - y \rVert\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;important-examples&quot;&gt;&lt;strong&gt;Important examples&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. L1 norm (LASSO):&lt;/strong&gt;
\(h(x) = \lambda \lVert x \rVert_1 \Rightarrow \text{prox}_t(x) = S_{\lambda t}(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Soft-thresholding operator:&lt;/strong&gt;
\([S_{\lambda t}(x)]_i = \begin{cases}
x_i - \lambda t &amp;amp; \text{if } x_i &amp;gt; \lambda t \\
0 &amp;amp; \text{if } |x_i| \le \lambda t \\
x_i + \lambda t &amp;amp; \text{if } x_i &amp;lt; -\lambda t
\end{cases}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Indicator function (Projection):&lt;/strong&gt;
\(h(x) = I_C(x) \Rightarrow \text{prox}_t(x) = P_C(x)\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. L2 norm:&lt;/strong&gt;
\(h(x) = \lambda \lVert x \rVert_2 \Rightarrow \text{prox}_t(x) = \max\left\{0, 1 - \frac{\lambda t}{\lVert x \rVert_2}\right\} x\)&lt;/p&gt;

&lt;h3 id=&quot;-convergence-analysis&quot;&gt;📊 &lt;strong&gt;Convergence Analysis&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;assumptions&quot;&gt;&lt;strong&gt;Assumptions&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;\(g\) convex and differentiable with \(\nabla g\) Lipschitz continuous (constant \(L\))&lt;/li&gt;
  &lt;li&gt;\(h\) convex, with \(\text{prox}_t\) computable&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;convergence-theorem&quot;&gt;&lt;strong&gt;Convergence theorem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;With step size \(t \le 1/L\):
\(f(x^{(k)}) - f^* \le \frac{\lVert x^{(0)} - x^* \rVert_2^2}{2tk}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meaning:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Convergence rate:&lt;/strong&gt; \(O(1/k)\) (same as gradient descent)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step-size condition:&lt;/strong&gt; \(t \le 1/L\) (same as gradient descent)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Performance:&lt;/strong&gt; Equivalent to gradient descent in number of iterations&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;backtracking-line-search&quot;&gt;&lt;strong&gt;Backtracking line search&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt;
\(g(x - tG_t(x)) &amp;gt; g(x) - t\nabla g(x)^T G_t(x) + \frac{t}{2} \lVert G_t(x) \rVert_2^2\)&lt;/p&gt;

&lt;p&gt;with \(G_t(x) = \frac{x - \text{prox}_t(x - t\nabla g(x))}{t}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The condition is checked only on \(g\), not on \(f\)&lt;/p&gt;

&lt;h3 id=&quot;-example-ista-iterative-soft-thresholding-algorithm&quot;&gt;🎯 &lt;strong&gt;Example: ISTA (Iterative Soft-Thresholding Algorithm)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;the-lasso-problem&quot;&gt;&lt;strong&gt;The LASSO problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_\beta \frac{1}{2} \lVert y - X\beta \rVert_2^2 + \lambda \lVert \beta \rVert_1\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decomposition:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g(\beta) = \frac{1}{2} \lVert y - X\beta \rVert_2^2\) (differentiable)&lt;/li&gt;
  &lt;li&gt;\(h(\beta) = \lambda \lVert \beta \rVert_1\) (non-differentiable)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;gradient-of-g&quot;&gt;&lt;strong&gt;Gradient of \(g\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\nabla g(\beta) = -X^T(y - X\beta) = X^T(X\beta - y)\)&lt;/p&gt;

&lt;h4 id=&quot;ista-update&quot;&gt;&lt;strong&gt;ISTA update&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\beta^{(k)} = S_{\lambda t}(\beta^{(k-1)} + tX^T(y - X\beta^{(k-1)}))\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Simple, and much more efficient than the subgradient method&lt;/p&gt;

&lt;h3 id=&quot;-example-matrix-completion&quot;&gt;🎯 &lt;strong&gt;Example: Matrix Completion&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;problem&quot;&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\min_B \frac{1}{2} \sum_{(i,j) \in \Omega} (Y_{ij} - B_{ij})^2 + \lambda \lVert B \rVert_{tr}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decomposition:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g(B) = \frac{1}{2} \lVert P_\Omega(Y) - P_\Omega(B) \rVert_F^2\) (differentiable)&lt;/li&gt;
  &lt;li&gt;\(h(B) = \lambda \lVert B \rVert_{tr}\) (trace norm, non-differentiable)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;projection-operator&quot;&gt;&lt;strong&gt;Projection operator&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\([P_\Omega(B)]_{ij} = \begin{cases}
B_{ij} &amp;amp; \text{if } (i,j) \in \Omega \\
0 &amp;amp; \text{otherwise}
\end{cases}\)&lt;/p&gt;

&lt;h4 id=&quot;gradient-of-g-1&quot;&gt;&lt;strong&gt;Gradient of \(g\)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\nabla g(B) = -(P_\Omega(Y) - P_\Omega(B))\)&lt;/p&gt;

&lt;h4 id=&quot;proximal-mapping-for-the-trace-norm&quot;&gt;&lt;strong&gt;Proximal mapping for the trace norm&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\text{prox}_t(B) = S_{\lambda t}(B)\) (matrix soft-thresholding)&lt;/p&gt;

&lt;p&gt;If \(B = U\Sigma V^T\) (SVD), then:
\(S_{\lambda t}(B) = U\Sigma_{\lambda t} V^T\)&lt;/p&gt;

&lt;p&gt;with \((\Sigma_{\lambda t})_{ii} = \max\{\Sigma_{ii} - \lambda t, 0\}\)&lt;/p&gt;

&lt;h4 id=&quot;soft-impute-algorithm&quot;&gt;&lt;strong&gt;Soft-Impute Algorithm&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(B^{(k)} = S_{\lambda}(P_\Omega(Y) + P_\Omega^\perp(B^{(k-1)}))\)&lt;/p&gt;

&lt;h3 id=&quot;-special-cases&quot;&gt;🔄 &lt;strong&gt;Special Cases&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Proximal gradient is a &lt;strong&gt;general method&lt;/strong&gt; that includes:&lt;/p&gt;

&lt;h4 id=&quot;1-gradient-descent&quot;&gt;&lt;strong&gt;1. Gradient Descent&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(h = 0 \Rightarrow \text{prox}_t(x) = x\)
\(x^{(k)} = x^{(k-1)} - t\nabla g(x^{(k-1)})\)&lt;/p&gt;

&lt;h4 id=&quot;2-projected-gradient-descent&quot;&gt;&lt;strong&gt;2. Projected Gradient Descent&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(h = I_C \Rightarrow \text{prox}_t(x) = P_C(x)\)
\(x^{(k)} = P_C(x^{(k-1)} - t\nabla g(x^{(k-1)}))\)&lt;/p&gt;

&lt;h4 id=&quot;3-proximal-minimization-algorithm-pma&quot;&gt;&lt;strong&gt;3. Proximal Minimization Algorithm (PMA)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(g = 0 \Rightarrow x^{(k)} = \text{prox}_t(x^{(k-1)})\)&lt;/p&gt;

&lt;h3 id=&quot;-accelerated-proximal-gradient-fista&quot;&gt;⚡ &lt;strong&gt;Accelerated Proximal Gradient (FISTA)&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;idea&quot;&gt;&lt;strong&gt;Idea&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Add &lt;strong&gt;momentum&lt;/strong&gt; to accelerate convergence from \(O(1/k)\) to \(O(1/k^2)\)&lt;/p&gt;

&lt;h4 id=&quot;algorithm&quot;&gt;&lt;strong&gt;Algorithm&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(v = x^{(k-1)} + \frac{k-2}{k+1}(x^{(k-1)} - x^{(k-2)})\)
\(x^{(k)} = \text{prox}_{t_k}(v - t_k \nabla g(v))\)&lt;/p&gt;

&lt;h4 id=&quot;momentum-weight&quot;&gt;&lt;strong&gt;Momentum weight&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(\frac{k-2}{k+1} \to 1\) as \(k \to \infty\)&lt;/p&gt;

&lt;h4 id=&quot;characteristics&quot;&gt;&lt;strong&gt;Characteristics&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Convergence rate:&lt;/strong&gt; \(O(1/k^2)\) - optimal for first-order methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Not monotonic:&lt;/strong&gt; May increase temporarily (“Nesterov ripples”)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Highly effective:&lt;/strong&gt; Especially good for problems with a large condition number&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;fista-for-lasso&quot;&gt;&lt;strong&gt;FISTA for LASSO&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;A significant improvement over ISTA and the subgradient method&lt;/p&gt;

&lt;h3 id=&quot;-comparing-the-methods&quot;&gt;🔄 &lt;strong&gt;Comparing the Methods&lt;/strong&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Condition&lt;/th&gt;
      &lt;th&gt;Convergence rate&lt;/th&gt;
      &lt;th&gt;Applications&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Gradient Descent&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f\) differentiable&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;Smooth optimization&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Subgradient&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f\) convex&lt;/td&gt;
      &lt;td&gt;\(O(1/\sqrt{k})\)&lt;/td&gt;
      &lt;td&gt;Non-smooth&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Proximal Gradient&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f = g + h\), \(g\) smooth&lt;/td&gt;
      &lt;td&gt;\(O(1/k)\)&lt;/td&gt;
      &lt;td&gt;Composite problems&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Accelerated Proximal&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;\(f = g + h\), \(g\) smooth&lt;/td&gt;
      &lt;td&gt;\(O(1/k^2)\)&lt;/td&gt;
      &lt;td&gt;Fast composite&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;️-practical-techniques&quot;&gt;🛠️ &lt;strong&gt;Practical Techniques&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;when-to-use-proximal-gradient&quot;&gt;&lt;strong&gt;When to use Proximal Gradient:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Composite functions:&lt;/strong&gt; \(f = g + h\) with \(g\) smooth, \(h\) non-smooth&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regularization problems:&lt;/strong&gt; LASSO, elastic net, group LASSO&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constrained optimization:&lt;/strong&gt; Projected gradient descent&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrix problems:&lt;/strong&gt; Matrix completion, robust PCA&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sparse optimization:&lt;/strong&gt; Feature selection, compressed sensing&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;implementation-requirements&quot;&gt;&lt;strong&gt;Implementation requirements:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(\nabla g\):&lt;/strong&gt; The gradient of the smooth part must be computable&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute \(\text{prox}_t\):&lt;/strong&gt; A closed-form formula or an efficient solver is needed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lipschitz constant \(L\):&lt;/strong&gt; To choose a suitable step size&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;debugging-and-tuning&quot;&gt;&lt;strong&gt;Debugging and tuning:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Check the proximal mapping:&lt;/strong&gt; Verify its correctness&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step size selection:&lt;/strong&gt; Fixed (\(t = 1/L\)) or backtracking&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Convergence monitoring:&lt;/strong&gt; Track \(f(x^{(k)})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Acceleration:&lt;/strong&gt; Try FISTA if speed-up is needed&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-real-world-applications&quot;&gt;📈 &lt;strong&gt;Real-World Applications&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-machine-learning&quot;&gt;&lt;strong&gt;1. Machine Learning&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LASSO Regression:&lt;/strong&gt; Feature selection&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Elastic Net:&lt;/strong&gt; Combines L1 and L2 regularization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Group LASSO:&lt;/strong&gt; Structured sparsity&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sparse Logistic Regression:&lt;/strong&gt; Classification with feature selection&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-signal-processing&quot;&gt;&lt;strong&gt;2. Signal Processing&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Compressed Sensing:&lt;/strong&gt; Recovering sparse signals&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Image Denoising:&lt;/strong&gt; Total variation regularization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Matrix Completion:&lt;/strong&gt; Collaborative filtering, recommender systems&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-computer-vision&quot;&gt;&lt;strong&gt;3. Computer Vision&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Image Segmentation:&lt;/strong&gt; Total variation methods&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optical Flow:&lt;/strong&gt; Regularized motion estimation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Structure from Motion:&lt;/strong&gt; Bundle adjustment with sparsity&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;4-statistics&quot;&gt;&lt;strong&gt;4. Statistics&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Variable Selection:&lt;/strong&gt; High-dimensional regression&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robust Statistics:&lt;/strong&gt; Huber loss, quantile regression&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Graphical Models:&lt;/strong&gt; Sparse precision matrix estimation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-illustrative-examples&quot;&gt;💡 &lt;strong&gt;Illustrative Examples&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;problem-min_x-frac12x-22--x&quot;&gt;&lt;strong&gt;Problem:&lt;/strong&gt; \(\min_x \frac{1}{2}(x-2)^2 + |x|\)&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Decomposition:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(g(x) = \frac{1}{2}(x-2)^2\), \(\nabla g(x) = x-2\)&lt;/li&gt;
  &lt;li&gt;
\[h(x) = |x|\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Proximal mapping:&lt;/strong&gt;
\(\text{prox}_t(x) = S_t(x) = \begin{cases}
x - t &amp;amp; \text{if } x &amp;gt; t \\
0 &amp;amp; \text{if } |x| \le t \\
x + t &amp;amp; \text{if } x &amp;lt; -t
\end{cases}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proximal gradient step:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Gradient step: \(x - t(x-2) = (1-t)x + 2t\)&lt;/li&gt;
  &lt;li&gt;Soft-thresholding: \(\text{prox}_t((1-t)x + 2t)\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;-connections-to-other-chapters&quot;&gt;🎯 &lt;strong&gt;Connections to Other Chapters&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;from-the-previous-chapter&quot;&gt;&lt;strong&gt;From the previous chapter:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 08:&lt;/strong&gt; The subgradient method for non-smooth functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 07:&lt;/strong&gt; Subgradients and subdifferentials&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chapter 06:&lt;/strong&gt; Gradient descent for smooth functions&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;advantages-of-proximal-gradient&quot;&gt;&lt;strong&gt;Advantages of Proximal Gradient:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Faster than subgradient:&lt;/strong&gt; \(O(1/k)\) vs \(O(1/\sqrt{k})\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;More general than gradient descent:&lt;/strong&gt; Handles non-smooth components&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Can be accelerated:&lt;/strong&gt; FISTA achieves \(O(1/k^2)\)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;looking-ahead&quot;&gt;&lt;strong&gt;Looking ahead:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;ADMM:&lt;/strong&gt; Alternating Direction Method of Multipliers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Primal-dual methods:&lt;/strong&gt; Handle constrained problems&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stochastic variants:&lt;/strong&gt; Mini-batch and online versions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-theoretical-significance&quot;&gt;🌟 &lt;strong&gt;Theoretical Significance&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;the-proximal-operator-as-a-generalized-gradient&quot;&gt;&lt;strong&gt;The proximal operator as a “generalized gradient”:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gradient:&lt;/strong&gt; \(\nabla f(x)\) for smooth functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Subgradient:&lt;/strong&gt; \(\partial f(x)\) for non-smooth functions&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Proximal operator:&lt;/strong&gt; \(\text{prox}_t\) for composite functions&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;moreau-envelope&quot;&gt;&lt;strong&gt;Moreau envelope:&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;\(f_t(x) = \min_z \left\{ f(z) + \frac{1}{2t}\lVert x - z \rVert^2 \right\}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; \(f_t\) is smooth with \(\nabla f_t(x) = \frac{x - \text{prox}_t(x)}{t}\)&lt;/p&gt;

&lt;h4 id=&quot;connection-to-variational-analysis&quot;&gt;&lt;strong&gt;Connection to variational analysis:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Proximal gradient ↔ Forward-backward splitting&lt;/li&gt;
  &lt;li&gt;Acceleration ↔ Inertial methods&lt;/li&gt;
  &lt;li&gt;Convergence rates ↔ Complexity theory&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-practical-tips&quot;&gt;💡 &lt;strong&gt;Practical Tips&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;choosing-a-method&quot;&gt;&lt;strong&gt;Choosing a method:&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Smooth function:&lt;/strong&gt; Gradient descent&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-smooth function:&lt;/strong&gt; Subgradient method&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Composite function with a computable prox:&lt;/strong&gt; Proximal gradient&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Need acceleration:&lt;/strong&gt; FISTA&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Constrained:&lt;/strong&gt; Projected gradient descent&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;implementation-tips&quot;&gt;&lt;strong&gt;Implementation tips:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vectorization:&lt;/strong&gt; Exploit parallel computation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm start:&lt;/strong&gt; Use the previous solution as initialization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive step size:&lt;/strong&gt; Backtracking line search&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Early stopping:&lt;/strong&gt; Monitoring convergence criteria&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;common-pitfalls&quot;&gt;&lt;strong&gt;Common pitfalls:&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Wrong proximal mapping:&lt;/strong&gt; Check the formula carefully&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step size too large:&lt;/strong&gt; May fail to converge&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Not checking the Lipschitz constant:&lt;/strong&gt; Affects convergence&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Forgetting to normalize data:&lt;/strong&gt; Affects numerical stability&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;💡 &lt;strong&gt;Tip:&lt;/strong&gt; The proximal gradient method is the perfect bridge between smooth and non-smooth optimization, and is especially powerful for machine learning with regularization!&lt;/p&gt;

&lt;hr /&gt;

&lt;style&gt;
/* Fix alignment for MathJax inline math */
.MathJax {
    vertical-align: baseline !important;
}

mjx-container[jax=&quot;CHTML&quot;][display=&quot;false&quot;] {
    vertical-align: baseline !important;
    display: inline !important;
}

/* Make sure labels in the quiz are well aligned */
.options label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: #f0f0f0;
}

.options input[type=&quot;radio&quot;] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Styling cho quiz container */
#quiz-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: &apos;Segoe UI&apos;, Tahoma, Geneva, Verdana, sans-serif;
}

.question {
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.question h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.explanation {
    background: #e8f5e8;
    border: 1px solid #28a745;
    padding: 15px;
    margin-top: 15px;
    border-radius: 6px;
}

.quiz-controls {
    text-align: center;
    margin: 30px 0;
}

.quiz-controls button {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.quiz-controls button:hover {
    background: #0056b3;
}

.quiz-controls button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    transition: width 0.3s ease;
}

.score-display {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    margin: 20px 0;
}

.options label.selected {
    background-color: #e3f2fd;
    border: 2px solid #2196f3;
}

.final-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin: 30px 0;
}
&lt;/style&gt;

&lt;p&gt;This multiple-choice quiz tests your understanding of the proximal gradient method, proximal operators, composite optimization and acceleration methods such as FISTA.&lt;/p&gt;

&lt;hr /&gt;

&lt;div id=&quot;quiz-container&quot;&gt;
    &lt;div id=&quot;quiz-header&quot;&gt;
        &lt;h2&gt;🎯 Quiz: The Proximal Gradient Method&lt;/h2&gt;
        &lt;div class=&quot;progress-bar&quot;&gt;
            &lt;div class=&quot;progress-fill&quot; id=&quot;progress-fill&quot; style=&quot;width: 5%&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;score-display&quot; id=&quot;score-display&quot;&gt;Question: &lt;span id=&quot;current-q&quot;&gt;1&lt;/span&gt; / &lt;span id=&quot;total-q&quot;&gt;20&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id=&quot;quiz-content&quot;&gt;
        &lt;!-- Question 1 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q1&quot; style=&quot;display: block;&quot;&gt;
            &lt;h3&gt;Question 1: The proximal gradient method applies to problems of the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;a&quot; /&gt; A) \(\min f(x)\) with \(f\) differentiable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;b&quot; /&gt; B) \(\min f(x) = g(x) + h(x)\) with \(g\) differentiable, \(h\) convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;c&quot; /&gt; C) \(\min f(x)\) with \(f\) non-convex&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;d&quot; /&gt; D) \(\min f(x)\) with linear constraints&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\min f(x) = g(x) + h(x)$$ with $$g$$ differentiable, $$h$$ convex&lt;/strong&gt;&lt;br /&gt;
                The proximal gradient method is designed for composite optimization with $$g$$ differentiable and $$h$$ possibly non-differentiable.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 2 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q2&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 2: The proximal operator of a function \(h\) is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;a&quot; /&gt; A) \(\text{prox}_h(v) = \arg\min_x \{h(x) + \frac{1}{2}\|x - v\|^2\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;b&quot; /&gt; B) \(\text{prox}_h(v) = \arg\min_x \{h(x) - \frac{1}{2}\|x - v\|^2\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;c&quot; /&gt; C) \(\text{prox}_h(v) = \arg\min_x \{h(x) + \|x - v\|\}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;d&quot; /&gt; D) \(\text{prox}_h(v) = v - \nabla h(v)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\text{prox}_h(v) = \arg\min_x \{h(x) + \frac{1}{2}\|x - v\|^2\}$$&lt;/strong&gt;&lt;br /&gt;
                The proximal operator balances minimizing $$h(x)$$ against keeping $$x$$ close to $$v$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 3 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q3&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 3: The update formula of the proximal gradient method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;a&quot; /&gt; A) \(x^{(k+1)} = x^{(k)} - t \nabla g(x^{(k)})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;b&quot; /&gt; B) \(x^{(k+1)} = \text{prox}_{th}(x^{(k)} - t \nabla g(x^{(k)}))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;c&quot; /&gt; C) \(x^{(k+1)} = \text{prox}_{tg}(x^{(k)} - t \nabla h(x^{(k)}))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q3&quot; value=&quot;d&quot; /&gt; D) \(x^{(k+1)} = x^{(k)} - t(\nabla g(x^{(k)}) + \nabla h(x^{(k)}))\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$x^{(k+1)} = \text{prox}_{th}(x^{(k)} - t \nabla g(x^{(k)}))$$&lt;/strong&gt;&lt;br /&gt;
                Take a gradient step on $$g$$, then apply the proximal operator of $$h$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 4 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q4&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 4: The proximal operator of \(h(x) = \lambda\|x\|_1\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;a&quot; /&gt; A) \(\text{prox}_{\lambda\|\cdot\|_1}(v) = v - \lambda\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;b&quot; /&gt; B) \(\text{prox}_{\lambda\|\cdot\|_1}(v) = \text{sign}(v) \max(|v| - \lambda, 0)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;c&quot; /&gt; C) \(\text{prox}_{\lambda\|\cdot\|_1}(v) = \frac{v}{1 + \lambda}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q4&quot; value=&quot;d&quot; /&gt; D) \(\text{prox}_{\lambda\|\cdot\|_1}(v) = v\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\text{prox}_{\lambda\|\cdot\|_1}(v) = \text{sign}(v) \max(|v| - \lambda, 0)$$&lt;/strong&gt;&lt;br /&gt;
                This is the soft-thresholding operator, which shrinks each component toward 0 by $$\lambda$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 5 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q5&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 5: The proximal operator of \(h(x) = \frac{\lambda}{2}\|x\|_2^2\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;a&quot; /&gt; A) \(\text{prox}_{\frac{\lambda}{2}\|\cdot\|_2^2}(v) = \frac{v}{1 + \lambda}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;b&quot; /&gt; B) \(\text{prox}_{\frac{\lambda}{2}\|\cdot\|_2^2}(v) = v - \lambda v\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;c&quot; /&gt; C) \(\text{prox}_{\frac{\lambda}{2}\|\cdot\|_2^2}(v) = v\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q5&quot; value=&quot;d&quot; /&gt; D) \(\text{prox}_{\frac{\lambda}{2}\|\cdot\|_2^2}(v) = 0\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\text{prox}_{\frac{\lambda}{2}\|\cdot\|_2^2}(v) = \frac{v}{1 + \lambda}$$&lt;/strong&gt;&lt;br /&gt;
                The proximal operator of a quadratic function is a shrinkage with factor $$\frac{1}{1 + \lambda}$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 6 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q6&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 6: The convergence rate of the proximal gradient method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;a&quot; /&gt; A) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;b&quot; /&gt; B) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;c&quot; /&gt; C) \(O(1/\sqrt{k})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q6&quot; value=&quot;d&quot; /&gt; D) \(O(e^{-k})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$O(1/k)$$&lt;/strong&gt;&lt;br /&gt;
                The proximal gradient method converges at rate $$O(1/k)$$, like gradient descent for convex functions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 7 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q7&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 7: The proximal gradient method is appropriate when:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;a&quot; /&gt; A) Both \(g\) and \(h\) are differentiable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;b&quot; /&gt; B) \(g\) is differentiable and the proximal operator of \(h\) is easy to compute&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;c&quot; /&gt; C) Neither \(g\) nor \(h\) is differentiable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q7&quot; value=&quot;d&quot; /&gt; D) The objective is non-convex&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$g$$ is differentiable and the proximal operator of $$h$$ is easy to compute&lt;/strong&gt;&lt;br /&gt;
                The method is effective when the gradient of $$g$$ and the proximal operator of $$h$$ can be computed easily.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 8 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q8&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 8: FISTA (Fast Iterative Shrinkage-Thresholding Algorithm) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;a&quot; /&gt; A) A slow version of proximal gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;b&quot; /&gt; B) An accelerated version of proximal gradient with momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;c&quot; /&gt; C) An algorithm for non-convex problems&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q8&quot; value=&quot;d&quot; /&gt; D) An algorithm only for L1 regularization&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) An accelerated version of proximal gradient with momentum&lt;/strong&gt;&lt;br /&gt;
                FISTA uses momentum to achieve the convergence rate $$O(1/k^2)$$ instead of $$O(1/k)$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 9 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q9&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 9: The convergence rate of FISTA is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;a&quot; /&gt; A) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;b&quot; /&gt; B) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;c&quot; /&gt; C) \(O(1/\sqrt{k})\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q9&quot; value=&quot;d&quot; /&gt; D) \(O(e^{-k})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$O(1/k^2)$$&lt;/strong&gt;&lt;br /&gt;
                FISTA achieves the optimal rate $$O(1/k^2)$$ for first-order methods on convex functions.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 10 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q10&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 10: In FISTA, the momentum parameter \(t_k\) is updated by the formula:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;a&quot; /&gt; A) \(t_{k+1} = \frac{1 + \sqrt{1 + 4t_k^2}}{2}\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;b&quot; /&gt; B) \(t_{k+1} = t_k + 1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;c&quot; /&gt; C) \(t_{k+1} = 0.9 t_k\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q10&quot; value=&quot;d&quot; /&gt; D) \(t_{k+1} = 1\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$t_{k+1} = \frac{1 + \sqrt{1 + 4t_k^2}}{2}$$&lt;/strong&gt;&lt;br /&gt;
                This is the special formula in FISTA that guarantees the optimal convergence rate.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 11 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q11&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 11: The proximal operator has the property of:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;a&quot; /&gt; A) Not increasing distances (non-expansive, for convex $$h$$)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;b&quot; /&gt; B) Increasing distances&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;c&quot; /&gt; C) Being discontinuous&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q11&quot; value=&quot;d&quot; /&gt; D) Applying only to differentiable functions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Not increasing distances (non-expansive, for convex $$h$$)&lt;/strong&gt;&lt;br /&gt;
                $$\|\text{prox}_h(u) - \text{prox}_h(v)\| \leq \|u - v\|$$ for all $$u, v$$; this is an important property for the convergence analysis.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 12 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q12&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 12: The Lasso problem \(\min \frac{1}{2}\|Ax - b\|_2^2 + \lambda\|x\|_1\) can be solved with:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;a&quot; /&gt; A) Gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;b&quot; /&gt; B) Proximal gradient with \(g(x) = \frac{1}{2}\|Ax - b\|_2^2\), \(h(x) = \lambda\|x\|_1\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;c&quot; /&gt; C) Newton method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q12&quot; value=&quot;d&quot; /&gt; D) It cannot be solved&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Proximal gradient with $$g(x) = \frac{1}{2}\|Ax - b\|_2^2$$, $$h(x) = \lambda\|x\|_1$$&lt;/strong&gt;&lt;br /&gt;
                Lasso is the textbook example of composite optimization with $$g$$ differentiable and $$h$$ non-differentiable.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 13 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q13&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 13: In matrix completion, the proximal operator of the nuclear norm performs:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;a&quot; /&gt; A) Hard thresholding of the singular values&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;b&quot; /&gt; B) Soft thresholding of the singular values&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;c&quot; /&gt; C) No change to the matrix&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q13&quot; value=&quot;d&quot; /&gt; D) Setting all entries to 0&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Soft thresholding of the singular values&lt;/strong&gt;&lt;br /&gt;
                The proximal operator of the nuclear norm $$\|X\|_*$$ computes an SVD and soft-thresholds the singular values.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 14 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q14&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 14: Can backtracking line search be used in the proximal gradient method?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;a&quot; /&gt; A) No, because the function is not differentiable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;b&quot; /&gt; B) Yes, based on a sufficient-decrease condition for the composite function&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;c&quot; /&gt; C) Only when \(h = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q14&quot; value=&quot;d&quot; /&gt; D) Only for FISTA&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Yes, based on a sufficient-decrease condition for the composite function&lt;/strong&gt;&lt;br /&gt;
                Backtracking can be used with the condition $$f(x^+) \leq Q_t(x^+, x)$$, where $$Q_t$$ is the quadratic upper bound.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 15 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q15&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 15: The proximal operator of the indicator function \(I_C(x)\) of a convex set \(C\) is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;a&quot; /&gt; A) \(\text{prox}_{I_C}(v) = v\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;b&quot; /&gt; B) \(\text{prox}_{I_C}(v) = P_C(v)\) (projection onto \(C\))&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;c&quot; /&gt; C) \(\text{prox}_{I_C}(v) = 0\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q15&quot; value=&quot;d&quot; /&gt; D) It does not exist&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$\text{prox}_{I_C}(v) = P_C(v)$$ (projection onto $$C$$)&lt;/strong&gt;&lt;br /&gt;
                The proximal operator of an indicator function is exactly the projection onto the constraint set.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 16 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q16&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 16: The composite gradient mapping \(G_t(x)\) is defined as:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;a&quot; /&gt; A) \(G_t(x) = \nabla g(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;b&quot; /&gt; B) \(G_t(x) = \frac{1}{t}(x - \text{prox}_{th}(x - t\nabla g(x)))\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;c&quot; /&gt; C) \(G_t(x) = \text{prox}_{th}(x)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q16&quot; value=&quot;d&quot; /&gt; D) \(G_t(x) = x - t\nabla g(x)\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$G_t(x) = \frac{1}{t}(x - \text{prox}_{th}(x - t\nabla g(x)))$$&lt;/strong&gt;&lt;br /&gt;
                The composite gradient mapping generalizes the gradient to composite functions and is used in stopping criteria.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 17 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q17&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 17: Is acceleration (such as FISTA) always beneficial?&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;a&quot; /&gt; A) Always beneficial&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;b&quot; /&gt; B) No, it can slow convergence in some cases&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;c&quot; /&gt; C) Only beneficial for quadratic functions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q17&quot; value=&quot;d&quot; /&gt; D) Only beneficial for L1 regularization&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) No, it can slow convergence in some cases&lt;/strong&gt;&lt;br /&gt;
                Acceleration can cause oscillation and slow convergence, especially for poorly conditioned functions or in the early phase.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 18 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q18&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 18: Compared with the subgradient method, the proximal gradient method is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;a&quot; /&gt; A) Slower&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;b&quot; /&gt; B) Faster and more stable&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;c&quot; /&gt; C) Applying only to differentiable functions&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q18&quot; value=&quot;d&quot; /&gt; D) Has the same convergence rate&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) Faster and more stable&lt;/strong&gt;&lt;br /&gt;
                Proximal gradient has rate $$O(1/k)$$ versus $$O(1/\sqrt{k})$$ for subgradient, and oscillates less.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 19 --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q19&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 19: When \(g\) is strongly convex, the proximal gradient method converges at rate:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;a&quot; /&gt; A) \(O(1/k)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;b&quot; /&gt; B) \(O(\rho^k)\) with \(\rho &amp;lt; 1\) (linear)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;c&quot; /&gt; C) \(O(1/k^2)\)&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q19&quot; value=&quot;d&quot; /&gt; D) \(O(1/\sqrt{k})\)&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: B) $$O(\rho^k)$$ with $$\rho &amp;lt; 1$$ (linear)&lt;/strong&gt;&lt;br /&gt;
                Strong convexity of $$g$$ guarantees a linear (geometric) convergence rate for the proximal gradient method.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 20: Practical considerations --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q20&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 20: In practice, to apply the proximal gradient method effectively, we need:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;a&quot; /&gt; A) The proximal operator of \(h\) to have a closed-form solution&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;b&quot; /&gt; B) \(g\) to have a Lipschitz gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;c&quot; /&gt; C) A suitable step size&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q20&quot; value=&quot;d&quot; /&gt; D) All of the above conditions&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: D) All of the above conditions&lt;/strong&gt;&lt;br /&gt;
                To be effective, we need an easily computed proximal operator, a Lipschitz gradient for $$g$$, and a suitable step size.
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;!-- Question 21: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q21&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 21: The proximal operator of $$f(x) = \lambda|x|$$ is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;a&quot; /&gt; A) $$\text{prox}_f(x) = \text{sign}(x)\max\{|x|-\lambda, 0\}$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;b&quot; /&gt; B) $$\text{prox}_f(x) = x - \lambda$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;c&quot; /&gt; C) $$\text{prox}_f(x) = \lambda x$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q21&quot; value=&quot;d&quot; /&gt; D) $$\text{prox}_f(x) = |x|$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\text{prox}_f(x) = \text{sign}(x)\max\{|x|-\lambda, 0\}$$&lt;/strong&gt;&lt;br /&gt;
                This is the soft-thresholding operator, one of the most important proximal operators.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 22: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q22&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 22: The proximal gradient method combines:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;a&quot; /&gt; A) Gradient descent + proximal operator&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;b&quot; /&gt; B) Newton method + gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;c&quot; /&gt; C) SGD + momentum&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q22&quot; value=&quot;d&quot; /&gt; D) Line search + Hessian&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Gradient descent + proximal operator&lt;/strong&gt;&lt;br /&gt;
                Proximal gradient method: $$x^{(k+1)} = \text{prox}_{th}(x^{(k)} - t\nabla g(x^{(k)}))$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 23: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q23&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 23: FISTA is an algorithm that:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;a&quot; /&gt; A) Accelerates proximal gradient&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;b&quot; /&gt; B) Is an improved Newton method&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;c&quot; /&gt; C) Stochastic gradient descent&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q23&quot; value=&quot;d&quot; /&gt; D) Interior point method&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) Accelerates proximal gradient&lt;/strong&gt;&lt;br /&gt;
                FISTA (Fast Iterative Shrinkage-Thresholding Algorithm) is the accelerated version of proximal gradient.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 24: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q24&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 24: The LASSO problem has the form:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;a&quot; /&gt; A) $$\min \frac{1}{2}\|Ax-b\|^2 + \lambda\|x\|_1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;b&quot; /&gt; B) $$\min \frac{1}{2}\|Ax-b\|^2 + \lambda\|x\|_2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;c&quot; /&gt; C) $$\min \|Ax-b\|_1 + \lambda\|x\|_2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q24&quot; value=&quot;d&quot; /&gt; D) $$\min \|Ax-b\|_\infty + \lambda\|x\|_1$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$\min \frac{1}{2}\|Ax-b\|^2 + \lambda\|x\|_1$$&lt;/strong&gt;&lt;br /&gt;
                LASSO uses L1 regularization: $$\min \frac{1}{2}\|Ax-b\|^2 + \lambda\|x\|_1$$.
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Question 25: Practice --&gt;
        &lt;div class=&quot;question&quot; id=&quot;q25&quot; style=&quot;display: none;&quot;&gt;
            &lt;h3&gt;Question 25: For $$\text{prox}_{\lambda|\cdot|}(2)$$ with $$\lambda = 0.5$$, the result is:&lt;/h3&gt;
            &lt;div class=&quot;options&quot;&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;a&quot; /&gt; A) $$1.5$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;b&quot; /&gt; B) $$2$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;c&quot; /&gt; C) $$1$$&lt;/label&gt;
                &lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;q25&quot; value=&quot;d&quot; /&gt; D) $$0.5$$&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;explanation&quot; style=&quot;display: none;&quot;&gt;
                &lt;strong&gt;Correct answer: A) $$1.5$$&lt;/strong&gt;&lt;br /&gt;
                $$\text{prox}_{0.5|\cdot|}(2) = \text{sign}(2)\max\{|2|-0.5, 0\} = 1 \cdot 1.5 = 1.5$$.
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;quiz-controls&quot;&gt;
        &lt;button onclick=&quot;previousQuestion()&quot; id=&quot;prev-btn&quot; disabled=&quot;&quot;&gt;← Previous&lt;/button&gt;
        &lt;button onclick=&quot;nextQuestion()&quot; id=&quot;next-btn&quot;&gt;Next →&lt;/button&gt;
        &lt;button onclick=&quot;submitQuiz()&quot; id=&quot;submit-btn&quot; style=&quot;display: none;&quot;&gt;Submit&lt;/button&gt;
        &lt;button onclick=&quot;resetQuiz()&quot; id=&quot;reset-btn&quot; style=&quot;display: none;&quot;&gt;Try again&lt;/button&gt;
    &lt;/div&gt;

    &lt;div id=&quot;final-result&quot; style=&quot;display: none;&quot; class=&quot;final-score&quot;&gt;
        &lt;h2&gt;🎉 Quiz Complete!&lt;/h2&gt;
        &lt;p&gt;Your score: &lt;span id=&quot;final-score-text&quot;&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p id=&quot;performance-message&quot;&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;
let currentQuestion = 1;
const totalQuestions = 25;
let userAnswers = {};
let quizSubmitted = false;

// Correct answers
const correctAnswers = {
    q1: &apos;b&apos;, q2: &apos;a&apos;, q3: &apos;b&apos;, q4: &apos;b&apos;, q5: &apos;a&apos;,
    q6: &apos;b&apos;, q7: &apos;b&apos;, q8: &apos;b&apos;, q9: &apos;a&apos;, q10: &apos;a&apos;,
    q11: &apos;a&apos;, q12: &apos;b&apos;, q13: &apos;b&apos;, q14: &apos;b&apos;, q15: &apos;b&apos;,
    q16: &apos;b&apos;, q17: &apos;b&apos;, q18: &apos;b&apos;, q19: &apos;b&apos;, q20: &apos;d&apos;
,
    q21: &apos;a&apos;, q22: &apos;a&apos;, q23: &apos;a&apos;, q24: &apos;a&apos;, q25: &apos;a&apos;};

function showQuestion(n) {
    // Hide all questions
    for (let i = 1; i &lt;= totalQuestions; i++) {
        document.getElementById(`q${i}`).style.display = &apos;none&apos;;
    }
    
    // Show the current question
    document.getElementById(`q${n}`).style.display = &apos;block&apos;;
    
    // Update the progress bar
    const progress = (n / totalQuestions) * 100;
    document.getElementById(&apos;progress-fill&apos;).style.width = progress + &apos;%&apos;;
    
    // Update the question number
    document.getElementById(&apos;current-q&apos;).textContent = n;
    
    // Update the navigation buttons
    document.getElementById(&apos;prev-btn&apos;).disabled = (n === 1);
    document.getElementById(&apos;next-btn&apos;).style.display = (n === totalQuestions) ? &apos;none&apos; : &apos;inline-block&apos;;
    document.getElementById(&apos;submit-btn&apos;).style.display = (n === totalQuestions) ? &apos;inline-block&apos; : &apos;none&apos;;
    
    currentQuestion = n;
}

function nextQuestion() {
    if (currentQuestion &lt; totalQuestions) {
        showQuestion(currentQuestion + 1);
    }
}

function previousQuestion() {
    if (currentQuestion &gt; 1) {
        showQuestion(currentQuestion - 1);
    }
}

function saveAnswer(questionId, answer) {
    userAnswers[questionId] = answer;
    
    // Highlight selected option
    const questionDiv = document.getElementById(questionId);
    const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
    labels.forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
        const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
        if (input.checked) {
            label.classList.add(&apos;selected&apos;);
        }
    });
}

function calculateScore() {
    let correct = 0;
    for (let q in correctAnswers) {
        if (userAnswers[q] === correctAnswers[q]) {
            correct++;
        }
    }
    return correct;
}

function submitQuiz() {
    quizSubmitted = true;
    const score = calculateScore();
    const percentage = Math.round((score / totalQuestions) * 100);
    
    // Show all explanations
    for (let i = 1; i &lt;= totalQuestions; i++) {
        const explanation = document.querySelector(`#q${i} .explanation`);
        explanation.style.display = &apos;block&apos;;
        
        // Highlight correct and incorrect answers
        const questionDiv = document.getElementById(`q${i}`);
        const labels = questionDiv.querySelectorAll(&apos;.options label&apos;);
        labels.forEach(label =&gt; {
            const input = label.querySelector(&apos;input[type=&quot;radio&quot;]&apos;);
            const value = input.value;
            
            if (value === correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#d4edda&apos;;
                label.style.border = &apos;2px solid #28a745&apos;;
            } else if (value === userAnswers[`q${i}`] &amp;&amp; value !== correctAnswers[`q${i}`]) {
                label.style.backgroundColor = &apos;#f8d7da&apos;;
                label.style.border = &apos;2px solid #dc3545&apos;;
            }
        });
    }
    
    // Show the final result
    document.getElementById(&apos;final-result&apos;).style.display = &apos;block&apos;;
    document.getElementById(&apos;final-score-text&apos;).textContent = `${score}/${totalQuestions} (${percentage}%)`;
    
    let message = &apos;&apos;;
    if (percentage &gt;= 90) {
        message = &apos;🌟 Excellent! You have mastered the proximal gradient method!&apos;;
    } else if (percentage &gt;= 80) {
        message = &apos;👍 Very good! You understand proximal operators and FISTA well.&apos;;
    } else if (percentage &gt;= 70) {
        message = &apos;📚 Not bad! Review proximal operators and acceleration.&apos;;
    } else if (percentage &gt;= 60) {
        message = &apos;💪 Needs improvement! Review composite optimization and proximal operators.&apos;;
    } else {
        message = &apos;📖 Study the proximal gradient method again from the beginning!&apos;;
    }
    
    document.getElementById(&apos;performance-message&apos;).textContent = message;
    
    // Hide the submit button, show the reset button
    document.getElementById(&apos;submit-btn&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;inline-block&apos;;
    
    // Scroll to the results
    document.getElementById(&apos;final-result&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
}

function resetQuiz() {
    // Reset state
    currentQuestion = 1;
    userAnswers = {};
    quizSubmitted = false;
    
    // Hide all explanations
    document.querySelectorAll(&apos;.explanation&apos;).forEach(exp =&gt; {
        exp.style.display = &apos;none&apos;;
    });
    
    // Reset label styles
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.style.backgroundColor = &apos;&apos;;
        label.style.border = &apos;&apos;;
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Uncheck all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.checked = false;
    });
    
    document.querySelectorAll(&apos;.options label&apos;).forEach(label =&gt; {
        label.classList.remove(&apos;selected&apos;);
    });
    
    // Show the first question
    showQuestion(1);
    
    // Scroll to the top
    document.getElementById(&apos;quiz-header&apos;).scrollIntoView({ behavior: &apos;smooth&apos; });
    
    // Hide the final result and the reset button
    document.getElementById(&apos;final-result&apos;).style.display = &apos;none&apos;;
    document.getElementById(&apos;reset-btn&apos;).style.display = &apos;none&apos;;
}

// Initialize the exercise when the page loads
document.addEventListener(&apos;DOMContentLoaded&apos;, function() {
    showQuestion(1);
    
    // Add event listeners to all radio buttons
    document.querySelectorAll(&apos;input[type=&quot;radio&quot;]&apos;).forEach(input =&gt; {
        input.addEventListener(&apos;change&apos;, function() {
            const questionId = this.name;
            const answer = this.value;
            saveAnswer(questionId, answer);
        });
    });
    
    // Render MathJax after the DOM has loaded
    if (window.MathJax &amp;&amp; MathJax.startup &amp;&amp; MathJax.startup.promise) {
        MathJax.startup.promise.then(() =&gt; MathJax.typesetPromise());
    }
});

// Handle keyboard shortcuts
document.addEventListener(&apos;keydown&apos;, function(event) {
    if (quizSubmitted) return;
    
    switch(event.key) {
        case &apos;ArrowLeft&apos;:
            if (currentQuestion &gt; 1) previousQuestion();
            break;
        case &apos;ArrowRight&apos;:
            if (currentQuestion &lt; totalQuestions) nextQuestion();
            break;
        case &apos;Enter&apos;:
            if (currentQuestion === totalQuestions) submitQuiz();
            break;
    }
});
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>09-05 Acceleration</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_05_acceleration/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_05_acceleration</id>
   <content type="html">&lt;p&gt;Watch plain gradient descent or ISTA descend an elongated, narrow canyon: even with the optimal step size \(t = 1/L\), the iterates bounce back and forth across the steep walls while inching agonizingly slowly down the gentle valley floor. In 1983, a 27-year-old Yurii Nesterov published a four-page paper proving that adding a carefully calibrated &lt;strong&gt;momentum extrapolation&lt;/strong&gt; step cuts the number of iterations from \(O(1/\varepsilon)\) to \(O(1/\sqrt{\varepsilon})\)—the mathematically provable speed limit for all first-order methods! This lesson builds the geometric intuition behind Nesterov acceleration before diving into the algebra of FISTA.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-intuition-behind-optimal-first-order-acceleration&quot;&gt;Key ideas: The Intuition Behind Optimal First-Order Acceleration&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Zig-Zagging in Ill-Conditioned Valleys:&lt;/strong&gt; Along steep directions (eigenvalue \(L\)), step size \(1/L\) stops oscillations; along flat directions (small curvature), \(1/L\) takes tiny steps, causing \(O(1/k)\) progress. Momentum cancels out the alternating cross-valley zig-zags while reinforcing consistent motion along the valley floor.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Look-Ahead Gradient Evaluation (Nesterov vs. Heavy Ball):&lt;/strong&gt; Unlike Polyak’s classical heavy-ball momentum (which evaluates the gradient at \(x^{(k-1)}\) and then adds momentum), Nesterov extrapolates &lt;em&gt;first&lt;/em&gt; to \(v^{(k)} = x^{(k-1)} + \beta_k(x^{(k-1)} - x^{(k-2)})\) and evaluates the gradient/prox &lt;em&gt;at the look-ahead point&lt;/em&gt; \(v^{(k)}\), providing a crucial braking correction that guarantees global \(O(1/k^2)\) convergence for all convex problems.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Increasing Momentum Schedule (\(\beta_k \to 1\)):&lt;/strong&gt; Unlike constant-momentum SGD in deep learning, Nesterov’s convex schedule \(\beta_k = \frac{k-2}{k+1}\) starts at \(0\) and asymptotically approaches \(1\), corresponding in continuous time to the Su–Boyd–Candès second-order ODE \(\ddot{X}(t) + \frac{3}{t}\dot{X}(t) + \nabla f(X(t)) = 0\) with vanishing friction \(3/t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Non-Monotonic Ripples &amp;amp; Adaptive Restarts:&lt;/strong&gt; Because vanishing friction lets the iterate overshoot the minimum like a lightly damped spring, Nesterov acceleration produces characteristic “ripples” where \(f(x^{(k)})\) briefly rises—which O’Donoghue and Candès (2015) tamed by resetting momentum whenever the velocity points uphill.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-watching-nesterov-extrapolation-outpace-plain-gradient-descent&quot;&gt;Worked example: Watching Nesterov Extrapolation Outpace Plain Gradient Descent&lt;/h3&gt;

&lt;p&gt;Minimize the flat 1D quadratic \(g(x) = \frac{1}{20} x^2\) (so \(\nabla g(x) = 0.1 x\), optimal \(x^\star = 0\)), using a conservative step size \(t = 1\) (as if another coordinate had \(L = 1\)). Start at \(x^{(0)} = x^{(-1)} = 10\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Plain Gradient Descent (\(x^{(k)} = x^{(k-1)} - 0.1 x^{(k-1)} = 0.9 x^{(k-1)}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(k = 1\): \(x^{(1)} = 9.0\).&lt;/li&gt;
      &lt;li&gt;\(k = 2\): \(x^{(2)} = 8.1\).&lt;/li&gt;
      &lt;li&gt;\(k = 3\): \(x^{(3)} = 7.29\) (total distance moved: \(2.71\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nesterov Accelerated Gradient with \(\beta_k = \frac{k-1}{k+2}\) (indexing \(k=1,2,3\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(k = 1\) (\(\beta_1 = 0\)): \(v^{(1)} = 10\), \(x^{(1)} = 10 - 0.1(10) = 9.0\).&lt;/li&gt;
      &lt;li&gt;\(k = 2\) (\(\beta_2 = 1/4 = 0.25\)):
        &lt;ul&gt;
          &lt;li&gt;Extrapolate: \(v^{(2)} = 9.0 + 0.25(9.0 - 10) = 8.75\).&lt;/li&gt;
          &lt;li&gt;Gradient step at \(v^{(2)}\): \(x^{(2)} = 8.75 - 0.1(8.75) = 7.875\) (already ahead of \(8.1\)!).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;\(k = 3\) (\(\beta_3 = 2/5 = 0.40\)):
        &lt;ul&gt;
          &lt;li&gt;Extrapolate: \(v^{(3)} = 7.875 + 0.40(7.875 - 9.0) = 7.425\).&lt;/li&gt;
          &lt;li&gt;Gradient step at \(v^{(3)}\): \(x^{(3)} = 7.425 - 0.1(7.425) = 6.6825\) (total distance moved: \(3.3175\)—already 22% farther after just 3 steps, and the lead widens quadratically with \(k\)!).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;acceleration&quot;&gt;Acceleration&lt;/h1&gt;

&lt;p&gt;Proximal gradient descent on a composite problem \(\min_x g(x)+h(x)\) already has a clean rate \(O(1/k)\) when \(\nabla g\) is Lipschitz (lesson 09-02). &lt;strong&gt;Acceleration&lt;/strong&gt; is the extra memory that upgrades that rate to the optimal first-order \(O(1/k^2)\) on smooth convex \(g\), without forming a Hessian. This page is the Distill-style &lt;em&gt;picture&lt;/em&gt; that sits in front of the FISTA algebra. The algorithm and the \(O(1/k^2)\) proof live in &lt;a href=&quot;/contents/en/chapter09/09_05_01_accelerated_proximal_gradient_method/&quot;&gt;09-05-01&lt;/a&gt; and &lt;a href=&quot;/contents/en/chapter09/09_05_02_convergence_analysis/&quot;&gt;09-05-02&lt;/a&gt;; the stochastic, constant-\(\beta\) cousin used to train nets is &lt;a href=&quot;/contents/en/chapter26/26_02_momentum_and_nesterov/&quot;&gt;26-02&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;why-a-plain-proximal-step-zig-zags&quot;&gt;Why a plain proximal step zig-zags&lt;/h2&gt;

&lt;p&gt;Write a proximal gradient step as “take a gradient step on the smooth piece, then snap back with \(\operatorname{prox}_{t h}\).” When \(h=0\) this is ordinary gradient descent, and the classroom counter-example is again the long valley \(g(x)=\tfrac12 x^\top\operatorname{diag}(1,L)\,x\). A step small enough not to bounce off the sharp wall crawls down the floor. Momentum — the idea Nesterov introduced for smooth convex problems in 1983, and that Beck–Teboulle (2009) wrapped around a proximal map as &lt;strong&gt;FISTA&lt;/strong&gt; — stores the &lt;em&gt;previous&lt;/em&gt; position and extrapolates before the prox.&lt;/p&gt;

&lt;p&gt;The FISTA look-ahead of 09-05-01 is&lt;/p&gt;

\[\begin{align}
v^{(k)} &amp;amp;= x^{(k-1)}+\frac{k-2}{k+1}\bigl(x^{(k-1)}-x^{(k-2)}\bigr),\\
x^{(k)} &amp;amp;= \operatorname{prox}_{t_k h}\bigl(v^{(k)}-t_k\nabla g(v^{(k)})\bigr).
\end{align}\]

&lt;p&gt;The weight \((k-2)/(k+1)\) starts at zero (the first step &lt;em&gt;is&lt;/em&gt; proximal gradient) and climbs toward \(1\). That schedule is not a tasteful default; it is the discrete analogue of the continuous-time damping that makes Nesterov’s \(O(1/k^2)\) proof close. Goh’s Distill essay &lt;em&gt;&lt;a href=&quot;https://distill.pub/2017/momentum/&quot;&gt;Why Momentum Really Works&lt;/a&gt;&lt;/em&gt; is the same geometry without the prox: a second-order recurrence whose characteristic roots can be placed on a circle of radius \((\sqrt{\kappa}-1)/(\sqrt{\kappa}+1)\), turning a \(1-\Theta(1/\kappa)\) crawl into a \(1-\Theta(1/\sqrt{\kappa})\) glide.&lt;/p&gt;

&lt;h2 id=&quot;nesterov-versus-pytorch-nesterov&quot;&gt;Nesterov versus “PyTorch Nesterov”&lt;/h2&gt;

&lt;p&gt;Two objects share a name in this course, and they are not interchangeable.&lt;/p&gt;

&lt;p&gt;On a &lt;em&gt;smooth convex&lt;/em&gt; \(g\) (or a composite \(g+h\) with convex \(h\)), Nesterov / FISTA uses a &lt;strong&gt;scheduled&lt;/strong&gt; momentum weight and evaluates the smooth gradient at the extrapolated point \(v\). The theorem is \(g(x^{(k)})+h(x^{(k)})-F^\star=O(1/k^2)\), matching the first-order lower bound of &lt;a href=&quot;/contents/en/chapter06/06_03_06_can_we_do_better/&quot;&gt;06-03-06&lt;/a&gt;. The ISTA-versus-FISTA Lasso paths in &lt;a href=&quot;/contents/en/chapter09/09_05_03_example_FISTA/&quot;&gt;09-05-03&lt;/a&gt; are the picture you should be able to redraw.&lt;/p&gt;

&lt;p&gt;On a &lt;em&gt;deep net&lt;/em&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.optim.SGD(..., nesterov=True)&lt;/code&gt; is usually a &lt;strong&gt;constant&lt;/strong&gt; \(\beta\approx 0.9\) look-ahead on a nonconvex loss. The filter intuition survives — consistent directions get a longer memory, oscillating directions cancel, look-ahead damps overshoot — but the \(O(1/k^2)\) certificate does not. Lesson 26-02 is where that distinction is drawn in full, including the heavy-ball characteristic polynomial and a two-line NumPy comparison.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box&quot;&gt;
&lt;strong&gt;One sentence to keep.&lt;/strong&gt; FISTA is Nesterov’s look-ahead &lt;em&gt;plus&lt;/em&gt; a prox, with a weight that depends on $$k$$. Deep-learning momentum is the same look-ahead with the weight frozen. Use the scheduled theorem on Lasso and logistic regression; use the Distill valley on everything else.
&lt;/div&gt;

&lt;h2 id=&quot;when-acceleration-is-the-wrong-first-knob&quot;&gt;When acceleration is the wrong first knob&lt;/h2&gt;

&lt;p&gt;Acceleration is not free speed. The same inertia that glides down a convex valley can overshoot a nonsmooth kink or a small basin, which is why &lt;a href=&quot;/contents/en/chapter09/09_05_04_is_acceleration_always_useful/&quot;&gt;09-05-04&lt;/a&gt; exists and why restarted FISTA is a standard fix. If the smooth piece is cheap and strongly convex, a well-tuned proximal gradient step (or a variance-reduced sibling in &lt;a href=&quot;/contents/en/chapter26/26_05_variance_reduction/&quot;&gt;26-05&lt;/a&gt;) can beat an un-restarted accelerated method in wall-clock. Monitor the objective; if you see the famous “Nesterov ripples,” restart or drop \(\beta\).&lt;/p&gt;

&lt;h3 id=&quot;ista-and-fista-in-about-3-minutes&quot;&gt;ISTA and FISTA in about 3 minutes&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/ista-fista_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;p&gt;ISTA and FISTA on lasso: soft thresholding, the (k − 2)/(k + 1) weight, Nesterov ripples, a case where acceleration slows down, and restart.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exercise.&lt;/strong&gt; On the valley \(g(x)=\tfrac12 x^\top\operatorname{diag}(1,100)\,x\) with \(h=0\), plot ISTA (plain GD), FISTA with the \((k-2)/(k+1)\) weight, and constant-\(\beta\) Nesterov from 26-02. Which schedule first reaches \(\|x\|_2\le 10^{-4}\), and which one rings around the origin if you forget to restart?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question.&lt;/strong&gt; The FISTA weight tends to \(1\). Distill’s optimal heavy-ball \(\beta^\star\) for a known \(\kappa\) is strictly less than \(1\). Why can both be right — and what changes when you do &lt;em&gt;not&lt;/em&gt; know \(\kappa\)?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>09-05-04 Is acceleration always useful?</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_05_04_is_acceleration_always_useful/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_05_04_is_acceleration_always_useful</id>
   <content type="html">&lt;p&gt;After seeing FISTA slash iteration counts from 20,000 down to 282, it is tempting to bolt Nesterov acceleration onto every optimization problem you ever encounter. Yet seasoned practitioners know a sobering truth: acceleration is a &lt;strong&gt;high-gain amplifier&lt;/strong&gt;—it amplifies smooth deterministic curvature beautifully, but it also amplifies gradient noise, inexact proximal errors, and miscalibrated step sizes! Knowing &lt;em&gt;when&lt;/em&gt; acceleration helps and when plain proximal gradient (or restarted FISTA) wins is what separates textbook theory from production-grade optimization.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-practical-limits-of-acceleration&quot;&gt;Key ideas: The Practical Limits of Acceleration&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Nesterov Ripples &amp;amp; Overshoot:&lt;/strong&gt; When momentum approaches \(1\) on a strongly convex or locally curved valley, FISTA overshoots the minimum and oscillates in visible “ripples” where \(f(x^{(k)})\) temporarily increases. Gradient-scheme restarting (resetting \(t_k = 1\) whenever \((y^{(k)} - x^{(k)})^\top(x^{(k)} - x^{(k-1)}) &amp;gt; 0\)) eliminates ripples and often unlocks linear convergence.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Sensitivity to Stochastic Noise &amp;amp; Inexact Prox:&lt;/strong&gt; Accelerated methods accumulate gradient errors with weight \(O(k)\) instead of averaging them out; in noisy SGD or when \(\operatorname{prox}_{t h}\) is solved only approximately, plain proximal gradient can actually beat FISTA unless errors decay rapidly.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Warm Starts &amp;amp; Well-Conditioned Problems:&lt;/strong&gt; When solving a Lasso regularization path with warm starts (or when the condition number \(\kappa = L/\mu\) is small, say \(\kappa \le 5\)), plain proximal gradient already converges in a handful of iterations where \(\beta_k\) barely has time to ramp up.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Strong Convexity Mismatch:&lt;/strong&gt; Standard FISTA assumes \(\mu = 0\) (merely convex) and sets \(\beta_k \to 1\), which is &lt;em&gt;under-damped&lt;/em&gt; when \(g\) is \(\mu\)-strongly convex. Using the fixed strong-convexity momentum \(\beta = \frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\) (or adaptive restart) avoids under-damped oscillations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-seeing-nesterov-overshoot-on-a-well-conditioned-quadratic&quot;&gt;Worked example: Seeing Nesterov Overshoot on a Well-Conditioned Quadratic&lt;/h3&gt;

&lt;p&gt;Consider the perfectly conditioned 1D quadratic \(g(x) = \frac{1}{2} x^2\) (\(L = 1, \mu = 1, \kappa = 1, x^\star = 0\)) with step size \(t = 0.5\), starting at \(x^{(0)} = x^{(-1)} = 4\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Plain Gradient Descent (\(x^{(k)} = 0.5 x^{(k-1)}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(x^{(1)} = 2.0\), \(x^{(2)} = 1.0\), \(x^{(3)} = 0.5\), \(x^{(4)} = 0.25\) (smooth, monotone decay; objective drops \(4\times\) per step).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Standard FISTA (with \(\beta_2 \approx 0.28, \beta_3 \approx 0.43, \beta_4 \approx 0.53\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(k = 1\): \(x^{(1)} = 2.0\).&lt;/li&gt;
      &lt;li&gt;\(k = 2\): \(y^{(2)} = 2.0 + 0.28(2.0 - 4.0) = 1.44 \implies x^{(2)} = 0.5(1.44) = 0.72\).&lt;/li&gt;
      &lt;li&gt;\(k = 3\): \(y^{(3)} = 0.72 + 0.43(0.72 - 2.0) = 0.17 \implies x^{(3)} = 0.5(0.17) = 0.085\).&lt;/li&gt;
      &lt;li&gt;\(k = 4\): \(y^{(4)} = 0.085 + 0.53(0.085 - 0.72) = -0.252 \implies x^{(4)} = -0.126\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Notice the ripple:&lt;/strong&gt; At \(k = 4\), FISTA &lt;em&gt;overshot&lt;/em&gt; \(x^\star = 0\) to \(-0.126\), and the objective &lt;em&gt;increased&lt;/em&gt; from \(f(x^{(3)}) = \frac{1}{2}(0.085)^2 = 0.0036\) to \(f(x^{(4)}) = \frac{1}{2}(-0.126)^2 = 0.0079\)! Applying an &lt;strong&gt;adaptive restart&lt;/strong&gt; at \(k = 4\) (since \((y^{(4)} - x^{(4)})(x^{(4)} - x^{(3)}) = (-0.126)(-0.211) &amp;gt; 0\)) immediately kills the ripple.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;is-acceleration-always-useful&quot;&gt;Is acceleration always useful?&lt;/h1&gt;

&lt;p&gt;Acceleration methods such as FISTA can achieve faster convergence rates in theory, but in practice, acceleration is not always beneficial.&lt;/p&gt;

&lt;h2 id=&quot;when-acceleration-may-not-help&quot;&gt;When acceleration may not help&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;If the problem is well-conditioned (small condition number \(\kappa = L/\mu\)), plain proximal gradient already converges fast, at a linear rate. Acceleration gains little, and the momentum can even make it a bit slower. For example, on a 2D lasso with \(\kappa = 3\), ISTA needs 14 iterations and FISTA needs 16.&lt;/li&gt;
  &lt;li&gt;Acceleration helps most when the problem is ill-conditioned (large \(\kappa\)). There, plain proximal gradient is slow, and FISTA cuts the number of iterations by a large factor. The price is that the objective value can oscillate.&lt;/li&gt;
  &lt;li&gt;With a non-smooth \(g\), or when \(\nabla g\) has no useful Lipschitz constant, the \(O(1/k^2)\) guarantee does not apply.&lt;/li&gt;
  &lt;li&gt;The “Nesterov ripples” phenomenon makes the objective value non-monotonic: it can go up for some iterations before it goes down again.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;practical-advice&quot;&gt;Practical advice&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Use acceleration when the smooth part is ill-conditioned; that is where it pays off most.&lt;/li&gt;
  &lt;li&gt;When the problem is well-conditioned, plain proximal gradient is often enough.&lt;/li&gt;
  &lt;li&gt;Monitor the objective value. If the ripples are large, use a restart scheme (reset \(t_k = 1\) when the objective goes up) instead of giving up acceleration.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-05-03 Example: FISTA</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_05_03_example_FISTA/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_05_03_example_FISTA</id>
   <content type="html">&lt;p&gt;In 2009, Amir Beck and Marc Teboulle published a paper that became one of the most cited optimization articles of the twenty-first century: &lt;strong&gt;FISTA&lt;/strong&gt; (&lt;em&gt;Fast Iterative Shrinkage-Thresholding Algorithm&lt;/em&gt;). Built directly on Nesterov’s acceleration, FISTA replaces the simple linear weight \(\frac{k-2}{k+1}\) with the exact golden-ratio recurrence \(t_{k+1} = \frac{1 + \sqrt{1 + 4t_k^2}}{2}\), turning ISTA into a blazing-fast workhorse for image deblurring, compressed sensing, and large-scale Lasso.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-anatomy-of-the-fista-recurrence&quot;&gt;Key ideas: Anatomy of the FISTA Recurrence&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The Quadratic Recurrence for \(t_k\):&lt;/strong&gt; Starting from \(t_0 = 1\), the update \(t_{k+1} = \frac{1 + \sqrt{1 + 4t_k^2}}{2}\) is the exact positive root of \(t_{k+1}^2 - t_{k+1} = t_k^2\). That algebraic identity is what makes the Lyapunov proof telescope cleanly and guarantees \(t_k \ge \frac{k+1}{2}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Momentum Weight \(\frac{t_{k-1} - 1}{t_k}\):&lt;/strong&gt; Using \(\beta_k = \frac{t_{k-1} - 1}{t_k}\) gives \(\beta_1 = 0\) on the first step and approaches \(1 - \frac{3}{k}\) as \(k\) grows, closely matching Nesterov’s \(3/k\) friction law while tightening the constant in the \(O(1/k^2)\) bound.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — FISTA for Lasso:&lt;/strong&gt; Setting \(g(x) = \frac{1}{2}\|Ax - b\|_2^2\) and \(h(x) = \lambda\|x\|_1\) makes the FISTA step \(x^{(k)} = S_{\lambda / L}(y^{(k)} - \frac{1}{L} A^\top (A y^{(k)} - b))\), where \(L = \|A\|_2^2 = \lambda_{\max}(A^\top A)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Practical Extensions (MFISTA &amp;amp; Restarting):&lt;/strong&gt; Because FISTA can exhibit non-monotonic ripples, Beck &amp;amp; Teboulle introduced Monotone FISTA (MFISTA), which compares \(f(x^{(k)})\) against \(f(x^{(k-1)})\) and keeps the lower-objective point while preserving \(O(1/k^2)\) convergence.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-computing-the-exact-fista-sequence-t_k-and-momentum-weights-beta_k&quot;&gt;Worked example: Computing the Exact FISTA Sequence \(t_k\) and Momentum Weights \(\beta_k\)&lt;/h3&gt;

&lt;p&gt;Let’s compute the first four scalar weights \(t_k\) and momentum factors \(\beta_k = \frac{t_{k-1} - 1}{t_k}\) by hand, starting from \(t_0 = 1\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Step \(k = 1\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(t_1 = \frac{1 + \sqrt{1 + 4(1)^2}}{2} = \frac{1 + \sqrt{5}}{2} \approx 1.6180\) (literally the golden ratio \(\phi\)!).&lt;/li&gt;
      &lt;li&gt;Momentum weight: \(\beta_1 = \frac{t_0 - 1}{t_1} = \frac{1 - 1}{1.6180} = 0\).&lt;/li&gt;
      &lt;li&gt;Check identity: \(t_1^2 - t_1 = \phi^2 - \phi = 1 = t_0^2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step \(k = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(t_2 = \frac{1 + \sqrt{1 + 4(1.6180)^2}}{2} = \frac{1 + \sqrt{1 + 10.4721}}{2} = \frac{1 + 3.3871}{2} \approx 2.1935\).&lt;/li&gt;
      &lt;li&gt;Momentum weight: \(\beta_2 = \frac{t_1 - 1}{t_2} = \frac{0.6180}{2.1935} \approx 0.2817\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Step \(k = 3\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(t_3 = \frac{1 + \sqrt{1 + 4(2.1935)^2}}{2} = \frac{1 + \sqrt{20.246}}{2} \approx \frac{1 + 4.4996}{2} \approx 2.7498\).&lt;/li&gt;
      &lt;li&gt;Momentum weight: \(\beta_3 = \frac{t_2 - 1}{t_3} = \frac{1.1935}{2.7498} \approx 0.4340\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the growth lower bound \(t_k \ge (k+1)/2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(t_1 \approx 1.618 \ge 1.0\), \(t_2 \approx 2.194 \ge 1.5\), \(t_3 \approx 2.750 \ge 2.0\). Because \(f(x^{(k)}) - f^\star \le \frac{L \|x^{(0)} - x^\star\|_2^2}{2 t_{k-1}^2}\), this steady linear growth of \(t_k\) is the exact engine behind FISTA’s \(O(1/k^2)\) decay.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;example-fista&quot;&gt;Example: FISTA&lt;/h1&gt;

&lt;p&gt;In this section, we introduce an example of the Fast Iterative Shrinkage-Thresholding Algorithm (FISTA), which is an accelerated proximal gradient method.&lt;/p&gt;

&lt;h2 id=&quot;fista-algorithm&quot;&gt;FISTA Algorithm&lt;/h2&gt;
&lt;p&gt;The FISTA algorithm solves problems of the form:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\(\min_x g(x) + h(x)\)
where \(g\) is convex and differentiable with an \(L\)-Lipschitz gradient, and \(h\) is convex.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With a fixed step size \(\alpha \le 1/L\) (for example \(\alpha = 1/L\)), the update steps are:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Initialize \(x^{(0)} = x^{(-1)}\), \(t_0 = 1\).&lt;/li&gt;
  &lt;li&gt;For \(k = 1, 2, ...\):
    &lt;ul&gt;
      &lt;li&gt;
\[t_k = \frac{1 + \sqrt{1 + 4 t_{k-1}^2}}{2}\]
      &lt;/li&gt;
      &lt;li&gt;
\[y^{(k)} = x^{(k-1)} + \frac{t_{k-1} - 1}{t_k} (x^{(k-1)} - x^{(k-2)})\]
      &lt;/li&gt;
      &lt;li&gt;
\[x^{(k)} = \text{prox}_{\alpha}\left(y^{(k)} - \alpha \nabla g(y^{(k)})\right)\]
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here \(t_k\) is only the momentum sequence; it is not a step size. The step size in the prox step stays fixed at \(\alpha\). (With backtracking, \(\alpha\) may shrink, but it is still a separate quantity from \(t_k\).)&lt;/p&gt;

&lt;h2 id=&quot;application-to-lasso&quot;&gt;Application to Lasso&lt;/h2&gt;
&lt;p&gt;FISTA can be applied to Lasso regression, which involves minimizing a least squares loss with an \(L_1\) regularization term.&lt;/p&gt;

&lt;p&gt;FISTA achieves faster convergence compared to standard proximal gradient methods.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>09-05-02 Convergence analysis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_05_02_convergence_analysis/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_05_02_convergence_analysis</id>
   <content type="html">&lt;p&gt;Proving \(O(1/k)\) convergence for plain proximal gradient was straightforward because \(f(x^{(k)})\) decreases monotonically at every step. Proving \(O(1/k^2)\) convergence for accelerated proximal gradient is famously subtler—precisely because \(f(x^{(k)})\) is &lt;em&gt;not&lt;/em&gt; monotonic! Instead of proving \(f(x^{(k)}) \le f(x^{(k-1)})\), the proof constructs a clever &lt;strong&gt;Lyapunov potential function&lt;/strong&gt; combining the scaled objective gap \((k+1)^2 (f(x^{(k)}) - f^\star)\) with a kinetic-energy term, and shows that &lt;em&gt;this combined energy&lt;/em&gt; never increases.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-understanding-the-o1k2-convergence-theorem&quot;&gt;Key ideas: Understanding the \(O(1/k^2)\) Convergence Theorem&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — The \(O(1/(k+1)^2)\) Upper Bound:&lt;/strong&gt; Under \(L\)-smoothness of \(g\) and convexity of \(h\), accelerated proximal gradient with fixed step \(t \le 1/L\) satisfies \(f(x^{(k)}) - f^\star \le \frac{2L \|x^{(0)} - x^\star\|_2^2}{(k+1)^2}\). Notice the quadratic denominator \((k+1)^2\), which cuts iteration complexity from \(O(1/\varepsilon)\) down to \(O(1/\sqrt{\varepsilon})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Energy Conservation Instead of Monotonic Descent:&lt;/strong&gt; Because momentum injects kinetic energy, \(f(x^{(k)})\) can temporarily rise while kinetic energy drops, yet the total potential \(\mathcal{E}_k = t_k^2(f(x^{(k)}) - f^\star) + \frac{1}{2t}\|z^{(k)} - x^\star\|_2^2\) decreases monotonically (\(\mathcal{E}_k \le \mathcal{E}_{k-1}\)), immediately yielding \(f(x^{(k)}) - f^\star \le \mathcal{E}_0 / t_k^2 = O(1/k^2)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Backtracking Line Search Constant:&lt;/strong&gt; When \(L\) is unknown and backtracking shrinks \(t\) by factor \(\beta \in (0, 1)\), the exact same \(O(1/k^2)\) bound holds with \(L\) replaced by \(L/\beta\) (provided step sizes are non-increasing, \(t_k \le t_{k-1}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Optimality via Nesterov’s Lower Bound:&lt;/strong&gt; For high-dimensional smooth convex problems (\(n \ge 2k+1\)), no first-order method whose iterates lie in the span of past gradients can beat \(\Omega(L \|x^{(0)} - x^\star\|_2^2 / k^2)\), certifying that accelerated proximal gradient is worst-case optimal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-comparing-guaranteed-iteration-budgets-for-o1k-vs-o1k2&quot;&gt;Worked example: Comparing Guaranteed Iteration Budgets for \(O(1/k)\) vs. \(O(1/k^2)\)&lt;/h3&gt;

&lt;p&gt;Suppose a composite problem has \(L = 10\), initial squared distance \(\|x^{(0)} - x^\star\|_2^2 = 4\), step size \(t = 1/L = 0.1\), and target suboptimality \(\varepsilon = 10^{-3}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Plain Proximal Gradient bound:&lt;/strong&gt; \(f(x^{(k)}) - f^\star \le \frac{L \|x^{(0)} - x^\star\|_2^2}{2k} = \frac{10 \cdot 4}{2k} = \frac{20}{k}\).
    &lt;ul&gt;
      &lt;li&gt;Set \(\frac{20}{k} \le 10^{-3} \implies k \ge 20{,}000\) iterations.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Accelerated Proximal Gradient bound:&lt;/strong&gt; \(f(x^{(k)}) - f^\star \le \frac{2L \|x^{(0)} - x^\star\|_2^2}{(k+1)^2} = \frac{2 \cdot 10 \cdot 4}{(k+1)^2} = \frac{80}{(k+1)^2}\).
    &lt;ul&gt;
      &lt;li&gt;Set \(\frac{80}{(k+1)^2} \le 10^{-3} \implies (k+1)^2 \ge 80{,}000 \implies k + 1 \ge \sqrt{80{,}000} \approx 282.84 \implies k = 282\) iterations!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Speedup ratio:&lt;/strong&gt; Even though the numerator constant is \(4\times\) larger (\(80\) vs. \(20\)), the quadratic denominator reduces the guaranteed iteration count from &lt;strong&gt;20,000&lt;/strong&gt; down to &lt;strong&gt;282&lt;/strong&gt;—more than a &lt;strong&gt;\(70\times\) speedup&lt;/strong&gt;—and at \(\varepsilon = 10^{-5}\) the speedup jumps to over &lt;strong&gt;\(700\times\)&lt;/strong&gt;!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;convergence-analysis&quot;&gt;Convergence analysis&lt;/h1&gt;

&lt;p&gt;In this section, we analyze the convergence of the accelerated proximal gradient method.&lt;/p&gt;

&lt;h2 id=&quot;convergence-theorem&quot;&gt;Convergence Theorem&lt;/h2&gt;
&lt;p&gt;Suppose \(g\) is convex and differentiable, \(h\) is convex, and \(\nabla g\) is Lipschitz continuous with constant \(L &amp;gt; 0\). Then, the accelerated proximal gradient method with fixed step size \(t \le 1/L\) satisfies the following:&lt;/p&gt;

&lt;blockquote&gt;
\[f(x^{(k)}) - f^* \le \frac{2L \lVert x^{(0)} - x^* \rVert^2_2}{(k+1)^2}\]
&lt;/blockquote&gt;

&lt;p&gt;This means the convergence rate is \(O(1/k^2)\), which is faster than the standard proximal gradient method.&lt;/p&gt;

&lt;h2 id=&quot;backtracking-line-search&quot;&gt;Backtracking line search&lt;/h2&gt;
&lt;p&gt;The backtracking line search for the accelerated proximal gradient method is similar to that for the standard proximal gradient method, but the step size is chosen adaptively.&lt;/p&gt;

&lt;p&gt;For more details, refer to Beck and Teboulle (2009), “A Fast Iterative Shrinkage-Thresholding Algorithm for Linear Inverse Problems” (FISTA).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>09-05-01 Accelerated proximal gradient method</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_05_01_accelerated_proximal_gradient_method/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_05_01_accelerated_proximal_gradient_method</id>
   <content type="html">&lt;p&gt;Extending Nesterov’s smooth acceleration to composite nonsmooth problems \(f(x) = g(x) + h(x)\) was one of the landmark breakthroughs of 2000s optimization—independently refined by Nesterov (2007) and popularized by Beck and Teboulle (2009) as &lt;strong&gt;FISTA&lt;/strong&gt;. With only two lines of extra arithmetic—an extrapolated point \(v\) and a scalar momentum sequence—you keep the exact same per-iteration cost as proximal gradient descent while upgrading the convergence rate from \(O(1/\varepsilon)\) to the optimal \(O(1/\sqrt{\varepsilon})\).&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-mechanics-of-accelerated-proximal-gradient&quot;&gt;Key ideas: Mechanics of Accelerated Proximal Gradient&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Two-Sequence State (\(x^{(k)}\) and \(v^{(k)}\)):&lt;/strong&gt; The algorithm maintains the main proximal iterates \(x^{(k)}\) and an auxiliary extrapolated sequence \(v^{(k)} = x^{(k-1)} + \frac{k-2}{k+1}(x^{(k-1)} - x^{(k-2)})\). Notice that \(v^{(k)}\) may leave the sparse support or feasible set; the subsequent proximal map \(\operatorname{prox}_{t_k h}\) immediately snaps \(x^{(k)}\) back.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Same Oracle Cost as Plain Proximal Gradient:&lt;/strong&gt; Each iteration still performs exactly one smooth gradient evaluation \(\nabla g(v^{(k)})\) and one proximal evaluation \(\operatorname{prox}_{t_k h}\). There are no Hessians, no inner loops, and only one extra vector stored in memory.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Nesterov’s Historical Arc (1983–2007):&lt;/strong&gt; Nesterov first accelerated smooth unconstrained problems (1983), then refined estimate sequences (1988), bridged to nonsmooth problems via smoothing (2005), and finally unified composite optimization \(g + h\) (2007)—achieving \(O(1/\sqrt{\varepsilon})\) whenever \(h\) is prox-friendly.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Backtracking Compatibility:&lt;/strong&gt; Just like plain proximal gradient, accelerated proximal gradient supports backtracking line search on \(g\) at the extrapolated point \(v^{(k)}\) whenever \(L\) is unknown, preserving the \(O(1/k^2)\) rate.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-two-steps-of-accelerated-proximal-gradient-on-a-1d-lasso&quot;&gt;Worked example: Two Steps of Accelerated Proximal Gradient on a 1D Lasso&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Minimize $$f(x) = \frac{1}{2}(x - 5)^2 +&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\((so\)\nabla g(x) = x - 5\(,\)L = 1\(, exact optimum\)x^\star = S_1(5) = 4\() using conservative step size\)t = 0.5\(, starting from\)x^{(0)} = x^{(-1)} = 0\(, with momentum\)\beta_k = \frac{k-1}{k+2}\(for\)k = 1, 2$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Iteration \(k = 1\) (\(\beta_1 = 0\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Extrapolate: \(v^{(1)} = x^{(0)} + 0 = 0\).&lt;/li&gt;
      &lt;li&gt;Smooth step: \(u^{(1)} = 0 - 0.5(0 - 5) = 2.5\).&lt;/li&gt;
      &lt;li&gt;Soft-threshold with \(\lambda t = 1 \cdot 0.5 = 0.5\):
\(x^{(1)} = S_{0.5}(2.5) = 2.0.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Iteration \(k = 2\) (\(\beta_2 = 1/4 = 0.25\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Extrapolate: \(v^{(2)} = x^{(1)} + 0.25(x^{(1)} - x^{(0)}) = 2.0 + 0.25(2.0 - 0) = 2.5\).&lt;/li&gt;
      &lt;li&gt;Smooth step at \(v^{(2)}\): \(u^{(2)} = 2.5 - 0.5(2.5 - 5) = 2.5 + 1.25 = 3.75\).&lt;/li&gt;
      &lt;li&gt;Soft-threshold with \(\lambda t = 0.5\):
\(x^{(2)} = S_{0.5}(3.75) = 3.25.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare with plain ISTA (\(\beta_k \equiv 0\)) at \(k = 2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Plain ISTA gives \(u^{(2)}_{\text{ISTA}} = 2.0 - 0.5(2.0 - 5) = 3.5 \implies x^{(2)}_{\text{ISTA}} = S_{0.5}(3.5) = 3.0\).&lt;/li&gt;
      &lt;li&gt;Accelerated proximal gradient is already at \(3.25\) (distance \(0.75\) from \(x^\star = 4\)) vs. \(3.0\) (distance \(1.0\)) after just two steps!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;accelerated-proximal-gradient-method&quot;&gt;Accelerated proximal gradient method&lt;/h1&gt;

&lt;p&gt;If proximal gradient descent is accelerated, it can achieve the optimal convergence rate of \(O(1/\sqrt{\epsilon})\). Nesterov proposed four methods, three of which are acceleration methods:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;1983: Original acceleration method for smooth functions&lt;/li&gt;
  &lt;li&gt;1988: Another acceleration method for smooth functions&lt;/li&gt;
  &lt;li&gt;2005: Technique for smoothing nonsmooth functions along with the original acceleration method&lt;/li&gt;
  &lt;li&gt;2007: Acceleration method for composite functions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let’s look at the method of Beck and Teboulle (2008), which extends Nesterov’s (1983) method for composite functions.&lt;/p&gt;

&lt;h2 id=&quot;accelerated-proximal-gradient-method-1&quot;&gt;Accelerated proximal gradient method&lt;/h2&gt;
&lt;p&gt;As before, suppose \(g\) is convex and differentiable, and \(h\) is convex. The problem is defined as:&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\min_x g(x) + h(x)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;strong&gt;Accelerated proximal gradient method&lt;/strong&gt; considers the direction in which \(x\) was moving so that the direction does not change abruptly when moving to the next position. In other words, it gives momentum to the direction of progress, creating inertia to continue moving in the same direction as before.&lt;/p&gt;

&lt;p&gt;The initial value of the algorithm is set to \(x^{(0)} = x^{(-1)} \in \mathbb{R}^n\). Then, after calculating the position \(v\) considering momentum, the proximal gradient is performed.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
v &amp;amp; = x^{(k-1)} + \frac{k-2}{k + 1}  (x^{(k-1)} −x^{(k-2)}) \\
x^{(k)} &amp;amp; = \text{prox}_{t_k} (v − t_k \nabla g(v)), k = 1,2,3,...  \\
\end{align}\]
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;In the first step \(k = 1\), \(x^{(k-1)} −x^{(k-2)}\) is zero, so it is the same as the proximal gradient update.&lt;/li&gt;
  &lt;li&gt;In the next steps, \(v\) has momentum in the previous direction \(x^{(k-1)} −x^{(k-2)}\). As \(k\) increases, the momentum weight increases and converges to 1.&lt;/li&gt;
  &lt;li&gt;When \(h = 0\), this is the same as the &lt;strong&gt;accelerated gradient method&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The figure below shows how the momentum weight changes as \(k\) changes.&lt;/p&gt;

&lt;p&gt;In this figure, the value is negative when k = 0, but since the momentum term is zero at that time, it does not cause any problems. As k increases, the weight approaches 1, so the value is updated further and helps to converge faster.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter09/momentum_weight.png&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Momentum weights [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;lasso-example&quot;&gt;Lasso example&lt;/h2&gt;
&lt;p&gt;If we apply the accelerated proximal gradient to the Lasso example seen earlier, we get the results shown in the figure below. It can be seen that the accelerated proximal gradient has much faster performance compared to subgradient or proximal gradient methods.&lt;/p&gt;

&lt;p&gt;There is a part in the middle of the graph that jumps, which is called “Nesterov ripples.” Therefore, the accelerated proximal gradient is not monotonic decreasing and is not a descent method.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter09/accelerated_proximal_gradient.png&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig2] Accelerated Proximal Gradient [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>09-04 Special cases</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_04_special_cases/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_04_special_cases</id>
   <content type="html">&lt;p&gt;One of the deepest pleasures in convex optimization is watching seemingly unrelated algorithms snap together as special cases of a single template. Proximal gradient descent on \(f(x) = g(x) + h(x)\) is not merely one more algorithm—it is a unifying umbrella that contains unconstrained gradient descent (\(h = 0\)), projected gradient descent (\(h = I_C\)), and Martinet–Rockafellar’s proximal point / proximal minimization algorithm (\(g = 0\)) all at once. Seeing these connections lets you transfer convergence proofs and intuition effortlessly across all three regimes.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-the-unified-family-of-generalized-gradient-methods&quot;&gt;Key ideas: The Unified Family of Generalized Gradient Methods&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Smooth Limit (\(h(x) \equiv 0 \implies\) Gradient Descent):&lt;/strong&gt; When \(h = 0\), \(\operatorname{prox}_{t h}(y) = \arg\min_z \frac{1}{2t}\|z - y\|_2^2 = y\) (the identity map), reducing proximal gradient directly to \(x^{(k)} = x^{(k-1)} - t_k \nabla g(x^{(k-1)})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Indicator Limit (\(h(x) = I_C(x) \implies\) Projected Gradient Descent):&lt;/strong&gt; Setting \(h(x) = 0\) for \(x \in C\) and \(+\infty\) otherwise makes \(\operatorname{prox}_{t I_C}(y) = \arg\min_{z \in C} \|z - y\|_2^2 = P_C(y)\), recovering projected gradient descent with an \(O(1/\varepsilon)\) rate (beating projected &lt;em&gt;subgradient&lt;/em&gt;’s \(O(1/\varepsilon^2)\) whenever \(g\) is smooth!).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Pure Proximal Limit (\(g(x) \equiv 0 \implies\) Proximal Minimization / Point Algorithm):&lt;/strong&gt; When \(g = 0\), the update \(x^{(k)} = \operatorname{prox}_{t_k h}(x^{(k-1)})\) minimizes a strongly convex regularization of \(h\) at every step. It converges for &lt;em&gt;any&lt;/em&gt; step size \(t_k &amp;gt; 0\) (even without smoothness of \(h\)!), though evaluating \(\operatorname{prox}_{t_k h}\) can be as hard as minimizing \(h\) itself.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — When Prox Is Intractable:&lt;/strong&gt; If \(\operatorname{prox}_{t h}\) has no closed form (e.g., total variation or overlapping group Lasso), one must either solve the prox subproblem approximately (requiring summable inner errors) or switch to operator splitting (ADMM, Douglas–Rachford, primal-dual methods).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-formula-three-classical-algorithms&quot;&gt;Worked example: One Formula, Three Classical Algorithms&lt;/h3&gt;

&lt;p&gt;Let \(C = [0, \infty)\) (the nonnegative half-line), \(g(x) = \frac{1}{2}(x + 2)^2\) (so \(\nabla g(x) = x + 2\), \(L = 1\)), and start at \(x^{(0)} = 1\) with step size \(t = 0.5\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Case 1 — \(h(x) = 0\) (Ordinary Gradient Descent):&lt;/strong&gt;
\(x^{(1)} = \operatorname{prox}_{0.5 \cdot 0}(1 - 0.5(3)) = 1 - 1.5 = -0.5.\)
The iterate freely enters the negative half-line heading toward \(x^\star = -2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 2 — \(h(x) = I_{[0, \infty)}(x)\) (Projected Gradient Descent):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gradient proposal: \(y = 1 - 0.5(3) = -0.5\).&lt;/li&gt;
      &lt;li&gt;Prox of indicator = Euclidean projection onto \([0, \infty)\):
\(x^{(1)} = P_{[0, \infty)}(-0.5) = \max(-0.5,\; 0) = 0.\)
It immediately hits the constrained optimum \(x^\star = 0\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Case 3 — \(g(x) = 0\), \(h(x) = \frac{1}{2}(x + 2)^2\) (Proximal Minimization Algorithm):&lt;/strong&gt;
\(x^{(1)} = \arg\min_z \left\{ \frac{1}{2(0.5)}(z - 1)^2 + \frac{1}{2}(z + 2)^2 \right\} = \arg\min_z \left\{ (z - 1)^2 + \frac{1}{2}(z + 2)^2 \right\}.\)
Setting the derivative \(2(z - 1) + (z + 2) = 0 \implies 3z = 0 \implies x^{(1)} = 0\). Notice that unlike explicit gradient descent, this &lt;em&gt;implicit&lt;/em&gt; step stays stable for any \(t &amp;gt; 0\)—even \(t = 1000\) moves smoothly to \(z = \frac{1 - 2t}{1 + t} \approx -2\) without ever diverging!&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;special-cases&quot;&gt;Special cases&lt;/h1&gt;

&lt;p&gt;Proximal gradient descent is also called composite gradient descent or generalized gradient descent.&lt;/p&gt;

&lt;p&gt;Why is it called &lt;strong&gt;“generalized”&lt;/strong&gt;? The reason is that Proximal gradient descent encompasses all of the following special cases:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(h = 0 \to\) gradient descent&lt;/li&gt;
  &lt;li&gt;\(h = I_C \to\) projected gradient descent&lt;/li&gt;
  &lt;li&gt;\(g = 0 \to\) proximal minimization algorithm&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Therefore, all these algorithms have a convergence rate of \(O(1/\epsilon)\).&lt;/p&gt;

&lt;h2 id=&quot;projected-gradient-descent&quot;&gt;Projected gradient descent&lt;/h2&gt;
&lt;p&gt;When \(I_C(x)\) is the indicator function of a closed convex set \(C \in \mathbb{R}^n\), the problem of minimizing \(g(x)\) over the set \(C\) can be reformulated as follows. (Note: \(C\) must be a closed set so that the projection is well-defined.)&lt;/p&gt;

&lt;blockquote&gt;
\[\min_{x \in C} g(x) \iff \min_x g(x) + I_C(x)\]

\[I_C(x) = 
\begin{cases}
0, &amp;amp; x \in C \\
\infty, &amp;amp; x \notin C
\end{cases}\]
&lt;/blockquote&gt;

&lt;p&gt;At this time, the proximal mapping is defined as follows.&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{prox}_t(x)  
&amp;amp;= \underset{z}{\text{argmin}} \frac{1}{2t} \lVert x−z \rVert_2^2 + I_C(z) \\
&amp;amp; = \underset{z \in C}{\text{argmin}} \lVert x−z \rVert_2^2
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;As a result, the proximal mapping \(\text{prox}_t(x) = P_C(x)\) is the projection operator onto \(C\).&lt;/p&gt;

&lt;p&gt;The proximal gradient update step is: \(x^+ = P_C (x−t \nabla g(x) )\). In other words, after performing the gradient descent update, you project onto \(C\).&lt;/p&gt;

&lt;p&gt;In the figure below, the pink rectangle is the feasible set \(C\), and the current position is the upper of the two points below the rectangle. After taking a gradient descent step, you move outside \(C\), so you project back onto \(C\) to return inside the feasible set.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter09/projected_gradient_descent.png&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig1] Projected Gradient Descent [3]]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;proximal-minimization-algorithm&quot;&gt;Proximal minimization algorithm&lt;/h2&gt;

&lt;p&gt;Consider the problem of minimizing a convex function \(h\) as follows. Here, \(h\) does not need to be differentiable and \(g(x) = 0\).&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;\begin{align}
\min_x h(x)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The proximal mapping is defined as:&lt;/p&gt;
&lt;blockquote&gt;
\[\begin{align}
x^{(k)} &amp;amp;= \text{prox}_{t_k} \big(x^{(k-1)} - t_k \nabla g ( x^{(k-1)} ) \big) , \qquad k = 1, 2, 3, ... \\
&amp;amp;= \text{prox}_{t_k} \big(x^{(k-1)} \big) ,  \qquad \qquad \qquad \qquad \; k = 1, 2, 3, ... \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Therefore, the proximal gradient update step is:&lt;/p&gt;
&lt;blockquote&gt;
\[x^+ = \underset{z}{\text{argmin}} \frac{1}{2t} \lVert x−z \rVert_2^2 + h(z)\]
&lt;/blockquote&gt;

&lt;p&gt;This proximal gradient method, defined only by \(h\) with \(g = 0\), is called the &lt;strong&gt;proximal minimization algorithm (PMA)&lt;/strong&gt;. This method is faster than subgradient methods, but if the proximal mapping does not have a closed form, it cannot be implemented.&lt;/p&gt;

&lt;h2 id=&quot;what-happens-if-we-cant-evaluate-prox&quot;&gt;What happens if we can’t evaluate prox?&lt;/h2&gt;
&lt;p&gt;Theoretically, when applying proximal gradient to \(f = g + h\), it is assumed that the prox function can be computed exactly. That is, it is assumed that the minimum can be found exactly via the proximal mapping.&lt;/p&gt;
&lt;blockquote&gt;
\[\text{prox}_t(x )= \underset{z}{\text{argmin}} \frac{1}{2t} \lVert x−z \rVert_2^2 + h(z)\]
&lt;/blockquote&gt;

&lt;p&gt;In general, it is not clear what happens if the minimum is only approximated.
However, if the error in approximating the prox operator can be precisely controlled, it has been shown that the original convergence rate can be maintained. (Schmidt et al. (2011), Convergence rates of inexact proximal-gradient methods for convex optimization)&lt;/p&gt;

&lt;p&gt;In practice, if prox can be computed approximately, it will be performed with high accuracy.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>09-03 Example: matrix completion</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_03_example_matrix_completion/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_03_example_matrix_completion</id>
   <content type="html">&lt;p&gt;In 2006, Netflix offered a one-million-dollar prize to anyone who could improve movie rating predictions by 10%. Mathematically, the user-by-movie rating table is a giant matrix with 99% of its entries missing—and predicting the blanks requires assuming the true preference matrix has &lt;strong&gt;low rank&lt;/strong&gt; (most viewers’ tastes are combinations of a few latent genres). Minimizing rank directly is NP-hard, so optimization theorists replace rank with its tightest convex envelope: the &lt;strong&gt;nuclear (trace) norm&lt;/strong&gt; \(\|B\|_* = \sum_i \sigma_i(B)\). Proximal gradient descent then solves matrix completion with extraordinary elegance by soft-thresholding singular values at every step!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-low-rank-matrix-completion-via-proximal-gradient&quot;&gt;Key ideas: Low-Rank Matrix Completion via Proximal Gradient&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Observed-Entry Projection \(P_\Omega\):&lt;/strong&gt; Given observed index set \(\Omega\), \([P_\Omega(B)]_{ij} = B_{ij}\) if \((i, j) \in \Omega\) and \(0\) otherwise. The smooth data-fidelity term \(g(B) = \frac{1}{2}\|P_\Omega(Y) - P_\Omega(B)\|_F^2\) has Lipschitz gradient \(\nabla g(B) = -(P_\Omega(Y) - P_\Omega(B))\) with constant \(L = 1\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — Trace (Nuclear) Norm as Matrix \(\ell_1\):&lt;/strong&gt; Just as \(\|x\|_1\) is the convex relaxation of vector sparsity \(\|x\|_0\), the trace norm \(\|B\|_* = \sum_{i=1}^r \sigma_i(B)\) is the convex relaxation of \(\operatorname{rank}(B)\), promoting low-rank solutions by driving small singular values to exact zero.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Singular Value Thresholding (SVT) Proximal Operator:&lt;/strong&gt; The proximal mapping of \(h(B) = \lambda \|B\|_*\) is \(\operatorname{prox}_{t h}(Z) = U \operatorname{diag}((\sigma_i - \lambda t)_+) V^\top\), where \(Z = U \Sigma V^\top\) is the SVD of \(Z\). It leaves singular vectors untouched and soft-thresholds each singular value by \(\lambda t\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Soft-Impute Algorithm:&lt;/strong&gt; Because \(L = 1\), choosing step size \(t = 1\) simplifies the gradient proposal to \(B^{(k-1)} + P_\Omega(Y - B^{(k-1)}) = P_\Omega(Y) + P_{\Omega^\perp}(B^{(k-1)})\)—literally filling missing entries with the current estimate and applying SVT!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-soft-impute-proximal-gradient-step-on-a-2-times-2-matrix&quot;&gt;Worked example: One Soft-Impute (Proximal Gradient) Step on a \(2 \times 2\) Matrix&lt;/h3&gt;

&lt;p&gt;Suppose we observe three entries of a \(2 \times 2\) matrix \(Y\): \(Y_{11} = 4,\; Y_{12} = 0,\; Y_{21} = 0\), while \(Y_{22}\) is missing (\(\Omega = \{(1,1), (1,2), (2,1)\}\)). We solve \(\min_B \frac{1}{2}\|P_\Omega(Y - B)\|_F^2 + \lambda \|B\|_*\) with \(\lambda = 1.5\), step size \(t = 1\), starting from \(B^{(0)} = \begin{pmatrix}0 &amp;amp; 0 \\ 0 &amp;amp; 2\end{pmatrix}\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Form the gradient-step matrix \(Z^{(0)} = P_\Omega(Y) + P_{\Omega^\perp}(B^{(0)})\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;On observed entries \(\Omega\), insert \(Y\): \((4, 0, 0)\).&lt;/li&gt;
      &lt;li&gt;On missing entry \((2, 2)\), keep \(B^{(0)}_{22} = 2\).
\(Z^{(0)} = \begin{pmatrix}4 &amp;amp; 0 \\ 0 &amp;amp; 2\end{pmatrix}.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the SVD of \(Z^{(0)}\):&lt;/strong&gt;
Since \(Z^{(0)}\) is already diagonal and nonnegative, \(U = V = I_2\) with singular values \(\sigma_1 = 4\) and \(\sigma_2 = 2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply Singular Value Soft-Thresholding with threshold \(\lambda t = 1.5 \cdot 1 = 1.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(\tilde{\sigma}_1 = \max(4 - 1.5,\; 0) = 2.5\).&lt;/li&gt;
      &lt;li&gt;\(\tilde{\sigma}_2 = \max(2 - 1.5,\; 0) = 0.5\).
\(B^{(1)} = \begin{pmatrix}2.5 &amp;amp; 0 \\ 0 &amp;amp; 0.5\end{pmatrix}.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Watch the rank drop on Iteration 2:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(Z^{(1)} = \begin{pmatrix}4 &amp;amp; 0 \\ 0 &amp;amp; 0.5\end{pmatrix}\) (singular values \(4\) and \(0.5\)).&lt;/li&gt;
      &lt;li&gt;Threshold by \(1.5\): \(\tilde{\sigma}_1 = 2.5\), \(\tilde{\sigma}_2 = \max(0.5 - 1.5, 0) = 0\)!&lt;/li&gt;
      &lt;li&gt;Thus \(B^{(2)} = \begin{pmatrix}2.5 &amp;amp; 0 \\ 0 &amp;amp; 0\end{pmatrix}\)—an exact &lt;strong&gt;rank-1&lt;/strong&gt; fixed point reached in just two steps!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;example-matrix-completion&quot;&gt;Example: matrix completion&lt;/h1&gt;

&lt;p&gt;In various applications, measured data is often represented as a matrix. In these cases, most entries in the matrix may be empty, with only a few entries containing observed data, leading to a sparse matrix. The challenge of filling in the missing entries in such a matrix is referred to as the &lt;strong&gt;Matrix completion&lt;/strong&gt; problem.&lt;/p&gt;

&lt;p&gt;For instance, this issue can occur in recommendation systems when suggesting products or services to customers who have not yet made a purchase.&lt;/p&gt;

&lt;h2 id=&quot;matrix-completion-problem&quot;&gt;Matrix Completion Problem&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;Matrix completion&lt;/strong&gt; problem can be articulated as follows:&lt;/p&gt;

&lt;p&gt;Let the matrix \(Y \in \mathbb{R}^{m\times n}\) represent the observed data, and let \(Y_{ij}, (i,j) \in \Omega\) denote the entries that contain observed data. The matrix \(B\) is the estimated matrix used to predict the missing entries.&lt;/p&gt;

&lt;blockquote&gt;
\[\min_B \frac{1}{2} \sum_{(i,j)\in\Omega} (Y_{ij} −B_{ij})^2 + \lambda\lVert B \rVert_{tr}\]
&lt;/blockquote&gt;

&lt;p&gt;The first term in the objective function aims to minimize the error between matrix \(B\) and the observed data, while the second term encourages matrix \(B\) to be low-rank. (It is assumed that matrix B resides on a low-dimensional manifold.) Consequently, matrix \(B\) fills in the missing entries with the lowest-dimensional values that align with the observed data.&lt;/p&gt;

&lt;h3 id=&quot;reference-trace-norm&quot;&gt;[Reference] Trace Norm&lt;/h3&gt;
&lt;p&gt;The trace norm of a matrix is defined as the sum of its singular values.&lt;/p&gt;

&lt;blockquote&gt;
\[\lVert B \rVert_{tr} = \text{trace}(\sqrt{B^* B}) = \sum_{i=1}^r \sigma_i(B), \quad r = rank(B)\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(B^* B\) is positive semi-definite, and the singular values are ordered as \(\sigma_1(X) \ge ... \ge \sigma_r(X) \ge 0\).&lt;/p&gt;

&lt;h3 id=&quot;reference-l1-norm-regularizer-vs-trace-norm-regularizer&quot;&gt;[Reference] &lt;strong&gt;L1&lt;/strong&gt; Norm Regularizer vs. Trace Norm Regularizer&lt;/h3&gt;
&lt;p&gt;This problem can be interpreted as matrix soft-thresholding, where the vector in the original soft-thresholding is substituted with a matrix. In the regularizer term, the &lt;strong&gt;L1&lt;/strong&gt; norm regularizer for vectors (\(\lVert \cdot \rVert_{1}\)) is replaced by the trace norm regularizer (\(\lVert \cdot \rVert_{tr}\)) for matrices, and indeed, the functions of the two regularizers are analogous.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;L1&lt;/strong&gt; norm regularizer induces sparsity in the vector, while the trace norm regularizer similarly induces sparsity in the singular value vector of the matrix. When the matrix is diagonal, the diagonal elements can be viewed as the singular value vector, and the trace norm regularizer minimizes the sum of the singular values, promoting sparsity in the singular value vector.&lt;/p&gt;

&lt;p&gt;In this context, the trace norm \(\lVert B \rVert_{tr}\) serves as an approximation for \(\text{Rank}(B)\).&lt;/p&gt;

&lt;h2 id=&quot;proximal-gradient-descent&quot;&gt;Proximal gradient descent&lt;/h2&gt;
&lt;p&gt;When this problem is framed using a projection operator, proximal gradient descent can be effectively utilized.&lt;/p&gt;
&lt;h3 id=&quot;projection-operator&quot;&gt;Projection Operator&lt;/h3&gt;
&lt;p&gt;Let’s define the projection operator \(P_\Omega\) for the observed values as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[[ P_\Omega(B) ] _{ij} =
\begin{cases}
B_{ij}, &amp;amp; (i,j) ∈ \Omega \\\
0, &amp;amp; (i,j) \notin \Omega
\end{cases}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;objective-function&quot;&gt;Objective Function&lt;/h3&gt;
&lt;p&gt;Utilizing the projection operator, the objective function is defined as:&lt;/p&gt;

&lt;blockquote&gt;
\[f(B) = \underbrace{ \frac{1}{2} \lVert P_\Omega(Y) − P_\Omega(B) \rVert_F^2 }_{g(B)} + \underbrace{ \lambda \lVert B \rVert_{tr} }_{h(B)}\]
&lt;/blockquote&gt;

&lt;p&gt;Now, the function \(f(B)\) consists of a differentiable part \(g(B)\) and a non-differentiable part \(h(B)\).&lt;/p&gt;

&lt;h3 id=&quot;proximal-mapping&quot;&gt;Proximal Mapping&lt;/h3&gt;
&lt;p&gt;To apply proximal gradient descent, we need to compute the gradient of the function \(g(B)\) and define the proximal mapping.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Gradient of \(g(B)\): \(\nabla g(B) = −(P_\Omega(Y )−P_\Omega(B))\)&lt;/li&gt;
  &lt;li&gt;Proximal mapping:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
\[\begin{align}
\text{prox}_t (B) = \underset{Z}{\text{argmin}} \frac{1}{2t} \Vert B−Z \Vert_F^2 + \lambda \Vert Z \Vert_{tr}
\end{align}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;matrix-svd--soft-thresholding&quot;&gt;Matrix SVD &amp;amp; Soft-thresholding&lt;/h3&gt;
&lt;p&gt;The proximal mapping corresponds to matrix soft-thresholding at level \(\lambda\): \(\text{prox}_t(B) = S_{\lambda t}(B)\).&lt;/p&gt;

&lt;p&gt;Typically, matrix \(B\) is large, so Singular Vector Decomposition (SVD) is employed to minimize the computational load. If we perform SVD such that \(B = U \Sigma V^T\), then \(S_\lambda(B)\) can be defined as:&lt;/p&gt;

&lt;blockquote&gt;
\[S_\lambda(B) = U \Sigma_\lambda V^T\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(\Sigma_\lambda\) is a diagonal matrix defined as follows:&lt;/p&gt;

&lt;blockquote&gt;
\[(\Sigma_\lambda)_{ii} = \max \{ \Sigma_{ii} −\lambda,0 \}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;reference-sigma_lambda_ii--max--sigma_ii-lambda0---inducement&quot;&gt;[Reference] \((\Sigma_\lambda)_{ii} = \max \{ \Sigma_{ii} −\lambda,0 \}\)  inducement&lt;/h3&gt;
&lt;p&gt;How is this expression derived? Assuming \(\text{prox}_t(B) = Z\), we have:
(Differentiating the right-hand side of \(\text{prox}_t(B)\) with respect to Z yields the following result.)&lt;/p&gt;

&lt;blockquote&gt;
\[0 ∈ Z − B + \lambda t \cdot \partial \lVert Z \rVert_{tr}\]
&lt;/blockquote&gt;

&lt;p&gt;Rearranging this expression gives:&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
Z &amp;amp; = B - \lambda t \cdot \partial \lVert Z \rVert_{tr} \\
 &amp;amp; = U \Sigma V^T - \lambda t \cdot (UV^T + W) \\
 &amp;amp; = U (\Sigma - \lambda t) V^T - \lambda t  W \\
 &amp;amp; = U (\Sigma - \lambda ) V^T  \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;The final expression can be obtained when the Lipschitz constant is \(L=1\) and \(W\) is 0.&lt;/p&gt;

&lt;p&gt;Thus, we have \(\text{prox}_t(B) = S_\lambda(B) = Z\), leading to the derivation of the following expression:&lt;/p&gt;

&lt;blockquote&gt;
\[(\Sigma_\lambda)_{ii} = \max \{ \Sigma_{ii} −\lambda,0 \}\]
&lt;/blockquote&gt;

&lt;h3 id=&quot;reference-derivative-of-trace-norm&quot;&gt;[Reference] Derivative of Trace Norm&lt;/h3&gt;
&lt;p&gt;If \(Z = U \Sigma V^T\), the derivative of the trace norm is given by:&lt;/p&gt;
&lt;blockquote&gt;
\[\partial \lVert Z \rVert_{tr} = \{UV^T + W : \lVert W \rVert_{op} ≤ 1, U^TW = 0, WV = 0 \}\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(\lVert W \rVert_{op}\) represents the operator norm, with the largest singular value being less than 1. Additionally, \(W\) is orthogonal to both \(U^T\) and \(V\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For proof, refer to &lt;a href=&quot;https://math.stackexchange.com/questions/701062/derivative-of-the-nuclear-norm-with-respect-to-its-argument&quot;&gt;Derivative of the nuclear norm with respect to its argument&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;proximal-gradient-update&quot;&gt;Proximal gradient update&lt;/h3&gt;
&lt;p&gt;Now, let’s define the proximal gradient update equation.&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = S_{\lambda t} ( B + t( P_\Omega(Y) − P_\Omega(B) ) )\]
&lt;/blockquote&gt;

&lt;p&gt;When \(L = 1\), \(\nabla g(B)\) is Lipschitz continuous, allowing us to choose a fixed step size of \(t = 1\).&lt;/p&gt;

&lt;p&gt;Consequently, the update equation simplifies to:&lt;/p&gt;

&lt;blockquote&gt;
\[B^+ = S_\lambda (P_\Omega(Y) + P_\Omega^\bot (B) )\]
&lt;/blockquote&gt;

&lt;p&gt;Here, \(P_\Omega^\bot\) represents the projection onto the unobserved values, satisfying the equation \(P_\Omega(B) + P_\Omega^\bot (B) = B\).&lt;/p&gt;

&lt;p&gt;In this equation, \(P_\Omega(Y)\) denotes the observed part, while \(P_\Omega^\bot (B)\) represents the missing part. The \(S_\lambda\) function is straightforward to compute, as it only requires performing SVD and calculating \((\Sigma_\lambda)_{ii} = \max \{ \Sigma_{ii} −\lambda,0 \}\).&lt;/p&gt;

&lt;h2 id=&quot;soft-impute-algorithm&quot;&gt;Soft-Impute Algorithm&lt;/h2&gt;
&lt;p&gt;This algorithm is known as &lt;strong&gt;Soft-Impute&lt;/strong&gt; and provides a simple yet effective solution for matrix completion. When dealing with large matrices, the computational cost of SVD can be high. However, due to the sparsity of \(P_\Omega(Y)\) and the low rank of \(P_\Omega^\bot (B)\) in this algorithm, SVD can be performed efficiently.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For more detailed information, please refer to the paper: Mazumder et al. (2011), “Spectral regularization algorithms for learning
large incomplete matrices”&lt;/li&gt;
&lt;/ul&gt;

</content>
 </entry>
 
 <entry>
   <title>09-02 Convergence analysis</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_02_convergence_analysis/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_02_convergence_analysis</id>
   <content type="html">&lt;p&gt;How can an algorithm that minimizes a &lt;em&gt;nondifferentiable&lt;/em&gt; objective \(f = g + h\) achieve the exact same \(O(1/\varepsilon)\) convergence rate as smooth gradient descent? The secret lies in a remarkable algebraic disguise: by defining the &lt;strong&gt;generalized gradient&lt;/strong&gt; \(G_t(x) = \frac{1}{t}(x - \operatorname{prox}_{t h}(x - t\nabla g(x)))\), every proximal gradient step looks formally identical to smooth gradient descent—and obeys the same sufficient-decrease inequality whenever \(t \le 1/L\) or Armijo-style backtracking holds!&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-proving-the-o1varepsilon-proximal-rate&quot;&gt;Key ideas: Proving the \(O(1/\varepsilon)\) Proximal Rate&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — \(L\)-Smoothness of \(g\) (Quadratic Upper Bound):&lt;/strong&gt; Assuming \(\nabla g\) is \(L\)-Lipschitz guarantees \(g(y) \le g(x) + \nabla g(x)^\top(y - x) + \frac{L}{2}\|y - x\|_2^2\). Whenever \(t \le 1/L\), the proximal subproblem majorizes \(f\) globally, ensuring monotonic descent \(f(x^{(k)}) \le f(x^{(k-1)})\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — The Generalized Gradient \(G_t(x)\):&lt;/strong&gt; Rewriting \(x^+ = x - t G_t(x)\) implies \(G_t(x) - \nabla g(x) \in \partial h(x^+)\) by first-order optimality of \(\operatorname{prox}_{t h}\). Consequently, \(G_t(x) = 0 \iff 0 \in \nabla g(x) + \partial h(x) = \partial f(x)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 3 — Key Descent Inequality:&lt;/strong&gt; For \(t \le 1/L\) and any \(z\), \(f(x^+) \le f(z) + G_t(x)^\top(x - z) - \frac{t}{2}\|G_t(x)\|_2^2\). Setting \(z = x\) shows guaranteed descent of \(\frac{t}{2}\|G_t(x)\|_2^2\); setting \(z = x^\star\) telescopes \(\|x^{(k)} - x^\star\|_2^2\) cleanly to yield \(f(x^{(k)}) - f^\star \le \frac{\|x^{(0)} - x^\star\|_2^2}{2 k t}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 4 — Backtracking Line Search Without Knowing \(L\):&lt;/strong&gt; When \(L\) is unknown or expensive to compute (e.g., top singular value of a massive matrix), shrinking \(t \leftarrow \beta t\) until \(g(x - t G_t(x)) \le g(x) - t\nabla g(x)^\top G_t(x) + \frac{t}{2}\|G_t(x)\|_2^2\) preserves the exact \(O(1/k)\) rate with effective step size \(\ge \min\{t_0, \beta/L\}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-verifying-the-generalized-gradient--descent-bound&quot;&gt;Worked example: Verifying the Generalized Gradient &amp;amp; Descent Bound&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Take \(g(x) = 2x^2\) (so \(\nabla g(x) = 4x\), Lipschitz constant \(L = 4\)) and $$h(x) =&lt;/td&gt;
      &lt;td&gt;x&lt;/td&gt;
      &lt;td&gt;\(on\)\mathbb{R}\((minimizer\)x^\star = 0, f^\star = 0\(). Start at\)x^{(0)} = 1\(with step size\)t = 1/L = 0.25$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the proximal gradient step:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Smooth step: \(u = x^{(0)} - t\nabla g(x^{(0)}) = 1 - 0.25(4) = 0\).&lt;/li&gt;
      &lt;li&gt;Prox step (threshold \(t \cdot 1 = 0.25\)): \(x^{(1)} = S_{0.25}(0) = 0\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute the generalized gradient \(G_t(x^{(0)})\):&lt;/strong&gt;
\(G_t(1) = \frac{x^{(0)} - x^{(1)}}{t} = \frac{1 - 0}{0.25} = 4.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the sufficient-decrease inequality \(f(x^{(1)}) \le f(x^{(0)}) - \frac{t}{2}\|G_t(x^{(0)})\|_2^2\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Left-hand side: \(f(x^{(1)}) = f(0) = 0\).&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Right-hand side: $$f(1) - \frac{0.25}{2}(4^2) = (2(1)^2 +&lt;/td&gt;
              &lt;td&gt;1&lt;/td&gt;
              &lt;td&gt;) - 0.125(16) = 3 - 2 = 1$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Indeed \(0 \le 1\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check the \(O(1/k)\) theorem bound at \(k = 1\):&lt;/strong&gt;
\(\frac{\|x^{(0)} - x^\star\|_2^2}{2kt} = \frac{(1 - 0)^2}{2 \cdot 1 \cdot 0.25} = \frac{1}{0.5} = 2 \ge 0 = f(x^{(1)}) - f^\star.\)
Notice also what happens if we &lt;em&gt;violate&lt;/em&gt; \(t \le 1/L\) by choosing \(t = 1 &amp;gt; 0.25\): the backtracking test \(g(x^+) \le g(x) - t\nabla g(x)^\top G_t(x) + \frac{t}{2}\|G_t(x)\|_2^2\) immediately triggers and shrinks \(t\) back into the safe regime.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;convergence-analysis&quot;&gt;Convergence analysis&lt;/h1&gt;
&lt;p&gt;In this section, we analyze the convergence of proximal gradient descent.&lt;/p&gt;

&lt;h2 id=&quot;convergence-analysis-1&quot;&gt;Convergence Analysis&lt;/h2&gt;
&lt;p&gt;For the objective function \(f(x) = g(x) + h(x)\), we assume the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(g\) is convex, differentiable, and &lt;strong&gt;dom&lt;/strong&gt;\((g) = \mathbb{R}^n\), and \(\nabla g\) is Lipschitz continuous (\(L &amp;gt; 0\)).&lt;/li&gt;
  &lt;li&gt;\(h\) is convex, and \(\text{prox}_{t}(x) = \underset{z} {\text{argmin}} \{ \parallel x - z \parallel_2^2/ (2t) + h(z) \}\) needs to be computed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;convergence-theorem&quot;&gt;Convergence Theorem&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Proximal gradient descent&lt;/strong&gt; satisfies the following equation for a fixed step size \(t \le 1/L\): 
\begin{align}
f(x^{(k)}) - f^{*} \le  \frac{ \lVert x^{(0)} - x^{*} \rVert^2_2 }{2tk}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Proximal gradient descent has a convergence rate of \(O(1/k)\) or \(O(1/\epsilon)\), which is the same performance as gradient descent. However, this performance is based on the number of iterations, not the number of operations. (The number of operations can vary depending on the function \(h\).)&lt;/p&gt;

&lt;h2 id=&quot;backtracking-line-search&quot;&gt;Backtracking line search&lt;/h2&gt;
&lt;p&gt;The backtracking line search method of proximal gradient descent is similar to gradient descent but operates only on the smooth part \(g\), not the function \(f\).&lt;/p&gt;

&lt;p&gt;First, set the parameter to \(0 &amp;lt; \beta &amp;lt; 1\) and start with \(t=1\). In each iteration, reduce \(t\) to \(t = \beta t\) while satisfying the following condition, and update proximal gradient descent if the condition is not met.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
g(x - tG_t(x)) &amp;gt; g(x) - t \nabla g(x)^T G_t(x) + \frac{t}{2} \parallel G_t(x) \parallel_2 ^2
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This backtracking condition means that the value of the function \(g\) at the next step location \(x - tG_t(x)\) is greater than the value of the Taylor second-order approximation of the function \(g\).&lt;/p&gt;

&lt;p&gt;If \(G_t(x) = \nabla g(x)\) in this equation, we can see that \(g(x - t \nabla g(x)) &amp;gt; g(x) - \alpha t \lVert \nabla g(x) \rVert_2^2\), which becomes identical to the backtracking condition of gradient descent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For more details on the backtracking of gradient descent, refer to &lt;a href=&quot;/contents/en/chapter06/06_02_02_backtracking_line_search/&quot;&gt;06-02-02 backtracking line search&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;backtracking-line-search-algorithm&quot;&gt;Backtracking line search algorithm&lt;/h3&gt;
&lt;p&gt;If we summarize this in an algorithm, it is as follows. (However, \(\nabla x = - t G_t(x)\))&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Initialize the parameters. (\(0 \lt \beta \lt 1\), \(0 \lt \alpha \le 1/2\))&lt;/li&gt;
  &lt;li&gt;In each iteration, initialize \(t = t_{\text{init}}\). (\(t_{\text{init}} = 1\))&lt;/li&gt;
  &lt;li&gt;If the condition \(g(x - tG_t(x)) \gt g(x) - t \nabla g(x)^T G_t(x) + \frac{t}{2} \parallel G_t(x) \parallel_2 ^2\) is satisfied, reduce \(t = \beta t\). Repeat step 3 while this condition is met.&lt;/li&gt;
  &lt;li&gt;Perform the gradient descent update \(x^+ = x - t G_t(x) = \text{prox}_t(x - t \nabla g(x))\).&lt;/li&gt;
  &lt;li&gt;If the termination condition is not met, go back to step 2.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When backtracking in proximal gradient descent, since \(G_t(x)\) is computed repeatedly, the proximal mapping included in \(G_t(x)\) is also computed repeatedly. Since the proximal mapping is very costly to compute, the overall computational cost of backtracking can be high.&lt;/p&gt;

&lt;h3 id=&quot;convergence-theorem-1&quot;&gt;Convergence Theorem&lt;/h3&gt;
&lt;p&gt;Under the same assumptions as above, the backtracking line search method also satisfies the same performance.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Proximal gradient descent&lt;/strong&gt; satisfies the following equation for backtracking line search. The step size is \(t_{\text{min}} = \text{min} \{1,\beta /L \}\).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
\[f(x^{(k)})−f^{\star} ≤ \frac{\lVert x^{(0)} − x^{\star} \rVert_{2}^{2}}{2 t_{min}k}, \space t_{\text{min}} = \text{min} \{ 1, \beta / L \} \\\]
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>09-01 Proximal gradient descent</title>
   <link href="https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_01_proximal_gradient_descent/"/>
   <updated>2020-01-08T00:00:00+00:00</updated>
   <id>https://optimization-for-data-science-iuh-2025.pages.dev/contents/en/chapter09/09_01_proximal_gradient_descent</id>
   <content type="html">&lt;p&gt;When minimizing a smooth function \(g\), gradient descent works because \(x - t\nabla g(x)\) minimizes the local quadratic model \(g(x) + \nabla g(x)^\top(z - x) + \frac{1}{2t}\|z - x\|_2^2\). The breakthrough idea behind &lt;strong&gt;proximal gradient descent&lt;/strong&gt; is stunningly simple: when your objective is \(f(x) = g(x) + h(x)\), keep that exact quadratic model for the smooth part \(g\), leave the nonsmooth part \(h(z)\) &lt;em&gt;untouched&lt;/em&gt;, and minimize their sum! That single design choice births the proximal operator and unlocks exact sparsity in problems like Lasso via ISTA.&lt;/p&gt;

&lt;h2 id=&quot;key-ideas-from-quadratic-models-to-soft-thresholding-ista&quot;&gt;Key ideas: From Quadratic Models to Soft-Thresholding (ISTA)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 1 — Partial Quadratic Majorization:&lt;/strong&gt; Replacing \(g(z)\) by \(g(x) + \nabla g(x)^\top(z - x) + \frac{1}{2t}\|z - x\|_2^2\) while keeping \(h(z)\) exact yields the update \(x^+ = \arg\min_z \left\{\frac{1}{2t}\|z - (x - t\nabla g(x))\|_2^2 + h(z)\right\}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pillar 2 — The Proximal Mapping \(\operatorname{prox}_{t h}(y)\):&lt;/strong&gt; Because \(\frac{1}{2t}\|z - y\|_2^2\) is strictly convex, \(\operatorname{prox}_{t h}(y)\) is always well-defined and unique for any closed proper convex \(h\). Importantly, \(\operatorname{prox}_{t h}\) depends &lt;em&gt;only&lt;/em&gt; on \(h\), never on the data matrix inside \(g\).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 3 — Separability &amp;amp; Closed-Form Soft-Thresholding:&lt;/strong&gt; When $$h(x) = \lambda |x|&lt;em&gt;1 = \sum&lt;/em&gt;{j=1}^p \lambda&lt;/td&gt;
          &lt;td&gt;x_j&lt;/td&gt;
          &lt;td&gt;\(, the proximal problem decouples into\)p\(independent 1D problems whose exact solution is coordinatewise soft-thresholding\)[S_{\lambda t}(y)]_j = \operatorname{sign}(y_j)\max(&lt;/td&gt;
          &lt;td&gt;y_j&lt;/td&gt;
          &lt;td&gt;- \lambda t, 0)$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Pillar 4 — ISTA (Iterative Shrinkage-Thresholding Algorithm):&lt;/strong&gt; Applying proximal gradient descent to Lasso \(g(\beta) = \frac{1}{2}|y - X\beta|_2^2\), \(h(\beta) = \lambda |\beta|_1\) gives \(\beta^{(k)} = S_{\lambda t}(\beta^{(k-1)} + t X^\top (y - X\beta^{(k-1)}))\), producing exact zeros on every iteration where $$&lt;/td&gt;
          &lt;td&gt;y_j&lt;/td&gt;
          &lt;td&gt;\le \lambda t$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;worked-example-one-full-ista-iteration-by-hand&quot;&gt;Worked example: One Full ISTA Iteration by Hand&lt;/h3&gt;

&lt;p&gt;Consider a 2-variable Lasso problem \(\min_{\beta \in \mathbb{R}^2} \frac{1}{2}\|y - X\beta\|_2^2 + \lambda \|\beta\|_1\) with \(X = I_2\) (the \(2\times 2\) identity, so \(L = \|X\|_2^2 = 1\)), \(y = (3.0, -0.4)^\top\), and \(\lambda = 1.0\). Start at \(\beta^{(0)} = (1.0, 1.0)^\top\) with step size \(t = 0.5 \le 1/L\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the smooth gradient \(\nabla g(\beta^{(0)}) = -X^\top(y - X\beta^{(0)})\):&lt;/strong&gt;
\(y - X\beta^{(0)} = \begin{pmatrix}3.0 \\ -0.4\end{pmatrix} - \begin{pmatrix}1.0 \\ 1.0\end{pmatrix} = \begin{pmatrix}2.0 \\ -1.4\end{pmatrix} \implies \nabla g(\beta^{(0)}) = \begin{pmatrix}-2.0 \\ 1.4\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Take the gradient step on \(g\):&lt;/strong&gt;
\(u = \beta^{(0)} - t\nabla g(\beta^{(0)}) = \begin{pmatrix}1.0 \\ 1.0\end{pmatrix} - 0.5\begin{pmatrix}-2.0 \\ 1.4\end{pmatrix} = \begin{pmatrix}2.0 \\ 0.3\end{pmatrix}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Apply soft-thresholding \(S_{\lambda t}(u)\) with threshold \(\lambda t = 1.0 \cdot 0.5 = 0.5\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Coordinate 1: $$&lt;/td&gt;
              &lt;td&gt;2.0&lt;/td&gt;
              &lt;td&gt;&amp;gt; 0.5 \implies \beta_1^{(1)} = 2.0 - 0.5 = 1.5$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Coordinate 2: $$&lt;/td&gt;
              &lt;td&gt;0.3&lt;/td&gt;
              &lt;td&gt;\le 0.5 \implies \beta_2^{(1)} = 0$$ (exact zero!).&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify progress:&lt;/strong&gt; The true minimizer for \(X = I_2\) is \(\beta^\star = S_{\lambda}(y) = (2.0, 0)^\top\). In just one step with \(t = 0.5\), ISTA identified the exact active support (\(\beta_2 = 0\)) and moved \(\beta_1\) halfway from \(1.0\) to \(2.0\)! (With \(t = 1/L = 1\), it hits \(\beta^\star = (2.0, 0)^\top\) in a single step.)&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;proximal-gradient-descent&quot;&gt;Proximal gradient descent&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Proximal gradient descent&lt;/strong&gt; is a method for finding the optimum by decomposing the objective function into a differentiable part and a non-differentiable part. In this section, we will look at how to define functions and find the optimum in proximal gradient descent.&lt;/p&gt;

&lt;h2 id=&quot;decomposable-functions&quot;&gt;Decomposable functions&lt;/h2&gt;
&lt;p&gt;Suppose the objective function \(f\) can be decomposed into two functions \(g\) and \(h\).&lt;/p&gt;

&lt;blockquote&gt;
\[f(x) = g(x) + h(x)\]
&lt;/blockquote&gt;

&lt;p&gt;Here, the two functions \(g\) and \(h\) have the following properties:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(g\) is convex and differentiable. (&lt;strong&gt;dom&lt;/strong&gt;\((g) = \mathbb{R}^n\))&lt;/li&gt;
  &lt;li&gt;\(h\) is convex and non-differentiable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If \(f\) is differentiable, you can find the next position using gradient descent:&lt;/p&gt;

&lt;blockquote&gt;
\[x^+ = x - t \cdot \nabla f(x)\]
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;[Note]&lt;/strong&gt; In gradient descent, the function \(f\) is approximated near \(x\) by a second-order Taylor expansion, and the Hessian \(\nabla^2 f(x)\) is replaced by \(\frac{1}{2t} I\). The minimum of this approximation is chosen as the next position. (See Chapter 6 Gradient descent for details)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^+ = \underset{z}{\text{argmin}}  \underbrace{ f(x) + \nabla f(x)^T (z - x) + \frac{1}{2t} \parallel z - x \parallel_2 ^2}_{\tilde{f}_t(z)}
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, if \(f\) is not differentiable, you cannot use gradient descent. But if \(f\) is composed as \(f = g + h\), can’t we approximate the differentiable part \(g\) with a quadratic?&lt;/p&gt;

&lt;p&gt;This idea leads to &lt;strong&gt;Proximal gradient descent&lt;/strong&gt;. In this method, you adjust to the best position that is close to the location predicted by gradient descent for \(g\) and also makes the non-differentiable function \(h\) small. This process can be expressed as follows:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
x^+ &amp;amp; = \underset{z}{\text{argmin}}   \tilde{g}_t(z) + h(z) \\
&amp;amp; = \underset{z}{\text{argmin}} \ g(x) + \nabla g(x)^T (z - x) + \frac{1}{2t} \parallel z - x \parallel_2 ^2 + h(z) \\
&amp;amp; = \underset{z}{\text{argmin}}  \nabla g(x)^T (z - x) + \frac{1}{2t} \parallel z - x \parallel_2 ^2 + \frac{t}{2} \parallel \nabla g(x) \parallel_2 ^2  + h(z) \\
&amp;amp; = \underset{z}{\text{argmin}}  \frac{1}{2t} \left ( 2t \nabla g(x)^T (z - x) + \parallel z - x \parallel_2 ^2 + t^2 \parallel \nabla g(x) \parallel_2 ^2 \right )  + h(z) \\
&amp;amp; = \underset{z}{\text{argmin}}  \frac{1}{2t} \left ( \parallel z - x \parallel_2 ^2 + 2t \nabla g(x)^T (z - x) + t^2 \parallel \nabla g(x) \parallel_2 ^2 \right ) + h(z) \\
&amp;amp; = \underset{z}{\text{argmin}}   \frac{1}{2t} \parallel z - (x - t \nabla g(x) )\parallel_2 ^2 + h(z) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;When moving from the 2nd to the 3rd line, the term \(g(x)\) is removed as a constant term with respect to z, and the term \(\frac{t}{2} \parallel \nabla g(x)^T \parallel_2 ^2\) is added. In the final equation, the first term \(\frac{1}{2t} \parallel z - (x - t \nabla g(x) )\parallel_2 ^2\) is the term that brings it closer to the gradient update position of \(g\), and the second term \(h(z)\) is the term that reduces \(h\).&lt;/p&gt;

&lt;h2 id=&quot;proximal-gradient-descent-1&quot;&gt;Proximal gradient descent&lt;/h2&gt;
&lt;p&gt;Proximal gradient descent starts from an initial point \(x^{(0)}\) and iteratively applies the following update:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\(x^{(k)} = \text{prox}_{t_k}(x^{(k-1)} - t_k \nabla g(x^{(k-1)}) )\), \(k=1,2,3,...\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, \(\text{prox}_{t}\) is defined as the proximal mapping:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
\text{prox}_{t}(x) = \underset{z}{\arg \min}  \frac{1}{2t} \parallel x - z \parallel_2^2 + h(z)
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If we rewrite this in the update form we have seen so far, it becomes:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
x^{(k)} = x^{(k-1)} - t_k \cdot G_{t_k}(x^{(k-1)}), \space \space \text{where} \space G_{t}(x) = \frac{x-\text{prox}_{t} (x - t \nabla g(x))}{t} &lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;what-good-did-this-do&quot;&gt;What good did this do?&lt;/h2&gt;
&lt;p&gt;What is the benefit of doing this? Could it be just changing the problem to another form of minimization problem?&lt;/p&gt;

&lt;p&gt;The key point is that for most of the main \(h\) functions, \(\text{prox}_{t}(\cdot)\) can be computed analytically. In other words, it can be calculated as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The mapping function \(\text{prox}_{t}(\cdot)\) depends only on \(h\), not on \(g\).&lt;/li&gt;
  &lt;li&gt;The function \(g\) can be very complex, but here we only need to compute the gradient \(\nabla g\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The convergence analysis will be done concerning the number of iterations of the algorithm. Note that in each iteration, computing \(\text{prox}_{t}(\cdot)\) may vary in computational cost depending on \(h\).&lt;/p&gt;

&lt;h2 id=&quot;example-ista&quot;&gt;Example: ISTA&lt;/h2&gt;
&lt;p&gt;Let’s look at an example of proximal gradient descent. In the previous chapter, the lasso criterion was defined as follows when \(y \in \mathbb{R}^n\) and \(X \in \mathbb{R}^{n \times p}\):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;\begin{align}
f(\beta) = \frac{1}{2} \parallel y - X\beta \parallel_2^2 + \lambda \parallel \beta \parallel_1 &lt;br /&gt;
\end{align}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, \(g(\beta) = \frac{1}{2} \parallel y - X\beta \parallel_2^2\) and \(h(\beta) = \lambda \parallel \beta \parallel_1\). In this case, the proximal mapping is defined as:&lt;/p&gt;

&lt;blockquote&gt;

\[\begin{align}
\text{prox}_{t}(\beta) &amp;amp; = \underset{z}{\text{argmin}}  \frac{1}{2t} \parallel \beta - z \parallel_2^2 + \lambda \parallel z \parallel_1 \\
&amp;amp; = S_{\lambda t}(\beta) \\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;\(S_{\lambda t}(\beta)\) is the soft-thresholding operator, defined as follows. (For more details, see Chapter 7 Subgradient)&lt;/p&gt;

&lt;blockquote&gt;
\[\begin{align}
[S_{\lambda t}(\beta)]_i =
\begin{cases}
\beta_i - \lambda &amp;amp; \mbox{if } \beta_i \gt \lambda \\
0 &amp;amp; \mbox{if } \lambda \le \beta_i \le \lambda, i = 1, ..., n \\
\beta_i + \lambda &amp;amp; \mbox{if } \beta_i \lt -\lambda \\
\end{cases}
\\
\end{align}\]
&lt;/blockquote&gt;

&lt;p&gt;Since the gradient of \(g\) is \(\nabla g(\beta) = -X^{T} (y - X \beta)\), the proximal gradient update is defined as:&lt;/p&gt;

&lt;blockquote&gt;
\[\beta^+ = S_{\lambda t}(\beta + tX^{T} (y - X \beta) )\]
&lt;/blockquote&gt;

&lt;p&gt;This algorithm is a very simple algorithm called the &lt;strong&gt;iterative soft-thresholding algorithm (ISTA)&lt;/strong&gt;. (Beck and Teboulle (2008), “A fast iterative shrinkage-thresholding algorithm for linear inverse problems”)&lt;/p&gt;

&lt;p&gt;In the following figure, you can clearly see the performance difference between the subgradient method and proximal gradient descent. In terms of the number of iterations, the performance of proximal gradient descent is comparable to that of gradient descent.&lt;/p&gt;

&lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;/img/chapter_img/chapter09/09.01_01_ISTA.png&quot; width=&quot;80%&quot; height=&quot;80%&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;[Fig 1] Example of proximal gradient (ISTA) vs. subgradient method convergence rate [3]&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;soft-thresholding-the-prox-of-λx-and-exact-zeros-video&quot;&gt;Soft-thresholding: the prox of λ|x| and exact zeros (video)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot; style=&quot;text-align:center;margin:1.5rem 0;&quot;&gt;
&lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; style=&quot;width:100%;max-width:360px;height:auto;aspect-ratio:9/16;border-radius:12px;background:#10121a;&quot; src=&quot;/public/videos/reels/prox-shrink_en.mp4&quot;&gt;&lt;/video&gt;
&lt;/div&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;The prox of \(\lambda|x|_1\) sends small entries to exactly zero and shrinks the others by \(\lambda\): $$\operatorname{sign}(y)\max(&lt;/td&gt;
      &lt;td&gt;y&lt;/td&gt;
      &lt;td&gt;-\lambda,0)$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;try-it-yourself-ista-on-a-tiny-lasso&quot;&gt;Try it yourself: ISTA on a tiny lasso&lt;/h3&gt;

&lt;div class=&quot;opx-explainer&quot; data-opx=&quot;ista&quot; data-lang=&quot;en&quot;&gt;&lt;/div&gt;
</content>
 </entry>
 

</feed>
